]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/wikilens/Utils.php
Activated Id substitution for Subversion
[SourceForge/phpwiki.git] / lib / wikilens / Utils.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  Copyright 2004 Mike Cassano
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  */
25
26 function addPageTextData($user, $dbi, $new_data, $START_DELIM, $DELIM) {
27     // This is largely lifted from the TranslateText plugin, which performs a
28     // similar set of functions (retrieves a user's homepage, modifies it 
29     // progmatically, and saves the changes)
30     $homepage = $user->_HomePagehandle;
31     $transpagename = $homepage->getName();
32     $page    = $dbi->getPage($transpagename);
33     $current = $page->getCurrentRevision();
34     $version = $current->getVersion();
35     if ($version) {
36         $text = $current->getPackedContent() . "\n";
37         $meta = $current->_data;
38     } else {
39         $text = '';
40         $meta = array('markup' => 2.0,
41                       'author' => $user->getId());
42     }
43
44     // add new data to the appropriate line
45     if(preg_match('/^' . preg_quote($START_DELIM) . '/', $text)) {
46         // need multiline modifier to match EOL correctly
47         $text = preg_replace('/(^' . preg_quote($START_DELIM) . '.*)$/m', 
48                              '$1' . $DELIM . $new_data, $text);
49     } else {
50         // handle case where the line does not yet exist
51         $text .= "\n" . $START_DELIM . $new_data . "\n";
52     }
53
54     // advance version counter, save
55     $page->save($text, $version + 1, $meta);
56 }
57  
58 function getMembers($groupName, $dbi, $START_DELIM = false, $DELIM = ",") {
59     if (!$START_DELIM) $START_DELIM = _("Members:");    
60     return getPageTextData($groupName, $dbi, $START_DELIM, $DELIM);     
61 }
62
63 function getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM) {
64     if (is_object($fromUser))
65         $fromUser = $fromUser->getId();
66     if ($fromUser == "")
67         return "";
68     $userPage = $dbi->getPage($fromUser);
69     $transformed = $userPage->getCurrentRevision();
70     $pageArray = $transformed->getContent();
71     $p = -1;
72     for ($i = 0; $i < count($pageArray); $i++){
73         if($pageArray[$i] != ""){
74             if(!((strpos($pageArray[$i], $START_DELIM)) === FALSE)){
75                 $p = $i;
76                 break;
77             }   
78         }
79     }
80     $retArray = array();
81     if ($p >= 0){
82         $singles = $pageArray[$p];
83         $singles = substr($singles, strpos($singles, $START_DELIM) + strlen($START_DELIM));
84         
85         $retArray = split($DELIM, $singles);
86     }    
87     for ($i = 0; $i < count($retArray); $i++) {
88         $retArray[$i] = trim($retArray[$i]);
89     }
90     //$retArray = array_filter($retArray, "notEmptyName");
91     $retArray = array_unique($retArray);
92
93     return $retArray;
94 }
95
96 function notEmptyName($var) {
97     return $var != "";
98 }
99
100 // $Log: not supported by cvs2svn $
101 // Revision 1.1  2004/06/18 14:42:17  rurban
102 // added wikilens libs (not yet merged good enough, some work for DanFr)
103 // 
104
105 // Local Variables:
106 // mode: php
107 // tab-width: 8
108 // c-basic-offset: 4
109 // c-hanging-comment-ender-p: nil
110 // indent-tabs-mode: nil
111 // End:
112 ?>