/** * Fetches categories from cache, rebuilding it if necessary * * @param boolean $force_rebuild Force rebuilding of the cache * @return array Array of category info */ function fetch_socialgroup_category_cloud($force_rebuild = false) { global $vbulletin; $categories = $vbulletin->sg_category_cloud; $hook_query_fields = $hook_query_joins = $hook_query_where = ''; ($hook = vBulletinHook::fetch_hook('group_fetch_own')) ? eval($hook) : false; if ($force_rebuild or !is_array($categories)) { $sql = "SELECT cat.socialgroupcategoryid AS categoryid, cat.title, COUNT(socialgroup.groupid) AS total\n\t\t\t\t{$hook_query_fields}\n\t\t\t\tFROM " . TABLE_PREFIX . "socialgroupcategory AS cat\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "socialgroup AS socialgroup\n\t\t\t\t ON (socialgroup.socialgroupcategoryid = cat.socialgroupcategoryid)\n\t\t\t\t{$hook_query_joins}\n\t\t\t\tWHERE socialgroup.groupid IS NOT NULL\n\t\t\t\t{$hook_query_where}\n\t\t\t\tGROUP BY cat.socialgroupcategoryid\n\t\t\t\tORDER BY total\n\t\t\t\tLIMIT 0, " . intval($vbulletin->options['sg_category_cloud_size']); $category_result = $vbulletin->db->query_read_slave($sql); $categories = $totals = array(); // fetch categories and their totals while ($category = $vbulletin->db->fetch_array($category_result)) { $categories[$category['title']] = $category; $totals[$category['categoryid']] = $category['total']; } $vbulletin->db->free_result($category_result); // fetch the stddev levels $levels = fetch_standard_deviated_levels($totals, $vbulletin->options['tagcloud_levels']); // assign the levels back to the categories foreach ($categories as $title => $category) { $categories[$title]['level'] = $levels[$category['categoryid']]; } // sort the categories by title uksort($categories, 'strnatcasecmp'); // build the cache build_datastore('sg_category_cloud', serialize($categories), 1); } return $categories; }
private function fetch_tagcloud($type = 'usage') { $vbulletin = &$this->registry; $tags = array(); if ($vbulletin->options['tagcloud_usergroup'] > 0 AND !isset($vbulletin->usergroupcache[$vbulletin->options['tagcloud_usergroup']])) { // handle a usergroup being deleted: default to live permission checking $vbulletin->options['tagcloud_usergroup'] = -1; } require_once(DIR . '/includes/class_taggablecontent.php'); $collection = new vB_Collection_ContentType(); $collection->filterTaggable(true); //create dummy content item objects. We use these to call a couple of (what? - Darren) $type_objects = array(); foreach ($collection AS $contenttype) { $type_objects[$contenttype->getID()] = vB_Taggable_Content_Item::create($vbulletin, $contenttype->getID(), null); } unset($collection, $contenttype); $cacheable = true; foreach ($type_objects AS $content) { if (!$content->is_cloud_cachable()) { $cacheable = false; break; } } if (!$cacheable) { $cloud = null; } else { switch ($type) { case 'search': if (isset($vbulletin->searchcloud)) { $cloud = $vbulletin->searchcloud; } break; case 'usage': default: $cloud = $vbulletin->tagcloud; break; } } $cloud = null; if (!is_array($cloud) OR $cloud['dateline'] < (TIMENOW - (60 * $vbulletin->options['tagcloud_cachetime']))) { if ($type == 'search') { $tags_result = $vbulletin->db->query_read_slave(" SELECT tagsearch.tagid, tag.tagtext, COUNT(*) AS searchcount FROM " . TABLE_PREFIX . "tagsearch AS tagsearch INNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tagsearch.tagid = tag.tagid) " . ($vbulletin->options['tagcloud_searchhistory'] ? "WHERE tagsearch.dateline > " . (TIMENOW - (60 * 60 * 24 * $vbulletin->options['tagcloud_searchhistory'])) : '') . " GROUP BY tagsearch.tagid, tag.tagtext ORDER BY searchcount DESC LIMIT " . $vbulletin->options['tagcloud_tags'] ); } else { //get the query bits from the type objects. If two objects return the same exact join/where information //we can collapse the subqueries. This is particularly useful for the cms content types which are //largely the same under the hood. $bit_ids = array(); $bit_values = array(); foreach ($type_objects AS $type => $content) { $contenttypeid = vB_Types::instance()->getContentTypeID($type); $bits = $content->fetch_tag_cloud_query_bits(); if ($bits) { $pos = array_search($bits, $bit_values); if ($pos === false) { $bit_ids[] = array($contenttypeid); $bit_values[] = $bits; } else { $bit_ids[$pos][] = $contenttypeid; } } } //build the subqueries from the bits. $subqueries = array(); foreach ($bit_values AS $key => $bits) { $timelimit = (TIMENOW - (60 * 60 * 24 * $vbulletin->options['tagcloud_usagehistory'])); $query = " SELECT tagcontent.tagid, tag.tagtext, COUNT(*) AS searchcount FROM " . TABLE_PREFIX . "tagcontent AS tagcontent INNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tagcontent.tagid = tag.tagid) " . implode("\n", $bits['join']) . " WHERE tagcontent.contenttypeid IN (" . implode(",", $bit_ids[$key]) . ") AND tagcontent.dateline > $timelimit AND " . implode(" AND ", $bits['where']) . " GROUP BY tagcontent.tagid, tag.tagtext "; $subqueries[] = $query; } if (count($subqueries)) { $query = " SELECT data.tagid, data.tagtext, SUM(data.searchcount) AS searchcount FROM (" . implode(" UNION ALL ", $subqueries) . ") AS data GROUP BY data.tagid, data.tagtext ORDER BY searchcount DESC LIMIT " . $vbulletin->options['tagcloud_tags']; $tags_result = $vbulletin->db->query_read_slave($query); while ($currenttag = $vbulletin->db->fetch_array($tags_result)) { $tags["$currenttag[tagtext]"] = $currenttag; $totals[$currenttag['tagid']] = $currenttag['searchcount']; } } } while ($currenttag = $vbulletin->db->fetch_array($tags_result)) { $tags["$currenttag[tagtext]"] = $currenttag; $totals[$currenttag['tagid']] = $currenttag['searchcount']; } // fetch the stddev levels $levels = fetch_standard_deviated_levels($totals, $vbulletin->options['tagcloud_levels']); // assign the levels back to the tags foreach ($tags AS $tagtext => $tag) { $tags[$tagtext]['level'] = $levels[$tag['tagid']]; $tags[$tagtext]['tagtext_url'] = urlencode(unhtmlspecialchars($tag['tagtext'])); } // sort the categories by title uksort($tags, 'strnatcasecmp'); $cloud = array( 'tags' => $tags, 'count' => sizeof($tags), 'dateline' => TIMENOW ); if ($cacheable) { if ($type == 'search' OR $type == 'selectlist') { $vbulletin->searchcloud = $cloud; } else { $vbulletin->tagcloud = $cloud; } } } if (empty($cloud['tags'])) { return ''; } $cloud['links'] = ''; return $cloud; }
/** * Returns an array of tags for the tag navigation widget * * @param int Channel ID for the root channel for this tag navigation module * @param int Maximum number of tags to return * @param bool If true, it will add the information to display as a cloud (instead of a list) * @param int The number of levels of tags (sizes for cloud) * * @return array Tag information */ public function fetchTagsForTagNavigation($channelId, $limit = 25, $addCloudInfo = false, $levels = 5) { $channelId = (int) $channelId; $channelId = $channelId < 1 ? 1 : $channelId; $limit = (int) $limit; $limit = $limit < 1 ? 1 : ($limit > 500 ? 500 : $limit); $tags = vB::getDbAssertor()->getRows('fetchTagsForTagNavigation', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, vB_dB_Query::PARAM_LIMIT => $limit, 'root_channel' => $channelId)); if ($addCloudInfo) { // assign levels to tags for tag cloud display $counts = array(); foreach ($tags as $tag) { $counts[$tag['tagid']] = $tag['count']; } $stddevlevels = fetch_standard_deviated_levels($counts, $levels); foreach ($tags as $k => $tag) { $tags[$k]['level'] = $stddevlevels[$tag['tagid']]; } } usort($tags, array($this, 'sortTagsByTagText')); return $tags; }
/** * Fetches the HTML for the tag cloud. * * @param string Type of cloud. Supports search, usage * @param bool Return full cloud box or just the links * @param int Limit cloud to blog entries owned by a specific user * * @return string Tag cloud HTML (nothing if no cloud) */ function fetch_blog_tagcloud($type = 'usage', $links = false, $userid = 0) { global $vbulletin, $vbphrase, $show, $template_hook; if (!$vbulletin->options['vbblog_tagging']) { return false; } $wheresql = array( "blog.dateline <= " . TIMENOW, "blog.pending = 0", "blog.state = 'visible'", "~blog.options & " . $vbulletin->bf_misc_vbblogoptions['private'], ); if ($userid AND $type == 'usage') { $userinfo = fetch_userinfo($userid); $wheresql[] = "blog.userid = $userid"; $cloud = @unserialize($userinfo['tagcloud']); } else { if ($vbulletin->options['vbblog_tagcloud_cachetype'] == 1) { $cloud = null; } else { switch ($type) { case 'search': $cloud = $vbulletin->blogsearchcloud; break; case 'usage': default: if ($userid) { $userinfo = fetch_userinfo($userid); $wheresql[] = "blog.userid = $userid"; } else { $cloud = $vbulletin->blogtagcloud; } break; } } } if (!is_array($cloud) OR $cloud['dateline'] < (TIMENOW - (60 * $vbulletin->options['vbblog_tagcloud_cachetime']))) { if ($type == 'search') { $tags_result = $vbulletin->db->query_read_slave(" SELECT tagsearch.tagid, tag.tagtext, COUNT(*) AS searchcount FROM " . TABLE_PREFIX . "blog_tagsearch AS tagsearch INNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tagsearch.tagid = tag.tagid) " . ($vbulletin->options['tagcloud_searchhistory'] ? "WHERE tagsearch.dateline > " . (TIMENOW - (60 * 60 * 24 * $vbulletin->options['vbblog_tagcloud_searchhistory'])) : '') . " GROUP BY tagsearch.tagid, tag.tagtext ORDER BY searchcount DESC LIMIT " . $vbulletin->options['vbblog_tagcloud_tags'] ); } else { $joinsql = array(); if ($vbulletin->options['vbblog_tagcloud_cachetype'] == 1) { if ($vbulletin->userinfo['userid']) { $userlist_sql = array(); $userlist_sql[] = "(options_ignore & " . $vbulletin->bf_misc_vbblogsocnetoptions['canviewmyblog'] . " AND ignored.relationid IS NOT NULL)"; $userlist_sql[] = "(options_buddy & " . $vbulletin->bf_misc_vbblogsocnetoptions['canviewmyblog'] . " AND buddy.relationid IS NOT NULL)"; $userlist_sql[] = "(options_member & " . $vbulletin->bf_misc_vbblogsocnetoptions['canviewmyblog'] . " AND (options_buddy & " . $vbulletin->bf_misc_vbblogsocnetoptions['canviewmyblog'] . " OR buddy.relationid IS NULL) AND (options_ignore & " . $vbulletin->bf_misc_vbblogsocnetoptions['canviewmyblog'] . " OR ignored.relationid IS NULL))"; $wheresql[] = "(" . implode(" OR ", $userlist_sql) . ")"; $joinsql[] = "LEFT JOIN " . TABLE_PREFIX . "userlist AS buddy ON (buddy.userid = blog.userid AND buddy.relationid = " . $vbulletin->userinfo['userid'] . " AND buddy.type = 'buddy')"; $joinsql[] = "LEFT JOIN " . TABLE_PREFIX . "userlist AS ignored ON (ignored.userid = blog.userid AND ignored.relationid = " . $vbulletin->userinfo['userid'] . " AND ignored.type = 'ignore')"; } else { $wheresql[] = "options_guest & " . $vbulletin->bf_misc_vbblogsocnetoptions['canviewmyblog']; $wheresql[] = "~blog.options & " . $vbulletin->bf_misc_vbblogoptions['private']; } if (!empty($vbulletin->userinfo['blogcategorypermissions']['cantview']) AND $userinfo['userid'] != $vbulletin->userinfo['userid']) { $joinsql[] = "LEFT JOIN " . TABLE_PREFIX . "blog_categoryuser AS cu ON (cu.blogid = blog.blogid AND cu.blogcategoryid IN (" . implode(", ", $vbulletin->userinfo['blogcategorypermissions']['cantview']) . "))"; $wheresql[] = "cu.blogcategoryid IS NULL"; } // remove blog entries that don't interest us require_once(DIR . '/includes/functions_bigthree.php'); if ($coventry = fetch_coventry('string')) { $wheresql[] = "blog.userid NOT IN ($coventry)"; } } else { if (trim($vbulletin->options['globalignore']) != '') { if ($coventry = preg_split('#\s+#s', $vbulletin->options['globalignore'], -1, PREG_SPLIT_NO_EMPTY)) { $wheresql[] = "blog.userid NOT IN (" . implode(',', $coventry) . ")"; } } } //get autoloader hooked up. require_once(DIR . '/includes/class_bootstrap_framework.php'); vB_Bootstrap_Framework::init(); $contenttypeid = vB_Types::instance()->getContentTypeID('vBBlog_BlogEntry'); $tags_result = $vbulletin->db->query_read_slave(" SELECT tagcontent.tagid, tag.tagtext, COUNT(*) AS searchcount FROM " . TABLE_PREFIX . "tagcontent AS tagcontent INNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tagcontent.tagid = tag.tagid) INNER JOIN " . TABLE_PREFIX . "blog AS blog ON (tagcontent.contenttypeid = $contenttypeid AND tagcontent.contentid = blog.blogid) INNER JOIN " . TABLE_PREFIX . "blog_user AS blog_user ON (blog.userid = blog_user.bloguserid) " . (!empty($joinsql) ? implode("\r\n", $joinsql) : "") . " WHERE " . implode(" AND ", $wheresql) . " " . ($vbulletin->options['vbblog_tagcloud_usagehistory'] ? "AND tagcontent.dateline > " . (TIMENOW - (60 * 60 * 24 * $vbulletin->options['vbblog_tagcloud_usagehistory'])) : "") . " GROUP BY tagcontent.tagid, tag.tagtext ORDER BY searchcount DESC LIMIT " . $vbulletin->options['vbblog_tagcloud_tags'] ); } $tags = array(); $counts = array(); if (!empty($tags_result)) { while ($currenttag = $vbulletin->db->fetch_array($tags_result)) { $tags["$currenttag[tagtext]"] = $currenttag; $counts[$currenttag['tagid']] = $currenttag['searchcount']; } $vbulletin->db->free_result($tags_result); // fetch the stddev levels $levels = fetch_standard_deviated_levels($counts, $vbulletin->options['vbblog_tagcloud_levels']); // assign the levels back to the tags $final_tags = array(); foreach ($tags AS $tagtext => $thistag) { $thistag['level'] = $levels[$thistag['tagid']]; $thistag['tagtext_url'] = urlencode(unhtmlspecialchars($thistag['tagtext'])); $final_tags[] = $thistag; } uksort($tags, 'strnatcasecmp'); } $cloud = array( 'tags' => $final_tags, 'count' => sizeof($final_tags), 'dateline' => TIMENOW ); if ($userid) { $dataman =& datamanager_init('Blog_User', $vbulletin, ERRTYPE_STANDARD); $info = array('bloguserid' => $userinfo['userid']); $dataman->set_existing($info); $dataman->set('tagcloud', $cloud); $dataman->save(); unset($dataman); } else { if ($vbulletin->options['vbblog_tagcloud_cachetype'] == 2) { if ($type == 'search') { $vbulletin->blogsearchcloud = $cloud; build_datastore('blogsearchcloud', serialize($cloud), 1); } else { $vbulletin->blogtagcloud = $cloud; build_datastore('blogtagcloud', serialize($cloud), 1); } } } } if (empty($cloud['tags'])) { return ''; } $cloud['links'] = ''; foreach ($cloud['tags'] AS $thistag) { ($hook = vBulletinHook::fetch_hook('blog_tag_cloud_bit')) ? eval($hook) : false; $show['userlink'] = ($userid); $templater = vB_Template::create('blog_tag_cloud_link'); $templater->register('thistag', $thistag); $templater->register('userinfo', $userinfo); $templater->register('pageinfo', array('tag' => $thistag['tagtext_url'])); $cloud['links'] .= $templater->render(); } if ($links) { $cloud_html = $cloud['links']; } else { $cloud['count'] = vb_number_format($cloud['count']); $templater = vB_Template::create('blog_tag_cloud_box'); $templater->register('cloud', $cloud); $templater->register('userinfo', $userinfo); $cloud_html .= $templater->render(); } if ($cloud_html) { $show['tagcloud_css'] = true; } return $cloud_html; }
/** * Fetches the HTML for the tag cloud. * * @param string Type of cloud. Supports search, usage * * @return string Tag cloud HTML (nothing if no cloud) */ function fetch_tagcloud($type = 'usage') { global $vbulletin, $stylevar, $vbphrase, $show, $template_hook; $tags = array(); if ($vbulletin->options['tagcloud_usergroup'] > 0 and !isset($vbulletin->usergroupcache[$vbulletin->options['tagcloud_usergroup']])) { // handle a usergroup being deleted: default to live permission checking $vbulletin->options['tagcloud_usergroup'] = -1; } $cacheable = $vbulletin->options['tagcloud_usergroup'] != -1; if (!$cacheable) { $cloud = null; } else { switch ($type) { case 'search': $cloud = $vbulletin->searchcloud; break; case 'usage': default: $cloud = $vbulletin->tagcloud; break; } } if (!is_array($cloud) or $cloud['dateline'] < TIMENOW - 60 * $vbulletin->options['tagcloud_cachetime']) { if ($type == 'search') { $tags_result = $vbulletin->db->query_read_slave("\n\t\t\t\tSELECT tagsearch.tagid, tag.tagtext, COUNT(*) AS searchcount\n\t\t\t\tFROM " . TABLE_PREFIX . "tagsearch AS tagsearch\n\t\t\t\tINNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tagsearch.tagid = tag.tagid)\n\t\t\t\t" . ($vbulletin->options['tagcloud_searchhistory'] ? "WHERE tagsearch.dateline > " . (TIMENOW - 60 * 60 * 24 * $vbulletin->options['tagcloud_searchhistory']) : '') . "\n\t\t\t\tGROUP BY tagsearch.tagid, tag.tagtext\n\t\t\t\tORDER BY searchcount DESC\n\t\t\t\tLIMIT " . $vbulletin->options['tagcloud_tags']); } else { if (!$vbulletin->options['tagcloud_usergroup']) { $perm_limit = false; } else { $forums = array(); $perm_limit = true; foreach ($vbulletin->forumcache as $forumid => $forum) { // -1 for live permission checking $perm_array = $vbulletin->options['tagcloud_usergroup'] == -1 ? $vbulletin->userinfo['forumpermissions']["{$forumid}"] : $forum['permissions'][$vbulletin->options['tagcloud_usergroup']]; if ($perm_array & $vbulletin->bf_ugp_forumpermissions['canview'] and $perm_array & $vbulletin->bf_ugp_forumpermissions['canviewthreads'] and $perm_array & $vbulletin->bf_ugp_forumpermissions['canviewothers']) { $forums[] = intval($forumid); } } } if (!$perm_limit or $forums) { $tags_result = $vbulletin->db->query_read_slave("\n\t\t\t\t\tSELECT tagthread.tagid, tag.tagtext, COUNT(*) AS searchcount\n\t\t\t\t\tFROM " . TABLE_PREFIX . "tagthread AS tagthread\n\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "tag AS tag ON (tagthread.tagid = tag.tagid)\n\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "thread AS thread ON (tagthread.threadid = thread.threadid)\n\t\t\t\t\tWHERE thread.open <> 10\n\t\t\t\t\t\tAND thread.visible = 1\n\t\t\t\t\t" . ($perm_limit ? "AND thread.forumid IN (" . implode(',', $forums) . ")" : '') . "\n\t\t\t\t\t" . ($vbulletin->options['tagcloud_usagehistory'] ? "AND tagthread.dateline > " . (TIMENOW - 60 * 60 * 24 * $vbulletin->options['tagcloud_usagehistory']) : '') . "\n\t\t\t\t\tGROUP BY tagthread.tagid, tag.tagtext\n\t\t\t\t\tORDER BY searchcount DESC\n\t\t\t\t\tLIMIT " . $vbulletin->options['tagcloud_tags']); } } while ($currenttag = $vbulletin->db->fetch_array($tags_result)) { $tags["{$currenttag['tagtext']}"] = $currenttag; $totals[$currenttag['tagid']] = $currenttag['searchcount']; } // fetch the stddev levels $levels = fetch_standard_deviated_levels($totals, $vbulletin->options['tagcloud_levels']); // assign the levels back to the tags foreach ($tags as $tagtext => $tag) { $tags[$tagtext]['level'] = $levels[$tag['tagid']]; $tags[$tagtext]['tagtext_url'] = urlencode(unhtmlspecialchars($tag['tagtext'])); } // sort the categories by title uksort($tags, 'strnatcasecmp'); $cloud = array('tags' => $tags, 'count' => sizeof($tags), 'dateline' => TIMENOW); if ($cacheable) { if ($type == 'search') { $vbulletin->searchcloud = $cloud; build_datastore('searchcloud', serialize($cloud), 1); } else { $vbulletin->tagcloud = $cloud; build_datastore('tagcloud', serialize($cloud), 1); } } } if (empty($cloud['tags'])) { return ''; } $cloud['links'] = ''; foreach ($cloud['tags'] as $thistag) { ($hook = vBulletinHook::fetch_hook('tag_cloud_bit')) ? eval($hook) : false; eval('$cloud[\'links\'] .= "' . fetch_template('tag_cloud_link') . '";'); } $cloud['count'] = vb_number_format($cloud['count']); if ($type == 'search') { eval('$cloud_html .= "' . fetch_template('tag_cloud_box_search') . '";'); } else { eval('$cloud_html .= "' . fetch_template('tag_cloud_box') . '";'); } return $cloud_html; }