forked from objectivehtml/Postmaster-for-Craft-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostmasterPlugin.php
112 lines (91 loc) · 3.67 KB
/
PostmasterPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace Craft;
class PostmasterPlugin extends BasePlugin
{
public function getName()
{
return Craft::t('Postmaster');
}
public function getVersion()
{
return '0.5.2';
}
public function getDeveloper()
{
return 'Objective HTML';
}
public function getDeveloperUrl()
{
return 'https://objectivehtml.com';
}
public function hasCpSection()
{
return true;
}
public function addTwigExtension()
{
Craft::import('plugins.postmaster.twigextensions.PostmasterTwigExtension');
return new PostmasterTwigExtension();
}
public function registerSiteRoutes()
{
$routes = array(
'postmaster/send' => array('action' => 'postmaster/forms/send'),
'postmaster/queue/marshal' => array('action' => 'postmaster/queue/marshal'),
'postmaster/notifications/marshal' => array('action' => 'postmaster/notification/marshal'),
'postmaster/notification/marshal/(?P<notificationId>\d+)' => array('action' => 'postmaster/notification/marshal'),
'postmaster/template/html/(?P<templateId>\d+)' => array('action' => 'postmaster/template/getHtml'),
'postmaster/template/text/(?P<templateId>\d+)' => array('action' => 'postmaster/template/getText'),
);
foreach(craft()->postmaster->getRegisteredServices() as $service)
{
$routes = array_merge($routes, $service->registerSiteRoutes());
}
foreach(craft()->postmaster->getRegisteredParcelTypes() as $service)
{
$routes = array_merge($routes, $service->registerSiteRoutes());
}
return $routes;
}
public function registerCpRoutes()
{
$routes = array(
'postmaster/parcel/new' => array('action' => 'postmaster/parcel/createParcel'),
'postmaster/parcel/(?P<parcelId>\d+)' => array('action' => 'postmaster/parcel/editParcel'),
'postmaster/parcel/delete/(?P<parcelId>\d+)' => array('action' => 'postmaster/parcel/deleteParcel'),
'postmaster/notification/new' => array('action' => 'postmaster/notification/createNotification'),
'postmaster/notification/(?P<parcelId>\d+)' => array('action' => 'postmaster/notification/editNotification'),
'postmaster/notification/delete/(?P<parcelId>\d+)' => array('action' => 'postmaster/notification/deleteNotification'),
'postmaster/data/success-fail-rate' => array('action' => 'postmaster/data/successFailRate'),
'postmaster/data/monthly-breakdown' => array('action' => 'postmaster/data/monthlyBreakdown'),
// 'postmaster/queue/marshal' => array('action' => 'postmaster/queue/marshal'),
);
foreach(craft()->postmaster->getRegisteredServices() as $service)
{
$routes = array_merge($routes, $service->registerCpRoutes());
}
foreach(craft()->postmaster->getRegisteredParcelTypes() as $service)
{
$routes = array_merge($routes, $service->registerCpRoutes());
}
return $routes;
}
public function init()
{
require_once 'autoload.php';
require_once 'vendor/autoload.php';
require_once 'bootstrap.php';
craft()->on('plugins.loadPlugins', function(Event $event)
{
craft()->postmaster->onInit(new Event());
foreach(craft()->postmaster_parcels->findEnabled() as $parcel)
{
$parcel->init();
}
foreach(craft()->postmaster_notifications->findEnabled() as $notification)
{
$notification->init();
}
});
}
}