Пример #1
0
/**
 * bp_like_post_to_stream()
 * 
 * Posts to stream, depending on settings
 * 
 * TODO, Should we be posted that people like comments to the feed? This can get messy..
 * Also no point having 20 posts saying people liked the same status..
 * 
 */
function bp_like_post_to_stream($item_id, $user_id)
{
    if (bp_like_get_settings('post_to_activity_stream') == 1) {
        $activity = bp_activity_get_specific(array('activity_ids' => $item_id, 'component' => 'buddypress-like'));
        $author_id = $activity['activities'][0]->user_id;
        if ($user_id == $author_id) {
            $action = bp_like_get_text('record_activity_likes_own');
        } elseif ($user_id == 0) {
            $action = bp_like_get_text('record_activity_likes_an');
        } else {
            $action = bp_like_get_text('record_activity_likes_users');
        }
        $liker = bp_core_get_userlink($user_id);
        $author = bp_core_get_userlink($author_id);
        $activity_url = bp_activity_get_permalink($item_id);
        $content = '';
        //content must be defined...
        /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
        if (bp_like_get_settings('show_excerpt') == 1) {
            $content = $activity['activities'][0]->content;
            if (strlen($content) > bp_like_get_settings('excerpt_length')) {
                $content = substr($content, 0, bp_like_get_settings('excerpt_length'));
                $content = strip_tags($content);
                $content = $content . '...';
            }
        }
        /* Filter out the placeholders */
        $action = str_replace('%user%', $liker, $action);
        $action = str_replace('%permalink%', $activity_url, $action);
        $action = str_replace('%author%', $author, $action);
        bp_activity_add(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id, 'item_id' => $item_id));
    }
}
function bp_links_at_message_notification($content, $poster_user_id, $link_id, $activity_id)
{
    global $bp;
    /* Scan for @username strings in an activity update. Notify each user. */
    $pattern = '/[@]+([A-Za-z0-9-_]+)/';
    preg_match_all($pattern, $content, $usernames);
    /* Make sure there's only one instance of each username */
    if (!($usernames = array_unique($usernames[1]))) {
        return false;
    }
    $link = new BP_Links_Link($link_id);
    foreach ((array) $usernames as $username) {
        if (!($receiver_user_id = bp_core_get_userid($username))) {
            continue;
        }
        if (!bp_links_is_link_visibile($link, $receiver_user_id)) {
            continue;
        }
        // Now email the user with the contents of the message (if they have enabled email notifications)
        if ('no' != get_usermeta($user_id, 'notification_activity_new_mention')) {
            $poster_name = bp_core_get_user_displayname($poster_user_id);
            $message_link = bp_activity_get_permalink($activity_id);
            $settings_link = bp_core_get_user_domain($receiver_user_id) . 'settings/notifications/';
            // Set up and send the message
            $ud = bp_core_get_core_userdata($receiver_user_id);
            $to = $ud->user_email;
            $subject = '[' . get_blog_option(BP_ROOT_BLOG, 'blogname') . '] ' . sprintf(__('%s mentioned you in the link "%s"', 'buddypress-links'), stripslashes($poster_name), wp_filter_kses(stripslashes($link->name)));
            $message = sprintf(__('%s mentioned you in the link "%s":

"%s"

To view and respond to the message, log in and visit: %s

---------------------
', 'buddypress-links'), $poster_name, wp_filter_kses(stripslashes_deep($link->name)), wp_filter_kses(stripslashes_deep($content)), $message_link);
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
            // Send it
            wp_mail($to, $subject, $message);
        }
    }
}
Пример #3
0
 /**
  * "In response to" column markup.
  *
  * @since BuddyPress (1.6.0)
  *
  * @see WP_List_Table::single_row_columns()
  *
  * @param array $item A singular item (one full row).
  */
 function column_response($item)
 {
     // Is $item is a root activity?
     /**
      * Filters default list of default root activity types.
      *
      * @since BuddyPress (1.6.0)
      *
      * @param array $value Array of default activity types.
      * @param array $item  Current item being displayed.
      */
     if (empty($item['item_id']) || !in_array($item['type'], apply_filters('bp_activity_admin_root_activity_types', array('activity_comment'), $item))) {
         $comment_count = !empty($item['children']) ? bp_activity_recurse_comment_count((object) $item) : 0;
         $root_activity_url = bp_get_admin_url('admin.php?page=bp-activity&aid=' . $item['id']);
         // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble
         if ($comment_count) {
             $title_attr = sprintf(_n('%s related activity', '%s related activities', $comment_count, 'buddypress'), number_format_i18n($comment_count));
             printf('<a href="%1$s" title="%2$s" class="post-com-count"><span class="comment-count">%3$s</span></a>', esc_url($root_activity_url), esc_attr($title_attr), number_format_i18n($comment_count));
         }
         // For non-root activities, display a link to the replied-to activity's author's profile
     } else {
         echo '<strong>' . get_avatar($this->get_activity_user_id($item['item_id']), '32') . ' ' . bp_core_get_userlink($this->get_activity_user_id($item['item_id'])) . '</strong><br />';
     }
     // Activity permalink
     if (!$item['is_spam']) {
         printf(__('<a href="%1$s">View Activity</a>', 'buddypress'), bp_activity_get_permalink($item['id'], (object) $item));
     }
 }
/**
 * Load the page for a single activity item.
 *
 * @since 1.2.0
 *
 * @uses bp_is_activity_component()
 * @uses bp_activity_get_specific()
 * @uses bp_current_action()
 * @uses bp_action_variables()
 * @uses bp_do_404()
 * @uses bp_is_active()
 * @uses groups_get_group()
 * @uses groups_is_user_member()
 * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_access' hook.
 * @uses do_action() To call the 'bp_activity_screen_single_activity_permalink' hook.
 * @uses bp_core_add_message()
 * @uses is_user_logged_in()
 * @uses bp_core_redirect()
 * @uses site_url()
 * @uses esc_url()
 * @uses bp_get_root_domain()
 * @uses bp_get_activity_root_slug()
 * @uses bp_core_load_template()
 * @uses apply_filters() To call the 'bp_activity_template_profile_activity_permalink' hook.
 */
function bp_activity_screen_single_activity_permalink()
{
    $bp = buddypress();
    // No displayed user or not viewing activity component.
    if (!bp_is_activity_component()) {
        return false;
    }
    if (!bp_current_action() || !is_numeric(bp_current_action())) {
        return false;
    }
    // Get the activity details.
    $activity = bp_activity_get_specific(array('activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only'));
    // 404 if activity does not exist
    if (empty($activity['activities'][0]) || bp_action_variables()) {
        bp_do_404();
        return;
    } else {
        $activity = $activity['activities'][0];
    }
    // Default access is true.
    $has_access = true;
    // If activity is from a group, do an extra cap check.
    if (isset($bp->groups->id) && $activity->component == $bp->groups->id) {
        // Activity is from a group, but groups is currently disabled.
        if (!bp_is_active('groups')) {
            bp_do_404();
            return;
        }
        // Check to see if the group is not public, if so, check the
        // user has access to see this activity.
        if ($group = groups_get_group(array('group_id' => $activity->item_id))) {
            // Group is not public.
            if ('public' != $group->status) {
                // User is not a member of group.
                if (!groups_is_user_member(bp_loggedin_user_id(), $group->id)) {
                    $has_access = false;
                }
            }
        }
    }
    /**
     * Filters the access permission for a single activity view.
     *
     * @since 1.2.0
     *
     * @param array $access Array holding the current $has_access value and current activity item instance.
     */
    $has_access = apply_filters_ref_array('bp_activity_permalink_access', array($has_access, &$activity));
    /**
     * Fires before the loading of a single activity template file.
     *
     * @since 1.2.0
     *
     * @param BP_Activity_Activity $activity   Object representing the current activity item being displayed.
     * @param bool                 $has_access Whether or not the current user has access to view activity.
     */
    do_action('bp_activity_screen_single_activity_permalink', $activity, $has_access);
    // Access is specifically disallowed.
    if (false === $has_access) {
        // User feedback.
        bp_core_add_message(__('You do not have access to this activity.', 'buddypress'), 'error');
        // Redirect based on logged in status.
        if (is_user_logged_in()) {
            $url = bp_loggedin_user_domain();
        } else {
            $url = sprintf(site_url('wp-login.php?redirect_to=%s'), urlencode(esc_url_raw(bp_activity_get_permalink((int) bp_current_action()))));
        }
        bp_core_redirect($url);
    }
    /**
     * Filters the template to load for a single activity screen.
     *
     * @since 1.0.0
     *
     * @param string $template Path to the activity template to load.
     */
    bp_core_load_template(apply_filters('bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink'));
}
Пример #5
0
 /**
  * The search function
  *
  * @return array|string
  */
 protected function do_search()
 {
     global $wpdb;
     if (isset($wpdb->base_prefix)) {
         $_prefix = $wpdb->base_prefix;
     } else {
         $_prefix = $wpdb->prefix;
     }
     $options = $this->options;
     $searchData = $this->searchData;
     $kw_logic = w_isset_def($searchData['keyword_logic'], 'or');
     $q_config['language'] = $options['qtranslate_lang'];
     $s = $this->s;
     // full keyword
     $_s = $this->_s;
     // array of keywords
     if ($kw_logic == 'orex') {
         $_si = "[[:<:]]" . implode('[[:>:]]|[[:<:]]', $_s) . "[[:>:]]";
     } else {
         $_si = implode('|', $_s);
     }
     // imploded phrase for regexp
     $_si = $_si != '' ? $_si : $s;
     $repliesresults = array();
     $userresults = array();
     $groupresults = array();
     $activityresults = array();
     $words = $options['set_exactonly'] == 1 ? array($s) : $_s;
     $regexp_words = count($_s > 0) ? implode('|', $_s) : $s;
     if (function_exists('bp_core_get_user_domain')) {
         $parts = array();
         $relevance_parts = array();
         /*----------------------- User query ---------------------------*/
         // User query had been replaced with user results..
         /*---------------------------------------------------------------*/
         /*----------------------- Groups query --------------------------*/
         if ($searchData['search_in_bp_groups'] && bp_is_active('groups')) {
             $parts = array();
             $relevance_parts = array();
             /*------------------------- Statuses ----------------------------*/
             $statuses = array();
             if ($searchData['search_in_bp_groups_public'] == 1) {
                 $statuses[] = 'public';
             }
             if ($searchData['search_in_bp_groups_private'] == 1) {
                 $statuses[] = 'private';
             }
             if ($searchData['search_in_bp_groups_hidden'] == 1) {
                 $statuses[] = 'hidden';
             }
             if (count($statuses) < 1) {
                 return '';
             }
             $swords = implode('|', $statuses);
             $group_statuses = "(lower(" . $wpdb->prefix . "bp_groups.status) REGEXP '{$swords}')";
             /*---------------------------------------------------------------*/
             /*------------------------- Title query -------------------------*/
             if ($kw_logic == 'or' || $kw_logic == 'and') {
                 $op = strtoupper($kw_logic);
                 if (count($_s) > 0) {
                     $_like = implode("%' " . $op . " lower(" . $wpdb->prefix . "bp_groups.name) LIKE '%", $words);
                 } else {
                     $_like = $s;
                 }
                 $parts[] = "( lower(" . $wpdb->prefix . "bp_groups.name) LIKE '%" . $_like . "%' )";
             } else {
                 $_like = array();
                 $op = $kw_logic == 'andex' ? 'AND' : 'OR';
                 foreach ($words as $word) {
                     $_like[] = "\r\n                           (lower(" . $wpdb->prefix . "bp_groups.name) LIKE '% " . $word . " %'\r\n                        OR  lower(" . $wpdb->prefix . "bp_groups.name) LIKE '" . $word . " %'\r\n                        OR  lower(" . $wpdb->prefix . "bp_groups.name) LIKE '% " . $word . "'\r\n                        OR  lower(" . $wpdb->prefix . "bp_groups.name) = '" . $word . "')";
                 }
                 $parts[] = "(" . implode(' ' . $op . ' ', $_like) . ")";
             }
             /*$words = $options['set_exactonly'] == 1 ? $s : $_si;
               if ($kw_logic == 'or' || $kw_logic == 'orex') {
                   $parts[] = "(lower(" . $wpdb->prefix . "bp_groups.name) REGEXP '$words')";
               } else {
                   if (count($_s) > 0)
                       $and_like = implode("$r_sign' AND lower(" . $wpdb->prefix . "bp_groups.name) RLIKE '$l_sign", $_s);
                   else
                       $and_like = $s;
                   $parts[] = "lower(" . $wpdb->prefix . "bp_groups.name) RLIKE '$l_sign" . $and_like . "$r_sign'";
               }*/
             $relevance_parts[] = "(case when\r\n                    (lower(" . $wpdb->prefix . "bp_groups.name) REGEXP '{$regexp_words}')\r\n                     then {$searchData['titleweight']} else 0 end)";
             $relevance_parts[] = "(case when\r\n                    (lower(" . $wpdb->prefix . "bp_groups.name) = '{$s}')\r\n                     then {$searchData['etitleweight']} else 0 end)";
             // The first word relevance is higher
             if (count($_s) > 0) {
                 $relevance_parts[] = "(case when\r\n                      (lower(" . $wpdb->prefix . "bp_groups.name) REGEXP '" . $_s[0] . "')\r\n                       then {$searchData['etitleweight']} else 0 end)";
             }
             /*---------------------------------------------------------------*/
             /*---------------------- Description query ----------------------*/
             if ($kw_logic == 'or' || $kw_logic == 'and') {
                 $op = strtoupper($kw_logic);
                 if (count($_s) > 0) {
                     $_like = implode("%' " . $op . " lower(" . $wpdb->prefix . "bp_groups.description) LIKE '%", $words);
                 } else {
                     $_like = $s;
                 }
                 $parts[] = "( lower(" . $wpdb->prefix . "bp_groups.description) LIKE '%" . $_like . "%' )";
             } else {
                 $_like = array();
                 $op = $kw_logic == 'andex' ? 'AND' : 'OR';
                 foreach ($words as $word) {
                     $_like[] = "\r\n                           (lower(" . $wpdb->prefix . "bp_groups.description) LIKE '% " . $word . " %'\r\n                        OR  lower(" . $wpdb->prefix . "bp_groups.description) LIKE '" . $word . " %'\r\n                        OR  lower(" . $wpdb->prefix . "bp_groups.description) LIKE '% " . $word . "'\r\n                        OR  lower(" . $wpdb->prefix . "bp_groups.description) = '" . $word . "')";
                 }
                 $parts[] = "(" . implode(' ' . $op . ' ', $_like) . ")";
             }
             /*if ($kw_logic == 'or' || $kw_logic == 'orex') {
                   $parts[] = "(lower(" . $wpdb->prefix . "bp_groups.description) REGEXP '$words')";
               } else {
                   if (count($_s) > 0)
                       $and_like = implode("$r_sign' AND lower(" . $wpdb->prefix . "bp_groups.description) RLIKE '$l_sign", $_s);
                   else
                       $and_like = $s;
                   $parts[] = "lower(" . $wpdb->prefix . "bp_groups.description) RLIKE '$l_sign" . $and_like . "$r_sign'";
               }*/
             $relevance_parts[] = "(case when\r\n                    (lower(" . $wpdb->prefix . "bp_groups.description) REGEXP '{$regexp_words}')\r\n                     then {$searchData['contentweight']} else 0 end)";
             $relevance_parts[] = "(case when\r\n                    (lower(" . $wpdb->prefix . "bp_groups.description) = '{$s}')\r\n                     then {$searchData['econtentweight']} else 0 end)";
             /*---------------------------------------------------------------*/
             /*------------------------- Build like --------------------------*/
             $like_query = implode(' OR ', $parts);
             if ($like_query == "") {
                 $like_query = "(1)";
             } else {
                 $like_query = "({$like_query})";
             }
             /*---------------------------------------------------------------*/
             /*---------------------- Build relevance ------------------------*/
             $relevance = implode(' + ', $relevance_parts);
             if ($searchData['userelevance'] != 1 || $relevance == "") {
                 $relevance = "(1)";
             } else {
                 $relevance = "({$relevance})";
             }
             /*---------------------------------------------------------------*/
             $querystr = "\r\n             SELECT\r\n               " . $wpdb->prefix . "bp_groups.id as id,\r\n               " . $wpdb->prefix . "bp_groups.name as title,\r\n               " . $wpdb->prefix . "bp_groups.description as content,\r\n               " . $wpdb->prefix . "bp_groups.date_created as date,\r\n               {$wpdb->users}.user_nicename as author,\r\n               'bp_group' as content_type,\r\n               {$relevance} as relevance\r\n             FROM\r\n               " . $wpdb->prefix . "bp_groups\r\n             LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = " . $wpdb->prefix . "bp_groups.creator_id\r\n             WHERE\r\n                  {$group_statuses}\r\n              AND {$like_query}\r\n              ORDER BY relevance DESC, title ASC";
             $groupresults = $wpdb->get_results($querystr, OBJECT);
             foreach ($groupresults as $k => $v) {
                 $group = new BP_Groups_Group($v->id);
                 $groupresults[$k]->link = bp_get_group_permalink($group);
                 if ($searchData['image_options']['show_images'] == 1) {
                     $avatar_options = array('item_id' => $v->id, 'object' => 'group', 'type' => 'full', 'html' => false);
                     $im = bp_core_fetch_avatar($avatar_options);
                     if ($im != '') {
                         $groupresults[$k]->image = $im;
                     }
                 }
                 if ($groupresults[$k]->content != '') {
                     $groupresults[$k]->content = wd_substr_at_word(strip_tags($groupresults[$k]->content), $searchData['descriptionlength']) . "...";
                 }
             }
         }
         /*---------------------------------------------------------------*/
         /*----------------------- Activity query ------------------------*/
         if ($searchData['search_in_bp_activities'] && bp_is_active('groups')) {
             $parts = array();
             $relevance_parts = array();
             /*---------------------- Description query ----------------------*/
             if ($kw_logic == 'or' || $kw_logic == 'and') {
                 $op = strtoupper($kw_logic);
                 if (count($_s) > 0) {
                     $_like = implode("%' " . $op . " lower(" . $wpdb->prefix . "bp_activity.content) LIKE '%", $words);
                 } else {
                     $_like = $s;
                 }
                 $parts[] = "( lower(" . $wpdb->prefix . "bp_activity.content) LIKE '%" . $_like . "%' )";
             } else {
                 $_like = array();
                 $op = $kw_logic == 'andex' ? 'AND' : 'OR';
                 foreach ($words as $word) {
                     $_like[] = "\r\n                           (lower(" . $wpdb->prefix . "bp_activity.content) LIKE '% " . $word . " %'\r\n                        OR  lower(" . $wpdb->prefix . "bp_activity.content) LIKE '" . $word . " %'\r\n                        OR  lower(" . $wpdb->prefix . "bp_activity.content) LIKE '% " . $word . "'\r\n                        OR  lower(" . $wpdb->prefix . "bp_activity.content) = '" . $word . "')";
                 }
                 $parts[] = "(" . implode(' ' . $op . ' ', $_like) . ")";
             }
             /*$words = $options['set_exactonly'] == 1 ? $s : $_si;
               if ($kw_logic == 'or' || $kw_logic == 'orex') {
                   $parts[] = "(lower(" . $wpdb->prefix . "bp_activity.content) REGEXP '$words')";
               } else {
                   if (count($_s) > 0)
                       $and_like = implode("$r_sign' AND lower(" . $wpdb->prefix . "bp_activity.content) RLIKE '$l_sign", $_s);
                   else
                       $and_like = $s;
                   $parts[] = "lower(" . $wpdb->prefix . "bp_activity.content) RLIKE '$l_sign" . $and_like . "$r_sign'";
               }*/
             $relevance_parts[] = "(case when\r\n                    (lower(" . $wpdb->prefix . "bp_activity.content) REGEXP '{$regexp_words}')\r\n                     then {$searchData['contentweight']} else 0 end)";
             $relevance_parts[] = "(case when\r\n                    (lower(" . $wpdb->prefix . "bp_activity.content) = '{$s}')\r\n                     then {$searchData['econtentweight']} else 0 end)";
             /*---------------------------------------------------------------*/
             /*------------------------- Build like --------------------------*/
             $like_query = implode(' OR ', $parts);
             if ($like_query == "") {
                 $like_query = "(1)";
             } else {
                 $like_query = "({$like_query})";
             }
             /*---------------------------------------------------------------*/
             /*---------------------- Build relevance ------------------------*/
             $relevance = implode(' + ', $relevance_parts);
             if ($searchData['userelevance'] != 1 || $relevance == "") {
                 $relevance = "(1)";
             } else {
                 $relevance = "({$relevance})";
             }
             /*---------------------------------------------------------------*/
             $querystr = "\r\n                 SELECT\r\n                   " . $wpdb->prefix . "bp_activity.id as id,\r\n                   " . $wpdb->prefix . "bp_activity.content as title,\r\n                   " . $wpdb->prefix . "bp_activity.content as content,\r\n                   " . $wpdb->prefix . "bp_activity.date_recorded as date,\r\n                   {$wpdb->users}.user_nicename as author,\r\n                   " . $wpdb->prefix . "bp_activity.user_id as author_id,\r\n                   'bp_activity' as content_type,\r\n                   {$relevance} as relevance\r\n                 FROM\r\n                   " . $wpdb->prefix . "bp_activity\r\n                 LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = " . $wpdb->prefix . "bp_activity.user_id\r\n                 WHERE\r\n                   (" . $wpdb->prefix . "bp_activity.component = 'activity' AND " . $wpdb->prefix . "bp_activity.is_spam = 0)\r\n                   AND {$like_query}\r\n                   ORDER BY relevance DESC, title ASC";
             $activityresults = $wpdb->get_results($querystr, OBJECT);
             foreach ($activityresults as $k => $v) {
                 $activityresults[$k]->link = bp_activity_get_permalink($v->id);
                 $activityresults[$k]->image = bp_core_fetch_avatar(array('item_id' => $v->author_id, 'html' => false));
             }
         }
         do_action('bbpress_init');
     }
     $this->results = array('repliesresults' => $repliesresults, 'groupresults' => $groupresults, 'activityresults' => $activityresults);
     return $this->results;
 }
/**
 * Get the latest update from the current member in the loop.
 *
 * @param array|string $args {
 *     Array of optional arguments.
 *     @type int  $length    Truncation length. Default: 225.
 *     @type bool $view_link Whether to provide a 'View' link for
 *                           truncated entries. Default: false.
 * }
 * @return string
 */
function bp_get_member_latest_update($args = '')
{
    global $members_template;
    $defaults = array('length' => 225, 'view_link' => true);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    if (!bp_is_active('activity') || empty($members_template->member->latest_update) || !($update = maybe_unserialize($members_template->member->latest_update))) {
        return false;
    }
    /**
     * Filters the excerpt of the latest update for current member in the loop.
     *
     * @since 1.2.5
     *
     * @param string $value Excerpt of the latest update for current member in the loop.
     */
    $update_content = apply_filters('bp_get_activity_latest_update_excerpt', trim(strip_tags(bp_create_excerpt($update['content'], $length))));
    $update_content = sprintf(_x('- &quot;%s&quot;', 'member latest update in member directory', 'buddypress'), $update_content);
    // If $view_link is true and the text returned by bp_create_excerpt() is different from the original text (ie it's
    // been truncated), add the "View" link.
    if ($view_link && $update_content != $update['content']) {
        $view = __('View', 'buddypress');
        $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink($update['id']) . '" rel="nofollow">' . $view . '</a></span>';
    }
    /**
     * Filters the latest update from the current member in the loop.
     *
     * @since 1.2.0
     *
     * @param string $update_content Formatted latest update for current member.
     */
    return apply_filters('bp_get_member_latest_update', $update_content);
}
        function widget($args, $instance)
        {
            if (RWLogger::IsOn()) {
                $params = func_get_args();
                RWLogger::LogEnterence("RatingWidgetPlugin_TopRatedWidget.widget", $params, true);
            }
            if (!defined("WP_RW__SITE_PUBLIC_KEY") || false === WP_RW__SITE_PUBLIC_KEY) {
                return;
            }
            if (RatingWidgetPlugin::$WP_RW__HIDE_RATINGS) {
                return;
            }
            extract($args, EXTR_SKIP);
            $bpInstalled = ratingwidget()->IsBuddyPressInstalled();
            $bbInstalled = ratingwidget()->IsBBPressInstalled();
            $types = $this->GetTypesInfo();
            $show_any = false;
            foreach ($types as $type => $data) {
                if (false !== $instance["show_{$type}"]) {
                    $show_any = true;
                    break;
                }
            }
            if (RWLogger::IsOn()) {
                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget', 'show_any = ' . ($show_any ? 'TRUE' : 'FALSE'));
            }
            if (false === $show_any) {
                // Nothing to show.
                return;
            }
            $details = array("uid" => WP_RW__SITE_PUBLIC_KEY);
            $queries = array();
            foreach ($types as $type => $type_data) {
                if (isset($instance["show_{$type}"]) && $instance["show_{$type}"] && $instance["{$type}_count"] > 0) {
                    $options = ratingwidget()->GetOption($type_data["options"]);
                    $queries[$type] = array("rclasses" => $type_data["classes"], "votes" => max(1, (int) $instance["{$type}_min_votes"]), "orderby" => $instance["{$type}_orderby"], "order" => $instance["{$type}_order"], "limit" => (int) $instance["{$type}_count"], "types" => isset($options->type) ? $options->type : "star");
                    $since_created = isset($instance["{$type}_since_created"]) ? (int) $instance["{$type}_since_created"] : WP_RW__TIME_ALL_TIME;
                    // since_created should be at least 24 hours (86400 seconds), skip otherwise.
                    if ($since_created >= WP_RW__TIME_24_HOURS_IN_SEC) {
                        $time = current_time('timestamp', true) - $since_created;
                        // c: ISO 8601 full date/time, e.g.: 2004-02-12T15:19:21+00:00
                        $queries[$type]['since_created'] = date('c', $time);
                    }
                }
            }
            $details["queries"] = urlencode(json_encode($queries));
            $rw_ret_obj = ratingwidget()->RemoteCall("action/query/ratings.php", $details, WP_RW__CACHE_TIMEOUT_TOP_RATED);
            if (false === $rw_ret_obj) {
                return;
            }
            $rw_ret_obj = json_decode($rw_ret_obj);
            if (null === $rw_ret_obj || true !== $rw_ret_obj->success) {
                return;
            }
            $title = empty($instance['title']) ? __('Top Rated', WP_RW__ID) : apply_filters('widget_title', $instance['title']);
            $titleMaxLength = isset($instance['title_max_length']) && is_numeric($instance['title_max_length']) ? (int) $instance['title_max_length'] : 30;
            $empty = true;
            $toprated_data = new stdClass();
            $toprated_data->id = rand(1, 100);
            $toprated_data->title = array('label' => $title, 'show' => true, 'before' => $this->EncodeHtml($before_title), 'after' => $this->EncodeHtml($after_title));
            $toprated_data->options = array('align' => 'vertical', 'direction' => 'ltr', 'html' => array('before' => $this->EncodeHtml($before_widget), 'after' => $this->EncodeHtml($after_widget)));
            $toprated_data->site = array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST'], 'type' => 'WordPress');
            $toprated_data->itemGroups = array();
            if (count($rw_ret_obj->data) > 0) {
                foreach ($rw_ret_obj->data as $type => $ratings) {
                    if (is_array($ratings) && count($ratings) > 0) {
                        $item_group = new stdClass();
                        $item_group->type = $type;
                        $item_group->title = $instance["{$type}_title"];
                        $item_group->showTitle = 1 === $instance["show_{$type}_title"] && '' !== trim($item_group->title);
                        if (is_numeric($instance["{$type}_style"])) {
                            switch ($instance["{$type}_style"]) {
                                case 0:
                                    $instance["{$type}_style"] = 'legacy';
                                    break;
                                case 1:
                                default:
                                    $instance["{$type}_style"] = 'thumbs';
                                    break;
                            }
                        }
                        $item_group->style = $instance["{$type}_style"];
                        $item_group->options = array('title' => array('maxLen' => $titleMaxLength));
                        $item_group->items = array();
                        $has_thumb = strtolower($instance["{$type}_style"]) !== 'legacy';
                        $thumb_width = 160;
                        $thumb_height = 100;
                        if ($has_thumb) {
                            switch ($instance["{$type}_style"]) {
                                case '2':
                                case 'compact_thumbs':
                                    $thumb_width = 50;
                                    $thumb_height = 40;
                                    break;
                                case '1':
                                case 'thumbs':
                                default:
                                    $thumb_width = 160;
                                    $thumb_height = 100;
                                    break;
                            }
                            $item_group->options['thumb'] = array('width' => $thumb_width, 'height' => $thumb_height);
                        }
                        $cell = 0;
                        foreach ($ratings as $rating) {
                            $urid = $rating->urid;
                            $rclass = $types[$type]["rclass"];
                            $rclasses[$rclass] = true;
                            $extension_type = false;
                            if (RWLogger::IsOn()) {
                                RWLogger::Log('HANDLED_ITEM', 'Urid = ' . $urid . '; Class = ' . $rclass . ';');
                            }
                            if ('posts' === $type || 'pages' === $type) {
                                $post = null;
                                $id = RatingWidgetPlugin::Urid2PostId($urid);
                                $status = @get_post_status($id);
                                if (false === $status) {
                                    if (RWLogger::IsOn()) {
                                        RWLogger::Log('POST_NOT_EXIST', $id);
                                    }
                                    // Post not exist.
                                    continue;
                                } else {
                                    if ('publish' !== $status && 'private' !== $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('POST_NOT_VISIBLE', 'status = ' . $status);
                                        }
                                        // Post not yet published.
                                        continue;
                                    } else {
                                        if ('private' === $status && !is_user_logged_in()) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('RatingWidgetPlugin_TopRatedWidget::widget', 'POST_PRIVATE && USER_LOGGED_OUT');
                                            }
                                            // Private post but user is not logged in.
                                            continue;
                                        }
                                    }
                                }
                                $post = @get_post($id);
                                $title = trim(strip_tags($post->post_title));
                                $permalink = get_permalink($post->ID);
                            } else {
                                if ('comments' === $type) {
                                    $comment = null;
                                    $id = RatingWidgetPlugin::Urid2CommentId($urid);
                                    $status = @wp_get_comment_status($id);
                                    if (false === $status) {
                                        if (RWLogger::IsOn()) {
                                            RWLogger::Log('COMMENT_NOT_EXIST', $id);
                                        }
                                        // Comment not exist.
                                        continue;
                                    } else {
                                        if ('approved' !== $status) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('COMMENT_NOT_VISIBLE', 'status = ' . $status);
                                            }
                                            // Comment not approved.
                                            continue;
                                        }
                                    }
                                    $comment = @get_comment($id);
                                    $title = trim(strip_tags($comment->comment_content));
                                    $permalink = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
                                } else {
                                    if ('activity_updates' === $type || 'activity_comments' === $type) {
                                        $id = RatingWidgetPlugin::Urid2ActivityId($urid);
                                        $activity = new bp_activity_activity($id);
                                        if (!is_object($activity)) {
                                            if (RWLogger::IsOn()) {
                                                RWLogger::Log('BP_ACTIVITY_NOT_EXIST', $id);
                                            }
                                            // Activity not exist.
                                            continue;
                                        } else {
                                            if (!empty($activity->is_spam)) {
                                                if (RWLogger::IsOn()) {
                                                    RWLogger::Log('BP_ACTIVITY_NOT_VISIBLE (SPAM or TRASH)');
                                                }
                                                // Activity marked as SPAM or TRASH.
                                                continue;
                                            } else {
                                                if (!empty($activity->hide_sitewide)) {
                                                    if (RWLogger::IsOn()) {
                                                        RWLogger::Log('BP_ACTIVITY_HIDE_SITEWIDE');
                                                    }
                                                    // Activity marked as hidden in site.
                                                    continue;
                                                }
                                            }
                                        }
                                        $title = trim(strip_tags($activity->content));
                                        $permalink = bp_activity_get_permalink($id);
                                    } else {
                                        if ('users' === $type) {
                                            $id = RatingWidgetPlugin::Urid2UserId($urid);
                                            if ($bpInstalled) {
                                                $title = trim(strip_tags(bp_core_get_user_displayname($id)));
                                                $permalink = bp_core_get_user_domain($id);
                                            } else {
                                                if ($bbInstalled) {
                                                    $title = trim(strip_tags(bbp_get_user_display_name($id)));
                                                    $permalink = bbp_get_user_profile_url($id);
                                                } else {
                                                    continue;
                                                }
                                            }
                                        } else {
                                            if ('forum_posts' === $type || 'forum_replies' === $type) {
                                                $id = RatingWidgetPlugin::Urid2ForumPostId($urid);
                                                if (function_exists('bp_forums_get_post')) {
                                                    $forum_post = @bp_forums_get_post($id);
                                                    if (!is_object($forum_post)) {
                                                        continue;
                                                    }
                                                    $title = trim(strip_tags($forum_post->post_text));
                                                    $page = bb_get_page_number($forum_post->post_position);
                                                    $permalink = get_topic_link($id, $page) . "#post-{$id}";
                                                } else {
                                                    if (function_exists('bbp_get_reply_id')) {
                                                        $forum_item = bbp_get_topic();
                                                        if (is_object($forum_item)) {
                                                            $is_topic = true;
                                                        } else {
                                                            $is_topic = false;
                                                            $forum_item = bbp_get_reply($id);
                                                            if (!is_object($forum_item)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_FORUM_ITEM_NOT_EXIST', $id);
                                                                }
                                                                // Invalid id (no topic nor reply).
                                                                continue;
                                                            }
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_IS_TOPIC_REPLY', $is_topic ? 'FALSE' : 'TRUE');
                                                            }
                                                        }
                                                        // Visible statueses: Public or Closed.
                                                        $visible_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id());
                                                        if (!in_array($forum_item->post_status, $visible_statuses)) {
                                                            if (RWLogger::IsOn()) {
                                                                RWLogger::Log('BBP_FORUM_ITEM_HIDDEN', $forum_item->post_status);
                                                            }
                                                            // Item is not public nor closed.
                                                            continue;
                                                        }
                                                        $is_reply = !$is_topic;
                                                        if ($is_reply) {
                                                            // Get parent topic.
                                                            $forum_topic = bbp_get_topic($forum_post->post_parent);
                                                            if (!in_array($forum_topic->post_status, $visible_statuses)) {
                                                                if (RWLogger::IsOn()) {
                                                                    RWLogger::Log('BBP_PARENT_FORUM_TOPIC_IS_HIDDEN', 'TRUE');
                                                                }
                                                                // Parent topic is not public nor closed.
                                                                continue;
                                                            }
                                                        }
                                                        $title = trim(strip_tags($forum_post->post_title));
                                                        $permalink = get_permalink($forum_post->ID);
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                                $types[$type]['handler']->GetElementInfoByRating();
                                            } else {
                                                $found_handler = false;
                                                $extensions = ratingwidget()->GetExtensions();
                                                foreach ($extensions as $ext) {
                                                    $result = $ext->GetElementInfoByRating($type, $rating);
                                                    if (false !== $result) {
                                                        $found_handler = true;
                                                        break;
                                                    }
                                                }
                                                if ($found_handler) {
                                                    $id = $result['id'];
                                                    $title = $result['title'];
                                                    $permalink = $result['permalink'];
                                                    $img = rw_get_thumb_url($result['img'], $thumb_width, $thumb_height, $result['permalink']);
                                                    $extension_type = true;
                                                } else {
                                                    continue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            $queued = ratingwidget()->QueueRatingData($urid, "", "", $rclass);
                            // Override rating class in case the same rating has already been queued with a different rclass.
                            $rclass = $queued['rclass'];
                            $short = mb_strlen($title) > $titleMaxLength ? trim(mb_substr($title, 0, $titleMaxLength)) . "..." : $title;
                            $item = array('site' => array('id' => WP_RW__SITE_ID, 'domain' => $_SERVER['HTTP_HOST']), 'page' => array('externalID' => $id, 'url' => $permalink, 'title' => $short), 'rating' => array('localID' => $urid, 'options' => array('rclass' => $rclass)));
                            // Add thumb url.
                            if ($extension_type && is_string($img)) {
                                $item['page']['img'] = $img;
                            } else {
                                if ($has_thumb && in_array($type, array('posts', 'pages'))) {
                                    $item['page']['img'] = rw_get_post_thumb_url($post, $thumb_width, $thumb_height);
                                }
                            }
                            $item_group->items[] = $item;
                            $cell++;
                            $empty = false;
                        }
                        $toprated_data->itemGroups[] = $item_group;
                    }
                }
            }
            if (true === $empty) {
                //            echo '<p style="margin: 0;">There are no rated items for this period.</p>';
                //        echo $before_widget;
                //        echo $after_widget;
            } else {
                // Set a flag that the widget is loaded.
                ratingwidget()->TopRatedWidgetLoaded();
                ?>
					<b class="rw-ui-recommendations" data-id="<?php 
                echo $toprated_data->id;
                ?>
"></b>
					<script type="text/javascript">
						var _rwq = _rwq || [];
						_rwq.push(['_setRecommendations', <?php 
                echo json_encode($toprated_data);
                ?>
]);
					</script>
				<?php 
            }
        }
Пример #8
0
 public function rw_display_activity_comment_rating($comment_content)
 {
     if (RWLogger::IsOn()) {
         $params = func_get_args();
         RWLogger::LogEnterence('rw_display_activity_comment_rating', $params);
     }
     // If this is a newly inserted comment, assign it to $this->current_comment
     if (isset($_POST['action']) && 'new_activity_comment' == $_POST['action']) {
         global $activities_template;
         $current_comment = $activities_template->activity->current_comment;
         $parent_comment = $activities_template->activity_parents[$current_comment->item_id];
         $current_comment->parent = $parent_comment;
         $this->current_comment = $parent_comment;
         $this->current_comment->children = array($current_comment->id => $current_comment);
     }
     if (!isset($this->current_comment) || null === $this->current_comment) {
         if (RWLogger::IsOn()) {
             RWLogger::Log('rw_display_activity_comment_rating', 'Current comment is not set.');
         }
         return $comment_content;
     }
     // Find current comment.
     while (!$this->current_comment->children || false === current($this->current_comment->children)) {
         $this->current_comment = $this->current_comment->parent;
         next($this->current_comment->children);
     }
     $parent = $this->current_comment;
     $this->current_comment = current($this->current_comment->children);
     $this->current_comment->parent = $parent;
     /*
     // Check if comment rating isn't specifically excluded.
     if (false === $this->rw_validate_visibility($this->current_comment->id, "activity-comment"))
         return $comment_content;
     
     // Get activity comment user-rating-id.
     $comment_urid = $this->_getActivityRatingGuid($this->current_comment->id);
     
     // Queue activity-comment rating.
     $this->QueueRatingData($comment_urid, strip_tags($this->current_comment->content), bp_activity_get_permalink($this->current_comment->id), "activity-comment");
     
     $rw = '<div class="rw-' . $this->activity_align["activity-comment"]->hor . '"><div class="rw-ui-container rw-class-activity-comment rw-urid-' . $comment_urid . '"></div></div><p></p>';
     */
     $options = array();
     // Add accumulator id if user accumulated rating.
     if ($this->IsUserAccumulatedRating()) {
         $options['uarid'] = $this->_getUserRatingGuid($this->current_comment->user_id);
     }
     $rw = $this->EmbedRatingIfVisible($this->current_comment->id, $this->current_comment->user_id, strip_tags($this->current_comment->content), bp_activity_get_permalink($this->current_comment->id), 'activity-comment', false, $this->activity_align['activity-comment']->hor, false, $options, false);
     // Attach rating html container.
     return $this->activity_align['activity-comment']->ver == 'top' ? $rw . $comment_content : $comment_content . $rw;
 }
Пример #9
0
/**
 * Return the activity latest update link.
 *
 * @since BuddyPress (1.2.0)
 *
 * @uses bp_is_user_inactive()
 * @uses bp_core_is_user_deleted()
 * @uses bp_get_user_meta()
 * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook
 * @uses bp_create_excerpt()
 * @uses bp_get_root_domain()
 * @uses bp_get_activity_root_slug()
 * @uses apply_filters() To call the 'bp_get_activity_latest_update' hook
 *
 * @param int $user_id If empty, will fall back on displayed user.
 * @return string|bool $latest_update The activity latest update link.
 *         False on failure
 */
function bp_get_activity_latest_update($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = bp_displayed_user_id();
    }
    if (bp_is_user_inactive($user_id)) {
        return false;
    }
    if (!($update = bp_get_user_meta($user_id, 'bp_latest_update', true))) {
        return false;
    }
    /**
     * Filters the latest update excerpt.
     *
     * @since BuddyPress (1.2.10)
     *
     * @param string $value The excerpt for the latest update.
     */
    $latest_update = apply_filters('bp_get_activity_latest_update_excerpt', trim(strip_tags(bp_create_excerpt($update['content'], 358))));
    $latest_update = sprintf('%s <a href="%s">%s</a>', $latest_update, esc_url_raw(bp_activity_get_permalink($update['id'])), esc_attr__('View', 'buddypress'));
    /**
     * Filters the latest update excerpt with view link appended to the end.
     *
     * @since BuddyPress (1.2.0)
     *
     * @param string $latest_update The latest update with "view" link appended to it.
     */
    return apply_filters('bp_get_activity_latest_update', $latest_update);
}
Пример #10
0
/**
 * bp_like_add_user_like()
 *
 * Registers that the user likes a given item.
 *
 */
function bp_like_add_user_like($item_id = '', $type = 'activity')
{
    global $bp;
    if (!$item_id) {
        return false;
    }
    if (!$user_id) {
        $user_id = $bp->loggedin_user->id;
    }
    if ($user_id == 0) {
        echo bp_like_get_text('must_be_logged_in');
        return false;
    }
    if ($type == 'activity') {
        /* Add to the users liked activities. */
        $user_likes = get_user_meta($user_id, 'bp_liked_activities', true);
        $user_likes[$item_id] = 'activity_liked';
        update_user_meta($user_id, 'bp_liked_activities', $user_likes);
        /* Add to the total likes for this activity. */
        $users_who_like = bp_activity_get_meta($item_id, 'liked_count', true);
        $users_who_like[$user_id] = 'user_likes';
        bp_activity_update_meta($item_id, 'liked_count', $users_who_like);
        $liked_count = count($users_who_like);
        /* Publish to the activity stream if we're allowed to. */
        if (bp_like_get_settings('post_to_activity_stream') == 1) {
            $activity = bp_activity_get_specific(array('activity_ids' => $item_id, 'component' => 'bp-like'));
            $author_id = $activity['activities'][0]->user_id;
            if ($user_id == $author_id) {
                $action = bp_like_get_text('record_activity_likes_own');
            } elseif ($user_id == 0) {
                $action = bp_like_get_text('record_activity_likes_an');
            } else {
                $action = bp_like_get_text('record_activity_likes_users');
            }
            $liker = bp_core_get_userlink($user_id);
            $author = bp_core_get_userlink($author_id);
            $activity_url = bp_activity_get_permalink($item_id);
            /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
            if (bp_like_get_settings('show_excerpt') == 1) {
                $content = $activity['activities'][0]->content;
                if (strlen($content) > bp_like_get_settings('excerpt_length')) {
                    $content = substr($content, 0, bp_like_get_settings('excerpt_length'));
                    $content = $content . '...';
                }
            }
            /* Filter out the placeholders */
            $action = str_replace('%user%', $liker, $action);
            $action = str_replace('%permalink%', $activity_url, $action);
            $action = str_replace('%author%', $author, $action);
            bp_activity_add(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id, 'item_id' => $item_id));
        }
    } elseif ($type == 'blogpost') {
        /* Add to the users liked blog posts. */
        $user_likes = get_user_meta($user_id, 'bp_liked_blogposts', true);
        $user_likes[$item_id] = 'blogpost_liked';
        update_user_meta($user_id, 'bp_liked_blogposts', $user_likes);
        /* Add to the total likes for this blog post. */
        $users_who_like = get_post_meta($item_id, 'liked_count', true);
        $users_who_like[$user_id] = 'user_likes';
        update_post_meta($item_id, 'liked_count', $users_who_like);
        $liked_count = count($users_who_like);
        if (bp_like_get_settings('post_to_activity_stream') == 1) {
            $post = get_post($item_id);
            $author_id = $post->post_author;
            $liker = bp_core_get_userlink($user_id);
            $permalink = get_permalink($item_id);
            $title = $post->post_title;
            $author = bp_core_get_userlink($post->post_author);
            if ($user_id == $author_id) {
                $action = bp_like_get_text('record_activity_likes_own_blogpost');
            } elseif ($user_id == 0) {
                $action = bp_like_get_text('record_activity_likes_a_blogpost');
            } else {
                $action = bp_like_get_text('record_activity_likes_users_blogpost');
            }
            /* Filter out the placeholders */
            $action = str_replace('%user%', $liker, $action);
            $action = str_replace('%permalink%', $permalink, $action);
            $action = str_replace('%title%', $title, $action);
            $action = str_replace('%author%', $author, $action);
            /* Grab the content and make it into an excerpt of 140 chars if we're allowed */
            if (bp_like_get_settings('show_excerpt') == 1) {
                $content = $post->post_content;
                if (strlen($content) > bp_like_get_settings('excerpt_length')) {
                    $content = substr($content, 0, bp_like_get_settings('excerpt_length'));
                    $content = $content . '...';
                }
            }
            bp_activity_add(array('action' => $action, 'content' => $content, 'component' => 'bp-like', 'type' => 'blogpost_liked', 'user_id' => $user_id, 'item_id' => $item_id, 'primary_link' => $permalink));
        }
    }
    echo bp_like_get_text('unlike');
    if ($liked_count) {
        echo ' (' . $liked_count . ')';
    }
}
Пример #11
0
/**
 * Return the activity comment permalink.
 *
 * @since BuddyPress (1.8)
 *
 * @uses bp_activity_get_permalink()
 * @uses apply_filters() To call the 'bp_get_activity_comment_permalink' hook.
 *
 * @return string $link The activity comment permalink.
 */
function bp_get_activity_comment_permalink()
{
    global $activities_template;
    // Check that comment exists
    $comment_id = isset($activities_template->activity->current_comment->id) ? $activities_template->activity->current_comment->id : 0;
    // Setup the comment link
    $comment_link = !empty($comment_id) ? '#acomment-' . $comment_id : false;
    // Append comment ID to end of activity permalink
    $link = bp_activity_get_permalink($activities_template->activity->id, $activities_template->activity) . $comment_link;
    return apply_filters('bp_get_activity_comment_permalink', $link, $comment_id);
}
/**
 * Return the activity comment permalink.
 *
 * @since BuddyPress (1.8)
 *
 * @uses bp_activity_get_permalink()
 * @uses apply_filters() To call the 'bp_get_activity_comment_permalink' hook.
 *
 * @return string $link The activity comment permalink.
 */
function bp_get_activity_comment_permalink()
{
    global $activities_template;
    $link = bp_activity_get_permalink($activities_template->activity->id, $activities_template->activity) . '#acomment-' . $activities_template->activity->current_comment->id;
    return apply_filters('bp_get_activity_comment_permalink', $link);
}
 function process_like_button_code($atts, $content = '')
 {
     global $wp_current_filter;
     // Check allowed
     $allow = $this->data->get_option('wdfb_button', 'allow_facebook_button');
     if (!apply_filters('wdfb-show_facebook_button', $allow)) {
         return '';
     }
     // Check nesting (i.e. posts within post, reformatted with apply_filters)
     $filters = array_count_values($wp_current_filter);
     if (isset($filters['the_content']) && $filters['the_content'] > 1) {
         return '';
     }
     $atts = shortcode_atts(array('forced' => false), $atts);
     $forced = $atts['forced'] && 'no' != $atts['forced'] ? true : false;
     $in_types = $this->data->get_option('wdfb_button', 'not_in_post_types');
     $in_types = is_array($in_types) ? $in_types : array();
     $post_type = get_post_type();
     if ($post_type && in_array(get_post_type(), $in_types) && !$forced) {
         return '';
     }
     $is_activity = defined('BP_VERSION') && isset($filters['bp_get_activity_content_body']);
     if ($is_activity && !@in_array('_buddypress_activity', $in_types)) {
         return '';
     }
     // Reverse logic for BuddyPress Activity check.
     $send = $this->data->get_option('wdfb_button', 'show_send_button');
     $layout = $this->data->get_option('wdfb_button', 'button_appearance');
     $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     /*
     		$width = ("standard" == $layout) ? 300 : (
     			("button_count" == $layout) ? 150 : 60
     		);
     */
     $width = 450;
     $width = apply_filters('wdfb-like_button-width', $width);
     $scheme = $this->data->get_option('wdfb_button', 'color_scheme');
     $scheme = $scheme ? $scheme : 'light';
     if (is_home() && $this->data->get_option('wdfb_button', 'show_on_front_page') || is_archive() && $this->data->get_option('wdfb_button', 'show_on_archive_page') || defined('BP_VERSION') && $is_activity && !wdfb_is_single_bp_activity()) {
         $tmp_url = $is_activity && function_exists('bp_activity_get_permalink') ? bp_activity_get_permalink(bp_get_activity_id()) : (in_the_loop() ? get_permalink() : false);
         $href = !empty($tmp_url) ? $tmp_url : $url;
         $locale = wdfb_get_locale();
         $height = "box_count" == $layout ? 60 : 25;
         $height = apply_filters('wdfb-like_button-height', $height);
         $use_xfbml = false;
         if (defined('BP_VERSION') && $is_activity && !wdfb_is_single_bp_activity() && $this->data->get_option('wdfb_button', 'bp_activity_xfbml') || is_home() && $this->data->get_option('wdfb_button', 'show_on_front_page') && $this->data->get_option('wdfb_button', 'shared_pages_use_xfbml') || is_archive() && $this->data->get_option('wdfb_button', 'show_on_archive_page') && $this->data->get_option('wdfb_button', 'shared_pages_use_xfbml')) {
             $use_xfbml = true;
         }
         $href = apply_filters('wdfb-like_button-href_attribute', WDFB_PROTOCOL . preg_replace('/^https?:\\/\\//', '', $href));
         return $use_xfbml ? '<div class="wdfb_like_button">' . wdfb_get_fb_plugin_markup('like', compact(array('href', 'send', 'layout', 'width', 'scheme'))) . '</div>' : "<div class='wdfb_like_button'><iframe src='http://www.facebook.com/plugins/like.php?&amp;href=" . rawurlencode($href) . "&amp;send=false&amp;layout={$layout}&amp;show_faces=false&amp;action=like&amp;colorscheme={$scheme}&amp;font&amp;height={$height}&amp;width={$width}&amp;locale={$locale}' scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:{$height}px; width:{$width}px;' allowTransparency='true'></iframe></div>";
     }
     $href = apply_filters('wdfb-like_button-href_attribute', WDFB_PROTOCOL . preg_replace('/^https?:\\/\\//', '', $url));
     return '<div class="wdfb_like_button">' . wdfb_get_fb_plugin_markup('like', compact(array('href', 'send', 'layout', 'width', 'scheme'))) . '</div>';
 }
Пример #14
0
/**
 * Adds anchor to an activity comment's "View" link.
 *
 * Who likes scrolling all the way down the page to find their comment!
 *
 * @since 1.0-beta
 */
function bp_rbe_activity_comment_view_link($link, $activity)
{
    if ($activity->type == 'activity_comment') {
        $action = apply_filters_ref_array('bp_get_activity_action_pre_meta', array($activity->action, &$activity, array('no_timestamp' => false)));
        $time_since = apply_filters_ref_array('bp_activity_time_since', array('<span class="time-since">' . bp_core_time_since($activity->date_recorded) . '</span>', &$activity));
        return $action . ' <a href="' . bp_activity_get_permalink($activity->id) . '#acomment-' . $activity->id . '" class="view activity-time-since" title="' . __('View Discussion', 'buddypress') . '">' . $time_since . '</a>';
    }
    return $link;
}
/**
 * Sends an email notification and a BP notification when someone mentions you in an update
 *
 * @since BuddyPress (1.2)
 *
 * @param int $comment_id The comment id
 * @param int $commenter_id The unique user_id of the user who posted the comment
 * @param array $params {@link bp_activity_new_comment()}
 *
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses wp_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_get_root_blog_id()
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook
 * @uses wp_mail()
 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook
 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook
 */
function bp_activity_new_comment_notification($comment_id, $commenter_id, $params)
{
    // Set some default parameters
    $activity_id = 0;
    $parent_id = 0;
    extract($params);
    $original_activity = new BP_Activity_Activity($activity_id);
    if ($original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta($original_activity->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($original_activity->user_id) . $settings_slug . '/notifications/';
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        // Set up and send the message
        $ud = bp_core_get_core_userdata($original_activity->user_id);
        $to = $ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('%s replied to one of your updates', 'buddypress'), $poster_name)));
        $message = sprintf(__('%1$s replied to one of your updates:

"%2$s"

To view your original update and all comments, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        // Only show the disable notifications line if the settings component is enabled
        if (bp_is_active('settings')) {
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        }
        /* Send the message */
        $to = apply_filters('bp_activity_new_comment_notification_to', $to);
        $subject = apply_filters('bp_activity_new_comment_notification_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link);
        wp_mail($to, $subject, $message);
        do_action('bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
    /***
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if (empty($parent_id) || $activity_id == $parent_id) {
        return false;
    }
    $parent_comment = new BP_Activity_Activity($parent_id);
    if ($parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta($parent_comment->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($parent_comment->user_id) . $settings_slug . '/notifications/';
        // Set up and send the message
        $ud = bp_core_get_core_userdata($parent_comment->user_id);
        $to = $ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('%s replied to one of your comments', 'buddypress'), $poster_name)));
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        $message = sprintf(__('%1$s replied to one of your comments:

"%2$s"

To view the original activity, your comment and all replies, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        // Only show the disable notifications line if the settings component is enabled
        if (bp_is_active('settings')) {
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        }
        /* Send the message */
        $to = apply_filters('bp_activity_new_comment_notification_comment_author_to', $to);
        $subject = apply_filters('bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link);
        wp_mail($to, $subject, $message);
        do_action('bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
}
 /**
  * Build a data package for the Akismet service to inspect
  *
  * @param BP_Activity_Activity $activity
  * @see http://akismet.com/development/api/#comment-check
  * @since BuddyPress (1.6)
  * @static
  */
 public static function build_akismet_data_package($activity)
 {
     $userdata = get_userdata($activity->user_id);
     $activity_data = array();
     $activity_data['akismet_comment_nonce'] = 'inactive';
     $activity_data['comment_author'] = $userdata->display_name;
     $activity_data['comment_author_email'] = $userdata->user_email;
     $activity_data['comment_author_url'] = bp_core_get_userlink($userdata->ID, false, true);
     $activity_data['comment_content'] = $activity->content;
     $activity_data['comment_type'] = $activity->type;
     $activity_data['permalink'] = bp_activity_get_permalink($activity->id, $activity);
     $activity_data['user_ID'] = $userdata->ID;
     $activity_data['user_role'] = akismet_get_user_roles($userdata->ID);
     /**
      * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
      * This helps Akismet ensure that the update was a valid form submission.
      */
     if (!empty($_POST['_bp_as_nonce'])) {
         $activity_data['akismet_comment_nonce'] = wp_verify_nonce($_POST['_bp_as_nonce'], "_bp_as_nonce_{$userdata->ID}") ? 'passed' : 'failed';
     } elseif (!empty($activity->secondary_item_id) && !empty($_POST['_bp_as_nonce_' . $activity->secondary_item_id])) {
         $activity_data['akismet_comment_nonce'] = wp_verify_nonce($_POST["_bp_as_nonce_{$activity->secondary_item_id}"], "_bp_as_nonce_{$userdata->ID}_{$activity->secondary_item_id}") ? 'passed' : 'failed';
     }
     return apply_filters('bp_akismet_build_akismet_data_package', $activity_data, $activity);
 }
Пример #17
0
/**
 * Create WP ULike BuddyPress Logs page with separate pagination
 *
 * @author       	Alimir	 	
 * @since           1.7
 * @updated         2.1	
 * @return			String
 */
function wp_ulike_buddypress_likes_logs()
{
    global $wpdb;
    $alternate = true;
    $items = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->prefix . "ulike_activities");
    if ($items > 0) {
        $p = new pagination();
        $p->items($items);
        $p->limit(wp_ulike_logs_return_per_page());
        // Limit entries per page
        $p->target("admin.php?page=wp-ulike-bp-logs");
        $p->calculate();
        // Calculates what to show
        $p->parameterName('page_number');
        $p->adjacents(1);
        //No. of page away from the current page
        if (!isset($_GET['page_number'])) {
            $p->page = 1;
        } else {
            $p->page = $_GET['page_number'];
        }
        //Query for limit page_number
        $limit = "LIMIT " . ($p->page - 1) * $p->limit . ", " . $p->limit;
        $get_ulike_logs = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ulike_activities ORDER BY id DESC " . $limit . "");
        ?>
		<div class="wrap">
			<h2><?php 
        _e('WP ULike Logs', 'alimir');
        ?>
</h2>
			<h3><?php 
        _e('Activity Likes Logs', 'alimir');
        ?>
</h3>
			<div class="tablenav">
				<div class='tablenav-pages'>
					<span class="displaying-num"><?php 
        echo $items . ' ' . __('Logs', 'alimir');
        ?>
</span>
					<?php 
        echo $p->show();
        // Echo out the list of paging.
        ?>
				</div>
			</div>
			<table class="widefat">
				<thead>
					<tr>
						<th width="3%"><?php 
        _e('ID', 'alimir');
        ?>
</th>
						<th width="13%"><?php 
        _e('Username', 'alimir');
        ?>
</th>
						<th><?php 
        _e('Status', 'alimir');
        ?>
</th>
						<th width="6%"><?php 
        _e('Activity ID', 'alimir');
        ?>
</th>
						<th><?php 
        _e('Permalink', 'alimir');
        ?>
</th>
						<th><?php 
        _e('Date / Time', 'alimir');
        ?>
</th>
						<th><?php 
        _e('IP', 'alimir');
        ?>
</th>
						<th><?php 
        _e('Actions', 'alimir');
        ?>
</th>	
					</tr>
				</thead>
				<tbody>
					<?php 
        foreach ($get_ulike_logs as $get_ulike_log) {
            ?>
					<tr <?php 
            if ($alternate == true) {
                echo 'class="alternate"';
            }
            ?>
>
					<td>
					<?php 
            echo $get_ulike_log->id;
            ?>
					</td>
					<td>
					<?php 
            $user_info = get_userdata($get_ulike_log->user_id);
            if ($user_info) {
                echo get_avatar($user_info->user_email, 16, '', 'avatar') . '<em> @' . $user_info->user_login . '</em>';
            } else {
                echo '<em> #' . __('Guest User', 'alimir') . '</em>';
            }
            ?>
					</td>
					<td>
					<?php 
            $get_the_status = $get_ulike_log->status;
            if ($get_the_status == 'like') {
                echo '<img src="' . plugin_dir_url(__FILE__) . '/classes/img/like.png" alt="like" width="24"/>';
            } else {
                echo '<img src="' . plugin_dir_url(__FILE__) . '/classes/img/unlike.png" alt="unlike" width="24"/>';
            }
            ?>
					</td>
					<td>
					<?php 
            echo $get_ulike_log->activity_id;
            ?>
					</td>
					<td>
					<?php 
            printf(__('<a href="%1$s">Activity Permalink</a>', 'alimir'), bp_activity_get_permalink($get_ulike_log->activity_id));
            ?>
					</td>
					<td>
					<?php 
            echo wp_ulike_date_i18n($get_ulike_log->date_time);
            ?>
					</td>
					<td>
					<?php 
            echo $get_ulike_log->ip;
            ?>
 
					</td>
					<td>
					<button class="wp_ulike_delete button" type="button" data-id="<?php 
            echo $get_ulike_log->id;
            ?>
" data-table="ulike_activities"><i class="dashicons dashicons-trash"></i></button> 
					</td>					
					<?php 
            $alternate = !$alternate;
        }
        ?>
					</tr>
				</tbody>
			</table>
			<div class="tablenav">
				<div class='tablenav-pages'>
					<span class="displaying-num"><?php 
        echo $items . ' ' . __('Logs', 'alimir');
        ?>
</span>
					<?php 
        echo $p->show();
        // Echo out the list of paging.
        ?>
				</div>
			</div>
		</div>	
		
	<?php 
    } else {
        echo "<div class='error'><p>" . __('<strong>ERROR:</strong> No Record Found. (This problem is created because you don\'t have any data on this table)', 'alimir') . "</p></div>";
    }
}
/**
 * Status metabox for the Activity admin edit screen.
 *
 * @since 1.6.0
 *
 * @param object $item Activity item.
 */
function bp_activity_admin_edit_metabox_status($item)
{
    ?>

	<div class="submitbox" id="submitcomment">

		<div id="minor-publishing">
			<div id="minor-publishing-actions">
				<div id="preview-action">
					<a class="button preview" href="<?php 
    echo esc_attr(bp_activity_get_permalink($item->id, $item));
    ?>
" target="_blank"><?php 
    _e('View Activity', 'buddypress');
    ?>
</a>
				</div>

				<div class="clear"></div>
			</div><!-- #minor-publishing-actions -->

			<div id="misc-publishing-actions">
				<div class="misc-pub-section" id="comment-status-radio">
					<label class="approved" for="activity-status-approved"><input type="radio" name="activity_status" id="activity-status-approved" value="ham" <?php 
    checked($item->is_spam, 0);
    ?>
><?php 
    _e('Approved', 'buddypress');
    ?>
</label><br />
					<label class="spam" for="activity-status-spam"><input type="radio" name="activity_status" id="activity-status-spam" value="spam" <?php 
    checked($item->is_spam, 1);
    ?>
><?php 
    _e('Spam', 'buddypress');
    ?>
</label>
				</div>

				<div class="misc-pub-section curtime misc-pub-section-last">
					<?php 
    // Translators: Publish box date format, see http://php.net/date.
    $datef = __('M j, Y @ G:i', 'buddypress');
    $date = date_i18n($datef, strtotime($item->date_recorded));
    ?>
					<span id="timestamp"><?php 
    printf(__('Submitted on: %s', 'buddypress'), '<strong>' . $date . '</strong>');
    ?>
</span>&nbsp;<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php 
    _e('Edit', 'buddypress');
    ?>
</a>

					<div id='timestampdiv' class='hide-if-js'>
						<?php 
    touch_time(1, 0, 5);
    ?>
					</div><!-- #timestampdiv -->
				</div>
			</div> <!-- #misc-publishing-actions -->

			<div class="clear"></div>
		</div><!-- #minor-publishing -->

		<div id="major-publishing-actions">
			<div id="publishing-action">
				<?php 
    submit_button(__('Update', 'buddypress'), 'primary', 'save', false);
    ?>
			</div>
			<div class="clear"></div>
		</div><!-- #major-publishing-actions -->

	</div><!-- #submitcomment -->

<?php 
}
/**
 * Sends an email notification and a BP notification when someone mentions you in an update
 *
 * @since 1.2.0
 *
 * @param int $comment_id The comment id
 * @param int $commenter_id The unique user_id of the user who posted the comment
 * @param array $params {@link bp_activity_new_comment()}
 *
 * @global object $bp BuddyPress global settings
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses nxt_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_get_root_blog_id()
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook
 * @uses nxt_mail()
 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook
 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook
 */
function bp_activity_new_comment_notification($comment_id, $commenter_id, $params)
{
    global $bp;
    extract($params);
    $original_activity = new BP_Activity_Activity($activity_id);
    if ($original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta($original_activity->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($original_activity->user_id) . $settings_slug . '/notifications/';
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        // Set up and send the message
        $ud = bp_core_get_core_userdata($original_activity->user_id);
        $to = $ud->user_email;
        $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
        $subject = '[' . $sitename . '] ' . sprintf(__('%s replied to one of your updates', 'buddypress'), $poster_name);
        $message = sprintf(__('%1$s replied to one of your updates:

"%2$s"

To view your original update and all comments, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        /* Send the message */
        $to = apply_filters('bp_activity_new_comment_notification_to', $to);
        $subject = apply_filters('bp_activity_new_comment_notification_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link);
        nxt_mail($to, $subject, $message);
        do_action('bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
    /***
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if ($activity_id == $parent_id) {
        return false;
    }
    $parent_comment = new BP_Activity_Activity($parent_id);
    if ($parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta($parent_comment->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($parent_comment->user_id) . $settings_slug . '/notifications/';
        // Set up and send the message
        $ud = bp_core_get_core_userdata($parent_comment->user_id);
        $to = $ud->user_email;
        $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
        $subject = '[' . $sitename . '] ' . sprintf(__('%s replied to one of your comments', 'buddypress'), $poster_name);
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        $message = sprintf(__('%1$s replied to one of your comments:

"%2$s"

To view the original activity, your comment and all replies, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        /* Send the message */
        $to = apply_filters('bp_activity_new_comment_notification_comment_author_to', $to);
        $subject = apply_filters('bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name);
        $message = apply_filters('bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link);
        nxt_mail($to, $subject, $message);
        do_action('bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
}
/**
 * Send email and BP notifications when an activity item receives a comment.
 *
 * @since 1.2.0
 * @since 2.5.0 Updated to use new email APIs.
 *
 * @param int   $comment_id   The comment id.
 * @param int   $commenter_id The ID of the user who posted the comment.
 * @param array $params       {@link bp_activity_new_comment()}.
 */
function bp_activity_new_comment_notification($comment_id = 0, $commenter_id = 0, $params = array())
{
    $original_activity = new BP_Activity_Activity($params['activity_id']);
    $poster_name = bp_core_get_user_displayname($commenter_id);
    $thread_link = bp_activity_get_permalink($params['activity_id']);
    remove_filter('bp_get_activity_content_body', 'convert_smilies');
    remove_filter('bp_get_activity_content_body', 'wpautop');
    remove_filter('bp_get_activity_content_body', 'bp_activity_truncate_entry', 5);
    /** This filter is documented in bp-activity/bp-activity-template.php */
    $content = apply_filters('bp_get_activity_content_body', $params['content']);
    add_filter('bp_get_activity_content_body', 'convert_smilies');
    add_filter('bp_get_activity_content_body', 'wpautop');
    add_filter('bp_get_activity_content_body', 'bp_activity_truncate_entry', 5);
    if ($original_activity->user_id != $commenter_id) {
        // Send an email if the user hasn't opted-out.
        if ('no' != bp_get_user_meta($original_activity->user_id, 'notification_activity_new_reply', true)) {
            $unsubscribe_args = array('user_id' => $original_activity->user_id, 'notification_type' => 'activity-comment');
            $args = array('tokens' => array('comment.id' => $comment_id, 'commenter.id' => $commenter_id, 'usermessage' => wp_strip_all_tags($content), 'original_activity.user_id' => $original_activity->user_id, 'poster.name' => $poster_name, 'thread.url' => esc_url($thread_link), 'unsubscribe' => esc_url(bp_email_get_unsubscribe_link($unsubscribe_args))));
            bp_send_email('activity-comment', $original_activity->user_id, $args);
        }
        /**
         * Fires at the point that notifications should be sent for activity comments.
         *
         * @since 2.6.0
         *
         * @param BP_Activity_Activity $original_activity The original activity.
         * @param int                  $comment_id        ID for the newly received comment.
         * @param int                  $commenter_id      ID of the user who made the comment.
         * @param array                $params            Arguments used with the original activity comment.
         */
        do_action('bp_activity_sent_reply_to_update_notification', $original_activity, $comment_id, $commenter_id, $params);
    }
    /*
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if (empty($params['parent_id']) || $params['activity_id'] == $params['parent_id']) {
        return;
    }
    $parent_comment = new BP_Activity_Activity($params['parent_id']);
    if ($parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id) {
        // Send an email if the user hasn't opted-out.
        if ('no' != bp_get_user_meta($parent_comment->user_id, 'notification_activity_new_reply', true)) {
            $unsubscribe_args = array('user_id' => $parent_comment->user_id, 'notification_type' => 'activity-comment-author');
            $args = array('tokens' => array('comment.id' => $comment_id, 'commenter.id' => $commenter_id, 'usermessage' => wp_strip_all_tags($content), 'parent-comment-user.id' => $parent_comment->user_id, 'poster.name' => $poster_name, 'thread.url' => esc_url($thread_link), 'unsubscribe' => esc_url(bp_email_get_unsubscribe_link($unsubscribe_args))));
            bp_send_email('activity-comment-author', $parent_comment->user_id, $args);
        }
        /**
         * Fires at the point that notifications should be sent for comments on activity replies.
         *
         * @since 2.6.0
         *
         * @param BP_Activity_Activity $parent_comment The parent activity.
         * @param int                  $comment_id     ID for the newly received comment.
         * @param int                  $commenter_id   ID of the user who made the comment.
         * @param array                $params         Arguments used with the original activity comment.
         */
        do_action('bp_activity_sent_reply_to_reply_notification', $parent_comment, $comment_id, $commenter_id, $params);
    }
}
function ass_digest_format_item($item, $type)
{
    global $ass_email_css;
    $replies = '';
    //load from the cache if it exists
    if ($item_cached = wp_cache_get('digest_item_' . $type . '_' . $item->id, 'ass')) {
        //$item_cached .= "GENERATED FROM CACHE";
        return $item_cached;
    }
    /* Action text - This technique will not translate well */
    // bbPress 2 support
    if (strpos($item->type, 'bbp_') !== false) {
        $action_split = explode(' in the forum', ass_clean_subject_html($item->action));
        // regular group activity items
    } else {
        $action_split = explode(' in the group', ass_clean_subject_html($item->action));
    }
    if ($action_split[1]) {
        $action = $action_split[0];
    } else {
        $action = $item->action;
    }
    $action = ass_digest_filter($action);
    $action = str_replace(' started the forum topic', ' started', $action);
    // won't translate but it's not essential
    $action = str_replace(' posted on the forum topic', ' posted on', $action);
    $action = str_replace(' started the discussion topic', ' started', $action);
    $action = str_replace(' posted on the discussion topic', ' posted on', $action);
    /* Activity timestamp */
    //	$timestamp = strtotime( $item->date_recorded );
    /* Because BuddyPress core set gmt = true, timezone must be added */
    $timestamp = strtotime($item->date_recorded) + date('Z');
    $time_posted = date(get_option('time_format'), $timestamp);
    $date_posted = date(get_option('date_format'), $timestamp);
    // Daily Digest
    if ($type == 'dig') {
        //$item_message = strip_tags( $action ) . ": \n";
        $item_message = "<div {$ass_email_css['item_div']}>";
        $item_message .= "<span {$ass_email_css['item_action']}>" . $action . ": ";
        $item_message .= "<span {$ass_email_css['item_date']}>" . sprintf(__('at %s, %s', 'bp-ass'), $time_posted, $date_posted) . "</span>";
        $item_message .= "</span>\n";
        // activity content
        if (!empty($item->content)) {
            $item_message .= "<br><span {$ass_email_css['item_content']}>" . apply_filters('ass_digest_content', $item->content, $item, $type) . "</span>";
        }
        // view link
        if ($item->type == 'activity_update' || $item->type == 'activity_comment') {
            $item_message .= ' - <a href="' . bp_activity_get_permalink($item->id, $item) . '">' . __('View', 'bp-ass') . '</a>';
        } else {
            $item_message .= ' - <a href="' . $item->primary_link . '">' . __('View', 'bp-ass') . '</a>';
        }
        $item_message .= "</div>\n\n";
        // Weekly summary
    } elseif ($type == 'sum') {
        // count the number of replies
        //
        // commented out for now
        // if we want to bring this back we should use a direct DB query to the
        // wp_bb_topics table and locally cache the value
        /*
        if ( $item->type == 'new_forum_topic' ) {
        	if ( $posts = bp_forums_get_topic_posts( 'per_page=10000&topic_id='. $item->secondary_item_id ) ) {
        		foreach ( $posts as $post ) {
        			$since = time() - strtotime( $post->post_time );
        			if ( $since < 604800 ) //number of seconds in a week
        				$counter++;
        		}
        	}
        	$replies = ' ' . sprintf( __( '(%s replies)', 'bp-ass' ), $counter );
        }
        */
        $item_message = "<div {$ass_email_css['item_div']}>";
        $item_message .= "<span {$ass_email_css['item_action']}>" . $action . ": ";
        $item_message .= "<span {$ass_email_css['item_date']}>" . sprintf(__('at %s, %s', 'bp-ass'), $time_posted, $date_posted) . "</span>";
        $item_message .= "</span>\n";
        // activity content
        if (!empty($item->content)) {
            $item_message .= "<br><span {$ass_email_css['item_content']}>" . apply_filters('ass_digest_content', $item->content, $item, $type) . "</span>";
        }
        // view link
        if ($item->type == 'activity_update' || $item->type == 'activity_comment') {
            $item_message .= ' - <a href="' . bp_activity_get_permalink($item->id, $item) . '">' . __('View', 'bp-ass') . '</a>';
        } else {
            $item_message .= ' - <a href="' . $item->primary_link . '">' . __('View', 'bp-ass') . '</a>';
        }
        $item_message .= "</div>\n\n";
    }
    $item_message = apply_filters('ass_digest_format_item', $item_message, $item, $action, $timestamp, $type, $replies);
    $item_message = ass_digest_filter($item_message);
    // save the cache
    if ($item->id) {
        wp_cache_set('digest_item_' . $type . '_' . $item->id, $item_message, 'ass');
    }
    return $item_message;
}
/**
 * Format notifications related to activity.
 *
 * @since 1.5.0
 *
 * @param string $action            The type of activity item. Just 'new_at_mention' for now.
 * @param int    $item_id           The activity ID.
 * @param int    $secondary_item_id In the case of at-mentions, this is the mentioner's ID.
 * @param int    $total_items       The total number of notifications to format.
 * @param string $format            'string' to get a BuddyBar-compatible notification, 'array' otherwise.
 * @param int    $id                Optional. The notification ID.
 * @return string $return Formatted @mention notification.
 */
function bp_activity_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string', $id = 0)
{
    $action_filter = $action;
    $return = false;
    $activity_id = $item_id;
    $user_id = $secondary_item_id;
    $user_fullname = bp_core_get_user_displayname($user_id);
    switch ($action) {
        case 'new_at_mention':
            $action_filter = 'at_mentions';
            $link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
            $title = sprintf(__('@%s Mentions', 'buddypress'), bp_get_loggedin_user_username());
            $amount = 'single';
            if ((int) $total_items > 1) {
                $text = sprintf(__('You have %1$d new mentions', 'buddypress'), (int) $total_items);
                $amount = 'multiple';
            } else {
                $text = sprintf(__('%1$s mentioned you', 'buddypress'), $user_fullname);
            }
            break;
        case 'update_reply':
            $link = bp_get_notifications_permalink();
            $title = __('New Activity reply', 'buddypress');
            $amount = 'single';
            if ((int) $total_items > 1) {
                $link = add_query_arg('type', $action, $link);
                $text = sprintf(__('You have %1$d new replies', 'buddypress'), (int) $total_items);
                $amount = 'multiple';
            } else {
                $link = add_query_arg('nid', (int) $id, bp_activity_get_permalink($activity_id));
                $text = sprintf(__('%1$s commented on one of your updates', 'buddypress'), $user_fullname);
            }
            break;
        case 'comment_reply':
            $link = bp_get_notifications_permalink();
            $title = __('New Activity comment reply', 'buddypress');
            $amount = 'single';
            if ((int) $total_items > 1) {
                $link = add_query_arg('type', $action, $link);
                $text = sprintf(__('You have %1$d new comment replies', 'buddypress'), (int) $total_items);
                $amount = 'multiple';
            } else {
                $link = add_query_arg('nid', (int) $id, bp_activity_get_permalink($activity_id));
                $text = sprintf(__('%1$s replied to one your activity comments', 'buddypress'), $user_fullname);
            }
            break;
    }
    if ('string' == $format) {
        /**
         * Filters the activity notification for the string format.
         *
         * This is a variable filter that is dependent on how many items
         * need notified about. The two possible hooks are bp_activity_single_at_mentions_notification
         * or bp_activity_multiple_at_mentions_notification.
         *
         * @since 1.5.0
         * @since 2.6.0 use the $action_filter as a new dynamic portion of the filter name.
         *
         * @param string $string          HTML anchor tag for the interaction.
         * @param string $link            The permalink for the interaction.
         * @param int    $total_items     How many items being notified about.
         * @param int    $activity_id     ID of the activity item being formatted.
         * @param int    $user_id         ID of the user who inited the interaction.
         */
        $return = apply_filters('bp_activity_' . $amount . '_' . $action_filter . '_notification', '<a href="' . esc_url($link) . '" title="' . esc_attr($title) . '">' . esc_html($text) . '</a>', $link, (int) $total_items, $activity_id, $user_id);
    } else {
        /**
         * Filters the activity notification for any non-string format.
         *
         * This is a variable filter that is dependent on how many items need notified about.
         * The two possible hooks are bp_activity_single_at_mentions_notification
         * or bp_activity_multiple_at_mentions_notification.
         *
         * @since 1.5.0
         * @since 2.6.0 use the $action_filter as a new dynamic portion of the filter name.
         *
         * @param array  $array           Array holding the content and permalink for the interaction notification.
         * @param string $link            The permalink for the interaction.
         * @param int    $total_items     How many items being notified about.
         * @param int    $activity_id     ID of the activity item being formatted.
         * @param int    $user_id         ID of the user who inited the interaction.
         */
        $return = apply_filters('bp_activity_' . $amount . '_' . $action_filter . '_notification', array('text' => $text, 'link' => $link), $link, (int) $total_items, $activity_id, $user_id);
    }
    /**
     * Fires right before returning the formatted activity notifications.
     *
     * @since 1.2.0
     *
     * @param string $action            The type of activity item.
     * @param int    $item_id           The activity ID.
     * @param int    $secondary_item_id The user ID who inited the interaction.
     * @param int    $total_items       Total amount of items to format.
     */
    do_action('activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items);
    return $return;
}
Пример #23
0
/**
 * Send an email and a BP notification on receipt of an @-mention in a group
 *
 * @deprecated 1.5
 * @deprecated Deprecated in favor of the more general bp_activity_at_message_notification()
 */
function groups_at_message_notification($content, $poster_user_id, $group_id, $activity_id)
{
    global $bp;
    _deprecated_function(__FUNCTION__, '1.5', 'bp_activity_at_message_notification()');
    /* Scan for @username strings in an activity update. Notify each user. */
    $pattern = '/[@]+([A-Za-z0-9-_\\.@]+)/';
    preg_match_all($pattern, $content, $usernames);
    /* Make sure there's only one instance of each username */
    if (!($usernames = array_unique($usernames[1]))) {
        return false;
    }
    $group = new BP_Groups_Group($group_id);
    foreach ((array) $usernames as $username) {
        if (!($receiver_user_id = bp_core_get_userid($username))) {
            continue;
        }
        /* Check the user is a member of the group before sending the update. */
        if (!groups_is_user_member($receiver_user_id, $group_id)) {
            continue;
        }
        // Now email the user with the contents of the message (if they have enabled email notifications)
        if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) {
            $poster_name = bp_core_get_user_displayname($poster_user_id);
            $message_link = bp_activity_get_permalink($activity_id);
            $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
            $settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
            $poster_name = stripslashes($poster_name);
            $content = bp_groups_filter_kses(stripslashes($content));
            // Set up and send the message
            $ud = bp_core_get_core_userdata($receiver_user_id);
            $to = $ud->user_email;
            $sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
            $subject = '[' . $sitename . '] ' . sprintf(__('%1$s mentioned you in the group "%2$s"', 'buddypress'), $poster_name, $group->name);
            $message = sprintf(__('%1$s mentioned you in the group "%2$s":

"%3$s"

To view and respond to the message, log in and visit: %4$s

---------------------
', 'buddypress'), $poster_name, $group->name, $content, $message_link);
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
            /* Send the message */
            $to = apply_filters('groups_at_message_notification_to', $to);
            $subject = apply_filters('groups_at_message_notification_subject', $subject, $group, $poster_name);
            $message = apply_filters('groups_at_message_notification_message', $message, $group, $poster_name, $content, $message_link, $settings_link);
            nxt_mail($to, $subject, $message);
        }
    }
    do_action('bp_groups_sent_mention_email', $usernames, $subject, $message, $content, $poster_user_id, $group_id, $activity_id);
}
/**
 * Send email and BP notifications when an activity item receives a comment.
 *
 * @since 1.2.0
 * @since 2.5.0 Updated to use new email APIs.
 *
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses wp_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_get_root_blog_id()
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook.
 * @uses wp_mail()
 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook.
 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook.
 *
 * @param int   $comment_id   The comment id.
 * @param int   $commenter_id The ID of the user who posted the comment.
 * @param array $params       {@link bp_activity_new_comment()}.
 */
function bp_activity_new_comment_notification($comment_id = 0, $commenter_id = 0, $params = array())
{
    $original_activity = new BP_Activity_Activity($params['activity_id']);
    $poster_name = bp_core_get_user_displayname($commenter_id);
    $thread_link = bp_activity_get_permalink($params['activity_id']);
    remove_filter('bp_get_activity_content_body', 'convert_smilies');
    remove_filter('bp_get_activity_content_body', 'wpautop');
    remove_filter('bp_get_activity_content_body', 'bp_activity_truncate_entry', 5);
    /** This filter is documented in bp-activity/bp-activity-template.php */
    $content = apply_filters('bp_get_activity_content_body', $params['content']);
    add_filter('bp_get_activity_content_body', 'convert_smilies');
    add_filter('bp_get_activity_content_body', 'wpautop');
    add_filter('bp_get_activity_content_body', 'bp_activity_truncate_entry', 5);
    if ($original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta($original_activity->user_id, 'notification_activity_new_reply', true)) {
        $args = array('tokens' => array('comment.id' => $comment_id, 'commenter.id' => $commenter_id, 'usermessage' => wp_strip_all_tags($content), 'original_activity.user_id' => $original_activity->user_id, 'poster.name' => $poster_name, 'thread.url' => esc_url($thread_link)));
        bp_send_email('activity-comment', $original_activity->user_id, $args);
    }
    /*
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if (empty($params['parent_id']) || $params['activity_id'] == $params['parent_id']) {
        return;
    }
    $parent_comment = new BP_Activity_Activity($params['parent_id']);
    if ($parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta($parent_comment->user_id, 'notification_activity_new_reply', true)) {
        $args = array('tokens' => array('comment.id' => $comment_id, 'commenter.id' => $commenter_id, 'usermessage' => wp_strip_all_tags($content), 'parent-comment-user.id' => $parent_comment->user_id, 'poster.name' => $poster_name, 'thread.url' => esc_url($thread_link)));
        bp_send_email('activity-comment-author', $parent_comment->user_id, $args);
    }
}
 /**
  * BuddyPress Activity publishing procedure.
  */
 function publish_bp_activity($content, $user_id, $activity_id)
 {
     $is_particular = (bool) (isset($_POST['wdfb_send_activity']) && $_POST['wdfb_send_activity']);
     if (!$this->data->get_option('wdfb_autopost', 'type_bp_activity_fb_type')) {
         if ($this->data->get_option('wdfb_autopost', 'prevent_bp_activity_switch')) {
             return false;
         }
         if (!$this->data->get_option('wdfb_autopost', 'prevent_bp_activity_switch') && !$is_particular) {
             return false;
         }
     }
     $fb_id = $is_particular ? $this->model->get_fb_user_from_wp($user_id) : $this->data->get_option('wdfb_autopost', 'type_bp_activity_fb_user');
     //$fb_id = $fb_id ? $fb_id : $this->model->fb->getUser(); // No current user fallback - if not caught by WP mapping, no permissions are likely granted.
     if (!$fb_id) {
         return false;
     }
     $post_as = $is_particular ? "feed" : $this->data->get_option('wdfb_autopost', "type_bp_activity_fb_type");
     $post_to = $fb_id;
     $permalink = bp_activity_get_permalink($activity_id);
     $send = array('caption' => substr($content, 0, 999), 'message' => substr($content, 0, 999), 'link' => $permalink, 'name' => __('Activity Update', 'wdfb'), 'description' => get_option('blogdescription'), 'actions' => array('name' => __('Share', 'wdfb'), 'link' => 'http://www.facebook.com/sharer.php?u=' . rawurlencode($permalink)));
     $send = apply_filters('wdfb-autopost-bp_activity_update', $send, $activity_id, $user_id);
     $send = apply_filters('wdfb-autopost-send', $send, $post_as, $post_to);
     // Strip nulled out values
     foreach ($send as $key => $val) {
         if (!$val) {
             unset($send[$key]);
         }
     }
     $res = $this->model->post_on_facebook($post_as, $post_to, $send, false);
     if ($res) {
         bp_activity_update_meta($activity_id, 'wdfb_published_on_fb', 1);
     }
 }
Пример #26
0
function dwqa_replace_activity_meta()
{
    global $activities_template;
    $blog_url = bp_blogs_get_blogmeta($activity->item_id, 'url');
    $blog_name = bp_blogs_get_blogmeta($activity->item_id, 'name');
    if (empty($blog_url) || empty($blog_name)) {
        $blog_url = get_home_url($activity->item_id);
        $blog_name = get_blog_option($activity->item_id, 'blogname');
        bp_blogs_update_blogmeta($activity->item_id, 'url', $blog_url);
        bp_blogs_update_blogmeta($activity->item_id, 'name', $blog_name);
    }
    $post_url = add_query_arg('p', $activities_template->activity->secondary_item_id, trailingslashit($blog_url));
    $post_title = bp_activity_get_meta($activities_template->activity->id, 'post_title');
    if (empty($post_title)) {
        $post = get_post($activities_template->activity->secondary_item_id);
        if (is_a($post, 'WP_Post')) {
            $post_title = $post->post_title;
            bp_activity_update_meta($activities_template->activity->id, 'post_title', $post_title);
        }
    }
    $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
    $user_link = bp_core_get_userlink($activities_template->activity->user_id);
    if ($activities_template->activity->type == 'new_question') {
        $action = sprintf(__('%1$s asked a new question: %2$s', 'dwqa'), $user_link, $post_link);
    } elseif ($activities_template->activity->type == 'new_answer') {
        $action = sprintf(__('%1$s answered the question: %2$s', 'dwqa'), $user_link, $post_link);
    } elseif ($activities_template->activity->type == 'comment_question') {
        $action = sprintf(__('%1$s commented on the question: %2$s', 'dwqa'), $user_link, $post_link);
    } elseif ($activities_template->activity->type == 'comment_answer') {
        $action = sprintf(__('%1$s commented on the answer at: %2$s', 'dwqa'), $user_link, $post_link);
    } else {
        $action = $activities_template->activity->action;
    }
    // Strip any legacy time since placeholders from BP 1.0-1.1
    $content = str_replace('<span class="time-since">%s</span>', '', $content);
    // Insert the time since.
    $time_since = apply_filters_ref_array('bp_activity_time_since', array('<span class="time-since">' . bp_core_time_since($activities_template->activity->date_recorded) . '</span>', &$activities_template->activity));
    // Insert the permalink
    if (!bp_is_single_activity()) {
        $content = apply_filters_ref_array('bp_activity_permalink', array(sprintf('%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink($activities_template->activity->id, $activities_template->activity), esc_attr__('View Discussion', 'buddypress'), $time_since), &$activities_template->activity));
    } else {
        $content .= str_pad($time_since, strlen($time_since) + 2, ' ', STR_PAD_BOTH);
    }
    echo $action . ' ' . $content;
    // echo 'abc';
    // echo $activities_template->activity->content;
}
/**
 * Send email and BP notifications when an activity item receives a comment.
 *
 * @since 1.2.0
 *
 * @uses bp_get_user_meta()
 * @uses bp_core_get_user_displayname()
 * @uses bp_activity_get_permalink()
 * @uses bp_core_get_user_domain()
 * @uses bp_get_settings_slug()
 * @uses bp_activity_filter_kses()
 * @uses bp_core_get_core_userdata()
 * @uses wp_specialchars_decode()
 * @uses get_blog_option()
 * @uses bp_get_root_blog_id()
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook.
 * @uses wp_mail()
 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook.
 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook.
 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook.
 *
 * @param int   $comment_id   The comment id.
 * @param int   $commenter_id The ID of the user who posted the comment.
 * @param array $params       {@link bp_activity_new_comment()}.
 * @return bool
 */
function bp_activity_new_comment_notification($comment_id = 0, $commenter_id = 0, $params = array())
{
    // Set some default parameters.
    $activity_id = 0;
    $parent_id = 0;
    extract($params);
    $original_activity = new BP_Activity_Activity($activity_id);
    if ($original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta($original_activity->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($original_activity->user_id) . $settings_slug . '/notifications/';
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        // Set up and send the message.
        $ud = bp_core_get_core_userdata($original_activity->user_id);
        $to = $ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('%s replied to one of your updates', 'buddypress'), $poster_name)));
        $message = sprintf(__('%1$s replied to one of your updates:

"%2$s"

To view your original update and all comments, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        // Only show the disable notifications line if the settings component is enabled.
        if (bp_is_active('settings')) {
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        }
        /**
         * Filters the user email that the new comment notification will be sent to.
         *
         * @since 1.2.0
         *
         * @param string $to User email the notification is being sent to.
         */
        $to = apply_filters('bp_activity_new_comment_notification_to', $to);
        /**
         * Filters the new comment notification subject that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $subject     Email notification subject text.
         * @param string $poster_name Name of the person who made the comment.
         */
        $subject = apply_filters('bp_activity_new_comment_notification_subject', $subject, $poster_name);
        /**
         * Filters the new comment notification message that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $message       Email notification message text.
         * @param string $poster_name   Name of the person who made the comment.
         * @param string $content       Content of the comment.
         * @param string $thread_link   URL permalink for the activity thread.
         * @param string $settings_link URL permalink for the user's notification settings area.
         */
        $message = apply_filters('bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link);
        wp_mail($to, $subject, $message);
        /**
         * Fires after the sending of a reply to an update email notification.
         *
         * @since 1.5.0
         *
         * @param int    $user_id      ID of the original activity item author.
         * @param string $subject      Email notification subject text.
         * @param string $message      Email notification message text.
         * @param int    $comment_id   ID for the newly received comment.
         * @param int    $commenter_id ID of the user who made the comment.
         * @param array  $params       Arguments used with the original activity comment.
         */
        do_action('bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
    /*
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if (empty($parent_id) || $activity_id == $parent_id) {
        return false;
    }
    $parent_comment = new BP_Activity_Activity($parent_id);
    if ($parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta($parent_comment->user_id, 'notification_activity_new_reply', true)) {
        $poster_name = bp_core_get_user_displayname($commenter_id);
        $thread_link = bp_activity_get_permalink($activity_id);
        $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
        $settings_link = bp_core_get_user_domain($parent_comment->user_id) . $settings_slug . '/notifications/';
        // Set up and send the message.
        $ud = bp_core_get_core_userdata($parent_comment->user_id);
        $to = $ud->user_email;
        $subject = bp_get_email_subject(array('text' => sprintf(__('%s replied to one of your comments', 'buddypress'), $poster_name)));
        $poster_name = stripslashes($poster_name);
        $content = bp_activity_filter_kses(stripslashes($content));
        $message = sprintf(__('%1$s replied to one of your comments:

"%2$s"

To view the original activity, your comment and all replies, log in and visit: %3$s

---------------------
', 'buddypress'), $poster_name, $content, $thread_link);
        // Only show the disable notifications line if the settings component is enabled.
        if (bp_is_active('settings')) {
            $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
        }
        /**
         * Filters the user email that the new comment reply notification will be sent to.
         *
         * @since 1.2.0
         *
         * @param string $to User email the notification is being sent to.
         */
        $to = apply_filters('bp_activity_new_comment_notification_comment_author_to', $to);
        /**
         * Filters the new comment reply notification subject that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $subject     Email notification subject text.
         * @param string $poster_name Name of the person who made the comment reply.
         */
        $subject = apply_filters('bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name);
        /**
         * Filters the new comment reply notification message that will be sent to user.
         *
         * @since 1.2.0
         *
         * @param string $message       Email notification message text.
         * @param string $poster_name   Name of the person who made the comment reply.
         * @param string $content       Content of the comment reply.
         * @param string $settings_link URL permalink for the user's notification settings area.
         * @param string $thread_link   URL permalink for the activity thread.
         */
        $message = apply_filters('bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link);
        wp_mail($to, $subject, $message);
        /**
         * Fires after the sending of a reply to a reply email notification.
         *
         * @since 1.5.0
         *
         * @param int    $user_id      ID of the parent activity item author.
         * @param string $subject      Email notification subject text.
         * @param string $message      Email notification message text.
         * @param int    $comment_id   ID for the newly received comment.
         * @param int    $commenter_id ID of the user who made the comment.
         * @param array  $params       Arguments used with the original activity comment.
         */
        do_action('bp_activity_sent_reply_to_reply_email', $parent_comment->user_id, $subject, $message, $comment_id, $commenter_id, $params);
    }
}
Пример #28
0
/**
 * Gets the activity thread permalink
 *
 * @since 1.2.0
 *
 * @global object $bp BuddyPress global settings
 * @uses bp_activity_get_permalink()
 * @uses apply_filters() To call the 'bp_get_activity_thread_permalink' hook
 *
 * @return string $link The activity thread permalink
 */
function bp_get_activity_thread_permalink()
{
    global $bp, $activities_template;
    $link = bp_activity_get_permalink($activities_template->activity->id, $activities_template->activity);
    return apply_filters('bp_get_activity_thread_permalink', $link);
}
Пример #29
0
 /**
  * @group bp_activity_remove_screen_notifications
  * @group mentions
  */
 public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_wrong_user()
 {
     $this->create_notifications();
     $notifications = BP_Notifications_Notification::get(array('user_id' => $this->u1));
     // Double check it's there
     $this->assertEquals(array($this->a1), wp_list_pluck($notifications, 'item_id'));
     // Switch user
     $this->set_current_user($this->u2);
     // Go to the activity permalink page
     $this->go_to(bp_activity_get_permalink($this->a1));
     $activity = bp_activity_get_specific(array('activity_ids' => $this->a1, 'show_hidden' => true, 'spam' => 'ham_only'));
     do_action('bp_activity_screen_single_activity_permalink', $activity['activities'][0]);
     $notifications = BP_Notifications_Notification::get(array('user_id' => $this->u1));
     // Should be untouched
     $this->assertEquals(array($this->a1), wp_list_pluck($notifications, 'item_id'));
     $this->set_current_user($this->u1);
 }
Пример #30
0
/**
	 * Generate content for our picture grid
	 *
	 * @since BuddyBoss 2.0
	 * @todo	Update the theme file (members/single/pictures.php) and create a Wordpress like loop for the images 
	 					e.g. 
	 					<?php if ( buddyboss_picgrid_has_pics() ): while( buddyboss_picgrid_has_pics() ): ?>
	 						<?php buddyboss_picgrid_thumbnail(); ?>
	 						- and -
	 						<a href="<?php buddyboss_picgrid_fullsize_url(); ?>" title="<?php buddyboss_picgrid_image_title(); ?>">
	 							<img src="<?php buddyboss_picgrid_thumbnail_url(); ?>" width="<?php buddyboss_picgrid_thumbnail_width(); ?>" height="<?php buddyboss_picgrid_thumbnail_height(); ?>" />
	 						</a>
	 					<?php endwhile; endif; ?>
					
	 					(need to rename these for clarity, I think they're too long (JP))
					* functions to create:
					buddyboss_picgrid_has_pics()							For the if/while Wordpress style loop
	 					buddyboss_picgrid_attachment_id()					Returns the ID of the current image
	 					buddyboss_picgrid_thumbnail()							Echo '<li><a><img>' tags for you of the current thumbnail
	 					buddyboss_picgrid_thumbnail_url()					Echos the url location of the current thumbnail
	 					get_buddyboss_picgrid_thumbnail_url()			Returns the url location of the current thumbnail
	 					buddyboss_picgrid_thumbnail_width()				Echos the current thumbnail width
	 					get_buddyboss_picgrid_thumbnail_width()		Returns the current thumbnail width
	 					buddyboss_picgrid_thumbnail_height()			Echos the current thumbnail height
	 					get_buddyboss_picgrid_thumbnail_height()	Returns the current thumbnail height
	 					buddyboss_picgrid_fullsize_url()					Echos the url location of the current full size image
	 					get_buddyboss_picgrid_fullsize_url()			Returns the url location of the current thumbnail
	 					buddyboss_picgrid_fullsize_width()				Echos the current full size image width
	 					get_buddyboss_picgrid_fullsize_width()		Returns the current full size image width
	 					buddyboss_picgrid_fullsize_height()				Echos the current full size image height
	 					get_buddyboss_picgrid_fullsize_height()		Returns the current full size image height
*/
function buddyboss_pics_screen_picture_grid_content()
{
    global $bp, $wpdb, $bbpics;
    $wpdb->show_errors = BUDDY_BOSS_DEBUG;
    $img_size = is_active_sidebar('Profile') ? 'buddyboss_pic_med' : 'buddyboss_pic_wide';
    $gallery_class = is_active_sidebar('Profile') ? 'gallery has-sidebar' : 'gallery';
    $user_id = $bp->displayed_user->id;
    $activity_table = $wpdb->prefix . "bp_activity";
    $activity_meta_table = $wpdb->prefix . "bp_activity_meta";
    $pages_sql = "SELECT COUNT(*) FROM {$activity_table} a INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id WHERE a.user_id = {$user_id} AND meta_key = 'bboss_pics_aid'";
    $bbpics->grid_num_pics = $wpdb->get_var($pages_sql);
    $bbpics->grid_current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
    // Prepare a SQL query to retrieve the activity posts
    // that have pictures associated with them
    $sql = "SELECT a.*, am.meta_value FROM {$activity_table} a INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id WHERE a.user_id = {$user_id} AND meta_key = 'bboss_pics_aid' ORDER BY a.date_recorded DESC";
    buddy_boss_log("SQL: {$sql}");
    $pics = $wpdb->get_results($sql, ARRAY_A);
    $bbpics->grid_pagination = new BuddyBoss_Paginated($pics, $bbpics->grid_pics_per_page, $bbpics->grid_current_page);
    buddy_boss_log("RESULT: {$pics}");
    // If we have results let's print out a simple grid
    if (!empty($pics)) {
        $bbpics->grid_had_pics = true;
        $bbpics->grid_num_pics = count($pics);
        /**
        			 * DEBUG
        			 *
        			echo '<br/><br/><div style="display:block;background:#f0f0f0;border:2px solid #ccc;margin:20px;padding:15px;color:#333;"><pre>';
        			var_dump( $pics );
        			echo '</pre></div><hr/><br/><br/><br/><br/>';
        			die;
        			/**/
        $html_grid = '<ul class="' . $gallery_class . '" id="buddyboss-pics-grid">' . "\n";
        foreach ($pics as $pic) {
            /**
            				 * DEBUG
            				 *
            				echo '<br/><br/><div style="display:block;background:#f0f0f0;border:2px solid #ccc;margin:20px;padding:15px;color:#333;"><pre>';
            				var_dump( bp_activity_get_permalink($pic['id']), $pic );
            				echo '</pre></div><hr/><br/><br/><br/><br/>';
            				die;
            				/**/
            $attachment_id = isset($pic['meta_value']) ? (int) $pic['meta_value'] : 0;
            // Make sure we have a valid attachment ID
            if ($attachment_id > 0) {
                // Let's get the permalink of this attachment to show within a lightbox
                $permalink = bp_activity_get_permalink($pic['id']);
                $ajax_link = rtrim($permalink, '/') . '/?buddyboss_ajax_pic=true';
                // Grab the image details
                $image = wp_get_attachment_image_src($attachment_id, $img_size);
                // grab the thumbnail details
                $tn = wp_get_attachment_image_src($attachment_id, 'buddyboss_pic_tn');
                if (is_array($tn) && !empty($tn) && isset($tn[0]) && $tn[0] != '') {
                    $bbpics->grid_data[] = array('attachment' => $attachment_id, 'image' => $image, 'tn' => $tn, 'permalink' => $permalink, 'ajaxlink' => $ajax_link);
                    $html_grid .= '<li class="gallery-item"><div><a rel="gal_item" href="' . $ajax_link . '"><img src="' . $tn[0] . '" width="' . $tn[1] . '" height="' . $tn[2] . '" /></a></div></li>' . "\n";
                }
            }
        }
        $html_grid .= '</ul>' . "\n\n";
        $bbpics->grid_html = $html_grid;
        $bbpics->grid_has_pics = true;
    } else {
        $bbpics->grid_has_pics = false;
        $bbpics->grid_num_pics = 0;
        $bbpics->grid_current_pic = null;
        $bbpics->grid_data = array();
        $bbpics->grid_html = null;
    }
}