plugins:calendar2:calendar2_code

NP_Calendar2.phpのソースコード

<?php
class NP_Calendar2 extends NucleusPlugin {
 
	function getName() {return 'Calendar2';}
	function getAuthor() {return 'mas';}
	function getURL() {return 'http://neconnect.net';}
	function getVersion() {return '0.31';}
	function getMinNucleusVersion() {return 323;}
	function getDescription() {return 'Nucleus Calendar like tDiary\'s one.<br />use:<br /> <%Calendar2%> or <%Calendar2(mode,orderYear,orderMonth)%><br />params:<br /> [mode] 1:new mode, 2:old mode(default)<br /> [orderYear] 1:ASC, 2:DESC(default)<br /> [orderMonth] 1:ASC(default), 2:DESC';}
	function supportsFeature($what) {
		switch($what){
		     case 'SqlTablePrefix':return 1; break;
		     default:return 0;
		}
	}
 
	function doSkinVar($skinType, $paramMode='2', $paramYear='2', $paramMonth='1') {
		global $manager, $blog, $CONF, $catid;
 
		//init
		$mode = intval($paramMode)==1 ? "new" : "old";
		$orderYear = intval($paramYear)==1 ? "ASC" : "DESC";
		$orderMonth = intval($paramMonth)==2 ? "DESC" : "ASC";
 
		if ($blog) {
			$b =& $blog;
		} else {
			$b =& $manager->getBlog($CONF['DefaultBlog']);
		}
 
		$blogid = intval($b->getID());
 
		if (intval($catid)) 
			$this->linkparams = array('catid' => intval($catid));
 
		$homeURL = $CONF['IndexURL'];
		$blogURL = createBlogidLink($blogid, $linkparams);
 
		$now = time();
		$query = 'SELECT UNIX_TIMESTAMP(itime) as itime, SUBSTRING(itime,1,4) AS year, SUBSTRING(itime,6,2) AS month FROM '.sql_table('item');
		$query .= ' WHERE iblog=' . $blogid;
		$query .= ' and UNIX_TIMESTAMP(itime)<=' . $now;   // don't show future items!
		$query .= ' and idraft=0'; // don't show draft items
 
		if (intval($catid))
			$query .= ' and icat=' . intval($catid);
 
		$query .= ' GROUP BY Year, Month';
		$query .= ' ORDER BY Year '.$orderYear.', Month '.$orderMonth; 
 
		$res = sql_query($query);
		$num_row = mysql_num_rows($res);
 
		$preYear = Null;
		$arrayYear = array();
		$arrayMonth = array('01','02','03','04','05','06','07','08','09','10','11','12');
 
		// partition character
		$sep = "|";
 
		if ($num_row > 0)
 
			while ($current = mysql_fetch_object($res)) {
				if ($current->year != $preYear)
					array_push($arrayYear, $current->year);
 
				$archivedate = date('Y-m',$current->itime);
				$archivelink = createArchiveLink($blogid,$archivedate,$linkparams);
				$array[$current->year][$current->month] = $archivelink;
 
				$preYear = $current->year;
			}
 
			mysql_free_result($res);
 
			//show part
			echo '<div class="calendar">'."\n";
			foreach ($arrayYear as $year) {
				echo '<div class="year">'.$year.$sep;
 
				foreach ($arrayMonth as $month) {
					if (isset($array[$year][$month])) {
						echo '<a href="'.$array[$year][$month].'">'.$month.'</a>'.$sep;
					} else {
						echo $mode == "new" ? $month.$sep : "";
					}
				}
 
				echo "</div>\n\n";
			}
 
			echo "</div>\n";
		}
	}
?>
 
plugins/calendar2/calendar2_code.txt · 最終更新: 2011/03/23 21:28 (外部編集)