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

  1. <?php
  2. // $Id: category.php,v 1.1 2004/01/12 22:14:04 comsubvie Exp $
  3.  
  4. require('parse/main.php');
  5.  
  6. // Add a page to a list of categories.
  7. function add_to_category($page, $catlist)
  8. {
  9.   global $pagestore, $Entity, $UserName, $REMOTE_ADDR, $FlgChr;
  10.  
  11.   // Parse the category list for category names.
  12.   $parsed = parseText($catlist, array('parse_freelink', 'parse_wikiname'), '');
  13.   $pagenames = array();
  14.   preg_replace('/' . $FlgChr . '!?(\\d+)' . $FlgChr . '/e',
  15.                '$pagenames[]=$Entity[\\1][1]', $parsed);
  16.  
  17.   // Add it to each category.
  18.   foreach($pagenames as $category)
  19.   {
  20.     $pg = $pagestore->page($category);
  21.  
  22.     $pg->read();
  23.     if($pg->exists)
  24.     {
  25.       if(preg_match('/\\[\\[!(.*)\\]\\]/', $pg->text, $match))
  26.       {
  27.         $parsed = parseText($match[1], array('parse_freelink', 
  28.                                              'parse_wikiname'), '');
  29.         $categorypages = array();
  30.         preg_replace('/' . $FlgChr . '!?(\\d+)' . $FlgChr . '/e',
  31.                '$categorypages[$Entity[\\1][1]]=1', $parsed);
  32.  
  33.         if (!$categorypages[$page] ) 
  34.         {
  35.           if(validate_page($page) == 2)
  36.             { $page = '((' . $page . '))'; }
  37.                   
  38.           $pg->text = preg_replace('/(\\[\\[!.*)\\]\\]/',
  39.                                    "\\1 $page]]", $pg->text);
  40.         }
  41.         else
  42.           { continue; }
  43.       }
  44.       else 
  45.       {  
  46.         if(validate_page($page) == 2)
  47.           { $page = '((' . $page . '))'; }
  48.         $pg->text = $pg->text . "\n[[! $page]]\n"; 
  49.       }
  50.  
  51.       $pg->text = str_replace("\\", "\\\\", $pg->text);
  52.       $pg->text = str_replace("'", "\\'", $pg->text);
  53.      
  54.       $pg->version++;
  55.       $pg->comment  = '';
  56.       $pg->hostname = gethostbyaddr($REMOTE_ADDR);
  57.       $pg->username = $UserName;
  58.  
  59.       $pg->write();
  60.     }
  61.   }
  62. }
  63. ?>
  64.