]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/wikilens/Utils.php
New FSF address
[SourceForge/phpwiki.git] / lib / wikilens / Utils.php
1 <?php // -*-php-*-
2 // $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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 function addPageTextData($user, $dbi, $new_data, $START_DELIM, $DELIM) {
24     // This is largely lifted from the TranslateText plugin, which performs a
25     // similar set of functions (retrieves a user's homepage, modifies it
26     // progmatically, and saves the changes)
27     $homepage = $user->_HomePagehandle;
28     $transpagename = $homepage->getName();
29     $page    = $dbi->getPage($transpagename);
30     $current = $page->getCurrentRevision();
31     $version = $current->getVersion();
32     if ($version) {
33         $text = $current->getPackedContent() . "\n";
34         $meta = $current->_data;
35     } else {
36         $text = '';
37         $meta = array('markup' => 2.0,
38                       'author' => $user->getId());
39     }
40
41     // add new data to the appropriate line
42     if(preg_match('/^' . preg_quote($START_DELIM) . '/', $text)) {
43         // need multiline modifier to match EOL correctly
44         $text = preg_replace('/(^' . preg_quote($START_DELIM) . '.*)$/m',
45                              '$1' . $DELIM . $new_data, $text);
46     } else {
47         // handle case where the line does not yet exist
48         $text .= "\n" . $START_DELIM . $new_data . "\n";
49     }
50
51     // advance version counter, save
52     $page->save($text, $version + 1, $meta);
53 }
54
55 function getMembers($groupName, $dbi, $START_DELIM = false, $DELIM = ",") {
56     if (!$START_DELIM) $START_DELIM = _("Members:");
57     return getPageTextData($groupName, $dbi, $START_DELIM, $DELIM);
58 }
59
60 function getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM) {
61     if (is_object($fromUser))
62         $fromUser = $fromUser->getId();
63     if ($fromUser == "")
64         return "";
65     $userPage = $dbi->getPage($fromUser);
66     $transformed = $userPage->getCurrentRevision();
67     $pageArray = $transformed->getContent();
68     $p = -1;
69     for ($i = 0; $i < count($pageArray); $i++){
70         if($pageArray[$i] != ""){
71             if(!((strpos($pageArray[$i], $START_DELIM)) === FALSE)){
72                 $p = $i;
73                 break;
74             }
75         }
76     }
77     $retArray = array();
78     if ($p >= 0){
79         $singles = $pageArray[$p];
80         $singles = substr($singles, strpos($singles, $START_DELIM) + strlen($START_DELIM));
81
82         $retArray = explode($DELIM, $singles);
83     }
84     for ($i = 0; $i < count($retArray); $i++) {
85         $retArray[$i] = trim($retArray[$i]);
86     }
87     //$retArray = array_filter($retArray, "notEmptyName");
88     $retArray = array_unique($retArray);
89
90     return $retArray;
91 }
92
93 function notEmptyName($var) {
94     return $var != "";
95 }
96
97 // Local Variables:
98 // mode: php
99 // tab-width: 8
100 // c-basic-offset: 4
101 // c-hanging-comment-ender-p: nil
102 // indent-tabs-mode: nil
103 // End:
104 ?>