微擎模块机制分析2

 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq43599939/article/details/78275713

利用微擎开发些微信公众号还是非常方便的;模块机制分析主要从其安装、卸载、使用角度,

 

一、安装

安装界面,主要是module_get_all_unistalled获取未安装模块

 

  1.  
    if ($do == 'not_installed') {
  2.  
    if (empty($_W['isfounder'])) {
  3.  
    itoast('非法访问!', referer(), 'info');
  4.  
    }
  5.  
    $_W['page']['title'] = '安装模块 - 模块 - 扩展';
  6.  
     
  7.  
    $status = $_GPC['status'] == 'recycle'? 'recycle' : 'uninstalled';
  8.  
    $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  9.  
    $title = $_GPC['title'];
  10.  
    $letter = $_GPC['letter'];
  11.  
    $pageindex = max($_GPC['page'], 1);
  12.  
    $pagesize = 20;
  13.  
     
  14.  
    $uninstallModules = module_get_all_unistalled($status, false);
  15.  
    $total_uninstalled = $uninstallModules['module_count'];
  16.  
    $uninstallModules = (array)$uninstallModules['modules'];
  17.  
    if (!empty($uninstallModules)) {
  18.  
    foreach($uninstallModules as $name => &$module) {
  19.  
    if (!empty($letter) && strlen($letter) == 1) {
  20.  
    $first_char = get_first_pinyin($module['title']);
  21.  
    if ($letter != $first_char) {
  22.  
    unset($uninstallModules[$name]);
  23.  
    continue;
  24.  
    }
  25.  
    }
  26.  
    if (!empty($title)) {
  27.  
    if (!strexists($module['title'], $title)) {
  28.  
    unset($uninstallModules[$name]);
  29.  
    continue;
  30.  
    }
  31.  
    }
  32.  
     
  33.  
    if (file_exists(IA_ROOT.'/addons/'.$module['name'].'/icon-custom.jpg')) {
  34.  
    $module['logo'] = tomedia(IA_ROOT.'/addons/'.$module['name'].'/icon-custom.jpg');
  35.  
    } elseif (file_exists(IA_ROOT.'/addons/'.$module['name'].'/icon.jpg')) {
  36.  
    $module['logo'] = tomedia(IA_ROOT.'/addons/'.$module['name'].'/icon.jpg');
  37.  
    } else {
  38.  
    $module['logo'] = tomedia($module['thumb']);
  39.  
    }
  40.  
    if (!empty($module['main_module'])) {
  41.  
    $main_module_installed = module_fetch($module['main_module']);
  42.  
    if ($main_module_installed) {
  43.  
    $module['main_module_logo'] = $main_module_installed['logo'];
  44.  
    } else {
  45.  
    if ($module['from'] == 'cloud') {
  46.  
    $module['main_module_logo'] = tomedia($uninstallModules[$module['main_module']]['thumb']);
  47.  
    } else {
  48.  
    if (file_exists(IA_ROOT.'/addons/'.$module['main_module'].'/icon-custom.jpg')) {
  49.  
    $module['main_module_logo'] = tomedia(IA_ROOT.'/addons/'.$module['main_module'].'/icon-custom.jpg');
  50.  
    } elseif (file_exists(IA_ROOT.'/addons/'.$module['main_module'].'/icon.jpg')) {
  51.  
    $module['main_module_logo'] = tomedia(IA_ROOT.'/addons/'.$module['main_module'].'/icon.jpg');
  52.  
    }
  53.  
    }
  54.  
    }
  55.  
    }
  56.  
    }
  57.  
    }
  58.  
    $total = count($uninstallModules);
  59.  
    $uninstallModules = array_slice($uninstallModules, ($pageindex - 1)*$pagesize, $pagesize);
  60.  
    $pager = pagination($total, $pageindex, $pagesize);
  61.  
    }

module_get_all_unistalled 函数源码,可以看到先判断是否有缓存(微擎的缓存实现机制还是很清晰易懂的,数据库、文件、memcache、Redis),没有再取,关键是cache_build_uninstalled_module;可以看到有云模块的请求,当然这部分你可以干掉,我还是坚持用正版哈

 

 

  1.  
    function module_get_all_unistalled($status, $cache = true) {
  2.  
    global $_GPC;
  3.  
    load()->func('communication');
  4.  
    load()->model('cloud');
  5.  
    load()->classs('cloudapi');
  6.  
    $status = $status == 'recycle' ? 'recycle' : 'uninstalled';
  7.  
     
  8.  
     
  9.  
     
  10.  
    $uninstallModules = cache_load(cache_system_key('module:all_uninstall'));
  11.  
     
  12.  
    if (!$cache && $status == 'uninstalled') {
  13.  
    $cloud_api = new CloudApi();
  14.  
    $get_cloud_m_count = $cloud_api->get('site', 'stat', array('module_quantity' => 1), 'json');
  15.  
    $cloud_m_count = $get_cloud_m_count['module_quantity'];
  16.  
    } else {
  17.  
     
  18.  
    if(is_array($uninstallModules)){
  19.  
    $cloud_m_count = $uninstallModules['cloud_m_count'];
  20.  
    }
  21.  
    }
  22.  
    if (empty($uninstallModules['modules']) || intval($uninstallModules['cloud_m_count']) !== intval($cloud_m_count) || is_error($get_cloud_m_count)) {
  23.  
     
  24.  
    $uninstallModules = cache_build_uninstalled_module();
  25.  
    }
  26.  
    if (ACCOUNT_TYPE == ACCOUNT_TYPE_APP_NORMAL) {
  27.  
    $uninstallModules['modules'] = (array)$uninstallModules['modules'][$status]['wxapp'];
  28.  
    $uninstallModules['module_count'] = $uninstallModules['wxapp_count'];
  29.  
    return $uninstallModules;
  30.  
    } elseif (ACCOUNT_TYPE == ACCOUNT_TYPE_OFFCIAL_NORMAL) {
  31.  
    $uninstallModules['modules'] = (array)$uninstallModules['modules'][$status]['app'];
  32.  
    $uninstallModules['module_count'] = $uninstallModules['app_count'];
  33.  
    return $uninstallModules;
  34.  
    } else {
  35.  
    return $uninstallModules;
  36.  
    }
  37.  
    }

cache_build_uninstalled_module源码,现在知道为什么模块要放在addons下了,最后还把模块信息写入缓存,以便下次直接使用

 

 

  1.  
    function cache_build_uninstalled_module() {
  2.  
    load()->model('cloud');
  3.  
    load()->classs('cloudapi');
  4.  
    load()->model('extension');
  5.  
    load()->func('file');
  6.  
    $cloud_api = new CloudApi();
  7.  
     
  8.  
    $cloud_m_count = $cloud_api->get('site', 'stat', array('module_quantity' => 1), 'json');
  9.  
     
  10.  
     
  11.  
     
  12.  
    $installed_module = pdo_getall('modules', array(), array(), 'name');
  13.  
     
  14.  
    $uninstallModules = array('recycle' => array(), 'uninstalled' => array());
  15.  
    $recycle_modules = pdo_getall('modules_recycle', array(), array(), 'modulename');
  16.  
    $recycle_modules = array_keys($recycle_modules);
  17.  
    $cloud_module = cloud_m_query();
  18.  
     
  19.  
    if (!empty($cloud_module) && !is_error($cloud_module)) {
  20.  
    foreach ($cloud_module as $module) {
  21.  
    $upgrade_support_module = false;
  22.  
    $wxapp_support = !empty($module['site_branch']['wxapp_support']) && is_array($module['site_branch']['bought']) && in_array('wxapp', $module['site_branch']['bought']) ? $module['site_branch']['wxapp_support'] : 1;
  23.  
    $app_support = !empty($module['site_branch']['app_support']) && is_array($module['site_branch']['bought']) && in_array('app', $module['site_branch']['bought']) ? $module['site_branch']['app_support'] : 1;
  24.  
    if ($wxapp_support == 1 && $app_support == 1) {
  25.  
    $app_support = 2;
  26.  
    }
  27.  
    if (!empty($installed_module[$module['name']]) && ($installed_module[$module['name']]['app_support'] != $app_support || $installed_module[$module['name']]['wxapp_support'] != $wxapp_support)) {
  28.  
    $upgrade_support_module = true;
  29.  
    }
  30.  
    if (!in_array($module['name'], array_keys($installed_module)) || $upgrade_support_module) {
  31.  
    $status = in_array($module['name'], $recycle_modules) ? 'recycle' : 'uninstalled';
  32.  
    if (!empty($module['id'])) {
  33.  
    $cloud_module_info = array (
  34.  
    'from' => 'cloud',
  35.  
    'name' => $module['name'],
  36.  
    'version' => $module['version'],
  37.  
    'title' => $module['title'],
  38.  
    'thumb' => $module['thumb'],
  39.  
    'wxapp_support' => $wxapp_support,
  40.  
    'app_support' => $app_support,
  41.  
    'main_module' => empty($module['main_module']) ? '' : $module['main_module'],
  42.  
    'upgrade_support' => $upgrade_support_module
  43.  
    );
  44.  
    if ($upgrade_support_module) {
  45.  
    if ($wxapp_support == 2 && $installed_module[$module['name']]['wxapp_support'] != 2) {
  46.  
    $uninstallModules[$status]['wxapp'][$module['name']] = $cloud_module_info;
  47.  
    }
  48.  
    if ($app_support == 2 && $installed_module[$module['name']]['app_support'] != 2) {
  49.  
    $uninstallModules[$status]['app'][$module['name']] = $cloud_module_info;
  50.  
    }
  51.  
    } else {
  52.  
    if ($wxapp_support == 2) {
  53.  
    $uninstallModules[$status]['wxapp'][$module['name']] = $cloud_module_info;
  54.  
    }
  55.  
    if ($app_support == 2) {
  56.  
    $uninstallModules[$status]['app'][$module['name']] = $cloud_module_info;
  57.  
    }
  58.  
    }
  59.  
    }
  60.  
    }
  61.  
    }
  62.  
    }
  63.  
    $path = IA_ROOT . '/addons/';
  64.  
    mkdirs($path);
  65.  
     
  66.  
    $module_file = glob($path . '*');
  67.  
    if (is_array($module_file) && !empty($module_file)) {
  68.  
    foreach ($module_file as $modulepath) {
  69.  
    $upgrade_support_module = false;
  70.  
    $modulepath = str_replace($path, '', $modulepath);
  71.  
    $manifest = ext_module_manifest($modulepath);
  72.  
    if (!is_array($manifest) || empty($manifest) || empty($manifest['application']['identifie'])) {
  73.  
    continue;
  74.  
    }
  75.  
    $main_module = empty($manifest['platform']['main_module']) ? '' : $manifest['platform']['main_module'];
  76.  
    $manifest = ext_module_convert($manifest);
  77.  
     
  78.  
    if (!empty($installed_module[$modulepath]) && ($manifest['app_support'] != $installed_module[$modulepath]['app_support'] || $manifest['wxapp_support'] != $installed_module[$modulepath]['wxapp_support'])) {
  79.  
    $upgrade_support_module = true;
  80.  
    }
  81.  
    if (!in_array($manifest['name'], array_keys($installed_module)) || $upgrade_support_module) {
  82.  
    $module[$manifest['name']] = $manifest;
  83.  
    $module_info = array(
  84.  
    'from' => 'local',
  85.  
    'name' => $manifest['name'],
  86.  
    'version' => $manifest['version'],
  87.  
    'title' => $manifest['title'],
  88.  
    'app_support' => $manifest['app_support'],
  89.  
    'wxapp_support' => $manifest['wxapp_support'],
  90.  
    'main_module' => $main_module,
  91.  
    'upgrade_support' => $upgrade_support_module
  92.  
    );
  93.  
    $module_type = in_array($manifest['name'], $recycle_modules) ? 'recycle' : 'uninstalled';
  94.  
    if ($upgrade_support_module) {
  95.  
    if ($module_info['app_support'] == 2 && $installed_module[$module_info['name']]['app_support'] != 2) {
  96.  
    $uninstallModules['uninstalled']['app'][$manifest['name']] = $module_info;
  97.  
    }
  98.  
    if ($module_info['wxapp_support'] == 2 && $installed_module[$module_info['name']]['wxapp_support'] != 2) {
  99.  
    $uninstallModules['uninstalled']['wxapp'][$manifest['name']] = $module_info;
  100.  
    }
  101.  
    } else {
  102.  
    if ($module_info['app_support'] == 2) {
  103.  
    $uninstallModules[$module_type]['app'][$manifest['name']] = $module_info;
  104.  
    }
  105.  
    if ($module_info['wxapp_support'] == 2) {
  106.  
    $uninstallModules[$module_type]['wxapp'][$manifest['name']] = $module_info;
  107.  
    }
  108.  
    }
  109.  
    }
  110.  
    }
  111.  
    }
  112.  
    $cache = array(
  113.  
    'cloud_m_count' => $cloud_m_count['module_quantity'],
  114.  
    'modules' => $uninstallModules,
  115.  
    'app_count' => count($uninstallModules['uninstalled']['app']),
  116.  
    'wxapp_count' => count($uninstallModules['uninstalled']['wxapp'])
  117.  
    );
  118.  
     
  119.  
     
  120.  
    cache_write('we7:module:all_uninstall', $cache, CACHE_EXPIRE_LONG);
  121.  
    return $cache;
  122.  
    }

还有个地方值得学习,模块的信息定义在manifest.xml中,有点java的感觉,具体信息读取都在extension.mod.php中,代码如下

 

 

 

  1.  
    function ext_module_manifest_parse($xml) {
  2.  
    if (!strexists($xml, '<manifest')) {
  3.  
    $xml = base64_decode($xml);
  4.  
    }
  5.  
    if (empty($xml)) {
  6.  
    return array();
  7.  
    }
  8.  
    $dom = new DOMDocument();
  9.  
    $dom->loadXML($xml);
  10.  
    $root = $dom->getElementsByTagName('manifest')->item(0);
  11.  
    if (empty($root)) {
  12.  
    return array();
  13.  
    }
  14.  
    $vcode = explode(',', $root->getAttribute('versionCode'));
  15.  
    $manifest['versions'] = array();
  16.  
    if (is_array($vcode)) {
  17.  
    foreach ($vcode as $v) {
  18.  
    $v = trim($v);
  19.  
    if (!empty($v)) {
  20.  
    $manifest['versions'][] = $v;
  21.  
    }
  22.  
    }
  23.  
    $manifest['versions'][] = '0.52';
  24.  
    $manifest['versions'][] = '0.6';
  25.  
    $manifest['versions'] = array_unique($manifest['versions']);
  26.  
    }
  27.  
    $manifest['install'] = $root->getElementsByTagName('install')->item(0)->textContent;
  28.  
    $manifest['uninstall'] = $root->getElementsByTagName('uninstall')->item(0)->textContent;
  29.  
    $manifest['upgrade'] = $root->getElementsByTagName('upgrade')->item(0)->textContent;
  30.  
    $application = $root->getElementsByTagName('application')->item(0);
  31.  
    if (empty($application)) {
  32.  
    return array();
  33.  
    }
  34.  
    $manifest['application'] = array(
  35.  
    'name' => trim($application->getElementsByTagName('name')->item(0)->textContent),
  36.  
    'identifie' => trim($application->getElementsByTagName('identifie')->item(0)->textContent),
  37.  
    'version' => trim($application->getElementsByTagName('version')->item(0)->textContent),
  38.  
    'type' => trim($application->getElementsByTagName('type')->item(0)->textContent),
  39.  
    'ability' => trim($application->getElementsByTagName('ability')->item(0)->textContent),
  40.  
    'description' => trim($application->getElementsByTagName('description')->item(0)->textContent),
  41.  
    'author' => trim($application->getElementsByTagName('author')->item(0)->textContent),
  42.  
    'url' => trim($application->getElementsByTagName('url')->item(0)->textContent),
  43.  
    'setting' => trim($application->getAttribute('setting')) == 'true',
  44.  
    );
  45.  
    $platform = $root->getElementsByTagName('platform')->item(0);
  46.  
    if (!empty($platform)) {
  47.  
    $manifest['platform'] = array(
  48.  
    'subscribes' => array(),
  49.  
    'handles' => array(),
  50.  
    'isrulefields' => false,
  51.  
    'iscard' => false,
  52.  
    'supports' => array(),
  53.  
    );
  54.  
    $subscribes = $platform->getElementsByTagName('subscribes')->item(0);
  55.  
    if (!empty($subscribes)) {
  56.  
    $messages = $subscribes->getElementsByTagName('message');
  57.  
    for ($i = 0; $i < $messages->length; $i++) {
  58.  
    $t = $messages->item($i)->getAttribute('type');
  59.  
    if (!empty($t)) {
  60.  
    $manifest['platform']['subscribes'][] = $t;
  61.  
    }
  62.  
    }
  63.  
    }
  64.  
    $handles = $platform->getElementsByTagName('handles')->item(0);
  65.  
    if (!empty($handles)) {
  66.  
    $messages = $handles->getElementsByTagName('message');
  67.  
    for ($i = 0; $i < $messages->length; $i++) {
  68.  
    $t = $messages->item($i)->getAttribute('type');
  69.  
    if (!empty($t)) {
  70.  
    $manifest['platform']['handles'][] = $t;
  71.  
    }
  72.  
    }
  73.  
    }
  74.  
    $rule = $platform->getElementsByTagName('rule')->item(0);
  75.  
    if (!empty($rule) && $rule->getAttribute('embed') == 'true') {
  76.  
    $manifest['platform']['isrulefields'] = true;
  77.  
    }
  78.  
    $card = $platform->getElementsByTagName('card')->item(0);
  79.  
    if (!empty($card) && $card->getAttribute('embed') == 'true') {
  80.  
    $manifest['platform']['iscard'] = true;
  81.  
    }
  82.  
    $supports = $platform->getElementsByTagName('supports')->item(0);
  83.  
    if (!empty($supports)) {
  84.  
    $support_type = $supports->getElementsByTagName('item');
  85.  
    for ($i = 0; $i < $support_type->length; $i++) {
  86.  
    $t = $support_type->item($i)->getAttribute('type');
  87.  
    if (!empty($t)) {
  88.  
    $manifest['platform']['supports'][] = $t;
  89.  
    }
  90.  
    }
  91.  
    }
  92.  
    $plugins = $platform->getElementsByTagName('plugins')->item(0);
  93.  
    if (!empty($plugins)) {
  94.  
    $plugin_list = $plugins->getElementsByTagName('item');
  95.  
    for ($i = 0; $i < $plugin_list->length; $i++) {
  96.  
    $plugin = $plugin_list->item($i)->getAttribute('name');
  97.  
    if (!empty($plugin)) {
  98.  
    $manifest['platform']['plugin_list'][] = $plugin;
  99.  
    }
  100.  
    }
  101.  
    }
  102.  
    $plugin_main = $platform->getElementsByTagName('plugin-main')->item(0);
  103.  
    if (!empty($plugin_main)) {
  104.  
    $plugin_main = $plugin_main->getAttribute('name');
  105.  
    if (!empty($plugin_main)) {
  106.  
    $manifest['platform']['main_module'] = $plugin_main;
  107.  
    }
  108.  
    }
  109.  
    }
  110.  
    $bindings = $root->getElementsByTagName('bindings')->item(0);
  111.  
    if (!empty($bindings)) {
  112.  
    global $points;
  113.  
    if (!empty($points)) {
  114.  
    $ps = array_keys($points);
  115.  
    $manifest['bindings'] = array();
  116.  
    foreach ($ps as $p) {
  117.  
    $define = $bindings->getElementsByTagName($p)->item(0);
  118.  
    $manifest['bindings'][$p] = _ext_module_manifest_entries($define);
  119.  
    }
  120.  
    }
  121.  
    }
  122.  
    $permissions = $root->getElementsByTagName('permissions')->item(0);
  123.  
    if (!empty($permissions)) {
  124.  
    $manifest['permissions'] = array();
  125.  
    $items = $permissions->getElementsByTagName('entry');
  126.  
    for ($i = 0; $i < $items->length; $i++) {
  127.  
    $item = $items->item($i);
  128.  
    $row = array(
  129.  
    'title' => $item->getAttribute('title'),
  130.  
    'permission' => $item->getAttribute('do'),
  131.  
    );
  132.  
    if (!empty($row['title']) && !empty($row['permission'])) {
  133.  
    $manifest['permissions'][] = $row;
  134.  
    }
  135.  
    }
  136.  
    }
  137.  
    return $manifest;
  138.  
    }
  139.  
     
  140.  
     
  141.  
    function ext_module_manifest($modulename) {
  142.  
    $filename = IA_ROOT . '/addons/' . $modulename . '/manifest.xml';
  143.  
    if (!file_exists($filename)) {
  144.  
    return array();
  145.  
    }
  146.  
    $xml = file_get_contents($filename);
  147.  
    return ext_module_manifest_parse($xml);
  148.  
    }

好了,现在该分析安装了,先把安装代码贴上;这部分主要做业务判断,模块信息插入数据库,主要表modules_bindings ,modules,要修改模块的信息、或者增加显示功能列表修改表就行了

 

 

  1.  
    if ($do =='install') {
  2.  
    $points = ext_module_bindings();
  3.  
    $module_name = trim($_GPC['module_name']);
  4.  
    $is_recycle_module = pdo_get('modules_recycle', array('modulename' => $module_name));
  5.  
    if (empty($_W['isfounder'])) {
  6.  
    itoast('您没有安装模块的权限', '', 'error');
  7.  
    }
  8.  
    $module_info = module_fetch($module_name);
  9.  
    if (!empty($module_info)) {
  10.  
    itoast('模块已经安装或是唯一标识已存在!', '', 'error');
  11.  
    }
  12.  
    $manifest = ext_module_manifest($module_name);
  13.  
    if (!empty($manifest)) {
  14.  
    $result = cloud_m_prepare($module_name);
  15.  
    if (is_error($result)) {
  16.  
    itoast($result['message'], url('module/manage-system/not_installed', array('account_type' => ACCOUNT_TYPE)), 'error');
  17.  
    }
  18.  
    } else {
  19.  
    $result = cloud_prepare();
  20.  
    if (is_error($result)) {
  21.  
    itoast($result['message'], url('cloud/profile'), 'error');
  22.  
    }
  23.  
    $module_info = cloud_m_info($module_name);
  24.  
    if (!is_error($module_info)) {
  25.  
    if (empty($_GPC['flag'])) {
  26.  
    header('location: ' . url('cloud/process', array('account_type' => ACCOUNT_TYPE, 'm' => $module_name)));
  27.  
    exit;
  28.  
    } else {
  29.  
    define('ONLINE_MODULE', true);
  30.  
    $packet = cloud_m_build($module_name);
  31.  
    $manifest = ext_module_manifest_parse($packet['manifest']);
  32.  
    }
  33.  
    } else {
  34.  
    itoast($module_info['message'], '', 'error');
  35.  
    }
  36.  
    }
  37.  
    if (empty($manifest)) {
  38.  
    itoast('模块安装配置文件不存在或是格式不正确,请刷新重试!', url('module/manage-system/not_installed', array('account_type' => ACCOUNT_TYPE)), 'error');
  39.  
    }
  40.  
    if (!empty($manifest['platform']['main_module'])) {
  41.  
    $plugin_exist = pdo_get('modules_plugin', array('main_module' => $manifest['platform']['main_module'], 'name' => $manifest['application']['identifie']));
  42.  
    if (empty($plugin_exist)) {
  43.  
    itoast('请先更新主模块后再安装插件', url('module/manage-system/installed'), 'error');
  44.  
    }
  45.  
    }
  46.  
    $check_manifest_result = manifest_check($module_name, $manifest);
  47.  
    if (is_error($check_manifest_result)) {
  48.  
    itoast($check_manifest_result['message'], '', 'error');
  49.  
    }
  50.  
    $module_path = IA_ROOT . '/addons/' . $module_name . '/';
  51.  
    if (!file_exists($module_path . 'processor.php') && !file_exists($module_path . 'module.php') && !file_exists($module_path . 'receiver.php') && !file_exists($module_path . 'site.php')) {
  52.  
    itoast('模块缺失文件,请检查模块文件中site.php, processor.php, module.php, receiver.php 文件是否存在!', '', 'error');
  53.  
    }
  54.  
    $module = ext_module_convert($manifest);
  55.  
    $module_group = uni_groups();
  56.  
    if (!$_W['ispost'] || empty($_GPC['flag'])) {
  57.  
    template('system/select-module-group');
  58.  
    exit;
  59.  
    }
  60.  
    if (!empty($manifest['platform']['plugin_list'])) {
  61.  
    foreach ($manifest['platform']['plugin_list'] as $plugin) {
  62.  
    pdo_insert('modules_plugin', array('main_module' => $manifest['application']['identifie'], 'name' => $plugin));
  63.  
    }
  64.  
    }
  65.  
    $post_groups = $_GPC['group'];
  66.  
    ext_module_clean($module_name);
  67.  
    $bindings = array_elements(array_keys($points), $module, false);
  68.  
    if (!empty($points)) {
  69.  
    foreach ($points as $name => $point) {
  70.  
    unset($module[$name]);
  71.  
    if (is_array($bindings[$name]) && !empty($bindings[$name])) {
  72.  
    foreach ($bindings[$name] as $entry) {
  73.  
    $entry['module'] = $manifest['application']['identifie'];
  74.  
    $entry['entry'] = $name;
  75.  
    if ($name == 'page' && !empty($wxapp_support)) {
  76.  
    $entry['url'] = $entry['do'];
  77.  
    $entry['do'] = '';
  78.  
    }
  79.  
    pdo_insert('modules_bindings', $entry);
  80.  
    }
  81.  
    }
  82.  
    }
  83.  
    }
  84.  
    $module['permissions'] = iserializer($module['permissions']);
  85.  
    $module_subscribe_success = true;
  86.  
    if (!empty($module['subscribes'])) {
  87.  
    $subscribes = iunserializer($module['subscribes']);
  88.  
    if (!empty($subscribes)) {
  89.  
    $module_subscribe_success = ext_check_module_subscribe($module['name']);
  90.  
    }
  91.  
    }
  92.  
    if (!empty($module_info['version']['cloud_setting'])) {
  93.  
    $module['settings'] = 2;
  94.  
    }
  95.  
    $module['title_initial'] = get_first_pinyin($module['title']);
  96.  
    if (strexists($manifest['install'], '.php')) {
  97.  
    if (file_exists($module_path . $manifest['install'])) {
  98.  
    include_once $module_path . $manifest['install'];
  99.  
    if (ONLINE_MODULE) {
  100.  
    unlink ($module_path . $manifest['install']);
  101.  
    }
  102.  
    }
  103.  
    } else {
  104.  
    pdo_run($manifest['install']);
  105.  
    }
  106.  
    if (pdo_insert('modules', $module)) {
  107.  
    if (ONLINE_MODULE) {
  108.  
    if (strexists($manifest['upgrade'], '.php') && file_exists($module_path . $manifest['upgrade'])) {
  109.  
    unlink($module_path . $manifest['upgrade']);
  110.  
    }
  111.  
    if (strexists($manifest['uninstall'], '.php') && file_exists($module_path . $manifest['uninstall'])) {
  112.  
    unlink($module_path . $manifest['uninstall']);
  113.  
    }
  114.  
    }
  115.  
     
  116.  
    if (defined('ONLINE_MODULE')) {
  117.  
    ext_module_script_clean($module['name'], $manifest);
  118.  
    }
  119.  
    if ($_GPC['flag'] && !empty($post_groups) && $module['name']) {
  120.  
    foreach ($post_groups as $groupid) {
  121.  
    $group_info = pdo_get('uni_group', array('id' => intval($groupid)), array('id', 'name', 'modules'));
  122.  
    if (empty($group_info)) {
  123.  
    continue;
  124.  
    }
  125.  
    $group_info['modules'] = iunserializer($group_info['modules']);
  126.  
    if (in_array($module['name'], $group_info['modules'])) {
  127.  
    continue;
  128.  
    }
  129.  
    $group_info['modules'][] = $module['name'];
  130.  
    $group_info['modules'] = iserializer($group_info['modules']);
  131.  
    pdo_update('uni_group', $group_info, array('id' => $groupid));
  132.  
    }
  133.  
    }
  134.  
     
  135.  
    if (!empty($is_recycle_module)) {
  136.  
    pdo_delete('modules_recycle', array('modulename' => $module_name));
  137.  
    }
  138.  
    cache_build_module_subscribe_type();
  139.  
    cache_build_account_modules();
  140.  
    cache_build_uninstalled_module();
  141.  
    cache_build_module_info($module_name);
  142.  
     
  143.  
    if (empty($module_subscribe_success)) {
  144.  
    itoast('模块安装成功!模块订阅消息有错误,系统已禁用该模块的订阅消息,详细信息请查看', url('module/manage-system/module_detail', array('name' => $module['name'])), 'tips');
  145.  
    } else {
  146.  
    itoast('模块安装成功!', url('module/manage-system', array('account_type' => ACCOUNT_TYPE)), 'success');
  147.  
    }
  148.  
    } else {
  149.  
    itoast('模块安装失败, 请联系模块开发者!');
  150.  
    }
  151.  
    }

安装完成后,模块就可以开始使用了,模块的使用稍后分析

 

 

先说卸载,卸载只是将之前的入库的数据删了,本质上没有删文件

 

  1.  
    if ($do == 'uninstall') {
  2.  
    $name = trim($_GPC['name']);
  3.  
    $message = '';
  4.  
    $module = module_fetch($name);
  5.  
    if (!empty($module['plugin'])) {
  6.  
    $plugin_list = module_get_plugin_list($module['name']);
  7.  
    if (!empty($plugin_list) && is_array($plugin_list)) {
  8.  
    $message .= '删除' . $module['title'] . '并删除' . $module['title'] . '包含插件<ul>';
  9.  
    foreach ($plugin_list as $plugin) {
  10.  
    $message .= "<li>{$plugin['title']}</li>";
  11.  
    }
  12.  
    unset($plugin);
  13.  
    $message .= '</ul>';
  14.  
    }
  15.  
    }
  16.  
    if (!isset($_GPC['confirm'])) {
  17.  
    if ($module['isrulefields']) {
  18.  
    $message .= '是否删除相关规则和统计分析数据<div><a class="btn btn-primary" style="width:80px;" href="' . url('module/manage-system/uninstall', array('name' => $name, 'confirm' => 1)) . '">是</a>   <a class="btn btn-default" style="width:80px;" href="' . url('module/manage-system/uninstall', array('account_type' => ACCOUNT_TYPE, 'name' => $name, 'confirm' => 0)) . '">否</a></div>';
  19.  
    } elseif (!empty($plugin_list)) {
  20.  
    $message .= "<a href=" . url('module/manage-system/uninstall', array('name' => $name,'confirm' => 0)) . " class='btn btn-info'>继续删除</a>";
  21.  
    }
  22.  
    if (!empty($message)) {
  23.  
    itoast($message, '', 'tips');
  24.  
    }
  25.  
    }
  26.  
    if (!empty($plugin_list) && is_array($plugin_list)) {
  27.  
    foreach ($plugin_list as $plugin) {
  28.  
    module_uninstall($plugin['name']);
  29.  
    }
  30.  
    }
  31.  
    $uninstall_result = module_uninstall($module['name'], $_GPC['confirm'] == 1);
  32.  
    if (is_error($uninstall_result)) {
  33.  
    itoast($uninstall_result['message'], url('module/manage-system'), 'error');
  34.  
    }
  35.  
    itoast('模块已放入回收站!', url('module/manage-system', array('account_type' => ACCOUNT_TYPE)), 'success');
  36.  
    }
posted @ 2018-11-14 20:13  归一山人  阅读(1207)  评论(0编辑  收藏  举报