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