source: extensions/GuestBook/include/functions.inc.php @ 17495

Last change on this file since 17495 was 17495, checked in by mistic100, 12 years ago

better integration in simple and stripped

File size: 1.7 KB
Line 
1<?php
2
3if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
4
5if (!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
25function 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  {
33    $regex = '#^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$#i';
34
35    if (!preg_match($regex, $url)) return false;
36    return true;
37  }
38}
39
40function get_stars($score, $path)
41{
42  if ($score === null) return null;
43 
44  $max = 5;
45  $score = min(max($score, 0), $max);
46  $floor = floor($score);
47 
48  $html = null;
49  for ($i=1; $i<=$floor; $i++)
50  {
51    $html.= '<img alt="'.$i.'" src="'.$path.'star-on.png">';
52  }
53 
54  if ($score != $max)
55  {
56    if ($score-$floor <= .25)
57    {
58      $html.= '<img alt="'.($floor+1).'" src="'.$path.'star-off.png">';
59    }
60    else if ($score-$floor <= .75)
61    {
62      $html.= '<img alt="'.($floor+1).'" src="'.$path.'star-half.png">';
63    }
64    else
65    {
66      $html.= '<img alt="'.($floor+1).'" src="'.$path.'star-on.png">';
67    }
68 
69    for ($i=$floor+2; $i<=$max; $i++)
70    {
71      $html.= '<img alt="'.$i.'" src="'.$path.'star-off.png">';
72    }
73  }
74 
75  return $html;
76}
77
78?>
Note: See TracBrowser for help on using the repository browser.