/** * Add reply link below each post * * @param $post_links Array of the links * @param $args Array of args */ function em_reply_link($post_links = array(), $args = array()) { global $em_plugopts; if ($em_plugopts['reply-link'] == 1 && $em_plugopts['reply-text'] && bb_is_topic() && topic_is_open() && (bb_is_user_logged_in() || function_exists('bb_is_login_required') && !bb_is_login_required())) { /* Check if link is needed */ $text = str_replace("%%POSTLINK%%", get_post_link(), str_replace("%%USERNAME%%", get_post_author(), $em_plugopts['reply-text'])); $js = "var ema=document.getElementById('post_content');var emb=ema.value;if(emb!='')emb+='\\n\\n';ema.value=emb+'" . $text . "\\n\\n';ema.focus();void(0);"; $post_links[] = $args['before_each'] . '<a class="reply_link" style="cursor:pointer" onclick="' . $js . '">' . __('Reply', 'easy-mentions') . '</a>' . $args['after_each']; } return $post_links; }
/** * Whether current user has capability or role. * * @since 0.7.2 * @uses $bb_current_user Current User Object * * @param string $capability Capability or role name. * @return bool */ function bb_current_user_can($capability) { global $bb_current_user; $args = array_slice(func_get_args(), 1); $args = array_merge(array($capability), $args); if (empty($bb_current_user)) { $retvalue = false; if (($capability == 'write_topic' || $capability == 'write_topics') && !bb_is_login_required()) { $retvalue = true; } } else { $retvalue = call_user_func_array(array(&$bb_current_user, 'has_cap'), $args); } // Use bb_user_has_cap whenever possible! This will not work everywhere. return apply_filters('bb_current_user_can', $retvalue, $capability, $args); }
bb_check_admin_referer('create-topic'); $topic = trim($_POST['topic']); $tags = trim($_POST['tags']); if ('' == $topic) { bb_die(__('Please enter a topic title')); } $args = array(); if (isset($post_author)) { $args['topic_poster_name'] = $args['topic_last_poster_name'] = $post_author; } $topic_id = bb_new_topic($topic, $forum_id, $tags, $args); } elseif (isset($_POST['topic_id'])) { $topic_id = (int) $_POST['topic_id']; bb_check_admin_referer('create-post_' . $topic_id); } if (bb_is_login_required() && !bb_current_user_can('write_post', $topic_id)) { bb_die(__('You are not allowed to post. Are you logged in?')); } if (!topic_is_open($topic_id)) { bb_die(__('This topic has been closed')); } $post_data = array('post_text' => stripslashes($_POST['post_content']), 'topic_id' => $topic_id); foreach (array('post_author', 'post_email', 'post_url') as $field) { if (!empty(${$field})) { $post_data[$field] = ${$field}; } } $post_id = bb_insert_post($post_data); $tags = trim($_POST['tags']); bb_add_topic_tags($topic_id, $tags); $topic = get_topic($topic_id, false);
/** * bb_get_new_topic_link() - Get the link to the form for a new topic * * @since 1.0 * @param mixed The arguments for this function. * @return string The link to the new topic form */ function bb_get_new_topic_link($args = null) { $defaults = array('text' => __('Add New »'), 'forum' => 0, 'tag' => ''); if ($args && is_string($args) && false === strpos($args, '=')) { $args = array('text' => $args); } $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); if ($forum && ($forum = bb_get_forum($forum))) { $url = get_forum_link($forum->forum_id) . '#postform'; } elseif ($tag && ($tag = bb_get_tag($tag))) { $url = bb_get_tag_link($tag->tag) . '#postform'; } elseif (bb_is_forum()) { global $forum; $url = get_forum_link($forum->forum_id) . '#postform'; } elseif (bb_is_tag()) { global $tag; $url = bb_get_tag_link($tag) . '#postform'; } elseif (bb_is_topic()) { $url = get_forum_link() . '#postform'; } elseif (bb_is_front()) { $url = bb_get_uri(null, array('new' => 1)); } if (!bb_is_user_logged_in() && bb_is_login_required()) { $url = bb_get_uri('bb-login.php', array('redirect_to' => $url), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_USER_FORMS); } elseif (bb_is_forum() || bb_is_topic()) { if (!bb_current_user_can('write_topic', get_forum_id())) { return; } } else { if (!bb_current_user_can('write_topics')) { return; } } if ($url = esc_attr(apply_filters('new_topic_url', $url, $args))) { return '<a href="' . $url . '" class="new-topic">' . $text . '</a>' . "\n"; } }
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; }
/** * 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; }