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