Source for file BackendController.php

Documentation is available at BackendController.php

  1. <?php
  2.  
  3. /**
  4.  * @package inc
  5.  * @subpackage controller
  6.  */
  7.  
  8.  
  9. /**
  10.  * Imports
  11.  */
  12. require_once BASEDIR.'/inc/utility/SimpleXMLExtended.php';
  13. require_once BASEDIR.'/inc/utility/CaramelException.php';
  14. require_once BASEDIR.'/inc/model/DatabaseModel.php';
  15. require_once BASEDIR.'/inc/model/ConfigurationModel.php';
  16. require_once BASEDIR.'/inc/view/TemplateView.php';
  17.  
  18. /**
  19.  *
  20.  * BackendController class
  21.  * 
  22.  * @author Felix Rupp <kontakt@felixrupp.com>
  23.  * @version $Id$
  24.  * @copyright Copyright (c) 2011, Felix Rupp, Nicole Reinhardt
  25.  * @license http://www.opensource.org/licenses/mit-license.php MIT-License
  26.  * @license http://www.gnu.org/licenses/gpl.html GNU GPL
  27.  * 
  28.  * @package inc
  29.  * @subpackage controller
  30.  */
  31.  
  32.     /**
  33.      * @var ConfigurationModel $_config Holds an instance of a Config
  34.      */
  35.     private $_config;
  36.  
  37.     /**
  38.      * @var DatabaseModel $_dataBase Holds the Database
  39.      */
  40.     private $_dataBase;
  41.     
  42.     /**
  43.      * @var TemplateView $_templateView Holds an instance of our TemplatingEngine
  44.      */
  45.     private $_templateView;
  46.     
  47.     /**
  48.      * @var boolean $_navigation Boolean: Show navigation or not
  49.      */
  50.     private $_navigation FALSE;
  51.     
  52.     /**
  53.      * @var boolean $_login Boolean: Show loginform or not
  54.      */
  55.     private $_login FALSE;
  56.     
  57.     /**
  58.      * @var boolean $_welcome Boolean: Show welcome page or not
  59.      */
  60.     private $_welcome FALSE;
  61.         
  62.     /**
  63.      * @var String VERSION Constant for system version
  64.      */
  65.     const VERSION "0.3.0";
  66.     
  67.     /**
  68.      * @var String VERSION Constant for version date
  69.      */
  70.     const VERSION_DATE "2012-09-10";
  71.     
  72.     /**
  73.      * @var String SYSTEM_SALT System Salt for bcrypt hashing
  74.      */
  75.     const SYSTEM_SALT 'Mv7DAYvR782k5PgANTYG262P3h6b4p757e2k2jA788ESdAHKP2wBfV93SK3u87Ks';
  76.     
  77.  
  78.     /**
  79.      * Constructor
  80.      * 
  81.      * @return void 
  82.      */
  83.     public function BackendController({
  84.  
  85.         # Get Configurator 
  86.         $this->_config ConfigurationModel::getConfigurationModel();
  87.         
  88.         # Get TemplatingEngine for Backend
  89.         $this->_templateView new TemplateView("Backend");
  90.         
  91.         # Get Database 
  92.         $this->_dataBase DatabaseModel::getDatabaseModel();
  93.         
  94.                 
  95.     // End of constructor declaration
  96.     
  97.     
  98.     
  99. # Main content actions:
  100.  
  101.     /**
  102.      * This method assigns needed content to our template engine and renders the template.
  103.      * 
  104.      * @return void 
  105.      */
  106.     public function backendOutputAction({
  107.         
  108.         if($this->getSession(== FALSE# No session, so please show login
  109.             
  110.             $this->_login TRUE;
  111.                 
  112.             if(isset($_POST&& isset($_POST["username"]&& isset($_POST["password"])) {
  113.             
  114.                 # Check login data
  115.                 $realAdmin "";
  116.                 $realPassword "";
  117.                 $realEmail "";
  118.                     
  119.                 try {
  120.                     $loginInformation $this->_config->getLoginInfoAction();
  121.                 }
  122.                 catch(CaramelException $e{
  123.                     $e->getDetails();
  124.                 }
  125.                     
  126.                 if($_POST["username"]==$loginInformation["username"]{
  127.                     
  128.                     if($this->bcryptCheck($loginInformation["email"]$_POST["password"]$loginInformation["password"])) {
  129.                     
  130.                         # Set loggedin
  131.                         $_SESSION["loggedin"TRUE;
  132.                         $_SESSION["timestamp"time();
  133.                             
  134.                         $this->_navigation TRUE;
  135.                         $this->_login FALSE;
  136.                         $this->_welcome TRUE;
  137.                     }
  138.                     else {
  139.                         # Password wrong
  140.                         $this->_navigation FALSE;
  141.                         $this->_login TRUE;
  142.                         $this->_welcome FALSE;
  143.                             
  144.                         $this->_templateView->assign("error""The password you provided seems to be wrong. Please try again.");
  145.                     }
  146.                 else {
  147.                     # Username wrong
  148.                     $this->_navigation FALSE;
  149.                     $this->_login TRUE;
  150.                     $this->_welcome FALSE;
  151.                     
  152.                     $this->_templateView->assign("error""The username you provided seems to be wrong. Please try again.");
  153.                 }
  154.             else {
  155.             
  156.                 $this->_navigation FALSE;
  157.                 $this->_login TRUE;
  158.                 $this->_welcome FALSE;
  159.                             
  160.             }
  161.             
  162.         }
  163.         else # Already logged in
  164.             
  165.             $this->_navigation TRUE;
  166.             $this->_login FALSE;
  167.             $this->_welcome TRUE;
  168.             
  169.             # Logout
  170.             if(isset($_GET["q"]&& $_GET["q"]=="logout"{
  171.                 $this->logoutAction();
  172.                 
  173.                 $this->_navigation FALSE;
  174.                 $this->_login TRUE;
  175.                 $this->_welcome FALSE;
  176.                 
  177.             }
  178.             # New page
  179.             if(isset($_GET["q"]&& $_GET["q"]=="newpage"{
  180.                 
  181.                 $this->_navigation TRUE;
  182.                 $this->_login FALSE;
  183.                 $this->_welcome FALSE;
  184.                 $this->_templateView->assign("newpage"TRUE);
  185.             
  186.             }
  187.             # Page overview
  188.             if(isset($_GET["q"]&& $_GET["q"]=="editpages" && !isset($_GET["id"]&& !isset($_GET["delete"])) {
  189.                 
  190.                 try {
  191.                     $allPages $this->_dataBase->backendGetWebsitePagesAction("en");
  192.                 }
  193.                 catch(CaramelException $e{
  194.                     $e->getDetails();
  195.                 }
  196.                                 
  197.                 $this->_navigation TRUE;
  198.                 $this->_login FALSE;
  199.                 $this->_welcome FALSE;
  200.                 
  201.                 $this->_templateView->assign("pages"$allPages);
  202.                 $this->_templateView->assign("editpages"TRUE);
  203.                     
  204.             }
  205.             # Move page up
  206.             if(isset($_GET["q"]&& $_GET["q"]=="moveup" && isset($_GET["id"])) {
  207.                 
  208.                 $id = (int)trim($_GET["id"]);
  209.                 
  210.                 try {
  211.                     $result $this->_dataBase->backendMovePageUpAction($id);
  212.                     $allPages $this->_dataBase->backendGetWebsitePagesAction("en");
  213.                 }
  214.                 catch(CaramelException $e{
  215.                     $e->getDetails();
  216.                 }
  217.                                 
  218.                 $this->_navigation TRUE;
  219.                 $this->_login FALSE;
  220.                 $this->_welcome FALSE;
  221.                 
  222.                 $this->_templateView->assign("pages"$allPages);
  223.                 $this->_templateView->assign("editpages"TRUE);
  224.                 
  225.             }
  226.             # Move page down
  227.             if(isset($_GET["q"]&& $_GET["q"]=="movedown" && isset($_GET["id"])) {
  228.             
  229.                 $id = (int)trim($_GET["id"]);
  230.             
  231.                 try {
  232.                     $result $this->_dataBase->backendMovePageDownAction($id);
  233.                     $allPages $this->_dataBase->backendGetWebsitePagesAction("en");
  234.                 }
  235.                 catch(CaramelException $e{
  236.                     $e->getDetails();
  237.                 }
  238.             
  239.                 $this->_navigation TRUE;
  240.                 $this->_login FALSE;
  241.                 $this->_welcome FALSE;
  242.             
  243.                 $this->_templateView->assign("pages"$allPages);
  244.                 $this->_templateView->assign("editpages"TRUE);
  245.             
  246.             }
  247.             # Edit a single page
  248.             if(isset($_GET["q"]&& $_GET["q"]=="editpages" && isset($_GET["id"]&& !isset($_GET["delete"])) {
  249.             
  250.                 $id = (int)trim($_GET["id"]);
  251.                 
  252.                 try {
  253.                     $page $this->_dataBase->backendGetPageInformation($id);
  254.                 }
  255.                 catch(CaramelException $e{
  256.                     $e->getDetails();
  257.                 }
  258.                                             
  259.                 $this->_navigation TRUE;
  260.                 $this->_login FALSE;
  261.                 $this->_welcome FALSE;
  262.             
  263.                 $this->_templateView->assign("page"$page);
  264.                 $this->_templateView->assign("editonepage"TRUE);
  265.                     
  266.             }
  267.             # Delete a single page
  268.             if(isset($_GET["q"]&& $_GET["q"]=="editpages" && isset($_GET["id"]&& isset($_GET["delete"])) {
  269.                     
  270.                 $id = (int)trim($_GET["id"]);
  271.             
  272.                 try {
  273.                     $result $this->_dataBase->backendDeletePageAction($id);
  274.                     $allPages $this->_dataBase->backendGetWebsitePagesAction("en");
  275.                 }
  276.                 catch(CaramelException $e{
  277.                     $e->getDetails();
  278.                 }
  279.                                     
  280.                 $this->_navigation TRUE;
  281.                 $this->_login FALSE;
  282.                 $this->_welcome FALSE;
  283.                     
  284.                 $this->_templateView->assign("pages"$allPages);
  285.                 $this->_templateView->assign("editpages"TRUE);
  286.                     
  287.             }
  288.             # Edit admin user
  289.             if(isset($_GET["q"]&& $_GET["q"]=="editadmin"{
  290.                 
  291.                 $admin $this->_config->getAdminAction()
  292.                 
  293.                 $this->_navigation TRUE;
  294.                 $this->_login FALSE;
  295.                 $this->_welcome FALSE;
  296.                 
  297.                 $this->_templateView->assign("admin"$admin);
  298.                 $this->_templateView->assign("editadmin"TRUE);
  299.                     
  300.             }
  301.             # Edit templates
  302.             if(isset($_GET["q"]&& $_GET["q"]=="edittemplates"{
  303.                     
  304.                 $template $this->getTemplateConfig();
  305.                 
  306.                 $this->_navigation TRUE;
  307.                 $this->_login FALSE;
  308.                 $this->_welcome FALSE;
  309.                 
  310.                 $this->_templateView->assign("template"$template);
  311.                 $this->_templateView->assign("edittemplates"TRUE);
  312.                     
  313.             }
  314.             # Edit global settings
  315.             if(isset($_GET["q"]&& $_GET["q"]=="editglobal"{
  316.                 
  317.                 $globals $this->getGlobalConfig();
  318.                     
  319.                 $this->_navigation TRUE;
  320.                 $this->_login FALSE;
  321.                 $this->_welcome FALSE;
  322.                 
  323.                 $this->_templateView->assign("globals"$globals);
  324.                 $this->_templateView->assign("editglobal"TRUE);
  325.                     
  326.             }
  327.             
  328.             ####### POST
  329.             
  330.             # New page
  331.             if(isset($_POST["newpage"])) {
  332.                         
  333.                 $path strtolower(trim($_POST["path"]));
  334.                 $defaultLang strtolower(trim($_POST["defaultLanguage"]));
  335.                 
  336.                 $recordContents["navigation"trim($_POST["navigation"]);
  337.                 $recordContents["title"trim($_POST["title"]);
  338.                 $recordContents["titletag"trim($_POST["titletag"]);
  339.                 $recordContents["metadescription"trim($_POST["metadescription"]);
  340.                 $recordContents["metakeywords"trim($_POST["metakeywords"]);
  341.                 $recordContents["metaauthor"trim($_POST["metaauthor"]);
  342.                 $recordContents["content"trim($_POST["content"]);
  343.                 
  344.             
  345.                 try {
  346.                     
  347.                     $result $this->_dataBase->backendCreatePageAction($path$defaultLang$recordContents);
  348.                     
  349.                     $allPages $this->_dataBase->backendGetWebsitePagesAction("en");
  350.                     
  351.                 }
  352.                 catch(CaramelException $e{
  353.                     $e->getDetails();
  354.                 }
  355.                                 
  356.                 $this->_navigation TRUE;
  357.                 $this->_login FALSE;
  358.                 $this->_welcome FALSE;
  359.                 
  360.                 $this->_templateView->assign("pages"$allPages);
  361.                 $this->_templateView->assign("editpages"TRUE);
  362.             
  363.             }
  364.             # Edit one page
  365.             if(isset($_POST["editonepage"]&& isset($_POST["pageid"])) {
  366.                 
  367.                                 
  368.                 $id = (int)trim($_POST["pageid"]);
  369.                 
  370.                 try {
  371.                     $page $this->_dataBase->backendGetPageInformation($id);
  372.                 }
  373.                 catch(CaramelException $e{
  374.                     $e->getDetails();
  375.                 }
  376.                 
  377.                 $page["path"]["value"trim($_POST["path"]);
  378.                 
  379.                 $page["stylesheet"]["value"trim($_POST["stylesheet"]);
  380.                 $page["scriptfile"]["value"trim($_POST["scriptfile"]);
  381.                 
  382.                 foreach($_POST as $key => $value{
  383.                     
  384.                     if($key!="editonepage" && $key!="submit" && $key!="pageid" && $key!="path" && $key != "stylesheet" && $key != "scriptfile"{
  385.                         
  386.                         # Current language
  387.                         $lang substr($keystrrpos($key"_")+1strlen($key));
  388.                             
  389.                         $key substr($key0strrpos($key"_"));
  390.                         
  391.                         if($key != "visible"{
  392.                             
  393.                             $page["records"][$lang][$key]["value"$value;
  394.                             
  395.                         }
  396.                         else if($key == "visible"{
  397.                             
  398.                             $page["records"][$lang][$key]["value""true";
  399.                             
  400.                         }
  401.                         
  402.                     }
  403.                                         
  404.                 }
  405.                 
  406.                 
  407.                 
  408.                 
  409.                 try{
  410.                     $result $this->_dataBase->backendSetPageInformation($id$page);
  411.                     $page $this->_dataBase->backendGetPageInformation($id);
  412.                 
  413.                 catch(CaramelException $e{
  414.                     $e->getDetails();
  415.                 }
  416.                                 
  417.                 $this->_navigation TRUE;
  418.                 $this->_login FALSE;
  419.                 $this->_welcome FALSE;                
  420.                     
  421.                 $this->_templateView->assign("page"$page);
  422.                 $this->_templateView->assign("editonepage"TRUE);
  423.                 
  424.             }
  425.             # Edit template config
  426.             if(isset($_POST["edittemplates"])) {
  427.                                 
  428.                 $newTemplate $_POST["template"];
  429.                 
  430.                 try {
  431.                     $this->_config->setTemplateAction($newTemplate);
  432.                 }
  433.                 catch(CaramelException $e{
  434.                     $e->getDetails();
  435.                 }
  436.                 
  437.                 $this->_navigation TRUE;
  438.                 $this->_login FALSE;
  439.                 $this->_welcome FALSE;
  440.                 
  441.                 $template $this->getTemplateConfig();
  442.                 
  443.                 $this->_templateView->assign("template"$template);
  444.                 $this->_templateView->assign("edittemplates"TRUE);
  445.                                 
  446.             }
  447.             # Edit global config
  448.             if(isset($_POST["editglobal"])) {
  449.                                                 
  450.                 $globals $this->getGlobalConfig();
  451.                 
  452.                 $globals["speaking_urls"]["value""false";
  453.                 $globals["language_selector_in_footer"]["value""false";
  454.                 
  455.                 
  456.                 foreach($_POST as $key => $value{
  457.                     
  458.                     if($key != "editglobal" && $key != "submit"{
  459.                         $globals[$key]["value"$value;
  460.                     }
  461.                     
  462.                     # Cover Speaking URLs
  463.                     if($key == "speaking_urls"{
  464.                         $globals["speaking_urls"]["value""true";
  465.                     }
  466.                     
  467.                     # Cover language_selector_in_footer
  468.                     if($key == "language_selector_in_footer"{
  469.                         $globals["language_selector_in_footer"]["value""true";
  470.                     }
  471.                     
  472.                 }
  473.  
  474.                 try{
  475.                     $result $this->_config->setGlobalsAction($globals);
  476.                     
  477.                 catch(CaramelException $e{
  478.                     $e->getDetails();
  479.                 }
  480.                 
  481.                 $globals $this->getGlobalConfig();
  482.                                     
  483.                 $this->_navigation TRUE;
  484.                 $this->_login FALSE;
  485.                 $this->_welcome FALSE;
  486.                 
  487.                 $this->_templateView->assign("globals"$globals);
  488.                 $this->_templateView->assign("editglobal"TRUE);
  489.                     
  490.             }
  491.             # Edit users
  492.             if(isset($_POST["editadmin"])) {
  493.                             
  494.                 $admin $this->_config->getAdminAction();
  495.             
  496.                 foreach($_POST as $key => $value{
  497.                     
  498.                     if($key != "editadmin" && $key != "submit" && $key != "admin_password" && $key != "password_verification"{
  499.                         $admin[$key]["value"$value;
  500.                     }
  501.                     
  502.                     # Handle password
  503.                     if($key=="admin_password" && $value!="" && $_POST["password_verification"]!=""{
  504.                         
  505.                         if($value==$_POST["password_verification"&& strlen($_POST["admin_email"])>1# verifiy password, save only when email is provided
  506.                             
  507.                             $admin["admin_password"]["value"$this->bcryptEncode($_POST["admin_email"]$value);
  508.                         
  509.                         }
  510.                     }
  511.                     
  512.                 }
  513.             
  514.                 try{
  515.                     $result $this->_config->setAdminAction($admin);
  516.                 
  517.                 catch(CaramelException $e{
  518.                     $e->getDetails();
  519.                 }
  520.             
  521.                 $admin $this->_config->getAdminAction();
  522.                     
  523.                 $this->_navigation TRUE;
  524.                 $this->_login FALSE;
  525.                 $this->_welcome FALSE;
  526.                 
  527.                 $this->_templateView->assign("admin"$admin);
  528.                 $this->_templateView->assign("editadmin"TRUE);
  529.                     
  530.             }
  531.  
  532.         }
  533.         
  534.         $this->_templateView->assign("navigation"$this->_navigation);
  535.         $this->_templateView->assign("login"$this->_login);
  536.         $this->_templateView->assign("welcome"$this->_welcome);
  537.  
  538.         $this->_templateView->renderGzipped();
  539.         
  540.     // End of method declaration
  541.     
  542.     
  543.     
  544.     /**
  545.      * Method to initialize login session
  546.      * 
  547.      * @return void 
  548.      */
  549.     public function sessionAction({
  550.                 
  551.         session_set_cookie_params(604800)# 7 Days        
  552.         session_start();
  553.         
  554.     // End of method declaration
  555.     
  556.     
  557.  
  558.     /**
  559.      * Print out version-information in index.php
  560.      * 
  561.      * @return Version information comment
  562.      */
  563.     public function versionInformationAction({
  564.         
  565.         $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";
  566.                 
  567.         return $comment;
  568.     
  569.     // End of method declaration
  570.     
  571.     
  572.     
  573.     /**
  574.      * Print out head-tag in index.php
  575.      *
  576.      * @return Complete head-tag
  577.      */
  578.     public function headTagAction({
  579.         
  580.         $meta $this->getMeta();
  581.         
  582.         $headTag "\n<meta charset=\"utf-8\">\n\n".$meta."\n\n<title>Caramel CMS Backend</title>\n\n";
  583.     
  584.         $headTag .= $this->_templateView->addCssJs();
  585.         
  586.         $headTag .= "<script type=\"text/javascript\" src=\"".TEMPLATEDIR."/Backend/js/ckeditor/ckeditor.js\"></script>\n";
  587.         $headTag .= "<script type=\"text/javascript\" src=\"".TEMPLATEDIR."/Backend/js/ckeditor/adapters/jquery.js\"></script>\n";
  588.             
  589.         return $headTag;
  590.     
  591.     // End of method declaration
  592.     
  593.     
  594.     
  595.     /**
  596.      * This action logs the user off
  597.      *
  598.      * @return void 
  599.      */
  600.     public function logoutAction({
  601.     
  602.         if($this->getSession()==TRUE{
  603.             session_destroy();
  604.             session_unset();
  605.         }
  606.     
  607.     // End of method declaration
  608.     
  609.     
  610.     
  611. ##################################################
  612. ### Helper functions:
  613. ##################################################
  614.  
  615.     /**
  616.      * Check if session is active or not
  617.      * 
  618.      * @return TRUE or FALSE, wether a session is active or not
  619.      */
  620.     private function getSession({
  621.         
  622.         if(!isset($_SESSION["loggedin"]|| $_SESSION["loggedin"]==FALSE{
  623.             return FALSE;
  624.         else {
  625.             return TRUE;
  626.         }
  627.         
  628.     // End of method declaration
  629.     
  630.     
  631.     
  632.     /**
  633.      * Get parameters of GET-query before ampersand
  634.      * 
  635.      * @return New querystring for building correct URL
  636.      */
  637.     private function getParametersBefore({
  638.         $serverQueryString $_SERVER['QUERY_STRING'];
  639.  
  640.         try {
  641.             $speakingUrls $this->_config->getConfigStringAction("SPEAKING_URLS");
  642.         }
  643.         catch(CaramelException $e{
  644.             $e->getDetails();
  645.         }
  646.             
  647.         if($speakingUrls == "false"{
  648.                 
  649.             if(preg_match('/lang/',$serverQueryString)) {        
  650.                 $newQueryString '?'.substr($serverQueryString,0,7).'&amp;';
  651.             }
  652.             elseif (!preg_match('/lang/',$serverQueryStringand preg_match('/display/',$serverQueryString)) {
  653.                 $newQueryString '?';
  654.             }
  655.             else {
  656.                 $newQueryString '';
  657.             }
  658.             
  659.         }
  660.         
  661.         if($speakingUrls == "true"{
  662.             $newQueryString substr($_SERVER['REQUEST_URI']0strpos($_SERVER['REQUEST_URI']$this->getLanguage())+strlen($this->getLanguage()));
  663.         }
  664.         
  665.         return $newQueryString;
  666.         
  667.     // End of method declaration
  668.     
  669.     
  670.     
  671.     /**
  672.      * Get parameters of GET-query behind ampersand
  673.      * 
  674.      * @return New querystring for building correct URL
  675.      */
  676.     private function getParametersBehind({
  677.         $serverQueryString $_SERVER['QUERY_STRING'];
  678.  
  679.         try {
  680.             $speakingUrls $this->_config->getConfigStringAction("SPEAKING_URLS");
  681.         }
  682.         catch(CaramelException $e{
  683.             $e->getDetails();
  684.         }
  685.             
  686.         if($speakingUrls == "false"{
  687.         
  688.             if(preg_match('/lang/',$serverQueryString)) {                
  689.                         
  690.                 if(preg_match('/display/',$serverQueryString)) {
  691.                     $ampZeichen '&amp;';
  692.                 }
  693.                 else {
  694.                     $ampZeichen '';
  695.                 }
  696.                 $newQueryString $ampZeichen.substr($serverQueryString,8);
  697.             }
  698.             elseif (preg_match('/display/',$serverQueryStringAND !preg_match('/lang/',$serverQueryString)) {
  699.                 $newQueryString '&amp;'.substr($serverQueryString,0);
  700.             }
  701.             else {
  702.                 $newQueryString '';
  703.             }
  704.             
  705.             return $newQueryString;
  706.             
  707.         }
  708.         
  709.         elseif($speakingUrls == "true"{
  710.                 
  711.             if(isset($_GET['display'])) {
  712.                 $newQueryString '/'.substr($serverQueryString,16).'/';
  713.             else {
  714.                 $newQueryString '/'.substr($serverQueryString,16);
  715.             }
  716.             
  717.             return $newQueryString;
  718.             
  719.         }
  720.         
  721.     // End of method declaration
  722.     
  723.     
  724.     
  725.     /**
  726.      * Print out base url in index.php
  727.      * 
  728.      * @return The Base-URL
  729.      */
  730.     private function getBaseUrl({
  731.     
  732.         try {
  733.             $speakingUrls $this->_config->getConfigStringAction("SPEAKING_URLS");
  734.         }
  735.         catch(CaramelException $e{
  736.             $e->getDetails();
  737.         }
  738.         
  739.         
  740.         if($speakingUrls == "true"{
  741.             
  742.             try {
  743.                 return "<base href=\"".$this->_config->getConfigStringAction('BASE')."\">\n";
  744.             }
  745.             catch(CaramelException $e{
  746.                 $e->getDetails();
  747.             }
  748.             
  749.         else {
  750.             return "";
  751.         }
  752.         
  753.     // End of method declaration
  754.     
  755.     
  756.     
  757.     /**
  758.      * Print out meta-tags in index.php
  759.      * 
  760.      * @return Meta-tags for author, keywords and description
  761.      */
  762.     private function getMeta({
  763.         
  764.         $metaAuthor "<meta name=\"author\" content=\"Felix Rupp, Nicole Reinhardt\">";
  765.         
  766.         $metaGenerator "<meta name=\"generator\" content=\"Caramel CMS ".self::VERSION."\">";
  767.         
  768.         $metaTags $metaAuthor."\n".$metaGenerator."\n";
  769.                         
  770.         return $metaTags;
  771.     
  772.     // End of method declaration
  773.     
  774.     
  775.     
  776.     /**
  777.      * This method returns a correct formatted array with all global settings
  778.      * 
  779.      * @return Array with global configuration
  780.      */
  781.     private function getGlobalConfig({
  782.         
  783.         try {
  784.             $globals $this->_config->getGlobalsAction();
  785.                     
  786.             $globals["startpage"]["acceptedValues"$this->_dataBase->backendGetAllPageNamesAction();
  787.                         
  788.             return $globals;
  789.         }
  790.         catch(CaramelException $e{
  791.             $e->getDetails();
  792.         }
  793.         
  794.     // End of method declaration
  795.     
  796.     
  797.     
  798.     /**
  799.      * This method returns a correct formatted array with our template settings
  800.      * 
  801.      * @return Array with template configuration
  802.      */
  803.     private function getTemplateConfig({
  804.         
  805.         try {
  806.             $template $this->_config->getTemplateAction();
  807.         }
  808.         catch(CaramelException $e{
  809.             $e->getDetails();
  810.         }
  811.         
  812.         $acceptedValues array();
  813.         
  814.         ## Find all possible templates
  815.         $dirIterator new DirectoryIterator(BASEDIR.'/template/');
  816.         
  817.         foreach($dirIterator as $dirItem{
  818.             
  819.             if($dirItem->isDir(&& !$dirItem->isDot(&& strpos($dirItem->getPathname()"Backend")==FALSE# All folders without dots and NOT Backend-Template
  820.                 
  821.                 if(is_file($dirItem->getPathname()."/index.tpl.php")) {
  822.                 
  823.                     $acceptedValues[substr($dirItem->getPathname()strrpos($dirItem->getPathname()"/")+1strlen($dirItem->getPathname()));
  824.                     
  825.                 }
  826.                             
  827.             }
  828.             
  829.         }
  830.         
  831.         
  832.         $templateArray["template"]["label""Template";
  833.         $templateArray["template"]["value"$template;
  834.         $templateArray["template"]["blank""false";
  835.         $templateArray["template"]["acceptedValues"$acceptedValues;
  836.         
  837.         return $templateArray;
  838.         
  839.     // End of method declaration
  840.     
  841.     
  842.     
  843.     /**
  844.      * Method to hash via bcrypt.
  845.      * 
  846.      * @param String $email eMail adress
  847.      * @param String $password Password to encode
  848.      * 
  849.      * @return BCrypt hashed password.
  850.      */
  851.     private function bcryptEncode($email$password{
  852.         
  853.         try {
  854.             $result $this->checkBlowfish();
  855.             
  856.             $salt 'q8JJ4Ere8w75fCQ3yMZj5A8Yr632zm8keZDSbphjY43r3Z9cY4L5A6V4vK75p4xP';
  857.             $string hash_hmac("whirlpool"str_pad ($passwordstrlen ($password)*4sha1($email)STR_PAD_BOTH )self::SYSTEM_SALTtrue );
  858.             $rounds '12';
  859.                 
  860.             return crypt($string'$2a$'.$rounds.'$'.$salt);
  861.             
  862.         catch(CaramelException $e{
  863.             $e->getDetails();
  864.         }
  865.         
  866.     // End of method declaration
  867.     
  868.     
  869.     
  870.     /**
  871.      * Method to check bcrypt encoded passwords
  872.      * 
  873.      * @param String $email eMail adress
  874.      * @param String $password Password given to check
  875.      * @param String $stored Password to check against
  876.      * 
  877.      * @return Boolean value. True if password is valid.
  878.      */
  879.     private function bcryptCheck($email$password$stored{
  880.         
  881.         try {
  882.             $result $this->checkBlowfish();
  883.             
  884.             $string hash_hmac("whirlpool"str_pad($passwordstrlen($password)*4sha1($email)STR_PAD_BOTH)self::SYSTEM_SALTtrue);
  885.             
  886.             return crypt($stringsubstr($stored030)) == $stored;
  887.             
  888.         catch(CaramelException $e{
  889.             $e->getDetails();
  890.         }
  891.         
  892.         
  893.         
  894.     // End of method declaration
  895.     
  896.     
  897.     
  898.     /**
  899.      * Method to check if Blowfish algorithm is available on this server.
  900.      * 
  901.      * @throws CaramelException
  902.      */
  903.     private function checkBlowfish({
  904.         
  905.         if (!defined('CRYPT_BLOWFISH')) {
  906.             
  907.             throw new CaramelException(66);
  908.             
  909.         }
  910.             
  911.     // End of method declaration
  912.  
  913. // End of class declaration
  914.  
  915. ?>