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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiShortUrl
  • cApiShortUrlCollection

Functions

  • piUsAfterLoadPlugins
  • piUsConSaveArtAfter
  • piUseConDeleteArtAfter
  • 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:  * @method cApiShortUrl createNewItem
 25:  * @method cApiShortUrl next
 26:  */
 27: class cApiShortUrlCollection extends ItemCollection {
 28: 
 29:     /**
 30:      *
 31:      * @var int
 32:      */
 33:     const ERR_IS_CLIENT_FOLDER = 1;
 34: 
 35:     /**
 36:      *
 37:      * @var int
 38:      */
 39:     const ERR_TOO_SHORT = 2;
 40: 
 41:     /**
 42:      *
 43:      * @var int
 44:      */
 45:     const ERR_INVALID_CHARS = 3;
 46: 
 47:     /**
 48:      *
 49:      * @var int
 50:      */
 51:     const ERR_IS_ARTICLE_ALIAS = 4;
 52: 
 53:     /**
 54:      *
 55:      * @var int
 56:      */
 57:     const ERR_IS_CATEGORY_ALIAS = 5;
 58: 
 59:     /**
 60:      *
 61:      * @var int
 62:      */
 63:     const ERR_ALREADY_EXISTS = 6;
 64: 
 65:     /**
 66:      * @throws cInvalidArgumentException
 67:      */
 68:     public function __construct() {
 69:         $cfg = cRegistry::getConfig();
 70:         parent::__construct($cfg['tab']['url_shortener']['shorturl'], 'idshorturl');
 71:         $this->_setItemClass('cApiShortUrl');
 72:     }
 73: 
 74:     /**
 75:      *
 76:      * @param string $shorturl
 77:      * @param int    $idart
 78:      * @param int    $idlang
 79:      * @param int    $idclient
 80:      *
 81:      * @return cApiShortUrl
 82:      * @throws cDbException
 83:      * @throws cException
 84:      * @throws cInvalidArgumentException
 85:      */
 86:     public function create($shorturl, $idart = NULL, $idlang = NULL, $idclient = NULL) {
 87:         if (is_null($idart)) {
 88:             $idart = cRegistry::getArticleId();
 89:         }
 90:         if (is_null($idlang)) {
 91:             $idlang = cRegistry::getLanguageId();
 92:         }
 93:         if (is_null($idclient)) {
 94:             $idclient = cRegistry::getClientId();
 95:         }
 96: 
 97:         /** @var cApiShortUrl $item */
 98:         $item = $this->createNewItem();
 99:         $item->set('shorturl', $shorturl);
100:         $item->set('idart', $idart);
101:         $item->set('idlang', $idlang);
102:         $item->set('idclient', $idclient);
103:         $item->set('created', date('Y-m-d H:i:s'));
104:         $item->store();
105: 
106:         return $item;
107:     }
108: 
109:     /**
110:      * Checks whether the given short URL is valid with the following criteria:
111:      * - given url is not a directory in the client folder
112:      * - given url respects minimum length
113:      * - given url contains only valid characters
114:      * - given url is not an article or category alias
115:      *
116:      * @param string $shorturl the short URL to check
117:      *
118:      * @return int boolean error code if the given shorturl is invalid or true
119:      *         if it is valid
120:      * @throws cDbException
121:      */
122:     public function isValidShortUrl($shorturl) {
123:         $cfg = cRegistry::getConfig();
124: 
125:         if (cString::getStringLength(trim($shorturl)) === 0) {
126:             return true;
127:         }
128: 
129:         // check if given shorturl is a directory in the client folder
130:         $exclude = scandir(cRegistry::getFrontendPath());
131:         if (is_array($cfg['url_shortener']['exlude_dirs'])) {
132:             $exclude = array_merge($exclude, $cfg['url_shortener']['exlude_dirs']);
133:         }
134:         if (in_array($shorturl, $exclude)) {
135:             return self::ERR_IS_CLIENT_FOLDER;
136:         }
137: 
138:         // check if given shorturl respects minimum length
139:         $minLength = 3;
140:         if (is_numeric($cfg['url_shortener']['minimum_length'])) {
141:             $minLength = $cfg['url_shortener']['minimum_length'];
142:         }
143:         if (cString::getStringLength($shorturl) < $minLength) {
144:             return self::ERR_TOO_SHORT;
145:         }
146: 
147:         // check if given shorturl contains only valid characters
148:         if (isset($cfg['url_shortener']['allowed_chars'])) {
149:             if (!preg_match($cfg['url_shortener']['allowed_chars'], $shorturl)) {
150:                 return self::ERR_INVALID_CHARS;
151:             }
152:         }
153: 
154:         // check if there is an article or category alias with this name
155:         $artLangColl = new cApiArticleLanguageCollection();
156:         $artLangColl->select("urlname='" . $shorturl . "'");
157:         if ($artLangColl->count() > 0) {
158:             return self::ERR_IS_ARTICLE_ALIAS;
159:         }
160:         $catLangColl = new cApiCategoryLanguageCollection();
161:         $catLangColl->select("urlname='" . $shorturl . "'");
162:         if ($catLangColl->count() > 0) {
163:             return self::ERR_IS_CATEGORY_ALIAS;
164:         }
165: 
166:         return true;
167:     }
168: }
169: 
170: /**
171:  *
172:  * @author Ingo van Peeren
173:  * @package Plugin
174:  * @subpackage UrlShortener
175:  */
176: class cApiShortUrl extends Item {
177:     /**
178:      * Constructor Function
179:      *
180:      * @param mixed $id Specifies the ID of item to load
181:      *
182:      * @throws cDbException
183:      * @throws cException
184:      */
185:     public function __construct($id = false) {
186:         $cfg = cRegistry::getConfig();
187:         parent::__construct($cfg['tab']['url_shortener']['shorturl'], 'idshorturl');
188:         if ($id !== false) {
189:             $this->loadByPrimaryKey($id);
190:         }
191:     }
192: }
193: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0