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