Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

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