root/trunk/gregarius/cls/categories.php

Revision 1668, 6.0 kB (checked in by mbonetti, 23 months ago)

replaced eval() - based rendering in favor of include()'s

  • Property svn:eolstyle set to native
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
28define('COLLAPSED_CATEGORIES_COOKIE', 'collapsedcategories');
29
30class CatFolder extends FeedFolder{
31        var $isRootFolder = false;
32
33        function CatFolder($name, $id, &$rootList) {
34                $this->name = $name;
35                $this->id = $id;
36                if (getConfig('rss.output.usemodrewrite')) {
37                        $this->rlink = $this -> makeFolderUrl($name); //.preg_replace("/[^a-zA-Z0-9_]/", "_", $name)."/";
38                } else {
39                        $this->rlink = getPath()."feed.php?vfolder=$id";
40                }
41                $this->rootList = $rootList;
42        }
43       
44        function render() {             
45                $GLOBALS['rss']->currentFeedsFolder = $this;
46                include($GLOBALS['rss'] ->getTemplateFile("catfolder.php"));
47        }
48}
49
50class CatList extends FeedList {
51       
52        var $tagCnt = 0;
53        var $taggedFeedCnt = 0;
54        var $feedCnt = 0;
55       
56        function CatList() {
57                //parent::FeedList(null);
58                $this->loadCollapsedState();
59                $this -> populate();
60                $this ->        columnTitle = __('Categories');
61                $GLOBALS['rss']-> feedList = $this;
62        }
63       
64        function getFeedCount() {
65                // cached?
66                if ($this -> feedCnt > 0) {
67                        return $this -> feedCnt;
68                }
69       
70                $sql = "select "
71                                ." count(*) as cnt "
72                                ." from ".getTable("channels")." c "
73                                ." where  not(c.mode & ".RSS_MODE_DELETED_STATE.") ";
74
75                if (hidePrivate()) {
76                        $sql .= " and not(c.mode & ".RSS_MODE_PRIVATE_STATE.") ";
77                }
78
79
80                list($this -> feedCnt) = rss_fetch_row(rss_query($sql));
81
82                return $this -> feedCnt;
83        }
84       
85       
86        function getStats() {
87                return sprintf(__('<strong>%d</strong> feeds in <strong>%d</strong> categories'), $this -> taggedFeedCnt, $this -> tagCnt, 0);
88        }
89       
90        function loadCollapsedState() {
91                _pf('CatList->loadCollapsedState()...');
92               
93                if (getConfig('rss.output.channelcollapse')) {
94
95                        //read per-user stored collapsed categories
96                        if (array_key_exists(COLLAPSED_CATEGORIES_COOKIE, $_COOKIE)) {
97                                $this->collapsed_ids = explode(":", $_COOKIE[COLLAPSED_CATEGORIES_COOKIE]);
98                        } elseif (empty($this->collapsed_ids) && getConfig("rss.output.channelcollapsedefault")) {
99                           // Lets collapse all categories
100                           $res = rss_query("select distinct(tid) from " . getTable('metatag') . " where ttype='channel'");
101                           while (list ($this->collapsed_ids[]) = rss_fetch_row($res)) {
102                           }
103                           if (!headers_sent()) { // Sajax does not allow us to set cookies
104                                setcookie(COLLAPSED_CATEGORIES_COOKIE, 
105                                   implode(":", $this->collapsed_ids ) , time()+COOKIE_LIFESPAN,getPath());
106                           }
107                        }
108
109                        //get unread count per folder
110                        $sql = "select m.tid, t.tag, count(*) as cnt "
111                        ." from " . getTable('item') ." i "
112                        ." inner join " . getTable('channels') . " c on c.id = i.cid "
113                        ." inner join " . getTable('metatag') ." m on m.fid = c.id "
114                        ." inner join " . getTable('tag') . " t on t.id = m.tid "
115                        ." where i.unread & ". RSS_MODE_UNREAD_STATE
116                        ." and not(i.unread & ". RSS_MODE_DELETED_STATE .")";
117                        if (hidePrivate()) {
118                                $sql .=" and not(unread & " . RSS_MODE_PRIVATE_STATE .") ";
119                        }
120                        $sql .= " and not(c.mode & " . RSS_MODE_DELETED_STATE .") "
121                        ." group by m.tid";
122                        _pf('query');
123                        $res = rss_query($sql);
124                        _pf('ok');     
125                        while (list ($cid, $cname, $cuc) = rss_fetch_row($res)) {
126                                $this->collapsed_folders[$cid] = $cuc;
127                        }
128                   
129                        sort($this->collapsed_ids);
130                }
131                _pf('done');
132        }
133
134        function populate() {
135
136               
137                ////// actual feeds ///////
138                $this->folders = array();
139                _pf('CatList->populate() ...');
140                $sql = "select "
141                 ." c.id, c.title, c.url, c.siteurl, t.tag, c.parent, c.icon, c.descr, c.mode, t.id "
142                 ." from " . getTable('channels') ." c "
143                 ." inner join " . getTable('metatag') ." m on m.fid = c.id "
144                 ." inner join " . getTable('tag') . " t on t.id = m.tid "
145                 ." where m.ttype = 'channel' ";
146
147                if (hidePrivate()) {
148                        $sql .= " and not(c.mode & ".RSS_MODE_PRIVATE_STATE.") ";
149                }
150
151                $sql .= " and not(c.mode & ".RSS_MODE_DELETED_STATE.") ";
152
153                $sql .= " order by t.tag asc";
154               
155                if(!getConfig("rss.config.absoluteordering")){
156                         $sql .= ", c.title asc";
157                }
158               
159                $res = rss_query($sql);
160                $this -> taggedFeedCnt = rss_num_rows($res);
161               
162                // get # of unread items for each feed
163                $ucres = rss_query ("select cid, count(*) from " .getTable("item")
164                 ." where unread & "  . RSS_MODE_UNREAD_STATE
165                 . " and not(unread & " . RSS_MODE_DELETED_STATE
166                 . ") group by cid");
167                $uc = array();
168                while (list($uccid,$ucuc) = rss_fetch_row($ucres)) {
169                        $uc[$uccid]=$ucuc;
170                }
171               
172                while (list ($cid, $ctitle, $curl, $csiteurl, $fname, 
173                                                                $cparent, $cico, $cdescr, $cmode, $tid) = rss_fetch_row($res)) {
174                       
175                        $unread = 0;
176                        if(isset($uc[$cid])) $unread = $uc[$cid];
177                        $f = new FeedListItem($cid, $ctitle, $curl, $csiteurl, $fname, $cparent, $cico, $cdescr, $cmode, $unread);
178                       
179                        if (!array_key_exists($tid, $this->folders)) {
180                                $this->folders[$tid] = new CatFolder($fname, $tid,$this);
181                                $this -> tagCnt++;
182                        }
183                       
184                        $this->folders[$tid]->feeds[] = $f;
185                        $this->folders[$tid]->isCollapsed = in_array($tid, $this->collapsed_ids) && ($tid > 0);
186                       
187                _pf('done');
188                }
189        }
190       
191}
192
193?>
Note: See TracBrowser for help on using the browser.