-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
137 lines (125 loc) · 5.32 KB
/
lib.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
<?php
function site_email($to,$subject,$message) {
require_once('lib/class.phpmailer.php');
require_once('lib/emogrifier.php');
$mail = new PHPMailer();
$emogrifier = new Emogrifier();
$emogrifier->setHTML(file_get_contents('emailtemplates/basic/index.htm'));
$email = $emogrifier->emogrify();
$email = str_replace('[CONTENT]',$message,$email);
$email = str_replace('[SUBJECT]',$subject,$email);
$email = str_replace('[SITE NAME]','Site Name',$email); # TODO
$mail->SetFrom('[email protected]', 'Site Name'); # TODO
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->MsgHTML($email);
$mail->Send();
}
function printr(&$var, $info = FALSE) {
$scope = false;
$prefix = 'unique';
$suffix = 'value';
if($scope) $vals = $scope;
else $vals = $GLOBALS;
$old = $var;
$var = $new = $prefix.rand().$suffix; $vname = FALSE;
foreach($vals as $key => $val) if($val === $new) $vname = $key;
$var = $old;
echo "<pre>";
if($info != FALSE) echo "<b style='color: red;'>$info:</b><br>";
do_dump($var, '$'.$vname);
echo "</pre>";
}
function do_dump(&$var, $var_name = NULL, $indent = NULL, $reference = NULL) {
$do_dump_indent = "<span style='color:#eeeeee;'>|</span> ";
$reference = $reference.$var_name;
$keyvar = 'the_do_dump_recursion_protection_scheme'; $keyname = 'referenced_object_name';
if (is_array($var) && isset($var[$keyvar]))
{
$real_var = &$var[$keyvar];
$real_name = &$var[$keyname];
$type = ucfirst(gettype($real_var));
echo "$indent$var_name <span style='color:#a2a2a2'>$type</span> = <span style='color:#e87800;'>&$real_name</span><br>";
}
else
{
$var = array($keyvar => $var, $keyname => $reference);
$avar = &$var[$keyvar];
$type = ucfirst(gettype($avar));
if($type == "String") $type_color = "<span style='color:green'>";
elseif($type == "Integer") $type_color = "<span style='color:red'>";
elseif($type == "Double"){ $type_color = "<span style='color:#0099c5'>"; $type = "Float"; }
elseif($type == "Boolean") $type_color = "<span style='color:#92008d'>";
elseif($type == "NULL") $type_color = "<span style='color:black'>";
if(is_array($avar))
{
$count = count($avar);
echo "$indent" . ($var_name ? "$var_name => ":"") . "<span style='color:#a2a2a2'>$type ($count)</span><br>$indent(<br>";
$keys = array_keys($avar);
foreach($keys as $name)
{
$value = &$avar[$name];
do_dump($value, "['$name']", $indent.$do_dump_indent, $reference);
}
echo "$indent)<br>";
}
elseif(is_object($avar))
{
echo "$indent$var_name <span style='color:#a2a2a2'>$type</span><br>$indent(<br>";
foreach($avar as $name=>$value) do_dump($value, "$name", $indent.$do_dump_indent, $reference);
echo "$indent)<br>";
}
elseif(is_int($avar)) echo "$indent$var_name = <span style='color:#a2a2a2'>$type(".strlen($avar).")</span> $type_color$avar</span><br>";
elseif(is_string($avar)) echo "$indent$var_name = <span style='color:#a2a2a2'>$type(".strlen($avar).")</span> $type_color\"$avar\"</span><br>";
elseif(is_float($avar)) echo "$indent$var_name = <span style='color:#a2a2a2'>$type(".strlen($avar).")</span> $type_color$avar</span><br>";
elseif(is_bool($avar)) echo "$indent$var_name = <span style='color:#a2a2a2'>$type(".strlen($avar).")</span> $type_color".($avar == 1 ? "TRUE":"FALSE")."</span><br>";
elseif(is_null($avar)) echo "$indent$var_name = <span style='color:#a2a2a2'>$type(".strlen($avar).")</span> {$type_color}NULL</span><br>";
else echo "$indent$var_name = <span style='color:#a2a2a2'>$type(".strlen($avar).")</span> $avar<br>";
$var = $var[$keyvar];
}
}
function createRandomPassword($length = 8) {
$chars = "abcdefghjkmnpqrstuvwxyz23456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= $length) {
$num = rand() % strlen($chars);
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
function check_email_address($email) {
# First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
# Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
# Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { # Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; # Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
function arrayStripSlashes(&$array) {
foreach($array as $key=>$value) {
if (!is_array($array[$key])) $array[$key] = stripslashes($value);
}
}