home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / wiki / action / save.php < prev    next >
PHP Script  |  2004-03-08  |  2KB  |  78 lines

  1. <?php
  2. // $Id: save.php,v 1.1 2004/01/12 22:14:04 comsubvie Exp $
  3.  
  4. require(TemplateDir . '/save.php');
  5. require('lib/category.php');
  6. require('parse/save.php');
  7.  
  8. // Commit an edit to the database.
  9. function action_save()
  10. {
  11.   global $pagestore, $comment, $categories, $archive;
  12.   global $Save, $page, $document, $nextver, $REMOTE_ADDR;
  13.   global $MaxPostLen, $UserName, $SaveMacroEngine;
  14.  
  15.   if(empty($Save))                      // Didn't click the save button.
  16.   {
  17.     include('action/preview.php');
  18.     action_preview();
  19.     return;
  20.   }
  21.  
  22.   $pagestore->lock();                   // Ensure atomicity.
  23.  
  24.   $pg = $pagestore->page($page);
  25.   $pg->read();
  26.  
  27.   if(!$pg->mutable)                     // Edit disallowed.
  28.     { die(ACTION_ErrorPageLocked); }
  29.  
  30.   if($pg->exists()                      // Page already exists.
  31.      && $pg->version >= $nextver        // Someone has changed it.
  32.      && $pg->hostname != gethostbyaddr($REMOTE_ADDR)  // Wasn't us.
  33.      && !$archive)                      // Not editing an archive version.
  34.   {
  35.     $pagestore->unlock();
  36.     include('action/conflict.php');
  37.     action_conflict();
  38.     return;
  39.   }
  40.  
  41.   // Silently trim string to $MaxPostLen chars.
  42.  
  43.   $document = substr($document, 0, $MaxPostLen);
  44.   $document = str_replace("\r", "", $document);
  45.  
  46.   $esc_doc = str_replace("\\", "\\\\", $document);
  47.   $esc_doc = str_replace("'", "\\'", $esc_doc);
  48.  
  49.   $comment = str_replace("\\", "\\\\", $comment);
  50.   $comment = str_replace("'", "\\'", $comment);
  51.  
  52.   $pg->text = $esc_doc;
  53.   $pg->hostname = gethostbyaddr($REMOTE_ADDR);
  54.   $pg->username = $UserName;
  55.   $pg->comment  = $comment;
  56.  
  57.   if($pg->exists)
  58.     { $pg->version++; }
  59.   else
  60.     { $pg->version = 1; }
  61.   $pg->write();
  62.  
  63.   if(!empty($categories))               // Editor asked page to be added to
  64.   {                                     //   a category or categories.
  65.     add_to_category($page, $categories);
  66.   }
  67.  
  68.   template_save(array('page' => $page,
  69.                       'text' => $document));
  70.  
  71.   // Process save macros (e.g., to define interwiki entries).
  72.   parseText($document, $SaveMacroEngine, $page);
  73.  
  74.   $pagestore->unlock();                 // End "transaction".
  75.  
  76. }
  77. ?>
  78.