-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
executable file
·1750 lines (1575 loc) · 62.2 KB
/
init.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
/**
* This file is part of Monkeychow - http://shokk.wordpress.com/tag/monkeychow/
*
* init.php - initializes MC, and contains functions used from other scripts
*
* PHP version 5
*
* Copyright (C) 2006 Ernie Oporto
* ernieoporto@yahoo.com - http://shokk.wordpress.com
*
* Copyright (C) 2004 Stephen Minutillo
* steve@minutillo.com - http://minutillo.com/steve/
*
* LICENSE: Distributed under the GPL - see LICENSE
*
* @category Stand-alone_Multi-user_RSS_Feed_Reader
* @package MonkeyChow
* @author Ernie Oporto <ernieoporto@yahoo.com>
* @copyright 2006-2013 Ernie Oporto, 2004 Steve Minutillo
* @license http://www.gnu.org/licenses/gpl.html GPL License
* @version GIT: <git_id>
* @link http://shokk.wordpress.org/tag/monkeychow/
*
**/
error_reporting(E_ERROR);
require_once('config.php');
$fb_app_id = FB_APP_ID;
$fb_app_secret = FB_APP_SECRET;
$fb_callback = FB_CALLBACK;
$tw_app_id = TWITTER_APP_ID;
$tw_app_secret = TWITTER_APP_SECRET;
$tw_callback = TWITTER_CALLBACK;
$li_app_id = LINKEDIN_APP_ID;
$li_app_secret = LINKEDIN_APP_SECRET;
$li_callback = LINKEDIN_CALLBACK;
$gg_app_id = GOOGLE_APP_ID;
$gg_app_secret = GOOGLE_APP_SECRET;
$gg_callback = GOOGLE_CALLBACK;
$bu_app_id = BUFFER_APP_ID;
$bu_app_secret = BUFFER_APP_SECRET;
$bu_callback = BUFFER_CALLBACK;
//$tu_app_id = TUMBLR_APP_ID;
//$tu_app_secret = TUMBLR_APP_SECRET;
//$tu_callback = TUMBLR_CALLBACK;
require_once('includes/Oauth.php');
if ($fb_app_id) {require_once('includes/Facebook.php');}
if ($gg_app_id) {require_once('includes/Google.php');}
if ($li_app_id) {require_once('includes/LinkedIn.php');}
if ($tw_app_id) {require_once('includes/Twitter.php');}
//if ($tu_app_id) {require_once('includes/Tumblr.php');}
if ($bu_app_id) {require_once('includes/Buffer.php');}
define('FOF_MAX_INT', 2147483647);
$_REQUEST['baserequest']=$_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
$FOF_FEED_TABLE = FOF_FEED_TABLE;
$FOF_ITEM_TABLE = FOF_ITEM_TABLE;
$FOF_SUBSCRIPTION_TABLE = FOF_SUBSCRIPTION_TABLE;
$FOF_FLAG_TABLE = FOF_FLAG_TABLE;
$FOF_USER_TABLE = FOF_USER_TABLE;
$FOF_USERITEM_TABLE = FOF_USERITEM_TABLE;
require_once('simplepie/autoloader.php');
// If not in 'safe mode', increase the maximum execution time:
if (!ini_get('safe_mode')) {
set_time_limit(240);
}
if (!function_exists("gettext")) {
/**
* Convert string with gettext
*
* @param string $str the text to convert
*
* @return string
*/
function _($str)
{
/**
* @str string
*/
return $str;
}
}
if ( !function_exists('htmlspecialchars_decode') ) {
/**
* Converts htmlspecialchars
*
* @param string $text the text to convert
*
* @return string
*/
function htmlspecialchars_decode($text)
{
// @text string
return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}
}
$fof_connection = mysql_connect(FOF_DB_HOST, FOF_DB_USER, FOF_DB_PASS) or
die ( _("Cannot connect to database. Check your configuration.") . " " . _("Mysql says") . ": <b>" . mysql_error() . "</b>");
mysql_select_db(FOF_DB_DBNAME, $fof_connection) or
die ( _("Cannot select database. Check your configuration") . " " . _("Mysql says") . ": " . mysql_error());
if (!$installing) {
is_writable(FOF_CACHE_DIR) or die ( _("Cache directory is not writable or does not exist.") . " " . _("Have you run") . " <a href=\"install.php\"><code>install.php</code></a>?");
}
/**
* Prune a feed's old stuff
*
* @param string $id the ID of the feed that needs to be pruned
*
* @return void
*/
function fof_prune_feed($id)
{
/**
* @id string
*/
$sql = "select aging from" . $FOF_FEED_TABLE . "where id='$id'";
//$result=fof_do_query($sql);
$row = mysql_fetch_array(fof_do_query($sql));
$keep_days = $row['aging'];
if ($keep_days > 0) {
$sql = "delete from " . $FOF_ITEM_TABLE . " where `feed_id`=$id AND `star`!=1 AND `read`=1 AND to_days(CURDATE()) - to_days(`timestamp`) > $keep_days";
//print "<br />" . $sql . "<br />";
fof_do_query($sql);
}
}
/**
* Nothing to See Here
*
* @return void
*/
function prune_feeds()
{
global $FOF_FEED_TABLE;
$sql="SELECT id FROM `" . $FOF_FEED_TABLE . "` ORDER BY `" . $FOF_FEED_TABLE . "`.`id` ASC;";
$result=fof_do_query($sql);
while ($row = mysql_fetch_array($result)) {
$feedsidarray[]=$row['id'];
}
$sql="SELECT DISTINCT feed_id FROM `" . $FOF_ITEM_TABLE . "` ORDER BY `" . $FOF_ITEM_TABLE . "`.`feed_id` ASC;";
$result=fof_do_query($sql);
while ($row = mysql_fetch_array($result)) {
$feedsitemsarray[]=$row['feed_id'];
}
$result = array_diff($feedsitemsarray, $feedsidarray);
//$sql="delete FROM `" . $FOF_ITEM_TABLE . "` ";
$sql="";
foreach ($result as $resultthing) {//print "::" . $resultthing . "::<br />\n";
if ($sql == "") {
$sql = "delete FROM `" . $FOF_ITEM_TABLE . "` WHERE `" . $FOF_ITEM_TABLE . "`.`feed_id` LIKE $resultthing ";
} else {
$sql .= "OR `" . $FOF_ITEM_TABLE . "`.`feed_id` LIKE $resultthing ";
}
}
//print_r($result);
//print "<br />" . $sql;
$result=fof_do_query($sql, 1);
flush();
}
/** Returns a comma separated list of subscribed feeds with optional tag support.
*
* @param string $tags the tags to display feeds for
*
* @return string
*/
function fof_get_subscribed_feeds_list($tags = null) //Suitable for input into SQL queries
{
global $FOF_FEED_TABLE, $FOF_SUBSCRIPTION_TABLE;
$sql = "select $FOF_FEED_TABLE.id from $FOF_FEED_TABLE, $FOF_SUBSCRIPTION_TABLE where $FOF_SUBSCRIPTION_TABLE.user_id = " . current_user() . " and $FOF_FEED_TABLE.id = $FOF_SUBSCRIPTION_TABLE.feed_id ";
if ($tags != '' && $tags != _("All tags") && $tags != _("No tags")) {
$sql .= " AND $FOF_SUBSCRIPTION_TABLE.tags LIKE '%$tags%'";
}
if ($tags == _("No tags")) {
$sql .= " AND ($FOF_SUBSCRIPTION_TABLE.tags IS NULL or $FOF_SUBSCRIPTION_TABLE.tags LIKE '')";
}
//echo $sql . "<br />\n";
$result = fof_do_query($sql);
$i = 0;
while ($row = mysql_fetch_array($result)) {
if ($i == 0) {
$list = $row['id'];
} else {
$list .= ", " . $row['id'];
}
$i++;
}
return $list;
}
/**
* Get the list of subscribed feeds
*
* @param string $order the order to sort the feed
* @param string $direction normal or reverse sort?
* @param string $tags the tags to display feeds for
*
* @return array
*/
function fof_get_feeds($order = 'title', $direction = 'asc', $tags = null)
{
global $FOF_FEED_TABLE, $FOF_USER_TABLE, $FOF_FLAG_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $FOF_USERITEM_TABLE;
//fof_prune_expir_feeds();
// subscriptions query returns results
// need to provide tag so that list can be filtered
// fof_db_get_subscriptions(current_user(), $order, $direction, $tags);
// $sql = "SELECT id, url, title, link, image, description FROM " . $FOF_FEED_TABLE;
if (fof_is_admin()) {
$sql2 = "select distinct ";
} else {
$sql2 = "select ";
}
$sql2 .= "$FOF_FEED_TABLE.id, $FOF_FEED_TABLE.url, $FOF_FEED_TABLE.title, $FOF_FEED_TABLE.link, $FOF_FEED_TABLE.image, $FOF_FEED_TABLE.description from $FOF_FEED_TABLE, $FOF_SUBSCRIPTION_TABLE where $FOF_FEED_TABLE.id = $FOF_SUBSCRIPTION_TABLE.feed_id";
if (!fof_is_admin()) {
$sql2 .= " and $FOF_SUBSCRIPTION_TABLE.user_id = " . current_user();
}
$feedlist=fof_get_subscribed_feeds_list($tags);
if ($feedlist != "") {
if (!fof_is_admin()) {
$sql2 .= " AND $FOF_FEED_TABLE.id in ($feedlist)";
}
//echo "FIRSTSQL: " . $sql2 . "<br />\n";
$result = fof_do_query($sql2);
} else {
$result = "";
}
$i = 0;
while ($row = mysql_fetch_array($result)) {
//$id = $row['id'];
$feeds[$i]['id'] = $row['id'];
$feeds[$i]['url'] = $row['url'];
$feeds[$i]['title'] = $row['title'];
$feeds[$i]['link'] = $row['link'];
$feeds[$i]['description'] = $row['description'];
$feeds[$i]['image'] = $row['image'];
$age = fof_rss_age($row['id']);
$feeds[$i]['age'] = $age;
if ($age == FOF_MAX_INT) {
$agestr = "never";
$agestrabbr = "∞";
} else {
$seconds = $age % 60;
$minutes = $age / 60 % 60;
$hours = $age / 60 / 60 % 24;
$days = floor($age / 60 / 60 / 24);
if ($seconds) {
$agestr = "$seconds sec";
if ($seconds != 1) {
$agestr .= "s";
}
$agestr .= " ago";
$agestrabbr = $seconds . "s";
}
if ($minutes) {
$agestr = "$minutes min";
if ($minutes != 1) {
$agestr .= "s";
}
$agestr .= " ago";
$agestrabbr = $minutes . "m";
}
if ($hours) {
$agestr = "$hours hr";
if ($hours != 1) {
$agestr .= "s";
}
$agestr .= " ago";
$agestrabbr = $hours . "h";
}
if ($days) {
$agestr = "$days day";
if ($days != 1) {
$agestr .= "s";
}
$agestr .= " ago";
$agestrabbr = $days . "d";
}
}
$feeds[$i]['agestr'] = $agestr;
$feeds[$i]['agestrabbr'] = $agestrabbr;
$i++;
}
// unread articles count
$sql = "SELECT count( feed_id ) AS count, feed_id AS id FROM " . $FOF_FEED_TABLE . ", " . $FOF_ITEM_TABLE . " WHERE " . $FOF_FEED_TABLE . ".id = " . $FOF_ITEM_TABLE . ".feed_id ";
$sql .= " AND " . $FOF_ITEM_TABLE . ".id NOT IN ( SELECT `$FOF_ITEM_TABLE`.id FROM `$FOF_ITEM_TABLE`,`$FOF_FEED_TABLE`,`$FOF_FLAG_TABLE`,`$FOF_USER_TABLE` WHERE `$FOF_USER_TABLE`.user_id=" . current_user() . " AND flag_id=1) ";
$sql .= " AND " . $FOF_FEED_TABLE . ".id IN (SELECT `feed_id` FROM `" . $FOF_SUBSCRIPTION_TABLE . "` WHERE user_id =" . current_user() . ")";
$sql .= " group by feed_id order by " . $FOF_FEED_TABLE . ".title";
//print "SECOND SQL: $sql <br/>";
$result = fof_do_query($sql);
while ($row = mysql_fetch_array($result)) {
for ($i=0; $i<count($feeds); $i++) {
if ($feeds[$i]['id'] == $row['id']) {
$feeds[$i]['unread'] = $row['count'];
}
}
}
//total articles count
$result = fof_do_query("SELECT count( feed_id ) as count, feed_id as id from " . $FOF_FEED_TABLE . ", " . $FOF_ITEM_TABLE . " where " . $FOF_FEED_TABLE . ".id = " . $FOF_ITEM_TABLE . ".feed_id group by feed_id order by " . $FOF_FEED_TABLE . ".title");
while ($row = mysql_fetch_array($result)) {
for ($i=0; $i<count($feeds); $i++) {
if ($feeds[$i]['id'] == $row['id']) {
$feeds[$i]['items'] = $row['count'];
}
}
}
$feeds = fof_multi_sort($feeds, $order, $direction != "asc");
return $feeds;
}
/**
* Actually prunes the feed
*
* @return void
*/
function fof_prune_expir_feeds()
{
global $FOF_FEED_TABLE;
//from `$FOF_FEED_TABLE`, " . $FOF_ITEM_TABLE . " where `$FOF_FEED_TABLE`.id = " . $FOF_ITEM_TABLE . ".feed_id AND `read` is null group by feed_id order by " . $FOF_FEED_TABLE . ".title
$sql = "select id from " . $FOF_FEED_TABLE . " where expir != 0 AND ((to_days( CURDATE( ) ) - to_days( date_added )) > expir)";
$result = fof_do_query($sql);
while ($row = mysql_fetch_array($result)) {
$feed_id = $row['id'];
$result = fof_do_query("delete from " . $FOF_FEED_TABLE . " where id = $feed_id");
$result = fof_do_query("delete from " . $FOF_ITEM_TABLE . " where feed_id = $feed_id");
}
}
/**
* Get the name of the user based on the id
*
* @return string
*/
function get_user_name()
{
global $FOF_USER_TABLE;
$sql = "SELECT user_name from $FOF_USER_TABLE where user_id =" . current_user();
//$pieces = explode("::", $_COOKIE["mc_info"]);
//$user_name = $pieces[0];
$result = fof_do_query($sql);
$row= mysql_fetch_array($result);
$user_name = $row['user_name'];
return $user_name;
}
/**
* Gets the title of a feed
*
* @param string $feed the feed to display
* @param string $what what kind of articles
* @param string $when date
* @param int $start the starting number
* @param int $limit how may to display
*
* @return string
*/
function fof_view_title($feed=null, $what="new", $when=null, $start=null, $limit=null)
{
$title = "";
//$pieces = explode("::", $_COOKIE["mc_info"]);
//$user_name = $pieces[0];
$title = "<i>[" . get_user_name() . ":" . current_user() ."]</i> - ";
$title .= "MonkeyChow";
if (!is_null($when) && $when != "") {
$title .= ' - ' . $when ;
}
if (!is_null($feed) && $feed != "") {
$r = fof_feed_row($feed);
$title .= ' - <a href="' . $r['link'] . '" title="' . htmlspecialchars($r['feed_description']) . '">' . htmlspecialchars($r['title']) . '</a> ';
}
if (is_numeric($start)) {
if (!is_numeric($limit)) {
$limit = FOF_HOWMANY;
}
$title .= " - items $start to " . ($start + $limit);
}
if ($what == "published") {
$title .=' - ' . _("published items");
} else if ($what == "search") {
$title .=' - ' . _("custom search");
} else if ($what != "all") {
$title .=' - ' . _("new items");
} else {
$title .= ' - ' . _("all items");
}
return $title;
}
/**
* Get the articles of a feed
*
* @param string $feed the feed we are displaying
* @param string $what what kind of feeds
* @param string $when date
* @param int $start starting number
* @param int $limit how many to show
* @param string $order most recent or oldest?
* @param string $tags the tag of the feeds to diplay
* @param string $search are we searching for something in particular
*
* @return array
*/
function array_kshift(&$arr)
{
list($k) = array_keys($arr);
$r = array($k=>$arr[$k]);
unset($arr[$k]);
return $r;
}
function fof_get_items_pastweek($feed=null, $what="new", $when=null, $start=null, $limit=null, $order="desc", $tags=null, $search=null)
{
$stopwords = array("a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","among", "amongst", "amoungst", "amount", "an", "and", "another", "any","anyhow","anyone","anything","anyway", "anywhere", "are", "around", "as", "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own","part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the","...","thank","screenshot","Chapters","new");
$stopworduniquearray=array();
foreach($stopwords as $stopword)
{
$stopworduniquearray[$stopword]=1;
}
#print_r($stopworduniquearray);
$titlestring="";
global $FOF_FEED_TABLE;
global $FOF_ITEM_TABLE;
global $FOF_USERITEM_TABLE;
global $FOF_SUBSCRIPTION_TABLE;
if ($when="week")
{
$begin = strtotime(date("Y/m/d", time() - (7 * 24 * 60 * 60))); # one week ago
}
elseif ($when="today")
{
$begin = strtotime(date("Y/m/d", time() - (24 * 60 * 60))); # one day ago
}
else
{
#blah
}
$end=time();
$sql = "SELECT `$FOF_ITEM_TABLE`.`title`,`$FOF_ITEM_TABLE`.`timestamp` FROM `$FOF_ITEM_TABLE`,`$FOF_FEED_TABLE`,`$FOF_SUBSCRIPTION_TABLE` WHERE `$FOF_ITEM_TABLE`.`feed_id`=`$FOF_FEED_TABLE`.`id` AND `$FOF_FEED_TABLE`.`id`=`$FOF_SUBSCRIPTION_TABLE`.`feed_id` AND `$FOF_SUBSCRIPTION_TABLE`.`user_id`=" . current_user() . " AND (`$FOF_ITEM_TABLE`.`timestamp` > NOW( ) - INTERVAL 1 WEEK)";
#echo "SQL:: " . $sql . " ::SQL</br></br>";
$result = fof_do_query($sql);
while($row = mysql_fetch_array($result))
{
$origstring = $row['title'];
$origstring = trim($origstring);
$origstring = strtolower(str_replace(array("[","]","–","-","&","\$","...","\'","\"","#","?","!",",",";",":"),"", $origstring));
$titlestring .= htmlspecialchars($origstring) . " ";
}
$pieces=explode(" ", $titlestring);
$countingarray=array_count_values($pieces); #count all the pieces - not unique
foreach($countingarray as $key => $value)
{
$value=trim($value);
if(preg_match('/^\d/',$key))
{
#echo $countingarray[$key];
}
else
{
$countarray[$key]=$value;
}
}
$countingarray=array();
krsort($countarray);
$uniquearray=array_diff_key($countarray,$stopworduniquearray); #the unique count of the group of non-stopwords
$countarray=array();
$stopworduniquearray=array();
arsort($uniquearray);
array_kshift($uniquearray);
#at this point we have all the popular keep words in titles from the articles of the past week
#everything below is how we determine which are the most popular
#for something quick and dirty, I take 3 articles of the top 10 (30) and 2 articles from the next 10 (20)
$array=array();
for($i=0;$i<20;$i++)
{
$keyword = key(array_kshift($uniquearray));
$rows=fof_get_items($null,"search",$null,0,3,$null,$null,$keyword);
$array[] = $rows;
}
for($i=0;$i<10;$i++)
{
$keyword = key(array_kshift($uniquearray));
$rows=fof_get_items($null,"search",$null,0,2,$null,$null,$keyword);
$array[] = $rows;
}
$array = fof_multi_sort($array, 'dcdate', $order != "asc");
return $array;
}
function fof_get_items($feed=null, $what="new", $when=null, $start=null, $limit=null, $order="desc", $tags=null, $search=null)
{
global $FOF_FEED_TABLE;
global $FOF_ITEM_TABLE;
global $FOF_USERITEM_TABLE;
global $FOF_SUBSCRIPTION_TABLE;
if (!is_null($when) && $when != "") {
if ($when == "today") {
$whendate = date("Y/m/d", time() - (FOF_TIME_OFFSET * 60 * 60));
} else {
$whendate = $when;
}
$begin = strtotime($whendate);
$begin = $begin + (FOF_TIME_OFFSET * 60 * 60);
$end = $begin + (24 * 60 * 60);
$tomorrow = date("Y/m/d", $begin + (24 * 60 * 60));
$yesterday = date("Y/m/d", $begin - (24 * 60 * 60));
}
if (is_numeric($start)) {
if (!is_numeric($limit)) {
$limit = FOF_HOWMANY;
}
$limit_clause = " limit $start, $limit ";
}
$query = "select " . $FOF_FEED_TABLE . ".tags as feed_tags, " . $FOF_FEED_TABLE . ".image as feed_image, " . $FOF_FEED_TABLE . ".title as feed_title, " . $FOF_FEED_TABLE . ".link as feed_link, " . $FOF_FEED_TABLE . ".description as feed_description, " . $FOF_ITEM_TABLE . ".id as item_id, " . $FOF_ITEM_TABLE . ".link as item_link, " . $FOF_ITEM_TABLE . ".title as item_title, UNIX_TIMESTAMP(" . $FOF_ITEM_TABLE . ".timestamp) as timestamp, " . $FOF_ITEM_TABLE . ".content as item_content, " . $FOF_ITEM_TABLE . ".dcdate as dcdate, " . $FOF_ITEM_TABLE . ".dccreator as dccreator, " . $FOF_ITEM_TABLE . ".dcsubject as dcsubject ";
$query .= " from " . $FOF_FEED_TABLE . ", " . $FOF_ITEM_TABLE . ", " . $FOF_SUBSCRIPTION_TABLE;
if (($what == "published")||($what == "starred")||($what == "private")) {
$query .= ", " . $FOF_USERITEM_TABLE;
}
$feedlist = fof_get_subscribed_feeds_list($tags);
//$query .= " where " . $FOF_ITEM_TABLE . ".feed_id=" . $FOF_FEED_TABLE . ".id and " . $FOF_SUBSCRIPTION_TABLE . ".feed_id = " . $FOF_FEED_TABLE . ".id and " . $FOF_FEED_TABLE . ".id in ($feedlist)";
$query .= " WHERE " . $FOF_ITEM_TABLE . ".feed_id=" . $FOF_FEED_TABLE . ".id and " . $FOF_SUBSCRIPTION_TABLE . ".feed_id = " . $FOF_FEED_TABLE . ".id ";
if (($what == "published")||($what == "starred")||($what == "private")) {
$query .= " AND " . $FOF_USERITEM_TABLE . ".item_id = " . $FOF_ITEM_TABLE . ".id ";
}
if (!is_null($feed) && $feed != "") {
$query .= " AND " . $FOF_FEED_TABLE . ".id = $feed";
}
if (!is_null($when) && $when != "") {
$query .= " AND UNIX_TIMESTAMP(" . $FOF_ITEM_TABLE . ".timestamp) > $begin AND UNIX_TIMESTAMP(" . $FOF_ITEM_TABLE . ".timestamp) < $end";
}
if (!is_null($tags) && $tags!="" && $tags!="All tags") {
if ($tags=="No tags") {
$query .= " AND " . $FOF_SUBSCRIPTION_TABLE . ".tags IS NULL";// or tags LIKE ''";
} else {
$query .= " AND " . $FOF_SUBSCRIPTION_TABLE . ".tags LIKE \"%" . $tags . "%\"";
}
}
$query .= " AND " . $FOF_SUBSCRIPTION_TABLE . ".user_id = " . current_user();
if (($what == "published")||($what == "starred")||($what == "private")) {
$query .= " AND " . $FOF_SUBSCRIPTION_TABLE . ".user_id=" . $FOF_USERITEM_TABLE . ".user_id ";
}
if ($what == "published") {
//$query .= " AND " . $FOF_ITEM_TABLE . ".publish=1";
//$query .= " AND " . $FOF_ITEM_TABLE . ".id IN ( SELECT `item_id` FROM `" . $FOF_USERITEM_TABLE . "` WHERE `user_id`=" . current_user() . " AND `flag_id`=3) ";
$query .= " AND " . $FOF_USERITEM_TABLE . ".flag_id=3 ";
} else if ($what == "public") {
//$query .= " AND " . $FOF_FEED_TABLE . ".private=0";
$query .= " AND " . $FOF_ITEM_TABLE . ".id NOT IN ( SELECT `item_id` FROM `" . $FOF_USERITEM_TABLE . "` WHERE `user_id`=" . current_user() . " AND `flag_id`=4) ";
} else if ($what == "starred") {
//$query .= " AND " . $FOF_ITEM_TABLE . ".star=1";
//$query .= " AND " . $FOF_ITEM_TABLE . ".id IN ( SELECT `item_id` FROM `" . $FOF_USERITEM_TABLE . "` WHERE `user_id`=" . current_user() . " AND `flag_id`=2) ";
$query .= " AND " . $FOF_USERITEM_TABLE . ".flag_id=2 ";
} else if ($what == "search") {
$query .= " AND " . $FOF_ITEM_TABLE . ".title LIKE \"%" . $search . "%\"";
} else if ($what != "all") {
//$query .= " AND " . $FOF_ITEM_TABLE . ".read is null";
$query .= " AND " . $FOF_ITEM_TABLE . ".id NOT IN ( SELECT item_id FROM " . $FOF_USERITEM_TABLE . " WHERE user_id =" . current_user() . " AND flag_id=1) ";
}
$query .= " order by timestamp desc $limit_clause";
//echo "SQL:: " . $query . " ::SQL<br/>";
if ($feedlist != "") {
$result = fof_do_query($query);
} else {
$result="";
}
while ($row = mysql_fetch_array($result)) {
$array[] = $row;
}
$array = fof_multi_sort($array, 'dcdate', $order != "asc");
return $array;
}
/**
* Get the navigation links for the framed view
*
* @param string $feed the feed we are displaying
* @param string $what what kind of articles
* @param string $when date
* @param int $start the starting number
* @param int $limit how many to display
* @param string $framed are we in the framed view
* @param string $tags the tags to show
*
* @return string
*/
function fof_get_frame_nav_links($feed=null, $what="new", $when=null, $start=null, $limit=null, $framed=null, $tags=null)
{
$string = "";
if (!is_null($when) && $when != "") {
if ($when == "today") {
$whendate = date("Y/m/d", time() - (FOF_TIME_OFFSET * 60 * 60));
} else {
$whendate = $when;
}
$begin = strtotime($whendate);
$begin = $begin + (FOF_TIME_OFFSET * 60 * 60);
$end = $begin + (24 * 60 * 60);
$tomorrow = date("Y/m/d", $begin + (24 * 60 * 60));
$yesterday = date("Y/m/d", $begin - (24 * 60 * 60));
$string .= "<a href=\"framesview.php?feed=$feed&what=$what&when=$yesterday&how=$how&howmany=$howmany";
$string .= ($framed) ? "&framed=yes" : "";
$string .= ($tags) ? "&tags=" . $tags : "";
$string .= "\">[« $yesterday]</a> ";
if ($when != "today") {
$string .= "<a href=\"framesview.php?feed=$feed&what=$what&when=today&how=$how&howmany=$howmany";
$string .= ($framed) ? "&framed=yes" : "";
$string .= ($tags) ? "&tags=" . $tags : "";
$string .= "\">[today]</a> ";
}
if ($when != "today") {
$string .= "<a href=\"framesview.php?feed=$feed&what=$what&when=$tomorrow&how=$how&howmany=$howmany";
$string .= ($framed) ? "&framed=yes" : "";
$string .= ($tags) ? "&tags=" . $tags : "";
$string .= "\">[$tomorrow »]</a> ";
}
}
if (is_numeric($start)) {
if (!is_numeric($limit)) {
$limit = FOF_HOWMANY;
}
$earlier = $start + $limit;
$later = $start - $limit;
$newonly = $_REQUEST['newonly'];
$string .= "<a href=\"framesview.php?feed=$feed&what=$what&when=$when&how=paged&which=$earlier&howmany=$limit";
$string .= ($framed) ? "&framed=yes" : "";
$string .= ($tags) ? "&tags=" . $tags : "";
$string .= ($newonly) ? "&newonly=" . $newonly : "";
$string .= "\">[« previous $limit]</a> ";
if ($later >= 0) {
$string .= "<a href=\"framesview.php?feed=$feed&what=$what&when=$when&how=paged&howmany=$limit";
$string .= ($framed) ? "&framed=yes" : "";
$string .= ($tags) ? "&tags=" . $tags : "";
$string .= ($newonly) ? "&newonly=" . $newonly : "";
$string .= "\">[current items]</a> ";
}
if ($later >= 0) {
$string .= "<a href=\"framesview.php?feed=$feed&what=$what&when=$when&how=paged&which=$later&howmany=$limit";
$string .= ($framed) ? "&framed=yes" : "";
$string .= ($tags) ? "&tags=" . $tags : "";
$string .= ($newonly) ? "&newonly=" . $newonly : "";
$string .= "\">[next $limit »]</a> ";
}
}
return $string;
}
/**
* Renders the navigation links
*
* @param string $feed the feed to get
* @param string $what what kind of articles
* @param string $when date
* @param int $start starting number
* @param int $limit how many articles to show
*
* @return string
*/
function fof_get_nav_links($feed=null, $what="new", $when=null, $start=null, $limit=null)
{
$string = "";
if (!is_null($when) && $when != "") {
if ($when == "today") {
$whendate = date("Y/m/d", time() - (FOF_TIME_OFFSET * 60 * 60));
} else {
$whendate = $when;
}
$begin = strtotime($whendate);
$begin = $begin + (FOF_TIME_OFFSET * 60 * 60);
$end = $begin + (24 * 60 * 60);
$tomorrow = date("Y/m/d", $begin + (24 * 60 * 60));
$yesterday = date("Y/m/d", $begin - (24 * 60 * 60));
$string .= "<a href=\"view.php?feed=$feed&what=$what&when=$yesterday&how=$how&howmany=$howmany\">[« $yesterday]</a> ";
if ($when != "today") {
$string .= "<a href=\"view.php?feed=$feed&what=$what&when=today&how=$how&howmany=$howmany\">[today]</a> ";
}
if ($when != "today") {
$string .= "<a href=\"view.php?feed=$feed&what=$what&when=$tomorrow&how=$how&howmany=$howmany\">[$tomorrow »]</a> ";
}
}
if (is_numeric($start)) {
if (!is_numeric($limit)) {
$limit = FOF_HOWMANY;
}
$earlier = $start + $limit;
$later = $start - $limit;
$string .= "<a href=\"view.php?feed=$feed&what=$what&when=$when&how=paged&which=$earlier&howmany=$limit\">[« previous $limit]</a> ";
if ($later >= 0) {
$string .= "<a href=\"view.php?feed=$feed&what=$what&when=$when&how=paged&howmany=$limit\">[current items]</a> ";
}
if ($later >= 0) {
$string .= "<a href=\"view.php?feed=$feed&what=$what&when=$when&how=paged&which=$later&howmany=$limit\">[next $limit »]</a> ";
}
}
return $string;
}
/**
* Performs the workhorse function of makimg simpler SQL queries and returning an array of rows
*
* @param string $sql the sql to be executed
* @param int $live whether we are getting error messages for sql queries
*
* @return array
*/
function fof_do_query($sql, $live=0)
{
global $fof_connection, $fof_query_log;
if (defined('FOF_QUERY_LOG') && FOF_QUERY_LOG) {
list($usec, $sec) = explode(" ", microtime());
$t1 = (float)$sec + (float)$usec;
}
#echo "SQL:: " . $sql . " ::SQL<br/>";
$result = mysql_query($sql, $fof_connection);
if (defined('FOF_QUERY_LOG') && FOF_QUERY_LOG) {
list($usec, $sec) = explode(" ", microtime());
$t2 = (float)$sec + (float)$usec;
$elapsed = $t2 - $t1;
$fof_query_log .= "[$sql]: $elapsed\n";
}
if ($live) {
return $result;
} else {
if (mysql_errno()) {
die( _("Cannot query database.") . " " . _("Have you run") . " <a href=\"install.php\"><code>install.php</code></a>? " . _("MySQL says") . ": <b>". mysql_error() . "</b>");
}
return $result;
}
}
/**
* Get the age of the RSS feed
*
* @param string $url the feed's url
*
* @return int
*/
function fof_rss_age($id)
{
global $FOF_ITEM_TABLE;
//sha or md5?
//$filename = FOF_CACHE_DIR . "/" . md5($url) . '.spc';
//if (file_exists($filename)) {
// // find how long ago the file was added to the cache
// // and whether that is longer then MAX_AGE
// $mtime = filemtime($filename);
// $age = time() - $mtime;
// return $id;
//} else {
// return FOF_MAX_INT;
//}
//given the id of a feed, look up the most recent article and return it
$sql = "SELECT $FOF_ITEM_TABLE.`timestamp` FROM $FOF_ITEM_TABLE where $FOF_ITEM_TABLE.`feed_id`=".$id." ORDER BY $FOF_ITEM_TABLE.`timestamp` DESC LIMIT 1;";
$row = mysql_fetch_array(fof_do_query($sql));
$latest_time = strtotime("now") - strtotime($row['timestamp']);
#echo "<b>$latest_time</b> $sql</br>";
return $latest_time;
}
/**
* Gets an RSS feed given an html url
*
* @param string $html the url of the site
* @param string $location another url of the site
*
* @return $bool
*/
function fof_getRSSLocation($html, $location)
{
if (!$html or !$location) {
return false;
} else {
//search through the HTML, save all <link> tags
// and store each link's attributes in an associative array
preg_match_all('/<link\s+(.*?)\s*\/?>/si', $html, $matches);
$links = $matches[1];
$final_links = array();
$link_count = count($links);
for ($n=0; $n<$link_count; $n++) {
$attributes = preg_split('/\s+/s', $links[$n]);
foreach ($attributes as $attribute) {
$att = preg_split('/\s*=\s*/s', $attribute, 2);
if (isset($att[1])) {
$att[1] = preg_replace('/([\'"]?)(.*)\1/', '$2', $att[1]);
$final_link[strtolower($att[0])] = $att[1];
}
}
$final_links[$n] = $final_link;
}
//now figure out which one points to the RSS file
for ($n=0; $n<$link_count; $n++) {
if (strtolower($final_links[$n]['rel']) == 'alternate') {
if (strtolower($final_links[$n]['type']) == 'application/rss+xml') {
$href = $final_links[$n]['href'];
}
if (!$href and strtolower($final_links[$n]['type']) == 'text/xml') {
//kludge to make the first version of this still work
$href = $final_links[$n]['href'];
}
if ($href) {
if (strstr($href, "http://") !== false) { //if it's absolute
$full_url = $href;
} else { //otherwise, 'absolutize' it
$url_parts = parse_url($location);
//only made it work for http:// links. Any problem with this?
$full_url = "http://$url_parts[host]";
if (isset($url_parts['port'])) {
$full_url .= ":$url_parts[port]";
}
if ($href{0} != '/') { //it's a relative link on the domain
$full_url .= dirname($url_parts['path']);
if (substr($full_url, -1) != '/') {
//if the last character isn't a '/', add it
$full_url .= '/';
}
}
$full_url .= $href;
}
return $full_url;
}
}
}
return false;
}
}
/**
* Print the link in the article, given the $row
*
* @param array $row the row that is the item that will be rendered
*
* @return string
*/
function fof_render_feed_link($row)
{
$link = $row['link'];
$description = htmlspecialchars($row['description']);
$title = htmlspecialchars($row['title']);
$url = $row['url'];
$s = "<b><font class=\"feed_title\"><a target=\"_blank\" class=\"item_title\" href=\"$link\" title=\"$description\">$title</a></font></b> ";
//$s .= "<a href=\"$url\"><img class=\"valign\" src=\"rss.gif\" border=\"0\"></a>";
return $s;
}
/**
* Changes opml text into an array of URLs
*
* @param string $opml the text of the whole OPML being imprted
*
* @return array
*/
function fof_opml_to_array($opml)
{
$rx = "/xmlurl=\"(.*?)\"/mi";
if (preg_match_all($rx, $opml, $m)) {
for ($i = 0; $i < count($m[0]); $i++) {
$r[] = $m[1][$i];
}
}
return $r;
}
/**
* Subscribe someone to a feed
*
* @param string $id the user id that will subscribe to a feed
*
* @return bool
*/
function subscribe_user($id)
{
global $FOF_SUBSCRIPTION_TABLE;
$sql = "INSERT INTO `" . $FOF_SUBSCRIPTION_TABLE . "` (`feed_id`,`user_id`) VALUES (" . $id . ", " . current_user() . ")";
fof_do_query($sql);
echo "<font color=\"green\"><b>" . _("User Subscribed") . ".</b></font><br />";
return true;
}
/**
* Checks if someone is already subscribed to a feed
*
* @param string $id the user id
*
* @return $bool
*/
function user_is_subscribed($id)
{
// checks to see if a user is subscribed to a particular feed
global $FOF_SUBSCRIPTION_TABLE;
//$id = $row['id'];
$sql = "select * from $FOF_SUBSCRIPTION_TABLE WHERE feed_id=$id AND user_id=" . current_user();
if (mysql_fetch_array($result = fof_do_query($sql))) {
return true;
} else {
return false;
}
}
/*
function add_feed_link($name, $url)
{
echo "<a href=\"";
echo "http://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["SCRIPT_NAME"]) . "monkeychow/add.php?rss_url=" . urlencode($url);
echo "\">$name</a><br />";
}
*/
/**
* Checks if the user is new so that we can display a list of recommended feeds
*
* @return bool
*/
function user_is_new()
{
global $FOF_SUBSCRIPTION_TABLE;