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: class cContentTypeLinkeditor extends cContentTypeAbstractTabbed {
27:
28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
39: function __construct($rawSettings, $id, array $contentTypes) {
40:
41: $this->_type = 'CMS_LINKEDITOR';
42: $this->_prefix = 'linkeditor';
43: $this->_settingsType = self::SETTINGS_TYPE_XML;
44: $this->_formFields = array(
45: 'linkeditor_type',
46: 'linkeditor_externallink',
47: 'linkeditor_title',
48: 'linkeditor_newwindow',
49: 'linkeditor_idart',
50: 'linkeditor_filename'
51: );
52:
53:
54: $rawSettings = conHtmlEntityDecode($rawSettings);
55: $rawSettings = utf8_encode($rawSettings);
56: parent::__construct($rawSettings, $id, $contentTypes);
57: $this->_settings['linkeditor_title'] = utf8_decode($this->_settings['linkeditor_title']);
58: $this->_settings['linkeditor_title'] = conHtmlentities($this->_settings['linkeditor_title']);
59:
60:
61:
62:
63: if (isset($_POST['linkeditor_action']) && $_POST['linkeditor_action'] === 'store' && isset($_POST['linkeditor_id']) && (int) $_POST['linkeditor_id'] == $this->_id) {
64:
65:
66: $_POST['linkeditor_title'] = conHtmlentities(conHtmlEntityDecode($_POST['linkeditor_title']));
67: $this->_storeSettings();
68: }
69: }
70:
71: 72: 73: 74: 75: 76: 77:
78: public function getConfiguredData() {
79: $data = array(
80: 'type' => $this->_settings['linkeditor_type'],
81: 'externallink' => $this->_settings['linkeditor_externallink'],
82: 'title' => $this->_settings['linkeditor_title'],
83: 'newwindow' => $this->_settings['linkeditor_newwindow'],
84: 'idart' => $this->_settings['linkeditor_idart'],
85: 'filename' => $this->_settings['linkeditor_filename'],
86: 'href' => $this->_generateHref()
87: );
88:
89: return $data;
90: }
91:
92: 93: 94: 95: 96: 97: 98:
99: public function generateViewCode() {
100:
101: $href = $this->_generateHref();
102: if (empty($href)) {
103: return '';
104: }
105: $linktext = $this->_settings['linkeditor_title'];
106: $alt = $linktext;
107:
108: if (empty($linktext)) {
109: $linktext = $href;
110: }
111: $target = ($this->_settings['linkeditor_newwindow'] === 'true')? '_blank' : '';
112:
113: $link = new cHTMLLink($href);
114: $link->setAlt($alt);
115: $link->setTargetFrame($target);
116: $link->setContent($linktext);
117:
118: return $this->_encodeForOutput($link->render());
119: }
120:
121: 122: 123: 124: 125:
126: protected function _generateHref() {
127: switch ($this->_settings['linkeditor_type']) {
128: case 'external':
129:
130: $link = $this->_settings['linkeditor_externallink'];
131: if (strpos($link, 'http://') !== 0 && strpos($link, 'www.') === 0) {
132: $link = 'http://' . $link;
133: }
134: return $link;
135: break;
136: case 'internal':
137: if ($this->_settings['linkeditor_idart'] != "") {
138: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'front_content.php?idart=' . $this->_settings['linkeditor_idart'];
139: }
140: break;
141: case 'file':
142: return $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $this->_settings['linkeditor_filename'];
143: break;
144: default:
145:
146: return '';
147: }
148: }
149:
150: 151: 152: 153: 154: 155:
156: public function generateEditCode() {
157: $template = new cTemplate();
158: $template->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
159: $template->set('s', 'ID', $this->_id);
160: $template->set('s', 'IDARTLANG', $this->_idArtLang);
161: $template->set('s', 'CONTENIDO', $_REQUEST['contenido']);
162: $template->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
163:
164: $templateTabs = new cTemplate();
165: $templateTabs->set('s', 'PREFIX', $this->_prefix);
166:
167:
168: $templateTabs->set('d', 'TAB_ID', 'external');
169: $templateTabs->set('d', 'TAB_CLASS', 'external');
170: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabExternal());
171: $templateTabs->next();
172:
173:
174: $templateTabs->set('d', 'TAB_ID', 'internal');
175: $templateTabs->set('d', 'TAB_CLASS', 'internal');
176: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabInternal());
177: $templateTabs->next();
178:
179:
180: $templateTabs->set('d', 'TAB_ID', 'file');
181: $templateTabs->set('d', 'TAB_CLASS', 'file');
182: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabFile());
183: $templateTabs->next();
184:
185:
186:
187: $templateTabs->set('d', 'TAB_ID', 'basic-settings');
188: $templateTabs->set('d', 'TAB_CLASS', 'basic-settings');
189: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateBasicSettings());
190: $templateTabs->next();
191:
192: $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
193:
194:
195: $templateTop = new cTemplate();
196: $templateTop->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
197: $templateTop->set('s', 'ICON', 'images/but_editlink.gif');
198: $templateTop->set('s', 'ID', $this->_id);
199: $templateTop->set('s', 'PREFIX', $this->_prefix);
200: $templateTop->set('s', 'HEADLINE', i18n('Link settings'));
201: $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
202:
203:
204: $tabMenu = array(
205: 'external' => i18n('External link'),
206: 'internal' => i18n('Internal link'),
207: 'file' => i18n('Link to a file')
208: );
209:
210:
211: $templateBottom = new cTemplate();
212: $templateBottom->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
213: $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
214: $templateBottom->set('s', 'ID', $this->_id);
215: $templateBottom->set('s', 'PREFIX', $this->_prefix);
216: $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
217: $templateBottom->set('s', 'CONTENIDO', $_REQUEST['contenido']);
218: $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
219: $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
220: $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsLinkeditor.js');
221: $templateBottom->set('s', 'JS_CLASS_NAME', 'cContentTypeLinkeditor');
222: $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
223:
224:
225: $code = $this->generateViewCode();
226: $code .= $this->_encodeForOutput($codeTop);
227: $code .= $this->_generateTabMenuCode($tabMenu);
228: $code .= $this->_encodeForOutput($codeTabs);
229: $code .= $this->_generateActionCode();
230: $code .= $this->_encodeForOutput($codeBottom);
231:
232: return $code;
233: }
234:
235: 236: 237: 238: 239: 240:
241: private function _generateTabExternal() {
242:
243: $wrapper = new cHTMLDiv();
244: $wrapperContent = array();
245:
246: $wrapperContent[] = new cHTMLLabel(i18n('Href'), 'linkeditor_externallink_' . $this->_id);
247: $wrapperContent[] = new cHTMLTextbox('linkeditor_externallink_' . $this->_id, $this->_settings['linkeditor_externallink'], '', '', 'linkeditor_externallink_' . $this->_id);
248:
249: $wrapper->setContent($wrapperContent);
250:
251: return $wrapper->render();
252: }
253:
254: 255: 256: 257: 258: 259: 260:
261: private function _generateBasicSettings() {
262:
263:
264: $wrapper = new cHTMLDiv();
265: $wrapperContent = array();
266:
267: $wrapperContent[] = new cHTMLLabel(i18n('Title'), 'linkeditor_title_' . $this->_id);
268: $title = conHtmlEntityDecode($this->_settings['linkeditor_title']);
269: $wrapperContent[] = new cHTMLTextbox('linkeditor_title_' . $this->_id, $title, '', '', 'linkeditor_title_' . $this->_id);
270: $wrapperContent[] = new cHTMLCheckbox('linkeditor_newwindow_' . $this->_id, '', 'linkeditor_newwindow_' . $this->_id, ($this->_settings['linkeditor_newwindow'] === 'true'));
271: $wrapperContent[] = new cHTMLLabel(i18n('Open in a new window'), 'linkeditor_newwindow_' . $this->_id);
272:
273: $wrapper->setContent($wrapperContent);
274:
275: return $wrapper->render();
276: }
277:
278: 279: 280: 281: 282: 283:
284: private function _generateTabInternal() {
285:
286: $wrapper = new cHTMLDiv();
287: $wrapperContent = array();
288:
289: $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
290: $liRoot = new cHTMLListItem('root', 'last');
291: $aUpload = new cHTMLLink('#');
292: $aUpload->setClass('on');
293: $aUpload->setAttribute('title', '0');
294: $aUpload->setContent('Root');
295: $directoryListCode = $this->getCategoryList($this->buildCategoryArray());
296: $div = new cHTMLDiv(array(
297: '<em><a href="#"></a></em>',
298: $aUpload
299: ));
300: $liRoot->setContent(array(
301: $div,
302: $directoryListCode
303: ));
304: $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
305: $directoryList->setContent($conStrTree);
306: $wrapperContent[] = $directoryList;
307:
308: $activeIdcats = $this->_getActiveIdcats();
309: $wrapperContent[] = new cHTMLDiv($this->generateArticleSelect($activeIdcats[0]), 'directoryFile', 'directoryFile' . '_' . $this->_id);
310:
311: $wrapper->setContent($wrapperContent);
312:
313: return $wrapper->render();
314: }
315:
316: 317: 318: 319: 320:
321: public function buildCategoryArray($level = 0, $parentid = 0) {
322: $db = cRegistry::getDb();
323: $directories = array();
324: $sql = 'SELECT distinct
325: *
326: FROM
327: ' . $this->_cfg['tab']['cat_tree'] . ' AS a,
328: ' . $this->_cfg['tab']['cat'] . ' AS c,
329: ' . $this->_cfg['tab']['cat_lang'] . ' AS d
330: WHERE
331: a.level = ' . $level . ' AND
332: c.parentid = ' . $parentid . ' AND
333: a.idcat = d.idcat AND
334: c.idcat = a.idcat AND
335: d.idlang = ' . cSecurity::toInteger($this->_lang) . ' AND
336: c.idclient = ' . cSecurity::toInteger($this->_client) . '
337: ORDER BY
338: a.idtree';
339:
340: $db->query($sql);
341: while ($db->nextRecord()) {
342: $directory = array();
343: $directory['idcat'] = $db->f('idcat');
344: $directory['name'] = $db->f('name');
345: $directory['sub'] = $this->buildCategoryArray($level + 1, $directory['idcat']);
346: $directories[] = $directory;
347: }
348:
349: return $directories;
350: }
351:
352: 353: 354: 355: 356: 357: 358:
359: public function getCategoryList(array $categories) {
360: $template = new cTemplate();
361: $i = 1;
362:
363: foreach ($categories as $category) {
364: $activeIdcats = $this->_getActiveIdcats();
365:
366: $divClass = (isset($activeIdcats[0]) && $category['idcat'] == $activeIdcats[0])? 'active' : '';
367: $template->set('d', 'DIVCLASS', $divClass);
368:
369: $template->set('d', 'TITLE', $category['idcat']);
370: $template->set('d', 'DIRNAME', $category['name']);
371:
372: $liClasses = array();
373:
374: if (in_array($category['idcat'], $activeIdcats) && $category['sub'] != '') {
375: $template->set('d', 'SUBDIRLIST', $this->getCategoryList($category['sub']));
376: } else if ($category['sub'] != '' && count($category['sub']) > 0) {
377: $liClasses[] = 'collapsed';
378: $template->set('d', 'SUBDIRLIST', '');
379: } else {
380: $template->set('d', 'SUBDIRLIST', '');
381: }
382:
383: if ($i === count($categories)) {
384: $liClasses[] = 'last';
385: }
386:
387: $template->set('d', 'LICLASS', implode(' ', $liClasses));
388:
389: $i++;
390: $template->next();
391: }
392:
393: return $template->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_filelist_dirlistitem.html', true);
394: }
395:
396: 397: 398: 399: 400:
401: private function _getActiveIdcats() {
402: $activeIdcats = array();
403: if ($this->_settings['linkeditor_type'] === 'internal') {
404: $sql = 'SELECT distinct
405: *
406: FROM
407: ' . $this->_cfg['tab']['cat_tree'] . ' AS a,
408: ' . $this->_cfg['tab']['cat_art'] . ' AS b,
409: ' . $this->_cfg['tab']['cat'] . ' AS c,
410: ' . $this->_cfg['tab']['cat_lang'] . ' AS d
411: WHERE
412: b.idart = ' . cSecurity::toInteger($this->_settings['linkeditor_idart']) . ' AND
413: a.idcat = d.idcat AND
414: b.idcat = c.idcat AND
415: c.idcat = a.idcat AND
416: d.idlang = ' . cSecurity::toInteger($this->_lang) . ' AND
417: c.idclient = ' . cSecurity::toInteger($this->_client) . '
418: ORDER BY
419: a.idtree';
420: $db = cRegistry::getDb();
421: $db->query($sql);
422: while ($db->nextRecord()) {
423: $activeIdcats = $this->_getParentIdcats($db->f('idcat'));
424: }
425: }
426:
427: return $activeIdcats;
428: }
429:
430: 431: 432: 433: 434: 435: 436: 437: 438:
439: private function _getParentIdcats($idcat, array $idcats = array()) {
440:
441: $idcats[] = $idcat;
442:
443:
444: $category = new cApiCategory($idcat);
445: $parentId = $category->get('parentid');
446: if ($parentId != 0) {
447: $idcats = $this->_getParentIdcats($parentId, $idcats);
448: }
449:
450: return $idcats;
451: }
452:
453: 454: 455: 456: 457: 458: 459:
460: public function generateArticleSelect($idCat = 0) {
461: $htmlSelect = new cHTMLSelectElement('linkeditor_idart', '', 'linkeditor_idart_' . $this->_id);
462: $htmlSelect->setSize(16);
463: $htmlSelectOption = new cHTMLOptionElement('Kein', '', false);
464: $htmlSelect->appendOptionElement($htmlSelectOption);
465:
466: if (empty($idCat)) {
467: return $htmlSelect->render();
468: }
469:
470:
471:
472: $sql = 'SELECT distinct
473: e.*
474: FROM
475: ' . $this->_cfg['tab']['cat_tree'] . ' AS a,
476: ' . $this->_cfg['tab']['cat_art'] . ' AS b,
477: ' . $this->_cfg['tab']['cat'] . ' AS c,
478: ' . $this->_cfg['tab']['cat_lang'] . ' AS d,
479: ' . $this->_cfg['tab']['art_lang'] . ' AS e
480: WHERE
481: c.idcat = ' . $idCat . ' AND
482: e.online = 1 AND
483: a.idcat = b.idcat AND
484: b.idcat = d.idcat AND
485: d.idlang = ' . cSecurity::toInteger($this->_lang) . ' AND
486: b.idart = e.idart AND
487: c.idcat = a.idcat AND
488: c.idclient = ' . cSecurity::toInteger($this->_client) . ' AND
489: e.idlang = ' . cSecurity::toInteger($this->_lang) . '
490: ORDER BY
491: a.idtree';
492: $db = cRegistry::getDb();
493: $db->query($sql);
494: while ($db->nextRecord()) {
495: $htmlSelectOption = new cHTMLOptionElement($db->f('title'), $db->f('idart'), ($db->f('idart') == $this->_settings['linkeditor_idart']));
496: $htmlSelect->appendOptionElement($htmlSelectOption);
497: }
498:
499: return $htmlSelect->render();
500: }
501:
502: 503: 504: 505: 506: 507:
508: private function _generateTabFile() {
509:
510: $wrapper = new cHTMLDiv();
511: $wrapperContent = array();
512:
513:
514: $newDirForm = new cHTMLForm();
515: $newDirForm->setAttribute('name', 'newdir');
516: $newDirForm->setAttribute('method', 'post');
517: $newDirForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
518: $caption1Span = new cHTMLSpan();
519: $caption1Span->setID('caption1');
520: $newDirHead = new cHTMLDiv(array(
521: '<b>' . i18n('Create a directory in') . '</b>',
522: $caption1Span
523: ));
524: $area = new cHTMLHiddenField('area', 'upl');
525: $action = new cHTMLHiddenField('action', 'upl_mkdir');
526: $frame = new cHTMLHiddenField('frame', '2');
527: $appendparameters = new cHTMLHiddenField('appendparameters');
528: $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
529: $path = new cHTMLHiddenField('path');
530: $foldername = new cHTMLTextbox('foldername');
531: $button = new cHTMLButton('', '', '', false, null, '', 'image');
532: $button->setAttribute('src', $this->_cfg['path']['contenido_fullhtml'] . 'images/submit.gif');
533: $newDirContent = new cHTMLDiv(array(
534: $area,
535: $action,
536: $frame,
537: $appendparameters,
538: $contenido,
539: $path,
540: $foldername,
541: $button
542: ));
543: $newDirForm->setContent(array(
544: $newDirHead,
545: $newDirContent
546: ));
547: $wrapperContent[] = $newDirForm;
548:
549:
550: $propertiesForm = new cHTMLForm();
551: $propertiesForm->setID('properties' . $this->_id);
552: $propertiesForm->setAttribute('name', 'properties');
553: $propertiesForm->setAttribute('method', 'post');
554: $propertiesForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
555: $propertiesForm->setAttribute('enctype', 'multipart/form-data');
556: $frame = new cHTMLHiddenField('frame', '4');
557: $area = new cHTMLHiddenField('area', 'upl');
558: $path = new cHTMLHiddenField('path');
559: $file = new cHTMLHiddenField('file');
560: $action = new cHTMLHiddenField('action', 'upl_upload');
561: $appendparameters = new cHTMLHiddenField('appendparameters');
562: $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
563: $caption2Span = new cHTMLSpan();
564: $caption2Span->setID('caption2');
565: $propertiesHead = new cHTMLDiv(array(
566: '<b>' . i18n('Path') . '</b>',
567: $caption2Span
568: ));
569: $imageUpload = new cHTMLUpload('file[]', '', '', 'cms_image_m' . $this->_id, false, '', '', 'file');
570: $imageUpload->setClass('jqueryAjaxUpload');
571: $propertiesForm->setContent(array(
572: $frame,
573: $area,
574: $path,
575: $file,
576: $action,
577: $appendparameters,
578: $contenido,
579: $propertiesHead,
580: $imageUpload
581: ));
582: $wrapperContent[] = $propertiesForm;
583:
584: $wrapperContent[] = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/ajax-loader.gif', 'loading');
585:
586:
587: $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList_' . $this->_id);
588: $liRoot = new cHTMLListItem('root', 'last');
589: $aUpload = new cHTMLLink('#');
590: $aUpload->setClass('on');
591: $aUpload->setAttribute('title', 'upload');
592: $aUpload->setContent('Uploads');
593: $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
594: $div = new cHTMLDiv(array(
595: '<em><a href="#"></a></em>',
596: $aUpload
597: ));
598:
599: if (dirname($this->_settings['linkeditor_filename']) === '\\') {
600: $div->setClass('active');
601: }
602: $liRoot->setContent(array(
603: $div,
604: $directoryListCode
605: ));
606: $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
607: $directoryList->setContent($conStrTree);
608: $wrapperContent[] = $directoryList;
609:
610: $wrapperContent[] = new cHTMLDiv($this->getUploadFileSelect(dirname($this->_settings['linkeditor_filename'])), 'directoryFile', 'directoryFile' . '_' . $this->_id);
611:
612: $wrapper->setContent($wrapperContent);
613:
614: return $wrapper->render();
615: }
616:
617: 618: 619: 620: 621: 622:
623: public function getUploadFileSelect($directoryPath = '') {
624:
625: $directoryPath = str_replace('\\', '/', $directoryPath);
626:
627:
628: if ($directoryPath === '/') {
629: $directoryPath = '';
630: }
631:
632: if ($directoryPath !== '' && substr($directoryPath, -1) != '/') {
633: $directoryPath .= '/';
634: }
635:
636: $htmlSelect = new cHTMLSelectElement('linkeditor_filename', '', 'linkeditor_filename_' . $this->_id);
637: $htmlSelect->setSize(16);
638: $htmlSelectOption = new cHTMLOptionElement('Kein', '', false);
639: $htmlSelect->addOptionElement(0, $htmlSelectOption);
640:
641: $i = 1;
642:
643: if (is_dir($this->_uploadPath . $directoryPath)) {
644: if ($handle = opendir($this->_uploadPath . $directoryPath)) {
645: while (($entry = readdir($handle)) !== false) {
646: if (is_file($this->_uploadPath . $directoryPath . $entry)) {
647: $htmlSelectOption = new cHTMLOptionElement($entry, $directoryPath . $entry);
648: $htmlSelect->addOptionElement($i, $htmlSelectOption);
649: $i++;
650: }
651: }
652: closedir($handle);
653: }
654: }
655:
656: if ($i === 0) {
657: $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '', false);
658: $htmlSelectOption->setAlt(i18n('No files found'));
659: $htmlSelectOption->setDisabled(true);
660: $htmlSelect->addOptionElement($i, $htmlSelectOption);
661: $htmlSelect->setDisabled(true);
662: }
663:
664:
665: if ($this->_settings['linkeditor_type'] === 'file') {
666: $htmlSelect->setDefault($this->_settings['linkeditor_filename']);
667: }
668:
669: return $htmlSelect->render();
670: }
671:
672: 673: 674: 675: 676: 677: 678: 679:
680: protected function _isActiveDirectory(array $dirData) {
681: return $dirData['path'] . $dirData['name'] === dirname($this->_settings['linkeditor_filename']);
682: }
683:
684: 685: 686: 687: 688: 689: 690: 691:
692: protected function _shouldDirectoryBeExpanded(array $dirData) {
693: return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
694: }
695:
696: }