forked from Kliqqi-CMS/Kliqqi-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstory.php
353 lines (291 loc) · 12.6 KB
/
story.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
<?php
include_once('internal/Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'group.php');
include(mnminclude.'smartyvariables.php');
include_once(mnminclude.'user.php');
$requestID = isset($_GET['id']) && is_numeric($_GET['id']) ? $_GET['id'] : 0;
if(isset($_GET['title']) && sanitize($_GET['title'], 3) != ''){$requestTitle = sanitize($_GET['title'], 3);}
// if we're using "Friendly URL's for categories"
if(isset($_GET['category']) && sanitize($_GET['category'], 3) != '')
{
// One or multiple categories in the URL
$thecat = explode(',',$_GET['category']);
if (sizeof($thecat)<=1)
$thecat[0] = $db->get_var("SELECT category_id FROM " . table_categories . " WHERE `category_safe_name` = '".$db->escape(urlencode(sanitize($_GET['category'], 3)))."';");
else
foreach ($thecat as &$cat)
$cat = $db->get_var("SELECT category_id FROM " . table_categories . " WHERE `category_safe_name` = '".$db->escape(urlencode(sanitize($cat, 3)))."';");
}
if($requestID > 0 && enable_friendly_urls == true){
// if we're using friendly urls, don't call /story.php?id=XX or /story/XX/
// this is to prevent google from thinking it's spam
// more work needs to be done on this
$link = new Link;
$link->id=$requestID;
if ($link->read() == false || (sizeof($thecat)>0 &&
(array_diff($thecat, $link->additional_cats, array($link->category)) ||
sizeof($thecat)!=sizeof($link->additional_cats)+1)))
{
header("Location: $my_pligg_base/error_404.php");
die();
}
$url = getmyurl("storyURL", $link->category_safe_names(), urlencode($link->title_url), $link->id);
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: " . $url );
die();
}
// if we're using "Friendly URL's for stories"
if(isset($requestTitle)){
$requestID = $db->get_var($sql="SELECT link_id FROM " . table_links . " WHERE `link_title_url` = '".$db->escape(sanitize($requestTitle,4))."';");
// Search in old urls if not found
if (!is_numeric($requestID))
$requestID = $db->get_var($sql="SELECT old_link_id FROM " . table_old_urls . " WHERE `old_title_url` = '".$db->escape(sanitize($requestTitle,4))."';");
}
if(is_numeric($requestID)) {
$id = $requestID;
$link = new Link;
$link->id=$requestID;
if ($link->read() == false || (sizeof($thecat)>0 &&
(array_diff($thecat, $link->additional_cats, array($link->category)) ||
sizeof($thecat)!=sizeof($link->additional_cats)+1)) ||
(($link->status=='spam' || $link->status=='discard') && !checklevel('admin') && !checklevel('moderator'))){
// check for redirects
include(mnminclude.'redirector.php');
$x = new redirector($_SERVER['REQUEST_URI']);
header("Location: $my_pligg_base/error_404.php");
die();
}
// Hide private group stories
if ($link->link_group_id)
{
$privacy = $db->get_var("SELECT group_privacy FROM " . table_groups . " WHERE group_id = {$link->link_group_id}");
if ($privacy == 'private' && !isMember($link->link_group_id))
{
die('Access denied');
}
}
if(isset($_POST['process']) && sanitize($_POST['process'], 3) != ''){
if (sanitize($_POST['process'], 3)=='newcomment') {
check_referrer();
$vars = array('user_id' => $link->author,'link_id' => $link->id);
check_actions('comment_subscription', $vars);
insert_comment();
}
}
require_once(mnminclude.'check_behind_proxy.php');
// Set globals
$globals['link_id']=$link->id;
$globals['category_id']=$link->category;
$globals['category_name']=$link->category_name();
$globals['category_url']=$link->category_safe_name();
$vars = '';
check_actions('story_top', $vars);
$main_smarty->assign('link_submitter', $link->username());
// setup breadcrumbs and page title
$main_smarty->assign('posttitle', $link->title);
$navwhere['text1'] = $globals['category_name'];
$navwhere['link1'] = getmyurl('maincategory', $globals['category_url']);
$navwhere['text2'] = $link->title;
$navwhere['link2'] = getmyurl('storycattitle', $globals['category_url'], urlencode($link->title_url));
$main_smarty->assign('navbar_where', $navwhere);
$main_smarty->assign('request_category', $globals['category_url']);
$main_smarty->assign('request_category_name', $globals['category_name']);
// for the comment form
$randkey = rand(1000000,100000000);
$main_smarty->assign('randkey', $randkey);
$main_smarty->assign('link_id', $link->id);
$main_smarty->assign('user_id', $current_user->user_id);
$main_smarty->assign('randmd5', md5($current_user->user_id.$randkey));
if(!$current_user->authenticated){
$vars = '';
check_actions('anonymous_user_id', $vars);
}
// for login to comment
$main_smarty->assign('register_url', getmyurl("register", ''));
$main_smarty->assign('login_url', getmyurl("login", $_SERVER['REQUEST_URI']));
// for show who voted
$main_smarty->assign('user_url', getmyurl('userblank', ""));
$main_smarty->assign('voter', who_voted($id, 'large', '>0'));
$main_smarty->assign('downvoter', who_voted($id, 'large', '<0'));
// misc smarty
$main_smarty->assign('Enable_Comment_Voting', Enable_Comment_Voting);
$main_smarty->assign('enable_show_last_visit', enable_show_last_visit);
$main_smarty->assign('UseAvatars', do_we_use_avatars());
$main_smarty->assign('related_title_url', getmyurl('storytitle', ""));
$main_smarty->assign('related_story', related_stories($id, $link->tags, $link->category));
// meta tags
$meta_description = preg_replace(array('/\r/', '/\n/'), '', $link->truncate_content());
$main_smarty->assign('meta_description', strip_tags($meta_description));
$main_smarty->assign('meta_keywords', $link->tags);
//sidebar
$main_smarty = do_sidebar($main_smarty);
// pagename
define('pagename', 'story');
$main_smarty->assign('pagename', pagename);
if($current_user->authenticated != TRUE){
$vars = '';
check_actions('register_showform', $vars);
}
$story_url = getmyurl("storyURL", $link->category_safe_names(), urlencode($link->title_url), $link->id);
$main_smarty->assign('story_url',$story_url);
$main_smarty->assign('the_story', $link->print_summary('full', true));
$parent_comment_id=sanitize($_GET['comment_id'], 3);
if(isset($_GET['reply']) && !empty($parent_comment_id)){
$main_smarty->assign('the_comments', get_comments(true,0,$_GET['comment_id']));
$main_smarty->assign('parrent_comment_id',$parent_comment_id);
}elseif(!empty($parent_comment_id)){
$main_smarty->assign('the_comments', get_comments(true,$parent_comment_id,0,1));
$main_smarty->assign('parrent_comment_id',$parent_comment_id);
}else{
$main_smarty->assign('the_comments', get_comments(true));
$main_smarty->assign('parrent_comment_id',0);
}
$main_smarty->assign('url', $link->url);
$main_smarty->assign('enc_url', urlencode($link->url));
$main_smarty->assign('story_comment_count', $link->comments());
$main_smarty->assign('URL_rss_page', getmyurl('storyrss', isset($requestTitle) ? $requestTitle : urlencode($link->title_url), $link->category_safe_name($link->category)));
$main_smarty->assign('tpl_center', $the_template . '/story_center');
$main_smarty->display($the_template . '/pligg.tpl');
} else {
// check for redirects
include(mnminclude.'redirector.php');
$x = new redirector($_SERVER['REQUEST_URI']);
header("Location: $my_pligg_base/error_404.php");
// $main_smarty->assign('tpl_center', 'error_404_center');
// $main_smarty->display($the_template . '/pligg.tpl');
die();
}
function get_comments ($fetch = false, $parent = 0, $comment_id=0, $show_parent=0){
Global $db, $main_smarty, $current_user, $CommentOrder, $link, $cached_comments;
//Set comment order to 1 if it's not set in the admin panel
if (isset($_GET['comment_sort'])) setcookie('CommentOrder', $CommentOrder = $_GET['comment_sort'], time()+60*60*24*180);
elseif (isset($_COOKIE['CommentOrder'])) $CommentOrder = $_COOKIE['CommentOrder'];
if (!isset($CommentOrder)) $CommentOrder = 1;
If ($CommentOrder == 1){$CommentOrderBy = "comment_votes DESC, comment_date DESC";}
If ($CommentOrder == 2){$CommentOrderBy = "comment_date DESC";}
If ($CommentOrder == 3){$CommentOrderBy = "comment_votes ASC, comment_date DESC";}
If ($CommentOrder == 4){$CommentOrderBy = "comment_date ASC";}
$output = '';
if (checklevel('admin') || checklevel('moderator'))
$status_sql = " OR comment_status='moderated'";
// get all parent comments
if($comment_id!=0){
$comments = $db->get_results("SELECT *
FROM " . table_comments . "
WHERE (comment_status='published' $status_sql) AND
comment_link_id=$link->id AND comment_id = $comment_id
ORDER BY " . $CommentOrderBy);
}elseif($show_parent==1){
$comments = $db->get_results("SELECT *
FROM " . table_comments . "
WHERE (comment_status='published' $status_sql) AND
comment_link_id=$link->id AND comment_id = $parent
ORDER BY " . $CommentOrderBy);
}else{
$comments = $db->get_results("SELECT *
FROM " . table_comments . "
WHERE (comment_status='published' $status_sql) AND
comment_link_id=$link->id AND comment_parent = $parent
ORDER BY " . $CommentOrderBy);
}
if ($comments) {
require_once(mnminclude.'comment.php');
$comment = new Comment;
foreach($comments as $dbcomment) {
$comment->id=$dbcomment->comment_id;
$cached_comments[$dbcomment->comment_id] = $dbcomment;
$comment->read();
$output .= $comment->print_summary($link, true);
$output .= "<div class='child-comment'>\n";
if($comment_id==0)
$output .= get_comments(true, $dbcomment->comment_id);
$output .= "</div>\n";
}
if($fetch == false){
echo $output;
} else {
return $output;
}
}
}
function insert_comment () {
global $link, $db, $current_user, $main_smarty, $the_template, $story_url;
$main_smarty->assign('TheComment',$_POST['comment_content']);
if($vars['error'] == true){
$error = true;
return;
}
require_once(mnminclude.'comment.php');
$comment = new Comment;
$cancontinue = false;
//anonymous comment
$cancontinue_anon = false;
$anon = $_POST['anon'];
$comment->content=sanitize($_POST['comment_content'], 4);
if (strlen($comment->content) > maxCommentLength)
{
$main_smarty->assign('url', $_SERVER['REQUEST_URI']);
$main_smarty->assign('tpl_center', $the_template . '/comment_errors');
$main_smarty->display($the_template . '/pligg.tpl');
exit;
}
if(sanitize($_POST['link_id'], 3) == $link->id && $current_user->authenticated && sanitize($_POST['user_id'], 3) == $current_user->user_id && sanitize($_POST['randkey'], 3) > 0)
{
if(sanitize($_POST['comment_content'], 4) != '')
// this is a normal new comment
$cancontinue = true;
if (is_array($_POST['reply_comment_content']))
{
// comment replies
foreach ($_POST['reply_comment_content'] as $id => $value)
if ($id > 0 && $value)
{
$comment->content = sanitize($value, 4);
$comment->parent= $id;
$cancontinue = true;
break;
}
}
}
elseif($_POST['link_id'] == $link->id && $_POST['randkey'] > 0 && $anon == 1)
{
if(strlen($_POST['comment_content']) > 0)
{
check_actions('register_check_errors', $vars);
if($vars['error'] == true)
$error = true;
elseif(!$current_user->authenticated)
{
$vars = array('link_id' => $link->id,'randkey' => $_POST['randkey'],'user_id' => $_POST['user_id'],'a_email' => $_POST['a_email'],'a_username' => $_POST['a_username'],'a_website' => $_POST['a_website'],'comment_content' => sanitize($_POST['comment_content'],4));
check_actions('anonymous_comment', $vars);
}
}
}
$parrent_comment_id=sanitize($_POST['parrent_comment_id'], 3);
if($cancontinue == true)
{
$comment->link=$link->id;
if($parrent_comment_id!=0)
$comment->parent= $parrent_comment_id;
else
$comment->parent=0;
$comment->randkey=sanitize($_POST['randkey'], 3);
$comment->author=sanitize($_POST['user_id'], 3);
$vars = array('comment'=>&$comment);
check_actions('story_insert_comment',$vars);
if($vars['comment']->status)
$comment->status = $vars['comment']->status;
$comment->store();
$vars['comment'] = $comment->id;
check_actions( 'after_comment_submit', $vars ) ;
$story_url = getmyurl("storyURL", $link->category_safe_names(), urlencode($link->title_url), $link->id);
//$story_url;
header('Location: '.$story_url."#comment-reply-".$comment->id);
die;
}
}
?>