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