notification.plugin.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function notification_menu(){
  4. global $_,$myUser;
  5. if(!$myUser->can('notification','read')) return;
  6. ?>
  7. <div class="dropdown notification_menu ml-auto">
  8. <button class="btn btn-dark dropdown-toggle" type="button" id="dropdownNotification" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  9. <span class="badge badge-pill badge-danger notification-number">-</span>
  10. <i class="fas fa-bell"></i>
  11. </button>
  12. <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownNotification"></div>
  13. </div>
  14. <div class="notification-template">
  15. <div data-id="{{id}}" class="dropdown-item notification-{{class}} notification-item" onclick="notification_user_notification_toggle_read(this,event,'.dropdown-item'); window.location='{{link}}';">
  16. <ul class="notification-item-options">
  17. <li onclick="notification_user_notification_toggle_read(this,event,'.dropdown-item')" title="Marquer comme lu" class="notification-read"><i class="fas fa-eye"></i></li>
  18. <li onclick="notification_user_notification_delete(this,event,'.dropdown-item')" title="Supprimer la notification" class="notification-delete"><i class="fas fa-times"></i></li>
  19. </ul>
  20. <small>{{created-relative}}</small>
  21. <strong>{{label}}</strong>
  22. <p>{{{html}}}</p>
  23. </div>
  24. <div class="dropdown-divider" data-notification="{{id}}"></div>
  25. </div>
  26. <?php
  27. }
  28. //Cette fonction va generer une page quand on clique sur notification dans menu
  29. function notification_page(){
  30. global $_,$myUser;
  31. if(!isset($_['module']) || $_['module'] !='notification') return;
  32. $page = !isset($_['page']) ? 'list' : $_['page'];
  33. $file = __DIR__.SLASH.'page.'.$page.'.php';
  34. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  35. require_once($file);
  36. }
  37. //Fonction executée lors de l'activation du plugin
  38. function notification_install($id){
  39. if($id != 'fr.idleman.notification') return;
  40. Entity::install(__DIR__);
  41. global $myUser,$_;
  42. require_once(__DIR__.SLASH.'UserNotification.class.php');
  43. require_once(__DIR__.SLASH.'Notification.class.php');
  44. $recipients = array();
  45. foreach (User::getAll() as $user) {
  46. $recipients[] = $user->login;
  47. }
  48. Notification::emit(
  49. array(
  50. 'label' => "Nouvelle fonctionnalité de notification !",
  51. 'html' => "Une nouvelle <strong>Notification</strong>
  52. à été ajoutée à votre espace.<br/> Vous pouvez consulter toutes vos notifications <a href='".ROOT_URL."/index.php?module=notification'>ici</a> et configurer vos <a href='".ROOT_URL."/account.php?section=notification'>préférences la.</a>",
  53. 'meta' => array(
  54. 'link' => ROOT_URL.'/index.php?module=notification',
  55. )
  56. ),$recipients
  57. );
  58. }
  59. //Fonction executée lors de la désactivation du plugin
  60. function notification_uninstall($id){
  61. if($id != 'fr.idleman.notification') return;
  62. Entity::uninstall(__DIR__);
  63. }
  64. //Déclaration des sections de droits du plugin
  65. function notification_section(&$sections){
  66. $sections['notification'] = "Gestion des droits sur le plugin notification";
  67. }
  68. //Cette fonction comprends toutes les actions
  69. //du plugin qui ne nécessitent pas de vue html
  70. function notification_action(){
  71. require_once(__DIR__.SLASH.'action.php');
  72. }
  73. //Déclaration du menu de réglages
  74. function notification_menu_setting(&$settingMenu){
  75. global $_, $myUser;
  76. if(!$myUser->can('notification','configure')) return;
  77. $settingMenu[]= array(
  78. 'sort' =>1,
  79. 'url' => 'setting.php?section=notification',
  80. 'icon' => 'fas fa-angle-right',
  81. 'label' => 'Notifications'
  82. );
  83. }
  84. function notification_menu_account(&$accountMenu){
  85. global $_, $myUser;
  86. if(!$myUser->connected() || !$myUser->can('notification', 'read')) return;
  87. $accountMenu[]= array(
  88. 'sort' =>0,
  89. 'url' => 'account.php?section=notification',
  90. 'icon' => 'fas fa-angle-right',
  91. 'label' => 'Notifications',
  92. );
  93. }
  94. //Déclaration des pages de réglages
  95. function notification_content_setting(){
  96. global $_;
  97. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  98. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  99. }
  100. //Déclaration des pages de réglages
  101. function notification_content_account(){
  102. global $_;
  103. if(file_exists(__DIR__.SLASH.'account.'.$_['section'].'.php'))
  104. require_once(__DIR__.SLASH.'account.'.$_['section'].'.php');
  105. }
  106. //Émission d'une notification
  107. function notification_emit_notification($params, $recipients){
  108. require_once(__DIR__.SLASH.'Notification.class.php');
  109. Notification::emit($params,$recipients);
  110. }
  111. //Déclation des assets
  112. Plugin::addCss("/css/main.css?v=1");
  113. Plugin::addJs("/js/main.js?v=1");
  114. //Mapping hook / fonctions
  115. Plugin::addHook("install", "notification_install");
  116. Plugin::addHook("uninstall", "notification_uninstall");
  117. Plugin::addHook("section", "notification_section");
  118. Plugin::addHook("login_header", "notification_menu");
  119. Plugin::addHook("page", "notification_page");
  120. Plugin::addHook("action", "notification_action");
  121. Plugin::addHook("menu_account", "notification_menu_account");
  122. Plugin::addHook("content_account", "notification_content_account");
  123. Plugin::addHook("menu_setting", "notification_menu_setting");
  124. Plugin::addHook("content_setting", "notification_content_setting");
  125. Plugin::addHook("emit_notification", "notification_emit_notification");
  126. ?>