-
Notifications
You must be signed in to change notification settings - Fork 19
/
functions.inc
executable file
·2715 lines (2322 loc) · 98.9 KB
/
functions.inc
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Static Pages Plugin 1.7 |
// +---------------------------------------------------------------------------+
// | functions.inc |
// | |
// | This file does two things: 1) it implements the necessary Geeklog Plugin |
// | API method and 2) implements all the common code needed by the Static |
// | Pages' PHP files. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2019 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Tom Willett - twillett AT users DOT sourceforge DOT net |
// | Blaine Lang - blaine AT portalparts DOT com |
// | Dirk Haun - dirk AT haun-online DOT 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. |
// | |
// +---------------------------------------------------------------------------+
/**
* Implementation of the Plugin API for the Static Pages plugin
*
* @package StaticPages
*/
if (stripos($_SERVER['PHP_SELF'], basename(__FILE__)) !== false) {
die('This file can not be used on its own.');
}
$plugin_path = $_CONF['path'] . 'plugins/staticpages/';
/**
* Language file include
*/
$langfile = $plugin_path . 'language/' . $_CONF['language'] . '.php';
if (file_exists($langfile)) {
require_once $langfile;
} else {
require_once $plugin_path . 'language/english.php';
}
Language::override(array(
'LANG_STATIC', 'PLG_staticpages_MESSAGE15', 'PLG_staticpages_MESSAGE19',
'PLG_staticpages_MESSAGE20', 'PLG_staticpages_MESSAGE21',
));
/**
* Check and see if we need to load the plugin configuration
*/
if (!isset($_SP_CONF['allow_php'])) {
$sp_config = config::get_instance();
$_SP_CONF = $sp_config->get_config('staticpages');
}
// +---------------------------------------------------------------------------+
// | Plugin API - Services |
// +---------------------------------------------------------------------------+
include_once $plugin_path . 'services.inc.php';
// +---------------------------------------------------------------------------+
// | Geeklog Plugin API Implementations |
// +---------------------------------------------------------------------------+
/**
* Returns the items for this plugin that should appear on the main menu
* NOTE: this MUST return the url/value pairs in the following format
* $<arrayname>[<label>] = <url>
*/
function plugin_getmenuitems_staticpages()
{
global $_CONF, $_TABLES, $_SP_CONF;
$order = '';
if (!empty($_SP_CONF['sort_menu_by'])) {
$order = ' ORDER BY ';
if ($_SP_CONF['sort_menu_by'] == 'date') {
$order .= 'modified DESC';
} elseif ($_SP_CONF['sort_menu_by'] == 'label') {
$order .= 'sp_label';
} elseif ($_SP_CONF['sort_menu_by'] == 'title') {
$order .= 'sp_title';
} else { // default to "sort by id"
$order .= 'sp_id';
}
}
$current_topic = TOPIC_currentTopic();
if (!empty($current_topic)) {
$topic_sql = " AND (ta.tid = '{$current_topic}' OR ta.tid = '" . TOPIC_ALL_OPTION . "')";
} else {
if (COM_onFrontpage()) {
$topic_sql = " AND (ta.tid = '" . TOPIC_HOMEONLY_OPTION . "' OR ta.tid = '" . TOPIC_ALL_OPTION . "')";
} else {
$topic_sql = " AND (ta.tid = '" . TOPIC_ALL_OPTION . "')";
}
}
// Have to recheck for homeonly and all since the staticpage could be that
$com_topic_sql = COM_getTopicSQL('', 0, 'ta');
if ($com_topic_sql != "") {
$topic_sql .= " AND (" . $com_topic_sql . "";
if (COM_onFrontpage()) {
$topic_sql .= " OR (ta.tid = '" . TOPIC_HOMEONLY_OPTION . "' OR ta.tid = '" . TOPIC_ALL_OPTION . "'))";
} else {
$topic_sql .= " OR ta.tid = '" . TOPIC_ALL_OPTION . "')";
}
}
$sql = "SELECT sp.sp_id, sp.sp_label
FROM {$_TABLES['staticpage']} sp, {$_TABLES['topic_assignments']} ta
WHERE (sp.sp_onmenu = 1) AND (sp.draft_flag = 0) AND (sp.template_flag = 0)
AND ta.type = 'staticpages' AND ta.id = sp_id $topic_sql
" . COM_getPermSql('AND', 0, 2, 'sp') . COM_getLangSql('sp_id', 'AND', 'sp') . $order;
$result = DB_query($sql);
$nrows = DB_numRows($result);
$menuitems = array();
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$menuitems[$A['sp_label']] = COM_buildURL($_CONF['site_url']
. '/staticpages/index.php?page=' . $A['sp_id']);
}
return $menuitems;
}
/**
* Plugin should display [a] comment[s]
*
* @param string $id Unique idenifier for item comment belongs to
* @param int $cid Comment id to display (possibly including sub-comments)
* @param string $title Page/comment title
* @param string $order 'ASC' or 'DSC' or blank
* @param string $format 'threaded', 'nested', or 'flat'
* @param int $page Page number of comments to display
* @param boolean $view True to view comment (by cid), false to display (by $pid)
* @return mixed results of calling the plugin_displaycomment_ function
*/
function plugin_displaycomment_staticpages($id, $cid, $title, $order, $format, $page, $view)
{
global $_TABLES, $LANG_ACCESS, $LANG_STATIC;
$retval = '';
$sql = "SELECT COUNT(*) AS count, commentcode, owner_id, group_id, perm_owner, "
. "perm_group, perm_members, perm_anon "
. "FROM {$_TABLES['staticpage']} "
. "WHERE (sp_id = '$id') AND (draft_flag = 0) AND (template_flag = 0)" . COM_getPermSQL('AND')
. ' GROUP BY sp_id';
$result = DB_query($sql);
$A = DB_fetchArray($result);
$allowed = $A['count'];
if ($allowed == 1) {
$delete_option = (SEC_hasRights('staticpages.edit') &&
(SEC_hasAccess($A['owner_id'], $A['group_id'],
$A['perm_owner'], $A['perm_group'], $A['perm_members'],
$A['perm_anon']) == 3));
$retval .= CMT_userComments($id, $title, 'staticpages', $order, $format,
$cid, $page, $view, $delete_option,
$A['commentcode']);
} else {
$retval .= COM_showMessageText($LANG_STATIC['deny_msg'], $LANG_ACCESS['accessdenied']);
}
return $retval;
}
/**
* Return the comment code to this plugin item. This is based not only the code of the actual plugin item but the access the user has to the item
*
* @param string $id Item id to which $cid belongs
* @return int Return a CommentCode: COMMENT_CODE_ENABLED (0), COMMENT_CODE_DISABLED (-1), COMMENT_CODE_CLOSED (1)
*/
function plugin_commentenabled_staticpages($id)
{
global $_CONF, $_TABLES;
// CommentCode: COMMENT_CODE_ENABLED (0), COMMENT_CODE_DISABLED (-1), COMMENT_CODE_CLOSED (1)
$commentCode = COMMENT_CODE_DISABLED;
$sql = "SELECT sp_id, commentcode, owner_id, group_id, perm_owner, perm_group, perm_members, perm_anon FROM {$_TABLES['staticpage']}";
$sql .= " WHERE (template_flag = 0) AND sp_id = '" . DB_escapeString($id) . "' " . COM_getPermSQL('AND');
if (!SEC_hasRights('staticpages.edit')) {
$sql .= ' AND (draft_flag = 0)';
}
$result = DB_query($sql);
$A = DB_fetchArray($result);
if (DB_numRows($result) == 1) {
if ($A['commentcode'] == COMMENT_CODE_ENABLED) {
$commentCode = COMMENT_CODE_ENABLED;
} elseif ($A['commentcode'] == COMMENT_CODE_CLOSED) { // Closed but still visible so give admins access
if (SEC_hasRights('staticpages.edit') &&
(SEC_hasAccess($A['owner_id'], $A['group_id'],
$A['perm_owner'], $A['perm_group'], $A['perm_members'],
$A['perm_anon']) == 3)) {
$commentCode = COMMENT_CODE_ENABLED; // If Admin then treat comment like enabled
} else {
$commentCode = COMMENT_CODE_CLOSED;
}
}
}
return $commentCode;
}
/**
* Static Page saves a comment
*
* @param string $title comment title
* @param string $comment comment text
* @param string $id Item id to which $cid belongs
* @param int $pid comment parent
* @param string $postmode 'html' or 'text'
* @return mixed false for failure, HTML string (redirect?) for success
*/
function plugin_savecomment_staticpages($title, $comment, $id, $pid, $postmode)
{
global $_CONF, $_TABLES, $LANG03;
$retval = '';
// Use plugin_commentenabled_foo permission check to determine if user has permissions to save a comment for this item
// CommentCode: COMMENT_CODE_ENABLED (0), COMMENT_CODE_DISABLED (-1), COMMENT_CODE_CLOSED (1)
if (plugin_commentenabled_staticpages($id) != COMMENT_CODE_ENABLED) {
COM_handle404($_CONF['site_url'] . '/index.php');
}
$ret = CMT_saveComment($title, $comment, $id, $pid, 'staticpages', $postmode);
if (($ret > 0) || is_string($ret)) { // failure //FIXME: some failures should not return to comment form
if (is_string($ret)) {
$retval .= $ret;
}
$retval .= CMT_commentForm($title, $comment, $id, $pid, 'staticpages',
$LANG03[14], $postmode);
if (!defined('COMMENT_ON_SAME_PAGE')) {
$retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG03[1]));
} else {
if (!COMMENT_ON_SAME_PAGE) {
$retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG03[1]));
}
}
} else { // success
$url = COM_buildURL($_CONF['site_url'] . '/staticpages/index.php?page='
. $id);
// if the comment ends up in the submission queue, say so
if (($_CONF['commentsubmission'] == 1) &&
!SEC_hasRights('comment.submit')
) {
$url .= ($_CONF['url_rewrite'] ? '?' : '&') . 'msg=15';
}
COM_redirect($url);
}
return $retval;
}
/**
* Comment Submission approved
*
* @param string $id Item id to which $cid belongs
* @param int $cid Approved Comment id
*/
function plugin_moderationcommentapprove_staticpages($id, $cid)
{
// Nothing needed to do on approval of comment to plugin item
return true;
}
/**
* staticpages: delete a comment
*
* @param int $cid Comment to be deleted
* @param string $id Item id to which $cid belongs
* @param boolean $returnOption Either return a boolean on success or not, or redirect
* @return mixed Based on $returnOption. false for failure or true for success, else a redirect for success or failure
*/
function plugin_deletecomment_staticpages($cid, $id, $returnBoolean)
{
global $_CONF, $_TABLES, $_USER;
$retval = false;
$has_editPermissions = SEC_hasRights('staticpages.edit');
$result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['staticpage']} WHERE sp_id = '{$id}'");
$A = DB_fetchArray($result);
if ($has_editPermissions && SEC_hasAccess($A['owner_id'],
$A['group_id'], $A['perm_owner'], $A['perm_group'],
$A['perm_members'], $A['perm_anon']) == 3
) {
CMT_deleteComment($cid, $id, 'staticpages');
if ($returnBoolean) {
$retval = true;
} else {
$url = COM_buildUrl($_CONF['site_url'] . '/staticpages/index.php?page='
. $id);
COM_redirect($url);
}
} else {
COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) "
. "tried to illegally delete comment $cid from staticpage $id");
if ($returnBoolean) {
$retval = false;
} else {
COM_redirect($_CONF['site_url'] . '/index.php');
}
}
return $retval;
}
/**
* Did user create any pages
*
* @param int $uid
* @return string number of pages user contributed. If nothing leave blank
*/
function plugin_usercontributed_staticpages($uid)
{
global $_TABLES, $LANG_STATIC;
$retval = '';
$count = DB_getItem($_TABLES['staticpage'], 'COUNT(owner_id)', "owner_id = {$uid}");
if ($count > 0) {
$retval = str_replace('%s', $count, $LANG_STATIC['num_pages']);
}
return $retval;
}
/**
* Helper function: Count static pages visible to the current user
*
* @return int number of pages
*/
function SP_countVisiblePages()
{
global $_TABLES;
$perms = SP_getPerms();
if (!empty($perms)) {
$perms = ' WHERE ' . $perms;
}
if (!SEC_hasRights('staticpages.edit')) {
if (empty($perms)) {
$perms .= ' WHERE';
} else {
$perms .= ' AND';
}
$perms .= ' (draft_flag = 0) AND (template_flag = 0)';
}
$result = DB_query("SELECT COUNT(*) AS cnt FROM {$_TABLES['staticpage']}" . $perms);
$A = DB_fetchArray($result);
return $A['cnt'];
}
/**
* Prepare static page for display.
*
* @param string $page static page id
* @param array $A static page data
* @param string $comment_order sorting of comments
* @param string $comment_mode comment mode (nested, flat, etc.)
* @param int $comment_page
* @param int $msg optional message number
* @param string $query optional search query string to highlight
* @return string HTML for the static page
*/
function SP_displayPage($page, $A, $comment_order = 'ASC', $comment_mode = 'nested', $comment_page = 1, $msg = 0, $query = '')
{
global $_CONF, $_TABLES, $_USER, $LANG01, $LANG11, $LANG_STATIC, $_IMAGE_TYPE, $_SP_CONF;
$retval = '';
// get content
$content = $A['sp_content'];
if (!empty($query)) {
$content = COM_highlightQuery($content, $query);
}
if ($A['sp_format'] === 'blankpage') {
// The format is "blank page", only return the content of the page - nothing else.
$retval = $content;
} else {
// The format is not "blank page", we need to do some more processing
$sp_url = COM_buildURL($_CONF['site_url'] . '/staticpages/index.php?page=' . $page);
$headerCode = '<link rel="canonical" href="' . $sp_url . '"' . XHTML . '>';
// Meta Tags
if ($_SP_CONF['meta_tags'] > 0) {
$headerCode .= PHP_EOL . PLG_getMetaTags(
'staticpages', $page,
array(
array(
'name' => 'description',
'content' => $A['meta_description'],
),
array(
'name' => 'keywords',
'content' => $A['meta_keywords'],
),
)
);
}
// Add hreflang link element if Multi Language Content is setup
// Only allow hreflang link element to be visible when on canonical url
// ie no second pages which can happen with comments or with extra trailing variables like from a search query
if (strtolower(COM_getCurrentURL()) == strtolower($sp_url)) {
$headerCode .= COM_createHREFLang('staticpages', $page);
}
// Previous and next pages
$sp_prev = stripslashes($A['sp_prev']);
if ($sp_prev !== '') {
$headerCode .= PHP_EOL . sprintf(
'<link href="%s"%s>',
COM_buildURL($_CONF['site_url'] . '/staticpages/index.php?page=' . $sp_prev),
XHTML
);
}
$sp_next = stripslashes($A['sp_next']);
if ($sp_next !== '') {
$headerCode .= PHP_EOL . sprintf(
'<link href="%s"%s>',
COM_buildURL($_CONF['site_url'] . '/staticpages/index.php?page=' . $sp_next),
XHTML
);
}
$page_title = stripslashes($A['sp_page_title']);
if (empty($page_title)) {
$page_title = stripslashes($A['sp_title']);
}
if ($A['sp_format'] === 'allblocks' || $A['sp_format'] === 'leftblocks') {
$what = 'menu';
} else {
$what = 'none';
}
if ($msg > 0) {
$retval .= COM_showMessage($msg, 'staticpages');
}
$spage = COM_newTemplate(CTL_plugin_templatePath('staticpages'));
$spage->set_file(array(
'page' => 'staticpage.thtml',
'comments' => 'spcomments.thtml',
));
$spage->set_var('sp_id', $page);
if ($A['sp_inblock'] == 1) {
$spage->set_var('block_start', COM_startBlock(stripslashes($A['sp_title']), $A['sp_help'],
COM_getBlockTemplate('_staticpages_block', 'header')));
}
if (XHTML != '') {
$spage->set_var('xmlns', ' xmlns="http://www.w3.org/1999/xhtml"');
}
$author_name = COM_getDisplayName($A['owner_id']);
$author_username = DB_getItem($_TABLES['users'], 'username',
"uid = {$A['owner_id']}");
$spage->set_var('author_id', $A['owner_id']);
$spage->set_var('author', $author_name);
$spage->set_var('author_name', $author_name);
$spage->set_var('author_username', $author_username);
if ($A['owner_id'] > 1) {
$profile_link = $_CONF['site_url']
. '/users.php?mode=profile&uid=' . $A['owner_id'];
$authorNameTag = COM_getProfileLink($A['owner_id'], $author_username, $author_name, '', '');
$spage->set_var('lang_author', $LANG_STATIC['author']);
$spage->set_var('start_author_anchortag', $authorNameTag);
$spage->set_var('end_author_anchortag', '');
$spage->set_var('author_link', $authorNameTag);
$photo = '';
if ($_CONF['allow_user_photo']) {
require_once $_CONF['path_system'] . 'lib-user.php';
$photo = DB_getItem($_TABLES['users'], 'photo',
"uid = {$A['owner_id']}");
$photo = USER_getPhoto($A['owner_id'], $photo);
if (!empty($photo)) {
$spage->set_var('author_photo', $photo);
$camera_icon = '<img src="' . $_CONF['layout_url']
. '/images/smallcamera.' . $_IMAGE_TYPE
. '" alt=""' . XHTML . '>';
$spage->set_var('camera_icon',
COM_createLink($camera_icon, $profile_link));
}
}
if (empty($photo)) {
$spage->set_var('author_photo', '');
$spage->set_var('camera_icon', '');
}
} else {
$spage->set_var('start_author_anchortag', '');
$spage->set_var('end_author_anchortag', '');
$spage->set_var('author_link', $author_name);
}
if ($_CONF['hideprintericon'] == 0) {
$icon_url = $_CONF['layout_url'] . '/images/print.' . $_IMAGE_TYPE;
$attr = array('title' => $LANG_STATIC['printable_format']);
$printicon = COM_createImage($icon_url, $LANG01[65], $attr);
$print_url = COM_buildURL($_CONF['site_url']
. '/staticpages/index.php?page=' . $page
. '&disp_mode=print');
$icon = COM_createLink($printicon, $print_url, array('rel' => 'nofollow'));
$spage->set_var('printable_url', $print_url);
$spage->set_var('print_icon', $icon);
}
if ((SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'],
$A['perm_group'], $A['perm_members'], $A['perm_anon']) == 3) &&
SEC_hasRights('staticpages.edit')
) {
$icon_url = $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE;
$attr = array('title' => $LANG_STATIC['edit']);
$editiconhtml = COM_createImage($icon_url, $LANG_STATIC['edit'], $attr);
$attr = array(
'class' => 'editlink',
'title' => $LANG_STATIC['edit'],
'rel' => 'nofollow',
);
$url = $_CONF['site_admin_url']
. '/plugins/staticpages/index.php?mode=edit&sp_id=' . $page;
$icon = ' '
. COM_createLink(
$editiconhtml, //display
$url, //target
$attr //other attributes
);
$spage->set_var('edit_icon', $icon);
}
if ($A['commentcode'] >= 0) {
$delete_option = (SEC_hasRights('staticpages.edit') &&
SEC_hasAccess($A['owner_id'], $A['group_id'],
$A['perm_owner'], $A['perm_group'], $A['perm_members'],
$A['perm_anon']) == 3 ? true : false);
require_once $_CONF['path_system'] . 'lib-comment.php';
$spage->set_var('commentbar',
CMT_userComments($page, $A['sp_title'], 'staticpages',
$comment_order, $comment_mode, 0, $comment_page, false,
$delete_option, $A['commentcode']));
}
$spage->set_var('content', $content);
$spage->set_var('lastupdate', '');
if ($_SP_CONF['show_date'] == 1 && $A['sp_onlastupdate'] == 1) {
$curtime = COM_getUserDateTimeFormat($A['modified']);
$lastupdate = $LANG_STATIC['lastupdated'] . ': ' . $curtime[0];
$spage->set_var('lang_updated', $LANG_STATIC['lastupdated']);
$spage->set_var('updated_date', $curtime[0]);
$spage->set_var('lastupdate', $lastupdate);
}
$spage->set_var('hits', '');
if ($_SP_CONF['show_hits'] == 1 && $A['sp_onhits'] == 1) {
$num_hits = COM_numberFormat($A['sp_hits']);
$hits = $LANG_STATIC['hits'] . ': ' . $num_hits;
$spage->set_var('lang_hits', $LANG_STATIC['hits']);
$spage->set_var('hits_number', $num_hits);
$spage->set_var('sp_hits', $num_hits);
$spage->set_var('hits', $hits);
}
// Call to plugins to set template variables
PLG_templateSetVars('staticpage', $spage);
if ($A['sp_inblock'] == 1) {
$spage->set_var('block_end', COM_endBlock(COM_getBlockTemplate('_staticpages_block',
'footer')));
}
$retval .= $spage->finish($spage->parse('output', 'page'));
if (!isset($_USER['noboxes'])) {
if (COM_isAnonUser()) {
$_USER['noboxes'] = 0;
} else {
$_USER['noboxes'] = DB_getItem($_TABLES['userindex'],
'noboxes', "uid = '{$_USER['uid']}'");
}
}
if (($A['sp_format'] == 'allblocks') && ($_USER['noboxes'] != 1)) {
$rightblock = true;
} elseif (($A['sp_format'] == 'leftblocks') ||
($A['sp_format'] == 'noblocks')
) {
$rightblock = false;
} else {
$rightblock = -1;
}
$breadcrumbs = '';
if (!$_SP_CONF['disable_breadcrumbs_staticpages']) {
$breadcrumbs = TOPIC_breadcrumbs('staticpages', $page);
}
$retval = COM_createHTMLDocument($retval, array('what' => $what, 'pagetitle' => $page_title, 'breadcrumbs' => $breadcrumbs, 'headercode' => $headerCode, 'rightblock' => $rightblock));
}
return $retval;
}
/**
* Prepare static page for print (i.e. display as "printable version").
*
* @param string $page static page id
* @param array $A static page data
* @return string HTML for the static page
*/
function SP_printPage($page, $A)
{
global $_CONF, $_TABLES, $LANG01, $LANG_STATIC, $LANG_DIRECTION,
$_IMAGE_TYPE;
$print = COM_newTemplate(CTL_plugin_templatePath('staticpages'));
$print->set_file(array('print' => 'printable.thtml'));
$print->set_var('site_slogan', $_CONF['site_slogan']);
$print->set_var('direction', $LANG_DIRECTION);
COM_setLangIdAndAttribute($print);
$page_title = stripslashes($A['sp_page_title']);
if (empty($page_title)) {
$page_title = $_CONF['site_name'] . ' - ' . stripslashes($A['sp_title']);
}
$print->set_var('page_title', $page_title);
$print->set_var('sp_id', $page);
$sp_url = COM_buildURL($_CONF['site_url']
. '/staticpages/index.php?page=' . $page);
$print->set_var('sp_url', $sp_url);
$print->set_var('sp_title', stripslashes($A['sp_title']));
$print->set_var('sp_content', $A['sp_content']);
$author_name = COM_getDisplayName($A['owner_id']);
$author_username = DB_getItem($_TABLES['users'], 'username',
"uid = {$A['owner_id']}");
$print->set_var('author_id', $A['owner_id']);
$print->set_var('author', $author_name);
$print->set_var('author_name', $author_name);
$print->set_var('author_username', $author_username);
if ($A['owner_id'] > 1) {
$profile_link = $_CONF['site_url']
. '/users.php?mode=profile&uid=' . $A['owner_id'];
$authorNameTag = COM_getProfileLink($A['owner_id'], $author_username, $author_name, '');
$print->set_var('start_author_anchortag', $authorNameTag);
$print->set_var('end_author_anchortag', '');
$print->set_var('author_link', $authorNameTag);
$photo = '';
if ($_CONF['allow_user_photo']) {
require_once $_CONF['path_system'] . 'lib-user.php';
$photo = DB_getItem($_TABLES['users'], 'photo',
"uid = {$A['owner_id']}");
$photo = USER_getPhoto($A['owner_id'], $photo);
if (!empty($photo)) {
$print->set_var('author_photo', $photo);
$camera_icon = '<img src="' . $_CONF['layout_url']
. '/images/smallcamera.' . $_IMAGE_TYPE
. '" alt=""' . XHTML . '>';
$print->set_var('camera_icon',
COM_createLink($camera_icon, $profile_link));
}
}
if (empty($photo)) {
$print->set_var('author_photo', '');
$print->set_var('camera_icon', '');
}
} else {
$print->set_var('start_author_anchortag', '');
$print->set_var('end_author_anchortag', '');
$print->set_var('author_link', $author_name);
}
$num_hits = COM_numberFormat($A['sp_hits']);
$hits = $LANG_STATIC['hits'] . ': ' . $num_hits;
$print->set_var('lang_hits', $LANG_STATIC['hits']);
$print->set_var('hits_number', $num_hits);
$print->set_var('sp_hits', $num_hits);
$print->set_var('hits', $hits);
$curtime = COM_getUserDateTimeFormat($A['modified']);
$lastupdate = $LANG_STATIC['lastupdated'] . ': ' . $curtime[0];
$print->set_var('lang_updated', $LANG_STATIC['lastupdated']);
$print->set_var('updated_date', $curtime[0]);
$print->set_var('lastupdate', $lastupdate);
$printable = COM_buildURL($_CONF['site_url']
. '/staticpages/index.php?page=' . $page
. '&disp_mode=print');
$print->set_var('printable_url', $printable);
if ($A['commentcode'] >= 0) {
$commentsUrl = $sp_url . '#comments';
$comments = DB_count($_TABLES['comments'],
array('sid', 'type'), array($page, 'staticpages'));
$numComments = COM_numberFormat($comments);
$print->set_var('story_comments', $numComments);
$print->set_var('comments_url', $commentsUrl);
$comments_text = $numComments . ' ' . $LANG01[3];
$print->set_var('comments_text', $comments_text);
$print->set_var('comments_text_in_brackets',
'(' . $comments_text . ')');
$print->set_var('comments_count', $numComments);
$print->set_var('lang_comments', $LANG01[3]);
if ($numComments > 1) {
$comments_with_count = sprintf($LANG01[121], $numComments);
} else {
$comments_with_count = sprintf($LANG01[143], $numComments);
}
if ($comments > 0) {
$comments_with_count = COM_createLink($comments_with_count,
$commentsUrl);
}
$print->set_var('comments_with_count', $comments_with_count);
}
$print->parse('output', 'print');
return $print->finish($print->get_var('output'));
}
/**
* Prepare static page for display
*
* @param string $page static page id
* @param string $mode type of display to return ('', 'print', 'autotag'
* @param string $comment_order sorting of comments
* @param string $comment_mode comment mode (nested, flat, etc.)
* @param int $comment_page
* @param int $msg optional message number
* @param string $query optional search query string to highlight
* @return string HTML for the static page
*/
function SP_returnStaticpage($page = '', $mode = '', $comment_order = 'ASC', $comment_mode = 'nested', $comment_page = 1, $msg = 0, $query = '')
{
global $_TABLES, $_USER;
$retval = '';
$args = array(
'sp_id' => $page,
'mode' => $mode,
);
$svc_msg = array();
if (PLG_invokeService('staticpages', 'get', $args, $output, $svc_msg) == PLG_RET_OK) {
// Grab page id from database since some comparisons are case sensitive
// and staticpage ids are not.
$result = DB_query(
"SELECT sp_id, owner_id FROM {$_TABLES['staticpage']} "
. "WHERE (sp_id = '" . DB_escapeString($page) . "')"
);
if ($result !== false) {
list ($page, $owner_id) = DB_fetchArray($result);
} else {
$owner_id = 0;
}
if ($mode === 'print') {
$retval = SP_printPage($page, $output);
} elseif ($mode === 'autotag') {
// This allows for the autotag to be used within templates and return page templates
if ($output['template_flag'] == 1) {
$retval = $output['page_data'];
} else {
$retval = $output['sp_content'];
}
} else {
$retval = SP_displayPage($page, $output, $comment_order, $comment_mode, $comment_page, $msg, $query);
}
// Increment hit counter for page, but don't count views for the author
// of the page (feature request #0001572)
if (COM_isAnonUser() || ($_USER['uid'] != $owner_id)) {
DB_query(
"UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 "
. "WHERE (sp_id = '" . DB_escapeString($page) . "') "
. " AND (draft_flag = 0) AND (template_flag = 0) "
);
}
}
return $retval;
}
/**
* Shows the statistics for the Static Pages plugin on stats.php.
* If $showsitestats is 1 then we are to only print the overall stats in the
* 'site statistics box' otherwise we show the detailed stats
*
* @param int $showsitestats Flag to let us know which stats to get
* @return string
*/
function plugin_showstats_staticpages($showsitestats)
{
global $_CONF, $_TABLES, $LANG_STATIC;
$retval = '';
$perms = SP_getPerms();
if (!empty($perms)) {
$perms = ' AND ' . $perms;
}
$result = DB_query("SELECT sp_id,sp_title,sp_page_title,sp_hits FROM {$_TABLES['staticpage']} WHERE (sp_hits > 0) AND (draft_flag = 0) AND (template_flag = 0)" . $perms . ' ORDER BY sp_hits DESC LIMIT 10');
$nrows = DB_numRows($result);
if ($nrows > 0) {
require_once $_CONF['path_system'] . 'lib-admin.php';
$header_arr = array(
array('text' => $LANG_STATIC['stats_page_title'],
'field' => 'sid',
'header_class' => 'stats-header-title'),
array('text' => $LANG_STATIC['stats_hits'],
'field' => 'sp_hits',
'header_class' => 'stats-header-count',
'field_class' => 'stats-list-count'),
);
$data_arr = array();
$text_arr = array('has_menu' => false,
'title' => $LANG_STATIC['stats_headline'],
'form_url' => $_CONF['site_url'] . '/stats.php',
);
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$A['sp_title'] = stripslashes(trim($A['sp_title']));
if (empty($A['sp_title'])) {
$A['sp_title'] = $A['sp_page_title'];
if (empty($A['sp_title'])) {
$A['sp_title'] = $A['sp_id'];
}
$A['sp_title'] = '(' . $A['sp_title'] . ')';
}
$A['sid'] = COM_createLink($A['sp_title'],
COM_buildUrl($_CONF['site_url']
. "/staticpages/index.php?page={$A['sp_id']}"));
$A['sp_hits'] = COM_NumberFormat($A['sp_hits']);
$data_arr[$i] = $A;
}
$retval .= ADMIN_simpleList("", $header_arr, $text_arr, $data_arr);
} else {
$retval .= COM_startBlock($LANG_STATIC['stats_headline']);
$retval .= $LANG_STATIC['stats_no_hits'];
$retval .= COM_endBlock();
}
return $retval;
}
/**
* New stats plugin API function for proper integration with the site stats
*
* @return array(item text, item count);
*/
function plugin_statssummary_staticpages()
{
global $LANG_STATIC;
$total_pages = SP_countVisiblePages();
return array($LANG_STATIC['pages'], COM_numberFormat($total_pages));
}
/**
* Geeklog is asking us to provide any new items that show up in the type
* drop-down on search.php. Let's let users search static pages!
*
* @return string
*/
function plugin_searchtypes_staticpages()
{
global $LANG_STATIC, $_SP_CONF;
if ($_SP_CONF['includesearch'] == 1) {
$tmp['staticpages'] = $LANG_STATIC['pages'];
return $tmp;
} else {
return '';
}
}
/**
* this searches for static pages matching the user query and returns an array of
* for the header and table rows back to search.php where it will be formated and
* printed
*
* @param string $query Keywords user is looking for
* @param date $datestart Start date to get results for
* @param date $dateend End date to get results for
* @param string $topic The topic they were searching in
* @param string $type Type of items they are searching, or 'all' (deprecated)
* @param int $author Get all results by this author
* @param string $keyType search key type: 'all', 'phrase', 'any'
* @param int $page page number of current search (deprecated)
* @param int $perpage number of results per page (deprecated)
* @return array
*/
function plugin_dopluginsearch_staticpages($query, $datestart, $dateend, $topic, $type, $author, $keyType, $page, $perpage)
{
global $_TABLES, $_DB_dbms, $LANG_STATIC, $LANG09, $_SP_CONF;
if ($_SP_CONF['includesearch'] != 1) {
return array();
}
// Make sure the query is SQL safe
$query = trim(DB_escapeString($query));
$sql = "SELECT sp.sp_id AS id, sp.sp_title AS title, sp.sp_content AS description, ";
$sql .= "UNIX_TIMESTAMP(sp.created) AS date, sp.owner_id AS uid, sp.sp_hits AS hits, ";
$sql .= "CONCAT('/staticpages/index.php?page=', sp.sp_id) AS url ";
$sql .= "FROM {$_TABLES['staticpage']} AS sp,{$_TABLES['users']} AS u, {$_TABLES['topic_assignments']} ta ";
$sql .= "WHERE (sp.owner_id = u.uid) AND (draft_flag = 0) AND (template_flag = 0) ";
$sql .= "AND ta.type = 'staticpages' AND ta.id = sp.sp_id ";
$sql .= COM_getPermSQL('AND') . COM_getLangSQL('sp_id', 'AND', 'sp') . ' ';
// Topic Permissions
$topic_perms = COM_getTopicSQL('', 0, 'ta');
if ($topic_perms != '') {
$topic_perms = " AND (" . $topic_perms . "";
$topic_perms .= " OR (ta.tid = '" . TOPIC_HOMEONLY_OPTION . "' OR ta.tid = '" . TOPIC_ALL_OPTION . "'))";
}
$sql .= $topic_perms;
if (!empty($author)) {
$sql .= "AND (owner_id = '$author') ";
}
if (!empty($topic)) {
// Retrieve list of inherited topics
if ($topic == TOPIC_ALL_OPTION) {
$sql .= "AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '" . TOPIC_ALL_OPTION . "') OR (ta.inherit = 0 AND ta.tid = '" . TOPIC_HOMEONLY_OPTION . "')) ";
} else {
$tid_list = TOPIC_getChildList($topic);
$sql .= "AND (ta.tid IN('" . TOPIC_ALL_OPTION . "',{$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND (ta.tid = '" . $topic . "' OR ta.tid = '" . TOPIC_ALL_OPTION . "')))) ";
}
}
if ($_SP_CONF['includesearchcenterblocks'] == 0) {
$sql .= 'AND sp_centerblock = 0 ';
}
if ($_SP_CONF['includesearchphp'] == 0) {
$sql .= 'AND sp_php = 0 ';
}
if ($_SP_CONF['includesearchtemplate'] == 0) {
if ($_DB_dbms === 'pgsql') {
$sql .= 'AND ((CASE coalesce (template_id, \'\') WHEN \'\' THEN 0 ELSE 1 END) <> 0) ';
} else {
$sql .= 'AND template_id = "" ';
}
}
$search_p = new SearchCriteria('staticpages', $LANG_STATIC['pages']);