Ejemplo n.º 1
0
 function _buildpath($matches)
 {
     $tid = $matches[1];
     if (USEPREFIX && (!$this->prefix || $this->prefix == '')) {
         $langs = explode(',', AVAILABLELANG);
         $this->prefix = $langs[0] . '/';
     }
     $t = new Tree();
     return $this->prefix . $t->getPath((int) $tid);
 }
Ejemplo n.º 2
0
 public function init()
 {
     $this->_setLanguage();
     if (isset($_SERVER['REDIRECT_STATUS'])) {
         // no need to check the url, serve a special page
         switch ($_SERVER['REDIRECT_STATUS']) {
             case Serve::$SPECIAL_403:
             case Serve::$SPECIAL_404:
                 $this->serveSpecial($_SERVER['REDIRECT_STATUS'], __LINE__);
                 return;
         }
     }
     // Fix for Windows / IIS servers
     if (!isset($_SERVER['REQUEST_URI'])) {
         if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) {
             $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
         } else {
             $_SERVER['REQUEST_URI'] = '/index.php';
             // substr($_SERVER['PHP_SELF'],1 );
             if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] !== '') {
                 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
             }
         }
     }
     if ($this->_isFile()) {
         $this->serveSpecial(Serve::$SPECIAL_404, __LINE__);
         return;
     }
     // Request by treeId (e.g. /index.php?tid=123
     if (strpos($_SERVER['REQUEST_URI'], '/index.php') === 0 && isset($_GET['tid'])) {
         $bright_tree = new Tree();
         $bright_path = $bright_tree->getPath($_GET['tid']);
         if ($bright_path) {
             // IF path is valid, redirect...
             $url = USEPREFIX === true ? BASEURL . $_SESSION['language'] . '/' . $bright_path : BASEURL . $bright_path;
             header('Location: ' . $url);
             exit;
         } else {
             // Else: 404
             $this->serveSpecial(Serve::$SPECIAL_404);
             return;
         }
     }
     // Normal request
     if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== 0) {
         $requestUri = $_SERVER['REQUEST_URI'];
         // Save get variables
         $urlParameters = explode('?', $requestUri);
         if (count($urlParameters) >= 2) {
             $requestUri = $urlParameters[0];
             $bright_gv = explode('&', $urlParameters[1]);
             foreach ($bright_gv as $bright_getval) {
                 $bright_gva = explode('=', $bright_getval, 2);
                 if (count($bright_gva) > 1) {
                     $_GET[$bright_gva[0]] = $bright_gva[1];
                 }
             }
         }
         // Get the path
         $treeNodes = $this->_router->getTreeNodes($requestUri);
     } else {
         // Just serve the homepage
         $treeNodes = $this->_router->getTreeNodes('');
     }
     $bright_is404 = $treeNodes && is_numeric($treeNodes[0]) && (int) $treeNodes[0] == 404;
     // Path not found
     if ($bright_is404) {
         $this->serveSpecial(Serve::$SPECIAL_404, __LINE__);
         return;
     }
     $this->servepage($treeNodes);
 }
Ejemplo n.º 3
0
 /**
  * Deletes a page<br/>
  * Required permissions:<br/>
  * <ul>
  * <li>IS_AUTH</li>
  * <li>DELETE_PAGE</li>
  * </ul>
  * @param int $id The id of the page
  * @return bool True when successful
  * @throws \Exception
  */
 public function deletePage($id)
 {
     if (!$this->IS_AUTH) {
         throw $this->throwException(AuthenticationException::NO_USER_AUTH);
     }
     if (!$this->DELETE_PAGE) {
         throw $this->throwException(5001);
     }
     if (!is_numeric($id)) {
         throw $this->throwException(ParameterException::INTEGER_EXCEPTION);
     }
     $cache = new Cache();
     $cache->deleteCacheByPrefix('pages');
     //First check if the page is present in the tree.
     $sql = 'SELECT `treeId` FROM tree WHERE `pageId`=' . (int) $id;
     $tids = $this->conn->getFields($sql);
     if (count($tids) > 0) {
         $tree = new Tree();
         $paths = array();
         foreach ($tids as $tid) {
             $paths[] = $tree->getPath($tid);
         }
         throw $this->throwException(5003, array(join("\n- ", $paths)));
     }
     $sql = 'DELETE FROM `page` WHERE `pageId` = ' . (int) $id;
     $this->conn->deleteRow($sql);
     $sql = 'DELETE FROM `content` WHERE `pageId` = ' . (int) $id;
     $this->conn->deleteRow($sql);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Redirects to the given treeId
  * @param int $treeId
  */
 public static function redirect($treeId)
 {
     $t = new Tree();
     $path = $t->getPath((int) $treeId);
     $url = BASEURL;
     if ($path === null) {
         $bs = new Serve();
         $bs->serveSpecial(Serve::$SPECIAL_404);
         exit;
     }
     if (USEPREFIX) {
         if (isset($_SESSION) && isset($_SESSION['language'])) {
             $url .= $_SESSION['language'] . '/';
         } else {
             $l = explode(',', AVAILABLELANG);
             $url .= $l[0] . '/';
         }
     }
     $url .= $path;
     header("Location: {$url}");
     exit;
 }
Ejemplo n.º 5
0
 /**
  * Submits the form
  */
 public function submit()
 {
     $this->check();
     if (count($this->_errors) == 0) {
         // Valid form
         switch ($this->_action) {
             case self::ACTION_EMAIL:
                 // Send the form
                 if (!$this->_recipient) {
                     throw new \Exception($this->_exceptions[Form::EXCEPTION_INVALID_EMAIL], Form::EXCEPTION_INVALID_EMAIL);
                 }
                 $emldata = array('bodytext' => $this->_bodytext, 'title' => $this->_title, 'fields' => $this->_data);
                 $smarty = new \Smarty();
                 $ds = DIRECTORY_SEPARATOR;
                 $smarty->assign($emldata)->setCacheDir(BASEPATH . "bright{$ds}cache{$ds}smarty")->setCompileDir(BASEPATH . "bright{$ds}cache{$ds}smarty_c")->enableSecurity()->addTemplateDir(BASEPATH . "bright{$ds}library{$ds}Bright{$ds}templates{$ds}")->registerPlugin(\Smarty::PLUGIN_FUNCTION, 'getLabel', array($this, '_getLabel'))->registerPlugin(\Smarty::PLUGIN_FUNCTION, 'getValue', array($this, '_getValue'))->php_handling = \Smarty::PHP_REMOVE;
                 ob_start();
                 $smarty->display('FormMailTemplate.tpl');
                 $html = ob_get_clean();
                 ob_start();
                 $smarty->display('FormMailPlainTemplate.tpl');
                 $plain = ob_get_clean();
                 $mailer = new Mailer();
                 $res = $mailer->sendHtmlMail(MAILINGFROM, $this->_recipient, $this->_subject, $html, $plain);
                 if ($res && $this->_pageAfterSuccess != null) {
                     $t = new Tree();
                     $path = $t->getPath($this->_pageAfterSuccess);
                     if (USEPREFIX) {
                         $path = $_SESSION['language'] . '/' . $path;
                     }
                     $path = BASEURL . $path;
                     header("Location: {$path}");
                     exit;
                 }
                 break;
             case self::ACTION_STORE:
                 // Store the data
                 throw new \Exception($this->_exceptions[Form::EXCEPTION_NOT_IMPLEMENTED] . ' ACTION_STORE', Form::EXCEPTION_NOT_IMPLEMENTED);
                 break;
         }
     }
     return $this;
 }