Last active
October 18, 2023 19:31
-
-
Save cornernote/23f970210577d9c25dd906bcc5c53891 to your computer and use it in GitHub Desktop.
Revisions
-
cornernote revised this gist
Feb 16, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -32,9 +32,9 @@ Finally run `composer update` to generate the `autoload.php`. ## Usage 1. Favourite an entity (shelf, book, chapter, page) 2. Edit the entity, then save 3. An email will be sent ## Reources -
cornernote revised this gist
Feb 16, 2023 . 1 changed file with 2 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,15 +19,11 @@ Add the namespace to your `composer.json` autoload section: ```json { "autoload": { "psr-4": { "Custom\\": "themes/custom/" } } } ``` -
cornernote revised this gist
Feb 16, 2023 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ This guide will show you how to setup BookStack to send an email notification, when an entity changes, to anyone who marked the entity as a favourite. ## Installation Create the files below in your `bookstack/themes/custom/` folder. @@ -14,11 +15,38 @@ Add the theme to your `.env` file: APP_THEME=custom ``` Add the namespace to your `composer.json` autoload section: ```json { ... "autoload": { "psr-4": { .... "Custom\\": "themes/custom/" }, ... }, ... } ``` Finally run `composer update` to generate the `autoload.php`. ## Usage 1. Mark an entity (book, chapter, page) as a Favourite 2. Edit the entity, then save 3. An email should have been sent ## Reources - [Hacking BookStack](https://www.bookstackapp.com/docs/admin/hacking-bookstack/) - [BookStack theme documentation](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md) ## Thanks To This code was sponsored by [Aussie Broadband: Australia's Leading nbn™ Internet Provider](https://www.aussiebroadband.com.au/) -
cornernote revised this gist
Jan 20, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,3 +18,7 @@ APP_THEME=custom - [Hacking BookStack](https://www.bookstackapp.com/docs/admin/hacking-bookstack/) - [BookStack theme documentation](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md) ## Thanks To This code was sponsored by [Aussie Broadband: Australia's Leading nbn™ Internet Provider](https://www.aussiebroadband.com.au/) -
cornernote created this gist
Jan 20, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ <?php namespace Custom; use BookStack\Auth\User; use BookStack\Entities\Models\Entity; use BookStack\Notifications\MailNotification; use Illuminate\Notifications\Messages\MailMessage; class FavouriteNotification extends MailNotification { private string $type; private Entity $entity; public function __construct(string $type, Entity $entity) { $this->type = $type; $this->entity = $entity; } /** * Get the mail representation of the notification. */ public function toMail(User $notifiable): MailMessage { $language = setting()->getUser($notifiable, 'language'); $replace = [ 'appName' => setting('app-name'), 'entityName' => $this->entity->name, 'entityType' => class_basename($this->entity), 'changeType' => $this->type, ]; return $this->newMailMessage() ->subject(trans('custom::favourite_notification.email_subject', $replace, $language)) ->greeting(trans('custom::favourite_notification.email_greeting', $replace, $language)) ->line(trans('custom::favourite_notification.email_text', $replace, $language)) ->action(trans('custom::favourite_notification.email_action', $replace, $language), $this->entity->getUrl()); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ # BookStack Favourite Change Notification This guide will show you how to setup BookStack to send an email notification, when an entity changes, to anyone who marked the entity as a favourite. ## Installation Create the files below in your `bookstack/themes/custom/` folder. The `favourite_notification.php` must be in the folder `themes/custom/resources/lang/en/'. Add other languages as needed. Add the theme to your `.env` file: ```shell APP_THEME=custom ``` ## Reources - [Hacking BookStack](https://www.bookstackapp.com/docs/admin/hacking-bookstack/) - [BookStack theme documentation](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ <?php namespace Custom; use Custom\FavouriteNotification; use BookStack\Actions\Favourite; use BookStack\Auth\User; use BookStack\Entities\Models\Entity; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Support\Facades\Notification; class SendFavouriteNotification { use Dispatchable; private string $type; private mixed $detail; public function __construct($type, $detail) { $this->type = $type; $this->detail = $detail; } public function handle(): void { if ($this->detail instanceof Entity) { $users = $this->detail->favourites->map(function (Favourite $favourite) { return User::find($favourite->user_id); }); if ($users->count()) { Notification::send($users, new FavouriteNotification($this->type, $this->detail)); } } } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <?php /** * Favourite Alert text strings. * Is used for all the text within favourite alerts. */ return [ // Emails 'email_subject' => 'Favourite Notification for :changeType to :entityName', 'email_greeting' => ':entityName had :changeType on :appName.', 'email_text' => 'Click the button below to view the :entityType.', 'email_action' => 'View :entityType', ]; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <?php use BookStack\Facades\Theme; use BookStack\Theming\ThemeEvents; use Custom\SendFavouriteNotification; use Illuminate\Support\Facades\Lang; Theme::listen(ThemeEvents::APP_BOOT, function ($app) { Lang::addNamespace('custom', __DIR__ . '/resources/lang'); }); Theme::listen(ThemeEvents::ACTIVITY_LOGGED, function ($type, $detail) { SendFavouriteNotification::dispatch($type, $detail); });