2009-07-16 02:55:19 +00:00
< ? php
/*
2009-08-19 14:39:57 +00:00
* e107 website system
*
2013-03-24 18:59:18 +01:00
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
2009-08-19 14:39:57 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* e107 Menu Class
*
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
2010-01-12 12:23:02 +00:00
*
2009-08-19 14:39:57 +00:00
* @ 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 ();
2010-01-12 12:23:02 +00:00
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
2017-02-09 11:24:54 -08:00
/**
* @ var null
*/
2016-02-10 19:51:32 -08:00
protected $_current_menu = null ;
2017-02-09 11:24:54 -08:00
/**
* @ var array
*/
2016-02-10 19:51:32 -08:00
protected $_current_parms = array ();
2017-02-09 11:24:54 -08:00
/**
2017-02-09 12:04:39 -08:00
* Params of all active menus .
2017-02-09 11:24:54 -08:00
* @ var array
*/
protected $_menu_parms = array ();
2009-08-19 14:39:57 +00:00
/**
* Constructor
*
*/
2020-12-14 16:21:48 -08:00
public function __construct ()
2009-08-16 16:30:56 +00:00
{
}
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-12-27 10:52:22 +00:00
global $_E107 ;
2010-01-12 12:23:02 +00:00
2020-12-20 11:50:10 -08:00
if ( ! empty ( $_E107 [ 'cli' ]))
2009-12-27 10:52:22 +00:00
{
return ;
}
2012-11-15 21:50:49 +00:00
2013-05-10 02:46:09 -07:00
// print_a($eMenuArea);
2020-12-14 16:21:48 -08:00
if ( varset ( $_SERVER [ 'E_DEV_MENU' ]) === 'true' ) // New in v2.x Experimental
2009-07-16 02:55:19 +00:00
{
2013-05-10 02:46:09 -07:00
$layouts = e107 :: getPref ( 'menu_layouts' );
if ( ! is_array ( $layouts ))
{
$converted = $this -> convertMenuTable ();
2020-12-14 16:21:48 -08:00
e107 :: getConfig () -> set ( 'menu_layouts' , $converted ) -> save ();
2013-05-10 02:46:09 -07:00
}
$eMenuArea = $this -> getData ( THEME_LAYOUT );
2013-05-20 17:09:58 -07:00
//print_a($eMenuArea);
2009-08-16 16:30:56 +00:00
}
2015-08-24 17:39:28 -07:00
else // standard DB 'table' method.
2013-05-10 02:46:09 -07:00
{
$eMenuArea = $this -> getDataLegacy ();
}
2013-05-20 17:09:58 -07:00
2013-05-09 20:16:39 -07: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 ;
2017-02-09 11:24:54 -08:00
if ( ! empty ( $row [ 'menu_parms' ]))
{
$key = $row [ 'menu_name' ];
$this -> _menu_parms [ $area ][ $key ][] = $row [ 'menu_parms' ];
}
2009-08-16 23:58:33 +00:00
$total [ $area ] ++ ;
}
}
2009-08-16 16:30:56 +00:00
}
2013-05-09 20:16:39 -07:00
2009-08-19 14:39:57 +00:00
e107 :: getRender () -> eMenuTotal = $total ;
2009-08-16 23:58:33 +00:00
}
2013-05-09 22:24:23 -07:00
/**
* Convert from v1 . x e107_menu table to v2 . x $pref format .
*/
function convertMenuTable ()
{
$sql = e107 :: getDb ();
$sql -> select ( 'menus' , '*' , 'menu_location !=0 ORDER BY menu_location,menu_order' );
$data = array ();
while ( $row = $sql -> fetch ())
{
$layout = vartrue ( $row [ 'menu_layout' ], 'default' );
$location = $row [ 'menu_location' ];
2020-12-14 16:21:48 -08:00
$data [ $layout ][ $location ][] = array ( 'name' => $row [ 'menu_name' ], 'class' => ( int ) $row [ 'menu_class' ], 'path' => $row [ 'menu_path' ], 'pages' => $row [ 'menu_pages' ], 'parms' => $row [ 'menu_parms' ]);
2013-05-09 22:24:23 -07:00
}
return $data ;
2016-02-10 19:51:32 -08:00
}
/**
* Return the preferences / parms for the current menu .
* @ return array
*/
public function pref ()
{
2016-12-16 10:53:59 -08:00
return ( empty ( $this -> _current_parms )) ? array () : $this -> _current_parms ;
2016-02-10 19:51:32 -08:00
}
2013-05-09 20:16:39 -07:00
2017-02-09 11:24:54 -08:00
/**
* Return the parameters of an active Menu .
* @ param string $menuName
* @ param int $area
* @ example $parms = $tmp -> getParams ( 'news_months_menu' , 1 );
* @ return array | bool
*/
public function getParams ( $menuName , $area )
{
if ( empty ( $area ) || empty ( $menuName ))
{
return false ;
}
if ( ! empty ( $this -> _menu_parms [ $area ][ $menuName ]))
{
$arr = array ();
foreach ( $this -> _menu_parms [ $area ][ $menuName ] as $val )
{
$arr [] = e107 :: unserialize ( $val );
}
return $arr ;
}
return false ;
}
2013-05-09 20:16:39 -07:00
/**
2016-02-08 13:54:44 -08:00
* Experimental V2 Menu Re - Write - retrieve Menu data from $pref [ 'menu_layouts' ]
2013-05-09 20:16:39 -07:00
*/
protected function getData ( $layout )
{
2013-05-20 17:09:58 -07:00
$mpref = e107 :: getPref ( 'menu_layouts' );
2013-05-10 04:38:04 -07:00
2013-05-20 17:09:58 -07:00
if ( ! varset ( $mpref [ $layout ]))
2013-05-10 04:38:04 -07:00
{
return array ();
}
2020-12-14 16:21:48 -08:00
$ret = array ();
2013-05-10 04:38:04 -07:00
2013-05-20 17:09:58 -07:00
foreach ( $mpref [ $layout ] as $area => $v )
2013-05-09 20:16:39 -07:00
{
2013-05-09 22:24:23 -07:00
$c = 1 ;
2013-05-20 17:09:58 -07:00
2013-05-09 20:16:39 -07:00
foreach ( $v as $val )
{
2020-12-14 16:21:48 -08:00
$class = ( int ) $val [ 'class' ];
2013-05-09 20:16:39 -07:00
if ( ! check_class ( $class ))
{
continue ;
}
$ret [ $area ][] = array (
2013-05-09 22:24:23 -07:00
'menu_id' => $c ,
2013-05-09 20:16:39 -07:00
'menu_name' => $val [ 'name' ],
'menu_location' => $area ,
'menu_class' => $class ,
'menu_order' => $c ,
'menu_pages' => $val [ 'pages' ],
'menu_path' => $val [ 'path' ],
'menu_layout' => '' ,
'menu_parms' => $val [ 'parms' ]
);
2013-05-20 17:09:58 -07:00
2013-05-09 20:16:39 -07:00
$c ++ ;
}
}
2013-05-20 17:09:58 -07:00
// print_a($ret);
2013-05-09 20:16:39 -07:00
return $ret ;
}
2016-02-10 19:51:32 -08:00
/**
* Set Parms for a specific menu .
* @ param string $plugin ie . plugin folder name .
* @ param string $menu menu name . including the _menu but not the . php
* @ param array $parms
* @ param string | int $location default 'all' or a menu area number ..
2021-12-03 14:58:33 -08:00
* @ return int number of records updated or false .
2016-02-10 19:51:32 -08:00
*/
public function setParms ( $plugin , $menu , $parms = array (), $location = 'all' )
{
$qry = 'menu_parms="' . e107 :: serialize ( $parms ) . '" WHERE menu_parms="" AND menu_path="' . $plugin . '/" AND menu_name="' . $menu . '" ' ;
2020-12-14 16:21:48 -08:00
$qry .= ( $location !== 'all' ) ? 'menu_location=' . ( int ) $location : '' ;
2016-02-10 19:51:32 -08:00
return e107 :: getDb () -> update ( 'menus' , $qry );
}
2013-05-09 20:16:39 -07:00
2017-01-26 15:37:42 -08:00
2017-03-02 09:39:50 -08:00
/**
* @ param int $id menu_id
* @ param array $parms
* @ return mixed
*/
public function updateParms ( $id , $parms )
{
$model = e107 :: getModel ();
$model -> setModelTable ( " menus " );
$model -> setFieldIdName ( " menu_id " );
$model -> setDataFields ( array ( 'menu_parms' => 'json' ));
2023-03-18 12:31:23 -07:00
2017-03-02 09:39:50 -08:00
$model -> load ( $id , true );
$d = $model -> get ( 'menu_parms' );
$model -> setPostedData ( 'menu_parms' , e107 :: unserialize ( $d ));
foreach ( $parms as $key => $value )
{
if ( ! is_array ( $value ))
{
$model -> setPostedData ( 'menu_parms/' . $key , $value );
}
else
{
2023-03-18 12:31:23 -07:00
foreach ( $value as $lang => $val )
{
$model -> setPostedData ( 'menu_parms/' . $key . '/' . $lang , $val );
}
2017-03-02 09:39:50 -08:00
}
}
2023-03-18 12:31:23 -07:00
// file_put_contents(e_LOG."menuParmsAjax.log", print_r($parms,true));
2017-03-02 09:39:50 -08:00
return $model -> save ();
// return $model;
}
2017-01-26 15:37:42 -08:00
/**
* Add a Menu to the Menu Table .
* @ param string $plugin folder name
* @ param string $menufile name without the . php
* @ return bool | int
*/
public function add ( $plugin , $menufile )
{
$sql = e107 :: getDb ();
if ( empty ( $plugin ) || empty ( $menufile ))
{
return false ;
}
if ( $sql -> select ( 'menus' , 'menu_id' , 'menu_path="' . $plugin . '/" AND menu_name="' . $menufile . '" LIMIT 1' ))
{
return false ;
}
$insert = array (
'menu_id' => 0 ,
'menu_name' => $menufile ,
'menu_location' => 0 ,
'menu_order' => 0 ,
'menu_class' => 0 ,
'menu_pages' => 0 ,
'menu_path' => $plugin . " / " ,
'menu_layout' => '' ,
'menu_parms' => ''
);
return $sql -> insert ( 'menus' , $insert );
}
/**
* Remove a menu from the Menu table .
* @ param string $plugin folder name
* @ param string $menufile
* @ return int
*/
public function remove ( $plugin , $menufile = null )
{
$qry = 'menu_path="' . $plugin . '/" ' ;
if ( ! empty ( $menufile ))
{
$qry .= ' AND menu_name="' . $menufile . '" ' ;
}
return e107 :: getDb () -> delete ( 'menus' , $qry );
}
2013-05-09 22:24:23 -07:00
/**
2016-02-08 13:54:44 -08:00
* Function to retrieve Menu data from tables .
2013-05-09 22:24:23 -07:00
*/
private function getDataLegacy ()
{
$sql = e107 :: getDb ();
2021-01-01 14:05:51 -08:00
$menu_layout_field = THEME_LAYOUT != e107 :: getPref ( 'sitetheme_deflayout' ) ? THEME_LAYOUT : " " ;
2013-05-09 22:24:23 -07:00
// e107::getCache()->CachePageMD5 = md5(e_LANGUAGE.$menu_layout_field); // Disabled by line 93 of Cache class.
2016-11-18 14:40:53 -08:00
//FIXME add a function to the cache class for this.
2021-01-01 14:05:51 -08:00
if ( ! defined ( 'PREVIEWTHEME' ))
{
$cacheData = e107 :: getCache () -> retrieve_sys ( " menus_ " . USERCLASS_LIST . " _ " . md5 ( e_LANGUAGE . $menu_layout_field ));
$menu_data = e107 :: unserialize ( $cacheData );
}
2016-11-18 14:40:53 -08:00
2013-05-09 22:24:23 -07:00
$eMenuArea = array ();
// $eMenuList = array();
// $eMenuActive = array(); // DEPRECATED
2016-11-18 14:40:53 -08:00
if ( empty ( $menu_data ) || ! is_array ( $menu_data ))
2013-05-09 22:24:23 -07:00
{
2021-01-01 14:05:51 -08:00
$menu_qry = 'SELECT * FROM #menus WHERE menu_location > 0 AND menu_class IN (' . USERCLASS_LIST . ') ' ;
$menu_qry .= ! defined ( 'PREVIEWTHEME' ) ? 'AND menu_layout = "' . $menu_layout_field . '" ' : '' ;
$menu_qry .= 'ORDER BY menu_location,menu_order' ;
2013-05-09 22:24:23 -07:00
if ( $sql -> gen ( $menu_qry ))
{
while ( $row = $sql -> fetch ())
{
$eMenuArea [ $row [ 'menu_location' ]][] = $row ;
}
}
$menu_data [ 'menu_area' ] = $eMenuArea ;
2016-11-18 14:40:53 -08:00
$menuData = e107 :: serialize ( $menu_data , 'json' );
2013-05-09 22:24:23 -07:00
e107 :: getCache () -> set_sys ( 'menus_' . USERCLASS_LIST . '_' . md5 ( e_LANGUAGE . $menu_layout_field ), $menuData );
}
else
{
$eMenuArea = $menu_data [ 'menu_area' ];
}
return $eMenuArea ;
}
2013-05-09 20:16:39 -07:00
2014-01-30 10:14:13 -08:00
/**
* Returns true if a menu is currently active .
* @ param string $menuname ( without the '_menu.php' )
*/
2020-12-14 16:21:48 -08:00
public function isLoaded ( $menuname )
2014-01-30 10:14:13 -08:00
{
if ( empty ( $menuname ))
{
return false ;
}
foreach ( $this -> eMenuActive as $area )
{
foreach ( $area as $menu )
{
if ( $menu [ 'menu_name' ] == $menuname . " _menu " )
{
return true ;
}
}
}
return false ;
}
2013-05-09 20:16:39 -07:00
2022-04-04 10:54:24 -07:00
/**
* @ return bool
*/
2016-04-15 14:09:48 -07:00
protected function isFrontPage ()
{
2020-12-14 16:21:48 -08:00
return e_REQUEST_SELF == SITEURL ;
2016-04-15 14:09:48 -07:00
}
2013-05-09 20:16:39 -07:00
2009-08-19 14:39:57 +00:00
/**
* Check visibility of a menu against URL
2010-01-12 12:23:02 +00:00
*
2009-08-19 14:39:57 +00:00
* @ param array $row menu data
* @ return boolean
*/
protected function isVisible ( $row , $url = '' )
2009-08-16 23:58:33 +00:00
{
2010-01-12 12:23:02 +00:00
$iD = varset ( $row [ 'menu_id' ]);
2009-09-04 14:35:01 +00:00
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
}
2010-01-12 12:23:02 +00:00
2009-08-16 23:58:33 +00:00
$show_menu = TRUE ;
2010-01-12 12:23:02 +00:00
$tp = e107 :: getParser ();
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 );
2010-01-12 12:23:02 +00:00
// TODO - check against REQUEST_URI, see what would get broken
$check_url = $url ? $url : ( $_SERVER [ 'REQUEST_URI' ] ? SITEURLBASE . $_SERVER [ 'REQUEST_URI' ] : e_SELF . ( e_QUERY ? " ? " . e_QUERY : '' ));
2009-08-19 14:39:57 +00:00
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 ;
2010-01-12 12:23:02 +00:00
2009-08-19 14:39:57 +00:00
foreach ( $pagelist as $p )
2009-07-16 02:55:19 +00:00
{
2020-12-14 16:21:48 -08:00
if ( $p === 'FRONTPAGE' && $this -> isFrontPage ())
2016-04-15 14:09:48 -07:00
{
$show_menu = true ;
break ;
}
2010-01-12 12:23:02 +00:00
$p = $tp -> replaceConstants ( $p , 'full' );
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 );
2010-01-12 12:23:02 +00:00
if ( substr ( $check_url , strlen ( $p ) *- 1 ) == $p )
{
$show_menu = true ;
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
{
2020-12-14 16:21:48 -08:00
if ( $p === 'FRONTPAGE' && $this -> isFrontPage ())
2016-04-15 14:09:48 -07:00
{
$show_menu = false ;
break ;
}
2010-01-12 12:23:02 +00:00
$p = $tp -> replaceConstants ( $p , 'full' );
2020-12-14 16:21:48 -08: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 );
2010-01-12 12:23:02 +00:00
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
2010-01-12 12:23:02 +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 ;
2012-12-03 04:51:27 -08:00
2009-08-19 14:39:57 +00:00
$e107 = e107 :: getInstance ();
2010-01-12 12:23:02 +00:00
2009-08-19 14:39:57 +00:00
$tmp = explode ( ':' , $parm );
2012-12-03 04:51:27 -08:00
$buffer_output = ( E107_DBG_INCLUDES ) ? false : true ; // Turn off when trouble-shooting includes. Default - return all output.
2013-03-08 20:27:12 -08:00
2020-12-14 16:21:48 -08:00
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 ();
}
2013-03-08 20:27:12 -08:00
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
{
2020-12-14 16:21:48 -08:00
return ob_get_clean ();
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
*/
2013-03-08 20:27:12 -08:00
public function renderMenu ( $mpath , $mname = '' , $parm = '' , $return = false )
2009-08-16 23:58:33 +00:00
{
2013-03-08 20:27:12 -08:00
// global $sql; // required at the moment.
2017-01-18 19:56:27 -08:00
2020-04-26 13:32:18 -07:00
global $sc_style ;
2013-03-24 18:59:18 +01:00
2016-02-10 19:51:32 -08:00
2017-12-11 17:11:22 -08:00
$sql = e107 :: getDb ();
$ns = e107 :: getRender ();
$tp = e107 :: getParser ();
$e107cache = e107 :: getCache (); // Often used by legacy menus.
2016-02-08 13:54:44 -08:00
if ( $tmp = e107 :: unserialize ( $parm )) // support e_menu.php e107 serialized parm.
{
$parm = $tmp ;
unset ( $tmp );
}
2010-01-12 12:23:02 +00:00
2016-02-10 19:51:32 -08:00
$this -> _current_parms = $parm ;
$this -> _current_menu = $mname ;
2009-08-19 14:39:57 +00:00
if ( $return )
{
ob_start ();
}
2010-01-12 12:23:02 +00:00
2016-02-08 13:54:44 -08:00
if ( e_DEBUG === true )
2009-08-16 23:58:33 +00:00
{
echo " \n <!-- Menu Start: " . $mname . " --> \n " ;
}
2020-05-02 15:35:30 -07:00
e107 :: getDebug () -> logTime ( $mname );
2013-03-06 23:01:16 -08:00
2013-03-08 20:27:12 -08:00
if ( is_numeric ( $mpath ) || ( $mname === false )) // Custom Page/Menu
2009-08-16 23:58:33 +00:00
{
2020-12-14 16:21:48 -08:00
$query = ( $mname === false ) ? " menu_name = ' " . $mpath . " ' " : " page_id= " . ( int ) $mpath . " " ; // load by ID or load by menu-name (menu_name)
2013-03-08 20:27:12 -08:00
$sql -> select ( " page " , " * " , $query );
2013-03-06 23:01:16 -08:00
$page = $sql -> fetch ();
2014-06-28 00:08:35 -07:00
if ( ! empty ( $page [ 'menu_class' ]) && ! check_class ( $page [ 'menu_class' ]))
{
echo " \n <!-- Menu not rendered due to userclass settings --> \n " ;
2020-04-26 13:32:18 -07:00
return null ;
2014-06-28 00:08:35 -07:00
}
2014-01-08 04:29:00 -08:00
$caption = ( vartrue ( $page [ 'menu_icon' ])) ? $tp -> toIcon ( $page [ 'menu_icon' ]) : '' ;
$caption .= $tp -> toHTML ( $page [ 'menu_title' ], true , 'parse_sc, constants' );
2013-03-06 23:01:16 -08:00
2020-12-20 11:50:10 -08:00
if ( ! empty ( $page [ 'menu_template' ])) // New v2.x templates. see core/menu_template.php
2013-03-06 23:01:16 -08:00
{
2014-06-14 19:10:16 -07:00
$template = e107 :: getCoreTemplate ( 'menu' , $page [ 'menu_template' ], true , true ); // override and merge required. ie. when menu template is not in the theme, but only in the core.
2013-03-06 23:01:16 -08:00
$page_shortcodes = e107 :: getScBatch ( 'page' , null , 'cpage' );
2022-09-11 17:36:47 +02:00
$page_shortcodes -> setVars ( $page ) -> wrapper ( 'menu/' . $page [ 'menu_template' ] );
2013-03-06 23:01:16 -08:00
2016-03-10 17:32:36 -08:00
$head = $tp -> parseTemplate ( $template [ 'start' ], true , $page_shortcodes );
$foot = $tp -> parseTemplate ( $template [ 'end' ], true , $page_shortcodes );
2014-01-07 08:18:27 -08:00
2013-03-06 23:01:16 -08:00
// print_a($template['body']);
2016-03-10 17:32:36 -08:00
$text = $head . $tp -> parseTemplate ( $template [ 'body' ], true , $page_shortcodes ) . $foot ;
2013-03-06 23:01:16 -08:00
// echo "TEMPLATE= ($mpath)".$page['menu_template'];
2016-12-28 18:37:05 -08:00
$ns -> setUniqueId ( 'cmenu-' . $page [ 'menu_name' ]);
2020-12-14 16:21:48 -08:00
$caption .= e107 :: getForm () -> instantEditButton ( e_ADMIN_ABS . " cpage.php?mode=menu&action=edit&tab=2&id= " . ( int ) $page [ 'page_id' ], 'J' );
2016-12-28 18:37:05 -08:00
$ns -> tablerender ( $caption , $text , 'cmenu-' . $page [ 'menu_template' ]);
2013-03-06 23:01:16 -08:00
}
else
2013-03-24 18:59:18 +01:00
{
$text = $tp -> toHTML ( $page [ 'menu_text' ], true , 'parse_sc, constants' );
2016-11-08 19:01:26 -08:00
$ns -> setUniqueId ( 'cmenu-' . $page [ 'menu_name' ]);
2016-12-28 18:37:05 -08:00
2013-04-14 17:08:38 -07:00
$ns -> tablerender ( $caption , $text , 'cmenu' );
2013-03-06 23:01:16 -08:00
}
2009-08-16 23:58:33 +00:00
}
else
{
2012-05-04 15:00:33 +00:00
// not sure what would break this, but it's good idea to go away
2012-05-14 21:02:08 +00:00
e107 :: loadLanFiles ( $mpath );
2012-05-04 15:00:33 +00:00
2009-08-25 08:34:24 +00:00
//include once is not an option anymore
2012-05-04 15:00:33 +00:00
//e107_include will break many old menus (evil globals), so we'll wait for a while...
2009-08-25 08:34:24 +00:00
//e107_include(e_PLUGIN.$mpath."/".$mname.".php");
2012-05-04 15:00:33 +00:00
//if(substr($mpath,-1)!='/')
//{
// $mpath .= '/';
//}
2016-11-09 12:44:03 +01:00
2012-05-04 15:00:33 +00:00
$mpath = trim ( $mpath , '/' ) . '/' ; // faster...
2016-11-09 12:44:03 +01:00
$id = e107 :: getForm () -> name2id ( $mpath . $mname );
$ns -> setUniqueId ( $id );
2017-01-18 19:56:27 -08:00
$pref = e107 :: getPref (); // possibly used by plugin menu.
2017-01-02 14:08:34 -08:00
2020-04-26 13:32:18 -07:00
deftrue ( 'e_DEBUG' ) ? include ( e_PLUGIN . $mpath . $mname . '.php' ) : @ include ( e_PLUGIN . $mpath . $mname . '.php' );
2009-08-16 23:58:33 +00:00
}
2020-05-02 15:35:30 -07:00
e107 :: getDebug () -> logTime ( " (After " . $mname . " ) " );
2016-02-12 12:58:44 -08:00
if ( e_DEBUG === true )
2009-08-16 23:58:33 +00:00
{
echo " \n <!-- Menu End: " . $mname . " --> \n " ;
}
2010-01-12 12:23:02 +00:00
2009-08-19 14:39:57 +00:00
if ( $return )
{
2020-12-14 16:21:48 -08:00
return ob_get_clean ();
2009-08-19 14:39:57 +00:00
}
2020-04-26 13:32:18 -07:00
unset ( $pref );
return null ;
2009-08-16 23:58:33 +00:00
}
}