-
Notifications
You must be signed in to change notification settings - Fork 1
/
rss.php
129 lines (111 loc) · 4.73 KB
/
rss.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
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
<?php
/**
* Generating an RSS feed for a tag or category, draws content from across modules
*
* @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 sprockets
* @version $Id$
*/
/** Include the module's header for all pages */
include_once 'header.php';
include_once ICMS_ROOT_PATH.'/header.php';
/*
* Encodes entities to ensure that feed content matches RSS specification
*
* @param string $field
* @return string $field
*/
function encode_entities($field) {
$field = htmlspecialchars(html_entity_decode($field, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES, 'UTF-8');
return $field;
}
global $sprocketsConfig;
$clean_tag_id = $sort_order = '';
$tags_with_rss = $content_item_array = array();
$clean_tag_id = isset($_GET['tag_id']) ? (int)$_GET['tag_id'] : FALSE;
include_once ICMS_ROOT_PATH . '/modules/' . basename(dirname(__FILE__)) . '/class/icmsfeed.php';
$unified_feed = new IcmsFeed();
$sprocketsModule = icms_getModuleInfo(basename(dirname(__FILE__)));
// get handlers
$sprockets_taglink_handler = icms_getModuleHandler('taglink', $sprocketsModule->getVar('dirname'),
'sprockets');
$sprockets_tag_handler = icms_getModuleHandler('tag', $sprocketsModule->getVar('dirname'),
'sprockets');
// generate a tag-specific RSS feed, drawing on content from all compatible modules
$tagObj = $sprockets_tag_handler->get($clean_tag_id);
// check that feeds are enabled for this tag, exit if not
if (!$tagObj->getVar('rss', 'e')) {
exit;
}
// remove html tags and problematic characters to meet RSS spec
$site_name = encode_entities($icmsConfig['sitename']);
$tag_title = encode_entities($tagObj->getVar('title'));
$tag_description = strip_tags($tagObj->getVar('description'));
$tag_description = encode_entities($tag_description);
$unified_feed->title = $site_name . ' - ' . $tag_title;
$unified_feed->url = ICMS_URL;
$unified_feed->description = $tag_description;
$unified_feed->language = _LANGCODE;
$unified_feed->charset = _CHARSET;
$unified_feed->category = $sprocketsModule->getVar('name');
// if there's a tag icon, use it as the feed image
if ($tagObj->getVar('icon', 'e')) {
$url = $tagObj->getImageDir() . $tagObj->getVar('icon', 'e');
} else {
$url = ICMS_URL . 'images/logo.gif';
}
$unified_feed->image = array('title' => $unified_feed->title, 'url' => $url,
'link' => $unified_feed->url);
$unified_feed->width = 144;
$unified_feed->atom_link = '"' . SPROCKETS_URL . 'rss.php';
if ($clean_tag_id) {
$unified_feed->atom_link .= '?tag_id=' . $tagObj->id() . '"';
} else {
$unified_feed->atom_link .= '"';
}
// get the content objects for this tag's feed
// $tag_id = FALSE, $module_id = FALSE, $item_type = FALSE, $start = FALSE, $limit = FALSE,
// $sort = 'DESC')
$content_item_array = $sprockets_taglink_handler->getTaggedItems($clean_tag_id, FALSE,
FALSE, FALSE, icms::$module->config['number_rss_items']);
// Unset the first result as it contains a count value that we do not need in this case
unset($content_item_array[0]);
// Prepare an array of content items (these are NOT objects, array of required fields only)
foreach($content_item_array as $contentItem) {
// encode content fields to ensure feed is compliant with the RSS spec
// Isengard convention: Multiple creators are pipe-delimited
if ($contentItem['creator']) {
$creator = $contentItem['creator'];
$creator = explode('|', $creator);
foreach ($creator as &$individual) {
$individual = encode_entities($individual);
}
} else {
$creator = encode_entities();
}
// Strip the filtered by HTML purifier notices before they get encoded
$contentItem['description'] = str_replace('<!-- filtered with htmlpurifier -->', '',
$contentItem['description']);
$contentItem['description'] = str_replace('<!-- input filtered -->', '',
$contentItem['description']);
$description = encode_entities($contentItem['description']);
$title = encode_entities($contentItem['title']);
$link = encode_entities($contentItem['itemUrl']);
// Unfortunately, could not allow for the possibility of media attachments (eg. MP3s, videos)
// due to the way the generic query is structured in getTaggedItems(). Could be solved by
// adding identifier, format and file_size fields to all client modules (could be hidden from
// view if they aren't used), but since its a minor issue will address it in a later version.
$unified_feed->feeds[] = array (
'title' => $title,
'link' => $link,
'description' => $description,
'author' => $creator,
// pubdate must be a RFC822-date-time EXCEPT with 4-digit year or won't validate
'pubdate' => date(DATE_RSS, $contentItem['date']),
'guid' => $link,
'category' => $tag_title);
}
$unified_feed->render();