]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/UserPreferences.php
BOGO users allowed preferences too when ALLOW_BOGO_LOGIN == true.
[SourceForge/phpwiki.git] / lib / plugin / UserPreferences.php
1 <?php // -*-php-*-
2 rcs_id('$Id: UserPreferences.php,v 1.11 2003-09-19 22:01:19 carstenklapp Exp $');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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" or in a subpage of a
26  * user called like HomePage/Preferences.
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.11 $");
40     }
41
42     function getDefaultArguments() {
43         global $request;
44         $pagename = $request->getArg('pagename');
45         $user = $request->getUser();
46         // for a UserPage/Prefences plugin default to this userid
47         if (isSubPage($pagename)) {
48             $pages  = explode(SUBPAGE_SEPARATOR, $pagename);
49             $userid = $pages[0];
50         } else {
51             // take current user
52             $userid = $user->_userid;
53         }
54         return
55             array('userid'  => $userid, // current or the one from the SubPage
56                   'changePass'    => $user->mayChangePassword(),
57                   'appearance'    => true,
58                   'email'         => true,
59                   'notifyPages'   => true,
60                   'editAreaSize'  => true,
61                   'timeOffset'    => true,
62                   'theme'         => THEME,
63                   'lang'          => DEFAULT_LANGUAGE,
64                   'relativeDates' => true
65                   );
66     }
67
68     function run($dbi, $argstr, $request) {
69         $args = $this->getArgs($argstr, $request);
70         $user = &$request->getUser();
71         if (! $request->isActionPage($request->getArg('pagename'))) {
72             $no_args = $this->getDefaultArguments();
73             foreach ($no_args as $key => $value) {
74                 $no_args[$value] = false;
75             }
76             $no_args['errmsg'] = HTML(HTML::h2(_("Error: The page with the UserPreferences plugin must be valid WikiWord or a Preferences subpage of the users HomePage. Sorry, UserPreferences cannot be saved."),HTML::hr()));
77             $no_args['isForm'] = false;
78             return Template('userprefs', $no_args);
79         }
80         if (((defined('ALLOW_BOGO_LOGIN') && ALLOW_BOGO_LOGIN && $user->isSignedIn())
81              || $user->isAuthenticated())
82             && $args['userid'] == $user->_userid) {
83             if ($request->isPost()) {
84                 if ($request->_prefs) {
85                     $pref = $request->_prefs;
86                 } else { // hmm. already handled somewhere else...
87                     $pref = new UserPreferences($request->getArg('pref'));
88                 }
89                 // Fixme: How to update the Theme? Correct update?
90                 $num = $request->_user->SetPreferences($pref);
91                 if (!$num) {
92                     $errmsg = _("No changes.");
93                 } else {
94                     $errmsg = fmt("%d UserPreferences fields successfully updated.", $num);
95                 }
96                 $args['errmsg'] = HTML(HTML::h2($errmsg), HTML::hr());
97             }
98             $available_themes = array(); 
99             $dir_root = 'themes/';
100             if (defined('PHPWIKI_DIR'))
101                 $dir_root = PHPWIKI_DIR . "/$dir_root";
102             $dir = dir($dir_root);
103             if ($dir) {
104                 while($entry = $dir->read()) {
105                     if (is_dir($dir_root.$entry)
106                         && (substr($entry,0,1) != '.')
107                         && $entry != 'CVS') {
108                         array_push($available_themes, $entry);
109                     }
110                 }
111                 $dir->close();
112             }
113             $args['available_themes'] = $available_themes;
114
115             $available_languages = array('en');
116             $dir_root = 'locale/';
117             if (defined('PHPWIKI_DIR'))
118                 $dir_root = PHPWIKI_DIR . "/$dir_root";
119             $dir = dir($dir_root);
120             if ($dir) {
121                 while($entry = $dir->read()) {
122                     if (is_dir($dir_root.$entry)
123                         && (substr($entry,0,1) != '.')
124                         && $entry != 'po'
125                         && $entry != 'CVS') {
126                         array_push($available_languages, $entry);
127                     }
128                 }
129                 $dir->close();
130             }
131             $args['available_languages'] = $available_languages;
132
133             return Template('userprefs', $args);
134         } else {
135             return $user->PrintLoginForm ($request, $args, false, false);
136         }
137     }
138 };
139
140 // $Log: not supported by cvs2svn $
141 // Revision 1.10  2003/09/13 21:57:26  carstenklapp
142 // Reformatting only.
143 //
144 // Revision 1.9  2003/09/13 21:53:41  carstenklapp
145 // Added lang and theme arguments, getVersion(), copyright and cvs log.
146 //
147
148 // For emacs users
149 // Local Variables:
150 // mode: php
151 // tab-width: 8
152 // c-basic-offset: 4
153 // c-hanging-comment-ender-p: nil
154 // indent-tabs-mode: nil
155 // End:
156 ?>