_siteHendler(CURR_LANG.'/'.$aliasFull)){
return $doc;
} else {
return siteMap::get404Doc($aliasFull, $docHandler);
}
if (array_key_exists('docHandler', $siteMap)) {
$docHandler = $siteMap['docHandler'];
}
$curr_page .= '/' . $parent;
$level ++;
} while ($alias && !$siteMap['final']);
if ($siteMap['final']) {
$siteMap = SiteMap::_setRestAlias($siteMap, $alias);
}
$siteMap['docHandler'] = $docHandler;
$siteMap['CURR_PAGE'] = trim($curr_page, '/');
return $siteMap;
}
function _setRestAlias($siteMap, $alias)
{
foreach ($siteMap['item'] as $key => $v) {
$siteMap['item'][$key]['_restAlias'] = $alias;
}
return $siteMap;
}
function get404Item($alias)
{
return array('type' => 'NotFound');
}
function get404Doc($alias, $docHandler)
{
return array('title' => '404 Not Found',
'notFoundFlag' => true,
'docHandler' => $docHandler,
'item' => array(SiteMap::get404Item($alias)
)
);
}
function path2Type($type, $siteMap = null, $path = '')
{
if (is_null($siteMap)){
$siteMap = SiteMap::getArr();
$siteMap = $siteMap['site'];
}
$pathParent = $path;
if ($pathParent != ''){
$pathParent .= '/';
}
foreach ((array)$siteMap as $key => $page){
$path = $pathParent.$key;
foreach ((array)$page['item'] as $val) {
if ($type == $val['type']){
return $path;
}
}
if (is_array($page['sub'])){
$pathOut = SiteMap::path2Type($type, $page['sub'], $path);
if (!is_null($pathOut)){
return $pathOut;
}
}
}
return null;
}
function _getModuleFromPath($path)
{
return substr($path, 0, strpos($path, '/') );
}
function _getTplPathFromPath($path)
{
return substr($path, strpos($path, '/')+1 );
}
function getPath2ClassTpl($type, $fileIn, $filePattern, $fileName = null)
{ /*���� ���� ����������� �� ���� ������ ?
*/
// dump(debug_backtrace(), 'debug_backtrace');
if (!is_null($fileIn)){
if ('/' == substr($fileIn, 0, 1)){
$fullPath2File = $fileIn;
}else {
$fullPath2File = dirname(__FILE__).'/../../'.$fileIn;
}
} else {
if (!empty($fileName)){
$fileInfo = pathinfo($filePattern);
$file = $fileName.'-'.$fileInfo['basename'];
if ('.' != $fileInfo['dirname']){
$file = $fileInfo['dirname'].'/'.$fileIn;
}
}else {
$file = $filePattern;
}
$pathArr = array(
'form' => array(
Constant::get('BASE_PATH') . '/tpl/Form',
Constant::get('BASE_PATH') . '/class/Form/tpl',
),
'list' => array(
Constant::get('BASE_PATH') . '/tpl/List',
Constant::get('BASE_PATH') . '/class/DB/List/tpl',
),
'grid' => array(
Constant::get('BASE_PATH') . '/tpl/Grid',
Constant::get('BASE_PATH') . '/class/DB/Grid/tpl',
),
);
$errorMsg = 'Files not found: ';
foreach ($pathArr[$type] as $path){
$fullPath2File = $path.'/'.$file;
$errorMsg .= '
'.$fullPath2File;
if (file_exists($fullPath2File) && is_file($fullPath2File) ){
return $fullPath2File;
}
}
$errorMsg .= '
';
if (!empty($fileName)){
trigger_error($errorMsg, E_USER_ERROR);
return SiteMap::getPath2ClassTpl($type, null, $filePattern);
}else {
trigger_error($errorMsg, E_USER_ERROR);
return false;
}
}
return $fullPath2File;
}
public static function getPath($path)
{
$pathLocal = SITEMAP_APP_DIR. '/' . $path;
$pathModule = SITEMAP_APP_DIR. '/' . SiteMap::_getModuleFromPath($path) .'/Module/'. SiteMap::_getTplPathFromPath($path) ;
if ('tpl' == substr(SiteMap::_getTplPathFromPath($path), 0, 3) ){
$pathTpl = Constant::get('BASE_PATH') . '/tpl/'. SiteMap::_getModuleFromPath($path). '/'. substr(SiteMap::_getTplPathFromPath($path), 4);
if (file_exists($pathTpl) && is_file($pathTpl) ){
return $pathTpl;
}
}
if (file_exists($pathLocal) && is_file($pathLocal) ){
return $pathLocal;
}elseif (file_exists($pathModule) && is_file($pathModule)) {
return $pathModule;
}
return null;
}
function getObjName($path)
{
$fullPath = SiteMap::getPath($path);
$fullPath = str_replace(SITEMAP_APP_DIR. '/', '', $fullPath);
$const = str_replace('/', '', $fullPath);
$const = preg_replace('/\.php$/', '', $const);
$const = 'cn_'.$const;
if (defined($const)){
return constant($const);
}else {
trigger_error("$const is not defined in ".SiteMap::getPath($path)."", E_USER_ERROR);
return false;
}
}
public static function &getObj($path, $arg0 = null, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null, $arg8 = null, $arg9 = null, $arg10 = null)
{
if (file_exists(SiteMap::getPath($path)) ){
require_once SiteMap::getPath($path);
$objName = SiteMap::getObjName($path);
if (false === $objName){
return null;
}
$obj = new $objName($arg0, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $arg8, $arg9, $arg10);
return $obj;
}else {
trigger_error("Files not found: $path
", E_USER_ERROR);
}
}
function getAliasByItemType($itemType)
{
return SiteMap::getAliasByItem($itemType, null);
}
function getAliasByItem($itemType, $itemName = 'Nameless')
{
require_once('class/Session.php');
if ($cache = Session::getData($itemType, ($itemName === null)?'NULL':$itemName)) {
return $cache;
}
require_once('class/DB/S_db2.php');
$db = S_db2::getInstance();
$sql = "
SELECT Doc.id
FROM {$db->tblzz_DocItem} as DocItem
JOIN {$db->tblzz_Doc} as Doc
ON DocItem.id_doc = Doc.id
WHERE DocItem.type = ".$db->quote($itemType, 'text')."
".(($itemName !== null)?"AND DocItem.name = ".$db->quote($itemName, 'text'):'')."
LIMIT 1
";
$id_doc = $db->queryOne($sql);
if (!intval($id_doc)) {
return false;
}
$alias = SiteMap::_getPath2Doc($id_doc);
Session::setData($itemType, ($itemName === null)?'NULL':$itemName, $alias);
return $alias;
}
function _getPath2Doc($id_doc)
{
require_once('class/DB/S_db2.php');
$db = S_db2::getInstance();
$aliasToPage = '';
$sql = "SELECT * FROM {$db->tblzz_Doc} WHERE id = %s";
do {
$docArr = $db->queryRow(sprintf($sql, $db->quote($id_doc, 'integer')));
$aliasToPage = $docArr['alias'].'/'.$aliasToPage;
$id_doc = $docArr['id_parent'];
} while ($docArr['id_parent'] != 0);
return substr($aliasToPage, 0, -1);
}
}
function SMGetPath($path)
{
return SiteMap::getPath($path);
}
function SMGetAliasByItemType($itemType)
{
return SiteMap::getAliasByItemType($itemType);
}
function SMGetAliasByItem($itemType, $itemName = 'Nameless')
{
return SiteMap::getAliasByItem($itemType, $itemName);
}
function define_class($fullFileName, $class_name = NULL)
{
$define = str_replace(realpath(SITEMAP_APP_DIR).'/', '', $fullFileName);
$define = str_replace('.php', '', $define);
$define = str_replace('/', '', $define);
if ($class_name == NULL) {
$class_name = $define;
}
define('cn_'.$define, $class_name);
}
?>