Skip to content

Commit

Permalink
Add Blacklist class and BlacklistedEmailInfo (API 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
SRJ9 committed Feb 16, 2017
1 parent 08c3e14 commit 81bd84d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/restapi/call.php
Expand Up @@ -16,6 +16,7 @@
include_once 'includes/subscribers.php';
include_once 'includes/templates.php';
include_once 'includes/campaigns.php';
include_once 'includes/blacklist.php';
//If other than POST then assume documentation report
if (strcmp($_SERVER['REQUEST_METHOD'], 'POST')) {
include_once 'doc/doc.php';
Expand All @@ -25,6 +26,7 @@
$doc->addClass('Subscribers');
$doc->addClass('Templates');
$doc->addClass('Campaigns');
$doc->addClass('Blacklist');
print $doc->output();
return;
}
Expand Down Expand Up @@ -84,5 +86,9 @@
Campaigns::$cmd();
}

if (is_callable(array('phpListRestapi\Blacklist', $cmd))) {
Blacklist::$cmd();
}

//If no command found, return error message!
Response::outputErrorMessage('No function for provided [cmd] found!');
68 changes: 68 additions & 0 deletions plugins/restapi/includes/blacklist.php
@@ -0,0 +1,68 @@
<?php

namespace phpListRestapi;

defined('PHPLISTINIT') || die;

class Blacklist
{
/**
* Check if a email or user (by email) is in blacklist and the reason if exists.
* @param string $email Email to check in blacklist
*/

/**
* Check if a email or user (by email) is in blacklist and the reason if exists.
*
* <p><strong>Parameters:</strong><br/>
* [*email] {string} Email to check in blacklist<br/>
* <p><strong>Returns:</strong><br/>
* Type (whitelist, blacklist) and the reason if is in blacklisted.
* </p>
*/
public static function blacklistedEmailInfo($email=''){
if($email == ''){
$email = $_REQUEST['email'];
}
if ($email == '') {
Response::outputErrorMessage('Email param is empty');
}
$response = new Response();

$sql = "SELECT ". $GLOBALS['tables']['user_blacklist'] . ".email, added, `data` as reason FROM "
. $GLOBALS['tables']['user_blacklist'] . " INNER JOIN ".$GLOBALS['tables']['user_blacklist_data']
. " ON ".$GLOBALS['tables']['user_blacklist'] . ".email=".$GLOBALS['tables']['user_blacklist_data'] .".email"
." WHERE ".$GLOBALS['tables']['user_blacklist'].".email = :email"
. "
UNION
(
SELECT email, null, 'Blacklist by profile user'
FROM " . $GLOBALS['tables']['user'] . " WHERE blacklisted=1 AND email = :email
)
LIMIT 1
"
;
try {
$db = PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam('email', $email, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_OBJ); // only first coincidence.
if($result){
$response->setData('blacklist', $result); // type attribute == 'blacklist'
} else {
$result = array(
'email' => $email
);
$response->setData('whitelist', $result); // type attribute == 'whitelist'
}
$db = null;
$response->output();
} catch(\PDOException $e) {
Response::outputError($e);
}
die(0);
}


}

0 comments on commit 81bd84d

Please sign in to comment.