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