function handleDirectory($dirName) { $dir = dir($dirName); /* @var $dir Directory */ $fileNames = array(); $errors = array(); while (false !== ($fileName = $dir->read())) { $filePath = realpath("{$dirName}/{$fileName}"); if ($fileName[0] == '.' || is_dir($filePath) || !preg_match('/^\\d+\\.\\w+\\.ini$/', $fileName)) { continue; } KalturaLog::debug("Validate file [{$filePath}]"); $objectConfigurations = parse_ini_file($filePath, true); if (!is_array($objectConfigurations)) { $errors[] = "Content file [{$filePath}] is not a valid ini file"; } $matches = null; if (preg_match_all('/@[A-Z_0-9]+@/', file_get_contents($filePath), $matches) > 0) { $errors[] = "Content file [{$filePath}] contains place holders: " . implode("\n\t", $matches[0]); } list($order, $objectType, $fileExtension) = explode('.', $fileName, 3); if ($fileExtension == 'ini') { $fileNames[] = $fileName; } } $dir->close(); if (count($errors)) { KalturaLog::err(implode("\n\n", $errors)); exit(-3); } sort($fileNames); KalturaLog::info("Handling files [" . print_r($fileNames, true) . "]"); foreach ($fileNames as $fileName) { handleFile(realpath("{$dirName}/{$fileName}")); } }
function simpleUploadHandler($arParams, $arResult = array()) { global $APPLICATION; $APPLICATION->RestartBuffer(); $sTmpPath = CImageUploader::SetTmpPath($_REQUEST["PackageGuid"], $arParams["PATH_TO_TMP"]); $savedData = CImageUploader::GetSavedData(); if ($savedData['SECTION_ID']) { unset($savedData['SECTION_ID']); CImageUploader::SetSavedData($savedData); } onBeforeUpload(array('pathToTmp' => $arParams["PATH_TO_TMP"], 'arParams' => $arParams, "~arResult" => $arResult, 'sessid' => bitrix_sessid(), 'packageFields' => array('photo_album_id' => $_POST['photo_album_id'], 'new_album_name' => $_POST['new_album_name'], 'photo_resize_size' => intVal($_POST['photo_resize_size'])))); $files = $_FILES['photos']; $file_count = 0; if (!empty($files)) { if (!is_array($files['name']) && is_string($files['name'])) { $files = array('name' => array($files['name']), 'type' => array($files['type']), 'tmp_name' => array($files['tmp_name']), 'error' => array($files['error']), 'size' => array($files['size'])); } $file_count = count($files['name']); } if ($arParams['WATERMARK_RULES'] == 'ALL') { $arWatermark = array('type' => strtolower($arParams['WATERMARK_TYPE']), 'position' => $arParams['WATERMARK_POSITION']); if ($arParams['WATERMARK_TYPE'] == 'TEXT') { $arWatermark['coefficient'] = $arParams['WATERMARK_SIZE']; $arWatermark['text'] = trim($arParams['WATERMARK_TEXT']); $arWatermark['font'] = trim($arParams['PATH_TO_FONT']); $arWatermark['color'] = trim($arParams['WATERMARK_COLOR']); $arWatermark['use_copyright'] = "N"; } else { $arWatermark['file'] = $arParams['WATERMARK_FILE']; $arWatermark['alpha_level'] = $arParams['WATERMARK_TRANSPARENCY']; $arWatermark['size'] = 'real'; $arWatermark['fill'] = $arParams['WATERMARK_FILE_ORDER'] == 'usual' ? 'exact' : $arParams['WATERMARK_FILE_ORDER']; } } elseif ($_POST['photo_watermark_use'] == 'Y') { $arWatermark = array('type' => $_POST['photo_watermark_type'], 'text' => $_POST['photo_watermark_text'], 'font' => $arParams['PATH_TO_FONT'], 'position' => $_POST['photo_watermark_position'], 'color' => $_POST['photo_watermark_color'], 'size' => $_POST['photo_watermark_size'], 'fill' => 'resize', 'file' => $_SERVER["DOCUMENT_ROOT"] . $_POST['photo_watermark_path'], 'alpha_level' => $_POST['photo_watermark_opacity'], 'use_copyright' => $_POST["photo_watermark_copyright"] == "Y" ? "Y" : "N"); } else { $arWatermark = array(); } $arIds = array(); for ($i = 0; $i < $file_count; $i++) { $Info = array('name' => $files['name'][$i], 'filename' => $files['name'][$i], 'description' => '', 'tags' => ''); $arFiles = array(); $name_i = $files['name'][$i]; $type_i = $files['type'][$i]; $tmp_name_i = $files['tmp_name'][$i]; $error_i = $files['error'][$i]; $size_i = $files['size'][$i]; if ($size_i > 0 && $arParams["UPLOAD_MAX_FILE_SIZE"] > 0 && $size_i > $arParams["UPLOAD_MAX_FILE_SIZE"]) { CImageUploader::SaveError(array(array("file" => $name_i, "id" => "BXPH_FUNC_HANDLE_LARGE_SIZE", "text" => GetMessage('P_WM_IMG_ERROR04')))); continue; } if ($type_i && strpos(strtolower($type_i), 'image') === false) { CImageUploader::SaveError(array(array("file" => $name_i, "id" => "BXPH_FUNC_HANDLE_TYPE", "text" => GetMessage('P_WM_IMG_ERROR02')))); continue; } $ext_i = GetFileExtension($name_i); $name_i = GetFileNameWithoutExtension($name_i); $name_i_ = preg_replace("/[^a-zA-Z0-9_]/i", "", $name_i); if ($name_i_ != $name_i) { $name_i = ($name_i_ == '' ? substr(md5(mt_rand()), 0, 6) : '') . $name_i_; } // TODO: exif, iptc //$exif = CFile::ExtractImageExif($tmp_name_i); //$iptc = CFile::ExtractImageIPTC($tmp_name_i); $thumbSize = round($arParams["THUMBNAIL_SIZE"] * 1.8); foreach ($arParams['converters'] as $key => $val) { $destPath = $sTmpPath . $name_i . "_" . $key . "." . $ext_i; if ($val["code"] == "real_picture") { $size = intVal($_POST['photo_resize_size']); if ($arParams['ORIGINAL_SIZE'] && $arParams['ORIGINAL_SIZE'] > 0 && ($arParams['ORIGINAL_SIZE'] < $size || $size <= 0)) { $size = $arParams['ORIGINAL_SIZE']; } $arSize = array('width' => $size, 'height' => $size); $jpegQuality = $arParams['JPEG_QUALITY']; } else { if ($val["code"] == "thumbnail") { $arSize = array('width' => $thumbSize, 'height' => $thumbSize); $jpegQuality = $arParams['JPEG_QUALITY1']; } else { $arSize = array('width' => intVal($val['width']), 'height' => intVal($val['height'])); } } if (!$jpegQuality || $jpegQuality < 20) { $jpegQuality = false; } $arCurWatermark = $arSize['width'] > $arParams['WATERMARK_MIN_PICTURE_SIZE'] || $arSize['height'] > $arParams['WATERMARK_MIN_PICTURE_SIZE'] ? $arWatermark : array(); $res = CFile::ResizeImageFile($tmp_name_i, $destPath, $arSize, BX_RESIZE_IMAGE_PROPORTIONAL, $arCurWatermark, $jpegQuality, array()); $arFiles[] = array('name' => $files['name'][$i], 'tmp_name' => $destPath, 'errors' => $files['error'][$i], 'type' => $files['type'][$i], 'size' => '', 'mode' => $val["code"], 'width' => '', 'height' => '', 'path' => $destPath); } $elementId = handleFile($Info, $arFiles, array('arParams' => $arParams, "~arResult" => $arResult)); if ($elementId) { $arIds[] = $elementId; } foreach ($arFiles as $arFile) { if (file_exists($arFile['tmp_name'])) { unlink($arFile['tmp_name']); } } } $jsResFiles = array(); if (count($arIds) > 0) { $rsElement = CIBlockElement::GetList(array(), array("ID" => $arIds), false, false, array("ID", "PREVIEW_PICTURE")); while ($arElement = $rsElement->Fetch()) { $arFile = CFile::GetFileArray($arElement["PREVIEW_PICTURE"]); $jsResFiles[$arFile['ORIGINAL_NAME']] = array('ID' => $arElement["ID"], 'PATH' => $arFile['SRC'], 'WIDTH' => $arFile['WIDTH'], 'HEIGHT' => $arFile['HEIGHT'], 'NAME' => $arFile['FILE_NAME']); } } $savedData = CImageUploader::GetSavedData(); if ($savedData['NEW_SECTION_NAME'] && $savedData['SECTION_ID'] > 0) { $newSectionName = $savedData['NEW_SECTION_NAME']; unset($savedData['NEW_SECTION_NAME']); CImageUploader::SetSavedData($savedData); } onAfterUpload(array('arParams' => $arParams, "~arResult" => $arResult)); // Update redirect url $REDIRECT_URL = CComponentEngine::MakePathFromTemplate($arParams["~SECTION_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $savedData["SECTION_ID"])); //$REDIRECT_URL = $REDIRECT_URL.(strpos($REDIRECT_URL, "?") === false ? "?" : "&")."uploader_redirect=Y&sessid=".bitrix_sessid(); ?> <script>top.bxiu_simple_res = { error: <?php echo $savedData['arError'] && count($savedData['arError']) > 0 ? CUtil::PhpToJSObject($savedData['arError']) : '""'; ?> , files: <?php echo CUtil::PhpToJSObject($jsResFiles); ?> , redirectUrl: '<?php echo CUtil::JSEscape($REDIRECT_URL); ?> ' <?php if (!empty($newSectionName)) { ?> ,newSection: { id: <?php echo intVal($savedData['SECTION_ID']); ?> , title: '<?php echo CUtil::JSEscape($newSectionName); ?> ' } <?php } ?> };</script> <?php $savedData['arError'] = array(); CImageUploader::SetSavedData($savedData); die; }
function handleDir($src_dir, $dest_dir) { $dirlist = opendir($src_dir); if (!is_dir($dest_dir)) { mkdir($dest_dir); } while ($file = readdir($dirlist)) { if ($file != '.' && $file != '..' && $file != '.svn') { $newpath_src = $src_dir . '/' . $file; $newpath_dest = $dest_dir . "/" . $file; if (is_dir($newpath_src)) { handleDir($newpath_src, $newpath_dest); } else { handleFile($newpath_src, $newpath_dest); } } } closedir($dirlist); }