forked from statamic/Plugin-SimplePie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi.simplepie.php
81 lines (61 loc) · 2.21 KB
/
pi.simplepie.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
require_once('lib/simplepie_1.3.mini.php');
class Plugin_simplepie extends Plugin
{
var $meta = array(
'name' => 'Simple Pie',
'version' => '1.0.1',
'author' => 'Statamic',
'author_url' => 'http://statamic.com'
);
public function index()
{
$urls = $this->fetchParam('url', null);
$order_by_date = $this->fetchParam('order_by_date', true, false, true);
$offset = $this->fetchParam('offset', 0);
$cache = $this->fetchParam('cache', false, false, true);
$timeout = $this->fetchParam('timeout', 10);
$count = $this->fetchParam('count', false);
$limit = $this->fetchParam('limit', 10);
$limit = $limit == 'no' ? 0 : $limit;
if ($count && $this->fetchParam('limit', false) === false) {
$limit = $count; # backwards compatibility
}
$feeds = Helper::explodeOptions($urls);
$feed = new SimplePie();
$cache_folder = '_cache/_add-ons/simplepie';
if ( ! Folder::exists($cache_folder)) {
Folder::make($cache_folder);
}
$feed->set_cache_location($cache_folder);
$feed->enable_cache($cache);
$feed->set_feed_url($feeds);
$feed->enable_order_by_date($order_by_date);
$success = $feed->init();
$feed->handle_content_type();
if ( ! $feed->error() && $success) {
$loop_count = 0;
$output = '';
foreach($feed->get_items($offset) as $item) {
$data = array();
$data['title'] = $item->get_title();
$data['permalink'] = $item->get_permalink();
$data['date'] = $item->get_date(Config::getDateFormat());
$data['updated_date'] = $item->get_updated_date(Config::getDateFormat());
$data['author'] = $item->get_author() === NULL ? '' : $item->get_author()->get_name();
$data['category'] = $item->get_category();
$data['description'] = $item->get_description();
$data['contentencoded'] = $item->get_content();
$loop_count ++;
$output .= Parse::template($this->content, $data);
if ($loop_count >= $limit) break;
}
return $output;
}
return '';
}
public function feed()
{
return $this->index();
}
}