Your IP : 3.17.76.178


Current Path : /var/www/www-root/data/www/monolith-realty.ru/local/import/
Upload File :
Current File : /var/www/www-root/data/www/monolith-realty.ru/local/import/news.php

<?php
header('Expires: 0');
header('Pragma: no-cache');
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');

header('Content-Type: application/json; charset=utf-8');

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule('iblock');

if(!function_exists('pre')) {
	function pre($array) {
		echo '<pre>'; print_r($array); echo '</pre>';
	}
}

function getFilePath($id) {
	if(!empty($id)) {
		return $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . CFile::GetPath($id);
	}
}

$token = 'yJNTQdseEIlDQMh6V9Kjys8IzVj2GMop';

if(!isset($_GET['token']) || $token !== htmlspecialchars($_GET['token'])) {
	if (!defined("ERROR_404"))
		define("ERROR_404", "Y");
	
	\CHTTP::setStatus("404 Not Found");
	require(\Bitrix\Main\Application::getDocumentRoot() . "/404.php");
	die();
}

$newsIblockId = 63;

$pageNum = isset($_GET['page_num']) ? htmlspecialchars($_GET['page_num']) : 1;
$pageSize = isset($_GET['page_size']) ? htmlspecialchars($_GET['page_size']) : 10;
if($pageNum <= 0) { 
	$pageNum = 1;
}

$res = CIBlockElement::GetList(['ACTIVE_FROM' => 'DESC'], 
			['IBLOCK_ID' => $newsIblockId, 'ACTIVE' => 'Y'], 
			false, 
			//['nPageSize' => $pageSize, 'iNumPage' => $pageNum],
			['nTopCount' => $pageSize, 'nOffset' => ($pageNum - 1) * $pageSize], 
			['ID', 'NAME', 'ACTIVE_FROM', 'PREVIEW_TEXT', 'DETAIL_TEXT', 'PREVIEW_PICTURE', 'DETAIL_PICTURE' ]);

$arResult = [];
while($item = $res->Fetch()) {
	$item['PREVIEW_PICTURE'] = getFilePath($item['PREVIEW_PICTURE']);
	$item['DETAIL_PICTURE'] = getFilePath($item['DETAIL_PICTURE']);
	$arResult[] = $item;
}

echo json_encode($arResult);