forked from PHPFusion/PHPFusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.php
395 lines (388 loc) · 17.9 KB
/
news.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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: news.php
| Author: PHP-Fusion Development Team
| Co Author: Frederick MC Chan (Hien)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once file_exists('maincore.php') ? 'maincore.php' : __DIR__."/../../maincore.php";
if (!db_exists(DB_NEWS)) { redirect(BASEDIR."error.php?code=404"); }
require_once THEMES."templates/header.php";
require_once INCLUDES."infusions_include.php";
if (file_exists(INFUSIONS."news/locale/".LOCALESET."news.php")) {
include INFUSIONS."news/locale/".LOCALESET."news.php";
} else {
include INFUSIONS."news/locale/English/news.php";
}
$news_settings = get_settings("news");
require_once INFUSIONS."news/templates/news.php";
if (!isset($_GET['rowstart']) || !isnum($_GET['rowstart'])) {
$_GET['rowstart'] = 0;
$rows = 0;
}
// Predefined variables, do not edit these values
$news_cat_index = dbquery_tree(DB_NEWS_CATS, 'news_cat_id', 'news_cat_parent');
$info = array();
$i = 0;
add_to_title($locale['global_200'].\PHPFusion\SiteLinks::get_current_SiteLinks("", "link_name"));
add_breadcrumb(array('link' => INFUSIONS.'news/news.php', 'title' =>\PHPFusion\SiteLinks::get_current_SiteLinks("", "link_name")));
if (isset($_GET['readmore']) && isnum($_GET['readmore'])) {
$result = dbquery("SELECT tn.*, tc.*, tu.user_id, tu.user_name, tu.user_status, tu.user_avatar , tu.user_level, tu.user_joined,
SUM(tr.rating_vote) AS sum_rating,
COUNT(tr.rating_item_id) AS count_votes,
COUNT(td.comment_item_id) AS count_comment
FROM ".DB_NEWS." tn
LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id
LEFT JOIN ".DB_NEWS_CATS." tc ON tn.news_cat=tc.news_cat_id
LEFT JOIN ".DB_RATINGS." tr ON tr.rating_item_id = tn.news_id AND tr.rating_type='N'
LEFT JOIN ".DB_COMMENTS." td ON td.comment_item_id = tn.news_id AND td.comment_type='N' AND td.comment_hidden='0'
".(multilang_table("NS") ? "WHERE news_language='".LANGUAGE."' AND" : "WHERE")." ".groupaccess('news_visibility')."
AND news_id='".$_GET['readmore']."' AND news_draft='0'
LIMIT 1
");
if (dbrows($result)>0) {
include INCLUDES."comments_include.php";
include INCLUDES."ratings_include.php";
$data = dbarray($result);
if ($data['news_keywords'] !== "") {
set_meta("keywords", $data['news_keywords']);
}
if (!isset($_POST['post_comment']) && !isset($_POST['post_rating'])) {
$result2 = dbquery("UPDATE ".DB_NEWS." SET news_reads=news_reads+1 WHERE news_id='".$_GET['readmore']."'");
$data['news_reads']++;
}
$news_cat_image = "";
$news_image = "";
$news_subject = $data['news_subject'];
$news_news = preg_split("/<!?--\s*pagebreak\s*-->/i", $data['news_breaks'] == "y" ?
nl2br(parse_textarea($data['news_extended'] ? $data['news_extended'] : $data['news_news'])) :
parse_textarea($data['news_extended'] ? $data['news_extended'] : $data['news_news'])
);
$pagecount = count($news_news);
$news_info = array(
"news_id" => $data['news_id'],
"user_id" => $data['user_id'],
"user_name" => $data['user_name'],
"user_status" => $data['user_status'],
"user_joined" => $data['user_joined'],
"user_level" => $data['user_level'],
"user_avatar" => $data['user_avatar'],
"news_date" => $data['news_datestamp'],
"news_ialign" => $data['news_ialign'],
"cat_id" => $data['news_cat'],
"cat_name" => $data['news_cat_name'],
"news_image" => $data['news_image'],
"cat_image" => $data['news_cat_image'],
"news_subject" => $data['news_subject'],
"news_descr" => $data['news_news'],
'news_url' => INFUSIONS.'news/news.php?readmore='.$data['news_id'],
'news_news' => $news_news[$_GET['rowstart']],
"news_ext" => "n",
"news_keywords" => $data['news_keywords'],
"news_reads" => $data['news_reads'],
"news_comments" => $data['count_comment'],
'news_sum_rating' => $data['sum_rating'] ? $data['sum_rating'] : 0,
'news_count_votes' => $data['count_votes'],
"news_allow_comments" => $data['news_allow_comments'],
'news_allow_ratings' => $data['news_allow_ratings'],
"news_sticky" => $data['news_sticky'],
"print_link" => BASEDIR."print.php?type=N&item_id=".$data['news_id'],
);
$admin_actions = array();
if (iADMIN && checkrights("N")) {
$admin_actions = array(
"edit" => INFUSIONS."news/news_admin.php".$aidlink."&action=edit&section=nform&news_id=".$news_info['news_id'],
"delete" => INFUSIONS."news/news_admin.php".$aidlink."&action=delete&section=nform&news_id=".$news_info['news_id'],
);
}
if (fusion_get_settings("create_og_tags")) {
add_to_head("<meta property='og:title' content='".$data['news_subject']."' />");
add_to_head("<meta property='og:description' content='".strip_tags($data['news_news'])."' />");
add_to_head("<meta property='og:site_name' content='".fusion_get_settings('sitename')."' />");
add_to_head("<meta property='og:type' content='article' />");
add_to_head("<meta property='og:url' content='".$settings['siteurl']."infusions/news.php?readmore=".$_GET['readmore']."' />");
if ($data['news_image']) {
$og_image = IMAGES_N.$data['news_image'];
} else {
$og_image = IMAGES_NC.$data['news_cat_image'];
}
$og_image = str_replace(BASEDIR, $settings['siteurl'], $og_image);
add_to_head("<meta property='og:image' content='".$og_image."' />");
}
$_GET['cat_id'] = $data['news_cat_id'];
set_title($news_subject.$locale['global_200'].$locale['news_0004']);
news_cat_breadcrumbs($news_cat_index);
add_breadcrumb(array(
'link' => INFUSIONS."news/news.php?readmore=".$data['news_id'],
'title' => $data['news_subject']
));
$info['news_item'] = $news_info;
$info['news_item']['page_count'] = $pagecount;
} else {
redirect(INFUSIONS."news/news.php");
}
} else {
// Front Page
/* Init */
$result = '';
$info['news_cat_id'] = '0';
$info['news_cat_name'] = $locale['news_0007'];
$info['news_cat_image'] = '';
$info['news_cat_language'] = LANGUAGE;
$info['news_categories'] = '';
/* News Category */
$result = dbquery("SELECT news_cat_id, news_cat_name FROM ".DB_NEWS_CATS." ".(multilang_table("NS") ? "WHERE news_cat_language='".LANGUAGE."'" : '')." ORDER BY news_cat_id ASC");
if (dbrows($result) > 0) {
while ($cdata = dbarray($result)) {
$info['news_categories'][$cdata['news_cat_id']] = array(
'link' => INFUSIONS.'news.php?cat_id='.$cdata['news_cat_id'],
'name' => $cdata['news_cat_name']
);
}
unset($cdata);
}
/* Filter Construct */
$filter = array('recent', 'comment', 'rating');
$info['allowed_filters'] = array(
'recent' => $locale['news_0011'],
'comment' => $locale['news_0012'],
'rating' => $locale['news_0013']
);
foreach ($info['allowed_filters'] as $type => $filter_name) {
$filter_link = INFUSIONS."news/news.php?".(isset($_GET['cat_id']) ? "cat_id=".$_GET['cat_id']."&" : '')."type=".$type;
$info['news_filter'][$filter_link] = $filter_name;
unset($filter_link);
}
$columns = '';
if (isset($_GET['type']) && in_array($_GET['type'], $filter)) {
$current_filter = $_GET['type'];
$cat_filter = 'news_datestamp DESC';
if ($current_filter == 'recent') {
// order by datestamp.
$cat_filter = 'news_datestamp DESC';
} elseif ($current_filter == 'comment') {
// order by comment_count
$cat_filter = 'count_comment DESC';
} elseif ($current_filter == 'rating') {
// order by download_title
$cat_filter = 'sum_rating DESC';
}
} else {
$cat_filter = 'news_datestamp DESC';
}
if (isset($_GET['cat_id']) && isnum($_GET['cat_id'])) {
// Filtered by Category ID.
$result = dbquery("SELECT * FROM ".DB_NEWS_CATS." ".(multilang_table("NS") ? "WHERE news_cat_language='".LANGUAGE."' AND" : "WHERE")." news_cat_id='".intval($_GET['cat_id'])."'");
if (dbrows($result)) {
$data = dbarray($result);
// build categorial data.
$info['news_cat_id'] = $data['news_cat_id'];
$info['news_cat_name'] = $data['news_cat_name'];
$info['news_cat_image'] = $data['news_cat_image'] && file_exists(IMAGES_NC.$data['news_cat_image']) ? "<img class='img-responsive' src='".IMAGES_NC.$data['news_cat_image']."' />" : "<img class='img-responsive' src='holder.js/80x80/text:".$locale['no_image']."/grey' />";
$info['news_cat_language'] = $data['news_cat_language'];
$rows = dbcount("(news_id)", DB_NEWS, "news_cat='".$data['news_cat_id']."' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'");
if ($rows) {
// apply filter.
$result = dbquery("SELECT tn.*, tc.*,
tu.user_id, tu.user_name, tu.user_status, tu.user_avatar , tu.user_level, tu.user_joined,
SUM(tr.rating_vote) AS sum_rating,
COUNT(tr.rating_item_id) AS count_votes,
COUNT(td.comment_item_id) AS count_comment
FROM ".DB_NEWS." tn
LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id
LEFT JOIN ".DB_NEWS_CATS." tc ON tn.news_cat=tc.news_cat_id
LEFT JOIN ".DB_RATINGS." tr ON tr.rating_item_id = tn.news_id AND tr.rating_type='N'
LEFT JOIN ".DB_COMMENTS." td ON td.comment_item_id = tn.news_id AND td.comment_type='N' AND td.comment_hidden='0'
".(multilang_table("NS") ? "WHERE news_language='".LANGUAGE."' AND" : "WHERE")." ".groupaccess('news_visibility')." AND news_cat='".$data['news_cat_id']."' AND (news_start='0'||news_start<=".time().")
AND (news_end='0'||news_end>=".time().") AND news_draft='0'
GROUP BY news_id
ORDER BY news_sticky DESC, ".$cat_filter." LIMIT ".$_GET['rowstart'].",".$news_settings['news_pagination']);
$info['news_item_rows'] = $rows;
// the above query will need to be left join unlimited times to solve the piece.
news_cat_breadcrumbs($news_cat_index);
}
} elseif ($_GET['cat_id'] == 0) {
$rows = dbcount("(news_id)", DB_NEWS, "news_cat='0' AND ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'");
if ($rows) {
// apply filter.
$result = dbquery("SELECT tn.*, tc.*,
tu.user_id, tu.user_name, tu.user_status, tu.user_avatar , tu.user_level, tu.user_joined,
SUM(tr.rating_vote) AS sum_rating,
COUNT(tr.rating_item_id) AS count_votes,
COUNT(td.comment_item_id) AS count_comment
FROM ".DB_NEWS." tn
LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id
LEFT JOIN ".DB_NEWS_CATS." tc ON tn.news_cat=tc.news_cat_id
LEFT JOIN ".DB_RATINGS." tr ON tr.rating_item_id = tn.news_id AND tr.rating_type='N'
LEFT JOIN ".DB_COMMENTS." td ON td.comment_item_id = tn.news_id AND td.comment_type='N' AND td.comment_hidden='0'
".(multilang_table("NS") ? "WHERE news_language='".LANGUAGE."' AND" : "WHERE")." ".groupaccess('news_visibility')." AND news_cat='0' AND (news_start='0'||news_start<=".time().")
AND (news_end='0'||news_end>=".time().") AND news_draft='0'
GROUP BY news_id
ORDER BY news_sticky DESC, ".$cat_filter." LIMIT ".$_GET['rowstart'].",".$news_settings['news_pagination']);
$info['news_item_rows'] = $rows;
add_breadcrumb(array(
'link' => INFUSIONS."news/news.php?cat_id=".$_GET['cat_id'],
'title' => $locale['news_0006']
));
}
} else {
redirect(INFUSIONS."news/news.php");
}
} else {
// All Results
$rows = dbcount("(news_id)", DB_NEWS, groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().") AND (news_end='0'||news_end>=".time().") AND news_draft='0'");
if ($rows) {
$result = dbquery("SELECT tn.*, tc.*,
tu.user_id, tu.user_name, tu.user_status, tu.user_avatar , tu.user_level, tu.user_joined,
SUM(tr.rating_vote) AS sum_rating,
COUNT(tr.rating_item_id) AS count_votes,
COUNT(td.comment_item_id) AS count_comment
FROM ".DB_NEWS." tn
LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id
LEFT JOIN ".DB_NEWS_CATS." tc ON tn.news_cat=tc.news_cat_id
LEFT JOIN ".DB_RATINGS." tr ON tr.rating_item_id = tn.news_id AND tr.rating_type='N'
LEFT JOIN ".DB_COMMENTS." td ON td.comment_item_id = tn.news_id AND td.comment_type='N' AND td.comment_hidden='0'
".(multilang_table("NS") ? "WHERE news_language='".LANGUAGE."' AND" : "WHERE")." ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().")
AND (news_end='0'||news_end>=".time().") AND news_draft='0'
GROUP BY news_id
ORDER BY news_sticky DESC, ".$cat_filter." LIMIT ".$_GET['rowstart'].",".$news_settings['news_pagination']);
$info['news_item_rows'] = dbrows($result);
} else {
$info['news_item_rows'] = 0;
}
}
// end sql
$info['news_last_updated'] = 0;
if (!empty($info['news_item_rows'])) {
while ($data = dbarray($result)) {
$i++;
if ($i == 1) {
$info['news_last_updated'] = $data['news_datestamp'];
}
$news_cat_image = '';
$news_image = '';
$news_subject = stripslashes($data['news_subject']);
// need to check if want to link.
$imageSource = IMAGES_N."news_default.jpg";
if ($data['news_cat_image']) {
$imageSource = get_image("nc_".$data['news_cat_name']);
}
if ($news_settings['news_image_frontpage'] == 0) {
if ($data['news_image'] && file_exists(IMAGES_N.$data['news_image'])) {
$imageSource = IMAGES_N.$data['news_image'];
}
if ($data['news_image_t2'] && file_exists(IMAGES_N_T.$data['news_image_t2'])) {
$imageSource = IMAGES_N_T.$data['news_image_t2'];
}
if ($data['news_image_t1'] && file_exists(IMAGES_N_T.$data['news_image_t1'])) {
$imageSource = IMAGES_N_T.$data['news_image_t1'];
}
}
$image = "<img class='img-responsive' src='".$imageSource."' alt='".$data['news_subject']."' />\n";
if ($data['news_extended'] !== "") {
$news_image = "<a class='img-link' href='
".($news_settings['news_image_link'] == 0 ? INFUSIONS."news/news.php?cat_id=".$data['news_cat'] : INFUSIONS."news/news.php?readmore=".$data['news_id'])."
'>".$image."</a>\n";
} else {
$news_image = $image;
}
$news_cat_image = "<a href='".($news_settings['news_image_link'] == 0 ? "".INFUSIONS."news/news.php?cat_id=".$data['news_cat'] : INFUSIONS."news/news.php?readmore=".$data['news_id'])."'>";
if ($data['news_image_t2'] && $news_settings['news_image_frontpage'] == 0) {
$news_cat_image .= $image."</a>";
} elseif ($data['news_cat_image']) {
$news_cat_image .= "<img src='".get_image("nc_".$data['news_cat_name'])."' alt='".$data['news_cat_name']."' class='img-responsive news-category' /></a>";
}
$news_news = preg_replace("/<!?--\s*pagebreak\s*-->/i", "", ($data['news_breaks'] == "y" ?
nl2br(parse_textarea($data['news_news'])) : parse_textarea($data['news_news'])
));
$news_info[$i] = array(
"news_id" => $data['news_id'],
'news_subject' => $news_subject,
"news_url" => INFUSIONS.'news/news.php?readmore='.$data['news_id'],
'news_anchor' => "<a name='news_".$data['news_id']."' id='news_".$data['news_id']."'></a>",
'news_news' => $news_news,
"news_keywords" => $data['news_keywords'],
"user_id" => $data['user_id'],
"user_name" => $data['user_name'],
"user_status" => $data['user_status'],
"user_avatar" => $data['user_avatar'],
'user_level' => $data['user_level'],
"news_date" => $data['news_datestamp'],
"cat_id" => $data['news_cat'],
"cat_name" => $data['news_cat_name'],
"cat_image" => $news_cat_image,
"news_image" => $news_image,
'news_image_src' => $imageSource,
"news_ext" => $data['news_extended'] ? "y" : "n",
"news_reads" => $data['news_reads'],
"news_comments" => $data['count_comment'],
'news_sum_rating' => $data['sum_rating'] ? $data['sum_rating'] : 0,
'news_count_votes' => $data['count_votes'],
"news_allow_comments" => $data['news_allow_comments'],
"news_allow_ratings" => $data['news_allow_ratings'],
"news_sticky" => $data['news_sticky'],
"print_link" => BASEDIR."print.php?type=N&item_id=".$data['news_id'],
);
}
$info['news_items'] = $news_info;
} else {
$info['news_items'] = array();
}
}
render_main_news($info);
require_once THEMES."templates/footer.php";
/**
* News Category Breadcrumbs Generator
* @param $forum_index
*/
function news_cat_breadcrumbs($news_cat_index) {
global $locale;
/* Make an infinity traverse */
function breadcrumb_arrays($index, $id) {
$crumb = & $crumb;
if (isset($index[get_parent($index, $id)])) {
$_name = dbarray(dbquery("SELECT news_cat_id, news_cat_name, news_cat_parent FROM ".DB_NEWS_CATS." WHERE news_cat_id='".$id."'"));
$crumb = array(
'link' => INFUSIONS."news/news.php?cat_id=".$_name['news_cat_id'],
'title' => $_name['news_cat_name']
);
if (isset($index[get_parent($index, $id)])) {
if (get_parent($index, $id) == 0) {
return $crumb;
}
$crumb_1 = breadcrumb_arrays($index, get_parent($index, $id));
$crumb = array_merge_recursive($crumb, $crumb_1); // convert so can comply to Fusion Tab API.
}
}
return $crumb;
}
// then we make a infinity recursive function to loop/break it out.
$crumb = breadcrumb_arrays($news_cat_index, $_GET['cat_id']);
// then we sort in reverse.
if (count($crumb['title']) > 1) {
krsort($crumb['title']);
krsort($crumb['link']);
}
if (count($crumb['title']) > 1) {
foreach ($crumb['title'] as $i => $value) {
add_breadcrumb(array('link' => $crumb['link'][$i], 'title' => $value));
if ($i == count($crumb['title'])-1) {
add_to_title($locale['global_201'].$value);
}
}
} elseif (isset($crumb['title'])) {
add_to_title($locale['global_201'].$crumb['title']);
add_breadcrumb(array('link' => $crumb['link'], 'title' => $crumb['title']));
}
}