Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

email.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 4.79 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\notification\method;
015   
016  use phpbb\notification\type\type_interface;
017   
018  /**
019  * Email notification method class
020  * This class handles sending emails for notifications
021  */
022   
023  class email extends \phpbb\notification\method\messenger_base
024  {
025      /** @var \phpbb\user */
026      protected $user;
027   
028      /** @var \phpbb\config\config */
029      protected $config;
030   
031      /** @var \phpbb\db\driver\driver_interface */
032      protected $db;
033   
034      /** @var string Notification emails table */
035      protected $notification_emails_table;
036   
037      /**
038       * Notification Method email Constructor
039       *
040       * @param \phpbb\user_loader $user_loader
041       * @param \phpbb\user $user
042       * @param \phpbb\config\config $config
043       * @param \phpbb\db\driver\driver_interface $db
044       * @param string $phpbb_root_path
045       * @param string $php_ext
046       * @param string $notification_emails_table
047       */
048      public function __construct(\phpbb\user_loader $user_loader, \phpbb\user $user, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext, $notification_emails_table)
049      {
050          parent::__construct($user_loader, $phpbb_root_path, $php_ext);
051   
052          $this->user = $user;
053          $this->config = $config;
054          $this->db = $db;
055          $this->notification_emails_table = $notification_emails_table;
056      }
057   
058      /**
059      * Get notification method name
060      *
061      * @return string
062      */
063      public function get_type()
064      {
065          return 'notification.method.email';
066      }
067   
068      /**
069      * Is this method available for the user?
070      * This is checked on the notifications options
071      *
072      * @param type_interface $notification_type  An optional instance of a notification type. If provided, this
073      *                                            method additionally checks if the type provides an email template.
074      * @return bool
075      */
076      public function is_available(type_interface $notification_type = null)
077      {
078          return parent::is_available($notification_type) && $this->config['email_enable'] && !empty($this->user->data['user_email']);
079      }
080   
081      /**
082      * {@inheritdoc}
083      */
084      public function get_notified_users($notification_type_id, array $options)
085      {
086          $notified_users = [];
087   
088          $sql = 'SELECT user_id
089              FROM ' . $this->notification_emails_table . '
090              WHERE notification_type_id = ' . (int) $notification_type_id .
091              (isset($options['item_id']) ? ' AND item_id = ' . (int) $options['item_id'] : '') .
092              (isset($options['item_parent_id']) ? ' AND item_parent_id = ' . (int) $options['item_parent_id'] : '') .
093              (isset($options['user_id']) ? ' AND user_id = ' . (int) $options['user_id'] : '');
094          $result = $this->db->sql_query($sql);
095          while ($row = $this->db->sql_fetchrow($result))
096          {
097              $notified_users[$row['user_id']] = $row;
098          }
099          $this->db->sql_freeresult($result);
100   
101          return $notified_users;
102      }
103   
104      /**
105      * Parse the queue and notify the users
106      */
107      public function notify()
108      {
109          $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->notification_emails_table);
110   
111          /** @var type_interface $notification */
112          foreach ($this->queue as $notification)
113          {
114              $data = self::clean_data($notification->get_insert_array());
115              $insert_buffer->insert($data);
116          }
117   
118          $insert_buffer->flush();
119   
120          return $this->notify_using_messenger(NOTIFY_EMAIL);
121      }
122   
123      /**
124      * {@inheritdoc}
125      */
126      public function mark_notifications($notification_type_id, $item_id, $user_id, $time = false, $mark_read = true)
127      {
128          $sql = 'DELETE FROM ' . $this->notification_emails_table . '
129              WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : '1=1') .
130              ($user_id !== false ? ' AND ' . $this->db->sql_in_set('user_id', $user_id) : '') .
131              ($item_id !== false ? ' AND ' . $this->db->sql_in_set('item_id', $item_id) : '');
132          $this->db->sql_query($sql);
133      }
134   
135      /**
136      * {@inheritdoc}
137      */
138      public function mark_notifications_by_parent($notification_type_id, $item_parent_id, $user_id, $time = false, $mark_read = true)
139      {
140          $sql = 'DELETE FROM ' . $this->notification_emails_table . '
141              WHERE ' . ($notification_type_id !== false ? $this->db->sql_in_set('notification_type_id', $notification_type_id) : '1=1') .
142              ($user_id !== false ? ' AND ' . $this->db->sql_in_set('user_id', $user_id) : '') .
143              ($item_parent_id !== false ? ' AND ' . $this->db->sql_in_set('item_parent_id', $item_parent_id, false, true) : '');
144          $this->db->sql_query($sql);
145      }
146   
147      /**
148       * Clean data to contain only what we need for email notifications table
149       *
150       * @param array $data Notification data
151       * @return array Cleaned notification data
152       */
153      static public function clean_data(array $data)
154      {
155          $row = [
156              'notification_type_id'    => null,
157              'item_id'                => null,
158              'item_parent_id'        => null,
159              'user_id'                => null,
160          ];
161   
162          return array_intersect_key($data, $row);
163      }
164  }
165