Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#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
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>&id=</code>”.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Pages: 1