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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
<?php
/**
* Bayonet Content Management System
* Copyright (C) 2008-2011 Joseph Hunkeler & Evan O'Connell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class Bayonet_Layout
{
function OpenContent()
{
echo "<div class=\"contentBorder1\">";
echo "<div class=\"contentBorder2\">";
}
function CloseContent()
{
echo "</div>";
echo "</div>";
}
}
class Bayonet_Theme extends Bayonet_Layout
{
static public $index;
static public $header;
static public $footer;
static public $name;
static public $root_path;
static public $include_path;
static public $image_path;
static public $config_path;
static public $config;
static public $primary_css;
static function init()
{
if (!isset($_GET['theme']))
{
self::$name = Bayonet_Config::$ini['site']['theme'];
}
else
{
self::$name = $_GET['theme'];
}
decho('Initializing theme variables for \'' . self::$name . '\'');
self::$root_path = dirname(BAYONET_ROOT) . '/themes/' . self::$name;
self::$include_path = self::$root_path . '/include';
self::$image_path = self::$root_path . '/images';
self::$primary_css = self::$include_path . '/primary.css';
self::$config_path = self::$include_path . '/theme.ini';
if (!self::is_valid())
{
die('Theme failed during initialization.');
}
self::$config = parse_ini_file(self::$config_path, true);
self::$index = self::$root_path . '/index.php';
self::$header = self::$root_path . '/header.php';
self::$footer = self::$root_path . '/footer.php';
//decho(get_class_vars(Bayonet_Theme)); //do not re-enable this
self::load();
}
static private function is_valid()
{
if (file_exists(self::$root_path) && file_exists(self::$include_path) &&
file_exists(self::$config_path)) return true;
else return false;
}
static function load()
{
global $db, $config;
decho("Loading theme: '" . self::$name . "'");
require self::$index;
}
}
class Bayonet_Config
{
static $ini;
static function init()
{
decho('Parsing configuration data');
if (file_exists(BAYONET_CONFIG))
{
self::$ini = require_once 'config.php';
}
else die(BAYONET_CONFIG . ' not found');
}
}
class Bayonet
{
static function init()
{
global $db, $config;
Bayonet_Config::init();
// Set globally referenced configuration and database variables
$config = Bayonet_Config::$ini;
$db = new Bayonet_SQL();
//Connect to the MySQL server
$db->Connect($config['sql']['hostname'], $config['sql']['username'], $config['sql']['password']);
$db->Select_db($config['sql']['database']);
decho('Initializing Bayonet');
Bayonet_Theme::init();
}
}
define('PASSWORD', true);
define('NO_PASSWORD', false);
define('CHECKED', true);
class BayonetForm
{
static public $request;
public function __construct($action, $method)
{
$this->request = $_POST;
echo "<form action=\"$action\" method=\"$method\">\n";
}
public function __destruct()
{
echo "</form>\n";
}
function getKeyStates($keys)
{
$good = array();
$bad = array();
if (!is_array($keys)) return array();
foreach ($keys as $key => $value)
{
if (!empty($value)) $good[$key] = $value;
else $bad[$key] = $value;
}
$data = array('set' => $good, 'unset' => $bad);
return $data;
}
function verify($submit_key)
{
return $this->verifySubmit($submit_key);
}
function verifySubmit($submit_key)
{
return isset($this->request[$submit_key]) ? true : false;
}
function button($extern_name, $value, $text = "Button")
{
echo "<button name=\"{$extern_name}\" value=\"{$value}\">{$text}</button>\n";
}
function submitButton($extern_name, $value = "Submit")
{
echo "<input type=\"submit\" name=\"{$extern_name}\" value=\"{$value}\" />\n";
}
function reset($value = "Reset")
{
echo "<input type=\"reset\" value=\"{$value}\" />\n";
}
function textField($extern_name, $value = null, $isPassword = false, $size = null,
$max = null)
{
$type = 'text';
if ($isPassword) $type = 'password';
$value = filter_var($value, FILTER_SANITIZE_STRING);
echo "<input type=\"{$type}\" name=\"{$extern_name}\" value=\"$value\" size=\"{$size}\" maxLength=\"{$max}\" />\n";
}
function radioButton($extern_name, $value, $isChecked = false)
{
if ($isChecked)
{
echo "<input type=\"radio\" name=\"{$extern_name}\" value=\"$value\" checked=\"checked\"/>\n";
}
else
{
echo "<input type=\"radio\" name=\"{$extern_name}\" value=\"$value\" />\n";
}
}
function checkBox($extern_name, $value, $isChecked = false)
{
if ($isChecked)
{
echo "<input type=\"checkbox\" name=\"{$extern_name}\" value=\"$value\" checked=\"checked\"/>\n";
}
else
{
echo "<input type=\"checkbox\" name=\"{$extern_name}\" value=\"$value\" />\n";
}
}
function dropDown($extern_name, $values = array('None'), $select = null)
{
$selectIterator = 1;
echo "<select name=\"{$extern_name}\">\n";
foreach ($values as $option => $text)
{
if (!is_null($select) && $selectIterator !== (int)$select)
{
echo "<option value=\"{$option}\">{$text}</option>\n";
}
else
{
echo "<option value=\"{$option}\" selected=\"selected\">{$text}</option>\n";
}
$selectIterator++;
}
echo "</select>\n";
}
function textArea($extern_name, $rows = 10, $cols = 30, $value = null)
{
$value = filter_var($value, FILTER_SANITIZE_STRING);
echo "<textarea name=\"{$extern_name}\" rows=\"$rows\" cols=\"$cols\">{$value}</textarea>\n";
}
}
?>
|