ninjaMail_public/ninjamail.class.php

137 lines
3.1 KiB
PHP
Raw Normal View History

2019-04-05 20:59:23 +02:00
<?php
class ninjaMail
{
private $host;
private $key;
public $data;
public function __construct($host, $key = false)
{
$this->host = $host;
if ($key) $this->key = $key;
}
public function check()
{
if (!$this->host || !$this->key)
return false;
return true;
}
public function process($f, $data, $post_method = true)
{
$ch = curl_init($this->host.'/a/'.$f.'/?key='.$this->key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$data = curl_exec($ch);
curl_close($ch);
$data = @(object)json_decode($response);
$this->data = $data;
return $data;
}
public function login()
{
return $this->process('login', ['rkey' => md5(time().rand(0,65500).rand(0,10))]);
}
}
// Send Email
class ninjaMailSend extends ninjaMail
{
private $to;
private $subject;
private $message;
private $message_text;
public function to($to)
{
$this->to = $to;
return true;
}
public function subject($s)
{
$this->subject = $s;
return true;
}
public function message($m, $t = false)
{
$this->message = $m;
if (!$t) $this->message_text = trim(strip_tags($m));
else $this->message_text = $t;
return true;
}
public function send()
{
$post = [
'to' => $this->to,
'subject' => $this->subject,
'message' => $this->message,
'message_text' => $this->message_text
];
return $this->process('send', $post, true)->status == 'message_queued' ? true : false;
}
}
// Subscribe
class ninjaMailSubscription extends ninjaMail
{
private $list;
private $activated = false;
public function list($id)
{
if (is_numeric($id))
{
$this->list = $id;
return true;
}
return false;
}
public function activated($s)
{
if ($s) $this->activated = 1;
else $this->activated = 0;
return true;
}
public function subscribe($email, $name = '')
{
if (!$this->list || !is_numeric($this->activated))
return false;
$post = [
'list' => $this->list,
'name' => $name,
'email' => $email,
'activated' => $this->activated
];
return $this->process('subscribe', $post, true)->status == 'success' ? true : false;
}
public function unsubscribe($email)
{
if (!$this->list)
return false;
$post = [
'list' => $this->list,
'email' => $email
];
return $this->process('unsubscribe', $post, true)->status == 'success' ? true : false;
}
}