書式1:[pm_count type="unread" from_uid="1"] 返り値はユーザーID1からの未読数
書式2:[pm_count type="unread"] 返り値は未読数
書式3:[pm_count] 返り値はメッセージ総数
<?php
class CustomSanitizer extends XCube_ActionFilter
{
function preBlockFilter() {
$this->mController->mRoot->mDelegateManager->add("MyTextSanitizer.XoopsCodePre",array(&$this,"BBCodePre"));
}
/*
* Add Short code into Delegate BBCode
*/
function BBCodePre(&$patterns, &$replacements, $allowimage) {
// Replacement rules for [pm_count] tag
$patterns[] = '/\[pm_count (.*?)\]/es';
$replacements[] = "CustomSanitizer::pm_count('\\1');";
$patterns[] = '/\[pm_count\]/es';
$replacements[] = "CustomSanitizer::pm_count();";
}
/*
* Make Shrot code return strings
*/
function pm_count($args='') {
global $xoopsDB;
// Short code parser start
$args = preg_replace('/("|")/',"",stripslashes($args));
$keyval = explode(" ",$args);
foreach($keyval as $k){
preg_match("/(.*)=(.*)/",$k,$matches);
$params[$matches[1]] = $matches[2];
}
// Short code parser end
$sql = "SELECT count(*) FROM " . $xoopsDB->prefix("message_inbox");
switch ($params['type']){
case 'unread':
$sql .= " WHERE is_read=0";
if ($params['from_uid']) $sql .= " AND from_uid=".$params['from_uid'];
}
$res = $xoopsDB->query($sql);
list($cnt) = $xoopsDB->fetchRow($res);
return $cnt;
}
}
?>
0 件のコメント:
コメントを投稿