]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/UserPreferences.php
Added lang and theme arguments, getVersion(), copyright and cvs log.
[SourceForge/phpwiki.git] / lib / plugin / UserPreferences.php
1 <?php // -*-php-*-
2 rcs_id('$Id: UserPreferences.php,v 1.9 2003-09-13 21:53:41 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.9 $");
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 array('userid'           => $userid, // current or the one from the SubPage
55                      'changePass'       => $user->mayChangePassword(),
56                      'appearance'       => true,
57                      'email'            => true,
58                      'notifyPages'      => true,
59                      'editAreaSize'     => true,
60                      'timeOffset'       => true,
61                      'theme'         => THEME,
62                      'lang'          => DEFAULT_LANGUAGE,
63                      'relativeDates'    => true
64                      );
65     }
66    
67     function run($dbi, $argstr, $request) {
68         $args = $this->getArgs($argstr, $request);
69         $user = &$request->getUser();
70         if (! $request->isActionPage($request->getArg('pagename'))) {
71             $no_args = $this->getDefaultArguments();
72             foreach ($no_args as $key => $value) {
73                 $no_args[$value] = false;
74             }
75             $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()));
76             $no_args['isForm'] = false;
77             return Template('userprefs', $no_args);
78         }
79         if ($user->isAuthenticated() and $args['userid'] == $user->_userid) {
80             if ($request->isPost()) {
81                 if ($request->_prefs) {
82                   $pref = $request->_prefs;
83                 } else { // hmm. already handled somewhere else...
84                   $pref = new UserPreferences($request->getArg('pref'));
85                 }
86                 // Fixme: How to update the Theme? Correct update?
87                 $num = $request->_user->SetPreferences($pref);
88                 if (!$num) {
89                     $errmsg = _("No changes.");
90                 } else {
91                     $errmsg = fmt("%d UserPreferences fields successfully updated.", $num);
92                 }
93                 $args['errmsg'] = HTML(HTML::h2($errmsg),HTML::hr());
94             }
95             $available_themes = array(); 
96             $dir_root = 'themes/';
97             if (defined('PHPWIKI_DIR'))
98                 $dir_root = PHPWIKI_DIR . "/$dir_root";
99             $dir = dir($dir_root);
100             if ($dir) {
101                 while($entry = $dir->read()) {
102                     if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and 
103                         $entry!='CVS') {
104                         array_push($available_themes,$entry);
105                     }
106                 }
107                 $dir->close();
108             }
109             $args['available_themes'] = $available_themes;
110
111             $available_languages = array('en');
112             $dir_root = 'locale/';
113             if (defined('PHPWIKI_DIR'))
114                 $dir_root = PHPWIKI_DIR . "/$dir_root";
115             $dir = dir($dir_root);
116             if ($dir) {
117                 while($entry = $dir->read()) {
118                     if (is_dir($dir_root.$entry) and (substr($entry,0,1) != '.') and 
119                         $entry != 'po' and $entry != 'CVS') {
120                         array_push($available_languages,$entry);
121                     }
122                 }
123                 $dir->close();
124             }
125             $args['available_languages'] = $available_languages;
126
127             return Template('userprefs', $args);
128         } else {
129             return $user->PrintLoginForm ($request, $args, false, false);
130         }
131     }
132 };
133
134 // $Log: not supported by cvs2svn $
135
136 // For emacs users
137 // Local Variables:
138 // mode: php
139 // tab-width: 8
140 // c-basic-offset: 4
141 // c-hanging-comment-ender-p: nil
142 // indent-tabs-mode: nil
143 // End:
144 ?>