Skip to content

Commit 0f89922

Browse files
committed
Added custom JS code feature to PHP API
1 parent 807827b commit 0f89922

File tree

7 files changed

+129
-11
lines changed

7 files changed

+129
-11
lines changed

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
{
22
"name": "grabzit/grabzit",
33
"type": "library",
4-
"keywords": ["screenshots","PDF","DOCX","HTML","table","capture","PNG","JPG","BMP","mp4","TIFF","API","web","images","videos","animated gif","csv","xlsx","video conversion","HTML to PDF","HTML to DOCX","HTML to Image","HTML to Video","URL to PDF","URL to DOCX","URL to Image","URL to Video", "Rendered HTML"],
4+
"keywords": ["screenshots","PDF","DOCX","HTML","table","capture","PNG","SVG","JPG","BMP","mp4","TIFF","API","web","images","videos","animated gif","csv","xlsx","video conversion","HTML to PDF","HTML to DOCX","HTML to Image","HTML to Video","URL to PDF","URL to DOCX","URL to Image","URL to Video", "Rendered HTML"],
55
"homepage": "https://grabz.it/",
66
"description": "Use our API to allow your app to create images, DOCX documents, videos, rendered HTML and PDF's from URL's or raw HTML. Additionally GrabzIt allows you to convert online videos into animated GIF's or HTML tables into CSV's.",
77
"license": "MIT",
8-
"version":"3.5.4",
8+
"version":"3.5.5",
99
"autoload": {
1010
"psr-4": {
1111
"GrabzIt\\": "lib/"
12-
}
12+
},
13+
"classmap": [
14+
"vendor/"
15+
]
1316
},
1417
"support": {
1518
"issues": "https://grabz.it/support/"
1619
},
1720
"require": {
1821
"php": ">=5.3.2"
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^11"
1925
}
2026
}

lib/GrabzItDOCXOptions.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class GrabzItDOCXOptions extends GrabzItBaseOptions
1616
private $requestAs = 0;
1717
private $quality = -1;
1818
private $clickElement = null;
19+
private $jsCode = null;
1920
private $hideElement = null;
2021
private $waitForElement = null;
2122
private $noAds = false;
@@ -191,6 +192,22 @@ public function getTitle()
191192
{
192193
return $this->title;
193194
}
195+
196+
/*
197+
Set the JavaScript Code to execute in the web page.
198+
*/
199+
public function setJavaScriptCode($value)
200+
{
201+
$this->jsCode = $value;
202+
}
203+
204+
/*
205+
Get the JavaScript Code to execute in the web page.
206+
*/
207+
public function getJavaScriptCode()
208+
{
209+
return $this->jsCode;
210+
}
194211

195212
/*
196213
Set the CSS selector of the HTML element in the web page to click.
@@ -495,7 +512,8 @@ public function _getSignatureString($applicationSecret, $callBackURL, $url = nul
495512
$this->nullToEmpty($this->hideElement)."|".$this->nullToEmpty($this->getExportURL())."|".$this->nullToEmpty($this->waitForElement)."|".
496513
$this->nullToEmpty($this->getEncryptionKey())."|".$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".
497514
$this->nullToEmpty($this->targetElement)."|".$this->nullToEmpty($this->templateId)."|".$this->nullToEmpty($this->templateVariables)."|".
498-
$this->nullToEmpty($this->height)."|".$this->nullToEmpty($this->width)."|".$this->nullToEmpty($this->browserWidth)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->mergeId)."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications))."|".$this->nullToEmpty($this->password."|".$this->nullToEmpty($this->clickElement));
515+
$this->nullToEmpty($this->height)."|".$this->nullToEmpty($this->width)."|".$this->nullToEmpty($this->browserWidth)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->mergeId)."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications))."|".
516+
$this->nullToEmpty($this->password."|".$this->nullToEmpty($this->clickElement)."|".$this->nullToEmpty($this->jsCode));
499517
}
500518

501519
public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue)
@@ -529,6 +547,7 @@ public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $
529547
$params['nonotify'] = $this->nullToEmpty(intval($this->noCookieNotifications));
530548
$params['password'] = $this->nullToEmpty($this->password);
531549
$params['click'] = $this->nullToEmpty($this->clickElement);
550+
$params['jscode'] = $this->nullToEmpty($this->jsCode);
532551

533552
return $params;
534553
}

lib/GrabzItHTMLOptions.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class GrabzItHTMLOptions extends GrabzItBaseOptions
1010
private $noAds = false;
1111
private $noCookieNotifications = false;
1212
private $address = null;
13+
private $clickElement = null;
14+
private $jsCode = null;
1315

1416
/*
1517
Set the width of the browser in pixels.
@@ -137,6 +139,38 @@ public function setAddress($value)
137139
public function getAddress()
138140
{
139141
return $this->address;
142+
}
143+
144+
/*
145+
Set the JavaScript Code to execute in the web page.
146+
*/
147+
public function setJavaScriptCode($value)
148+
{
149+
$this->jsCode = $value;
150+
}
151+
152+
/*
153+
Get the JavaScript Code to execute in the web page.
154+
*/
155+
public function getJavaScriptCode()
156+
{
157+
return $this->jsCode;
158+
}
159+
160+
/*
161+
Set the CSS selector of the HTML element in the web page to click.
162+
*/
163+
public function setClickElement($value)
164+
{
165+
$this->clickElement = $value;
166+
}
167+
168+
/*
169+
Get the CSS selector of the HTML element in the web page to click.
170+
*/
171+
public function getClickElement()
172+
{
173+
return $this->clickElement;
140174
}
141175

142176
/*
@@ -169,7 +203,8 @@ public function _getSignatureString($applicationSecret, $callBackURL, $url = nul
169203
"|".$this->nullToEmpty($this->browserHeight)
170204
."|".$this->nullToEmpty($this->browserWidth)."|".$this->nullToEmpty($this->getCustomId())."|".$this->nullToEmpty($this->delay)."|".$this->nullToEmpty(intval($this->requestAs))."|".$this->nullToEmpty($this->getCountry())."|".
171205
$this->nullToEmpty($this->getExportURL())."|".
172-
$this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty($this->getEncryptionKey())."|".$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications));
206+
$this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty($this->getEncryptionKey())."|".$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->getProxy())."|".
207+
$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications))."|".$this->nullToEmpty($this->clickElement)."|".$this->nullToEmpty($this->jsCode);
173208
}
174209

175210
public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue)
@@ -184,6 +219,8 @@ public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $
184219
$params['post'] = $this->nullToEmpty($this->post);
185220
$params['address'] = $this->nullToEmpty($this->address);
186221
$params['nonotify'] = $this->nullToEmpty(intval($this->noCookieNotifications));
222+
$params['click'] = $this->nullToEmpty($this->clickElement);
223+
$params['jscode'] = $this->nullToEmpty($this->jsCode);
187224

188225
return $params;
189226
}

lib/GrabzItImageOptions.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class GrabzItImageOptions extends GrabzItBaseOptions
2020
private $noCookieNotifications = false;
2121
private $address = null;
2222
private $hd = false;
23+
private $jsCode = null;
2324

2425
/*
2526
Set the width of the browser in pixels.
@@ -307,6 +308,22 @@ public function setAddress($value)
307308
public function getAddress()
308309
{
309310
return $this->address;
311+
}
312+
313+
/*
314+
Set the JavaScript Code to execute in the web page.
315+
*/
316+
public function setJavaScriptCode($value)
317+
{
318+
$this->jsCode = $value;
319+
}
320+
321+
/*
322+
Get the JavaScript Code to execute in the web page.
323+
*/
324+
public function getJavaScriptCode()
325+
{
326+
return $this->jsCode;
310327
}
311328

312329
/*
@@ -340,7 +357,9 @@ public function _getSignatureString($applicationSecret, $callBackURL, $url = nul
340357
."|".$this->nullToEmpty($this->browserWidth)."|".$this->nullToEmpty($this->getCustomId())."|".$this->nullToEmpty($this->delay)."|".$this->nullToEmpty($this->targetElement)
341358
."|".$this->nullToEmpty($this->customWaterMarkId)."|".$this->nullToEmpty(intval($this->requestAs))."|".$this->nullToEmpty($this->getCountry())."|".
342359
$this->nullToEmpty($this->quality)."|".$this->nullToEmpty($this->hideElement)."|".$this->nullToEmpty($this->getExportURL())."|".
343-
$this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty(intval($this->transparent))."|".$this->nullToEmpty($this->getEncryptionKey())."|".$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications))."|".$this->nullToEmpty(intval($this->hd))."|".$this->nullToEmpty($this->clickElement);
360+
$this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty(intval($this->transparent))."|".$this->nullToEmpty($this->getEncryptionKey())."|".
361+
$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->address)."|".
362+
$this->nullToEmpty(intval($this->noCookieNotifications))."|".$this->nullToEmpty(intval($this->hd))."|".$this->nullToEmpty($this->clickElement)."|".$this->nullToEmpty($this->jsCode);
344363
}
345364

346365
public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue)
@@ -365,6 +384,7 @@ public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $
365384
$params['nonotify'] = $this->nullToEmpty(intval($this->noCookieNotifications));
366385
$params['hd'] = $this->nullToEmpty(intval($this->hd));
367386
$params['click'] = $this->nullToEmpty($this->clickElement);
387+
$params['jscode'] = $this->nullToEmpty($this->jsCode);
368388

369389
return $params;
370390
}

lib/GrabzItPDFOptions.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class GrabzItPDFOptions extends GrabzItBaseOptions
3232
private $address = null;
3333
private $cssMediaType = null;
3434
private $password = null;
35+
private $jsCode = null;
3536

3637
/*
3738
Set the width of the resulting PDF in mm.
@@ -500,6 +501,22 @@ public function getPassword()
500501
return $this->password;
501502
}
502503

504+
/*
505+
Set the JavaScript Code to execute in the web page.
506+
*/
507+
public function setJavaScriptCode($value)
508+
{
509+
$this->jsCode = $value;
510+
}
511+
512+
/*
513+
Get the JavaScript Code to execute in the web page.
514+
*/
515+
public function getJavaScriptCode()
516+
{
517+
return $this->jsCode;
518+
}
519+
503520
/*
504521
Define a HTTP Post parameter and optionally value, this method can be called multiple times to add multiple parameters. Using this method will force
505522
GrabzIt to perform a HTTP post.
@@ -548,7 +565,7 @@ public function _getSignatureString($applicationSecret, $callBackURL, $url = nul
548565
$this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty($this->getEncryptionKey())."|".$this->nullToEmpty(intval($this->noAds))."|".
549566
$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->browserWidth)."|".$this->nullToEmpty($this->height)."|".$this->nullToEmpty($this->width)."|".
550567
$this->nullToEmpty($this->templateVariables)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->mergeId)."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications))."|".$this->nullToEmpty($this->cssMediaType)."|".
551-
$this->nullToEmpty($this->password)."|".$this->nullToEmpty($this->clickElement);
568+
$this->nullToEmpty($this->password)."|".$this->nullToEmpty($this->clickElement)."|".$this->nullToEmpty($this->jsCode);
552569
}
553570

554571
public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue)
@@ -585,6 +602,7 @@ public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $
585602
$params['media'] = $this->nullToEmpty($this->cssMediaType);
586603
$params['password'] = $this->nullToEmpty($this->password);
587604
$params['click'] = $this->nullToEmpty($this->clickElement);
605+
$params['jscode'] = $this->nullToEmpty($this->jsCode);
588606

589607
return $params;
590608
}

lib/GrabzItVideoOptions.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class GrabzItVideoOptions extends GrabzItBaseOptions
1616
private $clickElement = null;
1717
private $noAds = false;
1818
private $noCookieNotifications = false;
19-
private $address = null;
19+
private $address = null;
20+
private $jsCode = null;
2021

2122
/*
2223
Set the number of frames per second that should be used to create the video. From a minimum of 0.2 to a maximum of 10.
@@ -242,6 +243,22 @@ public function getClickElement()
242243
return $this->clickElement;
243244
}
244245

246+
/*
247+
Set the JavaScript Code to execute in the web page.
248+
*/
249+
public function setJavaScriptCode($value)
250+
{
251+
$this->jsCode = $value;
252+
}
253+
254+
/*
255+
Get the JavaScript Code to execute in the web page.
256+
*/
257+
public function getJavaScriptCode()
258+
{
259+
return $this->jsCode;
260+
}
261+
245262
public function _getSignatureString($applicationSecret, $callBackURL, $url = null)
246263
{
247264
$urlParam = '';
@@ -262,7 +279,7 @@ public function _getSignatureString($applicationSecret, $callBackURL, $url = nul
262279
$this->nullToEmpty(intval($this->requestAs))."|".$this->nullToEmpty($this->getCountry())."|".$this->nullToEmpty($this->getExportURL())."|".
263280
$this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty($this->getEncryptionKey())."|".
264281
$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications))."|".
265-
$this->nullToEmpty($this->clickElement)."|".$this->nullToEmpty($this->framesPerSecond)."|".$this->nullToEmpty($this->duration)."|".$this->nullToEmpty($this->width)."|".$this->nullToEmpty($this->height);
282+
$this->nullToEmpty($this->clickElement)."|".$this->nullToEmpty($this->framesPerSecond)."|".$this->nullToEmpty($this->duration)."|".$this->nullToEmpty($this->width)."|".$this->nullToEmpty($this->height)."|".$this->nullToEmpty($this->jsCode);
266283
}
267284

268285
public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue)
@@ -283,6 +300,7 @@ public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $
283300
$params['address'] = $this->nullToEmpty($this->address);
284301
$params['nonotify'] = $this->nullToEmpty(intval($this->noCookieNotifications));
285302
$params['click'] = $this->nullToEmpty($this->clickElement);
303+
$params['jscode'] = $this->nullToEmpty($this->jsCode);
286304

287305
return $params;
288306
}

readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GrabzIt 3.5
22
===========
33

4-
This library allows you to programmatically convert HTML and URL's into images, DOCX documents, videos, rendered HTML, PDF's, CSV's, spreadsheets and JSON. Additionally GrabzIt allows you to convert online videos into animated GIF's.
4+
This library allows you to programmatically convert HTML and URL's into images, DOCX documents, rendered HTML, PDF's, CSV's, spreadsheets and JSON. Additionally GrabzIt allows you to convert online videos into animated GIF's.
55

66
It is usually best to place these package files in their own directory.
77

@@ -21,4 +21,4 @@ Ensure your application has read and write access to the "results" directory.
2121

2222
Finally run the index.php to start converting web pages.
2323

24-
More documentation can be found at: https://grabz.it/api/php/
24+
More documentation can be found at: https://grabz.it/api/php/

0 commit comments

Comments
 (0)