示例#1
0
 public function posts_merging($event)
 {
     $mode = $event['mode'];
     $subject = $event['subject'];
     $username = $event['username'];
     $topic_type = $event['topic_type'];
     $poll = $event['poll'];
     $data = $event['data'];
     $update_message = $event['update_message'];
     $update_search_index = $event['update_search_index'];
     $current_time = time();
     $do_not_merge_with_previous = $this->request->variable('posts_merging_option', false);
     if (!$do_not_merge_with_previous && !$this->helper->post_needs_approval($data) && in_array($mode, array('reply', 'quote')) && $this->merge_interval && !$this->helper->excluded_from_merge($data)) {
         $merge_post_data = $this->helper->get_last_post_data($data);
         // Do not merge if there's no last post data, the post is locked or allowed merge period has left
         if (!$merge_post_data || $merge_post_data['post_edit_locked'] || $current_time - (int) $merge_post_data['topic_last_post_time'] > $this->merge_interval || !$this->user->data['is_registered']) {
             return;
         }
         // Also, don't let user to violate attachments limit by posts merging
         // In this case, also don't merge posts and return
         // Exceptions are administrators and forum moderators
         $num_old_attachments = $this->helper->count_post_attachments((int) $merge_post_data['post_id']);
         $num_new_attachments = sizeof($data['attachment_data']);
         $total_attachments_count = $num_old_attachments + $num_new_attachments;
         if ($total_attachments_count > $this->config['max_attachments'] && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_', (int) $data['forum_id'])) {
             return;
         }
         $data['post_id'] = (int) $merge_post_data['post_id'];
         $merge_post_data['post_attachment'] = $total_attachments_count ? 1 : 0;
         // Decode old message and addon
         $merge_post_data['post_text'] = $this->helper->prepare_text_for_merge($merge_post_data);
         $data['message'] = $this->helper->prepare_text_for_merge($data);
         // Handle inline attachments BBCode in old message
         if ($num_new_attachments) {
             $merge_post_data['post_text'] = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + {$num_new_attachments}).']\\2[/attachment]'", $merge_post_data['post_text']);
         }
         // Prepare message separator
         $this->user->add_lang_ext('rxu/PostsMerging', 'posts_merging');
         $interval = $this->helper->get_time_interval($current_time, $merge_post_data['post_time']);
         $time = array();
         $time[] = $interval->h ? $this->user->lang('D_HOURS', $interval->h) : null;
         $time[] = $interval->i ? $this->user->lang('D_MINUTES', $interval->i) : null;
         $time[] = $interval->s ? $this->user->lang('D_SECONDS', $interval->s) : null;
         $separator = $this->user->lang('MERGE_SEPARATOR', implode(' ', $time));
         // Merge subject
         if (!empty($subject) && $subject != $merge_post_data['post_subject'] && $merge_post_data['post_id'] != $merge_post_data['topic_first_post_id']) {
             $separator .= sprintf($this->user->lang['MERGE_SUBJECT'], $subject);
         }
         // Merge posts
         $merge_post_data['post_text'] = $merge_post_data['post_text'] . $separator . $data['message'];
         // Make sure the message is safe
         $this->type_cast_helper->recursive_set_var($merge_post_data['post_text'], '', true);
         //Prepare post for submit
         $options = '';
         $warn_msg = generate_text_for_storage($merge_post_data['post_text'], $merge_post_data['bbcode_uid'], $merge_post_data['bbcode_bitfield'], $options, $merge_post_data['enable_bbcode'], $merge_post_data['enable_magic_url'], $merge_post_data['enable_smilies']);
         // If $warn_msg is not empty, the merged message does not conform some restrictions
         // In this case we simply don't merge and return back to the function submit_post()
         if (!empty($warn_msg)) {
             return;
         }
         // Update post time and submit post to database
         $merge_post_data['post_time'] = $data['post_time'] = $current_time;
         $this->helper->submit_post_to_database($merge_post_data);
         // Submit attachments
         $this->helper->submit_attachments($data);
         // Update read tracking
         $this->helper->update_read_tracking($data);
         // If a username was supplied or the poster is a guest, we will use the supplied username.
         // Doing it this way we can use "...post by guest-username..." in notifications when
         // "guest-username" is supplied or ommit the username if it is not.
         $username = $username !== '' || !$this->user->data['is_registered'] ? $username : $this->user->data['username'];
         // Send Notifications
         // Despite the post_id is the same and users who've been already notified
         // won't be notified again about the same post_id, we send notifications
         // for new users possibly subscribed to it
         $notification_data = array_merge($data, array('topic_title' => isset($data['topic_title']) ? $data['topic_title'] : $subject, 'post_username' => $username, 'poster_id' => (int) $data['poster_id'], 'post_text' => $data['message'], 'post_time' => $merge_post_data['post_time'], 'post_subject' => $subject));
         $this->notification_manager->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post'), $notification_data);
         // Update search index
         $this->helper->update_search_index($merge_post_data);
         //Generate redirection URL and redirecting
         $params = $add_anchor = '';
         $params .= '&t=' . $data['topic_id'];
         $params .= '&p=' . $data['post_id'];
         $add_anchor = '#p' . $data['post_id'];
         $url = "{$this->phpbb_root_path}viewtopic.{$this->php_ext}";
         $url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor;
         /**
          * Modify the data for post submitting
          *
          * @event rxu.postsmerging.posts_merging_end
          * @var	string	mode				Variable containing posting mode value
          * @var	string	subject				Variable containing post subject value
          * @var	string	username			Variable containing post author name
          * @var	int		topic_type			Variable containing topic type value
          * @var	array	poll				Array with the poll data for the post
          * @var	array	data				Array with the data for the post
          * @var	bool	update_message		Flag indicating if the post will be updated
          * @var	bool	update_search_index	Flag indicating if the search index will be updated
          * @var	string	url					The "Return to topic" URL
          * @since 2.0.0
          */
         $vars = array('mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'update_message', 'update_search_index', 'url');
         extract($this->phpbb_dispatcher->trigger_event('rxu.postsmerging.posts_merging_end', compact($vars)));
         redirect($url);
     }
 }
示例#2
0
 public function test_header_escaping()
 {
     $this->type_cast_helper->expects($this->once())->method('recursive_set_var')->with($this->anything(), '', true);
     $this->request->header('SOMEVAR');
 }