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
    • NavigationMain
    • 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

  • cApiShortUrlCollection

Functions

  • piUsAfterLoadPlugins
  • piUsConSaveArtAfter
  • piUsEditFormAdditionalRows
  • piUsGetErrorMessage
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the Plugin Manager configurations.
  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:  * Constructs the HTML code containing table rows which are added to the end of
 20:  * the article edit form
 21:  *
 22:  * @return string rendered HTML code
 23:  */
 24: function piUsEditFormAdditionalRows($idart, $idlang, $idclient) {
 25:     $shortUrl = new cApiShortUrl();
 26:     $shortUrl->loadByMany(array(
 27:         'idart' => $idart,
 28:         'idlang' => $idlang,
 29:         'idclient' => $idclient
 30:     ));
 31: 
 32:     $tr = new cHTMLTableRow();
 33: 
 34:     $td = new cHTMLTableData();
 35:     $td->setClass('text_medium');
 36:     $td->setContent(i18n('Short URL', 'url_shortener'));
 37:     $tr->appendContent($td);
 38: 
 39:     $td = new cHTMLTableData();
 40:     $td->setClass('text_medium');
 41:     $textbox = new cHTMLTextbox('url_shortener_shorturl', $shortUrl->get('shorturl'), 24);
 42:     $td->setContent($textbox.' <img class="vAlignMiddle" title="'. i18n('INFO', 'url_shortener') .'" src="images/info.gif">');
 43:     $tr->appendContent($td);
 44: 
 45:     return $tr->render();
 46: }
 47: 
 48: /**
 49:  * Function is called after an article has been saved.
 50:  * Checks whether a short URL has been given via $_POST and saves/deletes it.
 51:  *
 52:  * @param array $values the values which are saved
 53:  */
 54: function piUsConSaveArtAfter($editedIdArt, $values) {
 55:     // if not all parameters have been given, do nothing
 56:     if (!isset($_POST['url_shortener_shorturl']) || $_POST['url_shortener_shorturl'] == '' || !isset($editedIdArt)) {
 57:         return;
 58:     }
 59:     $shorturl = $_POST['url_shortener_shorturl'];
 60:     $idart = $editedIdArt;
 61:     $idlang = cRegistry::getLanguageId();
 62:     $idclient = cRegistry::getClientId();
 63:     $shortUrlItem = new cApiShortUrl();
 64:     $shortUrlItem->loadByMany(array(
 65:         'idart' => $idart,
 66:         'idlang' => $idlang,
 67:         'idclient' => $idclient
 68:     ));
 69:     // if given shorturl is already in use, show error message
 70:     $checkShortUrlItem = new cApiShortUrl();
 71:     $checkShortUrlItem->loadBy('shorturl', $shorturl);
 72:     if ($checkShortUrlItem->isLoaded()) {
 73:         // if shorturl has not been changed, do nothing
 74:         if ($shortUrlItem->get('shorturl') === $checkShortUrlItem->get('shorturl')) {
 75:             return;
 76:         }
 77:         // TODO add warning to session as soon as this is possible (depends
 78:         // CON-772)
 79:         // $session = cRegistry::getSession();
 80:         // $session->addWarning($message);
 81:         $message = piUsGetErrorMessage(cApiShortUrlCollection::ERR_ALREADY_EXISTS, $shortUrlItem);
 82:         $notification = new cGuiNotification();
 83:         $notification->displayNotification(cGuiNotification::LEVEL_ERROR, $message);
 84:         return;
 85:     }
 86:     // check if given shorturl is valid
 87:     $shortUrlColl = new cApiShortUrlCollection();
 88:     $errorCode = $shortUrlColl->isValidShortUrl($shorturl);
 89:     if ($errorCode !== true) {
 90:         $message = piUsGetErrorMessage($errorCode);
 91:         // TODO add warning to session as soon as this is possible (depends
 92:         // CON-772)
 93:         // $session = cRegistry::getSession();
 94:         // $session->addWarning($message);
 95:         $notification = new cGuiNotification();
 96:         $notification->displayNotification(cGuiNotification::LEVEL_ERROR, $message);
 97:         return;
 98:     }
 99:     if ($_POST['url_shortener_shorturl'] === '') {
100:         // delete short URL if it exists
101:         if ($shortUrlItem->isLoaded()) {
102:             $shortUrlColl->delete($shortUrlItem->get('idshorturl'));
103:         }
104:     } else {
105:         // a short URL has been given, so save it
106:         if ($shortUrlItem->isLoaded()) {
107:             // short URL already exists, update it
108:             $shortUrlItem->set('shorturl', $shorturl);
109:             $shortUrlItem->store();
110:         } else {
111:             // short URL does not exist yet, create a new one
112:             $shortUrlColl->create($shorturl, $idart, $idlang, $idclient);
113:         }
114:     }
115: }
116: 
117: /**
118:  * Computes an error message which describes the given error code.
119:  *
120:  * @param int $errorCode the error code
121:  * @return string the error message describing the given error code
122:  */
123: function piUsGetErrorMessage($errorCode, $shortUrlItem = null) {
124:     switch ($errorCode) {
125:         case cApiShortUrlCollection::ERR_INVALID_CHARS:
126:             return i18n('The entered short URL contains invalid characters!', 'url_shortener');
127:             break;
128:         case cApiShortUrlCollection::ERR_IS_ARTICLE_ALIAS:
129:             return i18n('The entered short URL is already an article alias!', 'url_shortener');
130:             break;
131:         case cApiShortUrlCollection::ERR_IS_CATEGORY_ALIAS:
132:             return i18n('The entered short URL is already a category alias!', 'url_shortener');
133:             break;
134:         case cApiShortUrlCollection::ERR_IS_CLIENT_FOLDER:
135:             return i18n('The entered short URL is a subdirectory of the client directory!', 'url_shortener');
136:             break;
137:         case cApiShortUrlCollection::ERR_TOO_SHORT:
138:             return i18n('The entered short URL is too short!', 'url_shortener');
139:             break;
140:         case cApiShortUrlCollection::ERR_ALREADY_EXISTS:
141:             $message = i18n('The entered short URL already exists!', 'url_shortener');
142:             $message .= '<br />';
143:             if ($shortUrlItem !== null) {
144:                 // add the client name to the error message
145:                 $clientColl = new cApiClientCollection();
146:                 $message .= i18n('Client', 'url_shortener') . ': ' . $clientColl->getClientname($shortUrlItem->get('idclient'));;
147:                 $message .= '<br />';
148:                 // add the language name to the error message
149:                 $langColl = new cApiLanguageCollection();
150:                 $message .= i18n('Language', 'url_shortener') . ': ' . $langColl->getLanguageName($shortUrlItem->get('idlang'));
151:                 $message .= '<br />';
152:                 // add the category name to the error message
153:                 $catArt = new cApiCategoryArticle();
154:                 $catArt->loadBy('idart', $shortUrlItem->get('idart'));
155:                 $catLang = new cApiCategoryLanguage();
156:                 $catLang->loadByCategoryIdAndLanguageId($catArt->get('idcat'), $shortUrlItem->get('idlang'));
157:                 $message .= i18n('Category', 'url_shortener') . ': ' . $catLang->get('name');
158:                 $message .= '<br />';
159:                 // add the article name to the error message
160:                 $artlang = new cApiArticleLanguage();
161:                 $artlang->loadByArticleAndLanguageId($shortUrlItem->get('idart'), $shortUrlItem->get('idlang'));
162:                 $message .= i18n('Article', 'url_shortener') . ': ' . $artlang->get('title');
163:             }
164:             return $message;
165:             break;
166:     }
167:     return i18n('The entered short URL is not valid!', 'url_shortener');
168: }
169: 
170: /**
171:  * Function is called after the plugins have been loaded.
172:  * If the string placeholder in the example URL http://www.domain.de/placeholder
173:  * is a defined short URL, the user is redirected to the correct URL.
174:  */
175: function piUsAfterLoadPlugins() {
176:     $requestUri = $_SERVER['REQUEST_URI'];
177:     $shorturl = substr($requestUri, strrpos($requestUri, '/') + 1);
178:     $shortUrlItem = new cApiShortUrl();
179:     $shortUrlItem->loadBy('shorturl', $shorturl);
180:     if ($shortUrlItem->isLoaded()) {
181:         $uriParams = array(
182:             'idart' => $shortUrlItem->get('idart'),
183:             'lang' => $shortUrlItem->get('idlang')
184:         );
185:         $url = cUri::getInstance()->build($uriParams, true);
186:         header('Location:' . $url);
187:         exit();
188:     }
189: }
190: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0