Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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