function rss_item_date() { if ($GLOBALS['rss']->currentItem->date) { $date_fmt = getConfig('rss.config.dateformat'); //define all string format that we will change //key: date fmt, value=strftime fmt //month possible fmt $tabMonthFmt = array(); $tabMonthFmt["F"] = "%B"; $tabMonthFmt["m"] = "%m"; $tabMonthFmt["M"] = "%b"; $tabMonthFmt["n"] = "%m"; //day possible fmt,order is important $tabDayFmt = array(); $tabDayFmt["d"] = "%d"; $tabDayFmt["D"] = "%a"; $tabDayFmt["l"] = "%A"; $tabDayFmt["j"] = "%e"; /* if (!eregi("^en",getConfig('rss.output.lang'))) { $tabDayFmt["jS"]="%e"; $tabDayFmt["S"]=""; //we remove this } else $tabDayFmt["j"]="%e"; */ $tabFmt = $tabMonthFmt + $tabDayFmt; $arrReplace = array(); $i = 0; foreach ($tabFmt as $old_fmt => $new_fmt) { $isDay = isset($tabDayFmt["{$old_fmt}"]) && $tabDayFmt["{$old_fmt}"]; if ($isDay && $new_fmt && strpos($date_fmt, "{$old_fmt}S") !== FALSE) { //we manage the S string format, to be sure to //link it properly $i++; $key = "#{$i}"; $value = rss_locale_date($new_fmt, $GLOBALS['rss']->currentItem->date, false); if (eregi("en", getConfig('rss.output.lang'))) { //we add the english suffixe only for english language $value .= rss_date('S', $GLOBALS['rss']->currentItem->date, false); } $arrReplace["{$key}"] = array("value" => $value, "isDay" => true); $old_fmt .= "S"; $date_fmt = str_replace($old_fmt, $key, $date_fmt); } else { if (strpos($date_fmt, $old_fmt) !== FALSE) { if ($new_fmt) { $i++; $key = "#{$i}"; $value = rss_locale_date($new_fmt, $GLOBALS['rss']->currentItem->date, false); $arrReplace["{$key}"] = array("value" => $value, "isDay" => $isDay); } else { $key = ""; } $date_fmt = str_replace($old_fmt, $key, $date_fmt); } } } //now we do the replacement and make permalink urls $date_lbl = rss_date($date_fmt, $GLOBALS['rss']->currentItem->date); if (count($arrReplace) > 0) { foreach ($arrReplace as $search => $data) { $durl = makeArchiveUrl($GLOBALS['rss']->currentItem->date, $GLOBALS['rss']->currentItem->parent->escapedTitle, $GLOBALS['rss']->currentItem->parent->cid, $data["isDay"]); $replace = "<a href=\"{$durl}\">{$data['value']}</a>"; $date_lbl = str_replace($search, $replace, $date_lbl); } } /* $date_lbl = rss_date(getConfig('rss.config.dateformat'), $GLOBALS['rss']->currentItem->date); // make a permalink url for the date (month) if (strpos(getConfig('rss.config.dateformat'), 'F') !== FALSE) { $mlbl = rss_date('F', $GLOBALS['rss']->currentItem->date, false); $murl = makeArchiveUrl( $GLOBALS['rss']->currentItem->date, $GLOBALS['rss']->currentItem->parent->escapedTitle, $GLOBALS['rss']->currentItem->parent->cid, false); $date_lbl = str_replace($mlbl, "<a href=\"$murl\">$mlbl</a>", $date_lbl); } // make a permalink url for the date (day) if (strpos(getConfig('rss.config.dateformat'), 'jS') !== FALSE) { $dlbl = rss_date('jS', $GLOBALS['rss']->currentItem->date, false); $durl = makeArchiveUrl( $GLOBALS['rss']->currentItem->date, $GLOBALS['rss']->currentItem->parent->escapedTitle, $GLOBALS['rss']->currentItem->parent->cid, true); $date_lbl = str_replace($dlbl, "<a href=\"$durl\">$dlbl</a>", $date_lbl); } */ return ($GLOBALS['rss']->currentItem->isPubDate ? __('Posted: ') : __('Fetched: ')) . $date_lbl; } }
/** * 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; }