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