Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit 02a22b6

Browse files
committed
Patch.
Updating links and reference information + Improving compatibility (can now be used with both pre-v1 and post-v1 code).
1 parent edb30fc commit 02a22b6

File tree

2 files changed

+95
-50
lines changed

2 files changed

+95
-50
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ An ideal solution for shared hosting environments, where it's often not possible
66

77
## **What's this repository for?**
88

9-
This repository, "phpMussel-plugin-notifications", is the repository for a phpMussel plugin that allows you to receive email notifications from phpMussel whenever a file upload is blocked (requires PHP "mail" function to be correctly configured).
9+
This repository, "plugin-notifications", is the repository for a phpMussel plugin that allows you to receive email notifications from phpMussel whenever a file upload is blocked (requires PHP "mail" function to be correctly configured).
1010

11-
The main repository: [phpMussel](https://github.com/Maikuolan/phpMussel).
11+
The core phpMussel repository: [phpMussel](https://github.com/Maikuolan/phpMussel).
1212

13-
This repository: [phpMussel-plugin-notifications](https://github.com/phpMussel/phpMussel-plugin-notifications).
13+
This repository: [plugin-notifications](https://github.com/phpMussel/plugin-notifications).
1414

1515
---
1616

@@ -32,4 +32,4 @@ That's everything! :-)
3232

3333
---
3434

35-
*This file, "README.md", last edited: 15th November 2015 (2015.11.15).*
35+
*This file, "README.md", last edited: 29th May 2016 (2016.05.29).*

notifications/plugin.php

Lines changed: 91 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
* PLUGIN INFORMATION BEGIN
66
* Plugin Name: Notifications.
77
* Plugin Author: Caleb M / Maikuolan.
8-
* Plugin Version: 1.0.2
9-
* Download Address: https://github.com/Maikuolan/phpMussel-plugin-notifications
8+
* Plugin Version: 1.0.3
9+
* Download Address: https://github.com/phpMussel/plugin-notifications
1010
* Min. Compatible: 0.10.0
1111
* Max. Compatible: -
12-
* Tested up to: 0.10.0
13-
* Last Modified: 2016.02.09
12+
* Tested up to: 1.0.0-DEV
13+
* Last Modified: 2016.05.29
1414
* PLUGIN INFORMATION END
1515
*
1616
* Receive email notifications from phpMussel whenever a file upload is
1717
* blocked. Requires PHP "mail" function to be correctly configured; for more
1818
* information, please refer to "http://php.net/manual/en/function.mail.php".
19-
*
20-
* @package Maikuolan/phpMussel-plugin-notifications
2119
*/
2220

2321
/**
@@ -28,11 +26,6 @@
2826
die('[phpMussel] This should not be accessed directly.');
2927
}
3028

31-
/**
32-
* Registers the `phpMussel_Notify()` function to the `before_html_out` hook.
33-
*/
34-
phpMussel_Register_Hook('phpMussel_Notify', 'before_html_out');
35-
3629
/** Fallback for missing "notifications" configuration category. */
3730
if (!isset($phpMussel['MusselConfig']['notifications'])) {
3831
$phpMussel['MusselConfig']['notifications'] = array();
@@ -47,41 +40,93 @@
4740
}
4841

4942
/**
50-
* The actual plugin code (the "Notifications" plugin only has one small
51-
* function; nothing else is needed).
52-
*
53-
* @param array $input An empty array (we don't need to send anything from the
54-
* calling scope to the function, but, the plugin system nonetheless
55-
* requires this parameter to exist).
56-
* @return bool Returns true if everything is working correctly.
43+
* Determine whether to use functions or closures (based upon whether we're
44+
* pre-v1 or post-v1, which can be determined by the presense of certain
45+
* functions).
5746
*/
58-
function phpMussel_Notify($input) {
59-
global $phpMussel;
60-
if (
61-
!$phpMussel['MusselConfig']['notifications']['to_addr'] ||
62-
!$phpMussel['MusselConfig']['notifications']['from_addr'] ||
63-
empty($phpMussel['whyflagged'])
64-
) {
65-
return false;
47+
if (function_exists('phpMussel_Register_Hook')) {
48+
/** Pre-v1 code (considered deprecated and will eventually remove). */
49+
50+
/**
51+
* Registers the `phpMussel_Notify()` function to the `before_html_out` hook.
52+
*/
53+
phpMussel_Register_Hook('phpMussel_Notify', 'before_html_out');
54+
55+
/**
56+
* The pre-v1 plugin code.
57+
*
58+
* @param array $input An empty array (we don't need to send anything from the
59+
* calling scope to the function, but, the plugin system nonetheless
60+
* requires this parameter to exist).
61+
* @return bool Returns true if everything is working correctly.
62+
*/
63+
function phpMussel_Notify($input) {
64+
global $phpMussel;
65+
if (
66+
empty($phpMussel['MusselConfig']['notifications']['to_addr']) ||
67+
empty($phpMussel['MusselConfig']['notifications']['from_addr']) ||
68+
empty($phpMussel['whyflagged'])
69+
) {
70+
return false;
71+
}
72+
$NotifyLang =
73+
(!file_exists($phpMussel['vault'] . 'plugins/notifications/template.' . $phpMussel['MusselConfig']['general']['lang'] . '.eml')) ?
74+
'en' :
75+
$phpMussel['MusselConfig']['general']['lang'];
76+
$content = phpMusselV(array(
77+
'whyflagged' => $phpMussel['whyflagged'],
78+
'ipaddr' => $_SERVER[$phpMussel['MusselConfig']['general']['ipaddr']],
79+
'time' => date('r')
80+
), phpMusselFile($phpMussel['vault'] . 'plugins/notifications/template.' . $NotifyLang . '.eml', 0, true));
81+
mail(
82+
$phpMussel['MusselConfig']['notifications']['to_addr'],
83+
$phpMussel['MusselConfig']['lang']['denied'],
84+
$content,
85+
"MIME-Version: 1.0\nContent-type: text/plain; charset=iso-8859-1\nFrom: " . $phpMussel['MusselConfig']['notifications']['from_addr'],
86+
'-f' . $phpMussel['MusselConfig']['notifications']['from_addr']
87+
);
88+
return true;
6689
}
67-
$NotifyLang =
68-
(!file_exists($phpMussel['vault'] . 'plugins/notifications/template.' . $phpMussel['MusselConfig']['general']['lang'] . '.eml')) ?
69-
'en' :
70-
$phpMussel['MusselConfig']['general']['lang'];
71-
$NotifyVars = array();
72-
$NotifyVars['whyflagged'] = $phpMussel['whyflagged'];
73-
$NotifyVars['ipaddr'] = $_SERVER[$phpMussel['MusselConfig']['general']['ipaddr']];
74-
$NotifyVars['time'] = date('r');
75-
$content = phpMusselV(
76-
$NotifyVars,
77-
phpMusselFile($phpMussel['vault'] . 'plugins/notifications/template.' . $NotifyLang . '.eml', 0, true)
78-
);
79-
mail(
80-
$phpMussel['MusselConfig']['notifications']['to_addr'],
81-
$phpMussel['MusselConfig']['lang']['denied'],
82-
$content,
83-
"MIME-Version: 1.0\nContent-type: text/plain; charset=iso-8859-1\nFrom: " . $phpMussel['MusselConfig']['notifications']['from_addr'],
84-
'-f' . $phpMussel['MusselConfig']['notifications']['from_addr']
85-
);
86-
return true;
90+
91+
} else {
92+
/** Post-v1 code. */
93+
94+
/**
95+
* Registers the `$phpMussel_Notifications` closure to the `before_html_out`
96+
* hook.
97+
*/
98+
$phpMussel['Register_Hook']('phpMussel_Notifications', 'before_html_out');
99+
100+
/**
101+
* The post-v1 plugin code.
102+
*
103+
* @return bool Returns true if everything is working correctly.
104+
*/
105+
$phpMussel_Notifications = function () use (&$phpMussel) {
106+
if (
107+
empty($phpMussel['MusselConfig']['notifications']['to_addr']) ||
108+
empty($phpMussel['MusselConfig']['notifications']['from_addr']) ||
109+
empty($phpMussel['whyflagged'])
110+
) {
111+
return false;
112+
}
113+
$NotifyLang =
114+
(!file_exists($phpMussel['vault'] . 'plugins/notifications/template.' . $phpMussel['MusselConfig']['general']['lang'] . '.eml')) ?
115+
'en' :
116+
$phpMussel['MusselConfig']['general']['lang'];
117+
$content = $phpMussel['ParseVars'](array(
118+
'whyflagged' => $phpMussel['whyflagged'],
119+
'ipaddr' => $_SERVER[$phpMussel['MusselConfig']['general']['ipaddr']],
120+
'time' => date('r')
121+
), $phpMussel['ReadFile']($phpMussel['vault'] . 'plugins/notifications/template.' . $NotifyLang . '.eml', 0, true));
122+
mail(
123+
$phpMussel['MusselConfig']['notifications']['to_addr'],
124+
$phpMussel['MusselConfig']['lang']['denied'],
125+
$content,
126+
"MIME-Version: 1.0\nContent-type: text/plain; charset=iso-8859-1\nFrom: " . $phpMussel['MusselConfig']['notifications']['from_addr'],
127+
'-f' . $phpMussel['MusselConfig']['notifications']['from_addr']
128+
);
129+
return true;
130+
};
131+
87132
}

0 commit comments

Comments
 (0)