求大神指导 如何做cms插件开发

小磊无痕 发布于 2016年10月08日
无人欣赏。

最近在修改cms插件bug,但是就是简单的修修改改,然后自己动手写一个插件的时候,无从下手,写过百度地图插件,但是无卵用,我把cms安装包发这里,还有几个插件。还上一部分插件控制器代码 我的cms安装包 https://pan.baidu.com/s/1slB04mp 求大神指导

namespace AddonsController;

use CommonControllerAdminBase;

class AddonsController extends AdminBase {

protected $addons = NULL;

protected function _initialize() {
    parent::_initialize();
    $this->addons = D('Addons/Addons');
}

//显示插件列表
public function index() {
    $addons = $this->addons->getAddonList();
    if (!empty($addons)) {
        //遍历检查是否有前台
        foreach ($addons as $key => $rs) {
            $path = $this->addons->getAddonsPath() . "{$rs['name']}/Controller/IndexController.class.php";
            if (file_exists($path)) {
                $addons[$key]['url'] = U("Addons/{$rs['name']}/index");
            } else {
                $addons[$key]['url'] = '';
            }
        }
    }
    $this->assign('addons', $addons);
    $this->display();
}

//安装
public function install() {
    //插件名称
    $addonName = trim(I('get.addonename'));
    if (empty($addonName)) {
        $this->error('请选择需要安装的插件!');
    }
    if ($this->addons->installAddon($addonName)) {
        $this->success('插件安装成功!', U('Addons/index'));
    } else {
        $error = $this->addons->getError();
        $this->error($error ? $error : '插件安装失败!');
    }
}

//卸载插件
public function uninstall() {
    //插件名称
    $addonId = trim(I('get.id'));
    if (empty($addonId)) {
        $this->error('请选择需要卸载的插件!');
    }
    if ($this->addons->uninstallAddon($addonId)) {
        $this->success('插件卸载成功!', U('Addons/index'));
    } else {
        $error = $this->addons->getError();
        $this->error($error ? $error : '插件卸载失败!');
    }
}

//插件设置界面
public function config() {
    if (IS_POST) {
        //插件ID
        $id = (int) I('post.id');
        //获取插件信息
        $info = $this->addons->where(array('id' => $id))->find();
        if (empty($info)) {
            $this->error('该插件没有安装!');
        }
        //插件配置
        $config = I('post.config', '', '');
        if (false !== $this->addons->where(array('id' => $id))->save(array('config' => serialize($config)))) {
            //更新附件状态,把相关附件和插件进行关联
            service("Attachment")->api_update('', 'addons-' . $id, 1);
            //更新插件缓存
            $this->addons->addons_cache();
            $this->success('保存成功!', U('Addons/index'));
        } else {
            $this->error('保存失败!');
        }
    } else {
        //插件名称
        $addonId = trim(I('get.id'));
        if (empty($addonId)) {
            $this->error('请选择需要操作的插件!');
        }
        //获取插件信息
        $info = $this->addons->where(array('id' => $addonId))->find();
        if (empty($info)) {
            $this->error('该插件没有安装!');
        }
        $info['config'] = unserialize($info['config']);
        //实例化插件入口类
        $addonObj = $this->addons->getAddonObject($info['name']);
        //标题
        $meta_title = '设置插件-' . $addonObj->info['title'];
        //载入插件配置数组
        $fileConfig = include $addonObj->configFile;
        if (!empty($info['config'])) {
            foreach ($fileConfig as $key => $form) {
                //如果已经有保存的值
                if (isset($info['config'][$key])) {
                    $fileConfig[$key]['value'] = $info['config'][$key];
                }
            }
        }
        $this->assign('meta_title', $meta_title);
        $this->assign('config', $fileConfig);
        $this->assign('info', $info);
        $this->display();
    }
}

alt text

暂无回复
登录 或者 注册
相关帖子