Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cCodeGeneratorAbstract
  • cCodeGeneratorFactory
  • cCodeGeneratorStandard
  • cContentTypeAbstract
  • cContentTypeAbstractTabbed
  • cContentTypeDate
  • cContentTypeFilelist
  • cContentTypeHead
  • cContentTypeHtml
  • cContentTypeHtmlhead
  • cContentTypeImg
  • cContentTypeImgdescr
  • cContentTypeImgeditor
  • cContentTypeLink
  • cContentTypeLinkdescr
  • cContentTypeLinkeditor
  • cContentTypeLinktarget
  • cContentTypeRaw
  • cContentTypeTeaser
  • cContentTypeText
  • cTypeGenerator
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the cContentTypeLinkeditor class.
  5:  *
  6:  * @package Core
  7:  * @subpackage ContentType
  8:  * @author Fulai Zhang
  9:  * @author Simon Sprankel
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: cInclude('includes', 'functions.con.php');
 19: cInclude('includes', 'functions.upl.php');
 20: 
 21: /**
 22:  * Content type CMS_LINKEDITOR which lets the editor select a link.
 23:  *
 24:  * @package Core
 25:  * @subpackage ContentType
 26:  */
 27: class cContentTypeLinkeditor extends cContentTypeAbstractTabbed {
 28:     /**
 29:      * @var string
 30:      */
 31:     protected $_dirname = '';
 32: 
 33:     /**
 34:      * Constructor to create an instance of this class.
 35:      *
 36:      * Initialises class attributes and handles store events.
 37:      *
 38:      * @param string $rawSettings
 39:      *         the raw settings in an XML structure or as plaintext
 40:      * @param int    $id
 41:      *         ID of the content type, e.g. 3 if CMS_DATE[3] is used
 42:      * @param array  $contentTypes
 43:      *         array containing the values of all content types
 44:      *
 45:      * @throws cDbException
 46:      */
 47:     function __construct($rawSettings, $id, array $contentTypes) {
 48: 
 49:         // set props
 50:         $this->_type = 'CMS_LINKEDITOR';
 51:         $this->_prefix = 'linkeditor';
 52:         $this->_settingsType = self::SETTINGS_TYPE_XML;
 53:         $this->_formFields = array(
 54:             'linkeditor_type',
 55:             'linkeditor_externallink',
 56:             'linkeditor_title',
 57:             'linkeditor_newwindow',
 58:             'linkeditor_idart',
 59:             'linkeditor_filename'
 60:         );
 61: 
 62:         // encoding conversions to avoid problems with umlauts
 63:         $rawSettings = conHtmlEntityDecode($rawSettings);
 64:         $rawSettings = utf8_encode($rawSettings);
 65: 
 66:         // call parent constructor
 67:         parent::__construct($rawSettings, $id, $contentTypes);
 68: 
 69:         $this->_settings['linkeditor_title'] = utf8_decode($this->_settings['linkeditor_title']);
 70:         $this->_settings['linkeditor_title'] = conHtmlentities($this->_settings['linkeditor_title']);
 71: 
 72:         // if form is submitted, store the current teaser settings
 73:         // notice: also check the ID of the content type (there could be more
 74:         // than one content type of the same type on the same page!)
 75:         if (isset($_POST['linkeditor_action']) && $_POST['linkeditor_action'] === 'store' && isset($_POST['linkeditor_id']) && (int) $_POST['linkeditor_id'] == $this->_id) {
 76:             // use htmlentities for the title
 77:             // otherwise umlauts will crash the XML parsing
 78:             $_POST['linkeditor_title'] = conHtmlentities(conHtmlEntityDecode($_POST['linkeditor_title']));
 79:             $this->_storeSettings();
 80:         }
 81:     }
 82: 
 83:     /**
 84:      * Returns the link type ('external', 'internal' or 'file')
 85:      *
 86:      * @return string
 87:      */
 88:     public function getLinkType() {
 89:         return $this->_settings['linkeditor_type'];
 90:     }
 91: 
 92:     /**
 93:      * Returns the link title
 94:      *
 95:      * @return string
 96:      */
 97:     public function getTitle() {
 98:         return $this->_settings['linkeditor_title'];
 99:     }
100: 
101:     /**
102:      * Returns the link target (e.g. "_blank")
103:      *
104:      * @return string
105:      */
106:     public function getTarget() {
107:         return ($this->_settings['linkeditor_newwindow'] === 'true') ? '_blank' : '';
108:     }
109: 
110:     /**
111:      * Returns the href of the link
112:      *
113:      * @return string
114:      * @throws cInvalidArgumentException
115:      */
116:     public function getLink() {
117:         return $this->_generateHref();
118:     }
119: 
120:     /**
121:      * @return string
122:      */
123:     public function getFilename()
124:     {
125:         return $this->_settings['linkeditor_filename'];
126:     }
127: 
128:     /**
129:      * Returns array with configured data (keys: type, externallink, title,
130:      * newwindow, idart, filename).
131:      * Additionally the key href contains the actual hyperreference.
132:      *
133:      * @return array
134:      * @throws cInvalidArgumentException
135:      */
136:     public function getConfiguredData() {
137:         $data = array(
138:             'type'          => $this->_settings['linkeditor_type'],
139:             'externallink'  => $this->_settings['linkeditor_externallink'],
140:             'title'         => $this->_settings['linkeditor_title'],
141:             'newwindow'     => $this->_settings['linkeditor_newwindow'],
142:             'idart'         => $this->_settings['linkeditor_idart'],
143:             'filename'      => $this->getFilename(),
144:             'href'          => $this->_generateHref()
145:         );
146: 
147:         return $data;
148:     }
149: 
150:     /**
151:      * Generates the code which should be shown if this content type is shown in
152:      * the frontend.
153:      *
154:      * @return string
155:      *         escaped HTML code which sould be shown if content type is shown in frontend
156:      * @throws cInvalidArgumentException
157:      */
158:     public function generateViewCode() {
159:         // generate the needed attributes
160:         $href = $this->_generateHref();
161:         if (empty($href)) {
162:             return '';
163:         }
164:         $linktext = $this->_settings['linkeditor_title'];
165:         // if the linktext is empty, use the link as the link text
166:         if (empty($linktext)) {
167:             $linktext = $href;
168:         }
169:         $target = ($this->_settings['linkeditor_newwindow'] === 'true') ? '_blank' : '';
170: 
171:         $link = new cHTMLLink($href);
172:         $link->setClass('link_list');
173:         $link->setTargetFrame($target);
174:         $link->setContent($linktext);
175: 
176:         return $this->_encodeForOutput($link->render());
177:     }
178: 
179:     /**
180:      * Generates the actual link depending on the link type.
181:      *
182:      * @return string
183:      *         the generated link
184:      * @throws cInvalidArgumentException
185:      */
186:     protected function _generateHref() {
187:         switch ($this->_settings['linkeditor_type']) {
188:             case 'external':
189:                 // make sure that link starts with http://
190:                 $link = $this->_settings['linkeditor_externallink'];
191:                 if (cString::findFirstPos($link, 'http://') !== 0 && cString::findFirstPos($link, 'www.') === 0) {
192:                     $link = 'http://' . $link;
193:                 }
194:                 return $link;
195:                 break;
196:             case 'internal':
197:                 if (cString::getPartOfString($this->_settings['linkeditor_idart'], 0, 8) == 'category') { // Selection of category (CON-2563)
198: 
199:                     $uriInstance = cUri::getInstance();
200:                     $uriBuilder = $uriInstance->getUriBuilder();
201:                     $uriParams = array(
202:                         'idcat' => cSecurity::toInteger(cString::getPartOfString($this->_settings['linkeditor_idart'], 9))
203:                     );
204:                     $uriBuilder->buildUrl($uriParams, true);
205: 
206:                     return $uriBuilder->getUrl();
207:                 } else if ($this->_settings['linkeditor_idart'] != "") {
208: 
209:                     $oUri = cUri::getInstance();
210:                     $uriBuilder = $oUri->getUriBuilder();
211:                     $uriParams = array(
212:                         'idart' => cSecurity::toInteger($this->_settings['linkeditor_idart'])
213:                     );
214:                     $uriBuilder->buildUrl($uriParams, true);
215: 
216:                     return $uriBuilder->getUrl();
217: 
218:                 }
219:                 break;
220:             case 'file':
221:                 if (!empty($this->getFilename())) {
222:                     return $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $this->getFilename();
223:                 } else {
224:                     return '';
225:                 }
226:                 break;
227:             default:
228:                 // invalid link type, output nothing
229:                 return '';
230:         }
231:     }
232: 
233:     /**
234:      * Generates the code which should be shown if this content type is edited.
235:      *
236:      * *
237:      * @return string
238:      *         escaped HTML code which should be shown if content type is edited
239:      * @throws cDbException
240:      * @throws cInvalidArgumentException
241:      */
242:     public function generateEditCode() {
243:         $template = new cTemplate();
244:         $template->set('s', 'ID', $this->_id);
245:         $template->set('s', 'IDARTLANG', $this->_idArtLang);
246:         $template->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
247: 
248:         $templateTabs = new cTemplate();
249:         $templateTabs->set('s', 'PREFIX', $this->_prefix);
250: 
251:         // create code for external tab
252:         $templateTabs->set('d', 'TAB_ID', 'external');
253:         $templateTabs->set('d', 'TAB_CLASS', 'external');
254:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabExternal());
255:         $templateTabs->next();
256: 
257:         // create code for internal tab
258:         $templateTabs->set('d', 'TAB_ID', 'internal');
259:         $templateTabs->set('d', 'TAB_CLASS', 'internal');
260:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabInternal());
261:         $templateTabs->next();
262: 
263:         // create code for file tab
264:         $templateTabs->set('d', 'TAB_ID', 'file');
265:         $templateTabs->set('d', 'TAB_CLASS', 'file');
266:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabFile());
267:         $templateTabs->next();
268: 
269:         // create code for basic settings "tab" - these settings are actually
270:         // visible any time
271:         $templateTabs->set('d', 'TAB_ID', 'basic-settings');
272:         $templateTabs->set('d', 'TAB_CLASS', 'basic-settings');
273:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateBasicSettings());
274:         $templateTabs->next();
275: 
276:         $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
277: 
278:         // construct the top code of the template
279:         $templateTop = new cTemplate();
280:         $templateTop->set('s', 'ICON', 'images/but_editlink.gif');
281:         $templateTop->set('s', 'ID', $this->_id);
282:         $templateTop->set('s', 'PREFIX', $this->_prefix);
283:         $templateTop->set('s', 'HEADLINE', i18n('Link settings'));
284:         $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
285: 
286:         // define the available tabs
287:         $tabMenu = array(
288:             'external' => i18n('External link'),
289:             'internal' => i18n('Internal link'),
290:             'file' => i18n('Link to a file')
291:         );
292: 
293:         // construct the bottom code of the template
294:         $templateBottom = new cTemplate();
295:         $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
296:         $templateBottom->set('s', 'ID', $this->_id);
297:         $templateBottom->set('s', 'PREFIX', $this->_prefix);
298:         $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
299:         $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
300:         $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
301:         $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsLinkeditor.js');
302:         $templateBottom->set('s', 'JS_CLASS_NAME', 'Con.cContentTypeLinkeditor');
303:         $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
304: 
305:         // construct the whole template code
306:         $code = $this->generateViewCode();
307:         $code .= $this->_encodeForOutput($codeTop);
308:         $code .= $this->_generateTabMenuCode($tabMenu);
309:         $code .= $this->_encodeForOutput($codeTabs);
310:         $code .= $this->_generateActionCode();
311:         $code .= $this->_encodeForOutput($codeBottom);
312: 
313:         return $code;
314:     }
315: 
316:     /**
317:      * Generates code for the external link tab in which links to external sites
318:      * can be specified.
319:      *
320:      * @return string
321:      *         the code for the external link tab
322:      */
323:     private function _generateTabExternal() {
324:         // define a wrapper which contains the whole content of the general tab
325:         $wrapper = new cHTMLDiv();
326:         $wrapperContent = array();
327: 
328:         $wrapperContent[] = new cHTMLLabel(i18n('Href'), 'linkeditor_externallink_' . $this->_id);
329:         $wrapperContent[] = new cHTMLTextbox('linkeditor_externallink_' . $this->_id, $this->_settings['linkeditor_externallink'], '', '', 'linkeditor_externallink_' . $this->_id);
330: 
331:         $wrapper->setContent($wrapperContent);
332: 
333:         return $wrapper->render();
334:     }
335: 
336:     /**
337:      * Generates code for the basic settings "tab" in which the link title and
338:      * target can be specified.
339:      *
340:      * This tab is always shown.
341:      *
342:      * @return string
343:      *         the code for the basic settings tab
344:      */
345:     private function _generateBasicSettings() {
346:         // define a wrapper which contains the whole content of the basic
347:         // settings section
348:         $wrapper = new cHTMLDiv();
349:         $wrapperContent = array();
350: 
351:         $wrapperContent[] = new cHTMLLabel(i18n('Title'), 'linkeditor_title_' . $this->_id);
352:         $title = conHtmlEntityDecode($this->_settings['linkeditor_title']);
353:         $wrapperContent[] = new cHTMLTextbox('linkeditor_title_' . $this->_id, $title, '', '', 'linkeditor_title_' . $this->_id);
354:         $wrapperContent[] = new cHTMLCheckbox('linkeditor_newwindow_' . $this->_id, '', 'linkeditor_newwindow_' . $this->_id, ($this->_settings['linkeditor_newwindow'] === 'true'));
355:         $wrapperContent[] = new cHTMLLabel(i18n('Open in a new window'), 'linkeditor_newwindow_' . $this->_id);
356: 
357:         $wrapper->setContent($wrapperContent);
358: 
359:         return $wrapper->render();
360:     }
361: 
362:     /**
363:      * Generates code for the internal link tab in which links to internal sites
364:      * can be specified.
365:      *
366:      * @return string
367:      *         the code for the internal link tab
368:      * @throws cDbException
369:      */
370:     private function _generateTabInternal() {
371:         // define a wrapper which contains the whole content of the general tab
372:         $wrapper = new cHTMLDiv();
373:         $wrapperContent = array();
374: 
375:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
376:         $liRoot = new cHTMLListItem('root', 'last');
377:         $aUpload = new cHTMLLink('#');
378:         $aUpload->setClass('on');
379:         $aUpload->setAttribute('title', '0');
380:         $aUpload->setContent('Root');
381: 
382:         $div = new cHTMLDiv(array(
383:             '<em><a href="#"></a></em>',
384:             $aUpload
385:         ));
386:         $liRoot->setContent(array(
387:             $div,
388:         ));
389:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
390:         $directoryList->setContent($conStrTree);
391:         $wrapperContent[] = $directoryList;
392:         $wrapperContent[] = new cHTMLDiv($this->generateArticleSelect(), 'directoryFile', 'directoryFile' . '_' . $this->_id);
393: 
394:         $wrapper->setContent($wrapperContent);
395: 
396:         return $wrapper->render();
397:     }
398: 
399:     /**
400:      * Builds an array with category information.
401:      *
402:      * @param int $level    [optional]
403:      * @param int $parentid [optional]
404:      *
405:      * @return array
406:      *         with directory information
407:      * @throws cDbException
408:      */
409:     public function buildCategoryArray($level = 0, $parentid = 0) {
410:         $db = cRegistry::getDb();
411:         $directories = array();
412:         $sql = 'SELECT distinct
413:                     *
414:                 FROM
415:                     ' . $this->_cfg['tab']['cat_tree'] . ' AS a,
416:                     ' . $this->_cfg['tab']['cat'] . ' AS c,
417:                     ' . $this->_cfg['tab']['cat_lang'] . ' AS d
418:                 WHERE
419:                     a.level = ' . $level . ' AND
420:                     c.parentid = ' . $parentid . ' AND
421:                     a.idcat = d.idcat AND
422:                     c.idcat = a.idcat AND
423:                     d.idlang = ' . cSecurity::toInteger($this->_lang) . ' AND
424:                     c.idclient = ' . cSecurity::toInteger($this->_client) . '
425:                 ORDER BY
426:                     a.idtree';
427: 
428:         $db->query($sql);
429:         while ($db->nextRecord()) {
430:             $directory = array();
431:             $directory['idcat'] = $db->f('idcat');
432:             $directory['name'] = $db->f('name');
433:             $directory['sub'] = $this->buildCategoryArray($level + 1, $directory['idcat']);
434:             $directories[] = $directory;
435:         }
436: 
437:         return $directories;
438:     }
439: 
440:     /**
441:      * Generates a category list from the given category information (which is
442:      * typically built by {@link cContentTypeLinkeditor::buildCategoryArray}).
443:      *
444:      * @param array $categories directory information
445:      *
446:      * @return string HTML code showing a directory list
447:      * @throws cDbException
448:      * @throws cInvalidArgumentException
449:      */
450:     public function getCategoryList(array $categories) {
451:         $template = new cTemplate();
452:         $i = 1;
453: 
454:         foreach ($categories as $category) {
455:             $activeIdcats = $this->getActiveIdcats();
456:             // set the active class if this is the chosen directory
457:             $divClass = (isset($activeIdcats[0]) && $category['idcat'] == $activeIdcats[0]) ? 'active' : '';
458:             $template->set('d', 'DIVCLASS', $divClass);
459: 
460:             $template->set('d', 'TITLE', $category['idcat']);
461:             $template->set('d', 'DIRNAME', $category['name']);
462: 
463:             $liClasses = array();
464:             // check if the category should be shown expanded or collapsed
465:             if (in_array($category['idcat'], $activeIdcats) && $category['sub'] != '') {
466:                 $template->set('d', 'SUBDIRLIST', $this->getCategoryList($category['sub']));
467:             } else if ($category['sub'] != '' && count($category['sub']) > 0) {
468:                 $liClasses[] = 'collapsed';
469:                 $template->set('d', 'SUBDIRLIST', '');
470:             } else {
471:                 $template->set('d', 'SUBDIRLIST', '');
472:             }
473: 
474:             if ($i === count($categories)) {
475:                 $liClasses[] = 'last';
476:             }
477: 
478:             $template->set('d', 'LICLASS', implode(' ', $liClasses));
479: 
480:             $i++;
481:             $template->next();
482:         }
483: 
484:         return $template->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_filelist_dirlistitem.html', true);
485:     }
486: 
487:     /**
488:      * Computes all active idcats.
489:      *
490:      * @return array
491:      *         containing all active idcats
492:      * @throws cDbException
493:      */
494:     public function getActiveIdcats() {
495:         $activeIdcats = array();
496:         if ($this->_settings['linkeditor_type'] === 'internal') {
497:             if (cSecurity::isInteger($this->_settings['linkeditor_idart'])) {
498:                 $sql = 'SELECT distinct
499:                                 *
500:                             FROM
501:                                 ' . $this->_cfg['tab']['cat_tree'] . ' AS a,
502:                                 ' . $this->_cfg['tab']['cat_art'] . ' AS b,
503:                                 ' . $this->_cfg['tab']['cat'] . ' AS c,
504:                                 ' . $this->_cfg['tab']['cat_lang'] . ' AS d
505:                             WHERE
506:                                 b.idart = ' . cSecurity::toInteger($this->_settings['linkeditor_idart']) . ' AND
507:                                 a.idcat = d.idcat AND
508:                                 b.idcat = c.idcat AND
509:                                 c.idcat = a.idcat AND
510:                                 d.idlang = ' . cSecurity::toInteger($this->_lang) . ' AND
511:                                 c.idclient = ' . cSecurity::toInteger($this->_client) . '
512:                             ORDER BY
513:                                 a.idtree';
514:             } else if (cString::getPartOfString($this->_settings['linkeditor_idart'], 0, 8) == 'category') { // Selection of category (CON-2563)
515:                 $sql = 'SELECT distinct
516:                                 *
517:                            FROM
518:                                 ' . $this->_cfg['tab']['cat_tree'] . ' AS a,
519:                                 ' . $this->_cfg['tab']['cat_art'] . ' AS b,
520:                                 ' . $this->_cfg['tab']['cat'] . ' AS c,
521:                                 ' . $this->_cfg['tab']['cat_lang'] . ' AS d
522:                             WHERE
523:                                 b.idcat = ' . cSecurity::toInteger(cString::getPartOfString($this->_settings['linkeditor_idart'], 9)) . ' AND
524:                                 a.idcat = d.idcat AND
525:                                 b.idcat = c.idcat AND
526:                                 c.idcat = a.idcat AND
527:                                 d.idlang = ' . cSecurity::toInteger($this->_lang) . ' AND
528:                                 c.idclient = ' . cSecurity::toInteger($this->_client) . '
529:                             ORDER BY
530:                                 a.idtree';
531:             }
532:             $db = cRegistry::getDb();
533:             $db->query($sql);
534:             while ($db->nextRecord()) {
535:                 $activeIdcats = $this->_getParentIdcats($db->f('idcat'));
536:             }
537:         }
538: 
539:         return $activeIdcats;
540:     }
541: 
542:     /**
543:      * Computes all parent idcats of the given idcat and returns them.
544:      *
545:      * @param int $idcat
546:      *         the current idcat
547:      * @param array $idcats [optional]
548:      *         the array of idcats to which all idcats should be added
549:      * @return array
550:      *         the given idcats array with the given idcat and all parent idcats
551:      */
552:     private function _getParentIdcats($idcat, array $idcats = array()) {
553:         // add the current idcat to the result idcats
554:         $idcats[] = $idcat;
555: 
556:         // get the cat entries with the given idcat
557:         $category = new cApiCategory($idcat);
558:         $parentId = $category->get('parentid');
559:         if ($parentId != 0) {
560:             $idcats = $this->_getParentIdcats($parentId, $idcats);
561:         }
562: 
563:         return $idcats;
564:     }
565: 
566:     /**
567:      * Generate a select box for all articles of the given idcat.
568:      *
569:      * @param int $idCat [optional]
570:      *                   idcat of the category from which all articles should be shown
571:      * @return string
572:      *                   rendered cHTMLSelectElement
573:      * @throws cDbException
574:      */
575:     public function generateArticleSelect($idCat = 0) {
576:         $htmlSelect = new cHTMLSelectElement('linkeditor_idart', '', 'linkeditor_idart_' . $this->_id);
577:         $htmlSelect->setSize(16);
578: 
579:         // Selection of category (CON-2563)
580:         // Format: category-CATID
581:         $checkCategorySelection = ((cString::getPartOfString($this->_settings['linkeditor_idart'], 0, 8) == 'category' ? true : false));
582:         $htmlSelectOptionCategory = new cHTMLOptionElement('- ' . i18n('Select category') . ' -', 'category-' . $idCat, $checkCategorySelection);
583:         $htmlSelect->appendOptionElement($htmlSelectOptionCategory);
584: 
585:         // Select neither (deselection)
586:         $htmlSelectOptionNothing = new cHTMLOptionElement('- '. i18n('Neither') . ' -', '', false);
587:         $htmlSelect->appendOptionElement($htmlSelectOptionNothing);
588: 
589:         // if no idcat has been given, do not search for articles
590:         if (empty($idCat)) {
591:             return $htmlSelect->render();
592:         }
593: 
594:         // get all articles from the category with the given idcat and add them
595:         // to the select element
596:         $sql = 'SELECT distinct
597:                     e.*
598:                 FROM
599:                     ' . $this->_cfg['tab']['cat_tree'] . ' AS a,
600:                     ' . $this->_cfg['tab']['cat_art'] . ' AS b,
601:                     ' . $this->_cfg['tab']['cat'] . ' AS c,
602:                     ' . $this->_cfg['tab']['cat_lang'] . ' AS d,
603:                     ' . $this->_cfg['tab']['art_lang'] . ' AS e
604:                 WHERE
605:                     c.idcat = ' . $idCat . ' AND
606:                     e.online = 1 AND
607:                     a.idcat = b.idcat AND
608:                     b.idcat = d.idcat AND
609:                     d.idlang = ' . cSecurity::toInteger($this->_lang) . ' AND
610:                     b.idart  = e.idart AND
611:                     c.idcat = a.idcat AND
612:                     c.idclient = ' . cSecurity::toInteger($this->_client) . ' AND
613:                     e.idlang = ' . cSecurity::toInteger($this->_lang) . '
614:                 ORDER BY
615:                     e.title';
616:         $db = cRegistry::getDb();
617:         $db->query($sql);
618:         while ($db->nextRecord()) {
619:             $htmlSelectOption = new cHTMLOptionElement($db->f('title'), $db->f('idart'), ($db->f('idart') == $this->_settings['linkeditor_idart']));
620:             $htmlSelect->appendOptionElement($htmlSelectOption);
621:         }
622: 
623:         return $htmlSelect->render();
624:     }
625: 
626:     /**
627:      * Generates code for the link to file tab in which links to files can be
628:      * specified.
629:      *
630:      * @return string
631:      *         the code for the link to file tab
632:      * @throws cInvalidArgumentException
633:      */
634:     private function _generateTabFile() {
635:         // define a wrapper which contains the whole content of the general tab
636:         $wrapper = new cHTMLDiv();
637:         $wrapperContent = array();
638: 
639:         // create a new directory form
640:         $newDirForm = new cHTMLForm();
641:         $newDirForm->setAttribute('name', 'newdir');
642:         $newDirForm->setAttribute('method', 'post');
643:         $newDirForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
644:         $caption1Span = new cHTMLSpan();
645:         $caption1Span->setID('caption1');
646:         $newDirHead = new cHTMLDiv(array(
647:             '<b>' . i18n('Create a directory in') . '</b>',
648:             $caption1Span
649:         ));
650:         $area = new cHTMLHiddenField('area', 'upl');
651:         $action = new cHTMLHiddenField('action', 'upl_mkdir');
652:         $frame = new cHTMLHiddenField('frame', '2');
653:         $appendparameters = new cHTMLHiddenField('appendparameters');
654:         $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
655:         $path = new cHTMLHiddenField('path');
656:         $foldername = new cHTMLTextbox('foldername');
657:         $button = new cHTMLButton('', '', '', false, NULL, '', 'image');
658:         $button->setAttribute('src', $this->_cfg['path']['contenido_fullhtml'] . 'images/submit.gif');
659:         $newDirContent = new cHTMLDiv(array(
660:             $area,
661:             $action,
662:             $frame,
663:             $appendparameters,
664:             $contenido,
665:             $path,
666:             $foldername,
667:             $button
668:         ));
669:         $newDirForm->setContent(array(
670:             $newDirHead,
671:             $newDirContent
672:         ));
673:         $wrapperContent[] = $newDirForm;
674: 
675:         // upload a new file form
676:         $propertiesForm = new cHTMLForm();
677:         $propertiesForm->setID('properties' . $this->_id);
678:         $propertiesForm->setAttribute('name', 'properties');
679:         $propertiesForm->setAttribute('method', 'post');
680:         $propertiesForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
681:         $propertiesForm->setAttribute('enctype', 'multipart/form-data');
682:         $frame = new cHTMLHiddenField('frame', '4');
683:         $area = new cHTMLHiddenField('area', 'upl');
684:         $path = new cHTMLHiddenField('path');
685:         $file = new cHTMLHiddenField('file');
686:         $action = new cHTMLHiddenField('action', 'upl_upload');
687:         $appendparameters = new cHTMLHiddenField('appendparameters');
688:         $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
689:         $caption2Span = new cHTMLSpan();
690:         $caption2Span->setID('caption2');
691:         $propertiesHead = new cHTMLDiv(array(
692:             '<b>' . i18n('Path') . '</b>',
693:             $caption2Span
694:         ));
695:         $imageUpload = new cHTMLUpload('file[]', '', '', 'cms_image_m' . $this->_id, false, '', '', 'file');
696:         $imageUpload->setClass('jqueryAjaxUpload');
697:         $propertiesForm->setContent(array(
698:             $frame,
699:             $area,
700:             $path,
701:             $file,
702:             $action,
703:             $appendparameters,
704:             $contenido,
705:             $propertiesHead,
706:             $imageUpload
707:         ));
708:         $wrapperContent[] = $propertiesForm;
709: 
710:         $wrapperContent[] = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/ajax-loader.gif', 'loading');
711: 
712:         // directory navigation
713:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList_' . $this->_id);
714:         $liRoot = new cHTMLListItem('root', 'last');
715:         $aUpload = new cHTMLLink('#');
716:         $aUpload->setClass('on');
717:         $aUpload->setAttribute('title', 'upload');
718:         $aUpload->setContent('Uploads');
719:         $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
720:         $div = new cHTMLDiv(array(
721:             '<em><a href="#"></a></em>',
722:             $aUpload
723:         ));
724:         // set the active class if the root directory has been chosen
725:         if (dirname($this->getFilename()) === '\\') {
726:             $div->setClass('active');
727:         }
728:         $liRoot->setContent(array(
729:             $div
730:         ));
731:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
732:         $directoryList->setContent($conStrTree);
733:         $wrapperContent[] = $directoryList;
734: 
735:         $wrapperContent[] = new cHTMLDiv($this->getUploadFileSelect('', true), 'directoryFile', 'directoryFile' . '_' . $this->_id);
736: 
737:         $wrapper->setContent($wrapperContent);
738: 
739:         return $wrapper->render();
740:     }
741: 
742:     /**
743:      * Generates a select box for the manual files.
744:      *
745:      * @SuppressWarnings docBlocks
746:      * @param string $directoryPath [optional]
747:      *         to directory of the files
748:      * @param bool   $isEmptySelect
749:      *
750:      * @return string|int
751:      */
752:     public function getUploadFileSelect($directoryPath = '', $isEmptySelect = false) {
753:         // replace all backslashes with slashes
754:         $directoryPath = str_replace('\\', '/', $directoryPath);
755:         // if the directory path only contains a slash, leave it empty
756:         // otherwise there will be two slashes in the end
757:         if ($directoryPath === '/') {
758:             $directoryPath = '';
759:         }
760:         // make sure the path ends with a slash if it is not empty
761:         if ($directoryPath !== '' && cString::getPartOfString($directoryPath, -1) != '/') {
762:             $directoryPath .= '/';
763:         }
764: 
765:         $htmlSelect = new cHTMLSelectElement('linkeditor_filename', '', 'linkeditor_filename_' . $this->_id);
766:         $htmlSelect->setSize(16);
767:         $htmlSelectOption = new cHTMLOptionElement('Kein', '', false);
768:         $htmlSelect->addOptionElement(0, $htmlSelectOption);
769: 
770:         if (!$isEmptySelect) {
771:             $files = array();
772:             if (is_dir($this->_uploadPath . $directoryPath)) {
773:                 // get only files
774:                 if (false !== ($handle = cDirHandler::read($this->_uploadPath . $directoryPath, false, false, true))) {
775:                     foreach ($handle as $entry) {
776:                         if (cFileHandler::fileNameBeginsWithDot($entry) === false) {
777:                             $file = array();
778:                             $file["name"] = $entry;
779:                             $file["path"] = $directoryPath . $entry;
780:                             $files[] = $file;
781:                         }
782:                     }
783:                 }
784:             }
785: 
786:             usort($files, function($a, $b) {
787:                 $a = cString::toLowerCase($a["name"]);
788:                 $b = cString::toLowerCase($b["name"]);
789:                 if($a < $b) {
790:                     return -1;
791:                 } else if($a > $b) {
792:                     return 1;
793:                 } else {
794:                     return 0;
795:                 }
796:             });
797: 
798:             $i = 1;
799:             foreach($files as $file) {
800:                 $htmlSelectOption = new cHTMLOptionElement($file["name"], $file["path"]);
801:                 $htmlSelect->addOptionElement($i, $htmlSelectOption);
802:                 $i++;
803:             }
804: 
805:             // set default value
806:             if ($this->_settings['linkeditor_type'] === 'file') {
807:                 $htmlSelect->setDefault($this->getFilename());
808:             }
809:         }
810: 
811:         return $htmlSelect->render();
812:     }
813: 
814:     /**
815:      * Checks whether the directory defined by the given directory
816:      * information is the currently active directory.
817:      *
818:      * Overwrite in subclasses if you use getDirectoryList!
819:      *
820:      * @param array $dirData
821:      *         directory information
822:      * @return bool
823:      *         whether the directory is the currently active directory
824:      */
825:     protected function _isActiveDirectory(array $dirData) {
826:         return $dirData['path'] . $dirData['name'] === dirname($this->getFilename());
827:     }
828: 
829:     /**
830:      * Checks whether the directory defined by the given directory information
831:      * should be shown expanded.
832:      *
833:      * Overwrite in subclasses if you use getDirectoryList!
834:      *
835:      * @param array $dirData
836:      *         directory information
837:      * @return bool
838:      *         whether the directory should be shown expanded
839:      */
840:     protected function _shouldDirectoryBeExpanded(array $dirData) {
841:         return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
842:     }
843: 
844: }
845: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0