$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']) {
         dheader('location: ' . ADMINSCRIPT . '?action=plugins&operation=import&dir=' . $_GET['key']);
     } else {
         dheader('location: ' . ADMINSCRIPT . '?action=plugins&operation=upgrade&pluginid=' . $plugin['pluginid']);
     }
function cloudaddons_copytree($from, $to)
{
    global $_G;
    $dh = opendir($from);
    while (($file = readdir($dh)) !== false) {
        if ($file != '.' && $file != '..') {
            $readfile = $from . '/' . $file;
            $writefile = $to . '/' . $file;
            if (is_file($readfile)) {
                if (!in_array($readfile, $_G['treeop']['copy'])) {
                    continue;
                }
                if (!isset($_G['siteftp'])) {
                    $content = -1;
                    if ($fp = @fopen($readfile, 'r')) {
                        $startTime = microtime();
                        do {
                            $canRead = flock($fp, LOCK_SH);
                            if (!$canRead) {
                                usleep(round(rand(0, 100) * 1000));
                            }
                        } while (!$canRead && microtime() - $startTime < 1000);
                        if (!$canRead) {
                            cpmsg('cloudaddons_file_read_error', '', 'error');
                        }
                        $content = fread($fp, filesize($readfile));
                        flock($fp, LOCK_UN);
                        fclose($fp);
                    }
                    if ($content < 0) {
                        cpmsg('cloudaddons_file_read_error', '', 'error');
                    }
                    dmkdir(dirname($writefile), 0777, false);
                    $writefile = preg_replace('/\\._addons_$/', '', $writefile);
                    if ($fp = fopen($writefile, 'w')) {
                        $startTime = microtime();
                        do {
                            $canWrite = flock($fp, LOCK_EX);
                            if (!$canWrite) {
                                usleep(round(rand(0, 100) * 1000));
                            }
                        } while (!$canWrite && microtime() - $startTime < 1000);
                        if (!$canWrite) {
                            cpmsg('cloudaddons_file_write_error', '', 'error');
                        }
                        fwrite($fp, $content);
                        flock($fp, LOCK_UN);
                        fclose($fp);
                    }
                    if (!$canWrite) {
                        cpmsg('cloudaddons_file_write_error', '', 'error');
                    }
                } else {
                    $writefile = preg_replace('/\\._addons_$/', '', $writefile);
                    siteftp_upload($readfile, preg_replace('/^' . preg_quote(DISCUZ_ROOT) . '/', '', $writefile));
                }
                if (md5_file($readfile) != md5_file($writefile)) {
                    cpmsg('cloudaddons_file_write_error', '', 'error');
                }
            } else {
                cloudaddons_copytree($readfile, $writefile);
            }
        }
    }
}
Beispiel #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));
}