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