function get_topic($id, $cache = true) { global $bbdb; if (!is_numeric($id)) { list($slug, $sql) = bb_get_sql_from_slug('topic', $id); $id = nxt_cache_get($slug, 'bb_topic_slug'); } // not else if (is_numeric($id)) { $id = (int) $id; $sql = "topic_id = {$id}"; } if (0 === $id || !$sql) { return false; } // &= not =& $cache &= 'AND topic_status = 0' == ($where = apply_filters('get_topic_where', 'AND topic_status = 0')); if (($cache || !$where) && is_numeric($id) && false !== ($topic = nxt_cache_get($id, 'bb_topic'))) { return $topic; } // $where is NOT bbdb:prepared $topic = $bbdb->get_row("SELECT * FROM {$bbdb->topics} WHERE {$sql} {$where}"); $topic = bb_append_meta($topic, 'topic'); if ($cache) { nxt_cache_set($topic->topic_id, $topic, 'bb_topic'); nxt_cache_add($topic->topic_slug, $topic->topic_id, 'bb_topic_slug'); } return $topic; }
function bb_get_post($post_id) { global $bbdb; $post_id = (int) $post_id; if (false === ($post = nxt_cache_get($post_id, 'bb_post'))) { $post = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->posts} WHERE post_id = %d", $post_id)); $post = bb_append_meta($post, 'post'); nxt_cache_set($post_id, $post, 'bb_post'); } return $post; }
function bp_adminbar_blogs_menu() { global $bp; if (!is_user_logged_in() || !bp_is_active('blogs')) { return false; } if (!is_multisite()) { return false; } if (!($blogs = nxt_cache_get('bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp'))) { $blogs = bp_blogs_get_blogs_for_user($bp->loggedin_user->id, true); nxt_cache_set('bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp'); } $counter = 0; if (is_array($blogs['blogs']) && (int) $blogs['count']) { echo '<li id="bp-adminbar-blogs-menu"><a href="' . trailingslashit($bp->loggedin_user->domain . bp_get_blogs_slug()) . '">'; _e('My Sites', 'buddypress'); echo '</a>'; echo '<ul>'; foreach ((array) $blogs['blogs'] as $blog) { $alt = 0 == $counter % 2 ? ' class="alt"' : ''; $site_url = esc_attr($blog->siteurl); echo '<li' . $alt . '>'; echo '<a href="' . $site_url . '">' . esc_html($blog->name) . '</a>'; echo '<ul>'; echo '<li class="alt"><a href="' . $site_url . 'nxt-admin/">' . __('Dashboard', 'buddypress') . '</a></li>'; echo '<li><a href="' . $site_url . 'nxt-admin/post-new.php">' . __('New Post', 'buddypress') . '</a></li>'; echo '<li class="alt"><a href="' . $site_url . 'nxt-admin/edit.php">' . __('Manage Posts', 'buddypress') . '</a></li>'; echo '<li><a href="' . $site_url . 'nxt-admin/edit-comments.php">' . __('Manage Comments', 'buddypress') . '</a></li>'; echo '</ul>'; do_action('bp_adminbar_blog_items', $blog); echo '</li>'; $counter++; } $alt = 0 == $counter % 2 ? ' class="alt"' : ''; if (bp_blog_signup_enabled()) { echo '<li' . $alt . '>'; echo '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __('Create a Site!', 'buddypress') . '</a>'; echo '</li>'; } echo '</ul>'; echo '</li>'; } }
function groups_update_groupmeta($group_id, $meta_key, $meta_value) { global $nxtdb, $bp; if (!is_numeric($group_id)) { return false; } $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if (is_string($meta_value)) { $meta_value = stripslashes($nxtdb->escape($meta_value)); } $meta_value = maybe_serialize($meta_value); if (empty($meta_value)) { return groups_delete_groupmeta($group_id, $meta_key); } $cur = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key)); if (!$cur) { $nxtdb->query($nxtdb->prepare("INSERT INTO " . $bp->groups->table_name_groupmeta . " ( group_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $group_id, $meta_key, $meta_value)); } else { if ($cur->meta_value != $meta_value) { $nxtdb->query($nxtdb->prepare("UPDATE " . $bp->groups->table_name_groupmeta . " SET meta_value = %s WHERE group_id = %d AND meta_key = %s", $meta_value, $group_id, $meta_key)); } else { return false; } } // Update the cached object and recache nxt_cache_set('bp_groups_groupmeta_' . $group_id . '_' . $meta_key, $meta_value, 'bp'); return true; }
/** * Returns Achievement's picture; takes into account size of image required * * @since 2.0 * @global DPA_Achievement_Template $achievements_template Achievements template tag object * @global int $blog_id Site ID * @global object $bp BuddyPress global settings * @param string $size Optional; set to "thumb" to fetch thumbnail-sized picture, and "activitystream" for a thumbnail-sized picture with width/height style tags. * @return string HTML image tag */ function dpa_get_achievement_picture($size = '') { global $achievements_template, $blog_id, $bp; $achievement_slug = dpa_get_achievement_slug(); $achievement_id = dpa_get_achievement_id(); if ('thumb' == $size || 'activitystream' == $size) { $is_thumbnail = true; } else { $is_thumbnail = dpa_get_achievement_picture_is_thumbnail(); } if (($picture_id = dpa_get_achievement_picture_id()) < 1) { if (empty($bp->grav_default->user)) { $default_grav = 'wavatar'; } elseif ('mystery' == $bp->grav_default->user) { $default_grav = apply_filters('bp_core_mysteryman_src', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg'); } else { $default_grav = $bp->grav_default->user; } if ('thumb' == $size) { $grav_size = apply_filters('dpa_get_achievement_picture_gravatar_width', BP_AVATAR_THUMB_WIDTH, 'thumb'); } elseif ('activitystream' == $size) { $grav_size = apply_filters('dpa_get_achievement_picture_gravatar_width', 20, 'activitystream'); } else { $grav_size = apply_filters('dpa_get_achievement_picture_gravatar_width', BP_AVATAR_FULL_WIDTH, 'full'); } $email = apply_filters('bp_core_gravatar_email', $achievement_slug . '@' . $bp->root_domain, $achievement_id, 'achievements'); if (is_ssl()) { $host = 'https://secure.gravatar.com/avatar/'; } else { $host = 'http://www.gravatar.com/avatar/'; } $avatar_url = apply_filters('bp_gravatar_url', $host) . md5($email) . '?d=' . $default_grav . '&s=' . $grav_size; } else { if ($cached_urls = nxt_cache_get('dpa_achievement_picture_urls', 'dpa') && isset($cached_urls) && is_array($cached_urls) && isset($cached_urls[$picture_id]) && $cached_urls[$picture_id]) { $avatar_url = $cached_urls[$picture_id]; } else { if ($is_nonroot_multisite = is_multisite() && BP_ROOT_BLOG != $blog_id) { switch_to_blog(BP_ROOT_BLOG); } // Necessary evil list($avatar_url, $avatar_width, $avatar_height, $is_intermediate) = image_downsize($picture_id, 'large'); if ($is_nonroot_multisite) { restore_current_blog(); } if (!is_array($cached_urls)) { $cached_urls = array($picture_id => $avatar_url); } else { $cached_urls[$picture_id] = $avatar_url; } $grav_size = 0; nxt_cache_set('dpa_achievement_picture_urls', $cached_urls, 'dpa'); } } $style = ''; if ('activitystream' == $size && ('mystery' == $bp->grav_default->user || $picture_id > 0)) { $style = 'width="20" height="20"'; } if ($is_thumbnail) { $picture_type = "avatar-thumbnail"; } else { $picture_type = "avatar-full"; } $url = '<img src="' . esc_url($avatar_url) . '" alt="' . esc_attr(dpa_get_achievement_name()) . '" title="' . esc_attr(dpa_get_achievement_name()) . '" ' . $style . ' class="avatar' . esc_attr(' achievement-' . $achievement_slug . '-avatar ') . $picture_type . '" />'; return apply_filters('dpa_get_achievement_picture', $url, $achievement_id, $picture_id, $grav_size, $style); }
/** * Updates the cache for Term ID(s). * * Will only update the cache for terms not already cached. * * The $object_ids expects that the ids be separated by commas, if it is a * string. * * It should be noted that update_object_term_cache() is very time extensive. It * is advised that the function is not called very often or at least not for a * lot of terms that exist in a lot of taxonomies. The amount of time increases * for each term and it also increases for each taxonomy the term belongs to. * * @package NXTClass * @subpackage Taxonomy * @since 2.3.0 * @uses $this->get_object_terms() Used to get terms from the database to update * * @param string|array $object_ids Single or list of term object ID(s) * @param string $object_type The taxonomy object type * @return null|bool Null value is given with empty $object_ids. False if */ function update_object_term_cache($object_ids, $object_type) { if (empty($object_ids)) { return; } if (!is_array($object_ids)) { $object_ids = explode(',', $object_ids); } $object_ids = array_map('intval', $object_ids); $taxonomies = $this->get_object_taxonomies($object_type); $ids = array(); foreach ((array) $object_ids as $id) { foreach ($taxonomies as $taxonomy) { if (false === nxt_cache_get($id, "{$taxonomy}_relationships")) { $ids[] = $id; break; } } } if (empty($ids)) { return false; } $terms = $this->get_object_terms($ids, $taxonomies, 'fields=all_with_object_id'); $object_terms = array(); foreach ((array) $terms as $term) { $object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term; } foreach ($ids as $id) { foreach ($taxonomies as $taxonomy) { if (!isset($object_terms[$id][$taxonomy])) { if (!isset($object_terms[$id])) { $object_terms[$id] = array(); } $object_terms[$id][$taxonomy] = array(); } } } foreach ($object_terms as $id => $value) { foreach ($value as $taxonomy => $terms) { nxt_cache_set($id, $terms, "{$taxonomy}_relationships"); } } }
/** * Retrieve adjacent post. * * Can either be next or previous post. * * @since 2.5.0 * * @param bool $in_same_cat Optional. Whether post should be in a same category. * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. * @param bool $previous Optional. Whether to retrieve previous post. * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. */ function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) { global $post, $nxtdb; if (empty($post)) { return null; } $current_post_date = $post->post_date; $join = ''; $posts_in_ex_cats_sql = ''; if ($in_same_cat || !empty($excluded_categories)) { $join = " INNER JOIN {$nxtdb->term_relationships} AS tr ON p.ID = tr.object_id INNER JOIN {$nxtdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; if ($in_same_cat) { $cat_array = nxt_get_object_terms($post->ID, 'category', array('fields' => 'ids')); $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; } $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; if (!empty($excluded_categories)) { if (!is_array($excluded_categories)) { // back-compat, $excluded_categories used to be IDs separated by " and " if (strpos($excluded_categories, ' and ') !== false) { _deprecated_argument(__FUNCTION__, '3.3', sprintf(__('Use commas instead of %s to separate excluded categories.'), "'and'")); $excluded_categories = explode(' and ', $excluded_categories); } else { $excluded_categories = explode(',', $excluded_categories); } } $excluded_categories = array_map('intval', $excluded_categories); if (!empty($cat_array)) { $excluded_categories = array_diff($excluded_categories, $cat_array); $posts_in_ex_cats_sql = ''; } if (!empty($excluded_categories)) { $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; } } } $adjacent = $previous ? 'previous' : 'next'; $op = $previous ? '<' : '>'; $order = $previous ? 'DESC' : 'ASC'; $join = apply_filters("get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories); $where = apply_filters("get_{$adjacent}_post_where", $nxtdb->prepare("WHERE p.post_date {$op} %s AND p.post_type = %s AND p.post_status = 'publish' {$posts_in_ex_cats_sql}", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories); $sort = apply_filters("get_{$adjacent}_post_sort", "ORDER BY p.post_date {$order} LIMIT 1"); $query = "SELECT p.* FROM {$nxtdb->posts} AS p {$join} {$where} {$sort}"; $query_key = 'adjacent_post_' . md5($query); $result = nxt_cache_get($query_key, 'counts'); if (false !== $result) { return $result; } $result = $nxtdb->get_row("SELECT p.* FROM {$nxtdb->posts} AS p {$join} {$where} {$sort}"); if (null === $result) { $result = ''; } nxt_cache_set($query_key, $result, 'counts'); return $result; }
/** * Set/update the value of a transient * * You do not need to serialize values, if the value needs to be serialize, then * it will be serialized before it is set. * * @since 1.0 * @package bbPress * @subpackage Transient * * @param string $transient Transient name. Expected to not be SQL-escaped * @param mixed $value Transient value. * @param int $expiration Time until expiration in seconds, default 0 * @return bool False if value was not set and true if value was set. */ function bb_set_transient($transient, $value, $expiration = 0) { global $_bb_using_ext_object_cache, $bbdb; if ($_bb_using_ext_object_cache) { return nxt_cache_set($transient, $value, 'transient', $expiration); } else { $transient_timeout = '_transient_timeout_' . $bbdb->escape($transient); $transient = '_transient_' . $bbdb->escape($transient); if (0 != $expiration) { bb_update_option($transient_timeout, time() + $expiration); } return bb_update_option($transient, $value); } }
/** * Display calendar with days that have posts as links. * * The calendar is cached, which will be retrieved, if it exists. If there are * no posts for the month, then it will not be displayed. * * @since 1.0.0 * * @param bool $initial Optional, default is true. Use initial calendar names. * @param bool $echo Optional, default is true. Set to false for return. */ function get_calendar($initial = true, $echo = true) { global $nxtdb, $m, $monthnum, $year, $nxt_locale, $posts; $cache = array(); $key = md5($m . $monthnum . $year); if ($cache = nxt_cache_get('get_calendar', 'calendar')) { if (is_array($cache) && isset($cache[$key])) { if ($echo) { echo apply_filters('get_calendar', $cache[$key]); return; } else { return apply_filters('get_calendar', $cache[$key]); } } } if (!is_array($cache)) { $cache = array(); } // Quick check. If we have no posts at all, abort! if (!$posts) { $gotsome = $nxtdb->get_var("SELECT 1 as test FROM {$nxtdb->posts} WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); if (!$gotsome) { $cache[$key] = ''; nxt_cache_set('get_calendar', $cache, 'calendar'); return; } } if (isset($_GET['w'])) { $w = '' . intval($_GET['w']); } // week_begins = 0 stands for Sunday $week_begins = intval(get_option('start_of_week')); // Let's figure out when we are if (!empty($monthnum) && !empty($year)) { $thismonth = '' . zeroise(intval($monthnum), 2); $thisyear = '' . intval($year); } elseif (!empty($w)) { // We need to get the month from MySQL $thisyear = '' . intval(substr($m, 0, 4)); $d = ($w - 1) * 7 + 6; //it seems MySQL's weeks disagree with PHP's $thismonth = $nxtdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL {$d} DAY) ), '%m')"); } elseif (!empty($m)) { $thisyear = '' . intval(substr($m, 0, 4)); if (strlen($m) < 6) { $thismonth = '01'; } else { $thismonth = '' . zeroise(intval(substr($m, 4, 2)), 2); } } else { $thisyear = gmdate('Y', current_time('timestamp')); $thismonth = gmdate('m', current_time('timestamp')); } $unixmonth = mktime(0, 0, 0, $thismonth, 1, $thisyear); $last_day = date('t', $unixmonth); // Get the next and previous month and year with at least one post $previous = $nxtdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year\n\t\tFROM {$nxtdb->posts}\n\t\tWHERE post_date < '{$thisyear}-{$thismonth}-01'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\t\tORDER BY post_date DESC\n\t\t\tLIMIT 1"); $next = $nxtdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year\n\t\tFROM {$nxtdb->posts}\n\t\tWHERE post_date > '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\t\tORDER BY post_date ASC\n\t\t\tLIMIT 1"); /* translators: Calendar caption: 1: month name, 2: 4-digit year */ $calendar_caption = _x('%1$s %2$s', 'calendar caption'); $calendar_output = '<table id="nxt-calendar"> <caption>' . sprintf($calendar_caption, $nxt_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption> <thead> <tr>'; $myweek = array(); for ($wdcount = 0; $wdcount <= 6; $wdcount++) { $myweek[] = $nxt_locale->get_weekday(($wdcount + $week_begins) % 7); } foreach ($myweek as $wd) { $day_name = true == $initial ? $nxt_locale->get_weekday_initial($wd) : $nxt_locale->get_weekday_abbrev($wd); $wd = esc_attr($wd); $calendar_output .= "\n\t\t<th scope=\"col\" title=\"{$wd}\">{$day_name}</th>"; } $calendar_output .= ' </tr> </thead> <tfoot> <tr>'; if ($previous) { $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr(sprintf(__('View posts for %1$s %2$s'), $nxt_locale->get_month($previous->month), date('Y', mktime(0, 0, 0, $previous->month, 1, $previous->year)))) . '">« ' . $nxt_locale->get_month_abbrev($nxt_locale->get_month($previous->month)) . '</a></td>'; } else { $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev" class="pad"> </td>'; } $calendar_output .= "\n\t\t" . '<td class="pad"> </td>'; if ($next) { $calendar_output .= "\n\t\t" . '<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr(sprintf(__('View posts for %1$s %2$s'), $nxt_locale->get_month($next->month), date('Y', mktime(0, 0, 0, $next->month, 1, $next->year)))) . '">' . $nxt_locale->get_month_abbrev($nxt_locale->get_month($next->month)) . ' »</a></td>'; } else { $calendar_output .= "\n\t\t" . '<td colspan="3" id="next" class="pad"> </td>'; } $calendar_output .= ' </tr> </tfoot> <tbody> <tr>'; // Get days with posts $dayswithposts = $nxtdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)\n\t\tFROM {$nxtdb->posts} WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\tAND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); if ($dayswithposts) { foreach ((array) $dayswithposts as $daywith) { $daywithpost[] = $daywith[0]; } } else { $daywithpost = array(); } if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) { $ak_title_separator = "\n"; } else { $ak_title_separator = ', '; } $ak_titles_for_day = array(); $ak_post_titles = $nxtdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom " . "FROM {$nxtdb->posts} " . "WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " . "AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " . "AND post_type = 'post' AND post_status = 'publish'"); if ($ak_post_titles) { foreach ((array) $ak_post_titles as $ak_post_title) { $post_title = esc_attr(apply_filters('the_title', $ak_post_title->post_title, $ak_post_title->ID)); if (empty($ak_titles_for_day['day_' . $ak_post_title->dom])) { $ak_titles_for_day['day_' . $ak_post_title->dom] = ''; } if (empty($ak_titles_for_day["{$ak_post_title->dom}"])) { // first one $ak_titles_for_day["{$ak_post_title->dom}"] = $post_title; } else { $ak_titles_for_day["{$ak_post_title->dom}"] .= $ak_title_separator . $post_title; } } } // See how much we should pad in the beginning $pad = calendar_week_mod(date('w', $unixmonth) - $week_begins); if (0 != $pad) { $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr($pad) . '" class="pad"> </td>'; } $daysinmonth = intval(date('t', $unixmonth)); for ($day = 1; $day <= $daysinmonth; ++$day) { if (isset($newrow) && $newrow) { $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; } $newrow = false; if ($day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp'))) { $calendar_output .= '<td id="today">'; } else { $calendar_output .= '<td>'; } if (in_array($day, $daywithpost)) { // any posts today? $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . '" title="' . esc_attr($ak_titles_for_day[$day]) . "\">{$day}</a>"; } else { $calendar_output .= $day; } $calendar_output .= '</td>'; if (6 == calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins)) { $newrow = true; } } $pad = 7 - calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins); if ($pad != 0 && $pad != 7) { $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr($pad) . '"> </td>'; } $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>"; $cache[$key] = $calendar_output; nxt_cache_set('get_calendar', $cache, 'calendar'); if ($echo) { echo apply_filters('get_calendar', $calendar_output); } else { return apply_filters('get_calendar', $calendar_output); } }
function bp_get_friend_reject_request_link() { global $members_template, $bp; if (!($friendship_id = nxt_cache_get('friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id))) { $friendship_id = friends_get_friendship_id($members_template->member->id, $bp->loggedin_user->id); nxt_cache_set('friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp'); } return apply_filters('bp_get_friend_reject_request_link', nxt_nonce_url($bp->loggedin_user->domain . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship')); }
function friends_get_total_friend_count($user_id = 0) { global $bp; if (!$user_id) { $user_id = $bp->displayed_user->id ? $bp->displayed_user->id : $bp->loggedin_user->id; } if (!($count = nxt_cache_get('bp_total_friend_count_' . $user_id, 'bp'))) { $count = bp_get_user_meta($user_id, 'total_friend_count', true); if (empty($count)) { $count = 0; } nxt_cache_set('bp_total_friend_count_' . $user_id, $count, 'bp'); } return apply_filters('friends_get_total_friend_count', $count); }
/** * Loads the actions from the database. * * @global object $bp BuddyPress global settings * @global nxtdb $nxtdb NXTClass database object * @return string * @since 2.0 */ function dpa_get_actions() { global $bp, $nxtdb; if (!($actions = nxt_cache_get('dpa_actions', 'dpa'))) { $actions = $nxtdb->get_results($nxtdb->prepare("SELECT * FROM {$bp->achievements->table_actions} ORDER BY category, description")); nxt_cache_set('dpa_actions', $actions, 'dpa'); } return apply_filters('dpa_get_actions', (array) $actions); }
/** * Populate the instantiated class with data based on the User ID provided. * * @global object $bp Global BuddyPress settings object * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text * @uses bp_core_get_user_email() Returns the email address for the user based on user ID * @uses bp_get_user_meta() BP function returns the value of passed usermeta name from usermeta table * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user * @uses bp_profile_last_updated_date() Returns the last updated date for a user. */ function populate() { global $bp; if (bp_is_active('xprofile')) { $this->profile_data = $this->get_profile_data(); } if (!empty($this->profile_data)) { $full_name_field_name = bp_xprofile_fullname_field_name(); $this->user_url = bp_core_get_user_domain($this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login']); $this->fullname = esc_attr($this->profile_data[$full_name_field_name]['field_data']); $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>"; $this->email = esc_attr($this->profile_data['user_email']); } else { $this->user_url = bp_core_get_user_domain($this->id); $this->user_link = bp_core_get_userlink($this->id); $this->fullname = esc_attr(bp_core_get_user_displayname($this->id)); $this->email = esc_attr(bp_core_get_user_email($this->id)); } // Cache a few things that are fetched often nxt_cache_set('bp_user_fullname_' . $this->id, $this->fullname, 'bp'); nxt_cache_set('bp_user_email_' . $this->id, $this->email, 'bp'); nxt_cache_set('bp_user_url_' . $this->id, $this->user_url, 'bp'); $this->avatar = bp_core_fetch_avatar(array('item_id' => $this->id, 'type' => 'full')); $this->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $this->id, 'type' => 'thumb')); $this->avatar_mini = bp_core_fetch_avatar(array('item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30)); $this->last_active = bp_core_get_last_activity(bp_get_user_meta($this->id, 'last_activity', true), __('active %s', 'buddypress')); }
$blogname = htmlspecialchars(substr($_SERVER['REQUEST_URI'], strlen($path))); if (false !== strpos($blogname, '/')) { $blogname = substr($blogname, 0, strpos($blogname, '/')); } if (false !== strpos($blogname, '?')) { $blogname = substr($blogname, 0, strpos($blogname, '?')); } $reserved_blognames = array('page', 'comments', 'blog', 'nxt-admin', 'nxt-includes', 'nxt-content', 'files', 'feed'); if ($blogname != '' && !in_array($blogname, $reserved_blognames) && !is_file($blogname)) { $path .= $blogname . '/'; } $current_blog = nxt_cache_get('current_blog_' . $domain . $path, 'site-options'); if (!$current_blog) { $current_blog = get_blog_details(array('domain' => $domain, 'path' => $path), false); if ($current_blog) { nxt_cache_set('current_blog_' . $domain . $path, $current_blog, 'site-options'); } } unset($reserved_blognames); } if (!defined('nxt_INSTALLING') && is_subdomain_install() && !is_object($current_blog)) { if (defined('NOBLOGREDIRECT')) { $destination = NOBLOGREDIRECT; if ('%siteurl%' == $destination) { $destination = "http://" . $current_site->domain . $current_site->path; } } else { $destination = 'http://' . $current_site->domain . $current_site->path . 'nxt-signup.php?new=' . str_replace('.' . $current_site->domain, '', $domain); } header('Location: ' . $destination); die;
/** * Get a blog's numeric ID from its URL. * * On a subdirectory installation like example.com/blog1/, * $domain will be the root 'example.com' and $path the * subdirectory '/blog1/'. With subdomains like blog1.example.com, * $domain is 'blog1.example.com' and $path is '/'. * * @since MU 2.6.5 * * @param string $domain * @param string $path Optional. Not required for subdomain installations. * @return int */ function get_blog_id_from_url($domain, $path = '/') { global $nxtdb; $domain = strtolower($nxtdb->escape($domain)); $path = strtolower($nxtdb->escape($path)); $id = nxt_cache_get(md5($domain . $path), 'blog-id-cache'); if ($id == -1) { // blog does not exist return 0; } elseif ($id) { return (int) $id; } $id = $nxtdb->get_var("SELECT blog_id FROM {$nxtdb->blogs} WHERE domain = '{$domain}' and path = '{$path}' /* get_blog_id_from_url */"); if (!$id) { nxt_cache_set(md5($domain . $path), -1, 'blog-id-cache'); return false; } nxt_cache_set(md5($domain . $path), $id, 'blog-id-cache'); return $id; }
/** * Update an option for a particular blog. * * @since MU * * @param int $id The blog id * @param string $key The option key * @param mixed $value The option value * @return bool True on success, false on failrue. */ function update_blog_option($id, $key, $value, $deprecated = null) { $id = (int) $id; if (null !== $deprecated) { _deprecated_argument(__FUNCTION__, '3.1'); } switch_to_blog($id); $return = update_option($key, $value); restore_current_blog(); refresh_blog_details($id); if ($return) { nxt_cache_set($id . '-' . $key . '-blog_option', $value, 'site-options'); } return $return; }
/** * Returns the total number of members for the installation. * * @package BuddyPress Core * @return int The total number of members. */ function bp_core_get_total_member_count() { global $nxtdb, $bp; if (!($count = nxt_cache_get('bp_total_member_count', 'bp'))) { $status_sql = bp_core_get_status_sql(); $count = $nxtdb->get_var($nxtdb->prepare("SELECT COUNT(ID) FROM {$nxtdb->users} WHERE {$status_sql}")); nxt_cache_set('bp_total_member_count', $count, 'bp'); } return apply_filters('bp_core_get_total_member_count', $count); }
/** * Set/update the value of a site transient. * * You do not need to serialize values, if the value needs to be serialize, then * it will be serialized before it is set. * * @see set_transient() * @since 2.9.0 * @package NXTClass * @subpackage Transient * * @uses apply_filters() Calls 'pre_set_site_transient_$transient' hook to allow overwriting the * transient value to be stored. * @uses do_action() Calls 'set_site_transient_$transient' and 'setted_site_transient' hooks on success. * * @param string $transient Transient name. Expected to not be SQL-escaped. * @param mixed $value Transient value. Expected to not be SQL-escaped. * @param int $expiration Time until expiration in seconds, default 0 * @return bool False if value was not set and true if value was set. */ function set_site_transient($transient, $value, $expiration = 0) { global $_nxt_using_ext_object_cache; $value = apply_filters('pre_set_site_transient_' . $transient, $value); if ($_nxt_using_ext_object_cache) { $result = nxt_cache_set($transient, $value, 'site-transient', $expiration); } else { $transient_timeout = '_site_transient_timeout_' . $transient; $transient = '_site_transient_' . $transient; if (false === get_site_option($transient)) { if ($expiration) { add_site_option($transient_timeout, time() + $expiration); } $result = add_site_option($transient, $value); } else { if ($expiration) { update_site_option($transient_timeout, time() + $expiration); } $result = update_site_option($transient, $value); } } if ($result) { do_action('set_site_transient_' . $transient); do_action('setted_site_transient', $transient); } return $result; }
/** * Get count of how many (active) Achievements the specified user has. * Only users with edit permission can see hidden Achievements. * * @global object $bp BuddyPress global settings * @global nxtdb $nxtdb NXTClass database object * @param int $user_id * @since 2.0 */ function dpa_get_total_achievements_count_for_user($user_id = false) { global $bp, $nxtdb; if (!$user_id) { $user_id = $bp->displayed_user->id ? $bp->displayed_user->id : $bp->loggedin_user->id; } if (!($count = nxt_cache_get('dpa_get_total_achievements_count_for_user_' . $user_id, 'bp'))) { $admin_sql = $nxtdb->prepare("AND (is_active = 1 OR is_active = 2)"); $count = $nxtdb->get_var($nxtdb->prepare("SELECT COUNT(a.id) FROM {$bp->achievements->table_achievements} as a, {$bp->achievements->table_unlocked} as u WHERE a.id = u.achievement_id AND u.user_id = %d {$admin_sql}", $user_id)); nxt_cache_set('dpa_get_total_achievements_count_for_user_' . $user_id, $count, 'bp'); } return $count; }
/** * Sets current_site object. * * @access private * @since 3.0.0 * @return object $current_site object */ function nxtmu_current_site() { global $nxtdb, $current_site, $domain, $path, $sites, $cookie_domain; if (empty($current_site)) { $current_site = new stdClass(); } if (defined('DOMAIN_CURRENT_SITE') && defined('PATH_CURRENT_SITE')) { $current_site->id = defined('SITE_ID_CURRENT_SITE') ? SITE_ID_CURRENT_SITE : 1; $current_site->domain = DOMAIN_CURRENT_SITE; $current_site->path = $path = PATH_CURRENT_SITE; if (defined('BLOG_ID_CURRENT_SITE')) { $current_site->blog_id = BLOG_ID_CURRENT_SITE; } elseif (defined('BLOGID_CURRENT_SITE')) { // deprecated. $current_site->blog_id = BLOGID_CURRENT_SITE; } if (DOMAIN_CURRENT_SITE == $domain) { $current_site->cookie_domain = $cookie_domain; } elseif (substr($current_site->domain, 0, 4) == 'www.') { $current_site->cookie_domain = substr($current_site->domain, 4); } else { $current_site->cookie_domain = $current_site->domain; } nxt_load_core_site_options($current_site->id); return $current_site; } $current_site = nxt_cache_get('current_site', 'site-options'); if ($current_site) { return $current_site; } $sites = $nxtdb->get_results("SELECT * FROM {$nxtdb->site}"); // usually only one site if (1 == count($sites)) { $current_site = $sites[0]; nxt_load_core_site_options($current_site->id); $path = $current_site->path; $current_site->blog_id = $nxtdb->get_var($nxtdb->prepare("SELECT blog_id FROM {$nxtdb->blogs} WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path)); $current_site = get_current_site_name($current_site); if (substr($current_site->domain, 0, 4) == 'www.') { $current_site->cookie_domain = substr($current_site->domain, 4); } nxt_cache_set('current_site', $current_site, 'site-options'); return $current_site; } $path = substr($_SERVER['REQUEST_URI'], 0, 1 + strpos($_SERVER['REQUEST_URI'], '/', 1)); if ($domain == $cookie_domain) { $current_site = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->site} WHERE domain = %s AND path = %s", $domain, $path)); } else { $current_site = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->site} WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path)); } if (!$current_site) { if ($domain == $cookie_domain) { $current_site = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->site} WHERE domain = %s AND path='/'", $domain)); } else { $current_site = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->site} WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path)); } } if ($current_site) { $path = $current_site->path; $current_site->cookie_domain = $cookie_domain; return $current_site; } if (is_subdomain_install()) { $sitedomain = substr($domain, 1 + strpos($domain, '.')); $current_site = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->site} WHERE domain = %s AND path = %s", $sitedomain, $path)); if ($current_site) { $current_site->cookie_domain = $current_site->domain; return $current_site; } $current_site = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->site} WHERE domain = %s AND path='/'", $sitedomain)); } if ($current_site || defined('nxt_INSTALLING')) { $path = '/'; return $current_site; } // Still no dice. if (1 == count($sites)) { nxt_die(sprintf('That site does not exist. Please try <a href="%s">%s</a>.', $sites[0]->domain . $sites[0]->path)); } else { nxt_die('No site defined on this host. If you are the owner of this site, please check <a href="http://codex.nxtclass.org/Debugging_a_NXTClass_Network">Debugging a NXTClass Network</a> for help.'); } }
/** * Retrieve latest post date data based on timezone. * * @access private * @since 3.1.0 * * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. * @param string $field Field to check. Can be 'date' or 'modified'. * @return string The date. */ function _get_last_post_time($timezone, $field) { global $nxtdb; if (!in_array($field, array('date', 'modified'))) { return false; } $timezone = strtolower($timezone); $key = "lastpost{$field}:{$timezone}"; $date = nxt_cache_get($key, 'timeinfo'); if (!$date) { $add_seconds_server = date('Z'); $post_types = get_post_types(array('public' => true)); array_walk($post_types, array(&$nxtdb, 'escape_by_ref')); $post_types = "'" . implode("', '", $post_types) . "'"; switch ($timezone) { case 'gmt': $date = $nxtdb->get_var("SELECT post_{$field}_gmt FROM {$nxtdb->posts} WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); break; case 'blog': $date = $nxtdb->get_var("SELECT post_{$field} FROM {$nxtdb->posts} WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); break; case 'server': $date = $nxtdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '{$add_seconds_server}' SECOND) FROM {$nxtdb->posts} WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); break; } if ($date) { nxt_cache_set($key, $date, 'timeinfo'); } } return $date; }
function bp_xprofile_update_meta($object_id, $object_type, $meta_key, $meta_value) { global $nxtdb, $bp; $object_id = (int) $object_id; if (empty($object_id)) { return false; } if (!isset($object_type)) { return false; } if (!in_array($object_type, array('group', 'field', 'data'))) { return false; } $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if (is_string($meta_value)) { $meta_value = stripslashes($nxtdb->escape($meta_value)); } $meta_value = maybe_serialize($meta_value); if (empty($meta_value)) { return bp_xprofile_delete_meta($object_id, $object_type, $meta_key); } $cur = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key)); if (empty($cur)) { $nxtdb->query($nxtdb->prepare("INSERT INTO " . $bp->profile->table_name_meta . " ( object_id, object_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )", $object_id, $object_type, $meta_key, $meta_value)); } else { if ($cur->meta_value != $meta_value) { $nxtdb->query($nxtdb->prepare("UPDATE " . $bp->profile->table_name_meta . " SET meta_value = %s WHERE object_id = %d AND object_type = %s AND meta_key = %s", $meta_value, $object_id, $object_type, $meta_key)); } else { return false; } } // Update the cached object and recache nxt_cache_set('bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $meta_value, 'bp'); return true; }
/** * Retrieve an activity or activities * * @since 1.2.0 * * @param array $args * * @uses nxt_parse_args() * @uses nxt_cache_get() * @uses nxt_cache_set() * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity} * @uses apply_filters_ref_array() To call the 'bp_activity_get' hook * * @return object $activity The activity/activities object */ function bp_activity_get($args = '') { $defaults = array('max' => false, 'page' => 1, 'per_page' => false, 'sort' => 'DESC', 'display_comments' => false, 'search_terms' => false, 'show_hidden' => false, 'exclude' => false, 'in' => false, 'filter' => array()); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); // Attempt to return a cached copy of the first page of sitewide activity. if (1 == (int) $page && empty($max) && empty($search_terms) && empty($filter) && 'DESC' == $sort && empty($exclude)) { if (!($activity = nxt_cache_get('bp_activity_sitewide_front', 'bp'))) { $activity = BP_Activity_Activity::get($max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden); nxt_cache_set('bp_activity_sitewide_front', $activity, 'bp'); } } else { $activity = BP_Activity_Activity::get($max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $exclude, $in); } return apply_filters_ref_array('bp_activity_get', array(&$activity, &$r)); }
function bb_get_forum($id) { global $bbdb; if (!is_numeric($id)) { list($slug, $sql) = bb_get_sql_from_slug('forum', $id); $id = nxt_cache_get($slug, 'bb_forum_slug'); } // not else if (is_numeric($id)) { $sql = $bbdb->prepare("forum_id = %d", $id); } if (0 === $id || empty($sql)) { return false; } // $where is NOT bbdb:prepared if ($where = apply_filters('get_forum_where', '')) { $forum = $bbdb->get_row("SELECT * FROM {$bbdb->forums} WHERE {$sql} {$where}"); return bb_append_meta($forum, 'forum'); } if (is_numeric($id) && false !== ($forum = nxt_cache_get($id, 'bb_forum'))) { return $forum; } $forum = $bbdb->get_row("SELECT * FROM {$bbdb->forums} WHERE {$sql}"); $forum = bb_append_meta($forum, 'forum'); nxt_cache_set($forum->forum_id, $forum, 'bb_forum'); nxt_cache_add($forum->forum_slug, $forum->forum_id, 'bb_forum_slug'); return $forum; }
function bp_blogs_update_blogmeta($blog_id, $meta_key, $meta_value) { global $nxtdb, $bp; if (!is_numeric($blog_id)) { return false; } $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if (is_string($meta_value)) { $meta_value = stripslashes($nxtdb->escape($meta_value)); } $meta_value = maybe_serialize($meta_value); if (empty($meta_value)) { return bp_blogs_delete_blogmeta($blog_id, $meta_key); } $cur = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key)); if (!$cur) { $nxtdb->query($nxtdb->prepare("INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value)); } else { if ($cur->meta_value != $meta_value) { $nxtdb->query($nxtdb->prepare("UPDATE {$bp->blogs->table_name_blogmeta} SET meta_value = %s WHERE blog_id = %d AND meta_key = %s", $meta_value, $blog_id, $meta_key)); } else { return false; } } nxt_cache_set('bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $meta_value, 'bp'); return true; }
function &query() { global $bbdb; if ($args = func_get_args()) { call_user_func_array(array(&$this, 'init'), $args); } if (!$this->generate_query()) { return; } do_action_ref_array('bb_query', array(&$this)); $key = md5($this->request); if (false === ($cached_ids = nxt_cache_get($key, 'bb_query'))) { if ('post' == $this->type) { $this->results = bb_cache_posts($this->request, $this->query_vars['post_id_only']); // This always appends meta $_the_id = 'post_id'; $this->query_vars['append_meta'] = false; } else { $this->results = $bbdb->get_results($this->request); $_the_id = 'topic_id'; } $cached_ids = array(); if (is_array($this->results)) { foreach ($this->results as $object) { $cached_ids[] = $object->{$_the_id}; } } nxt_cache_set($key, $cached_ids, 'bb_query'); } else { if ('post' == $this->type) { $_query_ids = array(); $_cached_posts = array(); foreach ($cached_ids as $_cached_id) { if (false !== ($_post = nxt_cache_get($_cached_id, 'bb_post'))) { $_cached_posts[$_post->post_id] = $_post; } else { $_query_ids[] = $_cached_id; } } if (count($_query_ids)) { $_query_ids = join(',', array_map('intval', $_query_ids)); $results = $bbdb->get_results("SELECT * FROM {$bbdb->posts} WHERE post_id IN({$_query_ids})"); $results = array_merge($results, $_cached_posts); } else { $results = $_cached_posts; } $_the_id = 'post_id'; } else { $_query_ids = array(); $_cached_topics = array(); foreach ($cached_ids as $_cached_id) { if (false !== ($_topic = nxt_cache_get($_cached_id, 'bb_topic'))) { $_cached_topics[$_topic->topic_id] = $_topic; } else { $_query_ids[] = $_cached_id; } } if (count($_query_ids)) { $_query_ids = join(',', array_map('intval', $_query_ids)); $results = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN({$_query_ids})"); $results = array_merge($results, $_cached_topics); } else { $results = $_cached_topics; } $_the_id = 'topic_id'; } $this->results = array(); $trans = array(); foreach ($results as $object) { $trans[$object->{$_the_id}] = $object; } foreach ($cached_ids as $cached_id) { $this->results[] = $trans[$cached_id]; } } $this->count = count($this->results); if (false === $this->found_rows && $this->query_vars['count']) { // handles FOUND_ROWS() or COUNT(*) $this->found_rows = bb_count_last_query($this->request); } if ('post' == $this->type) { if ($this->query_vars['append_meta']) { $this->results = bb_append_meta($this->results, 'post'); } if ($this->query_vars['cache_users']) { bb_post_author_cache($this->results); } if ($this->query_vars['cache_topics']) { bb_cache_post_topics($this->results); } } else { if ($this->query_vars['append_meta']) { $this->results = bb_append_meta($this->results, 'topic'); } } return $this->results; }
function append_meta($object, $args = null) { $defaults = array('meta_table' => 'usermeta', 'meta_field' => 'user_id', 'id_field' => 'ID', 'cache_group' => 'users'); $args = nxt_parse_args($args, $defaults); extract($args, EXTR_SKIP); if (is_array($object)) { $trans = array(); foreach (array_keys($object) as $i) { $trans[$object[$i]->{$id_field}] =& $object[$i]; } $ids = join(',', array_keys($trans)); if ($ids && ($metas = $this->db->get_results("SELECT {$meta_field}, meta_key, meta_value FROM {$this->db->{$meta_table}} WHERE {$meta_field} IN ({$ids}) /* nxt_Users::append_meta */"))) { usort($metas, array(&$this, '_append_meta_sort')); foreach ($metas as $meta) { if (empty($meta->meta_key)) { continue; } $trans[$meta->{$meta_field}]->{$meta->meta_key} = maybe_unserialize($meta->meta_value); if (strpos($meta->meta_key, $this->db->prefix) === 0) { $trans[$meta->{$meta_field}]->{substr($meta->meta_key, strlen($this->db->prefix))} = maybe_unserialize($meta->meta_value); } } } foreach (array_keys($trans) as $i) { nxt_cache_set($i, $trans[$i], $cache_group); if ('users' == $cache_group) { nxt_cache_set($trans[$i]->user_login, $i, 'userlogins'); nxt_cache_set($trans[$i]->user_email, $i, 'useremail'); nxt_cache_set($trans[$i]->user_nicename, $i, 'usernicename'); } } return $object; } elseif ($object) { if ($metas = $this->db->get_results("SELECT meta_key, meta_value FROM {$this->db->{$meta_table}} WHERE {$meta_field} = '{$object->{$id_field}}' /* nxt_Users::append_meta */")) { usort($metas, array(&$this, '_append_meta_sort')); foreach ($metas as $meta) { if (empty($meta->meta_key)) { continue; } $object->{$meta->meta_key} = maybe_unserialize($meta->meta_value); if (strpos($meta->meta_key, $this->db->prefix) === 0) { $object->{substr($meta->meta_key, strlen($this->db->prefix))} = maybe_unserialize($meta->meta_value); } } } nxt_cache_set($object->{$id_field}, $object, $cache_group); if ('users' == $cache_group) { nxt_cache_set($object->user_login, $object->ID, 'userlogins'); nxt_cache_set($object->user_email, $object->ID, 'useremail'); nxt_cache_set($object->user_nicename, $object->ID, 'usernicename'); } return $object; } }
/** * bb_get_topic_tags() - Returns all of the bb_topic_tags associated with the specified topic. * * @param int $topic_id * @param mixed $args * @return array|false Term objects (back-compat), false on failure */ function bb_get_topic_tags($topic_id = 0, $args = null) { global $nxt_taxonomy_object; if (!($topic = get_topic(get_topic_id($topic_id)))) { return false; } $topic_id = (int) $topic->topic_id; $cache_id = $topic_id . serialize($args); $terms = nxt_cache_get($cache_id, 'bb_topic_tag_terms'); if (false === $terms) { $terms = $nxt_taxonomy_object->get_object_terms((int) $topic->topic_id, 'bb_topic_tag', $args); nxt_cache_set($cache_id, $terms, 'bb_topic_tag_terms'); } if (is_nxt_error($terms)) { return false; } for ($i = 0; isset($terms[$i]); $i++) { _bb_make_tag_compat($terms[$i]); } return $terms; }
function get_activity_comments($activity_id, $left, $right) { global $nxtdb, $bp; if (!($comments = nxt_cache_get('bp_activity_comments_' . $activity_id))) { // Select the user's fullname with the query if (bp_is_active('xprofile')) { $fullname_select = ", pd.value as user_fullname"; $fullname_from = ", {$bp->profile->table_name_data} pd "; $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1"; // Prevent debug errors } else { $fullname_select = $fullname_from = $fullname_where = ''; } // Retrieve all descendants of the $root node $descendants = $nxtdb->get_results(apply_filters('bp_activity_comments_user_join_filter', $nxtdb->prepare("SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$nxtdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right), $activity_id, $left, $right)); // Loop descendants and build an assoc array foreach ((array) $descendants as $d) { $d->children = array(); // If we have a reference on the parent if (isset($ref[$d->secondary_item_id])) { $ref[$d->secondary_item_id]->children[$d->id] = $d; $ref[$d->id] =& $ref[$d->secondary_item_id]->children[$d->id]; // If we don't have a reference on the parent, put in the root level } else { $comments[$d->id] = $d; $ref[$d->id] =& $comments[$d->id]; } } nxt_cache_set('bp_activity_comments_' . $activity_id, $comments, 'bp'); } return $comments; }
function widget($args, $instance) { global $comments, $comment; $cache = nxt_cache_get('widget_recent_comments', 'widget'); if (!is_array($cache)) { $cache = array(); } if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return; } extract($args, EXTR_SKIP); $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'], $instance, $this->id_base); if (empty($instance['number']) || !($number = absint($instance['number']))) { $number = 5; } $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')); $output .= $before_widget; if ($title) { $output .= $before_title . $title . $after_title; } $output .= '<ul id="recentcomments">'; if ($comments) { foreach ((array) $comments as $comment) { $output .= '<li class="recentcomments">' . sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; } } $output .= '</ul>'; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; nxt_cache_set('widget_recent_comments', $cache, 'widget'); }