Small changes to index.php, moved the page time to the footer (all pages), and hopefu...
[specialops2.git] / theme.php
blobab0f6d3aca008c0eaaefe95b3ec6091fa70e6336
1 <?php
2 /**
3 * Theme Editor
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://COPYING
7 * @version $Id$
8 */
10 require 'con.php';
11 $page->title = 'Theme Settings';
13 if ( ! ($user instanceof User_Authenticated) ) {
14 $page->errorfooter('login');
16 if ( 0 >= $user->points ) {
17 $page->errorfooter('points');
19 $user->userlinks['General Settings'] = 'options';
21 $premade_themes = new HTML_Select('premade_theme', 2, $user->theme);
22 $user_themes = new HTML_Select('user_theme', 2);
24 $premade_themes->db_fill($DB->query('SELECT `themeid`, `theme_name` FROM `themes` ORDER BY `theme_name` ASC', MYSQLI_USE_RESULT));
25 $user_themes->db_fill($DB->query('SELECT `userid`, `alias` FROM `users` WHERE `theme` = 0 ORDER BY `alias` ASC', MYSQLI_USE_RESULT));
27 if ( isset($_POST['save']) ) {
28 try {
29 switch ( $_POST['themetype'] ) {
30 case 'premade':
31 $premade_themes->check_value($_POST['premade_theme']);
33 $t = intval($_POST['premade_theme']);
34 $premade_themes->default = $t;
36 if ( isset($_POST['importpre']) ) {
37 list($f) = $DB->query('SELECT `css_file` FROM `themes` WHERE `themeid` = '.$t)->fetch_row();
38 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/'.$f.'.css'));
39 $user->theme = 0;
40 } else {
41 $user->theme = $t;
43 break;
45 case 'import':
46 $user_themes->check_value($_POST['user_theme']);
47 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/u'.intval($_POST['user_theme']).'.css'));
48 $user->theme = 0;
49 break;
51 case 'custom':
52 $user->theme = 0;
53 file_put_contents('css/u'.$user->userid.'.css', str_replace("\r\n", "\n", $_POST['user_css']));
56 $user->userheader();
57 echo '<p class="notice">Settings have been saved.</p>';
58 } catch ( Exception $e ) {
59 $user->userheader();
60 echo '<p class="error">',$e->getMessage(),'</p>';
62 } elseif ( isset($_POST['preview']) ) {
63 $user->userheader();
64 echo '<p class="notice">This is a preview of your custom theme. Changes have not been saved.</p>';
65 } else {
66 $user->userheader();
69 $css_textbox = htmlspecialchars(
70 isset($_POST['themetype'], $_POST['user_css']) && 'custom' == $_POST['themetype']
71 ? $_POST['user_css']
72 : (
73 file_exists('css/u'.$user->userid.'.css')
74 ? file_get_contents('css/u'.$user->userid.'.css')
75 : ''
76 ) // weirdest ternary I've ever wrote.
78 $themetype = isset($_POST['preview']) ? 0 : $user->theme;
81 <form id="theme" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
82 <button type="submit" name="save" accesskey="s">Save Settings (S)</button>
83 <fieldset class="content">
84 <legend><label>
85 <input type="radio" name="themetype" value="premade"<?php if ( $themetype > 0 ) echo ' checked="checked"' ?>/> Premade Theme
86 </label></legend>
87 <p><label>Select theme: <?php echo $premade_themes->display() ?></label></p>
88 <p><label><input type="checkbox" name="importpre"/> Set your custom theme to this</label></p>
89 </fieldset>
91 <fieldset class="content">
92 <legend><label>
93 <input type="radio" name="themetype" value="import"/> Import from user
94 </label></legend>
95 <p><label>User name: <?php echo $user_themes->display() ?></label></p>
96 </fieldset>
98 <fieldset class="content">
99 <legend><label>
100 <input type="radio" name="themetype" value="custom"<?php if ( 0 == $themetype ) echo ' checked="checked"' ?>/> Custom CSS
101 </label></legend>
102 <textarea rows="20" cols="80" name="user_css" id="user_css"><?php echo $css_textbox ?></textarea>
104 <a href="css/">CSS Directory</a> | <button type="submit" name="preview" accesskey="p">Preview Custom CSS (P)</button>
105 </p>
106 </fieldset>
107 </form>
109 <div id="theme-help">
110 <h3>CSS classes &amp; IDs:</h3>
111 <dl>
112 <dt><code>h1</code></dt>
113 <dd>Page title</dd>
114 <dt><code>body#so2-index</code>, [...]</dt>
115 <dd><code>&lt;body&gt;</code> tag for index.php</dd>
116 <dt><code>.nl</code>,
117 <code>#userheader</code>,
118 <code>#navbar</code></dt>
119 <dd>Generic navigation list, user navigation, page navigation</dd>
120 <dt><code>#messagelist</code>,
121 <code>#topiclist</code>,
122 <code>#boardlist</code></dt>
123 <dd>Message list/topic list/board list</dd>
124 <dt><code>.Messagelist_Default</code>,
125 <code>.Topiclist_Default</code>,
126 <code>.Boardlist_Default</code>,
127 [...]</dt>
128 <dd>Layout-specific classes for messagelist/topiclist/boardlist</dd>
129 <dt><code>.error</code>,
130 <code>.notice</code>,
131 <code>.info</code></dt>
132 <dd>Errors, important messages and informational messages</dd>
133 <dt><code>.c0</code>,
134 <code>.c1</code></dt>
135 <dd>Alternating rows in tables</dd>
136 <dt><code>.message</code>, <code>.thread</code></dt>
137 <dd>Messages in messagelist, threads (threaded view only)</dd>
138 <dt><code>.message > .info</code>, <code>.message > .content</code></dt>
139 <dd>Message header &amp; message body</dd>
140 <dt><code>.message.u100</code></dt>
141 <dd>Any messages posted by a user with userid 100</dd>
142 </dl>
143 </div>
145 <?php
146 $page->pagefooter();