<? class NP_BlogTimes extends NucleusPlugin { function getName() { return 'BlogTimes'; } function getAuthor() { return 'type613 + nakahara21'; } function getURL() { return 'http://tankyard.xrea.jp/'; } function getVersion() { return '1.0'; } function getDescription() { return 'BlogTimes Graphic Generate. use GD.<%BlogTimes(blogid,catid,height,width,padding,bordercolor,basecolor,linecolor,show_text,textcolor,font_id)%> '; } function supportsFeature($what) { switch($what){ case 'SqlTablePrefix': return 1; default: return 0; } } /** * On plugin install, three options are created */ function install() { // create some options // $this->createOption('Path','Graphic Generate PHP Path','text','./gdblogtimes.php'); $this->createOption('BlogId','Display Blog id(0=all,null=current)','text',''); $this->createOption('CategoryId','Display CategoryId(0=all,null=current)','text',''); $this->createOption('Height','Height','text','30'); $this->createOption('Width','Width','text','400'); $this->createOption('Padding','Padding','text','5'); $this->createOption('BorderColor','BorderColor(#rrggbb)','text','#757575'); $this->createOption('BaseColor','BaseColor(#rrggbb)','text','#757575'); $this->createOption('LineColor','LineColor(#rrggbb)','text','#ffffff'); $this->createOption('Show text','Display TextLabel(on/off)','text','on'); $this->createOption('TextColor','TextColor(#rrggbb)','text','#757575'); $this->createOption('FontId','Default Font ID(1-5)','text','1'); } function init(){ $this->php_path = $this->getOption('Path'); $this->pblogid = $this->getOption('BlogId'); $this->pcatid = $this->getOption('CategoryId'); $this->height = $this->getOption('Height'); $this->width = $this->getOption('Width'); $this->padding= $this->getOption('Padding'); $this->bocolor= $this->getOption('BorderColor'); $this->bscolor= $this->getOption('BaseColor'); $this->lncolor= $this->getOption('LineColor'); $this->show_text= $this->getOption('Show_text'); $this->txcolor= $this->getOption('TextColor'); $this->fontid= $this->getOption('FontId'); } /** * skinvar parameters: * - blogname (optional) */ function doSkinVar($skinType,$pblogid='',$pcatid='',$height='',$width='',$padding='',$bocolor='',$bscolor='',$lncolor='',$show_text='',$txcolor='',$fontid=''){ global $manager, $blog, $CONF, $catid, $DIR_PLUGINS,$catid,$archive; if($blog){ $b =& $blog; }else{ $b =& $manager->getBlog($CONF['DefaultBlog']); } $blogid = $b->getID(); switch($skinType){ case 'archive': sscanf($archive,'%d-%d-%d',$y,$m,$d); $time = mktime(0,0,0,$m,1,$y); break; default: $time = $b->getCorrectTime(time()); } $date = getDate($time); $month = $date['mon']; $year = $date['year']; //初期化 if($pblogid == '') $pblogid = $this->pblogid; if($pblogid == '') $pblogid = $blogid; if($pcatid == '') $pcatid = $this->pcatid ; if($pcatid == '') $pcatid = $catid; if($height == '') $height = $this->height; if($width == '') $width = $this->width; if($padding == '') $padding = $this->padding ; if($bocolor == '') $bocolor = $this->bocolor; if($bscolor == '') $bscolor = $this->bscolor ; if($lncolor == '') $lncolor = $this->lncolor; if($txcolor == '') $txcolor = $this->txcolor; if($show_text == '') $show_text = $this->show_text; if($fontid == '') $fontid = $this->fontid; $bocolor = str_replace('#','',$bocolor); $bscolor = str_replace('#','',$bscolor); $lncolor = str_replace('#','',$lncolor); $txcolor = str_replace('#','',$txcolor); $php_path = $CONF['PluginURL'] . 'blogtimes/blogtime-'.$pblogid.'-'.$pcatid.'.png'; // $this->doPNG($pblogid, $pcatid, $height, $width, $padding, $bocolor, $bscolor, $lncolor); ?> <img src="<?php echo $CONF['ActionURL'];?>?action=plugin&name=BlogTimes&pblogid=<?=$pblogid?>&pcatid=<?=$pcatid?>&height=<?=$height?>&width=<?=$width?>&padding=<?=$padding?>&bocolor=<?=$bocolor?>&bscolor=<?=$bscolor?>&lncolor=<?=$lncolor?>&show_text=<?=$show_text?>&txcolor=<?=$txcolor?>&month=<?=$month?>&year=<?=$year?>&fontid=<?=$fontid?>" ALT="B L O G T I M E S" /> <? //echo '<img src="' . $CONF['PluginURL'].'NP_BlogTimes.php" />'; } function doAction($type) { $pblogid = requestVar('pblogid'); $pcatid = requestVar('pcatid'); $height = requestVar('height'); $width = requestVar('width'); $padding = requestVar('padding'); $bocolor = requestVar('bocolor'); $bscolor = requestVar('bscolor'); $lncolor = requestVar('lncolor'); $show_text = requestVar('show_text'); $txcolor = requestVar('txcolor'); $fontid = requestVar('fontid'); $month = requestVar('month'); $year = requestVar('year'); $this->doPNG($pblogid, $pcatid, $height, $width, $padding, $bocolor, $bscolor, $lncolor,$show_text,$txcolor,$year,$month,$fontid); } function doPNG($_blogid,$_catid,$_height,$_width,$_padding,$_bordercolor,$_basecolor,$_linecolor,$_show_text,$_textcolor,$year,$month,$_font_id){ global $CONF, $manager, $DIR_PLUGINS; $blogid=0; $catid=0; $height='30'; $width='400'; $padding='5'; $bordercolor=''; $basecolor='#757575'; $linecolor='#FFffff'; $show_text='on'; $textcolor='#757575'; $font_id = 1 ; /* default font id(1-5)*/ if($_blogid != '') $blogid = $_blogid; if($_catid != '') $catid = $_catid; if($_height != '') $height = $_height; if($_width != '') $width = $_width; if($_padding != '') $padding = $_padding ; if($_bordercolor != '') $bordercolor = $_bordercolor; if($_basecolor != '') $basecolor = $_basecolor ; if($_linecolor != '') $linecolor = $_linecolor ; if($_show_text != '') $show_text = $_show_text ; if($_textcolor != '') $textcolor = $_textcolor ; if($_font_id != '') $font_id = $_font_id ; $query = 'SELECT hour(itime) as hour, minute(itime) as minute FROM ' .sql_table('item') . ' WHERE idraft=0' . ' and year(itime) ='.$year . ' and month(itime) = '.$month; // don't show draft items if($blogid != 0) $query .= ' and iblog='.$blogid ; if($catid != 0) $query .= ' and icat='.$catid ; $res = sql_query($query); #オリジナル互換 $txtpad = ($show_text != 'on')? 0 : imageFontHeight($font_id); $scale_width = $width+($padding*2); $scale_height= $height+($padding*2)+($txtpad*2); $img = ImageCreate($scale_width,$scale_height) or die ("Cannnot Initialize new GD image stream"); //色設定 $white = ImageColorAllocate($img,255,255,255); ImageColorTransparent($img,$white); $bgarray = $this->hex2dec($bordercolor); $bocol = ImageColorAllocate($img,$bgarray[0],$bgarray[1],$bgarray[2]); $bsarray = $this->hex2dec($basecolor); $bscol = ImageColorAllocate($img,$bsarray[0],$bsarray[1],$bsarray[2]); $lnarray = $this->hex2dec($linecolor); $lncol = ImageColorAllocate($img,$lnarray[0],$lnarray[1],$lnarray[2]); $txarray = $this->hex2dec($textcolor); $txcol = ImageColorAllocate($img,$txarray[0],$txarray[1],$txarray[2]); $line_y1 = $padding+$txtpad; $line_y2 = $padding+$txtpad+$height-1; ImageFilledRectangle($img,0,0,$scale_width-1,$scale_height-1,$white); if($bordercolor != ''){ ImageRectangle($img,0,0,$scale_width-1,$scale_height-1,$bocol); } ImageFilledRectangle($img,$padding,$line_y1,$padding+$width-1,$line_y2,$bscol); while ($current = mysql_fetch_object($res)) { $hour = $current->hour ; $minute = $current->minute ; $line_x= $padding + (round(($hour*60+$minute)/(24*60) * $width)) ; ImageLine($img,$line_x,$line_y1,$line_x,$line_y2,$lncol); } mysql_free_result($res); #text出力 if($show_text == 'on'){ if($width >= 140){ $ruler_y = $padding+$txtpad+$height; for($i=0;$i <= 23;$i+=2){ $ruler_x = $padding+round($i*$width/24); ImageString($img,$font_id,$ruler_x,$ruler_y,$i,$txcol); } ImageString($img,$font_id,$padding+$width-4,$ruler_y,"0",$txcol); $caption_x = $padding; $caption_y = $padding; $caption = "B L O G T I M E S ".$year."/".$month; imageString($img,$font_id,$caption_x,$caption_y,$caption,$txcol); }else{ $ruler_y = $padding+$txtpad+$height; for($i=0;$i<=23;$i+=6){ $ruler_x = $padding+round($i*$width/24); imageString($img,$font_id,$ruler_x,$ruler_y,$i,$txcol); } imageString($img,$font_id,$padding+$width-4,$ruler_y,"0",$txcol); $caption_x = $padding; $caption_y = $padding-1; $caption = $year."/".$month; imageString($img,$font_id,$caption_x,$caption_y,$caption,$txcol); } } /* pngの出力 */ Header("Content-type: image/png"); Header("Cache-control: no-cache"); ImagePng($img); /* ob_start(); imagepng($img); $im = ob_get_contents(); ob_end_clean(); return $im; */ /* $fname = $DIR_PLUGINS . 'blogtimes/blogtime-'.$blogid.'-'.$catid.'.png'; if(ImagePng($img,$fname)){ // echo '<a href="'.$fname.'">here</a>'; }else{ echo $fname.'bad'; } */ /* メモリの解放 */ ImageDestroy($img); } function hex2dec($hex){ $color = str_replace('#','',$hex); $ret = array(); $ret[0]= hexdec(substr($color,0,2)); $ret[1]= hexdec(substr($color,2,2)); $ret[2]= hexdec(substr($color,4,2)); return $ret; } } ?>