/** * Constructor. Fills in the instance variables, escapes urls accordingly */ function FeedListItem($id, $title, $url, $siteurl, $name, $parent, $icon, $descr, $mode, $unreadCount) { $this->id = $id; $this->title = $title; $this->url = $url; $this->publicUrl = preg_replace('|(https?://)([^:]+:[^@]+@)(.+)$|', '\\1\\3', $url); $this->siteurl = $siteurl; $this->name = $name; $this->parent = $parent; if (getConfig('rss.output.showfavicons') && $icon) { if (substr($icon, 0, 5) == 'blob:') { $this->icon = getPath() . "extlib/favicon.php?url=" . rss_real_escape_string(substr($icon, 5)); } else { $this->icon = $icon; } } elseif (getConfig('rss.output.showfavicons')) { $this->icon = getExternalThemeFile("media/noicon.png"); } else { $this->icon = false; } $this->descr = $descr; $this->mode = $mode; if (getConfig('rss.output.usemodrewrite')) { $this->rlink = getPath(rss_uri($title)) . "/"; } else { $this->rlink = getPath() . "feed.php?channel={$id}"; } if ($unreadCount > 0) { $this->rdLbl = sprintf(__('<strong id="%s" style="%s">(%d unread)</strong>'), "cid{$id}", "", $unreadCount); $this->class_ = "feed title unread"; } else { $this->rdLbl = ""; $this->class_ = "feed title"; } }
/** * This function will return an array for the previous, next and up * navigation elements, based on the current location * * @return: array ( ('prev'|'next'|'up')* => array ( 'y' => year of the prev,next,up item 'm' => month of the prev,next,up item 'd' => day of the prev,next,up item 'cnt' => count of the prev,next,up items for this date 'ts' => unix timestamp of the above 'url' => precomputed uri for the link 'lbl' => precomupted label to be used in the links ) ) */ function makeNav($cid, $iid, $y, $m, $d, $fid, $vfid, $cids) { //echo "X-info: $cid,$iid,$y,$m,$d,$fid,$vfid,$cids"; $currentView = null; $prev = $succ = $up = null; if (isset($_REQUEST['channel'])) { $escaped_title = rss_uri($_REQUEST['channel']); //preg_replace("/[^A-Za-z0-9\.]/","_",$_REQUEST['channel']); } else { $escaped_title = null; } // where are we anyway? if ($y > 0 && $m > 0 && $d > 0) { if ($iid != "") { $currentView = 'item'; } else { $currentView = 'day'; } } elseif ($y > 0 && $m > 0 && $d == 0) { $currentView = 'month'; } elseif ($cids) { if ($fid) { $currentView = "folder"; } elseif ($vfid) { $currentView = "cat"; } } elseif ($cid) { $currentView = "feed"; } if ($currentView) { switch ($currentView) { case 'month': case 'day': if ($currentView == 'day') { $ts_p = mktime(23, 59, 59, $m, $d - 1, $y); $ts_s = mktime(0, 0, 0, $m, $d, $y); } elseif ($currentView == 'month') { $ts_p = mktime(0, 0, 0, $m + 1, 0, $y); $ts_s = mktime(0, 0, 0, $m, 1, $y); } $sql_succ = " select " . " UNIX_TIMESTAMP( ifnull(i.pubdate, i.added)) as ts_, " . " year( ifnull(i.pubdate, i.added)) as y_, " . " month( ifnull(i.pubdate, i.added)) as m_, " . ($currentView == 'day' ? " dayofmonth( ifnull(i.pubdate, i.added)) as d_, " : "") . " count(*) as cnt_ " . " from " . getTable("item") . "i where " . " UNIX_TIMESTAMP(ifnull(i.pubdate, i.added)) > {$ts_s} "; if ($cid) { $sql_succ .= " and cid={$cid} "; } if (hidePrivate()) { $sql_succ .= " and not(i.unread & " . RSS_MODE_PRIVATE_STATE . ") "; } $sql_succ .= " group by y_,m_" . ($currentView == 'day' ? ",d_ " : "") . " order by ts_ asc limit 4"; $sql_prev = " select " . " UNIX_TIMESTAMP( ifnull(i.pubdate, i.added)) as ts_, " . " year( ifnull(i.pubdate, i.added)) as y_, " . " month( ifnull(i.pubdate, i.added)) as m_, " . ($currentView == 'day' ? " dayofmonth( ifnull(i.pubdate, i.added)) as d_, " : "") . " count(*) as cnt_ " . " from " . getTable("item") . " i where " . " UNIX_TIMESTAMP(ifnull(i.pubdate, i.added)) < {$ts_p} "; if ($cid) { $sql_prev .= " and cid={$cid} "; } if (hidePrivate()) { $sql_prev .= " and not(i.unread & " . RSS_MODE_PRIVATE_STATE . ") "; } $sql_prev .= " group by y_,m_" . ($currentView == 'day' ? ",d_ " : "") . " order by ts_ desc limit 4"; //echo "<!-- $sql_prev -->\n"; $res_prev = rss_query($sql_prev); $res_succ = rss_query($sql_succ); $mCount = 12 * $y + $m; // next while ($succ == null && ($row = rss_fetch_assoc($res_succ))) { if ($currentView == 'day') { if (mktime(0, 0, 0, $row['m_'], $row['d_'], $row['y_']) > $ts_s) { $succ = array('y' => $row['y_'], 'm' => $row['m_'], 'd' => $row['d_'], 'cnt' => $row['cnt_'], 'ts' => $row['ts_'], 'url' => makeArchiveUrl($row['ts_'], $escaped_title, $cid, $currentView == 'day'), 'lbl' => rss_locale_date('%B %e', $row['ts_']) . " (" . $row['cnt_'] . " " . ($row['cnt_'] > 1 ? __('items') : __('item')) . ")"); } } elseif ($currentView == 'month') { if ($row['m_'] + 12 * $row['y_'] > $mCount) { $succ = array('y' => $row['y_'], 'm' => $row['m_'], 'cnt' => $row['cnt_'], 'ts' => $row['ts_'], 'url' => makeArchiveUrl($row['ts_'], $escaped_title, $cid, $currentView == 'day'), 'lbl' => rss_locale_date('%B %Y', $row['ts_']) . " (" . $row['cnt_'] . " " . ($row['cnt_'] > 1 ? __('items') : ITEM) . ")"); } } } // prev while ($prev == null && ($row = rss_fetch_assoc($res_prev))) { if ($currentView == 'day') { if (mktime(0, 0, 0, $row['m_'], $row['d_'], $row['y_']) < $ts_p) { $prev = array('y' => $row['y_'], 'm' => $row['m_'], 'd' => $row['d_'], 'cnt' => $row['cnt_'], 'ts' => $row['ts_'], 'url' => makeArchiveUrl($row['ts_'], $escaped_title, $cid, $currentView == 'day'), 'lbl' => rss_locale_date('%B %e', $row['ts_']) . " (" . $row['cnt_'] . " " . ($row['cnt_'] > 1 ? __('items') : __('item')) . ")"); } } elseif ($currentView == 'month') { if ($row['m_'] + 12 * $row['y_'] < $mCount) { $prev = array('y' => $row['y_'], 'm' => $row['m_'], 'cnt' => $row['cnt_'], 'ts' => $row['ts_'], 'url' => makeArchiveUrl($row['ts_'], $escaped_title, $cid, $currentView == 'day'), 'lbl' => rss_locale_date('%B %Y', $row['ts_']) . " (" . $row['cnt_'] . " " . ($row['cnt_'] > 1 ? __('items') : __('item')) . ")"); } } } // up if ($currentView == 'day') { $ts = mktime(0, 0, 0, $m, 10, $y); $up = array('y' => $y, 'm' => $m, 'url' => makeArchiveUrl($ts, $escaped_title, $cid, false), 'lbl' => rss_locale_date('%B %Y', $ts)); } elseif ($currentView == 'month') { $up = array('url' => getPath() . (getConfig('rss.output.usemodrewrite') ? $escaped_title : "feed.php?channel={$cid}"), 'lbl' => $escaped_title, 'lbl' => ''); } break; case 'item': $sql = " select i.title, i.id, " . " UNIX_TIMESTAMP( ifnull(i.pubdate, i.added)) as ts_, " . " year( ifnull(i.pubdate, i.added)) as y_, " . " month( ifnull(i.pubdate, i.added)) as m_, " . " dayofmonth( ifnull(i.pubdate, i.added)) as d_ " . " from " . getTable("item") . " i " . " where i.cid = {$cid} "; if (hidePrivate()) { $sql .= " and not(i.unread & " . RSS_MODE_PRIVATE_STATE . ") "; } if (getConfig('rss.config.datedesc.unread')) { $sql .= " order by ts_ desc, i.id asc"; } else { $sql .= " order by ts_ asc, i.id asc"; } $rs = rss_query($sql); $found = false; $stop = false; $prev__ = null; $fCounter = 0; while (!$stop && (list($title_, $iid_, $ts_, $y_, $m_, $d_) = rss_fetch_row($rs))) { if ($iid_ == $iid) { //this is the "current" item, get a hold on the previous one $found = true; if ($prev__) { list($ptitle_, $piid_, $pts_, $py_, $pm_, $pd_) = $prev__; $succ = array('y' => $py_, 'm' => $pm_, 'cnt' => 0, 'ts' => $pts_, 'url' => makeArchiveUrl($pts_, $escaped_title, $cid, true) . (getConfig('rss.output.usemodrewrite') ? rss_uri($ptitle_) : "&iid={$piid_}"), 'lbl' => htmlentities($ptitle_, ENT_COMPAT, "UTF-8")); } } if ($found) { // okay, this is the next item, then. $fCounter++; if ($fCounter == 2) { $prev = array('y' => $y_, 'm' => $m_, 'cnt' => 0, 'ts' => $ts_, 'url' => makeArchiveUrl($ts_, $escaped_title, $cid, true) . (getConfig('rss.output.usemodrewrite') ? rss_uri($title_) : "&iid={$iid_}"), 'lbl' => htmlentities($title_, ENT_COMPAT, "UTF-8")); $stop = true; } } $prev__ = array($title_, $iid_, $ts_, $y_, $m_, $d_); } // up $ts = mktime(0, 0, 0, $m, $d, $y); $up = array('y' => $y, 'm' => $m, 'd' => $d, 'url' => makeArchiveUrl($ts, $escaped_title, $cid, true), 'lbl' => rss_locale_date('%B %e', $ts)); break; case 'feed': $sql = "select " . " c.id, c.title " . " from " . getTable("channels") . " c " . " inner join " . getTable("folders") . " d " . " on d.id = c.parent "; $sql .= " where not(c.mode & " . RSS_MODE_DELETED_STATE . ") "; if (hidePrivate()) { $sql .= " and not(c.mode & " . RSS_MODE_PRIVATE_STATE . ") "; } if (getConfig('rss.config.absoluteordering')) { $sql .= " order by d.position asc, c.position asc"; } else { $sql .= " order by d.name asc, c.title asc"; } $res = rss_query($sql); $pcid = $ptitile = null; $cidname = array(); $cids = array(); while (list($cid_, $title_) = rss_fetch_row($res)) { $cids[] = $cid_; $cidname[] = array($cid_, $title_); } $key = array_search($cid, $cids); if ($key !== NULL && $key !== FALSE) { //echo "$key " .count($cidname); if ($key + 1 < count($cidname)) { list($cid_, $title_) = $cidname[$key + 1]; $succ = array('url' => getPath() . (getConfig('rss.output.usemodrewrite') ? rss_uri($title_) . "/" : "feed.php?channel={$cid_}"), 'lbl' => htmlentities($title_, ENT_COMPAT, "UTF-8")); } if ($key > 0) { list($cid_, $title_) = $cidname[$key - 1]; $prev = array('url' => getPath() . (getConfig('rss.output.usemodrewrite') ? rss_uri($title_) . "/" : "feed.php?channel={$cid_}"), 'lbl' => htmlentities($title_, ENT_COMPAT, "UTF-8")); } } break; case 'cat': $res = rss_query(" select t.tag,t.id from " . getTable('metatag') . " m " . "inner join " . getTable('tag') . "t on t.id = m.tid " . " where m.ttype = 'channel' " . " order by t.tag asc"); $pp = null; $nn = null; $found = false; $stop = false; while (!$stop && (list($tt_, $tid_) = rss_fetch_row($res))) { if ($vfid == $tid_) { $found = true; } if (!$found) { $pp = array('id' => $tid_, 'title' => $tt_); } elseif ($vfid != $tid_) { $nn = array('id' => $tid_, 'title' => $tt_); $stop = true; } } if ($pp) { $vftitle_ = $pp['title']; $vfid_ = $pp['id']; $prev = array('url' => getPath() . (getConfig('rss.output.usemodrewrite') ? rss_uri($vftitle_) . "/" : "feed.php?vfolder={$vfid_}"), 'lbl' => htmlentities($vftitle_, ENT_COMPAT, "UTF-8")); } if ($nn) { $vftitle_ = $nn['title']; $vfid_ = $nn['id']; $succ = array('url' => getPath() . (getConfig('rss.output.usemodrewrite') ? rss_uri($vftitle_) . "/" : "feed.php?vfolder={$vfid_}"), 'lbl' => htmlentities($vftitle_, ENT_COMPAT, "UTF-8")); } break; case 'folder': $sql = "select f.id, f.name, count(*) from " . getTable('channels') . " c " . "inner join " . getTable('folders') . " f on f.id = c.parent " . " where f.name != '' "; if (hidePrivate()) { $sql .= " and not (c.mode & " . RSS_MODE_PRIVATE_STATE . ")"; } $sql .= " group by f.id "; if (getConfig('rss.config.absoluteordering')) { $sql .= " order by f.position asc, c.position asc"; } else { $sql .= " order by f.name, c.title asc"; } $res = rss_query($sql); $pp = null; $nn = null; $found = false; $stop = false; while (!$stop && (list($fid_, $fn_, $fc_) = rss_fetch_row($res))) { if ($fc_ == 0) { continue; } if ($fid == $fid_) { $found = true; } if (!$found) { $pp = array('id' => $fid_, 'title' => $fn_); } elseif ($fid != $fid_) { $nn = array('id' => $fid_, 'title' => $fn_); $stop = true; } } if ($pp) { $ftitle__ = $pp['title']; $fid__ = $pp['id']; $prev = array('url' => getPath() . (getConfig('rss.output.usemodrewrite') ? rss_uri($ftitle__) . "/" : "feed.php?folder={$fid__}"), 'lbl' => htmlentities($ftitle__, ENT_COMPAT, "UTF-8")); } if ($nn) { $ftitle__ = $nn['title']; $fid__ = $nn['id']; $succ = array('url' => getPath() . (getConfig('rss.output.usemodrewrite') ? rss_uri($ftitle__) . "/" : "feed.php?folder={$fid__}"), 'lbl' => htmlentities($ftitle__, ENT_COMPAT, "UTF-8")); } break; default: //echo "current view: $currentView"; break; } return array($prev, $succ, $up); } return null; }
/** * Feed constructor */ function Feed($title, $cid, $icon) { $this->rss =& $GLOBALS['rss']; $this->title = rss_htmlspecialchars($title); $this->cid = $cid; if (substr($icon, 0, 5) == 'blob:') { $this->iconUrl = getPath() . "extlib/favicon.php?url=" . rss_real_escape_string(substr($icon, 5)); } else { $this->iconUrl = $icon; } //$this->escapedTitle = preg_replace("/[^A-Za-z0-9\.]/", "_", $title); $this->escapedTitle = rss_uri($title); }
<?php $displayFolder = FALSE; // use rss_uri to convert current channel name or feed name to compare to the channel in argument // note that channel in argument might be channel folder or a feed if (isset($_GET['channel']) && rss_uri($_GET['channel']) === rss_uri(rss_feeds_folder_name())) { $displayFolder = TRUE; // as a fallback, if user tried to mark a folder as read, then we should show that same folder open } else { if (isset($_POST['metaaction']) && $_POST['metaaction'] == 'ACT_MARK_FOLDER_READ' && $_POST["folder"] === rss_feeds_folder_id()) { $displayFolder = TRUE; } else { if (isset($_GET['channel'])) { foreach ($GLOBALS['rss']->currentFeedsFolder->feeds as $feed) { if (rss_uri($feed->title) === rss_uri($_GET['channel'])) { $displayFolder = TRUE; break; } } } else { if (isset($_POST['metaaction']) && $_POST['metaaction'] == 'ACT_MARK_CHANNEL_READ') { foreach ($GLOBALS['rss']->currentFeedsFolder->feeds as $feed) { if ($feed->id === $_POST['channel']) { $displayFolder = TRUE; break; } } } } } }