/** * Получает все изображения коллекции медиабиблиотеки * @param $medialibraryCollectionId * @return array */ public function getImagesFromMedialibraryCollection($medialibraryCollectionId) { $images = array(); CMedialib::Init(); //Классы медиабиблиотеки недоступны до ее инициализации $items = CMedialibItem::GetList(array( 'arCollections' => array( $medialibraryCollectionId, ) )); /** * В CMedialibItem::GetList нет возможности фильтрации по типу элемента коллекции, * поэтому придется выбрать изображения вручную */ foreach ($items as $item) { if ($item['TYPE'] === 'image') { $image = array( 'HEIGHT' => $item['HEIGHT'], 'WIDTH' => $item['WIDTH'], 'PATH' => $item['PATH'], 'THUMB_PATH' => $item['THUMB_PATH'], 'DESCRIPTION' => $item['DESCRIPTION'], ); $images[] = $image; } } return $images; }
function handleFile($hash, $file, &$package, &$upload) { global $APPLICATION; $name = $file["name"]; $pattern = defined('BX_UTF') ? "/[^\\p{L}L0-9!\\p{Z}\$&\\(\\)\\[\\]\\{\\}\\-\\.;=@\\^_\\~]/uis" : "/[^A-Za-zÀ-ߨà-ÿ¸0-9!\\s\$&\\(\\)\\[\\]\\{\\}\\-\\.;=@\\^_\\~]/is"; $name = trim(preg_replace($pattern, "", $name)); if (strlen(trim(substr($name, 0, strpos($name, '.')))) <= 0) { $name = substr(md5(uniqid(rand(), true)), 0, 8) . trim($name); } $res = CMedialibItem::Edit(array('file' => array_key_exists("files", $file) ? $file["files"]["default"] : $file, 'arFields' => array('NAME' => $name, 'DESCRIPTION' => $file['description'], 'KEYWORDS' => ''), 'arCollections' => array($package["collectionId"]))); if (!array_key_exists("redirectUrl", $upload) && $res && $res['ID'] > 0) { $upload["redirectUrlPart"] = "action=redirect&" . bitrix_sessid_get() . "&first_id=" . $res["ID"] . "&col_id=" . $package["collectionId"] . "&ml_type=" . htmlspecialcharsEx($package["ml_type"]); $upload["redirectUrl"] = $APPLICATION->GetCurPageParam($upload["redirectUrlPart"], array("action", "ml_type", "first_id", "col_id", "sessid")); } return $res; }
public static function Search($arQuery, $arTypes = array()) { global $DB; $err_mess = CMedialibCollection::GetErrorMess() . "<br>Function: CMedialibItem::Search<br>Line: "; $strSql = "SELECT\n\t\t\t\t\tMI.*, MI.*,MCI.COLLECTION_ID, F.HEIGHT, F.WIDTH, F.FILE_SIZE, F.CONTENT_TYPE, F.SUBDIR, F.FILE_NAME, F.HANDLER_ID,\n\t\t\t\t\t" . $DB->DateToCharFunction("MI.DATE_UPDATE") . " as DATE_UPDATE2\n\t\t\t\tFROM b_medialib_item MI\n\t\t\t\tINNER JOIN b_medialib_collection_item MCI ON (MI.ID=MCI.ITEM_ID)\n\t\t\t\tINNER JOIN b_file F ON (F.ID=MI.SOURCE_ID)\n\t\t\t\tWHERE 1=1"; $l = count($arQuery); if ($l == 0) { return array(); } for ($i = 0; $i < $l; $i++) { $strSql .= " AND MI.SEARCHABLE_CONTENT LIKE '%" . $DB->ForSql($arQuery[$i]) . "%'"; } $strSql .= " ORDER BY MI.ID DESC"; $res = $DB->Query($strSql, false, $err_mess); $arResult = array(); $rootPath = CSite::GetSiteDocRoot(false); $tmbW = COption::GetOptionInt('fileman', "ml_thumb_width", 140); $tmbH = COption::GetOptionInt('fileman', "ml_thumb_height", 105); $elId2Index = array(); $colId2Index = array(); $arCol = CMedialibCollection::GetList(array('arFilter' => array('ACTIVE' => 'Y', "TYPES" => $arTypes))); for ($i = 0, $l = count($arCol); $i < $l; $i++) { $colId2Index[$arCol[$i]['ID']] = $i; } while ($arRes = $res->Fetch()) { $colId = $arRes['COLLECTION_ID']; if (!isset($colId2Index[$colId]) || !CMedialibCollection::IsViewable($arCol[$colId2Index[$colId]], $arCol)) { continue; } if (isset($elId2Index[$arRes['ID']])) { $arResult[$elId2Index[$arRes['ID']]]['collections'][] = $colId; } else { $elId2Index[$arRes['ID']] = count($arResult); $arRes['collections'] = array($colId); $arRes['perm'] = array('edit' => true, 'del' => true); CMedialibItem::GenerateThumbnail($arRes, array('rootPath' => $rootPath, 'width' => $tmbW, 'height' => $tmbH)); $arRes['PATH'] = CFile::GetFileSRC($arRes); $arResult[] = $arRes; } } return $arResult; }
$arCols_ = explode(',', trim($_POST['item_colls_'.$i], ' ,')); $arCols = array(); for ($j = 0, $n = count($arCols_); $j < $n; $j++) { if (intVal($arCols_[$j]) > 0 && CMedialib::CanDoOperation("medialib_edit_item", $arCols_[$j])) // Check access $arCols[] = intVal($arCols_[$j]); } if (count($arCols) > 0) { $res = CMedialibItem::Edit(array( 'arFields' => array( 'ID' => intVal($_POST['item_id_'.$i]), 'NAME' => $_POST['item_name_'.$i], 'DESCRIPTION' => $_POST['item_desc_'.$i], 'KEYWORDS' => $_POST['item_keys_'.$i] ), 'arCollections' => $arCols )); } } } LocalRedirect("/freetrix/admin/fileman_medialib_admin.php?lang=".LANGUAGE_ID."&".freetrix_sessid_get()); } else // ***************************** Show upploader ************************** { $APPLICATION->AddHeadScript('/freetrix/image_uploader/iuembed.js'); $APPLICATION->SetTitle(GetMessage('FM_ML_UPL_TITLE1'));
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule("fileman")) { return; } $source_base = dirname(__FILE__); $documentRoot = rtrim(str_replace(array("\\\\", "//", "\\"), array("\\", "/", "/"), $_SERVER["DOCUMENT_ROOT"]), "\\/"); $source_base = substr($source_base, strLen($documentRoot)); $source_base = str_replace(array("\\", "//"), "/", "/" . $source_base . "/"); __IncludeLang(dirname(__FILE__) . "/lang/" . LANGUAGE_ID . '/' . basename(__FILE__)); $arCollections = array(array('name' => GetMessage('ML_COL_NAME_0'), 'desc' => GetMessage('ML_COL_DESC_0')), array('name' => GetMessage('ML_COL_NAME_1'), 'desc' => GetMessage('ML_COL_DESC_1')), array('name' => GetMessage('ML_COL_NAME_2'), 'desc' => GetMessage('ML_COL_DESC_2'), 'ex_parent' => 0)); $arExCols = array(); for ($i = 0, $l = count($arCollections); $i < $l; $i++) { $arExCols[$i] = CMedialib::EditCollection(array('name' => $arCollections[$i]['name'], 'desc' => $arCollections[$i]['desc'], 'keywords' => '', 'parent' => isset($arCollections[$i]['ex_parent'], $arExCols[$arCollections[$i]['ex_parent']]) ? intVal($arExCols[$arCollections[$i]['ex_parent']]) : 0, 'type' => 0)); } // Save elements $arItems = array(array('fname' => 'ml01.jpg', 'name' => GetMessage('ML_IT_NAME_1'), 'ex_cols' => array(2)), array('fname' => 'ml02.jpg', 'name' => GetMessage('ML_IT_NAME_2'), 'ex_cols' => array(1)), array('fname' => 'ml03.jpg', 'name' => GetMessage('ML_IT_NAME_3'), 'ex_cols' => array(2)), array('fname' => 'ml04.jpg', 'name' => GetMessage('ML_IT_NAME_4'), 'ex_cols' => array(1)), array('fname' => 'ml05.jpg', 'name' => GetMessage('ML_IT_NAME_5'), 'ex_cols' => array(2)), array('fname' => 'ml06.jpg', 'name' => GetMessage('ML_IT_NAME_6'), 'ex_cols' => array(1, 2)), array('fname' => 'ml07.jpg', 'name' => GetMessage('ML_IT_NAME_7'), 'ex_cols' => array(1, 2)), array('fname' => 'ml08.jpg', 'name' => GetMessage('ML_IT_NAME_8'), 'ex_cols' => array(1)), array('fname' => 'ml09.jpg', 'name' => GetMessage('ML_IT_NAME_9'), 'ex_cols' => array(0, 1)), array('fname' => 'ml10.jpg', 'name' => GetMessage('ML_IT_NAME_10'), 'ex_cols' => array(0, 1))); for ($i = 0, $l = count($arItems); $i < $l; $i++) { $path = $source_base . 'files/' . $arItems[$i]['fname']; $arCols = array(); for ($j = 0, $n = count($arItems[$i]['ex_cols']); $j < $n; $j++) { $arCols[] = $arExCols[$arItems[$i]['ex_cols'][$j]]; } CMedialibItem::Edit(array('path' => $path, 'arFields' => array('NAME' => $arItems[$i]['name'], 'DESCRIPTION' => '', 'KEYWORDS' => ''), 'arCollections' => $arCols)); }
<div class="container"> <div class="container-hold container-hold-index"> <!-- Left column starts here --> <div class="blog-col"> <div class="blocl-type01"> <div class="container"> <div class="heading-blog"> <p class="cert_title">Сертификаты</p> <a class="cert_title_link" href="/about/sertifikaty/">Все сертификаты</a> </div> <div class="slideshow"> <ul class="slides"> <?php CModule::IncludeModule("fileman"); CMedialib::Init(); $arItems = CMedialibItem::GetList(array('arCollections' => array("0" => 3))); // test_dump("ABCDFGGWEWEF"); // test_dump($arItems); foreach ($arItems as $image) { $resized_src = GetResizedImage($image["SOURCE_ID"], 220, 270)["src"]; if (!$resized_src) { $resized_src = $image["PATH"]; } ?> <li class="slide"> <a id="single_cert_image" href="<?php echo $image["PATH"]; ?> "> <img src="<?php echo $resized_src;
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } if ($arParams["INCLUDE_JQUERY"] == "Y") { $APPLICATION->AddHeadScript("/bitrix/components/aprof/lenta_zoom/js/jquery-1.7.min.js"); } CModule::IncludeModule("fileman"); CMedialib::Init(); $arElements = CMedialibItem::GetList(array("arCollections" => array($arParams["MEDIA_ID"]))); $max_w = $arParams["SLIDE_WIDTH"]; $max_h = $arParams["SLIDE_HEIGHT"]; if ($arParams["MEDIA_SORT_FIELD"] != "DESCRIPTION" && $arParams["MEDIA_SORT_FIELD"] != "KEYWORDS") { unset($arParams["MEDIA_SORT_FIELD"]); } if ($arParams["MEDIA_SORT_ORDER"] != "DESC") { $arParams["MEDIA_SORT_ORDER"] = "ASC"; } if (strlen($arParams["MEDIA_SORT_FIELD"]) > 0) { foreach ($arElements as $arElement) { if (strlen($arElement[$arParams["MEDIA_SORT_FIELD"]]) > 0) { $sort[$arElement[$arParams["MEDIA_SORT_FIELD"]]] = $arElement; } else { $sort[] = $arElement; } } if ($arParams["MEDIA_SORT_ORDER"] == "ASC") { ksort($sort); } else { krsort($sort);