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; }
/** * Retrieves all category IDs. * * @since 2.0.0 * @link http://codex.nxtclass.org/Function_Reference/get_all_category_ids * * @return object List of all of the category IDs. */ function get_all_category_ids() { if (!($cat_ids = nxt_cache_get('all_category_ids', 'category'))) { $cat_ids = get_terms('category', array('fields' => 'ids', 'get' => 'all')); nxt_cache_add('all_category_ids', $cat_ids, 'category'); } return $cat_ids; }
function _get_cron_lock() { global $_nxt_using_ext_object_cache, $nxtdb; $value = 0; if ($_nxt_using_ext_object_cache) { // Skip local cache and force refetch of doing_cron transient in case // another processs updated the cache $value = nxt_cache_get('doing_cron', 'transient', true); } else { $row = $nxtdb->get_row($nxtdb->prepare("SELECT option_value FROM {$nxtdb->options} WHERE option_name = %s LIMIT 1", '_transient_doing_cron')); if (is_object($row)) { $value = $row->option_value; } } return $value; }
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>'; } }
/** * 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"); } } }
function bp_xprofile_get_meta($object_id, $object_type, $meta_key = '') { global $nxtdb, $bp; $object_id = (int) $object_id; if (!$object_id) { return false; } if (!isset($object_type)) { return false; } if (!in_array($object_type, array('group', 'field', 'data'))) { return false; } if (!empty($meta_key)) { $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if (!($metas = nxt_cache_get('bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, 'bp'))) { $metas = $nxtdb->get_col($nxtdb->prepare("SELECT meta_value FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s AND meta_key = %s", $object_id, $object_type, $meta_key)); nxt_cache_set('bp_xprofile_meta_' . $object_type . '_' . $object_id . '_' . $meta_key, $metas, 'bp'); } } else { $metas = $nxtdb->get_col($nxtdb->prepare("SELECT meta_value FROM " . $bp->profile->table_name_meta . " WHERE object_id = %d AND object_type = %s", $object_id, $object_type)); } if (empty($metas)) { if (empty($meta_key)) { return array(); } else { return ''; } } $metas = array_map('maybe_unserialize', (array) $metas); if (1 == count($metas)) { return $metas[0]; } else { return $metas; } }
/** * Get the value of a transient * * If the transient does not exist or does not have a value, then the return value * will be false. * * @since 1.0 * @package bbPress * @subpackage Transient * * @param string $transient Transient name. Expected to not be SQL-escaped * @return mixed Value of transient */ function bb_get_transient($transient) { global $_bb_using_ext_object_cache, $bbdb; if ($_bb_using_ext_object_cache) { $value = nxt_cache_get($transient, 'transient'); } else { $transient_option = '_transient_' . $bbdb->escape($transient); $transient_timeout = '_transient_timeout_' . $bbdb->escape($transient); $timeout = bb_get_option($transient_timeout); if ($timeout && $timeout < time()) { bb_delete_option($transient_option); bb_delete_option($transient_timeout); return false; } $value = bb_get_option($transient_option); } return apply_filters('transient_' . $transient, $value); }
/** * 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; }
/** * Retrieve info for user lists to prevent multiple queries by get_userdata() * * @since 3.0.0 * * @param array $user_ids User ID numbers list */ function cache_users($user_ids) { global $nxtdb; $clean = array(); foreach ($user_ids as $id) { $id = (int) $id; if (!nxt_cache_get($id, 'users')) { $clean[] = $id; } } if (empty($clean)) { return; } $list = implode(',', $clean); $users = $nxtdb->get_results("SELECT * FROM {$nxtdb->users} WHERE ID IN ({$list})"); $ids = array(); foreach ($users as $user) { update_user_caches($user); $ids[] = $user->ID; } update_meta_cache('user', $ids); }
/** * 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); }
} else { $blogname = substr($domain, 0, strpos($domain, '.')); } } else { $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 {
/** * Retrieve user metadata. * * If $user_id is not a number, then the function will fail over with a 'false' * boolean return value. Other returned values depend on whether there is only * one item to be returned, which be that single item type. If there is more * than one metadata value, then it will be list of metadata values. * * @since 2.0.0 * @deprecated 3.0.0 * @deprecated Use get_user_meta() * @see get_user_meta() * * @param int $user_id User ID * @param string $meta_key Optional. Metadata key. * @return mixed */ function get_usermeta($user_id, $meta_key = '') { _deprecated_function(__FUNCTION__, '3.0', 'get_user_meta()'); global $nxtdb; $user_id = (int) $user_id; if (!$user_id) { return false; } if (!empty($meta_key)) { $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); $user = nxt_cache_get($user_id, 'users'); // Check the cached user object if (false !== $user && isset($user->{$meta_key})) { $metas = array($user->{$meta_key}); } else { $metas = $nxtdb->get_col($nxtdb->prepare("SELECT meta_value FROM {$nxtdb->usermeta} WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key)); } } else { $metas = $nxtdb->get_col($nxtdb->prepare("SELECT meta_value FROM {$nxtdb->usermeta} WHERE user_id = %d", $user_id)); } if (empty($metas)) { if (empty($meta_key)) { return array(); } else { return ''; } } $metas = array_map('maybe_unserialize', $metas); if (count($metas) == 1) { return $metas[0]; } else { return $metas; } }
/** * 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; }
/** * Retrieve option value based on setting name and blog_id. * * If the option does not exist or does not have a value, then the return value * will be false. This is useful to check whether you need to install an option * and is commonly used during installation of plugin options and to test * whether upgrading is required. * * There is a filter called 'blog_option_$option' with the $option being * replaced with the option name. The filter takes two parameters. $value and * $blog_id. It returns $value. * The 'option_$option' filter in get_option() is not called. * * @since MU * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value. * * @param int $blog_id Optional. Blog ID, can be null to refer to the current blog. * @param string $setting Name of option to retrieve. Should already be SQL-escaped. * @param string $default (optional) Default value returned if option not found. * @return mixed Value set for the option. */ function get_blog_option($blog_id, $setting, $default = false) { global $nxtdb; if (null === $blog_id) { $blog_id = $nxtdb->blogid; } $key = $blog_id . '-' . $setting . '-blog_option'; $value = nxt_cache_get($key, 'site-options'); if ($value == null) { if ($blog_id == $nxtdb->blogid) { $value = get_option($setting, $default); $notoptions = nxt_cache_get('notoptions', 'options'); if (isset($notoptions[$setting])) { nxt_cache_set($key, 'noop', 'site-options'); $value = $default; } elseif ($value == false) { nxt_cache_set($key, 'falsevalue', 'site-options'); } else { nxt_cache_set($key, $value, 'site-options'); } return apply_filters('blog_option_' . $setting, $value, $blog_id); } else { $blog_prefix = $nxtdb->get_blog_prefix($blog_id); $row = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$blog_prefix}options WHERE option_name = %s", $setting)); if (is_object($row)) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values $value = $row->option_value; if ($value == false) { nxt_cache_set($key, 'falsevalue', 'site-options'); } else { nxt_cache_set($key, $value, 'site-options'); } } else { // option does not exist, so we must cache its non-existence nxt_cache_set($key, 'noop', 'site-options'); $value = $default; } } } elseif ($value == 'noop') { $value = $default; } elseif ($value == 'falsevalue') { $value = false; } // If home is not set use siteurl. if ('home' == $setting && '' == $value) { return get_blog_option($blog_id, 'siteurl'); } if ('siteurl' == $setting || 'home' == $setting || 'category_base' == $setting) { $value = untrailingslashit($value); } return apply_filters('blog_option_' . $setting, maybe_unserialize($value), $blog_id); }
/** * 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); } }
/** * 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); }
/** * 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); }
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); }
/** * Get the value of a site transient. * * If the transient does not exist or does not have a value, then the return value * will be false. * * @see get_transient() * @since 2.9.0 * @package NXTClass * @subpackage Transient * * @uses apply_filters() Calls 'pre_site_transient_$transient' hook before checking the transient. * Any value other than false will "short-circuit" the retrieval of the transient * and return the returned value. * @uses apply_filters() Calls 'site_transient_$option' hook, after checking the transient, with * the transient value. * * @param string $transient Transient name. Expected to not be SQL-escaped. * @return mixed Value of transient */ function get_site_transient($transient) { global $_nxt_using_ext_object_cache; $pre = apply_filters('pre_site_transient_' . $transient, false); if (false !== $pre) { return $pre; } if ($_nxt_using_ext_object_cache) { $value = nxt_cache_get($transient, 'site-transient'); } else { // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. $no_timeout = array('update_core', 'update_plugins', 'update_themes'); $transient_option = '_site_transient_' . $transient; if (!in_array($transient, $no_timeout)) { $transient_timeout = '_site_transient_timeout_' . $transient; $timeout = get_site_option($transient_timeout); if (false !== $timeout && $timeout < time()) { delete_site_option($transient_option); delete_site_option($transient_timeout); return false; } } $value = get_site_option($transient_option); } return apply_filters('site_transient_' . $transient, $value); }
/** * 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; }
/** * Update the metadata cache for the specified objects. * * @since 2.9.0 * @uses $nxtdb NXTClass database object for queries. * * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) * @param int|array $object_ids array or comma delimited list of object IDs to update cache for * @return mixed Metadata cache for the specified objects, or false on failure. */ function update_meta_cache($meta_type, $object_ids) { if (empty($meta_type) || empty($object_ids)) { return false; } if (!($table = _get_meta_table($meta_type))) { return false; } $column = esc_sql($meta_type . '_id'); global $nxtdb; if (!is_array($object_ids)) { $object_ids = preg_replace('|[^0-9,]|', '', $object_ids); $object_ids = explode(',', $object_ids); } $object_ids = array_map('intval', $object_ids); $cache_key = $meta_type . '_meta'; $ids = array(); $cache = array(); foreach ($object_ids as $id) { $cached_object = nxt_cache_get($id, $cache_key); if (false === $cached_object) { $ids[] = $id; } else { $cache[$id] = $cached_object; } } if (empty($ids)) { return $cache; } // Get meta info $id_list = join(',', $ids); $meta_list = $nxtdb->get_results($nxtdb->prepare("SELECT {$column}, meta_key, meta_value FROM {$table} WHERE {$column} IN ({$id_list})", $meta_type), ARRAY_A); if (!empty($meta_list)) { foreach ($meta_list as $metarow) { $mpid = intval($metarow[$column]); $mkey = $metarow['meta_key']; $mval = $metarow['meta_value']; // Force subkeys to be array type: if (!isset($cache[$mpid]) || !is_array($cache[$mpid])) { $cache[$mpid] = array(); } if (!isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey])) { $cache[$mpid][$mkey] = array(); } // Add a value to the current pid/key: $cache[$mpid][$mkey][] = $mval; } } foreach ($ids as $id) { if (!isset($cache[$id])) { $cache[$id] = array(); } nxt_cache_add($id, $cache[$id], $cache_key); } return $cache; }
/** * 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_cache_post_topics($posts) { global $bbdb; if (!$posts) { return; } $topic_ids = array(); foreach ($posts as $post) { if (false === nxt_cache_get($post->topic_id, 'bb_topic')) { $topic_ids[] = (int) $post->topic_id; } } if (!$topic_ids) { return; } sort($topic_ids); $topic_ids = join(',', $topic_ids); if ($topics = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN({$topic_ids})")) { bb_append_meta($topics, 'topic'); } }
function bp_blogs_get_blogmeta($blog_id, $meta_key = '') { global $nxtdb, $bp; $blog_id = (int) $blog_id; if (!$blog_id) { return false; } if (!empty($meta_key)) { $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if (!($metas = nxt_cache_get('bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp'))) { $metas = $nxtdb->get_col($nxtdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key)); nxt_cache_set('bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp'); } } else { $metas = $nxtdb->get_col($nxtdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id)); } if (empty($metas)) { if (empty($meta_key)) { return array(); } else { return ''; } } $metas = array_map('maybe_unserialize', (array) $metas); if (1 == count($metas)) { return $metas[0]; } else { return $metas; } }
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 get_user($user_id = 0, $args = null) { $defaults = array('output' => OBJECT, 'by' => false, 'from_cache' => true, 'append_meta' => true); $args = nxt_parse_args($args, $defaults); extract($args, EXTR_SKIP); if (!$user_id) { return false; } // Let's just deal with arrays $user_ids = (array) $user_id; if (!count($user_ids)) { return false; } // Validate passed ids $safe_user_ids = array(); foreach ($user_ids as $_user_id) { switch ($by) { case 'login': $safe_user_ids[] = $this->sanitize_user($_user_id, true); break; case 'email': if ($this->is_email($_user_id)) { $safe_user_ids[] = $_user_id; } break; case 'nicename': $safe_user_ids[] = $this->sanitize_nicename($_user_id); break; default: if (is_numeric($_user_id)) { $safe_user_ids[] = (int) $_user_id; } else { // If one $_user_id is non-numerical, treat all $user_ids as user_logins $safe_user_ids[] = $this->sanitize_user($_user_id, true); $by = 'login'; } break; } } // No soup for you! if (!count($safe_user_ids)) { return false; } // Name the cache storing non-existant ids and the SQL field to query by switch ($by) { case 'login': $non_existant_cache = 'userlogins'; $sql_field = 'user_login'; break; case 'email': $non_existant_cache = 'useremail'; $sql_field = 'user_email'; break; case 'nicename': $non_existant_cache = 'usernicename'; $sql_field = 'user_nicename'; break; default: $non_existant_cache = 'users'; $sql_field = 'ID'; break; } // Check if the numeric user IDs exist from caches $cached_users = array(); if ($from_cache) { $existant_user_ids = array(); $maybe_existant_user_ids = array(); switch ($by) { case 'login': case 'email': case 'nicename': foreach ($safe_user_ids as $_safe_user_id) { $ID = nxt_cache_get($_safe_user_id, $non_existant_cache); if (false === $ID) { $maybe_existant_user_ids[] = $_safe_user_id; } elseif (0 !== $ID) { $existant_user_ids[] = $ID; } } if (count($existant_user_ids)) { // We need to run again using numeric ids $args['by'] = false; $cached_users = $this->get_user($existant_user_ids, $args); } break; default: foreach ($safe_user_ids as $_safe_user_id) { $user = nxt_cache_get($_safe_user_id, 'users'); if (false === $user) { $maybe_existant_user_ids[] = $_safe_user_id; } elseif (0 !== $user) { $cached_users[] = $user; } } break; } // No maybes? Then it's definite. if (!count($maybe_existant_user_ids)) { if (!count($cached_users)) { // Nothing there sorry return false; } // Deal with the case where one record was requested but multiple records are returned if (!is_array($user_id) && $user_id) { if (1 < count($cached_users)) { if ('user_email' == $sql_field) { $err = __('Multiple email matches. Log in with your username.'); } else { $err = sprintf(__('Multiple %s matches'), $sql_field); } return new nxt_Error($sql_field, $err, $args + array('user_id' => $user_id, 'unique' => false)); } // If one item was requested, it expects a single user object back $cached_users = array_shift($cached_users); } backpress_convert_object($cached_users, $output); return $cached_users; } // If we get this far, there are some maybes so try and grab them } else { $maybe_existant_user_ids = $safe_user_ids; } // Escape the ids for the SQL query $maybe_existant_user_ids = $this->db->escape_deep($maybe_existant_user_ids); // Sort the ids so the MySQL will more consistently cache the query sort($maybe_existant_user_ids); // Get the users from the database $sql = "SELECT * FROM `{$this->db->users}` WHERE `{$sql_field}` in ('" . join("','", $maybe_existant_user_ids) . "');"; $db_users = $this->db->get_results($sql); // Merge in the cached users if available if (count($cached_users)) { // Create a convenient array of database fetched user ids $db_user_ids = array(); foreach ($db_users as $_db_user) { $db_user_ids[] = $_db_user->ID; } $users = array_merge($cached_users, $db_users); } else { $users = $db_users; } // Deal with the case where one record was requested but multiple records are returned if (!is_array($user_id) && $user_id) { if (1 < count($users)) { if ('user_email' == $sql_field) { $err = __('Multiple email matches. Log in with your username.'); } else { $err = sprintf(__('Multiple %s matches'), $sql_field); } return new nxt_Error($sql_field, $err, $args + array('user_id' => $user_id, 'unique' => false)); } } // Create a convenient array of final user ids $final_user_ids = array(); foreach ($users as $_user) { $final_user_ids[] = $_user->{$sql_field}; } foreach ($safe_user_ids as $_safe_user_id) { if (!in_array($_safe_user_id, $final_user_ids)) { nxt_cache_add($_safe_user_id, 0, $non_existant_cache); } } if (!count($users)) { return false; } // Add display names $final_users = array(); foreach ($users as $_user) { // Make sure there is a display_name set if (!$_user->display_name) { $_user->display_name = $_user->user_login; } $final_users[] = $_user; } // append_meta() does the user object, useremail, userlogins caching if ($append_meta) { if (count($cached_users)) { $db_final_users = array(); $cached_final_users = array(); foreach ($final_users as $final_user) { if (in_array($final_user->ID, $db_user_ids)) { $db_final_users[] = $final_user; } else { $cached_final_users[] = $final_user; } } $db_final_users = $this->append_meta($db_final_users); $final_users = array_merge($cached_final_users, $db_final_users); } else { $final_users = $this->append_meta($final_users); } } // If one item was requested, it expects a single user object back if (!is_array($user_id) && $user_id) { $final_users = array_shift($final_users); } backpress_convert_object($final_users, $output); return $final_users; }
/** * 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 update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['number'] = absint($new_instance['number']); $this->flush_widget_cache(); $alloptions = nxt_cache_get('alloptions', 'options'); if (isset($alloptions['widget_recent_comments'])) { delete_option('widget_recent_comments'); } return $instance; }