コード例 #1
0
ファイル: import.php プロジェクト: Satariall/izurit
 protected function _MakeFields(&$arFields, $itemType = null)
 {
     $arRes = array();
     $upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
     $arStopList = array();
     foreach ($arFields["#"] as $field => $arValue) {
         if (in_array($field, $arStopList)) {
             continue;
         }
         if (in_array($field, $this->arUnsetFields) && $itemType !== 'TMK' && $itemType !== 'QUE') {
             if (!($itemType === 'TES' && in_array($field, $this->arPreventUnsetFieldsForTest))) {
                 continue;
             }
         }
         if (in_array($field, $this->arDraftFields) && $itemType !== 'TMK') {
             if (is_set($arValue[0]["#"], "cdata-section")) {
                 $arRes[strtoupper($field)] = preg_replace("~([\"'])(cid:resources/(.+?))(\\1)~is", "\\1/" . $upload_dir . "/learning/" . $this->COURSE_ID . "/\\3\\1", $arValue[0]["#"]["cdata-section"][0]["#"]);
                 continue;
             } elseif (isset($arValue[0]["#"])) {
                 $arRes[strtoupper($field)] = preg_replace("~([\"'])(cid:resources/(.+?))(\\1)~is", "\\1/" . $upload_dir . "/learning/" . $this->COURSE_ID . "/\\3\\1", $arValue[0]["#"]);
                 continue;
             }
         }
         if (in_array($field, $this->arDate) && strlen($arValue[0]["#"]) > 0) {
             $time = date("His", $arValue[0]["#"]);
             $arRes[strtoupper($field)] = ConvertTimeStamp($arValue[0]["#"], $time == "000000" ? "SHORT" : "FULL");
             continue;
         }
         if (in_array($field, $this->arPicture) && intval($arValue[0]["#"]) > 0) {
             $file = $this->package_dir . "/dbresources/" . $arValue[0]["#"];
             if (method_exists('CFile', 'GetImageSize')) {
                 $aImage = @CFile::GetImageSize($file);
                 if ($aImage === false) {
                     continue;
                 }
                 if (function_exists("image_type_to_mime_type")) {
                     $image_type_to_mime_type = image_type_to_mime_type($aImage[2]);
                 } else {
                     $image_type_to_mime_type = CCourseImport::ImageTypeToMimeType($aImage[2]);
                 }
             } else {
                 $image_type_to_mime_type = self::ImageTypeToMimeTypeByFileName($file);
             }
             $arRes[strtoupper($field)] = array("MODULE_ID" => "learning", "name" => $arValue[0]["#"], "tmp_name" => $file, "size" => @filesize($file), "type" => $image_type_to_mime_type);
             if (isset($arFields["#"][$field . '_description'][0]['#'])) {
                 $arRes[strtoupper($field)]['description'] = $arFields["#"][$field . '_description'][0]['#'];
                 $arStopList[] = $field . '_description';
             }
             continue;
         }
         $arRes[strtoupper($field)] = $arValue[0]["#"];
     }
     unset($arFields);
     return $arRes;
 }