Made the GFCSS theme work a bit better
[specialops2.git] / theme.php
blobe035a024821494e484f9fc0d6dcee838eceb077e
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']);
32 $premade_themes->default = intval($_POST['premade_theme']);
34 if ( isset($_POST['importpre']) ) {
35 list($f) = $DB->query('SELECT `css_file` FROM `themes`
36 WHERE `themeid` = '.intval($_POST['premade_theme']))->fetch_row();
37 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/'.$f.'.css'));
38 $user->theme = 0;
39 } else {
40 $user->theme = intval($_POST['premade_theme']);
42 break;
44 case 'import':
45 $user_themes->check_value($_POST['user_theme']);
46 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/u'.intval($_POST['user_theme']).'.css'));
47 $user->theme = 0;
48 break;
50 case 'custom':
51 $user->theme = 0;
52 file_put_contents('css/u'.$user->userid.'.css', str_replace("\r\n", "\n", $_POST['user_css']));
55 $user->userheader();
56 echo '<p class="notice">Settings have been saved.</p>';
57 } catch ( Exception $e ) {
58 $user->userheader();
59 echo '<p class="error">',$e->getMessage(),'</p>';
61 } elseif ( isset($_POST['preview']) ) {
62 $user->userheader();
63 echo '<p class="notice">This is a preview of your custom theme. Changes have not been saved.</p>';
64 } else {
65 $user->userheader();
68 $css_textbox = htmlspecialchars(
69 empty($_POST['user_css'])
70 ? (
71 file_exists('css/u'.$user->userid.'.css')
72 ? file_get_contents('css/u'.$user->userid.'.css')
73 : ''
75 : $_POST['user_css']
77 $themetype = isset($_POST['preview']) ? 0 : $user->theme;
80 <form id="theme" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
81 <button type="submit" name="save" accesskey="s">Save Settings (S)</button>
82 <fieldset class="content">
83 <legend><label><input type="radio" name="themetype" value="premade"<?php
84 echo 0 < $themetype ? ' checked="checked"' : '' ?>/> Premade Theme</label></legend>
85 <p><label>Select theme: <?php echo $premade_themes->display() ?></label></p>
86 <p><label><input type="checkbox" name="importpre"/> Set your custom theme to this</label></p>
87 </fieldset>
89 <fieldset class="content">
90 <legend><label><input type="radio" name="themetype" value="import"/> Import from user</label></legend>
91 <p><label>User name: <?php echo $user_themes->display() ?></label></p>
92 </fieldset>
94 <fieldset class="content">
95 <legend><label><input type="radio" name="themetype" value="custom"<?php
96 echo 0 == $themetype ? ' checked="checked"' : '' ?>/> Custom CSS</label></legend>
97 <textarea rows="20" cols="80" name="user_css" id="user_css"><?php echo $css_textbox ?></textarea>
98 <p><a href="css/">CSS Directory</a> <button type="submit" name="preview" accesskey="p">Preview (P)</button></p>
99 </fieldset>
100 </form>
102 <div id="theme-help">
103 <h3>CSS classes &amp; IDs:</h3>
104 <dl>
105 <dt><code>h1</code></dt>
106 <dd>Page title</dd>
107 <dt><code>body#so2-index</code>, [...]</dt>
108 <dd><code>&lt;body&gt;</code> tag for index.php</dd>
109 <dt><code>.nl</code>,
110 <code>#userheader</code>,
111 <code>#navbar</code></dt>
112 <dd>Generic navigation list, user navigation, page navigation</dd>
113 <dt><code>#messagelist</code>,
114 <code>#topiclist</code>,
115 <code>#boardlist</code></dt>
116 <dd>Message list/topic list/board list</dd>
117 <dt><code>.Messagelist_Default</code>,
118 <code>.Topiclist_Default</code>,
119 <code>.Boardlist_Default</code>,
120 [...]</dt>
121 <dd>Layout-specific classes for messagelist/topiclist/boardlist</dd>
122 <dt><code>.error</code>,
123 <code>.notice</code>,
124 <code>.info</code></dt>
125 <dd>Errors, important messages and informational messages</dd>
126 <dt><code>.c0</code>,
127 <code>.c1</code></dt>
128 <dd>Alternating rows in tables</dd>
129 <dt><code>.message</code>, <code>.thread</code></dt>
130 <dd>Messages in messagelist, threads (threaded view only)</dd>
131 <dt><code>.message > .info</code>, <code>.message > .content</code></dt>
132 <dd>Message header &amp; message body</dd>
133 <dt><code>.message.u100</code></dt>
134 <dd>Any messages posted by a user with userid 100</dd>
135 </dl>
136 </div>
138 <?php
139 $page->pagefooter();