Skip to content

Commit fee6bfe

Browse files
authored
Merge pull request phpList#46 from SRJ9/blacklisted-email-info
Add BlacklistedEmailInfo (API 1)
2 parents 46eb99c + 81bd84d commit fee6bfe

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ plugins/restapi/output/
33
/composer.lock
44
/.php_cs.cache
55
/behat.yml
6+
.idea

plugins/restapi/call.php

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
include_once 'includes/subscribers.php';
1717
include_once 'includes/templates.php';
1818
include_once 'includes/campaigns.php';
19+
include_once 'includes/blacklist.php';
1920
//If other than POST then assume documentation report
2021
if (strcmp($_SERVER['REQUEST_METHOD'], 'POST')) {
2122
include_once 'doc/doc.php';
@@ -25,6 +26,7 @@
2526
$doc->addClass('Subscribers');
2627
$doc->addClass('Templates');
2728
$doc->addClass('Campaigns');
29+
$doc->addClass('Blacklist');
2830
print $doc->output();
2931
return;
3032
}
@@ -84,5 +86,9 @@
8486
Campaigns::$cmd();
8587
}
8688

89+
if (is_callable(array('phpListRestapi\Blacklist', $cmd))) {
90+
Blacklist::$cmd();
91+
}
92+
8793
//If no command found, return error message!
8894
Response::outputErrorMessage('No function for provided [cmd] found!');
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace phpListRestapi;
4+
5+
defined('PHPLISTINIT') || die;
6+
7+
class Blacklist
8+
{
9+
/**
10+
* Check if a email or user (by email) is in blacklist and the reason if exists.
11+
* @param string $email Email to check in blacklist
12+
*/
13+
14+
/**
15+
* Check if a email or user (by email) is in blacklist and the reason if exists.
16+
*
17+
* <p><strong>Parameters:</strong><br/>
18+
* [*email] {string} Email to check in blacklist<br/>
19+
* <p><strong>Returns:</strong><br/>
20+
* Type (whitelist, blacklist) and the reason if is in blacklisted.
21+
* </p>
22+
*/
23+
public static function blacklistedEmailInfo($email=''){
24+
if($email == ''){
25+
$email = $_REQUEST['email'];
26+
}
27+
if ($email == '') {
28+
Response::outputErrorMessage('Email param is empty');
29+
}
30+
$response = new Response();
31+
32+
$sql = "SELECT ". $GLOBALS['tables']['user_blacklist'] . ".email, added, `data` as reason FROM "
33+
. $GLOBALS['tables']['user_blacklist'] . " INNER JOIN ".$GLOBALS['tables']['user_blacklist_data']
34+
. " ON ".$GLOBALS['tables']['user_blacklist'] . ".email=".$GLOBALS['tables']['user_blacklist_data'] .".email"
35+
." WHERE ".$GLOBALS['tables']['user_blacklist'].".email = :email"
36+
. "
37+
UNION
38+
(
39+
SELECT email, null, 'Blacklist by profile user'
40+
FROM " . $GLOBALS['tables']['user'] . " WHERE blacklisted=1 AND email = :email
41+
)
42+
LIMIT 1
43+
"
44+
;
45+
try {
46+
$db = PDO::getConnection();
47+
$stmt = $db->prepare($sql);
48+
$stmt->bindParam('email', $email, PDO::PARAM_STR);
49+
$stmt->execute();
50+
$result = $stmt->fetch(PDO::FETCH_OBJ); // only first coincidence.
51+
if($result){
52+
$response->setData('blacklist', $result); // type attribute == 'blacklist'
53+
} else {
54+
$result = array(
55+
'email' => $email
56+
);
57+
$response->setData('whitelist', $result); // type attribute == 'whitelist'
58+
}
59+
$db = null;
60+
$response->output();
61+
} catch(\PDOException $e) {
62+
Response::outputError($e);
63+
}
64+
die(0);
65+
}
66+
67+
68+
}

plugins/restapi/includes/subscribers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static function subscriberBulkAdd()
224224
$stmtCount = $db->prepare($sqlCount);
225225
$stmtInsert = $db->prepare($sqlInsert);
226226
$stmtUpdate = $db->prepare($sqlUpdate);
227-
$objs = [];
227+
$objs = array(); # <5.3 compatibility
228228
foreach ($subscribers as $subscriber) {
229229
if (!validateEmail($subscriber['email'])) {
230230
Response::outputErrorMessage('invalid email address');

0 commit comments

Comments
 (0)