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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

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