Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Tracking.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace SCF\Additionals;
  3. use SCF\Core\Database;
  4. class Tracking
  5. {
  6. private $_db;
  7. private $currentUserIp;
  8. private $currentUserAgent;
  9. private $currentUserReferer;
  10. private $trackingTarget;
  11. public function __construct(Database $db)
  12. {
  13. $this->_db = $db;
  14. }
  15. /**
  16. * @param mixed $currentUserIp
  17. */
  18. public function setCurrentUserIp($currentUserIp)
  19. {
  20. $this->currentUserIp = $currentUserIp;
  21. }
  22. /**
  23. * @param mixed $currentUserAgent
  24. */
  25. public function setCurrentUserAgent($currentUserAgent)
  26. {
  27. $this->currentUserAgent = $currentUserAgent;
  28. }
  29. /**
  30. * @param mixed $currentUserReferer
  31. */
  32. public function setCurrentUserReferer($currentUserReferer)
  33. {
  34. $this->currentUserReferer = $currentUserReferer;
  35. }
  36. /**
  37. * @return mixed
  38. */
  39. public function getCurrentUserIp()
  40. {
  41. return $this->currentUserIp;
  42. }
  43. /**
  44. * @return mixed
  45. */
  46. public function getCurrentUserAgent()
  47. {
  48. return $this->currentUserAgent;
  49. }
  50. /**
  51. * @return mixed
  52. */
  53. public function getCurrentUserReferer()
  54. {
  55. return $this->currentUserReferer;
  56. }
  57. public function checkUniqueUser()
  58. {
  59. $this->_db->query("SELECT ip_adress, `timestamp` FROM sks_unique_user WHERE ip_adress = '{$this->getCurrentUserIp()}' ORDER BY `timestamp` DESC LIMIT 1");
  60. $result = $this->_db->single();
  61. $trackedDate = date("Y-m-d", $result['timestamp']);
  62. $currentDate = date("Y-m-d", time());
  63. //echo $trackedDate . ' - ' . $currentDate;
  64. if ($trackedDate == $currentDate) {
  65. //echo 'Du warst heute um ' . date("H:i:s", $result['timestamp']) . ' Uhr schon einmal hier!';
  66. } else {
  67. //echo 'different Dates visit';
  68. $this->_db->query("INSERT INTO sks_unique_user (`ip_adress`, `user_agent`, `referrer`, `timestamp`) VALUES
  69. (:ip, :userAgent, :userReferer, :timeValue)");
  70. $this->_db->bind(':ip', $this->getCurrentUserIp());
  71. $this->_db->bind(':userAgent', $this->getCurrentUserAgent());
  72. $this->_db->bind(':userReferer', $this->getCurrentUserReferer());
  73. $this->_db->bind(':timeValue', time());
  74. $this->_db->execute();
  75. }
  76. }
  77. /**
  78. * @param mixed $trackingTarget
  79. */
  80. public function setTrackingTarget($trackingTarget)
  81. {
  82. $this->trackingTarget = $trackingTarget;
  83. }
  84. /**
  85. * @return mixed
  86. */
  87. public function getTrackingTarget()
  88. {
  89. return $this->trackingTarget;
  90. }
  91. public function saveTrackingInDb($target, $dlVersion)
  92. {
  93. $tmpTarget = $target;
  94. $tmpDlVersion = $dlVersion;
  95. $timestamp = time();
  96. if ($tmpTarget == 'download') {
  97. try {
  98. $this->_db->query("INSERT INTO `sks_unique_dls` (ip_adress, timestamp, user_agent, dl_version)
  99. VALUES ('{$this->getCurrentUserIp()}', '{$timestamp}', '{$this->getCurrentUserAgent()}', '{$tmpDlVersion}')");
  100. $this->_db->execute();
  101. } catch (\PDOException $e) {
  102. echo $e->getMessage();
  103. }
  104. }
  105. }
  106. }