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