Overview

Packages

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