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