Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * PureCSS menu class
- * @author Kondin Dmitriy <kondin@etown.ru> http://www.sitebill.ru
- */
- class PureCSS_Menu extends Structure_Manager {
- /**
- * Constructor
- */
- function __construct() {
- $this->SiteBill();
- }
- /**
- * Get menu
- * @param
- * @return
- */
- function get_menu ($menues=array()) {
- $DBC=DBC::getInstance();
- $structure=$this->loadCategoryStructure();
- $add_points=array();
- $additional_menues=array();
- $ids==array();
- if(!empty($menues)){
- foreach($menues as $m){
- if($m['id']==0){
- $m['href']='http://'.$_SERVER['HTTP_HOST'].'/'.SITEBILL_MAIN_URL.'/';
- }else{
- if(isset($_SESSION['_site_cache']['nave_menu'][$m['id']])){
- $add_points[$m['id']]=$_SESSION['_site_cache']['nave_menu'][$m['id']];
- }else{
- $ids[]=$m['id'];
- }
- }
- $additional_menues[$m['id']]=$m;
- }
- if(!empty($ids)){
- $query='SELECT * FROM '.DB_PREFIX.'_menu_structure WHERE menu_id IN ('.implode(',', $ids).') ORDER BY sort_order';
- $stmt=$DBC->query($query);
- if($stmt){
- while($ar=$DBC->fetch($stmt)){
- $ar['url']=trim($ar['url']);
- if($ar['url']!='' && 0!==strpos($ar['url'], 'http:')){
- $ar['url'] = trim($ar['url'], '/');
- }
- $add_points[$ar['menu_id']][]=$ar;
- $_SESSION['_site_cache']['nave_menu'][$ar['menu_id']]=$add_points[$ar['menu_id']];
- }
- }
- }
- }
- if(!empty($additional_menues)){
- $behind=array();
- $after=array();
- foreach ($additional_menues as $k=>$ad_menu){
- if($ad_menu['position']=='behind'){
- $behind[]=$ad_menu;
- }else{
- $after[]=$ad_menu;
- }
- }
- if(!empty($behind)){
- $behind=array_reverse($behind);
- }
- $additional_menues=array_merge($behind, $after);
- foreach ($additional_menues as $ad_menu){
- $k=$ad_menu['id'];
- $indexes=array_keys($structure['catalog']);
- sort($indexes);
- $last_index=end($indexes)+1;
- if($ad_menu['position']=='behind'){
- array_unshift($structure['childs'][0], $last_index);
- }else{
- $structure['childs'][0][]=$last_index;
- }
- if(isset($ad_menu['href']) && $ad_menu['href']!=''){
- $href=trim($ad_menu['href'], '/');
- }else{
- $href='#';
- }
- $structure['catalog'][$last_index]=array('url'=>$href, 'name'=>$ad_menu['title']);
- if(isset($add_points[$k]) && !empty($add_points[$k])){
- $current_index=$last_index+1;
- foreach ($add_points[$k] as $ad_point){
- $structure['catalog'][$current_index]=array('url'=>$ad_point['url'], 'name'=>$ad_point['name']);
- $structure['childs'][$last_index][]=$current_index;
- $current_index++;
- }
- }
- }
- }
- //return Realty_Menu_Decorator::getMenu($structure);
- $category_structure = $structure;
- $level = 1;
- $rs = '<ul class="nav navbar-nav">';
- foreach ( $category_structure['childs'][0] as $item_id => $categoryID ) {
- if ( isset($category_structure['childs'][$categoryID]) && count($category_structure['childs'][$categoryID]) > 0 ) {
- $name = '<span>'.$category_structure['catalog'][$categoryID]['name'].'</span>';
- } else {
- $name = '<span>'.$category_structure['catalog'][$categoryID]['name'].'</span>';
- }
- if($category_structure['catalog'][$categoryID]['url']!=''){
- if ( preg_match('/^http/', $category_structure['catalog'][$categoryID]['url']) ) {
- $rs .= '<li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown'.($category_structure['catalog'][$categoryID]['current']==1 ? ' current' : '').'" href="'.$category_structure['catalog'][$categoryID]['url'].'">'.$name.'<span class="caret"></span></a>';
- } else {
- $rs .= '<li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown'.($category_structure['catalog'][$categoryID]['current']==1 ? ' current' : '').'" href="'.SITEBILL_MAIN_URL.'/'.$category_structure['catalog'][$categoryID]['url'].'">'.$name.'<span class="caret"></span></a>';
- }
- }else{
- $rs .= '<li class="dropdown active"><a class="dropdown-toggle" data-toggle="dropdown'.($category_structure['catalog'][$categoryID]['current']==1 ? ' current' : '').'" href="'.SITEBILL_MAIN_URL.'/topic'.$categoryID.'.html">'.$name.'<span class="caret"></span></a>';
- }
- $rs .= $this->getChildNodes($categoryID, $category_structure, $level + 1, $current_category_id=0);
- $rs .= '</li>';
- }
- $rs .= '</ul>';
- return $rs;
- }
- /**
- * Get child nodes
- * @param $categoryID
- * @param $category_structure
- * @param $level
- * @param $current_category_id
- */
- function getChildNodes($categoryID, $category_structure, $level, $current_category_id) {
- $rs='';
- if ( !is_array($category_structure['childs'][$categoryID]) ) {
- return '';
- }
- $rs .= '<ul class="dropdown-menu">';
- foreach ( $category_structure['childs'][$categoryID] as $child_id ) {
- if ( !empty($category_structure['childs'][$child_id]) AND count($category_structure['childs'][$child_id]) > 0 ) {
- $name = '<span>'.$category_structure['catalog'][$child_id]['name'].'</span>';
- } else {
- $name = $category_structure['catalog'][$child_id]['name'];
- }
- if($category_structure['catalog'][$child_id]['url']!=''){
- $rs .= '<li><a '.($category_structure['catalog'][$child_id]['current']==1 ? ' current' : '').'" href="'.SITEBILL_MAIN_URL.'/'.$category_structure['catalog'][$child_id]['url'].'">'.$name.'</a>';
- }else{
- $rs .= '<li><a '.($category_structure['catalog'][$child_id]['current']==1 ? ' current' : '').'" href="'.SITEBILL_MAIN_URL.'/topic'.$child_id.'.html">'.$name.'</a>';
- }
- if ( !empty($category_structure['childs'][$child_id]) AND count($category_structure['childs'][$child_id]) > 0 ) {
- $rs .= $this->getChildNodes($child_id, $category_structure, $level + 1, $current_category_id);
- }
- $rs .= '</li>';
- }
- $rs .= '</ul>';
- return $rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement