-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.php
More file actions
278 lines (235 loc) · 9.26 KB
/
feed.php
File metadata and controls
278 lines (235 loc) · 9.26 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/**
* Feed page
*
* @copyright Copyright Madfish (Simon Wilkinson) 2011
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @since 1.0
* @author Madfish (Simon Wilkinson) <simon@isengard.biz>
* @package reader
* @version $Id$
*/
include_once "header.php";
$xoopsOption["template_main"] = "reader_feed.html";
include_once ICMS_ROOT_PATH . "/header.php";
// Include the Simplepie library
require_once(ICMS_ROOT_PATH . '/libraries/simplepie/autoloader.php');
$reader_feed_handler = icms_getModuleHandler("feed", basename(dirname(__FILE__)), "reader");
/** Use a naming convention that indicates the source of the content of the variable */
$clean_feed_id = isset($_GET["feed_id"]) ? (int)$_GET["feed_id"] : 0 ;
$clean_start = isset($_GET["start"]) ? (int)$_GET["start"] : 0 ;
$feedObj = $reader_feed_handler->get($clean_feed_id);
// Check if feed is marked online
if ($feedObj->getVar('online_status', 'e') == 0) {
unset($feedObj);
$feedObj = $reader_feed_handler->get(0);
}
if($feedObj && !$feedObj->isNew()) {
/////////////////////////////////////////
////////// Display single feed //////////
/////////////////////////////////////////
// Display feed navigation select box
if (icms::$module->config["display_select_box"])
{
// Create select box options
$criteria = icms_buildCriteria(array("online_status" => "1"));
$feed_select_options = array(0 => _CO_READER_SELECT_FEED) + $reader_feed_handler->getList($criteria);
// Build feed select box
$form = '<div><form name="feed_selection_form" action="feed.php" method="get">';
$form .= '<select name="feed_id" id="feed_id" onchange="this.form.submit()">';
foreach ($feed_select_options as $key => $value)
{
$form .= '<option value="' . $key . '">' . $value . '</option>';
}
$form .= '</select></form></div>';
// Assign select box to template
$icmsTpl->assign('reader_feed_select_box', $form);
}
// Configure feed
$feed = new SimplePie();
$feed->set_timeout(icms::$module->config['timeout']);
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
$feed->set_autodiscovery_cache_duration(1209600);
$feed->enable_cache(icms::$module->config['enable_cache']);
$feed->set_cache_duration(icms::$module->config['cache_duration']);
$feed->set_cache_location(ICMS_ROOT_PATH . '/cache');
// Add images to the default list of html tags to strip
$feed->strip_htmltags(array('img'));
// You can review the default list via the *property* $feed->strip_htmltags
$feed->strip_comments(TRUE);
// Set which feed to process.
$feed->set_feed_url($feedObj->getVar('identifier', 'e'));
// Force feed to cope with publishers who do stupid things to feeds
$feed->force_feed(TRUE);
// Run SimplePie.
$feed->init();
// Makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
// Handle errors here
if ($feed->error()) {
echo $feed->error();
} else {
// Populate the feed
$feedArray = $feedObj->toArray();
if (empty($feedArray['title']))
{
$feedArray['title'] = $feed->get_title();
}
if (icms::$module->config['display_feed_description'])
{
$feedArray['description'] = $feed->get_description();
}
else
{
unset($feedArray['description']);
}
if (icms::$module->config['show_feed_logos'])
{
$feedArray['image_url'] = urldecode($feed->get_image_url());
}
$feedArray['image_title'] = $feed->get_image_title();
$feedArray['permalink'] = urldecode($feed->get_permalink());
$feedArray['image_width'] = icms::$module->config['image_width'];
$feedArray['subscribe_feed'] = urldecode($feed->subscribe_url());
$feedArray['items'] = array();
$items = $feed->get_items(0, $feedObj->getVar('item_limit', 'e'));
foreach ($items as $item) {
$itemArray = array();
$itemArray['title'] = $item->get_title();
$itemArray['date'] = $item->get_date(icms::$module->config['date_format']);
$itemArray['description'] = $item->get_description();
$itemArray['authors'] = $item->get_authors();
$itemArray['link'] = urldecode($item->get_link());
$enclosure = $item->get_enclosure();
if (!empty($enclosure))
{
$itemArray['enclosure_link'] = urldecode($enclosure->get_link());
$itemArray['enclosure_type'] = $enclosure->get_real_type();
$itemArray['enclosure_size'] = $enclosure->get_size();
if (!empty($itemArray['enclosure_type']))
{
// Expand the list to add other icons later on. Most enclosures will be
// either audio or video, so not too many will be needed.
switch ($itemArray['enclosure_type'])
{
case 'audio/mpeg':
$itemArray['enclosure_image'] = READER_IMAGES_URL . 'audio.png';
break;
default:
$itemArray['enclosure_image'] = READER_IMAGES_URL . 'download.png';
}
}
}
$feedArray['items'][] = $itemArray;
unset($enclosure);
}
$icmsTpl->assign("reader_feed", $feedArray);
$icmsTpl->assign("reader_show_breadcrumb", icms::$module->config['show_breadcrumb']);
$icmsTpl->assign('reader_category_path', ' ' . $feedArray['title']);
}
} else {
/////////////////////////////////////////
////////// Display feed index ///////////
/////////////////////////////////////////
$icmsTpl->assign("reader_title", _MD_READER_ALL_FEEDS);
// Retrieve a list of feeds + count the total number of feeds
$criteria = icms_buildCriteria(array('online_status' => '1'));
$feedCount = $reader_feed_handler->getCount($criteria);
$criteria->setStart($clean_start);
$criteria->setLimit(icms::$module->config['number_of_feeds_per_page']);
$criteria->setSort('weight');
$criteria->setOrder('ASC');
$feed_array = $reader_feed_handler->getObjects($criteria, FALSE, FALSE);
// Display feed navigation select box *if* the number of feeds exceeds the pagination limit
if (icms::$module->config["display_select_box"] && $feedCount > icms::$module->config['number_of_feeds_per_page'])
{
// Create select box options
$criteria = icms_buildCriteria(array("online_status" => "1"));
$feed_select_options = array(0 => _CO_READER_SELECT_FEED) + $reader_feed_handler->getList($criteria);
// Build feed select box
$form = '<div><form name="feed_selection_form" action="feed.php" method="get">';
$form .= '<select name="feed_id" id="feed_id" onchange="this.form.submit()">';
foreach ($feed_select_options as $key => $value)
{
$form .= '<option value="' . $key . '">' . $value . '</option>';
}
$form .= '</select></form></div>';
// Assign select box to template
$icmsTpl->assign('reader_feed_select_box', $form);
}
// Configure feeds
foreach ($feed_array as & $myfeed)
{
$feed = new SimplePie();
$feed->set_timeout(icms::$module->config['timeout']);
$feed->enable_cache(icms::$module->config['enable_cache']);
$feed->set_cache_duration(icms::$module->config['cache_duration']);
$feed->set_cache_location(ICMS_ROOT_PATH . '/cache');
$feed->strip_comments(TRUE);
// Set which feed to process.
$feed->set_feed_url($myfeed['identifier']);
// Force feed to cope with publishers who do stupid things to feeds
$feed->force_feed(TRUE);
// Run SimplePie.
$feed->init();
// Makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
if ($feed->error())
{
// Remove feed from display
unset($feed);
}
else
{
// Populate feed
if (empty($myfeed['title']))
{
$myfeed['title'] = $feed->get_title();
}
if (icms::$module->config['display_feed_description'])
{
$myfeed['description'] = $feed->get_description();
}
else
{
unset($myfeed['description']);
}
$author = $feed->get_author();
if (is_object($author))
{
$myfeed['author'] = $author->get_name();
}
$item = $feed->get_item(0);
if(!empty($item))
{
$myfeed['date'] = $item->get_date(icms::$module->config['date_format']);
}
if (icms::$module->config['show_feed_logos'])
{
$myfeed['image_url'] = urldecode($feed->get_image_url());
}
$myfeed['image_title'] = $feed->get_image_title();
$myfeed['image_width'] = icms::$module->config['image_width'];
$myfeed['subscribe_feed'] = urldecode($feed->subscribe_url());
unset($feed, $author, $item);
}
}
$icmsTpl->assign('reader_feeds', $feed_array);
$icmsTpl->assign("reader_show_breadcrumb", icms::$module->config['show_breadcrumb']);
// Pagination controls
$feed_count = $reader_feed_handler->getCount($criteria);
$pagenav = new icms_view_PageNav($feed_count, icms::$module->config['number_of_feeds_per_page'],
$clean_start, 'start');
$icmsTpl->assign('reader_navbar', $pagenav->renderNav());
}
// Set feed logo position
if (icms::$module->config['logo_position'] == 0)
{
$icmsTpl->assign('reader_logo_position', 'reader_float_left');
}
else
{
$icmsTpl->assign('reader_logo_position', 'reader_float_right');
}
$icmsTpl->assign("reader_module_home", '<a href="' . ICMS_URL . "/modules/" . icms::$module->getVar("dirname") . '/">' . icms::$module->getVar("name") . "</a>");
include_once "footer.php";