Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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

  • cApiShortUrl
  • cApiShortUrlCollection

Functions

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