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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

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