1 | <?php |
---|
2 | |
---|
3 | if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | function gb_is_valid_email($mail_address) |
---|
6 | { |
---|
7 | if (function_exists('email_check_format')) |
---|
8 | { |
---|
9 | return email_check_format($email_address); |
---|
10 | } |
---|
11 | else if (version_compare(PHP_VERSION, '5.2.0') >= 0) |
---|
12 | { |
---|
13 | return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false; |
---|
14 | } |
---|
15 | else |
---|
16 | { |
---|
17 | $atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // before arobase |
---|
18 | $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name |
---|
19 | $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i'; |
---|
20 | |
---|
21 | return (bool)preg_match($regex, $mail_address); |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | function gb_is_valid_url($url) |
---|
26 | { |
---|
27 | if (function_exists('url_check_format')) |
---|
28 | { |
---|
29 | return url_check_format($url); |
---|
30 | } |
---|
31 | else if (version_compare(PHP_VERSION, '5.2.0') >= 0) |
---|
32 | { |
---|
33 | return filter_var($url, FILTER_VALIDATE_URL)!==false; |
---|
34 | } |
---|
35 | else |
---|
36 | { |
---|
37 | $regex = '#^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$#i'; |
---|
38 | |
---|
39 | return (bool)preg_match($regex, $url); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | function get_stars($score, $path) |
---|
44 | { |
---|
45 | if ($score === null) return null; |
---|
46 | |
---|
47 | $max = 5; |
---|
48 | $score = min(max($score, 0), $max); |
---|
49 | $floor = floor($score); |
---|
50 | |
---|
51 | $html = null; |
---|
52 | for ($i=1; $i<=$floor; $i++) |
---|
53 | { |
---|
54 | $html.= '<img alt="'.$i.'" src="'.$path.'star-on.png">'; |
---|
55 | } |
---|
56 | |
---|
57 | if ($score != $max) |
---|
58 | { |
---|
59 | if ($score-$floor <= .25) |
---|
60 | { |
---|
61 | $html.= '<img alt="'.($floor+1).'" src="'.$path.'star-off.png">'; |
---|
62 | } |
---|
63 | else if ($score-$floor <= .75) |
---|
64 | { |
---|
65 | $html.= '<img alt="'.($floor+1).'" src="'.$path.'star-half.png">'; |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | $html.= '<img alt="'.($floor+1).'" src="'.$path.'star-on.png">'; |
---|
70 | } |
---|
71 | |
---|
72 | for ($i=$floor+2; $i<=$max; $i++) |
---|
73 | { |
---|
74 | $html.= '<img alt="'.$i.'" src="'.$path.'star-off.png">'; |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | return $html; |
---|
79 | } |
---|
80 | |
---|
81 | ?> |
---|