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