Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e6ddf45

Browse files
Changed the internal behavior to handle request parameters to be parsed with a single reference.
1 parent 00dc719 commit e6ddf45

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

‎ChangeLog.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
### 1.4.1 - 2020年04月02日
4+
- Changed the internal behavior to handle request parameters to be parsed with a single reference.
5+
36
### 1.4.0 - 2020年04月01日
47
- Added the dependency, PHP Class Map Generator.
58
- Made the repository available to be imported via Composer.

‎web/include/class/scraper/ScraperHandler.php‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ class ScraperHandler extends Utility {
88
protected $_sBinaryPath = '';
99
protected $_sDiskCacheDirPath = '';
1010

11-
public function __construct() {
11+
/**
12+
* @var array $_REQUEST
13+
*/
14+
public $aRequest = array();
15+
16+
public function __construct( array $aRequest ) {
1217

18+
$this->aRequest = $aRequest;
19+
1320
$this->___checkPhantomJSBinary();
1421
$this->___setCacheDirectory();
1522

@@ -34,12 +41,12 @@ private function ___setCacheDirectory() {
3441

3542
public function do() {
3643

37-
$_aBaseArguments = $this->___getBaseArguments( $_REQUEST );
38-
$_sClassName = "PHPSimpleWebScraper\Scraper\Scraper_" . $this->___getOutputType( $_REQUEST );
44+
$_aBaseArguments = $this->___getBaseArguments( $this->aRequest );
45+
$_sClassName = "PHPSimpleWebScraper\Scraper\Scraper_" . $this->___getOutputType( $this->aRequest );
3946
$_oScraper = new $_sClassName(
4047
$_aBaseArguments,
41-
$this->___getClientArguments( $_REQUEST ),
42-
$this->___getRequestArguments( $_REQUEST, $_aBaseArguments[ 'method' ] )
48+
$this->___getClientArguments( $this->aRequest ),
49+
$this->___getRequestArguments( $this->aRequest, $_aBaseArguments[ 'method' ] )
4350
);
4451
$_oScraper->do();
4552

@@ -53,8 +60,11 @@ private function ___getOutputType( array $aRequest ) {
5360
? $_sOutputType
5461
: 'html';
5562
}
63+
5664
/**
5765
* @param array $aRequest
66+
* @param $sMethod
67+
*
5868
* @return array
5969
*/
6070
private function ___getRequestArguments( array $aRequest, $sMethod ) {
@@ -65,7 +75,7 @@ private function ___getRequestArguments( array $aRequest, $sMethod ) {
6575
if ( 'POST' === $sMethod ) {
6676
$_aRequestArguments[ 'data' ] = isset( $aRequest[ 'data' ] ) ? $aRequest[ 'data' ] : array();
6777
}
68-
return $_aRequestArguments;
78+
return $_aRequestArguments + $aRequest;
6979
}
7080
/**
7181
* @param array $aRequest
@@ -85,7 +95,7 @@ private function ___getClientArguments( array $aRequest ) {
8595
* @return array
8696
*/
8797
private function ___getBaseArguments( array $aRequest ) {
88-
$_aArguments = array(
98+
return array(
8999
'url' => urldecode( trim( $aRequest[ 'url' ] ) ),
90100
'user_agent' => $this->___getUserAgent( $aRequest ),
91101
'headers' => isset( $aRequest[ 'headers' ] ) && is_array( $aRequest[ 'headers' ] )
@@ -97,7 +107,6 @@ private function ___getBaseArguments( array $aRequest ) {
97107
'binary_path' => $this->_sBinaryPath,
98108
'cache_lifespan' => isset( $aRequest[ 'cache-lifespan' ] ) ? $aRequest[ 'cache-lifespan' ] : 1200,
99109
);
100-
return $_aArguments;
101110
}
102111
private function ___getUserAgent( array $aRequest ) {
103112
if ( ! isset( $aRequest[ 'user-agent' ] ) ) {

‎web/include/class/scraper/Scraper_screenshot.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ class Scraper_screenshot extends Scraper_Base {
1212
protected function _construct() {
1313

1414
// Sanitize parameters
15-
$this->_aClientArguments[ 'load-images' ] = isset( $_REQUEST[ 'load-images' ] ) && ! Utility::getBoolean( $_REQUEST[ 'load-images' ] )
15+
$this->_aClientArguments[ 'load-images' ] = isset( $this->_aRequestArguments[ 'load-images' ] ) && ! $this->getBoolean( $this->_aRequestArguments[ 'load-images' ] )
1616
? false
1717
: true;
1818

19-
$this->_aRequestArguments[ 'width' ] = isset( $_REQUEST[ 'width' ] )
20-
? ( integer ) $_REQUEST[ 'width' ]
19+
$this->_aRequestArguments[ 'width' ] = isset( $this->_aRequestArguments[ 'width' ] )
20+
? ( integer ) $this->_aRequestArguments[ 'width' ]
2121
: 480;
22-
$this->_aRequestArguments[ 'height' ] = isset( $_REQUEST[ 'height' ] )
23-
? ( integer ) $_REQUEST[ 'height' ]
22+
$this->_aRequestArguments[ 'height' ] = isset( $this->_aRequestArguments[ 'height' ] )
23+
? ( integer ) $this->_aRequestArguments[ 'height' ]
2424
: null; // to get all the height
2525

2626
}

‎web/include/class/utility/Utility.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Utility {
99
* If parsed normally string like `true`, `false` will be considered a true value.
1010
* This method converts them into a boolean value.
1111
*
12-
* @param $isValue
12+
* @param integer|boolean|string $ibsValue
1313
* @return boolean
1414
*/
1515
static public function getBoolean( $ibsValue ) {

‎web/index.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Registry {
1414
const SUBTITLE = 'Fetches even JavaScript generated contents.';
1515
const DESCRIPTION = 'A web page content proxy scraper, supporting JavaScript generated contents, a cross domain solution.';
1616
const PROGRAM_URI = 'https://github.com/michaeluno/php-simple-web-scraper';
17-
const VERSION = '1.4.0';
17+
const VERSION = '1.4.1';
1818
const AUTHOR = 'Michael Uno';
1919
const AUTHOR_URI = 'http://en.michaeluno.jp';
2020

@@ -49,11 +49,11 @@ static public function replyToLoadClass( $sCalledUnknownClassName ) {
4949
header( 'Access-Control-Allow-Origin: *' );
5050

5151
// Front-end Form
52-
if ( ! isset( $_GET[ 'url' ] ) ) {
52+
if ( ! isset( $_REQUEST[ 'url' ] ) ) {
5353
include( dirname( __FILE__ ) . '/include/template/form.php' );
5454
exit;
5555
}
5656
// Fetched Results
57-
$_oScraper = new \PHPSimpleWebScraper\Scraper\ScraperHandler;
57+
$_oScraper = new \PHPSimpleWebScraper\Scraper\ScraperHandler( $_REQUEST );
5858
$_oScraper->do();
5959
exit;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /