LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.easymultilang_menu.php
Go to the documentation of this file.
1<?php
2
19// include secure.php to protect this file and the whole CMS!
20if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
21if (defined('LEPTON_PATH')) {
22 include LEPTON_PATH.SEC_FILE;
23} else {
24 $oneback = "../";
25 $root = $oneback;
26 $level = 1;
27 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
28 $root .= $oneback;
29 $level += 1;
30 }
31 if (file_exists($root.SEC_FILE)) {
32 include $root.SEC_FILE;
33 } else {
34 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
35 }
36}
37// end include secure file
38
39
49function easymultilang_menu($list = false )
50{
52
53 $langarr = [];
54 $classarr = [];
55
56 $aPage = [];
57 $sTempQuery = (defined("PAGE_ID"))
58 ? "SELECT * FROM ".TABLE_PREFIX."pages WHERE `page_id` = ". PAGE_ID." "
59 : "SELECT * FROM ".TABLE_PREFIX."pages WHERE `page_code` = 'home' "
60 ;
61
62 $database->execute_query(
63 $sTempQuery,
64 true,
65 $aPage,
66 false
67 );
68
69 if (!empty($aPage))
70 {
71 $lang = $aPage[ "language" ];
72 $code = $aPage[ "page_code" ];
73 $langarr[ $lang ] = "";
74 $classarr[ $lang ] = "easymultilang_current";
75 }
76 elseif ( isset( $_SESSION[ 'LANGUAGE' ] ) && strlen( $_SESSION[ 'LANGUAGE' ] ) == 2 )
77 {
78 $lang = "";
79 $code = "home";
80 }
81 else
82 {
83 // L* 5.3 :: this ist not really clear!
84 $lang = ""; // dummy language for search page
85 $code = "home";
86 }
87
88 // in some cases (for instance multi page form) we do not want a language menu at all
89 // with page_code: 'none' we switch the language menu off
90 if ( $code == "none" )
91 {
92 return false;
93 }
94
95 // 1. call home --> all languages
96 $aPageHome = [];
97 $database->execute_query(
98 "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_code = 'home' and language = '".$lang."' ",
99 true,
100 $aPageHome,
101 true
102 );
103
104 if (!empty($aPageHome))
105 {
106 foreach ($aPageHome as $cp)
107 {
108 $l = $cp[ "language" ];
109 $langarr[ $l ] = $cp[ "link" ];
110 if($classarr[ $l ] != "easymultilang_current")
111 {
112 $classarr[ $l ] = "easymultilang";
113 }
114 }
115 }
116 // 2. call current page and replace result
117 $aCurrentPage = [];
118 $database->execute_query(
119 "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_code = '".$code."' and language != '".$lang."' AND visibility != 'none' ",
120 true,
121 $aCurrentPage,
122 true
123 );
124
125 if (!empty($aCurrentPage))
126 {
127 foreach ($aCurrentPage as $cp)
128 {
129 $l = $cp[ "language" ];
130 $langarr[ $l ] = $cp[ "link" ];
131 $classarr[ $l ] = "easymultilang";
132 }
133 }
134
135 // sort array to always have the same language at the same position
136 ksort( $langarr );
137
138 // returns a blank list of items
139 if ($list === true)
140 {
141 $return_array = [];
142 foreach ( $langarr as $key => $value )
143 {
144 $real_language = $database->get_one("SELECT name FROM " . TABLE_PREFIX . "addons where type = 'language' and directory = '".$key."' ");
145 $return_array[$key] = array(
146 'value'=>$value,
147 'language'=>$real_language
148 );
149 }
150 return $return_array;
151 }
152
153 // loop
154 $aMenuValues = [];
155 foreach ( $langarr as $key => $value )
156 {
157 $aResult = [];
158 $database->execute_query(
159 "SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'language' and directory = '".$key."' ",
160 true,
161 $aResult,
162 false
163 );
164
165 if (!empty($aResult))
166 {
167 $txt = $aResult[ "name" ];
168 $link = LEPTON_URL . PAGES_DIRECTORY . $value . ".php?lang=$key";
169 if (file_exists(LEPTON_PATH ."/modules/lib_lepton/flags/custom/" . strtolower( $key ) . ".png"))
170 {
171 $flag = LEPTON_URL ."/modules/lib_lepton/flags/custom/" . strtolower( $key ) . ".png";
172 }
173 else
174 {
175 $flag = LEPTON_URL ."/modules/lib_lepton/flags/" . strtolower( $key ) . ".png";
176 }
177
178 $values = array(
179 'CLASS' => $classarr[ $key ],
180 'IMG' => $flag,
181 'TXT' => $txt
182 );
183
184 if ( $classarr[ $key ] == "easymultilang_current" )
185 {
186 $values[ 'ASTART' ] = '';
187 $values[ 'AEND' ] = '';
188 }
189 else
190 {
191 $values[ 'ASTART' ] = "<a href='$link' title='$txt'>";
192 $values[ 'AEND' ] = '</a>';
193 }
194 $aMenuValues[] = $values;
195 }
196 }
197
198 // Aldus:: L* 4.4
199 $html = "";
200 $sMenuTemplateFile = LEPTON_PATH."/templates/".DEFAULT_TEMPLATE."/frontend/easymultilang/menu.lte";
201 if(file_exists( $sMenuTemplateFile ))
202 {
203 // use twig
204 $oTWIG = lib_twig_box::getInstance();
205 $oTWIG->registerPath( LEPTON_PATH."/templates/".DEFAULT_TEMPLATE."/frontend/easymultilang/", "easymultilang");
206 $html = $oTWIG->render(
207 "@easymultilang/menu.lte",
208 [
209 "allMenuItems" => $aMenuValues
210 ]
211 );
212
213 }
214 else
215 {
216 // use this template ...
217 $html_template_str = "\n<span class='{{ CLASS }}'>{{ ASTART }}<img src='{{ IMG }}' alt='{{ TXT }}' /> {{ TXT }}{{ AEND }}</span>";
218
219 foreach($aMenuValues as &$ref)
220 {
221 $sTempLine = $html_template_str;
222 foreach($ref as $key=>$value)
223 {
224 $sTempLine = str_replace("{{ ".$key." }}", $value, $sTempLine);
225 }
226 $html .= $sTempLine;
227 }
228 }
229 return $html;
230}
static getInstance(array &$settings=[])
$database
Definition constants.php:52
easymultilang_menu($list=false)