/
RssFeedDataSource.php
45 lines (37 loc) · 1.31 KB
/
RssFeedDataSource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Concrete\Core\Gathering\DataSource;
use Loader;
use Concrete\Core\Gathering\DataSource\Configuration\Configuration as GatheringDataSourceConfiguration;
class RssFeedDataSource extends DataSource
{
public function createConfigurationObject(Gathering $ag, $post)
{
$o = new RssFeedGatheringDataSourceConfiguration();
$o->setRssFeedURL($post['rssFeedURL']);
return $o;
}
public function createGatheringItems(GatheringDataSourceConfiguration $configuration)
{
$fp = Loader::helper('feed');
$feed = $fp->load($configuration->getRssFeedURL(), false);
$feed->init();
$feed->handle_content_type();
$posts = $feed->get_items(0);
$gathering = $configuration->getGatheringObject();
$lastupdated = 0;
if ($gathering->getGatheringDateLastUpdated()) {
$lastupdated = strtotime($gathering->getGatheringDateLastUpdated());
}
$items = array();
foreach ($posts as $p) {
$posttime = strtotime($p->get_date('Y-m-d H:i:s'));
//if ($posttime > $lastupdated) {
$item = RssFeedGatheringItem::add($configuration, $p);
//}
if (is_object($item)) {
$items[] = $item;
}
}
return $items;
}
}