Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cGuiBackendHelpbox
  • cGuiFileOverview
  • cGuiFoldingRow
  • cGuiList
  • cGuiMenu
  • cGuiNavigation
  • cGuiNotification
  • cGuiObjectPager
  • cGuiPage
  • cGuiScrollList
  • cGuiSourceEditor
  • cGuiTableForm
  • cGuiTree
  • cPager
  • cTemplate
  • cTree
  • cTreeItem
  • NoteLink
  • NoteList
  • NoteListItem
  • NoteView
  • TODOLink
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the navigation GUI class.
  5:  *
  6:  * @package          Core
  7:  * @subpackage       GUI
  8:  * @author           Jan Lengowski
  9:  * @copyright        four for business AG <www.4fb.de>
 10:  * @license          http://www.contenido.org/license/LIZENZ.txt
 11:  * @link             http://www.4fb.de
 12:  * @link             http://www.contenido.org
 13:  */
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: cInclude('includes', 'functions.api.string.php');
 18: cInclude('includes', 'functions.api.images.php');
 19: 
 20: /**
 21:  * Backend navigaton class.
 22:  *
 23:  * Renders the header navigation document containing the navigtion structure.
 24:  *
 25:  * @package    Core
 26:  * @subpackage GUI
 27:  */
 28: class cGuiNavigation {
 29: 
 30:     /**
 31:      * Array storing all data.
 32:      *
 33:      * @var  array
 34:      */
 35:     public $data = array();
 36: 
 37:     /**
 38:      * Array storing all errors.
 39:      *
 40:      * @var  array
 41:      */
 42:     protected $errors = array();
 43: 
 44:     /**
 45:      * Constructor to create an instance of this class.
 46:      *
 47:      * Loads the XML language file using cXmlReader.
 48:      *
 49:      * @throws cException if XML language files could not be loaded
 50:      */
 51:     public function __construct() {
 52:         global $cfg;
 53: 
 54:         $this->xml = new cXmlReader();
 55:         $this->plugxml = new cXmlReader();
 56: 
 57:         // Load language file
 58:         if ($this->xml->load($cfg['path']['xml'] . "navigation.xml") == false) {
 59:             throw new cException('Unable to load any XML language file');
 60:         }
 61:     }
 62: 
 63:     /**
 64:      * Extracts caption from the XML language file including plugins
 65:      * extended multilang version.
 66:      *
 67:      * @param string $location
 68:      *         The location of navigation item caption. Feasible values are
 69:      *         - "{xmlFilePath};{XPath}": Path to XML File and the XPath
 70:      *         value separated by semicolon. This type is used to extract
 71:      *         caption from a plugin XML file.
 72:      *         - "{XPath}": XPath value to extract caption from CONTENIDO
 73:      *         XML file
 74:      * @throws cException
 75:      *         if XML language files could not be loaded
 76:      * @return string
 77:      *         The found caption
 78:      */
 79:     public function getName($location) {
 80:         global $cfg, $belang;
 81: 
 82:         // If a ";" is found entry is from a plugin -> explode location,
 83:         // first is xml file path, second is xpath location in xml file.
 84:         if (strstr($location, ';')) {
 85:             $locs = explode(';', $location);
 86:             $file = trim($locs[0]);
 87:             $xpath = trim($locs[1]);
 88: 
 89:             $filepath = explode('/', $file);
 90:             $counter = count($filepath) - 1;
 91: 
 92:             if ($filepath[$counter] == '') {
 93:                 unset($filepath[$counter]);
 94:                 $counter--;
 95:             }
 96: 
 97:             if (strstr($filepath[$counter], '.xml')) {
 98:                 $filename = $filepath[$counter];
 99:                 unset($filepath[$counter]);
100:                 $counter--;
101:             }
102: 
103:             $filepath[($counter + 1)] = '';
104: 
105:             $filepath = implode('/', $filepath);
106: 
107:             if ($this->plugxml->load($cfg['path']['plugins'] . $filepath . $cfg['lang'][$belang]) == false) {
108:                 if (!isset($filename)) {
109:                     $filename = 'lang_en_US.xml';
110:                 }
111:                 if ($this->plugxml->load($cfg['path']['plugins'] . $filepath . $filename) == false) {
112:                     throw new cException("Unable to load $filepath XML language file");
113:                 }
114:             }
115:             $caption = $this->plugxml->getXpathValue('/language/' . $xpath);
116:         } else {
117:             $caption = $this->xml->getXpathValue('/language/' . $location);
118:         }
119: 
120:         return i18n($caption);
121:     }
122: 
123:     /**
124:      * Reads and fills the navigation structure data
125:      */
126:     public function _buildHeaderData() {
127:         global $cfg, $perm;
128: 
129:         $db = cRegistry::getDb();
130:         $db2 = cRegistry::getDb();
131: 
132:         // Load main items
133:         $sql = "SELECT idnavm, location FROM " . $cfg['tab']['nav_main'] . " ORDER BY idnavm";
134: 
135:         $db->query($sql);
136: 
137:         // Loop result and build array
138:         while ($db->nextRecord()) {
139: 
140:             // Extract names from the XML document.
141:             $main = $this->getName($db->f('location'));
142: 
143:             // Build data array
144:             $this->data[$db->f('idnavm')] = array($main);
145: 
146:             $sql = "SELECT
147:                         a.location AS location, b.name AS area, b.relevant
148:                     FROM
149:                         " . $cfg['tab']['nav_sub'] . " AS a, " . $cfg['tab']['area'] . " AS b
150:                     WHERE
151:                         a.idnavm = " . $db->f('idnavm') . " AND
152:                         a.level  = 0 AND
153:                         b.idarea = a.idarea AND
154:                         a.online = 1 AND
155:                         b.online = 1
156:                     ORDER BY
157:                         a.idnavs";
158: 
159:             $db2->query($sql);
160: 
161:             while ($db2->nextRecord()) {
162:                 $area = $db2->f('area');
163:                 if ($perm->have_perm_area_action($area) || $db2->f('relevant') == 0) {
164:                     // if this menu entry is a plugin and plugins are disabled, ignore it
165:                     if (strpos($db2->f('location'), ';') !== false && $cfg['debug']['disable_plugins']) {
166:                         continue;
167:                     }
168:                     // Extract names from the XML document.
169:                     try {
170:                         $name = $this->getName($db2->f('location'));
171:                     } catch(cException $e) {
172:                         $this->errors[] = i18n('Unable to load ' . $db2->f('location'));
173:                         continue;
174:                     }
175:                     $this->data[$db->f('idnavm')][] = array($name, $area);
176:                 }
177:             }
178:         }
179: 
180:         // debugging information
181:         cDebug::out(print_r($this->data, true));
182:     }
183: 
184:     /**
185:      * Function to build the CONTENIDO header document for backend.
186:      *
187:      * @param int $lang
188:      *         The language to use for header doc creation
189:      */
190:     public function buildHeader($lang) {
191:         global $cfg, $sess, $client, $auth, $cfgClient;
192: 
193:         $this->_buildHeaderData();
194: 
195:         $main = new cTemplate();
196:         $sub = new cTemplate();
197: 
198:         $cnt = 0;
199:         $t_sub = '';
200:         $numSubMenus = 0;
201: 
202:         $properties = new cApiPropertyCollection();
203:         $clientImage = $properties->getValue('idclient', $client, 'backend', 'clientimage', false);
204: 
205:         $sJsEvents = '';
206:         foreach ($this->data as $id => $item) {
207:             $sub->reset();
208:             $genSubMenu = false;
209: 
210:             foreach ($item as $key => $value) {
211:                 if (is_array($value)) {
212:                     $sub->set('s', 'SUBID', 'sub_' . $id);
213: 
214:                     // create sub menu link
215:                     $link = new cHTMLLink();
216:                     $link->disableAutomaticParameterAppend();
217:                     $link->setClass('sub');
218:                     $link->setID('sub_' . $value[1]);
219:                     $link->setLink($sess->url('frameset.php?area=' . $value[1]));
220:                     $link->setTargetFrame('content');
221:                     $link->setContent(i18n($value[0]));
222: 
223:                     if ($cfg['help'] == true) {
224:                         $sJsEvents .= "\n\t" . '$("#sub_' . $value[1] . '").click(function() { $("#help").attr("data", "' . $value[0] . '"); })';
225:                     }
226:                     $sub->set('d', 'CAPTION', $link->render());
227: 
228:                     $sub->next();
229:                     $genSubMenu = true;
230:                 }
231:             }
232: 
233:             if ($genSubMenu == true) {
234:                 $link = new cHTMLLink();
235:                 $link->setClass('main');
236:                 $link->setID('main_' . $id);
237:                 $link->setLink('javascript://');
238:                 $link->setAttribute('ident', 'sub_' . $id);
239:                 $link->setContent(i18n($item[0]));
240: 
241:                 $main->set('d', 'CAPTION', $link->render());
242:                 $main->next();
243: 
244:                 $numSubMenus++;
245:             } else {
246:                 // first entry in array is a main menu item
247:             }
248: 
249:             // generate a sub menu item.
250:             $t_sub .= $sub->generate($cfg['path']['templates'] . $cfg['templates']['submenu'], true);
251:             $cnt++;
252:         }
253: 
254:         if ($numSubMenus == 0) {
255:             $main->set('d', 'CAPTION', '&nbsp;');
256:             $main->next();
257:         }
258: 
259:         $main->set('s', 'SUBMENUS', $t_sub);
260: 
261:         $backendUrl = cRegistry::getBackendUrl();
262: 
263:         // my CONTENIDO link
264:         $link = new cHTMLLink();
265:         $link->setClass('main');
266:         $link->setTargetFrame('content');
267:         $link->setLink($sess->url("frameset.php?area=mycontenido&frame=4"));
268:         $link->setContent('<img class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'my_contenido.gif" border="0" alt="My CONTENIDO" id="imgMyContenido" title="' . i18n("My CONTENIDO") . '">');
269:         $main->set('s', 'MYCONTENIDO', $link->render());
270: 
271:         // info link
272:         $link = new cHTMLLink();
273:         $link->setClass('main');
274:         $link->setTargetFrame('content');
275:         $link->setLink($sess->url('frameset.php?area=info&frame=4'));
276:         $link->setContent('<img alt="" class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'info.gif" border="0" alt="Info" title="Info" id="imgInfo">');
277:         $main->set('s', 'INFO', $link->render());
278: 
279:         $main->set('s', 'LOGOUT', $sess->url('logout.php'));
280: 
281:         if ($cfg['help'] == true) {
282:             // help link
283:             $link = new cHTMLLink();
284:             $link->setID('help');
285:             $link->setClass('main');
286:             $link->setLink('javascript://');
287:             $link->setEvent('click', 'Con.Help.show($(\'#help\').attr(\'data\'));');
288:             $link->setContent('<img class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'but_help.gif" border="0" alt="Hilfe" title="Hilfe">');
289:             $main->set('s', 'HELP', $link->render());
290:         } else {
291:             $main->set('s', 'HELP', '');
292:         }
293: 
294:         $oUser = new cApiUser($auth->auth["uid"]);
295:         $clientCollection = new cApiClientCollection();
296: 
297:         if (getEffectiveSetting('system', 'clickmenu') == 'true') {
298:             // set click menu
299:             $main->set('s', 'HEADER_MENU_OBJ', 'Con.HeaderClickMenu');
300:             $main->set('s', 'HEADER_MENU_OPTIONS', '{menuId: "main_0", subMenuId: "sub_0"}');
301:         } else {
302:             // set delay menu
303:             $mouseOver = getEffectiveSetting('system', 'delaymenu_mouseover', 300);
304:             $mouseOot = getEffectiveSetting('system', 'delaymenu_mouseout', 1000);
305:             $main->set('s', 'HEADER_MENU_OBJ', 'Con.HeaderDelayMenu');
306:             $main->set('s', 'HEADER_MENU_OPTIONS', '{menuId: "main_0", subMenuId: "sub_0", mouseOverDelay: ' . $mouseOver . ', mouseOutDelay: ' . $mouseOot . '}');
307:         }
308: 
309:         $main->set('s', 'ACTION', $sess->url('index.php'));
310: 
311:         if ($this->hasErrors()) {
312:             $errors = $this->getErrors();
313:             $errorString = '';
314:             foreach ($errors as $error) {
315:                 $errorString .= $error.'<br>';
316:             }
317:             $errorString .= '<br>' . i18n('Some plugin menus can not be shown because of these errors.');
318:             $helpBox = new cGuiBackendHelpbox($errorString, './images/but_warn.gif');
319:             $main->set('s', 'LANG', $helpBox->render(true) . $this->_renderLanguageSelect());
320:         } else {
321:             $main->set('s', 'LANG', $this->_renderLanguageSelect());
322:         }
323: 
324:         $sClientName = $clientCollection->getClientname($client);
325:         if (strlen($sClientName) > 25) {
326:             $sClientName = cString::trimHard($sClientName, 25);
327:         }
328: 
329:         $client = cSecurity::toInteger($client);
330:         if ($client == 0) {
331:             $sClientNameTemplate = '<b>' . i18n("Client") . ':</b> %s';
332:             $main->set('s', 'CHOSENCLIENT', sprintf($sClientNameTemplate, $sClientName));
333:         } else {
334:             $sClientNameTemplate = '<b>' . i18n("Client") . ':</b> <a href="%s" target="_blank">%s</a>';
335: 
336:             $sClientName = $clientCollection->getClientname($client) . ' (' . $client . ')';
337:             $sClientNameWithHtml = '<span id="chosenclient">' .$sClientName . '</span>';
338: 
339:             $sClientUrl = cRegistry::getFrontendUrl();
340:             $frontendPath = cRegistry::getFrontendPath();
341: 
342:             if ($clientImage !== false && $clientImage != "" && cFileHandler::exists($frontendPath . $clientImage)) {
343:                 $sClientImageTemplate = '<img src="%s" alt="%s" title="%s" style="height: 15px;">';
344: 
345:                 $sThumbnailPath = cApiImgScale($frontendPath . $clientImage, 80, 25, 0, 1);
346:                 $sClientImageTag = sprintf($sClientImageTemplate, $sThumbnailPath, $sClientName, $sClientName);
347: 
348:                 $main->set('s', 'CHOSENCLIENT', sprintf($sClientNameTemplate, $sClientUrl, $sClientImageTag));
349:             } else {
350:                 $html = sprintf($sClientNameTemplate, $sClientUrl, $sClientNameWithHtml);
351:                 $html .= $this->_renderClientSelect();
352:                 $main->set('s', 'CHOSENCLIENT', $html);
353:             }
354:         }
355: 
356:         $main->set('s', 'CHOSENUSER', "<b>" . i18n("User") . ":</b> " . $oUser->getEffectiveName());
357:         $main->set('s', 'MAINLOGINLINK', $sess->url("frameset.php?area=mycontenido&frame=4"));
358: 
359:         // additional footer javascript
360:         $footerJs = '';
361:         if ($sJsEvents !== '') {
362:             $footerJs = '$(function() {' . $sJsEvents . '});';
363:         }
364:         $main->set('s', 'FOOTER_JS', $footerJs);
365: 
366:         $main->generate($cfg['path']['templates'] . $cfg['templates']['header']);
367:     }
368: 
369:     /**
370:      * Renders the language select box.
371:      *
372:      * @return string
373:      */
374:     public function _renderLanguageSelect() {
375:         global $cfg, $client, $lang;
376: 
377:         $tpl = new cTemplate();
378: 
379:         $tpl->set('s', 'NAME', 'changelang');
380:         $tpl->set('s', 'CLASS', 'vAlignMiddle text_medium');
381:         $tpl->set('s', 'ID', 'cLanguageSelect');
382:         $tpl->set('s', 'OPTIONS', 'onchange="Con.Header.changeContenidoLanguage(this.value)"');
383: 
384:         $availableLanguages = new cApiLanguageCollection();
385: 
386:         if (getEffectiveSetting('system', 'languageorder', 'name') == 'name') {
387:             $availableLanguages->select('', '', 'name ASC');
388:         } else {
389:             $availableLanguages->select('', '', 'idlang ASC');
390:         }
391: 
392:         if ($availableLanguages->count() > 0) {
393:             while (($myLang = $availableLanguages->nextAccessible()) !== false) {
394:                 $key = $myLang->get('idlang');
395:                 $value = $myLang->get('name');
396: 
397:                 $clientsLang = new cApiClientLanguage();
398:                 $clientsLang->loadBy('idlang', cSecurity::toInteger($key));
399:                 if ($clientsLang->isLoaded()) {
400:                     if ($clientsLang->get('idclient') == $client) {
401:                         if ($key == $lang) {
402:                             $tpl->set('d', 'SELECTED', 'selected');
403:                         } else {
404:                             $tpl->set('d', 'SELECTED', '');
405:                         }
406: 
407:                         if (strlen($value) > 20) {
408:                             $value = cString::trimHard($value, 20);
409:                         }
410: 
411:                         $tpl->set('d', 'VALUE', $key);
412:                         $tpl->set('d', 'CAPTION', $value . ' (' . $key . ')');
413:                         $tpl->next();
414:                     }
415:                 }
416:             }
417:         } else {
418:             $tpl->set('d', 'VALUE', 0);
419:             $tpl->set('d', 'CAPTION', i18n('-- No Language available --'));
420:             $tpl->next();
421:         }
422: 
423:         return $tpl->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
424:     }
425: 
426:     /**
427:      * Renders a select box where the client can be selected as well as
428:      * an edit button.
429:      *
430:      * @return string
431:      *         rendered HTML
432:      */
433:     protected function _renderClientSelect() {
434:         $cfg = cRegistry::getConfig();
435:         $client = cRegistry::getClientId();
436:         // get all accessible clients
437:         $clientCollection = new cApiClientCollection();
438:         $clients = $clientCollection->getAccessibleClients();
439:         if (count($clients) === 1) {
440:             return '';
441:         }
442: 
443:         $tpl = new cTemplate();
444:         $tpl->set('s', 'NAME', 'changeclient');
445:         $tpl->set('s', 'CLASS', 'vAlignMiddle text_medium nodisplay');
446:         $tpl->set('s', 'ID', 'cClientSelect');
447:         $tpl->set('s', 'OPTIONS', 'onchange="Con.Header.changeContenidoClient(this.value)"');
448: 
449:         // add all accessible clients to the select
450:         foreach ($clients as $idclient => $clientInfo) {
451:             $name = $clientInfo['name'];
452:             if ($idclient == $client) {
453:                 $tpl->set('d', 'SELECTED', 'selected');
454:             } else {
455:                 $tpl->set('d', 'SELECTED', '');
456:             }
457: 
458:             if (strlen($name) > 20) {
459:                 $name = cString::trimHard($name, 20);
460:             }
461: 
462:             $tpl->set('d', 'VALUE', $idclient);
463:             $tpl->set('d', 'CAPTION', $name . ' (' . $idclient . ')');
464:             $tpl->next();
465:         }
466: 
467:         $html = $tpl->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
468:         $editButton = new cHTMLImage(cRegistry::getBackendUrl() . $cfg['path']['images'] . 'but_edithead.gif');
469:         $editButton->setID('changeclient');
470:         $editButton->setClass("vAlignMiddle");
471:         $editButton->appendStyleDefinition('cursor', 'pointer');
472: 
473:         return $html . $editButton->render();
474:     }
475: 
476:     /**
477:      * Returns true if the class encountered errors while building the
478:      * navigation-
479:      *
480:      * @return bool
481:      */
482:     public function hasErrors() {
483:         return count($this->errors) > 0;
484:     }
485: 
486:     /**
487:      * Returns an array of localized error messages.
488:      *
489:      * @return array
490:      */
491:     public function getErrors() {
492:         return $this->errors;
493:     }
494: }
495: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0