-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hermand PESSEK
committed
May 26, 2021
0 parents
commit 7a91da8
Showing
87 changed files
with
6,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# hypeNotifications for Elgg | ||
|
||
![Elgg 3.0](https://img.shields.io/badge/Elgg-3.0-orange.svg?style=flat-square) | ||
|
||
![Popup](https://raw.github.com/hypeJunction/hypeNotifications/master/screenshots/popup.png "Popup") | ||
![Digest](https://raw.github.com/hypeJunction/hypeNotifications/master/screenshots/digest.png "Email Digest") | ||
|
||
## Features | ||
|
||
* Facebook-style site notifications | ||
* Email digest: users can specify at which interval they receive notifications for each type | ||
* A tool to update preferred notification methods for all site users | ||
* Leverages `Zend_Mail` (email library used in core) to send out HTML emails | ||
* Allows to configure email transports (Sendmail, SMTP, File Transport, SendGrid, Mailgun, SparkPost) | ||
* Allows to send file attachments | ||
* Inlines CSS styles for improved email client experience | ||
* Simpler testing experience: catch all email address, email/domain whitelist | ||
|
||
## Usage | ||
|
||
### Notification preferences | ||
|
||
Go to Admin > Administer > Utilities > Notification Methods to update personal | ||
and subscription notification preferences globally. | ||
|
||
|
||
## Developer Notes | ||
|
||
### Notification event types | ||
|
||
Notification event types can be filtered using ``'notification_events','notifications'`` hook. | ||
Users will be given an option to unsubscribe from notifications about these events or batch them into a digest. | ||
Note that some instant notification events should not be added this list, e.g. password reset and other | ||
account related notifications should remain instant. | ||
|
||
### Notification Testing | ||
|
||
You can disable outgoing email by switching to File Transport in plugin settings, | ||
this will instead write email as txt files to the filestore under `/notifications_log/zend/` | ||
|
||
### Sample SMTP config for GMail | ||
|
||
To use GMail as your SMTP relay, you will likely need to Allow less secure apps: | ||
https://support.google.com/accounts/answer/6010255?hl=en | ||
|
||
- Host: smtp.gmail.com | ||
- Port: 587 | ||
- Secure Connection: TLS | ||
- Auth: SMTP with AUTH LOGIN | ||
- Username: <your gmail email> | ||
- Password: <your gmail password> | ||
|
||
### Sample SMTP config for SendGrid | ||
|
||
- Host: smtp.sendgrid.com | ||
- Port: 587 | ||
- Secure Connection: TLS | ||
- Auth: SMTP with AUTH LOGIN | ||
- Username: apikey | ||
- Password: <your api key> | ||
|
||
|
||
### File Attachments | ||
|
||
To add attachments to your email, add an array of `ElggFile` objects to notification parameters: | ||
|
||
```php | ||
notify_user($to, $from, $subject, $body, array( | ||
'attachments' => array( | ||
$file1, $file2, | ||
) | ||
)); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
$limit = get_input('limit'); | ||
$offset = get_input('offset'); | ||
|
||
$personal_methods = (array) get_input('personal', []); | ||
$friends_methods = (array) get_input('friends', []); | ||
$groups_methods = (array) get_input('groups', []); | ||
|
||
$users = elgg_get_entities([ | ||
'types' => 'user', | ||
'limit' => $limit, | ||
'offset' => $offset, | ||
'batch' => true, | ||
]); | ||
|
||
$i = 0; | ||
|
||
foreach ($users as $user) { | ||
/* @var $user ElggUser */ | ||
|
||
foreach ($personal_methods as $method) { | ||
$user->setNotificationSetting($method, true); | ||
} | ||
|
||
if (!empty($friends_methods)) { | ||
$metaname = 'collections_notifications_preferences_' . $method; | ||
$user->$metaname = -1; // enable for new friends | ||
|
||
$friends = elgg_get_entities([ | ||
'types' => 'user', | ||
'relationship' => 'friend', | ||
'relationship_guid' => $user->guid, | ||
'limit' => 0, | ||
'callback' => false, | ||
'batch' => true, | ||
]); | ||
|
||
foreach ($friends as $friend) { | ||
foreach ($friends_methods as $method) { | ||
elgg_add_subscription($user->guid, $method, $friend->guid); | ||
} | ||
} | ||
} | ||
|
||
if (!empty($groups_methods)) { | ||
$groups = elgg_get_entities([ | ||
'types' => 'group', | ||
'relationship' => 'member', | ||
'relationship_guid' => $user->guid, | ||
'inverse_relationship' => true, | ||
'limit' => 0, | ||
'callback' => false, | ||
'batch' => true, | ||
]); | ||
|
||
foreach ($groups as $group) { | ||
foreach ($groups_methods as $method) { | ||
elgg_add_subscription($user->guid, $method, $group->guid); | ||
} | ||
} | ||
} | ||
|
||
$i++; | ||
} | ||
|
||
return elgg_ok_response(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
$user = elgg_get_logged_in_user_entity(); | ||
$site = elgg_get_site_entity(); | ||
|
||
$recipient = get_input('recipient'); | ||
$subject = get_input('subject'); | ||
$body = get_input('body', '', false); | ||
|
||
$attachments = []; | ||
$uploads = elgg_get_uploaded_files('attachments'); | ||
if (!empty($uploads)) { | ||
foreach ($uploads as $upload) { | ||
if ($upload && $upload->isValid()) { | ||
$file = new ElggFile(); | ||
$file->owner_guid = $user->guid; | ||
$file->access_id = ACCESS_PRIVATE; | ||
$file->acceptUploadedFile($upload); | ||
$attachments[] = $file; | ||
} | ||
} | ||
} | ||
|
||
$result = elgg_send_email(null, $recipient, $subject, $body, array( | ||
'attachments' => $attachments, | ||
), 'email'); | ||
|
||
foreach ($attachments as $attachment) { | ||
$attachment->delete(); | ||
} | ||
|
||
if ($result) { | ||
return elgg_ok_response('', elgg_echo('admin:notifications:test_email:success')); | ||
} else { | ||
return elgg_error_response(elgg_echo('admin:notifications:test_email:error')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Saves global plugin settings. | ||
* | ||
* This action can be overriden for a specific plugin by creating the | ||
* <plugin_id>/settings/save action in that plugin. | ||
* | ||
* @uses array $_REQUEST['params'] A set of key/value pairs to save to the ElggPlugin entity | ||
* @uses int $_REQUEST['plugin_id'] The ID of the plugin | ||
*/ | ||
|
||
$params = get_input('params'); | ||
$plugin_id = get_input('plugin_id'); | ||
$plugin = elgg_get_plugin_from_id($plugin_id); | ||
|
||
if (!$plugin) { | ||
return elgg_error_response(elgg_echo('plugins:settings:save:fail', [$plugin_id])); | ||
} | ||
|
||
$plugin_name = $plugin->getDisplayName(); | ||
|
||
$result = false; | ||
|
||
$config = [ | ||
'transport', | ||
'smtp_host_name', | ||
'smtp_host', | ||
'smtp_port', | ||
'smtp_connection', | ||
'smtp_username', | ||
'smtp_password', | ||
'smtp_ssl', | ||
'sparkpost_apikey', | ||
'sendgrid_apikey', | ||
'mailgun_apikey', | ||
'mailgun_domain', | ||
]; | ||
|
||
foreach ($params as $k => $v) { | ||
if (in_array($k, $config)) { | ||
elgg_save_config("email.$k", $v); | ||
} else { | ||
$result = $plugin->setSetting($k, $v); | ||
if (!$result) { | ||
return elgg_error_response(elgg_echo('plugins:settings:save:fail', [$plugin_name])); | ||
} | ||
} | ||
} | ||
|
||
return elgg_ok_response('', elgg_echo('plugins:settings:save:ok', [$plugin_name])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
$guid = get_input('guid'); | ||
$user = get_entity($guid); | ||
|
||
if (!$user || !$user->canEdit()) { | ||
return elgg_error_response(elgg_echo('actionunauthorized')); | ||
} | ||
|
||
hypeapps_mark_all_notifications_read($user->guid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
$id = get_input('id'); | ||
$notification = hypeapps_get_notification_by_id($id); | ||
|
||
if (!$notification) { | ||
return elgg_error_response(); | ||
} | ||
|
||
$recipient = $notification->getRecipient(); | ||
if (!$recipient || !$recipient->canEdit()) { | ||
return elgg_error_response(); | ||
} | ||
|
||
if (!$notification->isSeen()) { | ||
$notification->markAsSeen(); | ||
} | ||
|
||
if (!$notification->isRead()) { | ||
$notification->markAsRead(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
$guid = get_input('guid'); | ||
$user = get_entity($guid); | ||
|
||
if (!$user instanceof ElggUser || !$user->canEdit()) { | ||
return elgg_error_response(elgg_echo('actionunauthorized')); | ||
} | ||
|
||
$params = get_input('params'); | ||
|
||
foreach ($params as $key => $value) { | ||
elgg_set_plugin_user_setting($key, $value, $user->guid, 'hypeNotifications'); | ||
} | ||
|
||
elgg_ok_response('', elgg_echo('notifications:settings:digest:success')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
$plugin_root = __DIR__; | ||
if (file_exists("{$plugin_root}/vendor/autoload.php")) { | ||
// check if composer dependencies are distributed with the plugin | ||
require_once "{$plugin_root}/vendor/autoload.php"; | ||
} | ||
|
||
require_once __DIR__ . '/lib/functions.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace hypeJunction\Notifications; | ||
|
||
use Elgg\Hook; | ||
use Zend\Mail\Message; | ||
use Zend\Mime\Mime; | ||
use Zend\Mime\Part; | ||
|
||
class AddHtmlEmailPart { | ||
|
||
/** | ||
* Add HTML email part | ||
* | ||
* @param Hook $hook Hook | ||
* @return Message | ||
*/ | ||
public function __invoke(Hook $hook) { | ||
|
||
$message = $hook->getValue(); | ||
/* @var $message Message */ | ||
|
||
if (elgg_get_plugin_setting('enable_html_emails', 'hypeNotifications') == "yes") { | ||
|
||
$html_body = elgg_view('notifications/wrapper/html', [ | ||
'email' => $hook->getParam('email'), | ||
]); | ||
|
||
if ($html_body) { | ||
$html_part = new Part($html_body); | ||
$html_part->setCharset('UTF-8'); | ||
$html_part->setType(Mime::TYPE_HTML); | ||
|
||
$message->getBody()->addPart($html_part); | ||
} | ||
} | ||
|
||
return $message; | ||
|
||
} | ||
} |
Oops, something went wrong.