diff --git a/CHANGELOG.md b/CHANGELOG.md index 348bdf0..0158323 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,169 +1,178 @@ -# DiliCMS更新日志 - -## 版本号 2.1.3 - -> 2013年8月15日 更新内容 - -- 1.增加数据库配置模板文件,解决由于文件污染导致的卡在管理员设置处 - -## 版本号 2.1.2 - -> 2013年8月10日 更新内容 - -- 1.修复内容模型字段ajax调用失败的错误 -- 2.增强安装程序文件夹可写权限的判断 - -## 版本号 2.1.1 - -> 2013年8月5日 更新内容 - -- 1. 添加遗漏的更新变动(开启了csrf检测) -- 2. 禁止了在SAE平台下使用数据库管理功能 -- 3. 修复编辑器字段高宽设置无效的问题 - -## 版本号 2.1.0 - -> 2013年8月4日 更新内容 - -- 1.升级CI内核到2.1.4 -- 2.新增数据库备份还原和优化功能 -- 3.启用csrf检测 -- 4.发布2.1.0正式版 - -> 2013年8月3日 更新内容 - -- 1.修复安装程序部分错误 -- 2.富文本编辑器放弃xheditor,采用kindeditor - -> 2013年3月28日 更新内容 - -- 1.修复安装程序base标记多写一个"/"的BUG -- 2.模型表id字段设置为unsigned -- 2.模型表默认的4个字段默认值设为0 - -> 2013年3月24日 更新内容 - -- 1.全新的DiliCMS Installer -- 2.修改部分类库已适应安装程序 -- 3.移除旧版初始化程序 - -> 2013年3月14号 更新内容 - -- 1.增加调用内容模型的字段 - -## 版本号 2.0 Final - -> 2013年2月28日 更新内容 - -- 1.修复错误Field 'path' doesn't have a default value -- 2.修复错误”BLOB/TEXT column can't have a default value“ - -> 2012年10月25日 更新内容 - -- 1.用户密码换用sha1和salt加密 -- 2.内容模型字段增加create_user和update_user,用来记录操作人员. -- 3.如果没有插件,则不显示顶部【工具】菜单. -``` -旧版本更新须知: -数据库执行:ALTER TABLE `dili_admins` CHANGE COLUMN `password` `password` VARCHAR(40) NOT NULL AFTER `username`, ADD COLUMN `salt` VARCHAR(10) NOT NULL AFTER `password`;注意表名前缀改成你自己的,然后修改password为1e95b0358f0465957bf236079d064a6c5be22a1c,修改salt为516f36ef1b,然后就可以使用密码"dilicms"进行登录了,到后台自行修改密码. -``` - -> 2012年10月21日 更新内容 - -- 1.升级CI内核到2.1.3 - -> 2012年10月20日 更新内容 - -- 1.修复对数据表前缀的支持 -- 2.界面交互体验调整 -- 3.内容模型管理与分类模型添加面包屑导航 -- 4.site_settings表增加attachment_url字段,用来自适应附件调用地址. - -> 2012年9月27日 更新内容 - -- 1.不再兼容【随便编辑器】插件(依然可以安装,但下述更新的内容就无法使用到了). -- 2.支持从xheditor上传文件,并与flash控件上传功能一致(新上传的文件可以同步到附件列表中,可以在其上管理) -- 3.支持从附件列表中直接向编辑器插入附件,并且也支持1个模型内多编辑器的情况。 -- 4.升级jquery库到1.7.2版本 -- 5.升级xheditor到1.1.14 -- 6.移除无用的hialert组件 -- 7.增加jquery.contentMenu插件,用于完成更新【3】中所述功能。 - -> 2012年8月28日 更新内容 - -- 1.修改自定义字段类名的命名规则,去掉extra_的前缀. -- 2.增加自定义字段对表单数据二次处理的程序on_on_post方法. -- 3.新增自定义字段实例,文件上传字段类型field_file.php,地址:https://github.com/DiliCMS/DiliCMS-extensions - -> 2012年8月13日 更新内容 - -- 1.升级CI内核到2.1.2。 -- 2.目录重构,前后台分离。 -- 3.新增package:shared。 -- 4.合并插件目录和自定义字段目录到extensions目录下。 -- 5.代码重写,更规范,更方便阅读。 -- 6.后台用户增加冻结/解冻功能。 -- 7.后台用户新增分页。 - -## 版本号 2.0.0 - -> 2011年11月19号 更新内容 - -- 1.升级CI内核到2.1.0版本。 -- 2.视图路径的扩展采用扩展CI_Loader来实现。 -- 3.设置后台默认时区为PRC(以后可自定义)。 -- 4.增加功能插件的钩子:register_attachment($file = ''),用于对上传的附件进行相关处理。 -- 5.移除原安装程序,用初始化工具替代。 -- 6.增加了字段默认值(部分字段支持)。 -- 7.增加了一个自动搜索补全工具,使用方法在后续上手册上会有说明。 -- 8.新增加2个模型插件钩子,详情见后续手册。 -- 9.修正后台首页平台信息部分显示的错位现象。 -- 10.修正加载colorpicker.css由于大小写问题导致的无法加载。 -- 11.修正权限类库对于默认链接获取错误的BUG。 -- 12.数据库表存储引擎由Innodb换成MyIsam(某些服务商的数据库不支持Innodb引擎)。 -- 13.增加了robots.txt文件。 -- 14.增加平台驱动,用以支持云平台,重写相关I/O程序,内置普通平台和SAE(新浪云平台)平台驱动。 -- 15.增加IN_DiliCMS常量。 -- 16.增加了字段类型行为类库,重构了相关代码。 -- 17.为int,float,datetime等字段类型增加区间搜索支持。 -- 18.允许自定义新的字段类型。 -- 19.将内置字段类型和验证规则写入数据库(之前是直接放在settings文件夹下的),方便程序的迁移。 -- 20.增加默认路由:$route['admin'] = 'admin/login'。 -- 21.生成的缓存文件也增加了IN_DiliCMS判断。 -- 22.后台首页获取数据库版本改用$this->db->version();来获取。 -- 23.修正checkbox,checkbox_from_model,linked_menu字段类型多项搜索错误的BUG。 -- 24.移除column_mdl.php文件,功能由字段行为类库提供。 -- 25.增加了platform.php配置文件。 - -## 版本号 V1.0 Beta3 - -> 2011年8月13号 更新内容 - -- 编辑用户时,用户密码修改无故被修改的BUG -- 附件上传无权限的BUG -- 修改分类时候按钮依然显示添加的显示错误 - -## 版本号 V1.0 Beta2 - -> 2011年7月19号 更新内容 - -- 修改Dili_Controller.php解决了后台自动跳转函数的BUG。 -- 模型字段增加radio以及checkbox的模型数据类型。 -- 新增插件函数_url方便生成插件链接地址。 -- 移除common文件夹。 -- 新增模型插件4个钩子。 -- 修改模型信息的添加修改操作,解决了字段不可编辑属性的兼容问题。 -- 解决了新建插件,插件标识不能通过验证的问题(CI中国mvc999提出)。 -- 解决筛选框在IE6,7下被遮住的问题。 -- 移除附件的flash复制功能,改用文本框自主复制。 -- 修正update_plugin_cache函数,解决在部分PHP环境下出错的问题。 -- 修正部分环境获取不到网站IP的问题。 -- 为数字型字段增加默认值为0,varchar,text型字段增加字段默认值''。 -- 安装程序的部分英文中文化。 -- 集成了CI的中文语言包。 -- 修改user_data字段属性,兼容某些版本mysql。 -- 下载包采用zip压缩方式。 - -## Version V1.0 beta1 - +# DiliCMS更新日志 + +## 版本号 2.2.0-rc.1 + +> 2013年12月29日 更新内容 + +- 1.全新的插件系统,每个插件都已HMVC组织实现 +- 2.二级菜单[插件管理]改名为[扩展管理] +- 3.一级菜单[工具]改名为[插件] +- 4.增加插件开发模式开关,方便插件开发 + +## 版本号 2.1.3 + +> 2013年8月15日 更新内容 + +- 1.增加数据库配置模板文件,解决由于文件污染导致的卡在管理员设置处 + +## 版本号 2.1.2 + +> 2013年8月10日 更新内容 + +- 1.修复内容模型字段ajax调用失败的错误 +- 2.增强安装程序文件夹可写权限的判断 + +## 版本号 2.1.1 + +> 2013年8月5日 更新内容 + +- 1. 添加遗漏的更新变动(开启了csrf检测) +- 2. 禁止了在SAE平台下使用数据库管理功能 +- 3. 修复编辑器字段高宽设置无效的问题 + +## 版本号 2.1.0 + +> 2013年8月4日 更新内容 + +- 1.升级CI内核到2.1.4 +- 2.新增数据库备份还原和优化功能 +- 3.启用csrf检测 +- 4.发布2.1.0正式版 + +> 2013年8月3日 更新内容 + +- 1.修复安装程序部分错误 +- 2.富文本编辑器放弃xheditor,采用kindeditor + +> 2013年3月28日 更新内容 + +- 1.修复安装程序base标记多写一个"/"的BUG +- 2.模型表id字段设置为unsigned +- 2.模型表默认的4个字段默认值设为0 + +> 2013年3月24日 更新内容 + +- 1.全新的DiliCMS Installer +- 2.修改部分类库已适应安装程序 +- 3.移除旧版初始化程序 + +> 2013年3月14号 更新内容 + +- 1.增加调用内容模型的字段 + +## 版本号 2.0 Final + +> 2013年2月28日 更新内容 + +- 1.修复错误Field 'path' doesn't have a default value +- 2.修复错误”BLOB/TEXT column can't have a default value“ + +> 2012年10月25日 更新内容 + +- 1.用户密码换用sha1和salt加密 +- 2.内容模型字段增加create_user和update_user,用来记录操作人员. +- 3.如果没有插件,则不显示顶部【工具】菜单. +``` +旧版本更新须知: +数据库执行:ALTER TABLE `dili_admins` CHANGE COLUMN `password` `password` VARCHAR(40) NOT NULL AFTER `username`, ADD COLUMN `salt` VARCHAR(10) NOT NULL AFTER `password`;注意表名前缀改成你自己的,然后修改password为1e95b0358f0465957bf236079d064a6c5be22a1c,修改salt为516f36ef1b,然后就可以使用密码"dilicms"进行登录了,到后台自行修改密码. +``` + +> 2012年10月21日 更新内容 + +- 1.升级CI内核到2.1.3 + +> 2012年10月20日 更新内容 + +- 1.修复对数据表前缀的支持 +- 2.界面交互体验调整 +- 3.内容模型管理与分类模型添加面包屑导航 +- 4.site_settings表增加attachment_url字段,用来自适应附件调用地址. + +> 2012年9月27日 更新内容 + +- 1.不再兼容【随便编辑器】插件(依然可以安装,但下述更新的内容就无法使用到了). +- 2.支持从xheditor上传文件,并与flash控件上传功能一致(新上传的文件可以同步到附件列表中,可以在其上管理) +- 3.支持从附件列表中直接向编辑器插入附件,并且也支持1个模型内多编辑器的情况。 +- 4.升级jquery库到1.7.2版本 +- 5.升级xheditor到1.1.14 +- 6.移除无用的hialert组件 +- 7.增加jquery.contentMenu插件,用于完成更新【3】中所述功能。 + +> 2012年8月28日 更新内容 + +- 1.修改自定义字段类名的命名规则,去掉extra_的前缀. +- 2.增加自定义字段对表单数据二次处理的程序on_on_post方法. +- 3.新增自定义字段实例,文件上传字段类型field_file.php,地址:https://github.com/DiliCMS/DiliCMS-extensions + +> 2012年8月13日 更新内容 + +- 1.升级CI内核到2.1.2。 +- 2.目录重构,前后台分离。 +- 3.新增package:shared。 +- 4.合并插件目录和自定义字段目录到extensions目录下。 +- 5.代码重写,更规范,更方便阅读。 +- 6.后台用户增加冻结/解冻功能。 +- 7.后台用户新增分页。 + +## 版本号 2.0.0 + +> 2011年11月19号 更新内容 + +- 1.升级CI内核到2.1.0版本。 +- 2.视图路径的扩展采用扩展CI_Loader来实现。 +- 3.设置后台默认时区为PRC(以后可自定义)。 +- 4.增加功能插件的钩子:register_attachment($file = ''),用于对上传的附件进行相关处理。 +- 5.移除原安装程序,用初始化工具替代。 +- 6.增加了字段默认值(部分字段支持)。 +- 7.增加了一个自动搜索补全工具,使用方法在后续上手册上会有说明。 +- 8.新增加2个模型插件钩子,详情见后续手册。 +- 9.修正后台首页平台信息部分显示的错位现象。 +- 10.修正加载colorpicker.css由于大小写问题导致的无法加载。 +- 11.修正权限类库对于默认链接获取错误的BUG。 +- 12.数据库表存储引擎由Innodb换成MyIsam(某些服务商的数据库不支持Innodb引擎)。 +- 13.增加了robots.txt文件。 +- 14.增加平台驱动,用以支持云平台,重写相关I/O程序,内置普通平台和SAE(新浪云平台)平台驱动。 +- 15.增加IN_DiliCMS常量。 +- 16.增加了字段类型行为类库,重构了相关代码。 +- 17.为int,float,datetime等字段类型增加区间搜索支持。 +- 18.允许自定义新的字段类型。 +- 19.将内置字段类型和验证规则写入数据库(之前是直接放在settings文件夹下的),方便程序的迁移。 +- 20.增加默认路由:$route['admin'] = 'admin/login'。 +- 21.生成的缓存文件也增加了IN_DiliCMS判断。 +- 22.后台首页获取数据库版本改用$this->db->version();来获取。 +- 23.修正checkbox,checkbox_from_model,linked_menu字段类型多项搜索错误的BUG。 +- 24.移除column_mdl.php文件,功能由字段行为类库提供。 +- 25.增加了platform.php配置文件。 + +## 版本号 V1.0 Beta3 + +> 2011年8月13号 更新内容 + +- 编辑用户时,用户密码修改无故被修改的BUG +- 附件上传无权限的BUG +- 修改分类时候按钮依然显示添加的显示错误 + +## 版本号 V1.0 Beta2 + +> 2011年7月19号 更新内容 + +- 修改Dili_Controller.php解决了后台自动跳转函数的BUG。 +- 模型字段增加radio以及checkbox的模型数据类型。 +- 新增插件函数_url方便生成插件链接地址。 +- 移除common文件夹。 +- 新增模型插件4个钩子。 +- 修改模型信息的添加修改操作,解决了字段不可编辑属性的兼容问题。 +- 解决了新建插件,插件标识不能通过验证的问题(CI中国mvc999提出)。 +- 解决筛选框在IE6,7下被遮住的问题。 +- 移除附件的flash复制功能,改用文本框自主复制。 +- 修正update_plugin_cache函数,解决在部分PHP环境下出错的问题。 +- 修正部分环境获取不到网站IP的问题。 +- 为数字型字段增加默认值为0,varchar,text型字段增加字段默认值''。 +- 安装程序的部分英文中文化。 +- 集成了CI的中文语言包。 +- 修改user_data字段属性,兼容某些版本mysql。 +- 下载包采用zip压缩方式。 + +## Version V1.0 beta1 + > 2011年6月28日 正式发布 \ No newline at end of file diff --git a/admin/config/database.php b/admin/config/database.php index 5b9c1a8..834aad9 100755 --- a/admin/config/database.php +++ b/admin/config/database.php @@ -58,7 +58,7 @@ $db['default']['password'] = 'root'; $db['default']['database'] = 'dilicms'; $db['default']['dbdriver'] = 'mysql'; -$db['default']['dbprefix'] = 'cd_'; +$db['default']['dbprefix'] = 'dili_'; $db['default']['pconnect'] = FALSE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; diff --git a/admin/controllers/attachment.php b/admin/controllers/attachment.php index c067232..0e9a775 100644 --- a/admin/controllers/attachment.php +++ b/admin/controllers/attachment.php @@ -1,270 +1,269 @@ -load->database(); - } - - // ------------------------------------------------------------------------ - - /** - * 处理上传的POST请求 - * - * @access public - * @return string - */ - public function _upload_post() - { - - //不能加载SESSION类库 - $session_id = $this->input->post('hash', TRUE); - $session = $this->db->where('session_id', $session_id)->get($this->db->dbprefix('sessions'))->row(); - $status = "ok"; - $response = ""; - if ($session) - { - $userdata = $session->user_data ? @unserialize($session->user_data) : array(); - $this->load->helper('date'); - $now = now(); - if ( - ! $userdata - OR - $now - $session->last_activity > $this->config->item('sess_expiration') - OR - $userdata['uid'] != $this->input->post('uid', TRUE) - ) - { - $status = "fail"; - } - else - { - //获取用户信息,让插件管理类正确执行(暂时的解决方案) - $this->_admin = $this->user_mdl->get_full_user_by_username($userdata['uid'], 'uid'); - //加载ACL - $this->load->library('acl'); - //加载插件经理 - $this->load->library('plugin_manager'); - if ( ! $_FILES['Filedata']['error']) - { - $data['folder'] = date('Y/m', $now); - $target_path = DILICMS_SHARE_PATH . '../' . setting('attachment_dir') . '/' . $data['folder']; - if ($status != 'fail') - { - $realname = explode(".", $_FILES['Filedata']['name']); - $data['type'] = strtolower(array_pop($realname)); - $data['realname'] = implode('.', $realname); - $data['name'] = now() . substr(md5($data['realname'] . rand()), 0, 16); - $data['posttime'] = now(); - $data['uid'] = $userdata['uid']; - $target_file = $target_path . '/' . $data['name'] . '.' . $data['type']; - if ( ! $this->platform->file_upload($_FILES['Filedata']['tmp_name'], $target_file)) - { - $status = "fail"; - } - else - { - $data['image'] = (in_array($data['type'], array('jpg', 'gif', 'png', 'jpeg', 'bmp'))) ? 1 : 0; - $this->db->insert($this->db->dbprefix('attachments'), $data); - $response = $this->db->insert_id() . '|' . $data['realname'] . '|' . $data['name'] . '|' . $data['image'].'|'.$data['folder'].'|'.$data['type']; - $this->plugin_manager->trigger_attachment($target_file); - } - } - } - else - { - $status = "fail"; - } - } - } - else - { - $status = "fail"; - } - echo ' - - ' . $status.' - ' . $this->input->post('proid') .' - ' . $response . ' - '; - } - - // ------------------------------------------------------------------------ - - /** - * 编辑器文件上传接口 - * - * @access public - * @return void - * - * $_GET['field'], 上传域名称,不指定则使用默认值(xheditor),filedata - * $_GET['tpl'],返回数据的模版,{{error}}代表错误信息,{{url}}代表附件的地址,{{aid}}代表上传返回的0,不传则使用默认值(xheditor),'{"err":"{{error}}","msg":"{{url}}","aid":{{aid}}}' - * {{name}}代表名称,{{type}}代表扩展名 - * {{object}}代表文件的完整信息 - */ - public function _save_post() - { - if ( ! ($field = $this->input->post('field'))) - { - $field = 'imgFile'; - } - if ( ! ($tpl = $this->input->post('tpl'))) - { - $tpl = '{"error":{{status}},"url":"{{url}}","message":"{{error}}","msg":"{{object}}"}'; - } - $error = '啊哦,登陆超时了。'; - $url = ''; - $aid = 0; - $name = ''; - $type = ''; - $object = ''; - $this->load->library('session'); - $is_valid = FALSE; - if ($uid = $this->session->userdata('uid')) - { - if (isset($_FILES[$field]) AND ! $_FILES[$field]['error']) - { - //判断文件MIME是否合法,文件的格式将使用数据源的位置填写,不填写则允许一切格式上传 - //加载MIMES数据 - include APPPATH.'config/mimes.php'; - $error = '对不起,不支持上传此文件类型.'; - foreach (explode(';', str_replace("*.", "", setting('attachment_type'))) as $_mime) - { - if (isset($mimes[$_mime])) - { - if (! is_array($mimes[$_mime])) - { - $mimes[$_mime] = array($mimes[$_mime]); - } - if (in_array($_FILES[$field]['type'], $mimes[$_mime])) - { - $is_valid = TRUE; - $error = ''; - } - } - } - //判断文件大小 - if ($is_valid AND $_FILES[$field]['size'] > setting('attachment_maxupload')) - { - $is_valid = FALSE; - $error = '文件过大.'; - } - if ($is_valid) - { - $this->load->helper('date'); - $_timestamp = now(); - $upload['folder'] = date('Y/m', $_timestamp); - $target_path = DILICMS_SHARE_PATH.'../'.setting('attachment_dir').'/'.$upload['folder']; - $realname = explode('.', $_FILES[$field]['name']); - $type = $upload['type'] = strtolower(array_pop($realname)); - $name = $upload['realname'] = implode('.', $realname); - $upload['name'] = $_timestamp.substr(md5($upload['realname']. rand()), 0, 16); - $upload['posttime'] = $_timestamp; - $upload['uid'] = $uid; - $target_file = $target_path.'/'.$upload['name'].'.'.$upload['type']; - if ($this->platform->file_upload($_FILES[$field]['tmp_name'], $target_file)) - { - $upload['image'] = (in_array($upload['type'], array('jpg', 'gif', 'png', 'jpeg', 'bmp')) ? 1 : 0); - $this->db->insert($this->db->dbprefix('attachments'), $upload); - if ($aid = $this->db->insert_id()) - { - //已上传成功并已插入数据库 - $url = setting('attachment_url').'/'.$upload['folder'].'/'.$upload['name'].'.'.$upload['type']; - $error = ''; - $object = $aid . '|' . $upload['realname'] . '|' . $upload['name'] . '|' . $upload['image'].'|'.$upload['folder'].'|'.$upload['type']; - } - } - } - } - else - { - $error = '上传的文件不存在'; - } - } - $status = ($error === '' ? 0 : 1); - echo str_replace(array('{{status}}', '{{error}}', '{{url}}', '{{aid}}', '{{name}}', '{{type}}', '{{object}}'), array($status, $error, $url, $aid, $name, $type, $object), $tpl); - } - - // ------------------------------------------------------------------------ - - /** - * 返回上传控件所需配置信息的XML - * - * @access public - * @return void - */ - public function config() - { - $this->load->library('session'); - echo ' - - - ' . $this->settings->item('attachment_type') . ' - - - 确定 - 继续 - 文件名 - 文件大小 - 上传进度 - 浏览 - 删除 - 返回 - 上传 - 上传完成 - 文件上传完成 - 正在上传 - 总共有 - 个文件等待上传,正在上传第 - 个文件 - 文件过大 - 上传失败 - - - '.$this->session->userdata('uid').' - '.$this->session->userdata('session_id').' - '.$this->settings->item('attachment_maxupload').' - - '; - } - - // ------------------------------------------------------------------------ - -} - -/* End of file attachment.php */ +load->database(); + } + + // ------------------------------------------------------------------------ + + /** + * 处理上传的POST请求 + * + * @access public + * @return string + */ + public function _upload_post() + { + + //不能加载SESSION类库 + $session_id = $this->input->post('hash', TRUE); + $session = $this->db->where('session_id', $session_id)->get($this->db->dbprefix('sessions'))->row(); + $status = "ok"; + $response = ""; + if ($session) + { + $userdata = $session->user_data ? @unserialize($session->user_data) : array(); + $this->load->helper('date'); + $now = now(); + if ( + ! $userdata + OR + $now - $session->last_activity > $this->config->item('sess_expiration') + OR + $userdata['uid'] != $this->input->post('uid', TRUE) + ) + { + $status = "fail"; + } + else + { + //获取用户信息,让插件管理类正确执行(暂时的解决方案) + $this->_admin = $this->user_mdl->get_full_user_by_username($userdata['uid'], 'uid'); + //加载ACL + $this->load->library('acl'); + //加载插件经理 + $this->load->library('plugin_manager'); + if ( ! $_FILES['Filedata']['error']) + { + $data['folder'] = date('Y/m', $now); + $target_path = DILICMS_SHARE_PATH . '../' . setting('attachment_dir') . '/' . $data['folder']; + if ($status != 'fail') + { + $realname = explode(".", $_FILES['Filedata']['name']); + $data['type'] = strtolower(array_pop($realname)); + $data['realname'] = implode('.', $realname); + $data['name'] = now() . substr(md5($data['realname'] . rand()), 0, 16); + $data['posttime'] = now(); + $data['uid'] = $userdata['uid']; + $target_file = $target_path . '/' . $data['name'] . '.' . $data['type']; + if ( ! $this->platform->file_upload($_FILES['Filedata']['tmp_name'], $target_file)) + { + $status = "fail"; + } + else + { + $data['image'] = (in_array($data['type'], array('jpg', 'gif', 'png', 'jpeg', 'bmp'))) ? 1 : 0; + $this->db->insert($this->db->dbprefix('attachments'), $data); + $response = $this->db->insert_id() . '|' . $data['realname'] . '|' . $data['name'] . '|' . $data['image'].'|'.$data['folder'].'|'.$data['type']; + } + } + } + else + { + $status = "fail"; + } + } + } + else + { + $status = "fail"; + } + echo ' + + ' . $status.' + ' . $this->input->post('proid') .' + ' . $response . ' + '; + } + + // ------------------------------------------------------------------------ + + /** + * 编辑器文件上传接口 + * + * @access public + * @return void + * + * $_GET['field'], 上传域名称,不指定则使用默认值(xheditor),filedata + * $_GET['tpl'],返回数据的模版,{{error}}代表错误信息,{{url}}代表附件的地址,{{aid}}代表上传返回的0,不传则使用默认值(xheditor),'{"err":"{{error}}","msg":"{{url}}","aid":{{aid}}}' + * {{name}}代表名称,{{type}}代表扩展名 + * {{object}}代表文件的完整信息 + */ + public function _save_post() + { + if ( ! ($field = $this->input->post('field'))) + { + $field = 'imgFile'; + } + if ( ! ($tpl = $this->input->post('tpl'))) + { + $tpl = '{"error":{{status}},"url":"{{url}}","message":"{{error}}","msg":"{{object}}"}'; + } + $error = '啊哦,登陆超时了。'; + $url = ''; + $aid = 0; + $name = ''; + $type = ''; + $object = ''; + $this->load->library('session'); + $is_valid = FALSE; + if ($uid = $this->session->userdata('uid')) + { + if (isset($_FILES[$field]) AND ! $_FILES[$field]['error']) + { + //判断文件MIME是否合法,文件的格式将使用数据源的位置填写,不填写则允许一切格式上传 + //加载MIMES数据 + include APPPATH.'config/mimes.php'; + $error = '对不起,不支持上传此文件类型.'; + foreach (explode(';', str_replace("*.", "", setting('attachment_type'))) as $_mime) + { + if (isset($mimes[$_mime])) + { + if (! is_array($mimes[$_mime])) + { + $mimes[$_mime] = array($mimes[$_mime]); + } + if (in_array($_FILES[$field]['type'], $mimes[$_mime])) + { + $is_valid = TRUE; + $error = ''; + } + } + } + //判断文件大小 + if ($is_valid AND $_FILES[$field]['size'] > setting('attachment_maxupload')) + { + $is_valid = FALSE; + $error = '文件过大.'; + } + if ($is_valid) + { + $this->load->helper('date'); + $_timestamp = now(); + $upload['folder'] = date('Y/m', $_timestamp); + $target_path = DILICMS_SHARE_PATH.'../'.setting('attachment_dir').'/'.$upload['folder']; + $realname = explode('.', $_FILES[$field]['name']); + $type = $upload['type'] = strtolower(array_pop($realname)); + $name = $upload['realname'] = implode('.', $realname); + $upload['name'] = $_timestamp.substr(md5($upload['realname']. rand()), 0, 16); + $upload['posttime'] = $_timestamp; + $upload['uid'] = $uid; + $target_file = $target_path.'/'.$upload['name'].'.'.$upload['type']; + if ($this->platform->file_upload($_FILES[$field]['tmp_name'], $target_file)) + { + $upload['image'] = (in_array($upload['type'], array('jpg', 'gif', 'png', 'jpeg', 'bmp')) ? 1 : 0); + $this->db->insert($this->db->dbprefix('attachments'), $upload); + if ($aid = $this->db->insert_id()) + { + //已上传成功并已插入数据库 + $url = setting('attachment_url').'/'.$upload['folder'].'/'.$upload['name'].'.'.$upload['type']; + $error = ''; + $object = $aid . '|' . $upload['realname'] . '|' . $upload['name'] . '|' . $upload['image'].'|'.$upload['folder'].'|'.$upload['type']; + } + } + } + } + else + { + $error = '上传的文件不存在'; + } + } + $status = ($error === '' ? 0 : 1); + echo str_replace(array('{{status}}', '{{error}}', '{{url}}', '{{aid}}', '{{name}}', '{{type}}', '{{object}}'), array($status, $error, $url, $aid, $name, $type, $object), $tpl); + } + + // ------------------------------------------------------------------------ + + /** + * 返回上传控件所需配置信息的XML + * + * @access public + * @return void + */ + public function config() + { + $this->load->library('session'); + echo ' + + + ' . $this->settings->item('attachment_type') . ' + + + 确定 + 继续 + 文件名 + 文件大小 + 上传进度 + 浏览 + 删除 + 返回 + 上传 + 上传完成 + 文件上传完成 + 正在上传 + 总共有 + 个文件等待上传,正在上传第 + 个文件 + 文件过大 + 上传失败 + + + '.$this->session->userdata('uid').' + '.$this->session->userdata('session_id').' + '.$this->settings->item('attachment_maxupload').' + + '; + } + + // ------------------------------------------------------------------------ + +} + +/* End of file attachment.php */ /* Location: ./admin/controllers/attachment.php */ \ No newline at end of file diff --git a/admin/controllers/category_content.php b/admin/controllers/category_content.php index c631dd3..4c346a8 100644 --- a/admin/controllers/category_content.php +++ b/admin/controllers/category_content.php @@ -1,459 +1,459 @@ -_view_post(); - } - - // ------------------------------------------------------------------------ - - /** - * 分类内容列表页 - * - * @access public - * @return void - */ - public function _view_post() - { - $model = $this->input->get('model', TRUE); - if ( ! $model AND $this->acl->_default_link) - { - redirect($this->acl->_default_link); - } - $this->_check_permit(); - if ( ! $this->platform->cache_exists(DILICMS_SHARE_PATH . 'settings/category/cate_' . $model . '.php')) - { - $this->_message('不存在的分类模型!', '', FALSE); - } - $this->plugin_manager->trigger_model_action('register_on_reach_model_list'); - $this->settings->load('category/cate_' . $model); - $data['model'] = $this->settings->item('cate_models'); - $data['model'] = $data['model'][$model]; - $this->load->library('form'); - $this->load->library('field_behavior'); - $data['provider'] = $this->_pagination($data['model']); - - $bread = Array( - '分类管理' => '', - $data['model']['description'] => site_url('category_content/view?model=' . $data['model']['name']), - ); - if($data['provider']) - { - foreach($data['provider']['path'] as $path) - { - $bread[ translate_number_to_tradition($path) ] = ''; - } - } - $data['bread'] = make_bread($bread); - $this->_template('category_content_list', $data); - } - - // ------------------------------------------------------------------------ - - /** - * 分页处理 - * - * @access private - * @param array - * @return array - */ - private function _pagination($model) - { - $this->load->library('pagination'); - $config['base_url'] = backend_url('category_content/view'); - $config['per_page'] = $model['perpage']; - $config['uri_segment'] = 3; - $config['suffix'] = '?model=' . $model['name']; - - $condition = array('classid >' => '0'); - $data['where'] = array(); - - //暂时无搜索 - - $level = $this->input->get('u_c_level', TRUE) ? $this->input->get('u_c_level', TRUE) : 0; - - $config['suffix'] .= '&level=' . $level; - $data['where']['u_c_level'] = $level; - $condition['parentid ='] = $level; - - $this->plugin_manager->trigger_model_action('register_before_query', $condition); - - $config['total_rows'] = $this->db - ->where($condition) - ->count_all_results($this->db->dbprefix('u_c_') . $model['name']); - - $this->db->from($this->db->dbprefix('u_c_') . $model['name']); - $this->db->select('classid, parentid'); - $this->db->where($condition); - foreach ($model['listable'] as $v) - { - $this->db->select($model['fields'][$v]['name']); - } - - $this->db->offset($this->uri->segment($config['uri_segment'], 0)); - $this->db->limit($config['per_page']); - - $data['list'] = $this->db->get()->result(); - - $this->plugin_manager->trigger_model_action('register_before_list', $data['list']); - - if ($level != 0) - { - $data['parent'] = $this->db->where('classid', $level)->get($this->db->dbprefix('u_c_') . $model['name'])->row(); - $data['next_level'] = $data['parent']->level + 1; - } - else - { - $data['parent'] = NULL ; - $data['next_level'] = 1; - } - - $data['path'] = $this->_find_path($data['next_level']); - - $config['first_url'] = $config['base_url'] . $config['suffix']; - $this->pagination->initialize($config); - $data['pagination'] = $this->pagination->create_links(); - return $data; - } - - // ------------------------------------------------------------------------ - - /** - * 获取path,用于显示在导航栏 - * - * @access private - * @param int - * @return array - */ - private function _find_path($parentid = 0) - { - $path = array(); - for ($i = 1; $i <= $parentid; $i++) - { - array_push($path, $i . "级分类"); - } - return $path; - } - - // ------------------------------------------------------------------------ - - /** - * 添加/修改入口 - * - * @access public - * @return void - */ - public function form() - { - $this->_save_post(); - } - - // ------------------------------------------------------------------------ - - /** - * 添加/修改表单显示/处理函数 - * - * @access public - * @return void - */ - public function _save_post() - { - - $model = $this->input->get('model', TRUE); - $this->settings->load('category/cate_' . $model); - $data['model'] = $this->settings->item('cate_models'); - $data['model'] = $data['model'][$model]; - $id = $this->input->get('id'); - if ($id) - { - $this->_check_permit('edit'); - $data['content'] = $this->db->where('classid', $id)->get($this->db->dbprefix('u_c_') . $model)->row_array(); - $data['attachment'] = $this->db->where('model', $data['model']['id']) - ->where('content', $id) - ->where('from', 1) - ->get($this->db->dbprefix('attachments')) - ->result_array(); - $data['parentid'] = $data['content']['parentid']; - $data['button_name'] = '编辑'; - } - else - { - $this->_check_permit('add'); - $data['parentid'] = $this->input->get('u_c_level') ? $this->input->get('u_c_level') : 0; - $data['content'] = array(); - $data['button_name'] = '添加'; - } - - if ($data['parentid'] > 0) - { - $current_level = $this->db->where('classid', $data['parentid']) - ->get($this->db->dbprefix('u_c_') . $model) - ->row() - ->level + 1; - } - else - { - $current_level = 1; - } - - - $data['path'] = $this->_find_path($current_level); - - $this->load->library('form_validation'); - - foreach ($data['model']['fields'] as $v) - { - if ($v['rules'] != '') - { - $this->form_validation->set_rules($v['name'], $v['description'], str_replace(",", "|", $v['rules'])); - } - } - - $this->load->library('form'); - $this->load->library('field_behavior'); - if ($this->form_validation->run() == FALSE) - { - - $bread = Array( - '分类管理' => '', - $data['model']['description'] => site_url('category_content/view?model=' . $data['model']['name']), - ); - if($data['path']) - { - foreach($data['path'] as $path) - { - $bread[ translate_number_to_tradition($path) ] = ''; - } - } - $bread[ $id ? '编辑' : '添加' ] = ''; - $data['bread'] = make_bread($bread); - - $this->_template('category_content_form', $data); - } - else - { - $modeldata = $data['model']; - $data = array(); - foreach ($modeldata['fields'] as $v) - { - if ($v['editable']) - { - $this->field_behavior->on_do_post($v, $data); - } - } - $data['parentid'] = $this->input->post('parentid', TRUE); - //获取path - if ($data['parentid'] > 0) - { - //如果不是顶级分类,就读其path数据 - $data['path'] = '0'; - $data['level'] = 1; - $parent_class = $this->db->where('classid', $data['parentid'])->get($this->db->dbprefix('u_c_') . $model)->row(); - if ($parent_class AND ! $parent_class->path) - { - $data['path'] .= ',' ; - $data['level'] = $parent_class->level + 1; - } - $data['path'] .= $data['parentid'] . ',0'; - } - $attachment = $this->input->post('uploadedfile', TRUE); - - if ($id) - { - $this->plugin_manager->trigger_model_action('register_before_update', $data, $id); - $this->db->where('classid', $id); - $this->db->update($this->db->dbprefix('u_c_') . $model,$data); - $this->plugin_manager->trigger_model_action('register_after_update', $data, $id); - if ($attachment != '0') - { - $this->db->set('model', $modeldata['id']) - ->set('from', 1) - ->set('content', $id) - ->where('aid in (' . $attachment . ')') - ->update($this->db->dbprefix('attachments')); - } - $this->_message('修改成功!', 'category_content/form', TRUE, '?model=' . $modeldata['name'] . '&id=' . $id); - } - else - { - $this->plugin_manager->trigger_model_action('register_before_insert', $data); - $this->db->insert($this->db->dbprefix('u_c_') . $model,$data); - $id = $this->db->insert_id(); - $this->plugin_manager->trigger_model_action('register_after_insert', $data, $id); - if($attachment != '0') - { - $this->db->set('model',$modeldata['id'])->set('from',1)->set('content',$id)->where('aid in ('.$attachment.')')->update($this->db->dbprefix('attachments')); - } - $this->_message('添加成功!','category_content/view',true,'?model='.$modeldata['name'].'&u_c_level='.$data['parentid']); - } - } - - } - - // ------------------------------------------------------------------------ - - /** - * 删除入口 - * - * @access public - * @return void - */ - public function del() - { - $this->_check_permit(); - $this->_del_post(); - } - - // ------------------------------------------------------------------------ - - /** - * 删除处理函数 - * - * @access public - * @return void - */ - public function _del_post() - { - $this->_check_permit(); - $ids = $this->input->get_post('classid', TRUE); - $model = $this->input->get('model', TRUE); - $model_id = $this->db->select('id')->where('name', $model)->get($this->db->dbprefix('cate_models'))->row()->id; - if ($ids) - { - - if ( ! is_array($ids)) - { - $ids = array($ids); - } - //搜索子分类 - $this->db->select('classid')->from($this->db->dbprefix('u_c_') . $model); - $where_string = 'classid < 0 '; - foreach ($ids as $v) - { - $where_string .= " OR path Like '%," . $v . ",%'"; - } - $this->db->where($where_string); - $result = $this->db->get()->result(); - foreach ($result as $v) - { - array_push($ids, $v->classid); - } - $this->plugin_manager->trigger_model_action('register_before_delete', $ids); - $attachments = $this->db->select('name, folder, type') - ->where('model', $model_id) - ->where_in('content', $ids) - ->where('from', 1) - ->get($this->db->dbprefix('attachments')) - ->result(); - foreach ($attachments as $attachment) - { - $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . - setting('attachment_dir') . '/' . - $attachment->folder . '/' . - $attachment->name . '.' . - $attachment->type); - } - $this->db->where('model', $model_id)->where_in('content', $ids) - ->where('from', 1) - ->delete($this->db->dbprefix('attachments')); - $this->db->where_in('classid', $ids)->delete($this->db->dbprefix('u_c_') . $model); - $this->plugin_manager->trigger_model_action('register_after_delete', $ids); - } - $this->_message('删除操作成功完成!', '', TRUE); - } - - // ------------------------------------------------------------------------ - - /** - * 相关附件列表和删除 - * - * @access public - * @param string - * @return void - */ - public function attachment($action = 'list') - { - if ($action == 'list') - { - $response = array(); - $ids = $this->input->get('ids', TRUE); - $attachments = $this->db->select('aid, realname, name, image, folder, type') - ->where("aid in ($ids)") - ->get($this->db->dbprefix('attachments')) - ->result_array(); - foreach ($attachments as $v) - { - array_push($response, implode('|', $v)); - } - echo implode(',', $response); - } - else if($action == 'del') - { - $attach = $this->db->select('aid, name, folder, type') - ->where('aid', $this->input->get('id', TRUE)) - ->get($this->db->dbprefix('attachments')) - ->row(); - if ($attach) - { - $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . - setting('attachment_dir') . '/' . - $attach->folder . '/' . - $attach->name . '.' . - $attach->type); - $this->db->where('aid', $attach->aid)->delete($this->db->dbprefix('attachments')); - echo 'ok'; - } - } - } - - // ------------------------------------------------------------------------ - -} - -/* End of file category_content.php */ -/* Location: ./admin/controllers/category_content.php */ +_view_post(); + } + + // ------------------------------------------------------------------------ + + /** + * 分类内容列表页 + * + * @access public + * @return void + */ + public function _view_post() + { + $model = $this->input->get('model', TRUE); + if ( ! $model AND $this->acl->_default_link) + { + redirect($this->acl->_default_link); + } + $this->_check_permit(); + if ( ! $this->platform->cache_exists(DILICMS_SHARE_PATH . 'settings/category/cate_' . $model . '.php')) + { + $this->_message('不存在的分类模型!', '', FALSE); + } + $this->plugin_manager->trigger('reached'); + $this->settings->load('category/cate_' . $model); + $data['model'] = $this->settings->item('cate_models'); + $data['model'] = $data['model'][$model]; + $this->load->library('form'); + $this->load->library('field_behavior'); + $data['provider'] = $this->_pagination($data['model']); + + $bread = Array( + '分类管理' => '', + $data['model']['description'] => site_url('category_content/view?model=' . $data['model']['name']), + ); + if($data['provider']) + { + foreach($data['provider']['path'] as $path) + { + $bread[ translate_number_to_tradition($path) ] = ''; + } + } + $data['bread'] = make_bread($bread); + $this->_template('category_content_list', $data); + } + + // ------------------------------------------------------------------------ + + /** + * 分页处理 + * + * @access private + * @param array + * @return array + */ + private function _pagination($model) + { + $this->load->library('pagination'); + $config['base_url'] = backend_url('category_content/view'); + $config['per_page'] = $model['perpage']; + $config['uri_segment'] = 3; + $config['suffix'] = '?model=' . $model['name']; + + $condition = array('classid >' => '0'); + $data['where'] = array(); + + //暂时无搜索 + + $level = $this->input->get('u_c_level', TRUE) ? $this->input->get('u_c_level', TRUE) : 0; + + $config['suffix'] .= '&level=' . $level; + $data['where']['u_c_level'] = $level; + $condition['parentid ='] = $level; + + $this->plugin_manager->trigger('querying', $condition); + + $config['total_rows'] = $this->db + ->where($condition) + ->count_all_results($this->db->dbprefix('u_c_') . $model['name']); + + $this->db->from($this->db->dbprefix('u_c_') . $model['name']); + $this->db->select('classid, parentid'); + $this->db->where($condition); + foreach ($model['listable'] as $v) + { + $this->db->select($model['fields'][$v]['name']); + } + + $this->db->offset($this->uri->segment($config['uri_segment'], 0)); + $this->db->limit($config['per_page']); + + $data['list'] = $this->db->get()->result(); + + $this->plugin_manager->trigger('listing', $data['list']); + + if ($level != 0) + { + $data['parent'] = $this->db->where('classid', $level)->get($this->db->dbprefix('u_c_') . $model['name'])->row(); + $data['next_level'] = $data['parent']->level + 1; + } + else + { + $data['parent'] = NULL ; + $data['next_level'] = 1; + } + + $data['path'] = $this->_find_path($data['next_level']); + + $config['first_url'] = $config['base_url'] . $config['suffix']; + $this->pagination->initialize($config); + $data['pagination'] = $this->pagination->create_links(); + return $data; + } + + // ------------------------------------------------------------------------ + + /** + * 获取path,用于显示在导航栏 + * + * @access private + * @param int + * @return array + */ + private function _find_path($parentid = 0) + { + $path = array(); + for ($i = 1; $i <= $parentid; $i++) + { + array_push($path, $i . "级分类"); + } + return $path; + } + + // ------------------------------------------------------------------------ + + /** + * 添加/修改入口 + * + * @access public + * @return void + */ + public function form() + { + $this->_save_post(); + } + + // ------------------------------------------------------------------------ + + /** + * 添加/修改表单显示/处理函数 + * + * @access public + * @return void + */ + public function _save_post() + { + + $model = $this->input->get('model', TRUE); + $this->settings->load('category/cate_' . $model); + $data['model'] = $this->settings->item('cate_models'); + $data['model'] = $data['model'][$model]; + $id = $this->input->get('id'); + if ($id) + { + $this->_check_permit('edit'); + $data['content'] = $this->db->where('classid', $id)->get($this->db->dbprefix('u_c_') . $model)->row_array(); + $data['attachment'] = $this->db->where('model', $data['model']['id']) + ->where('content', $id) + ->where('from', 1) + ->get($this->db->dbprefix('attachments')) + ->result_array(); + $data['parentid'] = $data['content']['parentid']; + $data['button_name'] = '编辑'; + } + else + { + $this->_check_permit('add'); + $data['parentid'] = $this->input->get('u_c_level') ? $this->input->get('u_c_level') : 0; + $data['content'] = array(); + $data['button_name'] = '添加'; + } + + if ($data['parentid'] > 0) + { + $current_level = $this->db->where('classid', $data['parentid']) + ->get($this->db->dbprefix('u_c_') . $model) + ->row() + ->level + 1; + } + else + { + $current_level = 1; + } + + + $data['path'] = $this->_find_path($current_level); + + $this->load->library('form_validation'); + + foreach ($data['model']['fields'] as $v) + { + if ($v['rules'] != '') + { + $this->form_validation->set_rules($v['name'], $v['description'], str_replace(",", "|", $v['rules'])); + } + } + + $this->load->library('form'); + $this->load->library('field_behavior'); + if ($this->form_validation->run() == FALSE) + { + + $bread = Array( + '分类管理' => '', + $data['model']['description'] => site_url('category_content/view?model=' . $data['model']['name']), + ); + if($data['path']) + { + foreach($data['path'] as $path) + { + $bread[ translate_number_to_tradition($path) ] = ''; + } + } + $bread[ $id ? '编辑' : '添加' ] = ''; + $data['bread'] = make_bread($bread); + + $this->_template('category_content_form', $data); + } + else + { + $modeldata = $data['model']; + $data = array(); + foreach ($modeldata['fields'] as $v) + { + if ($v['editable']) + { + $this->field_behavior->on_do_post($v, $data); + } + } + $data['parentid'] = $this->input->post('parentid', TRUE); + //获取path + if ($data['parentid'] > 0) + { + //如果不是顶级分类,就读其path数据 + $data['path'] = '0'; + $data['level'] = 1; + $parent_class = $this->db->where('classid', $data['parentid'])->get($this->db->dbprefix('u_c_') . $model)->row(); + if ($parent_class AND ! $parent_class->path) + { + $data['path'] .= ',' ; + $data['level'] = $parent_class->level + 1; + } + $data['path'] .= $data['parentid'] . ',0'; + } + $attachment = $this->input->post('uploadedfile', TRUE); + + if ($id) + { + $this->plugin_manager->trigger('updating', $data, $id); + $this->db->where('classid', $id); + $this->db->update($this->db->dbprefix('u_c_') . $model,$data); + $this->plugin_manager->trigger('updated', $data, $id); + if ($attachment != '0') + { + $this->db->set('model', $modeldata['id']) + ->set('from', 1) + ->set('content', $id) + ->where('aid in (' . $attachment . ')') + ->update($this->db->dbprefix('attachments')); + } + $this->_message('修改成功!', 'category_content/form', TRUE, '?model=' . $modeldata['name'] . '&id=' . $id); + } + else + { + $this->plugin_manager->trigger('inserting', $data); + $this->db->insert($this->db->dbprefix('u_c_') . $model,$data); + $id = $this->db->insert_id(); + $this->plugin_manager->trigger('inserted', $data, $id); + if($attachment != '0') + { + $this->db->set('model',$modeldata['id'])->set('from',1)->set('content',$id)->where('aid in ('.$attachment.')')->update($this->db->dbprefix('attachments')); + } + $this->_message('添加成功!','category_content/view',true,'?model='.$modeldata['name'].'&u_c_level='.$data['parentid']); + } + } + + } + + // ------------------------------------------------------------------------ + + /** + * 删除入口 + * + * @access public + * @return void + */ + public function del() + { + $this->_check_permit(); + $this->_del_post(); + } + + // ------------------------------------------------------------------------ + + /** + * 删除处理函数 + * + * @access public + * @return void + */ + public function _del_post() + { + $this->_check_permit(); + $ids = $this->input->get_post('classid', TRUE); + $model = $this->input->get('model', TRUE); + $model_id = $this->db->select('id')->where('name', $model)->get($this->db->dbprefix('cate_models'))->row()->id; + if ($ids) + { + + if ( ! is_array($ids)) + { + $ids = array($ids); + } + //搜索子分类 + $this->db->select('classid')->from($this->db->dbprefix('u_c_') . $model); + $where_string = 'classid < 0 '; + foreach ($ids as $v) + { + $where_string .= " OR path Like '%," . $v . ",%'"; + } + $this->db->where($where_string); + $result = $this->db->get()->result(); + foreach ($result as $v) + { + array_push($ids, $v->classid); + } + $this->plugin_manager->trigger('deleting', $ids); + $attachments = $this->db->select('name, folder, type') + ->where('model', $model_id) + ->where_in('content', $ids) + ->where('from', 1) + ->get($this->db->dbprefix('attachments')) + ->result(); + foreach ($attachments as $attachment) + { + $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . + setting('attachment_dir') . '/' . + $attachment->folder . '/' . + $attachment->name . '.' . + $attachment->type); + } + $this->db->where('model', $model_id)->where_in('content', $ids) + ->where('from', 1) + ->delete($this->db->dbprefix('attachments')); + $this->db->where_in('classid', $ids)->delete($this->db->dbprefix('u_c_') . $model); + $this->plugin_manager->trigger('deleted', $ids); + } + $this->_message('删除操作成功完成!', '', TRUE); + } + + // ------------------------------------------------------------------------ + + /** + * 相关附件列表和删除 + * + * @access public + * @param string + * @return void + */ + public function attachment($action = 'list') + { + if ($action == 'list') + { + $response = array(); + $ids = $this->input->get('ids', TRUE); + $attachments = $this->db->select('aid, realname, name, image, folder, type') + ->where("aid in ($ids)") + ->get($this->db->dbprefix('attachments')) + ->result_array(); + foreach ($attachments as $v) + { + array_push($response, implode('|', $v)); + } + echo implode(',', $response); + } + else if($action == 'del') + { + $attach = $this->db->select('aid, name, folder, type') + ->where('aid', $this->input->get('id', TRUE)) + ->get($this->db->dbprefix('attachments')) + ->row(); + if ($attach) + { + $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . + setting('attachment_dir') . '/' . + $attach->folder . '/' . + $attach->name . '.' . + $attach->type); + $this->db->where('aid', $attach->aid)->delete($this->db->dbprefix('attachments')); + echo 'ok'; + } + } + } + + // ------------------------------------------------------------------------ + +} + +/* End of file category_content.php */ +/* Location: ./admin/controllers/category_content.php */ diff --git a/admin/controllers/content.php b/admin/controllers/content.php index b079fb4..cb2d716 100644 --- a/admin/controllers/content.php +++ b/admin/controllers/content.php @@ -1,391 +1,394 @@ -_view_post(); - } - - // ------------------------------------------------------------------------ - - /** - * 内容列表页 - * - * @access public - * @return void - */ - public function _view_post() - { - $model = $this->input->get('model', TRUE); - if ( ! $model AND $this->acl->_default_link) - { - redirect($this->acl->_default_link); - } - $this->_check_permit(); - if ( ! $this->platform->cache_exists(DILICMS_SHARE_PATH . 'settings/model/' . $model . '.php')) - { - $this->_message('不存在的模型!', '', FALSE); - } - $this->plugin_manager->trigger_model_action('register_on_reach_model_list'); - $this->settings->load('model/' . $model); - $data['model'] = $this->settings->item('models'); - $data['model'] = $data['model'][$model]; - $this->load->library('form'); - $this->load->library('field_behavior'); - $data['provider'] = $this->_pagination($data['model']); - $data['bread'] = make_bread(Array( - '内容管理' => '', - $data['model']['description'] => site_url('content/view?model=' . $data['model']['name']), - )); - $this->_template('content_list', $data); - } - - // ------------------------------------------------------------------------ - - /** - * 分页处理 - * - * @access private - * @param array - * @return array - */ - private function _pagination($model) - { - $this->load->library('pagination'); - $config['base_url'] = backend_url('content/view'); - $config['per_page'] = $model['perpage']; - $config['uri_segment'] = 3; - $config['suffix'] = '?model=' . $model['name']; - - $condition = array('id >' => '0'); - $data['where'] = array(); - - foreach ($model['searchable'] as $v) - { - $this->field_behavior->on_do_search($model['fields'][$v], $condition, $data['where'], $config['suffix']); - } - - $this->plugin_manager->trigger_model_action('register_before_query', $condition); - - $config['total_rows'] = $this->db->where($condition)->count_all_results($this->db->dbprefix('u_m_') . $model['name']); - - $this->db->from($this->db->dbprefix('u_m_') . $model['name']); - $this->db->select('id, create_time'); - $this->db->where($condition); - $this->field_behavior->set_extra_condition(); - foreach ($model['listable'] as $v) - { - $this->db->select($model['fields'][$v]['name']); - } - - $this->db->order_by('create_time', 'DESC'); - $this->db->offset($this->uri->segment($config['uri_segment'], 0)); - $this->db->limit($config['per_page']); - - $data['list'] = $this->db->get()->result(); - - $this->plugin_manager->trigger_model_action('register_before_list', $data['list']); - - $config['first_url'] = $config['base_url'] . $config['suffix']; - $this->pagination->initialize($config); - $data['pagination'] = $this->pagination->create_links(); - return $data; - } - - // ------------------------------------------------------------------------ - - /** - * 添加/修改入口 - * - * @access public - * @return void - */ - public function form() - { - $this->_save_post(); - } - - // ------------------------------------------------------------------------ - - /** - * 添加/修改表单显示/处理函数 - * - * @access public - * @return void - */ - public function _save_post() - { - $model = $this->input->get('model', TRUE); - $this->settings->load('model/' . $model); - $data['model'] = $this->settings->item('models'); - $data['model'] = $data['model'][$model]; - $id = $this->input->get('id'); - - $data['button_name'] = $id ? '编辑' : '添加'; - $data['bread'] = make_bread(Array( - '内容管理' => '', - $data['model']['description'] => site_url('content/view?model=' . $data['model']['name']), - $data['button_name'] => '', - )); - - if ($id) - { - $this->_check_permit('edit'); - $data['content'] = $this->db->where('id',$id)->get($this->db->dbprefix('u_m_') . $model)->row_array(); - $data['attachment'] = $this->db->where('model', $data['model']['id']) - ->where('content', $id) - ->where('from', 0) - ->get($this->db->dbprefix('attachments')) - ->result_array(); - } - else - { - $this->_check_permit('add'); - $data['content'] = array(); - } - - $this->load->library('form_validation'); - - foreach ($data['model']['fields'] as $v) - { - if ($v['rules'] != '') - { - $this->form_validation->set_rules($v['name'], $v['description'], str_replace(",", "|", $v['rules'])); - } - } - - - $this->load->library('form'); - $this->load->library('field_behavior'); - if ($this->form_validation->run() == FALSE) - { - $this->_template('content_form', $data); - } - else - { - $modeldata = $data['model']; - $data = array(); - foreach ($modeldata['fields'] as $v) - { - if ($v['editable']) - { - $this->field_behavior->on_do_post($v, $data); - } - - } - $attachment = $this->input->post('uploadedfile', TRUE); - if ($id) - { - $this->db->where('id', $id); - $data['update_time'] = $this->session->_get_time(); - $data['update_user'] = $this->_admin->uid; - $this->plugin_manager->trigger_model_action('register_before_update', $data , $id); - $this->db->update($this->db->dbprefix('u_m_') . $model,$data); - $this->plugin_manager->trigger_model_action('register_after_update', $data , $id); - if ($attachment != '0') - { - $this->db->set('model', $modeldata['id']) - ->set('from', 0) - ->set('content', $id) - ->where('aid in (' . $attachment . ')') - ->update($this->db->dbprefix('attachments')); - } - $this->_message('修改成功!', 'content/form', TRUE, '?model=' . $modeldata['name'] . '&id=' . $id); - } - else - { - - $data['create_time'] = $data['update_time'] = $this->session->_get_time(); - $data['create_user'] = $data['update_user'] = $this->_admin->uid; - $this->plugin_manager->trigger_model_action('register_before_insert', $data); - $this->db->insert($this->db->dbprefix('u_m_') . $model,$data); - $id = $this->db->insert_id(); - $this->plugin_manager->trigger_model_action('register_after_insert', $data,$id); - if ($attachment != '0') - { - $this->db->set('model', $modeldata['id']) - ->set('from', 0) - ->set('content', $id) - ->where('aid in (' . $attachment . ')') - ->update($this->db->dbprefix('attachments')); - } - $this->_message('添加成功!', 'content/view', TRUE, '?model=' . $modeldata['name']); - } - } - - } - - // ------------------------------------------------------------------------ - - /** - * 删除入口 - * - * @access public - * @return void - */ - public function del() - { - $this->_check_permit(); - $this->_del_post(); - } - - // ------------------------------------------------------------------------ - - /** - * 删除处理函数 - * - * @access public - * @return void - */ - public function _del_post() - { - $this->_check_permit(); - $ids = $this->input->get_post('id', TRUE); - $model = $this->input->get('model', TRUE); - $model_id = $this->db->select('id')->where('name', $model)->get($this->db->dbprefix('models'))->row()->id; - if ($ids) - { - - if ( ! is_array($ids)) - { - $ids = array($ids); - } - $this->plugin_manager->trigger_model_action('register_before_delete', $ids); - $attachments = $this->db->select('name, folder, type') - ->where('model', $model_id) - ->where('from', 0) - ->where_in('content', $ids) - ->get($this->db->dbprefix('attachments')) - ->result(); - foreach ($attachments as $attachment) - { - $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . - setting('attachment_dir') . '/' . - $attachment->folder . '/' . - $attachment->name . '.' . - $attachment->type); - } - $this->db->where('model', $model_id)->where_in('content', $ids)->where('from', 0)->delete($this->db->dbprefix('attachments')); - $this->db->where_in('id', $ids)->delete($this->db->dbprefix('u_m_') . $model); - $this->plugin_manager->trigger_model_action('register_after_delete', $ids); - } - $this->_message('删除成功!', '', TRUE); - } - - // ------------------------------------------------------------------------ - - /** - * 相关附件列表和删除 - * - * @access public - * @param string - * @return void - */ - public function attachment($action = 'list') - { - if ($action == 'list') - { - $response = array(); - $ids = $this->input->get('ids', TRUE); - $attachments = $this->db->select('aid, realname, name, image, folder, type') - ->where("aid in ($ids)") - ->get($this->db->dbprefix('attachments')) - ->result_array(); - foreach ($attachments as $v) - { - array_push($response, implode('|', $v)); - } - echo implode(',', $response); - } - else if($action == 'del') - { - $attach = $this->db->select('aid, name, folder, type') - ->where('aid', $this->input->get('id', TRUE)) - ->get($this->db->dbprefix('attachments')) - ->row(); - if ($attach) - { - $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . - setting('attachment_dir') . '/' . - $attach->folder . '/' . - $attach->name . '.' . - $attach->type); - $this->db->where('aid', $attach->aid)->delete($this->db->dbprefix('attachments')); - echo 'ok'; - } - } - } - - // ------------------------------------------------------------------------ - - /** - * 模糊搜索记录,用于调用内容字段 - * - * @access public - * @param string - * @return void - */ - public function search($model, $field) - { - $html = ''; - $q = $this->input->get('keyword', TRUE); - if ($q AND $results = $this->db->select("id, $field")->like($field, $q)->limit(10)->get('u_m_'.$model)->result()) - { - foreach ($results as $result) - { - $html .= '

'.str_replace($q, "$q", $result->$field).'

'; - } - } - echo $html; - } - - // ------------------------------------------------------------------------ - -} - -/* End of file content.php */ -/* Location: ./admin/controllers/content.php */ +_view_post(); + } + + // ------------------------------------------------------------------------ + + /** + * 内容列表页 + * + * @access public + * @return void + */ + public function _view_post() + { + $model = $this->input->get('model', TRUE); + if ( ! $model AND $this->acl->_default_link) + { + redirect($this->acl->_default_link); + } + $this->_check_permit(); + if ( ! $this->platform->cache_exists(DILICMS_SHARE_PATH . 'settings/model/' . $model . '.php')) + { + $this->_message('不存在的模型!', '', FALSE); + } + $this->plugin_manager->trigger('reached'); + $this->settings->load('model/' . $model); + $data['model'] = $this->settings->item('models'); + $data['model'] = $data['model'][$model]; + $this->load->library('form'); + $this->load->library('field_behavior'); + $data['provider'] = $this->_pagination($data['model']); + $data['bread'] = make_bread(Array( + '内容管理' => '', + $data['model']['description'] => site_url('content/view?model=' . $data['model']['name']), + )); + $this->_template('content_list', $data); + } + + // ------------------------------------------------------------------------ + + /** + * 分页处理 + * + * @access private + * @param array + * @return array + */ + private function _pagination($model) + { + $this->load->library('pagination'); + $config['base_url'] = backend_url('content/view'); + $config['per_page'] = $model['perpage']; + $config['uri_segment'] = 3; + $config['suffix'] = '?model=' . $model['name']; + + $condition = array('id >' => '0'); + $data['where'] = array(); + + foreach ($model['searchable'] as $v) + { + $this->field_behavior->on_do_search($model['fields'][$v], $condition, $data['where'], $config['suffix']); + } + + $this->plugin_manager->trigger('querying', $condition); + + $config['total_rows'] = $this->db->where($condition)->count_all_results($this->db->dbprefix('u_m_') . $model['name']); + + $this->db->from($this->db->dbprefix('u_m_') . $model['name']); + $this->db->select('id, create_time'); + $this->db->where($condition); + $this->field_behavior->set_extra_condition(); + foreach ($model['listable'] as $v) + { + $this->db->select($model['fields'][$v]['name']); + } + + $this->db->order_by('create_time', 'DESC'); + $this->db->offset($this->uri->segment($config['uri_segment'], 0)); + $this->db->limit($config['per_page']); + + $data['list'] = $this->db->get()->result(); + + $this->plugin_manager->trigger('listing', $data['list']); + + $config['first_url'] = $config['base_url'] . $config['suffix']; + + $this->pagination->initialize($config); + + $data['pagination'] = $this->pagination->create_links(); + + return $data; + } + + // ------------------------------------------------------------------------ + + /** + * 添加/修改入口 + * + * @access public + * @return void + */ + public function form() + { + $this->_save_post(); + } + + // ------------------------------------------------------------------------ + + /** + * 添加/修改表单显示/处理函数 + * + * @access public + * @return void + */ + public function _save_post() + { + $model = $this->input->get('model', TRUE); + $this->settings->load('model/' . $model); + $data['model'] = $this->settings->item('models'); + $data['model'] = $data['model'][$model]; + $id = $this->input->get('id'); + + $data['button_name'] = $id ? '编辑' : '添加'; + $data['bread'] = make_bread(Array( + '内容管理' => '', + $data['model']['description'] => site_url('content/view?model=' . $data['model']['name']), + $data['button_name'] => '', + )); + + if ($id) + { + $this->_check_permit('edit'); + $data['content'] = $this->db->where('id',$id)->get($this->db->dbprefix('u_m_') . $model)->row_array(); + $data['attachment'] = $this->db->where('model', $data['model']['id']) + ->where('content', $id) + ->where('from', 0) + ->get($this->db->dbprefix('attachments')) + ->result_array(); + } + else + { + $this->_check_permit('add'); + $data['content'] = array(); + } + + $this->load->library('form_validation'); + + foreach ($data['model']['fields'] as $v) + { + if ($v['rules'] != '') + { + $this->form_validation->set_rules($v['name'], $v['description'], str_replace(",", "|", $v['rules'])); + } + } + + + $this->load->library('form'); + $this->load->library('field_behavior'); + if ($this->form_validation->run() == FALSE) + { + $this->_template('content_form', $data); + } + else + { + $modeldata = $data['model']; + $data = array(); + foreach ($modeldata['fields'] as $v) + { + if ($v['editable']) + { + $this->field_behavior->on_do_post($v, $data); + } + + } + $attachment = $this->input->post('uploadedfile', TRUE); + if ($id) + { + $this->db->where('id', $id); + $data['update_time'] = $this->session->_get_time(); + $data['update_user'] = $this->_admin->uid; + $this->plugin_manager->trigger('updating', $data , $id); + $this->db->update($this->db->dbprefix('u_m_') . $model, $data); + $this->plugin_manager->trigger('updated', $data , $id); + if ($attachment != '0') + { + $this->db->set('model', $modeldata['id']) + ->set('from', 0) + ->set('content', $id) + ->where('aid in (' . $attachment . ')') + ->update($this->db->dbprefix('attachments')); + } + $this->_message('修改成功!', 'content/form', TRUE, '?model=' . $modeldata['name'] . '&id=' . $id); + } + else + { + + $data['create_time'] = $data['update_time'] = $this->session->_get_time(); + $data['create_user'] = $data['update_user'] = $this->_admin->uid; + $this->plugin_manager->trigger('inserting', $data); + $this->db->insert($this->db->dbprefix('u_m_') . $model, $data); + $id = $this->db->insert_id(); + $this->plugin_manager->trigger('inserted', $data, $id); + if ($attachment != '0') + { + $this->db->set('model', $modeldata['id']) + ->set('from', 0) + ->set('content', $id) + ->where('aid in (' . $attachment . ')') + ->update($this->db->dbprefix('attachments')); + } + $this->_message('添加成功!', 'content/view', TRUE, '?model=' . $modeldata['name']); + } + } + + } + + // ------------------------------------------------------------------------ + + /** + * 删除入口 + * + * @access public + * @return void + */ + public function del() + { + $this->_check_permit(); + $this->_del_post(); + } + + // ------------------------------------------------------------------------ + + /** + * 删除处理函数 + * + * @access public + * @return void + */ + public function _del_post() + { + $this->_check_permit(); + $ids = $this->input->get_post('id', TRUE); + $model = $this->input->get('model', TRUE); + $model_id = $this->db->select('id')->where('name', $model)->get($this->db->dbprefix('models'))->row()->id; + if ($ids) + { + + if ( ! is_array($ids)) + { + $ids = array($ids); + } + $this->plugin_manager->trigger('deleting', $ids); + $attachments = $this->db->select('name, folder, type') + ->where('model', $model_id) + ->where('from', 0) + ->where_in('content', $ids) + ->get($this->db->dbprefix('attachments')) + ->result(); + foreach ($attachments as $attachment) + { + $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . + setting('attachment_dir') . '/' . + $attachment->folder . '/' . + $attachment->name . '.' . + $attachment->type); + } + $this->db->where('model', $model_id)->where_in('content', $ids)->where('from', 0)->delete($this->db->dbprefix('attachments')); + $this->db->where_in('id', $ids)->delete($this->db->dbprefix('u_m_') . $model); + $this->plugin_manager->trigger('deleted', $ids); + } + $this->_message('删除成功!', '', TRUE); + } + + // ------------------------------------------------------------------------ + + /** + * 相关附件列表和删除 + * + * @access public + * @param string + * @return void + */ + public function attachment($action = 'list') + { + if ($action == 'list') + { + $response = array(); + $ids = $this->input->get('ids', TRUE); + $attachments = $this->db->select('aid, realname, name, image, folder, type') + ->where("aid in ($ids)") + ->get($this->db->dbprefix('attachments')) + ->result_array(); + foreach ($attachments as $v) + { + array_push($response, implode('|', $v)); + } + echo implode(',', $response); + } + else if($action == 'del') + { + $attach = $this->db->select('aid, name, folder, type') + ->where('aid', $this->input->get('id', TRUE)) + ->get($this->db->dbprefix('attachments')) + ->row(); + if ($attach) + { + $this->platform->file_delete(DILICMS_SHARE_PATH . '../' . + setting('attachment_dir') . '/' . + $attach->folder . '/' . + $attach->name . '.' . + $attach->type); + $this->db->where('aid', $attach->aid)->delete($this->db->dbprefix('attachments')); + echo 'ok'; + } + } + } + + // ------------------------------------------------------------------------ + + /** + * 模糊搜索记录,用于调用内容字段 + * + * @access public + * @param string + * @return void + */ + public function search($model, $field) + { + $html = ''; + $q = $this->input->get('keyword', TRUE); + if ($q AND $results = $this->db->select("id, $field")->like($field, $q)->limit(10)->get('u_m_'.$model)->result()) + { + foreach ($results as $result) + { + $html .= '

'.str_replace($q, "$q", $result->$field).'

'; + } + } + echo $html; + } + + // ------------------------------------------------------------------------ + +} + +/* End of file content.php */ +/* Location: ./admin/controllers/content.php */ diff --git a/admin/controllers/module.php b/admin/controllers/module.php index 2fe51bd..91f5dd8 100644 --- a/admin/controllers/module.php +++ b/admin/controllers/module.php @@ -1,92 +1,80 @@ -acl->detect_plugin_menus(); - } - - // ------------------------------------------------------------------------ - - /** - * GET方式入口 - * - * @access public - * @return void - */ - public function run() - { - $this->_run_post(); - } - - // ------------------------------------------------------------------------ - - /** - * POST方式入口 - * - * @access public - * @return void - */ - public function _run_post() - { - $plugin = $this->input->get('plugin', TRUE); - if ( ! $plugin AND $this->acl->_default_link) - { - redirect($this->acl->_default_link); - } - $this->_check_permit(); - $action = $this->input->get('action', TRUE); - if ( $action - AND - isset($this->plugin_manager->active_plugins[$plugin]['instance']) - AND - in_array(strtolower($action), array_map('strtolower', get_class_methods('plugin_' . $plugin))) - ) - { - $data['content'] = $this->plugin_manager->active_plugins[$plugin]['instance']->$action(); - $this->_template('', $data); - } - else - { - $this->_message('未定义的操作!', '', FALSE); - } - } - - // ------------------------------------------------------------------------ - -} - -/* End of file module.php */ +acl->detect_plugin_menus(); + + $this->initialize(); + + } + + private function initialize() + { + $plugin = $this->input->get('plugin', TRUE); + if ( ! $plugin AND $this->acl->_default_link) + { + redirect($this->acl->_default_link); + } + $this->_check_permit(); + $controller = $this->input->get('c', true); + $method = $this->input->get('m', TRUE); + $path = DILICMS_EXTENSION_PATH.'plugins/'.$plugin.'/controllers/'.$plugin.'_'.$controller.'.php'; + if ( $controller + and + file_exists($path) + ) + { + include $path; + $controller = ucfirst($plugin . '_' . $controller); + $this->plugin = new $controller($plugin); + $data['content'] = $this->plugin->$method(); + $this->_template('', $data); + exit($this->output->get_output()); + } + else + { + $this->_message('未找到处理程序!', '', FALSE); + } + } + +} + +/* End of file module.php */ /* Location: ./admin/controllers/module.php */ \ No newline at end of file diff --git a/admin/controllers/setting.php b/admin/controllers/setting.php index 85176bd..35cb65d 100644 --- a/admin/controllers/setting.php +++ b/admin/controllers/setting.php @@ -1,104 +1,104 @@ -_check_permit(); - } - - // ------------------------------------------------------------------------ - - /** - * 站点设置表单页 - * - * @access public - * @return void - */ - public function site() - { - $data['site'] = $this->db->get($this->db->dbprefix('site_settings'))->row(); - $this->_template('settings_site', $data); - } - - // ------------------------------------------------------------------------ - - /** - * 站点设置处理函数 - * - * @access public - * @return void - */ - public function _site_post() - { - $this->db->update($this->db->dbprefix('site_settings'), $this->input->post()); - update_cache('site'); - $this->_message("更新成功", 'setting/site', TRUE, ($this->input->get('tab') ? '?tab=' . $this->input->get('tab') : '' )); - } - - // ------------------------------------------------------------------------ - - /** - * DiliCMS 设置表单页 - * - * @access public - * @return void - */ - public function backend() - { - $data['backend'] = $this->db->get($this->db->dbprefix('backend_settings'))->row(); - $this->_template('settings_backend', $data); - } - - // ------------------------------------------------------------------------ - - /** - * DiliCMS 设置处理函数 - * - * @access public - * @return void - */ - public function _backend_post() - { - $this->db->update($this->db->dbprefix('backend_settings'), $this->input->post()); - update_cache('backend'); - $this->_message("更新成功", 'setting/backend', TRUE, ($this->input->get('tab') ? '?tab=' . $this->input->get('tab') : '' )); - } - - // ------------------------------------------------------------------------ - -} - -/* End of file setting.php */ +_check_permit(); + } + + // ------------------------------------------------------------------------ + + /** + * 站点设置表单页 + * + * @access public + * @return void + */ + public function site() + { + $data['site'] = $this->db->get($this->db->dbprefix('site_settings'))->row(); + $this->_template('settings_site', $data); + } + + // ------------------------------------------------------------------------ + + /** + * 站点设置处理函数 + * + * @access public + * @return void + */ + public function _site_post() + { + $this->db->update($this->db->dbprefix('site_settings'), $this->input->post()); + update_cache('site'); + $this->_message("更新成功", 'setting/site', TRUE, ($this->input->get('tab') ? '?tab=' . $this->input->get('tab') : '' )); + } + + // ------------------------------------------------------------------------ + + /** + * DiliCMS 设置表单页 + * + * @access public + * @return void + */ + public function backend() + { + $data['backend'] = $this->db->get($this->db->dbprefix('backend_settings'))->row(); + $this->_template('settings_backend', $data); + } + + // ------------------------------------------------------------------------ + + /** + * DiliCMS 设置处理函数 + * + * @access public + * @return void + */ + public function _backend_post() + { + $this->db->update($this->db->dbprefix('backend_settings'), $this->input->post()); + update_cache('backend'); + $this->_message("更新成功", 'setting/backend', TRUE, ($this->input->get('tab') ? '?tab=' . $this->input->get('tab') : '' )); + } + + // ------------------------------------------------------------------------ + +} + +/* End of file setting.php */ /* Location: ./admin/controllers/setting.php */ \ No newline at end of file diff --git a/admin/core/Dili_Controller.php b/admin/core/Dili_Controller.php index 8839e8e..c073816 100644 --- a/admin/core/Dili_Controller.php +++ b/admin/core/Dili_Controller.php @@ -1,148 +1,148 @@ -load->database(); - $this->load->library('session'); - $this->settings->load('backend'); - $this->load->switch_theme(setting('backend_theme')); - $this->_check_login(); - $this->load->library('acl'); - $this->load->library('plugin_manager'); - } - - // ------------------------------------------------------------------------ - - /** - * 检查用户是否登录 - * - * @access protected - * @return void - */ - protected function _check_login() - { - if ( ! $this->session->userdata('uid')) - { - redirect(setting('backend_access_point') . '/login'); - } - else - { - $this->_admin = $this->user_mdl->get_full_user_by_username($this->session->userdata('uid'), 'uid'); - if ($this->_admin->status != 1) - { - $this->session->set_flashdata('error', "此帐号已被冻结,请联系管理员!"); - redirect(setting('backend_access_point') . '/login'); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * 加载视图 - * - * @access protected - * @param string - * @param array - * @return void - */ - protected function _template($template, $data = array()) - { - $data['tpl'] = $template; - $this->load->view('sys_entry', $data); - } - - // ------------------------------------------------------------------------ - - /** - * 检查权限 - * - * @access protected - * @param string - * @return void - */ - protected function _check_permit($action = '', $folder = '') - { - if ( ! $this->acl->permit($action, $folder)) - { - $this->_message('对不起,你没有访问这里的权限!', '', FALSE); - } - } - - // ------------------------------------------------------------------------ - - /** - * 信息提示 - * - * @access public - * @param string - * @param string - * @param bool - * @param string - * @return void - */ - public function _message($msg, $goto = '', $auto = TRUE, $fix = '', $pause = 3000) - { - if($goto == '') - { - $goto = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : site_url(); - } - else - { - $goto = strpos($goto, 'http') !== false ? $goto : backend_url($goto); - } - $goto .= $fix; - $this->_template('sys_message', array('msg' => $msg, 'goto' => $goto, 'auto' => $auto, 'pause' => $pause)); - echo $this->output->get_output(); - exit(); - } - - // ------------------------------------------------------------------------ - -} - -/* End of file Dili_Controller.php */ -/* Location: ./admin/core/Dili_Controller.php */ +load->database(); + $this->load->library('session'); + $this->settings->load('backend'); + $this->load->switch_theme(setting('backend_theme')); + $this->_check_login(); + $this->load->library('acl'); + $this->load->library('plugin_manager'); + } + + // ------------------------------------------------------------------------ + + /** + * 检查用户是否登录 + * + * @access protected + * @return void + */ + protected function _check_login() + { + if ( ! $this->session->userdata('uid')) + { + redirect(setting('backend_access_point') . '/login'); + } + else + { + $this->_admin = $this->user_mdl->get_full_user_by_username($this->session->userdata('uid'), 'uid'); + if ($this->_admin->status != 1) + { + $this->session->set_flashdata('error', "此帐号已被冻结,请联系管理员!"); + redirect(setting('backend_access_point') . '/login'); + } + } + } + + // ------------------------------------------------------------------------ + + /** + * 加载视图 + * + * @access protected + * @param string + * @param array + * @return void + */ + protected function _template($template, $data = array()) + { + $data['tpl'] = $template; + $this->load->view('sys_entry', $data); + } + + // ------------------------------------------------------------------------ + + /** + * 检查权限 + * + * @access protected + * @param string + * @return void + */ + protected function _check_permit($action = '', $folder = '') + { + if ( ! $this->acl->permit($action, $folder)) + { + $this->_message('对不起,你没有访问这里的权限!', '', FALSE); + } + } + + // ------------------------------------------------------------------------ + + /** + * 信息提示 + * + * @access public + * @param string + * @param string + * @param bool + * @param string + * @return void + */ + public function _message($msg, $goto = '', $auto = TRUE, $fix = '', $pause = 3000) + { + if($goto == '') + { + $goto = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : site_url(); + } + else + { + $goto = strpos($goto, 'http') !== false ? $goto : backend_url($goto); + } + $goto .= $fix; + $this->_template('sys_message', array('msg' => $msg, 'goto' => $goto, 'auto' => $auto, 'pause' => $pause)); + echo $this->output->get_output(); + exit(); + } + + // ------------------------------------------------------------------------ + +} + +/* End of file Dili_Controller.php */ +/* Location: ./admin/core/Dili_Controller.php */ \ No newline at end of file diff --git a/admin/templates/default/category_content_form.php b/admin/templates/default/category_content_form.php index 80fefa8..4981167 100644 --- a/admin/templates/default/category_content_form.php +++ b/admin/templates/default/category_content_form.php @@ -1,53 +1,53 @@ - - - - - - - - - -
-
- -
- -
- -
-
-
- - - - - - - - - - - - plugin_manager->trigger_model_action('register_view', $content); ?> - - - - - -
- field_behavior->on_form($v , isset($content[$v['name']]) ? $content[$v['name']] : '', TRUE, $model['hasattach']); ?> - -
- - form->show_hidden('uploadedfile','0',true); ?> - - form->show_hidden('parentid', $parentid ,true); ?> - -
- -
-
- + + + + + + + + + +
+
+ +
+ +
+ +
+
+
+ + + + + + + + + + + + plugin_manager->trigger('rendered', $content); ?> + + + + + +
+ field_behavior->on_form($v , isset($content[$v['name']]) ? $content[$v['name']] : '', TRUE, $model['hasattach']); ?> + +
+ + form->show_hidden('uploadedfile','0',true); ?> + + form->show_hidden('parentid', $parentid ,true); ?> + +
+ +
+
+ diff --git a/admin/templates/default/category_content_list.php b/admin/templates/default/category_content_list.php index 170be0f..a5e6b88 100644 --- a/admin/templates/default/category_content_list.php +++ b/admin/templates/default/category_content_list.php @@ -1,85 +1,85 @@ - -
-
-
- - - - 1): ?> - - - plugin_manager->trigger_model_action('register_operation'); ?> -
-
- - - - - - - - - - - - -
操作选项
-
-
- -
- 'category_content_list_form')); ?> - - - - - - - - - - - - - - -
- field_behavior->on_list($model['fields'][$vt],$v); ?> - - - 进入子分类 - 添加 - - 修改 - 删除 - plugin_manager->trigger_model_action('register_list_view', $v); ?> -
- -
- - -plugin_manager->trigger_model_action('register_list_view', $provider['list']); ?> + +
+
+
+ + + + 1): ?> + + + plugin_manager->trigger('buttons'); ?> +
+
+ + + + + + + + + + + + +
操作选项
+
+
+ +
+ 'category_content_list_form')); ?> + + + + + + + + + + + + + + +
+ field_behavior->on_list($model['fields'][$vt],$v); ?> + + + 进入子分类 + 添加 + + 修改 + 删除 + plugin_manager->trigger('row_buttons', $v); ?> +
+ +
+ + +plugin_manager->trigger('listed', $provider['list']); ?> diff --git a/admin/templates/default/content_form.php b/admin/templates/default/content_form.php index 07ff8c1..e5c7069 100644 --- a/admin/templates/default/content_form.php +++ b/admin/templates/default/content_form.php @@ -1,57 +1,57 @@ - - - - - - - - - -
-
-
- - - - - - -
-
-
-
- - - - - - - - - - - - - plugin_manager->trigger_model_action('register_view', $content); ?> - - - - -
- field_behavior->on_form($v , isset($content[$v['name']]) ? $content[$v['name']] : '', TRUE, $model['hasattach']); ?> - -
- - form->show_hidden('uploadedfile','0',true); ?> - - -
- -
-
- + + + + + + + + + +
+
+
+ + + + + + +
+
+
+
+ + + + + + + + + + + + + plugin_manager->trigger('rendered', $content); ?> + + + + +
+ field_behavior->on_form($v , isset($content[$v['name']]) ? $content[$v['name']] : '', TRUE, $model['hasattach']); ?> + +
+ + form->show_hidden('uploadedfile','0',true); ?> + + +
+ +
+
+ diff --git a/admin/templates/default/content_list.php b/admin/templates/default/content_list.php index 0115a95..7de2df2 100644 --- a/admin/templates/default/content_list.php +++ b/admin/templates/default/content_list.php @@ -1,107 +1,107 @@ - - - - - -
-
-
- - - - - -
- - - - - - - - - - - - - -
- field_behavior->on_search($model['fields'][$v],(isset($provider['where'][$model['fields'][$v]['name']]) ? $provider['where'][$model['fields'][$v]['name']] : '' )); ?> -
- -
- - plugin_manager->trigger_model_action('register_operation'); ?> -
-
- - - - - - - - - - - - - -
发布时间操作选项
-
-
- -
- 'content_list_form')); ?> - - - - - - - - - - - - - - - -
create_time); ?> - field_behavior->on_list($model['fields'][$vt],$v); ?> - - 修改 - 删除 - plugin_manager->trigger_model_action('register_list_operation_view', $v); ?> -
- -
- - - -plugin_manager->trigger_model_action('register_list_view', $provider['list']); ?> + + + + + +
+
+
+ + + + + +
+ + + + + + + + + + + + + +
+ field_behavior->on_search($model['fields'][$v],(isset($provider['where'][$model['fields'][$v]['name']]) ? $provider['where'][$model['fields'][$v]['name']] : '' )); ?> +
+ +
+ + plugin_manager->trigger('buttons'); ?> +
+
+ + + + + + + + + + + + + +
发布时间操作选项
+
+
+ +
+ 'content_list_form')); ?> + + + + + + + + + + + + + + + +
create_time); ?> + field_behavior->on_list($model['fields'][$vt],$v); ?> + + 修改 + 删除 + plugin_manager->trigger('row_buttons', $v); ?> +
+ +
+ + + +plugin_manager->trigger('listed', $provider['list']); ?> diff --git a/admin/templates/default/settings_backend.php b/admin/templates/default/settings_backend.php index 5d6e113..825aa29 100644 --- a/admin/templates/default/settings_backend.php +++ b/admin/templates/default/settings_backend.php @@ -1,49 +1,57 @@ - - -
-
系统>系统设置>后台设置
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
后台主题:
后台语言:
后台入口:
后台网页标题:
后台LOGO:
是否允许root用户登录: - backend_root_access ? 'checked="checked"' :''; ?> value="1" >开启 - backend_root_access ? 'checked="checked"' :''; ?> >关闭 -
- -
- -
+ + +
+
系统>系统设置>后台设置
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
后台主题:
后台语言:
后台入口:
后台网页标题:
后台LOGO:
插件开发模式: + plugin_dev_mode ? 'checked="checked"' :''; ?> value="1" >开启 + plugin_dev_mode ? 'checked="checked"' :''; ?> >关闭 + +
是否允许root用户登录: + backend_root_access ? 'checked="checked"' :''; ?> value="1" >开启 + backend_root_access ? 'checked="checked"' :''; ?> >关闭 +
+ +
+ +
\ No newline at end of file diff --git a/admin/templates/default/sys_entry.php b/admin/templates/default/sys_entry.php index 4a7a772..6ff3b00 100644 --- a/admin/templates/default/sys_entry.php +++ b/admin/templates/default/sys_entry.php @@ -1,62 +1,68 @@ - - - - -<?php echo setting('backend_title'); ?>----Powered By DiliCMS - - - - - - - -
- -
- - plugin_manager->trigger_navigation(); ?> -
-
- -
-
- uri->rsegment(1) != 'module'): ?> - load->view(isset($tpl) && $tpl ? $tpl : 'sys_default'); ?> - - load->view($tpl);} ?> - -
-
-
- - - + + + + +<?php echo setting('backend_title'); ?>----Powered By DiliCMS + + + + + + + +
+ +
+ + + + + plugin_manager->trigger_navigation(); ?> + +
+
+ +
+
+ uri->rsegment(1) != 'module'): ?> + load->view(isset($tpl) && $tpl ? $tpl : 'sys_default'); ?> + + load->view($tpl);} ?> + +
+
+
+ + + diff --git a/application/config/database.php b/application/config/database.php index 5b9c1a8..834aad9 100755 --- a/application/config/database.php +++ b/application/config/database.php @@ -58,7 +58,7 @@ $db['default']['password'] = 'root'; $db['default']['database'] = 'dilicms'; $db['default']['dbdriver'] = 'mysql'; -$db['default']['dbprefix'] = 'cd_'; +$db['default']['dbprefix'] = 'dili_'; $db['default']['pconnect'] = FALSE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php index 5c819ae..3aead59 100644 --- a/application/views/welcome_message.php +++ b/application/views/welcome_message.php @@ -71,8 +71,18 @@
+ + DiliCMS只有后台的基础部分,没有前台程序,请确认满足您的需求再进行安装使用。 + +

安装

- 点此进行安装 + + 点此进行安装 +
    +
  • 请确环境检测中提到的文件夹有写入权限(windows也有权限问题)
  • +
  • 安装程序采用HTML5,CSS3制作,请使用高端大气上档次的浏览器执行,^_^
  • +
+

QQ讨论群

185074106 diff --git a/install/config/database.php b/install/config/database.php index edb3d8e..fb6ce20 100755 --- a/install/config/database.php +++ b/install/config/database.php @@ -58,7 +58,7 @@ $db['default']['password'] = 'root'; $db['default']['database'] = 'dilicms'; $db['default']['dbdriver'] = 'mysql'; -$db['default']['dbprefix'] = 'cd_'; +$db['default']['dbprefix'] = 'dili_'; $db['default']['pconnect'] = FALSE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; diff --git a/install/schema/backend_settings.sql b/install/schema/backend_settings.sql index 4c6de37..caa1eb9 100644 --- a/install/schema/backend_settings.sql +++ b/install/schema/backend_settings.sql @@ -5,7 +5,8 @@ CREATE TABLE IF NOT EXISTS `{DB_PREFIX}backend_settings` ( `backend_root_access` tinyint(1) unsigned DEFAULT '1', `backend_access_point` varchar(20) DEFAULT 'admin', `backend_title` varchar(100) DEFAULT 'DiliCMS后台管理', - `backend_logo` varchar(100) DEFAULT 'images/logo.gif' + `backend_logo` varchar(100) DEFAULT 'images/logo.gif', + `plugin_dev_mode` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' ) ENGINE=MyISAM DEFAULT CHARSET=utf8{SEPERATOR} DELETE FROM `{DB_PREFIX}backend_settings`{SEPERATOR} INSERT INTO `{DB_PREFIX}backend_settings` (`backend_theme`, `backend_lang`, `backend_root_access`, `backend_access_point`, `backend_title`, `backend_logo`) VALUES ('default', 'zh-cn', 1, '', 'DiliCMS', 'images/logo.gif') \ No newline at end of file diff --git a/install/schema/menus.sql b/install/schema/menus.sql index 5d3d042..004de91 100644 --- a/install/schema/menus.sql +++ b/install/schema/menus.sql @@ -1,12 +1,12 @@ -DROP TABLE IF EXISTS `{DB_PREFIX}menus`{SEPERATOR} -CREATE TABLE IF NOT EXISTS `{DB_PREFIX}menus` ( - `menu_id` tinyint(10) unsigned NOT NULL AUTO_INCREMENT, - `class_name` varchar(20) NOT NULL, - `method_name` varchar(30) NOT NULL, - `menu_name` varchar(20) NOT NULL, - `menu_level` tinyint(2) unsigned DEFAULT '0', - `menu_parent` tinyint(10) unsigned DEFAULT '0', - PRIMARY KEY (`menu_id`) -) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=utf8{SEPERATOR} -DELETE FROM `{DB_PREFIX}menus`{SEPERATOR} -INSERT INTO `{DB_PREFIX}menus` (`menu_id`, `class_name`, `method_name`, `menu_name`, `menu_level`, `menu_parent`) VALUES (1, 'system', 'home', '系统', 0, 0), (2, 'system', 'home', '后台首页', 1, 1), (3, 'system', 'home', '后台首页', 2, 2), (4, 'setting', 'site', '系统设置', 1, 1), (5, 'setting', 'site', '站点设置', 2, 4), (6, 'setting', 'backend', '后台设置', 2, 4), (7, 'system', 'password', '修改密码', 2, 4), (8, 'system', 'cache', '更新缓存', 2, 4), (9, 'model', 'view', '模型管理', 1, 1), (10, 'model', 'view', '内容模型管理', 2, 9), (11, 'category', 'view', '分类模型管理', 2, 9), (12, 'plugin', 'view', '插件管理', 1, 1), (13, 'plugin', 'view', '插件管理', 2, 12), (14, 'role', 'view', '权限管理', 1, 1), (15, 'role', 'view', '用户组管理', 2, 14), (16, 'user', 'view', '用户管理', 2, 14), (17, 'content', 'view', '内容管理', 0, 0), (18, 'content', 'view', '内容管理', 1, 17), (19, 'category_content', 'view', '分类管理', 1, 17), (20, 'module', 'run', '工具', 0, 0), (21, 'database', 'index', '数据库管理', 1, 1), (22, 'database', 'index', '数据库备份', 2, 21), (23, 'database', 'recover', '数据库还原', 2, 21), (24, 'database', 'optimize', '数据库优化', 2, 21) \ No newline at end of file +DROP TABLE IF EXISTS `{DB_PREFIX}menus`{SEPERATOR} +CREATE TABLE IF NOT EXISTS `{DB_PREFIX}menus` ( + `menu_id` tinyint(10) unsigned NOT NULL AUTO_INCREMENT, + `class_name` varchar(20) NOT NULL, + `method_name` varchar(30) NOT NULL, + `menu_name` varchar(20) NOT NULL, + `menu_level` tinyint(2) unsigned DEFAULT '0', + `menu_parent` tinyint(10) unsigned DEFAULT '0', + PRIMARY KEY (`menu_id`) +) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=utf8{SEPERATOR} +DELETE FROM `{DB_PREFIX}menus`{SEPERATOR} +INSERT INTO `{DB_PREFIX}menus` (`menu_id`, `class_name`, `method_name`, `menu_name`, `menu_level`, `menu_parent`) VALUES (1, 'system', 'home', '系统', 0, 0), (2, 'system', 'home', '后台首页', 1, 1), (3, 'system', 'home', '后台首页', 2, 2), (4, 'setting', 'site', '系统设置', 1, 1), (5, 'setting', 'site', '站点设置', 2, 4), (6, 'setting', 'backend', '后台设置', 2, 4), (7, 'system', 'password', '修改密码', 2, 4), (8, 'system', 'cache', '更新缓存', 2, 4), (9, 'model', 'view', '模型管理', 1, 1), (10, 'model', 'view', '内容模型管理', 2, 9), (11, 'category', 'view', '分类模型管理', 2, 9), (12, 'plugin', 'view', '扩展管理', 1, 1), (13, 'plugin', 'view', '插件管理', 2, 12), (14, 'role', 'view', '权限管理', 1, 1), (15, 'role', 'view', '用户组管理', 2, 14), (16, 'user', 'view', '用户管理', 2, 14), (17, 'content', 'view', '内容管理', 0, 0), (18, 'content', 'view', '内容管理', 1, 17), (19, 'category_content', 'view', '分类管理', 1, 17), (20, 'module', 'run', '插件', 0, 0), (21, 'database', 'index', '数据库管理', 1, 1), (22, 'database', 'index', '数据库备份', 2, 21), (23, 'database', 'recover', '数据库还原', 2, 21), (24, 'database', 'optimize', '数据库优化', 2, 21) \ No newline at end of file diff --git a/shared/config/constant.php b/shared/config/constant.php index 9bca037..4cd2b4a 100755 --- a/shared/config/constant.php +++ b/shared/config/constant.php @@ -11,7 +11,7 @@ define('IN_DILICMS', TRUE); - define('DILICMS_VERSION', 'V2.1.3'); + define('DILICMS_VERSION', 'V2.2.0-rc.1'); define('DILICMS_SHARE_PATH', BASEPATH . '../shared/'); diff --git a/shared/helpers/common_helper.php b/shared/helpers/common_helper.php index 928e1f3..fb58047 100755 --- a/shared/helpers/common_helper.php +++ b/shared/helpers/common_helper.php @@ -1,112 +1,136 @@ -settings->item($key); - } -} - -// ------------------------------------------------------------------------ - -/** - * 更新缓存 - * - * @access public - * @param array - * @param string - * @return void - */ -if ( ! function_exists('update_cache')) -{ - function update_cache($array, $fix = '') - { - $ci = &get_instance(); - $ci->load->model('cache_mdl'); - $array = is_array($array) ? $array : array($array); - foreach ($array as $v) - { - $method = 'update_' . $v . '_cache'; - $ci->cache_mdl->$method($fix); - } - } -} - -// ------------------------------------------------------------------------ - -/** - * 将array转换成缓存字符 - * - * @access public - * @param string - * @param array - * @return void - */ -if ( ! function_exists('array_to_cache')) -{ - function array_to_cache($name, $array) - { - return 'settings->item($key); + } +} + +// ------------------------------------------------------------------------ + +/** + * 更新缓存 + * + * @access public + * @param array + * @param string + * @return void + */ +if ( ! function_exists('update_cache')) +{ + function update_cache($array, $fix = '') + { + $ci = &get_instance(); + $ci->load->model('cache_mdl'); + $array = is_array($array) ? $array : array($array); + foreach ($array as $v) + { + $method = 'update_' . $v . '_cache'; + $ci->cache_mdl->$method($fix); + } + } +} + +// ------------------------------------------------------------------------ + +/** + * 将array转换成缓存字符 + * + * @access public + * @param string + * @param array + * @return void + */ +if ( ! function_exists('array_to_cache')) +{ + function array_to_cache($name, $array) + { + return 'config->item('index_page') === '') + { + return backend_url("plugin/$name/$controller/$method", http_build_query($qs)); + } + $qs['plugin'] = $plugin; + $qs['c'] = $controller; + $qs['m'] = $method; + return backend_url('module/run', http_build_query($qs)); + } +} + +// ------------------------------------------------------------------------ + +/* End of file common_helper.php */ /* Location: ./shared/heleprs/common_helper.php */ \ No newline at end of file diff --git a/shared/libraries/Acl.php b/shared/libraries/Acl.php index a198b41..16521eb 100755 --- a/shared/libraries/Acl.php +++ b/shared/libraries/Acl.php @@ -1,426 +1,432 @@ -ci = & get_instance(); - $this->ci->settings->load('menus');//加载菜单数据 - $this->top_menus = & setting('menus'); - if ($this->ci->_admin->role != 1) - { - $this->ci->settings->load('acl/role_' . $this->ci->_admin->role . '.php');//加载权限数据 - $this->top_menus = & setting('menus'); - $this->rights = & setting('current_role'); - } - $this->_filter_menus(); - } - - // ------------------------------------------------------------------------ - - /** - * 输出顶部菜单 - * - * @access public - * @return void - */ - public function show_top_menus() - { - //检查是否显示顶部插件菜单. - $is_show_module_menu = FALSE; - if ($this->ci->plugin_manager->trigger_left_menu()) - { - $is_show_module_menu = TRUE; - } - $last_menu_key = count($this->top_menus) - 1; - foreach ($this->top_menus as $key => $v) - { - if ($key === 2 AND ! $is_show_module_menu) - { - continue; - } - echo '
  • ' . $v['menu_name'] .' -
  • '; - } - } - - // ------------------------------------------------------------------------ - - /** - * 输出边栏菜单 - * - * @access public - * @return void - */ - public function show_left_menus() - { - foreach ($this->left_menus as $v) - { - if ($v['sub_menus']) - { - echo '
  • ' . $v['menu_name'] . ' -
      '; - foreach ($v['sub_menus'] as $j) - { - $extra = ''; - $this->_current_menu == 1 AND $extra = 'model=' . $j['extra'] ; - $this->_current_menu == 2 AND $extra = $j['extra']; - echo '
    • ' . $j['menu_name'] . '
    • '; - } - echo '
    -
  • '; - } - } - } - - // ------------------------------------------------------------------------ - - /** - * 过滤菜单 - * - * @access private - * @return void - */ - private function _filter_menus() - { - $class_name = $this->ci->uri->rsegment(1); - $method_name = $this->ci->uri->rsegment(2); - switch ($class_name) - { - case 'content' : - case 'category_content' : - $this->_filter_content_menus($class_name, $method_name); - break; - case 'module' : - $this->_filter_module_menus($class_name, $method_name); - break; - case 'system' : - case 'setting': - case 'model' : - case 'category' : - case 'plugin' : - case 'role' : - case 'user' : - case 'database' : - $this->_filter_normal_menus($class_name, $method_name); - break; - default : - //noting to do - } - } - - // ------------------------------------------------------------------------ - - /** - * 过滤系统菜单 - * - * @access private - * @param string - * @param string - * @return void - */ - private function _filter_normal_menus($class_name, $method_name, $default_uri = 'system/home', $current_menu = 0, $folder = '') - {//0 - $this->_current_menu = $current_menu; - $this->_default_link = backend_url($default_uri); - $this->left_menus = & $this->top_menus[$this->_current_menu]['sub_menus']; - foreach ($this->left_menus as $vkey => & $v) - { - foreach ($v['sub_menus'] as $jkey => & $j) - { - if ($j['class_name'] == $folder . $class_name AND $j['method_name'] == $method_name) - { - $j['current'] = TRUE; - } - if ($this->ci->_admin->role == 1) - { - continue; - } - $right = $j['class_name'] . '@' . $j['method_name']; - if ( ! in_array($right, $this->rights['rights']) AND $right !='system@home') - { - unset($this->left_menus[$vkey]['sub_menus'][$jkey]); - } - } - if ( ! $v['sub_menus']) - { - unset($this->left_menus[$vkey]); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * 过滤模型菜单 - * - * @access private - * @param string - * @param string - * @return void - */ - private function _filter_content_menus($class_name, $method_name) - {//1 - $this->_current_menu = 1; - $this->left_menus = & $this->top_menus[$this->_current_menu]['sub_menus']; - $extra = $this->ci->input->get('model'); - foreach ($this->left_menus as $vkey => & $v) - { - foreach ($v['sub_menus'] as $jkey => & $j) - { - if ($j['class_name'] == $class_name AND $j['method_name'] == $method_name AND - ( ($j['extra'] == $extra AND $vkey == 0) || ($j['extra'] == $extra AND $vkey == 1) ) ) - { - $j['current'] = TRUE; - } - - if ($this->ci->_admin->role == 1) - { - continue; - } - $right = $j['class_name'] . '@' . $j['method_name']; - if ( ! in_array($right, $this->rights['rights']) || - ( ! in_array($j['extra'], $this->rights['models']) AND $vkey == 0) || - ( ! in_array($j['extra'], $this->rights['category_models']) AND $vkey == 1) - ) - { - unset($this->left_menus[$vkey]['sub_menus'][$jkey]); - } - } - if ( ! $v['sub_menus']) - { - unset($this->left_menus[$vkey]); - } - } - //设定默认链接 - if ($_item = @ reset($this->left_menus[0]['sub_menus'])) - { - if ( ! $this->_default_link) - { - $this->_default_link = backend_url($_item['class_name'] . '/view', 'model=' . $_item['extra']); - } - } - - } - - // ------------------------------------------------------------------------ - - /** - * 过滤插件菜单 - * - * @access private - * @param string - * @param string - * @return void - */ - private function _filter_module_menus($class_name, $method_name) - {//2 - $this->_current_menu = 2; - } - - // ------------------------------------------------------------------------ - - /** - * 检测模块插件菜单 - * - * @access public - * @return void - */ - public function detect_plugin_menus() - { - $this->top_menus[$this->_current_menu]['sub_menus'] = $this->ci->plugin_manager->trigger_left_menu(); - $this->left_menus = & $this->top_menus[$this->_current_menu]['sub_menus']; - foreach ($this->left_menus as $key => & $v) - { - if (isset($v['sub_menus']) AND $v['sub_menus']) - { - foreach ($v['sub_menus'] as & $j) - { - $j['extra'] = 'plugin=' . $j['class_name'] . '&action=' . $j['method_name']; - if ($j['class_name'] == $this->ci->input->get('plugin') AND $j['method_name'] == $this->ci->input->get('action')) - { - $j['current'] = TRUE; - } - $j['class_name'] = 'module'; - $j['method_name'] = 'run'; - if ( ! $this->_default_link) - { - $this->_default_link = backend_url('module/run', $j['extra']); - } - } - } - else - { - unset($this->left_menus[$key]); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * 检测插件 - * - * @access public - * @param string - * @return void - */ - public function permit($act = '', $folder = '') - { - if ($this->ci->_admin->role == 1) - { - return TRUE; - } - $class_method = $folder . $this->ci->uri->rsegment(1) . '@' . $this->ci->uri->rsegment(2) . ($act ? '@' . $act : ''); - if ( ! in_array($class_method,$this->rights['rights'])) - { - return FALSE; - } - if ( $this->ci->uri->rsegment(1) == 'content' ) - { - if ( ! in_array($this->ci->input->get('model'), $this->rights['models'])) - { - return FALSE; - } - } - else if ($this->ci->uri->rsegment(1) == 'category_content') - { - if ( ! in_array($this->ci->input->get('model'), $this->rights['category_models'])) - { - return FALSE; - } - } - else if ($this->ci->uri->rsegment(1) == 'module') - { - if ( ! in_array($this->ci->input->get('plugin'), $this->rights['plugins'])) - { - return FALSE; - } - } - return TRUE; - } - - // ------------------------------------------------------------------------ - - /** - * 设置顶部选中菜单 - * - * @access public - * @param int - * @return void - */ - public function set_current_menu($key = 0) - { - $this->_current_menu = $key; - } - - // ------------------------------------------------------------------------ - - /** - * 触发自定义菜单的检测 - * - * @access public - * @param int - * @return void - */ - public function filter_left_menus($default_uri = '', $current_menu = 0, $folder = '') - { - $current_menu AND $this->_current_menu = $current_menu; - $class_name = $this->ci->uri->rsegment(1); - $method_name = $this->ci->uri->rsegment(2); - $this->_filter_normal_menus($class_name, $method_name, $default_uri, $this->_current_menu, $folder); - } - - // ------------------------------------------------------------------------ - -} - -/* End of file Acl.php */ +ci = & get_instance(); + $this->ci->settings->load('menus');//加载菜单数据 + $this->top_menus = & setting('menus'); + if ($this->ci->_admin->role != 1) + { + $this->ci->settings->load('acl/role_' . $this->ci->_admin->role . '.php');//加载权限数据 + $this->top_menus = & setting('menus'); + $this->rights = & setting('current_role'); + } + $this->_filter_menus(); + } + + // ------------------------------------------------------------------------ + + /** + * 输出顶部菜单 + * + * @access public + * @return void + */ + public function show_top_menus() + { + //检查是否显示顶部插件菜单. + $is_show_module_menu = FALSE; + if ($this->ci->plugin_manager->get_menus()) + { + $is_show_module_menu = TRUE; + } + $last_menu_key = count($this->top_menus) - 1; + foreach ($this->top_menus as $key => $v) + { + if ($key === 2 AND ! $is_show_module_menu) + { + continue; + } + echo '
  • ' . $v['menu_name'] .' +
  • '; + } + } + + // ------------------------------------------------------------------------ + + /** + * 输出边栏菜单 + * + * @access public + * @return void + */ + public function show_left_menus() + { + foreach ($this->left_menus as $key => $v) + { + if ($v['sub_menus']) + { + echo '
  • ' . $v['menu_name'] . ' +
      '; + foreach ($v['sub_menus'] as $j) + { + $extra = ''; + $this->_current_menu == 1 AND $extra = 'model=' . $j['extra'] ; + if ($this->_current_menu == 2) { + echo '
    • ' . $j['menu_name'] . '
    • '; + continue; + } + echo '
    • ' . $j['menu_name'] . '
    • '; + } + echo '
    +
  • '; + } + } + } + + // ------------------------------------------------------------------------ + + /** + * 过滤菜单 + * + * @access private + * @return void + */ + private function _filter_menus() + { + $class_name = $this->ci->uri->rsegment(1); + $method_name = $this->ci->uri->rsegment(2); + switch ($class_name) + { + case 'content' : + case 'category_content' : + $this->_filter_content_menus($class_name, $method_name); + break; + case 'module' : + $this->_filter_module_menus($class_name, $method_name); + break; + case 'system' : + case 'setting': + case 'model' : + case 'category' : + case 'plugin' : + case 'role' : + case 'user' : + case 'database' : + $this->_filter_normal_menus($class_name, $method_name); + break; + default : + //noting to do + } + } + + // ------------------------------------------------------------------------ + + /** + * 过滤系统菜单 + * + * @access private + * @param string + * @param string + * @return void + */ + private function _filter_normal_menus($class_name, $method_name, $default_uri = 'system/home', $current_menu = 0, $folder = '') + {//0 + $this->_current_menu = $current_menu; + $this->_default_link = backend_url($default_uri); + $this->left_menus = & $this->top_menus[$this->_current_menu]['sub_menus']; + foreach ($this->left_menus as $vkey => & $v) + { + foreach ($v['sub_menus'] as $jkey => & $j) + { + if ($j['class_name'] == $folder . $class_name AND $j['method_name'] == $method_name) + { + $j['current'] = TRUE; + } + if ($this->ci->_admin->role == 1) + { + continue; + } + $right = $j['class_name'] . '@' . $j['method_name']; + if ( ! in_array($right, $this->rights['rights']) AND $right !='system@home') + { + unset($this->left_menus[$vkey]['sub_menus'][$jkey]); + } + } + if ( ! $v['sub_menus']) + { + unset($this->left_menus[$vkey]); + } + } + } + + // ------------------------------------------------------------------------ + + /** + * 过滤模型菜单 + * + * @access private + * @param string + * @param string + * @return void + */ + private function _filter_content_menus($class_name, $method_name) + {//1 + $this->_current_menu = 1; + $this->left_menus = & $this->top_menus[$this->_current_menu]['sub_menus']; + $extra = $this->ci->input->get('model'); + foreach ($this->left_menus as $vkey => & $v) + { + foreach ($v['sub_menus'] as $jkey => & $j) + { + if ($j['class_name'] == $class_name AND $j['method_name'] == $method_name AND + ( ($j['extra'] == $extra AND $vkey == 0) || ($j['extra'] == $extra AND $vkey == 1) ) ) + { + $j['current'] = TRUE; + } + + if ($this->ci->_admin->role == 1) + { + continue; + } + $right = $j['class_name'] . '@' . $j['method_name']; + if ( ! in_array($right, $this->rights['rights']) || + ( ! in_array($j['extra'], $this->rights['models']) AND $vkey == 0) || + ( ! in_array($j['extra'], $this->rights['category_models']) AND $vkey == 1) + ) + { + unset($this->left_menus[$vkey]['sub_menus'][$jkey]); + } + } + if ( ! $v['sub_menus']) + { + unset($this->left_menus[$vkey]); + } + } + //设定默认链接 + if ($_item = @ reset($this->left_menus[0]['sub_menus'])) + { + if ( ! $this->_default_link) + { + $this->_default_link = backend_url($_item['class_name'] . '/view', 'model=' . $_item['extra']); + } + } + + } + + // ------------------------------------------------------------------------ + + /** + * 过滤插件菜单 + * + * @access private + * @param string + * @param string + * @return void + */ + private function _filter_module_menus($class_name, $method_name) + {//2 + $this->_current_menu = 2; + } + + // ------------------------------------------------------------------------ + + /** + * 检测模块插件菜单 + * + * @access public + * @return void + */ + public function detect_plugin_menus() + { + $this->top_menus[$this->_current_menu]['sub_menus'] = $this->ci->plugin_manager->get_menus(); + $this->left_menus = & $this->top_menus[$this->_current_menu]['sub_menus']; + foreach ($this->left_menus as $key => & $v) + { + if (isset($v['sub_menus']) AND $v['sub_menus']) + { + foreach ($v['sub_menus'] as & $j) + { + $j['extra'] = 'plugin=' . $key . '&action=' . $j['method_name']; + if ($key == $this->ci->input->get('plugin') + AND + $j['class_name'] == $this->ci->input->get('c') + AND + $j['method_name'] == $this->ci->input->get('m')) + { + $j['current'] = TRUE; + } + if ( ! $this->_default_link) + { + $this->_default_link = plugin_url($key, $j['class_name'], $j['method_name']); + } + } + } + else + { + unset($this->left_menus[$key]); + } + } + } + + // ------------------------------------------------------------------------ + + /** + * 检测插件 + * + * @access public + * @param string + * @return void + */ + public function permit($act = '', $folder = '') + { + if ($this->ci->_admin->role == 1) + { + return TRUE; + } + $class_method = $folder . $this->ci->uri->rsegment(1) . '@' . $this->ci->uri->rsegment(2) . ($act ? '@' . $act : ''); + if ( ! in_array($class_method,$this->rights['rights'])) + { + return FALSE; + } + if ( $this->ci->uri->rsegment(1) == 'content' ) + { + if ( ! in_array($this->ci->input->get('model'), $this->rights['models'])) + { + return FALSE; + } + } + else if ($this->ci->uri->rsegment(1) == 'category_content') + { + if ( ! in_array($this->ci->input->get('model'), $this->rights['category_models'])) + { + return FALSE; + } + } + else if ($this->ci->uri->rsegment(1) == 'module') + { + if ( ! in_array($this->ci->input->get('plugin'), $this->rights['plugins'])) + { + return FALSE; + } + } + return TRUE; + } + + // ------------------------------------------------------------------------ + + /** + * 设置顶部选中菜单 + * + * @access public + * @param int + * @return void + */ + public function set_current_menu($key = 0) + { + $this->_current_menu = $key; + } + + // ------------------------------------------------------------------------ + + /** + * 触发自定义菜单的检测 + * + * @access public + * @param int + * @return void + */ + public function filter_left_menus($default_uri = '', $current_menu = 0, $folder = '') + { + $current_menu AND $this->_current_menu = $current_menu; + $class_name = $this->ci->uri->rsegment(1); + $method_name = $this->ci->uri->rsegment(2); + $this->_filter_normal_menus($class_name, $method_name, $default_uri, $this->_current_menu, $folder); + } + + // ------------------------------------------------------------------------ + +} + +/* End of file Acl.php */ /* Location: ./shared/libraries/Acl.php */ \ No newline at end of file diff --git a/shared/libraries/Plugin_manager.php b/shared/libraries/Plugin_manager.php index f0380a9..ba1d72d 100755 --- a/shared/libraries/Plugin_manager.php +++ b/shared/libraries/Plugin_manager.php @@ -1,352 +1,276 @@ -ci = & get_instance(); - $this->_init(); - } - - // ------------------------------------------------------------------------ - - /** - * 初始化 - * - * @access private - * @return void - */ - private function _init() - { - if ($this->ci->platform->cache_exists(DILICMS_SHARE_PATH . 'settings/plugins.php')) - { - eval('?>' . $this->ci->platform->cache_read(DILICMS_SHARE_PATH . 'settings/plugins.php')); - if (isset($setting['active_plugins'])) - { - $this->active_plugins = $setting['active_plugins']['plugins']; - $this->active_model_plugins = $setting['active_plugins']['model_plugins']; - $this->_load_plugins($this->active_plugins); - unset($setting['active_plugins']); - } - } - if ($this->ci->uri->rsegment(1) == 'category_content' || $this->ci->uri->rsegment(1) == 'content') - { - $this->_load_plugins($this->active_model_plugins, 'model_'); - } - } - - // ------------------------------------------------------------------------ - - /** - * 加载插件 - * - * @access private - * @param array - * @param string - * @return void - */ - private function _load_plugins( & $plugins, $name_fix = '') - { - foreach ($plugins as $key => & $plugin) - { - if ($plugin['access'] == 1 && $this->ci->_admin->role != 1) - { - unset($plugins[$key]); - continue; - } - if ($this->ci->_admin->role != 1 && ! in_array('module@run', $this->ci->acl->rights['rights']) ) - { - unset($plugins[$key]); - continue; - } - if ($this->ci->_admin->role != 1 && ! in_array($plugin['name'], $this->ci->acl->rights['plugins'])) - { - unset($plugins[$key]); - continue; - } - if ( ! file_exists(DILICMS_EXTENSION_PATH . 'plugins/' . $plugin['name'] . '/' . 'plugin_' . $name_fix . $plugin['name'] . '.php')) - { - unset($plugins[$key]); - } - else - { - $plugin_class = 'plugin_' . $name_fix . $plugin['name']; - include DILICMS_EXTENSION_PATH . 'plugins/' . $plugin['name'] . '/' . 'plugin_' . $name_fix . $plugin['name'] . '.php'; - if (class_exists($plugin_class)) - { - $plugin['instance'] = new $plugin_class($plugin['name']); - } - else - { - unset($plugins[$key]); - } - } - } - } - - // ------------------------------------------------------------------------ - - /** - * 导航触发钩子 - * - * @access public - * @return void - */ - public function trigger_navigation() - { - foreach ($this->active_plugins as $plugin) - { - $plugin['instance']->register_navigation(); - } - } - - // ------------------------------------------------------------------------ - - /** - * 菜单触发钩子 - * - * @access public - * @return void - */ - public function trigger_left_menu() - { - $left_menus = array(); - foreach ($this->active_plugins as $plugin) - { - $left_menu = $plugin['instance']->register_left_menu(); - if( $left_menu ) - { - $left_menus[] = $left_menu; - } - } - return $left_menus; - } - - // ------------------------------------------------------------------------ - - /** - * 附件处理钩子触发 - * - * @access public - * @param string - * @return void - */ - public function trigger_attachment($file) - { - foreach ($this->active_plugins as $plugin) - { - $plugin['instance']->register_attachment($file); - } - } - - // ------------------------------------------------------------------------ - - /** - * 模型插件系列钩子触发 - * - * @access public - * @param string - * @return void/false - */ - public function trigger_model_action($name = '' , & $arg1 = '' , & $arg2 = '') - { - if ( ! $name) - { - return FALSE; - } - foreach ($this->active_model_plugins as $plugin) - { - call_user_func_array(array(& $plugin['instance'], $name), array(& $arg1, & $arg2)); - } - } - -} - -// ------------------------------------------------------------------------ - -/** - * DiliCMS 插件基类 - * - * @package DiliCMS - * @subpackage Libraries - * @category Libraries - * @author Jeongee - * @link http://www.dilicms.com - */ -abstract class Dili_basic_plugin -{ - protected $_name = ''; - protected $_ci = NULL; - protected $_path = ''; - - public function __construct($name) - { - $this->_name = $name; - $this->_ci = & get_instance(); - $this->_path = DILICMS_EXTENSION_PATH . 'plugins/' . $this->_name . '/'; - } - - protected function _url($action, $qs = '') - { - return backend_url('module/run','plugin='.$this->_name.'&action='.$action).$qs; - } - - protected function _check($type = '' , $model = '') - { - return $this->_ci->uri->rsegment(1) == $type && $model == $this->_ci->input->get('model'); - } - - protected function _template($view , $data = array() , $output = true) - { - extract($data); - ob_start(); - eval('?>' . file_get_contents($this->_path . $view . '.php')); - $content = ob_get_contents(); - ob_end_clean(); - if ($output == TRUE) - { - echo $content; - } - else - { - return $content; - } - } - -} - -// ------------------------------------------------------------------------ - -/** - * DiliCMS 模型插件基类 - * - * @package DiliCMS - * @subpackage Libraries - * @category Libraries - * @author Jeongee - * @link http://www.dilicms.com - */ -abstract class Dili_model_plugin extends Dili_basic_plugin -{ - public function __construct($name) - { - parent::__construct($name); - } - //注册操作栏 - public function register_operation(){} - //注册模型信息插入前操作 - public function register_before_insert(){}//& $data - //注册模型信息插入后操作 - public function register_after_insert(){}//& $data ,$id - //注册模型信息修改前操作 - public function register_before_update(){}//& $data ,$id - //注册模型信息修改后操作 - public function register_after_update(){}//& $data ,$id - //注册模型信息删除前操作 - public function register_before_delete(){}//$ids - //注册模型信息删除后操作 - public function register_after_delete(){}//$ids - //注册模型信息添加修改页面视图 - public function register_view(){}//& $content - //注册模型信息列表QUERY之前 - public function register_before_query(){}//&$where - //注册模型信息列表数据二次处理 - public function register_before_list(){}//& $list - //注册模型信息列表显示页面 - public function register_list_view(){}//& $list - //注册模型信息列表操作栏 - public function register_list_operation_view(){}// &$data - //注册模型信息进入列表信息动作 - public function register_on_reach_model_list(){}// -} - -// ------------------------------------------------------------------------ - -/** - * DiliCMS 模块插件基类 - * - * @package DiliCMS - * @subpackage Libraries - * @category Libraries - * @author Jeongee - * @link http://www.dilicms.com - */ -abstract class Dili_plugin extends Dili_basic_plugin -{ - public function __construct($name) - { - parent::__construct($name); - } - //注册快速导航栏按钮 - public function register_navigation(){} - //注册左边栏菜单 - public function register_left_menu(){} - /*return array( 'menu_name' => 'Hello World 插件', - 'sub_menus' => array( - 0=>array('class_name'=>$this->_name,'method_name'=>'welcome','menu_name'=>'测试左菜单') - ) - );*/ - //注册快速导航栏按钮 - public function register_attachment(){}//参数为路径 -} - -/* End of file Plugin_manager.php */ +app = get_instance(); + + //如果插件开发模式开启了,将会每次自动更新插件缓存 + if ($this->app->settings->item('plugin_dev_mode')) { + + $this->app->load->model('cache_mdl'); + + $this->app->cache_mdl->update_plugin_cache(); + + } + + $this->initialize(); + } + + private function initialize() + { + //加载插件 + if ($this->app->platform->cache_exists(DILICMS_SHARE_PATH . 'settings/plugins.php')) + { + eval('?>' . $this->app->platform->cache_read(DILICMS_SHARE_PATH . 'settings/plugins.php')); + if (isset($setting['plugins']) and is_array($setting['plugins'])) + { + $this->plugins = $setting['plugins']; + $this->watch(); + unset($setting['plugins']); + } + } + if ($this->app->uri->rsegment(1) == 'category_content' || $this->app->uri->rsegment(1) == 'content') + { + $model = $this->app->input->get('model', true); + //重新分析classmap,加入autoloader + foreach ($this->plugins as $name => $plugin) { + foreach ($plugin['classmap'] as $filename => $hook) { + if ($model == $filename) { + $filename = ($name.'_hook_'.$model); + $this->classmap[$filename] = $hook; + } + } + } + + } + + //加载菜单 + foreach ($this->plugins as $name => $plugin) { + $this->menus[$name] = $plugin['menus']; + } + + } + + private function watch() + { + foreach ($this->plugins as $key => $plugin) + { + if ($plugin['access'] == 1 and $this->app->_admin->role != 1) + { + unset($this->plugins[$key]); + continue; + } + if ($this->app->_admin->role != 1 and ! in_array('module@run', $this->app->acl->rights['rights']) ) + { + unset($this->plugins[$key]); + continue; + } + if ($this->app->_admin->role != 1 && ! in_array($plugin['name'], $this->app->acl->rights['plugins'])) + { + unset($this->plugins[$key]); + continue; + } + } + } + + private function autoloader($class_name) + { + if (class_exists(ucfirst($class_name))) { + return true; + } + $path = DILICMS_EXTENSION_PATH . $this->classmap[$class_name]; + + if (isset($this->classmap[$class_name]) and file_exists($path)) + { + include $path; + } + if (! class_exists(ucfirst($class_name))) { + throw new RuntimeException("Can't Find Class $class_name."); + } + + } + + public function trigger($method, & $data = null, $other = null) + { + $args = array(&$data, $other); + foreach ($this->classmap as $class => $path) { + if (! isset($this->instances[$class])) { + $this->autoloader($class); + $this->instances[$class] = new $class; + } + + return call_user_func_array(array($this->instances[$class], $method), $args); + } + } + + public function get_menus() + { + return $this->menus; + } + +} + +interface DiliCMS_Model_Hook_Interface +{ + + /** + * 为操作工具栏新增按钮 + */ + public function buttons(); + + /** + * 模型数据新增入库前 + */ + public function inserting(&$data); + + /** + * 模型数据新增入库后 + */ + public function inserted($data, $id); + + /** + * 模型数据修改入库前 + */ + public function updating(&$data, $id); + + /** + * 模型数据修改入库后 + */ + public function updated($data, $id); + + /** + * 模型数据删除操作前 + */ + public function deleting(&$ids); + + /** + * 模型数据删除操作后 + */ + public function deleted($ids); + + /** + * 模型数据表单展示后 + */ + public function rendered($content); + + /** + * 模型数据列表执行查询前 + */ + public function querying(&$where); + + /** + * 模型数据列表展示前 + */ + public function listing(&$results); + + /** + * 模型数据列表展示后 + */ + public function listed($results); + + /** + * 模型数据列表各记录操作位置 + */ + public function row_buttons($data); + + /** + * 模型数据进入列表页面开始处理前 + * + * 可用于更细化的权限判断 + */ + //注册模型信息进入列表信息动作 + public function reaching(); +} + +/** + * DiliCMS 插件基类 + * + * @package DiliCMS + * @subpackage Libraries + * @category Libraries + * @author Jeongee + * @link http://www.dilicms.com + */ +abstract class DiliCMS_Plugin_Controller +{ + protected $name = ''; + + protected $app = null; + + protected $path = ''; + + public function __construct($name) + { + $this->name = $name; + + $this->app = & get_instance(); + + $this->path = DILICMS_EXTENSION_PATH . 'plugins/' . $this->name . '/'; + + $this->add_packages(); + } + + private function add_packages() + { + $this->load->add_package_path($this->path); + } + + protected function plugin_url($controller, $method, $qs = array()) + { + return plugin_url($this->name, $controller, $method, $qs); + } + + public function get_path() + { + return $this->path; + } + + public function __get($name) + { + if (property_exists($this->app, $name)) + { + return $this->app->$name; + } + } + +} + +/* End of file Plugin_manager.php */ /* Location: ./shared/libraries/Plugin_manager.php */ \ No newline at end of file diff --git a/shared/models/cache_mdl.php b/shared/models/cache_mdl.php index f40075a..96c0c97 100755 --- a/shared/models/cache_mdl.php +++ b/shared/models/cache_mdl.php @@ -1,420 +1,439 @@ -platform->get_type() == 'default') - { - if ( ! file_exists(DILICMS_SHARE_PATH . 'settings/' . $folder)) - { - mkdir(DILICMS_SHARE_PATH . 'settings/' . $folder); - } - } - - } - - // ------------------------------------------------------------------------ - - /** - * 更新内容模型缓存 - * - * @access public - * @param string - * @return void - */ - public function update_model_cache($target = '') - { - $data = array(); - if ($target) - { - $target = is_array($target) ? $target : array($target); - $this->db->where_in('name', $target); - } - $models = $this->db->get($this->db->dbprefix('models'))->result_array(); - foreach ($models as $model) - { - $model['fields'] = array(); - $model['fields_org'] = $this->db->where('model', $model['id']) - ->order_by('`order`', 'ASC') - ->get($this->db->dbprefix('model_fields')) - ->result_array(); - $model['listable'] = array(); - $model['searchable'] = array(); - foreach ($model['fields_org'] as $key=> & $v) - { - if ($v['listable'] == 1) - { - array_push($model['listable'], $v['id']); - } - if ($v['searchable'] == 1) - { - array_push($model['searchable'], $v['id']); - } - if (in_array($v['type'], array('select', 'checkbox', 'radio'))) - { - if ($v['values'] == '') - { - $v['values'] = array(); - } - else - { - $value = array(); - foreach (explode('|', $v['values']) as $vt) - { - if (strpos($vt, '=') > -1) - { - $vt = explode('=', $vt); - $value[$vt[0]] = $vt[1]; - } - else - { - $value[$vt] = $vt; - } - } - $v['values'] = $value; - } - } - $model['fields'][$v['id']] = $v; - } - unset($model['fields_org']); - $this->_create_folder('model'); - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/model/'.$model['name'].'.php', - array_to_cache("setting['models']['" . $model['name'] . "']", $model) - ); - } - } - - // ------------------------------------------------------------------------ - - /** - * 更新分类模型缓存 - * - * @access public - * @param string - * @return void - */ - public function update_category_cache($target = '') - { - $this->load->model('category_mdl'); - $data = array(); - if ($target) - { - $target = is_array($target) ? $target : array($target); - $this->db->where_in('name', $target); - } - $models = $this->db->get($this->db->dbprefix('cate_models'))->result_array(); - foreach ($models as $model) - { - $model['fields'] = array(); - $model['fields_org'] = $this->db->where('model', $model['id']) - ->order_by('`order`', 'ASC') - ->get($this->db->dbprefix('cate_fields')) - ->result_array(); - $model['listable'] = array(); - $model['searchable'] = array(); - foreach ($model['fields_org'] as $key=> & $v) - { - if ($v['listable'] == 1) - { - array_push($model['listable'], $v['id']); - } - if ($v['searchable'] == 1) - { - array_push($model['searchable'], $v['id']); - } - if (in_array($v['type'], array('select', 'checkbox', 'radio'))) - { - if ($v['values'] == '') - { - $v['values'] = array(); - } - else - { - $value = array(); - foreach (explode('|', $v['values']) as $vt) - { - if (strpos($vt,'=') > -1) - { - $vt = explode('=', $vt); - $value[$vt[0]] = $vt[1]; - } - else - { - $value[$vt] = $vt; - } - } - $v['values'] = $value; - } - } - $model['fields'][$v['id']] = $v; - } - unset($model['fields_org']); - $this->_create_folder('category'); - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/category/cate_' . $model['name'] . '.php', - array_to_cache("setting['cate_models']['" . $model['name'] . "']", $model)); - $category = array(); - $categories = $this->category_mdl->get_category($model['name']); - foreach($categories as $c) - { - $category[$c['classid']] = $c; - } - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/category/data_' . $model['name'] . '.php', - array_to_cache("setting['category']['" . $model['name'] . "']", $category)); - unset($categories,$category); - } - } - - // ------------------------------------------------------------------------ - - /** - * 更新菜单缓存 - * - * @access public - * @return void - */ - public function update_menu_cache() - { - $table_menu = $this->db->dbprefix('menus'); - $level_1_menus = $this->db->select('menu_id, class_name, method_name, menu_name') - ->where('menu_level', 0) - ->where('menu_parent', 0) - ->get($table_menu) - ->result_array(); - foreach ($level_1_menus as & $i) - { - $level_2_menus = $this->db->select('menu_id, class_name, method_name, menu_name') - ->where('menu_level', 1) - ->where('menu_parent', $i['menu_id']) - ->get($table_menu) - ->result_array(); - foreach ($level_2_menus as & $j) - { - if ($j['class_name'] == 'content') - { - $level_3_menus = $this->db - ->select(" 'content' AS class_name, 'view' AS 'method_name', name AS extra, description AS menu_name", FALSE) - ->get($this->db->dbprefix('models')) - ->result_array(); - } - else if ($j['class_name'] == 'category_content') - { - $level_3_menus = $this->db - ->select(" 'category_content' AS class_name, 'view' AS 'method_name', name AS extra, description AS menu_name", FALSE) - ->get($this->db->dbprefix('cate_models')) - ->result_array(); - } - else - { - $level_3_menus = $this->db->select('menu_id, class_name, method_name, menu_name') - ->where('menu_level', 2) - ->where('menu_parent', $j['menu_id']) - ->get($table_menu) - ->result_array(); - } - $j['sub_menus'] = $level_3_menus; - } - $i['sub_menus'] = $level_2_menus; - } - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/menus.php', - array_to_cache("setting['menus']", $level_1_menus)); - } - - // ------------------------------------------------------------------------ - - /** - * 更新用户组缓存 - * - * @access public - * @param string - * @return void - */ - public function update_role_cache($target = '') - { - if ($target) - { - $target = is_array($target) ? $target : array($target); - $this->db->where_in('id', $target); - } - $roles = $this->db->get($this->db->dbprefix('roles'))->result_array(); - foreach ($roles as & $role) - { - $role['rights'] = explode(',', $role['rights']); - $rights = $this->db->select('right_class, right_method, right_detail') - ->where_in('right_id', $role['rights']) - ->get($this->db->dbprefix('rights')) - ->result(); - $role['rights'] = array(); - foreach ($rights as $right) - { - $role['rights'][] = $right->right_class . '@' . $right->right_method . ($right->right_detail ? '@' . $right->right_detail : ''); - } - $role['models'] = explode(',', $role['models']); - $role['category_models'] = explode(',', $role['category_models']); - $role['plugins'] = explode(',', $role['plugins']); - $this->_create_folder('acl'); - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/acl/role_' . $role['id'] . '.php', - array_to_cache("setting['current_role']",$role)); - } - } - - // ------------------------------------------------------------------------ - - /** - * 更新站点信息缓存 - * - * @access public - * @return void - */ - public function update_site_cache() - { - $data = $this->db->get($this->db->dbprefix('site_settings'))->row_array(); - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/site.php', - array_to_cache("setting", $data)); - } - - // ------------------------------------------------------------------------ - - /** - * 更新后台设置缓存 - * - * @access public - * @return void - */ - public function update_backend_cache() - { - $data = $this->db->get($this->db->dbprefix('backend_settings'))->row_array(); - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/backend.php', - array_to_cache("setting", $data)); - } - - // ------------------------------------------------------------------------ - - /** - * 更新插件信息缓存 - * - * @access public - * @return void - */ - public function update_plugin_cache() - { - $cached_plugins = $model_plugins = $result_plugins = array(); - $plugins = $this->db->select('name, access') - ->where('active', '1') - ->get($this->db->dbprefix('plugins')) - ->result_array(); - if ($plugins) - { - foreach ($plugins as $key => $plugin) - { - if (file_exists(DILICMS_EXTENSION_PATH . 'plugins/' . $plugin['name'] . '/' . 'plugin_' . $plugin['name'] . '.php')) - { - $result_plugins[$plugin['name']] = $plugin; - } - if (file_exists(DILICMS_EXTENSION_PATH . 'plugins/' . $plugin['name'] . '/' . 'plugin_model_' . $plugin['name'] . '.php')) - { - $model_plugins[$plugin['name']] = $plugin; - } - } - } - $cached_plugins['plugins'] = $result_plugins; - $cached_plugins['model_plugins'] = $model_plugins; - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/plugins.php', - array_to_cache("setting['active_plugins']", $cached_plugins)); - } - - // ------------------------------------------------------------------------ - - /** - * 更新字段类型缓存 - * - * @access public - * @return void - */ - public function update_fieldtypes_cache() - { - $cached_fieldtypes = array(); - $cached_fieldtypes['fieldtypes'] = array(); - $cached_fieldtypes['extra_fieldtypes'] = array(); - $cached_fieldtypes['validation'] = array(); - $results = $this->db->get($this->db->dbprefix('fieldtypes'))->result_array(); - foreach ($results as $v) - { - $cached_fieldtypes['fieldtypes'][$v['k']] = $v['v']; - } - $results = $this->db->get($this->db->dbprefix('validations'))->result_array(); - foreach ($results as $v) - { - $cached_fieldtypes['validation'][$v['k']] = $v['v']; - } - $extra_path = DILICMS_EXTENSION_PATH . 'fields/'; - $this->load->helper('file'); - $extra_files = get_filenames($extra_path); - foreach ($extra_files as $v) - { - if (preg_match("/^field_(.*?)\.php$/", $v)) - { - include $extra_path . $v; - if (class_exists($extra_class = str_replace('.php', '', $v))) - { - $tmp = new $extra_class(); - $cached_fieldtypes['extra_fieldtypes'][$tmp->k] = $tmp->v; - } - } - } - $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/fieldtypes.php', - array_to_cache("setting",$cached_fieldtypes)); - } - - // ------------------------------------------------------------------------ - -} - -/* End of file cache_mdl.php */ +platform->get_type() == 'default') + { + if ( ! file_exists(DILICMS_SHARE_PATH . 'settings/' . $folder)) + { + mkdir(DILICMS_SHARE_PATH . 'settings/' . $folder); + } + } + + } + + // ------------------------------------------------------------------------ + + /** + * 更新内容模型缓存 + * + * @access public + * @param string + * @return void + */ + public function update_model_cache($target = '') + { + $data = array(); + if ($target) + { + $target = is_array($target) ? $target : array($target); + $this->db->where_in('name', $target); + } + $models = $this->db->get($this->db->dbprefix('models'))->result_array(); + foreach ($models as $model) + { + $model['fields'] = array(); + $model['fields_org'] = $this->db->where('model', $model['id']) + ->order_by('`order`', 'ASC') + ->get($this->db->dbprefix('model_fields')) + ->result_array(); + $model['listable'] = array(); + $model['searchable'] = array(); + foreach ($model['fields_org'] as $key=> & $v) + { + if ($v['listable'] == 1) + { + array_push($model['listable'], $v['id']); + } + if ($v['searchable'] == 1) + { + array_push($model['searchable'], $v['id']); + } + if (in_array($v['type'], array('select', 'checkbox', 'radio'))) + { + if ($v['values'] == '') + { + $v['values'] = array(); + } + else + { + $value = array(); + foreach (explode('|', $v['values']) as $vt) + { + if (strpos($vt, '=') > -1) + { + $vt = explode('=', $vt); + $value[$vt[0]] = $vt[1]; + } + else + { + $value[$vt] = $vt; + } + } + $v['values'] = $value; + } + } + $model['fields'][$v['id']] = $v; + } + unset($model['fields_org']); + $this->_create_folder('model'); + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/model/'.$model['name'].'.php', + array_to_cache("setting['models']['" . $model['name'] . "']", $model) + ); + } + } + + // ------------------------------------------------------------------------ + + /** + * 更新分类模型缓存 + * + * @access public + * @param string + * @return void + */ + public function update_category_cache($target = '') + { + $this->load->model('category_mdl'); + $data = array(); + if ($target) + { + $target = is_array($target) ? $target : array($target); + $this->db->where_in('name', $target); + } + $models = $this->db->get($this->db->dbprefix('cate_models'))->result_array(); + foreach ($models as $model) + { + $model['fields'] = array(); + $model['fields_org'] = $this->db->where('model', $model['id']) + ->order_by('`order`', 'ASC') + ->get($this->db->dbprefix('cate_fields')) + ->result_array(); + $model['listable'] = array(); + $model['searchable'] = array(); + foreach ($model['fields_org'] as $key=> & $v) + { + if ($v['listable'] == 1) + { + array_push($model['listable'], $v['id']); + } + if ($v['searchable'] == 1) + { + array_push($model['searchable'], $v['id']); + } + if (in_array($v['type'], array('select', 'checkbox', 'radio'))) + { + if ($v['values'] == '') + { + $v['values'] = array(); + } + else + { + $value = array(); + foreach (explode('|', $v['values']) as $vt) + { + if (strpos($vt,'=') > -1) + { + $vt = explode('=', $vt); + $value[$vt[0]] = $vt[1]; + } + else + { + $value[$vt] = $vt; + } + } + $v['values'] = $value; + } + } + $model['fields'][$v['id']] = $v; + } + unset($model['fields_org']); + $this->_create_folder('category'); + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/category/cate_' . $model['name'] . '.php', + array_to_cache("setting['cate_models']['" . $model['name'] . "']", $model)); + $category = array(); + $categories = $this->category_mdl->get_category($model['name']); + foreach($categories as $c) + { + $category[$c['classid']] = $c; + } + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/category/data_' . $model['name'] . '.php', + array_to_cache("setting['category']['" . $model['name'] . "']", $category)); + unset($categories,$category); + } + } + + // ------------------------------------------------------------------------ + + /** + * 更新菜单缓存 + * + * @access public + * @return void + */ + public function update_menu_cache() + { + $table_menu = $this->db->dbprefix('menus'); + $level_1_menus = $this->db->select('menu_id, class_name, method_name, menu_name') + ->where('menu_level', 0) + ->where('menu_parent', 0) + ->get($table_menu) + ->result_array(); + foreach ($level_1_menus as & $i) + { + $level_2_menus = $this->db->select('menu_id, class_name, method_name, menu_name') + ->where('menu_level', 1) + ->where('menu_parent', $i['menu_id']) + ->get($table_menu) + ->result_array(); + foreach ($level_2_menus as & $j) + { + if ($j['class_name'] == 'content') + { + $level_3_menus = $this->db + ->select(" 'content' AS class_name, 'view' AS 'method_name', name AS extra, description AS menu_name", FALSE) + ->get($this->db->dbprefix('models')) + ->result_array(); + } + else if ($j['class_name'] == 'category_content') + { + $level_3_menus = $this->db + ->select(" 'category_content' AS class_name, 'view' AS 'method_name', name AS extra, description AS menu_name", FALSE) + ->get($this->db->dbprefix('cate_models')) + ->result_array(); + } + else + { + $level_3_menus = $this->db->select('menu_id, class_name, method_name, menu_name') + ->where('menu_level', 2) + ->where('menu_parent', $j['menu_id']) + ->get($table_menu) + ->result_array(); + } + $j['sub_menus'] = $level_3_menus; + } + $i['sub_menus'] = $level_2_menus; + } + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/menus.php', + array_to_cache("setting['menus']", $level_1_menus)); + } + + // ------------------------------------------------------------------------ + + /** + * 更新用户组缓存 + * + * @access public + * @param string + * @return void + */ + public function update_role_cache($target = '') + { + if ($target) + { + $target = is_array($target) ? $target : array($target); + $this->db->where_in('id', $target); + } + $roles = $this->db->get($this->db->dbprefix('roles'))->result_array(); + foreach ($roles as & $role) + { + $role['rights'] = explode(',', $role['rights']); + $rights = $this->db->select('right_class, right_method, right_detail') + ->where_in('right_id', $role['rights']) + ->get($this->db->dbprefix('rights')) + ->result(); + $role['rights'] = array(); + foreach ($rights as $right) + { + $role['rights'][] = $right->right_class . '@' . $right->right_method . ($right->right_detail ? '@' . $right->right_detail : ''); + } + $role['models'] = explode(',', $role['models']); + $role['category_models'] = explode(',', $role['category_models']); + $role['plugins'] = explode(',', $role['plugins']); + $this->_create_folder('acl'); + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/acl/role_' . $role['id'] . '.php', + array_to_cache("setting['current_role']",$role)); + } + } + + // ------------------------------------------------------------------------ + + /** + * 更新站点信息缓存 + * + * @access public + * @return void + */ + public function update_site_cache() + { + $data = $this->db->get($this->db->dbprefix('site_settings'))->row_array(); + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/site.php', + array_to_cache("setting", $data)); + } + + // ------------------------------------------------------------------------ + + /** + * 更新后台设置缓存 + * + * @access public + * @return void + */ + public function update_backend_cache() + { + $data = $this->db->get($this->db->dbprefix('backend_settings'))->row_array(); + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/backend.php', + array_to_cache("setting", $data)); + } + + // ------------------------------------------------------------------------ + + /** + * 更新插件信息缓存 + * + * @access public + * @return void + */ + public function update_plugin_cache() + { + $cached_plugins = array(); + $plugins = $this->db->select('name, access') + ->where('active', '1') + ->get($this->db->dbprefix('plugins')) + ->result_array(); + if ($plugins) + { + foreach ($plugins as $key => $plugin) + { + if (! isset($cached_plugins[$plugin['name']])) { + $cached_plugins[$plugin['name']] = array( + 'classmap' => array(), + 'menus' => array(), + 'access' => $plugin['access'] + ); + } + + $this_plugin_path = DILICMS_EXTENSION_PATH.'plugins/'.$plugin['name'].'/'; + + $this_hook_path = 'plugins/'.$plugin['name'].'/hooks/'; + + if (file_exists($this_plugin_path.'hooks')) { + foreach (glob($this_plugin_path.'hooks/'.$plugin['name']."_hook_*.php") as $filename) { + $filename = basename($filename); + $model = str_replace(array('.php', $plugin['name']."_hook_"), array('', ''), $filename); + $cached_plugins[$plugin['name']]['classmap'][$model] = $this_hook_path.$filename; + } + } + + if (file_exists($this_plugin_path.'menus.php')) { + $this_plugin_menus = include ($this_plugin_path.'menus.php'); + $cached_plugins[$plugin['name']]['menus'] = $this_plugin_menus; + } + + + } + } + + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/plugins.php', + array_to_cache("setting['plugins']", $cached_plugins)); + + + } + + // ------------------------------------------------------------------------ + + /** + * 更新字段类型缓存 + * + * @access public + * @return void + */ + public function update_fieldtypes_cache() + { + $cached_fieldtypes = array(); + $cached_fieldtypes['fieldtypes'] = array(); + $cached_fieldtypes['extra_fieldtypes'] = array(); + $cached_fieldtypes['validation'] = array(); + $results = $this->db->get($this->db->dbprefix('fieldtypes'))->result_array(); + foreach ($results as $v) + { + $cached_fieldtypes['fieldtypes'][$v['k']] = $v['v']; + } + $results = $this->db->get($this->db->dbprefix('validations'))->result_array(); + foreach ($results as $v) + { + $cached_fieldtypes['validation'][$v['k']] = $v['v']; + } + $extra_path = DILICMS_EXTENSION_PATH . 'fields/'; + $this->load->helper('file'); + $extra_files = get_filenames($extra_path); + foreach ($extra_files as $v) + { + if (preg_match("/^field_(.*?)\.php$/", $v)) + { + include $extra_path . $v; + if (class_exists($extra_class = str_replace('.php', '', $v))) + { + $tmp = new $extra_class(); + $cached_fieldtypes['extra_fieldtypes'][$tmp->k] = $tmp->v; + } + } + } + $this->platform->cache_write(DILICMS_SHARE_PATH . 'settings/fieldtypes.php', + array_to_cache("setting",$cached_fieldtypes)); + } + + // ------------------------------------------------------------------------ + +} + +/* End of file cache_mdl.php */ /* Location: ./shared/models/cache_mdl.php */ \ No newline at end of file