Source for file FrontendController.php
Documentation is available at FrontendController.php
require_once BASEDIR.
'/inc/utility/SimpleXMLExtended.php';
require_once BASEDIR.
'/inc/utility/CaramelException.php';
require_once BASEDIR.
'/inc/model/DatabaseModel.php';
require_once BASEDIR.
'/inc/model/ConfigurationModel.php';
require_once BASEDIR.
'/inc/view/TemplateView.php';
* FrontendController class
* @author Felix Rupp <kontakt@felixrupp.com>
* @copyright Copyright (c) 2011, Felix Rupp, Nicole Reinhardt
* @license http://www.opensource.org/licenses/mit-license.php MIT-License
* @license http://www.gnu.org/licenses/gpl.html GNU GPL
* @var ConfigurationModel $_config Holds an instance of a Config
* @var DatabaseModel $_dataBase Holds the Database
* @var TemplateView $_templateView Holds an instance of our TemplatingEngine
* @var String VERSION Constant for system version
* @var String VERSION Constant for version date
const VERSION_DATE =
"2012-09-10";
} // End of constructor declaration
* This method assigns needed content to our template engine and renders the template.
$lang =
$this->getLanguage();
$pageName =
$this->getDisplay();
if(!$pageName) { // no page is set for display
$pageId =
$this->_dataBase->getPageId($pageName);
# Build navigation links from given information. Returned array is very compact
$navigation =
$this->getNavigationLinks($navigation);
$this->_templateView->assign("content", $content);
$this->_templateView->assign("navigation", $navigation);
$this->_templateView->assign("languageSelector", $this->getLanguageSelector());
$this->_templateView->assign("footer", $this->getFooter());
} // End of method declaration
* Redirects the user to the language set in browser
if(!isset
($_GET['lang'])) {
if($speakingUrls ==
"false") {
$language =
explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
header("Location: ./?lang=".
$language);
header("Location: ./?lang=".
$defaultLanguage);
elseif($speakingUrls ==
"true"){
$language =
explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
header("Location: ./".
$language.
"/");
header("Location: ./".
$defaultLanguage.
"/");
} // End of method declaration
* Print out version-information in index.php
* @return Version information comment
$comment =
"<!-- \n######### Caramel CMS\n######### Version: ".
self::VERSION.
"\n######### Release: ".
self::VERSION_DATE.
"\n\n######### Dual-licensed under the MIT-License: http://www.opensource.org/licenses/mit-license.php and the GNU GPL: http://www.gnu.org/licenses/gpl.html\n\n######### Copyright (c) Felix Rupp, Nicole Reinhardt\n\n######### http://www.caramel-cms.com/\n -->\n";
} // End of method declaration
* Print out current language code in index.php
* @return Language code for current language
return $this->getLanguage();
} // End of method declaration
* Print out head-tag in index.php
$metaGenerator =
"<meta name=\"generator\" content=\"Caramel CMS\">";
$lang =
$this->getLanguage();
$pageName =
$this->getDisplay();
if(!$pageName) { // no page is set for display
$pageId =
$this->_dataBase->getPageId($pageName);
$headTag =
$this->getBaseUrl().
"\n<meta charset=\"utf-8\">\n\n".
$meta.
"\n\n<title>".
$title.
"</title>\n\n";
if(strlen($additionalCssFile) >
1) {
$this->_templateView->addCssFile($additionalCssFile);
if(strlen($additionalJsFile) >
1) {
$this->_templateView->addJsFile($additionalJsFile);
$headTag .=
$this->_templateView->addCssJs();
} // End of method declaration
##################################################
##################################################
* This method build our navigation links from given information
* Note: Navigation is restricted to one sublevel
* @param array $navigationArray Array with detailed navigation information
* @return Array with link information for navigation
private function getNavigationLinks($navigationArray) {
# Get Parameters before ampersand
$newQueryString =
$this->getParametersBefore();
# Concatenate link for navigation
$naviLink =
(empty($_SERVER['QUERY_STRING']) ?
'?' :
$newQueryString).
'display=';
# Test if STARTPAGE is active or not
$pageName =
$this->getDisplay();
// no page is set for display
# For loop to build nav links
foreach($navigationArray as $navPageId =>
$page) {
if(intval($navPageId) ==
$pageId) {
if(strlen($navigationClass)<
1) { # No navigationClass set
else { # navigationClass set
if(strlen($navigationClass)<
1) {
else { # navigationClass set
if($page["visible"]==
"true") { # false values are not appearing in standard navigation
$link .=
$navigationClass.
$activeClass;
# Define link-syntax (speaking urls or not)
$link .=
" href=\"".
$naviLink.
$page["path"].
"\"";
$link .=
" href=\"".
$this->getParametersBefore().
'/'.
$page["path"].
"/\"";
# DEACTIVATED BECAUSE OF HTML5 DOCTYPE
#if($this->_config->getConfigStringAction("NAVIGATION_REL") !="disabled") {
# $link .= $this->_config->getConfigStringAction("NAVIGATION_REL");
$link .=
" title=\"".
$page["titletag"].
"\">";
# Evaluate position of NAVIGATION_ACTIVE_MARKER
$link .=
$active.
$page["navigation"];
$link .=
$page["navigation"].
$active;
$link .=
$page["navigation"];
$navigation[$navPageId]["path"] =
$page["path"];
$navigation[$navPageId]["link"] =
$link;
foreach($page["subpages"] as $subPageId =>
$page) {
if(intval($subPageId) ==
$pageId) {
if(strlen($navigationClass)<
1) { # No navigationClass set
else { # navigationClass set
if(strlen($navigationClass)<
1) {
else { # navigationClass set
if($page["visible"]==
"true") { # false values are not appearing in standard navigation
$link .=
$navigationClass;
# Define link-syntax (speaking urls or not)
$link .=
" href=\"".
$naviLink.
$page["path"].
"\"";
$link .=
" href=\"".
$this->getParametersBefore().
'/'.
$page["path"].
"/\"";
# DEACTIVATED BECAUSE OF HTML5 DOCTYPE
#if($this->_config->getConfigStringAction("NAVIGATION_REL") !="disabled") {
# $link .= $this->_config->getConfigStringAction("NAVIGATION_REL");
$link .=
" title=\"".
$page["titletag"].
"\">";
# Evaluate position of NAVIGATION_ACTIVE_MARKER
$link .=
$active.
$page["navigation"];
$link .=
$page["navigation"].
$active;
$link .=
$page["navigation"];
$navigation[$pageId]["subpages"][$subPageId]["path"] =
$page["path"];
$navigation[$pageId]["subpages"][$subPageId]["link"] =
$link;
} // End of method declaration
* Print out language selector in index.php
* @return All language selectors
private function getLanguageSelector() {
$selectorLinks =
array();
foreach($allLangs as $langCode) {
if($this->getLanguage() !=
$langCode) {
# Get Parameters before ampersand
$newQueryString =
$this->getParametersBehind();
if($speakingUrls ==
"false") {
array_push($selectorLinks, '<a title="" href="?lang=en'.
$newQueryString.
'">'.
strtoupper($langCode).
'</a>');
elseif($speakingUrls ==
"true") {
array_push($selectorLinks, '<a title="" href="'.
substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], $this->getLanguage())).
$langCode.
$newQueryString.
'">'.
strtoupper($langCode).
'</a>');
if(count($selectorLinks) >
1) {
foreach($selectorLinks as $key =>
$link) {
if($key ==
count($selectorLinks)-
1) {
$languageSelector .=
$link;
return "\t".
$languageSelector.
"\n";
} // End of method declaration
* Print out footer in footer of index.php
private function getFooter() {
if($langSelectInFooter ==
'true') {
$languageSelector =
$this->getLanguageSelector().
" ";
$footer =
$languageSelector;
} // End of method declaration
* Extract language from GET-query
* @return Actual language
private function getLanguage() {
if(isset
($_GET['lang']) &&
in_array($_GET['lang'], $allLangs)) { # Test if set language is in our language array
$language =
$_GET['lang'];
$language =
$defaultLanguage;
} // End of method declaration
* Get display from GET-query
* @return Actual page displayed
private function getDisplay() {
if(isset
($_GET['display'])) {
$display =
$_GET['display'];
} // End of method declaration
* Get parameters of GET-query before ampersand
* @return New querystring for building correct URL
private function getParametersBefore() {
$serverQueryString =
$_SERVER['QUERY_STRING'];
if($speakingUrls ==
"false") {
$newQueryString =
'?'.
substr($serverQueryString,0,7).
'&';
if($speakingUrls ==
"true") {
$newQueryString =
substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], $this->getLanguage())+
strlen($this->getLanguage()));
} // End of method declaration
* Get parameters of GET-query behind ampersand
* @return New querystring for building correct URL
private function getParametersBehind() {
$serverQueryString =
$_SERVER['QUERY_STRING'];
if($speakingUrls ==
"false") {
$newQueryString =
$ampZeichen.
substr($serverQueryString,8);
$newQueryString =
'&'.
substr($serverQueryString,0);
elseif($speakingUrls ==
"true") {
if(isset
($_GET['display'])) {
$newQueryString =
'/'.
substr($serverQueryString,16).
'/';
$newQueryString =
'/'.
substr($serverQueryString,16);
} // End of method declaration
* Print out base url in index.php
private function getBaseUrl() {
if($speakingUrls ==
"true") {
} // End of method declaration
} // End of class declaration