Ejemplo n.º 1
0
	public function ImportFromID($id = 0) {
		global $USER;
		if (!is_object($USER)) $USER = new CUser;

		$channel = CIChannelsRssRep::GetRssChannelById($id);
		if (!$channel) return;

		$arUrl = parse_url($channel['URL']);

		if (!array_key_exists('port', $arUrl)) $arUrl['port'] = 80;
		if (!array_key_exists('path', $arUrl)) $arUrl['path'] = '';
		if (!array_key_exists('query', $arUrl)) $arUrl['query'] = '';

		CModule::IncludeModule('iblock');

		$rChannel = CIBlockRSS::GetNewsEx(
			$arUrl['host'],
			$arUrl['port'],
			$arUrl['path'],
			$arUrl['query']
		);

		$arChannel = CIBlockRSS::FormatArray($rChannel);

		$mapper = CIChannels::getRssMapperByID($channel['MAPPER']);

		$ins = new $mapper['class'];

		foreach ($arChannel['item'] as $item) {
			$arFields = $ins->{$mapper['method']}($item, $channel);
			if (empty ($arFields)) continue;

			$arFields['ACTIVE'] = 'Y';
			$arFields['IBLOCK_TYPE_ID'] = $channel['IBLOCK_TYPE_ID'];
			$arFields['IBLOCK_ID'] = $channel['IBLOCK_ID'];

			if ($channel['IBLOCK_SECTION_ID'] != '0') {
				$arFields['IBLOCK_SECTION_ID'] = $channel['IBLOCK_SECTION_ID'];
			}

			$iblockElement = new CIBlockElement();
			$iNewElementID = $iblockElement->Add($arFields);
		}

		return sprintf('%s(%d);', __METHOD__, $id);
	}
Ejemplo n.º 2
0
	function GetNews($ID, $LANG, $TYPE, $SITE, $PORT, $PATH, $LIMIT = 0)
	{
		if (IntVal($ID)>0)
		{
			$ID = IntVal($ID);
		}
		else
		{
			$ID = Trim($ID);
		}
		$LANG = Trim($LANG);
		$TYPE = Trim($TYPE);
		$LIMIT = IntVal($LIMIT);

		return CIBlockRSS::GetNewsEx($SITE, $PORT, $PATH, "ID=".$ID."&LANG=".$LANG."&TYPE=".$TYPE."&LIMIT=".$LIMIT);
	}
Ejemplo n.º 3
0
        $arParams["QUERY_STR"] = $ar["query"];
    }
} else {
    $arParams["SITE"] = trim($arParams["SITE"]);
    $arParams["PORT"] = intval($arParams["PORT"]);
    $arParams["PATH"] = trim($arParams["PATH"]);
    $arParams["QUERY_STR"] = trim($arParams["QUERY_STR"]);
}
$arParams["OUT_CHANNEL"] = $arParams["OUT_CHANNEL"] == "Y";
$arParams["NUM_NEWS"] = intval($arParams["NUM_NEWS"]);
if ($arParams["PROCESS"] != "QUOTE" && $arParams["PROCESS"] != "TEXT") {
    $arParams["PROCESS"] = "NONE";
}
/*************************************************************************
	Start caching
*************************************************************************/
if ($this->StartResultCache()) {
    $arResult = CIBlockRSS::GetNewsEx($arParams["SITE"], $arParams["PORT"], $arParams["PATH"], $arParams["QUERY_STR"], $arParams["OUT_CHANNEL"]);
    $arResult = CIBlockRSS::FormatArray($arResult, $arParams["OUT_CHANNEL"]);
    if ($arParams["NUM_NEWS"] > 0) {
        while (count($arResult["item"]) > $arParams["NUM_NEWS"]) {
            array_pop($arResult["item"]);
        }
    }
    if ($arParams["PROCESS"] == "QUOTE") {
        array_walk_recursive($arResult, create_function('&$val, $key', '$val=htmlspecialcharsex($val);'));
    } elseif ($arParams["PROCESS"] == "TEXT") {
        array_walk_recursive($arResult, create_function('&$val, $key', '$val=str_replace(array("    ", "\\r\\n"), array("&nbsp;&nbsp;&nbsp;&nbsp;", "<br>"), HTMLToTxt($val));'));
    }
    $this->IncludeComponentTemplate();
}