Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-06-13 23:41:34

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Download Statistics plugin

Have some code that works well for me that might be interesting as a plugin.
Thought I would get some opinions here before I made them available.
The point is to return the total number of downloads for the site, and by category;
and to return the most popular download for the site , and by category.
The code is as follows:

<code>function ras_download_total($atts)
{ extract(lAtts(array( ‘category’ => ‘’, ),$atts));
if(!$category)
{ $result = safe_query(“select SUM from “.PFX.“txp_file”,$debug); $rs = mysql_fetch_array($result); return $rs[“SUM”];
}else{ $result = safe_query(“select SUM from “.PFX.“txp_file where category=’$category’” ,$debug); $rs = mysql_fetch_array($result); return $rs[‘SUM’];
}
}
function ras_download_max($atts)
{ extract(lAtts(array( ‘category’ => ‘’, ‘label’ => ‘’, ‘break’ => br, ‘wraptag’ => ‘p’ ),$atts));
if(!$category) { $md = mysql_fetch_array(safe_query(“select MAX as max from “.PFX.“txp_file”,$debug)); extract($md); $result = safe_query(“select * from “.PFX.“txp_file where downloads=’$max’”,$debug); }else{ $md = mysql_fetch_array(safe_query(“select MAX as max from “.PFX.“txp_file where category=’$category’”,$debug)); extract($md); $result = safe_query(“select * from “.PFX.“txp_file where downloads=’$max’ && category=’$category’”,$debug); } if ($label) $out[] = $label; while($row = mysql_fetch_array($result)) { $out[] = ‘ <a href=”’.hu.‘index.php?s=file_download&id=’.$row[‘id’].’”> ‘ .$row[“filename”] . ‘</a> : ‘ . $max . ‘ ‘; }
if (!empty($out))
{ if ($wraptag 'ul' or $wraptag ‘ol’) { return doWrap($out, $wraptag, $break); }
return tag(join($break,$out),$wraptag);
}
</code>
<br />
I am open to suggestions and ideas.
I would also like to know if these functions are likely to cause anyone a pain as is, that would be bad!

Offline

#2 2006-03-29 23:00:22

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Download Statistics plugin

I’ve recently been validating a friend’s site to XHTML 1.0 Strict and came across a minor problem with the Download Stats plug-in. There are un-encoded “&” (ampersands) in the output links in the format “<code>&id=</code>” which need modifying to “<code>&amp;id=</code>”.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

Board footer

Powered by FluxBB