예제 #1
0
 /**
  * @return string
  */
 public function getFileInfo()
 {
     $fileInfo = null;
     if ($this->encoding === 'B' || $this->encoding === 'BASE64') {
         $type = $this->type !== '' ? strtolower($this->type) : 'jpg';
         if ($type === '' || !in_array($type, explode(',', \CFile::GetImageExtensions()), true)) {
             $type = 'jpg';
         }
         $filePath = \CTempFile::GetFileName(uniqid('vcard_img') . '.' . $type);
         CheckDirPath($filePath);
         //Removing of line folding
         $encodedData = preg_replace("/\\\\n/i", "\n", $this->value);
         if (file_put_contents($filePath, base64_decode($encodedData)) !== false) {
             $fileInfo = \CFile::MakeFileArray($filePath, "image/{$type}");
         }
     } elseif ($this->valueType === 'URI' && \CCrmUrlUtil::HasScheme($this->value) && \CCrmUrlUtil::IsSecureUrl($this->value)) {
         $fileInfo = \CFile::MakeFileArray($this->value);
     }
     return is_array($fileInfo) && strlen(\CFile::CheckImageFile($fileInfo)) === 0 ? $fileInfo : null;
 }
예제 #2
0
function GetFilrIcon($compPath, $pathQ, $arParams, $arF)
{
    $arMime = array('pdf' => 'pdf.png', 'doc' => 'doc.png', 'docx' => 'doc.png', 'ppt' => 'ppt.png', 'pptx' => 'ppt.png', 'rar' => 'rar.png', 'xls' => 'xls.png', 'xlsx' => 'xls.png', 'zip' => 'zip.png');
    $fIcon = $compPath . "/images/" . "blank.png";
    $fExtQ = strtolower(GetFileExtension($pathQ));
    if ($arParams["RESOURCE_TYPE"] == "IBLOCK") {
        if (CFile::isImage($arF['NAME'])) {
            return $compPath . "/images/img.png";
        }
        $icon = isset($arMime[$fExtQ]) ? $arMime[$fExtQ] : 'blank.png';
        return $compPath . "/images/{$icon}";
    }
    $fileID = $pathQ;
    $arFile = CFile::MakeFileArray($fileID);
    $isPictureExt = false;
    $arPExt = explode(",", CFile::GetImageExtensions());
    foreach ($arPExt as $v) {
        if (strtolower(trim($v)) == $fExtQ) {
            $isPictureExt = true;
            break;
        }
    }
    $isPicture = false;
    if ($isPictureExt && isset($arFile["tmp_name"])) {
        $imgArray = CFile::GetImageSize($arFile["tmp_name"], true);
        if (is_array($imgArray)) {
            if ($arFIcon = CFile::ResizeImageGet($fileID, array("width" => "58", "height" => "58"), BX_RESIZE_IMAGE_EXACT, true)) {
                $fIcon = $arFIcon["src"];
                $isPicture = true;
            }
        }
    }
    if (!$isPicture && array_key_exists($fExtQ, $arMime)) {
        $fIcon = $compPath . "/images/" . $arMime[$fExtQ];
    }
    return $fIcon;
}
예제 #3
0
 function CheckImageFile($arFile, $iMaxSize = 0, $iMaxWidth = 0, $iMaxHeight = 0, $access_typies = array())
 {
     if ($arFile["name"] == "") {
         return "";
     }
     $file_type = GetFileType($arFile["name"]);
     // IMAGE by default
     if (!in_array($file_type, $access_typies)) {
         $file_type = "IMAGE";
     }
     switch ($file_type) {
         case "FLASH":
             $res = CFile::CheckFile($arFile, $iMaxSize, "application/x-shockwave-flash", CFile::GetFlashExtensions());
             break;
         default:
             $res = CFile::CheckFile($arFile, $iMaxSize, "image/", CFile::GetImageExtensions());
     }
     if ($res != '') {
         return $res;
     }
     $imgArray = CFile::GetImageSize($arFile["tmp_name"], true);
     if (is_array($imgArray)) {
         $intWIDTH = $imgArray[0];
         $intHEIGHT = $imgArray[1];
     } else {
         return GetMessage("FILE_BAD_FILE_TYPE") . ".<br>";
     }
     //check for dimensions
     if ($iMaxWidth > 0 && ($intWIDTH > $iMaxWidth || $intWIDTH == 0) || $iMaxHeight > 0 && ($intHEIGHT > $iMaxHeight || $intHEIGHT == 0)) {
         return GetMessage("FILE_BAD_MAX_RESOLUTION") . " (" . $iMaxWidth . " * " . $iMaxHeight . " " . GetMessage("main_include_dots") . ").<br>";
     }
     return null;
 }
예제 #4
0
 /**
  * Checks file params
  * @param $file
  * @param $arFile
  * @return mixed|null|string
  */
 protected function checkFile($file, &$arFile)
 {
     $status = new Status("checked");
     if ($file["error"] > 0) {
         $status = new Error("BXU347.2", $file["error"]);
     } else {
         if (array_key_exists("tmp_url", $file)) {
             $url = new Uri($file["tmp_url"]);
             if ($url->getHost() == '' && ($tmp = \CFile::MakeFileArray($url->getPath())) && is_array($tmp)) {
                 $file = array_merge($tmp, $file);
             } else {
                 if ($url->getHost() != '' && $this->http->query("HEAD", $file["tmp_url"]) && $this->http->getStatus() == "200") {
                     $file = array_merge($file, array("size" => (int) $this->http->getHeaders()->get("content-length"), "type" => $this->http->getHeaders()->get("content-type")));
                 } else {
                     $status = new Error("BXU347.2");
                 }
             }
         } else {
             if (!is_uploaded_file($file['tmp_name']) || !file_exists($file['tmp_name'])) {
                 $status = new Error("BXU347.2");
             }
         }
     }
     if ($status instanceof Error) {
         //
     } elseif ($this->params["allowUpload"] == "I") {
         $error = \CFile::CheckFile($file, $this->params["uploadMaxFilesize"], "image/", \CFile::GetImageExtensions());
         if (!empty($error)) {
             $status = new Error("BXU347.3", $error);
         }
     } elseif ($this->params["allowUpload"] == "F") {
         $error = \CFile::CheckFile($file, $this->params["uploadMaxFilesize"], false, $this->params["allowUploadExt"]);
         if (!empty($error)) {
             $status = new Error("BXU347.3", $error);
         }
     } else {
         $error = \CFile::CheckFile($file, $this->params["uploadMaxFilesize"]);
         if (!empty($error)) {
             $status = new Error("BXU347.3", $error);
         }
     }
     if ($status instanceof Status) {
         $matches = array();
         $name = $file["~name"];
         if (preg_match("/^(.+?)\\.ch(\\d+)\\.(\\d+)\\.chs(\\d+)\$/", $file["~name"], $matches)) {
             $name = $matches[1];
         }
         $key = !empty($name) ? $name : 'default';
         $file["copy"] = $key;
         if (empty($matches)) {
             $arFile["files"][$key] = $file;
         } else {
             $fileAddInfo = array("chunks" => array(), "chunksInfo" => array("count" => $matches[4], "uploaded" => array(), "written" => array()));
             if (array_key_exists($key, $arFile["files"])) {
                 $fileAddInfo = $arFile["files"][$key];
             }
             $file["status"] = "inprogress";
             $file["number"] = $matches[2];
             $file["start"] = $matches[3];
             $fileAddInfo["chunks"][self::getChunkKey($fileAddInfo["chunksInfo"]["count"], $file["number"])] = $file;
             $arFile["files"][$key] = $fileAddInfo;
         }
     }
     return $status;
 }
예제 #5
0
 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;
 }
예제 #6
0
파일: file.php 프로젝트: nProfessor/Mytb
	function CheckImageFile($arFile, $iMaxSize=0, $iMaxWidth=0, $iMaxHeight=0, $access_typies=array())
	{
		if(strlen($arFile["name"])<=0)
			return "";

		if(GetFileNameWithoutExtension(RemoveScriptExtension($arFile["name"])) == '')
			return GetMessage("FILE_BAD_FILENAME");

		$file_type = GetFileType($arFile["name"]);
		// если тип файла не входит в массив допустимых типов то
		// присваиваем ему тип IMAGE по умолчанию
		if(!in_array($file_type, $access_typies))
			$file_type = "IMAGE";

		switch ($file_type)
		{
			case "FLASH":
				$res = CFile::CheckFile($arFile, $iMaxSize, "application/x-shockwave-flash", CFile::GetFlashExtensions());
				break;
			default:
				$res = CFile::CheckFile($arFile, $iMaxSize, "image/", CFile::GetImageExtensions());
		}

		if(strlen($res)>0)
			return $res;

		$imgArray = CFile::GetImageSize($arFile["tmp_name"]);

		if(is_array($imgArray))
		{
			$intWIDTH = $imgArray[0];
			$intHEIGHT = $imgArray[1];
		}
		else
			return GetMessage("FILE_BAD_FILE_TYPE").".<br>";

		//проверка на максимальный размер картинки (ширина/высота)
		if($iMaxWidth > 0 && ($intWIDTH > $iMaxWidth || $intWIDTH == 0) || $iMaxHeight > 0 && ($intHEIGHT > $iMaxHeight || $intHEIGHT == 0))
			return GetMessage("FILE_BAD_MAX_RESOLUTION")." (".$iMaxWidth." * ".$iMaxHeight." ".GetMessage("main_include_dots").").<br>";

		return null;
	}
예제 #7
0
##############################################
# Bitrix: SiteManager                        #
# Copyright (c) 2002 Bitrix                  #
# http://www.bitrix.ru                       #
# mailto:admin@bitrix.ru                     #
##############################################
*/
define("STOP_STATISTICS", "Y");
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/workflow/prolog.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/workflow/include.php";
$fname = $_REQUEST["fname"];
if ($APPLICATION->GetGroupRight("workflow") >= "R") {
    session_write_close();
    $src = CWorkflow::GetFileContent($did, $fname, $wf_path, $site);
    $ext = strtolower(GetFileExtension($fname));
    $arrExt = explode(",", strtolower(CFile::GetImageExtensions()));
    if (in_array($ext, $arrExt)) {
        if ($ext == "jpg") {
            $ext = "jpeg";
        }
        header("Content-type: image/" . $ext);
        header("Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0");
        header("Expires: 0");
        header("Pragma: public");
        echo $src;
        die;
    }
    echo TxtToHtml($src);
}
die;
예제 #8
0
파일: file.php 프로젝트: nycmic/bittest
 public static function CheckImageFile($arFile, $iMaxSize = 0, $iMaxWidth = 0, $iMaxHeight = 0, $access_typies = array(), $bForceMD5 = false, $bSkipExt = false)
 {
     if ($arFile["name"] == "") {
         return "";
     }
     if (preg_match("#^php://filter#i", $arFile["tmp_name"])) {
         return GetMessage("FILE_BAD_FILE_TYPE") . ".<br>";
     }
     $file_type = GetFileType($arFile["name"]);
     // IMAGE by default
     $flashEnabled = false;
     if (!in_array($file_type, $access_typies)) {
         $file_type = "IMAGE";
     }
     if ($file_type == "FLASH") {
         $flashEnabled = true;
         static $flashMime = array("application/x-shockwave-flash", "application/vnd.adobe.flash.movie");
         $res = CFile::CheckFile($arFile, $iMaxSize, $flashMime, CFile::GetFlashExtensions(), $bForceMD5, $bSkipExt);
     } else {
         $res = CFile::CheckFile($arFile, $iMaxSize, "image/", CFile::GetImageExtensions(), $bForceMD5, $bSkipExt);
     }
     if ($res != '') {
         return $res;
     }
     $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, $flashEnabled);
     if (is_array($imgArray)) {
         $intWIDTH = $imgArray[0];
         $intHEIGHT = $imgArray[1];
     } else {
         return GetMessage("FILE_BAD_FILE_TYPE") . ".<br>";
     }
     //check for dimensions
     if ($iMaxWidth > 0 && ($intWIDTH > $iMaxWidth || $intWIDTH == 0) || $iMaxHeight > 0 && ($intHEIGHT > $iMaxHeight || $intHEIGHT == 0)) {
         return GetMessage("FILE_BAD_MAX_RESOLUTION") . " (" . $iMaxWidth . " * " . $iMaxHeight . " " . GetMessage("main_include_dots") . ").<br>";
     }
     return null;
 }
예제 #9
0
		'css' => $pathCSS.'/core_canvas.css',
		'lang' => $pathLang.'/js_core_canvas.php',
		'rel' => array('popup'),
	),
	'uploader' => array(
		'js' => array(
			$pathJS.'/core_uploader/common.js',
			$pathJS.'/core_uploader/uploader.js',
			$pathJS.'/core_uploader/file.js',
			$pathJS.'/core_uploader/queue.js',
		),
		'lang_additional' => array(
			"phpMaxFileUploads" => ini_get("max_file_uploads"),
			"phpPostMaxSize" => CUtil::Unformat(ini_get("post_max_size")),
			"phpUploadMaxFilesize" => CUtil::Unformat(ini_get("upload_max_filesize")),
			"bxImageExtensions" => CFile::GetImageExtensions()
		),
		'lang' => $pathLang.'/js_core_uploader.php',
		'rel' => array('ajax', 'dd')
	),
	'site_speed' => array(
		'js' => $pathJS.'/site_speed/site_speed.js',
		'lang' => $pathLang.'/js_site_speed.php',
		'rel' => array('amcharts_serial', 'ajax', "date")
	),
	'qrcode' => array(
		'js' => array(
			'/bitrix/js/main/qrcode/qrcode.js'
		)
	),
예제 #10
0
 public static function CheckFile($arFile, $iMaxSize = 0, $iMaxWidth = 0, $iMaxHeight = 0, $access_typies = array(), $bForceMD5 = false, $bSkipExt = false)
 {
     if ($arFile["name"] == "") {
         return "";
     }
     if (preg_match("#^php://filter#i", $arFile["tmp_name"])) {
         return GetMessage("FILE_BAD_FILE_TYPE") . ".<br>";
     }
     $extension = GetFileExtension(strtolower($arFile["name"]));
     switch ($extension) {
         case "jpg":
         case "jpeg":
         case "gif":
         case "bmp":
         case "png":
             $file_type = "IMAGE";
             break;
         case "swf":
             $file_type = "FLASH";
             break;
         case "mp4":
         case "webm":
         case "ogg":
             $file_type = "VIDEO";
             break;
         default:
             $file_type = "UNKNOWN";
     }
     // IMAGE by default
     $flashEnabled = false;
     if (!in_array($file_type, $access_typies)) {
         $file_type = "IMAGE";
     }
     if ($file_type == "FLASH") {
         $flashEnabled = true;
         static $flashMime = array("application/x-shockwave-flash", "application/vnd.adobe.flash.movie");
         $res = CFile::CheckFile($arFile, $iMaxSize, $flashMime, CFile::GetFlashExtensions(), $bForceMD5, $bSkipExt);
     } else {
         if ($file_type == "VIDEO") {
             $res = CFile::CheckFile($arFile, $iMaxSize, "video/", "mp4,webm,ogg", $bForceMD5, $bSkipExt);
         } else {
             $res = CFile::CheckFile($arFile, $iMaxSize, "image/", CFile::GetImageExtensions(), $bForceMD5, $bSkipExt);
         }
     }
     if ($res != '') {
         return $res;
     }
     if ($file_type == 'IMAGE' || $file_type == "FLASH") {
         $imgArray = CFile::GetImageSize($arFile["tmp_name"], true, $flashEnabled);
         if (is_array($imgArray)) {
             $intWIDTH = $imgArray[0];
             $intHEIGHT = $imgArray[1];
         } else {
             return GetMessage("FILE_BAD_FILE_TYPE") . ".<br>";
         }
         //check for dimensions
         if ($iMaxWidth > 0 && ($intWIDTH > $iMaxWidth || $intWIDTH == 0) || $iMaxHeight > 0 && ($intHEIGHT > $iMaxHeight || $intHEIGHT == 0)) {
             return GetMessage("FILE_BAD_MAX_RESOLUTION") . " (" . $iMaxWidth . " * " . $iMaxHeight . " " . GetMessage("main_include_dots") . ").<br>";
         }
     }
     return null;
 }
예제 #11
0
 public function CheckFields(&$arFields, $ID = false, $options = array())
 {
     global $APPLICATION, $USER_FIELD_MANAGER;
     $this->LAST_ERROR = '';
     if (($ID == false || isset($arFields['TITLE'])) && empty($arFields['TITLE'])) {
         $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_IS_MISSING', array('%FIELD_NAME%' => GetMessage('CRM_FIELD_TITLE'))) . "<br />";
     }
     if (isset($arFields['FM']) && is_array($arFields['FM'])) {
         $CCrmFieldMulti = new CCrmFieldMulti();
         if (!$CCrmFieldMulti->CheckComplexFields($arFields['FM'])) {
             $this->LAST_ERROR .= $CCrmFieldMulti->LAST_ERROR;
         }
     }
     if (isset($arFields['LOGO']) && is_array($arFields['LOGO'])) {
         if (($strError = CFile::CheckFile($arFields['LOGO'], 0, 0, CFile::GetImageExtensions())) != '') {
             $this->LAST_ERROR .= $strError . "<br />";
         }
     }
     $enableUserFildCheck = !(is_array($options) && isset($options['DISABLE_USER_FIELD_CHECK']) && $options['DISABLE_USER_FIELD_CHECK'] === true);
     if ($enableUserFildCheck) {
         // We have to prepare field data before check (issue #22966)
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $USER_FIELD_MANAGER, array('IS_NEW' => $ID == false));
         if (!$USER_FIELD_MANAGER->CheckFields(self::$sUFEntityID, $ID, $arFields)) {
             $e = $APPLICATION->GetException();
             $this->LAST_ERROR .= $e->GetString();
         }
     }
     if (strlen($this->LAST_ERROR) > 0) {
         return false;
     }
     return true;
 }
예제 #12
0
 public function CheckFields(&$arFields, $ID = false, $options = array())
 {
     global $APPLICATION, $USER_FIELD_MANAGER;
     $this->LAST_ERROR = '';
     if (($ID == false || isset($arFields['NAME']) && isset($arFields['LAST_NAME'])) && (empty($arFields['NAME']) && empty($arFields['LAST_NAME']))) {
         $this->LAST_ERROR .= GetMessage('CRM_ERROR_REQUIRED_FIELDS') . "<br />";
     }
     if (isset($arFields['FM']) && is_array($arFields['FM'])) {
         $CCrmFieldMulti = new CCrmFieldMulti();
         if (!$CCrmFieldMulti->CheckComplexFields($arFields['FM'])) {
             $this->LAST_ERROR .= $CCrmFieldMulti->LAST_ERROR;
         }
     }
     if (isset($arFields['PHOTO']) && is_array($arFields['PHOTO'])) {
         if (($strError = CFile::CheckFile($arFields['PHOTO'], 0, 0, CFile::GetImageExtensions())) != '') {
             $this->LAST_ERROR .= $strError . "<br />";
         }
     }
     if (isset($arFields['BIRTHDATE']) && $arFields['BIRTHDATE'] !== '' && !CheckDateTime($arFields['BIRTHDATE'])) {
         $this->LAST_ERROR .= GetMessage('CRM_ERROR_FIELD_INCORRECT', array('%FIELD_NAME%' => self::GetFieldCaption('BIRTHDATE'))) . "<br />";
     }
     $enableUserFildCheck = !(is_array($options) && isset($options['DISABLE_USER_FIELD_CHECK']) && $options['DISABLE_USER_FIELD_CHECK'] === true);
     if ($enableUserFildCheck) {
         // We have to prepare field data before check (issue #22966)
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $USER_FIELD_MANAGER, array('IS_NEW' => $ID == false));
         if (!$USER_FIELD_MANAGER->CheckFields(self::$sUFEntityID, $ID, $arFields)) {
             $e = $APPLICATION->GetException();
             $this->LAST_ERROR .= $e->GetString();
         }
     }
     return $this->LAST_ERROR === '';
 }
예제 #13
0
파일: jscore.php 프로젝트: Satariall/izurit
<?php

$pathJS = '/bitrix/js/main/core';
$pathCSS = '/bitrix/js/main/core/css';
$pathCSSPanel = '/bitrix/panel/main';
$pathLang = BX_ROOT . '/modules/main/lang/' . LANGUAGE_ID;
//WARNING: Don't use CUserOptions here! CJSCore::Init can be called from php_interface/init.php where no $USER exists
$amChartsPath = '/bitrix/js/main/amcharts/3.13/';
$arJSCoreConfig = array('ajax' => array('js' => $pathJS . '/core_ajax.js'), 'admin' => array('js' => $pathJS . '/core_admin.js', 'css' => array($pathCSS . '/core_panel.css', $pathCSSPanel . '/admin-public.css'), 'lang' => $pathLang . '/js_core_admin.php', 'rel' => array('ajax'), 'use' => CJSCore::USE_PUBLIC), 'admin_interface' => array('js' => $pathJS . '/core_admin_interface.js', 'lang' => $pathLang . '/js_core_admin_interface.php', 'css' => $pathCSSPanel . '/admin-public.css', 'rel' => array('ajax', 'popup', 'window', 'date', 'fx'), 'lang_additional' => array('TITLE_PREFIX' => CUtil::JSEscape(COption::GetOptionString("main", "site_name", $_SERVER["SERVER_NAME"])) . " - ")), "admin_login" => array('js' => $pathJS . "/core_admin_login.js", 'css' => $pathCSSPanel . "/login.css", 'rel' => array("ajax", "window")), 'autosave' => array('js' => $pathJS . '/core_autosave.js', 'lang' => $pathLang . '/js_core_autosave.php', 'rel' => array('ajax')), 'fx' => array('js' => $pathJS . '/core_fx.js'), 'dd' => array('js' => $pathJS . '/core_dd.js'), 'webrtc' => array('js' => $pathJS . '/core_webrtc.js'), 'popup' => array('js' => $pathJS . '/core_popup.js', 'css' => $pathCSS . '/core_popup.css'), 'tags' => array('js' => $pathJS . '/core_tags.js', 'css' => $pathCSS . '/core_tags.css', 'lang' => $pathLang . '/js_core_tags.php', 'rel' => array('popup')), 'timer' => array('js' => $pathJS . '/core_timer.js'), 'tooltip' => array('js' => $pathJS . '/core_tooltip.js', 'css' => $pathCSS . '/core_tooltip.css', 'rel' => array('ajax'), 'lang_additional' => array('TOOLTIP_ENABLED' => IsModuleInstalled("socialnetwork") && COption::GetOptionString("socialnetwork", "allow_tooltip", "Y") == "Y" ? "Y" : "N")), 'translit' => array('js' => $pathJS . '/core_translit.js', 'lang' => $pathLang . '/js_core_translit.php', 'lang_additional' => array('YANDEX_KEY' => COption::GetOptionString('main', 'translate_key_yandex', ''))), 'image' => array('js' => $pathJS . '/core_image.js', 'css' => $pathCSS . '/core_image.css', 'rel' => array('ls')), 'viewer' => array('js' => $pathJS . '/core_viewer.js', 'css' => $pathCSS . '/core_viewer.css', 'lang' => $pathLang . '/js_core_viewer.php', 'rel' => array('ls', 'ajax', 'popup')), 'window' => array('js' => $pathJS . '/core_window.js', 'css' => $pathCSSPanel . '/popup.css', 'rel' => array('ajax')), 'access' => array('js' => $pathJS . '/core_access.js', 'css' => $pathCSS . '/core_access.css', 'rel' => array('popup', 'ajax', 'finder'), 'lang' => $pathLang . '/js_core_access.php'), 'finder' => array('js' => $pathJS . '/core_finder.js', 'css' => $pathCSS . '/core_finder.css', 'rel' => array('popup', 'ajax', 'db_indexeddb')), 'date' => array('js' => $pathJS . '/core_date.js', 'css' => $pathCSS . '/core_date.css', 'lang' => $pathLang . '/date_format.php', 'lang_additional' => array('WEEK_START' => CSite::GetWeekStart()), 'rel' => array('popup')), 'ls' => array('js' => $pathJS . '/core_ls.js', 'rel' => array('json')), 'db' => array('js' => $pathJS . '/core_db.js'), 'db_indexeddb' => array('js' => $pathJS . '/core_db_indexeddb.js'), 'fc' => array('js' => $pathJS . '/core_frame_cache.js', 'rel' => array('db', 'ajax', 'ls', 'fx')), 'canvas' => array('js' => $pathJS . '/core_canvas.js', 'css' => $pathCSS . '/core_canvas.css', 'lang' => $pathLang . '/js_core_canvas.php', 'rel' => array('popup')), 'uploader' => array('js' => array($pathJS . '/core_uploader/common.js', $pathJS . '/core_uploader/uploader.js', $pathJS . '/core_uploader/file.js', $pathJS . '/core_uploader/queue.js'), 'lang_additional' => array("phpMaxFileUploads" => ini_get("max_file_uploads"), "phpPostMaxSize" => CUtil::Unformat(ini_get("post_max_size")), "phpUploadMaxFilesize" => CUtil::Unformat(ini_get("upload_max_filesize")), "bxImageExtensions" => CFile::GetImageExtensions(), "bxUploaderLog" => COption::GetOptionString("main", "uploaderLog", "N")), 'lang' => $pathLang . '/js_core_uploader.php', 'rel' => array('ajax', 'dd')), 'site_speed' => array('js' => $pathJS . '/site_speed/site_speed.js', 'lang' => $pathLang . '/js_site_speed.php', 'rel' => array('amcharts_serial', 'ajax', "date")), 'qrcode' => array('js' => array('/bitrix/js/main/qrcode/qrcode.js')), 'fileinput' => array('js' => $pathJS . '/core_fileinput.js', 'css' => $pathCSS . '/core_fileinput.css', 'lang' => $pathLang . '/js_core_fileinput.php', 'rel' => array("ajax", "window", "popup", "uploader", "canvas", "dd")), 'jquery' => array('js' => '/bitrix/js/main/jquery/jquery-1.8.3.min.js', 'skip_core' => true), 'jquery_src' => array('js' => '/bitrix/js/main/jquery/jquery-1.8.3.js', 'skip_core' => true), 'jquery2' => array('js' => '/bitrix/js/main/jquery/jquery-2.1.3.min.js', 'skip_core' => true), 'jquery2_src' => array('js' => '/bitrix/js/main/jquery/jquery-2.1.3.js', 'skip_core' => true), 'json' => array('js' => '/bitrix/js/main/json/json2.min.js', 'skip_core' => true), 'json_src' => array('js' => '/bitrix/js/main/json/json2.js', 'skip_core' => true), 'amcharts' => array('js' => $amChartsPath . 'amcharts.js', 'lang_additional' => array('AMCHARTS_PATH' => $amChartsPath, 'AMCHARTS_IMAGES_PATH' => $amChartsPath . 'images/'), 'skip_core' => true), 'amcharts_funnel' => array('js' => $amChartsPath . 'funnel.js', 'rel' => array('amcharts'), 'skip_core' => true), 'amcharts_gauge' => array('js' => $amChartsPath . 'gauge.js', 'rel' => array('amcharts'), 'skip_core' => true), 'amcharts_pie' => array('js' => $amChartsPath . 'pie.js', 'rel' => array('amcharts'), 'skip_core' => true), 'amcharts_radar' => array('js' => $amChartsPath . 'radar.js', 'rel' => array('amcharts'), 'skip_core' => true), 'amcharts_serial' => array('js' => $amChartsPath . 'serial.js', 'rel' => array('amcharts'), 'skip_core' => true), 'amcharts_xy' => array('js' => $amChartsPath . 'xy.js', 'rel' => array('amcharts'), 'skip_core' => true));
foreach ($arJSCoreConfig as $ext => $arExt) {
    CJSCore::RegisterExt($ext, $arExt);
}
예제 #14
0
 function GetExtensionIcon($urlT)
 {
     $arIco = array("doc" => "doc.jpg", "docx" => "doc.jpg", "pdf" => "pdf.jpg", "pic.jpg" => "pdf.jpg", "ppt" => "ppt.jpg", "pptx" => "ppt.jpg", "xls" => "xls.jpg", "xlsx" => "xls.jpg", "txt" => "txt.jpg");
     $res = "empty.jpg";
     $arIm = explode(",", CFile::GetImageExtensions());
     foreach ($arIm as $ci) {
         if (strlen($ci) > 0) {
             $arIco[$ci] = "pic.jpg";
         }
     }
     $fExtQ = strtolower(GetFileExtension($urlT));
     if (array_key_exists($fExtQ, $arIco)) {
         $res = $arIco[$fExtQ];
     }
     return $res;
 }