4 // 0.2: $archive, $blogid and $catid suppot ($exmode=all ready)
7 // Initialize $this->exquery
10 // 0.5: use createGlobalArchiveLink
11 // sql_table support :-P
12 // 0.6: support gif format
13 // print archive month for the first
14 // 0.7: linkmode: [0]archive day link, [1]item link for the image
17 // plugin needs to work on Nucleus versions <=2.0 as well
18 if (!function_exists('sql_table')){
19 function sql_table($name) {
20 return 'nucleus_' . $name;
25 class NP_ImageCalendar extends NucleusPlugin {
26 function getName () {return 'ImageCalendar'; }
27 function getAuthor () {return 'nakahara21'; }
28 function getURL () {return 'http://nakahara21.com/';}
29 function getVersion () {return '0.7';}
30 function supportsFeature($what) {
32 case 'SqlTablePrefix':
38 function getDescription () {
39 return 'Embed the image of day into Calendar.';
44 $this->createOption('default_catname','Default Category Name.','text','');
49 $this->fileex = array('.gif','.jpg','.png');
50 $this->linkmode = 0; // create link for image [0]archive day link, [1]item link for the image
54 function doSkinVar($skinType, $cnt=1, $wsize=50, $hsize=35, $point=0, $exmode=0) {
58 $b =& $manager->getBlog($CONF['DefaultBlog']);
60 if($cnt=='') $cnt = 1;
61 if($hsize=='') $hsize = 80;
62 if($wsize=='') $wsize = 80;
63 if($exmode != 'all') $exmode = 0;
64 if($point != 'lefttop') $point = 0;
70 sscanf($archive,'%4c-%2c-%2c',$year,$month,$day);
72 $timestamp_start = mktime(0,0,0,$month,1,$year);
73 $timestamp_end = mktime(0,0,0,$month+1,1,$year); // also works when $month==12
75 $timestamp_start = mktime(0,0,0,$month,$day,$year);
76 $timestamp_end = mktime(0,0,0,$month,$day+1,$year);
78 $this->exquery .= ' and itime>=' . mysqldate($timestamp_start)
79 . ' and itime<' . mysqldate($timestamp_end);
80 $monthForPrint = getDate(mktime (0,0,0,$month,1, $year));
86 $this->exquery .= ' and iblog =' . $b->getID();
88 if($catid) $this->exquery .= ' and icat =' . $catid;
94 $this->imglists = array();
95 $this->imgfilename = array();
96 if(!($filelist = $this->listup())){
97 echo 'No images here.';
100 // print_r($filelist);
103 foreach($filelist as $key => $value){
104 // $itemlink = createItemLink($value[1], '');
105 $archivedaylink = createArchiveLink($b->getID(),$key,'');
108 if($point) $exq = '&pnt=lefttop';
110 echo '<a href="'.$archivedaylink.'">';
111 echo '<img src="'.$CONF['ActionURL'].'?action=plugin&name=ImageCalendar&type=draw&p='.$value[0].'&wsize='.$wsize.'&hsize='.$hsize.$exq.'" />';
118 //==Calendar start==============
121 $wakurgb = $this->func_SetRgbValueFromHex($waku);
122 $wakugr = $this->func_GetRgbFamilyFromRgb($waku,3,23,5);
125 <style type="text/css">
127 table.imgcalendar th{
128 FONT-FAMILY: verdana, arial, sans-serif;
132 background-color:<?php echo $waku; ?>;
133 color:RGB(<?php echo $wakugr[9]; ?>);
135 table.imgcalendar th.monthname{
137 background-color:RGB(<?php echo $wakugr[2]; ?>);
138 border:0px solid RGB(<?php echo $wakugr[2]; ?>);
141 width : <?php echo $wsize; ?>px;
142 height : <?php echo $hsize; ?>px;
143 Vertical-align: middle;
147 background-color:none;
148 border: 1px solid RGB(<?php echo $wakurgb; ?>);
149 FONT-FAMILY: verdana, arial, sans-serif;
152 COLOR: <?php echo $waku; ?>;
155 width : <?php echo $wsize; ?>px;
160 background-color:RGB(<?php echo $wakugr[8]; ?>);
161 border: 1px solid <?php echo $waku; ?>;
169 height : <?php echo $hsize; ?>px;
172 width : <?php echo $wsize; ?>px;
173 height : <?php echo $hsize; ?>px;
174 background-color:silver;
177 FONT-FAMILY: verdana, arial, sans-serif;
180 COLOR: RGB(<?php echo $wakugr[2]; ?>);
181 background-color:#fff;
182 border-right: 1px solid <?php echo $waku; ?>;
183 border-bottom: 1px solid <?php echo $waku; ?>;
192 $monthForPrint = ($monthForPrint)? $monthForPrint: getDate($b->getCorrectTime());
194 for($a=0;$a<$cnt;$a++){
195 $p_month = date("Y-m",mktime(0,0,0,$monthForPrint['mon']-$a,1,$monthForPrint['year']));
196 sscanf($p_month,'%4c-%2c',$year,$month);
197 $date = getDate(mktime (0,0,0,$month,1, $year));
199 $out = '<table class="imgcalendar"><tr><th colspan="7" class="monthname">'.$p_month.'</th></tr><tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr><tr>';
200 while (checkdate($date['mon'], $d, $date['year'])){
201 $p = date("w",mktime(0,0,0,$date['mon'],$d,$date['year']));
202 $di = date("Y-m-d",mktime(0,0,0,$date['mon'],$d,$date['year']));
203 if($d == 1) for($s=0;$s<$p;$s++){ $out .= '<td class="empcell">*</td>';} // filling
204 if(!$p) $out .= "</tr><tr>";
205 $out .= '<td class="imgcell">';
209 $linkurl = createItemLink($filelist[$di][1],'');
210 $itemtitle = quickQuery('SELECT ititle as result FROM '.sql_table('item').' WHERE inumber='.intval($filelist[$di][1]));
211 $alt = shorten(strip_tags($itemtitle),25,'..');
213 $linkurl = $this->createGlobalArchiveLink($filelist[$di][2],$di,'');
217 $out .= '<div class="d">'.$d.'</div>';
218 $out .= '<DIV class=cellimg>';
219 $out .= '<a href="'.$linkurl.'">';
220 $out .= '<img src="'.$CONF['ActionURL'].'?action=plugin&name=ImageCalendar&type=draw&p='.$filelist[$di][0].'&wsize='.$wsize.'&hsize='.$hsize.'" alt="'.$alt.'" />';
224 $out .= '<div class="d">'.$d.'</div>';
228 $out .= '<div class="cellspacer"> <div>';
230 if($d == date("t",mktime(0,0,0,$date['mon'],$d,$date['year']))) for($s=$p+1;$s<=6;$s++){ $out .= '<td class="empcell">*</td>';} // filling
233 $out .= '</tr></table>';
236 //==Calendar end==============
240 //==color manegagement start==========
241 function func_SetRgbValueFromHex ($pHexColor)
244 // $pHexColor : ie #339933
247 // Source : Rini Setiadarma, http://www.oodie.com/
249 $l_returnarray = array ();
250 $pHexColor = str_replace ("#", "", $pHexColor);
251 for ($l_counter=0; $l_counter<3; $l_counter++){
252 $l_temp = substr($pHexColor, 2*$l_counter, 2);
253 $l_returnarray[$l_counter] = 16 * hexdec(substr($l_temp, 0, 1)) + hexdec(substr($l_temp, 1, 1));
255 return implode(",",$l_returnarray);
258 function func_GetRgbFamilyFromRgb ($pHexColor, $pPrimary, $pIncrement, $pNum){
261 $pHexColor = str_replace ("#", "", $pHexColor);
262 for ($l=0; $l<3; $l++){
263 $l_temp = substr($pHexColor, 2*$l, 2);
264 $rgbarr[$l] = 16 * hexdec(substr($l_temp, 0, 1)) + hexdec(substr($l_temp, 1, 1));
266 $pRgbColor = implode(",",$rgbarr);
270 // $pRgbColor : ie 255,255,255 ; $pPrimary = pos. int (0-3); $pIncrement = pos. int ; $pNum = pos. int
272 // array family from input
274 $l_returnarray = array();
275 $l_rgbarray = explode (",",$pRgbColor);
276 if (($l_rgbarray != array ()) AND (count ($l_rgbarray) == 3))
278 $l_start = $l_basevalue - ($pNum*$pIncrement);
279 $l_end = $l_basevalue + ($pNum*$pIncrement);
285 $l_startin = $pPrimary;
286 $l_endin = $pPrimary;
288 for ($l_counter=$l_start;$l_counter<$l_end;$l_counter = $l_counter+$pIncrement)
290 $l_rgbarraytemp = $l_rgbarray;
291 for ($l_counterint=$l_startin;$l_counterint<=$l_endin;$l_counterint++){
292 $l_value = $l_rgbarray[$l_counterint]+$l_counter;
293 if ($l_value < 0) $l_value = 0;
294 if ($l_value > 255) $l_value = 255;
295 $l_rgbarraytemp[$l_counterint] = $l_value;
297 if ($l_rgbarraytemp != array ()) $l_returnarray[] = implode (",",$l_rgbarraytemp);
300 return $l_returnarray;
303 //==color manegagement end==========
310 $b =& $manager->getBlog($CONF['DefaultBlog']);
312 $query = 'SELECT inumber as itemid, ititle as title, ibody as body, iauthor, itime, imore as more, iblog, ' ;
313 $query .= ' icat as catid, iclosed as closed' ;
314 $query .= ' FROM '.sql_table('item');
315 $query .= ' WHERE idraft=0';
316 $query .= ' and itime <=' . mysqldate($b->getCorrectTime()); // don't show future items!
317 $query .= $this->exquery;
318 $query .= ' ORDER BY itime DESC';
320 $res = sql_query($query);
322 if(!mysql_num_rows($res)) return FALSE;
324 while ($it = mysql_fetch_object($res)){
325 $txt = $it->body.$it->more;
326 $item_ymd = date("Y-m-d",strtotime($it->itime));
327 preg_match_all("/\<\%image\((.*)\)\%\>/Us",$txt,$imgpnt,PREG_PATTERN_ORDER);
328 @array_walk($imgpnt[1], array(&$this, "exarray"), array($it->itemid,$it->iauthor,$item_ymd,$it->iblog));
330 return $this->imglists;
333 function exarray($imginfo,$key,$iaid){
334 $imginfo = explode("|",$imginfo);
335 if(!in_array(strtolower(strrchr($imginfo[0], "." )),$this->fileex)) return;
336 // if(in_array($imginfo[0],$this->imgfilename)) return;
337 // $this->imgfilename[] = $imginfo[0];
338 list($iid,$auid,$item_ymd,$iblog) = $iaid;
339 if (!strstr($imginfo[0],'/')) {
340 $imginfo[0] = $auid . '/' . $imginfo[0];
342 // $this->imglists[] = array($imginfo,$iaid[0]);
343 // $this->imglists[] = array($imginfo[0],$iaid[0],$iaid[2]);
344 $this->imglists[$item_ymd] = array($imginfo[0],$iid,$iblog);
347 function baseimageCreate($p,$imgtype){
350 return ImageCreateFromGif($p);
352 return ImageCreateFromJpeg($p);
354 return ImageCreateFromPng($p);
360 function doAction($type) {
363 $return = serverVar('HTTP_REFERER');
366 if(!requestVar('p')) return;
367 $p = $DIR_MEDIA.requestVar('p'); //path
369 list($imgwidth, $imgheight, $imgtype) = GetImageSize($p);
371 $tsize['w'] = requestVar('wsize');
372 $tsize['h'] = requestVar('hsize');
373 $point = requestVar('pnt');
375 if($imgwidth / $imgheight < $tsize['w'] / $tsize['h']){ // height longer
378 $trimH = intval($tsize['h']/$tsize['w']*$imgwidth);
379 $trimY = intval(($imgheight - $trimH) / 2);
380 }else{ // width longer
383 $trimW = intval($tsize['w']/$tsize['h']*$imgheight);
384 $trimX = intval(($imgwidth - $trimW) / 2);
387 if($point == 'lefttop'){
391 $im_r = $this->baseimageCreate($p,$imgtype);
392 $im = ImageCreateTrueColor($tsize['w'],$tsize['h']);
393 ImageCopyResampled( $im, $im_r, 0, 0, $trimX, $trimY, $tsize['w'], $tsize['h'], $trimW, $trimH);
396 header ("Content-type: image/gif");
401 header ("Content-type: image/jpeg");
406 header ("Content-type: image/png");
416 Header('Location: ' . $return);
423 global $member, $manager;
424 if (!$member->isLoggedIn()) return 0;
425 return $member->isAdmin();
428 function createGlobalArchiveLink($blogid, $archive, $extra = '') {
429 global $CONF, $manager;
430 if ($CONF['URLMode'] == 'pathinfo'){
431 $link = $CONF['ArchiveURL'] . '/archive/'.$blogid.'/' . $archive;
433 $script_name = $CONF['Self'];
434 if(!$script_name) $script_name = 'index.php';
436 $b_tmp =& $manager->getBlog($blogid);
437 $blogurl = $b_tmp->getURL() ;
439 $blogurl = $CONF['IndexURL'];
441 if(substr($blogurl, -4) != '.php'){
442 if(substr($blogurl, -1) != '/')
444 $blogurl .= 'index.php';
447 $link = $blogurl . '?blogid='.$blogid.'&archive=' . $archive;
449 return addLinkParams($link, $extra);