Пример #1
0
 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;
 }
Пример #2
0
    public static function EditItem($Params)
    {
        $bOpName = $Params['id'] ? 'medialib_edit_item' : 'medialib_new_item';
        $arCols_ = explode(',', $Params['item_collections']);
        $arCols = array();
        for ($i = 0, $l = count($arCols_); $i < $l; $i++) {
            if (intVal($arCols_[$i]) > 0 && CMedialib::CanDoOperation($bOpName, $arCols_[$i])) {
                // Check access
                $arCols[] = intVal($arCols_[$i]);
            }
        }
        if (count($arCols) > 0) {
            if ($Params['source_type'] == 'PC') {
                $Params['path'] = false;
            } else {
                if ($Params['source_type'] == 'FD') {
                    $Params['file'] = false;
                }
            }
            $res = CMedialibItem::Edit(array('file' => $Params['file'], 'path' => $Params['path'], 'arFields' => array('ID' => $Params['id'], 'NAME' => $Params['name'], 'DESCRIPTION' => $Params['desc'], 'KEYWORDS' => $Params['keywords']), 'arCollections' => $arCols));
            if ($res) {
                if (!isset($res['DATE_UPDATE']) && isset($res['TIMESTAMP_X'])) {
                    $res['DATE_UPDATE'] = $res['TIMESTAMP_X'];
                }
                ?>
			<script>
			top.bx_req_res = {
				id: <?php 
                echo intVal($res['ID']);
                ?>
,
				name: '<?php 
                echo CMedialib::Escape($res['NAME']);
                ?>
',
				desc: '<?php 
                echo CMedialib::Escape($res['DESCRIPTION']);
                ?>
',
				keywords: '<?php 
                echo CMedialib::Escape($res['KEYWORDS']);
                ?>
',
				<?php 
                if (isset($res['FILE_NAME'])) {
                    ?>
file_name: '<?php 
                    echo CMedialib::Escape($res['FILE_NAME']);
                    ?>
',<?php 
                }
                ?>
				<?php 
                if (isset($res['DATE_UPDATE'])) {
                    ?>
date_mod: '<?php 
                    echo CMedialib::GetUsableDate($res['DATE_UPDATE']);
                    ?>
',<?php 
                }
                ?>
				<?php 
                if (isset($res['FILE_SIZE'])) {
                    ?>
file_size: '<?php 
                    echo CMedialib::GetUsableSize($res['FILE_SIZE']);
                    ?>
',<?php 
                }
                ?>
				<?php 
                if (isset($res['THUMB_PATH'])) {
                    ?>
thumb_path: '<?php 
                    echo CMedialib::Escape($res['THUMB_PATH']);
                    ?>
',<?php 
                }
                ?>
				<?php 
                if (isset($res['PATH'])) {
                    ?>
path: '<?php 
                    echo CMedialib::Escape($res['PATH']);
                    ?>
',<?php 
                }
                ?>
				<?php 
                if (isset($res['TYPE'])) {
                    ?>
type: '<?php 
                    echo $res['TYPE'];
                    ?>
',<?php 
                }
                ?>
				height: <?php 
                echo $res['HEIGHT'] ? $res['HEIGHT'] : '0';
                ?>
,
				width: <?php 
                echo $res['WIDTH'] ? $res['WIDTH'] : '0';
                ?>
			};

			top._ml_items_colls = [<?php 
                for ($i = 0, $l = count($arCols); $i < $l; $i++) {
                    echo $arCols[$i] . ($i != $l - 1 ? ',' : '');
                }
                ?>
];
			</script>
			<?php 
            } else {
                ?>
			<script>top.bx_req_res = false;</script>
			<?php 
            }
        }
    }
Пример #3
0
			$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'));
Пример #4
0
<?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));
}