Example #1
0
 function plain_db_init()
 {
     //	global $xoopsDB,$whatsnew,$vars,$post,$get,$related,$comment_no;
     if ($dir = @opendir($this->cont['DATA_DIR'])) {
         $this->root->rtf['is_init'] = true;
         // 処理済ファイルリストデーター
         $work = $this->cont['CACHE_DIR'] . "dbsync_p.dat";
         $domix = $dones = array();
         $done = 0;
         if (is_file($work)) {
             $dones = unserialize(file_get_contents($work));
             if (!isset($dones[1])) {
                 $dones[1] = array();
             }
             $docnt = count($dones[1]);
             $domix = array_merge($dones[0], $dones[1]);
             $done = count($domix);
         }
         if ($done) {
             echo "<div style=\"font-size:14px;\"><b>DB '" . $this->root->mydirname . "_plain' Already converted {$docnt} pages.</b></div>";
         }
         echo "<div style=\"font-size:14px;\"><b>DB '" . $this->root->mydirname . "_plain' Now converting... </b>( * = 10 Pages)<hr>";
         $counter = 0;
         $files = array();
         while ($file = readdir($dir)) {
             $files[] = $file;
         }
         // PHP の上限メモリーサイズ
         $memory_limit = HypCommonFunc::return_bytes(ini_get('memory_limit'));
         $debug = array();
         foreach (array_diff($files, $domix) as $file) {
             if ($file == ".." || $file == "." || strstr($file, ".txt") === FALSE) {
                 $dones[0][] = $file;
                 continue;
             }
             $this->root->related = array();
             $page = $this->func->decode(trim(preg_replace("/\\.txt\$/", " ", $file)));
             $this->root->vars['page'] = $this->root->get['page'] = $this->root->post['page'] = $page;
             $this->root->comment_no = 0;
             if ($page === $this->root->whatsnew) {
                 $dones[0][] = $file;
                 continue;
             }
             $id = $this->func->get_pgid_by_name($page, FALSE, TRUE);
             $query = "SELECT LENGTH(plain) FROM `" . $this->db->prefix($this->root->mydirname . "_plain") . "` WHERE `pgid` = " . $id . ";";
             $result = $this->db->query($query);
             if ($result && $this->db->getRowsNum($result)) {
                 list($len) = $this->db->fetchRow($result);
                 if ($len && !$this->root->post['plain_all']) {
                     $dones[0][] = $file;
                     continue;
                 }
                 $mode = "update";
             } else {
                 $mode = "insert";
             }
             $s_page = $this->func->htmlspecialchars($page);
             if ($this->root->post['p_info']) {
                 echo 'Start: ' . $s_page . '<br />';
             }
             if ($this->root->post['plain_bg'] || $this->func->plain_db_write($page, $mode, TRUE)) {
                 if ($this->root->post['plain_bg']) {
                     $this->func->need_update_plaindb($page, $mode, FALSE, FALSE);
                 }
                 $dones[1][] = $file;
                 $counter++;
                 if ($this->root->post['p_info']) {
                     echo 'Finish: ' . $s_page . (function_exists('memory_get_usage') ? ' - M: ' . number_format(memory_get_usage()) : '') . '<br />';
                 } else {
                     if ($counter / 10 == floor($counter / 10)) {
                         echo "*";
                     }
                 }
                 if ($counter / 100 == floor($counter / 100)) {
                     echo " ( Done " . $counter . " Pages !)<br />";
                 }
             } else {
                 if ($this->root->post['p_info']) {
                     echo 'Error: ' . $s_page . '<br />';
                 }
                 $dones[0][] = $file;
             }
             if (function_exists('memory_get_usage')) {
                 // メモリーチェック マージン 1MB (1024 * 1024 = 1048576)
                 $memory_full = $memory_limit && memory_get_usage() + 1048576 > $memory_limit;
             } else {
                 $memory_full = false;
             }
             if ($memory_full || $this->check_time_limit()) {
                 // 処理済ファイルリスト保存
                 if ($fp = fopen($work, "wb")) {
                     fputs($fp, serialize($dones));
                     fclose($fp);
                 }
                 closedir($dir);
                 $this->plugin_dbsync_next_do();
             }
         }
         closedir($dir);
         $this->root->vars['page'] = $this->root->get['page'] = $this->root->post['page'] = "";
         $this->root->post['plain'] = "";
         $this->func->autolink_dat_update();
         echo " ( Done " . $counter . " Pages !)<hr />";
         if (!empty($debug['donepage']) && $this->root->post['p_info']) {
             echo join('<br />', $debug['donepage']);
         }
         echo "</div>";
         @unlink($work);
     }
 }
Example #2
0
 $mytrustdirpath = dirname(__FILE__);
 define('_XPWIKI_FILES_LOADED', TRUE);
 // For PHP >= 5.3
 if (error_reporting() > 6143) {
     error_reporting(E_ALL & ~E_DEPRECATED);
 }
 if (!function_exists('XC_CLASS_EXISTS')) {
     include dirname(dirname($mytrustdirpath)) . '/class/hyp_common/XC_CLASS_EXISTS.inc.php';
 }
 // Load & check a class HypCommonFunc
 if (!XC_CLASS_EXISTS('HypCommonFunc')) {
     include dirname(dirname($mytrustdirpath)) . '/class/hyp_common/hyp_common_func.php';
 }
 // Set 'memory_limit'
 // 64M = 64 * 1024 * 1024 = 67108864 bytes
 if (HypCommonFunc::return_bytes(ini_get('memory_limit')) < 67108864) {
     ini_set('memory_limit', '64M');
 }
 include $mytrustdirpath . '/class/xpwiki.php';
 include $mytrustdirpath . '/class/root.php';
 include $mytrustdirpath . '/class/func/base_func.php';
 include $mytrustdirpath . '/class/func/pukiwiki_func.php';
 if (extension_loaded('zlib')) {
     include $mytrustdirpath . '/class/func/backup_gzip.php';
 } else {
     include $mytrustdirpath . '/class/func/backup_text.php';
 }
 include $mytrustdirpath . '/class/func/xoops_wrapper.php';
 include $mytrustdirpath . '/class/func/xpwiki_func.php';
 include $mytrustdirpath . '/class/extension.php';
 include $mytrustdirpath . '/class/plugin.php';
Example #3
0
    function plugin_dump_disp_form($reqfile = '')
    {
        $act_down = $this->cont['PLUGIN_DUMP_DUMP'];
        $act_up = $this->cont['PLUGIN_DUMP_RESTORE'];
        $maxsize = $this->cont['PLUGIN_DUMP_MAX_FILESIZE'];
        $this->msg['max_filesize'] = str_replace('$maxsize', $maxsize, $this->msg['max_filesize']);
        $memory_limit = HypCommonFunc::return_bytes(ini_get('memory_limit'));
        if (function_exists('memory_get_usage')) {
            $memory_usage = memory_get_usage() * 1.1;
        } else {
            $memory_usage = 7 * 1024 * 1024;
        }
        if ($memory_limit) {
            $maxsize = max(0.1, min(20, ceil(($memory_limit - $memory_usage) / 1024 / 1024 * 10) / 10));
        } else {
            $maxsize = 5;
        }
        $fullpath = array();
        foreach ($this->datadirs as $name => $path) {
            if (strpos($path, $this->cont['DATA_HOME']) !== 0) {
                $msg = str_replace('$1', $path, $this->msg['make_fullpath']);
                $fullpath[$name] = '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="fullpath_' . $name . '" id="_p_dump_fullpath_' . $name . '"><label for="_p_dump_fullpath_' . $name . '"> ' . $msg . '</label><br />';
            } else {
                $fullpath[$name] = '';
            }
        }
        $passform = $this->root->userinfo['admin'] ? '' : '<label for="_p_dump_adminpass_dump"><strong>' . $this->msg['admin_pass'] . '</strong></label>
  <input type="password" name="pass" id="_p_dump_adminpass_dump" size="12" />';
        if (extension_loaded('zlib')) {
            $tarop = <<<EOD
  <input type="radio" name="pcmd" id="_p_dump_tgz" value="tgz" checked="checked" />
  <label for="_p_dump_tgz">{$this->msg['tar.gz']}</label><br />
  <input type="radio" name="pcmd" id="_p_dump_tar" value="tar" />
  <label for="_p_dump_tar">{$this->msg['tar']}</label>
EOD;
        } else {
            $tarop = <<<EOD
  <input type="radio" name="pcmd" id="_p_dump_tar" value="tar" checked="checked" />
  <label for="_p_dump_tar">{$this->msg['tar']}</label>
EOD;
        }
        $script = $this->func->get_script_uri();
        $data = '';
        if (!$reqfile) {
            $data .= <<<EOD
<div class="level3">
<h3>{$this->msg['data_download']}</h3>
<form action="{$script}" method="post">
 <div>
  <input type="hidden" name="cmd"  value="dump" />
  <input type="hidden" name="act"  value="{$act_down}" />

<p><strong>{$this->msg['tar_type']}</strong>
<br />
{$tarop}
</p>

<p>
<strong>{$this->msg['maxsize']}: <input type="text" size="4" name="limitsize" value="{$maxsize}" style="text-align:right;" />MB</strong>
<br />
{$this->msg['maxsize_desc']}
</p>

<p><strong>{$this->msg['backup_dir']}</strong><br />
<br />
  <input type="checkbox" name="bk_wiki" id="_p_dump_d_wiki" checked="checked" />
  <label for="_p_dump_d_wiki">wiki</label><br />
  {$fullpath['wiki']}
  <input type="radio" name="bk_counter" value="1" id="_p_dump_d_counter" />
  <label for="_p_dump_d_counter">counter</label><br />
  <input type="checkbox" name="bk_attach" id="_p_dump_d_attach" checked="checked" />
  <label for="_p_dump_d_attach">attach</label><br />
  {$fullpath['attach']}
  <input type="checkbox" name="bk_backup" id="_p_dump_d_backup" checked="checked" />
  <label for="_p_dump_d_backup">backup</label><br />
  {$fullpath['backup']}
  <input type="checkbox" name="bk_diff" id="_p_dump_d_diff" checked="checked" />
  <label for="_p_dump_d_diff">diff</label><br />
  {$fullpath['diff']}
  <input type="checkbox" name="bk_trackback" id="_p_dump_d_trackback" checked="checked" />
  <label for="_p_dump_d_trackback">trackback</label><br />
  {$fullpath['trackback']}
  <input type="checkbox" name="bk_ini" id="_p_dump_d_ini" checked="checked" />
  <label for="_p_dump_d_ini">ini(*.ini.php)</label><br />
  {$fullpath['ini']}
  <input type="checkbox" name="bk_cache" id="_p_dump_d_cache" checked="checked" />
  <label for="_p_dump_d_cache">cache(*.ini.php|[pgid].css)</label><br />
  {$fullpath['cache']}
</p>
<p><strong>{$this->msg['option']}</strong>
<br />
  <input type="checkbox" name="namedecode" id="_p_dump_namedecode" />
  <label for="_p_dump_namedecode">{$this->msg['decode_pagename']}</label><br />
</p>
<p><strong>{$this->msg['backup_table']}</strong><br />
<br />
  <input type="checkbox" name="bk_dbpginfo" id="_p_dump_d_dbinfo" checked="checked" />
  <label for="_p_dump_d_dbinfo">DB@pginfo</label><br />
  <input type="radio" name="bk_counter" value="2" id="_p_dump_d_dbcount" checked="checked" onmousedown="if (this.checked) this.checked = false;return false;" />
  <label for="_p_dump_d_dbcount" onmousedown="if (getElementById('_p_dump_d_dbcount').checked) getElementById('_p_dump_d_dbcount').checked = false;return false;">DB@count</label><br />
  <input type="checkbox" name="bk_dbattach" id="_p_dump_d_dbattach" checked="checked" />
  <label for="_p_dump_d_dbattach">DB@attach</label><br />
  <input type="checkbox" name="bk_dbplain" id="_p_dump_d_dbplain" checked="checked" />
  <label for="_p_dump_d_dbplain">DB@plain</label><br />
  <input type="checkbox" name="bk_dbrel" id="_p_dump_d_dbrel" checked="checked" />
  <label for="_p_dump_d_dbrel">DB@rel</label><br />
  <input type="checkbox" name="bk_dbalias" id="_p_dump_d_dbalias" checked="checked" />
  <label for="_p_dump_d_dbalias">DB@alias</label><br />
</p>
<p>{$passform}
  <input type="submit"   name="ok"   value="{$this->msg['do_download']}" />
  <br />
  {$this->msg['click_once']}
</p>
 </div>
</form>
</div>
EOD;
        }
        if ($this->cont['PLUGIN_DUMP_ALLOW_RESTORE']) {
            $passform = $this->root->userinfo['admin'] ? '' : '<label for="_p_dump_adminpass_restore"><strong>' . $this->msg['admin_pass'] . '</strong></label>
  <input type="password" name="pass" id="_p_dump_adminpass_restore" size="12" />';
            $script = $this->func->get_script_uri();
            $notice = '<p><strong>' . $this->msg['data_overwrite'] . '</strong></p>';
            if ($reqfile && $reqfile !== 'finish') {
                $notice = $reqfile;
                $restore_hint = '';
            } else {
                $reqfile = '';
                $notice = $this->msg['data_overwrite'];
                $restore_hint = $this->cont['SOURCE_ENCODING'] === 'UTF-8' ? '<p>' . $this->msg['restore_hint'] . '</p>' : '';
            }
            $data .= <<<EOD
<form enctype="multipart/form-data" action="{$script}" method="post">
 <input type="hidden" name="cmd"  value="dump" />
 <input type="hidden" name="act"  value="{$act_up}" />
 <div class="level3">
  <h3>{$this->msg['data_restore']}</h3>
  <p><strong>{$notice}</strong></p>
  {$restore_hint}
  <div class="level4">
   <h4>{$this->msg['uplode_now']}</h4>
    <p>
     <span class="small">{$this->msg['max_filesize']}</span><br />
     <label for="_p_dump_upload_file">{$this->msg['file']}</label>
     <input type="file" name="upload_file" id="_p_dump_upload_file" size="40" />
    </p>
  </div>
EOD;
            // private/cache のファイル検索
            $tars = array();
            if ($handle = opendir($this->cont['CACHE_DIR'])) {
                while (false !== ($file = readdir($handle))) {
                    if ($reqfile) {
                        if ($file === $reqfile) {
                            $tars[$file][] = $file;
                            break;
                        }
                    } else {
                        if (preg_match($this->tar_pregex, $file, $match)) {
                            $tars[$match[1]][] = $file;
                        }
                    }
                }
            }
            $data .= <<<EOD
  <div class="level4">
   <h4>{$this->msg['uploded_ftp']}</h4>
   <p><strong>{$this->cont['CACHE_DIR']}</strong></p>
EOD;
            if ($tars) {
                $radio = '';
                $i = 0;
                krsort($tars);
                $image = '<img src="' . $this->cont['LOADER_URL'] . '?src=package_go.png" alt="Download" />';
                $t_dl = ' title="Download"';
                foreach ($tars as $name => $tars) {
                    if (count($tars) === 1) {
                        $tar = $tars[0];
                        $tar_view = $this->func->htmlspecialchars($tar);
                        $checked = $reqfile ? ' checked="checked"' : '';
                        $fsize = filesize($this->cont['CACHE_DIR'] . $tar);
                        $radio .= '    <input type="radio" name="localfile" id="_p_dump_localfile' . $i . '" value="' . $tar_view . '"' . $checked . ' /><label for="_p_dump_localfile' . $i++ . '"> ' . $tar_view . ' ( ' . $this->func->bytes2KMT($fsize) . ' )</label>';
                        $radio .= '    <a target="xpwiki_dump" href="' . $this->cont['HOME_URL'] . '?cmd=dump&amp;act=download&amp;file=' . rawurlencode($tar) . '"' . $t_dl . '>' . $image . '</a><br />' . "\n";
                    } else {
                        natsort($tars);
                        $radio .= '    <input type="radio" disabled="disabled" /> ' . $this->func->htmlspecialchars($name) . '<br />';
                        foreach ($tars as $tar) {
                            $tar_view = $this->func->htmlspecialchars(substr($tar, strlen($name)));
                            $fsize = filesize($this->cont['CACHE_DIR'] . $tar);
                            $radio .= '    &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="localfile" id="_p_dump_localfile' . $i . '" value="' . $this->func->htmlspecialchars($tar) . '" /><label for="_p_dump_localfile' . $i++ . '"> ' . $tar_view . ' ( ' . $this->func->bytes2KMT($fsize) . ' )</label>';
                            $radio .= '    <a target="xpwiki_dump" href="' . $this->cont['HOME_URL'] . '?cmd=dump&amp;act=download&amp;file=' . rawurlencode($tar) . '"' . $t_dl . '>' . $image . '</a><br />' . "\n";
                        }
                    }
                }
                $data .= <<<EOD
   <p>
{$radio}
   </p>
EOD;
            } else {
                $data .= <<<EOD
   <p>{$this->msg['file_notfound']}</p>
EOD;
            }
            $data .= <<<EOD

  </div>
  <p>
  <input type="submit" name="ok" value="{$this->msg['do_restore']}" />
  <input type="checkbox" name="show_sql" id="_p_dump_show_sql" value="1" /><label for="_p_dump_show_sql"> {$this->msg['show_sql']}</label>
  <br />
  {$this->msg['click_once']}
  </p>
 </div>
</form>
EOD;
        }
        return $data;
    }