2 rcs_id('$Id: UserPreferences.php,v 1.11 2003-09-19 22:01:19 carstenklapp Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.
28 class WikiPlugin_UserPreferences
34 return _("UserPreferences");
37 function getVersion() {
38 return preg_replace("/[Revision: $]/", '',
39 "\$Revision: 1.11 $");
42 function getDefaultArguments() {
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);
52 $userid = $user->_userid;
55 array('userid' => $userid, // current or the one from the SubPage
56 'changePass' => $user->mayChangePassword(),
59 'notifyPages' => true,
60 'editAreaSize' => true,
63 'lang' => DEFAULT_LANGUAGE,
64 'relativeDates' => true
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;
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);
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'));
89 // Fixme: How to update the Theme? Correct update?
90 $num = $request->_user->SetPreferences($pref);
92 $errmsg = _("No changes.");
94 $errmsg = fmt("%d UserPreferences fields successfully updated.", $num);
96 $args['errmsg'] = HTML(HTML::h2($errmsg), HTML::hr());
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);
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);
113 $args['available_themes'] = $available_themes;
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);
121 while($entry = $dir->read()) {
122 if (is_dir($dir_root.$entry)
123 && (substr($entry,0,1) != '.')
125 && $entry != 'CVS') {
126 array_push($available_languages, $entry);
131 $args['available_languages'] = $available_languages;
133 return Template('userprefs', $args);
135 return $user->PrintLoginForm ($request, $args, false, false);
140 // $Log: not supported by cvs2svn $
141 // Revision 1.10 2003/09/13 21:57:26 carstenklapp
142 // Reformatting only.
144 // Revision 1.9 2003/09/13 21:53:41 carstenklapp
145 // Added lang and theme arguments, getVersion(), copyright and cvs log.
153 // c-hanging-comment-ender-p: nil
154 // indent-tabs-mode: nil