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