ѡ̳

 找回密码
 ע
搜索
查看: 843|回复: 0
打印 上一主题 下一主题

phpcms的模块安装 卸载 --模块安装

[复制链接]

789

主题

1158

帖子

4197

积分

Ա

Rank: 9Rank: 9Rank: 9

积分
4197
跳转到指定楼层
¥
发表于 2017-11-11 01:40:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
安装
  1. /**
  2.          * 模块安装
  3.          */
  4.         public function install() {
  5.                 $this->module = $_POST['module'] ? $_POST['module'] : $_GET['module'];
  6.                 $module_api = pc_base::load_app_class('module_api');
  7.                 if (!$module_api->check($this->module)) showmessage($module_api->error_msg, 'blank');
  8.                 if ($_POST['dosubmit']) {
  9.                         if ($module_api->install()) showmessage(L('success_module_install').L('update_cache'), '?m=admin&c=module&a=cache&pc_hash='.$_SESSION['pc_hash']);
  10.                         else showmesage($module_api->error_msg, HTTP_REFERER);
  11.                 } else {
  12.                         include PC_PATH.'modules'.DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'config.inc.php';
  13.                         include $this->admin_tpl('module_config');
  14.                 }
  15.         }
复制代码
module_api.class.php 的install
  1. /**
  2.          * 模块安装
  3.          * @param string $module 模块名
  4.          */
  5.         public function install($module = '') {
  6.                 define('INSTALL', true);
  7.                 if ($module) $this->module = $module;
  8.                 $this->installdir = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR;
  9.                
  10.                 $this->check();
  11.                 $models = @require($this->installdir.'model.php');
  12.                 if (!is_array($models) || empty($models)) {
  13.                         $models = array('module');
  14.                 }
  15.                 if (!in_array('module', $models)) {
  16.                         array_unshift($models, 'module');
  17.                 }
  18.                 if (is_array($models) && !empty($models)) {
  19.                         foreach ($models as $m) {
  20.                                 $this->m_db = pc_base::load_model($m.'_model');
  21.                                 $sql = file_get_contents($this->installdir.$m.'.sql');
  22.                                 $this->sql_execute($sql);
  23.                         }
  24.                 }
  25.                 if (file_exists($this->installdir.'extention.inc.php')) {
  26.                         $menu_db = pc_base::load_model('menu_model');
  27.                         @include ($this->installdir.'extention.inc.php');
  28.                         if(!defined('INSTALL_MODULE')) {
  29.                                 $file = PC_PATH.'languages'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'lang').DIRECTORY_SEPARATOR.'system_menu.lang.php';
  30.                                 if(file_exists($file)) {
  31.                                         $content = file_get_contents($file);
  32.                                         $content = substr($content,0,-2);
  33.                                         $data = '';
  34.                                         foreach ($language as $key => $l) {
  35.                                                 if (L($key, '', 'system_menu')==$key) {
  36.                                                         $data .= "\$LANG['".$key."'] = '".$l."';\r\n";
  37.                                                 }
  38.                                         }
  39.                                         $data = $content.$data."?>";
  40.                                         file_put_contents($file,$data);
  41.                                 } else {
  42.                                         foreach ($language as $key =>$l) {
  43.                                                 if (L($key, '', 'system_menu')==$key) {
  44.                                                         $data .= "\$LANG['".$key."'] = '".$l."';\r\n";
  45.                                                 }
  46.                                         }
  47.                                         $data = "<?"."php\r\n\$data?>";
  48.                                         file_put_contents($file,$data);
  49.                                 }
  50.                         }
  51.                 }

  52.                 if(!defined('INSTALL_MODULE')) {
  53.                         if (file_exists($this->installdir.'languages'.DIRECTORY_SEPARATOR)) {
  54.                                 dir_copy($this->installdir.'languages'.DIRECTORY_SEPARATOR, PC_PATH.'languages'.DIRECTORY_SEPARATOR);
  55.                         }
  56.                         if(file_exists($this->installdir.'templates'.DIRECTORY_SEPARATOR)) {
  57.                                 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);
  58.                                 if (file_exists($this->installdir.'templates'.DIRECTORY_SEPARATOR.'name.inc.php')) {
  59.                                         $keyid = 'templates|'.pc_base::load_config('system', 'tpl_name').'|'.$this->module;
  60.                                         $file_explan[$keyid] = include $this->installdir.'templates'.DIRECTORY_SEPARATOR.'name.inc.php';
  61.                                         $templatepath = PC_PATH.'templates'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'tpl_name').DIRECTORY_SEPARATOR;
  62.                                         if (file_exists($templatepath.'config.php')) {
  63.                                                 $style_info = include $templatepath.'config.php';
  64.                                                 $style_info['file_explan'] = array_merge($style_info['file_explan'], $file_explan);
  65.                                                 @file_put_contents($templatepath.'config.php', '<?php return '.var_export($style_info, true).';?>');
  66.                                         }
  67.                                         unlink(PC_PATH.'templates'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'tpl_name').DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'name.inc.php');
  68.                                 }
  69.                         }
  70.                 }
  71.                 return true;
  72.         }
复制代码


检查安装目录
  1. /**
  2.          * 检查安装目录
  3.          * @param string $module 模块名
  4.          */
  5.         public function check($module = '') {
  6.         define('INSTALL', true);
  7.                 if ($module) $this->module = $module;
  8.                 if(!$this->module) {
  9.                         $this->error_msg = L('no_module');
  10.                         return false;
  11.                 }
  12.                 if(!defined('INSTALL_MODULE')) {
  13.                         if (dir_create(PC_PATH.'languages'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'lang').DIRECTORY_SEPARATOR.'test_create_dir')) {
  14.                                 sleep(1);
  15.                                 dir_delete(PC_PATH.'languages'.DIRECTORY_SEPARATOR.pc_base::load_config('system', 'lang').DIRECTORY_SEPARATOR.'test_create_dir');
  16.                                
  17.                         } else {
  18.                                 $this->error_msg = L('lang_dir_no_write');
  19.                                 return false;
  20.                         }
  21.                 }
  22.                 $r = $this->db->get_one(array('module'=>$this->module));
  23.                 if ($r) {
  24.                         $this->error_msg = L('this_module_installed');
  25.                         return false;
  26.                 }
  27.                 if (!$this->installdir) {
  28.                         $this->installdir = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$this->module.DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR;
  29.                 }
  30.                 if (!is_dir($this->installdir)) {
  31.                         $this->error_msg = L('install_dir_no_exist');
  32.                         return false;
  33.                 }
  34.                 if (!file_exists($this->installdir.'module.sql')) {
  35.                         $this->error_msg = L('module_sql_no_exist');
  36.                         return false;
  37.                 }
  38.                 $models = @require($this->installdir.'model.php');
  39.                 if (is_array($models) && !empty($models)) {
  40.                         foreach ($models as $m) {
  41.                                 if (!file_exists(PC_PATH.'model'.DIRECTORY_SEPARATOR.$m.'_model.class.php')) {
  42.                                         $this->error_msg = $m.L('model_clas_no_exist');
  43.                                         return false;
  44.                                 }
  45.                                 if (!file_exists($this->installdir.$m.'.sql')) {
  46.                                         $this->error_msg = $m.L('sql_no_exist');
  47.                                         return false;
  48.                                 }
  49.                         }
  50.                 }
  51.                 return true;
  52.         }
复制代码





回复

使用道具 举报

您需要登录后才可以回帖 登录 | ע

本版积分规则

QQ|Archiver|ֻ|С|ѡ̳

GMT+8, 2026-5-2 04:39 , Processed in 0.077992 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表
0.0927s