Readme update
[specialops2.git] / theme.php
blobccab1dd7d264f74775e126fc6e12bd66b19e4841
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 $user->userlinks['General Settings'] = 'options';
18 $premade_themes = new HTML_Select('premade_theme', 2, $user->theme);
19 $user_themes = new HTML_Select('user_theme', 2);
21 $premade_themes->db_fill($DB->query('SELECT `themeid`, `theme_name` FROM `themes` ORDER BY `theme_name` ASC', MYSQLI_USE_RESULT));
22 $user_themes->db_fill($DB->query('SELECT `userid`, `alias` FROM `users` WHERE `theme` = 0 ORDER BY `alias` ASC', MYSQLI_USE_RESULT));
24 if ( isset($_POST['submit']) ) {
25 try {
26 switch ( $_POST['themetype'] ) {
27 case 'premade':
28 $premade_themes->check_value($_POST['premade_theme']);
29 $premade_themes->default = intval($_POST['premade_theme']);
31 if ( isset($_POST['importpre']) ) {
32 list($f) = $DB->query('SELECT `css_file` FROM `themes`
33 WHERE `themeid` = '.intval($_POST['premade_theme']))->fetch_row();
34 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/'.$f.'.css'));
35 $user->theme = 0;
36 } else {
37 $user->theme = intval($_POST['premade_theme']);
39 break;
41 case 'import':
42 $user_themes->check_value($_POST['user_theme']);
43 file_put_contents('css/u'.$user->userid.'.css', file_get_contents('css/u'.intval($_POST['user_theme']).'.css'));
44 $user->theme = 0;
45 break;
47 case 'custom':
48 $user->theme = 0;
49 file_put_contents('css/u'.$user->userid.'.css', str_replace("\r\n", "\n", $_POST['user_css']));
52 $user->userheader();
53 echo '<p class="notice">Settings have been saved.</p>';
54 } catch ( Exception $e ) {
55 $user->userheader();
56 echo '<p class="error">',$e->getMessage(),'</p>';
58 } else {
59 $user->userheader();
62 if ( file_exists('css/u'.$user->userid.'.css') ) {
63 $css_textbox = htmlspecialchars(file_get_contents('css/u'.$user->userid.'.css'));
64 } else {
65 $css_textbox = '';
69 <form id="theme" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
70 <fieldset class="content">
71 <legend><label><input type="radio" name="themetype" value="premade"<?php
72 echo 0 < $user->theme ? ' checked="checked"' : '' ?>/> Premade Theme</label></legend>
73 <p><label>Select theme: <?php echo $premade_themes->display() ?></label></p>
74 <p><label><input type="checkbox" name="importpre"/> Set your custom theme to this</label></p>
75 </fieldset>
76 <fieldset class="content">
77 <legend><label><input type="radio" name="themetype" value="import"/> Import from user</label></legend>
78 <p><label>User name: <?php echo $user_themes->display() ?></label></p>
79 </fieldset>
80 <fieldset class="content">
81 <legend><label><input type="radio" name="themetype" value="custom"<?php
82 echo 0 == $user->theme ? ' checked="checked"' : '' ?>/> Custom CSS</label></legend>
83 <textarea rows="20" cols="80" name="user_css" id="user_css"><?php echo $css_textbox ?></textarea>
84 </fieldset>
86 <button type="submit" name="submit" accesskey="s">Save Settings (S)</button>
88 <h3>Some useful CSS:</h3>
89 <dl>
90 <dt><code>#userheader</code>, <code>#navbar</code> (<code>h1 + ul</code>, <code>h1 + ul + ul</code>)</dt>
91 <dd>Navigation menus at top of page</dd>
92 <dt><code>h1</code></dt>
93 <dd>Page title</dd>
94 <dt><code>#messagelist</code>, <code>#topiclist</code>, <code>#boardlist</code></dt>
95 <dd>Container block elements for message list/topic list/board list</dd>
96 <dt><code>.messagelist_default</code>, <code>.topiclist_default</code>, [...]</dt>
97 <dd>Class name for whatever layout is in use on the above</dd>
98 <dt><code>body#so2-<var>{pagename}</var></code></dt>
99 <dd>ID for the page being viewed (filename without .php extension)</dd>
100 </dl>
102 </form>
104 <?php
105 $page->pagefooter();