Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

quote.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 4.65 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\type;
 015   
 016  /**
 017  * Post quoting notifications class
 018  * This class handles notifying users when they have been quoted in a post
 019  */
 020   
 021  class quote extends \phpbb\notification\type\post
 022  {
 023      /**
 024      * Get notification type name
 025      *
 026      * @return string
 027      */
 028      public function get_type()
 029      {
 030          return 'notification.type.quote';
 031      }
 032   
 033      /**
 034      * regular expression to match to find usernames
 035      *
 036      * @var string
 037      */
 038      protected static $regular_expression_match = '#\[quote=&quot;(.+?)&quot;#';
 039   
 040      /**
 041      * Language key used to output the text
 042      *
 043      * @var string
 044      */
 045      protected $language_key = 'NOTIFICATION_QUOTE';
 046   
 047      /**
 048      * Notification option data (for outputting to the user)
 049      *
 050      * @var bool|array False if the service should use it's default data
 051      *                     Array of data (including keys 'id', 'lang', and 'group')
 052      */
 053      public static $notification_option = array(
 054          'lang'    => 'NOTIFICATION_TYPE_QUOTE',
 055          'group'    => 'NOTIFICATION_GROUP_POSTING',
 056      );
 057   
 058      /**
 059      * Is available
 060      */
 061      public function is_available()
 062      {
 063          return true;
 064      }
 065   
 066      /**
 067      * Find the users who want to receive notifications
 068      *
 069      * @param array $post Data from submit_post
 070      * @param array $options Options for finding users for notification
 071      *
 072      * @return array
 073      */
 074      public function find_users_for_notification($post, $options = array())
 075      {
 076          $options = array_merge(array(
 077              'ignore_users'        => array(),
 078          ), $options);
 079   
 080          $usernames = false;
 081          preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames);
 082   
 083          if (empty($usernames[1]))
 084          {
 085              return array();
 086          }
 087   
 088          $usernames[1] = array_unique($usernames[1]);
 089   
 090          $usernames = array_map('utf8_clean_string', $usernames[1]);
 091   
 092          $users = array();
 093   
 094          $sql = 'SELECT user_id
 095              FROM ' . USERS_TABLE . '
 096              WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . '
 097                  AND user_id <> ' . (int) $post['poster_id'];
 098          $result = $this->db->sql_query($sql);
 099          while ($row = $this->db->sql_fetchrow($result))
 100          {
 101              $users[] = (int) $row['user_id'];
 102          }
 103          $this->db->sql_freeresult($result);
 104   
 105          return $this->get_authorised_recipients($users, $post['forum_id'], $options, true);
 106      }
 107   
 108      /**
 109      * Update a notification
 110      *
 111      * @param array $post Data specific for this type that will be updated
 112      */
 113      public function update_notifications($post)
 114      {
 115          $old_notifications = array();
 116          $sql = 'SELECT n.user_id
 117              FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
 118              WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
 119                  AND n.item_id = ' . self::get_item_id($post) . '
 120                  AND nt.notification_type_id = n.notification_type_id
 121                  AND nt.notification_type_enabled = 1';
 122          $result = $this->db->sql_query($sql);
 123          while ($row = $this->db->sql_fetchrow($result))
 124          {
 125              $old_notifications[] = $row['user_id'];
 126          }
 127          $this->db->sql_freeresult($result);
 128   
 129          // Find the new users to notify
 130          $notifications = $this->find_users_for_notification($post);
 131   
 132          // Find the notifications we must delete
 133          $remove_notifications = array_diff($old_notifications, array_keys($notifications));
 134   
 135          // Find the notifications we must add
 136          $add_notifications = array();
 137          foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id)
 138          {
 139              $add_notifications[$user_id] = $notifications[$user_id];
 140          }
 141   
 142          // Add the necessary notifications
 143          $this->notification_manager->add_notifications_for_users($this->get_type(), $post, $add_notifications);
 144   
 145          // Remove the necessary notifications
 146          if (!empty($remove_notifications))
 147          {
 148              $sql = 'DELETE FROM ' . $this->notifications_table . '
 149                  WHERE notification_type_id = ' . (int) $this->notification_type_id . '
 150                      AND item_id = ' . self::get_item_id($post) . '
 151                      AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
 152              $this->db->sql_query($sql);
 153          }
 154   
 155          // return true to continue with the update code in the notifications service (this will update the rest of the notifications)
 156          return true;
 157      }
 158   
 159      /**
 160      * {inheritDoc}
 161      */
 162      public function get_redirect_url()
 163      {
 164          return $this->get_url();
 165      }
 166   
 167      /**
 168      * Get email template
 169      *
 170      * @return string|bool
 171      */
 172      public function get_email_template()
 173      {
 174          return 'quote';
 175      }
 176   
 177      /**
 178      * Get email template variables
 179      *
 180      * @return array
 181      */
 182      public function get_email_template_variables()
 183      {
 184          $user_data = $this->user_loader->get_user($this->get_data('poster_id'));
 185   
 186          return array_merge(parent::get_email_template_variables(), array(
 187              'AUTHOR_NAME'        => htmlspecialchars_decode($user_data['username']),
 188          ));
 189      }
 190  }
 191