From 45d41f49ae2f83835b9b96ac78a05b3a96f36f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikke=20Schir=C3=A9n?= Date: Sun, 7 Apr 2024 00:42:49 +0200 Subject: [PATCH 1/6] adding sniffs to improve coding standard --- API.php | 491 +++++++++++++------------- BotTracker.php | 20 +- Commands/AddBot.php | 5 +- Commands/AddBotType.php | 5 +- Commands/AddDefaultBots.php | 7 +- Commands/DeleteBot.php | 7 +- Commands/ListBotTypes.php | 3 + Commands/ListBots.php | 7 +- Controller.php | 12 +- Menu.php | 3 + Reports/Base.php | 3 + Reports/GetBotTracker.php | 26 +- Reports/GetBotTrackerAnzeige.php | 26 +- Reports/GetBotTrackerReport.php | 27 +- Reports/GetBotTrackerTopTenReport.php | 29 +- Reports/GetOtherBots.php | 25 +- Reports/GetStatsReport.php | 25 +- Reports/GetTop10.php | 24 +- SystemSettings.php | 11 +- TESTS.md | 2 +- Widgets/GetDigiInfo.php | 29 +- composer.json | 5 +- tests/phpunit.xml | 1 + 23 files changed, 425 insertions(+), 368 deletions(-) diff --git a/API.php b/API.php index b5194b4..095bf92 100644 --- a/API.php +++ b/API.php @@ -3,41 +3,173 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ namespace Piwik\Plugins\BotTracker; -use Piwik\Container\StaticContainer; -use Piwik\Db; use Piwik\Common; +use Piwik\Container\StaticContainer; use Piwik\DataTable; -use Piwik\Site; use Piwik\Date; -use Piwik\Piwik; +use Piwik\Db; use Piwik\Period; +use Piwik\Piwik; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution; +use Piwik\Site; /** * @package Piwik_BotTracker */ class API extends \Piwik\Plugin\API { + private static $instance = null; - private static function getDb() + public function deleteBot($botId) { - return Db::get(); + Piwik::checkUserHasSuperUserAccess(); + try { + $db = self::getDb(); + $query = $db->query( + "DELETE FROM `" . + Common::prefixTable('bot_db') . + "` WHERE `botId` = ?", + [$botId] + ); + return true; + } catch (\Exception $e) { + throw $e; + return false; + } } /** - * @return DataTable + * Get Data for the Report "Top10" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable */ - private static function getDataTable($rows) + public function getTop10($idSite, $period, $date, $segment = false) { - return DataTable::makeFromIndexedArray($rows); + Piwik::checkUserHasSomeViewAccess(); + return $this->getAllBotDataPie($idSite); + } + + /** + * Get Data for the Report "BotTracker" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable + */ + public function getBotTracker($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getAllBotData($idSite); + } + + /** + * Get Data for the Report "BotTrackerReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getBotTrackerReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getBotTrackerReportDataTable($idSite, $period, $date, $segment = false); + } + + /** + * Get Data for the Report "BotStatsReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getOtherBots($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getOtherBotsDataTable($idSite, $period, $date, $segment = false); + } + + /** + * Get Data for the Report "BotStatsReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getStatsReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getStatsReportDataTable($idSite, $period, $date, $segment = false); + } + + /** + * Get Data for the Report "BotTrackerReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable + */ + public function getBotTrackerTopTenReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getBotTrackerTopTenReportPieDataTable($idSite, $period, $date, $segment = false); } + + /** + * Get Data for Dashboard-Widget + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable + */ + public function getBotTrackerAnzeige($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getActiveBotData($idSite); + } + + public function getBotTypes() + { + Piwik::checkUserHasSomeViewAccess(); + $db = self::getDb(); + $rows = $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); + return $rows; + } + + public function addBotType($type) + { + Piwik::checkUserHasSuperUserAccess(); + try { + $db = self::getDb(); + $sql = sprintf( + 'INSERT INTO ' . Common::prefixTable('bot_type') . ' (`name`) VALUES (?)' + ); + $db->query($sql, [$type]); + } catch (\Exception $e) { + throw $e; + } + } + /** * @return \Piwik\Plugins\BotTracker\API * @throws \Exception @@ -72,7 +204,7 @@ public static function getAllBotData($idSite) } /** - * @return DataTable + * @return \Piwik\DataTable */ public static function getBotTrackerReportDataTable($idSite, $period, $date, $segment) { @@ -134,9 +266,9 @@ public static function getBotTrackerTopTenReportPieData($idSite, $period, $date, // For some reason, we are off by one, add an dummy bot in end. // @todo: Look into why this is needed. $dummy = [ - 'botName' => 'dummy', - 'botId' => 0, 'botCount' => 0, + 'botId' => 0, + 'botName' => 'dummy', ]; array_push($rows, $dummy); // Get totals of a bot number. @@ -183,7 +315,6 @@ public static function getAllBotDataForConfig($idsite) return $rows; } - public static function getActiveBotData($idSite) { Piwik::checkUserHasSomeViewAccess(); @@ -269,66 +400,65 @@ public static function insertBot($idSite, $botName, $botActive, $botKeyword, $ex } } - public static function defaultBots() { $botList = []; - $botList[] = ['Amazonbot','Amazonbot']; - $botList[] = ['Qualys','Qualys']; - $botList[] = ['bingbot','bingbot']; - $botList[] = ['YandexBot','YandexBot']; - $botList[] = ['AhrefsBot','AhrefsBot']; - $botList[] = ['Ahrefs','Ahrefs']; - $botList[] = ['Scrapy','Scrapy']; - $botList[] = ['Googlebot-Image','Google-Image']; - $botList[] = ['Googlebot-News','Googlebot-News']; - $botList[] = ['Googlebot-Video','Googlebot-Video']; - $botList[] = ['Storebot-Google','Storebot-Google']; - $botList[] = ['Google-InspectionTool','Google-InspectionTool']; - $botList[] = ['Google-Extended','Google-Extended']; - $botList[] = ['GoogleOther','GoogleOther']; - $botList[] = ['APIs-Google','APIs-Google']; - $botList[] = ['AdsBot-Google-Mobile','AdsBot-Google-Mobile']; - $botList[] = ['AdsBot-Google','AdsBot-Google']; - $botList[] = ['Mediapartners-Google','Google AdSense']; - $botList[] = ['Google-Safety','Google-Safety']; - $botList[] = ['Googlebot','Googlebot']; - $botList[] = ['Google-Read-Aloud','Google-Read-Aloud']; - $botList[] = ['Google-Site-Verification','Google-Site-Verification']; - $botList[] = ['AdIdxBot','AdIdxBot']; - $botList[] = ['NewRelic','NewRelic']; - $botList[] = ['Detectify','Detectify']; - $botList[] = ['UptimeRobot','UptimeRobot']; - $botList[] = ['SendGrid','SendGrid']; - $botList[] = ['Applebot','Applebot']; - $botList[] = ['PinterestBot','PinterestBot']; - $botList[] = ['Pingdom','Pingdom']; - $botList[] = ['Barkrowler','Barkrowler']; - $botList[] = ['SEMrush','SEMrush']; - $botList[] = ['GPTBot','GPTBot']; - $botList[] = ['ChatGPT-User','ChatGPT-User']; - $botList[] = ['Bytespider','Bytespider']; - $botList[] = ['CCBot','CCBot']; - $botList[] = ['FacebookBot','FacebookBot']; - $botList[] = ['Google-Extended','Google-Extended']; - $botList[] = ['Site24x7','Site24x7']; - $botList[] = ['Stripe','Stripe']; - $botList[] = ['Slackbot','Slackbot']; - $botList[] = ['Proximic','Proximic']; - $botList[] = ['okhttp','okhttp']; - $botList[] = ['Python','Python']; - $botList[] = ['SemrushBot','SemrushBot']; - $botList[] = ['Chrome-Lighthouse','Chrome-Lighthouse']; - $botList[] = ['Axios','Axios']; - $botList[] = ['PetalBot','PetalBot']; - $botList[] = ['CriteoBot','CriteoBot']; - $botList[] = ['Baidu','Baidu']; - $botList[] = ['ContentKing','ContentKing']; - $botList[] = ['IAS crawler','IAS crawler']; - $botList[] = ['Sucuri','Sucuri']; - $botList[] = ['Seekport','Seekport']; - $botList[] = ['Sogou','Sogou']; - $botList[] = ['YahooMailProxy','YahooMailProxy']; + $botList[] = ['Amazonbot', 'Amazonbot']; + $botList[] = ['Qualys', 'Qualys']; + $botList[] = ['bingbot', 'bingbot']; + $botList[] = ['YandexBot', 'YandexBot']; + $botList[] = ['AhrefsBot', 'AhrefsBot']; + $botList[] = ['Ahrefs', 'Ahrefs']; + $botList[] = ['Scrapy', 'Scrapy']; + $botList[] = ['Googlebot-Image', 'Google-Image']; + $botList[] = ['Googlebot-News', 'Googlebot-News']; + $botList[] = ['Googlebot-Video', 'Googlebot-Video']; + $botList[] = ['Storebot-Google', 'Storebot-Google']; + $botList[] = ['Google-InspectionTool', 'Google-InspectionTool']; + $botList[] = ['Google-Extended', 'Google-Extended']; + $botList[] = ['GoogleOther', 'GoogleOther']; + $botList[] = ['APIs-Google', 'APIs-Google']; + $botList[] = ['AdsBot-Google-Mobile', 'AdsBot-Google-Mobile']; + $botList[] = ['AdsBot-Google', 'AdsBot-Google']; + $botList[] = ['Mediapartners-Google', 'Google AdSense']; + $botList[] = ['Google-Safety', 'Google-Safety']; + $botList[] = ['Googlebot', 'Googlebot']; + $botList[] = ['Google-Read-Aloud', 'Google-Read-Aloud']; + $botList[] = ['Google-Site-Verification', 'Google-Site-Verification']; + $botList[] = ['AdIdxBot', 'AdIdxBot']; + $botList[] = ['NewRelic', 'NewRelic']; + $botList[] = ['Detectify', 'Detectify']; + $botList[] = ['UptimeRobot', 'UptimeRobot']; + $botList[] = ['SendGrid', 'SendGrid']; + $botList[] = ['Applebot', 'Applebot']; + $botList[] = ['PinterestBot', 'PinterestBot']; + $botList[] = ['Pingdom', 'Pingdom']; + $botList[] = ['Barkrowler', 'Barkrowler']; + $botList[] = ['SEMrush', 'SEMrush']; + $botList[] = ['GPTBot', 'GPTBot']; + $botList[] = ['ChatGPT-User', 'ChatGPT-User']; + $botList[] = ['Bytespider', 'Bytespider']; + $botList[] = ['CCBot', 'CCBot']; + $botList[] = ['FacebookBot', 'FacebookBot']; + $botList[] = ['Google-Extended', 'Google-Extended']; + $botList[] = ['Site24x7', 'Site24x7']; + $botList[] = ['Stripe', 'Stripe']; + $botList[] = ['Slackbot', 'Slackbot']; + $botList[] = ['Proximic', 'Proximic']; + $botList[] = ['okhttp', 'okhttp']; + $botList[] = ['Python', 'Python']; + $botList[] = ['SemrushBot', 'SemrushBot']; + $botList[] = ['Chrome-Lighthouse', 'Chrome-Lighthouse']; + $botList[] = ['Axios', 'Axios']; + $botList[] = ['PetalBot', 'PetalBot']; + $botList[] = ['CriteoBot', 'CriteoBot']; + $botList[] = ['Baidu', 'Baidu']; + $botList[] = ['ContentKing', 'ContentKing']; + $botList[] = ['IAS crawler', 'IAS crawler']; + $botList[] = ['Sucuri', 'Sucuri']; + $botList[] = ['Seekport', 'Seekport']; + $botList[] = ['Sogou', 'Sogou']; + $botList[] = ['YahooMailProxy', 'YahooMailProxy']; return $botList; } @@ -351,24 +481,6 @@ public static function insertDefaultBots($idsite = 0) return $i; } - public function deleteBot($botId) - { - Piwik::checkUserHasSuperUserAccess(); - try { - $db = self::getDb(); - $query = $db->query( - "DELETE FROM `" . - Common::prefixTable('bot_db') . - "` WHERE `botId` = ?", - [$botId] - ); - return true; - } catch (\Exception $e) { - throw $e; - return false; - } - } - public static function getBotByName($idSite, $botName) { Piwik::checkUserHasSomeViewAccess(); @@ -382,92 +494,8 @@ public static function getBotByName($idSite, $botName) return $rows; } - private static function convertBotLastVisitToLocalTime($rows, $idSite) - { - // convert lastVisit to localtime - $timezone = Site::getTimezoneFor($idSite); - - try { - foreach ($rows as &$row) { - if ($row['botLastVisit'] == '0000-00-00 00:00:00') { - $row['botLastVisit'] = " - "; - } elseif ($row['botLastVisit'] == '2000-01-01 00:00:00') { - $row['botLastVisit'] = " - "; - } else { - $botLastVisit = Date::adjustForTimezone(strtotime($row['botLastVisit']), $timezone); - $row['botLastVisit'] = date('Y-m-d H:i:s', $botLastVisit); - } - } - } catch (\Exception $e) { - throw $e; - return false; - } - return $rows; - } - private static function htmlentities2utf8($string) - { - $output = preg_replace_callback("/(&#[0-9]+;)/", function ($m) { - return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); - }, $string); - return html_entity_decode($output); - } - - /** - * Get Data for the Report "Top10" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getTop10($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getAllBotDataPie($idSite); - } /** - * Get Data for the Report "BotTracker" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getBotTracker($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getAllBotData($idSite); - } - - /** - * Get Data for the Report "BotTrackerReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getBotTrackerReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getBotTrackerReportDataTable($idSite, $period, $date, $segment = false); - } - - - /** - * Get Data for the Report "BotStatsReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getOtherBots($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getOtherBotsDataTable($idSite, $period, $date, $segment = false); - } - - /** - * @return DataTable + * @return \Piwik\DataTable */ public static function getOtherBotsDataTable($idSite, $period, $date, $segment) { @@ -488,28 +516,14 @@ public static function getOtherBotsData($idSite, $period, $date, $segment) "SELECT useragent, COUNT(*) as total FROM " . Common::prefixTable('bot_device_detector_bots') . " WHERE idSite= ? AND date(date) between ? AND ? GROUP BY `useragent` ORDER BY `useragent`", - [$idSite, $startDate, $endDate ] + [$idSite, $startDate, $endDate] ); // // @todo: convert visit_timestamp to site return $rows; } - /** - * Get Data for the Report "BotStatsReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getStatsReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getStatsReportDataTable($idSite, $period, $date, $segment = false); - } - - /** - * @return DataTable + * @return \Piwik\DataTable */ public static function getStatsReportDataTable($idSite, $period, $date, $segment) { @@ -530,7 +544,7 @@ public static function getStatsReportData($idSite, $period, $date, $segment) "SELECT * FROM " . Common::prefixTable('bot_db_stat') . " WHERE idSite= ? AND date(visit_timestamp) between ? AND ? ORDER BY `botId`", - [$idSite, $startDate, $endDate ] + [$idSite, $startDate, $endDate] ); foreach ($rows as &$row) { $name = self::getDb()->fetchRow( @@ -545,55 +559,6 @@ public static function getStatsReportData($idSite, $period, $date, $segment) return $rows; } - /** - * Get Data for the Report "BotTrackerReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getBotTrackerTopTenReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getBotTrackerTopTenReportPieDataTable($idSite, $period, $date, $segment = false); - } - - /** - * Get Data for Dashboard-Widget - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getBotTrackerAnzeige($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getActiveBotData($idSite); - } - - public function getBotTypes() - { - Piwik::checkUserHasSomeViewAccess(); - $db = self::getDb(); - $rows = $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); - return $rows; - } - public function addBotType($type) - { - Piwik::checkUserHasSuperUserAccess(); - try { - $db = self::getDb(); - $sql = sprintf( - 'INSERT INTO ' . Common::prefixTable('bot_type') . ' (`name`) VALUES (?)' - ); - $db->query($sql, [$type]); - } catch (\Exception $e) { - throw $e; - } - } - public static function getDateRangeForPeriod($date, $period, $lastN = false) { $lastN = false; @@ -612,7 +577,8 @@ public static function getDateRangeForPeriod($date, $period, $lastN = false) $oPeriod = Period\Factory::build($period, Date::factory($date)); $startDate = $oPeriod->getDateStart(); $endDate = $oPeriod->getDateEnd(); - } else { // if the range includes the last N periods or is a multiple period + } else { + // if the range includes the last N periods or is a multiple period if (!$isMultiplePeriod) { list($date, $lastN) = Evolution::getDateRangeAndLastN($period, $date, $lastN); } @@ -623,4 +589,49 @@ public static function getDateRangeForPeriod($date, $period, $lastN = false) } return [$startDate, $endDate]; } + + private static function getDb() + { + return Db::get(); + } + + /** + * @return \Piwik\DataTable + */ + private static function getDataTable($rows) + { + return DataTable::makeFromIndexedArray($rows); + } + + private static function convertBotLastVisitToLocalTime($rows, $idSite) + { + // convert lastVisit to localtime + $timezone = Site::getTimezoneFor($idSite); + + try { + foreach ($rows as &$row) { + if ($row['botLastVisit'] == '0000-00-00 00:00:00') { + $row['botLastVisit'] = " - "; + } elseif ($row['botLastVisit'] == '2000-01-01 00:00:00') { + $row['botLastVisit'] = " - "; + } else { + $botLastVisit = Date::adjustForTimezone(strtotime($row['botLastVisit']), $timezone); + $row['botLastVisit'] = date('Y-m-d H:i:s', $botLastVisit); + } + } + } catch (\Exception $e) { + throw $e; + return false; + } + return $rows; + } + + private static function htmlentities2utf8($string) + { + $output = preg_replace_callback("/(&#[0-9]+;)/", function ($m) { + return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); + }, $string); + return html_entity_decode($output); + } + } diff --git a/BotTracker.php b/BotTracker.php index 39a6a1b..1f02aee 100644 --- a/BotTracker.php +++ b/BotTracker.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -13,24 +14,19 @@ use Piwik\Config; use Piwik\Container\StaticContainer; use Piwik\Db; +use Piwik\DeviceDetector\DeviceDetectorFactory; +use Piwik\Plugins\BotTracker\API as BotTrackerAPI; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Tracker; -use Piwik\Plugins\BotTracker\API as BotTrackerAPI; -use Piwik\DeviceDetector\DeviceDetectorFactory; class BotTracker extends \Piwik\Plugin { - private function getDb() - { - return Db::get(); - } public function install() { $tableExists = false; $db = $this->getDb(); - // create new table "bot_db" $query = "CREATE TABLE `" . Common::prefixTable('bot_db') . "` (`botId` INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT, `idsite` INTEGER(10) UNSIGNED NOT NULL, @@ -57,7 +53,6 @@ public function install() BotTrackerAPI::insertDefaultBots($site['idsite']); } } - // Create bot_db_stat table. $query2 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_db_stat') . '` ( `visitId` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, @@ -75,7 +70,6 @@ public function install() throw $e; } - // Create bot_type table $query3 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_type') . '` ( `id` INT(11) NOT NULL AUTO_INCREMENT, @@ -260,7 +254,7 @@ public function checkBot(&$exclude, $request) $query = "INSERT INTO `" . Common::prefixTable('bot_db_stat') . "` (idsite, botid, page, visit_timestamp, useragent) VALUES (?,?,?,?,?)"; // max length of useragent can be 256 Bytes - $params = [$idSite,$botId,$currentUrl,$currentTimestamp,substr($userAgent, 0, 256)]; + $params = [$idSite, $botId, $currentUrl, $currentTimestamp, substr($userAgent, 0, 256)]; $db->query($query, $params); } } else { @@ -288,4 +282,10 @@ public function checkBot(&$exclude, $request) } } } + + private function getDb() + { + return Db::get(); + } + } diff --git a/Commands/AddBot.php b/Commands/AddBot.php index 1479822..0dca19f 100644 --- a/Commands/AddBot.php +++ b/Commands/AddBot.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -10,14 +11,15 @@ namespace Piwik\Plugins\BotTracker\Commands; use Piwik\Plugin\ConsoleCommand; -use Symfony\Component\Console\Input\InputOption; use Piwik\Plugins\BotTracker\API; +use Symfony\Component\Console\Input\InputOption; /** * Add new bot. */ class AddBot extends ConsoleCommand { + protected function configure() { $HelpText = 'The %command.name% command will add a new bot. @@ -83,4 +85,5 @@ protected function doExecute(): int $output->write("New bot added, $name\n"); return self::SUCCESS; } + } diff --git a/Commands/AddBotType.php b/Commands/AddBotType.php index 1251337..855cffc 100644 --- a/Commands/AddBotType.php +++ b/Commands/AddBotType.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -10,14 +11,15 @@ namespace Piwik\Plugins\BotTracker\Commands; use Piwik\Plugin\ConsoleCommand; -use Symfony\Component\Console\Input\InputOption; use Piwik\Plugins\BotTracker\API; +use Symfony\Component\Console\Input\InputOption; /** * Add new bot type. */ class AddBotType extends ConsoleCommand { + protected function configure() { $HelpText = 'The %command.name% command will add a new bot type. @@ -60,4 +62,5 @@ protected function doExecute(): int return self::FAILURE; } } + } diff --git a/Commands/AddDefaultBots.php b/Commands/AddDefaultBots.php index 50111ee..fdbc171 100644 --- a/Commands/AddDefaultBots.php +++ b/Commands/AddDefaultBots.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -10,14 +11,15 @@ namespace Piwik\Plugins\BotTracker\Commands; use Piwik\Plugin\ConsoleCommand; -use Symfony\Component\Console\Input\InputOption; use Piwik\Plugins\BotTracker\API; +use Symfony\Component\Console\Input\InputOption; /** * Add default bots. */ class AddDefaultBots extends ConsoleCommand { + protected function configure() { $HelpText = 'The %command.name% will add the default bots included. @@ -35,7 +37,7 @@ protected function configure() InputOption::VALUE_OPTIONAL, 'SiteId', null - ) + ), ] ); } @@ -60,4 +62,5 @@ protected function doExecute(): int return self::FAILURE; } } + } diff --git a/Commands/DeleteBot.php b/Commands/DeleteBot.php index 1eee9bc..a94246b 100644 --- a/Commands/DeleteBot.php +++ b/Commands/DeleteBot.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -10,14 +11,15 @@ namespace Piwik\Plugins\BotTracker\Commands; use Piwik\Plugin\ConsoleCommand; -use Symfony\Component\Console\Input\InputOption; use Piwik\Plugins\BotTracker\API; +use Symfony\Component\Console\Input\InputOption; /** * Add new bot. */ class DeleteBot extends ConsoleCommand { + protected function configure() { $HelpText = 'The %command.name% command will add a new bot. @@ -35,7 +37,7 @@ protected function configure() InputOption::VALUE_REQUIRED, 'Id of bot', null - ) + ), ] ); } @@ -59,4 +61,5 @@ protected function doExecute(): int $output->write("Bot with id $botId deleted.\n"); return self::SUCCESS; } + } diff --git a/Commands/ListBotTypes.php b/Commands/ListBotTypes.php index 0fc72e4..6b009de 100644 --- a/Commands/ListBotTypes.php +++ b/Commands/ListBotTypes.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -17,6 +18,7 @@ */ class ListBotTypes extends ConsoleCommand { + protected function configure() { $HelpText = 'The %command.name% will add the default bots included. @@ -50,4 +52,5 @@ protected function doExecute(): int } return self::SUCCESS; } + } diff --git a/Commands/ListBots.php b/Commands/ListBots.php index 68a1c21..311e32b 100644 --- a/Commands/ListBots.php +++ b/Commands/ListBots.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -10,14 +11,15 @@ namespace Piwik\Plugins\BotTracker\Commands; use Piwik\Plugin\ConsoleCommand; -use Symfony\Component\Console\Input\InputOption; use Piwik\Plugins\BotTracker\API; +use Symfony\Component\Console\Input\InputOption; /** * Add new bot. */ class ListBots extends ConsoleCommand { + protected function configure() { $HelpText = 'The %command.name% command will list bots for site id. @@ -35,7 +37,7 @@ protected function configure() InputOption::VALUE_REQUIRED, 'SiteId', null - ) + ), ] ); } @@ -69,4 +71,5 @@ protected function doExecute(): int } return self::SUCCESS; } + } diff --git a/Controller.php b/Controller.php index 2f041cc..d10640d 100644 --- a/Controller.php +++ b/Controller.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -12,14 +13,15 @@ use Piwik\Nonce; use Piwik\Notification\Manager as NotificationManager; use Piwik\Piwik; -use Piwik\View; -use Piwik\Plugins\SitesManager\API as APISitesManager; +use Piwik\Plugin\ControllerAdmin; use Piwik\Plugins\BotTracker\API as APIBotTracker; +use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Request; -use Piwik\Plugin\ControllerAdmin; +use Piwik\View; class Controller extends ControllerAdmin { + public string $nonce; /** * @property string $nonce @@ -55,7 +57,7 @@ public function docs() Piwik::checkUserHasSomeViewAccess(); $info = "Bot Tracker Docs"; return $this->renderTemplate('docs', array( - 'info' => $info + 'info' => $info, )); } @@ -147,7 +149,6 @@ public function saveConfig() } } - public function addNew() { try { @@ -222,4 +223,5 @@ public function configInsertDb() echo $e; } } + } diff --git a/Menu.php b/Menu.php index 66dcd86..6052800 100644 --- a/Menu.php +++ b/Menu.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -19,6 +20,7 @@ */ class Menu extends \Piwik\Plugin\Menu { + public function configureAdminMenu(MenuAdmin $menu) { if (Piwik::isUserHasSomeAdminAccess()) { @@ -28,4 +30,5 @@ public function configureAdminMenu(MenuAdmin $menu) $menu->addItem('BotTracker', 'BotTracker_Documentation', $this->urlForAction('docs'), $order = 52); } } + } diff --git a/Reports/Base.php b/Reports/Base.php index a845231..10ea313 100644 --- a/Reports/Base.php +++ b/Reports/Base.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -13,8 +14,10 @@ abstract class Base extends Report { + protected function init() { $this->categoryId = 'General_Visitors'; } + } diff --git a/Reports/GetBotTracker.php b/Reports/GetBotTracker.php index 22063ad..3e39976 100644 --- a/Reports/GetBotTracker.php +++ b/Reports/GetBotTracker.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @deprecated since release 5.2.0 @@ -12,28 +13,21 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Widget\WidgetsList; use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; /** * Defines the GetBotTracker report. * * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * * @deprecated since v5.2.0, will be removed in v5.3.0 */ class GetBotTracker extends Base { - protected function init() - { - parent::init(); - - $this->name = Piwik::translate('BotTracker_Bot_Tracker_Total_Over_Time_Deprecated_Report'); - $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); - $this->order = 99; - } /** - * @param ViewDataTable $view + * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -42,7 +36,7 @@ public function configureView(ViewDataTable $view) $view->config->translations['botKeyword'] = Piwik::translate('BotTracker_BotKeyword'); $view->config->translations['botCount'] = Piwik::translate('BotTracker_BotCount'); $view->config->translations['botLastVisit'] = Piwik::translate('BotTracker_BotLastVisit'); - $view->config->columns_to_display = ['botName','botCount','botLastVisit']; + $view->config->columns_to_display = ['botName', 'botCount', 'botLastVisit']; $view->config->show_search = false; $view->config->show_footer_icons = false; $view->config->show_exclude_low_population = false; @@ -75,4 +69,14 @@ public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $ $factory->createWidget()->setIsNotWidgetizable() ); } + + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('BotTracker_Bot_Tracker_Total_Over_Time_Deprecated_Report'); + $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); + $this->order = 99; + } + } diff --git a/Reports/GetBotTrackerAnzeige.php b/Reports/GetBotTrackerAnzeige.php index b159064..50e0e7b 100644 --- a/Reports/GetBotTrackerAnzeige.php +++ b/Reports/GetBotTrackerAnzeige.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @deprecated since release 5.2.0 @@ -12,28 +13,21 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Widget\WidgetsList; use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; /** * Defines the GetBotTrackerAnzeige report. * * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * * @deprecated since v5.2.0, will be removed in v5.3.0 */ class GetBotTrackerAnzeige extends Base { - protected function init() - { - parent::init(); - - $this->name = Piwik::translate('BotTracker_DisplayWidget_Deprecated_Report'); - $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); - $this->order = 99; - } /** - * @param ViewDataTable $view + * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -51,7 +45,7 @@ public function configureView(ViewDataTable $view) $view->config->show_table_performance = false; $view->config->show_all_views_icons = false; $view->config->show_export = false; - $view->config->columns_to_display = ["botName","botCount","botLastVisit"]; + $view->config->columns_to_display = ["botName", "botCount", "botLastVisit"]; $view->requestConfig->filter_sort_column = 'botCount'; $view->requestConfig->filter_sort_order = 'desc'; $view->requestConfig->filter_limit = 10; @@ -69,4 +63,14 @@ public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $ { $widgetsList->addWidgetConfig($factory->createWidget()); } + + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('BotTracker_DisplayWidget_Deprecated_Report'); + $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); + $this->order = 99; + } + } diff --git a/Reports/GetBotTrackerReport.php b/Reports/GetBotTrackerReport.php index 606c9f3..62b9e58 100644 --- a/Reports/GetBotTrackerReport.php +++ b/Reports/GetBotTrackerReport.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -11,8 +12,8 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Widget\WidgetsList; use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; /** * Defines the GetBotTrackerReport report. @@ -20,25 +21,16 @@ */ class GetBotTrackerReport extends Base { - protected function init() - { - parent::init(); - - $this->name = Piwik::translate('BotTracker_Bot_Tracker_Report'); - $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); - $this->documentation = Piwik::translate('BotTracker_ReportDocumentation'); - $this->order = 98; - } /** - * @param ViewDataTable $view + * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { $view->config->translations['botId'] = Piwik::translate('BotTracker_BotId'); $view->config->translations['botName'] = Piwik::translate('BotTracker_BotName'); $view->config->translations['total'] = Piwik::translate('BotTracker_BotCount'); - $view->config->columns_to_display = ['botName','total']; + $view->config->columns_to_display = ['botName', 'total']; $view->config->show_search = false; $view->config->show_footer_icons = false; $view->config->show_exclude_low_population = false; @@ -68,4 +60,15 @@ public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $ $config->setOrder(1); $widgetsList->addWidgetConfig($config); } + + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('BotTracker_Bot_Tracker_Report'); + $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); + $this->documentation = Piwik::translate('BotTracker_ReportDocumentation'); + $this->order = 98; + } + } diff --git a/Reports/GetBotTrackerTopTenReport.php b/Reports/GetBotTrackerTopTenReport.php index b74bc47..858e167 100644 --- a/Reports/GetBotTrackerTopTenReport.php +++ b/Reports/GetBotTrackerTopTenReport.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -11,8 +12,8 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Widget\WidgetsList; use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; /** * Defines the class GetBotTrackerTopTenReport report. @@ -20,22 +21,12 @@ */ class GetBotTrackerTopTenReport extends Base { - protected function init() - { - parent::init(); - - $this->name = Piwik::translate('BotTracker_Top_10_Bots'); - $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); - $this->documentation = Piwik::translate('BotTracker_TopTenDocumentation'); - // This defines in which order your report appears in the mobile app, in the menu and in the list of widgets - $this->order = 98; - } /** * Here you can configure how your report should be displayed. For instance whether your report supports a search * etc. You can also change the default request config. For instance change how many rows are displayed by default. * - * @param ViewDataTable $view + * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -58,11 +49,11 @@ public function getRelatedReports() return []; } - public function getDefaultTypeViewDataTable() { return 'graphPie'; } + public function alwaysUseDefaultViewDataTable() { return true; @@ -74,4 +65,16 @@ public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $ $config->setOrder(2); $widgetsList->addWidgetConfig($config); } + + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('BotTracker_Top_10_Bots'); + $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); + $this->documentation = Piwik::translate('BotTracker_TopTenDocumentation'); + // This defines in which order your report appears in the mobile app, in the menu and in the list of widgets + $this->order = 98; + } + } diff --git a/Reports/GetOtherBots.php b/Reports/GetOtherBots.php index 2c2c5b8..b4fe52d 100644 --- a/Reports/GetOtherBots.php +++ b/Reports/GetOtherBots.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -11,8 +12,8 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Widget\WidgetsList; use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; /** * Defines the GetBotStatsReport report. @@ -20,18 +21,9 @@ */ class GetOtherBots extends Base { - protected function init() - { - parent::init(); - - $this->name = Piwik::translate('BotTracker_Bot_Tracker_OtherBots'); - $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); - $this->documentation = Piwik::translate('BotTracker_Bot_Tracker_OtherBotsDocumentation'); - $this->order = 98; - } /** - * @param ViewDataTable $view + * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -67,4 +59,15 @@ public function isEnabled() { return true; } + + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('BotTracker_Bot_Tracker_OtherBots'); + $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); + $this->documentation = Piwik::translate('BotTracker_Bot_Tracker_OtherBotsDocumentation'); + $this->order = 98; + } + } diff --git a/Reports/GetStatsReport.php b/Reports/GetStatsReport.php index bb161bc..bee09f0 100644 --- a/Reports/GetStatsReport.php +++ b/Reports/GetStatsReport.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ @@ -11,8 +12,8 @@ use Piwik\Piwik; use Piwik\Plugin\ViewDataTable; -use Piwik\Widget\WidgetsList; use Piwik\Report\ReportWidgetFactory; +use Piwik\Widget\WidgetsList; /** * Defines the GetBotStatsReport report. @@ -20,18 +21,9 @@ */ class GetStatsReport extends Base { - protected function init() - { - parent::init(); - - $this->name = Piwik::translate('BotTracker_Bot_Tracker_Report_Stats'); - $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); - $this->documentation = Piwik::translate('BotTracker_ReportDocumentation'); - $this->order = 98; - } /** - * @param ViewDataTable $view + * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -69,4 +61,15 @@ public function isEnabled() // @todo: Add check if there is any data in db_stats table, do not show if there is none. return true; } + + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('BotTracker_Bot_Tracker_Report_Stats'); + $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); + $this->documentation = Piwik::translate('BotTracker_ReportDocumentation'); + $this->order = 98; + } + } diff --git a/Reports/GetTop10.php b/Reports/GetTop10.php index dcaa817..78a9e85 100644 --- a/Reports/GetTop10.php +++ b/Reports/GetTop10.php @@ -3,6 +3,7 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * @deprecated since v5.2.0, will be removed in v5.3.0 @@ -20,18 +21,9 @@ */ class GetTop10 extends Base { - protected function init() - { - parent::init(); - - $this->name = Piwik::translate('BotTracker_Top_10_Bots_Deprecated_Report'); - $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); - // This defines in which order your report appears in the mobile app, in the menu and in the list of widgets - $this->order = 99; - } /** - * @param ViewDataTable $view + * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -55,8 +47,20 @@ public function getDefaultTypeViewDataTable() { return 'graphPie'; } + public function alwaysUseDefaultViewDataTable() { return true; } + + protected function init() + { + parent::init(); + + $this->name = Piwik::translate('BotTracker_Top_10_Bots_Deprecated_Report'); + $this->subcategoryId = Piwik::translate('BotTracker_BotTracker'); + // This defines in which order your report appears in the mobile app, in the menu and in the list of widgets + $this->order = 99; + } + } diff --git a/SystemSettings.php b/SystemSettings.php index 5c802e7..f96a3f6 100644 --- a/SystemSettings.php +++ b/SystemSettings.php @@ -3,13 +3,13 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ namespace Piwik\Plugins\BotTracker; -use Piwik\Settings\Setting; use Piwik\Settings\FieldConfig; /** @@ -17,7 +17,10 @@ */ class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings { - /** @var Setting */ + + /** + * @var \Piwik\Settings\Setting + */ public $trackDeviceDetectorBots; protected function init() @@ -25,9 +28,8 @@ protected function init() $this->trackDeviceDetectorBots = $this->trackDeviceDetectorBots(); } - /** - * @return Setting + * @return \Piwik\Settings\Setting */ private function trackDeviceDetectorBots() { @@ -43,4 +45,5 @@ function (FieldConfig $field) { } ); } + } diff --git a/TESTS.md b/TESTS.md index 0498243..d66859a 100644 --- a/TESTS.md +++ b/TESTS.md @@ -45,7 +45,7 @@ Set up test environment: ```bash ./console development:enable -./console config:set --section=tests --key=http_host --value=web +./console config:set --section=tests --key=http_host --value=matomo.loc ./console config:set --section=tests --key=request_uri --value=/ ./console config:set --section=database_tests --key=host --value=db ./console config:set --section=database_tests --key=username --value=root diff --git a/Widgets/GetDigiInfo.php b/Widgets/GetDigiInfo.php index f06cd2e..772b97c 100644 --- a/Widgets/GetDigiInfo.php +++ b/Widgets/GetDigiInfo.php @@ -5,28 +5,9 @@ use Piwik\Piwik; use Piwik\Widget\Widget; use Piwik\Widget\WidgetConfig; -use Piwik\Translation\Translator; class GetDigiInfo extends Widget { - /** - * @var Translator - */ - private $translator; - - public function __construct(Translator $translator) - { - $this->translator = $translator; - } - - public static function configure(WidgetConfig $config) - { - $config->setCategoryId('General_Visitors'); - $config->setSubcategoryId(Piwik::translate('BotTracker_BotTracker')); - $config->setIsWide(); - $config->setOrder(0); - $config->setIsNotWidgetizable(); - } public function render() { @@ -48,4 +29,14 @@ public function render() '; } + + public static function configure(WidgetConfig $config) + { + $config->setCategoryId('General_Visitors'); + $config->setSubcategoryId(Piwik::translate('BotTracker_BotTracker')); + $config->setIsWide(); + $config->setOrder(0); + $config->setIsNotWidgetizable(); + } + } diff --git a/composer.json b/composer.json index 725573b..09f013c 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,11 @@ "php-webdriver/webdriver": "^1.15", "squizlabs/php_codesniffer": "^3.7", "phpstan/phpstan": "^1.10.62", - "slevomat/coding-standard": "^8.8", + "slevomat/coding-standard": "^8.15", "spaze/phpstan-disallowed-calls": "^2.12", "psr/container": "1.1.2", - "phpstan/phpstan-deprecation-rules": "^1.1" + "phpstan/phpstan-deprecation-rules": "^1.1", + "sirbrillig/phpcs-import-detection": "^1.3" }, "config": { "allow-plugins": { diff --git a/tests/phpunit.xml b/tests/phpunit.xml index d92adfe..374b7fe 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -4,6 +4,7 @@ ../Commands/ ../Reports/ + ../Widgets/ From 8170d0e11c39952d246faca541c604a32776e04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikke=20Schir=C3=A9n?= Date: Sun, 7 Apr 2024 01:09:28 +0200 Subject: [PATCH 2/6] more coding standards and update phpcs test --- .github/workflows/phpcs.yaml | 3 +-- API.php | 28 +++++++++++---------------- BotTracker.php | 26 +++++++++++++------------ Controller.php | 11 ++++++----- Menu.php | 3 ++- Reports/GetBotTracker.php | 3 +-- Reports/GetBotTrackerAnzeige.php | 3 +-- Reports/GetBotTrackerReport.php | 3 +-- Reports/GetBotTrackerTopTenReport.php | 4 +--- Reports/GetOtherBots.php | 1 - Reports/GetStatsReport.php | 1 - Reports/GetTop10.php | 3 +-- SystemSettings.php | 9 ++++----- Widgets/GetDigiInfo.php | 2 +- 14 files changed, 44 insertions(+), 56 deletions(-) diff --git a/.github/workflows/phpcs.yaml b/.github/workflows/phpcs.yaml index 7e8ba9b..881ad94 100644 --- a/.github/workflows/phpcs.yaml +++ b/.github/workflows/phpcs.yaml @@ -32,5 +32,4 @@ jobs: php-version: '8.1' tools: cs2pr - name: Run phpcs - run: ./vendor/bin/phpcs . --standard=PSR12 -q --report=checkstyle --ignore=*/vendor/*,Updates/*,tests/* | cs2pr - + run: ./vendor/bin/phpcs . --standard=tests/ruleset.xml -q --report=checkstyle --ignore=*/vendor/*,Updates/*,tests/* | cs2pr diff --git a/API.php b/API.php index 095bf92..cdc151f 100644 --- a/API.php +++ b/API.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\BotTracker; +use Exception; use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\DataTable; @@ -40,7 +41,7 @@ public function deleteBot($botId) [$botId] ); return true; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; return false; } @@ -152,8 +153,7 @@ public function getBotTypes() { Piwik::checkUserHasSomeViewAccess(); $db = self::getDb(); - $rows = $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); - return $rows; + return $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); } public function addBotType($type) @@ -165,7 +165,7 @@ public function addBotType($type) 'INSERT INTO ' . Common::prefixTable('bot_type') . ' (`name`) VALUES (?)' ); $db->query($sql, [$type]); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -179,10 +179,10 @@ public static function getInstance() try { $instance = StaticContainer::get('BotTracker_API'); if (!($instance instanceof API)) { - throw new \Exception('BotTracker_API must inherit API'); + throw new Exception('BotTracker_API must inherit API'); } self::$instance = $instance; - } catch (\Exception $e) { + } catch (Exception $e) { self::$instance = StaticContainer::get('Piwik\Plugins\BotTracker\API'); StaticContainer::getContainer()->set('BotTracker_API', self::$instance); } @@ -294,15 +294,13 @@ public static function getBotTrackerTopTenReportPieData($idSite, $period, $date, // Remove zero results, and limit to ten. $pie = array_diff($pie, [0]); arsort($pie); - $rows = array_slice($pie, 0, 10); - - return $rows; + return array_slice($pie, 0, 10); } public static function getAllBotDataForConfig($idsite) { Piwik::checkUserHasSomeViewAccess(); - $rows = self::getDb()->fetchAll( + return self::getDb()->fetchAll( "SELECT `idsite`, `botId`, `botName`, `botActive`, `botKeyword`, `extra_stats`, @@ -311,8 +309,6 @@ public static function getAllBotDataForConfig($idsite) " WHERE `idsite` = ? ORDER BY `botId`", [$idsite] ); - - return $rows; } public static function getActiveBotData($idSite) @@ -394,7 +390,7 @@ public static function insertBot($idSite, $botName, $botActive, $botKeyword, $ex $botType] ); return true; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; return false; } @@ -512,14 +508,12 @@ public static function getOtherBotsData($idSite, $period, $date, $segment) list($startDate, $endDate) = self::getDateRangeForPeriod($date, $period, false); $startDate = $startDate->toString(); $endDate = $endDate->toString(); - $rows = self::getDb()->fetchAll( + return self::getDb()->fetchAll( "SELECT useragent, COUNT(*) as total FROM " . Common::prefixTable('bot_device_detector_bots') . " WHERE idSite= ? AND date(date) between ? AND ? GROUP BY `useragent` ORDER BY `useragent`", [$idSite, $startDate, $endDate] ); - // // @todo: convert visit_timestamp to site - return $rows; } /** @@ -619,7 +613,7 @@ private static function convertBotLastVisitToLocalTime($rows, $idSite) $row['botLastVisit'] = date('Y-m-d H:i:s', $botLastVisit); } } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; return false; } diff --git a/BotTracker.php b/BotTracker.php index 1f02aee..512d2f8 100644 --- a/BotTracker.php +++ b/BotTracker.php @@ -10,16 +10,18 @@ namespace Piwik\Plugins\BotTracker; +use Exception; use Piwik\Common; use Piwik\Config; use Piwik\Container\StaticContainer; use Piwik\Db; use Piwik\DeviceDetector\DeviceDetectorFactory; +use Piwik\Plugin; use Piwik\Plugins\BotTracker\API as BotTrackerAPI; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Tracker; -class BotTracker extends \Piwik\Plugin +class BotTracker extends Plugin { public function install() @@ -43,7 +45,7 @@ public function install() // if the table already exist do not throw error. Could be installed twice... try { $db->exec($query); - } catch (\Exception $e) { + } catch (Exception $e) { $tableExists = true; } @@ -53,7 +55,7 @@ public function install() BotTrackerAPI::insertDefaultBots($site['idsite']); } } - $query2 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_db_stat') . '` + $query2 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_db_stat') . '` ( `visitId` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `botId` INTEGER(10) UNSIGNED NOT NULL, @@ -66,11 +68,11 @@ public function install() ) DEFAULT CHARSET=utf8'; try { $db->exec($query2); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } - $query3 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_type') . '` + $query3 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_type') . '` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(256) NOT NULL, @@ -79,7 +81,7 @@ public function install() ) DEFAULT CHARSET=utf8'; try { $db->exec($query3); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } @@ -105,11 +107,11 @@ public function install() ); $db->query($sql, [$type]); } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } - $query4 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_visits') . '` + $query4 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_visits') . '` ( `id` BIGINT UNSIGNED AUTO_INCREMENT, `botId` INT UNSIGNED, @@ -119,11 +121,11 @@ public function install() ) DEFAULT CHARSET=utf8'; try { $db->exec($query4); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } - $query5 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_device_detector_bots') . '` + $query5 = 'CREATE TABLE IF NOT EXISTS `' . Common::prefixTable('bot_device_detector_bots') . '` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `idsite` INT UNSIGNED, @@ -133,7 +135,7 @@ public function install() ) DEFAULT CHARSET=utf8'; try { $db->exec($query5); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -156,7 +158,7 @@ public function uninstall() public function registerEvents() { return [ - 'Tracker.isExcludedVisit' => 'checkBot', + 'Tracker.isExcludedVisit' => 'checkBot', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', ]; } diff --git a/Controller.php b/Controller.php index d10640d..b9b4168 100644 --- a/Controller.php +++ b/Controller.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\BotTracker; +use Exception; use Piwik\Nonce; use Piwik\Notification\Manager as NotificationManager; use Piwik\Piwik; @@ -144,7 +145,7 @@ public function saveConfig() } } $this->index($siteID, $errorList); - } catch (\Exception $e) { + } catch (Exception $e) { echo $e; } } @@ -166,7 +167,7 @@ public function addNew() $botActive = trim(Request::fromRequest()->getStringParameter('new_botActive', '0')); $extraStats = trim(Request::fromRequest()->getStringParameter('new_extraStats', '0')); if ( - $botName != '' || + $botName != '' || $botKeyword != '' ) { if (empty($botName)) { @@ -182,7 +183,7 @@ public function addNew() $errorList[] = 'Bot ' . $botName . ' ' . Piwik::translate('BotTracker_Added'); $this->index($siteID, $errorList); - } catch (\Exception $e) { + } catch (Exception $e) { echo $e; } } @@ -202,7 +203,7 @@ public function deleteBotEntry() $errorList[] = 'Bot ' . $botId . ' ' . Piwik::translate('BotTracker_Message_deleted'); $this->index($siteID, $errorList); - } catch (\Exception $e) { + } catch (Exception $e) { echo $e; } } @@ -219,7 +220,7 @@ public function configInsertDb() $errorList[] = $i . " " . Piwik::translate('BotTracker_Message_bot_inserted'); $this->index($siteID, $errorList); - } catch (\Exception $e) { + } catch (Exception $e) { echo $e; } } diff --git a/Menu.php b/Menu.php index 6052800..db27ded 100644 --- a/Menu.php +++ b/Menu.php @@ -12,13 +12,14 @@ use Piwik\Menu\MenuAdmin; use Piwik\Piwik; +use Piwik\Plugin\Menu as MatomoMenu; /** * This class allows you to add, remove or rename menu items. * To configure a menu (such as Admin Menu, Reporting Menu, User Menu...) simply call the corresponding methods as * described in the API-Reference http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract */ -class Menu extends \Piwik\Plugin\Menu +class Menu extends MatomoMenu { public function configureAdminMenu(MenuAdmin $menu) diff --git a/Reports/GetBotTracker.php b/Reports/GetBotTracker.php index 3e39976..921d76d 100644 --- a/Reports/GetBotTracker.php +++ b/Reports/GetBotTracker.php @@ -27,7 +27,6 @@ class GetBotTracker extends Base { /** - * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -42,7 +41,7 @@ public function configureView(ViewDataTable $view) $view->config->show_exclude_low_population = false; $view->config->show_table_all_columns = false; $view->config->show_insights = false; - $view->config->show_related_reports = false; + $view->config->show_related_reports = false; $view->config->show_pivot_by_subtable = false; $view->config->show_table_performance = false; $view->config->show_all_views_icons = false; diff --git a/Reports/GetBotTrackerAnzeige.php b/Reports/GetBotTrackerAnzeige.php index 50e0e7b..ceff65a 100644 --- a/Reports/GetBotTrackerAnzeige.php +++ b/Reports/GetBotTrackerAnzeige.php @@ -27,7 +27,6 @@ class GetBotTrackerAnzeige extends Base { /** - * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -40,7 +39,7 @@ public function configureView(ViewDataTable $view) $view->config->show_exclude_low_population = false; $view->config->show_table_all_columns = false; $view->config->show_insights = false; - $view->config->show_related_reports = false; + $view->config->show_related_reports = false; $view->config->show_pivot_by_subtable = false; $view->config->show_table_performance = false; $view->config->show_all_views_icons = false; diff --git a/Reports/GetBotTrackerReport.php b/Reports/GetBotTrackerReport.php index 62b9e58..362392f 100644 --- a/Reports/GetBotTrackerReport.php +++ b/Reports/GetBotTrackerReport.php @@ -23,7 +23,6 @@ class GetBotTrackerReport extends Base { /** - * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -36,7 +35,7 @@ public function configureView(ViewDataTable $view) $view->config->show_exclude_low_population = false; $view->config->show_table_all_columns = false; $view->config->show_insights = false; - $view->config->show_related_reports = false; + $view->config->show_related_reports = false; $view->config->show_pivot_by_subtable = false; $view->config->show_table_performance = false; $view->config->show_all_views_icons = false; diff --git a/Reports/GetBotTrackerTopTenReport.php b/Reports/GetBotTrackerTopTenReport.php index 858e167..70b55a3 100644 --- a/Reports/GetBotTrackerTopTenReport.php +++ b/Reports/GetBotTrackerTopTenReport.php @@ -25,8 +25,6 @@ class GetBotTrackerTopTenReport extends Base /** * Here you can configure how your report should be displayed. For instance whether your report supports a search * etc. You can also change the default request config. For instance change how many rows are displayed by default. - * - * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -34,7 +32,7 @@ public function configureView(ViewDataTable $view) $view->config->show_footer_icons = true; $view->config->show_insights = false; $view->config->selectable_columns = ["value"]; - $view->config->show_related_reports = false; + $view->config->show_related_reports = false; $view->config->show_table_all_columns = false; } diff --git a/Reports/GetOtherBots.php b/Reports/GetOtherBots.php index b4fe52d..cbe0b8a 100644 --- a/Reports/GetOtherBots.php +++ b/Reports/GetOtherBots.php @@ -23,7 +23,6 @@ class GetOtherBots extends Base { /** - * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { diff --git a/Reports/GetStatsReport.php b/Reports/GetStatsReport.php index bee09f0..df9c842 100644 --- a/Reports/GetStatsReport.php +++ b/Reports/GetStatsReport.php @@ -23,7 +23,6 @@ class GetStatsReport extends Base { /** - * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { diff --git a/Reports/GetTop10.php b/Reports/GetTop10.php index 78a9e85..fb72bfc 100644 --- a/Reports/GetTop10.php +++ b/Reports/GetTop10.php @@ -23,7 +23,6 @@ class GetTop10 extends Base { /** - * @param \Piwik\Plugin\ViewDataTable $view */ public function configureView(ViewDataTable $view) { @@ -31,7 +30,7 @@ public function configureView(ViewDataTable $view) $view->config->show_footer_icons = true; $view->config->show_insights = false; $view->config->selectable_columns = ["value"]; - $view->config->show_related_reports = false; + $view->config->show_related_reports = false; $view->config->show_table_all_columns = false; } diff --git a/SystemSettings.php b/SystemSettings.php index f96a3f6..87ae837 100644 --- a/SystemSettings.php +++ b/SystemSettings.php @@ -11,17 +11,16 @@ namespace Piwik\Plugins\BotTracker; use Piwik\Settings\FieldConfig; +use Piwik\Settings\Plugin\SystemSettings as MatomoSystemSettings; +use Piwik\Settings\Setting; /** * Defines Settings for BotTracker. */ -class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings +class SystemSettings extends MatomoSystemSettings { - /** - * @var \Piwik\Settings\Setting - */ - public $trackDeviceDetectorBots; + public Setting $trackDeviceDetectorBots; protected function init() { diff --git a/Widgets/GetDigiInfo.php b/Widgets/GetDigiInfo.php index 772b97c..be968ff 100644 --- a/Widgets/GetDigiInfo.php +++ b/Widgets/GetDigiInfo.php @@ -18,7 +18,7 @@ public function render()

Bot Tracker

From 217a718dcf3506f0ac61fd129415b7866b5e05ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikke=20Schir=C3=A9n?= Date: Sun, 7 Apr 2024 01:11:31 +0200 Subject: [PATCH 3/6] add missing file --- tests/ruleset.xml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/ruleset.xml diff --git a/tests/ruleset.xml b/tests/ruleset.xml new file mode 100644 index 0000000..da03310 --- /dev/null +++ b/tests/ruleset.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c07ed73748a45bc7145dafa3c2c0ea5b7f45794c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikke=20Schir=C3=A9n?= Date: Mon, 8 Apr 2024 11:45:17 +0200 Subject: [PATCH 4/6] WIP: work needed --- .gitignore | 3 + API.php | 511 +++++++++++++------------- BotTracker.php | 3 + CHANGELOG.md | 2 +- Controller.php | 3 + Menu.php | 4 +- Reports/Base.php | 3 + Reports/GetBotTracker.php | 1 + Reports/GetBotTrackerAnzeige.php | 1 + Reports/GetBotTrackerReport.php | 1 + Reports/GetBotTrackerTopTenReport.php | 1 + Reports/GetOtherBots.php | 1 + Reports/GetStatsReport.php | 1 + Reports/GetTop10.php | 1 + SystemSettings.php | 2 +- Widgets/GetDigiInfo.php | 3 + 16 files changed, 278 insertions(+), 263 deletions(-) diff --git a/.gitignore b/.gitignore index b63e503..d227213 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ vendor tests/.phpunit.result.cache +docs/docs.md +composer.lock +usage diff --git a/API.php b/API.php index cdc151f..df309cf 100644 --- a/API.php +++ b/API.php @@ -3,173 +3,41 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) - * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ namespace Piwik\Plugins\BotTracker; -use Exception; -use Piwik\Common; use Piwik\Container\StaticContainer; +use Piwik\Db; +use Piwik\Common; use Piwik\DataTable; +use Piwik\Site; use Piwik\Date; -use Piwik\Db; -use Piwik\Period; use Piwik\Piwik; +use Piwik\Period; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution; -use Piwik\Site; /** - * @package Piwik_BotTracker + * @package Matomo_BotTracker */ class API extends \Piwik\Plugin\API { - private static $instance = null; - public function deleteBot($botId) - { - Piwik::checkUserHasSuperUserAccess(); - try { - $db = self::getDb(); - $query = $db->query( - "DELETE FROM `" . - Common::prefixTable('bot_db') . - "` WHERE `botId` = ?", - [$botId] - ); - return true; - } catch (Exception $e) { - throw $e; - return false; - } - } - - /** - * Get Data for the Report "Top10" - * - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return \Piwik\DataTable - */ - public function getTop10($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getAllBotDataPie($idSite); - } - - /** - * Get Data for the Report "BotTracker" - * - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return \Piwik\DataTable - */ - public function getBotTracker($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getAllBotData($idSite); - } - - /** - * Get Data for the Report "BotTrackerReport" - * - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getBotTrackerReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getBotTrackerReportDataTable($idSite, $period, $date, $segment = false); - } - - /** - * Get Data for the Report "BotStatsReport" - * - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getOtherBots($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getOtherBotsDataTable($idSite, $period, $date, $segment = false); - } - - /** - * Get Data for the Report "BotStatsReport" - * - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getStatsReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getStatsReportDataTable($idSite, $period, $date, $segment = false); - } - - /** - * Get Data for the Report "BotTrackerReport" - * - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return \Piwik\DataTable - */ - public function getBotTrackerTopTenReport($idSite, $period, $date, $segment = false) + private static function getDb() { - Piwik::checkUserHasSomeViewAccess(); - return $this->getBotTrackerTopTenReportPieDataTable($idSite, $period, $date, $segment = false); + return Db::get(); } /** - * Get Data for Dashboard-Widget - * - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return \Piwik\DataTable + * @return DataTable */ - public function getBotTrackerAnzeige($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getActiveBotData($idSite); - } - - public function getBotTypes() - { - Piwik::checkUserHasSomeViewAccess(); - $db = self::getDb(); - return $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); - } - - public function addBotType($type) + private static function getDataTable($rows) { - Piwik::checkUserHasSuperUserAccess(); - try { - $db = self::getDb(); - $sql = sprintf( - 'INSERT INTO ' . Common::prefixTable('bot_type') . ' (`name`) VALUES (?)' - ); - $db->query($sql, [$type]); - } catch (Exception $e) { - throw $e; - } + return DataTable::makeFromIndexedArray($rows); } - /** * @return \Piwik\Plugins\BotTracker\API * @throws \Exception @@ -179,10 +47,10 @@ public static function getInstance() try { $instance = StaticContainer::get('BotTracker_API'); if (!($instance instanceof API)) { - throw new Exception('BotTracker_API must inherit API'); + throw new \Exception('BotTracker_API must inherit API'); } self::$instance = $instance; - } catch (Exception $e) { + } catch (\Exception $e) { self::$instance = StaticContainer::get('Piwik\Plugins\BotTracker\API'); StaticContainer::getContainer()->set('BotTracker_API', self::$instance); } @@ -204,7 +72,7 @@ public static function getAllBotData($idSite) } /** - * @return \Piwik\DataTable + * @return DataTable */ public static function getBotTrackerReportDataTable($idSite, $period, $date, $segment) { @@ -266,9 +134,9 @@ public static function getBotTrackerTopTenReportPieData($idSite, $period, $date, // For some reason, we are off by one, add an dummy bot in end. // @todo: Look into why this is needed. $dummy = [ - 'botCount' => 0, - 'botId' => 0, 'botName' => 'dummy', + 'botId' => 0, + 'botCount' => 0, ]; array_push($rows, $dummy); // Get totals of a bot number. @@ -294,13 +162,15 @@ public static function getBotTrackerTopTenReportPieData($idSite, $period, $date, // Remove zero results, and limit to ten. $pie = array_diff($pie, [0]); arsort($pie); - return array_slice($pie, 0, 10); + $rows = array_slice($pie, 0, 10); + + return $rows; } public static function getAllBotDataForConfig($idsite) { Piwik::checkUserHasSomeViewAccess(); - return self::getDb()->fetchAll( + $rows = self::getDb()->fetchAll( "SELECT `idsite`, `botId`, `botName`, `botActive`, `botKeyword`, `extra_stats`, @@ -309,8 +179,11 @@ public static function getAllBotDataForConfig($idsite) " WHERE `idsite` = ? ORDER BY `botId`", [$idsite] ); + + return $rows; } + public static function getActiveBotData($idSite) { Piwik::checkUserHasSomeViewAccess(); @@ -390,71 +263,72 @@ public static function insertBot($idSite, $botName, $botActive, $botKeyword, $ex $botType] ); return true; - } catch (Exception $e) { + } catch (\Exception $e) { throw $e; return false; } } + public static function defaultBots() { $botList = []; - $botList[] = ['Amazonbot', 'Amazonbot']; - $botList[] = ['Qualys', 'Qualys']; - $botList[] = ['bingbot', 'bingbot']; - $botList[] = ['YandexBot', 'YandexBot']; - $botList[] = ['AhrefsBot', 'AhrefsBot']; - $botList[] = ['Ahrefs', 'Ahrefs']; - $botList[] = ['Scrapy', 'Scrapy']; - $botList[] = ['Googlebot-Image', 'Google-Image']; - $botList[] = ['Googlebot-News', 'Googlebot-News']; - $botList[] = ['Googlebot-Video', 'Googlebot-Video']; - $botList[] = ['Storebot-Google', 'Storebot-Google']; - $botList[] = ['Google-InspectionTool', 'Google-InspectionTool']; - $botList[] = ['Google-Extended', 'Google-Extended']; - $botList[] = ['GoogleOther', 'GoogleOther']; - $botList[] = ['APIs-Google', 'APIs-Google']; - $botList[] = ['AdsBot-Google-Mobile', 'AdsBot-Google-Mobile']; - $botList[] = ['AdsBot-Google', 'AdsBot-Google']; - $botList[] = ['Mediapartners-Google', 'Google AdSense']; - $botList[] = ['Google-Safety', 'Google-Safety']; - $botList[] = ['Googlebot', 'Googlebot']; - $botList[] = ['Google-Read-Aloud', 'Google-Read-Aloud']; - $botList[] = ['Google-Site-Verification', 'Google-Site-Verification']; - $botList[] = ['AdIdxBot', 'AdIdxBot']; - $botList[] = ['NewRelic', 'NewRelic']; - $botList[] = ['Detectify', 'Detectify']; - $botList[] = ['UptimeRobot', 'UptimeRobot']; - $botList[] = ['SendGrid', 'SendGrid']; - $botList[] = ['Applebot', 'Applebot']; - $botList[] = ['PinterestBot', 'PinterestBot']; - $botList[] = ['Pingdom', 'Pingdom']; - $botList[] = ['Barkrowler', 'Barkrowler']; - $botList[] = ['SEMrush', 'SEMrush']; - $botList[] = ['GPTBot', 'GPTBot']; - $botList[] = ['ChatGPT-User', 'ChatGPT-User']; - $botList[] = ['Bytespider', 'Bytespider']; - $botList[] = ['CCBot', 'CCBot']; - $botList[] = ['FacebookBot', 'FacebookBot']; - $botList[] = ['Google-Extended', 'Google-Extended']; - $botList[] = ['Site24x7', 'Site24x7']; - $botList[] = ['Stripe', 'Stripe']; - $botList[] = ['Slackbot', 'Slackbot']; - $botList[] = ['Proximic', 'Proximic']; - $botList[] = ['okhttp', 'okhttp']; - $botList[] = ['Python', 'Python']; - $botList[] = ['SemrushBot', 'SemrushBot']; - $botList[] = ['Chrome-Lighthouse', 'Chrome-Lighthouse']; - $botList[] = ['Axios', 'Axios']; - $botList[] = ['PetalBot', 'PetalBot']; - $botList[] = ['CriteoBot', 'CriteoBot']; - $botList[] = ['Baidu', 'Baidu']; - $botList[] = ['ContentKing', 'ContentKing']; - $botList[] = ['IAS crawler', 'IAS crawler']; - $botList[] = ['Sucuri', 'Sucuri']; - $botList[] = ['Seekport', 'Seekport']; - $botList[] = ['Sogou', 'Sogou']; - $botList[] = ['YahooMailProxy', 'YahooMailProxy']; + $botList[] = ['Amazonbot','Amazonbot']; + $botList[] = ['Qualys','Qualys']; + $botList[] = ['bingbot','bingbot']; + $botList[] = ['YandexBot','YandexBot']; + $botList[] = ['AhrefsBot','AhrefsBot']; + $botList[] = ['Ahrefs','Ahrefs']; + $botList[] = ['Scrapy','Scrapy']; + $botList[] = ['Googlebot-Image','Google-Image']; + $botList[] = ['Googlebot-News','Googlebot-News']; + $botList[] = ['Googlebot-Video','Googlebot-Video']; + $botList[] = ['Storebot-Google','Storebot-Google']; + $botList[] = ['Google-InspectionTool','Google-InspectionTool']; + $botList[] = ['Google-Extended','Google-Extended']; + $botList[] = ['GoogleOther','GoogleOther']; + $botList[] = ['APIs-Google','APIs-Google']; + $botList[] = ['AdsBot-Google-Mobile','AdsBot-Google-Mobile']; + $botList[] = ['AdsBot-Google','AdsBot-Google']; + $botList[] = ['Mediapartners-Google','Google AdSense']; + $botList[] = ['Google-Safety','Google-Safety']; + $botList[] = ['Googlebot','Googlebot']; + $botList[] = ['Google-Read-Aloud','Google-Read-Aloud']; + $botList[] = ['Google-Site-Verification','Google-Site-Verification']; + $botList[] = ['AdIdxBot','AdIdxBot']; + $botList[] = ['NewRelic','NewRelic']; + $botList[] = ['Detectify','Detectify']; + $botList[] = ['UptimeRobot','UptimeRobot']; + $botList[] = ['SendGrid','SendGrid']; + $botList[] = ['Applebot','Applebot']; + $botList[] = ['PinterestBot','PinterestBot']; + $botList[] = ['Pingdom','Pingdom']; + $botList[] = ['Barkrowler','Barkrowler']; + $botList[] = ['SEMrush','SEMrush']; + $botList[] = ['GPTBot','GPTBot']; + $botList[] = ['ChatGPT-User','ChatGPT-User']; + $botList[] = ['Bytespider','Bytespider']; + $botList[] = ['CCBot','CCBot']; + $botList[] = ['FacebookBot','FacebookBot']; + $botList[] = ['Google-Extended','Google-Extended']; + $botList[] = ['Site24x7','Site24x7']; + $botList[] = ['Stripe','Stripe']; + $botList[] = ['Slackbot','Slackbot']; + $botList[] = ['Proximic','Proximic']; + $botList[] = ['okhttp','okhttp']; + $botList[] = ['Python','Python']; + $botList[] = ['SemrushBot','SemrushBot']; + $botList[] = ['Chrome-Lighthouse','Chrome-Lighthouse']; + $botList[] = ['Axios','Axios']; + $botList[] = ['PetalBot','PetalBot']; + $botList[] = ['CriteoBot','CriteoBot']; + $botList[] = ['Baidu','Baidu']; + $botList[] = ['ContentKing','ContentKing']; + $botList[] = ['IAS crawler','IAS crawler']; + $botList[] = ['Sucuri','Sucuri']; + $botList[] = ['Seekport','Seekport']; + $botList[] = ['Sogou','Sogou']; + $botList[] = ['YahooMailProxy','YahooMailProxy']; return $botList; } @@ -477,6 +351,24 @@ public static function insertDefaultBots($idsite = 0) return $i; } + public function deleteBot($botId) + { + Piwik::checkUserHasSuperUserAccess(); + try { + $db = self::getDb(); + $query = $db->query( + "DELETE FROM `" . + Common::prefixTable('bot_db') . + "` WHERE `botId` = ?", + [$botId] + ); + return true; + } catch (\Exception $e) { + throw $e; + return false; + } + } + public static function getBotByName($idSite, $botName) { Piwik::checkUserHasSomeViewAccess(); @@ -490,8 +382,92 @@ public static function getBotByName($idSite, $botName) return $rows; } + private static function convertBotLastVisitToLocalTime($rows, $idSite) + { + // convert lastVisit to localtime + $timezone = Site::getTimezoneFor($idSite); + + try { + foreach ($rows as &$row) { + if ($row['botLastVisit'] == '0000-00-00 00:00:00') { + $row['botLastVisit'] = " - "; + } elseif ($row['botLastVisit'] == '2000-01-01 00:00:00') { + $row['botLastVisit'] = " - "; + } else { + $botLastVisit = Date::adjustForTimezone(strtotime($row['botLastVisit']), $timezone); + $row['botLastVisit'] = date('Y-m-d H:i:s', $botLastVisit); + } + } + } catch (\Exception $e) { + throw $e; + return false; + } + return $rows; + } + private static function htmlentities2utf8($string) + { + $output = preg_replace_callback("/(&#[0-9]+;)/", function ($m) { + return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); + }, $string); + return html_entity_decode($output); + } + + /** + * Get Data for the Report "Top10" + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return DataTable + */ + public function getTop10($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getAllBotDataPie($idSite); + } /** - * @return \Piwik\DataTable + * Get Data for the Report "BotTracker" + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return DataTable + */ + public function getBotTracker($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getAllBotData($idSite); + } + + /** + * Get Data for the Report "BotTrackerReport" + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getBotTrackerReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getBotTrackerReportDataTable($idSite, $period, $date, $segment = false); + } + + + /** + * Get Data for the Report "BotStatsReport" + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getOtherBots($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getOtherBotsDataTable($idSite, $period, $date, $segment = false); + } + + /** + * @return DataTable */ public static function getOtherBotsDataTable($idSite, $period, $date, $segment) { @@ -508,16 +484,32 @@ public static function getOtherBotsData($idSite, $period, $date, $segment) list($startDate, $endDate) = self::getDateRangeForPeriod($date, $period, false); $startDate = $startDate->toString(); $endDate = $endDate->toString(); - return self::getDb()->fetchAll( + $rows = self::getDb()->fetchAll( "SELECT useragent, COUNT(*) as total FROM " . Common::prefixTable('bot_device_detector_bots') . " WHERE idSite= ? AND date(date) between ? AND ? GROUP BY `useragent` ORDER BY `useragent`", - [$idSite, $startDate, $endDate] + [$idSite, $startDate, $endDate ] ); + // // @todo: convert visit_timestamp to site + return $rows; } + /** - * @return \Piwik\DataTable + * Get Data for the Report "BotStatsReport" + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getStatsReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getStatsReportDataTable($idSite, $period, $date, $segment = false); + } + + /** + * @return DataTable */ public static function getStatsReportDataTable($idSite, $period, $date, $segment) { @@ -538,7 +530,7 @@ public static function getStatsReportData($idSite, $period, $date, $segment) "SELECT * FROM " . Common::prefixTable('bot_db_stat') . " WHERE idSite= ? AND date(visit_timestamp) between ? AND ? ORDER BY `botId`", - [$idSite, $startDate, $endDate] + [$idSite, $startDate, $endDate ] ); foreach ($rows as &$row) { $name = self::getDb()->fetchRow( @@ -553,6 +545,55 @@ public static function getStatsReportData($idSite, $period, $date, $segment) return $rows; } + /** + * Get Data for the Report "BotTrackerReport" + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return DataTable + */ + public function getBotTrackerTopTenReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getBotTrackerTopTenReportPieDataTable($idSite, $period, $date, $segment = false); + } + + /** + * Get Data for Dashboard-Widget + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return DataTable + */ + public function getBotTrackerAnzeige($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getActiveBotData($idSite); + } + + public function getBotTypes() + { + Piwik::checkUserHasSomeViewAccess(); + $db = self::getDb(); + $rows = $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); + return $rows; + } + public function addBotType($type) + { + Piwik::checkUserHasSuperUserAccess(); + try { + $db = self::getDb(); + $sql = sprintf( + 'INSERT INTO ' . Common::prefixTable('bot_type') . ' (`name`) VALUES (?)' + ); + $db->query($sql, [$type]); + } catch (\Exception $e) { + throw $e; + } + } + public static function getDateRangeForPeriod($date, $period, $lastN = false) { $lastN = false; @@ -571,8 +612,7 @@ public static function getDateRangeForPeriod($date, $period, $lastN = false) $oPeriod = Period\Factory::build($period, Date::factory($date)); $startDate = $oPeriod->getDateStart(); $endDate = $oPeriod->getDateEnd(); - } else { - // if the range includes the last N periods or is a multiple period + } else { // if the range includes the last N periods or is a multiple period if (!$isMultiplePeriod) { list($date, $lastN) = Evolution::getDateRangeAndLastN($period, $date, $lastN); } @@ -583,49 +623,4 @@ public static function getDateRangeForPeriod($date, $period, $lastN = false) } return [$startDate, $endDate]; } - - private static function getDb() - { - return Db::get(); - } - - /** - * @return \Piwik\DataTable - */ - private static function getDataTable($rows) - { - return DataTable::makeFromIndexedArray($rows); - } - - private static function convertBotLastVisitToLocalTime($rows, $idSite) - { - // convert lastVisit to localtime - $timezone = Site::getTimezoneFor($idSite); - - try { - foreach ($rows as &$row) { - if ($row['botLastVisit'] == '0000-00-00 00:00:00') { - $row['botLastVisit'] = " - "; - } elseif ($row['botLastVisit'] == '2000-01-01 00:00:00') { - $row['botLastVisit'] = " - "; - } else { - $botLastVisit = Date::adjustForTimezone(strtotime($row['botLastVisit']), $timezone); - $row['botLastVisit'] = date('Y-m-d H:i:s', $botLastVisit); - } - } - } catch (Exception $e) { - throw $e; - return false; - } - return $rows; - } - - private static function htmlentities2utf8($string) - { - $output = preg_replace_callback("/(&#[0-9]+;)/", function ($m) { - return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); - }, $string); - return html_entity_decode($output); - } - } diff --git a/BotTracker.php b/BotTracker.php index 512d2f8..914058f 100644 --- a/BotTracker.php +++ b/BotTracker.php @@ -21,6 +21,9 @@ use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Tracker; +/** + * @package Matomo_BotTracker + */ class BotTracker extends Plugin { diff --git a/CHANGELOG.md b/CHANGELOG.md index 374e832..6b873a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,7 +108,7 @@ Matomo 5 compatibility fixes. * change order of columns in the BotTracker report (issue #68) -## [2.00] - 2020-12-05 +## [2.00] - unknown2-05 * upgrade to Matomo 4 (issue #66) diff --git a/Controller.php b/Controller.php index b9b4168..37e8ca3 100644 --- a/Controller.php +++ b/Controller.php @@ -20,6 +20,9 @@ use Piwik\Request; use Piwik\View; +/** + * @package Matomo_BotTracker + */ class Controller extends ControllerAdmin { diff --git a/Menu.php b/Menu.php index db27ded..e571a6d 100644 --- a/Menu.php +++ b/Menu.php @@ -15,9 +15,7 @@ use Piwik\Plugin\Menu as MatomoMenu; /** - * This class allows you to add, remove or rename menu items. - * To configure a menu (such as Admin Menu, Reporting Menu, User Menu...) simply call the corresponding methods as - * described in the API-Reference http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract + * @package Matomo_BotTracker */ class Menu extends MatomoMenu { diff --git a/Reports/Base.php b/Reports/Base.php index 10ea313..a36b33b 100644 --- a/Reports/Base.php +++ b/Reports/Base.php @@ -12,6 +12,9 @@ use Piwik\Plugin\Report; +/** + * @package Matomo_BotTracker + */ abstract class Base extends Report { diff --git a/Reports/GetBotTracker.php b/Reports/GetBotTracker.php index 921d76d..2fbb3e7 100644 --- a/Reports/GetBotTracker.php +++ b/Reports/GetBotTracker.php @@ -22,6 +22,7 @@ * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. * * @deprecated since v5.2.0, will be removed in v5.3.0 + * @package Matomo_BotTracker */ class GetBotTracker extends Base { diff --git a/Reports/GetBotTrackerAnzeige.php b/Reports/GetBotTrackerAnzeige.php index ceff65a..19c7480 100644 --- a/Reports/GetBotTrackerAnzeige.php +++ b/Reports/GetBotTrackerAnzeige.php @@ -22,6 +22,7 @@ * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. * * @deprecated since v5.2.0, will be removed in v5.3.0 + * @package Matomo_BotTracker */ class GetBotTrackerAnzeige extends Base { diff --git a/Reports/GetBotTrackerReport.php b/Reports/GetBotTrackerReport.php index 362392f..f63d0f7 100644 --- a/Reports/GetBotTrackerReport.php +++ b/Reports/GetBotTrackerReport.php @@ -18,6 +18,7 @@ /** * Defines the GetBotTrackerReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * @package Matomo_BotTracker */ class GetBotTrackerReport extends Base { diff --git a/Reports/GetBotTrackerTopTenReport.php b/Reports/GetBotTrackerTopTenReport.php index 70b55a3..52b2a39 100644 --- a/Reports/GetBotTrackerTopTenReport.php +++ b/Reports/GetBotTrackerTopTenReport.php @@ -18,6 +18,7 @@ /** * Defines the class GetBotTrackerTopTenReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * @package Matomo_BotTracker */ class GetBotTrackerTopTenReport extends Base { diff --git a/Reports/GetOtherBots.php b/Reports/GetOtherBots.php index cbe0b8a..614e3c0 100644 --- a/Reports/GetOtherBots.php +++ b/Reports/GetOtherBots.php @@ -18,6 +18,7 @@ /** * Defines the GetBotStatsReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * @package Matomo_BotTracker */ class GetOtherBots extends Base { diff --git a/Reports/GetStatsReport.php b/Reports/GetStatsReport.php index df9c842..e1c15a9 100644 --- a/Reports/GetStatsReport.php +++ b/Reports/GetStatsReport.php @@ -18,6 +18,7 @@ /** * Defines the GetBotStatsReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * @package Matomo_BotTracker */ class GetStatsReport extends Base { diff --git a/Reports/GetTop10.php b/Reports/GetTop10.php index fb72bfc..ed5ca6b 100644 --- a/Reports/GetTop10.php +++ b/Reports/GetTop10.php @@ -18,6 +18,7 @@ * Defines the GetTop10 report. * * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * @package Matomo_BotTracker */ class GetTop10 extends Base { diff --git a/SystemSettings.php b/SystemSettings.php index 87ae837..8641d9e 100644 --- a/SystemSettings.php +++ b/SystemSettings.php @@ -15,7 +15,7 @@ use Piwik\Settings\Setting; /** - * Defines Settings for BotTracker. + * @package Matomo_BotTracker */ class SystemSettings extends MatomoSystemSettings { diff --git a/Widgets/GetDigiInfo.php b/Widgets/GetDigiInfo.php index be968ff..6dda120 100644 --- a/Widgets/GetDigiInfo.php +++ b/Widgets/GetDigiInfo.php @@ -6,6 +6,9 @@ use Piwik\Widget\Widget; use Piwik\Widget\WidgetConfig; +/** + * @package Matomo_BotTracker + */ class GetDigiInfo extends Widget { From 8e759af815977d35c4066ae8a0fada404c7f610a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikke=20Schir=C3=A9n?= Date: Mon, 8 Apr 2024 22:16:27 +0200 Subject: [PATCH 5/6] some coding standard fixes --- API.php | 512 +++++++++++++------------- Reports/GetBotTrackerReport.php | 1 + Reports/GetBotTrackerTopTenReport.php | 1 + Reports/GetOtherBots.php | 1 + Reports/GetStatsReport.php | 1 + Reports/GetTop10.php | 1 + 6 files changed, 264 insertions(+), 253 deletions(-) diff --git a/API.php b/API.php index df309cf..ccafe8b 100644 --- a/API.php +++ b/API.php @@ -3,41 +3,174 @@ /** * BotTracker, a Matomo plugin by Digitalist Open Tech * Based on the work of Thomas--F (https://github.com/Thomas--F) + * * @link https://github.com/digitalist-se/BotTracker * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ namespace Piwik\Plugins\BotTracker; -use Piwik\Container\StaticContainer; -use Piwik\Db; +use Exception; use Piwik\Common; +use Piwik\Container\StaticContainer; use Piwik\DataTable; -use Piwik\Site; use Piwik\Date; -use Piwik\Piwik; +use Piwik\Db; use Piwik\Period; +use Piwik\Piwik; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution; +use Piwik\Site; +use Piwik\Plugin\API as PiwikAPI; /** * @package Matomo_BotTracker */ -class API extends \Piwik\Plugin\API +class API extends PiwikAPI { + private static $instance = null; - private static function getDb() + public function deleteBot($botId) { - return Db::get(); + Piwik::checkUserHasSuperUserAccess(); + try { + $db = self::getDb(); + $db->query( + "DELETE FROM `" . + Common::prefixTable('bot_db') . + "` WHERE `botId` = ?", + [$botId] + ); + return true; + } catch (Exception $e) { + throw $e; + return false; + } } /** - * @return DataTable + * Get Data for the Report "Top10" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable */ - private static function getDataTable($rows) + public function getTop10($idSite, $period, $date, $segment = false) { - return DataTable::makeFromIndexedArray($rows); + Piwik::checkUserHasSomeViewAccess(); + return $this->getAllBotDataPie($idSite); + } + + /** + * Get Data for the Report "BotTracker" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable + */ + public function getBotTracker($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getAllBotData($idSite); + } + + /** + * Get Data for the Report "BotTrackerReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getBotTrackerReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getBotTrackerReportDataTable($idSite, $period, $date, $segment = false); + } + + /** + * Get Data for the Report "BotStatsReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getOtherBots($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getOtherBotsDataTable($idSite, $period, $date, $segment = false); + } + + /** + * Get Data for the Report "BotStatsReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + */ + public function getStatsReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getStatsReportDataTable($idSite, $period, $date, $segment = false); } + + /** + * Get Data for the Report "BotTrackerReport" + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable + */ + public function getBotTrackerTopTenReport($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getBotTrackerTopTenReportPieDataTable($idSite, $period, $date, $segment = false); + } + + /** + * Get Data for Dashboard-Widget + * + * @param int $idSite + * @param string $period + * @param string $date + * @param bool|string $segment + * @return \Piwik\DataTable + */ + public function getBotTrackerAnzeige($idSite, $period, $date, $segment = false) + { + Piwik::checkUserHasSomeViewAccess(); + return $this->getActiveBotData($idSite); + } + + public function getBotTypes() + { + Piwik::checkUserHasSomeViewAccess(); + $db = self::getDb(); + return $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); + } + + public function addBotType($type) + { + Piwik::checkUserHasSuperUserAccess(); + try { + $db = self::getDb(); + $sql = sprintf( + 'INSERT INTO ' . Common::prefixTable('bot_type') . ' (`name`) VALUES (?)' + ); + $db->query($sql, [$type]); + } catch (Exception $e) { + throw $e; + } + } + /** * @return \Piwik\Plugins\BotTracker\API * @throws \Exception @@ -47,10 +180,10 @@ public static function getInstance() try { $instance = StaticContainer::get('BotTracker_API'); if (!($instance instanceof API)) { - throw new \Exception('BotTracker_API must inherit API'); + throw new Exception('BotTracker_API must inherit API'); } self::$instance = $instance; - } catch (\Exception $e) { + } catch (Exception $e) { self::$instance = StaticContainer::get('Piwik\Plugins\BotTracker\API'); StaticContainer::getContainer()->set('BotTracker_API', self::$instance); } @@ -72,7 +205,7 @@ public static function getAllBotData($idSite) } /** - * @return DataTable + * @return \Piwik\DataTable */ public static function getBotTrackerReportDataTable($idSite, $period, $date, $segment) { @@ -134,9 +267,9 @@ public static function getBotTrackerTopTenReportPieData($idSite, $period, $date, // For some reason, we are off by one, add an dummy bot in end. // @todo: Look into why this is needed. $dummy = [ - 'botName' => 'dummy', - 'botId' => 0, 'botCount' => 0, + 'botId' => 0, + 'botName' => 'dummy', ]; array_push($rows, $dummy); // Get totals of a bot number. @@ -162,15 +295,13 @@ public static function getBotTrackerTopTenReportPieData($idSite, $period, $date, // Remove zero results, and limit to ten. $pie = array_diff($pie, [0]); arsort($pie); - $rows = array_slice($pie, 0, 10); - - return $rows; + return array_slice($pie, 0, 10); } public static function getAllBotDataForConfig($idsite) { Piwik::checkUserHasSomeViewAccess(); - $rows = self::getDb()->fetchAll( + return self::getDb()->fetchAll( "SELECT `idsite`, `botId`, `botName`, `botActive`, `botKeyword`, `extra_stats`, @@ -179,11 +310,8 @@ public static function getAllBotDataForConfig($idsite) " WHERE `idsite` = ? ORDER BY `botId`", [$idsite] ); - - return $rows; } - public static function getActiveBotData($idSite) { Piwik::checkUserHasSomeViewAccess(); @@ -263,72 +391,71 @@ public static function insertBot($idSite, $botName, $botActive, $botKeyword, $ex $botType] ); return true; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; return false; } } - public static function defaultBots() { $botList = []; - $botList[] = ['Amazonbot','Amazonbot']; - $botList[] = ['Qualys','Qualys']; - $botList[] = ['bingbot','bingbot']; - $botList[] = ['YandexBot','YandexBot']; - $botList[] = ['AhrefsBot','AhrefsBot']; - $botList[] = ['Ahrefs','Ahrefs']; - $botList[] = ['Scrapy','Scrapy']; - $botList[] = ['Googlebot-Image','Google-Image']; - $botList[] = ['Googlebot-News','Googlebot-News']; - $botList[] = ['Googlebot-Video','Googlebot-Video']; - $botList[] = ['Storebot-Google','Storebot-Google']; - $botList[] = ['Google-InspectionTool','Google-InspectionTool']; - $botList[] = ['Google-Extended','Google-Extended']; - $botList[] = ['GoogleOther','GoogleOther']; - $botList[] = ['APIs-Google','APIs-Google']; - $botList[] = ['AdsBot-Google-Mobile','AdsBot-Google-Mobile']; - $botList[] = ['AdsBot-Google','AdsBot-Google']; - $botList[] = ['Mediapartners-Google','Google AdSense']; - $botList[] = ['Google-Safety','Google-Safety']; - $botList[] = ['Googlebot','Googlebot']; - $botList[] = ['Google-Read-Aloud','Google-Read-Aloud']; - $botList[] = ['Google-Site-Verification','Google-Site-Verification']; - $botList[] = ['AdIdxBot','AdIdxBot']; - $botList[] = ['NewRelic','NewRelic']; - $botList[] = ['Detectify','Detectify']; - $botList[] = ['UptimeRobot','UptimeRobot']; - $botList[] = ['SendGrid','SendGrid']; - $botList[] = ['Applebot','Applebot']; - $botList[] = ['PinterestBot','PinterestBot']; - $botList[] = ['Pingdom','Pingdom']; - $botList[] = ['Barkrowler','Barkrowler']; - $botList[] = ['SEMrush','SEMrush']; - $botList[] = ['GPTBot','GPTBot']; - $botList[] = ['ChatGPT-User','ChatGPT-User']; - $botList[] = ['Bytespider','Bytespider']; - $botList[] = ['CCBot','CCBot']; - $botList[] = ['FacebookBot','FacebookBot']; - $botList[] = ['Google-Extended','Google-Extended']; - $botList[] = ['Site24x7','Site24x7']; - $botList[] = ['Stripe','Stripe']; - $botList[] = ['Slackbot','Slackbot']; - $botList[] = ['Proximic','Proximic']; - $botList[] = ['okhttp','okhttp']; - $botList[] = ['Python','Python']; - $botList[] = ['SemrushBot','SemrushBot']; - $botList[] = ['Chrome-Lighthouse','Chrome-Lighthouse']; - $botList[] = ['Axios','Axios']; - $botList[] = ['PetalBot','PetalBot']; - $botList[] = ['CriteoBot','CriteoBot']; - $botList[] = ['Baidu','Baidu']; - $botList[] = ['ContentKing','ContentKing']; - $botList[] = ['IAS crawler','IAS crawler']; - $botList[] = ['Sucuri','Sucuri']; - $botList[] = ['Seekport','Seekport']; - $botList[] = ['Sogou','Sogou']; - $botList[] = ['YahooMailProxy','YahooMailProxy']; + $botList[] = ['Amazonbot', 'Amazonbot']; + $botList[] = ['Qualys', 'Qualys']; + $botList[] = ['bingbot', 'bingbot']; + $botList[] = ['YandexBot', 'YandexBot']; + $botList[] = ['AhrefsBot', 'AhrefsBot']; + $botList[] = ['Ahrefs', 'Ahrefs']; + $botList[] = ['Scrapy', 'Scrapy']; + $botList[] = ['Googlebot-Image', 'Google-Image']; + $botList[] = ['Googlebot-News', 'Googlebot-News']; + $botList[] = ['Googlebot-Video', 'Googlebot-Video']; + $botList[] = ['Storebot-Google', 'Storebot-Google']; + $botList[] = ['Google-InspectionTool', 'Google-InspectionTool']; + $botList[] = ['Google-Extended', 'Google-Extended']; + $botList[] = ['GoogleOther', 'GoogleOther']; + $botList[] = ['APIs-Google', 'APIs-Google']; + $botList[] = ['AdsBot-Google-Mobile', 'AdsBot-Google-Mobile']; + $botList[] = ['AdsBot-Google', 'AdsBot-Google']; + $botList[] = ['Mediapartners-Google', 'Google AdSense']; + $botList[] = ['Google-Safety', 'Google-Safety']; + $botList[] = ['Googlebot', 'Googlebot']; + $botList[] = ['Google-Read-Aloud', 'Google-Read-Aloud']; + $botList[] = ['Google-Site-Verification', 'Google-Site-Verification']; + $botList[] = ['AdIdxBot', 'AdIdxBot']; + $botList[] = ['NewRelic', 'NewRelic']; + $botList[] = ['Detectify', 'Detectify']; + $botList[] = ['UptimeRobot', 'UptimeRobot']; + $botList[] = ['SendGrid', 'SendGrid']; + $botList[] = ['Applebot', 'Applebot']; + $botList[] = ['PinterestBot', 'PinterestBot']; + $botList[] = ['Pingdom', 'Pingdom']; + $botList[] = ['Barkrowler', 'Barkrowler']; + $botList[] = ['SEMrush', 'SEMrush']; + $botList[] = ['GPTBot', 'GPTBot']; + $botList[] = ['ChatGPT-User', 'ChatGPT-User']; + $botList[] = ['Bytespider', 'Bytespider']; + $botList[] = ['CCBot', 'CCBot']; + $botList[] = ['FacebookBot', 'FacebookBot']; + $botList[] = ['Google-Extended', 'Google-Extended']; + $botList[] = ['Site24x7', 'Site24x7']; + $botList[] = ['Stripe', 'Stripe']; + $botList[] = ['Slackbot', 'Slackbot']; + $botList[] = ['Proximic', 'Proximic']; + $botList[] = ['okhttp', 'okhttp']; + $botList[] = ['Python', 'Python']; + $botList[] = ['SemrushBot', 'SemrushBot']; + $botList[] = ['Chrome-Lighthouse', 'Chrome-Lighthouse']; + $botList[] = ['Axios', 'Axios']; + $botList[] = ['PetalBot', 'PetalBot']; + $botList[] = ['CriteoBot', 'CriteoBot']; + $botList[] = ['Baidu', 'Baidu']; + $botList[] = ['ContentKing', 'ContentKing']; + $botList[] = ['IAS crawler', 'IAS crawler']; + $botList[] = ['Sucuri', 'Sucuri']; + $botList[] = ['Seekport', 'Seekport']; + $botList[] = ['Sogou', 'Sogou']; + $botList[] = ['YahooMailProxy', 'YahooMailProxy']; return $botList; } @@ -351,24 +478,6 @@ public static function insertDefaultBots($idsite = 0) return $i; } - public function deleteBot($botId) - { - Piwik::checkUserHasSuperUserAccess(); - try { - $db = self::getDb(); - $query = $db->query( - "DELETE FROM `" . - Common::prefixTable('bot_db') . - "` WHERE `botId` = ?", - [$botId] - ); - return true; - } catch (\Exception $e) { - throw $e; - return false; - } - } - public static function getBotByName($idSite, $botName) { Piwik::checkUserHasSomeViewAccess(); @@ -382,92 +491,8 @@ public static function getBotByName($idSite, $botName) return $rows; } - private static function convertBotLastVisitToLocalTime($rows, $idSite) - { - // convert lastVisit to localtime - $timezone = Site::getTimezoneFor($idSite); - - try { - foreach ($rows as &$row) { - if ($row['botLastVisit'] == '0000-00-00 00:00:00') { - $row['botLastVisit'] = " - "; - } elseif ($row['botLastVisit'] == '2000-01-01 00:00:00') { - $row['botLastVisit'] = " - "; - } else { - $botLastVisit = Date::adjustForTimezone(strtotime($row['botLastVisit']), $timezone); - $row['botLastVisit'] = date('Y-m-d H:i:s', $botLastVisit); - } - } - } catch (\Exception $e) { - throw $e; - return false; - } - return $rows; - } - private static function htmlentities2utf8($string) - { - $output = preg_replace_callback("/(&#[0-9]+;)/", function ($m) { - return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); - }, $string); - return html_entity_decode($output); - } - - /** - * Get Data for the Report "Top10" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getTop10($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getAllBotDataPie($idSite); - } - /** - * Get Data for the Report "BotTracker" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getBotTracker($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getAllBotData($idSite); - } - - /** - * Get Data for the Report "BotTrackerReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getBotTrackerReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getBotTrackerReportDataTable($idSite, $period, $date, $segment = false); - } - - /** - * Get Data for the Report "BotStatsReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getOtherBots($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getOtherBotsDataTable($idSite, $period, $date, $segment = false); - } - - /** - * @return DataTable + * @return \Piwik\DataTable */ public static function getOtherBotsDataTable($idSite, $period, $date, $segment) { @@ -484,32 +509,16 @@ public static function getOtherBotsData($idSite, $period, $date, $segment) list($startDate, $endDate) = self::getDateRangeForPeriod($date, $period, false); $startDate = $startDate->toString(); $endDate = $endDate->toString(); - $rows = self::getDb()->fetchAll( + return self::getDb()->fetchAll( "SELECT useragent, COUNT(*) as total FROM " . Common::prefixTable('bot_device_detector_bots') . " WHERE idSite= ? AND date(date) between ? AND ? GROUP BY `useragent` ORDER BY `useragent`", - [$idSite, $startDate, $endDate ] + [$idSite, $startDate, $endDate] ); - // // @todo: convert visit_timestamp to site - return $rows; } - /** - * Get Data for the Report "BotStatsReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - */ - public function getStatsReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getStatsReportDataTable($idSite, $period, $date, $segment = false); - } - - /** - * @return DataTable + * @return \Piwik\DataTable */ public static function getStatsReportDataTable($idSite, $period, $date, $segment) { @@ -530,7 +539,7 @@ public static function getStatsReportData($idSite, $period, $date, $segment) "SELECT * FROM " . Common::prefixTable('bot_db_stat') . " WHERE idSite= ? AND date(visit_timestamp) between ? AND ? ORDER BY `botId`", - [$idSite, $startDate, $endDate ] + [$idSite, $startDate, $endDate] ); foreach ($rows as &$row) { $name = self::getDb()->fetchRow( @@ -545,55 +554,6 @@ public static function getStatsReportData($idSite, $period, $date, $segment) return $rows; } - /** - * Get Data for the Report "BotTrackerReport" - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getBotTrackerTopTenReport($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getBotTrackerTopTenReportPieDataTable($idSite, $period, $date, $segment = false); - } - - /** - * Get Data for Dashboard-Widget - * @param int $idSite - * @param string $period - * @param string $date - * @param bool|string $segment - * @return DataTable - */ - public function getBotTrackerAnzeige($idSite, $period, $date, $segment = false) - { - Piwik::checkUserHasSomeViewAccess(); - return $this->getActiveBotData($idSite); - } - - public function getBotTypes() - { - Piwik::checkUserHasSomeViewAccess(); - $db = self::getDb(); - $rows = $db->fetchAll("SELECT `name`, `id` FROM " . Common::prefixTable('bot_type') . " ORDER BY `name`"); - return $rows; - } - public function addBotType($type) - { - Piwik::checkUserHasSuperUserAccess(); - try { - $db = self::getDb(); - $sql = sprintf( - 'INSERT INTO ' . Common::prefixTable('bot_type') . ' (`name`) VALUES (?)' - ); - $db->query($sql, [$type]); - } catch (\Exception $e) { - throw $e; - } - } - public static function getDateRangeForPeriod($date, $period, $lastN = false) { $lastN = false; @@ -612,7 +572,8 @@ public static function getDateRangeForPeriod($date, $period, $lastN = false) $oPeriod = Period\Factory::build($period, Date::factory($date)); $startDate = $oPeriod->getDateStart(); $endDate = $oPeriod->getDateEnd(); - } else { // if the range includes the last N periods or is a multiple period + } else { + // if the range includes the last N periods or is a multiple period if (!$isMultiplePeriod) { list($date, $lastN) = Evolution::getDateRangeAndLastN($period, $date, $lastN); } @@ -623,4 +584,49 @@ public static function getDateRangeForPeriod($date, $period, $lastN = false) } return [$startDate, $endDate]; } + + private static function getDb() + { + return Db::get(); + } + + /** + * @return \Piwik\DataTable + */ + private static function getDataTable($rows) + { + return DataTable::makeFromIndexedArray($rows); + } + + private static function convertBotLastVisitToLocalTime($rows, $idSite) + { + // convert lastVisit to localtime + $timezone = Site::getTimezoneFor($idSite); + + try { + foreach ($rows as &$row) { + if ($row['botLastVisit'] == '0000-00-00 00:00:00') { + $row['botLastVisit'] = " - "; + } elseif ($row['botLastVisit'] == '2000-01-01 00:00:00') { + $row['botLastVisit'] = " - "; + } else { + $botLastVisit = Date::adjustForTimezone(strtotime($row['botLastVisit']), $timezone); + $row['botLastVisit'] = date('Y-m-d H:i:s', $botLastVisit); + } + } + } catch (Exception $e) { + throw $e; + return false; + } + return $rows; + } + + private static function htmlentities2utf8($string) + { + $output = preg_replace_callback("/(&#[0-9]+;)/", function ($m) { + return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); + }, $string); + return html_entity_decode($output); + } + } diff --git a/Reports/GetBotTrackerReport.php b/Reports/GetBotTrackerReport.php index f63d0f7..1a01742 100644 --- a/Reports/GetBotTrackerReport.php +++ b/Reports/GetBotTrackerReport.php @@ -18,6 +18,7 @@ /** * Defines the GetBotTrackerReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * * @package Matomo_BotTracker */ class GetBotTrackerReport extends Base diff --git a/Reports/GetBotTrackerTopTenReport.php b/Reports/GetBotTrackerTopTenReport.php index 52b2a39..1eebf09 100644 --- a/Reports/GetBotTrackerTopTenReport.php +++ b/Reports/GetBotTrackerTopTenReport.php @@ -18,6 +18,7 @@ /** * Defines the class GetBotTrackerTopTenReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * * @package Matomo_BotTracker */ class GetBotTrackerTopTenReport extends Base diff --git a/Reports/GetOtherBots.php b/Reports/GetOtherBots.php index 614e3c0..bb71b47 100644 --- a/Reports/GetOtherBots.php +++ b/Reports/GetOtherBots.php @@ -18,6 +18,7 @@ /** * Defines the GetBotStatsReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * * @package Matomo_BotTracker */ class GetOtherBots extends Base diff --git a/Reports/GetStatsReport.php b/Reports/GetStatsReport.php index e1c15a9..d9c6afb 100644 --- a/Reports/GetStatsReport.php +++ b/Reports/GetStatsReport.php @@ -18,6 +18,7 @@ /** * Defines the GetBotStatsReport report. * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * * @package Matomo_BotTracker */ class GetStatsReport extends Base diff --git a/Reports/GetTop10.php b/Reports/GetTop10.php index ed5ca6b..e9fad53 100644 --- a/Reports/GetTop10.php +++ b/Reports/GetTop10.php @@ -18,6 +18,7 @@ * Defines the GetTop10 report. * * See {@link https://developer.matomo.org/api-reference/Piwik/Plugin/Report} for more information. + * * @package Matomo_BotTracker */ class GetTop10 extends Base From ca9b3b9341bb9aba8aaaffff953a22cd64740293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikke=20Schir=C3=A9n?= Date: Mon, 8 Apr 2024 22:18:32 +0200 Subject: [PATCH 6/6] fix use sort --- API.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API.php b/API.php index ccafe8b..83b2b68 100644 --- a/API.php +++ b/API.php @@ -18,9 +18,9 @@ use Piwik\Db; use Piwik\Period; use Piwik\Piwik; +use Piwik\Plugin\API as PiwikAPI; use Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Evolution; use Piwik\Site; -use Piwik\Plugin\API as PiwikAPI; /** * @package Matomo_BotTracker