-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.php
95 lines (88 loc) · 2.92 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/*
# Plugin Download Counter by Web-eau.net - Forked of 'Simple Download Counter' from Yagnenok
# ------------------------------------------------------------------------
# Author web-eau.net
# Copyright (C) 2022 - web-eau-net - All Rights Reserved.
# License - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Website: https://web-eau.net
*/
// no direct access
defined( '_JEXEC' ) or die;
abstract class DownloadCounterHelper
{
public function getnames($text) {
$matches = array(); // Array for matches
if (preg_match_all('/\(downloadCounter.+\)/', $text, $matches)) { // If there is nothing with the tag (sdc xxxxxxx) then we do not sweat further
$sdc = array();
foreach($matches as $brand => $massiv)
{
foreach($massiv as $inner_key => $value)
{
$old = $value;
$value=trim($value, '()'); // Remove brackets
$value = mb_substr($value, mb_strpos($value, ' ')); // Remove the sdc tag
$value = str_replace(" ","",$value); // Remove the space
$sdc[$old] = $value;
}
}
}
return $sdc;
}
public static function check($name) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id');
$query->from($db->quoteName('#__download_counter'));
$query->where($db->quoteName('name')." = ".$db->quote($name));
$db->setQuery($query);
$result = $db->loadObjectList();
if (!count($result) > 0)
{
$query = $db->getQuery(true);
$columns = array('name', 'clicks');
$values = array($db->quote($name), 0);
$query
->insert($db->quoteName('#__download_counter'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$db->setQuery($query);
$db->execute();
}
}
public static function fsize($bytes, $decimals = 0) {
$sz = array('b','kb','mb','gb');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
public static function click($name) {
$db =& JFactory::getDBO();
$query = $db->getQuery(true)
->update('#__download_counter')
->set('clicks = (clicks + 1)')
->where("name = '$name'");
$db->setQuery($query);
$db->query(); }
public static function showclick($name) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('clicks');
$query->from($db->quoteName('#__download_counter'));
$query->where($db->quoteName('name')." = ".$db->quote($name));
$db->setQuery($query);
$result = $db->loadObjectList();
return $result;
}
public static function plural($number) {
$suffix = array("PLG_CONTENT_DOWNLOAD_COUNTER_SITE_CLICKS_COUNTER","PLG_CONTENT_DOWNLOAD_COUNTER_SITE_CLICKS_COUNTER2","PLG_CONTENT_SDC_SITE_CLICKS_COUNTER3");
$keys = array(2, 0, 1, 1, 1, 2);
$mod = $number % 100;
$suffix_key = ($mod > 7 && $mod < 20) ? 2: $keys[min($mod % 10, 5)];
return $suffix[$suffix_key];
}
public static function downloadfile($url) {
header("Location: $url ");
die;
}
}
?>