root/branches/multiuser/feed.php

Revision 1759, 49.1 kB (checked in by mdodoo, 2 years ago)

Lots of things are still not working, but I think this code is better than what was currently committed ([1639]
should have been reverted, and the person who committed should have had their SVN access pulled, for example).
Created this by grabbing the trunk code and then manually inserting the MU branch's changes in. This is probably
not usable in an actual installation (no support for creating new user accounts yet, for example), but patches are
welcome.

Not sure why I write so much here - I am not sure anyone other than my fellow devs actually read them...

  • Property svn:eol-style set to native
  • Property svn:eolstyle set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2###############################################################################
3# Gregarius - A PHP based RSS aggregator.
4# Copyright (C) 2003 - 2006 Marco Bonetti
5#
6###############################################################################
7# This program is free software and open source software; you can redistribute
8# it and/or modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the License,
10# or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15# more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
20# http://www.gnu.org/licenses/gpl.html
21#
22###############################################################################
23# E-mail:      mbonetti at gmail dot com
24# Web page:    http://gregarius.net/
25#
26###############################################################################
27
28
29
30require_once('init.php');
31rss_require('extlib/rss_fetch.inc');
32
33define ('ACT_NAV_PREV_PREFIX','&larr;&nbsp;');
34define ('ACT_NAV_SUCC_POSTFIX','&nbsp;&rarr;');
35
36
37
38
39// Show unread items on the front page?
40// default to the config value, user can override this via a cookie
41$show_what = (getConfig('rss.output.frontpage.mixeditems') ?
42        SHOW_READ_AND_UNREAD : SHOW_UNREAD_ONLY);
43
44if (array_key_exists(SHOW_WHAT,$_POST)) {
45    $show_what = $_POST[SHOW_WHAT];
46    $period = time()+COOKIE_LIFESPAN;
47    setcookie(SHOW_WHAT, $show_what , $period, getPath());
48}
49elseif (array_key_exists(SHOW_WHAT,$_COOKIE)) {
50    $show_what = $_COOKIE[SHOW_WHAT];
51}
52
53
54
55$y=$m=$d=0;
56if (
57    getConfig('rss.output.usemodrewrite')
58    && array_key_exists('channel',$_REQUEST)
59    // this is nasty because a numeric feed title could break it
60    && !is_numeric($_REQUEST['channel'])
61) {
62        $sqlid = preg_replace('#'.RSS_URI_SEPARATOR.'#','_',
63                sanitize($_REQUEST['channel'] , RSS_SANITIZER_SIMPLE_SQL )
64                );
65
66    $sql = "select c.id from " . getTable("channels") 
67      . " c left join " .getTable('channels2user') 
68      ." c2u on (c.id=c2u.fkcid) where title like '$sqlid'";
69    if (hidePrivate()) {
70        $sql .=" and c2u.flgprivate=0 ";
71    }
72    // don't hide deprecated items becuase we want items of deprecated feeds to be accessible
73    // $sql .= " and c2u.flgdeleted=0 ";
74
75    $res =  rss_query( $sql );
76    //echo $sql;
77    if ( rss_num_rows ( $res ) >= 1) {
78        list($cid) = rss_fetch_row($res);
79    } else {
80        $cid = "";
81
82        // is this a folder?
83        $sql = "select c.id, c.parent from ". getTable('channels')." c left join "
84          . getTable('channels2user') . " c2u on (c.id=c2u.fkcid) "
85          ." inner join " . getTable('folders') . " f on f.id = c.parent "
86          ." where f.name like '$sqlid' and f.id > 0";
87
88        if (hidePrivate()) {
89            $sql .=" and c2u.flgprivate=0 ";
90        }
91        $sql .= " and c2u.flgdeleted=0 ";
92
93        $res = rss_query( $sql );
94        if ( rss_num_rows ( $res ) > 0) {
95            $cids = array();
96            while (list ($cid__,$fid__) = rss_fetch_row($res)) {
97                $cids[] = $cid__;
98                $fid = $fid__;
99            }
100        } else {
101            // maybe it's a virtual folder?
102            $sql = "select c.id, m.tid from ". getTable('channels')." c "
103                   . "inner join " . getTable('metatag') . " m on m.fid = c.id " 
104                   . "inner join " . getTable('tag') . " t on m.tid = t.id "
105                   . "where m.ttype = 'channel' and t.tag like '$sqlid'";
106
107            if (hidePrivate()) {
108                $sql .=" and not(c.mode & " . RSS_MODE_PRIVATE_STATE .") ";
109            }
110            $sql .= " and not(c.mode & " .  RSS_MODE_DELETED_STATE .") ";
111
112            $res = rss_query( $sql );
113            if ( rss_num_rows ( $res ) > 0) {
114                $cids = array();
115                while (list ($cid__,$vfid__) = rss_fetch_row($res)) {
116                    $cids[] = $cid__;
117                    $vfid = $vfid__;
118                }
119            }
120        }
121    }
122
123    // date ?
124    if ($cid != ""
125            && array_key_exists('y',$_REQUEST) && $_REQUEST['y'] != "" && is_numeric($_REQUEST['y'])
126            && array_key_exists('m',$_REQUEST) && $_REQUEST['m'] != "" && is_numeric($_REQUEST['m'])) {
127        $y = (int) $_REQUEST['y'];
128        if ($y < 1000)
129            $y+=2000;
130
131        $m =  (int)$_REQUEST['m'];
132        if ($m > 12) {
133            $m = date("m");
134        }
135
136        $d =  (int)$_REQUEST['d'];
137        if ($d > 31) {
138            $d = date("d");
139        }
140    }
141
142
143
144    // lets see if theres an item id as well
145    $iid = "";
146    if ($cid != "" && array_key_exists('iid',$_REQUEST) && $_REQUEST['iid'] != "") {
147        $sqlid =  preg_replace("/[^A-Za-z0-9\.]/","%",$_REQUEST['iid']);
148        $sql = "select id from " .getTable("item") ." i where i.title like '$sqlid' and i.cid=$cid";
149        if ($m > 0 && $y > 0) {
150            $sql .= " and month(ifnull(i.pubdate,i.added))= $m "
151                    ." and year(ifnull(i.pubdate, i.added))= $y ";
152
153            if ($d > 0) {
154                $sql .= " and dayofmonth(ifnull(i.pubdate,i.added))= $d ";
155            }
156
157        }
158
159        if (hidePrivate()) {
160            $sql .=" and not(i.unread & " . RSS_MODE_PRIVATE_STATE .") ";
161        }
162
163        $sql .=" and not(i.unread & " . RSS_MODE_DELETED_STATE  .") ";
164        $sql .=" order by i.added desc, i.id asc";
165
166        $res =  rss_query( $sql );
167
168        if ( rss_num_rows ( $res ) >0) {
169            list($iid) = rss_fetch_row($res);
170        }
171    }
172    // no mod rewrite: ugly but effective
173}
174elseif (array_key_exists('channel',$_REQUEST) || array_key_exists('folder',$_REQUEST) || array_key_exists('vfolder',$_REQUEST)) {
175    $cid= (array_key_exists('channel',$_REQUEST))?sanitize($_REQUEST['channel'],RSS_SANITIZER_NUMERIC):"";
176    $iid= (array_key_exists('iid',$_REQUEST))?sanitize($_REQUEST['iid'],RSS_SANITIZER_NUMERIC):"";
177    $fid= (array_key_exists('folder',$_REQUEST))?sanitize($_REQUEST['folder'],RSS_SANITIZER_NUMERIC):"";
178    $vfid= (array_key_exists('vfolder',$_REQUEST))?sanitize($_REQUEST['vfolder'],RSS_SANITIZER_NUMERIC):"";
179       
180    $y= (array_key_exists('y',$_REQUEST))?sanitize($_REQUEST['y'],RSS_SANITIZER_NUMERIC):"0";
181    $m= (array_key_exists('m',$_REQUEST))?sanitize($_REQUEST['m'],RSS_SANITIZER_NUMERIC):"0";
182    $d= (array_key_exists('d',$_REQUEST))?sanitize($_REQUEST['d'],RSS_SANITIZER_NUMERIC):"0";
183
184    if ($fid) {
185        $sql = "select c.id from ". getTable('channels')." c "
186               ." where c.parent=$fid and c.parent > 0";
187        $sql .= " and not(c.mode & " .  RSS_MODE_DELETED_STATE .") ";
188
189        if (hidePrivate()) {
190            $sql .=" and not(c.mode & " . RSS_MODE_PRIVATE_STATE .") ";
191        }
192        $res = rss_query( $sql );
193
194        if ( rss_num_rows ( $res ) > 0) {
195            $cids = array();
196            while (list ($cid__) = rss_fetch_row($res)) {
197                $cids[] = $cid__;
198            }
199        }
200    }
201    elseif ($vfid) {
202        $sql = "select c.id, m.tid from ". getTable('channels')." c "
203               . "inner join " . getTable('metatag') . " m on c.id = m.fid "
204               . "inner join " . getTable('tag') . " t on m.tid = t.id "
205               . "where m.ttype = 'channel' ";
206        // $vfid can be numeric (t.id) or alphabetic (t.tag)
207        if(is_numeric($vfid)) {
208            $sql .= "and t.id = $vfid";
209        } else {
210            $sql .= "and t.tag like '$vfid'";
211        }
212        $sql .= " and not(c.mode & " .  RSS_MODE_DELETED_STATE .") ";
213
214        if (hidePrivate()) {
215            $sql .=" and not(c.mode & " . RSS_MODE_PRIVATE_STATE .") ";
216        }
217        $res = rss_query( $sql );
218
219        if ( rss_num_rows ( $res ) > 0) {
220            $cids = array();
221            while (list ($cid__,$vfid__) = rss_fetch_row($res)) {
222                $cids[] = $cid__;
223                $vfid = $vfid__;
224            }
225        }
226    }
227    elseif ($cid) {
228        if (hidePrivate()) {
229            $sql = "select id from ". getTable('channels')." where id=$cid ";
230            $sql .=" and not(mode & " . RSS_MODE_PRIVATE_STATE .") ";
231            list ($cid) = rss_fetch_row(rss_query($sql));
232        }
233    }
234}
235elseif (
236    array_key_exists('y',$_REQUEST) && $_REQUEST['y'] != "" && is_numeric($_REQUEST['y'])
237    && array_key_exists('m',$_REQUEST) && $_REQUEST['m'] != "" && is_numeric($_REQUEST['m'])
238    && array_key_exists('d',$_REQUEST) && $_REQUEST['d'] != "" && is_numeric($_REQUEST['d'])
239)   {
240
241    $y = (int) sanitize($_REQUEST['y'],RSS_SANITIZER_NUMERIC);
242    if ($y < 1000)
243        $y+=2000;
244
245    $m =  (int) sanitize($_REQUEST['m'],RSS_SANITIZER_NUMERIC);
246    if ($m > 12) {
247        $m = date("m");
248    }
249
250    $d =  (int) sanitize($_REQUEST['d'],RSS_SANITIZER_NUMERIC);
251    if ($d > 31) {
252        $d = date("d");
253    }
254    $iid = $cid  = null;
255}
256
257
258
259
260// If we have no channel-id something went terribly wrong.
261// Send a 404.
262if (
263    // channel id:
264    (
265        // not set
266        !isset($cid)    ||
267        // ...or empty
268        $cid == ""              ||
269        // or not numeric while mod_rewrite is off
270        (
271            !getConfig('rss.output.usemodrewrite') && !is_numeric($cid)
272        )
273    )
274
275    &&
276    // folder id
277    (
278        // not set
279        !isset($cids) ||
280        // not an array of ids
281        !is_array($cids) ||
282        // zero elements
283        !count($cids)
284    )
285
286    &&
287    // virtual folder id
288    (!isset($vfid))
289
290    &&
291    // date?
292    ($d == 0 && $m == 0 && $y == 0)
293) {
294        rss_404();
295        exit;
296}
297//echo ("cid=".(isset($cid)?"$cid":"") . " fid=" . (isset($fid)?"$fid":""));
298
299if (!hidePrivate() && array_key_exists ('metaaction', $_REQUEST)) {
300
301    if (array_key_exists('markreadids',$_POST)) {
302        $IdsToMarkAsRead = explode(",",rss_real_escape_string($_POST['markreadids']));
303        //var_dump($IdsToMarkAsRead);
304    } else {
305        $IdsToMarkAsRead = array();
306    }
307    switch ($_REQUEST['metaaction']) {
308
309    case  'ACT_MARK_CHANNEL_READ':
310
311        /** mark channel as read **/
312        $sql = "update " .getTable("i2u")
313               ." set flgunread = 0 where i2u.fkcid=$cid";
314        if (hidePrivate()) {
315            $sql .= " and i2u.flgprivate =0";
316        }
317        if (count($IdsToMarkAsRead)) {
318            $sql .= " and id in (" . implode(',',$IdsToMarkAsRead) .")";
319        }
320        rss_query($sql);
321
322        rss_invalidate_cache();
323
324        /* Redirect! If this feed has more unread items, self-redirect */
325
326        $sql = "select count(*) from " .getTable("item2user") . " i2u "
327                ." where i2u.flgunread=1 "
328                ." and i2u.fkcid=$cid"
329                ." and i2u.flgdeleted=0 ";
330        if (hidePrivate()) {
331            $sql .=" and i2u.flgprivate =0";
332        }
333        list($hasMoreUnreads) = rss_fetch_row(rss_query($sql));
334
335
336        //more unread items in this feed?
337        if ($hasMoreUnreads) {
338            $next_unread_id=$cid;
339
340        } else {
341
342            /*
343                Find where we should redirect
344                 - The next feed in the list with unread items, or, failing that:
345                 - The first feed in the list with unread items, or, faling that:
346                 - The main page
347            */
348
349            // 1: build a list of all feeds:
350            $feeds = array();
351            $sql = "select c.id from " . getTable('channels') . " c "
352                   . "inner join " . getTable('folders') . " f on c.parent=f.id "
353                   ." where not (c.mode & " . RSS_MODE_DELETED_STATE .") "
354                   ;
355            if (hidePrivate()) {
356                $sql .= " and not (c.mode & " . RSS_MODE_PRIVATE_STATE . ") ";
357            }
358            if (getConfig('rss.config.absoluteordering')) {
359                $sql .= " order by f.position asc, c.position asc";
360            } else {
361                $sql .=" order by f.name asc, c.title asc";
362            }
363            $res = rss_query($sql);
364            while (list($cid__) = rss_fetch_row($res)) {
365                $feeds[$cid__] = 0;
366            }
367
368            // 2: Get the unread count for each feed:
369            $sql = "select fkcid, count(*) from " .getTable('item2user')
370                   ." i2u where i2u.flgunread=1 "
371                   ." and i2u.flgdeletd=0";
372            if (hidePrivate()) {
373                $sql .= " and i2u.flgprivate=0 ";
374            }
375            $sql .= " group by i2u.fkcid";
376            $res = rss_query($sql);
377            while (list($cid__,$uc__) = rss_fetch_row($res)) {
378                // this makes sure only the feeds that were gathered in the
379                // last query are put into this array.. fixes #305
380                if(array_key_exists($cid__, $feeds)) {
381                    $feeds[$cid__] = $uc__;
382                }
383            }
384
385            // 3: iterate over the feeds and see where we should redirect.
386            $found = false;
387            $first_unread_id = $next_unread_id = 0;
388            foreach($feeds as $cid__ => $cnt) {
389                // reached the feed we're coming from?
390                if ($cid == $cid__) {
391                    $found = true;
392                }
393                // if not yet, get a hold of the first in the list with unread items
394                if ($cnt && !$first_unread_id) {
395                    $first_unread_id = $cid__;
396                }
397
398                // passed the previous feed? We got a winner!
399                if ($cnt && $found) {
400                    $next_unread_id = $cid__;
401                    break;
402                }
403            }
404
405            // found none after the previous feed, but there is on on top
406            if (!$next_unread_id && $first_unread_id) {
407                $next_unread_id = $first_unread_id;
408            }
409        }
410
411        //redirect
412        if (!$next_unread_id) {
413            rss_redirect();
414        } else {
415            $cid = $next_unread_id;
416        }
417
418        break;
419
420        // folder
421    case 'ACT_MARK_FOLDER_READ':
422        $fid = sanitize($_REQUEST['folder'],RSS_SANITIZER_NUMERIC);
423        $rs  = rss_query("select id from " .getTable('channels') . " where parent=$fid");
424        $cids_ = array();
425        while(list($cid_) = rss_fetch_row($rs)) {
426                $cids_[]=$cid_;
427        }
428       
429       
430        $sql = "update " .getTable('item2user')
431               . " set unread = 0 "
432               . " where fkcid  in (" .implode(',', $cids_) . ") ";
433                  unset($cids_);
434        if (count($IdsToMarkAsRead)) {
435            $sql .= " and fkiid in (" . implode(',',$IdsToMarkAsRead) .")";
436        }
437
438        //die($sql);
439        rss_query($sql);
440
441        rss_invalidate_cache();
442
443        $next_fid = $first_fid = 0;
444        $found = false;
445        $res = rss_query( " select id from " .getTable('folders') ." f order by "
446                          .(getConfig('rss.config.absoluteordering')?" f.position asc":"f.name asc")
447                        );
448
449        while (list($fid__) = rss_fetch_row($res)) {
450            if($fid__ == $fid) {
451                $found = true;
452            }
453                       
454                        if( $found || !$first_fid ) {
455                                $sql = "select count(*) from " . getTable('item2user') . " i2u "
456                                           . "inner join ". getTable('channels') ." c on i2u.fkcid = c.id"
457                                           ." where i2u.flgunread=1 and c.parent = $fid__"
458                                           ." and i2u.fkuid=" . rss_user_id();
459                                if (hidePrivate()) {
460                                        $sql .= " and i2u.flgprivate=0 ";
461                                }
462       
463                                list($c) = rss_fetch_row(rss_query($sql));
464                                //echo "$fid__ -> $c\n";
465
466                                if ($c > 0) {
467                                        if (!$first_fid)
468                                                $first_fid = $fid__;
469                                        if ($found) {
470                                                $next_fid = $fid__;
471                                                break;
472                                        }
473                                }
474                        }
475        }
476               
477                if( !$next_fid && $first_fid )
478                        $next_fid = $first_fid;
479
480        if ( $next_fid ) {
481            $fid = $next_fid;
482            $sql = "select id from " . getTable('channels') ." where parent=$fid";
483            $res = rss_query($sql);
484            $cids = array();
485            while ( list($cid__) = rss_fetch_row($res)) {
486                $cids[] = $cid__;
487            }
488        } else {
489            rss_redirect();
490        }
491        break;
492        // virtual folder - code extremely similar to __('Mark These Items as Read')
493    case 'ACT_MARK_VFOLDER_READ':
494        $vfid = sanitize($_REQUEST['vfolder'],RSS_SANITIZER_NUMERIC);
495       
496        $rs  = rss_query(
497                "select fid from " .getTable('metatag') . "m  "
498                ." where m.ttype = 'channel' and m.tid = $vfid");
499        $fids_ = array();
500        while(list($fid_) = rss_fetch_row($rs)) {
501                $fids_[]=$fid_;
502        }
503       
504        $sql = "update " .getTable('item2user') 
505          . " set unread = 0 "
506          . " where fkcid in (" .implode(',',$fids_). ")"
507          . " and fkuid=". rss_user_id();
508         
509
510        if (count($IdsToMarkAsRead)) {
511            $sql .= " and fkiid in (" . implode(',',$IdsToMarkAsRead) .")";
512        }
513
514        rss_query($sql);
515
516        rss_invalidate_cache();
517
518        // find next virtual folder to redirect to
519        $next_vfid = $first_vfid = 0;
520        $found = false;
521        $res = rss_query("select distinct tid from " .getTable('metatag') ." m "
522                                . "inner join" . getTable('tag') ."t on m.tid = t.id order by t.tag asc");
523        while (list($tid__) = rss_fetch_row($res)) {
524            if ($tid__ == $vfid) {
525                $found = true;
526            }
527                       
528                        if( $found || !$first_vfid ) {
529                                // check for unread items in next virtual folder
530                                $sql = "select count(distinct(i.fkiid)) as cnt from "
531                                           .getTable('metatag') ." left join "
532                                           .getTable('item2user') . "i2u on (i2u.fkcid=fid) "
533                                           ."where tid = $tid__ and ttype = 'channel' "
534                                           ." and i2u.flgunread=1 "
535                                           ." and i2u.fkuid=" .rss_user_id()
536                                           ." and i2u.flgdeleted=0 ";
537                                if (hidePrivate()) {
538                                        $sql .= " and i2u.flgprivate=0 ";
539                                }
540                                list($c) = rss_fetch_row(rss_query($sql));
541                                if ($c > 0) {
542                                        if (!$first_vfid)
543                                                $first_vfid = $tid__;
544                                        if ($found) {
545                                                $next_vfid = $tid__;
546                                                break;
547                                        }
548                                }
549                        }
550        }
551               
552                if( !$next_vfid && $first_vfid )
553                        $next_vfid = $first_vfid;
554
555        if($next_vfid) {
556            $vfid = $next_vfid;
557            $sql = "select distinct(fid) from " . getTable('metatag') . " where tid = $vfid";
558            $res = rss_query($sql);
559            $cids = array();
560            while(list($cid__) = rss_fetch_row($res)) {
561                $cids[] = $cid__;
562            }
563        } else {
564            rss_redirect();
565        }
566        break;
567    }
568
569        if( array_key_exists ('redirectto', $_REQUEST)) {
570                header("Location: " .
571                           $_REQUEST['redirectto']);
572                exit();
573        }
574}
575//echo ("cid=".(isset($cid)?"$cid":"") . " fid=" . (isset($fid)?"$fid":""));
576assert(
577    (isset($cid) && is_numeric($cid)) ||
578    (isset($fid) && isset($cids) && is_array($cids) && count($cids)) ||
579    (isset($vfid) && isset($cids) && is_array($cids) && count($cids)) ||
580    (!isset($cid) && ($y || $m))
581);
582
583$itemFound = true;
584if ($iid != "" && !is_numeric($iid)) {
585    //item was deleted
586    $itemFound = false;
587    $iid = "";
588}
589
590// make sure the variables passed to makeName are initialized
591if (!isset($fid)) {
592    $fid=null;
593}
594if (!isset($vfid)) {
595    $vfid=null;
596}
597if (!isset($cids)) {
598    $cids=null;
599}
600//precompute the navigation hints, which will be passed to the header as <link>s
601$links = NULL;
602if (($cid || $fid || $vfid || ($y && $m && $d)) && ($nv = makeNav($cid,$iid,$y,$m,$d,$fid,$vfid,$cids)) != null) {
603    list($prev,$succ, $up) = $nv;
604    $links =array();
605    if ($prev != null) {
606        $links['prev'] =
607            array('title' => $prev['lbl'],
608                  'href' => $prev['url']);
609    }
610    if ($succ != null) {
611        $links['next'] =
612            array(
613                'title' => $succ['lbl'],
614                'href' => $succ['url']);
615    }
616    if ($up != null) {
617        $links['up'] =
618            array(
619                'title' => $up['lbl'],
620                'href' => $up['url']
621            );
622    }
623}
624
625
626
627if ($iid == "") {
628    $cidfid = array();
629    // "channel / folder mode"
630    $prepend = false;
631    if ($cid) {
632        $res = rss_query("select title,icon from " . getTable("channels") ." where id = $cid");
633        list($title,$icon) = rss_fetch_row($res);
634        if (isset($y) && $y > 0 && $m > 0 && $d == 0) {
635            $dtitle =  (" " . TITLE_SEP ." " . rss_locale_date('%B %Y',mktime(0,0,0,$m,1,$y),false));
636            $prepend=true;
637        }
638        elseif (isset($y) && $y > 0 && $m > 0 && $d > 0) {
639            $prepend=true;
640            $dtitle =  (" " . TITLE_SEP ." " . rss_locale_date('%B %e, %Y',mktime(0,0,0,$m,$d,$y),false));
641        }
642        else {
643            $dtitle ="";
644        }
645        $cidfid ['cid']=$cid;
646        $cidfid ['fid']=null;
647    }
648    elseif($fid) {
649        list($title) = rss_fetch_row( rss_query("select name from " . getTable('folders') . " where id = $fid") );
650        $dtitle ="";
651        $cidfid ['cid']=null;
652        $cidfid ['fid']=$fid;
653    }
654    elseif($vfid) {
655        list($title) = rss_fetch_row(rss_query("select tag from " . getTable('tag') . " where id = $vfid"));
656        $dtitle = "";
657        $cidfid ['cid']=null;
658        $cidfid ['fid']=null;
659    }
660    elseif($y && $m && $d) {
661        $dtitle =  ( rss_locale_date('%B %e, %Y',mktime(0,0,0,$m,$d,$y),false));
662        $cidfid ['cid']=null;
663        $cidfid ['fid']=null;
664        $title ="";
665    }
666    else {
667        $dtitle ="";
668        $title = "";
669        $cidfid ['cid']=null;
670        $cidfid ['fid']=null;
671    }
672
673
674    if ($links) {
675        foreach ($links as $rel => $val) {
676            if (($lbl = $links[$rel]['title']) != "" && $prepend) {
677                $links[$rel]['title'] = htmlentities( $title,ENT_COMPAT,"UTF-8" ) . " " . TITLE_SEP ." " . $lbl;
678            }
679            elseif (($lbl = $links[$rel]['title']) != "" && !$prepend) {
680                $links[$rel]['title'] = htmlentities( $lbl, ENT_COMPAT,"UTF-8" );
681            }
682            elseif ($title) {
683                $links[$rel]['title'] = htmlentities( $title,ENT_COMPAT,"UTF-8" );
684            }
685        }
686    }
687    //rss_header( rss_htmlspecialchars( $title ) . $dtitle,0,$cidfid,"", HDR_NONE, $links);
688    $GLOBALS['rss'] -> header = new Header( rss_htmlspecialchars( $title ) . $dtitle,0,$cidfid,"", HDR_NONE, $links);
689} else {
690    // "item mode"
691    $res = rss_query ("select c.title, c.icon, i.title from " . getTable("channels") ." c "
692                      . "inner join " . getTable("item") ." i on i.cid=c.id "
693                      . "inner join ". getTable('item2user') ." i2u on i2u.fkiid=i.id "
694                      ."where c.id = $cid and i.id=$iid"
695                      ." and i2u.flgdeleted=0 "
696                     );
697
698    list($title,$icon,$ititle) = rss_fetch_row($res);
699
700    $GLOBALS['rss'] -> header = new Header(
701                                    rss_htmlspecialchars($title)
702                                    . " " . TITLE_SEP ." "
703                                    .  rss_htmlspecialchars($ititle),
704                                    0,null,"", HDR_NONE, $links
705                                );
706}
707
708
709$GLOBALS['rss'] -> feedList = new FeedList($cid);
710
711if (array_key_exists('dbg',$_GET)) {
712    require_once('cls/debugfeed.php');
713    $dbg = new DebugFeed($cid);
714    $GLOBALS['rss'] -> appendContentObject($dbg);
715
716} else {
717    if ($cid && !(isset($cids) && is_array($cids) && count($cids))) {
718        $cids = array($cid);
719    }
720    if(!isset($vfid))
721        $vfid = null;
722    doItems($cids,$fid,$vfid,$title,$iid,$y,$m,$d,(isset($nv)?$nv:null),$show_what);
723}
724
725$GLOBALS['rss'] -> renderWithTemplate('index.php','items');
726
727function doItems($cids,$fid,$vfid,$title,$iid,$y,$m,$d,$nv,$show_what) {
728
729    $do_show=$show_what;
730    //should we honour unread-only?
731    if ($show_what == SHOW_UNREAD_ONLY) {
732
733        // permalink will always be printed
734        if ($iid != "") {
735            $do_show = SHOW_READ_AND_UNREAD;
736        } else {
737            // archives, folders, channels
738            $sql = "select count(*) from " . getTable('item2user') 
739                . " i2u left join ".getTable('item')." i on (i2u.fkiid=i.id) where"
740                   ."  i2u.flgunread=1 and i2u.flgdeleted=0";
741
742            //archive?
743            if ($m > 0 && $y > 0) {
744                $sql .= " and month(ifnull(pubdate,added))= $m "
745                        ." and year(ifnull(pubdate, added))= $y ";
746                if ($d > 0) {
747                    $sql .= " and dayofmonth(ifnull(pubdate,added))= $d ";
748                }
749            }
750            if ($cids && count($cids)) {
751                $sql .= " and i.cid in (".implode(',',$cids).")";
752            }
753            list($unreadCount) = rss_fetch_row(rss_query($sql));
754            if ($unreadCount == 0) {
755                $do_show = SHOW_READ_AND_UNREAD;
756            }
757
758        }
759    }
760
761    $items = new ItemList();
762    $severalFeeds = (($fid != null) || ($vfid != null));
763
764    if ($severalFeeds && !getConfig('rss.config.feedgrouping')) {
765        $sqlWhere = "(";
766        foreach ($cids as $cid) {
767            $sqlWhere .= " i.cid = $cid or ";
768        }
769        $sqlWhere .= " 1=0) ";
770        $hint = ITEM_SORT_HINT_MIXED;
771        if  ($do_show == SHOW_UNREAD_ONLY) {
772            $sqlWhere .= " and i2u.flgunread=1 ";
773            $hint = ITEM_SORT_HINT_UNREAD;
774        }
775
776        // how many items should we display in a folder view?
777        // default to numitemsonpage.
778        $cnt = getConfig('rss.output.frontpage.numitems');
779        // if that is set to zero, use itemsinchannelview times the number of feeds in the folder
780        if ($cnt == 0) {
781            $cnt = count($cids) * getConfig('rss.output.itemsinchannelview');
782        }
783        // should that be zero too, go for a fixed value
784        if ($cnt == 0) {
785            // arbitrary!
786            $cnt = 50;
787        }
788        $items -> populate($sqlWhere, "", 0, $cnt, $hint);
789
790    } else {
791        if (!isset($cids)) {
792            $cids = array(-1);
793        }
794        foreach ($cids as $cid) {
795            $hint = ITEM_SORT_HINT_MIXED;
796            if ($cid > -1) {
797                $sqlWhere = "i.cid = $cid";
798                if  ($do_show == SHOW_UNREAD_ONLY) {
799                    $sqlWhere .= " and i2u.flgunread=1 ";
800                    $hint = ITEM_SORT_HINT_UNREAD;
801                }
802            } else {
803                $sqlWhere = " 1 = 1 ";
804            }
805            if ($iid != "") {
806                $sqlWhere .= " and i.id=$iid";
807            }
808            if ($m > 0 && $y > 0) {
809                $sqlWhere .= " and month(ifnull(i.pubdate,i.added))= $m "
810                             ." and year(ifnull(i.pubdate, i.added))= $y ";
811
812                if ($d > 0) {
813                    $sqlWhere .= " and dayofmonth(ifnull(i.pubdate,i.added))= $d ";
814                }
815            }
816            if ( $m==0 && $y==0 ) {
817                $sqlLimit = getConfig('rss.output.itemsinchannelview');
818            } else {
819                $sqlLimit =  RSS_DB_MAX_QUERY_RESULTS;
820            }
821            /*
822            $sqlOrder = " order by i.unread & ".RSS_MODE_UNREAD_STATE." desc";
823            if(getConfig("rss.config.datedesc")){
824                $sqlOrder .= ", ts desc, i.id asc";
825            } else {
826                $sqlOrder .= ", ts asc, i.id asc";
827            }
828            */
829            $sqlOrder = "";
830            $items -> populate($sqlWhere,$sqlOrder,0, $sqlLimit, $hint, true);
831        }
832    }
833
834
835    if ($items -> unreadCount && $iid == "") {
836        $items -> preRender[] = array("showViewForm",$show_what);
837
838        if (!$severalFeeds) {
839            $items -> preRender[] = array("markReadForm",$cid);
840            $title .= " " .sprintf(__('<strong id="%s" style="%s">(%d unread)</strong>'), "ucnt","",$items -> unreadCount);
841        } else {
842            if(!$vfid) {
843                list($fid) = rss_fetch_row(rss_query('select parent from ' .getTable('channels') . 'where id = ' .$cids[0]));
844                $title .= " " .sprintf(__('<strong id="%s" style="%s">(%d unread)</strong>'), "ucnt","",$items -> unreadCount);
845                $items -> preRender[] = array("markFolderReadForm",$fid);
846            } else {
847                list($fid) = $vfid;
848                $title .= " " .sprintf(__('<strong id="%s" style="%s">(%d unread)</strong>'), "ucnt","",$items -> unreadCount);
849                $items -> preRender[] = array("markVirtualFolderReadForm",$vfid);
850            }
851        }
852    }
853
854
855
856    $items -> setTitle($title);
857    if ($severalFeeds) {
858        $items -> setRenderOptions(IL_NO_COLLAPSE | IL_FOLDER_VIEW);
859    }
860    elseif ($cid && $cid > -1) {
861        $items -> setRenderOptions(IL_CHANNEL_VIEW);
862    }
863    else {
864        $items -> setRenderOptions(IL_NO_COLLAPSE | IL_FOLDER_VIEW);
865    }
866
867    $items -> setRenderOptions(IL_TITLE_NO_ESCAPE);
868
869    if ($nv != null) {
870        list($prev,$succ,$up) = $nv;
871
872        $readMoreNav = "";
873        if($prev != null) {
874            $lbl = $prev['lbl'];
875            if (function_exists('mb_strlen') && function_exists('mb_substr') && mb_strlen($lbl) > 40) {
876                $lbl = mb_substr($lbl,0,37) . "...";
877            } elseif (strlen($lbl) > 40) {
878                $lbl = substr($lbl,0,37) . "...";
879            }
880            $readMoreNav .= "<a href=\"".$prev['url']."\" class=\"fl\">".ACT_NAV_PREV_PREFIX ."$lbl</a>\n";
881        }
882
883        if($succ != null) {
884            $lbl = $succ['lbl'];
885            if (function_exists('mb_strlen') && function_exists('mb_substr') && mb_strlen($lbl) > 40) {
886                $lbl = mb_substr($lbl,0,37) . "...";
887            } elseif (strlen($lbl) > 40) {
888                $lbl = substr($lbl,0,37) . "...";
889            }
890            $readMoreNav .= "<a href=\"".$succ['url']."\" class=\"fr\">$lbl".ACT_NAV_SUCC_POSTFIX."</a>\n";
891        }
892
893        if ($readMoreNav != "") {
894            $items->afterList = "<div class=\"readmore\">$readMoreNav"
895                                . "<hr class=\"clearer hidden\"/>\n</div>\n";
896        }
897    }
898    $GLOBALS['rss'] -> appendContentObject($items);
899
900}
901
902
903/**
904 * This function will return an array for the previous, next and up
905 * navigation elements, based on the current location
906 *
907 * @return: array (
908        ('prev'|'next'|'up')* => array (
909                 'y' => year of the prev,next,up item
910                 'm' => month of the prev,next,up item
911                 'd' => day of the prev,next,up item
912                 'cnt' => count of the prev,next,up items for this date
913                 'ts' => unix timestamp of the above
914                 'url' =>  precomputed uri for the link
915                 'lbl' => precomupted label to be used in the links
916        )
917 )
918 */
919function makeNav($cid,$iid,$y,$m,$d,$fid,$vfid,$cids) {
920
921    //echo "X-info: $cid,$iid,$y,$m,$d,$fid,$vfid,$cids";
922    $currentView = null;
923    $prev = $succ = $up = null;
924    if (isset($_REQUEST['channel'])) {
925        $escaped_title = preg_replace("/[^A-Za-z0-9\.]/","_",$_REQUEST['channel']);
926    } else {
927        $escaped_title = null;
928    }
929    // where are we anyway?
930    if ($y > 0 && $m > 0 && $d > 0) {
931        if ($iid != "") {
932            $currentView = 'item';
933        } else {
934            $currentView = 'day';
935        }
936    }
937    elseif ($y > 0 && $m > 0 && $d == 0) {
938        $currentView = 'month';
939    }
940    elseif ($cids) {
941        if ($fid) {
942            $currentView = "folder";
943        }
944        elseif ($vfid) {
945            $currentView = "cat";
946        }
947    }
948    elseif ($cid) {
949        $currentView = "feed";
950    }
951
952    if ($currentView) {
953
954        switch ($currentView) {
955        case 'month':
956        case 'day':
957
958            if ($currentView == 'day') {
959                $ts_p = mktime(23,59,59,$m,$d-1,$y);
960                $ts_s = mktime(0,0,0,$m,$d,$y);
961            }
962            elseif($currentView == 'month') {
963                $ts_p = mktime(0,0,0,$m+1,0,$y);
964                $ts_s = mktime(0,0,0,$m,1,$y);
965            }
966
967            $sql_succ = " select "
968                        ." UNIX_TIMESTAMP( ifnull(i.pubdate, i.added)) as ts_, "
969                        ." year( ifnull(i.pubdate, i.added)) as y_, "
970                        ." month( ifnull(i.pubdate, i.added)) as m_, "
971                        .(($currentView == 'day')?" dayofmonth( ifnull(i.pubdate, i.added)) as d_, ":"")
972                        ." count(*) as cnt_ "
973                        ." from " . getTable("item") . "i  where "
974                        ." UNIX_TIMESTAMP(ifnull(i.pubdate, i.added)) > $ts_s ";
975
976            if ($cid) {
977                $sql_succ .= " and cid=$cid ";
978            }
979
980
981            if (hidePrivate()) {
982                $sql_succ .=" and not(i.unread & " . RSS_MODE_PRIVATE_STATE .") ";
983            }
984
985            $sql_succ .= " group by y_,m_"
986                         .(($currentView == 'day')?",d_ ":"")
987                         ." order by ts_ asc limit 4";
988
989            $sql_prev = " select "
990                        ." UNIX_TIMESTAMP( ifnull(i.pubdate, i.added)) as ts_, "
991                        ." year( ifnull(i.pubdate, i.added)) as y_, "
992                        ." month( ifnull(i.pubdate, i.added)) as m_, "
993                        .(($currentView == 'day')?" dayofmonth( ifnull(i.pubdate, i.added)) as d_, ":"")
994                        ." count(*) as cnt_ "
995                        ." from " . getTable("item") ." i  where "
996                        ." UNIX_TIMESTAMP(ifnull(i.pubdate, i.added)) < $ts_p ";
997
998            if ($cid) {
999                $sql_prev .= " and cid=$cid ";
1000            }
1001
1002
1003            if (hidePrivate()) {
1004                $sql_prev .=" and not(i.unread & " . RSS_MODE_PRIVATE_STATE .") ";
1005            }
1006
1007            $sql_prev .= " group by y_,m_"
1008                         .(($currentView == 'day')?",d_ ":"")
1009                         ." order by ts_ desc limit 4";
1010
1011            //echo "<!-- $sql_prev -->\n";
1012            $res_prev = rss_query($sql_prev);
1013            $res_succ = rss_query($sql_succ);
1014
1015            $mCount = (12 * $y + $m);
1016
1017            // next
1018            while ($succ == null && $row=rss_fetch_assoc($res_succ)) {
1019                if ($currentView == 'day') {
1020                    if (mktime(0,0,0,$row['m_'],$row['d_'],$row['y_']) > $ts_s) {
1021                        $succ = array(
1022                                    'y' => $row['y_'],
1023                                    'm' => $row['m_'],
1024                                    'd' => $row['d_'],
1025                                    'cnt' => $row['cnt_'],
1026                                    'ts' => $row['ts_'],
1027                                    'url' =>  makeArchiveUrl($row['ts_'],$escaped_title,$cid,($currentView == 'day')),
1028                                    'lbl' => rss_locale_date('%B %e',$row['ts_']) . " (".$row['cnt_']." " . ($row['cnt_'] > 1? __('items'):__('item')) .")"
1029                                );
1030                    }
1031                }
1032                elseif($currentView == 'month') {
1033                    if (($row['m_'] + 12 * $row['y_']) > $mCount) {
1034                        $succ = array(
1035                                    'y' => $row['y_'],
1036                                    'm' => $row['m_'],
1037                                    'cnt' => $row['cnt_'],
1038                                    'ts' => $row['ts_'],
1039                                    'url' =>  makeArchiveUrl($row['ts_'],$escaped_title,$cid,($currentView == 'day')),
1040                                    'lbl' => rss_locale_date('%B %Y',$row['ts_']) . " (".$row['cnt_']." " . ($row['cnt_'] > 1? __('items'):ITEM) .")"
1041                                );
1042                    }
1043
1044                }
1045            }
1046
1047            // prev
1048            while ($prev == null && $row=rss_fetch_assoc($res_prev)) {
1049                if ($currentView == 'day') {
1050                    if (mktime(0,0,0,$row['m_'],$row['d_'],$row['y_']) < $ts_p) {
1051                        $prev = array(
1052                                    'y' => $row['y_'],
1053                                    'm' => $row['m_'],
1054                                    'd' => $row['d_'],
1055                                    'cnt' => $row['cnt_'],
1056                                    'ts' => $row['ts_'],
1057                                    'url' =>  makeArchiveUrl($row['ts_'],$escaped_title,$cid,($currentView == 'day')),
1058                                    'lbl' => rss_locale_date('%B %e',$row['ts_']) . " (".$row['cnt_']." " . ($row['cnt_'] > 1? __('items'):__('item')) .")"
1059                                );
1060                    }
1061                }
1062                elseif($currentView == 'month') {
1063                    if (($row['m_'] + 12 * $row['y_']) < $mCount) {
1064                        $prev = array(
1065                                    'y' => $row['y_'],
1066                                    'm' => $row['m_'],
1067                                    'cnt' => $row['cnt_'],
1068                                    'ts' => $row['ts_'],
1069                                    'url' =>  makeArchiveUrl($row['ts_'],$escaped_title,$cid,($currentView == 'day')),
1070                                    'lbl' => rss_locale_date('%B %Y',$row['ts_']) . " (".$row['cnt_']." ". ($row['cnt_'] > 1? __('items'):__('item')) .")"
1071                                );
1072                    }
1073                }
1074            }
1075            // up
1076            if ($currentView == 'day') {
1077                $ts = mktime(0,0,0,$m,10,$y);
1078                $up = array(
1079                          'y' => $y,
1080                          'm' => $m,
1081                          'url' => makeArchiveUrl($ts,$escaped_title,$cid,false),
1082                          'lbl' => rss_locale_date('%B %Y',$ts)
1083                      );
1084            }
1085            elseif ($currentView == 'month') {
1086                $up = array(
1087
1088                          'url' => getPath().
1089                                 ( getConfig('rss.output.usemodrewrite') ?
1090                                   $escaped_title
1091                                   :"feed.php?channel=$cid") ,
1092                          'lbl' => $escaped_title,
1093                          'lbl' => '');
1094            }
1095
1096            break;
1097
1098        case 'item':
1099
1100            $sql = " select i.title, i.id, "
1101                   ." UNIX_TIMESTAMP( ifnull(i.pubdate, i.added)) as ts_, "
1102                   ." year( ifnull(i.pubdate, i.added)) as y_, "
1103                   ." month( ifnull(i.pubdate, i.added)) as m_, "
1104                   ." dayofmonth( ifnull(i.pubdate, i.added)) as d_ "
1105                   ." from " .getTable("item") . " i "
1106                   ." where i.cid = $cid  ";
1107
1108            if (hidePrivate()) {
1109                $sql .= " and not(i.unread & " . RSS_MODE_PRIVATE_STATE .") ";
1110            }
1111
1112            if(getConfig('rss.config.datedesc.unread')) {
1113                $sql .= " order by ts_ desc, i.id asc";
1114            } else {
1115                $sql .= " order by ts_ asc, i.id asc";
1116            }
1117
1118            $rs = rss_query($sql);
1119            $found = false;
1120            $stop = false;
1121            $prev__ = null;
1122            $fCounter = 0;
1123            while (!$stop && list($title_,$iid_,$ts_,$y_,$m_,$d_) = rss_fetch_row($rs)) {
1124                if  ($iid_ == $iid) {
1125                    //this is the "current" item, get a hold on the previous one
1126                    $found = true;
1127                    if ($prev__) {
1128                        list($ptitle_,$piid_,$pts_,$py_,$pm_,$pd_) = $prev__;
1129                        $succ = array(
1130                                    'y' => $py_,
1131                                    'm' => $pm_,
1132                                    'cnt' => 0,
1133                                    'ts' => $pts_,
1134                                    'url' =>  makeArchiveUrl($pts_,$escaped_title,$cid,true)
1135                                           . (getConfig('rss.output.usemodrewrite') ?
1136                                              preg_replace("/[^A-Za-z0-9\.%]/","_",utf8_uri_encode($ptitle_)):
1137                                              "&amp;iid=$piid_"),
1138                                    'lbl' => htmlentities( $ptitle_,ENT_COMPAT,"UTF-8" )
1139                                );
1140                    }
1141                }
1142
1143                if ($found) {
1144                    // okay, this is the next item, then.
1145                    $fCounter++;
1146                    if ($fCounter == 2) {
1147                        $prev = array(
1148                                    'y' => $y_,
1149                                    'm' => $m_,
1150                                    'cnt' => 0,
1151                                    'ts' => $ts_,
1152                                    'url' =>  makeArchiveUrl($ts_,$escaped_title,$cid,true)
1153                                           . (getConfig('rss.output.usemodrewrite') ?
1154                                              preg_replace("/[^A-Za-z0-9\.%]/","_",utf8_uri_encode($title_)) :
1155                                              "&amp;iid=$iid_"),
1156                                    'lbl' => htmlentities($title_,ENT_COMPAT,"UTF-8")
1157                                );
1158                        $stop = true;
1159                    }
1160                }
1161
1162
1163                $prev__ = array($title_,$iid_,$ts_,$y_,$m_,$d_);
1164
1165            }
1166
1167            // up
1168
1169            $ts = mktime(0,0,0,$m,$d,$y);
1170            $up = array(
1171                      'y' => $y,
1172                      'm' => $m,
1173                      'd' => $d,
1174                      'url' => makeArchiveUrl($ts,$escaped_title,$cid,true),
1175                      'lbl' => rss_locale_date('%B %e',$ts)
1176                  );
1177
1178
1179            break;
1180
1181        case 'feed':
1182       
1183            $sql = "select c.id, c.title from " . getTable("channels") ." c "
1184                        . "inner join " . getTable("folders") ." d on d.id = c.parent "
1185                        . " where not(c.mode & " .  RSS_MODE_DELETED_STATE .") ";
1186
1187            if (hidePrivate()) {
1188                $sql .=" and not(c.mode & " . RSS_MODE_PRIVATE_STATE .") ";
1189            }
1190
1191            if (getConfig('rss.config.absoluteordering')) {
1192                $sql .=" order by d.position asc, c.position asc";
1193            } else {
1194                $sql .=" order by d.name asc, c.title asc";
1195            }
1196
1197
1198            $res  = rss_query($sql);
1199            $pcid = $ptitile = null;
1200            $cidname=array();
1201            $cids=array();
1202            while (list ($cid_,$title_)=rss_fetch_row($res)) {
1203                $cids[]=$cid_;
1204                $cidname[]=array($cid_,$title_);
1205            }
1206            $key = array_search($cid,$cids);
1207            if ($key !== NULL && $key !== FALSE) {
1208                //echo "$key " .count($cidname);
1209                if ($key+1 < count($cidname)) {
1210                    list($cid_,$title_) = $cidname[$key+1];
1211                    $succ = array(
1212                                'url' => getPath().
1213                                       ( getConfig('rss.output.usemodrewrite') ?
1214                                         preg_replace("/[^A-Za-z0-9\.]/","_",$title_) ."/"
1215                                         :"feed.php?channel=$cid_") ,
1216                                'lbl' => htmlentities( $title_,ENT_COMPAT,"UTF-8" )
1217                            );
1218                }
1219                if ($key > 0) {
1220                    list($cid_,$title_) = $cidname[$key-1];
1221                    $prev = array(
1222                                'url' => getPath().
1223                                       ( getConfig('rss.output.usemodrewrite') ?
1224                                         preg_replace("/[^A-Za-z0-9\.]/","_",$title_) ."/"
1225                                         :"feed.php?channel=$cid_") ,
1226                                'lbl' => htmlentities( $title_,ENT_COMPAT,"UTF-8" )
1227                            );
1228                }
1229
1230            }
1231
1232            break;
1233
1234        case 'cat':
1235            $res = rss_query(" select t.tag,t.id from  ".getTable('metatag') ." m "
1236                             . "inner join " . getTable('tag') . "t on m.tid = t.id"
1237                             ." where  m.ttype = 'channel' order by t.tag asc");
1238
1239            $pp = null;
1240            $nn = null;
1241            $found = false;
1242            $stop = false;
1243            while (!$stop && list($tt_,$tid_) = rss_fetch_row($res)) {
1244                if ($vfid == $tid_) {
1245                    $found = true;
1246                }
1247                if (!$found) {
1248                    $pp = array('id' => $tid_,  'title' => $tt_);
1249                }
1250                elseif ($vfid != $tid_) {
1251                    $nn = array('id' => $tid_ , 'title' => $tt_);
1252                    $stop = true;
1253                }
1254            }
1255            if ($pp) {
1256                $vftitle_ = $pp['title'];
1257                $vfid_ =        $pp['id'];
1258                $prev = array(
1259                            'url' => getPath().
1260                                   ( getConfig('rss.output.usemodrewrite') ?
1261                                     preg_replace("/[^A-Za-z0-9\.]/","_",$vftitle_) ."/"
1262                                     :"feed.php?vfolder=$vfid_") ,
1263                            'lbl' => htmlentities( $vftitle_,ENT_COMPAT,"UTF-8" )
1264                        );
1265            }
1266
1267            if ($nn) {
1268                $vftitle_ = $nn['title'];
1269                $vfid_ =        $nn['id'];
1270                $succ = array(
1271                            'url' => getPath().
1272                                   ( getConfig('rss.output.usemodrewrite') ?
1273                                     preg_replace("/[^A-Za-z0-9\.]/","_",$vftitle_) ."/"
1274                                     :"feed.php?vfolder=$vfid_") ,
1275                            'lbl' => htmlentities( $vftitle_,ENT_COMPAT,"UTF-8" )
1276                        );
1277            }
1278
1279
1280            break;
1281
1282        case 'folder':
1283            $sql = "select  f.id, f.name, count(*) from " . getTable('channels') . " c "
1284                   . "inner join " . getTable('folders') . " f on c.parent=f.id "
1285                   ."where f.name != '' ";
1286
1287            if (hidePrivate()) {
1288                $sql .= " and not (c.mode & ".RSS_MODE_PRIVATE_STATE.")";
1289            }
1290
1291            $sql .= " group by f.id ";
1292            if (getConfig('rss.config.absoluteordering')) {
1293                $sql .= " order by f.position asc, c.position asc";
1294            } else {
1295                $sql .= " order by f.name, c.title asc";
1296            }
1297            $res = rss_query($sql);
1298            $pp = null;
1299            $nn = null;
1300            $found = false;
1301            $stop = false;
1302
1303            while (!$stop && list($fid_, $fn_,$fc_) = rss_fetch_row($res)) {
1304                if ($fc_ == 0) {
1305                    continue;
1306                }
1307                if ($fid == $fid_) {
1308                    $found = true;
1309                }
1310                if (!$found) {
1311                    $pp = array('id' => $fid_,  'title' => $fn_);
1312                }
1313                elseif ($fid != $fid_) {
1314                    $nn = array('id' => $fid_ , 'title' => $fn_);
1315                    $stop = true;
1316                }
1317            }
1318            if ($pp) {
1319                $ftitle__ = $pp['title'];
1320                $fid__ =        $pp['id'];
1321                $prev = array(
1322                            'url' => getPath().
1323                                   ( getConfig('rss.output.usemodrewrite') ?
1324                                     preg_replace("/[^A-Za-z0-9\.]/","_",$ftitle__) ."/"
1325                                     :"feed.php?folder=$fid__") ,
1326                            'lbl' => htmlentities( $ftitle__,ENT_COMPAT,"UTF-8" )
1327                        );
1328            }
1329
1330            if ($nn) {
1331                $ftitle__ = $nn['title'];
1332                $fid__ =        $nn['id'];
1333                $succ = array(
1334                            'url' => getPath().
1335                                   ( getConfig('rss.output.usemodrewrite') ?
1336                                     preg_replace("/[^A-Za-z0-9\.]/","_",$ftitle__) ."/"
1337                                     :"feed.php?folder=$fid__") ,
1338                            'lbl' => htmlentities( $ftitle__,ENT_COMPAT,"UTF-8" )
1339                        );
1340            }
1341            break;
1342
1343        default:
1344            //echo "current view: $currentView";
1345            break;
1346        }
1347        return array($prev,$succ, $up);
1348    }
1349
1350    return null;
1351
1352}
1353
1354function markReadForm($cid) {
1355    if (hidePrivate()) {
1356        return;
1357    }
1358
1359    if (!defined('MARK_READ_FEED_FORM')) {
1360        define ('MARK_READ_FEED_FORM',$cid);
1361    }
1362    echo "\n\n<form action=\"". getPath() ."feed.php\" method=\"post\">\n"
1363    ."\t<p><input id=\"_markReadButton\" type=\"submit\" name=\"action\" accesskey=\"m\" value=\"". __('Mark These Items as Read') ."\"/>\n"
1364    ."\t<input type=\"hidden\" name=\"metaaction\" value=\"ACT_MARK_CHANNEL_READ\"/>\n"
1365    ."\t<input type=\"hidden\" name=\"channel\" value=\"$cid\"/>\n"
1366    ."\t<input type=\"hidden\" name=\"markreadids\" value=\"".implode(",",$GLOBALS['rss']->getShownUnreadIds())."\" />\n"
1367    ."</p>\n</form>";
1368}
1369
1370function markFolderReadForm($fid) {
1371    if (hidePrivate()) {
1372        return;
1373    }
1374
1375    if (!defined('MARK_READ_FOLDER_FORM')) {
1376        define ('MARK_READ_FOLDER_FORM',$fid);
1377    }
1378    echo "\n\n<form action=\"". getPath() ."feed.php\" method=\"post\">\n"
1379    ."\t<p><input id=\"_markReadButton\" type=\"submit\" name=\"action\" accesskey=\"m\" value=\"". __('Mark These Items as Read') ."\"/>\n"
1380    ."\t<input type=\"hidden\" name=\"metaaction\" value=\"ACT_MARK_FOLDER_READ\"/>\n"
1381    ."\t<input type=\"hidden\" name=\"folder\" value=\"$fid\"/>\n"
1382    ."\t<input type=\"hidden\" name=\"markreadids\" value=\"".implode(",",$GLOBALS['rss']->getShownUnreadIds())."\" />\n"
1383    ."</p></form>";
1384
1385}
1386
1387function markVirtualFolderReadForm($vfid) {
1388    if (hidePrivate()) {
1389        return;
1390    }
1391
1392    if (!defined('MARK_READ_VFOLDER_FORM')) {
1393        define ('MARK_READ_VFOLDER_FORM',$vfid);
1394    }
1395    echo "\n\n<form action=\"". getPath() ."feed.php\" method=\"post\">\n"
1396    ."\t<p><input id=\"_markReadButton\" type=\"submit\" name=\"action\" accesskey=\"m\" value=\"". __('Mark These Items as Read') ."\"/>\n"
1397    ."\t<input type=\"hidden\" name=\"metaaction\" value=\"ACT_MARK_VFOLDER_READ\"/>\n"
1398    ."\t<input type=\"hidden\" name=\"vfolder\" value=\"$vfid\"/>\n"
1399    ."\t<input type=\"hidden\" name=\"markreadids\" value=\"".implode(",",$GLOBALS['rss']->getShownUnreadIds())."\" />\n"
1400    ."</p>\n</form>";
1401}
1402
1403
1404
1405function debugFeed($cid) {}
1406
1407?>
Note: See TracBrowser for help on using the browser.