Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
panel.php
1<?php
3
8
9
10class Panel
11{
12 const DIALOG_ID = 'jsTranslateFilesWindow';
13
18 public static function onPanelCreate()
19 {
24 global $APPLICATION, $USER;
25
26 if (!$USER instanceof \CUser || !$USER->isAuthorized())
27 {
28 return;
29 }
30
31 if (!Translate\Permission::canView($USER))
32 {
33 return;
34 }
35
36 if (Translate\Config::getOption(Translate\Config::OPTION_BUTTON_LANG_FILES) === 'Y')
37 {
38 Loc::loadLanguageFile(__FILE__);
39
40 $cmd = 'Y';
41 $checked = false;
42 if (isset($_SESSION['SHOW_LANG_FILES']))
43 {
44 $cmd = $_SESSION['SHOW_LANG_FILES'] == 'Y' ? 'N' : 'Y';
45 $checked = ($_SESSION['SHOW_LANG_FILES'] == 'Y');
46 }
47
48 $url = $APPLICATION->getCurPageParam('show_lang_files='.$cmd, array('show_lang_files'));
49 $menu = array(
50 array(
51 'TEXT' => Loc::getMessage('TRANSLATE_SHOW_LANG_FILES_TEXT'),
52 'TITLE' => Loc::getMessage('TRANSLATE_SHOW_LANG_FILES_TITLE'),
53 'CHECKED' => $checked,
54 'LINK' => $url,
55 'DEFAULT' => false,
56 ),
57 );
58 if ($checked)
59 {
60 $menu[] = array(
61 'TEXT' => Loc::getMessage('TRANSLATE_SHOW_LOADED_LANG_FILES_TEXT'),
62 'TITLE' => Loc::getMessage('TRANSLATE_SHOW_LOADED_LANG_FILES_TITLE'),
63 'ONCLICK' => self::DIALOG_ID.'.Show()',
64 'DEFAULT' => false,
65 );
66 }
67
68 $APPLICATION->addPanelButton(array(
69 'HREF' => '',
70 'ID' => 'translate',
71 'ICON' => 'bx-panel-translate-icon',
72 'ALT' => Loc::getMessage('TRANSLATE_ICON_ALT'),
73 'TEXT' => Loc::getMessage('TRANSLATE_ICON_TEXT'),
74 'MAIN_SORT' => '1000',
75 'SORT' => 50,
76 'MODE' => array('configure'),
77 'MENU' => $menu,
78 'HINT' => array(
79 'TITLE' => Loc::getMessage('TRANSLATE_ICON_TEXT'),
80 'TEXT' => Loc::getMessage('TRANSLATE_ICON_HINT'),
81 ),
82 ));
83 }
84 }
85
90 public static function showLoadedFiles()
91 {
96 global $APPLICATION, $USER;
97
98 if (!$USER instanceof \CUser || !$USER->isAuthorized())
99 {
100 return;
101 }
102
103 if (!Translate\Permission::canView($USER))
104 {
105 return;
106 }
107
108 if (($_SESSION["SHOW_LANG_FILES"] ?? '') !== 'Y')
109 {
110 return;
111 }
112
113 $request = Main\Context::getCurrent()->getRequest();
114
115 // ajax
116 if ($request->isAjaxRequest() || $request->get('AJAX_CALL') !== null)
117 {
118 return;
119 }
120
121 $searchString = $request->get('srchlngfil');
122
123 \CJSCore::init('admin_interface');
124 if (!defined("ADMIN_SECTION"))
125 {
126 $APPLICATION->setAdditionalCSS('/bitrix/themes/.default/pubstyles.css');
127 }
128
129 $popup = new \CJSPopupOnPage();
130 $popup->jsPopup = self::DIALOG_ID;
131
132 ?>
133 <script type="text/javascript">
134 var <?= self::DIALOG_ID ?> = new BX.CDebugDialog();
135 </script>
136 <?
137
138 $popup->startDescription('bx-translate-search');
139 $popup->startContent(array('buffer' => true));
140
141
142 if(!defined('BX_PUBLIC_MODE'))
143 {
144 ?>
145 <p>
146 <input type="text" size="50" class="typeinput" name="srchlngfil" value="<?= \htmlspecialcharsbx($searchString) ?>">
147 <input type="submit" class="button" value="OK">
148 </p>
149 <?
150 }
151
152 ?>
153 <div id="BX_TRANSLATE_FILES">
154 <style type="text/css">
155 .bx-translate-files-table {width: 100%; border: none; border-spacing:0; }
156 .bx-translate-files-table td {padding: 0 4px 4px 0; border:none; vertical-align:top; }
157 .bx-component-debug.bx-debug-summary.bx-translate-debug-summary { left:unset; right: 10px; }
158 </style>
159 <table class="bx-translate-files-table">
160 <?
161
162 $includedLangFiles = Loc::getIncludedFiles();
163 if (!empty($includedLangFiles))
164 {
165 $includedLangFiles = \array_values($includedLangFiles);
166 }
167 $lowPriorityLangFiles = array();
168 $highPriorityLangFiles = array();
169 foreach ($includedLangFiles as $langFile)
170 {
171 $langFile = Main\IO\Path::normalize($langFile);
172
173 if (Localization\Translation::useTranslationRepository() && \in_array(\LANGUAGE_ID, Translate\Config::getTranslationRepositoryLanguages()))
174 {
175 if (\mb_strpos($langFile, Localization\Translation::getTranslationRepositoryPath()) === 0)
176 {
177 $langFile = \str_replace(
178 Localization\Translation::getTranslationRepositoryPath().'/'.\LANGUAGE_ID.'/',
179 '/bitrix/modules/',
180 $langFile
181 );
182 }
183 }
184 if (Localization\Translation::getDeveloperRepositoryPath() !== null)
185 {
186 if (\mb_strpos($langFile, Localization\Translation::getDeveloperRepositoryPath()) === 0)
187 {
188 $langFile = \str_replace(
189 Localization\Translation::getDeveloperRepositoryPath(). '/',
190 '/bitrix/modules/',
191 $langFile
192 );
193 }
194 }
195 if (\mb_strpos($langFile, Main\Application::getDocumentRoot()) === 0)
196 {
197 $langFile = \str_replace(
199 '/',
200 $langFile
201 );
202 }
203 if (empty($langFile))
204 {
205 continue;
206 }
207
208 if(
209 (\mb_strpos($langFile, "/menu") !== false) ||
210 (\mb_strpos($langFile, "/classes") !== false) ||
211 (\mb_strpos($langFile, "tools.") !== false) ||
212 (\mb_strpos($langFile, "/include.") !== false) ||
213 (\mb_strpos($langFile, "menu_template.php") !== false) ||
214 (\mb_strpos($langFile, ".menu.") !== false) ||
215 (\mb_strpos($langFile, "/top_panel.php") !== false) ||
216 (\mb_strpos($langFile, "prolog_main_admin.php") !== false) ||
217 (\mb_strpos($_SERVER["REQUEST_URI"], "/iblock_") === false && \mb_strpos($langFile, "/modules/iblock/lang/")!==false)
218 )
219 {
220 $lowPriorityLangFiles[] = $langFile;
221 }
222 else
223 {
224 $highPriorityLangFiles[] = $langFile;
225 }
226 }
227
228
229 $lowPriorityLangFiles = \array_unique($lowPriorityLangFiles);
230 $highPriorityLangFiles = \array_unique($highPriorityLangFiles);
231
232 \asort($lowPriorityLangFiles);
233 \reset($lowPriorityLangFiles);
234
235 $highPriorityLangFiles = \array_reverse($highPriorityLangFiles, true);
236
237 $includedLangFiles = \array_merge($highPriorityLangFiles, $lowPriorityLangFiles);
238
239 if ($searchString !== null)
240 {
241 $lookForCode = \preg_match("/[a-z1-9_]+/i", $searchString);
242 }
243
244 foreach ($includedLangFiles as $langFile)
245 {
246 $stf = '';
247
248 if ($searchString !== null)
249 {
250 $found = false;
251
252 $filePath = Localization\Translation::convertLangPath($_SERVER["DOCUMENT_ROOT"]. $langFile, \LANGUAGE_ID);
253 if (\file_exists($filePath))
254 {
255 $filePath = \str_replace('/lang/'.\LANGUAGE_ID.'/', '/', $langFile);
256 $messages = Loc::loadLanguageFile($_SERVER["DOCUMENT_ROOT"]. $filePath, \LANGUAGE_ID);
257
258 $stf = "";
259 foreach ($messages as $code => $phrase)
260 {
261 if (
262 $lookForCode && \mb_strpos($code, $searchString) !== false ||
263 \mb_strpos($phrase, $searchString) !== false
264 )
265 {
266 $found = true;
267 $highlight = "&highlight=". \preg_replace("/[^a-z1-9_]+/i", '', $code);
268 $stf .= '<a href="/bitrix/admin/translate_edit.php?lang='.\LANGUAGE_ID.'&file='.$langFile. $highlight.'">'.
269 \htmlspecialcharsbx($phrase).
270 '</a><br> ';
271 }
272 }
273 }
274 if (!$found)
275 {
276 continue;
277 }
278 }
279 ?>
280 <tr>
281 <td><a href="/bitrix/admin/translate_edit.php?lang=<?= \LANGUAGE_ID ?>&file=<?= $langFile ?>"><?= $langFile ?></a></td>
282 <td><?= $stf ?></td>
283 </tr>
284 <?
285
286 }
287 ?>
288 </table>
289 </div>
290 <?
291 $popup->endContent();
292
293 $popup->startButtons();
294 $popup->showStandardButtons(array('close'));
295
296 if ($searchString !== null)
297 {
298 ?>
299 <script type="text/javascript">BX.ready(function(){ <?= self::DIALOG_ID ?>.Show(); });</script>
300 <?
301 }
302
303 if (defined("ADMIN_SECTION"))
304 {
305 ?>
306 <style>
307 div.bx-component-debug {border:1px solid red; font-size:11px; color:black; background-color:white; text-align:left; }
308 div.bx-component-debug a, div.bx-component-debug a:visited {color:blue; text-decoration:none;}
309 div.bx-component-debug a:hover {color:red; text-decoration:underline}
310 div.bx-debug-summary {margin:5px; width:300px; padding:5px; position:fixed; bottom:10px; left:10px; z-index:1000; opacity: 0.4;}
311 div.bx-debug-summary:hover {opacity: 1;}
312 </style>
313 <?
314 }
315 ?>
316 <div class="bx-component-debug bx-debug-summary bx-translate-debug-summary">
317 <?= Loc::getMessage("TRANSLATE_COUNT_LOADED_LANG_FILES") ?>: <?= count($includedLangFiles) ?><br>
318 <a title="<?= Loc::getMessage("TRANSLATE_SHOW_LOADED_LANG_FILES_TITLE") ?>" href="javascript:<?= self::DIALOG_ID ?>.Show();">
319 <?= Loc::getMessage("TRANSLATE_SHOW_LOADED_LANG_FILES_TEXT") ?>
320 </a><br>
321 </div>
322 <?
323 }
324}
325
static loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static canView($checkUser)