1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: cInclude('includes', 'functions.con.php');
18: cInclude('includes', 'functions.upl.php');
19:
20: 21: 22: 23: 24: 25: 26:
27: class cContentTypeFilelist extends cContentTypeAbstractTabbed {
28:
29: 30: 31: 32: 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: 49: 50: 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: 62: 63: 64:
65: private $_dateFields = array(
66: 'ctime' => 'creationdate',
67: 'mtime' => 'modifydate'
68: );
69:
70: 71: 72: 73: 74: 75:
76: protected static $_translations = array(
77: "LABEL_FILESIZE",
78: "LABEL_UPLOAD_DATE"
79: );
80:
81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91:
92: function __construct($rawSettings, $id, array $contentTypes) {
93:
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:
117: foreach ($this->_metaDataIdents as $identName => $translation) {
118: $this->_formFields[] = 'filelist_md_' . $identName . '_limit';
119: }
120:
121:
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:
131:
132:
133: if (isset($_POST['filelist_action']) && $_POST['filelist_action'] === 'store' && isset($_POST['filelist_id']) && (int) $_POST['filelist_id'] == $this->_id) {
134:
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: 151: 152: 153: 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: 165: 166: 167:
168: protected function _readSettings() {
169: parent::_readSettings();
170:
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: 189: 190: 191: 192: 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: 208: 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:
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:
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:
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:
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: 305: 306: 307: 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:
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: 334: 335: 336: 337: 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: 354: 355: 356: 357:
358: private function _applyFileFilters(array $fileList) {
359: foreach ($fileList as $fullname) {
360: $filename = basename($fullname);
361: $directoryName = str_replace('/' . $filename, '', $fullname);
362:
363:
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:
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:
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: 410: 411: 412: 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: 427: 428: 429: 430: 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:
444:
445:
446:
447:
448:
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: 487: 488: 489: 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:
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:
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:
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:
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:
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:
538: $tabMenu = array(
539: 'directories' => i18n('Directories'),
540: 'general' => i18n('General'),
541: 'filter' => i18n('Filter'),
542: 'manual' => i18n('Manual')
543: );
544:
545:
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:
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: 572: 573: 574:
575: private function _generateTabDirectories() {
576:
577:
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: 601: 602: 603:
604: private function _generateTabGeneral() {
605:
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: 634: 635: 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: 654: 655: 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: 679: 680: 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:
692: $htmlSelect->setDefault($this->_settings['filelist_sortorder']);
693:
694: return $htmlSelect->render();
695: }
696:
697: 698: 699: 700: 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: 724: 725: 726:
727: private function _generateTabFilter() {
728:
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(' - ');
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(' - ');
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(' - ');
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: 776: 777: 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:
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:
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: 807: 808: 809: 810: 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: 818: 819: 820: 821: 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: 837: 838: 839:
840: private function _generateTabManual() {
841:
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:
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: 890: 891: 892: 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:
910: $htmlSelect->setMultiselect();
911: $htmlSelect->setSize(5);
912:
913: return $htmlSelect->render();
914: }
915:
916: 917: 918: 919: 920: 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: }