[ PHPXref.com ] [ Generated: Sun Jul 20 20:08:34 2008 ] [ PukiWiki 1.4.6 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/plugin/ -> backup.inc.php (source)

   1  <?php
   2  // PukiWiki - Yet another WikiWikiWeb clone.
   3  // $Id: backup.inc.php,v 1.23 2005/09/22 13:45:02 henoheno Exp $
   4  //
   5  // Backup plugin
   6  
   7  // Prohibit rendering old wiki texts (suppresses load, transfer rate, and security risk)
   8  define('PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING', PKWK_SAFE_MODE || PKWK_OPTIMISE);
   9  
  10  function plugin_backup_action()
  11  {
  12      global $vars, $do_backup, $hr;
  13      global $_msg_backuplist, $_msg_diff, $_msg_nowdiff, $_msg_source, $_msg_backup;
  14      global $_msg_view, $_msg_goto, $_msg_deleted;
  15      global $_title_backupdiff, $_title_backupnowdiff, $_title_backupsource;
  16      global $_title_backup, $_title_pagebackuplist, $_title_backuplist;
  17  
  18      if (! $do_backup) return;
  19  
  20      $page = isset($vars['page']) ? $vars['page']  : '';
  21      if ($page == '') return array('msg'=>$_title_backuplist, 'body'=>plugin_backup_get_list_all());
  22  
  23      check_readable($page, true, true);
  24      $s_page = htmlspecialchars($page);
  25      $r_page = rawurlencode($page);
  26  
  27      $action = isset($vars['action']) ? $vars['action'] : '';
  28      if ($action == 'delete') return plugin_backup_delete($page);
  29  
  30      $s_action = $r_action = '';
  31      if ($action != '') {
  32          $s_action = htmlspecialchars($action);
  33          $r_action = rawurlencode($action);
  34      }
  35  
  36      $s_age  = (isset($vars['age']) && is_numeric($vars['age'])) ? $vars['age'] : 0;
  37      if ($s_age == 0) return array( 'msg'=>$_title_pagebackuplist, 'body'=>plugin_backup_get_list($page));
  38  
  39      $script = get_script_uri();
  40  
  41      $body  = '<ul>' . "\n";
  42      $body .= ' <li><a href="' . $script . '?cmd=backup">' . $_msg_backuplist . '</a></li>' ."\n";
  43  
  44      $href    = $script . '?cmd=backup&amp;page=' . $r_page . '&amp;age=' . $s_age;
  45      $is_page = is_page($page);
  46  
  47      if ($is_page && $action != 'diff')
  48          $body .= ' <li>' . str_replace('$1', '<a href="' . $href .
  49              '&amp;action=diff">' . $_msg_diff . '</a>',
  50              $_msg_view) . '</li>' . "\n";
  51  
  52      if ($is_page && $action != 'nowdiff')
  53          $body .= ' <li>' . str_replace('$1', '<a href="' . $href .
  54              '&amp;action=nowdiff">' . $_msg_nowdiff . '</a>',
  55              $_msg_view) . '</li>' . "\n";
  56  
  57      if ($action != 'source')
  58          $body .= ' <li>' . str_replace('$1', '<a href="' . $href .
  59              '&amp;action=source">' . $_msg_source . '</a>',
  60              $_msg_view) . '</li>' . "\n";
  61  
  62      if ($action)
  63          $body .= ' <li>' . str_replace('$1', '<a href="' . $href .
  64              '">' . $_msg_backup . '</a>',
  65              $_msg_view) . '</li>' . "\n";
  66  
  67      if ($is_page) {
  68          $body .= ' <li>' . str_replace('$1',
  69              '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>',
  70              $_msg_goto) . "\n";
  71      } else {
  72          $body .= ' <li>' . str_replace('$1', $s_page, $_msg_deleted) . "\n";
  73      }
  74  
  75      $backups = get_backup($page);
  76      if (! empty($backups)) {
  77          $body .= '  <ul>' . "\n";
  78          foreach($backups as $age => $val) {
  79              $date = format_date($val['time'], TRUE);
  80              $body .= ($age == $s_age) ?
  81                  '   <li><em>' . $age . ' ' . $date . '</em></li>' . "\n" :
  82                  '   <li><a href="' . $script . '?cmd=backup&amp;action=' .
  83                  $r_action . '&amp;page=' . $r_page . '&amp;age=' . $age .
  84                  '">' . $age . ' ' . $date . '</a></li>' . "\n";
  85          }
  86          $body .= '  </ul>' . "\n";
  87      }
  88      $body .= ' </li>' . "\n";
  89      $body .= '</ul>'  . "\n";
  90  
  91      if ($action == 'diff') {
  92          $title = & $_title_backupdiff;
  93          $old = ($s_age > 1) ? join('', $backups[$s_age - 1]['data']) : '';
  94          $cur = join('', $backups[$s_age]['data']);
  95          $body .= plugin_backup_diff(do_diff($old, $cur));
  96      } else if ($s_action == 'nowdiff') {
  97          $title = & $_title_backupnowdiff;
  98          $old = join('', $backups[$s_age]['data']);
  99          $cur = join('', get_source($page));
 100          $body .= plugin_backup_diff(do_diff($old, $cur));
 101      } else if ($s_action == 'source') {
 102          $title = & $_title_backupsource;
 103          $body .= '<pre>' . htmlspecialchars(join('', $backups[$s_age]['data'])) .
 104              '</pre>' . "\n";
 105      } else {
 106          if (PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) {
 107              die_message('This feature is prohibited');
 108          } else {
 109              $title = & $_title_backup;
 110              $body .= $hr . "\n" .
 111                  drop_submit(convert_html($backups[$s_age]['data']));
 112          }
 113      }
 114  
 115      return array('msg'=>str_replace('$2', $s_age, $title), 'body'=>$body);
 116  }
 117  
 118  // Delete backup
 119  function plugin_backup_delete($page)
 120  {
 121      global $vars, $_title_backup_delete, $_title_pagebackuplist, $_msg_backup_deleted;
 122      global $_msg_backup_adminpass, $_btn_delete, $_msg_invalidpass;
 123  
 124      if (! _backup_file_exists($page))
 125          return array('msg'=>$_title_pagebackuplist, 'body'=>plugin_backup_get_list($page)); // Say "is not found"
 126  
 127      $body = '';
 128      if (isset($vars['pass'])) {
 129          if (pkwk_login($vars['pass'])) {
 130              _backup_delete($page);
 131              return array(
 132                  'msg'  => $_title_backup_delete,
 133                  'body' => str_replace('$1', make_pagelink($page), $_msg_backup_deleted)
 134              );
 135          } else {
 136              $body = '<p><strong>' . $_msg_invalidpass . '</strong></p>' . "\n";
 137          }
 138      }
 139  
 140      $script = get_script_uri();
 141      $s_page = htmlspecialchars($page);
 142      $body .= <<<EOD
 143  <p>$_msg_backup_adminpass</p>
 144  <form action="$script" method="post">
 145   <div>
 146    <input type="hidden"   name="cmd"    value="backup" />
 147    <input type="hidden"   name="page"   value="$s_page" />
 148    <input type="hidden"   name="action" value="delete" />
 149    <input type="password" name="pass"   size="12" />
 150    <input type="submit"   name="ok"     value="$_btn_delete" />
 151   </div>
 152  </form>
 153  EOD;
 154      return    array('msg'=>$_title_backup_delete, 'body'=>$body);
 155  }
 156  
 157  function plugin_backup_diff($str)
 158  {
 159      global $_msg_addline, $_msg_delline,$hr;
 160  
 161      $str = htmlspecialchars($str);
 162      $str = preg_replace('/^(\-)(.*)$/m', '<span class="diff_removed"> $2</span>', $str);
 163      $str = preg_replace('/^(\+)(.*)$/m', '<span class="diff_added"> $2</span>', $str);
 164      $str = trim($str);
 165      $str = <<<EOD
 166  $hr
 167  <ul>
 168   <li>$_msg_addline</li>
 169   <li>$_msg_delline</li>
 170  </ul>
 171  <pre>$str</pre>
 172  EOD;
 173  
 174      return $str;
 175  }
 176  
 177  function plugin_backup_get_list($page)
 178  {
 179      global $_msg_backuplist, $_msg_diff, $_msg_nowdiff, $_msg_source, $_msg_nobackup;
 180      global $_title_backup_delete;
 181  
 182      $script = get_script_uri();
 183      $r_page = rawurlencode($page);
 184      $s_page = htmlspecialchars($page);
 185      $retval = array();
 186      $retval[0] = <<<EOD
 187  <ul>
 188   <li><a href="$script?cmd=backup">$_msg_backuplist</a>
 189    <ul>
 190  EOD;
 191      $retval[1] = "\n";
 192      $retval[2] = <<<EOD
 193    </ul>
 194   </li>
 195  </ul>
 196  EOD;
 197  
 198      $backups = _backup_file_exists($page) ? get_backup($page) : array();
 199      if (empty($backups)) {
 200          $msg = str_replace('$1', make_pagelink($page), $_msg_nobackup);
 201          $retval[1] .= '   <li>' . $msg . '</li>' . "\n";
 202          return join('', $retval);
 203      }
 204  
 205      if (! PKWK_READONLY) {
 206          $retval[1] .= '   <li><a href="' . $script . '?cmd=backup&amp;action=delete&amp;page=' .
 207              $r_page . '">';
 208          $retval[1] .= str_replace('$1', $s_page, $_title_backup_delete);
 209          $retval[1] .= '</a></li>' . "\n";
 210      }
 211  
 212      $href = $script . '?cmd=backup&amp;page=' . $r_page . '&amp;age=';
 213      $_anchor_from = $_anchor_to   = '';
 214      foreach ($backups as $age=>$data) {
 215          if (! PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) {
 216              $_anchor_from = '<a href="' . $href . $age . '">';
 217              $_anchor_to   = '</a>';
 218          }
 219          $date = format_date($data['time'], TRUE);
 220          $retval[1] .= <<<EOD
 221     <li>$_anchor_from$age $date$_anchor_to
 222       [ <a href="$href$age&amp;action=diff">$_msg_diff</a>
 223       | <a href="$href$age&amp;action=nowdiff">$_msg_nowdiff</a>
 224       | <a href="$href$age&amp;action=source">$_msg_source</a>
 225       ]
 226     </li>
 227  EOD;
 228      }
 229  
 230      return join('', $retval);
 231  }
 232  
 233  // List for all pages
 234  function plugin_backup_get_list_all($withfilename = FALSE)
 235  {
 236      global $cantedit;
 237  
 238      $pages = array_diff(get_existpages(BACKUP_DIR, BACKUP_EXT), $cantedit);
 239  
 240      if (empty($pages)) {
 241          return '';
 242      } else {
 243          return page_list($pages, 'backup', $withfilename);
 244      }
 245  }
 246  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]