]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/UserPreferences.php
* changed stored pref representation as before.
[SourceForge/phpwiki.git] / lib / plugin / UserPreferences.php
1 <?php // -*-php-*-
2 rcs_id('$Id: UserPreferences.php,v 1.14 2004-01-26 09:18:00 rurban Exp $');
3 /**
4  Copyright 2001, 2002, 2003 $ThePhpWikiProgrammingTeam
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  * Plugin to allow any user to adjust his own preferences.
25  * This must be used in the page "UserPreferences".
26  * Prefs are stored in metadata within the user's home page or in a cookie.
27  */
28 class WikiPlugin_UserPreferences
29 extends WikiPlugin
30 {
31     var $bool_args;
32
33     function getName () {
34         return _("UserPreferences");
35     }
36
37     function getVersion() {
38         return preg_replace("/[Revision: $]/", '',
39                             "\$Revision: 1.14 $");
40     }
41
42     function getDefaultArguments() {
43         global $request;
44         $pagename = $request->getArg('pagename');
45         // take current userid from request
46         $user = $request->getUser();
47         $userid = $user->UserName();
48         $prefs = $user->getPreferences();
49         // return defaults established by the UserPreferences class
50         return $prefs;
51     }
52
53     function run($dbi, $argstr, $request) {
54         $args = $this->getArgs($argstr, $request);
55         $user = &$request->getUser();
56         if (! $request->isActionPage($request->getArg('pagename'))) {
57             $no_args = $this->getDefaultArguments();
58 // ?
59 //            foreach ($no_args as $key => $value) {
60 //                $no_args[$value] = false;
61 //            }
62             $no_args['errmsg'] = HTML(HTML::h2(_("Error: The user HomePage must be a valid WikiWord. Sorry, UserPreferences cannot be saved."),HTML::hr()));
63             $no_args['isForm'] = false;
64             return Template('userprefs', $no_args);
65         }
66         $userid = $user->UserName();
67         if (((defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN && $user->isSignedIn())
68              || $user->isAuthenticated())
69             && !empty($userid)) {
70             $pref = $user->getPreferences();
71             //trigger_error("DEBUG: reading prefs from getPreferences".print_r($pref));
72  
73             if ($request->isPost()) {
74                 //trigger_error("DEBUG: request is post");
75                 if ($request->_prefs) {
76                     // replace only changed prefs in $pref with those from request
77                     $rp = $request->_prefs->_prefs;
78                     //trigger_error("DEBUG: reading prefs from request".print_r($rp));
79                     //trigger_error("DEBUG: writing prefs with setPreferences".print_r($pref));
80                     $num = $user->setPreferences(new UserPreferences($rp));
81                     if (!$num) {
82                         $errmsg = _("No changes.");
83                     }
84                     else {
85                         $errmsg = fmt("%d UserPreferences fields successfully updated.", $num);
86                     }
87                     $args['errmsg'] = HTML(HTML::h2($errmsg), HTML::hr());
88                 }
89             }
90             $available_themes = array(); 
91             $dir_root = 'themes/';
92             if (defined('PHPWIKI_DIR'))
93                 $dir_root = PHPWIKI_DIR . "/$dir_root";
94             $dir = dir($dir_root);
95             if ($dir) {
96                 while($entry = $dir->read()) {
97                     if (is_dir($dir_root.$entry)
98                         && (substr($entry,0,1) != '.')
99                         && $entry != 'CVS') {
100                         array_push($available_themes, $entry);
101                     }
102                 }
103                 $dir->close();
104             }
105             $args['available_themes'] = $available_themes;
106
107             $available_languages = array('en');
108             $dir_root = 'locale/';
109             if (defined('PHPWIKI_DIR'))
110                 $dir_root = PHPWIKI_DIR . "/$dir_root";
111             $dir = dir($dir_root);
112             if ($dir) {
113                 while($entry = $dir->read()) {
114                     if (is_dir($dir_root.$entry)
115                         && (substr($entry,0,1) != '.')
116                         && $entry != 'po'
117                         && $entry != 'CVS') {
118                         array_push($available_languages, $entry);
119                     }
120                 }
121                 $dir->close();
122             }
123             $args['available_languages'] = $available_languages;
124
125             return Template('userprefs', $args);
126         }
127         else {
128             return $user->PrintLoginForm ($request, $args, false, false);
129         }
130     }
131 };
132
133 // $Log: not supported by cvs2svn $
134 // Revision 1.13  2003/12/04 20:27:00  carstenklapp
135 // Use the API.
136 //
137 // Revision 1.12  2003/12/01 22:21:33  carstenklapp
138 // Bugfix: UserPreferences are no longer clobbered when signing in after
139 // the previous session has ended (i.e. user closed browser then signed
140 // in again). This is still a bit of a mess, and the preferences do not
141 // take effect until the next page browse/link has been clicked.
142 //
143 // Revision 1.11  2003/09/19 22:01:19  carstenklapp
144 // BOGO users allowed preferences too when ALLOW_BOGO_LOGIN == true.
145 //
146 // Revision 1.10  2003/09/13 21:57:26  carstenklapp
147 // Reformatting only.
148 //
149 // Revision 1.9  2003/09/13 21:53:41  carstenklapp
150 // Added lang and theme arguments, getVersion(), copyright and cvs log.
151 //
152
153 // For emacs users
154 // Local Variables:
155 // mode: php
156 // tab-width: 8
157 // c-basic-offset: 4
158 // c-hanging-comment-ender-p: nil
159 // indent-tabs-mode: nil
160 // End:
161 ?>