Simple Groupware PHP Cross Reference Groupware Applications

Source: /src/modules/lib/pmwiki.php - 123 lines - 5074 bytes - Summary - Text - Print

   1  <?php
   2      /**************************************************************************\
   3      * Simple Groupware 0.743                                                   *
   4      * http://www.simple-groupware.de                                           *
   5      * Copyright (C) 2002-2012 by Thomas Bley                                   *
   6      * ------------------------------------------------------------------------ *
   7      *  This program is free software; you can redistribute it and/or           *
   8      *  modify it under the terms of the GNU General Public License Version 2   *
   9      *  as published by the Free Software Foundation; only version 2            *
  10      *  of the License, no later version.                                       *
  11      *                                                                          *
  12      *  This program is distributed in the hope that it will be useful,         *
  13      *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  14      *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
  15      *  GNU General Public License for more details.                            *
  16      *                                                                          *
  17      *  You should have received a copy of the GNU General Public License       *
  18      *  Version 2 along with this program; if not, write to the Free Software   *
  19      *  Foundation, Inc., 59 Temple Place - Suite 330, Boston,                  *
  20      *  MA  02111-1307, USA.                                                    *
  21      \**************************************************************************/
  22  
  23  class lib_pmwiki extends lib_default {
  24  
  25  static function count($path,$where,$vars,$mfolder) {
  26    if (sys_allowedpath($path)!="") return 0;
  27    $count = 0;
  28    if (is_dir($path) and $dh = opendir($path)) {
  29      while (($file = readdir($dh)) !== false) {
  30        if (is_dir($path.$file) or $file[0]=="." or strpos($file,".GroupAttributes")) continue;
  31        $count++;
  32      }
  33    } else {
  34      sys_warning("{t}Access denied.{/t}");
  35    }
  36    return $count;
  37  }
  38  
  39  static function select($path,$fields,$where,$order,$limit,$vars,$mfolder) {
  40    if (sys_allowedpath($path)!="") return array();
  41    $file_array = array();
  42    if (!$handle = @opendir($path)) return array();
  43    while (false !== ($file = readdir($handle))) {
  44      if (is_dir($path.$file) or $file[0]=='.' or strpos($file,".GroupAttributes")) continue;
  45      $file_array[]=$file;
  46    }
  47    closedir($handle);
  48  
  49    $GLOBALS["WikiLibDirs"] = array(new PageStore());
  50    $rows = array();
  51    foreach ($file_array as $filename) {
  52      $data = stat($path.$filename);
  53      $row = array();
  54      foreach ($fields as $field) {
  55        switch ($field) {
  56          case "filedata":
  57          case "id": $row[$field] = $path.$filename; break;
  58          case "folder": $row[$field] = $path; break;
  59          case "pagename":
  60          case "searchcontent": $row[$field] = $filename; break;
  61          case "created": $row[$field] = $data["ctime"]; break;
  62          case "lastmodified": $row[$field] = $data["mtime"]; break;
  63          case "lastmodifiedby": $row[$field] = ""; break;
  64          default: $row[$field] = ""; break;
  65        }
  66      }
  67      if (sys_select_where($row,$where,$vars)) $rows[] = $row;
  68    }
  69    $rows = sys_select($rows,$order,$limit,$fields);
  70    if (count($rows)>0) {
  71      foreach ($rows as $key=>$row) {
  72        $meta = self::_parse_pmwiki_file($row["id"]);
  73        $meta["history"] = "";
  74        foreach ($meta as $mkey=>$mval) {
  75          if (strpos($mkey,":")) {
  76            $mkey_arr = explode(":",$mkey);
  77            if ($mkey_arr[0]=="author") {
  78              $meta["history"] .= "\n".sprintf("{t}Item edited (%s) by %s at %s{/t}\n","{t}Content{/t}",$mval,sys_date("{t}m/d/y g:i:s a{/t}",$mkey_arr[1]))."\n";
  79            }
  80            if ($mkey_arr[0]=="diff") $meta["history"] .= $mval."\n";
  81            if ($mkey_arr[0]=="csum") $meta["history"] .= "Change summary: ".$mval."\n";
  82            unset($meta[$mkey]);
  83          }
  84        }
  85        $meta["history"] = preg_replace(array("/(^< )/ms","/(^> )/ms"),array("- ","+ "),$meta["history"]);
  86        foreach ($meta as $mkey=>$mval) if (in_array($mkey,$fields)) $rows[$key][$mkey] = $mval;
  87        $rows[$key]["title"] = modify::htmlunquote($rows[$key]["title"]);
  88      }
  89    }
  90    return $rows;
  91  }
  92  
  93  // Copyright (C) 2001-2007 Patrick R. Michaud (pmichaud  pobox.com)
  94  function _parse_pmwiki_file($pagefile) {
  95    if (sys_allowedpath(dirname($pagefile))!="") return array();
  96    $page = array();
  97    if (($fp=@fopen($pagefile, "r"))) {
  98      $newline = '';
  99      $urlencoded = false;
 100      while (!feof($fp)) {
 101        $line = fgets($fp, 8192);
 102        while (substr($line, -1, 1) != "\n" && !feof($fp)) $line .= fgets($fp, 8192);
 103        $line = rtrim($line);
 104        if ($urlencoded) $line = urldecode(str_replace('+', '%2b', $line));
 105        @list($k,$v) = explode('=', $line, 2);
 106        if (!$k) continue;
 107        if ($k == 'version') { 
 108          $urlencoded = (strpos($v, 'urlencoded=1') !== false); 
 109          if (strpos($v, 'pmwiki-0.')!==false) $newline="\262";
 110        }
 111        if ($k == 'newline') { $newline = $v; continue; }
 112        if ($newline) $v = str_replace($newline, "\n", $v);
 113        if ($k=="text") $k = "data";
 114        if ($k=="summary") $k = "description";
 115        $page[$k] = $v;
 116      }
 117      fclose($fp);
 118    } else {
 119      sys_warning(sprintf("{t}Cannot read the file %s.{/t}",$pagefile));
 120    }
 121    return $page;
 122  }
 123  }

title

Description

title

Description

title

Description

title

title

Body