2009-07-16 02:55:19 +00:00
< ? php
/*
2009-08-19 14:39:57 +00:00
* e107 website system
*
* Copyright ( C ) 2001 - 2008 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* e107 Menu Class
*
* $Source : / cvs_backup / e107_0 . 8 / e107_handlers / menu_class . php , v $
2009-09-10 15:24:57 +00:00
* $Revision : 1.14 $
* $Date : 2009 - 09 - 10 15 : 24 : 57 $
2009-09-04 14:35:01 +00:00
* $Author : e107coders $
2009-07-16 02:55:19 +00:00
*/
2009-08-19 14:39:57 +00:00
if ( ! defined ( 'e107_INIT' ))
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
exit ();
2009-08-16 16:30:56 +00:00
}
2009-08-19 14:39:57 +00:00
/**
* Retrieve and render site menus
*
* @ package e107
* @ category e107_handlers
* @ version 1.0
* @ author Cameron
* @ copyright Copyright ( c ) 2009 , e107 Inc .
*
*/
2009-08-16 16:30:56 +00:00
class e_menu
{
2009-08-19 14:39:57 +00:00
/**
* Runtime cached menu data
*
* @ var array
*/
2009-08-16 23:58:33 +00:00
public $eMenuActive = array ();
2009-08-19 14:39:57 +00:00
/**
* Visibility check cache
*
* @ var array
*/
protected $_visibility_cache = array ();
2009-08-16 23:58:33 +00:00
2009-08-19 14:39:57 +00:00
/**
* Constructor
*
*/
2009-08-16 16:30:56 +00:00
function __construct ()
{
}
2009-08-16 23:58:33 +00:00
2009-08-16 16:30:56 +00:00
/**
2009-08-19 14:39:57 +00:00
* Retrieve menus , check visibility against
* current user classes and current page url
*
*/
2009-08-16 16:30:56 +00:00
public function init ()
{
2009-08-19 14:39:57 +00:00
$menu_layout_field = THEME_LAYOUT != e107 :: getPref ( 'sitetheme_deflayout' ) ? THEME_LAYOUT : " " ;
$menu_data = e107 :: getCache () -> retrieve_sys ( " menus_ " . USERCLASS_LIST . " _ " . md5 ( e_LANGUAGE . $menu_layout_field ));
$menu_data = e107 :: getArrayStorage () -> ReadArray ( $menu_data );
2009-08-16 23:58:33 +00:00
$eMenuArea = array ();
// $eMenuList = array();
// $eMenuActive = array(); // DEPRECATED
2009-08-19 14:39:57 +00:00
if ( ! is_array ( $menu_data ))
2009-08-16 16:30:56 +00:00
{
$menu_qry = 'SELECT * FROM #menus WHERE menu_location > 0 AND menu_class IN (' . USERCLASS_LIST . ') AND menu_layout = "' . $menu_layout_field . '" ORDER BY menu_location,menu_order' ;
2009-08-19 14:39:57 +00:00
if ( e107 :: getDb () -> db_Select_gen ( $menu_qry ))
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
while ( $row = e107 :: getDb () -> db_Fetch ())
2009-08-16 16:30:56 +00:00
{
2009-08-16 23:58:33 +00:00
$eMenuArea [ $row [ 'menu_location' ]][] = $row ;
2009-08-16 16:30:56 +00:00
}
}
$menu_data [ 'menu_area' ] = $eMenuArea ;
2009-08-19 14:39:57 +00:00
$menuData = e107 :: getArrayStorage () -> WriteArray ( $menu_data , false );
e107 :: getCache () -> set_sys ( 'menus_' . USERCLASS_LIST . '_' . md5 ( e_LANGUAGE . $menu_layout_field ), $menuData );
2009-08-16 16:30:56 +00:00
}
else
2009-07-16 02:55:19 +00:00
{
2009-08-19 14:39:57 +00:00
$eMenuArea = $menu_data [ 'menu_area' ];
2009-08-16 16:30:56 +00:00
}
2009-08-16 23:58:33 +00:00
$total = array ();
2009-08-19 14:39:57 +00:00
foreach ( $eMenuArea as $area => $val )
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
foreach ( $val as $row )
2009-08-16 23:58:33 +00:00
{
2009-08-19 14:39:57 +00:00
if ( $this -> isVisible ( $row ))
2009-08-16 23:58:33 +00:00
{
2009-08-19 14:39:57 +00:00
$path = str_replace ( " / " , " " , $row [ 'menu_path' ]);
if ( ! isset ( $total [ $area ]))
2009-08-16 23:58:33 +00:00
{
$total [ $area ] = 0 ;
}
$this -> eMenuActive [ $area ][] = $row ;
$total [ $area ] ++ ;
}
}
2009-08-16 16:30:56 +00:00
}
2009-08-19 14:39:57 +00:00
e107 :: getRender () -> eMenuTotal = $total ;
2009-08-16 23:58:33 +00:00
}
2009-08-19 14:39:57 +00:00
/**
* Check visibility of a menu against URL
*
* @ param array $row menu data
* @ return boolean
*/
protected function isVisible ( $row , $url = '' )
2009-08-16 23:58:33 +00:00
{
2009-09-04 14:35:01 +00:00
$iD = varset ( $row [ 'id' ]);
if ( isset ( $this -> _visibility_cache [ $iD ]))
2009-08-19 14:39:57 +00:00
{
2009-09-04 14:35:01 +00:00
return $this -> _visibility_cache [ $iD ];
2009-08-19 14:39:57 +00:00
}
2009-08-16 23:58:33 +00:00
$show_menu = TRUE ;
2009-08-19 14:39:57 +00:00
if ( $row [ 'menu_pages' ])
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
list ( $listtype , $listpages ) = explode ( " - " , $row [ 'menu_pages' ], 2 );
$pagelist = explode ( " | " , $listpages );
$check_url = $url ? $url : e_SELF . ( e_QUERY ? " ? " . e_QUERY : '' );
switch ( $listtype )
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
case '1' : //show menu
2009-08-16 23:58:33 +00:00
$show_menu = false ;
2009-08-19 14:39:57 +00:00
foreach ( $pagelist as $p )
2009-07-16 02:55:19 +00:00
{
2009-08-19 14:39:57 +00:00
if ( substr ( $p , - 1 ) === '!' )
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
$p = substr ( $p , 0 , - 1 );
$show_menu = true ;
2009-08-16 23:58:33 +00:00
break 2 ;
2009-08-16 16:30:56 +00:00
}
2009-08-19 14:39:57 +00:00
elseif ( strpos ( $check_url , $p ) !== false )
2009-07-16 02:55:19 +00:00
{
2009-08-19 14:39:57 +00:00
$show_menu = true ;
2009-08-16 23:58:33 +00:00
break 2 ;
2009-07-16 02:55:19 +00:00
}
}
2009-08-16 23:58:33 +00:00
break ;
2009-08-19 14:39:57 +00:00
case '2' : //hide menu
$show_menu = true ;
foreach ( $pagelist as $p )
2009-08-16 23:58:33 +00:00
{
2009-08-19 14:39:57 +00:00
if ( substr ( $p , - 1 ) == '!' )
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
$p = substr ( $p , 0 , - 1 );
if ( substr ( $check_url , strlen ( $p ) *- 1 ) == $p )
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
$show_menu = false ;
2009-08-16 23:58:33 +00:00
break 2 ;
2009-08-16 16:30:56 +00:00
}
}
2009-08-19 14:39:57 +00:00
elseif ( strpos ( $check_url , $p ) !== false )
2009-08-16 16:30:56 +00:00
{
2009-08-19 14:39:57 +00:00
$show_menu = false ;
2009-08-16 23:58:33 +00:00
break 2 ;
2009-08-16 16:30:56 +00:00
}
}
2009-08-16 23:58:33 +00:00
break ;
} //end switch
} //endif menu_pages
2009-08-19 14:39:57 +00:00
2009-09-04 14:35:01 +00:00
$this -> _visibility_cache [ $iD ] = $show_menu ;
2009-08-16 23:58:33 +00:00
return $show_menu ;
}
2009-08-19 14:39:57 +00:00
/**
* Render menu area
*
* @ param string $parm
* @ return string
*/
2009-08-16 23:58:33 +00:00
public function renderArea ( $parm = '' )
{
2009-08-19 14:39:57 +00:00
global $sql , $ns , $tp , $sc_style ;
2009-08-16 23:58:33 +00:00
global $error_handler ;
2009-08-19 14:39:57 +00:00
$e107 = e107 :: getInstance ();
$tmp = explode ( ':' , $parm );
$buffer_output = true ; // Default - return all output.
if ( isset ( $tmp [ 1 ]) && $tmp [ 1 ] == 'echo' )
2009-08-16 23:58:33 +00:00
{
$buffer_output = false ;
}
2009-08-19 14:39:57 +00:00
if ( ! array_key_exists ( $tmp [ 0 ], $this -> eMenuActive ))
2009-08-16 23:58:33 +00:00
{
return ;
}
2009-08-19 14:39:57 +00:00
if ( $buffer_output )
2009-08-16 23:58:33 +00:00
{
ob_start ();
}
2009-08-19 14:39:57 +00:00
e107 :: getRender () -> eMenuArea = $tmp [ 0 ];
foreach ( $this -> eMenuActive [ $tmp [ 0 ]] as $row )
2009-08-16 23:58:33 +00:00
{
2009-08-19 14:39:57 +00:00
$this -> renderMenu ( $row [ 'menu_path' ], $row [ 'menu_name' ], $row [ 'menu_parms' ]);
2009-08-16 23:58:33 +00:00
}
2009-08-19 14:39:57 +00:00
e107 :: getRender () -> eMenuCount = 0 ;
e107 :: getRender () -> eMenuArea = null ;
if ( $buffer_output )
2009-07-16 02:55:19 +00:00
{
2009-08-16 16:30:56 +00:00
$ret = ob_get_contents ();
ob_end_clean ();
return $ret ;
2009-07-16 02:55:19 +00:00
}
}
2009-08-16 23:58:33 +00:00
2009-08-19 14:39:57 +00:00
/**
* Render menu
*
* @ param string $mpath menu path
* @ param string $mname menu name
* @ param string $parm menu parameters
* @ param boolean $return
* return string if required
*/
public function renderMenu ( $mpath , $mname , $parm = '' , $return = false )
2009-08-16 23:58:33 +00:00
{
global $sql ; // required at the moment.
2009-08-25 08:34:24 +00:00
global $ns , $tp , $sc_style , $e107_debug ;
2009-08-19 14:39:57 +00:00
$e107 = e107 :: getInstance ();
if ( $return )
{
ob_start ();
}
2009-09-06 20:04:04 +00:00
if ( vartrue ( $error_handler -> debug ))
2009-08-16 23:58:33 +00:00
{
echo " \n <!-- Menu Start: " . $mname . " --> \n " ;
}
2009-08-19 14:39:57 +00:00
e107 :: getDB () -> db_Mark_Time ( $mname );
if ( is_numeric ( $mpath ))
2009-08-16 23:58:33 +00:00
{
2009-08-25 08:34:24 +00:00
$sql -> db_Select ( " page " , " * " , " page_id= " . intval ( $mpath ) . " " );
2009-08-16 23:58:33 +00:00
$page = $sql -> db_Fetch ();
2009-08-19 14:39:57 +00:00
$caption = $e107 -> tp -> toHTML ( $page [ 'page_title' ], true , 'parse_sc, constants' );
$text = $e107 -> tp -> toHTML ( $page [ 'page_text' ], true , 'parse_sc, constants' );
e107 :: getRender () -> tablerender ( $caption , $text );
2009-08-16 23:58:33 +00:00
}
else
{
2009-09-10 15:24:57 +00:00
e107 :: loadLanFiles ( $mpath );
2009-08-25 08:34:24 +00:00
//include once is not an option anymore
//e107_include will break many old menus (evel globals), so we'll wait for a while...
//e107_include(e_PLUGIN.$mpath."/".$mname.".php");
$e107_debug ? include ( e_PLUGIN . $mpath . '/' . $mname . '.php' ) : @ include ( e_PLUGIN . $mpath . '/' . $mname . '.php' );
/* if ( file_exists ( e_PLUGIN . $mpath . " / " . $mname . " .php " ))
2009-08-16 23:58:33 +00:00
{
include_once ( e_PLUGIN . $mpath . " / " . $mname . " .php " );
2009-08-25 08:34:24 +00:00
} */
2009-08-16 23:58:33 +00:00
}
2009-08-19 14:39:57 +00:00
e107 :: getDB () -> db_Mark_Time ( " (After " . $mname . " ) " );
if ( $error_handler -> debug == true )
2009-08-16 23:58:33 +00:00
{
echo " \n <!-- Menu End: " . $mname . " --> \n " ;
}
2009-08-19 14:39:57 +00:00
if ( $return )
{
$ret = ob_get_contents ();
ob_end_clean ();
return $ret ;
}
2009-08-16 23:58:33 +00:00
}
}