Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions getLastNews.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?
@set_time_limit(0);
@ini_set('memory_limit', '512M');

$xml = simplexml_load_file('https://lenta.ru/rss');
if(!$xml) {
foreach(libxml_get_errors() as $error) {
echo $error->message . "\n";
}
die();
}
$counter = 0;
foreach($xml->channel->item as $item) {

if($counter >= 5) {
break;
}

echo "\n\n----" . ($counter + 1) . "----\n\n";
echo (string)$item->title . "\n";
echo (string)$item->link . "\n";
echo (string)$item->description . "\n";

$counter++;
}

echo 'done!';

?>
52 changes: 52 additions & 0 deletions local/php_interface/classes/Element.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?
namespace Developer\Test;

use Bitrix\Main\Loader;

class Element {

public function __construct() {
Loader::includeModule('iblock');
}

private $_cached = [];

/**
* Возвращает список элементов инфоблока
*
* @param array $arParams
* @return array
*/
public function getList($arParams) {
$arReturn = [];

// Реализовал временный php кеш
// если по заданию нужно было реализовать обычный кеш через файлы кеша, то
// можно было бы использовать штатный класс \CPhpCache и тегировать кеш через объект $GLOBALS['CACHE_MANAGER']
// или аналоги на d7.
$hash = md5(serialize($arParams));
if(key_exists($hash, $this->_cached)) {
return $this->_cached[$hash];
}

$rsElement = \CIBlockElement::GetList(
is_array($arParams['sort']) ? $arParams['sort'] : [],
is_array($arParams['filter']) ? $arParams['filter'] : [],
false,
false,
is_array($arParams['select']) ? $arParams['select'] : []
);
while($arElement = $rsElement->GetNext()) {
// если это инфоблок 1.0 (свойства лежат в общей таблице), то
// элементы будут дублироваться при выборке значений множ. свойства
// в задании про это ничего не сказано.
$arReturn[] = $arElement;
}

$this->_cached[$hash] = $arReturn;

return $arReturn;
}

}
?>
5 changes: 5 additions & 0 deletions local/php_interface/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?
use Bitrix\Main\Application;

require_once(Application::getDocumentRoot() . '/local/php_interface/classes/Element.php');
?>