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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • 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:      * @throws cDbException
127:      * @throws cException
128:      */
129:     public function _buildHeaderData() {
130:         global $cfg, $perm;
131: 
132:         $db = cRegistry::getDb();
133:         $db2 = cRegistry::getDb();
134: 
135:         // Load main items
136:         $sql = "SELECT idnavm, location FROM " . $cfg['tab']['nav_main'] . " ORDER BY idnavm";
137: 
138:         $db->query($sql);
139: 
140:         // Loop result and build array
141:         while ($db->nextRecord()) {
142: 
143:             // Extract names from the XML document.
144:             $main = $this->getName($db->f('location'));
145: 
146:             // Build data array
147:             $this->data[$db->f('idnavm')] = array($main);
148: 
149:             $sql = "SELECT
150:                         a.location AS location, b.name AS area, b.relevant
151:                     FROM
152:                         " . $cfg['tab']['nav_sub'] . " AS a, " . $cfg['tab']['area'] . " AS b
153:                     WHERE
154:                         a.idnavm = " . $db->f('idnavm') . " AND
155:                         a.level  = 0 AND
156:                         b.idarea = a.idarea AND
157:                         a.online = 1 AND
158:                         b.online = 1
159:                     ORDER BY
160:                         a.idnavs";
161: 
162:             $db2->query($sql);
163: 
164:             while ($db2->nextRecord()) {
165:                 $area = $db2->f('area');
166:                 if ($perm->have_perm_area_action($area) || $db2->f('relevant') == 0) {
167:                     // if this menu entry is a plugin and plugins are disabled, ignore it
168:                     if (cString::findFirstPos($db2->f('location'), ';') !== false && $cfg['debug']['disable_plugins']) {
169:                         continue;
170:                     }
171:                     // Extract names from the XML document.
172:                     try {
173:                         $name = $this->getName($db2->f('location'));
174:                     } catch(cException $e) {
175:                         $this->errors[] = i18n('Unable to load ' . $db2->f('location'));
176:                         continue;
177:                     }
178:                     $this->data[$db->f('idnavm')][] = array($name, $area);
179:                 }
180:             }
181:         }
182: 
183:         // debugging information
184:         cDebug::out(print_r($this->data, true));
185:     }
186: 
187:     /**
188:      * Function to build the CONTENIDO header document for backend.
189:      *
190:      * @param int $lang
191:      *         The language to use for header doc creation
192:      *
193:      * @throws cDbException
194:      * @throws cException
195:      * @throws cInvalidArgumentException
196:      */
197:     public function buildHeader($lang) {
198:         global $cfg, $sess, $client, $auth, $cfgClient;
199: 
200:         $this->_buildHeaderData();
201: 
202:         $main = new cTemplate();
203:         $sub = new cTemplate();
204: 
205:         $cnt = 0;
206:         $t_sub = '';
207:         $numSubMenus = 0;
208: 
209:         $properties = new cApiPropertyCollection();
210:         $clientImage = $properties->getValue('idclient', $client, 'backend', 'clientimage', false);
211: 
212:         $sJsEvents = '';
213:         foreach ($this->data as $id => $item) {
214:             $sub->reset();
215:             $genSubMenu = false;
216: 
217:             foreach ($item as $key => $value) {
218:                 if (is_array($value)) {
219:                     $sub->set('s', 'SUBID', 'sub_' . $id);
220: 
221:                     // create sub menu link
222:                     $link = new cHTMLLink();
223:                     $link->disableAutomaticParameterAppend();
224:                     $link->setClass('sub');
225:                     $link->setID('sub_' . $value[1]);
226:                     $link->setLink($sess->url('frameset.php?area=' . $value[1]));
227:                     $link->setTargetFrame('content');
228:                     $link->setContent(i18n($value[0]));
229: 
230:                     if ($cfg['help'] == true) {
231:                         $sJsEvents .= "\n\t" . '$("#sub_' . $value[1] . '").click(function() { $("#help").attr("data", "' . $value[0] . '"); })';
232:                     }
233:                     $sub->set('d', 'CAPTION', $link->render());
234: 
235:                     $sub->next();
236:                     $genSubMenu = true;
237:                 }
238:             }
239: 
240:             if ($genSubMenu == true) {
241:                 $link = new cHTMLLink();
242:                 $link->setClass('main');
243:                 $link->setID('main_' . $id);
244:                 $link->setLink('javascript://');
245:                 $link->setAttribute('ident', 'sub_' . $id);
246:                 $link->setContent(i18n($item[0]));
247: 
248:                 $main->set('d', 'CAPTION', $link->render());
249:                 $main->next();
250: 
251:                 $numSubMenus++;
252:             } else {
253:                 // first entry in array is a main menu item
254:             }
255: 
256:             // generate a sub menu item.
257:             $t_sub .= $sub->generate($cfg['path']['templates'] . $cfg['templates']['submenu'], true);
258:             $cnt++;
259:         }
260: 
261:         if ($numSubMenus == 0) {
262:             $main->set('d', 'CAPTION', '&nbsp;');
263:             $main->next();
264:         }
265: 
266:         $main->set('s', 'SUBMENUS', $t_sub);
267: 
268:         $backendUrl = cRegistry::getBackendUrl();
269: 
270:         // my CONTENIDO link
271:         $link = new cHTMLLink();
272:         $link->setClass('main');
273:         $link->setTargetFrame('content');
274:         $link->setLink($sess->url("frameset.php?area=mycontenido&frame=4"));
275:         $link->setContent('<img class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'my_contenido.gif" border="0" alt="My CONTENIDO" id="imgMyContenido" title="' . i18n("My CONTENIDO") . '">');
276:         $main->set('s', 'MYCONTENIDO', $link->render());
277: 
278:         // info link
279:         $link = new cHTMLLink();
280:         $link->setClass('main');
281:         $link->setTargetFrame('content');
282:         $link->setLink($sess->url('frameset.php?area=info&frame=4'));
283:         $link->setContent('<img alt="" class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'info.gif" border="0" alt="Info" title="Info" id="imgInfo">');
284:         $main->set('s', 'INFO', $link->render());
285: 
286:         $main->set('s', 'LOGOUT', $sess->url('logout.php'));
287: 
288:         if ($cfg['help'] == true) {
289:             // help link
290:             $link = new cHTMLLink();
291:             $link->setID('help');
292:             $link->setClass('main');
293:             $link->setLink('javascript://');
294:             $link->setEvent('click', 'Con.Help.show($(\'#help\').attr(\'data\'));');
295:             $link->setContent('<img class="vAlignMiddle" src="' . $backendUrl . $cfg['path']['images'] . 'but_help.gif" border="0" alt="Hilfe" title="Hilfe">');
296:             $main->set('s', 'HELP', $link->render());
297:         } else {
298:             $main->set('s', 'HELP', '');
299:         }
300: 
301:         $oUser = new cApiUser($auth->auth["uid"]);
302:         $clientCollection = new cApiClientCollection();
303: 
304:         if (getEffectiveSetting('system', 'clickmenu') == 'true') {
305:             // set click menu
306:             $main->set('s', 'HEADER_MENU_OBJ', 'Con.HeaderClickMenu');
307:             $main->set('s', 'HEADER_MENU_OPTIONS', '{menuId: "main_0", subMenuId: "sub_0"}');
308:         } else {
309:             // set delay menu
310:             $mouseOver = getEffectiveSetting('system', 'delaymenu_mouseover', 300);
311:             $mouseOot = getEffectiveSetting('system', 'delaymenu_mouseout', 1000);
312:             $main->set('s', 'HEADER_MENU_OBJ', 'Con.HeaderDelayMenu');
313:             $main->set('s', 'HEADER_MENU_OPTIONS', '{menuId: "main_0", subMenuId: "sub_0", mouseOverDelay: ' . $mouseOver . ', mouseOutDelay: ' . $mouseOot . '}');
314:         }
315: 
316:         $main->set('s', 'ACTION', $sess->url('index.php'));
317: 
318:         if ($this->hasErrors()) {
319:             $errors = $this->getErrors();
320:             $errorString = '';
321:             foreach ($errors as $error) {
322:                 $errorString .= $error.'<br>';
323:             }
324:             $errorString .= '<br>' . i18n('Some plugin menus can not be shown because of these errors.');
325:             $helpBox = new cGuiBackendHelpbox($errorString, './images/but_warn.gif');
326:             $main->set('s', 'LANG', $helpBox->render(true) . $this->_renderLanguageSelect());
327:         } else {
328:             $main->set('s', 'LANG', $this->_renderLanguageSelect());
329:         }
330: 
331:         $sClientName = $clientCollection->getClientname($client);
332:         if (cString::getStringLength($sClientName) > 25) {
333:             $sClientName = cString::trimHard($sClientName, 25);
334:         }
335: 
336:         $client = cSecurity::toInteger($client);
337:         if ($client == 0) {
338:             $sClientNameTemplate = '<b>' . i18n("Client") . ':</b> %s';
339:             $main->set('s', 'CHOSENCLIENT', sprintf($sClientNameTemplate, $sClientName));
340:         } else {
341:             $sClientNameTemplate = '<b>' . i18n("Client") . ':</b> <a href="%s" target="_blank">%s</a>';
342: 
343:             $sClientName = $clientCollection->getClientname($client) . ' (' . $client . ')';
344:             $sClientNameWithHtml = '<span id="chosenclient">' .$sClientName . '</span>';
345: 
346:             $sClientUrl = cRegistry::getFrontendUrl();
347:             $frontendPath = cRegistry::getFrontendPath();
348: 
349:             if ($clientImage !== false && $clientImage != "" && cFileHandler::exists($frontendPath . $clientImage)) {
350:                 $sClientImageTemplate = '<img src="%s" alt="%s" title="%s" style="height: 15px;">';
351: 
352:                 $sThumbnailPath = cApiImgScale($frontendPath . $clientImage, 80, 25, 0, 1);
353:                 $sClientImageTag = sprintf($sClientImageTemplate, $sThumbnailPath, $sClientName, $sClientName);
354: 
355:                 $main->set('s', 'CHOSENCLIENT', sprintf($sClientNameTemplate, $sClientUrl, $sClientImageTag));
356:             } else {
357:                 $html = sprintf($sClientNameTemplate, $sClientUrl, $sClientNameWithHtml);
358:                 $html .= $this->_renderClientSelect();
359:                 $main->set('s', 'CHOSENCLIENT', $html);
360:             }
361:         }
362: 
363:         $main->set('s', 'CHOSENUSER', "<b>" . i18n("User") . ":</b> " . $oUser->getEffectiveName());
364:         $main->set('s', 'MAINLOGINLINK', $sess->url("frameset.php?area=mycontenido&frame=4"));
365: 
366:         // additional footer javascript
367:         $footerJs = '';
368:         if ($sJsEvents !== '') {
369:             $footerJs = '$(function() {' . $sJsEvents . '});';
370:         }
371:         $main->set('s', 'FOOTER_JS', $footerJs);
372: 
373:         $main->generate($cfg['path']['templates'] . $cfg['templates']['header']);
374:     }
375: 
376:     /**
377:      * Renders the language select box.
378:      *
379:      * @return string
380:      *
381:      * @throws cDbException
382:      * @throws cException
383:      * @throws cInvalidArgumentException
384:      */
385:     public function _renderLanguageSelect() {
386:         global $cfg, $client, $lang;
387: 
388:         $tpl = new cTemplate();
389: 
390:         $tpl->set('s', 'NAME', 'changelang');
391:         $tpl->set('s', 'CLASS', 'vAlignMiddle text_medium');
392:         $tpl->set('s', 'ID', 'cLanguageSelect');
393:         $tpl->set('s', 'OPTIONS', 'onchange="Con.Header.changeContenidoLanguage(this.value)"');
394: 
395:         $availableLanguages = new cApiLanguageCollection();
396: 
397:         if (getEffectiveSetting('system', 'languageorder', 'name') == 'name') {
398:             $availableLanguages->select('', '', 'name ASC');
399:         } else {
400:             $availableLanguages->select('', '', 'idlang ASC');
401:         }
402: 
403:         if ($availableLanguages->count() > 0) {
404:             while (($myLang = $availableLanguages->nextAccessible()) !== false) {
405:                 $key = $myLang->get('idlang');
406:                 $value = $myLang->get('name');
407: 
408:                 $clientsLang = new cApiClientLanguage();
409:                 $clientsLang->loadBy('idlang', cSecurity::toInteger($key));
410:                 if ($clientsLang->isLoaded()) {
411:                     if ($clientsLang->get('idclient') == $client) {
412:                         if ($key == $lang) {
413:                             $tpl->set('d', 'SELECTED', 'selected');
414:                         } else {
415:                             $tpl->set('d', 'SELECTED', '');
416:                         }
417: 
418:                         if (cString::getStringLength($value) > 20) {
419:                             $value = cString::trimHard($value, 20);
420:                         }
421: 
422:                         $tpl->set('d', 'VALUE', $key);
423:                         $tpl->set('d', 'CAPTION', $value . ' (' . $key . ')');
424:                         $tpl->next();
425:                     }
426:                 }
427:             }
428:         } else {
429:             $tpl->set('d', 'VALUE', 0);
430:             $tpl->set('d', 'CAPTION', i18n('-- No Language available --'));
431:             $tpl->next();
432:         }
433: 
434:         return $tpl->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
435:     }
436: 
437:     /**
438:      * Renders a select box where the client can be selected as well as
439:      * an edit button.
440:      *
441:      * @return string
442:      *         rendered HTML
443:      * @throws cDbException
444:      * @throws cException
445:      * @throws cInvalidArgumentException
446:      */
447:     protected function _renderClientSelect() {
448:         $cfg = cRegistry::getConfig();
449:         $client = cRegistry::getClientId();
450:         // get all accessible clients
451:         $clientCollection = new cApiClientCollection();
452:         $clients = $clientCollection->getAccessibleClients();
453:         if (count($clients) === 1) {
454:             return '';
455:         }
456: 
457:         $tpl = new cTemplate();
458:         $tpl->set('s', 'NAME', 'changeclient');
459:         $tpl->set('s', 'CLASS', 'vAlignMiddle text_medium nodisplay');
460:         $tpl->set('s', 'ID', 'cClientSelect');
461:         $tpl->set('s', 'OPTIONS', 'onchange="Con.Header.changeContenidoClient(this.value)"');
462: 
463:         // add all accessible clients to the select
464:         foreach ($clients as $idclient => $clientInfo) {
465:             $name = $clientInfo['name'];
466:             if ($idclient == $client) {
467:                 $tpl->set('d', 'SELECTED', 'selected');
468:             } else {
469:                 $tpl->set('d', 'SELECTED', '');
470:             }
471: 
472:             if (cString::getStringLength($name) > 20) {
473:                 $name = cString::trimHard($name, 20);
474:             }
475: 
476:             $tpl->set('d', 'VALUE', $idclient);
477:             $tpl->set('d', 'CAPTION', $name . ' (' . $idclient . ')');
478:             $tpl->next();
479:         }
480: 
481:         $html = $tpl->generate($cfg['path']['templates'] . $cfg['templates']['generic_select'], true);
482:         $editButton = new cHTMLImage(cRegistry::getBackendUrl() . $cfg['path']['images'] . 'but_edithead.gif');
483:         $editButton->setID('changeclient');
484:         $editButton->setClass("vAlignMiddle");
485:         $editButton->appendStyleDefinition('cursor', 'pointer');
486: 
487:         return $html . $editButton->render();
488:     }
489: 
490:     /**
491:      * Returns true if the class encountered errors while building the
492:      * navigation-
493:      *
494:      * @return bool
495:      */
496:     public function hasErrors() {
497:         return count($this->errors) > 0;
498:     }
499: 
500:     /**
501:      * Returns an array of localized error messages.
502:      *
503:      * @return array
504:      */
505:     public function getErrors() {
506:         return $this->errors;
507:     }
508: }
509: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0