View Single Post
  #522  
Old 07-21-2004, 10:41 AM
Natch's Avatar
Natch Natch is offline
 
Join Date: Nov 2002
Location: Australia
Posts: 851
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have moved over to using vBa CMPS - here is my new module for tha tportal to show the last month's most popular links: Link to original posting of this module on vBa homepage

My members requested a different count of the hits - one that "reset" every month to show the current most popular links, not just the All time most popular links...

So I did it.

Replace your current hotlinks.php / install a hotlinks.php module with the following contents:
Code:
<?
// ######################## USER-EDITABLE VAR ############################
// If you want to use the standard VBulletin database table prefix, comment out
// the following line and uncomment the line after it
define('THIS_TABLE', 'local_');
// define ('THIS_TABLE', TABLE_PREFIX); 
//
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/functions_misc.php');

	global $DB_site, $vboptions, $forumcache;

	$limit = "3";  // default number of HotLinks to display in case not set in database

	$links_permissions = array();
	$links_defaults	= array();

	$asb = $DB_site->query("SELECT * FROM ".THIS_TABLE."linksadmin");
	while ($admin_settings = $DB_site->fetch_array($asb)) {
		if (substr($admin_settings["settingname"],0,3) == "can") {
			$array = preg_split("/[\s,]+/", $admin_settings["setting"]);
			$links_permissions[$admin_settings["settingname"]] = iif(in_array($bbuserinfo[usergroupid], $array), 1, 0);
		} else {
			$links_defaults[$admin_settings["settingname"]] = $admin_settings["setting"];
		}
	}

	if (isset($links_permissions[can_see_protected_links_on_portal])) {
		$cansee = $links_permissions[can_see_protected_links_on_portal];
	} else {
		$cansee = 0;
	}
	
	$thismonth = vbdate("n")-1;
	$thisyear = vbdate("Y");
	$lastmonth = vbmktime("6","0","0",$thismonth,"1",$thisyear);

	$filter = "WHERE link.linkmoderate = 0 AND ldown.usertime > $lastmonth ";

	if (!$cansee) {
		$limitfids = array(0);
		$forumperms = array();
		foreach ($forumcache AS $forum) {
			$forumperms["$forum[forumid]"] = fetch_permissions($forum['forumid']);
			if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
				$limitfids[] = $forum['forumid'];
			}
		}
		$filter .= 'AND link.linkforum NOT IN ('.implode(',', $limitfids).') ';
	}

	if (isset($links_defaults[categories_seen_on_portal])) {
		$catsee = $links_defaults[categories_seen_on_portal];
	} else {
		$catsee = '';
	}
	if ($catsee != '') $filter .= 'AND ltoc.catid IN ('.$catsee.')';

	if (isset($links_defaults[links_seen_on_portal])) {
		$linksee = $links_defaults[links_seen_on_portal];
	} else {
		$linksee = $limit;
	}

	$hotquery = "
		SELECT DISTINCT link.linkid AS linkid, link.linkname AS linkname, link.linkdesc AS linkdesc, 
			COUNT(ldown.usertime) AS linkhits, link.linkstatus AS linkstatus, 
			ltoc.catid AS linkcatid, link.linkhits AS olinkhits 
		FROM ".THIS_TABLE."linkslink AS link
		LEFT JOIN ".THIS_TABLE."linksdownloads AS ldown
			ON link.linkid = ldown.linkid
		LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
			ON link.linkid = ltoc.linkid
		$filter
		GROUP BY olinkhits ORDER BY linkhits DESC
		LIMIT $linksee
	";

	$hotties = $DB_site->query($hotquery);

	while ($myrow=$DB_site->fetch_array($hotties)) {
		$linkid	 	= $myrow["linkid"];
		$linkname	= parse_bbcode2($myrow["linkname"], 1, 1, 1, 1);
		$linkdesc	= parse_bbcode2($myrow["linkdesc"], 1, 1, 1, 1);
		$linkhits	= $myrow["olinkhits"];
		$monthhits	= $myrow["linkhits"];
		$linkstatus	= $myrow["linkstatus"];
		if ($linkstatus > 1)  {  // filesize, convert to KB
			$linkstatus = intval (round($linkstatus / 1024));
		}
		eval('$hotlinksbits .= "' . fetch_template('adv_portal_hotlinksbits') . '";');
		$nhits++;
	}
	eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_hotlinks') . '";');
?>
Enjoy!
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01120 seconds
  • Memory Usage 1,788KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete