1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
components_lib.php
См. документацию.
1<?
4{
5 var $IBlockID = 0;
6 var $Gallery = false;
7 var $User = array("Permission" => "D"); // current user
8 var $arCache = array();
9 var $arError = array();
10
11 private static
12 $userAliasesCache = array(),
13 $arPassFormShowed = array();
14
15 public function __construct($main_params = array(), $additional_params = array())
16 {
17 // check id iblock
18 if (intval($main_params["IBlockID"]) <= 0)
19 {
20 ShowError(GetMessage("P_IBLOCK_ID_EMPTY"));
21 return false;
22 }
23
24 if (isset($additional_params["cache_path"]) && !empty($additional_params["cache_path"]))
25 $cache_path = rtrim(trim($additional_params["cache_path"]), '/');
26 else
27 $cache_path = "/photogallery"; // default cache path
28 //$cache_path = "/".SITE_ID."/photogallery/".$main_params["IBlockID"]; // default cache path
29
30 // All caches:
31 // #CAHCE_PATH#/gallery#GALLERY_ID#
32 // #CAHCE_PATH#/section#SECTION_ID#
33 // #CAHCE_PATH#/pemission
34 $this->arCache = array(
35 "time" => intval($additional_params["cache_time"]),
36 "path" => str_replace("//", "/", $cache_path)
37 );
38 $this->arError = array(
39 "show_error" => ($additional_params["show_error"] ?? '') === "N" ? "N" : "Y",
40 "set_404" => $additional_params["set_404"] == "Y" ? "Y" : "N"
41 );
42
43 $this->IBlockID = intval($main_params["IBlockID"]);
44
45 if (!empty($main_params["GalleryID"]))
46 {
47 $this->Gallery = $this->GetGallery($main_params["GalleryID"]);
48 if (!$this->Gallery)
49 return false;
50 }
51 $this->User["Permission"] = (!empty($main_params["Permission"]) ? $main_params["Permission"] : $this->GetPermission());
52 if (!$this->CheckPermission("R"))
53 return false;
54 }
55
56 function GetGallery($gallery_id)
57 {
58 static $arResult = array();
60 "id" => serialize(array(
61 "iblock_id" => $this->IBlockID,
62 "user_alias" => $gallery_id,
63 "site" => SITE_ID,
64 "gallery" => $gallery_id
65 )
66 ),
67 "path" => $this->arCache["path"],
68 "time" => $this->arCache["time"]
69 );
70
71 if(($tzOffset = CTimeZone::GetOffset()) <> 0)
72 $arCache["id"] .= "_".$tzOffset;
73
74 if (empty($arResult[$arCache["id"]]))
75 {
76 $cache = new CPHPCache;
77 if ($arCache["time"] > 0 && $cache->InitCache($arCache["time"], $arCache["id"], $arCache["path"]))
78 {
79 $arResult[$arCache["id"]] = $cache->GetVars();
80 }
81 else
82 {
83 CModule::IncludeModule("iblock");
85 "IBLOCK_ACTIVE" => "Y",
86 "IBLOCK_ID" => $this->IBlockID,
87 "SECTION_ID" => 0,
88 "CODE" => $gallery_id
89 );
90
91 $db_res = CIBlockSection::GetList(
92 array(),
94 false
95 );
96
97 if ($db_res && $res = $db_res->GetNext())
98 {
99 $arResult[$arCache["id"]] = $res;
100 if ($arCache["time"] > 0)
101 {
102 $cache->StartDataCache($arCache["time"], $arCache["id"], $arCache["path"]);
103 $cache->EndDataCache($res);
104 }
105 }
106 }
107 }
108 if (empty($arResult[$arCache["id"]]))
109 {
110 if ($this->arError["show_error"] == "Y")
111 ShowError(GetMessage("P_GALLERY_NOT_FOUND"));
112 if ($this->arError["set_404"] == "Y")
113 {
114 @define("ERROR_404","Y");
115 CHTTP::SetStatus("404 Not Found");
116 }
117 return false;
118 }
119 elseif ($arResult[$arCache["id"]]["ACTIVE"] != "Y")
120 {
121 if ($this->arError["show_error"] == "Y")
122 ShowError(GetMessage("P_GALLERY_IS_BLOCKED"));
123 return false;
124 }
125
126 return $arResult[$arCache["id"]];
127 }
128
129 function GetSection($id, &$arSection, $params = array())
130 {
131 static $arResult = array();
132 $params = (is_array($params) ? $params : array($params));
133 $id = intval($id);
134 if ($id <= 0)
135 return 200;
136
137 $arCache = array(
138 "id" => serialize(array(
139 "iblock_id" => $this->IBlockID,
140 "section_id" => $id,
141 "gallery_id" => $this->Gallery && $this->Gallery['ID'] ? $this->Gallery['ID'] : "0",
142 "site" => SITE_ID
143 )
144 ),
145 "path" => $this->arCache["path"],
146 "time" => $this->arCache["time"]
147 );
148
149 if(($tzOffset = CTimeZone::GetOffset()) <> 0)
150 $arCache["id"] .= "_".$tzOffset;
151
152 if (empty($arResult[$arCache["id"]]))
153 {
154 $cache = new CPHPCache;
155 if ($arCache["time"] > 0 && $cache->InitCache($arCache["time"], $arCache["id"], $arCache["path"]))
156 {
157 $arResult[$arCache["id"]] = $cache->GetVars();
158 }
159 else
160 {
161 CModule::IncludeModule("iblock");
163 "IBLOCK_ACTIVE" => "Y",
164 "IBLOCK_ID" => $this->IBlockID,
165 "ID" => $id
166 );
167
168 $db_res = CIBlockSection::GetList(
169 array(),
170 $arFilter,
171 false
172 );
173
174 if (!($db_res && $arSection = $db_res->GetNext()))
175 {
176 if ($this->arError["show_error"] == "Y")
177 ShowError(GetMessage("P_SECTION_NOT_FOUND"));
178 if ($this->arError["set_404"] == "Y")
179 {
180 @define("ERROR_404","Y");
181 CHTTP::SetStatus("404 Not Found");
182 }
183 return 404;
184 }
185 elseif ($arSection["ACTIVE"] != "Y" && $this->User["Permission"] < "U")
186 {
187 if ($this->arError["show_error"] == "Y")
188 ShowError(GetMessage("P_ALBUM_IS_BLOCKED"));
189 return 405;
190 }
191 elseif ($this->Gallery && ($arSection["LEFT_MARGIN"] < $this->Gallery["LEFT_MARGIN"] ||
192 $this->Gallery["RIGHT_MARGIN"] < $arSection["RIGHT_MARGIN"]))
193 {
194 return 301;
195 }
196 else
197 {
198 $arSection["DESCRIPTION"] = htmlspecialcharsbx($arSection["~DESCRIPTION"]);
199
200 $arSection["SECTIONS_CNT"] = 0;
201 if (($arSection["RIGHT_MARGIN"] - $arSection["LEFT_MARGIN"]) > 1)
202 $arSection["SECTIONS_CNT"] = intval(CIBlockSection::GetCount(array("SECTION_ID" => $arSection["ID"])));
203
204 $arSection["SECTION_ELEMENTS_CNT"] = $arSection["SECTION_ELEMENTS_CNT_ALL"] = $arSection["ELEMENTS_CNT"] = 0;
205 $arSection["ELEMENTS_CNT_ALL"] = intval(CIBlockSection::GetSectionElementsCount(
206 $arSection["ID"], array("CNT_ALL" => "Y")));
207
208 // if section not empty
209 if ($arSection["ELEMENTS_CNT_ALL"] > 0)
210 {
211 if ($arSection["SECTIONS_CNT"] > 0)
212 {
213 $arSection["SECTION_ELEMENTS_CNT_ALL"] = intval(CIBlockElement::GetList(
214 array(),
215 array("SECTION_ID" => $arSection["ID"]),
216 array(),
217 false,
218 array("ID")));
219 }
220 else
221 {
222 $arSection["SECTION_ELEMENTS_CNT_ALL"] = $arSection["ELEMENTS_CNT_ALL"];
223 }
224 if ($this->User["Permission"] < "U")
225 {
226 $arSection["ELEMENTS_CNT"] = intval(CIBlockSection::GetSectionElementsCount($arSection["ID"], array("CNT_ACTIVE" => "Y")));
227 }
228 else
229 {
230 $arSection["ELEMENTS_CNT"] = $arSection["ELEMENTS_CNT_ALL"];
231 }
232 // if not exists active elements
233 if ($arSection["ELEMENTS_CNT"] <= 0)
234 $arSection["SECTION_ELEMENTS_CNT"] = 0;
235 // if not exists unactive elements
236 elseif ($arSection["ELEMENTS_CNT_ALL"] == $arSection["ELEMENTS_CNT"])
237 $arSection["SECTION_ELEMENTS_CNT"] = $arSection["SECTION_ELEMENTS_CNT_ALL"];
238 elseif ($arSection["SECTIONS_CNT"] <= 0)
239 $arSection["SECTION_ELEMENTS_CNT"] = $arSection["ELEMENTS_CNT"];
240 else
241 {
242 $arSection["SECTION_ELEMENTS_CNT"] = intval(CIBlockElement::GetList(
243 array(),
244 array("SECTION_ID" => $arSection["ID"], "ACTIVE" => "Y"),
245 array(),
246 false,
247 array("ID")));
248 }
249 }
250
251 $arUserFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("IBLOCK_".$this->IBlockID."_SECTION", $arSection["ID"], LANGUAGE_ID);
252 $arSection["USER_FIELDS"] = $arUserFields;
253 $arSection["DATE"] = $arSection["~DATE"] = $arUserFields["UF_DATE"] ?? null;
254 $arSection["~PASSWORD"] = $arUserFields["UF_PASSWORD"] ?? null;
255 if (is_array($arSection["~PASSWORD"]))
256 $arSection["PASSWORD"] = $arSection["~PASSWORD"]["VALUE"];
257
258 $arSection["PICTURE"] = CFile::GetFileArray($arSection["PICTURE"]);
259 $arSection["DETAIL_PICTURE"] = CFile::GetFileArray($arSection["DETAIL_PICTURE"]);
260 $arSection["PATH"] = array();
261 $db_res = GetIBlockSectionPath($this->IBlockID, $arSection["ID"]);
262 while ($res = $db_res->GetNext())
263 {
264 $arUserFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("IBLOCK_".$this->IBlockID."_SECTION", $res["ID"], LANGUAGE_ID);
265 $res["~PASSWORD"] = $arUserFields["UF_PASSWORD"] ?? null;
266 if (is_array($res["~PASSWORD"]))
267 $res["PASSWORD"] = $res["~PASSWORD"]["VALUE"];
268 $arSection["PATH"][$res["ID"]] = $res;
269 }
270
271 $arResult[$arCache["id"]] = $arSection;
272 if ($arCache["time"] > 0)
273 {
274 $cache->StartDataCache($arCache["time"], $arCache["id"], $arCache["path"]);
275 $cache->EndDataCache($arSection);
276 }
277 }
278 }
279 }
280 $arSection = $arResult[$arCache["id"]];
281 return 200;
282 }
283
284 function GetSectionGallery($arSection = array())
285 {
286 CModule::IncludeModule("iblock");
287 $db_res = CIBlockSection::GetList(
288 array(),
289 array(
290 "IBLOCK_ID" => $arSection["IBLOCK_ID"],
291 "SECTION_ID" => 0,
292 "!LEFT_MARGIN" => $arSection["LEFT_MARGIN"],
293 "!RIGHT_MARGIN" => $arSection["RIGHT_MARGIN"],
294 "!ID" => $arSection["ID"]),
295 false
296 );
297
298 if (!($db_res && $arGallery = $db_res->GetNext()))
299 {
300 if ($this->arError["show_error"] == "Y")
301 ShowError(GetMessage("P_GALLERY_NOT_FOUND"));
302 if ($this->arError["set_404"] == "Y")
303 {
304 @define("ERROR_404","Y");
305 CHTTP::SetStatus("404 Not Found");
306 }
307 return 0;
308 }
309 else
310 {
311 return $arGallery;
312 }
313 }
314
315 function GetPermission()
316 {
317 static $arResult = array();
318 $user_id = intval($GLOBALS["USER"]->GetID());
319 $user_groups = $GLOBALS["USER"]->GetGroups();
320
321 if (!$this->IBlockID)
322 return false;
323
324 $arCache = array(
325 "id" => serialize(array(
326 "iblock_id" => $this->IBlockID,
327 "permission" => $user_groups,
328 "site" => SITE_ID
329 )),
330 "path" => $this->arCache["path"],
331 "time" => $this->arCache["time"]
332 );
333
334 if (empty($arResult[$arCache["id"]]))
335 {
336 $cache = new CPHPCache;
337 if ($arCache["time"] > 0 && $cache->InitCache($arCache["time"], $arCache["id"], $arCache["path"]))
338 {
339 $arResult[$arCache["id"]] = $cache->GetVars();
340 }
341 else
342 {
343 CModule::IncludeModule("iblock");
344 $arResult[$arCache["id"]] = CIBlock::GetPermission($this->IBlockID);
345 if ($arCache["time"] > 0)
346 {
347 $cache->StartDataCache($arCache["time"], $arCache["id"], $arCache["path"]);
348 $cache->EndDataCache($arResult[$arCache["id"]]);
349 }
350 }
351 }
352
353 if (!empty($arResult[$arCache["id"]]))
354 {
355 if (!empty($this->Gallery) && "R" <= $arResult[$arCache["id"]] && $arResult[$arCache["id"]] < "W" && $this->Gallery["CREATED_BY"] == $user_id)
356 {
357 return "W";
358 }
359 return $arResult[$arCache["id"]];
360 }
361 return "D";
362 }
363
364 function CheckPermission($permission = "D", $arSection = array(), $bOutput = true)
365 {
366 $arSection = (!is_array($arSection) ? array() : $arSection);
367 if ($permission < "R")
368 {
369 ShowError(GetMessage("P_DENIED_ACCESS"));
370 return false;
371 }
372 elseif ($permission < "U" && !empty($arSection) && $arSection["ELEMENTS_CNT"] <= 0)
373 {
374 ShowNote($arSection["ELEMENTS_CNT_ALL"] > 0 ? GetMessage("P_SECTION_IS_NOT_APPROVED") : GetMessage("P_SECTION_IS_EMPTY"));
375 return false;
376 }
377 elseif ($permission < "U" && !empty($arSection["PATH"]))
378 {
379 $password_checked = true;
380
381 foreach ($arSection["PATH"] as $key => $res)
382 {
383 if (empty($res["PASSWORD"]))
384 continue;
385
386 if (check_bitrix_sessid() && $arSection["PASSWORD"] == md5($_REQUEST["password_".$arSection["ID"]]))
387 $_SESSION['PHOTOGALLERY']['SECTION'][$arSection["ID"]] = $arSection["PASSWORD"];
388 }
389
390 foreach ($arSection["PATH"] as $key => $res)
391 {
392 if (empty($res["PASSWORD"]))
393 continue;
394
395 if ($res["PASSWORD"] != ($_SESSION['PHOTOGALLERY']['SECTION'][$res["ID"]] ?? null))
396 {
397 $password_checked = false;
398 if ($bOutput)
399 {
400 ?>
401 <div class="photo-info-box photo-album-password">
402 <div class="photo-info-box-inner">
403 <?/*ShowError(GetMessage("P_DENIED_ACCESS"));*/?>
404 <p>
405 <?if ($res["ID"] != $arSection["ID"]):?>
406 <?=GetMessage("P_PARENT_ALBUM_IS_PASSWORDED")?>
407 <?else:?>
408 <?=GetMessage("P_ALBUM_IS_PASSWORDED")?>
409 <?endif;?>
410 <?=str_replace("#NAME#", $res["NAME"], GetMessage("P_ALBUM_IS_PASSWORDED_TITLE"))
411 ?></p>
412 <form method="post" action="<?=POST_FORM_ACTION_URI?>" class="photo-form">
413 <?=bitrix_sessid_post()?>
414 <label for="password_<?=$res["ID"]?>"><?=GetMessage("P_PASSWORD")?>: </label>
415 <input type="password" class="password" name="password_<?=$res["ID"]?>" <?
416 ?>id="password_<?=$res["ID"]?>" value="" />
417 <input type="submit" class="submit" name="supply_password" value="<?=GetMessage("P_ENTER")?>" />
418 </form>
419 </div>
420 </div>
421 <?
422 self::$arPassFormShowed[$arSection["ID"]] = true;
423 }
424 break;
425 }
426 }
427
428 return $password_checked;
429 }
430
431 return true;
432 }
433
434 public function IsPassFormDisplayed($sectId)
435 {
436 return isset(self::$arPassFormShowed[$sectId]) && self::$arPassFormShowed[$sectId];
437 }
438
439 public static function GetUserAlias($userId = false, $iblockId = 0)
440 {
441 if ($userId && $iblockId && isset(self::$userAliasesCache[$iblockId][$userId]))
442 return self::$userAliasesCache[$iblockId][$userId];
443 return false;
444 }
445
446 public static function GetPathWithUserAlias($path, $userId = false, $iblockId = 0)
447 {
448 $url = '';
449 if ($alias = self::GetUserAlias($userId, $iblockId))
450 $url = preg_replace("/#user_alias#/iu", $alias, $path);
451 return $url;
452 }
453
454 public static function HandleUserAliases($arUserIds = array(), $iblockId = 0)
455 {
456 if (!$iblockId || count($arUserIds) == 0)
457 return;
458
459 foreach($arUserIds as $k => $id)
460 if (isset(self::$userAliasesCache[$iblockId][$id]))
461 unset($arUserIds[$k]);
462
463 if (count($arUserIds) > 0)
464 {
465 CModule::IncludeModule("iblock");
466
467 $db_res = CIBlockSection::GetList(
468 array("ID", "CREATED_BY", "CODE", "IBLOCK_ID", "IBLOCK_SECTION_ID", "ACTIVE"),
469 array(
470 "ACTIVE" => "Y",
471 "IBLOCK_ACTIVE" => "Y",
472 "IBLOCK_ID" => $iblockId,
473 "SECTION_ID" => 0,
474 "CREATED_BY" => $arUserIds
475 ),
476 false
477 );
478
479 while ($res = $db_res->GetNext())
480 {
481 if (isset(self::$userAliasesCache[$iblockId][$res['CREATED_BY']]))
482 continue;
483 self::$userAliasesCache[$iblockId][$res['CREATED_BY']] = $res['CODE'];
484 }
485 }
486 }
487
488 private static function GetUniqAjaxId()
489 {
490 $uniq = COption::GetOptionString("photogallery", "~uniq_ajax_id", "");
491 if($uniq == '')
492 {
493 $uniq = md5(uniqid(rand(), true));
494 COption::SetOptionString("photogallery", "~uniq_ajax_id", $uniq);
495 }
496 return $uniq;
497 }
498
499 public static function GetSign($params = array())
500 {
501 return md5(implode('*',$params)."||".CPGalleryInterface::GetUniqAjaxId());
502 }
503
504 public static function CheckSign($sign, $params = array())
505 {
506 return (md5(implode('*', $params)."||".CPGalleryInterface::GetUniqAjaxId()) === $sign);
507 }
508
509 public static function CheckUploaderType($type = "")
510 {
511 if ($GLOBALS["USER"]->CanDoOperation('edit_php'))
512 {
513 if ($type != "form")
514 {
515 CAdminNotify::Add(Array(
516 "MESSAGE" => GetMessage("P_UPLOADER_TYPE_NOTIFY"),
517 "TAG" => "PHOTOGALLERY_UPLOADER",
518 "MODULE_ID" => "PHOTOGALLERY"
519 ));
520 }
521 else
522 {
523 CAdminNotify::DeleteByTag("PHOTOGALLERY_UPLOADER");
524 }
525 }
526 }
527}
528
529?>
$path
Определения access_edit.php:21
$type
Определения options.php:106
$db_res
Определения options_user_settings.php:8
$arResult
Определения generate_coupon.php:16
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static Add($arFields)
Определения admin_notify.php:22
static DeleteByTag($tagId)
Определения admin_notify.php:146
static SetStatus($status)
Определения http.php:476
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$_REQUEST["admin_mnu_menu_id"]
Определения get_menu.php:8
GetIBlockSectionPath($IBLOCK_ID, $SECTION_ID)
Определения iblock.php:520
$iblockId
Определения iblock_catalog_edit.php:30
endif
Определения csv_new_setup.php:990
bitrix_sessid_post($varname='sessid', $returnInvocations=false)
Определения tools.php:4700
check_bitrix_sessid($varname='sessid')
Определения tools.php:4686
ShowError($strError, $cls="errortext")
Определения tools.php:4499
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
ShowNote($strNote, $cls="notetext")
Определения tools.php:4477
$sign
Определения payment.php:69
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
const SITE_ID
Определения sonet_set_content_view.php:12
$k
Определения template_pdf.php:567
$GLOBALS['_____370096793']
Определения update_client.php:1
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7