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