add new helper method

add new plugin callback method
This commit is contained in:
joyqi
2017-09-08 14:49:29 +08:00
parent ae684c3a82
commit ed8a847ae6
2 changed files with 50 additions and 2 deletions
+32
View File
@@ -31,6 +31,38 @@ class Helper
return Typecho_Widget::widget('Widget_Security');
}
/**
* 根据ID获取单个Widget对象
*
* @param string $table 表名, 支持 contents, comments, metas, users
* @return Widget_Abstract
*/
public static function widgetById($table, $pkId)
{
$table = ucfirst($table);
if (!in_array($table, array('Contents', 'Comments', 'Metas', 'Users'))) {
return NULL;
}
$keys = array(
'Contents' => 'cid',
'Comments' => 'coid',
'Metas' => 'mid',
'Users' => 'uid'
);
$className = "Widget_Abstract_{$table}";
$key = $keys[$table];
$db = Typecho_Db::get();
$widget = new $className;
$db->fetchRow(
$widget->select()->where("{$key} = ?", $pkId)->limit(1),
array($widget, 'push'));
return $widget;
}
/**
* 强行删除某个插件
*