diff --git a/data/goURL.sql b/data/goURL.sql index 98b7a5b..75a77a1 100644 --- a/data/goURL.sql +++ b/data/goURL.sql @@ -27,6 +27,7 @@ CREATE TABLE IF NOT EXISTS `tblURLs` ( `submitDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `createdBy` varchar(25) DEFAULT NULL, `redirects` int(11) unsigned DEFAULT 0, + `qrCodeScans` int(11) unsigned DEFAULT 0, `lastRedirect` timestamp NULL, `maliciousCheck` enum('checked', 'unchecked', 'protected')NOT NULL DEFAULT 'unchecked', PRIMARY KEY (`urlID`) @@ -35,6 +36,7 @@ CREATE TABLE IF NOT EXISTS `tblURLs` ( -- ALTER TABLE `tblURLs` ADD COLUMN `groupID` int(10) unsigned NULL AFTER `urlID`; -- ALTER TABLE `tblURLs` ADD COLUMN `lastRedirect` timestamp NULL AFTER `redirects`; -- ALTER TABLE `tblURLs` ADD COLUMN `maliciousCheck` enum('checked', 'unchecked', 'protected') NOT NULL DEFAULT 'unchecked' AFTER `lastRedirect`; +-- ALTER TABLE `tblURLs` ADD COLUMN `qrCodeScans` int(11) unsigned DEFAULT 0 AFTER `redirects`; DROP TABLE IF EXISTS `tblGroups`; CREATE TABLE IF NOT EXISTS `tblGroups` ( diff --git a/src/goController.php b/src/goController.php index 0a0b1be..acaca3a 100644 --- a/src/goController.php +++ b/src/goController.php @@ -397,7 +397,7 @@ private function handleRouteURLQRCodePNG() $this->handle404(FALSE); } - $shortURL = $this->lilurl->getShortURL($this->goId); + $shortURL = $this->lilurl->getShortURL($this->goId) . '?qr'; $pngPrefix = __DIR__ . '/../data/qr/'; $qrCodeHash = hash("sha512", $shortURL); $qrCache = $pngPrefix . 'cache/' . $this->qrCachePrefix . hash("sha512", $shortURL) . '.png'; @@ -449,7 +449,7 @@ private function handleRouteURLQRCodeSVG() $this->handle404(false); } - $shortURL = $this->lilurl->getShortURL($this->goId); + $shortURL = $this->lilurl->getShortURL($this->goId) . '?qr'; $svgPrefix = __DIR__ . '/../data/qr/'; $qrCodeHash = hash("sha512", $shortURL); $qrCache = $svgPrefix . 'cache/' . $this->qrCachePrefix . hash("sha512", $shortURL) . '.svg'; diff --git a/src/lilURL.php b/src/lilURL.php index 0b62b7d..16f608d 100755 --- a/src/lilURL.php +++ b/src/lilURL.php @@ -36,6 +36,7 @@ class lilURL const PDO_PLACEHOLDER_LONG_URL = ':longURL'; const PDO_PLACEHOLDER_CREATED_BY = ':createdBy'; const PDO_PLACEHOLDER_REDIRECTS = ':redirects'; + const PDO_PLACEHOLDER_QR_CODE_SCANS = ':qrCodeScans'; const PDO_PLACEHOLDER_GROUP_ID = ':groupID'; const PDO_PLACEHOLDER_GROUP_NAME = ':groupName'; const PDO_PLACEHOLDER_UID = ':uid'; @@ -124,6 +125,9 @@ protected function trackHit($id) if (!$this->checkForBots()) { // track system redirect $this->incrementRedirectCount($id); + if (isset($_GET['qr'])) { + $this->incrementQRCodeScanCount($id); + } } $accountId = $this->getGaAccount(); @@ -754,7 +758,10 @@ public function deleteURL($urlID, $uid) public function resetRedirectCount($id) { return $this->db->update( self::TABLE_URLS, - array(ltrim(self::PDO_PLACEHOLDER_REDIRECTS, ':') => 0), + array( + ltrim(self::PDO_PLACEHOLDER_REDIRECTS, ':') => 0, + ltrim(self::PDO_PLACEHOLDER_QR_CODE_SCANS, ':') => 0, + ), self::WHERE_URL_ID, array(self::PDO_PLACEHOLDER_URL_ID => $id) ); @@ -983,4 +990,14 @@ private function incrementRedirectCount($id) { array(self::PDO_PLACEHOLDER_URL_ID => $id) ); } + + private function incrementQRCodeScanCount($id) { + return $this->db->run( + 'UPDATE ' + . self::TABLE_URLS + . ' SET qrCodeScans = qrCodeScans + 1 WHERE ' + . self::WHERE_URL_ID, + array(self::PDO_PLACEHOLDER_URL_ID => $id) + ); + } } diff --git a/www/templates/linkinfo.php b/www/templates/linkinfo.php index d819330..84089c3 100644 --- a/www/templates/linkinfo.php +++ b/www/templates/linkinfo.php @@ -41,6 +41,9 @@