plugindev:sample

<?php
class NP_QQQQQ extends NucleusPlugin
{
	function getName()           { return 'QQQQQ'; }         // プラグイン名
	function getAuthor()         { return 'QQQQQ'; }         // 作者名
	function getURL()            { return 'http://example.com/'; } // サポートサイトのURL
	function getVersion()        { return 'QQQQQ'; }         // このプラグインのバージョン
	function getDescription()    { return 'QQQQQ';	}        // プラグイン一覧に表示する簡易の説明文
	function supportsFeature($w) { return ($w == 'SqlTablePrefix') ? 1 : 0; } tableプリフィクス対策のおまじない
	function getEventList()
	{
		return array(
					'PostAddItem',
					'PreUpdateItem',
					'AddItemFormExtras',
					'EditItemFormExtras',
					'event_PrePluginOptionsEdit'
					);
	}
 
	function init()  // プラグイン実行時、無条件で必ず呼び出す処理をここに記述
	{
		global $member;
		if ($member->loggedin)
		{
			$language = preg_replace( '@\\|/@', '', getLanguageName());
			if  (file_exists( $this->getDirectory().$language.'.php'))
				{include_once($this->getDirectory().$language.'.php');}
			else
				{include_once($this->getDirectory().'english.php');}
		}
	}
 
	function install()
	{
		$this->createOption("name1", "desc1", "text", "QQQ") ;  // 1行タイプのテキストフィールド
		$this->createOption("name2", "desc2", "yesno", "yes");  //「はい」か「いいえ」のラジオボタン
		$this->createOption("name3", "desc3", "password", "");  // パスワード入力フィールド
		$this->createOption("name4", "desc4", "textarea", "");  // 複数行入力(textarea)
		$this->createOption("name5", "desc5", "select", "val1", "Opt1|val1|Opt2|val2|Opt3|val3");
		$this->createOption("del_uninstall", "Delete tables on uninstall?", "yesno", "no");
		$query  = "CREATE TABLE ".sql_table(plug_QQQQQ);
		$query .= "( itemid INT(9) NOT NULL,";
		$query .= " QQQQQa VARCHAR(255) NOT NULL,";
		$query .= " QQQQQb VARCHAR(255) NOT NULL,";
		$query .= " QQQQQc VARCHAR(255) NOT NULL,";
		$query .= " QQQQQd VARCHAR(100) NOT NULL,";
		$query .= " PRIMARY KEY (itemid))";
		mysql_query($query);
	}
 
	function uninstall()
	{
		if ($this->getOption('del_uninstall') == "yes")
		{
			mysql_query ("DROP table ".sql_table(plug_QQQQQ));
		}
	}
 
	function getTableList()
	{
		return array(sql_table(plug_QQQQQ),sql_table(plug_QQQQQ_cache));
	}
 
	function doSkinVar($skinType, $skinVar, $param1 = 'QQQQQ', $param2)
	{
		global $manager, $blog, $CONF;
		global $catid, $itemid;
		global $itemidprev, $itemidnext;
		global $archive, $archiveprev, $archivenext;
		switch($skinType)
		{
			case 'index':
				break;
			case 'item':
				break;
			case 'archive':
				break;
			case 'archivelist':
				break;
			case 'member':
				break;
			case 'error':
				break;
			case 'search':
				break;
			case 'imagepopup':
				break;
			case 'template':
				break;
			default:
				echo "QQQQQ";
		}
	}
 
	function doTemplateVar(&$item, $type, $param1 = 'QQQQQ') { }
 
	function doTemplateCommentsVar(&$item, &$comment, $type, $param1 = 'QQQQQ') { }
 
	function event_PostAddItem($data)
	{
		$Qa = requestVar('in_Qa');
		$Qb = requestVar('in_Qb');
		$Qc = requestVar('in_Qc');
 
		// 値が欠けてたら抜ける
		if ((!$Qa) && (!$Qb) && (!$Qc)) return;
 
		$itemid = $data['itemid'];
 
		$Qa = mysql_escape_string($Qa);
		$Qb = mysql_escape_string($Qb);
		$Qc = mysql_escape_string($Qc);
 
		mysql_query("INSERT INTO ".sql_table(plug_QQQQQ)." VALUES ('$itemid','$Qa','$Qb','$Qc','')");
	}
 
	function event_PreUpdateItem($data)
	{
		$Qa = requestVar('in_Qa');
		$Qb = requestVar('in_Qb');
		$Qc = requestVar('in_Qc');
		$Qa = mysql_escape_string($Qa);
		$Qb = mysql_escape_string($Qb);
		$Qc = mysql_escape_string($Qc);
 
		$itemid = $data['itemid'];
 
		$result = mysql_query("SELECT * FROM ".sql_table(plug_QQQQQ)." WHERE itemid='$itemid'");
 
		if (mysql_num_rows($result) > 0)
		{
			mysql_query("UPDATE ".sql_table(plug_QQQQQ)." SET QQQQQa='$Qa', QQQQQb='$Qb', QQQQQc='$Qc', mode='' WHERE itemid='$itemid'");
		}
		else
		{
			if (!$Qa && !$Qb && !$Qc) {return;}
			mysql_query("INSERT INTO ".sql_table(plug_QQQQQ)." VALUES ('$itemid','$Qa','$Qb','$Qc','')");
		}
	}
 
	function event_AddItemFormExtras($data)
	{
?>
<h3>QQQQQ</h3>
<p>
<label for="plug_Qa">QQQQQa:</label>
<input type="text" value="" id="plug_Qa" name="in_Qa" size="60" />
</p>
<p>
<label for="plug_Qb">QQQQQb:</label>
<input type="text" value="" id="plug_Qb" name="in_Qb" size="60" />
</p>
<p>
<label for="plug_Qc">QQQQQc:</label>
<input type="text" value="" id="plug_Qc" name="in_Qc" size="60" />
</p>
<?php
	}
 
	function event_EditItemFormExtras($data)
	{
		$id = $data['variables']['itemid'];
		$result = mysql_query("SELECT itemid, QQQQQa, QQQQQb, QQQQQc, QQQQd FROM ".sql_table(plug_QQQQQ)." WHERE itemid='$id'");
		if (mysql_num_rows($result) > 0)
		{
			$out_Qa = mysql_result($result,0,"QQQQQa");
			$out_Qb = mysql_result($result,0,"QQQQQb");
			$out_Qc = mysql_result($result,0,"QQQQQc");
		}
?>
<h3>Related Keyword</h3>
<p>
<label for="plug_Qa">QQQQQa:</label>
<input type="text" value="<?=$out_Qa?>" id="plug_Qa" name="in_Qa" size="60" />
</p>
<p>
<label for="plug_Qb">QQQQQb:</label>
<input type="text" value="<?=$out_Qb?>" id="plug_Qb" name="in_Qb" size="60" />
</p>
<p>
<label for="plug_Qc">QQQQQc:</label>
<input type="text" value="<?=$out_Qc?>" id="plug_Qc" name="in_Qc" size="60" />
</p>
<?php
	}
 
	function event_PrePluginOptionsEdit($data)
	{
		if ($data['plugid'] === $this->getID())
		{
			foreach($data['options'] as $key => $value)
			{
				if (defined($value['description']))
				{
					$data['options'][$key]['description'] = constant($value['description']);
				}
				if ($value['type'] == 'select' && defined($value['typeinfo']))
				{
					$data['options'][$key]['typeinfo'] = constant($value['typeinfo']);
				}
			}
		}
	}
 
	function doAction($type)
	{
		echo 'QQQQQ';
	}
}
?>
 
plugindev/sample.txt · 最終更新: 2011/03/23 21:28 (外部編集)