Current Path : /home/bitrix/ext_www/ballu.in.ua/import/ |
Current File : /home/bitrix/ext_www/ballu.in.ua/import/rk.functions.php |
<? function getPriceTypes(){ $db_res = CCatalogGroup::GetList(); while ($ar_res = $db_res->Fetch()){ $out[$ar_res["NAME"]] = $ar_res["ID"]; } return $out; } function mbr($str){ return nl2br( str_replace("<br>", "", $str ) ); } function formDate($date){ global $DB; if(empty($date)) return false; // укажем формат этой даты $date = implode(" ", explode("T", $date)); $format = "YYYY-MM-DD HH:MI:SS"; // получим формат текущего сайта $new_format = CSite::GetDateFormat("FULL"); // YYYY-MM-DD // переведем дату из одного формата в другой $new_date = $DB->FormatDate($date, $format, $new_format); // в результате получим дату в новом формате return $new_date; // 2007-12-31 } function getRest($address, $data=[], $method="GET",$direct=false){ global $API_URL; global $API_ADDRESS; global $API_KEY; if($direct==false) $service = $API_ADDRESS[$address]; else $service = $address; $url = $API_URL.$service; //print_r($API_ADDRESS); $opts = array('http' => array( 'method' => $method, 'header' => "Authorization: ".$API_KEY, ) ); if(!empty($data) && $method!="GET"){ $opts['http']['content'] = http_build_query($data); }elseif(!empty($data) && $method=="GET"){ $toSend = http_build_query($data); $url.="?".$toSend; } //echol($opts); //echol($url); $context = stream_context_create($opts); $result = file_get_contents($url, false, $context); // !!!! TBD write responce log //echo($result); if($result!==false) $responce = json_decode($result, true); else $responce = "error"; return $responce; } function getRestFile($address){ global $API_URL; global $API_ADDRESS; global $API_KEY; $method="POST"; $data = ""; $service = $address; $url = $API_URL.$service; //echol($url); //print_r($API_ADDRESS); $opts = array('http' => array( 'method' => $method, 'header' => "Authorization: ".$API_KEY, ) ); if(!empty($data) && $method!="GET"){ $opts['http']['content'] = http_build_query($data); }elseif(!empty($data) && $method=="GET"){ $toSend = http_build_query($data); $url.="?".$toSend; } //echol($opts); //echol($url); $context = stream_context_create($opts); $result = file_get_contents($url, false, $context); global $fileResponce; $fileResponce = $http_response_header; // !!!! TBD write responce log if($result!==false) return $result; else return "error"; } function getIBElements($IBL, $arFilter=[], $arSelect=false, $arSort=false, $main_field=false){ $arFilter["IBLOCK_ID"]=$IBL; $res = CIBlockElement::GetList($arSort, $arFilter, false, false, $arSelect); while ($arFields = $res->Fetch()) { if(!$main_field==false) $out[$arFields[$main_field]] = $arFields; else $out[] = $arFields; } return $out; } function GetRedirectURL($redirectItem){ global $CATALOG_IBLOCK_ID; $to = array_keys($redirectItem); $to = $to[0]; $type = $redirectItem[$to]; switch ($type){ case 'section': $arFilter = Array("ID" => $to, "ACTIVE"=>"Y"); $items = GetIBlockSectionList($CATALOG_IBLOCK_ID, false, Array("sort"=>"asc"), 1, $arFilter); if ($arItem = $items->GetNext()) { $SEND_URL =$arItem['SECTION_PAGE_URL']; } //echo "!".$SEND_URL."#"; break; case 'product': $arFilter = Array("IBLOCK_ID"=>$IBLOCK, "ID" =>$to, "ACTIVE"=>""); $arSelectFields = ['ID', 'DETAIL_PAGE_URL', 'LIST_PAGE_URL']; $res = GetIBlockElementListEx('catalog', $IBLOCK, false, false, 1, $arFilter, $arSelectFields, false); if ($arFields = $res->GetNext()) { $SEND_URL = $arFields['DETAIL_PAGE_URL']; } break; default: return false; } return $SEND_URL; } function find404to301($url=""){ // Поиск редиректа каталога include($_SERVER['DOCUMENT_ROOT'].'/local/php_interface/rk/redirect_caught.php'); // $REDIRECT_RK_NEW if(empty($url)) $URL = !empty($_SERVER['REDIRECT_URL']) ? $_SERVER['REDIRECT_URL'] : $_SERVER['SCRIPT_URL']; else $URL = $url; if (isset($REDIRECT_RK_NEW[$URL])) { $SEND_URL = GetRedirectURL($REDIRECT_RK_NEW[$URL]); } //если редирект не найден и ссылка иммеет вид product, то пробуем поискать редирект на section if(empty($SEND_URL)/* && strpos($URL,".html") > 0*/){ $arURL = explode("/",$URL); while(count($arURL) > 1 && empty($SEND_URL)) { unset($arURL[count($arURL)-1]); $URL = implode("/", $arURL)."/"; if (isset($REDIRECT_RK_NEW[$URL])) { $SEND_URL = GetRedirectURL($REDIRECT_RK_NEW[$URL]); } } if(!empty($SEND_URL)) return $SEND_URL; } unset($REDIRECT_RK_NEW); return false; } ?>