├── phpQuery └── phpQuery │ ├── plugins │ ├── Scripts │ │ ├── __config.example.php │ │ ├── print_source.php │ │ ├── print_websafe.php │ │ ├── example.php │ │ ├── fix_webroot.php │ │ └── google_login.php │ ├── example.php │ └── Scripts.php │ ├── bootstrap.example.php │ ├── Zend │ ├── Exception.php │ ├── Json │ │ └── Exception.php │ ├── Http │ │ ├── Exception.php │ │ └── Client │ │ │ ├── Exception.php │ │ │ └── Adapter │ │ │ ├── Exception.php │ │ │ ├── Interface.php │ │ │ └── Test.php │ ├── Uri │ │ └── Exception.php │ ├── Validate │ │ ├── Exception.php │ │ ├── Hostname │ │ │ ├── Se.php │ │ │ ├── Fi.php │ │ │ ├── Hu.php │ │ │ ├── At.php │ │ │ ├── Ch.php │ │ │ ├── Li.php │ │ │ ├── No.php │ │ │ ├── Interface.php │ │ │ └── De.php │ │ ├── Ip.php │ │ ├── NotEmpty.php │ │ ├── Hex.php │ │ ├── Int.php │ │ ├── Float.php │ │ ├── Interface.php │ │ ├── File │ │ │ ├── NotExists.php │ │ │ ├── FilesSize.php │ │ │ ├── Exists.php │ │ │ ├── MimeType.php │ │ │ ├── Extension.php │ │ │ ├── Count.php │ │ │ └── Upload.php │ │ ├── LessThan.php │ │ ├── GreaterThan.php │ │ ├── Digits.php │ │ ├── Barcode │ │ │ ├── UpcA.php │ │ │ └── Ean13.php │ │ ├── Barcode.php │ │ ├── Identical.php │ │ ├── Ccnum.php │ │ ├── Regex.php │ │ ├── Alpha.php │ │ ├── Alnum.php │ │ ├── InArray.php │ │ ├── StringLength.php │ │ ├── Between.php │ │ ├── Date.php │ │ └── EmailAddress.php │ ├── Uri.php │ ├── Registry.php │ └── Loader.php │ ├── compat │ └── mbstring.php │ ├── DOMEvent.php │ ├── Callback.php │ └── phpQueryEvents.php ├── API ├── Follow.php ├── Ask.php ├── Activity.php ├── Answer.php ├── Main.php └── User.php ├── demo.php └── index.php /phpQuery/phpQuery/plugins/Scripts/__config.example.php: -------------------------------------------------------------------------------- 1 | array('login@mail', 'password'), 9 | ); 10 | ?> -------------------------------------------------------------------------------- /phpQuery/phpQuery/plugins/Scripts/print_source.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | /** @var phpQueryObject */ 8 | $self = $self; 9 | $return = htmlspecialchars($self); -------------------------------------------------------------------------------- /phpQuery/phpQuery/plugins/Scripts/print_websafe.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | /** @var phpQueryObject */ 8 | $self = $self; 9 | $self 10 | ->find('script') 11 | ->add('meta[http-equiv=refresh]') 12 | ->add('meta[http-equiv=Refresh]') 13 | ->remove(); -------------------------------------------------------------------------------- /phpQuery/phpQuery/bootstrap.example.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/plugins/Scripts/example.php: -------------------------------------------------------------------------------- 1 | find($params[0]); 14 | ?> -------------------------------------------------------------------------------- /phpQuery/phpQuery/plugins/Scripts/fix_webroot.php: -------------------------------------------------------------------------------- 1 | filter($filter) as $el) { 9 | $el = pq($el, $self->getDocumentID()); 10 | // imgs and scripts 11 | if ( $el->is('img') || $el->is('script') ) 12 | $el->attr('src', $params[0].$el->attr('src')); 13 | // css 14 | if ( $el->is('link') ) 15 | $el->attr('href', $params[0].$el->attr('href')); 16 | } -------------------------------------------------------------------------------- /API/Follow.php: -------------------------------------------------------------------------------- 1 | username."/followees"); 15 | } 16 | public function getFollowees(){ 17 | phpQuery::browserGet('http://www.google.com/', 'success1'); 18 | 19 | } 20 | public function getFollower(){ 21 | 22 | } 23 | // toString方法 返回 类型、拉取的数量、最后输出json 24 | function __toString(){ 25 | //让php支持json中文编码 26 | return json_encode($this->detail,JSON_UNESCAPED_UNICODE); 27 | } 28 | } 29 | ?> 30 | 31 | -------------------------------------------------------------------------------- /API/Ask.php: -------------------------------------------------------------------------------- 1 | username."/asks"); 14 | } 15 | public function getAsks(){ 16 | $q = pq("#zh-profile-ask-list"); 17 | $column = pq($q)->find(".zm-profile-section-item .question_link"); 18 | return parent::getQuestion($column); 19 | } 20 | // toString方法 返回 类型、拉取的数量、最后生成json 21 | function __toString(){ 22 | $this->getAsks(); 23 | $this->detail["type"] = "Ask"; 24 | $this->detail["content"]=$this->arr; 25 | $this->detail["items"]=$this->itemi; 26 | //让php支持json中文编码 27 | return json_encode($this->detail,JSON_UNESCAPED_UNICODE); 28 | } 29 | } 30 | ?> -------------------------------------------------------------------------------- /demo.php: -------------------------------------------------------------------------------- 1 | init(); 13 | // echo $p; 14 | 15 | // require('API/User.php'); 16 | // $p = new User("yfgeek"); 17 | // $p->init(); 18 | // echo $p; 19 | require_once('phpQuery/phpQuery.php'); 20 | // phpQuery::browserGet('http://www.zhihu.com/people/yfgeek', 'success1'); 21 | phpQuery::browserGet('http://news.163.com/', 'success1'); 22 | function success1($browser) { 23 | $browser ->WebBrowser('callback') ->find('.zu-button-more') ->click(); 24 | } 25 | function callback($browser) { 26 | // $q = pq("#zh-profile-activity-wrap .zm-profile-activity-page-item-main"); 27 | print $browser; 28 | } 29 | ?> -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Exception.php: -------------------------------------------------------------------------------- 1 | find(".post-link"); 14 | return $this->getQuestion($column); 15 | } 16 | // 获得最近问题点赞信息 17 | public function getQuestionLink(){ 18 | $q = pq("#zh-profile-activity-wrap .zm-profile-activity-page-item-main"); 19 | $column = pq($q)->find(".question_link"); 20 | return $this->getQuestion($column); 21 | } 22 | // toString方法 返回 类型、拉取的数量、最后生成json 23 | function __toString(){ 24 | $this->detail["type"] = "Activity"; 25 | $this->getPostLink(); 26 | $this->getQuestionLink(); 27 | $this->detail["content"]=$this->arr; 28 | $this->detail["items"]=$this->itemi; 29 | //让php支持json中文编码 30 | return json_encode($this->detail,JSON_UNESCAPED_UNICODE); 31 | } 32 | } 33 | ?> -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Json/Exception.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | phpQuery::ajaxAllowHost( 10 | 'code.google.com', 11 | 'google.com', 'www.google.com', 12 | 'mail.google.com', 13 | 'docs.google.com', 14 | 'reader.google.com' 15 | ); 16 | if (! function_exists('ndfasui8923')) { 17 | function ndfasui8923($browser, $scope) { 18 | extract($scope); 19 | $browser 20 | ->WebBrowser() 21 | ->find('#Email') 22 | ->val($config['google_login'][0])->end() 23 | ->find('#Passwd') 24 | ->val($config['google_login'][1]) 25 | ->parents('form') 26 | ->submit(); 27 | } 28 | $ndfasui8923 = new Callback('ndfasui8923', new CallbackParam, compact( 29 | 'config', 'self', 'return', 'params' 30 | )); 31 | } 32 | phpQuery::plugin('WebBrowser'); 33 | $self->document->xhr = phpQuery::$plugins->browserGet( 34 | 'https://www.google.com/accounts/Login', 35 | $ndfasui8923 36 | ); 37 | //$self->document->xhr = phpQuery::$plugins->browserGet('https://www.google.com/accounts/Login', create_function('$browser', " 38 | // \$browser 39 | // ->WebBrowser() 40 | // ->find('#Email') 41 | // ->val('{$config['google_login'][0]}')->end() 42 | // ->find('#Passwd') 43 | // ->val('".str_replace("'", "\\'", $config['google_login'][1])."') 44 | // ->parents('form') 45 | // ->submit();" 46 | //)); 47 | ?> -------------------------------------------------------------------------------- /API/Answer.php: -------------------------------------------------------------------------------- 1 | username."/answers?page=".$page."&order_by=".$orderby); 17 | } 18 | public function getAnswers(){ 19 | $q = pq("#zh-profile-answer-list"); 20 | $column = pq($q)->find(".zm-item .question_link"); 21 | return parent::getQuestion($column); 22 | } 23 | public function getPages(){ 24 | $q = pq(".zm-invite-pager span:last"); 25 | $column = pq($q)->prev()->text(); 26 | $this->detail["pages"]=$column; 27 | return $column; 28 | 29 | } 30 | // toString方法 返回 类型、拉取的数量、最后生成json 31 | function __toString(){ 32 | $this->init(); 33 | $this->detail["type"] = "Answer"; 34 | // $this->datail["page"] = $page; 35 | $this->getAnswers(); 36 | $this->getPages(); 37 | $this->detail["content"]=$this->arr; 38 | $this->detail["items"]=$this->itemi; 39 | //让php支持json中文编码 40 | return json_encode($this->detail,JSON_UNESCAPED_UNICODE); 41 | } 42 | } 43 | ?> -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Hostname/Se.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not appear to be a valid IP address" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is a valid IP address 52 | * 53 | * @param mixed $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $valueString = (string) $value; 59 | 60 | $this->_setValue($valueString); 61 | 62 | if (ip2long($valueString) === false) { 63 | $this->_error(); 64 | return false; 65 | } 66 | 67 | return true; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/plugins/example.php: -------------------------------------------------------------------------------- 1 | plugin('example') 9 | * pq('ul')->plugin('example', 'example.php') 10 | * 11 | * Plugin classes are never intialized, just method calls are forwarded 12 | * in static way from phpQuery. 13 | * 14 | * Have fun writing plugins :) 15 | */ 16 | 17 | /** 18 | * phpQuery plugin class extending phpQuery object. 19 | * Methods from this class are callable on every phpQuery object. 20 | * 21 | * Class name prefix 'phpQueryObjectPlugin_' must be preserved. 22 | */ 23 | abstract class phpQueryObjectPlugin_example { 24 | /** 25 | * Limit binded methods. 26 | * 27 | * null means all public. 28 | * array means only specified ones. 29 | * 30 | * @var array|null 31 | */ 32 | public static $phpQueryMethods = null; 33 | /** 34 | * Enter description here... 35 | * 36 | * @param phpQueryObject $self 37 | */ 38 | public static function example($self, $arg1) { 39 | // this method can be called on any phpQuery object, like this: 40 | // pq('div')->example('$arg1 Value') 41 | 42 | // do something 43 | $self->append('Im just an example !'); 44 | // change stack of result object 45 | return $self->find('div'); 46 | } 47 | protected static function helperFunction() { 48 | // this method WONT be avaible as phpQuery method, 49 | // because it isn't publicly callable 50 | } 51 | } 52 | 53 | /** 54 | * phpQuery plugin class extending phpQuery static namespace. 55 | * Methods from this class are callable as follows: 56 | * phpQuery::$plugins->staticMethod() 57 | * 58 | * Class name prefix 'phpQueryPlugin_' must be preserved. 59 | */ 60 | abstract class phpQueryPlugin_example { 61 | /** 62 | * Limit binded methods. 63 | * 64 | * null means all public. 65 | * array means only specified ones. 66 | * 67 | * @var array|null 68 | */ 69 | public static $phpQueryMethods = null; 70 | public static function staticMethod() { 71 | // this method can be called within phpQuery class namespace, like this: 72 | // phpQuery::$plugins->staticMethod() 73 | } 74 | } 75 | ?> -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/NotEmpty.php: -------------------------------------------------------------------------------- 1 | "Value is empty, but a non-empty value is required" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is not an empty value. 52 | * 53 | * @param string $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $this->_setValue((string) $value); 59 | 60 | if (is_string($value) 61 | && (('' === $value) 62 | || preg_match('/^\s+$/s', $value)) 63 | ) { 64 | $this->_error(); 65 | return false; 66 | } elseif (!is_string($value) && empty($value)) { 67 | $this->_error(); 68 | return false; 69 | } 70 | 71 | return true; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/plugins/Scripts.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Hex.php: -------------------------------------------------------------------------------- 1 | "'%value%' has not only hexadecimal digit characters" 50 | ); 51 | 52 | /** 53 | * Defined by Zend_Validate_Interface 54 | * 55 | * Returns true if and only if $value contains only hexadecimal digit characters 56 | * 57 | * @param string $value 58 | * @return boolean 59 | */ 60 | public function isValid($value) 61 | { 62 | $valueString = (string) $value; 63 | 64 | $this->_setValue($valueString); 65 | 66 | if (!ctype_xdigit($valueString)) { 67 | $this->_error(); 68 | return false; 69 | } 70 | 71 | return true; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Int.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not appear to be an integer" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is a valid integer 52 | * 53 | * @param string $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $valueString = (string) $value; 59 | 60 | $this->_setValue($valueString); 61 | 62 | $locale = localeconv(); 63 | 64 | $valueFiltered = str_replace($locale['decimal_point'], '.', $valueString); 65 | $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered); 66 | 67 | if (strval(intval($valueFiltered)) != $valueFiltered) { 68 | $this->_error(); 69 | return false; 70 | } 71 | 72 | return true; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Float.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not appear to be a float" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is a floating-point value 52 | * 53 | * @param string $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $valueString = (string) $value; 59 | 60 | $this->_setValue($valueString); 61 | 62 | $locale = localeconv(); 63 | 64 | $valueFiltered = str_replace($locale['thousands_sep'], '', $valueString); 65 | $valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered); 66 | 67 | if (strval(floatval($valueFiltered)) != $valueFiltered) { 68 | $this->_error(); 69 | return false; 70 | } 71 | 72 | return true; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /API/Main.php: -------------------------------------------------------------------------------- 1 | username = $username; 17 | } 18 | // 初始化 加载phpquery类 19 | public function init(){ 20 | $web_path = "https://www.zhihu.com/people/"; 21 | require_once(ROOT_PATH . '/phpQuery/phpQuery.php'); 22 | phpQuery::newDocumentFile($web_path. $this->username); 23 | } 24 | // 统一获取平台 25 | protected function getQuestion($column){ 26 | if($column){ 27 | foreach ($column as $item) { 28 | $this->arr[$this->itemi]["title"]= $this->fixSpaces(pq($item)->html()); 29 | $this->arr[$this->itemi]["date"] = $this->fixSpaces(pq($item)->parent()->prev(".zm-profile-setion-time")->html()); 30 | $this->arr[$this->itemi]["url"]= $this->fixUrl(pq($item)->attr("href")); 31 | pq($item)->parent()->find("a")->html(""); //删掉链接 32 | $this->arr[$this->itemi]["status"] = $this->fixSpaces(pq($item)->parent()->text()); 33 | pq($item)->parent()->parent()->find(".zh-summary")->find(".toggle-expand")->html(""); // 删掉阅读全文 34 | $this->arr[$this->itemi]["description"] = $this->fixSpaces(pq($item)->parent()->parent()->find(".zh-summary")->text()); 35 | $this->itemi++; 36 | } 37 | } 38 | return $this->arr; 39 | } 40 | // 修正Url 41 | protected function fixUrl($url){ 42 | if($url[0]=='/'){ 43 | return "http://www.zhihu.com".$url; 44 | } 45 | else return $url; 46 | } 47 | // 删除多余空格 回车 48 | protected function fixSpaces($str){ 49 | // @gengqiupeng: fix bug我的账号会报 Uninitialized string offset: 0的错误 50 | while(!empty($str[0])&&($str[0]==" " || $str[0]==" " || $str[0]=="\n")){ 51 | $str = substr($str,1); 52 | } 53 | return $str; 54 | } 55 | // 销毁phpQuery 56 | function __destruct() { 57 | phpQuery::unloadDocuments(); 58 | } 59 | } 60 | ?> 61 | 62 | 63 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | init(); 49 | if ($method == "list") { 50 | echo $p; 51 | } else { 52 | try { 53 | if (method_exists($p, $method)) { // 检测是否存在这个方法 54 | echo json_encode($p->$method()); // json encode 请求的方法 55 | 56 | } else { 57 | throw new Exception('API method is not exist'); 58 | } 59 | } 60 | catch(Exception $e) { 61 | echo json_encode(array("status"=>"fail","error"=>$e->getMessage())); 62 | } 63 | } 64 | } 65 | }else{ 66 | throw new Exception('API is not exist'); 67 | } 68 | }catch(Exception $e) { 69 | echo json_encode(array("status"=>"fail","error"=>$e->getMessage())); 70 | } 71 | }else { 72 | throw new Exception('Request error'); 73 | } 74 | }catch(Exception $e) { 75 | echo json_encode(array("status"=>"fail","error"=>$e->getMessage())); 76 | } 77 | ?> -------------------------------------------------------------------------------- /API/User.php: -------------------------------------------------------------------------------- 1 | html(); 13 | return $q; 14 | } 15 | // 获取个性签名 16 | public function getBio(){ 17 | $q = pq(".title-section .bio")->html(); 18 | return $q; 19 | } 20 | // 获取地点 21 | public function getLocation(){ 22 | $q = pq(".info-wrap .location")->find("a")->html(); 23 | return $q; 24 | } 25 | // 获取领域 26 | public function getBusiness(){ 27 | $q = pq(".info-wrap .business")->find("a")->html(); 28 | return $q; 29 | } 30 | // 获取性别 31 | public function getGender(){ 32 | $q = pq(".info-wrap .gender")->find("i")->attr("class"); 33 | return $this->__fixGender($q); 34 | } 35 | // 获取关注和粉丝 36 | public function getFollow(){ 37 | $i =0; 38 | $q = pq(".zm-profile-side-following .item")->find("strong"); 39 | foreach ($q as $item) { 40 | $arr[$i] = pq($item)->html(); 41 | $i++; 42 | } 43 | return array("following" =>$arr[0], "follower"=>$arr[1]); 44 | } 45 | // 获得赞同 46 | public function getAgree(){ 47 | $q = pq(".zm-profile-header-user-agree")->find("strong")->html(); 48 | return $q; 49 | } 50 | // 获得感谢 51 | public function getThanks(){ 52 | $q = pq(".zm-profile-header-user-thanks")->find("strong")->html(); 53 | return $q; 54 | } 55 | // 将性别显示男或女 56 | private function __fixGender($classname){ 57 | if(stristr($classname,"female")){ 58 | return "女"; 59 | }else{ 60 | return "男"; 61 | } 62 | } 63 | // toString方法 返回 类型、拉取的数量、最后输出json 64 | function __toString(){ 65 | $this->detail["type"] = "User"; 66 | $this->detail["name"] = $this->getName(); 67 | $this->detail["gender"] = $this->getGender(); 68 | $this->detail["bio"] = $this->getBio(); 69 | $this->detail["location"] = $this->getLocation(); 70 | $this->detail["business"] = $this->getBusiness(); 71 | $this->detail["follow"] = $this->getFollow(); 72 | $this->detail["agree"] = $this->getAgree(); 73 | $this->detail["thanks"] = $this->getThanks(); 74 | //让php支持json中文编码 75 | return json_encode($this->detail,JSON_UNESCAPED_UNICODE); 76 | } 77 | } 78 | ?> -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Hostname/De.php: -------------------------------------------------------------------------------- 1 | 8 | * @package phpQuery 9 | * @todo implement ArrayAccess ? 10 | */ 11 | class DOMEvent { 12 | /** 13 | * Returns a boolean indicating whether the event bubbles up through the DOM or not. 14 | * 15 | * @var unknown_type 16 | */ 17 | public $bubbles = true; 18 | /** 19 | * Returns a boolean indicating whether the event is cancelable. 20 | * 21 | * @var unknown_type 22 | */ 23 | public $cancelable = true; 24 | /** 25 | * Returns a reference to the currently registered target for the event. 26 | * 27 | * @var unknown_type 28 | */ 29 | public $currentTarget; 30 | /** 31 | * Returns detail about the event, depending on the type of event. 32 | * 33 | * @var unknown_type 34 | * @link http://developer.mozilla.org/en/DOM/event.detail 35 | */ 36 | public $detail; // ??? 37 | /** 38 | * Used to indicate which phase of the event flow is currently being evaluated. 39 | * 40 | * NOT IMPLEMENTED 41 | * 42 | * @var unknown_type 43 | * @link http://developer.mozilla.org/en/DOM/event.eventPhase 44 | */ 45 | public $eventPhase; // ??? 46 | /** 47 | * The explicit original target of the event (Mozilla-specific). 48 | * 49 | * NOT IMPLEMENTED 50 | * 51 | * @var unknown_type 52 | */ 53 | public $explicitOriginalTarget; // moz only 54 | /** 55 | * The original target of the event, before any retargetings (Mozilla-specific). 56 | * 57 | * NOT IMPLEMENTED 58 | * 59 | * @var unknown_type 60 | */ 61 | public $originalTarget; // moz only 62 | /** 63 | * Identifies a secondary target for the event. 64 | * 65 | * @var unknown_type 66 | */ 67 | public $relatedTarget; 68 | /** 69 | * Returns a reference to the target to which the event was originally dispatched. 70 | * 71 | * @var unknown_type 72 | */ 73 | public $target; 74 | /** 75 | * Returns the time that the event was created. 76 | * 77 | * @var unknown_type 78 | */ 79 | public $timeStamp; 80 | /** 81 | * Returns the name of the event (case-insensitive). 82 | */ 83 | public $type; 84 | public $runDefault = true; 85 | public $data = null; 86 | public function __construct($data) { 87 | foreach($data as $k => $v) { 88 | $this->$k = $v; 89 | } 90 | if (! $this->timeStamp) 91 | $this->timeStamp = time(); 92 | } 93 | /** 94 | * Cancels the event (if it is cancelable). 95 | * 96 | */ 97 | public function preventDefault() { 98 | $this->runDefault = false; 99 | } 100 | /** 101 | * Stops the propagation of events further along in the DOM. 102 | * 103 | */ 104 | public function stopPropagation() { 105 | $this->bubbles = false; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/File/NotExists.php: -------------------------------------------------------------------------------- 1 | "The file '%value%' does exist" 47 | ); 48 | 49 | /** 50 | * Defined by Zend_Validate_Interface 51 | * 52 | * Returns true if and only if the file does not exist in the set destinations 53 | * 54 | * @param string $value Real file to check for 55 | * @param array $file File data from Zend_File_Transfer 56 | * @return boolean 57 | */ 58 | public function isValid($value, $file = null) 59 | { 60 | $directories = $this->getDirectory(true); 61 | if (($file !== null) and (!empty($file['destination']))) { 62 | $directories[] = $file['destination']; 63 | } else if (!isset($file['name'])) { 64 | $file['name'] = $value; 65 | } 66 | 67 | foreach ($directories as $directory) { 68 | if (empty($directory)) { 69 | continue; 70 | } 71 | 72 | $check = true; 73 | if (file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) { 74 | $this->_throw($file, self::DOES_EXIST); 75 | return false; 76 | } 77 | } 78 | 79 | if (!isset($check)) { 80 | $this->_throw($file, self::DOES_EXIST); 81 | return false; 82 | } 83 | 84 | return true; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/LessThan.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not less than '%max%'" 46 | ); 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $_messageVariables = array( 52 | 'max' => '_max' 53 | ); 54 | 55 | /** 56 | * Maximum value 57 | * 58 | * @var mixed 59 | */ 60 | protected $_max; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param mixed $max 66 | * @return void 67 | */ 68 | public function __construct($max) 69 | { 70 | $this->setMax($max); 71 | } 72 | 73 | /** 74 | * Returns the max option 75 | * 76 | * @return mixed 77 | */ 78 | public function getMax() 79 | { 80 | return $this->_max; 81 | } 82 | 83 | /** 84 | * Sets the max option 85 | * 86 | * @param mixed $max 87 | * @return Zend_Validate_LessThan Provides a fluent interface 88 | */ 89 | public function setMax($max) 90 | { 91 | $this->_max = $max; 92 | return $this; 93 | } 94 | 95 | /** 96 | * Defined by Zend_Validate_Interface 97 | * 98 | * Returns true if and only if $value is less than max option 99 | * 100 | * @param mixed $value 101 | * @return boolean 102 | */ 103 | public function isValid($value) 104 | { 105 | $this->_setValue($value); 106 | if ($this->_max <= $value) { 107 | $this->_error(); 108 | return false; 109 | } 110 | return true; 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/GreaterThan.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not greater than '%min%'" 46 | ); 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $_messageVariables = array( 52 | 'min' => '_min' 53 | ); 54 | 55 | /** 56 | * Minimum value 57 | * 58 | * @var mixed 59 | */ 60 | protected $_min; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param mixed $min 66 | * @return void 67 | */ 68 | public function __construct($min) 69 | { 70 | $this->setMin($min); 71 | } 72 | 73 | /** 74 | * Returns the min option 75 | * 76 | * @return mixed 77 | */ 78 | public function getMin() 79 | { 80 | return $this->_min; 81 | } 82 | 83 | /** 84 | * Sets the min option 85 | * 86 | * @param mixed $min 87 | * @return Zend_Validate_GreaterThan Provides a fluent interface 88 | */ 89 | public function setMin($min) 90 | { 91 | $this->_min = $min; 92 | return $this; 93 | } 94 | 95 | /** 96 | * Defined by Zend_Validate_Interface 97 | * 98 | * Returns true if and only if $value is greater than min option 99 | * 100 | * @param mixed $value 101 | * @return boolean 102 | */ 103 | public function isValid($value) 104 | { 105 | $this->_setValue($value); 106 | 107 | if ($this->_min >= $value) { 108 | $this->_error(); 109 | return false; 110 | } 111 | return true; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Digits.php: -------------------------------------------------------------------------------- 1 | "'%value%' contains not only digit characters", 62 | self::STRING_EMPTY => "'%value%' is an empty string" 63 | ); 64 | 65 | /** 66 | * Defined by Zend_Validate_Interface 67 | * 68 | * Returns true if and only if $value only contains digit characters 69 | * 70 | * @param string $value 71 | * @return boolean 72 | */ 73 | public function isValid($value) 74 | { 75 | $valueString = (string) $value; 76 | 77 | $this->_setValue($valueString); 78 | 79 | if ('' === $valueString) { 80 | $this->_error(self::STRING_EMPTY); 81 | return false; 82 | } 83 | 84 | if (null === self::$_filter) { 85 | /** 86 | * @see Zend_Filter_Digits 87 | */ 88 | require_once 'Zend/Filter/Digits.php'; 89 | self::$_filter = new Zend_Filter_Digits(); 90 | } 91 | 92 | if ($valueString !== self::$_filter->filter($valueString)) { 93 | $this->_error(self::NOT_DIGITS); 94 | return false; 95 | } 96 | 97 | return true; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Barcode/UpcA.php: -------------------------------------------------------------------------------- 1 | "'%value%' is an invalid UPC-A barcode", 57 | self::INVALID_LENGTH => "'%value%' should be 12 characters", 58 | ); 59 | 60 | /** 61 | * Defined by Zend_Validate_Interface 62 | * 63 | * Returns true if and only if $value contains a valid barcode 64 | * 65 | * @param string $value 66 | * @return boolean 67 | */ 68 | public function isValid($value) 69 | { 70 | $valueString = (string) $value; 71 | $this->_setValue($valueString); 72 | 73 | if (strlen($valueString) !== 12) { 74 | $this->_error(self::INVALID_LENGTH); 75 | return false; 76 | } 77 | 78 | $barcode = substr($valueString, 0, -1); 79 | $oddSum = 0; 80 | $evenSum = 0; 81 | 82 | for ($i = 0; $i < 11; $i++) { 83 | if ($i % 2 === 0) { 84 | $oddSum += $barcode[$i] * 3; 85 | } elseif ($i % 2 === 1) { 86 | $evenSum += $barcode[$i]; 87 | } 88 | } 89 | 90 | $calculation = ($oddSum + $evenSum) % 10; 91 | $checksum = ($calculation === 0) ? 0 : 10 - $calculation; 92 | 93 | if ($valueString[11] != $checksum) { 94 | $this->_error(self::INVALID); 95 | return false; 96 | } 97 | 98 | return true; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Barcode.php: -------------------------------------------------------------------------------- 1 | setType($barcodeType); 55 | } 56 | 57 | /** 58 | * Sets a new barcode validator 59 | * 60 | * @param string $barcodeType - Barcode validator to use 61 | * @return void 62 | * @throws Zend_Validate_Exception 63 | */ 64 | public function setType($barcodeType) 65 | { 66 | switch (strtolower($barcodeType)) { 67 | case 'upc': 68 | case 'upc-a': 69 | $className = 'UpcA'; 70 | break; 71 | case 'ean13': 72 | case 'ean-13': 73 | $className = 'Ean13'; 74 | break; 75 | default: 76 | require_once 'Zend/Validate/Exception.php'; 77 | throw new Zend_Validate_Exception("Barcode type '$barcodeType' is not supported'"); 78 | break; 79 | } 80 | 81 | require_once 'Zend/Validate/Barcode/' . $className . '.php'; 82 | 83 | $class = 'Zend_Validate_Barcode_' . $className; 84 | $this->_barcodeValidator = new $class; 85 | } 86 | 87 | /** 88 | * Defined by Zend_Validate_Interface 89 | * 90 | * Returns true if and only if $value contains a valid barcode 91 | * 92 | * @param string $value 93 | * @return boolean 94 | */ 95 | public function isValid($value) 96 | { 97 | return call_user_func(array($this->_barcodeValidator, 'isValid'), $value); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Barcode/Ean13.php: -------------------------------------------------------------------------------- 1 | "'%value%' is an invalid EAN-13 barcode", 57 | self::INVALID_LENGTH => "'%value%' should be 13 characters", 58 | ); 59 | 60 | /** 61 | * Defined by Zend_Validate_Interface 62 | * 63 | * Returns true if and only if $value contains a valid barcode 64 | * 65 | * @param string $value 66 | * @return boolean 67 | */ 68 | public function isValid($value) 69 | { 70 | $valueString = (string) $value; 71 | $this->_setValue($valueString); 72 | 73 | if (strlen($valueString) !== 13) { 74 | $this->_error(self::INVALID_LENGTH); 75 | return false; 76 | } 77 | 78 | $barcode = strrev(substr($valueString, 0, -1)); 79 | $oddSum = 0; 80 | $evenSum = 0; 81 | 82 | for ($i = 0; $i < 12; $i++) { 83 | if ($i % 2 === 0) { 84 | $oddSum += $barcode[$i] * 3; 85 | } elseif ($i % 2 === 1) { 86 | $evenSum += $barcode[$i]; 87 | } 88 | } 89 | 90 | $calculation = ($oddSum + $evenSum) % 10; 91 | $checksum = ($calculation === 0) ? 0 : 10 - $calculation; 92 | 93 | if ($valueString[12] != $checksum) { 94 | $this->_error(self::INVALID); 95 | return false; 96 | } 97 | 98 | return true; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Identical.php: -------------------------------------------------------------------------------- 1 | 'Tokens do not match', 47 | self::MISSING_TOKEN => 'No token was provided to match against', 48 | ); 49 | 50 | /** 51 | * Original token against which to validate 52 | * @var string 53 | */ 54 | protected $_token; 55 | 56 | /** 57 | * Sets validator options 58 | * 59 | * @param string $token 60 | * @return void 61 | */ 62 | public function __construct($token = null) 63 | { 64 | if (null !== $token) { 65 | $this->setToken($token); 66 | } 67 | } 68 | 69 | /** 70 | * Set token against which to compare 71 | * 72 | * @param string $token 73 | * @return Zend_Validate_Identical 74 | */ 75 | public function setToken($token) 76 | { 77 | $this->_token = (string) $token; 78 | return $this; 79 | } 80 | 81 | /** 82 | * Retrieve token 83 | * 84 | * @return string 85 | */ 86 | public function getToken() 87 | { 88 | return $this->_token; 89 | } 90 | 91 | /** 92 | * Defined by Zend_Validate_Interface 93 | * 94 | * Returns true if and only if a token has been set and the provided value 95 | * matches that token. 96 | * 97 | * @param string $value 98 | * @return boolean 99 | */ 100 | public function isValid($value) 101 | { 102 | $this->_setValue($value); 103 | $token = $this->getToken(); 104 | 105 | if (empty($token)) { 106 | $this->_error(self::MISSING_TOKEN); 107 | return false; 108 | } 109 | 110 | if ($value !== $token) { 111 | $this->_error(self::NOT_SAME); 112 | return false; 113 | } 114 | 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Ccnum.php: -------------------------------------------------------------------------------- 1 | "'%value%' must contain between 13 and 19 digits", 62 | self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'" 63 | ); 64 | 65 | /** 66 | * Defined by Zend_Validate_Interface 67 | * 68 | * Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum) 69 | * 70 | * @param string $value 71 | * @return boolean 72 | */ 73 | public function isValid($value) 74 | { 75 | $this->_setValue($value); 76 | 77 | if (null === self::$_filter) { 78 | /** 79 | * @see Zend_Filter_Digits 80 | */ 81 | require_once 'Zend/Filter/Digits.php'; 82 | self::$_filter = new Zend_Filter_Digits(); 83 | } 84 | 85 | $valueFiltered = self::$_filter->filter($value); 86 | 87 | $length = strlen($valueFiltered); 88 | 89 | if ($length < 13 || $length > 19) { 90 | $this->_error(self::LENGTH); 91 | return false; 92 | } 93 | 94 | $sum = 0; 95 | $weight = 2; 96 | 97 | for ($i = $length - 2; $i >= 0; $i--) { 98 | $digit = $weight * $valueFiltered[$i]; 99 | $sum += floor($digit / 10) + $digit % 10; 100 | $weight = $weight % 2 + 1; 101 | } 102 | 103 | if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) { 104 | $this->_error(self::CHECKSUM, $valueFiltered); 105 | return false; 106 | } 107 | 108 | return true; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Regex.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not match against pattern '%pattern%'" 46 | ); 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $_messageVariables = array( 52 | 'pattern' => '_pattern' 53 | ); 54 | 55 | /** 56 | * Regular expression pattern 57 | * 58 | * @var string 59 | */ 60 | protected $_pattern; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param string $pattern 66 | * @return void 67 | */ 68 | public function __construct($pattern) 69 | { 70 | $this->setPattern($pattern); 71 | } 72 | 73 | /** 74 | * Returns the pattern option 75 | * 76 | * @return string 77 | */ 78 | public function getPattern() 79 | { 80 | return $this->_pattern; 81 | } 82 | 83 | /** 84 | * Sets the pattern option 85 | * 86 | * @param string $pattern 87 | * @return Zend_Validate_Regex Provides a fluent interface 88 | */ 89 | public function setPattern($pattern) 90 | { 91 | $this->_pattern = (string) $pattern; 92 | return $this; 93 | } 94 | 95 | /** 96 | * Defined by Zend_Validate_Interface 97 | * 98 | * Returns true if and only if $value matches against the pattern option 99 | * 100 | * @param string $value 101 | * @throws Zend_Validate_Exception if there is a fatal error in pattern matching 102 | * @return boolean 103 | */ 104 | public function isValid($value) 105 | { 106 | $valueString = (string) $value; 107 | 108 | $this->_setValue($valueString); 109 | 110 | $status = @preg_match($this->_pattern, $valueString); 111 | if (false === $status) { 112 | /** 113 | * @see Zend_Validate_Exception 114 | */ 115 | require_once 'Zend/Validate/Exception.php'; 116 | throw new Zend_Validate_Exception("Internal error matching pattern '$this->_pattern' against value '$valueString'"); 117 | } 118 | if (!$status) { 119 | $this->_error(); 120 | return false; 121 | } 122 | return true; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Alpha.php: -------------------------------------------------------------------------------- 1 | "'%value%' has not only alphabetic characters", 69 | self::STRING_EMPTY => "'%value%' is an empty string" 70 | ); 71 | 72 | /** 73 | * Sets default option values for this instance 74 | * 75 | * @param boolean $allowWhiteSpace 76 | * @return void 77 | */ 78 | public function __construct($allowWhiteSpace = false) 79 | { 80 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 81 | } 82 | 83 | /** 84 | * Defined by Zend_Validate_Interface 85 | * 86 | * Returns true if and only if $value contains only alphabetic characters 87 | * 88 | * @param string $value 89 | * @return boolean 90 | */ 91 | public function isValid($value) 92 | { 93 | $valueString = (string) $value; 94 | 95 | $this->_setValue($valueString); 96 | 97 | if ('' === $valueString) { 98 | $this->_error(self::STRING_EMPTY); 99 | return false; 100 | } 101 | 102 | if (null === self::$_filter) { 103 | /** 104 | * @see Zend_Filter_Alpha 105 | */ 106 | require_once 'Zend/Filter/Alpha.php'; 107 | self::$_filter = new Zend_Filter_Alpha(); 108 | } 109 | 110 | self::$_filter->allowWhiteSpace = $this->allowWhiteSpace; 111 | 112 | if ($valueString !== self::$_filter->filter($valueString)) { 113 | $this->_error(self::NOT_ALPHA); 114 | return false; 115 | } 116 | 117 | return true; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Alnum.php: -------------------------------------------------------------------------------- 1 | "'%value%' has not only alphabetic and digit characters", 69 | self::STRING_EMPTY => "'%value%' is an empty string" 70 | ); 71 | 72 | /** 73 | * Sets default option values for this instance 74 | * 75 | * @param boolean $allowWhiteSpace 76 | * @return void 77 | */ 78 | public function __construct($allowWhiteSpace = false) 79 | { 80 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 81 | } 82 | 83 | /** 84 | * Defined by Zend_Validate_Interface 85 | * 86 | * Returns true if and only if $value contains only alphabetic and digit characters 87 | * 88 | * @param string $value 89 | * @return boolean 90 | */ 91 | public function isValid($value) 92 | { 93 | $valueString = (string) $value; 94 | 95 | $this->_setValue($valueString); 96 | 97 | if ('' === $valueString) { 98 | $this->_error(self::STRING_EMPTY); 99 | return false; 100 | } 101 | 102 | if (null === self::$_filter) { 103 | /** 104 | * @see Zend_Filter_Alnum 105 | */ 106 | require_once 'Zend/Filter/Alnum.php'; 107 | self::$_filter = new Zend_Filter_Alnum(); 108 | } 109 | 110 | self::$_filter->allowWhiteSpace = $this->allowWhiteSpace; 111 | 112 | if ($valueString !== self::$_filter->filter($valueString)) { 113 | $this->_error(self::NOT_ALNUM); 114 | return false; 115 | } 116 | 117 | return true; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/InArray.php: -------------------------------------------------------------------------------- 1 | "'%value%' was not found in the haystack" 46 | ); 47 | 48 | /** 49 | * Haystack of possible values 50 | * 51 | * @var array 52 | */ 53 | protected $_haystack; 54 | 55 | /** 56 | * Whether a strict in_array() invocation is used 57 | * 58 | * @var boolean 59 | */ 60 | protected $_strict; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param array $haystack 66 | * @param boolean $strict 67 | * @return void 68 | */ 69 | public function __construct(array $haystack, $strict = false) 70 | { 71 | $this->setHaystack($haystack) 72 | ->setStrict($strict); 73 | } 74 | 75 | /** 76 | * Returns the haystack option 77 | * 78 | * @return mixed 79 | */ 80 | public function getHaystack() 81 | { 82 | return $this->_haystack; 83 | } 84 | 85 | /** 86 | * Sets the haystack option 87 | * 88 | * @param mixed $haystack 89 | * @return Zend_Validate_InArray Provides a fluent interface 90 | */ 91 | public function setHaystack(array $haystack) 92 | { 93 | $this->_haystack = $haystack; 94 | return $this; 95 | } 96 | 97 | /** 98 | * Returns the strict option 99 | * 100 | * @return boolean 101 | */ 102 | public function getStrict() 103 | { 104 | return $this->_strict; 105 | } 106 | 107 | /** 108 | * Sets the strict option 109 | * 110 | * @param boolean $strict 111 | * @return Zend_Validate_InArray Provides a fluent interface 112 | */ 113 | public function setStrict($strict) 114 | { 115 | $this->_strict = $strict; 116 | return $this; 117 | } 118 | 119 | /** 120 | * Defined by Zend_Validate_Interface 121 | * 122 | * Returns true if and only if $value is contained in the haystack option. If the strict 123 | * option is true, then the type of $value is also checked. 124 | * 125 | * @param mixed $value 126 | * @return boolean 127 | */ 128 | public function isValid($value) 129 | { 130 | $this->_setValue($value); 131 | if (!in_array($value, $this->_haystack, $this->_strict)) { 132 | $this->_error(); 133 | return false; 134 | } 135 | return true; 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Callback.php: -------------------------------------------------------------------------------- 1 | 25 | * 26 | * @TODO??? return fake forwarding function created via create_function 27 | * @TODO honor paramStructure 28 | */ 29 | class Callback 30 | implements ICallbackNamed { 31 | public $callback = null; 32 | public $params = null; 33 | protected $name; 34 | public function __construct($callback, $param1 = null, $param2 = null, 35 | $param3 = null) { 36 | $params = func_get_args(); 37 | $params = array_slice($params, 1); 38 | if ($callback instanceof Callback) { 39 | // TODO implement recurention 40 | } else { 41 | $this->callback = $callback; 42 | $this->params = $params; 43 | } 44 | } 45 | public function getName() { 46 | return 'Callback: '.$this->name; 47 | } 48 | public function hasName() { 49 | return isset($this->name) && $this->name; 50 | } 51 | public function setName($name) { 52 | $this->name = $name; 53 | return $this; 54 | } 55 | // TODO test me 56 | // public function addParams() { 57 | // $params = func_get_args(); 58 | // return new Callback($this->callback, $this->params+$params); 59 | // } 60 | } 61 | /** 62 | * Shorthand for new Callback(create_function(...), ...); 63 | * 64 | * @author Tobiasz Cudnik 65 | */ 66 | class CallbackBody extends Callback { 67 | public function __construct($paramList, $code, $param1 = null, $param2 = null, 68 | $param3 = null) { 69 | $params = func_get_args(); 70 | $params = array_slice($params, 2); 71 | $this->callback = create_function($paramList, $code); 72 | $this->params = $params; 73 | } 74 | } 75 | /** 76 | * Callback type which on execution returns reference passed during creation. 77 | * 78 | * @author Tobiasz Cudnik 79 | */ 80 | class CallbackReturnReference extends Callback 81 | implements ICallbackNamed { 82 | protected $reference; 83 | public function __construct(&$reference, $name = null){ 84 | $this->reference =& $reference; 85 | $this->callback = array($this, 'callback'); 86 | } 87 | public function callback() { 88 | return $this->reference; 89 | } 90 | public function getName() { 91 | return 'Callback: '.$this->name; 92 | } 93 | public function hasName() { 94 | return isset($this->name) && $this->name; 95 | } 96 | } 97 | /** 98 | * Callback type which on execution returns value passed during creation. 99 | * 100 | * @author Tobiasz Cudnik 101 | */ 102 | class CallbackReturnValue extends Callback 103 | implements ICallbackNamed { 104 | protected $value; 105 | protected $name; 106 | public function __construct($value, $name = null){ 107 | $this->value =& $value; 108 | $this->name = $name; 109 | $this->callback = array($this, 'callback'); 110 | } 111 | public function callback() { 112 | return $this->value; 113 | } 114 | public function __toString() { 115 | return $this->getName(); 116 | } 117 | public function getName() { 118 | return 'Callback: '.$this->name; 119 | } 120 | public function hasName() { 121 | return isset($this->name) && $this->name; 122 | } 123 | } 124 | /** 125 | * CallbackParameterToReference can be used when we don't really want a callback, 126 | * only parameter passed to it. CallbackParameterToReference takes first 127 | * parameter's value and passes it to reference. 128 | * 129 | * @author Tobiasz Cudnik 130 | */ 131 | class CallbackParameterToReference extends Callback { 132 | /** 133 | * @param $reference 134 | * @TODO implement $paramIndex; 135 | * param index choose which callback param will be passed to reference 136 | */ 137 | public function __construct(&$reference){ 138 | $this->callback =& $reference; 139 | } 140 | } 141 | //class CallbackReference extends Callback { 142 | // /** 143 | // * 144 | // * @param $reference 145 | // * @param $paramIndex 146 | // * @todo implement $paramIndex; param index choose which callback param will be passed to reference 147 | // */ 148 | // public function __construct(&$reference, $name = null){ 149 | // $this->callback =& $reference; 150 | // } 151 | //} 152 | class CallbackParam {} -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/File/FilesSize.php: -------------------------------------------------------------------------------- 1 | "The files in sum exceed the maximum allowed size", 49 | self::TOO_SMALL => "All files are in sum smaller than required", 50 | self::NOT_READABLE => "One or more files can not be read" 51 | ); 52 | 53 | /** 54 | * @var array Error message template variables 55 | */ 56 | protected $_messageVariables = array( 57 | 'min' => '_min', 58 | 'max' => '_max' 59 | ); 60 | 61 | /** 62 | * Minimum filesize 63 | * 64 | * @var integer 65 | */ 66 | protected $_min; 67 | 68 | /** 69 | * Maximum filesize 70 | * 71 | * @var integer|null 72 | */ 73 | protected $_max; 74 | 75 | /** 76 | * Internal file array 77 | * 78 | * @var array 79 | */ 80 | protected $_files; 81 | 82 | /** 83 | * Internal file size counter 84 | * 85 | * @var integer 86 | */ 87 | protected $_size; 88 | 89 | /** 90 | * Sets validator options 91 | * 92 | * Min limits the used diskspace for all files, when used with max=null it is the maximum filesize 93 | * It also accepts an array with the keys 'min' and 'max' 94 | * 95 | * @param integer|array $min Minimum diskspace for all files 96 | * @param integer $max Maximum diskspace for all files 97 | * @return void 98 | */ 99 | public function __construct($min, $max = null) 100 | { 101 | $this->_files = array(); 102 | $this->_size = 0; 103 | parent::__construct($min, $max); 104 | } 105 | 106 | /** 107 | * Defined by Zend_Validate_Interface 108 | * 109 | * Returns true if and only if the disk usage of all files is at least min and 110 | * not bigger than max (when max is not null). 111 | * 112 | * @param string|array $value Real file to check for size 113 | * @param array $file File data from Zend_File_Transfer 114 | * @return boolean 115 | */ 116 | public function isValid($value, $file = null) 117 | { 118 | if (is_string($value)) { 119 | $value = array($value); 120 | } 121 | 122 | foreach ($value as $files) { 123 | // Is file readable ? 124 | if (!@is_readable($files)) { 125 | $this->_throw($file, self::NOT_READABLE); 126 | return false; 127 | } 128 | 129 | if (!isset($this->_files[$files])) { 130 | $this->_files[$files] = $files; 131 | } else { 132 | // file already counted... do not count twice 133 | continue; 134 | } 135 | 136 | // limited to 2GB files 137 | $size = @filesize($files); 138 | $this->_size += $size; 139 | $this->_setValue($this->_size); 140 | if (($this->_max !== null) && ($this->_max < $this->_size)) { 141 | $this->_throw($file, self::TOO_BIG); 142 | } 143 | } 144 | 145 | // Check that aggregate files are >= minimum size 146 | if (($this->_min !== null) && ($this->_size < $this->_min)) { 147 | $this->_throw($file, self::TOO_SMALL); 148 | } 149 | 150 | if (count($this->_messages) > 0) { 151 | return false; 152 | } else { 153 | return true; 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/StringLength.php: -------------------------------------------------------------------------------- 1 | "'%value%' is less than %min% characters long", 47 | self::TOO_LONG => "'%value%' is greater than %max% characters long" 48 | ); 49 | 50 | /** 51 | * @var array 52 | */ 53 | protected $_messageVariables = array( 54 | 'min' => '_min', 55 | 'max' => '_max' 56 | ); 57 | 58 | /** 59 | * Minimum length 60 | * 61 | * @var integer 62 | */ 63 | protected $_min; 64 | 65 | /** 66 | * Maximum length 67 | * 68 | * If null, there is no maximum length 69 | * 70 | * @var integer|null 71 | */ 72 | protected $_max; 73 | 74 | /** 75 | * Sets validator options 76 | * 77 | * @param integer $min 78 | * @param integer $max 79 | * @return void 80 | */ 81 | public function __construct($min = 0, $max = null) 82 | { 83 | $this->setMin($min); 84 | $this->setMax($max); 85 | } 86 | 87 | /** 88 | * Returns the min option 89 | * 90 | * @return integer 91 | */ 92 | public function getMin() 93 | { 94 | return $this->_min; 95 | } 96 | 97 | /** 98 | * Sets the min option 99 | * 100 | * @param integer $min 101 | * @throws Zend_Validate_Exception 102 | * @return Zend_Validate_StringLength Provides a fluent interface 103 | */ 104 | public function setMin($min) 105 | { 106 | if (null !== $this->_max && $min > $this->_max) { 107 | /** 108 | * @see Zend_Validate_Exception 109 | */ 110 | require_once 'Zend/Validate/Exception.php'; 111 | throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum length, but $min >" 112 | . " $this->_max"); 113 | } 114 | $this->_min = max(0, (integer) $min); 115 | return $this; 116 | } 117 | 118 | /** 119 | * Returns the max option 120 | * 121 | * @return integer|null 122 | */ 123 | public function getMax() 124 | { 125 | return $this->_max; 126 | } 127 | 128 | /** 129 | * Sets the max option 130 | * 131 | * @param integer|null $max 132 | * @throws Zend_Validate_Exception 133 | * @return Zend_Validate_StringLength Provides a fluent interface 134 | */ 135 | public function setMax($max) 136 | { 137 | if (null === $max) { 138 | $this->_max = null; 139 | } else if ($max < $this->_min) { 140 | /** 141 | * @see Zend_Validate_Exception 142 | */ 143 | require_once 'Zend/Validate/Exception.php'; 144 | throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum length, but " 145 | . "$max < $this->_min"); 146 | } else { 147 | $this->_max = (integer) $max; 148 | } 149 | 150 | return $this; 151 | } 152 | 153 | /** 154 | * Defined by Zend_Validate_Interface 155 | * 156 | * Returns true if and only if the string length of $value is at least the min option and 157 | * no greater than the max option (when the max option is not null). 158 | * 159 | * @param string $value 160 | * @return boolean 161 | */ 162 | public function isValid($value) 163 | { 164 | $valueString = (string) $value; 165 | $this->_setValue($valueString); 166 | $length = iconv_strlen($valueString); 167 | if ($length < $this->_min) { 168 | $this->_error(self::TOO_SHORT); 169 | } 170 | if (null !== $this->_max && $this->_max < $length) { 171 | $this->_error(self::TOO_LONG); 172 | } 173 | if (count($this->_messages)) { 174 | return false; 175 | } else { 176 | return true; 177 | } 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Between.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not between '%min%' and '%max%', inclusively", 55 | self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%'" 56 | ); 57 | 58 | /** 59 | * Additional variables available for validation failure messages 60 | * 61 | * @var array 62 | */ 63 | protected $_messageVariables = array( 64 | 'min' => '_min', 65 | 'max' => '_max' 66 | ); 67 | 68 | /** 69 | * Minimum value 70 | * 71 | * @var mixed 72 | */ 73 | protected $_min; 74 | 75 | /** 76 | * Maximum value 77 | * 78 | * @var mixed 79 | */ 80 | protected $_max; 81 | 82 | /** 83 | * Whether to do inclusive comparisons, allowing equivalence to min and/or max 84 | * 85 | * If false, then strict comparisons are done, and the value may equal neither 86 | * the min nor max options 87 | * 88 | * @var boolean 89 | */ 90 | protected $_inclusive; 91 | 92 | /** 93 | * Sets validator options 94 | * 95 | * @param mixed $min 96 | * @param mixed $max 97 | * @param boolean $inclusive 98 | * @return void 99 | */ 100 | public function __construct($min, $max, $inclusive = true) 101 | { 102 | $this->setMin($min) 103 | ->setMax($max) 104 | ->setInclusive($inclusive); 105 | } 106 | 107 | /** 108 | * Returns the min option 109 | * 110 | * @return mixed 111 | */ 112 | public function getMin() 113 | { 114 | return $this->_min; 115 | } 116 | 117 | /** 118 | * Sets the min option 119 | * 120 | * @param mixed $min 121 | * @return Zend_Validate_Between Provides a fluent interface 122 | */ 123 | public function setMin($min) 124 | { 125 | $this->_min = $min; 126 | return $this; 127 | } 128 | 129 | /** 130 | * Returns the max option 131 | * 132 | * @return mixed 133 | */ 134 | public function getMax() 135 | { 136 | return $this->_max; 137 | } 138 | 139 | /** 140 | * Sets the max option 141 | * 142 | * @param mixed $max 143 | * @return Zend_Validate_Between Provides a fluent interface 144 | */ 145 | public function setMax($max) 146 | { 147 | $this->_max = $max; 148 | return $this; 149 | } 150 | 151 | /** 152 | * Returns the inclusive option 153 | * 154 | * @return boolean 155 | */ 156 | public function getInclusive() 157 | { 158 | return $this->_inclusive; 159 | } 160 | 161 | /** 162 | * Sets the inclusive option 163 | * 164 | * @param boolean $inclusive 165 | * @return Zend_Validate_Between Provides a fluent interface 166 | */ 167 | public function setInclusive($inclusive) 168 | { 169 | $this->_inclusive = $inclusive; 170 | return $this; 171 | } 172 | 173 | /** 174 | * Defined by Zend_Validate_Interface 175 | * 176 | * Returns true if and only if $value is between min and max options, inclusively 177 | * if inclusive option is true. 178 | * 179 | * @param mixed $value 180 | * @return boolean 181 | */ 182 | public function isValid($value) 183 | { 184 | $this->_setValue($value); 185 | 186 | if ($this->_inclusive) { 187 | if ($this->_min > $value || $value > $this->_max) { 188 | $this->_error(self::NOT_BETWEEN); 189 | return false; 190 | } 191 | } else { 192 | if ($this->_min >= $value || $value >= $this->_max) { 193 | $this->_error(self::NOT_BETWEEN_STRICT); 194 | return false; 195 | } 196 | } 197 | return true; 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/phpQueryEvents.php: -------------------------------------------------------------------------------- 1 | document) 33 | $pq->find('*')->add($pq->document) 34 | ->trigger($type, $data); 35 | } 36 | } else { 37 | if (isset($data[0]) && $data[0] instanceof DOMEvent) { 38 | $event = $data[0]; 39 | $event->relatedTarget = $event->target; 40 | $event->target = $node; 41 | $data = array_slice($data, 1); 42 | } else { 43 | $event = new DOMEvent(array( 44 | 'type' => $type, 45 | 'target' => $node, 46 | 'timeStamp' => time(), 47 | )); 48 | } 49 | $i = 0; 50 | while($node) { 51 | // TODO whois 52 | phpQuery::debug("Triggering ".($i?"bubbled ":'')."event '{$type}' on " 53 | ."node \n");//.phpQueryObject::whois($node)."\n"); 54 | $event->currentTarget = $node; 55 | $eventNode = self::getNode($documentID, $node); 56 | if (isset($eventNode->eventHandlers)) { 57 | foreach($eventNode->eventHandlers as $eventType => $handlers) { 58 | $eventNamespace = null; 59 | if (strpos($type, '.') !== false) 60 | list($eventName, $eventNamespace) = explode('.', $eventType); 61 | else 62 | $eventName = $eventType; 63 | if ($name != $eventName) 64 | continue; 65 | if ($namespace && $eventNamespace && $namespace != $eventNamespace) 66 | continue; 67 | foreach($handlers as $handler) { 68 | phpQuery::debug("Calling event handler\n"); 69 | $event->data = $handler['data'] 70 | ? $handler['data'] 71 | : null; 72 | $params = array_merge(array($event), $data); 73 | $return = phpQuery::callbackRun($handler['callback'], $params); 74 | if ($return === false) { 75 | $event->bubbles = false; 76 | } 77 | } 78 | } 79 | } 80 | // to bubble or not to bubble... 81 | if (! $event->bubbles) 82 | break; 83 | $node = $node->parentNode; 84 | $i++; 85 | } 86 | } 87 | } 88 | /** 89 | * Binds a handler to one or more events (like click) for each matched element. 90 | * Can also bind custom events. 91 | * 92 | * @param DOMNode|phpQueryObject|string $document 93 | * @param unknown_type $type 94 | * @param unknown_type $data Optional 95 | * @param unknown_type $callback 96 | * 97 | * @TODO support '!' (exclusive) events 98 | * @TODO support more than event in $type (space-separated) 99 | * @TODO support binding to global events 100 | */ 101 | public static function add($document, $node, $type, $data, $callback = null) { 102 | phpQuery::debug("Binding '$type' event"); 103 | $documentID = phpQuery::getDocumentID($document); 104 | // if (is_null($callback) && is_callable($data)) { 105 | // $callback = $data; 106 | // $data = null; 107 | // } 108 | $eventNode = self::getNode($documentID, $node); 109 | if (! $eventNode) 110 | $eventNode = self::setNode($documentID, $node); 111 | if (!isset($eventNode->eventHandlers[$type])) 112 | $eventNode->eventHandlers[$type] = array(); 113 | $eventNode->eventHandlers[$type][] = array( 114 | 'callback' => $callback, 115 | 'data' => $data, 116 | ); 117 | } 118 | /** 119 | * Enter description here... 120 | * 121 | * @param DOMNode|phpQueryObject|string $document 122 | * @param unknown_type $type 123 | * @param unknown_type $callback 124 | * 125 | * @TODO namespace events 126 | * @TODO support more than event in $type (space-separated) 127 | */ 128 | public static function remove($document, $node, $type = null, $callback = null) { 129 | $documentID = phpQuery::getDocumentID($document); 130 | $eventNode = self::getNode($documentID, $node); 131 | if (is_object($eventNode) && isset($eventNode->eventHandlers[$type])) { 132 | if ($callback) { 133 | foreach($eventNode->eventHandlers[$type] as $k => $handler) 134 | if ($handler['callback'] == $callback) 135 | unset($eventNode->eventHandlers[$type][$k]); 136 | } else { 137 | unset($eventNode->eventHandlers[$type]); 138 | } 139 | } 140 | } 141 | protected static function getNode($documentID, $node) { 142 | foreach(phpQuery::$documents[$documentID]->eventsNodes as $eventNode) { 143 | if ($node->isSameNode($eventNode)) 144 | return $eventNode; 145 | } 146 | } 147 | protected static function setNode($documentID, $node) { 148 | phpQuery::$documents[$documentID]->eventsNodes[] = $node; 149 | return phpQuery::$documents[$documentID]->eventsNodes[ 150 | count(phpQuery::$documents[$documentID]->eventsNodes)-1 151 | ]; 152 | } 153 | protected static function issetGlobal($documentID, $type) { 154 | return isset(phpQuery::$documents[$documentID]) 155 | ? in_array($type, phpQuery::$documents[$documentID]->eventsGlobal) 156 | : false; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Uri.php: -------------------------------------------------------------------------------- 1 | getUri(); 53 | } 54 | 55 | /** 56 | * Convenience function, checks that a $uri string is well-formed 57 | * by validating it but not returning an object. Returns TRUE if 58 | * $uri is a well-formed URI, or FALSE otherwise. 59 | * 60 | * @param string $uri The URI to check 61 | * @return boolean 62 | */ 63 | public static function check($uri) 64 | { 65 | try { 66 | $uri = self::factory($uri); 67 | } catch (Exception $e) { 68 | return false; 69 | } 70 | 71 | return $uri->valid(); 72 | } 73 | 74 | /** 75 | * Create a new Zend_Uri object for a URI. If building a new URI, then $uri should contain 76 | * only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI. 77 | * 78 | * @param string $uri The URI form which a Zend_Uri instance is created 79 | * @throws Zend_Uri_Exception When an empty string was supplied for the scheme 80 | * @throws Zend_Uri_Exception When an illegal scheme is supplied 81 | * @throws Zend_Uri_Exception When the scheme is not supported 82 | * @return Zend_Uri 83 | * @link http://www.faqs.org/rfcs/rfc2396.html 84 | */ 85 | public static function factory($uri = 'http') 86 | { 87 | // Separate the scheme from the scheme-specific parts 88 | $uri = explode(':', $uri, 2); 89 | $scheme = strtolower($uri[0]); 90 | $schemeSpecific = isset($uri[1]) === true ? $uri[1] : ''; 91 | 92 | if (strlen($scheme) === 0) { 93 | require_once 'Zend/Uri/Exception.php'; 94 | throw new Zend_Uri_Exception('An empty string was supplied for the scheme'); 95 | } 96 | 97 | // Security check: $scheme is used to load a class file, so only alphanumerics are allowed. 98 | if (ctype_alnum($scheme) === false) { 99 | require_once 'Zend/Uri/Exception.php'; 100 | throw new Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted'); 101 | } 102 | 103 | /** 104 | * Create a new Zend_Uri object for the $uri. If a subclass of Zend_Uri exists for the 105 | * scheme, return an instance of that class. Otherwise, a Zend_Uri_Exception is thrown. 106 | */ 107 | switch ($scheme) { 108 | case 'http': 109 | // Break intentionally omitted 110 | case 'https': 111 | $className = 'Zend_Uri_Http'; 112 | break; 113 | 114 | case 'mailto': 115 | // TODO 116 | default: 117 | require_once 'Zend/Uri/Exception.php'; 118 | throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported"); 119 | break; 120 | } 121 | 122 | Zend_Loader::loadClass($className); 123 | $schemeHandler = new $className($scheme, $schemeSpecific); 124 | 125 | return $schemeHandler; 126 | } 127 | 128 | /** 129 | * Get the URI's scheme 130 | * 131 | * @return string|false Scheme or false if no scheme is set. 132 | */ 133 | public function getScheme() 134 | { 135 | if (empty($this->_scheme) === false) { 136 | return $this->_scheme; 137 | } else { 138 | return false; 139 | } 140 | } 141 | 142 | /** 143 | * Zend_Uri and its subclasses cannot be instantiated directly. 144 | * Use Zend_Uri::factory() to return a new Zend_Uri object. 145 | * 146 | * @param string $scheme The scheme of the URI 147 | * @param string $schemeSpecific The scheme-specific part of the URI 148 | */ 149 | abstract protected function __construct($scheme, $schemeSpecific = ''); 150 | 151 | /** 152 | * Return a string representation of this URI. 153 | * 154 | * @return string 155 | */ 156 | abstract public function getUri(); 157 | 158 | /** 159 | * Returns TRUE if this URI is valid, or FALSE otherwise. 160 | * 161 | * @return boolean 162 | */ 163 | abstract public function valid(); 164 | } 165 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/File/Exists.php: -------------------------------------------------------------------------------- 1 | "The file '%value%' does not exist" 47 | ); 48 | 49 | /** 50 | * Internal list of directories 51 | * @var string 52 | */ 53 | protected $_directory = ''; 54 | 55 | /** 56 | * @var array Error message template variables 57 | */ 58 | protected $_messageVariables = array( 59 | 'directory' => '_directory' 60 | ); 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param string|array $directory 66 | * @return void 67 | */ 68 | public function __construct($directory = array()) 69 | { 70 | $this->setDirectory($directory); 71 | } 72 | 73 | /** 74 | * Returns the set file directories which are checked 75 | * 76 | * @param boolean $asArray Returns the values as array, when false an concated string is returned 77 | * @return string 78 | */ 79 | public function getDirectory($asArray = false) 80 | { 81 | $asArray = (bool) $asArray; 82 | $directory = (string) $this->_directory; 83 | if ($asArray) { 84 | $directory = explode(',', $directory); 85 | } 86 | 87 | return $directory; 88 | } 89 | 90 | /** 91 | * Sets the file directory which will be checked 92 | * 93 | * @param string|array $directory The directories to validate 94 | * @return Zend_Validate_File_Extension Provides a fluent interface 95 | */ 96 | public function setDirectory($directory) 97 | { 98 | $this->_directory = null; 99 | $this->addDirectory($directory); 100 | return $this; 101 | } 102 | 103 | /** 104 | * Adds the file directory which will be checked 105 | * 106 | * @param string|array $directory The directory to add for validation 107 | * @return Zend_Validate_File_Extension Provides a fluent interface 108 | */ 109 | public function addDirectory($directory) 110 | { 111 | $directories = $this->getDirectory(true); 112 | if (is_string($directory)) { 113 | $directory = explode(',', $directory); 114 | } 115 | 116 | foreach ($directory as $content) { 117 | if (empty($content) || !is_string($content)) { 118 | continue; 119 | } 120 | 121 | $directories[] = trim($content); 122 | } 123 | $directories = array_unique($directories); 124 | 125 | // Sanity check to ensure no empty values 126 | foreach ($directories as $key => $dir) { 127 | if (empty($dir)) { 128 | unset($directories[$key]); 129 | } 130 | } 131 | 132 | $this->_directory = implode(',', $directories); 133 | 134 | return $this; 135 | } 136 | 137 | /** 138 | * Defined by Zend_Validate_Interface 139 | * 140 | * Returns true if and only if the file already exists in the set directories 141 | * 142 | * @param string $value Real file to check for existance 143 | * @param array $file File data from Zend_File_Transfer 144 | * @return boolean 145 | */ 146 | public function isValid($value, $file = null) 147 | { 148 | $directories = $this->getDirectory(true); 149 | if (($file !== null) and (!empty($file['destination']))) { 150 | $directories[] = $file['destination']; 151 | } else if (!isset($file['name'])) { 152 | $file['name'] = $value; 153 | } 154 | 155 | $check = false; 156 | foreach ($directories as $directory) { 157 | if (empty($directory)) { 158 | continue; 159 | } 160 | 161 | $check = true; 162 | if (!file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) { 163 | $this->_throw($file, self::DOES_NOT_EXIST); 164 | return false; 165 | } 166 | } 167 | 168 | if (!$check) { 169 | $this->_throw($file, self::DOES_NOT_EXIST); 170 | return false; 171 | } 172 | 173 | return true; 174 | } 175 | 176 | /** 177 | * Throws an error of the given type 178 | * 179 | * @param string $file 180 | * @param string $errorType 181 | * @return false 182 | */ 183 | protected function _throw($file, $errorType) 184 | { 185 | if ($file !== null) { 186 | $this->_value = $file['name']; 187 | } 188 | 189 | $this->_error($errorType); 190 | return false; 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/File/MimeType.php: -------------------------------------------------------------------------------- 1 | "The file '%value%' has a false mimetype", 46 | self::NOT_DETECTED => "The mimetype of file '%value%' has not been detected", 47 | self::NOT_READABLE => "The file '%value%' can not be read" 48 | ); 49 | 50 | /** 51 | * @var array 52 | */ 53 | protected $_messageVariables = array( 54 | 'mimetype' => '_mimetype' 55 | ); 56 | 57 | /** 58 | * Mimetypes 59 | * 60 | * If null, there is no mimetype 61 | * 62 | * @var string|null 63 | */ 64 | protected $_mimetype; 65 | 66 | /** 67 | * Sets validator options 68 | * 69 | * Mimetype to accept 70 | * 71 | * @param string|array $mimetype MimeType 72 | * @return void 73 | */ 74 | public function __construct($mimetype) 75 | { 76 | $this->setMimeType($mimetype); 77 | } 78 | 79 | /** 80 | * Returns the set mimetypes 81 | * 82 | * @param boolean $asArray Returns the values as array, when false an concated string is returned 83 | * @return integer 84 | */ 85 | public function getMimeType($asArray = false) 86 | { 87 | $asArray = (bool) $asArray; 88 | $mimetype = (string) $this->_mimetype; 89 | if ($asArray) { 90 | $mimetype = explode(',', $mimetype); 91 | } 92 | 93 | return $mimetype; 94 | } 95 | 96 | /** 97 | * Sets the mimetypes 98 | * 99 | * @param string|array $mimetype The mimetypes to validate 100 | * @return Zend_Validate_File_Extension Provides a fluent interface 101 | */ 102 | public function setMimeType($mimetype) 103 | { 104 | $this->_mimetype = null; 105 | $this->addMimeType($mimetype); 106 | return $this; 107 | } 108 | 109 | /** 110 | * Adds the mimetypes 111 | * 112 | * @param string|array $mimetype The mimetypes to add for validation 113 | * @return Zend_Validate_File_Extension Provides a fluent interface 114 | */ 115 | public function addMimeType($mimetype) 116 | { 117 | $mimetypes = $this->getMimeType(true); 118 | if (is_string($mimetype)) { 119 | $mimetype = explode(',', $mimetype); 120 | } 121 | 122 | foreach ($mimetype as $content) { 123 | if (empty($content) || !is_string($content)) { 124 | continue; 125 | } 126 | $mimetypes[] = trim($content); 127 | } 128 | $mimetypes = array_unique($mimetypes); 129 | 130 | // Sanity check to ensure no empty values 131 | foreach ($mimetypes as $key => $mt) { 132 | if (empty($mt)) { 133 | unset($mimetypes[$key]); 134 | } 135 | } 136 | 137 | $this->_mimetype = implode(',', $mimetypes); 138 | 139 | return $this; 140 | } 141 | 142 | /** 143 | * Defined by Zend_Validate_Interface 144 | * 145 | * Returns true if the mimetype of the file matches the given ones. Also parts 146 | * of mimetypes can be checked. If you give for example "image" all image 147 | * mime types will be accepted like "image/gif", "image/jpeg" and so on. 148 | * 149 | * @param string $value Real file to check for mimetype 150 | * @param array $file File data from Zend_File_Transfer 151 | * @return boolean 152 | */ 153 | public function isValid($value, $file = null) 154 | { 155 | // Is file readable ? 156 | if (!@is_readable($value)) { 157 | $this->_throw($file, self::NOT_READABLE); 158 | return false; 159 | } 160 | 161 | if ($file !== null) { 162 | $info['type'] = $file['type']; 163 | } else { 164 | $this->_throw($file, self::NOT_DETECTED); 165 | return false; 166 | } 167 | 168 | $mimetype = $this->getMimeType(true); 169 | if (in_array($info['type'], $mimetype)) { 170 | return true; 171 | } 172 | 173 | foreach($mimetype as $mime) { 174 | $types = explode('/', $info['type']); 175 | if (in_array($mime, $types)) { 176 | return true; 177 | } 178 | } 179 | 180 | $this->_throw($file, self::FALSE_TYPE); 181 | return false; 182 | } 183 | 184 | /** 185 | * Throws an error of the given type 186 | * 187 | * @param string $file 188 | * @param string $errorType 189 | * @return false 190 | */ 191 | protected function _throw($file, $errorType) 192 | { 193 | if ($file !== null) { 194 | $this->_value = $file['name']; 195 | } 196 | 197 | $this->_error($errorType); 198 | return false; 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Http/Client/Adapter/Test.php: -------------------------------------------------------------------------------- 1 | $v) { 86 | $this->config[strtolower($k)] = $v; 87 | } 88 | } 89 | 90 | /** 91 | * Connect to the remote server 92 | * 93 | * @param string $host 94 | * @param int $port 95 | * @param boolean $secure 96 | * @param int $timeout 97 | */ 98 | public function connect($host, $port = 80, $secure = false) 99 | { } 100 | 101 | /** 102 | * Send request to the remote server 103 | * 104 | * @param string $method 105 | * @param Zend_Uri_Http $uri 106 | * @param string $http_ver 107 | * @param array $headers 108 | * @param string $body 109 | * @return string Request as string 110 | */ 111 | public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '') 112 | { 113 | $host = $uri->getHost(); 114 | $host = (strtolower($uri->getScheme()) == 'https' ? 'sslv2://' . $host : $host); 115 | 116 | // Build request headers 117 | $path = $uri->getPath(); 118 | if ($uri->getQuery()) $path .= '?' . $uri->getQuery(); 119 | $request = "{$method} {$path} HTTP/{$http_ver}\r\n"; 120 | foreach ($headers as $k => $v) { 121 | if (is_string($k)) $v = ucfirst($k) . ": $v"; 122 | $request .= "$v\r\n"; 123 | } 124 | 125 | // Add the request body 126 | $request .= "\r\n" . $body; 127 | 128 | // Do nothing - just return the request as string 129 | 130 | return $request; 131 | } 132 | 133 | /** 134 | * Return the response set in $this->setResponse() 135 | * 136 | * @return string 137 | */ 138 | public function read() 139 | { 140 | if ($this->responseIndex >= count($this->responses)) { 141 | $this->responseIndex = 0; 142 | } 143 | return $this->responses[$this->responseIndex++]; 144 | } 145 | 146 | /** 147 | * Close the connection (dummy) 148 | * 149 | */ 150 | public function close() 151 | { } 152 | 153 | /** 154 | * Set the HTTP response(s) to be returned by this adapter 155 | * 156 | * @param Zend_Http_Response|array|string $response 157 | */ 158 | public function setResponse($response) 159 | { 160 | if ($response instanceof Zend_Http_Response) { 161 | $response = $response->asString(); 162 | } 163 | 164 | $this->responses = (array)$response; 165 | $this->responseIndex = 0; 166 | } 167 | 168 | /** 169 | * Add another response to the response buffer. 170 | * 171 | * @param string $response 172 | */ 173 | public function addResponse($response) 174 | { 175 | $this->responses[] = $response; 176 | } 177 | 178 | /** 179 | * Sets the position of the response buffer. Selects which 180 | * response will be returned on the next call to read(). 181 | * 182 | * @param integer $index 183 | */ 184 | public function setResponseIndex($index) 185 | { 186 | if ($index < 0 || $index >= count($this->responses)) { 187 | require_once 'Zend/Http/Client/Adapter/Exception.php'; 188 | throw new Zend_Http_Client_Adapter_Exception( 189 | 'Index out of range of response buffer size'); 190 | } 191 | $this->responseIndex = $index; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/File/Extension.php: -------------------------------------------------------------------------------- 1 | "The file '%value%' has a false extension", 48 | self::NOT_FOUND => "The file '%value%' was not found" 49 | ); 50 | 51 | /** 52 | * Internal list of extensions 53 | * @var string 54 | */ 55 | protected $_extension = ''; 56 | 57 | /** 58 | * Validate case sensitive 59 | * 60 | * @var boolean 61 | */ 62 | protected $_case = false; 63 | 64 | /** 65 | * @var array Error message template variables 66 | */ 67 | protected $_messageVariables = array( 68 | 'extension' => '_extension' 69 | ); 70 | 71 | /** 72 | * Sets validator options 73 | * 74 | * @param string|array $extension 75 | * @param boolean $case If true validation is done case sensitive 76 | * @return void 77 | */ 78 | public function __construct($extension, $case = false) 79 | { 80 | $this->_case = (boolean) $case; 81 | $this->setExtension($extension); 82 | } 83 | 84 | /** 85 | * Returns the set file extension 86 | * 87 | * @param boolean $asArray Returns the values as array, when false an concated string is returned 88 | * @return string 89 | */ 90 | public function getExtension($asArray = false) 91 | { 92 | $asArray = (bool) $asArray; 93 | $extension = (string) $this->_extension; 94 | if ($asArray) { 95 | $extension = explode(',', $extension); 96 | } 97 | 98 | return $extension; 99 | } 100 | 101 | /** 102 | * Sets the file extensions 103 | * 104 | * @param string|array $extension The extensions to validate 105 | * @return Zend_Validate_File_Extension Provides a fluent interface 106 | */ 107 | public function setExtension($extension) 108 | { 109 | $this->_extension = null; 110 | $this->addExtension($extension); 111 | return $this; 112 | } 113 | 114 | /** 115 | * Adds the file extensions 116 | * 117 | * @param string|array $extension The extensions to add for validation 118 | * @return Zend_Validate_File_Extension Provides a fluent interface 119 | */ 120 | public function addExtension($extension) 121 | { 122 | $extensions = $this->getExtension(true); 123 | if (is_string($extension)) { 124 | $extension = explode(',', $extension); 125 | } 126 | 127 | foreach ($extension as $content) { 128 | if (empty($content) || !is_string($content)) { 129 | continue; 130 | } 131 | 132 | $extensions[] = trim($content); 133 | } 134 | $extensions = array_unique($extensions); 135 | 136 | // Sanity check to ensure no empty values 137 | foreach ($extensions as $key => $ext) { 138 | if (empty($ext)) { 139 | unset($extensions[$key]); 140 | } 141 | } 142 | 143 | $this->_extension = implode(',', $extensions); 144 | 145 | return $this; 146 | } 147 | 148 | /** 149 | * Defined by Zend_Validate_Interface 150 | * 151 | * Returns true if and only if the fileextension of $value is included in the 152 | * set extension list 153 | * 154 | * @param string $value Real file to check for extension 155 | * @param array $file File data from Zend_File_Transfer 156 | * @return boolean 157 | */ 158 | public function isValid($value, $file = null) 159 | { 160 | // Is file readable ? 161 | if (!@is_readable($value)) { 162 | $this->_throw($file, self::NOT_FOUND); 163 | return false; 164 | } 165 | 166 | if ($file !== null) { 167 | $info['extension'] = substr($file['name'], strpos($file['name'], '.') + 1); 168 | } else { 169 | $info = @pathinfo($value); 170 | } 171 | 172 | $extensions = $this->getExtension(true); 173 | 174 | if ($this->_case and (in_array($info['extension'], $extensions))) { 175 | return true; 176 | } else if (!$this->_case) { 177 | foreach ($extensions as $extension) { 178 | if (strtolower($extension) == strtolower($info['extension'])) { 179 | return true; 180 | } 181 | } 182 | } 183 | 184 | $this->_throw($file, self::FALSE_EXTENSION); 185 | return false; 186 | } 187 | 188 | /** 189 | * Throws an error of the given type 190 | * 191 | * @param string $file 192 | * @param string $errorType 193 | * @return false 194 | */ 195 | protected function _throw($file, $errorType) 196 | { 197 | if ($file !== null) { 198 | $this->_value = $file['name']; 199 | } 200 | 201 | $this->_error($errorType); 202 | return false; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Registry.php: -------------------------------------------------------------------------------- 1 | offsetExists($index)) { 144 | require_once 'Zend/Exception.php'; 145 | throw new Zend_Exception("No entry is registered for key '$index'"); 146 | } 147 | 148 | return $instance->offsetGet($index); 149 | } 150 | 151 | /** 152 | * setter method, basically same as offsetSet(). 153 | * 154 | * This method can be called from an object of type Zend_Registry, or it 155 | * can be called statically. In the latter case, it uses the default 156 | * static instance stored in the class. 157 | * 158 | * @param string $index The location in the ArrayObject in which to store 159 | * the value. 160 | * @param mixed $value The object to store in the ArrayObject. 161 | * @return void 162 | */ 163 | public static function set($index, $value) 164 | { 165 | $instance = self::getInstance(); 166 | $instance->offsetSet($index, $value); 167 | } 168 | 169 | /** 170 | * Returns TRUE if the $index is a named value in the registry, 171 | * or FALSE if $index was not found in the registry. 172 | * 173 | * @param string $index 174 | * @return boolean 175 | */ 176 | public static function isRegistered($index) 177 | { 178 | if (self::$_registry === null) { 179 | return false; 180 | } 181 | return self::$_registry->offsetExists($index); 182 | } 183 | 184 | /** 185 | * @param string $index 186 | * @returns mixed 187 | * 188 | * Workaround for http://bugs.php.net/bug.php?id=40442 (ZF-960). 189 | */ 190 | public function offsetExists($index) 191 | { 192 | return array_key_exists($index, $this); 193 | } 194 | 195 | } 196 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/File/Count.php: -------------------------------------------------------------------------------- 1 | "Too much files, only '%value%' are allowed", 49 | self::TOO_LESS => "Too less files, minimum '%value%' must be given" 50 | ); 51 | 52 | /** 53 | * @var array Error message template variables 54 | */ 55 | protected $_messageVariables = array( 56 | 'min' => '_min', 57 | 'max' => '_max' 58 | ); 59 | 60 | /** 61 | * Minimum file count 62 | * 63 | * If null, there is no minimum file count 64 | * 65 | * @var integer 66 | */ 67 | protected $_min; 68 | 69 | /** 70 | * Maximum file count 71 | * 72 | * If null, there is no maximum file count 73 | * 74 | * @var integer|null 75 | */ 76 | protected $_max; 77 | 78 | /** 79 | * Internal file array 80 | * @var array 81 | */ 82 | protected $_files; 83 | 84 | /** 85 | * Sets validator options 86 | * 87 | * Min limits the file count, when used with max=null it is the maximum file count 88 | * It also accepts an array with the keys 'min' and 'max' 89 | * 90 | * @param integer|array $min Minimum file count 91 | * @param integer $max Maximum file count 92 | * @return void 93 | */ 94 | public function __construct($min, $max = null) 95 | { 96 | $this->_files = array(); 97 | if (is_array($min) === true) { 98 | if (isset($min['max']) === true) { 99 | $max = $min['max']; 100 | } 101 | 102 | if (isset($min['min']) === true) { 103 | $min = $min['min']; 104 | } 105 | 106 | if (isset($min[0]) === true) { 107 | if (count($min) === 2) { 108 | $max = $min[1]; 109 | $min = $min[0]; 110 | } else { 111 | $max = $min[0]; 112 | $min = null; 113 | } 114 | } 115 | } 116 | 117 | if (empty($max) === true) { 118 | $max = $min; 119 | $min = null; 120 | } 121 | 122 | $this->setMin($min); 123 | $this->setMax($max); 124 | } 125 | 126 | /** 127 | * Returns the minimum file count 128 | * 129 | * @return integer 130 | */ 131 | public function getMin() 132 | { 133 | $min = $this->_min; 134 | 135 | return $min; 136 | } 137 | 138 | /** 139 | * Sets the minimum file count 140 | * 141 | * @param integer $min The minimum file count 142 | * @return Zend_Validate_File_Size Provides a fluent interface 143 | * @throws Zend_Validate_Exception When min is greater than max 144 | */ 145 | public function setMin($min) 146 | { 147 | if ($min === null) { 148 | $this->_min = null; 149 | } else if (($this->_max !== null) and ($min > $this->_max)) { 150 | require_once 'Zend/Validate/Exception.php'; 151 | throw new Zend_Validate_Exception('The minimum must be less than or equal to the maximum file count, but ' 152 | . " {$min} > {$this->_max}"); 153 | } else { 154 | $this->_min = max(0, (integer) $min); 155 | } 156 | 157 | return $this; 158 | } 159 | 160 | /** 161 | * Returns the maximum file count 162 | * 163 | * @return integer|null 164 | */ 165 | public function getMax() 166 | { 167 | return $this->_max; 168 | } 169 | 170 | /** 171 | * Sets the maximum file count 172 | * 173 | * @param integer|null $max The maximum file count 174 | * @throws Zend_Validate_Exception When max is smaller than min 175 | * @return Zend_Validate_StringLength Provides a fluent interface 176 | */ 177 | public function setMax($max) 178 | { 179 | if ($max === null) { 180 | $this->_max = null; 181 | } else if (($this->_min !== null) and ($max < $this->_min)) { 182 | require_once 'Zend/Validate/Exception.php'; 183 | throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum file count, but " 184 | . "{$max} < {$this->_min}"); 185 | } else { 186 | $this->_max = (integer) $max; 187 | } 188 | 189 | return $this; 190 | } 191 | 192 | /** 193 | * Defined by Zend_Validate_Interface 194 | * 195 | * Returns true if and only if the file count of all checked files is at least min and 196 | * not bigger than max (when max is not null). Attention: When checking with set min you 197 | * must give all files with the first call, otherwise you will get an false. 198 | * 199 | * @param string|array $value Filenames to check for count 200 | * @param array $file File data from Zend_File_Transfer 201 | * @return boolean 202 | */ 203 | public function isValid($value, $file = null) 204 | { 205 | if (is_string($value)) { 206 | $value = array($value); 207 | } 208 | 209 | foreach ($value as $file) { 210 | if (!isset($this->_files[$file])) { 211 | $this->_files[$file] = $file; 212 | } 213 | } 214 | 215 | if (($this->_max !== null) && (count($this->_files) > $this->_max)) { 216 | $this->_value = $this->_max; 217 | $this->_error(self::TOO_MUCH); 218 | return false; 219 | } 220 | 221 | if (($this->_min !== null) && (count($this->_files) < $this->_min)) { 222 | $this->_value = $this->_min; 223 | $this->_error(self::TOO_LESS); 224 | return false; 225 | } 226 | 227 | return true; 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/File/Upload.php: -------------------------------------------------------------------------------- 1 | "The file '%value%' exceeds the defined ini size", 57 | self::FORM_SIZE => "The file '%value%' exceeds the defined form size", 58 | self::PARTIAL => "The file '%value%' was only partially uploaded", 59 | self::NO_FILE => "The file '%value%' was not uploaded", 60 | self::NO_TMP_DIR => "No temporary directory was found for the file '%value%'", 61 | self::CANT_WRITE => "The file '%value%' can't be written", 62 | self::EXTENSION => "The extension returned an error while uploading the file '%value%'", 63 | self::ATTACK => "The file '%value%' was illegal uploaded, possible attack", 64 | self::FILE_NOT_FOUND => "The file '%value%' was not found", 65 | self::UNKNOWN => "Unknown error while uploading the file '%value%'" 66 | ); 67 | 68 | /** 69 | * Internal array of files 70 | * @var array 71 | */ 72 | protected $_files = array(); 73 | 74 | /** 75 | * Sets validator options 76 | * 77 | * The array $files must be given in syntax of Zend_File_Transfer to be checked 78 | * If no files are given the $_FILES array will be used automatically. 79 | * NOTE: This validator will only work with HTTP POST uploads! 80 | * 81 | * @param array $files Array of files in syntax of Zend_File_Transfer 82 | * @return void 83 | */ 84 | public function __construct($files = array()) 85 | { 86 | $this->setFiles($files); 87 | } 88 | 89 | /** 90 | * Returns the array of set files 91 | * 92 | * @param string $files (Optional) The file to return in detail 93 | * @return array 94 | * @throws Zend_Validate_Exception If file is not found 95 | */ 96 | public function getFiles($file = null) 97 | { 98 | if ($file !== null) { 99 | $return = array(); 100 | foreach ($this->_files as $name => $content) { 101 | if ($name === $file) { 102 | $return[$file] = $this->_files[$name]; 103 | } 104 | 105 | if ($content['name'] === $file) { 106 | $return[$name] = $this->_files[$name]; 107 | } 108 | } 109 | 110 | if (count($return) === 0) { 111 | require_once 'Zend/Validate/Exception.php'; 112 | throw new Zend_Validate_Exception("The file '$file' was not found"); 113 | } 114 | 115 | return $return; 116 | } 117 | 118 | return $this->_files; 119 | } 120 | 121 | /** 122 | * Sets the minimum filesize 123 | * 124 | * @param array $files The files to check in syntax of Zend_File_Transfer 125 | * @return Zend_Validate_File_Upload Provides a fluent interface 126 | */ 127 | public function setFiles($files = array()) 128 | { 129 | if (count($files) === 0) { 130 | $this->_files = $_FILES; 131 | } else { 132 | $this->_files = $files; 133 | } 134 | return $this; 135 | } 136 | 137 | /** 138 | * Defined by Zend_Validate_Interface 139 | * 140 | * Returns true if and only if the file was uploaded without errors 141 | * 142 | * @param string $value Single file to check for upload errors, when giving null the $_FILES array 143 | * from initialization will be used 144 | * @return boolean 145 | */ 146 | public function isValid($value) 147 | { 148 | if (array_key_exists($value, $this->_files)) { 149 | $files[$value] = $this->_files[$value]; 150 | } else { 151 | foreach ($this->_files as $file => $content) { 152 | if ($content['name'] === $value) { 153 | $files[$file] = $this->_files[$file]; 154 | } 155 | 156 | if ($content['tmp_name'] === $value) { 157 | $files[$file] = $this->_files[$file]; 158 | } 159 | } 160 | } 161 | 162 | if (empty($files)) { 163 | $this->_error(self::FILE_NOT_FOUND); 164 | return false; 165 | } 166 | 167 | foreach ($files as $file => $content) { 168 | $this->_value = $file; 169 | switch($content['error']) { 170 | case 0: 171 | if (!is_uploaded_file($content['tmp_name'])) { 172 | $this->_error(self::ATTACK); 173 | } 174 | break; 175 | 176 | case 1: 177 | $this->_error(self::INI_SIZE); 178 | break; 179 | 180 | case 2: 181 | $this->_error(self::FORM_SIZE); 182 | break; 183 | 184 | case 3: 185 | $this->_error(self::PARTIAL); 186 | break; 187 | 188 | case 4: 189 | $this->_error(self::NO_FILE); 190 | break; 191 | 192 | case 6: 193 | $this->_error(self::NO_TMP_DIR); 194 | break; 195 | 196 | case 7: 197 | $this->_error(self::CANT_WRITE); 198 | break; 199 | 200 | case 8: 201 | $this->_error(self::EXTENSION); 202 | break; 203 | 204 | default: 205 | $this->_error(self::UNKNOWN); 206 | break; 207 | } 208 | } 209 | 210 | if (count($this->_messages) > 0) { 211 | return false; 212 | } else { 213 | return true; 214 | } 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/Date.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not of the format YYYY-MM-DD", 60 | self::INVALID => "'%value%' does not appear to be a valid date", 61 | self::FALSEFORMAT => "'%value%' does not fit given date format" 62 | ); 63 | 64 | /** 65 | * Optional format 66 | * 67 | * @var string|null 68 | */ 69 | protected $_format; 70 | 71 | /** 72 | * Optional locale 73 | * 74 | * @var string|Zend_Locale|null 75 | */ 76 | protected $_locale; 77 | 78 | /** 79 | * Sets validator options 80 | * 81 | * @param string $format OPTIONAL 82 | * @param string|Zend_Locale $locale OPTIONAL 83 | * @return void 84 | */ 85 | public function __construct($format = null, $locale = null) 86 | { 87 | $this->setFormat($format); 88 | $this->setLocale($locale); 89 | } 90 | 91 | /** 92 | * Returns the locale option 93 | * 94 | * @return string|Zend_Locale|null 95 | */ 96 | public function getLocale() 97 | { 98 | return $this->_locale; 99 | } 100 | 101 | /** 102 | * Sets the locale option 103 | * 104 | * @param string|Zend_Locale $locale 105 | * @return Zend_Validate_Date provides a fluent interface 106 | */ 107 | public function setLocale($locale = null) 108 | { 109 | if ($locale === null) { 110 | $this->_locale = null; 111 | return $this; 112 | } 113 | 114 | require_once 'Zend/Locale.php'; 115 | if (!Zend_Locale::isLocale($locale, true)) { 116 | if (!Zend_Locale::isLocale($locale, false)) { 117 | require_once 'Zend/Validate/Exception.php'; 118 | throw new Zend_Validate_Exception("The locale '$locale' is no known locale"); 119 | } 120 | 121 | $locale = new Zend_Locale($locale); 122 | } 123 | 124 | $this->_locale = (string) $locale; 125 | return $this; 126 | } 127 | 128 | /** 129 | * Returns the locale option 130 | * 131 | * @return string|null 132 | */ 133 | public function getFormat() 134 | { 135 | return $this->_format; 136 | } 137 | 138 | /** 139 | * Sets the format option 140 | * 141 | * @param string $format 142 | * @return Zend_Validate_Date provides a fluent interface 143 | */ 144 | public function setFormat($format = null) 145 | { 146 | $this->_format = $format; 147 | return $this; 148 | } 149 | 150 | /** 151 | * Defined by Zend_Validate_Interface 152 | * 153 | * Returns true if $value is a valid date of the format YYYY-MM-DD 154 | * If optional $format or $locale is set the date format is checked 155 | * according to Zend_Date, see Zend_Date::isDate() 156 | * 157 | * @param string $value 158 | * @return boolean 159 | */ 160 | public function isValid($value) 161 | { 162 | $valueString = (string) $value; 163 | 164 | $this->_setValue($valueString); 165 | 166 | if (($this->_format !== null) or ($this->_locale !== null)) { 167 | require_once 'Zend/Date.php'; 168 | if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) { 169 | if ($this->_checkFormat($value) === false) { 170 | $this->_error(self::FALSEFORMAT); 171 | } else { 172 | $this->_error(self::INVALID); 173 | } 174 | return false; 175 | } 176 | } else { 177 | if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $valueString)) { 178 | $this->_error(self::NOT_YYYY_MM_DD); 179 | return false; 180 | } 181 | 182 | list($year, $month, $day) = sscanf($valueString, '%d-%d-%d'); 183 | 184 | if (!checkdate($month, $day, $year)) { 185 | $this->_error(self::INVALID); 186 | return false; 187 | } 188 | } 189 | 190 | return true; 191 | } 192 | 193 | /** 194 | * Check if the given date fits the given format 195 | * 196 | * @param string $value Date to check 197 | * @return boolean False when date does not fit the format 198 | */ 199 | private function _checkFormat($value) 200 | { 201 | try { 202 | require_once 'Zend/Locale/Format.php'; 203 | $parsed = Zend_Locale_Format::getDate($value, array( 204 | 'date_format' => $this->_format, 'format_type' => 'iso', 205 | 'fix_date' => false)); 206 | if (isset($parsed['year']) and ((strpos(strtoupper($this->_format), 'YY') !== false) and 207 | (strpos(strtoupper($this->_format), 'YYYY') === false))) { 208 | $parsed['year'] = Zend_Date::_century($parsed['year']); 209 | } 210 | } catch (Exception $e) { 211 | // Date can not be parsed 212 | return false; 213 | } 214 | 215 | if (((strpos($this->_format, 'Y') !== false) or (strpos($this->_format, 'y') !== false)) and 216 | (!isset($parsed['year']))) { 217 | // Year expected but not found 218 | return false; 219 | } 220 | 221 | if ((strpos($this->_format, 'M') !== false) and (!isset($parsed['month']))) { 222 | // Month expected but not found 223 | return false; 224 | } 225 | 226 | if ((strpos($this->_format, 'd') !== false) and (!isset($parsed['day']))) { 227 | // Day expected but not found 228 | return false; 229 | } 230 | 231 | if (((strpos($this->_format, 'H') !== false) or (strpos($this->_format, 'h') !== false)) and 232 | (!isset($parsed['hour']))) { 233 | // Hour expected but not found 234 | return false; 235 | } 236 | 237 | if ((strpos($this->_format, 'm') !== false) and (!isset($parsed['minute']))) { 238 | // Minute expected but not found 239 | return false; 240 | } 241 | 242 | if ((strpos($this->_format, 's') !== false) and (!isset($parsed['second']))) { 243 | // Second expected but not found 244 | return false; 245 | } 246 | 247 | // Date fits the format 248 | return true; 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Validate/EmailAddress.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not a valid email address in the basic format local-part@hostname", 57 | self::INVALID_HOSTNAME => "'%hostname%' is not a valid hostname for email address '%value%'", 58 | self::INVALID_MX_RECORD => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'", 59 | self::DOT_ATOM => "'%localPart%' not matched against dot-atom format", 60 | self::QUOTED_STRING => "'%localPart%' not matched against quoted-string format", 61 | self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'" 62 | ); 63 | 64 | /** 65 | * @var array 66 | */ 67 | protected $_messageVariables = array( 68 | 'hostname' => '_hostname', 69 | 'localPart' => '_localPart' 70 | ); 71 | 72 | /** 73 | * Local object for validating the hostname part of an email address 74 | * 75 | * @var Zend_Validate_Hostname 76 | */ 77 | public $hostnameValidator; 78 | 79 | /** 80 | * Whether we check for a valid MX record via DNS 81 | * 82 | * @var boolean 83 | */ 84 | protected $_validateMx = false; 85 | 86 | /** 87 | * @var string 88 | */ 89 | protected $_hostname; 90 | 91 | /** 92 | * @var string 93 | */ 94 | protected $_localPart; 95 | 96 | /** 97 | * Instantiates hostname validator for local use 98 | * 99 | * You can pass a bitfield to determine what types of hostnames are allowed. 100 | * These bitfields are defined by the ALLOW_* constants in Zend_Validate_Hostname 101 | * The default is to allow DNS hostnames only 102 | * 103 | * @param integer $allow OPTIONAL 104 | * @param bool $validateMx OPTIONAL 105 | * @param Zend_Validate_Hostname $hostnameValidator OPTIONAL 106 | * @return void 107 | */ 108 | public function __construct($allow = Zend_Validate_Hostname::ALLOW_DNS, $validateMx = false, Zend_Validate_Hostname $hostnameValidator = null) 109 | { 110 | $this->setValidateMx($validateMx); 111 | $this->setHostnameValidator($hostnameValidator, $allow); 112 | } 113 | 114 | /** 115 | * @param Zend_Validate_Hostname $hostnameValidator OPTIONAL 116 | * @param int $allow OPTIONAL 117 | * @return void 118 | */ 119 | public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS) 120 | { 121 | if ($hostnameValidator === null) { 122 | $hostnameValidator = new Zend_Validate_Hostname($allow); 123 | } 124 | $this->hostnameValidator = $hostnameValidator; 125 | } 126 | 127 | /** 128 | * Whether MX checking via dns_get_mx is supported or not 129 | * 130 | * This currently only works on UNIX systems 131 | * 132 | * @return boolean 133 | */ 134 | public function validateMxSupported() 135 | { 136 | return function_exists('dns_get_mx'); 137 | } 138 | 139 | /** 140 | * Set whether we check for a valid MX record via DNS 141 | * 142 | * This only applies when DNS hostnames are validated 143 | * 144 | * @param boolean $allowed Set allowed to true to validate for MX records, and false to not validate them 145 | */ 146 | public function setValidateMx($allowed) 147 | { 148 | $this->_validateMx = (bool) $allowed; 149 | } 150 | 151 | /** 152 | * Defined by Zend_Validate_Interface 153 | * 154 | * Returns true if and only if $value is a valid email address 155 | * according to RFC2822 156 | * 157 | * @link http://www.ietf.org/rfc/rfc2822.txt RFC2822 158 | * @link http://www.columbia.edu/kermit/ascii.html US-ASCII characters 159 | * @param string $value 160 | * @return boolean 161 | */ 162 | public function isValid($value) 163 | { 164 | $valueString = (string) $value; 165 | 166 | $this->_setValue($valueString); 167 | 168 | // Split email address up 169 | if (!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) { 170 | $this->_error(self::INVALID); 171 | return false; 172 | } 173 | 174 | $this->_localPart = $matches[1]; 175 | $this->_hostname = $matches[2]; 176 | 177 | // Match hostname part 178 | $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator()) 179 | ->isValid($this->_hostname); 180 | if (!$hostnameResult) { 181 | $this->_error(self::INVALID_HOSTNAME); 182 | 183 | // Get messages and errors from hostnameValidator 184 | foreach ($this->hostnameValidator->getMessages() as $message) { 185 | $this->_messages[] = $message; 186 | } 187 | foreach ($this->hostnameValidator->getErrors() as $error) { 188 | $this->_errors[] = $error; 189 | } 190 | } 191 | 192 | // MX check on hostname via dns_get_record() 193 | if ($this->_validateMx) { 194 | if ($this->validateMxSupported()) { 195 | $result = dns_get_mx($this->_hostname, $mxHosts); 196 | if (count($mxHosts) < 1) { 197 | $hostnameResult = false; 198 | $this->_error(self::INVALID_MX_RECORD); 199 | } 200 | } else { 201 | /** 202 | * MX checks are not supported by this system 203 | * @see Zend_Validate_Exception 204 | */ 205 | require_once 'Zend/Validate/Exception.php'; 206 | throw new Zend_Validate_Exception('Internal error: MX checking not available on this system'); 207 | } 208 | } 209 | 210 | // First try to match the local part on the common dot-atom format 211 | $localResult = false; 212 | 213 | // Dot-atom characters are: 1*atext *("." 1*atext) 214 | // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*", 215 | // "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~" 216 | $atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d'; 217 | if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) { 218 | $localResult = true; 219 | } else { 220 | // Try quoted string format 221 | 222 | // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE 223 | // qtext: Non white space controls, and the rest of the US-ASCII characters not 224 | // including "\" or the quote character 225 | $noWsCtl = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f'; 226 | $qtext = $noWsCtl . '\x21\x23-\x5b\x5d-\x7e'; 227 | $ws = '\x20\x09'; 228 | if (preg_match('/^\x22([' . $ws . $qtext . '])*[$ws]?\x22$/', $this->_localPart)) { 229 | $localResult = true; 230 | } else { 231 | $this->_error(self::DOT_ATOM); 232 | $this->_error(self::QUOTED_STRING); 233 | $this->_error(self::INVALID_LOCAL_PART); 234 | } 235 | } 236 | 237 | // If both parts valid, return true 238 | if ($localResult && $hostnameResult) { 239 | return true; 240 | } else { 241 | return false; 242 | } 243 | } 244 | 245 | } 246 | -------------------------------------------------------------------------------- /phpQuery/phpQuery/Zend/Loader.php: -------------------------------------------------------------------------------- 1 | $dir) { 72 | if ($dir == '.') { 73 | $dirs[$key] = $dirPath; 74 | } else { 75 | $dir = rtrim($dir, '\\/'); 76 | $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath; 77 | } 78 | } 79 | $file = basename($file); 80 | self::loadFile($file, $dirs, true); 81 | } else { 82 | self::_securityCheck($file); 83 | include_once $file; 84 | } 85 | 86 | if (!class_exists($class, false) && !interface_exists($class, false)) { 87 | require_once 'Zend/Exception.php'; 88 | throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file"); 89 | } 90 | } 91 | 92 | /** 93 | * Loads a PHP file. This is a wrapper for PHP's include() function. 94 | * 95 | * $filename must be the complete filename, including any 96 | * extension such as ".php". Note that a security check is performed that 97 | * does not permit extended characters in the filename. This method is 98 | * intended for loading Zend Framework files. 99 | * 100 | * If $dirs is a string or an array, it will search the directories 101 | * in the order supplied, and attempt to load the first matching file. 102 | * 103 | * If the file was not found in the $dirs, or if no $dirs were specified, 104 | * it will attempt to load it from PHP's include_path. 105 | * 106 | * If $once is TRUE, it will use include_once() instead of include(). 107 | * 108 | * @param string $filename 109 | * @param string|array $dirs - OPTIONAL either a path or array of paths 110 | * to search. 111 | * @param boolean $once 112 | * @return boolean 113 | * @throws Zend_Exception 114 | */ 115 | public static function loadFile($filename, $dirs = null, $once = false) 116 | { 117 | self::_securityCheck($filename); 118 | 119 | /** 120 | * Search in provided directories, as well as include_path 121 | */ 122 | $incPath = false; 123 | if (!empty($dirs) && (is_array($dirs) || is_string($dirs))) { 124 | if (is_array($dirs)) { 125 | $dirs = implode(PATH_SEPARATOR, $dirs); 126 | } 127 | $incPath = get_include_path(); 128 | set_include_path($dirs . PATH_SEPARATOR . $incPath); 129 | } 130 | 131 | /** 132 | * Try finding for the plain filename in the include_path. 133 | */ 134 | if ($once) { 135 | include_once $filename; 136 | } else { 137 | include $filename; 138 | } 139 | 140 | /** 141 | * If searching in directories, reset include_path 142 | */ 143 | if ($incPath) { 144 | set_include_path($incPath); 145 | } 146 | 147 | return true; 148 | } 149 | 150 | /** 151 | * Returns TRUE if the $filename is readable, or FALSE otherwise. 152 | * This function uses the PHP include_path, where PHP's is_readable() 153 | * does not. 154 | * 155 | * @param string $filename 156 | * @return boolean 157 | */ 158 | public static function isReadable($filename) 159 | { 160 | if (!$fh = @fopen($filename, 'r', true)) { 161 | return false; 162 | } 163 | @fclose($fh); 164 | return true; 165 | } 166 | 167 | /** 168 | * spl_autoload() suitable implementation for supporting class autoloading. 169 | * 170 | * Attach to spl_autoload() using the following: 171 | * 172 | * spl_autoload_register(array('Zend_Loader', 'autoload')); 173 | * 174 | * 175 | * @param string $class 176 | * @return string|false Class name on success; false on failure 177 | */ 178 | public static function autoload($class) 179 | { 180 | try { 181 | self::loadClass($class); 182 | return $class; 183 | } catch (Exception $e) { 184 | return false; 185 | } 186 | } 187 | 188 | /** 189 | * Register {@link autoload()} with spl_autoload() 190 | * 191 | * @param string $class (optional) 192 | * @param boolean $enabled (optional) 193 | * @return void 194 | * @throws Zend_Exception if spl_autoload() is not found 195 | * or if the specified class does not have an autoload() method. 196 | */ 197 | public static function registerAutoload($class = 'Zend_Loader', $enabled = true) 198 | { 199 | if (!function_exists('spl_autoload_register')) { 200 | require_once 'Zend/Exception.php'; 201 | throw new Zend_Exception('spl_autoload does not exist in this PHP installation'); 202 | } 203 | 204 | self::loadClass($class); 205 | $methods = get_class_methods($class); 206 | if (!in_array('autoload', (array) $methods)) { 207 | require_once 'Zend/Exception.php'; 208 | throw new Zend_Exception("The class \"$class\" does not have an autoload() method"); 209 | } 210 | 211 | if ($enabled === true) { 212 | spl_autoload_register(array($class, 'autoload')); 213 | } else { 214 | spl_autoload_unregister(array($class, 'autoload')); 215 | } 216 | } 217 | 218 | /** 219 | * Ensure that filename does not contain exploits 220 | * 221 | * @param string $filename 222 | * @return void 223 | * @throws Zend_Exception 224 | */ 225 | protected static function _securityCheck($filename) 226 | { 227 | /** 228 | * Security check 229 | */ 230 | if (preg_match('/[^a-z0-9\\/\\\\_.-]/i', $filename)) { 231 | require_once 'Zend/Exception.php'; 232 | throw new Zend_Exception('Security check: Illegal character in filename'); 233 | } 234 | } 235 | 236 | /** 237 | * Attempt to include() the file. 238 | * 239 | * include() is not prefixed with the @ operator because if 240 | * the file is loaded and contains a parse error, execution 241 | * will halt silently and this is difficult to debug. 242 | * 243 | * Always set display_errors = Off on production servers! 244 | * 245 | * @param string $filespec 246 | * @param boolean $once 247 | * @return boolean 248 | * @deprecated Since 1.5.0; use loadFile() instead 249 | */ 250 | protected static function _includeFile($filespec, $once = false) 251 | { 252 | if ($once) { 253 | return include_once $filespec; 254 | } else { 255 | return include $filespec ; 256 | } 257 | } 258 | } 259 | --------------------------------------------------------------------------------