This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
67 lines (62 loc) · 2.03 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
if (!defined('IN_CMS')) {
exit();
}
Plugin::setInfos(array(
'id' => 'layoutswitcher',
'title' => 'Layout switcher',
'description' => 'Allow visitors to switch between layouts.',
'version' => '0.1.0',
'license' => 'MIT',
'author' => 'svanlaere',
'website' => 'http://svanlaere.nl/',
'update_url' => 'http://svanlaere.nl/plugin-versions.xml',
'require_wolf_version' => '0.7.0'
));
Observer::observe('page_found', 'ls_output');
function ls_output($page)
{
if (!isset($_SESSION)) {
session_start();
}
$layout = $page->layout_id;
$object = Layout::findAll();
if (isset($_POST['layout'])) {
$layout = $_POST['layout'];
foreach ($object as $item) {
$layouts = (array) $item->id;
if (in_array($layout, $layouts)) {
$_SESSION['layout'] = $layout;
}
}
} elseif (!isset($_SESSION['layout'])) {
$_SESSION['layout'] = $layout;
$layout = $_SESSION['layout'];
} else {
$layout = $_SESSION['layout'];
}
$page->layout_id = $layout;
}
function ls_dropdown()
{
$url = $_SERVER['REQUEST_URI'];
echo '<form action="' . $url . '" method="post">' . PHP_EOL;
echo '<p>' . PHP_EOL;
echo '<label class="layout" for="layout">Layouts</label>' . PHP_EOL;
echo '<select name="layout" id="layout" onchange="this.form.submit();">' . PHP_EOL;
$layouts = Layout::findAll();
$current_layout = $_SESSION['layout'];
asort($layouts);
foreach ($layouts as $layout) {
$selected = ($current_layout == $layout->id) ? ' selected="selected"' : '';
if ($layout->content_type == 'text/html') {
echo '<option value="' . $layout->id . '"' . $selected . '>' . $layout->name . '</option>' . PHP_EOL;
}
}
echo '</select>' . PHP_EOL;
echo '</p>' . PHP_EOL;
echo '<noscript>' . PHP_EOL;
echo '<p><input type="submit" value="Switch Layout" /></p>' . PHP_EOL;
echo '</noscript>' . PHP_EOL;
echo '</form>' . PHP_EOL;
}