-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.php
112 lines (98 loc) · 2.91 KB
/
utilities.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
<?php
class mf {
/**
* Generic function to show a message to the user using WP's
* standard CSS classes to make use of the already-defined
* message colour scheme.
*
* @param $message The message you want to tell the user.
* @param $errormsg If true, the message is an error, so use
* the red message style. If false, the message is a status
* message, so use the yellow information message style.
*/
static function wpLog ($message, $errormsg = false)
{
if ($errormsg) {
echo '<div id="message" class="error">';
}
else {
echo '<div id="message" class="updated fade">';
}
echo "<p><strong>$message</strong></p></div>";
}
/**
* Just show our message (with possible checking if we only want
* to show message to certain users.
*/
function buildUrlQuery($query, $get = true){
//merge querys
if($get) $query = array_merge($_GET, $query);
if(!is_array($query)) die ("urlQuery requires an array as its argument.");
$url_ext = "?";
foreach($query as $k => $v){
$url_ext .=$k."=".$v."&";
}
$url_ext = substr($url_ext, 0, -5);//chop last ampersand off
return $url_ext;
}
function removeURLQuery($query){
if(is_array($query)){
foreach ($query as $v){
removeURLQuery($v);
}
}
$get = $_GET;
if(array_key_exists($query, $get)) {
unset($get[$query]);
}
return $get;
}
function thisPage() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
static function urlQuery($query){
$curl = explode("?",$_SERVER['REQUEST_URI']);
$query = self::buildUrlQuery($query);
return $curl[0].$query;
}
static function removeQueryElements($query_elements = array()){
$get = $_GET;
foreach($get as $k=>$v){
if(array_key_exists($k, array_flip($query_elements))) unset($get[$k]);
}
$new_query = self::buildUrlQuery($get, false);
$curl = explode("?",$_SERVER['REQUEST_URI']);
return $curl[0].$new_query;
}
static function clean($str = '', $html = false) {
//is String Empty?
if (empty($str)) return false;
//is String an array? If so, run clean with each item.
if (is_array($str)) {
foreach($str as $key => $value) $str[$key] = self::clean($value, $html);
} else {
// get magic quotes
if (get_magic_quotes_gpc()) $str = stripslashes($str);
//is HTML an Array?
if (is_array($html)) $str = strip_tags($str, implode('', $html));
//is html a valid html tag?
elseif (preg_match('|<([a-z]+)>|i', $html)) $str = strip_tags($str, $html);
//is html false?
elseif ($html !== true) $str = strip_tags($str);
$str = trim($str);
}
return $str;
}
static function slugger($string){
return str_replace(" ","_",strtolower($string));
}
}
?>