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