Overview

Packages

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