扩展插件功能完善
测试扩展编写
This commit is contained in:
44
addons/test/Test.php
Normal file
44
addons/test/Test.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: yangweijie <yangweijiester@gmail.com> <code-tech.diandian.com>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace addons\test;
|
||||||
|
use app\common\controller\Addons;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统环境信息插件
|
||||||
|
* @author thinkphp
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Test extends Addons {
|
||||||
|
|
||||||
|
public $info = array(
|
||||||
|
'name' => 'Test',
|
||||||
|
'title' => '测试',
|
||||||
|
'description' => '用于显示一些服务器的信息',
|
||||||
|
'status' => 1,
|
||||||
|
'author' => 'molong',
|
||||||
|
'version' => '0.1',
|
||||||
|
);
|
||||||
|
|
||||||
|
public function AdminIndex(){
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function install(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function uninstall(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -87,9 +87,7 @@ class Addons extends \app\common\model\Base {
|
|||||||
if ($info) {
|
if ($info) {
|
||||||
$result = $this->save(array('isinstall'=>1, 'status'=>1), array('id'=>$info));
|
$result = $this->save(array('isinstall'=>1, 'status'=>1), array('id'=>$info));
|
||||||
}else{
|
}else{
|
||||||
$data['isinstall'] = 1;
|
$result = false;
|
||||||
$data['status'] = 1;
|
|
||||||
$result = $this->save($data);
|
|
||||||
}
|
}
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return model('Hooks')->addHooks($data['name']);
|
return model('Hooks')->addHooks($data['name']);
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ namespace app\common\model;
|
|||||||
class Hooks extends Base {
|
class Hooks extends Base {
|
||||||
|
|
||||||
public $keyList = array(
|
public $keyList = array(
|
||||||
array('name'=>'name','title'=>'钩子名称','type'=>'text','help'=>'需要在程序中先添加钩子,否则无效'),
|
array('name' => 'name', 'title' => '钩子名称', 'type' => 'text', 'help' => '需要在程序中先添加钩子,否则无效'),
|
||||||
array('name'=>'description','title'=>'钩子描述','type'=>'text','help'=>'钩子的描述信息'),
|
array('name' => 'description', 'title' => '钩子描述', 'type' => 'text', 'help' => '钩子的描述信息'),
|
||||||
array('name'=>'type_text','title'=>'钩子类型','type'=>'select','help'=>'钩子的描述信息'),
|
array('name' => 'type_text', 'title' => '钩子类型', 'type' => 'select', 'help' => '钩子的描述信息'),
|
||||||
array('name'=>'addons','title'=>'插件排序','type'=>'kanban')
|
array('name' => 'addons', 'title' => '插件排序', 'type' => 'kanban'),
|
||||||
);
|
);
|
||||||
|
|
||||||
public function initialize(){
|
public function initialize() {
|
||||||
parent::initialize();
|
parent::initialize();
|
||||||
foreach ($this->keyList as $key => $value) {
|
foreach ($this->keyList as $key => $value) {
|
||||||
if ($value['name'] == 'type_text') {
|
if ($value['name'] == 'type_text') {
|
||||||
@@ -32,14 +32,14 @@ class Hooks extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setAddonsAttr($value){
|
protected function setAddonsAttr($value) {
|
||||||
if ($value[1]) {
|
if ($value) {
|
||||||
$string = implode(",", $value[1]);
|
$string = implode(",", $value);
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTypeTextAttr($value, $data){
|
protected function getTypeTextAttr($value, $data) {
|
||||||
$hooks_type = config('hooks_type');
|
$hooks_type = config('hooks_type');
|
||||||
return $hooks_type[$data['type']];
|
return $hooks_type[$data['type']];
|
||||||
}
|
}
|
||||||
@@ -47,15 +47,15 @@ class Hooks extends Base {
|
|||||||
/**
|
/**
|
||||||
* 处理钩子挂载插件排序
|
* 处理钩子挂载插件排序
|
||||||
*/
|
*/
|
||||||
public function getaddons($addons = ''){
|
public function getaddons($addons = '') {
|
||||||
if ($addons) {
|
if ($addons) {
|
||||||
$hook_list = explode(',',$addons);
|
$hook_list = explode(',', $addons);
|
||||||
foreach ($hook_list as $key => $value) {
|
foreach ($hook_list as $key => $value) {
|
||||||
$field_list[] = array('id'=>$value,'title'=>$value,'name'=>$value,'is_show'=>1);
|
$field_list[] = array('id' => $value, 'title' => $value, 'name' => $value, 'is_show' => 1);
|
||||||
}
|
}
|
||||||
$option[1] = array('name'=>'钩子挂载排序','list'=>$field_list);
|
$option[1] = array('name' => '钩子挂载排序', 'list' => $field_list);
|
||||||
}else{
|
} else {
|
||||||
$option[] = array('name'=>'钩子挂载排序','list'=>array());
|
$option[] = array('name' => '钩子挂载排序', 'list' => array());
|
||||||
}
|
}
|
||||||
foreach ($this->keyList as $key => $value) {
|
foreach ($this->keyList as $key => $value) {
|
||||||
if ($value['name'] == 'addons') {
|
if ($value['name'] == 'addons') {
|
||||||
@@ -66,54 +66,59 @@ class Hooks extends Base {
|
|||||||
return $keylist;
|
return $keylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addHooks($addons_name){
|
public function addHooks($addons_name) {
|
||||||
$addons_class = get_addon_class($addons_name);//获取插件名
|
$addons_class = get_addon_class($addons_name); //获取插件名
|
||||||
if(!class_exists($addons_class)){
|
if (!class_exists($addons_class)) {
|
||||||
$this->error = "未实现{$addons_name}插件的入口文件";
|
$this->error = "未实现{$addons_name}插件的入口文件";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$methods = get_class_methods($addons_class);
|
$methods = array_diff(get_class_methods($addons_class), get_class_methods('\app\common\controller\Addons'));
|
||||||
|
$methods = array_diff($methods, array('install', 'uninstall'));
|
||||||
foreach ($methods as $item) {
|
foreach ($methods as $item) {
|
||||||
if ('Addon' === substr($item, -5, 5)) {
|
$info = $this->where('name', $item)->find();
|
||||||
$info = $this->where('name', substr($item, 0, -5))->find();
|
|
||||||
if (null == $info) {
|
if (null == $info) {
|
||||||
$save = array(
|
$save = array(
|
||||||
'name' => $addons_name,
|
'name' => $item,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'type' => 1,
|
'type' => 1,
|
||||||
'addons' => array($addons_name),
|
'addons' => array($addons_name),
|
||||||
'update_time' => time(),
|
'update_time' => time(),
|
||||||
'status' => 1
|
'status' => 1,
|
||||||
);
|
);
|
||||||
self::create($save);
|
self::create($save);
|
||||||
}else{
|
} else {
|
||||||
if ($info['addons']) {
|
if ($info['addons']) {
|
||||||
$addons = explode(',', $info['addons']);
|
$addons = explode(',', $info['addons']);
|
||||||
array_push($addons, substr($item, 0, -5));
|
array_push($addons, $addons_name);
|
||||||
}else{
|
} else {
|
||||||
$addons = array(substr($item, 0, -5));
|
$addons = array($addons_name);
|
||||||
}
|
|
||||||
$this->where('name', $addons_name)->setField('addons', $addons);
|
|
||||||
}
|
}
|
||||||
|
$this->where('name', $item)->setField('addons', implode(',', $addons));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeHooks($addons_name){
|
public function removeHooks($addons_name) {
|
||||||
$addons_class = get_addon_class($addons_name);//获取插件名
|
$addons_class = get_addon_class($addons_name); //获取插件名
|
||||||
if(!class_exists($addons_class)){
|
if (!class_exists($addons_class)) {
|
||||||
$this->error = "未实现{$addons_name}插件的入口文件";
|
$this->error = "未实现{$addons_name}插件的入口文件";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$row = $this->where(array('addons'=>array('like',$addons_name)))->select();
|
$row = $this->where(array('addons' => array('like', '%' . $addons_name . '%')))->select();
|
||||||
foreach ($row as $key => $value) {
|
foreach ($row as $value) {
|
||||||
$value['addons'] = explode(',', $info['addons']);
|
if ($addons_name === $value['addons']) {
|
||||||
$key = array_search($addons_name, $value['addons']);
|
$this->where('id', $value['id'])->delete();
|
||||||
|
} else {
|
||||||
|
$addons = explode(',', $value['addons']);
|
||||||
|
$key = array_search($addons_name, $addons);
|
||||||
|
if ($key) {
|
||||||
unset($value['addons'][$key]);
|
unset($value['addons'][$key]);
|
||||||
$addons = $value['addons'];
|
$addons = implode(',', $addons);
|
||||||
$this->where('id', $value['id'])->setField('addons', $addons);
|
$this->where('id', $value['id'])->setField('addons', $addons);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user