Source for file LPageService.php
Documentation is available at LPageService.php
* @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
* @copyright 2005, diemeisterei GmbH. All rights reserved.
* @author $Author: schmunk $
* @version $Revision: 636 $ $Date: 2007-02-25 14:01:09 +0100 (So, 25 Feb 2007) $
* @package Phundament.Packages
* @subpackage LVirtualNodes
* This service is able to use propel node tree objects from a database
* (l_virtual_nodes). You can request a node with a predefined NODE_PREFIX the node
* maps to a .page or and external link.
* @package System.Web.Services
Prado :: setPathOfAlias("LPageService", dirname(__FILE__ ));
Prado :: using("LPageService.db.propel.*");
Prado :: using("LPageService.db.propel.l_virtual_nodes.*");
private $_currentNode = null;
private $_currentNodeId = 0;
private $_currentNodeAlias = null;
private $_areNodesAvailable;
* Returns if node-based service is available
if ($this->Application->getGlobalState("LVirtualNodes:available") !== true)
$this->checkVirtualNodes();
$this->Application->setGlobalState("LVirtualNodes:available", $this->_areNodesAvailable);
$this->_areNodesAvailable= $this->Application->getGlobalState("LVirtualNodes:available");
return $this->_areNodesAvailable;
* Returns all nodes in tree structure starting from root
* Returns all nodes in list structure
return $this->_nodes_list;
* Returns the current node object
if ($this->_currentNodeId == 0 || $this->_currentNode !== null)
return $this->_currentNode;
$this->_currentNode = $this->findNodeById($this->getNodes(), $this->_currentNodeId);
return $this->_currentNode;
* Returns the current node object
* return current selected page for this service
if (!$this->_currentNodeAlias && !$this->_currentNodeId)
$p = $this->getRequest()->getServiceParameter();
return (empty ($p)) ? $this->getDefaultPage() : $p;
else if ($return_node_alias)
return $this->_currentNodeAlias;
return self :: NODE_PREFIX . $this->_currentNodeId;
public function init($config)
* Checks availablity of node service
private function checkVirtualNodes()
$conn= $this->Application->getModule("database")->getConnection("l_virtual_nodes", "propel");
$query= "SELECT id FROM l_virtual_nodes_site LIMIT 1";
$result= LCreole :: doQuery($query, $conn); // Propel-like object (getter & setter)
$this->_areNodesAvailable= true;
Prado :: trace("Virtual Nodes available", 'Lithron.LPageService');
Prado :: log($e->getMessage(), 4, 'Lithron.LPageService');
$this->_areNodesAvailable= false;
* Queries all nodes in database and serves them for later use
private function prepareNodes()
// query nodes if not in cache
$conn= $this->Application->getModule("database")->getConnection("l_virtual_nodes", "propel");
$this->_nodes= LVirtualNodesSiteNodePeer :: retrieveRootNode(true, $conn);
$fc->addAnd(LVirtualNodesSitePeer :: ID, 1, Criteria :: NOT_EQUAL);
$fc->addAscendingOrderByColumn(LVirtualNodesSitePeer :: PATH);
$this->_nodes_list= LVirtualNodesSitePeer :: doSelect($fc);
Prado :: trace("Nodes prepared ...", 'Lithron.LPageService');
if (substr($id, 0, 1) == self :: NODE_PREFIX)
return $this->findNodeById($this->getNodes(), $id);
return $this->findNodeById($this->getNodes(), $id);
return $this->findNodeByAlias($this->getNodes(), $id);
* Finds a node in the tree by id
private function findNodeById($startNode, $searchId)
if ($startNode->getId() == $searchId)
$child= $startNode->getFirstChildNode();
$nodeId= $child->getId();
if ($nodeId == $searchId)
$return= $this->findNodeById($child, $searchId);
$child= $child->getSiblingNode();
* Finds a node in the tree by alias
private function findNodeByAlias($startNode, $searchAlias)
#echo $startNode->getAlias()."=$searchAlias | ";
if ($startNode->getAlias() == $searchAlias)
$child= $startNode->getFirstChildNode();
$alias= $child->getAlias();
if ($alias == $searchAlias)
$return= $this->findNodeByAlias($child, $searchAlias);
$child= $child->getSiblingNode();
* Determines the requested page path.
* 1. nodeId (database needed)
* 2. path (database needed)
* @return string page path requested
Prado :: log("Determining requested PagePath", 1, 'Lithron.LPageService');
$param = $this->getRequest()->getServiceParameter();
$cache = $this->Application->Cache;
$param = $this->getDefaultPage();
Prado :: log("default page requested ($param)", 1, 'Lithron.LPageService');
$static_page_file = Prado :: getPathOfAlias("Pages") . "/" . str_replace(".", "/", $param) . ".page";
Prado :: log("static page found ($pagePath)", 1, 'Lithron.LPageService');
throw new Exception("no valid id given!");
$this->_currentNodeId = TPropertyValue::ensureInteger($suffix);
$cache_entry_path = "LVirtualNodes:PathForNodeId:" . $suffix;
$cache_entry_alias = "LVirtualNodes:AliasForNodeId:" . $suffix;
if ($cache && $cache->get($cache_entry_path) && $cache->get($cache_entry_alias))
$pagePath = $cache->get($cache_entry_path);
$this->_currentNodeAlias = $cache->get($cache_entry_alias);
Prado :: log("node by id ($suffix) found in cache ($pagePath)", 1, 'Lithron.LPageService');
$current_node = $this->findNodeById($this->getNodes(), $suffix);
throw new Exception("node with id $suffix not found!");
$pagePath = $current_node->getPage();
$this->_currentNodeAlias = $current_node->getAlias();
$cache->set($cache_entry_path, $pagePath);
$cache->set($cache_entry_alias, $this->_currentNodeAlias);
Prado :: log("node by id ($suffix) found in database and saved to cache ($pagePath)", 1, 'Lithron.LPageService');
$cache_entry_path = "LVirtualNodes:PathForNodeAlias:" . $param;
$cache_entry_id = "LVirtualNodes:IdForNodeAlias:" . $param;
$this->_currentNodeAlias = $param;
if ($cache && $cache->get($cache_entry_path) && $cache->get($cache_entry_id))
$pagePath = $cache->get($cache_entry_path);
$this->_currentNodeId = $cache->get($cache_entry_id);
Prado :: log("node by alias ($param) found in cache ($pagePath)", 1, 'Lithron.LPageService');
$current_node = $this->findNodeByAlias($this->getNodes(), $param);
$pagePath = $current_node->getPage();
$this->_currentNodeId = $current_node->getId();
$cache->set($cache_entry_path, $pagePath);
$cache->set($cache_entry_id, $this->_currentNodeId);
Prado :: log("node by alias ($param) found in database and saved to cache ($pagePath)", 1, 'Lithron.LPageService');
// when we come here, the requested page is no
// we could fall back to prado here, but I will rather throw an exception,
// because it's pretty sure Prado can't serve anything else.
throw new THttpException(404,'pageservice_page_unknown', $param);
Prado :: log("unknown pagetype - falling back to PRADO ($pagePath)", 1, 'Lithron.LPageService');
public function constructUrl($pagePath, $getParams= null, $encodeAmpersand= true, $encodeGetItems= true, $log= false)
if ($log) echo "constructUrl for $pagePath<br>";
if ($pattern= $this->Application->Parameters['LinkUrlType'])
$p= $this->parseGetParams($getParams, $encodeAmpersand, $encodeGetItems);
if ($this->Application->getModule('geo_ip') instanceof TModule)
$geoip_country_code= $this->Application->getModule('geo_ip')->getCountryCode();
$geoip_country_name= $this->Application->getModule('geo_ip')->getCountryName();
$geoip_country_code= "--";
$geoip_country_name= "--";
"{REQ_APPURL}" => $this->Request->ApplicationUrl,
$this->Request->ApplicationUrl
), "{CULTURE}" => $this->Application->Globalization->Culture, "{GEOIP_COUNTRY}" => $geoip_country_code, "{ALIAS}" => $pagePath, "{AMP_GET_PARAM}" => ($p ? "&" . $p : ""), "{QM_GET_PARAM}" => ($p ? "?" . $p : ""),);
$res = strtr($pattern, $trans);
return $this->getRequest()->constructUrl($this->getID(), $pagePath, $getParams, $encodeAmpersand, $encodeGetItems);
private function parseGetParams($getParams= null, $encodeAmpersand= false, $encodeGetItems= true)
foreach ($getParams AS $key => $value)
$params .= $key . "=" . $value . "&"; // TODO
Lithron :: saveLogging($this->Application);
$this->Response->redirect($url);
|