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