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

  • cCodeGeneratorAbstract
  • cCodeGeneratorFactory
  • cCodeGeneratorStandard
  • cContentTypeAbstract
  • cContentTypeAbstractTabbed
  • cContentTypeDate
  • cContentTypeFilelist
  • cContentTypeHead
  • cContentTypeHtml
  • cContentTypeHtmlhead
  • cContentTypeImg
  • cContentTypeImgdescr
  • cContentTypeImgeditor
  • cContentTypeLink
  • cContentTypeLinkdescr
  • cContentTypeLinkeditor
  • cContentTypeLinktarget
  • cContentTypeTeaser
  • cContentTypeText
  • cTypeGenerator
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: /**
   3:  * This file contains the cContentTypeLinkeditor class.
   4:  *
   5:  * @package Core
   6:  * @subpackage ContentType
   7:  * @version SVN Revision $Rev:$
   8:  *
   9:  * @author Timo Trautmann, 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: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  16: 
  17: cInclude('includes', 'functions.con.php');
  18: cInclude('includes', 'functions.api.images.php');
  19: 
  20: /**
  21:  * Content type CMS_TEASER which lets the editor select articles in various ways
  22:  * which are displayed as teasers.
  23:  *
  24:  * @package Core
  25:  * @subpackage ContentType
  26:  */
  27: class cContentTypeTeaser extends cContentTypeAbstractTabbed {
  28: 
  29:     /**
  30:      * Array which contains all avariable CMS_Types and its ids
  31:      * in current CONTENIDO isntallation (described as hash [idtype =>
  32:      * cmstypename])
  33:      *
  34:      * @var array
  35:      */
  36:     private $_cmsTypes;
  37: 
  38:     /**
  39:      * Content types in this array will be completely ignored by CMS_TEASER
  40:      * They won't be displayed in the frontend and they won't be shown as an
  41:      * option in the backend
  42:      *
  43:      * @var array
  44:      */
  45:     private $_ignoreTypes = array();
  46: 
  47:     /**
  48:      * If CMS_TEASER tries to load one of the content types listed as the keys
  49:      * of this array it will load the value of that key instead
  50:      * These won't be listed as an option in the backend either
  51:      *
  52:      * @var array
  53:      */
  54:     private $_forwardTypes = array(
  55:         "CMS_EASYIMG" => "CMS_IMG",
  56:         "CMS_IMGEDITOR" => "CMS_IMG",
  57:         "CMS_LINKEDITOR" => "CMS_LINK"
  58:     );
  59: 
  60:     /**
  61:      * Placeholders for labels in frontend.
  62:      * Important: This must be a static array!
  63:      *
  64:      * @var array
  65:      */
  66:     protected static $_translations = array(
  67:         "MORE"
  68:     );
  69: 
  70:     /**
  71:      * Variable for detecting current interation
  72:      */
  73:     protected $iteration = 0;
  74: 
  75:     /**
  76:      * Initialises class attributes and handles store events.
  77:      *
  78:      * @param string $rawSettings the raw settings in an XML structure or as
  79:      *        plaintext
  80:      * @param integer $id ID of the content type, e.g. 3 if CMS_DATE[3] is
  81:      *        used
  82:      * @param array $contentTypes array containing the values of all content
  83:      *        types
  84:      * @return void
  85:      */
  86:     public function __construct($rawSettings, $id, array $contentTypes) {
  87:         // change attributes from the parent class and call the parent
  88:         // constructor
  89:         $this->_type = 'CMS_TEASER';
  90:         $this->_prefix = 'teaser';
  91:         $this->_settingsType = self::SETTINGS_TYPE_XML;
  92:         $this->_formFields = array(
  93:             'teaser_title',
  94:             'teaser_category',
  95:             'teaser_count',
  96:             'teaser_style',
  97:             'teaser_manual',
  98:             'teaser_start',
  99:             'teaser_source_head',
 100:             'teaser_source_head_count',
 101:             'teaser_source_text',
 102:             'teaser_source_text_count',
 103:             'teaser_source_image',
 104:             'teaser_source_image_count',
 105:             'teaser_filter',
 106:             'teaser_sort',
 107:             'teaser_sort_order',
 108:             'teaser_character_limit',
 109:             'teaser_image_width',
 110:             'teaser_image_height',
 111:             'teaser_manual_art',
 112:             'teaser_image_crop',
 113:             'teaser_source_date',
 114:             'teaser_source_date_count'
 115:         );
 116: 
 117:         parent::__construct($rawSettings, $id, $contentTypes);
 118: 
 119:         // if form is submitted, store the current teaser settings
 120:         // notice: also check the ID of the content type (there could be more
 121:         // than one content type of the same type on the same page!)
 122:         if (isset($_POST[$this->_prefix . '_action']) && $_POST[$this->_prefix . '_action'] == 'store' && isset($_POST[$this->_prefix . '_id']) && (int) $_POST[$this->_prefix . '_id'] == $this->_id) {
 123:             $this->_storeSettings();
 124:         }
 125: 
 126:         $this->_setDefaultValues();
 127:     }
 128: 
 129:     /**
 130:      * Returns all translation strings for mi18n.
 131:      *
 132:      * @param array $translationStrings translation strings
 133:      * @return array updated translation string
 134:      */
 135:     public static function addModuleTranslations(array $translationStrings) {
 136:         foreach (self::$_translations as $value) {
 137:             $translationStrings[] = $value;
 138:         }
 139: 
 140:         return $translationStrings;
 141:     }
 142: 
 143:     /**
 144:      * Sets some default values for teaser in case that there is no value
 145:      * defined.
 146:      *
 147:      * @return void
 148:      */
 149:     private function _setDefaultValues() {
 150:         // character limit is 120 by default
 151:         if ((int) $this->_settings['teaser_character_limit'] == 0) {
 152:             $this->_settings['teaser_character_limit'] = 120;
 153:         }
 154: 
 155:         // teaser cont is 6 by default
 156:         if ((int) $this->_settings['teaser_count'] == 0) {
 157:             $this->_settings['teaser_count'] = 6;
 158:         }
 159: 
 160:         // teasersort is creationdate by default
 161:         if (strlen($this->_settings['teaser_sort']) == 0) {
 162:             $this->_settings['teaser_sort'] = 'creationdate';
 163:         }
 164: 
 165:         // teaser style is liststyle by default
 166:         if (strlen($this->_settings['teaser_style']) == 0) {
 167:             $this->_settings['teaser_style'] = 'cms_teaser_slider.html';
 168:         }
 169: 
 170:         // teaser image width default
 171:         if ((int) $this->_settings['teaser_image_width'] == 0) {
 172:             $this->_settings['teaser_image_width'] = 100;
 173:         }
 174: 
 175:         // teaser image height default
 176:         if ((int) $this->_settings['teaser_image_height'] == 0) {
 177:             $this->_settings['teaser_image_height'] = 75;
 178:         }
 179: 
 180:         // cms type head default
 181:         if (strlen($this->_settings['teaser_source_head']) == 0) {
 182:             $this->_settings['teaser_source_head'] = 'CMS_HTMLHEAD';
 183:         }
 184: 
 185:         // cms type text default
 186:         if (strlen($this->_settings['teaser_source_text']) == 0) {
 187:             $this->_settings['teaser_source_text'] = 'CMS_HTML';
 188:         }
 189: 
 190:         // cms type image default
 191:         if (strlen($this->_settings['teaser_source_image']) == 0) {
 192:             $this->_settings['teaser_source_image'] = 'CMS_IMG';
 193:         }
 194: 
 195:         // cms type date default
 196:         if (strlen($this->_settings['teaser_source_date']) == 0) {
 197:             $this->_settings['teaser_source_date'] = 'CMS_DATE';
 198:         }
 199: 
 200:         // sort order of teaser articles
 201:         if (strlen($this->_settings['teaser_sort_order']) == 0) {
 202:             $this->_settings['teaser_sort_order'] = 'asc';
 203:         }
 204: 
 205:         // teaser image crop option
 206:         if (strlen($this->_settings['teaser_image_crop']) == 0 || $this->_settings['teaser_image_crop'] == 'false') {
 207:             $this->_settings['teaser_image_crop'] = 'false';
 208:         }
 209:     }
 210: 
 211:     /**
 212:      * Generates the code which should be shown if this content type is shown in
 213:      * the frontend.
 214:      *
 215:      * @return string escaped HTML code which sould be shown if content type is
 216:      *         shown in frontend
 217:      */
 218:     public function generateViewCode() {
 219:         $code = '";?><?php
 220:                     $teaser = new cContentTypeTeaser(\'%s\', %s, %s);
 221: 
 222:                     echo $teaser->generateTeaserCode();
 223:                  ?><?php echo "';
 224:         $code = sprintf($code, $this->_rawSettings, $this->_id, 'array()');
 225: 
 226:         return $code;
 227:     }
 228: 
 229:     /**
 230:      * Function returns idarts of selected articles as array
 231:      *
 232:      * @return array
 233:      */
 234:     public function getConfiguredArticles() {
 235:         $articles = array();
 236:         $articles = $this->generateTeaserCode(true);
 237: 
 238:         return $articles;
 239:     }
 240: 
 241:     /**
 242:      * Function is called in edit- and viewmode in order to generate teasercode
 243:      * for output
 244:      *
 245:      * @param boolean $returnAsArray modeswitch betwwen template generation and
 246:      *        and returning result as array
 247:      * @return mixed string of select box or array of articles
 248:      */
 249:     public function generateTeaserCode($returnAsArray = false) {
 250:         global $contenido;
 251: 
 252:         $articles = array();
 253: 
 254:         $template = new cTemplate();
 255:         // set title of teaser
 256:         $template->set('s', 'TITLE', $this->_settings['teaser_title']);
 257: 
 258:         // decide if it is a manual or category teaser
 259:         if ($this->_settings['teaser_manual'] == 'true' && count($this->_settings['teaser_manual_art']) > 0) {
 260:             $manualArts = $this->_settings['teaser_manual_art'];
 261:             if (!empty($manualArts) && !is_array($manualArts)) {
 262:                 $manualArts = array(
 263:                     $manualArts
 264:                 );
 265:             }
 266:             if (is_array($manualArts)) {
 267:                 $i = 0;
 268:                 // in manual case get all art to display and generate article
 269:                 // objects manually
 270:                 foreach ($manualArts as $idArt) {
 271:                     $article = new cApiArticleLanguage();
 272:                     $article->loadByArticleAndLanguageId($idArt, $this->_lang);
 273: 
 274:                     // try to fill teaser image
 275:                     if ($returnAsArray == false && $this->_fillTeaserTemplateEntry($article, $template)) {
 276:                         $i++;
 277:                         // break render, if teaser limit is reached
 278:                         if ($i == $this->_settings['teaser_count']) {
 279:                             break;
 280:                         }
 281:                     }
 282: 
 283:                     if ($returnAsArray == true && $this->_fillTeaserTemplateEntry($article, $template)) {
 284:                         array_push($articles, $article);
 285: 
 286:                         if ($i == $this->_settings['teaser_count']) {
 287:                             break;
 288:                         }
 289:                     }
 290:                 }
 291:             }
 292:         } else {
 293:             // in case of automatic teaser use class cArticleCollector
 294:             // for getting all arts in category
 295: 
 296:             $options = array(
 297:                 'lang' => $this->_lang,
 298:                 'client' => $this->_client,
 299:                 'idcat' => $this->_settings['teaser_category'],
 300:                 'order' => $this->_settings['teaser_sort'],
 301:                 'direction' => $this->_settings['teaser_sort_order'],
 302:                 'limit' => $this->_settings['teaser_count'],
 303:                 'start' => false,
 304:                 'offline' => $contenido != ""
 305:             );
 306: 
 307:             if ($this->_settings['teaser_start'] == 'true') {
 308:                 $options['start'] = true;
 309:             }
 310: 
 311:             $artCollector = new cArticleCollector($options);
 312: 
 313:             foreach ($artCollector as $article) {
 314:                 if ($returnAsArray == true) {
 315:                     array_push($articles, $article);
 316:                 } else {
 317:                     $this->_fillTeaserTemplateEntry($article, $template);
 318:                 }
 319:             }
 320:         }
 321: 
 322:         $code = '';
 323: 
 324:         // generate teasertemplate
 325:         if ($returnAsArray == false && file_exists($this->_cfgClient[$this->_client]['path']['frontend'] . 'templates/' . $this->_settings['teaser_style'])) {
 326:             $code = $template->generate($this->_cfgClient[$this->_client]['path']['frontend'] . 'templates/' . $this->_settings['teaser_style'], true);
 327:             return $code;
 328:         } else if ($returnAsArray == true) {
 329:             return $articles;
 330:         }
 331:     }
 332: 
 333:     /**
 334:      * In edit and view mode this function fills teaser template with
 335:      * informations from a CONTENIDO article object.
 336:      *
 337:      * @param cApiArticleLanguage $article - CONTENIDO Article object
 338:      * @param cTemplate $template - CONTENIDO Template object (as reference)
 339:      * @return boolean - success state of this operation
 340:      */
 341:     private function _fillTeaserTemplateEntry(cApiArticleLanguage $article, cTemplate &$template) {
 342:         global $contenido;
 343: 
 344:         // get necessary informations for teaser from articles use properties in
 345:         // a Settings for retrieval
 346:         $title = $this->_getArtContent($article, $this->_settings['teaser_source_head'], $this->_settings['teaser_source_head_count']);
 347:         $text = $this->_getArtContent($article, $this->_settings['teaser_source_text'], $this->_settings['teaser_source_text_count']);
 348:         $imageId = $this->_getArtContent($article, $this->_settings['teaser_source_image'], $this->_settings['teaser_source_image_count']);
 349:         $date = $this->_getArtContent($article, $this->_settings['teaser_source_date'], $this->_settings['teaser_source_date_count']);
 350:         $idArt = $article->getField('idart');
 351:         $published = $article->getField('published');
 352:         $online = $article->getField('online');
 353: 
 354:         if ($online == 1 || $contenido) {
 355:             // teaserfilter defines strings which must be contained in text for
 356:             // display.
 357:             // if string is defined check if article contains this string and
 358:             // abort, if article does not contain this string
 359:             if ($this->_settings['teaser_filter'] != '') {
 360:                 $iPosText = strrpos(conHtmlEntityDecode($text), $this->_settings['teaser_filter']);
 361:                 $iPosHead = strrpos(conHtmlEntityDecode($title), $this->_settings['teaser_filter']);
 362:                 if (is_bool($iPosText) && !$iPosText && is_bool($iPosHead) && !$iPosHead) {
 363:                     return false;
 364:                 }
 365:             }
 366: 
 367:             // convert date to readable format
 368:             if (preg_match('/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/', $published, $results)) {
 369:                 $published = $results[3] . '.' . $results[2] . '.' . $results[1];
 370:             }
 371: 
 372:             // strip tags in teaser text and cut it if it is to long
 373:             $title = trim(strip_tags($title));
 374:             $text = trim(strip_tags($text));
 375:             if (strlen($text) > $this->_settings['teaser_character_limit']) {
 376:                 $text = capiStrTrimAfterWord($text, $this->_settings['teaser_character_limit']) . '...';
 377:             }
 378: 
 379:             // try to get a teaser image directly from cms_img or try to extract
 380:             // if a content type is given, wich contains html
 381:             if ((int) $imageId > 0) {
 382:                 $image = $this->_getImage($imageId, $this->_settings['teaser_image_width'], $this->_settings['teaser_image_height'], $this->_settings['teaser_image_crop']);
 383:                 $template->set('d', 'IMAGE', $image['element']);
 384:                 $template->set('d', 'IMAGE_SRC', $image['src']);
 385:             } else if (strip_tags($imageId) != $imageId && strlen($imageId) > 0) {
 386:                 $image = $this->_extractImage($imageId);
 387:                 if (strlen($image) > 0) {
 388:                     $template->set('d', 'IMAGE', $image['element']);
 389:                     $template->set('d', 'IMAGE_SRC', $image['src']);
 390:                 } else {
 391:                     $template->set('d', 'IMAGE', '');
 392:                     $template->set('d', 'IMAGE_SRC', '');
 393:                 }
 394:             } else {
 395:                 $template->set('d', 'IMAGE_SRC', '');
 396:                 $template->set('d', 'IMAGE', '');
 397:             }
 398: 
 399:             // strip all tags from manual teaser date
 400:             $date = strip_tags($date);
 401: 
 402:             // set generated values to teaser template
 403:             $template->set('d', 'TITLE', $title);
 404:             $template->set('d', 'TEXT', $text);
 405: 
 406:             $template->set('d', 'IDART', $idArt);
 407:             $template->set('d', 'ART_URL', 'front_content.php?idart=' . $idArt);
 408:             $template->set('d', 'PUBLISHED', $published);
 409:             $template->set('d', 'PUBLISHED_MANUAL', $date);
 410: 
 411:             if ($date != '') {
 412:                 $template->set('d', 'PUBLISHED_COMBINED', $date);
 413:             } else {
 414:                 $template->set('d', 'PUBLISHED_COMBINED', $published);
 415:             }
 416: 
 417:             foreach (self::$_translations as $translationString) {
 418:                 $template->set('d', $translationString, mi18n($translationString));
 419:             }
 420: 
 421:             if ($this->iteration == 0) {
 422:                 $template->set('d', 'ACTIVE', 'active');
 423:             } else {
 424:                 $template->set('d', 'ACTIVE', '');
 425:             }
 426:             $this->iteration++;
 427: 
 428:             $template->next();
 429:         }
 430: 
 431:         return true;
 432:     }
 433: 
 434:     /**
 435:      * Teaser allows to get a list of ids in which article content is searched
 436:      * in article like 1,2,5,6 the result with largest character count is
 437:      * returned
 438:      *
 439:      * @param cApiArticleLanguage $article - CONTENIDO article object
 440:      * @param string $contentTypeName - Name of Content type to extract
 441:      *        informations from
 442:      * @param string $ids - list of ids to search in
 443:      * @return string - largest result of content
 444:      */
 445:     private function _getArtContent(cApiArticleLanguage &$article, $contentTypeName, $ids) {
 446:         $this->_initCmsTypes();
 447: 
 448:         $return = '';
 449:         // split ids, if there is only one id, array has only one place filled,
 450:         // that is also ok
 451:         foreach (explode(',', $ids) as $currentId) {
 452:             if ($this->_forwardTypes[$contentTypeName] != "") {
 453:                 $contentTypeName = $this->_forwardTypes[$contentTypeName];
 454:             }
 455:             $return .= ' ' . $article->getContent($contentTypeName, $currentId);
 456:         }
 457: 
 458:         return $return;
 459:     }
 460: 
 461:     /**
 462:      * When a HTML Code is given for a Teaser image try to find a image in this
 463:      * code and generate
 464:      * Teaser image on that basis
 465:      *
 466:      * @param string $content - HTML string to search image in
 467:      * @return img tag containing scaled image
 468:      */
 469:     private function _extractImage($content) {
 470:         $image = array();
 471: 
 472:         // search an image tag
 473:         $regEx = "/<img[^>]*?>.*?/i";
 474: 
 475:         $match = array();
 476:         preg_match($regEx, $content, $match);
 477: 
 478:         // if found extract its src content
 479:         $regEx = "/(src)(=)(['\"]?)([^\"']*)(['\"]?)/i";
 480:         $img = array();
 481:         preg_match($regEx, $match[0], $img);
 482: 
 483:         // check if this image lies in upload folder
 484:         $pos = strrpos($img[4], $this->_cfgClient[$this->_client]['upload']);
 485:         if (!is_bool($pos)) {
 486:             // if it is generate full internal path to image and scale it for
 487:             // display using class internal function getImage()
 488:             $file = $this->_cfgClient[$this->_client]['path']['frontend'] . $img[4];
 489:             $image = $this->_getImage($file, $this->_settings['teaser_image_width'], $this->_settings['teaser_image_height'], $this->_settings['teaser_image_crop'], true);
 490:         }
 491: 
 492:         return $image;
 493:     }
 494: 
 495:     /**
 496:      * Function gets path to an image of base of idupload in CONTENIDO,
 497:      * scales this image on basis of teaser settings and returns path to
 498:      * scaled image.
 499:      * It is also possible to give path to image directly,
 500:      * in this case set fourth parameter to true
 501:      *
 502:      * @param integer $image - idupl of image to use for teaser
 503:      * @param integer $maxX - maximum image width
 504:      * @param integer $maxY - maximum image height
 505:      * @param boolean $isFile - in case of a direct file path retrival from
 506:      *        database is not needed
 507:      * @return string - <img> tag contains scaled image
 508:      */
 509:     private function _getImage($image, $maxX, $maxY, $cropped, $isFile = false) {
 510:         $content = '';
 511:         $return = array();
 512: 
 513:         if ($cropped == 'true') {
 514:             $cropped = true;
 515:         } else {
 516:             $cropped = false;
 517:         }
 518: 
 519:         // check if there is a need to get image path
 520:         if ($isFile == false) {
 521:             $upload = new cApiUpload($image);
 522:             $dirname = $upload->get('dirname');
 523:             $filename = $upload->get('filename');
 524:             if (!empty($dirname) && !empty($filename)) {
 525:                 $teaserImage = $this->_cfgClient[$this->_client]['path']['frontend'] . 'upload/' . $dirname . $filename;
 526:             }
 527:         } else {
 528:             $teaserImage = $image;
 529:         }
 530: 
 531:         // scale image if exists and return it
 532:         if (file_exists($teaserImage)) {
 533:             // Scale Image using cApiImgScale
 534:             $imgSrc = cApiImgScale($teaserImage, $maxX, $maxY, $cropped);
 535: 
 536:             if ($this->_useXHTML == 'true') {
 537:                 $letter = ' /';
 538:             } else {
 539:                 $letter = '';
 540:             }
 541: 
 542:             // Put Image into the teasertext
 543:             $content = '<img alt="" src="' . $imgSrc . '" class="teaser_image"' . $letter . '>' . $content;
 544:         }
 545: 
 546:         $return['element'] = $content;
 547:         $return['src'] = $imgSrc;
 548: 
 549:         return $return;
 550:     }
 551: 
 552:     /**
 553:      * Generates the code which should be shown if this content type is edited.
 554:      *
 555:      * @return string escaped HTML code which should be shown if content type is
 556:      *         edited
 557:      */
 558:     public function generateEditCode() {
 559:         $this->_initCmsTypes();
 560: 
 561:         $template = new cTemplate();
 562:         // Set some values into javascript for a better handling
 563:         $template->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
 564:         $template->set('s', 'ID', $this->_id);
 565:         $template->set('s', 'IDARTLANG', $this->_idArtLang);
 566:         $template->set('s', 'CONTENIDO', $_REQUEST['contenido']);
 567:         $template->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
 568: 
 569:         $templateTabs = new cTemplate();
 570:         $templateTabs->set('s', 'PREFIX', $this->_prefix);
 571: 
 572:         // create code for general tab
 573:         $templateTabs->set('d', 'TAB_ID', 'general');
 574:         $templateTabs->set('d', 'TAB_CLASS', 'general');
 575:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabGeneral());
 576:         $templateTabs->next();
 577: 
 578:         // create code for advanced tab
 579:         $templateTabs->set('d', 'TAB_ID', 'advanced');
 580:         $templateTabs->set('d', 'TAB_CLASS', 'advanced');
 581:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabAdvanced());
 582:         $templateTabs->next();
 583: 
 584:         // create code for manual tab
 585:         $templateTabs->set('d', 'TAB_ID', 'manual');
 586:         $templateTabs->set('d', 'TAB_CLASS', 'manual');
 587:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabManual());
 588:         $templateTabs->next();
 589: 
 590:         $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
 591: 
 592:         // construct the top code of the template
 593:         $templateTop = new cTemplate();
 594:         $templateTop->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
 595:         $templateTop->set('s', 'ICON', 'images/isstart0.gif');
 596:         $templateTop->set('s', 'ID', $this->_id);
 597:         $templateTop->set('s', 'PREFIX', $this->_prefix);
 598:         $templateTop->set('s', 'HEADLINE', i18n('Teaser settings'));
 599:         $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
 600: 
 601:         // define the available tabs
 602:         $tabMenu = array(
 603:             'general' => i18n('Automatic'),
 604:             'advanced' => i18n('Manual'),
 605:             'manual' => i18n('Settings')
 606:         );
 607: 
 608:         // construct the bottom code of the template
 609:         $templateBottom = new cTemplate();
 610:         $templateBottom->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
 611:         $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
 612:         $templateBottom->set('s', 'ID', $this->_id);
 613:         $templateBottom->set('s', 'PREFIX', $this->_prefix);
 614:         $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
 615:         $templateBottom->set('s', 'CONTENIDO', $_REQUEST['contenido']);
 616:         $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
 617:         $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
 618:         $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsTeaser.js');
 619:         $templateBottom->set('s', 'JS_CLASS_NAME', 'cContentTypeTeaser');
 620:         $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
 621: 
 622:         // construct the whole template code
 623:         $code = $this->generateViewCode();
 624:         $code .= $this->_encodeForOutput($codeTop);
 625:         $code .= $this->_generateTabMenuCode($tabMenu);
 626:         $code .= $this->_encodeForOutput($codeTabs);
 627:         $code .= $this->_generateActionCode();
 628:         $code .= $this->_encodeForOutput($codeBottom);
 629: 
 630:         return $code;
 631:     }
 632: 
 633:     /**
 634:      * Gets all currenty avariable content types and their ids
 635:      * from database and store it into class variable aCMSTypes.
 636:      * Because this information is used multiple times, this causes a better
 637:      * performance than gettting it seperately
 638:      *
 639:      * @return void
 640:      */
 641:     private function _initCmsTypes() {
 642:         if (!empty($this->_cmsTypes)) {
 643:             return;
 644:         }
 645: 
 646:         $this->_cmsTypes = array();
 647: 
 648:         $sql = 'SELECT * FROM ' . $this->_cfg['tab']['type'] . ' ORDER BY type';
 649:         $db = cRegistry::getDb();
 650:         $db->query($sql);
 651:         while ($db->nextRecord()) {
 652:             if (in_array($db->f('type'), $this->_ignoreTypes)) { // we do not
 653:                                                                  // want certain
 654:                                                                  // content
 655:                                                                  // types
 656:                 continue;
 657:             }
 658:             $this->_cmsTypes[$db->f('idtype')] = $db->f('type');
 659:         }
 660:     }
 661: 
 662:     /**
 663:      * Generates code for the general tab in which various settings can be made.
 664:      *
 665:      * @return string - the code for the general tab
 666:      */
 667:     private function _generateTabGeneral() {
 668:         // define a wrapper which contains the whole content of the general tab
 669:         $wrapper = new cHTMLDiv();
 670:         $wrapperContent = array();
 671: 
 672:         // $wrapperContent[] = new cHTMLParagraph(i18n('General settings'),
 673:         // 'head_sub');
 674:         $wrapperContent[] = new cHTMLLabel(i18n('Teaser title'), 'teaser_title_' . $this->_id);
 675:         $wrapperContent[] = new cHTMLTextbox('teaser_title_' . $this->_id, $this->_settings['teaser_title'], '', '', 'teaser_title_' . $this->_id);
 676:         $wrapperContent[] = new cHTMLLabel(i18n('Source category'), 'teaser_category_' . $this->_id);
 677:         $wrapperContent[] = buildCategorySelect('teaser_category_' . $this->_id, $this->_settings['teaser_category'], 0);
 678:         $wrapperContent[] = new cHTMLLabel(i18n('Number of articles'), 'teaser_count_' . $this->_id);
 679:         $wrapperContent[] = $this->_generateCountSelect();
 680: 
 681:         $wrapperContent[] = new cHTMLLabel(i18n("TEASER_START_ARTICLE"), 'teaser_start_' . $this->_id);
 682:         $wrapperContent[] = new cHTMLCheckbox('teaser_start_' . $this->_id, '', 'teaser_start_' . $this->_id, ($this->_settings['teaser_start'] == 'true'));
 683: 
 684:         $wrapperContent[] = new cHTMLLabel(i18n("Teaser sort"), 'teaser_sort_' . $this->_id);
 685:         $wrapperContent[] = $this->_generateSortSelect();
 686:         $wrapperContent[] = new cHTMLLabel(i18n("Sort order"), 'teaser_sort_order_' . $this->_id);
 687:         $wrapperContent[] = $this->_generateSortOrderSelect();
 688: 
 689:         $wrapper->setContent($wrapperContent);
 690:         return $wrapper->render();
 691:     }
 692: 
 693:     /**
 694:      * Generats a select box for setting number of articles which should be
 695:      * displayed in teaser as a maximum.
 696:      * Only important in editmode.
 697:      *
 698:      * @return html string of select box
 699:      */
 700:     private function _generateCountSelect() {
 701:         $htmlSelect = new cHTMLSelectElement('teaser_count_' . $this->_id, '', 'teaser_count_' . $this->_id);
 702: 
 703:         // set please chose option element
 704:         $htmlSelectOption = new cHTMLOptionElement(i18n('Please choose'), '', true);
 705:         $htmlSelect->appendOptionElement($htmlSelectOption);
 706: 
 707:         // generate a select box containing count 1 to 20 for maximum teaser
 708:         // count
 709:         for ($i = 1; $i <= 20; $i++) {
 710:             $htmlSelectOption = new cHTMLOptionElement($i, $i, false);
 711:             $htmlSelect->appendOptionElement($htmlSelectOption);
 712:         }
 713: 
 714:         // set default value
 715:         $htmlSelect->setDefault($this->_settings['teaser_count']);
 716: 
 717:         return $htmlSelect->render();
 718:     }
 719: 
 720:     /**
 721:      * Generats a select box for setting teaser style
 722:      * currently two seperate teaser templates were supported
 723:      *
 724:      * @return html string of select box
 725:      */
 726:     private function _generateStyleSelect() {
 727:         $htmlSelect = new cHTMLSelectElement('teaser_style_' . $this->_id, '', 'teaser_style_' . $this->_id);
 728: 
 729:         // set please chose option element
 730:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 731:         $htmlSelect->appendOptionElement($htmlSelectOption);
 732: 
 733:         // set other avariable options manually
 734:         $htmlSelectOption = new cHTMLOptionElement(i18n("Slider style"), 'cms_teaser_slider.html', false);
 735:         $htmlSelect->appendOptionElement($htmlSelectOption);
 736: 
 737:         $htmlSelectOption = new cHTMLOptionElement(i18n("Image style"), 'cms_teaser_image.html', false);
 738:         $htmlSelect->appendOptionElement($htmlSelectOption);
 739: 
 740:         $htmlSelectOption = new cHTMLOptionElement(i18n("Text style"), 'cms_teaser_text.html', false);
 741:         $htmlSelect->appendOptionElement($htmlSelectOption);
 742: 
 743:         $htmlSelectOption = new cHTMLOptionElement(i18n("Blog style"), 'cms_teaser_blog.html', false);
 744:         $htmlSelect->appendOptionElement($htmlSelectOption);
 745: 
 746:         $additionalOptions = getEffectiveSettingsByType('cms_teaser');
 747:         foreach ($additionalOptions as $sLabel => $sTemplate) {
 748:             $htmlSelectOption = new cHTMLOptionElement($sLabel, $sTemplate, false);
 749:             $htmlSelect->appendOptionElement($htmlSelectOption);
 750:         }
 751: 
 752:         // set default value
 753:         $htmlSelect->setDefault($this->_settings['teaser_style']);
 754: 
 755:         return $htmlSelect->render();
 756:     }
 757: 
 758:     /**
 759:      * Teaser gets informations from other articles and their content typs
 760:      * Function builds a select box in which coresponding cms type can be
 761:      * selected
 762:      * after that a text box is rendered for setting id for this conent type to
 763:      * get
 764:      * informations from.
 765:      * This function is used three times for source defintion of
 766:      * headline text and teaserimage
 767:      *
 768:      * @param string $selectName - name of input elements
 769:      * @param string $selected - value of select box which is selected
 770:      * @param string $value - current value of text box
 771:      * @return html string of select box
 772:      */
 773:     private function _generateTypeSelect($selectName, $selected, $value) {
 774:         // make sure that the ID is at the end of the form field name
 775:         $inputName = str_replace('_' . $this->_id, '_count_' . $this->_id, $selectName);
 776:         // generate textbox for content type id
 777:         $htmlInput = new cHTMLTextbox($inputName, $value, '', '', $inputName, false, '', '', 'teaser_type_count');
 778: 
 779:         // generate content type select
 780:         $htmlSelect = new cHTMLSelectElement($selectName, '', $selectName);
 781:         $htmlSelect->setClass('teaser_type_select');
 782: 
 783:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 784:         $htmlSelect->addOptionElement(0, $htmlSelectOption);
 785: 
 786:         // use $this->_cmsTypes as basis for this select box which contains all
 787:         // avariable content types in system
 788:         foreach ($this->_cmsTypes as $key => $value) {
 789:             if ($this->_forwardTypes[$value] != "") {
 790:                 continue;
 791:             }
 792:             $htmlSelectOption = new cHTMLOptionElement($value, $value, false);
 793:             $htmlSelect->addOptionElement($key, $htmlSelectOption);
 794:         }
 795: 
 796:         // set default value
 797:         $htmlSelect->setDefault($selected);
 798: 
 799:         return $htmlSelect->render() . $htmlInput->render();
 800:     }
 801: 
 802:     /**
 803:      * Generates code for the advanced tab in which various advanced settings
 804:      * can be made.
 805:      *
 806:      * @return string - the code for the advanced tab
 807:      */
 808:     private function _generateTabAdvanced() {
 809:         // define a wrapper which contains the whole content of the advanced tab
 810:         $wrapper = new cHTMLDiv();
 811:         $wrapperContent = array();
 812: 
 813:         // $wrapperContent[] = new cHTMLParagraph(i18n('Manual teaser
 814:         // settings'), 'head_sub');
 815:         $wrapperContent[] = new cHTMLLabel(i18n('Manual teaser'), 'teaser_manual_' . $this->_id);
 816:         $wrapperContent[] = new cHTMLCheckbox('teaser_manual_' . $this->_id, '', 'teaser_manual_' . $this->_id, ($this->_settings['teaser_manual'] == 'true'));
 817: 
 818:         // $wrapperContent[] = new cHTMLParagraph(i18n('Add article'),
 819:         // 'head_sub');
 820:         $wrapperContent[] = new cHTMLLabel(i18n('Category'), 'teaser_cat_' . $this->_id);
 821:         $wrapperContent[] = buildCategorySelect('teaser_cat_' . $this->_id, 0, 0);
 822:         $wrapperContent[] = new cHTMLLabel(i18n('Article'), 'teaser_art_' . $this->_id);
 823:         $wrapperContent[] = buildArticleSelect('teaser_art_' . $this->_id, 0, 0);
 824: 
 825:         $wrapperContent[] = new cHTMLLabel(i18n('Add'), 'add_art_' . $this->_id);
 826:         $image = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/but_art_new.gif');
 827:         $image->setAttribute('id', 'add_art_' . $this->_id);
 828:         $image->appendStyleDefinition('cursor', 'pointer');
 829:         $wrapperContent[] = $image;
 830: 
 831:         $wrapperContent[] = new cHTMLParagraph(i18n('Included articles'), 'head_sub');
 832:         $selectElement = new cHTMLSelectElement('teaser_manual_art_' . $this->_id, '', 'teaser_manual_art_' . $this->_id, false, '', '', 'manual');
 833:         $selectElement->setAttribute('size', '4');
 834:         $selectElement->setAttribute('multiple', 'multiple');
 835:         // there can be one or multiple selected articles
 836:         if (is_array($this->_settings['teaser_manual_art'])) {
 837:             foreach ($this->_settings['teaser_manual_art'] as $index => $idArt) {
 838:                 $option = new cHTMLOptionElement($this->_getArtName($idArt), $idArt, true);
 839:                 $selectElement->addOptionElement($index, $option);
 840:             }
 841:         } else {
 842:             // check if the article really exists
 843:             $artName = $this->_getArtName($this->_settings['teaser_manual_art']);
 844:             if ($artName != i18n('Unknown article')) {
 845:                 $option = new cHTMLOptionElement($artName, $this->_settings['teaser_manual_art'], true);
 846:                 $selectElement->addOptionElement(0, $option);
 847:             }
 848:         }
 849:         $wrapperContent[] = $selectElement;
 850: 
 851:         $wrapperContent[] = new cHTMLLabel(i18n("Delete"), 'del_art_' . $this->_id);
 852:         $image = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/delete.gif');
 853:         $image->setAttribute('id', 'del_art_' . $this->_id);
 854:         $image->appendStyleDefinition('cursor', 'pointer');
 855:         $wrapperContent[] = $image;
 856: 
 857:         $wrapper->setContent($wrapperContent);
 858:         return $wrapper->render();
 859:     }
 860: 
 861:     /**
 862:      * Function which generated a select box for setting teaser
 863:      * sort argument
 864:      *
 865:      * @return html string of select box
 866:      */
 867:     private function _generateSortSelect() {
 868:         $htmlSelect = new cHTMLSelectElement('teaser_sort_' . $this->_id, '', 'teaser_sort_' . $this->_id);
 869: 
 870:         // set please chose option element
 871:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 872:         $htmlSelect->appendOptionElement($htmlSelectOption);
 873: 
 874:         // set other avariable options manually
 875:         $htmlSelectOption = new cHTMLOptionElement(i18n("Sort sequence"), 'sortsequence', false);
 876:         $htmlSelect->appendOptionElement($htmlSelectOption);
 877: 
 878:         $htmlSelectOption = new cHTMLOptionElement(i18n("Creation date"), 'creationdate', false);
 879:         $htmlSelect->appendOptionElement($htmlSelectOption);
 880: 
 881:         $htmlSelectOption = new cHTMLOptionElement(i18n("Published date"), 'publisheddate', false);
 882:         $htmlSelect->appendOptionElement($htmlSelectOption);
 883: 
 884:         $htmlSelectOption = new cHTMLOptionElement(i18n("Modification date"), 'modificationdate', false);
 885:         $htmlSelect->appendOptionElement($htmlSelectOption);
 886: 
 887:         // set default value
 888:         $htmlSelect->setDefault($this->_settings['teaser_sort']);
 889: 
 890:         return $htmlSelect->render();
 891:     }
 892: 
 893:     /**
 894:      * Function which generated a select box for setting teaser
 895:      * sort order argument
 896:      *
 897:      * @return html string of select box
 898:      */
 899:     private function _generateSortOrderSelect() {
 900:         $htmlSelect = new cHTMLSelectElement('teaser_sort_order_' . $this->_id, '', 'teaser_sort_order_' . $this->_id);
 901: 
 902:         // set please chose option element
 903:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 904:         $htmlSelect->appendOptionElement($htmlSelectOption);
 905: 
 906:         // set other avariable options manually
 907:         $htmlSelectOption = new cHTMLOptionElement(i18n("Ascending"), 'asc', false);
 908:         $htmlSelect->appendOptionElement($htmlSelectOption);
 909: 
 910:         $htmlSelectOption = new cHTMLOptionElement(i18n("Descending"), 'desc', false);
 911:         $htmlSelect->appendOptionElement($htmlSelectOption);
 912: 
 913:         // set default value
 914:         $htmlSelect->setDefault($this->_settings['teaser_sort_order']);
 915: 
 916:         return $htmlSelect->render();
 917:     }
 918: 
 919:     /**
 920:      * Function which provides select option for cropping teaser images
 921:      *
 922:      * @return html string of select box
 923:      */
 924:     private function _generateCropSelect() {
 925:         $htmlSelect = new cHTMLSelectElement('teaser_image_crop_' . $this->_id, '', 'teaser_image_crop_' . $this->_id);
 926: 
 927:         // set please chose option element
 928:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 929:         $htmlSelect->appendOptionElement($htmlSelectOption);
 930: 
 931:         // set other avariable options manually
 932:         $htmlSelectOption = new cHTMLOptionElement(i18n("Scaled"), 'false', false);
 933:         $htmlSelect->appendOptionElement($htmlSelectOption);
 934: 
 935:         $htmlSelectOption = new cHTMLOptionElement(i18n("Cropped"), 'true', false);
 936:         $htmlSelect->appendOptionElement($htmlSelectOption);
 937: 
 938:         // set default value
 939:         $htmlSelect->setDefault($this->_settings['teaser_image_crop']);
 940: 
 941:         return $htmlSelect->render();
 942:     }
 943: 
 944:     /**
 945:      * Generates code for the manual tab in which various settings for the
 946:      * manual teaser can be made.
 947:      *
 948:      * @return string - the code for the manual tab
 949:      */
 950:     private function _generateTabManual() {
 951:         // define a wrapper which contains the whole content of the manual tab
 952:         $wrapper = new cHTMLDiv();
 953:         $wrapperContent = array();
 954: 
 955:         $wrapperContent[] = new cHTMLParagraph(i18n("Content visualisation"), 'head_sub');
 956:         $wrapperContent[] = new cHTMLLabel(i18n("Teaser visualisation"), 'teaser_style');
 957:         $wrapperContent[] = $this->_generateStyleSelect();
 958:         $wrapperContent[] = new cHTMLLabel(i18n("Teaser filter"), 'teaser_filter_' . $this->_id);
 959:         $wrapperContent[] = new cHTMLTextbox('teaser_filter_' . $this->_id, $this->_settings['teaser_filter'], '', '', 'teaser_filter_' . $this->_id);
 960:         $wrapperContent[] = new cHTMLLabel(i18n('Character length'), 'teaser_character_limit_' . $this->_id);
 961:         $wrapperContent[] = new cHTMLTextbox('teaser_character_limit_' . $this->_id, $this->_settings['teaser_character_limit'], '', '', 'teaser_character_limit_' . $this->_id);
 962: 
 963:         $wrapperContent[] = new cHTMLParagraph(i18n("Pictures"), 'head_sub');
 964:         $wrapperContent[] = new cHTMLLabel(i18n('Image width'), 'teaser_image_width_' . $this->_id);
 965:         $wrapperContent[] = new cHTMLTextbox('teaser_image_width_' . $this->_id, $this->_settings['teaser_image_width'], '', '', 'teaser_image_width_' . $this->_id);
 966:         $wrapperContent[] = new cHTMLLabel(i18n('Image height'), 'teaser_image_height_' . $this->_id);
 967:         $wrapperContent[] = new cHTMLTextbox('teaser_image_height_' . $this->_id, $this->_settings['teaser_image_height'], '', '', 'teaser_image_height_' . $this->_id);
 968:         $wrapperContent[] = new cHTMLLabel(i18n('Image scale'), 'teaser_image_crop_' . $this->_id);
 969:         $wrapperContent[] = $this->_generateCropSelect();
 970: 
 971:         $wrapperContent[] = new cHTMLParagraph(i18n("Content types"), 'head_sub');
 972:         $wrapperContent[] = new cHTMLLabel(i18n("Headline source"), 'teaser_source_head_' . $this->_id);
 973:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_head_' . $this->_id, $this->_settings['teaser_source_head'], $this->_settings['teaser_source_head_count']);
 974:         $wrapperContent[] = new cHTMLLabel(i18n("Text source"), 'teaser_source_text_' . $this->_id);
 975:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_text_' . $this->_id, $this->_settings['teaser_source_text'], $this->_settings['teaser_source_text_count']);
 976:         $wrapperContent[] = new cHTMLLabel(i18n('Image source'), 'teaser_source_image_' . $this->_id);
 977:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_image_' . $this->_id, $this->_settings['teaser_source_image'], $this->_settings['teaser_source_image_count']);
 978:         $wrapperContent[] = new cHTMLLabel(i18n('Date source'), 'teaser_source_date_' . $this->_id);
 979:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_date_' . $this->_id, $this->_settings['teaser_source_date'], $this->_settings['teaser_source_date_count']);
 980: 
 981:         $wrapper->setContent($wrapperContent);
 982:         return $wrapper->render();
 983:     }
 984: 
 985:     /**
 986:      * Function retrives name of an article by its id from database
 987:      *
 988:      * @param integer $idArt - CONTENIDO article id
 989:      * @return string - name of article
 990:      */
 991:     private function _getArtName($idArt) {
 992:         $article = new cApiArticleLanguage();
 993:         $article->loadByArticleAndLanguageId((int) $idArt, $this->_lang);
 994: 
 995:         $title = $article->get('title');
 996:         if ($article->isLoaded() && !empty($title)) {
 997:             return $article->get('title');
 998:         } else {
 999:             return i18n('Unknown article');
1000:         }
1001:     }
1002: 
1003: }
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0