/** * Returns action response XML * * @param string $action * @return CDataXML * @throws CBitrixCloudException */ protected function action($action) { /* @var CMain $APPLICATION */ global $APPLICATION; $url = $this->getActionURL(array("action" => $action, "debug" => $this->debug ? "y" : "n")); $this->server = new CHTTP(); if ($this->timeout > 0) { $this->server->http_timeout = $this->timeout; } $strXML = $this->server->Get($url); if ($strXML === false) { $e = $APPLICATION->GetException(); if (is_object($e)) { throw new CBitrixCloudException($e->GetString(), ""); } else { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_SERVER", array("#STATUS#" => "-1")), ""); } } if ($this->server->status != 200) { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_SERVER", array("#STATUS#" => (string) $this->server->status)), ""); } $obXML = new CDataXML(); if (!$obXML->LoadString($strXML)) { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_XML_PARSE", array("#CODE#" => "1")), ""); } $node = $obXML->SelectNodes("/error/code"); if (is_object($node)) { $error_code = $node->textContent(); $message_id = "BCL_CDN_WS_" . $error_code; /* GetMessage("BCL_CDN_WS_LICENSE_EXPIRE"); GetMessage("BCL_CDN_WS_LICENSE_NOT_FOUND"); GetMessage("BCL_CDN_WS_QUOTA_EXCEEDED"); GetMessage("BCL_CDN_WS_CMS_LICENSE_NOT_FOUND"); GetMessage("BCL_CDN_WS_DOMAIN_NOT_REACHABLE"); GetMessage("BCL_CDN_WS_LICENSE_DEMO"); GetMessage("BCL_CDN_WS_LICENSE_NOT_ACTIVE"); GetMessage("BCL_CDN_WS_NOT_POWERED_BY_BITRIX_CMS"); GetMessage("BCL_CDN_WS_WRONG_DOMAIN_SPECIFIED"); */ $debug_content = ""; $node = $obXML->SelectNodes("/error/debug"); if (is_object($node)) { $debug_content = $node->textContent(); } if (HasMessage($message_id)) { throw new CBitrixCloudException(GetMessage($message_id), $error_code, $debug_content); } else { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_SERVER", array("#STATUS#" => $error_code)), $error_code, $debug_content); } } return $obXML; }
function GetBoardFromSite($queryParameters) { global $APPLICATION; $result = array(); $ob = new CHTTP(); $ob->http_timeout = 60; $ob->Query("GET", "old.vnukovo.ru", 80, "/rus/for-passengers/board1/data.wbp?" . $queryParameters . '&ts=' . mktime(), false, "", "N"); $result["ERROR"]["CODE"] = $ob->errno; $result["ERROR"]["MESSAGE"] = $ob->errstr; if (!intval($result["ERROR"]["CODE"])) { $res = $APPLICATION->ConvertCharset($ob->result, "UTF-8", SITE_CHARSET); //trace($res); $xml = new CDataXML(); if ($xml->LoadString($res) && ($node = $xml->SelectNodes("/responce/rows"))) { $rows = $node->elementsByName("row"); $akNames = array(); $akCodes = array(); $departures = array(); $arrivals = array(); $terminals = array(); foreach ($rows as $row) { $cells = $row->elementsByName("cell"); // Определяем код авиакомпании и номер рейса preg_match_all("/([A-Za-zА-Яа-я0-9]{2})[\\s]*([0-9]+)/", $cells[0]->content, $flightNumber, PREG_PATTERN_ORDER); $result["FLIGHTS"][] = array("FLIGHT" => array("AK_CODE" => $flightNumber[1][0], "NUMBER" => $flightNumber[2][0]), "AK_NAME" => htmlspecialcharsEx($cells[1]->content), "DEPARTURE" => htmlspecialcharsEx($cells[2]->content), "ARRIVAL" => htmlspecialcharsEx($cells[3]->content), "STATUS" => CAirportBoard::GetStatusInfo($cells[4]->content), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($cells[5]->content), "ESTIMATED" => CAirportBoard::GetDateTimeArray($cells[6]->content), "ACTUAL" => CAirportBoard::GetDateTimeArray($cells[7]->content)), "TERMINAL" => htmlspecialcharsEx($cells[8]->content)); // Формируем список уникальных авиакомпаний, терминалов и пунктов вылета и прилета для фильтра if (!in_array(htmlspecialcharsEx($cells[1]->content), $akNames)) { $akNames[] = htmlspecialcharsEx($cells[1]->content); } if (!in_array($flightNumber[1][0], $akCodes)) { $akCodes[] = $flightNumber[1][0]; } if (!in_array(htmlspecialcharsEx($cells[2]->content), $departures)) { $departures[] = htmlspecialcharsEx($cells[2]->content); } if (!in_array(htmlspecialcharsEx($cells[3]->content), $arrivals)) { $arrivals[] = htmlspecialcharsEx($cells[3]->content); } if (!in_array(htmlspecialcharsEx($cells[8]->content), $terminals)) { $terminals[] = htmlspecialcharsEx($cells[8]->content); } } sort($akNames); sort($akCodes); sort($departures); sort($arrivals); sort($terminals); $result["AK_NAMES"] = $akNames; $result["AK_CODES"] = $akCodes; $result["DEPARTURES"] = $departures; $result["ARRIVALS"] = $arrivals; $result["TERMINALS"] = $terminals; } } return $result; }
function AddFlightsToResult($html, $result, $terminal) { $res = '<table>' . $html . '</table>'; $res = str_replace(" ", " ", $res); $res = str_replace("<br>", " ", $res); $res = preg_replace("/<!--.*-->/Uis", "", $res); $res = preg_replace("/<colgroup>.*<\\/colgroup>/Uis", "", $res); $res = preg_replace("/<param[^>]*>/Uis", "", $res); $res = preg_replace("/<a[^>]*>[^<]+<\\/a>/Uis", "", $res); //trace($res); $xml = new CDataXML(); if ($xml->LoadString($res)) { $node = $xml->SelectNodes("/table"); $rows = $node->elementsByName("tr"); $i = 0; foreach ($rows as $row) { //trace($row->getAttribute("class")); if (!strstr($row->getAttribute("class"), "onlineDetailTr")) { $cells = $row->elementsByName("td"); if (count($cells) && preg_match("/([A-Za-zА-Яа-я0-9]{2})\\s*([0-9]+)\\s*/", $cells[0]->content)) { // Определяем код авиакомпании и номер рейса preg_match_all("/([A-Za-zА-Яа-я0-9]{2})\\s*([0-9]+)\\s*/", $cells[0]->content, $flightNumber, PREG_PATTERN_ORDER); $result["FLIGHTS"][$i] = array("FLIGHT" => array("AK_CODE" => $flightNumber[1][0], "NUMBER" => $flightNumber[2][0]), "AK_NAME" => htmlspecialcharsEx($cells[5]->content), "DEPARTURE" => htmlspecialcharsEx($cells[1]->content), "ARRIVAL" => htmlspecialcharsEx($cells[1]->content), "STATUS" => CAirportBoard::GetStatusInfo($cells[4]->content), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($cells[2]->content), "ESTIMATED" => "", "ACTUAL" => CAirportBoard::GetDateTimeArray($cells[3]->content)), "TERMINAL" => $terminal); // Формируем список уникальных терминалов и пунктов вылета и прилета для фильтра if (!in_array($flightNumber[1][0], $result["AK_CODES"])) { $result["AK_CODES"][] = $flightNumber[1][0]; } if (!in_array($result["FLIGHTS"][$i]["AK_NAME"], $result["AK_NAMES"]) && strlen($result["FLIGHTS"][$i]["AK_NAME"])) { $result["AK_NAMES"][] = $result["FLIGHTS"][$i]["AK_NAME"]; } if (!in_array($result["FLIGHTS"][$i]["DEPARTURE"], $result["DEPARTURES"])) { $result["DEPARTURES"][] = $result["FLIGHTS"][$i]["DEPARTURE"]; } if (!in_array($result["FLIGHTS"][$i]["ARRIVAL"], $result["ARRIVALS"])) { $result["ARRIVALS"][] = $result["FLIGHTS"][$i]["ARRIVAL"]; } if (!in_array($result["FLIGHTS"][$i]["TERMINAL"], $result["TERMINALS"])) { $result["TERMINALS"][] = $result["FLIGHTS"][$i]["TERMINAL"]; } $i++; } } } } unset($html, $xml, $res); return $result; }
protected function CreateCourse() { global $APPLICATION; if (strlen($this->LAST_ERROR) > 0) { return false; } if (!($title = $this->objXML->SelectNodes("/manifest/organizations/organization/item/title"))) { $this->LAST_ERROR = GetMessage("LEARNING_BAD_NAME"); return false; } $arFields = array("NAME" => $title->content, "SITE_ID" => $this->arSITE_ID); $course = new CCourse(); $this->COURSE_ID = $course->Add($arFields); $res = $this->COURSE_ID; if (!$res) { if ($e = $APPLICATION->GetException()) { $this->LAST_ERROR = $e->GetString(); } return false; } $r = new CDataXML(); if (!$r->Load($this->package_dir . "/res1.xml")) { return false; } if (!($data = $r->SelectNodes("/coursetoc/"))) { return false; } $ar = $data->__toArray(); $arFields = $this->_MakeFields($ar); $res = $course->Update($this->COURSE_ID, $arFields); if (!$res) { if ($e = $APPLICATION->GetException()) { $this->LAST_ERROR = $e->GetString(); } return false; } CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/learning/" . $this->COURSE_ID); CLearnHelper::CopyDirFiles($this->package_dir . "/resources/res1", $_SERVER["DOCUMENT_ROOT"] . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/learning/" . $this->COURSE_ID . "/res1", true); return true; }
/** * Returns action response XML * * @param string $action * @return CDataXML * */ protected function action($action) { global $APPLICATION; $url = $this->getActionURL(array("action" => $action)); $server = new CHTTP(); $strXML = $server->Get($url); if ($strXML === false) { $e = $APPLICATION->GetException(); if (is_object($e)) { throw new CBitrixCloudException($e->GetString(), ""); } else { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_SERVER", array("#STATUS#" => "-1")), ""); } } if ($server->status != 200) { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_SERVER", array("#STATUS#" => (string) $server->status)), ""); } $obXML = new CDataXML(); if (!$obXML->LoadString($strXML)) { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_XML_PARSE", array("#CODE#" => "1")), ""); } $node = $obXML->SelectNodes("/error/code"); if (is_object($node)) { $error_code = $node->textContent(); $message_id = "BCL_CDN_WS_" . $error_code; /* GetMessage("BCL_CDN_WS_LICENSE_EXPIRE"); GetMessage("BCL_CDN_WS_LICENSE_NOT_FOUND"); GetMessage("BCL_CDN_WS_QUOTA_EXCEEDED"); */ if (HasMessage($message_id)) { throw new CBitrixCloudException(GetMessage($message_id), $error_code); } else { throw new CBitrixCloudException(GetMessage("BCL_CDN_WS_SERVER", array("#STATUS#" => $error_code)), $error_code); } } return $obXML; }
$url = 'ts=' . mktime(); } $cache = new CPageCache(); if ($arGadgetParams["CACHE_TIME"] > 0 && !$cache->StartDataCache($arGadgetParams["CACHE_TIME"], 'c' . $arGadgetParams["CITY"], "gdprobki")) { return; } $ob = new CHTTP(); $ob->http_timeout = 10; $ob->Query("GET", "export.yandex.ru", 80, "/bar/reginfo.xml?" . $url, false, "", "N"); $errno = $ob->errno; $errstr = $ob->errstr; $res = $ob->result; $res = str_replace("−", "-", $res); $xml = new CDataXML(); $xml->LoadString($APPLICATION->ConvertCharset($res, 'UTF-8', SITE_CHARSET)); $node = $xml->SelectNodes('/info/traffic/title'); ?> <h3><?php echo $node->content; ?> </h3> <table width="90%"><tr> <td width="80%" nowrap> <?php $node = $xml->SelectNodes('/info/traffic/hint'); ?> <span class="gdtrafic"><?php echo $node->content; ?> </span><br> <span class="gdtrafinfo">
function gdGetRss($rss_url, $cache_time = 0) { /** @global CMain $APPLICATION */ global $APPLICATION; $cache = new CPHPCache(); if (!$cache->StartDataCache($cache_time, 'c' . $rss_url, "gdrss")) { $v = $cache->GetVars(); return $v['oRss']; } $oRssFeeds = new gdRssFeeds(); $ob = new CHTTP(); $ob->http_timeout = 10; $ob->setFollowRedirect(true); $ob->HTTPQuery("GET", $rss_url); $res = $ob->result; if (!$res) { $cache->EndDataCache(array("oRss" => false)); return false; } if (preg_match("/<" . "\\?XML[^>]{1,}encoding=[\"']([^>\"']{1,})[\"'][^>]{0,}\\?" . ">/i", $res, $matches)) { $charset = trim($matches[1]); $res = $APPLICATION->ConvertCharset($res, $charset, SITE_CHARSET); } $xml = new CDataXML(); $xml->LoadString($res); $oNode = $xml->SelectNodes("/rss/channel/title"); if (!$oNode) { $cache->EndDataCache(array("oRss" => false)); return false; } $oRssFeeds->title = $oNode->content; if (trim($oRssFeeds->title) == '') { if ($oSubNode = $oNode->elementsByName("cdata-section")) { $oRssFeeds->title = $oSubNode[0]->content; } } if ($oNode = $xml->SelectNodes("/rss/channel/link")) { $oRssFeeds->link = $oNode->content; } if ($oNode = $xml->SelectNodes("/rss/channel/description")) { $oRssFeeds->description = $oNode->content; } if (trim($oRssFeeds->description) == '') { if ($oNode && ($oSubNode = $oNode->elementsByName("cdata-section"))) { $oRssFeeds->description = $oSubNode[0]->content; } } if ($oNode = $xml->SelectNodes("/rss/channel/pubDate")) { $oRssFeeds->pubDate = $oNode->content; } elseif ($oNode = $xml->SelectNodes("/rss/channel/lastBuildDate")) { $oRssFeeds->pubDate = $oNode->content; } if ($oNode = $xml->SelectNodes("/rss/channel")) { $oNodes = $oNode->elementsByName("item"); foreach ($oNodes as $oNode) { $item = array(); if ($oSubNode = $oNode->elementsByName("title")) { $item["TITLE"] = $oSubNode[0]->content; } if (trim($item["TITLE"]) == '' && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["TITLE"] = $oSubNode[0]->content; } } if ($oSubNode = $oNode->elementsByName("link")) { $item["LINK"] = $oSubNode[0]->content; } if ($oSubNode = $oNode->elementsByName("pubDate")) { $item["PUBDATE"] = $oSubNode[0]->content; } if ($oSubNode = $oNode->elementsByName("description")) { $item["DESCRIPTION"] = $oSubNode[0]->content; } if (trim($item["DESCRIPTION"]) == '' && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["DESCRIPTION"] = $oSubNode[0]->content; } } if ($oSubNode = $oNode->elementsByName("author")) { $item["AUTHOR"] = $oSubNode[0]->content; } if (trim($item["AUTHOR"]) == '' && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["AUTHOR"] = $oSubNode[0]->content; } } $oRssFeeds->items[] = $item; } } $cache->EndDataCache(array("oRss" => $oRssFeeds)); return $oRssFeeds; }
function gdGetRss($rss_url, $cache_time = 0) { $cache = new CPHPCache(); if (!$cache->StartDataCache($cache_time, 'c' . $rss_url, "gdrss")) { $v = $cache->GetVars(); return $v['oRss']; } $oRssFeeds = new gdRssFeeds(); $arUrl = parse_url($rss_url); if (IntVal($arUrl["port"]) <= 0) { $arUrl["port"] = 80; } $ob = new CHTTP(); $ob->http_timeout = 10; $ob->Query("GET", $arUrl["host"], $arUrl["port"], $arUrl["path"] . ($arUrl["query"] != '' ? "?" . $arUrl["query"] : ''), false, "", "N"); $errno = $ob->errno; $errstr = $ob->errstr; $res = $ob->result; if (!$res) { $cache->EndDataCache(array("oRss" => false)); return false; } if (preg_match("/<" . "\\?XML[^>]{1,}encoding=[\"']([^>\"']{1,})[\"'][^>]{0,}\\?" . ">/i", $res, $matches)) { $charset = Trim($matches[1]); } $res = $GLOBALS["APPLICATION"]->ConvertCharset($res, $charset, SITE_CHARSET); $xml = new CDataXML(); $xml->LoadString($res); $oNode = $xml->SelectNodes("/rss/channel/title"); if (!$oNode) { $cache->EndDataCache(array("oRss" => false)); return false; } $oRssFeeds->title = $oNode->content; if (strlen(trim($oRssFeeds->title)) <= 0) { if ($oSubNode = $oNode->elementsByName("cdata-section")) { $oRssFeeds->title = $oSubNode[0]->content; } } if ($oNode = $xml->SelectNodes("/rss/channel/link")) { $oRssFeeds->link = $oNode->content; } if ($oNode = $xml->SelectNodes("/rss/channel/description")) { $oRssFeeds->description = $oNode->content; } if (strlen(trim($oRssFeeds->description)) <= 0) { if ($oNode && ($oSubNode = $oNode->elementsByName("cdata-section"))) { $oRssFeeds->description = $oSubNode[0]->content; } } if ($oNode = $xml->SelectNodes("/rss/channel/pubDate")) { $oRssFeeds->pubDate = $oNode->content; } elseif ($oNode = $xml->SelectNodes("/rss/channel/lastBuildDate")) { $oRssFeeds->pubDate = $oNode->content; } if ($oNode = $xml->SelectNodes("/rss/channel")) { $oNodes = $oNode->elementsByName("item"); foreach ($oNodes as $oNode) { $item = array(); if ($oSubNode = $oNode->elementsByName("title")) { $item["TITLE"] = $oSubNode[0]->content; } if (strlen(trim($item["TITLE"])) <= 0 && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["TITLE"] = $oSubNode[0]->content; } } if ($oSubNode = $oNode->elementsByName("link")) { $item["LINK"] = $oSubNode[0]->content; } if ($oSubNode = $oNode->elementsByName("pubDate")) { $item["PUBDATE"] = $oSubNode[0]->content; } if ($oSubNode = $oNode->elementsByName("description")) { $item["DESCRIPTION"] = $oSubNode[0]->content; } if (strlen(trim($item["DESCRIPTION"])) <= 0 && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["DESCRIPTION"] = $oSubNode[0]->content; } } if ($oSubNode = $oNode->elementsByName("author")) { $item["AUTHOR"] = $oSubNode[0]->content; } if (strlen(trim($item["AUTHOR"])) <= 0 && !empty($oSubNode)) { if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) { $item["AUTHOR"] = $oSubNode[0]->content; } } $oRssFeeds->items[] = $item; } } $cache->EndDataCache(array("oRss" => $oRssFeeds)); return $oRssFeeds; }
// Лучше бы через // $xml->Load('/path/to/file'); $xml->LoadString($data); // получаем данные /** * В минимальном варианте: * - фото * - марка * - модель * - год выпуска * + объём двигателя * - пробег * - цена */ $arVehicles = array(); $xmlVehicles = $xml->SelectNodes('/response/vehicles'); $i = 0; if ($xmlVehicles && is_object($xmlVehicles)) { // Проверяем, что вообще есть объявления foreach ($xmlVehicles->children() as $vNode) { /* @var CDataXMLNode $vNode */ $vehicle = $vNode->__toArray(); $arVehicles[$i] = array(); $arVehicles[$i]['VEHICLE_ID'] = $vehicle['@']['vehicle_id']; $arVehicles[$i]['DEALER_ID'] = $vehicle['@']['dealer_id']; $arVehicles[$i]['URL_TO_VEHICLE'] = CComponentEngine::MakePathFromTemplate($arParams['URL_TEMPLATES_VEHICLE'], array('VEHICLE_ID' => $arVehicles[$i]['VEHICLE_ID'])); // Фото if (array_key_exists('photo', $vehicle['#']) && array_key_exists('0', $vehicle['#']['photo'])) { $photoFileName = $vehicle['#']['photo']['0']['@']['file_name']; $webDirPath = trim(COption::GetOptionString($moduleId, 'MAX_UPLOAD_PATH'), '/'); $basePhotoPath = sprintf('%s/%s/%d/%d', rtrim($_SERVER["DOCUMENT_ROOT"], '/'), $webDirPath, $arVehicles[$i]['DEALER_ID'], $arVehicles[$i]['VEHICLE_ID']);
/** * @param array[string]string $arSettings * @param string $verb * @param string $bucket * @param string $file_name * @param string $params * @param string $content * @param array[string]string $additional_headers * @return mixed */ public function SendRequest($arSettings, $verb, $bucket, $file_name = '/', $params = '', $content = '', $additional_headers = array()) { global $APPLICATION; $this->status = 0; if (isset($additional_headers["Content-Type"])) { $ContentType = $additional_headers["Content-Type"]; unset($additional_headers["Content-Type"]); } else { $ContentType = $content != "" ? 'text/plain' : ''; } foreach ($this->set_headers as $key => $value) { $additional_headers[$key] = $value; } if (array_key_exists("SESSION_TOKEN", $arSettings)) { $additional_headers["x-amz-security-token"] = $arSettings["SESSION_TOKEN"]; } ksort($additional_headers); $RequestURI = $file_name; $obRequest = new CHTTP(); if (isset($additional_headers["option-file-result"])) { $obRequest->fp = $additional_headers["option-file-result"]; } foreach ($this->SignRequest($arSettings, $verb, $bucket, $file_name, $ContentType, $additional_headers) as $key => $value) { $obRequest->additional_headers[$key] = $value; } foreach ($additional_headers as $key => $value) { if (preg_match("/^option-/", $key) == 0) { $obRequest->additional_headers[$key] = $value; } } if ($this->new_end_point != "" && preg_match('#^(http|https)://' . preg_quote($bucket, '#') . '(.+?)/#', $this->new_end_point, $match) > 0) { $host = $bucket . $match[2]; } elseif ($this->location) { $host = $bucket . "." . $this->location . ".amazonaws.com"; } else { $host = $bucket . ".s3.amazonaws.com"; } $was_end_point = $this->new_end_point; $this->new_end_point = ''; $obRequest->Query($verb, $host, 80, $RequestURI . $params, $content, '', $ContentType); $this->status = $obRequest->status; $this->host = $host; $this->verb = $verb; $this->url = $RequestURI . $params; $this->headers = $obRequest->headers; $this->errno = $obRequest->errno; $this->errstr = $obRequest->errstr; $this->result = $obRequest->result; if ($obRequest->status == 200) { if (isset($additional_headers["option-raw-result"]) || isset($additional_headers["option--result"])) { return $obRequest->result; } elseif ($obRequest->result != "") { $obXML = new CDataXML(); $text = preg_replace("/<" . "\\?XML.*?\\?" . ">/i", "", $obRequest->result); if ($obXML->LoadString($text)) { $arXML = $obXML->GetArray(); if (is_array($arXML)) { return $arXML; } } //XML parse error $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_PARSE_ERROR', array('#errno#' => '1'))); $APPLICATION->ThrowException($e); return false; } else { //Empty success result return array(); } } elseif ($obRequest->status == 307 && isset($obRequest->headers["Location"]) && $was_end_point === "") { $this->new_end_point = $obRequest->headers["Location"]; return $this->SendRequest($arSettings, $verb, $bucket, $file_name, $params, $content, $additional_headers); } elseif ($obRequest->status > 0) { if ($obRequest->result != "") { $obXML = new CDataXML(); if ($obXML->LoadString($obRequest->result)) { $node = $obXML->SelectNodes("/Error/Message"); if (is_object($node)) { $errmsg = trim($node->textContent(), '.'); $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_ERROR', array('#errmsg#' => $errmsg))); $APPLICATION->ThrowException($e); return false; } } } $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_PARSE_ERROR', array('#errno#' => '2'))); $APPLICATION->ThrowException($e); return false; } else { $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_PARSE_ERROR', array('#errno#' => '3'))); $APPLICATION->ThrowException($e); return false; } }
public static function ImportPropsFromXML($BID, $xmlPath, &$arOldNewID) { if (file_exists($xmlPath) && $BID && CModule::IncludeModule('iblock')) { require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/classes/general/xml.php'; $arExistProps = array(); $rsProp = CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $BID)); while ($arProp = $rsProp->Fetch()) { $arExistProps[$arProp['CODE']] = $arProp; } $arExistEnums = array(); $rsEnum = CIBlockPropertyEnum::GetList(array(), array('IBLOCK_ID' => $BID)); while ($arEnum = $rsEnum->Fetch()) { $arExistEnums[$arEnum['PROPERTY_ID'] . '_' . $arEnum['XML_ID']] = $arEnum; } $arOldNewID = array(); $xml = new CDataXML(); $ep = new CIBlockProperty(); $en = new CIBlockPropertyEnum(); if ($xml->Load($xmlPath)) { if ($node = $xml->SelectNodes('/asd_iblock_props/props/')) { foreach ($node->children() as $child) { $arProp = array_pop($child->__toArray()); $arFields = array('IBLOCK_ID' => $BID); foreach ($arProp as $code => $v) { $arFields[strtoupper($code)] = is_array($v[0]['#']['cdata-section']) ? $v[0]['#']['cdata-section'][0]['#'] : $v[0]['#']; } if (isset($arExistProps[$arFields['CODE']])) { $arOldNewID[$arFields['OLD_ID']] = $arExistProps[$arFields['CODE']]['ID']; $ep->Update($arExistProps[$arFields['CODE']]['ID'], $arFields); } else { $arOldNewID[$arFields['OLD_ID']] = $arFields['ID'] = $ep->Add($arFields); $arExistProps[$arFields['CODE']] = $arFields; } } } if ($node = $xml->SelectNodes('/asd_iblock_props/enums/')) { foreach ($node->children() as $child) { $arProp = array_pop($child->__toArray()); $arFields = array('IBLOCK_ID' => $BID); foreach ($arProp as $code => $v) { $arFields[strtoupper($code)] = is_array($v[0]['#']['cdata-section']) ? $v[0]['#']['cdata-section'][0]['#'] : $v[0]['#']; } $arFields['PROPERTY_ID'] = $arExistProps[$arFields['PROPERTY_CODE']]['ID']; if (isset($arExistEnums[$arFields['PROPERTY_ID'] . '_' . $arFields['XML_ID']])) { $en->Update($arExistEnums[$arFields['PROPERTY_ID'] . '_' . $arFields['XML_ID']]['ID'], $arFields); } else { $en->Add($arFields); } } } } } }
function GetBoardFromSite() { $result = array(); global $APPLICATION; $ob = new CHTTP(); $ob->http_timeout = 60; $ob->Query("GET", "svo.aero", 80, "/timetable/today/?ts=" . mktime(), false, "", "N"); $result["ERROR"] = array("CODE" => $ob->errno, "MESSAGE" => $ob->errstr); $res = $APPLICATION->ConvertCharset($ob->result, "UTF-8", SITE_CHARSET); $res = str_replace('</thead><tbody>', "++++", $res); $res = str_replace('</tr></tbody></table></div>', "</tr>++++", $res); $explode = explode("++++", $res); $res = '<table>' . $explode[1] . '</table>'; $resPatterns = array("/<a[^>]*>/Uis", "/<\\/a>/Uis"); $resReplace = array("", ""); $res = preg_replace($resPatterns, $resReplace, $res); //trace($res); if (!intval($result["ERROR"]["CODE"])) { $result["INBOUND"]["AK_NAMES"] = array(); $result["INBOUND"]["AK_CODES"] = array(); $result["INBOUND"]["DEPARTURES"] = array(); $result["INBOUND"]["ARRIVALS"] = array(); $result["INBOUND"]["TERMINALS"] = array(); $result["OUTBOUND"]["AK_NAMES"] = array(); $result["OUTBOUND"]["AK_CODES"] = array(); $result["OUTBOUND"]["DEPARTURES"] = array(); $result["OUTBOUND"]["ARRIVALS"] = array(); $result["OUTBOUND"]["TERMINALS"] = array(); $xml = new CDataXML(); if ($xml->LoadString($res)) { $node = $xml->SelectNodes("/table"); $rows = $node->elementsByName("tr"); $i = 0; foreach ($rows as $row) { $boardType = strstr($row->getAttribute("class"), "sA") ? "INBOUND" : (strstr($row->getAttribute("class"), "sD") ? "OUTBOUND" : false); if ($boardType) { $cells = $row->elementsByName("td"); if (count($cells)) { $img = $cells[4]->elementsByName("img"); preg_match_all("/([0-9]{1,2}:[0-9]{1,2})/", $cells[7]->content, $timeFromStatus, PREG_PATTERN_ORDER); preg_match_all("/^([а-я]+)\\s*/i", $cells[7]->content, $status, PREG_PATTERN_ORDER); $result[$boardType]["FLIGHTS"][$i] = array("FLIGHT" => array("AK_CODE" => $cells[2]->content, "NUMBER" => $cells[3]->content), "AK_NAME" => count($img) ? htmlspecialcharsEx($img[0]->getAttribute("alt")) : "", "DEPARTURE" => htmlspecialcharsEx($cells[5]->content), "ARRIVAL" => htmlspecialcharsEx($cells[5]->content), "STATUS" => CAirportBoard::GetStatusInfo($status), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($cells[1]->content, $cells[0]->content), "ESTIMATED" => strpos($cells[7]->content, "задерживается") !== false || strpos($cells[7]->content, "ожидается") !== false ? CAirportBoard::GetDateTimeArray($timeFromStatus[1][0]) : "", "ACTUAL" => strpos($cells[7]->content, "совершил посадку") !== false || strpos($cells[7]->content, "прибыл") !== false || strpos($cells[7]->content, "вылетел") !== false || strpos($cells[7]->content, "отправлен") !== false ? CAirportBoard::GetDateTimeArray($timeFromStatus[1][0]) : ""), "TERMINAL" => $cells[6]->content); // Формируем список уникальных терминалов и пунктов вылета и прилета для фильтра if (!in_array($result[$boardType]["FLIGHTS"][$i]["FLIGHT"]["AK_CODE"], $result[$boardType]["AK_CODES"])) { $result[$boardType]["AK_CODES"][] = $result[$boardType]["FLIGHTS"][$i]["FLIGHT"]["AK_CODE"]; } if (!in_array($result[$boardType]["FLIGHTS"][$i]["AK_NAME"], $result[$boardType]["AK_NAMES"]) && strlen($result[$boardType]["FLIGHTS"][$i]["AK_NAME"])) { $result[$boardType]["AK_NAMES"][] = $result[$boardType]["FLIGHTS"][$i]["AK_NAME"]; } if (!in_array($result[$boardType]["FLIGHTS"][$i]["DEPARTURE"], $result[$boardType]["DEPARTURES"])) { $result[$boardType]["DEPARTURES"][] = $result[$boardType]["FLIGHTS"][$i]["DEPARTURE"]; } if (!in_array($result[$boardType]["FLIGHTS"][$i]["ARRIVAL"], $result[$boardType]["ARRIVALS"])) { $result[$boardType]["ARRIVALS"][] = $result[$boardType]["FLIGHTS"][$i]["ARRIVAL"]; } if (!in_array($result[$boardType]["FLIGHTS"][$i]["TERMINAL"], $result[$boardType]["TERMINALS"])) { $result[$boardType]["TERMINALS"][] = $result[$boardType]["FLIGHTS"][$i]["TERMINAL"]; } $i++; } } } } sort($result["INBOUND"]["AK_NAMES"]); sort($result["INBOUND"]["AK_CODES"]); sort($result["INBOUND"]["DEPARTURES"]); sort($result["INBOUND"]["ARRIVALS"]); sort($result["INBOUND"]["TERMINALS"]); sort($result["OUTBOUND"]["AK_NAMES"]); sort($result["OUTBOUND"]["AK_CODES"]); sort($result["OUTBOUND"]["DEPARTURES"]); sort($result["OUTBOUND"]["ARRIVALS"]); sort($result["OUTBOUND"]["TERMINALS"]); /* // Сортируем рейсы по абсолютному времени вылета SortFreeStyleArray( $result["FLIGHTS"], Array( '["TIME"]["PLANNED"]["DATETIME"]' => 'ASC', '["FLIGHT"]' => 'ASC' ) ); */ //trace($result); } return $result; }
function GetBoardFromSite($queryParameters) { $result = array(); $result = CAirportBoard::GetOneBoardFromSite($queryParameters, ""); $res = $result["HTML"]; unset($result["HTML"]); /*// Ниже код для загрузки табло за сутки (используется три запроса с последующей склейкой) $result = CAirportBoard::GetOneBoardFromSite( $queryParameters, "v=3" ); $res = $result["HTML"]; unset($result["HTML"]); $result2 = CAirportBoard::GetOneBoardFromSite( $queryParameters, "v=11" ); $res .= $result2["HTML"]; unset($result2["HTML"]); $result3 = CAirportBoard::GetOneBoardFromSite( $queryParameters, "v=19" ); $res .= $result3["HTML"]; unset($result3["HTML"]); if ( intval($result2["ERROR"]["CODE"]) ) { $result["ERROR"] = $result2["ERROR"]; } elseif ( intval($result3["ERROR"]["CODE"]) ) { $result["ERROR"] = $result3["ERROR"]; } */ if (!intval($result["ERROR"]["CODE"])) { $res = '<table>' . $res . '</table>'; $res = str_replace("<br>", " ", $res); $res = str_replace("<nobr>", "", $res); $res = str_replace("</nobr>", "", $res); //trace($res); $xml = new CDataXML(); if ($xml->LoadString($res)) { $node = $xml->SelectNodes("/table"); $rows = $node->elementsByName("tr"); $akNames = array(); $akCodes = array(); $departures = array(); $arrivals = array(); $terminals = array(); $i = 0; foreach ($rows as $row) { if (strstr($row->getAttribute("class"), "tr0")) { $cells = $row->elementsByName("td"); // Определяем код авиакомпании и номер рейса preg_match_all("/([A-Za-zА-Яа-я0-9]{2})\\s*([0-9]+)\\s*/", $cells[0]->content, $flightNumber, PREG_PATTERN_ORDER); $cityPatterns = array("/([\\W\\d]+)\\(/", "/\\s+\\)\\s*/"); $cityReplace = array("\$1 (", ")"); $result["FLIGHTS"][$i] = array("FLIGHT" => array("AK_CODE" => $flightNumber[1][0], "NUMBER" => $flightNumber[2][0]), "AK_NAME" => "", "DEPARTURE" => htmlspecialcharsEx(preg_replace($cityPatterns, $cityReplace, $cells[1]->content)), "ARRIVAL" => htmlspecialcharsEx(preg_replace($cityPatterns, $cityReplace, $cells[1]->content)), "STATUS" => CAirportBoard::GetStatusInfo($cells[5]->content), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($cells[2]->content), "ESTIMATED" => "", "ACTUAL" => CAirportBoard::GetDateTimeArray($cells[3]->content)), "TERMINAL" => ""); // Формируем список уникальных терминалов и пунктов вылета и прилета для фильтра if (!in_array($flightNumber[1][0], $akCodes)) { $akCodes[] = $flightNumber[1][0]; } if (!in_array($result["FLIGHTS"][$i]["DEPARTURE"], $departures)) { $departures[] = $result["FLIGHTS"][$i]["DEPARTURE"]; } if (!in_array($result["FLIGHTS"][$i]["ARRIVAL"], $arrivals)) { $arrivals[] = $result["FLIGHTS"][$i]["ARRIVAL"]; } $i++; } } sort($akNames); sort($akCodes); sort($departures); sort($arrivals); sort($terminals); $result["AK_NAMES"] = $akNames; $result["AK_CODES"] = $akCodes; $result["DEPARTURES"] = $departures; $result["ARRIVALS"] = $arrivals; $result["TERMINALS"] = $terminals; } } return $result; }
$url = 'ts=' . mktime(); } $cache = new CPageCache(); if ($arGadgetParams["CACHE_TIME"] > 0 && !$cache->StartDataCache($arGadgetParams["CACHE_TIME"], 'c' . $arGadgetParams["CITY"], "gdweather")) { return; } $ob = new CHTTP(); $ob->http_timeout = 10; $ob->Query("GET", "export.yandex.ru", 80, "/bar/reginfo.xml?" . $url, false, "", "N"); $errno = $ob->errno; $errstr = $ob->errstr; $res = $ob->result; $res = str_replace("−", "-", $res); $xml = new CDataXML(); $xml->LoadString($APPLICATION->ConvertCharset($res, 'UTF-8', SITE_CHARSET)); $node = $xml->SelectNodes('/info/region/title'); ?> <h3><?php echo $node->content; ?> </h3> <?php $node = $xml->SelectNodes('/info/weather/day/day_part/temperature'); $t = Intval($node->content); ?> <table width="90%"> <tr> <td nowrap="yes" width="20%"><span class="t<?php echo intval($t / 10); ?>
<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } $defCity = "c213"; //Moscow $ob = new CHTTP(); $ob->http_timeout = 10; $ob->Query("GET", "export.yandex.ru", 80, "/bar/reginfo.xml?" . $url, false, "", "N"); if ($ob->result) { $res = str_replace("в€’", "-", $ob->result); $xml = new CDataXML(); $xml->LoadString($GLOBALS["APPLICATION"]->ConvertCharset($res, 'UTF-8', SITE_CHARSET)); $node = $xml->SelectNodes('/info/region'); if (is_object($node)) { $id = $node->getAttribute("id"); if ($id > 0) { $defCity = "c" . $id; } } } include dirname(__FILE__) . '/city.php'; asort($arCity); $arParameters = array("PARAMETERS" => array("CACHE_TIME" => array("NAME" => "Время кеширования, сек (0-не кешировать)", "TYPE" => "STRING", "DEFAULT" => "3600"), "SHOW_URL" => array("NAME" => "Показывать ссылку на подробную информацию", "TYPE" => "CHECKBOX", "MULTIPLE" => "N", "DEFAULT" => "N")), "USER_PARAMETERS" => array("CITY" => array("NAME" => "Город", "TYPE" => "LIST", "MULTIPLE" => "N", "DEFAULT" => $defCity, "VALUES" => $arCity)));
function GetBoardFromSite($queryParameters) { global $APPLICATION; $result = array(); $ob = new CHTTP(); $ob->http_timeout = 60; $ob->Query("GET", "www.rossiya-airlines.com", 80, "/ru/passenger/about_flight/" . $queryParameters . '?ts=' . mktime(), false, "", "N"); $result["ERROR"]["CODE"] = $ob->errno; $result["ERROR"]["MESSAGE"] = $ob->errstr; if (intval($result["ERROR"]["CODE"]) == 0) { $res = $ob->result; $res = str_replace('<table border="0" cellpadding="0" cellspacing="0" class="table" id="tblData">', "++++<table>", $res); $res = str_replace('$(document).ready(function()', "++++", $res); $explode = explode("++++", $res); $res = $explode[1]; $res = substr($res, 0, strlen($res) - 22); $res = str_replace("<br>", " ", $res); $res = str_replace("<nobr>", "", $res); $res = str_replace("</nobr>", "", $res); //trace($res); $xml = new CDataXML(); if ($xml->LoadString($res)) { $node = $xml->SelectNodes("/table"); $rows = $node->elementsByName("tr"); $akNames = array(); $akCodes = array(); $departures = array(); $arrivals = array(); $terminals = array(); foreach ($rows as $row) { if (strstr($row->getAttribute("class"), "finddata")) { $cells = $row->elementsByName("td"); $flightNumber = $cells[0]->elementsByName("div"); // Определяем код авиакомпании и номер рейса preg_match_all("/([A-Za-zА-Яа-я0-9]{2})([0-9]+)/", $flightNumber[0]->content, $flightNumber, PREG_PATTERN_ORDER); $terminal = $cells[1]->elementsByName("div"); $city = $cells[2]->elementsByName("div"); $plannedTime = $cells[3]->elementsByName("div"); $actualTime = $cells[4]->elementsByName("div"); $status = $cells[5]->elementsByName("span"); $result["FLIGHTS"][] = array("FLIGHT" => array("AK_CODE" => $flightNumber[1][0], "NUMBER" => $flightNumber[2][0]), "AK_NAME" => "", "DEPARTURE" => htmlspecialcharsEx($city[0]->content), "ARRIVAL" => htmlspecialcharsEx($city[0]->content), "STATUS" => CAirportBoard::GetStatusInfo($status[0]->content), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($plannedTime[0]->content), "ESTIMATED" => "", "ACTUAL" => CAirportBoard::GetDateTimeArray($actualTime[0]->content)), "TERMINAL" => htmlspecialchars($terminal[0]->content)); // Формируем список уникальных терминалов и пунктов вылета и прилета для фильтра if (!in_array($flightNumber[1][0], $akCodes)) { $akCodes[] = $flightNumber[1][0]; } if (!in_array(htmlspecialcharsEx($city[0]->content), $departures)) { $departures[] = htmlspecialcharsEx($city[0]->content); } if (!in_array(htmlspecialcharsEx($city[0]->content), $arrivals)) { $arrivals[] = htmlspecialcharsEx($city[0]->content); } if (!in_array(htmlspecialcharsEx($terminal[0]->content), $terminals)) { $terminals[] = htmlspecialcharsEx($terminal[0]->content); } } } sort($akNames); sort($akCodes); sort($departures); sort($arrivals); sort($terminals); $result["AK"] = $akNames; $result["AK_CODES"] = $akCodes; $result["DEPARTURES"] = $departures; $result["ARRIVALS"] = $arrivals; $result["TERMINALS"] = $terminals; } } //trace($result); return $result; }
if ($client->getResponseThemeName() == 'error') { CHTTP::SetStatus("404 Not Found"); ShowError(GetMessage('MAX_VEHICLE_NOT_FOUND')); return; } if (mb_strtolower(SITE_CHARSET) != 'utf-8') { $data = iconv('utf-8', SITE_CHARSET, $domXml); } else { $data = $domXml; } $xml = new CDataXML(); // Лучше бы через // $xml->Load('/path/to/file'); $xml->LoadString($data); /* @var $vehicle CDataXMLNode */ $vehicle = $xml->SelectNodes('/response/vehicle'); // Формирование результатов $arResult = array(); $arResult['ID'] = intval($arParams['VEHICLE_ID']); $arResult['DEALER_ID'] = intval($vehicle->getAttribute('dealer_id')); $arResult['MARK_ID'] = $xml->SelectNodes('/response/vehicle/mark')->getAttribute('mark_id'); $arResult['MARK_NAME'] = $xml->SelectNodes('/response/vehicle/mark')->textContent(); $arResult['MODEL_ID'] = $xml->SelectNodes('/response/vehicle/model')->getAttribute('model_id'); $arResult['MODEL_NAME'] = $xml->SelectNodes('/response/vehicle/model')->textContent(); // Заголовок на странице if ($arParams['SET_TITLE']) { $appTitle = sprintf('%s %s', $arResult['MARK_NAME'], $arResult['MODEL_NAME']); $APPLICATION->SetTitle($appTitle); $APPLICATION->SetPageProperty('title', $appTitle); } // Основное