Skip to content

Instantly share code, notes, and snippets.

@atsu666
Last active April 8, 2020 03:02
Show Gist options
  • Save atsu666/1372ab43226af3d48a69558380dd919f to your computer and use it in GitHub Desktop.
Save atsu666/1372ab43226af3d48a69558380dd919f to your computer and use it in GitHub Desktop.
php/ACMS/GET/Feed/ExList.php
<?php
class ACMS_GET_Feed_ExList extends ACMS_GET
{
function get()
{
$this->source = config('feed_exlist_source');
$this->limit = intval(config('feed_exlist_limit'));
$this->offset = intval(config('feed_exlist_offset'));
$this->newtime = config('feed_exlist_newtime');
$this->feed_exlist_cache_expire = config('feed_exlist_cache_expire');
$this->mo_feed_exlist_notfound = config('mo_feed_exlist_notfound');
$this->kind = config('feed_exlist_kind');
$Tpl = new Template($this->tpl, new ACMS_Corrector());
$this->buildModuleField($Tpl);
//echo 'make cache from xml.';
$RSS = new FeedParser($this->source, $this->kind);
$feeds = $RSS->get();
//----------
// notFound
if ( empty($feeds['items']) ) {
if ( $this->mo_feed_exlist_notfound == 'on' ) $Tpl->add('notFound');
return $Tpl->get();
}
//----------
// limit
$limit = count($feeds['items']) < $this->limit ? count($feeds['items']) : $this->limit;
//----------
// slice
foreach ( array_slice($feeds['items'], $this->offset, $limit) as $row ) {
if ( requestTime() <= @strtotime($row['datetime']) + $this->newtime ) {
$Tpl->add('new');
}
$row += $this->buildDate(@$row['datetime'], $Tpl, 'item:loop');
$Tpl->add('item:loop', $this->array_split($row));
}
$Tpl->add(null, $this->array_split($feeds['meta']));
return $Tpl->get();
}
function array_split($array)
{
foreach ($array as $key => $val) {
if ( is_array($val) ) {
foreach ( $val as $_key => $_val ) {
$array[$key.'_'.$_key] = $_val;
}
unset($array[$key]);
}
}
return $array;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment