Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • ArticleForum
  • cApiShortUrl
  • cGenericDb
  • cGenericDbDriver
  • cGenericDbDriverMysql
  • cItemBaseAbstract
  • cItemCache
  • Item
  • ItemCollection
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the Plugin Manager API classes.
  4:  *
  5:  * @package Plugin
  6:  * @subpackage UrlShortener
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Simon Sprankel
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Plugin Manager API classes.
 20:  *
 21:  * @package Plugin
 22:  * @subpackage UrlShortener
 23:  */
 24: class cApiShortUrlCollection extends ItemCollection {
 25: 
 26:     const ERR_IS_CLIENT_FOLDER = 1;
 27: 
 28:     const ERR_TOO_SHORT = 2;
 29: 
 30:     const ERR_INVALID_CHARS = 3;
 31: 
 32:     const ERR_IS_ARTICLE_ALIAS = 4;
 33: 
 34:     const ERR_IS_CATEGORY_ALIAS = 5;
 35: 
 36:     const ERR_ALREADY_EXISTS = 6;
 37: 
 38:     public function __construct() {
 39:         $cfg = cRegistry::getConfig();
 40:         parent::__construct($cfg['tab']['url_shortener']['shorturl'], 'idshorturl');
 41:         $this->_setItemClass('cApiShortUrl');
 42:     }
 43: 
 44:     public function create($shorturl, $idart = NULL, $idlang = NULL, $idclient = NULL) {
 45:         if (is_null($idart)) {
 46:             $idart = cRegistry::getArticleId();
 47:         }
 48:         if (is_null($idlang)) {
 49:             $idlang = cRegistry::getLanguageId();
 50:         }
 51:         if (is_null($idclient)) {
 52:             $idclient = cRegistry::getClientId();
 53:         }
 54: 
 55:         $item = parent::createNewItem();
 56:         $item->set('shorturl', $shorturl);
 57:         $item->set('idart', $idart);
 58:         $item->set('idlang', $idlang);
 59:         $item->set('idclient', $idclient);
 60:         $item->set('created', date('Y-m-d H:i:s'));
 61:         $item->store();
 62: 
 63:         return $item;
 64:     }
 65: 
 66:     /**
 67:      * Checks whether the given short URL is valid with the following criteria:
 68:      * - given url is not a directory in the client folder
 69:      * - given url respects minimum length
 70:      * - given url contains only valid characters
 71:      * - given url is not an article or category alias
 72:      *
 73:      * @param string $shorturl the short URL to check
 74:      * @return int boolean error code if the given shorturl is invalid or true
 75:      *         if it is valid
 76:      */
 77:     public function isValidShortUrl($shorturl) {
 78:         $cfg = cRegistry::getConfig();
 79: 
 80:         // check if given shorturl is a directory in the client folder
 81:         $exclude = scandir(cRegistry::getFrontendPath());
 82:         if (is_array($cfg['url_shortener']['exlude_dirs'])) {
 83:             $exclude = array_merge($exclude, $cfg['url_shortener']['exlude_dirs']);
 84:         }
 85:         if (in_array($shorturl, $exclude)) {
 86:             return self::ERR_IS_CLIENT_FOLDER;
 87:         }
 88: 
 89:         // check if given shorturl respects minimum length
 90:         $minLength = 3;
 91:         if (is_numeric($cfg['url_shortener']['minimum_length'])) {
 92:             $minLength = $cfg['url_shortener']['minimum_length'];
 93:         }
 94:         if (strlen($shorturl) < $minLength) {
 95:             return self::ERR_TOO_SHORT;
 96:         }
 97: 
 98:         // check if given shorturl contains only valid characters
 99:         if (isset($cfg['url_shortener']['allowed_chars'])) {
100:             if (!preg_match($cfg['url_shortener']['allowed_chars'], $shorturl)) {
101:                 return self::ERR_INVALID_CHARS;
102:             }
103:         }
104: 
105:         // check if there is an article or category alias with this name
106:         $artLangColl = new cApiArticleLanguageCollection();
107:         $artLangColl->select("urlname='" . $shorturl . "'");
108:         if ($artLangColl->count() > 0) {
109:             return self::ERR_IS_ARTICLE_ALIAS;
110:         }
111:         $catLangColl = new cApiCategoryLanguageCollection();
112:         $catLangColl->select("urlname='" . $shorturl . "'");
113:         if ($catLangColl->count() > 0) {
114:             return self::ERR_IS_CATEGORY_ALIAS;
115:         }
116: 
117:         return true;
118:     }
119: 
120: }
121: class cApiShortUrl extends Item {
122: 
123:     /**
124:      * Constructor Function
125:      *
126:      * @param mixed $id Specifies the ID of item to load
127:      */
128:     public function __construct($id = false) {
129:         $cfg = cRegistry::getConfig();
130:         parent::__construct($cfg['tab']['url_shortener']['shorturl'], 'idshorturl');
131:         if ($id !== false) {
132:             $this->loadByPrimaryKey($id);
133:         }
134:     }
135: 
136: }
137: 
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0