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