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
87 changes: 87 additions & 0 deletions GetListCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

class GetListCache
{
public function GetList($select,$filter,$cachetime=6000){

if(empty($filter))
return array(
'result' => 'error',
'data' => 'Заполнить фильтр',
);
$arReturn = array(
'result' => 'error',
'data' => 'Неправильный запрос',
);

$code=md5(serialize(array_merge($select,$filter)));
$cache = new CPHPCache();

// Устанавливаем время, на которое нужно кешировать
$cache_time = $cachetime;

// Уникальный ID
$cache_id = 'sectCache'.$code;

// Папка для хранения кеша
$cache_path = '/sectCache/sicache/'.$code;

// Проверяем существование кеша
if ( $cache->InitCache($cache_time, $cache_id, $cache_path) )
{
// Кеш есть, достаем данные
$arCacheData = $cache->GetVars();
$arReturn['result']="success";
// Достаем по ключу, с которым положили

$arReturn['data'] = $arCacheData['sectCache'.$sCode];

}
else
{
// Кеша нет, нужно получить данные

// Хороший тон - проверить, подключен ли модуль
if (\CModule::IncludeModule("iblock") )
{
if(empty($select))
$select= array('ID', 'NAME', 'XML_ID');


// Массив элементов
$arItems = [];

// Получаем данные
$res = \CIBlockElement::GetList(["ID"=>"DESC"], $filter, false, false, $select);
while($ob = $res->GetNextElement()){
$arFields = $ob->GetFields();

$arProps = $ob->GetProperties();
$arFields["PROPERTIES"]=$arProps;
$arItems[ $arFields['ID'] ] = $arFields;
}

// Сохраняем данные в кеше
$cache->StartDataCache($cache_time, $cache_id, $cache_path);
$cache->EndDataCache(['sectCache'.$sCode => $arItems]);
$arReturn['result']="success";
$arReturn['data'] = $arItems;

}
else
{
$arReturn['data'] = "Модуль инфоблоков не подключен";
}
}



return $arReturn;
}

public function ClearCache(){
$obCache = new CPHPCache();
$obCache->CleanDir("/sectCache/sicache");
return true;
}

}
30 changes: 30 additions & 0 deletions getLastNews.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class GetLastNews{

public function GetNews($count=5,$json=false){

if(!$json){
$cn=0;
$xml=simplexml_load_file("https://lenta.ru/rss", null, LIBXML_NOCDATA);
foreach($xml->channel->item as $item){

if($cn<$count){
$txt.= '<div><a href="'.$item->link.'">'.$item->title.'</a><div>'.$item->description.'</div></div>';
}
$cn++;
}
return $txt;
}else{
$cn=0;
$xml=simplexml_load_file("https://lenta.ru/rss", null, LIBXML_NOCDATA);
foreach($xml->channel->item as $item){

if($cn<$count){
$txt[]=array("link"=>$item->link,"title"=>$item->title,"description"=>$item->description);
}
$cn++;
}
return json_encode($txt);
}
}

}