This repository has been archived by the owner on Sep 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Uthando.php
333 lines (280 loc) · 8.22 KB
/
Uthando.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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
// no direct access
defined( 'PARENT_FILE' ) or die( 'Restricted access' );
class Uthando
{
// Set the attributes.
protected $vars = array();
protected $registry; // registry
public $striptags = false;
public function __construct ($registry)
{
$this->registry = $registry;
}
public function __set($index, $value)
{
$this->vars[$index] = $value;
}
public function __get($index)
{
if (array_key_exists($index, $this->vars)) return $this->vars[$index];
return null;
}
// Function for browser redirection.
public static function go($go=null)
{
header ('Location: ' . SCHEME . HOST . $go);
ob_end_clean();
exit;
}
// Function for setting the referer url.
public static function referer()
{
$_SESSION['referer_link'] = SCHEME . HOST . REQUEST_URI;
}
public function loadComponent()
{
$this->file = COMPONENTS.$this->registry->component;
if (is_file($this->file.DS.'index'.EXT) == false):
$this->registry->Error('404 Page NOT Found', $this->registry->path);
else:
$load = $this->getResult('enabled', $this->registry->db_default.'components', null, array('where' => "component='".$this->registry->component."'"), false);
endif;
if ($load->enabled):
include ($this->file.DS.'index'.EXT);
$this->registry->template->addContent($this->content);
else:
$this->registry->template->addContent('<p>Component is not enabled.</p>');
endif;
}
public function addComponentCSS($file=null)
{
$type = (defined('ADMIN')) ? 'admin' : 'public';
$path = '/uthando-css/'.$type.'/';
$css = $this->registry->get('component_css');
if ($file):
if (is_array($file)):
foreach ($file as $value):
$add_css[] = $path.$value.'.css';
endforeach;
else:
$add_css[] = $path.$file.'.css';
endif;
else:
$add_css[] = $path.$this->registry->component.'.css';
endif;
$this->registry->component_css = ($css) ? array_merge($css, $add_css) : $add_css;
}
public function addComponentJS($file=null)
{
$type = (defined('ADMIN')) ? 'admin' : 'public';
$path = '/uthando-js/uthando/'.$type.'/';
$js = $this->registry->get('component_js');
if ($file):
if (is_array($file)):
foreach ($file as $value):
$add_js[] = $path.$value.'.js';
endforeach;
else:
$add_js[] = $path.$file.'.js';
endif;
else:
$add_js[] = $path.$this->registry->component.'.js';
endif;
$this->registry->component_js = ($js) ? array_merge($js, $add_js) : $add_js;
}
public function addModules()
{
// Get Modules and add them.
$this->getModules();
}
private function getModules()
{
$result = $this->getResult('position_id, position', 'modules_position', null, null, true);
$cols = 2;
if ($result):
foreach ($result as $mod):
if ($mod->position == 'right') $cols = 3;
$module_position = $mod->position;
$modules = $this->getResult(
'module_id, module_name, module, show_title, params, html',
'modules',
'module_names',
array(
'WHERE' => "position_id='".$mod->position_id."'",
'AND' => 'enabled=1',
'ORDER BY' => 'sort_order ASC'
)
);
if ($modules):
foreach ($modules as $mod):
$module = new Module($this->registry);
$value[$module_position][] = $module->makeModule($mod);
unset($module);
endforeach;
endif;
endforeach;
endif;
$this->registry->template->addModules($value);
$this->registry->template->cols = $cols.'col';
}
public function removeSection($type, $html)
{
return preg_replace("/<!--".$type."_start-->(.*?)<!--".$type."_end-->/s", "", $html);
}
// form functions
public function escape_db_data ($data)
{
if (ini_get('magic_quotes_gpc')) $data = stripslashes($data);
if ($this->striptags) $data = strip_tags($data);
return $this->registry->db->escape(trim($data));
}
public function formValues($values)
{
foreach ($values as $key => $value):
if (is_array($value)):
$values[$key] = $this->formValues($value);
else:
$values[$key] = $this->escape_db_data($value);
endif;
endforeach;
return $values;
}
public function returnFormValues($values)
{
return $values;
}
public function objectToArray($object)
{
$array = array();
if (is_object($object)) $array = get_object_vars($object);
return $array;
}
function arrayToObject($array)
{
$object = new stdClass();
if (is_array($array) && count($array) > 0):
foreach ($array as $name=>$value):
$name = strtolower(trim($name));
if (!empty($name)) $object->$name = $value;
endforeach;
endif;
return $object;
}
public function dataTable($data, $header=null, $class=null)
{
$table = new HTML_Table();
$table->setAutoGrow(true);
$table->setAutoFill('');
$hrAttrs = ($class) ? array('class' => $class) : null;
for ($nr = 0; $nr < count($data); $nr++):
$table->setHeaderContents($nr+1, 0, (string)$data[$nr][0]);
for ($i = 1; $i < count($data[$nr]); $i++):
if ('' != $data[$nr][$i]) $table->setCellContents($nr+1, $i, $data[$nr][$i]);
$table->setRowAttributes($nr+1, $hrAttrs, true);
endfor;
endfor;
for ($i = 0; $i < count($header); $i++) $table->setHeaderContents(0, $i, $header[$i]);
return $table;
}
private function contentpaneHeading($heading)
{
$table = new HTML_Table(array('class' => 'contentpaneopen'));
$table->setCellContents(0, 0, stripslashes($heading));
$table->setColAttributes(0, array('class' => 'contentheading'));
return $table->toHTML();
}
private function getCdate($date)
{
return '<div class="createdate">'.$date.'</div>';
}
private function getMdate($date) {
return '<div class="modifydate">Last Updated ( '.$date.' )</div><span class="article_separator"></span>';
}
public function displayContentpane($data, $heading=null, $cdate=null, $mdate=null)
{
$pane = null;
if ($heading) $pane .= $this->contentpaneHeading($heading);
if ($cdate) $pane .= $this->getCdate($cdate);
$pane .= '<div class="contentpaneopen">'.$data.'</div>';
if ($mdate) $pane .= $this->getMdate($mdate);
return $pane;
}
public function message($params)
{
$message = file_get_contents(SITE_PATH.'/templates/' . $this->get('config.site.template') . '/html/message.html');
return $this->templateParser($message, $params, '<!--{', '}-->');
}
public function array_flatten(array $array)
{
if($array):
$flat = array();
foreach(new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::SELF_FIRST) as $key=>$value) if(!is_array($value)) $flat[] = $value;
return $flat;
else:
return false;
endif;
}
// shortcut functions for the modules and components.
public function remove($table, $where)
{
return $this->registry->db->remove($table, $where);
}
public function update($update, $table, $filter, $quote=true)
{
return $this->registry->db->update($update, $table, $filter, $quote);
}
public function insert($insert, $table, $quote=true)
{
return $this->registry->db->insert($insert, $table, $quote);
}
public function getResult($values, $table, $join=null, $filter=null, $array_mode=true)
{
return $this->registry->db->getResult($values, $table, $join, $filter, $array_mode);
}
public function getRow($sql, $bind=null)
{
return $this->registry->db->getRow($sql, $bind);
}
public function addContent($value)
{
$this->registry->template->addContent($value);
}
public function addParameter($variable, $value)
{
$this->registry->template->addParameter($variable, $value);
}
public function deleteParameter($variable)
{
$this->registry->template->deleteParameter($variable);
}
public function setTitle($title)
{
$this->registry->template->setTitle($title);
}
public function addScriptDeclaration($value)
{
$this->registry->template->addScriptDeclaration($value);
}
public function loadJavaScript($scripts)
{
$this->registry->template->loadJavaScript($scripts);
}
private function compressCSS($buffer)
{
return HTML_Template::compressStyles($buffer);
}
public function compress($buffer)
{
return HTML_Template::compress($buffer);
}
public function templateParser($template, $params, $key_start, $key_end)
{
return HTML_Template::templateParser($template, $params, $key_start, $key_end);
}
public function get($key=null)
{
return $this->registry->get($key);
}
}
?>