root/branches/style_switcher/manifest.xml

Revision 45, 2.3 KB (checked in by daris, 3 years ago)

adding go_to_page extension

Line 
1<?xml version="1.0" encoding="utf-8"?>
2
3<extension engine="1.0">
4        <id>style_switcher</id>
5        <title>Style Switcher</title>
6        <version>1.2</version>
7        <description>Allows users/guests select style</description>
8        <author>daris</author>
9        <minversion>1.3</minversion>
10        <maxtestedon>1.3.2</maxtestedon>
11
12        <hooks>
13                <hook id="co_common"><![CDATA[
14if (isset($_COOKIE['punbb_style']) && $forum_user['is_guest'])
15{
16        $style = basename($_COOKIE['punbb_style']);
17        if (file_exists(FORUM_ROOT.'style/'.$style) && is_dir(FORUM_ROOT.'style/'.$style) && $style != '')
18                $forum_user['style'] = $style;
19}
20                ]]></hook>
21
22                <hook id="in_start"><![CDATA[
23$style = (isset($_GET['style']) ? basename($_GET['style']) : null);
24if (isset($style) && file_exists(FORUM_ROOT.'style/'.$style) && is_dir(FORUM_ROOT.'style/'.$style) && substr($style, 0, 1) != '.')
25{
26        if ($forum_user['is_guest'])
27                setcookie('punbb_style', $style, time() + 2592000); // 30 days
28        else
29        {
30                // update current user style in db
31                $query = array(
32                        'UPDATE'        => 'users',
33                        'SET'           => 'style=\''.$forum_db->escape($style).'\'',
34                        'WHERE'         => 'id='.$forum_user['id']
35                );
36                $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
37        }
38
39        if (isset($_GET['redirect_url']))
40                $redirect = $_GET['redirect_url'];
41        else
42                $redirect = $base_url;
43
44        header('Location: '. $redirect);
45}
46]]></hook>
47
48                <hook id="ft_about_end"><![CDATA[
49?>
50<p>
51        <form action="<?php echo $base_url ?>" method="get" id="style_switcher" style="float: left; padding: 0.5em 0;">
52                <input type="hidden" name="redirect_url" value="<?php echo str_replace('&', '&amp;', $_SERVER['REQUEST_URI']) ?>" />
53               
54                <label for="style">Style: </label>
55                <select name="style" id="style" onchange="this.form.submit();"><?php
56
57$style = $forum_config['o_default_style'];
58if ($forum_user['is_guest'] && isset($_COOKIE['punbb_style']))
59        $style = $_COOKIE['punbb_style'];
60elseif (!$forum_user['is_guest'])
61        $style = $forum_user['style'];
62
63$d = dir(FORUM_ROOT.'style');
64while ($s = $d->read())
65{
66        if (substr($s, 0, 1) != '.' && is_dir(FORUM_ROOT.'style/'.$s))
67                echo "\n\t\t\t\t".'<option value="'.$s.'"'. ($style == $s ? ' selected="selected"' : '') .'>'.str_replace('_', ' ', $s).'</option>';
68}
69
70?>
71                </select>
72                <noscript>
73                        <input type="submit" value="OK" />
74                </noscript>
75        </form>
76</p>
77<?php
78
79                ]]></hook>
80        </hooks>
81</extension>
Note: See TracBrowser for help on using the browser.