[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/web_spider/src/ -> lmbUriFilter.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  /**

  11   * class lmbUriFilter.

  12   *

  13   * @package web_spider

  14   * @version $Id: lmbUriFilter.class.php 5945 2007-06-06 08:31:43Z pachanga $

  15   */
  16  class lmbUriFilter
  17  {
  18    protected $allowed_protocols = array();
  19    protected $allowed_hosts = array();
  20    protected $allowed_path_regexes = array();
  21  
  22    function allowProtocol($protocol)
  23    {
  24      $this->allowed_protocols[] = strtolower($protocol);
  25    }
  26  
  27    function allowHost($host)
  28    {
  29      $this->allowed_hosts[] = strtolower($host);
  30    }
  31  
  32    function allowPathRegex($regex)
  33    {
  34      $this->allowed_path_regexes[] = $regex;
  35    }
  36  
  37    function canPass($uri)
  38    {
  39      if(!in_array($uri->getProtocol(), $this->allowed_protocols))
  40        return false;
  41  
  42      if(!in_array($uri->getHost(), $this->allowed_hosts))
  43        return false;
  44  
  45      if(!sizeof($this->allowed_path_regexes))
  46        return false;
  47  
  48      foreach($this->allowed_path_regexes as $regex)
  49        if(!preg_match($regex, $uri->getPath()))
  50          return false;
  51  
  52      return true;
  53    }
  54  }
  55  
  56  ?>


Generated: Mon Dec 1 03:56:46 2008 Cross-referenced by PHPXref 0.7