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