| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
require_once("init.php"); |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 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 |
|
|---|
| 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) { |
|---|
| 88 |
// Should we show some uread items? |
|---|
| 89 |
if($cntReadItems == -1) { |
|---|
| 90 |
readItems($cntTotalItems); |
|---|
| 91 |
} else { |
|---|
| 92 |
readItems($cntReadItems); |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
} else { |
|---|
| 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 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|