Yoshi2889 /
SMF2.1
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This taks handles notifying someone that a new event has been |
||
| 5 | * added to the calendar - but only when no topic has been created. |
||
| 6 | * |
||
| 7 | * Simple Machines Forum (SMF) |
||
| 8 | * |
||
| 9 | * @package SMF |
||
| 10 | * @author Simple Machines http://www.simplemachines.org |
||
| 11 | * @copyright 2017 Simple Machines and individual contributors |
||
| 12 | * @license http://www.simplemachines.org/about/smf/license.php BSD |
||
| 13 | * |
||
| 14 | * @version 2.1 Beta 4 |
||
| 15 | */ |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Class EventNew_Notify_Background |
||
| 19 | */ |
||
| 20 | class EventNew_Notify_Background extends SMF_BackgroundTask |
||
|
0 ignored issues
–
show
|
|||
| 21 | { |
||
| 22 | /** |
||
| 23 | * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
||
| 24 | * @return bool Always returns true |
||
|
0 ignored issues
–
show
|
|||
| 25 | */ |
||
| 26 | public function execute() |
||
| 27 | { |
||
| 28 | global $sourcedir, $smcFunc, $user_profile; |
||
| 29 | |||
| 30 | // Get everyone who could be notified - those are the people who can see the calendar. |
||
| 31 | require_once($sourcedir . '/Subs-Members.php'); |
||
| 32 | $members = membersAllowedTo('calendar_view'); |
||
| 33 | |||
| 34 | // Don't alert the event creator |
||
| 35 | if (!empty($this->_details['sender_id'])) |
||
| 36 | $members = array_diff($members, array($this->_details['sender_id'])); |
||
| 37 | |||
| 38 | // Having successfully figured this out, now let's get the preferences of everyone. |
||
| 39 | require_once($sourcedir . '/Subs-Notify.php'); |
||
| 40 | $prefs = getNotifyPrefs($members, 'event_new', true); |
||
| 41 | |||
| 42 | // Just before we go any further, we may not have the sender's name. Let's just quickly fix that. |
||
| 43 | // If a guest creates the event, we wouldn't be capturing a username or anything. |
||
| 44 | if (!empty($this->_details['sender_id']) && empty($this->_details['sender_name'])) |
||
| 45 | { |
||
| 46 | loadMemberData($this->_details['sender_id'], 'minimal'); |
||
| 47 | if (!empty($user_profile[$this->_details['sender_id']])) |
||
| 48 | $this->_details['sender_name'] = $user_profile[$this->_details['sender_id']]['real_name']; |
||
| 49 | else |
||
| 50 | $this->_details['sender_id'] = 0; |
||
| 51 | } |
||
| 52 | |||
| 53 | // So now we find out who wants what. |
||
| 54 | $alert_bits = array( |
||
| 55 | 'alert' => 0x01, |
||
| 56 | 'email' => 0x02, |
||
| 57 | ); |
||
| 58 | $notifies = array(); |
||
| 59 | |||
| 60 | View Code Duplication | foreach ($prefs as $member => $pref_option) |
|
| 61 | { |
||
| 62 | foreach ($alert_bits as $type => $bitvalue) |
||
| 63 | if ($pref_option['event_new'] & $bitvalue) |
||
| 64 | $notifies[$type][] = $member; |
||
| 65 | } |
||
| 66 | |||
| 67 | // Firstly, anyone who wants alerts. |
||
| 68 | if (!empty($notifies['alert'])) |
||
| 69 | { |
||
| 70 | // Alerts are relatively easy. |
||
| 71 | $insert_rows = array(); |
||
| 72 | foreach ($notifies['alert'] as $member) |
||
| 73 | { |
||
| 74 | $insert_rows[] = array( |
||
| 75 | 'alert_time' => $this->_details['time'], |
||
| 76 | 'id_member' => $member, |
||
| 77 | 'id_member_started' => $this->_details['sender_id'], |
||
| 78 | 'member_name' => $this->_details['sender_name'], |
||
| 79 | 'content_type' => 'event', |
||
| 80 | 'content_id' => $this->_details['event_id'], |
||
| 81 | 'content_action' => empty($this->_details['sender_id']) ? 'new_guest' : 'new', |
||
| 82 | 'is_read' => 0, |
||
| 83 | 'extra' => $smcFunc['json_encode']( |
||
| 84 | array( |
||
| 85 | "event_id" => $this->_details['event_id'], |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
event_id does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 86 | "event_title" => $this->_details['event_title'] |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
event_title does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 87 | ) |
||
| 88 | ), |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | |||
| 92 | $smcFunc['db_insert']('insert', |
||
| 93 | '{db_prefix}user_alerts', |
||
| 94 | array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', |
||
| 95 | 'member_name' => 'string', 'content_type' => 'string', 'content_id' => 'int', |
||
| 96 | 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'), |
||
| 97 | $insert_rows, |
||
| 98 | array('id_alert') |
||
| 99 | ); |
||
| 100 | |||
| 101 | // And update the count of alerts for those people. |
||
| 102 | updateMemberData($notifies['alert'], array('alerts' => '+')); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | ?> |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider.