<?php
/*BEGIN_INFO
V1.0 Mr Happy - Shows the total amount of downloads for each catagory and in the queue on your site
END_INFO*/
if(!defined("WCDDL_GUTS"))
exit;
/*
To install this mod you need to have the Plugin Manager module installed which you can find here https://*********.net/topic/2058-wcddl/
Then just click on Install.
*/
$modEnabled = true; //Change to false to turn it off
class totalDownloads {
/*
How often do you want to update the list of downloads.
600 is every 10 minutes in seconds.
*/
public $time_limit = 600;
/*
debug shows errors if any exist. Only set to true if your testing or having problems etc.
*/
public $debug = false;
/*--------------- Don't edit below here unless you know what your at. ----------------*/
public $output = '';
public $total = 0;
public $error = array();
public $update = array();
public function total() {
$core = Core::load();
$data = $core->parseConfig('totalDownloads');
if($data['age'] < (time() - $this->time_limit)) {
$total = Database::quickColumn('SELECT COUNT(*) FROM ' . WCDDL_DB_PREFIX . 'queue', array());
if($total != $data['queue'][1])
$data = $this->update();
}
if((count($this->error) > 0) && $this->debug)
return 'Total Downloads Error:<br />' . implode('<br />', $this->error) . '<br />';
$this->output .= '<ul class="totaldownloads">';
foreach($data as $d) {
if($d != $data['age'])
$this->output .= '<li class="' . $d[0] . '">' . $d[0] . ' : ' . $d[1] . '</li>';
}
$this->output .= '</ul>';
return $this->output;
}
private function update() {
$rows = Database::quickRows('SELECT type,COUNT(*) cnt FROM ' . WCDDL_DB_PREFIX . 'downloads GROUP BY type');
if(!empty($rows)) {
$this->update['age'] = time();
foreach ($rows as $row) {
$this->update[$row['type']] = array($row['type'], $row['cnt']);
$this->total = $this->total + $row['cnt'];
}
}
else
$this->error[] = 'No Downloads found in database.';
$queue = Database::quickColumn('SELECT COUNT(*) FROM ' . WCDDL_DB_PREFIX . 'queue', array());
$this->update['queue'] = array('Queue', $queue);
$this->update['total'] = array('Total',$this->total);
$core = Core::load();
$core->config('totaldownloads',$this->update);
return $this->update;
}
public function checkupdate() {
return '100;https://*********.net/extra/mrhappy/check1.php?mod=totalDownloads;https://*********.net/topic/2058-wcddl-modules-advanced-seo-and-admin-protection/';
}
public function install() {
$core = Core::load();
$core->config('totaldownloads',array('age'=>123,'Movie'=>3,'Queue'=>5,'Totals'=>5));
echo "To add the Total Downloads just Add this line to your site where you want the :<br /><br /><strong>" . htmlentities("<?php echo Core::load()->templateVar('totalDownloads'); ?>") . "</strong><br /><br />For support and more modules visit <a href=\"http://*********.net\" target=\"_blank\">*********.net</a>";
}
public function uninstall() {
echo "To uninstall Total Downloads just remove the following from your your template:<br /><br /><strong>" . htmlentities("<?php echo Core::load()->templateVar('totalDownloads'); ?>") . "</strong><br /><br /><br />Remember to remove or disable the " . WCDDL_DB_PREFIX . "totalDownloads.php file from the modules folder.<br /><br />For support and more modules visit <a href=\"http://*********.net\" target=\"_blank\">*********.net</a>";
}
}
if($modEnabled) {
$totalDownloads = new totalDownloads();
Core::load()->templateVar("totalDownloads",$totalDownloads->total());
if(isset($_GET['go']) && $_GET['go']=='installtotalDownloads')
Core::load()->hook('AdminHandleContent', array('totalDownloads', 'install'));
if(isset($_GET['go']) && $_GET['go']=='checkupdatetotalDownloads')
Core::load()->hook('AdminHandleContent', array('totalDownloads', 'checkupdate'));
if(isset($_GET['go']) && $_GET['go']=='uninstalltotalDownloads')
Core::load()->hook('AdminHandleContent', array('totalDownloads', 'uninstall'));
}
?>