-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNewsletterPlugin.php
More file actions
87 lines (76 loc) · 2.38 KB
/
Copy pathNewsletterPlugin.php
File metadata and controls
87 lines (76 loc) · 2.38 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
<?php
/**
* @file plugins/generic/newsletter/NewsletterPlugin.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class NewsletterPlugin
* @brief Newsletter subscription plugin main class
*/
namespace APP\plugins\generic\newsletter;
use APP\core\Application;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use PKP\config\Config;
class NewsletterPlugin extends GenericPlugin
{
/**
* @copydoc Plugin::register()
*/
public function register($category, $path, $mainContextId = null)
{
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled($mainContextId)) {
Hook::add('LoadHandler', [$this, 'callbackHandleContent']);
Hook::add('TemplateManager::display', [$this, 'assignRecaptchaKey']);
}
return true;
}
return false;
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName()
{
return 'Newsletter Subscription';
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription()
{
return 'Enables newsletter subscription by registering users as Readers in OMP.';
}
/**
* Assign reCAPTCHA public key to all frontend templates so newsletter forms can render the widget
*/
public function assignRecaptchaKey($hookName, $args)
{
$templateMgr = $args[0];
if (Config::getVar('captcha', 'recaptcha') && Config::getVar('captcha', 'recaptcha_public_key')) {
$templateMgr->assign('recaptchaPublicKey', Config::getVar('captcha', 'recaptcha_public_key'));
}
return false;
}
/**
* Declare the handler function to process the newsletter/subscribe path
*/
public function callbackHandleContent($hookName, $args)
{
$page = &$args[0];
$op = &$args[1];
$handler = &$args[3];
if ($page === 'newsletter' && $op === 'subscribe') {
require_once($this->getPluginPath() . '/NewsletterHandler.php');
$handler = new NewsletterHandler($this);
return true;
}
return false;
}
}
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\newsletter\NewsletterPlugin', '\NewsletterPlugin');
}