Created
March 1, 2012 19:47
-
-
Save readingtype/1952607 to your computer and use it in GitHub Desktop.
Modify Textpattern plugin, http://www.wilshireone.com/textpattern-plugins/rss-suparchive. Format the excerpt with Textile if appropriate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rss_suparchive article listing plugin | |
// by Rob Sable | |
// http://www.wilshireone.com | |
// Version 0.1 - 11/02/2004 | |
// Full revision history at http://www.wilshireone.com/textpattern-plugins/rss-suparchive | |
// Version 0.16.1 - 01/09/2006 - Fix broken file downloads. Fix inadvertent date filtering on article pages. | |
// Version 0.17 - 08/08/06 - Change categories to display title instead of name. | |
// Version 0.18 - 08/09/06 - Add showcommentscount, showzerocount, countprefix, countsuffix to suparchive and suparchive_bycat. Change to use strftime for date formatting to allow for localization. Add wildcard and exclude format for section attribute on all 3 tags. (thanks Andrew). | |
// 20120301 BW Add ability to decode Textile markup in excerpts. * if other markup is used this probably won't work, but if USE_TEXTILE is false it will return the raw text. See rss_format() below * | |
register_callback('rss_suparchive_init','pretext'); | |
function rss_suparchive_init() { | |
global $attach_titles_to_permalinks; | |
$subpath = preg_quote(preg_replace("/http:\/\/.*(\/.*)/Ui","$1",hu),"/"); | |
$req = preg_replace("/^$subpath/i","/",serverSet('REQUEST_URI')); | |
extract(chopUrl($req)); | |
$f = safe_field('title','txp_section',"name='".doSlash($u1)."'"); | |
if (!empty($f)) { | |
if ($u2 && is_numeric($u2)) $_POST['s'] = $u1; | |
if (($u3 && !is_numeric($u3)) || (!$attach_titles_to_permalinks && !$u3)) $_POST['id'] = $u2; | |
} | |
} | |
function rss_suparchive_menu($atts) { | |
global $s, $pretext; | |
extract($pretext); | |
extract(lAtts(array( | |
'section' => "article", | |
'linktosection' => $s, | |
'timeframe' => "PAST", | |
'limit' => 6, | |
'showheader' => "0", | |
'headerlabel' => "Monthly Archives", | |
'headerlevel' => "2", | |
'showcount' => "1", | |
'countlabel' => "", | |
'mode' => "MONTH" | |
),$atts)); | |
foreach (explode(',', $section) as $section) | |
{ | |
switch (substr(trim($section), 0, 1)) | |
{ | |
case '*': | |
$sctsql[] = " (section like '%') "; | |
break; | |
case '!': | |
$notsctsql[] = " AND (section != '" . doSlash(str_replace('!','',$section)) . "') "; | |
break; | |
default: | |
$sctsql[] = " (section = '" . doSlash($section) . "') "; | |
break; | |
} | |
} | |
$sections = ' AND (' . join(' OR ', $sctsql) . @join(' AND ', $notsctsql) . ') '; | |
$posted= ($timeframe == "FUTURE") ? " AND Posted >= now() ORDER BY posted asc " : " AND posted < now() ORDER BY posted desc "; | |
$posted= isset($posted) ? $posted : " ORDER BY posted desc "; | |
$where = "status=4 $sections $posted"; | |
$res = safe_rows("id, unix_timestamp(posted) as posted","textpattern", $where); | |
if( $res ) { | |
$dateformat = ($mode == "YEAR") ? "%Y" : "%B %Y"; | |
$c=-1; $p=0; $lasto=""; | |
$lastd = safe_strftime($dateformat,$res[0]["posted"]); | |
$output[] = ($showheader) ? '<h' .$headerlevel. '>' .$headerlabel. '</h' .$headerlevel. '>'.n : ''; | |
$output[] = '<ul class="rssMenu">'.n; | |
foreach( $res as $a ) { | |
$date = safe_strftime($dateformat,$a["posted"]); | |
$datelink = ($mode == "YEAR") ? "/".safe_strftime('%Y',$lasto) : "/".safe_strftime('%Y',$lasto)."/".safe_strftime('%m',$lasto); | |
$c++; | |
$count = ($showcount) ? ' <span class="rssMonthCount">('.$c.$countlabel.')</span>' : ''; | |
$output[] = ($lastd != $date && $p <= ($limit-1)) ? '<li><a href="'.hu.$linktosection.$datelink.'">'.$lastd.$count.'</a></li>'.n : ""; | |
if ($p <= ($limit-1)) { | |
if ($lastd != $date) { $c=0; $p++; }; | |
$lastd = $date; | |
$lasto = $a["posted"]; | |
} | |
} | |
$datelink = ($mode == "YEAR") ? "/".safe_strftime('%Y',$lasto) : "/".safe_strftime('%Y',$lasto)."/".safe_strftime('%m',$lasto); | |
$count = ($showcount) ? ' <span class="rssMonthCount">('.($c+1).$countlabel.')</span>' : ''; | |
$output[] = ($p <= ($limit-1)) ? '<li><a href="'.hu.$linktosection.$datelink.'">'.$lastd.$count.'</a></li>'.n : ''; | |
$output[] = '</ul>'.n.n; | |
return implode( "", $output); | |
} | |
return; | |
} | |
function rss_suparchive($atts) { | |
global $siteurl, $c, $s, $url_mode, $pretext, $thisarticle; | |
extract($pretext); | |
extract(lAtts(array( | |
'section' => "article", | |
'category' => isset($nocatfilter) ? "" : $c, | |
'author' => gps('author'), | |
'dateformat' => "%B %d, %Y", | |
'showsection' => "0", | |
'showcats' => "0", | |
'showauthor' => "0", | |
'showexcerpt' => "0", | |
'secstart' => "in", | |
'catstart' => "under", | |
'catsep' => "and", | |
'authorsep' => "by", | |
'addbreak' => "0", | |
'showsubdate' => "0", | |
'subdateformat' => "%d", | |
'subdatesep' => ": ", | |
'limit' => 999999999, | |
'form' => "", | |
'class' => "", | |
'sortby' => "", | |
'timeframe' => "PAST", | |
'showcommentscount' => "0", | |
'showzerocount' => "1", | |
'countprefix' => "", | |
'countsuffix' => "" | |
),$atts)); | |
$category = doSlash($category); | |
foreach (explode(',', $section) as $section) | |
{ | |
switch (substr(trim($section), 0, 1)) | |
{ | |
case '*': | |
$sctsql[] = " (section like '%') "; | |
break; | |
case '!': | |
$notsctsql[] = " (section != '" . doSlash(str_replace('!','',$section)) . "') "; | |
break; | |
default: | |
$sctsql[] = " (section = '" . doSlash($section) . "') "; | |
break; | |
} | |
} | |
$sections = ' AND (' . @join(' OR ', $sctsql) . @join(' AND ', $notsctsql) . ') '; | |
foreach (explode(',', $category) as $category) { | |
if ($category) $catsql[] = " (category1 = '" . urldecode($category) . "') OR (category2 = '" . urldecode($category) . "') "; | |
} | |
$categories= isset($catsql) ? ' AND (' . join(' OR ', $catsql) . ') ' : ""; | |
foreach (explode(',', $author) as $author) { | |
if ($author) $authsql[] = " (authorid = '" . $author . "') "; | |
} | |
$authors= isset($authsql) ? ' AND (' . join(' OR ', $authsql) . ') ' : ""; | |
$offsetsql= isset($offset) ? 'LIMIT '.$offset.',9999999999' : ""; | |
switch ($timeframe) { | |
case "FUTURE": | |
$posted = " AND posted >= now() "; | |
break; | |
case "PAST": | |
$posted = " AND posted < now() "; | |
break; | |
case "ALL": | |
$posted = ""; | |
break; | |
case "RECENT": | |
$posted = " AND posted <= FROM_UNIXTIME(".$prev_posted.")"; | |
break; | |
case "LATER": | |
$posted = " AND posted >= FROM_UNIXTIME(".$next_posted.")"; | |
break; | |
default: | |
$posted = ""; | |
} | |
$orderby= ($timeframe == "FUTURE") ? " ORDER BY posted asc " : " ORDER BY posted desc "; | |
$orderby= ($sortby == "RANDOM") ? " ORDER BY rand() " : $orderby ; | |
$subpath = preg_quote(preg_replace("/http:\/\/.*(\/.*)/Ui","$1",hu),"/"); | |
$req = preg_replace("/^$subpath/i","/",serverSet('REQUEST_URI')); | |
extract(chopUrl($req)); | |
$showY = ($u2 != "") ? $u2."-" : ""; | |
$showM = ($u3 != "") ? $u3."-" : ""; | |
$showD = ($u4 != "") ? $u4 : ""; | |
if ($showY && is_numeric($u2) && !$thisarticle) $posted = " AND Posted LIKE '".$showY.$showM.$showD."%' "; | |
$where = "status=4 $sections $categories $authors $posted $orderby $offsetsql"; | |
if ($form) { | |
// PAGING INFO | |
$total = getCount("textpattern", $where); | |
$numPages = ($total > 0 && $limit) ? ceil($total/$limit) : 1; | |
$pg = (!$pg) ? 1 : $pg; | |
$offset = ($pg - 1) * $limit; | |
$pageout['pg'] = $pg; | |
$pageout['numPages'] = $numPages; | |
$pageout['s'] = $s; | |
$pageout['c'] = $c; | |
$GLOBALS['thispage'] = $pageout; | |
$res = safe_rows("*, unix_timestamp(Posted) as uPosted", "textpattern", $where." LIMIT ".$offset.",".$limit); | |
if ($res) { | |
foreach($res as $a) { | |
extract($a); | |
populateArticleData($a); | |
$article = fetch('Form', 'txp_form', 'name', $form); | |
$articles[] = parse($article); | |
// FOR PAGING | |
$GLOBALS['uPosted'] = $uPosted; | |
$GLOBALS['limit'] = $limit; | |
unset($GLOBALS['thisarticle']); | |
} | |
return join('',$articles); | |
} | |
} | |
if ($limit) $where.= " LIMIT $limit"; | |
$res = safe_rows("ID, title, authorid, unix_timestamp(Posted) as posted, section, category1, category2, url_title, excerpt, comments_count","textpattern", $where); | |
$lastd = safe_strftime($dateformat, -2208988800); | |
$count=0; | |
$output = array(); | |
if ($res) { | |
$output[] = "<dl"; | |
$output[] = isset($class) ? " class=\"$class\"" : ""; | |
$output[] = isset($id) && ($id) ? " id=\"$id\"" : ""; | |
$output[] = ">"; | |
foreach($res as $a) { | |
$date = safe_strftime($dateformat,$a["posted"]); | |
$subdate = safe_strftime($subdateformat,$a["posted"]); | |
$title = ($a["url_title"]) ? $a["url_title"]: stripSpace($a["title"]); | |
$title = ($url_mode) ? $title : ''; | |
$showtitle = $a["title"]; | |
$section = $a["section"]; | |
$id = $a["ID"]; | |
$cat1 = $a["category1"]; | |
$cat2 = $a["category2"]; | |
$author = $a["authorid"]; | |
$excerpt = $a["excerpt"]; | |
$cc = $a["comments_count"]; | |
if ($showauthor) { | |
$authres = safe_row("realname","txp_users", "name='$author'"); | |
$arealname = $authres["realname"]; | |
} | |
$permlink = permlinkurl($a); | |
$sectionlink = ($url_mode) ? urlencode($section) : '?s='.urlencode($section); | |
$cslink = ($url_mode) ? urlencode($s) : '?s='.urlencode($s); | |
$authorlink = ($url_mode) ? $cslink.'/?author='.urlencode($author) : $cslink.'&author='.urlencode($author); | |
$cat1link = ($url_mode) ? $sectionlink.'/?c='.urlencode($cat1) : $sectionlink.'&c='.urlencode($cat1); | |
$cat2link = ($url_mode) ? $sectionlink.'/?c='.urlencode($cat2) : $sectionlink.'&c='.urlencode($cat2); | |
$cnt = (!$showzerocount && $cc == 0) ? "" : $countprefix.$cc.$countsuffix; | |
$commcount = ($showcommentscount) ? '<span class="rssCmntCnt">'.$cnt.'</span>' : ''; | |
$output[] = ($lastd != $date) ? "<dt>$date</dt>".n : ""; | |
$output[] = "<dd>"; | |
$output[] = ($showsubdate == "1") ? '<span class="rssSubdate">'.$subdate.$subdatesep.'</span>' : ""; | |
$output[] = "<a href=\"$permlink\" title=\"Permanent link to $showtitle\" class=\"rssArticle"; | |
$output[] = (++$count % 2) ? " rssAlt" : ""; | |
$output[] = "\">"; | |
$output[] = "$showtitle</a>"; | |
$output[] = $commcount; | |
$output[] = ($addbreak) ? "<br/>" : ""; | |
$output[] = ($showauthor) ? " $authorsep <a href=\"$authorlink\" title=\"Link to articles by $author\" class=\"rssAuthor\">$arealname</a> " : ""; | |
$output[] = ($showsection) ? " $secstart <a href=\"$sectionlink\" title=\"Link to $section section\" class=\"rssSection\">$section</a> " : ""; | |
$catone = $showcats && $cat1; | |
$cattwo = $showcats && $cat2; | |
$output[] = ($catone) ? " $catstart <a href=\"$cat1link\" title=\"Link to $cat1\" class=\"rssCat\">".fetch_category_title($cat1)."</a> " : ""; | |
$output[] = ($cattwo) ? " $catsep <a href=\"$cat2link\" title=\"Link to $cat2\" class=\"rssCat\">".fetch_category_title($cat2)."</a> " : ""; | |
$output[] = ($showexcerpt) ? "<br/>" . rss_format($excerpt) : ""; | |
$output[] = "</dd>".n; | |
$lastd = $date; | |
} | |
$output[] = "</dl>"; | |
} | |
return ($output) ? implode('', $output) : ''; | |
} | |
function rss_suparchive_bycat($atts) { | |
global $s, $c, $url_mode, $pretext, $siteurl, $id; | |
extract(lAtts(array( | |
'section' => "article", | |
'showheader' => "0", | |
'headerlabel' => "Articles By Category:", | |
'showmenu' => "0", | |
'showcats' => "1", | |
'showcatsonly' => "0", | |
'showcatcount' => "1", | |
'showsections' => "0", | |
'showsectioncount' => "0", | |
'showjump' => "0", | |
'jumplabel' => "^ back to top", | |
'useartcat1' => "0", | |
'useartcat2' => "0", | |
'useartcats' => "0", | |
'limit' => "999999999", | |
'timeframe' => "PAST", | |
'linktosection' => "", | |
'form' => "", | |
'formwraptag' => "", | |
'addbreak' => "0", | |
'showdate' => "0", | |
'dateformat' => "%B %d, %Y", | |
'datesep' => " », ", | |
'showexcerpt' => "0", | |
'showauthor' => "0", | |
'authorsep' => "by ", | |
'showcommentscount' => "0", | |
'showzerocount' => "1", | |
'countprefix' => "", | |
'countsuffix' => "" | |
),$atts)); | |
$section = isset($section) ? $section : ""; | |
$linktosection = ($linktosection) ? $linktosection."/" : ""; | |
if ($useartcat1 || $useartcat2 || $useartcats) { | |
$ca = safe_row('category1, category2', 'textpattern', 'id='.$id); | |
extract($ca); | |
} | |
$catsql = ($useartcat1) ? " AND name = '".$category1."' " : ""; | |
$catsql.= ($useartcat2) ? " AND name = '".$category2."' " : ""; | |
if ($useartcats) { | |
$catsql = " AND (name = '".$category1."' OR name = '".$category2."') "; | |
} else { | |
if ($c && !$showcatsonly) $catsql = " AND name = '".$c."' "; | |
} | |
foreach (explode(',', $section) as $section) | |
{ | |
switch (substr(trim($section), 0, 1)) | |
{ | |
case '*': | |
$sctsql[] = " (section like '%') "; | |
break; | |
case '!': | |
$notsctsql[] = " AND (section != '" . doSlash(str_replace('!','',$section)) . "') "; | |
break; | |
default: | |
$sctsql[] = " (section = '" . doSlash($section) . "') "; | |
break; | |
} | |
} | |
$secsql = ($section != null) ? ' AND (' . join(' OR ', $sctsql) . @join(' AND ', $notsctsql) . ') ' : ''; | |
$subpath = preg_quote(preg_replace("/http:\/\/.*(\/.*)/Ui","$1",hu),"/"); | |
$req = preg_replace("/^$subpath/i","/",serverSet('REQUEST_URI')); | |
extract(chopUrl($req)); | |
$showY = ($u2 != "") ? $u2."-" : ""; | |
$showM = ($u3 != "") ? $u3."-" : ""; | |
$showD = ($u4 != "") ? $u4 : ""; | |
$dateposted = ($showY && is_numeric($u3)) ? " AND Posted LIKE '".$showY.$showM.$showD."%' " : " AND posted < now()"; | |
$q = 'SELECT DISTINCT name FROM '.PFX.'txp_category, '.PFX.'textpattern WHERE name !="default" and type="article" and (category1 = name or category2 = name) '. $catsql.$secsql .'AND status=4 '.$dateposted.' ORDER BY name'; | |
$rsc = getRows($q,""); | |
if ($rsc && $showmenu) { | |
foreach($rsc as $r) { | |
extract($r); | |
$catname = $r["name"]; | |
$cm[] = '<li><a href="#c_'.stripSpace($catname).'">'.fetch_category_title($catname).'</a></li>'.n; | |
} | |
$catmenu = '<ul class="rssCatArchiveMenu">'.implode('', $cm).'</ul>'.n; | |
} | |
$out[] = (!$form) ? '<div id="rssCatArchive">'.n : ''; | |
$out[] = ($showheader) ? '<div id="rssCatArchiveHeader">'.$headerlabel.'</div>'.n : ''; | |
$out[] = ($showmenu) ? $catmenu : ''; | |
$rs = getRows($q,""); | |
if ($rs) { | |
$out[] = (!$form) ? '<div id="rssCatList">'.n : ''; | |
$out[] = ($showcatsonly && !$form) ? '<ul>' : ''; | |
foreach($rs as $a) { | |
extract($a); | |
$catname = $a["name"]; | |
switch ($timeframe) { | |
case "FUTURE": | |
$posted = " AND posted >= now() "; | |
break; | |
case "PAST": | |
$posted = " AND posted < now() "; | |
break; | |
case "ALL": | |
$posted = ""; | |
break; | |
default: | |
$posted = ""; | |
} | |
$posted = ($showY && is_numeric($u3)) ? " AND Posted LIKE '".$showY.$showM.$showD."%' " : $posted; | |
$noidsql = ($useartcat1 || $useartcat2 || $useartcats) ? "id <> ".$id." AND " : ""; | |
$scsql = $noidsql. " (category1 = '" . doSlash($catname) . "' or category2 = '" . doSlash($catname) . "')" .$secsql. " AND status=4 $posted ORDER BY section, posted desc"; | |
$rscnt = safe_rows("*, unix_timestamp(Posted) as uPosted, ID, title, authorid, unix_timestamp(posted) as posted, section, category1, category2, url_title","textpattern", $scsql); | |
$catcnt = ($showcats && $showcatcount) ? " (".count($rscnt).") " : ""; | |
if ($showcatsonly && !$form) { | |
$out[] = ($showcats) ? '<li><a href="'.hu.$linktosection.'?c='.urlencode($catname).'" title="View all articles filed under '.$catname.'">'.fetch_category_title($catname).'</a>'.$catcnt.'</li>'.n : ''; | |
} else { | |
$out[] = ($showcats) ? '<div id="c_'.stripSpace($catname).'" class="rssCcat"><a href="'.hu.$linktosection.'?c='.urlencode($catname).'" title="View all articles filed under '.$catname.'">'.fetch_category_title($catname).'</a>'.$catcnt.'</div>'.n : ''; | |
} | |
if ($form) { | |
// PAGING INFO | |
$total = getCount("textpattern", $scsql); | |
$numPages = ($total > 0 && $limit) ? ceil($total/$limit) : 1; | |
$pg = (!$pg) ? 1 : $pg; | |
$offset = ($pg - 1) * $limit; | |
$pageout['pg'] = $pg; | |
$pageout['numPages'] = $numPages; | |
$pageout['s'] = $s; | |
$pageout['c'] = $c; | |
$GLOBALS['thispage'] = $pageout; | |
$frmWhere = $scsql." LIMIT ".$offset.",".$limit; | |
$res = safe_rows("*, unix_timestamp(Posted) as uPosted", "textpattern", $frmWhere); | |
if ($res) { | |
foreach($res as $b) { | |
extract($b); | |
populateArticleData($b); | |
$article = fetch('Form', 'txp_form', 'name', $form); | |
$articles[] = parse($article); | |
// FOR PAGING | |
$GLOBALS['uPosted'] = $uPosted; | |
$GLOBALS['limit'] = $limit; | |
unset($GLOBALS['thisarticle']); | |
} | |
} | |
$out[] = ($formwraptag) ? tag(join('',$articles), $formwraptag) : join('',$articles); | |
unset($articles); | |
} | |
if (!$form) { | |
if ($limit) $scsql.= " LIMIT $limit"; | |
$rs3 = safe_rows("*, unix_timestamp(Posted) as uPosted, ID, title, authorid, unix_timestamp(posted) as posted, section, category1, category2, url_title, comments_count","textpattern", $scsql); | |
$lasts = ""; | |
} | |
if ($rs3 && !$showcatsonly && !$form) { | |
$out[] = '<ul>'.n; | |
foreach($rs3 as $d) { | |
$aid= $d["ID"]; | |
$asection= $d["section"]; | |
$title = ($d["url_title"]) ? $d["url_title"]: stripSpace($d["title"]); | |
$title = ($url_mode) ? $title : ''; | |
$showtitle = $d["title"]; | |
$postdate = safe_strftime($dateformat,$d["posted"]); | |
$author = $d["authorid"]; | |
$excerpt = $d["excerpt"]; | |
$cc = $d["comments_count"]; | |
$cnt = (!$showzerocount && $cc == 0) ? "" : $countprefix.$cc.$countsuffix; | |
$commcount = ($showcommentscount) ? '<span class="rssCmntCnt">'.$cnt.'</span>' : ''; | |
$authres = safe_row("realname","txp_users", "name='$author'"); | |
$arealname = $authres["realname"]; | |
$permlink = permlinkurl($d); | |
if ($lasts != $asection && $showsections) { | |
$sctcnt = ($showsectioncount) ? " (".count($rs3).")" : ""; | |
$out[] = '<li><div class="rssCsec">in <a href="'.hu.$asection.'/?c='.$catname.'" title="View articles filed under '.$catname.' in '.$asection.'">'.$asection.'</a>'.$sctcnt.'</div></li>'.n; | |
$cnt = 1; | |
} | |
$out[] = '<li class="rssCart">'; | |
$out[] = '<a href="'.$permlink.'" title="Permanent link to '.$showtitle.'">'.$showtitle.'</a>'; | |
$out[] = $commcount; | |
$out[] = ($addbreak) ? "<br/>" : ""; | |
$out[] = ($showauthor) ? $authorsep.$arealname : ""; | |
$out[] = ($showdate) ? '<span class="rssSubdate">'.$datesep.$postdate.'</span>' : ''; | |
$out[] = ($showexcerpt) ? "<br/>$excerpt" : ""; | |
$out[] = '</li>'.n; | |
$cnt++; | |
$lasts = $asection; | |
} | |
$out[] = '</ul>'.n; | |
$out[] = ($showjump) ? '<div class="rssJump"><a href="#rssCatArchive">'. $jumplabel .'</a></div>' : ''; | |
} | |
} | |
$out[] = ($showcatsonly && !$form) ? '</ul>' : ''; | |
$out[] = (!$form) ? n.'</div>'.n.'</div>'.n : ''; | |
} | |
return ($out) ? implode('', $out) : ''; | |
} | |
function rss_format($string) { | |
global $txpcfg; | |
include_once txpath.'/lib/classTextile.php'; | |
$textile = new Textile(); | |
return (USE_TEXTILE == true ? $textile->TextileThis($string) : $string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment