Skip to content
This repository was archived by the owner on Apr 26, 2020. It is now read-only.

Added WebBrowser->download() #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions phpQuery/phpQuery/plugins/WebBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ public static function location($self, $url = null) {
}
return $return;
}


public static function download($self, $url = null) {
$xhr = isset($self->document->xhr)
? $self->document->xhr
: null;
$xhr = phpQuery::ajax(array(
'url' => $url,
), $xhr);
$return = false;
if ($xhr->getLastResponse()->isSuccessful()) {
$return = phpQueryPlugin_WebBrowser::browserDownload($xhr);
if (isset($self->document->WebBrowserCallback))
phpQuery::callbackRun(
$self->document->WebBrowserCallback,
array($return)
);
}
return $return;
}
}
class phpQueryPlugin_WebBrowser {
/**
Expand Down Expand Up @@ -246,6 +266,17 @@ public static function browserReceive($xhr) {
} else
return $pq;
}

/**
* @param Zend_Http_Client $xhr
*/
public static function browserDownload($xhr) {
phpQuery::debug("[WebBrowser] Received from ".$xhr->getUri(true));
// TODO handle meta redirects
$body = $xhr->getLastResponse()->getBody();

return $body;
}
/**
*
* @param $e
Expand Down
2 changes: 1 addition & 1 deletion test-cases/document-types/document-utf8.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<body>
<span>Hello World!</span>
<span>ąśżźć</span>
<a href='<?php foreach($foo as $bar} { print $foo['1'] } ?>'>Attr test</a>
<a href='<?php foreach($foo as $bar) { print $foo['1']; } ?>'>Attr test</a>
</body>
</html>