Browse Source

stat, campaign

master
4026 2 years ago
parent
commit
610c560eb2
1 changed files with 184 additions and 2 deletions
  1. +184
    -2
      ninjamail.class.php

+ 184
- 2
ninjamail.class.php View File

@ -23,12 +23,13 @@ class ninjaMail
public function process($f, $data, $post_method = true)
{
$ch = curl_init($this->host.'/a/'.$f.'/?key='.$this->key);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$data = curl_exec($ch);
curl_close($ch);
$data = @(object)json_decode($response);
$data = @(object)json_decode($data);
$this->data = $data;
return $data;
}
@ -40,6 +41,7 @@ class ninjaMail
}
// Send Email
class ninjaMailSend extends ninjaMail
{
@ -81,6 +83,7 @@ class ninjaMailSend extends ninjaMail
}
}
// Subscribe
class ninjaMailSubscription extends ninjaMail
{
@ -133,4 +136,183 @@ class ninjaMailSubscription extends ninjaMail
}
// Newsletter
class ninjaMailNewsletter extends ninjaMail
{
private $newsletter;
private $subject;
private $message;
private $message_text;
public function newsletter($id = false)
{
if (is_numeric($id))
{
$this->newsletter = $id;
return true;
}
return $this->newsletter;
}
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 query($update = false)
{
if (!$this->message)
return false;
$post = [
'new' => true,
'id' => $update ? $this->newsletter : false,
'subject' => $this->subject,
'message' => $this->message,
'message_text' => $this->message_text
];
$data = $this->process('newsletter', $post, true);
if ($data->status == 'success')
{
$this->newsletter = $data->id;
return $data->id;
}
return false;
}
public function create()
{
return $this->query(false);
}
public function update()
{
if (!$this->newsletter)
return false;
return $this->query(true);
}
public function send($time = false)
{
if (!$this->newsletter)
return false;
$post = [
'send' => true,
'id' => $this->newsletter,
'start' => $time ? $time : 0
];
$data = $this->process('newsletter', $post, true);
if ($data->status == 'success' || $this->status == 'already_queued')
return true;
return false;
}
public function get()
{
return $this->process('newsletter', ['get' => true], true);
}
}
// Campaign
class ninjaMailCampaign extends ninjaMail
{
private $campaign;
public function campaign($id = false)
{
if (!$id)
return $this->campaign;
if (is_numeric($id))
{
$this->campaign = $id;
return true;
}
return false;
}
public function create($name)
{
$post = [
'new' => true,
'name' => $name
];
$data = $this->process('campaign', $post, true);
if ($data->status == 'success')
{
$this->campaign = $data->id;
return $data->id;
}
return false;
}
public function remove()
{
$post = [
'remove' => true,
'id' => $this->campaign
];
return $this->process('campaign', $post, true)->status == 'success' ? true : false;
}
public function update($lists)
{
if (!is_array($lists))
return false;
$post = [
'update' => true,
'id' => $this->campaign,
'lists' => $lists
];
return $this->process('campaign', $post, true)->status == 'success' ? true : false;
}
public function attach($newsletter)
{
if (!is_numeric($newsletter))
return false;
$post = [
'relations' => true,
'id' => $this->campaign,
'newsletter' => $newsletter
];
return $this->process('campaign', $post, true)->status == 'success' ? true : false;
}
}
// Statistics
class ninjaMailStatistics extends ninjaMail
{
public function get($id)
{
if (!is_numeric($id))
return false;
$post = [
'newsletter' => $id,
'type' => 1
];
return $this->process('statistics', $post, true);
}
}

Loading…
Cancel
Save