-
Notifications
You must be signed in to change notification settings - Fork 19
/
lib-article.php
2624 lines (2291 loc) · 102 KB
/
lib-article.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
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). */
// +---------------------------------------------------------------------------+
// | Geeklog 2.2 |
// +---------------------------------------------------------------------------+
// | lib-article.php |
// | |
// | Story-related functions needed in more than one place. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2017 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Mark Limburg - mlimburg AT users DOT sourceforge DOT net |
// | Jason Whittenburg - jwhitten AT securitygeeks DOT com |
// | Dirk Haun - dirk AT haun-online DOT de |
// | Vincent Furia - vinny01 AT users DOT sourceforge DOT net |
// +---------------------------------------------------------------------------+
// | |
// | 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 (stripos($_SERVER['PHP_SELF'], basename(__FILE__)) !== false) {
die('This file can not be used on its own!');
}
if ($_CONF['allow_user_photo']) {
// only needed for the USER_getPhoto function
require_once $_CONF['path_system'] . 'lib-user.php';
}
// this must be kept in sync with the actual size of 'sid' in the db ...
define('STORY_MAX_ID_LENGTH', 128);
// Story Record Options for the STATUS Field
if (!defined('STORY_ARCHIVE_ON_EXPIRE')) {
define('STORY_ARCHIVE_ON_EXPIRE', '10');
define('STORY_DELETE_ON_EXPIRE', '11');
}
/**
* Takes an article class and renders HTML in the specified template and style.
* Formats the given article into HTML. Called by index.php, article.php,
* submit.php and admin/article.php (Preview mode for the last two).
*
* @param Article $story The story to display, an instance of the Story class.
* @param string $index n = Full display of article. p = 'Preview' mode. Else y = introtext only.
* @param string $storyTpl The template to use to render the story.
* @param string $query A search query, if one was specified.
* @return string Article as formatted HTML.
* Note: Formerly named COM_Article, and re-written totally since then.
*/
function STORY_renderArticle($story, $index = '', $storyTpl = 'articletext.thtml', $query = '', $articlecount = 1)
{
global $_CONF, $_TABLES, $_USER, $LANG01, $LANG05, $LANG11, $LANG_TRB,
$_IMAGE_TYPE, $mode;
static $storyCounter = 0;
if ($story->DisplayElements('featured') == 1) {
$article_filevar = 'featuredarticle';
} elseif ($story->DisplayElements('statuscode') == STORY_ARCHIVE_ON_EXPIRE && $story->DisplayElements('expire') <= time()) {
$article_filevar = 'archivearticle';
} else {
$article_filevar = 'article';
}
if (empty($storyTpl)) {
$storyTpl = 'articletext.thtml';
}
// Change article template file with the topic (feature request #275)
$templateDir = $_CONF['path_layout'];
$topicDir = $templateDir . 'topics/' . $story->DisplayElements('tid') . '/';
if (is_dir($topicDir) && file_exists($topicDir . $storyTpl)) {
$templateDir = $topicDir;
}
$article = COM_newTemplate(CTL_core_templatePath($templateDir));
$article->set_file(array(
'article' => $storyTpl,
'bodytext' => 'articlebodytext.thtml',
'featuredarticle' => 'featuredarticletext.thtml',
'featuredbodytext' => 'featuredarticlebodytext.thtml',
'archivearticle' => 'archivearticletext.thtml',
'archivebodytext' => 'archivearticlebodytext.thtml',
));
// begin instance caching...
$cache_time = $story->DisplayElements('cache_time');
$current_article_tid = $story->DisplayElements('tid');
$retval = false; // If stays false will rebuild article and not used cache (checks done below)
if ($cache_time > 0 || $cache_time == -1) {
$hash = CACHE_security_hash();
$cacheInstance = 'article__' . $story->getSid() . '_' . $index . $mode . '_' . $article_filevar . '_' . $current_article_tid . '_' . $hash . '_' . $_CONF['theme'];
if ($_CONF['cache_templates']) {
$retval = $article->check_instance($cacheInstance, $article_filevar);
} else {
$retval = CACHE_check_instance($cacheInstance);
}
if ($retval && $cache_time == -1) {
// Cache file found so use it since no time limit set to recreate
} elseif ($retval && $cache_time > 0) {
$lu = CACHE_get_instance_update($cacheInstance);
$now = time();
if (($now - $lu) < $cache_time) {
// Cache file found so use it since under time limit set to recreate
} else {
// generate article and create cache file
// Cache time is not built into template caching so need to delete it manually and reset $retval
if ($_CONF['cache_templates']) {
// Need to close and recreate template class since issues arise when theme templates are cached
unset($article); // Close template class
CACHE_remove_instance($cacheInstance);
$article = COM_newTemplate(CTL_core_templatePath($_CONF['path_layout']));
$article->set_file(array(
'article' => $storyTpl,
'bodytext' => 'articlebodytext.thtml',
'featuredarticle' => 'featuredarticletext.thtml',
'featuredbodytext' => 'featuredarticlebodytext.thtml',
'archivearticle' => 'archivearticletext.thtml',
'archivebodytext' => 'archivearticlebodytext.thtml',
));
} else { // theme templates are not cache so can go ahead and delete story cache
CACHE_remove_instance($cacheInstance);
}
$retval = false;
}
} else {
// Need to reset especially if caching is disabled for a certain story but template caching has been enabled for the theme
$retval = false;
}
}
$articleUrl = COM_buildURL($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
$article->set_var('article_url', $articleUrl);
$article->set_var('story_title', $story->DisplayElements('title'));
// Date formatting set by user therefore cannot be cached
$article->set_var('story_date', $story->DisplayElements('date'), false, true);
$article->set_var('story_datetime', $story->DisplayElements('datetime'), false, true);
// Story views increase with every visit so cannot be cached
if ($_CONF['hideviewscount'] != 1) {
$article->set_var('lang_views', $LANG01[106], false, true);
$article->set_var('story_hits', $story->DisplayElements('hits'), false, true);
}
// Topic Icon is user configurable so do not cache
$topicname = $story->DisplayElements('topic');
$topicurl = TOPIC_getUrl($story->DisplayElements('tid'));
if ((!isset($_USER['noicons']) || ($_USER['noicons'] != 1)) && $story->DisplayElements('show_topic_icon') == 1) {
$imageurl = $story->DisplayElements('imageurl');
if (!empty($imageurl)) {
$imageurl = COM_getTopicImageUrl($imageurl);
$article->set_var('story_topic_image_url', $imageurl, false, true);
$topicimage = '<img src="' . $imageurl . '" class="float'
. $_CONF['article_image_align'] . '" alt="'
. $topicname . '" title="' . $topicname . '"' . XHTML . '>';
$article->set_var('story_anchortag_and_image',
COM_createLink(
$topicimage,
$topicurl,
array()
)
, false, true
);
$article->set_var('story_topic_image', $topicimage, false, true);
$topicimage_noalign = '<img src="' . $imageurl . '" alt="'
. $topicname . '" title="' . $topicname . '"' . XHTML . '>';
$article->set_var('story_anchortag_and_image_no_align',
COM_createLink(
$topicimage_noalign,
$topicurl,
array()
),
false, true
);
$article->set_var('story_topic_image_no_align', $topicimage_noalign, false, true);
}
}
// Main article content
if ($index == 'p') {
$introtext = $story->getPreviewText('introtext');
$bodytext = $story->getPreviewText('bodytext');
} else {
$introtext = $story->displayElements('introtext');
$bodytext = $story->displayElements('bodytext');
}
$readmore = empty($bodytext) ? 0 : 1;
$numwords = COM_numberFormat(count(explode(' ', COM_getTextContent($bodytext))));
if (COM_onFrontpage()) {
$bodytext = '';
}
if (!empty($query)) {
$introtext = COM_highlightQuery($introtext, $query);
$bodytext = COM_highlightQuery($bodytext, $query);
}
// Create article only if preview, or query not empty, or if no cache version or cache version is not required
if ($index == 'p' || !empty($query) || !$retval) {
$article->set_var('article_filevar', '');
$article->set_var('site_name', $_CONF['site_name']);
//$article->set_var( 'story_date', $story->DisplayElements('date') );
$article->set_var('story_date_short', $story->DisplayElements('shortdate'));
$article->set_var('story_date_only', $story->DisplayElements('dateonly'));
$article->set_var('story_id', $story->getSid());
if ($_CONF['contributedbyline'] == 1) {
$article->set_var('lang_contributed_by', $LANG01[1]);
$article->set_var('contributedby_uid', $story->DisplayElements('uid'));
$fullname = $story->DisplayElements('fullname');
$username = $story->DisplayElements('username');
$article->set_var('contributedby_user', $username);
if (empty($fullname)) {
$article->set_var('contributedby_fullname', $username);
} else {
$article->set_var('contributedby_fullname', $fullname);
}
$authorname = COM_getDisplayName($story->DisplayElements('uid'),
$username, $fullname);
$article->set_var('contributedby_author', $authorname);
$article->set_var('author', $authorname);
$profileUrl = '';
if ($story->DisplayElements('uid') > 1) {
$profileUrl = $_CONF['site_url']
. '/users.php?mode=profile&uid='
. $story->DisplayElements('uid');
$article->set_var('start_contributedby_anchortag',
'<a class="storybyline" href="' . $profileUrl
. '" rel="author">');
$article->set_var('end_contributedby_anchortag', '</a>');
$article->set_var('contributedby_url', $profileUrl);
}
$photo = '';
if ($_CONF['allow_user_photo'] == 1) {
$authphoto = $story->DisplayElements('photo');
if (empty($authphoto)) {
$authphoto = '(none)'; // user does not have a photo
}
$photo = USER_getPhoto($story->DisplayElements('uid'), $authphoto,
$story->DisplayElements('email'));
}
if (!empty($photo)) {
$article->set_var('contributedby_photo', $photo);
$article->set_var('author_photo', $photo);
$camera_icon = '<img src="' . $_CONF['layout_url']
. '/images/smallcamera.' . $_IMAGE_TYPE . '" alt=""'
. XHTML . '>';
$article->set_var('camera_icon',
COM_createLink($camera_icon, $profileUrl));
} else {
$article->set_var('contributedby_photo', '');
$article->set_var('author_photo', '');
$article->set_var('camera_icon', '');
}
}
$article->set_var('story_topic_id', $story->DisplayElements('tid'));
$article->set_var('story_topic_name', $topicname);
$article->set_var('story_topic_url', $topicurl);
$recent_comment_anchortag = '';
$article->set_var('lang_permalink', $LANG01[127]);
$show_comments = true;
// n = Full display of article. p = 'Preview' mode.
if ((($index != 'n') && ($index != 'p')) || !empty($query)) {
$attributes = ' class="non-ul"';
$attr_array = array('class' => 'non-ul');
if (!empty($query)) {
$attributes .= ' rel="bookmark"';
$attr_array['rel'] = 'bookmark';
}
$article->set_var('start_storylink_anchortag',
'<a href="' . $articleUrl . '"' . $attributes . '>');
$article->set_var('end_storylink_anchortag', '</a>');
$article->set_var('story_title_link',
COM_createLink(
$story->DisplayElements('title'),
$articleUrl,
$attr_array
)
);
} else {
$article->set_var('story_title_link', $story->DisplayElements('title'));
}
$related_topics = '';
if ($index == 'n') {
if ($_CONF['supported_version_theme'] == '1.8.1') {
$article->set_var('breadcrumb_trail', TOPIC_breadcrumbs('article', $story->getSid()));
}
if ($_CONF['related_topics'] > 0) {
$related_topics = TOPIC_relatedTopics('article', $story->getSid(), $_CONF['related_topics_max']);
$article->set_var('related_topics', $related_topics);
}
} elseif ($index != 'p') {
if ($_CONF['related_topics'] > 1) {
$related_topics = TOPIC_relatedTopics('article', $story->getSid(), $_CONF['related_topics_max']);
$article->set_var('related_topics', $related_topics);
}
}
$page_selector = '';
$readmore_link = '';
$post_comment_link = '';
$plugin_itemdisplay = '';
$comments_with_count = '';
$trackbacks_with_count = '';
if (($index == 'n') || ($index == 'p')) {
if (empty($bodytext)) {
$article->set_var('story_introtext', $introtext);
$article->set_var('story_text_no_br', $introtext);
} else {
if (($_CONF['allow_page_breaks'] == 1) && ($index == 'n')) {
$story_page = 1;
// page selector
if (is_numeric($mode)) {
$story_page = $mode;
if ($story_page <= 0) {
$story_page = 1;
$mode = 0;
} elseif ($story_page > 1) {
$introtext = '';
}
}
$article_array = explode('[page_break]', $bodytext);
$page_break_count = count($article_array);
if ($story_page > $page_break_count) { // Can't have page count greater than actual number of pages
$story_page = $page_break_count;
}
$page_selector = COM_printPageNavigation(
$articleUrl, $story_page, $page_break_count,
'mode=', $_CONF['url_rewrite'], $LANG01[118]);
if (count($article_array) > 1) {
$bodytext = $article_array[$story_page - 1];
}
$article->set_var('page_selector', $page_selector);
if (
(($_CONF['page_break_comments'] == 'last') &&
($story_page < count($article_array)))
||
(($_CONF['page_break_comments'] == 'first') &&
($story_page != 1))
) {
$show_comments = false;
}
$article->set_var('story_page', $story_page);
}
$article->set_var('story_introtext', $introtext
. '<br' . XHTML . '><br' . XHTML . '>' . $bodytext);
$article->set_var('story_text_no_br', $introtext . ' ' . $bodytext);
}
$article->set_var('story_introtext_only', $introtext);
$article->set_var('story_bodytext_only', $bodytext);
if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) &&
SEC_hasRights('story.ping')
) {
$url = $_CONF['site_admin_url']
. '/trackback.php?mode=sendall&id=' . $story->getSid();
$article->set_var('send_trackback_link',
COM_createLink($LANG_TRB['send_trackback'], $url)
);
$pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.'
. $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback']
. '" title="' . $LANG_TRB['send_trackback'] . '"' . XHTML . '>';
$article->set_var('send_trackback_icon',
COM_createLink($pingico, $url)
);
$article->set_var('send_trackback_url', $url);
$article->set_var('lang_send_trackback_text',
$LANG_TRB['send_trackback']);
}
$article->set_var('story_display',
($index == 'p') ? 'preview' : 'article');
$article->set_var('story_counter', 0);
} else {
$article->set_var('story_introtext', $introtext);
$article->set_var('story_text_no_br', $introtext);
$article->set_var('story_introtext_only', $introtext);
if ($readmore) {
$article->set_var('lang_readmore', $LANG01[2]);
$article->set_var('lang_readmore_words', $LANG01[62]);
$article->set_var('readmore_words', $numwords);
$readmore_link = COM_createLink(
$LANG01[2],
$articleUrl,
array('class' => 'story-read-more-link')
) . ' (' . $numwords . ' ' . $LANG01[62] . ') ';
$article->set_var('readmore_link', $readmore_link);
$article->set_var('start_readmore_anchortag', '<a href="'
. $articleUrl . '" class="story-read-more-link">');
$article->set_var('end_readmore_anchortag', '</a>');
$article->set_var('read_more_class', 'class="story-read-more-link"');
}
if (($story->DisplayElements('commentcode') >= 0) && ($show_comments)) {
$commentsUrl = COM_buildUrl($_CONF['site_url']
. '/article.php?story=' . $story->getSid()) . '#comments';
$article->set_var('comments_url', $commentsUrl);
$article->set_var('comments_text',
COM_numberFormat($story->DisplayElements('comments')) . ' ' . $LANG01[3]);
$article->set_var('comments_count',
COM_numberFormat($story->DisplayElements('comments')));
$article->set_var('lang_comments', $LANG01[3]);
$numComments = (int) $story->DisplayElements('comments');
if ($numComments > 1) {
$comments_with_count = sprintf($LANG01[121], COM_numberFormat($numComments));
} else {
$comments_with_count = sprintf($LANG01[143], COM_numberFormat($numComments));
}
if ($_CONF['comment_on_same_page'] == true) {
$postCommentUrl = $_CONF['site_url'] . '/article.php?story='
. $story->getSid() . '#commenteditform';
} else {
$postCommentUrl = $_CONF['site_url'] . '/comment.php?sid='
. $story->getSid() . '&pid=0&type=article';
if ($_CONF['show_comments_at_replying'] == true) {
$postCommentUrl .= '#commenteditform';
}
}
if ($story->DisplayElements('comments') > 0) {
$result = DB_query("SELECT UNIX_TIMESTAMP(date) AS day,username,fullname,{$_TABLES['comments']}.uid as cuid FROM {$_TABLES['comments']},{$_TABLES['users']} WHERE {$_TABLES['users']}.uid = {$_TABLES['comments']}.uid AND sid = '" . $story->getSid() . "' ORDER BY date DESC LIMIT 1");
$C = DB_fetchArray($result);
$recent_comment_info = $LANG01[27] . ': '
. strftime($_CONF['daytime'], $C['day']) . ' '
. $LANG01[104] . ' ' . COM_getDisplayName($C['cuid'],
$C['username'], $C['fullname']);
$article->set_var('recent_comment_info', $recent_comment_info);
$attr = array('title' => htmlspecialchars($recent_comment_info));
$comments_with_count = COM_createLink($comments_with_count, $commentsUrl, $attr);
$article->set_var('comments_with_count', $comments_with_count);
$recent_comment_anchortag = COM_createLink($comments_with_count, $postCommentUrl, $attr);
// Not really used anymore but left in for old themes
$article->set_var('start_comments_anchortag', '<a href="' . $commentsUrl . '">');
$article->set_var('end_comments_anchortag', '</a>');
} else {
$article->set_var('comments_with_count', $comments_with_count);
$recent_comment_anchortag = COM_createLink($LANG01[60], $postCommentUrl);
}
if ($story->DisplayElements('commentcode') == 0) {
$post_comment_link = COM_createLink($LANG01[60], $postCommentUrl,
array('rel' => 'nofollow'));
$article->set_var('post_comment_link', $post_comment_link);
$article->set_var('lang_post_comment', $LANG01[60]);
// Not really used anymore but left in for old themes
$article->set_var('start_post_comment_anchortag',
'<a href="' . $postCommentUrl
. '" rel="nofollow">');
$article->set_var('end_post_comment_anchortag', '</a>');
}
}
if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) &&
($story->DisplayElements('trackbackcode') >= 0) && ($show_comments)
) {
$num_trackbacks = COM_numberFormat($story->DisplayElements('trackbacks'));
$trackbacksUrl = COM_buildUrl($_CONF['site_url']
. '/article.php?story=' . $story->getSid()) . '#trackback';
$article->set_var('trackbacks_url', $trackbacksUrl);
$article->set_var('trackbacks_text', $num_trackbacks . ' '
. $LANG_TRB['trackbacks']);
$article->set_var('trackbacks_count', $num_trackbacks);
$article->set_var('lang_trackbacks', $LANG_TRB['trackbacks']);
if (SEC_hasRights('story.ping')) {
$pingurl = $_CONF['site_admin_url']
. '/trackback.php?mode=sendall&id=' . $story->getSid();
$pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.'
. $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback']
. '" title="' . $LANG_TRB['send_trackback'] . '"' . XHTML . '>';
$article->set_var('send_trackback_icon',
COM_createLink($pingico, $pingurl)
);
}
$trackbacks_with_count = sprintf($LANG01[122], $num_trackbacks);
if ($story->DisplayElements('trackbacks') > 0) {
$trackbacks_with_count = COM_createLink(
$trackbacks_with_count, $trackbacksUrl);
}
$article->set_var('trackbacks_with_count', $trackbacks_with_count);
}
if (($_CONF['hideemailicon'] == 1) ||
(COM_isAnonUser() &&
(($_CONF['loginrequired'] == 1) ||
($_CONF['emailstoryloginrequired'] == 1)))
) {
$article->set_var('email_icon', '');
} else {
$emailUrl = $_CONF['site_url'] . '/profiles.php?sid=' . $story->getSid()
. '&what=emailstory';
$emailicon = '<img src="' . $_CONF['layout_url'] . '/images/mail.'
. $_IMAGE_TYPE . '" alt="' . $LANG01[64] . '" title="'
. $LANG11[2] . '"' . XHTML . '>';
$article->set_var('email_icon', COM_createLink($emailicon, $emailUrl));
$article->set_var('email_story_url', $emailUrl);
$article->set_var('lang_email_story', $LANG11[2]);
$article->set_var('lang_email_story_alt', $LANG01[64]);
}
$printUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story='
. $story->getSid() . '&mode=print');
if ($_CONF['hideprintericon'] == 1) {
$article->set_var('print_icon', '');
} else {
$printicon = '<img src="' . $_CONF['layout_url']
. '/images/print.' . $_IMAGE_TYPE . '" alt="' . $LANG01[65]
. '" title="' . $LANG11[3] . '"' . XHTML . '>';
$article->set_var('print_icon',
COM_createLink($printicon, $printUrl, array('rel' => 'nofollow'))
);
$article->set_var('print_story_url', $printUrl);
$article->set_var('lang_print_story', $LANG11[3]);
$article->set_var('lang_print_story_alt', $LANG01[65]);
}
$article->set_var('story_display', 'index');
$storyCounter++;
$article->set_var('story_counter', $storyCounter);
}
$article->set_var('recent_comment_anchortag', $recent_comment_anchortag);
if (($index != 'p') && SEC_hasRights('story.edit') &&
($story->checkAccess() == 3) &&
(TOPIC_hasMultiTopicAccess('article', $story->DisplayElements('sid')) == 3)
) {
$editUrl = $_CONF['site_admin_url'] . '/article.php?mode=edit&sid='
. $story->getSid();
$editiconhtml = '<img src="' . $_CONF['layout_url']
. '/images/edit.' . $_IMAGE_TYPE . '" alt="' . $LANG01[4]
. '" title="' . $LANG01[4] . '"' . XHTML . '>';
$article->set_var('edit_link', COM_createLink($LANG01[4], $editUrl));
$article->set_var('edit_url', $editUrl);
$article->set_var('lang_edit_text', $LANG01[4]);
$article->set_var(
'edit_icon',
COM_createLink(
$editiconhtml,
$editUrl,
array(
'class' => 'editlink',
'rel' => 'nofollow',
)
)
);
$article->set_var('edit_image', $editiconhtml);
}
$navi_list = true;
$feedback_list = true;
if ($index == 'p') {
$navi_list = false;
$feedback_list = false;
} else {
$navi_list =
($page_selector !== ''
|| $readmore_link !== ''
|| $post_comment_link !== '');
$feedback_list =
($plugin_itemdisplay !== ''
|| $comments_with_count !== ''
|| $trackbacks_with_count !== '');
}
$story_footer = ($navi_list || $feedback_list || $related_topics !== '');
$article->set_var('navi_list', $navi_list);
$article->set_var('feedback_list', $feedback_list);
$article->set_var('story_footer', $story_footer);
// Set type of view in template so can change display if needed
// Index variable: n = Full display of article. p = 'Preview' mode. Else y = introtext only.
$article->set_var('display_type', $index);
if ($story->DisplayElements('featured') == 1) {
$article->set_var('lang_todays_featured_article', $LANG05[4]);
$article->parse('story_bodyhtml', 'featuredbodytext', true);
PLG_templateSetVars('featuredstorytext', $article);
} elseif ($story->DisplayElements('statuscode') == STORY_ARCHIVE_ON_EXPIRE &&
$story->DisplayElements('expire') <= time()
) {
$article->parse('story_bodyhtml', 'archivestorybodytext', true);
PLG_templateSetVars('archivestorytext', $article);
} else {
$article->parse('story_bodyhtml', 'bodytext', true);
PLG_templateSetVars('storytext', $article);
}
// Add related articles
if ($index === 'n') {
$article->set_var(
'related_articles_by_keyword',
Article::getRelatedArticlesByKeywords(
$story->getSid(),
$story->DisplayElements('meta_keywords')
)
);
}
PLG_templateSetVars($article_filevar, $article);
// Used by Custom Block Locations (needs to be done before cache)
if ($index == 'n') { // p = preview, n = full article, y = intro only (displayed in topics)
PLG_templateSetVars($article_filevar . '_full', $article);
} elseif ($_CONF['blocks_article_topic_list_repeat_after'] > 0) {
if ($index == 'y' && ($articlecount %$_CONF['blocks_article_topic_list_repeat_after'] == 0)) {
PLG_templateSetVars($article_filevar . '_topic_list', $article);
}
}
if ($index != 'p' && ($cache_time > 0 || $cache_time == -1)) {
$article->create_instance($cacheInstance, $article_filevar);
// CACHE_create_instance($cacheInstance, $article);
}
} else {
PLG_templateSetVars($article_filevar, $article);
// Used by Custom Block Locations
if ($index == 'n') { // p = preview, n = full article, y = intro only (displayed in topics)
PLG_templateSetVars($article_filevar . '_full', $article);
} elseif ($_CONF['blocks_article_topic_list_repeat_after'] > 0) {
if ($index == 'y' && ($articlecount %$_CONF['blocks_article_topic_list_repeat_after'] == 0)) {
PLG_templateSetVars($article_filevar . '_topic_list', $article);
}
}
if (!$_CONF['cache_templates']) {
// This is only triggered if cache_templates is disabled but caching is enabled for the article itself
// Template var was original set with set_file (as it is a template file)
// Since the article itself is cached but not the rest of the templates we need to reset the templateCode variable in the template class
// Views use the templateCode variable as well so we can just update the template code variable with set_view as we have already retrieved the cache version of the article
$article->set_view($article_filevar, $retval);
}
}
$article->parse('finalstory', $article_filevar);
return $article->finish($article->get_var('finalstory'));
}
/**
* Extract links from an HTML-formatted text.
* Collects all the links in a story and returns them in an array.
*
* @param string $fulltext the text to search for links
* @param int $maxlength max. length of text in a link (can be 0)
* @return array an array of strings of form <a href="...">link</a>
*/
function STORY_extractLinks($fulltext, $maxlength = 26)
{
$rel = array();
/* Only match anchor tags that contain 'href="<something>"'
*/
preg_match_all("/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\/a>/i", $fulltext, $matches);
for ($i = 0; $i < count($matches[0]); $i++) {
$matches[2][$i] = GLText::stripTags($matches[2][$i]);
if (!MBYTE_strlen(trim($matches[2][$i]))) {
$matches[2][$i] = GLText::stripTags($matches[1][$i]);
}
// if link is too long, shorten it and add ... at the end
if (($maxlength > 0) && (MBYTE_strlen($matches[2][$i]) > $maxlength)) {
$matches[2][$i] = MBYTE_substr($matches[2][$i], 0, $maxlength - 3) . '...';
}
$rel[] = '<a href="' . $matches[1][$i] . '">'
. str_replace(array("\015", "\012"), '', $matches[2][$i])
. '</a>';
}
return ($rel);
}
/**
* Create "What's Related" links for a story
* Creates an HTML-formatted list of links to be used for the What's Related
* block next to a story (in article view).
*
* @param string $related contents of gl_stories 'related' field
* @param int $uid user id of the author
* @param int $sid story id
* @return string HTML-formatted list of links
*/
function STORY_whatsRelated($related, $uid, $sid)
{
global $_CONF, $_TABLES, $LANG24;
// Is it enabled?
// Disabled' => 0, 'Enabled' => 1, 'Enabled (No Links)' => 2, 'Enabled (No Outbound Links)' => 3
if ($_CONF['whats_related']) {
// get the links from the story text
if ($_CONF['whats_related'] != 2) {
if (!empty ($related)) {
$rel = explode("\n", $related);
} else {
$rel = array();
}
// Used to hunt out duplicates. Stores urls that have already passed filters
$urls = array();
foreach ($rel as $key => &$value) {
if (preg_match("/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\/a>/i",
$value, $matches) === 1
) {
// Go through array and remove links with no link text except link. Since a max of only 23 characters of link text showen then compare only this
if (substr($matches[1], 0, 23) != substr($matches[2], 0, 23)) {
// Check if outbound links (if needed)
$passd_check = false;
if ($_CONF['whats_related'] == 3) { // no outbound links
if ($_CONF['site_url'] == substr($matches[1], 0, strlen($_CONF['site_url']))) {
$passd_check = true;
}
} else {
$passd_check = true;
}
if ($passd_check) {
// Go through array and remove any duplicates of this link
if (in_array($matches[1], $urls)) {
// remove it from the array
unset($rel[$key]);
} else {
$urls[] = $matches[1];
// Now Check Words
$value = '<a href="' . $matches[1] . '">'
. COM_checkWords($matches[2], 'story') . '</a>';
}
} else {
// remove it from the array
unset($rel[$key]);
}
} else {
// remove it from the array
unset($rel[$key]);
}
} else {
$value = COM_checkWords($value, 'story');
}
}
unset($value);
}
$topics = array();
if (!COM_isAnonUser() || (($_CONF['loginrequired'] == 0) &&
($_CONF['searchloginrequired'] == 0))
) {
// add a link to "search by author"
if ($_CONF['contributedbyline'] == 1) {
$author = $LANG24[37] . ' ' . COM_getDisplayName($uid);
if ($_CONF['whats_related_trim'] > 0 && (MBYTE_strlen($author) > $_CONF['whats_related_trim'])) {
$author = substr($author, 0, $_CONF['whats_related_trim'] - 3) . '...';
}
$topics[] = "<a href=\"{$_CONF['site_url']}/search.php?mode=search&type=stories&author=$uid\">$author</a>";
}
// Retrieve topics
$tids = TOPIC_getTopicIdsForObject('article', $sid, 0);
foreach ($tids as $tid) {
// add a link to "search by topic"
$topic = $LANG24[38] . ' ' . stripslashes(DB_getItem($_TABLES['topics'], 'topic', "tid = '$tid'"));
// trim topics if needed
if ($_CONF['whats_related_trim'] > 0 && (MBYTE_strlen($topic) > $_CONF['whats_related_trim'])) {
$topic = substr($topic, 0, $_CONF['whats_related_trim'] - 3) . '...';
}
$topics[] = '<a href="' . $_CONF['site_url']
. '/search.php?mode=search&type=stories&topic=' . $tid
. '">' . $topic . '</a>';
}
}
// If line limit then split between related links and topics
if ($_CONF['whats_related_max'] > 0) {
if ($_CONF['whats_related_max'] < 3) {
$rel = array(); // Reset related links so at least user search and default topic search is displayed
$topics = array_slice($topics, 0, 2);
} else {
$rel_max_num_items = intval($_CONF['whats_related_max'] / 2);
$topic_max_num_items = $rel_max_num_items;
if (($rel_max_num_items + $topic_max_num_items) != $_CONF['whats_related_max']) {
$topic_max_num_items = $topic_max_num_items + 1;
}
// Now check if we have enough topics to display else give it to links
$topic_num_items = count($topics);
$rel_num_items = count($rel);
$added_flag = false;
if ($topic_num_items < $topic_max_num_items) {
$rel_max_num_items = $rel_max_num_items + ($topic_max_num_items - $topic_num_items);
$added_flag = true;
}
if (!$added_flag && ($rel_num_items < $rel_max_num_items)) {
$topic_max_num_items = $topic_max_num_items + ($rel_max_num_items - $rel_num_items);
}
$rel = array_slice($rel, 0, $rel_max_num_items);
$topics = array_slice($topics, 0, $topic_max_num_items);
}
}
$result = array_merge($rel, $topics);
$related = '';
if (count($result) > 0) {
$related = COM_makeList($result, 'list-whats-related');
}
} else {
$related = '';
}
return $related;
}
/**
* Delete one image from a story
* Deletes scaled and unscaled image, but does not update the database.
*
* @param string $image file name of the image (without the path)
*/
function STORY_deleteImage($image)
{
global $_CONF;
if (empty ($image)) {
return;
}
$filename = $_CONF['path_images'] . 'articles/' . $image;
if (!@unlink($filename)) {
// log the problem but don't abort the script
echo COM_errorLog('Unable to remove the following image from the article: ' . $filename);
}
// remove unscaled image, if it exists
$lFilename_large = substr_replace($image, '_original.',
strrpos($image, '.'), 1);
$lFilename_large_complete = $_CONF['path_images'] . 'articles/'
. $lFilename_large;
if (file_exists($lFilename_large_complete)) {
if (!@unlink($lFilename_large_complete)) {
// again, log the problem but don't abort the script
echo COM_errorLog('Unable to remove the following image from the article: ' . $lFilename_large_complete);
}
}
// delete thumbnail image
STORY_deleteThumbnail($image);
STORY_deleteThumbnail($lFilename_large);
}
/**
* Delete thumbnail
*
* @param string $image file name of the thumbnail (without the path)
*/
function STORY_deleteThumbnail($image)
{
global $_CONF;
$thumb = substr_replace($image, '_64x64px.', strrpos($image, '.'), 1);
$thumb_path = $_CONF['path_images'] . '_thumbs/articles/' . $thumb;
if (file_exists($thumb_path)) {
@unlink($thumb_path);
}
}
/**
* Delete all images from a story
* Deletes all scaled and unscaled images from the file system and the database.
*
* @param string $sid story id
*/
function STORY_deleteImages($sid)
{
global $_TABLES;
$result = DB_query("SELECT ai_filename FROM {$_TABLES['article_images']} WHERE ai_sid = '$sid'");
$nrows = DB_numRows($result);
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
STORY_deleteImage($A['ai_filename']);
}
DB_delete($_TABLES['article_images'], 'ai_sid', $sid);
}
/**
* Delete a story.
* This is used to delete a story from the list of stories.
*
* @param string $sid ID of the story to delete
* @return array
*/
function STORY_deleteStory($sid)
{
$args = array(
'sid' => $sid,
);
$output = array();
$svc_msg = array();
PLG_invokeService('story', 'delete', $args, $output, $svc_msg);
return $output;
}
/**
* Delete a story and related data immediately.
* Note: For internal use only! To delete a story, use STORY_deleteStory (see
* above), which will do permission checks and eventually end up here.
*
* @param string $sid ID of the story to delete
* @internal For internal use only!
*/
function STORY_doDeleteThisStoryNow($sid)
{
global $_CONF, $_TABLES;
require_once $_CONF['path_system'] . 'lib-comment.php';
STORY_deleteImages($sid);
DB_delete($_TABLES['comments'], array('sid', 'type'),
array($sid, 'article'));
DB_delete($_TABLES['trackback'], array('sid', 'type'),
array($sid, 'article'));
DB_delete($_TABLES['stories'], 'sid', $sid);
TOPIC_deleteTopicAssignments('article', $sid);
// notify plugins
PLG_itemDeleted($sid, 'article');
// update RSS feed
COM_rdfUpToDateCheck('article');
COM_rdfUpToDateCheck('comment');
STORY_updateLastArticlePublished();
CMT_updateCommentcodes();
}
/**
* Updates last_article_publish variables stored in vars table.
* Note: Used when insert/update/delete an article. last_article_publish is used to
* determine new articles and if feeds need to be updated.
*/
function STORY_updateLastArticlePublished()
{
global $_TABLES;
//Set new latest article published in feed
$sql = "SELECT date FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() AND perm_anon > 0 ORDER BY date DESC LIMIT 1";
$result = DB_query($sql);
$A = DB_fetchArray($result);
DB_query("UPDATE {$_TABLES['vars']} SET value='{$A['date']}' WHERE name='last_article_publish'");