forked from tombruijn/newsoffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews_show.php
469 lines (454 loc) · 14.4 KB
/
news_show.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?php
error_reporting(0);
@session_start();//Manual load of session.
//Define correct directories
if(defined("newsoffice_directory")==false)
{
define("newsoffice_directory", str_replace("news_show.php", '', __FILE__).'/');
}
if(defined("newsoffice_dir_core")==false)
{
define("newsoffice_dir_core", 'core/');
}
//Load configuration and libaries
if(defined("newsoffice_mode")==false)
{
define("newsoffice_mode", 'news_page');
}
include(newsoffice_directory.newsoffice_dir_core.'clean_boot.php'); //Send request for basic information without loading the requested page all over again.
//Filter theme url
$theme_selected = no_clear_url($theme_selected);
//Default theme
if(empty($theme_selected))
{
$themes = glob(newsoffice_directory.$no_config['dir_themes'].'*.nzr');
$theme_selected = str_replace('.nzr','',str_replace(newsoffice_directory.$no_config['dir_themes'],'',$themes[0]));
}
//Get theme information
$openTheme = new newanz_nzr(newsoffice_directory.$no_config['dir_themes'].$theme_selected.'.nzr','READ_ONLY');
$openTheme->readfile();
$openTheme->rekey(array('object'));
$no_theme = $openTheme->content;
$openTheme->close();
if(function_exists("newsoffice_news_show_run")==false)
{
function newsoffice_news_show_run($theme_selected,$selected_category='')
{
global $no_config;
global $no_theme;
global $users;
$mode = 'normal';
if(defined('nMode')==true)
{
$mode = nMode;
if($mode=='latest_news')
{
$openCatLinks = new newanz_nzr(newsoffice_directory.$no_config['dir_info'].'categories-link.nzr');
$openCatLinks->readfile();
$openInfo = new newanz_nzr(newsoffice_directory.$no_config['dir_info'].'published.nzr');
$openInfo->readfile();
//Only load published news posts
foreach($openInfo->content as $object)
{
if($object['published']=='yes' || ($object['published']=='time' && (($object['date']<date('Y-m-d')) || ($object['date']==date('Y-m-d') && $object['time']<date('H:i')))))
{
$newsObjects[$object['news_id']] = $object;
}
}
//Filter news posts on category
if(!empty($category))
{
$removeNews = array();
$openCatLinks->search(array('category_id'=>$category));
foreach($openCatLinks->content as $cObject)
{
//Remove non-matched ID from the newsObjects Array.
$newsObjectsCategories[$cObject['news_id']] = $newsObjects[$cObject['news_id']];
}
$newsObjects = $newsObjectsCategories;
}
$openInfo->content = $newsObjects;
$openInfo->sort(array('date','time'),'date_desc','0,'.nHeadlineItems);
if($openInfo->amount_rows>0)
{
echo "<div class='newsOfficeHeadlinesBox'>";
foreach($openInfo->content as $object)
{
$openNews = new newanz_nzr(newsoffice_directory.$no_config['dir_news'].$object['news_id'].'.nzr');
$openNews->readfile();
$openNews->search(array('version'=>'published'),false,1);
$news = $openNews->content[0];
echo "<div class='newsOfficeHeadlines' id='newsOfficeHeadline".$news['id']."'><a href='".newanz_nzr::decode(nNewsPageUrl)."?n-id=".$news['id']."'>".$news['name']."</a></div>";
$openNews->close();
}
echo "</div>";
}
$openInfo->close();
$openCatLinks->close();
}
}
if($mode=='normal')
{
$page = no_clear_url($_GET['n-page']); if(empty($page) || $page=='home'){ $page = 1; } //Default value
$id = no_clear_url($_GET['n-id']);
$user = no_clear_url($_GET['n-user']);
if(!empty($_GET['n-cat']))
{
$category = no_clear_url($_GET['n-cat']);
}
elseif(!empty($selected_category))
{//Only use the "normal" selected category when there is no user override
$category = $selected_category;
}
//Login
if(array_key_exists('no_login',$_POST)==true)
{
$nContent = new no_convert_content('message');
$nContent->set_theme($no_theme);
if(noUser::login(array('username'=>$_POST['no_username'],'password'=>$_POST['no_password']))==true)
{
//Login succes
$nContent->set_info($no_theme['theme_message-7']['value']);
}
else
{
//Login failed
$nContent->set_info($no_theme['theme_message-8']['value']);
}
$nContent->convert();
echo $nContent->get_content();
}
//Logout
if(array_key_exists('no_logout',$_POST)==true && noUser::isLoggedIn()==true)
{
//Show message
$nContent = new no_convert_content('message');
$nContent->set_theme($no_theme);
$nContent->set_info($no_theme['theme_message-9']['value']);
$nContent->convert();
echo $nContent->get_content();
//Logout
noUser::logout();
}
//Get permissions
if(noUser::isLoggedIn()==true)
{
$user_permissions = no_load_permissions();
}
//Save comment
if(array_key_exists('no_save_comment',$_POST)==true)
{
if($no_config['set_comments_limit']!=='none' && empty($_SESSION[install_id]['comments']['last']))
{
$_SESSION[install_id]['comments']['last'] = time()-310;
}
if($no_config['set_comments_limit']!=='none' && $_SESSION[install_id]['comments']['last']>=(time()-($no_config['set_comments_limit']*60)))
{
define('no_save_error',$no_theme['theme_error-6']['value']);
}
elseif(empty($_POST['no_content']))
{
define('no_save_error',$no_theme['theme_error-5']['value']);
}
else
{
$saveComment = new noComment();
$saveComment->save(array(
'news_id'=>$id,
'user_id'=>user,
'content'=>$_POST['no_content']
));
if($saveComment->result==true)
{//Succes
//Show message
$nContent = new no_convert_content('message');
$nContent->set_theme($no_theme);
$nContent->set_info($no_theme['theme_message-6']['value']);
$nContent->convert();
echo $nContent->get_content();
$_SESSION[install_id]['comments']['last'] = time();
unset($_POST['no_content']); //This to hide it from the content box
}
else
{//Failure
define('no_save_error',$no_theme['theme_error-comment-failure']['value']);
}
$saveComment->close();
}
}
//XHTML FIX
if($no_config['set_html']=='xhtml'){ $html_fix = ' /'; }
/*****************************************************************
Actual show of content
*****************************************************************/
//Show author profile
if(!empty($user))
{
echo "<div class='newsofficeUserPage'>";
//Get own profile
if(empty($user))
{
$user = user;
}
if(!empty($users[$user]['avatar']))
{
$users[$user]['avatar'] = "<img src='".$users[$user]['avatar']."' class='no_avatar'".$html_fix.">";
}
$nContent = new no_convert_content('user_page');
$nContent->set_theme($no_theme);
$nContent->set_info($users[$user]);
$nContent->convert();
echo $nContent->get_content();
echo "</div>";
}
//Show only one news post
elseif(!empty($id))
{
echo "<div class='newsofficeNewsPost'>";
$openInfo =new newanz_nzr(newsoffice_directory.$no_config['dir_info'].'published.nzr');
$openInfo->readfile();
//Only load published news posts
foreach($openInfo->content as $object)
{
if($object['news_id']==$id && ($object['published']=='yes' || ($object['published']=='time' && (($object['date']<date('Y-m-d')) || ($object['date']==date('Y-m-d') && $object['time']<date('H:i'))))))
{
$newsObjects[$object['news_id']] = $object;
}
}
if(count($newsObjects)<=0)
{
$nContent = new no_convert_content('message');
$nContent->set_theme($no_theme);
$nContent->set_info($no_theme['theme_error-1']['value']);
$nContent->convert();
echo $nContent->get_content();
}
else
{
$nContent = new no_convert_content('full');
$openNews = new newanz_nzr(newsoffice_directory.$no_config['dir_news'].$id.'.nzr');
$openNews->readfile();
$openNews->search(array('version'=>'published'));
$object = $openNews->content[0];
$info = array_merge($openNews->content[0],$newsObjects[$id]);
$nContent->set_info($info);
//Javascript save
$jschange = $info['name'];
$nContent->set_theme($no_theme);
$openCatLinks = new newanz_nzr(newsoffice_directory.$no_config['dir_info'].'categories-link.nzr');
$openCatLinks->readfile();
$openCatLinks->search(array('news_id'=>$info['id']));
$nContent->set_categories($_SESSION[install_id]['writer']['content']['category']);
$nContent->convert();
echo $nContent->find_page($nContent->get_content()); //Replace page key with new key
$openNews->close();
//Load comments
if($no_config['set_comments_active']=='true')
{
$openComments = new newanz_nzr(newsoffice_directory.$no_config['dir_info'].'comments.nzr');
$openComments->readfile();
$openComments->search(array('news_id'=>$id));
if($openComments->amount_rows<=0)
{
$nContent = new no_convert_content('message');
$nContent->set_theme($no_theme);
$nContent->set_info($no_theme['theme_error-3']['value']);
$nContent->convert();
echo $nContent->get_content();
}
else
{
//Order?
if($no_config['set_comments_order']=='latest')
{
$show_order = 'date_desc';
}
else
{
$show_order = 'date_asc';
}
$openComments->sort(array('date','time'));
foreach($openComments->content as $comment)
{
$openComment = new newanz_nzr(newsoffice_directory.$no_config['dir_comments'].$comment['comment_id'].'.nzr');
$openComment->readfile();
$nContent = new no_convert_content('comments');
$nContent->set_theme($no_theme);
$info = array_merge($openComment->content[0],$comment);
$nContent->set_info($info);
$nContent->convert();
echo $nContent->get_content();
$openComment->close();
}
}
$openComments->close();
if(noUser::isLoggedIn()==true)
{
if(no_is_allowed('comments')==false)
{//Show not allowed message
$nContent = new no_convert_content('message');
$nContent->set_theme($no_theme);
$nContent->set_info($no_theme['theme_error-7']['value']);
$nContent->convert();
echo $nContent->get_content();
}
else
{//Show comment form
$nContent = new no_convert_content('comments_form');
$nContent->set_theme($no_theme);
$nContent->convert();
echo $nContent->get_content();
}
}
else
{//Show login form
$nContent = new no_convert_content('login_form');
$nContent->set_theme($no_theme);
$nContent->convert();
echo $nContent->get_content();
}
}
$openInfo->close();
}
echo "</div>";
}
//Show news pages
else
{
echo "<div class='newsofficeNewsPage'>";
$openCatLinks = new newanz_nzr(newsoffice_directory.$no_config['dir_info'].'categories-link.nzr');
$openCatLinks->readfile();
$openInfo = new newanz_nzr(newsoffice_directory.$no_config['dir_info'].'published.nzr');
$openInfo->readfile();
//Only load published news posts
$newsObjects = array();
foreach($openInfo->content as $object)
{
if($object['published']=='yes' || ($object['published']=='time' && (($object['date']<date('Y-m-d')) || ($object['date']==date('Y-m-d') && $object['time']<date('H:i')))))
{
$newsObjects[$object['news_id']] = $object;
}
}
//Filter news posts on category
if(!empty($category))
{
$removeNews = array();
$openCatLinks->search(array('category_id'=>$category));
$newsObjectsCategories = array();
foreach($openCatLinks->content as $cObject)
{
//Remove non-matched ID from the newsObjects Array.
$newsObjectsCategories[$cObject['news_id']] = $newsObjects[$cObject['news_id']];
}
$newsObjects = $newsObjectsCategories;
}
$newsAmount = count($newsObjects);
$items['total'] = $newsAmount;
//Limit?
if($no_config['set_amount_posts']=='all')
{
$show_limit = '';
}
else
{
$show_limit = (($page-1)*$no_config['set_amount_posts']).','.$no_config['set_amount_posts'];
}
//Order?
if($no_config['set_news_order']=='latest')
{
$show_order = 'date_desc';
}
else
{
$show_order = 'date_asc';
}
$openInfo->content = $newsObjects;
$openInfo->sort(array('date','time'),$show_order,$show_limit);
$items['shown'] = $openInfo->amount_rows;
if($openInfo->amount_rows<=0)
{
$nContent = new no_convert_content('message');
$nContent->set_info($no_theme['theme_error-1']['value']);
$nContent->set_theme($no_theme);
$nContent->convert();
echo $nContent->get_content();
}
else
{
foreach($openInfo->content as $object)
{
$openNews = new newanz_nzr(newsoffice_directory.$no_config['dir_news'].$object['news_id'].'.nzr');
$openNews->readfile();
$openNews->search(array('version'=>'published'),false,1);
$info = array_merge($openNews->content[0],$object);
//Start Content displayer
if($openInfo->amount_rows>0)
{
$nContent = new no_convert_content('small');
$nContent->set_info($info);
}
else
{
$nContent = new no_convert_content('message');
$nContent->set_info($no_theme['theme_error-1']['value']);
}
$nContent->set_theme($no_theme);
$nContent->set_categories();
$nContent->convert();
echo $nContent->get_content();
$openNews->close();
}
}
$openInfo->close();
$openCatLinks->close();
echo "</div>";
if(
(!empty($category) && empty($selected_category))
||
(!empty($category) && !empty($selected_category) && $category!==$selected_category)
)
{
echo "<div class='newsofficeNewsPageCategory'>";
$nPages = new no_convert_content('message');
$nPages->set_theme($no_theme);
$nPages->set_info("<a href='".no_link_build('n-page','home',true)."'>".$no_theme['theme_message-1']['value']."</a>");
$nPages->convert();
echo $nPages->get_content();
if($page!==1)
{
$jschange = $no_theme['theme_message-4']['value'].' '.$page;
}
echo "</div>";
}
if($items['total']>$no_config['set_amount_posts'])
{
echo "<div class='newsofficeNewsPagePagination'>";
$nPages = new no_convert_content('message');
$nPages->set_theme($no_theme);
$nPages->set_info(no_show_pages($items['total'],$page));
$nPages->convert();
echo $nPages->get_content();
if($page!==1)
{
$jschange = $no_theme['theme_message-4']['value'].' '.$page;
}
echo "</div>";
}
}
if($no_config['set_change_title']=='true' && !empty($jschange))
{
echo "
<script type='text/javascript'>
if(document.title!=='')//Only add the seperator to the title when the title is not empty
{
document.title += ' | ';
}
document.title += '".$jschange."';
</script>";
}
echo "<div class='newsofficeCopyright' style='text-align: center;'>Powered by <a href='".$no_config['acp_url']."'>NewsOffice</a>.</div>";
}
}//End
}
newsoffice_news_show_run($theme_selected,$selected_category);
?>