Table of Contents

WhatPulse

Displays Whatpulse statistics, either of one user, a team, or a team and all its members….

Syntax

<%WhatPulse([UserID])%> displays the stats of one user.

<%WhatPulse([TeamID],team)%> displays the stats of one team.

<%WhatPulse([TeamID],team,yes)%> displays the stats of one team including all of its members.

Changelog

  • 0.1 (22 April 2005) - Initial release.

Links

Code

Save as NP_WhatPulse.php (mind the capital P)

<?
/*
This plugin fetches and outputs WhatPulse statistics from either user or team.
Based on webapi scripts by wasted@whatpulse.org
Version history:
0.1 Initial release
*/
 
class NP_Whatpulse extends NucleusPlugin {
    function getName()    {return 'WhatPulse'; }
    function getAuthor()  {return 'Armon Toubman'; }
    function getURL()     {return 'http://armon.globalog.net/'; }
    function getVersion() {return '0.1'; }
    function getDescription() {
	return 'A plugin to display WhatPulse statistics. Usage: <%WhatPulse(MemberID)%> for userstats, <%WhatPulse(TeamID,team)%> for teamstats, <%WhatPulse(TeamID,team,yes)%> for teamstats with all memberstats. Warning! Display members only from small teams, otherwise your site slows down drastically.';
    }
 
    function supportsFeature($what) {
	switch($what) {
	    case 'SqlTablePrefix':
		return 1;
	    default:
		return 0;
	}
    }
 
    function install() {
	$this->createOption('Userstats','Which user-stats should be displayed? Divide with one space.','textarea','UserID AccountName Country DateJoined Homepage LastPulse Pulses TotalKeyCount TotalMouseClicks AvKeysPerPulse AvClicksPerPulse AvKPS AvCPS Rank TeamID TeamName TeamMembers TeamKeys TeamClicks TeamDescription TeamDateFormed RankInTeam GeneratedTime');
	$this->createOption('Teamstats','Which team-stats should be displayed? Divide with one space.','textarea','TeamName TeamDescription TeamMembers TeamClicks TeamKeys TeamRank TeamDateFormed TeamFounder');
	$this->createOption('Memberstats','Which team-member-stats should be displayed? Divide with one space.','textarea','MemberName MemberUserID MemberKeys MemberClicks MemberLastpulse MemberManager MemberCountry');
	$this->createOption('StatsHeader','The text you enter here will be displayed at the top of the stats. Optional. (HTML enabled)','text','WhatPulse Stats');
	$this->createOption('WPLink','The link you enter here will be displayed at the bottom of the stats. Optional. (HTML enabled)','text','<a href="http://www.whatpulse.org" target="_blank">Join WhatPulse!</a>');
    }
 
	function doSkinVar($skintype, $id, $type = "user", $parsemembers = "no") {
 
		$header = $this->getOption(StatsHeader);
		    if ($header) {
			    echo $header . "<br />";
		    }
		    else {
		    }
 
		if ($type == "user") {
			$userid = $id;
 
		    // prepare an array to hold your stats
			$WhatPulseStats = array();
 
			// types of statistics 
			$stat_types = array("UserID", "AccountName", "Country",
							"DateJoined", "Homepage", "LastPulse", 
							"Pulses", "TotalKeyCount", "TotalMouseClicks",
							"AvKeysPerPulse", "AvClicksPerPulse", 
							"AvKPS", "AvCPS", "Rank", "TeamID", 
							"TeamName", "TeamMembers", "TeamKeys", 
							"TeamClicks", "TeamDescription", 
							"TeamDateFormed", "RankInTeam", "GeneratedTime");
 
   			// init the xml parser and read the data into an array
   			$data = implode("", file("http://whatpulse.org/api/users/".$userid.".xml"));
   			$parser = xml_parser_create();
   			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
   			xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
   			xml_parse_into_struct($parser, $data, $values, $tags);
   			xml_parser_free($parser);
 
   			// loop through the structures
   			foreach ($tags as $key => $val) 
   			{
	   			// only process stuff between the <UserStats> tags
       			if ($key == "UserStats") 
       			{
	    	   		// loop through the tags inside <UserStats>
        	   		$ranges = $val;
        	   		for ($i = 0; $i < count($ranges); $i += 2) 
        	   		{
						$offset = $ranges[$i] + 1;
						$len = $ranges[$i + 1] - $offset;
						$statsarray = array_slice($values, $offset, $len);
 
						// loop through the structure of the xml tag
						foreach($statsarray as $key => $value)
						{
							// match to a stats_type
							for($i = 0; $i < count($stat_types); $i++)
							{
								if($value['tag'] == $stat_types[$i]) 
								{
									// remember the value of the stats_type
									$type = $stat_types[$i];
									$WhatPulseStats[$type] = $value['value'];
								}
							} 
						} 
					} 
				} 
				else {
					continue;
				}
			}
 
			$printarray = $this->getOption(Userstats);
			$printarray = explode(" ", $printarray);
 
			foreach($printarray as $z) {
				echo $z . ": " . $WhatPulseStats[$z] . "<br />";
			}
 
			}
 
			elseif ($type == "team") {
				$teamid = $id;
				$allmembers = $this->getOption(AllMembers);
 
				$statistics_tags = array("TeamName", "TeamDescription", "TeamMembers", "TeamClicks", 
									 "TeamKeys", "TeamRank", "TeamDateFormed", "TeamFounder");
 
				$member_tags 	 = array("MemberName", "MemberUserID", "MemberKeys", "MemberClicks", 
										 "MemberLastpulse", "MemberManager", "MemberCountry");
 
				// init xml parser and read xml file
				$data   = implode("", file("http://whatpulse.org/api/teams/".$teamid.".xml"));
				$parser = xml_parser_create();
				xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
				xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
				xml_parse_into_struct($parser, $data, $values, $index);
				xml_parser_free($parser);
 
				for ($x = 0; $x < sizeof($statistics_tags); $x++) 
				{
					$team_stats[$statistics_tags[$x]] = $values[$index[$statistics_tags[$x]][0]]['value'];
				}	
 
				$printarray = $this->getOption(Teamstats);
				$printarray = explode(" ", $printarray);	
				foreach($printarray as $z) {
					echo $z . ": " . $team_stats[$z] . "<br />";
				}
 
				echo "<br />";
 
				if ($parsemembers == "yes") {
					for ($x = 0; $x < sizeof($index['Member']); $x++) {
						for ($y = 0; $y < sizeof($member_tags); $y++) {
							if ($values[$index[$member_tags[$y]][$x]]['level'] == 5)
							{
								$members[$x][$member_tags[$y]] = $values[$index[$member_tags[$y]][$x]]['value'];
							}
						}
					}
 
					$printarray = $this->getOption(Memberstats);
					$printarray = explode(" ", $printarray);
 
					for ($x = 0; $x < sizeof($members); $x++) {
						foreach($printarray as $z) {
							echo $z . ": " . $members[$x][$z] . "<br />";
						}
						echo "<br />";
					}
 
				}
				else {
				}
 
			}
 
 
		    $bottomlink = $this->getOption(WPLink);
		    if ($bottomlink) {
			    echo $bottomlink;
		    }
		    else {
		    }
 
    }
 
}
?>
whatpulse.txt · Last modified: 2006/07/05 13:03 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki