dimanche 25 janvier 2015

Counter Click or Total of Downloads DLE English

Counter Click or Total of Downloads
Counter clicks on the button or number of downloads.

1. At the root of the site to create a folder called click_counter ask her permission to write 777.

2. It create a PHP file with the contents of index.php:
<?PHP
@error_reporting ( E_ALL ^ E_WARNING ^ E_NOTICE );
@ini_set ( 'error_reporting', E_ALL ^ E_WARNING ^ E_NOTICE );
@ini_set ( 'display_errors', true );
@ini_set ( 'html_errors', false );
define ( 'ROOT_DIR', dirname ( __FILE__ ) );

if(!$_GET['href']) die('Undefinded href');
$href = md5($_GET['href']);
$stat = unserialize(file_get_contents(ROOT_DIR."/stats.txt"));
if(!$stat[$href]) $stat[$href] = 0;
if($_GET['type']=='set'){
$stat[$href]++;
file_put_contents(ROOT_DIR. "/stats.txt", serialize($stat), LOCK_EX);
}
echo $stat[$href];
?>

3. We now turn to the template and JS handler. As a trigger for the desired button adds the class name click_count.
For example it was:
<a href="[xfields_download]">Download</a>

And to do so:
<a href="[xfields_download]" class="click_count">Download</a>

4. Staying Connected js, for this purpose, in principle any pattern connected to the JS file, you can insert the following code:
$(function(){
function get_counter(a,b){
$.get(dle_root+'click_counter/index.php',{type:b,href:a.attr('href')},function(d){
a.find('.click_counter').html(d);
});
}
var click_trigger = ".click_count";
$(click_trigger).each(function(){
$(this).append(" <span class='click_counter' title='Click'><img src='/click_counter/loading.gif' alt=''/></span>");
get_counter($(this),'');
});
$('body').on("click",click_trigger,function(){
get_counter($(this),'set');
});
})

Done!
We should also mention - where and how the number itself will appear counter. On the example of the same html code that I quoted above, we get:
<a href="[xfields_download]" class="click_count">Download<span class='click_counter' title='Click'>0</span></a>

You just need to customize the style for the most number of counters.
Well, still, as you can see in the code, as long as the script is not processed as a plug used image /click_counter/loading.gif, you can either fill in your picture download anything at all clear picture of the code to you.

Version DLE: 9.x-10.x
Author: Sander

Aucun commentaire:

Enregistrer un commentaire