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

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;
}
/**
* 强行删除某个插件
*

View File

@ -21,6 +21,11 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
*/
class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Interface_Do
{
/**
* @var bool
*/
private $_configNoticed = false;
/**
* 手动配置插件变量
*
@ -232,8 +237,10 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
/** 设置高亮 */
$this->widget('Widget_Notice')->highlight('plugin-' . $pluginName);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t("插件设置已经保存"), 'success');
if (!$this->_configNoticed) {
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t("插件设置已经保存"), 'success');
}
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('plugins.php', $this->options->adminUrl));
@ -253,6 +260,15 @@ class Widget_Plugins_Edit extends Widget_Abstract_Options implements Widget_Inte
/** 获取插件入口 */
list($pluginFileName, $className) = Typecho_Plugin::portal($pluginName, $this->options->pluginDir($pluginName));
if (!$isInit && method_exists($className, 'configCheck')) {
$result = call_user_func(array($className, 'configCheck'), $settings);
if (!empty($result) && is_string($result)) {
$this->widget('Widget_Notice')->set($result, 'notice');
$this->_configNoticed = true;
}
}
if (method_exists($className, 'configHandle')) {
call_user_func(array($className, 'configHandle'), $settings, $isInit);
return true;