Db
6 years ago
Handler
6 years ago
TableLogAction
6 years ago
Visit
6 years ago
Action.php
6 years ago
ActionPageview.php
6 years ago
Cache.php
6 years ago
Db.php
6 years ago
Failures.php
6 years ago
FingerprintSalt.php
6 years ago
GoalManager.php
6 years ago
Handler.php
6 years ago
IgnoreCookie.php
6 years ago
LogTable.php
6 years ago
Model.php
6 years ago
PageUrl.php
6 years ago
Request.php
5 years ago
RequestProcessor.php
6 years ago
RequestSet.php
6 years ago
Response.php
6 years ago
ScheduledTasksRunner.php
6 years ago
Settings.php
5 years ago
TableLogAction.php
6 years ago
TrackerCodeGenerator.php
6 years ago
TrackerConfig.php
6 years ago
Visit.php
5 years ago
VisitExcluded.php
6 years ago
VisitInterface.php
6 years ago
Visitor.php
6 years ago
VisitorNotFoundInDb.php
6 years ago
VisitorRecognizer.php
6 years ago
IgnoreCookie.php
87 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Piwik - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * |
| 8 | */ |
| 9 | namespace Piwik\Tracker; |
| 10 | |
| 11 | use Piwik\Config; |
| 12 | use Piwik\Cookie; |
| 13 | use Piwik\ProxyHttp; |
| 14 | |
| 15 | /** |
| 16 | * Tracking cookies. |
| 17 | * |
| 18 | */ |
| 19 | class IgnoreCookie |
| 20 | { |
| 21 | /** |
| 22 | * Get tracking cookie |
| 23 | * |
| 24 | * @return Cookie |
| 25 | */ |
| 26 | private static function getTrackingCookie() |
| 27 | { |
| 28 | $cookie_name = @Config::getInstance()->Tracker['cookie_name']; |
| 29 | $cookie_path = @Config::getInstance()->Tracker['cookie_path']; |
| 30 | |
| 31 | return new Cookie($cookie_name, null, $cookie_path); |
| 32 | } |
| 33 | |
| 34 | public static function deleteThirdPartyCookieUIDIfExists() |
| 35 | { |
| 36 | $trackingCookie = self::getTrackingCookie(); |
| 37 | if ($trackingCookie->isCookieFound()) { |
| 38 | $trackingCookie->delete(); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get ignore (visit) cookie |
| 44 | * |
| 45 | * @return Cookie |
| 46 | */ |
| 47 | public static function getIgnoreCookie() |
| 48 | { |
| 49 | $cookie_name = @Config::getInstance()->Tracker['ignore_visits_cookie_name']; |
| 50 | $cookie_path = @Config::getInstance()->Tracker['cookie_path']; |
| 51 | |
| 52 | return new Cookie($cookie_name, null, $cookie_path); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Set ignore (visit) cookie or deletes it if already present |
| 57 | */ |
| 58 | public static function setIgnoreCookie() |
| 59 | { |
| 60 | $ignoreCookie = self::getIgnoreCookie(); |
| 61 | if ($ignoreCookie->isCookieFound()) { |
| 62 | $ignoreCookie->delete(); |
| 63 | } else { |
| 64 | $ignoreCookie->set('ignore', '*'); |
| 65 | if (ProxyHttp::isHttps()) { |
| 66 | $ignoreCookie->setSecure(true); |
| 67 | $ignoreCookie->save('None'); |
| 68 | } else { |
| 69 | $ignoreCookie->save('Lax'); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | self::deleteThirdPartyCookieUIDIfExists(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns true if ignore (visit) cookie is present |
| 78 | * |
| 79 | * @return bool True if ignore cookie found; false otherwise |
| 80 | */ |
| 81 | public static function isIgnoreCookieFound() |
| 82 | { |
| 83 | $cookie = self::getIgnoreCookie(); |
| 84 | return $cookie->isCookieFound() && $cookie->get('ignore') === '*'; |
| 85 | } |
| 86 | } |
| 87 |