Allow name change

This commit is contained in:
Sándor 2021-09-20 12:29:59 +02:00
parent a3768e996d
commit f120fb88d3
1 changed files with 327 additions and 318 deletions

View File

@ -1,318 +1,327 @@
<?php <?php
class ninjaMail class ninjaMail
{ {
private $host; private $host;
private $key; private $key;
public $data; public $data;
public function __construct($host, $key = false) public function __construct($host, $key = false)
{ {
$this->host = $host; $this->host = $host;
if ($key) $this->key = $key; if ($key) $this->key = $key;
} }
public function check() public function check()
{ {
if (!$this->host || !$this->key) if (!$this->host || !$this->key)
return false; return false;
return true; return true;
} }
public function process($f, $data, $post_method = true) public function process($f, $data, $post_method = true)
{ {
$ch = curl_init($this->host.'/a/'.$f.'/?key='.$this->key); $ch = curl_init($this->host.'/a/'.$f.'/?key='.$this->key);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$data = curl_exec($ch); $data = curl_exec($ch);
curl_close($ch); curl_close($ch);
$data = @(object)json_decode($data); $data = @(object)json_decode($data);
$this->data = $data; $this->data = $data;
return $data; return $data;
} }
public function login() public function login()
{ {
return $this->process('login', ['rkey' => md5(time().rand(0,65500).rand(0,10))]); return $this->process('login', ['rkey' => md5(time().rand(0,65500).rand(0,10))]);
} }
} }
// Send Email // Send Email
class ninjaMailSend extends ninjaMail class ninjaMailSend extends ninjaMail
{ {
private $to; private $to;
private $subject; private $subject;
private $message; private $message;
private $message_text; private $message_text;
public function to($to) public function to($to)
{ {
$this->to = $to; $this->to = $to;
return true; return true;
} }
public function subject($s) public function subject($s)
{ {
$this->subject = $s; $this->subject = $s;
return true; return true;
} }
public function message($m, $t = false) public function message($m, $t = false)
{ {
$this->message = $m; $this->message = $m;
if (!$t) $this->message_text = trim(strip_tags($m)); if (!$t) $this->message_text = trim(strip_tags($m));
else $this->message_text = $t; else $this->message_text = $t;
return true; return true;
} }
public function send() public function send()
{ {
$post = [ $post = [
'to' => $this->to, 'to' => $this->to,
'subject' => $this->subject, 'subject' => $this->subject,
'message' => $this->message, 'message' => $this->message,
'message_text' => $this->message_text 'message_text' => $this->message_text
]; ];
return $this->process('send', $post, true)->status == 'message_queued' ? true : false; return $this->process('send', $post, true)->status == 'message_queued' ? true : false;
} }
} }
// Subscribe // Subscribe
class ninjaMailSubscription extends ninjaMail class ninjaMailSubscription extends ninjaMail
{ {
private $list; private $list;
private $activated = false; private $activated = 0;
private $forcenamechange = 0;
public function list($id)
{ public function list($id)
if (is_numeric($id)) {
{ if (is_numeric($id))
$this->list = $id; {
return true; $this->list = $id;
} return true;
return false; }
} return false;
}
public function activated($s)
{ public function activated($s)
if ($s) $this->activated = 1; {
else $this->activated = 0; if ($s) $this->activated = 1;
return true; else $this->activated = 0;
} return true;
}
public function subscribe($email, $name = '')
{ public function namechange($s)
if (!$this->list || !is_numeric($this->activated)) {
return false; if ($s) $this->forcenamechange = 1;
else $this->forcenamechange = 0;
$post = [ return true;
'list' => $this->list, }
'name' => $name,
'email' => $email, public function subscribe($email, $name = '')
'activated' => $this->activated {
]; if (!$this->list || !is_numeric($this->activated))
return $this->process('subscribe', $post, true)->status == 'success' ? true : false; return false;
}
$post = [
public function unsubscribe($email) 'list' => $this->list,
{ 'name' => $name,
if (!$this->list) 'email' => $email,
return false; 'activated' => $this->activated,
'forcenamechange' => $this->forcenamechange
$post = [ ];
'list' => $this->list, return $this->process('subscribe', $post, true)->status == 'success' ? true : false;
'email' => $email }
];
return $this->process('unsubscribe', $post, true)->status == 'success' ? true : false; public function unsubscribe($email)
} {
} if (!$this->list)
return false;
// Newsletter $post = [
class ninjaMailNewsletter extends ninjaMail 'list' => $this->list,
{ 'email' => $email
];
private $newsletter; return $this->process('unsubscribe', $post, true)->status == 'success' ? true : false;
private $subject; }
private $message; }
private $message_text;
// Newsletter
public function newsletter($id = false) class ninjaMailNewsletter extends ninjaMail
{ {
if (is_numeric($id))
{ private $newsletter;
$this->newsletter = $id; private $subject;
return true; private $message;
} private $message_text;
return $this->newsletter;
}
public function newsletter($id = false)
public function subject($s) {
{ if (is_numeric($id))
$this->subject = $s; {
return true; $this->newsletter = $id;
} return true;
}
public function message($m, $t = false) return $this->newsletter;
{ }
$this->message = $m;
if (!$t) $this->message_text = trim(strip_tags($m)); public function subject($s)
else $this->message_text = $t; {
return true; $this->subject = $s;
} return true;
}
public function query($update = false)
{ public function message($m, $t = false)
if (!$this->message) {
return false; $this->message = $m;
if (!$t) $this->message_text = trim(strip_tags($m));
$post = [ else $this->message_text = $t;
'new' => true, return true;
'id' => $update ? $this->newsletter : false, }
'subject' => $this->subject,
'message' => $this->message, public function query($update = false)
'message_text' => $this->message_text {
]; if (!$this->message)
$data = $this->process('newsletter', $post, true); return false;
if ($data->status == 'success')
{ $post = [
$this->newsletter = $data->id; 'new' => true,
return $data->id; 'id' => $update ? $this->newsletter : false,
} 'subject' => $this->subject,
return false; 'message' => $this->message,
} 'message_text' => $this->message_text
];
public function create() $data = $this->process('newsletter', $post, true);
{ if ($data->status == 'success')
return $this->query(false); {
} $this->newsletter = $data->id;
return $data->id;
public function update() }
{ return false;
if (!$this->newsletter) }
return false;
public function create()
return $this->query(true); {
} return $this->query(false);
}
public function send($time = false)
{ public function update()
if (!$this->newsletter) {
return false; if (!$this->newsletter)
return false;
$post = [
'send' => true, return $this->query(true);
'id' => $this->newsletter, }
'start' => $time ? $time : 0
]; public function send($time = false)
$data = $this->process('newsletter', $post, true); {
if ($data->status == 'success' || $this->status == 'already_queued') if (!$this->newsletter)
return true; return false;
return false; $post = [
} 'send' => true,
'id' => $this->newsletter,
public function get() 'start' => $time ? $time : 0
{ ];
return $this->process('newsletter', ['get' => true], true); $data = $this->process('newsletter', $post, true);
} if ($data->status == 'success' || $this->status == 'already_queued')
} return true;
return false;
// Campaign }
class ninjaMailCampaign extends ninjaMail
{ public function get()
private $campaign; {
return $this->process('newsletter', ['get' => true], true);
public function campaign($id = false) }
{ }
if (!$id)
return $this->campaign;
// Campaign
if (is_numeric($id)) class ninjaMailCampaign extends ninjaMail
{ {
$this->campaign = $id; private $campaign;
return true;
} public function campaign($id = false)
return false; {
} if (!$id)
return $this->campaign;
public function create($name)
{ if (is_numeric($id))
$post = [ {
'new' => true, $this->campaign = $id;
'name' => $name return true;
]; }
$data = $this->process('campaign', $post, true); return false;
if ($data->status == 'success') }
{
$this->campaign = $data->id; public function create($name)
return $data->id; {
} $post = [
'new' => true,
return false; 'name' => $name
} ];
$data = $this->process('campaign', $post, true);
public function remove() if ($data->status == 'success')
{ {
$post = [ $this->campaign = $data->id;
'remove' => true, return $data->id;
'id' => $this->campaign }
];
return $this->process('campaign', $post, true)->status == 'success' ? true : false; return false;
} }
public function update($lists) public function remove()
{ {
if (!is_array($lists)) $post = [
return false; 'remove' => true,
'id' => $this->campaign
$post = [ ];
'update' => true, return $this->process('campaign', $post, true)->status == 'success' ? true : false;
'id' => $this->campaign, }
'lists' => $lists
]; public function update($lists)
return $this->process('campaign', $post, true)->status == 'success' ? true : false; {
} if (!is_array($lists))
return false;
public function attach($newsletter)
{ $post = [
if (!is_numeric($newsletter)) 'update' => true,
return false; 'id' => $this->campaign,
'lists' => $lists
$post = [ ];
'relations' => true, return $this->process('campaign', $post, true)->status == 'success' ? true : false;
'id' => $this->campaign, }
'newsletter' => $newsletter
]; public function attach($newsletter)
return $this->process('campaign', $post, true)->status == 'success' ? true : false; {
} if (!is_numeric($newsletter))
} return false;
$post = [
// Statistics 'relations' => true,
class ninjaMailStatistics extends ninjaMail 'id' => $this->campaign,
{ 'newsletter' => $newsletter
];
public function get($id) return $this->process('campaign', $post, true)->status == 'success' ? true : false;
{ }
if (!is_numeric($id)) }
return false;
$post = [ // Statistics
'newsletter' => $id, class ninjaMailStatistics extends ninjaMail
'type' => 1 {
];
return $this->process('statistics', $post, true); public function get($id)
} {
if (!is_numeric($id))
} return false;
$post = [
'newsletter' => $id,
'type' => 1
];
return $this->process('statistics', $post, true);
}
}