PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Calculation / Web / Service.php

Service.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Web/Service.php

76 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Calculation\Web;
4
5 use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
6 use PhpOffice\PhpSpreadsheet\Settings;
7 use Psr\Http\Client\ClientExceptionInterface;
8
9 class Service
10 {
11 /**
12 * WEBSERVICE.
13 *
14 * Returns data from a web service on the Internet or Intranet.
15 *
16 * Excel Function:
17 * Webservice(url)
18 *
19 * @return string the output resulting from a call to the webservice
20 */
21 public static function webService(string $url)
22 {
23 $url = trim($url);
24 if (strlen($url) > 2048) {
25 return ExcelError::VALUE(); // Invalid URL length
26 }
27
28 if (!preg_match('/^http[s]?:\/\//', $url)) {
29 return ExcelError::VALUE(); // Invalid protocol
30 }
31
32 // Get results from the the webservice
33 $client = Settings::getHttpClient();
34 $requestFactory = Settings::getRequestFactory();
35 $request = $requestFactory->createRequest('GET', $url);
36
37 try {
38 $response = $client->sendRequest($request);
39 } catch (ClientExceptionInterface $e) {
40 return ExcelError::VALUE(); // cURL error
41 }
42
43 if ($response->getStatusCode() != 200) {
44 return ExcelError::VALUE(); // cURL error
45 }
46
47 $output = $response->getBody()->getContents();
48 if (strlen($output) > 32767) {
49 return ExcelError::VALUE(); // Output not a string or too long
50 }
51
52 return $output;
53 }
54
55 /**
56 * URLENCODE.
57 *
58 * Returns data from a web service on the Internet or Intranet.
59 *
60 * Excel Function:
61 * urlEncode(text)
62 *
63 * @param mixed $text
64 *
65 * @return string the url encoded output
66 */
67 public static function urlEncode($text)
68 {
69 if (!is_string($text)) {
70 return ExcelError::VALUE();
71 }
72
73 return str_replace('+', '%20', urlencode($text));
74 }
75 }
76