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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

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