コード例 #1
0
ファイル: controller.php プロジェクト: melvingb/mentions
 /**
  * Mentions controller accessed from the URL /mentions/user_list
  *
  * @return null
  * @access public
  */
 public function get_userlist()
 {
     // Send a JSON response if an AJAX request was used
     if ($this->request->is_ajax()) {
         // If we have a query_string, we just get those usernames
         $query_string = $this->request->variable('term', '') ? $this->request->variable('term', '') : false;
         $user_list = $this->mentions->get_userlist($query_string);
         $user_list = array_values($user_list);
         $json_response = new \phpbb\json_response();
         $json_response->send($user_list);
     }
 }
コード例 #2
0
ファイル: listener.php プロジェクト: melvingb/mentions
 /**
  * Add the mention bbcode to the custom bbcodes of bbcode box for posts.
  * 
  * @param object $event The event object
  * @return void
  */
 public function custom_bbcodes_display($event)
 {
     $num_predefined_bbcodes = $event['num_predefined_bbcodes'];
     $bbcodes = array('mention' => $this->config['wolfsblvt.mentions.active_bbcode'] ? 'mention' : false, 'mention_text' => $this->config['wolfsblvt.mentions.active_bbcode_text'] ? 'mention=' : false);
     $this->mentions->add_bbcodes_to_display($bbcodes, $num_predefined_bbcodes);
     // We have more bbcodes that does not count as a custom bbcode, take the increased number
     $event['num_predefined_bbcodes'] = $num_predefined_bbcodes;
 }
コード例 #3
0
ファイル: mention.php プロジェクト: melvingb/mentions
 /**
  * Find the users who want to receive notifications
  *
  * @param array $post Data from submit_post
  * @param array $options Options for finding users for notification
  *
  * @return array
  */
 public function find_users_for_notification($post, $options = array())
 {
     $options = array_merge(array('ignore_users' => array()), $options);
     $users = $this->mentions->get_mentioned_users($post['post_text']);
     $user_ids = array_map(function ($value) {
         return $value['user_id'];
     }, $users);
     return $this->get_authorised_recipients($user_ids, $post['forum_id'], $options, true);
 }
コード例 #4
0
ファイル: parser.php プロジェクト: ezpz-cz/web-plugins
 /**
  * Replace all mentions inside of a text with full username_string and mention name
  * 
  * @param string $text the original text
  * @return string the text with replaced mentions
  */
 public function replace_mentions_for_display($text)
 {
     global $request;
     $is_debug = $request->variable('measure_time', 0);
     $start_time = time();
     $i = 0;
     if ($is_debug) {
         $start_text = $text;
     }
     for ($i; $i < 100; $i++) {
         // Get mentioned users ordered by position descending, so that we can safely replace without conflict
         $mentions = $this->mentions->get_mentioned_users($text, true);
         foreach ($mentions as $id => $mention_data) {
             if ($is_debug) {
                 $text = $start_text;
             }
             $replace_string = $mention_data['username_full'];
             // If we used a custom text for the mention, we take this as username
             if ($mention_data['type'] == mentions::MENTION_BBCODE_TEXT) {
                 $written_username = htmlentities(substr($text, $mention_data['start'], $mention_data['length']));
                 $replace_string = str_replace($mention_data['name'], $written_username, $replace_string);
             }
             // We add the username as title, so that we can see that someone is mentioned and who is mentioned on hover
             $a_title = htmlentities($this->user->lang['MENTIONS_MENTION'] . $this->user->lang['COLON'] . ' ' . $mention_data['name']);
             $replace_string = preg_replace('#<a#', "<a title=\"{$a_title}\"", $replace_string, 1);
             // Add image if it is enabled
             if ($this->config['wolfsblvt.mentions.image_inline']) {
                 $img = "<div class=\"mentions-avatar mentions-avatar-inline\">" . $mention_data['avatar'] . '</div> ';
                 $pos_end_of_a_tag = strpos($replace_string, '>') + 1;
                 $replace_string = substr_replace($replace_string, $img, $pos_end_of_a_tag, 0);
             }
             // We should cut the bbcodes as well, so we have to look now how long they are
             $len_before = $len_after = 0;
             switch ($mention_data['type']) {
                 case mentions::MENTION_AT:
                     break;
                 case mentions::MENTION_BBCODE:
                     $len_before = strlen('[mention]');
                     $len_after = strlen('[/mention]');
                     break;
                 case mentions::MENTION_BBCODE_TEXT:
                     $len_before = strlen("[mention=&quot;{$mention_data['name']}&quot;]");
                     $len_after = strlen('[/mention]');
             }
             $text = substr_replace($text, $replace_string, $mention_data['start'] - $len_before, $mention_data['length'] + $len_before + $len_after);
         }
         if ($is_debug) {
             // max 5 seconds for measuring
             if (time() - $start_time > 5) {
                 $i++;
                 break;
             }
         } else {
             $i++;
             break;
         }
     }
     if ($is_debug) {
         echo "Runtime of function ({$i}x): " . (time() - $start_time) . " seconds. Average: " . floatval(time() - $start_time) / $i . " seconds.<br />";
     }
     return $text;
 }