SHOW:
|
|
- or go back to the newest paste.
| 1 | private function getTemplateMenu($menues=array()){
| |
| 2 | - | //remove comment from next string for testing |
| 2 | + | $cacheLive=86400; //жизнь кеша в секундах (сутки) |
| 3 | - | //unset($_SESSION['_site_cache']['nave_menu']); |
| 3 | + | $useLang=false; |
| 4 | - | $DBC=DBC::getInstance(); |
| 4 | + | $ruAsDef=false; |
| 5 | $useCache=false; //использовать кеш. устанвовить true для использования | |
| 6 | - | require_once(SITEBILL_DOCUMENT_ROOT.'/template/frontend/realia/main/realia_menu_decorator.php'); |
| 6 | + | $refreshCache=false; |
| 7 | - | require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/admin/structure/structure_implements.php'); |
| 7 | + | $cache_file=SITEBILL_DOCUMENT_ROOT.'/cache/cache.tplmenu.txt'; |
| 8 | - | require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/admin/structure/structure_manager.php'); |
| 8 | + | |
| 9 | - | $SM=new Structure_Manager(); |
| 9 | + | if(1===intval($this->getConfigValue('apps.language.use_langs'))){
|
| 10 | - | $structure=$SM->loadCategoryStructure(); |
| 10 | + | $curlang=$this->getCurrentLang(); |
| 11 | $useLang=true; | |
| 12 | - | $DBC=DBC::getInstance(); |
| 12 | + | |
| 13 | if(1===intval($this->getConfigValue('apps.language.use_default_as_ru')) && $curlang=='ru'){
| |
| 14 | - | $add_points=array(); |
| 14 | + | $ruAsDef=true; |
| 15 | - | $additional_menues=array(); |
| 15 | + | |
| 16 | - | $ids=array(); |
| 16 | + | } |
| 17 | - | |
| 17 | + | |
| 18 | - | if(!empty($menues)){
|
| 18 | + | $DBC=DBC::getInstance(); |
| 19 | - | foreach($menues as $m){
|
| 19 | + | |
| 20 | - | if($m['id']==0){
|
| 20 | + | require_once(SITEBILL_DOCUMENT_ROOT.'/template/frontend/realia/main/realia_menu_decorator.php'); |
| 21 | - | $m['href']=$this->getServerFullUrl().'/'; |
| 21 | + | require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/admin/structure/structure_implements.php'); |
| 22 | require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/admin/structure/structure_manager.php'); | |
| 23 | - | if(isset($_SESSION['_site_cache']['nave_menu'][$m['id']])){
|
| 23 | + | $SM=new Structure_Manager(); |
| 24 | - | $add_points[$m['id']]=$_SESSION['_site_cache']['nave_menu'][$m['id']]; |
| 24 | + | $structure=$SM->loadCategoryStructure(); |
| 25 | - | }else{
|
| 25 | + | |
| 26 | - | $ids[]=$m['id']; |
| 26 | + | $DBC=DBC::getInstance(); |
| 27 | ||
| 28 | $add_points=array(); | |
| 29 | - | |
| 29 | + | $additional_menues=array(); |
| 30 | - | |
| 30 | + | $ids=array(); |
| 31 | - | $additional_menues[$m['id']]=$m; |
| 31 | + | |
| 32 | if(!empty($menues)){
| |
| 33 | if($useCache){
| |
| 34 | - | if(!empty($ids)){
|
| 34 | + | if(file_exists($cache_file) && (time()-filemtime($cache_file))<$cacheLive){
|
| 35 | - | $query='SELECT * FROM '.DB_PREFIX.'_menu_structure WHERE menu_id IN ('.implode(',', $ids).') ORDER BY sort_order';
|
| 35 | + | $precached=unserialize(file_get_contents($cache_file)); |
| 36 | - | $stmt=$DBC->query($query); |
| 36 | + | }else{
|
| 37 | - | if($stmt){
|
| 37 | + | $precached=array(); |
| 38 | - | while($ar=$DBC->fetch($stmt)){
|
| 38 | + | $refreshCache=true; |
| 39 | - | $ar['url']=trim($ar['url']); |
| 39 | + | |
| 40 | - | if($ar['url']!='' && 0!==strpos($ar['url'], 'http:')){
|
| 40 | + | |
| 41 | - | $ar['url'] = trim($ar['url'], '/'); |
| 41 | + | foreach($menues as $m){
|
| 42 | if($m['id']==0){
| |
| 43 | - | $add_points[$ar['menu_id']][]=$ar; |
| 43 | + | $m['href']=$this->getServerFullUrl().'/'; |
| 44 | - | $_SESSION['_site_cache']['nave_menu'][$ar['menu_id']]=$add_points[$ar['menu_id']]; |
| 44 | + | }else{
|
| 45 | if(isset($precached[$m['id']])){
| |
| 46 | $add_points[$m['id']]=$precached[$m['id']]; | |
| 47 | }else{
| |
| 48 | $ids[]=$m['id']; | |
| 49 | } | |
| 50 | } | |
| 51 | - | if(!empty($additional_menues)){
|
| 51 | + | $additional_menues[$m['id']]=$m; |
| 52 | - | $behind=array(); |
| 52 | + | |
| 53 | - | $after=array(); |
| 53 | + | |
| 54 | - | foreach ($additional_menues as $k=>$ad_menu){
|
| 54 | + | if(!empty($ids)){
|
| 55 | - | if($ad_menu['position']=='behind'){
|
| 55 | + | $query='SELECT * FROM '.DB_PREFIX.'_menu_structure WHERE menu_id IN ('.implode(',', $ids).') ORDER BY sort_order';
|
| 56 | - | $behind[]=$ad_menu; |
| 56 | + | $stmt=$DBC->query($query); |
| 57 | if($stmt){
| |
| 58 | - | $after[]=$ad_menu; |
| 58 | + | while($ar=$DBC->fetch($stmt)){
|
| 59 | $ar['url']=trim($ar['url']); | |
| 60 | - | |
| 60 | + | |
| 61 | - | |
| 61 | + | if($ar['url']!='' && 0!==strpos($ar['url'], 'http:')){
|
| 62 | $ar['url'] = trim($ar['url'], '/'); | |
| 63 | - | if(!empty($behind)){
|
| 63 | + | |
| 64 | - | $behind=array_reverse($behind); |
| 64 | + | $add_points[$ar['menu_id']][]=$ar; |
| 65 | $precached[$ar['menu_id']]=$add_points[$ar['menu_id']]; | |
| 66 | - | $additional_menues=array_merge($behind, $after); |
| 66 | + | |
| 67 | - | foreach ($additional_menues as $ad_menu){
|
| 67 | + | |
| 68 | - | $k=$ad_menu['id']; |
| 68 | + | if($useCache && $refreshCache){
|
| 69 | - | $indexes=array_keys($structure['catalog']); |
| 69 | + | $f=fopen($cache_file, 'w'); |
| 70 | - | sort($indexes); |
| 70 | + | fwrite($f, serialize($precached)); |
| 71 | - | $last_index=end($indexes)+1; |
| 71 | + | fclose($f); |
| 72 | - | if($ad_menu['position']=='behind'){
|
| 72 | + | |
| 73 | - | array_unshift($structure['childs'][0], $last_index); |
| 73 | + | |
| 74 | } | |
| 75 | - | $structure['childs'][0][]=$last_index; |
| 75 | + | |
| 76 | if(!empty($additional_menues)){
| |
| 77 | - | if(isset($ad_menu['href']) && $ad_menu['href']!=''){
|
| 77 | + | $behind=array(); |
| 78 | - | $href=trim($ad_menu['href'], '/'); |
| 78 | + | $after=array(); |
| 79 | foreach ($additional_menues as $k=>$ad_menu){
| |
| 80 | - | $href='#'; |
| 80 | + | if($ad_menu['position']=='behind'){
|
| 81 | $behind[]=$ad_menu; | |
| 82 | - | $structure['catalog'][$last_index]=array('url'=>$href, 'name'=>$ad_menu['title']);
|
| 82 | + | }else{
|
| 83 | - | |
| 83 | + | $after[]=$ad_menu; |
| 84 | - | if(isset($add_points[$k]) && !empty($add_points[$k])){
|
| 84 | + | |
| 85 | - | $current_index=$last_index+1; |
| 85 | + | |
| 86 | - | foreach ($add_points[$k] as $ad_point){
|
| 86 | + | if(!empty($behind)){
|
| 87 | - | $structure['catalog'][$current_index]=array('url'=>$ad_point['url'], 'name'=>$ad_point['name']);
|
| 87 | + | $behind=array_reverse($behind); |
| 88 | - | $structure['childs'][$last_index][]=$current_index; |
| 88 | + | |
| 89 | - | $current_index++; |
| 89 | + | $additional_menues=array_merge($behind, $after); |
| 90 | foreach ($additional_menues as $ad_menu){
| |
| 91 | $k=$ad_menu['id']; | |
| 92 | $indexes=array_keys($structure['catalog']); | |
| 93 | sort($indexes); | |
| 94 | $last_index=end($indexes)+1; | |
| 95 | if($ad_menu['position']=='behind'){
| |
| 96 | - | return Realia_Menu_Decorator::getMenu($structure); |
| 96 | + | array_unshift($structure['childs'][0], $last_index); |
| 97 | }else{
| |
| 98 | - | } |
| 98 | + | $structure['childs'][0][]=$last_index; |
| 99 | } | |
| 100 | if(isset($ad_menu['href']) && $ad_menu['href']!=''){
| |
| 101 | $href=trim($ad_menu['href'], '/'); | |
| 102 | }else{
| |
| 103 | $href='#'; | |
| 104 | } | |
| 105 | ||
| 106 | $structure['catalog'][$last_index]=array('url'=>$href, 'name'=>$ad_menu['title']);
| |
| 107 | ||
| 108 | if(isset($add_points[$k]) && !empty($add_points[$k])){
| |
| 109 | $current_index=$last_index+1; | |
| 110 | foreach ($add_points[$k] as $ad_point){
| |
| 111 | $ad_point_title=$ad_point['name']; | |
| 112 | if($useLang){
| |
| 113 | if($ruAsDef){
| |
| 114 | ||
| 115 | }else{
| |
| 116 | if($ad_point['name_'.$curlang]!=''){
| |
| 117 | $ad_point_title=$ad_point['name_'.$curlang]; | |
| 118 | } | |
| 119 | } | |
| 120 | } | |
| 121 | $structure['catalog'][$current_index]=array('url'=>$ad_point['url'], 'name'=>$ad_point_title);
| |
| 122 | $structure['childs'][$last_index][]=$current_index; | |
| 123 | $current_index++; | |
| 124 | } | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | } | |
| 129 | ||
| 130 | return Realia_Menu_Decorator::getMenu($structure); | |
| 131 | ||
| 132 | } |