plugins:itemnumber:itemnumber_code

NP_ItemNumber.phpのソースコード

<?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_ItemNumber extends NucleusPlugin { 
   function getEventList() { return array(); } 
   function getName() { return 'ItemNumber'; } 
   function getAuthor() { return 's.fjsk'; } 
   function getURL() { return 'http://japan.nucleuscms.org/bb/viewtopic.php?p=3491#3491'; } 
   function getVersion() { return '0.1'; } 
   function getDescription() { 
      return 'item Counter. &lt;%ItemNumber(all,11/15)%&gt;'; 
   } 
   function supportsFeature($what) { 
      switch($what){ 
         case 'SqlTablePrefix': 
            return 1; 
         default: 
            return 0; 
      } 
   } 
 
   function doTemplateVar(&$item, $cmode = "", $countblog = ''){ 
      global $manager; 
      $itemid = $item->itemid; 
//      $catid = $item->catid;
      $itemtime = date('Y-m-d H:i:s',$item->timestamp); 
      $sql = 'select count(*) as cnt from '.sql_table('item').' where'; 
      if($cmode == 'time'){ 
         $sql .= ' itime <= "'.$itemtime.'"'; 
      }else{ 
         $sql .= ' inumber <= "'.$itemid.'"'; 
      } 
      switch ($countblog){ 
         case "all" : 
            $sql .= ''; 
            break; 
         case "" : 
            $sql .= ' and iblog = '.getBlogIDFromItemID($itemid); 
//            $sql .= ' and icat = '.$catid; 
            break; 
         default : 
            $cblogs = explode('/', $countblog); 
            if(!$cblogs[1]){ 
               $sql .= ' and iblog = '.$cblogs[0]; 
            }else{ 
               $sql .= ' and (iblog = '.$cblogs[0]; 
               for($s=1;$s<count($cblogs);$s++){ 
                  $sql .= ' or iblog = '.$cblogs[$s]; 
               } 
               $sql .=')'; 
            } 
         } 
      $rs = mysql_query($sql); 
      $numarry =mysql_fetch_object($rs); 
      $num = $numarry -> cnt; 
      echo $num; 
   } 
} 
?>

カテゴリで絞込みを行う動作に変更したい場合

コメントアウトしてある2行を解除する

 
plugins/itemnumber/itemnumber_code.txt · 最終更新: 2011/03/23 21:28 (外部編集)