function BaseCheckFields($val) { $arErrors = array(); if (!is_array($val)) { $val = array(); } // Check uploaded file if ($val["B_NEW_FILE"] != "N" && isset($val["FILE"])) { if ($val["FILE"]["error"] == 1 || $val["FILE"]["error"] == 2) { $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_SIZE_ERROR", array('#FILE_NAME#' => $pathto)) . "\n"; } if (strlen($val["FILE"]["tmp_name"]) > 0) { $name = $val["FILE"]["name"]; $name = preg_replace("/[^a-zA-Z0-9_:\\.]/is", "_", $name); $ext = GetFileExtension($name); if (strlen($ext) == 0 || HasScriptExtension($name) || substr($name, 0, 1) == ".") { $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_INCORRECT_EXT", array("#EXT#" => strtoupper($ext))); } elseif (!is_uploaded_file($val["FILE"]["tmp_name"])) { $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_UPLOAD_ERROR"); } else { $quota = new CDiskQuota(); if (!$quota->checkDiskQuota(array("FILE_SIZE" => $val["FILE"]["size"]))) { $arErrors[] = GetMessage("IBLOCK_PROP_VIDEO_QUOTE_ERROR") . "\n"; } } } } return $arErrors; }
function ResizeImageGet($file, $arSize, $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL, $bInitSizes = false, $arFilters = false, $bImmediate = false, $jpgQuality = false) { if (!is_array($file) && intval($file) > 0) { $file = CFile::GetFileArray($file); } if (!is_array($file) || !array_key_exists("FILE_NAME", $file) || strlen($file["FILE_NAME"]) <= 0) { return false; } if ($resizeType != BX_RESIZE_IMAGE_EXACT && $resizeType != BX_RESIZE_IMAGE_PROPORTIONAL_ALT) { $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL; } if (!is_array($arSize)) { $arSize = array(); } if (!array_key_exists("width", $arSize) || intval($arSize["width"]) <= 0) { $arSize["width"] = 0; } if (!array_key_exists("height", $arSize) || intval($arSize["height"]) <= 0) { $arSize["height"] = 0; } $arSize["width"] = intval($arSize["width"]); $arSize["height"] = intval($arSize["height"]); $uploadDirName = COption::GetOptionString("main", "upload_dir", "upload"); $imageFile = "/" . $uploadDirName . "/" . $file["SUBDIR"] . "/" . $file["FILE_NAME"]; $arImageSize = false; $bFilters = is_array($arFilters) && !empty($arFilters); if (($arSize["width"] <= 0 || $arSize["width"] >= $file["WIDTH"]) && ($arSize["height"] <= 0 || $arSize["height"] >= $file["HEIGHT"])) { if ($bFilters) { //Only filters. Leave size unchanged $arSize["width"] = $file["WIDTH"]; $arSize["height"] = $file["HEIGHT"]; $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL; } else { global $arCloudImageSizeCache; $arCloudImageSizeCache[$file["SRC"]] = array($file["WIDTH"], $file["HEIGHT"]); return array("src" => $file["SRC"], "width" => intval($file["WIDTH"]), "height" => intval($file["HEIGHT"]), "size" => $file["FILE_SIZE"]); } } $io = CBXVirtualIo::GetInstance(); $cacheImageFile = "/" . $uploadDirName . "/resize_cache/" . $file["SUBDIR"] . "/" . $arSize["width"] . "_" . $arSize["height"] . "_" . $resizeType . (is_array($arFilters) ? md5(serialize($arFilters)) : "") . "/" . $file["FILE_NAME"]; $cacheImageFileCheck = $cacheImageFile; if ($file["CONTENT_TYPE"] == "image/bmp") { $cacheImageFileCheck .= ".jpg"; } static $cache = array(); $cache_id = $cacheImageFileCheck; if (isset($cache[$cache_id])) { return $cache[$cache_id]; } elseif (!file_exists($io->GetPhysicalName($_SERVER["DOCUMENT_ROOT"] . $cacheImageFileCheck))) { /****************************** QUOTA ******************************/ $bDiskQuota = true; if (COption::GetOptionInt("main", "disk_space") > 0) { $quota = new CDiskQuota(); $bDiskQuota = $quota->checkDiskQuota($file); } /****************************** QUOTA ******************************/ if ($bDiskQuota) { if (!is_array($arFilters)) { $arFilters = array(array("name" => "sharpen", "precision" => 15)); } $sourceImageFile = $_SERVER["DOCUMENT_ROOT"] . $imageFile; $cacheImageFileTmp = $_SERVER["DOCUMENT_ROOT"] . $cacheImageFile; $bNeedResize = true; $callbackData = null; foreach (GetModuleEvents("main", "OnBeforeResizeImage", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($file, array($arSize, $resizeType, array(), false, $arFilters, $bImmediate), &$callbackData, &$bNeedResize, &$sourceImageFile, &$cacheImageFileTmp))) { break; } } if ($bNeedResize && CFile::ResizeImageFile($sourceImageFile, $cacheImageFileTmp, $arSize, $resizeType, array(), $jpgQuality, $arFilters)) { $cacheImageFile = substr($cacheImageFileTmp, strlen($_SERVER["DOCUMENT_ROOT"])); /****************************** QUOTA ******************************/ if (COption::GetOptionInt("main", "disk_space") > 0) { CDiskQuota::updateDiskQuota("file", filesize($io->GetPhysicalName($cacheImageFileTmp)), "insert"); } /****************************** QUOTA ******************************/ } else { $cacheImageFile = $imageFile; } foreach (GetModuleEvents("main", "OnAfterResizeImage", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($file, array($arSize, $resizeType, array(), false, $arFilters), &$callbackData, &$cacheImageFile, &$cacheImageFileTmp, &$arImageSize))) { break; } } } else { $cacheImageFile = $imageFile; } $cacheImageFileCheck = $cacheImageFile; } if ($bInitSizes && !is_array($arImageSize)) { $arImageSize = CFile::GetImageSize($_SERVER["DOCUMENT_ROOT"] . $cacheImageFileCheck); $f = $io->GetFile($_SERVER["DOCUMENT_ROOT"] . $cacheImageFileCheck); $arImageSize[2] = $f->GetFileSize(); } $cache[$cache_id] = array("src" => $cacheImageFileCheck, "width" => intval($arImageSize[0]), "height" => intval($arImageSize[1]), "size" => $arImageSize[2]); return $cache[$cache_id]; }
function CheckFields(&$arFields, $ID = false) { global $DB, $APPLICATION; $this->LAST_ERROR = ""; if (($ID === false || is_set($arFields, "NAME")) && strlen($arFields["NAME"]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION") . "<br>"; } if (is_array($arFields["PICTURE"]) && array_key_exists("bucket", $arFields["PICTURE"]) && is_object($arFields["PICTURE"]["bucket"])) { //This is trusted image from xml import } elseif (isset($arFields["PICTURE"]) && is_array($arFields["PICTURE"]) && isset($arFields["PICTURE"]["name"])) { $error = CFile::CheckImageFile($arFields["PICTURE"]); if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } } if (is_array($arFields["DETAIL_PICTURE"]) && array_key_exists("bucket", $arFields["DETAIL_PICTURE"]) && is_object($arFields["DETAIL_PICTURE"]["bucket"])) { //This is trusted image from xml import } elseif (isset($arFields["DETAIL_PICTURE"]) && is_array($arFields["DETAIL_PICTURE"]) && isset($arFields["DETAIL_PICTURE"]["name"])) { $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]); if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } } $arIBlock = false; $arThis = false; if ($ID === false) { if (!array_key_exists("IBLOCK_ID", $arFields)) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>"; } else { $arIBlock = CIBlock::GetArrayByID($arFields["IBLOCK_ID"]); if (!$arIBlock) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>"; } } } else { $rsThis = $DB->Query("SELECT ID, IBLOCK_ID, DETAIL_PICTURE, PICTURE FROM b_iblock_section WHERE ID = " . intval($ID)); $arThis = $rsThis->Fetch(); if (!$arThis) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_ID", array("#ID#" => intval($ID))) . "<br>"; } else { $arIBlock = CIBlock::GetArrayByID($arThis["IBLOCK_ID"]); if (!$arIBlock) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>"; } } } $arParent = false; $IBLOCK_SECTION_ID = isset($arFields["IBLOCK_SECTION_ID"]) ? intval($arFields["IBLOCK_SECTION_ID"]) : 0; if ($IBLOCK_SECTION_ID > 0 && strlen($this->LAST_ERROR) <= 0) { $rsParent = $DB->Query("SELECT ID, IBLOCK_ID FROM b_iblock_section WHERE ID = " . $IBLOCK_SECTION_ID); $arParent = $rsParent->Fetch(); if (!$arParent) { $this->LAST_ERROR = GetMessage("IBLOCK_BAD_BLOCK_SECTION_PARENT") . "<br>"; } } if ($arParent && $arIBlock) { if ($arParent["IBLOCK_ID"] != $arIBlock["ID"]) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_ID_PARENT") . "<br>"; } } if ($arParent && strlen($this->LAST_ERROR) <= 0) { $rch = $DB->Query("\n\t\t\t\tSELECT 'x'\n\t\t\t\tFROM\n\t\t\t\t\tb_iblock_section bsto\n\t\t\t\t\t,b_iblock_section bsfrom\n\t\t\t\tWHERE\n\t\t\t\t\tbsto.ID = " . $arParent["ID"] . "\n\t\t\t\t\tAND bsfrom.ID = " . intval($ID) . "\n\t\t\t\t\tAND bsto.LEFT_MARGIN >= bsfrom.LEFT_MARGIN\n\t\t\t\t\tAND bsto.LEFT_MARGIN <= bsfrom.RIGHT_MARGIN\n\t\t\t"); if ($rch->Fetch()) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_RECURSE") . "<br>"; } } if ($arIBlock) { if (array_key_exists("CODE", $arFields) && strlen($arFields["CODE"]) && is_array($arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"]) && $arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y") { $res = $DB->Query("\n\t\t\t\t\tSELECT ID\n\t\t\t\t\tFROM b_iblock_section\n\t\t\t\t\tWHERE IBLOCK_ID = " . $arIBlock["ID"] . "\n\t\t\t\t\tAND CODE = '" . $DB->ForSQL($arFields["CODE"]) . "'\n\t\t\t\t\tAND ID <> " . intval($ID)); if ($res->Fetch()) { $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_SECTION_CODE") . "<br>"; } } foreach ($arIBlock["FIELDS"] as $FIELD_ID => $field) { if (!preg_match("/^SECTION_(.+)\$/", $FIELD_ID, $match)) { continue; } $FIELD_ID = $match[1]; if ($field["IS_REQUIRED"] === "Y") { switch ($FIELD_ID) { case "NAME": case "DESCRIPTION_TYPE": //We should never check for this fields break; case "PICTURE": $field["NAME"] = GetMessage("IBLOCK_FIELD_PICTURE"); case "DETAIL_PICTURE": if ($arThis && $arThis[$FIELD_ID] > 0) { //There was an picture so just check that it is not deleted if (array_key_exists($FIELD_ID, $arFields) && is_array($arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["del"] === "Y") { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } else { //There was NO picture so it MUST be present if (!array_key_exists($FIELD_ID, $arFields)) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } elseif (is_array($arFields[$FIELD_ID])) { if ($arFields[$FIELD_ID]["del"] === "Y" || array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0 || $arFields[$FIELD_ID]["size"] <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } else { if (intval($arFields[$FIELD_ID]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } } break; default: if ($ID === false || array_key_exists($FIELD_ID, $arFields)) { if (is_array($arFields[$FIELD_ID])) { $val = implode("", $arFields[$FIELD_ID]); } else { $val = $arFields[$FIELD_ID]; } if (strlen($val) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } break; } } } } $APPLICATION->ResetException(); if ($ID === false) { $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionAdd"); } else { $arFields["ID"] = $ID; $arFields["IBLOCK_ID"] = $arIBlock["ID"]; $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionUpdate"); } /****************************** QUOTA ******************************/ if (empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) { $quota = new CDiskQuota(); if (!$quota->checkDiskQuota($arFields)) { $this->LAST_ERROR = $quota->LAST_ERROR; } } /****************************** QUOTA ******************************/ while ($arEvent = $db_events->Fetch()) { $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields)); if ($bEventRes === false) { if ($err = $APPLICATION->GetException()) { $this->LAST_ERROR .= $err->GetString() . "<br>"; } else { $APPLICATION->ThrowException("Unknown error"); $this->LAST_ERROR .= "Unknown error.<br>"; } break; } } if (strlen($this->LAST_ERROR) > 0) { return false; } return true; }
function CheckFields(&$arFields, $ID = false, $bCheckDiskQuota = true) { global $DB, $APPLICATION, $USER; $this->LAST_ERROR = ""; $APPLICATION->ResetException(); if ($ID === false) { $db_events = GetModuleEvents("iblock", "OnStartIBlockElementAdd", true); } else { $arFields["ID"] = $ID; $db_events = GetModuleEvents("iblock", "OnStartIBlockElementUpdate", true); } foreach ($db_events as $arEvent) { $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields)); if ($bEventRes === false) { break; } } if (($ID === false || is_set($arFields, "NAME")) && strlen($arFields["NAME"]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ELEMENT_NAME") . "<br>"; } if (isset($arFields["ACTIVE_FROM"]) && $arFields["ACTIVE_FROM"] != '' && !$DB->IsDate($arFields["ACTIVE_FROM"], false, LANG, "FULL")) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_FROM") . "<br>"; } if (isset($arFields["ACTIVE_TO"]) && $arFields["ACTIVE_TO"] != '' && !$DB->IsDate($arFields["ACTIVE_TO"], false, LANG, "FULL")) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_TO") . "<br>"; } if (is_set($arFields, "PREVIEW_PICTURE")) { if (is_array($arFields["PREVIEW_PICTURE"]) && array_key_exists("bucket", $arFields["PREVIEW_PICTURE"]) && is_object($arFields["PREVIEW_PICTURE"]["bucket"])) { //This is trusted image from xml import } elseif (is_array($arFields["PREVIEW_PICTURE"])) { $error = CFile::CheckImageFile($arFields["PREVIEW_PICTURE"]); if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } elseif (($error = CFile::checkForDb($arFields, "PREVIEW_PICTURE")) !== "") { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>" . $error . "<br>"; } } elseif (intval($arFields["PREVIEW_PICTURE"]) > 0) { if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["PREVIEW_PICTURE"], $ID, "PREVIEW", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>"; } } } if (is_set($arFields, "DETAIL_PICTURE")) { if (is_array($arFields["DETAIL_PICTURE"]) && array_key_exists("bucket", $arFields["DETAIL_PICTURE"]) && is_object($arFields["DETAIL_PICTURE"]["bucket"])) { //This is trusted image from xml import } elseif (is_array($arFields["DETAIL_PICTURE"])) { $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]); if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } elseif (($error = CFile::checkForDb($arFields, "DETAIL_PICTURE")) !== "") { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>" . $error . "<br>"; } } elseif (intval($arFields["DETAIL_PICTURE"]) > 0) { if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["DETAIL_PICTURE"], $ID, "DETAIL", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>"; } } } if (array_key_exists("TAGS", $arFields) && CModule::IncludeModule('search')) { $arFields["TAGS"] = implode(", ", tags_prepare($arFields["TAGS"])); } if ($ID === false && !is_set($arFields, "IBLOCK_ID")) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>"; } if ($ID !== false && is_set($arFields, "XML_ID") && strlen($arFields["XML_ID"]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_EXTERNAL_CODE") . "<br>"; } //Find out IBLOCK_ID from fields or from element $IBLOCK_ID = intval($arFields["IBLOCK_ID"]); if ($IBLOCK_ID <= 0) { $IBLOCK_ID = 0; $res = $DB->Query("SELECT IBLOCK_ID FROM b_iblock_element WHERE ID=" . IntVal($ID)); if ($ar = $res->Fetch()) { $IBLOCK_ID = (int) $ar["IBLOCK_ID"]; } } //Read iblock metadata static $IBLOCK_CACHE = array(); if (!isset($IBLOCK_CACHE[$IBLOCK_ID])) { if ($IBLOCK_ID > 0) { $IBLOCK_CACHE[$IBLOCK_ID] = CIBlock::GetArrayByID($IBLOCK_ID); } else { $IBLOCK_CACHE[$IBLOCK_ID] = false; } } if ($IBLOCK_CACHE[$IBLOCK_ID]) { $arFields["IBLOCK_ID"] = $IBLOCK_ID; } else { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>"; } if (is_set($arFields, 'IBLOCK_SECTION') && !empty($arFields['IBLOCK_SECTION'])) { if (!is_array($arFields['IBLOCK_SECTION'])) { $arFields['IBLOCK_SECTION'] = array($arFields['IBLOCK_SECTION']); } $arFields['IBLOCK_SECTION'] = array_filter($arFields['IBLOCK_SECTION']); } if ($IBLOCK_CACHE[$IBLOCK_ID]) { $ar = $IBLOCK_CACHE[$IBLOCK_ID]["FIELDS"]; if (is_array($ar)) { $WF_PARENT_ELEMENT_ID = isset($arFields["WF_PARENT_ELEMENT_ID"]) ? intval($arFields["WF_PARENT_ELEMENT_ID"]) : 0; if (($WF_PARENT_ELEMENT_ID == 0 || $WF_PARENT_ELEMENT_ID == intval($ID)) && array_key_exists("CODE", $arFields) && strlen($arFields["CODE"]) > 0 && is_array($ar["CODE"]["DEFAULT_VALUE"]) && $ar["CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y") { $res = $DB->Query("\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_iblock_element\n\t\t\t\t\t\tWHERE IBLOCK_ID = " . $IBLOCK_ID . "\n\t\t\t\t\t\tAND CODE = '" . $DB->ForSQL($arFields["CODE"]) . "'\n\t\t\t\t\t\tAND WF_PARENT_ELEMENT_ID IS NULL\n\t\t\t\t\t\tAND ID <> " . intval($ID)); if ($res->Fetch()) { $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_ELEMENT_CODE") . "<br>"; } } $arOldElement = false; foreach ($ar as $FIELD_ID => $field) { if (preg_match("/^(SECTION_|LOG_)/", $FIELD_ID)) { continue; } if ($field["IS_REQUIRED"] === "Y") { switch ($FIELD_ID) { case "NAME": case "ACTIVE": case "PREVIEW_TEXT_TYPE": case "DETAIL_TEXT_TYPE": case "SORT": //We should never check for this fields break; case "IBLOCK_SECTION": if ($ID === false || array_key_exists($FIELD_ID, $arFields)) { $sum = 0; if (is_array($arFields[$FIELD_ID])) { foreach ($arFields[$FIELD_ID] as $k => $v) { if (intval($v) > 0) { $sum += intval($v); } } } else { $sum = intval($arFields[$FIELD_ID]); } if ($sum <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } break; case "PREVIEW_PICTURE": case "DETAIL_PICTURE": if ($ID !== false && !$arOldElement) { $rs = $DB->Query("SELECT PREVIEW_PICTURE, DETAIL_PICTURE from b_iblock_element WHERE ID = " . intval($ID)); $arOldElement = $rs->Fetch(); } if ($arOldElement && $arOldElement[$FIELD_ID] > 0) { //There was an picture so just check that it is not deleted if (array_key_exists($FIELD_ID, $arFields) && is_array($arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["del"] === "Y") { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } else { //There was NO picture so it MUST be present if (!array_key_exists($FIELD_ID, $arFields)) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } elseif (is_array($arFields[$FIELD_ID])) { if ($arFields[$FIELD_ID]["del"] === "Y" || array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0 || $arFields[$FIELD_ID]["size"] <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } else { if (intval($arFields[$FIELD_ID]) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } } break; default: if ($ID === false || array_key_exists($FIELD_ID, $arFields)) { if (is_array($arFields[$FIELD_ID])) { $val = implode("", $arFields[$FIELD_ID]); } else { $val = $arFields[$FIELD_ID]; } if (strlen($val) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>"; } } break; } } } } } if (array_key_exists("PROPERTY_VALUES", $arFields) && is_array($arFields["PROPERTY_VALUES"])) { //First "normalize" properties to form: //$arFields["PROPERTY_VALUES"][<PROPERTY_ID>][<PROPERTY_VALUE_ID>] => $value $arProperties = array(); foreach ($arFields["PROPERTY_VALUES"] as $key => $property_values) { $arProperties[$key] = array(); if (is_array($property_values)) { if (array_key_exists("VALUE", $property_values)) { $arProperties[$key][] = $property_values["VALUE"]; } elseif (array_key_exists("tmp_name", $property_values)) { $arProperties[$key][] = $property_values; } else { foreach ($property_values as $key2 => $property_value) { if (is_array($property_value) && array_key_exists("VALUE", $property_value)) { //each of these may be "complex" $arProperties[$key][] = $property_value["VALUE"]; } else { //or simple $arProperties[$key][] = $property_value; } } } } else { $arProperties[$key][] = $property_values; } } foreach ($arProperties as $key => $property_values) { $arProperty = CIBlockProperty::GetPropertyArray($key, $IBLOCK_ID); if ($arProperty["USER_TYPE"] != "") { $arUserType = CIBlockProperty::GetUserType($arProperty["USER_TYPE"]); } else { $arUserType = array(); } if (array_key_exists("CheckFields", $arUserType)) { foreach ($property_values as $key2 => $property_value) { $arError = call_user_func_array($arUserType["CheckFields"], array($arProperty, array("VALUE" => $property_value))); if (is_array($arError)) { foreach ($arError as $err_mess) { $this->LAST_ERROR .= $err_mess . "<br>"; } } } } //Files check $bError = false; if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] == 'F') { //New element if ($ID === false) { $bError = true; foreach ($property_values as $key2 => $property_value) { if (is_array($property_value) && array_key_exists("tmp_name", $property_value) && array_key_exists("size", $property_value)) { if ($property_value['size'] > 0) { $bError = false; break; } } elseif (intval($property_value) > 0) { //This is history copy of the file $bError = false; break; } } } else { $dbProperty = CIBlockElement::GetProperty($arProperty["IBLOCK_ID"], $ID, "sort", "asc", array("ID" => $arProperty["ORIG_ID"], "EMPTY" => "N")); $bCount = 0; while ($a = $dbProperty->Fetch()) { if ($a["VALUE"] > 0) { $bCount++; } } foreach ($property_values as $key2 => $property_value) { if (is_array($property_value)) { if ($property_value['size'] > 0) { $bCount++; break; } elseif ($property_value['del'] == 'Y') { $bCount--; } } elseif (intval($property_value) > 0) { //This is history copy of the file $bCount++; break; } } $bError = $bCount <= 0; } } if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] != 'F') { $len = 0; foreach ($property_values as $key2 => $property_value) { if (array_key_exists("GetLength", $arUserType)) { $len += call_user_func_array($arUserType["GetLength"], array($arProperty, array("VALUE" => $property_value))); } else { $len += strlen($property_value); } if ($len > 0) { break; } } $bError = $len <= 0; } if ($bError) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_PROPERTY", array("#PROPERTY#" => $arProperty["NAME"])) . "<br>"; } // check file properties for correctness if ($arProperty['PROPERTY_TYPE'] == 'F') { $bImageOnly = False; $arImageExtentions = explode(",", strtoupper(CFile::GetImageExtensions())); if (strlen($arProperty["FILE_TYPE"])) { $bImageOnly = True; $arAvailTypes = explode(",", strtoupper($arProperty["FILE_TYPE"])); foreach ($arAvailTypes as $avail_type) { if (!in_array(trim($avail_type), $arImageExtentions)) { $bImageOnly = False; break; } } } foreach ($property_values as $key2 => $property_value) { if (!is_array($property_value) && intval($property_value) > 0 && intval($arFields["WF_PARENT_ELEMENT_ID"]) > 0) { if (CIBlockElement::DeleteFile($property_value, $ID, "PROPERTY", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_FILE_PROPERTY") . "<br>"; } } elseif (is_array($property_value)) { if (is_object($property_value["bucket"])) { //This is trusted image from xml import $error = ""; } else { if ($bImageOnly) { $error = CFile::CheckImageFile($property_value); } else { $error = CFile::CheckFile($property_value, 0, false, $arProperty["FILE_TYPE"]); } } //For user without edit php permissions //we allow only pictures upload if (!is_object($USER) || !$USER->IsAdmin()) { if (HasScriptExtension($property_value["name"])) { $error = GetMessage("FILE_BAD_TYPE") . " (" . $property_value["name"] . ")."; } } if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } } } } } } $APPLICATION->ResetException(); if ($ID === false) { $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementAdd", true); } else { $arFields["ID"] = $ID; $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementUpdate", true); } foreach ($db_events as $arEvent) { $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields)); if ($bEventRes === false) { if ($err = $APPLICATION->GetException()) { $this->LAST_ERROR .= $err->GetString() . "<br>"; } else { $APPLICATION->ThrowException("Unknown error"); $this->LAST_ERROR .= "Unknown error.<br>"; } break; } } /****************************** QUOTA ******************************/ if ($bCheckDiskQuota && empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) { $quota = new CDiskQuota(); if (!$quota->checkDiskQuota($arFields)) { $this->LAST_ERROR = $quota->LAST_ERROR; } } /****************************** QUOTA ******************************/ if (!empty($this->LAST_ERROR)) { return false; } return true; }
function UploadFile($Params) { $buffer = 'parent.oWaitWindow.Hide();'; $F = $Params['file']; $io = CBXVirtualIo::GetInstance(); if (isset($F["tmp_name"]) && strlen($F["tmp_name"]) > 0 && strlen($F["name"]) > 0 || is_uploaded_file($F["tmp_name"])) { global $APPLICATION, $USER; $strWarning = ''; $filename = $Params['filename']; $path = $Params['path']; $site = $Params['site']; $upload_and_open = $Params['upload_and_open']; $rootPath = CSite::GetSiteDocRoot($site); if ($filename == '') { $filename = $F["name"]; } $pathto = Rel2Abs($path, $filename); if (strlen($filename) > 0 && ($mess = self::CheckFileName($filename)) !== true) { $strWarning = $mess; } if ($strWarning == '') { $fn = $io->ExtractNameFromPath($pathto); if ($APPLICATION->GetFileAccessPermission(array($site, $pathto)) > "R" && ($USER->IsAdmin() || !HasScriptExtension($fn) && substr($fn, 0, 1) != "." && $io->ValidateFilenameString($fn))) { if (!$io->FileExists($rootPath . $pathto) || $_REQUEST["rewrite"] == "Y") { //************************** Quota **************************// $bQuota = true; if (COption::GetOptionInt("main", "disk_space") > 0) { $bQuota = false; $quota = new CDiskQuota(); if ($quota->checkDiskQuota(array("FILE_SIZE" => filesize($F["tmp_name"])))) { $bQuota = true; } } //************************** Quota **************************// if ($bQuota) { $io->Copy($F["tmp_name"], $rootPath . $pathto); $flTmp = $io->GetFile($rootPath . $pathto); $flTmp->MarkWritable(); if (COption::GetOptionInt("main", "disk_space") > 0) { CDiskQuota::updateDiskQuota("file", $flTmp->GetFileSize(), "copy"); } $buffer = 'setTimeout(function(){parent.oBXDialogControls.Uploader.OnAfterUpload("' . $filename . '", ' . ($upload_and_open == "Y" ? 'true' : 'false') . ');}, 50);'; } else { $strWarning = $quota->LAST_ERROR; } } else { $strWarning = GetMessage("FD_LOAD_EXIST_ALERT"); } } else { $strWarning = GetMessage("FD_LOAD_DENY_ALERT"); } } } else { $strWarning = GetMessage("FD_LOAD_ERROR_ALERT"); } if ($strWarning != '') { $buffer = 'alert("' . addslashes(htmlspecialcharsex($strWarning)) . '");'; } return '<script>' . $buffer . '</script>'; }
public function CheckFields(&$arFields, $ID = false) { /** @global CMain $APPLICATION */ global $APPLICATION; $this->LAST_ERROR = ""; $NAME = isset($arFields["NAME"]) ? $arFields["NAME"] : ""; if (($ID === false || array_key_exists("NAME", $arFields)) && strlen($NAME) <= 0) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_NAME") . "<br>"; } if ($ID === false && !is_set($arFields, "IBLOCK_TYPE_ID")) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE") . "<br>"; } if ($ID === false) { //For new record take default values $WORKFLOW = array_key_exists("WORKFLOW", $arFields) ? $arFields["WORKFLOW"] : "Y"; $BIZPROC = array_key_exists("BIZPROC", $arFields) ? $arFields["BIZPROC"] : "N"; } else { //For existing one read old values $arIBlock = CIBlock::GetArrayByID($ID); $WORKFLOW = array_key_exists("WORKFLOW", $arFields) ? $arFields["WORKFLOW"] : $arIBlock["WORKFLOW"]; $BIZPROC = array_key_exists("BIZPROC", $arFields) ? $arFields["BIZPROC"] : $arIBlock["BIZPROC"]; if ($BIZPROC != "Y") { $BIZPROC = "N"; } //This is cache compatibility issue } if ($WORKFLOW == "Y" && $BIZPROC == "Y") { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_WORKFLOW_AND_BIZPROC") . "<br>"; } if (is_set($arFields, "IBLOCK_TYPE_ID")) { $r = CIBlockType::GetByID($arFields["IBLOCK_TYPE_ID"]); if (!$r->Fetch()) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE_ID") . "<br>"; } } if (is_array($arFields["PICTURE"]) && array_key_exists("bucket", $arFields["PICTURE"]) && is_object($arFields["PICTURE"]["bucket"])) { //This is trusted image from xml import } elseif (isset($arFields["PICTURE"]) && is_array($arFields["PICTURE"]) && isset($arFields["PICTURE"]["name"])) { $error = CFile::CheckImageFile($arFields["PICTURE"]); if (strlen($error) > 0) { $this->LAST_ERROR .= $error . "<br>"; } } if ($ID === false && !is_set($arFields, "LID") || is_set($arFields, "LID") && (is_array($arFields["LID"]) && count($arFields["LID"]) <= 0 || !is_array($arFields["LID"]) && strlen($arFields["LID"]) <= 0)) { $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SITE_ID_NA") . "<br>"; } elseif (is_set($arFields, "LID")) { if (!is_array($arFields["LID"])) { $arFields["LID"] = array($arFields["LID"]); } foreach ($arFields["LID"] as $v) { $r = CSite::GetByID($v); if (!$r->Fetch()) { $this->LAST_ERROR .= "'" . $v . "' - " . GetMessage("IBLOCK_BAD_SITE_ID") . "<br>"; } } } $APPLICATION->ResetException(); if ($ID === false) { $db_events = GetModuleEvents("iblock", "OnBeforeIBlockAdd", true); } else { $arFields["ID"] = $ID; $db_events = GetModuleEvents("iblock", "OnBeforeIBlockUpdate", true); } foreach ($db_events as $arEvent) { $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields)); if ($bEventRes === false) { if ($err = $APPLICATION->GetException()) { $this->LAST_ERROR .= $err->GetString() . "<br>"; } else { $APPLICATION->ThrowException("Unknown error"); $this->LAST_ERROR .= "Unknown error.<br>"; } break; } } /****************************** QUOTA ******************************/ if (empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) { $quota = new CDiskQuota(); if (!$quota->checkDiskQuota($arFields)) { $this->LAST_ERROR = $quota->LAST_ERROR; } } /****************************** QUOTA ******************************/ if (strlen($this->LAST_ERROR) > 0) { return false; } return true; }
function CopyEx($path_from, $path_to, $bDeleteAfterCopy = false, $bOverride = false) { global $APPLICATION, $USER; CMain::InitPathVars($site_from, $path_from); $DOC_ROOT_FROM = CSite::GetSiteDocRoot($site_from); CMain::InitPathVars($site_to, $path_to); $DOC_ROOT_TO = CSite::GetSiteDocRoot($site_to); $strWarning = ''; //check: if we copy to the same directory if (strpos($DOC_ROOT_TO . $path_to . "/", $DOC_ROOT_FROM . $path_from . "/") === 0) { return GetMessage("FILEMAN_LIB_BAD_FOLDER") . ": \"" . $path_from . "\".\n"; } $io = CBXVirtualIo::GetInstance(); if ($io->DirectoryExists($DOC_ROOT_FROM . $path_from)) { // Minimal access - read/listing for copying files if (!$USER->CanDoFileOperation('fm_view_listing', array($site_from, $path_from))) { return GetMessage("FILEMAN_FILEMAN_FOLDER_READ_DENY") . " \"" . $path_from . "\".\n"; } if ($bDeleteAfterCopy && !$USER->CanDoFileOperation('fm_delete_folder', array($site_from, $path_from))) { return GetMessage("FILEMAN_FILEMAN_FOLDER_DEL_DENY") . " \"" . $path_from . "\".\n"; } //Check: folder exist or not $strWarTmp = CFileMan::CreateDir(array($site_to, $path_to)); if (strlen($strWarTmp) > 0) { return $strWarTmp; } $APPLICATION->CopyFileAccessPermission(array($site_from, $path_from), array($site_to, $path_to)); } else { // If we can write this file if (!$USER->CanDoFileOperation('fm_create_new_file', array($site_to, $path_to))) { return GetMessage("FILEMAN_FILEMAN_FILE_WRITE_DENY") . " \"" . $path_to . "\".\n"; } // If we can't read source-file if (!$USER->CanDoFileOperation('fm_view_file', array($site_from, $path_from))) { return GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY") . " \"" . $path_from . "\".\n"; } // Copying php or system file without PHP or LPA access if (!($USER->CanDoOperation('edit_php') || $USER->CanDoFileOperation('fm_lpa', $arPath) || !(HasScriptExtension($Elem["NAME"]) || substr($Elem["NAME"], 0, 1) == "."))) { return GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY") . " \"" . $path_from . "\".\n"; } // If we can't move source-file if ($bDeleteAfterCopy && !$USER->CanDoFileOperation('fm_delete_file', array($site_from, $path_from))) { return GetMessage("FILEMAN_FILEMAN_FILE_DEL_DENY") . " \"" . $path_from . "\".\n"; } //Check if folder already exist and trying to create if not $p = strrpos($path_to, "/"); $path_to_dir = substr($path_to, 0, $p); $strWarTmp = CFileMan::CreateDir(array($site_to, $path_to_dir)); if (strlen($strWarTmp) > 0) { return $strWarTmp; } if ($io->FileExists($DOC_ROOT_TO . $path_to) || $io->DirectoryExists($DOC_ROOT_TO . $path_to)) { if ($bOverride) { $strWarn = CFileMan::DeleteEx(array($site_to, $path_to)); if ($strWarn != "") { return $strWarn; } } else { return GetMessage("FILEMAN_FILEMAN_FILE_WITH_NAME") . " \"" . $path_to . "\" " . GetMessage("FILEMAN_FILEMAN_ALREADY_EXISTS") . "!\n"; } } $APPLICATION->CopyFileAccessPermission(array($site_from, $path_from), array($site_to, $path_to)); //************************** Quota **************************// if (COption::GetOptionInt("main", "disk_space") > 0) { $f = $io->GetFile($DOC_ROOT_FROM . $path_from); $size = $f->GetFileSize(); $quota = new CDiskQuota(); if (!$quota->checkDiskQuota(array("FILE_SIZE" => $size))) { return $quota->LAST_ERROR; } } //************************** Quota **************************// // Copy file if (DEBUG_FILE_MAN) { echo "copy(" . $DOC_ROOT_FROM . $path_from . "," . $DOC_ROOT_TO . $path_to . ");<br>"; } if (!$io->Copy($DOC_ROOT_FROM . $path_from, $DOC_ROOT_TO . $path_to)) { $strWarning .= GetMessage('FILEMAN_COPY_ERROR', array('#PATH_FROM#' => htmlspecialcharsex($path_from), '#PATH_TO#' => htmlspecialcharsex($path_to))); } //************************** Quota **************************// if (COption::GetOptionInt("main", "disk_space") > 0) { $quota->updateDiskQuota("file", $size, "copy"); } //************************** Quota **************************// if (CModule::IncludeModule("search")) { $site = CSite::GetSiteByFullPath($DOC_ROOT_TO . $path_to); CSearch::ReIndexFile(array($site_to, $path_to), $site); } if ($bDeleteAfterCopy && strlen($strWarning) <= 0) { // If was command "delete after copy"? $strWarning .= CFileMan::DeleteFile(array($site_from, $path_from)); } return $strWarning; } // Recursive $d = $io->GetDirectory($DOC_ROOT_FROM . $path_from); $arChildren = $d->GetChildren(); foreach ($arChildren as $child) { $fn = $child->GetName(); if ($child->IsDirectory()) { //go to recursion $strWarning .= CFileMan::CopyEx(array($site_from, $path_from . "/" . $fn), array($site_to, $path_to . "/" . $fn), $bDeleteAfterCopy, $bOverride); //back from recursion, in this subfolder all right //if($bDeleteAfterCopy) //necessary delete this subfolder // $strWarning .= CFileMan::DeleteDir($path_from."/".$file); } else { if ($fn == ".access.php") { continue; } //let's check, if we can to write there if (!$USER->CanDoFileOperation('fm_create_new_file', array($site_to, $path_to . "/" . $fn))) { $strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_WRITE_DENY") . " \"" . $path_to . "/" . $fn . "\".\n"; } elseif (!$USER->CanDoFileOperation('fm_view_file', array($site_from, $path_from . "/" . $fn))) { $strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY") . " \"" . $path_from . "/" . $fn . "\".\n"; } elseif (!($USER->CanDoOperation('edit_php') || $USER->CanDoFileOperation('fm_lpa', array($site_from, $path_from . "/" . $fn)) || !(HasScriptExtension($fn) || substr($fn, 0, 1) == "."))) { $strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY") . " \"" . $path_from . "/" . $fn . "\".\n"; } else { if ($io->FileExists($DOC_ROOT_TO . $path_to . "/" . $fn)) { if ($bOverride) { $strWarn = CFileMan::DeleteEx(array($site_to, $path_to . "/" . $fn)); if ($strWarn != "") { $strWarning .= $strWarn . "\n"; } } else { $strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_WITH_NAME") . " \"" . $path_to . "/" . $fn . "\" " . GetMessage("FILEMAN_FILEMAN_ALREADY_EXISTS") . "!\n"; } } if ($strWarning == "") { //it means we can copy, if we found here $APPLICATION->CopyFileAccessPermission(array($site_from, $path_from . "/" . $fn), array($site_to, $path_to . "/" . $fn)); if (DEBUG_FILE_MAN) { echo "copy(" . $DOC_ROOT_FROM . $path_from . "/" . $fn . "," . $DOC_ROOT_TO . $path_to . "/" . $fn . ");<br>"; } if (!$io->Copy($DOC_ROOT_FROM . $path_from . "/" . $fn, $DOC_ROOT_TO . $path_to . "/" . $fn)) { $strWarning .= GetMessage('FILEMAN_COPY_ERROR', array('#PATH_FROM#' => htmlspecialcharsex($path_from . "/" . $fn), '#PATH_TO#' => htmlspecialcharsex($path_to . "/" . $fn))); } //************************** Quota **************************// if (COption::GetOptionInt("main", "disk_space") > 0) { $f = $io->GetFile($DOC_ROOT_TO . $path_to . "/" . $fn); $quota = new CDiskQuota(); $quota->updateDiskQuota("file", $f->GetFileSize(), "copy"); } //************************** Quota **************************// if (CModule::IncludeModule("search")) { $site = CSite::GetSiteByFullPath($DOC_ROOT_TO, $path_to . "/" . $fn); CSearch::ReindexFile($path_to . "/" . $fn, $site); } if ($bDeleteAfterCopy && strlen($strWarning) <= 0) { $strWarning .= CFileMan::DeleteFile(array($site_from, $path_from . "/" . $fn)); } } } } } //we may be need, to delete our initial folder if ($bDeleteAfterCopy) { $strWarning .= CFileMan::DeleteDir(array($site_from, $path_from)); } return $strWarning; }
function SaveFileContent($abs_path, $strContent) { $strContent = str_replace("\r\n", "\n", $strContent); $file = array(); $this->ResetException(); foreach (GetModuleEvents("main", "OnBeforeChangeFile", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($abs_path, &$strContent)) == false) { if (!$this->GetException()) { $this->ThrowException(GetMessage("main_save_file_handler_error", array("#HANDLER#" => $arEvent["TO_NAME"]))); } return false; } } $io = CBXVirtualIo::GetInstance(); $fileIo = $io->GetFile($abs_path); $io->CreateDirectory($fileIo->GetPath()); if ($fileIo->IsExists()) { $file["exists"] = true; if (!$fileIo->IsWritable()) { $fileIo->MarkWritable(); } $file["size"] = $fileIo->GetFileSize(); } /****************************** QUOTA ******************************/ if (COption::GetOptionInt("main", "disk_space") > 0) { $quota = new CDiskQuota(); if (false === $quota->checkDiskQuota(array("FILE_SIZE" => intVal(strLen($strContent) - intVal($file["size"]))))) { $this->ThrowException($quota->LAST_ERROR, "BAD_QUOTA"); return false; } } /****************************** QUOTA ******************************/ if ($fileIo->PutContents($strContent)) { $fileIo->MarkWritable(); } else { if ($file["exists"]) { $this->ThrowException(GetMessage("MAIN_FILE_NOT_CREATE"), "FILE_NOT_CREATE"); } else { $this->ThrowException(GetMessage("MAIN_FILE_NOT_OPENED"), "FILE_NOT_OPEN"); } return false; } bx_accelerator_reset(); $site = CSite::GetSiteByFullPath($abs_path); $DOC_ROOT = CSite::GetSiteDocRoot($site); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { //Fix for name case under Windows $abs_path = strtolower($abs_path); $DOC_ROOT = strtolower($DOC_ROOT); } if (strpos($abs_path, $DOC_ROOT) === 0 && $site !== false) { $DOC_ROOT = rtrim($DOC_ROOT, "/\\"); $path = "/" . ltrim(substr($abs_path, strlen($DOC_ROOT)), "/\\"); foreach (GetModuleEvents("main", "OnChangeFile", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($path, $site)); } } /****************************** QUOTA ******************************/ if (COption::GetOptionInt("main", "disk_space") > 0) { $fs = $fileIo->GetFileSize(); CDiskQuota::updateDiskQuota("files", intVal($fs - intVal($file["size"])), "update"); } /****************************** QUOTA ******************************/ return true; }
/** * Creates cache file * Old Html Cache * @param string $file_name * @param string $content */ public static function writeFile($file_name, $content) { global $USER; if(is_object($USER) && $USER->IsAuthorized()) return; $content_len = function_exists('mb_strlen')? mb_strlen($content, 'latin1'): strlen($content); if($content_len <= 0) return; $arHTMLPagesOptions = self::getOptions(); //Let's be pessimists $bQuota = false; if(class_exists("cdiskquota")) { $quota = new CDiskQuota(); if($quota->checkDiskQuota(array("FILE_SIZE" => $content_len))) $bQuota = true; } else { $bQuota = true; } $arStat = self::readStatistic(); if($arStat) $cached_size = $arStat["FILE_SIZE"]; else $cached_size = 0.0; $cache_quota = doubleval($arHTMLPagesOptions["~FILE_QUOTA"]); if($bQuota && ($cache_quota > 0.0)) { if($cache_quota < ($cached_size + $content_len)) $bQuota = false; } if($bQuota) { CheckDirPath($file_name); $written = 0; $tmp_filename = $file_name.md5(mt_rand()).".tmp"; $file = @fopen($tmp_filename, "wb"); if($file !== false) { $written = fwrite($file, $content); if($written == $content_len) { fclose($file); if(file_exists($file_name)) unlink($file_name); rename($tmp_filename, $file_name); @chmod($file_name, defined("BX_FILE_PERMISSIONS")? BX_FILE_PERMISSIONS: 0664); if(class_exists("cdiskquota")) { CDiskQuota::updateDiskQuota("file", $content_len, "copy"); } } else { $written = 0; fclose($file); if(file_exists($file_name)) unlink($file_name); if(file_exists($tmp_filename)) unlink($tmp_filename); } } self::writeStatistic( 0, //hit 1, //miss 0, //quota 0, //posts $written //files ); } else { //Fire cleanup $bytes = \Bitrix\Main\Data\StaticHtmlFileStorage::deleteRecursive("/"); if (class_exists("cdiskquota")) { CDiskQuota::updateDiskQuota("file", $bytes, "delete"); } self::writeStatistic(0, 0, 1, 0, false); } }
function writeFile($file_name, $content) { global $USER; if (is_object($USER) && $USER->IsAuthorized()) { return; } $content_len = function_exists('mb_strlen') ? mb_strlen($content, 'latin1') : strlen($content); if ($content_len <= 0) { return; } $arHTMLPagesOptions = CHTMLPagesCache::GetOptions(true); if (!is_array($arHTMLPagesOptions)) { return; } //Let's be pessimists $bQuota = false; if (class_exists("cdiskquota")) { $quota = new CDiskQuota(); if ($quota->checkDiskQuota(array("FILE_SIZE" => $content_len))) { $bQuota = true; } } else { $bQuota = true; } $arStat = CHTMLPagesCache::readStatistic(); if ($arStat) { $cached_size = $arStat["FILE_SIZE"]; } else { $cached_size = 0.0; } $cache_quota = doubleval($arHTMLPagesOptions["~FILE_QUOTA"]); if ($bQuota && $cache_quota > 0.0) { if ($cache_quota < $cached_size + $content_len) { $bQuota = false; } } if ($bQuota) { CheckDirPath($file_name); $written = 0; $tmp_filename = $file_name . md5(mt_rand()) . ".tmp"; $file = fopen($tmp_filename, "wb"); if ($file !== false) { $written = fwrite($file, $content); if ($written == $content_len) { fclose($file); if (file_exists($file_name)) { unlink($file_name); } rename($tmp_filename, $file_name); @chmod($file_name, defined("BX_FILE_PERMISSIONS") ? BX_FILE_PERMISSIONS : 0664); if (class_exists("cdiskquota")) { CDiskQuota::updateDiskQuota("file", $content_len, "copy"); } } else { $written = 0; fclose($file); if (file_exists($file_name)) { unlink($file_name); } if (file_exists($tmp_filename)) { unlink($tmp_filename); } } } $arStat = CHTMLPagesCache::writeStatistic(0, 1, 0, 0, $written); } else { //Fire cleanup CHTMLPagesCache::CleanAll(); CHTMLPagesCache::writeStatistic(0, 0, 1, 0, false); } }
$strWarning .= GetMessage("FILEMAN_FILEUPLOAD_SIZE_ERROR", array('#FILE_NAME#' => $pathto)) . "\n"; } elseif (($mess = CFileMan::CheckFileName(str_replace('/', '', $pathto))) !== true) { $strWarning .= $mess . ".\n"; } else { if ($io->FileExists($DOC_ROOT . $pathto)) { $strWarning .= GetMessage("FILEMAN_FILEUPLOAD_FILE_EXISTS1") . " \"" . $pathto . "\" " . GetMessage("FILEMAN_FILEUPLOAD_FILE_EXISTS2") . ".\n"; } elseif (!$USER->IsAdmin() && (HasScriptExtension($pathto) || substr(CFileman::GetFileName($pathto), 0, 1) == ".")) { $strWarning .= GetMessage("FILEMAN_FILEUPLOAD_PHPERROR") . " \"" . $pathto . "\".\n"; } else { $bQuota = true; if (COption::GetOptionInt("main", "disk_space") > 0) { $f = $io->GetFile($arFile["tmp_name"]); $bQuota = false; $size = $f->GetFileSize(); $quota = new CDiskQuota(); if ($quota->checkDiskQuota(array("FILE_SIZE" => $size))) { $bQuota = true; } } if ($bQuota) { if (!$io->Copy($arFile["tmp_name"], $DOC_ROOT . $pathto)) { $strWarning .= GetMessage("FILEMAN_FILEUPLOAD_FILE_CREATE_ERROR") . " \"" . $pathto . "\"\n"; } elseif (COption::GetOptionInt("main", "disk_space") > 0) { CDiskQuota::updateDiskQuota("file", $size, "copy"); } $f = $io->GetFile($DOC_ROOT . $pathto); $f->MarkWritable(); $module_id = 'fileman'; if (COption::GetOptionString($module_id, "log_page", "Y") == "Y") { $res_log['path'] = substr($pathto, 1); CEventLog::Log("content", "FILE_ADD", "main", "", serialize($res_log));