|
| 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 | +} |
0 commit comments