5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://COPYING
11 SO2
::$Page->title
= 'Options Screen';
13 if ( ! (SO2
::$User instanceof User_Authenticated
) ) {
14 SO2
::$Page->message(Page
::ERR_LOGIN
);
17 SO2
::$Page->usernav
['Theme Settings'] = 'theme';
19 // Set field size limits
20 $q = SO2
::$DB->query('SELECT COLUMN_NAME , CHARACTER_MAXIMUM_LENGTH '.
21 'FROM information_schema.COLUMNS '.
22 'WHERE TABLE_SCHEMA = "'.SO2
::$Cfg['db']['name'].'" '.
23 'AND TABLE_NAME = "users" '.
24 'AND CHARACTER_MAXIMUM_LENGTH IS NOT NULL');
25 while ( $row = $q->fetch(PDO
::FETCH_NUM
) ) {
26 $limits[$row[0]] = $row[1];
30 // function to make the SO2::$User->options checkboxes
31 function makeoptbox($n, $label, $title)
33 return "<label for='$n'><input type='checkbox' name='options[$n]' id='$n'".
34 ( SO2
::$User->getopt($n) ?
' checked="checked"' : '' ).
35 "/> $label<br/>\n<small>$title</small></label><br/>\n";
38 // function to make input textfields
39 function maketextbox($n, $l)
41 return '<input type="text" name="'.$n.'" value="'.SO2
::$User->$n.'" maxlength="'.$l.'" size="'.min(30, $l).'"/>';
44 // make the {topic,message,board}list selectboxes
46 'Messagelist' => 'msglist_layout',
47 'Messagestyle' => 'msglist_style',
48 'Topiclist' => 'topiclist_layout',
49 'Boardlist' => 'boardlist_layout',
53 foreach ( $selects as $class => $field ) {
54 $
{$field} = new HTML_Select($field, 4, SO2
::$User->$field);
56 foreach ( glob('lib/'.$class.'_*.php') as $filename ) {
57 include_once $filename;
59 preg_match('/_(.*?)\.php/', $filename, $tmp);
60 $
{$field}->add_item($tmp[1]);
65 $tz = new HTML_Select('tz', 2, SO2
::$User->tz
);
66 $tz->array_fill(timezone_identifiers_list());
69 if ( isset($_POST['submit']) ) {
72 * Check whether a $_POST value exists, is a number, and is between the minimum/maximum
74 function rangecheck($var, $min, $max, $name)
76 if ( !isset($_POST[$var]) ||
!is_numeric($_POST[$var]) ||
77 $_POST[$var] < $min ||
$_POST[$var] > $max ) {
78 throw new OutOfBoundsException(sprintf('%s must be a number between %d and %d.', $name, $min, $max));
80 return intval($_POST[$var]);
84 * Check whether a $_POST value exists and its string length is below the limit defined for it
86 function lengthcheck($var, $name)
89 if ( !isset($_POST[$var]) ||
strlen($_POST[$var]) > $limits[$var] ) {
90 throw new LengthException(sprintf('%s can\'t be longer than %d characters.', $name, $limits[$var]));
95 // PHP really needs a coerce function
96 if ( empty($_POST['options']) ) {
97 $_POST['options'] = array();
100 // Fields to check/update
102 'msgs_page' => 'Messages per page',
103 'topics_page' => 'Topics per page'
106 'sig' => 'Signature',
108 'date_format' => 'Custom date format',
109 'public_contact' => 'Public contact address',
110 'private_contact' => 'Private contact address'
113 SO2
::$DB->beginTransaction();
115 // Validation and database updating:
118 foreach ( $selects as $field ) {
119 $
{$field}->check_value($_POST[$field]);
120 $
{$field}->default = SO2
::$User->$field = $_POST[$field];
122 $tz->check_value($_POST['tz']);
123 $tz->default = SO2
::$User->tz
= $_POST['tz'];
126 foreach ( $numbers as $varname => $displayname ) {
127 SO2
::$User->$varname = rangecheck($varname, 5, 100, $displayname);
129 SO2
::$User->cutoff
= rangecheck('cutoff', -999, 999, 'Post Threshold');
133 foreach ( $strings as $varname => $displayname ) {
134 SO2
::$User->$varname = lengthcheck($varname, $displayname);
136 if ( htmlspecialchars($_POST['date_format']) != $_POST['date_format'] ) {
137 throw new OutOfBoundsException('Date format cannot contain special HTML characters.');
141 SO2
::$User->options
= array_intersect( array_keys($_POST['options']),
142 array('alwaysonline', 'javascript', 'cache', 'quickpost') );
146 SO2
::$Page->message('Settings have been saved.', E_USER_NOTICE
);
147 } catch ( OutOfBoundsException
$e ) {
148 SO2
::$Page->message($e->getMessage(), E_USER_WARNING
);
149 } catch ( LengthException
$e ) {
150 SO2
::$Page->message($e->getMessage(), E_USER_WARNING
);
153 SO2
::$Page->pageheader();
156 $options['Display Settings'] = array (
157 'Message list layout' => array('info' => 'Threaded view disables messages per page setting',
158 'field' => $msglist_layout.$msglist_style ),
159 'Topic list layout' => array('field' => $topiclist_layout ),
160 'Board list layout' => array('field' => $boardlist_layout ),
161 'Messages per page' => array('info' => 'Between 5-100',
162 'field' => maketextbox('msgs_page', 3) ),
163 'Topics per page' => array('info' => 'Between 5-100',
164 'field' => maketextbox('topics_page', 3) ),
165 'Timezone' => array('field' => $tz.': '.strip_tags(SO2
::$Page->fdate(T_NOW
)) ),
166 'Time format' => array('info' => 'See PHP <a href="//php.net/date">date</a> documentation. Default: "Y-m-d H:i:s"',
167 'field' => maketextbox('date_format', $limits['date_format']) ),
169 $options['Miscellaneous'] = array (
170 'Post threshold' => array('info' => 'Posts below this many points will be hidden from the message list.',
171 'field' => maketextbox('cutoff', 4) ),
172 'Initial post HTML method' => array('field' => $post_html ),
173 'Other Options' => array('field' => '<fieldset>'.
174 makeoptbox('alwaysonline', 'Enable active time updating',
175 'Disabling this will only update your last active time when you post.').
176 makeoptbox('javascript', 'Enable Javascript',
177 'Enables optional JS/AJAX functionality.').
178 makeoptbox('cache', 'Low bandwidth mode',
179 'Activates HTTP caching. Breaks most pages.').
180 makeoptbox('quickpost', 'Use quickpost box',
181 'Puts a quick post box under the topic and message list.').
186 $options['Profile'] = array (
187 'Signature' => array('info' => 'Appended to the bottom of your posts.',
188 'field' => '<textarea rows="4" cols="60" name="sig">'.htmlspecialchars(SO2
::$User->sig
).'</textarea>'),
189 'Quote' => array('info' => 'Shown in your userinfo page. Use plain text only.',
190 'field' => '<textarea rows="4" cols="60" name="quote">'.htmlspecialchars(SO2
::$User->quote
).'</textarea>'),
191 'Public contact address' => array('info' => 'Only visible to logged in users.',
192 'field' => maketextbox('public_contact', $limits['public_contact']) ),
193 'Private contact address' => array('info' => 'Only visible to you and admins.',
194 'field' => maketextbox('private_contact', $limits['private_contact']) )
198 <form method
="post" action
="<?php echo $_SERVER['PHP_SELF'] ?>">
200 foreach ( $options as $title => $fields ) { ?
>
201 <fieldset
><legend
><?php
echo $title ?
></legend
>
202 <table id
="<?php strtr(strtolower($title), ' ', '_') ?>">
204 <tr
><th scope
="col">Option
</th
><th scope
="col">Value
</th
></tr
>
209 foreach ( $fields as $name => $stuff ) { ?
>
210 <tr
class="content c<?php echo ++$a&1 ?>">
211 <td
><?php
echo $name ?
></td
>
213 echo $stuff['field'];
214 if ( isset($stuff['info']) )
215 echo ' <small>',$stuff['info'],'</small>';
223 <p
><input type
="submit" name
="submit" value
="Save Settings (S)" accesskey
="s"/></p
>