mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-09-02 18:25:11 +00:00
fixed PUT via curl, addde mailgun unsubscribe
This commit is contained in:
parent
b2f8bc619a
commit
c298e5860c
2 changed files with 38 additions and 8 deletions
37
lib/thirdparty/Mailgun.class.php
vendored
37
lib/thirdparty/Mailgun.class.php
vendored
|
@ -6,6 +6,29 @@ class Mailgun
|
|||
|
||||
const LIST_GENERAL = 'lbryians@lbry.io';
|
||||
|
||||
public static function unsubscribeFromMailingList($listAddress, $email)
|
||||
{
|
||||
list($status, $headers, $body) = static::put('/lists/' . $listAddress . '/members/' . $email, [
|
||||
'subscribed' => 'no',
|
||||
]);
|
||||
|
||||
if ($status == 200)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$data = json_decode($body, true);
|
||||
$message = $data['error'] ?? $data['message'] ?? false;
|
||||
|
||||
if (strpos($message, 'Member '.$email) === 0 && strrpos($message, ' not found') === (strlen($message) - strlen(' not found')))
|
||||
{
|
||||
// message says "Member $email ... not found", so email is not on list. that's the same as unsubscribing, right?
|
||||
return true;
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public static function sendDmcaReport($data)
|
||||
{
|
||||
list($status, $headers, $body) = static::post('/lbry.io/messages', [
|
||||
|
@ -89,7 +112,17 @@ class Mailgun
|
|||
|
||||
protected static function post($endpoint, $data)
|
||||
{
|
||||
return Curl::doCurl(Curl::POST, self::BASE_URL . $endpoint, $data, [
|
||||
return static::request(Curl::POST, $endpoint, $data);
|
||||
}
|
||||
|
||||
protected static function put($endpoint, $data)
|
||||
{
|
||||
return static::request(Curl::PUT, $endpoint, $data);
|
||||
}
|
||||
|
||||
protected static function request($method, $endpoint, $data)
|
||||
{
|
||||
return Curl::doCurl($method, self::BASE_URL . $endpoint, $data, [
|
||||
'headers' => [
|
||||
'Authorization: Basic ' . base64_encode('api:' . Config::get('mailgun_api_key'))
|
||||
],
|
||||
|
@ -102,4 +135,4 @@ class Mailgun
|
|||
$e = new \Pelago\Emogrifier($html, $css);
|
||||
return trim($e->emogrify());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ class Curl
|
|||
$ch = curl_init();
|
||||
|
||||
// curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
// curl_setopt($ch, CURLOPT_STDERR, fopen('php://temp', 'w+'));
|
||||
// curl_setopt($ch, CURLOPT_STDERR, fopen(sys_get_temp_dir().'/curl-debug-'.date('Ymd-His'), 'w+'));
|
||||
|
||||
if ($ch === false || $ch === null)
|
||||
{
|
||||
|
@ -100,12 +100,9 @@ class Curl
|
|||
{
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
}
|
||||
|
||||
if ($method == static::PUT)
|
||||
elseif ($method == static::PUT)
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_PUT, 1);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
}
|
||||
|
||||
if (in_array($method, [static::PUT, static::POST]))
|
||||
|
|
Loading…
Add table
Reference in a new issue