1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
wiki.php
См. документацию.
1<?php
2
3use \Bitrix\Main\Error;
6
8
9class CWiki
10{
16 var $cIB_E = null;
17 const PAGE_UPDATED_CACHE_ID = "WIKI_PAGE_UPDATED_";
18 const GET_BY_NAME_CACHE_ID = "WIKI_BY_NAME_CACHE_ID_";
19 const CWIKI_CACHE_TTL = 36000000;
20
23
24 function __construct()
25 {
26 $this->cIB_E = new CIBlockElement();
27 $this->errorCollection = new ErrorCollection();
28 }
29
30 function Add($arFields)
31 {
32 $arFields['XML_ID'] = $arFields['NAME'];
33
34 $arCats = array();
35 $CWikiParser = new CWikiParser();
36 $arFields['DETAIL_TEXT'] = $CWikiParser->parseBeforeSave($arFields['DETAIL_TEXT'], $arCats, $arFields['NAME_TEMPLATE']);
38 $arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId;
39
40 //add item
41 $ID = $this->cIB_E->Add($arFields);
42
43 $this->CleanCache($ID, $arFields['NAME'],$arFields['IBLOCK_ID']);
44
45 //serve category / bindings
46 $this->UpdateCategory($ID, $arFields['IBLOCK_ID'], $arCats);
47
48 //$this->UpdateHistory($ID, $arFields['IBLOCK_ID']);
49
50 return $ID;
51 }
52
53 function Update($ID, $arFields)
54 {
55 $arCats = array();
56 $CWikiParser = new CWikiParser();
57 $arFields['DETAIL_TEXT'] = $CWikiParser->parseBeforeSave($arFields['DETAIL_TEXT'], $arCats, $arFields['NAME_TEMPLATE']);
58
59 $this->CleanCache($ID, $arFields['NAME'], $arFields['IBLOCK_ID']);
60 //save item
61 $this->cIB_E->Update($ID, $arFields);
62
63 //serve category / bindings
64 $arCats = str_replace("/", "-", $arCats); //http://jabber.bx/view.php?id=28447
65 $this->UpdateCategory($ID, $arFields['IBLOCK_ID'], $arCats);
66
67 $modifyComment = isset($arFields["MODIFY_COMMENT"]) ? $arFields["MODIFY_COMMENT"] : "";
68
69 $this->UpdateHistory($ID, $arFields['IBLOCK_ID'], $modifyComment);
70
71 return true;
72 }
73
74 function Recover($HISTORY_ID, $ID, $IBLOCK_ID)
75 {
77
78 $rIBlock = CIBlock::getList(Array(), array('ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'));
79 $arIBlock = $rIBlock->GetNext();
80 if ($arIBlock['BIZPROC'] == 'Y' && CModule::IncludeModule('bizproc'))
81 {
82 $arErrorsTmp = array();
83 $arHistoryResult = CBPDocument::GetDocumentFromHistory($HISTORY_ID, $arErrorsTmp);
84 $modifyComment = GetMessage('WIKI_RECOVER_COMMENT')." ".$arHistoryResult["MODIFIED"];
85 if (CBPHistoryService::RecoverDocumentFromHistory($HISTORY_ID))
86 {
87 if ($this->UpdateHistory($ID, $IBLOCK_ID, $modifyComment))
88 return true;
89 else
90 return false;
91 }
92 else
93 return false;
94 }
95 else
96 return false;
97 }
98
99 function UpdateHistory($ID, $IBLOCK_ID, $modifyComment=false)
100 {
101 global $USER;
102
103 $rIBlock = CIBlock::getList(Array(), array('ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'));
104 $arIBlock = $rIBlock->GetNext();
105
106 // add changes history
107 if ($arIBlock['BIZPROC'] == 'Y' && CModule::IncludeModule('bizproc'))
108 {
109 $cRuntime = CBPRuntime::GetRuntime();
110 $cRuntime->StartRuntime();
111 $documentService = $cRuntime->GetService('DocumentService');
112
113 $historyIndex = CBPHistoryService::Add(
114 array(
115 'DOCUMENT_ID' => array('iblock', 'CWikiDocument', $ID),
116 'NAME' => 'New',
117 'DOCUMENT' => null,
118 'USER_ID' => $USER->GetID()
119 )
120 );
121
122 $arDocument = $documentService->GetDocumentForHistory(array('iblock', 'CWikiDocument', $ID), $historyIndex);
123 $arDocument["MODIFY_COMMENT"] = $modifyComment ? $modifyComment : '';
124
125 if (is_array($arDocument))
126 {
127 CBPHistoryService::Update(
128 $historyIndex,
129 array(
130 'NAME' => $arDocument['NAME'],
131 'DOCUMENT' => $arDocument,
132 )
133 );
134 }
135 return true;
136 }
137 return false;
138 }
139
140 function UpdateCategory($ID, $IBLOCK_ID, $arCats)
141 {
142
144
146 'IBLOCK_ID' => $IBLOCK_ID,
147 'CHECK_PERMISSIONS' => 'N'
148 );
149 $arElement = self::GetElementById($ID, $arFilter);
150 $bCategoryPage = false;
151 $sCatName = '';
152 $arCatsID = array();
153 if (CWikiUtils::IsCategoryPage($arElement['~NAME'], $sCatName))
154 $bCategoryPage = true;
155
156 if ($bCategoryPage)
157 {
158 // get current category
159 $arFilter = array('NAME' => $sCatName, 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
161 {
162 $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder;
163 $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder;
164 }
165 $rsCurCats = CIBlockSection::GetList(array(), $arFilter);
166 $arCurCat = $rsCurCats->GetNext();
167
168 if (empty($arCurCat))
169 {
170 $CIB_S = new CIBlockSection();
171 $_arFields = array();
172 $_arFields['IBLOCK_ID'] = $IBLOCK_ID;
173 $_arFields['ACTIVE'] = 'Y';
174 $_arFields['NAME'] = $sCatName;
175 $_arFields['XML_ID'] = $sCatName;
177 $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId;
178 $iCurCatID = $CIB_S->Add($_arFields);
179 if ($iCurCatID != false)
180 $arCatsID[] = $iCurCatID;
181 }
182 else
183 {
184 $iCurCatID = $arCurCat['ID'];
185 $arCatsID[] = $arCurCat['ID'];
186 }
187
188 // Page bind only to this category
189 CIBlockElement::SetElementSection($ID, $arCatsID);
190
191 $CIB_S = new CIBlockSection();
192 if (!empty($arCats))
193 {
194 // Nova create a category if it still has no
195 $arFilter = array('NAME' => $arCats[0], 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
197 {
198 $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder;
199 $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder;
200 }
201 $rsCats = CIBlockSection::GetList(array(), $arFilter);
202 $arCat = $rsCats->GetNext();
203
204 if (empty($arCat))
205 {
206 $_arFields = array();
207 $_arFields['IBLOCK_ID'] = $IBLOCK_ID;
208 $_arFields['ACTIVE'] = 'Y';
209 $_arFields['NAME'] = CWikiUtils::htmlspecialcharsback($arCats[0]);
210 $_arFields['XML_ID'] = CWikiUtils::htmlspecialcharsback($arCats[0]);
211 $_arFields['CHECK_PERMISSIONS'] = 'N';
213 $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId;
214
215 $iCatID = $CIB_S->Add($_arFields);
216 }
217 else
218 $iCatID = $arCat['ID'];
219
220 $_arFields = array();
221 $_arFields['IBLOCK_ID'] = $IBLOCK_ID;
222 $_arFields['ACTIVE'] = 'Y';
223 $_arFields['IBLOCK_SECTION_ID'] = $iCatID;
224 // current category doing this subcategory
225 $CIB_S->Update($iCurCatID, $_arFields);
226 }
227 else
228 {
229 $_arFields = array();
230 $_arFields['IBLOCK_ID'] = $IBLOCK_ID;
231 $_arFields['ACTIVE'] = 'Y';
232 $_arFields['IBLOCK_SECTION_ID'] = 0;
234 $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId;
235 // bind to the root category
236 $CIB_S->Update($iCurCatID, $_arFields);
237 }
238 }
239 else //not category
240 {
241 $arExistsCatsId = array();
242 $arDelCatId = array();
243 $rsSect = CIBlockElement::GetElementGroups($ID, false);
244 //$arResult['SECTIONS'] = array(); //erase candidat
245 while($arSect = $rsSect->GetNext())
246 $arExistsCatsId[] = $arSect['ID'];
247
248 if (!empty($arCats))
249 {
250 $arFilter = array('NAME' => $arCats, 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
252 {
253 $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder;
254 $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder;
255 }
256 $rsCats = CIBlockSection::GetList(array(), $arFilter);
257 $arExiststInBlockCats = [];
258 while($arCat = $rsCats->GetNext())
259 {
260 $arExiststInBlockCats[] = $arCat['~NAME'];
261 $arCatsID[] = $arCat['ID'];
262 }
263
264 $CIB_S = new CIBlockSection();
265 foreach ($arCats as $sCatName)
266 {
267 if (!in_array($sCatName, $arExiststInBlockCats))
268 {
269 $_arFields = array();
270 $_arFields['IBLOCK_ID'] = $IBLOCK_ID;
271 $_arFields['ACTIVE'] = 'Y';
272 $_arFields['NAME'] = CWikiUtils::htmlspecialcharsback($sCatName, false);
273 $_arFields['XML_ID'] = CWikiUtils::htmlspecialcharsback($sCatName, false);
274 $_arFields['CHECK_PERMISSIONS'] = 'N';
276 $_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId;
277 $iCatID = $CIB_S->Add($_arFields);
278 if ($iCatID != false)
279 $arCatsID[] = $iCatID;
280 }
281 }
282
283 //bind to the item
284 if (!empty($arCatsID))
285 {
286 //if (CWikiSocnet::IsSocNet())
287 // $arCatsID[] = CWikiSocnet::$iCatId;
288 CIBlockElement::SetElementSection($ID, $arCatsID);
289 }
290 }
291 else
292 {
293 $arCatsID = array();
295 $arCatsID = CWikiSocnet::$iCatId;
296 CIBlockElement::SetElementSection($ID, $arCatsID);
297 }
298
299 if (is_array($arCatsID))
300 $arDelCatId = array_diff($arExistsCatsId, $arCatsID);
301 if (!empty($arDelCatId))
302 {
303 foreach ($arDelCatId as $_iCatId)
304 {
305 $obRes = CIBlockSection::GetList(array(), array('ID' => $_iCatId, 'IBLOCK_ID' => $IBLOCK_ID), true);
306 $arCatProp = $obRes->Fetch();
307 if ($arCatProp['ELEMENT_CNT'] == 0)
308 CIBlockSection::Delete($_iCatId);
309 }
310 }
311 }
312 }
313
314 //TODO: Delete (check) all comments
316 {
317 $rIBlock = CIBlock::getList(Array(), array('ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N'));
318 $arIBlock = $rIBlock->GetNext();
319
320 // erase the history of changes
321 if ($arIBlock['BIZPROC'] == 'Y' && CModule::IncludeModule('bizproc'))
322 {
323 $historyService = new CBPHistoryService();
324 $historyService->DeleteHistoryByDocument(array('iblock', 'CWikiDocument', $ID));
325 }
326
328
329 // delete item
330 $bResult = $this->cIB_E->Delete($ID);
331
332 return $bResult;
333 }
334
335 function AddImage($ID, $IBLOCK_ID, $arImage)
336 {
338 $arCurImages = array();
339 $arCurImagesNew = array();
340 $arAddImage = array();
341
342 $rsProperties = CIBlockElement::GetProperty($IBLOCK_ID, $ID, 'value_id', 'asc', array('ACTIVE' => 'Y', 'CODE' => 'IMAGES'));
343 while($arProperty = $rsProperties->Fetch())
344 {
345 if($arProperty['CODE'] == 'IMAGES')
346 {
347 $arProperties['IMAGES'] = $arProperty;
348 $arCurImages[$arProperty['VALUE']] = '';
349 }
350 }
351
352 $rsFile = CFile::GetList(array(), array('@ID' => implode(',', array_keys($arCurImages))));
353 while($arFile = $rsFile->Fetch())
354 $arCurImages[$arFile['ID']] = $arFile['ORIGINAL_NAME'];
355
356 if(array_search($arImage['name'], $arCurImages) !== false)
357 {
358 $this->errorCollection->add(array(new Error(Loc::getMessage('WIKI_ERROR_IMAGE_ATTACHED'))));
359 return false;
360 }
361
362 $obProperty = new CIBlockProperty();
363 $res = true;
364 if(!array_key_exists('IMAGES', $arProperties))
365 {
366 $res = $obProperty->Add(array(
367 'IBLOCK_ID' => $IBLOCK_ID,
368 'ACTIVE' => 'Y',
369 'PROPERTY_TYPE' => 'F',
370 'MULTIPLE' => 'Y',
371 'NAME' => 'Images',
372 'CODE' => 'IMAGES'
373 ));
374 }
375
376 $arFields = array();
377
378 CFile::ResizeImage($arImage, array(
379 'width' => COption::GetOptionString('wiki', 'image_max_width', 600),
380 'height' => COption::GetOptionString('wiki', 'image_max_height', 600)
381 ));
382
383 $arFields['PROPERTY_VALUES'] = array('IMAGES' => $arImage);
384 $arFields['BLOCK_ID'] = $IBLOCK_ID;
385 $arFields['ELEMENT_ID'] = $ID;
386
387 $this->cIB_E->Update($ID, $arFields);
388
389 $rsProperties = CIBlockElement::GetProperty($IBLOCK_ID, $ID, 'value_id', 'asc', array('ACTIVE' => 'Y', 'CODE' => 'IMAGES', 'EMPTY' => 'N'));
390 while($arProperty = $rsProperties->Fetch())
391 {
392 if($arProperty['CODE'] == 'IMAGES')
393 $arCurImagesNew[$arProperty['VALUE']] = '';
394 }
395
396 $arAddImage = array_diff(array_keys($arCurImagesNew), array_keys($arCurImages));
397 $imgId = current($arAddImage);
398 return $imgId;
399 }
400
401 function DeleteImage($IMAGE_ID, $ID, $IBLOCK_ID)
402 {
403 $rsProperties = CIBlockElement::GetProperty($IBLOCK_ID, $ID, 'value_id', 'asc', array('ACTIVE' => 'Y', 'CODE' => 'IMAGES'));
404 $_iPropertyId = 0;
405 while($arProperty = $rsProperties->Fetch())
406 {
407 if($arProperty['CODE'] == 'IMAGES' && $arProperty['VALUE'] == $IMAGE_ID)
408 {
409 $_iPropertyId = $arProperty['PROPERTY_VALUE_ID'];
410 break;
411 }
412 }
413
414 if (!empty($_iPropertyId))
415 {
416 $arPropertyValues = array();
417 $arPropertyValues[$_iPropertyId] = array('VALUE' => array('del' => 'Y'), 'DESCRIPTION' => '');
418 $this->cIB_E->SetPropertyValues($ID, $IBLOCK_ID, $arPropertyValues, 'IMAGES');
419 }
420 }
421
422 function Rename($ID, $arFields, $bUpdateSearch=true)
423 {
424 $arFilter = array('IBLOCK_ID' => $arFields['IBLOCK_ID'], 'CHECK_PERMISSIONS' => 'N');
425
426 // checking for the existence of a page with this name
427 $arElement = self::GetElementByName($arFields['NAME'], $arFilter);
428 $arOldElement = self::GetElementById($ID, $arFilter);
429
430 $bRename = false;
431 if ($arOldElement != false)
432 {
433 if ($arElement == false)
434 $bRename = true;
435 else if($arElement['ID'] == $ID)
436 $bRename = true;
437 }
438
439 if ($bRename)
440 {
441 $this->CleanCacheById($ID, $arFields['IBLOCK_ID']);
442
443 $arFields['XML_ID'] = $arFields['NAME'];
444 $this->cIB_E->Update($ID, $arFields, false, $bUpdateSearch);
445
446 $sCatName = '';
447 if(CWikiUtils::IsCategoryPage($arFields['NAME'], $sCatName))
448 {
449 $sCatNameOld = '';
450 if (CWikiUtils::IsCategoryPage($arOldElement['NAME'], $sCatNameOld))
451 {
452 // rename a category
453 $arFilter = array('NAME' => $sCatNameOld, 'IBLOCK_ID' => $arFields['IBLOCK_ID'], 'CHECK_PERMISSIONS' => 'N');
455 {
456 $arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder;
457 $arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder;
458 }
459 $rsCats = CIBlockSection::GetList(array(), $arFilter);
460 $arCat = $rsCats->GetNext();
461
462 if ($arCat != false)
463 {
464 $CIB_S = new CIBlockSection();
465
466 $_arFields = array();
467 $_arFields['IBLOCK_ID'] = $arFields['IBLOCK_ID'];
468 $_arFields['NAME'] = $sCatName;
469 $_arFields['XML_ID'] = $sCatName;
470 $_arFields['CHECK_PERMISSIONS'] = 'N';
471
472 $CIB_S->Update($arCat['ID'], $_arFields);
473 }
474 }
475 }
476
477 $arOldElement['NAME'] = CWikiUtils::htmlspecialcharsback($arOldElement['NAME']);
478
479 if (self::GetDefaultPage($arFields['IBLOCK_ID']) == false
480 || (self::GetDefaultPage($arFields['IBLOCK_ID']) == $arOldElement['NAME']
481 && $arOldElement['NAME'] != $arFields['NAME']))
482 self::SetDefaultPage($arFields['IBLOCK_ID'], $arFields['NAME']);
483
484 return true;
485 }
486
487 return false;
488 }
489
490
502 function RenameLinkOnPages($iBlockId, $oldName, $newName, $iBlockSectId = false)
503 {
504 if(!$iBlockId || !$oldName || !$newName)
505 return false;
506
507 $arFilter["IBLOCK_ID"] = $iBlockId;
508 $arFilter["CHECK_PERMISSIONS"]="N";
509
510 if($iBlockSectId)
511 {
512 $arFilter["SECTION_ID"] = $iBlockSectId;
513 $arFilter["INCLUDE_SUBSECTIONS"] = "Y";
514 }
515
516 $count = 0;
517 $sCatName = '';
518 $isCategory = CWikiUtils::IsCategoryPage($oldName , $sCatName);
519
520 $catSearch = "[[".GetMessage('CATEGORY_NAME').":".$sCatName."]]";
521
522 $arPatterns = array(
523 //link and link_name are equal
524 array(
525 "search" => "[[".$oldName."|".$oldName."]]",
526 "pattern" => "/\[\[(".preg_quote($oldName).")\|(".preg_quote($oldName).")\]\]/isUu",
527 "replacement" => "[[".$newName."|".$newName."]]"
528 ),
529
530 //link and link_name are different
531 array(
532 "search" => "[[".$oldName."|",
533 "pattern" => "/\[\[(".preg_quote($oldName).")\|(.*)\]\]/isUu",
534 "replacement" => "[[".$newName."|$2]]"
535 ),
536
537 //exist only link
538 array(
539 "search" => "[[".$oldName."]]",
540 "pattern" => "/\[\[".preg_quote($oldName)."\]\]/isUu",
541 "replacement" => "[[".$newName."]]"
542 )
543 );
544
545
546
547 $dbRes = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID", "NAME", "DETAIL_TEXT"));
548
549 while($arElement = $dbRes->GetNext())
550 {
551 $bChanged = false;
552
553 $newText = $arElement["~DETAIL_TEXT"];
554
555 foreach ($arPatterns as $arPattern)
556 {
557 if(mb_strpos($newText, $arPattern["search"]) !== false)
558 {
559 $newText = preg_replace($arPattern["pattern"], $arPattern["replacement"], $newText);
560 $bChanged = true;
561 }
562 }
563
564
565 if ($isCategory)
566 if(mb_strpos($newText, $catSearch) !== false)
567 {
568 $newText = $this->RenameCategoryOnPage($newText, $sCatName, $newName);
569 $bChanged = true;
570 }
571
572 if($bChanged)
573 {
574 $this->CleanCache($arElement["ID"], $arElement["NAME"], $iBlockId);
575 $this->cIB_E->Update($arElement["ID"], array("DETAIL_TEXT" => $newText), false, true);
576 self::MarkPageAsUpdated($iBlockId, $iBlockSectId, $arElement["NAME"]);
577 $count++;
578 }
579 }
580
581 return $count;
582 }
583
584 function RenameCategoryOnPage($pageText, $oldCategoryName, $newCategoryName)
585 {
586 $newCategoryName = preg_replace("/category:/isU", "", $newCategoryName);
587 return preg_replace("/\[\[".GetMessage('CATEGORY_NAME').":".$oldCategoryName."\]\]/isU", "[[".GetMessage('CATEGORY_NAME').":".$newCategoryName."]]", $pageText);
588 }
589
590 static function SetDefaultPage($IBLOCK_ID, $NAME)
591 {
593 {
594 $ENTITY_ID = 'IBLOCK_'.$IBLOCK_ID.'_SECTION';
595 $ELEMENT_ID = CWikiSocnet::$iCatId;
596 }
597 else
598 {
599 $ENTITY_ID = 'IBLOCK_'.$IBLOCK_ID;
600 $ELEMENT_ID = $IBLOCK_ID;
601 }
602
603 AddEventHandler("main", "OnUserTypeBuildList", array("CUserTypeWiki", "GetUserTypeDescription"));
604 $GLOBALS['USER_FIELD_MANAGER']->CleanCache();
605
606 $arElement = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields($ENTITY_ID, $ELEMENT_ID);
607
608 if ($arElement !== false)
609 {
610 if (!isset($arElement['UF_WIKI_INDEX']))
611 {
612 $arFields = array();
613 $arFields['ENTITY_ID'] = $ENTITY_ID;
614 $arFields['FIELD_NAME'] = 'UF_WIKI_INDEX';
615 $arFields['USER_TYPE_ID'] = 'wiki';
616 $CAllUserTypeEntity = new CUserTypeEntity();
617 $intID=$CAllUserTypeEntity->Add($arFields);
618 if (false == $intID)
619 {
620 $e = $GLOBALS['APPLICATION']->GetException();
621 if ($e)
622 ShowError(GetMessage("WIKI_USER_T_ADD_ERR").$e->GetString());
623 }
624 }
625
626 if (empty($arElement['UF_WIKI_INDEX']['VALUE']) || $arElement['UF_WIKI_INDEX']['VALUE'] != $NAME)
627 {
628 $arFields = array();
629 $arFields['UF_WIKI_INDEX'] = $NAME;
630 $GLOBALS['USER_FIELD_MANAGER']->Update($ENTITY_ID, $ELEMENT_ID, $arFields);
631 }
632 return true;
633 }
634 return false;
635 }
636
637 static function GetDefaultPage($IBLOCK_ID)
638 {
640 {
641 $ENTITY_ID = 'IBLOCK_'.$IBLOCK_ID.'_SECTION';
642 $ELEMENT_ID = CWikiSocnet::$iCatId;
643 }
644 else
645 {
646 $ENTITY_ID = 'IBLOCK_'.$IBLOCK_ID;
647 $ELEMENT_ID = $IBLOCK_ID;
648 }
649
650 AddEventHandler("main", "OnUserTypeBuildList", array("CUserTypeWiki", "GetUserTypeDescription"));
651 $GLOBALS['USER_FIELD_MANAGER']->CleanCache();
652
653 $arElement = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields(
654 $ENTITY_ID,
655 $ELEMENT_ID
656 );
657
658 return isset($arElement['UF_WIKI_INDEX']['VALUE']) ? $arElement['UF_WIKI_INDEX']['VALUE'] : '';
659 }
660
661 public static function GetCategory($NAME, $IBLOCK_ID)
662 {
663 global $arParams;
664
665 $arResult = array();
666 $arResult[] = array(
667 'TITLE' => GetMessage('Service:Categories_TITLE'),
668 'NAME' => GetMessage('Service:Categories'),
669 'LINK' => CHTTP::urlAddParams(
670 CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CATEGORIES'],
671 array(
672 'wiki_name' => 'Service:Categories',
673 'group_id' => CWikiSocnet::$iSocNetId
674 )
675 ),
676 array()
677 ),
678 'IS_RED' => 'N',
679 'IS_SERVICE' => 'Y'
680 );
681
683 $arFilter['IBLOCK_ID'] = $IBLOCK_ID;
684 $arFilter['CHECK_PERMISSIONS'] = 'N';
685
687 $arFilter['SUBSECTION'] = CWikiSocnet::$iCatId;
688
689 $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, Array());
690 $arElement = $rsElement->GetNext();
691
692 $sCatName = '';
693 if (CWikiUtils::IsCategoryPage($NAME, $sCatName))
694 return $arResult;
695
696 $arLink = array();
697 $arLinkExists = array();
698 $arCat = array();
699 $rsSect = CIBlockElement::GetElementGroups($arElement['ID'], false);
700 while($arSect = $rsSect->GetNext())
701 {
702 $arCat[$arSect['ID']] = $arSect;
703 $arLink[] = 'category:'.CWikiUtils::htmlspecialcharsback($arSect['NAME']);
704 }
705
706 /*if(empty($arLink))
707 return array();*/
708
709 if (CWikiSocnet::IsSocNet() && isset($arCat[CWikiSocnet::$iCatId]))
710 unset($arCat[CWikiSocnet::$iCatId]);
711
712 $arFilter = array();
713 $arFilter['=NAME'] = $arLink;
714 $arFilter['IBLOCK_ID'] = $IBLOCK_ID;
715 $arFilter['ACTIVE'] = 'Y';
716 $arFilter['CHECK_PERMISSIONS'] = 'N';
718 $arFilter['SUBSECTION'] = CWikiSocnet::$iCatId;
719
720 $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, Array());
721
722 while($obElement = $rsElement->GetNextElement())
723 {
724 $arFields = $obElement->GetFields();
725 $arLinkExists[] = preg_replace('/^(category|'.GetMessage('CATEGORY_NAME').'):/iu', '', $arFields['NAME']);
726 }
727
728 if (!empty($arCat))
729 {
730 foreach ($arCat as $_arCat)
731 {
732 $_arCat['NAME'] = CWikiUtils::htmlspecialcharsback($_arCat['NAME'], false);
733 $_arResult = array();
734 $_arResult['ID'] = $_arCat['ID'];
735 $_arResult['IS_RED'] = 'N';
736 $_arResult['LINK'] = CHTTP::urlAddParams(
737 CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CATEGORY'],
738 array(
739 'wiki_name' => 'Category:'.$_arCat['NAME'],
740 'group_id' => CWikiSocnet::$iSocNetId
741 )
742 ),
743 array()
744 );
745
746 $_arResult['TITLE'] = $_arCat['NAME'];
747 $_arResult['NAME'] = $_arCat['NAME'];
748 $_arResult['IS_SERVICE'] = 'N';
749 if (!in_array($_arCat['NAME'], $arLinkExists))
750 $_arResult['IS_RED'] = 'Y';
751 $arResult[] = $_arResult;
752 }
753 }
754 return $arResult;
755 }
756
764 public static function GetElementById($ID, $arFilter)
765 {
766 global $arParams;
767 $arFilter['ID'] = $ID;
769 $arFilter['SUBSECTION'] = CWikiSocnet::$iCatId;
770 $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, Array());
771 $obElement = $rsElement->GetNextElement();
772 $arResult = false;
773 if ($obElement !== false)
774 {
775 $arResult = $obElement->GetFields();
776
777 if (isset($arResult['NAME']))
778 $arResult['NAME'] = htmlspecialcharsbx($arResult['NAME']);
779 $rsProperties = $obElement->GetProperties(array(), array('CODE' => 'IMAGES'));
780
781 foreach ($rsProperties as $arProperty)
782 $arResult[$arProperty['CODE']] = $arProperty['VALUE'];
783
784 $arResult['SECTIONS'] = self::GetCategory($arResult['XML_ID'], $arFilter['IBLOCK_ID']);
785 if (!empty($arResult['TAGS']))
786 {
787 $_arTAGS = explode(',', $arResult['TAGS']);
788 $arResult['_TAGS'] = array();
789 foreach ($_arTAGS as $sTag)
790 {
791 $arTag = array('NAME' => $sTag);
792 if (!empty($arParams['PATH_TO_SEARCH']))
793 {
794 $arP = $arParams['IN_COMPLEX'] == 'Y' && $arParams['SEF_MODE'] == 'N' ? array($arParams['OPER_VAR'] => 'search') : array();
795 $arP['tags'] = rawurlencode($sTag);
796 $arTag['LINK'] = CHTTP::urlAddParams(
797 CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_SEARCH'],
798 array(
799 'wiki_name' => $arParams['ELEMENT_NAME'],
800 'group_id' => CWikiSocnet::$iSocNetId)
801 ),
802 $arP
803 );
804 }
805 $arResult['_TAGS'][] = $arTag;
806 }
807 }
808 }
809 return $arResult;
810 }
811
820 public static function GetElementByName($NAME, $arFilter, $arComponentParams = array())
821 {
822 global $CACHE_MANAGER;
823
824 $iCatId = "";
825
827 {
828 $arFilter['SUBSECTION'] = CWikiSocnet::$iCatId;
829 $iCatId = $arFilter['SUBSECTION'];
830 }
831
832 $cacheByNameID = self::GetIdForCacheByName($arFilter['IBLOCK_ID'], $iCatId, $NAME);
833
834 $cacheTime = isset($arComponentParams['CACHE_TIME']) ? intval($arComponentParams['CACHE_TIME']) : CWiki::CWIKI_CACHE_TTL;
835
836 if($CACHE_MANAGER->Read($cacheTime, $cacheByNameID))
837 {
838 $cachedElement = $CACHE_MANAGER->Get($cacheByNameID);
839
840 if($cachedElement)
841 {
842 //if cached element satisfied to filter's conditions
843 $sameFilter = true;
844 foreach ($arFilter as $key => $value)
845 {
846 if(isset($cachedElement[$key]) && $value != "" && $cachedElement[$key] != $value)
847 {
848 $sameFilter = false;
849 break;
850 }
851 }
852
853 if($sameFilter)
854 return $cachedElement;
855 }
856 }
857
860 $arFilter['=XML_ID'] = $NAME;
861
862 $rsElement = CIBlockElement::GetList(array(), $arFilter);
863 $obElement = $rsElement->GetNextElement();
864 $arResult = false;
865 if ($obElement !== false)
866 {
867 $arResult = $obElement->GetFields();
868 if (isset($arResult['NAME']))
869 $arResult['NAME'] = htmlspecialcharsbx($arResult['NAME']);
870 $rsProperties = $obElement->GetProperties(array(), array('CODE' => 'IMAGES'));
871
872 foreach ($rsProperties as $arProperty)
873 $arResult[$arProperty['CODE']] = $arProperty['VALUE'];
874
875 $rsProperties = $obElement->GetProperties(array(), array('CODE' => 'FORUM_TOPIC_ID'));
876
877 foreach ($rsProperties as $arProperty)
878 $arResult[$arProperty['CODE']] = $arProperty['VALUE'];
879
880 $arResult['SECTIONS'] = self::GetCategory($arResult['XML_ID'], $arFilter['IBLOCK_ID']);
881 if (!empty($arResult['TAGS']))
882 {
883 $_arTAGS = explode(',', $arResult['TAGS']);
884 $arResult['_TAGS'] = array();
885 foreach ($_arTAGS as $sTag)
886 {
887 $sTag = trim($sTag);
888 $arTag = array('NAME' => $sTag);
889 if (
890 !empty($arComponentParams)
891 && (
892 isset($arComponentParams['PATH_TO_SEARCH'])
893 || isset($arComponentParams['~PATH_TO_TAG'])
894 )
895 )
896 {
897 if (isset($arComponentParams['PATH_TO_TAG']))
898 {
899 $arTag['LINK'] = \CComponentEngine::MakePathFromTemplate($arComponentParams['~PATH_TO_TAG'],
900 [
901 'group_id' => CWikiSocnet::$iSocNetId,
902 'tag' => rawurlencode($sTag)
903 ]
904 );
905 }
906 else
907 {
908 $arP = $arComponentParams['IN_COMPLEX'] == 'Y' && $arComponentParams['SEF_MODE'] == 'N' ? array($arComponentParams['OPER_VAR'] => 'search') : array();
909 $arP['tags'] = rawurlencode($sTag);
910 $arTag['LINK'] = CHTTP::urlAddParams(
911 CComponentEngine::MakePathFromTemplate($arComponentParams['PATH_TO_SEARCH'],
912 array(
913 'wiki_name' => $arComponentParams['ELEMENT_NAME'],
914 'group_id' => CWikiSocnet::$iSocNetId
915 )
916 ),
917 $arP
918 );
919 }
920 }
921 $arResult['_TAGS'][] = $arTag;
922 }
923 }
924 }
925
926 if(!empty($arComponentParams)) //Let's store only full page data with tag links
927 $CACHE_MANAGER->Set($cacheByNameID, $arResult);
928
929 return $arResult;
930 }
931
935 public function getErrors()
936 {
938 }
939
940 public function CleanCacheById($ID, $iBlockId = false)
941 {
942 return $this->CleanCache($ID, false, $iBlockId);
943 }
944
945 public function CleanCache($ID = false, $Name = false, $iBlockId = false)
946 {
947 if($ID === false && !$Name)
948 return false;
949
950 global $CACHE_MANAGER;
951
952 if($ID !== false)
953 $CACHE_MANAGER->ClearByTag('wiki_'.$ID);
954
955 if(!$iBlockId)
956 return true;
957
959
960 if($ID !== false )
961 {
962 $cacheByNameID = self::GetIdForCacheByName($iBlockId, $iCatId, $ID);
963 $CACHE_MANAGER->Clean($cacheByNameID);
964
965 if(!$Name)
966 {
968 'IBLOCK_ID' => $iBlockId,
969 'CHECK_PERMISSIONS' => 'N'
970 );
971
972 $arElement = self::GetElementById($ID, $arFilter);
973 if($arElement != false)
974 $elName = $arElement['NAME'];
975 }
976 else
977 {
978 $elName = $Name;
979 }
980 }
981
982 $cacheByNameID = self::GetIdForCacheByName($iBlockId, $iCatId, $elName);
983 $CACHE_MANAGER->Clean($cacheByNameID);
984
985 return true;
986 }
987
988 private static function GetIdForCacheByName($iBlockId, $iSocCatId, $elementName)
989 {
990 return self::GET_BY_NAME_CACHE_ID.$iBlockId.$iSocCatId.$elementName;
991 }
992
993 public static function UnMarkPageAsUpdated($iBlockId, $iSocCatId, $name)
994 {
995 global $CACHE_MANAGER;
996
997 $cacheId = self::GetCacheIdForPageUpdated($iBlockId, $iSocCatId, $name);
998
999 $CACHE_MANAGER->Clean($cacheId);
1000
1001 return true;
1002 }
1003
1004 public static function IsPageUpdated($iBlockId, $iSocCatId, $name, $cacheTime = self::CWIKI_CACHE_TTL)
1005 {
1006 global $CACHE_MANAGER;
1007
1008 $cacheId = self::GetCacheIdForPageUpdated($iBlockId, $iSocCatId, $name);
1009
1010 if ($CACHE_MANAGER->Read($cacheTime, $cacheId))
1011 {
1012 return ($CACHE_MANAGER->Get($cacheId) == "Y");
1013 }
1014
1015 return false;
1016 }
1017
1018 private static function MarkPageAsUpdated($iBlockId, $iSocCatId, $name)
1019 {
1020 global $CACHE_MANAGER;
1021
1022 $cacheId = self::GetCacheIdForPageUpdated($iBlockId, $iSocCatId, $name);
1023
1024 $CACHE_MANAGER->Set($cacheId, "Y");
1025
1026 return true;
1027 }
1028
1029 private static function GetCacheIdForPageUpdated($iBlockId, $iSocCatId, $name)
1030 {
1031 return self::PAGE_UPDATED_CACHE_ID.$iBlockId.$iSocCatId.$name;
1032 }
1033
1034}
1035
1036?>
$arParams
Определения access_dialog.php:21
$count
Определения admin_tab.php:4
$arResult
Определения generate_coupon.php:16
Определения error.php:15
static urlAddParams($url, $add_params, $options=[])
Определения http.php:521
Определения iblockelement.php:9
Определения iblocksection.php:5
Определения usertype.php:985
Определения wiki.php:10
__construct()
Определения wiki.php:24
static IsPageUpdated($iBlockId, $iSocCatId, $name, $cacheTime=self::CWIKI_CACHE_TTL)
Определения wiki.php:1004
static GetElementById($ID, $arFilter)
Определения wiki.php:764
CleanCache($ID=false, $Name=false, $iBlockId=false)
Определения wiki.php:945
DeleteImage($IMAGE_ID, $ID, $IBLOCK_ID)
Определения wiki.php:401
UpdateHistory($ID, $IBLOCK_ID, $modifyComment=false)
Определения wiki.php:99
$cIB_E
Определения wiki.php:16
Rename($ID, $arFields, $bUpdateSearch=true)
Определения wiki.php:422
const GET_BY_NAME_CACHE_ID
Определения wiki.php:18
getErrors()
Определения wiki.php:935
static GetCategory($NAME, $IBLOCK_ID)
Определения wiki.php:661
$errorCollection
Определения wiki.php:22
Recover($HISTORY_ID, $ID, $IBLOCK_ID)
Определения wiki.php:74
Delete($ID, $IBLOCK_ID)
Определения wiki.php:315
static SetDefaultPage($IBLOCK_ID, $NAME)
Определения wiki.php:590
RenameLinkOnPages($iBlockId, $oldName, $newName, $iBlockSectId=false)
Определения wiki.php:502
static UnMarkPageAsUpdated($iBlockId, $iSocCatId, $name)
Определения wiki.php:993
const PAGE_UPDATED_CACHE_ID
Определения wiki.php:17
UpdateCategory($ID, $IBLOCK_ID, $arCats)
Определения wiki.php:140
CleanCacheById($ID, $iBlockId=false)
Определения wiki.php:940
static GetElementByName($NAME, $arFilter, $arComponentParams=array())
Определения wiki.php:820
const CWIKI_CACHE_TTL
Определения wiki.php:19
Add($arFields)
Определения wiki.php:30
Update($ID, $arFields)
Определения wiki.php:53
RenameCategoryOnPage($pageText, $oldCategoryName, $newCategoryName)
Определения wiki.php:584
AddImage($ID, $IBLOCK_ID, $arImage)
Определения wiki.php:335
static GetDefaultPage($IBLOCK_ID)
Определения wiki.php:637
Определения wiki_parser.php:6
static $iCatRightBorder
Определения wiki_socnet.php:15
static $iCatLeftBorder
Определения wiki_socnet.php:14
static IsSocNet()
Определения wiki_socnet.php:97
static $iCatId
Определения wiki_socnet.php:13
static $iSocNetId
Определения wiki_socnet.php:17
static UnlocalizeCategoryName($categoryName)
Определения wiki_utils.php:478
static IsCategoryPage($NAME, &$CATEGORY_NAME)
Определения wiki_utils.php:291
static htmlspecialcharsback($str, $end=true)
Определения wiki_utils.php:399
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$arFields
Определения dblapprove.php:5
</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
if($ajaxMode) $ID
Определения get_user.php:27
$iBlockId
Определения iblock_subelement_generator.php:45
$IBLOCK_ID
Определения csv_new_run.php:168
global $USER
Определения csv_new_run.php:40
AddEventHandler($FROM_MODULE_ID, $MESSAGE_ID, $CALLBACK, $SORT=100, $FULL_PATH=false)
Определения tools.php:5165
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
$name
Определения menu_edit.php:35
if(empty($signedUserToken)) $key
Определения quickway.php:257
$GLOBALS['_____370096793']
Определения update_client.php:1
$arFilter
Определения user_search.php:106
$dbRes
Определения yandex_detail.php:168
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
if( $site[ 'SERVER_NAME']==='') if($site['SERVER_NAME']==='') $arProperties
Определения yandex_run.php:644