id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
209,800 | matomo-org/matomo | core/Updater/Migration/Db/Factory.php | Factory.addIndex | public function addIndex($table, $columnNames, $indexName = '')
{
$table = $this->prefixTable($table);
if (!is_array($columnNames)) {
$columnNames = array($columnNames);
}
return $this->container->make('Piwik\Updater\Migration\Db\AddIndex', array(
'table' => $table, 'columnNames' => $columnNames, 'indexName' => $indexName
));
} | php | public function addIndex($table, $columnNames, $indexName = '')
{
$table = $this->prefixTable($table);
if (!is_array($columnNames)) {
$columnNames = array($columnNames);
}
return $this->container->make('Piwik\Updater\Migration\Db\AddIndex', array(
'table' => $table, 'columnNames' => $columnNames, 'indexName' => $indexName
));
} | [
"public",
"function",
"addIndex",
"(",
"$",
"table",
",",
"$",
"columnNames",
",",
"$",
"indexName",
"=",
"''",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"prefixTable",
"(",
"$",
"table",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columnNames",
")",
")",
"{",
"$",
"columnNames",
"=",
"array",
"(",
"$",
"columnNames",
")",
";",
"}",
"return",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"'Piwik\\Updater\\Migration\\Db\\AddIndex'",
",",
"array",
"(",
"'table'",
"=>",
"$",
"table",
",",
"'columnNames'",
"=>",
"$",
"columnNames",
",",
"'indexName'",
"=>",
"$",
"indexName",
")",
")",
";",
"}"
] | Adds an index to an existing database table.
This is equivalent to an `ADD INDEX indexname (column_name_1, column_name_2)` in SQL.
It adds a normal index, no unique index.
Note: If no indexName is specified, it will automatically generate a name for this index if which is basically:
`'index_' . implode('_', $columnNames)`. If a column name is eg `column1(10)` then only the first part (`column1`)
will be used. For example when using columns `array('column1', 'column2(10)')` then the index name will be
`index_column1_column2`.
@param string $table Unprefixed database table name, eg 'log_visit'.
@param string[]|string $columnNames Either one or multiple column names, eg array('column_name_1', 'column_name_2').
A column name can be appended by a number bracket eg "column_name_1(10)".
@param string $indexName If specified, the given index name will be used instead of the automatically generated one.
@return AddIndex | [
"Adds",
"an",
"index",
"to",
"an",
"existing",
"database",
"table",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Updater/Migration/Db/Factory.php#L255-L266 |
209,801 | matomo-org/matomo | core/Updater/Migration/Db/Factory.php | Factory.addPrimaryKey | public function addPrimaryKey($table, $columnNames)
{
$table = $this->prefixTable($table);
if (!is_array($columnNames)) {
$columnNames = array($columnNames);
}
return $this->container->make('Piwik\Updater\Migration\Db\AddPrimaryKey', array(
'table' => $table, 'columnNames' => $columnNames
));
} | php | public function addPrimaryKey($table, $columnNames)
{
$table = $this->prefixTable($table);
if (!is_array($columnNames)) {
$columnNames = array($columnNames);
}
return $this->container->make('Piwik\Updater\Migration\Db\AddPrimaryKey', array(
'table' => $table, 'columnNames' => $columnNames
));
} | [
"public",
"function",
"addPrimaryKey",
"(",
"$",
"table",
",",
"$",
"columnNames",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"prefixTable",
"(",
"$",
"table",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columnNames",
")",
")",
"{",
"$",
"columnNames",
"=",
"array",
"(",
"$",
"columnNames",
")",
";",
"}",
"return",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"'Piwik\\Updater\\Migration\\Db\\AddPrimaryKey'",
",",
"array",
"(",
"'table'",
"=>",
"$",
"table",
",",
"'columnNames'",
"=>",
"$",
"columnNames",
")",
")",
";",
"}"
] | Adds a primary key to an existing database table.
This is equivalent to an `ADD PRIMARY KEY(column_name_1, column_name_2)` in SQL.
@param string $table Unprefixed database table name, eg 'log_visit'.
@param string[]|string $columnNames Either one or multiple column names, eg array('column_name_1', 'column_name_2')
@return AddPrimaryKey | [
"Adds",
"a",
"primary",
"key",
"to",
"an",
"existing",
"database",
"table",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Updater/Migration/Db/Factory.php#L337-L347 |
209,802 | matomo-org/matomo | plugins/Proxy/Controller.php | Controller.redirect | public function redirect()
{
$url = Common::getRequestVar('url', '', 'string', $_GET);
if (!UrlHelper::isLookLikeUrl($url)) {
die('Please check the &url= parameter: it should to be a valid URL');
}
// validate referrer
$referrer = Url::getReferrer();
if (empty($referrer) || !Url::isLocalUrl($referrer)) {
die('Invalid Referrer detected - This means that your web browser is not sending the "Referrer URL" which is
required to proceed with the redirect. Verify your browser settings and add-ons, to check why your browser
is not sending this referrer.
<br/><br/>You can access the page at: ' . $url);
}
// mask visits to *.piwik.org
if (!self::isPiwikUrl($url)) {
Piwik::checkUserHasSomeViewAccess();
}
Common::sendHeader('Content-Type: text/html; charset=utf-8');
echo '<html><head><meta http-equiv="refresh" content="0;url=' . $url . '" /></head></html>';
exit;
} | php | public function redirect()
{
$url = Common::getRequestVar('url', '', 'string', $_GET);
if (!UrlHelper::isLookLikeUrl($url)) {
die('Please check the &url= parameter: it should to be a valid URL');
}
// validate referrer
$referrer = Url::getReferrer();
if (empty($referrer) || !Url::isLocalUrl($referrer)) {
die('Invalid Referrer detected - This means that your web browser is not sending the "Referrer URL" which is
required to proceed with the redirect. Verify your browser settings and add-ons, to check why your browser
is not sending this referrer.
<br/><br/>You can access the page at: ' . $url);
}
// mask visits to *.piwik.org
if (!self::isPiwikUrl($url)) {
Piwik::checkUserHasSomeViewAccess();
}
Common::sendHeader('Content-Type: text/html; charset=utf-8');
echo '<html><head><meta http-equiv="refresh" content="0;url=' . $url . '" /></head></html>';
exit;
} | [
"public",
"function",
"redirect",
"(",
")",
"{",
"$",
"url",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'url'",
",",
"''",
",",
"'string'",
",",
"$",
"_GET",
")",
";",
"if",
"(",
"!",
"UrlHelper",
"::",
"isLookLikeUrl",
"(",
"$",
"url",
")",
")",
"{",
"die",
"(",
"'Please check the &url= parameter: it should to be a valid URL'",
")",
";",
"}",
"// validate referrer",
"$",
"referrer",
"=",
"Url",
"::",
"getReferrer",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"referrer",
")",
"||",
"!",
"Url",
"::",
"isLocalUrl",
"(",
"$",
"referrer",
")",
")",
"{",
"die",
"(",
"'Invalid Referrer detected - This means that your web browser is not sending the \"Referrer URL\" which is\n\t\t\t\trequired to proceed with the redirect. Verify your browser settings and add-ons, to check why your browser\n\t\t\t\t is not sending this referrer.\n\n\t\t\t\t<br/><br/>You can access the page at: '",
".",
"$",
"url",
")",
";",
"}",
"// mask visits to *.piwik.org",
"if",
"(",
"!",
"self",
"::",
"isPiwikUrl",
"(",
"$",
"url",
")",
")",
"{",
"Piwik",
"::",
"checkUserHasSomeViewAccess",
"(",
")",
";",
"}",
"Common",
"::",
"sendHeader",
"(",
"'Content-Type: text/html; charset=utf-8'",
")",
";",
"echo",
"'<html><head><meta http-equiv=\"refresh\" content=\"0;url='",
".",
"$",
"url",
".",
"'\" /></head></html>'",
";",
"exit",
";",
"}"
] | Output redirection page instead of linking directly to avoid
exposing the referrer on the Piwik demo.
@internal param string $url (via $_GET)
@deprecated @since 3.6.0 | [
"Output",
"redirection",
"page",
"instead",
"of",
"linking",
"directly",
"to",
"avoid",
"exposing",
"the",
"referrer",
"on",
"the",
"Piwik",
"demo",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Proxy/Controller.php#L79-L103 |
209,803 | matomo-org/matomo | plugins/UserCountry/LocationProvider/GeoIp.php | GeoIp.completeLocationResult | public function completeLocationResult(&$location)
{
parent::completeLocationResult($location);
// set region name if region code is set
if (empty($location[self::REGION_NAME_KEY])
&& !empty($location[self::REGION_CODE_KEY])
&& !empty($location[self::COUNTRY_CODE_KEY])
) {
$countryCode = $location[self::COUNTRY_CODE_KEY];
$regionCode = (string)$location[self::REGION_CODE_KEY];
$location[self::REGION_NAME_KEY] = self::getRegionNameFromCodes($countryCode, $regionCode);
}
} | php | public function completeLocationResult(&$location)
{
parent::completeLocationResult($location);
// set region name if region code is set
if (empty($location[self::REGION_NAME_KEY])
&& !empty($location[self::REGION_CODE_KEY])
&& !empty($location[self::COUNTRY_CODE_KEY])
) {
$countryCode = $location[self::COUNTRY_CODE_KEY];
$regionCode = (string)$location[self::REGION_CODE_KEY];
$location[self::REGION_NAME_KEY] = self::getRegionNameFromCodes($countryCode, $regionCode);
}
} | [
"public",
"function",
"completeLocationResult",
"(",
"&",
"$",
"location",
")",
"{",
"parent",
"::",
"completeLocationResult",
"(",
"$",
"location",
")",
";",
"// set region name if region code is set",
"if",
"(",
"empty",
"(",
"$",
"location",
"[",
"self",
"::",
"REGION_NAME_KEY",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"location",
"[",
"self",
"::",
"REGION_CODE_KEY",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"location",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
")",
")",
"{",
"$",
"countryCode",
"=",
"$",
"location",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
";",
"$",
"regionCode",
"=",
"(",
"string",
")",
"$",
"location",
"[",
"self",
"::",
"REGION_CODE_KEY",
"]",
";",
"$",
"location",
"[",
"self",
"::",
"REGION_NAME_KEY",
"]",
"=",
"self",
"::",
"getRegionNameFromCodes",
"(",
"$",
"countryCode",
",",
"$",
"regionCode",
")",
";",
"}",
"}"
] | Attempts to fill in some missing information in a GeoIP location.
This method will call LocationProvider::completeLocationResult and then
try to set the region name of the location if the country code & region
code are set.
@param array $location The location information to modify. | [
"Attempts",
"to",
"fill",
"in",
"some",
"missing",
"information",
"in",
"a",
"GeoIP",
"location",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/GeoIp.php#L56-L69 |
209,804 | matomo-org/matomo | plugins/UserCountry/LocationProvider/GeoIp.php | GeoIp.getRegionNames | public static function getRegionNames()
{
if (is_null(self::$regionNames)) {
$GEOIP_REGION_NAME = array();
require_once PIWIK_INCLUDE_PATH . '/libs/MaxMindGeoIP/geoipregionvars.php';
self::$regionNames = $GEOIP_REGION_NAME;
}
return self::$regionNames;
} | php | public static function getRegionNames()
{
if (is_null(self::$regionNames)) {
$GEOIP_REGION_NAME = array();
require_once PIWIK_INCLUDE_PATH . '/libs/MaxMindGeoIP/geoipregionvars.php';
self::$regionNames = $GEOIP_REGION_NAME;
}
return self::$regionNames;
} | [
"public",
"static",
"function",
"getRegionNames",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"regionNames",
")",
")",
"{",
"$",
"GEOIP_REGION_NAME",
"=",
"array",
"(",
")",
";",
"require_once",
"PIWIK_INCLUDE_PATH",
".",
"'/libs/MaxMindGeoIP/geoipregionvars.php'",
";",
"self",
"::",
"$",
"regionNames",
"=",
"$",
"GEOIP_REGION_NAME",
";",
"}",
"return",
"self",
"::",
"$",
"regionNames",
";",
"}"
] | Returns an array of region names mapped by country code & region code.
@return array | [
"Returns",
"an",
"array",
"of",
"region",
"names",
"mapped",
"by",
"country",
"code",
"&",
"region",
"code",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/GeoIp.php#L166-L175 |
209,805 | matomo-org/matomo | plugins/UserCountry/LocationProvider/GeoIp.php | GeoIp.getPathToGeoIpDatabase | public static function getPathToGeoIpDatabase($possibleFileNames)
{
foreach ($possibleFileNames as $filename) {
$path = self::getPathForGeoIpDatabase($filename);
if (file_exists($path)) {
return $path;
}
}
return false;
} | php | public static function getPathToGeoIpDatabase($possibleFileNames)
{
foreach ($possibleFileNames as $filename) {
$path = self::getPathForGeoIpDatabase($filename);
if (file_exists($path)) {
return $path;
}
}
return false;
} | [
"public",
"static",
"function",
"getPathToGeoIpDatabase",
"(",
"$",
"possibleFileNames",
")",
"{",
"foreach",
"(",
"$",
"possibleFileNames",
"as",
"$",
"filename",
")",
"{",
"$",
"path",
"=",
"self",
"::",
"getPathForGeoIpDatabase",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"path",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns the path of an existing GeoIP database or false if none can be found.
@param array $possibleFileNames The list of possible file names for the GeoIP database.
@return string|false | [
"Returns",
"the",
"path",
"of",
"an",
"existing",
"GeoIP",
"database",
"or",
"false",
"if",
"none",
"can",
"be",
"found",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/GeoIp.php#L183-L192 |
209,806 | matomo-org/matomo | plugins/UserCountry/LocationProvider/GeoIp.php | GeoIp.isDatabaseInstalled | public static function isDatabaseInstalled()
{
return self::getPathToGeoIpDatabase(self::$dbNames['loc'])
|| self::getPathToGeoIpDatabase(self::$dbNames['isp'])
|| self::getPathToGeoIpDatabase(self::$dbNames['org']);
} | php | public static function isDatabaseInstalled()
{
return self::getPathToGeoIpDatabase(self::$dbNames['loc'])
|| self::getPathToGeoIpDatabase(self::$dbNames['isp'])
|| self::getPathToGeoIpDatabase(self::$dbNames['org']);
} | [
"public",
"static",
"function",
"isDatabaseInstalled",
"(",
")",
"{",
"return",
"self",
"::",
"getPathToGeoIpDatabase",
"(",
"self",
"::",
"$",
"dbNames",
"[",
"'loc'",
"]",
")",
"||",
"self",
"::",
"getPathToGeoIpDatabase",
"(",
"self",
"::",
"$",
"dbNames",
"[",
"'isp'",
"]",
")",
"||",
"self",
"::",
"getPathToGeoIpDatabase",
"(",
"self",
"::",
"$",
"dbNames",
"[",
"'org'",
"]",
")",
";",
"}"
] | Returns true if there is a GeoIP database in the 'misc' directory.
@return bool | [
"Returns",
"true",
"if",
"there",
"is",
"a",
"GeoIP",
"database",
"in",
"the",
"misc",
"directory",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/GeoIp.php#L228-L233 |
209,807 | matomo-org/matomo | plugins/CoreAdminHome/Controller.php | Controller.trackingCodeGenerator | public function trackingCodeGenerator()
{
Piwik::checkUserHasSomeViewAccess();
$view = new View('@CoreAdminHome/trackingCodeGenerator');
$this->setBasicVariablesView($view);
$view->topMenu = MenuTop::getInstance()->getMenu();
$viewableIdSites = APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess();
$defaultIdSite = reset($viewableIdSites);
$view->idSite = $this->idSite ?: $defaultIdSite;
if ($view->idSite) {
try {
$view->siteName = Site::getNameFor($view->idSite);
} catch (Exception $e) {
// ignore if site no longer exists
}
}
$view->defaultReportSiteName = Site::getNameFor($view->idSite);
$view->defaultSiteRevenue = Site::getCurrencySymbolFor($view->idSite);
$view->maxCustomVariables = CustomVariables::getNumUsableCustomVariables();
$view->defaultSite = array('id' => $view->idSite, 'name' => $view->defaultReportSiteName);
$allUrls = APISitesManager::getInstance()->getSiteUrlsFromId($view->idSite);
if (isset($allUrls[1])) {
$aliasUrl = $allUrls[1];
} else {
$aliasUrl = 'x.domain.com';
}
$view->defaultReportSiteAlias = $aliasUrl;
$mainUrl = Site::getMainUrlFor($view->idSite);
$view->defaultReportSiteDomain = @parse_url($mainUrl, PHP_URL_HOST);
$dntChecker = new DoNotTrackHeaderChecker();
$view->serverSideDoNotTrackEnabled = $dntChecker->isActive();
return $view->render();
} | php | public function trackingCodeGenerator()
{
Piwik::checkUserHasSomeViewAccess();
$view = new View('@CoreAdminHome/trackingCodeGenerator');
$this->setBasicVariablesView($view);
$view->topMenu = MenuTop::getInstance()->getMenu();
$viewableIdSites = APISitesManager::getInstance()->getSitesIdWithAtLeastViewAccess();
$defaultIdSite = reset($viewableIdSites);
$view->idSite = $this->idSite ?: $defaultIdSite;
if ($view->idSite) {
try {
$view->siteName = Site::getNameFor($view->idSite);
} catch (Exception $e) {
// ignore if site no longer exists
}
}
$view->defaultReportSiteName = Site::getNameFor($view->idSite);
$view->defaultSiteRevenue = Site::getCurrencySymbolFor($view->idSite);
$view->maxCustomVariables = CustomVariables::getNumUsableCustomVariables();
$view->defaultSite = array('id' => $view->idSite, 'name' => $view->defaultReportSiteName);
$allUrls = APISitesManager::getInstance()->getSiteUrlsFromId($view->idSite);
if (isset($allUrls[1])) {
$aliasUrl = $allUrls[1];
} else {
$aliasUrl = 'x.domain.com';
}
$view->defaultReportSiteAlias = $aliasUrl;
$mainUrl = Site::getMainUrlFor($view->idSite);
$view->defaultReportSiteDomain = @parse_url($mainUrl, PHP_URL_HOST);
$dntChecker = new DoNotTrackHeaderChecker();
$view->serverSideDoNotTrackEnabled = $dntChecker->isActive();
return $view->render();
} | [
"public",
"function",
"trackingCodeGenerator",
"(",
")",
"{",
"Piwik",
"::",
"checkUserHasSomeViewAccess",
"(",
")",
";",
"$",
"view",
"=",
"new",
"View",
"(",
"'@CoreAdminHome/trackingCodeGenerator'",
")",
";",
"$",
"this",
"->",
"setBasicVariablesView",
"(",
"$",
"view",
")",
";",
"$",
"view",
"->",
"topMenu",
"=",
"MenuTop",
"::",
"getInstance",
"(",
")",
"->",
"getMenu",
"(",
")",
";",
"$",
"viewableIdSites",
"=",
"APISitesManager",
"::",
"getInstance",
"(",
")",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
";",
"$",
"defaultIdSite",
"=",
"reset",
"(",
"$",
"viewableIdSites",
")",
";",
"$",
"view",
"->",
"idSite",
"=",
"$",
"this",
"->",
"idSite",
"?",
":",
"$",
"defaultIdSite",
";",
"if",
"(",
"$",
"view",
"->",
"idSite",
")",
"{",
"try",
"{",
"$",
"view",
"->",
"siteName",
"=",
"Site",
"::",
"getNameFor",
"(",
"$",
"view",
"->",
"idSite",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// ignore if site no longer exists",
"}",
"}",
"$",
"view",
"->",
"defaultReportSiteName",
"=",
"Site",
"::",
"getNameFor",
"(",
"$",
"view",
"->",
"idSite",
")",
";",
"$",
"view",
"->",
"defaultSiteRevenue",
"=",
"Site",
"::",
"getCurrencySymbolFor",
"(",
"$",
"view",
"->",
"idSite",
")",
";",
"$",
"view",
"->",
"maxCustomVariables",
"=",
"CustomVariables",
"::",
"getNumUsableCustomVariables",
"(",
")",
";",
"$",
"view",
"->",
"defaultSite",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"view",
"->",
"idSite",
",",
"'name'",
"=>",
"$",
"view",
"->",
"defaultReportSiteName",
")",
";",
"$",
"allUrls",
"=",
"APISitesManager",
"::",
"getInstance",
"(",
")",
"->",
"getSiteUrlsFromId",
"(",
"$",
"view",
"->",
"idSite",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"allUrls",
"[",
"1",
"]",
")",
")",
"{",
"$",
"aliasUrl",
"=",
"$",
"allUrls",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"aliasUrl",
"=",
"'x.domain.com'",
";",
"}",
"$",
"view",
"->",
"defaultReportSiteAlias",
"=",
"$",
"aliasUrl",
";",
"$",
"mainUrl",
"=",
"Site",
"::",
"getMainUrlFor",
"(",
"$",
"view",
"->",
"idSite",
")",
";",
"$",
"view",
"->",
"defaultReportSiteDomain",
"=",
"@",
"parse_url",
"(",
"$",
"mainUrl",
",",
"PHP_URL_HOST",
")",
";",
"$",
"dntChecker",
"=",
"new",
"DoNotTrackHeaderChecker",
"(",
")",
";",
"$",
"view",
"->",
"serverSideDoNotTrackEnabled",
"=",
"$",
"dntChecker",
"->",
"isActive",
"(",
")",
";",
"return",
"$",
"view",
"->",
"render",
"(",
")",
";",
"}"
] | Renders and echo's an admin page that lets users generate custom JavaScript
tracking code and custom image tracker links. | [
"Renders",
"and",
"echo",
"s",
"an",
"admin",
"page",
"that",
"lets",
"users",
"generate",
"custom",
"JavaScript",
"tracking",
"code",
"and",
"custom",
"image",
"tracker",
"links",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/CoreAdminHome/Controller.php#L173-L215 |
209,808 | matomo-org/matomo | plugins/Live/Visitor.php | Visitor.getAllVisitorDetailsInstances | public static function getAllVisitorDetailsInstances()
{
$cacheId = CacheId::pluginAware('VisitorDetails');
$cache = Cache::getTransientCache();
if (!$cache->contains($cacheId)) {
$instances = [
new VisitorDetails() // needs to be first
];
/**
* Triggered to add new visitor details that cannot be picked up by the platform automatically.
*
* **Example**
*
* public function addVisitorDetails(&$visitorDetails)
* {
* $visitorDetails[] = new CustomVisitorDetails();
* }
*
* @param VisitorDetailsAbstract[] $visitorDetails An array of visitorDetails
*/
Piwik::postEvent('Live.addVisitorDetails', array(&$instances));
foreach (self::getAllVisitorDetailsClasses() as $className) {
$instance = new $className();
if ($instance instanceof VisitorDetails) {
continue;
}
$instances[] = $instance;
}
/**
* Triggered to filter / restrict vistor details.
*
* **Example**
*
* public function filterVisitorDetails(&$visitorDetails)
* {
* foreach ($visitorDetails as $index => $visitorDetail) {
* if (strpos(get_class($visitorDetail), 'MyPluginName') !== false) {}
* unset($visitorDetails[$index]); // remove all visitor details for a specific plugin
* }
* }
* }
*
* @param VisitorDetailsAbstract[] $visitorDetails An array of visitorDetails
*/
Piwik::postEvent('Live.filterVisitorDetails', array(&$instances));
$cache->save($cacheId, $instances);
}
return $cache->fetch($cacheId);
} | php | public static function getAllVisitorDetailsInstances()
{
$cacheId = CacheId::pluginAware('VisitorDetails');
$cache = Cache::getTransientCache();
if (!$cache->contains($cacheId)) {
$instances = [
new VisitorDetails() // needs to be first
];
/**
* Triggered to add new visitor details that cannot be picked up by the platform automatically.
*
* **Example**
*
* public function addVisitorDetails(&$visitorDetails)
* {
* $visitorDetails[] = new CustomVisitorDetails();
* }
*
* @param VisitorDetailsAbstract[] $visitorDetails An array of visitorDetails
*/
Piwik::postEvent('Live.addVisitorDetails', array(&$instances));
foreach (self::getAllVisitorDetailsClasses() as $className) {
$instance = new $className();
if ($instance instanceof VisitorDetails) {
continue;
}
$instances[] = $instance;
}
/**
* Triggered to filter / restrict vistor details.
*
* **Example**
*
* public function filterVisitorDetails(&$visitorDetails)
* {
* foreach ($visitorDetails as $index => $visitorDetail) {
* if (strpos(get_class($visitorDetail), 'MyPluginName') !== false) {}
* unset($visitorDetails[$index]); // remove all visitor details for a specific plugin
* }
* }
* }
*
* @param VisitorDetailsAbstract[] $visitorDetails An array of visitorDetails
*/
Piwik::postEvent('Live.filterVisitorDetails', array(&$instances));
$cache->save($cacheId, $instances);
}
return $cache->fetch($cacheId);
} | [
"public",
"static",
"function",
"getAllVisitorDetailsInstances",
"(",
")",
"{",
"$",
"cacheId",
"=",
"CacheId",
"::",
"pluginAware",
"(",
"'VisitorDetails'",
")",
";",
"$",
"cache",
"=",
"Cache",
"::",
"getTransientCache",
"(",
")",
";",
"if",
"(",
"!",
"$",
"cache",
"->",
"contains",
"(",
"$",
"cacheId",
")",
")",
"{",
"$",
"instances",
"=",
"[",
"new",
"VisitorDetails",
"(",
")",
"// needs to be first",
"]",
";",
"/**\n * Triggered to add new visitor details that cannot be picked up by the platform automatically.\n *\n * **Example**\n *\n * public function addVisitorDetails(&$visitorDetails)\n * {\n * $visitorDetails[] = new CustomVisitorDetails();\n * }\n *\n * @param VisitorDetailsAbstract[] $visitorDetails An array of visitorDetails\n */",
"Piwik",
"::",
"postEvent",
"(",
"'Live.addVisitorDetails'",
",",
"array",
"(",
"&",
"$",
"instances",
")",
")",
";",
"foreach",
"(",
"self",
"::",
"getAllVisitorDetailsClasses",
"(",
")",
"as",
"$",
"className",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
")",
";",
"if",
"(",
"$",
"instance",
"instanceof",
"VisitorDetails",
")",
"{",
"continue",
";",
"}",
"$",
"instances",
"[",
"]",
"=",
"$",
"instance",
";",
"}",
"/**\n * Triggered to filter / restrict vistor details.\n *\n * **Example**\n *\n * public function filterVisitorDetails(&$visitorDetails)\n * {\n * foreach ($visitorDetails as $index => $visitorDetail) {\n * if (strpos(get_class($visitorDetail), 'MyPluginName') !== false) {}\n * unset($visitorDetails[$index]); // remove all visitor details for a specific plugin\n * }\n * }\n * }\n *\n * @param VisitorDetailsAbstract[] $visitorDetails An array of visitorDetails\n */",
"Piwik",
"::",
"postEvent",
"(",
"'Live.filterVisitorDetails'",
",",
"array",
"(",
"&",
"$",
"instances",
")",
")",
";",
"$",
"cache",
"->",
"save",
"(",
"$",
"cacheId",
",",
"$",
"instances",
")",
";",
"}",
"return",
"$",
"cache",
"->",
"fetch",
"(",
"$",
"cacheId",
")",
";",
"}"
] | Returns all available visitor details instances
@return VisitorDetailsAbstract[]
@throws \Exception | [
"Returns",
"all",
"available",
"visitor",
"details",
"instances"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Live/Visitor.php#L71-L127 |
209,809 | matomo-org/matomo | libs/Zend/Validate/File/Md5.php | Zend_Validate_File_Md5.setHash | public function setHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'md5';
parent::setHash($options);
return $this;
} | php | public function setHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'md5';
parent::setHash($options);
return $this;
} | [
"public",
"function",
"setHash",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"(",
"array",
")",
"$",
"options",
";",
"}",
"$",
"options",
"[",
"'algorithm'",
"]",
"=",
"'md5'",
";",
"parent",
"::",
"setHash",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the md5 hash for one or multiple files
@param string|array $options
@param string $algorithm (Deprecated) Algorithm to use, fixed to md5
@return Zend_Validate_File_Hash Provides a fluent interface | [
"Sets",
"the",
"md5",
"hash",
"for",
"one",
"or",
"multiple",
"files"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Validate/File/Md5.php#L99-L108 |
209,810 | matomo-org/matomo | libs/Zend/Validate/File/Md5.php | Zend_Validate_File_Md5.addHash | public function addHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'md5';
parent::addHash($options);
return $this;
} | php | public function addHash($options)
{
if (!is_array($options)) {
$options = (array) $options;
}
$options['algorithm'] = 'md5';
parent::addHash($options);
return $this;
} | [
"public",
"function",
"addHash",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"(",
"array",
")",
"$",
"options",
";",
"}",
"$",
"options",
"[",
"'algorithm'",
"]",
"=",
"'md5'",
";",
"parent",
"::",
"addHash",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds the md5 hash for one or multiple files
@param string|array $options
@param string $algorithm (Deprecated) Algorithm to use, fixed to md5
@return Zend_Validate_File_Hash Provides a fluent interface | [
"Adds",
"the",
"md5",
"hash",
"for",
"one",
"or",
"multiple",
"files"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Validate/File/Md5.php#L129-L138 |
209,811 | matomo-org/matomo | plugins/UserCountry/Controller.php | Controller.downloadFreeGeoIPDB | public function downloadFreeGeoIPDB()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($this->isGeoIp2Enabled()) {
return $this->downloadFreeGeoIP2DB();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
$outputPath = GeoIp::getPathForGeoIpDatabase('GeoIPCity.dat') . '.gz';
try {
$result = Http::downloadChunk(
$url = GeoIp::GEO_LITE_URL,
$outputPath,
$continue = Common::getRequestVar('continue', true, 'int')
);
// if the file is done
if ($result['current_size'] >= $result['expected_file_size']) {
GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true);
// setup the auto updater
GeoIPAutoUpdater::setUpdaterOptions(array(
'loc' => GeoIp::GEO_LITE_URL,
'period' => GeoIPAutoUpdater::SCHEDULE_PERIOD_MONTHLY,
));
// make sure to echo out the geoip updater management screen
$result['settings'] = GeoIPAutoUpdater::getConfiguredUrls();
}
return json_encode($result);
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | php | public function downloadFreeGeoIPDB()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($this->isGeoIp2Enabled()) {
return $this->downloadFreeGeoIP2DB();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
$outputPath = GeoIp::getPathForGeoIpDatabase('GeoIPCity.dat') . '.gz';
try {
$result = Http::downloadChunk(
$url = GeoIp::GEO_LITE_URL,
$outputPath,
$continue = Common::getRequestVar('continue', true, 'int')
);
// if the file is done
if ($result['current_size'] >= $result['expected_file_size']) {
GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true);
// setup the auto updater
GeoIPAutoUpdater::setUpdaterOptions(array(
'loc' => GeoIp::GEO_LITE_URL,
'period' => GeoIPAutoUpdater::SCHEDULE_PERIOD_MONTHLY,
));
// make sure to echo out the geoip updater management screen
$result['settings'] = GeoIPAutoUpdater::getConfiguredUrls();
}
return json_encode($result);
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | [
"public",
"function",
"downloadFreeGeoIPDB",
"(",
")",
"{",
"$",
"this",
"->",
"dieIfGeolocationAdminIsDisabled",
"(",
")",
";",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isGeoIp2Enabled",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"downloadFreeGeoIP2DB",
"(",
")",
";",
"}",
"if",
"(",
"$",
"_SERVER",
"[",
"\"REQUEST_METHOD\"",
"]",
"==",
"\"POST\"",
")",
"{",
"$",
"this",
"->",
"checkTokenInUrl",
"(",
")",
";",
"Json",
"::",
"sendHeaderJSON",
"(",
")",
";",
"$",
"outputPath",
"=",
"GeoIp",
"::",
"getPathForGeoIpDatabase",
"(",
"'GeoIPCity.dat'",
")",
".",
"'.gz'",
";",
"try",
"{",
"$",
"result",
"=",
"Http",
"::",
"downloadChunk",
"(",
"$",
"url",
"=",
"GeoIp",
"::",
"GEO_LITE_URL",
",",
"$",
"outputPath",
",",
"$",
"continue",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'continue'",
",",
"true",
",",
"'int'",
")",
")",
";",
"// if the file is done",
"if",
"(",
"$",
"result",
"[",
"'current_size'",
"]",
">=",
"$",
"result",
"[",
"'expected_file_size'",
"]",
")",
"{",
"GeoIPAutoUpdater",
"::",
"unzipDownloadedFile",
"(",
"$",
"outputPath",
",",
"$",
"unlink",
"=",
"true",
")",
";",
"// setup the auto updater",
"GeoIPAutoUpdater",
"::",
"setUpdaterOptions",
"(",
"array",
"(",
"'loc'",
"=>",
"GeoIp",
"::",
"GEO_LITE_URL",
",",
"'period'",
"=>",
"GeoIPAutoUpdater",
"::",
"SCHEDULE_PERIOD_MONTHLY",
",",
")",
")",
";",
"// make sure to echo out the geoip updater management screen",
"$",
"result",
"[",
"'settings'",
"]",
"=",
"GeoIPAutoUpdater",
"::",
"getConfiguredUrls",
"(",
")",
";",
"}",
"return",
"json_encode",
"(",
"$",
"result",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"json_encode",
"(",
"array",
"(",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"}"
] | Starts or continues download of GeoLiteCity.dat.
To avoid a server/PHP timeout & to show progress of the download to the user, we
use the HTTP Range header to download one chunk of the file at a time. After each
chunk, it is the browser's responsibility to call the method again to continue the download.
Input:
'continue' query param - if set to 1, will assume we are currently downloading & use
Range: HTTP header to get another chunk of the file.
Output (in JSON):
'current_size' - Current size of the partially downloaded file on disk.
'expected_file_size' - The expected finished file size as returned by the HTTP server.
'next_screen' - When the download finishes, this is the next screen that should be shown.
'error' - When an error occurs, the message is returned in this property. | [
"Starts",
"or",
"continues",
"download",
"of",
"GeoLiteCity",
".",
"dat",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/Controller.php#L109-L148 |
209,812 | matomo-org/matomo | plugins/UserCountry/Controller.php | Controller.downloadFreeGeoIP2DB | public function downloadFreeGeoIP2DB()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
$outputPath = GeoIp2::getPathForGeoIpDatabase('GeoLite2-City.tar') . '.gz';
try {
$result = Http::downloadChunk(
$url = GeoIp2::GEO_LITE_URL,
$outputPath,
$continue = Common::getRequestVar('continue', true, 'int')
);
// if the file is done
if ($result['current_size'] >= $result['expected_file_size']) {
try {
GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, 'loc', $unlink = true);
} catch (\Exception $e) {
// remove downloaded file on error
unlink($outputPath);
throw $e;
}
// setup the auto updater
GeoIP2AutoUpdater::setUpdaterOptions(array(
'loc' => GeoIp2::GEO_LITE_URL,
'period' => GeoIP2AutoUpdater::SCHEDULE_PERIOD_MONTHLY,
));
$result['settings'] = GeoIP2AutoUpdater::getConfiguredUrls();
}
return json_encode($result);
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | php | public function downloadFreeGeoIP2DB()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
$outputPath = GeoIp2::getPathForGeoIpDatabase('GeoLite2-City.tar') . '.gz';
try {
$result = Http::downloadChunk(
$url = GeoIp2::GEO_LITE_URL,
$outputPath,
$continue = Common::getRequestVar('continue', true, 'int')
);
// if the file is done
if ($result['current_size'] >= $result['expected_file_size']) {
try {
GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, 'loc', $unlink = true);
} catch (\Exception $e) {
// remove downloaded file on error
unlink($outputPath);
throw $e;
}
// setup the auto updater
GeoIP2AutoUpdater::setUpdaterOptions(array(
'loc' => GeoIp2::GEO_LITE_URL,
'period' => GeoIP2AutoUpdater::SCHEDULE_PERIOD_MONTHLY,
));
$result['settings'] = GeoIP2AutoUpdater::getConfiguredUrls();
}
return json_encode($result);
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | [
"public",
"function",
"downloadFreeGeoIP2DB",
"(",
")",
"{",
"$",
"this",
"->",
"dieIfGeolocationAdminIsDisabled",
"(",
")",
";",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"if",
"(",
"$",
"_SERVER",
"[",
"\"REQUEST_METHOD\"",
"]",
"==",
"\"POST\"",
")",
"{",
"$",
"this",
"->",
"checkTokenInUrl",
"(",
")",
";",
"Json",
"::",
"sendHeaderJSON",
"(",
")",
";",
"$",
"outputPath",
"=",
"GeoIp2",
"::",
"getPathForGeoIpDatabase",
"(",
"'GeoLite2-City.tar'",
")",
".",
"'.gz'",
";",
"try",
"{",
"$",
"result",
"=",
"Http",
"::",
"downloadChunk",
"(",
"$",
"url",
"=",
"GeoIp2",
"::",
"GEO_LITE_URL",
",",
"$",
"outputPath",
",",
"$",
"continue",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'continue'",
",",
"true",
",",
"'int'",
")",
")",
";",
"// if the file is done",
"if",
"(",
"$",
"result",
"[",
"'current_size'",
"]",
">=",
"$",
"result",
"[",
"'expected_file_size'",
"]",
")",
"{",
"try",
"{",
"GeoIP2AutoUpdater",
"::",
"unzipDownloadedFile",
"(",
"$",
"outputPath",
",",
"'loc'",
",",
"$",
"unlink",
"=",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// remove downloaded file on error",
"unlink",
"(",
"$",
"outputPath",
")",
";",
"throw",
"$",
"e",
";",
"}",
"// setup the auto updater",
"GeoIP2AutoUpdater",
"::",
"setUpdaterOptions",
"(",
"array",
"(",
"'loc'",
"=>",
"GeoIp2",
"::",
"GEO_LITE_URL",
",",
"'period'",
"=>",
"GeoIP2AutoUpdater",
"::",
"SCHEDULE_PERIOD_MONTHLY",
",",
")",
")",
";",
"$",
"result",
"[",
"'settings'",
"]",
"=",
"GeoIP2AutoUpdater",
"::",
"getConfiguredUrls",
"(",
")",
";",
"}",
"return",
"json_encode",
"(",
"$",
"result",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"json_encode",
"(",
"array",
"(",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"}"
] | Starts or continues download of GeoLite2-City.mmdb.
To avoid a server/PHP timeout & to show progress of the download to the user, we
use the HTTP Range header to download one chunk of the file at a time. After each
chunk, it is the browser's responsibility to call the method again to continue the download.
Input:
'continue' query param - if set to 1, will assume we are currently downloading & use
Range: HTTP header to get another chunk of the file.
Output (in JSON):
'current_size' - Current size of the partially downloaded file on disk.
'expected_file_size' - The expected finished file size as returned by the HTTP server.
'next_screen' - When the download finishes, this is the next screen that should be shown.
'error' - When an error occurs, the message is returned in this property. | [
"Starts",
"or",
"continues",
"download",
"of",
"GeoLite2",
"-",
"City",
".",
"mmdb",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/Controller.php#L167-L206 |
209,813 | matomo-org/matomo | plugins/UserCountry/Controller.php | Controller.setUpdaterManageVars | private function setUpdaterManageVars($view)
{
$view->isGeoIp2Available = $this->isGeoIp2Enabled();
if ($this->isGeoIp2Enabled()) {
// Get GeoIPLegacy Update information to show them
$urls = GeoIPAutoUpdater::getConfiguredUrls();
$view->geoIPLegacyLocUrl = $urls['loc'];
$view->geoIPLegacyIspUrl = $urls['isp'];
$view->geoIPLegacyOrgUrl = $urls['org'];
$view->geoIPLegacyUpdatePeriod = GeoIPAutoUpdater::getSchedulePeriod();
$urls = GeoIP2AutoUpdater::getConfiguredUrls();
$view->geoIPLocUrl = $urls['loc'];
$view->geoIPIspUrl = $urls['isp'];
$view->geoIPUpdatePeriod = GeoIP2AutoUpdater::getSchedulePeriod();
$view->geoLiteUrl = GeoIp2::GEO_LITE_URL;
$view->geoLiteFilename = 'GeoLite2-City.mmdb';
$view->nextRunTime = GeoIP2AutoUpdater::getNextRunTime();
$lastRunTime = GeoIP2AutoUpdater::getLastRunTime();
} else {
$urls = GeoIPAutoUpdater::getConfiguredUrls();
$view->geoIPLocUrl = $urls['loc'];
$view->geoIPIspUrl = $urls['isp'];
$view->geoIPOrgUrl = $urls['org'];
$view->geoIPUpdatePeriod = GeoIPAutoUpdater::getSchedulePeriod();
$view->geoLiteUrl = GeoIp::GEO_LITE_URL;
$view->geoLiteFilename = 'GeoLiteCity.dat';
$view->nextRunTime = GeoIPAutoUpdater::getNextRunTime();
$lastRunTime = GeoIPAutoUpdater::getLastRunTime();
}
if ($lastRunTime !== false) {
$view->lastTimeUpdaterRun = '<strong>' . $lastRunTime->toString() . '</strong>';
}
} | php | private function setUpdaterManageVars($view)
{
$view->isGeoIp2Available = $this->isGeoIp2Enabled();
if ($this->isGeoIp2Enabled()) {
// Get GeoIPLegacy Update information to show them
$urls = GeoIPAutoUpdater::getConfiguredUrls();
$view->geoIPLegacyLocUrl = $urls['loc'];
$view->geoIPLegacyIspUrl = $urls['isp'];
$view->geoIPLegacyOrgUrl = $urls['org'];
$view->geoIPLegacyUpdatePeriod = GeoIPAutoUpdater::getSchedulePeriod();
$urls = GeoIP2AutoUpdater::getConfiguredUrls();
$view->geoIPLocUrl = $urls['loc'];
$view->geoIPIspUrl = $urls['isp'];
$view->geoIPUpdatePeriod = GeoIP2AutoUpdater::getSchedulePeriod();
$view->geoLiteUrl = GeoIp2::GEO_LITE_URL;
$view->geoLiteFilename = 'GeoLite2-City.mmdb';
$view->nextRunTime = GeoIP2AutoUpdater::getNextRunTime();
$lastRunTime = GeoIP2AutoUpdater::getLastRunTime();
} else {
$urls = GeoIPAutoUpdater::getConfiguredUrls();
$view->geoIPLocUrl = $urls['loc'];
$view->geoIPIspUrl = $urls['isp'];
$view->geoIPOrgUrl = $urls['org'];
$view->geoIPUpdatePeriod = GeoIPAutoUpdater::getSchedulePeriod();
$view->geoLiteUrl = GeoIp::GEO_LITE_URL;
$view->geoLiteFilename = 'GeoLiteCity.dat';
$view->nextRunTime = GeoIPAutoUpdater::getNextRunTime();
$lastRunTime = GeoIPAutoUpdater::getLastRunTime();
}
if ($lastRunTime !== false) {
$view->lastTimeUpdaterRun = '<strong>' . $lastRunTime->toString() . '</strong>';
}
} | [
"private",
"function",
"setUpdaterManageVars",
"(",
"$",
"view",
")",
"{",
"$",
"view",
"->",
"isGeoIp2Available",
"=",
"$",
"this",
"->",
"isGeoIp2Enabled",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isGeoIp2Enabled",
"(",
")",
")",
"{",
"// Get GeoIPLegacy Update information to show them",
"$",
"urls",
"=",
"GeoIPAutoUpdater",
"::",
"getConfiguredUrls",
"(",
")",
";",
"$",
"view",
"->",
"geoIPLegacyLocUrl",
"=",
"$",
"urls",
"[",
"'loc'",
"]",
";",
"$",
"view",
"->",
"geoIPLegacyIspUrl",
"=",
"$",
"urls",
"[",
"'isp'",
"]",
";",
"$",
"view",
"->",
"geoIPLegacyOrgUrl",
"=",
"$",
"urls",
"[",
"'org'",
"]",
";",
"$",
"view",
"->",
"geoIPLegacyUpdatePeriod",
"=",
"GeoIPAutoUpdater",
"::",
"getSchedulePeriod",
"(",
")",
";",
"$",
"urls",
"=",
"GeoIP2AutoUpdater",
"::",
"getConfiguredUrls",
"(",
")",
";",
"$",
"view",
"->",
"geoIPLocUrl",
"=",
"$",
"urls",
"[",
"'loc'",
"]",
";",
"$",
"view",
"->",
"geoIPIspUrl",
"=",
"$",
"urls",
"[",
"'isp'",
"]",
";",
"$",
"view",
"->",
"geoIPUpdatePeriod",
"=",
"GeoIP2AutoUpdater",
"::",
"getSchedulePeriod",
"(",
")",
";",
"$",
"view",
"->",
"geoLiteUrl",
"=",
"GeoIp2",
"::",
"GEO_LITE_URL",
";",
"$",
"view",
"->",
"geoLiteFilename",
"=",
"'GeoLite2-City.mmdb'",
";",
"$",
"view",
"->",
"nextRunTime",
"=",
"GeoIP2AutoUpdater",
"::",
"getNextRunTime",
"(",
")",
";",
"$",
"lastRunTime",
"=",
"GeoIP2AutoUpdater",
"::",
"getLastRunTime",
"(",
")",
";",
"}",
"else",
"{",
"$",
"urls",
"=",
"GeoIPAutoUpdater",
"::",
"getConfiguredUrls",
"(",
")",
";",
"$",
"view",
"->",
"geoIPLocUrl",
"=",
"$",
"urls",
"[",
"'loc'",
"]",
";",
"$",
"view",
"->",
"geoIPIspUrl",
"=",
"$",
"urls",
"[",
"'isp'",
"]",
";",
"$",
"view",
"->",
"geoIPOrgUrl",
"=",
"$",
"urls",
"[",
"'org'",
"]",
";",
"$",
"view",
"->",
"geoIPUpdatePeriod",
"=",
"GeoIPAutoUpdater",
"::",
"getSchedulePeriod",
"(",
")",
";",
"$",
"view",
"->",
"geoLiteUrl",
"=",
"GeoIp",
"::",
"GEO_LITE_URL",
";",
"$",
"view",
"->",
"geoLiteFilename",
"=",
"'GeoLiteCity.dat'",
";",
"$",
"view",
"->",
"nextRunTime",
"=",
"GeoIPAutoUpdater",
"::",
"getNextRunTime",
"(",
")",
";",
"$",
"lastRunTime",
"=",
"GeoIPAutoUpdater",
"::",
"getLastRunTime",
"(",
")",
";",
"}",
"if",
"(",
"$",
"lastRunTime",
"!==",
"false",
")",
"{",
"$",
"view",
"->",
"lastTimeUpdaterRun",
"=",
"'<strong>'",
".",
"$",
"lastRunTime",
"->",
"toString",
"(",
")",
".",
"'</strong>'",
";",
"}",
"}"
] | Sets some variables needed by the _updaterManage.twig template.
@param View $view | [
"Sets",
"some",
"variables",
"needed",
"by",
"the",
"_updaterManage",
".",
"twig",
"template",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/Controller.php#L221-L263 |
209,814 | matomo-org/matomo | plugins/UserCountry/Controller.php | Controller.updateGeoIPLinks | public function updateGeoIPLinks()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
Json::sendHeaderJSON();
try {
$this->checkTokenInUrl();
if ($this->isGeoIp2Enabled()) {
GeoIP2AutoUpdater::setUpdaterOptionsFromUrl();
} else {
GeoIPAutoUpdater::setUpdaterOptionsFromUrl();
}
// if there is a updater URL for a database, but its missing from the misc dir, tell
// the browser so it can download it next
$info = $this->getNextMissingDbUrlInfo();
if ($info !== false) {
return json_encode($info);
} else {
$view = new View("@UserCountry/_updaterNextRunTime");
if ($this->isGeoIp2Enabled()) {
$view->nextRunTime = GeoIP2AutoUpdater::getNextRunTime();
} else {
$view->nextRunTime = GeoIPAutoUpdater::getNextRunTime();
}
$nextRunTimeHtml = $view->render();
return json_encode(array('nextRunTime' => $nextRunTimeHtml));
}
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | php | public function updateGeoIPLinks()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
Json::sendHeaderJSON();
try {
$this->checkTokenInUrl();
if ($this->isGeoIp2Enabled()) {
GeoIP2AutoUpdater::setUpdaterOptionsFromUrl();
} else {
GeoIPAutoUpdater::setUpdaterOptionsFromUrl();
}
// if there is a updater URL for a database, but its missing from the misc dir, tell
// the browser so it can download it next
$info = $this->getNextMissingDbUrlInfo();
if ($info !== false) {
return json_encode($info);
} else {
$view = new View("@UserCountry/_updaterNextRunTime");
if ($this->isGeoIp2Enabled()) {
$view->nextRunTime = GeoIP2AutoUpdater::getNextRunTime();
} else {
$view->nextRunTime = GeoIPAutoUpdater::getNextRunTime();
}
$nextRunTimeHtml = $view->render();
return json_encode(array('nextRunTime' => $nextRunTimeHtml));
}
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | [
"public",
"function",
"updateGeoIPLinks",
"(",
")",
"{",
"$",
"this",
"->",
"dieIfGeolocationAdminIsDisabled",
"(",
")",
";",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"if",
"(",
"$",
"_SERVER",
"[",
"\"REQUEST_METHOD\"",
"]",
"==",
"\"POST\"",
")",
"{",
"Json",
"::",
"sendHeaderJSON",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"checkTokenInUrl",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isGeoIp2Enabled",
"(",
")",
")",
"{",
"GeoIP2AutoUpdater",
"::",
"setUpdaterOptionsFromUrl",
"(",
")",
";",
"}",
"else",
"{",
"GeoIPAutoUpdater",
"::",
"setUpdaterOptionsFromUrl",
"(",
")",
";",
"}",
"// if there is a updater URL for a database, but its missing from the misc dir, tell",
"// the browser so it can download it next",
"$",
"info",
"=",
"$",
"this",
"->",
"getNextMissingDbUrlInfo",
"(",
")",
";",
"if",
"(",
"$",
"info",
"!==",
"false",
")",
"{",
"return",
"json_encode",
"(",
"$",
"info",
")",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"new",
"View",
"(",
"\"@UserCountry/_updaterNextRunTime\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isGeoIp2Enabled",
"(",
")",
")",
"{",
"$",
"view",
"->",
"nextRunTime",
"=",
"GeoIP2AutoUpdater",
"::",
"getNextRunTime",
"(",
")",
";",
"}",
"else",
"{",
"$",
"view",
"->",
"nextRunTime",
"=",
"GeoIPAutoUpdater",
"::",
"getNextRunTime",
"(",
")",
";",
"}",
"$",
"nextRunTimeHtml",
"=",
"$",
"view",
"->",
"render",
"(",
")",
";",
"return",
"json_encode",
"(",
"array",
"(",
"'nextRunTime'",
"=>",
"$",
"nextRunTimeHtml",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"json_encode",
"(",
"array",
"(",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"}"
] | Sets the URLs used to download new versions of the installed GeoIP databases.
Input (query params):
'loc_db' - URL for a GeoIP location database.
'isp_db' - URL for a GeoIP ISP database (optional).
'org_db' - URL for a GeoIP Org database (optional).
'period' - 'weekly' or 'monthly'. Determines how often update is run.
Output (json):
'error' - if an error occurs its message is set as the resulting JSON object's
'error' property. | [
"Sets",
"the",
"URLs",
"used",
"to",
"download",
"new",
"versions",
"of",
"the",
"installed",
"GeoIP",
"databases",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/Controller.php#L278-L312 |
209,815 | matomo-org/matomo | plugins/UserCountry/Controller.php | Controller.downloadMissingGeoIpDb | public function downloadMissingGeoIpDb()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
// based on the database type (provided by the 'key' query param) determine the
// url & output file name
$key = Common::getRequestVar('key', null, 'string');
if ($this->isGeoIp2Enabled()) {
$url = GeoIP2AutoUpdater::getConfiguredUrl($key);
$ext = GeoIP2AutoUpdater::getGeoIPUrlExtension($url);
$filename = GeoIp2::$dbNames[$key][0] . '.' . $ext;
$outputPath = GeoIp2::getPathForGeoIpDatabase($filename);
} else {
$url = GeoIPAutoUpdater::getConfiguredUrl($key);
$ext = GeoIPAutoUpdater::getGeoIPUrlExtension($url);
$filename = GeoIp::$dbNames[$key][0] . '.' . $ext;
if (substr($filename, 0, 15) == 'GeoLiteCity.dat') {
$filename = 'GeoIPCity.dat' . substr($filename, 15);
}
$outputPath = GeoIp::getPathForGeoIpDatabase($filename);
}
// download part of the file
$result = Http::downloadChunk(
$url, $outputPath, Common::getRequestVar('continue', true, 'int'));
// if the file is done
if ($result['current_size'] >= $result['expected_file_size']) {
if ($this->isGeoIp2Enabled()) {
GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, $key, $unlink = true);
} else {
GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true);
}
$info = $this->getNextMissingDbUrlInfo();
if ($info !== false) {
return json_encode($info);
}
}
return json_encode($result);
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | php | public function downloadMissingGeoIpDb()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
$this->checkTokenInUrl();
Json::sendHeaderJSON();
// based on the database type (provided by the 'key' query param) determine the
// url & output file name
$key = Common::getRequestVar('key', null, 'string');
if ($this->isGeoIp2Enabled()) {
$url = GeoIP2AutoUpdater::getConfiguredUrl($key);
$ext = GeoIP2AutoUpdater::getGeoIPUrlExtension($url);
$filename = GeoIp2::$dbNames[$key][0] . '.' . $ext;
$outputPath = GeoIp2::getPathForGeoIpDatabase($filename);
} else {
$url = GeoIPAutoUpdater::getConfiguredUrl($key);
$ext = GeoIPAutoUpdater::getGeoIPUrlExtension($url);
$filename = GeoIp::$dbNames[$key][0] . '.' . $ext;
if (substr($filename, 0, 15) == 'GeoLiteCity.dat') {
$filename = 'GeoIPCity.dat' . substr($filename, 15);
}
$outputPath = GeoIp::getPathForGeoIpDatabase($filename);
}
// download part of the file
$result = Http::downloadChunk(
$url, $outputPath, Common::getRequestVar('continue', true, 'int'));
// if the file is done
if ($result['current_size'] >= $result['expected_file_size']) {
if ($this->isGeoIp2Enabled()) {
GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, $key, $unlink = true);
} else {
GeoIPAutoUpdater::unzipDownloadedFile($outputPath, $unlink = true);
}
$info = $this->getNextMissingDbUrlInfo();
if ($info !== false) {
return json_encode($info);
}
}
return json_encode($result);
} catch (Exception $ex) {
return json_encode(array('error' => $ex->getMessage()));
}
}
} | [
"public",
"function",
"downloadMissingGeoIpDb",
"(",
")",
"{",
"$",
"this",
"->",
"dieIfGeolocationAdminIsDisabled",
"(",
")",
";",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"if",
"(",
"$",
"_SERVER",
"[",
"\"REQUEST_METHOD\"",
"]",
"==",
"\"POST\"",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"checkTokenInUrl",
"(",
")",
";",
"Json",
"::",
"sendHeaderJSON",
"(",
")",
";",
"// based on the database type (provided by the 'key' query param) determine the",
"// url & output file name",
"$",
"key",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'key'",
",",
"null",
",",
"'string'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isGeoIp2Enabled",
"(",
")",
")",
"{",
"$",
"url",
"=",
"GeoIP2AutoUpdater",
"::",
"getConfiguredUrl",
"(",
"$",
"key",
")",
";",
"$",
"ext",
"=",
"GeoIP2AutoUpdater",
"::",
"getGeoIPUrlExtension",
"(",
"$",
"url",
")",
";",
"$",
"filename",
"=",
"GeoIp2",
"::",
"$",
"dbNames",
"[",
"$",
"key",
"]",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"ext",
";",
"$",
"outputPath",
"=",
"GeoIp2",
"::",
"getPathForGeoIpDatabase",
"(",
"$",
"filename",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"GeoIPAutoUpdater",
"::",
"getConfiguredUrl",
"(",
"$",
"key",
")",
";",
"$",
"ext",
"=",
"GeoIPAutoUpdater",
"::",
"getGeoIPUrlExtension",
"(",
"$",
"url",
")",
";",
"$",
"filename",
"=",
"GeoIp",
"::",
"$",
"dbNames",
"[",
"$",
"key",
"]",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"ext",
";",
"if",
"(",
"substr",
"(",
"$",
"filename",
",",
"0",
",",
"15",
")",
"==",
"'GeoLiteCity.dat'",
")",
"{",
"$",
"filename",
"=",
"'GeoIPCity.dat'",
".",
"substr",
"(",
"$",
"filename",
",",
"15",
")",
";",
"}",
"$",
"outputPath",
"=",
"GeoIp",
"::",
"getPathForGeoIpDatabase",
"(",
"$",
"filename",
")",
";",
"}",
"// download part of the file",
"$",
"result",
"=",
"Http",
"::",
"downloadChunk",
"(",
"$",
"url",
",",
"$",
"outputPath",
",",
"Common",
"::",
"getRequestVar",
"(",
"'continue'",
",",
"true",
",",
"'int'",
")",
")",
";",
"// if the file is done",
"if",
"(",
"$",
"result",
"[",
"'current_size'",
"]",
">=",
"$",
"result",
"[",
"'expected_file_size'",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isGeoIp2Enabled",
"(",
")",
")",
"{",
"GeoIP2AutoUpdater",
"::",
"unzipDownloadedFile",
"(",
"$",
"outputPath",
",",
"$",
"key",
",",
"$",
"unlink",
"=",
"true",
")",
";",
"}",
"else",
"{",
"GeoIPAutoUpdater",
"::",
"unzipDownloadedFile",
"(",
"$",
"outputPath",
",",
"$",
"unlink",
"=",
"true",
")",
";",
"}",
"$",
"info",
"=",
"$",
"this",
"->",
"getNextMissingDbUrlInfo",
"(",
")",
";",
"if",
"(",
"$",
"info",
"!==",
"false",
")",
"{",
"return",
"json_encode",
"(",
"$",
"info",
")",
";",
"}",
"}",
"return",
"json_encode",
"(",
"$",
"result",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"return",
"json_encode",
"(",
"array",
"(",
"'error'",
"=>",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"}"
] | Starts or continues a download for a missing GeoIP database. A database is missing if
it has an update URL configured, but the actual database is not available in the misc
directory.
Input:
'url' - The URL to download the database from.
'continue' - 1 if we're continuing a download, 0 if we're starting one.
Output:
'error' - If an error occurs this describes the error.
'to_download' - The URL of a missing database that should be downloaded next (if any).
'to_download_label' - The label to use w/ the progress bar that describes what we're
downloading.
'current_size' - Size of the current file on disk.
'expected_file_size' - Size of the completely downloaded file. | [
"Starts",
"or",
"continues",
"a",
"download",
"for",
"a",
"missing",
"GeoIP",
"database",
".",
"A",
"database",
"is",
"missing",
"if",
"it",
"has",
"an",
"update",
"URL",
"configured",
"but",
"the",
"actual",
"database",
"is",
"not",
"available",
"in",
"the",
"misc",
"directory",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/Controller.php#L331-L384 |
209,816 | matomo-org/matomo | plugins/UserCountry/Controller.php | Controller.getLocationUsingProvider | public function getLocationUsingProvider()
{
$providerId = Common::getRequestVar('id');
$provider = LocationProvider::getProviderById($providerId);
if (empty($provider)) {
throw new Exception("Invalid provider ID: '$providerId'.");
}
$location = $provider->getLocation(array('ip' => IP::getIpFromHeader(),
'lang' => Common::getBrowserLanguage(),
'disable_fallbacks' => true));
$location = LocationProvider::prettyFormatLocation(
$location, $newline = '<br/>', $includeExtra = true);
return $location;
} | php | public function getLocationUsingProvider()
{
$providerId = Common::getRequestVar('id');
$provider = LocationProvider::getProviderById($providerId);
if (empty($provider)) {
throw new Exception("Invalid provider ID: '$providerId'.");
}
$location = $provider->getLocation(array('ip' => IP::getIpFromHeader(),
'lang' => Common::getBrowserLanguage(),
'disable_fallbacks' => true));
$location = LocationProvider::prettyFormatLocation(
$location, $newline = '<br/>', $includeExtra = true);
return $location;
} | [
"public",
"function",
"getLocationUsingProvider",
"(",
")",
"{",
"$",
"providerId",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'id'",
")",
";",
"$",
"provider",
"=",
"LocationProvider",
"::",
"getProviderById",
"(",
"$",
"providerId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"provider",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid provider ID: '$providerId'.\"",
")",
";",
"}",
"$",
"location",
"=",
"$",
"provider",
"->",
"getLocation",
"(",
"array",
"(",
"'ip'",
"=>",
"IP",
"::",
"getIpFromHeader",
"(",
")",
",",
"'lang'",
"=>",
"Common",
"::",
"getBrowserLanguage",
"(",
")",
",",
"'disable_fallbacks'",
"=>",
"true",
")",
")",
";",
"$",
"location",
"=",
"LocationProvider",
"::",
"prettyFormatLocation",
"(",
"$",
"location",
",",
"$",
"newline",
"=",
"'<br/>'",
",",
"$",
"includeExtra",
"=",
"true",
")",
";",
"return",
"$",
"location",
";",
"}"
] | Echo's a pretty formatted location using a specific LocationProvider.
Input:
The 'id' query parameter must be set to the ID of the LocationProvider to use.
Output:
The pretty formatted location that was obtained. Will be HTML. | [
"Echo",
"s",
"a",
"pretty",
"formatted",
"location",
"using",
"a",
"specific",
"LocationProvider",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/Controller.php#L395-L410 |
209,817 | matomo-org/matomo | libs/Zend/Db/Statement.php | Zend_Db_Statement._stripQuoted | protected function _stripQuoted($sql)
{
// get the character for delimited id quotes,
// this is usually " but in MySQL is `
$d = $this->_adapter->quoteIdentifier('a');
$d = $d[0];
// get the value used as an escaped delimited id quote,
// e.g. \" or "" or \`
$de = $this->_adapter->quoteIdentifier($d);
$de = substr($de, 1, 2);
$de = str_replace('\\', '\\\\', $de);
// get the character for value quoting
// this should be '
$q = $this->_adapter->quote('a');
$q = $q[0];
// get the value used as an escaped quote,
// e.g. \' or ''
$qe = $this->_adapter->quote($q);
$qe = substr($qe, 1, 2);
$qe = str_replace('\\', '\\\\', $qe);
// get a version of the SQL statement with all quoted
// values and delimited identifiers stripped out
// remove "foo\"bar"
$sql = preg_replace("/$q($qe|\\\\{2}|[^$q])*$q/", '', $sql);
// remove 'foo\'bar'
if (!empty($q)) {
$sql = preg_replace("/$q($qe|[^$q])*$q/", '', $sql);
}
return $sql;
} | php | protected function _stripQuoted($sql)
{
// get the character for delimited id quotes,
// this is usually " but in MySQL is `
$d = $this->_adapter->quoteIdentifier('a');
$d = $d[0];
// get the value used as an escaped delimited id quote,
// e.g. \" or "" or \`
$de = $this->_adapter->quoteIdentifier($d);
$de = substr($de, 1, 2);
$de = str_replace('\\', '\\\\', $de);
// get the character for value quoting
// this should be '
$q = $this->_adapter->quote('a');
$q = $q[0];
// get the value used as an escaped quote,
// e.g. \' or ''
$qe = $this->_adapter->quote($q);
$qe = substr($qe, 1, 2);
$qe = str_replace('\\', '\\\\', $qe);
// get a version of the SQL statement with all quoted
// values and delimited identifiers stripped out
// remove "foo\"bar"
$sql = preg_replace("/$q($qe|\\\\{2}|[^$q])*$q/", '', $sql);
// remove 'foo\'bar'
if (!empty($q)) {
$sql = preg_replace("/$q($qe|[^$q])*$q/", '', $sql);
}
return $sql;
} | [
"protected",
"function",
"_stripQuoted",
"(",
"$",
"sql",
")",
"{",
"// get the character for delimited id quotes,",
"// this is usually \" but in MySQL is `",
"$",
"d",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"quoteIdentifier",
"(",
"'a'",
")",
";",
"$",
"d",
"=",
"$",
"d",
"[",
"0",
"]",
";",
"// get the value used as an escaped delimited id quote,",
"// e.g. \\\" or \"\" or \\`",
"$",
"de",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"quoteIdentifier",
"(",
"$",
"d",
")",
";",
"$",
"de",
"=",
"substr",
"(",
"$",
"de",
",",
"1",
",",
"2",
")",
";",
"$",
"de",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
",",
"$",
"de",
")",
";",
"// get the character for value quoting",
"// this should be '",
"$",
"q",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"quote",
"(",
"'a'",
")",
";",
"$",
"q",
"=",
"$",
"q",
"[",
"0",
"]",
";",
"// get the value used as an escaped quote,",
"// e.g. \\' or ''",
"$",
"qe",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"quote",
"(",
"$",
"q",
")",
";",
"$",
"qe",
"=",
"substr",
"(",
"$",
"qe",
",",
"1",
",",
"2",
")",
";",
"$",
"qe",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
",",
"$",
"qe",
")",
";",
"// get a version of the SQL statement with all quoted",
"// values and delimited identifiers stripped out",
"// remove \"foo\\\"bar\"",
"$",
"sql",
"=",
"preg_replace",
"(",
"\"/$q($qe|\\\\\\\\{2}|[^$q])*$q/\"",
",",
"''",
",",
"$",
"sql",
")",
";",
"// remove 'foo\\'bar'",
"if",
"(",
"!",
"empty",
"(",
"$",
"q",
")",
")",
"{",
"$",
"sql",
"=",
"preg_replace",
"(",
"\"/$q($qe|[^$q])*$q/\"",
",",
"''",
",",
"$",
"sql",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Remove parts of a SQL string that contain quoted strings
of values or identifiers.
@param string $sql
@return string | [
"Remove",
"parts",
"of",
"a",
"SQL",
"string",
"that",
"contain",
"quoted",
"strings",
"of",
"values",
"or",
"identifiers",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Statement.php#L177-L211 |
209,818 | matomo-org/matomo | libs/Zend/Db/Statement.php | Zend_Db_Statement._fetchBound | public function _fetchBound($row)
{
foreach ($row as $key => $value) {
// bindColumn() takes 1-based integer positions
// but fetch() returns 0-based integer indexes
if (is_int($key)) {
$key++;
}
// set results only to variables that were bound previously
if (isset($this->_bindColumn[$key])) {
$this->_bindColumn[$key] = $value;
}
}
return true;
} | php | public function _fetchBound($row)
{
foreach ($row as $key => $value) {
// bindColumn() takes 1-based integer positions
// but fetch() returns 0-based integer indexes
if (is_int($key)) {
$key++;
}
// set results only to variables that were bound previously
if (isset($this->_bindColumn[$key])) {
$this->_bindColumn[$key] = $value;
}
}
return true;
} | [
"public",
"function",
"_fetchBound",
"(",
"$",
"row",
")",
"{",
"foreach",
"(",
"$",
"row",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// bindColumn() takes 1-based integer positions",
"// but fetch() returns 0-based integer indexes",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"++",
";",
"}",
"// set results only to variables that were bound previously",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_bindColumn",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_bindColumn",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Helper function to map retrieved row
to bound column variables
@param array $row
@return bool True | [
"Helper",
"function",
"to",
"map",
"retrieved",
"row",
"to",
"bound",
"column",
"variables"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Statement.php#L449-L463 |
209,819 | matomo-org/matomo | plugins/MultiSites/API.php | API.getAll | public function getAll($period, $date, $segment = false, $_restrictSitesToLogin = false, $enhanced = false, $pattern = false, $showColumns = array())
{
Piwik::checkUserHasSomeViewAccess();
$sites = $this->getSitesIdFromPattern($pattern, $_restrictSitesToLogin);
if (!empty($showColumns) && !is_array($showColumns)) {
$showColumns = explode(',', $showColumns);
}
if (empty($sites)) {
return new DataTable();
}
return $this->buildDataTable(
$sites,
$period,
$date,
$segment,
$_restrictSitesToLogin,
$enhanced,
$multipleWebsitesRequested = true,
$showColumns
);
} | php | public function getAll($period, $date, $segment = false, $_restrictSitesToLogin = false, $enhanced = false, $pattern = false, $showColumns = array())
{
Piwik::checkUserHasSomeViewAccess();
$sites = $this->getSitesIdFromPattern($pattern, $_restrictSitesToLogin);
if (!empty($showColumns) && !is_array($showColumns)) {
$showColumns = explode(',', $showColumns);
}
if (empty($sites)) {
return new DataTable();
}
return $this->buildDataTable(
$sites,
$period,
$date,
$segment,
$_restrictSitesToLogin,
$enhanced,
$multipleWebsitesRequested = true,
$showColumns
);
} | [
"public",
"function",
"getAll",
"(",
"$",
"period",
",",
"$",
"date",
",",
"$",
"segment",
"=",
"false",
",",
"$",
"_restrictSitesToLogin",
"=",
"false",
",",
"$",
"enhanced",
"=",
"false",
",",
"$",
"pattern",
"=",
"false",
",",
"$",
"showColumns",
"=",
"array",
"(",
")",
")",
"{",
"Piwik",
"::",
"checkUserHasSomeViewAccess",
"(",
")",
";",
"$",
"sites",
"=",
"$",
"this",
"->",
"getSitesIdFromPattern",
"(",
"$",
"pattern",
",",
"$",
"_restrictSitesToLogin",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"showColumns",
")",
"&&",
"!",
"is_array",
"(",
"$",
"showColumns",
")",
")",
"{",
"$",
"showColumns",
"=",
"explode",
"(",
"','",
",",
"$",
"showColumns",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sites",
")",
")",
"{",
"return",
"new",
"DataTable",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"buildDataTable",
"(",
"$",
"sites",
",",
"$",
"period",
",",
"$",
"date",
",",
"$",
"segment",
",",
"$",
"_restrictSitesToLogin",
",",
"$",
"enhanced",
",",
"$",
"multipleWebsitesRequested",
"=",
"true",
",",
"$",
"showColumns",
")",
";",
"}"
] | Returns a report displaying the total visits, actions and revenue, as
well as the evolution of these values, of all existing sites over a
specified period of time.
If the specified period is not a 'range', this function will calculcate
evolution metrics. Evolution metrics are metrics that display the
percent increase/decrease of another metric since the last period.
This function will merge the result of the archive query so each
row in the result DataTable will correspond to the metrics of a single
site. If a date range is specified, the result will be a
DataTable\Map, but it will still be merged.
@param string $period The period type to get data for.
@param string $date The date(s) to get data for.
@param bool|string $segment The segments to get data for.
@param bool|string $_restrictSitesToLogin Hack used to enforce we restrict the returned data to the specified username
Only used when a scheduled task is running
@param bool|string $enhanced When true, return additional goal & ecommerce metrics
@param bool|string $pattern If specified, only the website which names (or site ID) match the pattern will be returned using SitesManager.getPatternMatchSites
@param array $showColumns If specified, only the requested columns will be fetched
@return DataTable | [
"Returns",
"a",
"report",
"displaying",
"the",
"total",
"visits",
"actions",
"and",
"revenue",
"as",
"well",
"as",
"the",
"evolution",
"of",
"these",
"values",
"of",
"all",
"existing",
"sites",
"over",
"a",
"specified",
"period",
"of",
"time",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/MultiSites/API.php#L88-L112 |
209,820 | matomo-org/matomo | plugins/MultiSites/API.php | API.getSitesIdFromPattern | private function getSitesIdFromPattern($pattern, $_restrictSitesToLogin)
{
// First clear cache
Site::clearCache();
if (empty($pattern)) {
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\Scheduler\Scheduler');
// Then, warm the cache with only the data we should have access to
if (Piwik::hasUserSuperUserAccess()
// Hack: when this API function is called as a Scheduled Task, Super User status is enforced.
// This means this function would return ALL websites in all cases.
// Instead, we make sure that only the right set of data is returned
&& !$scheduler->isRunningTask()
) {
APISitesManager::getInstance()->getAllSites();
} else {
APISitesManager::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin);
}
} else {
$sites = Request::processRequest('SitesManager.getPatternMatchSites',
array('pattern' => $pattern,
// added because caller could overwrite these
'limit' => SettingsPiwik::getWebsitesCountToDisplay(),
'showColumns' => '',
'hideColumns' => '',
'format' => 'original'));
if (!empty($sites)) {
Site::setSitesFromArray($sites);
}
}
// Both calls above have called Site::setSitesFromArray. We now get these sites:
$sitesToProblablyAdd = Site::getSites();
return $sitesToProblablyAdd;
} | php | private function getSitesIdFromPattern($pattern, $_restrictSitesToLogin)
{
// First clear cache
Site::clearCache();
if (empty($pattern)) {
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\Scheduler\Scheduler');
// Then, warm the cache with only the data we should have access to
if (Piwik::hasUserSuperUserAccess()
// Hack: when this API function is called as a Scheduled Task, Super User status is enforced.
// This means this function would return ALL websites in all cases.
// Instead, we make sure that only the right set of data is returned
&& !$scheduler->isRunningTask()
) {
APISitesManager::getInstance()->getAllSites();
} else {
APISitesManager::getInstance()->getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin);
}
} else {
$sites = Request::processRequest('SitesManager.getPatternMatchSites',
array('pattern' => $pattern,
// added because caller could overwrite these
'limit' => SettingsPiwik::getWebsitesCountToDisplay(),
'showColumns' => '',
'hideColumns' => '',
'format' => 'original'));
if (!empty($sites)) {
Site::setSitesFromArray($sites);
}
}
// Both calls above have called Site::setSitesFromArray. We now get these sites:
$sitesToProblablyAdd = Site::getSites();
return $sitesToProblablyAdd;
} | [
"private",
"function",
"getSitesIdFromPattern",
"(",
"$",
"pattern",
",",
"$",
"_restrictSitesToLogin",
")",
"{",
"// First clear cache",
"Site",
"::",
"clearCache",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"pattern",
")",
")",
"{",
"/** @var Scheduler $scheduler */",
"$",
"scheduler",
"=",
"StaticContainer",
"::",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'Piwik\\Scheduler\\Scheduler'",
")",
";",
"// Then, warm the cache with only the data we should have access to",
"if",
"(",
"Piwik",
"::",
"hasUserSuperUserAccess",
"(",
")",
"// Hack: when this API function is called as a Scheduled Task, Super User status is enforced.",
"// This means this function would return ALL websites in all cases.",
"// Instead, we make sure that only the right set of data is returned",
"&&",
"!",
"$",
"scheduler",
"->",
"isRunningTask",
"(",
")",
")",
"{",
"APISitesManager",
"::",
"getInstance",
"(",
")",
"->",
"getAllSites",
"(",
")",
";",
"}",
"else",
"{",
"APISitesManager",
"::",
"getInstance",
"(",
")",
"->",
"getSitesWithAtLeastViewAccess",
"(",
"$",
"limit",
"=",
"false",
",",
"$",
"_restrictSitesToLogin",
")",
";",
"}",
"}",
"else",
"{",
"$",
"sites",
"=",
"Request",
"::",
"processRequest",
"(",
"'SitesManager.getPatternMatchSites'",
",",
"array",
"(",
"'pattern'",
"=>",
"$",
"pattern",
",",
"// added because caller could overwrite these",
"'limit'",
"=>",
"SettingsPiwik",
"::",
"getWebsitesCountToDisplay",
"(",
")",
",",
"'showColumns'",
"=>",
"''",
",",
"'hideColumns'",
"=>",
"''",
",",
"'format'",
"=>",
"'original'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sites",
")",
")",
"{",
"Site",
"::",
"setSitesFromArray",
"(",
"$",
"sites",
")",
";",
"}",
"}",
"// Both calls above have called Site::setSitesFromArray. We now get these sites:",
"$",
"sitesToProblablyAdd",
"=",
"Site",
"::",
"getSites",
"(",
")",
";",
"return",
"$",
"sitesToProblablyAdd",
";",
"}"
] | Fetches the list of sites which names match the string pattern
@param string $pattern
@param bool $_restrictSitesToLogin
@return array|string | [
"Fetches",
"the",
"list",
"of",
"sites",
"which",
"names",
"match",
"the",
"string",
"pattern"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/MultiSites/API.php#L121-L160 |
209,821 | matomo-org/matomo | plugins/MultiSites/API.php | API.calculateEvolutionPercentages | private function calculateEvolutionPercentages($currentData, $pastData, $apiMetrics)
{
if (get_class($currentData) != get_class($pastData)) { // sanity check for regressions
throw new Exception("Expected \$pastData to be of type " . get_class($currentData) . " - got "
. get_class($pastData) . ".");
}
if ($currentData instanceof DataTable\Map) {
$pastArray = $pastData->getDataTables();
foreach ($currentData->getDataTables() as $subTable) {
$this->calculateEvolutionPercentages($subTable, current($pastArray), $apiMetrics);
next($pastArray);
}
} else {
$extraProcessedMetrics = $currentData->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
foreach ($apiMetrics as $metricSettings) {
$evolutionMetricClass = $this->isEcommerceEvolutionMetric($metricSettings)
? "Piwik\\Plugins\\MultiSites\\Columns\\Metrics\\EcommerceOnlyEvolutionMetric"
: "Piwik\\Plugins\\CoreHome\\Columns\\Metrics\\EvolutionMetric";
$extraProcessedMetrics[] = new $evolutionMetricClass(
$metricSettings[self::METRIC_RECORD_NAME_KEY],
$pastData,
$metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY],
$quotientPrecision = 1
);
}
$currentData->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
}
} | php | private function calculateEvolutionPercentages($currentData, $pastData, $apiMetrics)
{
if (get_class($currentData) != get_class($pastData)) { // sanity check for regressions
throw new Exception("Expected \$pastData to be of type " . get_class($currentData) . " - got "
. get_class($pastData) . ".");
}
if ($currentData instanceof DataTable\Map) {
$pastArray = $pastData->getDataTables();
foreach ($currentData->getDataTables() as $subTable) {
$this->calculateEvolutionPercentages($subTable, current($pastArray), $apiMetrics);
next($pastArray);
}
} else {
$extraProcessedMetrics = $currentData->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
foreach ($apiMetrics as $metricSettings) {
$evolutionMetricClass = $this->isEcommerceEvolutionMetric($metricSettings)
? "Piwik\\Plugins\\MultiSites\\Columns\\Metrics\\EcommerceOnlyEvolutionMetric"
: "Piwik\\Plugins\\CoreHome\\Columns\\Metrics\\EvolutionMetric";
$extraProcessedMetrics[] = new $evolutionMetricClass(
$metricSettings[self::METRIC_RECORD_NAME_KEY],
$pastData,
$metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY],
$quotientPrecision = 1
);
}
$currentData->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics);
}
} | [
"private",
"function",
"calculateEvolutionPercentages",
"(",
"$",
"currentData",
",",
"$",
"pastData",
",",
"$",
"apiMetrics",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"currentData",
")",
"!=",
"get_class",
"(",
"$",
"pastData",
")",
")",
"{",
"// sanity check for regressions",
"throw",
"new",
"Exception",
"(",
"\"Expected \\$pastData to be of type \"",
".",
"get_class",
"(",
"$",
"currentData",
")",
".",
"\" - got \"",
".",
"get_class",
"(",
"$",
"pastData",
")",
".",
"\".\"",
")",
";",
"}",
"if",
"(",
"$",
"currentData",
"instanceof",
"DataTable",
"\\",
"Map",
")",
"{",
"$",
"pastArray",
"=",
"$",
"pastData",
"->",
"getDataTables",
"(",
")",
";",
"foreach",
"(",
"$",
"currentData",
"->",
"getDataTables",
"(",
")",
"as",
"$",
"subTable",
")",
"{",
"$",
"this",
"->",
"calculateEvolutionPercentages",
"(",
"$",
"subTable",
",",
"current",
"(",
"$",
"pastArray",
")",
",",
"$",
"apiMetrics",
")",
";",
"next",
"(",
"$",
"pastArray",
")",
";",
"}",
"}",
"else",
"{",
"$",
"extraProcessedMetrics",
"=",
"$",
"currentData",
"->",
"getMetadata",
"(",
"DataTable",
"::",
"EXTRA_PROCESSED_METRICS_METADATA_NAME",
")",
";",
"foreach",
"(",
"$",
"apiMetrics",
"as",
"$",
"metricSettings",
")",
"{",
"$",
"evolutionMetricClass",
"=",
"$",
"this",
"->",
"isEcommerceEvolutionMetric",
"(",
"$",
"metricSettings",
")",
"?",
"\"Piwik\\\\Plugins\\\\MultiSites\\\\Columns\\\\Metrics\\\\EcommerceOnlyEvolutionMetric\"",
":",
"\"Piwik\\\\Plugins\\\\CoreHome\\\\Columns\\\\Metrics\\\\EvolutionMetric\"",
";",
"$",
"extraProcessedMetrics",
"[",
"]",
"=",
"new",
"$",
"evolutionMetricClass",
"(",
"$",
"metricSettings",
"[",
"self",
"::",
"METRIC_RECORD_NAME_KEY",
"]",
",",
"$",
"pastData",
",",
"$",
"metricSettings",
"[",
"self",
"::",
"METRIC_EVOLUTION_COL_NAME_KEY",
"]",
",",
"$",
"quotientPrecision",
"=",
"1",
")",
";",
"}",
"$",
"currentData",
"->",
"setMetadata",
"(",
"DataTable",
"::",
"EXTRA_PROCESSED_METRICS_METADATA_NAME",
",",
"$",
"extraProcessedMetrics",
")",
";",
"}",
"}"
] | Performs a binary filter of two
DataTables in order to correctly calculate evolution metrics.
@param DataTable|DataTable\Map $currentData
@param DataTable|DataTable\Map $pastData
@param array $apiMetrics The array of string fields to calculate evolution
metrics for.
@throws Exception | [
"Performs",
"a",
"binary",
"filter",
"of",
"two",
"DataTables",
"in",
"order",
"to",
"correctly",
"calculate",
"evolution",
"metrics",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/MultiSites/API.php#L321-L350 |
209,822 | matomo-org/matomo | plugins/MultiSites/API.php | API.setPastTotalVisitsMetadata | private function setPastTotalVisitsMetadata($dataTable, $pastTable)
{
if ($pastTable instanceof DataTable) {
$total = 0;
$metric = 'nb_visits';
$rows = $pastTable->getRows();
$rows = $this->filterRowsForTotalsCalculation($rows);
foreach ($rows as $row) {
$total += $row->getColumn($metric);
}
$dataTable->setMetadata(self::getTotalMetadataName($metric . '_lastdate'), $total);
}
} | php | private function setPastTotalVisitsMetadata($dataTable, $pastTable)
{
if ($pastTable instanceof DataTable) {
$total = 0;
$metric = 'nb_visits';
$rows = $pastTable->getRows();
$rows = $this->filterRowsForTotalsCalculation($rows);
foreach ($rows as $row) {
$total += $row->getColumn($metric);
}
$dataTable->setMetadata(self::getTotalMetadataName($metric . '_lastdate'), $total);
}
} | [
"private",
"function",
"setPastTotalVisitsMetadata",
"(",
"$",
"dataTable",
",",
"$",
"pastTable",
")",
"{",
"if",
"(",
"$",
"pastTable",
"instanceof",
"DataTable",
")",
"{",
"$",
"total",
"=",
"0",
";",
"$",
"metric",
"=",
"'nb_visits'",
";",
"$",
"rows",
"=",
"$",
"pastTable",
"->",
"getRows",
"(",
")",
";",
"$",
"rows",
"=",
"$",
"this",
"->",
"filterRowsForTotalsCalculation",
"(",
"$",
"rows",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"total",
"+=",
"$",
"row",
"->",
"getColumn",
"(",
"$",
"metric",
")",
";",
"}",
"$",
"dataTable",
"->",
"setMetadata",
"(",
"self",
"::",
"getTotalMetadataName",
"(",
"$",
"metric",
".",
"'_lastdate'",
")",
",",
"$",
"total",
")",
";",
"}",
"}"
] | Sets the number of total visits in tha pastTable on the dataTable as metadata.
@param DataTable $dataTable
@param DataTable $pastTable | [
"Sets",
"the",
"number",
"of",
"total",
"visits",
"in",
"tha",
"pastTable",
"on",
"the",
"dataTable",
"as",
"metadata",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/MultiSites/API.php#L463-L478 |
209,823 | matomo-org/matomo | plugins/PrivacyManager/Controller.php | Controller.getDatabaseSize | public function getDatabaseSize()
{
Piwik::checkUserHasSuperUserAccess();
$view = new View('@PrivacyManager/getDatabaseSize');
$forceEstimate = Common::getRequestVar('forceEstimate', 0);
$view->dbStats = $this->getDeleteDBSizeEstimate($getSettingsFromQuery = true, $forceEstimate);
$view->language = LanguagesManager::getLanguageCodeForCurrentUser();
return $view->render();
} | php | public function getDatabaseSize()
{
Piwik::checkUserHasSuperUserAccess();
$view = new View('@PrivacyManager/getDatabaseSize');
$forceEstimate = Common::getRequestVar('forceEstimate', 0);
$view->dbStats = $this->getDeleteDBSizeEstimate($getSettingsFromQuery = true, $forceEstimate);
$view->language = LanguagesManager::getLanguageCodeForCurrentUser();
return $view->render();
} | [
"public",
"function",
"getDatabaseSize",
"(",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"$",
"view",
"=",
"new",
"View",
"(",
"'@PrivacyManager/getDatabaseSize'",
")",
";",
"$",
"forceEstimate",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'forceEstimate'",
",",
"0",
")",
";",
"$",
"view",
"->",
"dbStats",
"=",
"$",
"this",
"->",
"getDeleteDBSizeEstimate",
"(",
"$",
"getSettingsFromQuery",
"=",
"true",
",",
"$",
"forceEstimate",
")",
";",
"$",
"view",
"->",
"language",
"=",
"LanguagesManager",
"::",
"getLanguageCodeForCurrentUser",
"(",
")",
";",
"return",
"$",
"view",
"->",
"render",
"(",
")",
";",
"}"
] | Echo's an HTML chunk describing the current database size, and the estimated space
savings after the scheduled data purge is run. | [
"Echo",
"s",
"an",
"HTML",
"chunk",
"describing",
"the",
"current",
"database",
"size",
"and",
"the",
"estimated",
"space",
"savings",
"after",
"the",
"scheduled",
"data",
"purge",
"is",
"run",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/PrivacyManager/Controller.php#L150-L160 |
209,824 | matomo-org/matomo | plugins/PrivacyManager/Controller.php | Controller.executeDataPurge | public function executeDataPurge()
{
$this->checkDataPurgeAdminSettingsIsEnabled();
Piwik::checkUserHasSuperUserAccess();
$this->checkTokenInUrl();
// if the request isn't a POST, redirect to index
if ($_SERVER["REQUEST_METHOD"] != "POST"
&& !Common::isPhpCliMode()
) {
$this->redirectToIndex('PrivacyManager', 'privacySettings');
return;
}
$settings = PrivacyManager::getPurgeDataSettings();
if ($settings['delete_logs_enable']) {
/** @var LogDataPurger $logDataPurger */
$logDataPurger = StaticContainer::get('Piwik\Plugins\PrivacyManager\LogDataPurger');
$logDataPurger->purgeData($settings['delete_logs_older_than'], true);
}
if ($settings['delete_reports_enable']) {
$reportsPurger = ReportsPurger::make($settings, PrivacyManager::getAllMetricsToKeep());
$reportsPurger->purgeData(true);
}
} | php | public function executeDataPurge()
{
$this->checkDataPurgeAdminSettingsIsEnabled();
Piwik::checkUserHasSuperUserAccess();
$this->checkTokenInUrl();
// if the request isn't a POST, redirect to index
if ($_SERVER["REQUEST_METHOD"] != "POST"
&& !Common::isPhpCliMode()
) {
$this->redirectToIndex('PrivacyManager', 'privacySettings');
return;
}
$settings = PrivacyManager::getPurgeDataSettings();
if ($settings['delete_logs_enable']) {
/** @var LogDataPurger $logDataPurger */
$logDataPurger = StaticContainer::get('Piwik\Plugins\PrivacyManager\LogDataPurger');
$logDataPurger->purgeData($settings['delete_logs_older_than'], true);
}
if ($settings['delete_reports_enable']) {
$reportsPurger = ReportsPurger::make($settings, PrivacyManager::getAllMetricsToKeep());
$reportsPurger->purgeData(true);
}
} | [
"public",
"function",
"executeDataPurge",
"(",
")",
"{",
"$",
"this",
"->",
"checkDataPurgeAdminSettingsIsEnabled",
"(",
")",
";",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"$",
"this",
"->",
"checkTokenInUrl",
"(",
")",
";",
"// if the request isn't a POST, redirect to index",
"if",
"(",
"$",
"_SERVER",
"[",
"\"REQUEST_METHOD\"",
"]",
"!=",
"\"POST\"",
"&&",
"!",
"Common",
"::",
"isPhpCliMode",
"(",
")",
")",
"{",
"$",
"this",
"->",
"redirectToIndex",
"(",
"'PrivacyManager'",
",",
"'privacySettings'",
")",
";",
"return",
";",
"}",
"$",
"settings",
"=",
"PrivacyManager",
"::",
"getPurgeDataSettings",
"(",
")",
";",
"if",
"(",
"$",
"settings",
"[",
"'delete_logs_enable'",
"]",
")",
"{",
"/** @var LogDataPurger $logDataPurger */",
"$",
"logDataPurger",
"=",
"StaticContainer",
"::",
"get",
"(",
"'Piwik\\Plugins\\PrivacyManager\\LogDataPurger'",
")",
";",
"$",
"logDataPurger",
"->",
"purgeData",
"(",
"$",
"settings",
"[",
"'delete_logs_older_than'",
"]",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"settings",
"[",
"'delete_reports_enable'",
"]",
")",
"{",
"$",
"reportsPurger",
"=",
"ReportsPurger",
"::",
"make",
"(",
"$",
"settings",
",",
"PrivacyManager",
"::",
"getAllMetricsToKeep",
"(",
")",
")",
";",
"$",
"reportsPurger",
"->",
"purgeData",
"(",
"true",
")",
";",
"}",
"}"
] | Executes a data purge, deleting raw data and report data using the current config
options. Echo's the result of getDatabaseSize after purging. | [
"Executes",
"a",
"data",
"purge",
"deleting",
"raw",
"data",
"and",
"report",
"data",
"using",
"the",
"current",
"config",
"options",
".",
"Echo",
"s",
"the",
"result",
"of",
"getDatabaseSize",
"after",
"purging",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/PrivacyManager/Controller.php#L217-L242 |
209,825 | matomo-org/matomo | plugins/Overlay/Controller.php | Controller.index | public function index()
{
Piwik::checkUserHasViewAccess($this->idSite);
$template = '@Overlay/index';
if (Config::getInstance()->General['overlay_disable_framed_mode']) {
$template = '@Overlay/index_noframe';
}
$view = new View($template);
$this->setGeneralVariablesView($view);
$view->segment = Request::getRawSegmentFromRequest();
$view->ssl = ProxyHttp::isHttps();
$view->siteUrls = SitesManager\API::getInstance()->getSiteUrlsFromId($this->site->getId());
$this->outputCORSHeaders();
return $view->render();
} | php | public function index()
{
Piwik::checkUserHasViewAccess($this->idSite);
$template = '@Overlay/index';
if (Config::getInstance()->General['overlay_disable_framed_mode']) {
$template = '@Overlay/index_noframe';
}
$view = new View($template);
$this->setGeneralVariablesView($view);
$view->segment = Request::getRawSegmentFromRequest();
$view->ssl = ProxyHttp::isHttps();
$view->siteUrls = SitesManager\API::getInstance()->getSiteUrlsFromId($this->site->getId());
$this->outputCORSHeaders();
return $view->render();
} | [
"public",
"function",
"index",
"(",
")",
"{",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"this",
"->",
"idSite",
")",
";",
"$",
"template",
"=",
"'@Overlay/index'",
";",
"if",
"(",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"General",
"[",
"'overlay_disable_framed_mode'",
"]",
")",
"{",
"$",
"template",
"=",
"'@Overlay/index_noframe'",
";",
"}",
"$",
"view",
"=",
"new",
"View",
"(",
"$",
"template",
")",
";",
"$",
"this",
"->",
"setGeneralVariablesView",
"(",
"$",
"view",
")",
";",
"$",
"view",
"->",
"segment",
"=",
"Request",
"::",
"getRawSegmentFromRequest",
"(",
")",
";",
"$",
"view",
"->",
"ssl",
"=",
"ProxyHttp",
"::",
"isHttps",
"(",
")",
";",
"$",
"view",
"->",
"siteUrls",
"=",
"SitesManager",
"\\",
"API",
"::",
"getInstance",
"(",
")",
"->",
"getSiteUrlsFromId",
"(",
"$",
"this",
"->",
"site",
"->",
"getId",
"(",
")",
")",
";",
"$",
"this",
"->",
"outputCORSHeaders",
"(",
")",
";",
"return",
"$",
"view",
"->",
"render",
"(",
")",
";",
"}"
] | The index of the plugin | [
"The",
"index",
"of",
"the",
"plugin"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Overlay/Controller.php#L42-L61 |
209,826 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php | Zend_Db_Adapter_Pdo_Ibm_Db2.describeTable | public function describeTable($tableName, $schemaName = null)
{
$sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
c.typename, c.default, c.nulls, c.length, c.scale,
c.identity, tc.type AS tabconsttype, k.colseq
FROM syscat.columns c
LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
ON (k.tabschema = tc.tabschema
AND k.tabname = tc.tabname
AND tc.type = 'P'))
ON (c.tabschema = k.tabschema
AND c.tabname = k.tabname
AND c.colname = k.colname)
WHERE "
. $this->_adapter->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->_adapter->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY c.colno";
$desc = array();
$stmt = $this->_adapter->query($sql);
/**
* To avoid case issues, fetch using FETCH_NUM
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
/**
* The ordering of columns is defined by the query so we can map
* to variables to improve readability
*/
$tabschema = 0;
$tabname = 1;
$colname = 2;
$colno = 3;
$typename = 4;
$default = 5;
$nulls = 6;
$length = 7;
$scale = 8;
$identityCol = 9;
$tabconstype = 10;
$colseq = 11;
foreach ($result as $key => $row) {
list ($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$tabconstype] == 'P') {
$primary = true;
$primaryPosition = $row[$colseq];
}
/**
* In IBM DB2, an column can be IDENTITY
* even if it is not part of the PRIMARY KEY.
*/
if ($row[$identityCol] == 'Y') {
$identity = true;
}
$desc[$this->_adapter->foldCase($row[$colname])] = array(
'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
'COLUMN_POSITION' => $row[$colno]+1,
'DATA_TYPE' => $row[$typename],
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) ($row[$nulls] == 'Y'),
'LENGTH' => $row[$length],
'SCALE' => $row[$scale],
'PRECISION' => ($row[$typename] == 'DECIMAL' ? $row[$length] : 0),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
} | php | public function describeTable($tableName, $schemaName = null)
{
$sql = "SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,
c.typename, c.default, c.nulls, c.length, c.scale,
c.identity, tc.type AS tabconsttype, k.colseq
FROM syscat.columns c
LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc
ON (k.tabschema = tc.tabschema
AND k.tabname = tc.tabname
AND tc.type = 'P'))
ON (c.tabschema = k.tabschema
AND c.tabname = k.tabname
AND c.colname = k.colname)
WHERE "
. $this->_adapter->quoteInto('UPPER(c.tabname) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->_adapter->quoteInto(' AND UPPER(c.tabschema) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY c.colno";
$desc = array();
$stmt = $this->_adapter->query($sql);
/**
* To avoid case issues, fetch using FETCH_NUM
*/
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
/**
* The ordering of columns is defined by the query so we can map
* to variables to improve readability
*/
$tabschema = 0;
$tabname = 1;
$colname = 2;
$colno = 3;
$typename = 4;
$default = 5;
$nulls = 6;
$length = 7;
$scale = 8;
$identityCol = 9;
$tabconstype = 10;
$colseq = 11;
foreach ($result as $key => $row) {
list ($primary, $primaryPosition, $identity) = array(false, null, false);
if ($row[$tabconstype] == 'P') {
$primary = true;
$primaryPosition = $row[$colseq];
}
/**
* In IBM DB2, an column can be IDENTITY
* even if it is not part of the PRIMARY KEY.
*/
if ($row[$identityCol] == 'Y') {
$identity = true;
}
$desc[$this->_adapter->foldCase($row[$colname])] = array(
'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
'COLUMN_POSITION' => $row[$colno]+1,
'DATA_TYPE' => $row[$typename],
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) ($row[$nulls] == 'Y'),
'LENGTH' => $row[$length],
'SCALE' => $row[$scale],
'PRECISION' => ($row[$typename] == 'DECIMAL' ? $row[$length] : 0),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
} | [
"public",
"function",
"describeTable",
"(",
"$",
"tableName",
",",
"$",
"schemaName",
"=",
"null",
")",
"{",
"$",
"sql",
"=",
"\"SELECT DISTINCT c.tabschema, c.tabname, c.colname, c.colno,\n c.typename, c.default, c.nulls, c.length, c.scale,\n c.identity, tc.type AS tabconsttype, k.colseq\n FROM syscat.columns c\n LEFT JOIN (syscat.keycoluse k JOIN syscat.tabconst tc\n ON (k.tabschema = tc.tabschema\n AND k.tabname = tc.tabname\n AND tc.type = 'P'))\n ON (c.tabschema = k.tabschema\n AND c.tabname = k.tabname\n AND c.colname = k.colname)\n WHERE \"",
".",
"$",
"this",
"->",
"_adapter",
"->",
"quoteInto",
"(",
"'UPPER(c.tabname) = UPPER(?)'",
",",
"$",
"tableName",
")",
";",
"if",
"(",
"$",
"schemaName",
")",
"{",
"$",
"sql",
".=",
"$",
"this",
"->",
"_adapter",
"->",
"quoteInto",
"(",
"' AND UPPER(c.tabschema) = UPPER(?)'",
",",
"$",
"schemaName",
")",
";",
"}",
"$",
"sql",
".=",
"\" ORDER BY c.colno\"",
";",
"$",
"desc",
"=",
"array",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"/**\n * To avoid case issues, fetch using FETCH_NUM\n */",
"$",
"result",
"=",
"$",
"stmt",
"->",
"fetchAll",
"(",
"Zend_Db",
"::",
"FETCH_NUM",
")",
";",
"/**\n * The ordering of columns is defined by the query so we can map\n * to variables to improve readability\n */",
"$",
"tabschema",
"=",
"0",
";",
"$",
"tabname",
"=",
"1",
";",
"$",
"colname",
"=",
"2",
";",
"$",
"colno",
"=",
"3",
";",
"$",
"typename",
"=",
"4",
";",
"$",
"default",
"=",
"5",
";",
"$",
"nulls",
"=",
"6",
";",
"$",
"length",
"=",
"7",
";",
"$",
"scale",
"=",
"8",
";",
"$",
"identityCol",
"=",
"9",
";",
"$",
"tabconstype",
"=",
"10",
";",
"$",
"colseq",
"=",
"11",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"list",
"(",
"$",
"primary",
",",
"$",
"primaryPosition",
",",
"$",
"identity",
")",
"=",
"array",
"(",
"false",
",",
"null",
",",
"false",
")",
";",
"if",
"(",
"$",
"row",
"[",
"$",
"tabconstype",
"]",
"==",
"'P'",
")",
"{",
"$",
"primary",
"=",
"true",
";",
"$",
"primaryPosition",
"=",
"$",
"row",
"[",
"$",
"colseq",
"]",
";",
"}",
"/**\n * In IBM DB2, an column can be IDENTITY\n * even if it is not part of the PRIMARY KEY.\n */",
"if",
"(",
"$",
"row",
"[",
"$",
"identityCol",
"]",
"==",
"'Y'",
")",
"{",
"$",
"identity",
"=",
"true",
";",
"}",
"$",
"desc",
"[",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"colname",
"]",
")",
"]",
"=",
"array",
"(",
"'SCHEMA_NAME'",
"=>",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"tabschema",
"]",
")",
",",
"'TABLE_NAME'",
"=>",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"tabname",
"]",
")",
",",
"'COLUMN_NAME'",
"=>",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"colname",
"]",
")",
",",
"'COLUMN_POSITION'",
"=>",
"$",
"row",
"[",
"$",
"colno",
"]",
"+",
"1",
",",
"'DATA_TYPE'",
"=>",
"$",
"row",
"[",
"$",
"typename",
"]",
",",
"'DEFAULT'",
"=>",
"$",
"row",
"[",
"$",
"default",
"]",
",",
"'NULLABLE'",
"=>",
"(",
"bool",
")",
"(",
"$",
"row",
"[",
"$",
"nulls",
"]",
"==",
"'Y'",
")",
",",
"'LENGTH'",
"=>",
"$",
"row",
"[",
"$",
"length",
"]",
",",
"'SCALE'",
"=>",
"$",
"row",
"[",
"$",
"scale",
"]",
",",
"'PRECISION'",
"=>",
"(",
"$",
"row",
"[",
"$",
"typename",
"]",
"==",
"'DECIMAL'",
"?",
"$",
"row",
"[",
"$",
"length",
"]",
":",
"0",
")",
",",
"'UNSIGNED'",
"=>",
"false",
",",
"'PRIMARY'",
"=>",
"$",
"primary",
",",
"'PRIMARY_POSITION'",
"=>",
"$",
"primaryPosition",
",",
"'IDENTITY'",
"=>",
"$",
"identity",
")",
";",
"}",
"return",
"$",
"desc",
";",
"}"
] | DB2 catalog lookup for describe table
@param string $tableName
@param string $schemaName OPTIONAL
@return array | [
"DB2",
"catalog",
"lookup",
"for",
"describe",
"table"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php#L77-L155 |
209,827 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php | Zend_Db_Adapter_Pdo_Ibm_Db2.lastSequenceId | public function lastSequenceId($sequenceName)
{
$sql = 'SELECT PREVVAL FOR '.$this->_adapter->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
$value = $this->_adapter->fetchOne($sql);
return $value;
} | php | public function lastSequenceId($sequenceName)
{
$sql = 'SELECT PREVVAL FOR '.$this->_adapter->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
$value = $this->_adapter->fetchOne($sql);
return $value;
} | [
"public",
"function",
"lastSequenceId",
"(",
"$",
"sequenceName",
")",
"{",
"$",
"sql",
"=",
"'SELECT PREVVAL FOR '",
".",
"$",
"this",
"->",
"_adapter",
"->",
"quoteIdentifier",
"(",
"$",
"sequenceName",
")",
".",
"' AS VAL FROM SYSIBM.SYSDUMMY1'",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"fetchOne",
"(",
"$",
"sql",
")",
";",
"return",
"$",
"value",
";",
"}"
] | DB2-specific last sequence id
@param string $sequenceName
@return integer | [
"DB2",
"-",
"specific",
"last",
"sequence",
"id"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Ibm/Db2.php#L209-L214 |
209,828 | matomo-org/matomo | core/Tracker/PageUrl.php | PageUrl.excludeQueryParametersFromUrl | public static function excludeQueryParametersFromUrl($originalUrl, $idSite)
{
$originalUrl = self::cleanupUrl($originalUrl);
$parsedUrl = @parse_url($originalUrl);
$parsedUrl = self::cleanupHostAndHashTag($parsedUrl, $idSite);
$parametersToExclude = self::getQueryParametersToExclude($idSite);
if (empty($parsedUrl['query'])) {
if (empty($parsedUrl['fragment'])) {
return UrlHelper::getParseUrlReverse($parsedUrl);
}
// Exclude from the hash tag as well
$queryParameters = UrlHelper::getArrayFromQueryString($parsedUrl['fragment']);
$parsedUrl['fragment'] = UrlHelper::getQueryStringWithExcludedParameters($queryParameters, $parametersToExclude);
$url = UrlHelper::getParseUrlReverse($parsedUrl);
return $url;
}
$queryParameters = UrlHelper::getArrayFromQueryString($parsedUrl['query']);
$parsedUrl['query'] = UrlHelper::getQueryStringWithExcludedParameters($queryParameters, $parametersToExclude);
$url = UrlHelper::getParseUrlReverse($parsedUrl);
return $url;
} | php | public static function excludeQueryParametersFromUrl($originalUrl, $idSite)
{
$originalUrl = self::cleanupUrl($originalUrl);
$parsedUrl = @parse_url($originalUrl);
$parsedUrl = self::cleanupHostAndHashTag($parsedUrl, $idSite);
$parametersToExclude = self::getQueryParametersToExclude($idSite);
if (empty($parsedUrl['query'])) {
if (empty($parsedUrl['fragment'])) {
return UrlHelper::getParseUrlReverse($parsedUrl);
}
// Exclude from the hash tag as well
$queryParameters = UrlHelper::getArrayFromQueryString($parsedUrl['fragment']);
$parsedUrl['fragment'] = UrlHelper::getQueryStringWithExcludedParameters($queryParameters, $parametersToExclude);
$url = UrlHelper::getParseUrlReverse($parsedUrl);
return $url;
}
$queryParameters = UrlHelper::getArrayFromQueryString($parsedUrl['query']);
$parsedUrl['query'] = UrlHelper::getQueryStringWithExcludedParameters($queryParameters, $parametersToExclude);
$url = UrlHelper::getParseUrlReverse($parsedUrl);
return $url;
} | [
"public",
"static",
"function",
"excludeQueryParametersFromUrl",
"(",
"$",
"originalUrl",
",",
"$",
"idSite",
")",
"{",
"$",
"originalUrl",
"=",
"self",
"::",
"cleanupUrl",
"(",
"$",
"originalUrl",
")",
";",
"$",
"parsedUrl",
"=",
"@",
"parse_url",
"(",
"$",
"originalUrl",
")",
";",
"$",
"parsedUrl",
"=",
"self",
"::",
"cleanupHostAndHashTag",
"(",
"$",
"parsedUrl",
",",
"$",
"idSite",
")",
";",
"$",
"parametersToExclude",
"=",
"self",
"::",
"getQueryParametersToExclude",
"(",
"$",
"idSite",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"parsedUrl",
"[",
"'query'",
"]",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"parsedUrl",
"[",
"'fragment'",
"]",
")",
")",
"{",
"return",
"UrlHelper",
"::",
"getParseUrlReverse",
"(",
"$",
"parsedUrl",
")",
";",
"}",
"// Exclude from the hash tag as well",
"$",
"queryParameters",
"=",
"UrlHelper",
"::",
"getArrayFromQueryString",
"(",
"$",
"parsedUrl",
"[",
"'fragment'",
"]",
")",
";",
"$",
"parsedUrl",
"[",
"'fragment'",
"]",
"=",
"UrlHelper",
"::",
"getQueryStringWithExcludedParameters",
"(",
"$",
"queryParameters",
",",
"$",
"parametersToExclude",
")",
";",
"$",
"url",
"=",
"UrlHelper",
"::",
"getParseUrlReverse",
"(",
"$",
"parsedUrl",
")",
";",
"return",
"$",
"url",
";",
"}",
"$",
"queryParameters",
"=",
"UrlHelper",
"::",
"getArrayFromQueryString",
"(",
"$",
"parsedUrl",
"[",
"'query'",
"]",
")",
";",
"$",
"parsedUrl",
"[",
"'query'",
"]",
"=",
"UrlHelper",
"::",
"getQueryStringWithExcludedParameters",
"(",
"$",
"queryParameters",
",",
"$",
"parametersToExclude",
")",
";",
"$",
"url",
"=",
"UrlHelper",
"::",
"getParseUrlReverse",
"(",
"$",
"parsedUrl",
")",
";",
"return",
"$",
"url",
";",
"}"
] | Given the Input URL, will exclude all query parameters set for this site
@static
@param $originalUrl
@param $idSite
@return bool|string Returned URL is HTML entities decoded | [
"Given",
"the",
"Input",
"URL",
"will",
"exclude",
"all",
"query",
"parameters",
"set",
"for",
"this",
"site"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/PageUrl.php#L39-L65 |
209,829 | matomo-org/matomo | core/Tracker/PageUrl.php | PageUrl.getQueryParametersToExclude | public static function getQueryParametersToExclude($idSite)
{
$campaignTrackingParameters = Common::getCampaignParameters();
$campaignTrackingParameters = array_merge(
$campaignTrackingParameters[0], // campaign name parameters
$campaignTrackingParameters[1] // campaign keyword parameters
);
$website = Cache::getCacheWebsiteAttributes($idSite);
$excludedParameters = self::getExcludedParametersFromWebsite($website);
$parametersToExclude = array_merge($excludedParameters,
self::getUrlParameterNamesToExcludeFromUrl(),
$campaignTrackingParameters);
/**
* Triggered before setting the action url in Piwik\Tracker\Action so plugins can register
* parameters to be excluded from the tracking URL (e.g. campaign parameters).
*
* @param array &$parametersToExclude An array of parameters to exclude from the tracking url.
*/
Piwik::postEvent('Tracker.PageUrl.getQueryParametersToExclude', array(&$parametersToExclude));
if (!empty($parametersToExclude)) {
Common::printDebug('Excluding parameters "' . implode(',', $parametersToExclude) . '" from URL');
}
$parametersToExclude = array_map('strtolower', $parametersToExclude);
return $parametersToExclude;
} | php | public static function getQueryParametersToExclude($idSite)
{
$campaignTrackingParameters = Common::getCampaignParameters();
$campaignTrackingParameters = array_merge(
$campaignTrackingParameters[0], // campaign name parameters
$campaignTrackingParameters[1] // campaign keyword parameters
);
$website = Cache::getCacheWebsiteAttributes($idSite);
$excludedParameters = self::getExcludedParametersFromWebsite($website);
$parametersToExclude = array_merge($excludedParameters,
self::getUrlParameterNamesToExcludeFromUrl(),
$campaignTrackingParameters);
/**
* Triggered before setting the action url in Piwik\Tracker\Action so plugins can register
* parameters to be excluded from the tracking URL (e.g. campaign parameters).
*
* @param array &$parametersToExclude An array of parameters to exclude from the tracking url.
*/
Piwik::postEvent('Tracker.PageUrl.getQueryParametersToExclude', array(&$parametersToExclude));
if (!empty($parametersToExclude)) {
Common::printDebug('Excluding parameters "' . implode(',', $parametersToExclude) . '" from URL');
}
$parametersToExclude = array_map('strtolower', $parametersToExclude);
return $parametersToExclude;
} | [
"public",
"static",
"function",
"getQueryParametersToExclude",
"(",
"$",
"idSite",
")",
"{",
"$",
"campaignTrackingParameters",
"=",
"Common",
"::",
"getCampaignParameters",
"(",
")",
";",
"$",
"campaignTrackingParameters",
"=",
"array_merge",
"(",
"$",
"campaignTrackingParameters",
"[",
"0",
"]",
",",
"// campaign name parameters",
"$",
"campaignTrackingParameters",
"[",
"1",
"]",
"// campaign keyword parameters",
")",
";",
"$",
"website",
"=",
"Cache",
"::",
"getCacheWebsiteAttributes",
"(",
"$",
"idSite",
")",
";",
"$",
"excludedParameters",
"=",
"self",
"::",
"getExcludedParametersFromWebsite",
"(",
"$",
"website",
")",
";",
"$",
"parametersToExclude",
"=",
"array_merge",
"(",
"$",
"excludedParameters",
",",
"self",
"::",
"getUrlParameterNamesToExcludeFromUrl",
"(",
")",
",",
"$",
"campaignTrackingParameters",
")",
";",
"/**\n * Triggered before setting the action url in Piwik\\Tracker\\Action so plugins can register\n * parameters to be excluded from the tracking URL (e.g. campaign parameters).\n *\n * @param array &$parametersToExclude An array of parameters to exclude from the tracking url.\n */",
"Piwik",
"::",
"postEvent",
"(",
"'Tracker.PageUrl.getQueryParametersToExclude'",
",",
"array",
"(",
"&",
"$",
"parametersToExclude",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parametersToExclude",
")",
")",
"{",
"Common",
"::",
"printDebug",
"(",
"'Excluding parameters \"'",
".",
"implode",
"(",
"','",
",",
"$",
"parametersToExclude",
")",
".",
"'\" from URL'",
")",
";",
"}",
"$",
"parametersToExclude",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"parametersToExclude",
")",
";",
"return",
"$",
"parametersToExclude",
";",
"}"
] | Returns the array of parameters names that must be excluded from the Query String in all tracked URLs
@static
@param $idSite
@return array | [
"Returns",
"the",
"array",
"of",
"parameters",
"names",
"that",
"must",
"be",
"excluded",
"from",
"the",
"Query",
"String",
"in",
"all",
"tracked",
"URLs"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/PageUrl.php#L73-L103 |
209,830 | matomo-org/matomo | core/Tracker/PageUrl.php | PageUrl.getUrlParameterNamesToExcludeFromUrl | protected static function getUrlParameterNamesToExcludeFromUrl()
{
$paramsToExclude = Config::getInstance()->Tracker['url_query_parameter_to_exclude_from_url'];
$paramsToExclude = explode(",", $paramsToExclude);
$paramsToExclude = array_map('trim', $paramsToExclude);
return $paramsToExclude;
} | php | protected static function getUrlParameterNamesToExcludeFromUrl()
{
$paramsToExclude = Config::getInstance()->Tracker['url_query_parameter_to_exclude_from_url'];
$paramsToExclude = explode(",", $paramsToExclude);
$paramsToExclude = array_map('trim', $paramsToExclude);
return $paramsToExclude;
} | [
"protected",
"static",
"function",
"getUrlParameterNamesToExcludeFromUrl",
"(",
")",
"{",
"$",
"paramsToExclude",
"=",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"Tracker",
"[",
"'url_query_parameter_to_exclude_from_url'",
"]",
";",
"$",
"paramsToExclude",
"=",
"explode",
"(",
"\",\"",
",",
"$",
"paramsToExclude",
")",
";",
"$",
"paramsToExclude",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"paramsToExclude",
")",
";",
"return",
"$",
"paramsToExclude",
";",
"}"
] | Returns the list of URL query parameters that should be removed from the tracked URL query string.
@return array | [
"Returns",
"the",
"list",
"of",
"URL",
"query",
"parameters",
"that",
"should",
"be",
"removed",
"from",
"the",
"tracked",
"URL",
"query",
"string",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/PageUrl.php#L110-L116 |
209,831 | matomo-org/matomo | core/Tracker/PageUrl.php | PageUrl.reconstructNormalizedUrl | public static function reconstructNormalizedUrl($url, $prefixId)
{
$map = array_flip(self::$urlPrefixMap);
if ($prefixId !== null && isset($map[$prefixId])) {
$fullUrl = $map[$prefixId] . $url;
} else {
$fullUrl = $url;
}
// Clean up host & hash tags, for URLs
$parsedUrl = @parse_url($fullUrl);
$parsedUrl = PageUrl::cleanupHostAndHashTag($parsedUrl);
$url = UrlHelper::getParseUrlReverse($parsedUrl);
if (!empty($url)) {
return $url;
}
return $fullUrl;
} | php | public static function reconstructNormalizedUrl($url, $prefixId)
{
$map = array_flip(self::$urlPrefixMap);
if ($prefixId !== null && isset($map[$prefixId])) {
$fullUrl = $map[$prefixId] . $url;
} else {
$fullUrl = $url;
}
// Clean up host & hash tags, for URLs
$parsedUrl = @parse_url($fullUrl);
$parsedUrl = PageUrl::cleanupHostAndHashTag($parsedUrl);
$url = UrlHelper::getParseUrlReverse($parsedUrl);
if (!empty($url)) {
return $url;
}
return $fullUrl;
} | [
"public",
"static",
"function",
"reconstructNormalizedUrl",
"(",
"$",
"url",
",",
"$",
"prefixId",
")",
"{",
"$",
"map",
"=",
"array_flip",
"(",
"self",
"::",
"$",
"urlPrefixMap",
")",
";",
"if",
"(",
"$",
"prefixId",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"map",
"[",
"$",
"prefixId",
"]",
")",
")",
"{",
"$",
"fullUrl",
"=",
"$",
"map",
"[",
"$",
"prefixId",
"]",
".",
"$",
"url",
";",
"}",
"else",
"{",
"$",
"fullUrl",
"=",
"$",
"url",
";",
"}",
"// Clean up host & hash tags, for URLs",
"$",
"parsedUrl",
"=",
"@",
"parse_url",
"(",
"$",
"fullUrl",
")",
";",
"$",
"parsedUrl",
"=",
"PageUrl",
"::",
"cleanupHostAndHashTag",
"(",
"$",
"parsedUrl",
")",
";",
"$",
"url",
"=",
"UrlHelper",
"::",
"getParseUrlReverse",
"(",
"$",
"parsedUrl",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"url",
")",
")",
"{",
"return",
"$",
"url",
";",
"}",
"return",
"$",
"fullUrl",
";",
"}"
] | Build the full URL from the prefix ID and the rest.
@param string $url
@param integer $prefixId
@return string | [
"Build",
"the",
"full",
"URL",
"from",
"the",
"prefix",
"ID",
"and",
"the",
"rest",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/PageUrl.php#L310-L330 |
209,832 | matomo-org/matomo | core/Tracker/PageUrl.php | PageUrl.normalizeUrl | public static function normalizeUrl($url)
{
foreach (self::$urlPrefixMap as $prefix => $id) {
if (strtolower(substr($url, 0, strlen($prefix))) == $prefix) {
return array(
'url' => substr($url, strlen($prefix)),
'prefixId' => $id
);
}
}
return array('url' => $url, 'prefixId' => null);
} | php | public static function normalizeUrl($url)
{
foreach (self::$urlPrefixMap as $prefix => $id) {
if (strtolower(substr($url, 0, strlen($prefix))) == $prefix) {
return array(
'url' => substr($url, strlen($prefix)),
'prefixId' => $id
);
}
}
return array('url' => $url, 'prefixId' => null);
} | [
"public",
"static",
"function",
"normalizeUrl",
"(",
"$",
"url",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"urlPrefixMap",
"as",
"$",
"prefix",
"=>",
"$",
"id",
")",
"{",
"if",
"(",
"strtolower",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
")",
"==",
"$",
"prefix",
")",
"{",
"return",
"array",
"(",
"'url'",
"=>",
"substr",
"(",
"$",
"url",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
",",
"'prefixId'",
"=>",
"$",
"id",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'url'",
"=>",
"$",
"url",
",",
"'prefixId'",
"=>",
"null",
")",
";",
"}"
] | Extract the prefix from a URL.
Return the prefix ID and the rest.
@param string $url
@return array | [
"Extract",
"the",
"prefix",
"from",
"a",
"URL",
".",
"Return",
"the",
"prefix",
"ID",
"and",
"the",
"rest",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/PageUrl.php#L339-L351 |
209,833 | matomo-org/matomo | plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php | Evolution.getSeriesLabel | private function getSeriesLabel($rowLabel, $columnName)
{
$metricLabel = @$this->properties['translations'][$columnName];
if ($rowLabel !== false) {
// eg. "Yahoo! (Visits)"
$label = "$rowLabel ($metricLabel)";
} else {
// eg. "Visits"
$label = $metricLabel;
}
return $label;
} | php | private function getSeriesLabel($rowLabel, $columnName)
{
$metricLabel = @$this->properties['translations'][$columnName];
if ($rowLabel !== false) {
// eg. "Yahoo! (Visits)"
$label = "$rowLabel ($metricLabel)";
} else {
// eg. "Visits"
$label = $metricLabel;
}
return $label;
} | [
"private",
"function",
"getSeriesLabel",
"(",
"$",
"rowLabel",
",",
"$",
"columnName",
")",
"{",
"$",
"metricLabel",
"=",
"@",
"$",
"this",
"->",
"properties",
"[",
"'translations'",
"]",
"[",
"$",
"columnName",
"]",
";",
"if",
"(",
"$",
"rowLabel",
"!==",
"false",
")",
"{",
"// eg. \"Yahoo! (Visits)\"",
"$",
"label",
"=",
"\"$rowLabel ($metricLabel)\"",
";",
"}",
"else",
"{",
"// eg. \"Visits\"",
"$",
"label",
"=",
"$",
"metricLabel",
";",
"}",
"return",
"$",
"label",
";",
"}"
] | Derive the series label from the row label and the column name.
If the row label is set, both the label and the column name are displayed.
@param string $rowLabel
@param string $columnName
@return string | [
"Derive",
"the",
"series",
"label",
"from",
"the",
"row",
"label",
"and",
"the",
"column",
"name",
".",
"If",
"the",
"row",
"label",
"is",
"set",
"both",
"the",
"label",
"and",
"the",
"column",
"name",
"are",
"displayed",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php#L120-L133 |
209,834 | matomo-org/matomo | core/DataTable/Filter/PivotByDimension.php | PivotByDimension.filter | public function filter($table)
{
// set of all column names in the pivoted table mapped with the sum of all column
// values. used later in truncating and ordering the pivoted table's columns.
$columnSet = array();
// if no pivot column was set, use the first one found in the row
if (empty($this->pivotColumn)) {
$this->pivotColumn = $this->getNameOfFirstNonLabelColumnInTable($table);
}
Log::debug("PivotByDimension::%s: pivoting table with pivot column = %s", __FUNCTION__, $this->pivotColumn);
foreach ($table->getRows() as $row) {
$row->setColumns(array('label' => $row->getColumn('label')));
$associatedTable = $this->getIntersectedTable($table, $row);
if (!empty($associatedTable)) {
foreach ($associatedTable->getRows() as $columnRow) {
$pivotTableColumn = $columnRow->getColumn('label');
$columnValue = $this->getColumnValue($columnRow, $this->pivotColumn);
if (isset($columnSet[$pivotTableColumn])) {
$columnSet[$pivotTableColumn] += $columnValue;
} else {
$columnSet[$pivotTableColumn] = $columnValue;
}
$row->setColumn($pivotTableColumn, $columnValue);
}
Common::destroy($associatedTable);
unset($associatedTable);
}
}
Log::debug("PivotByDimension::%s: pivoted columns set: %s", __FUNCTION__, $columnSet);
$others = Piwik::translate('General_Others');
$defaultRow = $this->getPivotTableDefaultRowFromColumnSummary($columnSet, $others);
Log::debug("PivotByDimension::%s: un-prepended default row: %s", __FUNCTION__, $defaultRow);
// post process pivoted datatable
foreach ($table->getRows() as $row) {
// remove subtables from rows
$row->removeSubtable();
$row->deleteMetadata('idsubdatatable_in_db');
// use default row to ensure column ordering and add missing columns/aggregate cut-off columns
$orderedColumns = $defaultRow;
foreach ($row->getColumns() as $name => $value) {
if (isset($orderedColumns[$name])) {
$orderedColumns[$name] = $value;
} else {
$orderedColumns[$others] += $value;
}
}
$row->setColumns($orderedColumns);
}
$table->clearQueuedFilters(); // TODO: shouldn't clear queued filters, but we can't wait for them to be run
// since generic filters are run before them. remove after refactoring
// processed metrics.
// prepend numerals to columns in a queued filter (this way, disable_queued_filters can be used
// to get machine readable data from the API if needed)
$prependedColumnNames = $this->getOrderedColumnsWithPrependedNumerals($defaultRow, $others);
Log::debug("PivotByDimension::%s: prepended column name mapping: %s", __FUNCTION__, $prependedColumnNames);
$table->queueFilter(function (DataTable $table) use ($prependedColumnNames) {
foreach ($table->getRows() as $row) {
$row->setColumns(array_combine($prependedColumnNames, $row->getColumns()));
}
});
} | php | public function filter($table)
{
// set of all column names in the pivoted table mapped with the sum of all column
// values. used later in truncating and ordering the pivoted table's columns.
$columnSet = array();
// if no pivot column was set, use the first one found in the row
if (empty($this->pivotColumn)) {
$this->pivotColumn = $this->getNameOfFirstNonLabelColumnInTable($table);
}
Log::debug("PivotByDimension::%s: pivoting table with pivot column = %s", __FUNCTION__, $this->pivotColumn);
foreach ($table->getRows() as $row) {
$row->setColumns(array('label' => $row->getColumn('label')));
$associatedTable = $this->getIntersectedTable($table, $row);
if (!empty($associatedTable)) {
foreach ($associatedTable->getRows() as $columnRow) {
$pivotTableColumn = $columnRow->getColumn('label');
$columnValue = $this->getColumnValue($columnRow, $this->pivotColumn);
if (isset($columnSet[$pivotTableColumn])) {
$columnSet[$pivotTableColumn] += $columnValue;
} else {
$columnSet[$pivotTableColumn] = $columnValue;
}
$row->setColumn($pivotTableColumn, $columnValue);
}
Common::destroy($associatedTable);
unset($associatedTable);
}
}
Log::debug("PivotByDimension::%s: pivoted columns set: %s", __FUNCTION__, $columnSet);
$others = Piwik::translate('General_Others');
$defaultRow = $this->getPivotTableDefaultRowFromColumnSummary($columnSet, $others);
Log::debug("PivotByDimension::%s: un-prepended default row: %s", __FUNCTION__, $defaultRow);
// post process pivoted datatable
foreach ($table->getRows() as $row) {
// remove subtables from rows
$row->removeSubtable();
$row->deleteMetadata('idsubdatatable_in_db');
// use default row to ensure column ordering and add missing columns/aggregate cut-off columns
$orderedColumns = $defaultRow;
foreach ($row->getColumns() as $name => $value) {
if (isset($orderedColumns[$name])) {
$orderedColumns[$name] = $value;
} else {
$orderedColumns[$others] += $value;
}
}
$row->setColumns($orderedColumns);
}
$table->clearQueuedFilters(); // TODO: shouldn't clear queued filters, but we can't wait for them to be run
// since generic filters are run before them. remove after refactoring
// processed metrics.
// prepend numerals to columns in a queued filter (this way, disable_queued_filters can be used
// to get machine readable data from the API if needed)
$prependedColumnNames = $this->getOrderedColumnsWithPrependedNumerals($defaultRow, $others);
Log::debug("PivotByDimension::%s: prepended column name mapping: %s", __FUNCTION__, $prependedColumnNames);
$table->queueFilter(function (DataTable $table) use ($prependedColumnNames) {
foreach ($table->getRows() as $row) {
$row->setColumns(array_combine($prependedColumnNames, $row->getColumns()));
}
});
} | [
"public",
"function",
"filter",
"(",
"$",
"table",
")",
"{",
"// set of all column names in the pivoted table mapped with the sum of all column",
"// values. used later in truncating and ordering the pivoted table's columns.",
"$",
"columnSet",
"=",
"array",
"(",
")",
";",
"// if no pivot column was set, use the first one found in the row",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"pivotColumn",
")",
")",
"{",
"$",
"this",
"->",
"pivotColumn",
"=",
"$",
"this",
"->",
"getNameOfFirstNonLabelColumnInTable",
"(",
"$",
"table",
")",
";",
"}",
"Log",
"::",
"debug",
"(",
"\"PivotByDimension::%s: pivoting table with pivot column = %s\"",
",",
"__FUNCTION__",
",",
"$",
"this",
"->",
"pivotColumn",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"row",
"->",
"setColumns",
"(",
"array",
"(",
"'label'",
"=>",
"$",
"row",
"->",
"getColumn",
"(",
"'label'",
")",
")",
")",
";",
"$",
"associatedTable",
"=",
"$",
"this",
"->",
"getIntersectedTable",
"(",
"$",
"table",
",",
"$",
"row",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"associatedTable",
")",
")",
"{",
"foreach",
"(",
"$",
"associatedTable",
"->",
"getRows",
"(",
")",
"as",
"$",
"columnRow",
")",
"{",
"$",
"pivotTableColumn",
"=",
"$",
"columnRow",
"->",
"getColumn",
"(",
"'label'",
")",
";",
"$",
"columnValue",
"=",
"$",
"this",
"->",
"getColumnValue",
"(",
"$",
"columnRow",
",",
"$",
"this",
"->",
"pivotColumn",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"columnSet",
"[",
"$",
"pivotTableColumn",
"]",
")",
")",
"{",
"$",
"columnSet",
"[",
"$",
"pivotTableColumn",
"]",
"+=",
"$",
"columnValue",
";",
"}",
"else",
"{",
"$",
"columnSet",
"[",
"$",
"pivotTableColumn",
"]",
"=",
"$",
"columnValue",
";",
"}",
"$",
"row",
"->",
"setColumn",
"(",
"$",
"pivotTableColumn",
",",
"$",
"columnValue",
")",
";",
"}",
"Common",
"::",
"destroy",
"(",
"$",
"associatedTable",
")",
";",
"unset",
"(",
"$",
"associatedTable",
")",
";",
"}",
"}",
"Log",
"::",
"debug",
"(",
"\"PivotByDimension::%s: pivoted columns set: %s\"",
",",
"__FUNCTION__",
",",
"$",
"columnSet",
")",
";",
"$",
"others",
"=",
"Piwik",
"::",
"translate",
"(",
"'General_Others'",
")",
";",
"$",
"defaultRow",
"=",
"$",
"this",
"->",
"getPivotTableDefaultRowFromColumnSummary",
"(",
"$",
"columnSet",
",",
"$",
"others",
")",
";",
"Log",
"::",
"debug",
"(",
"\"PivotByDimension::%s: un-prepended default row: %s\"",
",",
"__FUNCTION__",
",",
"$",
"defaultRow",
")",
";",
"// post process pivoted datatable",
"foreach",
"(",
"$",
"table",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"// remove subtables from rows",
"$",
"row",
"->",
"removeSubtable",
"(",
")",
";",
"$",
"row",
"->",
"deleteMetadata",
"(",
"'idsubdatatable_in_db'",
")",
";",
"// use default row to ensure column ordering and add missing columns/aggregate cut-off columns",
"$",
"orderedColumns",
"=",
"$",
"defaultRow",
";",
"foreach",
"(",
"$",
"row",
"->",
"getColumns",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"orderedColumns",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"orderedColumns",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"orderedColumns",
"[",
"$",
"others",
"]",
"+=",
"$",
"value",
";",
"}",
"}",
"$",
"row",
"->",
"setColumns",
"(",
"$",
"orderedColumns",
")",
";",
"}",
"$",
"table",
"->",
"clearQueuedFilters",
"(",
")",
";",
"// TODO: shouldn't clear queued filters, but we can't wait for them to be run",
"// since generic filters are run before them. remove after refactoring",
"// processed metrics.",
"// prepend numerals to columns in a queued filter (this way, disable_queued_filters can be used",
"// to get machine readable data from the API if needed)",
"$",
"prependedColumnNames",
"=",
"$",
"this",
"->",
"getOrderedColumnsWithPrependedNumerals",
"(",
"$",
"defaultRow",
",",
"$",
"others",
")",
";",
"Log",
"::",
"debug",
"(",
"\"PivotByDimension::%s: prepended column name mapping: %s\"",
",",
"__FUNCTION__",
",",
"$",
"prependedColumnNames",
")",
";",
"$",
"table",
"->",
"queueFilter",
"(",
"function",
"(",
"DataTable",
"$",
"table",
")",
"use",
"(",
"$",
"prependedColumnNames",
")",
"{",
"foreach",
"(",
"$",
"table",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"row",
"->",
"setColumns",
"(",
"array_combine",
"(",
"$",
"prependedColumnNames",
",",
"$",
"row",
"->",
"getColumns",
"(",
")",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] | Pivots to table.
@param DataTable $table The table to manipulate. | [
"Pivots",
"to",
"table",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Filter/PivotByDimension.php#L181-L258 |
209,835 | matomo-org/matomo | core/DataTable/Filter/PivotByDimension.php | PivotByDimension.getIntersectedTable | private function getIntersectedTable(DataTable $table, Row $row)
{
if ($this->isPivotDimensionSubtable()) {
return $this->loadSubtable($table, $row);
}
if ($this->isFetchingBySegmentEnabled) {
$segment = $row->getMetadata('segment');
if (empty($segment)) {
$segmentValue = $row->getMetadata('segmentValue');
if ($segmentValue === false) {
$segmentValue = $row->getColumn('label');
}
$segmentName = $this->thisReportDimensionSegment->getSegment();
if (empty($segmentName)) {
throw new \Exception("Invalid segment found when pivoting: " . $this->thisReportDimensionSegment->getName());
}
$segment = $segmentName . "==" . urlencode($segmentValue);
}
return $this->fetchIntersectedWithThisBySegment($table, $segment);
}
// should never occur, unless checkSupportedPivot() fails to catch an unsupported pivot
throw new Exception("Unexpected error, cannot fetch intersected table.");
} | php | private function getIntersectedTable(DataTable $table, Row $row)
{
if ($this->isPivotDimensionSubtable()) {
return $this->loadSubtable($table, $row);
}
if ($this->isFetchingBySegmentEnabled) {
$segment = $row->getMetadata('segment');
if (empty($segment)) {
$segmentValue = $row->getMetadata('segmentValue');
if ($segmentValue === false) {
$segmentValue = $row->getColumn('label');
}
$segmentName = $this->thisReportDimensionSegment->getSegment();
if (empty($segmentName)) {
throw new \Exception("Invalid segment found when pivoting: " . $this->thisReportDimensionSegment->getName());
}
$segment = $segmentName . "==" . urlencode($segmentValue);
}
return $this->fetchIntersectedWithThisBySegment($table, $segment);
}
// should never occur, unless checkSupportedPivot() fails to catch an unsupported pivot
throw new Exception("Unexpected error, cannot fetch intersected table.");
} | [
"private",
"function",
"getIntersectedTable",
"(",
"DataTable",
"$",
"table",
",",
"Row",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isPivotDimensionSubtable",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"loadSubtable",
"(",
"$",
"table",
",",
"$",
"row",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isFetchingBySegmentEnabled",
")",
"{",
"$",
"segment",
"=",
"$",
"row",
"->",
"getMetadata",
"(",
"'segment'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"segment",
")",
")",
"{",
"$",
"segmentValue",
"=",
"$",
"row",
"->",
"getMetadata",
"(",
"'segmentValue'",
")",
";",
"if",
"(",
"$",
"segmentValue",
"===",
"false",
")",
"{",
"$",
"segmentValue",
"=",
"$",
"row",
"->",
"getColumn",
"(",
"'label'",
")",
";",
"}",
"$",
"segmentName",
"=",
"$",
"this",
"->",
"thisReportDimensionSegment",
"->",
"getSegment",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"segmentName",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Invalid segment found when pivoting: \"",
".",
"$",
"this",
"->",
"thisReportDimensionSegment",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"segment",
"=",
"$",
"segmentName",
".",
"\"==\"",
".",
"urlencode",
"(",
"$",
"segmentValue",
")",
";",
"}",
"return",
"$",
"this",
"->",
"fetchIntersectedWithThisBySegment",
"(",
"$",
"table",
",",
"$",
"segment",
")",
";",
"}",
"// should never occur, unless checkSupportedPivot() fails to catch an unsupported pivot",
"throw",
"new",
"Exception",
"(",
"\"Unexpected error, cannot fetch intersected table.\"",
")",
";",
"}"
] | An intersected table is a table that describes visits by a certain dimension for the visits
represented by a row in another table. This method fetches intersected tables either via
subtable or by using a segment. Read the class docs for more info. | [
"An",
"intersected",
"table",
"is",
"a",
"table",
"that",
"describes",
"visits",
"by",
"a",
"certain",
"dimension",
"for",
"the",
"visits",
"represented",
"by",
"a",
"row",
"in",
"another",
"table",
".",
"This",
"method",
"fetches",
"intersected",
"tables",
"either",
"via",
"subtable",
"or",
"by",
"using",
"a",
"segment",
".",
"Read",
"the",
"class",
"docs",
"for",
"more",
"info",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Filter/PivotByDimension.php#L265-L291 |
209,836 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.getTableCreateSql | public function getTableCreateSql($tableName)
{
$tables = DbHelper::getTablesCreateSql();
if (!isset($tables[$tableName])) {
throw new Exception("The table '$tableName' SQL creation code couldn't be found.");
}
return $tables[$tableName];
} | php | public function getTableCreateSql($tableName)
{
$tables = DbHelper::getTablesCreateSql();
if (!isset($tables[$tableName])) {
throw new Exception("The table '$tableName' SQL creation code couldn't be found.");
}
return $tables[$tableName];
} | [
"public",
"function",
"getTableCreateSql",
"(",
"$",
"tableName",
")",
"{",
"$",
"tables",
"=",
"DbHelper",
"::",
"getTablesCreateSql",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"tables",
"[",
"$",
"tableName",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"The table '$tableName' SQL creation code couldn't be found.\"",
")",
";",
"}",
"return",
"$",
"tables",
"[",
"$",
"tableName",
"]",
";",
"}"
] | Get the SQL to create a specific Piwik table
@param string $tableName
@throws Exception
@return string SQL | [
"Get",
"the",
"SQL",
"to",
"create",
"a",
"specific",
"Piwik",
"table"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L325-L334 |
209,837 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.getTablesNames | public function getTablesNames()
{
$aTables = array_keys($this->getTablesCreateSql());
$prefixTables = $this->getTablePrefix();
$return = array();
foreach ($aTables as $table) {
$return[] = $prefixTables . $table;
}
return $return;
} | php | public function getTablesNames()
{
$aTables = array_keys($this->getTablesCreateSql());
$prefixTables = $this->getTablePrefix();
$return = array();
foreach ($aTables as $table) {
$return[] = $prefixTables . $table;
}
return $return;
} | [
"public",
"function",
"getTablesNames",
"(",
")",
"{",
"$",
"aTables",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"getTablesCreateSql",
"(",
")",
")",
";",
"$",
"prefixTables",
"=",
"$",
"this",
"->",
"getTablePrefix",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"aTables",
"as",
"$",
"table",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"prefixTables",
".",
"$",
"table",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Names of all the prefixed tables in piwik
Doesn't use the DB
@return array Table names | [
"Names",
"of",
"all",
"the",
"prefixed",
"tables",
"in",
"piwik",
"Doesn",
"t",
"use",
"the",
"DB"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L342-L353 |
209,838 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.getTableColumns | public function getTableColumns($tableName)
{
$db = $this->getDb();
$allColumns = $db->fetchAll("SHOW COLUMNS FROM " . $tableName);
$fields = array();
foreach ($allColumns as $column) {
$fields[trim($column['Field'])] = $column;
}
return $fields;
} | php | public function getTableColumns($tableName)
{
$db = $this->getDb();
$allColumns = $db->fetchAll("SHOW COLUMNS FROM " . $tableName);
$fields = array();
foreach ($allColumns as $column) {
$fields[trim($column['Field'])] = $column;
}
return $fields;
} | [
"public",
"function",
"getTableColumns",
"(",
"$",
"tableName",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getDb",
"(",
")",
";",
"$",
"allColumns",
"=",
"$",
"db",
"->",
"fetchAll",
"(",
"\"SHOW COLUMNS FROM \"",
".",
"$",
"tableName",
")",
";",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"allColumns",
"as",
"$",
"column",
")",
"{",
"$",
"fields",
"[",
"trim",
"(",
"$",
"column",
"[",
"'Field'",
"]",
")",
"]",
"=",
"$",
"column",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] | Get list of installed columns in a table
@param string $tableName The name of a table.
@return array Installed columns indexed by the column name. | [
"Get",
"list",
"of",
"installed",
"columns",
"in",
"a",
"table"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L362-L374 |
209,839 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.getTablesInstalled | public function getTablesInstalled($forceReload = true)
{
if (is_null($this->tablesInstalled)
|| $forceReload === true
) {
$db = $this->getDb();
$prefixTables = $this->getTablePrefixEscaped();
$allTables = $this->getAllExistingTables($prefixTables);
// all the tables to be installed
$allMyTables = $this->getTablesNames();
// we get the intersection between all the tables in the DB and the tables to be installed
$tablesInstalled = array_intersect($allMyTables, $allTables);
// at this point we have the static list of core tables, but let's add the monthly archive tables
$allArchiveNumeric = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "archive_numeric%'");
$allArchiveBlob = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "archive_blob%'");
$allTablesReallyInstalled = array_merge($tablesInstalled, $allArchiveNumeric, $allArchiveBlob);
$this->tablesInstalled = $allTablesReallyInstalled;
}
return $this->tablesInstalled;
} | php | public function getTablesInstalled($forceReload = true)
{
if (is_null($this->tablesInstalled)
|| $forceReload === true
) {
$db = $this->getDb();
$prefixTables = $this->getTablePrefixEscaped();
$allTables = $this->getAllExistingTables($prefixTables);
// all the tables to be installed
$allMyTables = $this->getTablesNames();
// we get the intersection between all the tables in the DB and the tables to be installed
$tablesInstalled = array_intersect($allMyTables, $allTables);
// at this point we have the static list of core tables, but let's add the monthly archive tables
$allArchiveNumeric = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "archive_numeric%'");
$allArchiveBlob = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "archive_blob%'");
$allTablesReallyInstalled = array_merge($tablesInstalled, $allArchiveNumeric, $allArchiveBlob);
$this->tablesInstalled = $allTablesReallyInstalled;
}
return $this->tablesInstalled;
} | [
"public",
"function",
"getTablesInstalled",
"(",
"$",
"forceReload",
"=",
"true",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"tablesInstalled",
")",
"||",
"$",
"forceReload",
"===",
"true",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getDb",
"(",
")",
";",
"$",
"prefixTables",
"=",
"$",
"this",
"->",
"getTablePrefixEscaped",
"(",
")",
";",
"$",
"allTables",
"=",
"$",
"this",
"->",
"getAllExistingTables",
"(",
"$",
"prefixTables",
")",
";",
"// all the tables to be installed",
"$",
"allMyTables",
"=",
"$",
"this",
"->",
"getTablesNames",
"(",
")",
";",
"// we get the intersection between all the tables in the DB and the tables to be installed",
"$",
"tablesInstalled",
"=",
"array_intersect",
"(",
"$",
"allMyTables",
",",
"$",
"allTables",
")",
";",
"// at this point we have the static list of core tables, but let's add the monthly archive tables",
"$",
"allArchiveNumeric",
"=",
"$",
"db",
"->",
"fetchCol",
"(",
"\"SHOW TABLES LIKE '\"",
".",
"$",
"prefixTables",
".",
"\"archive_numeric%'\"",
")",
";",
"$",
"allArchiveBlob",
"=",
"$",
"db",
"->",
"fetchCol",
"(",
"\"SHOW TABLES LIKE '\"",
".",
"$",
"prefixTables",
".",
"\"archive_blob%'\"",
")",
";",
"$",
"allTablesReallyInstalled",
"=",
"array_merge",
"(",
"$",
"tablesInstalled",
",",
"$",
"allArchiveNumeric",
",",
"$",
"allArchiveBlob",
")",
";",
"$",
"this",
"->",
"tablesInstalled",
"=",
"$",
"allTablesReallyInstalled",
";",
"}",
"return",
"$",
"this",
"->",
"tablesInstalled",
";",
"}"
] | Get list of tables installed
@param bool $forceReload Invalidate cache
@return array installed Tables | [
"Get",
"list",
"of",
"tables",
"installed"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L382-L408 |
209,840 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.createTable | public function createTable($nameWithoutPrefix, $createDefinition)
{
$statement = sprintf("CREATE TABLE `%s` ( %s ) ENGINE=%s DEFAULT CHARSET=utf8 ;",
Common::prefixTable($nameWithoutPrefix),
$createDefinition,
$this->getTableEngine());
try {
Db::exec($statement);
} catch (Exception $e) {
// mysql code error 1050:table already exists
// see bug #153 https://github.com/piwik/piwik/issues/153
if (!$this->getDb()->isErrNo($e, '1050')) {
throw $e;
}
}
} | php | public function createTable($nameWithoutPrefix, $createDefinition)
{
$statement = sprintf("CREATE TABLE `%s` ( %s ) ENGINE=%s DEFAULT CHARSET=utf8 ;",
Common::prefixTable($nameWithoutPrefix),
$createDefinition,
$this->getTableEngine());
try {
Db::exec($statement);
} catch (Exception $e) {
// mysql code error 1050:table already exists
// see bug #153 https://github.com/piwik/piwik/issues/153
if (!$this->getDb()->isErrNo($e, '1050')) {
throw $e;
}
}
} | [
"public",
"function",
"createTable",
"(",
"$",
"nameWithoutPrefix",
",",
"$",
"createDefinition",
")",
"{",
"$",
"statement",
"=",
"sprintf",
"(",
"\"CREATE TABLE `%s` ( %s ) ENGINE=%s DEFAULT CHARSET=utf8 ;\"",
",",
"Common",
"::",
"prefixTable",
"(",
"$",
"nameWithoutPrefix",
")",
",",
"$",
"createDefinition",
",",
"$",
"this",
"->",
"getTableEngine",
"(",
")",
")",
";",
"try",
"{",
"Db",
"::",
"exec",
"(",
"$",
"statement",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// mysql code error 1050:table already exists",
"// see bug #153 https://github.com/piwik/piwik/issues/153",
"if",
"(",
"!",
"$",
"this",
"->",
"getDb",
"(",
")",
"->",
"isErrNo",
"(",
"$",
"e",
",",
"'1050'",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}"
] | Creates a new table in the database.
@param string $nameWithoutPrefix The name of the table without any piwik prefix.
@param string $createDefinition The table create definition, see the "MySQL CREATE TABLE" specification for
more information.
@throws \Exception | [
"Creates",
"a",
"new",
"table",
"in",
"the",
"database",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L444-L460 |
209,841 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.createTables | public function createTables()
{
$db = $this->getDb();
$prefixTables = $this->getTablePrefix();
$tablesAlreadyInstalled = $this->getTablesInstalled();
$tablesToCreate = $this->getTablesCreateSql();
unset($tablesToCreate['archive_blob']);
unset($tablesToCreate['archive_numeric']);
foreach ($tablesToCreate as $tableName => $tableSql) {
$tableName = $prefixTables . $tableName;
if (!in_array($tableName, $tablesAlreadyInstalled)) {
$db->query($tableSql);
}
}
} | php | public function createTables()
{
$db = $this->getDb();
$prefixTables = $this->getTablePrefix();
$tablesAlreadyInstalled = $this->getTablesInstalled();
$tablesToCreate = $this->getTablesCreateSql();
unset($tablesToCreate['archive_blob']);
unset($tablesToCreate['archive_numeric']);
foreach ($tablesToCreate as $tableName => $tableSql) {
$tableName = $prefixTables . $tableName;
if (!in_array($tableName, $tablesAlreadyInstalled)) {
$db->query($tableSql);
}
}
} | [
"public",
"function",
"createTables",
"(",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getDb",
"(",
")",
";",
"$",
"prefixTables",
"=",
"$",
"this",
"->",
"getTablePrefix",
"(",
")",
";",
"$",
"tablesAlreadyInstalled",
"=",
"$",
"this",
"->",
"getTablesInstalled",
"(",
")",
";",
"$",
"tablesToCreate",
"=",
"$",
"this",
"->",
"getTablesCreateSql",
"(",
")",
";",
"unset",
"(",
"$",
"tablesToCreate",
"[",
"'archive_blob'",
"]",
")",
";",
"unset",
"(",
"$",
"tablesToCreate",
"[",
"'archive_numeric'",
"]",
")",
";",
"foreach",
"(",
"$",
"tablesToCreate",
"as",
"$",
"tableName",
"=>",
"$",
"tableSql",
")",
"{",
"$",
"tableName",
"=",
"$",
"prefixTables",
".",
"$",
"tableName",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"tableName",
",",
"$",
"tablesAlreadyInstalled",
")",
")",
"{",
"$",
"db",
"->",
"query",
"(",
"$",
"tableSql",
")",
";",
"}",
"}",
"}"
] | Create all tables | [
"Create",
"all",
"tables"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L475-L491 |
209,842 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.createAnonymousUser | public function createAnonymousUser()
{
$now = Date::factory('now')->getDatetime();
// The anonymous user is the user that is assigned by default
// note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin
$db = $this->getDb();
$db->query("INSERT IGNORE INTO " . Common::prefixTable("user") . "
VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', '', 'anonymous', 0, '$now', '$now' );");
} | php | public function createAnonymousUser()
{
$now = Date::factory('now')->getDatetime();
// The anonymous user is the user that is assigned by default
// note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin
$db = $this->getDb();
$db->query("INSERT IGNORE INTO " . Common::prefixTable("user") . "
VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', '', 'anonymous', 0, '$now', '$now' );");
} | [
"public",
"function",
"createAnonymousUser",
"(",
")",
"{",
"$",
"now",
"=",
"Date",
"::",
"factory",
"(",
"'now'",
")",
"->",
"getDatetime",
"(",
")",
";",
"// The anonymous user is the user that is assigned by default",
"// note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin",
"$",
"db",
"=",
"$",
"this",
"->",
"getDb",
"(",
")",
";",
"$",
"db",
"->",
"query",
"(",
"\"INSERT IGNORE INTO \"",
".",
"Common",
"::",
"prefixTable",
"(",
"\"user\"",
")",
".",
"\"\n VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', '', 'anonymous', 0, '$now', '$now' );\"",
")",
";",
"}"
] | Creates an entry in the User table for the "anonymous" user. | [
"Creates",
"an",
"entry",
"in",
"the",
"User",
"table",
"for",
"the",
"anonymous",
"user",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L496-L505 |
209,843 | matomo-org/matomo | core/Db/Schema/Mysql.php | Mysql.getInstallVersion | public function getInstallVersion()
{
Option::clearCachedOption(self::OPTION_NAME_MATOMO_INSTALL_VERSION);
$version = Option::get(self::OPTION_NAME_MATOMO_INSTALL_VERSION);
if (!empty($version)) {
return $version;
}
} | php | public function getInstallVersion()
{
Option::clearCachedOption(self::OPTION_NAME_MATOMO_INSTALL_VERSION);
$version = Option::get(self::OPTION_NAME_MATOMO_INSTALL_VERSION);
if (!empty($version)) {
return $version;
}
} | [
"public",
"function",
"getInstallVersion",
"(",
")",
"{",
"Option",
"::",
"clearCachedOption",
"(",
"self",
"::",
"OPTION_NAME_MATOMO_INSTALL_VERSION",
")",
";",
"$",
"version",
"=",
"Option",
"::",
"get",
"(",
"self",
"::",
"OPTION_NAME_MATOMO_INSTALL_VERSION",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"version",
")",
")",
"{",
"return",
"$",
"version",
";",
"}",
"}"
] | Returns which Matomo version was used to install this Matomo for the first time. | [
"Returns",
"which",
"Matomo",
"version",
"was",
"used",
"to",
"install",
"this",
"Matomo",
"for",
"the",
"first",
"time",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema/Mysql.php#L520-L527 |
209,844 | matomo-org/matomo | plugins/ScheduledReports/ScheduledReports.php | ScheduledReports.deleteSiteReport | public function deleteSiteReport($idSite)
{
$idReports = API::getInstance()->getReports($idSite);
foreach ($idReports as $report) {
$idReport = $report['idreport'];
API::getInstance()->deleteReport($idReport);
}
} | php | public function deleteSiteReport($idSite)
{
$idReports = API::getInstance()->getReports($idSite);
foreach ($idReports as $report) {
$idReport = $report['idreport'];
API::getInstance()->deleteReport($idReport);
}
} | [
"public",
"function",
"deleteSiteReport",
"(",
"$",
"idSite",
")",
"{",
"$",
"idReports",
"=",
"API",
"::",
"getInstance",
"(",
")",
"->",
"getReports",
"(",
"$",
"idSite",
")",
";",
"foreach",
"(",
"$",
"idReports",
"as",
"$",
"report",
")",
"{",
"$",
"idReport",
"=",
"$",
"report",
"[",
"'idreport'",
"]",
";",
"API",
"::",
"getInstance",
"(",
")",
"->",
"deleteReport",
"(",
"$",
"idReport",
")",
";",
"}",
"}"
] | Delete reports for the website | [
"Delete",
"reports",
"for",
"the",
"website"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/ScheduledReports/ScheduledReports.php#L121-L129 |
209,845 | matomo-org/matomo | plugins/ScheduledReports/ScheduledReports.php | ScheduledReports.getPeriodToFrequency | public static function getPeriodToFrequency()
{
return array(
Schedule::PERIOD_NEVER => Piwik::translate('General_Never'),
Schedule::PERIOD_DAY => Piwik::translate('General_Daily'),
Schedule::PERIOD_WEEK => Piwik::translate('General_Weekly'),
Schedule::PERIOD_MONTH => Piwik::translate('General_Monthly'),
);
} | php | public static function getPeriodToFrequency()
{
return array(
Schedule::PERIOD_NEVER => Piwik::translate('General_Never'),
Schedule::PERIOD_DAY => Piwik::translate('General_Daily'),
Schedule::PERIOD_WEEK => Piwik::translate('General_Weekly'),
Schedule::PERIOD_MONTH => Piwik::translate('General_Monthly'),
);
} | [
"public",
"static",
"function",
"getPeriodToFrequency",
"(",
")",
"{",
"return",
"array",
"(",
"Schedule",
"::",
"PERIOD_NEVER",
"=>",
"Piwik",
"::",
"translate",
"(",
"'General_Never'",
")",
",",
"Schedule",
"::",
"PERIOD_DAY",
"=>",
"Piwik",
"::",
"translate",
"(",
"'General_Daily'",
")",
",",
"Schedule",
"::",
"PERIOD_WEEK",
"=>",
"Piwik",
"::",
"translate",
"(",
"'General_Weekly'",
")",
",",
"Schedule",
"::",
"PERIOD_MONTH",
"=>",
"Piwik",
"::",
"translate",
"(",
"'General_Monthly'",
")",
",",
")",
";",
"}"
] | Used in the Report Listing
@ignore | [
"Used",
"in",
"the",
"Report",
"Listing"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/ScheduledReports/ScheduledReports.php#L596-L604 |
209,846 | matomo-org/matomo | core/Columns/MetricsList.php | MetricsList.remove | public function remove($metricCategory, $metricName = false)
{
foreach ($this->metrics as $index => $metric) {
if ($metric->getCategoryId() === $metricCategory) {
if (!$metricName || $metric->getName() === $metricName) {
unset($this->metrics[$index]);
$this->metricsByNameCache = array();
}
}
}
} | php | public function remove($metricCategory, $metricName = false)
{
foreach ($this->metrics as $index => $metric) {
if ($metric->getCategoryId() === $metricCategory) {
if (!$metricName || $metric->getName() === $metricName) {
unset($this->metrics[$index]);
$this->metricsByNameCache = array();
}
}
}
} | [
"public",
"function",
"remove",
"(",
"$",
"metricCategory",
",",
"$",
"metricName",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"metrics",
"as",
"$",
"index",
"=>",
"$",
"metric",
")",
"{",
"if",
"(",
"$",
"metric",
"->",
"getCategoryId",
"(",
")",
"===",
"$",
"metricCategory",
")",
"{",
"if",
"(",
"!",
"$",
"metricName",
"||",
"$",
"metric",
"->",
"getName",
"(",
")",
"===",
"$",
"metricName",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"metrics",
"[",
"$",
"index",
"]",
")",
";",
"$",
"this",
"->",
"metricsByNameCache",
"=",
"array",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | Removes one or more metrics from the metrics list.
@param string $metricCategory The metric category id. Can be a translation token eg 'General_Visits'
see {@link Metric::getCategory()}.
@param string|false $metricName The name of the metric to remove eg 'nb_visits'.
If not supplied, all metrics within that category will be removed. | [
"Removes",
"one",
"or",
"more",
"metrics",
"from",
"the",
"metrics",
"list",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Columns/MetricsList.php#L66-L76 |
209,847 | matomo-org/matomo | core/Columns/MetricsList.php | MetricsList.get | public static function get()
{
$cache = Cache::getTransientCache();
$cacheKey = CacheId::siteAware('MetricsList');
if ($cache->contains($cacheKey)) {
return $cache->fetch($cacheKey);
}
$list = new static;
/**
* Triggered to add new metrics that cannot be picked up automatically by the platform.
* This is useful if the plugin allows a user to create metrics dynamically. For example
* CustomDimensions or CustomVariables.
*
* **Example**
*
* public function addMetric(&$list)
* {
* $list->addMetric(new MyCustomMetric());
* }
*
* @param MetricsList $list An instance of the MetricsList. You can add metrics to the list this way.
*/
Piwik::postEvent('Metric.addMetrics', array($list));
$dimensions = Dimension::getAllDimensions();
foreach ($dimensions as $dimension) {
$factory = new DimensionMetricFactory($dimension);
$dimension->configureMetrics($list, $factory);
}
$computedFactory = new ComputedMetricFactory($list);
/**
* Triggered to add new metrics that cannot be picked up automatically by the platform.
* This is useful if the plugin allows a user to create metrics dynamically. For example
* CustomDimensions or CustomVariables.
*
* **Example**
*
* public function addMetric(&$list)
* {
* $list->addMetric(new MyCustomMetric());
* }
*
* @param MetricsList $list An instance of the MetricsList. You can add metrics to the list this way.
*/
Piwik::postEvent('Metric.addComputedMetrics', array($list, $computedFactory));
/**
* Triggered to filter metrics.
*
* **Example**
*
* public function removeMetrics(Piwik\Columns\MetricsList $list)
* {
* $list->remove($category='General_Visits'); // remove all metrics having this category
* }
*
* @param MetricsList $list An instance of the MetricsList. You can change the list of metrics this way.
*/
Piwik::postEvent('Metric.filterMetrics', array($list));
$availableMetrics = array();
foreach ($list->getMetrics() as $metric) {
$availableMetrics[] = $metric->getName();
}
foreach ($list->metrics as $index => $metric) {
if ($metric instanceof ProcessedMetric) {
$depMetrics = $metric->getDependentMetrics();
if (is_array($depMetrics)) {
foreach ($depMetrics as $depMetric) {
if (!in_array($depMetric, $availableMetrics, $strict = true)) {
unset($list->metrics[$index]); // not resolvable metric
}
}
}
}
}
$cache->save($cacheKey, $list);
return $list;
} | php | public static function get()
{
$cache = Cache::getTransientCache();
$cacheKey = CacheId::siteAware('MetricsList');
if ($cache->contains($cacheKey)) {
return $cache->fetch($cacheKey);
}
$list = new static;
/**
* Triggered to add new metrics that cannot be picked up automatically by the platform.
* This is useful if the plugin allows a user to create metrics dynamically. For example
* CustomDimensions or CustomVariables.
*
* **Example**
*
* public function addMetric(&$list)
* {
* $list->addMetric(new MyCustomMetric());
* }
*
* @param MetricsList $list An instance of the MetricsList. You can add metrics to the list this way.
*/
Piwik::postEvent('Metric.addMetrics', array($list));
$dimensions = Dimension::getAllDimensions();
foreach ($dimensions as $dimension) {
$factory = new DimensionMetricFactory($dimension);
$dimension->configureMetrics($list, $factory);
}
$computedFactory = new ComputedMetricFactory($list);
/**
* Triggered to add new metrics that cannot be picked up automatically by the platform.
* This is useful if the plugin allows a user to create metrics dynamically. For example
* CustomDimensions or CustomVariables.
*
* **Example**
*
* public function addMetric(&$list)
* {
* $list->addMetric(new MyCustomMetric());
* }
*
* @param MetricsList $list An instance of the MetricsList. You can add metrics to the list this way.
*/
Piwik::postEvent('Metric.addComputedMetrics', array($list, $computedFactory));
/**
* Triggered to filter metrics.
*
* **Example**
*
* public function removeMetrics(Piwik\Columns\MetricsList $list)
* {
* $list->remove($category='General_Visits'); // remove all metrics having this category
* }
*
* @param MetricsList $list An instance of the MetricsList. You can change the list of metrics this way.
*/
Piwik::postEvent('Metric.filterMetrics', array($list));
$availableMetrics = array();
foreach ($list->getMetrics() as $metric) {
$availableMetrics[] = $metric->getName();
}
foreach ($list->metrics as $index => $metric) {
if ($metric instanceof ProcessedMetric) {
$depMetrics = $metric->getDependentMetrics();
if (is_array($depMetrics)) {
foreach ($depMetrics as $depMetric) {
if (!in_array($depMetric, $availableMetrics, $strict = true)) {
unset($list->metrics[$index]); // not resolvable metric
}
}
}
}
}
$cache->save($cacheKey, $list);
return $list;
} | [
"public",
"static",
"function",
"get",
"(",
")",
"{",
"$",
"cache",
"=",
"Cache",
"::",
"getTransientCache",
"(",
")",
";",
"$",
"cacheKey",
"=",
"CacheId",
"::",
"siteAware",
"(",
"'MetricsList'",
")",
";",
"if",
"(",
"$",
"cache",
"->",
"contains",
"(",
"$",
"cacheKey",
")",
")",
"{",
"return",
"$",
"cache",
"->",
"fetch",
"(",
"$",
"cacheKey",
")",
";",
"}",
"$",
"list",
"=",
"new",
"static",
";",
"/**\n * Triggered to add new metrics that cannot be picked up automatically by the platform.\n * This is useful if the plugin allows a user to create metrics dynamically. For example\n * CustomDimensions or CustomVariables.\n *\n * **Example**\n *\n * public function addMetric(&$list)\n * {\n * $list->addMetric(new MyCustomMetric());\n * }\n *\n * @param MetricsList $list An instance of the MetricsList. You can add metrics to the list this way.\n */",
"Piwik",
"::",
"postEvent",
"(",
"'Metric.addMetrics'",
",",
"array",
"(",
"$",
"list",
")",
")",
";",
"$",
"dimensions",
"=",
"Dimension",
"::",
"getAllDimensions",
"(",
")",
";",
"foreach",
"(",
"$",
"dimensions",
"as",
"$",
"dimension",
")",
"{",
"$",
"factory",
"=",
"new",
"DimensionMetricFactory",
"(",
"$",
"dimension",
")",
";",
"$",
"dimension",
"->",
"configureMetrics",
"(",
"$",
"list",
",",
"$",
"factory",
")",
";",
"}",
"$",
"computedFactory",
"=",
"new",
"ComputedMetricFactory",
"(",
"$",
"list",
")",
";",
"/**\n * Triggered to add new metrics that cannot be picked up automatically by the platform.\n * This is useful if the plugin allows a user to create metrics dynamically. For example\n * CustomDimensions or CustomVariables.\n *\n * **Example**\n *\n * public function addMetric(&$list)\n * {\n * $list->addMetric(new MyCustomMetric());\n * }\n *\n * @param MetricsList $list An instance of the MetricsList. You can add metrics to the list this way.\n */",
"Piwik",
"::",
"postEvent",
"(",
"'Metric.addComputedMetrics'",
",",
"array",
"(",
"$",
"list",
",",
"$",
"computedFactory",
")",
")",
";",
"/**\n * Triggered to filter metrics.\n *\n * **Example**\n *\n * public function removeMetrics(Piwik\\Columns\\MetricsList $list)\n * {\n * $list->remove($category='General_Visits'); // remove all metrics having this category\n * }\n *\n * @param MetricsList $list An instance of the MetricsList. You can change the list of metrics this way.\n */",
"Piwik",
"::",
"postEvent",
"(",
"'Metric.filterMetrics'",
",",
"array",
"(",
"$",
"list",
")",
")",
";",
"$",
"availableMetrics",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"->",
"getMetrics",
"(",
")",
"as",
"$",
"metric",
")",
"{",
"$",
"availableMetrics",
"[",
"]",
"=",
"$",
"metric",
"->",
"getName",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"list",
"->",
"metrics",
"as",
"$",
"index",
"=>",
"$",
"metric",
")",
"{",
"if",
"(",
"$",
"metric",
"instanceof",
"ProcessedMetric",
")",
"{",
"$",
"depMetrics",
"=",
"$",
"metric",
"->",
"getDependentMetrics",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"depMetrics",
")",
")",
"{",
"foreach",
"(",
"$",
"depMetrics",
"as",
"$",
"depMetric",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"depMetric",
",",
"$",
"availableMetrics",
",",
"$",
"strict",
"=",
"true",
")",
")",
"{",
"unset",
"(",
"$",
"list",
"->",
"metrics",
"[",
"$",
"index",
"]",
")",
";",
"// not resolvable metric",
"}",
"}",
"}",
"}",
"}",
"$",
"cache",
"->",
"save",
"(",
"$",
"cacheKey",
",",
"$",
"list",
")",
";",
"return",
"$",
"list",
";",
"}"
] | Get all metrics defined in the Piwik platform.
@ignore
@return static | [
"Get",
"all",
"metrics",
"defined",
"in",
"the",
"Piwik",
"platform",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Columns/MetricsList.php#L103-L189 |
209,848 | matomo-org/matomo | core/DataTable/Renderer/Csv.php | Csv.renderTable | protected function renderTable($table, &$allColumns = array())
{
if (is_array($table)) {
// convert array to DataTable
$table = DataTable::makeFromSimpleArray($table);
}
if ($table instanceof DataTable\Map) {
$str = $this->renderDataTableMap($table, $allColumns);
} else {
$str = $this->renderDataTable($table, $allColumns);
}
return $str;
} | php | protected function renderTable($table, &$allColumns = array())
{
if (is_array($table)) {
// convert array to DataTable
$table = DataTable::makeFromSimpleArray($table);
}
if ($table instanceof DataTable\Map) {
$str = $this->renderDataTableMap($table, $allColumns);
} else {
$str = $this->renderDataTable($table, $allColumns);
}
return $str;
} | [
"protected",
"function",
"renderTable",
"(",
"$",
"table",
",",
"&",
"$",
"allColumns",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"table",
")",
")",
"{",
"// convert array to DataTable",
"$",
"table",
"=",
"DataTable",
"::",
"makeFromSimpleArray",
"(",
"$",
"table",
")",
";",
"}",
"if",
"(",
"$",
"table",
"instanceof",
"DataTable",
"\\",
"Map",
")",
"{",
"$",
"str",
"=",
"$",
"this",
"->",
"renderDataTableMap",
"(",
"$",
"table",
",",
"$",
"allColumns",
")",
";",
"}",
"else",
"{",
"$",
"str",
"=",
"$",
"this",
"->",
"renderDataTable",
"(",
"$",
"table",
",",
"$",
"allColumns",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Computes the output of the given data table
@param DataTable|array $table
@param array $allColumns
@return string | [
"Computes",
"the",
"output",
"of",
"the",
"given",
"data",
"table"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Renderer/Csv.php#L119-L132 |
209,849 | matomo-org/matomo | core/DataTable/Renderer/Csv.php | Csv.renderDataTableMap | protected function renderDataTableMap($table, &$allColumns = array())
{
$str = '';
foreach ($table->getDataTables() as $currentLinePrefix => $dataTable) {
$returned = explode("\n", $this->renderTable($dataTable, $allColumns));
// get rid of the columns names
$returned = array_slice($returned, 1);
// case empty datatable we don't print anything in the CSV export
// when in xml we would output <result date="2008-01-15" />
if (!empty($returned)) {
foreach ($returned as &$row) {
$row = $currentLinePrefix . $this->separator . $row;
}
$str .= "\n" . implode("\n", $returned);
}
}
// prepend table key to column list
$allColumns = array_merge(array($table->getKeyName() => true), $allColumns);
// add header to output string
$str = $this->getHeaderLine(array_keys($allColumns)) . $str;
return $str;
} | php | protected function renderDataTableMap($table, &$allColumns = array())
{
$str = '';
foreach ($table->getDataTables() as $currentLinePrefix => $dataTable) {
$returned = explode("\n", $this->renderTable($dataTable, $allColumns));
// get rid of the columns names
$returned = array_slice($returned, 1);
// case empty datatable we don't print anything in the CSV export
// when in xml we would output <result date="2008-01-15" />
if (!empty($returned)) {
foreach ($returned as &$row) {
$row = $currentLinePrefix . $this->separator . $row;
}
$str .= "\n" . implode("\n", $returned);
}
}
// prepend table key to column list
$allColumns = array_merge(array($table->getKeyName() => true), $allColumns);
// add header to output string
$str = $this->getHeaderLine(array_keys($allColumns)) . $str;
return $str;
} | [
"protected",
"function",
"renderDataTableMap",
"(",
"$",
"table",
",",
"&",
"$",
"allColumns",
"=",
"array",
"(",
")",
")",
"{",
"$",
"str",
"=",
"''",
";",
"foreach",
"(",
"$",
"table",
"->",
"getDataTables",
"(",
")",
"as",
"$",
"currentLinePrefix",
"=>",
"$",
"dataTable",
")",
"{",
"$",
"returned",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"this",
"->",
"renderTable",
"(",
"$",
"dataTable",
",",
"$",
"allColumns",
")",
")",
";",
"// get rid of the columns names",
"$",
"returned",
"=",
"array_slice",
"(",
"$",
"returned",
",",
"1",
")",
";",
"// case empty datatable we don't print anything in the CSV export",
"// when in xml we would output <result date=\"2008-01-15\" />",
"if",
"(",
"!",
"empty",
"(",
"$",
"returned",
")",
")",
"{",
"foreach",
"(",
"$",
"returned",
"as",
"&",
"$",
"row",
")",
"{",
"$",
"row",
"=",
"$",
"currentLinePrefix",
".",
"$",
"this",
"->",
"separator",
".",
"$",
"row",
";",
"}",
"$",
"str",
".=",
"\"\\n\"",
".",
"implode",
"(",
"\"\\n\"",
",",
"$",
"returned",
")",
";",
"}",
"}",
"// prepend table key to column list",
"$",
"allColumns",
"=",
"array_merge",
"(",
"array",
"(",
"$",
"table",
"->",
"getKeyName",
"(",
")",
"=>",
"true",
")",
",",
"$",
"allColumns",
")",
";",
"// add header to output string",
"$",
"str",
"=",
"$",
"this",
"->",
"getHeaderLine",
"(",
"array_keys",
"(",
"$",
"allColumns",
")",
")",
".",
"$",
"str",
";",
"return",
"$",
"str",
";",
"}"
] | Computes the output of the given data table array
@param DataTable\Map $table
@param array $allColumns
@return string | [
"Computes",
"the",
"output",
"of",
"the",
"given",
"data",
"table",
"array"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Renderer/Csv.php#L141-L167 |
209,850 | matomo-org/matomo | core/DataTable/Renderer/Csv.php | Csv.renderDataTable | protected function renderDataTable($table, &$allColumns = array())
{
if ($table instanceof Simple) {
$row = $table->getFirstRow();
if ($row !== false) {
$columnNameToValue = $row->getColumns();
if (count($columnNameToValue) == 1) {
// simple tables should only have one column, the value
$allColumns['value'] = true;
$value = array_values($columnNameToValue);
$str = 'value' . $this->lineEnd . $this->formatValue($value[0]);
return $str;
}
}
}
$csv = $this->makeArrayFromDataTable($table, $allColumns);
// now we make sure that all the rows in the CSV array have all the columns
foreach ($csv as &$row) {
foreach ($allColumns as $columnName => $true) {
if (!isset($row[$columnName])) {
$row[$columnName] = '';
}
}
}
$str = $this->buildCsvString($allColumns, $csv);
return $str;
} | php | protected function renderDataTable($table, &$allColumns = array())
{
if ($table instanceof Simple) {
$row = $table->getFirstRow();
if ($row !== false) {
$columnNameToValue = $row->getColumns();
if (count($columnNameToValue) == 1) {
// simple tables should only have one column, the value
$allColumns['value'] = true;
$value = array_values($columnNameToValue);
$str = 'value' . $this->lineEnd . $this->formatValue($value[0]);
return $str;
}
}
}
$csv = $this->makeArrayFromDataTable($table, $allColumns);
// now we make sure that all the rows in the CSV array have all the columns
foreach ($csv as &$row) {
foreach ($allColumns as $columnName => $true) {
if (!isset($row[$columnName])) {
$row[$columnName] = '';
}
}
}
$str = $this->buildCsvString($allColumns, $csv);
return $str;
} | [
"protected",
"function",
"renderDataTable",
"(",
"$",
"table",
",",
"&",
"$",
"allColumns",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"table",
"instanceof",
"Simple",
")",
"{",
"$",
"row",
"=",
"$",
"table",
"->",
"getFirstRow",
"(",
")",
";",
"if",
"(",
"$",
"row",
"!==",
"false",
")",
"{",
"$",
"columnNameToValue",
"=",
"$",
"row",
"->",
"getColumns",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"columnNameToValue",
")",
"==",
"1",
")",
"{",
"// simple tables should only have one column, the value",
"$",
"allColumns",
"[",
"'value'",
"]",
"=",
"true",
";",
"$",
"value",
"=",
"array_values",
"(",
"$",
"columnNameToValue",
")",
";",
"$",
"str",
"=",
"'value'",
".",
"$",
"this",
"->",
"lineEnd",
".",
"$",
"this",
"->",
"formatValue",
"(",
"$",
"value",
"[",
"0",
"]",
")",
";",
"return",
"$",
"str",
";",
"}",
"}",
"}",
"$",
"csv",
"=",
"$",
"this",
"->",
"makeArrayFromDataTable",
"(",
"$",
"table",
",",
"$",
"allColumns",
")",
";",
"// now we make sure that all the rows in the CSV array have all the columns",
"foreach",
"(",
"$",
"csv",
"as",
"&",
"$",
"row",
")",
"{",
"foreach",
"(",
"$",
"allColumns",
"as",
"$",
"columnName",
"=>",
"$",
"true",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"$",
"columnName",
"]",
")",
")",
"{",
"$",
"row",
"[",
"$",
"columnName",
"]",
"=",
"''",
";",
"}",
"}",
"}",
"$",
"str",
"=",
"$",
"this",
"->",
"buildCsvString",
"(",
"$",
"allColumns",
",",
"$",
"csv",
")",
";",
"return",
"$",
"str",
";",
"}"
] | Converts the output of the given simple data table
@param DataTable|Simple $table
@param array $allColumns
@return string | [
"Converts",
"the",
"output",
"of",
"the",
"given",
"simple",
"data",
"table"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Renderer/Csv.php#L176-L206 |
209,851 | matomo-org/matomo | core/DataTable/Renderer/Csv.php | Csv.getHeaderLine | private function getHeaderLine($columnMetrics)
{
foreach ($columnMetrics as $index => $value) {
if (in_array($value, $this->unsupportedColumns)) {
unset($columnMetrics[$index]);
}
}
if ($this->translateColumnNames) {
$columnMetrics = $this->translateColumnNames($columnMetrics);
}
foreach ($columnMetrics as &$value) {
$value = $this->formatValue($value);
}
return implode($this->separator, $columnMetrics);
} | php | private function getHeaderLine($columnMetrics)
{
foreach ($columnMetrics as $index => $value) {
if (in_array($value, $this->unsupportedColumns)) {
unset($columnMetrics[$index]);
}
}
if ($this->translateColumnNames) {
$columnMetrics = $this->translateColumnNames($columnMetrics);
}
foreach ($columnMetrics as &$value) {
$value = $this->formatValue($value);
}
return implode($this->separator, $columnMetrics);
} | [
"private",
"function",
"getHeaderLine",
"(",
"$",
"columnMetrics",
")",
"{",
"foreach",
"(",
"$",
"columnMetrics",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"unsupportedColumns",
")",
")",
"{",
"unset",
"(",
"$",
"columnMetrics",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"translateColumnNames",
")",
"{",
"$",
"columnMetrics",
"=",
"$",
"this",
"->",
"translateColumnNames",
"(",
"$",
"columnMetrics",
")",
";",
"}",
"foreach",
"(",
"$",
"columnMetrics",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"formatValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"this",
"->",
"separator",
",",
"$",
"columnMetrics",
")",
";",
"}"
] | Returns the CSV header line for a set of metrics. Will translate columns if desired.
@param array $columnMetrics
@return array | [
"Returns",
"the",
"CSV",
"header",
"line",
"for",
"a",
"set",
"of",
"metrics",
".",
"Will",
"translate",
"columns",
"if",
"desired",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Renderer/Csv.php#L214-L231 |
209,852 | matomo-org/matomo | core/DataTable/Renderer/Csv.php | Csv.renderHeader | protected function renderHeader()
{
$fileName = Piwik::translate('General_Export');
$period = Common::getRequestVar('period', false);
$date = Common::getRequestVar('date', false);
if ($period || $date) {
// in test cases, there are no request params set
if ($period == 'range') {
$period = new Range($period, $date);
} elseif (strpos($date, ',') !== false) {
$period = new Range('range', $date);
} else {
$period = Period\Factory::build($period, $date);
}
$prettyDate = $period->getLocalizedLongString();
$meta = $this->getApiMetaData();
$fileName .= ' _ ' . $meta['name']
. ' _ ' . $prettyDate . '.csv';
}
// silent fail otherwise unit tests fail
Common::sendHeader('Content-Disposition: attachment; filename="' . $fileName . '"', true);
ProxyHttp::overrideCacheControlHeaders();
} | php | protected function renderHeader()
{
$fileName = Piwik::translate('General_Export');
$period = Common::getRequestVar('period', false);
$date = Common::getRequestVar('date', false);
if ($period || $date) {
// in test cases, there are no request params set
if ($period == 'range') {
$period = new Range($period, $date);
} elseif (strpos($date, ',') !== false) {
$period = new Range('range', $date);
} else {
$period = Period\Factory::build($period, $date);
}
$prettyDate = $period->getLocalizedLongString();
$meta = $this->getApiMetaData();
$fileName .= ' _ ' . $meta['name']
. ' _ ' . $prettyDate . '.csv';
}
// silent fail otherwise unit tests fail
Common::sendHeader('Content-Disposition: attachment; filename="' . $fileName . '"', true);
ProxyHttp::overrideCacheControlHeaders();
} | [
"protected",
"function",
"renderHeader",
"(",
")",
"{",
"$",
"fileName",
"=",
"Piwik",
"::",
"translate",
"(",
"'General_Export'",
")",
";",
"$",
"period",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'period'",
",",
"false",
")",
";",
"$",
"date",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'date'",
",",
"false",
")",
";",
"if",
"(",
"$",
"period",
"||",
"$",
"date",
")",
"{",
"// in test cases, there are no request params set",
"if",
"(",
"$",
"period",
"==",
"'range'",
")",
"{",
"$",
"period",
"=",
"new",
"Range",
"(",
"$",
"period",
",",
"$",
"date",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"date",
",",
"','",
")",
"!==",
"false",
")",
"{",
"$",
"period",
"=",
"new",
"Range",
"(",
"'range'",
",",
"$",
"date",
")",
";",
"}",
"else",
"{",
"$",
"period",
"=",
"Period",
"\\",
"Factory",
"::",
"build",
"(",
"$",
"period",
",",
"$",
"date",
")",
";",
"}",
"$",
"prettyDate",
"=",
"$",
"period",
"->",
"getLocalizedLongString",
"(",
")",
";",
"$",
"meta",
"=",
"$",
"this",
"->",
"getApiMetaData",
"(",
")",
";",
"$",
"fileName",
".=",
"' _ '",
".",
"$",
"meta",
"[",
"'name'",
"]",
".",
"' _ '",
".",
"$",
"prettyDate",
".",
"'.csv'",
";",
"}",
"// silent fail otherwise unit tests fail",
"Common",
"::",
"sendHeader",
"(",
"'Content-Disposition: attachment; filename=\"'",
".",
"$",
"fileName",
".",
"'\"'",
",",
"true",
")",
";",
"ProxyHttp",
"::",
"overrideCacheControlHeaders",
"(",
")",
";",
"}"
] | Sends the http headers for csv file | [
"Sends",
"the",
"http",
"headers",
"for",
"csv",
"file"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Renderer/Csv.php#L294-L322 |
209,853 | matomo-org/matomo | core/DataTable/Filter/ReplaceColumnNames.php | ReplaceColumnNames.getRenamedColumns | protected function getRenamedColumns($columns)
{
$newColumns = array();
foreach ($columns as $columnName => $columnValue) {
$renamedColumn = $this->getRenamedColumn($columnName);
if ($renamedColumn) {
if ($renamedColumn == 'goals') {
$columnValue = $this->flattenGoalColumns($columnValue);
}
// If we happen to rename a column to a name that already exists,
// sum both values in the column. This should really not happen, but
// we introduced in 1.1 a new dataTable indexing scheme for Actions table, and
// could end up with both strings and their int indexes counterpart in a monthly/yearly dataTable
// built from DataTable with both formats
if (isset($newColumns[$renamedColumn])) {
$columnValue += $newColumns[$renamedColumn];
}
$columnName = $renamedColumn;
}
$newColumns[$columnName] = $columnValue;
}
return $newColumns;
} | php | protected function getRenamedColumns($columns)
{
$newColumns = array();
foreach ($columns as $columnName => $columnValue) {
$renamedColumn = $this->getRenamedColumn($columnName);
if ($renamedColumn) {
if ($renamedColumn == 'goals') {
$columnValue = $this->flattenGoalColumns($columnValue);
}
// If we happen to rename a column to a name that already exists,
// sum both values in the column. This should really not happen, but
// we introduced in 1.1 a new dataTable indexing scheme for Actions table, and
// could end up with both strings and their int indexes counterpart in a monthly/yearly dataTable
// built from DataTable with both formats
if (isset($newColumns[$renamedColumn])) {
$columnValue += $newColumns[$renamedColumn];
}
$columnName = $renamedColumn;
}
$newColumns[$columnName] = $columnValue;
}
return $newColumns;
} | [
"protected",
"function",
"getRenamedColumns",
"(",
"$",
"columns",
")",
"{",
"$",
"newColumns",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"columnName",
"=>",
"$",
"columnValue",
")",
"{",
"$",
"renamedColumn",
"=",
"$",
"this",
"->",
"getRenamedColumn",
"(",
"$",
"columnName",
")",
";",
"if",
"(",
"$",
"renamedColumn",
")",
"{",
"if",
"(",
"$",
"renamedColumn",
"==",
"'goals'",
")",
"{",
"$",
"columnValue",
"=",
"$",
"this",
"->",
"flattenGoalColumns",
"(",
"$",
"columnValue",
")",
";",
"}",
"// If we happen to rename a column to a name that already exists,",
"// sum both values in the column. This should really not happen, but",
"// we introduced in 1.1 a new dataTable indexing scheme for Actions table, and",
"// could end up with both strings and their int indexes counterpart in a monthly/yearly dataTable",
"// built from DataTable with both formats",
"if",
"(",
"isset",
"(",
"$",
"newColumns",
"[",
"$",
"renamedColumn",
"]",
")",
")",
"{",
"$",
"columnValue",
"+=",
"$",
"newColumns",
"[",
"$",
"renamedColumn",
"]",
";",
"}",
"$",
"columnName",
"=",
"$",
"renamedColumn",
";",
"}",
"$",
"newColumns",
"[",
"$",
"columnName",
"]",
"=",
"$",
"columnValue",
";",
"}",
"return",
"$",
"newColumns",
";",
"}"
] | Checks the given columns and renames them if required
@param array $columns
@return array | [
"Checks",
"the",
"given",
"columns",
"and",
"renames",
"them",
"if",
"required"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Filter/ReplaceColumnNames.php#L124-L147 |
209,854 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._getMetadatas | protected function _getMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
return $this->_metadatasArray[$id];
} else {
$metadatas = $this->_loadMetadatas($id);
if (!$metadatas) {
return false;
}
$this->_setMetadatas($id, $metadatas, false);
return $metadatas;
}
} | php | protected function _getMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
return $this->_metadatasArray[$id];
} else {
$metadatas = $this->_loadMetadatas($id);
if (!$metadatas) {
return false;
}
$this->_setMetadatas($id, $metadatas, false);
return $metadatas;
}
} | [
"protected",
"function",
"_getMetadatas",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_metadatasArray",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_metadatasArray",
"[",
"$",
"id",
"]",
";",
"}",
"else",
"{",
"$",
"metadatas",
"=",
"$",
"this",
"->",
"_loadMetadatas",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"metadatas",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"_setMetadatas",
"(",
"$",
"id",
",",
"$",
"metadatas",
",",
"false",
")",
";",
"return",
"$",
"metadatas",
";",
"}",
"}"
] | Get a metadatas record
@param string $id Cache id
@return array|false Associative array of metadatas | [
"Get",
"a",
"metadatas",
"record"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L475-L487 |
209,855 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._setMetadatas | protected function _setMetadatas($id, $metadatas, $save = true)
{
if (count($this->_metadatasArray) >= $this->_options['metadatas_array_max_size']) {
$n = (int) ($this->_options['metadatas_array_max_size'] / 10);
$this->_metadatasArray = array_slice($this->_metadatasArray, $n);
}
if ($save) {
$result = $this->_saveMetadatas($id, $metadatas);
if (!$result) {
return false;
}
}
$this->_metadatasArray[$id] = $metadatas;
return true;
} | php | protected function _setMetadatas($id, $metadatas, $save = true)
{
if (count($this->_metadatasArray) >= $this->_options['metadatas_array_max_size']) {
$n = (int) ($this->_options['metadatas_array_max_size'] / 10);
$this->_metadatasArray = array_slice($this->_metadatasArray, $n);
}
if ($save) {
$result = $this->_saveMetadatas($id, $metadatas);
if (!$result) {
return false;
}
}
$this->_metadatasArray[$id] = $metadatas;
return true;
} | [
"protected",
"function",
"_setMetadatas",
"(",
"$",
"id",
",",
"$",
"metadatas",
",",
"$",
"save",
"=",
"true",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"_metadatasArray",
")",
">=",
"$",
"this",
"->",
"_options",
"[",
"'metadatas_array_max_size'",
"]",
")",
"{",
"$",
"n",
"=",
"(",
"int",
")",
"(",
"$",
"this",
"->",
"_options",
"[",
"'metadatas_array_max_size'",
"]",
"/",
"10",
")",
";",
"$",
"this",
"->",
"_metadatasArray",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"_metadatasArray",
",",
"$",
"n",
")",
";",
"}",
"if",
"(",
"$",
"save",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_saveMetadatas",
"(",
"$",
"id",
",",
"$",
"metadatas",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"_metadatasArray",
"[",
"$",
"id",
"]",
"=",
"$",
"metadatas",
";",
"return",
"true",
";",
"}"
] | Set a metadatas record
@param string $id Cache id
@param array $metadatas Associative array of metadatas
@param boolean $save optional pass false to disable saving to file
@return boolean True if no problem | [
"Set",
"a",
"metadatas",
"record"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L497-L511 |
209,856 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._delMetadatas | protected function _delMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
unset($this->_metadatasArray[$id]);
}
$file = $this->_metadatasFile($id);
return $this->_remove($file);
} | php | protected function _delMetadatas($id)
{
if (isset($this->_metadatasArray[$id])) {
unset($this->_metadatasArray[$id]);
}
$file = $this->_metadatasFile($id);
return $this->_remove($file);
} | [
"protected",
"function",
"_delMetadatas",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_metadatasArray",
"[",
"$",
"id",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_metadatasArray",
"[",
"$",
"id",
"]",
")",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"_metadatasFile",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"_remove",
"(",
"$",
"file",
")",
";",
"}"
] | Drop a metadata record
@param string $id Cache id
@return boolean True if no problem | [
"Drop",
"a",
"metadata",
"record"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L519-L526 |
209,857 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._loadMetadatas | protected function _loadMetadatas($id)
{
$file = $this->_metadatasFile($id);
$result = $this->_fileGetContents($file);
if (!$result) {
return false;
}
$tmp = @unserialize($result);
return $tmp;
} | php | protected function _loadMetadatas($id)
{
$file = $this->_metadatasFile($id);
$result = $this->_fileGetContents($file);
if (!$result) {
return false;
}
$tmp = @unserialize($result);
return $tmp;
} | [
"protected",
"function",
"_loadMetadatas",
"(",
"$",
"id",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"_metadatasFile",
"(",
"$",
"id",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_fileGetContents",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tmp",
"=",
"@",
"unserialize",
"(",
"$",
"result",
")",
";",
"return",
"$",
"tmp",
";",
"}"
] | Load metadatas from disk
@param string $id Cache id
@return array|false Metadatas associative array | [
"Load",
"metadatas",
"from",
"disk"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L544-L553 |
209,858 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._saveMetadatas | protected function _saveMetadatas($id, $metadatas)
{
$file = $this->_metadatasFile($id);
$result = $this->_filePutContents($file, serialize($metadatas));
if (!$result) {
return false;
}
return true;
} | php | protected function _saveMetadatas($id, $metadatas)
{
$file = $this->_metadatasFile($id);
$result = $this->_filePutContents($file, serialize($metadatas));
if (!$result) {
return false;
}
return true;
} | [
"protected",
"function",
"_saveMetadatas",
"(",
"$",
"id",
",",
"$",
"metadatas",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"_metadatasFile",
"(",
"$",
"id",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_filePutContents",
"(",
"$",
"file",
",",
"serialize",
"(",
"$",
"metadatas",
")",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Save metadatas to disk
@param string $id Cache id
@param array $metadatas Associative array
@return boolean True if no problem | [
"Save",
"metadatas",
"to",
"disk"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L562-L570 |
209,859 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._isMetadatasFile | protected function _isMetadatasFile($fileName)
{
$id = $this->_fileNameToId($fileName);
if (substr($id, 0, 21) == 'internal-metadatas---') {
return true;
} else {
return false;
}
} | php | protected function _isMetadatasFile($fileName)
{
$id = $this->_fileNameToId($fileName);
if (substr($id, 0, 21) == 'internal-metadatas---') {
return true;
} else {
return false;
}
} | [
"protected",
"function",
"_isMetadatasFile",
"(",
"$",
"fileName",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"_fileNameToId",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"id",
",",
"0",
",",
"21",
")",
"==",
"'internal-metadatas---'",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Check if the given filename is a metadatas one
@param string $fileName File name
@return boolean True if it's a metadatas one | [
"Check",
"if",
"the",
"given",
"filename",
"is",
"a",
"metadatas",
"one"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L591-L599 |
209,860 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._recursiveMkdirAndChmod | protected function _recursiveMkdirAndChmod($id)
{
if ($this->_options['hashed_directory_level'] <=0) {
return true;
}
$partsArray = $this->_path($id, true);
foreach ($partsArray as $part) {
if (!is_dir($part)) {
@mkdir($part, $this->_options['hashed_directory_umask']);
@chmod($part, $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations)
}
}
return true;
} | php | protected function _recursiveMkdirAndChmod($id)
{
if ($this->_options['hashed_directory_level'] <=0) {
return true;
}
$partsArray = $this->_path($id, true);
foreach ($partsArray as $part) {
if (!is_dir($part)) {
@mkdir($part, $this->_options['hashed_directory_umask']);
@chmod($part, $this->_options['hashed_directory_umask']); // see #ZF-320 (this line is required in some configurations)
}
}
return true;
} | [
"protected",
"function",
"_recursiveMkdirAndChmod",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'hashed_directory_level'",
"]",
"<=",
"0",
")",
"{",
"return",
"true",
";",
"}",
"$",
"partsArray",
"=",
"$",
"this",
"->",
"_path",
"(",
"$",
"id",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"partsArray",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"part",
")",
")",
"{",
"@",
"mkdir",
"(",
"$",
"part",
",",
"$",
"this",
"->",
"_options",
"[",
"'hashed_directory_umask'",
"]",
")",
";",
"@",
"chmod",
"(",
"$",
"part",
",",
"$",
"this",
"->",
"_options",
"[",
"'hashed_directory_umask'",
"]",
")",
";",
"// see #ZF-320 (this line is required in some configurations)",
"}",
"}",
"return",
"true",
";",
"}"
] | Make the directory strucuture for the given id
@param string $id cache id
@return boolean true | [
"Make",
"the",
"directory",
"strucuture",
"for",
"the",
"given",
"id"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L914-L927 |
209,861 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._fileGetContents | protected function _fileGetContents($file)
{
$result = false;
if (!is_file($file)) {
return false;
}
$f = @fopen($file, 'rb');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_SH);
$result = stream_get_contents($f);
if ($this->_options['file_locking']) @flock($f, LOCK_UN);
@fclose($f);
}
return $result;
} | php | protected function _fileGetContents($file)
{
$result = false;
if (!is_file($file)) {
return false;
}
$f = @fopen($file, 'rb');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_SH);
$result = stream_get_contents($f);
if ($this->_options['file_locking']) @flock($f, LOCK_UN);
@fclose($f);
}
return $result;
} | [
"protected",
"function",
"_fileGetContents",
"(",
"$",
"file",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"f",
"=",
"@",
"fopen",
"(",
"$",
"file",
",",
"'rb'",
")",
";",
"if",
"(",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'file_locking'",
"]",
")",
"@",
"flock",
"(",
"$",
"f",
",",
"LOCK_SH",
")",
";",
"$",
"result",
"=",
"stream_get_contents",
"(",
"$",
"f",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'file_locking'",
"]",
")",
"@",
"flock",
"(",
"$",
"f",
",",
"LOCK_UN",
")",
";",
"@",
"fclose",
"(",
"$",
"f",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Return the file content of the given file
@param string $file File complete path
@return string File content (or false if problem) | [
"Return",
"the",
"file",
"content",
"of",
"the",
"given",
"file"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L954-L968 |
209,862 | matomo-org/matomo | libs/Zend/Cache/Backend/File.php | Zend_Cache_Backend_File._filePutContents | protected function _filePutContents($file, $string)
{
$result = false;
$f = @fopen($file, 'ab+');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_EX);
fseek($f, 0);
ftruncate($f, 0);
$tmp = @fwrite($f, $string);
if (!($tmp === FALSE)) {
$result = true;
}
@fclose($f);
}
@chmod($file, $this->_options['cache_file_umask']);
return $result;
} | php | protected function _filePutContents($file, $string)
{
$result = false;
$f = @fopen($file, 'ab+');
if ($f) {
if ($this->_options['file_locking']) @flock($f, LOCK_EX);
fseek($f, 0);
ftruncate($f, 0);
$tmp = @fwrite($f, $string);
if (!($tmp === FALSE)) {
$result = true;
}
@fclose($f);
}
@chmod($file, $this->_options['cache_file_umask']);
return $result;
} | [
"protected",
"function",
"_filePutContents",
"(",
"$",
"file",
",",
"$",
"string",
")",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"f",
"=",
"@",
"fopen",
"(",
"$",
"file",
",",
"'ab+'",
")",
";",
"if",
"(",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'file_locking'",
"]",
")",
"@",
"flock",
"(",
"$",
"f",
",",
"LOCK_EX",
")",
";",
"fseek",
"(",
"$",
"f",
",",
"0",
")",
";",
"ftruncate",
"(",
"$",
"f",
",",
"0",
")",
";",
"$",
"tmp",
"=",
"@",
"fwrite",
"(",
"$",
"f",
",",
"$",
"string",
")",
";",
"if",
"(",
"!",
"(",
"$",
"tmp",
"===",
"FALSE",
")",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"@",
"fclose",
"(",
"$",
"f",
")",
";",
"}",
"@",
"chmod",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"_options",
"[",
"'cache_file_umask'",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Put the given string into the given file
@param string $file File complete path
@param string $string String to put in file
@return boolean true if no problem | [
"Put",
"the",
"given",
"string",
"into",
"the",
"given",
"file"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/File.php#L977-L993 |
209,863 | matomo-org/matomo | core/QuickForm2.php | QuickForm2.getSubmitValue | public function getSubmitValue($elementName)
{
$value = $this->getValue();
return isset($value[$elementName]) ? $value[$elementName] : null;
} | php | public function getSubmitValue($elementName)
{
$value = $this->getValue();
return isset($value[$elementName]) ? $value[$elementName] : null;
} | [
"public",
"function",
"getSubmitValue",
"(",
"$",
"elementName",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"value",
"[",
"$",
"elementName",
"]",
")",
"?",
"$",
"value",
"[",
"$",
"elementName",
"]",
":",
"null",
";",
"}"
] | Ported from HTML_QuickForm to minimize changes to Controllers
@param string $elementName
@return mixed | [
"Ported",
"from",
"HTML_QuickForm",
"to",
"minimize",
"changes",
"to",
"Controllers"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/QuickForm2.php#L104-L108 |
209,864 | matomo-org/matomo | core/QuickForm2.php | QuickForm2.getFormData | public function getFormData($groupErrors = true)
{
if (!self::$registered) {
HTML_QuickForm2_Renderer::register('smarty', 'HTML_QuickForm2_Renderer_Smarty');
self::$registered = true;
}
// Create the renderer object
$renderer = HTML_QuickForm2_Renderer::factory('smarty');
$renderer->setOption('group_errors', $groupErrors);
// build the HTML for the form
$this->render($renderer);
return $renderer->toArray();
} | php | public function getFormData($groupErrors = true)
{
if (!self::$registered) {
HTML_QuickForm2_Renderer::register('smarty', 'HTML_QuickForm2_Renderer_Smarty');
self::$registered = true;
}
// Create the renderer object
$renderer = HTML_QuickForm2_Renderer::factory('smarty');
$renderer->setOption('group_errors', $groupErrors);
// build the HTML for the form
$this->render($renderer);
return $renderer->toArray();
} | [
"public",
"function",
"getFormData",
"(",
"$",
"groupErrors",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"registered",
")",
"{",
"HTML_QuickForm2_Renderer",
"::",
"register",
"(",
"'smarty'",
",",
"'HTML_QuickForm2_Renderer_Smarty'",
")",
";",
"self",
"::",
"$",
"registered",
"=",
"true",
";",
"}",
"// Create the renderer object",
"$",
"renderer",
"=",
"HTML_QuickForm2_Renderer",
"::",
"factory",
"(",
"'smarty'",
")",
";",
"$",
"renderer",
"->",
"setOption",
"(",
"'group_errors'",
",",
"$",
"groupErrors",
")",
";",
"// build the HTML for the form",
"$",
"this",
"->",
"render",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"renderer",
"->",
"toArray",
"(",
")",
";",
"}"
] | Returns the rendered form as an array.
@param bool $groupErrors Whether to group errors together or not.
@return array | [
"Returns",
"the",
"rendered",
"form",
"as",
"an",
"array",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/QuickForm2.php#L129-L144 |
209,865 | matomo-org/matomo | plugins/Transitions/API.php | API.getTransitionsForAction | public function getTransitionsForAction($actionName, $actionType, $idSite, $period, $date,
$segment = false, $limitBeforeGrouping = false, $parts = 'all')
{
Piwik::checkUserHasViewAccess($idSite);
// get idaction of the requested action
$idaction = $this->deriveIdAction($actionName, $actionType);
if ($idaction < 0) {
throw new Exception('NoDataForAction');
}
// prepare log aggregator
$segment = new Segment($segment, $idSite);
$site = new Site($idSite);
$period = Period\Factory::build($period, $date);
$params = new ArchiveProcessor\Parameters($site, $period, $segment);
$logAggregator = new LogAggregator($params);
// prepare the report
$report = array(
'date' => Period\Factory::build($period->getLabel(), $date)->getLocalizedShortString()
);
$partsArray = explode(',', $parts);
if ($parts == 'all' || in_array('internalReferrers', $partsArray)) {
$this->addInternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping);
}
if ($parts == 'all' || in_array('followingActions', $partsArray)) {
$includeLoops = $parts != 'all' && !in_array('internalReferrers', $partsArray);
$this->addFollowingActions($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops);
}
if ($parts == 'all' || in_array('externalReferrers', $partsArray)) {
$this->addExternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping);
}
// derive the number of exits from the other metrics
if ($parts == 'all') {
$report['pageMetrics']['exits'] = $report['pageMetrics']['pageviews']
- $this->getTotalTransitionsToFollowingActions()
- $report['pageMetrics']['loops'];
}
// replace column names in the data tables
$reportNames = array(
'previousPages' => true,
'previousSiteSearches' => false,
'followingPages' => true,
'followingSiteSearches' => false,
'outlinks' => true,
'downloads' => true
);
foreach ($reportNames as $reportName => $replaceLabel) {
if (isset($report[$reportName])) {
$columnNames = array(Metrics::INDEX_NB_ACTIONS => 'referrals');
if ($replaceLabel) {
$columnNames[Metrics::INDEX_NB_ACTIONS] = 'referrals';
}
$report[$reportName]->filter('ReplaceColumnNames', array($columnNames));
}
}
return $report;
} | php | public function getTransitionsForAction($actionName, $actionType, $idSite, $period, $date,
$segment = false, $limitBeforeGrouping = false, $parts = 'all')
{
Piwik::checkUserHasViewAccess($idSite);
// get idaction of the requested action
$idaction = $this->deriveIdAction($actionName, $actionType);
if ($idaction < 0) {
throw new Exception('NoDataForAction');
}
// prepare log aggregator
$segment = new Segment($segment, $idSite);
$site = new Site($idSite);
$period = Period\Factory::build($period, $date);
$params = new ArchiveProcessor\Parameters($site, $period, $segment);
$logAggregator = new LogAggregator($params);
// prepare the report
$report = array(
'date' => Period\Factory::build($period->getLabel(), $date)->getLocalizedShortString()
);
$partsArray = explode(',', $parts);
if ($parts == 'all' || in_array('internalReferrers', $partsArray)) {
$this->addInternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping);
}
if ($parts == 'all' || in_array('followingActions', $partsArray)) {
$includeLoops = $parts != 'all' && !in_array('internalReferrers', $partsArray);
$this->addFollowingActions($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops);
}
if ($parts == 'all' || in_array('externalReferrers', $partsArray)) {
$this->addExternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping);
}
// derive the number of exits from the other metrics
if ($parts == 'all') {
$report['pageMetrics']['exits'] = $report['pageMetrics']['pageviews']
- $this->getTotalTransitionsToFollowingActions()
- $report['pageMetrics']['loops'];
}
// replace column names in the data tables
$reportNames = array(
'previousPages' => true,
'previousSiteSearches' => false,
'followingPages' => true,
'followingSiteSearches' => false,
'outlinks' => true,
'downloads' => true
);
foreach ($reportNames as $reportName => $replaceLabel) {
if (isset($report[$reportName])) {
$columnNames = array(Metrics::INDEX_NB_ACTIONS => 'referrals');
if ($replaceLabel) {
$columnNames[Metrics::INDEX_NB_ACTIONS] = 'referrals';
}
$report[$reportName]->filter('ReplaceColumnNames', array($columnNames));
}
}
return $report;
} | [
"public",
"function",
"getTransitionsForAction",
"(",
"$",
"actionName",
",",
"$",
"actionType",
",",
"$",
"idSite",
",",
"$",
"period",
",",
"$",
"date",
",",
"$",
"segment",
"=",
"false",
",",
"$",
"limitBeforeGrouping",
"=",
"false",
",",
"$",
"parts",
"=",
"'all'",
")",
"{",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"idSite",
")",
";",
"// get idaction of the requested action",
"$",
"idaction",
"=",
"$",
"this",
"->",
"deriveIdAction",
"(",
"$",
"actionName",
",",
"$",
"actionType",
")",
";",
"if",
"(",
"$",
"idaction",
"<",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'NoDataForAction'",
")",
";",
"}",
"// prepare log aggregator",
"$",
"segment",
"=",
"new",
"Segment",
"(",
"$",
"segment",
",",
"$",
"idSite",
")",
";",
"$",
"site",
"=",
"new",
"Site",
"(",
"$",
"idSite",
")",
";",
"$",
"period",
"=",
"Period",
"\\",
"Factory",
"::",
"build",
"(",
"$",
"period",
",",
"$",
"date",
")",
";",
"$",
"params",
"=",
"new",
"ArchiveProcessor",
"\\",
"Parameters",
"(",
"$",
"site",
",",
"$",
"period",
",",
"$",
"segment",
")",
";",
"$",
"logAggregator",
"=",
"new",
"LogAggregator",
"(",
"$",
"params",
")",
";",
"// prepare the report",
"$",
"report",
"=",
"array",
"(",
"'date'",
"=>",
"Period",
"\\",
"Factory",
"::",
"build",
"(",
"$",
"period",
"->",
"getLabel",
"(",
")",
",",
"$",
"date",
")",
"->",
"getLocalizedShortString",
"(",
")",
")",
";",
"$",
"partsArray",
"=",
"explode",
"(",
"','",
",",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"parts",
"==",
"'all'",
"||",
"in_array",
"(",
"'internalReferrers'",
",",
"$",
"partsArray",
")",
")",
"{",
"$",
"this",
"->",
"addInternalReferrers",
"(",
"$",
"logAggregator",
",",
"$",
"report",
",",
"$",
"idaction",
",",
"$",
"actionType",
",",
"$",
"limitBeforeGrouping",
")",
";",
"}",
"if",
"(",
"$",
"parts",
"==",
"'all'",
"||",
"in_array",
"(",
"'followingActions'",
",",
"$",
"partsArray",
")",
")",
"{",
"$",
"includeLoops",
"=",
"$",
"parts",
"!=",
"'all'",
"&&",
"!",
"in_array",
"(",
"'internalReferrers'",
",",
"$",
"partsArray",
")",
";",
"$",
"this",
"->",
"addFollowingActions",
"(",
"$",
"logAggregator",
",",
"$",
"report",
",",
"$",
"idaction",
",",
"$",
"actionType",
",",
"$",
"limitBeforeGrouping",
",",
"$",
"includeLoops",
")",
";",
"}",
"if",
"(",
"$",
"parts",
"==",
"'all'",
"||",
"in_array",
"(",
"'externalReferrers'",
",",
"$",
"partsArray",
")",
")",
"{",
"$",
"this",
"->",
"addExternalReferrers",
"(",
"$",
"logAggregator",
",",
"$",
"report",
",",
"$",
"idaction",
",",
"$",
"actionType",
",",
"$",
"limitBeforeGrouping",
")",
";",
"}",
"// derive the number of exits from the other metrics",
"if",
"(",
"$",
"parts",
"==",
"'all'",
")",
"{",
"$",
"report",
"[",
"'pageMetrics'",
"]",
"[",
"'exits'",
"]",
"=",
"$",
"report",
"[",
"'pageMetrics'",
"]",
"[",
"'pageviews'",
"]",
"-",
"$",
"this",
"->",
"getTotalTransitionsToFollowingActions",
"(",
")",
"-",
"$",
"report",
"[",
"'pageMetrics'",
"]",
"[",
"'loops'",
"]",
";",
"}",
"// replace column names in the data tables",
"$",
"reportNames",
"=",
"array",
"(",
"'previousPages'",
"=>",
"true",
",",
"'previousSiteSearches'",
"=>",
"false",
",",
"'followingPages'",
"=>",
"true",
",",
"'followingSiteSearches'",
"=>",
"false",
",",
"'outlinks'",
"=>",
"true",
",",
"'downloads'",
"=>",
"true",
")",
";",
"foreach",
"(",
"$",
"reportNames",
"as",
"$",
"reportName",
"=>",
"$",
"replaceLabel",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"report",
"[",
"$",
"reportName",
"]",
")",
")",
"{",
"$",
"columnNames",
"=",
"array",
"(",
"Metrics",
"::",
"INDEX_NB_ACTIONS",
"=>",
"'referrals'",
")",
";",
"if",
"(",
"$",
"replaceLabel",
")",
"{",
"$",
"columnNames",
"[",
"Metrics",
"::",
"INDEX_NB_ACTIONS",
"]",
"=",
"'referrals'",
";",
"}",
"$",
"report",
"[",
"$",
"reportName",
"]",
"->",
"filter",
"(",
"'ReplaceColumnNames'",
",",
"array",
"(",
"$",
"columnNames",
")",
")",
";",
"}",
"}",
"return",
"$",
"report",
";",
"}"
] | General method to get transitions for an action
@param $actionName
@param $actionType "url"|"title"
@param $idSite
@param $period
@param $date
@param bool $segment
@param bool $limitBeforeGrouping
@param string $parts
@return array
@throws Exception | [
"General",
"method",
"to",
"get",
"transitions",
"for",
"an",
"action"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Transitions/API.php#L61-L123 |
209,866 | matomo-org/matomo | plugins/Transitions/API.php | API.deriveIdAction | private function deriveIdAction($actionName, $actionType)
{
switch ($actionType) {
case 'url':
$originalActionName = $actionName;
$actionName = Common::unsanitizeInputValue($actionName);
$id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
if ($id < 0) {
// an example where this is needed is urls containing < or >
$actionName = $originalActionName;
$id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
}
return $id;
case 'title':
$id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
if ($id < 0) {
$unknown = ArchivingHelper::getUnknownActionName(Action::TYPE_PAGE_TITLE);
if (trim($actionName) == trim($unknown)) {
$id = TableLogAction::getIdActionFromSegment('', 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
}
}
return $id;
default:
throw new Exception('Unknown action type');
}
} | php | private function deriveIdAction($actionName, $actionType)
{
switch ($actionType) {
case 'url':
$originalActionName = $actionName;
$actionName = Common::unsanitizeInputValue($actionName);
$id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
if ($id < 0) {
// an example where this is needed is urls containing < or >
$actionName = $originalActionName;
$id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
}
return $id;
case 'title':
$id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
if ($id < 0) {
$unknown = ArchivingHelper::getUnknownActionName(Action::TYPE_PAGE_TITLE);
if (trim($actionName) == trim($unknown)) {
$id = TableLogAction::getIdActionFromSegment('', 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
}
}
return $id;
default:
throw new Exception('Unknown action type');
}
} | [
"private",
"function",
"deriveIdAction",
"(",
"$",
"actionName",
",",
"$",
"actionType",
")",
"{",
"switch",
"(",
"$",
"actionType",
")",
"{",
"case",
"'url'",
":",
"$",
"originalActionName",
"=",
"$",
"actionName",
";",
"$",
"actionName",
"=",
"Common",
"::",
"unsanitizeInputValue",
"(",
"$",
"actionName",
")",
";",
"$",
"id",
"=",
"TableLogAction",
"::",
"getIdActionFromSegment",
"(",
"$",
"actionName",
",",
"'idaction_url'",
",",
"SegmentExpression",
"::",
"MATCH_EQUAL",
",",
"'pageUrl'",
")",
";",
"if",
"(",
"$",
"id",
"<",
"0",
")",
"{",
"// an example where this is needed is urls containing < or >",
"$",
"actionName",
"=",
"$",
"originalActionName",
";",
"$",
"id",
"=",
"TableLogAction",
"::",
"getIdActionFromSegment",
"(",
"$",
"actionName",
",",
"'idaction_url'",
",",
"SegmentExpression",
"::",
"MATCH_EQUAL",
",",
"'pageUrl'",
")",
";",
"}",
"return",
"$",
"id",
";",
"case",
"'title'",
":",
"$",
"id",
"=",
"TableLogAction",
"::",
"getIdActionFromSegment",
"(",
"$",
"actionName",
",",
"'idaction_name'",
",",
"SegmentExpression",
"::",
"MATCH_EQUAL",
",",
"'pageTitle'",
")",
";",
"if",
"(",
"$",
"id",
"<",
"0",
")",
"{",
"$",
"unknown",
"=",
"ArchivingHelper",
"::",
"getUnknownActionName",
"(",
"Action",
"::",
"TYPE_PAGE_TITLE",
")",
";",
"if",
"(",
"trim",
"(",
"$",
"actionName",
")",
"==",
"trim",
"(",
"$",
"unknown",
")",
")",
"{",
"$",
"id",
"=",
"TableLogAction",
"::",
"getIdActionFromSegment",
"(",
"''",
",",
"'idaction_name'",
",",
"SegmentExpression",
"::",
"MATCH_EQUAL",
",",
"'pageTitle'",
")",
";",
"}",
"}",
"return",
"$",
"id",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"'Unknown action type'",
")",
";",
"}",
"}"
] | Derive the action ID from the request action name and type. | [
"Derive",
"the",
"action",
"ID",
"from",
"the",
"request",
"action",
"name",
"and",
"type",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Transitions/API.php#L128-L159 |
209,867 | matomo-org/matomo | core/Visualization/Sparkline.php | Sparkline.setWidth | public function setWidth($width) {
if (!is_numeric($width) || $width <= 0) {
return;
}
if ($width > self::MAX_WIDTH) {
$this->_width = self::MAX_WIDTH;
} else {
$this->_width = (int)$width;
}
} | php | public function setWidth($width) {
if (!is_numeric($width) || $width <= 0) {
return;
}
if ($width > self::MAX_WIDTH) {
$this->_width = self::MAX_WIDTH;
} else {
$this->_width = (int)$width;
}
} | [
"public",
"function",
"setWidth",
"(",
"$",
"width",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"width",
")",
"||",
"$",
"width",
"<=",
"0",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"width",
">",
"self",
"::",
"MAX_WIDTH",
")",
"{",
"$",
"this",
"->",
"_width",
"=",
"self",
"::",
"MAX_WIDTH",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_width",
"=",
"(",
"int",
")",
"$",
"width",
";",
"}",
"}"
] | Sets the width of the sparkline
@param int $width | [
"Sets",
"the",
"width",
"of",
"the",
"sparkline"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Visualization/Sparkline.php#L116-L125 |
209,868 | matomo-org/matomo | core/Visualization/Sparkline.php | Sparkline.setHeight | public function setHeight($height) {
if (!is_numeric($height) || $height <= 0) {
return;
}
if ($height > self::MAX_HEIGHT) {
$this->_height = self::MAX_HEIGHT;
} else {
$this->_height = (int)$height;
}
} | php | public function setHeight($height) {
if (!is_numeric($height) || $height <= 0) {
return;
}
if ($height > self::MAX_HEIGHT) {
$this->_height = self::MAX_HEIGHT;
} else {
$this->_height = (int)$height;
}
} | [
"public",
"function",
"setHeight",
"(",
"$",
"height",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"height",
")",
"||",
"$",
"height",
"<=",
"0",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"height",
">",
"self",
"::",
"MAX_HEIGHT",
")",
"{",
"$",
"this",
"->",
"_height",
"=",
"self",
"::",
"MAX_HEIGHT",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_height",
"=",
"(",
"int",
")",
"$",
"height",
";",
"}",
"}"
] | Sets the height of the sparkline
@param int $height | [
"Sets",
"the",
"height",
"of",
"the",
"sparkline"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Visualization/Sparkline.php#L139-L148 |
209,869 | matomo-org/matomo | core/Visualization/Sparkline.php | Sparkline.setSparklineColors | private function setSparklineColors($sparkline) {
$colors = Common::getRequestVar('colors', false, 'json');
if (empty($colors)) { // quick fix so row evolution sparklines will have color in widgetize's iframes
$colors = array(
'backgroundColor' => '#ffffff',
'lineColor' => '#162C4A',
'minPointColor' => '#ff7f7f',
'maxPointColor' => '#75BF7C',
'lastPointColor' => '#55AAFF',
'fillColor' => '#ffffff'
);
}
if (strtolower($colors['backgroundColor']) !== '#ffffff') {
$sparkline->setBackgroundColorHex($colors['backgroundColor']);
} else {
$sparkline->deactivateBackgroundColor();
}
$sparkline->setLineColorHex($colors['lineColor']);
if (strtolower($colors['fillColor'] !== "#ffffff")) {
$sparkline->setFillColorHex($colors['fillColor']);
} else {
$sparkline->deactivateFillColor();
}
if (strtolower($colors['minPointColor'] !== "#ffffff")) {
$sparkline->addPoint("minimum", 5, $colors['minPointColor']);
}
if (strtolower($colors['maxPointColor'] !== "#ffffff")) {
$sparkline->addPoint("maximum", 5, $colors['maxPointColor']);
}
if (strtolower($colors['lastPointColor'] !== "#ffffff")) {
$sparkline->addPoint("last", 5, $colors['lastPointColor']);
}
} | php | private function setSparklineColors($sparkline) {
$colors = Common::getRequestVar('colors', false, 'json');
if (empty($colors)) { // quick fix so row evolution sparklines will have color in widgetize's iframes
$colors = array(
'backgroundColor' => '#ffffff',
'lineColor' => '#162C4A',
'minPointColor' => '#ff7f7f',
'maxPointColor' => '#75BF7C',
'lastPointColor' => '#55AAFF',
'fillColor' => '#ffffff'
);
}
if (strtolower($colors['backgroundColor']) !== '#ffffff') {
$sparkline->setBackgroundColorHex($colors['backgroundColor']);
} else {
$sparkline->deactivateBackgroundColor();
}
$sparkline->setLineColorHex($colors['lineColor']);
if (strtolower($colors['fillColor'] !== "#ffffff")) {
$sparkline->setFillColorHex($colors['fillColor']);
} else {
$sparkline->deactivateFillColor();
}
if (strtolower($colors['minPointColor'] !== "#ffffff")) {
$sparkline->addPoint("minimum", 5, $colors['minPointColor']);
}
if (strtolower($colors['maxPointColor'] !== "#ffffff")) {
$sparkline->addPoint("maximum", 5, $colors['maxPointColor']);
}
if (strtolower($colors['lastPointColor'] !== "#ffffff")) {
$sparkline->addPoint("last", 5, $colors['lastPointColor']);
}
} | [
"private",
"function",
"setSparklineColors",
"(",
"$",
"sparkline",
")",
"{",
"$",
"colors",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'colors'",
",",
"false",
",",
"'json'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"colors",
")",
")",
"{",
"// quick fix so row evolution sparklines will have color in widgetize's iframes",
"$",
"colors",
"=",
"array",
"(",
"'backgroundColor'",
"=>",
"'#ffffff'",
",",
"'lineColor'",
"=>",
"'#162C4A'",
",",
"'minPointColor'",
"=>",
"'#ff7f7f'",
",",
"'maxPointColor'",
"=>",
"'#75BF7C'",
",",
"'lastPointColor'",
"=>",
"'#55AAFF'",
",",
"'fillColor'",
"=>",
"'#ffffff'",
")",
";",
"}",
"if",
"(",
"strtolower",
"(",
"$",
"colors",
"[",
"'backgroundColor'",
"]",
")",
"!==",
"'#ffffff'",
")",
"{",
"$",
"sparkline",
"->",
"setBackgroundColorHex",
"(",
"$",
"colors",
"[",
"'backgroundColor'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"sparkline",
"->",
"deactivateBackgroundColor",
"(",
")",
";",
"}",
"$",
"sparkline",
"->",
"setLineColorHex",
"(",
"$",
"colors",
"[",
"'lineColor'",
"]",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"colors",
"[",
"'fillColor'",
"]",
"!==",
"\"#ffffff\"",
")",
")",
"{",
"$",
"sparkline",
"->",
"setFillColorHex",
"(",
"$",
"colors",
"[",
"'fillColor'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"sparkline",
"->",
"deactivateFillColor",
"(",
")",
";",
"}",
"if",
"(",
"strtolower",
"(",
"$",
"colors",
"[",
"'minPointColor'",
"]",
"!==",
"\"#ffffff\"",
")",
")",
"{",
"$",
"sparkline",
"->",
"addPoint",
"(",
"\"minimum\"",
",",
"5",
",",
"$",
"colors",
"[",
"'minPointColor'",
"]",
")",
";",
"}",
"if",
"(",
"strtolower",
"(",
"$",
"colors",
"[",
"'maxPointColor'",
"]",
"!==",
"\"#ffffff\"",
")",
")",
"{",
"$",
"sparkline",
"->",
"addPoint",
"(",
"\"maximum\"",
",",
"5",
",",
"$",
"colors",
"[",
"'maxPointColor'",
"]",
")",
";",
"}",
"if",
"(",
"strtolower",
"(",
"$",
"colors",
"[",
"'lastPointColor'",
"]",
"!==",
"\"#ffffff\"",
")",
")",
"{",
"$",
"sparkline",
"->",
"addPoint",
"(",
"\"last\"",
",",
"5",
",",
"$",
"colors",
"[",
"'lastPointColor'",
"]",
")",
";",
"}",
"}"
] | Sets the sparkline colors
@param \Davaxi\Sparkline $sparkline | [
"Sets",
"the",
"sparkline",
"colors"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Visualization/Sparkline.php#L155-L189 |
209,870 | matomo-org/matomo | core/Period/Week.php | Week.getLocalizedLongString | public function getLocalizedLongString()
{
$string = $this->getTranslatedRange($this->getRangeFormat());
return $this->translator->translate('Intl_PeriodWeek') . " " . $string;
} | php | public function getLocalizedLongString()
{
$string = $this->getTranslatedRange($this->getRangeFormat());
return $this->translator->translate('Intl_PeriodWeek') . " " . $string;
} | [
"public",
"function",
"getLocalizedLongString",
"(",
")",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"getTranslatedRange",
"(",
"$",
"this",
"->",
"getRangeFormat",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"'Intl_PeriodWeek'",
")",
".",
"\" \"",
".",
"$",
"string",
";",
"}"
] | Returns the current period as a localized long string
@return string | [
"Returns",
"the",
"current",
"period",
"as",
"a",
"localized",
"long",
"string"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Week.php#L36-L40 |
209,871 | matomo-org/matomo | core/Period/Week.php | Week.generate | protected function generate()
{
if ($this->subperiodsProcessed) {
return;
}
parent::generate();
$date = $this->date;
if ($date->toString('N') > 1) {
$date = $date->subDay($date->toString('N') - 1);
}
$startWeek = $date;
$currentDay = clone $startWeek;
while ($currentDay->compareWeek($startWeek) == 0) {
$this->addSubperiod(new Day($currentDay));
$currentDay = $currentDay->addDay(1);
}
} | php | protected function generate()
{
if ($this->subperiodsProcessed) {
return;
}
parent::generate();
$date = $this->date;
if ($date->toString('N') > 1) {
$date = $date->subDay($date->toString('N') - 1);
}
$startWeek = $date;
$currentDay = clone $startWeek;
while ($currentDay->compareWeek($startWeek) == 0) {
$this->addSubperiod(new Day($currentDay));
$currentDay = $currentDay->addDay(1);
}
} | [
"protected",
"function",
"generate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"subperiodsProcessed",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"generate",
"(",
")",
";",
"$",
"date",
"=",
"$",
"this",
"->",
"date",
";",
"if",
"(",
"$",
"date",
"->",
"toString",
"(",
"'N'",
")",
">",
"1",
")",
"{",
"$",
"date",
"=",
"$",
"date",
"->",
"subDay",
"(",
"$",
"date",
"->",
"toString",
"(",
"'N'",
")",
"-",
"1",
")",
";",
"}",
"$",
"startWeek",
"=",
"$",
"date",
";",
"$",
"currentDay",
"=",
"clone",
"$",
"startWeek",
";",
"while",
"(",
"$",
"currentDay",
"->",
"compareWeek",
"(",
"$",
"startWeek",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"addSubperiod",
"(",
"new",
"Day",
"(",
"$",
"currentDay",
")",
")",
";",
"$",
"currentDay",
"=",
"$",
"currentDay",
"->",
"addDay",
"(",
"1",
")",
";",
"}",
"}"
] | Generates the subperiods - one for each day in the week | [
"Generates",
"the",
"subperiods",
"-",
"one",
"for",
"each",
"day",
"in",
"the",
"week"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Week.php#L60-L80 |
209,872 | matomo-org/matomo | core/Tracker/Cache.php | Cache.regenerateCacheWebsiteAttributes | public static function regenerateCacheWebsiteAttributes($idSites = array())
{
if (!is_array($idSites)) {
$idSites = array($idSites);
}
foreach ($idSites as $idSite) {
self::deleteCacheWebsiteAttributes($idSite);
self::getCacheWebsiteAttributes($idSite);
}
} | php | public static function regenerateCacheWebsiteAttributes($idSites = array())
{
if (!is_array($idSites)) {
$idSites = array($idSites);
}
foreach ($idSites as $idSite) {
self::deleteCacheWebsiteAttributes($idSite);
self::getCacheWebsiteAttributes($idSite);
}
} | [
"public",
"static",
"function",
"regenerateCacheWebsiteAttributes",
"(",
"$",
"idSites",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"idSites",
")",
")",
"{",
"$",
"idSites",
"=",
"array",
"(",
"$",
"idSites",
")",
";",
"}",
"foreach",
"(",
"$",
"idSites",
"as",
"$",
"idSite",
")",
"{",
"self",
"::",
"deleteCacheWebsiteAttributes",
"(",
"$",
"idSite",
")",
";",
"self",
"::",
"getCacheWebsiteAttributes",
"(",
"$",
"idSite",
")",
";",
"}",
"}"
] | Regenerate Tracker cache files
@param array|int $idSites Array of idSites to clear cache for | [
"Regenerate",
"Tracker",
"cache",
"files"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/Cache.php#L189-L199 |
209,873 | matomo-org/matomo | core/Option.php | Option.set | public static function set($name, $value, $autoload = 0)
{
self::getInstance()->setValue($name, $value, $autoload);
} | php | public static function set($name, $value, $autoload = 0)
{
self::getInstance()->setValue($name, $value, $autoload);
} | [
"public",
"static",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"autoload",
"=",
"0",
")",
"{",
"self",
"::",
"getInstance",
"(",
")",
"->",
"setValue",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"autoload",
")",
";",
"}"
] | Sets an option value by name.
@param string $name The option name.
@param string $value The value to set the option to.
@param int $autoLoad If set to 1, this option value will be automatically loaded when Piwik is initialzed;
should be set to 1 for options that will be used in every Piwik request. | [
"Sets",
"an",
"option",
"value",
"by",
"name",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Option.php#L69-L72 |
209,874 | matomo-org/matomo | core/Option.php | Option.autoload | protected function autoload()
{
if ($this->loaded) {
return;
}
$table = Common::prefixTable('option');
$sql = 'SELECT option_value, option_name FROM `' . $table . '` WHERE autoload = 1';
$all = Db::fetchAll($sql);
foreach ($all as $option) {
$this->all[$option['option_name']] = $option['option_value'];
}
$this->loaded = true;
} | php | protected function autoload()
{
if ($this->loaded) {
return;
}
$table = Common::prefixTable('option');
$sql = 'SELECT option_value, option_name FROM `' . $table . '` WHERE autoload = 1';
$all = Db::fetchAll($sql);
foreach ($all as $option) {
$this->all[$option['option_name']] = $option['option_value'];
}
$this->loaded = true;
} | [
"protected",
"function",
"autoload",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loaded",
")",
"{",
"return",
";",
"}",
"$",
"table",
"=",
"Common",
"::",
"prefixTable",
"(",
"'option'",
")",
";",
"$",
"sql",
"=",
"'SELECT option_value, option_name FROM `'",
".",
"$",
"table",
".",
"'` WHERE autoload = 1'",
";",
"$",
"all",
"=",
"Db",
"::",
"fetchAll",
"(",
"$",
"sql",
")",
";",
"foreach",
"(",
"$",
"all",
"as",
"$",
"option",
")",
"{",
"$",
"this",
"->",
"all",
"[",
"$",
"option",
"[",
"'option_name'",
"]",
"]",
"=",
"$",
"option",
"[",
"'option_value'",
"]",
";",
"}",
"$",
"this",
"->",
"loaded",
"=",
"true",
";",
"}"
] | Initialize cache with autoload settings.
@return void | [
"Initialize",
"cache",
"with",
"autoload",
"settings",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Option.php#L263-L278 |
209,875 | matomo-org/matomo | core/Segment.php | Segment.willBeArchived | public function willBeArchived()
{
if ($this->isEmpty()) {
return true;
}
$idSites = $this->idSites;
if (!is_array($idSites)) {
$idSites = array($this->idSites);
}
return Rules::isRequestAuthorizedToArchive()
|| Rules::isBrowserArchivingAvailableForSegments()
|| Rules::isSegmentPreProcessed($idSites, $this);
} | php | public function willBeArchived()
{
if ($this->isEmpty()) {
return true;
}
$idSites = $this->idSites;
if (!is_array($idSites)) {
$idSites = array($this->idSites);
}
return Rules::isRequestAuthorizedToArchive()
|| Rules::isBrowserArchivingAvailableForSegments()
|| Rules::isSegmentPreProcessed($idSites, $this);
} | [
"public",
"function",
"willBeArchived",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"idSites",
"=",
"$",
"this",
"->",
"idSites",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"idSites",
")",
")",
"{",
"$",
"idSites",
"=",
"array",
"(",
"$",
"this",
"->",
"idSites",
")",
";",
"}",
"return",
"Rules",
"::",
"isRequestAuthorizedToArchive",
"(",
")",
"||",
"Rules",
"::",
"isBrowserArchivingAvailableForSegments",
"(",
")",
"||",
"Rules",
"::",
"isSegmentPreProcessed",
"(",
"$",
"idSites",
",",
"$",
"this",
")",
";",
"}"
] | Detects whether the Piwik instance is configured to be able to archive this segment. It checks whether the segment
will be either archived via browser or cli archiving. It does not check if the segment has been archived. If you
want to know whether the segment has been archived, the actual report data needs to be requested.
This method does not take any date/period into consideration. Meaning a Piwik instance might be able to archive
this segment in general, but not for a certain period if eg the archiving of range dates is disabled.
@return bool | [
"Detects",
"whether",
"the",
"Piwik",
"instance",
"is",
"configured",
"to",
"be",
"able",
"to",
"archive",
"this",
"segment",
".",
"It",
"checks",
"whether",
"the",
"segment",
"will",
"be",
"either",
"archived",
"via",
"browser",
"or",
"cli",
"archiving",
".",
"It",
"does",
"not",
"check",
"if",
"the",
"segment",
"has",
"been",
"archived",
".",
"If",
"you",
"want",
"to",
"know",
"whether",
"the",
"segment",
"has",
"been",
"archived",
"the",
"actual",
"report",
"data",
"needs",
"to",
"be",
"requested",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Segment.php#L235-L249 |
209,876 | matomo-org/matomo | core/Segment.php | Segment.getSelectQuery | public function getSelectQuery($select, $from, $where = false, $bind = array(), $orderBy = false, $groupBy = false, $limit = 0, $offset = 0)
{
$segmentExpression = $this->segmentExpression;
$limitAndOffset = null;
if($limit > 0) {
$limitAndOffset = (int) $offset . ', ' . (int) $limit;
}
return $this->segmentQueryBuilder->getSelectQueryString($segmentExpression, $select, $from, $where, $bind,
$groupBy, $orderBy, $limitAndOffset);
} | php | public function getSelectQuery($select, $from, $where = false, $bind = array(), $orderBy = false, $groupBy = false, $limit = 0, $offset = 0)
{
$segmentExpression = $this->segmentExpression;
$limitAndOffset = null;
if($limit > 0) {
$limitAndOffset = (int) $offset . ', ' . (int) $limit;
}
return $this->segmentQueryBuilder->getSelectQueryString($segmentExpression, $select, $from, $where, $bind,
$groupBy, $orderBy, $limitAndOffset);
} | [
"public",
"function",
"getSelectQuery",
"(",
"$",
"select",
",",
"$",
"from",
",",
"$",
"where",
"=",
"false",
",",
"$",
"bind",
"=",
"array",
"(",
")",
",",
"$",
"orderBy",
"=",
"false",
",",
"$",
"groupBy",
"=",
"false",
",",
"$",
"limit",
"=",
"0",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"segmentExpression",
"=",
"$",
"this",
"->",
"segmentExpression",
";",
"$",
"limitAndOffset",
"=",
"null",
";",
"if",
"(",
"$",
"limit",
">",
"0",
")",
"{",
"$",
"limitAndOffset",
"=",
"(",
"int",
")",
"$",
"offset",
".",
"', '",
".",
"(",
"int",
")",
"$",
"limit",
";",
"}",
"return",
"$",
"this",
"->",
"segmentQueryBuilder",
"->",
"getSelectQueryString",
"(",
"$",
"segmentExpression",
",",
"$",
"select",
",",
"$",
"from",
",",
"$",
"where",
",",
"$",
"bind",
",",
"$",
"groupBy",
",",
"$",
"orderBy",
",",
"$",
"limitAndOffset",
")",
";",
"}"
] | Extend an SQL query that aggregates data over one of the 'log_' tables with segment expressions.
@param string $select The select clause. Should NOT include the **SELECT** just the columns, eg,
`'t1.col1 as col1, t2.col2 as col2'`.
@param array $from Array of table names (without prefix), eg, `array('log_visit', 'log_conversion')`.
@param false|string $where (optional) Where clause, eg, `'t1.col1 = ? AND t2.col2 = ?'`.
@param array|string $bind (optional) Bind parameters, eg, `array($col1Value, $col2Value)`.
@param false|string $orderBy (optional) Order by clause, eg, `"t1.col1 ASC"`.
@param false|string $groupBy (optional) Group by clause, eg, `"t2.col2"`.
@param int $limit Limit number of result to $limit
@param int $offset Specified the offset of the first row to return
@param int If set to value >= 1 then the Select query (and All inner queries) will be LIMIT'ed by this value.
Use only when you're not aggregating or it will sample the data.
@return string The entire select query. | [
"Extend",
"an",
"SQL",
"query",
"that",
"aggregates",
"data",
"over",
"one",
"of",
"the",
"log_",
"tables",
"with",
"segment",
"expressions",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Segment.php#L335-L346 |
209,877 | matomo-org/matomo | core/Segment.php | Segment.combine | public static function combine($segment, $operator, $segmentCondition)
{
if (empty($segment)) {
return $segmentCondition;
}
if (empty($segmentCondition)
|| self::containsCondition($segment, $operator, $segmentCondition)
) {
return $segment;
}
return $segment . $operator . $segmentCondition;
} | php | public static function combine($segment, $operator, $segmentCondition)
{
if (empty($segment)) {
return $segmentCondition;
}
if (empty($segmentCondition)
|| self::containsCondition($segment, $operator, $segmentCondition)
) {
return $segment;
}
return $segment . $operator . $segmentCondition;
} | [
"public",
"static",
"function",
"combine",
"(",
"$",
"segment",
",",
"$",
"operator",
",",
"$",
"segmentCondition",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"segment",
")",
")",
"{",
"return",
"$",
"segmentCondition",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"segmentCondition",
")",
"||",
"self",
"::",
"containsCondition",
"(",
"$",
"segment",
",",
"$",
"operator",
",",
"$",
"segmentCondition",
")",
")",
"{",
"return",
"$",
"segment",
";",
"}",
"return",
"$",
"segment",
".",
"$",
"operator",
".",
"$",
"segmentCondition",
";",
"}"
] | Combines this segment with another segment condition, if the segment condition is not already
in the segment.
The combination is naive in that it does not take order of operations into account.
@param string $segment
@param string $operator The operator to use. Should be either SegmentExpression::AND_DELIMITER
or SegmentExpression::OR_DELIMITER.
@param string $segmentCondition The segment condition to add.
@return string
@throws Exception | [
"Combines",
"this",
"segment",
"with",
"another",
"segment",
"condition",
"if",
"the",
"segment",
"condition",
"is",
"not",
"already",
"in",
"the",
"segment",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Segment.php#L371-L384 |
209,878 | matomo-org/matomo | plugins/ImageGraph/StaticGraph.php | StaticGraph.sendToDisk | public function sendToDisk($filename)
{
$filePath = self::getOutputPath($filename);
$this->pImage->render($filePath);
return $filePath;
} | php | public function sendToDisk($filename)
{
$filePath = self::getOutputPath($filename);
$this->pImage->render($filePath);
return $filePath;
} | [
"public",
"function",
"sendToDisk",
"(",
"$",
"filename",
")",
"{",
"$",
"filePath",
"=",
"self",
"::",
"getOutputPath",
"(",
"$",
"filename",
")",
";",
"$",
"this",
"->",
"pImage",
"->",
"render",
"(",
"$",
"filePath",
")",
";",
"return",
"$",
"filePath",
";",
"}"
] | Save rendering to disk
@param string $filename without path
@return string path of file | [
"Save",
"rendering",
"to",
"disk"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/ImageGraph/StaticGraph.php#L98-L103 |
209,879 | matomo-org/matomo | plugins/Referrers/Tasks.php | Tasks.updateSearchEngines | public function updateSearchEngines()
{
$url = 'https://raw.githubusercontent.com/matomo-org/searchengine-and-social-list/master/SearchEngines.yml';
$list = Http::sendHttpRequest($url, 30);
$searchEngines = SearchEngine::getInstance()->loadYmlData($list);
if (count($searchEngines) < 200) {
return;
}
Option::set(SearchEngine::OPTION_STORAGE_NAME, base64_encode(serialize($searchEngines)));
} | php | public function updateSearchEngines()
{
$url = 'https://raw.githubusercontent.com/matomo-org/searchengine-and-social-list/master/SearchEngines.yml';
$list = Http::sendHttpRequest($url, 30);
$searchEngines = SearchEngine::getInstance()->loadYmlData($list);
if (count($searchEngines) < 200) {
return;
}
Option::set(SearchEngine::OPTION_STORAGE_NAME, base64_encode(serialize($searchEngines)));
} | [
"public",
"function",
"updateSearchEngines",
"(",
")",
"{",
"$",
"url",
"=",
"'https://raw.githubusercontent.com/matomo-org/searchengine-and-social-list/master/SearchEngines.yml'",
";",
"$",
"list",
"=",
"Http",
"::",
"sendHttpRequest",
"(",
"$",
"url",
",",
"30",
")",
";",
"$",
"searchEngines",
"=",
"SearchEngine",
"::",
"getInstance",
"(",
")",
"->",
"loadYmlData",
"(",
"$",
"list",
")",
";",
"if",
"(",
"count",
"(",
"$",
"searchEngines",
")",
"<",
"200",
")",
"{",
"return",
";",
"}",
"Option",
"::",
"set",
"(",
"SearchEngine",
"::",
"OPTION_STORAGE_NAME",
",",
"base64_encode",
"(",
"serialize",
"(",
"$",
"searchEngines",
")",
")",
")",
";",
"}"
] | Update the search engine definitions
@see https://github.com/matomo-org/searchengine-and-social-list | [
"Update",
"the",
"search",
"engine",
"definitions"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Referrers/Tasks.php#L31-L40 |
209,880 | matomo-org/matomo | plugins/Referrers/Tasks.php | Tasks.updateSocials | public function updateSocials()
{
$url = 'https://raw.githubusercontent.com/matomo-org/searchengine-and-social-list/master/Socials.yml';
$list = Http::sendHttpRequest($url, 30);
$socials = Social::getInstance()->loadYmlData($list);
if (count($socials) < 50) {
return;
}
Option::set(Social::OPTION_STORAGE_NAME, base64_encode(serialize($socials)));
} | php | public function updateSocials()
{
$url = 'https://raw.githubusercontent.com/matomo-org/searchengine-and-social-list/master/Socials.yml';
$list = Http::sendHttpRequest($url, 30);
$socials = Social::getInstance()->loadYmlData($list);
if (count($socials) < 50) {
return;
}
Option::set(Social::OPTION_STORAGE_NAME, base64_encode(serialize($socials)));
} | [
"public",
"function",
"updateSocials",
"(",
")",
"{",
"$",
"url",
"=",
"'https://raw.githubusercontent.com/matomo-org/searchengine-and-social-list/master/Socials.yml'",
";",
"$",
"list",
"=",
"Http",
"::",
"sendHttpRequest",
"(",
"$",
"url",
",",
"30",
")",
";",
"$",
"socials",
"=",
"Social",
"::",
"getInstance",
"(",
")",
"->",
"loadYmlData",
"(",
"$",
"list",
")",
";",
"if",
"(",
"count",
"(",
"$",
"socials",
")",
"<",
"50",
")",
"{",
"return",
";",
"}",
"Option",
"::",
"set",
"(",
"Social",
"::",
"OPTION_STORAGE_NAME",
",",
"base64_encode",
"(",
"serialize",
"(",
"$",
"socials",
")",
")",
")",
";",
"}"
] | Update the social definitions
@see https://github.com/matomo-org/searchengine-and-social-list | [
"Update",
"the",
"social",
"definitions"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Referrers/Tasks.php#L47-L56 |
209,881 | matomo-org/matomo | libs/Zend/Mail/Transport/Sendmail.php | Zend_Mail_Transport_Sendmail._prepareHeaders | protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
// require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
}
// mail() uses its $to parameter to set the To: header, and the $subject
// parameter to set the Subject: header. We need to strip them out.
if (0 === strpos(PHP_OS, 'WIN')) {
// If the current recipients list is empty, throw an error
if (empty($this->recipients)) {
/**
* @see Zend_Mail_Transport_Exception
*/
// require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To addresses');
}
} else {
// All others, simply grab the recipients and unset the To: header
if (!isset($headers['To'])) {
/**
* @see Zend_Mail_Transport_Exception
*/
// require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To header');
}
unset($headers['To']['append']);
$this->recipients = implode(',', $headers['To']);
}
// Remove recipient header
unset($headers['To']);
// Remove subject header, if present
if (isset($headers['Subject'])) {
unset($headers['Subject']);
}
// Prepare headers
parent::_prepareHeaders($headers);
// Fix issue with empty blank line ontop when using Sendmail Trnasport
$this->header = rtrim($this->header);
} | php | protected function _prepareHeaders($headers)
{
if (!$this->_mail) {
/**
* @see Zend_Mail_Transport_Exception
*/
// require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
}
// mail() uses its $to parameter to set the To: header, and the $subject
// parameter to set the Subject: header. We need to strip them out.
if (0 === strpos(PHP_OS, 'WIN')) {
// If the current recipients list is empty, throw an error
if (empty($this->recipients)) {
/**
* @see Zend_Mail_Transport_Exception
*/
// require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To addresses');
}
} else {
// All others, simply grab the recipients and unset the To: header
if (!isset($headers['To'])) {
/**
* @see Zend_Mail_Transport_Exception
*/
// require_once 'Zend/Mail/Transport/Exception.php';
throw new Zend_Mail_Transport_Exception('Missing To header');
}
unset($headers['To']['append']);
$this->recipients = implode(',', $headers['To']);
}
// Remove recipient header
unset($headers['To']);
// Remove subject header, if present
if (isset($headers['Subject'])) {
unset($headers['Subject']);
}
// Prepare headers
parent::_prepareHeaders($headers);
// Fix issue with empty blank line ontop when using Sendmail Trnasport
$this->header = rtrim($this->header);
} | [
"protected",
"function",
"_prepareHeaders",
"(",
"$",
"headers",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_mail",
")",
"{",
"/**\n * @see Zend_Mail_Transport_Exception\n */",
"// require_once 'Zend/Mail/Transport/Exception.php';",
"throw",
"new",
"Zend_Mail_Transport_Exception",
"(",
"'_prepareHeaders requires a registered Zend_Mail object'",
")",
";",
"}",
"// mail() uses its $to parameter to set the To: header, and the $subject",
"// parameter to set the Subject: header. We need to strip them out.",
"if",
"(",
"0",
"===",
"strpos",
"(",
"PHP_OS",
",",
"'WIN'",
")",
")",
"{",
"// If the current recipients list is empty, throw an error",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"recipients",
")",
")",
"{",
"/**\n * @see Zend_Mail_Transport_Exception\n */",
"// require_once 'Zend/Mail/Transport/Exception.php';",
"throw",
"new",
"Zend_Mail_Transport_Exception",
"(",
"'Missing To addresses'",
")",
";",
"}",
"}",
"else",
"{",
"// All others, simply grab the recipients and unset the To: header",
"if",
"(",
"!",
"isset",
"(",
"$",
"headers",
"[",
"'To'",
"]",
")",
")",
"{",
"/**\n * @see Zend_Mail_Transport_Exception\n */",
"// require_once 'Zend/Mail/Transport/Exception.php';",
"throw",
"new",
"Zend_Mail_Transport_Exception",
"(",
"'Missing To header'",
")",
";",
"}",
"unset",
"(",
"$",
"headers",
"[",
"'To'",
"]",
"[",
"'append'",
"]",
")",
";",
"$",
"this",
"->",
"recipients",
"=",
"implode",
"(",
"','",
",",
"$",
"headers",
"[",
"'To'",
"]",
")",
";",
"}",
"// Remove recipient header",
"unset",
"(",
"$",
"headers",
"[",
"'To'",
"]",
")",
";",
"// Remove subject header, if present",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'Subject'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"headers",
"[",
"'Subject'",
"]",
")",
";",
"}",
"// Prepare headers",
"parent",
"::",
"_prepareHeaders",
"(",
"$",
"headers",
")",
";",
"// Fix issue with empty blank line ontop when using Sendmail Trnasport",
"$",
"this",
"->",
"header",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"header",
")",
";",
"}"
] | Format and fix headers
mail() uses its $to and $subject arguments to set the To: and Subject:
headers, respectively. This method strips those out as a sanity check to
prevent duplicate header entries.
@access protected
@param array $headers
@return void
@throws Zend_Mail_Transport_Exception | [
"Format",
"and",
"fix",
"headers"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Mail/Transport/Sendmail.php#L154-L202 |
209,882 | matomo-org/matomo | plugins/Installation/FormDatabaseSetup.php | FormDatabaseSetup.createDatabaseObject | public function createDatabaseObject()
{
$dbname = trim($this->getSubmitValue('dbname'));
if (empty($dbname)) // disallow database object creation w/ no selected database
{
throw new Exception("No database name");
}
$adapter = $this->getSubmitValue('adapter');
$port = Adapter::getDefaultPortForAdapter($adapter);
$host = $this->getSubmitValue('host');
$tables_prefix = $this->getSubmitValue('tables_prefix');
$dbInfos = array(
'host' => (is_null($host)) ? $host : trim($host),
'username' => $this->getSubmitValue('username'),
'password' => $this->getSubmitValue('password'),
'dbname' => $dbname,
'tables_prefix' => (is_null($tables_prefix)) ? $tables_prefix : trim($tables_prefix),
'adapter' => $adapter,
'port' => $port,
'schema' => Config::getInstance()->database['schema'],
'type' => $this->getSubmitValue('type')
);
if (($portIndex = strpos($dbInfos['host'], '/')) !== false) {
// unix_socket=/path/sock.n
$dbInfos['port'] = substr($dbInfos['host'], $portIndex);
$dbInfos['host'] = '';
} else if (($portIndex = strpos($dbInfos['host'], ':')) !== false) {
// host:port
$dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1);
$dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex);
}
try {
@Db::createDatabaseObject($dbInfos);
} catch (Zend_Db_Adapter_Exception $e) {
$db = Adapter::factory($adapter, $dbInfos, $connect = false);
// database not found, we try to create it
if ($db->isErrNo($e, '1049')) {
$dbInfosConnectOnly = $dbInfos;
$dbInfosConnectOnly['dbname'] = null;
@Db::createDatabaseObject($dbInfosConnectOnly);
@DbHelper::createDatabase($dbInfos['dbname']);
// select the newly created database
@Db::createDatabaseObject($dbInfos);
} else {
throw $e;
}
}
return $dbInfos;
} | php | public function createDatabaseObject()
{
$dbname = trim($this->getSubmitValue('dbname'));
if (empty($dbname)) // disallow database object creation w/ no selected database
{
throw new Exception("No database name");
}
$adapter = $this->getSubmitValue('adapter');
$port = Adapter::getDefaultPortForAdapter($adapter);
$host = $this->getSubmitValue('host');
$tables_prefix = $this->getSubmitValue('tables_prefix');
$dbInfos = array(
'host' => (is_null($host)) ? $host : trim($host),
'username' => $this->getSubmitValue('username'),
'password' => $this->getSubmitValue('password'),
'dbname' => $dbname,
'tables_prefix' => (is_null($tables_prefix)) ? $tables_prefix : trim($tables_prefix),
'adapter' => $adapter,
'port' => $port,
'schema' => Config::getInstance()->database['schema'],
'type' => $this->getSubmitValue('type')
);
if (($portIndex = strpos($dbInfos['host'], '/')) !== false) {
// unix_socket=/path/sock.n
$dbInfos['port'] = substr($dbInfos['host'], $portIndex);
$dbInfos['host'] = '';
} else if (($portIndex = strpos($dbInfos['host'], ':')) !== false) {
// host:port
$dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1);
$dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex);
}
try {
@Db::createDatabaseObject($dbInfos);
} catch (Zend_Db_Adapter_Exception $e) {
$db = Adapter::factory($adapter, $dbInfos, $connect = false);
// database not found, we try to create it
if ($db->isErrNo($e, '1049')) {
$dbInfosConnectOnly = $dbInfos;
$dbInfosConnectOnly['dbname'] = null;
@Db::createDatabaseObject($dbInfosConnectOnly);
@DbHelper::createDatabase($dbInfos['dbname']);
// select the newly created database
@Db::createDatabaseObject($dbInfos);
} else {
throw $e;
}
}
return $dbInfos;
} | [
"public",
"function",
"createDatabaseObject",
"(",
")",
"{",
"$",
"dbname",
"=",
"trim",
"(",
"$",
"this",
"->",
"getSubmitValue",
"(",
"'dbname'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"dbname",
")",
")",
"// disallow database object creation w/ no selected database",
"{",
"throw",
"new",
"Exception",
"(",
"\"No database name\"",
")",
";",
"}",
"$",
"adapter",
"=",
"$",
"this",
"->",
"getSubmitValue",
"(",
"'adapter'",
")",
";",
"$",
"port",
"=",
"Adapter",
"::",
"getDefaultPortForAdapter",
"(",
"$",
"adapter",
")",
";",
"$",
"host",
"=",
"$",
"this",
"->",
"getSubmitValue",
"(",
"'host'",
")",
";",
"$",
"tables_prefix",
"=",
"$",
"this",
"->",
"getSubmitValue",
"(",
"'tables_prefix'",
")",
";",
"$",
"dbInfos",
"=",
"array",
"(",
"'host'",
"=>",
"(",
"is_null",
"(",
"$",
"host",
")",
")",
"?",
"$",
"host",
":",
"trim",
"(",
"$",
"host",
")",
",",
"'username'",
"=>",
"$",
"this",
"->",
"getSubmitValue",
"(",
"'username'",
")",
",",
"'password'",
"=>",
"$",
"this",
"->",
"getSubmitValue",
"(",
"'password'",
")",
",",
"'dbname'",
"=>",
"$",
"dbname",
",",
"'tables_prefix'",
"=>",
"(",
"is_null",
"(",
"$",
"tables_prefix",
")",
")",
"?",
"$",
"tables_prefix",
":",
"trim",
"(",
"$",
"tables_prefix",
")",
",",
"'adapter'",
"=>",
"$",
"adapter",
",",
"'port'",
"=>",
"$",
"port",
",",
"'schema'",
"=>",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"database",
"[",
"'schema'",
"]",
",",
"'type'",
"=>",
"$",
"this",
"->",
"getSubmitValue",
"(",
"'type'",
")",
")",
";",
"if",
"(",
"(",
"$",
"portIndex",
"=",
"strpos",
"(",
"$",
"dbInfos",
"[",
"'host'",
"]",
",",
"'/'",
")",
")",
"!==",
"false",
")",
"{",
"// unix_socket=/path/sock.n",
"$",
"dbInfos",
"[",
"'port'",
"]",
"=",
"substr",
"(",
"$",
"dbInfos",
"[",
"'host'",
"]",
",",
"$",
"portIndex",
")",
";",
"$",
"dbInfos",
"[",
"'host'",
"]",
"=",
"''",
";",
"}",
"else",
"if",
"(",
"(",
"$",
"portIndex",
"=",
"strpos",
"(",
"$",
"dbInfos",
"[",
"'host'",
"]",
",",
"':'",
")",
")",
"!==",
"false",
")",
"{",
"// host:port",
"$",
"dbInfos",
"[",
"'port'",
"]",
"=",
"substr",
"(",
"$",
"dbInfos",
"[",
"'host'",
"]",
",",
"$",
"portIndex",
"+",
"1",
")",
";",
"$",
"dbInfos",
"[",
"'host'",
"]",
"=",
"substr",
"(",
"$",
"dbInfos",
"[",
"'host'",
"]",
",",
"0",
",",
"$",
"portIndex",
")",
";",
"}",
"try",
"{",
"@",
"Db",
"::",
"createDatabaseObject",
"(",
"$",
"dbInfos",
")",
";",
"}",
"catch",
"(",
"Zend_Db_Adapter_Exception",
"$",
"e",
")",
"{",
"$",
"db",
"=",
"Adapter",
"::",
"factory",
"(",
"$",
"adapter",
",",
"$",
"dbInfos",
",",
"$",
"connect",
"=",
"false",
")",
";",
"// database not found, we try to create it",
"if",
"(",
"$",
"db",
"->",
"isErrNo",
"(",
"$",
"e",
",",
"'1049'",
")",
")",
"{",
"$",
"dbInfosConnectOnly",
"=",
"$",
"dbInfos",
";",
"$",
"dbInfosConnectOnly",
"[",
"'dbname'",
"]",
"=",
"null",
";",
"@",
"Db",
"::",
"createDatabaseObject",
"(",
"$",
"dbInfosConnectOnly",
")",
";",
"@",
"DbHelper",
"::",
"createDatabase",
"(",
"$",
"dbInfos",
"[",
"'dbname'",
"]",
")",
";",
"// select the newly created database",
"@",
"Db",
"::",
"createDatabaseObject",
"(",
"$",
"dbInfos",
")",
";",
"}",
"else",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"return",
"$",
"dbInfos",
";",
"}"
] | Creates database object based on form data.
@throws Exception|Zend_Db_Adapter_Exception
@return array The database connection info. Can be passed into Piwik::createDatabaseObject. | [
"Creates",
"database",
"object",
"based",
"on",
"form",
"data",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Installation/FormDatabaseSetup.php#L111-L167 |
209,883 | matomo-org/matomo | plugins/Installation/FormDatabaseSetup.php | Rule_checkUserPrivileges.validateOwner | public function validateOwner()
{
// try and create the database object
try {
$this->createDatabaseObject();
} catch (Exception $ex) {
if ($this->isAccessDenied($ex)) {
return false;
} else {
return true; // if we can't create the database object, skip this validation
}
}
$db = Db::get();
try {
// try to drop tables before running privilege tests
$this->dropExtraTables($db);
} catch (Exception $ex) {
if ($this->isAccessDenied($ex)) {
return false;
} else {
throw $ex;
}
}
// check each required privilege by running a query that uses it
foreach (self::getRequiredPrivileges() as $privilegeType => $queries) {
if (!is_array($queries)) {
$queries = array($queries);
}
foreach ($queries as $sql) {
try {
if (in_array($privilegeType, array('SELECT'))) {
$db->fetchAll($sql);
} else {
$db->exec($sql);
}
} catch (Exception $ex) {
if ($this->isAccessDenied($ex)) {
return false;
} else {
throw new Exception("Test SQL failed to execute: $sql\nError: " . $ex->getMessage());
}
}
}
}
// remove extra tables that were created
$this->dropExtraTables($db);
return true;
} | php | public function validateOwner()
{
// try and create the database object
try {
$this->createDatabaseObject();
} catch (Exception $ex) {
if ($this->isAccessDenied($ex)) {
return false;
} else {
return true; // if we can't create the database object, skip this validation
}
}
$db = Db::get();
try {
// try to drop tables before running privilege tests
$this->dropExtraTables($db);
} catch (Exception $ex) {
if ($this->isAccessDenied($ex)) {
return false;
} else {
throw $ex;
}
}
// check each required privilege by running a query that uses it
foreach (self::getRequiredPrivileges() as $privilegeType => $queries) {
if (!is_array($queries)) {
$queries = array($queries);
}
foreach ($queries as $sql) {
try {
if (in_array($privilegeType, array('SELECT'))) {
$db->fetchAll($sql);
} else {
$db->exec($sql);
}
} catch (Exception $ex) {
if ($this->isAccessDenied($ex)) {
return false;
} else {
throw new Exception("Test SQL failed to execute: $sql\nError: " . $ex->getMessage());
}
}
}
}
// remove extra tables that were created
$this->dropExtraTables($db);
return true;
} | [
"public",
"function",
"validateOwner",
"(",
")",
"{",
"// try and create the database object",
"try",
"{",
"$",
"this",
"->",
"createDatabaseObject",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAccessDenied",
"(",
"$",
"ex",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"// if we can't create the database object, skip this validation",
"}",
"}",
"$",
"db",
"=",
"Db",
"::",
"get",
"(",
")",
";",
"try",
"{",
"// try to drop tables before running privilege tests",
"$",
"this",
"->",
"dropExtraTables",
"(",
"$",
"db",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAccessDenied",
"(",
"$",
"ex",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"$",
"ex",
";",
"}",
"}",
"// check each required privilege by running a query that uses it",
"foreach",
"(",
"self",
"::",
"getRequiredPrivileges",
"(",
")",
"as",
"$",
"privilegeType",
"=>",
"$",
"queries",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"queries",
")",
")",
"{",
"$",
"queries",
"=",
"array",
"(",
"$",
"queries",
")",
";",
"}",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"sql",
")",
"{",
"try",
"{",
"if",
"(",
"in_array",
"(",
"$",
"privilegeType",
",",
"array",
"(",
"'SELECT'",
")",
")",
")",
"{",
"$",
"db",
"->",
"fetchAll",
"(",
"$",
"sql",
")",
";",
"}",
"else",
"{",
"$",
"db",
"->",
"exec",
"(",
"$",
"sql",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAccessDenied",
"(",
"$",
"ex",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Test SQL failed to execute: $sql\\nError: \"",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"// remove extra tables that were created",
"$",
"this",
"->",
"dropExtraTables",
"(",
"$",
"db",
")",
";",
"return",
"true",
";",
"}"
] | Checks that the DB user entered in the form has the necessary privileges for Piwik
to run. | [
"Checks",
"that",
"the",
"DB",
"user",
"entered",
"in",
"the",
"form",
"has",
"the",
"necessary",
"privileges",
"for",
"Piwik",
"to",
"run",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Installation/FormDatabaseSetup.php#L193-L246 |
209,884 | matomo-org/matomo | plugins/Installation/FormDatabaseSetup.php | Rule_checkUserPrivileges.getRequiredPrivileges | public static function getRequiredPrivileges()
{
return array(
'CREATE' => 'CREATE TABLE ' . self::TEST_TABLE_NAME . ' (
id INT AUTO_INCREMENT,
value INT,
PRIMARY KEY (id),
KEY index_value (value)
)',
'ALTER' => 'ALTER TABLE ' . self::TEST_TABLE_NAME . '
ADD COLUMN other_value INT DEFAULT 0',
'SELECT' => 'SELECT * FROM ' . self::TEST_TABLE_NAME,
'INSERT' => 'INSERT INTO ' . self::TEST_TABLE_NAME . ' (value) VALUES (123)',
'UPDATE' => 'UPDATE ' . self::TEST_TABLE_NAME . ' SET value = 456 WHERE id = 1',
'DELETE' => 'DELETE FROM ' . self::TEST_TABLE_NAME . ' WHERE id = 1',
'DROP' => 'DROP TABLE ' . self::TEST_TABLE_NAME,
'CREATE TEMPORARY TABLES' => 'CREATE TEMPORARY TABLE ' . self::TEST_TEMP_TABLE_NAME . ' (
id INT AUTO_INCREMENT,
PRIMARY KEY (id)
)',
);
} | php | public static function getRequiredPrivileges()
{
return array(
'CREATE' => 'CREATE TABLE ' . self::TEST_TABLE_NAME . ' (
id INT AUTO_INCREMENT,
value INT,
PRIMARY KEY (id),
KEY index_value (value)
)',
'ALTER' => 'ALTER TABLE ' . self::TEST_TABLE_NAME . '
ADD COLUMN other_value INT DEFAULT 0',
'SELECT' => 'SELECT * FROM ' . self::TEST_TABLE_NAME,
'INSERT' => 'INSERT INTO ' . self::TEST_TABLE_NAME . ' (value) VALUES (123)',
'UPDATE' => 'UPDATE ' . self::TEST_TABLE_NAME . ' SET value = 456 WHERE id = 1',
'DELETE' => 'DELETE FROM ' . self::TEST_TABLE_NAME . ' WHERE id = 1',
'DROP' => 'DROP TABLE ' . self::TEST_TABLE_NAME,
'CREATE TEMPORARY TABLES' => 'CREATE TEMPORARY TABLE ' . self::TEST_TEMP_TABLE_NAME . ' (
id INT AUTO_INCREMENT,
PRIMARY KEY (id)
)',
);
} | [
"public",
"static",
"function",
"getRequiredPrivileges",
"(",
")",
"{",
"return",
"array",
"(",
"'CREATE'",
"=>",
"'CREATE TABLE '",
".",
"self",
"::",
"TEST_TABLE_NAME",
".",
"' (\n id INT AUTO_INCREMENT,\n value INT,\n PRIMARY KEY (id),\n KEY index_value (value)\n )'",
",",
"'ALTER'",
"=>",
"'ALTER TABLE '",
".",
"self",
"::",
"TEST_TABLE_NAME",
".",
"'\n ADD COLUMN other_value INT DEFAULT 0'",
",",
"'SELECT'",
"=>",
"'SELECT * FROM '",
".",
"self",
"::",
"TEST_TABLE_NAME",
",",
"'INSERT'",
"=>",
"'INSERT INTO '",
".",
"self",
"::",
"TEST_TABLE_NAME",
".",
"' (value) VALUES (123)'",
",",
"'UPDATE'",
"=>",
"'UPDATE '",
".",
"self",
"::",
"TEST_TABLE_NAME",
".",
"' SET value = 456 WHERE id = 1'",
",",
"'DELETE'",
"=>",
"'DELETE FROM '",
".",
"self",
"::",
"TEST_TABLE_NAME",
".",
"' WHERE id = 1'",
",",
"'DROP'",
"=>",
"'DROP TABLE '",
".",
"self",
"::",
"TEST_TABLE_NAME",
",",
"'CREATE TEMPORARY TABLES'",
"=>",
"'CREATE TEMPORARY TABLE '",
".",
"self",
"::",
"TEST_TEMP_TABLE_NAME",
".",
"' (\n id INT AUTO_INCREMENT,\n PRIMARY KEY (id)\n )'",
",",
")",
";",
"}"
] | Returns an array describing the database privileges required for Matomo to run. The
array maps privilege names with one or more SQL queries that can be used to test
if the current user has the privilege.
NOTE: LOAD DATA INFILE & LOCK TABLES privileges are not **required** so they're
not checked.
@return array | [
"Returns",
"an",
"array",
"describing",
"the",
"database",
"privileges",
"required",
"for",
"Matomo",
"to",
"run",
".",
"The",
"array",
"maps",
"privilege",
"names",
"with",
"one",
"or",
"more",
"SQL",
"queries",
"that",
"can",
"be",
"used",
"to",
"test",
"if",
"the",
"current",
"user",
"has",
"the",
"privilege",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Installation/FormDatabaseSetup.php#L258-L279 |
209,885 | matomo-org/matomo | plugins/Login/SessionInitializer.php | SessionInitializer.getAuthCookie | protected function getAuthCookie($rememberMe)
{
$authCookieExpiry = $rememberMe ? time() + $this->authCookieValidTime : 0;
$cookie = new Cookie($this->authCookieName, $authCookieExpiry, $this->authCookiePath);
return $cookie;
} | php | protected function getAuthCookie($rememberMe)
{
$authCookieExpiry = $rememberMe ? time() + $this->authCookieValidTime : 0;
$cookie = new Cookie($this->authCookieName, $authCookieExpiry, $this->authCookiePath);
return $cookie;
} | [
"protected",
"function",
"getAuthCookie",
"(",
"$",
"rememberMe",
")",
"{",
"$",
"authCookieExpiry",
"=",
"$",
"rememberMe",
"?",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"authCookieValidTime",
":",
"0",
";",
"$",
"cookie",
"=",
"new",
"Cookie",
"(",
"$",
"this",
"->",
"authCookieName",
",",
"$",
"authCookieExpiry",
",",
"$",
"this",
"->",
"authCookiePath",
")",
";",
"return",
"$",
"cookie",
";",
"}"
] | Returns a Cookie instance that manages the browser cookie used to store session
information.
@param bool $rememberMe Whether the authenticated session should be remembered after
the browser is closed or not.
@return Cookie | [
"Returns",
"a",
"Cookie",
"instance",
"that",
"manages",
"the",
"browser",
"cookie",
"used",
"to",
"store",
"session",
"information",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Login/SessionInitializer.php#L153-L158 |
209,886 | matomo-org/matomo | plugins/Login/SessionInitializer.php | SessionInitializer.processFailedSession | protected function processFailedSession($rememberMe)
{
$cookie = $this->getAuthCookie($rememberMe);
$cookie->delete();
throw new Exception(Piwik::translate('Login_LoginPasswordNotCorrect'));
} | php | protected function processFailedSession($rememberMe)
{
$cookie = $this->getAuthCookie($rememberMe);
$cookie->delete();
throw new Exception(Piwik::translate('Login_LoginPasswordNotCorrect'));
} | [
"protected",
"function",
"processFailedSession",
"(",
"$",
"rememberMe",
")",
"{",
"$",
"cookie",
"=",
"$",
"this",
"->",
"getAuthCookie",
"(",
"$",
"rememberMe",
")",
";",
"$",
"cookie",
"->",
"delete",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"Piwik",
"::",
"translate",
"(",
"'Login_LoginPasswordNotCorrect'",
")",
")",
";",
"}"
] | Executed when the session could not authenticate.
@param bool $rememberMe Whether the authenticated session should be remembered after
the browser is closed or not.
@throws Exception always. | [
"Executed",
"when",
"the",
"session",
"could",
"not",
"authenticate",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Login/SessionInitializer.php#L167-L173 |
209,887 | matomo-org/matomo | plugins/UserCountry/LocationProvider/DefaultProvider.php | DefaultProvider.getLocation | public function getLocation($info)
{
$enableLanguageToCountryGuess = Config::getInstance()->Tracker['enable_language_to_country_guess'];
if (empty($info['lang'])) {
$info['lang'] = Common::getBrowserLanguage();
}
$country = Common::getCountry($info['lang'], $enableLanguageToCountryGuess, $info['ip']);
$location = array(parent::COUNTRY_CODE_KEY => $country);
$this->completeLocationResult($location);
return $location;
} | php | public function getLocation($info)
{
$enableLanguageToCountryGuess = Config::getInstance()->Tracker['enable_language_to_country_guess'];
if (empty($info['lang'])) {
$info['lang'] = Common::getBrowserLanguage();
}
$country = Common::getCountry($info['lang'], $enableLanguageToCountryGuess, $info['ip']);
$location = array(parent::COUNTRY_CODE_KEY => $country);
$this->completeLocationResult($location);
return $location;
} | [
"public",
"function",
"getLocation",
"(",
"$",
"info",
")",
"{",
"$",
"enableLanguageToCountryGuess",
"=",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"Tracker",
"[",
"'enable_language_to_country_guess'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"info",
"[",
"'lang'",
"]",
")",
")",
"{",
"$",
"info",
"[",
"'lang'",
"]",
"=",
"Common",
"::",
"getBrowserLanguage",
"(",
")",
";",
"}",
"$",
"country",
"=",
"Common",
"::",
"getCountry",
"(",
"$",
"info",
"[",
"'lang'",
"]",
",",
"$",
"enableLanguageToCountryGuess",
",",
"$",
"info",
"[",
"'ip'",
"]",
")",
";",
"$",
"location",
"=",
"array",
"(",
"parent",
"::",
"COUNTRY_CODE_KEY",
"=>",
"$",
"country",
")",
";",
"$",
"this",
"->",
"completeLocationResult",
"(",
"$",
"location",
")",
";",
"return",
"$",
"location",
";",
"}"
] | Guesses a visitor's location using a visitor's browser language.
@param array $info Contains 'ip' & 'lang' keys.
@return array Contains the guessed country code mapped to LocationProvider::COUNTRY_CODE_KEY. | [
"Guesses",
"a",
"visitor",
"s",
"location",
"using",
"a",
"visitor",
"s",
"browser",
"language",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/DefaultProvider.php#L32-L45 |
209,888 | matomo-org/matomo | core/Metrics/Formatter.php | Formatter.getPrettyNumber | public function getPrettyNumber($value, $precision = 0)
{
if ($this->decimalPoint === null) {
$locale = localeconv();
$this->decimalPoint = $locale['decimal_point'];
$this->thousandsSeparator = $locale['thousands_sep'];
}
return number_format($value, $precision, $this->decimalPoint, $this->thousandsSeparator);
} | php | public function getPrettyNumber($value, $precision = 0)
{
if ($this->decimalPoint === null) {
$locale = localeconv();
$this->decimalPoint = $locale['decimal_point'];
$this->thousandsSeparator = $locale['thousands_sep'];
}
return number_format($value, $precision, $this->decimalPoint, $this->thousandsSeparator);
} | [
"public",
"function",
"getPrettyNumber",
"(",
"$",
"value",
",",
"$",
"precision",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"decimalPoint",
"===",
"null",
")",
"{",
"$",
"locale",
"=",
"localeconv",
"(",
")",
";",
"$",
"this",
"->",
"decimalPoint",
"=",
"$",
"locale",
"[",
"'decimal_point'",
"]",
";",
"$",
"this",
"->",
"thousandsSeparator",
"=",
"$",
"locale",
"[",
"'thousands_sep'",
"]",
";",
"}",
"return",
"number_format",
"(",
"$",
"value",
",",
"$",
"precision",
",",
"$",
"this",
"->",
"decimalPoint",
",",
"$",
"this",
"->",
"thousandsSeparator",
")",
";",
"}"
] | Returns a prettified string representation of a number. The result will have
thousands separators and a decimal point specific to the current locale, eg,
`'1,000,000.05'` or `'1.000.000,05'`.
@param number $value
@return string
@api | [
"Returns",
"a",
"prettified",
"string",
"representation",
"of",
"a",
"number",
".",
"The",
"result",
"will",
"have",
"thousands",
"separators",
"and",
"a",
"decimal",
"point",
"specific",
"to",
"the",
"current",
"locale",
"eg",
"1",
"000",
"000",
".",
"05",
"or",
"1",
".",
"000",
".",
"000",
"05",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Metrics/Formatter.php#L42-L52 |
209,889 | matomo-org/matomo | core/Metrics/Formatter.php | Formatter.formatMetrics | public function formatMetrics(DataTable $dataTable, Report $report = null, $metricsToFormat = null, $formatAll = false)
{
$metrics = $this->getMetricsToFormat($dataTable, $report);
if (empty($metrics)
|| $dataTable->getMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG)
) {
return;
}
$dataTable->setMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG, true);
if ($metricsToFormat !== null) {
$metricMatchRegex = $this->makeRegexToMatchMetrics($metricsToFormat);
$metrics = array_filter($metrics, function ($metric) use ($metricMatchRegex) {
/** @var ProcessedMetric|ArchivedMetric $metric */
return preg_match($metricMatchRegex, $metric->getName());
});
}
foreach ($metrics as $name => $metric) {
if (!$metric->beforeFormat($report, $dataTable)) {
continue;
}
foreach ($dataTable->getRows() as $row) {
$columnValue = $row->getColumn($name);
if ($columnValue !== false) {
$row->setColumn($name, $metric->format($columnValue, $this));
}
}
}
foreach ($dataTable->getRows() as $row) {
$subtable = $row->getSubtable();
if (!empty($subtable)) {
$this->formatMetrics($subtable, $report, $metricsToFormat);
}
}
$idSite = DataTableFactory::getSiteIdFromMetadata($dataTable);
if (empty($idSite)) {
// possible when using search in visualization
$idSite = Common::getRequestVar('idSite', 0, 'int');
}
// @todo for matomo 4, should really use the Metric class to house this kind of logic
// format other metrics
if ($formatAll) {
foreach ($dataTable->getRows() as $row) {
foreach ($row->getColumns() as $column => $columnValue) {
if (strpos($column, 'revenue') === false
|| !is_numeric($columnValue)
) {
continue;
}
if ($columnValue !== false) {
$row->setColumn($column, $this->getPrettyMoney($columnValue, $idSite));
}
}
}
}
} | php | public function formatMetrics(DataTable $dataTable, Report $report = null, $metricsToFormat = null, $formatAll = false)
{
$metrics = $this->getMetricsToFormat($dataTable, $report);
if (empty($metrics)
|| $dataTable->getMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG)
) {
return;
}
$dataTable->setMetadata(self::PROCESSED_METRICS_FORMATTED_FLAG, true);
if ($metricsToFormat !== null) {
$metricMatchRegex = $this->makeRegexToMatchMetrics($metricsToFormat);
$metrics = array_filter($metrics, function ($metric) use ($metricMatchRegex) {
/** @var ProcessedMetric|ArchivedMetric $metric */
return preg_match($metricMatchRegex, $metric->getName());
});
}
foreach ($metrics as $name => $metric) {
if (!$metric->beforeFormat($report, $dataTable)) {
continue;
}
foreach ($dataTable->getRows() as $row) {
$columnValue = $row->getColumn($name);
if ($columnValue !== false) {
$row->setColumn($name, $metric->format($columnValue, $this));
}
}
}
foreach ($dataTable->getRows() as $row) {
$subtable = $row->getSubtable();
if (!empty($subtable)) {
$this->formatMetrics($subtable, $report, $metricsToFormat);
}
}
$idSite = DataTableFactory::getSiteIdFromMetadata($dataTable);
if (empty($idSite)) {
// possible when using search in visualization
$idSite = Common::getRequestVar('idSite', 0, 'int');
}
// @todo for matomo 4, should really use the Metric class to house this kind of logic
// format other metrics
if ($formatAll) {
foreach ($dataTable->getRows() as $row) {
foreach ($row->getColumns() as $column => $columnValue) {
if (strpos($column, 'revenue') === false
|| !is_numeric($columnValue)
) {
continue;
}
if ($columnValue !== false) {
$row->setColumn($column, $this->getPrettyMoney($columnValue, $idSite));
}
}
}
}
} | [
"public",
"function",
"formatMetrics",
"(",
"DataTable",
"$",
"dataTable",
",",
"Report",
"$",
"report",
"=",
"null",
",",
"$",
"metricsToFormat",
"=",
"null",
",",
"$",
"formatAll",
"=",
"false",
")",
"{",
"$",
"metrics",
"=",
"$",
"this",
"->",
"getMetricsToFormat",
"(",
"$",
"dataTable",
",",
"$",
"report",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"metrics",
")",
"||",
"$",
"dataTable",
"->",
"getMetadata",
"(",
"self",
"::",
"PROCESSED_METRICS_FORMATTED_FLAG",
")",
")",
"{",
"return",
";",
"}",
"$",
"dataTable",
"->",
"setMetadata",
"(",
"self",
"::",
"PROCESSED_METRICS_FORMATTED_FLAG",
",",
"true",
")",
";",
"if",
"(",
"$",
"metricsToFormat",
"!==",
"null",
")",
"{",
"$",
"metricMatchRegex",
"=",
"$",
"this",
"->",
"makeRegexToMatchMetrics",
"(",
"$",
"metricsToFormat",
")",
";",
"$",
"metrics",
"=",
"array_filter",
"(",
"$",
"metrics",
",",
"function",
"(",
"$",
"metric",
")",
"use",
"(",
"$",
"metricMatchRegex",
")",
"{",
"/** @var ProcessedMetric|ArchivedMetric $metric */",
"return",
"preg_match",
"(",
"$",
"metricMatchRegex",
",",
"$",
"metric",
"->",
"getName",
"(",
")",
")",
";",
"}",
")",
";",
"}",
"foreach",
"(",
"$",
"metrics",
"as",
"$",
"name",
"=>",
"$",
"metric",
")",
"{",
"if",
"(",
"!",
"$",
"metric",
"->",
"beforeFormat",
"(",
"$",
"report",
",",
"$",
"dataTable",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"dataTable",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"columnValue",
"=",
"$",
"row",
"->",
"getColumn",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"columnValue",
"!==",
"false",
")",
"{",
"$",
"row",
"->",
"setColumn",
"(",
"$",
"name",
",",
"$",
"metric",
"->",
"format",
"(",
"$",
"columnValue",
",",
"$",
"this",
")",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"dataTable",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"subtable",
"=",
"$",
"row",
"->",
"getSubtable",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"subtable",
")",
")",
"{",
"$",
"this",
"->",
"formatMetrics",
"(",
"$",
"subtable",
",",
"$",
"report",
",",
"$",
"metricsToFormat",
")",
";",
"}",
"}",
"$",
"idSite",
"=",
"DataTableFactory",
"::",
"getSiteIdFromMetadata",
"(",
"$",
"dataTable",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"idSite",
")",
")",
"{",
"// possible when using search in visualization",
"$",
"idSite",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'idSite'",
",",
"0",
",",
"'int'",
")",
";",
"}",
"// @todo for matomo 4, should really use the Metric class to house this kind of logic",
"// format other metrics",
"if",
"(",
"$",
"formatAll",
")",
"{",
"foreach",
"(",
"$",
"dataTable",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"foreach",
"(",
"$",
"row",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"columnValue",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"column",
",",
"'revenue'",
")",
"===",
"false",
"||",
"!",
"is_numeric",
"(",
"$",
"columnValue",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"columnValue",
"!==",
"false",
")",
"{",
"$",
"row",
"->",
"setColumn",
"(",
"$",
"column",
",",
"$",
"this",
"->",
"getPrettyMoney",
"(",
"$",
"columnValue",
",",
"$",
"idSite",
")",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Formats all metrics, including processed metrics, for a DataTable. Metrics to format
are found through report metadata and DataTable metadata.
@param DataTable $dataTable The table to format metrics for.
@param Report|null $report The report the table belongs to.
@param string[]|null $metricsToFormat Whitelist of names of metrics to format.
@param boolean $formatAll If true, will also apply formatting to non-processed metrics like revenue.
This parameter is not currently supported and subject to change.
@api | [
"Formats",
"all",
"metrics",
"including",
"processed",
"metrics",
"for",
"a",
"DataTable",
".",
"Metrics",
"to",
"format",
"are",
"found",
"through",
"report",
"metadata",
"and",
"DataTable",
"metadata",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Metrics/Formatter.php#L208-L270 |
209,890 | matomo-org/matomo | plugins/UserCountry/GeoIPAutoUpdater.php | GeoIPAutoUpdater.setUpdaterOptionsFromUrl | public static function setUpdaterOptionsFromUrl()
{
$options = array(
'loc' => Common::getRequestVar('loc_db', false, 'string'),
'isp' => Common::getRequestVar('isp_db', false, 'string'),
'org' => Common::getRequestVar('org_db', false, 'string'),
'period' => Common::getRequestVar('period', false, 'string'),
);
foreach (self::$urlOptions as $optionKey => $optionName) {
$options[$optionKey] = Common::unsanitizeInputValue($options[$optionKey]); // URLs should not be sanitized
}
self::setUpdaterOptions($options);
} | php | public static function setUpdaterOptionsFromUrl()
{
$options = array(
'loc' => Common::getRequestVar('loc_db', false, 'string'),
'isp' => Common::getRequestVar('isp_db', false, 'string'),
'org' => Common::getRequestVar('org_db', false, 'string'),
'period' => Common::getRequestVar('period', false, 'string'),
);
foreach (self::$urlOptions as $optionKey => $optionName) {
$options[$optionKey] = Common::unsanitizeInputValue($options[$optionKey]); // URLs should not be sanitized
}
self::setUpdaterOptions($options);
} | [
"public",
"static",
"function",
"setUpdaterOptionsFromUrl",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'loc'",
"=>",
"Common",
"::",
"getRequestVar",
"(",
"'loc_db'",
",",
"false",
",",
"'string'",
")",
",",
"'isp'",
"=>",
"Common",
"::",
"getRequestVar",
"(",
"'isp_db'",
",",
"false",
",",
"'string'",
")",
",",
"'org'",
"=>",
"Common",
"::",
"getRequestVar",
"(",
"'org_db'",
",",
"false",
",",
"'string'",
")",
",",
"'period'",
"=>",
"Common",
"::",
"getRequestVar",
"(",
"'period'",
",",
"false",
",",
"'string'",
")",
",",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"urlOptions",
"as",
"$",
"optionKey",
"=>",
"$",
"optionName",
")",
"{",
"$",
"options",
"[",
"$",
"optionKey",
"]",
"=",
"Common",
"::",
"unsanitizeInputValue",
"(",
"$",
"options",
"[",
"$",
"optionKey",
"]",
")",
";",
"// URLs should not be sanitized",
"}",
"self",
"::",
"setUpdaterOptions",
"(",
"$",
"options",
")",
";",
"}"
] | Sets the options used by this class based on query parameter values.
See setUpdaterOptions for query params used. | [
"Sets",
"the",
"options",
"used",
"by",
"this",
"class",
"based",
"on",
"query",
"parameter",
"values",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/GeoIPAutoUpdater.php#L312-L326 |
209,891 | matomo-org/matomo | plugins/UserCountry/GeoIPAutoUpdater.php | GeoIPAutoUpdater.clearOptions | public static function clearOptions()
{
foreach (self::$urlOptions as $optionKey => $optionName) {
Option::delete($optionName);
}
Option::delete(self::SCHEDULE_PERIOD_OPTION_NAME);
} | php | public static function clearOptions()
{
foreach (self::$urlOptions as $optionKey => $optionName) {
Option::delete($optionName);
}
Option::delete(self::SCHEDULE_PERIOD_OPTION_NAME);
} | [
"public",
"static",
"function",
"clearOptions",
"(",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"urlOptions",
"as",
"$",
"optionKey",
"=>",
"$",
"optionName",
")",
"{",
"Option",
"::",
"delete",
"(",
"$",
"optionName",
")",
";",
"}",
"Option",
"::",
"delete",
"(",
"self",
"::",
"SCHEDULE_PERIOD_OPTION_NAME",
")",
";",
"}"
] | Removes all options to disable any configured automatic updates | [
"Removes",
"all",
"options",
"to",
"disable",
"any",
"configured",
"automatic",
"updates"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/GeoIPAutoUpdater.php#L379-L385 |
209,892 | matomo-org/matomo | plugins/UserCountry/GeoIPAutoUpdater.php | GeoIPAutoUpdater.isUpdaterSetup | public static function isUpdaterSetup()
{
if (Option::get(self::LOC_URL_OPTION_NAME) !== false
|| Option::get(self::ISP_URL_OPTION_NAME) !== false
|| Option::get(self::ORG_URL_OPTION_NAME) !== false
) {
return true;
}
return false;
} | php | public static function isUpdaterSetup()
{
if (Option::get(self::LOC_URL_OPTION_NAME) !== false
|| Option::get(self::ISP_URL_OPTION_NAME) !== false
|| Option::get(self::ORG_URL_OPTION_NAME) !== false
) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"isUpdaterSetup",
"(",
")",
"{",
"if",
"(",
"Option",
"::",
"get",
"(",
"self",
"::",
"LOC_URL_OPTION_NAME",
")",
"!==",
"false",
"||",
"Option",
"::",
"get",
"(",
"self",
"::",
"ISP_URL_OPTION_NAME",
")",
"!==",
"false",
"||",
"Option",
"::",
"get",
"(",
"self",
"::",
"ORG_URL_OPTION_NAME",
")",
"!==",
"false",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if the auto-updater is setup to update at least one type of
database. False if otherwise.
@return bool | [
"Returns",
"true",
"if",
"the",
"auto",
"-",
"updater",
"is",
"setup",
"to",
"update",
"at",
"least",
"one",
"type",
"of",
"database",
".",
"False",
"if",
"otherwise",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/GeoIPAutoUpdater.php#L393-L403 |
209,893 | matomo-org/matomo | plugins/UserCountry/GeoIPAutoUpdater.php | GeoIPAutoUpdater.getOldAndNewPathsForBrokenDb | private function getOldAndNewPathsForBrokenDb($possibleDbNames)
{
$pathToDb = GeoIp::getPathToGeoIpDatabase($possibleDbNames);
$newPath = false;
if ($pathToDb !== false) {
$newPath = $pathToDb . ".broken";
}
return array($pathToDb, $newPath);
} | php | private function getOldAndNewPathsForBrokenDb($possibleDbNames)
{
$pathToDb = GeoIp::getPathToGeoIpDatabase($possibleDbNames);
$newPath = false;
if ($pathToDb !== false) {
$newPath = $pathToDb . ".broken";
}
return array($pathToDb, $newPath);
} | [
"private",
"function",
"getOldAndNewPathsForBrokenDb",
"(",
"$",
"possibleDbNames",
")",
"{",
"$",
"pathToDb",
"=",
"GeoIp",
"::",
"getPathToGeoIpDatabase",
"(",
"$",
"possibleDbNames",
")",
";",
"$",
"newPath",
"=",
"false",
";",
"if",
"(",
"$",
"pathToDb",
"!==",
"false",
")",
"{",
"$",
"newPath",
"=",
"$",
"pathToDb",
".",
"\".broken\"",
";",
"}",
"return",
"array",
"(",
"$",
"pathToDb",
",",
"$",
"newPath",
")",
";",
"}"
] | Returns the path to a GeoIP database and a path to rename it to if it's broken.
@param array $possibleDbNames The possible names of the database.
@return array Array with two elements, the path to the existing database, and
the path to rename it to if it is broken. The second will end
with something like .broken . | [
"Returns",
"the",
"path",
"to",
"a",
"GeoIP",
"database",
"and",
"a",
"path",
"to",
"rename",
"it",
"to",
"if",
"it",
"s",
"broken",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/GeoIPAutoUpdater.php#L616-L626 |
209,894 | matomo-org/matomo | plugins/UserCountry/GeoIPAutoUpdater.php | GeoIPAutoUpdater.catchGeoIPError | public static function catchGeoIPError($errno, $errstr, $errfile, $errline)
{
self::$unzipPhpError = array($errno, $errstr, $errfile, $errline);
} | php | public static function catchGeoIPError($errno, $errstr, $errfile, $errline)
{
self::$unzipPhpError = array($errno, $errstr, $errfile, $errline);
} | [
"public",
"static",
"function",
"catchGeoIPError",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
"{",
"self",
"::",
"$",
"unzipPhpError",
"=",
"array",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"}"
] | Custom PHP error handler used to catch any PHP errors that occur when
testing a downloaded GeoIP file.
If we download a file that is supposed to be a GeoIP database, we need to make
sure it is one. This is done simply by attempting to use it. If this fails, it
will most of the time fail as a PHP error, which we catch w/ this function
after it is passed to set_error_handler.
The PHP error is stored in self::$unzipPhpError.
@param int $errno
@param string $errstr
@param string $errfile
@param int $errline | [
"Custom",
"PHP",
"error",
"handler",
"used",
"to",
"catch",
"any",
"PHP",
"errors",
"that",
"occur",
"when",
"testing",
"a",
"downloaded",
"GeoIP",
"file",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/GeoIPAutoUpdater.php#L644-L647 |
209,895 | matomo-org/matomo | plugins/UserCountry/VisitorGeolocator.php | VisitorGeolocator.attributeExistingVisit | public function attributeExistingVisit($visit, $useClassCache = true)
{
if (empty($visit['idvisit'])) {
$this->logger->debug('Empty idvisit field. Skipping re-attribution..');
return null;
}
$idVisit = $visit['idvisit'];
if (empty($visit['location_ip'])) {
$this->logger->debug('Empty location_ip field for idvisit = %s. Skipping re-attribution.', array('idvisit' => $idVisit));
return null;
}
$ip = IPUtils::binaryToStringIP($visit['location_ip']);
$location = $this->getLocation(array('ip' => $ip), $useClassCache);
$valuesToUpdate = $this->getVisitFieldsToUpdate($visit, $location);
if (!empty($valuesToUpdate)) {
$this->logger->debug('Updating visit with idvisit = {idVisit} (IP = {ip}). Changes: {changes}', array(
'idVisit' => $idVisit,
'ip' => $ip,
'changes' => json_encode($valuesToUpdate)
));
$this->dao->updateVisits($valuesToUpdate, $idVisit);
$this->dao->updateConversions($valuesToUpdate, $idVisit);
} else {
$this->logger->debug('Nothing to update for idvisit = %s (IP = {ip}). Existing location info is same as geolocated.', array(
'idVisit' => $idVisit,
'ip' => $ip
));
}
return $valuesToUpdate;
} | php | public function attributeExistingVisit($visit, $useClassCache = true)
{
if (empty($visit['idvisit'])) {
$this->logger->debug('Empty idvisit field. Skipping re-attribution..');
return null;
}
$idVisit = $visit['idvisit'];
if (empty($visit['location_ip'])) {
$this->logger->debug('Empty location_ip field for idvisit = %s. Skipping re-attribution.', array('idvisit' => $idVisit));
return null;
}
$ip = IPUtils::binaryToStringIP($visit['location_ip']);
$location = $this->getLocation(array('ip' => $ip), $useClassCache);
$valuesToUpdate = $this->getVisitFieldsToUpdate($visit, $location);
if (!empty($valuesToUpdate)) {
$this->logger->debug('Updating visit with idvisit = {idVisit} (IP = {ip}). Changes: {changes}', array(
'idVisit' => $idVisit,
'ip' => $ip,
'changes' => json_encode($valuesToUpdate)
));
$this->dao->updateVisits($valuesToUpdate, $idVisit);
$this->dao->updateConversions($valuesToUpdate, $idVisit);
} else {
$this->logger->debug('Nothing to update for idvisit = %s (IP = {ip}). Existing location info is same as geolocated.', array(
'idVisit' => $idVisit,
'ip' => $ip
));
}
return $valuesToUpdate;
} | [
"public",
"function",
"attributeExistingVisit",
"(",
"$",
"visit",
",",
"$",
"useClassCache",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"visit",
"[",
"'idvisit'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Empty idvisit field. Skipping re-attribution..'",
")",
";",
"return",
"null",
";",
"}",
"$",
"idVisit",
"=",
"$",
"visit",
"[",
"'idvisit'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"visit",
"[",
"'location_ip'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Empty location_ip field for idvisit = %s. Skipping re-attribution.'",
",",
"array",
"(",
"'idvisit'",
"=>",
"$",
"idVisit",
")",
")",
";",
"return",
"null",
";",
"}",
"$",
"ip",
"=",
"IPUtils",
"::",
"binaryToStringIP",
"(",
"$",
"visit",
"[",
"'location_ip'",
"]",
")",
";",
"$",
"location",
"=",
"$",
"this",
"->",
"getLocation",
"(",
"array",
"(",
"'ip'",
"=>",
"$",
"ip",
")",
",",
"$",
"useClassCache",
")",
";",
"$",
"valuesToUpdate",
"=",
"$",
"this",
"->",
"getVisitFieldsToUpdate",
"(",
"$",
"visit",
",",
"$",
"location",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"valuesToUpdate",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Updating visit with idvisit = {idVisit} (IP = {ip}). Changes: {changes}'",
",",
"array",
"(",
"'idVisit'",
"=>",
"$",
"idVisit",
",",
"'ip'",
"=>",
"$",
"ip",
",",
"'changes'",
"=>",
"json_encode",
"(",
"$",
"valuesToUpdate",
")",
")",
")",
";",
"$",
"this",
"->",
"dao",
"->",
"updateVisits",
"(",
"$",
"valuesToUpdate",
",",
"$",
"idVisit",
")",
";",
"$",
"this",
"->",
"dao",
"->",
"updateConversions",
"(",
"$",
"valuesToUpdate",
",",
"$",
"idVisit",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'Nothing to update for idvisit = %s (IP = {ip}). Existing location info is same as geolocated.'",
",",
"array",
"(",
"'idVisit'",
"=>",
"$",
"idVisit",
",",
"'ip'",
"=>",
"$",
"ip",
")",
")",
";",
"}",
"return",
"$",
"valuesToUpdate",
";",
"}"
] | Geolcates an existing visit and then updates it if it's current attributes are different than
what was geolocated. Also updates all conversions of a visit.
**This method should NOT be used from within the tracker.**
@param array $visit The visit information. Must contain an `"idvisit"` element and `"location_ip"` element.
@param bool $useClassCache
@return array|null The visit properties that were updated in the DB mapped to the updated values. If null,
required information was missing from `$visit`. | [
"Geolcates",
"an",
"existing",
"visit",
"and",
"then",
"updates",
"it",
"if",
"it",
"s",
"current",
"attributes",
"are",
"different",
"than",
"what",
"was",
"geolocated",
".",
"Also",
"updates",
"all",
"conversions",
"of",
"a",
"visit",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/VisitorGeolocator.php#L169-L205 |
209,896 | matomo-org/matomo | plugins/UserCountry/VisitorGeolocator.php | VisitorGeolocator.getVisitFieldsToUpdate | private function getVisitFieldsToUpdate(array $row, $location)
{
if (isset($location[LocationProvider::COUNTRY_CODE_KEY])) {
$location[LocationProvider::COUNTRY_CODE_KEY] = strtolower($location[LocationProvider::COUNTRY_CODE_KEY]);
}
$valuesToUpdate = array();
foreach (self::$logVisitFieldsToUpdate as $column => $locationKey) {
if (empty($location[$locationKey])) {
continue;
}
$locationPropertyValue = $location[$locationKey];
$existingPropertyValue = $row[$column];
if (!$this->areLocationPropertiesEqual($locationKey, $locationPropertyValue, $existingPropertyValue)) {
$valuesToUpdate[$column] = $locationPropertyValue;
}
}
return $valuesToUpdate;
} | php | private function getVisitFieldsToUpdate(array $row, $location)
{
if (isset($location[LocationProvider::COUNTRY_CODE_KEY])) {
$location[LocationProvider::COUNTRY_CODE_KEY] = strtolower($location[LocationProvider::COUNTRY_CODE_KEY]);
}
$valuesToUpdate = array();
foreach (self::$logVisitFieldsToUpdate as $column => $locationKey) {
if (empty($location[$locationKey])) {
continue;
}
$locationPropertyValue = $location[$locationKey];
$existingPropertyValue = $row[$column];
if (!$this->areLocationPropertiesEqual($locationKey, $locationPropertyValue, $existingPropertyValue)) {
$valuesToUpdate[$column] = $locationPropertyValue;
}
}
return $valuesToUpdate;
} | [
"private",
"function",
"getVisitFieldsToUpdate",
"(",
"array",
"$",
"row",
",",
"$",
"location",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"location",
"[",
"LocationProvider",
"::",
"COUNTRY_CODE_KEY",
"]",
")",
")",
"{",
"$",
"location",
"[",
"LocationProvider",
"::",
"COUNTRY_CODE_KEY",
"]",
"=",
"strtolower",
"(",
"$",
"location",
"[",
"LocationProvider",
"::",
"COUNTRY_CODE_KEY",
"]",
")",
";",
"}",
"$",
"valuesToUpdate",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"logVisitFieldsToUpdate",
"as",
"$",
"column",
"=>",
"$",
"locationKey",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"location",
"[",
"$",
"locationKey",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"locationPropertyValue",
"=",
"$",
"location",
"[",
"$",
"locationKey",
"]",
";",
"$",
"existingPropertyValue",
"=",
"$",
"row",
"[",
"$",
"column",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"areLocationPropertiesEqual",
"(",
"$",
"locationKey",
",",
"$",
"locationPropertyValue",
",",
"$",
"existingPropertyValue",
")",
")",
"{",
"$",
"valuesToUpdate",
"[",
"$",
"column",
"]",
"=",
"$",
"locationPropertyValue",
";",
"}",
"}",
"return",
"$",
"valuesToUpdate",
";",
"}"
] | Returns location log values that are different than the values currently in a log row.
@param array $row The visit row.
@param array $location The location information.
@return array The location properties to update. | [
"Returns",
"location",
"log",
"values",
"that",
"are",
"different",
"than",
"the",
"values",
"currently",
"in",
"a",
"log",
"row",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/VisitorGeolocator.php#L214-L234 |
209,897 | matomo-org/matomo | core/DataTable/BaseFilter.php | BaseFilter.filterSubTable | public function filterSubTable(Row $row)
{
if (!$this->enableRecursive) {
return;
}
$subTable = $row->getSubtable();
if ($subTable) {
$this->filter($subTable);
}
} | php | public function filterSubTable(Row $row)
{
if (!$this->enableRecursive) {
return;
}
$subTable = $row->getSubtable();
if ($subTable) {
$this->filter($subTable);
}
} | [
"public",
"function",
"filterSubTable",
"(",
"Row",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enableRecursive",
")",
"{",
"return",
";",
"}",
"$",
"subTable",
"=",
"$",
"row",
"->",
"getSubtable",
"(",
")",
";",
"if",
"(",
"$",
"subTable",
")",
"{",
"$",
"this",
"->",
"filter",
"(",
"$",
"subTable",
")",
";",
"}",
"}"
] | Filters a row's subtable, if one exists and is loaded in memory.
@param Row $row The row whose subtable should be filter. | [
"Filters",
"a",
"row",
"s",
"subtable",
"if",
"one",
"exists",
"and",
"is",
"loaded",
"in",
"memory",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/BaseFilter.php#L70-L79 |
209,898 | matomo-org/matomo | core/Application/Environment.php | Environment.init | public function init()
{
$this->invokeBeforeContainerCreatedHook();
$this->container = $this->createContainer();
StaticContainer::push($this->container);
$this->validateEnvironment();
$this->invokeEnvironmentBootstrappedHook();
Piwik::postEvent('Environment.bootstrapped'); // this event should be removed eventually
} | php | public function init()
{
$this->invokeBeforeContainerCreatedHook();
$this->container = $this->createContainer();
StaticContainer::push($this->container);
$this->validateEnvironment();
$this->invokeEnvironmentBootstrappedHook();
Piwik::postEvent('Environment.bootstrapped'); // this event should be removed eventually
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"invokeBeforeContainerCreatedHook",
"(",
")",
";",
"$",
"this",
"->",
"container",
"=",
"$",
"this",
"->",
"createContainer",
"(",
")",
";",
"StaticContainer",
"::",
"push",
"(",
"$",
"this",
"->",
"container",
")",
";",
"$",
"this",
"->",
"validateEnvironment",
"(",
")",
";",
"$",
"this",
"->",
"invokeEnvironmentBootstrappedHook",
"(",
")",
";",
"Piwik",
"::",
"postEvent",
"(",
"'Environment.bootstrapped'",
")",
";",
"// this event should be removed eventually",
"}"
] | Initializes the kernel globals and DI container. | [
"Initializes",
"the",
"kernel",
"globals",
"and",
"DI",
"container",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Application/Environment.php#L86-L99 |
209,899 | matomo-org/matomo | core/NumberFormatter.php | NumberFormatter.formatNumber | public function formatNumber($value, $maximumFractionDigits=0, $minimumFractionDigits=0)
{
$pattern = $this->getPattern($value, 'Intl_NumberFormatNumber');
return $this->formatNumberWithPattern($pattern, $value, $maximumFractionDigits, $minimumFractionDigits);
} | php | public function formatNumber($value, $maximumFractionDigits=0, $minimumFractionDigits=0)
{
$pattern = $this->getPattern($value, 'Intl_NumberFormatNumber');
return $this->formatNumberWithPattern($pattern, $value, $maximumFractionDigits, $minimumFractionDigits);
} | [
"public",
"function",
"formatNumber",
"(",
"$",
"value",
",",
"$",
"maximumFractionDigits",
"=",
"0",
",",
"$",
"minimumFractionDigits",
"=",
"0",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"getPattern",
"(",
"$",
"value",
",",
"'Intl_NumberFormatNumber'",
")",
";",
"return",
"$",
"this",
"->",
"formatNumberWithPattern",
"(",
"$",
"pattern",
",",
"$",
"value",
",",
"$",
"maximumFractionDigits",
",",
"$",
"minimumFractionDigits",
")",
";",
"}"
] | Formats a given number
@see \Piwik\NumberFormatter::format()
@param string|int|float $value
@param int $maximumFractionDigits
@param int $minimumFractionDigits
@return mixed|string | [
"Formats",
"a",
"given",
"number"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/NumberFormatter.php#L73-L78 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.