root/trunk/gregarius/index.php

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