root/branches/multiuser/index.php

Revision 1759, 6.9 kB (checked in by mdodoo, 11 months 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
28require_once("init.php");
29
30// Show unread items on the front page?
31// default to the config value, user can override this via a cookie
32$show_what = (getConfig('rss.output.frontpage.mixeditems') ?
33        SHOW_READ_AND_UNREAD : SHOW_UNREAD_ONLY);
34       
35if (array_key_exists(SHOW_WHAT,$_POST)) {
36        $show_what = $_POST[SHOW_WHAT];
37        $period = time()+COOKIE_LIFESPAN;
38        setcookie(SHOW_WHAT, $show_what , $period,getPath()); 
39} elseif (array_key_exists(SHOW_WHAT,$_COOKIE)) {
40        $show_what = $_COOKIE[SHOW_WHAT];
41}
42
43
44if (array_key_exists('metaaction', $_POST)
45    && $_POST['metaaction'] != ""
46    && trim($_POST['metaaction']) == trim('ACT_MARK_READ') 
47    && !hidePrivate()) {
48   
49    $sql = "update " .getTable("item2user") . " i2u set i2u.flgunread=0 where i2u.flgunread=1 and i2u.fkuid=" .rss_user_id();
50   
51   
52     
53   if (hidePrivate()) {
54                $sql .= " and i2u.flgprivate=0 ";
55         }
56
57        if (array_key_exists('markreadids',$_POST)) {
58                $sql .= " and i2u.fkiid in (" . rss_real_escape_string($_POST['markreadids']) .")";
59        }
60         rss_query( $sql );
61        rss_invalidate_cache(); 
62}
63
64if (array_key_exists('update',$_REQUEST)) {
65    update("");
66}
67
68$cntTotalItems = getConfig('rss.output.frontpage.numitems');
69
70rss_plugin_hook('rss.plugins.frontpage.beforeunread', null);
71$cntUnreadItems = unreadItems($show_what);
72
73// Now we have to decide how many read items to display
74$cntReadItems = getConfig('rss.output.frontpage.numreaditems');
75
76rss_plugin_hook('rss.plugins.frontpage.beforeread', null);
77
78if(($show_what == SHOW_UNREAD_ONLY) ) { 
79        if (($cntUnreadItems == 0) && $cntTotalItems) { // we showed no unread items
80                // Should we show some uread items?
81                if($cntReadItems == -1) { 
82                        readItems($cntTotalItems);
83                } else {
84                        readItems($cntReadItems);
85                }
86        }
87} else { // We are showing read and unread items
88        if ($cntTotalItems){
89                readItems($cntTotalItems - $cntUnreadItems);
90        }
91}
92
93rss_plugin_hook('rss.plugins.frontpage.afterread', null);
94$GLOBALS['rss'] -> header = new Header("",LOCATION_HOME,array('cid'=>null,'fid'=>null));
95$GLOBALS['rss'] -> feedList = new FeedList(false);
96$GLOBALS['rss'] -> renderWithTemplate('index.php');
97
98/*
99function getHiddenChannelIds() {
100        static $hiddenIds;
101        if ($hiddenIds == NULL) {
102                $sql = "select fk_ref_object_id from " .getTable('properties')
103                ." where domain='feed' and property = 'Hide from front-page'";
104                $rs = rss_query($sql);
105                while (list($cid) = rss_fetch_row($rs)) {
106                        $hiddenIds[] = $cid;
107                }
108        }
109        return $hiddenIds;
110}
111*/
112
113function unreadCallback($show_what) {
114    showViewForm($show_what);
115        markAllReadForm();
116}
117
118function unreadItems($show_what) {
119
120    _pf('populate unread items');
121        $unreadItems = new ItemList();
122        $numItems = getConfig('rss.output.frontpage.numitems');
123        /*
124        $hiddenIds = getHiddenChannelIds();
125        if (count($hiddenIds)) {
126                $sqlWhereHidden = " and c.id not in (" . implode(',',$hiddenIds) . ") ";
127        } else {
128                $sqlWhereHidden = "";
129        }
130        */
131        $sqlWhereHidden = "";
132       
133        $unreadItems -> populate("i2u.flgunread=1 " . $sqlWhereHidden, "", 0, $numItems,ITEM_SORT_HINT_UNREAD);
134        //var_dump($unreadItems);
135    _pf('end populate unread items');
136        if ($unreadItems ->unreadCount) {
137                $unreadItems -> preRender[] = array("unreadCallback",$show_what);
138        }
139       
140        $ret = $unreadItems -> unreadCount;
141         
142         $unreadItems -> setTitle(sprintf(__('Unread items (<strong id="ucnt">%d</strong>)') , $ret));
143         $unreadItems -> setRenderOptions(IL_TITLE_NO_ESCAPE);
144         $GLOBALS['rss'] -> appendContentObject($unreadItems); 
145     _pf('appended unread items');
146         
147    return $ret;
148}
149
150function readItems($limit) {
151   
152    _pf('read items');
153   /*
154   $hiddenIds = getHiddenChannelIds();
155        if (count($hiddenIds)) {
156                $sqlWhereHidden = " and c.id not in (" . implode(',',$hiddenIds) . ") ";
157        } else {
158                $sqlWhereHidden = "";
159        }
160        */
161
162       
163    $readItems = new ItemList();
164        $readItems -> setRenderOptions(IL_TITLE_NO_ESCAPE);
165
166        if (getConfig('rss.config.feedgrouping')) {
167                if ($limit <= 0) {
168                        return;
169                }
170                $sql = "select c2u.fkcid from " . getTable("channels2user") . " c2u " 
171                        . "inner join " . getTable("channels") . " c "
172            . "inner join " . getTable("folders") ." f on c.parent = f.id ";
173         
174         // $sql .= $sqlWhereHidden;
175   
176        $sql .= " where c2u.flgdeleted=0 ";
177       
178        if (getConfig('rss.config.absoluteordering')) {
179                $sql .= " order by f.position asc, c.position asc";
180        } else {
181                $sql .=" order by f.name asc, c.title asc";
182        }
183        $res1=rss_query($sql);
184        while ($readItems->itemCount < $limit && (list($cid) = rss_fetch_row($res1))) {
185                        $sqlWhere  = " i2u.flgunread=0 and i.cid= $cid";
186                $sqlWhere .= " and i.pubdate <= now() ";
187               
188                        $readItems->populate($sqlWhere, "", 0, 2, ITEM_SORT_HINT_READ);
189                        //what if we have less than 2 items.
190                } 
191               
192               
193        } else {
194                 
195                if ($limit <= 0) {
196                        return;
197                }
198                $sqlWhere  = " i2u.flgunread=0  ";
199        $sqlWhere .= " and i.pubdate <= now() ";
200    //  $sqlWhere .= $sqlWhereHidden;
201                $readItems -> populate($sqlWhere, "", 0, $limit, ITEM_SORT_HINT_READ);
202                $readItems -> setRenderOptions(IL_NO_COLLAPSE | IL_TITLE_NO_ESCAPE);
203
204        }
205
206               
207        $readItems -> setTitle(__('Recent items'));
208       
209        $GLOBALS['rss'] -> appendContentObject($readItems);     
210        _pf('end read items');
211
212}
213
214function markAllReadForm() {
215        if (hidePrivate()) {
216                return;
217        }
218       
219        if (!defined('MARK_READ_ALL_FORM')) {
220                define ('MARK_READ_ALL_FORM',true);
221        }       
222       
223   echo "<form action=\"". getPath() ."\" method=\"post\">\n"
224      ."<p><input accesskey=\"m\" type=\"submit\" name=\"action\" value=\"". __('Mark These Items as Read') ." \"/></p>\n"
225      ."<p><input type=\"hidden\" name=\"metaaction\" value=\"ACT_MARK_READ\"/>\n"
226      ."<input type=\"hidden\" name=\"markreadids\" value=\"".implode(",",$GLOBALS['rss']->getShownUnreadIds())."\" />\n"
227      ."</p></form>\n";
228}
229
230
231?>
Note: See TracBrowser for help on using the browser.