NP_AboutThis
2007年6月8日
ブログ内の単一の記事に対するリンクを作成するための簡単なプラグインを書いた。利用方法は、
各ブログごとにアイテムIDを一つずつ指定する(ブログの設定の NP_AboutThis の所)。
<%AboutThis(link,『<:name:>』について)%> … リンクを表示 <%AboutThis(link,『<:shortname:>』について)%> … 上と同じだが、短いブログ名を使用 <%AboutThis(linkraw)%> … URL のみを表示 <%AboutThis(itemid)%> … アイテムID のみを表示
各ブログごとにアイテムIDを一つずつ指定する(ブログの設定の NP_AboutThis の所)。
<?php
class NP_AboutThis extends NucleusPlugin {
function getName() { return 'NP_AboutThis'; }
function getMinNucleusVersion() { return 220; }
function getAuthor() { return 'Katsumi'; }
function getVersion() { return '0.1'; }
function getURL() {return 'http://www.rad51.net/nucleus/index.php?itemid=333';}
function getDescription() { return $this->getName().' plugin'; }
function supportsFeature($what) { return ($what=='SqlTablePrefix')?1:0; }
function install() {
$this->createBlogOption('itemid','itemid','text','','datatype=numerical');
}
function doSkinVar($skinType,$type,$template='') {
global $blog;
$itemid=$this->getBlogOption($blog->getID(),'itemid');
switch($type=strtolower($type)){
case 'itemid':
echo (int)$itemid;
break;
case 'link':
case 'linkraw':
default:
$url=createItemLink($itemid,'');
$url=str_replace('&','&',htmlspecialchars($url));
if ($type=='linkraw') echo $url;
else {
if (!$template) $template='About this blog';
$template=str_replace(array('<:',':>'),array('<%','%>'),$template);
$name=$blog->getName();
$sname=$blog->getShortName();
$desc=TEMPLATE::fill($template,array('name'=>$name,'shortname'=>$sname));
echo '<a href="'.$url.'">'.htmlspecialchars($desc).'</a>';
}
break;
}
}
}
?>