-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessMillcoPush.module.php
More file actions
93 lines (66 loc) · 1.76 KB
/
ProcessMillcoPush.module.php
File metadata and controls
93 lines (66 loc) · 1.76 KB
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
<?php
namespace ProcessWire;
/**
* ProcessMillcoPush
*
* Admin page for tesing MilloPush
*/
class ProcessMillcoPush extends Process implements Module
{
public $public_key;
public $private_key;
public static function getModuleInfo()
{
return [
'title' => 'Millco Push Admin',
'summary' => 'Process to manage Millco Push',
'version' => 1,
'icon' => 'arrow-right',
'page' => [
'name' => 'mpush',
'parent' => 'setup',
'title' => 'Push notifications',
'permission' => 'millco-push-manage',
],
'autoload' => false,
'singular' => false,
'permanent' => false,
'requires' => [
'PHP>=8.0.0',
'ProcessWire>=3.0.0',
'MillcoPush',
]
];
}
public function init()
{
parent::init();
// get our config field values
$this->public_key = $this->get('public_key');
}
public function __construct()
{
}
public function ___execute()
{
$admin_page_markup='';
// get the main module so we can use some handy functions.
/** @var MillcoPush $mp */
$mp = $this->modules->get('MillcoPush');
if(wire('input')->post('mps_user') && wire('input')->post('mps_content')){
$recipient_id=wire('input')->post('mps_user');
$message=wire('input')->post('mps_content');
// Sanitize to a single line with no tags.
$message=wire('sanitizer')->line($message);
$success=$mp->notify_user($recipient_id, $message);
if($success){
$this->message("Notification sent to {$success} subscribers");
}else{
$this->error("No notification sent for this user.");
}
}
// render our form. We pass the mp module to it.
$admin_page_markup.= wire('files')->render(wire('config')->paths->siteModules . 'MillcoPush/markup/send_notification_form.php', ['mp'=>$mp]);
return $admin_page_markup;
}
}