Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • 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
  • cContentTypeRaw
  • cContentTypeTeaser
  • cContentTypeText
  • cTypeGenerator
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: 
   3: /**
   4:  * This file contains the cContentTypeFilelist class.
   5:  *
   6:  * @package Core
   7:  * @subpackage ContentType
   8:  * @author Dominik Ziegler
   9:  * @author Timo Trautmann
  10:  * @author Simon Sprankel
  11:  * @copyright four for business AG <www.4fb.de>
  12:  * @license http://www.contenido.org/license/LIZENZ.txt
  13:  * @link http://www.4fb.de
  14:  * @link http://www.contenido.org
  15:  */
  16: 
  17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  18: 
  19: cInclude('includes', 'functions.con.php');
  20: cInclude('includes', 'functions.upl.php');
  21: 
  22: /**
  23:  * Content type CMS_FILELIST which lets the editor select some folders or files.
  24:  * The corresponding files are then shown in the frontend.
  25:  *
  26:  * @package Core
  27:  * @subpackage ContentType
  28:  */
  29: class cContentTypeFilelist extends cContentTypeAbstractTabbed {
  30: 
  31:     /**
  32:      * Default file extensions.
  33:      *
  34:      * @var array
  35:      */
  36:     private $_fileExtensions = array(
  37:         'gif',
  38:         'jpeg',
  39:         'jpg',
  40:         'png',
  41:         'doc',
  42:         'xls',
  43:         'pdf',
  44:         'txt',
  45:         'zip',
  46:         'ppt'
  47:     );
  48: 
  49:     /**
  50:      * Meta data identifiers.
  51:      *
  52:      * @var array
  53:      */
  54:     private $_metaDataIdents = array(
  55:         'description' => 'Description',
  56:         'medianame' => 'Media name',
  57:         'copyright' => 'Copyright',
  58:         'keywords' => 'Keywords',
  59:         'internal_notice' => 'Internal notes'
  60:     );
  61: 
  62:     /**
  63:      * Date fields.
  64:      *
  65:      * @var array
  66:      */
  67:     private $_dateFields = array(
  68:         'ctime' => 'creationdate',
  69:         'mtime' => 'modifydate'
  70:     );
  71: 
  72:     /**
  73:      * Placeholders for labels in frontend.
  74:      * Important: This must be a static array!
  75:      *
  76:      * @var array
  77:      */
  78:     protected static $_translations = array(
  79:         "LABEL_FILESIZE",
  80:         "LABEL_UPLOAD_DATE"
  81:     );
  82: 
  83:     /**
  84:      * Constructor to create an instance of this class.
  85:      *
  86:      * Initialises class attributes and handles store events.
  87:      *
  88:      * @param string $rawSettings
  89:      *         the raw settings in an XML structure or as plaintext
  90:      * @param int    $id
  91:      *         ID of the content type, e.g. 3 if CMS_TEASER[3] is used
  92:      * @param array  $contentTypes
  93:      *         array containing the values of all content types
  94:      *
  95:      * @throws cDbException
  96:      * @throws cException
  97:      */
  98:     function __construct($rawSettings, $id, array $contentTypes) {
  99: 
 100:         // set props
 101:         $this->_type = 'CMS_FILELIST';
 102:         $this->_prefix = 'filelist';
 103:         $this->_settingsType = 'xml';
 104:         $this->_formFields = array(
 105:             'filelist_title',
 106:             'filelist_style',
 107:             'filelist_directories',
 108:             'filelist_incl_subdirectories',
 109:             'filelist_manual',
 110:             'filelist_sort',
 111:             'filelist_incl_metadata',
 112:             'filelist_extensions',
 113:             'filelist_sortorder',
 114:             'filelist_filesizefilter_from',
 115:             'filelist_filesizefilter_to',
 116:             'filelist_ignore_extensions',
 117:             'filelist_manual_files',
 118:             'filelist_filecount'
 119:         );
 120: 
 121:         // call parent constructor
 122:         parent::__construct($rawSettings, $id, $contentTypes);
 123: 
 124:         // dynamically add form fields based on the meta data identifiers
 125:         foreach ($this->_metaDataIdents as $identName => $translation) {
 126:             $this->_formFields[] = 'filelist_md_' . $identName . '_limit';
 127:         }
 128: 
 129:         // dynamically add form fields based on the date fields
 130:         $dateFormFields = array();
 131:         foreach ($this->_dateFields as $dateField) {
 132:             $this->_formFields[] = 'filelist_' . $dateField . 'filter_from';
 133:             $dateFormFields[] = 'filelist_' . $dateField . 'filter_from';
 134:             $this->_formFields[] = 'filelist_' . $dateField . 'filter_to';
 135:             $dateFormFields[] = 'filelist_' . $dateField . 'filter_to';
 136:         }
 137: 
 138:         // if form is submitted, store the current file list settings
 139:         // notice: there is also a need, that filelist_id is the same (case:
 140:         // more than one cms file list is used on the same page
 141:         if (isset($_POST['filelist_action']) && $_POST['filelist_action'] === 'store' && isset($_POST['filelist_id']) && (int) $_POST['filelist_id'] == $this->_id) {
 142: 
 143:             // convert the date form fields to timestamps
 144:             foreach ($dateFormFields as $dateFormField) {
 145:                 $value = $_POST[$dateFormField];
 146:                 if ($value != '' && $value != 'DD.MM.YYYY' && cString::getStringLength($value) == 10) {
 147:                     $valueSplit = explode('.', $value);
 148:                     $timestamp = mktime(0, 0, 0, $valueSplit[1], $valueSplit[0], $valueSplit[2]);
 149:                 } else {
 150:                     $timestamp = 0;
 151:                 }
 152:                 $_POST[$dateFormField] = $timestamp;
 153:             }
 154: 
 155:             $this->getConfiguredFiles();
 156:             $this->_storeSettings();
 157:         }
 158:     }
 159: 
 160:     /**
 161:      * Returns all translation strings for mi18n.
 162:      *
 163:      * @param array $translationStrings
 164:      *         translation strings
 165:      * @return array
 166:      *         updated translation string
 167:      */
 168:     public static function addModuleTranslations(array $translationStrings) {
 169:         foreach (self::$_translations as $value) {
 170:             $translationStrings[] = $value;
 171:         }
 172: 
 173:         return $translationStrings;
 174:     }
 175: 
 176:     /**
 177:      * Reads all settings from the $_rawSettings attribute (XML or plaintext)
 178:      * and stores them in the $_settings attribute (associative array or
 179:      * plaintext).
 180:      */
 181:     protected function _readSettings() {
 182:         parent::_readSettings();
 183:         // convert the timestamps to dates
 184:         $dateFormFields = array();
 185:         foreach ($this->_dateFields as $dateField) {
 186:             $dateFormFields[] = 'filelist_' . $dateField . 'filter_from';
 187:             $dateFormFields[] = 'filelist_' . $dateField . 'filter_to';
 188:         }
 189:         foreach ($dateFormFields as $dateFormField) {
 190:             $value = $this->_settings[$dateFormField];
 191:             if ($dateFormField == 0) {
 192:                 $value = 'DD.MM.YYYY';
 193:             } else {
 194:                 $value = date('d.m.Y', $dateFormField);
 195:             }
 196:             $this->_settings[$dateFormField] = $value;
 197:         }
 198:     }
 199: 
 200:     /**
 201:      * Generates the code which should be shown if this content type is shown in
 202:      * the frontend.
 203:      *
 204:      * @return string
 205:      *         escaped HTML code which sould be shown if content type is shown in frontend
 206:      */
 207:     public function generateViewCode() {
 208:         $code = '";?><?php
 209:                     $fileList = new cContentTypeFilelist(\'%s\', %s, %s);
 210:                     echo $fileList->generateFileListCode();
 211:                  ?><?php echo "';
 212:         // escape ' to avoid accidently ending the string in $code
 213:         $code = sprintf($code, str_replace('\'', '\\\'', $this->_rawSettings), $this->_id, 'array()');
 214: 
 215:         return $code;
 216:     }
 217: 
 218:     /**
 219:      *
 220:      * @todo unify return values
 221:      * @return void|string|array
 222:      * @throws cDbException
 223:      * @throws cException
 224:      */
 225:     public function getConfiguredFiles() {
 226:         $files = array();
 227: 
 228:         if ($this->_settings['filelist_manual'] === 'true' && count($this->_settings['filelist_manual_files']) > 0) {
 229:             $tempFileList = $this->_settings['filelist_manual_files'];
 230: 
 231:             // Check if manual selected file exists, otherwise ignore them
 232:             // Write only existing files into fileList array
 233:             if (is_array($tempFileList)) {
 234:                 foreach ($tempFileList as $filename) {
 235:                     if (cFileHandler::exists($this->_uploadPath . $filename)) {
 236:                         $fileList[] = $filename;
 237:                     }
 238:                 }
 239:             } else {
 240:                 if (cFileHandler::exists($this->_uploadPath . $tempFileList)) {
 241:                     $fileList[] = $tempFileList;
 242:                 }
 243:             }
 244: 
 245:         } else if (is_array($this->_settings['filelist_directories']) && count($this->_settings['filelist_directories']) > 0) {
 246:             $directories = $this->_settings['filelist_directories'];
 247: 
 248:             if ($this->_settings['filelist_incl_subdirectories'] === 'true') {
 249:                 foreach ($directories as $directoryName) {
 250:                     $directories = $this->_getAllSubdirectories($directoryName, $directories);
 251:                 }
 252:             }
 253: 
 254:             // strip duplicate directories to save performance
 255:             $directories = array_unique($directories);
 256: 
 257:             if (count($directories) < 1) {
 258:                 return;
 259:             }
 260: 
 261:             foreach ($directories as $directoryName) {
 262:                 if (is_dir($this->_uploadPath . $directoryName)) {
 263:                     if (false !== $handle = cDirHandler::read($this->_uploadPath . $directoryName . '/', false, false, true)) {
 264:                         foreach ($handle as $entry) {
 265:                             $fileList[] = $directoryName . '/' . $entry;
 266:                         }
 267:                     }
 268:                 }
 269:             }
 270:         } else {
 271:             return '';
 272:         }
 273: 
 274:         if (is_array($fileList)) {
 275:             $files = $this->_applyFileFilters($fileList);
 276:         } else {
 277:             $files = $this->_applyFileFilters((array) $fileList);
 278:         }
 279:         unset($fileList);
 280: 
 281:         if (count($files) > 0) {
 282:             // sort the files
 283:             if ($this->_settings['filelist_sortorder'] === 'desc') {
 284:                 krsort($files);
 285:             } else {
 286:                 ksort($files);
 287:             }
 288: 
 289:             $i = 1;
 290:             foreach ($files as $key => $filenameData) {
 291:                 if (($this->_settings['filelist_filecount'] != 0 && $i <= $this->_settings['filelist_filecount']) || $this->_settings['filelist_filecount'] == 0) {
 292:                     if ($this->_settings['filelist_incl_metadata'] === 'true') {
 293:                         $metaData = array();
 294:                         // load upload and upload meta object
 295:                         $upload = new cApiUpload();
 296:                         $upload->loadByMany(array(
 297:                             'filename' => $filenameData['filename'],
 298:                             'dirname' => $filenameData['path'] . '/',
 299:                             'idclient' => $this->_client
 300:                         ));
 301:                         $uploadMeta = new cApiUploadMeta();
 302:                         $uploadMeta->loadByMany(array(
 303:                             'idupl' => $upload->get('idupl'),
 304:                             'idlang' => $this->_lang
 305:                         ));
 306: 
 307:                         foreach ($this->_metaDataIdents as $identName => $translation) {
 308:                             $string = $uploadMeta->get($identName);
 309: 
 310:                             // Cut the string only, when the limit for identName
 311:                             // is active and the string length is more than the
 312:                             // setting
 313:                             if ($this->_settings['filelist_md_' . $identName . '_limit'] > 0 && cString::getStringLength($string) > $this->_settings['filelist_md_' . $identName . '_limit']) {
 314:                                 $metaData[$identName] = cString::trimAfterWord(cSecurity::unFilter($string), $this->_settings['filelist_md_' . $identName . '_limit']) . '...';
 315:                             } else {
 316:                                 $metaData[$identName] = cSecurity::unFilter($string);
 317:                             }
 318:                         }
 319: 
 320:                         $filenameData['metadata'] = $metaData;
 321:                     } else {
 322:                         $filenameData['metadata'] = array();
 323:                     }
 324: 
 325:                     // Define new array for files
 326:                     // If filelist_filecount is defined, this array has the same
 327:                     // size as "filelist_filecount" setting value (0 = no limit)
 328:                     $limitedfiles[$key] = $filenameData;
 329:                     $i++;
 330:                 }
 331:             }
 332: 
 333:             return $limitedfiles;
 334:         }
 335:     }
 336: 
 337:     /**
 338:      * Function is called in edit- and viewmode in order to generate code for
 339:      * output.
 340:      *
 341:      * @return string
 342:      *         generated code
 343:      * @throws cDbException
 344:      * @throws cException
 345:      * @throws cInvalidArgumentException
 346:      */
 347:     public function generateFileListCode() {
 348:         if ($this->_settings['filelist_style'] === '') {
 349:             return '';
 350:         }
 351:         $template = new cTemplate();
 352:         $fileList = array();
 353:         $template->set('s', 'TITLE', conHtmlSpecialChars($this->_settings['filelist_title']));
 354: 
 355:         $files = $this->getConfiguredFiles();
 356: 
 357:         if (is_array($files) && count($files) > 0) {
 358:             foreach ($files as $filenameData) {
 359:                 $this->_fillFileListTemplateEntry($filenameData, $template);
 360:             }
 361: 
 362:             // generate template
 363:             $code = $template->generate($this->_cfgClient[$this->_client]['path']['frontend'] . 'templates/' . $this->_settings['filelist_style'], true);
 364:         }
 365: 
 366:         return $code;
 367:     }
 368: 
 369:     /**
 370:      * Gets all subdirectories recursively.
 371:      *
 372:      * @param string $directoryPath
 373:      *         path to directory
 374:      * @param array $directories
 375:      *         already found directories
 376:      * @return array
 377:      *         containing all subdirectories and the initial directories
 378:      */
 379:     private function _getAllSubdirectories($directoryPath, array $directories) {
 380:         $handle = cDirHandler::read($this->_uploadPath . $directoryPath . '/', false, true);
 381: 
 382:         if (false !== $handle) {
 383:             foreach ($handle as $entry) {
 384:                 if (cFileHandler::fileNameBeginsWithDot($entry) === false) {
 385:                     $directories[] = $directoryPath . '/' . $entry;
 386:                     $directories = $this->_getAllSubdirectories($directoryPath . '/' . $entry, $directories);
 387:                 }
 388:             }
 389:         }
 390: 
 391:         return $directories;
 392:     }
 393: 
 394:     /**
 395:      * Removes all files not matching the filter criterias.
 396:      *
 397:      * @param array $fileList
 398:      *         files which should be filtered
 399:      * @return array
 400:      *         with filtered files
 401:      */
 402:     private function _applyFileFilters(array $fileList) {
 403:         foreach ($fileList as $fullname) {
 404:             $filename = basename($fullname);
 405:             $directoryName = str_replace('/' . $filename, '', $fullname);
 406: 
 407:             // checking the extension stuff
 408:             $extensionName = cFileHandler::getExtension($filename);
 409:             $extensions = $this->_settings['filelist_extensions'];
 410:             if(!is_array($extensions)) {
 411:                 $extensions = array($extensions);
 412:             }
 413:             if ($this->_settings['filelist_ignore_extensions'] === 'true' || count($extensions) == 0 || ($this->_settings['filelist_ignore_extensions'] === 'false' && in_array($extensionName, $extensions)) || ($this->_settings['filelist_ignore_extensions'] === 'false' && $extensionName == $extensions)) {
 414: 
 415:                 // Prevent errors with not existing files
 416:                 if (!cFileHandler::exists($this->_uploadPath . $directoryName . '/' . $filename)) {
 417:                     return;
 418:                 }
 419: 
 420:                 // checking filesize filter
 421:                 $fileStats = stat($this->_uploadPath . $directoryName . '/' . $filename);
 422:                 $filesize = $fileStats['size'];
 423: 
 424:                 $filesizeMib = $filesize / 1024 / 1024;
 425:                 if (($this->_settings['filelist_filesizefilter_from'] == 0 && $this->_settings['filelist_filesizefilter_to'] == 0) || ($this->_settings['filelist_filesizefilter_from'] <= $filesizeMib && $this->_settings['filelist_filesizefilter_to'] >= $filesizeMib)) {
 426: 
 427:                     if ($this->_applyDateFilters($fileStats)) {
 428:                         $creationDate = $fileStats['ctime'];
 429:                         $modifyDate = $fileStats['mtime'];
 430:                         // conditional stuff is completed, start sorting
 431:                         // inclusive fix CON_2605 for files created at the same time
 432:                         // or with the same filesize
 433:                         switch ($this->_settings['filelist_sort']) {
 434:                             case 'filesize':
 435:                                 if (!isset($files[$filesize])) {
 436:                                     $indexName = $filesize . "_" . mt_rand(0, mt_getrandmax());
 437:                                 } else {
 438:                                     $indexName = $filesize;
 439:                                 }
 440:                                 break;
 441:                             case 'createdate':
 442:                                 if (!isset($files[$creationDate])) {
 443:                                     $indexName = $creationDate . "_" . mt_rand(0, mt_getrandmax());
 444:                                 } else {
 445:                                     $indexName = $creationDate;
 446:                                 }
 447:                                 break;
 448:                             case 'modifydate':
 449:                                 if (!isset($files[$modifyDate])) {
 450:                                     $indexName = $modifyDate . "_" . mt_rand(0, mt_getrandmax());
 451:                                 } else {
 452:                                     $indexName = $modifyDate;
 453:                                 }
 454:                                 break;
 455:                             case 'filename':
 456:                             default:
 457:                                 $indexName = cString::toLowerCase($directoryName . $filename);
 458:                         }
 459: 
 460:                         $files[$indexName] = array();
 461:                         $files[$indexName]['filename'] = $filename;
 462:                         $files[$indexName]['path'] = $directoryName;
 463:                         $files[$indexName]['extension'] = $extensionName;
 464:                         $files[$indexName]['filesize'] = $filesize;
 465:                         $files[$indexName]['filemodifydate'] = $modifyDate;
 466:                         $files[$indexName]['filecreationdate'] = $creationDate;
 467:                     }
 468:                 }
 469:             }
 470:         }
 471: 
 472:         return $files;
 473:     }
 474: 
 475:     /**
 476:      * Checks whether the file passes the date filters.
 477:      *
 478:      * @param array $fileStats
 479:      *         file information
 480:      * @return bool
 481:      *         whether the file passes the date filters
 482:      */
 483:     private function _applyDateFilters(array $fileStats) {
 484:         foreach ($this->_dateFields as $index => $dateField) {
 485:             $date = $fileStats[$index];
 486:             if ($this->_settings['filelist_' . $dateField . 'filter_from'] == 0 && $this->_settings['filelist_' . $dateField . 'filter_from'] == 0 || $this->_settings['filelist_' . $dateField . 'filter_to'] == 0 && $date >= $this->_settings['filelist_' . $dateField . 'filter_from'] || $this->_settings['filelist_' . $dateField . 'filter_from'] == 0 && $date <= $this->_settings['filelist_' . $dateField . 'filter_to'] || $this->_settings['filelist_' . $dateField . 'filter_from'] != 0 && $this->_settings['filelist_' . $dateField . 'filter_to'] != 0 && $date >= $this->_settings['filelist_' . $dateField . 'filter_from'] && $date <= $this->_settings['filelist_' . $dateField . 'filter_to']) {
 487:                 return true;
 488:             }
 489:         }
 490: 
 491:         return false;
 492:     }
 493: 
 494:     /**
 495:      * Method to fill single entry (file) of the file list.
 496:      *
 497:      * @param array $fileData
 498:      *         information about the file
 499:      * @param cTemplate $template
 500:      *         reference to the used template object
 501:      */
 502:     private function _fillFileListTemplateEntry(array $fileData, cTemplate &$template) {
 503:         $filename = $fileData['filename'];
 504:         $directoryName = $fileData['path'];
 505: 
 506:         if (empty($filename) || empty($directoryName)) {
 507:             cWarning(__FILE__, __LINE__, "Empty directory '$directoryName' and or filename '$filename'");
 508:             return;
 509:         }
 510: 
 511:         $fileLink = $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $directoryName . '/' . $filename;
 512:         $filePath = $this->_cfgClient[$this->_client]['upl']['path'] . $directoryName . '/' . $filename;
 513: 
 514:         // If file is an image (extensions gif, jpg, jpeg, png) scale it
 515:         // otherwise use default png image
 516:         switch ($fileData['extension']) {
 517:             case 'gif':
 518:             case 'jpg':
 519:             case 'jpeg':
 520:             case 'png':
 521:                 $imgSrc = cApiImgScale($filePath, 148, 74);
 522:                 break;
 523:             default:
 524:                 $imgSrc = $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'images/misc/download_misc.png';
 525:                 break;
 526:         }
 527: 
 528:         $filesize = $fileData['filesize'];
 529:         $metaData = $fileData['metadata'];
 530: 
 531:         if ($this->_settings['filelist_incl_metadata'] === 'true' && count($metaData) != 0) {
 532:             $template->set('d', 'FILEMETA_DESCRIPTION', $metaData['description']);
 533:             $template->set('d', 'FILEMETA_MEDIANAME', $metaData['medianame']);
 534:             $template->set('d', 'FILEMETA_KEYWORDS', $metaData['keywords']);
 535:             $template->set('d', 'FILEMETA_INTERNAL_NOTICE', $metaData['internal_notice']);
 536:             $template->set('d', 'FILEMETA_COPYRIGHT', $metaData['copyright']);
 537:         } else {
 538:             $template->set('d', 'FILEMETA_DESCRIPTION', '');
 539:             $template->set('d', 'FILEMETA_MEDIANAME', '');
 540:             $template->set('d', 'FILEMETA_KEYWORDS', '');
 541:             $template->set('d', 'FILEMETA_INTERNAL_NOTICE', '');
 542:             $template->set('d', 'FILEMETA_COPYRIGHT', '');
 543:         }
 544: 
 545:         $template->set('d', 'FILETHUMB', $imgSrc);
 546:         $template->set('d', 'FILENAME', $filename);
 547:         $template->set('d', 'FILESIZE', humanReadableSize($filesize));
 548:         $template->set('d', 'FILEEXTENSION', $fileData['extension']);
 549:         $template->set('d', 'FILECREATIONDATE', date('d.m.Y', $fileData['filecreationdate']));
 550:         $template->set('d', 'FILEMODIFYDATE', date('d.m.Y', $fileData['filemodifydate']));
 551:         $template->set('d', 'FILEDIRECTORY', $directoryName);
 552:         $template->set('d', 'FILELINK', $fileLink);
 553: 
 554:         foreach (self::$_translations as $translationString) {
 555:             $template->set('d', $translationString, mi18n($translationString));
 556:         }
 557: 
 558:         $template->next();
 559:     }
 560: 
 561:     /**
 562:      * Generates the code which should be shown if this content type is edited.
 563:      *
 564:      * @return string
 565:      *         escaped HTML code which should be shown if content type is edited
 566:      * @throws cInvalidArgumentException
 567:      */
 568:     public function generateEditCode() {
 569:         $template = new cTemplate();
 570:         $template->set('s', 'ID', $this->_id);
 571:         $template->set('s', 'IDARTLANG', $this->_idArtLang);
 572:         $template->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
 573: 
 574:         $templateTabs = new cTemplate();
 575:         $templateTabs->set('s', 'PREFIX', $this->_prefix);
 576: 
 577:         // create code for external tab
 578:         $templateTabs->set('d', 'TAB_ID', 'directories');
 579:         $templateTabs->set('d', 'TAB_CLASS', 'directories');
 580:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabDirectories());
 581:         $templateTabs->next();
 582: 
 583:         // create code for internal tab
 584:         $templateTabs->set('d', 'TAB_ID', 'general');
 585:         $templateTabs->set('d', 'TAB_CLASS', 'general');
 586:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabGeneral());
 587:         $templateTabs->next();
 588: 
 589:         // create code for file tab
 590:         $templateTabs->set('d', 'TAB_ID', 'filter');
 591:         $templateTabs->set('d', 'TAB_CLASS', 'filter');
 592:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabFilter());
 593:         $templateTabs->next();
 594: 
 595:         // create code for manual tab
 596:         $templateTabs->set('d', 'TAB_ID', 'manual');
 597:         $templateTabs->set('d', 'TAB_CLASS', 'manual');
 598:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabManual());
 599:         $templateTabs->next();
 600: 
 601:         $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
 602: 
 603:         // construct the top code of the template
 604:         $templateTop = new cTemplate();
 605:         $templateTop->set('s', 'ICON', 'images/but_editlink.gif');
 606:         $templateTop->set('s', 'ID', $this->_id);
 607:         $templateTop->set('s', 'PREFIX', $this->_prefix);
 608:         $templateTop->set('s', 'HEADLINE', i18n('File list settings'));
 609:         $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
 610: 
 611:         // define the available tabs
 612:         $tabMenu = array(
 613:             'directories' => i18n('Directories'),
 614:             'general' => i18n('General'),
 615:             'filter' => i18n('Filter'),
 616:             'manual' => i18n('Manual')
 617:         );
 618: 
 619:         // construct the bottom code of the template
 620:         $templateBottom = new cTemplate();
 621:         $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
 622:         $templateBottom->set('s', 'ID', $this->_id);
 623:         $templateBottom->set('s', 'PREFIX', $this->_prefix);
 624:         $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
 625:         $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
 626:         $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
 627:         $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsFilelist.js');
 628:         $templateBottom->set('s', 'JS_CLASS_NAME', 'Con.cContentTypeFilelist');
 629:         $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
 630: 
 631:         // construct the whole template code
 632:         $code = $this->generateViewCode();
 633:         $code .= $this->_encodeForOutput($codeTop);
 634:         $code .= $this->_generateTabMenuCode($tabMenu);
 635:         $code .= $this->_encodeForOutput($codeTabs);
 636:         $code .= $this->_generateActionCode();
 637:         $code .= $this->_encodeForOutput($codeBottom);
 638: 
 639:         return $code;
 640:     }
 641: 
 642:     /**
 643:      * Generates code for the directories tab.
 644:      *
 645:      * @return string
 646:      *         the code for the directories tab
 647:      * @throws cInvalidArgumentException
 648:      */
 649:     private function _generateTabDirectories() {
 650:         // wrapper containing content of directories tab
 651:         $wrapper = new cHTMLDiv();
 652:         $wrapperContent = array();
 653: 
 654:         $wrapperContent[] = new cHTMLParagraph(i18n('Source directory'), 'head_sub');
 655: 
 656:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
 657:         $liRoot = new cHTMLListItem('root', 'root last');
 658:         $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
 659:         $liRoot->setContent(array(
 660:             '<em>Uploads</em>',
 661:             $directoryListCode
 662:         ));
 663:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
 664:         $directoryList->setContent($conStrTree);
 665:         $wrapperContent[] = $directoryList;
 666: 
 667:         $wrapper->setContent($wrapperContent);
 668: 
 669:         return $wrapper->render();
 670:     }
 671: 
 672:     /**
 673:      * Generates code for the general tab.
 674:      *
 675:      * @return string
 676:      *         the code for the general link tab
 677:      * @throws cInvalidArgumentException
 678:      */
 679:     private function _generateTabGeneral() {
 680:         // wrapper containing content of general tab
 681:         $wrapper = new cHTMLDiv();
 682:         $wrapperContent = array();
 683: 
 684:         $wrapperContent[] = new cHTMLParagraph(i18n('General settings'), 'head_sub');
 685: 
 686:         $wrapperContent[] = new cHTMLLabel(i18n('File list title'), 'filelist_title_' . $this->_id);
 687:         $wrapperContent[] = new cHTMLTextbox('filelist_title_' . $this->_id, conHtmlSpecialChars($this->_settings['filelist_title']), '', '', 'filelist_title_' . $this->_id);
 688:         $wrapperContent[] = new cHTMLLabel(i18n('File list style'), 'filelist_style_' . $this->_id);
 689:         $wrapperContent[] = $this->_generateStyleSelect();
 690:         $wrapperContent[] = new cHTMLLabel(i18n('File list sort'), 'filelist_sort_' . $this->_id);
 691:         $wrapperContent[] = $this->_generateSortSelect();
 692:         $wrapperContent[] = new cHTMLLabel(i18n('Sort order'), 'filelist_sortorder_' . $this->_id);
 693:         $wrapperContent[] = $this->_generateSortOrderSelect();
 694:         $wrapperContent[] = new cHTMLLabel(i18n('Include subdirectories?'), 'filelist_incl_subdirectories_' . $this->_id);
 695:         $wrapperContent[] = new cHTMLCheckbox('filelist_incl_subdirectories_' . $this->_id, '', 'filelist_incl_subdirectories_' . $this->_id, ($this->_settings['filelist_incl_subdirectories'] === 'true'));
 696:         $wrapperContent[] = new cHTMLLabel(i18n('Include meta data?'), 'filelist_incl_metadata_' . $this->_id);
 697:         $wrapperContent[] = new cHTMLCheckbox('filelist_incl_metadata_' . $this->_id, '', 'filelist_incl_metadata_' . $this->_id, ($this->_settings['filelist_incl_metadata'] === 'true'));
 698:         $div = new cHTMLDiv($this->_generateMetaDataList());
 699:         $div->setID('metaDataList');
 700:         $wrapperContent[] = $div;
 701: 
 702:         $wrapper->setContent($wrapperContent);
 703: 
 704:         return $wrapper->render();
 705:     }
 706: 
 707:     /**
 708:      * Generates a select box containing the filelist styles.
 709:      *
 710:      * @return string
 711:      *         rendered cHTMLSelectElement
 712:      */
 713:     private function _generateStyleSelect() {
 714:         $htmlSelect = new cHTMLSelectElement('filelist_style_' . $this->_id, '', 'filelist_style_' . $this->_id);
 715: 
 716:         $htmlSelectOption = new cHTMLOptionElement(i18n('Default style'), 'cms_filelist_style_default.html', true);
 717:         $htmlSelect->appendOptionElement($htmlSelectOption);
 718:         $additionalOptions = getEffectiveSettingsByType('cms_filelist_style');
 719:         $options = array();
 720:         foreach ($additionalOptions as $key => $value) {
 721:             $options[$value] = $key;
 722:         }
 723:         $htmlSelect->autoFill($options);
 724:         $htmlSelect->setDefault($this->_settings['filelist_style']);
 725:         return $htmlSelect->render();
 726:     }
 727: 
 728:     /**
 729:      * Generates a select box containing the sort options.
 730:      *
 731:      * @return string
 732:      *         rendered cHTMLSelectElement
 733:      */
 734:     private function _generateSortSelect() {
 735:         $htmlSelect = new cHTMLSelectElement('filelist_sort_' . $this->_id, '', 'filelist_sort_' . $this->_id);
 736: 
 737:         $htmlSelectOption = new cHTMLOptionElement(i18n('File name'), 'filename', true);
 738:         $htmlSelect->appendOptionElement($htmlSelectOption);
 739: 
 740:         $htmlSelectOption = new cHTMLOptionElement(i18n('File size'), 'filesize', false);
 741:         $htmlSelect->appendOptionElement($htmlSelectOption);
 742: 
 743:         $htmlSelectOption = new cHTMLOptionElement(i18n('Date created'), 'createdate', false);
 744:         $htmlSelect->appendOptionElement($htmlSelectOption);
 745: 
 746:         $htmlSelectOption = new cHTMLOptionElement(i18n('Date modified'), 'modifydate', false);
 747:         $htmlSelect->appendOptionElement($htmlSelectOption);
 748: 
 749:         $htmlSelect->setDefault($this->_settings['filelist_sort']);
 750: 
 751:         return $htmlSelect->render();
 752:     }
 753: 
 754:     /**
 755:      * Generates a select box containing the sort order options (asc/desc).
 756:      *
 757:      * @return string
 758:      *         rendered cHTMLSelectElement
 759:      */
 760:     private function _generateSortOrderSelect() {
 761:         $htmlSelect = new cHTMLSelectElement('filelist_sortorder_' . $this->_id, '', 'filelist_sortorder_' . $this->_id);
 762: 
 763:         $htmlSelectOption = new cHTMLOptionElement(i18n('Ascending'), 'asc', true);
 764:         $htmlSelect->appendOptionElement($htmlSelectOption);
 765: 
 766:         $htmlSelectOption = new cHTMLOptionElement(i18n('Descending'), 'desc', false);
 767:         $htmlSelect->appendOptionElement($htmlSelectOption);
 768: 
 769:         // set default value
 770:         $htmlSelect->setDefault($this->_settings['filelist_sortorder']);
 771: 
 772:         return $htmlSelect->render();
 773:     }
 774: 
 775:     /**
 776:      * Generates a list of meta data.
 777:      *
 778:      * @return string
 779:      *         HTML code showing a list of meta data
 780:      * @throws cInvalidArgumentException
 781:      */
 782:     private function _generateMetaDataList() {
 783:         $template = new cTemplate();
 784: 
 785:         foreach ($this->_metaDataIdents as $identName => $translation) {
 786:             $metaDataLimit = $this->_settings['filelist_md_' . $identName . '_limit'];
 787:             if (!isset($metaDataLimit) || $metaDataLimit === '') {
 788:                 $metaDataLimit = 0;
 789:             }
 790: 
 791:             $template->set('d', 'METADATA_NAME', $identName);
 792:             $template->set('d', 'METADATA_DISPLAYNAME', i18n($translation));
 793:             $template->set('d', 'METADATA_LIMIT', $metaDataLimit);
 794:             $template->set('d', 'ID', $this->_id);
 795: 
 796:             $template->next();
 797:         }
 798: 
 799:         return $template->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_filelist_metadata_limititem.html', true);
 800:     }
 801: 
 802:     /**
 803:      * Generates code for the filter tab.
 804:      *
 805:      * @return string
 806:      *         the code for the filter link tab
 807:      */
 808:     private function _generateTabFilter() {
 809:         // wrapper containing content of filter tab
 810:         $wrapper = new cHTMLDiv();
 811:         $wrapperContent = array();
 812: 
 813:         $wrapperContent[] = new cHTMLParagraph(i18n('Filter settings'), 'head_sub');
 814: 
 815:         $wrapperContent[] = new cHTMLLabel(i18n('Displayed file extensions'), 'filelist_extensions_' . $this->_id);
 816:         $wrapperContent[] = $this->_generateExtensionSelect();
 817:         $wrapperContent[] = '<br>';
 818:         $link = new cHTMLLink('#');
 819:         $link->setID('filelist_all_extensions');
 820:         $link->setContent(i18n('Select all entries'));
 821:         $wrapperContent[] = $link;
 822:         $wrapperContent[] = new cHTMLLabel(i18n('Ignore selection (use all)'), 'filelist_ignore_extensions_' . $this->_id, 'filelist_ignore_extensions');
 823:         $wrapperContent[] = new cHTMLCheckbox('filelist_ignore_extensions_' . $this->_id, '', 'filelist_ignore_extensions_' . $this->_id, ($this->_settings['filelist_ignore_extensions'] !== 'false'));
 824: 
 825:         $wrapperContent[] = new cHTMLLabel(i18n('File size limit (in MiB)'), 'filelist_filesizefilter_from_' . $this->_id);
 826:         $default = (!empty($this->_settings['filelist_filesizefilter_from'])) ? $this->_settings['filelist_filesizefilter_from'] : '0';
 827:         $wrapperContent[] = new cHTMLTextbox('filelist_filesizefilter_from_' . $this->_id, $default, '', '', 'filelist_filesizefilter_from_' . $this->_id);
 828:         $wrapperContent[] = new cHTMLSpan('&nbsp;-&nbsp;');
 829:         $default = (!empty($this->_settings['filelist_filesizefilter_to'])) ? $this->_settings['filelist_filesizefilter_to'] : '0';
 830:         $wrapperContent[] = new cHTMLTextbox('filelist_filesizefilter_to_' . $this->_id, $default, '', '', 'filelist_filesizefilter_to_' . $this->_id);
 831: 
 832:         $wrapperContent[] = new cHTMLLabel(i18n('Creation date limit'), 'filelist_creationdatefilter_from_' . $this->_id);
 833:         $default = (!empty($this->_settings['filelist_creationdatefilter_from'])) ? $this->_settings['filelist_creationdatefilter_from'] : 'DD.MM.YYYY';
 834:         $wrapperContent[] = new cHTMLTextbox('filelist_creationdatefilter_from_' . $this->_id, $default, '', '', 'filelist_creationdatefilter_from_' . $this->_id);
 835:         $wrapperContent[] = new cHTMLSpan('&nbsp;-&nbsp;');
 836:         $default = (!empty($this->_settings['filelist_creationdatefilter_to'])) ? $this->_settings['filelist_creationdatefilter_to'] : 'DD.MM.YYYY';
 837:         $wrapperContent[] = new cHTMLTextbox('filelist_creationdatefilter_to_' . $this->_id, $default, '', '', 'filelist_creationdatefilter_to_' . $this->_id);
 838: 
 839:         $wrapperContent[] = new cHTMLLabel(i18n('Modify date limit'), 'filelist_modifydatefilter_from_' . $this->_id);
 840:         $default = (!empty($this->_settings['filelist_modifydatefilter_from'])) ? $this->_settings['filelist_modifydatefilter_from'] : 'DD.MM.YYYY';
 841:         $wrapperContent[] = new cHTMLTextbox('filelist_modifydatefilter_from_' . $this->_id, $default, '', '', 'filelist_modifydatefilter_from_' . $this->_id);
 842:         $wrapperContent[] = new cHTMLSpan('&nbsp;-&nbsp;');
 843:         $default = (!empty($this->_settings['filelist_modifydatefilter_to'])) ? $this->_settings['filelist_modifydatefilter_to'] : 'DD.MM.YYYY';
 844:         $wrapperContent[] = new cHTMLTextbox('filelist_modifydatefilter_to_' . $this->_id, $default, '', '', 'filelist_modifydatefilter_to_' . $this->_id);
 845: 
 846:         $wrapperContent[] = new cHTMLLabel(i18n('File count'), 'filelist_filecount_' . $this->_id);
 847:         $default = (!empty($this->_settings['filelist_filecount'])) ? $this->_settings['filelist_filecount'] : '0';
 848:         $wrapperContent[] = new cHTMLTextbox('filelist_filecount_' . $this->_id, $default, '', '', 'filelist_filecount_' . $this->_id);
 849: 
 850:         $wrapper->setContent($wrapperContent);
 851: 
 852:         return $wrapper->render();
 853:     }
 854: 
 855:     /**
 856:      * Generates a select box containing the file extensions.
 857:      *
 858:      * @return string
 859:      *         rendered cHTMLSelectElement
 860:      */
 861:     private function _generateExtensionSelect() {
 862:         $htmlSelect = new cHTMLSelectElement('filelist_extensions_' . $this->_id, '', 'filelist_extensions_' . $this->_id, ($this->_settings['filelist_ignore_extensions'] !== 'false'), '', '', 'manual');
 863: 
 864:         // set other avariable options manually
 865:         foreach ($this->_fileExtensions as $fileExtension) {
 866:             $htmlSelectOption = new cHTMLOptionElement(uplGetFileTypeDescription($fileExtension) . ' (.' . $fileExtension . ')', $fileExtension, false);
 867:             $htmlSelectOption->setAlt(uplGetFileTypeDescription($fileExtension) . ' (.' . $fileExtension . ')');
 868:             $htmlSelect->appendOptionElement($htmlSelectOption);
 869:         }
 870: 
 871:         $additionalOptions = getEffectiveSettingsByType('cms_filelist_extensions');
 872:         foreach ($additionalOptions as $label => $extension) {
 873:             $htmlSelectOption = new cHTMLOptionElement($label . ' (.' . $extension . ')', $extension);
 874:             $htmlSelectOption->setAlt($label . ' (.' . $extension . ')');
 875:             $htmlSelect->appendOptionElement($htmlSelectOption);
 876:         }
 877: 
 878:         // set default values
 879:         $extensions = (is_array($this->_settings['filelist_extensions'])) ? $this->_settings['filelist_extensions'] : array(
 880:             $this->_settings['filelist_extensions']
 881:         );
 882:         $htmlSelect->setSelected($extensions);
 883:         $htmlSelect->setMultiselect();
 884:         $htmlSelect->setSize(5);
 885: 
 886:         return $htmlSelect->render();
 887:     }
 888: 
 889:     /**
 890:      * Checks whether the directory defined by the given directory
 891:      * information is the currently active directory.
 892:      *
 893:      * @param array $dirData
 894:      *         directory information
 895:      * @return bool
 896:      *         whether the directory is the currently active directory
 897:      */
 898:     protected function _isActiveDirectory(array $dirData) {
 899:         return is_array($this->_settings['filelist_directories']) && in_array($dirData['path'] . $dirData['name'], $this->_settings['filelist_directories']);
 900:     }
 901: 
 902:     /**
 903:      * Checks whether the directory defined by the given directory information
 904:      * should be shown expanded.
 905:      *
 906:      * @param array $dirData
 907:      *         directory information
 908:      * @return bool
 909:      *         whether the directory should be shown expanded
 910:      */
 911:     protected function _shouldDirectoryBeExpanded(array $dirData) {
 912:         if (is_array($this->_settings['filelist_directories'])) {
 913:             foreach ($this->_settings['filelist_directories'] as $directoryName) {
 914:                 if (preg_match('#^' . $dirData['path'] . $dirData['name'] . '/.*#', $directoryName)) {
 915:                     return true;
 916:                 }
 917:             }
 918:         }
 919: 
 920:         return false;
 921:     }
 922: 
 923:     /**
 924:      * Generates code for the manual tab.
 925:      *
 926:      * @return string
 927:      *         the code for the manual link tab
 928:      * @throws cInvalidArgumentException
 929:      */
 930:     private function _generateTabManual() {
 931:         // wrapper containing content of manual tab
 932:         $wrapper = new cHTMLDiv();
 933:         $wrapperContent = array();
 934: 
 935:         $wrapperContent[] = new cHTMLParagraph(i18n('Manual settings'), 'head_sub');
 936: 
 937:         $wrapperContent[] = new cHTMLLabel(i18n('Use manual file list?'), 'filelist_manual_' . $this->_id);
 938:         $wrapperContent[] = new cHTMLCheckbox('filelist_manual_' . $this->_id, '', 'filelist_manual_' . $this->_id, ($this->_settings['filelist_manual'] === 'true'));
 939: 
 940:         $manualDiv = new cHTMLDiv();
 941:         $manualDiv->setID('manual_filelist_setting');
 942:         $manualDiv->appendStyleDefinition('display', 'none');
 943:         $divContent = array();
 944:         $divContent[] = new cHTMLParagraph(i18n('Existing files'), 'head_sub');
 945:         $divContent[] = $this->_generateExistingFileSelect();
 946:         $divContent[] = new cHTMLSpan(i18n('Already configured entries can be deleted by using double click'), 'filelist_manual_' . $this->_id);
 947:         $divContent[] = new CHTMLSpan('<br><br>', 'filelist_manual_' . $this->_id);
 948:         $divContent[] = new cHTMLParagraph(i18n('Add file'), 'head_sub');
 949:         $divContent[] = new cHTMLLabel(i18n('Directory'), '');
 950: 
 951:         // directory navigation
 952:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList_' . $this->_id . '_manual');
 953:         $liRoot = new cHTMLListItem('root', 'last');
 954:         $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
 955:         $liRoot->setContent(array(
 956:             '<em>Uploads</em>',
 957:             $directoryListCode
 958:         ));
 959:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
 960:         $directoryList->setContent($conStrTree);
 961:         $divContent[] = $directoryList;
 962: 
 963:         $divContent[] = new cHTMLLabel(i18n('File'), 'filelist_filename_' . $this->_id, 'filelist_filename');
 964:         $divContent[] = $this->generateFileSelect();
 965:         $image = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/but_art_new.gif');
 966:         $image->setAttribute('id', 'add_file');
 967:         $image->appendStyleDefinition('cursor', 'pointer');
 968:         $divContent[] = $image;
 969: 
 970:         $manualDiv->setContent($divContent);
 971:         $wrapperContent[] = $manualDiv;
 972: 
 973:         $wrapper->setContent($wrapperContent);
 974: 
 975:         return $wrapper->render();
 976:     }
 977: 
 978:     /**
 979:      * Generate a select box containing the already existing files in the manual
 980:      * tab.
 981:      *
 982:      * @return string
 983:      *         rendered cHTMLSelectElement
 984:      */
 985:     private function _generateExistingFileSelect() {
 986:         $tempSelectedFiles = $this->_settings['filelist_manual_files'];
 987: 
 988:         // Check if manual selected file exists, otherwise ignore them
 989:         // Write only existing files into selectedFiles array
 990:         // if (is_array($tempSelectedFiles)) {
 991:         //     foreach ($tempSelectedFiles as $filename) {
 992:         //         if (cFileHandler::exists($this->_uploadPath . $filename)) {
 993:         //             $selectedFiles[] = $filename;
 994:         //         }
 995:         //     }
 996:         // }
 997: 
 998:         // If we have wasted selected files, update settings
 999:         // if (count($tempSelectedFiles) != count($selectedFiles)) {
1000:         //     $this->_settings['filelist_manual_files'] = $selectedFiles;
1001:         //     $this->_storeSettings();
1002:         // }
1003: 
1004:         $htmlSelect = new cHTMLSelectElement('filelist_manual_files_' . $this->_id, '', 'filelist_manual_files_' . $this->_id, false, '', '', 'manual');
1005: 
1006:         if (is_array($this->_settings['filelist_manual_files'])) { // More than one entry
1007:             foreach ($this->_settings['filelist_manual_files'] as $selectedFile) {
1008:                 $splits = explode('/', $selectedFile);
1009:                 $splitCount = count($splits);
1010:                 $fileName = $splits[$splitCount - 1];
1011:                 $htmlSelectOption = new cHTMLOptionElement($fileName, $selectedFile, true);
1012:                 $htmlSelectOption->setAlt($fileName);
1013:                 $htmlSelect->appendOptionElement($htmlSelectOption);
1014:             }
1015:         } elseif (!empty($this->_settings['filelist_manual_files'])) { // Only one entry
1016:             $splits = explode('/', $this->_settings['filelist_manual_files']);
1017:             $splitCount = count($splits);
1018:             $fileName = $splits[$splitCount - 1];
1019:             $htmlSelectOption = new cHTMLOptionElement($fileName, $this->_settings['filelist_manual_files'], true);
1020:             $htmlSelectOption->setAlt($fileName);
1021:             $htmlSelect->appendOptionElement($htmlSelectOption);
1022:         }
1023: 
1024:         // set default values
1025:         $htmlSelect->setMultiselect();
1026:         $htmlSelect->setSize(5);
1027: 
1028:         return $htmlSelect->render();
1029:     }
1030: 
1031:     /**
1032:      * Generate a select box containing all files for the manual tab.
1033:      *
1034:      * @SuppressWarnings docBlocks
1035:      * @param string $directoryPath [optional]
1036:      *         Path to directory of the files
1037:      * @return string
1038:      *         rendered cHTMLSelectElement
1039:      */
1040:     public function generateFileSelect($directoryPath = '') {
1041:         $htmlSelect = new cHTMLSelectElement('filelist_filename_' . $this->_id, '', 'filelist_filename_' . $this->_id, false, '', '', 'filelist_filename');
1042: 
1043:         $files = array();
1044:         if ($directoryPath != '') {
1045:             $handle = cDirHandler::read($this->_uploadPath . $directoryPath);
1046:             if (false !== $handle) {
1047:                 foreach ($handle as $entry) {
1048:                     if (is_file($this->_uploadPath . $directoryPath . '/' . $entry)) {
1049:                         $file = array();
1050:                         $file["name"] = $entry;
1051:                         $file["path"] = $directoryPath . "/" . $entry;
1052:                         $files[] = $file;
1053:                     }
1054:                 }
1055:             }
1056:         }
1057: 
1058:         usort($files, function($a, $b) {
1059:             $a = cString::toLowerCase($a["name"]);
1060:             $b = cString::toLowerCase($b["name"]);
1061:             if($a < $b) {
1062:                 return -1;
1063:             } else if($a > $b) {
1064:                 return 1;
1065:             } else {
1066:                 return 0;
1067:             }
1068:         });
1069: 
1070:         $i = 0;
1071:         foreach($files as $file) {
1072:             $htmlSelectOption = new cHTMLOptionElement($file["name"], $file["path"]);
1073:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
1074:             $i++;
1075:         }
1076: 
1077:         if ($i === 0) {
1078:             $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '');
1079:             $htmlSelectOption->setAlt(i18n('No files found'));
1080:             $htmlSelectOption->setDisabled(true);
1081:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
1082:             $htmlSelect->setDisabled(true);
1083:             $htmlSelect->setDefault('');
1084:         }
1085: 
1086:         return $htmlSelect->render();
1087:     }
1088: 
1089:     /**
1090:      * Generates a directory list from the given directory information (which is
1091:      * typically built by {@link cContentTypeAbstract::buildDirectoryList}).
1092:      * Special modified for Ajax call
1093:      *
1094:      * @param array $dirs
1095:      *         directory information
1096:      *
1097:      * @return string
1098:      *         HTML code showing a directory list
1099:      * @throws cInvalidArgumentException
1100:      */
1101:     public function generateAjaxDirectoryList(array $dirs) {
1102:         $template = new cTemplate();
1103:         $i = 1;
1104: 
1105:         foreach ($dirs as $dirData) {
1106:             // set the active class if this is the chosen directory
1107:             $divClass = ($this->_isActiveDirectory($dirData)) ? 'active' : '';
1108:             $template->set('d', 'DIVCLASS', $divClass);
1109: 
1110:             $template->set('d', 'TITLE', $dirData['path'] . $dirData['name']);
1111:             $template->set('d', 'DIRNAME', $dirData['name']);
1112: 
1113:             $liClasses = array();
1114:             $template->set('d', 'SUBDIRLIST', $this->generateAjaxDirectoryList($dirData['sub']));
1115: 
1116:             if ($i === count($dirs)) {
1117:                 $liClasses[] = 'last';
1118:             }
1119:             $template->set('d', 'LICLASS', implode(' ', $liClasses));
1120: 
1121:             $i++;
1122:             $template->next();
1123:         }
1124: 
1125:         return $template->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_filelist_dirlistitem.html', true);
1126:     }
1127: 
1128: }
1129: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0