PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,48 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Tracker\Visit;
use Piwik\Piwik;
use Piwik\Tracker\Visit;
use Piwik\Tracker\VisitInterface;
use Exception;
class Factory
{
/**
* Returns the Tracker_Visit object.
* This method can be overwritten to use a different Tracker_Visit object
*
* @throws Exception
* @return \Piwik\Tracker\Visit
*/
public static function make()
{
$visit = null;
/**
* Triggered before a new **visit tracking object** is created. Subscribers to this
* event can force the use of a custom visit tracking object that extends from
* {@link Piwik\Tracker\VisitInterface}.
*
* @param \Piwik\Tracker\VisitInterface &$visit Initialized to null, but can be set to
* a new visit object. If it isn't modified
* Piwik uses the default class.
*/
Piwik::postEvent('Tracker.makeNewVisitObject', array(&$visit));
if (!isset($visit)) {
$visit = new Visit();
} elseif (!($visit instanceof VisitInterface)) {
throw new Exception("The Visit object set in the plugin must implement VisitInterface");
}
return $visit;
}
}

View File

@ -0,0 +1,87 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Tracker\Visit;
use Piwik\Cache;
use Piwik\Common;
use Piwik\Option;
use Piwik\Tracker\Request;
/**
* Filters out tracking requests issued by spammers.
*/
class ReferrerSpamFilter
{
const OPTION_STORAGE_NAME = 'referrer_spam_blacklist';
/**
* @var string[]
*/
private $spammerList;
/**
* Check if the request is from a known spammer host.
*
* @param Request $request
* @return bool
*/
public function isSpam(Request $request)
{
$spammers = $this->getSpammerListFromCache();
$referrerUrl = $request->getParam('urlref');
foreach ($spammers as $spammerHost) {
if (stripos($referrerUrl, $spammerHost) !== false) {
Common::printDebug('Referrer URL is a known spam: ' . $spammerHost);
return true;
}
}
return false;
}
private function getSpammerListFromCache()
{
$cache = Cache::getEagerCache();
$cacheId = 'ReferrerSpamFilter-' . self::OPTION_STORAGE_NAME;
if ($cache->contains($cacheId)) {
$list = $cache->fetch($cacheId);
} else {
$list = $this->loadSpammerList();
$cache->save($cacheId, $list);
}
if(!is_array($list)) {
Common::printDebug('Warning: could not read list of spammers from cache.');
return array();
}
return $list;
}
private function loadSpammerList()
{
if ($this->spammerList !== null) {
return $this->spammerList;
}
// Read first from the auto-updated list in database
$list = Option::get(self::OPTION_STORAGE_NAME);
if ($list) {
$this->spammerList = Common::safe_unserialize($list);
} else {
// Fallback to reading the bundled list
$file = PIWIK_VENDOR_PATH . '/matomo/referrer-spam-blacklist/spammers.txt';
$this->spammerList = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
}
return $this->spammerList;
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tracker\Visit;
/**
* Holds temporary data for tracking requests.
*/
class VisitProperties
{
/**
* Information about the current visit. This array holds the column values that will be inserted or updated
* in the `log_visit` table, or the values for the last known visit of the current visitor.
*
* @var array
*/
private $visitInfo = array();
/**
* Returns a visit property, or `null` if none is set.
*
* @param string $name The property name.
* @return mixed
*/
public function getProperty($name)
{
return isset($this->visitInfo[$name]) ? $this->visitInfo[$name] : null;
}
/**
* Returns all visit properties by reference.
*
* @return array
*/
public function &getProperties()
{
return $this->visitInfo;
}
/**
* Sets a visit property.
*
* @param string $name The property name.
* @param mixed $value The property value.
*/
public function setProperty($name, $value)
{
$this->visitInfo[$name] = $value;
}
/**
* Unsets all visit properties.
*/
public function clearProperties()
{
$this->visitInfo = array();
}
/**
* Sets all visit properties.
*
* @param array $properties
*/
public function setProperties($properties)
{
$this->visitInfo = $properties;
}
}