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
    • SIWECOS
    • 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:      * Returns a list of configured files.
 220:      * @return array
 221:      * @throws cDbException
 222:      * @throws cException
 223:      */
 224:     public function getConfiguredFiles() {
 225:         $files = [];
 226:         $fileList = [];
 227: 
 228:         if ($this->_settings['filelist_manual'] === 'true' && !empty($this->_settings['filelist_manual_files'])) {
 229:             $tempFileList = $this->_settings['filelist_manual_files'];
 230: 
 231:             // Check if manual selected file exists, otherwise ignore them. Write only existing files into fileList array.
 232:             // Manual selected setting can be a string or an array!
 233:             if (!is_array($tempFileList)) {
 234:                 $tempFileList = [$tempFileList];
 235:             }
 236:             foreach ($tempFileList as $filename) {
 237:                 if (cFileHandler::exists($this->_uploadPath . $filename)) {
 238:                     $fileList[] = $filename;
 239:                 }
 240:             }
 241:         } else if (is_array($this->_settings['filelist_directories']) && count($this->_settings['filelist_directories']) > 0) {
 242:             $directories = $this->_settings['filelist_directories'];
 243: 
 244:             if ($this->_settings['filelist_incl_subdirectories'] === 'true') {
 245:                 foreach ($directories as $directoryName) {
 246:                     $directories = $this->_getAllSubdirectories($directoryName, $directories);
 247:                 }
 248:             }
 249: 
 250:             // strip duplicate directories to save performance
 251:             $directories = array_unique($directories);
 252:             if (count($directories) < 1) {
 253:                 return [];
 254:             }
 255: 
 256:             foreach ($directories as $directoryName) {
 257:                 if (is_dir($this->_uploadPath . $directoryName)) {
 258:                     if (false !== $handle = cDirHandler::read($this->_uploadPath . $directoryName . '/', false, false, true)) {
 259:                         foreach ($handle as $entry) {
 260:                             $fileList[] = $directoryName . '/' . $entry;
 261:                         }
 262:                     }
 263:                 }
 264:             }
 265:         } else {
 266:             return [];
 267:         }
 268: 
 269:         if (count($fileList) > 0) {
 270:             $files = $this->_applyFileFilters($fileList);
 271:         }
 272:         unset($fileList);
 273: 
 274:         $limitedFiles = [];
 275:         if (count($files) > 0) {
 276:             // sort the files
 277:             if ($this->_settings['filelist_sortorder'] === 'desc') {
 278:                 krsort($files);
 279:             } else {
 280:                 ksort($files);
 281:             }
 282: 
 283:             $i = 1;
 284:             foreach ($files as $key => $filenameData) {
 285:                 if (($this->_settings['filelist_filecount'] != 0 && $i <= $this->_settings['filelist_filecount']) || $this->_settings['filelist_filecount'] == 0) {
 286:                     if ($this->_settings['filelist_incl_metadata'] === 'true') {
 287:                         $metaData = [];
 288:                         // load upload and upload meta object
 289:                         $upload = new cApiUpload();
 290:                         $upload->loadByMany([
 291:                             'filename' => $filenameData['filename'],
 292:                             'dirname' => $filenameData['path'] . '/',
 293:                             'idclient' => $this->_client
 294:                         ]);
 295:                         $uploadMeta = new cApiUploadMeta();
 296:                         $uploadMeta->loadByMany([
 297:                             'idupl' => $upload->get('idupl'),
 298:                             'idlang' => $this->_lang
 299:                         ]);
 300: 
 301:                         foreach ($this->_metaDataIdents as $identName => $translation) {
 302:                             $string = $uploadMeta->get($identName);
 303: 
 304:                             // Cut the string only, when the limit for identName
 305:                             // is active and the string length is more than the
 306:                             // setting
 307:                             if ($this->_settings['filelist_md_' . $identName . '_limit'] > 0 && cString::getStringLength($string) > $this->_settings['filelist_md_' . $identName . '_limit']) {
 308:                                 $metaData[$identName] = cString::trimAfterWord(cSecurity::unFilter($string), $this->_settings['filelist_md_' . $identName . '_limit']) . '...';
 309:                             } else {
 310:                                 $metaData[$identName] = cSecurity::unFilter($string);
 311:                             }
 312:                         }
 313: 
 314:                         $filenameData['metadata'] = $metaData;
 315:                     } else {
 316:                         $filenameData['metadata'] = [];
 317:                     }
 318: 
 319:                     // Define new array for files
 320:                     // If filelist_filecount is defined, this array has the same
 321:                     // size as "filelist_filecount" setting value (0 = no limit)
 322:                     $limitedFiles[$key] = $filenameData;
 323:                     $i++;
 324:                 }
 325:             }
 326:         }
 327: 
 328:         return $limitedFiles;
 329:     }
 330: 
 331:     /**
 332:      * Function is called in edit- and viewmode in order to generate code for
 333:      * output.
 334:      *
 335:      * @return string
 336:      *         generated code
 337:      * @throws cDbException
 338:      * @throws cException
 339:      * @throws cInvalidArgumentException
 340:      */
 341:     public function generateFileListCode() {
 342:         $code = '';
 343:         if ($this->_settings['filelist_style'] === '') {
 344:             return $code;
 345:         }
 346:         $template = new cTemplate();
 347:         $template->set('s', 'TITLE', conHtmlSpecialChars($this->_settings['filelist_title']));
 348: 
 349:         $files = $this->getConfiguredFiles();
 350: 
 351:         if (count($files) > 0) {
 352:             foreach ($files as $filenameData) {
 353:                 $this->_fillFileListTemplateEntry($filenameData, $template);
 354:             }
 355: 
 356:             // generate template
 357:             $code = $template->generate($this->_cfgClient[$this->_client]['path']['frontend'] . 'templates/' . $this->_settings['filelist_style'], true);
 358:         }
 359: 
 360:         return $code;
 361:     }
 362: 
 363:     /**
 364:      * Gets all subdirectories recursively.
 365:      *
 366:      * @param string $directoryPath
 367:      *         path to directory
 368:      * @param array $directories
 369:      *         already found directories
 370:      * @return array
 371:      *         containing all subdirectories and the initial directories
 372:      */
 373:     private function _getAllSubdirectories($directoryPath, array $directories) {
 374:         $handle = cDirHandler::read($this->_uploadPath . $directoryPath . '/', false, true);
 375: 
 376:         if (false !== $handle) {
 377:             foreach ($handle as $entry) {
 378:                 if (cFileHandler::fileNameBeginsWithDot($entry) === false) {
 379:                     $directories[] = $directoryPath . '/' . $entry;
 380:                     $directories = $this->_getAllSubdirectories($directoryPath . '/' . $entry, $directories);
 381:                 }
 382:             }
 383:         }
 384: 
 385:         return $directories;
 386:     }
 387: 
 388:     /**
 389:      * Removes all files not matching the filter criteria.
 390:      *
 391:      * @param array $fileList
 392:      *         files which should be filtered
 393:      * @return array
 394:      *         with filtered files
 395:      */
 396:     private function _applyFileFilters(array $fileList) {
 397:         $files = [];
 398:         foreach ($fileList as $fullName) {
 399:             $fileName = basename($fullName);
 400:             $directoryName = str_replace('/' . $fileName, '', $fullName);
 401: 
 402:             // checking the extension stuff
 403:             $extensionName = cFileHandler::getExtension($fileName);
 404:             $extensions = $this->_settings['filelist_extensions'];
 405:             if (!is_array($extensions)) {
 406:                 $extensions = [$extensions];
 407:             }
 408:             if ($this->_settings['filelist_ignore_extensions'] === 'true' || count($extensions) == 0
 409:                 || ($this->_settings['filelist_ignore_extensions'] === 'false' && in_array($extensionName, $extensions))
 410:                 || ($this->_settings['filelist_ignore_extensions'] === 'false' && $extensionName == $extensions)) {
 411: 
 412:                 // Prevent errors with not existing files
 413:                 if (!cFileHandler::exists($this->_uploadPath . $directoryName . '/' . $fileName)) {
 414:                     return [];
 415:                 }
 416: 
 417:                 // checking filesize filter
 418:                 $fileStats = stat($this->_uploadPath . $directoryName . '/' . $fileName);
 419:                 $fileSize = $fileStats['size'];
 420: 
 421:                 $fileSizeMib = $fileSize / 1024 / 1024;
 422:                 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)) {
 423: 
 424:                     if ($this->_applyDateFilters($fileStats)) {
 425:                         $creationDate = $fileStats['ctime'];
 426:                         $modifyDate = $fileStats['mtime'];
 427:                         // conditional stuff is completed, start sorting
 428:                         // inclusive fix CON_2605 for files created at the same time
 429:                         // or with the same filesize
 430:                         switch ($this->_settings['filelist_sort']) {
 431:                             case 'filesize':
 432:                                 if (!isset($files[$fileSize])) {
 433:                                     $indexName = $fileSize . "_" . mt_rand(0, mt_getrandmax());
 434:                                 } else {
 435:                                     $indexName = $fileSize;
 436:                                 }
 437:                                 break;
 438:                             case 'createdate':
 439:                                 if (!isset($files[$creationDate])) {
 440:                                     $indexName = $creationDate . "_" . mt_rand(0, mt_getrandmax());
 441:                                 } else {
 442:                                     $indexName = $creationDate;
 443:                                 }
 444:                                 break;
 445:                             case 'modifydate':
 446:                                 if (!isset($files[$modifyDate])) {
 447:                                     $indexName = $modifyDate . "_" . mt_rand(0, mt_getrandmax());
 448:                                 } else {
 449:                                     $indexName = $modifyDate;
 450:                                 }
 451:                                 break;
 452:                             case 'filename':
 453:                             default:
 454:                                 $indexName = cString::toLowerCase($directoryName . $fileName);
 455:                         }
 456: 
 457:                         $files[$indexName] = [];
 458:                         $files[$indexName]['filename'] = $fileName;
 459:                         $files[$indexName]['path'] = $directoryName;
 460:                         $files[$indexName]['extension'] = $extensionName;
 461:                         $files[$indexName]['filesize'] = $fileSize;
 462:                         $files[$indexName]['filemodifydate'] = $modifyDate;
 463:                         $files[$indexName]['filecreationdate'] = $creationDate;
 464:                     }
 465:                 }
 466:             }
 467:         }
 468: 
 469:         return $files;
 470:     }
 471: 
 472:     /**
 473:      * Checks whether the file passes the date filters.
 474:      *
 475:      * @param array $fileStats
 476:      *         file information
 477:      * @return bool
 478:      *         whether the file passes the date filters
 479:      */
 480:     private function _applyDateFilters(array $fileStats) {
 481:         foreach ($this->_dateFields as $index => $dateField) {
 482:             $date = $fileStats[$index];
 483:             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']) {
 484:                 return true;
 485:             }
 486:         }
 487: 
 488:         return false;
 489:     }
 490: 
 491:     /**
 492:      * Method to fill single entry (file) of the file list.
 493:      *
 494:      * @param array $fileData
 495:      *         information about the file
 496:      * @param cTemplate $template
 497:      *         reference to the used template object
 498:      */
 499:     private function _fillFileListTemplateEntry(array $fileData, cTemplate &$template) {
 500:         $filename = $fileData['filename'];
 501:         $directoryName = $fileData['path'];
 502: 
 503:         if (empty($filename) || empty($directoryName)) {
 504:             cWarning(__FILE__, __LINE__, "Empty directory '$directoryName' and or filename '$filename'");
 505:             return;
 506:         }
 507: 
 508:         $fileLink = $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $directoryName . '/' . $filename;
 509:         $filePath = $this->_cfgClient[$this->_client]['upl']['path'] . $directoryName . '/' . $filename;
 510: 
 511:         // If file is an image (extensions gif, jpg, jpeg, png) scale it
 512:         // otherwise use default png image
 513:         switch ($fileData['extension']) {
 514:             case 'gif':
 515:             case 'jpg':
 516:             case 'jpeg':
 517:             case 'png':
 518:                 $imgSrc = cApiImgScale($filePath, 148, 74);
 519:                 break;
 520:             default:
 521:                 $imgSrc = $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'images/misc/download_misc.png';
 522:                 break;
 523:         }
 524: 
 525:         $filesize = $fileData['filesize'];
 526:         $metaData = $fileData['metadata'];
 527: 
 528:         if ($this->_settings['filelist_incl_metadata'] === 'true' && count($metaData) != 0) {
 529:             $template->set('d', 'FILEMETA_DESCRIPTION', $metaData['description']);
 530:             $template->set('d', 'FILEMETA_MEDIANAME', $metaData['medianame']);
 531:             $template->set('d', 'FILEMETA_KEYWORDS', $metaData['keywords']);
 532:             $template->set('d', 'FILEMETA_INTERNAL_NOTICE', $metaData['internal_notice']);
 533:             $template->set('d', 'FILEMETA_COPYRIGHT', $metaData['copyright']);
 534:         } else {
 535:             $template->set('d', 'FILEMETA_DESCRIPTION', '');
 536:             $template->set('d', 'FILEMETA_MEDIANAME', '');
 537:             $template->set('d', 'FILEMETA_KEYWORDS', '');
 538:             $template->set('d', 'FILEMETA_INTERNAL_NOTICE', '');
 539:             $template->set('d', 'FILEMETA_COPYRIGHT', '');
 540:         }
 541: 
 542:         $template->set('d', 'FILETHUMB', $imgSrc);
 543:         $template->set('d', 'FILENAME', $filename);
 544:         $template->set('d', 'FILESIZE', humanReadableSize($filesize));
 545:         $template->set('d', 'FILEEXTENSION', $fileData['extension']);
 546:         $template->set('d', 'FILECREATIONDATE', date('d.m.Y', $fileData['filecreationdate']));
 547:         $template->set('d', 'FILEMODIFYDATE', date('d.m.Y', $fileData['filemodifydate']));
 548:         $template->set('d', 'FILEDIRECTORY', $directoryName);
 549:         $template->set('d', 'FILELINK', $fileLink);
 550: 
 551:         foreach (self::$_translations as $translationString) {
 552:             $template->set('d', $translationString, mi18n($translationString));
 553:         }
 554: 
 555:         $template->next();
 556:     }
 557: 
 558:     /**
 559:      * Generates the code which should be shown if this content type is edited.
 560:      *
 561:      * @return string
 562:      *         escaped HTML code which should be shown if content type is edited
 563:      * @throws cInvalidArgumentException
 564:      */
 565:     public function generateEditCode() {
 566:         $template = new cTemplate();
 567:         $template->set('s', 'ID', $this->_id);
 568:         $template->set('s', 'IDARTLANG', $this->_idArtLang);
 569:         $template->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
 570: 
 571:         $templateTabs = new cTemplate();
 572:         $templateTabs->set('s', 'PREFIX', $this->_prefix);
 573: 
 574:         // create code for external tab
 575:         $templateTabs->set('d', 'TAB_ID', 'directories');
 576:         $templateTabs->set('d', 'TAB_CLASS', 'directories');
 577:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabDirectories());
 578:         $templateTabs->next();
 579: 
 580:         // create code for internal tab
 581:         $templateTabs->set('d', 'TAB_ID', 'general');
 582:         $templateTabs->set('d', 'TAB_CLASS', 'general');
 583:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabGeneral());
 584:         $templateTabs->next();
 585: 
 586:         // create code for file tab
 587:         $templateTabs->set('d', 'TAB_ID', 'filter');
 588:         $templateTabs->set('d', 'TAB_CLASS', 'filter');
 589:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabFilter());
 590:         $templateTabs->next();
 591: 
 592:         // create code for manual tab
 593:         $templateTabs->set('d', 'TAB_ID', 'manual');
 594:         $templateTabs->set('d', 'TAB_CLASS', 'manual');
 595:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabManual());
 596:         $templateTabs->next();
 597: 
 598:         $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
 599: 
 600:         // construct the top code of the template
 601:         $templateTop = new cTemplate();
 602:         $templateTop->set('s', 'ICON', 'images/but_editlink.gif');
 603:         $templateTop->set('s', 'ID', $this->_id);
 604:         $templateTop->set('s', 'PREFIX', $this->_prefix);
 605:         $templateTop->set('s', 'HEADLINE', i18n('File list settings'));
 606:         $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
 607: 
 608:         // define the available tabs
 609:         $tabMenu = array(
 610:             'directories' => i18n('Directories'),
 611:             'general' => i18n('General'),
 612:             'filter' => i18n('Filter'),
 613:             'manual' => i18n('Manual')
 614:         );
 615: 
 616:         // construct the bottom code of the template
 617:         $templateBottom = new cTemplate();
 618:         $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
 619:         $templateBottom->set('s', 'ID', $this->_id);
 620:         $templateBottom->set('s', 'PREFIX', $this->_prefix);
 621:         $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
 622:         $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
 623:         $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
 624:         $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsFilelist.js');
 625:         $templateBottom->set('s', 'JS_CLASS_NAME', 'Con.cContentTypeFilelist');
 626:         $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
 627: 
 628:         // construct the whole template code
 629:         $code = $this->generateViewCode();
 630:         $code .= $this->_encodeForOutput($codeTop);
 631:         $code .= $this->_generateTabMenuCode($tabMenu);
 632:         $code .= $this->_encodeForOutput($codeTabs);
 633:         $code .= $this->_generateActionCode();
 634:         $code .= $this->_encodeForOutput($codeBottom);
 635: 
 636:         return $code;
 637:     }
 638: 
 639:     /**
 640:      * Generates code for the directories tab.
 641:      *
 642:      * @return string
 643:      *         the code for the directories tab
 644:      * @throws cInvalidArgumentException
 645:      */
 646:     private function _generateTabDirectories() {
 647:         // wrapper containing content of directories tab
 648:         $wrapper = new cHTMLDiv();
 649:         $wrapperContent = array();
 650: 
 651:         $wrapperContent[] = new cHTMLParagraph(i18n('Source directory'), 'head_sub');
 652: 
 653:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
 654:         $liRoot = new cHTMLListItem('root', 'root last');
 655:         $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
 656:         $liRoot->setContent(array(
 657:             '<em>Uploads</em>',
 658:             $directoryListCode
 659:         ));
 660:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
 661:         $directoryList->setContent($conStrTree);
 662:         $wrapperContent[] = $directoryList;
 663: 
 664:         $wrapper->setContent($wrapperContent);
 665: 
 666:         return $wrapper->render();
 667:     }
 668: 
 669:     /**
 670:      * Generates code for the general tab.
 671:      *
 672:      * @return string
 673:      *         the code for the general link tab
 674:      * @throws cInvalidArgumentException
 675:      */
 676:     private function _generateTabGeneral() {
 677:         // wrapper containing content of general tab
 678:         $wrapper = new cHTMLDiv();
 679:         $wrapperContent = array();
 680: 
 681:         $wrapperContent[] = new cHTMLParagraph(i18n('General settings'), 'head_sub');
 682: 
 683:         $wrapperContent[] = new cHTMLLabel(i18n('File list title'), 'filelist_title_' . $this->_id);
 684:         $wrapperContent[] = new cHTMLTextbox('filelist_title_' . $this->_id, conHtmlSpecialChars($this->_settings['filelist_title']), '', '', 'filelist_title_' . $this->_id);
 685:         $wrapperContent[] = new cHTMLLabel(i18n('File list style'), 'filelist_style_' . $this->_id);
 686:         $wrapperContent[] = $this->_generateStyleSelect();
 687:         $wrapperContent[] = new cHTMLLabel(i18n('File list sort'), 'filelist_sort_' . $this->_id);
 688:         $wrapperContent[] = $this->_generateSortSelect();
 689:         $wrapperContent[] = new cHTMLLabel(i18n('Sort order'), 'filelist_sortorder_' . $this->_id);
 690:         $wrapperContent[] = $this->_generateSortOrderSelect();
 691:         $wrapperContent[] = new cHTMLLabel(i18n('Include subdirectories?'), 'filelist_incl_subdirectories_' . $this->_id);
 692:         $wrapperContent[] = new cHTMLCheckbox('filelist_incl_subdirectories_' . $this->_id, '', 'filelist_incl_subdirectories_' . $this->_id, ($this->_settings['filelist_incl_subdirectories'] === 'true'));
 693:         $wrapperContent[] = new cHTMLLabel(i18n('Include meta data?'), 'filelist_incl_metadata_' . $this->_id);
 694:         $wrapperContent[] = new cHTMLCheckbox('filelist_incl_metadata_' . $this->_id, '', 'filelist_incl_metadata_' . $this->_id, ($this->_settings['filelist_incl_metadata'] === 'true'));
 695:         $div = new cHTMLDiv($this->_generateMetaDataList());
 696:         $div->setID('metaDataList');
 697:         $wrapperContent[] = $div;
 698: 
 699:         $wrapper->setContent($wrapperContent);
 700: 
 701:         return $wrapper->render();
 702:     }
 703: 
 704:     /**
 705:      * Generates a select box containing the filelist styles.
 706:      *
 707:      * @return string
 708:      *         rendered cHTMLSelectElement
 709:      */
 710:     private function _generateStyleSelect() {
 711:         $htmlSelect = new cHTMLSelectElement('filelist_style_' . $this->_id, '', 'filelist_style_' . $this->_id);
 712: 
 713:         $htmlSelectOption = new cHTMLOptionElement(i18n('Default style'), 'cms_filelist_style_default.html', true);
 714:         $htmlSelect->appendOptionElement($htmlSelectOption);
 715:         $additionalOptions = getEffectiveSettingsByType('cms_filelist_style');
 716:         $options = array();
 717:         foreach ($additionalOptions as $key => $value) {
 718:             $options[$value] = $key;
 719:         }
 720:         $htmlSelect->autoFill($options);
 721:         $htmlSelect->setDefault($this->_settings['filelist_style']);
 722:         return $htmlSelect->render();
 723:     }
 724: 
 725:     /**
 726:      * Generates a select box containing the sort options.
 727:      *
 728:      * @return string
 729:      *         rendered cHTMLSelectElement
 730:      */
 731:     private function _generateSortSelect() {
 732:         $htmlSelect = new cHTMLSelectElement('filelist_sort_' . $this->_id, '', 'filelist_sort_' . $this->_id);
 733: 
 734:         $htmlSelectOption = new cHTMLOptionElement(i18n('File name'), 'filename', true);
 735:         $htmlSelect->appendOptionElement($htmlSelectOption);
 736: 
 737:         $htmlSelectOption = new cHTMLOptionElement(i18n('File size'), 'filesize', false);
 738:         $htmlSelect->appendOptionElement($htmlSelectOption);
 739: 
 740:         $htmlSelectOption = new cHTMLOptionElement(i18n('Date created'), 'createdate', false);
 741:         $htmlSelect->appendOptionElement($htmlSelectOption);
 742: 
 743:         $htmlSelectOption = new cHTMLOptionElement(i18n('Date modified'), 'modifydate', false);
 744:         $htmlSelect->appendOptionElement($htmlSelectOption);
 745: 
 746:         $htmlSelect->setDefault($this->_settings['filelist_sort']);
 747: 
 748:         return $htmlSelect->render();
 749:     }
 750: 
 751:     /**
 752:      * Generates a select box containing the sort order options (asc/desc).
 753:      *
 754:      * @return string
 755:      *         rendered cHTMLSelectElement
 756:      */
 757:     private function _generateSortOrderSelect() {
 758:         $htmlSelect = new cHTMLSelectElement('filelist_sortorder_' . $this->_id, '', 'filelist_sortorder_' . $this->_id);
 759: 
 760:         $htmlSelectOption = new cHTMLOptionElement(i18n('Ascending'), 'asc', true);
 761:         $htmlSelect->appendOptionElement($htmlSelectOption);
 762: 
 763:         $htmlSelectOption = new cHTMLOptionElement(i18n('Descending'), 'desc', false);
 764:         $htmlSelect->appendOptionElement($htmlSelectOption);
 765: 
 766:         // set default value
 767:         $htmlSelect->setDefault($this->_settings['filelist_sortorder']);
 768: 
 769:         return $htmlSelect->render();
 770:     }
 771: 
 772:     /**
 773:      * Generates a list of meta data.
 774:      *
 775:      * @return string
 776:      *         HTML code showing a list of meta data
 777:      * @throws cInvalidArgumentException
 778:      */
 779:     private function _generateMetaDataList() {
 780:         $template = new cTemplate();
 781: 
 782:         foreach ($this->_metaDataIdents as $identName => $translation) {
 783:             $metaDataLimit = $this->_settings['filelist_md_' . $identName . '_limit'];
 784:             if (!isset($metaDataLimit) || $metaDataLimit === '') {
 785:                 $metaDataLimit = 0;
 786:             }
 787: 
 788:             $template->set('d', 'METADATA_NAME', $identName);
 789:             $template->set('d', 'METADATA_DISPLAYNAME', i18n($translation));
 790:             $template->set('d', 'METADATA_LIMIT', $metaDataLimit);
 791:             $template->set('d', 'ID', $this->_id);
 792: 
 793:             $template->next();
 794:         }
 795: 
 796:         return $template->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_filelist_metadata_limititem.html', true);
 797:     }
 798: 
 799:     /**
 800:      * Generates code for the filter tab.
 801:      *
 802:      * @return string
 803:      *         the code for the filter link tab
 804:      */
 805:     private function _generateTabFilter() {
 806:         // wrapper containing content of filter tab
 807:         $wrapper = new cHTMLDiv();
 808:         $wrapperContent = array();
 809: 
 810:         $wrapperContent[] = new cHTMLParagraph(i18n('Filter settings'), 'head_sub');
 811: 
 812:         $wrapperContent[] = new cHTMLLabel(i18n('Displayed file extensions'), 'filelist_extensions_' . $this->_id);
 813:         $wrapperContent[] = $this->_generateExtensionSelect();
 814:         $wrapperContent[] = '<br>';
 815:         $link = new cHTMLLink('#');
 816:         $link->setID('filelist_all_extensions');
 817:         $link->setContent(i18n('Select all entries'));
 818:         $wrapperContent[] = $link;
 819:         $wrapperContent[] = new cHTMLLabel(i18n('Ignore selection (use all)'), 'filelist_ignore_extensions_' . $this->_id, 'filelist_ignore_extensions');
 820:         $wrapperContent[] = new cHTMLCheckbox('filelist_ignore_extensions_' . $this->_id, '', 'filelist_ignore_extensions_' . $this->_id, ($this->_settings['filelist_ignore_extensions'] !== 'false'));
 821: 
 822:         $wrapperContent[] = new cHTMLLabel(i18n('File size limit (in MiB)'), 'filelist_filesizefilter_from_' . $this->_id);
 823:         $default = (!empty($this->_settings['filelist_filesizefilter_from'])) ? $this->_settings['filelist_filesizefilter_from'] : '0';
 824:         $wrapperContent[] = new cHTMLTextbox('filelist_filesizefilter_from_' . $this->_id, $default, '', '', 'filelist_filesizefilter_from_' . $this->_id);
 825:         $wrapperContent[] = new cHTMLSpan('&nbsp;-&nbsp;');
 826:         $default = (!empty($this->_settings['filelist_filesizefilter_to'])) ? $this->_settings['filelist_filesizefilter_to'] : '0';
 827:         $wrapperContent[] = new cHTMLTextbox('filelist_filesizefilter_to_' . $this->_id, $default, '', '', 'filelist_filesizefilter_to_' . $this->_id);
 828: 
 829:         $wrapperContent[] = new cHTMLLabel(i18n('Creation date limit'), 'filelist_creationdatefilter_from_' . $this->_id);
 830:         $default = (!empty($this->_settings['filelist_creationdatefilter_from'])) ? $this->_settings['filelist_creationdatefilter_from'] : 'DD.MM.YYYY';
 831:         $wrapperContent[] = new cHTMLTextbox('filelist_creationdatefilter_from_' . $this->_id, $default, '', '', 'filelist_creationdatefilter_from_' . $this->_id);
 832:         $wrapperContent[] = new cHTMLSpan('&nbsp;-&nbsp;');
 833:         $default = (!empty($this->_settings['filelist_creationdatefilter_to'])) ? $this->_settings['filelist_creationdatefilter_to'] : 'DD.MM.YYYY';
 834:         $wrapperContent[] = new cHTMLTextbox('filelist_creationdatefilter_to_' . $this->_id, $default, '', '', 'filelist_creationdatefilter_to_' . $this->_id);
 835: 
 836:         $wrapperContent[] = new cHTMLLabel(i18n('Modify date limit'), 'filelist_modifydatefilter_from_' . $this->_id);
 837:         $default = (!empty($this->_settings['filelist_modifydatefilter_from'])) ? $this->_settings['filelist_modifydatefilter_from'] : 'DD.MM.YYYY';
 838:         $wrapperContent[] = new cHTMLTextbox('filelist_modifydatefilter_from_' . $this->_id, $default, '', '', 'filelist_modifydatefilter_from_' . $this->_id);
 839:         $wrapperContent[] = new cHTMLSpan('&nbsp;-&nbsp;');
 840:         $default = (!empty($this->_settings['filelist_modifydatefilter_to'])) ? $this->_settings['filelist_modifydatefilter_to'] : 'DD.MM.YYYY';
 841:         $wrapperContent[] = new cHTMLTextbox('filelist_modifydatefilter_to_' . $this->_id, $default, '', '', 'filelist_modifydatefilter_to_' . $this->_id);
 842: 
 843:         $wrapperContent[] = new cHTMLLabel(i18n('File count'), 'filelist_filecount_' . $this->_id);
 844:         $default = (!empty($this->_settings['filelist_filecount'])) ? $this->_settings['filelist_filecount'] : '0';
 845:         $wrapperContent[] = new cHTMLTextbox('filelist_filecount_' . $this->_id, $default, '', '', 'filelist_filecount_' . $this->_id);
 846: 
 847:         $wrapper->setContent($wrapperContent);
 848: 
 849:         return $wrapper->render();
 850:     }
 851: 
 852:     /**
 853:      * Generates a select box containing the file extensions.
 854:      *
 855:      * @return string
 856:      *         rendered cHTMLSelectElement
 857:      */
 858:     private function _generateExtensionSelect() {
 859:         $htmlSelect = new cHTMLSelectElement('filelist_extensions_' . $this->_id, '', 'filelist_extensions_' . $this->_id, ($this->_settings['filelist_ignore_extensions'] !== 'false'), '', '', 'manual');
 860: 
 861:         // set other avariable options manually
 862:         foreach ($this->_fileExtensions as $fileExtension) {
 863:             $htmlSelectOption = new cHTMLOptionElement(uplGetFileTypeDescription($fileExtension) . ' (.' . $fileExtension . ')', $fileExtension, false);
 864:             $htmlSelectOption->setAlt(uplGetFileTypeDescription($fileExtension) . ' (.' . $fileExtension . ')');
 865:             $htmlSelect->appendOptionElement($htmlSelectOption);
 866:         }
 867: 
 868:         $additionalOptions = getEffectiveSettingsByType('cms_filelist_extensions');
 869:         foreach ($additionalOptions as $label => $extension) {
 870:             $htmlSelectOption = new cHTMLOptionElement($label . ' (.' . $extension . ')', $extension);
 871:             $htmlSelectOption->setAlt($label . ' (.' . $extension . ')');
 872:             $htmlSelect->appendOptionElement($htmlSelectOption);
 873:         }
 874: 
 875:         // set default values
 876:         $extensions = (is_array($this->_settings['filelist_extensions'])) ? $this->_settings['filelist_extensions'] : array(
 877:             $this->_settings['filelist_extensions']
 878:         );
 879:         $htmlSelect->setSelected($extensions);
 880:         $htmlSelect->setMultiselect();
 881:         $htmlSelect->setSize(5);
 882: 
 883:         return $htmlSelect->render();
 884:     }
 885: 
 886:     /**
 887:      * Checks whether the directory defined by the given directory
 888:      * information is the currently active directory.
 889:      *
 890:      * @param array $dirData
 891:      *         directory information
 892:      * @return bool
 893:      *         whether the directory is the currently active directory
 894:      */
 895:     protected function _isActiveDirectory(array $dirData) {
 896:         return is_array($this->_settings['filelist_directories']) && in_array($dirData['path'] . $dirData['name'], $this->_settings['filelist_directories']);
 897:     }
 898: 
 899:     /**
 900:      * Checks whether the directory defined by the given directory information
 901:      * should be shown expanded.
 902:      *
 903:      * @param array $dirData
 904:      *         directory information
 905:      * @return bool
 906:      *         whether the directory should be shown expanded
 907:      */
 908:     protected function _shouldDirectoryBeExpanded(array $dirData) {
 909:         if (is_array($this->_settings['filelist_directories'])) {
 910:             foreach ($this->_settings['filelist_directories'] as $directoryName) {
 911:                 if (preg_match('#^' . $dirData['path'] . $dirData['name'] . '/.*#', $directoryName)) {
 912:                     return true;
 913:                 }
 914:             }
 915:         }
 916: 
 917:         return false;
 918:     }
 919: 
 920:     /**
 921:      * Generates code for the manual tab.
 922:      *
 923:      * @return string
 924:      *         the code for the manual link tab
 925:      * @throws cInvalidArgumentException
 926:      */
 927:     private function _generateTabManual() {
 928:         // wrapper containing content of manual tab
 929:         $wrapper = new cHTMLDiv();
 930:         $wrapperContent = array();
 931: 
 932:         $wrapperContent[] = new cHTMLParagraph(i18n('Manual settings'), 'head_sub');
 933: 
 934:         $wrapperContent[] = new cHTMLLabel(i18n('Use manual file list?'), 'filelist_manual_' . $this->_id);
 935:         $wrapperContent[] = new cHTMLCheckbox('filelist_manual_' . $this->_id, '', 'filelist_manual_' . $this->_id, ($this->_settings['filelist_manual'] === 'true'));
 936: 
 937:         $manualDiv = new cHTMLDiv();
 938:         $manualDiv->setID('manual_filelist_setting');
 939:         $manualDiv->appendStyleDefinition('display', 'none');
 940:         $divContent = array();
 941:         $divContent[] = new cHTMLParagraph(i18n('Existing files'), 'head_sub');
 942:         $divContent[] = $this->_generateExistingFileSelect();
 943:         $divContent[] = new cHTMLSpan(i18n('Already configured entries can be deleted by using double click'), 'filelist_manual_' . $this->_id);
 944:         $divContent[] = new CHTMLSpan('<br><br>', 'filelist_manual_' . $this->_id);
 945:         $divContent[] = new cHTMLParagraph(i18n('Add file'), 'head_sub');
 946:         $divContent[] = new cHTMLLabel(i18n('Directory'), '');
 947: 
 948:         // directory navigation
 949:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList_' . $this->_id . '_manual');
 950:         $liRoot = new cHTMLListItem('root', 'last');
 951:         $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
 952:         $liRoot->setContent(array(
 953:             '<em>Uploads</em>',
 954:             $directoryListCode
 955:         ));
 956:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
 957:         $directoryList->setContent($conStrTree);
 958:         $divContent[] = $directoryList;
 959: 
 960:         $divContent[] = new cHTMLLabel(i18n('File'), 'filelist_filename_' . $this->_id, 'filelist_filename');
 961:         $divContent[] = $this->generateFileSelect();
 962:         $image = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/but_art_new.gif');
 963:         $image->setAttribute('id', 'add_file');
 964:         $image->appendStyleDefinition('cursor', 'pointer');
 965:         $divContent[] = $image;
 966: 
 967:         $manualDiv->setContent($divContent);
 968:         $wrapperContent[] = $manualDiv;
 969: 
 970:         $wrapper->setContent($wrapperContent);
 971: 
 972:         return $wrapper->render();
 973:     }
 974: 
 975:     /**
 976:      * Generate a select box containing the already existing files in the manual
 977:      * tab.
 978:      *
 979:      * @return string
 980:      *         rendered cHTMLSelectElement
 981:      */
 982:     private function _generateExistingFileSelect() {
 983:         $tempSelectedFiles = $this->_settings['filelist_manual_files'];
 984: 
 985:         // Check if manual selected file exists, otherwise ignore them
 986:         // Write only existing files into selectedFiles array
 987:         // if (is_array($tempSelectedFiles)) {
 988:         //     foreach ($tempSelectedFiles as $filename) {
 989:         //         if (cFileHandler::exists($this->_uploadPath . $filename)) {
 990:         //             $selectedFiles[] = $filename;
 991:         //         }
 992:         //     }
 993:         // }
 994: 
 995:         // If we have wasted selected files, update settings
 996:         // if (count($tempSelectedFiles) != count($selectedFiles)) {
 997:         //     $this->_settings['filelist_manual_files'] = $selectedFiles;
 998:         //     $this->_storeSettings();
 999:         // }
1000: 
1001:         $htmlSelect = new cHTMLSelectElement('filelist_manual_files_' . $this->_id, '', 'filelist_manual_files_' . $this->_id, false, '', '', 'manual');
1002: 
1003:         if (is_array($this->_settings['filelist_manual_files'])) { // More than one entry
1004:             foreach ($this->_settings['filelist_manual_files'] as $selectedFile) {
1005:                 $splits = explode('/', $selectedFile);
1006:                 $splitCount = count($splits);
1007:                 $fileName = $splits[$splitCount - 1];
1008:                 $htmlSelectOption = new cHTMLOptionElement($fileName, $selectedFile, true);
1009:                 $htmlSelectOption->setAlt($fileName);
1010:                 $htmlSelect->appendOptionElement($htmlSelectOption);
1011:             }
1012:         } elseif (!empty($this->_settings['filelist_manual_files'])) { // Only one entry
1013:             $splits = explode('/', $this->_settings['filelist_manual_files']);
1014:             $splitCount = count($splits);
1015:             $fileName = $splits[$splitCount - 1];
1016:             $htmlSelectOption = new cHTMLOptionElement($fileName, $this->_settings['filelist_manual_files'], true);
1017:             $htmlSelectOption->setAlt($fileName);
1018:             $htmlSelect->appendOptionElement($htmlSelectOption);
1019:         }
1020: 
1021:         // set default values
1022:         $htmlSelect->setMultiselect();
1023:         $htmlSelect->setSize(5);
1024: 
1025:         return $htmlSelect->render();
1026:     }
1027: 
1028:     /**
1029:      * Generate a select box containing all files for the manual tab.
1030:      *
1031:      * @SuppressWarnings docBlocks
1032:      * @param string $directoryPath [optional]
1033:      *         Path to directory of the files
1034:      * @return string
1035:      *         rendered cHTMLSelectElement
1036:      */
1037:     public function generateFileSelect($directoryPath = '') {
1038:         $htmlSelect = new cHTMLSelectElement('filelist_filename_' . $this->_id, '', 'filelist_filename_' . $this->_id, false, '', '', 'filelist_filename');
1039: 
1040:         $files = array();
1041:         if ($directoryPath != '') {
1042:             $handle = cDirHandler::read($this->_uploadPath . $directoryPath);
1043:             if (false !== $handle) {
1044:                 foreach ($handle as $entry) {
1045:                     if (is_file($this->_uploadPath . $directoryPath . '/' . $entry)) {
1046:                         $file = array();
1047:                         $file["name"] = $entry;
1048:                         $file["path"] = $directoryPath . "/" . $entry;
1049:                         $files[] = $file;
1050:                     }
1051:                 }
1052:             }
1053:         }
1054: 
1055:         usort($files, function($a, $b) {
1056:             $a = cString::toLowerCase($a["name"]);
1057:             $b = cString::toLowerCase($b["name"]);
1058:             if($a < $b) {
1059:                 return -1;
1060:             } else if($a > $b) {
1061:                 return 1;
1062:             } else {
1063:                 return 0;
1064:             }
1065:         });
1066: 
1067:         $i = 0;
1068:         foreach($files as $file) {
1069:             $htmlSelectOption = new cHTMLOptionElement($file["name"], $file["path"]);
1070:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
1071:             $i++;
1072:         }
1073: 
1074:         if ($i === 0) {
1075:             $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '');
1076:             $htmlSelectOption->setAlt(i18n('No files found'));
1077:             $htmlSelectOption->setDisabled(true);
1078:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
1079:             $htmlSelect->setDisabled(true);
1080:             $htmlSelect->setDefault('');
1081:         }
1082: 
1083:         return $htmlSelect->render();
1084:     }
1085: 
1086:     /**
1087:      * Generates a directory list from the given directory information (which is
1088:      * typically built by {@link cContentTypeAbstract::buildDirectoryList}).
1089:      * Special modified for Ajax call
1090:      *
1091:      * @param array $dirs
1092:      *         directory information
1093:      *
1094:      * @return string
1095:      *         HTML code showing a directory list
1096:      * @throws cInvalidArgumentException
1097:      */
1098:     public function generateAjaxDirectoryList(array $dirs) {
1099:         $template = new cTemplate();
1100:         $i = 1;
1101: 
1102:         foreach ($dirs as $dirData) {
1103:             // set the active class if this is the chosen directory
1104:             $divClass = ($this->_isActiveDirectory($dirData)) ? 'active' : '';
1105:             $template->set('d', 'DIVCLASS', $divClass);
1106: 
1107:             $template->set('d', 'TITLE', $dirData['path'] . $dirData['name']);
1108:             $template->set('d', 'DIRNAME', $dirData['name']);
1109: 
1110:             $liClasses = array();
1111:             $template->set('d', 'SUBDIRLIST', $this->generateAjaxDirectoryList($dirData['sub']));
1112: 
1113:             if ($i === count($dirs)) {
1114:                 $liClasses[] = 'last';
1115:             }
1116:             $template->set('d', 'LICLASS', implode(' ', $liClasses));
1117: 
1118:             $i++;
1119:             $template->next();
1120:         }
1121: 
1122:         return $template->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_filelist_dirlistitem.html', true);
1123:     }
1124: 
1125: }
1126: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0