forked from glFusion/glfusion
/
index.php
360 lines (314 loc) · 13.1 KB
/
index.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
<?php
// +--------------------------------------------------------------------------+
// | glFusion CMS |
// +--------------------------------------------------------------------------+
// | index.php |
// | |
// | glFusion homepage. |
// +--------------------------------------------------------------------------+
// | Copyright (C) 2008-2016 by the following authors: |
// | |
// | Mark R. Evans mark AT glfusion DOT org |
// | |
// | Copyright (C) 2000-2008 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony@tonybibbs.com |
// | Mark Limburg - mlimburg@users.sourceforge.net |
// | Jason Whittenburg - jwhitten@securitygeeks.com |
// | Dirk Haun - dirk@haun-online.de |
// +--------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +--------------------------------------------------------------------------+
if (!@file_exists('siteconfig.php') ) {
header("Location:admin/install/index.php");
exit;
}
require_once 'lib-common.php';
USES_lib_story();
$newstories = false;
$displayall = false;
if (isset ($_GET['display'])) {
if (($_GET['display'] == 'new') && (empty ($topic))) {
$newstories = true;
} else if (($_GET['display'] == 'all') && (empty ($topic))) {
$displayall = true;
}
}
// Retrieve the archive topic - currently only one supported
$archivetid = DB_getItem ($_TABLES['topics'], 'tid', "archive_flag=1");
$page = 1;
if (isset ($_GET['page'])) {
$page = (int) COM_applyFilter ($_GET['page'], true);
if ($page == 0) {
$page = 1;
}
}
$display = '';
$pageBody = '';
// get template
$T = new Template($_CONF['path_layout']);
$T->set_file('page','index.thtml');
if (!$newstories && !$displayall) {
// give plugins a chance to replace this page entirely
$newcontent = PLG_showCenterblock (CENTERBLOCK_FULLPAGE, $page, $topic);
if (!empty ($newcontent)) {
echo $newcontent;
exit;
}
}
$ratedIds = array();
if ( $_CONF['rating_enabled'] != 0 ) {
$ratedIds = RATING_getRatedIds('article');
}
$pageBody .= glfusion_UpgradeCheck();
$pageBody .= glfusion_SecurityCheck();
$msg = COM_getMessage();
if ( $msg > 0 ) {
$plugin = '';
if (isset ($_GET['plugin'])) {
$plugin = COM_applyFilter ($_GET['plugin']);
}
$pageBody .= COM_showMessage ($msg, $plugin,'',0,'info');
}
// Show any Plugin formatted blocks
// Requires a plugin to have a function called plugin_centerblock_<plugin_name>
$displayBlock = PLG_showCenterblock (CENTERBLOCK_TOP, $page, $topic); // top blocks
if (!empty ($displayBlock)) {
$pageBody .= $displayBlock;
// Check if theme has added the template which allows the centerblock
// to span the top over the rightblocks
if (file_exists($_CONF['path_layout'] . 'topcenterblock-span.thtml')) {
$topspan = new Template($_CONF['path_layout']);
$topspan->set_file (array ('topspan'=>'topcenterblock-span.thtml'));
$topspan->parse ('output', 'topspan');
$pageBody .= $topspan->finish ($topspan->get_var('output'));
$GLOBALS['centerspan'] = true;
}
}
if (!COM_isAnonUser()) {
$U['maxstories'] = $_USER['maxstories'];
$U['aids'] = $_USER['aids'];
$U['tids'] = $_USER['tids'];
} else {
$U['maxstories'] = 0;
$U['aids'] = '';
$U['tids'] = '';
}
$topiclimit = 0;
$story_sort = 'date';
$story_sort_dir = 'DESC';
if ( !empty($topic) ) {
$result = DB_query("SELECT limitnews,sort_by,sort_dir FROM {$_TABLES['topics']} WHERE tid='".DB_escapeString($topic)."'");
if ( $result ) {
list($topiclimit, $story_sort, $story_sort_dir) = DB_fetchArray($result);
}
}
$maxstories = 0;
if ($U['maxstories'] >= $_CONF['minnews']) {
$maxstories = $U['maxstories'];
}
if ((!empty ($topic)) && ($maxstories == 0)) {
if ($topiclimit >= $_CONF['minnews']) {
$maxstories = $topiclimit;
}
}
if ($maxstories == 0) {
$maxstories = $_CONF['limitnews'];
}
$limit = $maxstories;
if ($limit < 1) {
$limit = 1;
}
if ( $_VARS['totalhits'] % 50 === 0 ) {
COM_rdfUpToDateCheck();
// Scan for any stories that have expired and should be archived or deleted
$asql = "SELECT sid,tid,title,expire,statuscode FROM {$_TABLES['stories']} ";
$asql .= 'WHERE (expire <= NOW()) AND (statuscode = ' . STORY_DELETE_ON_EXPIRE;
if (empty ($archivetid)) {
$asql .= ')';
} else {
$asql .= ' OR statuscode = ' . STORY_ARCHIVE_ON_EXPIRE . ") AND tid != '".DB_escapeString($archivetid)."'";
}
$expiresql = DB_query ($asql);
while (list ($sid, $expiretopic, $title, $expire, $statuscode) = DB_fetchArray ($expiresql)) {
if ($statuscode == STORY_ARCHIVE_ON_EXPIRE) {
if (!empty ($archivetid) ) {
COM_errorLOG("Archive Story: $sid, Topic: $archivetid, Title: $title, Expired: $expire");
DB_query ("UPDATE {$_TABLES['stories']} SET tid = '".DB_escapeString($archivetid)."', frontpage = '0', featured = '0' WHERE sid='".DB_escapeString($sid)."'");
CACHE_remove_instance('story_'.$sid);
CACHE_remove_instance('whatsnew');
}
} else if ($statuscode == STORY_DELETE_ON_EXPIRE) {
COM_errorLOG("Delete Story and comments: $sid, Topic: $expiretopic, Title: $title, Expired: $expire");
STORY_deleteImages ($sid);
DB_query("DELETE FROM {$_TABLES['comments']} WHERE sid='".DB_escapeString($sid)."' AND type = 'article'");
DB_query("DELETE FROM {$_TABLES['stories']} WHERE sid='".DB_escapeString($sid)."'");
CACHE_remove_instance('story_'.$sid);
CACHE_remove_instance('whatsnew');
}
}
}
$sql = " (date <= NOW()) AND (draft_flag = 0)";
if (empty ($topic)) {
$sql .= COM_getLangSQL ('tid', 'AND', 's');
}
// if a topic was provided only select those stories.
if (!empty($topic)) {
$sql .= " AND (s.tid = '".DB_escapeString($topic)."' OR s.alternate_tid = '".DB_escapeString($topic)."') ";
} elseif (!$newstories) {
$sql .= " AND frontpage = 1 ";
}
if ($topic != $archivetid) {
$sql .= " AND s.tid != '".DB_escapeString($archivetid)."' ";
}
$sql .= COM_getPermSQL ('AND', 0, 2, 's');
if (!empty($U['aids'])) {
$sql .= " AND s.uid NOT IN (" . str_replace( ' ', ",", $U['aids'] ) . ") ";
}
if (!empty($U['tids'])) {
$sql .= " AND s.tid NOT IN ('" . str_replace( ' ', "','", $U['tids'] ) . "') ";
}
$sql .= COM_getTopicSQL ('AND', 0, 's') . ' ';
if ($newstories) {
$sql .= "AND (date >= (date_sub(NOW(), INTERVAL {$_CONF['newstoriesinterval']} SECOND))) ";
}
$offset = intval(($page - 1) * $limit);
$userfields = 'u.uid, u.username, u.fullname';
if ($_CONF['allow_user_photo'] == 1) {
$userfields .= ', u.photo';
if ($_CONF['use_gravatar']) {
$userfields .= ', u.email';
}
}
if ( !empty($topic) ) {
switch ( $story_sort ) {
case 0 : // date
$orderBy = ' date ';
break;
case 1 : // title
$orderBy = ' title ';
break;
case 2 : // ID
$orderBy = ' sid ';
break;
default :
$orderBy = ' date ';
break;
}
switch ( $story_sort_dir ) {
case 'DESC' :
$orderBy = $orderBy . ' DESC ';
break;
case 'ASC' :
$orderBy = $orderBy . ' ASC ';
break;
default :
$orderBy = $orderBy . ' DESC ';
break;
}
} else {
$orderBy = ' date DESC';
}
$msql = "SELECT s.*, UNIX_TIMESTAMP(s.date) AS unixdate, "
. 'UNIX_TIMESTAMP(s.expire) as expireunix, '
. $userfields . ", t.topic, t.imageurl "
. "FROM {$_TABLES['stories']} AS s LEFT JOIN {$_TABLES['users']} AS u ON s.uid=u.uid "
. "LEFT JOIN {$_TABLES['topics']} AS t on s.tid=t.tid WHERE "
. $sql . "ORDER BY featured DESC," . $orderBy . " LIMIT $offset, $limit";
$result = DB_query ($msql);
$nrows = DB_numRows ($result);
$data = DB_query ("SELECT COUNT(*) AS count FROM {$_TABLES['stories']} AS s WHERE" . $sql);
$D = DB_fetchArray ($data);
$num_pages = ceil ($D['count'] / $limit);
$articleCounter = 0;
if ( $A = DB_fetchArray( $result ) ) {
$story = new Story();
$story->loadFromArray($A);
if ( $_CONF['showfirstasfeatured'] == 1 ) {
$story->_featured = 1;
}
// display first article
if ($story->DisplayElements('featured') == 1) {
$pageBody .= STORY_renderArticle ($story, 'y');
$pageBody .= PLG_showCenterblock (CENTERBLOCK_AFTER_FEATURED, $page, $topic);
} else {
$pageBody .= PLG_showCenterblock (CENTERBLOCK_AFTER_FEATURED, $page, $topic);
$pageBody .= STORY_renderArticle ($story, 'y');
}
$articleCounter++;
// get remaining stories
while ($A = DB_fetchArray ($result)) {
// $pageBody .= PLG_displayAdBlock('story',$articleCounter);
$story = new Story();
$story->loadFromArray($A);
$pageBody .= STORY_renderArticle ($story, 'y');
$articleCounter++;
}
// get plugin center blocks that follow articles
$pageBody .= PLG_showCenterblock (CENTERBLOCK_BOTTOM, $page, $topic); // bottom blocks
// Print Google-like paging navigation
if (!isset ($_CONF['hide_main_page_navigation']) ||
($_CONF['hide_main_page_navigation'] == 0)) {
if (empty ($topic)) {
$base_url = $_CONF['site_url'] . '/index.php';
if ($newstories) {
$base_url .= '?display=new';
}
} else {
$base_url = $_CONF['site_url'] . '/index.php?topic=' . $topic;
}
$pagination = COM_printPageNavigation ($base_url, $page, $num_pages);
$T->set_var('pagination',$pagination);
}
} else { // no stories to display
$cbDisplay = '';
$cbDisplay .= PLG_showCenterblock (CENTERBLOCK_AFTER_FEATURED, $page, $topic);
$cbDisplay .= PLG_showCenterblock (CENTERBLOCK_BOTTOM, $page, $topic); // bottom blocks
if ( (!isset ($_CONF['hide_no_news_msg']) ||
($_CONF['hide_no_news_msg'] == 0)) && $cbDisplay == '') {
// If there's still nothing to display, show any default centerblocks.
$cbDisplay .= PLG_showCenterblock(CENTERBLOCK_NONEWS, $page, $topic);
if ($cbDisplay == '') {
// If there's *still* nothing to show, show the stock message
$eMsg = $LANG05[2];
if (!empty ($topic)) {
$topicname = DB_getItem ($_TABLES['topics'], 'topic',
"tid = '".DB_escapeString($topic)."'");
$eMsg .= sprintf ($LANG05[3], $topicname);
}
$cbDisplay .= COM_showMessageText($eMsg, $LANG05[1],true,'info');
}
}
$pageBody .= $cbDisplay;
}
if (isset($_CONF['infinite_scroll']) && $_CONF['infinite_scroll'] == true ) {
$T->set_var('enable_infinite_scroll',true);
if ( isset($_CONF['comment_engine']) && $_CONF['comment_engine'] == 'facebook') {
$T->set_var('fb_comment_engine',true);
}
if ( isset($_CONF['comment_engine']) && $_CONF['comment_engine'] == 'disqus') {
$T->set_var('comment_disqus_shortname',$_CONF['comment_disqus_shortname']);
}
}
$T->set_var('page_contents',$pageBody);
$T->parse( 'output', 'page' );
$display = COM_siteHeader();
$display .= $T->finish( $T->get_var('output'));
$display .= COM_siteFooter (true); // The true value enables right hand blocks.
// Output page
echo $display;
?>