コード例 #1
0
ファイル: SmartyView.php プロジェクト: rsids/bright_api
 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);
 }
コード例 #2
0
ファイル: Router.php プロジェクト: rsids/bright_api
 /**
  * @param array $treeNodes
  * @return OTreeNode|int
  * @throws \Exception
  */
 public function getView($treeNodes)
 {
     $bright = new Bright();
     $tree = new Tree();
     $cal = new Calendar();
     $maps = new Maps();
     $user = new User();
     $root = $bright->getRoot();
     $numTreeNodes = count($treeNodes);
     $groups = array();
     if ($numTreeNodes > 0) {
         $child = $root;
         //new OTreeNode();
         for ($i = 0; $i < $numTreeNodes; $i++) {
             // Check if an alternative parser is required
             if ($child && isset($child->parser) && (int) $child->parser > 1) {
                 $child->parser = (int) $child->parser;
                 switch ($child->parser) {
                     case Router::$CALENDAR_PARSER:
                         // Must be last item
                         if ($i < $numTreeNodes - 1) {
                             return 404;
                         }
                         $event = $cal->getEventByLabel($treeNodes[$i]);
                         if (!$event) {
                             return 404;
                         }
                         $c = new OTreeNode();
                         $c->treeId = $child->treeId;
                         $c->page = $event;
                         $c->path = join('/', $treeNodes);
                         return $c;
                         break;
                     case Router::$MARKER_PARSER:
                         // Must be last item
                         if ($i < $numTreeNodes - 1) {
                             return 404;
                         }
                         $marker = $maps->getMarkerByLabel($treeNodes[$i]);
                         if (!$marker) {
                             return 404;
                         }
                         $result = new OTreeNode();
                         $result->parentId = $child->treeId;
                         $result->page = $marker;
                         $result->path = join('/', $treeNodes);
                         return $result;
                         break;
                     case Router::$USER_PARSER:
                         $userPage = $user->getUserByLabel($treeNodes[$i]);
                         if (!$userPage) {
                             return 404;
                         }
                         $child = new OTreeNode();
                         $child->page = $userPage;
                         $child->path = join('/', $treeNodes);
                         return $child;
                         break;
                 }
             } else {
                 $child = $tree->getChildByLabel($child->treeId, $treeNodes[$i]);
             }
             if (!$child) {
                 return 404;
             }
             if ($child->loginrequired) {
                 $groups = array_merge($groups, $child->requiredgroups);
             }
         }
         // Check if we're member of the required groups
         $hasAccess = true;
         if (count($groups) > 0) {
             $authenticatedUser = $user->getAuthUser();
             if ($authenticatedUser) {
                 $missing = array_diff($groups, $authenticatedUser->usergroups);
                 if (count($missing) > 0) {
                     //insufficient rights
                     $hasAccess = false;
                 }
             } else {
                 $hasAccess = false;
             }
         }
         if ($hasAccess === false) {
             // Redirect to login
             $path = BASEURL;
             $path .= USEPREFIX ? $_SESSION['prefix'] : '';
             $path .= LOGINPAGE;
             // Include treeId, so we can redirect back when login successful
             header('Location:' . $path . '?tid=' . $child->treeId);
             exit;
         }
         // Build path (no need to get it from the db, we just checked it, it exists :D)
         $child = $bright->getChild($child->treeId);
         $child->path = join('/', $treeNodes);
         return $child;
     }
     //ROOT
     return $root;
 }
コード例 #3
0
ファイル: Serve.php プロジェクト: rsids/bright_api
 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);
 }
コード例 #4
0
ファイル: BrightUtils.php プロジェクト: rsids/bright_api
 /**
  * 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;
 }
コード例 #5
0
ファイル: Page.php プロジェクト: rsids/bright_api
 /**
  * Updates a page
  * @param OPage page The page to update
  * @return OPage The updated page
  */
 private function _updatePage($page)
 {
     $ap = $page->alwayspublished ? 1 : 0;
     $sn = $page->showinnavigation ? 1 : 0;
     $cachebleChanged = $this->_cachebleChanged($page);
     $page->label = Connection::getInstance()->escape_string($this->generateLabel($page->label, $page->pageId));
     $page->modifiedby = isset($_SESSION['administratorId']) ? $_SESSION['administratorId'] : 0;
     BrightUtils::forceInt($page, array('publicationdate', 'expirationdate', 'itemType', 'pageId'));
     $sql = "UPDATE page \n\t\t\t\tSET label='{$page->label}',\n\t\t\t\titemType='{$page->itemType}', \n\t\t\t\tpublicationdate=FROM_UNIXTIME({$page->publicationdate}),\n\t\t\t\texpirationdate=FROM_UNIXTIME({$page->expirationdate}), \n\t\t\t\talwayspublished={$ap},\n\t\t\t\tshowinnavigation={$sn},\n\t\t\t\tmodificationdate=NOW(),\n\t\t\t\tmodifiedby={$page->modifiedby}\n\t\t\t\tWHERE pageId={$page->pageId}";
     $this->conn->updateRow($sql);
     $this->setContent($page);
     if ($cachebleChanged) {
         // Flush cache
         $cache = new Cache();
         $cache->flushCache();
         $tree = new Tree();
         $tree->generateSitemap();
     }
     return $this->getPageById($page->pageId, true);
 }
コード例 #6
0
ファイル: Form.php プロジェクト: rsids/bright_api
 /**
  * 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;
 }