4 * Copyright 2004 Mike Cassano
6 * This file is part of PhpWiki.
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.
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.
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.
23 function addPageTextData($user, $dbi, $new_data, $START_DELIM, $DELIM)
25 // This is largely lifted from the TranslateText plugin, which performs a
26 // similar set of functions (retrieves a user's homepage, modifies it
27 // progmatically, and saves the changes)
28 $homepage = $user->_HomePagehandle;
29 $transpagename = $homepage->getName();
30 $page = $dbi->getPage($transpagename);
31 $current = $page->getCurrentRevision();
32 $version = $current->getVersion();
34 $text = $current->getPackedContent() . "\n";
35 $meta = $current->_data;
38 $meta = array('markup' => 2.0,
39 'author' => $user->getId());
42 // add new data to the appropriate line
43 if (preg_match('/^' . preg_quote($START_DELIM) . '/', $text)) {
44 // need multiline modifier to match EOL correctly
45 $text = preg_replace('/(^' . preg_quote($START_DELIM) . '.*)$/m',
46 '$1' . $DELIM . $new_data, $text);
48 // handle case where the line does not yet exist
49 $text .= "\n" . $START_DELIM . $new_data . "\n";
52 // advance version counter, save
53 $page->save($text, $version + 1, $meta);
56 function getMembers($groupName, $dbi, $START_DELIM = false, $DELIM = ",")
58 if (!$START_DELIM) $START_DELIM = _("Members:");
59 return getPageTextData($groupName, $dbi, $START_DELIM, $DELIM);
62 function getPageTextData($fromUser, $dbi, $START_DELIM, $DELIM)
64 if (is_object($fromUser))
65 $fromUser = $fromUser->getId();
68 $userPage = $dbi->getPage($fromUser);
69 $transformed = $userPage->getCurrentRevision();
70 $pageArray = $transformed->getContent();
72 for ($i = 0; $i < count($pageArray); $i++) {
73 if ($pageArray[$i] != "") {
74 if (!((strpos($pageArray[$i], $START_DELIM)) === FALSE)) {
82 $singles = $pageArray[$p];
83 $singles = substr($singles, strpos($singles, $START_DELIM) + strlen($START_DELIM));
85 $retArray = explode($DELIM, $singles);
87 for ($i = 0; $i < count($retArray); $i++) {
88 $retArray[$i] = trim($retArray[$i]);
90 //$retArray = array_filter($retArray, "notEmptyName");
91 $retArray = array_unique($retArray);
96 function notEmptyName($var)
105 // c-hanging-comment-ender-p: nil
106 // indent-tabs-mode: nil