1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
medialib.php
См. документацию.
1<?
3class CMedialib
4{
5 private static
6 $bCache = true,
7 $cacheTime = 360000,
8 $cachePath = "medialib/";
9
10 public static function Init(){}
11 public static function GetOperations($collectionId, $menu = false)
12 {
13 global $USER;
14 static $oCollections;
15 static $arOp;
16
17 $userGroups = $USER->GetUserGroupArray();
18 $key = $collectionId.'|'.implode('-', $userGroups);
19
20 if (!is_array($arOp[$key] ?? null))
21 {
22 if (!is_array($arOp))
23 $arOp = array();
24
25 if (!is_array($oCollections))
26 {
27 $res = CMedialib::GetCollectionTree(array('menu' => $menu));
28 $oCollections = $res['Collections'];
29 }
30
31 $userGroups = $USER->GetUserGroupArray();
32 $res = CMedialib::GetAccessPermissionsArray($collectionId, $oCollections);
33
34 $arOp[$key] = array();
35 foreach ($res as $group_id => $task_id)
36 {
37 if (in_array($group_id, $userGroups))
38 $arOp[$key] = array_merge($arOp[$key], CTask::GetOperations($task_id, true));
39 }
40 }
41 return $arOp[$key];
42 }
43
44 public static function CanDoOperation($operation, $collectionId=0, $userId = false, $menu = false)
45 {
46 if ($GLOBALS["USER"]->IsAdmin())
47 return true;
48
49 $arOp = CMedialib::GetOperations($collectionId, $menu);
50 return in_array($operation, $arOp);
51 }
52
53 public static function GetAccessPermissionsArray($collectionId = 0, $oCollections = false)
54 {
55 static $arAllTasks;
56 if (is_array($arAllTasks[$collectionId] ?? null))
57 return $arAllTasks[$collectionId];
58
59 $col = $oCollections[$collectionId] ?? [];
60 $col['PARENT_ID'] = $col['PARENT_ID'] ?? null;
61 $arCols = array();
62 $resTask = array();
63
64 if ($col || $collectionId == 0)
65 {
66 $arCols[] = $collectionId;
67 if (intval($col['PARENT_ID']) > 0)
68 {
69 $col_ = $col;
70 while($col_ && intval($col_['PARENT_ID']) > 0)
71 {
72 $arCols[] = $col_['PARENT_ID'];
73 $col_ = $oCollections[$col_['PARENT_ID']];
74 }
75 }
76 $arCols[] = 0;
77 $arPerm = CMedialib::_GetAccessPermissions($arCols);
78
79 for($i = count($arCols); $i >= 0; $i--)
80 {
81 $colId = $arCols[$i] ?? null;
82 if (is_array($arPerm[$colId] ?? null))
83 {
84 for ($j = 0, $n = count($arPerm[$colId]); $j < $n; $j++)
85 $resTask[$arPerm[$colId][$j]['GROUP_ID']] = $arPerm[$colId][$j]['TASK_ID'];
86 }
87 }
88 }
89
90 if (!is_array($arAllTasks))
91 $arAllTasks = array();
92 $arAllTasks[$collectionId] = $resTask;
93
94 return $resTask;
95 }
96
97 public static function _GetAccessPermissions($arCols = array())
98 {
99 global $DB;
100
101 $s = '0';
102 for($i = 0, $l = count($arCols); $i < $l; $i++)
103 $s .= ",".intval($arCols[$i]);
104
105 $strSql = 'SELECT *
106 FROM b_group_collection_task GCT
107 WHERE GCT.COLLECTION_ID in ('.$s.')';
108
109 $res = $DB->Query($strSql );
110
111 $arResult = array();
112 while($arRes = $res->Fetch())
113 {
114 $colid = $arRes['COLLECTION_ID'];
115 if (!is_array($arResult[$colid] ?? null))
116 $arResult[$colid] = array();
117
118 unset($arRes['COLLECTION_ID']);
119 $arResult[$colid][] = $arRes;
120 }
121
122 return $arResult;
123 }
124
125 public static function getMaximumFileUploadSize()
126 {
127 return min(CUtil::Unformat(ini_get('post_max_size')), CUtil::Unformat(ini_get('upload_max_filesize')));
128 }
129
130 public static function ShowDialogScript($arConfig = array())
131 {
132 global $USER;
133
134 CUtil::InitJSCore(array('ajax'));
135
136 $strWarn = '';
137 $arConfig['bReadOnly'] = false;
138 $arConfig['lang'] = LANGUAGE_ID;
139
140 $event = '';
141 if (isset($arConfig['event']))
142 $event = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['event']);
143 if ($event == '')
144 $strWarn .= GetMessage('ML_BAD_EVENT').'. ';
145
146 $resultDest = "";
147 $bDest = is_array($arConfig['arResultDest']);
148 if ($bDest)
149 {
150 if (isset($arConfig['arResultDest']["FUNCTION_NAME"]))
151 {
152 $arConfig['arResultDest']["FUNCTION_NAME"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["FUNCTION_NAME"]);
153 $bDest = $arConfig['arResultDest']["FUNCTION_NAME"] <> '';
154 $resultDest = "FUNCTION";
155 }
156 elseif (isset($arConfig['arResultDest']["FORM_NAME"], $arConfig['arResultDest']["FORM_ELEMENT_NAME"]))
157 {
158 $arConfig['arResultDest']["FORM_NAME"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["FORM_NAME"]);
159 $arConfig['arResultDest']["FORM_ELEMENT_NAME"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["FORM_ELEMENT_NAME"]);
160 $bDest = $arConfig['arResultDest']["FORM_NAME"] <> '' && $arConfig['arResultDest']["FORM_ELEMENT_NAME"] <> '';
161 $resultDest = "FORM";
162 }
163 elseif (isset($arConfig['arResultDest']["ELEMENT_ID"]))
164 {
165 $arConfig['arResultDest']["ELEMENT_ID"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arConfig['arResultDest']["ELEMENT_ID"]);
166 $bDest = $arConfig['arResultDest']["ELEMENT_ID"] <> '';
167 $resultDest = "ID";
168 }
169 else
170 {
171 $bDest = false;
172 }
173 }
174 if (!$bDest)
175 $strWarn .= GetMessage('ML_BAD_RETURN').'. ';
176
177 if ($strWarn == '')
178 {
179 ?>
180 <script>
181 if (!window.BX && top.BX)
182 window.BX = top.BX;
183
184 <?CMedialib::AppendLangMessages();?>
185 window.<?= $arConfig['event']?> = function(bLoadJS)
186 {
187 if (window.oBXMedialib && window.oBXMedialib.bOpened)
188 return false;
189
190 <?if(!CMedialib::CanDoOperation('medialib_view_collection', 0)):?>
191 return alert(ML_MESS.AccessDenied);
192 <?else:?>
193
194 if (!window.BXMediaLib)
195 {
196 if (bLoadJS !== false)
197 {
198 // Append CSS
199 BX.loadCSS("/bitrix/js/fileman/medialib/medialib.css");
200
201 var arJS = [];
202 if (!window.jsAjaxUtil)
203 arJS.push("/bitrix/js/main/ajax.js?v=<?= filemtime($_SERVER["DOCUMENT_ROOT"].'/bitrix/js/main/ajax.js')?>");
204 if (!window.jsUtils)
205 arJS.push("/bitrix/js/main/utils.js?v=<?= filemtime($_SERVER["DOCUMENT_ROOT"].'/bitrix/js/main/utils.js')?>");
206 if (!window.CHttpRequest)
207 arJS.push("/bitrix/js/main/admin_tools.js?v=<?= filemtime($_SERVER["DOCUMENT_ROOT"].'/bitrix/js/main/admin_tools.js')?>");
208
209 arJS.push("/bitrix/js/fileman/medialib/common.js?v=<?= filemtime($_SERVER["DOCUMENT_ROOT"].'/bitrix/js/fileman/medialib/common.js')?>");
210 arJS.push("/bitrix/js/fileman/medialib/core.js?v=<?= filemtime($_SERVER["DOCUMENT_ROOT"].'/bitrix/js/fileman/medialib/core.js')?>");
211 BX.loadScript(arJS);
212 }
213 return setTimeout(function(){<?=$arConfig['event']?>(false)}, 50);
214 }
215
216 <?CMedialib::ShowJS()?>
217 <?
218 $arSet = explode(',' , CUserOptions::GetOption("fileman", "medialib_user_set", '600,450,0'));
219 $width = $arSet[0] ? intval($arSet[0]) : 600;
220 $height = $arSet[1] ? intval($arSet[1]) : 450;
221 $coll_id = $arSet[2] ? intval($arSet[2]) : 0;
222 ?>
223 window._mlUserSettings = window._mlUserSettings || {width: <?=$width?>, height: <?=$height?>, coll_id: <?=$coll_id?>}
224
225 var oConfig =
226 {
227 sessid: "<?=bitrix_sessid()?>",
228 thumbWidth : <?= COption::GetOptionInt('fileman', "ml_thumb_width", 140)?>,
229 thumbHeight : <?= COption::GetOptionInt('fileman', "ml_thumb_height", 105) ?>,
230 userSettings : window._mlUserSettings,
231 resType: "<?= $resultDest?>",
232 Types : <?= CUtil::PhpToJSObject(CMedialib::GetTypes($arConfig['types'] ?? null))?>,
233 arResultDest : <?= CUtil::PhpToJSObject($arConfig['arResultDest'])?>,
234 rootAccess: {
235 new_col: '<?= CMedialib::CanDoOperation('medialib_new_collection', 0)?>',
236 edit: '<?= CMedialib::CanDoOperation('medialib_edit_collection', 0)?>',
237 del: '<?= CMedialib::CanDoOperation('medialib_del_collection', 0)?>',
238 new_item: '<?= CMedialib::CanDoOperation('medialib_new_item', 0)?>',
239 edit_item: '<?= CMedialib::CanDoOperation('medialib_edit_item', 0)?>',
240 del_item: '<?= CMedialib::CanDoOperation('medialib_del_item', 0)?>',
241 access: '<?= CMedialib::CanDoOperation('medialib_access', 0)?>'
242 },
243 bCanUpload: <?= $USER->CanDoOperation('fileman_upload_files') ? 'true' : 'false'?>,
244 bCanViewStructure: <?= $USER->CanDoOperation('fileman_view_file_structure') ? 'true' : 'false'?>,
245 strExt : "<?= CUtil::JSEscape(CMedialib::GetMediaExtentions())?>",
246 lang : "<?= $arConfig['lang']?>",
247 description_id : '<?= CUtil::JSEscape($arConfig['description_id'] ?? null)?>'
248 };
249
250 window.oBXMedialib = new BXMediaLib(oConfig);
251 oBXMedialib.Open();
252 <?endif;?>
253 };
254 </script>
255 <?
256 }
257 else
258 {
259 echo '<font color="#FF0000">'.htmlspecialcharsbx($strWarn).'</font>';
260 }
261 }
262
263 public static function AttachJSScripts()
264 {
265 if(!defined("BX_B_MEDIALIB_SCRIPT_LOADED"))
266 {
267 define("BX_B_MEDIALIB_SCRIPT_LOADED", true);
268?>
269BX.loadScript("/bitrix/js/main/file_dialog.js?v=<?=@filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/js/main/file_dialog.js')?>");
270<?
271 }
272 }
273
274 public static function AppendLangMessages()
275 {
276?>
277if (typeof ML_MESS === "undefined")
278{
279 var ML_MESS =
280 {
281 AccessDenied : '<?= GetMessageJS('ML_ACCESS_DENIED')?>',
282 SessExpired : '<?= GetMessageJS('ML_SESS_EXPIRED')?>',
283 DelCollection : '<?= GetMessageJS('ML_DEL_COLLECTION')?>',
284 DelItem : '<?= GetMessageJS('ML_DEL_ITEM')?>',
285 DelCollectionConf : '<?= GetMessageJS('ML_DEL_COLLECTION_CONFIRM')?>',
286 DelItemConf : '<?= GetMessageJS('ML_DEL_ITEM_CONFIRM')?>',
287 EditCollection : '<?= GetMessageJS('ML_EDIT_COLLECTION')?>',
288 EditItem : '<?= GetMessageJS('ML_EDIT_ITEM')?>',
289 NewCollection : '<?= GetMessageJS('ML_NEW_COLLECTION')?>',
290 Collection : '<?= GetMessageJS('ML_COLLECTION')?>',
291 ColLocEr : '<?= GetMessageJS('ML_COL_LOC_ER')?>',
292 ColLocEr2 : '<?= GetMessageJS('ML_COL_LOC_ER2')?>',
293 Item : '<?= GetMessageJS('ML_ITEM')?>',
294 NewItem : '<?= GetMessageJS('ML_NEW_ITEM')?>',
295 DelColFromItem : '<?= GetMessageJS('ML_DEL_COL2ITEM')?>',
296 ItemNoColWarn : '<?= GetMessageJS('ML_COL2ITEM_WARN')?>',
297 DateModified : '<?= GetMessageJS('ML_DATE_MODIFIED')?>',
298 FileSize : '<?= GetMessageJS('ML_FILE_SIZE')?>',
299 ImageSize : '<?= GetMessageJS('ML_IMAGE_SIZE')?>',
300 CheckedColTitle : '<?= GetMessageJS('ML_CHECKED_COL_TITLE')?>',
301 ItSourceError : '<?= GetMessageJS('ML_SOURCE_ERROR')?>',
302 ItFileSizeError : '<?= GetMessageJS('ML_FILESIZE_ERROR')?>',
303 ItNameError : '<?= GetMessageJS('ML_NAME_ERROR')?>',
304 ItCollsError : '<?= GetMessageJS('ML_COLLS_ERROR')?>',
305 ColNameError : '<?= GetMessageJS('ML_COL_NAME_ERROR')?>',
306 DelItConfTxt : '<?= GetMessageJS('ML_DEL_CONF_TEXT')?>',
307 DelItB1 : '<?= GetMessageJS('ML_DEL_IT_B1')?>',
308 DelItB2 : '<?= GetMessageJS('ML_DEL_IT_B2')?>',
309 CollAccessDenied : '<?= GetMessageJS('ML_COLL_ACCESS_DENIED')?>',
310 CollAccessDenied2 : '<?= GetMessageJS('ML_COLL_ACCESS_DENIED2')?>',
311 CollAccessDenied3: '<?= GetMessageJS('ML_COLL_ACCESS_DENIED3')?>',
312 CollAccessDenied4: '<?= GetMessageJS('ML_COLL_ACCESS_DENIED4')?>',
313 BadSubmit: '<?= GetMessageJS('ML_BAD_SUBMIT')?>',
314 ItemExtError: '<?= GetMessageJS('ML_ITEM_EXT_ERROR')?>',
315 EditItemError: '<?= GetMessageJS('ML_EDIT_ITEM_ERROR')?>',
316 SearchResultEx: '<?= GetMessageJS('ML_SEARCH_RESULT_EX')?>',
317 DelElConfirm: '<?= GetMessageJS('ML_DEL_EL_CONFIRM')?>',
318 DelElConfirmYes: '<?= GetMessageJS('ML_DEL_EL_CONFIRM_YES')?>',
319 SearchDef: '<?= GetMessageJS('ML_SEARCH_DEF')?>',
320 NoResult: '<?= GetMessageJS('ML_SEARCH_NO_RESULT')?>',
321 ViewItem : '<?= GetMessageJS('ML_VIEW_ITEM')?>',
322 FileExt : '<?= GetMessageJS('ML_FILE_EXT')?>',
323 CheckExtTypeConf : '<?= GetMessageJS('ML_CHECK_TYPE_EXT_CONF')?>'
324 };
325}
326<?
327 }
328
329 public static function AppendLangMessagesEx()
330 {
331?>
332ML_MESS.Edit = '<?= GetMessageJS('ML_EDIT')?>';
333ML_MESS.Delete = '<?= GetMessageJS('ML_DELETE')?>';
334ML_MESS.Access = '<?= GetMessageJS('ML_ACCESS')?>';
335ML_MESS.AccessTitle = '<?= GetMessageJS('ML_ACCESS_TITLE')?>';
336
337ML_MESS.AddElement = '<?= GetMessageJS('ML_ADD_ELEMENT')?>';
338ML_MESS.AddElementTitle = '<?= GetMessageJS('ML_ADD_ELEMENT_TITLE')?>';
339ML_MESS.AddCollection = '<?= GetMessageJS('ML_ADD_COLLECTION')?>';
340ML_MESS.AddCollectionTitle = '<?= GetMessageJS('ML_ADD_COLLECTION_TITLE')?>';
341ML_MESS.MultiDelConfirm = '<?= GetMessageJS('ML_MULTI_DEL_CONFIRM')?>';
342ML_MESS.Decreased = '<?= GetMessageJS('ML_DECREASED')?>';
343
344ML_MESS.ChangeType = '<?= GetMessageJS('ML_CHANGE_TYPE')?>';
345ML_MESS.ChangeTypeTitle = '<?= GetMessageJS('ML_CHANGE_TYPE_TITLE')?>';
346ML_MESS.ChangeTypeError = '<?= GetMessageJS('ML_CHANGE_TYPE_ERROR')?>';
347ML_MESS.ChangeTypeChildConf = '<?= GetMessageJS('ML_CHANGE_TYPE_CHILD_CONF')?>';
348ML_MESS.Save = '<?= GetMessageJS('ML_SAVE')?>';
349<?
350 }
351
352 public static function Start($Params)
353 {
354 $Params['bReadOnly'] = false;
355 CMedialib::BuildDialog($Params);
356
357 // TODO: Check access
358 ?>#ML_SUBDIALOGS_BEGIN#<?
359 CMedialib::BuildAddCollectionDialog($Params);
360 CMedialib::BuildAddItemDialog($Params);
361 CMedialib::BuildConfirmDialog($Params);
362 CMedialib::BuildViewItemDialog($Params);
363 $exParams = array('types' => $Params['types']);
364 ?>#ML_SUBDIALOGS_END#
365
366 <script><?CMedialib::GetCollections($exParams);?></script>
367 <?
368 }
369
370 public static function BuildDialog($Params)
371 {
372 ?>
373 #ML_MAIN_DIALOG_BEGIN#
374 <form name="medialib_form"><table id="ml_frame" class="ml-frame"><tr>
375 <td class="ml-title-cell">
376 <table onmousedown="jsFloatDiv.StartDrag(arguments[0], document.getElementById('bxmedialib'));"><tr><td style="width: 10px; padding-left: 3px;"><img class="ml-iconkit ml-dd-dot" src="/bitrix/images/1.gif" /></td><td class="ml-diad-title" id="ml_diag_title"><?=GetMessage('ML_MEDIALIB')?></td><td id="bxml_close" class="ml-close" title="<?=GetMessage('ML_CLOSE')?>"><img src="/bitrix/images/1.gif"></td></tr></table>
377 </td></tr>
378 <tr><td class="ml-content-cell">
379 <div class="ml-head-cont" id="ml_head_cont">
380 <table><tr><td class="ml-left">
381 <div class="ml-breadcrumbs" id="ml_breadcrumbs"></div>
382 </td><td class="ml-right">
383 <input class="ml-search ml-search-empty" id="medialib_search" type="text" value="<?=GetMessage('ML_SEARCH_DEF')?>"/>
384 </td></tr></table>
385 </div>
386 <div class="ml-left-sec" id="ml_left_cont">
387 <div id="ml_type_cont" class="ml-type-cont"></div>
388 <div class="ml-collect-cont" id="ml_coll_cont"><div class="ml-no-colls"> - <?= GetMessage('ML_NO_COLS')?> - </div></div>
389 </div>
390 <div class="ml-right-sec" id="ml_right_cont">
391 <div class="ml-list-cont" id="ml_list_cont"><div class="ml-list-noitems"> - <?= GetMessage('ML_NO_ITEMS')?> - </div></div>
392 <div class="ml-info-cont" id="ml_info_wnd">
393 <div class="ml-info-noinfo"> - <?= GetMessage('ML_NO_ITEM_INFO')?> - </div>
394 <table class="ml-info-tbl">
395 <tr>
396 <td colSpan="2">
397 <div class="ml-info-name" id="ml_info_name"></div>
398 <div class="ml-info-collections" id="ml_info_colls"></div>
399 </td>
400 </tr>
401 <tr>
402 <td style="width: 50%;">
403 <span><?= GetMessage('ML_KEYWORDS')?>:</span>
404 <span id="ml_info_keys"></span>
405 </td>
406 <td rowSpan="2" style="width: 50%; vertical-align: top;">
407 <span><?= GetMessage('ML_DESC')?>:</span>
408 <div class="ml-info-desc" id="ml_info_desc"></div>
409 </td>
410 </tr>
411 <tr>
412 <td style="vertical-align: top;">
413 <div class="ml-info-details" id="ml_info_details"></div>
414 </td>
415 </tr>
416 </table>
417 </div>
418 </div>
419 <div class="ml-buttons-cont" id="ml_but_cont">
420 <table><tr>
421 <td class="ml-left">
422 <?if (!$Params['bReadOnly']):?>
423 <a id="ml_add_collection" href="javascript:void(0)" title="<?=GetMessage('ML_ADD_COLLECTION_TITLE')?>" class="ml-add-el-link"><img src="/bitrix/images/1.gif" /><?=GetMessage('ML_ADD_COLLECTION')?></a>
424
425 <a id="ml_add_item" href="javascript:void(0)" title="<?=GetMessage('ML_ADD_ELEMENT_TITLE')?>" class="ml-add-el-link"><img src="/bitrix/images/1.gif" /><?=GetMessage('ML_ADD_ELEMENT')?></a>
426 <?endif;?>
427 </td><td class="ml-right">
428 <input id="medialib_but_save" type="button" value="<?=GetMessage('ML_SELECT')?>" />
429 <input id="medialib_but_cancel" type="button" value="<?=GetMessage('ML_CANCEL')?>" />
430 </td></tr></table>
431 </div>
432 </td></tr>
433 </table>
434 </form>
435 <div id="bxml_resizer" class="ml-resizer"></div>
436 #ML_MAIN_DIALOG_END#
437 <?
438 }
439
440 public static function BuildAddCollectionDialogAdmin($Params)
441 {
442 ?>
443 <div id="mlsd_coll" class="mlsd_admin">
444 <table>
445 <tr><td><b><?=GetMessage('ML_NAME')?>:</b></td><td><input type="text" id="mlsd_coll_name" /></td></tr>
446 <tr><td style="vertical-align: top;"><?=GetMessage('ML_DESC')?>:</td><td><textarea id="mlsd_coll_desc" rows="2" cols="21" style="resize: vertical;"></textarea></td></tr>
447 <tr><td><?=GetMessage('ML_KEYWORDS')?>:</td><td><input type="text" id="mlsd_coll_keywords" /></td></tr>
448 <tr><td><?=GetMessage('ML_PLACE')?>:</td>
449 <td><select id="mlsd_coll_parent" style="width: 190px;"><option value="0"><?= GetMessage('ML_UPPER_LEVEL')?></option></select></td></tr>
450 </table>
451 </div>
452 <?
453 }
454
455 public static function BuildAddCollectionDialog($Params)
456 {
457 ?>
458 <div id="mlsd_coll" class="mlsd"><table class="mlsd-frame"><tr>
459 <td class="ml-title-cell">
460 <table onmousedown="jsFloatDiv.StartDrag(arguments[0], document.getElementById('mlsd_coll'));"><tr><td style="width: 10px; padding-left: 3px;"><img class="ml-iconkit ml-dd-dot" src="/bitrix/images/1.gif" /></td><td class="ml-diad-title"><span id="mlsd_coll_title"></span></td><td id="mlsd_coll_close" class="ml-close" title="<?=GetMessage('ML_CLOSE')?>"><img src="/bitrix/images/1.gif"></td></tr></table>
461 </td></tr>
462 <tr><td class="ml-content-cell">
463 <table class="mlsd-fields-tbl">
464 <tr><td><b><?=GetMessage('ML_NAME')?>:</b></td><td><input type="text" id="mlsd_coll_name" /></td></tr>
465 <tr><td style="vertical-align: top;"><?=GetMessage('ML_DESC')?>:</td><td><textarea id="mlsd_coll_desc" rows="2" cols="21" style="resize: vertical;"></textarea></td></tr>
466 <tr><td><?=GetMessage('ML_KEYWORDS')?>:</td><td><input type="text" id="mlsd_coll_keywords" /></td></tr>
467 <tr><td><?=GetMessage('ML_PLACE')?>:</td>
468 <td><select id="mlsd_coll_parent" style="width: 190px;"><option value="0"><?= GetMessage('ML_UPPER_LEVEL')?></option></select></td></tr>
469 </table>
470 </td></tr>
471 <tr><td class="ml-buttons-cell">
472 <input id="mlsd_coll_save" type="button" value="<?=GetMessage('ML_SAVE')?>">
473 <input id="mlsd_coll_cancel" type="button" value="<?=GetMessage('ML_CANCEL')?>">
474 </td></tr>
475 </table>
476 </div>
477 <?
478 }
479
480 public static function BuildAddItemDialogAdmin($Params)
481 {
482 ?>
483 <div id="mlsd_item" class="mlsd_admin">
484 <table>
485 <tr><td class="ml-content-cell">
486<form name="ml_item_form" action="/bitrix/admin/fileman_medialib.php?action=edit_item&<?=bitrix_sessid_get()?>" onsubmit="return parent.oBXMediaLib.EditItemDialogOnsubmit();" method="post" enctype="multipart/form-data"><table class="mlsd-ifrm-tbl">
487 <tr><td colSpan="2">
488 <div id="mlsd_fname_cont">
489 <b><?=GetMessage('ML_FILE')?>:</b><span style="padding: 0px 15px" id="ml_file_name"></span>
490 </div>
491 <div id="mlsd_load_cont">
492 <b><label for="ml_load_file"><?=GetMessage('ML_FILE')?>:</label></b>
493 <input id="ml_load_file" type="file" name="load_file" style="margin-left: 15px; max-width:250px;">
494 </div>
495 <div id="mlsd_select_cont" style="display: none;">
496 <b><label for="mlsd_item_path"><?=GetMessage('ML_FILE')?>:</label></b>
497 <input type="text" size="25" value="" id="mlsd_item_path" style="margin-left: 15px; width: 280px;" name="item_path">
498 <input type="button" id="mlsd_open_fd" value="..." style="width: 30px;">
499 </div>
500 <div style="text-align: right; padding-right: 20px;">
501 <div style="float: left; text-align: left; margin-top: -2px;">
502 <a id="mlsd_fname_change" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_CHANGE_FILE_TITLE')?>">(<?=GetMessage('ML_CHANGE')?>)</a>
503 <a id="mlsd_fname_change_back" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_CHANGE_UNDO_TITLE')?>">(<?=GetMessage('ML_CHANGE_UNDO')?>)</a>
504 </div>
505 <a id="mlsd_select_fd" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_SELECT_FILE_TITLE')?>"><?=GetMessage('ML_SELECT_FILE')?></a>
506 <a id="mlsd_select_pc" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_LOAD_FILE_TITLE')?>" style="display: none;"><?=GetMessage('ML_LOAD_FILE')?></a>
507 </div>
508 </td></tr>
509 <tr><td><b><label for="mlsd_item_name"><?=GetMessage('ML_NAME')?>:</label></b><br /><input type="text" id="mlsd_item_name" name="item_name"/></td>
510 <td rowSpan="3" style="padding-top: 10px;">
511 <div class="mlsd-prev-cont"><span id="mlsd_no_preview"><?= GetMessage('ML_NO_PREVIEW')?></span><img id="mlsd_item_thumb" src="/bitrix/images/1.gif" /></div>
512 <div class="mlsd-size-cont" id="mlsd_item_size" title="<?=GetMessage('ML_SIZE_IN_PX')?>"></div>
513 </td></tr>
514 <tr>
515 <td style="vertical-align: top;"><label for="mlsd_item_desc"><?=GetMessage('ML_DESC')?>:</label><br />
516 <textarea id="mlsd_item_desc" rows="2" cols="26" name="item_desc"></textarea></td>
517 </tr>
518 <tr><td><label for="mlsd_item_keywords"><?=GetMessage('ML_KEYWORDS')?>:<br /></label><input type="text" id="mlsd_item_keywords" name="item_keywords"/></td></tr>
519 <tr><td colSpan="2">
520 <div class="mlsd-col-cont">
521 <div class="mlsd-col-label"><label for="mlsd_coll_sel"><?=GetMessage('ML_COLLECTIONS')?>:</label></div>
522 <div class="mlsd-col-sel"><select title="<?= GetMessage('ML_ADD_COL2ITEM')?>" id="mlsd_coll_sel"><option value="0"><?= GetMessage('ML_COL_SELECT')?></option></select></div>
523 </div>
524 </td></tr>
525 </table>
526
527 <? /* <input type="hidden" name="MAX_FILE_SIZE" value="1000000000">*/?>
528 <input id="mlsd_item_collections" type="hidden" name="item_collections" value="">
529 <input id="mlsd_item_id" type="hidden" name="id" value="">
530 <input id="mlsd_source_type" type="hidden" name="source_type" value="PC">
531</form>
532 </td></tr>
533 </table>
534 </div>
535 <?
537 (
538 "event" => "mlOpenFileDialog",
539 "arResultDest" => Array("FUNCTION_NAME" => "mlOnFileDialogSave"),
540 "arPath" => Array(),
541 "select" => 'F',
542 "operation" => 'O',// O - open, S - save
543 "showUploadTab" => true,
544 "showAddToMenuTab" => false,
545 "fileFilter" => CMedialib::GetMediaExtentions(),
546 "allowAllFiles" => false,
547 "SaveConfig" => true
548 )
549 );
550 }
551
552 public static function BuildAddItemDialog($Params)
553 {
554 ?>
555 <div id="mlsd_item" class="mlsd"><table class="mlsd-frame"><tr>
556 <td class="ml-title-cell">
557 <table onmousedown="jsFloatDiv.StartDrag(arguments[0], document.getElementById('mlsd_item'));"><tr><td style="width: 10px; padding-left: 3px;"><img class="ml-iconkit ml-dd-dot" src="/bitrix/images/1.gif" /></td><td class="ml-diad-title"><span id="mlsd_item_title"></span></td><td id="mlsd_item_close" class="ml-close" title="<?=GetMessage('ML_CLOSE')?>"><img src="/bitrix/images/1.gif"></td></tr></table>
558 </td></tr>
559 <tr><td class="ml-content-cell">
560 <div id="mlsd_item_upload" style="overflow: hidden;"><iframe class="mlsd-iframe" id="mlsd_iframe_upload" src="javascript:''" frameborder="0"></iframe></div>
561 </td></tr>
562 <tr><td class="ml-buttons-cell">
563 <input id="mlsd_item_save" type="button" value="<?=GetMessage('ML_SAVE')?>">
564 <input id="mlsd_item_cancel" type="button" value="<?=GetMessage('ML_CANCEL')?>">
565 </td></tr>
566 </table>
567 </div>
568 <?
570 (
571 "event" => "mlOpenFileDialog",
572 "arResultDest" => Array("FUNCTION_NAME" => "mlOnFileDialogSave"),
573 "arPath" => Array(),
574 "select" => 'F',
575 "operation" => 'O',// O - open, S - save
576 "showUploadTab" => true,
577 "showAddToMenuTab" => false,
578 "fileFilter" => CMedialib::GetMediaExtentions(),
579 "allowAllFiles" => false,
580 "SaveConfig" => true
581 )
582 );
583 }
584
585 public static function ShowUploadForm($Params)
586 {
587 ?>
588<HTML>
589<HEAD>
590<style>
591 body {margin:0px !important; overflow: hidden;}
592 body *{font-family:Verdana,Arial,Helvetica,sans-serif; font-size: 13px; color: #000;}
593 form {margin:0px !important;}
594 table.mlsd-ifrm-tbl {width: 400px; height: 265px; margin: 3px;}
595 a.mlsd-up-link{text-decoration: none; color: #6E8C9B; font-size: 11px;}
596 table.mlsd-ifrm-tbl input{width: 220px;}
597 div.mlsd-col-cont{height: 70px;}
598 div.mlsd-col-label, div.mlsd-col-sel{font-weight: bold; float: left; padding: 2px; margin: 2px;}
599 div.mlsd-col-sel select{width: 90px; display: block; margin-top: -2px;}
600 div.mlsd-ch-col{float: left; border: 1px solid #6E8C9B; width: 80px; height: 20px; padding: 0px; overflow: hidden; margin: 2px; position: relative; background: url(/bitrix/images/fileman/medialib/group_bg.gif) repeat-x scroll left top;}
601 div.mlsd-ch-col span{white-space: nowrap; font-size: 12px !important; display: block; margin: 2px 0 0 2px;}
602 div.mlsd-ch-col img.ml-col-del{width: 17px; height: 18px; background-image: url(/bitrix/images/fileman/medialib/iconkit.gif); position: absolute; display: none; background-position: 0px -60px; top: 1px; right: 1px; cursor: pointer;}
603 div.col-over img.ml-col-del{display: block !important;}
604 div.mlsd-prev-cont{width: 150px; height: 140px; border: 1px solid #6E8C9B; text-align: center;}
605 div.mlsd-prev-cont img{margin: 2px;}
606 div.mlsd-prev-cont span{color: #6E8C9B; font-size: 11px; display: block; padding: 2px;}
607 select option.opt-checked{color: #808080; font-weight: bold; background-color: #F2F6F8;}
608 div.mlsd-size-cont{text-align: center; color: #808080;}
609</style>
610</HEAD>
611<BODY style="margin:0px !important;">
612<form name="ml_item_form" action="/bitrix/admin/fileman_medialib.php?action=edit_item&<?=bitrix_sessid_get()?>" onsubmit="return parent.oBXMediaLib.EditItemDialogOnsubmit();" method="post" enctype="multipart/form-data"><table class="mlsd-ifrm-tbl">
613 <tr><td colSpan="2">
614 <div id="mlsd_fname_cont">
615 <b><?=GetMessage('ML_FILE')?>:</b><span style="padding: 0px 15px" id="ml_file_name"></span>
616 </div>
617 <div id="mlsd_load_cont">
618 <b><label for="ml_load_file"><?=GetMessage('ML_FILE')?>:</label></b>
619 <input id="ml_load_file" type="file" name="load_file" style="margin-left: 15px; max-width:250px;">
620 <input id="ml_load_max_size" type="hidden" name="ml_load_max_size" value="<?=CMedialib::getMaximumFileUploadSize()?>">
621 </div>
622 <div id="mlsd_select_cont" style="display: none;">
623 <b><label for="mlsd_item_path"><?=GetMessage('ML_FILE')?>:</label></b>
624 <input type="text" size="25" value="" id="mlsd_item_path" style="margin-left: 15px; width: 280px;" name="item_path">
625 <input type="button" id="mlsd_open_fd" value="..." style="width: 30px;">
626 </div>
627 <div style="text-align: right; padding-right: 20px;">
628 <div style="float: left; text-align: left; margin-top: -2px;">
629 <a id="mlsd_fname_change" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_CHANGE_FILE_TITLE')?>">(<?=GetMessage('ML_CHANGE')?>)</a>
630 <a id="mlsd_fname_change_back" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_CHANGE_UNDO_TITLE')?>">(<?=GetMessage('ML_CHANGE_UNDO')?>)</a>
631 </div>
632 <a id="mlsd_select_fd" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_SELECT_FILE_TITLE')?>"><?=GetMessage('ML_SELECT_FILE')?></a>
633 <a id="mlsd_select_pc" href="javascript:void(0)" class="mlsd-up-link" title="<?=GetMessage('ML_LOAD_FILE_TITLE')?>" style="display: none;"><?=GetMessage('ML_LOAD_FILE')?></a>
634 </div>
635 </td></tr>
636 <tr><td><b><label for="mlsd_item_name"><?=GetMessage('ML_NAME')?>:</label></b><br /><input type="text" id="mlsd_item_name" name="item_name"/></td>
637 <td rowSpan="3" style="padding-top: 10px;">
638 <div class="mlsd-prev-cont"><span id="mlsd_no_preview"><?= GetMessage('ML_NO_PREVIEW')?></span><img id="mlsd_item_thumb" src="/bitrix/images/1.gif" /></div>
639 <div class="mlsd-size-cont" id="mlsd_item_size" title="<?=GetMessage('ML_SIZE_IN_PX')?>"></div>
640 </td></tr>
641 <tr>
642 <td style="vertical-align: top;"><label for="mlsd_item_desc"><?=GetMessage('ML_DESC')?>:</label><br />
643 <textarea id="mlsd_item_desc" rows="2" cols="26" name="item_desc"></textarea></td>
644 </tr>
645 <tr><td><label for="mlsd_item_keywords"><?=GetMessage('ML_KEYWORDS')?>:<br /></label><input type="text" id="mlsd_item_keywords" name="item_keywords"/></td></tr>
646 <tr><td colSpan="2">
647 <div class="mlsd-col-cont">
648 <div class="mlsd-col-label"><label for="mlsd_coll_sel"><?=GetMessage('ML_COLLECTIONS')?>:</label></div>
649 <div class="mlsd-col-sel"><select title="<?= GetMessage('ML_ADD_COL2ITEM')?>" id="mlsd_coll_sel"><option value="0"><?= GetMessage('ML_COL_SELECT')?></option></select></div>
650 </div>
651 </td></tr>
652 </table>
653
654 <? /* <input type="hidden" name="MAX_FILE_SIZE" value="1000000000">*/?>
655 <input id="mlsd_item_collections" type="hidden" name="item_collections" value="">
656 <input id="mlsd_item_id" type="hidden" name="id" value="">
657 <input id="mlsd_source_type" type="hidden" name="source_type" value="PC">
658</form>
659</BODY>
660</HTML>
661<?
662 }
663
664 public static function BuildConfirmDialog($Params)
665 {
666 ?>
667 <div id="ml_colfirm_dialog" class="mlsd mlsd-confirm">
668 <div id="ml_confd_text" class="ml-confd-text"></div>
669 <input id="ml_confd_b1" type="button" value="b1" />
670 <input id="ml_confd_b2" type="button" value="b2" />
671 <input id="ml_confd_cancel" type="button" value="<?=GetMessage('ML_CANCEL')?>" />
672 </div>
673 <?
674 }
675
676 public static function BuildViewItemDialog($Params)
677 {
678 ?>
679 <div id="mlsd_view_item" class="mlsd"><table class="mlsd-frame"><tr>
680 <td class="ml-title-cell">
681 <table onmousedown="jsFloatDiv.StartDrag(arguments[0], document.getElementById('mlsd_view_item'));"><tr><td style="width: 10px; padding-left: 3px;"><img class="ml-iconkit ml-dd-dot" src="/bitrix/images/1.gif" /></td><td class="ml-diad-title"><?= GetMessage('ML_VIEW_ITEM')?></td><td id="mlsd_viewit_close" class="ml-close" title="<?=GetMessage('ML_CLOSE')?>"><img src="/bitrix/images/1.gif"></td></tr></table>
682 </td></tr>
683 <tr><td class="ml-content-cell">
684 <div id="mlsd_info_cont" class="mlvi-info-cnt">
685 <table class="mlvi-info-tbl">
686 <tr><td><div class="mlvi-info-name" id="mlvi_info_name"></div></td></tr>
687 <tr><td><a id="mlvi_info_link" href="javascript: void(0);" title="<?= GetMessage("ML_DOWNLOAD_LINK")?>"><?= GetMessage('ML_DOWNLOAD_LINK')?></a></td></tr>
688 <tr><td><a id="mlvi_info_copy_link" href="javascript: void(0);" title="<?= GetMessage("ML_DOWNLOAD_LINK_TITLE")?>"><?= GetMessage("ML_DOWNLOAD_LINK_TITLE")?></a></td></tr>
689 <tr><td><input style="display:none;" id="mlvi_info_copy_input" value></td></tr>
690 <tr><td class="mlvi-new-row">
691 <div class="mlvi-info-details" id="mlvi_info_details"></div>
692 </td></tr>
693 <tr><td class="small-grey" id="mlvi_info_colls">
694 <span><?= GetMessage('ML_COLLECTIONS')?>: </span>
695 </td></tr>
696 <tr>
697 <td class="small-grey" ><span><?= GetMessage('ML_KEYWORDS')?>:</span>
698 <span id="mlvi_info_keys"></span></td>
699 </tr>
700 <tr><td class="mlvi-new-row">
701 <span style="font-size: 11px !important;"><?= GetMessage('ML_DESC')?>:</span>
702 <div class="ml-info-desc" id="mlvi_info_desc"></div>
703 </td></tr>
704 </table>
705 </div>
706 <div id="mlsd_item_cont" class="mlvi-img-cnt"><?/*<img id="mlsd_viewit_img" src="/bitrix/images/1.gif" />*/?></div>
707 </td></tr>
708 <tr><td class="ml-buttons-cell">
709 <input id="mlsd_viewit_del" type="button" value="<?=GetMessage('ML_DELETE')?>">
710 <input id="mlsd_viewit_edit" type="button" value="<?=GetMessage('ML_EDIT')?>">
711 <input id="mlsd_viewit_cancel" type="button" value="<?=GetMessage('ML_CANCEL')?>">
712 </td></tr>
713 </table>
714 </div>
715 <?
716 }
717
718 public static function BuildChangeType($Params)
719 {
720 ?>
721 <div id="mlsd_change_type" class="mlsd"><table class="mlsd-frame"><tr>
722 <td class="ml-title-cell">
723 <table onmousedown="jsFloatDiv.StartDrag(arguments[0], document.getElementById('mlsd_change_type'));"><tr><td style="width: 10px; padding-left: 3px;"><img class="ml-iconkit ml-dd-dot" src="/bitrix/images/1.gif" /></td><td class="ml-diad-title"><?= GetMessage('ML_CHANGE_TYPE_DIALOG')?></td><td id="mlsd_chtype_close" class="ml-close" title="<?=GetMessage('ML_CLOSE')?>"><img src="/bitrix/images/1.gif"></td></tr></table>
724 </td></tr>
725 <tr><td class="ml-content-cell">
726 <table class="mlsd-fields-tbl">
727 <tr>
728 <td><b><?=GetMessage('ML_CHOOSE_TYPE')?>:</b></td>
729 <td><select id="mlsd_chtype_type" style="width: 190px;"><option value="none">- <?= GetMessage('ML_COL_SELECT')?> -</option></select></td>
730 </tr>
731 <tr>
732 <td><?=GetMessage('ML_PLACE')?>:</td>
733 <td><select id="mlsd_chtype_parent" style="width: 190px;"><option value="0"><?= GetMessage('ML_UPPER_LEVEL')?></option></select></td>
734 </tr>
735 </table>
736 </td></tr>
737 <tr><td class="ml-buttons-cell">
738 <input id="mlsd_chtype_save" type="button" value="<?=GetMessage('ML_SAVE')?>">
739 <input id="mlsd_chtype_cancel" type="button" value="<?=GetMessage('ML_CANCEL')?>">
740 </td></tr>
741 </table>
742 </div>
743 <?
744 }
745
746 public static function ShowJS()
747 {
748 ?>
749 BX.loadCSS("/bitrix/js/fileman/medialib/medialib.css");
750 if (!window.jsUtils && top.jsUtils)
751 window.jsUtils = top.jsUtils;
752 if (!window.jsUtils)
753 BX.loadScript('/bitrix/js/main/utils.js?v=<?=@filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/js/main/utils.js')?>');
754
755 if (!window.CHttpRequest && top.CHttpRequest)
756 window.CHttpRequest = top.CHttpRequest;
757 if (!window.CHttpRequest)
758 BX.loadScript('/bitrix/js/main/admin_tools.js?v=<?=@filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/js/main/admin_tools.js')?>');
759
760 if (!window.jsAjaxUtil && top.jsAjaxUtil)
761 window.jsAjaxUtil = top.jsAjaxUtil;
762 if (!window.jsAjaxUtil)
763 BX.loadScript('/bitrix/js/main/ajax.js?v=<?=@filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/js/main/ajax.js')?>');
764 <?
765 }
766
767 public static function GetCollections(&$exParams)
768 {
769 $bCountPermissions = isset($exParams['bCountPermissions']) && $exParams['bCountPermissions'] === true;
770 $exParams['arCountPerm'] = array('new_col' => 0, 'edit' => 0, 'del' => 0, 'new_item' => 0, 'edit_item' => 0, 'del_item' => 0, 'access' => 0);
771
772 ?>window.MLCollections = [<?
773 $arCol = CMedialibCollection::GetList(array('arFilter' =>
774 array(
775 'ACTIVE' => 'Y',
776 'TYPES' => $exParams['types']
777 )
778 ));
779 $commonEdit = false;
780 $commonItemEdit = false;
781 $arResCol = array();
782 for ($i = 0, $l = count($arCol); $i < $l; $i++)
783 {
784 if (!CMedialibCollection::IsViewable($arCol[$i], $arCol))
785 continue;
786
787 $id = $arCol[$i]['ID'];
788 $arCol[$i]['PERMISSIONS'] = array(
789 'new_col' => CMedialib::CanDoOperation('medialib_new_collection', $arCol[$i]['ID']),
790 'edit' => CMedialib::CanDoOperation('medialib_edit_collection', $arCol[$i]['ID']),
791 'del' => CMedialib::CanDoOperation('medialib_del_collection', $arCol[$i]['ID']),
792 'new_item' => CMedialib::CanDoOperation('medialib_new_item', $arCol[$i]['ID']),
793 'edit_item' => CMedialib::CanDoOperation('medialib_edit_item', $arCol[$i]['ID']),
794 'del_item' => CMedialib::CanDoOperation('medialib_del_item', $arCol[$i]['ID']),
795 'access' => CMedialib::CanDoOperation('medialib_access', $arCol[$i]['ID'])
796 );
797
798 $accStr = '';
799 foreach($exParams['arCountPerm'] as $key => $el)
800 {
801 if ($bCountPermissions)
802 $exParams['arCountPerm'][$key] += intval($arCol[$i]['PERMISSIONS'][$key]);
803 $accStr .= $key.": '".$arCol[$i]['PERMISSIONS'][$key]."', ";
804 }
805 $accStr = rtrim($accStr, ' ,');
806 ?>
807{
808 id: <?= $arCol[$i]['ID']?>,
809 name: '<?= CMedialib::Escape($arCol[$i]['NAME'])?>',
810 desc: '<?= CMedialib::Escape($arCol[$i]['DESCRIPTION'])?>',
811 date: '<?= $arCol[$i]['DATE_UPDATE']?>',
812 keywords: '<?= CMedialib::Escape($arCol[$i]['KEYWORDS'])?>',
813 parent: <?= intval($arCol[$i]['PARENT_ID']) > 0 ? intval($arCol[$i]['PARENT_ID']) : '0'?>,
814 access: {<?= $accStr?>},
815 type: '<?= $arCol[$i]['ML_TYPE']?>'
816}
817 <?
818 if ($i != $l - 1)
819 echo ',';
820 $arResCol[] = $arCol[$i];
821 }
822 ?>];<?
823 return $arResCol;
824 }
825
826 public static function DelCollection($id, $arIds = [])
827 {
828 if (!CMedialib::CanDoOperation('medialib_del_collection', $id))
829 {
830 return false;
831 }
832
833 if (is_array($arIds))
834 {
835 for($i = 0, $l = count($arIds); $i < $l; $i++)
836 {
837 if (CMedialib::CanDoOperation('medialib_del_collection', $arIds[$i]))
838 {
839 CMedialibCollection::Delete($arIds[$i], false);
840 }
841 }
842 }
843
844 return CMedialibCollection::Delete($id);
845 }
846
847 public static function EditCollection($Params)
848 {
849 if ($Params['id'] && !CMedialib::CanDoOperation('medialib_edit_collection', $Params['id']) ||
850 !$Params['id'] && !CMedialib::CanDoOperation('medialib_new_collection', $Params['parent']))
851 return;
852
853 return CMedialibCollection::Edit(array(
854 'arFields' => array(
855 'ID' => $Params['id'],
856 'NAME' => $Params['name'],
857 'DESCRIPTION' => $Params['desc'],
858 'OWNER_ID' => $GLOBALS['USER']->GetId(),
859 'PARENT_ID' => $Params['parent'],
860 'KEYWORDS' => $Params['keywords'],
861 'ACTIVE' => "Y",
862 'ML_TYPE' => $Params['type']
863 )
864 ));
865 }
866
867 public static function EditItem($Params)
868 {
869 $bOpName = $Params['id'] ? 'medialib_edit_item' : 'medialib_new_item';
870 $arCols_ = explode(',', $Params['item_collections']);
871 $arCols = array();
872 for ($i = 0, $l = count($arCols_); $i < $l; $i++)
873 {
874 if (intval($arCols_[$i]) > 0 && CMedialib::CanDoOperation($bOpName, $arCols_[$i])) // Check access
875 $arCols[] = intval($arCols_[$i]);
876 }
877
878 if (count($arCols) > 0)
879 {
880 if ($Params['source_type'] == 'PC')
881 $Params['path'] = false;
882 else if($Params['source_type'] == 'FD')
883 $Params['file'] = false;
884
885 $res = CMedialibItem::Edit(array(
886 'file' => $Params['file'],
887 'path' => $Params['path'],
888 'arFields' => array(
889 'ID' => $Params['id'],
890 'NAME' => $Params['name'],
891 'DESCRIPTION' => $Params['desc'],
892 'KEYWORDS' => $Params['keywords']
893 ),
894 'arCollections' => $arCols
895 ));
896
897 if ($res):
898
899 if (!isset($res['DATE_UPDATE']) && isset($res['TIMESTAMP_X']))
900 $res['DATE_UPDATE'] = $res['TIMESTAMP_X'];
901 ?>
902 <script>
903 top.bx_req_res = {
904 id: <?=intval($res['ID'])?>,
905 name: '<?= CMedialib::Escape($res['NAME'])?>',
906 desc: '<?= CMedialib::Escape($res['DESCRIPTION'])?>',
907 keywords: '<?= CMedialib::Escape($res['KEYWORDS'])?>',
908 <?if (isset($res['FILE_NAME'])):?>file_name: '<?= CMedialib::Escape($res['FILE_NAME'])?>',<?endif;?>
909 <?if (isset($res['DATE_UPDATE'])):?>date_mod: '<?= CMedialib::GetUsableDate($res['DATE_UPDATE'])?>',<?endif;?>
910 <?if (isset($res['FILE_SIZE'])):?>file_size: '<?= CMedialib::GetUsableSize($res['FILE_SIZE'])?>',<?endif;?>
911 <?if (isset($res['THUMB_PATH'])):?>thumb_path: '<?= CMedialib::Escape($res['THUMB_PATH'])?>',<?endif;?>
912 <?if (isset($res['PATH'])):?>path: '<?= CMedialib::Escape($res['PATH'])?>',<?endif;?>
913 <?if (isset($res['TYPE'])):?>type: '<?= $res['TYPE']?>',<?endif;?>
914 height: <?= (($res['HEIGHT'] ?? null) ? $res['HEIGHT'] : '0')?>,
915 width: <?= (($res['WIDTH'] ?? null) ? $res['WIDTH'] : '0')?>
916 };
917
918 top._ml_items_colls = [<?
919 for ($i = 0, $l = count($arCols); $i < $l; $i++)
920 echo $arCols[$i].($i != $l - 1 ? ',' : '');
921 ?>];
922 </script>
923 <? else: ?>
924 <script>top.bx_req_res = false;</script>
925 <?endif;
926 }
927 }
928
929 public static function GetCollectionTree($Params = array())
930 {
931 $arColTree = array();
932 $arColTemp = array();
933 $Collections = array();
934 $arCol = ($Params['menu'] ?? null) ? CMedialibCollection::GetList(array('arFilter' => array('ACTIVE' => 'Y', 'PARENT_ID' => 0))) : CMedialibCollection::GetList(array('arFilter' => array('ACTIVE' => 'Y')));
935 $iter = 0;
936
937 for ($i = 0, $l = count($arCol); $i < $l; $i++)
938 {
939 if (isset($Params['CheckAccessFunk']) && !call_user_func($Params['CheckAccessFunk'], $arCol[$i]['ID']))
940 continue;
941
942 if (!CMedialib::_buildCollection($arCol[$i], $i, $arColTree, $Collections, $Params))
943 $arColTemp[] = array($arCol[$i], $i);
944 }
945
946 while(count($arColTemp) > 0 && $iter < 50)
947 {
948 $newAr = array();
949 for ($i = 0, $l = count($arColTemp); $i < $l; $i++)
950 {
951 if (isset($Params['CheckAccessFunk']) && !call_user_func($Params['CheckAccessFunk'], $arCol[$i]['ID']))
952 continue;
953
954 if (!CMedialib::_buildCollection($arColTemp[$i][0], $arColTemp[$i][1], $arColTree, $Collections, $Params))
955 $newAr[] = $arColTemp[$i];
956 }
957 $arColTemp = $newAr;
958 $iter++;
959 }
960
961 if (($Params['checkByType'] ?? null) && $Params['typeId'] > 0)
962 {
963 $arType = CMedialib::GetTypeById($Params['typeId']);
964 if ($arType)
965 {
966 foreach ($Collections as $id => $col)
967 {
968 // Del collection escription if it has another type
969 if (!CMedialib::CompareTypesEx($Collections[$id]['ML_TYPE'], $arType))
970 unset($Collections[$id]);
971 }
972 }
973 }
974
975 return array('arColTree' => $arColTree, 'Collections' => $Collections);
976 }
977
978 public static function _buildCollection($Col, $ind, &$arColTree, &$Collections, $Params = array())
979 {
980 if (($Params['CHECK_ACCESS'] ?? null) === true && !CMedialib::CanDoOperation('medialib_view_collection', $Col['ID']))
981 return true;
982
983 if (!$Col['PARENT_ID']) // Root element
984 $arColTree[] = array('id' => $Col['ID'], 'child' => array());
985 else if ($Collections[$Col['PARENT_ID']])
986 CMedialib::_findChildInColTree($arColTree, $Col['PARENT_ID'], $Col['ID']);
987 else
988 return false;
989
990 $Collections[$Col['ID']] = $Col;
991 return true;
992 }
993
994 public static function _findChildInColTree(&$arr, $id, $colId)
995 {
996 for ($i = 0, $l = count($arr); $i < $l; $i++)
997 {
998 if ($arr[$i]['id'] == $id)
999 {
1000 $arr[$i]['child'][] = array('id' => $colId, 'child' => array());
1001 return true;
1002 }
1003 else if (count($arr[$i]['child']) > 0)
1004 {
1005 if (CMedialib::_findChildInColTree($arr[$i]['child'], $id, $colId))
1006 return true;
1007 }
1008 }
1009 return false;
1010 }
1011
1012 public static function _BuildCollectionsSelectOptions($Collections = false, $arColTree = false, $level = 0, $selected = false)
1013 {
1014 if ($Collections === false && $arColTree === false)
1015 {
1016 $res = CMedialib::GetCollectionTree();
1017 $Collections = $res['Collections'];
1018 $arColTree = $res['arColTree'];
1019 }
1020
1021 $str = '';
1022 for ($i = 0, $l = count($arColTree); $i < $l; $i++)
1023 {
1024 //if ($type !== false && )
1025 $col = $Collections[$arColTree[$i]['id']] ?? null;
1026 if (!is_array($col))
1027 continue;
1028 $html = str_repeat(" . ", $level);
1029 $s = ($selected !== false && $selected == $arColTree[$i]['id']) ? ' selected' : '';
1030 $str .= '<option value="'.$arColTree[$i]['id'].'"'.$s.'>'.$html.htmlspecialcharsex($col['NAME']).'</option>';
1031
1032 if (count($arColTree[$i]['child']))
1033 $str .= CMedialib::_BuildCollectionsSelectOptions($Collections, $arColTree[$i]['child'], $level + 1, $selected);
1034 }
1035 return $str;
1036 }
1037
1038 public static function GetItems($Params)
1039 {
1040 $arCollections = array();
1041 if (!CMedialib::CanDoOperation('medialib_view_collection', $Params['collectionId']))
1042 return false;
1043
1044 if (isset($Params['collectionId']) && $Params['collectionId'] > 0)
1045 $arCollections[] = $Params['collectionId'];
1046
1047 $arItems = CMedialibItem::GetList(array(
1048 'arCollections' => $arCollections
1049 ));
1050
1051 ?>
1052 <script>
1053 window.MLItems[<?=$Params['collectionId']?>] = [<?
1054 for ($i = 0, $l = count($arItems); $i < $l; $i++)
1055 {
1056 ?>
1057 {
1058 id: <?=intval($arItems[$i]['ID'])?>,
1059 name: '<?= CMedialib::Escape($arItems[$i]['NAME'])?>',
1060 desc: '<?= CMedialib::Escape($arItems[$i]['DESCRIPTION'])?>',
1061 keywords: '<?= CMedialib::Escape($arItems[$i]['KEYWORDS'])?>',
1062 file_name: '<?= CMedialib::Escape($arItems[$i]['FILE_NAME'])?>',
1063 date_mod: '<?= CMedialib::GetUsableDate($arItems[$i]['DATE_UPDATE2'])?>',
1064 height: <?= ($arItems[$i]['HEIGHT'] ? $arItems[$i]['HEIGHT'] : '0')?>,
1065 width: <?= ($arItems[$i]['WIDTH'] ? $arItems[$i]['WIDTH'] : '0')?>,
1066 file_size: '<?= CMedialib::GetUsableSize($arItems[$i]['FILE_SIZE'])?>',
1067 thumb_path: '<?= CMedialib::Escape($arItems[$i]['THUMB_PATH'] ?? '')?>',
1068 path: '<?= CMedialib::Escape($arItems[$i]['PATH'])?>',
1069 path_external: '<?= CMedialib::Escape($arItems[$i]['PATH_EXTERNAL'])?>',
1070 type: '<?= $arItems[$i]['TYPE']?>'
1071 }
1072 <?
1073 if ($i != $l - 1)
1074 echo ',';
1075 }
1076 ?>];
1077 </script>
1078 <?
1079 }
1080
1081 public static function DelItem($id, $bCurrent = false, $colId = false)
1082 {
1083 return CMedialibItem::Delete($id, $bCurrent, $colId);
1084 }
1085
1086 public static function DeleteThumbnails()
1087 {
1088 CFileman::DeleteEx(BX_PERSONAL_ROOT."/tmp/medialibrary");
1089 }
1090
1091 public static function GetItemCollectionList($Params)
1092 {
1093 if(!CMedialib::CanDoOperation('medialib_view_collection', 0))
1094 return false;
1095
1096 $ar = CMedialibItem::GetItemCollections($Params);
1097 ?>
1098 <script>
1099 window._ml_items_colls = [<?
1100 for ($i = 0, $l = count($ar); $i < $l; $i++)
1101 echo $ar[$i].($i != $l - 1 ? ',' : '');
1102 ?>];
1103 </script>
1104 <?
1105 }
1106
1107 public static function SaveUserSettings($Params)
1108 {
1109 if ($GLOBALS["USER"]->IsAuthorized())
1110 CUserOptions::SetOption("fileman", "medialib_user_set", intval($Params['width']).','.intval($Params['height']).','.intval($Params['coll_id']));
1111 }
1112
1113 public static function SaveAccessPermissions($colId, $arTaskPerm)
1114 {
1115 global $DB;
1116 $DB->Query("DELETE FROM b_group_collection_task WHERE COLLECTION_ID=".intval($colId));
1117
1118 foreach($arTaskPerm as $group_id => $task_id)
1119 {
1120 $arInsert = $DB->PrepareInsert("b_group_collection_task", array("GROUP_ID" => $group_id, "TASK_ID" => $task_id, "COLLECTION_ID" => intval($colId)));
1121 $strSql = "INSERT INTO b_group_collection_task(".$arInsert[0].") VALUES(".$arInsert[1].")";
1122 $DB->Query($strSql );
1123 }
1124 }
1125
1126 public static function MultiActionDelete($Params = array())
1127 {
1128 global $DB;
1129
1130 if (is_array($Params['Cols']) && count($Params['Cols']) > 0) // Del collections
1131 {
1132 $strCols = "0";
1133 for($i = 0, $l = count($Params['Cols']); $i < $l; $i++)
1134 {
1135 $colId = $Params['Cols'][$i];
1136 if (CMedialib::CanDoOperation('medialib_del_collection', $colId)) // Access
1137 {
1138 $strCols .= ",".intval($colId);
1139 }
1140 }
1141
1142 if ($strCols != "0")
1143 {
1144 $strSql = "DELETE FROM b_medialib_collection WHERE ID in (".$strCols.")";
1145 $z = $DB->Query($strSql);
1146
1147 $strSql = "DELETE FROM b_medialib_collection_item WHERE COLLECTION_ID in (".$strCols.")";
1148 $z = $DB->Query($strSql);
1149 }
1150 }
1151
1152 if (is_array($Params['Items']) && count($Params['Items']) > 0) // Del items
1153 {
1154 foreach($Params['Items'] as $colId => $arItems)
1155 {
1156 if (!CMedialib::CanDoOperation('medialib_del_item', $colId)) // Access
1157 {
1158 return false;
1159 }
1160
1161 $strItems = "0";
1162 for($i = 0, $l = count($arItems); $i < $l; $i++)
1163 {
1164 $strItems .= ",".intval($arItems[$i]);
1165 }
1166
1167 $strSql = "DELETE FROM b_medialib_collection_item WHERE ITEM_ID IN (".$strItems.") AND COLLECTION_ID=".intval($colId);
1168 $z = $DB->Query($strSql);
1169 }
1170 }
1171
1172 CMedialibItem::DeleteEmpty(); // Del all items which are absent in 'b_medialib_collection_item'
1173 return true;
1174 }
1175
1176 public static function ShowBrowseButton($Params = array())
1177 {
1178 $value = isset($Params['value']) ? $Params['value'] : '...';
1179 $buttonId = isset($Params['button_id']) ? $Params['button_id'] : '';
1180 $inputId = isset($Params['id']) ? $Params['id'] : '';
1181 $title = isset($Params['title']) ? $Params['title'] : '';
1182 $event = $Params['event'];
1183 $mode = isset($Params['mode']) ? $Params['mode'] : '';
1184
1185 if (!isset($Params['useMLDefault']))
1186 $useMLDefault = COption::GetOptionString('fileman', "ml_use_default", true);
1187 else
1188 $useMLDefault = $Params['useMLDefault'];
1189
1190 if ($mode == 'file_dialog' || COption::GetOptionString('fileman', "use_medialib", "Y") == "N" || !CMedialib::CanDoOperation('medialib_view_collection', 0))
1191 $mode = 'file_dialog';
1192 else if ($mode == 'medialib' || !$GLOBALS["USER"]->CanDoOperation('fileman_view_file_structure'))
1193 $mode = 'medialib';
1194 else
1195 $mode = 'select';
1196
1197 if (($Params['bReturnResult'] ?? null))
1198 ob_start();
1199
1200 if ($mode == 'medialib' || $mode == 'select')
1201 {
1202 $arMLConfig = $Params['MedialibConfig'];
1203 if (!isset($arMLConfig['event']))
1204 $arMLConfig['event'] = 'BXOpenMLEvent';
1205 CMedialib::ShowDialogScript($arMLConfig);
1206 }
1207
1208 if ($mode == 'medialib')
1209 {
1210 $title = isset($Params['title']) ? $Params['title'] : GetMessage('ML_BR_BUT_ML_TITLE');
1211 ?>
1212 <input id="<?= 'bx_ml_'.$inputId?>" type="button" value="<?= $value?>" title="<?= $title?>" onclick="<?= $arMLConfig['event']?>();"/>
1213 <?
1214 }
1215 elseif ($mode == 'file_dialog')
1216 {
1217 $title = isset($Params['title']) ? $Params['title'] : GetMessage('ML_BR_BUT_FD_TITLE');
1218 ?><input type="button" class="adm-btn" style="float:left;" value="<?= $value?>" id="<?= $inputId?>" title="<?= $title?>" onclick="<?= $Params['event']?>();"/><?
1219 }
1220 else
1221 {
1222 $cid = 'bxmlbut'.$inputId;
1223 ?>
1224
1225<script>
1226<? self::AttachJSScripts();?>
1227if (!window.<?= $cid?>_onclick)
1228{
1229 window.<?= $cid?>_onclick = function (pEl)
1230 {
1231 if (!!pEl.OPENER)
1232 return true;
1233
1234 pEl.OPENER = new BX.COpener({
1235 DIV: pEl,
1236 TYPE: 'click',
1237 MENU: [
1238 {ICONCLASS : 'bxml-empty-icon', DEFAULT: <?= $useMLDefault ? 'true' : 'false'?>, TEXT : '<?= GetMessageJS('ML_BR_BUT_ML')?>', TITLE: '<?= GetMessageJS('ML_BR_BUT_ML_TITLE')?>', ONCLICK: '<?= $arMLConfig['event']?>();'},
1239 {ICONCLASS : 'bxml-empty-icon', DEFAULT: <?= $useMLDefault ? 'false' : 'true'?>, TEXT : '<?= GetMessageJS('ML_BR_BUT_FD')?>',TITLE: '<?= GetMessageJS('ML_BR_BUT_FD_TITLE')?>', ONCLICK: '<?= $event?>();'}
1240 ]
1241 });
1242
1243 pEl.OPENER.Toggle();
1244 }
1245}
1246</script>
1247
1248<div id="<?= $buttonId?>" class="bx-ml-pnbutton">
1249<div class="bx-pn1" title="<?= GetMessage('ML_BR_BUT_ML_TITLE')?>" onclick="<?= ($useMLDefault ? $arMLConfig['event'] : $event)?>();"></div>
1250<div class="bx-pn2" title="<?= GetMessage('ML_BR_BUT_SEL')?>" onclick="<?= $cid?>_onclick(this);"></div>
1251</div>
1252 <?
1253 }
1254
1255 if (($Params['bReturnResult'] ?? null))
1256 {
1257 $s = ob_get_contents();
1258 ob_end_clean();
1259 return $s;
1260 }
1261 }
1262
1263 public static function GetUsableSize($size = 0)
1264 {
1265 $size = intval($size);
1266 if ($size < 1024)
1267 return $size." ".GetMessage('ML_BYTE');
1268
1269 $size = round($size / 1024);
1270 if ($size < 1024)
1271 return $size." K".GetMessage('ML_BYTE');
1272
1273 $size = round($size / 1024);
1274 if ($size < 1024)
1275 return $size." M".GetMessage('ML_BYTE');
1276
1277 return $size;
1278 }
1279
1280 public static function GetUsableDate($date = '')
1281 {
1282 return ConvertDateTime($date, "DD.MM.YYYY HH:MI");
1283 }
1284
1285 public static function GetMediaExtentions($bStr = true)
1286 {
1287 $strExt = COption::GetOptionString('fileman', "ml_media_available_ext", CMedialib::GetDefaultMediaExtentions());
1288
1289 $arExt_ = explode(',', $strExt);
1290
1291 $arTypes = CMedialib::GetTypes();
1292 for($i = 0, $l = count($arTypes); $i < $l; $i++)
1293 $arExt_ = array_merge($arExt_, explode(',', $arTypes[$i]["ext"]));
1294
1295 $arExt = array();
1296 for ($i = 0, $l = count($arExt_); $i < $l; $i++)
1297 {
1298 $ext = mb_strtolower(trim($arExt_[$i], ' .'));
1299 if ($ext <> '' && !in_array($ext, $arExt))
1300 $arExt[] = $ext;
1301 }
1302
1303 if ($bStr)
1304 return implode(",", $arExt);
1305
1306 return $arExt;
1307 }
1308
1309 public static function GetDefaultMediaExtentions()
1310 {
1311 return 'jpg,jpeg,gif,png,flv,mp4,wmv,wma,mp3,ppt';
1312 }
1313
1314 public static function CheckFileExtention($strPath = '', $arExt = false)
1315 {
1316 if (!$arExt)
1317 $arExt = CMedialib::GetMediaExtentions(false);
1318 $ext = mb_strtolower(CFileman::GetFileExtension($strPath));
1319 return in_array($ext, $arExt);
1320 }
1321
1322 public static function Escape($str, $bHtmlSpCh = true)
1323 {
1324 return CUtil::JSEscape($str);
1325 }
1326
1327 public static function SearchItems($Params)
1328 {
1329 if (!CModule::IncludeModule("search"))
1330 return;
1331
1332 $arQuery = array_keys(stemming($Params['query'], LANGUAGE_ID));
1333 $arItems = CMedialibItem::Search($arQuery, $Params['types']);
1334?>
1335<script>
1336window.MLSearchResult = [
1337<?
1338 for ($i = 0, $l = count($arItems); $i < $l; $i++)
1339 {
1340?>
1341{
1342 id: <?=intval($arItems[$i]['ID'])?>,
1343 name: '<?= CMedialib::Escape($arItems[$i]['NAME'])?>',
1344 desc: '<?= CMedialib::Escape($arItems[$i]['DESCRIPTION'])?>',
1345 keywords: '<?= CMedialib::Escape($arItems[$i]['KEYWORDS'])?>',
1346 file_name: '<?= CMedialib::Escape($arItems[$i]['FILE_NAME'])?>',
1347 height: <?= ($arItems[$i]['HEIGHT'] ? $arItems[$i]['HEIGHT'] : '0')?>,
1348 width: <?= ($arItems[$i]['WIDTH'] ? $arItems[$i]['WIDTH'] : '0')?>,
1349 file_size: '<?= CMedialib::GetUsableSize($arItems[$i]['FILE_SIZE'])?>',
1350 date_mod: '<?= CMedialib::GetUsableDate($arItems[$i]['DATE_UPDATE2'])?>',
1351 thumb_path: '<?= CMedialib::Escape($arItems[$i]['THUMB_PATH'] ?? '')?>',
1352 path: '<?= CMedialib::Escape($arItems[$i]['PATH'])?>',
1353 type: '<?= $arItems[$i]['TYPE']?>',
1354 perm: {edit: <?= $arItems[$i]['perm']['edit'] ? 'true' : 'false'?>, del: <?= $arItems[$i]['perm']['del'] ? 'true' : 'false'?>},
1355 collections: <?= count($arItems[$i]['collections']) == 1 ? "['".$arItems[$i]['collections'][0]."']" : CUtil::PhpToJSObject($arItems[$i]['collections'])?>
1356
1357}<?
1358 if ($i != $l - 1)
1359 echo ",\n";
1360 }
1361?>
1362];
1363</script>
1364<?
1365 }
1366
1367 /*
1368 $strInputName //the name of element
1369 $strImageID // the file identifier or path to the file from site root
1370 $showInfo => array(
1371 "IMAGE" => "Y",
1372 "MAX_SIZE" => array("W" => ww, "H" => hh)
1373 "IMAGE_POPUP" => "Y",
1374 "PATH" => "Y",
1375 "DIMENSIONS" => "Y",
1376 "FILE_SIZE" => "Y",
1377 ),
1378 $fileInput => array( // if false then loading from computer don't used
1379 "NAME" => "...", //the name for INPUT has "file" type. For loading from computer. It equals $strInputName for defaults
1380 ["ID" => "...",] //the identifier of INPUT. It equals $strInputName."_file" for defaults with replacement all symbols except a-zA-z0-9_ by _
1381 ["SIZE" => NN,] // optional param, default 35
1382 ["SHOW_INFO" => "Y",] //to show information about image or not. Default not
1383 ["LABEL" => "INPUT title"],
1384 ),
1385 $servInput => array( //if false, then choose file from server not used. Default equals $strInputName
1386 "NAME" => "...", //name for INPUT type of text. For chosing file from server.
1387 ["ID" => "...",] //INPUT identifier.Default equals $strInputName."_serv" with replacement all symbols except a-zA-z0-9_ by _
1388 ["SIZE" => NN,] // optional param, default 35
1389 ["SHOW_INFO" => "Y",] //to show information about image, or not, default not
1390 ["LABEL" => "INPUT title"],
1391 ),
1392 $pathInput => array( //if false, then library not use.
1393 ["NAME" => "NNN",] //INPUT name type text. For selection from media library. Default $strInputName.
1394 ["ID" => "...",] //INPUT identifier. Default equals $strInputName."_path" with replacement all symbols except a-zA-z0-9_ by _
1395 ["SIZE" => NN,] // optional param, default 35
1396 ["LABEL" => "INPUT title"],
1397 ),
1398 $descInput => array( //if false, then the describtion field will not showed.
1399 ["NAME" => "NNN",] //The INPUT's name type of text. File description. Default equals $strInputName."_descr" without array indexes influence.
1400 ["SIZE" => NN,] // optional param, default 35
1401 ["VALUE" => "...",] //Value for file description. if undefined, it will be got from $strImageID
1402 ["LABEL" => "INPUT title"],
1403 ),
1404 $delInput => array( //if false, then delition flag will not be shown
1405 ["NAME" => "NNN",] //The INPUT's name type of checkbox. File delition flag/
1406 // Default it equals $strInputName."_del" without array indexes influence.
1407 ["LABEL" => "INPUT title"],
1408 ),
1409 $scaleIcon => array( //if false, then icon with help will not be shown.
1410 "SCALE" => Y|N // Y - show scale (zoom) icon N - save size icon
1411 "WIDTH" => xxx // information for hint over icon
1412 "HEIGHT" => yyy // information for hint over icon
1413 ),
1414 */
1415 public static function InputFile(
1416 $strInputName,
1417 $strImageID = "",
1418 $showInfo = false,
1419 $fileInput = false,
1420 $servInput = false,
1421 $pathInput = false,
1422 $descInput = false,
1423 $delInput = false,
1424 $scaleIcon = false,
1425 $cloudInput = false
1426 )
1427 {
1428 return CFileInput::Show($strInputName,
1429 $strImageID,
1430 $showInfo,
1431 array(
1432 'upload' => $fileInput,
1433 'medialib' => $pathInput,
1434 'file_dialog' => $servInput,
1435 'cloud' => $cloudInput,
1436 'del' => $delInput,
1437 'description' => $descInput
1438 )
1439 );
1440 }
1441
1442 public static function GetTypeById($id, $arMLTypes = false)
1443 {
1444 if ($arMLTypes === false)
1445 $arMLTypes = CMedialib::GetTypes();
1446
1447 for ($i = 0, $l = count($arMLTypes); $i < $l; $i++)
1448 if ($arMLTypes[$i]['id'] == $id)
1449 return $arMLTypes[$i];
1450
1451 return false;
1452 }
1453
1454 public static function GetTypes($arConfigTypes = array(), $bGetEmpties = false)
1455 {
1456 global $DB;
1457
1458 if (self::$bCache)
1459 {
1460 $cache = new CPHPCache;
1461 $cacheId = 'medialib_types_'.$bGetEmpties;
1462 $cachePath = self::$cachePath.'types';
1463
1464 if ($cache->InitCache(self::$cacheTime, $cacheId, $cachePath))
1465 {
1466 $res = $cache->GetVars();
1467 $arMLTypes = $res["arMLTypes"];
1468 }
1469 }
1470
1471 if (!self::$bCache || !isset($arMLTypes))
1472 {
1473 if ($bGetEmpties)
1474 $q = "SELECT MT.*, MC.ML_TYPE FROM b_medialib_type MT LEFT JOIN b_medialib_collection MC ON (MT.ID=MC.ML_TYPE)";
1475 else
1476 $q = "SELECT * FROM b_medialib_type";
1477
1478 $res = $DB->Query($q);
1479 $arMLTypes = array();
1480 $arMLTypesInd = array();
1481
1482 while($arRes = $res->Fetch())
1483 {
1484 if ($arMLTypesInd[$arRes["ID"]] ?? false)
1485 continue;
1486
1487 $typeIcon = "/bitrix/images/fileman/medialib/type_".mb_strtolower($arRes["CODE"]).".gif";
1488 if (!file_exists($_SERVER['DOCUMENT_ROOT'].$typeIcon))
1489 $typeIcon = "/bitrix/images/fileman/medialib/type_default.gif";
1490
1491 if ($arRes["SYSTEM"] == "Y")
1492 {
1493 $arRes["NAME"] = GetMessage("ML_TYPE_".mb_strtoupper($arRes["NAME"]));
1494 $arRes["DESCRIPTION"] = GetMessage("ML_TYPE_".mb_strtoupper($arRes["DESCRIPTION"]));
1495 }
1496
1497 $arMLTypesInd[$arRes["ID"]] = true;
1498
1499 $arMLTypes[] = array(
1500 "id" => $arRes["ID"],
1501 "code" => $arRes["CODE"],
1502 "name" => $arRes["NAME"],
1503 "ext" => $arRes["EXT"],
1504 "system" => $arRes["SYSTEM"] == "Y",
1505 "desc" => $arRes["DESCRIPTION"],
1506 "type_icon" => $typeIcon,
1507 "empty" => !($arRes['ML_TYPE'] ?? null) && ($arRes["CODE"] != "image" || $arRes["SYSTEM"] != "Y")
1508 );
1509 }
1510
1511 if (self::$bCache)
1512 {
1513 $cache->StartDataCache(self::$cacheTime, $cacheId, $cachePath);
1514 $cache->EndDataCache(array(
1515 "arMLTypes" => $arMLTypes
1516 ));
1517 }
1518 }
1519
1520 $result = array();
1521 if (is_array($arConfigTypes) && count($arConfigTypes) > 0)
1522 {
1523 foreach($arMLTypes as $type)
1524 {
1525 if (in_array(mb_strtolower($type["code"]), $arConfigTypes))
1526 $result[] = $type;
1527 }
1528 }
1529 else
1530 {
1532 }
1533
1534 return $result;
1535 }
1536
1537 public static function SetTypes($arTypes = array())
1538 {
1539 global $DB;
1540
1541 for ($i = 0, $l = count($arTypes); $i < $l; $i++)
1542 {
1544
1545 $arFields["CODE"] = preg_replace("/[^a-zA-Z0-9_]/i", "", $arFields["CODE"]);
1546 $arFields["EXT"] = preg_replace("/[^a-zA-Z0-9_\,]/i", "", $arFields["EXT"]);
1547
1548 //if ($arFields["CODE"] == '' || $arFields["EXT"] == '' || $arFields["NAME"] == '')
1549 if ($arFields["CODE"] == '' || $arFields["EXT"] == '')
1550 continue;
1551
1552 $id = intval($arFields['ID']);
1553 unset($arFields['ID']);
1554
1555 if ($arFields['NEW'] ?? null) // Add
1556 {
1557 unset($arFields['NEW']);
1558 $DB->Add("b_medialib_type", $arFields, array("DESCRIPTION"));
1559 }
1560 else // Update
1561 {
1562 // Edit only non system types
1563 //if ($arFields['SYSTEM'] == 'Y')
1564 // continue;
1565
1566 //$strSql =
1567 // "UPDATE b_medialib_type SET ".
1568 // $DB->PrepareUpdate("b_medialib_type", $arFields).
1569 // " WHERE SYSTEM<>'Y' AND ID=".$id;
1570
1571 $strSql =
1572 "UPDATE b_medialib_type SET ".
1573 $DB->PrepareUpdate("b_medialib_type", $arFields).
1574 " WHERE ID=".$id;
1575
1576 $DB->QueryBind($strSql,
1577 array('DESCRIPTION' => $arFields['DESCRIPTION'] ?? '')
1578 );
1579 }
1580 }
1581
1582 self::ClearCache(array("types"));
1583 }
1584
1585 public static function DelTypes($arIds = array())
1586 {
1587 if (count($arIds) == 0)
1588 return;
1589
1590 global $DB;
1591 $strItems = "0";
1592 for($i = 0, $l = count($arIds); $i < $l; $i++)
1593 $strItems .= ",".intval($arIds[$i]);
1594
1595 $res = $DB->Query("DELETE FROM b_medialib_type WHERE ID in (".$strItems.")");
1596
1597 self::ClearCache(array("types"));
1598
1599 return $res;
1600 }
1601
1602 public static function GetItemViewHTML($itemId)
1603 {
1604 $arItem = CMedialibItem::GetList(array('id' => $itemId));
1605 if (is_array($arItem) && count($arItem) > 0)
1606 {
1607 $events = GetModuleEvents("fileman", "OnMedialibItemView");
1608 $bHandled = false;
1609 while($arEvent = $events->Fetch())
1610 {
1611 $arRes = ExecuteModuleEventEx($arEvent, array($arItem[0]));
1612 if (!$arRes || !is_array($arRes))
1613 continue;
1614 $bHandled = true;
1615 }
1616 }
1617
1618 if (!$bHandled)
1619 {
1620 $item = $arItem[0];
1621
1622 // Default view
1623 $ext = mb_strtolower(GetFileExtension($item['PATH']));
1624 $videoExt = array('flv', 'mp4', 'wmv', 'avi');
1625 $soundExt = array('aac', 'mp3', 'wma');
1626
1627 if ($item['TYPE'] == 'image' || mb_strpos($item['CONTENT_TYPE'], 'image') !== false)
1628 {
1629 if(mb_substr($item['PATH'], 0, 1) !== '/' || $item['PATH'] !== $item['PATH_EXTERNAL'])
1630 {
1631 $src = $item['PATH_EXTERNAL'];
1632 }
1633 else
1634 {
1635 $src = $item['PATH'];
1636 }
1637
1638 // It's image
1639 $arRes = array(
1640 "html" => "<img src=\"".htmlspecialcharsex($src)."\" width=\"".intval($item['WIDTH'])."\" height=\"".intval($item['HEIGHT'])."\" title=\"".htmlspecialcharsex($item['NAME'])."\" />",
1641 "width" => intval($item['WIDTH']),
1642 "height" => intval($item['HEIGHT'])
1643 );
1644 }
1645 else if (mb_strpos($item['CONTENT_TYPE'], 'video') !== false || in_array($ext, $videoExt))
1646 {
1647 global $APPLICATION;
1648 $item['WIDTH'] = 400;
1649 $item['HEIGHT'] = 300;
1650
1651 ob_start();
1652 $APPLICATION->IncludeComponent(
1653 "bitrix:player",
1654 "",
1655 array(
1656 "PLAYER_TYPE" => "auto",
1657 "PATH" => $item['PATH'],
1658 "WIDTH" => $item['WIDTH'],
1659 "HEIGHT" => $item['HEIGHT'],
1660 "FILE_TITLE" => $item['NAME'],
1661 "FILE_DESCRIPTION" => "",
1662 //"SKIN_PATH" => "/bitrix/components/bitrix/player/mediaplayer/skins",
1663 //"SKIN" => "bitrix.swf",
1664 "WMODE" => "transparent",
1665 "WMODE_WMV" => "windowless",
1666 "SHOW_CONTROLS" => "Y",
1667 "BUFFER_LENGTH" => "3",
1668 "ALLOW_SWF" => "N"
1669 ),
1670 false,
1671 array('HIDE_ICONS' => 'Y')
1672 );
1673 $s = ob_get_contents();
1674 ob_end_clean();
1675
1676 $arRes = array(
1677 "html" => $s,
1678 "width" => $item['WIDTH'],
1679 "height" => $item['HEIGHT']
1680 );
1681 }
1682 else if (mb_strpos($item['CONTENT_TYPE'], 'audio') !== false || in_array($ext, $soundExt))
1683 {
1684 global $APPLICATION;
1685 $item['WIDTH'] = 300;
1686 $item['HEIGHT'] = 24;
1687
1688 ob_start();
1689 $APPLICATION->IncludeComponent(
1690 "bitrix:player",
1691 "",
1692 array(
1693 "PROVIDER" => "sound",
1694 "PLAYER_TYPE" => "auto",
1695 "PATH" => $item['PATH'],
1696 "WIDTH" => $item['WIDTH'],
1697 "HEIGHT" => $item['HEIGHT'],
1698 "FILE_TITLE" => $item['NAME'],
1699 "FILE_DESCRIPTION" => "",
1700 "WMODE" => "transparent",
1701 "WMODE_WMV" => "windowless",
1702 "SHOW_CONTROLS" => "Y",
1703 "BUFFER_LENGTH" => "3",
1704 "ALLOW_SWF" => "N"
1705 ),
1706 false,
1707 array('HIDE_ICONS' => 'Y')
1708 );
1709 $s = "<div style='margin-top: 10px;'>".ob_get_contents()."</div>";
1710 ob_end_clean();
1711 $arRes = array(
1712 "html" => $s,
1713 "width" => $item['WIDTH'],
1714 "height" => $item['HEIGHT']
1715 );
1716 }
1717 }
1718?>
1719<script>
1720window.bx_req_res = {
1721 html: '<?= CUtil::JSEscape($arRes['html'])?>',
1722 width: '<?= intval($arRes['width'])?>',
1723 height: '<?= intval($arRes['height'])?>',
1724 bReplaceAll: <?= ($arRes['bReplaceAll'] ?? null) === true ? 'true' : 'false'?>
1725};
1726</script>
1727<?
1728 }
1729
1730 public static function ChangeColType($Params)
1731 {
1732 if (
1733 CMedialib::CanDoOperation('medialib_edit_collection', $Params['col']) &&
1734 CMedialib::CanDoOperation('medialib_edit_collection', $Params['parent']) &&
1735 $Params['col'] > 0 && $Params['type'] > 0
1736 )
1737 {
1738 $arChild = array();
1739 for($i = 0, $l = count($Params['childCols']); $i < $l; $i++)
1740 {
1741 if (intval($Params['childCols'][$i]) > 0 &&
1742 CMedialib::CanDoOperation('medialib_edit_collection', $Params['childCols'][$i]))
1743 $arChild[] = intval($Params['childCols'][$i]);
1744 }
1745 $Params['childCols'] = $arChild;
1746
1747 CMedialibCollection::ChangeType($Params);
1748 ?><script>top.bx_req_res = true;</script><?
1749 }
1750 else
1751 {
1752 ?><script>top.bx_req_res = false;</script><?
1753 }
1754 }
1755
1756 public static function CompareTypesEx($typeMix, $arType)
1757 {
1758 if ($typeMix == $arType['id'] || (!$typeMix && $arType['code'] == 'image' && $arType['system']))
1759 return true;
1760
1761 return false;
1762 }
1763
1764 public static function ClearCache($arPath = false)
1765 {
1766 if ($arPath === false)
1767 $arPath = array('types');
1768 elseif (!is_array($arPath))
1770
1771 if (is_array($arPath) && count($arPath) > 0)
1772 {
1773 $cache = new CPHPCache;
1774 foreach($arPath as $path)
1775 if ($path != '')
1776 $cache->CleanDir(self::$cachePath.$path);
1777 }
1778 }
1779
1780 public static function AutosaveImage($file = false)
1781 {
1782 $res = CMedialibCollection::GetList(array(
1783 'arFilter' => array(
1784 'ACTIVE' => 'Y',
1785 'NAME' => GetMessage('ML_AUTOSAVE_DEFAULT_COL')
1786 )
1787 ));
1788 $result = false;
1789
1790 if (!$res || count($res) == 0)
1791 {
1792 $colId = CMedialibCollection::Edit(array(
1793 'arFields' => array(
1794 'NAME' => GetMessage('ML_AUTOSAVE_DEFAULT_COL'),
1795 'DESCRIPTION' => GetMessage('ML_AUTOSAVE_DEFAULT_COL_DEF'),
1796 'OWNER_ID' => $GLOBALS['USER']->GetId(),
1797 'KEYWORDS' => '',
1798 'ACTIVE' => "Y",
1799 'ML_TYPE' => 'image'
1800 )
1801 ));
1802 }
1803 else
1804 {
1805 $colId = $res[0]['ID'];
1806 }
1807
1808 if ($colId && $file)
1809 {
1810 $res = CMedialibItem::Edit(array(
1811 'file' => $file,
1812 'path' => '',
1813 'arFields' => array(
1814 'NAME' => $file['name']
1815 ),
1816 'arCollections' => array($colId)
1817 ));
1818
1819 if ($res && $res['ID'] > 0)
1820 {
1821 $item = CMedialibItem::GetList(array('id' => $res['ID']));
1822 if (is_array($item) && count($item) > 0)
1823 {
1824 $result = $item[0];
1825 }
1826 }
1827 }
1828
1829 return $result;
1830 }
1831}
1832
1833class CMedialibCollection
1834{
1835 public static function GetList($Params = array())
1836 {
1837 global $DB, $USER;
1838 $arFilter = $Params['arFilter'];
1839 $arOrder = isset($Params['arOrder']) ? $Params['arOrder'] : Array('ID' => 'asc');
1840
1841 static $arFields = array(
1842 "ID" => Array("FIELD_NAME" => "MLC.ID", "FIELD_TYPE" => "int"),
1843 "NAME" => Array("FIELD_NAME" => "MLC.NAME", "FIELD_TYPE" => "string"),
1844 "ACTIVE" => Array("FIELD_NAME" => "MLC.ACTIVE", "FIELD_TYPE" => "string"),
1845 "DATE_UPDATE" => Array("FIELD_NAME" => "MLC.DATE_UPDATE", "FIELD_TYPE" => "date"),
1846 "KEYWORDS" => Array("FIELD_NAME" => "MLC.KEYWORDS", "FIELD_TYPE" => "string"),
1847 "DESCRIPTION" => Array("FIELD_NAME" => "MLC.DESCRIPTION", "FIELD_TYPE" => "string"),
1848 "OWNER_ID" => Array("FIELD_NAME" => "MLC.OWNER_ID", "FIELD_TYPE" => "int"),
1849 "PARENT_ID" => Array("FIELD_NAME" => "MLC.PARENT_ID", "FIELD_TYPE" => "int"),
1850 "ML_TYPE" => Array("FIELD_NAME" => "MLC.ML_TYPE", "FIELD_TYPE" => "string")
1851 );
1852
1853 $arSqlSearch = array();
1854 $strSqlSearch = "";
1855 if(is_array($arFilter))
1856 {
1857 $filter_keys = array_keys($arFilter);
1858 for($i=0, $l = count($filter_keys); $i<$l; $i++)
1859 {
1860 $n = mb_strtoupper($filter_keys[$i]);
1861 $val = $arFilter[$filter_keys[$i]];
1862 if((is_string($val) && $val == '') || (!is_array($val) && (string)$val==="NOT_REF"))
1863 continue;
1864 if ($n == 'ID' || $n == 'PARENT_ID' || $n == 'OWNER_ID')
1865 $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val, 'N');
1866 elseif(isset($arFields[$n]))
1867 $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val);
1868 }
1869 }
1870
1871 $strOrderBy = '';
1872 foreach($arOrder as $by=>$order)
1873 if(isset($arFields[mb_strtoupper($by)]))
1874 $strOrderBy .= $arFields[mb_strtoupper($by)]["FIELD_NAME"].' '.(mb_strtolower($order) == 'desc'?'desc'.($DB->type == "ORACLE"?" NULLS LAST":""):'asc'.($DB->type == "ORACLE"?" NULLS FIRST":"")).',';
1875
1876 if($strOrderBy <> '')
1877 $strOrderBy = "ORDER BY ".rtrim($strOrderBy, ",");
1878
1879 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
1880 if (isset($arFilter['TYPES']) && is_array($arFilter['TYPES']))
1881 {
1882 $strTypes = "";
1883 for($i = 0, $l = count($arFilter['TYPES']); $i < $l; $i++)
1884 $strTypes .= ",".intval($arFilter['TYPES'][$i]);
1885 $strSqlSearch .= "\n AND ML_TYPE in (".trim($strTypes, ", ").")";
1886 }
1887
1888 $strSql = "
1889 SELECT
1890 MLC.*
1891 FROM
1892 b_medialib_collection MLC
1893 WHERE
1894 $strSqlSearch
1895 $strOrderBy";
1896
1897 $res = $DB->Query($strSql);
1898 $arResult = Array();
1899 while($arRes = $res->Fetch())
1900 $arResult[] = $arRes;
1901
1902 return $arResult;
1903 }
1904
1905 public static function CheckFields($arFields)
1906 {
1907 if (!isset($arFields['NAME']) || $arFields['NAME'] == '')
1908 return false;
1909
1910 /*
1911 ID int not null auto_increment,
1912 NAME varchar(255) not null,
1913 DESCRIPTION text null,
1914 ACTIVE char(1) not null default 'Y',
1915 DATE_UPDATE datetime not null,
1916 OWNER_ID int null,
1917 PARENT_ID int null,
1918 SITE_ID char(2) not null,
1919 KEYWORDS varchar(255) null
1920 */
1921 return true;
1922 }
1923
1924 public static function Edit($Params)
1925 {
1926 global $DB;
1927 $arFields = $Params['arFields'];
1928
1929 if (!isset($arFields['~DATE_UPDATE']))
1930 $arFields['~DATE_UPDATE'] = $DB->CurrentTimeFunction();
1931
1932 if(!CMedialibCollection::CheckFields($arFields))
1933 return false;
1934
1935 if (!isset($arFields['ML_TYPE']))
1936 $arFields['ML_TYPE'] = '';
1937
1938 $bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0;
1939 if ($bNew) // Add
1940 {
1941 unset($arFields['ID']);
1942 $ID = $DB->Add("b_medialib_collection", $arFields, array("DESCRIPTION"));
1943 }
1944 else // Update
1945 {
1946 $ID = $arFields['ID'];
1947 unset($arFields['ID']);
1948 $strUpdate = $DB->PrepareUpdate("b_medialib_collection", $arFields);
1949 $strSql =
1950 "UPDATE b_medialib_collection SET ".
1951 $strUpdate.
1952 " WHERE ID=".intval($ID);
1953
1954 $DB->QueryBind($strSql,
1955 array('DESCRIPTION' => $arFields['DESCRIPTION']));
1956 }
1957
1958 return $ID;
1959 }
1960
1961 public static function Delete($ID, $bDelEmpty = true)
1962 {
1963 global $DB;
1964 $ID = intval($ID);
1965
1966 $strSql = "DELETE FROM b_medialib_collection WHERE ID=".$ID;
1967 $z = $DB->Query($strSql);
1968
1969 $strSql = "DELETE FROM b_medialib_collection_item WHERE COLLECTION_ID=".$ID;
1970 $z = $DB->Query($strSql);
1971
1972 if ($bDelEmpty)
1973 CMedialibItem::DeleteEmpty();
1974
1975 return $z;
1976 }
1977
1978 public static function IsViewable($oCol, $arCol=false)
1979 {
1980 if(!$arCol)
1981 $arCol = CMedialibCollection::GetList(array('arFilter' => array('ACTIVE' => 'Y')));
1982
1983 if (!CMedialib::CanDoOperation('medialib_view_collection', $oCol['ID']))
1984 return false;
1985
1986 $l = count($arCol);
1987 if ($oCol['PARENT_ID'])
1988 {
1989 $parId = $oCol['PARENT_ID'];
1990 while(intval($parId) > 0)
1991 {
1992 $bFind = false;
1993 for($i = 0; $i < $l; $i++) // Find parent
1994 {
1995 if ($arCol[$i]['ID'] == $parId)
1996 {
1997 if (!CMedialib::CanDoOperation('medialib_view_collection', $arCol[$i]['ID']))
1998 return false;
1999 $parId = $arCol[$i]['PARENT_ID'];
2000 $bFind = true;
2001 break;
2002 }
2003 }
2004 if (!$bFind)
2005 return false;
2006 }
2007 }
2008 return true;
2009 }
2010
2011 public static function ChangeType($Params)
2012 {
2013 global $DB;
2014 $arFields = array(
2015 'ML_TYPE' => $Params['type'],
2016 'PARENT_ID' => $Params['parent']
2017 );
2018
2019 $strUpdate = $DB->PrepareUpdate("b_medialib_collection", $arFields);
2020 $strSql =
2021 "UPDATE b_medialib_collection SET ".
2022 $strUpdate.
2023 " WHERE ID=".intval($Params['col']);
2024
2025 $res = $DB->Query($strSql);
2026
2027 if (count($Params['childCols']) > 0 && $res)
2028 {
2029 $strIds = "0";
2030 for($i = 0, $l = count($Params['childCols']); $i < $l; $i++)
2031 $strIds .= ",".intval($Params['childCols'][$i]);
2032
2033 $strUpdate = $DB->PrepareUpdate("b_medialib_collection", array('ML_TYPE' => $Params['type']));
2034 $strSql =
2035 "UPDATE b_medialib_collection SET ".
2036 $strUpdate.
2037 " WHERE ID in (".$strIds.")";
2038
2039 $res = $DB->Query($strSql);
2040 }
2041
2042 return $res;
2043 }
2044}
2045
2046class CMedialibItem
2047{
2048 public static function CheckFields($arFields)
2049 {
2050 if (!isset($arFields['NAME']) || $arFields['NAME'] == '')
2051 return false;
2052
2053 return true;
2054 }
2055
2056 public static function GetList($Params)
2057 {
2058 global $DB;
2059
2060 $q = '';
2061 if (is_array($Params['arCollections'] ?? null))
2062 {
2063 if (count($Params['arCollections']) == 1)
2064 {
2065 $q = 'WHERE MCI.COLLECTION_ID='.intval($Params['arCollections'][0]);
2066 }
2067 elseif (count($Params['arCollections']) > 1)
2068 {
2069 $strCollections = "0";
2070 for($i = 0, $l = count($Params['arCollections']); $i < $l; $i++)
2071 $strCollections .= ",".intval($Params['arCollections'][$i]);
2072 $q = 'WHERE MCI.COLLECTION_ID in ('.$strCollections.')';
2073 }
2074 }
2075
2076 if (isset($Params['id']) && $Params['id'] > 0)
2077 $q = 'WHERE MI.ID='.intval($Params['id']);
2078
2079 if (isset($Params['minId']) && $Params['minId'] > 0)
2080 {
2081 if ($q <> '')
2082 $q = trim($q)." AND MI.ID>=".intval($Params['minId']);
2083 else
2084 $q .= "WHERE MI.ID>=".intval($Params['minId']);
2085 }
2086
2087 $strSql = "SELECT
2088 MI.*,MCI.COLLECTION_ID, F.HEIGHT, F.WIDTH, F.FILE_SIZE, F.CONTENT_TYPE, F.SUBDIR, F.FILE_NAME, F.HANDLER_ID,
2089 ".$DB->DateToCharFunction("MI.DATE_UPDATE")." as DATE_UPDATE2
2090 FROM b_medialib_collection_item MCI
2091 INNER JOIN b_medialib_item MI ON (MI.ID=MCI.ITEM_ID)
2092 INNER JOIN b_file F ON (F.ID=MI.SOURCE_ID) ".$q;
2093
2094 $res = $DB->Query($strSql);
2095 $arResult = Array();
2096 $rootPath = CSite::GetSiteDocRoot(false);
2097 $tmbW = COption::GetOptionInt('fileman', "ml_thumb_width", 140);
2098 $tmbH = COption::GetOptionInt('fileman', "ml_thumb_height", 105);
2099
2100 while($arRes = $res->Fetch())
2101 {
2102 CMedialibItem::GenerateThumbnail($arRes, array('rootPath' => $rootPath, 'width' => $tmbW, 'height' => $tmbH));
2103 $arRes['PATH'] = CFile::GetFileSRC($arRes, false, false);
2104 $arRes['PATH_EXTERNAL'] = CFile::GetFileSRC($arRes, false, true);
2105 $arResult[]=$arRes;
2106 }
2107
2108 return $arResult;
2109 }
2110
2111 // Add or edit ITEM
2112 public static function Edit($Params)
2113 {
2114 global $DB;
2115 $source_id = false;
2116 $arFields = $Params['arFields'];
2117 $arFields['ID'] = $arFields['ID'] ?? null;
2118 $bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0;
2119 $Params['path'] ??= null;
2120 $Params['file'] ??= null;
2121 $bFile_FD = $Params['path'] && $Params['path'] <> '';
2122 $bFile_PC = $Params['file'] && $Params['file']['name'] <> '' && $Params['file']['size'] > 0;
2123
2125
2126 if ($bFile_FD || $bFile_PC)
2127 {
2128 if ($bFile_FD)
2129 {
2130 $DocRoot = CSite::GetSiteDocRoot(false);
2131 $tmp_name = $DocRoot.$Params['path'];
2132
2133 if ($io->FileExists($tmp_name))
2134 {
2135 $flTmp = $io->GetFile($tmp_name);
2136 $file_name = mb_substr($Params['path'], mb_strrpos($Params['path'], '/') + 1);
2137 $arFile = array(
2138 "name" => $file_name,
2139 "size" => $flTmp->GetFileSize(),
2140 "tmp_name" => $tmp_name,
2141 "type" => CFile::IsImage($file_name) ? 'image' : 'file'
2142 );
2143 }
2144 }
2145 else if ($bFile_PC)
2146 {
2147 $arFile = $Params['file'];
2148 }
2149
2150 if (!CMedialib::CheckFileExtention($arFile["name"]))
2151 return false;
2152
2153 if (!$bNew) // Del old file
2154 {
2155 $arFile["old_file"] = CMedialibItem::GetSourceId($arFields['ID']);
2156 $arFile["del"] = "Y";
2157 }
2158
2159 // Resizing Image
2160 if (CFile::IsImage($arFile["name"]))
2161 {
2162 $arSize = array(
2163 'width' => COption::GetOptionInt('fileman', "ml_max_width", 1024),
2164 'height' => COption::GetOptionInt('fileman', "ml_max_height", 1024)
2165 );
2166 $res = CFile::ResizeImage($arFile, $arSize);
2167 }
2168
2169 $arFile["MODULE_ID"] = "fileman";
2170 $source_id = CFile::SaveFile($arFile, "medialibrary");
2171
2172 if ($source_id) // Get file
2173 {
2174 $r = CFile::GetByID($source_id);
2175 if ($arFile = $r->Fetch())
2176 {
2177 if (CFile::IsImage($arFile['FILE_NAME']))
2178 CMedialibItem::GenerateThumbnail($arFile, array('width' => COption::GetOptionInt('fileman', "ml_thumb_width", 140), 'height' => COption::GetOptionInt('fileman', "ml_thumb_height", 105)));
2179
2180 $arFile['PATH'] = CMedialibItem::GetFullPath($arFile);
2181 }
2182 }
2183 }
2184
2185 // TODO: Add error handling
2186 if ($bNew && !$source_id)
2187 return false;
2188
2189 // 2. Add to b_medialib_item
2190 if (!isset($arFields['~DATE_UPDATE']))
2191 $arFields['~DATE_UPDATE'] = $DB->CurrentTimeFunction();
2192
2193 if(!CMedialibItem::CheckFields($arFields))
2194 return false;
2195
2196 if (CModule::IncludeModule("search"))
2197 {
2198 $arStem = stemming($arFields['NAME'].' '.$arFields['DESCRIPTION'].' '.$arFields['KEYWORDS'], LANGUAGE_ID);
2199 if (count($arStem) > 0)
2200 $arFields['SEARCHABLE_CONTENT'] = '{'.implode('}{', array_keys($arStem)).'}';
2201 else
2202 $arFields['SEARCHABLE_CONTENT'] = '';
2203 }
2204
2205 if ($bNew) // Add
2206 {
2207 unset($arFields['ID']);
2208 $arFields['SOURCE_ID'] = $source_id;
2209 $arFields['~DATE_CREATE'] = $arFields['~DATE_UPDATE'];
2210 $arFields['ITEM_TYPE'] = '';
2211 $ID = $DB->Add("b_medialib_item", $arFields, array("DESCRIPTION","SEARCHABLE_CONTENT"));
2212 }
2213 else // Update
2214 {
2215 if ($source_id)
2216 $arFields['SOURCE_ID'] = $source_id;
2217 $ID = $arFields['ID'];
2218 unset($arFields['ID']);
2219
2220 $strUpdate = $DB->PrepareUpdate("b_medialib_item", $arFields);
2221 $strSql =
2222 "UPDATE b_medialib_item SET ".
2223 $strUpdate.
2224 " WHERE ID=".intval($ID);
2225
2226 $DB->QueryBind($strSql,
2227 array(
2228 "DESCRIPTION" => $arFields["DESCRIPTION"],
2229 "SEARCHABLE_CONTENT" => $arFields["SEARCHABLE_CONTENT"]
2230 ));
2231 }
2232
2233 // 3. Set fields to b_medialib_collection_item
2234 if (!$bNew) // Del all rows if
2235 {
2236 $strSql = "DELETE FROM b_medialib_collection_item WHERE ITEM_ID=".intval($ID);
2237 $DB->Query($strSql);
2238 }
2239
2240 $strCollections = "0";
2241
2242 for($i = 0, $l = count($Params['arCollections']); $i < $l; $i++)
2243 $strCollections .= ",".intval($Params['arCollections'][$i]);
2244
2245 $strSql =
2246 "INSERT INTO b_medialib_collection_item(ITEM_ID, COLLECTION_ID) ".
2247 "SELECT ".intval($ID).", ID ".
2248 "FROM b_medialib_collection ".
2249 "WHERE ID in (".$strCollections.")";
2250
2251 $res = $DB->Query($strSql);
2252
2253 if (!($arFields['ID'] ?? false))
2254 $arFields['ID'] = $ID;
2255
2256 if ($source_id)
2257 $arFields = array_merge($arFile, $arFields);
2258
2259 return $arFields;
2260 }
2261
2262 public static function GenerateThumbnail(&$arFile, $Params = array())
2263 {
2264 $rootPath = isset($Params['rootPath']) ? $Params['rootPath'] : CSite::GetSiteDocRoot(false);
2265 if (CFile::IsImage($arFile['FILE_NAME']))
2266 {
2267 $arResized = CFile::ResizeImageGet($arFile, array('width' => $Params['width'], 'height' => $Params['height']));
2268 if($arResized)
2269 $arFile['THUMB_PATH'] = $arResized['src'];
2270 $arFile['TYPE'] = 'image';
2271 }
2272 else
2273 $arFile['TYPE'] = 'file';
2274 }
2275
2276 public static function GetItemCollections($Params)
2277 {
2278 global $DB;
2279 $strSql = 'SELECT MCI.COLLECTION_ID
2280 FROM b_medialib_collection_item MCI
2281 WHERE MCI.ITEM_ID='.intval($Params['ID']);
2282 $res = $DB->Query($strSql);
2283
2284 $arResult = array();
2285 while($arRes = $res->Fetch())
2286 $arResult[]=$arRes['COLLECTION_ID'];
2287 return $arResult;
2288 }
2289
2290 public static function Delete($ID, $bCurrent, $colId)
2291 {
2292 global $DB;
2293 if ($bCurrent) // Del from one collection
2294 {
2295 if (!CMedialib::CanDoOperation('medialib_del_item', $colId))
2296 return false;
2297 $strSql = "DELETE FROM b_medialib_collection_item WHERE ITEM_ID=".intval($ID)." AND COLLECTION_ID=".intval($colId);
2298 $z = $DB->Query($strSql);
2299 }
2300 else // Del from all collections
2301 {
2302 $arCols = CMedialibItem::GetItemCollections(array('ID' => $ID));
2303 for ($i = 0, $l = count($arCols); $i < $l; $i++)
2304 {
2305 if (!CMedialib::CanDoOperation('medialib_del_item', $arCols[$i])) // Check access
2306 return false;
2307 }
2308 $strSql = "DELETE FROM b_medialib_collection_item WHERE ITEM_ID=".intval($ID);
2309 $z = $DB->Query($strSql);
2310 }
2311
2312 CMedialibItem::DeleteEmpty();
2313
2314 return $z;
2315 }
2316
2317 public static function DeleteEmpty()
2318 {
2319 global $DB;
2320
2321 $strSql = 'SELECT MI.*,MCI.COLLECTION_ID
2322 FROM b_medialib_item MI
2323 LEFT JOIN b_medialib_collection_item MCI ON (MI.ID=MCI.ITEM_ID)
2324 WHERE MCI.COLLECTION_ID is null';
2325 $res = $DB->Query($strSql);
2326
2327 $strItems = "0";
2328 while($arRes = $res->Fetch())
2329 {
2330 $strItems .= ",".intval($arRes['ID']);
2331
2332 if ($arRes['SOURCE_ID'] > 0) // Clean from 'b_file'
2333 CFile::Delete(intval($arRes['SOURCE_ID']));
2334 }
2335
2336 // Clean from 'b_medialib_item'
2337 if ($strItems != "0")
2338 $DB->Query("DELETE FROM b_medialib_item WHERE ID in (".$strItems.")");
2339 }
2340
2341 public static function GetThumbPath($arImage)
2342 {
2343 return BX_PERSONAL_ROOT."/tmp/".$arImage['SUBDIR'].'/'.$arImage['FILE_NAME'];
2344 }
2345
2346 public static function GetFullPath($arImage, $upload_dir = false)
2347 {
2348 return CFile::GetFileSRC($arImage, $upload_dir);
2349 }
2350
2351 public static function GetSourceId($id)
2352 {
2353 global $DB;
2354 $strSql = 'SELECT SOURCE_ID
2355 FROM b_medialib_item
2356 WHERE ID='.intval($id);
2357 $r = $DB->Query($strSql);
2358 if ($res = $r->Fetch())
2359 return $res['SOURCE_ID'];
2360
2361 return false;
2362 }
2363
2364 public static function Search($arQuery, $arTypes = array())
2365 {
2366 global $DB;
2367
2368 $strSql = "SELECT
2369 MI.*, MI.*,MCI.COLLECTION_ID, F.HEIGHT, F.WIDTH, F.FILE_SIZE, F.CONTENT_TYPE, F.SUBDIR, F.FILE_NAME, F.HANDLER_ID,
2370 ".$DB->DateToCharFunction("MI.DATE_UPDATE")." as DATE_UPDATE2
2371 FROM b_medialib_item MI
2372 INNER JOIN b_medialib_collection_item MCI ON (MI.ID=MCI.ITEM_ID)
2373 INNER JOIN b_file F ON (F.ID=MI.SOURCE_ID)
2374 WHERE 1=1";
2375
2376 $l = count($arQuery);
2377 if ($l == 0)
2378 return array();
2379
2380 for ($i = 0; $i < $l; $i++)
2381 $strSql .= " AND MI.SEARCHABLE_CONTENT LIKE '%".$DB->ForSql($arQuery[$i])."%'";
2382
2383 $strSql .= " ORDER BY MI.ID DESC";
2384
2385 $res = $DB->Query($strSql);
2386 $arResult = Array();
2387 $rootPath = CSite::GetSiteDocRoot(false);
2388 $tmbW = COption::GetOptionInt('fileman', "ml_thumb_width", 140);
2389 $tmbH = COption::GetOptionInt('fileman', "ml_thumb_height", 105);
2390
2391 $elId2Index = array();
2392 $colId2Index = array();
2393 $arCol = CMedialibCollection::GetList(array('arFilter' => array('ACTIVE' => 'Y', "TYPES" => $arTypes)));
2394
2395 for ($i = 0, $l = count($arCol); $i < $l; $i++)
2396 $colId2Index[$arCol[$i]['ID']] = $i;
2397
2398 while($arRes = $res->Fetch())
2399 {
2400 $colId = $arRes['COLLECTION_ID'];
2401 if (!isset($colId2Index[$colId]) || !CMedialibCollection::IsViewable($arCol[$colId2Index[$colId]], $arCol))
2402 continue;
2403
2404 if (isset($elId2Index[$arRes['ID']]))
2405 {
2406 $arResult[$elId2Index[$arRes['ID']]]['collections'][] = $colId;
2407 }
2408 else
2409 {
2410 $elId2Index[$arRes['ID']] = count($arResult);
2411 $arRes['collections'] = array($colId);
2412 $arRes['perm'] = array
2413 (
2414 'edit' => true,
2415 'del' => true
2416 );
2417
2418 CMedialibItem::GenerateThumbnail($arRes, array('rootPath' => $rootPath, 'width' => $tmbW, 'height' => $tmbH));
2419 $arRes['PATH'] = CFile::GetFileSRC($arRes);
2420 $arResult[]=$arRes;
2421 }
2422 }
2423
2424 return $arResult;
2425 }
2426}
2427
2428// Deprecated and unused class. Placed here to prevent fatal errors in customized forms
2429class CMedialibTabControl
2430{
2431 public static function ShowScript()
2432 {
2433 }
2434}
2435
2436?>
$path
Определения access_edit.php:21
return select
Определения access_edit.php:440
$type
Определения options.php:106
$arTypes
Определения options.php:23
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static ShowScript($arConfig)
Определения file_dialog.php:9
static GetOptionString($module_id, $name, $def="", $site=false, $bExactSite=false)
Определения option.php:8
static GetOptionInt($module_id, $name, $def="", $site=false)
Определения option.php:49
static GetSiteDocRoot($site)
Определения site.php:557
static GetOperations($ID, $return_names=false)
Определения task.php:230
static GetInstance()
Определения virtual_io.php:60
static ResizeImageGet($file, $arSize, $resizeType=BX_RESIZE_IMAGE_PROPORTIONAL, $bInitSizes=false, $arFilters=false, $bImmediate=false, $jpgQuality=false)
Определения file.php:2242
static Delete($ID)
Определения file.php:706
static SaveFile($arFile, $strSavePath, $forceRandom=false, $skipExtension=false, $dirAdd='')
Определения file.php:164
static GetFileSRC($file, $uploadDir=false, $external=true)
Определения file.php:1172
static ResizeImage(&$arFile, $arSize, $resizeType=BX_RESIZE_IMAGE_PROPORTIONAL)
Определения file.php:2203
static GetByID($fileId, $realId=false)
Определения file.php:1021
static Show( $strInputName, $strFileId="", $showInfo=false, $inputs=array())
Определения file_input.php:62
static SetOption($category, $name, $value, $bCommon=false, $user_id=false)
Определения user_options.php:163
static InitJSCore($arExt=[], $bReturn=false)
Определения util.php:581
static JSEscape($s)
Определения util.php:48
static PhpToJSObject($arData, $bWS=false, $bSkipTilda=false, $bExtType=false)
Определения util.php:66
$str
Определения commerceml2.php:63
$arFields
Определения dblapprove.php:5
$arPath
Определения file_edit.php:72
hidden PROPERTY[<?=$propertyIndex?>][CODE]<?=htmlspecialcharsEx( $propertyCode)?> height
Определения file_new.php:759
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
Определения file_new.php:677
bx popup label bx hidden PROPERTY[<?=$propertyIndex?>][CODE]<?=htmlspecialcharsEx( $propertyCode)?> bx_view_property_<?=$propertyIndex?> overflow
Определения file_new.php:745
background position
Определения file_new.php:745
$arr
Определения file_new.php:624
background repeat
Определения file_new.php:745
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
background color
Определения file_new.php:745
bx_acc_lim_group_list limitGroupList[] multiple<?=$group[ 'ID']?> ID selected margin top
Определения file_new.php:657
$arMLTypes
Определения options.php:1621
hidden mSiteList<?=htmlspecialcharsbx(serialize( $siteList))?><?=htmlspecialcharsbx( $siteList[ $j]["ID"])?> _Propery<? if(((COption::GetOptionString( $module_id, "different_set", "N")=="Y") &&( $j !=0))||(COption::GetOptionString( $module_id, "different_set", "N")=="N")) echo "display: none;"?> top adm detail content cell l top adm detail content cell r heading center center ID left
Определения options.php:768
$res
Определения filter_act.php:7
GetFilterSqlSearch($arSqlSearch=array(), $FilterLogic="FILTER_logic")
Определения filter_tools.php:397
GetFilterQuery($field, $val, $procent="Y", $ex_sep=array(), $clob="N", $div_fields="Y", $clob_upper="N")
Определения filter_tools.php:383
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
if( $adminSidePanelHelper->isSidePanel())
Определения csv_new_setup.php:231
$io
Определения csv_new_run.php:98
endif
Определения csv_new_setup.php:990
$l
Определения options.php:783
$z
Определения options.php:31
ConvertDateTime($datetime, $to_format=false, $from_site=false, $bSearchInSitesOnly=false)
Определения tools.php:724
GetFileExtension($path)
Определения tools.php:2972
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$value
Определения Param.php:39
Types
Определения Types.php:7
$order
Определения payment.php:8
white space
Определения options.php:321
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
<? endif;?> window document title
Определения prolog_main_admin.php:76
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
lang
Определения options.php:182
$i
Определения factura.php:643
font style
Определения invoice.php:442
font size
Определения invoice.php:442
</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
$width
Определения html.php:68
$arCols
Определения template.php:277
text align
Определения template.php:556
$title
Определения pdf.php:123
$val
Определения options.php:1793
margin right
Определения options_user_settings.php:273
$arRes
Определения options.php:104
stemming($sText, $sLang='ru', $bIgnoreStopWords=false, $bReturnPositions=false)
Определения stemming.php:148
path
Определения template_copy.php:201
$GLOBALS['_____370096793']
Определения update_client.php:1
$n
Определения update_log.php:107
$arFilter
Определения user_search.php:106
adm detail iblock types adm detail iblock list tr_SITE_ID display
Определения yandex_setup.php:388