1: <?php
   2:    3:    4:    5:    6:    7:    8:    9:   10:   11:   12:   13:   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:   22:   23:   24:   25:   26: 
  27: class cContentTypeTeaser extends cContentTypeAbstractTabbed {
  28: 
  29:       30:   31:   32:   33:   34:   35: 
  36:     private $_cmsTypes;
  37: 
  38:       39:   40:   41:   42:   43:   44: 
  45:     private $_ignoreTypes = array();
  46: 
  47:       48:   49:   50:   51:   52:   53: 
  54:     private $_forwardTypes = array(
  55:         "CMS_EASYIMG" => "CMS_IMGEDITOR",
  56:         "CMS_IMG" => "CMS_IMGEDITOR",
  57:         "CMS_LINK" => "CMS_LINKEDITOR"
  58:     );
  59: 
  60:       61:   62:   63:   64:   65: 
  66:     protected static $_translations = array(
  67:         "MORE"
  68:     );
  69: 
  70:       71:   72: 
  73:     protected $iteration = 0;
  74: 
  75:       76:   77:   78:   79:   80:   81:   82:   83:   84:   85: 
  86:     public function __construct($rawSettings, $id, array $contentTypes) {
  87:         
  88:         
  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:         
 120:         
 121:         
 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:  131:  132:  133:  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:  145:  146:  147:  148: 
 149:     private function _setDefaultValues() {
 150:         
 151:         if ((int) $this->_settings['teaser_character_limit'] == 0) {
 152:             $this->_settings['teaser_character_limit'] = 120;
 153:         }
 154: 
 155:         
 156:         if ((int) $this->_settings['teaser_count'] == 0) {
 157:             $this->_settings['teaser_count'] = 6;
 158:         }
 159: 
 160:         
 161:         if (strlen($this->_settings['teaser_sort']) == 0) {
 162:             $this->_settings['teaser_sort'] = 'creationdate';
 163:         }
 164: 
 165:         
 166:         if (strlen($this->_settings['teaser_style']) == 0) {
 167:             $this->_settings['teaser_style'] = 'cms_teaser_slider.html';
 168:         }
 169: 
 170:         
 171:         if ((int) $this->_settings['teaser_image_width'] == 0) {
 172:             $this->_settings['teaser_image_width'] = 100;
 173:         }
 174: 
 175:         
 176:         if ((int) $this->_settings['teaser_image_height'] == 0) {
 177:             $this->_settings['teaser_image_height'] = 75;
 178:         }
 179: 
 180:         
 181:         if (strlen($this->_settings['teaser_source_head']) == 0) {
 182:             $this->_settings['teaser_source_head'] = 'CMS_HTMLHEAD';
 183:         }
 184: 
 185:         
 186:         if (strlen($this->_settings['teaser_source_text']) == 0) {
 187:             $this->_settings['teaser_source_text'] = 'CMS_HTML';
 188:         }
 189: 
 190:         
 191:         if (strlen($this->_settings['teaser_source_image']) == 0) {
 192:             $this->_settings['teaser_source_image'] = 'CMS_IMG';
 193:         }
 194: 
 195:         
 196:         if (strlen($this->_settings['teaser_source_date']) == 0) {
 197:             $this->_settings['teaser_source_date'] = 'CMS_DATE';
 198:         }
 199: 
 200:         
 201:         if (strlen($this->_settings['teaser_sort_order']) == 0) {
 202:             $this->_settings['teaser_sort_order'] = 'asc';
 203:         }
 204: 
 205:         
 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:  213:  214:  215:  216:  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:  231:  232:  233: 
 234:     public function getConfiguredArticles() {
 235:         $articles = array();
 236:         $articles = $this->generateTeaserCode(true);
 237: 
 238:         return $articles;
 239:     }
 240: 
 241:      242:  243:  244:  245:  246:  247:  248: 
 249:     public function generateTeaserCode($returnAsArray = false) {
 250:         global $contenido;
 251: 
 252:         $articles = array();
 253: 
 254:         $template = new cTemplate();
 255:         
 256:         $template->set('s', 'TITLE', $this->_settings['teaser_title']);
 257: 
 258:         
 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:                 
 269:                 
 270:                 foreach ($manualArts as $idArt) {
 271:                     $article = new cApiArticleLanguage();
 272:                     $article->loadByArticleAndLanguageId($idArt, $this->_lang);
 273: 
 274:                     
 275:                     if ($returnAsArray == false && $this->_fillTeaserTemplateEntry($article, $template)) {
 276:                         $i++;
 277:                         
 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:             
 294:             
 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:         
 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:  335:  336:  337:  338:  339:  340: 
 341:     private function _fillTeaserTemplateEntry(cApiArticleLanguage $article, cTemplate &$template) {
 342:         global $contenido;
 343: 
 344:         
 345:         
 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:             
 356:             
 357:             
 358:             
 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:             
 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:             
 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:             
 380:             
 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:             
 400:             $date = strip_tags($date);
 401: 
 402:             
 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:  436:  437:  438:  439:  440:  441:  442:  443:  444: 
 445:     private function _getArtContent(cApiArticleLanguage &$article, $contentTypeName, $ids) {
 446:         $this->_initCmsTypes();
 447: 
 448:         $return = '';
 449:         
 450:         
 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:  463:  464:  465:  466:  467:  468: 
 469:     private function ($content) {
 470:         $image = array();
 471: 
 472:         
 473:         $regEx = "/<img[^>]*?>.*?/i";
 474: 
 475:         $match = array();
 476:         preg_match($regEx, $content, $match);
 477: 
 478:         
 479:         $regEx = "/(src)(=)(['\"]?)([^\"']*)(['\"]?)/i";
 480:         $img = array();
 481:         preg_match($regEx, $match[0], $img);
 482: 
 483:         
 484:         $pos = strrpos($img[4], $this->_cfgClient[$this->_client]['upload']);
 485:         if (!is_bool($pos)) {
 486:             
 487:             
 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:  497:  498:  499:  500:  501:  502:  503:  504:  505:  506:  507:  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:         
 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:         
 532:         if (file_exists($teaserImage)) {
 533:             
 534:             $imgSrc = cApiImgScale($teaserImage, $maxX, $maxY, $cropped);
 535: 
 536:             if ($this->_useXHTML == 'true') {
 537:                 $letter = ' /';
 538:             } else {
 539:                 $letter = '';
 540:             }
 541: 
 542:             
 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:  554:  555:  556:  557: 
 558:     public function generateEditCode() {
 559:         $this->_initCmsTypes();
 560: 
 561:         $template = new cTemplate();
 562:         
 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:         
 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:         
 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:         
 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:         
 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:         
 602:         $tabMenu = array(
 603:             'general' => i18n('Automatic'),
 604:             'advanced' => i18n('Manual'),
 605:             'manual' => i18n('Settings')
 606:         );
 607: 
 608:         
 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:         
 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:  635:  636:  637:  638:  639:  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:             
 653:             if (in_array($db->f('type'), $this->_ignoreTypes)) {
 654:                 continue;
 655:             }
 656:             $this->_cmsTypes[$db->f('idtype')] = $db->f('type');
 657:         }
 658:     }
 659: 
 660:      661:  662:  663:  664: 
 665:     private function _generateTabGeneral() {
 666:         
 667:         $wrapper = new cHTMLDiv();
 668:         $wrapperContent = array();
 669: 
 670:         
 671:         
 672:         $wrapperContent[] = new cHTMLLabel(i18n('Teaser title'), 'teaser_title_' . $this->_id);
 673:         $wrapperContent[] = new cHTMLTextbox('teaser_title_' . $this->_id, $this->_settings['teaser_title'], '', '', 'teaser_title_' . $this->_id);
 674:         $wrapperContent[] = new cHTMLLabel(i18n('Source category'), 'teaser_category_' . $this->_id);
 675:         $wrapperContent[] = buildCategorySelect('teaser_category_' . $this->_id, $this->_settings['teaser_category'], 0);
 676:         $wrapperContent[] = new cHTMLLabel(i18n('Number of articles'), 'teaser_count_' . $this->_id);
 677:         $wrapperContent[] = $this->_generateCountSelect();
 678: 
 679:         $wrapperContent[] = new cHTMLLabel(i18n("TEASER_START_ARTICLE"), 'teaser_start_' . $this->_id);
 680:         $wrapperContent[] = new cHTMLCheckbox('teaser_start_' . $this->_id, '', 'teaser_start_' . $this->_id, ($this->_settings['teaser_start'] == 'true'));
 681: 
 682:         $wrapperContent[] = new cHTMLLabel(i18n("Teaser sort"), 'teaser_sort_' . $this->_id);
 683:         $wrapperContent[] = $this->_generateSortSelect();
 684:         $wrapperContent[] = new cHTMLLabel(i18n("Sort order"), 'teaser_sort_order_' . $this->_id);
 685:         $wrapperContent[] = $this->_generateSortOrderSelect();
 686: 
 687:         $wrapper->setContent($wrapperContent);
 688:         return $wrapper->render();
 689:     }
 690: 
 691:      692:  693:  694:  695:  696:  697: 
 698:     private function _generateCountSelect() {
 699:         $htmlSelect = new cHTMLSelectElement('teaser_count_' . $this->_id, '', 'teaser_count_' . $this->_id);
 700: 
 701:         
 702:         $htmlSelectOption = new cHTMLOptionElement(i18n('Please choose'), '', true);
 703:         $htmlSelect->appendOptionElement($htmlSelectOption);
 704: 
 705:         
 706:         
 707:         for ($i = 1; $i <= 20; $i++) {
 708:             $htmlSelectOption = new cHTMLOptionElement($i, $i, false);
 709:             $htmlSelect->appendOptionElement($htmlSelectOption);
 710:         }
 711: 
 712:         
 713:         $htmlSelect->setDefault($this->_settings['teaser_count']);
 714: 
 715:         return $htmlSelect->render();
 716:     }
 717: 
 718:      719:  720:  721:  722:  723: 
 724:     private function _generateStyleSelect() {
 725:         $htmlSelect = new cHTMLSelectElement('teaser_style_' . $this->_id, '', 'teaser_style_' . $this->_id);
 726: 
 727:         
 728:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 729:         $htmlSelect->appendOptionElement($htmlSelectOption);
 730: 
 731:         
 732:         $htmlSelectOption = new cHTMLOptionElement(i18n("Slider style"), 'cms_teaser_slider.html', false);
 733:         $htmlSelect->appendOptionElement($htmlSelectOption);
 734: 
 735:         $htmlSelectOption = new cHTMLOptionElement(i18n("Image style"), 'cms_teaser_image.html', false);
 736:         $htmlSelect->appendOptionElement($htmlSelectOption);
 737: 
 738:         $htmlSelectOption = new cHTMLOptionElement(i18n("Text style"), 'cms_teaser_text.html', false);
 739:         $htmlSelect->appendOptionElement($htmlSelectOption);
 740: 
 741:         $htmlSelectOption = new cHTMLOptionElement(i18n("Blog style"), 'cms_teaser_blog.html', false);
 742:         $htmlSelect->appendOptionElement($htmlSelectOption);
 743: 
 744:         $additionalOptions = getEffectiveSettingsByType('cms_teaser');
 745:         foreach ($additionalOptions as $sLabel => $sTemplate) {
 746:             $htmlSelectOption = new cHTMLOptionElement($sLabel, $sTemplate, false);
 747:             $htmlSelect->appendOptionElement($htmlSelectOption);
 748:         }
 749: 
 750:         
 751:         $htmlSelect->setDefault($this->_settings['teaser_style']);
 752: 
 753:         return $htmlSelect->render();
 754:     }
 755: 
 756:      757:  758:  759:  760:  761:  762:  763:  764:  765:  766:  767:  768:  769:  770: 
 771:     private function _generateTypeSelect($selectName, $selected, $value) {
 772:         
 773:         $inputName = str_replace('_' . $this->_id, '_count_' . $this->_id, $selectName);
 774:         
 775:         $htmlInput = new cHTMLTextbox($inputName, $value, '', '', $inputName, false, '', '', 'teaser_type_count');
 776: 
 777:         
 778:         $htmlSelect = new cHTMLSelectElement($selectName, '', $selectName);
 779:         $htmlSelect->setClass('teaser_type_select');
 780: 
 781:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 782:         $htmlSelect->addOptionElement(0, $htmlSelectOption);
 783: 
 784:         
 785:         
 786:         foreach ($this->_cmsTypes as $key => $value) {
 787:             if ($this->_forwardTypes[$value] != "") {
 788:                 continue;
 789:             }
 790:             $htmlSelectOption = new cHTMLOptionElement($value, $value, false);
 791:             $htmlSelect->addOptionElement($key, $htmlSelectOption);
 792:         }
 793: 
 794:         
 795:         $htmlSelect->setDefault($selected);
 796: 
 797:         return $htmlSelect->render() . $htmlInput->render();
 798:     }
 799: 
 800:      801:  802:  803:  804:  805: 
 806:     private function _generateTabAdvanced() {
 807:         
 808:         $wrapper = new cHTMLDiv();
 809:         $wrapperContent = array();
 810: 
 811:         
 812:         
 813:         $wrapperContent[] = new cHTMLLabel(i18n('Manual teaser'), 'teaser_manual_' . $this->_id);
 814:         $wrapperContent[] = new cHTMLCheckbox('teaser_manual_' . $this->_id, '', 'teaser_manual_' . $this->_id, ($this->_settings['teaser_manual'] == 'true'));
 815: 
 816:         
 817:         
 818:         $wrapperContent[] = new cHTMLLabel(i18n('Category'), 'teaser_cat_' . $this->_id);
 819:         $wrapperContent[] = buildCategorySelect('teaser_cat_' . $this->_id, 0, 0);
 820:         $wrapperContent[] = new cHTMLLabel(i18n('Article'), 'teaser_art_' . $this->_id);
 821:         $wrapperContent[] = buildArticleSelect('teaser_art_' . $this->_id, 0, 0);
 822: 
 823:         $wrapperContent[] = new cHTMLLabel(i18n('Add'), 'add_art_' . $this->_id);
 824:         $image = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/but_art_new.gif');
 825:         $image->setAttribute('id', 'add_art_' . $this->_id);
 826:         $image->appendStyleDefinition('cursor', 'pointer');
 827:         $wrapperContent[] = $image;
 828: 
 829:         $wrapperContent[] = new cHTMLParagraph(i18n('Included articles'), 'head_sub');
 830:         $selectElement = new cHTMLSelectElement('teaser_manual_art_' . $this->_id, '', 'teaser_manual_art_' . $this->_id, false, '', '', 'manual');
 831:         $selectElement->setAttribute('size', '4');
 832:         $selectElement->setAttribute('multiple', 'multiple');
 833:         
 834:         if (is_array($this->_settings['teaser_manual_art'])) {
 835:             foreach ($this->_settings['teaser_manual_art'] as $index => $idArt) {
 836:                 $option = new cHTMLOptionElement($this->_getArtName($idArt), $idArt, true);
 837:                 $selectElement->addOptionElement($index, $option);
 838:             }
 839:         } else {
 840:             
 841:             $artName = $this->_getArtName($this->_settings['teaser_manual_art']);
 842:             if ($artName != i18n('Unknown article')) {
 843:                 $option = new cHTMLOptionElement($artName, $this->_settings['teaser_manual_art'], true);
 844:                 $selectElement->addOptionElement(0, $option);
 845:             }
 846:         }
 847:         $wrapperContent[] = $selectElement;
 848: 
 849:         $wrapperContent[] = new cHTMLLabel(i18n("Delete"), 'del_art_' . $this->_id);
 850:         $image = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/delete.gif');
 851:         $image->setAttribute('id', 'del_art_' . $this->_id);
 852:         $image->appendStyleDefinition('cursor', 'pointer');
 853:         $wrapperContent[] = $image;
 854: 
 855:         $wrapper->setContent($wrapperContent);
 856:         return $wrapper->render();
 857:     }
 858: 
 859:      860:  861:  862:  863:  864: 
 865:     private function _generateSortSelect() {
 866:         $htmlSelect = new cHTMLSelectElement('teaser_sort_' . $this->_id, '', 'teaser_sort_' . $this->_id);
 867: 
 868:         
 869:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 870:         $htmlSelect->appendOptionElement($htmlSelectOption);
 871: 
 872:         
 873:         $htmlSelectOption = new cHTMLOptionElement(i18n("Sort sequence"), 'sortsequence', false);
 874:         $htmlSelect->appendOptionElement($htmlSelectOption);
 875: 
 876:         $htmlSelectOption = new cHTMLOptionElement(i18n("Creation date"), 'creationdate', false);
 877:         $htmlSelect->appendOptionElement($htmlSelectOption);
 878: 
 879:         $htmlSelectOption = new cHTMLOptionElement(i18n("Published date"), 'publisheddate', false);
 880:         $htmlSelect->appendOptionElement($htmlSelectOption);
 881: 
 882:         $htmlSelectOption = new cHTMLOptionElement(i18n("Modification date"), 'modificationdate', false);
 883:         $htmlSelect->appendOptionElement($htmlSelectOption);
 884: 
 885:         
 886:         $htmlSelect->setDefault($this->_settings['teaser_sort']);
 887: 
 888:         return $htmlSelect->render();
 889:     }
 890: 
 891:      892:  893:  894:  895:  896: 
 897:     private function _generateSortOrderSelect() {
 898:         $htmlSelect = new cHTMLSelectElement('teaser_sort_order_' . $this->_id, '', 'teaser_sort_order_' . $this->_id);
 899: 
 900:         
 901:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 902:         $htmlSelect->appendOptionElement($htmlSelectOption);
 903: 
 904:         
 905:         $htmlSelectOption = new cHTMLOptionElement(i18n("Ascending"), 'asc', false);
 906:         $htmlSelect->appendOptionElement($htmlSelectOption);
 907: 
 908:         $htmlSelectOption = new cHTMLOptionElement(i18n("Descending"), 'desc', false);
 909:         $htmlSelect->appendOptionElement($htmlSelectOption);
 910: 
 911:         
 912:         $htmlSelect->setDefault($this->_settings['teaser_sort_order']);
 913: 
 914:         return $htmlSelect->render();
 915:     }
 916: 
 917:      918:  919:  920:  921: 
 922:     private function _generateCropSelect() {
 923:         $htmlSelect = new cHTMLSelectElement('teaser_image_crop_' . $this->_id, '', 'teaser_image_crop_' . $this->_id);
 924: 
 925:         
 926:         $htmlSelectOption = new cHTMLOptionElement(i18n("Please choose"), '', true);
 927:         $htmlSelect->appendOptionElement($htmlSelectOption);
 928: 
 929:         
 930:         $htmlSelectOption = new cHTMLOptionElement(i18n("Scaled"), 'false', false);
 931:         $htmlSelect->appendOptionElement($htmlSelectOption);
 932: 
 933:         $htmlSelectOption = new cHTMLOptionElement(i18n("Cropped"), 'true', false);
 934:         $htmlSelect->appendOptionElement($htmlSelectOption);
 935: 
 936:         
 937:         $htmlSelect->setDefault($this->_settings['teaser_image_crop']);
 938: 
 939:         return $htmlSelect->render();
 940:     }
 941: 
 942:      943:  944:  945:  946:  947: 
 948:     private function _generateTabManual() {
 949:         
 950:         $wrapper = new cHTMLDiv();
 951:         $wrapperContent = array();
 952: 
 953:         $wrapperContent[] = new cHTMLParagraph(i18n("Content visualisation"), 'head_sub');
 954:         $wrapperContent[] = new cHTMLLabel(i18n("Teaser visualisation"), 'teaser_style');
 955:         $wrapperContent[] = $this->_generateStyleSelect();
 956:         $wrapperContent[] = new cHTMLLabel(i18n("Teaser filter"), 'teaser_filter_' . $this->_id);
 957:         $wrapperContent[] = new cHTMLTextbox('teaser_filter_' . $this->_id, $this->_settings['teaser_filter'], '', '', 'teaser_filter_' . $this->_id);
 958:         $wrapperContent[] = new cHTMLLabel(i18n('Character length'), 'teaser_character_limit_' . $this->_id);
 959:         $wrapperContent[] = new cHTMLTextbox('teaser_character_limit_' . $this->_id, $this->_settings['teaser_character_limit'], '', '', 'teaser_character_limit_' . $this->_id);
 960: 
 961:         $wrapperContent[] = new cHTMLParagraph(i18n("Pictures"), 'head_sub');
 962:         $wrapperContent[] = new cHTMLLabel(i18n('Image width'), 'teaser_image_width_' . $this->_id);
 963:         $wrapperContent[] = new cHTMLTextbox('teaser_image_width_' . $this->_id, $this->_settings['teaser_image_width'], '', '', 'teaser_image_width_' . $this->_id);
 964:         $wrapperContent[] = new cHTMLLabel(i18n('Image height'), 'teaser_image_height_' . $this->_id);
 965:         $wrapperContent[] = new cHTMLTextbox('teaser_image_height_' . $this->_id, $this->_settings['teaser_image_height'], '', '', 'teaser_image_height_' . $this->_id);
 966:         $wrapperContent[] = new cHTMLLabel(i18n('Image scale'), 'teaser_image_crop_' . $this->_id);
 967:         $wrapperContent[] = $this->_generateCropSelect();
 968: 
 969:         $wrapperContent[] = new cHTMLParagraph(i18n("Content types"), 'head_sub');
 970:         $wrapperContent[] = new cHTMLLabel(i18n("Headline source"), 'teaser_source_head_' . $this->_id);
 971:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_head_' . $this->_id, $this->_settings['teaser_source_head'], $this->_settings['teaser_source_head_count']);
 972:         $wrapperContent[] = new cHTMLLabel(i18n("Text source"), 'teaser_source_text_' . $this->_id);
 973:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_text_' . $this->_id, $this->_settings['teaser_source_text'], $this->_settings['teaser_source_text_count']);
 974:         $wrapperContent[] = new cHTMLLabel(i18n('Image source'), 'teaser_source_image_' . $this->_id);
 975:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_image_' . $this->_id, $this->_settings['teaser_source_image'], $this->_settings['teaser_source_image_count']);
 976:         $wrapperContent[] = new cHTMLLabel(i18n('Date source'), 'teaser_source_date_' . $this->_id);
 977:         $wrapperContent[] = $this->_generateTypeSelect('teaser_source_date_' . $this->_id, $this->_settings['teaser_source_date'], $this->_settings['teaser_source_date_count']);
 978: 
 979:         $wrapper->setContent($wrapperContent);
 980:         return $wrapper->render();
 981:     }
 982: 
 983:      984:  985:  986:  987:  988: 
 989:     private function _getArtName($idArt) {
 990:         $article = new cApiArticleLanguage();
 991:         $article->loadByArticleAndLanguageId((int) $idArt, $this->_lang);
 992: 
 993:         $title = $article->get('title');
 994:         if ($article->isLoaded() && !empty($title)) {
 995:             return $article->get('title');
 996:         } else {
 997:             return i18n('Unknown article');
 998:         }
 999:     }
1000: 
1001: }