|
5 | 5 | * PLUGIN INFORMATION BEGIN
|
6 | 6 | * Plugin Name: Notifications.
|
7 | 7 | * 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 |
10 | 10 | * Min. Compatible: 0.10.0
|
11 | 11 | * 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 |
14 | 14 | * PLUGIN INFORMATION END
|
15 | 15 | *
|
16 | 16 | * Receive email notifications from phpMussel whenever a file upload is
|
17 | 17 | * blocked. Requires PHP "mail" function to be correctly configured; for more
|
18 | 18 | * information, please refer to "http://php.net/manual/en/function.mail.php".
|
19 |
| - * |
20 |
| - * @package Maikuolan/phpMussel-plugin-notifications |
21 | 19 | */
|
22 | 20 |
|
23 | 21 | /**
|
|
28 | 26 | die('[phpMussel] This should not be accessed directly.');
|
29 | 27 | }
|
30 | 28 |
|
31 |
| -/** |
32 |
| - * Registers the `phpMussel_Notify()` function to the `before_html_out` hook. |
33 |
| - */ |
34 |
| -phpMussel_Register_Hook('phpMussel_Notify', 'before_html_out'); |
35 |
| - |
36 | 29 | /** Fallback for missing "notifications" configuration category. */
|
37 | 30 | if (!isset($phpMussel['MusselConfig']['notifications'])) {
|
38 | 31 | $phpMussel['MusselConfig']['notifications'] = array();
|
|
47 | 40 | }
|
48 | 41 |
|
49 | 42 | /**
|
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). |
57 | 46 | */
|
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; |
66 | 89 | }
|
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 | + |
87 | 132 | }
|
0 commit comments