function vortex_update_meta($post_id, $key, $value) { $bbp = vortex_is_buddypress($post_id); if ($bbp) { return bp_activity_update_meta($post_id, $key, $value); } else { return update_post_meta($post_id, $key, $value); } }
function bp_course_record_activity_meta($args = '') { if (!function_exists('bp_activity_update_meta')) { return false; } $defaults = array('id' => false, 'meta_key' => '', 'meta_value' => ''); $r = wp_parse_args($args, $defaults); extract($r); return bp_activity_update_meta($id, $meta_key, $meta_value); }
/** * @group get */ public function test_get_with_meta_query_two_clauses_with_or_relation() { $now = time(); $a1 = $this->factory->activity->create(array('recorded_time' => date('Y-m-d H:i:s', $now))); $a2 = $this->factory->activity->create(array('recorded_time' => date('Y-m-d H:i:s', $now - 60))); $a3 = $this->factory->activity->create(array('recorded_time' => date('Y-m-d H:i:s', $now - 120))); bp_activity_update_meta($a1, 'foo', 'bar'); bp_activity_update_meta($a2, 'foo', 'bar'); bp_activity_update_meta($a1, 'baz', 'barry'); $activity = BP_Activity_Activity::get(array('meta_query' => array('relation' => 'OR', array('key' => 'foo', 'value' => 'bar'), array('key' => 'baz', 'value' => 'barry')), 'count_total' => 'count_query')); $ids = wp_list_pluck($activity['activities'], 'id'); $this->assertEquals(array($a1, $a2), $ids); $this->assertEquals(2, $activity['total']); }
/** * Saves a BuddyPress Activity * * @param stdObject $activity Row from the activity table * @return boolean (TRUE if there were actually Bible references to save) */ public function save_activity($activity) { // Add any read passage strings if (!empty($activity->bfox_read_ref_str)) { bp_activity_update_meta($activity->id, 'bfox_read_ref_str', $activity->bfox_read_ref_str); do_action('bfox_save_activity_read_ref_str', $activity); } if ($success = $this->save_item($activity->id, apply_filters('bfox_save_activity_ref', $activity->bfox_ref, $activity))) { // If we successfully saved some Bible references, lets cache the string in the activity meta // That way we don't have to recalculate it each time which could be a pain // For example, recalculating the references for a blog post requires switching to that blog, getting the blog post and parsing it // Instead, we can just use this meta bp_activity_update_meta($activity->id, 'bfox_ref_str', $activity->bfox_ref->get_string(BibleMeta::name_short)); } return $success; }
/** * @group bp_activity_update_meta_cache */ public function test_bp_activity_update_meta_cache() { $a1 = $this->factory->activity->create(); $a2 = $this->factory->activity->create(); // Set up some data bp_activity_update_meta($a1, 'foo', 'bar'); bp_activity_update_meta($a1, 'Boone', 'Rules'); bp_activity_update_meta($a2, 'foo', 'baz'); bp_activity_update_meta($a2, 'BuddyPress', 'Is Cool'); // Prime the cache for $a1 bp_activity_get_meta($a1, 'foo'); // Ensure an empty cache for $a2 wp_cache_delete($a2, 'activity_meta'); bp_activity_update_meta_cache(array($a1, $a2)); $expected = array($a1 => array('foo' => array('bar'), 'Boone' => array('Rules')), $a2 => array('foo' => array('baz'), 'BuddyPress' => array('Is Cool'))); $found = array($a1 => wp_cache_get($a1, 'activity_meta'), $a2 => wp_cache_get($a2, 'activity_meta')); $this->assertEquals($expected, $found); }
/** * Handles the uploaded media file and creates attachment post for the file. * * @since BP Media 2.0 */ function add_media($name, $description) { global $bp, $wpdb, $bp_media_count; include_once(ABSPATH . 'wp-admin/includes/file.php'); include_once(ABSPATH . 'wp-admin/includes/image.php'); //media_handle_upload('async-upload', $_REQUEST['post_id']); $postarr = array( 'post_status' => 'draft', 'post_type' => 'bp_media', 'post_content' => $description, 'post_title' => $name ); $post_id = wp_insert_post($postarr); $file = wp_handle_upload($_FILES['bp_media_file']); if (isset($file['error']) || $file === null) { wp_delete_post($post_id, true); throw new Exception(__('Error Uploading File', 'bp-media')); } $attachment = array(); $url = $file['url']; $type = $file['type']; $file = $file['file']; $title = $name; $content = $description; $attachment = array( 'post_mime_type' => $type, 'guid' => $url, 'post_title' => $title, 'post_content' => $content, 'post_parent' => $post_id, ); bp_media_init_count(bp_loggedin_user_id()); switch ($type) { case 'video/mp4' : $type = 'video'; include_once(trailingslashit(BP_MEDIA_PLUGIN_DIR) . 'includes/lib/getid3/getid3.php'); try { $getID3 = new getID3; $vid_info = $getID3->analyze($file); } catch (Exception $e) { wp_delete_post($post_id, true); unlink($file); $activity_content = false; throw new Exception(__('MP4 file you have uploaded is currupt.', 'bp-media')); } if (is_array($vid_info)) { if (!array_key_exists('error',$vid_info)&& array_key_exists('fileformat', $vid_info) && array_key_exists('video', $vid_info)&&array_key_exists('fourcc',$vid_info['video'])) { if (!($vid_info['fileformat']=='mp4'&&$vid_info['video']['fourcc']=='avc1')) { wp_delete_post($post_id, true); unlink($file); $activity_content = false; throw new Exception(__('The MP4 file you have uploaded is using an unsupported video codec. Supported video codec is H.264.', 'bp-media')); } } else { wp_delete_post($post_id, true); unlink($file); $activity_content = false; throw new Exception(__('The MP4 file you have uploaded is using an unsupported video codec. Supported video codec is H.264.', 'bp-media')); } } else { wp_delete_post($post_id, true); unlink($file); $activity_content = false; throw new Exception(__('The MP4 file you have uploaded is not a video file.', 'bp-media')); } $bp_media_count['videos'] = intval($bp_media_count['videos']) + 1; break; case 'audio/mpeg' : $type = 'audio'; $bp_media_count['audio'] = intval($bp_media_count['audio']) + 1; break; case 'image/gif' : case 'image/jpeg' : case 'image/png' : $type = 'image'; $bp_media_count['images'] = intval($bp_media_count['images']) + 1; break; default : unlink($file); wp_delete_post($post_id, true); unlink($file); $activity_content = false; throw new Exception(__('Media File you have tried to upload is not supported. Supported media files are .jpg, .png, .gif, .mp3 and .mp4.', 'bp-media')); } $attachment_id = wp_insert_attachment($attachment, $file, $post_id); if (!is_wp_error($attachment_id)) { wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $file)); } else { wp_delete_post($post_id, true); unlink($file); throw new Exception(__('Error creating activity for the media file, please try again', 'bp-media')); } $postarr['ID'] = $post_id; $postarr['post_mime_type'] = $type; $postarr['post_status'] = 'publish'; wp_insert_post($postarr); $activity_content = '[bp_media_content id="' . $post_id . '"]'; $activity_id = bp_media_record_activity(array( 'action' => '[bp_media_action id="' . $post_id . '"]', 'content' => $activity_content, 'primary_link' => '[bp_media_url id="' . $post_id . '"]', 'type' => 'media_upload' )); bp_activity_update_meta($activity_id, 'bp_media_parent_post', $post_id); update_post_meta($post_id, 'bp_media_child_activity', $activity_id); update_post_meta($post_id, 'bp_media_child_attachment', $attachment_id); update_post_meta($post_id, 'bp_media_type', $type); update_post_meta($post_id, 'bp_media_hosting', 'wordpress'); $this->id = $post_id; $this->name = $name; $this->description = $description; $this->owner = bp_loggedin_user_id(); $this->type = $type; $this->url = $url; bp_update_user_meta(bp_loggedin_user_id(), 'bp_media_count', $bp_media_count); }
function add_rating($args = '') { global $bp; $defaults = array('group_id' => $bp->groups->current_group->id, 'score' => false, 'user_id' => $bp->loggedin_user->id, 'activity_id' => false); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (empty($score)) { return false; } // First record the activity meta for this particular rating bp_activity_update_meta($activity_id, 'bpgr_rating', $score); // Then add this item to the list of reviews for this group if (!($ratings = groups_get_groupmeta($group_id, 'bpgr_ratings'))) { $ratings = array(); } $ratings[$activity_id] = $score; // Pull the composite scores and recalculate if (!($rating = groups_get_groupmeta($group_id, 'bpgr_rating'))) { $avg_score = 0; } if (!($how_many = (int) groups_get_groupmeta($group_id, 'bpgr_how_many_ratings'))) { $how_many = 0; } $how_many++; groups_update_groupmeta($group_id, 'bpgr_how_many_ratings', $how_many); $raw_score = 0; foreach ($ratings as $score) { $raw_score += (int) $score; } $rating = $raw_score / $how_many; groups_update_groupmeta($group_id, 'bpgr_rating', $rating); groups_update_groupmeta($group_id, 'bpgr_ratings', $ratings); }
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; }
function bp_activity_posted_update($content, $user_id, $activity_id) { global $wpdb, $bp; $updated_content = ''; // hook for rtmedia buddypress before activity posted do_action('rtmedia_bp_before_activity_posted', $content, $user_id, $activity_id); if (isset($_POST['rtMedia_attached_files']) && is_array($_POST['rtMedia_attached_files'])) { $updated_content = $wpdb->get_var("select content from {$bp->activity->table_name} where id= {$activity_id}"); $objActivity = new RTMediaActivity($_POST['rtMedia_attached_files'], 0, $updated_content); $html_content = $objActivity->create_activity_html(); bp_activity_update_meta($activity_id, 'bp_old_activity_content', $html_content); bp_activity_update_meta($activity_id, 'bp_activity_text', $updated_content); $wpdb->update($bp->activity->table_name, array('type' => 'rtmedia_update', 'content' => $html_content), array('id' => $activity_id)); $mediaObj = new RTMediaModel(); $sql = "update {$mediaObj->table_name} set activity_id = '" . $activity_id . "' where blog_id = '" . get_current_blog_id() . "' and id in (" . implode(',', $_POST['rtMedia_attached_files']) . ')'; $wpdb->query($sql); } // hook for rtmedia buddypress after activity posted do_action('rtmedia_bp_activity_posted', $updated_content, $user_id, $activity_id); if (isset($_POST['rtmedia-privacy'])) { $privacy = -1; if (is_rtmedia_privacy_enable()) { if (is_rtmedia_privacy_user_overide()) { $privacy = $_POST['rtmedia-privacy']; } else { $privacy = get_rtmedia_default_privacy(); } } bp_activity_update_meta($activity_id, 'rtmedia_privacy', $privacy); // insert/update activity details in rtmedia activity table $rtmedia_activity_model = new RTMediaActivityModel(); if (!$rtmedia_activity_model->check($activity_id)) { $rtmedia_activity_model->insert(array('activity_id' => $activity_id, 'user_id' => $user_id, 'privacy' => $privacy)); } else { $rtmedia_activity_model->update(array('activity_id' => $activity_id, 'user_id' => $user_id, 'privacy' => $privacy), array('activity_id' => $activity_id)); } } }
/** * Set an activity item's embed cache. * * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}. * * @since BuddyPress (1.5.0) * * @see BP_Embed::parse_oembed() * @uses bp_activity_update_meta() * * @param string $cache An empty string passed by BP_Embed::parse_oembed() for * functions like this one to filter. * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). * @param int $id The ID of the activity item. * @return bool True on success, false on failure. */ function bp_embed_activity_save_cache($cache, $cachekey, $id) { bp_activity_update_meta($id, $cachekey, $cache); }
function bp_cover_group_handle_upload($activity_id) { global $bp, $wpdb; $group_id = bp_get_current_group_id(); $activity_table = $wpdb->prefix . "bp_activity"; $activity_meta_table = $wpdb->prefix . "bp_activity_meta"; $sql = "SELECT COUNT(*) as photo_count FROM {$activity_table} a INNER JOIN {$activity_meta_table} am ON a.id = am.activity_id WHERE a.item_id = %d AND meta_key = 'all_bp_cover_group'"; $sql = $wpdb->prepare($sql, $group_id); $cnt = $wpdb->get_var($sql); $max_cnt = bp_cover_get_max_total(); if ($cnt < $max_cnt) { if ($_POST['encodedimg']) { $file = $_POST['imgsize']; $max_upload_size = bp_cover_get_max_media_size(); if ($max_upload_size > $file) { $group_id = $bp->groups->current_group->id; $imgresponse = array(); $uploaddir = wp_upload_dir(); /* let's decode the base64 encoded image sent */ $img = $_POST['encodedimg']; $img = str_replace('data:' . $_POST['imgtype'] . ';base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $imgname = wp_unique_filename($uploaddir['path'], $_POST['imgname']); $filepath = $uploaddir['path'] . '/' . $imgname; $fileurl = $uploaddir['url'] . '/' . $imgname; /* now we write the image in dir */ $success = file_put_contents($filepath, $data); if ($success) { $imgresponse[0] = "1"; $imgresponse[1] = $fileurl; $size = @getimagesize($filepath); $attachment = array('post_mime_type' => $_POST['imgtype'], 'guid' => $fileurl, 'post_title' => $imgname); require_once ABSPATH . 'wp-admin/includes/image.php'; $attachment_id = wp_insert_attachment($attachment, $filepath); $attach_data = wp_generate_attachment_metadata($attachment_id, $filepath); wp_update_attachment_metadata($attachment_id, $attach_data); groups_update_groupmeta($group_id, 'bp_cover_group', $fileurl); groups_update_groupmeta($group_id, 'bp_cover_group_position', 0); $group = groups_get_group(array("group_id" => $group_id)); $activity_id = groups_record_activity(array('action' => sprintf(__('%s uploaded a new cover picture to the group %s', 'bp-cover'), bp_core_get_userlink($bp->loggedin_user->id), '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'), 'type' => 'cover_added', 'item_id' => $group_id, 'content' => bp_cover_group_get_image_scr(), 'item_id' => $group_id)); bp_activity_update_meta($activity_id, 'all_bp_cover_group', $attachment_id); update_post_meta($attachment_id, 'bp_cover_group_thumb', $imgresponse[2]); } else { $imgresponse[0] = "0"; $imgresponse[1] = __('Upload Failed! Unable to write the image on server', 'bp-cover'); } } else { $imgresponse[0] = "0"; $imgresponse[1] = sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'bp-cover'), size_format($max_upload_size)); } } else { $imgresponse[0] = "0"; $imgresponse[1] = __('Upload Failed! No image sent', 'bp-cover'); } } else { $imgresponse[0] = "0"; $imgresponse[1] = sprintf(__('Max total images allowed %d in a cover gallery', 'bp-cover'), $max_cnt); } /* if everything is ok, we send back url to thumbnail and to full image */ echo json_encode($imgresponse); die; }
function bp_checkins_untrashed_place($place_id) { // we need to rebuilt the activity type new_place and its activity_meta if (empty($place_id)) { return false; } $place = get_post($place_id); if (!in_array($place->post_type, array('places'))) { return false; } /* do we have a group_id ? */ $group_id = get_post_meta($place_id, '_bpci_group_id', true); /* let's build the activity vars */ $place_name = esc_attr($place->post_title); $thumbnail = bp_get_checkins_places_featured_image($place_id); $excerpt = bp_get_checkins_places_excerpt($place->post_content); $place_content = apply_filters('bp_checkins_place_content_before_activity', $thumbnail . $excerpt); $args = array('content' => $place_content, 'user_id' => $place->post_author, 'type' => 'new_place', 'place_id' => $place_id, 'place_name' => $place_name, 'recorded_time' => $place->post_date_gmt); if (!empty($group_id) && $group_id != 0) { // adding the group_id to args. $args['group_id'] = $group_id; $activity_id = bp_checkins_groups_post_update($args); } else { $activity_id = bp_checkins_post_update($args); } if (!empty($activity_id)) { /* * now we store the post meta as activity meta * this way if cookies of superadmin were writen * we'll be sure to have the correct values. */ $lat = get_post_meta($place_id, 'bpci_places_lat', true); $lng = get_post_meta($place_id, 'bpci_places_lng', true); $address = get_post_meta($place_id, 'bpci_places_address', true); if (empty($lat) || empty($lng) || empty($address)) { return false; } bp_activity_update_meta($activity_id, 'bpci_activity_lat', $lat); bp_activity_update_meta($activity_id, 'bpci_activity_lng', $lng); bp_activity_update_meta($activity_id, 'bpci_activity_address', $address); } }
/** * In case of a reshare delete, reset some activity metas * * @package BP Reshare * @since 1.0 * * @param integer $activity_id the reshared activity id * @param integer $user_id the user id * @uses bp_activity_get_meta() to get some meta infos about the activity * @uses bp_activity_delete_meta() to delete some meta infos for the activity * @uses bp_activity_update_meta() to save some meta infos for the activity * @return boolean true */ function buddyreshare_reset_metas($activity_id = 0, $user_id = 0) { if (empty($activity_id) || empty($user_id)) { return false; } $count = bp_activity_get_meta($activity_id, 'reshared_count'); $count = $count - 1; $reshared_by = bp_activity_get_meta($activity_id, 'reshared_by'); if ($count == 0) { // if count is null, then we can delete all metas ! bp_activity_delete_meta($activity_id, 'reshared_count'); bp_activity_delete_meta($activity_id, 'reshared_by'); } else { foreach ($reshared_by as $key => $val) { if ($user_id == $val) { unset($reshared_by[$key]); } } bp_activity_update_meta($activity_id, 'reshared_count', $count); bp_activity_update_meta($activity_id, 'reshared_by', $reshared_by); } return true; }
/** * Syncs activity comments and posts them back as blog comments. * * Note: This is only a one-way sync - activity comments -> blog comment. * * For blog post -> activity comment, see {@link bp_activity_post_type_comment()}. * * @since 2.0.0 * @since 2.5.0 Allow custom post types to sync their comments with activity ones * * @param int $comment_id The activity ID for the posted activity comment. * @param array $params Parameters for the activity comment. * @param object $parent_activity Parameters of the parent activity item (in this case, the blog post). */ function bp_blogs_sync_add_from_activity_comment($comment_id, $params, $parent_activity) { // 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; } // If activity comments are disabled for blog posts, stop now! if (bp_disable_blogforum_comments()) { return; } // Get userdata. if ($params['user_id'] == bp_loggedin_user_id()) { $user = buddypress()->loggedin_user->userdata; } else { $user = bp_core_get_core_userdata($params['user_id']); } // Get associated post type and set default comment parent $post_type = bp_activity_post_type_get_tracking_arg($parent_activity->type, 'post_type'); $comment_parent = 0; // See if a parent WP comment ID exists. if (!empty($params['parent_id']) && !empty($post_type)) { $comment_parent = bp_activity_get_meta($params['parent_id'], "bp_blogs_{$post_type}_comment_id"); } // Comment args. $args = array('comment_post_ID' => $parent_activity->secondary_item_id, 'comment_author' => bp_core_get_user_displayname($params['user_id']), 'comment_author_email' => $user->user_email, 'comment_author_url' => bp_core_get_user_domain($params['user_id'], $user->user_nicename, $user->user_login), 'comment_content' => $params['content'], 'comment_type' => '', 'comment_parent' => (int) $comment_parent, 'user_id' => $params['user_id'], 'comment_approved' => 1); // Prevent separate activity entry being made. remove_action('comment_post', 'bp_activity_post_type_comment', 10, 2); // Handle multisite. switch_to_blog($parent_activity->item_id); // Handle timestamps for the WP comment after we've switched to the blog. $args['comment_date'] = current_time('mysql'); $args['comment_date_gmt'] = current_time('mysql', 1); // Post the comment. $post_comment_id = wp_insert_comment($args); // Add meta to comment. add_comment_meta($post_comment_id, 'bp_activity_comment_id', $comment_id); // Add meta to activity comment. if (!empty($post_type)) { bp_activity_update_meta($comment_id, "bp_blogs_{$post_type}_comment_id", $post_comment_id); } // Resave activity comment with WP comment permalink. // // in bp_blogs_activity_comment_permalink(), we change activity comment // permalinks to use the post comment link // // @todo since this is done after AJAX posting, the activity comment permalink // doesn't change on the frontend until the next page refresh. $resave_activity = new BP_Activity_Activity($comment_id); $resave_activity->primary_link = get_comment_link($post_comment_id); /** * Now that the activity id exists and the post comment was created, we don't need to update * the content of the comment as there are no chances it has evolved. */ remove_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20); $resave_activity->save(); // Add the edit activity comment hook back. add_action('bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20); // Multisite again! restore_current_blog(); // Add the comment hook back. add_action('comment_post', 'bp_activity_post_type_comment', 10, 2); /** * Fires after activity comments have been synced and posted as blog comments. * * @since 2.0.0 * * @param int $comment_id The activity ID for the posted activity comment. * @param array $args Array of args used for the comment syncing. * @param object $parent_activity Parameters of the blog post parent activity item. * @param object $user User data object for the blog comment. */ do_action('bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user); }
/** * Update meta data * * @author Alimir * @param Integer $id * @param String $key * @param Integer $data * @since 2.0 * @updated 2.2 * @return Void */ public function update_meta_data($id, $key, $data) { if ($key == "_liked" || $key == "_topicliked") { update_post_meta($id, $key, $data); } else { if ($key == "_commentliked") { update_comment_meta($id, $key, $data); } else { if ($key == "_activityliked") { bp_activity_update_meta($id, $key, $data); } else { return 0; } } } }
/** * */ function unpin_activity() { global $wpdb; $nonce = isset($_REQUEST['nonces']) ? sanitize_text_field($_REQUEST['nonces']) : 0; if (!wp_verify_nonce($nonce, 'pin-activity-nonce')) { exit(__('Not permitted', RW_Sticky_Activity::$textdomain)); } $activityID = isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ? $_REQUEST['id'] : ''; if ($activityID != '') { bp_activity_update_meta($activityID, 'rw_sticky_activity', 0); } $meta_query_args = array('relation' => 'AND', array('key' => 'rw_sticky_activity', 'value' => '1', 'compare' => '=')); if (function_exists('bb_bp_activity_url_filter')) { // deactivate BuddyBoss Wall activity url preview remove_action('bp_get_activity_content_body', 'bb_bp_activity_url_filter'); } add_filter('bp_activity_excerpt_length', function () { return 99999; }); if (bp_has_activities(array('meta_query' => $meta_query_args))) { ?> <?php while (bp_activities()) { bp_the_activity(); ?> <div class="buddypress-sa"> <div id="factivity-stream"> <div class="activity-list"> <div class="activity-content" style="margin-left: 0px;"> <?php $nonce = wp_create_nonce('pin-activity-nonce'); $title = __('Unpin activity', RW_Sticky_Activity::$textdomain); $class = "sa-button-unpin pinned"; ?> <a href="" class="fa fa-map-marker icon-button sa-button <?php echo $class; ?> " title="<?php echo $title; ?> " data-post-nonces="<?php echo $nonce; ?> " data-post-id="<?php echo bp_get_activity_id(); ?> "></a> <?php if (bp_activity_has_content() && bp_get_activity_type() != 'bbp_topic_create' && bp_get_activity_type() != 'bbp_reply_create') { ?> <div class="activity-inner"> <?php bp_activity_content_body(); ?> </div> <?php } ?> <?php if (bp_get_activity_type() == 'bp_doc_edited') { ?> <div class="activity-inner"><p> <?php $doc = get_post(url_to_postid(bp_get_activity_feed_item_link())); echo __('Doc: ', RW_Sticky_Activity::$textdomain); echo "<a href='" . get_permalink($doc->ID) . "'>"; echo $doc->post_title; echo "</a>"; ?> </p> </div> <?php } // New forum topic created if (bp_get_activity_type() == 'bbp_topic_create') { // url_to_postid fails on permalinks like http://gruppen.domain.tld/groups/frank-testgruppe/forum/topic/neues-thema/ !!! ?> <div class="activity-inner"><p> <?php $link = bp_get_activity_feed_item_link(); $guid = substr($link, strpos($link, "/forum/topic") + 6); $topicid = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid like '%%%s%%'", $guid)); $topic = get_post($topicid); echo __('Forum new topic: ', RW_Sticky_Activity::$textdomain); echo "<a href='" . get_permalink($topic->ID) . "'> "; echo $topic->post_title; echo "</a><br>"; ?> </p> </div> <?php } // New forum reply if (bp_get_activity_type() == 'bbp_reply_create') { // url_to_postid fails on permalinks like http://gruppen.domain.tld/groups/frank-testgruppe/forum/topic/neues-thema/ !!! ?> <div class="activity-inner"><p> <?php $link = bp_get_activity_feed_item_link(); $id = substr($link, strpos($link, "/#post-") + 7); $topic = get_post($id); echo __('Forum reply: ', RW_Sticky_Activity::$textdomain); echo "<a href='" . get_permalink($topic->ID) . "'> "; $parent = get_post($topic->post_parent); echo $parent->post_title; echo "</a><br>"; ?> </p> </div> <?php } ?> <div class="activity-header"> <?php $userid = bp_get_activity_user_id(); $user = get_user_by('id', $userid); echo "(" . $user->nickname . ")"; ?> </div> <div class="clearfix"></div> </div> </div> </div> </div> <?php } ?> <?php } if (function_exists('bb_bp_activity_url_filter')) { // activate BuddyBoss Wall activity url preview add_action('bp_get_activity_content_body', 'bb_bp_activity_url_filter'); } wp_die(); }
/** * This will save some data to the activity meta table when someone posts a picture * * @since BuddyBoss 2.0 */ function buddyboss_pics_input_filter(&$activity) { global $bp, $buddy_boss_wall; $user = $bp->loggedin_user; $new_action = $result = false; if (strstr($activity->content, 'class="buddyboss-pics-picture-link"') !== false && isset($_POST['has_pic']) && isset($_POST['has_pic']['attachment_id'])) { $action = '<a href="' . $user->domain . '">' . $user->fullname . '</a> ' . __('posted a new picture', 'buddyboss'); bp_activity_update_meta($activity->id, 'bboss_pics_action', $action); bp_activity_update_meta($activity->id, 'bboss_pics_aid', $_POST['has_pic']['attachment_id']); } }
/** * bp_like_remove_user_like() * * Registers that the user has unliked a given item. * */ function bp_like_remove_user_like($item_id = '', $type = 'activity') { global $bp; if (!$item_id) { return false; } if (!isset($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') { /* Remove this from the users liked activities. */ $user_likes = get_user_meta($user_id, 'bp_liked_activities', true); unset($user_likes[$item_id]); update_user_meta($user_id, 'bp_liked_activities', $user_likes); /* Update the total number of users who have liked this activity. */ $users_who_like = bp_activity_get_meta($item_id, 'liked_count', true); unset($users_who_like[$user_id]); /* If nobody likes the activity, delete the meta for it to save space, otherwise, update the meta */ if (empty($users_who_like)) { bp_activity_delete_meta($item_id, 'liked_count'); } else { bp_activity_update_meta($item_id, 'liked_count', $users_who_like); } $liked_count = count($users_who_like); /* Remove the update on the users profile from when they liked the activity. */ $update_id = bp_activity_get_activity_id(array('item_id' => $item_id, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id)); bp_activity_delete(array('id' => $update_id, 'item_id' => $item_id, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id)); } elseif ($type == 'blogpost') { /* Remove this from the users liked activities. */ $user_likes = get_user_meta($user_id, 'bp_liked_blogposts', true); unset($user_likes[$item_id]); update_user_meta($user_id, 'bp_liked_blogposts', $user_likes); /* Update the total number of users who have liked this blog post. */ $users_who_like = get_post_meta($item_id, 'liked_count', true); unset($users_who_like[$user_id]); /* If nobody likes the blog post, delete the meta for it to save space, otherwise, update the meta */ if (empty($users_who_like)) { delete_post_meta($item_id, 'liked_count'); } else { update_post_meta($item_id, 'liked_count', $users_who_like); } $liked_count = count($users_who_like); /* Remove the update on the users profile from when they liked the activity. */ $update_id = bp_activity_get_activity_id(array('item_id' => $item_id, 'component' => 'bp-like', 'type' => 'blogpost_liked', 'user_id' => $user_id)); bp_activity_delete(array('id' => $update_id, 'item_id' => $item_id, 'component' => 'bp-like', 'type' => 'blogpost_liked', 'user_id' => $user_id)); } echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } }
/** * Integration test for 'meta_query' param */ function test_bp_has_activities_with_meta_query() { $a1 = $this->factory->activity->create(); $a2 = $this->factory->activity->create(); bp_activity_update_meta($a1, 'foo', 'bar'); global $activities_template; bp_has_activities(array('meta_query' => array(array('key' => 'foo', 'value' => 'bar')))); $ids = wp_list_pluck($activities_template->activities, 'id'); $this->assertEquals($ids, array($a1)); }
/** * Update an activity item's Akismet history * * @param int $activity_id Activity item ID * @param string $message Human-readable description of what's changed * @param string $event The type of check we were carrying out * @since BuddyPress (1.6) */ public function update_activity_history($activity_id = 0, $message = '', $event = '') { $event = array('event' => $event, 'message' => $message, 'time' => akismet_microtime(), 'user' => bp_loggedin_user_id()); // Save the history data bp_activity_update_meta($activity_id, '_bp_akismet_history', $event); }
/** * Function to fetch group feeds and save RSS entries as BP activity items. * * @param int $group_id The group ID. */ function bp_groupblogs_fetch_group_feeds($group_id = false) { if (empty($group_id)) { $group_id = bp_get_current_group_id(); } if ($group_id == bp_get_current_group_id()) { $group = groups_get_current_group(); } else { $group = new BP_Groups_Group($group_id); } if (!$group) { return false; } $group_blogs = groups_get_groupmeta($group_id, 'blogfeeds'); $items = array(); foreach ((array) $group_blogs as $feed_url) { $feed_url = trim($feed_url); if (empty($feed_url)) { continue; } // Make sure the feed is accessible $test = wp_remote_get($feed_url); if (is_wp_error($test)) { continue; } try { $rss = new SimpleXmlElement($test['body']); } catch (Exception $e) { continue; } $rss = fetch_feed(trim($feed_url)); if (!is_wp_error($rss)) { $maxitems = $rss->get_item_quantity(10); $rss_items = $rss->get_items(0, $maxitems); foreach ($rss_items as $item) { $key = $item->get_date('U'); $items[$key]['title'] = $item->get_title(); $items[$key]['subtitle'] = $item->get_title(); //$items[$key]['author'] = $item->get_author()->get_name(); $items[$key]['blogname'] = $item->get_feed()->get_title(); $items[$key]['link'] = $item->get_permalink(); $items[$key]['blogurl'] = $item->get_feed()->get_link(); $items[$key]['description'] = $item->get_description(); $items[$key]['source'] = $item->get_source(); $items[$key]['copyright'] = $item->get_copyright(); $items[$key]['primary_link'] = $item->get_link(); $items[$key]['guid'] = $item->get_id(); $items[$key]['feedurl'] = $feed_url; } } } if (!empty($items)) { ksort($items); $items = array_reverse($items, true); } else { return false; } /* Set the visibility */ $hide_sitewide = 'public' != $group->status ? true : false; /* Record found blog posts in activity streams */ foreach ((array) $items as $post_date => $post) { $activity_action = sprintf(__('Blog: %s from %s in the group %s', 'bp-groups-externalblogs'), '<a class="feed-link" href="' . esc_attr($post['link']) . '">' . esc_attr($post['title']) . '</a>', '<a class="feed-author" href="' . esc_attr($post['blogurl']) . '">' . esc_attr($post['blogname']) . '</a>', '<a href="' . bp_get_group_permalink($group) . '">' . esc_attr($group->name) . '</a>'); $activity_content = '<div>' . strip_tags(bp_create_excerpt($post['description'], 175)) . '</div>'; $activity_content = apply_filters('bp_groupblogs_activity_content', $activity_content, $post, $group); /* Fetch an existing activity_id if one exists. */ // backpat $id = bp_activity_get_activity_id(array('user_id' => false, 'action' => $activity_action, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'secondary_item_id' => wp_hash($post['blogurl']))); // new method if (empty($id)) { $existing = bp_activity_get(array('user_id' => false, 'component' => 'groups', 'type' => 'exb', 'item_id' => $group_id, 'update_meta_cache' => false, 'display_comments' => false, 'meta_query' => array(array('key' => 'exb_guid', 'value' => $post['guid'])))); // we've found an existing entry if (!empty($existing['activities'])) { $id = (int) $existing['activities'][0]->id; } } /* Record or update in activity streams. */ // Skip if it already exists if (empty($id)) { $aid = groups_record_activity(array('id' => $id, 'user_id' => false, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $post['primary_link'], 'type' => 'exb', 'item_id' => $group_id, 'recorded_time' => gmdate("Y-m-d H:i:s", $post_date), 'hide_sitewide' => $hide_sitewide)); // save rss guid as activity meta bp_activity_update_meta($aid, 'exb_guid', $post['guid']); bp_activity_update_meta($aid, 'exb_feedurl', $post['feedurl']); } } return $items; }
/** * 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); } }
function bp_checkins_post_foursquare_updates($args) { global $bp; $defaults = array('action' => '', 'content' => '', 'component' => 'checkins', 'type' => 'foursquare_checkin', 'primary_link' => '', 'user_id' => $bp->loggedin_user->id, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'bp_checkins_meta' => false, 'hide_sitewide' => false); $params = wp_parse_args($args, $defaults); extract($params, EXTR_SKIP); $activity_id = bp_activity_add(array('user_id' => $user_id, 'action' => apply_filters('bp_activity_new_update_action', $action), 'content' => apply_filters('bp_activity_new_update_content', $content), 'primary_link' => apply_filters('bp_activity_new_update_primary_link', $primary_link), 'component' => $component, 'type' => $type, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide)); if ($activity_id && $bp_checkins_meta && is_array($bp_checkins_meta)) { foreach ($bp_checkins_meta as $meta_key => $meta_value) { bp_activity_update_meta($activity_id, $meta_key, $meta_value); } } if ($activity_id) { return 1; } }
/** * Set an activity item's embed cache. * * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}. * * @since 1.5.0 * * @see BP_Embed::parse_oembed() * * @param string $cache An empty string passed by BP_Embed::parse_oembed() for * functions like this one to filter. * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). * @param int $id The ID of the activity item. */ function bp_embed_activity_save_cache($cache, $cachekey, $id) { bp_activity_update_meta($id, $cachekey, $cache); // Cache full oEmbed response. if (true === isset(buddypress()->activity->oembed_response)) { $cachekey = str_replace('_oembed', '_oembed_response', $cachekey); bp_activity_update_meta($id, $cachekey, buddypress()->activity->oembed_response); } }
/** * Update entity custom fields */ public function updateCustomFields($identifier, $likes, $dislikes, $url = '') { global $wpdb; $likebtn_entities = _likebtn_get_entities(true, true); preg_match("/^(.*)_(\\d+)\$/", $identifier, $identifier_parts); list($entity_name, $entity_id) = $this->parseIdentifier($identifier); $likes_minus_dislikes = null; if ($likes !== null && $dislikes !== null) { $likes_minus_dislikes = $likes - $dislikes; } $entity_updated = false; if (array_key_exists($entity_name, $likebtn_entities) && is_numeric($entity_id)) { // set Custom fields switch ($entity_name) { case LIKEBTN_ENTITY_COMMENT: // Comment $comment = get_comment($entity_id); // check if post exists and is not revision if (!empty($comment) && $comment->comment_type != 'revision') { if ($likes !== null) { if (count(get_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES)) > 1) { delete_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES); add_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes, true); } else { update_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes); } } if ($dislikes !== null) { if (count(get_comment_meta($entity_id, LIKEBTN_META_KEY_DISLIKES)) > 1) { delete_comment_meta($entity_id, LIKEBTN_META_KEY_DISLIKES); add_comment_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes, true); } else { update_comment_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes); } } if ($likes_minus_dislikes !== null) { if (count(get_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES)) > 1) { delete_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES); add_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes, true); } else { update_comment_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes); } } $entity_updated = true; } break; case LIKEBTN_ENTITY_BP_ACTIVITY_POST: case LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE: case LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT: case LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC: if (!_likebtn_is_bp_active()) { break; } // BuddyPress Activity /*$bp_activity_list = bp_activity_get(array( 'show_hidden' => true, 'spam' => 'all', //'in' => array((int)$entity_id) ));*/ $bp_activity = $wpdb->get_row("\n SELECT id\n FROM " . $wpdb->prefix . "bp_activity\n WHERE id = {$entity_id}\n "); if (!empty($bp_activity)) { if ($likes !== null) { if (count(bp_activity_get_meta($entity_id, LIKEBTN_META_KEY_LIKES)) > 1) { bp_activity_delete_meta($entity_id, LIKEBTN_META_KEY_LIKES); bp_activity_add_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes, true); } else { bp_activity_update_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes); } } if ($dislikes !== null) { if (count(bp_activity_get_meta($entity_id, LIKEBTN_META_KEY_DISLIKES)) > 1) { bp_activity_delete_meta($entity_id, LIKEBTN_META_KEY_DISLIKES); bp_activity_add_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes, true); } else { bp_activity_update_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes); } } if ($likes_minus_dislikes !== null) { if (count(bp_activity_get_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES)) > 1) { bp_activity_delete_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES); bp_activity_add_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes, true); } else { bp_activity_update_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes); } } $entity_updated = true; } break; case LIKEBTN_ENTITY_BP_MEMBER: // BuddyPress Member Profile $entity_updated = _likebtn_save_bp_member_votes($entity_id, $likes, $dislikes, $likes_minus_dislikes); break; case LIKEBTN_ENTITY_BBP_USER: // bbPress Member Profile $entity_updated = _likebtn_save_user_votes($entity_id, $likes, $dislikes, $likes_minus_dislikes); break; case LIKEBTN_ENTITY_USER: // BuddyPress Member Profile $entity_updated = _likebtn_save_bp_member_votes($entity_id, $likes, $dislikes, $likes_minus_dislikes); // General user and bbPress Member Profile $entity_updated = $entity_updated || _likebtn_save_user_votes($entity_id, $likes, $dislikes, $likes_minus_dislikes); break; default: // Post $post = get_post($entity_id); // check if post exists and is not revision if (!empty($post) && !empty($post->post_type) && $post->post_type != 'revision') { if ($likes !== null) { if (count(get_post_meta($entity_id, LIKEBTN_META_KEY_LIKES)) > 1) { delete_post_meta($entity_id, LIKEBTN_META_KEY_LIKES); add_post_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes, true); } else { update_post_meta($entity_id, LIKEBTN_META_KEY_LIKES, $likes); } } if ($dislikes !== null) { if (count(get_post_meta($entity_id, LIKEBTN_META_KEY_DISLIKES)) > 1) { delete_post_meta($entity_id, LIKEBTN_META_KEY_DISLIKES); add_post_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes, true); } else { update_post_meta($entity_id, LIKEBTN_META_KEY_DISLIKES, $dislikes); } } if ($likes_minus_dislikes !== null) { if (count(get_post_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES)) > 1) { delete_post_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES); add_post_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes, true); } else { update_post_meta($entity_id, LIKEBTN_META_KEY_LIKES_MINUS_DISLIKES, $likes_minus_dislikes); } } $entity_updated = true; } break; } } // Check custom item $item_db = $wpdb->get_row($wpdb->prepare("SELECT likes, dislikes\n FROM " . $wpdb->prefix . LIKEBTN_TABLE_ITEM . "\n WHERE identifier = %s", $identifier)); // Custom identifier if ($item_db || !$entity_updated) { if ($likes === null || $dislikes === null) { if ($item_db) { if ($likes === null) { $likes = $item_db->likes; } if ($dislikes === null) { $dislikes = $item_db->dislikes; } } } if ($likes !== null && $dislikes !== null) { $likes_minus_dislikes = $likes - $dislikes; } $item_data = array('identifier' => $identifier, 'likes' => $likes, 'dislikes' => $dislikes, 'likes_minus_dislikes' => $likes_minus_dislikes, 'identifier_hash' => md5($identifier)); if ($url) { $item_data['url'] = $url; } $update_where = array('identifier' => $item_data['identifier']); $update_result = $wpdb->update($wpdb->prefix . LIKEBTN_TABLE_ITEM, $item_data, $update_where); if ($update_result) { $entity_updated = true; } else { $insert_result = $wpdb->insert($wpdb->prefix . LIKEBTN_TABLE_ITEM, $item_data); if ($insert_result) { $entity_updated = true; } } } return $entity_updated; }
/** * Updated! * * @package Rendez Vous * @subpackage Activity * * @since Rendez Vous (1.0.0) */ function rendez_vous_updated_activity($id = 0, $args = array(), $notify = false, $activity = false) { if (empty($id) || empty($activity)) { return; } $rdv = rendez_vous(); if (empty($rdv->item->id)) { $rendez_vous = rendez_vous_get_item($id); } else { $rendez_vous = $rdv->item; } $rendez_vous_url = rendez_vous_get_single_link($id, $rendez_vous->organizer); $rendez_vous_link = '<a href="' . esc_url($rendez_vous_url) . '">' . esc_html($rendez_vous->title) . '</a>'; $user_link = bp_core_get_userlink($rendez_vous->organizer); $action_part = __('updated a', 'rendez-vous'); $action = sprintf(__('%1$s %2$s rendez-vous, %3$s', 'rendez-vous'), $user_link, $action_part, $rendez_vous_link); $activity_id = bp_activity_add(apply_filters('rendez_vous_updated_activity_args', array('action' => $action, 'component' => buddypress()->rendez_vous->id, 'type' => 'updated_rendez_vous', 'primary_link' => $rendez_vous_url, 'user_id' => $rendez_vous->organizer, 'item_id' => $rendez_vous->id, 'secondary_item_id' => $rendez_vous->organizer))); if (!empty($activity_id)) { bp_activity_update_meta($activity_id, 'rendez_vous_title', $rendez_vous->title); } return true; }
/** * Syncs activity comments and posts them back as blog comments. * * Note: This is only a one-way sync - activity comments -> blog comment. * * For blog post -> activity comment, see {@link bp_blogs_record_comment()}. * * @since BuddyPress (2.0.0) * * @param int $comment_id The activity ID for the posted activity comment. * @param array $params Parameters for the activity comment. * @param object Parameters of the parent activity item (in this case, the blog post). */ function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { // if parent activity isn't a blog post, stop now! if ( $parent_activity->type != 'new_blog_post' ) { return; } // if activity comments are disabled for blog posts, stop now! if ( bp_disable_blogforum_comments() ) { return; } // get userdata if ( $params['user_id'] == bp_loggedin_user_id() ) { $user = buddypress()->loggedin_user->userdata; } else { $user = bp_core_get_core_userdata( $params['user_id'] ); } // see if a parent WP comment ID exists if ( ! empty( $params['parent_id'] ) ) { $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' ); } else { $comment_parent = 0; } // comment args $args = array( 'comment_post_ID' => $parent_activity->secondary_item_id, 'comment_author' => bp_core_get_user_displayname( $params['user_id'] ), 'comment_author_email' => $user->user_email, 'comment_author_url' => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ), 'comment_content' => $params['content'], 'comment_type' => '', // could be interesting to add 'buddypress' here... 'comment_parent' => (int) $comment_parent, 'user_id' => $params['user_id'], // commenting these out for now //'comment_author_IP' => '127.0.0.1', //'comment_agent' => '', 'comment_approved' => 1 ); // prevent separate activity entry being made remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); // handle multisite switch_to_blog( $parent_activity->item_id ); // handle timestamps for the WP comment after we've switched to the blog $args['comment_date'] = current_time( 'mysql' ); $args['comment_date_gmt'] = current_time( 'mysql', 1 ); // post the comment $post_comment_id = wp_insert_comment( $args ); // add meta to comment add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id ); // add meta to activity comment bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); // resave activity comment with WP comment permalink // // in bp_blogs_activity_comment_permalink(), we change activity comment // permalinks to use the post comment link // // @todo since this is done after AJAX posting, the activity comment permalink // doesn't change on the frontend until the next page refresh. $resave_activity = new BP_Activity_Activity( $comment_id ); $resave_activity->primary_link = get_comment_link( $post_comment_id ); $resave_activity->save(); // multisite again! restore_current_blog(); // add the comment hook back add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); /** * Fires after activity comments have been synced and posted as blog comments. * * @since BuddyPress (2.0.0) * * @param int $comment_id The activity ID for the posted activity comment. * @param array $args Array of args used for the comment syncing. * @param object $parent_activity Parameters of the blog post parent activity item. * @param object $user User data object for the blog comment. */ do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user ); }
/** * Record a new blog comment in the BuddyPress activity stream. * * Only posts the item if blog is public and post is not password-protected. * * @param int $comment_id ID of the comment being recorded. * @param bool|string $is_approved Optional. The $is_approved value passed to * the 'comment_post' action. Default: true. * @return bool|object Returns false on failure, the comment object on success. */ function bp_blogs_record_comment($comment_id, $is_approved = true) { // bail if activity component is not active if (!bp_is_active('activity')) { return; } // Get the users comment $recorded_comment = get_comment($comment_id); // Don't record activity if the comment hasn't been approved if (empty($is_approved)) { return false; } // Don't record activity if no email address has been included if (empty($recorded_comment->comment_author_email)) { return false; } // Don't record activity if the comment has already been marked as spam if ('spam' === $is_approved) { return false; } // Get the user by the comment author email. $user = get_user_by('email', $recorded_comment->comment_author_email); // If user isn't registered, don't record activity if (empty($user)) { return false; } // Get the user_id $user_id = (int) $user->ID; // Get blog and post data $blog_id = get_current_blog_id(); // If blog is not trackable, do not record the activity. if (!bp_blogs_is_blog_trackable($blog_id, $user_id)) { return false; } $recorded_comment->post = get_post($recorded_comment->comment_post_ID); if (empty($recorded_comment->post) || is_wp_error($recorded_comment->post)) { return false; } // If this is a password protected post, don't record the comment if (!empty($recorded_comment->post->post_password)) { return false; } // Don't record activity if the comment's associated post isn't a WordPress Post if (!in_array($recorded_comment->post->post_type, apply_filters('bp_blogs_record_comment_post_types', array('post')))) { return false; } $is_blog_public = apply_filters('bp_is_blog_public', (int) get_blog_option($blog_id, 'blog_public')); // If blog is public allow activity to be posted if ($is_blog_public) { // Get activity related links $post_permalink = get_permalink($recorded_comment->comment_post_ID); $comment_link = get_comment_link($recorded_comment->comment_ID); // Setup activity args $args = array(); $args['user_id'] = $user_id; $args['content'] = apply_filters_ref_array('bp_blogs_activity_new_comment_content', array($recorded_comment->comment_content, &$recorded_comment, $comment_link)); $args['primary_link'] = apply_filters_ref_array('bp_blogs_activity_new_comment_primary_link', array($comment_link, &$recorded_comment)); $args['recorded_time'] = $recorded_comment->comment_date_gmt; // Setup some different activity args depending if activity commenting is // enabled or not // if cannot comment, record separate activity entry // this is the old way of doing things if (bp_disable_blogforum_comments()) { $args['type'] = 'new_blog_comment'; $args['item_id'] = $blog_id; $args['secondary_item_id'] = $comment_id; // record the activity entry $activity_id = bp_blogs_record_activity($args); // add some post info in activity meta bp_activity_update_meta($activity_id, 'post_title', $recorded_comment->post->post_title); bp_activity_update_meta($activity_id, 'post_url', add_query_arg('p', $recorded_comment->post->ID, home_url('/'))); // record comment as BP activity comment under the parent 'new_blog_post' // activity item } else { // this is a comment edit // check to see if corresponding activity entry already exists if (!empty($_REQUEST['action'])) { $existing_activity_id = get_comment_meta($comment_id, 'bp_activity_comment_id', true); if (!empty($existing_activity_id)) { $args['id'] = $existing_activity_id; } } // find the parent 'new_blog_post' activity entry $parent_activity_id = bp_activity_get_activity_id(array('component' => 'blogs', 'type' => 'new_blog_post', 'item_id' => $blog_id, 'secondary_item_id' => $recorded_comment->comment_post_ID)); // we found the parent activity entry // so let's go ahead and reconfigure some activity args if (!empty($parent_activity_id)) { // set the 'item_id' with the parent activity entry ID $args['item_id'] = $parent_activity_id; // now see if the WP parent comment has a BP activity ID $comment_parent = 0; if (!empty($recorded_comment->comment_parent)) { $comment_parent = get_comment_meta($recorded_comment->comment_parent, 'bp_activity_comment_id', true); } // WP parent comment does not have a BP activity ID // so set to 'new_blog_post' activity ID if (empty($comment_parent)) { $comment_parent = $parent_activity_id; } $args['secondary_item_id'] = $comment_parent; $args['component'] = 'activity'; $args['type'] = 'activity_comment'; // could not find corresponding parent activity entry // so wipe out $args array } else { $args = array(); } // Record in activity streams if (!empty($args)) { // @todo should we use bp_activity_new_comment()? that function will also send // an email to people in the activity comment thread // // what if a site already has some comment email notification plugin setup? // this is why I decided to go with bp_activity_add() to avoid any conflict // with existing comment email notification plugins $comment_activity_id = bp_activity_add($args); if (empty($args['id'])) { // add meta to activity comment bp_activity_update_meta($comment_activity_id, 'bp_blogs_post_comment_id', $comment_id); bp_activity_update_meta($comment_activity_id, 'post_title', $recorded_comment->post->post_title); bp_activity_update_meta($comment_activity_id, 'post_url', add_query_arg('p', $recorded_comment->post->ID, home_url('/'))); // add meta to comment add_comment_meta($comment_id, 'bp_activity_comment_id', $comment_activity_id); } } } // Update the blogs last active date bp_blogs_update_blogmeta($blog_id, 'last_activity', bp_core_current_time()); } return $recorded_comment; }
function update_activity_after_thumb_set($id) { $model = new RTMediaModel(); $mediaObj = new RTMediaMedia(); $media = $model->get(array('id' => $id)); $privacy = $media[0]->privacy; $activity_id = rtmedia_activity_id($id); if (!empty($activity_id)) { $same_medias = $mediaObj->model->get(array('activity_id' => $activity_id)); $update_activity_media = array(); foreach ($same_medias as $a_media) { $update_activity_media[] = $a_media->id; } $objActivity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $activity_old_content = bp_activity_get_meta($activity_id, "bp_old_activity_content"); $activity_text = bp_activity_get_meta($activity_id, "bp_activity_text"); if ($activity_old_content == "") { // get old activity content and save in activity meta $activity_get = bp_activity_get_specific(array('activity_ids' => $activity_id)); $activity = $activity_get['activities'][0]; $activity_body = $activity->content; bp_activity_update_meta($activity_id, "bp_old_activity_content", $activity_body); //extract activity text from old content $activity_text = strip_tags($activity_body, '<span>'); $activity_text = explode("</span>", $activity_text); $activity_text = strip_tags($activity_text[0]); bp_activity_update_meta($activity_id, "bp_activity_text", $activity_text); } $activity_text = bp_activity_get_meta($activity_id, "bp_activity_text"); $objActivity->activity_text = $activity_text; $wpdb->update($bp->activity->table_name, array("type" => "rtmedia_update", "content" => $objActivity->create_activity_html()), array("id" => $activity_id)); } }
private function _update_activity_geotag($activity_id, $lat, $lng) { bp_activity_update_meta($activity_id, '_agm_latitude', $lat); bp_activity_update_meta($activity_id, '_agm_longitude', $lng); }