-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.php
More file actions
87 lines (78 loc) · 1.6 KB
/
helper.php
File metadata and controls
87 lines (78 loc) · 1.6 KB
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
<?php
/**
* The helper class, containing all kinds of useful functions that don't really have a better place.
*/
class Helper
{
/**
* Print a nice representation of an array.
*/
static function printr($array)
{
echo '<pre>' . print_r($array, true) . '</pre>';
}
/**
* Checks a list of POST variables.
*
* Checks each key for both existance, and non-emptyiness.
*/
static function available()
{
foreach (func_get_args() as $key)
if (!isset($_POST[$key]) || empty($_POST[$key]))
return false;
return true;
}
/**
* Show an informational message.
*/
static function message($message)
{
global $template_vars;
$template_vars['messages'][] = $message;
}
/**
* Show an error message.
*/
static function error($error)
{
global $template_vars;
$template_vars['errors'][] = $error;
}
/**
* Redirect to another page.
*
* Redirects immediately, ending the current script execution.
*/
static function redirect($url, $arguments = array())
{
if (substr($url, 0, 1) == '@')
{
global $router;
$url = $router->generate(substr($url, 1), $arguments);
}
header("location: $url");
die();
}
/**
* Login an user.
*/
static function login($user)
{
$_SESSION['user'] = $user->getID();
}
/**
* Logout the current user.
*/
static function logout()
{
session_destroy();
}
/**
* Return the currently logged in user.
*/
static function getUser()
{
return isset($_SESSION['user']) ? UserQuery::create()->findOneById($_SESSION['user']) : false;
}
}