/** * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}. * * Wrapper function for {@link bb_update_postmeta()}. * * @since BuddyPress (1.5.0) */ function bp_embed_forum_save_cache($cache, $cachekey, $id) { bb_update_postmeta($id, $cachekey, $cache); }
/** * Processes pingback requests * * @since 1.0 * @link http://www.hixie.ch/specs/pingback/pingback * @return string|object A message of success or an IXR_Error object on failure * @param array $args Arguments passed by the XML-RPC call * @param string $args[0] The full URI of the post where the pingback is being sent from * @param string $args[1] The full URI of the post where the pingback is being sent to * * XML-RPC request to register a pingback * <methodCall> * <methodName>pingback.ping</methodName> * <params> * <param><value><string>http://example.org/2008/09/post-containing-a-link/</string></value></param> * <param><value><string>http://example.com/2008/08/post-being-linked-to/</string></value></param> * </params> * </methodCall> */ function pingback_ping($args) { do_action('bb_xmlrpc_call', 'pingback.ping'); $this->escape($args); // No particular need to sanitise $link_from = (string) $args[0]; $link_to = (string) $args[1]; // Tidy up ampersands in the URLs $link_from = str_replace('&', '&', $link_from); $link_to = str_replace('&', '&', $link_to); $link_to = str_replace('&', '&', $link_to); // Check if the topic linked to is in our site - a little more strict than NXTClass, doesn't pull out the www if added if (!bb_match_domains($link_to, bb_get_uri())) { // These are not the droids you are looking for $this->error = new IXR_Error(0, __('This is not the site you are trying to pingback.')); return $this->error; } // Get the topic if ($topic_to = bb_get_topic_from_uri($link_to)) { // Topics shouldn't ping themselves if ($topic_from = bb_get_topic_from_uri($link_from)) { if ($topic_from->topic_id === $topic_to->topic_id) { $this->error = new IXR_Error(0, __('The source URL and the target URL cannot both point to the same resource.')); return $this->error; } } } else { $this->error = new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.')); return $this->error; } // Let's check that the remote site didn't already pingback this entry $query = new BB_Query('post', array('topic_id' => $topic_to->topic_id, 'append_meta' => true), 'get_thread'); $posts_to = $query->results; unset($query); // Make sure we have some posts in the topic, this error should never happen really if (!$posts_to || !is_array($posts_to) || !count($posts_to)) { $this->error = new IXR_Error(0, __('The specified target topic does not contain any posts.')); return $this->error; } // Check if we already have a pingback from this URL foreach ($posts_to as $post) { if (isset($post->pingback_uri) && trim($post->pingback_uri) === trim($link_from)) { $this->error = new IXR_Error(48, __('The pingback has already been registered.')); return $this->error; } } unset($posts_to, $post); // Give time for the server sending the pingback to finish publishing it's post sleep(1); // Let's check the remote site for valid URL and content $link_from_source = nxt_remote_fopen($link_from); if (!$link_from_source) { $this->error = new IXR_Error(16, __('The source URL does not exist.')); return $this->error; } // Allow plugins to filter here $link_from_source = apply_filters('bb_pre_remote_source', $link_from_source, $link_to); // Work around bug in strip_tags() $link_from_source = str_replace('<!DOC', '<DOC', $link_from_source); // Normalize spaces $link_from_source = preg_replace('/[\\s\\r\\n\\t]+/', ' ', $link_from_source); // Turn certain elements to double line returns $link_from_source = preg_replace("/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $link_from_source); // Find the title of the page preg_match('|<title>([^<]*?)</title>|is', $link_from_source, $link_from_title); $link_from_title = $link_from_title[1]; if (empty($link_from_title)) { $this->error = new IXR_Error(32, __('We cannot find a title on that page.')); return $this->error; } // Strip out all tags except anchors $link_from_source = strip_tags($link_from_source, '<a>'); // just keep the tag we need // Split the source into paragraphs $link_from_paragraphs = explode("\n\n", $link_from_source); // Prepare the link to search for in preg_match() once here $preg_target = preg_quote($link_to); // Loop through the paragraphs looking for the context for the url foreach ($link_from_paragraphs as $link_from_paragraph) { // The url exists if (strpos($link_from_paragraph, $link_to) !== false) { // But is it in an anchor tag preg_match("|<a[^>]+?" . $preg_target . "[^>]*>([^>]+?)</a>|", $link_from_paragraph, $context); // If the URL isn't in an anchor tag, keep looking if (empty($context)) { continue; } // We're going to use this fake tag to mark the context in a bit // the marker is needed in case the link text appears more than once in the paragraph $excerpt = preg_replace('|\\</?nxtcontext\\>|', '', $link_from_paragraph); // Prevent really long link text if (strlen($context[1]) > 100) { $context[1] = substr($context[1], 0, 100) . '...'; } // Set up the marker around the context $marker = '<nxtcontext>' . $context[1] . '</nxtcontext>'; // Swap out the link for our marker $excerpt = str_replace($context[0], $marker, $excerpt); // Strip all tags except for our context marker $excerpt = trim(strip_tags($excerpt, '<nxtcontext>')); // Make the marker safe for use in regexp $preg_marker = preg_quote($marker); // Reduce the excerpt to only include 100 characters on either side of the link $excerpt = preg_replace("|.*?\\s(.{0,100}" . $preg_marker . "{0,100})\\s.*|s", '$1', $excerpt); // Strip tags again, to remove the marker wrapper $excerpt = strip_tags($excerpt); break; } } // Make sure the link to the target was found in the excerpt if (empty($context)) { $this->error = new IXR_Error(17, __('The source URL does not contain a link to the target URL, and so cannot be used as a source.')); return $this->error; } // Add whacky prefix and suffix to the excerpt and sanitize $excerpt = '[...] ' . esc_html($excerpt) . ' [...]'; $this->escape($excerpt); // Build an array of post data to insert then insert a new post $postdata = array('topic_id' => $topic_to->topic_id, 'post_text' => $excerpt, 'poster_id' => 0); if (!($post_ID = bb_insert_post($postdata))) { $this->error = new IXR_Error(0, __('The pingback could not be added.')); return $this->error; } // Add meta to let us know where the pingback came from $link_from = str_replace('&', '&', $link_from); $this->escape($link_from); bb_update_postmeta($post_ID, 'pingback_uri', $link_from); // Add the title to meta $this->escape($link_from_title); bb_update_postmeta($post_ID, 'pingback_title', $link_from_title); // Action for plugins and what not do_action('bb_pingback_post', $post_ID); // Return success message, complete with emoticon return sprintf(__('Pingback from %1$s to %2$s registered. Keep the web talking! :-)'), $link_from, $link_to); }
/** * When RBE posts a new group forum post, record the post meta in bundled bbPress * so we can reference it later in the topic post loop. * * @uses bb_update_postmeta() To add post meta in bundled bbPress. * @since 1.0-RC1 */ function bp_rbe_group_forum_record_meta($id) { // since we post items outside of BP's screen functions, it should be safe // to just check if BP's current component and actions are false if (!bp_current_component() && !bp_current_action()) { bb_update_postmeta($id, 'bp_rbe', 1); } }
function bb_insert_post($args = null) { global $bbdb, $bb_current_user, $bb; if (!($args = nxt_parse_args($args))) { return false; } $fields = array_keys($args); if (isset($args['post_id']) && false !== $args['post_id']) { $update = true; if (!($post_id = (int) get_post_id($args['post_id']))) { return false; } // Get from db, not cache. Good idea? $post = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->posts} WHERE post_id = %d", $post_id)); $defaults = get_object_vars($post); unset($defaults['post_id']); // Only update the args we passed $fields = array_intersect($fields, array_keys($defaults)); if (in_array('topic_id', $fields)) { $fields[] = 'forum_id'; } // No need to run filters if these aren't changing // bb_new_post() and bb_update_post() will always run filters $run_filters = (bool) array_intersect(array('post_status', 'post_text'), $fields); } else { $post_id = false; $update = false; $now = bb_current_time('mysql'); $current_user_id = bb_get_current_user_info('id'); $ip_address = $_SERVER['REMOTE_ADDR']; $defaults = array('topic_id' => 0, 'post_text' => '', 'post_time' => $now, 'poster_id' => $current_user_id, 'poster_ip' => $ip_address, 'post_status' => 0, 'post_position' => false); // Insert all args $fields = array_keys($defaults); $fields[] = 'forum_id'; $run_filters = true; } $defaults['throttle'] = true; extract(nxt_parse_args($args, $defaults)); // If the user is not logged in and loginless posting is ON, then this function expects $post_author, $post_email and $post_url to be sanitized (check bb-post.php for example) if (!($topic = get_topic($topic_id))) { return false; } if (bb_is_login_required() && !($user = bb_get_user($poster_id))) { return false; } $topic_id = (int) $topic->topic_id; $forum_id = (int) $topic->forum_id; if ($run_filters && !($post_text = apply_filters('pre_post', $post_text, $post_id, $topic_id))) { return false; } if ($update) { // Don't change post_status with this function. Use bb_delete_post(). $post_status = $post->post_status; } if ($run_filters) { $post_status = (int) apply_filters('pre_post_status', $post_status, $post_id, $topic_id); } if (false === $post_position) { $post_position = $topic_posts = intval(0 == $post_status ? $topic->topic_posts + 1 : $topic->topic_posts); } unset($defaults['throttle']); if ($update) { $bbdb->update($bbdb->posts, compact($fields), compact('post_id')); nxt_cache_delete($post_id, 'bb_post'); } else { $bbdb->insert($bbdb->posts, compact($fields)); $post_id = $topic_last_post_id = (int) $bbdb->insert_id; if (0 == $post_status) { $topic_time = $post_time; $topic_last_poster = !bb_is_user_logged_in() && !bb_is_login_required() ? -1 : $poster_id; $topic_last_poster_name = !bb_is_user_logged_in() && !bb_is_login_required() ? $post_author : $user->user_login; $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts + 1 WHERE forum_id = %d;", $topic->forum_id)); $bbdb->update($bbdb->topics, compact('topic_time', 'topic_last_poster', 'topic_last_poster_name', 'topic_last_post_id', 'topic_posts'), compact('topic_id')); $query = new BB_Query('post', array('post_author_id' => $poster_id, 'topic_id' => $topic_id, 'post_id' => "-{$post_id}")); if (!$query->results) { $topics_replied_key = $bbdb->prefix . 'topics_replied'; bb_update_usermeta($poster_id, $topics_replied_key, $user->{$topics_replied_key} + 1); } } else { bb_update_topicmeta($topic->topic_id, 'deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts + 1 : 1); } } bb_update_topic_voices($topic_id); // if user not logged in, save user data as meta data if (!$user) { bb_update_meta($post_id, 'post_author', $post_author, 'post'); bb_update_meta($post_id, 'post_email', $post_email, 'post'); bb_update_meta($post_id, 'post_url', $post_url, 'post'); } if ($throttle && !bb_current_user_can('throttle')) { if ($user) { bb_update_usermeta($poster_id, 'last_posted', time()); } else { bb_set_transient($_SERVER['REMOTE_ADDR'] . '_last_posted', time()); } } if (!bb_is_login_required() && !($user = bb_get_user($poster_id))) { $post_cookie_lifetime = apply_filters('bb_post_cookie_lifetime', 30000000); setcookie('post_author_' . BB_HASH, $post_author, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain); setcookie('post_author_email_' . BB_HASH, $post_email, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain); setcookie('post_author_url_' . BB_HASH, $post_url, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain); } nxt_cache_delete($topic_id, 'bb_topic'); nxt_cache_delete($topic_id, 'bb_thread'); nxt_cache_delete($forum_id, 'bb_forum'); nxt_cache_flush('bb_forums'); nxt_cache_flush('bb_query'); nxt_cache_flush('bb_cache_posts_post_ids'); if ($update) { // fire actions after cache is flushed do_action('bb_update_post', $post_id); } else { do_action('bb_new_post', $post_id); } do_action('bb_insert_post', $post_id, $args, compact(array_keys($args))); // post_id, what was passed, what was used if (bb_get_option('enable_pingback')) { bb_update_postmeta($post_id, 'pingback_queued', ''); nxt_schedule_single_event(time(), 'do_pingbacks'); } return $post_id; }
<?php require_once '../../bb-load.php'; require_once "thanks-output.php"; $post_id = $_POST['post_id']; $user_id = $_POST['user_id']; $meta = bb_get_post_meta("thanks", $post_id); if (!isset($meta)) { $meta = array(); } $tmp = array(); for ($i = 0; $i < count($meta); $i++) { $tmp[$meta[$i]] = "X"; } $tmp[$user_id] = "X"; $meta = array_keys($tmp); bb_update_postmeta($post_id, "thanks", $meta); $opt = bb_get_option("thanks_posts"); if (!isset($opt)) { $opt = array(); } $tmp = array(); for ($i = 0; $i < count($opt); $i++) { $tmp[$opt[$i]] = "X"; } $tmp[$post_id] = "X"; $opt = array_keys($tmp); bb_update_option('thanks_posts', $opt); echo thanks_output_details($post_id, $user_id, true);
function bb_insert_post($args = null) { global $bbdb, $bb_current_user; if (!($args = wp_parse_args($args))) { return false; } $fields = array_keys($args); if (isset($args['post_id']) && false !== $args['post_id']) { $update = true; if (!($post_id = (int) get_post_id($args['post_id']))) { return false; } // Get from db, not cache. Good idea? $post = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->posts} WHERE post_id = %d", $post_id)); $defaults = get_object_vars($post); unset($defaults['post_id']); // Only update the args we passed $fields = array_intersect($fields, array_keys($defaults)); if (in_array('topic_id', $fields)) { $fields[] = 'forum_id'; } // No need to run filters if these aren't changing // bb_new_post() and bb_update_post() will always run filters $run_filters = (bool) array_intersect(array('post_status', 'post_text'), $fields); } else { $post_id = false; $update = false; $now = bb_current_time('mysql'); $current_user_id = bb_get_current_user_info('id'); $ip_address = $_SERVER['REMOTE_ADDR']; $defaults = array('topic_id' => 0, 'post_text' => '', 'post_time' => $now, 'poster_id' => $current_user_id, 'poster_ip' => $ip_address, 'post_status' => 0, 'post_position' => false); // Insert all args $fields = array_keys($defaults); $fields[] = 'forum_id'; $run_filters = true; } $defaults['throttle'] = true; extract(wp_parse_args($args, $defaults)); if (!($topic = get_topic($topic_id))) { return false; } if (!($user = bb_get_user($poster_id))) { return false; } $topic_id = (int) $topic->topic_id; $forum_id = (int) $topic->forum_id; if ($run_filters && !($post_text = apply_filters('pre_post', $post_text, $post_id, $topic_id))) { return false; } if ($update) { // Don't change post_status with this function. Use bb_delete_post(). $post_status = $post->post_status; } if ($run_filters) { $post_status = (int) apply_filters('pre_post_status', $post_status, $post_id, $topic_id); } if (false === $post_position) { $post_position = $topic_posts = intval(0 == $post_status ? $topic->topic_posts + 1 : $topic->topic_posts); } unset($defaults['throttle']); if ($update) { $bbdb->update($bbdb->posts, compact($fields), compact('post_id')); wp_cache_delete($post_id, 'bb_post'); } else { $bbdb->insert($bbdb->posts, compact($fields)); $post_id = $topic_last_post_id = (int) $bbdb->insert_id; if (0 == $post_status) { $topic_time = $post_time; $topic_last_poster = $poster_id; $topic_last_poster_name = $user->user_login; $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts + 1 WHERE forum_id = %d;", $topic->forum_id)); $bbdb->update($bbdb->topics, compact('topic_time', 'topic_last_poster', 'topic_last_poster_name', 'topic_last_post_id', 'topic_posts'), compact('topic_id')); $query = new BB_Query('post', array('post_author_id' => $poster_id, 'topic_id' => $topic_id, 'post_id' => "-{$post_id}")); if (!$query->results) { bb_update_usermeta($poster_id, $bbdb->prefix . 'topics_replied', $user->topics_replied + 1); } } else { bb_update_topicmeta($topic->topic_id, 'deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts + 1 : 1); } } bb_update_topic_voices($topic_id); if ($throttle && !bb_current_user_can('throttle')) { bb_update_usermeta($poster_id, 'last_posted', time()); } wp_cache_delete($topic_id, 'bb_topic'); wp_cache_delete($topic_id, 'bb_thread'); wp_cache_delete($forum_id, 'bb_forum'); wp_cache_flush('bb_forums'); wp_cache_flush('bb_query'); wp_cache_flush('bb_cache_posts_post_ids'); if ($update) { // fire actions after cache is flushed do_action('bb_update_post', $post_id); } else { do_action('bb_new_post', $post_id); } do_action('bb_insert_post', $post_id, $args, compact(array_keys($args))); // post_id, what was passed, what was used if (bb_get_option('enable_pingback')) { bb_update_postmeta($post_id, 'pingback_queued', ''); wp_schedule_single_event(time(), 'do_pingbacks'); } return $post_id; }
function bb_ksd_pre_post_status($post_status, $post_ID) { global $bb_current_user, $bb_ksd_pre_post_status, $bb_ksd_pre_post; // Don't filter content from users with a trusted role if (in_array($bb_current_user->roles[0], bb_trusted_roles())) { return $post_status; } $response = bb_ksd_submit($bb_ksd_pre_post); if (isset($response[1])) { bb_update_postmeta($post_ID, 'akismet_response', $response[1]); } if ('true' == $response[1]) { $bb_ksd_pre_post_status = '2'; return $bb_ksd_pre_post_status; } return $post_status; }
/** * Custom insert post function so that we could do what we need * * All counting functions have been removed from here, recount should be done * after running this script. * * @param mixed $args * @return int|bool New post ID if post was created, otherwise false */ function w2bc_insert_post($args = null) { global $bbdb, $bb_current_user, $bb; if (!($args = wp_parse_args($args))) { return false; } $fields = array_keys($args); $defaults = array('topic_id' => 0, 'post_text' => '', 'post_time' => bb_current_time('mysql'), 'poster_id' => bb_get_current_user_info('id'), 'poster_ip' => $_SERVER['REMOTE_ADDR'], 'post_status' => 0, 'post_position' => false); // Insert all args $fields = array_keys($defaults); $fields[] = 'forum_id'; extract(wp_parse_args($args, $defaults)); if (!($topic = get_topic($topic_id))) { return false; } $topic_id = (int) $topic->topic_id; $forum_id = (int) $topic->forum_id; if (false === $post_position) { $post_position = $topic_posts = intval(0 == $post_status ? $topic->topic_posts + 1 : $topic->topic_posts); } $bbdb->insert($bbdb->posts, compact($fields)); $post_id = $topic_last_post_id = (int) $bbdb->insert_id; // if anonymous posting, save user data as meta data if (!$user) { if ($post_author) { bb_update_meta($post_id, 'post_author', $post_author, 'post'); } // Atleast this should be there if ($post_email) { bb_update_meta($post_id, 'post_email', $post_email, 'post'); } if ($post_url) { bb_update_meta($post_id, 'post_url', $post_url, 'post'); } } $topic_time = $post_time; $topic_last_poster = !bb_is_user_logged_in() && !bb_is_login_required() ? -1 : $poster_id; $topic_last_poster_name = !bb_is_user_logged_in() && !bb_is_login_required() ? $post_author : $user->user_login; $bbdb->update($bbdb->topics, compact('topic_time', 'topic_last_poster', 'topic_last_poster_name', 'topic_last_post_id', 'topic_posts'), compact('topic_id')); wp_cache_delete($topic_id, 'bb_topic'); wp_cache_delete($topic_id, 'bb_thread'); wp_cache_delete($forum_id, 'bb_forum'); wp_cache_flush('bb_forums'); wp_cache_flush('bb_query'); wp_cache_flush('bb_cache_posts_post_ids'); if (bb_get_option('enable_pingback')) { bb_update_postmeta($post_id, 'pingback_queued', ''); wp_schedule_single_event(time(), 'do_pingbacks'); } return $post_id; }
function ray_bp_oembed($content) { global $bp_oembed; // WP(MU) 2.9 oEmbed check if (!function_exists(wp_oembed_get)) { return $content; } // match URLs - could use some work // preg_match_all( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $content, $matches ); preg_match_all('`.*?((http|https)://[\\w#$&+,\\/:;=?@.-]+)[^\\w#$&+,\\/:;=?@.-]*?`i', $content, $matches); // debug regex // print_r($matches[0]); // if there are no links to parse, return $content now! if (empty($matches[0])) { return $content; } $whitelist = $bp_oembed['whitelist']; for ($i = 0; $i < count($matches[0]); $i++) { $url = $matches[0][$i]; // check url with whitelist, if url matches any whitelist item, skip from parsing foreach ($whitelist as $whitelist_item) { if (strpos($url, $whitelist_item) !== false) { continue 2; } } $cachekey = '_oembed_' . md5($url); // grab oEmbed cache depending on BP component // not pretty! only looking for activity updates or forum posts ATM if (!bp_get_activity_id() && bp_forums_is_installed_correctly()) { $cache = bb_get_postmeta(bp_get_the_topic_post_id(), $cachekey); } else { $cache = bp_activity_get_meta(bp_get_activity_id(), $cachekey); } // cache check - no oEmbed, but cached result, skip rest of loop if ($url === $cache) { continue; } // cache check - yes oEmbed if (!empty($cache)) { $replace = apply_filters('embed_oembed_html', $cache, $url, $attr); } else { // process url to oEmbed $oembed = wp_oembed_get($url); // returns true if link is oEmbed //$oembed = file_get_contents("http://autoembed.com/api/?url=".urlencode($url)); if ($oembed) { $replace = apply_filters('embed_oembed_html', $oembed, $url, $attr); $replace = str_replace(' ', '', $replace); // fix Viddler line break in <object> tag } else { $replace = $url; // unlike WP's oEmbed, I cache the URL if not oEmbed-dable! // the URL is more useful in the DB than a string called {{unknown}} ;) } // save oEmbed cache depending on BP component // the same "not prettiness!" if (!bp_get_activity_id() && bp_forums_is_installed_correctly()) { bb_update_postmeta(bp_get_the_topic_post_id(), $cachekey, $replace); } else { bp_activity_update_meta(bp_get_activity_id(), $cachekey, $replace); } } $content = str_replace($url, $replace, $content); } return $content; }