|
|
安装
- /**
- * 模块安装
- */
- public function install() {
- $this->module = $_POST['module'] ? $_POST['module'] : $_GET['module'];
- $module_api = pc_base::load_app_class('module_api');
- if (!$module_api->check($this->module)) showmessage($module_api->error_msg, 'blank');
- if ($_POST['dosubmit']) {
- if ($module_api->install()) showmessage(L('success_module_install').L('update_cache'), '?m=admin&c=module&a=cache&pc_hash='.$_SESSION['pc_hash']);
- else showmesage($module_api->error_msg, HTTP_REFERER);
- } else {
- include PC_PATH.'modules'.DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'config.inc.php';
- include $this->admin_tpl('module_config');
- }
- }
复制代码 module_api.class.php 的install
- /**
- * 模块安装
- * @param string $module 模块名
- */
- public function install($module = '') {
- define('INSTALL', true);
- if ($module) $this->module = $module;
- $this->installdir = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR;
-
- $this->check();
- $models = @require($this->installdir.'model.php');
- if (!is_array($models) || empty($models)) {
- $models = array('module');
- }
- if (!in_array('module', $models)) {
- array_unshift($models, 'module');
- }
- if (is_array($models) && !empty($models)) {
- foreach ($models as $m) {
- $this->m_db = pc_base::load_model($m.'_model');
- $sql = file_get_contents($this->installdir.$m.'.sql');
- $this->sql_execute($sql);
- }
- }
- if (file_exists($this->installdir.'extention.inc.php')) {
- $menu_db = pc_base::load_model('menu_model');
- @include ($this->installdir.'extention.inc.php');
- if(!defined('INSTALL_MODULE')) {
- $file = PC_PATH.'languages'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'lang').DIRECTORY_SEPARATOR.'system_menu.lang.php';
- if(file_exists($file)) {
- $content = file_get_contents($file);
- $content = substr($content,0,-2);
- $data = '';
- foreach ($language as $key => $l) {
- if (L($key, '', 'system_menu')==$key) {
- $data .= "\$LANG['".$key."'] = '".$l."';\r\n";
- }
- }
- $data = $content.$data."?>";
- file_put_contents($file,$data);
- } else {
- foreach ($language as $key =>$l) {
- if (L($key, '', 'system_menu')==$key) {
- $data .= "\$LANG['".$key."'] = '".$l."';\r\n";
- }
- }
- $data = "<?"."php\r\n\$data?>";
- file_put_contents($file,$data);
- }
- }
- }
- if(!defined('INSTALL_MODULE')) {
- if (file_exists($this->installdir.'languages'.DIRECTORY_SEPARATOR)) {
- dir_copy($this->installdir.'languages'.DIRECTORY_SEPARATOR, PC_PATH.'languages'.DIRECTORY_SEPARATOR);
- }
- if(file_exists($this->installdir.'templates'.DIRECTORY_SEPARATOR)) {
- dir_copy($this->installdir.'templates'.DIRECTORY_SEPARATOR, PC_PATH.'templates'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'tpl_name').DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR);
- if (file_exists($this->installdir.'templates'.DIRECTORY_SEPARATOR.'name.inc.php')) {
- $keyid = 'templates|'.pc_base::load_config('system', 'tpl_name').'|'.$this->module;
- $file_explan[$keyid] = include $this->installdir.'templates'.DIRECTORY_SEPARATOR.'name.inc.php';
- $templatepath = PC_PATH.'templates'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'tpl_name').DIRECTORY_SEPARATOR;
- if (file_exists($templatepath.'config.php')) {
- $style_info = include $templatepath.'config.php';
- $style_info['file_explan'] = array_merge($style_info['file_explan'], $file_explan);
- @file_put_contents($templatepath.'config.php', '<?php return '.var_export($style_info, true).';?>');
- }
- unlink(PC_PATH.'templates'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'tpl_name').DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'name.inc.php');
- }
- }
- }
- return true;
- }
复制代码
检查安装目录
- /**
- * 检查安装目录
- * @param string $module 模块名
- */
- public function check($module = '') {
- define('INSTALL', true);
- if ($module) $this->module = $module;
- if(!$this->module) {
- $this->error_msg = L('no_module');
- return false;
- }
- if(!defined('INSTALL_MODULE')) {
- if (dir_create(PC_PATH.'languages'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'lang').DIRECTORY_SEPARATOR.'test_create_dir')) {
- sleep(1);
- dir_delete(PC_PATH.'languages'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'lang').DIRECTORY_SEPARATOR.'test_create_dir');
-
- } else {
- $this->error_msg = L('lang_dir_no_write');
- return false;
- }
- }
- $r = $this->db->get_one(array('module'=>$this->module));
- if ($r) {
- $this->error_msg = L('this_module_installed');
- return false;
- }
- if (!$this->installdir) {
- $this->installdir = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR;
- }
- if (!is_dir($this->installdir)) {
- $this->error_msg = L('install_dir_no_exist');
- return false;
- }
- if (!file_exists($this->installdir.'module.sql')) {
- $this->error_msg = L('module_sql_no_exist');
- return false;
- }
- $models = @require($this->installdir.'model.php');
- if (is_array($models) && !empty($models)) {
- foreach ($models as $m) {
- if (!file_exists(PC_PATH.'model'.DIRECTORY_SEPARATOR.$m.'_model.class.php')) {
- $this->error_msg = $m.L('model_clas_no_exist');
- return false;
- }
- if (!file_exists($this->installdir.$m.'.sql')) {
- $this->error_msg = $m.L('sql_no_exist');
- return false;
- }
- }
- }
- return true;
- }
复制代码
|
|