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