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
46 changes: 46 additions & 0 deletions IBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?
use \Bitrix\Main\Loader;
Loader::includeModule("iblock");
class IBlock
{
/**
* @param $select - массив выбираемые поля, пример - array("PREVIEW_PICTURE", "PREVIEW_TEXT", "NAME")
* @param $filter - массив фильтр, пример - array('IBLOCK_ID' => 1, '=ID' => 1)
* @param $order - массив порядок сортировки, пример - array('PUBLISH_DATE' => 'DESC', 'TITLE' => 'ASC')
* @param null $cache_bd - массив кеширование из БД, пример - array('ttl'=>3600,'cache_joins' => true,) с версии 16.5.9
* в методе getElement так же реализован управляемый кеш
* @return array|mixed - возвращаемые значения
* @throws \Bitrix\Main\ArgumentException
* @throws \Bitrix\Main\ObjectPropertyException
* @throws \Bitrix\Main\SystemException
*/
public static function getElement($select, $filter, $order, $cache_bd = null)
{
if(empty($cache_bd)){
$cache_bd = array(
'ttl' => 3600
);
}
$cacheTtl = intval(36000);
$cacheID = md5(serialize($filter));
$cachePath = '/ElementCacheTable';
$cache = \Bitrix\Main\Application::getInstance()->getManagedCache();
if ($cache->read($cacheTtl, $cacheID, $cachePath)) {
$arItems = $cache->get($cacheID);
}else{
$res = \Bitrix\Iblock\ElementTable::getList(
array(
'select' => $select,
'filter' => $filter,
'order' => $order,
"cache"=> $cache_bd
));
$arItems = array();
while ($arItem = $res->fetch()) {
$arItems[] = $arItem;
}
}
return $arItems;
}
}
?>
23 changes: 23 additions & 0 deletions getLastNews.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
$headers = array( 'Expect:','Connection: Keep-Alive','Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7' );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, 'https://lenta.ru/rss');
$rss_str = curl_exec($ch);
if(!$rss_str) {
print "Oooops. Can't get rss stream.\n";
exit;
}
$rss = simplexml_load_string($rss_str, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ($rss->channel->item as $item) {
$mas[] = "\nНазвание: \n".$item->title."\nСсылка:\n".$item->link."\nАнонс:\n".$item->description."\n \n";
}
$new_mas = array_slice($mas, -5);
foreach ($new_mas as $news){
print $news;
}
?>