/
cnt22.article.inc.php
195 lines (139 loc) · 6.22 KB
/
cnt22.article.inc.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
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
<?php
/**
* phpwcms content management system
*
* @author Oliver Georgi <oliver@phpwcms.de>
* @copyright Copyright (c) 2002-2013, Oliver Georgi
* @license http://opensource.org/licenses/GPL-2.0 GNU GPL-2
* @link http://www.phpwcms.de
*
**/
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------
// RSS feed
//$CNT_TMP .= headline($crow["acontent_title"], $crow["acontent_subtitle"], $template_default["article"]);
if( !empty($crow["acontent_form"]) && is_string($crow["acontent_form"]) ) {
$rssfeed = unserialize($crow["acontent_form"]);
} elseif( empty($rssfeed) || !is_array($rssfeed) ) {
$rssfeed = array();
}
// Feed
if( isset($rssfeed['rssurl']) && !empty($rssfeed['rssurl']) ) {
if( empty($rssfeed['template']) || !is_file(PHPWCMS_TEMPLATE.'inc_cntpart/rssfeed/'.$rssfeed['template']) ) {
$rssfeed['template'] = render_device( @file_get_contents(PHPWCMS_TEMPLATE.'inc_default/rssfeed.tmpl') );
} else {
$rssfeed['template'] = render_device( @file_get_contents(PHPWCMS_TEMPLATE.'inc_cntpart/rssfeed/'.$rssfeed['template']) );
}
if(!$rssfeed['template']) {
$rssfeed['template'] = '<!--ITEM_START//--><li><a href="{LINK}" target="_blank">{TITLE}</a></li><!--ITEM_END//-->
<!--DIVIDER_START//--><hr /><!--DIVIDER_END//-->
<!--FEEDINFO_START//--><p>{IMAGE}</p><!--FEEDINFO_END//-->
<!--RSSFEED_START//-->[TITLE]<h3>{TITLE}</h3>[/TITLE][SUBTITLE]<h4>{SUBTITLE}</h4>[/SUBTITLE]<div class="rss-feed">{FEEDINFO}<ul>{ITEMS}</ul></div><!--RSSFEED_END//-->';
}
// Get Template
$rss['template_ITEM'] = get_tmpl_section('ITEM', $rssfeed['template']);
$rss['template_DIVIDER'] = get_tmpl_section('DIVIDER', $rssfeed['template']);
$rss['template_FEEDINFO'] = get_tmpl_section('FEEDINFO', $rssfeed['template']);
$rss['template_RSSFEED'] = get_tmpl_section('RSSFEED', $rssfeed['template']);
// fallback for mb_convert_encoding()
if(!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
function mb_convert_encoding($string='', $out_charset='utf-8', $in_charset='utf-8') {
if(strtolower($in_charset) == 'utf-16be') {
$in_charset = 'utf-8';
}
if(strtolower($out_charset) == 'utf-16be') {
$out_charset = 'utf-8';
}
return makeCharsetConversion($string, $in_charset, $out_charset);
}
}
// Load SimplePie
require_once(PHPWCMS_ROOT.'/include/inc_ext/simplepie.inc.php');
$rss_obj = new SimplePie();
//$CNT_TMP .= dumpVar($rssfeed['rssurl'], 2);
// Feed URL
$rss_obj->set_feed_url( $rssfeed['rssurl'] );
// Output Encoding Charset
$rss_obj->set_output_encoding( PHPWCMS_CHARSET );
// Input Encoding Charset
if(!empty($rssfeed['content_type'])) {
$rss_obj->set_input_encoding( $rssfeed['content_type'] );
}
// Feed Cache Timeout
if(!$rssfeed["timeout"]) {
// set to default value = 3600 seconds = 1 hour
$rssfeed["timeout"] = 3600;
}
if($rssfeed["cacheoff"]) {
// check if cache enabled or not
$rssfeed["timeout"] = 0;
}
if($rssfeed["timeout"]) {
$rss_obj->enable_cache( true );
$rss_obj->set_cache_duration ( $rssfeed["timeout"] );
$rss_obj->set_cache_location ( PHPWCMS_RSS );
} else {
$rss_obj->enable_cache( false );
}
//$rss_obj->enable_cache( false );
// Remove surrounding DIV
$rss_obj->remove_div( true );
// Strip all HTML Tags
$rss_obj->strip_htmltags( true );
// Limit items
if($rssfeed["item"]) {
$rss_obj->set_item_limit( $rssfeed["item"] );
}
// Init Feed
$rss_obj->init();
/*
if($rss_obj->error()) {
$CNT_TMP .= $rss_obj->error();
}
*/
if( $rss_obj->data ) {
// check RSS image
if( $rss_obj->get_image_url() ) {
$rss['temp_feedinfo'] = '<a href="'. ( $rss_obj->get_image_link() ? $rss_obj->get_image_link() : $rss_obj->get_permalink() ) .'" target="_blank">';
$rss['temp_feedinfo'] .= '<img src="' . $rss_obj->get_image_url() . '" border="0" alt="' . $rss_obj->get_image_title() . '" />';
$rss['temp_feedinfo'] .= '</a>';
$rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'IMAGE', $rss['temp_feedinfo']);
} else {
$rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'IMAGE', '');
}
$rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'TITLE', $rss_obj->get_title());
$rss['template_FEEDINFO'] = render_cnt_template($rss['template_FEEDINFO'], 'DESCRIPTION', $rss_obj->get_description());
$c = 0;
$rss['items'] = array();
foreach($rss_obj->get_items() as $rssvalue) {
// general item info
$rss['items'][$c] = render_cnt_template($rss['template_ITEM'], 'LINK', $rssvalue->get_permalink() );
$rss['items'][$c] = render_cnt_template($rss['items'][$c], 'TITLE', $rssvalue->get_title() );
$rss['items'][$c] = render_cnt_template($rss['items'][$c], 'DESCRIPTION', $rssvalue->get_description() );
$rss['items'][$c] = render_cnt_template($rss['items'][$c], 'CONTENT', $rssvalue->get_content() );
// author
$rss['item_author'] = $rssvalue->get_author();
$rss['items'][$c] = render_cnt_template($rss['items'][$c], 'AUTHOR', $rss['item_author'] ? $rss['item_author']->get_name() : '' );
// item date
$rss['items'][$c] = render_cnt_date($rss['items'][$c], $rssvalue->get_date('U') );
$c++;
if($rssfeed["item"] && $rssfeed["item"] == $c) {
break;
}
}
// whole rss feed
$rss['template_RSSFEED'] = render_cnt_template($rss['template_RSSFEED'], 'TITLE', html_specialchars($crow['acontent_title']) );
$rss['template_RSSFEED'] = render_cnt_template($rss['template_RSSFEED'], 'SUBTITLE', html_specialchars($crow['acontent_subtitle']) );
$rss['template_RSSFEED'] = render_cnt_template($rss['template_RSSFEED'], 'ITEMS', implode( LF , $rss['items'] ) );
$rss['template_RSSFEED'] = str_replace('{FEEDINFO}', $rss['template_FEEDINFO'], $rss['template_RSSFEED']);
$rss['template_RSSFEED'] = render_cnt_template($rss['template_RSSFEED'], 'LINK', $rss_obj->get_permalink() );
$rss['template_RSSFEED'] = str_replace('{DIVIDER}', $rss['template_DIVIDER'], $rss['template_RSSFEED']);
$CNT_TMP .= $rss['template_RSSFEED'];
}
}
unset($rss, $rssfeed);
?>