Skip to content

Commit 30ca9d5

Browse files
authored
Fixes for problems with running restapi tests (#72)
* Avoid php deprecation about the naming of constructor * Fix error in outputting error message * Simplify deriving the URL to call and include the secret parameter if required
1 parent 6e71d95 commit 30ca9d5

3 files changed

Lines changed: 26 additions & 27 deletions

File tree

plugins/restapi/call.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@
5252
}
5353
$ipAddress = getConfig('restapi_ipaddress');
5454
if (!empty($ipAddress) && ($GLOBALS['remoteAddr'] != $ipAddress)) {
55-
$response->outputErrorMessage('Incorrect ip address for request. Check your settings.');
55+
Response::outputErrorMessage('Incorrect ip address for request. Check your settings.');
5656
die(0);
57-
}
57+
}
5858
$requireSecret = getConfig('restapi_usesecret');
5959
if ($requireSecret) {
6060
$secret = getConfig('remote_processing_secret');
6161
if (empty($_REQUEST['secret']) || $_REQUEST['secret'] != $secret) {
62-
$response->outputErrorMessage('Incorrect processing secret. Check your settings.');
62+
Response::outputErrorMessage('Incorrect processing secret. Check your settings.');
6363
die(0);
6464
}
65-
}
65+
}
6666
$enforceSSL = getConfig('restapi_enforcessl');
6767
if ($enforceSSL && empty($_SERVER['HTTPS'])) {
68-
$response->outputErrorMessage('Invalid API request. Request is not using SSL, which is enforced by the plugin settings.');
68+
Response::outputErrorMessage('Invalid API request. Request is not using SSL, which is enforced by the plugin settings.');
6969
die(0);
7070
}
7171

plugins/restapi_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class restapi_test extends phplistPlugin
2727
),
2828
);
2929

30-
public function restapi_test()
30+
public function __construct()
3131
{
32-
parent::phplistplugin();
32+
parent::__construct();
3333
$this->coderoot = dirname(__FILE__).'/restapi_test/';
3434
}
3535

plugins/restapi_test/main.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
if (empty($login)) {
1919
print Error('Please configure the login details in the settings page<br/>Parameters: <strong>restapi_test_login</strong> and <strong>restapi_test_password</strong> for admin login.');
2020
?>
21-
<form method="POST">
22-
<input type="text" placeholder="restapi_test_login" name="restapi_test_login" /><br/>
23-
<input type="password" placeholder="restapi_test_password" name="restapi_test_password" /><br/>
24-
<input type="submit" value="Save" />
25-
</form>
26-
<?php
21+
<form method="POST">
22+
<input type="text" placeholder="restapi_test_login" name="restapi_test_login" /><br/>
23+
<input type="password" placeholder="restapi_test_password" name="restapi_test_password" /><br/>
24+
<input type="submit" value="Save" />
25+
</form>
26+
<?php
2727

2828
return;
2929
}
@@ -187,8 +187,8 @@
187187

188188
?>
189189

190-
<h2>Step <?php echo $step++; ?> - Count subscribers / subscribers AGAIN!</h2>
191-
<?php
190+
<h2>Step <?php echo $step++; ?> - Count subscribers / subscribers AGAIN!</h2>
191+
<?php
192192

193193
$result = $api->subscribersGet();
194194
if ($result->status != 'success') {
@@ -395,7 +395,7 @@
395395

396396
?>
397397

398-
<h2>The test completed successfully!</h2>
398+
<h2>The test completed successfully!</h2>
399399

400400
</html>
401401

@@ -406,28 +406,27 @@
406406
*/
407407
function apiUrl($website)
408408
{
409-
$url = '';
409+
global $adminpages, $website;
410410

411411
if (!empty($_SERVER['HTTPS'])) {
412412

413413
// Check which protocol to use
414414
if ($_SERVER['HTTPS'] !== 'off') {
415-
$url = 'https://'; //https
415+
$scheme = 'https'; //https
416416
} else {
417-
$url = 'http://'; //http
417+
$scheme = 'http'; //http
418418
}
419419
} else {
420-
$url = 'http://'; //http
420+
$scheme = 'http'; //http
421421
}
422+
$params = ['page' => 'call', 'pi' => 'restapi'];
422423

423-
$api_url = str_replace('page=main&pi=restapi_test', 'page=call&pi=restapi', $_SERVER['REQUEST_URI']);
424-
$api_url = preg_replace('/\&tk\=[^&]*/', '', $api_url);
425-
$api_url1 = str_replace('page=main&pi=restapi', 'page=call&pi=restapi', $api_url);
426-
427-
$concatenatedUrl = $url.$website.$api_url1;
428-
$trimmedUrl = rtrim($concatenatedUrl, '/');
424+
if (getConfig('restapi_usesecret')) {
425+
$params['secret'] = getConfig('remote_processing_secret');
426+
}
427+
$url = sprintf('%s://%s%s/?%s', $scheme, $website, $adminpages, http_build_query($params));
429428

430-
return $trimmedUrl;
429+
return $url;
431430
}
432431

433432
?>

0 commit comments

Comments
 (0)