| author | Bashkim Isai |
|---|---|
| package | Output |
In file D:\oblib-core\php\oblib\dataContent\dataMenu.class.php between lines 52 and 192.
<?php
/**
* A dataMenu will traverse an XML document containing menu information to allow
* Controllers and XML documents to be launched depending on the URL
*
* @author Bashkim Isai
* @package Output
* @see Class [data]
* @see Class [dataController]
* @see Class [dataSection]
*/
class dataMenu
{
/**
* The DOMDocument for the Menu XML
*
* @type String
* @see Class [DOMDocument]
*/
private $_domMenu;
/**
* The XPath reader for the Menu XML
*
* @type String
* @see Class [DOMDocument]
*/
private $_dxpMenu;
/**
* Stores all the required information for the Menu and the current Menu item
*
* @see Class [data]
* @see Class [DOMDocument]
* @see Class [DOMXPath]
* @return Void
*/
function __construct ($strMenuFile)
{
$this->_domMenu = new DOMDocument;
$this->_domMenu->Load ($strMenuFile);
$this->_dxpMenu = new DOMXPath ($this->_domMenu);
}
/**
* Renders the Controller using the XSL document as a View. If no XSL
* document is specified, it will output the raw XSL information
*
* @return Void
*/
public function ___Render ($strRequestPath=NULL)
{
$arrParam = Array ();
if ($strRequestPath === NULL)
{
if (isset ($argc) && $argc !== 0 && isset ($argv [1]))
{
$strRequestPath = $argv [1];
}
else if (isset ($_SERVER ['PATH_INFO']))
{
$strRequestPath = $_SERVER ['PATH_INFO'];
}
else
{
$strRequestPath = '';
}
}
$arrRequestPath = preg_split ('/\//', $strRequestPath, NULL, PREG_SPLIT_NO_EMPTY);
// Get the DOMNode Object
$dnoRequestData = $this->_Parse ($arrRequestPath);
if ($dnoRequestData === NULL)
{
throw new dataControllerHTTPError (404);
}
// Include Requested Files
$dnlFile = $this->_dxpMenu->Query ('./file', $dnoRequestData);
foreach ($dnlFile as $dnoFile)
{
require_once (DIR_CONTROLLER . '/' . $dnoFile->nodeValue);
}
// Get the Params
$dnlParam = $this->_dxpMenu->Query ('./param', $dnoRequestData);
foreach ($dnlParam as $dnoParam)
{
$arrParam [$dnoParam->getAttribute ('name')] = $arrRequestPath [$dnoParam->getAttribute ('position')];
}
// Get the Controller
$dnoController = $this->_dxpMenu->Query ('./controller', $dnoRequestData)->item (0);
if (!$dnoController)
{
throw new dataControllerHTTPError (404);
}
$cntController = new $dnoController->nodeValue ($arrParam);
// Get the XSL File
$dnoXSLDocument = $this->_dxpMenu->Query ('./xsl', $dnoRequestData)->item (0);
if ($dnoXSLDocument === NULL)
{
echo $cntController;
}
else
{
$cntController->___Output (DIR_VIEW . $dnoXSLDocument->nodeValue);
}
}
/**
* Traverses through the dataMenu XML Document attempting to find a
* match for a menu path
*
* @return DOMNode
*/
private function _Parse ($arrPath)
{
$dnoParent = $this->_domMenu->documentElement;
foreach ($arrPath as $strPath)
{
$dnoPath = $this->_dxpMenu->Query ('./menu[@path=' . escapeshellarg ($strPath) . ']', $dnoParent)->item (0);
if (!$dnoPath)
{
$dnoPath = $this->_dxpMenu->Query ('./menu[@path="%"]', $dnoParent)->item (0);
}
if (!$dnoPath)
{
return NULL;
}
$dnoParent = $dnoPath;
}
return $dnoParent;
}
}
?>