<?php
// plugin needs to work on Nucleus versions <=2.0 as well
if (!function_exists('sql_table')){
function sql_table($name) {
return 'nucleus_' . $name;
}
}
class NP_ShowBlogs extends NucleusPlugin {
function getEventList() { return array(); }
function getName() { return 'Show Blogs for Sub Categories '; }
function getAuthor() { return 'Taka + nakahara21'; }
function getURL() { return 'http://reverb.jp/vivian/download.php?itemid=NP_MultipleCategories'; }
function getVersion() { return '2.01 scat'; }
function getDescription() {
return 'This plugin displays items of ALL or EACH blogs, and the link to other pages. <br />"MultipleCategories" supported! (NP_MultipleCategories v0.15 is required.)<br />Usage: <%ShowBlogs(grey/short,15,all,2,DESC,6/15/56/186,grey/stick)%>';
}
function supportsFeature($what) {
switch($what){
case 'SqlTablePrefix':
return 1;
default:
return 0;
}
}
function install() {
$this->createOption('catnametoshow', '[allblog mode only] category name to show (0:catname on blogname, 1:catname only, 2:blogname only)','text','0');
$this->createOption('stickmode','[currentblog mode only] 0:show all stickyID, 1:show current blog stickyID only','text','1');
}
function doSkinVar($skinType, $template = 'grey/short', $amount = 10, $bmode = '', $type = 1, $sort = 'DESC', $sticky = '', $sticktemplate = '') {
global $manager, $blog, $CONF, $catid, $blogid, $archive;
$params = func_get_args();
if (is_numeric($params[3])){ $type = intval($params[3]); }
if($sort == 'ASC'){
$sort = 'ASC';
}else{
$sort = 'DESC';
}
if($sticktemplate == '') $sticktemplate = $template;
/***************************************
extra setting
***************************************/
/* blogid(blogshortname) you want to hide
example:
$hide =array(5)
$hide = array(3,5);
$hide = array('private');
$hide =array('private','atloss');
*/
$hide = array();
/* limit number of pages(months)
Please delete the character '//' of the head of the following.
*/
//$pagelimit = 10;
//$monthlimit = 12;
/**************************************/
switch($skinType){
case 'index':
case 'archive':
$params = func_get_args();
switch($amount){
case 'all':
$bmode = $amount;
if(is_numeric($params[3])) $type = $params[3];
break;
case '0':
$type = $amount;
break;
}
$type = intval($type);
list($pageamount, $offset) = sscanf($amount, '%d(%d)');
if(!$pageamount) $pageamount = 10;
if (isset($monthlimit)) {
$monthlimit = intval($monthlimit);
} else {
$monthlimit = 0;
}
if (isset($pagelimit)) {
$pagelimit = intval($pagelimit);
} else {
$pagelimit = 0;
}
if($blog){
$b =& $blog;
}else{
$b =& $manager->getBlog($CONF['DefaultBlog']);
}
$where = '';
if($bmode != 'all') $where .= ' and i.iblog='.intval($b->getID());
$query .= ' and i.idraft=0';
if(!$catid && $sticky != ''){
$stickys = explode('/',$sticky);
foreach($stickys as $stickynumber){
$where .= ' and i.inumber<>'.$stickynumber;
}
}
$hidden = '';
if($archive){
$hidden .= '<input type="hidden" name="archive" value="'.htmlspecialchars($archive).'" />'."\n";
sscanf($archive,'%d-%d-%d',$y,$m,$d);
if ($d) {
$timestamp_start = mktime(0,0,0,$m,$d,$y);
$timestamp_end = mktime(0,0,0,$m,$d+1,$y);
} else {
$timestamp_start = mktime(0,0,0,$m,1,$y);
$timestamp_end = mktime(0,0,0,$m+1,1,$y);
}
$where .= ' and i.itime>=' . mysqldate($timestamp_start)
. ' and i.itime<' . mysqldate($timestamp_end);
}elseif($monthlimit){
$timestamp_end = mysqldate($b->getCorrectTime());
sscanf($timestamp_end,'"%d-%d-%d %s"',$y,$m,$d,$temp);
$timestamp_start = mktime(0,0,0,$m-$monthlimit,$d,$y);
$where .= ' and i.itime>=' . mysqldate($timestamp_start)
. ' and i.itime<=' . $timestamp_end;
}else{
$where .= ' and i.itime<=' . mysqldate($b->getCorrectTime());
}
if($catid){
$hidden .= '<input type="hidden" name="catid" value="'.intval($catid).'" />'."\n";
if ($manager->pluginInstalled('NP_MultipleCategories')) {
$where .= ' and ((i.inumber=p.item_id and (p.categories REGEXP "(^|,)'.intval($catid).'(,|$)" or i.icat='.intval($catid).')) or (i.icat='.intval($catid).' and p.item_id IS NULL))';
$mtable = ' LEFT JOIN '.sql_table('plug_multiple_categories').' as p ON i.inumber=p.item_id';
$mplugin =& $manager->getPlugin('NP_MultipleCategories');
global $subcatid;
if ($subcatid && method_exists($mplugin,"getRequestName")) {
$where .= ' and p.subcategories REGEXP "(^|,)'.intval($subcatid).'(,|$)"';
}
} else {
$where .= ' and i.icat='.intval($catid);
}
}
if($blogid) $hidden .= '<input type="hidden" name="blogid" value="'.intval($blogid).'" />'."\n";
if($hide[0] && $bmode=='all'){
foreach($hide as $val){
if(gettype($val) == 'string'){
$val = getBlogIDFromName($val);
}
$where .= ' and i.iblog!='.intval($val);
}
}
$startpos = 0;
$uri = sprintf("%s%s%s","http://",serverVar("HTTP_HOST"),serverVar("REQUEST_URI"));
list($pagelink, $currentpage) = explode("page=",$uri);
$currentpage = intval($currentpage);
$pagelink = rawurldecode($pagelink);
$pagelink = stripslashes($pagelink);
$pagelink = preg_replace('|[^a-z0-9-~+_.?#=&;,/:@%]|i', '', $pagelink);
if($currentpage>0){
$startpos = ($currentpage-1) * $pageamount;
}else{
$currentpage = 1;
$uri = parse_url($pagelink);
if($uri['query']){
$pagelink .= '&';
$pagelink = str_replace('&&','&',$pagelink);
}else{
$pagelink .= '?';
}
}
// select
$query = 'SELECT COUNT(i.inumber)'
. ' FROM '.sql_table('item').' as i'.$mtable
. ' WHERE i.idraft=0'
. $where;
$totalamount = 0;
$entries = sql_query($query);
if($row = mysql_fetch_row($entries)) $totalamount = $row[0];
if(!$archive && $pagelimit && ($pagelimit*$pageamount < $totalamount)){
$totalamount = $pagelimit*$pageamount;
}
if($offset){
$startpos += $offset;
$totalamount -= $offset;
}
$totalpages = ceil($totalamount/$pageamount);
if($startpos > $totalamount){
$currentpage = $totalpages;
$startpos = $totalamount-$pageamount;
}
if($type >= 1){ //--------------------------------------------------------------
if($CONF['URLMode'] == 'pathinfo'){
// $buf = '<form method="get" action="'.substr($pagelink,0,-1).'">'."\n";
$buf .= '<div class="pageswitch">'."\n";
}else{
// $buf = '<form method="get" action="'.$CONF['Self'].'">'."\n";
$buf .= '<div class="pageswitch">'."\n";
// $buf .= $hidden;
}
$currentpage > 1 ? $prevpage = $currentpage - 1 : $prevpage = 0;
$nextpage = $currentpage + 1;
if($prevpage){
$prevpagelink = $pagelink. 'page=' . $prevpage;
$buf .= "\n".'<a href="'.$prevpagelink.'" title="Previous">«Prev</a>';
}
$buf .= "\n |";
if($type >= 2){
for($i=1; $i<=$totalpages; $i++){
if($i == $currentpage){
$buf .= " <strong>{$currentpage}</strong> |\n";
}elseif($totalpages<10 || $i<4 || $i>$totalpages-3){
$buf .= ' <a href="'.$pagelink. 'page=' . $i.'">'.$i.'</a> |'."\n";
}else{
if($i<$currentpage-1 || $i>$currentpage+1){
if(($i==4 && ($currentpage>5 || $currentpage==1)) || $i==$currentpage+2){
$buf .= '...|'."\n";
}
}else{
$buf .= ' <a href="'.$pagelink. 'page=' . $i.'">'.$i.'</a> |';
}
}
}
// if($totalpages>=10){
// $buf .= '<input type="text" name="page" size="1" maxlength="3" title="Input page number and press Enter" style="width:20px;" />'."\n";
// }
} // type2 end
if($totalpages >= $nextpage){
$nextpagelink = $pagelink. 'page=' . $nextpage;
$buf .= ' <a href="'.$nextpagelink.'" title="Next">Next»</a>'."\n";
}
$buf .= "</div>\n";
// $buf .= "</form>\n";
echo $buf;
}// type1 end -------------------------------------------------------
//==sticky start============
if($startpos == 0 && !$catid && $sticky != '' ){
foreach($stickys as $stickynumber){
$tempblogid = getBlogIDFromItemID($stickynumber);
$query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, UNIX_TIMESTAMP(i.itime) as timestamp, i.itime, i.imore as more, m.mnumber as authorid,' ;
if($bmode != 'all'){
$query .= ' c.cname as category,' ;
}else{
$query .= ' b.bname as category,' ;
// $query .= ' concat(c.cname, " on ", ifnull(b.bname,"")) as category,' ;
}
$query .= ' i.icat as catid, i.iclosed as closed' ;
$query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' ;
if($bmode == 'all'){
$query .= ', '.sql_table('blog').' as b ';
}
$query .= ' WHERE i.iauthor=m.mnumber'
. ' and i.icat=c.catid';
if($bmode == 'all'){
$query .= ' and b.bnumber = c.cblog';
}
$query .= ' and i.inumber='.$stickynumber;
$query .= ' and i.itime<=' . mysqldate($b->getCorrectTime());
$query .= ' and i.idraft=0';
if($bmode == 'all'){
$b->showUsingQuery($sticktemplate, $query, 0, 1, 0);
}elseif($this->getOption('stickmode') == 1 && $b->getID() == $tempblogid){
$b->showUsingQuery($sticktemplate, $query, 0, 1, 0);
}elseif(!$this->getOption('stickmode')){
$b->showUsingQuery($sticktemplate, $query, 0, 1, 0);
}
}
}
//==sticky end==============
$query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, UNIX_TIMESTAMP(i.itime) as timestamp, i.itime, i.imore as more, m.mnumber as authorid,' ;
if($bmode != 'all'){
$query .= ' c.cname as category,' ;
}else{
if($this->getOption('catnametoshow') == 2){
$query .= ' b.bname as category,' ;
}elseif($this->getOption('catnametoshow') == 1){
$query .= ' c.cname as category,' ;
}else{
$query .= ' concat(c.cname, " on ", ifnull(b.bname,"")) as category,' ;
}
}
$query .= ' i.icat as catid, i.iclosed as closed' ;
$query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'.$mtable ;
if($bmode == 'all'){
$query .= ', '.sql_table('blog').' as b ';
}
$query .= ' WHERE i.iauthor=m.mnumber'
. ' and i.icat=c.catid'
. $where ;
if($bmode == 'all'){
$query .= ' and b.bnumber = c.cblog';
}
$query .= ' and i.idraft=0';
$query .= ' ORDER BY i.itime '.$sort;
if ($pageamount > 0){
$query .= ' LIMIT ' . $startpos .',' . $pageamount;
}
$b->showUsingQuery($template, $query, 0, 1, 1);
if($type >= 1) echo $buf;
break;
}// switch end
}// doSkinVar end
}
?>
Plugins :: NP_ShowBlogs