123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
-
- namespace SCF\Additionals;
-
- use SCF\Core\Database;
-
- class Tracking
- {
- /**
- * @var Database
- */
- private $_db;
-
- /**
- * @var string
- */
- private $currentUserIp;
-
- /**
- * @var string
- */
- private $currentUserAgent;
-
- /**
- * @var string
- */
- private $currentUserReferer;
-
- /**
- * @var string
- */
- private $trackingTarget;
-
- /**
- * Tracking constructor.
- * @param Database $db
- */
- public function __construct(Database $db)
- {
- $this->_db = $db;
- }
-
- /**
- * @param mixed $currentUserIp
- */
- public function setCurrentUserIp($currentUserIp)
- {
- $this->currentUserIp = $currentUserIp;
- }
-
- /**
- * @param mixed $currentUserAgent
- */
- public function setCurrentUserAgent($currentUserAgent)
- {
- $this->currentUserAgent = $currentUserAgent;
- }
-
- /**
- * @param mixed $currentUserReferer
- */
- public function setCurrentUserReferer($currentUserReferer)
- {
- $this->currentUserReferer = $currentUserReferer;
- }
-
- /**
- * @return mixed
- */
- public function getCurrentUserIp()
- {
- return $this->currentUserIp;
- }
-
- /**
- * @return mixed
- */
- public function getCurrentUserAgent()
- {
- return $this->currentUserAgent;
- }
-
- /**
- * @return mixed
- */
- public function getCurrentUserReferer()
- {
- return $this->currentUserReferer;
- }
-
- /**
- * Check Users to track them only once a day
- */
- public function checkUniqueUser()
- {
- $this->_db->query("SELECT ip_adress, `timestamp` FROM sks_unique_user WHERE ip_adress = '{$this->getCurrentUserIp()}' ORDER BY `timestamp` DESC LIMIT 1");
- $result = $this->_db->single();
- $trackedDate = date("Y-m-d", $result['timestamp']);
- $currentDate = date("Y-m-d", time());
- //echo $trackedDate . ' - ' . $currentDate;
- if ($trackedDate == $currentDate) {
- //echo 'Du warst heute um ' . date("H:i:s", $result['timestamp']) . ' Uhr schon einmal hier!';
- } else {
- //echo 'different Dates visit';
- $this->_db->query("INSERT INTO sks_unique_user (`ip_adress`, `user_agent`, `referrer`, `timestamp`) VALUES
- (:ip, :userAgent, :userReferer, :timeValue)");
- $this->_db->bind(':ip', $this->getCurrentUserIp());
- $this->_db->bind(':userAgent', $this->getCurrentUserAgent());
- $this->_db->bind(':userReferer', $this->getCurrentUserReferer());
- $this->_db->bind(':timeValue', time());
- $this->_db->execute();
- }
-
- }
-
- /**
- * @param mixed $trackingTarget
- */
- public function setTrackingTarget($trackingTarget)
- {
- $this->trackingTarget = $trackingTarget;
- }
-
- /**
- * @return mixed
- */
- public function getTrackingTarget()
- {
- return $this->trackingTarget;
- }
-
- /**
- * @param $target
- * @param $dlVersion
- */
- public function saveTrackingInDb($target, $dlVersion)
- {
- $tmpTarget = $target;
- $tmpDlVersion = substr($dlVersion, 1);
- $timestamp = time();
- if ($tmpTarget == 'download') {
- try {
- $this->_db->query("INSERT INTO `sks_unique_dls` (ip_adress, timestamp, user_agent, dl_version)
- VALUES ('{$this->getCurrentUserIp()}', '{$timestamp}', '{$this->getCurrentUserAgent()}', '{$tmpDlVersion}')");
- $this->_db->execute();
- } catch (\PDOException $e) {
- echo $e->getMessage();
- }
- }
-
- }
- }
|