root/trunk/gregarius/feed.php

Revision 1785, 49.6 kB (checked in by cfriesen, 2 years ago)

undo the changes made to the core in the attempt to make the plugin change the output count

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