示例#1
0
 /**
  * Edit the new comment notification message
  *
  * @package WP Idea Stream
  * @subpackage comments/classes
  *
  * @since 2.0.0
  *
  * @param  string  $message    the content of the notification
  * @param  integer $comment_id the comment ID
  * @uses   wp_idea_stream_comments_get_comment() to get the comment object
  * @uses   wp_idea_stream_get_post_type() to get the idea post type identifier
  * @uses   do_action() call 'wp_idea_stream_ideas_get_pagination_count' to perform custom actions
  * @return string              the content, edited if needed
  */
 public function comment_notification($message = '', $comment_id = 0)
 {
     // Return if no comment ID
     if (empty($comment_id)) {
         return $message;
     }
     // Check caught value
     if (!empty($this->{'comment_post_' . $comment_id})) {
         $comment = $this->{'comment_post_' . $comment_id};
         // Get the comment to check if it relates to an idea
     } else {
         $comment = wp_idea_stream_comments_get_comment($comment_id);
     }
     // Return if no user_id or the comment does not relate to an idea
     if (empty($comment->comment_post_author) || empty($comment->comment_post_type) || wp_idea_stream_get_post_type() != $comment->comment_post_type) {
         return $message;
     }
     // First add a post type var at the end of the links
     preg_match_all('/(comment|comments).php\\?(.*)\\r\\n/', $message, $matches);
     if (!empty($matches[2])) {
         foreach ($matches[2] as $action) {
             $message = str_replace($action, $action . '&post_type=' . wp_idea_stream_get_post_type(), $message);
         }
     }
     // It's not a notification to author return the message
     if (empty($comment->comment_approved)) {
         return $message;
     }
     /**
      * If we arrive here, then WordPress is notifying the author of the idea
      * that a new comment has been posted and approuved on his idea. So if the
      * idea's author does not have the capability to moderate comments, we need
      * to make sure he won't receive the links to delete|trash|spam the comment
      * The easiest way is to completely replace the content of the message sent.
      *
      * @todo in a future release, we could create a specific capability to let
      * for instance BuddyPress group moderators/administrator moderate the comments
      * about the ideas posted in their group.
      */
     if (!user_can($comment->comment_post_author, 'moderate_comments')) {
         // reset the message
         $message = sprintf(__('New comment on your idea "%s"', 'wp-idea-stream'), $comment->comment_post_title) . "\r\n";
         $message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
         $message .= sprintf(__('Permalink to the comment: %s', 'wp-idea-stream'), wp_idea_stream_comments_get_comment_link($comment_id)) . "\r\n";
     }
     /**
      * Used internally to generate a BuddyPress screen notification
      *
      * @param  object $comment the comment object
      */
     do_action('wp_idea_stream_comments_notify_author', $comment);
     return $message;
 }
示例#2
0
 /**
  * 4-Comments/ Format the activity actions in case a comment about an idea was posted
  *
  * @package WP Idea Stream
  * @subpackage buddypress/activity
  *
  * @since 2.0.0
  *
  * @param  string               $action   the action string
  * @param  BP_Activity_Activity $activity the activity object
  * @uses   wp_idea_stream_comments_get_comment_link() to override the primary link
  * @uses   bp_core_get_userlink() to get user's profile url
  * @uses   esc_url() to sanitize the primary link (unchanged)
  * @uses   esc_html() to sanitize the custom part of the action
  * @uses   apply_filters() call 'wp_idea_stream_buddypress_format_idea_comment_activity_action' to override the comment action strings
  * @return string                         the action adjusted for an idea if needed
  */
 public function format_idea_comment_activity_action($action = '', $activity = null)
 {
     if (!is_object($activity)) {
         return false;
     }
     $primary_link = wp_idea_stream_comments_get_comment_link($activity->secondary_item_id);
     if (empty($primary_link)) {
         $primary_link = $activity->primary_link;
     }
     $action = sprintf(_x('%1$s replied to this %2$s', 'idea commented activity action', 'wp-idea-stream'), bp_core_get_userlink($activity->user_id), '<a href="' . esc_url($primary_link) . '">' . esc_html(mb_strtolower($this->post_type_object->labels->singular_name, 'UTF-8')) . '</a>');
     return apply_filters('wp_idea_stream_buddypress_format_idea_comment_activity_action', $action);
 }
示例#3
0
 /**
  * Action formatting callback for comments posted within a group
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @param  string               $action   the activity action string
  * @param  BP_Activity_Activity $activity the activity object
  * @uses   buddypress() to get BuddyPress instance
  * @uses   groups_get_group() to get a group's object thanks to its ID
  * @uses   wp_idea_stream_comments_get_comment_link() to get the comment link
  * @uses   esc_url() to sanitize the url
  * @uses   bp_get_group_permalink() to get group's home link
  * @uses   esc_html() to sanitize output
  * @uses   bp_core_get_userlink() to build user's profile link
  * @return string           the action string adapted to group's context
  */
 public static function group_format_comment_action($action = '', $activity = null)
 {
     if (empty($activity->item_id)) {
         return $action;
     }
     if (buddypress()->groups->id != $activity->component) {
         return $action;
     }
     $group = groups_get_group(array('group_id' => $activity->item_id, 'populate_extras' => false));
     if (empty($group)) {
         return $action;
     }
     $primary_link = wp_idea_stream_comments_get_comment_link($activity->secondary_item_id);
     if (empty($primary_link)) {
         $primary_link = $activity->primary_link;
     }
     $group_link = '<a href="' . esc_url(bp_get_group_permalink($group)) . '">' . esc_html($group->name) . '</a>';
     $action = sprintf(_x('%1$s replied to this %2$s posted in the group %3$s', 'idea commented group activity action', 'wp-idea-stream'), bp_core_get_userlink($activity->user_id), '<a href="' . esc_url($primary_link) . '">' . esc_html(mb_strtolower(self::$post_type_object->labels->singular_name, 'UTF-8')) . '</a>', $group_link);
     return $action;
 }
示例#4
0
/**
 * Return the permalink of the comment currently being iterated on.
 *
 * @package WP Idea Stream
 * @subpackage comments/tags
 *
 * @since 2.0.0
 *
 * @uses   wp_idea_stream() to get plugin's main instance
 * @uses   wp_idea_stream_comments_get_comment_link() to get the permalink
 * @uses   apply_filters() call 'wp_idea_stream_comments_get_comment_permalink' to override the output
 * @return string the comment's permalink.
 */
function wp_idea_stream_comments_get_comment_permalink()
{
    $comment = wp_idea_stream()->comment_query_loop->comment;
    $comment_link = wp_idea_stream_comments_get_comment_link($comment);
    /**
     * @param  string  $comment_link the comment link
     * @param  object  $comment the comment object
     */
    return apply_filters('wp_idea_stream_comments_get_comment_permalink', esc_url($comment_link), $comment);
}
示例#5
0
 /**
  * @group activity_action
  */
 public function test_wp_idea_stream_idea_activity_actions()
 {
     bp_activity_get_actions();
     $u = $this->factory->user->create();
     $i = $this->factory->idea->create(array('author' => $u));
     $user = $this->factory->user->get_object_by_id($u);
     // Create comment
     $c = $this->factory->idea_comment->create(array('user_id' => $u, 'comment_author_email' => $user->user_email, 'comment_post_ID' => $i));
     $user_link = bp_core_get_userlink($u);
     $blog_url = get_home_url();
     $post_url = add_query_arg('p', $i, trailingslashit($blog_url));
     $comment_link = wp_idea_stream_comments_get_comment_link($c);
     $a = $this->factory->activity->create(array('component' => buddypress()->blogs->id, 'type' => 'new_ideas', 'user_id' => $u, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $i, 'primary_link' => $post_url));
     $expected = sprintf('%1$s wrote a new %2$s', $user_link, '<a href="' . esc_url($post_url) . '">idea</a>');
     $a_obj = new BP_Activity_Activity($a);
     $this->assertSame($expected, $a_obj->action);
     // Comment
     $a = $this->factory->activity->create(array('component' => buddypress()->blogs->id, 'type' => 'new_ideas_comment', 'user_id' => $u, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $c));
     $expected = sprintf('%1$s replied to this %2$s', $user_link, '<a href="' . esc_url($comment_link) . '">idea</a>');
     $a_obj = new BP_Activity_Activity($a);
     $this->assertSame($expected, $a_obj->action);
     /** Group */
     $g = $this->factory->group->create();
     $a = $this->factory->activity->create(array('component' => buddypress()->groups->id, 'type' => 'new_ideas', 'user_id' => $u, 'item_id' => $g, 'secondary_item_id' => $i, 'primary_link' => $post_url));
     $group = $this->factory->group->get_object_by_id($g);
     $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . $group->name . '</a>';
     $expected = sprintf('%1$s wrote a new %2$s in the group %3$s', $user_link, '<a href="' . esc_url($post_url) . '">idea</a>', $group_link);
     $a_obj = new BP_Activity_Activity($a);
     $this->assertSame($expected, $a_obj->action);
     // Comment
     $a = $this->factory->activity->create(array('component' => buddypress()->groups->id, 'type' => 'new_ideas_comment', 'user_id' => $u, 'item_id' => $g, 'secondary_item_id' => $c));
     $expected = sprintf('%1$s replied to this %2$s posted in the group %3$s', $user_link, '<a href="' . esc_url($comment_link) . '">idea</a>', $group_link);
     $a_obj = new BP_Activity_Activity($a);
     $this->assertSame($expected, $a_obj->action);
 }