} else {
     $descdir = DISCUZ_ROOT;
     $subdir = '';
 }
 $unwriteabledirs = cloudaddons_dirwriteable($descdir, $subdir, $tmpdir);
 if ($unwriteabledirs) {
     if (!submitcheck('settingsubmit')) {
         showtips(cplang('cloudaddons_unwriteabledirs', array('basedir' => $typedir[$_GET['type']] != '.' ? $typedir[$_GET['type']] : '/', 'unwriteabledirs' => implode(', ', $unwriteabledirs))));
         siteftp_form("cloudaddons&operation=download&addonids={$_GET['addonids']}&i={$addoni}&end=" . rawurlencode($_GET['end']) . "&step=2&md5hash=" . $_GET['md5hash'] . '&timestamp=' . $_GET['timestamp']);
         exit;
     } else {
         siteftp_check($_GET['siteftp'], $typedir[$_GET['type']]);
     }
 }
 $descdir .= $subdir;
 cloudaddons_comparetree($tmpdir, $descdir, $tmpdir, $_GET['key'] . '.' . $_GET['type'], 1);
 if (!empty($_G['treeop']['oldchange']) && empty($_GET['confirmed'])) {
     cpmsg('cloudaddons_install_files_changed', '', 'form', array('files' => implode('<br />', $_G['treeop']['oldchange'])));
 }
 cloudaddons_copytree($tmpdir, $descdir);
 cloudaddons_savemd5($_GET['key'] . '.' . $_GET['type'], $_GET['end'], $_G['treeop']['md5']);
 cloudaddons_deltree($tmpdir);
 if (count($addonids) - 1 > $addoni) {
     $addoni++;
     cpmsg('cloudaddons_downloading', "action=cloudaddons&operation=download&addonids={$_GET['addonids']}&i={$addoni}&step=1&md5hash=" . $_GET['md5hash'] . '&timestamp=' . $_GET['timestamp'], 'loading', array('addonid' => $_GET['key'] . '.' . $_GET['type']), FALSE);
 }
 list($_GET['key'], $_GET['type'], $_GET['rid']) = explode('.', $addonids[0]);
 cloudaddons_downloadlog($_GET['key'] . '.' . $_GET['type']);
 if ($_GET['type'] == 'plugin') {
     $plugin = C::t('common_plugin')->fetch_by_identifier($_GET['key']);
     if (!$plugin['pluginid']) {
function cloudaddons_comparetree($new, $old, $basedir, $md5file, $first = 0)
{
    global $_G;
    if ($first && file_exists(DISCUZ_ROOT . './data/addonmd5/' . $md5file . '.xml')) {
        require_once libfile('class/xml');
        $xml = implode('', @file(DISCUZ_ROOT . './data/addonmd5/' . $md5file . '.xml'));
        $array = xml2array($xml);
        $_G['treeop']['md5old'] = $array['Data'];
    }
    $dh = opendir($new);
    while (($file = readdir($dh)) !== false) {
        if ($file != '.' && $file != '..') {
            $newfile = $new . '/' . $file;
            $oldfile = $old . '/' . $file;
            if (is_file($newfile)) {
                $oldfile = preg_replace('/\\._addons_$/', '', $oldfile);
                $md5key = str_replace($basedir, '', preg_replace('/\\._addons_$/', '', $newfile));
                $newmd5 = md5_file($newfile);
                $oldmd5 = file_exists($oldfile) ? md5_file($oldfile) : '';
                if (isset($_G['treeop']['md5old'][$md5key]) && $_G['treeop']['md5old'][$md5key] != $oldmd5 && $oldmd5) {
                    $_G['treeop']['oldchange'][] = $md5key;
                }
                if ($newmd5 != $oldmd5) {
                    $_G['treeop']['copy'][] = $newfile;
                }
                $_G['treeop']['md5'][$md5key] = $newmd5;
            } else {
                cloudaddons_comparetree($newfile, $oldfile, $basedir);
            }
        }
    }
}
Esempio n. 3
0
function pick_install()
{
    global $_G;
    $tmpdir = DISCUZ_ROOT . './data/download/dxc_temp';
    if (!is_dir($tmpdir)) {
        cpmsg(milu_lang('cloudaddons_download_error'), '', 'error');
        //数据下载错误
    }
    $_GET['type'] = 'plugin';
    $_GET['key'] = 'milu_pick';
    $to_version = $_GET['version'];
    $to_version_dateline = $_GET['version_dateline'];
    if (!libfile('function/cloudaddons')) {
        exit('error01:file not found');
    }
    require_once libfile('function/cloudaddons');
    $descdir = DISCUZ_ROOT . 'source/plugin/';
    $subdir = 'milu_pick';
    $unwriteabledirs = cloudaddons_dirwriteable($descdir, $subdir, $tmpdir);
    if ($unwriteabledirs) {
        //目录不可写
        showtips(milu_lang('cloudaddons_unwriteabledirs', array('basedir' => 'source/plugin', 'unwriteabledirs' => implode(', ', $unwriteabledirs))));
        exit;
    }
    $descdir .= $subdir;
    cloudaddons_comparetree($tmpdir, $descdir, $tmpdir, $_GET['key'] . '.' . $_GET['type'] . 'vip', 1);
    if (!empty($_G['treeop']['oldchange']) && empty($_GET['confirmed'])) {
        cpmsg(milu_lang('cloudaddons_install_files_changed', array('files' => implode('<br />', $_G['treeop']['oldchange']))), '', 'form', '');
    }
    cloudaddons_copytree($tmpdir, $descdir);
    $client_info = get_client_info();
    $_GET['end'] = 'Status=End&ID=milu_pick_vip.plugin&SN=' . $client_info['domain'] . '&RevisionID=' . $client_info['domain'] . '&RevisionDateline=' . $client_info['domain'];
    cloudaddons_savemd5($_GET['key'] . '.' . $_GET['type'] . 'vip', $_GET['end'], $_G['treeop']['md5']);
    cloudaddons_deltree($tmpdir);
    //成功之后的一些动作
    $set['pick_tips']['check_version'] = 0;
    pick_common_set($set);
    $charset = str_replace('-', '', strtoupper($_G['config']['output']['charset']));
    $locale = '';
    if ($charset == 'BIG5') {
        $locale = 'TC';
    } elseif ($charset == 'GBK') {
        $locale = 'SC';
    } elseif ($charset == 'UTF8') {
        if ($_G['config']['output']['language'] == 'zh_cn') {
            $locale = 'SC';
        } elseif ($_G['config']['output']['language'] == 'zh_tw') {
            $locale = 'TC';
        }
    }
    $xml_ext = 'discuz_plugin_milu_pick_' . $locale . '_' . $charset . '.xml';
    $xml_file = $descdir . '/' . $xml_ext;
    if (!file_exists($xml_file)) {
        cpmsg(milu_lang('xml_no_found', array('f' => $xml_ext)), '', 'error');
    }
    //xml文件丢失
    require_once libfile('class/xml');
    $data = file_get_contents($xml_file);
    $data_arr = xml2array($data);
    $xml_data = exportarray($data_arr['Data'], 0);
    $installtype = $locale . '_' . $charset;
    pluginupgrade($xml_data, $installtype);
    $auth_file = PICK_DIR . '/data/pick_auth.txt';
    $upgrade_file = $descdir . '/upgrade.php';
    if (file_exists($upgrade_file)) {
        $_GET['fromversion'] = PICK_VERSION;
        include $upgrade_file;
        if (!$finish) {
            cpmsg_error(milu_lang('up_fail'));
        }
    }
    @unlink($auth_file);
    cpmsg('plugins_upgrade_succeed', PICK_GO . "pick_info", 'succeed', array('toversion' => $to_version . ' ' . $to_version_dateline));
}