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