/**
 * Create a activity item
 * @param $params
 * @return string
 */
function buddystreamCreateActivity($params)
{
    global $bp, $wpdb;
    $buddyStreamExtensions = new BuddyStreamExtensions();
    $buddyStreamFilters = new BuddyStreamFilters();
    /**
     * buddystreamCreateActivity(array(
     *     'user_id'    => $user_meta->user_id,
     *     'extension'  => 'facebook',
     *     'type'       => 'photo',
     *     'content'    => $content,
     *     'item_id'    => $item['id'],
     *     'raw_date'   => $item['created_time'],
     *     'actionlink' => 'url_to_original_item')
     *  ));
     *
     */
    if (is_array($params)) {
        //load config of extension
        $originalText = $params['content'];
        foreach ($buddyStreamExtensions->getExtensionsConfigs() as $extension) {
            if (isset($extension['hashtag'])) {
                $originalText = str_replace($extension['hashtag'], "", $originalText);
                $originalText = trim($originalText);
            }
        }
        //set the content
        $content = "";
        $content = '<div class="buddystream_activity_container ' . $params['extension'] . '">' . $originalText . '</div>';
        if (!buddyStreamCheckImportLog($params['user_id'], $params['item_id'], $params['extension']) && !buddyStreamCheckExistingContent($content) && !buddyStreamCheckExistingContent($originalText)) {
            buddyStreamAddToImportLog($params['user_id'], $params['item_id'], $params['extension']);
            remove_filter('bp_activity_action_before_save', 'bp_activity_filter_kses', 1);
            $activity = new BP_Activity_Activity();
            $activity->user_id = $params['user_id'];
            $activity->component = $params['extension'];
            $activity->type = $params['extension'];
            $activity->content = $content;
            $activity->item_id = $params['item_id'];
            $activity->secondary_item_id = '';
            $activity->date_recorded = $params['raw_date'];
            $activity->hide_sitewide = 0;
            $activity->action .= '<a href="' . bp_core_get_user_domain($params['user_id']) . '" title="' . bp_core_get_username($params['user_id']) . '">' . bp_core_get_user_displayname($params['user_id']) . '</a>';
            $activity->action .= ' ' . __('posted&nbsp;a', 'buddystream_lang') . ' ';
            $activity->action .= '<a href="' . $params['actionlink'] . '" target="_blank" rel="external"> ' . __($params['type'], 'buddystream_' . $extension['name']);
            $activity->action .= '</a>: ';
            $activity->primary_link = $params['actionlink'];
            if (!preg_match("/" . $params['item_id'] . "/i", get_user_meta($params['user_id'], 'buddystream_blacklist_ids', 1))) {
                $activity->save();
                $buddyStreamFilters->updateDayLimitByOne($params['extension'], $params['user_id']);
                return true;
            }
        }
    }
    return false;
}
 /**
  * Post a gallery or media Main comment on single page
  * 
  * @return type
  */
 public function post_comment()
 {
     // Bail if not a POST action
     if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
         return;
     }
     // Check the nonce
     check_admin_referer('post_update', '_wpnonce_post_update');
     if (!is_user_logged_in()) {
         exit('-1');
     }
     $mpp_type = $_POST['mpp-type'];
     $mpp_id = $_POST['mpp-id'];
     if (empty($_POST['content'])) {
         exit('-1<div id="message" class="error"><p>' . __('Please enter some content to post.', 'mediapress') . '</p></div>');
     }
     $activity_id = 0;
     if (empty($_POST['object']) && bp_is_active('activity')) {
         //we are preventing this comment to be set as the user's lastes_update
         $user_id = bp_loggedin_user_id();
         $old_latest_update = bp_get_user_meta($user_id, 'bp_latest_update', true);
         $activity_id = bp_activity_post_update(array('content' => $_POST['content']));
         //restore
         if (!empty($old_latest_update)) {
             bp_update_user_meta($user_id, 'bp_latest_update', $old_latest_update);
         }
     } elseif ($_POST['object'] == 'groups') {
         if (!empty($_POST['item_id']) && bp_is_active('groups')) {
             $activity_id = groups_post_update(array('content' => $_POST['content'], 'group_id' => $_POST['item_id']));
         }
     } else {
         $activity_id = apply_filters('bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content']);
     }
     if (empty($activity_id)) {
         exit('-1<div id="message" class="error"><p>' . __('There was a problem posting your update, please try again.', 'mediapress') . '</p></div>');
     }
     //if we have got activity id, let us add a meta key
     if ($mpp_type == 'gallery') {
         mpp_activity_update_gallery_id($activity_id, $mpp_id);
     } elseif ($mpp_type == 'media') {
         mpp_activity_update_media_id($activity_id, $mpp_id);
     }
     $activity = new BP_Activity_Activity($activity_id);
     // $activity->component = buddypress()->mediapress->id;
     $activity->type = 'mpp_media_upload';
     $activity->save();
     if (bp_has_activities('include=' . $activity_id)) {
         while (bp_activities()) {
             bp_the_activity();
             mpp_locate_template(array('activity/entry.php'), true);
         }
     }
     exit;
 }
Beispiel #3
0
 function update_object($activity_id, $fields)
 {
     $activity = new BP_Activity_Activity($activity_id);
     foreach ($fields as $field_name => $value) {
         if (isset($activity->{$field_name})) {
             $activity->{$field_name} = $value;
         }
     }
     $activity->save();
     return $activity;
 }
Beispiel #4
0
 /**
  * @group bp_activity_clear_cache_for_activity
  */
 public function test_bp_activity_clear_cache_for_activity()
 {
     $u = $this->factory->user->create();
     $a = $this->factory->activity->create(array('component' => buddypress()->activity->id, 'type' => 'activity_update', 'user_id' => $u, 'content' => 'foo bar'));
     $a_fp = bp_activity_get(array('type' => 'activity_update', 'user' => array('filter' => array('user_id' => $u))));
     $activity_updated = new BP_Activity_Activity($a);
     $activity_updated->content = 'bar foo';
     $activity_updated->save();
     $a_fp = bp_activity_get(array('type' => 'activity_update', 'user' => array('filter' => array('user_id' => $u))));
     $this->assertSame('bar foo', $a_fp['activities'][0]->content);
 }
Beispiel #5
0
/**
 * Retrieve sitewide activity
 *
 * You should use bp_activity_get() instead
 *
 * @since 1.0.0
 * @deprecated 1.2.0
 *
 * @param array $args
 *
 * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity}
 *
 * @return object $activity The activity/activities object
 */
function bp_activity_get_sitewide($args = '')
{
    _deprecated_function(__FUNCTION__, '1.2', 'bp_activity_get()');
    $defaults = array('max' => false, 'page' => 1, 'per_page' => false, 'sort' => 'DESC', 'display_comments' => false, 'search_terms' => false, 'show_hidden' => false, 'filter' => array());
    $args = wp_parse_args($args, $defaults);
    return apply_filters('bp_activity_get_sitewide', BP_Activity_Activity::get($args), $r);
}
Beispiel #6
0
function delete_pic_cover_group($activity_id)
{
    global $bp;
    $group_id = $bp->groups->current_group->id;
    $activity_id = $_POST['activity_id'];
    $attachment_id = bp_activity_get_meta($activity_id, 'all_bp_cover_group', true);
    wp_delete_attachment($attachment_id, true);
    groups_delete_groupmeta($group_id, 'bp_cover_group');
    groups_delete_groupmeta($group_id, 'bp_cover_group_position');
    bp_activity_delete(array('id' => $activity_id, 'item_id' => $group_id));
    BP_Activity_Activity::delete_activity_meta_entries($activity_id);
}
/**
 * CLEANUP DATABASE AND RECONCILE WITH WP MEDIA LIBRARY
 */
function buddy_boss_pics_cleanup_db()
{
    global $wpdb;
    $activity_table = $wpdb->prefix . "bp_activity";
    $activity_meta_table = $wpdb->prefix . "bp_activity_meta";
    $posts_table = $wpdb->prefix . "posts";
    // Prepare a SQL query to retrieve the activity posts
    // that have pictures associated with them
    $all_aids_sql = "SELECT am.meta_value, am.activity_id FROM {$activity_table} a \r\n\t\t\t\t\t\t\t\t\t\t INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id \r\n\t\t\t\t\t\t\t\t\t\t WHERE am.meta_key = 'bboss_pics_aid'";
    // Now perpare a SQL query to retrieve all attachments
    // that are BuddyBoss wall pictures AND are published in the media library
    $existing_sql = "SELECT am.meta_value FROM {$activity_table} a \r\n\t\t\t\t\t\t\t\t\t\t INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id \r\n\t\t\t\t\t\t\t\t\t\t INNER JOIN {$posts_table} p ON am.meta_value = p.ID \r\n\t\t\t\t\t\t\t\t\t\t WHERE am.meta_key = 'bboss_pics_aid'\r\n\t\t\t\t\t\t\t\t\t\t AND p.post_status = 'inherit'\r\n\t\t\t\t\t\t\t\t\t\t AND p.post_parent = 0";
    // Query the database for all attachment IDS
    $all_aids = (array) $wpdb->get_results($all_aids_sql, ARRAY_A);
    // Query the database for all pics in the media library that are BuddyBoss pics
    $existing_aids = (array) $wpdb->get_col($existing_sql);
    // If we have a result set
    if (!empty($all_aids)) {
        // Prepare array
        $attachment_ids = $activity_ids = $aids2activity = array();
        foreach ($all_aids as $aid) {
            $attachment_ids[] = $aid['meta_value'];
            $aids2activity[$aid['meta_value']] = $activity_ids[] = $aid['activity_id'];
        }
        // Lets get the difference of our published vs. orphaned IDs
        $orphans = array_diff($attachment_ids, $existing_aids);
        // Delete related activity stream posts
        if (!empty($orphans)) {
            $orphan_acitivity_ids = array();
            foreach ($orphans as $orphan) {
                if (isset($aids2activity[$orphan])) {
                    $orphan_acitivity_ids[] = $aids2activity[$orphan];
                }
            }
            $orphan_acitivity_ids_string = implode(',', $orphan_acitivity_ids);
            $sql = $wpdb->prepare("DELETE FROM {$activity_table} WHERE id IN ({$orphan_acitivity_ids_string})");
            $deleted = $wpdb->query($sql);
            BP_Activity_Activity::delete_activity_item_comments($orphan_acitivity_ids);
            BP_Activity_Activity::delete_activity_meta_entries($orphan_acitivity_ids);
        }
    }
}
 protected function get_comments()
 {
     $count = BP_Activity_Activity::get_activity_comments($this->activity->id, $this->activity->mptt_left, $this->activity->mptt_right);
     return count($count);
 }
 /**
  * Create filter SQL clauses.
  *
  * @since BuddyPress (1.5.0)
  *
  * @param array $filter_array {
  *     Fields and values to filter by.
  *     @type array|string|id $user_id User ID(s).
  *     @type array|string $object Corresponds to the 'component'
  *           column in the database.
  *     @type array|string $action Corresponds to the 'type' column
  *           in the database.
  *     @type array|string|int $primary_id Corresponds to the 'item_id'
  *           column in the database.
  *     @type array|string|int $secondary_id Corresponds to the
  *           'secondary_item_id' column in the database.
  *     @type int $offset Return only those items with an ID greater
  *           than the offset value.
  *     @type string $since Return only those items that have a
  *           date_recorded value greater than a given MySQL-formatted
  *           date.
  * }
  * @return string The filter clause, for use in a SQL query.
  */
 public static function get_filter_sql($filter_array)
 {
     $filter_sql = array();
     if (!empty($filter_array['user_id'])) {
         global $wpdb;
         $user_sql = BP_Activity_Activity::get_in_operator_sql('a.user_id', $filter_array['user_id']);
         // START Also include @Mentions in User Stream
         $search_terms = '@' . bp_core_get_username($filter_array['user_id']);
         $user_sql .= "OR ( a.content LIKE '%%" . $wpdb->esc_like($search_terms) . "%%' )";
         // END Also include @Mentions in User Stream
         if (!empty($user_sql)) {
             $filter_sql[] = $user_sql;
         }
     }
     if (!empty($filter_array['object'])) {
         $object_sql = BP_Activity_Activity::get_in_operator_sql('a.component', $filter_array['object']);
         if (!empty($object_sql)) {
             $filter_sql[] = $object_sql;
         }
     }
     if (!empty($filter_array['action'])) {
         $action_sql = BP_Activity_Activity::get_in_operator_sql('a.type', $filter_array['action']);
         if (!empty($action_sql)) {
             $filter_sql[] = $action_sql;
         }
     }
     if (!empty($filter_array['primary_id'])) {
         $pid_sql = BP_Activity_Activity::get_in_operator_sql('a.item_id', $filter_array['primary_id']);
         if (!empty($pid_sql)) {
             $filter_sql[] = $pid_sql;
         }
     }
     if (!empty($filter_array['secondary_id'])) {
         $sid_sql = BP_Activity_Activity::get_in_operator_sql('a.secondary_item_id', $filter_array['secondary_id']);
         if (!empty($sid_sql)) {
             $filter_sql[] = $sid_sql;
         }
     }
     if (!empty($filter_array['offset'])) {
         $sid_sql = absint($filter_array['offset']);
         $filter_sql[] = "a.id >= {$sid_sql}";
     }
     if (!empty($filter_array['since'])) {
         // Validate that this is a proper Y-m-d H:i:s date
         // Trick: parse to UNIX date then translate back
         $translated_date = date('Y-m-d H:i:s', strtotime($filter_array['since']));
         if ($translated_date === $filter_array['since']) {
             $filter_sql[] = "a.date_recorded > '{$translated_date}'";
         }
     }
     if (empty($filter_sql)) {
         return false;
     }
     return join(' AND ', $filter_sql);
 }
 function migrate_single_media($result, $album = false)
 {
     $blog_id = get_current_blog_id();
     $old = $result;
     if (function_exists('bp_core_get_table_prefix')) {
         $bp_prefix = bp_core_get_table_prefix();
     } else {
         $bp_prefix = '';
     }
     global $wpdb;
     if (false !== $album && !is_object($result)) {
         $id = $wpdb->get_var($wpdb->prepare("select ID from {$this->bmp_table} where media_id = %d", $result));
         if (null == $id) {
             $sql = "select\n                        a.post_id as 'post_id',\n                        a.meta_value as 'privacy',\n                        b.meta_value as 'context_id',\n                        c.meta_value as 'activity_id',\n                        p.post_type,\n                        p.post_mime_type,\n                        p.post_author as 'media_author',\n                        p.post_title as 'media_title',\n                        p.post_parent as 'parent'\n                    from\n                        {$wpdb->postmeta} a\n                            left join\n                        {$wpdb->postmeta} b ON ((a.post_id = b.post_id)\n                            and (b.meta_key = 'bp-media-key'))\n                            left join\n                        {$wpdb->postmeta} c ON (a.post_id = c.post_id)\n                            and (c.meta_key = 'bp_media_child_activity')\n                            left join\n                        {$wpdb->posts} p ON (a.post_id = p.ID)\n                    where\n                        a.post_id = %d and (NOT p.ID IS NULL)\n                            and a.meta_key = 'bp_media_privacy'";
             $result = $wpdb->get_row($wpdb->prepare($sql, $result));
         } else {
             return $id;
         }
     }
     if (!isset($result) || !isset($result->post_id)) {
         return $old;
     }
     $media_id = $result->post_id;
     if (intval($result->context_id) > 0) {
         $media_context = 'profile';
         $prefix = 'users/' . abs(intval($result->context_id));
     } else {
         $media_context = 'group';
         $prefix = bp_get_groups_root_slug() . abs(intval($result->context_id));
     }
     $old_type = '';
     if ('attachment' != $result->post_type) {
         $media_type = 'album';
     } else {
         $mime_type = strtolower($result->post_mime_type);
         $old_type = '';
         if (0 === strpos($mime_type, 'image')) {
             $media_type = 'photo';
             $old_type = 'photos';
         } else {
             if (0 === strpos($mime_type, 'audio')) {
                 $media_type = 'music';
                 $old_type = 'music';
             } else {
                 if (0 === strpos($mime_type, 'video')) {
                     $media_type = 'video';
                     $old_type = 'videos';
                 } else {
                     $media_type = 'other';
                 }
             }
         }
     }
     $activity_data = $wpdb->get_row($wpdb->prepare("select * from {$bp_prefix}bp_activity where id= %d", $result->activity_id));
     if ('album' != $media_type) {
         $this->importmedia($media_id, $prefix);
     }
     if ($this->table_exists($bp_prefix . 'bp_activity') && class_exists('BP_Activity_Activity')) {
         $bp_activity = new BP_Activity_Activity();
         $activity_sql = $wpdb->prepare("SELECT\n                            *\n                        FROM\n                            {$bp_prefix}bp_activity\n                        where\n                                        id in (select distinct\n                                    a.meta_value\n                                from\n                                    {$wpdb->postmeta} a\n                                        left join\n                                    {$wpdb->posts} p ON (a.post_id = p.ID)\n                                where\n                                    (NOT p.ID IS NULL) and p.ID = %d\n                and a.meta_key = 'bp_media_child_activity')", $media_id);
         $all_activity = $wpdb->get_results($activity_sql);
         remove_all_actions('wp_insert_comment');
         foreach ($all_activity as $activity) {
             $comments = $bp_activity->get_activity_comments($activity->id, $activity->mptt_left, $activity->mptt_right);
             $exclude = get_post_meta($media_id, 'rtmedia_imported_activity', true);
             if (!is_array($exclude)) {
                 $exclude = array();
             }
             if ($comments) {
                 $this->insert_comment($media_id, $comments, $exclude);
             }
         }
     }
     if (0 !== intval($result->parent)) {
         $album_id = $this->migrate_single_media($result->parent, true);
     } else {
         $album_id = 0;
     }
     if (function_exists('bp_activity_get_meta')) {
         $likes = bp_activity_get_meta($result->activity_id, 'favorite_count');
     } else {
         $likes = 0;
     }
     $wpdb->insert($this->bmp_table, array('blog_id' => $blog_id, 'media_id' => $media_id, 'media_type' => $media_type, 'context' => $media_context, 'context_id' => abs(intval($result->context_id)), 'activity_id' => $result->activity_id, 'privacy' => intval($result->privacy) * 10, 'media_author' => $result->media_author, 'media_title' => $result->media_title, 'album_id' => $album_id, 'likes' => $likes), array('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%d', '%d'));
     $last_id = $wpdb->insert_id;
     // Photo tag meta migration
     //$photo_tag_meta = get_post_meta($media_id, "bp-media-user-tags", true);
     //        if($photo_tag_meta && !empty($photo_tag_meta)){
     //            $wpdb->insert(
     //                $wpdb->prefix . "rt_rtm_media_meta", array(
     //                    'media_id' => $media_id,
     //                    'meta_key' => "user-tags",
     //                    "meta_value" =>  maybe_serialize($photo_tag_meta)), array('%d', '%s', '%s'));
     //        }
     if ('album' != $media_type && function_exists('bp_core_get_user_domain') && $activity_data) {
         if (function_exists('bp_core_get_table_prefix')) {
             $bp_prefix = bp_core_get_table_prefix();
         } else {
             $bp_prefix = '';
         }
         $activity_data->old_primary_link = $activity_data->primary_link;
         $parent_link = get_rtmedia_user_link($activity_data->user_id);
         $activity_data->primary_link = $parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id;
         $this->search_and_replace($activity_data->old_primary_link, $activity_data->primary_link);
         $activity_data->action = str_replace($activity_data->old_primary_link, $activity_data->primary_link, $activity_data->action);
         $activity_data->content = str_replace($activity_data->old_primary_link, $activity_data->primary_link, $activity_data->content);
         global $last_baseurl, $last_newurl;
         $replace_img = $last_newurl;
         //$last_baseurl . "rtMedia/$prefix/";
         if (false === strpos($activity_data->content, $replace_img)) {
             $activity_data->content = str_replace($last_baseurl, $replace_img, $activity_data->content);
         }
         global $wpdb;
         $wpdb->update($bp_prefix . 'bp_activity', array('primary_link' => $activity_data->primary_link, 'action' => $activity_data->action, 'content' => $activity_data->content), array('id' => $activity_data->id));
     } else {
         if ('group' == $media_context) {
             $activity_data->old_primary_link = $activity_data->primary_link;
             $parent_link = get_rtmedia_group_link(abs(intval($result->context_id)));
             $parent_link = trailingslashit($parent_link);
             $activity_data->primary_link = trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id);
             $this->search_and_replace($activity_data->old_primary_link, $activity_data->primary_link);
         } else {
             $activity_data->old_primary_link = $activity_data->primary_link;
             $parent_link = get_rtmedia_user_link($activity_data->user_id);
             $parent_link = trailingslashit($parent_link);
             $activity_data->primary_link = trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id);
             $this->search_and_replace($activity_data->old_primary_link, $activity_data->primary_link);
         }
     }
     if ('' != $old_type) {
         if ('group' == $media_context) {
             $parent_link = get_rtmedia_group_link(abs(intval($result->context_id)));
             $parent_link = trailingslashit($parent_link);
             $this->search_and_replace(trailingslashit($parent_link . $old_type . '/' . $media_id), trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id));
         } else {
             $parent_link = get_rtmedia_user_link($activity_data->user_id);
             $parent_link = trailingslashit($parent_link);
             $this->search_and_replace(trailingslashit($parent_link . $old_type . '/' . $media_id), trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id));
         }
     }
     return $last_id;
 }
 static function update_recorded_time_and_comments($media, $bp_album_id, $table)
 {
     global $wpdb;
     if (function_exists('bp_activity_add')) {
         if (!is_object($media)) {
             try {
                 $media = new BPMediaHostWordpress($media);
             } catch (exception $e) {
                 return false;
             }
         }
         $activity_id = get_post_meta($media->get_id(), 'bp_media_child_activity', true);
         if ($activity_id) {
             $date_uploaded = $wpdb->get_var("SELECT date_uploaded from {$table} WHERE id = {$bp_album_id}");
             $old_activity_id = $wpdb->get_var("SELECT id from {$wpdb->base_prefix}bp_activity WHERE component = 'album' AND type = 'bp_album_picture' AND item_id = {$bp_album_id}");
             if ($old_activity_id) {
                 $comments = $wpdb->get_results("SELECT id,secondary_item_id from {$wpdb->base_prefix}bp_activity WHERE component = 'activity' AND type = 'activity_comment' AND item_id = {$old_activity_id}");
                 foreach ($comments as $comment) {
                     $update = array('item_id' => $activity_id);
                     if ($comment->secondary_item_id == $old_activity_id) {
                         $update['secondary_item_id'] = $activity_id;
                     }
                     $wpdb->update($wpdb->base_prefix . 'bp_activity', $update, array('id' => $comment->id));
                     BP_Activity_Activity::rebuild_activity_comment_tree($activity_id);
                 }
             }
             $wpdb->update($wpdb->base_prefix . 'bp_activity', array('date_recorded' => $date_uploaded), array('id' => $activity_id));
             return count($comments);
         }
         return 0;
     }
 }
 /**
  * Generate WHERE clauses for a first-order clause.
  *
  * @since BuddyPress (2.2.0)
  * @access protected
  *
  * @param  array $clause       Array of arguments belonging to the clause.
  * @param  array $parent_query Parent query to which the clause belongs.
  * @return array {
  *     @type array $where Array of subclauses for the WHERE statement.
  *     @type array $join  Empty array. Not used.
  * }
  */
 protected function get_sql_for_clause($clause, $parent_query)
 {
     global $wpdb;
     $sql_chunks = array('where' => array(), 'join' => array());
     $column = isset($clause['column']) ? $this->validate_column($clause['column']) : '';
     $value = isset($clause['value']) ? $clause['value'] : '';
     if (empty($column) || !isset($clause['value'])) {
         return $sql_chunks;
     }
     if (isset($clause['compare'])) {
         $clause['compare'] = strtoupper($clause['compare']);
     } else {
         $clause['compare'] = isset($clause['value']) && is_array($clause['value']) ? 'IN' : '=';
     }
     // default 'compare' to '=' if no valid operator is found
     if (!in_array($clause['compare'], array('=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'REGEXP', 'NOT REGEXP', 'RLIKE'))) {
         $clause['compare'] = '=';
     }
     $compare = $clause['compare'];
     $alias = !empty($this->table_alias) ? "{$this->table_alias}." : '';
     // Next, Build the WHERE clause.
     $where = '';
     // value.
     if (isset($clause['value'])) {
         if (in_array($compare, array('IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'))) {
             if (!is_array($value)) {
                 $value = preg_split('/[,\\s]+/', $value);
             }
         }
         // tinyint
         if (!empty($column) && true === in_array($column, array('hide_sitewide', 'is_spam'))) {
             $sql_chunks['where'][] = $wpdb->prepare("{$alias}{$column} = %d", $value);
         } else {
             switch ($compare) {
                 // IN uses different syntax
                 case 'IN':
                 case 'NOT IN':
                     $in_sql = BP_Activity_Activity::get_in_operator_sql("{$alias}{$column}", $value);
                     // 'NOT IN' operator is as easy as a string replace!
                     if ('NOT IN' === $compare) {
                         $in_sql = str_replace('IN', 'NOT IN', $in_sql);
                     }
                     $sql_chunks['where'][] = $in_sql;
                     break;
                 case 'BETWEEN':
                 case 'NOT BETWEEN':
                     $value = array_slice($value, 0, 2);
                     $where = $wpdb->prepare('%s AND %s', $value);
                     break;
                 case 'LIKE':
                 case 'NOT LIKE':
                     $value = '%' . bp_esc_like($value) . '%';
                     $where = $wpdb->prepare('%s', $value);
                     break;
                 default:
                     $where = $wpdb->prepare('%s', $value);
                     break;
             }
         }
         if ($where) {
             $sql_chunks['where'][] = "{$alias}{$column} {$compare} {$where}";
         }
     }
     /*
      * Multiple WHERE clauses should be joined in parentheses.
      */
     if (1 < count($sql_chunks['where'])) {
         $sql_chunks['where'] = array('( ' . implode(' AND ', $sql_chunks['where']) . ' )');
     }
     return $sql_chunks;
 }
 public function get($max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false)
 {
     global $wpdb, $bp;
     /* Select conditions */
     $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
     //from conditions
     $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
     /* Sorting */
     if ($sort != 'ASC' && $sort != 'DESC') {
         $sort = 'DESC';
     }
     //get or sql, to support your component, please filter on fb_like_activity_or_sql
     $or_sql = apply_filters("fb_like_activity_or_sql", self::get_filter_sql($filter), $filter);
     //get and sql
     $and_sql = apply_filters("fb_like_activity_or_sql", self::get_action_sql($filter), $filter);
     if (!empty($or_sql)) {
         $where_sql = "( " . $or_sql . " )";
     }
     if (!empty($and_sql)) {
         $where_sql = $where_sql . " AND " . $and_sql;
     }
     $activity_sql = "{$select_sql} {$from_sql}  WHERE {$where_sql}  ORDER BY date_recorded {$sort}";
     if ($per_page && $page) {
         $pag_sql = $wpdb->prepare("LIMIT %d, %d", intval(($page - 1) * $per_page), intval($per_page));
         $activities = $wpdb->get_results("{$activity_sql} {$pag_sql}");
     } else {
         $activities = $wpdb->get_results("{$activity_sql} {$pag_sql}");
     }
     // echo //needs mod
     $total_activities = $wpdb->get_var("SELECT count(a.id) FROM {$bp->activity->table_name} a WHERE {$where_sql} ORDER BY a.date_recorded {$sort}");
     /* Get the fullnames of users so we don't have to query in the loop */
     if (function_exists('xprofile_install') && $activities) {
         foreach ((array) $activities as $activity) {
             if ((int) $activity->user_id) {
                 $activity_user_ids[] = $activity->user_id;
             }
         }
         $activity_user_ids = implode(',', array_unique((array) $activity_user_ids));
         if (!empty($activity_user_ids)) {
             if ($names = $wpdb->get_results("SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})")) {
                 foreach ((array) $names as $name) {
                     $tmp_names[$name->user_id] = $name->user_fullname;
                 }
                 foreach ((array) $activities as $i => $activity) {
                     if (!empty($tmp_names[$activity->user_id])) {
                         $activities[$i]->user_fullname = $tmp_names[$activity->user_id];
                     }
                 }
                 unset($names);
                 unset($tmp_names);
             }
         }
     }
     if ($activities && $display_comments) {
         $activities = BP_Activity_Activity::append_comments($activities);
     }
     /* If $max is set, only return up to the max results */
     if (!empty($max)) {
         if ((int) $total_activities > (int) $max) {
             $total_activities = $max;
         }
     }
     return array('activities' => $activities, 'total' => (int) $total_activities);
 }
/**
 * Deletes the blog comment when the associated activity comment is deleted.
 *
 * Note: This is hooked on the 'bp_activity_delete_comment_pre' filter instead
 * of the 'bp_activity_delete_comment' action because we need to fetch the
 * activity comment children before they are deleted.
 *
 * @since 2.0.0
 * @since 2.5.0 Add the $delected parameter
 *
 * @param bool $retval             Whether BuddyPress should continue or not.
 * @param int  $parent_activity_id The parent activity ID for the activity comment.
 * @param int  $activity_id        The activity ID for the pending deleted activity comment.
 * @param bool $deleted            Whether the comment was deleted or not.
 * @return bool
 */
function bp_blogs_sync_delete_from_activity_comment($retval, $parent_activity_id, $activity_id, &$deleted)
{
    // Check if parent activity is a blog post.
    $parent_activity = new BP_Activity_Activity($parent_activity_id);
    // if parent activity isn't a post type having the buddypress-activity support, stop now!
    if (!bp_activity_type_supports($parent_activity->type, 'post-type-comment-tracking')) {
        return $retval;
    }
    // Fetch the activity comments for the activity item.
    $activity = bp_activity_get(array('in' => $activity_id, 'display_comments' => 'stream', 'spam' => 'all'));
    // Get all activity comment IDs for the pending deleted item.
    $activity_ids = bp_activity_recurse_comments_activity_ids($activity);
    $activity_ids[] = $activity_id;
    // Handle multisite
    // switch to the blog where the comment was made.
    switch_to_blog($parent_activity->item_id);
    // Remove associated blog comments.
    bp_blogs_remove_associated_blog_comments($activity_ids, current_user_can('moderate_comments'));
    // Multisite again!
    restore_current_blog();
    // Rebuild activity comment tree
    // emulate bp_activity_delete_comment().
    BP_Activity_Activity::rebuild_activity_comment_tree($parent_activity_id);
    // Avoid the error message although the comments were successfully deleted
    $deleted = true;
    // We're overriding the default bp_activity_delete_comment() functionality
    // so we need to return false.
    return false;
}
Beispiel #15
0
function delete_pic_cover($activity_id)
{
    global $bp;
    $user_id = bp_loggedin_user_id();
    $activity_id = $_POST['activity_id'];
    $attachment_id = bp_activity_get_meta($activity_id, 'bp_cover_activity', true);
    wp_delete_attachment($attachment_id, true);
    delete_post_meta($attachment_id, true);
    delete_user_meta($user_id, 'bp_cover');
    delete_user_meta($user_id, 'bp_cover_position');
    bp_activity_delete(array('id' => $activity_id, 'user_id' => $bp->loggedin_user->id));
    BP_Activity_Activity::delete_activity_meta_entries($activity_id);
}
function mpp_delete_activity_by_meta_key_value($key, $object_id = null)
{
    global $bp, $wpdb;
    if (!function_exists('bp_is_active') || !bp_is_active('activity')) {
        return false;
        //or false?
    }
    $where_sql = array();
    $where_sql[] = $wpdb->prepare('meta_key=%s', $key);
    if ($object_id) {
        $where_sql[] = $wpdb->prepare('meta_value = %d', $object_id);
    }
    $where_sql = join(' AND ', $where_sql);
    // Fetch the activity IDs so we can delete any comments for this activity item
    $activity_ids = $wpdb->get_col("SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE {$where_sql}");
    if (empty($activity_ids)) {
        return false;
    }
    $list = '(' . join(',', $activity_ids) . ')';
    if (!$wpdb->query("DELETE FROM {$bp->activity->table_name} WHERE id IN {$list}")) {
        return false;
    }
    // Handle accompanying activity comments and meta deletion
    $activity_comment_ids = mpp_delete_activity_comments($activity_ids);
    $activity_ids = array_merge($activity_ids, $activity_comment_ids);
    BP_Activity_Activity::delete_activity_meta_entries($activity_ids);
    return $activity_ids;
}
/**
 * Filter the activity WHERE SQL conditions to support groupblog entries.
 *
 * @param array $retval Current MySQL WHERE conditions
 * @param array $r Current activity get arguments
 * @return array
 */
function bp_follow_blogs_groupblog_activity_where_conditions($retval, $r)
{
    global $bp;
    // support heartbeat in groupblog query
    $extra = '';
    if (!empty($r['filter']['since'])) {
        $extra = BP_Activity_Activity::get_filter_sql(array('since' => $r['filter']['since']));
        $extra = ' AND ' . $extra;
    }
    // For BP Groupblog, we need to grab the group IDs that are connected to blogs
    // This is what this query is for, which will form our groupblog subquery
    $group_ids_connected_to_blogs_subquery = "SELECT group_id FROM {$bp->groups->table_name_groupmeta} WHERE meta_key = 'groupblog_blog_id' AND meta_value IN ( " . $r['filter']['primary_id'] . " )";
    $retval['filter_sql'] = "( ( {$retval['filter_sql']} ) OR ( component = 'groups' AND item_id IN ( {$group_ids_connected_to_blogs_subquery} ) AND type = 'new_groupblog_post'{$extra} ) )";
    remove_filter('bp_activity_get_where_conditions', 'bp_follow_blogs_groupblog_activity_where_conditions', 10, 2);
    return $retval;
}
Beispiel #18
0
function bp_activity_total_favorites_for_user( $user_id = false ) {
	global $bp;

	if ( !$user_id )
		$user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;

	return BP_Activity_Activity::total_favorite_count( $user_id );
}
Beispiel #19
0
	function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
		global $wpdb, $bp;

		/* The right value of this node is the left value + 1 */
		$right = $left + 1;

		/* Get all descendants of this node */
		$descendants = BP_Activity_Activity::get_child_comments( $parent_id );

		/* Loop the descendants and recalculate the left and right values */
		foreach ( (array)$descendants as $descendant )
			$right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );

		/* We've got the left value, and now that we've processed the children of this node we also know the right value */
		if ( 1 == $left )
			$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
		else
			$wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );

		/* Return the right value of this node + 1 */
		return $right + 1;
	}
    function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array('title' => __('Site Wide Activities', 'swa'), 'max_items' => 200, 'per_page' => 25, 'is_personal' => 'no', 'is_blog_admin_activity' => 'no', 'show_avatar' => 'yes', 'show_feed_link' => 'yes', 'show_post_form' => 'no', 'allow_reply' => 'no', 'show_activity_filters' => 'yes', 'included_components' => false, 'excluded_components' => false));
        $per_page = strip_tags($instance['per_page']);
        $max_items = strip_tags($instance['max_items']);
        $title = strip_tags($instance['title']);
        extract($instance);
        ?>

                <p><label for="bp-swa-title"><strong><?php 
        _e('Title:', 'swa');
        ?>
 </strong><input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" style="width: 100%" /></label></p>
		<p><label for="bp-swa-per-page"><?php 
        _e('Number of Items Per Page:', 'swa');
        ?>
 <input class="widefat" id="<?php 
        echo $this->get_field_id('per_page');
        ?>
" name="<?php 
        echo $this->get_field_name('per_page');
        ?>
" type="text" value="<?php 
        echo esc_attr($per_page);
        ?>
" style="width: 30%" /></label></p>
		<p><label for="bp-swa-max"><?php 
        _e('Max items to show:', 'swa');
        ?>
 <input class="widefat" id="<?php 
        echo $this->get_field_id('max_items');
        ?>
" name="<?php 
        echo $this->get_field_name('max_items');
        ?>
" type="text" value="<?php 
        echo esc_attr($max_items);
        ?>
" style="width: 30%" /></label></p>
		 <p><label for="bp-swa-is-personal"><strong><?php 
        _e("Limit to Logged In user's activity:", 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('is_personal');
        ?>
" type="radio" <?php 
        if ($is_personal == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('is_personal');
        ?>
_no" name="<?php 
        echo $this->get_field_name('is_personal');
        ?>
" type="radio" <?php 
        if ($is_personal !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
                <p><label for="bp-swa-is-blog-admin-activity"><strong><?php 
        _e("List My Activity Only:", 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('is_blog_admin_activity');
        ?>
" type="radio" <?php 
        if ($is_blog_admin_activity == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('is_blog_admin_activity');
        ?>
_no" name="<?php 
        echo $this->get_field_name('is_blog_admin_activity');
        ?>
" type="radio" <?php 
        if ($is_blog_admin_activity !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
                <p><label for="bp-swa-show-avatar"><strong><?php 
        _e('Show Avatar:', 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_avatar');
        ?>
" type="radio" <?php 
        if ($show_avatar == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_avatar');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_avatar');
        ?>
" type="radio" <?php 
        if ($show_avatar !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>
                    
                    </label>
               </p>
               <p><label for="bp-swa-show-feed-link"><?php 
        _e('Show Feed Link:', 'swa');
        ?>
                       <label for="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_feed_link');
        ?>
" type="radio" <?php 
        if ($show_feed_link == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_feed_link');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_feed_link');
        ?>
" type="radio" <?php 
        if ($show_feed_link !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
               <p><label for="bp-swa-show-post-form"><strong><?php 
        _e('Show Post Form', 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_post_form');
        ?>
" type="radio" <?php 
        if ($show_post_form == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_post_form');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_post_form');
        ?>
" type="radio" <?php 
        if ($show_post_form !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
               <!-- <p><label for="bp-swa-show-reply-link"><?php 
        _e('Allow reply to activity item:', 'swa');
        ?>
                       <label for="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('allow_reply');
        ?>
" type="radio" <?php 
        if ($show_feed_link == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('allow_reply');
        ?>
_no" name="<?php 
        echo $this->get_field_name('allow_reply');
        ?>
" type="radio" <?php 
        if ($show_feed_link !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>-->
               <p><label for="bp-swa-show-activity-filters"><strong><?php 
        _e('Show Activity Filters:', 'swa');
        ?>
</strong>
                       <label for="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_yes" > <input id="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_yes" name="<?php 
        echo $this->get_field_name('show_activity_filters');
        ?>
" type="radio" <?php 
        if ($show_activity_filters == 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="yes" style="width: 10%" />Yes</label>
                       <label for="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_no" > <input  id="<?php 
        echo $this->get_field_id('show_activity_filters');
        ?>
_no" name="<?php 
        echo $this->get_field_name('show_activity_filters');
        ?>
" type="radio" <?php 
        if ($show_activity_filters !== 'yes') {
            echo "checked='checked'";
        }
        ?>
 value="no" style="width: 10%" />No</label>

                    </label>
               </p>
               <p><label for="bp-swa-included-filters"><strong><?php 
        _e('Include only following Filters:', 'swa');
        ?>
</strong></label></p>
                 <p>     <?php 
        $recorded_components = BP_Activity_Activity::get_recorded_components();
        foreach ((array) $recorded_components as $component) {
            ?>
                         <label for="<?php 
            echo $this->get_field_id('included_components') . '_' . $component;
            ?>
" ><?php 
            echo ucwords($component);
            ?>
 <input id="<?php 
            echo $this->get_field_id('included_components') . '_' . $component;
            ?>
" name="<?php 
            echo $this->get_field_name('included_components');
            ?>
[]" type="checkbox" <?php 
            if (is_array($included_components) && in_array($component, $included_components)) {
                echo "checked='checked'";
            }
            ?>
 value="<?php 
            echo $component;
            ?>
" style="width: 10%" /></label>
                       <?php 
        }
        ?>
                   
               </p>

              <p><label for="bp-swa-included-filters"><strong><?php 
        _e('Exclude following Components activity', 'swa');
        ?>
</strong></label></p>
                 <p>     <?php 
        $recorded_components = BP_Activity_Activity::get_recorded_components();
        foreach ((array) $recorded_components as $component) {
            ?>
                         <label for="<?php 
            echo $this->get_field_id('excluded_components') . '_' . $component;
            ?>
" ><?php 
            echo ucwords($component);
            ?>
 <input id="<?php 
            echo $this->get_field_id('excluded_components') . '_' . $component;
            ?>
" name="<?php 
            echo $this->get_field_name('excluded_components');
            ?>
[]" type="checkbox" <?php 
            if (is_array($excluded_components) && in_array($component, $excluded_components)) {
                echo "checked='checked'";
            }
            ?>
 value="<?php 
            echo $component;
            ?>
" style="width: 10%" /></label>
                       <?php 
        }
        ?>

               </p>
               
	<?php 
    }
 /**
  * Create filter SQL clauses.
  *
  * @since 1.5.0
  *
  * @param array $filter_array {
  *     Fields and values to filter by.
  *
  *     @type array|string|int $user_id User ID(s).
  *     @type array|string     $object       Corresponds to the 'component'
  *                                          column in the database.
  *     @type array|string     $action       Corresponds to the 'type' column
  *                                          in the database.
  *     @type array|string|int $primary_id   Corresponds to the 'item_id'
  *                                          column in the database.
  *     @type array|string|int $secondary_id Corresponds to the
  *                                          'secondary_item_id' column in the database.
  *     @type int              $offset       Return only those items with an ID greater
  *                                          than the offset value.
  *     @type string           $since        Return only those items that have a
  *                                          date_recorded value greater than a
  *                                          given MySQL-formatted date.
  * }
  * @return string The filter clause, for use in a SQL query.
  */
 public static function get_filter_sql($filter_array)
 {
     $filter_sql = array();
     if (!empty($filter_array['user_id'])) {
         $user_sql = BP_Activity_Activity::get_in_operator_sql('a.user_id', $filter_array['user_id']);
         if (!empty($user_sql)) {
             $filter_sql[] = $user_sql;
         }
     }
     if (!empty($filter_array['object'])) {
         $object_sql = BP_Activity_Activity::get_in_operator_sql('a.component', $filter_array['object']);
         if (!empty($object_sql)) {
             $filter_sql[] = $object_sql;
         }
     }
     if (!empty($filter_array['action'])) {
         $action_sql = BP_Activity_Activity::get_in_operator_sql('a.type', $filter_array['action']);
         if (!empty($action_sql)) {
             $filter_sql[] = $action_sql;
         }
     }
     if (!empty($filter_array['primary_id'])) {
         $pid_sql = BP_Activity_Activity::get_in_operator_sql('a.item_id', $filter_array['primary_id']);
         if (!empty($pid_sql)) {
             $filter_sql[] = $pid_sql;
         }
     }
     if (!empty($filter_array['secondary_id'])) {
         $sid_sql = BP_Activity_Activity::get_in_operator_sql('a.secondary_item_id', $filter_array['secondary_id']);
         if (!empty($sid_sql)) {
             $filter_sql[] = $sid_sql;
         }
     }
     if (!empty($filter_array['offset'])) {
         $sid_sql = absint($filter_array['offset']);
         $filter_sql[] = "a.id >= {$sid_sql}";
     }
     if (!empty($filter_array['since'])) {
         // Validate that this is a proper Y-m-d H:i:s date.
         // Trick: parse to UNIX date then translate back.
         $translated_date = date('Y-m-d H:i:s', strtotime($filter_array['since']));
         if ($translated_date === $filter_array['since']) {
             $filter_sql[] = "a.date_recorded > '{$translated_date}'";
         }
     }
     if (empty($filter_sql)) {
         return false;
     }
     return join(' AND ', $filter_sql);
 }
/**
 * Return the activity filter links.
 *
 * @since BuddyPress (1.1.0)
 *
 * @uses wp_parse_args()
 * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
 * @uses esc_attr()
 * @uses add_query_arg()
 * @uses remove_query_arg()
 * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook.
 * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook.
 *
 * @param array $args {
 *     @type string $style The type of markup to use for the links.
 *           'list', 'paragraph', or 'span'. Default: 'list'.
 * }
 * @return string|bool $component_links The activity filter links.
 *         False on failure.
 */
function bp_get_activity_filter_links($args = false)
{
    $defaults = array('style' => 'list');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Define local variable
    $component_links = array();
    // Fetch the names of components that have activity recorded in the DB
    $components = BP_Activity_Activity::get_recorded_components();
    if (empty($components)) {
        return false;
    }
    foreach ((array) $components as $component) {
        // Skip the activity comment filter
        if ('activity' == $component) {
            continue;
        }
        if (isset($_GET['afilter']) && $component == $_GET['afilter']) {
            $selected = ' class="selected"';
        } else {
            unset($selected);
        }
        $component = esc_attr($component);
        switch ($style) {
            case 'list':
                $tag = 'li';
                $before = '<li id="afilter-' . $component . '"' . $selected . '>';
                $after = '</li>';
                break;
            case 'paragraph':
                $tag = 'p';
                $before = '<p id="afilter-' . $component . '"' . $selected . '>';
                $after = '</p>';
                break;
            case 'span':
                $tag = 'span';
                $before = '<span id="afilter-' . $component . '"' . $selected . '>';
                $after = '</span>';
                break;
        }
        $link = add_query_arg('afilter', $component);
        $link = remove_query_arg('acpage', $link);
        /**
         * Filters the activity filter link URL for the current activity component.
         *
         * @since BuddyPress (1.1.0)
         *
         * @param string $link The URL for the current component.
         * @param string $component The current component getting links constructed for.
         */
        $link = apply_filters('bp_get_activity_filter_link_href', $link, $component);
        $component_links[] = $before . '<a href="' . esc_url($link) . '">' . ucwords($component) . '</a>' . $after;
    }
    $link = remove_query_arg('afilter', $link);
    if (isset($_GET['afilter'])) {
        $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_url($link) . '">' . __('Clear Filter', 'buddypress') . '</a></' . $tag . '>';
    }
    /**
     * Filters all of the constructed filter links.
     *
     * @since BuddyPress (1.1.0)
     *
     * @param string $value All of the links to be displayed to the user.
     */
    return apply_filters('bp_get_activity_filter_links', implode("\n", $component_links));
}
 /**
  * @group get_recorded_components
  */
 public function test_get_recorded_components_skip_last_activity_true_la_in_multiple_components()
 {
     $a1 = $this->factory->activity->create(array('component' => 'members', 'action' => 'last_activity'));
     $a2 = $this->factory->activity->create(array('component' => 'groups', 'action' => 'created_group'));
     $a3 = $this->factory->activity->create(array('component' => 'friends', 'action' => 'friendship_accepted'));
     $a4 = $this->factory->activity->create(array('component' => 'groups', 'action' => 'last_activity'));
     $found = BP_Activity_Activity::get_recorded_components(true);
     sort($found);
     $this->assertSame(array('friends', 'groups'), BP_Activity_Activity::get_recorded_components());
 }
function bp_checkins_update_to_checkin_type($activity_id, $old_activity, $new_type = 'activity_checkin')
{
    if (!empty($activity_id) && !empty($old_activity)) {
        $activity = new BP_Activity_Activity($activity_id);
        $activity->user_id = $old_activity->user_id;
        $activity->component = $old_activity->component;
        $activity->type = $new_type;
        $activity->action = $old_activity->action;
        $activity->content = $old_activity->content;
        $activity->primary_link = $old_activity->primary_link;
        $activity->item_id = $old_activity->item_id;
        $activity->secondary_item_id = $old_activity->secondary_item_id;
        $activity->date_recorded = $old_activity->date_recorded;
        $activity->hide_sitewide = $old_activity->hide_sitewide;
        $test = $activity->save();
    }
}
Beispiel #25
0
/**
 * Hide a user's activity.
 *
 * @since BuddyPress (1.2.0)
 *
 * @uses BP_Activity_Activity::hide_all_for_user() {@link BP_Activity_Activity}
 *
 * @param int $user_id The ID of the user whose activity is being hidden.
 * @return bool True on success, false on failure.
 */
function bp_activity_hide_user_activity($user_id)
{
    return BP_Activity_Activity::hide_all_for_user($user_id);
}
/**
 * Remove a blog comment activity item from the activity stream.
 *
 * @param int $comment_id ID of the comment to be removed.
 */
function bp_blogs_remove_comment($comment_id)
{
    global $wpdb;
    // activity comments are disabled for blog posts
    // which means that individual activity items exist for blog comments
    if (bp_disable_blogforum_comments()) {
        // Delete the individual activity stream item
        bp_blogs_delete_activity(array('item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment'));
        // activity comments are enabled for blog posts
        // remove the associated activity item
    } else {
        // get associated activity ID from comment meta
        $activity_id = get_comment_meta($comment_id, 'bp_activity_comment_id', true);
        // delete the associated activity comment
        //
        // also removes child post comments and associated activity comments
        if (!empty($activity_id) && bp_is_active('activity')) {
            // fetch the activity comments for the activity item
            $activity = bp_activity_get(array('in' => $activity_id, 'display_comments' => 'stream'));
            // get all activity comment IDs for the pending deleted item
            if (!empty($activity['activities'])) {
                $activity_ids = bp_activity_recurse_comments_activity_ids($activity);
                $activity_ids[] = $activity_id;
                // delete activity items
                foreach ($activity_ids as $activity_id) {
                    bp_activity_delete(array('id' => $activity_id));
                }
                // remove associated blog comments
                bp_blogs_remove_associated_blog_comments($activity_ids);
                // rebuild activity comment tree
                BP_Activity_Activity::rebuild_activity_comment_tree($activity['activities'][0]->item_id);
            }
        }
    }
    /**
     * Fires after a blog comment activity item was removed from activity stream.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param int $blogid     Item ID for the blog associated with the removed comment.
     * @param int $comment_id ID of the comment being removed.
     * @param int $value      ID of the current logged in user.
     */
    do_action('bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id());
}
/**
 * Deletes the blog comment when the associated activity comment is deleted.
 *
 * Note: This is hooked on the 'bp_activity_delete_comment_pre' filter instead
 * of the 'bp_activity_delete_comment' action because we need to fetch the
 * activity comment children before they are deleted.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param bool $retval
 * @param int $parent_activity_id The parent activity ID for the activity comment.
 * @param int $activity_id The activity ID for the pending deleted activity comment.
 */
function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {
	// check if parent activity is a blog post
	$parent_activity = new BP_Activity_Activity( $parent_activity_id );
	if ( 'new_blog_post' != $parent_activity->type ) {
		return $retval;
	}

	// fetch the activity comments for the activity item
	$activity = bp_activity_get( array(
		'in'               => $activity_id,
		'display_comments' => 'stream',
	) );

	// get all activity comment IDs for the pending deleted item
	$activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
	$activity_ids[] = $activity_id;

	// handle multisite
	// switch to the blog where the comment was made
	switch_to_blog( $parent_activity->item_id );

	// remove associated blog comments
	bp_blogs_remove_associated_blog_comments( $activity_ids, current_user_can( 'moderate_comments' ) );

	// multisite again!
	restore_current_blog();

	// rebuild activity comment tree
	// emulate bp_activity_delete_comment()
	BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id );

	// we're overriding the default bp_activity_delete_comment() functionality
	// so we need to return false
	return false;
}
/**
 * Return the activity filter links.
 *
 * @since 1.1.0
 *
 * @param array $args Defaults to false
 *
 * @global object $activities_template {@link BP_Activity_Template}
 * @global object $bp BuddyPress global settings
 * @uses nxt_parse_args()
 * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
 * @uses esc_attr()
 * @uses add_query_arg()
 * @uses remove_query_arg()
 * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook
 * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook
 *
 * @return string|bool $component_links The activity filter links. False on failure
 */
function bp_get_activity_filter_links($args = false)
{
    global $activities_template, $bp;
    $defaults = array('style' => 'list');
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Fetch the names of components that have activity recorded in the DB
    $components = BP_Activity_Activity::get_recorded_components();
    if (!$components) {
        return false;
    }
    foreach ((array) $components as $component) {
        /* Skip the activity comment filter */
        if ('activity' == $component) {
            continue;
        }
        if (isset($_GET['afilter']) && $component == $_GET['afilter']) {
            $selected = ' class="selected"';
        } else {
            unset($selected);
        }
        $component = esc_attr($component);
        switch ($style) {
            case 'list':
                $tag = 'li';
                $before = '<li id="afilter-' . $component . '"' . $selected . '>';
                $after = '</li>';
                break;
            case 'paragraph':
                $tag = 'p';
                $before = '<p id="afilter-' . $component . '"' . $selected . '>';
                $after = '</p>';
                break;
            case 'span':
                $tag = 'span';
                $before = '<span id="afilter-' . $component . '"' . $selected . '>';
                $after = '</span>';
                break;
        }
        $link = add_query_arg('afilter', $component);
        $link = remove_query_arg('acpage', $link);
        $link = apply_filters('bp_get_activity_filter_link_href', $link, $component);
        // Make sure all core internal component names are translatable
        $translatable_components = array(__('xprofile', 'buddypress'), __('friends', 'buddypress'), __('groups', 'buddypress'), __('status', 'buddypress'), __('sites', 'buddypress'));
        $component_links[] = $before . '<a href="' . esc_attr($link) . '">' . ucwords(__($component, 'buddypress')) . '</a>' . $after;
    }
    $link = remove_query_arg('afilter', $link);
    if (isset($_GET['afilter'])) {
        $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr($link) . '">' . __('Clear Filter', 'buddypress') . '</a></' . $tag . '>';
    }
    return apply_filters('bp_get_activity_filter_links', implode("\n", $component_links));
}
 function get_filter_sql($filter_array)
 {
     global $nxtdb;
     if (!empty($filter_array['user_id'])) {
         $user_sql = BP_Activity_Activity::get_in_operator_sql('a.user_id', $filter_array['user_id']);
         if (!empty($user_sql)) {
             $filter_sql[] = $user_sql;
         }
     }
     if (!empty($filter_array['object'])) {
         $object_sql = BP_Activity_Activity::get_in_operator_sql('a.component', $filter_array['object']);
         if (!empty($object_sql)) {
             $filter_sql[] = $object_sql;
         }
     }
     if (!empty($filter_array['action'])) {
         $action_sql = BP_Activity_Activity::get_in_operator_sql('a.type', $filter_array['action']);
         if (!empty($action_sql)) {
             $filter_sql[] = $action_sql;
         }
     }
     if (!empty($filter_array['primary_id'])) {
         $pid_sql = BP_Activity_Activity::get_in_operator_sql('a.item_id', $filter_array['primary_id']);
         if (!empty($pid_sql)) {
             $filter_sql[] = $pid_sql;
         }
     }
     if (!empty($filter_array['secondary_id'])) {
         $sid_sql = BP_Activity_Activity::get_in_operator_sql('a.secondary_item_id', $filter_array['secondary_id']);
         if (!empty($sid_sql)) {
             $filter_sql[] = $sid_sql;
         }
     }
     if (empty($filter_sql)) {
         return false;
     }
     return join(' AND ', $filter_sql);
 }
Beispiel #30
0
function mpp_delete_activity_by_meta_key_value($key, $object_id = null)
{
    global $bp, $wpdb;
    if (!bp_is_active('activity')) {
        return false;
        //or false?
    }
    $where_sql = array();
    $where_sql[] = $wpdb->prepare('meta_key=%s', $key);
    if ($object_id) {
        $where_sql[] = $wpdb->prepare('meta_value = %d', $object_id);
    }
    $where_sql = join(' AND ', $where_sql);
    // Fetch the activity IDs so we can delete any comments for this activity item
    $activity_ids = $wpdb->get_col("SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE {$where_sql}");
    if (empty($activity_ids)) {
        return false;
    }
    $list = '(' . join(',', $activity_ids) . ')';
    if (!$wpdb->query("DELETE FROM {$bp->activity->table_name} WHERE id IN {$list}")) {
        return false;
    }
    // Handle accompanying activity comments and meta deletion
    if ($activity_ids) {
        $activity_ids_comma = implode(',', wp_parse_id_list($activity_ids));
        $activity_comments_where_sql = "WHERE type = 'activity_comment' AND item_id IN ({$activity_ids_comma})";
        // Fetch the activity comment IDs for our deleted activity items
        $activity_comment_ids = $wpdb->get_col("SELECT id FROM {$bp->activity->table_name} {$activity_comments_where_sql}");
        // We have activity comments!
        if (!empty($activity_comment_ids)) {
            // Delete activity comments
            $wpdb->query("DELETE FROM {$bp->activity->table_name} {$activity_comments_where_sql}");
            // Merge activity IDs with activity comment IDs
            $activity_ids = array_merge($activity_ids, $activity_comment_ids);
        }
        // Delete all activity meta entries for activity items and activity comments
        BP_Activity_Activity::delete_activity_meta_entries($activity_ids);
    }
    return $activity_ids;
}