forked from Thomas--F/BotTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.php
More file actions
125 lines (100 loc) · 3.91 KB
/
API.php
File metadata and controls
125 lines (100 loc) · 3.91 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id: API.php 4448 2011-04-14 08:20:49Z matt $
*
* @category Piwik_Plugins
* @package Piwik_BotTracker
*/
namespace Piwik\Plugins\BotTracker;
use Piwik\Db;
use Piwik\Common;
use Piwik\DataTable;
/**
* @see plugins/BotTracker/functions.php
*/
require_once PIWIK_INCLUDE_PATH . '/plugins/BotTracker/functions.php';
/**
* @package Piwik_BotTracker
*/
class API extends \Piwik\Plugin\API
{
static private $instance = null;
static public function getInstance()
{
if (self::$instance == null)
{
self::$instance = new self;
}
return self::$instance;
}
static function getAllBotData($idSite)
{
$rows = Db::get()->fetchAll("SELECT * FROM ".Common::prefixTable('bot_db')." WHERE idSite= ? ORDER BY `botId`", array($idSite));
// convert this array to a DataTable object
return DataTable::makeFromIndexedArray($rows);
}
static function getAllBotDataForConfig($idsite)
{
$rows = Db::get()->fetchAll("SELECT `idsite`, `botId`, `botName`, `botActive`, `botKeyword`, `extra_stats` FROM ".Common::prefixTable('bot_db')." WHERE `idsite` = ? ORDER BY `botId`", array($idsite));
return $rows;
}
static function getActiveBotData($idSite)
{
$rows = Db::get()->fetchAll("SELECT * FROM ".Common::prefixTable('bot_db')." WHERE `botActive` = 1 AND idSite= ? ORDER BY `botId`", array($idSite));
// convert this array to a DataTable object
return DataTable::makeFromIndexedArray($rows);
}
function getAllBotDataWithIcon($idSite)
{
$dataTable = $this->getAllBotData($idSite);
$dataTable->renameColumn('botActive', 'label');
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getActiveIcon'));
$dataTable->filter('ColumnCallbackReplace', array('label', create_function('$label', "return ' ';")));
$dataTable->queueFilter('ColumnCallbackAddMetadata', array(array(), 'logoWidth', function () { return 16; }));
$dataTable->queueFilter('ColumnCallbackAddMetadata', array(array(), 'logoHeight', function () { return 16; }));
return $dataTable;
}
static function getAllBotDataPie($idSite)
{
$rows = Db::get()->fetchAll("SELECT `botName`, `botCount` FROM ".Common::prefixTable('bot_db')." WHERE `idSite`= ? ORDER BY `botCount` DESC LIMIT 10", array($idSite));
$i = 0;
foreach($rows as $row)
{
$keys[$i] = $row['botName'];
$values[$i] = $row['botCount'];
$i++;
}
$pieArray = array_combine($keys, $values);
// convert this array to a DataTable object
return DataTable::makeFromIndexedArray($pieArray);
}
static function updateBot($botName, $botKeyword, $botActive, $botId, $extraStats)
{
Db::get()->query("UPDATE `".Common::prefixTable('bot_db')."`
SET `botName` = ?
, `botKeyword` = ?
, `botActive` = ?
, `extra_stats` = ?
WHERE `botId` = ?", array($botName, $botKeyword, $botActive, $extraStats, $botId));
}
static function insertBot($siteID, $botName, $botActive, $botKeyword, $extraStats)
{
Db::get()->query("INSERT INTO `".Common::prefixTable('bot_db')."`
(`idsite`,`botName`, `botActive`, `botKeyword`, `botCount`, `botLastVisit`, `extra_stats`)
VALUES (?,?,?,?,0,'0000-00-00 00:00:00',?)"
, array($siteID, $botName, $botActive, $botKeyword, $extraStats));
}
static function deleteBot($botId)
{
Db::get()->query("DELETE FROM `".Common::prefixTable('bot_db')."` WHERE `botId` = ?",array($botId));
}
static function getBotByName($siteID,$botName)
{
$rows = Db::get()->fetchAll("SELECT * FROM ".Common::prefixTable('bot_db')." WHERE `botName` = ? AND `idSite`= ? ORDER BY `botId`", array($botName, $siteID));
return $rows;
}
}