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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
210,000 | matomo-org/matomo | core/Access.php | Access.getSqlAccessSite | public static function getSqlAccessSite($select)
{
$access = Common::prefixTable('access');
$siteTable = Common::prefixTable('site');
return "SELECT " . $select . " FROM " . $access . " as t1
JOIN " . $siteTable . " as t2 USING (idsite) WHERE login = ?";
} | php | public static function getSqlAccessSite($select)
{
$access = Common::prefixTable('access');
$siteTable = Common::prefixTable('site');
return "SELECT " . $select . " FROM " . $access . " as t1
JOIN " . $siteTable . " as t2 USING (idsite) WHERE login = ?";
} | [
"public",
"static",
"function",
"getSqlAccessSite",
"(",
"$",
"select",
")",
"{",
"$",
"access",
"=",
"Common",
"::",
"prefixTable",
"(",
"'access'",
")",
";",
"$",
"siteTable",
"=",
"Common",
"::",
"prefixTable",
"(",
"'site'",
")",
";",
"return",
"\"SELECT \"",
".",
"$",
"select",
".",
"\" FROM \"",
".",
"$",
"access",
".",
"\" as t1\n\t\t\t\tJOIN \"",
".",
"$",
"siteTable",
".",
"\" as t2 USING (idsite) WHERE login = ?\"",
";",
"}"
] | Returns the SQL query joining sites and access table for a given login
@param string $select Columns or expression to SELECT FROM table, eg. "MIN(ts_created)"
@return string SQL query | [
"Returns",
"the",
"SQL",
"query",
"joining",
"sites",
"and",
"access",
"table",
"for",
"a",
"given",
"login"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L187-L194 |
210,001 | matomo-org/matomo | core/Access.php | Access.setSuperUserAccess | public function setSuperUserAccess($bool = true)
{
$this->hasSuperUserAccess = (bool) $bool;
if ($bool) {
$this->makeSureLoginNameIsSet();
} else {
$this->resetSites();
}
} | php | public function setSuperUserAccess($bool = true)
{
$this->hasSuperUserAccess = (bool) $bool;
if ($bool) {
$this->makeSureLoginNameIsSet();
} else {
$this->resetSites();
}
} | [
"public",
"function",
"setSuperUserAccess",
"(",
"$",
"bool",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"hasSuperUserAccess",
"=",
"(",
"bool",
")",
"$",
"bool",
";",
"if",
"(",
"$",
"bool",
")",
"{",
"$",
"this",
"->",
"makeSureLoginNameIsSet",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"resetSites",
"(",
")",
";",
"}",
"}"
] | We bypass the normal auth method and give the current user Super User rights.
This should be very carefully used.
@param bool $bool | [
"We",
"bypass",
"the",
"normal",
"auth",
"method",
"and",
"give",
"the",
"current",
"user",
"Super",
"User",
"rights",
".",
"This",
"should",
"be",
"very",
"carefully",
"used",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L285-L294 |
210,002 | matomo-org/matomo | core/Access.php | Access.getSitesIdWithAtLeastViewAccess | public function getSitesIdWithAtLeastViewAccess()
{
$this->loadSitesIfNeeded();
return array_unique(array_merge(
$this->idsitesByAccess['view'],
$this->idsitesByAccess['write'],
$this->idsitesByAccess['admin'],
$this->idsitesByAccess['superuser'])
);
} | php | public function getSitesIdWithAtLeastViewAccess()
{
$this->loadSitesIfNeeded();
return array_unique(array_merge(
$this->idsitesByAccess['view'],
$this->idsitesByAccess['write'],
$this->idsitesByAccess['admin'],
$this->idsitesByAccess['superuser'])
);
} | [
"public",
"function",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
"{",
"$",
"this",
"->",
"loadSitesIfNeeded",
"(",
")",
";",
"return",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"'view'",
"]",
",",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"'write'",
"]",
",",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"'admin'",
"]",
",",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"'superuser'",
"]",
")",
")",
";",
"}"
] | Returns an array of ID sites for which the user has at least a VIEW access.
Which means VIEW OR WRITE or ADMIN or SUPERUSER.
@return array Example if the user is ADMIN for 4
and has VIEW access for 1 and 7, it returns array(1, 4, 7); | [
"Returns",
"an",
"array",
"of",
"ID",
"sites",
"for",
"which",
"the",
"user",
"has",
"at",
"least",
"a",
"VIEW",
"access",
".",
"Which",
"means",
"VIEW",
"OR",
"WRITE",
"or",
"ADMIN",
"or",
"SUPERUSER",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L333-L343 |
210,003 | matomo-org/matomo | core/Access.php | Access.getSitesIdWithAtLeastWriteAccess | public function getSitesIdWithAtLeastWriteAccess()
{
$this->loadSitesIfNeeded();
return array_unique(array_merge(
$this->idsitesByAccess['write'],
$this->idsitesByAccess['admin'],
$this->idsitesByAccess['superuser'])
);
} | php | public function getSitesIdWithAtLeastWriteAccess()
{
$this->loadSitesIfNeeded();
return array_unique(array_merge(
$this->idsitesByAccess['write'],
$this->idsitesByAccess['admin'],
$this->idsitesByAccess['superuser'])
);
} | [
"public",
"function",
"getSitesIdWithAtLeastWriteAccess",
"(",
")",
"{",
"$",
"this",
"->",
"loadSitesIfNeeded",
"(",
")",
";",
"return",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"'write'",
"]",
",",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"'admin'",
"]",
",",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"'superuser'",
"]",
")",
")",
";",
"}"
] | Returns an array of ID sites for which the user has at least a WRITE access.
Which means WRITE or ADMIN or SUPERUSER.
@return array Example if the user is WRITE for 4 and 8
and has VIEW access for 1 and 7, it returns array(4, 8); | [
"Returns",
"an",
"array",
"of",
"ID",
"sites",
"for",
"which",
"the",
"user",
"has",
"at",
"least",
"a",
"WRITE",
"access",
".",
"Which",
"means",
"WRITE",
"or",
"ADMIN",
"or",
"SUPERUSER",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L352-L361 |
210,004 | matomo-org/matomo | core/Access.php | Access.checkUserHasSomeViewAccess | public function checkUserHasSomeViewAccess()
{
if ($this->hasSuperUserAccess()) {
return;
}
$idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess();
if (count($idSitesAccessible) == 0) {
throw new NoAccessException(Piwik::translate('General_ExceptionPrivilegeAtLeastOneWebsite', array('view')));
}
} | php | public function checkUserHasSomeViewAccess()
{
if ($this->hasSuperUserAccess()) {
return;
}
$idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess();
if (count($idSitesAccessible) == 0) {
throw new NoAccessException(Piwik::translate('General_ExceptionPrivilegeAtLeastOneWebsite', array('view')));
}
} | [
"public",
"function",
"checkUserHasSomeViewAccess",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasSuperUserAccess",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"idSitesAccessible",
"=",
"$",
"this",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"idSitesAccessible",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"NoAccessException",
"(",
"Piwik",
"::",
"translate",
"(",
"'General_ExceptionPrivilegeAtLeastOneWebsite'",
",",
"array",
"(",
"'view'",
")",
")",
")",
";",
"}",
"}"
] | If the user doesn't have any view permission, throw exception
@throws \Piwik\NoAccessException | [
"If",
"the",
"user",
"doesn",
"t",
"have",
"any",
"view",
"permission",
"throw",
"exception"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L480-L491 |
210,005 | matomo-org/matomo | core/Access.php | Access.checkUserHasAdminAccess | public function checkUserHasAdminAccess($idSites)
{
if ($this->hasSuperUserAccess()) {
return;
}
$idSites = $this->getIdSites($idSites);
$idSitesAccessible = $this->getSitesIdWithAdminAccess();
foreach ($idSites as $idsite) {
if (!in_array($idsite, $idSitesAccessible)) {
throw new NoAccessException(Piwik::translate('General_ExceptionPrivilegeAccessWebsite', array("'admin'", $idsite)));
}
}
} | php | public function checkUserHasAdminAccess($idSites)
{
if ($this->hasSuperUserAccess()) {
return;
}
$idSites = $this->getIdSites($idSites);
$idSitesAccessible = $this->getSitesIdWithAdminAccess();
foreach ($idSites as $idsite) {
if (!in_array($idsite, $idSitesAccessible)) {
throw new NoAccessException(Piwik::translate('General_ExceptionPrivilegeAccessWebsite', array("'admin'", $idsite)));
}
}
} | [
"public",
"function",
"checkUserHasAdminAccess",
"(",
"$",
"idSites",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasSuperUserAccess",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"idSites",
"=",
"$",
"this",
"->",
"getIdSites",
"(",
"$",
"idSites",
")",
";",
"$",
"idSitesAccessible",
"=",
"$",
"this",
"->",
"getSitesIdWithAdminAccess",
"(",
")",
";",
"foreach",
"(",
"$",
"idSites",
"as",
"$",
"idsite",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"idsite",
",",
"$",
"idSitesAccessible",
")",
")",
"{",
"throw",
"new",
"NoAccessException",
"(",
"Piwik",
"::",
"translate",
"(",
"'General_ExceptionPrivilegeAccessWebsite'",
",",
"array",
"(",
"\"'admin'\"",
",",
"$",
"idsite",
")",
")",
")",
";",
"}",
"}",
"}"
] | This method checks that the user has ADMIN access for the given list of websites.
If the user doesn't have ADMIN access for at least one website of the list, we throw an exception.
@param int|array $idSites List of ID sites to check
@throws \Piwik\NoAccessException If for any of the websites the user doesn't have an ADMIN access | [
"This",
"method",
"checks",
"that",
"the",
"user",
"has",
"ADMIN",
"access",
"for",
"the",
"given",
"list",
"of",
"websites",
".",
"If",
"the",
"user",
"doesn",
"t",
"have",
"ADMIN",
"access",
"for",
"at",
"least",
"one",
"website",
"of",
"the",
"list",
"we",
"throw",
"an",
"exception",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L500-L514 |
210,006 | matomo-org/matomo | core/Access.php | Access.doAsSuperUser | public static function doAsSuperUser($function)
{
$isSuperUser = self::getInstance()->hasSuperUserAccess();
$access = self::getInstance();
$login = $access->getLogin();
$shouldResetLogin = empty($login); // make sure to reset login if a login was set by "makeSureLoginNameIsSet()"
$access->setSuperUserAccess(true);
try {
$result = $function();
} catch (Exception $ex) {
$access->setSuperUserAccess($isSuperUser);
if ($shouldResetLogin) {
$access->login = null;
}
throw $ex;
}
if ($shouldResetLogin) {
$access->login = null;
}
$access->setSuperUserAccess($isSuperUser);
return $result;
} | php | public static function doAsSuperUser($function)
{
$isSuperUser = self::getInstance()->hasSuperUserAccess();
$access = self::getInstance();
$login = $access->getLogin();
$shouldResetLogin = empty($login); // make sure to reset login if a login was set by "makeSureLoginNameIsSet()"
$access->setSuperUserAccess(true);
try {
$result = $function();
} catch (Exception $ex) {
$access->setSuperUserAccess($isSuperUser);
if ($shouldResetLogin) {
$access->login = null;
}
throw $ex;
}
if ($shouldResetLogin) {
$access->login = null;
}
$access->setSuperUserAccess($isSuperUser);
return $result;
} | [
"public",
"static",
"function",
"doAsSuperUser",
"(",
"$",
"function",
")",
"{",
"$",
"isSuperUser",
"=",
"self",
"::",
"getInstance",
"(",
")",
"->",
"hasSuperUserAccess",
"(",
")",
";",
"$",
"access",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"login",
"=",
"$",
"access",
"->",
"getLogin",
"(",
")",
";",
"$",
"shouldResetLogin",
"=",
"empty",
"(",
"$",
"login",
")",
";",
"// make sure to reset login if a login was set by \"makeSureLoginNameIsSet()\"",
"$",
"access",
"->",
"setSuperUserAccess",
"(",
"true",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"function",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"access",
"->",
"setSuperUserAccess",
"(",
"$",
"isSuperUser",
")",
";",
"if",
"(",
"$",
"shouldResetLogin",
")",
"{",
"$",
"access",
"->",
"login",
"=",
"null",
";",
"}",
"throw",
"$",
"ex",
";",
"}",
"if",
"(",
"$",
"shouldResetLogin",
")",
"{",
"$",
"access",
"->",
"login",
"=",
"null",
";",
"}",
"$",
"access",
"->",
"setSuperUserAccess",
"(",
"$",
"isSuperUser",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Executes a callback with superuser privileges, making sure those privileges are rescinded
before this method exits. Privileges will be rescinded even if an exception is thrown.
@param callback $function The callback to execute. Should accept no arguments.
@return mixed The result of `$function`.
@throws Exception rethrows any exceptions thrown by `$function`.
@api | [
"Executes",
"a",
"callback",
"with",
"superuser",
"privileges",
"making",
"sure",
"those",
"privileges",
"are",
"rescinded",
"before",
"this",
"method",
"exits",
".",
"Privileges",
"will",
"be",
"rescinded",
"even",
"if",
"an",
"exception",
"is",
"thrown",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L618-L644 |
210,007 | matomo-org/matomo | core/Access.php | Access.getRoleForSite | public function getRoleForSite($idSite)
{
if ($this->hasSuperUserAccess
|| in_array($idSite, $this->getSitesIdWithAdminAccess())
) {
return 'admin';
}
if (in_array($idSite, $this->getSitesIdWithWriteAccess())) {
return 'write';
}
if (in_array($idSite, $this->getSitesIdWithViewAccess())) {
return 'view';
}
return 'noaccess';
} | php | public function getRoleForSite($idSite)
{
if ($this->hasSuperUserAccess
|| in_array($idSite, $this->getSitesIdWithAdminAccess())
) {
return 'admin';
}
if (in_array($idSite, $this->getSitesIdWithWriteAccess())) {
return 'write';
}
if (in_array($idSite, $this->getSitesIdWithViewAccess())) {
return 'view';
}
return 'noaccess';
} | [
"public",
"function",
"getRoleForSite",
"(",
"$",
"idSite",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasSuperUserAccess",
"||",
"in_array",
"(",
"$",
"idSite",
",",
"$",
"this",
"->",
"getSitesIdWithAdminAccess",
"(",
")",
")",
")",
"{",
"return",
"'admin'",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"idSite",
",",
"$",
"this",
"->",
"getSitesIdWithWriteAccess",
"(",
")",
")",
")",
"{",
"return",
"'write'",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"idSite",
",",
"$",
"this",
"->",
"getSitesIdWithViewAccess",
"(",
")",
")",
")",
"{",
"return",
"'view'",
";",
"}",
"return",
"'noaccess'",
";",
"}"
] | Returns the level of access the current user has to the given site.
@param int $idSite The site to check.
@return string The access level, eg, 'view', 'admin', 'noaccess'. | [
"Returns",
"the",
"level",
"of",
"access",
"the",
"current",
"user",
"has",
"to",
"the",
"given",
"site",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L652-L669 |
210,008 | matomo-org/matomo | core/Access.php | Access.getCapabilitiesForSite | public function getCapabilitiesForSite($idSite)
{
$result = [];
foreach ($this->capabilityProvider->getAllCapabilityIds() as $capabilityId) {
if (empty($this->idsitesByAccess[$capabilityId])) {
continue;
}
if (in_array($idSite, $this->idsitesByAccess[$capabilityId])) {
$result[] = $capabilityId;
}
}
return $result;
} | php | public function getCapabilitiesForSite($idSite)
{
$result = [];
foreach ($this->capabilityProvider->getAllCapabilityIds() as $capabilityId) {
if (empty($this->idsitesByAccess[$capabilityId])) {
continue;
}
if (in_array($idSite, $this->idsitesByAccess[$capabilityId])) {
$result[] = $capabilityId;
}
}
return $result;
} | [
"public",
"function",
"getCapabilitiesForSite",
"(",
"$",
"idSite",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"capabilityProvider",
"->",
"getAllCapabilityIds",
"(",
")",
"as",
"$",
"capabilityId",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"$",
"capabilityId",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"idSite",
",",
"$",
"this",
"->",
"idsitesByAccess",
"[",
"$",
"capabilityId",
"]",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"capabilityId",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the capabilities the current user has for a given site.
@param int $idSite The site to check.
@return string[] The capabilities the user has. | [
"Returns",
"the",
"capabilities",
"the",
"current",
"user",
"has",
"for",
"a",
"given",
"site",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Access.php#L677-L690 |
210,009 | matomo-org/matomo | libs/HTML/QuickForm2/Renderer.php | HTML_QuickForm2_Renderer.factory | final public static function factory($type)
{
$type = strtolower($type);
if (!isset(self::$_types[$type])) {
throw new HTML_QuickForm2_InvalidArgumentException(
"Renderer type '$type' is not known"
);
}
list ($className, $includeFile) = self::$_types[$type];
if (!class_exists($className)) {
HTML_QuickForm2_Loader::loadClass($className, $includeFile);
}
if (!class_exists('HTML_QuickForm2_Renderer_Proxy')) {
HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_Renderer_Proxy');
}
return new HTML_QuickForm2_Renderer_Proxy(new $className, self::$_pluginClasses[$type]);
} | php | final public static function factory($type)
{
$type = strtolower($type);
if (!isset(self::$_types[$type])) {
throw new HTML_QuickForm2_InvalidArgumentException(
"Renderer type '$type' is not known"
);
}
list ($className, $includeFile) = self::$_types[$type];
if (!class_exists($className)) {
HTML_QuickForm2_Loader::loadClass($className, $includeFile);
}
if (!class_exists('HTML_QuickForm2_Renderer_Proxy')) {
HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_Renderer_Proxy');
}
return new HTML_QuickForm2_Renderer_Proxy(new $className, self::$_pluginClasses[$type]);
} | [
"final",
"public",
"static",
"function",
"factory",
"(",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_types",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"HTML_QuickForm2_InvalidArgumentException",
"(",
"\"Renderer type '$type' is not known\"",
")",
";",
"}",
"list",
"(",
"$",
"className",
",",
"$",
"includeFile",
")",
"=",
"self",
"::",
"$",
"_types",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"HTML_QuickForm2_Loader",
"::",
"loadClass",
"(",
"$",
"className",
",",
"$",
"includeFile",
")",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"'HTML_QuickForm2_Renderer_Proxy'",
")",
")",
"{",
"HTML_QuickForm2_Loader",
"::",
"loadClass",
"(",
"'HTML_QuickForm2_Renderer_Proxy'",
")",
";",
"}",
"return",
"new",
"HTML_QuickForm2_Renderer_Proxy",
"(",
"new",
"$",
"className",
",",
"self",
"::",
"$",
"_pluginClasses",
"[",
"$",
"type",
"]",
")",
";",
"}"
] | Creates a new renderer instance of the given type
A renderer is always wrapped by a Proxy, which handles calling its
"published" methods and methods of its plugins. Registered plugins are
added automagically to the existing renderer instances so that
<code>
$foo = HTML_QuickForm2_Renderer::factory('foo');
// Plugin implementing bar() method
HTML_QuickForm2_Renderer::registerPlugin('foo', 'Plugin_Foo_Bar');
$foo->bar();
</code>
will work.
@param string Type name (treated case-insensitively)
@return HTML_QuickForm2_Renderer_Proxy A renderer instance of the given
type wrapped by a Proxy
@throws HTML_QuickForm2_InvalidArgumentException If type name is unknown
@throws HTML_QuickForm2_NotFoundException If class for the renderer can
not be found and/or loaded from file | [
"Creates",
"a",
"new",
"renderer",
"instance",
"of",
"the",
"given",
"type"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Renderer.php#L131-L148 |
210,010 | matomo-org/matomo | libs/HTML/QuickForm2/Renderer.php | HTML_QuickForm2_Renderer.register | final public static function register($type, $className, $includeFile = null)
{
$type = strtolower($type);
if (!empty(self::$_types[$type])) {
throw new HTML_QuickForm2_InvalidArgumentException(
"Renderer type '$type' is already registered"
);
}
self::$_types[$type] = array($className, $includeFile);
if (empty(self::$_pluginClasses[$type])) {
self::$_pluginClasses[$type] = array();
}
} | php | final public static function register($type, $className, $includeFile = null)
{
$type = strtolower($type);
if (!empty(self::$_types[$type])) {
throw new HTML_QuickForm2_InvalidArgumentException(
"Renderer type '$type' is already registered"
);
}
self::$_types[$type] = array($className, $includeFile);
if (empty(self::$_pluginClasses[$type])) {
self::$_pluginClasses[$type] = array();
}
} | [
"final",
"public",
"static",
"function",
"register",
"(",
"$",
"type",
",",
"$",
"className",
",",
"$",
"includeFile",
"=",
"null",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"$",
"_types",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"HTML_QuickForm2_InvalidArgumentException",
"(",
"\"Renderer type '$type' is already registered\"",
")",
";",
"}",
"self",
"::",
"$",
"_types",
"[",
"$",
"type",
"]",
"=",
"array",
"(",
"$",
"className",
",",
"$",
"includeFile",
")",
";",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_pluginClasses",
"[",
"$",
"type",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_pluginClasses",
"[",
"$",
"type",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}"
] | Registers a new renderer type
@param string Type name (treated case-insensitively)
@param string Class name
@param string File containing the class, leave empty if class already loaded
@throws HTML_QuickForm2_InvalidArgumentException if type already registered | [
"Registers",
"a",
"new",
"renderer",
"type"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Renderer.php#L158-L170 |
210,011 | matomo-org/matomo | libs/HTML/QuickForm2/Renderer.php | HTML_QuickForm2_Renderer.registerPlugin | final public static function registerPlugin($type, $className, $includeFile = null)
{
$type = strtolower($type);
// We don't check self::$_types, since a plugin may be registered
// before renderer itself if it goes with some custom element
if (empty(self::$_pluginClasses[$type])) {
self::$_pluginClasses[$type] = array(array($className, $includeFile));
} else {
foreach (self::$_pluginClasses[$type] as $plugin) {
if (0 == strcasecmp($plugin[0], $className)) {
throw new HTML_QuickForm2_InvalidArgumentException(
"Plugin '$className' for renderer type '$type' is already registered"
);
}
}
self::$_pluginClasses[$type][] = array($className, $includeFile);
}
} | php | final public static function registerPlugin($type, $className, $includeFile = null)
{
$type = strtolower($type);
// We don't check self::$_types, since a plugin may be registered
// before renderer itself if it goes with some custom element
if (empty(self::$_pluginClasses[$type])) {
self::$_pluginClasses[$type] = array(array($className, $includeFile));
} else {
foreach (self::$_pluginClasses[$type] as $plugin) {
if (0 == strcasecmp($plugin[0], $className)) {
throw new HTML_QuickForm2_InvalidArgumentException(
"Plugin '$className' for renderer type '$type' is already registered"
);
}
}
self::$_pluginClasses[$type][] = array($className, $includeFile);
}
} | [
"final",
"public",
"static",
"function",
"registerPlugin",
"(",
"$",
"type",
",",
"$",
"className",
",",
"$",
"includeFile",
"=",
"null",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"// We don't check self::$_types, since a plugin may be registered",
"// before renderer itself if it goes with some custom element",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_pluginClasses",
"[",
"$",
"type",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_pluginClasses",
"[",
"$",
"type",
"]",
"=",
"array",
"(",
"array",
"(",
"$",
"className",
",",
"$",
"includeFile",
")",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"self",
"::",
"$",
"_pluginClasses",
"[",
"$",
"type",
"]",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"0",
"==",
"strcasecmp",
"(",
"$",
"plugin",
"[",
"0",
"]",
",",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"HTML_QuickForm2_InvalidArgumentException",
"(",
"\"Plugin '$className' for renderer type '$type' is already registered\"",
")",
";",
"}",
"}",
"self",
"::",
"$",
"_pluginClasses",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"array",
"(",
"$",
"className",
",",
"$",
"includeFile",
")",
";",
"}",
"}"
] | Registers a plugin for a renderer type
@param string Renderer type name (treated case-insensitively)
@param string Plugin class name
@param string File containing the plugin class, leave empty if class already loaded
@throws HTML_QuickForm2_InvalidArgumentException if plugin is already registered | [
"Registers",
"a",
"plugin",
"for",
"a",
"renderer",
"type"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Renderer.php#L180-L197 |
210,012 | matomo-org/matomo | libs/HTML/QuickForm2/Renderer.php | HTML_QuickForm2_Renderer.getJavascriptBuilder | public function getJavascriptBuilder()
{
if (empty($this->jsBuilder)) {
if (!class_exists('HTML_QuickForm2_JavascriptBuilder')) {
HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_JavascriptBuilder');
}
$this->jsBuilder = new HTML_QuickForm2_JavascriptBuilder();
}
return $this->jsBuilder;
} | php | public function getJavascriptBuilder()
{
if (empty($this->jsBuilder)) {
if (!class_exists('HTML_QuickForm2_JavascriptBuilder')) {
HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_JavascriptBuilder');
}
$this->jsBuilder = new HTML_QuickForm2_JavascriptBuilder();
}
return $this->jsBuilder;
} | [
"public",
"function",
"getJavascriptBuilder",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"jsBuilder",
")",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'HTML_QuickForm2_JavascriptBuilder'",
")",
")",
"{",
"HTML_QuickForm2_Loader",
"::",
"loadClass",
"(",
"'HTML_QuickForm2_JavascriptBuilder'",
")",
";",
"}",
"$",
"this",
"->",
"jsBuilder",
"=",
"new",
"HTML_QuickForm2_JavascriptBuilder",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"jsBuilder",
";",
"}"
] | Returns the javascript builder object
@return HTML_QuickForm2_JavascriptBuilder | [
"Returns",
"the",
"javascript",
"builder",
"object"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Renderer.php#L285-L294 |
210,013 | matomo-org/matomo | libs/Zend/Session/SaveHandler/DbTable.php | Zend_Session_SaveHandler_DbTable._setup | protected function _setup()
{
parent::_setup();
$this->_setupPrimaryAssignment();
$this->setLifetime($this->_lifetime);
$this->_checkRequiredColumns();
} | php | protected function _setup()
{
parent::_setup();
$this->_setupPrimaryAssignment();
$this->setLifetime($this->_lifetime);
$this->_checkRequiredColumns();
} | [
"protected",
"function",
"_setup",
"(",
")",
"{",
"parent",
"::",
"_setup",
"(",
")",
";",
"$",
"this",
"->",
"_setupPrimaryAssignment",
"(",
")",
";",
"$",
"this",
"->",
"setLifetime",
"(",
"$",
"this",
"->",
"_lifetime",
")",
";",
"$",
"this",
"->",
"_checkRequiredColumns",
"(",
")",
";",
"}"
] | Calls other protected methods for individual setup tasks and requirement checks
@return void | [
"Calls",
"other",
"protected",
"methods",
"for",
"individual",
"setup",
"tasks",
"and",
"requirement",
"checks"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Session/SaveHandler/DbTable.php#L401-L409 |
210,014 | matomo-org/matomo | libs/Zend/Session/SaveHandler/DbTable.php | Zend_Session_SaveHandler_DbTable._setupTableName | protected function _setupTableName()
{
if (empty($this->_name) && basename(($this->_name = session_save_path())) != $this->_name) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception('session.save_path is a path and not a table name.');
}
if (strpos($this->_name, '.')) {
list($this->_schema, $this->_name) = explode('.', $this->_name);
}
} | php | protected function _setupTableName()
{
if (empty($this->_name) && basename(($this->_name = session_save_path())) != $this->_name) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception('session.save_path is a path and not a table name.');
}
if (strpos($this->_name, '.')) {
list($this->_schema, $this->_name) = explode('.', $this->_name);
}
} | [
"protected",
"function",
"_setupTableName",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_name",
")",
"&&",
"basename",
"(",
"(",
"$",
"this",
"->",
"_name",
"=",
"session_save_path",
"(",
")",
")",
")",
"!=",
"$",
"this",
"->",
"_name",
")",
"{",
"/**\n * @see Zend_Session_SaveHandler_Exception\n */",
"// require_once 'Zend/Session/SaveHandler/Exception.php';",
"throw",
"new",
"Zend_Session_SaveHandler_Exception",
"(",
"'session.save_path is a path and not a table name.'",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"_name",
",",
"'.'",
")",
")",
"{",
"list",
"(",
"$",
"this",
"->",
"_schema",
",",
"$",
"this",
"->",
"_name",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"this",
"->",
"_name",
")",
";",
"}",
"}"
] | Initialize table and schema names
@return void
@throws Zend_Session_SaveHandler_Exception | [
"Initialize",
"table",
"and",
"schema",
"names"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Session/SaveHandler/DbTable.php#L417-L431 |
210,015 | matomo-org/matomo | libs/Zend/Session/SaveHandler/DbTable.php | Zend_Session_SaveHandler_DbTable._checkRequiredColumns | protected function _checkRequiredColumns()
{
if ($this->_modifiedColumn === null) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception(
"Configuration must define '" . self::MODIFIED_COLUMN . "' which names the "
. "session table last modification time column.");
} else if ($this->_lifetimeColumn === null) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception(
"Configuration must define '" . self::LIFETIME_COLUMN . "' which names the "
. "session table lifetime column.");
} else if ($this->_dataColumn === null) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception(
"Configuration must define '" . self::DATA_COLUMN . "' which names the "
. "session table data column.");
}
} | php | protected function _checkRequiredColumns()
{
if ($this->_modifiedColumn === null) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception(
"Configuration must define '" . self::MODIFIED_COLUMN . "' which names the "
. "session table last modification time column.");
} else if ($this->_lifetimeColumn === null) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception(
"Configuration must define '" . self::LIFETIME_COLUMN . "' which names the "
. "session table lifetime column.");
} else if ($this->_dataColumn === null) {
/**
* @see Zend_Session_SaveHandler_Exception
*/
// require_once 'Zend/Session/SaveHandler/Exception.php';
throw new Zend_Session_SaveHandler_Exception(
"Configuration must define '" . self::DATA_COLUMN . "' which names the "
. "session table data column.");
}
} | [
"protected",
"function",
"_checkRequiredColumns",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_modifiedColumn",
"===",
"null",
")",
"{",
"/**\n * @see Zend_Session_SaveHandler_Exception\n */",
"// require_once 'Zend/Session/SaveHandler/Exception.php';",
"throw",
"new",
"Zend_Session_SaveHandler_Exception",
"(",
"\"Configuration must define '\"",
".",
"self",
"::",
"MODIFIED_COLUMN",
".",
"\"' which names the \"",
".",
"\"session table last modification time column.\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"_lifetimeColumn",
"===",
"null",
")",
"{",
"/**\n * @see Zend_Session_SaveHandler_Exception\n */",
"// require_once 'Zend/Session/SaveHandler/Exception.php';",
"throw",
"new",
"Zend_Session_SaveHandler_Exception",
"(",
"\"Configuration must define '\"",
".",
"self",
"::",
"LIFETIME_COLUMN",
".",
"\"' which names the \"",
".",
"\"session table lifetime column.\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"_dataColumn",
"===",
"null",
")",
"{",
"/**\n * @see Zend_Session_SaveHandler_Exception\n */",
"// require_once 'Zend/Session/SaveHandler/Exception.php';",
"throw",
"new",
"Zend_Session_SaveHandler_Exception",
"(",
"\"Configuration must define '\"",
".",
"self",
"::",
"DATA_COLUMN",
".",
"\"' which names the \"",
".",
"\"session table data column.\"",
")",
";",
"}",
"}"
] | Check for required session table columns
@return void
@throws Zend_Session_SaveHandler_Exception | [
"Check",
"for",
"required",
"session",
"table",
"columns"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Session/SaveHandler/DbTable.php#L478-L508 |
210,016 | matomo-org/matomo | libs/Zend/Session/SaveHandler/DbTable.php | Zend_Session_SaveHandler_DbTable._getPrimary | protected function _getPrimary($id, $type = null)
{
$this->_setupPrimaryKey();
if ($type === null) {
$type = self::PRIMARY_TYPE_NUM;
}
$primaryArray = array();
foreach ($this->_primary as $index => $primary) {
switch ($this->_primaryAssignment[$index]) {
case self::PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH:
$value = $this->_sessionSavePath;
break;
case self::PRIMARY_ASSIGNMENT_SESSION_NAME:
$value = $this->_sessionName;
break;
case self::PRIMARY_ASSIGNMENT_SESSION_ID:
$value = (string) $id;
break;
default:
$value = (string) $this->_primaryAssignment[$index];
break;
}
switch ((string) $type) {
case self::PRIMARY_TYPE_PRIMARYNUM:
$primaryArray[$index] = $value;
break;
case self::PRIMARY_TYPE_ASSOC:
$primaryArray[$primary] = $value;
break;
case self::PRIMARY_TYPE_WHERECLAUSE:
$primaryArray[] = $this->getAdapter()->quoteIdentifier($primary, true) . ' = '
. $this->getAdapter()->quote($value);
break;
case self::PRIMARY_TYPE_NUM:
default:
$primaryArray[] = $value;
break;
}
}
return $primaryArray;
} | php | protected function _getPrimary($id, $type = null)
{
$this->_setupPrimaryKey();
if ($type === null) {
$type = self::PRIMARY_TYPE_NUM;
}
$primaryArray = array();
foreach ($this->_primary as $index => $primary) {
switch ($this->_primaryAssignment[$index]) {
case self::PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH:
$value = $this->_sessionSavePath;
break;
case self::PRIMARY_ASSIGNMENT_SESSION_NAME:
$value = $this->_sessionName;
break;
case self::PRIMARY_ASSIGNMENT_SESSION_ID:
$value = (string) $id;
break;
default:
$value = (string) $this->_primaryAssignment[$index];
break;
}
switch ((string) $type) {
case self::PRIMARY_TYPE_PRIMARYNUM:
$primaryArray[$index] = $value;
break;
case self::PRIMARY_TYPE_ASSOC:
$primaryArray[$primary] = $value;
break;
case self::PRIMARY_TYPE_WHERECLAUSE:
$primaryArray[] = $this->getAdapter()->quoteIdentifier($primary, true) . ' = '
. $this->getAdapter()->quote($value);
break;
case self::PRIMARY_TYPE_NUM:
default:
$primaryArray[] = $value;
break;
}
}
return $primaryArray;
} | [
"protected",
"function",
"_getPrimary",
"(",
"$",
"id",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_setupPrimaryKey",
"(",
")",
";",
"if",
"(",
"$",
"type",
"===",
"null",
")",
"{",
"$",
"type",
"=",
"self",
"::",
"PRIMARY_TYPE_NUM",
";",
"}",
"$",
"primaryArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_primary",
"as",
"$",
"index",
"=>",
"$",
"primary",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"_primaryAssignment",
"[",
"$",
"index",
"]",
")",
"{",
"case",
"self",
"::",
"PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH",
":",
"$",
"value",
"=",
"$",
"this",
"->",
"_sessionSavePath",
";",
"break",
";",
"case",
"self",
"::",
"PRIMARY_ASSIGNMENT_SESSION_NAME",
":",
"$",
"value",
"=",
"$",
"this",
"->",
"_sessionName",
";",
"break",
";",
"case",
"self",
"::",
"PRIMARY_ASSIGNMENT_SESSION_ID",
":",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"id",
";",
"break",
";",
"default",
":",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"_primaryAssignment",
"[",
"$",
"index",
"]",
";",
"break",
";",
"}",
"switch",
"(",
"(",
"string",
")",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"PRIMARY_TYPE_PRIMARYNUM",
":",
"$",
"primaryArray",
"[",
"$",
"index",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"self",
"::",
"PRIMARY_TYPE_ASSOC",
":",
"$",
"primaryArray",
"[",
"$",
"primary",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"self",
"::",
"PRIMARY_TYPE_WHERECLAUSE",
":",
"$",
"primaryArray",
"[",
"]",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"quoteIdentifier",
"(",
"$",
"primary",
",",
"true",
")",
".",
"' = '",
".",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"self",
"::",
"PRIMARY_TYPE_NUM",
":",
"default",
":",
"$",
"primaryArray",
"[",
"]",
"=",
"$",
"value",
";",
"break",
";",
"}",
"}",
"return",
"$",
"primaryArray",
";",
"}"
] | Retrieve session table primary key values
@param string $id
@param string $type (optional; default: self::PRIMARY_TYPE_NUM)
@return array | [
"Retrieve",
"session",
"table",
"primary",
"key",
"values"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Session/SaveHandler/DbTable.php#L517-L562 |
210,017 | matomo-org/matomo | libs/Zend/Cache/Backend/TwoLevels.php | Zend_Cache_Backend_TwoLevels._prepareData | private function _prepareData($data, $lifetime, $priority)
{
$lt = $lifetime;
if ($lt === null) {
$lt = 9999999999;
}
return serialize(array(
'data' => $data,
'lifetime' => $lifetime,
'expire' => time() + $lt,
'priority' => $priority
));
} | php | private function _prepareData($data, $lifetime, $priority)
{
$lt = $lifetime;
if ($lt === null) {
$lt = 9999999999;
}
return serialize(array(
'data' => $data,
'lifetime' => $lifetime,
'expire' => time() + $lt,
'priority' => $priority
));
} | [
"private",
"function",
"_prepareData",
"(",
"$",
"data",
",",
"$",
"lifetime",
",",
"$",
"priority",
")",
"{",
"$",
"lt",
"=",
"$",
"lifetime",
";",
"if",
"(",
"$",
"lt",
"===",
"null",
")",
"{",
"$",
"lt",
"=",
"9999999999",
";",
"}",
"return",
"serialize",
"(",
"array",
"(",
"'data'",
"=>",
"$",
"data",
",",
"'lifetime'",
"=>",
"$",
"lifetime",
",",
"'expire'",
"=>",
"time",
"(",
")",
"+",
"$",
"lt",
",",
"'priority'",
"=>",
"$",
"priority",
")",
")",
";",
"}"
] | Prepare a serialized array to store datas and metadatas informations
@param string $data data to store
@param int $lifetime original lifetime
@param int $priority priority
@return string serialize array to store into cache | [
"Prepare",
"a",
"serialized",
"array",
"to",
"store",
"datas",
"and",
"metadatas",
"informations"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/TwoLevels.php#L459-L471 |
210,018 | matomo-org/matomo | libs/Zend/Cache/Backend/TwoLevels.php | Zend_Cache_Backend_TwoLevels._getFastLifetime | private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
{
if ($lifetime <= 0) {
// if no lifetime, we have an infinite lifetime
// we need to use arbitrary lifetimes
$fastLifetime = (int) (2592000 / (11 - $priority));
} else {
// prevent computed infinite lifetime (0) by ceil
$fastLifetime = (int) ceil($lifetime / (11 - $priority));
}
if ($maxLifetime >= 0 && $fastLifetime > $maxLifetime) {
return $maxLifetime;
}
return $fastLifetime;
} | php | private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
{
if ($lifetime <= 0) {
// if no lifetime, we have an infinite lifetime
// we need to use arbitrary lifetimes
$fastLifetime = (int) (2592000 / (11 - $priority));
} else {
// prevent computed infinite lifetime (0) by ceil
$fastLifetime = (int) ceil($lifetime / (11 - $priority));
}
if ($maxLifetime >= 0 && $fastLifetime > $maxLifetime) {
return $maxLifetime;
}
return $fastLifetime;
} | [
"private",
"function",
"_getFastLifetime",
"(",
"$",
"lifetime",
",",
"$",
"priority",
",",
"$",
"maxLifetime",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"lifetime",
"<=",
"0",
")",
"{",
"// if no lifetime, we have an infinite lifetime",
"// we need to use arbitrary lifetimes",
"$",
"fastLifetime",
"=",
"(",
"int",
")",
"(",
"2592000",
"/",
"(",
"11",
"-",
"$",
"priority",
")",
")",
";",
"}",
"else",
"{",
"// prevent computed infinite lifetime (0) by ceil",
"$",
"fastLifetime",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"lifetime",
"/",
"(",
"11",
"-",
"$",
"priority",
")",
")",
";",
"}",
"if",
"(",
"$",
"maxLifetime",
">=",
"0",
"&&",
"$",
"fastLifetime",
">",
"$",
"maxLifetime",
")",
"{",
"return",
"$",
"maxLifetime",
";",
"}",
"return",
"$",
"fastLifetime",
";",
"}"
] | Compute and return the lifetime for the fast backend
@param int $lifetime original lifetime
@param int $priority priority
@param int $maxLifetime maximum lifetime
@return int lifetime for the fast backend | [
"Compute",
"and",
"return",
"the",
"lifetime",
"for",
"the",
"fast",
"backend"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/TwoLevels.php#L481-L497 |
210,019 | matomo-org/matomo | plugins/WebsiteMeasurable/Settings/Urls.php | Urls.checkAtLeastOneUrl | public function checkAtLeastOneUrl($urls)
{
$urls = $this->cleanParameterUrls($urls);
if (!is_array($urls)
|| count($urls) == 0
) {
throw new Exception(Piwik::translate('SitesManager_ExceptionNoUrl'));
}
} | php | public function checkAtLeastOneUrl($urls)
{
$urls = $this->cleanParameterUrls($urls);
if (!is_array($urls)
|| count($urls) == 0
) {
throw new Exception(Piwik::translate('SitesManager_ExceptionNoUrl'));
}
} | [
"public",
"function",
"checkAtLeastOneUrl",
"(",
"$",
"urls",
")",
"{",
"$",
"urls",
"=",
"$",
"this",
"->",
"cleanParameterUrls",
"(",
"$",
"urls",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"urls",
")",
"||",
"count",
"(",
"$",
"urls",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"Piwik",
"::",
"translate",
"(",
"'SitesManager_ExceptionNoUrl'",
")",
")",
";",
"}",
"}"
] | Checks that the array has at least one element
@param array $urls
@throws Exception | [
"Checks",
"that",
"the",
"array",
"has",
"at",
"least",
"one",
"element"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/WebsiteMeasurable/Settings/Urls.php#L67-L76 |
210,020 | matomo-org/matomo | plugins/WebsiteMeasurable/Settings/Urls.php | Urls.checkUrls | public function checkUrls($urls)
{
$urls = $this->cleanParameterUrls($urls);
foreach ($urls as $url) {
if (!UrlHelper::isLookLikeUrl($url)) {
throw new Exception(sprintf(Piwik::translate('SitesManager_ExceptionInvalidUrl'), $url));
}
}
} | php | public function checkUrls($urls)
{
$urls = $this->cleanParameterUrls($urls);
foreach ($urls as $url) {
if (!UrlHelper::isLookLikeUrl($url)) {
throw new Exception(sprintf(Piwik::translate('SitesManager_ExceptionInvalidUrl'), $url));
}
}
} | [
"public",
"function",
"checkUrls",
"(",
"$",
"urls",
")",
"{",
"$",
"urls",
"=",
"$",
"this",
"->",
"cleanParameterUrls",
"(",
"$",
"urls",
")",
";",
"foreach",
"(",
"$",
"urls",
"as",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"UrlHelper",
"::",
"isLookLikeUrl",
"(",
"$",
"url",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"Piwik",
"::",
"translate",
"(",
"'SitesManager_ExceptionInvalidUrl'",
")",
",",
"$",
"url",
")",
")",
";",
"}",
"}",
"}"
] | Check that the array of URLs are valid URLs
@param array $urls
@throws Exception if any of the urls is not valid | [
"Check",
"that",
"the",
"array",
"of",
"URLs",
"are",
"valid",
"URLs"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/WebsiteMeasurable/Settings/Urls.php#L84-L93 |
210,021 | matomo-org/matomo | plugins/SegmentEditor/Services/StoredSegmentService.php | StoredSegmentService.getAllSegmentsAndIgnoreVisibility | public function getAllSegmentsAndIgnoreVisibility()
{
$cacheKey = 'SegmentEditor.getAllSegmentsAndIgnoreVisibility';
if (!$this->transientCache->contains($cacheKey)) {
$result = $this->model->getAllSegmentsAndIgnoreVisibility();
$this->transientCache->save($cacheKey, $result);
}
return $this->transientCache->fetch($cacheKey);
} | php | public function getAllSegmentsAndIgnoreVisibility()
{
$cacheKey = 'SegmentEditor.getAllSegmentsAndIgnoreVisibility';
if (!$this->transientCache->contains($cacheKey)) {
$result = $this->model->getAllSegmentsAndIgnoreVisibility();
$this->transientCache->save($cacheKey, $result);
}
return $this->transientCache->fetch($cacheKey);
} | [
"public",
"function",
"getAllSegmentsAndIgnoreVisibility",
"(",
")",
"{",
"$",
"cacheKey",
"=",
"'SegmentEditor.getAllSegmentsAndIgnoreVisibility'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"transientCache",
"->",
"contains",
"(",
"$",
"cacheKey",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"model",
"->",
"getAllSegmentsAndIgnoreVisibility",
"(",
")",
";",
"$",
"this",
"->",
"transientCache",
"->",
"save",
"(",
"$",
"cacheKey",
",",
"$",
"result",
")",
";",
"}",
"return",
"$",
"this",
"->",
"transientCache",
"->",
"fetch",
"(",
"$",
"cacheKey",
")",
";",
"}"
] | Returns all stored segments that haven't been deleted.
@return array | [
"Returns",
"all",
"stored",
"segments",
"that",
"haven",
"t",
"been",
"deleted",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SegmentEditor/Services/StoredSegmentService.php#L41-L50 |
210,022 | matomo-org/matomo | plugins/DevicePlugins/Archiver.php | Archiver.aggregateByPlugin | protected function aggregateByPlugin()
{
$selects = array();
$columns = DevicePlugins::getAllPluginColumns();
foreach ($columns as $column) {
$selects[] = sprintf(
"sum(case log_visit.%s when 1 then 1 else 0 end) as %s",
$column->getColumnName(),
substr($column->getColumnName(), 7) // remove leading `config_`
);
}
$query = $this->getLogAggregator()->queryVisitsByDimension(array(), false, $selects, $metrics = array());
$data = $query->fetch();
$cleanRow = LogAggregator::makeArrayOneColumn($data, Metrics::INDEX_NB_VISITS);
$table = DataTable::makeFromIndexedArray($cleanRow);
$this->insertTable(self::PLUGIN_RECORD_NAME, $table);
} | php | protected function aggregateByPlugin()
{
$selects = array();
$columns = DevicePlugins::getAllPluginColumns();
foreach ($columns as $column) {
$selects[] = sprintf(
"sum(case log_visit.%s when 1 then 1 else 0 end) as %s",
$column->getColumnName(),
substr($column->getColumnName(), 7) // remove leading `config_`
);
}
$query = $this->getLogAggregator()->queryVisitsByDimension(array(), false, $selects, $metrics = array());
$data = $query->fetch();
$cleanRow = LogAggregator::makeArrayOneColumn($data, Metrics::INDEX_NB_VISITS);
$table = DataTable::makeFromIndexedArray($cleanRow);
$this->insertTable(self::PLUGIN_RECORD_NAME, $table);
} | [
"protected",
"function",
"aggregateByPlugin",
"(",
")",
"{",
"$",
"selects",
"=",
"array",
"(",
")",
";",
"$",
"columns",
"=",
"DevicePlugins",
"::",
"getAllPluginColumns",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"selects",
"[",
"]",
"=",
"sprintf",
"(",
"\"sum(case log_visit.%s when 1 then 1 else 0 end) as %s\"",
",",
"$",
"column",
"->",
"getColumnName",
"(",
")",
",",
"substr",
"(",
"$",
"column",
"->",
"getColumnName",
"(",
")",
",",
"7",
")",
"// remove leading `config_`",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"getLogAggregator",
"(",
")",
"->",
"queryVisitsByDimension",
"(",
"array",
"(",
")",
",",
"false",
",",
"$",
"selects",
",",
"$",
"metrics",
"=",
"array",
"(",
")",
")",
";",
"$",
"data",
"=",
"$",
"query",
"->",
"fetch",
"(",
")",
";",
"$",
"cleanRow",
"=",
"LogAggregator",
"::",
"makeArrayOneColumn",
"(",
"$",
"data",
",",
"Metrics",
"::",
"INDEX_NB_VISITS",
")",
";",
"$",
"table",
"=",
"DataTable",
"::",
"makeFromIndexedArray",
"(",
"$",
"cleanRow",
")",
";",
"$",
"this",
"->",
"insertTable",
"(",
"self",
"::",
"PLUGIN_RECORD_NAME",
",",
"$",
"table",
")",
";",
"}"
] | Archives reports for all available plugin columns
@see DevicePluginColumn | [
"Archives",
"reports",
"for",
"all",
"available",
"plugin",
"columns"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/DevicePlugins/Archiver.php#L60-L78 |
210,023 | matomo-org/matomo | plugins/GeoIp2/LocationProvider/GeoIp2/Php.php | Php.getGeoIpInstance | private function getGeoIpInstance($key)
{
if (empty($this->readerCache[$key])) {
$pathToDb = self::getPathToGeoIpDatabase($this->customDbNames[$key]);
if ($pathToDb !== false) {
try {
$this->readerCache[$key] = new Reader($pathToDb);
} catch (InvalidDatabaseException $e) {
// ignore invalid database exception
}
}
}
return empty($this->readerCache[$key]) ? false : $this->readerCache[$key];
} | php | private function getGeoIpInstance($key)
{
if (empty($this->readerCache[$key])) {
$pathToDb = self::getPathToGeoIpDatabase($this->customDbNames[$key]);
if ($pathToDb !== false) {
try {
$this->readerCache[$key] = new Reader($pathToDb);
} catch (InvalidDatabaseException $e) {
// ignore invalid database exception
}
}
}
return empty($this->readerCache[$key]) ? false : $this->readerCache[$key];
} | [
"private",
"function",
"getGeoIpInstance",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"readerCache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"pathToDb",
"=",
"self",
"::",
"getPathToGeoIpDatabase",
"(",
"$",
"this",
"->",
"customDbNames",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"$",
"pathToDb",
"!==",
"false",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"readerCache",
"[",
"$",
"key",
"]",
"=",
"new",
"Reader",
"(",
"$",
"pathToDb",
")",
";",
"}",
"catch",
"(",
"InvalidDatabaseException",
"$",
"e",
")",
"{",
"// ignore invalid database exception",
"}",
"}",
"}",
"return",
"empty",
"(",
"$",
"this",
"->",
"readerCache",
"[",
"$",
"key",
"]",
")",
"?",
"false",
":",
"$",
"this",
"->",
"readerCache",
"[",
"$",
"key",
"]",
";",
"}"
] | Returns a GeoIP2 reader instance. Creates it if necessary.
@param string $key 'loc' or 'isp'. Determines the type of GeoIP database
to load.
@return Reader|false | [
"Returns",
"a",
"GeoIP2",
"reader",
"instance",
".",
"Creates",
"it",
"if",
"necessary",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/GeoIp2/LocationProvider/GeoIp2/Php.php#L320-L334 |
210,024 | matomo-org/matomo | core/Plugin/ControllerAdmin.php | ControllerAdmin.setBasicVariablesAdminView | public static function setBasicVariablesAdminView(View $view)
{
self::notifyWhenTrackingStatisticsDisabled();
self::notifyIfEAcceleratorIsUsed();
self::notifyIfURLIsNotSecure();
$view->topMenu = MenuTop::getInstance()->getMenu();
$view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled();
$enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
$view->enableFrames = $enableFrames;
if (!$enableFrames) {
$view->setXFrameOptions('sameorigin');
}
$view->isSuperUser = Piwik::hasUserSuperUserAccess();
self::notifyAnyInvalidLicense();
self::notifyAnyInvalidPlugin();
self::notifyWhenPhpVersionIsEOL();
self::notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik();
self::notifyWhenDebugOnDemandIsEnabled('debug');
self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand');
/**
* Posted when rendering an admin page and notifications about any warnings or errors should be triggered.
* You can use it for example when you have a plugin that needs to be configured in order to work and the
* plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling
* eg `Notification\Manager::cancel($notificationId)`.
*
* **Example**
*
* public function onTriggerAdminNotifications(Piwik\Widget\WidgetsList $list)
* {
* if ($pluginFooIsNotConfigured) {
* $notification = new Notification('The plugin foo has not been configured yet');
* $notification->context = Notification::CONTEXT_WARNING;
* Notification\Manager::notify('fooNotConfigured', $notification);
* }
* }
*
*/
Piwik::postEvent('Controller.triggerAdminNotifications');
$view->adminMenu = MenuAdmin::getInstance()->getMenu();
$notifications = $view->notifications;
if (empty($notifications)) {
$view->notifications = NotificationManager::getAllNotificationsToDisplay();
NotificationManager::cancelAllNonPersistent();
}
} | php | public static function setBasicVariablesAdminView(View $view)
{
self::notifyWhenTrackingStatisticsDisabled();
self::notifyIfEAcceleratorIsUsed();
self::notifyIfURLIsNotSecure();
$view->topMenu = MenuTop::getInstance()->getMenu();
$view->isDataPurgeSettingsEnabled = self::isDataPurgeSettingsEnabled();
$enableFrames = PiwikConfig::getInstance()->General['enable_framed_settings'];
$view->enableFrames = $enableFrames;
if (!$enableFrames) {
$view->setXFrameOptions('sameorigin');
}
$view->isSuperUser = Piwik::hasUserSuperUserAccess();
self::notifyAnyInvalidLicense();
self::notifyAnyInvalidPlugin();
self::notifyWhenPhpVersionIsEOL();
self::notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik();
self::notifyWhenDebugOnDemandIsEnabled('debug');
self::notifyWhenDebugOnDemandIsEnabled('debug_on_demand');
/**
* Posted when rendering an admin page and notifications about any warnings or errors should be triggered.
* You can use it for example when you have a plugin that needs to be configured in order to work and the
* plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling
* eg `Notification\Manager::cancel($notificationId)`.
*
* **Example**
*
* public function onTriggerAdminNotifications(Piwik\Widget\WidgetsList $list)
* {
* if ($pluginFooIsNotConfigured) {
* $notification = new Notification('The plugin foo has not been configured yet');
* $notification->context = Notification::CONTEXT_WARNING;
* Notification\Manager::notify('fooNotConfigured', $notification);
* }
* }
*
*/
Piwik::postEvent('Controller.triggerAdminNotifications');
$view->adminMenu = MenuAdmin::getInstance()->getMenu();
$notifications = $view->notifications;
if (empty($notifications)) {
$view->notifications = NotificationManager::getAllNotificationsToDisplay();
NotificationManager::cancelAllNonPersistent();
}
} | [
"public",
"static",
"function",
"setBasicVariablesAdminView",
"(",
"View",
"$",
"view",
")",
"{",
"self",
"::",
"notifyWhenTrackingStatisticsDisabled",
"(",
")",
";",
"self",
"::",
"notifyIfEAcceleratorIsUsed",
"(",
")",
";",
"self",
"::",
"notifyIfURLIsNotSecure",
"(",
")",
";",
"$",
"view",
"->",
"topMenu",
"=",
"MenuTop",
"::",
"getInstance",
"(",
")",
"->",
"getMenu",
"(",
")",
";",
"$",
"view",
"->",
"isDataPurgeSettingsEnabled",
"=",
"self",
"::",
"isDataPurgeSettingsEnabled",
"(",
")",
";",
"$",
"enableFrames",
"=",
"PiwikConfig",
"::",
"getInstance",
"(",
")",
"->",
"General",
"[",
"'enable_framed_settings'",
"]",
";",
"$",
"view",
"->",
"enableFrames",
"=",
"$",
"enableFrames",
";",
"if",
"(",
"!",
"$",
"enableFrames",
")",
"{",
"$",
"view",
"->",
"setXFrameOptions",
"(",
"'sameorigin'",
")",
";",
"}",
"$",
"view",
"->",
"isSuperUser",
"=",
"Piwik",
"::",
"hasUserSuperUserAccess",
"(",
")",
";",
"self",
"::",
"notifyAnyInvalidLicense",
"(",
")",
";",
"self",
"::",
"notifyAnyInvalidPlugin",
"(",
")",
";",
"self",
"::",
"notifyWhenPhpVersionIsEOL",
"(",
")",
";",
"self",
"::",
"notifyWhenPhpVersionIsNotCompatibleWithNextMajorPiwik",
"(",
")",
";",
"self",
"::",
"notifyWhenDebugOnDemandIsEnabled",
"(",
"'debug'",
")",
";",
"self",
"::",
"notifyWhenDebugOnDemandIsEnabled",
"(",
"'debug_on_demand'",
")",
";",
"/**\n * Posted when rendering an admin page and notifications about any warnings or errors should be triggered.\n * You can use it for example when you have a plugin that needs to be configured in order to work and the\n * plugin has not been configured yet. It can be also used to cancel / remove other notifications by calling \n * eg `Notification\\Manager::cancel($notificationId)`.\n *\n * **Example**\n *\n * public function onTriggerAdminNotifications(Piwik\\Widget\\WidgetsList $list)\n * {\n * if ($pluginFooIsNotConfigured) {\n * $notification = new Notification('The plugin foo has not been configured yet');\n * $notification->context = Notification::CONTEXT_WARNING;\n * Notification\\Manager::notify('fooNotConfigured', $notification);\n * }\n * }\n *\n */",
"Piwik",
"::",
"postEvent",
"(",
"'Controller.triggerAdminNotifications'",
")",
";",
"$",
"view",
"->",
"adminMenu",
"=",
"MenuAdmin",
"::",
"getInstance",
"(",
")",
"->",
"getMenu",
"(",
")",
";",
"$",
"notifications",
"=",
"$",
"view",
"->",
"notifications",
";",
"if",
"(",
"empty",
"(",
"$",
"notifications",
")",
")",
"{",
"$",
"view",
"->",
"notifications",
"=",
"NotificationManager",
"::",
"getAllNotificationsToDisplay",
"(",
")",
";",
"NotificationManager",
"::",
"cancelAllNonPersistent",
"(",
")",
";",
"}",
"}"
] | Assigns view properties that would be useful to views that render admin pages.
Assigns the following variables:
- **statisticsNotRecorded** - Set to true if the `[Tracker] record_statistics` INI
config is `0`. If not `0`, this variable will not be defined.
- **topMenu** - The result of `MenuTop::getInstance()->getMenu()`.
- **enableFrames** - The value of the `[General] enable_framed_pages` INI config option. If
true, {@link Piwik\View::setXFrameOptions()} is called on the view.
- **isSuperUser** - Whether the current user is a superuser or not.
- **usingOldGeoIPPlugin** - Whether this Piwik install is currently using the old GeoIP
plugin or not.
- **invalidPluginsWarning** - Set if some of the plugins to load (determined by INI configuration)
are invalid or missing.
- **phpVersion** - The current PHP version.
- **phpIsNewEnough** - Whether the current PHP version is new enough to run Piwik.
- **adminMenu** - The result of `MenuAdmin::getInstance()->getMenu()`.
@param View $view
@api | [
"Assigns",
"view",
"properties",
"that",
"would",
"be",
"useful",
"to",
"views",
"that",
"render",
"admin",
"pages",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/ControllerAdmin.php#L308-L361 |
210,025 | matomo-org/matomo | core/Plugin/Report.php | Report.getMetricsRequiredForReport | public function getMetricsRequiredForReport($allMetrics = null, $restrictToColumns = null)
{
if (empty($allMetrics)) {
$allMetrics = $this->metrics;
}
if (empty($restrictToColumns)) {
$restrictToColumns = array_merge($allMetrics, array_keys($this->getProcessedMetrics()));
}
$restrictToColumns = array_unique($restrictToColumns);
$processedMetricsById = $this->getProcessedMetricsById();
$metricsSet = array_flip($allMetrics);
$metrics = array();
foreach ($restrictToColumns as $column) {
if (isset($processedMetricsById[$column])) {
$metrics = array_merge($metrics, $processedMetricsById[$column]->getDependentMetrics());
} elseif (isset($metricsSet[$column])) {
$metrics[] = $column;
}
}
return array_unique($metrics);
} | php | public function getMetricsRequiredForReport($allMetrics = null, $restrictToColumns = null)
{
if (empty($allMetrics)) {
$allMetrics = $this->metrics;
}
if (empty($restrictToColumns)) {
$restrictToColumns = array_merge($allMetrics, array_keys($this->getProcessedMetrics()));
}
$restrictToColumns = array_unique($restrictToColumns);
$processedMetricsById = $this->getProcessedMetricsById();
$metricsSet = array_flip($allMetrics);
$metrics = array();
foreach ($restrictToColumns as $column) {
if (isset($processedMetricsById[$column])) {
$metrics = array_merge($metrics, $processedMetricsById[$column]->getDependentMetrics());
} elseif (isset($metricsSet[$column])) {
$metrics[] = $column;
}
}
return array_unique($metrics);
} | [
"public",
"function",
"getMetricsRequiredForReport",
"(",
"$",
"allMetrics",
"=",
"null",
",",
"$",
"restrictToColumns",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"allMetrics",
")",
")",
"{",
"$",
"allMetrics",
"=",
"$",
"this",
"->",
"metrics",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"restrictToColumns",
")",
")",
"{",
"$",
"restrictToColumns",
"=",
"array_merge",
"(",
"$",
"allMetrics",
",",
"array_keys",
"(",
"$",
"this",
"->",
"getProcessedMetrics",
"(",
")",
")",
")",
";",
"}",
"$",
"restrictToColumns",
"=",
"array_unique",
"(",
"$",
"restrictToColumns",
")",
";",
"$",
"processedMetricsById",
"=",
"$",
"this",
"->",
"getProcessedMetricsById",
"(",
")",
";",
"$",
"metricsSet",
"=",
"array_flip",
"(",
"$",
"allMetrics",
")",
";",
"$",
"metrics",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"restrictToColumns",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"processedMetricsById",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"metrics",
"=",
"array_merge",
"(",
"$",
"metrics",
",",
"$",
"processedMetricsById",
"[",
"$",
"column",
"]",
"->",
"getDependentMetrics",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"metricsSet",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"metrics",
"[",
"]",
"=",
"$",
"column",
";",
"}",
"}",
"return",
"array_unique",
"(",
"$",
"metrics",
")",
";",
"}"
] | Returns the list of metrics required at minimum for a report factoring in the columns requested by
the report requester.
This will return all the metrics requested (or all the metrics in the report if nothing is requested)
**plus** the metrics required to calculate the requested processed metrics.
This method should be used in **Plugin.get** API methods.
@param string[]|null $allMetrics The list of all available unprocessed metrics. Defaults to this report's
metrics.
@param string[]|null $restrictToColumns The requested columns.
@return string[] | [
"Returns",
"the",
"list",
"of",
"metrics",
"required",
"at",
"minimum",
"for",
"a",
"report",
"factoring",
"in",
"the",
"columns",
"requested",
"by",
"the",
"report",
"requester",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L401-L424 |
210,026 | matomo-org/matomo | core/Plugin/Report.php | Report.getDimensions | public function getDimensions()
{
$dimensions = [];
if (!empty($this->getDimension())) {
$dimensionId = str_replace('.', '_', $this->getDimension()->getId());
$dimensions[$dimensionId] = $this->getDimension()->getName();
}
if (!empty($this->getSubtableDimension())) {
$subDimensionId = str_replace('.', '_', $this->getSubtableDimension()->getId());
$dimensions[$subDimensionId] = $this->getSubtableDimension()->getName();
}
if (!empty($this->getThirdLeveltableDimension())) {
$subDimensionId = str_replace('.', '_', $this->getThirdLeveltableDimension()->getId());
$dimensions[$subDimensionId] = $this->getThirdLeveltableDimension()->getName();
}
return $dimensions;
} | php | public function getDimensions()
{
$dimensions = [];
if (!empty($this->getDimension())) {
$dimensionId = str_replace('.', '_', $this->getDimension()->getId());
$dimensions[$dimensionId] = $this->getDimension()->getName();
}
if (!empty($this->getSubtableDimension())) {
$subDimensionId = str_replace('.', '_', $this->getSubtableDimension()->getId());
$dimensions[$subDimensionId] = $this->getSubtableDimension()->getName();
}
if (!empty($this->getThirdLeveltableDimension())) {
$subDimensionId = str_replace('.', '_', $this->getThirdLeveltableDimension()->getId());
$dimensions[$subDimensionId] = $this->getThirdLeveltableDimension()->getName();
}
return $dimensions;
} | [
"public",
"function",
"getDimensions",
"(",
")",
"{",
"$",
"dimensions",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getDimension",
"(",
")",
")",
")",
"{",
"$",
"dimensionId",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"this",
"->",
"getDimension",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"$",
"dimensions",
"[",
"$",
"dimensionId",
"]",
"=",
"$",
"this",
"->",
"getDimension",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getSubtableDimension",
"(",
")",
")",
")",
"{",
"$",
"subDimensionId",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"this",
"->",
"getSubtableDimension",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"$",
"dimensions",
"[",
"$",
"subDimensionId",
"]",
"=",
"$",
"this",
"->",
"getSubtableDimension",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getThirdLeveltableDimension",
"(",
")",
")",
")",
"{",
"$",
"subDimensionId",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"this",
"->",
"getThirdLeveltableDimension",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"$",
"dimensions",
"[",
"$",
"subDimensionId",
"]",
"=",
"$",
"this",
"->",
"getThirdLeveltableDimension",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"dimensions",
";",
"}"
] | Get dimensions used for current report and its subreports
@return array [dimensionId => dimensionName]
@ignore | [
"Get",
"dimensions",
"used",
"for",
"current",
"report",
"and",
"its",
"subreports"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L760-L780 |
210,027 | matomo-org/matomo | core/Plugin/Report.php | Report.getSubtableDimension | public function getSubtableDimension()
{
if (empty($this->actionToLoadSubTables)) {
return null;
}
list($subtableReportModule, $subtableReportAction) = $this->getSubtableApiMethod();
$subtableReport = ReportsProvider::factory($subtableReportModule, $subtableReportAction);
if (empty($subtableReport)) {
return null;
}
return $subtableReport->getDimension();
} | php | public function getSubtableDimension()
{
if (empty($this->actionToLoadSubTables)) {
return null;
}
list($subtableReportModule, $subtableReportAction) = $this->getSubtableApiMethod();
$subtableReport = ReportsProvider::factory($subtableReportModule, $subtableReportAction);
if (empty($subtableReport)) {
return null;
}
return $subtableReport->getDimension();
} | [
"public",
"function",
"getSubtableDimension",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"actionToLoadSubTables",
")",
")",
"{",
"return",
"null",
";",
"}",
"list",
"(",
"$",
"subtableReportModule",
",",
"$",
"subtableReportAction",
")",
"=",
"$",
"this",
"->",
"getSubtableApiMethod",
"(",
")",
";",
"$",
"subtableReport",
"=",
"ReportsProvider",
"::",
"factory",
"(",
"$",
"subtableReportModule",
",",
"$",
"subtableReportAction",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"subtableReport",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"subtableReport",
"->",
"getDimension",
"(",
")",
";",
"}"
] | Returns the Dimension instance of this report's subtable report.
@return Dimension|null The subtable report's dimension or null if there is subtable report or
no dimension for the subtable report.
@api | [
"Returns",
"the",
"Dimension",
"instance",
"of",
"this",
"report",
"s",
"subtable",
"report",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L809-L823 |
210,028 | matomo-org/matomo | core/Plugin/Report.php | Report.getThirdLeveltableDimension | public function getThirdLeveltableDimension()
{
if (empty($this->actionToLoadSubTables)) {
return null;
}
list($subtableReportModule, $subtableReportAction) = $this->getSubtableApiMethod();
$subtableReport = ReportsProvider::factory($subtableReportModule, $subtableReportAction);
if (empty($subtableReport) || empty($subtableReport->actionToLoadSubTables)) {
return null;
}
list($subSubtableReportModule, $subSubtableReportAction) = $subtableReport->getSubtableApiMethod();
$subSubtableReport = ReportsProvider::factory($subSubtableReportModule, $subSubtableReportAction);
if (empty($subSubtableReport)) {
return null;
}
return $subSubtableReport->getDimension();
} | php | public function getThirdLeveltableDimension()
{
if (empty($this->actionToLoadSubTables)) {
return null;
}
list($subtableReportModule, $subtableReportAction) = $this->getSubtableApiMethod();
$subtableReport = ReportsProvider::factory($subtableReportModule, $subtableReportAction);
if (empty($subtableReport) || empty($subtableReport->actionToLoadSubTables)) {
return null;
}
list($subSubtableReportModule, $subSubtableReportAction) = $subtableReport->getSubtableApiMethod();
$subSubtableReport = ReportsProvider::factory($subSubtableReportModule, $subSubtableReportAction);
if (empty($subSubtableReport)) {
return null;
}
return $subSubtableReport->getDimension();
} | [
"public",
"function",
"getThirdLeveltableDimension",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"actionToLoadSubTables",
")",
")",
"{",
"return",
"null",
";",
"}",
"list",
"(",
"$",
"subtableReportModule",
",",
"$",
"subtableReportAction",
")",
"=",
"$",
"this",
"->",
"getSubtableApiMethod",
"(",
")",
";",
"$",
"subtableReport",
"=",
"ReportsProvider",
"::",
"factory",
"(",
"$",
"subtableReportModule",
",",
"$",
"subtableReportAction",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"subtableReport",
")",
"||",
"empty",
"(",
"$",
"subtableReport",
"->",
"actionToLoadSubTables",
")",
")",
"{",
"return",
"null",
";",
"}",
"list",
"(",
"$",
"subSubtableReportModule",
",",
"$",
"subSubtableReportAction",
")",
"=",
"$",
"subtableReport",
"->",
"getSubtableApiMethod",
"(",
")",
";",
"$",
"subSubtableReport",
"=",
"ReportsProvider",
"::",
"factory",
"(",
"$",
"subSubtableReportModule",
",",
"$",
"subSubtableReportAction",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"subSubtableReport",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"subSubtableReport",
"->",
"getDimension",
"(",
")",
";",
"}"
] | Returns the Dimension instance of the subtable report of this report's subtable report.
@return Dimension|null The subtable report's dimension or null if there is no subtable report or
no dimension for the subtable report.
@api | [
"Returns",
"the",
"Dimension",
"instance",
"of",
"the",
"subtable",
"report",
"of",
"this",
"report",
"s",
"subtable",
"report",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L832-L853 |
210,029 | matomo-org/matomo | core/Plugin/Report.php | Report.fetchSubtable | public function fetchSubtable($idSubtable, $paramOverride = array())
{
$paramOverride = array('idSubtable' => $idSubtable) + $paramOverride;
list($module, $action) = $this->getSubtableApiMethod();
return Request::processRequest($module . '.' . $action, $paramOverride);
} | php | public function fetchSubtable($idSubtable, $paramOverride = array())
{
$paramOverride = array('idSubtable' => $idSubtable) + $paramOverride;
list($module, $action) = $this->getSubtableApiMethod();
return Request::processRequest($module . '.' . $action, $paramOverride);
} | [
"public",
"function",
"fetchSubtable",
"(",
"$",
"idSubtable",
",",
"$",
"paramOverride",
"=",
"array",
"(",
")",
")",
"{",
"$",
"paramOverride",
"=",
"array",
"(",
"'idSubtable'",
"=>",
"$",
"idSubtable",
")",
"+",
"$",
"paramOverride",
";",
"list",
"(",
"$",
"module",
",",
"$",
"action",
")",
"=",
"$",
"this",
"->",
"getSubtableApiMethod",
"(",
")",
";",
"return",
"Request",
"::",
"processRequest",
"(",
"$",
"module",
".",
"'.'",
".",
"$",
"action",
",",
"$",
"paramOverride",
")",
";",
"}"
] | Fetches a subtable for the report represented by this instance.
@param int $idSubtable The subtable ID.
@param array $paramOverride Query parameter overrides.
@return DataTable
@api | [
"Fetches",
"a",
"subtable",
"for",
"the",
"report",
"represented",
"by",
"this",
"instance",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L885-L891 |
210,030 | matomo-org/matomo | core/Plugin/Report.php | Report.getForDimension | public static function getForDimension(Dimension $dimension)
{
$provider = new ReportsProvider();
$reports = $provider->getAllReports();
foreach ($reports as $report) {
if (!$report->isSubtableReport()
&& $report->getDimension()
&& $report->getDimension()->getId() == $dimension->getId()
) {
return $report;
}
}
return null;
} | php | public static function getForDimension(Dimension $dimension)
{
$provider = new ReportsProvider();
$reports = $provider->getAllReports();
foreach ($reports as $report) {
if (!$report->isSubtableReport()
&& $report->getDimension()
&& $report->getDimension()->getId() == $dimension->getId()
) {
return $report;
}
}
return null;
} | [
"public",
"static",
"function",
"getForDimension",
"(",
"Dimension",
"$",
"dimension",
")",
"{",
"$",
"provider",
"=",
"new",
"ReportsProvider",
"(",
")",
";",
"$",
"reports",
"=",
"$",
"provider",
"->",
"getAllReports",
"(",
")",
";",
"foreach",
"(",
"$",
"reports",
"as",
"$",
"report",
")",
"{",
"if",
"(",
"!",
"$",
"report",
"->",
"isSubtableReport",
"(",
")",
"&&",
"$",
"report",
"->",
"getDimension",
"(",
")",
"&&",
"$",
"report",
"->",
"getDimension",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"$",
"dimension",
"->",
"getId",
"(",
")",
")",
"{",
"return",
"$",
"report",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Finds a top level report that provides stats for a specific Dimension.
@param Dimension $dimension The dimension whose report we're looking for.
@return Report|null The
@api | [
"Finds",
"a",
"top",
"level",
"report",
"that",
"provides",
"stats",
"for",
"a",
"specific",
"Dimension",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L929-L942 |
210,031 | matomo-org/matomo | core/Plugin/Report.php | Report.getProcessedMetricsById | public function getProcessedMetricsById()
{
$processedMetrics = $this->processedMetrics ?: array();
$result = array();
foreach ($processedMetrics as $processedMetric) {
if ($processedMetric instanceof ProcessedMetric || $processedMetric instanceof ArchivedMetric) { // instanceof check for backwards compatibility
$result[$processedMetric->getName()] = $processedMetric;
}
}
return $result;
} | php | public function getProcessedMetricsById()
{
$processedMetrics = $this->processedMetrics ?: array();
$result = array();
foreach ($processedMetrics as $processedMetric) {
if ($processedMetric instanceof ProcessedMetric || $processedMetric instanceof ArchivedMetric) { // instanceof check for backwards compatibility
$result[$processedMetric->getName()] = $processedMetric;
}
}
return $result;
} | [
"public",
"function",
"getProcessedMetricsById",
"(",
")",
"{",
"$",
"processedMetrics",
"=",
"$",
"this",
"->",
"processedMetrics",
"?",
":",
"array",
"(",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"processedMetrics",
"as",
"$",
"processedMetric",
")",
"{",
"if",
"(",
"$",
"processedMetric",
"instanceof",
"ProcessedMetric",
"||",
"$",
"processedMetric",
"instanceof",
"ArchivedMetric",
")",
"{",
"// instanceof check for backwards compatibility",
"$",
"result",
"[",
"$",
"processedMetric",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"processedMetric",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an array mapping the ProcessedMetrics served by this report by their string names.
@return ProcessedMetric[] | [
"Returns",
"an",
"array",
"mapping",
"the",
"ProcessedMetrics",
"served",
"by",
"this",
"report",
"by",
"their",
"string",
"names",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L949-L960 |
210,032 | matomo-org/matomo | core/Plugin/Report.php | Report.getMetricsForTable | public static function getMetricsForTable(DataTable $dataTable, Report $report = null, $baseType = 'Piwik\\Plugin\\Metric')
{
$metrics = $dataTable->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME) ?: array();
if (!empty($report)) {
$metrics = array_merge($metrics, $report->getProcessedMetricsById());
}
$result = array();
/** @var Metric $metric */
foreach ($metrics as $metric) {
if (!($metric instanceof $baseType)) {
continue;
}
$result[$metric->getName()] = $metric;
}
return $result;
} | php | public static function getMetricsForTable(DataTable $dataTable, Report $report = null, $baseType = 'Piwik\\Plugin\\Metric')
{
$metrics = $dataTable->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME) ?: array();
if (!empty($report)) {
$metrics = array_merge($metrics, $report->getProcessedMetricsById());
}
$result = array();
/** @var Metric $metric */
foreach ($metrics as $metric) {
if (!($metric instanceof $baseType)) {
continue;
}
$result[$metric->getName()] = $metric;
}
return $result;
} | [
"public",
"static",
"function",
"getMetricsForTable",
"(",
"DataTable",
"$",
"dataTable",
",",
"Report",
"$",
"report",
"=",
"null",
",",
"$",
"baseType",
"=",
"'Piwik\\\\Plugin\\\\Metric'",
")",
"{",
"$",
"metrics",
"=",
"$",
"dataTable",
"->",
"getMetadata",
"(",
"DataTable",
"::",
"EXTRA_PROCESSED_METRICS_METADATA_NAME",
")",
"?",
":",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"report",
")",
")",
"{",
"$",
"metrics",
"=",
"array_merge",
"(",
"$",
"metrics",
",",
"$",
"report",
"->",
"getProcessedMetricsById",
"(",
")",
")",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"/** @var Metric $metric */",
"foreach",
"(",
"$",
"metrics",
"as",
"$",
"metric",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"metric",
"instanceof",
"$",
"baseType",
")",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"metric",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"metric",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the Metrics that are displayed by a DataTable of a certain Report type.
Includes ProcessedMetrics and Metrics.
@param DataTable $dataTable
@param Report|null $report
@param string $baseType The base type each metric class needs to be of.
@return Metric[]
@api | [
"Returns",
"the",
"Metrics",
"that",
"are",
"displayed",
"by",
"a",
"DataTable",
"of",
"a",
"certain",
"Report",
"type",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L973-L993 |
210,033 | matomo-org/matomo | core/Plugin/Report.php | Report.getProcessedMetricsForTable | public static function getProcessedMetricsForTable(DataTable $dataTable, Report $report = null)
{
/** @var ProcessedMetric[] $metrics */
$metrics = self::getMetricsForTable($dataTable, $report, 'Piwik\\Plugin\\ProcessedMetric');
// sort metrics w/ dependent metrics calculated before the metrics that depend on them
$result = [];
self::processedMetricDfs($metrics, function ($metricName) use (&$result, $metrics) {
$result[$metricName] = $metrics[$metricName];
});
return $result;
} | php | public static function getProcessedMetricsForTable(DataTable $dataTable, Report $report = null)
{
/** @var ProcessedMetric[] $metrics */
$metrics = self::getMetricsForTable($dataTable, $report, 'Piwik\\Plugin\\ProcessedMetric');
// sort metrics w/ dependent metrics calculated before the metrics that depend on them
$result = [];
self::processedMetricDfs($metrics, function ($metricName) use (&$result, $metrics) {
$result[$metricName] = $metrics[$metricName];
});
return $result;
} | [
"public",
"static",
"function",
"getProcessedMetricsForTable",
"(",
"DataTable",
"$",
"dataTable",
",",
"Report",
"$",
"report",
"=",
"null",
")",
"{",
"/** @var ProcessedMetric[] $metrics */",
"$",
"metrics",
"=",
"self",
"::",
"getMetricsForTable",
"(",
"$",
"dataTable",
",",
"$",
"report",
",",
"'Piwik\\\\Plugin\\\\ProcessedMetric'",
")",
";",
"// sort metrics w/ dependent metrics calculated before the metrics that depend on them",
"$",
"result",
"=",
"[",
"]",
";",
"self",
"::",
"processedMetricDfs",
"(",
"$",
"metrics",
",",
"function",
"(",
"$",
"metricName",
")",
"use",
"(",
"&",
"$",
"result",
",",
"$",
"metrics",
")",
"{",
"$",
"result",
"[",
"$",
"metricName",
"]",
"=",
"$",
"metrics",
"[",
"$",
"metricName",
"]",
";",
"}",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Returns the ProcessedMetrics that should be computed and formatted for a DataTable of a
certain report. The ProcessedMetrics returned are those specified by the Report metadata
as well as the DataTable metadata.
@param DataTable $dataTable
@param Report|null $report
@return ProcessedMetric[]
@api | [
"Returns",
"the",
"ProcessedMetrics",
"that",
"should",
"be",
"computed",
"and",
"formatted",
"for",
"a",
"DataTable",
"of",
"a",
"certain",
"report",
".",
"The",
"ProcessedMetrics",
"returned",
"are",
"those",
"specified",
"by",
"the",
"Report",
"metadata",
"as",
"well",
"as",
"the",
"DataTable",
"metadata",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin/Report.php#L1005-L1016 |
210,034 | matomo-org/matomo | plugins/LanguagesManager/TranslationWriter/Writer.php | Writer.getTranslations | public function getTranslations($lang)
{
$path = $this->getTranslationPathBaseDirectory('lang', $lang);
if (!is_readable($path)) {
return array();
}
$data = file_get_contents($path);
$translations = json_decode($data, true);
return $translations;
} | php | public function getTranslations($lang)
{
$path = $this->getTranslationPathBaseDirectory('lang', $lang);
if (!is_readable($path)) {
return array();
}
$data = file_get_contents($path);
$translations = json_decode($data, true);
return $translations;
} | [
"public",
"function",
"getTranslations",
"(",
"$",
"lang",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getTranslationPathBaseDirectory",
"(",
"'lang'",
",",
"$",
"lang",
")",
";",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"$",
"translations",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"return",
"$",
"translations",
";",
"}"
] | Get translations from file
@param string $lang ISO 639-1 alpha-2 language code
@throws Exception
@return array Array of translations ( plugin => ( key => translated string ) ) | [
"Get",
"translations",
"from",
"file"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/LanguagesManager/TranslationWriter/Writer.php#L152-L164 |
210,035 | matomo-org/matomo | plugins/LanguagesManager/TranslationWriter/Writer.php | Writer.getTranslationPathBaseDirectory | protected function getTranslationPathBaseDirectory($base, $lang = null)
{
if (empty($lang)) {
$lang = $this->getLanguage();
}
if (!empty($this->pluginName)) {
if ($base == 'tmp') {
return sprintf('%s/plugins/%s/lang/%s.json', StaticContainer::get('path.tmp'), $this->pluginName, $lang);
} else {
return sprintf('%s/lang/%s.json', Manager::getPluginDirectory($this->pluginName), $lang);
}
}
if ($base == 'tmp') {
return sprintf('%s/%s.json', StaticContainer::get('path.tmp'), $lang);
}
return sprintf('%s/%s/%s.json', PIWIK_INCLUDE_PATH, $base, $lang);
} | php | protected function getTranslationPathBaseDirectory($base, $lang = null)
{
if (empty($lang)) {
$lang = $this->getLanguage();
}
if (!empty($this->pluginName)) {
if ($base == 'tmp') {
return sprintf('%s/plugins/%s/lang/%s.json', StaticContainer::get('path.tmp'), $this->pluginName, $lang);
} else {
return sprintf('%s/lang/%s.json', Manager::getPluginDirectory($this->pluginName), $lang);
}
}
if ($base == 'tmp') {
return sprintf('%s/%s.json', StaticContainer::get('path.tmp'), $lang);
}
return sprintf('%s/%s/%s.json', PIWIK_INCLUDE_PATH, $base, $lang);
} | [
"protected",
"function",
"getTranslationPathBaseDirectory",
"(",
"$",
"base",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"lang",
")",
")",
"{",
"$",
"lang",
"=",
"$",
"this",
"->",
"getLanguage",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"pluginName",
")",
")",
"{",
"if",
"(",
"$",
"base",
"==",
"'tmp'",
")",
"{",
"return",
"sprintf",
"(",
"'%s/plugins/%s/lang/%s.json'",
",",
"StaticContainer",
"::",
"get",
"(",
"'path.tmp'",
")",
",",
"$",
"this",
"->",
"pluginName",
",",
"$",
"lang",
")",
";",
"}",
"else",
"{",
"return",
"sprintf",
"(",
"'%s/lang/%s.json'",
",",
"Manager",
"::",
"getPluginDirectory",
"(",
"$",
"this",
"->",
"pluginName",
")",
",",
"$",
"lang",
")",
";",
"}",
"}",
"if",
"(",
"$",
"base",
"==",
"'tmp'",
")",
"{",
"return",
"sprintf",
"(",
"'%s/%s.json'",
",",
"StaticContainer",
"::",
"get",
"(",
"'path.tmp'",
")",
",",
"$",
"lang",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s/%s/%s.json'",
",",
"PIWIK_INCLUDE_PATH",
",",
"$",
"base",
",",
"$",
"lang",
")",
";",
"}"
] | Get translation file path based on given params
@param string $base Optional base directory (either 'lang' or 'tmp')
@param string|null $lang forced language
@throws \Exception
@return string path | [
"Get",
"translation",
"file",
"path",
"based",
"on",
"given",
"params"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/LanguagesManager/TranslationWriter/Writer.php#L194-L214 |
210,036 | matomo-org/matomo | plugins/LanguagesManager/TranslationWriter/Writer.php | Writer.save | public function save()
{
$this->applyFilters();
if (!$this->hasTranslations() || !$this->isValid()) {
throw new Exception('unable to save empty or invalid translations');
}
$path = $this->getTranslationPath();
Filesystem::mkdir(dirname($path));
return file_put_contents($path, $this->__toString());
} | php | public function save()
{
$this->applyFilters();
if (!$this->hasTranslations() || !$this->isValid()) {
throw new Exception('unable to save empty or invalid translations');
}
$path = $this->getTranslationPath();
Filesystem::mkdir(dirname($path));
return file_put_contents($path, $this->__toString());
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"this",
"->",
"applyFilters",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasTranslations",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'unable to save empty or invalid translations'",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"getTranslationPath",
"(",
")",
";",
"Filesystem",
"::",
"mkdir",
"(",
"dirname",
"(",
"$",
"path",
")",
")",
";",
"return",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"__toString",
"(",
")",
")",
";",
"}"
] | Save translations to file; translations should already be cleaned.
@throws \Exception
@return bool|int False if failure, or number of bytes written | [
"Save",
"translations",
"to",
"file",
";",
"translations",
"should",
"already",
"be",
"cleaned",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/LanguagesManager/TranslationWriter/Writer.php#L243-L256 |
210,037 | matomo-org/matomo | plugins/LanguagesManager/TranslationWriter/Writer.php | Writer.saveTemporary | public function saveTemporary()
{
$this->applyFilters();
if (!$this->hasTranslations() || !$this->isValid()) {
throw new Exception('unable to save empty or invalid translations');
}
$path = $this->getTemporaryTranslationPath();
Filesystem::mkdir(dirname($path));
return file_put_contents($path, $this->__toString());
} | php | public function saveTemporary()
{
$this->applyFilters();
if (!$this->hasTranslations() || !$this->isValid()) {
throw new Exception('unable to save empty or invalid translations');
}
$path = $this->getTemporaryTranslationPath();
Filesystem::mkdir(dirname($path));
return file_put_contents($path, $this->__toString());
} | [
"public",
"function",
"saveTemporary",
"(",
")",
"{",
"$",
"this",
"->",
"applyFilters",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasTranslations",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'unable to save empty or invalid translations'",
")",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"getTemporaryTranslationPath",
"(",
")",
";",
"Filesystem",
"::",
"mkdir",
"(",
"dirname",
"(",
"$",
"path",
")",
")",
";",
"return",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"__toString",
"(",
")",
")",
";",
"}"
] | Save translations to temporary file; translations should already be cleansed.
@throws \Exception
@return bool|int False if failure, or number of bytes written | [
"Save",
"translations",
"to",
"temporary",
"file",
";",
"translations",
"should",
"already",
"be",
"cleansed",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/LanguagesManager/TranslationWriter/Writer.php#L264-L277 |
210,038 | matomo-org/matomo | plugins/LanguagesManager/TranslationWriter/Writer.php | Writer.isValid | public function isValid()
{
$this->applyFilters();
$this->validationMessage = null;
foreach ($this->validators as $validator) {
if (!$validator->isValid($this->translations)) {
$this->validationMessage = $validator->getMessage();
return false;
}
}
return true;
} | php | public function isValid()
{
$this->applyFilters();
$this->validationMessage = null;
foreach ($this->validators as $validator) {
if (!$validator->isValid($this->translations)) {
$this->validationMessage = $validator->getMessage();
return false;
}
}
return true;
} | [
"public",
"function",
"isValid",
"(",
")",
"{",
"$",
"this",
"->",
"applyFilters",
"(",
")",
";",
"$",
"this",
"->",
"validationMessage",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"validators",
"as",
"$",
"validator",
")",
"{",
"if",
"(",
"!",
"$",
"validator",
"->",
"isValid",
"(",
"$",
"this",
"->",
"translations",
")",
")",
"{",
"$",
"this",
"->",
"validationMessage",
"=",
"$",
"validator",
"->",
"getMessage",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Returns if translations are valid to save or not
@return bool | [
"Returns",
"if",
"translations",
"are",
"valid",
"to",
"save",
"or",
"not"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/LanguagesManager/TranslationWriter/Writer.php#L294-L308 |
210,039 | matomo-org/matomo | plugins/UserCountry/LocationProvider/GeoIp/Pecl.php | Pecl.getLocation | public function getLocation($info)
{
$ip = $this->getIpFromInfo($info);
$result = array();
// get location data
if (self::isCityDatabaseAvailable()) {
// Must hide errors because missing IPV6:
$location = @geoip_record_by_name($ip);
if (!empty($location)) {
$result[self::COUNTRY_CODE_KEY] = $location['country_code'];
$result[self::REGION_CODE_KEY] = $location['region'];
$result[self::CITY_NAME_KEY] = utf8_encode($location['city']);
$result[self::AREA_CODE_KEY] = $location['area_code'];
$result[self::LATITUDE_KEY] = $location['latitude'];
$result[self::LONGITUDE_KEY] = $location['longitude'];
$result[self::POSTAL_CODE_KEY] = $location['postal_code'];
}
} else if (self::isRegionDatabaseAvailable()) {
$location = @geoip_region_by_name($ip);
if (!empty($location)) {
$result[self::REGION_CODE_KEY] = $location['region'];
$result[self::COUNTRY_CODE_KEY] = $location['country_code'];
}
} else {
$result[self::COUNTRY_CODE_KEY] = @geoip_country_code_by_name($ip);
}
// get organization data if the org database is available
if (self::isOrgDatabaseAvailable()) {
$org = @geoip_org_by_name($ip);
if ($org !== false) {
$result[self::ORG_KEY] = utf8_encode($org);
}
}
// get isp data if the isp database is available
if (self::isISPDatabaseAvailable()) {
$isp = @geoip_isp_by_name($ip);
if ($isp !== false) {
$result[self::ISP_KEY] = utf8_encode($isp);
}
}
if (empty($result)) {
return false;
}
$this->completeLocationResult($result);
return $result;
} | php | public function getLocation($info)
{
$ip = $this->getIpFromInfo($info);
$result = array();
// get location data
if (self::isCityDatabaseAvailable()) {
// Must hide errors because missing IPV6:
$location = @geoip_record_by_name($ip);
if (!empty($location)) {
$result[self::COUNTRY_CODE_KEY] = $location['country_code'];
$result[self::REGION_CODE_KEY] = $location['region'];
$result[self::CITY_NAME_KEY] = utf8_encode($location['city']);
$result[self::AREA_CODE_KEY] = $location['area_code'];
$result[self::LATITUDE_KEY] = $location['latitude'];
$result[self::LONGITUDE_KEY] = $location['longitude'];
$result[self::POSTAL_CODE_KEY] = $location['postal_code'];
}
} else if (self::isRegionDatabaseAvailable()) {
$location = @geoip_region_by_name($ip);
if (!empty($location)) {
$result[self::REGION_CODE_KEY] = $location['region'];
$result[self::COUNTRY_CODE_KEY] = $location['country_code'];
}
} else {
$result[self::COUNTRY_CODE_KEY] = @geoip_country_code_by_name($ip);
}
// get organization data if the org database is available
if (self::isOrgDatabaseAvailable()) {
$org = @geoip_org_by_name($ip);
if ($org !== false) {
$result[self::ORG_KEY] = utf8_encode($org);
}
}
// get isp data if the isp database is available
if (self::isISPDatabaseAvailable()) {
$isp = @geoip_isp_by_name($ip);
if ($isp !== false) {
$result[self::ISP_KEY] = utf8_encode($isp);
}
}
if (empty($result)) {
return false;
}
$this->completeLocationResult($result);
return $result;
} | [
"public",
"function",
"getLocation",
"(",
"$",
"info",
")",
"{",
"$",
"ip",
"=",
"$",
"this",
"->",
"getIpFromInfo",
"(",
"$",
"info",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"// get location data",
"if",
"(",
"self",
"::",
"isCityDatabaseAvailable",
"(",
")",
")",
"{",
"// Must hide errors because missing IPV6:",
"$",
"location",
"=",
"@",
"geoip_record_by_name",
"(",
"$",
"ip",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"location",
")",
")",
"{",
"$",
"result",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
"=",
"$",
"location",
"[",
"'country_code'",
"]",
";",
"$",
"result",
"[",
"self",
"::",
"REGION_CODE_KEY",
"]",
"=",
"$",
"location",
"[",
"'region'",
"]",
";",
"$",
"result",
"[",
"self",
"::",
"CITY_NAME_KEY",
"]",
"=",
"utf8_encode",
"(",
"$",
"location",
"[",
"'city'",
"]",
")",
";",
"$",
"result",
"[",
"self",
"::",
"AREA_CODE_KEY",
"]",
"=",
"$",
"location",
"[",
"'area_code'",
"]",
";",
"$",
"result",
"[",
"self",
"::",
"LATITUDE_KEY",
"]",
"=",
"$",
"location",
"[",
"'latitude'",
"]",
";",
"$",
"result",
"[",
"self",
"::",
"LONGITUDE_KEY",
"]",
"=",
"$",
"location",
"[",
"'longitude'",
"]",
";",
"$",
"result",
"[",
"self",
"::",
"POSTAL_CODE_KEY",
"]",
"=",
"$",
"location",
"[",
"'postal_code'",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"self",
"::",
"isRegionDatabaseAvailable",
"(",
")",
")",
"{",
"$",
"location",
"=",
"@",
"geoip_region_by_name",
"(",
"$",
"ip",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"location",
")",
")",
"{",
"$",
"result",
"[",
"self",
"::",
"REGION_CODE_KEY",
"]",
"=",
"$",
"location",
"[",
"'region'",
"]",
";",
"$",
"result",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
"=",
"$",
"location",
"[",
"'country_code'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"result",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
"=",
"@",
"geoip_country_code_by_name",
"(",
"$",
"ip",
")",
";",
"}",
"// get organization data if the org database is available",
"if",
"(",
"self",
"::",
"isOrgDatabaseAvailable",
"(",
")",
")",
"{",
"$",
"org",
"=",
"@",
"geoip_org_by_name",
"(",
"$",
"ip",
")",
";",
"if",
"(",
"$",
"org",
"!==",
"false",
")",
"{",
"$",
"result",
"[",
"self",
"::",
"ORG_KEY",
"]",
"=",
"utf8_encode",
"(",
"$",
"org",
")",
";",
"}",
"}",
"// get isp data if the isp database is available",
"if",
"(",
"self",
"::",
"isISPDatabaseAvailable",
"(",
")",
")",
"{",
"$",
"isp",
"=",
"@",
"geoip_isp_by_name",
"(",
"$",
"ip",
")",
";",
"if",
"(",
"$",
"isp",
"!==",
"false",
")",
"{",
"$",
"result",
"[",
"self",
"::",
"ISP_KEY",
"]",
"=",
"utf8_encode",
"(",
"$",
"isp",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"completeLocationResult",
"(",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Uses the GeoIP PECL module to get a visitor's location based on their IP address.
This function will return different results based on the data available. If a city
database can be detected by the PECL module, it may return the country code,
region code, city name, area code, latitude, longitude and postal code of the visitor.
Alternatively, if only the country database can be detected, only the country code
will be returned.
The GeoIP PECL module will detect the following filenames:
- GeoIP.dat
- GeoIPCity.dat
- GeoIPISP.dat
- GeoIPOrg.dat
Note how GeoLiteCity.dat, the name for the GeoLite city database, is not detected
by the PECL module.
@param array $info Must have an 'ip' field.
@return array | [
"Uses",
"the",
"GeoIP",
"PECL",
"module",
"to",
"get",
"a",
"visitor",
"s",
"location",
"based",
"on",
"their",
"IP",
"address",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php#L53-L104 |
210,040 | matomo-org/matomo | plugins/UserCountry/LocationProvider/GeoIp/Pecl.php | Pecl.isWorking | public function isWorking()
{
// if no no location database is available, this implementation is not setup correctly
if (!self::isLocationDatabaseAvailable()) {
$dbDir = dirname(geoip_db_filename(GEOIP_COUNTRY_EDITION)) . '/';
$quotedDir = "'$dbDir'";
// check if the directory the PECL module is looking for exists
if (!is_dir($dbDir)) {
return Piwik::translate('UserCountry_PeclGeoIPNoDBDir', array($quotedDir, "'geoip.custom_directory'"));
}
// check if the user named the city database GeoLiteCity.dat
if (file_exists($dbDir . 'GeoLiteCity.dat')) {
return Piwik::translate('UserCountry_PeclGeoLiteError',
array($quotedDir, "'GeoLiteCity.dat'", "'GeoIPCity.dat'"));
}
return Piwik::translate('UserCountry_CannotFindPeclGeoIPDb',
array($quotedDir, "'GeoIP.dat'", "'GeoIPCity.dat'"));
}
return parent::isWorking();
} | php | public function isWorking()
{
// if no no location database is available, this implementation is not setup correctly
if (!self::isLocationDatabaseAvailable()) {
$dbDir = dirname(geoip_db_filename(GEOIP_COUNTRY_EDITION)) . '/';
$quotedDir = "'$dbDir'";
// check if the directory the PECL module is looking for exists
if (!is_dir($dbDir)) {
return Piwik::translate('UserCountry_PeclGeoIPNoDBDir', array($quotedDir, "'geoip.custom_directory'"));
}
// check if the user named the city database GeoLiteCity.dat
if (file_exists($dbDir . 'GeoLiteCity.dat')) {
return Piwik::translate('UserCountry_PeclGeoLiteError',
array($quotedDir, "'GeoLiteCity.dat'", "'GeoIPCity.dat'"));
}
return Piwik::translate('UserCountry_CannotFindPeclGeoIPDb',
array($quotedDir, "'GeoIP.dat'", "'GeoIPCity.dat'"));
}
return parent::isWorking();
} | [
"public",
"function",
"isWorking",
"(",
")",
"{",
"// if no no location database is available, this implementation is not setup correctly",
"if",
"(",
"!",
"self",
"::",
"isLocationDatabaseAvailable",
"(",
")",
")",
"{",
"$",
"dbDir",
"=",
"dirname",
"(",
"geoip_db_filename",
"(",
"GEOIP_COUNTRY_EDITION",
")",
")",
".",
"'/'",
";",
"$",
"quotedDir",
"=",
"\"'$dbDir'\"",
";",
"// check if the directory the PECL module is looking for exists",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dbDir",
")",
")",
"{",
"return",
"Piwik",
"::",
"translate",
"(",
"'UserCountry_PeclGeoIPNoDBDir'",
",",
"array",
"(",
"$",
"quotedDir",
",",
"\"'geoip.custom_directory'\"",
")",
")",
";",
"}",
"// check if the user named the city database GeoLiteCity.dat",
"if",
"(",
"file_exists",
"(",
"$",
"dbDir",
".",
"'GeoLiteCity.dat'",
")",
")",
"{",
"return",
"Piwik",
"::",
"translate",
"(",
"'UserCountry_PeclGeoLiteError'",
",",
"array",
"(",
"$",
"quotedDir",
",",
"\"'GeoLiteCity.dat'\"",
",",
"\"'GeoIPCity.dat'\"",
")",
")",
";",
"}",
"return",
"Piwik",
"::",
"translate",
"(",
"'UserCountry_CannotFindPeclGeoIPDb'",
",",
"array",
"(",
"$",
"quotedDir",
",",
"\"'GeoIP.dat'\"",
",",
"\"'GeoIPCity.dat'\"",
")",
")",
";",
"}",
"return",
"parent",
"::",
"isWorking",
"(",
")",
";",
"}"
] | Returns true if the PECL module that is installed can be successfully used
to get the location of an IP address.
@return bool | [
"Returns",
"true",
"if",
"the",
"PECL",
"module",
"that",
"is",
"installed",
"can",
"be",
"successfully",
"used",
"to",
"get",
"the",
"location",
"of",
"an",
"IP",
"address",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/GeoIp/Pecl.php#L122-L145 |
210,041 | matomo-org/matomo | libs/Zend/Db/Table/Row/Abstract.php | Zend_Db_Table_Row_Abstract.setTable | public function setTable(Zend_Db_Table_Abstract $table = null)
{
if ($table == null) {
$this->_table = null;
$this->_connected = false;
return false;
}
$tableClass = get_class($table);
if (! $table instanceof $this->_tableClass) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The specified Table is of class $tableClass, expecting class to be instance of $this->_tableClass");
}
$this->_table = $table;
$this->_tableClass = $tableClass;
$info = $this->_table->info();
if ($info['cols'] != array_keys($this->_data)) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('The specified Table does not have the same columns as the Row');
}
if (! array_intersect((array) $this->_primary, $info['primary']) == (array) $this->_primary) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The specified Table '$tableClass' does not have the same primary key as the Row");
}
$this->_connected = true;
return true;
} | php | public function setTable(Zend_Db_Table_Abstract $table = null)
{
if ($table == null) {
$this->_table = null;
$this->_connected = false;
return false;
}
$tableClass = get_class($table);
if (! $table instanceof $this->_tableClass) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The specified Table is of class $tableClass, expecting class to be instance of $this->_tableClass");
}
$this->_table = $table;
$this->_tableClass = $tableClass;
$info = $this->_table->info();
if ($info['cols'] != array_keys($this->_data)) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('The specified Table does not have the same columns as the Row');
}
if (! array_intersect((array) $this->_primary, $info['primary']) == (array) $this->_primary) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("The specified Table '$tableClass' does not have the same primary key as the Row");
}
$this->_connected = true;
return true;
} | [
"public",
"function",
"setTable",
"(",
"Zend_Db_Table_Abstract",
"$",
"table",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"table",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"_table",
"=",
"null",
";",
"$",
"this",
"->",
"_connected",
"=",
"false",
";",
"return",
"false",
";",
"}",
"$",
"tableClass",
"=",
"get_class",
"(",
"$",
"table",
")",
";",
"if",
"(",
"!",
"$",
"table",
"instanceof",
"$",
"this",
"->",
"_tableClass",
")",
"{",
"// require_once 'Zend/Db/Table/Row/Exception.php';",
"throw",
"new",
"Zend_Db_Table_Row_Exception",
"(",
"\"The specified Table is of class $tableClass, expecting class to be instance of $this->_tableClass\"",
")",
";",
"}",
"$",
"this",
"->",
"_table",
"=",
"$",
"table",
";",
"$",
"this",
"->",
"_tableClass",
"=",
"$",
"tableClass",
";",
"$",
"info",
"=",
"$",
"this",
"->",
"_table",
"->",
"info",
"(",
")",
";",
"if",
"(",
"$",
"info",
"[",
"'cols'",
"]",
"!=",
"array_keys",
"(",
"$",
"this",
"->",
"_data",
")",
")",
"{",
"// require_once 'Zend/Db/Table/Row/Exception.php';",
"throw",
"new",
"Zend_Db_Table_Row_Exception",
"(",
"'The specified Table does not have the same columns as the Row'",
")",
";",
"}",
"if",
"(",
"!",
"array_intersect",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"_primary",
",",
"$",
"info",
"[",
"'primary'",
"]",
")",
"==",
"(",
"array",
")",
"$",
"this",
"->",
"_primary",
")",
"{",
"// require_once 'Zend/Db/Table/Row/Exception.php';",
"throw",
"new",
"Zend_Db_Table_Row_Exception",
"(",
"\"The specified Table '$tableClass' does not have the same primary key as the Row\"",
")",
";",
"}",
"$",
"this",
"->",
"_connected",
"=",
"true",
";",
"return",
"true",
";",
"}"
] | Set the table object, to re-establish a live connection
to the database for a Row that has been de-serialized.
@param Zend_Db_Table_Abstract $table
@return boolean
@throws Zend_Db_Table_Row_Exception | [
"Set",
"the",
"table",
"object",
"to",
"re",
"-",
"establish",
"a",
"live",
"connection",
"to",
"the",
"database",
"for",
"a",
"Row",
"that",
"has",
"been",
"de",
"-",
"serialized",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Table/Row/Abstract.php#L335-L367 |
210,042 | matomo-org/matomo | libs/Zend/Db/Table/Row/Abstract.php | Zend_Db_Table_Row_Abstract.setFromArray | public function setFromArray(array $data)
{
$data = array_intersect_key($data, $this->_data);
foreach ($data as $columnName => $value) {
$this->__set($columnName, $value);
}
return $this;
} | php | public function setFromArray(array $data)
{
$data = array_intersect_key($data, $this->_data);
foreach ($data as $columnName => $value) {
$this->__set($columnName, $value);
}
return $this;
} | [
"public",
"function",
"setFromArray",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"array_intersect_key",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"_data",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"columnName",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"__set",
"(",
"$",
"columnName",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets all data in the row from an array.
@param array $data
@return Zend_Db_Table_Row_Abstract Provides a fluent interface | [
"Sets",
"all",
"data",
"in",
"the",
"row",
"from",
"an",
"array",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Table/Row/Abstract.php#L666-L675 |
210,043 | matomo-org/matomo | libs/Zend/Db/Table/Row/Abstract.php | Zend_Db_Table_Row_Abstract._refresh | protected function _refresh()
{
$where = $this->_getWhereQuery();
$row = $this->_getTable()->fetchRow($where);
if (null === $row) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('Cannot refresh row as parent is missing');
}
$this->_data = $row->toArray();
$this->_cleanData = $this->_data;
$this->_modifiedFields = array();
} | php | protected function _refresh()
{
$where = $this->_getWhereQuery();
$row = $this->_getTable()->fetchRow($where);
if (null === $row) {
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception('Cannot refresh row as parent is missing');
}
$this->_data = $row->toArray();
$this->_cleanData = $this->_data;
$this->_modifiedFields = array();
} | [
"protected",
"function",
"_refresh",
"(",
")",
"{",
"$",
"where",
"=",
"$",
"this",
"->",
"_getWhereQuery",
"(",
")",
";",
"$",
"row",
"=",
"$",
"this",
"->",
"_getTable",
"(",
")",
"->",
"fetchRow",
"(",
"$",
"where",
")",
";",
"if",
"(",
"null",
"===",
"$",
"row",
")",
"{",
"// require_once 'Zend/Db/Table/Row/Exception.php';",
"throw",
"new",
"Zend_Db_Table_Row_Exception",
"(",
"'Cannot refresh row as parent is missing'",
")",
";",
"}",
"$",
"this",
"->",
"_data",
"=",
"$",
"row",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"_cleanData",
"=",
"$",
"this",
"->",
"_data",
";",
"$",
"this",
"->",
"_modifiedFields",
"=",
"array",
"(",
")",
";",
"}"
] | Refreshes properties from the database.
@return void | [
"Refreshes",
"properties",
"from",
"the",
"database",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Table/Row/Abstract.php#L757-L770 |
210,044 | matomo-org/matomo | libs/Zend/Db/Table/Row/Abstract.php | Zend_Db_Table_Row_Abstract._prepareReference | protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
{
$parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
$map = $dependentTable->getReference($parentTableName, $ruleKey);
if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
$parentInfo = $parentTable->info();
$map[Zend_Db_Table_Abstract::REF_COLUMNS] = array_values((array) $parentInfo['primary']);
}
$map[Zend_Db_Table_Abstract::COLUMNS] = (array) $map[Zend_Db_Table_Abstract::COLUMNS];
$map[Zend_Db_Table_Abstract::REF_COLUMNS] = (array) $map[Zend_Db_Table_Abstract::REF_COLUMNS];
return $map;
} | php | protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
{
$parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
$map = $dependentTable->getReference($parentTableName, $ruleKey);
if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
$parentInfo = $parentTable->info();
$map[Zend_Db_Table_Abstract::REF_COLUMNS] = array_values((array) $parentInfo['primary']);
}
$map[Zend_Db_Table_Abstract::COLUMNS] = (array) $map[Zend_Db_Table_Abstract::COLUMNS];
$map[Zend_Db_Table_Abstract::REF_COLUMNS] = (array) $map[Zend_Db_Table_Abstract::REF_COLUMNS];
return $map;
} | [
"protected",
"function",
"_prepareReference",
"(",
"Zend_Db_Table_Abstract",
"$",
"dependentTable",
",",
"Zend_Db_Table_Abstract",
"$",
"parentTable",
",",
"$",
"ruleKey",
")",
"{",
"$",
"parentTableName",
"=",
"(",
"get_class",
"(",
"$",
"parentTable",
")",
"===",
"'Zend_Db_Table'",
")",
"?",
"$",
"parentTable",
"->",
"getDefinitionConfigName",
"(",
")",
":",
"get_class",
"(",
"$",
"parentTable",
")",
";",
"$",
"map",
"=",
"$",
"dependentTable",
"->",
"getReference",
"(",
"$",
"parentTableName",
",",
"$",
"ruleKey",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"REF_COLUMNS",
"]",
")",
")",
"{",
"$",
"parentInfo",
"=",
"$",
"parentTable",
"->",
"info",
"(",
")",
";",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"REF_COLUMNS",
"]",
"=",
"array_values",
"(",
"(",
"array",
")",
"$",
"parentInfo",
"[",
"'primary'",
"]",
")",
";",
"}",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"COLUMNS",
"]",
"=",
"(",
"array",
")",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"COLUMNS",
"]",
";",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"REF_COLUMNS",
"]",
"=",
"(",
"array",
")",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"REF_COLUMNS",
"]",
";",
"return",
"$",
"map",
";",
"}"
] | Prepares a table reference for lookup.
Ensures all reference keys are set and properly formatted.
@param Zend_Db_Table_Abstract $dependentTable
@param Zend_Db_Table_Abstract $parentTable
@param string $ruleKey
@return array | [
"Prepares",
"a",
"table",
"reference",
"for",
"lookup",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Table/Row/Abstract.php#L842-L856 |
210,045 | matomo-org/matomo | libs/Zend/Db/Table/Row/Abstract.php | Zend_Db_Table_Row_Abstract.findDependentRowset | public function findDependentRowset($dependentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
{
$db = $this->_getTable()->getAdapter();
if (is_string($dependentTable)) {
$dependentTable = $this->_getTableFromString($dependentTable);
}
if (!$dependentTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($dependentTable);
if ($type == 'object') {
$type = get_class($dependentTable);
}
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Dependent table must be a Zend_Db_Table_Abstract, but it is $type");
}
// even if we are interacting between a table defined in a class and a
// table via extension, ensure to persist the definition
if (($tableDefinition = $this->_table->getDefinition()) !== null
&& ($dependentTable->getDefinition() == null)) {
$dependentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
}
if ($select === null) {
$select = $dependentTable->select();
} else {
$select->setTable($dependentTable);
}
$map = $this->_prepareReference($dependentTable, $this->_getTable(), $ruleKey);
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$parentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
$value = $this->_data[$parentColumnName];
// Use adapter from dependent table to ensure correct query construction
$dependentDb = $dependentTable->getAdapter();
$dependentColumnName = $dependentDb->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
$dependentColumn = $dependentDb->quoteIdentifier($dependentColumnName, true);
$dependentInfo = $dependentTable->info();
$type = $dependentInfo[Zend_Db_Table_Abstract::METADATA][$dependentColumnName]['DATA_TYPE'];
$select->where("$dependentColumn = ?", $value, $type);
}
return $dependentTable->fetchAll($select);
} | php | public function findDependentRowset($dependentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
{
$db = $this->_getTable()->getAdapter();
if (is_string($dependentTable)) {
$dependentTable = $this->_getTableFromString($dependentTable);
}
if (!$dependentTable instanceof Zend_Db_Table_Abstract) {
$type = gettype($dependentTable);
if ($type == 'object') {
$type = get_class($dependentTable);
}
// require_once 'Zend/Db/Table/Row/Exception.php';
throw new Zend_Db_Table_Row_Exception("Dependent table must be a Zend_Db_Table_Abstract, but it is $type");
}
// even if we are interacting between a table defined in a class and a
// table via extension, ensure to persist the definition
if (($tableDefinition = $this->_table->getDefinition()) !== null
&& ($dependentTable->getDefinition() == null)) {
$dependentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
}
if ($select === null) {
$select = $dependentTable->select();
} else {
$select->setTable($dependentTable);
}
$map = $this->_prepareReference($dependentTable, $this->_getTable(), $ruleKey);
for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
$parentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
$value = $this->_data[$parentColumnName];
// Use adapter from dependent table to ensure correct query construction
$dependentDb = $dependentTable->getAdapter();
$dependentColumnName = $dependentDb->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
$dependentColumn = $dependentDb->quoteIdentifier($dependentColumnName, true);
$dependentInfo = $dependentTable->info();
$type = $dependentInfo[Zend_Db_Table_Abstract::METADATA][$dependentColumnName]['DATA_TYPE'];
$select->where("$dependentColumn = ?", $value, $type);
}
return $dependentTable->fetchAll($select);
} | [
"public",
"function",
"findDependentRowset",
"(",
"$",
"dependentTable",
",",
"$",
"ruleKey",
"=",
"null",
",",
"Zend_Db_Table_Select",
"$",
"select",
"=",
"null",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"_getTable",
"(",
")",
"->",
"getAdapter",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"dependentTable",
")",
")",
"{",
"$",
"dependentTable",
"=",
"$",
"this",
"->",
"_getTableFromString",
"(",
"$",
"dependentTable",
")",
";",
"}",
"if",
"(",
"!",
"$",
"dependentTable",
"instanceof",
"Zend_Db_Table_Abstract",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"dependentTable",
")",
";",
"if",
"(",
"$",
"type",
"==",
"'object'",
")",
"{",
"$",
"type",
"=",
"get_class",
"(",
"$",
"dependentTable",
")",
";",
"}",
"// require_once 'Zend/Db/Table/Row/Exception.php';",
"throw",
"new",
"Zend_Db_Table_Row_Exception",
"(",
"\"Dependent table must be a Zend_Db_Table_Abstract, but it is $type\"",
")",
";",
"}",
"// even if we are interacting between a table defined in a class and a",
"// table via extension, ensure to persist the definition",
"if",
"(",
"(",
"$",
"tableDefinition",
"=",
"$",
"this",
"->",
"_table",
"->",
"getDefinition",
"(",
")",
")",
"!==",
"null",
"&&",
"(",
"$",
"dependentTable",
"->",
"getDefinition",
"(",
")",
"==",
"null",
")",
")",
"{",
"$",
"dependentTable",
"->",
"setOptions",
"(",
"array",
"(",
"Zend_Db_Table_Abstract",
"::",
"DEFINITION",
"=>",
"$",
"tableDefinition",
")",
")",
";",
"}",
"if",
"(",
"$",
"select",
"===",
"null",
")",
"{",
"$",
"select",
"=",
"$",
"dependentTable",
"->",
"select",
"(",
")",
";",
"}",
"else",
"{",
"$",
"select",
"->",
"setTable",
"(",
"$",
"dependentTable",
")",
";",
"}",
"$",
"map",
"=",
"$",
"this",
"->",
"_prepareReference",
"(",
"$",
"dependentTable",
",",
"$",
"this",
"->",
"_getTable",
"(",
")",
",",
"$",
"ruleKey",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"COLUMNS",
"]",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"parentColumnName",
"=",
"$",
"db",
"->",
"foldCase",
"(",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"REF_COLUMNS",
"]",
"[",
"$",
"i",
"]",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"_data",
"[",
"$",
"parentColumnName",
"]",
";",
"// Use adapter from dependent table to ensure correct query construction",
"$",
"dependentDb",
"=",
"$",
"dependentTable",
"->",
"getAdapter",
"(",
")",
";",
"$",
"dependentColumnName",
"=",
"$",
"dependentDb",
"->",
"foldCase",
"(",
"$",
"map",
"[",
"Zend_Db_Table_Abstract",
"::",
"COLUMNS",
"]",
"[",
"$",
"i",
"]",
")",
";",
"$",
"dependentColumn",
"=",
"$",
"dependentDb",
"->",
"quoteIdentifier",
"(",
"$",
"dependentColumnName",
",",
"true",
")",
";",
"$",
"dependentInfo",
"=",
"$",
"dependentTable",
"->",
"info",
"(",
")",
";",
"$",
"type",
"=",
"$",
"dependentInfo",
"[",
"Zend_Db_Table_Abstract",
"::",
"METADATA",
"]",
"[",
"$",
"dependentColumnName",
"]",
"[",
"'DATA_TYPE'",
"]",
";",
"$",
"select",
"->",
"where",
"(",
"\"$dependentColumn = ?\"",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"dependentTable",
"->",
"fetchAll",
"(",
"$",
"select",
")",
";",
"}"
] | Query a dependent table to retrieve rows matching the current row.
@param string|Zend_Db_Table_Abstract $dependentTable
@param string OPTIONAL $ruleKey
@param Zend_Db_Table_Select OPTIONAL $select
@return Zend_Db_Table_Rowset_Abstract Query result from $dependentTable
@throws Zend_Db_Table_Row_Exception If $dependentTable is not a table or is not loadable. | [
"Query",
"a",
"dependent",
"table",
"to",
"retrieve",
"rows",
"matching",
"the",
"current",
"row",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Table/Row/Abstract.php#L867-L912 |
210,046 | matomo-org/matomo | core/Period/Range.php | Range.getPrettyString | public function getPrettyString()
{
$out = $this->translator->translate('General_DateRangeFromTo', array($this->getDateStart()->toString(), $this->getDateEnd()->toString()));
return $out;
} | php | public function getPrettyString()
{
$out = $this->translator->translate('General_DateRangeFromTo', array($this->getDateStart()->toString(), $this->getDateEnd()->toString()));
return $out;
} | [
"public",
"function",
"getPrettyString",
"(",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"'General_DateRangeFromTo'",
",",
"array",
"(",
"$",
"this",
"->",
"getDateStart",
"(",
")",
"->",
"toString",
"(",
")",
",",
"$",
"this",
"->",
"getDateEnd",
"(",
")",
"->",
"toString",
"(",
")",
")",
")",
";",
"return",
"$",
"out",
";",
"}"
] | Returns the current period as a string.
@return string | [
"Returns",
"the",
"current",
"period",
"as",
"a",
"string",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Range.php#L166-L170 |
210,047 | matomo-org/matomo | core/Period/Range.php | Range.generate | protected function generate()
{
if ($this->subperiodsProcessed) {
return;
}
$this->loadAllFromCache();
if ($this->subperiodsProcessed) {
return;
}
parent::generate();
if (preg_match('/(last|previous)([0-9]*)/', $this->strDate, $regs)) {
$lastN = $regs[2];
$lastOrPrevious = $regs[1];
if (!is_null($this->defaultEndDate)) {
$defaultEndDate = $this->defaultEndDate;
} else {
$defaultEndDate = $this->today;
}
$period = $this->strPeriod;
if ($period == 'range') {
$period = 'day';
}
if ($lastOrPrevious == 'last') {
$endDate = $defaultEndDate;
} elseif ($lastOrPrevious == 'previous') {
if ('month' == $period) {
$endDate = $defaultEndDate->subMonth(1);
} else {
$endDate = $defaultEndDate->subPeriod(1, $period);
}
}
$lastN = $this->getMaxN($lastN);
// last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
$lastN--;
if ($lastN < 0) {
$lastN = 0;
}
$startDate = $endDate->addPeriod(-1 * $lastN, $period);
} elseif ($dateRange = Range::parseDateRange($this->strDate)) {
$strDateStart = $dateRange[1];
$strDateEnd = $dateRange[2];
$startDate = Date::factory($strDateStart);
// we set the timezone in the Date object only if the date is relative eg. 'today', 'yesterday', 'now'
$timezone = null;
if (strpos($strDateEnd, '-') === false) {
$timezone = $this->timezone;
}
$endDate = Date::factory($strDateEnd, $timezone);
} else {
throw new Exception($this->translator->translate('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\'')));
}
if ($this->strPeriod != 'range') {
$this->fillArraySubPeriods($startDate, $endDate, $this->strPeriod);
$this->cacheAll();
return;
}
$this->processOptimalSubperiods($startDate, $endDate);
// When period=range, we want End Date to be the actual specified end date,
// rather than the end of the month / week / whatever is used for processing this range
$this->endDate = $endDate;
$this->cacheAll();
} | php | protected function generate()
{
if ($this->subperiodsProcessed) {
return;
}
$this->loadAllFromCache();
if ($this->subperiodsProcessed) {
return;
}
parent::generate();
if (preg_match('/(last|previous)([0-9]*)/', $this->strDate, $regs)) {
$lastN = $regs[2];
$lastOrPrevious = $regs[1];
if (!is_null($this->defaultEndDate)) {
$defaultEndDate = $this->defaultEndDate;
} else {
$defaultEndDate = $this->today;
}
$period = $this->strPeriod;
if ($period == 'range') {
$period = 'day';
}
if ($lastOrPrevious == 'last') {
$endDate = $defaultEndDate;
} elseif ($lastOrPrevious == 'previous') {
if ('month' == $period) {
$endDate = $defaultEndDate->subMonth(1);
} else {
$endDate = $defaultEndDate->subPeriod(1, $period);
}
}
$lastN = $this->getMaxN($lastN);
// last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
$lastN--;
if ($lastN < 0) {
$lastN = 0;
}
$startDate = $endDate->addPeriod(-1 * $lastN, $period);
} elseif ($dateRange = Range::parseDateRange($this->strDate)) {
$strDateStart = $dateRange[1];
$strDateEnd = $dateRange[2];
$startDate = Date::factory($strDateStart);
// we set the timezone in the Date object only if the date is relative eg. 'today', 'yesterday', 'now'
$timezone = null;
if (strpos($strDateEnd, '-') === false) {
$timezone = $this->timezone;
}
$endDate = Date::factory($strDateEnd, $timezone);
} else {
throw new Exception($this->translator->translate('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\'')));
}
if ($this->strPeriod != 'range') {
$this->fillArraySubPeriods($startDate, $endDate, $this->strPeriod);
$this->cacheAll();
return;
}
$this->processOptimalSubperiods($startDate, $endDate);
// When period=range, we want End Date to be the actual specified end date,
// rather than the end of the month / week / whatever is used for processing this range
$this->endDate = $endDate;
$this->cacheAll();
} | [
"protected",
"function",
"generate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"subperiodsProcessed",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"loadAllFromCache",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"subperiodsProcessed",
")",
"{",
"return",
";",
"}",
"parent",
"::",
"generate",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/(last|previous)([0-9]*)/'",
",",
"$",
"this",
"->",
"strDate",
",",
"$",
"regs",
")",
")",
"{",
"$",
"lastN",
"=",
"$",
"regs",
"[",
"2",
"]",
";",
"$",
"lastOrPrevious",
"=",
"$",
"regs",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"defaultEndDate",
")",
")",
"{",
"$",
"defaultEndDate",
"=",
"$",
"this",
"->",
"defaultEndDate",
";",
"}",
"else",
"{",
"$",
"defaultEndDate",
"=",
"$",
"this",
"->",
"today",
";",
"}",
"$",
"period",
"=",
"$",
"this",
"->",
"strPeriod",
";",
"if",
"(",
"$",
"period",
"==",
"'range'",
")",
"{",
"$",
"period",
"=",
"'day'",
";",
"}",
"if",
"(",
"$",
"lastOrPrevious",
"==",
"'last'",
")",
"{",
"$",
"endDate",
"=",
"$",
"defaultEndDate",
";",
"}",
"elseif",
"(",
"$",
"lastOrPrevious",
"==",
"'previous'",
")",
"{",
"if",
"(",
"'month'",
"==",
"$",
"period",
")",
"{",
"$",
"endDate",
"=",
"$",
"defaultEndDate",
"->",
"subMonth",
"(",
"1",
")",
";",
"}",
"else",
"{",
"$",
"endDate",
"=",
"$",
"defaultEndDate",
"->",
"subPeriod",
"(",
"1",
",",
"$",
"period",
")",
";",
"}",
"}",
"$",
"lastN",
"=",
"$",
"this",
"->",
"getMaxN",
"(",
"$",
"lastN",
")",
";",
"// last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc",
"$",
"lastN",
"--",
";",
"if",
"(",
"$",
"lastN",
"<",
"0",
")",
"{",
"$",
"lastN",
"=",
"0",
";",
"}",
"$",
"startDate",
"=",
"$",
"endDate",
"->",
"addPeriod",
"(",
"-",
"1",
"*",
"$",
"lastN",
",",
"$",
"period",
")",
";",
"}",
"elseif",
"(",
"$",
"dateRange",
"=",
"Range",
"::",
"parseDateRange",
"(",
"$",
"this",
"->",
"strDate",
")",
")",
"{",
"$",
"strDateStart",
"=",
"$",
"dateRange",
"[",
"1",
"]",
";",
"$",
"strDateEnd",
"=",
"$",
"dateRange",
"[",
"2",
"]",
";",
"$",
"startDate",
"=",
"Date",
"::",
"factory",
"(",
"$",
"strDateStart",
")",
";",
"// we set the timezone in the Date object only if the date is relative eg. 'today', 'yesterday', 'now'",
"$",
"timezone",
"=",
"null",
";",
"if",
"(",
"strpos",
"(",
"$",
"strDateEnd",
",",
"'-'",
")",
"===",
"false",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"timezone",
";",
"}",
"$",
"endDate",
"=",
"Date",
"::",
"factory",
"(",
"$",
"strDateEnd",
",",
"$",
"timezone",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"'General_ExceptionInvalidDateRange'",
",",
"array",
"(",
"$",
"this",
"->",
"strDate",
",",
"' \\'lastN\\', \\'previousN\\', \\'YYYY-MM-DD,YYYY-MM-DD\\''",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"strPeriod",
"!=",
"'range'",
")",
"{",
"$",
"this",
"->",
"fillArraySubPeriods",
"(",
"$",
"startDate",
",",
"$",
"endDate",
",",
"$",
"this",
"->",
"strPeriod",
")",
";",
"$",
"this",
"->",
"cacheAll",
"(",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"processOptimalSubperiods",
"(",
"$",
"startDate",
",",
"$",
"endDate",
")",
";",
"// When period=range, we want End Date to be the actual specified end date,",
"// rather than the end of the month / week / whatever is used for processing this range",
"$",
"this",
"->",
"endDate",
"=",
"$",
"endDate",
";",
"$",
"this",
"->",
"cacheAll",
"(",
")",
";",
"}"
] | Generates the subperiods
@throws Exception | [
"Generates",
"the",
"subperiods"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Range.php#L209-L282 |
210,048 | matomo-org/matomo | core/Period/Range.php | Range.parseDateRange | public static function parseDateRange($dateString)
{
$matched = preg_match('/^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),(([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})|today|now|yesterday)$/D', trim($dateString), $regs);
if (empty($matched)) {
return false;
}
return $regs;
} | php | public static function parseDateRange($dateString)
{
$matched = preg_match('/^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),(([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})|today|now|yesterday)$/D', trim($dateString), $regs);
if (empty($matched)) {
return false;
}
return $regs;
} | [
"public",
"static",
"function",
"parseDateRange",
"(",
"$",
"dateString",
")",
"{",
"$",
"matched",
"=",
"preg_match",
"(",
"'/^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),(([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})|today|now|yesterday)$/D'",
",",
"trim",
"(",
"$",
"dateString",
")",
",",
"$",
"regs",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"matched",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"regs",
";",
"}"
] | Given a date string, returns `false` if not a date range,
or returns the array containing start and end dates.
@param string $dateString
@return mixed array(1 => dateStartString, 2 => dateEndString) or `false` if the input was not a date range. | [
"Given",
"a",
"date",
"string",
"returns",
"false",
"if",
"not",
"a",
"date",
"range",
"or",
"returns",
"the",
"array",
"containing",
"start",
"and",
"end",
"dates",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Range.php#L291-L300 |
210,049 | matomo-org/matomo | core/Period/Range.php | Range.fillArraySubPeriods | protected function fillArraySubPeriods($startDate, $endDate, $period)
{
$arrayPeriods = array();
$endSubperiod = Period\Factory::build($period, $endDate);
$arrayPeriods[] = $endSubperiod;
// set end date to start of end period since we're comparing against start date.
$endDate = $endSubperiod->getDateStart();
while ($endDate->isLater($startDate)) {
$endDate = $endDate->addPeriod(-1, $period);
$subPeriod = Period\Factory::build($period, $endDate);
$arrayPeriods[] = $subPeriod;
}
$arrayPeriods = array_reverse($arrayPeriods);
foreach ($arrayPeriods as $period) {
$this->addSubperiod($period);
}
} | php | protected function fillArraySubPeriods($startDate, $endDate, $period)
{
$arrayPeriods = array();
$endSubperiod = Period\Factory::build($period, $endDate);
$arrayPeriods[] = $endSubperiod;
// set end date to start of end period since we're comparing against start date.
$endDate = $endSubperiod->getDateStart();
while ($endDate->isLater($startDate)) {
$endDate = $endDate->addPeriod(-1, $period);
$subPeriod = Period\Factory::build($period, $endDate);
$arrayPeriods[] = $subPeriod;
}
$arrayPeriods = array_reverse($arrayPeriods);
foreach ($arrayPeriods as $period) {
$this->addSubperiod($period);
}
} | [
"protected",
"function",
"fillArraySubPeriods",
"(",
"$",
"startDate",
",",
"$",
"endDate",
",",
"$",
"period",
")",
"{",
"$",
"arrayPeriods",
"=",
"array",
"(",
")",
";",
"$",
"endSubperiod",
"=",
"Period",
"\\",
"Factory",
"::",
"build",
"(",
"$",
"period",
",",
"$",
"endDate",
")",
";",
"$",
"arrayPeriods",
"[",
"]",
"=",
"$",
"endSubperiod",
";",
"// set end date to start of end period since we're comparing against start date.",
"$",
"endDate",
"=",
"$",
"endSubperiod",
"->",
"getDateStart",
"(",
")",
";",
"while",
"(",
"$",
"endDate",
"->",
"isLater",
"(",
"$",
"startDate",
")",
")",
"{",
"$",
"endDate",
"=",
"$",
"endDate",
"->",
"addPeriod",
"(",
"-",
"1",
",",
"$",
"period",
")",
";",
"$",
"subPeriod",
"=",
"Period",
"\\",
"Factory",
"::",
"build",
"(",
"$",
"period",
",",
"$",
"endDate",
")",
";",
"$",
"arrayPeriods",
"[",
"]",
"=",
"$",
"subPeriod",
";",
"}",
"$",
"arrayPeriods",
"=",
"array_reverse",
"(",
"$",
"arrayPeriods",
")",
";",
"foreach",
"(",
"$",
"arrayPeriods",
"as",
"$",
"period",
")",
"{",
"$",
"this",
"->",
"addSubperiod",
"(",
"$",
"period",
")",
";",
"}",
"}"
] | Adds new subperiods
@param Date $startDate
@param Date $endDate
@param string $period | [
"Adds",
"new",
"subperiods"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Range.php#L409-L426 |
210,050 | matomo-org/matomo | core/Period/Range.php | Range.getDateXPeriodsAgo | public static function getDateXPeriodsAgo($subXPeriods, $date = false, $period = false)
{
if ($date === false) {
$date = Common::getRequestVar('date');
}
if ($period === false) {
$period = Common::getRequestVar('period');
}
if (365 == $subXPeriods && 'day' == $period && Date::today()->isLeapYear()) {
$subXPeriods = 366;
}
// can't get the last date for range periods & dates that use lastN/previousN
$strLastDate = false;
$lastPeriod = false;
if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
if (strpos($date, ',')) {
// date in the form of 2011-01-01,2011-02-02
$rangePeriod = new Range($period, $date);
$lastStartDate = $rangePeriod->getDateStart()->subPeriod($subXPeriods, $period);
$lastEndDate = $rangePeriod->getDateEnd()->subPeriod($subXPeriods, $period);
$strLastDate = "$lastStartDate,$lastEndDate";
} else {
$lastPeriod = Date::factory($date)->subPeriod($subXPeriods, $period);
$strLastDate = $lastPeriod->toString();
}
}
return array($strLastDate, $lastPeriod);
} | php | public static function getDateXPeriodsAgo($subXPeriods, $date = false, $period = false)
{
if ($date === false) {
$date = Common::getRequestVar('date');
}
if ($period === false) {
$period = Common::getRequestVar('period');
}
if (365 == $subXPeriods && 'day' == $period && Date::today()->isLeapYear()) {
$subXPeriods = 366;
}
// can't get the last date for range periods & dates that use lastN/previousN
$strLastDate = false;
$lastPeriod = false;
if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
if (strpos($date, ',')) {
// date in the form of 2011-01-01,2011-02-02
$rangePeriod = new Range($period, $date);
$lastStartDate = $rangePeriod->getDateStart()->subPeriod($subXPeriods, $period);
$lastEndDate = $rangePeriod->getDateEnd()->subPeriod($subXPeriods, $period);
$strLastDate = "$lastStartDate,$lastEndDate";
} else {
$lastPeriod = Date::factory($date)->subPeriod($subXPeriods, $period);
$strLastDate = $lastPeriod->toString();
}
}
return array($strLastDate, $lastPeriod);
} | [
"public",
"static",
"function",
"getDateXPeriodsAgo",
"(",
"$",
"subXPeriods",
",",
"$",
"date",
"=",
"false",
",",
"$",
"period",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"date",
"===",
"false",
")",
"{",
"$",
"date",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'date'",
")",
";",
"}",
"if",
"(",
"$",
"period",
"===",
"false",
")",
"{",
"$",
"period",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'period'",
")",
";",
"}",
"if",
"(",
"365",
"==",
"$",
"subXPeriods",
"&&",
"'day'",
"==",
"$",
"period",
"&&",
"Date",
"::",
"today",
"(",
")",
"->",
"isLeapYear",
"(",
")",
")",
"{",
"$",
"subXPeriods",
"=",
"366",
";",
"}",
"// can't get the last date for range periods & dates that use lastN/previousN",
"$",
"strLastDate",
"=",
"false",
";",
"$",
"lastPeriod",
"=",
"false",
";",
"if",
"(",
"$",
"period",
"!=",
"'range'",
"&&",
"!",
"preg_match",
"(",
"'/(last|previous)([0-9]*)/'",
",",
"$",
"date",
",",
"$",
"regs",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"date",
",",
"','",
")",
")",
"{",
"// date in the form of 2011-01-01,2011-02-02",
"$",
"rangePeriod",
"=",
"new",
"Range",
"(",
"$",
"period",
",",
"$",
"date",
")",
";",
"$",
"lastStartDate",
"=",
"$",
"rangePeriod",
"->",
"getDateStart",
"(",
")",
"->",
"subPeriod",
"(",
"$",
"subXPeriods",
",",
"$",
"period",
")",
";",
"$",
"lastEndDate",
"=",
"$",
"rangePeriod",
"->",
"getDateEnd",
"(",
")",
"->",
"subPeriod",
"(",
"$",
"subXPeriods",
",",
"$",
"period",
")",
";",
"$",
"strLastDate",
"=",
"\"$lastStartDate,$lastEndDate\"",
";",
"}",
"else",
"{",
"$",
"lastPeriod",
"=",
"Date",
"::",
"factory",
"(",
"$",
"date",
")",
"->",
"subPeriod",
"(",
"$",
"subXPeriods",
",",
"$",
"period",
")",
";",
"$",
"strLastDate",
"=",
"$",
"lastPeriod",
"->",
"toString",
"(",
")",
";",
"}",
"}",
"return",
"array",
"(",
"$",
"strLastDate",
",",
"$",
"lastPeriod",
")",
";",
"}"
] | Returns the date that is X periods before the supplied date.
@param bool|string $date The date to get the last date of.
@param bool|string $period The period to use (either 'day', 'week', 'month', 'year');
@param int $subXPeriods How many periods in the past the date should be, for instance 1 or 7.
If sub period is 365 days and the current year is a leap year we assume you want to get the
day one year ago and change the value to 366 days therefore.
@return array An array with two elements, a string for the date before $date and
a Period instance for the period before $date.
@api | [
"Returns",
"the",
"date",
"that",
"is",
"X",
"periods",
"before",
"the",
"supplied",
"date",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Range.php#L456-L490 |
210,051 | matomo-org/matomo | core/Period/Range.php | Range.getRelativeToEndDate | public static function getRelativeToEndDate($period, $lastN, $endDate, $site)
{
$timezone = $site->getTimezone();
$last30Relative = new Range($period, $lastN, $timezone);
if (strpos($endDate, '-') === false) {
// eg today, yesterday, ... needs the timezone
$endDate = Date::factoryInTimezone($endDate, $timezone);
} else {
$endDate = Date::factory($endDate);
}
$last30Relative->setDefaultEndDate($endDate);
$date = $last30Relative->getDateStart()->toString() . "," . $last30Relative->getDateEnd()->toString();
return $date;
} | php | public static function getRelativeToEndDate($period, $lastN, $endDate, $site)
{
$timezone = $site->getTimezone();
$last30Relative = new Range($period, $lastN, $timezone);
if (strpos($endDate, '-') === false) {
// eg today, yesterday, ... needs the timezone
$endDate = Date::factoryInTimezone($endDate, $timezone);
} else {
$endDate = Date::factory($endDate);
}
$last30Relative->setDefaultEndDate($endDate);
$date = $last30Relative->getDateStart()->toString() . "," . $last30Relative->getDateEnd()->toString();
return $date;
} | [
"public",
"static",
"function",
"getRelativeToEndDate",
"(",
"$",
"period",
",",
"$",
"lastN",
",",
"$",
"endDate",
",",
"$",
"site",
")",
"{",
"$",
"timezone",
"=",
"$",
"site",
"->",
"getTimezone",
"(",
")",
";",
"$",
"last30Relative",
"=",
"new",
"Range",
"(",
"$",
"period",
",",
"$",
"lastN",
",",
"$",
"timezone",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"endDate",
",",
"'-'",
")",
"===",
"false",
")",
"{",
"// eg today, yesterday, ... needs the timezone",
"$",
"endDate",
"=",
"Date",
"::",
"factoryInTimezone",
"(",
"$",
"endDate",
",",
"$",
"timezone",
")",
";",
"}",
"else",
"{",
"$",
"endDate",
"=",
"Date",
"::",
"factory",
"(",
"$",
"endDate",
")",
";",
"}",
"$",
"last30Relative",
"->",
"setDefaultEndDate",
"(",
"$",
"endDate",
")",
";",
"$",
"date",
"=",
"$",
"last30Relative",
"->",
"getDateStart",
"(",
")",
"->",
"toString",
"(",
")",
".",
"\",\"",
".",
"$",
"last30Relative",
"->",
"getDateEnd",
"(",
")",
"->",
"toString",
"(",
")",
";",
"return",
"$",
"date",
";",
"}"
] | Returns a date range string given a period type, end date and number of periods
the range spans over.
@param string $period The sub period type, `'day'`, `'week'`, `'month'` and `'year'`.
@param int $lastN The number of periods of type `$period` that the result range should
span.
@param string $endDate The desired end date of the range.
@param \Piwik\Site $site The site whose timezone should be used.
@return string The date range string, eg, `'2012-01-02,2013-01-02'`.
@api | [
"Returns",
"a",
"date",
"range",
"string",
"given",
"a",
"period",
"type",
"end",
"date",
"and",
"number",
"of",
"periods",
"the",
"range",
"spans",
"over",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Range.php#L504-L519 |
210,052 | matomo-org/matomo | core/Period/Range.php | Range.getRangeString | public function getRangeString()
{
$dateStart = $this->getDateStart();
$dateEnd = $this->getDateEnd();
return $dateStart->toString("Y-m-d") . "," . $dateEnd->toString("Y-m-d");
} | php | public function getRangeString()
{
$dateStart = $this->getDateStart();
$dateEnd = $this->getDateEnd();
return $dateStart->toString("Y-m-d") . "," . $dateEnd->toString("Y-m-d");
} | [
"public",
"function",
"getRangeString",
"(",
")",
"{",
"$",
"dateStart",
"=",
"$",
"this",
"->",
"getDateStart",
"(",
")",
";",
"$",
"dateEnd",
"=",
"$",
"this",
"->",
"getDateEnd",
"(",
")",
";",
"return",
"$",
"dateStart",
"->",
"toString",
"(",
"\"Y-m-d\"",
")",
".",
"\",\"",
".",
"$",
"dateEnd",
"->",
"toString",
"(",
"\"Y-m-d\"",
")",
";",
"}"
] | Returns the date range string comprising two dates
@return string eg, `'2012-01-01,2012-01-31'`. | [
"Returns",
"the",
"date",
"range",
"string",
"comprising",
"two",
"dates"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Period/Range.php#L538-L544 |
210,053 | matomo-org/matomo | libs/Zend/Validate/Abstract.php | Zend_Validate_Abstract.setMessages | public function setMessages(array $messages)
{
foreach ($messages as $key => $message) {
$this->setMessage($message, $key);
}
return $this;
} | php | public function setMessages(array $messages)
{
foreach ($messages as $key => $message) {
$this->setMessage($message, $key);
}
return $this;
} | [
"public",
"function",
"setMessages",
"(",
"array",
"$",
"messages",
")",
"{",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"key",
"=>",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"setMessage",
"(",
"$",
"message",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets validation failure message templates given as an array, where the array keys are the message keys,
and the array values are the message template strings.
@param array $messages
@return Zend_Validate_Abstract | [
"Sets",
"validation",
"failure",
"message",
"templates",
"given",
"as",
"an",
"array",
"where",
"the",
"array",
"keys",
"are",
"the",
"message",
"keys",
"and",
"the",
"array",
"values",
"are",
"the",
"message",
"template",
"strings",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Validate/Abstract.php#L167-L173 |
210,054 | matomo-org/matomo | libs/Zend/Validate/Abstract.php | Zend_Validate_Abstract.getTranslator | public function getTranslator()
{
if ($this->translatorIsDisabled()) {
return null;
}
if (null === $this->_translator) {
return self::getDefaultTranslator();
}
return $this->_translator;
} | php | public function getTranslator()
{
if ($this->translatorIsDisabled()) {
return null;
}
if (null === $this->_translator) {
return self::getDefaultTranslator();
}
return $this->_translator;
} | [
"public",
"function",
"getTranslator",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"translatorIsDisabled",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"_translator",
")",
"{",
"return",
"self",
"::",
"getDefaultTranslator",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_translator",
";",
"}"
] | Return translation object
@return Zend_Translate_Adapter|null | [
"Return",
"translation",
"object"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Validate/Abstract.php#L342-L353 |
210,055 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.parseAttributes | protected static function parseAttributes($attrString)
{
$attributes = array();
if (preg_match_all(
"/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/",
$attrString,
$regs
)) {
for ($i = 0; $i < count($regs[1]); $i++) {
$name = trim($regs[1][$i]);
$check = trim($regs[0][$i]);
$value = trim($regs[7][$i]);
if ($name == $check) {
$attributes[strtolower($name)] = strtolower($name);
} else {
if (!empty($value) && ($value[0] == '\'' || $value[0] == '"')) {
$value = substr($value, 1, -1);
}
$attributes[strtolower($name)] = $value;
}
}
}
return $attributes;
} | php | protected static function parseAttributes($attrString)
{
$attributes = array();
if (preg_match_all(
"/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/",
$attrString,
$regs
)) {
for ($i = 0; $i < count($regs[1]); $i++) {
$name = trim($regs[1][$i]);
$check = trim($regs[0][$i]);
$value = trim($regs[7][$i]);
if ($name == $check) {
$attributes[strtolower($name)] = strtolower($name);
} else {
if (!empty($value) && ($value[0] == '\'' || $value[0] == '"')) {
$value = substr($value, 1, -1);
}
$attributes[strtolower($name)] = $value;
}
}
}
return $attributes;
} | [
"protected",
"static",
"function",
"parseAttributes",
"(",
"$",
"attrString",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"\"/(([A-Za-z_:]|[^\\\\x00-\\\\x7F])([A-Za-z0-9_:.-]|[^\\\\x00-\\\\x7F])*)\"",
".",
"\"([ \\\\n\\\\t\\\\r]+)?(=([ \\\\n\\\\t\\\\r]+)?(\\\"[^\\\"]*\\\"|'[^']*'|[^ \\\\n\\\\t\\\\r]*))?/\"",
",",
"$",
"attrString",
",",
"$",
"regs",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"regs",
"[",
"1",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"$",
"regs",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
";",
"$",
"check",
"=",
"trim",
"(",
"$",
"regs",
"[",
"0",
"]",
"[",
"$",
"i",
"]",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"regs",
"[",
"7",
"]",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"name",
"==",
"$",
"check",
")",
"{",
"$",
"attributes",
"[",
"strtolower",
"(",
"$",
"name",
")",
"]",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"(",
"$",
"value",
"[",
"0",
"]",
"==",
"'\\''",
"||",
"$",
"value",
"[",
"0",
"]",
"==",
"'\"'",
")",
")",
"{",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"1",
",",
"-",
"1",
")",
";",
"}",
"$",
"attributes",
"[",
"strtolower",
"(",
"$",
"name",
")",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Parses the HTML attributes given as string
@param string HTML attribute string
@return array An associative aray of attributes | [
"Parses",
"the",
"HTML",
"attributes",
"given",
"as",
"string"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L145-L169 |
210,056 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.prepareAttributes | protected static function prepareAttributes($attributes)
{
$prepared = array();
if (is_string($attributes)) {
return self::parseAttributes($attributes);
} elseif (is_array($attributes)) {
foreach ($attributes as $key => $value) {
if (is_int($key)) {
$key = strtolower($value);
$prepared[$key] = $key;
} else {
$prepared[strtolower($key)] = (string)$value;
}
}
}
return $prepared;
} | php | protected static function prepareAttributes($attributes)
{
$prepared = array();
if (is_string($attributes)) {
return self::parseAttributes($attributes);
} elseif (is_array($attributes)) {
foreach ($attributes as $key => $value) {
if (is_int($key)) {
$key = strtolower($value);
$prepared[$key] = $key;
} else {
$prepared[strtolower($key)] = (string)$value;
}
}
}
return $prepared;
} | [
"protected",
"static",
"function",
"prepareAttributes",
"(",
"$",
"attributes",
")",
"{",
"$",
"prepared",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"attributes",
")",
")",
"{",
"return",
"self",
"::",
"parseAttributes",
"(",
"$",
"attributes",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"$",
"prepared",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
";",
"}",
"else",
"{",
"$",
"prepared",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"prepared",
";",
"}"
] | Creates a valid attribute array from either a string or an array
@param mixed Array of attributes or HTML attribute string
@return array An associative aray of attributes | [
"Creates",
"a",
"valid",
"attribute",
"array",
"from",
"either",
"a",
"string",
"or",
"an",
"array"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L177-L194 |
210,057 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.getAttributesString | protected static function getAttributesString($attributes)
{
$str = '';
if (is_array($attributes)) {
$charset = self::getOption('charset');
foreach ($attributes as $key => $value) {
$str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES, $charset) . '"';
}
}
return $str;
} | php | protected static function getAttributesString($attributes)
{
$str = '';
if (is_array($attributes)) {
$charset = self::getOption('charset');
foreach ($attributes as $key => $value) {
$str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES, $charset) . '"';
}
}
return $str;
} | [
"protected",
"static",
"function",
"getAttributesString",
"(",
"$",
"attributes",
")",
"{",
"$",
"str",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"charset",
"=",
"self",
"::",
"getOption",
"(",
"'charset'",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"str",
".=",
"' '",
".",
"$",
"key",
".",
"'=\"'",
".",
"htmlspecialchars",
"(",
"$",
"value",
",",
"ENT_QUOTES",
",",
"$",
"charset",
")",
".",
"'\"'",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] | Creates HTML attribute string from array
@param array Attribute array
@return string Attribute string | [
"Creates",
"HTML",
"attribute",
"string",
"from",
"array"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L213-L223 |
210,058 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.setAttribute | public function setAttribute($name, $value = null)
{
$name = strtolower($name);
if (is_null($value)) {
$value = $name;
}
if (in_array($name, $this->watchedAttributes)) {
$this->onAttributeChange($name, $value);
} else {
$this->attributes[$name] = (string)$value;
}
return $this;
} | php | public function setAttribute($name, $value = null)
{
$name = strtolower($name);
if (is_null($value)) {
$value = $name;
}
if (in_array($name, $this->watchedAttributes)) {
$this->onAttributeChange($name, $value);
} else {
$this->attributes[$name] = (string)$value;
}
return $this;
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"name",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"watchedAttributes",
")",
")",
"{",
"$",
"this",
"->",
"onAttributeChange",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"name",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the value of the attribute
@param string Attribute name
@param string Attribute value (will be set to $name if omitted)
@return HTML_Common2 | [
"Sets",
"the",
"value",
"of",
"the",
"attribute"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L242-L254 |
210,059 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.setAttributes | public function setAttributes($attributes)
{
$attributes = self::prepareAttributes($attributes);
$watched = array();
foreach ($this->watchedAttributes as $watchedKey) {
if (isset($attributes[$watchedKey])) {
$this->setAttribute($watchedKey, $attributes[$watchedKey]);
unset($attributes[$watchedKey]);
} else {
$this->removeAttribute($watchedKey);
}
if (isset($this->attributes[$watchedKey])) {
$watched[$watchedKey] = $this->attributes[$watchedKey];
}
}
$this->attributes = array_merge($watched, $attributes);
return $this;
} | php | public function setAttributes($attributes)
{
$attributes = self::prepareAttributes($attributes);
$watched = array();
foreach ($this->watchedAttributes as $watchedKey) {
if (isset($attributes[$watchedKey])) {
$this->setAttribute($watchedKey, $attributes[$watchedKey]);
unset($attributes[$watchedKey]);
} else {
$this->removeAttribute($watchedKey);
}
if (isset($this->attributes[$watchedKey])) {
$watched[$watchedKey] = $this->attributes[$watchedKey];
}
}
$this->attributes = array_merge($watched, $attributes);
return $this;
} | [
"public",
"function",
"setAttributes",
"(",
"$",
"attributes",
")",
"{",
"$",
"attributes",
"=",
"self",
"::",
"prepareAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"watched",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"watchedAttributes",
"as",
"$",
"watchedKey",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"$",
"watchedKey",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"$",
"watchedKey",
",",
"$",
"attributes",
"[",
"$",
"watchedKey",
"]",
")",
";",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"watchedKey",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"removeAttribute",
"(",
"$",
"watchedKey",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"watchedKey",
"]",
")",
")",
"{",
"$",
"watched",
"[",
"$",
"watchedKey",
"]",
"=",
"$",
"this",
"->",
"attributes",
"[",
"$",
"watchedKey",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"attributes",
"=",
"array_merge",
"(",
"$",
"watched",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the attributes
@param mixed Array of attribute 'name' => 'value' pairs or HTML attribute string
@return HTML_Common2 | [
"Sets",
"the",
"attributes"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L274-L291 |
210,060 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.getAttributes | public function getAttributes($asString = false)
{
if ($asString) {
return self::getAttributesString($this->attributes);
} else {
return $this->attributes;
}
} | php | public function getAttributes($asString = false)
{
if ($asString) {
return self::getAttributesString($this->attributes);
} else {
return $this->attributes;
}
} | [
"public",
"function",
"getAttributes",
"(",
"$",
"asString",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"asString",
")",
"{",
"return",
"self",
"::",
"getAttributesString",
"(",
"$",
"this",
"->",
"attributes",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"attributes",
";",
"}",
"}"
] | Returns the attribute array or string
@param bool Whether to return attributes as string
@return mixed Either an array or string of attributes | [
"Returns",
"the",
"attribute",
"array",
"or",
"string"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L299-L306 |
210,061 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.mergeAttributes | public function mergeAttributes($attributes)
{
$attributes = self::prepareAttributes($attributes);
foreach ($this->watchedAttributes as $watchedKey) {
if (isset($attributes[$watchedKey])) {
$this->onAttributeChange($watchedKey, $attributes[$watchedKey]);
unset($attributes[$watchedKey]);
}
}
$this->attributes = array_merge($this->attributes, $attributes);
return $this;
} | php | public function mergeAttributes($attributes)
{
$attributes = self::prepareAttributes($attributes);
foreach ($this->watchedAttributes as $watchedKey) {
if (isset($attributes[$watchedKey])) {
$this->onAttributeChange($watchedKey, $attributes[$watchedKey]);
unset($attributes[$watchedKey]);
}
}
$this->attributes = array_merge($this->attributes, $attributes);
return $this;
} | [
"public",
"function",
"mergeAttributes",
"(",
"$",
"attributes",
")",
"{",
"$",
"attributes",
"=",
"self",
"::",
"prepareAttributes",
"(",
"$",
"attributes",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"watchedAttributes",
"as",
"$",
"watchedKey",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"$",
"watchedKey",
"]",
")",
")",
"{",
"$",
"this",
"->",
"onAttributeChange",
"(",
"$",
"watchedKey",
",",
"$",
"attributes",
"[",
"$",
"watchedKey",
"]",
")",
";",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"watchedKey",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"attributes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Merges the existing attributes with the new ones
@param mixed Array of attribute 'name' => 'value' pairs or HTML attribute string
@return HTML_Common2 | [
"Merges",
"the",
"existing",
"attributes",
"with",
"the",
"new",
"ones"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L314-L325 |
210,062 | matomo-org/matomo | libs/HTML/Common2.php | HTML_Common2.setIndentLevel | public function setIndentLevel($level)
{
$level = intval($level);
if (0 <= $level) {
$this->_indentLevel = $level;
}
return $this;
} | php | public function setIndentLevel($level)
{
$level = intval($level);
if (0 <= $level) {
$this->_indentLevel = $level;
}
return $this;
} | [
"public",
"function",
"setIndentLevel",
"(",
"$",
"level",
")",
"{",
"$",
"level",
"=",
"intval",
"(",
"$",
"level",
")",
";",
"if",
"(",
"0",
"<=",
"$",
"level",
")",
"{",
"$",
"this",
"->",
"_indentLevel",
"=",
"$",
"level",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the indentation level
@param int
@return HTML_Common2 | [
"Sets",
"the",
"indentation",
"level"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/Common2.php#L349-L356 |
210,063 | matomo-org/matomo | core/Settings/Plugin/SystemSettings.php | SystemSettings.makeSetting | protected function makeSetting($name, $defaultValue, $type, $fieldConfigCallback)
{
$setting = new SystemSetting($name, $defaultValue, $type, $this->pluginName);
$setting->setConfigureCallback($fieldConfigCallback);
$this->addSetting($setting);
return $setting;
} | php | protected function makeSetting($name, $defaultValue, $type, $fieldConfigCallback)
{
$setting = new SystemSetting($name, $defaultValue, $type, $this->pluginName);
$setting->setConfigureCallback($fieldConfigCallback);
$this->addSetting($setting);
return $setting;
} | [
"protected",
"function",
"makeSetting",
"(",
"$",
"name",
",",
"$",
"defaultValue",
",",
"$",
"type",
",",
"$",
"fieldConfigCallback",
")",
"{",
"$",
"setting",
"=",
"new",
"SystemSetting",
"(",
"$",
"name",
",",
"$",
"defaultValue",
",",
"$",
"type",
",",
"$",
"this",
"->",
"pluginName",
")",
";",
"$",
"setting",
"->",
"setConfigureCallback",
"(",
"$",
"fieldConfigCallback",
")",
";",
"$",
"this",
"->",
"addSetting",
"(",
"$",
"setting",
")",
";",
"return",
"$",
"setting",
";",
"}"
] | Creates a new system setting.
Settings will be displayed in the UI depending on the order of `makeSetting` calls. This means you can define
the order of the displayed settings by calling makeSetting first for more important settings.
@param string $name The name of the setting that shall be created
@param mixed $defaultValue The default value for this setting. Note the value will not be converted to the
specified type.
@param string $type The PHP internal type the value of this setting should have.
Use one of FieldConfig::TYPE_* constancts
@param \Closure $fieldConfigCallback A callback method to configure the field that shall be displayed in the
UI to define the value for this setting
@return SystemSetting Returns an instance of the created measurable setting. | [
"Creates",
"a",
"new",
"system",
"setting",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Settings/Plugin/SystemSettings.php#L57-L63 |
210,064 | matomo-org/matomo | core/Settings/Plugin/SystemSettings.php | SystemSettings.makeSettingManagedInConfigOnly | protected function makeSettingManagedInConfigOnly($configSectionName, $name, $defaultValue, $type, $fieldConfigCallback)
{
$setting = new SystemConfigSetting($name, $defaultValue, $type, $this->pluginName, $configSectionName);
$setting->setConfigureCallback($fieldConfigCallback);
$this->addSetting($setting);
return $setting;
} | php | protected function makeSettingManagedInConfigOnly($configSectionName, $name, $defaultValue, $type, $fieldConfigCallback)
{
$setting = new SystemConfigSetting($name, $defaultValue, $type, $this->pluginName, $configSectionName);
$setting->setConfigureCallback($fieldConfigCallback);
$this->addSetting($setting);
return $setting;
} | [
"protected",
"function",
"makeSettingManagedInConfigOnly",
"(",
"$",
"configSectionName",
",",
"$",
"name",
",",
"$",
"defaultValue",
",",
"$",
"type",
",",
"$",
"fieldConfigCallback",
")",
"{",
"$",
"setting",
"=",
"new",
"SystemConfigSetting",
"(",
"$",
"name",
",",
"$",
"defaultValue",
",",
"$",
"type",
",",
"$",
"this",
"->",
"pluginName",
",",
"$",
"configSectionName",
")",
";",
"$",
"setting",
"->",
"setConfigureCallback",
"(",
"$",
"fieldConfigCallback",
")",
";",
"$",
"this",
"->",
"addSetting",
"(",
"$",
"setting",
")",
";",
"return",
"$",
"setting",
";",
"}"
] | This is only meant for some core features used by some core plugins that are shipped with Piwik
@internal
@ignore
@param string $configSectionName
@param $name
@param $defaultValue
@param $type
@param $fieldConfigCallback
@return SystemSetting
@throws \Exception | [
"This",
"is",
"only",
"meant",
"for",
"some",
"core",
"features",
"used",
"by",
"some",
"core",
"plugins",
"that",
"are",
"shipped",
"with",
"Piwik"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Settings/Plugin/SystemSettings.php#L77-L83 |
210,065 | matomo-org/matomo | core/Tracker/Visit.php | Visit.handle | public function handle()
{
$this->checkSiteExists($this->request);
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::manipulateRequest()...");
$processor->manipulateRequest($this->request);
}
$this->visitProperties = new VisitProperties();
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::processRequestParams()...");
$abort = $processor->processRequestParams($this->visitProperties, $this->request);
if ($abort) {
Common::printDebug("-> aborting due to processRequestParams method");
return;
}
}
$isNewVisit = $this->request->getMetadata('CoreHome', 'isNewVisit');
if (!$isNewVisit) {
$isNewVisit = $this->triggerPredicateHookOnDimensions($this->getAllVisitDimensions(), 'shouldForceNewVisit');
$this->request->setMetadata('CoreHome', 'isNewVisit', $isNewVisit);
}
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::afterRequestProcessed()...");
$abort = $processor->afterRequestProcessed($this->visitProperties, $this->request);
if ($abort) {
Common::printDebug("-> aborting due to afterRequestProcessed method");
return;
}
}
$isNewVisit = $this->request->getMetadata('CoreHome', 'isNewVisit');
// Known visit when:
// ( - the visitor has the Piwik cookie with the idcookie ID used by Piwik to match the visitor
// OR
// - the visitor doesn't have the Piwik cookie but could be match using heuristics @see recognizeTheVisitor()
// )
// AND
// - the last page view for this visitor was less than 30 minutes ago @see isLastActionInTheSameVisit()
if (!$isNewVisit) {
try {
$this->handleExistingVisit($this->request->getMetadata('Goals', 'visitIsConverted'));
} catch (VisitorNotFoundInDb $e) {
$this->request->setMetadata('CoreHome', 'visitorNotFoundInDb', true); // TODO: perhaps we should just abort here?
}
}
// New visit when:
// - the visitor has the Piwik cookie but the last action was performed more than 30 min ago @see isLastActionInTheSameVisit()
// - the visitor doesn't have the Piwik cookie, and couldn't be matched in @see recognizeTheVisitor()
// - the visitor does have the Piwik cookie but the idcookie and idvisit found in the cookie didn't match to any existing visit in the DB
if ($isNewVisit) {
$this->handleNewVisit($this->request->getMetadata('Goals', 'visitIsConverted'));
}
// update the cookie with the new visit information
$this->request->setThirdPartyCookie($this->request->getVisitorIdForThirdPartyCookie());
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::recordLogs()...");
$processor->recordLogs($this->visitProperties, $this->request);
}
$this->markArchivedReportsAsInvalidIfArchiveAlreadyFinished();
} | php | public function handle()
{
$this->checkSiteExists($this->request);
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::manipulateRequest()...");
$processor->manipulateRequest($this->request);
}
$this->visitProperties = new VisitProperties();
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::processRequestParams()...");
$abort = $processor->processRequestParams($this->visitProperties, $this->request);
if ($abort) {
Common::printDebug("-> aborting due to processRequestParams method");
return;
}
}
$isNewVisit = $this->request->getMetadata('CoreHome', 'isNewVisit');
if (!$isNewVisit) {
$isNewVisit = $this->triggerPredicateHookOnDimensions($this->getAllVisitDimensions(), 'shouldForceNewVisit');
$this->request->setMetadata('CoreHome', 'isNewVisit', $isNewVisit);
}
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::afterRequestProcessed()...");
$abort = $processor->afterRequestProcessed($this->visitProperties, $this->request);
if ($abort) {
Common::printDebug("-> aborting due to afterRequestProcessed method");
return;
}
}
$isNewVisit = $this->request->getMetadata('CoreHome', 'isNewVisit');
// Known visit when:
// ( - the visitor has the Piwik cookie with the idcookie ID used by Piwik to match the visitor
// OR
// - the visitor doesn't have the Piwik cookie but could be match using heuristics @see recognizeTheVisitor()
// )
// AND
// - the last page view for this visitor was less than 30 minutes ago @see isLastActionInTheSameVisit()
if (!$isNewVisit) {
try {
$this->handleExistingVisit($this->request->getMetadata('Goals', 'visitIsConverted'));
} catch (VisitorNotFoundInDb $e) {
$this->request->setMetadata('CoreHome', 'visitorNotFoundInDb', true); // TODO: perhaps we should just abort here?
}
}
// New visit when:
// - the visitor has the Piwik cookie but the last action was performed more than 30 min ago @see isLastActionInTheSameVisit()
// - the visitor doesn't have the Piwik cookie, and couldn't be matched in @see recognizeTheVisitor()
// - the visitor does have the Piwik cookie but the idcookie and idvisit found in the cookie didn't match to any existing visit in the DB
if ($isNewVisit) {
$this->handleNewVisit($this->request->getMetadata('Goals', 'visitIsConverted'));
}
// update the cookie with the new visit information
$this->request->setThirdPartyCookie($this->request->getVisitorIdForThirdPartyCookie());
foreach ($this->requestProcessors as $processor) {
Common::printDebug("Executing " . get_class($processor) . "::recordLogs()...");
$processor->recordLogs($this->visitProperties, $this->request);
}
$this->markArchivedReportsAsInvalidIfArchiveAlreadyFinished();
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"this",
"->",
"checkSiteExists",
"(",
"$",
"this",
"->",
"request",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"requestProcessors",
"as",
"$",
"processor",
")",
"{",
"Common",
"::",
"printDebug",
"(",
"\"Executing \"",
".",
"get_class",
"(",
"$",
"processor",
")",
".",
"\"::manipulateRequest()...\"",
")",
";",
"$",
"processor",
"->",
"manipulateRequest",
"(",
"$",
"this",
"->",
"request",
")",
";",
"}",
"$",
"this",
"->",
"visitProperties",
"=",
"new",
"VisitProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"requestProcessors",
"as",
"$",
"processor",
")",
"{",
"Common",
"::",
"printDebug",
"(",
"\"Executing \"",
".",
"get_class",
"(",
"$",
"processor",
")",
".",
"\"::processRequestParams()...\"",
")",
";",
"$",
"abort",
"=",
"$",
"processor",
"->",
"processRequestParams",
"(",
"$",
"this",
"->",
"visitProperties",
",",
"$",
"this",
"->",
"request",
")",
";",
"if",
"(",
"$",
"abort",
")",
"{",
"Common",
"::",
"printDebug",
"(",
"\"-> aborting due to processRequestParams method\"",
")",
";",
"return",
";",
"}",
"}",
"$",
"isNewVisit",
"=",
"$",
"this",
"->",
"request",
"->",
"getMetadata",
"(",
"'CoreHome'",
",",
"'isNewVisit'",
")",
";",
"if",
"(",
"!",
"$",
"isNewVisit",
")",
"{",
"$",
"isNewVisit",
"=",
"$",
"this",
"->",
"triggerPredicateHookOnDimensions",
"(",
"$",
"this",
"->",
"getAllVisitDimensions",
"(",
")",
",",
"'shouldForceNewVisit'",
")",
";",
"$",
"this",
"->",
"request",
"->",
"setMetadata",
"(",
"'CoreHome'",
",",
"'isNewVisit'",
",",
"$",
"isNewVisit",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"requestProcessors",
"as",
"$",
"processor",
")",
"{",
"Common",
"::",
"printDebug",
"(",
"\"Executing \"",
".",
"get_class",
"(",
"$",
"processor",
")",
".",
"\"::afterRequestProcessed()...\"",
")",
";",
"$",
"abort",
"=",
"$",
"processor",
"->",
"afterRequestProcessed",
"(",
"$",
"this",
"->",
"visitProperties",
",",
"$",
"this",
"->",
"request",
")",
";",
"if",
"(",
"$",
"abort",
")",
"{",
"Common",
"::",
"printDebug",
"(",
"\"-> aborting due to afterRequestProcessed method\"",
")",
";",
"return",
";",
"}",
"}",
"$",
"isNewVisit",
"=",
"$",
"this",
"->",
"request",
"->",
"getMetadata",
"(",
"'CoreHome'",
",",
"'isNewVisit'",
")",
";",
"// Known visit when:",
"// ( - the visitor has the Piwik cookie with the idcookie ID used by Piwik to match the visitor",
"// OR",
"// - the visitor doesn't have the Piwik cookie but could be match using heuristics @see recognizeTheVisitor()",
"// )",
"// AND",
"// - the last page view for this visitor was less than 30 minutes ago @see isLastActionInTheSameVisit()",
"if",
"(",
"!",
"$",
"isNewVisit",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"handleExistingVisit",
"(",
"$",
"this",
"->",
"request",
"->",
"getMetadata",
"(",
"'Goals'",
",",
"'visitIsConverted'",
")",
")",
";",
"}",
"catch",
"(",
"VisitorNotFoundInDb",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"request",
"->",
"setMetadata",
"(",
"'CoreHome'",
",",
"'visitorNotFoundInDb'",
",",
"true",
")",
";",
"// TODO: perhaps we should just abort here?",
"}",
"}",
"// New visit when:",
"// - the visitor has the Piwik cookie but the last action was performed more than 30 min ago @see isLastActionInTheSameVisit()",
"// - the visitor doesn't have the Piwik cookie, and couldn't be matched in @see recognizeTheVisitor()",
"// - the visitor does have the Piwik cookie but the idcookie and idvisit found in the cookie didn't match to any existing visit in the DB",
"if",
"(",
"$",
"isNewVisit",
")",
"{",
"$",
"this",
"->",
"handleNewVisit",
"(",
"$",
"this",
"->",
"request",
"->",
"getMetadata",
"(",
"'Goals'",
",",
"'visitIsConverted'",
")",
")",
";",
"}",
"// update the cookie with the new visit information",
"$",
"this",
"->",
"request",
"->",
"setThirdPartyCookie",
"(",
"$",
"this",
"->",
"request",
"->",
"getVisitorIdForThirdPartyCookie",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"requestProcessors",
"as",
"$",
"processor",
")",
"{",
"Common",
"::",
"printDebug",
"(",
"\"Executing \"",
".",
"get_class",
"(",
"$",
"processor",
")",
".",
"\"::recordLogs()...\"",
")",
";",
"$",
"processor",
"->",
"recordLogs",
"(",
"$",
"this",
"->",
"visitProperties",
",",
"$",
"this",
"->",
"request",
")",
";",
"}",
"$",
"this",
"->",
"markArchivedReportsAsInvalidIfArchiveAlreadyFinished",
"(",
")",
";",
"}"
] | Main algorithm to handle the visit.
Once we have the visitor information, we have to determine if the visit is a new or a known visit.
1) When the last action was done more than 30min ago,
or if the visitor is new, then this is a new visit.
2) If the last action is less than 30min ago, then the same visit is going on.
Because the visit goes on, we can get the time spent during the last action.
NB:
- In the case of a new visit, then the time spent
during the last action of the previous visit is unknown.
- In the case of a new visit but with a known visitor,
we can set the 'returning visitor' flag.
In all the cases we set a cookie to the visitor with the new information. | [
"Main",
"algorithm",
"to",
"handle",
"the",
"visit",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/Visit.php#L121-L194 |
210,066 | matomo-org/matomo | core/Tracker/Visit.php | Visit.getVisitorIdcookie | protected function getVisitorIdcookie()
{
$isKnown = $this->request->getMetadata('CoreHome', 'isVisitorKnown');
if ($isKnown) {
return $this->visitProperties->getProperty('idvisitor');
}
// If the visitor had a first party ID cookie, then we use this value
$idVisitor = $this->visitProperties->getProperty('idvisitor');
if (!empty($idVisitor)
&& Tracker::LENGTH_BINARY_ID == strlen($this->visitProperties->getProperty('idvisitor'))
) {
return $this->visitProperties->getProperty('idvisitor');
}
return Common::hex2bin($this->generateUniqueVisitorId());
} | php | protected function getVisitorIdcookie()
{
$isKnown = $this->request->getMetadata('CoreHome', 'isVisitorKnown');
if ($isKnown) {
return $this->visitProperties->getProperty('idvisitor');
}
// If the visitor had a first party ID cookie, then we use this value
$idVisitor = $this->visitProperties->getProperty('idvisitor');
if (!empty($idVisitor)
&& Tracker::LENGTH_BINARY_ID == strlen($this->visitProperties->getProperty('idvisitor'))
) {
return $this->visitProperties->getProperty('idvisitor');
}
return Common::hex2bin($this->generateUniqueVisitorId());
} | [
"protected",
"function",
"getVisitorIdcookie",
"(",
")",
"{",
"$",
"isKnown",
"=",
"$",
"this",
"->",
"request",
"->",
"getMetadata",
"(",
"'CoreHome'",
",",
"'isVisitorKnown'",
")",
";",
"if",
"(",
"$",
"isKnown",
")",
"{",
"return",
"$",
"this",
"->",
"visitProperties",
"->",
"getProperty",
"(",
"'idvisitor'",
")",
";",
"}",
"// If the visitor had a first party ID cookie, then we use this value",
"$",
"idVisitor",
"=",
"$",
"this",
"->",
"visitProperties",
"->",
"getProperty",
"(",
"'idvisitor'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"idVisitor",
")",
"&&",
"Tracker",
"::",
"LENGTH_BINARY_ID",
"==",
"strlen",
"(",
"$",
"this",
"->",
"visitProperties",
"->",
"getProperty",
"(",
"'idvisitor'",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"visitProperties",
"->",
"getProperty",
"(",
"'idvisitor'",
")",
";",
"}",
"return",
"Common",
"::",
"hex2bin",
"(",
"$",
"this",
"->",
"generateUniqueVisitorId",
"(",
")",
")",
";",
"}"
] | Returns visitor cookie
@return string binary | [
"Returns",
"visitor",
"cookie"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/Visit.php#L295-L311 |
210,067 | matomo-org/matomo | core/Tracker/Visit.php | Visit.isHostKnownAliasHost | public static function isHostKnownAliasHost($urlHost, $idSite)
{
$websiteData = Cache::getCacheWebsiteAttributes($idSite);
if (isset($websiteData['hosts'])) {
$canonicalHosts = array();
foreach ($websiteData['hosts'] as $host) {
$canonicalHosts[] = self::toCanonicalHost($host);
}
$canonicalHost = self::toCanonicalHost($urlHost);
if (in_array($canonicalHost, $canonicalHosts)) {
return true;
}
}
return false;
} | php | public static function isHostKnownAliasHost($urlHost, $idSite)
{
$websiteData = Cache::getCacheWebsiteAttributes($idSite);
if (isset($websiteData['hosts'])) {
$canonicalHosts = array();
foreach ($websiteData['hosts'] as $host) {
$canonicalHosts[] = self::toCanonicalHost($host);
}
$canonicalHost = self::toCanonicalHost($urlHost);
if (in_array($canonicalHost, $canonicalHosts)) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"isHostKnownAliasHost",
"(",
"$",
"urlHost",
",",
"$",
"idSite",
")",
"{",
"$",
"websiteData",
"=",
"Cache",
"::",
"getCacheWebsiteAttributes",
"(",
"$",
"idSite",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"websiteData",
"[",
"'hosts'",
"]",
")",
")",
"{",
"$",
"canonicalHosts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"websiteData",
"[",
"'hosts'",
"]",
"as",
"$",
"host",
")",
"{",
"$",
"canonicalHosts",
"[",
"]",
"=",
"self",
"::",
"toCanonicalHost",
"(",
"$",
"host",
")",
";",
"}",
"$",
"canonicalHost",
"=",
"self",
"::",
"toCanonicalHost",
"(",
"$",
"urlHost",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"canonicalHost",
",",
"$",
"canonicalHosts",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | is the host any of the registered URLs for this website? | [
"is",
"the",
"host",
"any",
"of",
"the",
"registered",
"URLs",
"for",
"this",
"website?"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/Visit.php#L342-L359 |
210,068 | matomo-org/matomo | core/Tracker/Visit.php | Visit.getExistingVisitFieldsToUpdate | private function getExistingVisitFieldsToUpdate($visitIsConverted)
{
$valuesToUpdate = array();
$valuesToUpdate = $this->setIdVisitorForExistingVisit($valuesToUpdate);
$dimensions = $this->getAllVisitDimensions();
$valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onExistingVisit', $valuesToUpdate);
if ($visitIsConverted) {
$valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onConvertedVisit', $valuesToUpdate);
}
// Custom Variables overwrite previous values on each page view
return $valuesToUpdate;
} | php | private function getExistingVisitFieldsToUpdate($visitIsConverted)
{
$valuesToUpdate = array();
$valuesToUpdate = $this->setIdVisitorForExistingVisit($valuesToUpdate);
$dimensions = $this->getAllVisitDimensions();
$valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onExistingVisit', $valuesToUpdate);
if ($visitIsConverted) {
$valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onConvertedVisit', $valuesToUpdate);
}
// Custom Variables overwrite previous values on each page view
return $valuesToUpdate;
} | [
"private",
"function",
"getExistingVisitFieldsToUpdate",
"(",
"$",
"visitIsConverted",
")",
"{",
"$",
"valuesToUpdate",
"=",
"array",
"(",
")",
";",
"$",
"valuesToUpdate",
"=",
"$",
"this",
"->",
"setIdVisitorForExistingVisit",
"(",
"$",
"valuesToUpdate",
")",
";",
"$",
"dimensions",
"=",
"$",
"this",
"->",
"getAllVisitDimensions",
"(",
")",
";",
"$",
"valuesToUpdate",
"=",
"$",
"this",
"->",
"triggerHookOnDimensions",
"(",
"$",
"dimensions",
",",
"'onExistingVisit'",
",",
"$",
"valuesToUpdate",
")",
";",
"if",
"(",
"$",
"visitIsConverted",
")",
"{",
"$",
"valuesToUpdate",
"=",
"$",
"this",
"->",
"triggerHookOnDimensions",
"(",
"$",
"dimensions",
",",
"'onConvertedVisit'",
",",
"$",
"valuesToUpdate",
")",
";",
"}",
"// Custom Variables overwrite previous values on each page view",
"return",
"$",
"valuesToUpdate",
";",
"}"
] | Gather fields=>values that needs to be updated for the existing visit in log_visit
@param $visitIsConverted
@return array | [
"Gather",
"fields",
"=",
">",
"values",
"that",
"needs",
"to",
"be",
"updated",
"for",
"the",
"existing",
"visit",
"in",
"log_visit"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker/Visit.php#L426-L441 |
210,069 | matomo-org/matomo | core/ReportRenderer/Csv.php | Csv.sendToBrowserDownload | public function sendToBrowserDownload($filename)
{
ReportRenderer::sendToBrowser(
$filename,
ReportRenderer::CSV_FORMAT,
"text/" . ReportRenderer::CSV_FORMAT,
$this->getRenderedReport()
);
} | php | public function sendToBrowserDownload($filename)
{
ReportRenderer::sendToBrowser(
$filename,
ReportRenderer::CSV_FORMAT,
"text/" . ReportRenderer::CSV_FORMAT,
$this->getRenderedReport()
);
} | [
"public",
"function",
"sendToBrowserDownload",
"(",
"$",
"filename",
")",
"{",
"ReportRenderer",
"::",
"sendToBrowser",
"(",
"$",
"filename",
",",
"ReportRenderer",
"::",
"CSV_FORMAT",
",",
"\"text/\"",
".",
"ReportRenderer",
"::",
"CSV_FORMAT",
",",
"$",
"this",
"->",
"getRenderedReport",
"(",
")",
")",
";",
"}"
] | Send rendering to browser with a 'download file' prompt
@param string $filename without path & without format extension | [
"Send",
"rendering",
"to",
"browser",
"with",
"a",
"download",
"file",
"prompt"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ReportRenderer/Csv.php#L57-L65 |
210,070 | matomo-org/matomo | core/ReportRenderer/Csv.php | Csv.sendToBrowserInline | public function sendToBrowserInline($filename)
{
ReportRenderer::sendToBrowser(
$filename,
ReportRenderer::CSV_FORMAT,
"application/" . ReportRenderer::CSV_FORMAT,
$this->getRenderedReport()
);
} | php | public function sendToBrowserInline($filename)
{
ReportRenderer::sendToBrowser(
$filename,
ReportRenderer::CSV_FORMAT,
"application/" . ReportRenderer::CSV_FORMAT,
$this->getRenderedReport()
);
} | [
"public",
"function",
"sendToBrowserInline",
"(",
"$",
"filename",
")",
"{",
"ReportRenderer",
"::",
"sendToBrowser",
"(",
"$",
"filename",
",",
"ReportRenderer",
"::",
"CSV_FORMAT",
",",
"\"application/\"",
".",
"ReportRenderer",
"::",
"CSV_FORMAT",
",",
"$",
"this",
"->",
"getRenderedReport",
"(",
")",
")",
";",
"}"
] | Output rendering to browser
@param string $filename without path & without format extension | [
"Output",
"rendering",
"to",
"browser"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ReportRenderer/Csv.php#L72-L80 |
210,071 | matomo-org/matomo | core/ReportRenderer/Csv.php | Csv.renderReport | public function renderReport($processedReport)
{
$csvRenderer = $this->getRenderer(
$processedReport['reportData'],
$processedReport['metadata']['uniqueId']
);
$reportData = $csvRenderer->render($processedReport);
if (empty($reportData)) {
$reportData = Piwik::translate('CoreHome_ThereIsNoDataForThisReport');
}
$replaceBySpace = array( $csvRenderer->separator, ";");
$reportName = str_replace($replaceBySpace, " ", $processedReport['metadata']['name']);
$this->rendered .= implode(
'',
array(
$reportName,
$csvRenderer->lineEnd,
$reportData,
$csvRenderer->lineEnd,
$csvRenderer->lineEnd,
)
);
} | php | public function renderReport($processedReport)
{
$csvRenderer = $this->getRenderer(
$processedReport['reportData'],
$processedReport['metadata']['uniqueId']
);
$reportData = $csvRenderer->render($processedReport);
if (empty($reportData)) {
$reportData = Piwik::translate('CoreHome_ThereIsNoDataForThisReport');
}
$replaceBySpace = array( $csvRenderer->separator, ";");
$reportName = str_replace($replaceBySpace, " ", $processedReport['metadata']['name']);
$this->rendered .= implode(
'',
array(
$reportName,
$csvRenderer->lineEnd,
$reportData,
$csvRenderer->lineEnd,
$csvRenderer->lineEnd,
)
);
} | [
"public",
"function",
"renderReport",
"(",
"$",
"processedReport",
")",
"{",
"$",
"csvRenderer",
"=",
"$",
"this",
"->",
"getRenderer",
"(",
"$",
"processedReport",
"[",
"'reportData'",
"]",
",",
"$",
"processedReport",
"[",
"'metadata'",
"]",
"[",
"'uniqueId'",
"]",
")",
";",
"$",
"reportData",
"=",
"$",
"csvRenderer",
"->",
"render",
"(",
"$",
"processedReport",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"reportData",
")",
")",
"{",
"$",
"reportData",
"=",
"Piwik",
"::",
"translate",
"(",
"'CoreHome_ThereIsNoDataForThisReport'",
")",
";",
"}",
"$",
"replaceBySpace",
"=",
"array",
"(",
"$",
"csvRenderer",
"->",
"separator",
",",
"\";\"",
")",
";",
"$",
"reportName",
"=",
"str_replace",
"(",
"$",
"replaceBySpace",
",",
"\" \"",
",",
"$",
"processedReport",
"[",
"'metadata'",
"]",
"[",
"'name'",
"]",
")",
";",
"$",
"this",
"->",
"rendered",
".=",
"implode",
"(",
"''",
",",
"array",
"(",
"$",
"reportName",
",",
"$",
"csvRenderer",
"->",
"lineEnd",
",",
"$",
"reportData",
",",
"$",
"csvRenderer",
"->",
"lineEnd",
",",
"$",
"csvRenderer",
"->",
"lineEnd",
",",
")",
")",
";",
"}"
] | Render the provided report.
Multiple calls to this method before calling outputRendering appends each report content.
@param array $processedReport @see API::getProcessedReport() | [
"Render",
"the",
"provided",
"report",
".",
"Multiple",
"calls",
"to",
"this",
"method",
"before",
"calling",
"outputRendering",
"appends",
"each",
"report",
"content",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ReportRenderer/Csv.php#L110-L134 |
210,072 | matomo-org/matomo | plugins/UserCountry/UserCountry.php | UserCountry.getCountriesForContinent | public static function getCountriesForContinent($continent)
{
/** @var RegionDataProvider $regionDataProvider */
$regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider');
$result = array();
$continent = strtolower($continent);
foreach ($regionDataProvider->getCountryList() as $countryCode => $continentCode) {
if ($continent == $continentCode) {
$result[] = $countryCode;
}
}
return array('SQL' => "'" . implode("', '", $result) . "', ?",
'bind' => '-'); // HACK: SegmentExpression requires a $bind, even if there's nothing to bind
} | php | public static function getCountriesForContinent($continent)
{
/** @var RegionDataProvider $regionDataProvider */
$regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider');
$result = array();
$continent = strtolower($continent);
foreach ($regionDataProvider->getCountryList() as $countryCode => $continentCode) {
if ($continent == $continentCode) {
$result[] = $countryCode;
}
}
return array('SQL' => "'" . implode("', '", $result) . "', ?",
'bind' => '-'); // HACK: SegmentExpression requires a $bind, even if there's nothing to bind
} | [
"public",
"static",
"function",
"getCountriesForContinent",
"(",
"$",
"continent",
")",
"{",
"/** @var RegionDataProvider $regionDataProvider */",
"$",
"regionDataProvider",
"=",
"StaticContainer",
"::",
"get",
"(",
"'Piwik\\Intl\\Data\\Provider\\RegionDataProvider'",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"continent",
"=",
"strtolower",
"(",
"$",
"continent",
")",
";",
"foreach",
"(",
"$",
"regionDataProvider",
"->",
"getCountryList",
"(",
")",
"as",
"$",
"countryCode",
"=>",
"$",
"continentCode",
")",
"{",
"if",
"(",
"$",
"continent",
"==",
"$",
"continentCode",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"countryCode",
";",
"}",
"}",
"return",
"array",
"(",
"'SQL'",
"=>",
"\"'\"",
".",
"implode",
"(",
"\"', '\"",
",",
"$",
"result",
")",
".",
"\"', ?\"",
",",
"'bind'",
"=>",
"'-'",
")",
";",
"// HACK: SegmentExpression requires a $bind, even if there's nothing to bind",
"}"
] | Returns a list of country codes for a given continent code.
@param string $continent The continent code.
@return array | [
"Returns",
"a",
"list",
"of",
"country",
"codes",
"for",
"a",
"given",
"continent",
"code",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/UserCountry.php#L72-L86 |
210,073 | matomo-org/matomo | plugins/UserCountry/UserCountry.php | UserCountry.isGeoIPWorking | public function isGeoIPWorking()
{
$provider = LocationProvider::getCurrentProvider();
return $provider instanceof GeoIp
&& $provider->isAvailable() === true
&& $provider->isWorking() === true;
} | php | public function isGeoIPWorking()
{
$provider = LocationProvider::getCurrentProvider();
return $provider instanceof GeoIp
&& $provider->isAvailable() === true
&& $provider->isWorking() === true;
} | [
"public",
"function",
"isGeoIPWorking",
"(",
")",
"{",
"$",
"provider",
"=",
"LocationProvider",
"::",
"getCurrentProvider",
"(",
")",
";",
"return",
"$",
"provider",
"instanceof",
"GeoIp",
"&&",
"$",
"provider",
"->",
"isAvailable",
"(",
")",
"===",
"true",
"&&",
"$",
"provider",
"->",
"isWorking",
"(",
")",
"===",
"true",
";",
"}"
] | Returns true if a GeoIP provider is installed & working, false if otherwise.
@return bool | [
"Returns",
"true",
"if",
"a",
"GeoIP",
"provider",
"is",
"installed",
"&",
"working",
"false",
"if",
"otherwise",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/UserCountry.php#L93-L99 |
210,074 | matomo-org/matomo | core/Menu/MenuAdmin.php | MenuAdmin.getMenu | public function getMenu()
{
if (!$this->menu) {
foreach ($this->getAllMenus() as $menu) {
$menu->configureAdminMenu($this);
}
}
return parent::getMenu();
} | php | public function getMenu()
{
if (!$this->menu) {
foreach ($this->getAllMenus() as $menu) {
$menu->configureAdminMenu($this);
}
}
return parent::getMenu();
} | [
"public",
"function",
"getMenu",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"menu",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getAllMenus",
"(",
")",
"as",
"$",
"menu",
")",
"{",
"$",
"menu",
"->",
"configureAdminMenu",
"(",
"$",
"this",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"getMenu",
"(",
")",
";",
"}"
] | Triggers the Menu.MenuAdmin.addItems hook and returns the admin menu.
@return Array | [
"Triggers",
"the",
"Menu",
".",
"MenuAdmin",
".",
"addItems",
"hook",
"and",
"returns",
"the",
"admin",
"menu",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAdmin.php#L114-L124 |
210,075 | matomo-org/matomo | plugins/UsersManager/UserAccessFilter.php | UserAccessFilter.filterUsers | public function filterUsers($users)
{
if ($this->access->hasSuperUserAccess()) {
return $users;
}
if (!$this->access->isUserHasSomeAdminAccess()) {
// keep only own user if it is in the list
foreach ($users as $user) {
if ($this->isOwnLogin($user['login'])) {
return array($user);
}
}
return array();
}
foreach ($users as $index => $user) {
if (!$this->isNonSuperUserAllowedToSeeThisLogin($user['login'])) {
unset($users[$index]);
}
}
return array_values($users);
} | php | public function filterUsers($users)
{
if ($this->access->hasSuperUserAccess()) {
return $users;
}
if (!$this->access->isUserHasSomeAdminAccess()) {
// keep only own user if it is in the list
foreach ($users as $user) {
if ($this->isOwnLogin($user['login'])) {
return array($user);
}
}
return array();
}
foreach ($users as $index => $user) {
if (!$this->isNonSuperUserAllowedToSeeThisLogin($user['login'])) {
unset($users[$index]);
}
}
return array_values($users);
} | [
"public",
"function",
"filterUsers",
"(",
"$",
"users",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"access",
"->",
"hasSuperUserAccess",
"(",
")",
")",
"{",
"return",
"$",
"users",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"access",
"->",
"isUserHasSomeAdminAccess",
"(",
")",
")",
"{",
"// keep only own user if it is in the list",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOwnLogin",
"(",
"$",
"user",
"[",
"'login'",
"]",
")",
")",
"{",
"return",
"array",
"(",
"$",
"user",
")",
";",
"}",
"}",
"return",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"users",
"as",
"$",
"index",
"=>",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isNonSuperUserAllowedToSeeThisLogin",
"(",
"$",
"user",
"[",
"'login'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"users",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"return",
"array_values",
"(",
"$",
"users",
")",
";",
"}"
] | Removes all users from the list of the given users where the current user has no permission to see the existence
of that other user.
@param array $users An array of arrays. Each inner array must have a key 'login'. Eg:
array(array('login' => 'username1'), array('login' => 'username2'), ...)
@return array | [
"Removes",
"all",
"users",
"from",
"the",
"list",
"of",
"the",
"given",
"users",
"where",
"the",
"current",
"user",
"has",
"no",
"permission",
"to",
"see",
"the",
"existence",
"of",
"that",
"other",
"user",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UsersManager/UserAccessFilter.php#L86-L110 |
210,076 | matomo-org/matomo | plugins/UsersManager/UserAccessFilter.php | UserAccessFilter.filterLogins | public function filterLogins($logins)
{
if ($this->access->hasSuperUserAccess()) {
return $logins;
}
if (!$this->access->isUserHasSomeAdminAccess()) {
// keep only own user if it is in the list
foreach ($logins as $login) {
if ($this->isOwnLogin($login)) {
return array($login);
}
}
return array();
}
foreach ($logins as $index => $login) {
if (!$this->isNonSuperUserAllowedToSeeThisLogin($login)) {
unset($logins[$index]);
}
}
return array_values($logins);
} | php | public function filterLogins($logins)
{
if ($this->access->hasSuperUserAccess()) {
return $logins;
}
if (!$this->access->isUserHasSomeAdminAccess()) {
// keep only own user if it is in the list
foreach ($logins as $login) {
if ($this->isOwnLogin($login)) {
return array($login);
}
}
return array();
}
foreach ($logins as $index => $login) {
if (!$this->isNonSuperUserAllowedToSeeThisLogin($login)) {
unset($logins[$index]);
}
}
return array_values($logins);
} | [
"public",
"function",
"filterLogins",
"(",
"$",
"logins",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"access",
"->",
"hasSuperUserAccess",
"(",
")",
")",
"{",
"return",
"$",
"logins",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"access",
"->",
"isUserHasSomeAdminAccess",
"(",
")",
")",
"{",
"// keep only own user if it is in the list",
"foreach",
"(",
"$",
"logins",
"as",
"$",
"login",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOwnLogin",
"(",
"$",
"login",
")",
")",
"{",
"return",
"array",
"(",
"$",
"login",
")",
";",
"}",
"}",
"return",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"logins",
"as",
"$",
"index",
"=>",
"$",
"login",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isNonSuperUserAllowedToSeeThisLogin",
"(",
"$",
"login",
")",
")",
"{",
"unset",
"(",
"$",
"logins",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"return",
"array_values",
"(",
"$",
"logins",
")",
";",
"}"
] | Removes all logins from the list of logins where the current user has no permission to see them.
@param string[] $logins An array of logins / usernames. Eg array('username1', 'username2')
@return array | [
"Removes",
"all",
"logins",
"from",
"the",
"list",
"of",
"logins",
"where",
"the",
"current",
"user",
"has",
"no",
"permission",
"to",
"see",
"them",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UsersManager/UserAccessFilter.php#L130-L154 |
210,077 | matomo-org/matomo | plugins/Live/API.php | API.getCounters | public function getCounters($idSite, $lastMinutes, $segment = false, $showColumns = array(), $hideColumns = array())
{
Piwik::checkUserHasViewAccess($idSite);
$model = new Model();
if (is_string($showColumns)) {
$showColumns = explode(',', $showColumns);
}
if (is_string($hideColumns)) {
$hideColumns = explode(',', $hideColumns);
}
$counters = array();
$hasVisits = true;
if ($this->shouldColumnBePresentInResponse('visits', $showColumns, $hideColumns)) {
$counters['visits'] = $model->getNumVisits($idSite, $lastMinutes, $segment);
$hasVisits = !empty($counters['visits']);
}
if ($this->shouldColumnBePresentInResponse('actions', $showColumns, $hideColumns)) {
if ($hasVisits) {
$counters['actions'] = $model->getNumActions($idSite, $lastMinutes, $segment);
} else {
$counters['actions'] = 0;
}
}
if ($this->shouldColumnBePresentInResponse('visitors', $showColumns, $hideColumns)) {
if ($hasVisits) {
$counters['visitors'] = $model->getNumVisitors($idSite, $lastMinutes, $segment);
} else {
$counters['visitors'] = 0;
}
}
if ($this->shouldColumnBePresentInResponse('visitsConverted', $showColumns, $hideColumns)) {
if ($hasVisits) {
$counters['visitsConverted'] = $model->getNumVisitsConverted($idSite, $lastMinutes, $segment);
} else {
$counters['visitsConverted'] = 0;
}
}
return array($counters);
} | php | public function getCounters($idSite, $lastMinutes, $segment = false, $showColumns = array(), $hideColumns = array())
{
Piwik::checkUserHasViewAccess($idSite);
$model = new Model();
if (is_string($showColumns)) {
$showColumns = explode(',', $showColumns);
}
if (is_string($hideColumns)) {
$hideColumns = explode(',', $hideColumns);
}
$counters = array();
$hasVisits = true;
if ($this->shouldColumnBePresentInResponse('visits', $showColumns, $hideColumns)) {
$counters['visits'] = $model->getNumVisits($idSite, $lastMinutes, $segment);
$hasVisits = !empty($counters['visits']);
}
if ($this->shouldColumnBePresentInResponse('actions', $showColumns, $hideColumns)) {
if ($hasVisits) {
$counters['actions'] = $model->getNumActions($idSite, $lastMinutes, $segment);
} else {
$counters['actions'] = 0;
}
}
if ($this->shouldColumnBePresentInResponse('visitors', $showColumns, $hideColumns)) {
if ($hasVisits) {
$counters['visitors'] = $model->getNumVisitors($idSite, $lastMinutes, $segment);
} else {
$counters['visitors'] = 0;
}
}
if ($this->shouldColumnBePresentInResponse('visitsConverted', $showColumns, $hideColumns)) {
if ($hasVisits) {
$counters['visitsConverted'] = $model->getNumVisitsConverted($idSite, $lastMinutes, $segment);
} else {
$counters['visitsConverted'] = 0;
}
}
return array($counters);
} | [
"public",
"function",
"getCounters",
"(",
"$",
"idSite",
",",
"$",
"lastMinutes",
",",
"$",
"segment",
"=",
"false",
",",
"$",
"showColumns",
"=",
"array",
"(",
")",
",",
"$",
"hideColumns",
"=",
"array",
"(",
")",
")",
"{",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"idSite",
")",
";",
"$",
"model",
"=",
"new",
"Model",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"showColumns",
")",
")",
"{",
"$",
"showColumns",
"=",
"explode",
"(",
"','",
",",
"$",
"showColumns",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"hideColumns",
")",
")",
"{",
"$",
"hideColumns",
"=",
"explode",
"(",
"','",
",",
"$",
"hideColumns",
")",
";",
"}",
"$",
"counters",
"=",
"array",
"(",
")",
";",
"$",
"hasVisits",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"shouldColumnBePresentInResponse",
"(",
"'visits'",
",",
"$",
"showColumns",
",",
"$",
"hideColumns",
")",
")",
"{",
"$",
"counters",
"[",
"'visits'",
"]",
"=",
"$",
"model",
"->",
"getNumVisits",
"(",
"$",
"idSite",
",",
"$",
"lastMinutes",
",",
"$",
"segment",
")",
";",
"$",
"hasVisits",
"=",
"!",
"empty",
"(",
"$",
"counters",
"[",
"'visits'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"shouldColumnBePresentInResponse",
"(",
"'actions'",
",",
"$",
"showColumns",
",",
"$",
"hideColumns",
")",
")",
"{",
"if",
"(",
"$",
"hasVisits",
")",
"{",
"$",
"counters",
"[",
"'actions'",
"]",
"=",
"$",
"model",
"->",
"getNumActions",
"(",
"$",
"idSite",
",",
"$",
"lastMinutes",
",",
"$",
"segment",
")",
";",
"}",
"else",
"{",
"$",
"counters",
"[",
"'actions'",
"]",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"shouldColumnBePresentInResponse",
"(",
"'visitors'",
",",
"$",
"showColumns",
",",
"$",
"hideColumns",
")",
")",
"{",
"if",
"(",
"$",
"hasVisits",
")",
"{",
"$",
"counters",
"[",
"'visitors'",
"]",
"=",
"$",
"model",
"->",
"getNumVisitors",
"(",
"$",
"idSite",
",",
"$",
"lastMinutes",
",",
"$",
"segment",
")",
";",
"}",
"else",
"{",
"$",
"counters",
"[",
"'visitors'",
"]",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"shouldColumnBePresentInResponse",
"(",
"'visitsConverted'",
",",
"$",
"showColumns",
",",
"$",
"hideColumns",
")",
")",
"{",
"if",
"(",
"$",
"hasVisits",
")",
"{",
"$",
"counters",
"[",
"'visitsConverted'",
"]",
"=",
"$",
"model",
"->",
"getNumVisitsConverted",
"(",
"$",
"idSite",
",",
"$",
"lastMinutes",
",",
"$",
"segment",
")",
";",
"}",
"else",
"{",
"$",
"counters",
"[",
"'visitsConverted'",
"]",
"=",
"0",
";",
"}",
"}",
"return",
"array",
"(",
"$",
"counters",
")",
";",
"}"
] | This will return simple counters, for a given website ID, for visits over the last N minutes
@param int $idSite Id Site
@param int $lastMinutes Number of minutes to look back at
@param bool|string $segment
@param array $showColumns The columns to show / not to request. Eg 'visits', 'actions', ...
@param array $hideColumns The columns to hide / not to request. Eg 'visits', 'actions', ...
@return array( visits => N, actions => M, visitsConverted => P ) | [
"This",
"will",
"return",
"simple",
"counters",
"for",
"a",
"given",
"website",
"ID",
"for",
"visits",
"over",
"the",
"last",
"N",
"minutes"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Live/API.php#L70-L116 |
210,078 | matomo-org/matomo | plugins/Live/API.php | API.getMostRecentVisitorId | public function getMostRecentVisitorId($idSite, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
// for faster performance search for a visitor within the last 7 days first
$minTimestamp = Date::now()->subDay(7)->getTimestamp();
$dataTable = $this->loadLastVisitsDetailsFromDatabase(
$idSite, $period = false, $date = false, $segment, $offset = 0, $limit = 1, $minTimestamp
);
if (0 >= $dataTable->getRowsCount()) {
$minTimestamp = Date::now()->subYear(1)->getTimestamp();
// no visitor found in last 7 days, look further back for up to 1 year. This query will be slower
$dataTable = $this->loadLastVisitsDetailsFromDatabase(
$idSite, $period = false, $date = false, $segment, $offset = 0, $limit = 1, $minTimestamp
);
}
if (0 >= $dataTable->getRowsCount()) {
// no visitor found in last year, look over all logs. This query might be quite slow
$dataTable = $this->loadLastVisitsDetailsFromDatabase(
$idSite, $period = false, $date = false, $segment, $offset = 0, $limit = 1
);
}
if (0 >= $dataTable->getRowsCount()) {
return false;
}
$visitorFactory = new VisitorFactory();
$visitDetails = $dataTable->getFirstRow()->getColumns();
$visitor = $visitorFactory->create($visitDetails);
return $visitor->getVisitorId();
} | php | public function getMostRecentVisitorId($idSite, $segment = false)
{
Piwik::checkUserHasViewAccess($idSite);
// for faster performance search for a visitor within the last 7 days first
$minTimestamp = Date::now()->subDay(7)->getTimestamp();
$dataTable = $this->loadLastVisitsDetailsFromDatabase(
$idSite, $period = false, $date = false, $segment, $offset = 0, $limit = 1, $minTimestamp
);
if (0 >= $dataTable->getRowsCount()) {
$minTimestamp = Date::now()->subYear(1)->getTimestamp();
// no visitor found in last 7 days, look further back for up to 1 year. This query will be slower
$dataTable = $this->loadLastVisitsDetailsFromDatabase(
$idSite, $period = false, $date = false, $segment, $offset = 0, $limit = 1, $minTimestamp
);
}
if (0 >= $dataTable->getRowsCount()) {
// no visitor found in last year, look over all logs. This query might be quite slow
$dataTable = $this->loadLastVisitsDetailsFromDatabase(
$idSite, $period = false, $date = false, $segment, $offset = 0, $limit = 1
);
}
if (0 >= $dataTable->getRowsCount()) {
return false;
}
$visitorFactory = new VisitorFactory();
$visitDetails = $dataTable->getFirstRow()->getColumns();
$visitor = $visitorFactory->create($visitDetails);
return $visitor->getVisitorId();
} | [
"public",
"function",
"getMostRecentVisitorId",
"(",
"$",
"idSite",
",",
"$",
"segment",
"=",
"false",
")",
"{",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"idSite",
")",
";",
"// for faster performance search for a visitor within the last 7 days first",
"$",
"minTimestamp",
"=",
"Date",
"::",
"now",
"(",
")",
"->",
"subDay",
"(",
"7",
")",
"->",
"getTimestamp",
"(",
")",
";",
"$",
"dataTable",
"=",
"$",
"this",
"->",
"loadLastVisitsDetailsFromDatabase",
"(",
"$",
"idSite",
",",
"$",
"period",
"=",
"false",
",",
"$",
"date",
"=",
"false",
",",
"$",
"segment",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"limit",
"=",
"1",
",",
"$",
"minTimestamp",
")",
";",
"if",
"(",
"0",
">=",
"$",
"dataTable",
"->",
"getRowsCount",
"(",
")",
")",
"{",
"$",
"minTimestamp",
"=",
"Date",
"::",
"now",
"(",
")",
"->",
"subYear",
"(",
"1",
")",
"->",
"getTimestamp",
"(",
")",
";",
"// no visitor found in last 7 days, look further back for up to 1 year. This query will be slower",
"$",
"dataTable",
"=",
"$",
"this",
"->",
"loadLastVisitsDetailsFromDatabase",
"(",
"$",
"idSite",
",",
"$",
"period",
"=",
"false",
",",
"$",
"date",
"=",
"false",
",",
"$",
"segment",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"limit",
"=",
"1",
",",
"$",
"minTimestamp",
")",
";",
"}",
"if",
"(",
"0",
">=",
"$",
"dataTable",
"->",
"getRowsCount",
"(",
")",
")",
"{",
"// no visitor found in last year, look over all logs. This query might be quite slow",
"$",
"dataTable",
"=",
"$",
"this",
"->",
"loadLastVisitsDetailsFromDatabase",
"(",
"$",
"idSite",
",",
"$",
"period",
"=",
"false",
",",
"$",
"date",
"=",
"false",
",",
"$",
"segment",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"limit",
"=",
"1",
")",
";",
"}",
"if",
"(",
"0",
">=",
"$",
"dataTable",
"->",
"getRowsCount",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"visitorFactory",
"=",
"new",
"VisitorFactory",
"(",
")",
";",
"$",
"visitDetails",
"=",
"$",
"dataTable",
"->",
"getFirstRow",
"(",
")",
"->",
"getColumns",
"(",
")",
";",
"$",
"visitor",
"=",
"$",
"visitorFactory",
"->",
"create",
"(",
"$",
"visitDetails",
")",
";",
"return",
"$",
"visitor",
"->",
"getVisitorId",
"(",
")",
";",
"}"
] | Returns the visitor ID of the most recent visit.
@param int $idSite
@param bool|string $segment
@return string | [
"Returns",
"the",
"visitor",
"ID",
"of",
"the",
"most",
"recent",
"visit",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Live/API.php#L267-L302 |
210,079 | matomo-org/matomo | plugins/Live/API.php | API.getFirstVisitForVisitorId | public function getFirstVisitForVisitorId($idSite, $visitorId)
{
Piwik::checkUserHasSomeViewAccess();
if (empty($visitorId)) {
return new DataTable();
}
$model = new Model();
$data = $model->queryLogVisits($idSite, false, false, false, 0, 1, $visitorId, false, 'ASC');
$dataTable = $this->makeVisitorTableFromArray($data);
$this->addFilterToCleanVisitors($dataTable, $idSite, false, true);
return $dataTable;
} | php | public function getFirstVisitForVisitorId($idSite, $visitorId)
{
Piwik::checkUserHasSomeViewAccess();
if (empty($visitorId)) {
return new DataTable();
}
$model = new Model();
$data = $model->queryLogVisits($idSite, false, false, false, 0, 1, $visitorId, false, 'ASC');
$dataTable = $this->makeVisitorTableFromArray($data);
$this->addFilterToCleanVisitors($dataTable, $idSite, false, true);
return $dataTable;
} | [
"public",
"function",
"getFirstVisitForVisitorId",
"(",
"$",
"idSite",
",",
"$",
"visitorId",
")",
"{",
"Piwik",
"::",
"checkUserHasSomeViewAccess",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"visitorId",
")",
")",
"{",
"return",
"new",
"DataTable",
"(",
")",
";",
"}",
"$",
"model",
"=",
"new",
"Model",
"(",
")",
";",
"$",
"data",
"=",
"$",
"model",
"->",
"queryLogVisits",
"(",
"$",
"idSite",
",",
"false",
",",
"false",
",",
"false",
",",
"0",
",",
"1",
",",
"$",
"visitorId",
",",
"false",
",",
"'ASC'",
")",
";",
"$",
"dataTable",
"=",
"$",
"this",
"->",
"makeVisitorTableFromArray",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"addFilterToCleanVisitors",
"(",
"$",
"dataTable",
",",
"$",
"idSite",
",",
"false",
",",
"true",
")",
";",
"return",
"$",
"dataTable",
";",
"}"
] | Returns the very first visit for the given visitorId
@internal
@param $idSite
@param $visitorId
@return DataTable | [
"Returns",
"the",
"very",
"first",
"visit",
"for",
"the",
"given",
"visitorId"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Live/API.php#L314-L328 |
210,080 | matomo-org/matomo | plugins/Live/API.php | API.addFilterToCleanVisitors | private function addFilterToCleanVisitors(DataTable $dataTable, $idSite, $flat = false, $doNotFetchActions = false, $filterNow = false)
{
$filter = 'queueFilter';
if ($filterNow) {
$filter = 'filter';
}
$dataTable->$filter(function ($table) use ($idSite, $flat, $doNotFetchActions) {
/** @var DataTable $table */
$visitorFactory = new VisitorFactory();
// live api is not summable, prevents errors like "Unexpected ECommerce status value"
$table->deleteRow(DataTable::ID_SUMMARY_ROW);
$actionsByVisitId = array();
if (!$doNotFetchActions) {
$visitIds = $table->getColumn('idvisit');
$visitorDetailsManipulators = Visitor::getAllVisitorDetailsInstances();
foreach ($visitorDetailsManipulators as $instance) {
$instance->provideActionsForVisitIds($actionsByVisitId, $visitIds);
}
}
foreach ($table->getRows() as $visitorDetailRow) {
$visitorDetailsArray = Visitor::cleanVisitorDetails($visitorDetailRow->getColumns());
$visitor = $visitorFactory->create($visitorDetailsArray);
$visitorDetailsArray = $visitor->getAllVisitorDetails();
$visitorDetailsArray['actionDetails'] = array();
if (!$doNotFetchActions) {
$bulkFetchedActions = isset($actionsByVisitId[$visitorDetailsArray['idVisit']]) ? $actionsByVisitId[$visitorDetailsArray['idVisit']] : array();
$visitorDetailsArray = Visitor::enrichVisitorArrayWithActions($visitorDetailsArray, $bulkFetchedActions);
}
if ($flat) {
$visitorDetailsArray = Visitor::flattenVisitorDetailsArray($visitorDetailsArray);
}
$visitorDetailRow->setColumns($visitorDetailsArray);
}
});
} | php | private function addFilterToCleanVisitors(DataTable $dataTable, $idSite, $flat = false, $doNotFetchActions = false, $filterNow = false)
{
$filter = 'queueFilter';
if ($filterNow) {
$filter = 'filter';
}
$dataTable->$filter(function ($table) use ($idSite, $flat, $doNotFetchActions) {
/** @var DataTable $table */
$visitorFactory = new VisitorFactory();
// live api is not summable, prevents errors like "Unexpected ECommerce status value"
$table->deleteRow(DataTable::ID_SUMMARY_ROW);
$actionsByVisitId = array();
if (!$doNotFetchActions) {
$visitIds = $table->getColumn('idvisit');
$visitorDetailsManipulators = Visitor::getAllVisitorDetailsInstances();
foreach ($visitorDetailsManipulators as $instance) {
$instance->provideActionsForVisitIds($actionsByVisitId, $visitIds);
}
}
foreach ($table->getRows() as $visitorDetailRow) {
$visitorDetailsArray = Visitor::cleanVisitorDetails($visitorDetailRow->getColumns());
$visitor = $visitorFactory->create($visitorDetailsArray);
$visitorDetailsArray = $visitor->getAllVisitorDetails();
$visitorDetailsArray['actionDetails'] = array();
if (!$doNotFetchActions) {
$bulkFetchedActions = isset($actionsByVisitId[$visitorDetailsArray['idVisit']]) ? $actionsByVisitId[$visitorDetailsArray['idVisit']] : array();
$visitorDetailsArray = Visitor::enrichVisitorArrayWithActions($visitorDetailsArray, $bulkFetchedActions);
}
if ($flat) {
$visitorDetailsArray = Visitor::flattenVisitorDetailsArray($visitorDetailsArray);
}
$visitorDetailRow->setColumns($visitorDetailsArray);
}
});
} | [
"private",
"function",
"addFilterToCleanVisitors",
"(",
"DataTable",
"$",
"dataTable",
",",
"$",
"idSite",
",",
"$",
"flat",
"=",
"false",
",",
"$",
"doNotFetchActions",
"=",
"false",
",",
"$",
"filterNow",
"=",
"false",
")",
"{",
"$",
"filter",
"=",
"'queueFilter'",
";",
"if",
"(",
"$",
"filterNow",
")",
"{",
"$",
"filter",
"=",
"'filter'",
";",
"}",
"$",
"dataTable",
"->",
"$",
"filter",
"(",
"function",
"(",
"$",
"table",
")",
"use",
"(",
"$",
"idSite",
",",
"$",
"flat",
",",
"$",
"doNotFetchActions",
")",
"{",
"/** @var DataTable $table */",
"$",
"visitorFactory",
"=",
"new",
"VisitorFactory",
"(",
")",
";",
"// live api is not summable, prevents errors like \"Unexpected ECommerce status value\"",
"$",
"table",
"->",
"deleteRow",
"(",
"DataTable",
"::",
"ID_SUMMARY_ROW",
")",
";",
"$",
"actionsByVisitId",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"doNotFetchActions",
")",
"{",
"$",
"visitIds",
"=",
"$",
"table",
"->",
"getColumn",
"(",
"'idvisit'",
")",
";",
"$",
"visitorDetailsManipulators",
"=",
"Visitor",
"::",
"getAllVisitorDetailsInstances",
"(",
")",
";",
"foreach",
"(",
"$",
"visitorDetailsManipulators",
"as",
"$",
"instance",
")",
"{",
"$",
"instance",
"->",
"provideActionsForVisitIds",
"(",
"$",
"actionsByVisitId",
",",
"$",
"visitIds",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"table",
"->",
"getRows",
"(",
")",
"as",
"$",
"visitorDetailRow",
")",
"{",
"$",
"visitorDetailsArray",
"=",
"Visitor",
"::",
"cleanVisitorDetails",
"(",
"$",
"visitorDetailRow",
"->",
"getColumns",
"(",
")",
")",
";",
"$",
"visitor",
"=",
"$",
"visitorFactory",
"->",
"create",
"(",
"$",
"visitorDetailsArray",
")",
";",
"$",
"visitorDetailsArray",
"=",
"$",
"visitor",
"->",
"getAllVisitorDetails",
"(",
")",
";",
"$",
"visitorDetailsArray",
"[",
"'actionDetails'",
"]",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"doNotFetchActions",
")",
"{",
"$",
"bulkFetchedActions",
"=",
"isset",
"(",
"$",
"actionsByVisitId",
"[",
"$",
"visitorDetailsArray",
"[",
"'idVisit'",
"]",
"]",
")",
"?",
"$",
"actionsByVisitId",
"[",
"$",
"visitorDetailsArray",
"[",
"'idVisit'",
"]",
"]",
":",
"array",
"(",
")",
";",
"$",
"visitorDetailsArray",
"=",
"Visitor",
"::",
"enrichVisitorArrayWithActions",
"(",
"$",
"visitorDetailsArray",
",",
"$",
"bulkFetchedActions",
")",
";",
"}",
"if",
"(",
"$",
"flat",
")",
"{",
"$",
"visitorDetailsArray",
"=",
"Visitor",
"::",
"flattenVisitorDetailsArray",
"(",
"$",
"visitorDetailsArray",
")",
";",
"}",
"$",
"visitorDetailRow",
"->",
"setColumns",
"(",
"$",
"visitorDetailsArray",
")",
";",
"}",
"}",
")",
";",
"}"
] | For an array of visits, query the list of pages for this visit
as well as make the data human readable
@param DataTable $dataTable
@param int $idSite
@param bool $flat whether to flatten the array (eg. 'customVariables' names/values will appear in the root array rather than in 'customVariables' key
@param bool $doNotFetchActions If set to true, we only fetch visit info and not actions (much faster)
@param bool $filterNow If true, the visitors will be cleaned immediately | [
"For",
"an",
"array",
"of",
"visits",
"query",
"the",
"list",
"of",
"pages",
"for",
"this",
"visit",
"as",
"well",
"as",
"make",
"the",
"data",
"human",
"readable"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/Live/API.php#L347-L392 |
210,081 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.getMenu | public function getMenu()
{
$this->buildMenu();
$this->applyEdits();
$this->applyRemoves();
$this->applyRenames();
$this->applyOrdering();
return $this->menu;
} | php | public function getMenu()
{
$this->buildMenu();
$this->applyEdits();
$this->applyRemoves();
$this->applyRenames();
$this->applyOrdering();
return $this->menu;
} | [
"public",
"function",
"getMenu",
"(",
")",
"{",
"$",
"this",
"->",
"buildMenu",
"(",
")",
";",
"$",
"this",
"->",
"applyEdits",
"(",
")",
";",
"$",
"this",
"->",
"applyRemoves",
"(",
")",
";",
"$",
"this",
"->",
"applyRenames",
"(",
")",
";",
"$",
"this",
"->",
"applyOrdering",
"(",
")",
";",
"return",
"$",
"this",
"->",
"menu",
";",
"}"
] | Builds the menu, applies edits, renames
and orders the entries.
@return Array | [
"Builds",
"the",
"menu",
"applies",
"edits",
"renames",
"and",
"orders",
"the",
"entries",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L43-L51 |
210,082 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.getAllMenus | protected function getAllMenus()
{
if (!empty(self::$menus)) {
return self::$menus;
}
$components = PluginManager::getInstance()->findComponents('Menu', 'Piwik\\Plugin\\Menu');
self::$menus = array();
foreach ($components as $component) {
self::$menus[] = StaticContainer::get($component);
}
return self::$menus;
} | php | protected function getAllMenus()
{
if (!empty(self::$menus)) {
return self::$menus;
}
$components = PluginManager::getInstance()->findComponents('Menu', 'Piwik\\Plugin\\Menu');
self::$menus = array();
foreach ($components as $component) {
self::$menus[] = StaticContainer::get($component);
}
return self::$menus;
} | [
"protected",
"function",
"getAllMenus",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"$",
"menus",
")",
")",
"{",
"return",
"self",
"::",
"$",
"menus",
";",
"}",
"$",
"components",
"=",
"PluginManager",
"::",
"getInstance",
"(",
")",
"->",
"findComponents",
"(",
"'Menu'",
",",
"'Piwik\\\\Plugin\\\\Menu'",
")",
";",
"self",
"::",
"$",
"menus",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"components",
"as",
"$",
"component",
")",
"{",
"self",
"::",
"$",
"menus",
"[",
"]",
"=",
"StaticContainer",
"::",
"get",
"(",
"$",
"component",
")",
";",
"}",
"return",
"self",
"::",
"$",
"menus",
";",
"}"
] | Returns a list of available plugin menu instances.
@return \Piwik\Plugin\Menu[] | [
"Returns",
"a",
"list",
"of",
"available",
"plugin",
"menu",
"instances",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L69-L83 |
210,083 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.addItem | public function addItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false, $icon = false, $onclick = false)
{
// make sure the idSite value used is numeric (hack-y fix for #3426)
if (isset($url['idSite']) && !is_numeric($url['idSite'])) {
$idSites = API::getInstance()->getSitesIdWithAtLeastViewAccess();
$url['idSite'] = reset($idSites);
}
$this->menuEntries[] = array(
$menuName,
$subMenuName,
$url,
$order,
$tooltip,
$icon,
$onclick
);
} | php | public function addItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false, $icon = false, $onclick = false)
{
// make sure the idSite value used is numeric (hack-y fix for #3426)
if (isset($url['idSite']) && !is_numeric($url['idSite'])) {
$idSites = API::getInstance()->getSitesIdWithAtLeastViewAccess();
$url['idSite'] = reset($idSites);
}
$this->menuEntries[] = array(
$menuName,
$subMenuName,
$url,
$order,
$tooltip,
$icon,
$onclick
);
} | [
"public",
"function",
"addItem",
"(",
"$",
"menuName",
",",
"$",
"subMenuName",
",",
"$",
"url",
",",
"$",
"order",
"=",
"50",
",",
"$",
"tooltip",
"=",
"false",
",",
"$",
"icon",
"=",
"false",
",",
"$",
"onclick",
"=",
"false",
")",
"{",
"// make sure the idSite value used is numeric (hack-y fix for #3426)",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'idSite'",
"]",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"url",
"[",
"'idSite'",
"]",
")",
")",
"{",
"$",
"idSites",
"=",
"API",
"::",
"getInstance",
"(",
")",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
";",
"$",
"url",
"[",
"'idSite'",
"]",
"=",
"reset",
"(",
"$",
"idSites",
")",
";",
"}",
"$",
"this",
"->",
"menuEntries",
"[",
"]",
"=",
"array",
"(",
"$",
"menuName",
",",
"$",
"subMenuName",
",",
"$",
"url",
",",
"$",
"order",
",",
"$",
"tooltip",
",",
"$",
"icon",
",",
"$",
"onclick",
")",
";",
"}"
] | Adds a new entry to the menu.
@param string $menuName The menu's category name. Can be a translation token.
@param string $subMenuName The menu item's name. Can be a translation token.
@param string|array $url The URL the admin menu entry should link to, or an array of query parameters
that can be used to build the URL.
@param int $order The order hint.
@param bool|string $tooltip An optional tooltip to display or false to display the tooltip.
@param bool|string $icon An icon classname, such as "icon-add". Only supported by admin menu
@param bool|string $onclick Will execute the on click handler instead of executing the link. Only supported by admin menu.
@since 2.7.0
@api | [
"Adds",
"a",
"new",
"entry",
"to",
"the",
"menu",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L109-L126 |
210,084 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.buildMenuItem | private function buildMenuItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false, $icon = false, $onclick = false)
{
if (!isset($this->menu[$menuName])) {
$this->menu[$menuName] = array(
'_hasSubmenu' => false,
'_order' => $order
);
}
if (empty($subMenuName)) {
$this->menu[$menuName]['_url'] = $url;
$this->menu[$menuName]['_order'] = $order;
$this->menu[$menuName]['_name'] = $menuName;
$this->menu[$menuName]['_tooltip'] = $tooltip;
if (!empty($this->menuIcons[$menuName])) {
$this->menu[$menuName]['_icon'] = $this->menuIcons[$menuName];
} else {
$this->menu[$menuName]['_icon'] = '';
}
}
if (!empty($subMenuName)) {
$this->menu[$menuName][$subMenuName]['_url'] = $url;
$this->menu[$menuName][$subMenuName]['_order'] = $order;
$this->menu[$menuName][$subMenuName]['_name'] = $subMenuName;
$this->menu[$menuName][$subMenuName]['_tooltip'] = $tooltip;
$this->menu[$menuName][$subMenuName]['_icon'] = $icon;
$this->menu[$menuName][$subMenuName]['_onclick'] = $onclick;
$this->menu[$menuName]['_hasSubmenu'] = true;
if (!array_key_exists('_tooltip', $this->menu[$menuName])) {
$this->menu[$menuName]['_tooltip'] = $tooltip;
}
}
} | php | private function buildMenuItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false, $icon = false, $onclick = false)
{
if (!isset($this->menu[$menuName])) {
$this->menu[$menuName] = array(
'_hasSubmenu' => false,
'_order' => $order
);
}
if (empty($subMenuName)) {
$this->menu[$menuName]['_url'] = $url;
$this->menu[$menuName]['_order'] = $order;
$this->menu[$menuName]['_name'] = $menuName;
$this->menu[$menuName]['_tooltip'] = $tooltip;
if (!empty($this->menuIcons[$menuName])) {
$this->menu[$menuName]['_icon'] = $this->menuIcons[$menuName];
} else {
$this->menu[$menuName]['_icon'] = '';
}
}
if (!empty($subMenuName)) {
$this->menu[$menuName][$subMenuName]['_url'] = $url;
$this->menu[$menuName][$subMenuName]['_order'] = $order;
$this->menu[$menuName][$subMenuName]['_name'] = $subMenuName;
$this->menu[$menuName][$subMenuName]['_tooltip'] = $tooltip;
$this->menu[$menuName][$subMenuName]['_icon'] = $icon;
$this->menu[$menuName][$subMenuName]['_onclick'] = $onclick;
$this->menu[$menuName]['_hasSubmenu'] = true;
if (!array_key_exists('_tooltip', $this->menu[$menuName])) {
$this->menu[$menuName]['_tooltip'] = $tooltip;
}
}
} | [
"private",
"function",
"buildMenuItem",
"(",
"$",
"menuName",
",",
"$",
"subMenuName",
",",
"$",
"url",
",",
"$",
"order",
"=",
"50",
",",
"$",
"tooltip",
"=",
"false",
",",
"$",
"icon",
"=",
"false",
",",
"$",
"onclick",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"=",
"array",
"(",
"'_hasSubmenu'",
"=>",
"false",
",",
"'_order'",
"=>",
"$",
"order",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"subMenuName",
")",
")",
"{",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_url'",
"]",
"=",
"$",
"url",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_order'",
"]",
"=",
"$",
"order",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_name'",
"]",
"=",
"$",
"menuName",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_tooltip'",
"]",
"=",
"$",
"tooltip",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"menuIcons",
"[",
"$",
"menuName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_icon'",
"]",
"=",
"$",
"this",
"->",
"menuIcons",
"[",
"$",
"menuName",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_icon'",
"]",
"=",
"''",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"subMenuName",
")",
")",
"{",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"$",
"subMenuName",
"]",
"[",
"'_url'",
"]",
"=",
"$",
"url",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"$",
"subMenuName",
"]",
"[",
"'_order'",
"]",
"=",
"$",
"order",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"$",
"subMenuName",
"]",
"[",
"'_name'",
"]",
"=",
"$",
"subMenuName",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"$",
"subMenuName",
"]",
"[",
"'_tooltip'",
"]",
"=",
"$",
"tooltip",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"$",
"subMenuName",
"]",
"[",
"'_icon'",
"]",
"=",
"$",
"icon",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"$",
"subMenuName",
"]",
"[",
"'_onclick'",
"]",
"=",
"$",
"onclick",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_hasSubmenu'",
"]",
"=",
"true",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'_tooltip'",
",",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"menu",
"[",
"$",
"menuName",
"]",
"[",
"'_tooltip'",
"]",
"=",
"$",
"tooltip",
";",
"}",
"}",
"}"
] | Builds a single menu item
@param string $menuName
@param string $subMenuName
@param string $url
@param int $order
@param bool|string $tooltip Tooltip to display. | [
"Builds",
"a",
"single",
"menu",
"item"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L152-L185 |
210,085 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.rename | public function rename($mainMenuOriginal, $subMenuOriginal, $mainMenuRenamed, $subMenuRenamed)
{
$this->renames[] = array($mainMenuOriginal, $subMenuOriginal,
$mainMenuRenamed, $subMenuRenamed);
} | php | public function rename($mainMenuOriginal, $subMenuOriginal, $mainMenuRenamed, $subMenuRenamed)
{
$this->renames[] = array($mainMenuOriginal, $subMenuOriginal,
$mainMenuRenamed, $subMenuRenamed);
} | [
"public",
"function",
"rename",
"(",
"$",
"mainMenuOriginal",
",",
"$",
"subMenuOriginal",
",",
"$",
"mainMenuRenamed",
",",
"$",
"subMenuRenamed",
")",
"{",
"$",
"this",
"->",
"renames",
"[",
"]",
"=",
"array",
"(",
"$",
"mainMenuOriginal",
",",
"$",
"subMenuOriginal",
",",
"$",
"mainMenuRenamed",
",",
"$",
"subMenuRenamed",
")",
";",
"}"
] | Renames a single menu entry.
@param $mainMenuOriginal
@param $subMenuOriginal
@param $mainMenuRenamed
@param $subMenuRenamed
@api | [
"Renames",
"a",
"single",
"menu",
"entry",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L206-L210 |
210,086 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.applyEdits | private function applyEdits()
{
foreach ($this->edits as $edit) {
$mainMenuToEdit = $edit[0];
$subMenuToEdit = $edit[1];
$newUrl = $edit[2];
if ($subMenuToEdit === null) {
if (isset($this->menu[$mainMenuToEdit])) {
$menuDataToEdit = &$this->menu[$mainMenuToEdit];
} else {
$menuDataToEdit = null;
}
} else {
if (isset($this->menu[$mainMenuToEdit][$subMenuToEdit])) {
$menuDataToEdit = &$this->menu[$mainMenuToEdit][$subMenuToEdit];
} else {
$menuDataToEdit = null;
}
}
if (empty($menuDataToEdit)) {
$this->buildMenuItem($mainMenuToEdit, $subMenuToEdit, $newUrl);
} else {
$menuDataToEdit['_url'] = $newUrl;
}
}
} | php | private function applyEdits()
{
foreach ($this->edits as $edit) {
$mainMenuToEdit = $edit[0];
$subMenuToEdit = $edit[1];
$newUrl = $edit[2];
if ($subMenuToEdit === null) {
if (isset($this->menu[$mainMenuToEdit])) {
$menuDataToEdit = &$this->menu[$mainMenuToEdit];
} else {
$menuDataToEdit = null;
}
} else {
if (isset($this->menu[$mainMenuToEdit][$subMenuToEdit])) {
$menuDataToEdit = &$this->menu[$mainMenuToEdit][$subMenuToEdit];
} else {
$menuDataToEdit = null;
}
}
if (empty($menuDataToEdit)) {
$this->buildMenuItem($mainMenuToEdit, $subMenuToEdit, $newUrl);
} else {
$menuDataToEdit['_url'] = $newUrl;
}
}
} | [
"private",
"function",
"applyEdits",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"edits",
"as",
"$",
"edit",
")",
"{",
"$",
"mainMenuToEdit",
"=",
"$",
"edit",
"[",
"0",
"]",
";",
"$",
"subMenuToEdit",
"=",
"$",
"edit",
"[",
"1",
"]",
";",
"$",
"newUrl",
"=",
"$",
"edit",
"[",
"2",
"]",
";",
"if",
"(",
"$",
"subMenuToEdit",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuToEdit",
"]",
")",
")",
"{",
"$",
"menuDataToEdit",
"=",
"&",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuToEdit",
"]",
";",
"}",
"else",
"{",
"$",
"menuDataToEdit",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuToEdit",
"]",
"[",
"$",
"subMenuToEdit",
"]",
")",
")",
"{",
"$",
"menuDataToEdit",
"=",
"&",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuToEdit",
"]",
"[",
"$",
"subMenuToEdit",
"]",
";",
"}",
"else",
"{",
"$",
"menuDataToEdit",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"menuDataToEdit",
")",
")",
"{",
"$",
"this",
"->",
"buildMenuItem",
"(",
"$",
"mainMenuToEdit",
",",
"$",
"subMenuToEdit",
",",
"$",
"newUrl",
")",
";",
"}",
"else",
"{",
"$",
"menuDataToEdit",
"[",
"'_url'",
"]",
"=",
"$",
"newUrl",
";",
"}",
"}",
"}"
] | Applies all edits to the menu. | [
"Applies",
"all",
"edits",
"to",
"the",
"menu",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L228-L255 |
210,087 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.applyRenames | private function applyRenames()
{
foreach ($this->renames as $rename) {
$mainMenuOriginal = $rename[0];
$subMenuOriginal = $rename[1];
$mainMenuRenamed = $rename[2];
$subMenuRenamed = $rename[3];
// Are we changing a submenu?
if (!empty($subMenuOriginal)) {
if (isset($this->menu[$mainMenuOriginal][$subMenuOriginal])) {
$save = $this->menu[$mainMenuOriginal][$subMenuOriginal];
$save['_name'] = $subMenuRenamed;
unset($this->menu[$mainMenuOriginal][$subMenuOriginal]);
$this->menu[$mainMenuRenamed][$subMenuRenamed] = $save;
}
} // Changing a first-level element
elseif (isset($this->menu[$mainMenuOriginal])) {
$save = $this->menu[$mainMenuOriginal];
$save['_name'] = $mainMenuRenamed;
unset($this->menu[$mainMenuOriginal]);
$this->menu[$mainMenuRenamed] = $save;
}
}
} | php | private function applyRenames()
{
foreach ($this->renames as $rename) {
$mainMenuOriginal = $rename[0];
$subMenuOriginal = $rename[1];
$mainMenuRenamed = $rename[2];
$subMenuRenamed = $rename[3];
// Are we changing a submenu?
if (!empty($subMenuOriginal)) {
if (isset($this->menu[$mainMenuOriginal][$subMenuOriginal])) {
$save = $this->menu[$mainMenuOriginal][$subMenuOriginal];
$save['_name'] = $subMenuRenamed;
unset($this->menu[$mainMenuOriginal][$subMenuOriginal]);
$this->menu[$mainMenuRenamed][$subMenuRenamed] = $save;
}
} // Changing a first-level element
elseif (isset($this->menu[$mainMenuOriginal])) {
$save = $this->menu[$mainMenuOriginal];
$save['_name'] = $mainMenuRenamed;
unset($this->menu[$mainMenuOriginal]);
$this->menu[$mainMenuRenamed] = $save;
}
}
} | [
"private",
"function",
"applyRenames",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"renames",
"as",
"$",
"rename",
")",
"{",
"$",
"mainMenuOriginal",
"=",
"$",
"rename",
"[",
"0",
"]",
";",
"$",
"subMenuOriginal",
"=",
"$",
"rename",
"[",
"1",
"]",
";",
"$",
"mainMenuRenamed",
"=",
"$",
"rename",
"[",
"2",
"]",
";",
"$",
"subMenuRenamed",
"=",
"$",
"rename",
"[",
"3",
"]",
";",
"// Are we changing a submenu?",
"if",
"(",
"!",
"empty",
"(",
"$",
"subMenuOriginal",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuOriginal",
"]",
"[",
"$",
"subMenuOriginal",
"]",
")",
")",
"{",
"$",
"save",
"=",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuOriginal",
"]",
"[",
"$",
"subMenuOriginal",
"]",
";",
"$",
"save",
"[",
"'_name'",
"]",
"=",
"$",
"subMenuRenamed",
";",
"unset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuOriginal",
"]",
"[",
"$",
"subMenuOriginal",
"]",
")",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuRenamed",
"]",
"[",
"$",
"subMenuRenamed",
"]",
"=",
"$",
"save",
";",
"}",
"}",
"// Changing a first-level element",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuOriginal",
"]",
")",
")",
"{",
"$",
"save",
"=",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuOriginal",
"]",
";",
"$",
"save",
"[",
"'_name'",
"]",
"=",
"$",
"mainMenuRenamed",
";",
"unset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuOriginal",
"]",
")",
";",
"$",
"this",
"->",
"menu",
"[",
"$",
"mainMenuRenamed",
"]",
"=",
"$",
"save",
";",
"}",
"}",
"}"
] | Applies renames to the menu. | [
"Applies",
"renames",
"to",
"the",
"menu",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L276-L300 |
210,088 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.applyOrdering | private function applyOrdering()
{
if (empty($this->menu)
|| $this->orderingApplied
) {
return;
}
uasort($this->menu, array($this, 'menuCompare'));
foreach ($this->menu as $key => &$element) {
if (is_null($element)) {
unset($this->menu[$key]);
} elseif ($element['_hasSubmenu']) {
uasort($element, array($this, 'menuCompare'));
}
}
$this->orderingApplied = true;
} | php | private function applyOrdering()
{
if (empty($this->menu)
|| $this->orderingApplied
) {
return;
}
uasort($this->menu, array($this, 'menuCompare'));
foreach ($this->menu as $key => &$element) {
if (is_null($element)) {
unset($this->menu[$key]);
} elseif ($element['_hasSubmenu']) {
uasort($element, array($this, 'menuCompare'));
}
}
$this->orderingApplied = true;
} | [
"private",
"function",
"applyOrdering",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"menu",
")",
"||",
"$",
"this",
"->",
"orderingApplied",
")",
"{",
"return",
";",
"}",
"uasort",
"(",
"$",
"this",
"->",
"menu",
",",
"array",
"(",
"$",
"this",
",",
"'menuCompare'",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"menu",
"as",
"$",
"key",
"=>",
"&",
"$",
"element",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"element",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"menu",
"[",
"$",
"key",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"element",
"[",
"'_hasSubmenu'",
"]",
")",
"{",
"uasort",
"(",
"$",
"element",
",",
"array",
"(",
"$",
"this",
",",
"'menuCompare'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"orderingApplied",
"=",
"true",
";",
"}"
] | Orders the menu according to their order. | [
"Orders",
"the",
"menu",
"according",
"to",
"their",
"order",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L305-L323 |
210,089 | matomo-org/matomo | core/Menu/MenuAbstract.php | MenuAbstract.menuCompare | protected function menuCompare($itemOne, $itemTwo)
{
if (!is_array($itemOne) && !is_array($itemTwo)) {
return 0;
}
if (!is_array($itemOne) && is_array($itemTwo)) {
return -1;
}
if (is_array($itemOne) && !is_array($itemTwo)) {
return 1;
}
if (!isset($itemOne['_order']) && !isset($itemTwo['_order'])) {
return 0;
}
if (!isset($itemOne['_order']) && isset($itemTwo['_order'])) {
return -1;
}
if (isset($itemOne['_order']) && !isset($itemTwo['_order'])) {
return 1;
}
if ($itemOne['_order'] == $itemTwo['_order']) {
return strcmp(
@$itemOne['_name'],
@$itemTwo['_name']);
}
return ($itemOne['_order'] < $itemTwo['_order']) ? -1 : 1;
} | php | protected function menuCompare($itemOne, $itemTwo)
{
if (!is_array($itemOne) && !is_array($itemTwo)) {
return 0;
}
if (!is_array($itemOne) && is_array($itemTwo)) {
return -1;
}
if (is_array($itemOne) && !is_array($itemTwo)) {
return 1;
}
if (!isset($itemOne['_order']) && !isset($itemTwo['_order'])) {
return 0;
}
if (!isset($itemOne['_order']) && isset($itemTwo['_order'])) {
return -1;
}
if (isset($itemOne['_order']) && !isset($itemTwo['_order'])) {
return 1;
}
if ($itemOne['_order'] == $itemTwo['_order']) {
return strcmp(
@$itemOne['_name'],
@$itemTwo['_name']);
}
return ($itemOne['_order'] < $itemTwo['_order']) ? -1 : 1;
} | [
"protected",
"function",
"menuCompare",
"(",
"$",
"itemOne",
",",
"$",
"itemTwo",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"itemOne",
")",
"&&",
"!",
"is_array",
"(",
"$",
"itemTwo",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"itemOne",
")",
"&&",
"is_array",
"(",
"$",
"itemTwo",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"itemOne",
")",
"&&",
"!",
"is_array",
"(",
"$",
"itemTwo",
")",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"itemOne",
"[",
"'_order'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"itemTwo",
"[",
"'_order'",
"]",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"itemOne",
"[",
"'_order'",
"]",
")",
"&&",
"isset",
"(",
"$",
"itemTwo",
"[",
"'_order'",
"]",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"itemOne",
"[",
"'_order'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"itemTwo",
"[",
"'_order'",
"]",
")",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"$",
"itemOne",
"[",
"'_order'",
"]",
"==",
"$",
"itemTwo",
"[",
"'_order'",
"]",
")",
"{",
"return",
"strcmp",
"(",
"@",
"$",
"itemOne",
"[",
"'_name'",
"]",
",",
"@",
"$",
"itemTwo",
"[",
"'_name'",
"]",
")",
";",
"}",
"return",
"(",
"$",
"itemOne",
"[",
"'_order'",
"]",
"<",
"$",
"itemTwo",
"[",
"'_order'",
"]",
")",
"?",
"-",
"1",
":",
"1",
";",
"}"
] | Compares two menu entries. Used for ordering.
@param array $itemOne
@param array $itemTwo
@return boolean | [
"Compares",
"two",
"menu",
"entries",
".",
"Used",
"for",
"ordering",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Menu/MenuAbstract.php#L332-L365 |
210,090 | matomo-org/matomo | plugins/CoreAdminHome/Tasks/ArchivesToPurgeDistributedList.php | ArchivesToPurgeDistributedList.convertOldDistributedList | private function convertOldDistributedList(&$yearMonths)
{
foreach ($yearMonths as $key => $value) {
if (preg_match("/^[0-9]{4}_[0-9]{2}$/", $key)) {
unset($yearMonths[$key]);
$yearMonths[] = $key;
}
}
} | php | private function convertOldDistributedList(&$yearMonths)
{
foreach ($yearMonths as $key => $value) {
if (preg_match("/^[0-9]{4}_[0-9]{2}$/", $key)) {
unset($yearMonths[$key]);
$yearMonths[] = $key;
}
}
} | [
"private",
"function",
"convertOldDistributedList",
"(",
"&",
"$",
"yearMonths",
")",
"{",
"foreach",
"(",
"$",
"yearMonths",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/^[0-9]{4}_[0-9]{2}$/\"",
",",
"$",
"key",
")",
")",
"{",
"unset",
"(",
"$",
"yearMonths",
"[",
"$",
"key",
"]",
")",
";",
"$",
"yearMonths",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"}"
] | Before 2.12.0 Piwik stored this list as an array mapping year months to arrays of site IDs. If this is
found in the DB, we convert the array to an array of year months to avoid errors and to make sure
the correct tables are still purged. | [
"Before",
"2",
".",
"12",
".",
"0",
"Piwik",
"stored",
"this",
"list",
"as",
"an",
"array",
"mapping",
"year",
"months",
"to",
"arrays",
"of",
"site",
"IDs",
".",
"If",
"this",
"is",
"found",
"in",
"the",
"DB",
"we",
"convert",
"the",
"array",
"to",
"an",
"array",
"of",
"year",
"months",
"to",
"avoid",
"errors",
"and",
"to",
"make",
"sure",
"the",
"correct",
"tables",
"are",
"still",
"purged",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/CoreAdminHome/Tasks/ArchivesToPurgeDistributedList.php#L77-L86 |
210,091 | matomo-org/matomo | libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php | Zend_Mail_Protocol_Smtp_Auth_Plain.auth | public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH PLAIN');
$this->_expect(334);
$this->_send(base64_encode("\0" . $this->_username . "\0" . $this->_password));
$this->_expect(235);
$this->_auth = true;
} | php | public function auth()
{
// Ensure AUTH has not already been initiated.
parent::auth();
$this->_send('AUTH PLAIN');
$this->_expect(334);
$this->_send(base64_encode("\0" . $this->_username . "\0" . $this->_password));
$this->_expect(235);
$this->_auth = true;
} | [
"public",
"function",
"auth",
"(",
")",
"{",
"// Ensure AUTH has not already been initiated.",
"parent",
"::",
"auth",
"(",
")",
";",
"$",
"this",
"->",
"_send",
"(",
"'AUTH PLAIN'",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"334",
")",
";",
"$",
"this",
"->",
"_send",
"(",
"base64_encode",
"(",
"\"\\0\"",
".",
"$",
"this",
"->",
"_username",
".",
"\"\\0\"",
".",
"$",
"this",
"->",
"_password",
")",
")",
";",
"$",
"this",
"->",
"_expect",
"(",
"235",
")",
";",
"$",
"this",
"->",
"_auth",
"=",
"true",
";",
"}"
] | Perform PLAIN authentication with supplied credentials
@return void | [
"Perform",
"PLAIN",
"authentication",
"with",
"supplied",
"credentials"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Mail/Protocol/Smtp/Auth/Plain.php#L85-L95 |
210,092 | matomo-org/matomo | plugins/API/API.php | API.getAvailableMeasurableTypes | public function getAvailableMeasurableTypes()
{
Piwik::checkUserHasSomeViewAccess();
$typeManager = new TypeManager();
$types = $typeManager->getAllTypes();
$available = array();
foreach ($types as $type) {
$measurableSettings = $this->settingsProvider->getAllMeasurableSettings($idSite = 0, $type->getId());
$settingsMetadata = new SettingsMetadata();
$available[] = array(
'id' => $type->getId(),
'name' => Piwik::translate($type->getName()),
'description' => Piwik::translate($type->getDescription()),
'howToSetupUrl' => $type->getHowToSetupUrl(),
'settings' => $settingsMetadata->formatSettings($measurableSettings)
);
}
return $available;
} | php | public function getAvailableMeasurableTypes()
{
Piwik::checkUserHasSomeViewAccess();
$typeManager = new TypeManager();
$types = $typeManager->getAllTypes();
$available = array();
foreach ($types as $type) {
$measurableSettings = $this->settingsProvider->getAllMeasurableSettings($idSite = 0, $type->getId());
$settingsMetadata = new SettingsMetadata();
$available[] = array(
'id' => $type->getId(),
'name' => Piwik::translate($type->getName()),
'description' => Piwik::translate($type->getDescription()),
'howToSetupUrl' => $type->getHowToSetupUrl(),
'settings' => $settingsMetadata->formatSettings($measurableSettings)
);
}
return $available;
} | [
"public",
"function",
"getAvailableMeasurableTypes",
"(",
")",
"{",
"Piwik",
"::",
"checkUserHasSomeViewAccess",
"(",
")",
";",
"$",
"typeManager",
"=",
"new",
"TypeManager",
"(",
")",
";",
"$",
"types",
"=",
"$",
"typeManager",
"->",
"getAllTypes",
"(",
")",
";",
"$",
"available",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"measurableSettings",
"=",
"$",
"this",
"->",
"settingsProvider",
"->",
"getAllMeasurableSettings",
"(",
"$",
"idSite",
"=",
"0",
",",
"$",
"type",
"->",
"getId",
"(",
")",
")",
";",
"$",
"settingsMetadata",
"=",
"new",
"SettingsMetadata",
"(",
")",
";",
"$",
"available",
"[",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"type",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"Piwik",
"::",
"translate",
"(",
"$",
"type",
"->",
"getName",
"(",
")",
")",
",",
"'description'",
"=>",
"Piwik",
"::",
"translate",
"(",
"$",
"type",
"->",
"getDescription",
"(",
")",
")",
",",
"'howToSetupUrl'",
"=>",
"$",
"type",
"->",
"getHowToSetupUrl",
"(",
")",
",",
"'settings'",
"=>",
"$",
"settingsMetadata",
"->",
"formatSettings",
"(",
"$",
"measurableSettings",
")",
")",
";",
"}",
"return",
"$",
"available",
";",
"}"
] | Returns all available measurable types.
Marked as deprecated so it won't appear in API page. It won't be a public API for now.
@deprecated
@return array | [
"Returns",
"all",
"available",
"measurable",
"types",
".",
"Marked",
"as",
"deprecated",
"so",
"it",
"won",
"t",
"appear",
"in",
"API",
"page",
".",
"It",
"won",
"t",
"be",
"a",
"public",
"API",
"for",
"now",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/API/API.php#L159-L182 |
210,093 | matomo-org/matomo | plugins/API/API.php | API.getReportPagesMetadata | public function getReportPagesMetadata($idSite)
{
Piwik::checkUserHasViewAccess($idSite);
$widgetsList = WidgetsList::get();
$categoryList = CategoryList::get();
$metadata = new WidgetMetadata();
return $metadata->getPagesMetadata($categoryList, $widgetsList);
} | php | public function getReportPagesMetadata($idSite)
{
Piwik::checkUserHasViewAccess($idSite);
$widgetsList = WidgetsList::get();
$categoryList = CategoryList::get();
$metadata = new WidgetMetadata();
return $metadata->getPagesMetadata($categoryList, $widgetsList);
} | [
"public",
"function",
"getReportPagesMetadata",
"(",
"$",
"idSite",
")",
"{",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"idSite",
")",
";",
"$",
"widgetsList",
"=",
"WidgetsList",
"::",
"get",
"(",
")",
";",
"$",
"categoryList",
"=",
"CategoryList",
"::",
"get",
"(",
")",
";",
"$",
"metadata",
"=",
"new",
"WidgetMetadata",
"(",
")",
";",
"return",
"$",
"metadata",
"->",
"getPagesMetadata",
"(",
"$",
"categoryList",
",",
"$",
"widgetsList",
")",
";",
"}"
] | Get a list of all pages that shall be shown in a Matomo UI including a list of all widgets that shall
be shown within each page.
@param int $idSite
@return array | [
"Get",
"a",
"list",
"of",
"all",
"pages",
"that",
"shall",
"be",
"shown",
"in",
"a",
"Matomo",
"UI",
"including",
"a",
"list",
"of",
"all",
"widgets",
"that",
"shall",
"be",
"shown",
"within",
"each",
"page",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/API/API.php#L361-L370 |
210,094 | matomo-org/matomo | plugins/API/API.php | API.getWidgetMetadata | public function getWidgetMetadata($idSite)
{
Piwik::checkUserHasViewAccess($idSite);
$widgetsList = WidgetsList::get();
$categoryList = CategoryList::get();
$metadata = new WidgetMetadata();
return $metadata->getWidgetMetadata($categoryList, $widgetsList);
} | php | public function getWidgetMetadata($idSite)
{
Piwik::checkUserHasViewAccess($idSite);
$widgetsList = WidgetsList::get();
$categoryList = CategoryList::get();
$metadata = new WidgetMetadata();
return $metadata->getWidgetMetadata($categoryList, $widgetsList);
} | [
"public",
"function",
"getWidgetMetadata",
"(",
"$",
"idSite",
")",
"{",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"idSite",
")",
";",
"$",
"widgetsList",
"=",
"WidgetsList",
"::",
"get",
"(",
")",
";",
"$",
"categoryList",
"=",
"CategoryList",
"::",
"get",
"(",
")",
";",
"$",
"metadata",
"=",
"new",
"WidgetMetadata",
"(",
")",
";",
"return",
"$",
"metadata",
"->",
"getWidgetMetadata",
"(",
"$",
"categoryList",
",",
"$",
"widgetsList",
")",
";",
"}"
] | Get a list of all widgetizable widgets.
@param int $idSite
@return array | [
"Get",
"a",
"list",
"of",
"all",
"widgetizable",
"widgets",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/API/API.php#L378-L387 |
210,095 | matomo-org/matomo | plugins/API/API.php | API.getBulkRequest | public function getBulkRequest($urls)
{
if (empty($urls)) {
return array();
}
$urls = array_map('urldecode', $urls);
$urls = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $urls);
$result = array();
foreach ($urls as $url) {
$params = Request::getRequestArrayFromString($url . '&format=php&serialize=0');
if (isset($params['urls']) && $params['urls'] == $urls) {
// by default 'urls' is added to $params as Request::getRequestArrayFromString adds all $_GET/$_POST
// default parameters
unset($params['urls']);
}
if (!empty($params['segment']) && strpos($url, 'segment=') > -1) {
// only unsanitize input when segment is actually present in URL, not when it was used from
// $defaultRequest in Request::getRequestArrayFromString from $_GET/$_POST
$params['segment'] = urlencode(Common::unsanitizeInputValue($params['segment']));
}
$req = new Request($params);
$result[] = $req->process();
}
return $result;
} | php | public function getBulkRequest($urls)
{
if (empty($urls)) {
return array();
}
$urls = array_map('urldecode', $urls);
$urls = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $urls);
$result = array();
foreach ($urls as $url) {
$params = Request::getRequestArrayFromString($url . '&format=php&serialize=0');
if (isset($params['urls']) && $params['urls'] == $urls) {
// by default 'urls' is added to $params as Request::getRequestArrayFromString adds all $_GET/$_POST
// default parameters
unset($params['urls']);
}
if (!empty($params['segment']) && strpos($url, 'segment=') > -1) {
// only unsanitize input when segment is actually present in URL, not when it was used from
// $defaultRequest in Request::getRequestArrayFromString from $_GET/$_POST
$params['segment'] = urlencode(Common::unsanitizeInputValue($params['segment']));
}
$req = new Request($params);
$result[] = $req->process();
}
return $result;
} | [
"public",
"function",
"getBulkRequest",
"(",
"$",
"urls",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"urls",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"urls",
"=",
"array_map",
"(",
"'urldecode'",
",",
"$",
"urls",
")",
";",
"$",
"urls",
"=",
"array_map",
"(",
"array",
"(",
"'Piwik\\Common'",
",",
"'unsanitizeInputValue'",
")",
",",
"$",
"urls",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"urls",
"as",
"$",
"url",
")",
"{",
"$",
"params",
"=",
"Request",
"::",
"getRequestArrayFromString",
"(",
"$",
"url",
".",
"'&format=php&serialize=0'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'urls'",
"]",
")",
"&&",
"$",
"params",
"[",
"'urls'",
"]",
"==",
"$",
"urls",
")",
"{",
"// by default 'urls' is added to $params as Request::getRequestArrayFromString adds all $_GET/$_POST",
"// default parameters",
"unset",
"(",
"$",
"params",
"[",
"'urls'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"[",
"'segment'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"url",
",",
"'segment='",
")",
">",
"-",
"1",
")",
"{",
"// only unsanitize input when segment is actually present in URL, not when it was used from",
"// $defaultRequest in Request::getRequestArrayFromString from $_GET/$_POST",
"$",
"params",
"[",
"'segment'",
"]",
"=",
"urlencode",
"(",
"Common",
"::",
"unsanitizeInputValue",
"(",
"$",
"params",
"[",
"'segment'",
"]",
")",
")",
";",
"}",
"$",
"req",
"=",
"new",
"Request",
"(",
"$",
"params",
")",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"req",
"->",
"process",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Performs multiple API requests at once and returns every result.
@param array $urls The array of API requests.
@return array | [
"Performs",
"multiple",
"API",
"requests",
"at",
"once",
"and",
"returns",
"every",
"result",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/API/API.php#L516-L545 |
210,096 | matomo-org/matomo | plugins/API/API.php | API.isPluginActivated | public function isPluginActivated($pluginName)
{
Piwik::checkUserHasSomeViewAccess();
return \Piwik\Plugin\Manager::getInstance()->isPluginActivated($pluginName);
} | php | public function isPluginActivated($pluginName)
{
Piwik::checkUserHasSomeViewAccess();
return \Piwik\Plugin\Manager::getInstance()->isPluginActivated($pluginName);
} | [
"public",
"function",
"isPluginActivated",
"(",
"$",
"pluginName",
")",
"{",
"Piwik",
"::",
"checkUserHasSomeViewAccess",
"(",
")",
";",
"return",
"\\",
"Piwik",
"\\",
"Plugin",
"\\",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"isPluginActivated",
"(",
"$",
"pluginName",
")",
";",
"}"
] | Return true if plugin is activated, false otherwise
@param string $pluginName
@return bool | [
"Return",
"true",
"if",
"plugin",
"is",
"activated",
"false",
"otherwise"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/API/API.php#L553-L557 |
210,097 | matomo-org/matomo | plugins/API/API.php | API.getSuggestedValuesForSegment | public function getSuggestedValuesForSegment($segmentName, $idSite)
{
if (empty(Config::getInstance()->General['enable_segment_suggested_values'])) {
return array();
}
Piwik::checkUserHasViewAccess($idSite);
$maxSuggestionsToReturn = 30;
$segment = $this->findSegment($segmentName, $idSite);
// if segment has suggested values callback then return result from it instead
$suggestedValuesCallbackRequiresTable = false;
if (isset($segment['suggestedValuesCallback'])) {
$suggestedValuesCallbackRequiresTable = $this->doesSuggestedValuesCallbackNeedData(
$segment['suggestedValuesCallback']);
if (!$suggestedValuesCallbackRequiresTable) {
return call_user_func($segment['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn);
}
}
// if period=range is disabled, do not proceed
if (!Period\Factory::isPeriodEnabledForAPI('range')) {
return array();
}
if (!empty($segment['unionOfSegments'])) {
$values = array();
foreach ($segment['unionOfSegments'] as $unionSegmentName) {
$unionSegment = $this->findSegment($unionSegmentName, $idSite);
try {
$result = $this->getSuggestedValuesForSegmentName($idSite, $unionSegment, $maxSuggestionsToReturn);
if (!empty($result)) {
$values = array_merge($result, $values);
}
} catch (\Exception $e) {
// we ignore if there was no data found for $unionSegmentName
}
}
if (empty($values)) {
throw new \Exception("There was no data to suggest for $segmentName");
}
} else {
$values = $this->getSuggestedValuesForSegmentName($idSite, $segment, $maxSuggestionsToReturn);
}
$values = $this->getMostFrequentValues($values);
$values = array_slice($values, 0, $maxSuggestionsToReturn);
$values = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $values);
return $values;
} | php | public function getSuggestedValuesForSegment($segmentName, $idSite)
{
if (empty(Config::getInstance()->General['enable_segment_suggested_values'])) {
return array();
}
Piwik::checkUserHasViewAccess($idSite);
$maxSuggestionsToReturn = 30;
$segment = $this->findSegment($segmentName, $idSite);
// if segment has suggested values callback then return result from it instead
$suggestedValuesCallbackRequiresTable = false;
if (isset($segment['suggestedValuesCallback'])) {
$suggestedValuesCallbackRequiresTable = $this->doesSuggestedValuesCallbackNeedData(
$segment['suggestedValuesCallback']);
if (!$suggestedValuesCallbackRequiresTable) {
return call_user_func($segment['suggestedValuesCallback'], $idSite, $maxSuggestionsToReturn);
}
}
// if period=range is disabled, do not proceed
if (!Period\Factory::isPeriodEnabledForAPI('range')) {
return array();
}
if (!empty($segment['unionOfSegments'])) {
$values = array();
foreach ($segment['unionOfSegments'] as $unionSegmentName) {
$unionSegment = $this->findSegment($unionSegmentName, $idSite);
try {
$result = $this->getSuggestedValuesForSegmentName($idSite, $unionSegment, $maxSuggestionsToReturn);
if (!empty($result)) {
$values = array_merge($result, $values);
}
} catch (\Exception $e) {
// we ignore if there was no data found for $unionSegmentName
}
}
if (empty($values)) {
throw new \Exception("There was no data to suggest for $segmentName");
}
} else {
$values = $this->getSuggestedValuesForSegmentName($idSite, $segment, $maxSuggestionsToReturn);
}
$values = $this->getMostFrequentValues($values);
$values = array_slice($values, 0, $maxSuggestionsToReturn);
$values = array_map(array('Piwik\Common', 'unsanitizeInputValue'), $values);
return $values;
} | [
"public",
"function",
"getSuggestedValuesForSegment",
"(",
"$",
"segmentName",
",",
"$",
"idSite",
")",
"{",
"if",
"(",
"empty",
"(",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"General",
"[",
"'enable_segment_suggested_values'",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"idSite",
")",
";",
"$",
"maxSuggestionsToReturn",
"=",
"30",
";",
"$",
"segment",
"=",
"$",
"this",
"->",
"findSegment",
"(",
"$",
"segmentName",
",",
"$",
"idSite",
")",
";",
"// if segment has suggested values callback then return result from it instead",
"$",
"suggestedValuesCallbackRequiresTable",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"segment",
"[",
"'suggestedValuesCallback'",
"]",
")",
")",
"{",
"$",
"suggestedValuesCallbackRequiresTable",
"=",
"$",
"this",
"->",
"doesSuggestedValuesCallbackNeedData",
"(",
"$",
"segment",
"[",
"'suggestedValuesCallback'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"suggestedValuesCallbackRequiresTable",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"segment",
"[",
"'suggestedValuesCallback'",
"]",
",",
"$",
"idSite",
",",
"$",
"maxSuggestionsToReturn",
")",
";",
"}",
"}",
"// if period=range is disabled, do not proceed",
"if",
"(",
"!",
"Period",
"\\",
"Factory",
"::",
"isPeriodEnabledForAPI",
"(",
"'range'",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"segment",
"[",
"'unionOfSegments'",
"]",
")",
")",
"{",
"$",
"values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"segment",
"[",
"'unionOfSegments'",
"]",
"as",
"$",
"unionSegmentName",
")",
"{",
"$",
"unionSegment",
"=",
"$",
"this",
"->",
"findSegment",
"(",
"$",
"unionSegmentName",
",",
"$",
"idSite",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getSuggestedValuesForSegmentName",
"(",
"$",
"idSite",
",",
"$",
"unionSegment",
",",
"$",
"maxSuggestionsToReturn",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"values",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// we ignore if there was no data found for $unionSegmentName",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"There was no data to suggest for $segmentName\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"getSuggestedValuesForSegmentName",
"(",
"$",
"idSite",
",",
"$",
"segment",
",",
"$",
"maxSuggestionsToReturn",
")",
";",
"}",
"$",
"values",
"=",
"$",
"this",
"->",
"getMostFrequentValues",
"(",
"$",
"values",
")",
";",
"$",
"values",
"=",
"array_slice",
"(",
"$",
"values",
",",
"0",
",",
"$",
"maxSuggestionsToReturn",
")",
";",
"$",
"values",
"=",
"array_map",
"(",
"array",
"(",
"'Piwik\\Common'",
",",
"'unsanitizeInputValue'",
")",
",",
"$",
"values",
")",
";",
"return",
"$",
"values",
";",
"}"
] | Given a segment, will return a list of the most used values for this particular segment.
@param $segmentName
@param $idSite
@throws \Exception
@return array | [
"Given",
"a",
"segment",
"will",
"return",
"a",
"list",
"of",
"the",
"most",
"used",
"values",
"for",
"this",
"particular",
"segment",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/API/API.php#L566-L621 |
210,098 | matomo-org/matomo | core/DataTable/Renderer/Php.php | Php.flatRender | public function flatRender($dataTable = null)
{
if (is_null($dataTable)) {
$dataTable = $this->table;
}
if (is_array($dataTable)) {
$flatArray = $dataTable;
if (self::shouldWrapArrayBeforeRendering($flatArray)) {
$flatArray = array($flatArray);
}
} elseif ($dataTable instanceof DataTable\Map) {
$flatArray = array();
foreach ($dataTable->getDataTables() as $keyName => $table) {
$serializeSave = $this->serialize;
$this->serialize = false;
$flatArray[$keyName] = $this->flatRender($table);
$this->serialize = $serializeSave;
}
} elseif ($dataTable instanceof Simple) {
$flatArray = $this->renderSimpleTable($dataTable);
// if we return only one numeric value then we print out the result in a simple <result> tag
// keep it simple!
if (count($flatArray) == 1) {
$flatArray = current($flatArray);
}
} // A normal DataTable needs to be handled specifically
else {
$array = $this->renderTable($dataTable);
$flatArray = $this->flattenArray($array);
}
if ($this->serialize) {
$flatArray = serialize($flatArray);
}
return $flatArray;
} | php | public function flatRender($dataTable = null)
{
if (is_null($dataTable)) {
$dataTable = $this->table;
}
if (is_array($dataTable)) {
$flatArray = $dataTable;
if (self::shouldWrapArrayBeforeRendering($flatArray)) {
$flatArray = array($flatArray);
}
} elseif ($dataTable instanceof DataTable\Map) {
$flatArray = array();
foreach ($dataTable->getDataTables() as $keyName => $table) {
$serializeSave = $this->serialize;
$this->serialize = false;
$flatArray[$keyName] = $this->flatRender($table);
$this->serialize = $serializeSave;
}
} elseif ($dataTable instanceof Simple) {
$flatArray = $this->renderSimpleTable($dataTable);
// if we return only one numeric value then we print out the result in a simple <result> tag
// keep it simple!
if (count($flatArray) == 1) {
$flatArray = current($flatArray);
}
} // A normal DataTable needs to be handled specifically
else {
$array = $this->renderTable($dataTable);
$flatArray = $this->flattenArray($array);
}
if ($this->serialize) {
$flatArray = serialize($flatArray);
}
return $flatArray;
} | [
"public",
"function",
"flatRender",
"(",
"$",
"dataTable",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"dataTable",
")",
")",
"{",
"$",
"dataTable",
"=",
"$",
"this",
"->",
"table",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"dataTable",
")",
")",
"{",
"$",
"flatArray",
"=",
"$",
"dataTable",
";",
"if",
"(",
"self",
"::",
"shouldWrapArrayBeforeRendering",
"(",
"$",
"flatArray",
")",
")",
"{",
"$",
"flatArray",
"=",
"array",
"(",
"$",
"flatArray",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"dataTable",
"instanceof",
"DataTable",
"\\",
"Map",
")",
"{",
"$",
"flatArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"dataTable",
"->",
"getDataTables",
"(",
")",
"as",
"$",
"keyName",
"=>",
"$",
"table",
")",
"{",
"$",
"serializeSave",
"=",
"$",
"this",
"->",
"serialize",
";",
"$",
"this",
"->",
"serialize",
"=",
"false",
";",
"$",
"flatArray",
"[",
"$",
"keyName",
"]",
"=",
"$",
"this",
"->",
"flatRender",
"(",
"$",
"table",
")",
";",
"$",
"this",
"->",
"serialize",
"=",
"$",
"serializeSave",
";",
"}",
"}",
"elseif",
"(",
"$",
"dataTable",
"instanceof",
"Simple",
")",
"{",
"$",
"flatArray",
"=",
"$",
"this",
"->",
"renderSimpleTable",
"(",
"$",
"dataTable",
")",
";",
"// if we return only one numeric value then we print out the result in a simple <result> tag",
"// keep it simple!",
"if",
"(",
"count",
"(",
"$",
"flatArray",
")",
"==",
"1",
")",
"{",
"$",
"flatArray",
"=",
"current",
"(",
"$",
"flatArray",
")",
";",
"}",
"}",
"// A normal DataTable needs to be handled specifically",
"else",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"renderTable",
"(",
"$",
"dataTable",
")",
";",
"$",
"flatArray",
"=",
"$",
"this",
"->",
"flattenArray",
"(",
"$",
"array",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"serialize",
")",
"{",
"$",
"flatArray",
"=",
"serialize",
"(",
"$",
"flatArray",
")",
";",
"}",
"return",
"$",
"flatArray",
";",
"}"
] | Produces a flat php array from the DataTable, putting "columns" and "metadata" on the same level.
For example, when a originalRender() would be
array( 'columns' => array( 'col1_name' => value1, 'col2_name' => value2 ),
'metadata' => array( 'metadata1_name' => value_metadata) )
a flatRender() is
array( 'col1_name' => value1,
'col2_name' => value2,
'metadata1_name' => value_metadata )
@param null|DataTable|DataTable\Map|Simple $dataTable
@return array Php array representing the 'flat' version of the datatable | [
"Produces",
"a",
"flat",
"php",
"array",
"from",
"the",
"DataTable",
"putting",
"columns",
"and",
"metadata",
"on",
"the",
"same",
"level",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Renderer/Php.php#L103-L141 |
210,099 | matomo-org/matomo | core/DataTable/Renderer/Php.php | Php.originalRender | public function originalRender()
{
Piwik::checkObjectTypeIs($this->table, array('Simple', 'DataTable'));
if ($this->table instanceof Simple) {
$array = $this->renderSimpleTable($this->table);
} elseif ($this->table instanceof DataTable) {
$array = $this->renderTable($this->table);
}
if ($this->serialize) {
$array = serialize($array);
}
return $array;
} | php | public function originalRender()
{
Piwik::checkObjectTypeIs($this->table, array('Simple', 'DataTable'));
if ($this->table instanceof Simple) {
$array = $this->renderSimpleTable($this->table);
} elseif ($this->table instanceof DataTable) {
$array = $this->renderTable($this->table);
}
if ($this->serialize) {
$array = serialize($array);
}
return $array;
} | [
"public",
"function",
"originalRender",
"(",
")",
"{",
"Piwik",
"::",
"checkObjectTypeIs",
"(",
"$",
"this",
"->",
"table",
",",
"array",
"(",
"'Simple'",
",",
"'DataTable'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"table",
"instanceof",
"Simple",
")",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"renderSimpleTable",
"(",
"$",
"this",
"->",
"table",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"table",
"instanceof",
"DataTable",
")",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"renderTable",
"(",
"$",
"this",
"->",
"table",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"serialize",
")",
"{",
"$",
"array",
"=",
"serialize",
"(",
"$",
"array",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Converts the current data table to an array
@return array
@throws Exception | [
"Converts",
"the",
"current",
"data",
"table",
"to",
"an",
"array"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable/Renderer/Php.php#L172-L186 |
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.