id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
209,400 | matomo-org/matomo | core/DataTable.php | DataTable.deleteRow | public function deleteRow($id)
{
if ($id === self::ID_SUMMARY_ROW) {
$this->summaryRow = null;
return;
}
if (!isset($this->rows[$id])) {
throw new Exception("Trying to delete unknown row with idkey = $id");
}
unset($this->rows[$id]);
} | php | public function deleteRow($id)
{
if ($id === self::ID_SUMMARY_ROW) {
$this->summaryRow = null;
return;
}
if (!isset($this->rows[$id])) {
throw new Exception("Trying to delete unknown row with idkey = $id");
}
unset($this->rows[$id]);
} | [
"public",
"function",
"deleteRow",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"self",
"::",
"ID_SUMMARY_ROW",
")",
"{",
"$",
"this",
"->",
"summaryRow",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rows",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Trying to delete unknown row with idkey = $id\"",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"rows",
"[",
"$",
"id",
"]",
")",
";",
"}"
] | Deletes a row by ID.
@param int $id The row ID.
@throws Exception If the row `$id` cannot be found. | [
"Deletes",
"a",
"row",
"by",
"ID",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1139-L1149 |
209,401 | matomo-org/matomo | core/DataTable.php | DataTable.isEqual | public static function isEqual(DataTable $table1, DataTable $table2)
{
$table1->rebuildIndex();
$table2->rebuildIndex();
if ($table1->getRowsCount() != $table2->getRowsCount()) {
return false;
}
$rows1 = $table1->getRows();
foreach ($rows1 as $row1) {
$row2 = $table2->getRowFromLabel($row1->getColumn('label'));
if ($row2 === false
|| !Row::isEqual($row1, $row2)
) {
return false;
}
}
return true;
} | php | public static function isEqual(DataTable $table1, DataTable $table2)
{
$table1->rebuildIndex();
$table2->rebuildIndex();
if ($table1->getRowsCount() != $table2->getRowsCount()) {
return false;
}
$rows1 = $table1->getRows();
foreach ($rows1 as $row1) {
$row2 = $table2->getRowFromLabel($row1->getColumn('label'));
if ($row2 === false
|| !Row::isEqual($row1, $row2)
) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"isEqual",
"(",
"DataTable",
"$",
"table1",
",",
"DataTable",
"$",
"table2",
")",
"{",
"$",
"table1",
"->",
"rebuildIndex",
"(",
")",
";",
"$",
"table2",
"->",
"rebuildIndex",
"(",
")",
";",
"if",
"(",
"$",
"table1",
"->",
"getRowsCount",
"(",
")",
"!=",
"$",
"table2",
"->",
"getRowsCount",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"rows1",
"=",
"$",
"table1",
"->",
"getRows",
"(",
")",
";",
"foreach",
"(",
"$",
"rows1",
"as",
"$",
"row1",
")",
"{",
"$",
"row2",
"=",
"$",
"table2",
"->",
"getRowFromLabel",
"(",
"$",
"row1",
"->",
"getColumn",
"(",
"'label'",
")",
")",
";",
"if",
"(",
"$",
"row2",
"===",
"false",
"||",
"!",
"Row",
"::",
"isEqual",
"(",
"$",
"row1",
",",
"$",
"row2",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Returns true if both DataTable instances are exactly the same.
DataTables are equal if they have the same number of rows, if
each row has a label that exists in the other table, and if each row
is equal to the row in the other table with the same label. The order
of rows is not important.
@param \Piwik\DataTable $table1
@param \Piwik\DataTable $table2
@return bool | [
"Returns",
"true",
"if",
"both",
"DataTable",
"instances",
"are",
"exactly",
"the",
"same",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1225-L1246 |
209,402 | matomo-org/matomo | core/DataTable.php | DataTable.getSerialized | public function getSerialized($maximumRowsInDataTable = null,
$maximumRowsInSubDataTable = null,
$columnToSortByBeforeTruncation = null,
&$aSerializedDataTable = array())
{
static $depth = 0;
// make sure subtableIds are consecutive from 1 to N
static $subtableId = 0;
if ($depth > self::$maximumDepthLevelAllowed) {
$depth = 0;
$subtableId = 0;
throw new Exception("Maximum recursion level of " . self::$maximumDepthLevelAllowed . " reached. Maybe you have set a DataTable\Row with an associated DataTable belonging already to one of its parent tables?");
}
if (!is_null($maximumRowsInDataTable)) {
$this->filter('Truncate',
array($maximumRowsInDataTable - 1,
DataTable::LABEL_SUMMARY_ROW,
$columnToSortByBeforeTruncation,
$filterRecursive = false)
);
}
$consecutiveSubtableIds = array();
$forcedId = $subtableId;
// For each row, get the serialized row
// If it is associated to a sub table, get the serialized table recursively ;
// but returns all serialized tables and subtable in an array of 1 dimension
foreach ($this->rows as $id => $row) {
$subTable = $row->getSubtable();
if ($subTable) {
$consecutiveSubtableIds[$id] = ++$subtableId;
$depth++;
$subTable->getSerialized($maximumRowsInSubDataTable, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation, $aSerializedDataTable);
$depth--;
} else {
$row->removeSubtable();
}
}
// if the datatable is the parent we force the Id at 0 (this is part of the specification)
if ($depth == 0) {
$forcedId = 0;
$subtableId = 0;
}
// we then serialize the rows and store them in the serialized dataTable
$rows = array();
foreach ($this->rows as $id => $row) {
if (isset($consecutiveSubtableIds[$id])) {
$backup = $row->subtableId;
$row->subtableId = $consecutiveSubtableIds[$id];
$rows[$id] = $row->export();
$row->subtableId = $backup;
} else {
$rows[$id] = $row->export();
}
}
if (isset($this->summaryRow)) {
$rows[self::ID_SUMMARY_ROW] = $this->summaryRow->export();
}
$aSerializedDataTable[$forcedId] = serialize($rows);
unset($rows);
return $aSerializedDataTable;
} | php | public function getSerialized($maximumRowsInDataTable = null,
$maximumRowsInSubDataTable = null,
$columnToSortByBeforeTruncation = null,
&$aSerializedDataTable = array())
{
static $depth = 0;
// make sure subtableIds are consecutive from 1 to N
static $subtableId = 0;
if ($depth > self::$maximumDepthLevelAllowed) {
$depth = 0;
$subtableId = 0;
throw new Exception("Maximum recursion level of " . self::$maximumDepthLevelAllowed . " reached. Maybe you have set a DataTable\Row with an associated DataTable belonging already to one of its parent tables?");
}
if (!is_null($maximumRowsInDataTable)) {
$this->filter('Truncate',
array($maximumRowsInDataTable - 1,
DataTable::LABEL_SUMMARY_ROW,
$columnToSortByBeforeTruncation,
$filterRecursive = false)
);
}
$consecutiveSubtableIds = array();
$forcedId = $subtableId;
// For each row, get the serialized row
// If it is associated to a sub table, get the serialized table recursively ;
// but returns all serialized tables and subtable in an array of 1 dimension
foreach ($this->rows as $id => $row) {
$subTable = $row->getSubtable();
if ($subTable) {
$consecutiveSubtableIds[$id] = ++$subtableId;
$depth++;
$subTable->getSerialized($maximumRowsInSubDataTable, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation, $aSerializedDataTable);
$depth--;
} else {
$row->removeSubtable();
}
}
// if the datatable is the parent we force the Id at 0 (this is part of the specification)
if ($depth == 0) {
$forcedId = 0;
$subtableId = 0;
}
// we then serialize the rows and store them in the serialized dataTable
$rows = array();
foreach ($this->rows as $id => $row) {
if (isset($consecutiveSubtableIds[$id])) {
$backup = $row->subtableId;
$row->subtableId = $consecutiveSubtableIds[$id];
$rows[$id] = $row->export();
$row->subtableId = $backup;
} else {
$rows[$id] = $row->export();
}
}
if (isset($this->summaryRow)) {
$rows[self::ID_SUMMARY_ROW] = $this->summaryRow->export();
}
$aSerializedDataTable[$forcedId] = serialize($rows);
unset($rows);
return $aSerializedDataTable;
} | [
"public",
"function",
"getSerialized",
"(",
"$",
"maximumRowsInDataTable",
"=",
"null",
",",
"$",
"maximumRowsInSubDataTable",
"=",
"null",
",",
"$",
"columnToSortByBeforeTruncation",
"=",
"null",
",",
"&",
"$",
"aSerializedDataTable",
"=",
"array",
"(",
")",
")",
"{",
"static",
"$",
"depth",
"=",
"0",
";",
"// make sure subtableIds are consecutive from 1 to N",
"static",
"$",
"subtableId",
"=",
"0",
";",
"if",
"(",
"$",
"depth",
">",
"self",
"::",
"$",
"maximumDepthLevelAllowed",
")",
"{",
"$",
"depth",
"=",
"0",
";",
"$",
"subtableId",
"=",
"0",
";",
"throw",
"new",
"Exception",
"(",
"\"Maximum recursion level of \"",
".",
"self",
"::",
"$",
"maximumDepthLevelAllowed",
".",
"\" reached. Maybe you have set a DataTable\\Row with an associated DataTable belonging already to one of its parent tables?\"",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"maximumRowsInDataTable",
")",
")",
"{",
"$",
"this",
"->",
"filter",
"(",
"'Truncate'",
",",
"array",
"(",
"$",
"maximumRowsInDataTable",
"-",
"1",
",",
"DataTable",
"::",
"LABEL_SUMMARY_ROW",
",",
"$",
"columnToSortByBeforeTruncation",
",",
"$",
"filterRecursive",
"=",
"false",
")",
")",
";",
"}",
"$",
"consecutiveSubtableIds",
"=",
"array",
"(",
")",
";",
"$",
"forcedId",
"=",
"$",
"subtableId",
";",
"// For each row, get the serialized row",
"// If it is associated to a sub table, get the serialized table recursively ;",
"// but returns all serialized tables and subtable in an array of 1 dimension",
"foreach",
"(",
"$",
"this",
"->",
"rows",
"as",
"$",
"id",
"=>",
"$",
"row",
")",
"{",
"$",
"subTable",
"=",
"$",
"row",
"->",
"getSubtable",
"(",
")",
";",
"if",
"(",
"$",
"subTable",
")",
"{",
"$",
"consecutiveSubtableIds",
"[",
"$",
"id",
"]",
"=",
"++",
"$",
"subtableId",
";",
"$",
"depth",
"++",
";",
"$",
"subTable",
"->",
"getSerialized",
"(",
"$",
"maximumRowsInSubDataTable",
",",
"$",
"maximumRowsInSubDataTable",
",",
"$",
"columnToSortByBeforeTruncation",
",",
"$",
"aSerializedDataTable",
")",
";",
"$",
"depth",
"--",
";",
"}",
"else",
"{",
"$",
"row",
"->",
"removeSubtable",
"(",
")",
";",
"}",
"}",
"// if the datatable is the parent we force the Id at 0 (this is part of the specification)",
"if",
"(",
"$",
"depth",
"==",
"0",
")",
"{",
"$",
"forcedId",
"=",
"0",
";",
"$",
"subtableId",
"=",
"0",
";",
"}",
"// we then serialize the rows and store them in the serialized dataTable",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rows",
"as",
"$",
"id",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"consecutiveSubtableIds",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"backup",
"=",
"$",
"row",
"->",
"subtableId",
";",
"$",
"row",
"->",
"subtableId",
"=",
"$",
"consecutiveSubtableIds",
"[",
"$",
"id",
"]",
";",
"$",
"rows",
"[",
"$",
"id",
"]",
"=",
"$",
"row",
"->",
"export",
"(",
")",
";",
"$",
"row",
"->",
"subtableId",
"=",
"$",
"backup",
";",
"}",
"else",
"{",
"$",
"rows",
"[",
"$",
"id",
"]",
"=",
"$",
"row",
"->",
"export",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"summaryRow",
")",
")",
"{",
"$",
"rows",
"[",
"self",
"::",
"ID_SUMMARY_ROW",
"]",
"=",
"$",
"this",
"->",
"summaryRow",
"->",
"export",
"(",
")",
";",
"}",
"$",
"aSerializedDataTable",
"[",
"$",
"forcedId",
"]",
"=",
"serialize",
"(",
"$",
"rows",
")",
";",
"unset",
"(",
"$",
"rows",
")",
";",
"return",
"$",
"aSerializedDataTable",
";",
"}"
] | Serializes an entire DataTable hierarchy and returns the array of serialized DataTables.
The first element in the returned array will be the serialized representation of this DataTable.
Every subsequent element will be a serialized subtable.
This DataTable and subtables can optionally be truncated before being serialized. In most
cases where DataTables can become quite large, they should be truncated before being persisted
in an archive.
The result of this method is intended for use with the {@link ArchiveProcessor::insertBlobRecord()} method.
@throws Exception If infinite recursion detected. This will occur if a table's subtable is one of its parent tables.
@param int $maximumRowsInDataTable If not null, defines the maximum number of rows allowed in the serialized DataTable.
@param int $maximumRowsInSubDataTable If not null, defines the maximum number of rows allowed in serialized subtables.
@param string $columnToSortByBeforeTruncation The column to sort by before truncating, eg, `Metrics::INDEX_NB_VISITS`.
@param array $aSerializedDataTable Will contain all the output arrays
@return array The array of serialized DataTables:
array(
// this DataTable (the root)
0 => 'eghuighahgaueytae78yaet7yaetae',
// a subtable
1 => 'gaegae gh gwrh guiwh uigwhuige',
// another subtable
2 => 'gqegJHUIGHEQjkgneqjgnqeugUGEQHGUHQE',
// etc.
); | [
"Serializes",
"an",
"entire",
"DataTable",
"hierarchy",
"and",
"returns",
"the",
"array",
"of",
"serialized",
"DataTables",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1280-L1348 |
209,403 | matomo-org/matomo | core/DataTable.php | DataTable.addRowsFromSerializedArray | public function addRowsFromSerializedArray($serialized)
{
$rows = $this->unserializeRows($serialized);
if (array_key_exists(self::ID_SUMMARY_ROW, $rows)) {
if (is_array($rows[self::ID_SUMMARY_ROW])) {
$this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]);
} elseif (isset($rows[self::ID_SUMMARY_ROW]->c)) {
$this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]->c); // Pre Piwik 2.13
}
unset($rows[self::ID_SUMMARY_ROW]);
}
foreach ($rows as $id => $row) {
if (isset($row->c)) {
$this->addRow(new Row($row->c)); // Pre Piwik 2.13
} else {
$this->addRow(new Row($row));
}
}
} | php | public function addRowsFromSerializedArray($serialized)
{
$rows = $this->unserializeRows($serialized);
if (array_key_exists(self::ID_SUMMARY_ROW, $rows)) {
if (is_array($rows[self::ID_SUMMARY_ROW])) {
$this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]);
} elseif (isset($rows[self::ID_SUMMARY_ROW]->c)) {
$this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]->c); // Pre Piwik 2.13
}
unset($rows[self::ID_SUMMARY_ROW]);
}
foreach ($rows as $id => $row) {
if (isset($row->c)) {
$this->addRow(new Row($row->c)); // Pre Piwik 2.13
} else {
$this->addRow(new Row($row));
}
}
} | [
"public",
"function",
"addRowsFromSerializedArray",
"(",
"$",
"serialized",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"unserializeRows",
"(",
"$",
"serialized",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"self",
"::",
"ID_SUMMARY_ROW",
",",
"$",
"rows",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"rows",
"[",
"self",
"::",
"ID_SUMMARY_ROW",
"]",
")",
")",
"{",
"$",
"this",
"->",
"summaryRow",
"=",
"new",
"Row",
"(",
"$",
"rows",
"[",
"self",
"::",
"ID_SUMMARY_ROW",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"rows",
"[",
"self",
"::",
"ID_SUMMARY_ROW",
"]",
"->",
"c",
")",
")",
"{",
"$",
"this",
"->",
"summaryRow",
"=",
"new",
"Row",
"(",
"$",
"rows",
"[",
"self",
"::",
"ID_SUMMARY_ROW",
"]",
"->",
"c",
")",
";",
"// Pre Piwik 2.13",
"}",
"unset",
"(",
"$",
"rows",
"[",
"self",
"::",
"ID_SUMMARY_ROW",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"id",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"row",
"->",
"c",
")",
")",
"{",
"$",
"this",
"->",
"addRow",
"(",
"new",
"Row",
"(",
"$",
"row",
"->",
"c",
")",
")",
";",
"// Pre Piwik 2.13",
"}",
"else",
"{",
"$",
"this",
"->",
"addRow",
"(",
"new",
"Row",
"(",
"$",
"row",
")",
")",
";",
"}",
"}",
"}"
] | Adds a set of rows from a serialized DataTable string.
See {@link serialize()}.
_Note: This function will successfully load DataTables serialized by Piwik 1.X._
@param string $serialized A string with the format of a string in the array returned by
{@link serialize()}.
@throws Exception if `$serialized` is invalid. | [
"Adds",
"a",
"set",
"of",
"rows",
"from",
"a",
"serialized",
"DataTable",
"string",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1392-L1412 |
209,404 | matomo-org/matomo | core/DataTable.php | DataTable.addRowsFromArray | public function addRowsFromArray($array)
{
foreach ($array as $id => $row) {
if (is_array($row)) {
$row = new Row($row);
}
if ($id == self::ID_SUMMARY_ROW) {
$this->summaryRow = $row;
} else {
$this->addRow($row);
}
}
} | php | public function addRowsFromArray($array)
{
foreach ($array as $id => $row) {
if (is_array($row)) {
$row = new Row($row);
}
if ($id == self::ID_SUMMARY_ROW) {
$this->summaryRow = $row;
} else {
$this->addRow($row);
}
}
} | [
"public",
"function",
"addRowsFromArray",
"(",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"id",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"row",
")",
")",
"{",
"$",
"row",
"=",
"new",
"Row",
"(",
"$",
"row",
")",
";",
"}",
"if",
"(",
"$",
"id",
"==",
"self",
"::",
"ID_SUMMARY_ROW",
")",
"{",
"$",
"this",
"->",
"summaryRow",
"=",
"$",
"row",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addRow",
"(",
"$",
"row",
")",
";",
"}",
"}",
"}"
] | Adds multiple rows from an array.
You can add row metadata with this method.
@param array $array Array with the following structure
array(
// row1
array(
Row::COLUMNS => array( col1_name => value1, col2_name => value2, ...),
Row::METADATA => array( metadata1_name => value1, ...), // see Row
),
// row2
array( ... ),
) | [
"Adds",
"multiple",
"rows",
"from",
"an",
"array",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1431-L1444 |
209,405 | matomo-org/matomo | core/DataTable.php | DataTable.addRowsFromSimpleArray | public function addRowsFromSimpleArray($array)
{
if (count($array) === 0) {
return;
}
$exceptionText = " Data structure returned is not convertible in the requested format." .
" Try to call this method with the parameters '&format=original&serialize=1'" .
"; you will get the original php data structure serialized." .
" The data structure looks like this: \n \$data = %s; ";
// first pass to see if the array has the structure
// array(col1_name => val1, col2_name => val2, etc.)
// with val* that are never arrays (only strings/numbers/bool/etc.)
// if we detect such a "simple" data structure we convert it to a row with the correct columns' names
$thisIsNotThatSimple = false;
foreach ($array as $columnValue) {
if (is_array($columnValue) || is_object($columnValue)) {
$thisIsNotThatSimple = true;
break;
}
}
if ($thisIsNotThatSimple === false) {
// case when the array is indexed by the default numeric index
if (array_keys($array) == array_keys(array_fill(0, count($array), true))) {
foreach ($array as $row) {
$this->addRow(new Row(array(Row::COLUMNS => array($row))));
}
} else {
$this->addRow(new Row(array(Row::COLUMNS => $array)));
}
// we have converted our simple array to one single row
// => we exit the method as the job is now finished
return;
}
foreach ($array as $key => $row) {
// stuff that looks like a line
if (is_array($row)) {
/**
* We make sure we can convert this PHP array without losing information.
* We are able to convert only simple php array (no strings keys, no sub arrays, etc.)
*
*/
// if the key is a string it means that some information was contained in this key.
// it cannot be lost during the conversion. Because we are not able to handle properly
// this key, we throw an explicit exception.
if (is_string($key)) {
// we define an exception we may throw if at one point we notice that we cannot handle the data structure
throw new Exception(sprintf($exceptionText, var_export($array, true)));
}
// if any of the sub elements of row is an array we cannot handle this data structure...
foreach ($row as $subRow) {
if (is_array($subRow)) {
throw new Exception(sprintf($exceptionText, var_export($array, true)));
}
}
$row = new Row(array(Row::COLUMNS => $row));
} // other (string, numbers...) => we build a line from this value
else {
$row = new Row(array(Row::COLUMNS => array($key => $row)));
}
$this->addRow($row);
}
} | php | public function addRowsFromSimpleArray($array)
{
if (count($array) === 0) {
return;
}
$exceptionText = " Data structure returned is not convertible in the requested format." .
" Try to call this method with the parameters '&format=original&serialize=1'" .
"; you will get the original php data structure serialized." .
" The data structure looks like this: \n \$data = %s; ";
// first pass to see if the array has the structure
// array(col1_name => val1, col2_name => val2, etc.)
// with val* that are never arrays (only strings/numbers/bool/etc.)
// if we detect such a "simple" data structure we convert it to a row with the correct columns' names
$thisIsNotThatSimple = false;
foreach ($array as $columnValue) {
if (is_array($columnValue) || is_object($columnValue)) {
$thisIsNotThatSimple = true;
break;
}
}
if ($thisIsNotThatSimple === false) {
// case when the array is indexed by the default numeric index
if (array_keys($array) == array_keys(array_fill(0, count($array), true))) {
foreach ($array as $row) {
$this->addRow(new Row(array(Row::COLUMNS => array($row))));
}
} else {
$this->addRow(new Row(array(Row::COLUMNS => $array)));
}
// we have converted our simple array to one single row
// => we exit the method as the job is now finished
return;
}
foreach ($array as $key => $row) {
// stuff that looks like a line
if (is_array($row)) {
/**
* We make sure we can convert this PHP array without losing information.
* We are able to convert only simple php array (no strings keys, no sub arrays, etc.)
*
*/
// if the key is a string it means that some information was contained in this key.
// it cannot be lost during the conversion. Because we are not able to handle properly
// this key, we throw an explicit exception.
if (is_string($key)) {
// we define an exception we may throw if at one point we notice that we cannot handle the data structure
throw new Exception(sprintf($exceptionText, var_export($array, true)));
}
// if any of the sub elements of row is an array we cannot handle this data structure...
foreach ($row as $subRow) {
if (is_array($subRow)) {
throw new Exception(sprintf($exceptionText, var_export($array, true)));
}
}
$row = new Row(array(Row::COLUMNS => $row));
} // other (string, numbers...) => we build a line from this value
else {
$row = new Row(array(Row::COLUMNS => array($key => $row)));
}
$this->addRow($row);
}
} | [
"public",
"function",
"addRowsFromSimpleArray",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"array",
")",
"===",
"0",
")",
"{",
"return",
";",
"}",
"$",
"exceptionText",
"=",
"\" Data structure returned is not convertible in the requested format.\"",
".",
"\" Try to call this method with the parameters '&format=original&serialize=1'\"",
".",
"\"; you will get the original php data structure serialized.\"",
".",
"\" The data structure looks like this: \\n \\$data = %s; \"",
";",
"// first pass to see if the array has the structure",
"// array(col1_name => val1, col2_name => val2, etc.)",
"// with val* that are never arrays (only strings/numbers/bool/etc.)",
"// if we detect such a \"simple\" data structure we convert it to a row with the correct columns' names",
"$",
"thisIsNotThatSimple",
"=",
"false",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"columnValue",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"columnValue",
")",
"||",
"is_object",
"(",
"$",
"columnValue",
")",
")",
"{",
"$",
"thisIsNotThatSimple",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"thisIsNotThatSimple",
"===",
"false",
")",
"{",
"// case when the array is indexed by the default numeric index",
"if",
"(",
"array_keys",
"(",
"$",
"array",
")",
"==",
"array_keys",
"(",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"array",
")",
",",
"true",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"addRow",
"(",
"new",
"Row",
"(",
"array",
"(",
"Row",
"::",
"COLUMNS",
"=>",
"array",
"(",
"$",
"row",
")",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"addRow",
"(",
"new",
"Row",
"(",
"array",
"(",
"Row",
"::",
"COLUMNS",
"=>",
"$",
"array",
")",
")",
")",
";",
"}",
"// we have converted our simple array to one single row",
"// => we exit the method as the job is now finished",
"return",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"// stuff that looks like a line",
"if",
"(",
"is_array",
"(",
"$",
"row",
")",
")",
"{",
"/**\n * We make sure we can convert this PHP array without losing information.\n * We are able to convert only simple php array (no strings keys, no sub arrays, etc.)\n *\n */",
"// if the key is a string it means that some information was contained in this key.",
"// it cannot be lost during the conversion. Because we are not able to handle properly",
"// this key, we throw an explicit exception.",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"// we define an exception we may throw if at one point we notice that we cannot handle the data structure",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"$",
"exceptionText",
",",
"var_export",
"(",
"$",
"array",
",",
"true",
")",
")",
")",
";",
"}",
"// if any of the sub elements of row is an array we cannot handle this data structure...",
"foreach",
"(",
"$",
"row",
"as",
"$",
"subRow",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"subRow",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"$",
"exceptionText",
",",
"var_export",
"(",
"$",
"array",
",",
"true",
")",
")",
")",
";",
"}",
"}",
"$",
"row",
"=",
"new",
"Row",
"(",
"array",
"(",
"Row",
"::",
"COLUMNS",
"=>",
"$",
"row",
")",
")",
";",
"}",
"// other (string, numbers...) => we build a line from this value",
"else",
"{",
"$",
"row",
"=",
"new",
"Row",
"(",
"array",
"(",
"Row",
"::",
"COLUMNS",
"=>",
"array",
"(",
"$",
"key",
"=>",
"$",
"row",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"addRow",
"(",
"$",
"row",
")",
";",
"}",
"}"
] | Adds multiple rows from an array containing arrays of column values.
Row metadata cannot be added with this method.
@param array $array Array with the following structure:
array(
array( col1_name => valueA, col2_name => valueC, ...),
array( col1_name => valueB, col2_name => valueD, ...),
)
@throws Exception if `$array` is in an incorrect format. | [
"Adds",
"multiple",
"rows",
"from",
"an",
"array",
"containing",
"arrays",
"of",
"column",
"values",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1459-L1525 |
209,406 | matomo-org/matomo | core/DataTable.php | DataTable.setMetadataValues | public function setMetadataValues($values)
{
foreach ($values as $name => $value) {
$this->metadata[$name] = $value;
}
} | php | public function setMetadataValues($values)
{
foreach ($values as $name => $value) {
$this->metadata[$name] = $value;
}
} | [
"public",
"function",
"setMetadataValues",
"(",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"metadata",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Sets several metadata values by name.
@param array $values Array mapping metadata names with metadata values. | [
"Sets",
"several",
"metadata",
"values",
"by",
"name",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1639-L1644 |
209,407 | matomo-org/matomo | core/DataTable.php | DataTable.walkPath | public function walkPath($path, $missingRowColumns = false, $maxSubtableRows = 0)
{
$pathLength = count($path);
$table = $this;
$next = false;
for ($i = 0; $i < $pathLength; ++$i) {
$segment = $path[$i];
$next = $table->getRowFromLabel($segment);
if ($next === false) {
// if there is no table to advance to, and we're not adding missing rows, return false
if ($missingRowColumns === false) {
return array(false, $i);
} else {
// if we're adding missing rows, add a new row
$row = new DataTableSummaryRow();
$row->setColumns(array('label' => $segment) + $missingRowColumns);
$next = $table->addRow($row);
if ($next !== $row) {
// if the row wasn't added, the table is full
// Summary row, has no metadata
$next->deleteMetadata();
return array($next, $i);
}
}
}
$table = $next->getSubtable();
if ($table === false) {
// if the row has no table (and thus no child rows), and we're not adding
// missing rows, return false
if ($missingRowColumns === false) {
return array(false, $i);
} elseif ($i != $pathLength - 1) {
// create subtable if missing, but only if not on the last segment
$table = new DataTable();
$table->setMaximumAllowedRows($maxSubtableRows);
$table->metadata[self::COLUMN_AGGREGATION_OPS_METADATA_NAME]
= $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME);
$next->setSubtable($table);
// Summary row, has no metadata
$next->deleteMetadata();
}
}
}
return array($next, $i);
} | php | public function walkPath($path, $missingRowColumns = false, $maxSubtableRows = 0)
{
$pathLength = count($path);
$table = $this;
$next = false;
for ($i = 0; $i < $pathLength; ++$i) {
$segment = $path[$i];
$next = $table->getRowFromLabel($segment);
if ($next === false) {
// if there is no table to advance to, and we're not adding missing rows, return false
if ($missingRowColumns === false) {
return array(false, $i);
} else {
// if we're adding missing rows, add a new row
$row = new DataTableSummaryRow();
$row->setColumns(array('label' => $segment) + $missingRowColumns);
$next = $table->addRow($row);
if ($next !== $row) {
// if the row wasn't added, the table is full
// Summary row, has no metadata
$next->deleteMetadata();
return array($next, $i);
}
}
}
$table = $next->getSubtable();
if ($table === false) {
// if the row has no table (and thus no child rows), and we're not adding
// missing rows, return false
if ($missingRowColumns === false) {
return array(false, $i);
} elseif ($i != $pathLength - 1) {
// create subtable if missing, but only if not on the last segment
$table = new DataTable();
$table->setMaximumAllowedRows($maxSubtableRows);
$table->metadata[self::COLUMN_AGGREGATION_OPS_METADATA_NAME]
= $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME);
$next->setSubtable($table);
// Summary row, has no metadata
$next->deleteMetadata();
}
}
}
return array($next, $i);
} | [
"public",
"function",
"walkPath",
"(",
"$",
"path",
",",
"$",
"missingRowColumns",
"=",
"false",
",",
"$",
"maxSubtableRows",
"=",
"0",
")",
"{",
"$",
"pathLength",
"=",
"count",
"(",
"$",
"path",
")",
";",
"$",
"table",
"=",
"$",
"this",
";",
"$",
"next",
"=",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"pathLength",
";",
"++",
"$",
"i",
")",
"{",
"$",
"segment",
"=",
"$",
"path",
"[",
"$",
"i",
"]",
";",
"$",
"next",
"=",
"$",
"table",
"->",
"getRowFromLabel",
"(",
"$",
"segment",
")",
";",
"if",
"(",
"$",
"next",
"===",
"false",
")",
"{",
"// if there is no table to advance to, and we're not adding missing rows, return false",
"if",
"(",
"$",
"missingRowColumns",
"===",
"false",
")",
"{",
"return",
"array",
"(",
"false",
",",
"$",
"i",
")",
";",
"}",
"else",
"{",
"// if we're adding missing rows, add a new row",
"$",
"row",
"=",
"new",
"DataTableSummaryRow",
"(",
")",
";",
"$",
"row",
"->",
"setColumns",
"(",
"array",
"(",
"'label'",
"=>",
"$",
"segment",
")",
"+",
"$",
"missingRowColumns",
")",
";",
"$",
"next",
"=",
"$",
"table",
"->",
"addRow",
"(",
"$",
"row",
")",
";",
"if",
"(",
"$",
"next",
"!==",
"$",
"row",
")",
"{",
"// if the row wasn't added, the table is full",
"// Summary row, has no metadata",
"$",
"next",
"->",
"deleteMetadata",
"(",
")",
";",
"return",
"array",
"(",
"$",
"next",
",",
"$",
"i",
")",
";",
"}",
"}",
"}",
"$",
"table",
"=",
"$",
"next",
"->",
"getSubtable",
"(",
")",
";",
"if",
"(",
"$",
"table",
"===",
"false",
")",
"{",
"// if the row has no table (and thus no child rows), and we're not adding",
"// missing rows, return false",
"if",
"(",
"$",
"missingRowColumns",
"===",
"false",
")",
"{",
"return",
"array",
"(",
"false",
",",
"$",
"i",
")",
";",
"}",
"elseif",
"(",
"$",
"i",
"!=",
"$",
"pathLength",
"-",
"1",
")",
"{",
"// create subtable if missing, but only if not on the last segment",
"$",
"table",
"=",
"new",
"DataTable",
"(",
")",
";",
"$",
"table",
"->",
"setMaximumAllowedRows",
"(",
"$",
"maxSubtableRows",
")",
";",
"$",
"table",
"->",
"metadata",
"[",
"self",
"::",
"COLUMN_AGGREGATION_OPS_METADATA_NAME",
"]",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
"self",
"::",
"COLUMN_AGGREGATION_OPS_METADATA_NAME",
")",
";",
"$",
"next",
"->",
"setSubtable",
"(",
"$",
"table",
")",
";",
"// Summary row, has no metadata",
"$",
"next",
"->",
"deleteMetadata",
"(",
")",
";",
"}",
"}",
"}",
"return",
"array",
"(",
"$",
"next",
",",
"$",
"i",
")",
";",
"}"
] | Traverses a DataTable tree using an array of labels and returns the row
it finds or `false` if it cannot find one. The number of path segments that
were successfully walked is also returned.
If `$missingRowColumns` is supplied, the specified path is created. When
a subtable is encountered w/o the required label, a new row is created
with the label, and a new subtable is added to the row.
Read [http://en.wikipedia.org/wiki/Tree_(data_structure)#Traversal_methods](http://en.wikipedia.org/wiki/Tree_(data_structure)#Traversal_methods)
for more information about tree walking.
@param array $path The path to walk. An array of label values. The first element
refers to a row in this DataTable, the second in a subtable of
the first row, the third a subtable of the second row, etc.
@param array|bool $missingRowColumns The default columns to use when creating new rows.
If this parameter is supplied, new rows will be
created for path labels that cannot be found.
@param int $maxSubtableRows The maximum number of allowed rows in new subtables. New
subtables are only created if `$missingRowColumns` is provided.
@return array First element is the found row or `false`. Second element is
the number of path segments walked. If a row is found, this
will be == to `count($path)`. Otherwise, it will be the index
of the path segment that we could not find. | [
"Traverses",
"a",
"DataTable",
"tree",
"using",
"an",
"array",
"of",
"labels",
"and",
"returns",
"the",
"row",
"it",
"finds",
"or",
"false",
"if",
"it",
"cannot",
"find",
"one",
".",
"The",
"number",
"of",
"path",
"segments",
"that",
"were",
"successfully",
"walked",
"is",
"also",
"returned",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1693-L1746 |
209,408 | matomo-org/matomo | core/DataTable.php | DataTable.mergeSubtables | public function mergeSubtables($labelColumn = false, $useMetadataColumn = false)
{
$result = new DataTable();
$result->setAllTableMetadata($this->getAllTableMetadata());
foreach ($this->getRowsWithoutSummaryRow() as $row) {
$subtable = $row->getSubtable();
if ($subtable !== false) {
$parentLabel = $row->getColumn('label');
// add a copy of each subtable row to the new datatable
foreach ($subtable->getRows() as $id => $subRow) {
$copy = clone $subRow;
// if the summary row, add it to the existing summary row (or add a new one)
if ($id == self::ID_SUMMARY_ROW) {
$existing = $result->getRowFromId(self::ID_SUMMARY_ROW);
if ($existing === false) {
$result->addSummaryRow($copy);
} else {
$existing->sumRow($copy, $copyMeta = true, $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME));
}
} else {
if ($labelColumn !== false) {
// if we're modifying the subtable's rows' label column, then we make
// sure to prepend the existing label w/ the parent row's label. otherwise
// we're just adding the parent row's label as a new column/metadata.
$newLabel = $parentLabel;
if ($labelColumn == 'label') {
$newLabel .= ' - ' . $copy->getColumn('label');
}
// modify the child row's label or add new column/metadata
if ($useMetadataColumn) {
$copy->setMetadata($labelColumn, $newLabel);
} else {
$copy->setColumn($labelColumn, $newLabel);
}
}
$result->addRow($copy);
}
}
}
}
return $result;
} | php | public function mergeSubtables($labelColumn = false, $useMetadataColumn = false)
{
$result = new DataTable();
$result->setAllTableMetadata($this->getAllTableMetadata());
foreach ($this->getRowsWithoutSummaryRow() as $row) {
$subtable = $row->getSubtable();
if ($subtable !== false) {
$parentLabel = $row->getColumn('label');
// add a copy of each subtable row to the new datatable
foreach ($subtable->getRows() as $id => $subRow) {
$copy = clone $subRow;
// if the summary row, add it to the existing summary row (or add a new one)
if ($id == self::ID_SUMMARY_ROW) {
$existing = $result->getRowFromId(self::ID_SUMMARY_ROW);
if ($existing === false) {
$result->addSummaryRow($copy);
} else {
$existing->sumRow($copy, $copyMeta = true, $this->getMetadata(self::COLUMN_AGGREGATION_OPS_METADATA_NAME));
}
} else {
if ($labelColumn !== false) {
// if we're modifying the subtable's rows' label column, then we make
// sure to prepend the existing label w/ the parent row's label. otherwise
// we're just adding the parent row's label as a new column/metadata.
$newLabel = $parentLabel;
if ($labelColumn == 'label') {
$newLabel .= ' - ' . $copy->getColumn('label');
}
// modify the child row's label or add new column/metadata
if ($useMetadataColumn) {
$copy->setMetadata($labelColumn, $newLabel);
} else {
$copy->setColumn($labelColumn, $newLabel);
}
}
$result->addRow($copy);
}
}
}
}
return $result;
} | [
"public",
"function",
"mergeSubtables",
"(",
"$",
"labelColumn",
"=",
"false",
",",
"$",
"useMetadataColumn",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"new",
"DataTable",
"(",
")",
";",
"$",
"result",
"->",
"setAllTableMetadata",
"(",
"$",
"this",
"->",
"getAllTableMetadata",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getRowsWithoutSummaryRow",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"subtable",
"=",
"$",
"row",
"->",
"getSubtable",
"(",
")",
";",
"if",
"(",
"$",
"subtable",
"!==",
"false",
")",
"{",
"$",
"parentLabel",
"=",
"$",
"row",
"->",
"getColumn",
"(",
"'label'",
")",
";",
"// add a copy of each subtable row to the new datatable",
"foreach",
"(",
"$",
"subtable",
"->",
"getRows",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"subRow",
")",
"{",
"$",
"copy",
"=",
"clone",
"$",
"subRow",
";",
"// if the summary row, add it to the existing summary row (or add a new one)",
"if",
"(",
"$",
"id",
"==",
"self",
"::",
"ID_SUMMARY_ROW",
")",
"{",
"$",
"existing",
"=",
"$",
"result",
"->",
"getRowFromId",
"(",
"self",
"::",
"ID_SUMMARY_ROW",
")",
";",
"if",
"(",
"$",
"existing",
"===",
"false",
")",
"{",
"$",
"result",
"->",
"addSummaryRow",
"(",
"$",
"copy",
")",
";",
"}",
"else",
"{",
"$",
"existing",
"->",
"sumRow",
"(",
"$",
"copy",
",",
"$",
"copyMeta",
"=",
"true",
",",
"$",
"this",
"->",
"getMetadata",
"(",
"self",
"::",
"COLUMN_AGGREGATION_OPS_METADATA_NAME",
")",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"labelColumn",
"!==",
"false",
")",
"{",
"// if we're modifying the subtable's rows' label column, then we make",
"// sure to prepend the existing label w/ the parent row's label. otherwise",
"// we're just adding the parent row's label as a new column/metadata.",
"$",
"newLabel",
"=",
"$",
"parentLabel",
";",
"if",
"(",
"$",
"labelColumn",
"==",
"'label'",
")",
"{",
"$",
"newLabel",
".=",
"' - '",
".",
"$",
"copy",
"->",
"getColumn",
"(",
"'label'",
")",
";",
"}",
"// modify the child row's label or add new column/metadata",
"if",
"(",
"$",
"useMetadataColumn",
")",
"{",
"$",
"copy",
"->",
"setMetadata",
"(",
"$",
"labelColumn",
",",
"$",
"newLabel",
")",
";",
"}",
"else",
"{",
"$",
"copy",
"->",
"setColumn",
"(",
"$",
"labelColumn",
",",
"$",
"newLabel",
")",
";",
"}",
"}",
"$",
"result",
"->",
"addRow",
"(",
"$",
"copy",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns a new DataTable in which the rows of this table are replaced with the aggregatated rows of all its subtables.
@param string|bool $labelColumn If supplied the label of the parent row will be added to
a new column in each subtable row.
If set to, `'label'` each subtable row's label will be prepended
w/ the parent row's label. So `'child_label'` becomes
`'parent_label - child_label'`.
@param bool $useMetadataColumn If true and if `$labelColumn` is supplied, the parent row's
label will be added as metadata and not a new column.
@return \Piwik\DataTable | [
"Returns",
"a",
"new",
"DataTable",
"in",
"which",
"the",
"rows",
"of",
"this",
"table",
"are",
"replaced",
"with",
"the",
"aggregatated",
"rows",
"of",
"all",
"its",
"subtables",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataTable.php#L1761-L1806 |
209,409 | matomo-org/matomo | core/Segment/SegmentExpression.php | SegmentExpression.checkFieldIsAvailable | private function checkFieldIsAvailable($field, &$availableTables)
{
$fieldParts = explode('.', $field);
$table = count($fieldParts) == 2 ? $fieldParts[0] : false;
// remove sql functions from field name
// example: `HOUR(log_visit.visit_last_action_time)` gets `HOUR(log_visit` => remove `HOUR(`
$table = preg_replace('/^[A-Z_]+\(/', '', $table);
$tableExists = !$table || in_array($table, $availableTables);
if ($tableExists) {
return;
}
if (is_array($availableTables)) {
foreach ($availableTables as $availableTable) {
if (is_array($availableTable)) {
if (!isset($availableTable['tableAlias']) && $availableTable['table'] === $table) {
return;
} elseif (isset($availableTable['tableAlias']) && $availableTable['tableAlias'] === $table) {
return;
}
}
}
}
$availableTables[] = $table;
} | php | private function checkFieldIsAvailable($field, &$availableTables)
{
$fieldParts = explode('.', $field);
$table = count($fieldParts) == 2 ? $fieldParts[0] : false;
// remove sql functions from field name
// example: `HOUR(log_visit.visit_last_action_time)` gets `HOUR(log_visit` => remove `HOUR(`
$table = preg_replace('/^[A-Z_]+\(/', '', $table);
$tableExists = !$table || in_array($table, $availableTables);
if ($tableExists) {
return;
}
if (is_array($availableTables)) {
foreach ($availableTables as $availableTable) {
if (is_array($availableTable)) {
if (!isset($availableTable['tableAlias']) && $availableTable['table'] === $table) {
return;
} elseif (isset($availableTable['tableAlias']) && $availableTable['tableAlias'] === $table) {
return;
}
}
}
}
$availableTables[] = $table;
} | [
"private",
"function",
"checkFieldIsAvailable",
"(",
"$",
"field",
",",
"&",
"$",
"availableTables",
")",
"{",
"$",
"fieldParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
";",
"$",
"table",
"=",
"count",
"(",
"$",
"fieldParts",
")",
"==",
"2",
"?",
"$",
"fieldParts",
"[",
"0",
"]",
":",
"false",
";",
"// remove sql functions from field name",
"// example: `HOUR(log_visit.visit_last_action_time)` gets `HOUR(log_visit` => remove `HOUR(`",
"$",
"table",
"=",
"preg_replace",
"(",
"'/^[A-Z_]+\\(/'",
",",
"''",
",",
"$",
"table",
")",
";",
"$",
"tableExists",
"=",
"!",
"$",
"table",
"||",
"in_array",
"(",
"$",
"table",
",",
"$",
"availableTables",
")",
";",
"if",
"(",
"$",
"tableExists",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"availableTables",
")",
")",
"{",
"foreach",
"(",
"$",
"availableTables",
"as",
"$",
"availableTable",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"availableTable",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"availableTable",
"[",
"'tableAlias'",
"]",
")",
"&&",
"$",
"availableTable",
"[",
"'table'",
"]",
"===",
"$",
"table",
")",
"{",
"return",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"availableTable",
"[",
"'tableAlias'",
"]",
")",
"&&",
"$",
"availableTable",
"[",
"'tableAlias'",
"]",
"===",
"$",
"table",
")",
"{",
"return",
";",
"}",
"}",
"}",
"}",
"$",
"availableTables",
"[",
"]",
"=",
"$",
"table",
";",
"}"
] | Check whether the field is available
If not, add it to the available tables
@param string $field
@param array $availableTables | [
"Check",
"whether",
"the",
"field",
"is",
"available",
"If",
"not",
"add",
"it",
"to",
"the",
"available",
"tables"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Segment/SegmentExpression.php#L335-L363 |
209,410 | matomo-org/matomo | core/Segment/SegmentExpression.php | SegmentExpression.escapeLikeString | private function escapeLikeString($str)
{
if (false !== strpos($str, '%')) {
$str = str_replace("%", "\%", $str);
}
if (false !== strpos($str, '_')) {
$str = str_replace("_", "\_", $str);
}
return $str;
} | php | private function escapeLikeString($str)
{
if (false !== strpos($str, '%')) {
$str = str_replace("%", "\%", $str);
}
if (false !== strpos($str, '_')) {
$str = str_replace("_", "\_", $str);
}
return $str;
} | [
"private",
"function",
"escapeLikeString",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"str",
",",
"'%'",
")",
")",
"{",
"$",
"str",
"=",
"str_replace",
"(",
"\"%\"",
",",
"\"\\%\"",
",",
"$",
"str",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"str",
",",
"'_'",
")",
")",
"{",
"$",
"str",
"=",
"str_replace",
"(",
"\"_\"",
",",
"\"\\_\"",
",",
"$",
"str",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Escape the characters % and _ in the given string
@param string $str
@return string | [
"Escape",
"the",
"characters",
"%",
"and",
"_",
"in",
"the",
"given",
"string"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Segment/SegmentExpression.php#L370-L381 |
209,411 | matomo-org/matomo | core/Segment/SegmentExpression.php | SegmentExpression.parseTree | protected function parseTree()
{
$string = $this->string;
if (empty($string)) {
return array();
}
$tree = array();
$i = 0;
$length = strlen($string);
$isBackslash = false;
$operand = '';
while ($i <= $length) {
$char = $string[$i];
$isAND = ($char == self::AND_DELIMITER);
$isOR = ($char == self::OR_DELIMITER);
$isEnd = ($length == $i + 1);
if ($isEnd) {
if ($isBackslash && ($isAND || $isOR)) {
$operand = substr($operand, 0, -1);
}
$operand .= $char;
$tree[] = array(self::INDEX_BOOL_OPERATOR => self::BOOL_OPERATOR_END, self::INDEX_OPERAND => $operand);
break;
}
if ($isAND && !$isBackslash) {
$tree[] = array(self::INDEX_BOOL_OPERATOR => self::BOOL_OPERATOR_AND, self::INDEX_OPERAND => $operand);
$operand = '';
} elseif ($isOR && !$isBackslash) {
$tree[] = array(self::INDEX_BOOL_OPERATOR => self::BOOL_OPERATOR_OR, self::INDEX_OPERAND => $operand);
$operand = '';
} else {
if ($isBackslash && ($isAND || $isOR)) {
$operand = substr($operand, 0, -1);
}
$operand .= $char;
}
$isBackslash = ($char == "\\");
$i++;
}
return $tree;
} | php | protected function parseTree()
{
$string = $this->string;
if (empty($string)) {
return array();
}
$tree = array();
$i = 0;
$length = strlen($string);
$isBackslash = false;
$operand = '';
while ($i <= $length) {
$char = $string[$i];
$isAND = ($char == self::AND_DELIMITER);
$isOR = ($char == self::OR_DELIMITER);
$isEnd = ($length == $i + 1);
if ($isEnd) {
if ($isBackslash && ($isAND || $isOR)) {
$operand = substr($operand, 0, -1);
}
$operand .= $char;
$tree[] = array(self::INDEX_BOOL_OPERATOR => self::BOOL_OPERATOR_END, self::INDEX_OPERAND => $operand);
break;
}
if ($isAND && !$isBackslash) {
$tree[] = array(self::INDEX_BOOL_OPERATOR => self::BOOL_OPERATOR_AND, self::INDEX_OPERAND => $operand);
$operand = '';
} elseif ($isOR && !$isBackslash) {
$tree[] = array(self::INDEX_BOOL_OPERATOR => self::BOOL_OPERATOR_OR, self::INDEX_OPERAND => $operand);
$operand = '';
} else {
if ($isBackslash && ($isAND || $isOR)) {
$operand = substr($operand, 0, -1);
}
$operand .= $char;
}
$isBackslash = ($char == "\\");
$i++;
}
return $tree;
} | [
"protected",
"function",
"parseTree",
"(",
")",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"string",
";",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"tree",
"=",
"array",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"isBackslash",
"=",
"false",
";",
"$",
"operand",
"=",
"''",
";",
"while",
"(",
"$",
"i",
"<=",
"$",
"length",
")",
"{",
"$",
"char",
"=",
"$",
"string",
"[",
"$",
"i",
"]",
";",
"$",
"isAND",
"=",
"(",
"$",
"char",
"==",
"self",
"::",
"AND_DELIMITER",
")",
";",
"$",
"isOR",
"=",
"(",
"$",
"char",
"==",
"self",
"::",
"OR_DELIMITER",
")",
";",
"$",
"isEnd",
"=",
"(",
"$",
"length",
"==",
"$",
"i",
"+",
"1",
")",
";",
"if",
"(",
"$",
"isEnd",
")",
"{",
"if",
"(",
"$",
"isBackslash",
"&&",
"(",
"$",
"isAND",
"||",
"$",
"isOR",
")",
")",
"{",
"$",
"operand",
"=",
"substr",
"(",
"$",
"operand",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"$",
"operand",
".=",
"$",
"char",
";",
"$",
"tree",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"INDEX_BOOL_OPERATOR",
"=>",
"self",
"::",
"BOOL_OPERATOR_END",
",",
"self",
"::",
"INDEX_OPERAND",
"=>",
"$",
"operand",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"isAND",
"&&",
"!",
"$",
"isBackslash",
")",
"{",
"$",
"tree",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"INDEX_BOOL_OPERATOR",
"=>",
"self",
"::",
"BOOL_OPERATOR_AND",
",",
"self",
"::",
"INDEX_OPERAND",
"=>",
"$",
"operand",
")",
";",
"$",
"operand",
"=",
"''",
";",
"}",
"elseif",
"(",
"$",
"isOR",
"&&",
"!",
"$",
"isBackslash",
")",
"{",
"$",
"tree",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"INDEX_BOOL_OPERATOR",
"=>",
"self",
"::",
"BOOL_OPERATOR_OR",
",",
"self",
"::",
"INDEX_OPERAND",
"=>",
"$",
"operand",
")",
";",
"$",
"operand",
"=",
"''",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"isBackslash",
"&&",
"(",
"$",
"isAND",
"||",
"$",
"isOR",
")",
")",
"{",
"$",
"operand",
"=",
"substr",
"(",
"$",
"operand",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"$",
"operand",
".=",
"$",
"char",
";",
"}",
"$",
"isBackslash",
"=",
"(",
"$",
"char",
"==",
"\"\\\\\"",
")",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"tree",
";",
"}"
] | Given a filter string,
will parse it into an array where each row contains the boolean operator applied to it,
and the operand
@return array | [
"Given",
"a",
"filter",
"string",
"will",
"parse",
"it",
"into",
"an",
"array",
"where",
"each",
"row",
"contains",
"the",
"boolean",
"operator",
"applied",
"to",
"it",
"and",
"the",
"operand"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Segment/SegmentExpression.php#L390-L433 |
209,412 | matomo-org/matomo | core/Segment/SegmentExpression.php | SegmentExpression.getSql | public function getSql()
{
if ($this->isEmpty()) {
throw new Exception("Invalid segment, please specify a valid segment.");
}
$sql = '';
$subExpression = false;
foreach ($this->tree as $expression) {
$operator = $expression[self::INDEX_BOOL_OPERATOR];
$operand = $expression[self::INDEX_OPERAND];
if ($operator == self::BOOL_OPERATOR_OR
&& !$subExpression
) {
$sql .= ' (';
$subExpression = true;
} else {
$sql .= ' ';
}
$sql .= $operand;
if ($operator == self::BOOL_OPERATOR_AND
&& $subExpression
) {
$sql .= ')';
$subExpression = false;
}
$sql .= " $operator";
}
if ($subExpression) {
$sql .= ')';
}
return array(
'where' => $sql,
'bind' => $this->valuesBind,
'join' => implode(' ', $this->joins)
);
} | php | public function getSql()
{
if ($this->isEmpty()) {
throw new Exception("Invalid segment, please specify a valid segment.");
}
$sql = '';
$subExpression = false;
foreach ($this->tree as $expression) {
$operator = $expression[self::INDEX_BOOL_OPERATOR];
$operand = $expression[self::INDEX_OPERAND];
if ($operator == self::BOOL_OPERATOR_OR
&& !$subExpression
) {
$sql .= ' (';
$subExpression = true;
} else {
$sql .= ' ';
}
$sql .= $operand;
if ($operator == self::BOOL_OPERATOR_AND
&& $subExpression
) {
$sql .= ')';
$subExpression = false;
}
$sql .= " $operator";
}
if ($subExpression) {
$sql .= ')';
}
return array(
'where' => $sql,
'bind' => $this->valuesBind,
'join' => implode(' ', $this->joins)
);
} | [
"public",
"function",
"getSql",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid segment, please specify a valid segment.\"",
")",
";",
"}",
"$",
"sql",
"=",
"''",
";",
"$",
"subExpression",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"tree",
"as",
"$",
"expression",
")",
"{",
"$",
"operator",
"=",
"$",
"expression",
"[",
"self",
"::",
"INDEX_BOOL_OPERATOR",
"]",
";",
"$",
"operand",
"=",
"$",
"expression",
"[",
"self",
"::",
"INDEX_OPERAND",
"]",
";",
"if",
"(",
"$",
"operator",
"==",
"self",
"::",
"BOOL_OPERATOR_OR",
"&&",
"!",
"$",
"subExpression",
")",
"{",
"$",
"sql",
".=",
"' ('",
";",
"$",
"subExpression",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"sql",
".=",
"' '",
";",
"}",
"$",
"sql",
".=",
"$",
"operand",
";",
"if",
"(",
"$",
"operator",
"==",
"self",
"::",
"BOOL_OPERATOR_AND",
"&&",
"$",
"subExpression",
")",
"{",
"$",
"sql",
".=",
"')'",
";",
"$",
"subExpression",
"=",
"false",
";",
"}",
"$",
"sql",
".=",
"\" $operator\"",
";",
"}",
"if",
"(",
"$",
"subExpression",
")",
"{",
"$",
"sql",
".=",
"')'",
";",
"}",
"return",
"array",
"(",
"'where'",
"=>",
"$",
"sql",
",",
"'bind'",
"=>",
"$",
"this",
"->",
"valuesBind",
",",
"'join'",
"=>",
"implode",
"(",
"' '",
",",
"$",
"this",
"->",
"joins",
")",
")",
";",
"}"
] | Given the array of parsed boolean logic, will return
an array containing the full SQL string representing the filter,
the needed joins and the values to bind to the query
@throws Exception
@return array SQL Query, Joins and Bind parameters | [
"Given",
"the",
"array",
"of",
"parsed",
"boolean",
"logic",
"will",
"return",
"an",
"array",
"containing",
"the",
"full",
"SQL",
"string",
"representing",
"the",
"filter",
"the",
"needed",
"joins",
"and",
"the",
"values",
"to",
"bind",
"to",
"the",
"query"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Segment/SegmentExpression.php#L443-L482 |
209,413 | matomo-org/matomo | core/Tracker.php | Tracker.initCorePiwikInTrackerMode | public static function initCorePiwikInTrackerMode()
{
if (SettingsServer::isTrackerApiRequest()
&& self::$initTrackerMode === false
) {
self::$initTrackerMode = true;
require_once PIWIK_INCLUDE_PATH . '/core/Option.php';
Access::getInstance();
Config::getInstance();
try {
Db::get();
} catch (Exception $e) {
Db::createDatabaseObject();
}
PluginManager::getInstance()->loadCorePluginsDuringTracker();
}
} | php | public static function initCorePiwikInTrackerMode()
{
if (SettingsServer::isTrackerApiRequest()
&& self::$initTrackerMode === false
) {
self::$initTrackerMode = true;
require_once PIWIK_INCLUDE_PATH . '/core/Option.php';
Access::getInstance();
Config::getInstance();
try {
Db::get();
} catch (Exception $e) {
Db::createDatabaseObject();
}
PluginManager::getInstance()->loadCorePluginsDuringTracker();
}
} | [
"public",
"static",
"function",
"initCorePiwikInTrackerMode",
"(",
")",
"{",
"if",
"(",
"SettingsServer",
"::",
"isTrackerApiRequest",
"(",
")",
"&&",
"self",
"::",
"$",
"initTrackerMode",
"===",
"false",
")",
"{",
"self",
"::",
"$",
"initTrackerMode",
"=",
"true",
";",
"require_once",
"PIWIK_INCLUDE_PATH",
".",
"'/core/Option.php'",
";",
"Access",
"::",
"getInstance",
"(",
")",
";",
"Config",
"::",
"getInstance",
"(",
")",
";",
"try",
"{",
"Db",
"::",
"get",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"Db",
"::",
"createDatabaseObject",
"(",
")",
";",
"}",
"PluginManager",
"::",
"getInstance",
"(",
")",
"->",
"loadCorePluginsDuringTracker",
"(",
")",
";",
"}",
"}"
] | Used to initialize core Piwik components on a piwik.php request
Eg. when cache is missed and we will be calling some APIs to generate cache | [
"Used",
"to",
"initialize",
"core",
"Piwik",
"components",
"on",
"a",
"piwik",
".",
"php",
"request",
"Eg",
".",
"when",
"cache",
"is",
"missed",
"and",
"we",
"will",
"be",
"calling",
"some",
"APIs",
"to",
"generate",
"cache"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Tracker.php#L150-L169 |
209,414 | matomo-org/matomo | core/Widget/WidgetConfig.php | WidgetConfig.getUniqueId | public function getUniqueId()
{
$parameters = $this->getParameters();
unset($parameters['module']);
unset($parameters['action']);
return WidgetsList::getWidgetUniqueId($this->getModule(), $this->getAction(), $parameters);
} | php | public function getUniqueId()
{
$parameters = $this->getParameters();
unset($parameters['module']);
unset($parameters['action']);
return WidgetsList::getWidgetUniqueId($this->getModule(), $this->getAction(), $parameters);
} | [
"public",
"function",
"getUniqueId",
"(",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"getParameters",
"(",
")",
";",
"unset",
"(",
"$",
"parameters",
"[",
"'module'",
"]",
")",
";",
"unset",
"(",
"$",
"parameters",
"[",
"'action'",
"]",
")",
";",
"return",
"WidgetsList",
"::",
"getWidgetUniqueId",
"(",
"$",
"this",
"->",
"getModule",
"(",
")",
",",
"$",
"this",
"->",
"getAction",
"(",
")",
",",
"$",
"parameters",
")",
";",
"}"
] | Returns the unique id of an widget based on module, action and the set parameters.
@return string | [
"Returns",
"the",
"unique",
"id",
"of",
"an",
"widget",
"based",
"on",
"module",
"action",
"and",
"the",
"set",
"parameters",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Widget/WidgetConfig.php#L270-L277 |
209,415 | matomo-org/matomo | plugins/UsersManager/UserUpdater.php | UserUpdater.updateUserWithoutCurrentPassword | public function updateUserWithoutCurrentPassword($userLogin, $password = false, $email = false, $alias = false,
$_isPasswordHashed = false)
{
API::$UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION = false;
try {
Request::processRequest('UsersManager.updateUser', [
'userLogin' => $userLogin,
'password' => $password,
'email' => $email,
'alias' => $alias,
'_isPasswordHashed' => $_isPasswordHashed,
], $default = []);
API::$UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION = true;
} catch (\Exception $e) {
API::$UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION = true;
throw $e;
}
} | php | public function updateUserWithoutCurrentPassword($userLogin, $password = false, $email = false, $alias = false,
$_isPasswordHashed = false)
{
API::$UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION = false;
try {
Request::processRequest('UsersManager.updateUser', [
'userLogin' => $userLogin,
'password' => $password,
'email' => $email,
'alias' => $alias,
'_isPasswordHashed' => $_isPasswordHashed,
], $default = []);
API::$UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION = true;
} catch (\Exception $e) {
API::$UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION = true;
throw $e;
}
} | [
"public",
"function",
"updateUserWithoutCurrentPassword",
"(",
"$",
"userLogin",
",",
"$",
"password",
"=",
"false",
",",
"$",
"email",
"=",
"false",
",",
"$",
"alias",
"=",
"false",
",",
"$",
"_isPasswordHashed",
"=",
"false",
")",
"{",
"API",
"::",
"$",
"UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION",
"=",
"false",
";",
"try",
"{",
"Request",
"::",
"processRequest",
"(",
"'UsersManager.updateUser'",
",",
"[",
"'userLogin'",
"=>",
"$",
"userLogin",
",",
"'password'",
"=>",
"$",
"password",
",",
"'email'",
"=>",
"$",
"email",
",",
"'alias'",
"=>",
"$",
"alias",
",",
"'_isPasswordHashed'",
"=>",
"$",
"_isPasswordHashed",
",",
"]",
",",
"$",
"default",
"=",
"[",
"]",
")",
";",
"API",
"::",
"$",
"UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION",
"=",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"API",
"::",
"$",
"UPDATE_USER_REQUIRE_PASSWORD_CONFIRMATION",
"=",
"true",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] | Use this method if you have to update the user without having the ability to ask the user for a password confirmation
@param $userLogin
@param bool $password
@param bool $email
@param bool $alias
@param bool $_isPasswordHashed
@throws \Exception | [
"Use",
"this",
"method",
"if",
"you",
"have",
"to",
"update",
"the",
"user",
"without",
"having",
"the",
"ability",
"to",
"ask",
"the",
"user",
"for",
"a",
"password",
"confirmation"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UsersManager/UserUpdater.php#L25-L42 |
209,416 | matomo-org/matomo | core/Db/BatchInsert.php | BatchInsert.tableInsertBatchIterate | public static function tableInsertBatchIterate($tableName, $fields, $values, $ignoreWhenDuplicate = true)
{
$fieldList = '(' . join(',', $fields) . ')';
$ignore = $ignoreWhenDuplicate ? 'IGNORE' : '';
foreach ($values as $row) {
$query = "INSERT $ignore INTO " . $tableName . "
$fieldList
VALUES (" . Common::getSqlStringFieldsArray($row) . ")";
Db::query($query, $row);
}
} | php | public static function tableInsertBatchIterate($tableName, $fields, $values, $ignoreWhenDuplicate = true)
{
$fieldList = '(' . join(',', $fields) . ')';
$ignore = $ignoreWhenDuplicate ? 'IGNORE' : '';
foreach ($values as $row) {
$query = "INSERT $ignore INTO " . $tableName . "
$fieldList
VALUES (" . Common::getSqlStringFieldsArray($row) . ")";
Db::query($query, $row);
}
} | [
"public",
"static",
"function",
"tableInsertBatchIterate",
"(",
"$",
"tableName",
",",
"$",
"fields",
",",
"$",
"values",
",",
"$",
"ignoreWhenDuplicate",
"=",
"true",
")",
"{",
"$",
"fieldList",
"=",
"'('",
".",
"join",
"(",
"','",
",",
"$",
"fields",
")",
".",
"')'",
";",
"$",
"ignore",
"=",
"$",
"ignoreWhenDuplicate",
"?",
"'IGNORE'",
":",
"''",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"row",
")",
"{",
"$",
"query",
"=",
"\"INSERT $ignore INTO \"",
".",
"$",
"tableName",
".",
"\"\n\t\t\t\t\t $fieldList\n\t\t\t\t\t VALUES (\"",
".",
"Common",
"::",
"getSqlStringFieldsArray",
"(",
"$",
"row",
")",
".",
"\")\"",
";",
"Db",
"::",
"query",
"(",
"$",
"query",
",",
"$",
"row",
")",
";",
"}",
"}"
] | Performs a batch insert into a specific table by iterating through the data
NOTE: you should use tableInsertBatch() which will fallback to this function if LOAD DATA INFILE not available
@param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
@param array $fields array of unquoted field names
@param array $values array of data to be inserted
@param bool $ignoreWhenDuplicate Ignore new rows that contain unique key values that duplicate old rows | [
"Performs",
"a",
"batch",
"insert",
"into",
"a",
"specific",
"table",
"by",
"iterating",
"through",
"the",
"data"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/BatchInsert.php#L31-L42 |
209,417 | matomo-org/matomo | libs/HTML/QuickForm2.php | HTML_QuickForm2.setDataSources | public function setDataSources(array $datasources)
{
foreach ($datasources as $ds) {
if (!$ds instanceof HTML_QuickForm2_DataSource) {
throw new HTML_QuickForm2_InvalidArgumentException(
'Array should contain only DataSource instances'
);
}
}
$this->datasources = $datasources;
$this->updateValue();
} | php | public function setDataSources(array $datasources)
{
foreach ($datasources as $ds) {
if (!$ds instanceof HTML_QuickForm2_DataSource) {
throw new HTML_QuickForm2_InvalidArgumentException(
'Array should contain only DataSource instances'
);
}
}
$this->datasources = $datasources;
$this->updateValue();
} | [
"public",
"function",
"setDataSources",
"(",
"array",
"$",
"datasources",
")",
"{",
"foreach",
"(",
"$",
"datasources",
"as",
"$",
"ds",
")",
"{",
"if",
"(",
"!",
"$",
"ds",
"instanceof",
"HTML_QuickForm2_DataSource",
")",
"{",
"throw",
"new",
"HTML_QuickForm2_InvalidArgumentException",
"(",
"'Array should contain only DataSource instances'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"datasources",
"=",
"$",
"datasources",
";",
"$",
"this",
"->",
"updateValue",
"(",
")",
";",
"}"
] | Replaces the list of form's data sources with a completely new one
@param array A new data source list
@throws HTML_QuickForm2_InvalidArgumentException if given array
contains something that is not a valid data source | [
"Replaces",
"the",
"list",
"of",
"form",
"s",
"data",
"sources",
"with",
"a",
"completely",
"new",
"one"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2.php#L157-L168 |
209,418 | matomo-org/matomo | libs/HTML/QuickForm2.php | HTML_QuickForm2.render | public function render(HTML_QuickForm2_Renderer $renderer)
{
$renderer->startForm($this);
$renderer->getJavascriptBuilder()->startForm($this);
foreach ($this as $element) {
$element->render($renderer);
}
$renderer->finishForm($this);
return $renderer;
} | php | public function render(HTML_QuickForm2_Renderer $renderer)
{
$renderer->startForm($this);
$renderer->getJavascriptBuilder()->startForm($this);
foreach ($this as $element) {
$element->render($renderer);
}
$renderer->finishForm($this);
return $renderer;
} | [
"public",
"function",
"render",
"(",
"HTML_QuickForm2_Renderer",
"$",
"renderer",
")",
"{",
"$",
"renderer",
"->",
"startForm",
"(",
"$",
"this",
")",
";",
"$",
"renderer",
"->",
"getJavascriptBuilder",
"(",
")",
"->",
"startForm",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"element",
")",
"{",
"$",
"element",
"->",
"render",
"(",
"$",
"renderer",
")",
";",
"}",
"$",
"renderer",
"->",
"finishForm",
"(",
"$",
"this",
")",
";",
"return",
"$",
"renderer",
";",
"}"
] | Renders the form using the given renderer
@param HTML_QuickForm2_Renderer Renderer instance
@return HTML_QuickForm2_Renderer | [
"Renders",
"the",
"form",
"using",
"the",
"given",
"renderer"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2.php#L213-L222 |
209,419 | matomo-org/matomo | core/Notification.php | Notification.getPriority | public function getPriority()
{
if (!isset($this->priority)) {
$typeToPriority = array(static::CONTEXT_ERROR => static::PRIORITY_MAX,
static::CONTEXT_WARNING => static::PRIORITY_HIGH,
static::CONTEXT_SUCCESS => static::PRIORITY_MIN,
static::CONTEXT_INFO => static::PRIORITY_LOW);
if (array_key_exists($this->context, $typeToPriority)) {
return $typeToPriority[$this->context];
}
return static::PRIORITY_LOW;
}
return $this->priority;
} | php | public function getPriority()
{
if (!isset($this->priority)) {
$typeToPriority = array(static::CONTEXT_ERROR => static::PRIORITY_MAX,
static::CONTEXT_WARNING => static::PRIORITY_HIGH,
static::CONTEXT_SUCCESS => static::PRIORITY_MIN,
static::CONTEXT_INFO => static::PRIORITY_LOW);
if (array_key_exists($this->context, $typeToPriority)) {
return $typeToPriority[$this->context];
}
return static::PRIORITY_LOW;
}
return $this->priority;
} | [
"public",
"function",
"getPriority",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"priority",
")",
")",
"{",
"$",
"typeToPriority",
"=",
"array",
"(",
"static",
"::",
"CONTEXT_ERROR",
"=>",
"static",
"::",
"PRIORITY_MAX",
",",
"static",
"::",
"CONTEXT_WARNING",
"=>",
"static",
"::",
"PRIORITY_HIGH",
",",
"static",
"::",
"CONTEXT_SUCCESS",
"=>",
"static",
"::",
"PRIORITY_MIN",
",",
"static",
"::",
"CONTEXT_INFO",
"=>",
"static",
"::",
"PRIORITY_LOW",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"context",
",",
"$",
"typeToPriority",
")",
")",
"{",
"return",
"$",
"typeToPriority",
"[",
"$",
"this",
"->",
"context",
"]",
";",
"}",
"return",
"static",
"::",
"PRIORITY_LOW",
";",
"}",
"return",
"$",
"this",
"->",
"priority",
";",
"}"
] | Returns the notification's priority. If no priority has been set, a priority will be set based
on the notification's context.
@return int | [
"Returns",
"the",
"notification",
"s",
"priority",
".",
"If",
"no",
"priority",
"has",
"been",
"set",
"a",
"priority",
"will",
"be",
"set",
"based",
"on",
"the",
"notification",
"s",
"context",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Notification.php#L197-L213 |
209,420 | matomo-org/matomo | plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php | ServerModule.isAvailable | public function isAvailable()
{
if (function_exists('apache_get_modules')) {
foreach (apache_get_modules() as $name) {
if (strpos($name, 'maxminddb') !== false) {
return true;
}
}
}
$settings = self::getGeoIpServerVars();
$available = array_key_exists($settings[self::CONTINENT_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::COUNTRY_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::REGION_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::CITY_NAME_KEY], $_SERVER);
if ($available) {
return true;
}
// if not available return message w/ extra info
if (!function_exists('apache_get_modules')) {
return Piwik::translate('General_Note') . ': ' . Piwik::translate('UserCountry_AssumingNonApache');
}
$message = "<strong>" . Piwik::translate('General_Note') . ': '
. Piwik::translate('UserCountry_FoundApacheModules')
. "</strong>:<br/><br/>\n<ul style=\"list-style:disc;margin-left:24px\">\n";
foreach (apache_get_modules() as $name) {
$message .= "<li>$name</li>\n";
}
$message .= "</ul>";
return $message;
} | php | public function isAvailable()
{
if (function_exists('apache_get_modules')) {
foreach (apache_get_modules() as $name) {
if (strpos($name, 'maxminddb') !== false) {
return true;
}
}
}
$settings = self::getGeoIpServerVars();
$available = array_key_exists($settings[self::CONTINENT_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::COUNTRY_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::REGION_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::CITY_NAME_KEY], $_SERVER);
if ($available) {
return true;
}
// if not available return message w/ extra info
if (!function_exists('apache_get_modules')) {
return Piwik::translate('General_Note') . ': ' . Piwik::translate('UserCountry_AssumingNonApache');
}
$message = "<strong>" . Piwik::translate('General_Note') . ': '
. Piwik::translate('UserCountry_FoundApacheModules')
. "</strong>:<br/><br/>\n<ul style=\"list-style:disc;margin-left:24px\">\n";
foreach (apache_get_modules() as $name) {
$message .= "<li>$name</li>\n";
}
$message .= "</ul>";
return $message;
} | [
"public",
"function",
"isAvailable",
"(",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'apache_get_modules'",
")",
")",
"{",
"foreach",
"(",
"apache_get_modules",
"(",
")",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'maxminddb'",
")",
"!==",
"false",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"$",
"settings",
"=",
"self",
"::",
"getGeoIpServerVars",
"(",
")",
";",
"$",
"available",
"=",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"CONTINENT_CODE_KEY",
"]",
",",
"$",
"_SERVER",
")",
"||",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
",",
"$",
"_SERVER",
")",
"||",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"REGION_CODE_KEY",
"]",
",",
"$",
"_SERVER",
")",
"||",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"CITY_NAME_KEY",
"]",
",",
"$",
"_SERVER",
")",
";",
"if",
"(",
"$",
"available",
")",
"{",
"return",
"true",
";",
"}",
"// if not available return message w/ extra info",
"if",
"(",
"!",
"function_exists",
"(",
"'apache_get_modules'",
")",
")",
"{",
"return",
"Piwik",
"::",
"translate",
"(",
"'General_Note'",
")",
".",
"': '",
".",
"Piwik",
"::",
"translate",
"(",
"'UserCountry_AssumingNonApache'",
")",
";",
"}",
"$",
"message",
"=",
"\"<strong>\"",
".",
"Piwik",
"::",
"translate",
"(",
"'General_Note'",
")",
".",
"': '",
".",
"Piwik",
"::",
"translate",
"(",
"'UserCountry_FoundApacheModules'",
")",
".",
"\"</strong>:<br/><br/>\\n<ul style=\\\"list-style:disc;margin-left:24px\\\">\\n\"",
";",
"foreach",
"(",
"apache_get_modules",
"(",
")",
"as",
"$",
"name",
")",
"{",
"$",
"message",
".=",
"\"<li>$name</li>\\n\"",
";",
"}",
"$",
"message",
".=",
"\"</ul>\"",
";",
"return",
"$",
"message",
";",
"}"
] | Checks if an mod_maxminddb has been installed and MMDB_ADDR server variable is defined.
There's a special check for the Apache module, but we can't check specifically
for anything else.
@return bool|string | [
"Checks",
"if",
"an",
"mod_maxminddb",
"has",
"been",
"installed",
"and",
"MMDB_ADDR",
"server",
"variable",
"is",
"defined",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php#L139-L173 |
209,421 | matomo-org/matomo | plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php | ServerModule.isWorking | public function isWorking()
{
$settings = self::getGeoIpServerVars();
$available = array_key_exists($settings[self::CONTINENT_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::COUNTRY_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::REGION_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::CITY_NAME_KEY], $_SERVER);
if (!$available) {
return Piwik::translate("UserCountry_CannotFindGeoIPServerVar", $settings[self::COUNTRY_CODE_KEY] . ' $_SERVER');
}
return true;
} | php | public function isWorking()
{
$settings = self::getGeoIpServerVars();
$available = array_key_exists($settings[self::CONTINENT_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::COUNTRY_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::REGION_CODE_KEY], $_SERVER)
|| array_key_exists($settings[self::CITY_NAME_KEY], $_SERVER);
if (!$available) {
return Piwik::translate("UserCountry_CannotFindGeoIPServerVar", $settings[self::COUNTRY_CODE_KEY] . ' $_SERVER');
}
return true;
} | [
"public",
"function",
"isWorking",
"(",
")",
"{",
"$",
"settings",
"=",
"self",
"::",
"getGeoIpServerVars",
"(",
")",
";",
"$",
"available",
"=",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"CONTINENT_CODE_KEY",
"]",
",",
"$",
"_SERVER",
")",
"||",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
",",
"$",
"_SERVER",
")",
"||",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"REGION_CODE_KEY",
"]",
",",
"$",
"_SERVER",
")",
"||",
"array_key_exists",
"(",
"$",
"settings",
"[",
"self",
"::",
"CITY_NAME_KEY",
"]",
",",
"$",
"_SERVER",
")",
";",
"if",
"(",
"!",
"$",
"available",
")",
"{",
"return",
"Piwik",
"::",
"translate",
"(",
"\"UserCountry_CannotFindGeoIPServerVar\"",
",",
"$",
"settings",
"[",
"self",
"::",
"COUNTRY_CODE_KEY",
"]",
".",
"' $_SERVER'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Returns true if the MMDB_ADDR server variable is defined.
@return bool | [
"Returns",
"true",
"if",
"the",
"MMDB_ADDR",
"server",
"variable",
"is",
"defined",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php#L180-L194 |
209,422 | matomo-org/matomo | plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php | ServerModule.isSameOrAnonymizedIp | public static function isSameOrAnonymizedIp($ip, $currentIp)
{
$ip = array_reverse(explode('.', $ip));
$currentIp = array_reverse(explode('.', $currentIp));
if (count($ip) != count($currentIp)) {
return false;
}
foreach ($ip as $i => $byte) {
if ($byte == 0) {
$currentIp[$i] = 0;
} else {
break;
}
}
foreach ($ip as $i => $byte) {
if ($byte != $currentIp[$i]) {
return false;
}
}
return true;
} | php | public static function isSameOrAnonymizedIp($ip, $currentIp)
{
$ip = array_reverse(explode('.', $ip));
$currentIp = array_reverse(explode('.', $currentIp));
if (count($ip) != count($currentIp)) {
return false;
}
foreach ($ip as $i => $byte) {
if ($byte == 0) {
$currentIp[$i] = 0;
} else {
break;
}
}
foreach ($ip as $i => $byte) {
if ($byte != $currentIp[$i]) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"isSameOrAnonymizedIp",
"(",
"$",
"ip",
",",
"$",
"currentIp",
")",
"{",
"$",
"ip",
"=",
"array_reverse",
"(",
"explode",
"(",
"'.'",
",",
"$",
"ip",
")",
")",
";",
"$",
"currentIp",
"=",
"array_reverse",
"(",
"explode",
"(",
"'.'",
",",
"$",
"currentIp",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"ip",
")",
"!=",
"count",
"(",
"$",
"currentIp",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"ip",
"as",
"$",
"i",
"=>",
"$",
"byte",
")",
"{",
"if",
"(",
"$",
"byte",
"==",
"0",
")",
"{",
"$",
"currentIp",
"[",
"$",
"i",
"]",
"=",
"0",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"foreach",
"(",
"$",
"ip",
"as",
"$",
"i",
"=>",
"$",
"byte",
")",
"{",
"if",
"(",
"$",
"byte",
"!=",
"$",
"currentIp",
"[",
"$",
"i",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if two IP addresses are the same or if the first is the anonymized
version of the other.
@param string $ip
@param string $currentIp This IP should not be anonymized.
@return bool | [
"Checks",
"if",
"two",
"IP",
"addresses",
"are",
"the",
"same",
"or",
"if",
"the",
"first",
"is",
"the",
"anonymized",
"version",
"of",
"the",
"other",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php#L271-L294 |
209,423 | matomo-org/matomo | plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php | ServerModule.getGeoIpServerVars | protected static function getGeoIpServerVars($type = null)
{
$storedSettings = self::getSystemSettingsValues();
if ($type === null) {
return $storedSettings;
}
if (array_key_exists($type, $storedSettings)) {
return $storedSettings[$type];
}
return '';
} | php | protected static function getGeoIpServerVars($type = null)
{
$storedSettings = self::getSystemSettingsValues();
if ($type === null) {
return $storedSettings;
}
if (array_key_exists($type, $storedSettings)) {
return $storedSettings[$type];
}
return '';
} | [
"protected",
"static",
"function",
"getGeoIpServerVars",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"storedSettings",
"=",
"self",
"::",
"getSystemSettingsValues",
"(",
")",
";",
"if",
"(",
"$",
"type",
"===",
"null",
")",
"{",
"return",
"$",
"storedSettings",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"storedSettings",
")",
")",
"{",
"return",
"$",
"storedSettings",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Returns currently configured server variable name for given type
@param string|null $type
@return mixed|string | [
"Returns",
"currently",
"configured",
"server",
"variable",
"name",
"for",
"given",
"type"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/GeoIp2/LocationProvider/GeoIp2/ServerModule.php#L302-L315 |
209,424 | matomo-org/matomo | core/Archive/ArchivePurger.php | ArchivePurger.purge | protected function purge(array $idArchivesToDelete, Date $dateStart, $reason)
{
$deletedRowCount = 0;
if (!empty($idArchivesToDelete)) {
$deletedRowCount = $this->deleteArchiveIds($dateStart, $idArchivesToDelete);
$this->logger->info(
"Deleted {count} rows in archive tables (numeric + blob) for {reason} for {date}.",
array(
'count' => $deletedRowCount,
'date' => $dateStart,
'reason' => $reason
)
);
$this->logger->debug("[Deleted IDs: {deletedIds}]", array(
'deletedIds' => implode(',', $idArchivesToDelete)
));
} else {
$this->logger->debug(
"No archives for {reason} found in archive numeric table for {date}.",
array('date' => $dateStart, 'reason' => $reason)
);
}
return $deletedRowCount;
} | php | protected function purge(array $idArchivesToDelete, Date $dateStart, $reason)
{
$deletedRowCount = 0;
if (!empty($idArchivesToDelete)) {
$deletedRowCount = $this->deleteArchiveIds($dateStart, $idArchivesToDelete);
$this->logger->info(
"Deleted {count} rows in archive tables (numeric + blob) for {reason} for {date}.",
array(
'count' => $deletedRowCount,
'date' => $dateStart,
'reason' => $reason
)
);
$this->logger->debug("[Deleted IDs: {deletedIds}]", array(
'deletedIds' => implode(',', $idArchivesToDelete)
));
} else {
$this->logger->debug(
"No archives for {reason} found in archive numeric table for {date}.",
array('date' => $dateStart, 'reason' => $reason)
);
}
return $deletedRowCount;
} | [
"protected",
"function",
"purge",
"(",
"array",
"$",
"idArchivesToDelete",
",",
"Date",
"$",
"dateStart",
",",
"$",
"reason",
")",
"{",
"$",
"deletedRowCount",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"idArchivesToDelete",
")",
")",
"{",
"$",
"deletedRowCount",
"=",
"$",
"this",
"->",
"deleteArchiveIds",
"(",
"$",
"dateStart",
",",
"$",
"idArchivesToDelete",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Deleted {count} rows in archive tables (numeric + blob) for {reason} for {date}.\"",
",",
"array",
"(",
"'count'",
"=>",
"$",
"deletedRowCount",
",",
"'date'",
"=>",
"$",
"dateStart",
",",
"'reason'",
"=>",
"$",
"reason",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"[Deleted IDs: {deletedIds}]\"",
",",
"array",
"(",
"'deletedIds'",
"=>",
"implode",
"(",
"','",
",",
"$",
"idArchivesToDelete",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"No archives for {reason} found in archive numeric table for {date}.\"",
",",
"array",
"(",
"'date'",
"=>",
"$",
"dateStart",
",",
"'reason'",
"=>",
"$",
"reason",
")",
")",
";",
"}",
"return",
"$",
"deletedRowCount",
";",
"}"
] | Purge all numeric and blob archives with the given IDs from the database.
@param array $idArchivesToDelete
@param Date $dateStart
@param string $reason
@return int | [
"Purge",
"all",
"numeric",
"and",
"blob",
"archives",
"with",
"the",
"given",
"IDs",
"from",
"the",
"database",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Archive/ArchivePurger.php#L185-L211 |
209,425 | matomo-org/matomo | core/Archive/ArchivePurger.php | ArchivePurger.purgeArchivesWithPeriodRange | public function purgeArchivesWithPeriodRange(Date $date)
{
$numericTable = ArchiveTableCreator::getNumericTable($date);
$blobTable = ArchiveTableCreator::getBlobTable($date);
$deletedCount = $this->model->deleteArchivesWithPeriod(
$numericTable, $blobTable, Piwik::$idPeriods['range'], $this->purgeCustomRangesOlderThan);
$level = $deletedCount == 0 ? LogLevel::DEBUG : LogLevel::INFO;
$this->logger->log($level, "Purged {count} range archive rows from {numericTable} & {blobTable}.", array(
'count' => $deletedCount,
'numericTable' => $numericTable,
'blobTable' => $blobTable
));
$this->logger->debug(" [ purged archives older than {threshold} ]", array('threshold' => $this->purgeCustomRangesOlderThan));
return $deletedCount;
} | php | public function purgeArchivesWithPeriodRange(Date $date)
{
$numericTable = ArchiveTableCreator::getNumericTable($date);
$blobTable = ArchiveTableCreator::getBlobTable($date);
$deletedCount = $this->model->deleteArchivesWithPeriod(
$numericTable, $blobTable, Piwik::$idPeriods['range'], $this->purgeCustomRangesOlderThan);
$level = $deletedCount == 0 ? LogLevel::DEBUG : LogLevel::INFO;
$this->logger->log($level, "Purged {count} range archive rows from {numericTable} & {blobTable}.", array(
'count' => $deletedCount,
'numericTable' => $numericTable,
'blobTable' => $blobTable
));
$this->logger->debug(" [ purged archives older than {threshold} ]", array('threshold' => $this->purgeCustomRangesOlderThan));
return $deletedCount;
} | [
"public",
"function",
"purgeArchivesWithPeriodRange",
"(",
"Date",
"$",
"date",
")",
"{",
"$",
"numericTable",
"=",
"ArchiveTableCreator",
"::",
"getNumericTable",
"(",
"$",
"date",
")",
";",
"$",
"blobTable",
"=",
"ArchiveTableCreator",
"::",
"getBlobTable",
"(",
"$",
"date",
")",
";",
"$",
"deletedCount",
"=",
"$",
"this",
"->",
"model",
"->",
"deleteArchivesWithPeriod",
"(",
"$",
"numericTable",
",",
"$",
"blobTable",
",",
"Piwik",
"::",
"$",
"idPeriods",
"[",
"'range'",
"]",
",",
"$",
"this",
"->",
"purgeCustomRangesOlderThan",
")",
";",
"$",
"level",
"=",
"$",
"deletedCount",
"==",
"0",
"?",
"LogLevel",
"::",
"DEBUG",
":",
"LogLevel",
"::",
"INFO",
";",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"level",
",",
"\"Purged {count} range archive rows from {numericTable} & {blobTable}.\"",
",",
"array",
"(",
"'count'",
"=>",
"$",
"deletedCount",
",",
"'numericTable'",
"=>",
"$",
"numericTable",
",",
"'blobTable'",
"=>",
"$",
"blobTable",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\" [ purged archives older than {threshold} ]\"",
",",
"array",
"(",
"'threshold'",
"=>",
"$",
"this",
"->",
"purgeCustomRangesOlderThan",
")",
")",
";",
"return",
"$",
"deletedCount",
";",
"}"
] | Deleting "Custom Date Range" reports after 1 day, since they can be re-processed and would take up un-necessary space.
@param $date Date
@return int The total number of rows deleted from both the numeric & blob table. | [
"Deleting",
"Custom",
"Date",
"Range",
"reports",
"after",
"1",
"day",
"since",
"they",
"can",
"be",
"re",
"-",
"processed",
"and",
"would",
"take",
"up",
"un",
"-",
"necessary",
"space",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Archive/ArchivePurger.php#L252-L270 |
209,426 | matomo-org/matomo | core/Archive/ArchivePurger.php | ArchivePurger.deleteArchiveIds | protected function deleteArchiveIds(Date $date, $idArchivesToDelete)
{
$batches = array_chunk($idArchivesToDelete, 1000);
$numericTable = ArchiveTableCreator::getNumericTable($date);
$blobTable = ArchiveTableCreator::getBlobTable($date);
$deletedCount = 0;
foreach ($batches as $idsToDelete) {
$deletedCount += $this->model->deleteArchiveIds($numericTable, $blobTable, $idsToDelete);
}
return $deletedCount;
} | php | protected function deleteArchiveIds(Date $date, $idArchivesToDelete)
{
$batches = array_chunk($idArchivesToDelete, 1000);
$numericTable = ArchiveTableCreator::getNumericTable($date);
$blobTable = ArchiveTableCreator::getBlobTable($date);
$deletedCount = 0;
foreach ($batches as $idsToDelete) {
$deletedCount += $this->model->deleteArchiveIds($numericTable, $blobTable, $idsToDelete);
}
return $deletedCount;
} | [
"protected",
"function",
"deleteArchiveIds",
"(",
"Date",
"$",
"date",
",",
"$",
"idArchivesToDelete",
")",
"{",
"$",
"batches",
"=",
"array_chunk",
"(",
"$",
"idArchivesToDelete",
",",
"1000",
")",
";",
"$",
"numericTable",
"=",
"ArchiveTableCreator",
"::",
"getNumericTable",
"(",
"$",
"date",
")",
";",
"$",
"blobTable",
"=",
"ArchiveTableCreator",
"::",
"getBlobTable",
"(",
"$",
"date",
")",
";",
"$",
"deletedCount",
"=",
"0",
";",
"foreach",
"(",
"$",
"batches",
"as",
"$",
"idsToDelete",
")",
"{",
"$",
"deletedCount",
"+=",
"$",
"this",
"->",
"model",
"->",
"deleteArchiveIds",
"(",
"$",
"numericTable",
",",
"$",
"blobTable",
",",
"$",
"idsToDelete",
")",
";",
"}",
"return",
"$",
"deletedCount",
";",
"}"
] | Deletes by batches Archive IDs in the specified month,
@param Date $date
@param $idArchivesToDelete
@return int Number of rows deleted from both numeric + blob table. | [
"Deletes",
"by",
"batches",
"Archive",
"IDs",
"in",
"the",
"specified",
"month"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Archive/ArchivePurger.php#L279-L290 |
209,427 | matomo-org/matomo | plugins/SitesManager/API.php | API.getJavascriptTag | public function getJavascriptTag($idSite, $piwikUrl = '', $mergeSubdomains = false, $groupPageTitlesByDomain = false,
$mergeAliasUrls = false, $visitorCustomVariables = false, $pageCustomVariables = false,
$customCampaignNameQueryParam = false, $customCampaignKeywordParam = false,
$doNotTrack = false, $disableCookies = false, $trackNoScript = false,
$crossDomain = false, $forceMatomoEndpoint = false)
{
Piwik::checkUserHasViewAccess($idSite);
if (empty($piwikUrl)) {
$piwikUrl = SettingsPiwik::getPiwikUrl();
}
// Revert the automatic encoding
// TODO remove that when https://github.com/piwik/piwik/issues/4231 is fixed
$piwikUrl = Common::unsanitizeInputValue($piwikUrl);
$visitorCustomVariables = Common::unsanitizeInputValues($visitorCustomVariables);
$pageCustomVariables = Common::unsanitizeInputValues($pageCustomVariables);
$customCampaignNameQueryParam = Common::unsanitizeInputValue($customCampaignNameQueryParam);
$customCampaignKeywordParam = Common::unsanitizeInputValue($customCampaignKeywordParam);
$generator = new TrackerCodeGenerator();
if ($forceMatomoEndpoint) {
$generator->forceMatomoEndpoint();
}
$code = $generator->generate($idSite, $piwikUrl, $mergeSubdomains, $groupPageTitlesByDomain,
$mergeAliasUrls, $visitorCustomVariables, $pageCustomVariables,
$customCampaignNameQueryParam, $customCampaignKeywordParam,
$doNotTrack, $disableCookies, $trackNoScript, $crossDomain);
$code = str_replace(array('<br>', '<br />', '<br/>'), '', $code);
return $code;
} | php | public function getJavascriptTag($idSite, $piwikUrl = '', $mergeSubdomains = false, $groupPageTitlesByDomain = false,
$mergeAliasUrls = false, $visitorCustomVariables = false, $pageCustomVariables = false,
$customCampaignNameQueryParam = false, $customCampaignKeywordParam = false,
$doNotTrack = false, $disableCookies = false, $trackNoScript = false,
$crossDomain = false, $forceMatomoEndpoint = false)
{
Piwik::checkUserHasViewAccess($idSite);
if (empty($piwikUrl)) {
$piwikUrl = SettingsPiwik::getPiwikUrl();
}
// Revert the automatic encoding
// TODO remove that when https://github.com/piwik/piwik/issues/4231 is fixed
$piwikUrl = Common::unsanitizeInputValue($piwikUrl);
$visitorCustomVariables = Common::unsanitizeInputValues($visitorCustomVariables);
$pageCustomVariables = Common::unsanitizeInputValues($pageCustomVariables);
$customCampaignNameQueryParam = Common::unsanitizeInputValue($customCampaignNameQueryParam);
$customCampaignKeywordParam = Common::unsanitizeInputValue($customCampaignKeywordParam);
$generator = new TrackerCodeGenerator();
if ($forceMatomoEndpoint) {
$generator->forceMatomoEndpoint();
}
$code = $generator->generate($idSite, $piwikUrl, $mergeSubdomains, $groupPageTitlesByDomain,
$mergeAliasUrls, $visitorCustomVariables, $pageCustomVariables,
$customCampaignNameQueryParam, $customCampaignKeywordParam,
$doNotTrack, $disableCookies, $trackNoScript, $crossDomain);
$code = str_replace(array('<br>', '<br />', '<br/>'), '', $code);
return $code;
} | [
"public",
"function",
"getJavascriptTag",
"(",
"$",
"idSite",
",",
"$",
"piwikUrl",
"=",
"''",
",",
"$",
"mergeSubdomains",
"=",
"false",
",",
"$",
"groupPageTitlesByDomain",
"=",
"false",
",",
"$",
"mergeAliasUrls",
"=",
"false",
",",
"$",
"visitorCustomVariables",
"=",
"false",
",",
"$",
"pageCustomVariables",
"=",
"false",
",",
"$",
"customCampaignNameQueryParam",
"=",
"false",
",",
"$",
"customCampaignKeywordParam",
"=",
"false",
",",
"$",
"doNotTrack",
"=",
"false",
",",
"$",
"disableCookies",
"=",
"false",
",",
"$",
"trackNoScript",
"=",
"false",
",",
"$",
"crossDomain",
"=",
"false",
",",
"$",
"forceMatomoEndpoint",
"=",
"false",
")",
"{",
"Piwik",
"::",
"checkUserHasViewAccess",
"(",
"$",
"idSite",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"piwikUrl",
")",
")",
"{",
"$",
"piwikUrl",
"=",
"SettingsPiwik",
"::",
"getPiwikUrl",
"(",
")",
";",
"}",
"// Revert the automatic encoding",
"// TODO remove that when https://github.com/piwik/piwik/issues/4231 is fixed",
"$",
"piwikUrl",
"=",
"Common",
"::",
"unsanitizeInputValue",
"(",
"$",
"piwikUrl",
")",
";",
"$",
"visitorCustomVariables",
"=",
"Common",
"::",
"unsanitizeInputValues",
"(",
"$",
"visitorCustomVariables",
")",
";",
"$",
"pageCustomVariables",
"=",
"Common",
"::",
"unsanitizeInputValues",
"(",
"$",
"pageCustomVariables",
")",
";",
"$",
"customCampaignNameQueryParam",
"=",
"Common",
"::",
"unsanitizeInputValue",
"(",
"$",
"customCampaignNameQueryParam",
")",
";",
"$",
"customCampaignKeywordParam",
"=",
"Common",
"::",
"unsanitizeInputValue",
"(",
"$",
"customCampaignKeywordParam",
")",
";",
"$",
"generator",
"=",
"new",
"TrackerCodeGenerator",
"(",
")",
";",
"if",
"(",
"$",
"forceMatomoEndpoint",
")",
"{",
"$",
"generator",
"->",
"forceMatomoEndpoint",
"(",
")",
";",
"}",
"$",
"code",
"=",
"$",
"generator",
"->",
"generate",
"(",
"$",
"idSite",
",",
"$",
"piwikUrl",
",",
"$",
"mergeSubdomains",
",",
"$",
"groupPageTitlesByDomain",
",",
"$",
"mergeAliasUrls",
",",
"$",
"visitorCustomVariables",
",",
"$",
"pageCustomVariables",
",",
"$",
"customCampaignNameQueryParam",
",",
"$",
"customCampaignKeywordParam",
",",
"$",
"doNotTrack",
",",
"$",
"disableCookies",
",",
"$",
"trackNoScript",
",",
"$",
"crossDomain",
")",
";",
"$",
"code",
"=",
"str_replace",
"(",
"array",
"(",
"'<br>'",
",",
"'<br />'",
",",
"'<br/>'",
")",
",",
"''",
",",
"$",
"code",
")",
";",
"return",
"$",
"code",
";",
"}"
] | Returns the javascript tag for the given idSite.
This tag must be included on every page to be tracked by Matomo
@param int $idSite
@param string $piwikUrl
@param bool $mergeSubdomains
@param bool $groupPageTitlesByDomain
@param bool $mergeAliasUrls
@param bool $visitorCustomVariables
@param bool $pageCustomVariables
@param bool $customCampaignNameQueryParam
@param bool $customCampaignKeywordParam
@param bool $doNotTrack
@param bool $disableCookies
@param bool $trackNoScript
@param bool $forceMatomoEndpoint Whether the Matomo endpoint should be forced if Matomo was installed prior 3.7.0.
@return string The Javascript tag ready to be included on the HTML pages | [
"Returns",
"the",
"javascript",
"tag",
"for",
"the",
"given",
"idSite",
".",
"This",
"tag",
"must",
"be",
"included",
"on",
"every",
"page",
"to",
"be",
"tracked",
"by",
"Matomo"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L107-L138 |
209,428 | matomo-org/matomo | plugins/SitesManager/API.php | API.getImageTrackingCode | public function getImageTrackingCode($idSite, $piwikUrl = '', $actionName = false, $idGoal = false, $revenue = false, $forceMatomoEndpoint = false)
{
$urlParams = array('idsite' => $idSite, 'rec' => 1);
if ($actionName !== false) {
$urlParams['action_name'] = urlencode(Common::unsanitizeInputValue($actionName));
}
if ($idGoal !== false) {
$urlParams['idgoal'] = $idGoal;
if ($revenue !== false) {
$urlParams['revenue'] = $revenue;
}
}
/**
* Triggered when generating image link tracking code server side. Plugins can use
* this event to customise the image tracking code that is displayed to the
* user.
*
* @param string &$piwikHost The domain and URL path to the Matomo installation, eg,
* `'examplepiwik.com/path/to/piwik'`.
* @param array &$urlParams The query parameters used in the <img> element's src
* URL. See Matomo's image tracking docs for more info.
*/
Piwik::postEvent('SitesManager.getImageTrackingCode', array(&$piwikUrl, &$urlParams));
$trackerCodeGenerator = new TrackerCodeGenerator();
if ($forceMatomoEndpoint) {
$trackerCodeGenerator->forceMatomoEndpoint();
}
$matomoPhp = $trackerCodeGenerator->getPhpTrackerEndpoint();
$url = (ProxyHttp::isHttps() ? "https://" : "http://") . rtrim($piwikUrl, '/') . '/'.$matomoPhp.'?' . Url::getQueryStringFromParameters($urlParams);
$html = "<!-- Matomo Image Tracker-->
<img src=\"" . htmlspecialchars($url, ENT_COMPAT, 'UTF-8') . "\" style=\"border:0\" alt=\"\" />
<!-- End Matomo -->";
return htmlspecialchars($html, ENT_COMPAT, 'UTF-8');
} | php | public function getImageTrackingCode($idSite, $piwikUrl = '', $actionName = false, $idGoal = false, $revenue = false, $forceMatomoEndpoint = false)
{
$urlParams = array('idsite' => $idSite, 'rec' => 1);
if ($actionName !== false) {
$urlParams['action_name'] = urlencode(Common::unsanitizeInputValue($actionName));
}
if ($idGoal !== false) {
$urlParams['idgoal'] = $idGoal;
if ($revenue !== false) {
$urlParams['revenue'] = $revenue;
}
}
/**
* Triggered when generating image link tracking code server side. Plugins can use
* this event to customise the image tracking code that is displayed to the
* user.
*
* @param string &$piwikHost The domain and URL path to the Matomo installation, eg,
* `'examplepiwik.com/path/to/piwik'`.
* @param array &$urlParams The query parameters used in the <img> element's src
* URL. See Matomo's image tracking docs for more info.
*/
Piwik::postEvent('SitesManager.getImageTrackingCode', array(&$piwikUrl, &$urlParams));
$trackerCodeGenerator = new TrackerCodeGenerator();
if ($forceMatomoEndpoint) {
$trackerCodeGenerator->forceMatomoEndpoint();
}
$matomoPhp = $trackerCodeGenerator->getPhpTrackerEndpoint();
$url = (ProxyHttp::isHttps() ? "https://" : "http://") . rtrim($piwikUrl, '/') . '/'.$matomoPhp.'?' . Url::getQueryStringFromParameters($urlParams);
$html = "<!-- Matomo Image Tracker-->
<img src=\"" . htmlspecialchars($url, ENT_COMPAT, 'UTF-8') . "\" style=\"border:0\" alt=\"\" />
<!-- End Matomo -->";
return htmlspecialchars($html, ENT_COMPAT, 'UTF-8');
} | [
"public",
"function",
"getImageTrackingCode",
"(",
"$",
"idSite",
",",
"$",
"piwikUrl",
"=",
"''",
",",
"$",
"actionName",
"=",
"false",
",",
"$",
"idGoal",
"=",
"false",
",",
"$",
"revenue",
"=",
"false",
",",
"$",
"forceMatomoEndpoint",
"=",
"false",
")",
"{",
"$",
"urlParams",
"=",
"array",
"(",
"'idsite'",
"=>",
"$",
"idSite",
",",
"'rec'",
"=>",
"1",
")",
";",
"if",
"(",
"$",
"actionName",
"!==",
"false",
")",
"{",
"$",
"urlParams",
"[",
"'action_name'",
"]",
"=",
"urlencode",
"(",
"Common",
"::",
"unsanitizeInputValue",
"(",
"$",
"actionName",
")",
")",
";",
"}",
"if",
"(",
"$",
"idGoal",
"!==",
"false",
")",
"{",
"$",
"urlParams",
"[",
"'idgoal'",
"]",
"=",
"$",
"idGoal",
";",
"if",
"(",
"$",
"revenue",
"!==",
"false",
")",
"{",
"$",
"urlParams",
"[",
"'revenue'",
"]",
"=",
"$",
"revenue",
";",
"}",
"}",
"/**\n * Triggered when generating image link tracking code server side. Plugins can use\n * this event to customise the image tracking code that is displayed to the\n * user.\n *\n * @param string &$piwikHost The domain and URL path to the Matomo installation, eg,\n * `'examplepiwik.com/path/to/piwik'`.\n * @param array &$urlParams The query parameters used in the <img> element's src\n * URL. See Matomo's image tracking docs for more info.\n */",
"Piwik",
"::",
"postEvent",
"(",
"'SitesManager.getImageTrackingCode'",
",",
"array",
"(",
"&",
"$",
"piwikUrl",
",",
"&",
"$",
"urlParams",
")",
")",
";",
"$",
"trackerCodeGenerator",
"=",
"new",
"TrackerCodeGenerator",
"(",
")",
";",
"if",
"(",
"$",
"forceMatomoEndpoint",
")",
"{",
"$",
"trackerCodeGenerator",
"->",
"forceMatomoEndpoint",
"(",
")",
";",
"}",
"$",
"matomoPhp",
"=",
"$",
"trackerCodeGenerator",
"->",
"getPhpTrackerEndpoint",
"(",
")",
";",
"$",
"url",
"=",
"(",
"ProxyHttp",
"::",
"isHttps",
"(",
")",
"?",
"\"https://\"",
":",
"\"http://\"",
")",
".",
"rtrim",
"(",
"$",
"piwikUrl",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"matomoPhp",
".",
"'?'",
".",
"Url",
"::",
"getQueryStringFromParameters",
"(",
"$",
"urlParams",
")",
";",
"$",
"html",
"=",
"\"<!-- Matomo Image Tracker-->\n<img src=\\\"\"",
".",
"htmlspecialchars",
"(",
"$",
"url",
",",
"ENT_COMPAT",
",",
"'UTF-8'",
")",
".",
"\"\\\" style=\\\"border:0\\\" alt=\\\"\\\" />\n<!-- End Matomo -->\"",
";",
"return",
"htmlspecialchars",
"(",
"$",
"html",
",",
"ENT_COMPAT",
",",
"'UTF-8'",
")",
";",
"}"
] | Returns image link tracking code for a given site with specified options.
@param int $idSite The ID to generate tracking code for.
@param string $piwikUrl The domain and URL path to the Matomo installation.
@param int $idGoal An ID for a goal to trigger a conversion for.
@param int $revenue The revenue of the goal conversion. Only used if $idGoal is supplied.
@param bool $forceMatomoEndpoint Whether the Matomo endpoint should be forced if Matomo was installed prior 3.7.0.
@return string The HTML tracking code. | [
"Returns",
"image",
"link",
"tracking",
"code",
"for",
"a",
"given",
"site",
"with",
"specified",
"options",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L150-L188 |
209,429 | matomo-org/matomo | plugins/SitesManager/API.php | API.getAllSites | public function getAllSites()
{
Piwik::checkUserHasSuperUserAccess();
$sites = $this->getModel()->getAllSites();
$return = array();
foreach ($sites as $site) {
$this->enrichSite($site);
$return[$site['idsite']] = $site;
}
$return = Site::setSitesFromArray($return);
return $return;
} | php | public function getAllSites()
{
Piwik::checkUserHasSuperUserAccess();
$sites = $this->getModel()->getAllSites();
$return = array();
foreach ($sites as $site) {
$this->enrichSite($site);
$return[$site['idsite']] = $site;
}
$return = Site::setSitesFromArray($return);
return $return;
} | [
"public",
"function",
"getAllSites",
"(",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"$",
"sites",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"getAllSites",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sites",
"as",
"$",
"site",
")",
"{",
"$",
"this",
"->",
"enrichSite",
"(",
"$",
"site",
")",
";",
"$",
"return",
"[",
"$",
"site",
"[",
"'idsite'",
"]",
"]",
"=",
"$",
"site",
";",
"}",
"$",
"return",
"=",
"Site",
"::",
"setSitesFromArray",
"(",
"$",
"return",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Returns all websites, requires Super User access
@return array The list of websites, indexed by idsite | [
"Returns",
"all",
"websites",
"requires",
"Super",
"User",
"access"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L276-L290 |
209,430 | matomo-org/matomo | plugins/SitesManager/API.php | API.getSitesIdWithVisits | public function getSitesIdWithVisits($timestamp = false)
{
Piwik::checkUserHasSuperUserAccess();
if (empty($timestamp)) $timestamp = time();
$time = Date::factory((int)$timestamp)->getDatetime();
$now = Date::now()->addHour(1)->getDatetime();
$result = $this->getModel()->getSitesWithVisits($time, $now);
$idSites = array();
foreach ($result as $idSite) {
$idSites[] = $idSite['idsite'];
}
return $idSites;
} | php | public function getSitesIdWithVisits($timestamp = false)
{
Piwik::checkUserHasSuperUserAccess();
if (empty($timestamp)) $timestamp = time();
$time = Date::factory((int)$timestamp)->getDatetime();
$now = Date::now()->addHour(1)->getDatetime();
$result = $this->getModel()->getSitesWithVisits($time, $now);
$idSites = array();
foreach ($result as $idSite) {
$idSites[] = $idSite['idsite'];
}
return $idSites;
} | [
"public",
"function",
"getSitesIdWithVisits",
"(",
"$",
"timestamp",
"=",
"false",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"timestamp",
")",
")",
"$",
"timestamp",
"=",
"time",
"(",
")",
";",
"$",
"time",
"=",
"Date",
"::",
"factory",
"(",
"(",
"int",
")",
"$",
"timestamp",
")",
"->",
"getDatetime",
"(",
")",
";",
"$",
"now",
"=",
"Date",
"::",
"now",
"(",
")",
"->",
"addHour",
"(",
"1",
")",
"->",
"getDatetime",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"getSitesWithVisits",
"(",
"$",
"time",
",",
"$",
"now",
")",
";",
"$",
"idSites",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"idSite",
")",
"{",
"$",
"idSites",
"[",
"]",
"=",
"$",
"idSite",
"[",
"'idsite'",
"]",
";",
"}",
"return",
"$",
"idSites",
";",
"}"
] | Returns the list of the website IDs that received some visits since the specified timestamp.
Requires Super User access.
@param bool|int $timestamp
@return array The list of website IDs
@deprecated since 2.15 This method will be removed in Matomo 3.0, there is no replacement. | [
"Returns",
"the",
"list",
"of",
"the",
"website",
"IDs",
"that",
"received",
"some",
"visits",
"since",
"the",
"specified",
"timestamp",
".",
"Requires",
"Super",
"User",
"access",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L317-L334 |
209,431 | matomo-org/matomo | plugins/SitesManager/API.php | API.getSitesWithAdminAccess | public function getSitesWithAdminAccess($fetchAliasUrls = false, $pattern = false, $limit = false)
{
$sitesId = $this->getSitesIdWithAdminAccess();
if ($pattern === false) {
$sites = $this->getSitesFromIds($sitesId, $limit);
} else {
$sites = $this->getModel()->getPatternMatchSites($sitesId, $pattern, $limit);
foreach ($sites as &$site) {
$this->enrichSite($site);
}
$sites = Site::setSitesFromArray($sites);
}
if ($fetchAliasUrls) {
foreach ($sites as &$site) {
$site['alias_urls'] = $this->getSiteUrlsFromId($site['idsite']);
}
}
return $sites;
} | php | public function getSitesWithAdminAccess($fetchAliasUrls = false, $pattern = false, $limit = false)
{
$sitesId = $this->getSitesIdWithAdminAccess();
if ($pattern === false) {
$sites = $this->getSitesFromIds($sitesId, $limit);
} else {
$sites = $this->getModel()->getPatternMatchSites($sitesId, $pattern, $limit);
foreach ($sites as &$site) {
$this->enrichSite($site);
}
$sites = Site::setSitesFromArray($sites);
}
if ($fetchAliasUrls) {
foreach ($sites as &$site) {
$site['alias_urls'] = $this->getSiteUrlsFromId($site['idsite']);
}
}
return $sites;
} | [
"public",
"function",
"getSitesWithAdminAccess",
"(",
"$",
"fetchAliasUrls",
"=",
"false",
",",
"$",
"pattern",
"=",
"false",
",",
"$",
"limit",
"=",
"false",
")",
"{",
"$",
"sitesId",
"=",
"$",
"this",
"->",
"getSitesIdWithAdminAccess",
"(",
")",
";",
"if",
"(",
"$",
"pattern",
"===",
"false",
")",
"{",
"$",
"sites",
"=",
"$",
"this",
"->",
"getSitesFromIds",
"(",
"$",
"sitesId",
",",
"$",
"limit",
")",
";",
"}",
"else",
"{",
"$",
"sites",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"getPatternMatchSites",
"(",
"$",
"sitesId",
",",
"$",
"pattern",
",",
"$",
"limit",
")",
";",
"foreach",
"(",
"$",
"sites",
"as",
"&",
"$",
"site",
")",
"{",
"$",
"this",
"->",
"enrichSite",
"(",
"$",
"site",
")",
";",
"}",
"$",
"sites",
"=",
"Site",
"::",
"setSitesFromArray",
"(",
"$",
"sites",
")",
";",
"}",
"if",
"(",
"$",
"fetchAliasUrls",
")",
"{",
"foreach",
"(",
"$",
"sites",
"as",
"&",
"$",
"site",
")",
"{",
"$",
"site",
"[",
"'alias_urls'",
"]",
"=",
"$",
"this",
"->",
"getSiteUrlsFromId",
"(",
"$",
"site",
"[",
"'idsite'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"sites",
";",
"}"
] | Returns the list of websites with the 'admin' access for the current user.
For the superUser it returns all the websites in the database.
@param bool $fetchAliasUrls
@param false|string $pattern
@param false|int $limit
@return array for each site, an array of information (idsite, name, main_url, etc.) | [
"Returns",
"the",
"list",
"of",
"websites",
"with",
"the",
"admin",
"access",
"for",
"the",
"current",
"user",
".",
"For",
"the",
"superUser",
"it",
"returns",
"all",
"the",
"websites",
"in",
"the",
"database",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L345-L368 |
209,432 | matomo-org/matomo | plugins/SitesManager/API.php | API.getSitesWithAtLeastViewAccess | public function getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin = false)
{
$sitesId = $this->getSitesIdWithAtLeastViewAccess($_restrictSitesToLogin);
return $this->getSitesFromIds($sitesId, $limit);
} | php | public function getSitesWithAtLeastViewAccess($limit = false, $_restrictSitesToLogin = false)
{
$sitesId = $this->getSitesIdWithAtLeastViewAccess($_restrictSitesToLogin);
return $this->getSitesFromIds($sitesId, $limit);
} | [
"public",
"function",
"getSitesWithAtLeastViewAccess",
"(",
"$",
"limit",
"=",
"false",
",",
"$",
"_restrictSitesToLogin",
"=",
"false",
")",
"{",
"$",
"sitesId",
"=",
"$",
"this",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
"$",
"_restrictSitesToLogin",
")",
";",
"return",
"$",
"this",
"->",
"getSitesFromIds",
"(",
"$",
"sitesId",
",",
"$",
"limit",
")",
";",
"}"
] | Returns the list of websites with the 'view' or 'admin' access for the current user.
For the superUser it returns all the websites in the database.
@param bool|int $limit Specify max number of sites to return
@param bool $_restrictSitesToLogin Hack necessary when running scheduled tasks, where "Super User" is forced, but sometimes not desired, see #3017
@return array array for each site, an array of information (idsite, name, main_url, etc.) | [
"Returns",
"the",
"list",
"of",
"websites",
"with",
"the",
"view",
"or",
"admin",
"access",
"for",
"the",
"current",
"user",
".",
"For",
"the",
"superUser",
"it",
"returns",
"all",
"the",
"websites",
"in",
"the",
"database",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L390-L394 |
209,433 | matomo-org/matomo | plugins/SitesManager/API.php | API.getSitesIdWithAtLeastViewAccess | public function getSitesIdWithAtLeastViewAccess($_restrictSitesToLogin = false)
{
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\Scheduler\Scheduler');
if (Piwik::hasUserSuperUserAccess() && !$scheduler->isRunningTask()) {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
if (!empty($_restrictSitesToLogin)
// Only Super User or logged in user can see viewable sites for a specific login,
// but during scheduled task execution, we sometimes want to restrict sites to
// a different login than the superuser.
&& (Piwik::hasUserSuperUserAccessOrIsTheUser($_restrictSitesToLogin)
|| $scheduler->isRunningTask())
) {
if (Piwik::hasTheUserSuperUserAccess($_restrictSitesToLogin)) {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
$accessRaw = Access::getInstance()->getRawSitesWithSomeViewAccess($_restrictSitesToLogin);
$sitesId = array();
foreach ($accessRaw as $access) {
$sitesId[] = $access['idsite'];
}
return $sitesId;
} else {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
} | php | public function getSitesIdWithAtLeastViewAccess($_restrictSitesToLogin = false)
{
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\Scheduler\Scheduler');
if (Piwik::hasUserSuperUserAccess() && !$scheduler->isRunningTask()) {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
if (!empty($_restrictSitesToLogin)
// Only Super User or logged in user can see viewable sites for a specific login,
// but during scheduled task execution, we sometimes want to restrict sites to
// a different login than the superuser.
&& (Piwik::hasUserSuperUserAccessOrIsTheUser($_restrictSitesToLogin)
|| $scheduler->isRunningTask())
) {
if (Piwik::hasTheUserSuperUserAccess($_restrictSitesToLogin)) {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
$accessRaw = Access::getInstance()->getRawSitesWithSomeViewAccess($_restrictSitesToLogin);
$sitesId = array();
foreach ($accessRaw as $access) {
$sitesId[] = $access['idsite'];
}
return $sitesId;
} else {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
} | [
"public",
"function",
"getSitesIdWithAtLeastViewAccess",
"(",
"$",
"_restrictSitesToLogin",
"=",
"false",
")",
"{",
"/** @var Scheduler $scheduler */",
"$",
"scheduler",
"=",
"StaticContainer",
"::",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'Piwik\\Scheduler\\Scheduler'",
")",
";",
"if",
"(",
"Piwik",
"::",
"hasUserSuperUserAccess",
"(",
")",
"&&",
"!",
"$",
"scheduler",
"->",
"isRunningTask",
"(",
")",
")",
"{",
"return",
"Access",
"::",
"getInstance",
"(",
")",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_restrictSitesToLogin",
")",
"// Only Super User or logged in user can see viewable sites for a specific login,",
"// but during scheduled task execution, we sometimes want to restrict sites to",
"// a different login than the superuser.",
"&&",
"(",
"Piwik",
"::",
"hasUserSuperUserAccessOrIsTheUser",
"(",
"$",
"_restrictSitesToLogin",
")",
"||",
"$",
"scheduler",
"->",
"isRunningTask",
"(",
")",
")",
")",
"{",
"if",
"(",
"Piwik",
"::",
"hasTheUserSuperUserAccess",
"(",
"$",
"_restrictSitesToLogin",
")",
")",
"{",
"return",
"Access",
"::",
"getInstance",
"(",
")",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
";",
"}",
"$",
"accessRaw",
"=",
"Access",
"::",
"getInstance",
"(",
")",
"->",
"getRawSitesWithSomeViewAccess",
"(",
"$",
"_restrictSitesToLogin",
")",
";",
"$",
"sitesId",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"accessRaw",
"as",
"$",
"access",
")",
"{",
"$",
"sitesId",
"[",
"]",
"=",
"$",
"access",
"[",
"'idsite'",
"]",
";",
"}",
"return",
"$",
"sitesId",
";",
"}",
"else",
"{",
"return",
"Access",
"::",
"getInstance",
"(",
")",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
";",
"}",
"}"
] | Returns the list of websites ID with the 'view' or 'admin' access for the current user.
For the superUser it returns all the websites in the database.
@param bool $_restrictSitesToLogin
@return array list of websites ID | [
"Returns",
"the",
"list",
"of",
"websites",
"ID",
"with",
"the",
"view",
"or",
"admin",
"access",
"for",
"the",
"current",
"user",
".",
"For",
"the",
"superUser",
"it",
"returns",
"all",
"the",
"websites",
"in",
"the",
"database",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L437-L469 |
209,434 | matomo-org/matomo | plugins/SitesManager/API.php | API.getSitesFromIds | private function getSitesFromIds($idSites, $limit = false)
{
$sites = $this->getModel()->getSitesFromIds($idSites, $limit);
foreach ($sites as &$site) {
$this->enrichSite($site);
}
$sites = Site::setSitesFromArray($sites);
return $sites;
} | php | private function getSitesFromIds($idSites, $limit = false)
{
$sites = $this->getModel()->getSitesFromIds($idSites, $limit);
foreach ($sites as &$site) {
$this->enrichSite($site);
}
$sites = Site::setSitesFromArray($sites);
return $sites;
} | [
"private",
"function",
"getSitesFromIds",
"(",
"$",
"idSites",
",",
"$",
"limit",
"=",
"false",
")",
"{",
"$",
"sites",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"getSitesFromIds",
"(",
"$",
"idSites",
",",
"$",
"limit",
")",
";",
"foreach",
"(",
"$",
"sites",
"as",
"&",
"$",
"site",
")",
"{",
"$",
"this",
"->",
"enrichSite",
"(",
"$",
"site",
")",
";",
"}",
"$",
"sites",
"=",
"Site",
"::",
"setSitesFromArray",
"(",
"$",
"sites",
")",
";",
"return",
"$",
"sites",
";",
"}"
] | Returns the list of websites from the ID array in parameters.
The user access is not checked in this method so the ID have to be accessible by the user!
@param array $idSites list of website ID
@param bool $limit
@return array | [
"Returns",
"the",
"list",
"of",
"websites",
"from",
"the",
"ID",
"array",
"in",
"parameters",
".",
"The",
"user",
"access",
"is",
"not",
"checked",
"in",
"this",
"method",
"so",
"the",
"ID",
"have",
"to",
"be",
"accessible",
"by",
"the",
"user!"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L479-L490 |
209,435 | matomo-org/matomo | plugins/SitesManager/API.php | API.addSiteAliasUrls | public function addSiteAliasUrls($idSite, $urls)
{
Piwik::checkUserHasAdminAccess($idSite);
if (empty($urls)) {
return 0;
}
if (!is_array($urls)) {
$urls = array($urls);
}
$urlsInit = $this->getSiteUrlsFromId($idSite);
$toInsert = array_merge($urlsInit, $urls);
$urlsProperty = new Urls($idSite);
$urlsProperty->setValue($toInsert);
$urlsProperty->save();
$inserted = array_diff($urlsProperty->getValue(), $urlsInit);
$this->postUpdateWebsite($idSite);
return count($inserted);
} | php | public function addSiteAliasUrls($idSite, $urls)
{
Piwik::checkUserHasAdminAccess($idSite);
if (empty($urls)) {
return 0;
}
if (!is_array($urls)) {
$urls = array($urls);
}
$urlsInit = $this->getSiteUrlsFromId($idSite);
$toInsert = array_merge($urlsInit, $urls);
$urlsProperty = new Urls($idSite);
$urlsProperty->setValue($toInsert);
$urlsProperty->save();
$inserted = array_diff($urlsProperty->getValue(), $urlsInit);
$this->postUpdateWebsite($idSite);
return count($inserted);
} | [
"public",
"function",
"addSiteAliasUrls",
"(",
"$",
"idSite",
",",
"$",
"urls",
")",
"{",
"Piwik",
"::",
"checkUserHasAdminAccess",
"(",
"$",
"idSite",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"urls",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"urls",
")",
")",
"{",
"$",
"urls",
"=",
"array",
"(",
"$",
"urls",
")",
";",
"}",
"$",
"urlsInit",
"=",
"$",
"this",
"->",
"getSiteUrlsFromId",
"(",
"$",
"idSite",
")",
";",
"$",
"toInsert",
"=",
"array_merge",
"(",
"$",
"urlsInit",
",",
"$",
"urls",
")",
";",
"$",
"urlsProperty",
"=",
"new",
"Urls",
"(",
"$",
"idSite",
")",
";",
"$",
"urlsProperty",
"->",
"setValue",
"(",
"$",
"toInsert",
")",
";",
"$",
"urlsProperty",
"->",
"save",
"(",
")",
";",
"$",
"inserted",
"=",
"array_diff",
"(",
"$",
"urlsProperty",
"->",
"getValue",
"(",
")",
",",
"$",
"urlsInit",
")",
";",
"$",
"this",
"->",
"postUpdateWebsite",
"(",
"$",
"idSite",
")",
";",
"return",
"count",
"(",
"$",
"inserted",
")",
";",
"}"
] | Add a list of alias Urls to the given idSite
If some URLs given in parameter are already recorded as alias URLs for this website,
they won't be duplicated. The 'main_url' of the website won't be affected by this method.
@param int $idSite
@param array|string $urls When calling API via HTTP specify multiple URLs via `&urls[]=http...&urls[]=http...`.
@return int the number of inserted URLs | [
"Add",
"a",
"list",
"of",
"alias",
"Urls",
"to",
"the",
"given",
"idSite"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L893-L917 |
209,436 | matomo-org/matomo | plugins/SitesManager/API.php | API.setSiteAliasUrls | public function setSiteAliasUrls($idSite, $urls = array())
{
Piwik::checkUserHasAdminAccess($idSite);
$mainUrl = Site::getMainUrlFor($idSite);
array_unshift($urls, $mainUrl);
$urlsProperty = new Urls($idSite);
$urlsProperty->setValue($urls);
$urlsProperty->save();
$inserted = array_diff($urlsProperty->getValue(), $urls);
$this->postUpdateWebsite($idSite);
return count($inserted);
} | php | public function setSiteAliasUrls($idSite, $urls = array())
{
Piwik::checkUserHasAdminAccess($idSite);
$mainUrl = Site::getMainUrlFor($idSite);
array_unshift($urls, $mainUrl);
$urlsProperty = new Urls($idSite);
$urlsProperty->setValue($urls);
$urlsProperty->save();
$inserted = array_diff($urlsProperty->getValue(), $urls);
$this->postUpdateWebsite($idSite);
return count($inserted);
} | [
"public",
"function",
"setSiteAliasUrls",
"(",
"$",
"idSite",
",",
"$",
"urls",
"=",
"array",
"(",
")",
")",
"{",
"Piwik",
"::",
"checkUserHasAdminAccess",
"(",
"$",
"idSite",
")",
";",
"$",
"mainUrl",
"=",
"Site",
"::",
"getMainUrlFor",
"(",
"$",
"idSite",
")",
";",
"array_unshift",
"(",
"$",
"urls",
",",
"$",
"mainUrl",
")",
";",
"$",
"urlsProperty",
"=",
"new",
"Urls",
"(",
"$",
"idSite",
")",
";",
"$",
"urlsProperty",
"->",
"setValue",
"(",
"$",
"urls",
")",
";",
"$",
"urlsProperty",
"->",
"save",
"(",
")",
";",
"$",
"inserted",
"=",
"array_diff",
"(",
"$",
"urlsProperty",
"->",
"getValue",
"(",
")",
",",
"$",
"urls",
")",
";",
"$",
"this",
"->",
"postUpdateWebsite",
"(",
"$",
"idSite",
")",
";",
"return",
"count",
"(",
"$",
"inserted",
")",
";",
"}"
] | Set the list of alias Urls for the given idSite
Completely overwrites the current list of URLs with the provided list.
The 'main_url' of the website won't be affected by this method.
@return int the number of inserted URLs | [
"Set",
"the",
"list",
"of",
"alias",
"Urls",
"for",
"the",
"given",
"idSite"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L927-L943 |
209,437 | matomo-org/matomo | plugins/SitesManager/API.php | API.getIpsForRange | public function getIpsForRange($ipRange)
{
$range = IPUtils::getIPRangeBounds($ipRange);
if ($range === null) {
return false;
}
return array(IPUtils::binaryToStringIP($range[0]), IPUtils::binaryToStringIP($range[1]));
} | php | public function getIpsForRange($ipRange)
{
$range = IPUtils::getIPRangeBounds($ipRange);
if ($range === null) {
return false;
}
return array(IPUtils::binaryToStringIP($range[0]), IPUtils::binaryToStringIP($range[1]));
} | [
"public",
"function",
"getIpsForRange",
"(",
"$",
"ipRange",
")",
"{",
"$",
"range",
"=",
"IPUtils",
"::",
"getIPRangeBounds",
"(",
"$",
"ipRange",
")",
";",
"if",
"(",
"$",
"range",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"array",
"(",
"IPUtils",
"::",
"binaryToStringIP",
"(",
"$",
"range",
"[",
"0",
"]",
")",
",",
"IPUtils",
"::",
"binaryToStringIP",
"(",
"$",
"range",
"[",
"1",
"]",
")",
")",
";",
"}"
] | Get the start and end IP addresses for an IP address range
@param string $ipRange IP address range in presentation format
@return array|false Array( low, high ) IP addresses in presentation format; or false if error | [
"Get",
"the",
"start",
"and",
"end",
"IP",
"addresses",
"for",
"an",
"IP",
"address",
"range"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L951-L959 |
209,438 | matomo-org/matomo | plugins/SitesManager/API.php | API.setGlobalExcludedIps | public function setGlobalExcludedIps($excludedIps)
{
Piwik::checkUserHasSuperUserAccess();
$excludedIps = $this->checkAndReturnExcludedIps($excludedIps);
Option::set(self::OPTION_EXCLUDED_IPS_GLOBAL, $excludedIps);
Cache::deleteTrackerCache();
return true;
} | php | public function setGlobalExcludedIps($excludedIps)
{
Piwik::checkUserHasSuperUserAccess();
$excludedIps = $this->checkAndReturnExcludedIps($excludedIps);
Option::set(self::OPTION_EXCLUDED_IPS_GLOBAL, $excludedIps);
Cache::deleteTrackerCache();
return true;
} | [
"public",
"function",
"setGlobalExcludedIps",
"(",
"$",
"excludedIps",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"$",
"excludedIps",
"=",
"$",
"this",
"->",
"checkAndReturnExcludedIps",
"(",
"$",
"excludedIps",
")",
";",
"Option",
"::",
"set",
"(",
"self",
"::",
"OPTION_EXCLUDED_IPS_GLOBAL",
",",
"$",
"excludedIps",
")",
";",
"Cache",
"::",
"deleteTrackerCache",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Sets IPs to be excluded from all websites. IPs can contain wildcards.
Will also apply to websites created in the future.
@param string $excludedIps Comma separated list of IPs to exclude from being tracked (allows wildcards)
@return bool | [
"Sets",
"IPs",
"to",
"be",
"excluded",
"from",
"all",
"websites",
".",
"IPs",
"can",
"contain",
"wildcards",
".",
"Will",
"also",
"apply",
"to",
"websites",
"created",
"in",
"the",
"future",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L968-L975 |
209,439 | matomo-org/matomo | plugins/SitesManager/API.php | API.setSiteSpecificUserAgentExcludeEnabled | public function setSiteSpecificUserAgentExcludeEnabled($enabled)
{
Piwik::checkUserHasSuperUserAccess();
// update option
Option::set(self::OPTION_SITE_SPECIFIC_USER_AGENT_EXCLUDE_ENABLE, $enabled);
// make sure tracker cache will reflect change
Cache::deleteTrackerCache();
} | php | public function setSiteSpecificUserAgentExcludeEnabled($enabled)
{
Piwik::checkUserHasSuperUserAccess();
// update option
Option::set(self::OPTION_SITE_SPECIFIC_USER_AGENT_EXCLUDE_ENABLE, $enabled);
// make sure tracker cache will reflect change
Cache::deleteTrackerCache();
} | [
"public",
"function",
"setSiteSpecificUserAgentExcludeEnabled",
"(",
"$",
"enabled",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"// update option",
"Option",
"::",
"set",
"(",
"self",
"::",
"OPTION_SITE_SPECIFIC_USER_AGENT_EXCLUDE_ENABLE",
",",
"$",
"enabled",
")",
";",
"// make sure tracker cache will reflect change",
"Cache",
"::",
"deleteTrackerCache",
"(",
")",
";",
"}"
] | Sets whether it should be allowed to exclude different user agents for different
websites.
@param bool $enabled | [
"Sets",
"whether",
"it",
"should",
"be",
"allowed",
"to",
"exclude",
"different",
"user",
"agents",
"for",
"different",
"websites",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1080-L1089 |
209,440 | matomo-org/matomo | plugins/SitesManager/API.php | API.setKeepURLFragmentsGlobal | public function setKeepURLFragmentsGlobal($enabled)
{
Piwik::checkUserHasSuperUserAccess();
// update option
Option::set(self::OPTION_KEEP_URL_FRAGMENTS_GLOBAL, $enabled);
// make sure tracker cache will reflect change
Cache::deleteTrackerCache();
} | php | public function setKeepURLFragmentsGlobal($enabled)
{
Piwik::checkUserHasSuperUserAccess();
// update option
Option::set(self::OPTION_KEEP_URL_FRAGMENTS_GLOBAL, $enabled);
// make sure tracker cache will reflect change
Cache::deleteTrackerCache();
} | [
"public",
"function",
"setKeepURLFragmentsGlobal",
"(",
"$",
"enabled",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"// update option",
"Option",
"::",
"set",
"(",
"self",
"::",
"OPTION_KEEP_URL_FRAGMENTS_GLOBAL",
",",
"$",
"enabled",
")",
";",
"// make sure tracker cache will reflect change",
"Cache",
"::",
"deleteTrackerCache",
"(",
")",
";",
"}"
] | Sets whether the default behavior should be to keep URL fragments when
tracking or not.
@param $enabled bool If true, the default behavior will be to keep URL
fragments when tracking. If false, the default
behavior will be to remove them. | [
"Sets",
"whether",
"the",
"default",
"behavior",
"should",
"be",
"to",
"keep",
"URL",
"fragments",
"when",
"tracking",
"or",
"not",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1111-L1120 |
209,441 | matomo-org/matomo | plugins/SitesManager/API.php | API.setGlobalExcludedQueryParameters | public function setGlobalExcludedQueryParameters($excludedQueryParameters)
{
Piwik::checkUserHasSuperUserAccess();
$excludedQueryParameters = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters);
Option::set(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL, $excludedQueryParameters);
Cache::deleteTrackerCache();
return true;
} | php | public function setGlobalExcludedQueryParameters($excludedQueryParameters)
{
Piwik::checkUserHasSuperUserAccess();
$excludedQueryParameters = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters);
Option::set(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL, $excludedQueryParameters);
Cache::deleteTrackerCache();
return true;
} | [
"public",
"function",
"setGlobalExcludedQueryParameters",
"(",
"$",
"excludedQueryParameters",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"$",
"excludedQueryParameters",
"=",
"$",
"this",
"->",
"checkAndReturnCommaSeparatedStringList",
"(",
"$",
"excludedQueryParameters",
")",
";",
"Option",
"::",
"set",
"(",
"self",
"::",
"OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL",
",",
"$",
"excludedQueryParameters",
")",
";",
"Cache",
"::",
"deleteTrackerCache",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Sets list of URL query parameters to be excluded on all websites.
Will also apply to websites created in the future.
@param string $excludedQueryParameters Comma separated list of URL query parameters to exclude from URLs
@return bool | [
"Sets",
"list",
"of",
"URL",
"query",
"parameters",
"to",
"be",
"excluded",
"on",
"all",
"websites",
".",
"Will",
"also",
"apply",
"to",
"websites",
"created",
"in",
"the",
"future",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1129-L1136 |
209,442 | matomo-org/matomo | plugins/SitesManager/API.php | API.getDefaultCurrency | public function getDefaultCurrency()
{
Piwik::checkUserHasSomeAdminAccess();
$defaultCurrency = Option::get(self::OPTION_DEFAULT_CURRENCY);
if ($defaultCurrency) {
return $defaultCurrency;
}
return 'USD';
} | php | public function getDefaultCurrency()
{
Piwik::checkUserHasSomeAdminAccess();
$defaultCurrency = Option::get(self::OPTION_DEFAULT_CURRENCY);
if ($defaultCurrency) {
return $defaultCurrency;
}
return 'USD';
} | [
"public",
"function",
"getDefaultCurrency",
"(",
")",
"{",
"Piwik",
"::",
"checkUserHasSomeAdminAccess",
"(",
")",
";",
"$",
"defaultCurrency",
"=",
"Option",
"::",
"get",
"(",
"self",
"::",
"OPTION_DEFAULT_CURRENCY",
")",
";",
"if",
"(",
"$",
"defaultCurrency",
")",
"{",
"return",
"$",
"defaultCurrency",
";",
"}",
"return",
"'USD'",
";",
"}"
] | Returns the default currency that will be set when creating a website through the API.
@return string Currency ID eg. 'USD' | [
"Returns",
"the",
"default",
"currency",
"that",
"will",
"be",
"set",
"when",
"creating",
"a",
"website",
"through",
"the",
"API",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1154-L1162 |
209,443 | matomo-org/matomo | plugins/SitesManager/API.php | API.setDefaultCurrency | public function setDefaultCurrency($defaultCurrency)
{
Piwik::checkUserHasSuperUserAccess();
$this->checkValidCurrency($defaultCurrency);
Option::set(self::OPTION_DEFAULT_CURRENCY, $defaultCurrency);
return true;
} | php | public function setDefaultCurrency($defaultCurrency)
{
Piwik::checkUserHasSuperUserAccess();
$this->checkValidCurrency($defaultCurrency);
Option::set(self::OPTION_DEFAULT_CURRENCY, $defaultCurrency);
return true;
} | [
"public",
"function",
"setDefaultCurrency",
"(",
"$",
"defaultCurrency",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"$",
"this",
"->",
"checkValidCurrency",
"(",
"$",
"defaultCurrency",
")",
";",
"Option",
"::",
"set",
"(",
"self",
"::",
"OPTION_DEFAULT_CURRENCY",
",",
"$",
"defaultCurrency",
")",
";",
"return",
"true",
";",
"}"
] | Sets the default currency that will be used when creating websites
@param string $defaultCurrency Currency code, eg. 'USD'
@return bool | [
"Sets",
"the",
"default",
"currency",
"that",
"will",
"be",
"used",
"when",
"creating",
"websites"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1170-L1176 |
209,444 | matomo-org/matomo | plugins/SitesManager/API.php | API.setDefaultTimezone | public function setDefaultTimezone($defaultTimezone)
{
Piwik::checkUserHasSuperUserAccess();
$this->checkValidTimezone($defaultTimezone);
Option::set(self::OPTION_DEFAULT_TIMEZONE, $defaultTimezone);
return true;
} | php | public function setDefaultTimezone($defaultTimezone)
{
Piwik::checkUserHasSuperUserAccess();
$this->checkValidTimezone($defaultTimezone);
Option::set(self::OPTION_DEFAULT_TIMEZONE, $defaultTimezone);
return true;
} | [
"public",
"function",
"setDefaultTimezone",
"(",
"$",
"defaultTimezone",
")",
"{",
"Piwik",
"::",
"checkUserHasSuperUserAccess",
"(",
")",
";",
"$",
"this",
"->",
"checkValidTimezone",
"(",
"$",
"defaultTimezone",
")",
";",
"Option",
"::",
"set",
"(",
"self",
"::",
"OPTION_DEFAULT_TIMEZONE",
",",
"$",
"defaultTimezone",
")",
";",
"return",
"true",
";",
"}"
] | Sets the default timezone that will be used when creating websites
@param string $defaultTimezone Timezone string eg. Europe/Paris or UTC+8
@return bool | [
"Sets",
"the",
"default",
"timezone",
"that",
"will",
"be",
"used",
"when",
"creating",
"websites"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1199-L1205 |
209,445 | matomo-org/matomo | plugins/SitesManager/API.php | API.getCurrencyList | public function getCurrencyList()
{
$currency = Site::getCurrencyList();
$return = array();
foreach (array_keys(Site::getCurrencyList()) as $currencyCode) {
$return[$currencyCode] = Piwik::translate('Intl_Currency_' . $currencyCode) .
' (' . Piwik::translate('Intl_CurrencySymbol_' . $currencyCode) . ')';
}
asort($return);
return $return;
} | php | public function getCurrencyList()
{
$currency = Site::getCurrencyList();
$return = array();
foreach (array_keys(Site::getCurrencyList()) as $currencyCode) {
$return[$currencyCode] = Piwik::translate('Intl_Currency_' . $currencyCode) .
' (' . Piwik::translate('Intl_CurrencySymbol_' . $currencyCode) . ')';
}
asort($return);
return $return;
} | [
"public",
"function",
"getCurrencyList",
"(",
")",
"{",
"$",
"currency",
"=",
"Site",
"::",
"getCurrencyList",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"Site",
"::",
"getCurrencyList",
"(",
")",
")",
"as",
"$",
"currencyCode",
")",
"{",
"$",
"return",
"[",
"$",
"currencyCode",
"]",
"=",
"Piwik",
"::",
"translate",
"(",
"'Intl_Currency_'",
".",
"$",
"currencyCode",
")",
".",
"' ('",
".",
"Piwik",
"::",
"translate",
"(",
"'Intl_CurrencySymbol_'",
".",
"$",
"currencyCode",
")",
".",
"')'",
";",
"}",
"asort",
"(",
"$",
"return",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Returns the list of supported currencies
@see getCurrencySymbols()
@return array ( currencyId => currencyName) | [
"Returns",
"the",
"list",
"of",
"supported",
"currencies"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1376-L1389 |
209,446 | matomo-org/matomo | plugins/SitesManager/API.php | API.getTimezonesList | public function getTimezonesList()
{
if (!SettingsServer::isTimezoneSupportEnabled()) {
return array('UTC' => $this->getTimezonesListUTCOffsets());
}
$countries = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider')->getCountryList();
$return = array();
$continents = array();
foreach ($countries as $countryCode => $continentCode) {
$countryCode = strtoupper($countryCode);
$timezones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $countryCode);
foreach ($timezones as $timezone) {
if (!isset($continents[$continentCode])) {
$continents[$continentCode] = Piwik::translate('Intl_Continent_' . $continentCode);
}
$continent = $continents[$continentCode];
$return[$continent][$timezone] = $this->getTimezoneName($timezone, $countryCode, count($timezones) > 1);
}
}
// Sort by continent name and then by country name.
ksort($return);
foreach ($return as $continent => $countries) {
asort($return[$continent]);
}
$return['UTC'] = $this->getTimezonesListUTCOffsets();
return $return;
} | php | public function getTimezonesList()
{
if (!SettingsServer::isTimezoneSupportEnabled()) {
return array('UTC' => $this->getTimezonesListUTCOffsets());
}
$countries = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider')->getCountryList();
$return = array();
$continents = array();
foreach ($countries as $countryCode => $continentCode) {
$countryCode = strtoupper($countryCode);
$timezones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $countryCode);
foreach ($timezones as $timezone) {
if (!isset($continents[$continentCode])) {
$continents[$continentCode] = Piwik::translate('Intl_Continent_' . $continentCode);
}
$continent = $continents[$continentCode];
$return[$continent][$timezone] = $this->getTimezoneName($timezone, $countryCode, count($timezones) > 1);
}
}
// Sort by continent name and then by country name.
ksort($return);
foreach ($return as $continent => $countries) {
asort($return[$continent]);
}
$return['UTC'] = $this->getTimezonesListUTCOffsets();
return $return;
} | [
"public",
"function",
"getTimezonesList",
"(",
")",
"{",
"if",
"(",
"!",
"SettingsServer",
"::",
"isTimezoneSupportEnabled",
"(",
")",
")",
"{",
"return",
"array",
"(",
"'UTC'",
"=>",
"$",
"this",
"->",
"getTimezonesListUTCOffsets",
"(",
")",
")",
";",
"}",
"$",
"countries",
"=",
"StaticContainer",
"::",
"get",
"(",
"'Piwik\\Intl\\Data\\Provider\\RegionDataProvider'",
")",
"->",
"getCountryList",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"$",
"continents",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"countries",
"as",
"$",
"countryCode",
"=>",
"$",
"continentCode",
")",
"{",
"$",
"countryCode",
"=",
"strtoupper",
"(",
"$",
"countryCode",
")",
";",
"$",
"timezones",
"=",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
"DateTimeZone",
"::",
"PER_COUNTRY",
",",
"$",
"countryCode",
")",
";",
"foreach",
"(",
"$",
"timezones",
"as",
"$",
"timezone",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"continents",
"[",
"$",
"continentCode",
"]",
")",
")",
"{",
"$",
"continents",
"[",
"$",
"continentCode",
"]",
"=",
"Piwik",
"::",
"translate",
"(",
"'Intl_Continent_'",
".",
"$",
"continentCode",
")",
";",
"}",
"$",
"continent",
"=",
"$",
"continents",
"[",
"$",
"continentCode",
"]",
";",
"$",
"return",
"[",
"$",
"continent",
"]",
"[",
"$",
"timezone",
"]",
"=",
"$",
"this",
"->",
"getTimezoneName",
"(",
"$",
"timezone",
",",
"$",
"countryCode",
",",
"count",
"(",
"$",
"timezones",
")",
">",
"1",
")",
";",
"}",
"}",
"// Sort by continent name and then by country name.",
"ksort",
"(",
"$",
"return",
")",
";",
"foreach",
"(",
"$",
"return",
"as",
"$",
"continent",
"=>",
"$",
"countries",
")",
"{",
"asort",
"(",
"$",
"return",
"[",
"$",
"continent",
"]",
")",
";",
"}",
"$",
"return",
"[",
"'UTC'",
"]",
"=",
"$",
"this",
"->",
"getTimezonesListUTCOffsets",
"(",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Returns the list of timezones supported.
Used for addSite and updateSite
@return array of timezone strings | [
"Returns",
"the",
"list",
"of",
"timezones",
"supported",
".",
"Used",
"for",
"addSite",
"and",
"updateSite"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1421-L1452 |
209,447 | matomo-org/matomo | plugins/SitesManager/API.php | API.removeTrailingSlash | private function removeTrailingSlash($url)
{
// if there is a final slash, we take the URL without this slash (expected URL format)
if (strlen($url) > 5
&& $url[strlen($url) - 1] == '/'
) {
$url = substr($url, 0, strlen($url) - 1);
}
return $url;
} | php | private function removeTrailingSlash($url)
{
// if there is a final slash, we take the URL without this slash (expected URL format)
if (strlen($url) > 5
&& $url[strlen($url) - 1] == '/'
) {
$url = substr($url, 0, strlen($url) - 1);
}
return $url;
} | [
"private",
"function",
"removeTrailingSlash",
"(",
"$",
"url",
")",
"{",
"// if there is a final slash, we take the URL without this slash (expected URL format)",
"if",
"(",
"strlen",
"(",
"$",
"url",
")",
">",
"5",
"&&",
"$",
"url",
"[",
"strlen",
"(",
"$",
"url",
")",
"-",
"1",
"]",
"==",
"'/'",
")",
"{",
"$",
"url",
"=",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"strlen",
"(",
"$",
"url",
")",
"-",
"1",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Remove the final slash in the URLs if found
@param string $url
@return string the URL without the trailing slash | [
"Remove",
"the",
"final",
"slash",
"in",
"the",
"URLs",
"if",
"found"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1548-L1558 |
209,448 | matomo-org/matomo | plugins/SitesManager/API.php | API.getPatternMatchSites | public function getPatternMatchSites($pattern, $limit = false)
{
$ids = $this->getSitesIdWithAtLeastViewAccess();
if (empty($ids)) {
return array();
}
$sites = $this->getModel()->getPatternMatchSites($ids, $pattern, $limit);
foreach ($sites as &$site) {
$this->enrichSite($site);
}
$sites = Site::setSitesFromArray($sites);
return $sites;
} | php | public function getPatternMatchSites($pattern, $limit = false)
{
$ids = $this->getSitesIdWithAtLeastViewAccess();
if (empty($ids)) {
return array();
}
$sites = $this->getModel()->getPatternMatchSites($ids, $pattern, $limit);
foreach ($sites as &$site) {
$this->enrichSite($site);
}
$sites = Site::setSitesFromArray($sites);
return $sites;
} | [
"public",
"function",
"getPatternMatchSites",
"(",
"$",
"pattern",
",",
"$",
"limit",
"=",
"false",
")",
"{",
"$",
"ids",
"=",
"$",
"this",
"->",
"getSitesIdWithAtLeastViewAccess",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"sites",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"getPatternMatchSites",
"(",
"$",
"ids",
",",
"$",
"pattern",
",",
"$",
"limit",
")",
";",
"foreach",
"(",
"$",
"sites",
"as",
"&",
"$",
"site",
")",
"{",
"$",
"this",
"->",
"enrichSite",
"(",
"$",
"site",
")",
";",
"}",
"$",
"sites",
"=",
"Site",
"::",
"setSitesFromArray",
"(",
"$",
"sites",
")",
";",
"return",
"$",
"sites",
";",
"}"
] | Find websites matching the given pattern.
Any website will be returned that matches the pattern in the name, URL or group.
To limit the number of returned sites you can either specify `filter_limit` as usual or `limit` which is
faster.
@param string $pattern
@param int|false $limit
@return array | [
"Find",
"websites",
"matching",
"the",
"given",
"pattern",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/SitesManager/API.php#L1635-L1651 |
209,449 | matomo-org/matomo | core/DataAccess/LogQueryBuilder.php | LogQueryBuilder.buildSelectQuery | private function buildSelectQuery($select, $from, $where, $groupBy, $orderBy, $limitAndOffset)
{
$sql = "
SELECT
$select
FROM
$from";
if ($where) {
$sql .= "
WHERE
$where";
}
if ($groupBy) {
$sql .= "
GROUP BY
$groupBy";
}
if ($orderBy) {
$sql .= "
ORDER BY
$orderBy";
}
$sql = $this->appendLimitClauseToQuery($sql, $limitAndOffset);
return $sql;
} | php | private function buildSelectQuery($select, $from, $where, $groupBy, $orderBy, $limitAndOffset)
{
$sql = "
SELECT
$select
FROM
$from";
if ($where) {
$sql .= "
WHERE
$where";
}
if ($groupBy) {
$sql .= "
GROUP BY
$groupBy";
}
if ($orderBy) {
$sql .= "
ORDER BY
$orderBy";
}
$sql = $this->appendLimitClauseToQuery($sql, $limitAndOffset);
return $sql;
} | [
"private",
"function",
"buildSelectQuery",
"(",
"$",
"select",
",",
"$",
"from",
",",
"$",
"where",
",",
"$",
"groupBy",
",",
"$",
"orderBy",
",",
"$",
"limitAndOffset",
")",
"{",
"$",
"sql",
"=",
"\"\n\t\t\tSELECT\n\t\t\t\t$select\n\t\t\tFROM\n\t\t\t\t$from\"",
";",
"if",
"(",
"$",
"where",
")",
"{",
"$",
"sql",
".=",
"\"\n\t\t\tWHERE\n\t\t\t\t$where\"",
";",
"}",
"if",
"(",
"$",
"groupBy",
")",
"{",
"$",
"sql",
".=",
"\"\n\t\t\tGROUP BY\n\t\t\t\t$groupBy\"",
";",
"}",
"if",
"(",
"$",
"orderBy",
")",
"{",
"$",
"sql",
".=",
"\"\n\t\t\tORDER BY\n\t\t\t\t$orderBy\"",
";",
"}",
"$",
"sql",
"=",
"$",
"this",
"->",
"appendLimitClauseToQuery",
"(",
"$",
"sql",
",",
"$",
"limitAndOffset",
")",
";",
"return",
"$",
"sql",
";",
"}"
] | Build select query the normal way
@param string $select fieldlist to be selected
@param string $from tablelist to select from
@param string $where where clause
@param string $groupBy group by clause
@param string $orderBy order by clause
@param string|int $limitAndOffset limit by clause eg '5' for Limit 5 Offset 0 or '10, 5' for Limit 5 Offset 10
@return string | [
"Build",
"select",
"query",
"the",
"normal",
"way"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/DataAccess/LogQueryBuilder.php#L223-L252 |
209,450 | matomo-org/matomo | core/AssetManager.php | AssetManager.getCompiledBaseCss | public function getCompiledBaseCss()
{
$mergedAsset = new InMemoryUIAsset();
$assetMerger = new StylesheetUIAssetMerger($mergedAsset, $this->minimalStylesheetFetcher, $this->cacheBuster);
$assetMerger->generateFile();
return $mergedAsset;
} | php | public function getCompiledBaseCss()
{
$mergedAsset = new InMemoryUIAsset();
$assetMerger = new StylesheetUIAssetMerger($mergedAsset, $this->minimalStylesheetFetcher, $this->cacheBuster);
$assetMerger->generateFile();
return $mergedAsset;
} | [
"public",
"function",
"getCompiledBaseCss",
"(",
")",
"{",
"$",
"mergedAsset",
"=",
"new",
"InMemoryUIAsset",
"(",
")",
";",
"$",
"assetMerger",
"=",
"new",
"StylesheetUIAssetMerger",
"(",
"$",
"mergedAsset",
",",
"$",
"this",
"->",
"minimalStylesheetFetcher",
",",
"$",
"this",
"->",
"cacheBuster",
")",
";",
"$",
"assetMerger",
"->",
"generateFile",
"(",
")",
";",
"return",
"$",
"mergedAsset",
";",
"}"
] | Return the base.less compiled to css
@return UIAsset | [
"Return",
"the",
"base",
".",
"less",
"compiled",
"to",
"css"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/AssetManager.php#L141-L150 |
209,451 | matomo-org/matomo | core/AssetManager.php | AssetManager.getMergedStylesheet | public function getMergedStylesheet()
{
$mergedAsset = $this->getMergedStylesheetAsset();
$assetFetcher = new StylesheetUIAssetFetcher(Manager::getInstance()->getLoadedPluginsName(), $this->theme);
$assetMerger = new StylesheetUIAssetMerger($mergedAsset, $assetFetcher, $this->cacheBuster);
$assetMerger->generateFile();
return $mergedAsset;
} | php | public function getMergedStylesheet()
{
$mergedAsset = $this->getMergedStylesheetAsset();
$assetFetcher = new StylesheetUIAssetFetcher(Manager::getInstance()->getLoadedPluginsName(), $this->theme);
$assetMerger = new StylesheetUIAssetMerger($mergedAsset, $assetFetcher, $this->cacheBuster);
$assetMerger->generateFile();
return $mergedAsset;
} | [
"public",
"function",
"getMergedStylesheet",
"(",
")",
"{",
"$",
"mergedAsset",
"=",
"$",
"this",
"->",
"getMergedStylesheetAsset",
"(",
")",
";",
"$",
"assetFetcher",
"=",
"new",
"StylesheetUIAssetFetcher",
"(",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"getLoadedPluginsName",
"(",
")",
",",
"$",
"this",
"->",
"theme",
")",
";",
"$",
"assetMerger",
"=",
"new",
"StylesheetUIAssetMerger",
"(",
"$",
"mergedAsset",
",",
"$",
"assetFetcher",
",",
"$",
"this",
"->",
"cacheBuster",
")",
";",
"$",
"assetMerger",
"->",
"generateFile",
"(",
")",
";",
"return",
"$",
"mergedAsset",
";",
"}"
] | Return the css merged file absolute location.
If there is none, the generation process will be triggered.
@return UIAsset | [
"Return",
"the",
"css",
"merged",
"file",
"absolute",
"location",
".",
"If",
"there",
"is",
"none",
"the",
"generation",
"process",
"will",
"be",
"triggered",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/AssetManager.php#L158-L169 |
209,452 | matomo-org/matomo | core/AssetManager.php | AssetManager.removeMergedAssets | public function removeMergedAssets($pluginName = false)
{
$assetsToRemove = array($this->getMergedStylesheetAsset());
if ($pluginName) {
if ($this->pluginContainsJScriptAssets($pluginName)) {
if (Manager::getInstance()->isPluginBundledWithCore($pluginName)) {
$assetsToRemove[] = $this->getMergedCoreJSAsset();
} else {
$assetsToRemove[] = $this->getMergedNonCoreJSAsset();
}
}
} else {
$assetsToRemove[] = $this->getMergedCoreJSAsset();
$assetsToRemove[] = $this->getMergedNonCoreJSAsset();
}
$this->removeAssets($assetsToRemove);
} | php | public function removeMergedAssets($pluginName = false)
{
$assetsToRemove = array($this->getMergedStylesheetAsset());
if ($pluginName) {
if ($this->pluginContainsJScriptAssets($pluginName)) {
if (Manager::getInstance()->isPluginBundledWithCore($pluginName)) {
$assetsToRemove[] = $this->getMergedCoreJSAsset();
} else {
$assetsToRemove[] = $this->getMergedNonCoreJSAsset();
}
}
} else {
$assetsToRemove[] = $this->getMergedCoreJSAsset();
$assetsToRemove[] = $this->getMergedNonCoreJSAsset();
}
$this->removeAssets($assetsToRemove);
} | [
"public",
"function",
"removeMergedAssets",
"(",
"$",
"pluginName",
"=",
"false",
")",
"{",
"$",
"assetsToRemove",
"=",
"array",
"(",
"$",
"this",
"->",
"getMergedStylesheetAsset",
"(",
")",
")",
";",
"if",
"(",
"$",
"pluginName",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pluginContainsJScriptAssets",
"(",
"$",
"pluginName",
")",
")",
"{",
"if",
"(",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"isPluginBundledWithCore",
"(",
"$",
"pluginName",
")",
")",
"{",
"$",
"assetsToRemove",
"[",
"]",
"=",
"$",
"this",
"->",
"getMergedCoreJSAsset",
"(",
")",
";",
"}",
"else",
"{",
"$",
"assetsToRemove",
"[",
"]",
"=",
"$",
"this",
"->",
"getMergedNonCoreJSAsset",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"assetsToRemove",
"[",
"]",
"=",
"$",
"this",
"->",
"getMergedCoreJSAsset",
"(",
")",
";",
"$",
"assetsToRemove",
"[",
"]",
"=",
"$",
"this",
"->",
"getMergedNonCoreJSAsset",
"(",
")",
";",
"}",
"$",
"this",
"->",
"removeAssets",
"(",
"$",
"assetsToRemove",
")",
";",
"}"
] | Remove previous merged assets | [
"Remove",
"previous",
"merged",
"assets"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/AssetManager.php#L216-L234 |
209,453 | matomo-org/matomo | core/AssetManager.php | AssetManager.getAssetDirectory | public function getAssetDirectory()
{
$mergedFileDirectory = StaticContainer::get('path.tmp') . '/assets';
if (!is_dir($mergedFileDirectory)) {
Filesystem::mkdir($mergedFileDirectory);
}
if (!is_writable($mergedFileDirectory)) {
throw new Exception("Directory " . $mergedFileDirectory . " has to be writable.");
}
return $mergedFileDirectory;
} | php | public function getAssetDirectory()
{
$mergedFileDirectory = StaticContainer::get('path.tmp') . '/assets';
if (!is_dir($mergedFileDirectory)) {
Filesystem::mkdir($mergedFileDirectory);
}
if (!is_writable($mergedFileDirectory)) {
throw new Exception("Directory " . $mergedFileDirectory . " has to be writable.");
}
return $mergedFileDirectory;
} | [
"public",
"function",
"getAssetDirectory",
"(",
")",
"{",
"$",
"mergedFileDirectory",
"=",
"StaticContainer",
"::",
"get",
"(",
"'path.tmp'",
")",
".",
"'/assets'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"mergedFileDirectory",
")",
")",
"{",
"Filesystem",
"::",
"mkdir",
"(",
"$",
"mergedFileDirectory",
")",
";",
"}",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"mergedFileDirectory",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Directory \"",
".",
"$",
"mergedFileDirectory",
".",
"\" has to be writable.\"",
")",
";",
"}",
"return",
"$",
"mergedFileDirectory",
";",
"}"
] | Check if the merged file directory exists and is writable.
@return string The directory location
@throws Exception if directory is not writable. | [
"Check",
"if",
"the",
"merged",
"file",
"directory",
"exists",
"and",
"is",
"writable",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/AssetManager.php#L242-L255 |
209,454 | matomo-org/matomo | core/AssetManager.php | AssetManager.isMergedAssetsDisabled | public function isMergedAssetsDisabled()
{
if (Config::getInstance()->Development['disable_merged_assets'] == 1) {
return true;
}
if (isset($_GET['disable_merged_assets']) && $_GET['disable_merged_assets'] == 1) {
return true;
}
return false;
} | php | public function isMergedAssetsDisabled()
{
if (Config::getInstance()->Development['disable_merged_assets'] == 1) {
return true;
}
if (isset($_GET['disable_merged_assets']) && $_GET['disable_merged_assets'] == 1) {
return true;
}
return false;
} | [
"public",
"function",
"isMergedAssetsDisabled",
"(",
")",
"{",
"if",
"(",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"Development",
"[",
"'disable_merged_assets'",
"]",
"==",
"1",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'disable_merged_assets'",
"]",
")",
"&&",
"$",
"_GET",
"[",
"'disable_merged_assets'",
"]",
"==",
"1",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Return the global option disable_merged_assets
@return boolean | [
"Return",
"the",
"global",
"option",
"disable_merged_assets"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/AssetManager.php#L262-L273 |
209,455 | matomo-org/matomo | libs/HTML/QuickForm2/Controller/Page.php | HTML_QuickForm2_Controller_Page.setDefaultAction | public function setDefaultAction($actionName, $imageSrc = '')
{
// require_once 'HTML/QuickForm2/Controller/DefaultAction.php';
if (0 == count($this->form)) {
$image = $this->form->appendChild(
new HTML_QuickForm2_Controller_DefaultAction(
$this->getButtonName($actionName), array('src' => $imageSrc)
)
);
// replace the existing DefaultAction
} elseif ($image = $this->form->getElementById('_qf_default')) {
$image->setName($this->getButtonName($actionName))
->setAttribute('src', $imageSrc);
// Inject the element to the first position to improve chances that
// it ends up on top in the output
} else {
$it = $this->form->getIterator();
$it->rewind();
$image = $this->form->insertBefore(
new HTML_QuickForm2_Controller_DefaultAction(
$this->getButtonName($actionName), array('src' => $imageSrc)
),
$it->current()
);
}
return $image;
} | php | public function setDefaultAction($actionName, $imageSrc = '')
{
// require_once 'HTML/QuickForm2/Controller/DefaultAction.php';
if (0 == count($this->form)) {
$image = $this->form->appendChild(
new HTML_QuickForm2_Controller_DefaultAction(
$this->getButtonName($actionName), array('src' => $imageSrc)
)
);
// replace the existing DefaultAction
} elseif ($image = $this->form->getElementById('_qf_default')) {
$image->setName($this->getButtonName($actionName))
->setAttribute('src', $imageSrc);
// Inject the element to the first position to improve chances that
// it ends up on top in the output
} else {
$it = $this->form->getIterator();
$it->rewind();
$image = $this->form->insertBefore(
new HTML_QuickForm2_Controller_DefaultAction(
$this->getButtonName($actionName), array('src' => $imageSrc)
),
$it->current()
);
}
return $image;
} | [
"public",
"function",
"setDefaultAction",
"(",
"$",
"actionName",
",",
"$",
"imageSrc",
"=",
"''",
")",
"{",
"// require_once 'HTML/QuickForm2/Controller/DefaultAction.php';",
"if",
"(",
"0",
"==",
"count",
"(",
"$",
"this",
"->",
"form",
")",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"form",
"->",
"appendChild",
"(",
"new",
"HTML_QuickForm2_Controller_DefaultAction",
"(",
"$",
"this",
"->",
"getButtonName",
"(",
"$",
"actionName",
")",
",",
"array",
"(",
"'src'",
"=>",
"$",
"imageSrc",
")",
")",
")",
";",
"// replace the existing DefaultAction",
"}",
"elseif",
"(",
"$",
"image",
"=",
"$",
"this",
"->",
"form",
"->",
"getElementById",
"(",
"'_qf_default'",
")",
")",
"{",
"$",
"image",
"->",
"setName",
"(",
"$",
"this",
"->",
"getButtonName",
"(",
"$",
"actionName",
")",
")",
"->",
"setAttribute",
"(",
"'src'",
",",
"$",
"imageSrc",
")",
";",
"// Inject the element to the first position to improve chances that",
"// it ends up on top in the output",
"}",
"else",
"{",
"$",
"it",
"=",
"$",
"this",
"->",
"form",
"->",
"getIterator",
"(",
")",
";",
"$",
"it",
"->",
"rewind",
"(",
")",
";",
"$",
"image",
"=",
"$",
"this",
"->",
"form",
"->",
"insertBefore",
"(",
"new",
"HTML_QuickForm2_Controller_DefaultAction",
"(",
"$",
"this",
"->",
"getButtonName",
"(",
"$",
"actionName",
")",
",",
"array",
"(",
"'src'",
"=>",
"$",
"imageSrc",
")",
")",
",",
"$",
"it",
"->",
"current",
"(",
")",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Sets the default action invoked on page-form submit
This is necessary as the user may just press Enter instead of
clicking one of the named submit buttons and then no action name will
be passed to the script.
@param string Default action name
@param string Path to a 1x1 transparent GIF image
@return object Returns the image input used for default action | [
"Sets",
"the",
"default",
"action",
"invoked",
"on",
"page",
"-",
"form",
"submit"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Controller/Page.php#L181-L210 |
209,456 | matomo-org/matomo | libs/Zend/Cache/Frontend/Function.php | Zend_Cache_Frontend_Function.makeId | public function makeId($callback, array $args = array())
{
if (!is_callable($callback, true, $name)) {
Zend_Cache::throwException('Invalid callback');
}
// functions, methods and classnames are case-insensitive
$name = strtolower($name);
// generate a unique id for object callbacks
if (is_object($callback)) { // Closures & __invoke
$object = $callback;
} elseif (isset($callback[0])) { // array($object, 'method')
$object = $callback[0];
}
if (isset($object)) {
try {
$tmp = @serialize($callback);
} catch (Exception $e) {
Zend_Cache::throwException($e->getMessage());
}
if (!$tmp) {
$lastErr = error_get_last();
Zend_Cache::throwException("Can't serialize callback object to generate id: {$lastErr['message']}");
}
$name.= '__' . $tmp;
}
// generate a unique id for arguments
$argsStr = '';
if ($args) {
try {
$argsStr = @serialize(array_values($args));
} catch (Exception $e) {
Zend_Cache::throwException($e->getMessage());
}
if (!$argsStr) {
$lastErr = error_get_last();
throw Zend_Cache::throwException("Can't serialize arguments to generate id: {$lastErr['message']}");
}
}
return md5($name . $argsStr);
} | php | public function makeId($callback, array $args = array())
{
if (!is_callable($callback, true, $name)) {
Zend_Cache::throwException('Invalid callback');
}
// functions, methods and classnames are case-insensitive
$name = strtolower($name);
// generate a unique id for object callbacks
if (is_object($callback)) { // Closures & __invoke
$object = $callback;
} elseif (isset($callback[0])) { // array($object, 'method')
$object = $callback[0];
}
if (isset($object)) {
try {
$tmp = @serialize($callback);
} catch (Exception $e) {
Zend_Cache::throwException($e->getMessage());
}
if (!$tmp) {
$lastErr = error_get_last();
Zend_Cache::throwException("Can't serialize callback object to generate id: {$lastErr['message']}");
}
$name.= '__' . $tmp;
}
// generate a unique id for arguments
$argsStr = '';
if ($args) {
try {
$argsStr = @serialize(array_values($args));
} catch (Exception $e) {
Zend_Cache::throwException($e->getMessage());
}
if (!$argsStr) {
$lastErr = error_get_last();
throw Zend_Cache::throwException("Can't serialize arguments to generate id: {$lastErr['message']}");
}
}
return md5($name . $argsStr);
} | [
"public",
"function",
"makeId",
"(",
"$",
"callback",
",",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
",",
"true",
",",
"$",
"name",
")",
")",
"{",
"Zend_Cache",
"::",
"throwException",
"(",
"'Invalid callback'",
")",
";",
"}",
"// functions, methods and classnames are case-insensitive",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"// generate a unique id for object callbacks",
"if",
"(",
"is_object",
"(",
"$",
"callback",
")",
")",
"{",
"// Closures & __invoke",
"$",
"object",
"=",
"$",
"callback",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
")",
"{",
"// array($object, 'method')",
"$",
"object",
"=",
"$",
"callback",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"object",
")",
")",
"{",
"try",
"{",
"$",
"tmp",
"=",
"@",
"serialize",
"(",
"$",
"callback",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"Zend_Cache",
"::",
"throwException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"tmp",
")",
"{",
"$",
"lastErr",
"=",
"error_get_last",
"(",
")",
";",
"Zend_Cache",
"::",
"throwException",
"(",
"\"Can't serialize callback object to generate id: {$lastErr['message']}\"",
")",
";",
"}",
"$",
"name",
".=",
"'__'",
".",
"$",
"tmp",
";",
"}",
"// generate a unique id for arguments",
"$",
"argsStr",
"=",
"''",
";",
"if",
"(",
"$",
"args",
")",
"{",
"try",
"{",
"$",
"argsStr",
"=",
"@",
"serialize",
"(",
"array_values",
"(",
"$",
"args",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"Zend_Cache",
"::",
"throwException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"argsStr",
")",
"{",
"$",
"lastErr",
"=",
"error_get_last",
"(",
")",
";",
"throw",
"Zend_Cache",
"::",
"throwException",
"(",
"\"Can't serialize arguments to generate id: {$lastErr['message']}\"",
")",
";",
"}",
"}",
"return",
"md5",
"(",
"$",
"name",
".",
"$",
"argsStr",
")",
";",
"}"
] | Make a cache id from the function name and parameters
@param callback $callback A valid callback
@param array $args Function parameters
@throws Zend_Cache_Exception
@return string Cache id | [
"Make",
"a",
"cache",
"id",
"from",
"the",
"function",
"name",
"and",
"parameters"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Frontend/Function.php#L134-L177 |
209,457 | matomo-org/matomo | core/Archive/ArchiveQueryFactory.php | ArchiveQueryFactory.getSiteInfoFromQueryParam | protected function getSiteInfoFromQueryParam($idSites, $_restrictSitesToLogin)
{
$websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
$timezone = false;
if (count($websiteIds) == 1) {
$timezone = Site::getTimezoneFor($websiteIds[0]);
}
$idSiteIsAll = $idSites == Archive::REQUEST_ALL_WEBSITES_FLAG;
return [$websiteIds, $timezone, $idSiteIsAll];
} | php | protected function getSiteInfoFromQueryParam($idSites, $_restrictSitesToLogin)
{
$websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
$timezone = false;
if (count($websiteIds) == 1) {
$timezone = Site::getTimezoneFor($websiteIds[0]);
}
$idSiteIsAll = $idSites == Archive::REQUEST_ALL_WEBSITES_FLAG;
return [$websiteIds, $timezone, $idSiteIsAll];
} | [
"protected",
"function",
"getSiteInfoFromQueryParam",
"(",
"$",
"idSites",
",",
"$",
"_restrictSitesToLogin",
")",
"{",
"$",
"websiteIds",
"=",
"Site",
"::",
"getIdSitesFromIdSitesString",
"(",
"$",
"idSites",
",",
"$",
"_restrictSitesToLogin",
")",
";",
"$",
"timezone",
"=",
"false",
";",
"if",
"(",
"count",
"(",
"$",
"websiteIds",
")",
"==",
"1",
")",
"{",
"$",
"timezone",
"=",
"Site",
"::",
"getTimezoneFor",
"(",
"$",
"websiteIds",
"[",
"0",
"]",
")",
";",
"}",
"$",
"idSiteIsAll",
"=",
"$",
"idSites",
"==",
"Archive",
"::",
"REQUEST_ALL_WEBSITES_FLAG",
";",
"return",
"[",
"$",
"websiteIds",
",",
"$",
"timezone",
",",
"$",
"idSiteIsAll",
"]",
";",
"}"
] | Parses the site ID string provided in the 'idSite' query parameter to a list of
website IDs.
@param string $idSites the value of the 'idSite' query parameter
@param bool $_restrictSitesToLogin
@return array an array containing three elements:
- an array of website IDs
- string timezone to use (or false to use no timezone) when creating periods.
- true if the request was for all websites (this forces the archive result to
be indexed by site, even if there is only one site in Piwik) | [
"Parses",
"the",
"site",
"ID",
"string",
"provided",
"in",
"the",
"idSite",
"query",
"parameter",
"to",
"a",
"list",
"of",
"website",
"IDs",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Archive/ArchiveQueryFactory.php#L75-L87 |
209,458 | matomo-org/matomo | core/Archive/ArchiveQueryFactory.php | ArchiveQueryFactory.getPeriodInfoFromQueryParam | protected function getPeriodInfoFromQueryParam($strDate, $strPeriod, $timezone)
{
if (Period::isMultiplePeriod($strDate, $strPeriod)) {
$oPeriod = PeriodFactory::build($strPeriod, $strDate, $timezone);
$allPeriods = $oPeriod->getSubperiods();
} else {
$oPeriod = PeriodFactory::makePeriodFromQueryParams($timezone, $strPeriod, $strDate);
$allPeriods = array($oPeriod);
}
$isMultipleDate = Period::isMultiplePeriod($strDate, $strPeriod);
return [$allPeriods, $isMultipleDate];
} | php | protected function getPeriodInfoFromQueryParam($strDate, $strPeriod, $timezone)
{
if (Period::isMultiplePeriod($strDate, $strPeriod)) {
$oPeriod = PeriodFactory::build($strPeriod, $strDate, $timezone);
$allPeriods = $oPeriod->getSubperiods();
} else {
$oPeriod = PeriodFactory::makePeriodFromQueryParams($timezone, $strPeriod, $strDate);
$allPeriods = array($oPeriod);
}
$isMultipleDate = Period::isMultiplePeriod($strDate, $strPeriod);
return [$allPeriods, $isMultipleDate];
} | [
"protected",
"function",
"getPeriodInfoFromQueryParam",
"(",
"$",
"strDate",
",",
"$",
"strPeriod",
",",
"$",
"timezone",
")",
"{",
"if",
"(",
"Period",
"::",
"isMultiplePeriod",
"(",
"$",
"strDate",
",",
"$",
"strPeriod",
")",
")",
"{",
"$",
"oPeriod",
"=",
"PeriodFactory",
"::",
"build",
"(",
"$",
"strPeriod",
",",
"$",
"strDate",
",",
"$",
"timezone",
")",
";",
"$",
"allPeriods",
"=",
"$",
"oPeriod",
"->",
"getSubperiods",
"(",
")",
";",
"}",
"else",
"{",
"$",
"oPeriod",
"=",
"PeriodFactory",
"::",
"makePeriodFromQueryParams",
"(",
"$",
"timezone",
",",
"$",
"strPeriod",
",",
"$",
"strDate",
")",
";",
"$",
"allPeriods",
"=",
"array",
"(",
"$",
"oPeriod",
")",
";",
"}",
"$",
"isMultipleDate",
"=",
"Period",
"::",
"isMultiplePeriod",
"(",
"$",
"strDate",
",",
"$",
"strPeriod",
")",
";",
"return",
"[",
"$",
"allPeriods",
",",
"$",
"isMultipleDate",
"]",
";",
"}"
] | Parses the date & period query parameters into a list of periods.
@param string $strDate the value of the 'date' query parameter
@param string $strPeriod the value of the 'period' query parameter
@param string $timezone the timezone to use when constructing periods.
@return array an array containing two elements:
- the list of period objects to query archive data for
- true if the request was for multiple periods (ie, two months, two weeks, etc.), false if otherwise.
(this forces the archive result to be indexed by period, even if the list of periods
has only one period). | [
"Parses",
"the",
"date",
"&",
"period",
"query",
"parameters",
"into",
"a",
"list",
"of",
"periods",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Archive/ArchiveQueryFactory.php#L101-L114 |
209,459 | matomo-org/matomo | core/Db/Adapter/Pdo/Mssql.php | Mssql.checkClientVersion | public function checkClientVersion()
{
$serverVersion = $this->getServerVersion();
$clientVersion = $this->getClientVersion();
if (version_compare($serverVersion, '10') >= 0
&& version_compare($clientVersion, '10') < 0
) {
throw new Exception(Piwik::translate('General_ExceptionIncompatibleClientServerVersions', array('MSSQL', $clientVersion, $serverVersion)));
}
} | php | public function checkClientVersion()
{
$serverVersion = $this->getServerVersion();
$clientVersion = $this->getClientVersion();
if (version_compare($serverVersion, '10') >= 0
&& version_compare($clientVersion, '10') < 0
) {
throw new Exception(Piwik::translate('General_ExceptionIncompatibleClientServerVersions', array('MSSQL', $clientVersion, $serverVersion)));
}
} | [
"public",
"function",
"checkClientVersion",
"(",
")",
"{",
"$",
"serverVersion",
"=",
"$",
"this",
"->",
"getServerVersion",
"(",
")",
";",
"$",
"clientVersion",
"=",
"$",
"this",
"->",
"getClientVersion",
"(",
")",
";",
"if",
"(",
"version_compare",
"(",
"$",
"serverVersion",
",",
"'10'",
")",
">=",
"0",
"&&",
"version_compare",
"(",
"$",
"clientVersion",
",",
"'10'",
")",
"<",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"Piwik",
"::",
"translate",
"(",
"'General_ExceptionIncompatibleClientServerVersions'",
",",
"array",
"(",
"'MSSQL'",
",",
"$",
"clientVersion",
",",
"$",
"serverVersion",
")",
")",
")",
";",
"}",
"}"
] | Check client version compatibility against database server
@throws Exception | [
"Check",
"client",
"version",
"compatibility",
"against",
"database",
"server"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Adapter/Pdo/Mssql.php#L169-L179 |
209,460 | matomo-org/matomo | core/Plugin.php | Plugin.findComponent | public function findComponent($componentName, $expectedSubclass)
{
$this->createCacheIfNeeded();
$cacheId = 'Plugin' . $this->pluginName . $componentName . $expectedSubclass;
$pluginsDir = Manager::getPluginDirectory($this->pluginName);
$componentFile = sprintf('%s/%s.php', $pluginsDir, $componentName);
if ($this->cache->contains($cacheId)) {
$classname = $this->cache->fetch($cacheId);
if (empty($classname)) {
return null; // might by "false" in case has no menu, widget, ...
}
if (file_exists($componentFile)) {
include_once $componentFile;
}
} else {
$this->cache->save($cacheId, false); // prevent from trying to load over and over again for instance if there is no Menu for a plugin
if (!file_exists($componentFile)) {
return null;
}
require_once $componentFile;
$classname = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
if (!class_exists($classname)) {
return null;
}
if (!empty($expectedSubclass) && !is_subclass_of($classname, $expectedSubclass)) {
Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
$componentName, $this->pluginName, $classname, $expectedSubclass));
return null;
}
$this->cache->save($cacheId, $classname);
}
return $classname;
} | php | public function findComponent($componentName, $expectedSubclass)
{
$this->createCacheIfNeeded();
$cacheId = 'Plugin' . $this->pluginName . $componentName . $expectedSubclass;
$pluginsDir = Manager::getPluginDirectory($this->pluginName);
$componentFile = sprintf('%s/%s.php', $pluginsDir, $componentName);
if ($this->cache->contains($cacheId)) {
$classname = $this->cache->fetch($cacheId);
if (empty($classname)) {
return null; // might by "false" in case has no menu, widget, ...
}
if (file_exists($componentFile)) {
include_once $componentFile;
}
} else {
$this->cache->save($cacheId, false); // prevent from trying to load over and over again for instance if there is no Menu for a plugin
if (!file_exists($componentFile)) {
return null;
}
require_once $componentFile;
$classname = sprintf('Piwik\\Plugins\\%s\\%s', $this->pluginName, $componentName);
if (!class_exists($classname)) {
return null;
}
if (!empty($expectedSubclass) && !is_subclass_of($classname, $expectedSubclass)) {
Log::warning(sprintf('Cannot use component %s for plugin %s, class %s does not extend %s',
$componentName, $this->pluginName, $classname, $expectedSubclass));
return null;
}
$this->cache->save($cacheId, $classname);
}
return $classname;
} | [
"public",
"function",
"findComponent",
"(",
"$",
"componentName",
",",
"$",
"expectedSubclass",
")",
"{",
"$",
"this",
"->",
"createCacheIfNeeded",
"(",
")",
";",
"$",
"cacheId",
"=",
"'Plugin'",
".",
"$",
"this",
"->",
"pluginName",
".",
"$",
"componentName",
".",
"$",
"expectedSubclass",
";",
"$",
"pluginsDir",
"=",
"Manager",
"::",
"getPluginDirectory",
"(",
"$",
"this",
"->",
"pluginName",
")",
";",
"$",
"componentFile",
"=",
"sprintf",
"(",
"'%s/%s.php'",
",",
"$",
"pluginsDir",
",",
"$",
"componentName",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cache",
"->",
"contains",
"(",
"$",
"cacheId",
")",
")",
"{",
"$",
"classname",
"=",
"$",
"this",
"->",
"cache",
"->",
"fetch",
"(",
"$",
"cacheId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"null",
";",
"// might by \"false\" in case has no menu, widget, ...",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"componentFile",
")",
")",
"{",
"include_once",
"$",
"componentFile",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"cacheId",
",",
"false",
")",
";",
"// prevent from trying to load over and over again for instance if there is no Menu for a plugin",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"componentFile",
")",
")",
"{",
"return",
"null",
";",
"}",
"require_once",
"$",
"componentFile",
";",
"$",
"classname",
"=",
"sprintf",
"(",
"'Piwik\\\\Plugins\\\\%s\\\\%s'",
",",
"$",
"this",
"->",
"pluginName",
",",
"$",
"componentName",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"expectedSubclass",
")",
"&&",
"!",
"is_subclass_of",
"(",
"$",
"classname",
",",
"$",
"expectedSubclass",
")",
")",
"{",
"Log",
"::",
"warning",
"(",
"sprintf",
"(",
"'Cannot use component %s for plugin %s, class %s does not extend %s'",
",",
"$",
"componentName",
",",
"$",
"this",
"->",
"pluginName",
",",
"$",
"classname",
",",
"$",
"expectedSubclass",
")",
")",
";",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"cacheId",
",",
"$",
"classname",
")",
";",
"}",
"return",
"$",
"classname",
";",
"}"
] | Tries to find a component such as a Menu or Tasks within this plugin.
@param string $componentName The name of the component you want to look for. In case you request a
component named 'Menu' it'll look for a file named 'Menu.php' within the
root of the plugin folder that implements a class named
Piwik\Plugin\$PluginName\Menu . If such a file exists but does not implement
this class it'll silently ignored.
@param string $expectedSubclass If not empty, a check will be performed whether a found file extends the
given subclass. If the requested file exists but does not extend this class
a warning will be shown to advice a developer to extend this certain class.
@return string|null Null if the requested component does not exist or an instance of the found
component. | [
"Tries",
"to",
"find",
"a",
"component",
"such",
"as",
"a",
"Menu",
"or",
"Tasks",
"within",
"this",
"plugin",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin.php#L352-L397 |
209,461 | matomo-org/matomo | core/Plugin.php | Plugin.getPluginNameFromBacktrace | public static function getPluginNameFromBacktrace($backtrace)
{
foreach ($backtrace as $tracepoint) {
// try and discern the plugin name
if (isset($tracepoint['class'])) {
$className = self::getPluginNameFromNamespace($tracepoint['class']);
if ($className) {
return $className;
}
}
}
return false;
} | php | public static function getPluginNameFromBacktrace($backtrace)
{
foreach ($backtrace as $tracepoint) {
// try and discern the plugin name
if (isset($tracepoint['class'])) {
$className = self::getPluginNameFromNamespace($tracepoint['class']);
if ($className) {
return $className;
}
}
}
return false;
} | [
"public",
"static",
"function",
"getPluginNameFromBacktrace",
"(",
"$",
"backtrace",
")",
"{",
"foreach",
"(",
"$",
"backtrace",
"as",
"$",
"tracepoint",
")",
"{",
"// try and discern the plugin name",
"if",
"(",
"isset",
"(",
"$",
"tracepoint",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"className",
"=",
"self",
"::",
"getPluginNameFromNamespace",
"(",
"$",
"tracepoint",
"[",
"'class'",
"]",
")",
";",
"if",
"(",
"$",
"className",
")",
"{",
"return",
"$",
"className",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Extracts the plugin name from a backtrace array. Returns `false` if we can't find one.
@param array $backtrace The result of {@link debug_backtrace()} or
[Exception::getTrace()](http://www.php.net/manual/en/exception.gettrace.php).
@return string|false | [
"Extracts",
"the",
"plugin",
"name",
"from",
"a",
"backtrace",
"array",
".",
"Returns",
"false",
"if",
"we",
"can",
"t",
"find",
"one",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Plugin.php#L487-L499 |
209,462 | matomo-org/matomo | core/ArchiveProcessor.php | ArchiveProcessor.aggregateDataTableRecords | public function aggregateDataTableRecords($recordNames,
$maximumRowsInDataTableLevelZero = null,
$maximumRowsInSubDataTable = null,
$columnToSortByBeforeTruncation = null,
&$columnsAggregationOperation = null,
$columnsToRenameAfterAggregation = null,
$countRowsRecursive = true)
{
if (!is_array($recordNames)) {
$recordNames = array($recordNames);
}
$nameToCount = array();
foreach ($recordNames as $recordName) {
$latestUsedTableId = Manager::getInstance()->getMostRecentTableId();
$table = $this->aggregateDataTableRecord($recordName, $columnsAggregationOperation, $columnsToRenameAfterAggregation);
$nameToCount[$recordName]['level0'] = $table->getRowsCount();
if ($countRowsRecursive === true || (is_array($countRowsRecursive) && in_array($recordName, $countRowsRecursive))) {
$nameToCount[$recordName]['recursive'] = $table->getRowsCountRecursive();
}
$blob = $table->getSerialized($maximumRowsInDataTableLevelZero, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation);
Common::destroy($table);
$this->insertBlobRecord($recordName, $blob);
unset($blob);
DataTable\Manager::getInstance()->deleteAll($latestUsedTableId);
}
return $nameToCount;
} | php | public function aggregateDataTableRecords($recordNames,
$maximumRowsInDataTableLevelZero = null,
$maximumRowsInSubDataTable = null,
$columnToSortByBeforeTruncation = null,
&$columnsAggregationOperation = null,
$columnsToRenameAfterAggregation = null,
$countRowsRecursive = true)
{
if (!is_array($recordNames)) {
$recordNames = array($recordNames);
}
$nameToCount = array();
foreach ($recordNames as $recordName) {
$latestUsedTableId = Manager::getInstance()->getMostRecentTableId();
$table = $this->aggregateDataTableRecord($recordName, $columnsAggregationOperation, $columnsToRenameAfterAggregation);
$nameToCount[$recordName]['level0'] = $table->getRowsCount();
if ($countRowsRecursive === true || (is_array($countRowsRecursive) && in_array($recordName, $countRowsRecursive))) {
$nameToCount[$recordName]['recursive'] = $table->getRowsCountRecursive();
}
$blob = $table->getSerialized($maximumRowsInDataTableLevelZero, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation);
Common::destroy($table);
$this->insertBlobRecord($recordName, $blob);
unset($blob);
DataTable\Manager::getInstance()->deleteAll($latestUsedTableId);
}
return $nameToCount;
} | [
"public",
"function",
"aggregateDataTableRecords",
"(",
"$",
"recordNames",
",",
"$",
"maximumRowsInDataTableLevelZero",
"=",
"null",
",",
"$",
"maximumRowsInSubDataTable",
"=",
"null",
",",
"$",
"columnToSortByBeforeTruncation",
"=",
"null",
",",
"&",
"$",
"columnsAggregationOperation",
"=",
"null",
",",
"$",
"columnsToRenameAfterAggregation",
"=",
"null",
",",
"$",
"countRowsRecursive",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"recordNames",
")",
")",
"{",
"$",
"recordNames",
"=",
"array",
"(",
"$",
"recordNames",
")",
";",
"}",
"$",
"nameToCount",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"recordNames",
"as",
"$",
"recordName",
")",
"{",
"$",
"latestUsedTableId",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"getMostRecentTableId",
"(",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"aggregateDataTableRecord",
"(",
"$",
"recordName",
",",
"$",
"columnsAggregationOperation",
",",
"$",
"columnsToRenameAfterAggregation",
")",
";",
"$",
"nameToCount",
"[",
"$",
"recordName",
"]",
"[",
"'level0'",
"]",
"=",
"$",
"table",
"->",
"getRowsCount",
"(",
")",
";",
"if",
"(",
"$",
"countRowsRecursive",
"===",
"true",
"||",
"(",
"is_array",
"(",
"$",
"countRowsRecursive",
")",
"&&",
"in_array",
"(",
"$",
"recordName",
",",
"$",
"countRowsRecursive",
")",
")",
")",
"{",
"$",
"nameToCount",
"[",
"$",
"recordName",
"]",
"[",
"'recursive'",
"]",
"=",
"$",
"table",
"->",
"getRowsCountRecursive",
"(",
")",
";",
"}",
"$",
"blob",
"=",
"$",
"table",
"->",
"getSerialized",
"(",
"$",
"maximumRowsInDataTableLevelZero",
",",
"$",
"maximumRowsInSubDataTable",
",",
"$",
"columnToSortByBeforeTruncation",
")",
";",
"Common",
"::",
"destroy",
"(",
"$",
"table",
")",
";",
"$",
"this",
"->",
"insertBlobRecord",
"(",
"$",
"recordName",
",",
"$",
"blob",
")",
";",
"unset",
"(",
"$",
"blob",
")",
";",
"DataTable",
"\\",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"deleteAll",
"(",
"$",
"latestUsedTableId",
")",
";",
"}",
"return",
"$",
"nameToCount",
";",
"}"
] | Sums records for every subperiod of the current period and inserts the result as the record
for this period.
DataTables are summed recursively so subtables will be summed as well.
@param string|array $recordNames Name(s) of the report we are aggregating, eg, `'Referrers_type'`.
@param int $maximumRowsInDataTableLevelZero Maximum number of rows allowed in the top level DataTable.
@param int $maximumRowsInSubDataTable Maximum number of rows allowed in each subtable.
@param string $columnToSortByBeforeTruncation The name of the column to sort by before truncating a DataTable.
@param array $columnsAggregationOperation Operations for aggregating columns, see {@link Row::sumRow()}.
@param array $columnsToRenameAfterAggregation Columns mapped to new names for columns that must change names
when summed because they cannot be summed, eg,
`array('nb_uniq_visitors' => 'sum_daily_nb_uniq_visitors')`.
@param bool|array $countRowsRecursive if set to true, will calculate the recursive rows count for all record names
which makes it slower. If you only need it for some records pass an array of
recordNames that defines for which ones you need a recursive row count.
@return array Returns the row counts of each aggregated report before truncation, eg,
array(
'report1' => array('level0' => $report1->getRowsCount,
'recursive' => $report1->getRowsCountRecursive()),
'report2' => array('level0' => $report2->getRowsCount,
'recursive' => $report2->getRowsCountRecursive()),
...
)
@api | [
"Sums",
"records",
"for",
"every",
"subperiod",
"of",
"the",
"current",
"period",
"and",
"inserts",
"the",
"result",
"as",
"the",
"record",
"for",
"this",
"period",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ArchiveProcessor.php#L203-L235 |
209,463 | matomo-org/matomo | core/ArchiveProcessor.php | ArchiveProcessor.aggregateNumericMetrics | public function aggregateNumericMetrics($columns, $operationToApply = false)
{
$metrics = $this->getAggregatedNumericMetrics($columns, $operationToApply);
foreach ($metrics as $column => $value) {
$value = Common::forceDotAsSeparatorForDecimalPoint($value);
$this->archiveWriter->insertRecord($column, $value);
}
// if asked for only one field to sum
if (count($metrics) == 1) {
return reset($metrics);
}
// returns the array of records once summed
return $metrics;
} | php | public function aggregateNumericMetrics($columns, $operationToApply = false)
{
$metrics = $this->getAggregatedNumericMetrics($columns, $operationToApply);
foreach ($metrics as $column => $value) {
$value = Common::forceDotAsSeparatorForDecimalPoint($value);
$this->archiveWriter->insertRecord($column, $value);
}
// if asked for only one field to sum
if (count($metrics) == 1) {
return reset($metrics);
}
// returns the array of records once summed
return $metrics;
} | [
"public",
"function",
"aggregateNumericMetrics",
"(",
"$",
"columns",
",",
"$",
"operationToApply",
"=",
"false",
")",
"{",
"$",
"metrics",
"=",
"$",
"this",
"->",
"getAggregatedNumericMetrics",
"(",
"$",
"columns",
",",
"$",
"operationToApply",
")",
";",
"foreach",
"(",
"$",
"metrics",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"Common",
"::",
"forceDotAsSeparatorForDecimalPoint",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"archiveWriter",
"->",
"insertRecord",
"(",
"$",
"column",
",",
"$",
"value",
")",
";",
"}",
"// if asked for only one field to sum",
"if",
"(",
"count",
"(",
"$",
"metrics",
")",
"==",
"1",
")",
"{",
"return",
"reset",
"(",
"$",
"metrics",
")",
";",
"}",
"// returns the array of records once summed",
"return",
"$",
"metrics",
";",
"}"
] | Aggregates one or more metrics for every subperiod of the current period and inserts the results
as metrics for the current period.
@param array|string $columns Array of metric names to aggregate.
@param bool|string $operationToApply The operation to apply to the metric. Either `'sum'`, `'max'` or `'min'`.
@return array|int Returns the array of aggregate values. If only one metric was aggregated,
the aggregate value will be returned as is, not in an array.
For example, if `array('nb_visits', 'nb_hits')` is supplied for `$columns`,
array(
'nb_visits' => 3040,
'nb_hits' => 405
)
could be returned. If `array('nb_visits')` or `'nb_visits'` is used for `$columns`,
then `3040` would be returned.
@api | [
"Aggregates",
"one",
"or",
"more",
"metrics",
"for",
"every",
"subperiod",
"of",
"the",
"current",
"period",
"and",
"inserts",
"the",
"results",
"as",
"metrics",
"for",
"the",
"current",
"period",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ArchiveProcessor.php#L256-L271 |
209,464 | matomo-org/matomo | core/ArchiveProcessor.php | ArchiveProcessor.insertNumericRecords | public function insertNumericRecords($numericRecords)
{
foreach ($numericRecords as $name => $value) {
$this->insertNumericRecord($name, $value);
}
} | php | public function insertNumericRecords($numericRecords)
{
foreach ($numericRecords as $name => $value) {
$this->insertNumericRecord($name, $value);
}
} | [
"public",
"function",
"insertNumericRecords",
"(",
"$",
"numericRecords",
")",
"{",
"foreach",
"(",
"$",
"numericRecords",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"insertNumericRecord",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Caches multiple numeric records in the archive for this processor's site, period
and segment.
@param array $numericRecords A name-value mapping of numeric values that should be
archived, eg,
array('Referrers_distinctKeywords' => 23, 'Referrers_distinctCampaigns' => 234)
@api | [
"Caches",
"multiple",
"numeric",
"records",
"in",
"the",
"archive",
"for",
"this",
"processor",
"s",
"site",
"period",
"and",
"segment",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ArchiveProcessor.php#L296-L301 |
209,465 | matomo-org/matomo | core/ArchiveProcessor.php | ArchiveProcessor.insertNumericRecord | public function insertNumericRecord($name, $value)
{
$value = round($value, 2);
$value = Common::forceDotAsSeparatorForDecimalPoint($value);
$this->archiveWriter->insertRecord($name, $value);
} | php | public function insertNumericRecord($name, $value)
{
$value = round($value, 2);
$value = Common::forceDotAsSeparatorForDecimalPoint($value);
$this->archiveWriter->insertRecord($name, $value);
} | [
"public",
"function",
"insertNumericRecord",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"round",
"(",
"$",
"value",
",",
"2",
")",
";",
"$",
"value",
"=",
"Common",
"::",
"forceDotAsSeparatorForDecimalPoint",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"archiveWriter",
"->",
"insertRecord",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}"
] | Caches a single numeric record in the archive for this processor's site, period and
segment.
Numeric values are not inserted if they equal `0`.
@param string $name The name of the numeric value, eg, `'Referrers_distinctKeywords'`.
@param float $value The numeric value.
@api | [
"Caches",
"a",
"single",
"numeric",
"record",
"in",
"the",
"archive",
"for",
"this",
"processor",
"s",
"site",
"period",
"and",
"segment",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ArchiveProcessor.php#L313-L319 |
209,466 | matomo-org/matomo | core/ArchiveProcessor.php | ArchiveProcessor.computeNbUniques | protected function computeNbUniques($metrics)
{
$logAggregator = $this->getLogAggregator();
$query = $logAggregator->queryVisitsByDimension(array(), false, array(), $metrics);
$data = $query->fetch();
return $data;
} | php | protected function computeNbUniques($metrics)
{
$logAggregator = $this->getLogAggregator();
$query = $logAggregator->queryVisitsByDimension(array(), false, array(), $metrics);
$data = $query->fetch();
return $data;
} | [
"protected",
"function",
"computeNbUniques",
"(",
"$",
"metrics",
")",
"{",
"$",
"logAggregator",
"=",
"$",
"this",
"->",
"getLogAggregator",
"(",
")",
";",
"$",
"query",
"=",
"$",
"logAggregator",
"->",
"queryVisitsByDimension",
"(",
"array",
"(",
")",
",",
"false",
",",
"array",
"(",
")",
",",
"$",
"metrics",
")",
";",
"$",
"data",
"=",
"$",
"query",
"->",
"fetch",
"(",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Processes number of unique visitors for the given period
This is the only Period metric (ie. week/month/year/range) that we process from the logs directly,
since unique visitors cannot be summed like other metrics.
@param array Metrics Ids for which to aggregates count of values
@return array of metrics, where the key is metricid and the value is the metric value | [
"Processes",
"number",
"of",
"unique",
"visitors",
"for",
"the",
"given",
"period"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ArchiveProcessor.php#L487-L493 |
209,467 | matomo-org/matomo | core/ArchiveProcessor.php | ArchiveProcessor.getAggregatedDataTableMap | protected function getAggregatedDataTableMap($data, $columnsAggregationOperation)
{
$table = new DataTable();
if (!empty($columnsAggregationOperation)) {
$table->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsAggregationOperation);
}
if ($data instanceof DataTable\Map) {
// as $date => $tableToSum
$this->aggregatedDataTableMapsAsOne($data, $table);
} else {
$table->addDataTable($data);
}
return $table;
} | php | protected function getAggregatedDataTableMap($data, $columnsAggregationOperation)
{
$table = new DataTable();
if (!empty($columnsAggregationOperation)) {
$table->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsAggregationOperation);
}
if ($data instanceof DataTable\Map) {
// as $date => $tableToSum
$this->aggregatedDataTableMapsAsOne($data, $table);
} else {
$table->addDataTable($data);
}
return $table;
} | [
"protected",
"function",
"getAggregatedDataTableMap",
"(",
"$",
"data",
",",
"$",
"columnsAggregationOperation",
")",
"{",
"$",
"table",
"=",
"new",
"DataTable",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"columnsAggregationOperation",
")",
")",
"{",
"$",
"table",
"->",
"setMetadata",
"(",
"DataTable",
"::",
"COLUMN_AGGREGATION_OPS_METADATA_NAME",
",",
"$",
"columnsAggregationOperation",
")",
";",
"}",
"if",
"(",
"$",
"data",
"instanceof",
"DataTable",
"\\",
"Map",
")",
"{",
"// as $date => $tableToSum",
"$",
"this",
"->",
"aggregatedDataTableMapsAsOne",
"(",
"$",
"data",
",",
"$",
"table",
")",
";",
"}",
"else",
"{",
"$",
"table",
"->",
"addDataTable",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"table",
";",
"}"
] | If the DataTable is a Map, sums all DataTable in the map and return the DataTable.
@param $data DataTable|DataTable\Map
@param $columnsToRenameAfterAggregation array
@return DataTable | [
"If",
"the",
"DataTable",
"is",
"a",
"Map",
"sums",
"all",
"DataTable",
"in",
"the",
"map",
"and",
"return",
"the",
"DataTable",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ArchiveProcessor.php#L503-L519 |
209,468 | matomo-org/matomo | core/ArchiveProcessor.php | ArchiveProcessor.processDependentArchive | public function processDependentArchive($plugin, $segment)
{
$params = $this->getParams();
if (!$params->isRootArchiveRequest()) { // prevent all recursion
return;
}
$idSites = [$params->getSite()->getId()];
$newSegment = Segment::combine($params->getSegment()->getString(), SegmentExpression::AND_DELIMITER, $segment);
if ($newSegment === $segment && $params->getRequestedPlugin() === $plugin) { // being processed now
return;
}
$newSegment = new Segment($newSegment, $idSites);
if (ArchiveProcessor\Rules::isSegmentPreProcessed($idSites, $newSegment)) {
// will be processed anyway
return;
}
$parameters = new ArchiveProcessor\Parameters($params->getSite(), $params->getPeriod(), $newSegment);
$parameters->onlyArchiveRequestedPlugin();
$parameters->setIsRootArchiveRequest(false);
$archiveLoader = new ArchiveProcessor\Loader($parameters);
$archiveLoader->prepareArchive($plugin);
} | php | public function processDependentArchive($plugin, $segment)
{
$params = $this->getParams();
if (!$params->isRootArchiveRequest()) { // prevent all recursion
return;
}
$idSites = [$params->getSite()->getId()];
$newSegment = Segment::combine($params->getSegment()->getString(), SegmentExpression::AND_DELIMITER, $segment);
if ($newSegment === $segment && $params->getRequestedPlugin() === $plugin) { // being processed now
return;
}
$newSegment = new Segment($newSegment, $idSites);
if (ArchiveProcessor\Rules::isSegmentPreProcessed($idSites, $newSegment)) {
// will be processed anyway
return;
}
$parameters = new ArchiveProcessor\Parameters($params->getSite(), $params->getPeriod(), $newSegment);
$parameters->onlyArchiveRequestedPlugin();
$parameters->setIsRootArchiveRequest(false);
$archiveLoader = new ArchiveProcessor\Loader($parameters);
$archiveLoader->prepareArchive($plugin);
} | [
"public",
"function",
"processDependentArchive",
"(",
"$",
"plugin",
",",
"$",
"segment",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParams",
"(",
")",
";",
"if",
"(",
"!",
"$",
"params",
"->",
"isRootArchiveRequest",
"(",
")",
")",
"{",
"// prevent all recursion",
"return",
";",
"}",
"$",
"idSites",
"=",
"[",
"$",
"params",
"->",
"getSite",
"(",
")",
"->",
"getId",
"(",
")",
"]",
";",
"$",
"newSegment",
"=",
"Segment",
"::",
"combine",
"(",
"$",
"params",
"->",
"getSegment",
"(",
")",
"->",
"getString",
"(",
")",
",",
"SegmentExpression",
"::",
"AND_DELIMITER",
",",
"$",
"segment",
")",
";",
"if",
"(",
"$",
"newSegment",
"===",
"$",
"segment",
"&&",
"$",
"params",
"->",
"getRequestedPlugin",
"(",
")",
"===",
"$",
"plugin",
")",
"{",
"// being processed now",
"return",
";",
"}",
"$",
"newSegment",
"=",
"new",
"Segment",
"(",
"$",
"newSegment",
",",
"$",
"idSites",
")",
";",
"if",
"(",
"ArchiveProcessor",
"\\",
"Rules",
"::",
"isSegmentPreProcessed",
"(",
"$",
"idSites",
",",
"$",
"newSegment",
")",
")",
"{",
"// will be processed anyway",
"return",
";",
"}",
"$",
"parameters",
"=",
"new",
"ArchiveProcessor",
"\\",
"Parameters",
"(",
"$",
"params",
"->",
"getSite",
"(",
")",
",",
"$",
"params",
"->",
"getPeriod",
"(",
")",
",",
"$",
"newSegment",
")",
";",
"$",
"parameters",
"->",
"onlyArchiveRequestedPlugin",
"(",
")",
";",
"$",
"parameters",
"->",
"setIsRootArchiveRequest",
"(",
"false",
")",
";",
"$",
"archiveLoader",
"=",
"new",
"ArchiveProcessor",
"\\",
"Loader",
"(",
"$",
"parameters",
")",
";",
"$",
"archiveLoader",
"->",
"prepareArchive",
"(",
"$",
"plugin",
")",
";",
"}"
] | Initiate archiving for a plugin during an ongoing archiving. The plugin can be another
plugin or the same plugin.
This method should be called during archiving when one plugin uses the report of another
plugin with a segment. It will ensure reports for that segment & plugin will be archived
without initiating archiving for every plugin with that segment (which would be a performance
killer).
@param string $plugin
@param string $segment | [
"Initiate",
"archiving",
"for",
"a",
"plugin",
"during",
"an",
"ongoing",
"archiving",
".",
"The",
"plugin",
"can",
"be",
"another",
"plugin",
"or",
"the",
"same",
"plugin",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/ArchiveProcessor.php#L608-L634 |
209,469 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php | Zend_Db_Adapter_Pdo_Ibm_Ids.describeTable | public function describeTable($tableName, $schemaName = null)
{
// this is still a work in progress
$sql= "SELECT DISTINCT t.owner, t.tabname, c.colname, c.colno, c.coltype,
d.default, c.collength, t.tabid
FROM syscolumns c
JOIN systables t ON c.tabid = t.tabid
LEFT JOIN sysdefaults d ON c.tabid = d.tabid AND c.colno = d.colno
WHERE "
. $this->_adapter->quoteInto('UPPER(t.tabname) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->_adapter->quoteInto(' AND UPPER(t.owner) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY c.colno";
$desc = array();
$stmt = $this->_adapter->query($sql);
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
/**
* The ordering of columns is defined by the query so we can map
* to variables to improve readability
*/
$tabschema = 0;
$tabname = 1;
$colname = 2;
$colno = 3;
$typename = 4;
$default = 5;
$length = 6;
$tabid = 7;
$primaryCols = null;
foreach ($result as $key => $row) {
$primary = false;
$primaryPosition = null;
if (!$primaryCols) {
$primaryCols = $this->_getPrimaryInfo($row[$tabid]);
}
if (array_key_exists($row[$colno], $primaryCols)) {
$primary = true;
$primaryPosition = $primaryCols[$row[$colno]];
}
$identity = false;
if ($row[$typename] == 6 + 256 ||
$row[$typename] == 18 + 256) {
$identity = true;
}
$desc[$this->_adapter->foldCase($row[$colname])] = array (
'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
'COLUMN_POSITION' => $row[$colno],
'DATA_TYPE' => $this->_getDataType($row[$typename]),
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) !($row[$typename] - 256 >= 0),
'LENGTH' => $row[$length],
'SCALE' => ($row[$typename] == 5 ? $row[$length]&255 : 0),
'PRECISION' => ($row[$typename] == 5 ? (int)($row[$length]/256) : 0),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
} | php | public function describeTable($tableName, $schemaName = null)
{
// this is still a work in progress
$sql= "SELECT DISTINCT t.owner, t.tabname, c.colname, c.colno, c.coltype,
d.default, c.collength, t.tabid
FROM syscolumns c
JOIN systables t ON c.tabid = t.tabid
LEFT JOIN sysdefaults d ON c.tabid = d.tabid AND c.colno = d.colno
WHERE "
. $this->_adapter->quoteInto('UPPER(t.tabname) = UPPER(?)', $tableName);
if ($schemaName) {
$sql .= $this->_adapter->quoteInto(' AND UPPER(t.owner) = UPPER(?)', $schemaName);
}
$sql .= " ORDER BY c.colno";
$desc = array();
$stmt = $this->_adapter->query($sql);
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
/**
* The ordering of columns is defined by the query so we can map
* to variables to improve readability
*/
$tabschema = 0;
$tabname = 1;
$colname = 2;
$colno = 3;
$typename = 4;
$default = 5;
$length = 6;
$tabid = 7;
$primaryCols = null;
foreach ($result as $key => $row) {
$primary = false;
$primaryPosition = null;
if (!$primaryCols) {
$primaryCols = $this->_getPrimaryInfo($row[$tabid]);
}
if (array_key_exists($row[$colno], $primaryCols)) {
$primary = true;
$primaryPosition = $primaryCols[$row[$colno]];
}
$identity = false;
if ($row[$typename] == 6 + 256 ||
$row[$typename] == 18 + 256) {
$identity = true;
}
$desc[$this->_adapter->foldCase($row[$colname])] = array (
'SCHEMA_NAME' => $this->_adapter->foldCase($row[$tabschema]),
'TABLE_NAME' => $this->_adapter->foldCase($row[$tabname]),
'COLUMN_NAME' => $this->_adapter->foldCase($row[$colname]),
'COLUMN_POSITION' => $row[$colno],
'DATA_TYPE' => $this->_getDataType($row[$typename]),
'DEFAULT' => $row[$default],
'NULLABLE' => (bool) !($row[$typename] - 256 >= 0),
'LENGTH' => $row[$length],
'SCALE' => ($row[$typename] == 5 ? $row[$length]&255 : 0),
'PRECISION' => ($row[$typename] == 5 ? (int)($row[$length]/256) : 0),
'UNSIGNED' => false,
'PRIMARY' => $primary,
'PRIMARY_POSITION' => $primaryPosition,
'IDENTITY' => $identity
);
}
return $desc;
} | [
"public",
"function",
"describeTable",
"(",
"$",
"tableName",
",",
"$",
"schemaName",
"=",
"null",
")",
"{",
"// this is still a work in progress",
"$",
"sql",
"=",
"\"SELECT DISTINCT t.owner, t.tabname, c.colname, c.colno, c.coltype,\n d.default, c.collength, t.tabid\n FROM syscolumns c\n JOIN systables t ON c.tabid = t.tabid\n LEFT JOIN sysdefaults d ON c.tabid = d.tabid AND c.colno = d.colno\n WHERE \"",
".",
"$",
"this",
"->",
"_adapter",
"->",
"quoteInto",
"(",
"'UPPER(t.tabname) = UPPER(?)'",
",",
"$",
"tableName",
")",
";",
"if",
"(",
"$",
"schemaName",
")",
"{",
"$",
"sql",
".=",
"$",
"this",
"->",
"_adapter",
"->",
"quoteInto",
"(",
"' AND UPPER(t.owner) = UPPER(?)'",
",",
"$",
"schemaName",
")",
";",
"}",
"$",
"sql",
".=",
"\" ORDER BY c.colno\"",
";",
"$",
"desc",
"=",
"array",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"fetchAll",
"(",
"Zend_Db",
"::",
"FETCH_NUM",
")",
";",
"/**\n * The ordering of columns is defined by the query so we can map\n * to variables to improve readability\n */",
"$",
"tabschema",
"=",
"0",
";",
"$",
"tabname",
"=",
"1",
";",
"$",
"colname",
"=",
"2",
";",
"$",
"colno",
"=",
"3",
";",
"$",
"typename",
"=",
"4",
";",
"$",
"default",
"=",
"5",
";",
"$",
"length",
"=",
"6",
";",
"$",
"tabid",
"=",
"7",
";",
"$",
"primaryCols",
"=",
"null",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"$",
"primary",
"=",
"false",
";",
"$",
"primaryPosition",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"primaryCols",
")",
"{",
"$",
"primaryCols",
"=",
"$",
"this",
"->",
"_getPrimaryInfo",
"(",
"$",
"row",
"[",
"$",
"tabid",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"row",
"[",
"$",
"colno",
"]",
",",
"$",
"primaryCols",
")",
")",
"{",
"$",
"primary",
"=",
"true",
";",
"$",
"primaryPosition",
"=",
"$",
"primaryCols",
"[",
"$",
"row",
"[",
"$",
"colno",
"]",
"]",
";",
"}",
"$",
"identity",
"=",
"false",
";",
"if",
"(",
"$",
"row",
"[",
"$",
"typename",
"]",
"==",
"6",
"+",
"256",
"||",
"$",
"row",
"[",
"$",
"typename",
"]",
"==",
"18",
"+",
"256",
")",
"{",
"$",
"identity",
"=",
"true",
";",
"}",
"$",
"desc",
"[",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"colname",
"]",
")",
"]",
"=",
"array",
"(",
"'SCHEMA_NAME'",
"=>",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"tabschema",
"]",
")",
",",
"'TABLE_NAME'",
"=>",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"tabname",
"]",
")",
",",
"'COLUMN_NAME'",
"=>",
"$",
"this",
"->",
"_adapter",
"->",
"foldCase",
"(",
"$",
"row",
"[",
"$",
"colname",
"]",
")",
",",
"'COLUMN_POSITION'",
"=>",
"$",
"row",
"[",
"$",
"colno",
"]",
",",
"'DATA_TYPE'",
"=>",
"$",
"this",
"->",
"_getDataType",
"(",
"$",
"row",
"[",
"$",
"typename",
"]",
")",
",",
"'DEFAULT'",
"=>",
"$",
"row",
"[",
"$",
"default",
"]",
",",
"'NULLABLE'",
"=>",
"(",
"bool",
")",
"!",
"(",
"$",
"row",
"[",
"$",
"typename",
"]",
"-",
"256",
">=",
"0",
")",
",",
"'LENGTH'",
"=>",
"$",
"row",
"[",
"$",
"length",
"]",
",",
"'SCALE'",
"=>",
"(",
"$",
"row",
"[",
"$",
"typename",
"]",
"==",
"5",
"?",
"$",
"row",
"[",
"$",
"length",
"]",
"&",
"255",
":",
"0",
")",
",",
"'PRECISION'",
"=>",
"(",
"$",
"row",
"[",
"$",
"typename",
"]",
"==",
"5",
"?",
"(",
"int",
")",
"(",
"$",
"row",
"[",
"$",
"length",
"]",
"/",
"256",
")",
":",
"0",
")",
",",
"'UNSIGNED'",
"=>",
"false",
",",
"'PRIMARY'",
"=>",
"$",
"primary",
",",
"'PRIMARY_POSITION'",
"=>",
"$",
"primaryPosition",
",",
"'IDENTITY'",
"=>",
"$",
"identity",
")",
";",
"}",
"return",
"$",
"desc",
";",
"}"
] | IDS catalog lookup for describe table
@param string $tableName
@param string $schemaName OPTIONAL
@return array | [
"IDS",
"catalog",
"lookup",
"for",
"describe",
"table"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php#L78-L152 |
209,470 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php | Zend_Db_Adapter_Pdo_Ibm_Ids._getPrimaryInfo | protected function _getPrimaryInfo($tabid)
{
$sql = "SELECT i.part1, i.part2, i.part3, i.part4, i.part5, i.part6,
i.part7, i.part8, i.part9, i.part10, i.part11, i.part12,
i.part13, i.part14, i.part15, i.part16
FROM sysindexes i
JOIN sysconstraints c ON c.idxname = i.idxname
WHERE i.tabid = " . $tabid . " AND c.constrtype = 'P'";
$stmt = $this->_adapter->query($sql);
$results = $stmt->fetchAll();
$cols = array();
// this should return only 1 row
// unless there is no primary key,
// in which case, the empty array is returned
if ($results) {
$row = $results[0];
} else {
return $cols;
}
$position = 0;
foreach ($row as $key => $colno) {
$position++;
if ($colno == 0) {
return $cols;
} else {
$cols[$colno] = $position;
}
}
} | php | protected function _getPrimaryInfo($tabid)
{
$sql = "SELECT i.part1, i.part2, i.part3, i.part4, i.part5, i.part6,
i.part7, i.part8, i.part9, i.part10, i.part11, i.part12,
i.part13, i.part14, i.part15, i.part16
FROM sysindexes i
JOIN sysconstraints c ON c.idxname = i.idxname
WHERE i.tabid = " . $tabid . " AND c.constrtype = 'P'";
$stmt = $this->_adapter->query($sql);
$results = $stmt->fetchAll();
$cols = array();
// this should return only 1 row
// unless there is no primary key,
// in which case, the empty array is returned
if ($results) {
$row = $results[0];
} else {
return $cols;
}
$position = 0;
foreach ($row as $key => $colno) {
$position++;
if ($colno == 0) {
return $cols;
} else {
$cols[$colno] = $position;
}
}
} | [
"protected",
"function",
"_getPrimaryInfo",
"(",
"$",
"tabid",
")",
"{",
"$",
"sql",
"=",
"\"SELECT i.part1, i.part2, i.part3, i.part4, i.part5, i.part6,\n i.part7, i.part8, i.part9, i.part10, i.part11, i.part12,\n i.part13, i.part14, i.part15, i.part16\n FROM sysindexes i\n JOIN sysconstraints c ON c.idxname = i.idxname\n WHERE i.tabid = \"",
".",
"$",
"tabid",
".",
"\" AND c.constrtype = 'P'\"",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"results",
"=",
"$",
"stmt",
"->",
"fetchAll",
"(",
")",
";",
"$",
"cols",
"=",
"array",
"(",
")",
";",
"// this should return only 1 row",
"// unless there is no primary key,",
"// in which case, the empty array is returned",
"if",
"(",
"$",
"results",
")",
"{",
"$",
"row",
"=",
"$",
"results",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"cols",
";",
"}",
"$",
"position",
"=",
"0",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"key",
"=>",
"$",
"colno",
")",
"{",
"$",
"position",
"++",
";",
"if",
"(",
"$",
"colno",
"==",
"0",
")",
"{",
"return",
"$",
"cols",
";",
"}",
"else",
"{",
"$",
"cols",
"[",
"$",
"colno",
"]",
"=",
"$",
"position",
";",
"}",
"}",
"}"
] | Helper method to retrieve primary key column
and column location
@param int $tabid
@return array | [
"Helper",
"method",
"to",
"retrieve",
"primary",
"key",
"column",
"and",
"column",
"location"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php#L205-L237 |
209,471 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php | Zend_Db_Adapter_Pdo_Ibm_Ids.limit | public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count < 0) {
/** @see Zend_Db_Adapter_Exception */
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
} else if ($count == 0) {
$limit_sql = str_ireplace("SELECT", "SELECT * FROM (SELECT", $sql);
$limit_sql .= ") WHERE 0 = 1";
} else {
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
if ($offset == 0) {
$limit_sql = str_ireplace("SELECT", "SELECT FIRST $count", $sql);
} else {
$limit_sql = str_ireplace("SELECT", "SELECT SKIP $offset LIMIT $count", $sql);
}
}
return $limit_sql;
} | php | public function limit($sql, $count, $offset = 0)
{
$count = intval($count);
if ($count < 0) {
/** @see Zend_Db_Adapter_Exception */
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
} else if ($count == 0) {
$limit_sql = str_ireplace("SELECT", "SELECT * FROM (SELECT", $sql);
$limit_sql .= ") WHERE 0 = 1";
} else {
$offset = intval($offset);
if ($offset < 0) {
/** @see Zend_Db_Adapter_Exception */
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
}
if ($offset == 0) {
$limit_sql = str_ireplace("SELECT", "SELECT FIRST $count", $sql);
} else {
$limit_sql = str_ireplace("SELECT", "SELECT SKIP $offset LIMIT $count", $sql);
}
}
return $limit_sql;
} | [
"public",
"function",
"limit",
"(",
"$",
"sql",
",",
"$",
"count",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"count",
"=",
"intval",
"(",
"$",
"count",
")",
";",
"if",
"(",
"$",
"count",
"<",
"0",
")",
"{",
"/** @see Zend_Db_Adapter_Exception */",
"// require_once 'Zend/Db/Adapter/Exception.php';",
"throw",
"new",
"Zend_Db_Adapter_Exception",
"(",
"\"LIMIT argument count=$count is not valid\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"count",
"==",
"0",
")",
"{",
"$",
"limit_sql",
"=",
"str_ireplace",
"(",
"\"SELECT\"",
",",
"\"SELECT * FROM (SELECT\"",
",",
"$",
"sql",
")",
";",
"$",
"limit_sql",
".=",
"\") WHERE 0 = 1\"",
";",
"}",
"else",
"{",
"$",
"offset",
"=",
"intval",
"(",
"$",
"offset",
")",
";",
"if",
"(",
"$",
"offset",
"<",
"0",
")",
"{",
"/** @see Zend_Db_Adapter_Exception */",
"// require_once 'Zend/Db/Adapter/Exception.php';",
"throw",
"new",
"Zend_Db_Adapter_Exception",
"(",
"\"LIMIT argument offset=$offset is not valid\"",
")",
";",
"}",
"if",
"(",
"$",
"offset",
"==",
"0",
")",
"{",
"$",
"limit_sql",
"=",
"str_ireplace",
"(",
"\"SELECT\"",
",",
"\"SELECT FIRST $count\"",
",",
"$",
"sql",
")",
";",
"}",
"else",
"{",
"$",
"limit_sql",
"=",
"str_ireplace",
"(",
"\"SELECT\"",
",",
"\"SELECT SKIP $offset LIMIT $count\"",
",",
"$",
"sql",
")",
";",
"}",
"}",
"return",
"$",
"limit_sql",
";",
"}"
] | Adds an IDS-specific LIMIT clause to the SELECT statement.
@param string $sql
@param integer $count
@param integer $offset OPTIONAL
@throws Zend_Db_Adapter_Exception
@return string | [
"Adds",
"an",
"IDS",
"-",
"specific",
"LIMIT",
"clause",
"to",
"the",
"SELECT",
"statement",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php#L248-L272 |
209,472 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php | Zend_Db_Adapter_Pdo_Ibm_Ids.nextSequenceId | public function nextSequenceId($sequenceName)
{
$sql = 'SELECT '.$this->_adapter->quoteIdentifier($sequenceName).'.NEXTVAL FROM '
.'systables WHERE tabid = 1';
$value = $this->_adapter->fetchOne($sql);
return $value;
} | php | public function nextSequenceId($sequenceName)
{
$sql = 'SELECT '.$this->_adapter->quoteIdentifier($sequenceName).'.NEXTVAL FROM '
.'systables WHERE tabid = 1';
$value = $this->_adapter->fetchOne($sql);
return $value;
} | [
"public",
"function",
"nextSequenceId",
"(",
"$",
"sequenceName",
")",
"{",
"$",
"sql",
"=",
"'SELECT '",
".",
"$",
"this",
"->",
"_adapter",
"->",
"quoteIdentifier",
"(",
"$",
"sequenceName",
")",
".",
"'.NEXTVAL FROM '",
".",
"'systables WHERE tabid = 1'",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"_adapter",
"->",
"fetchOne",
"(",
"$",
"sql",
")",
";",
"return",
"$",
"value",
";",
"}"
] | IDS-specific sequence id value
@param string $sequenceName
@return integer | [
"IDS",
"-",
"specific",
"sequence",
"id",
"value"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Ibm/Ids.php#L294-L300 |
209,473 | matomo-org/matomo | libs/Zend/Config/Writer/Json.php | Zend_Config_Writer_Json.render | public function render()
{
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
$extends = $this->_config->getExtends();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
foreach ($extends as $section => $parentSection) {
$data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection;
}
// Ensure that each "extends" section actually exists
foreach ($data as $section => $sectionData) {
if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) {
$sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME];
if (!isset($data[$sectionExtends])) {
// Remove "extends" declaration if section does not exist
unset($data[$section][Zend_Config_Json::EXTENDS_NAME]);
}
}
}
$out = Zend_Json::encode($data);
if ($this->prettyPrint()) {
$out = Zend_Json::prettyPrint($out);
}
return $out;
} | php | public function render()
{
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
$extends = $this->_config->getExtends();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
foreach ($extends as $section => $parentSection) {
$data[$section][Zend_Config_Json::EXTENDS_NAME] = $parentSection;
}
// Ensure that each "extends" section actually exists
foreach ($data as $section => $sectionData) {
if (is_array($sectionData) && isset($sectionData[Zend_Config_Json::EXTENDS_NAME])) {
$sectionExtends = $sectionData[Zend_Config_Json::EXTENDS_NAME];
if (!isset($data[$sectionExtends])) {
// Remove "extends" declaration if section does not exist
unset($data[$section][Zend_Config_Json::EXTENDS_NAME]);
}
}
}
$out = Zend_Json::encode($data);
if ($this->prettyPrint()) {
$out = Zend_Json::prettyPrint($out);
}
return $out;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_config",
"->",
"toArray",
"(",
")",
";",
"$",
"sectionName",
"=",
"$",
"this",
"->",
"_config",
"->",
"getSectionName",
"(",
")",
";",
"$",
"extends",
"=",
"$",
"this",
"->",
"_config",
"->",
"getExtends",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"sectionName",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"$",
"sectionName",
"=>",
"$",
"data",
")",
";",
"}",
"foreach",
"(",
"$",
"extends",
"as",
"$",
"section",
"=>",
"$",
"parentSection",
")",
"{",
"$",
"data",
"[",
"$",
"section",
"]",
"[",
"Zend_Config_Json",
"::",
"EXTENDS_NAME",
"]",
"=",
"$",
"parentSection",
";",
"}",
"// Ensure that each \"extends\" section actually exists",
"foreach",
"(",
"$",
"data",
"as",
"$",
"section",
"=>",
"$",
"sectionData",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"sectionData",
")",
"&&",
"isset",
"(",
"$",
"sectionData",
"[",
"Zend_Config_Json",
"::",
"EXTENDS_NAME",
"]",
")",
")",
"{",
"$",
"sectionExtends",
"=",
"$",
"sectionData",
"[",
"Zend_Config_Json",
"::",
"EXTENDS_NAME",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"sectionExtends",
"]",
")",
")",
"{",
"// Remove \"extends\" declaration if section does not exist",
"unset",
"(",
"$",
"data",
"[",
"$",
"section",
"]",
"[",
"Zend_Config_Json",
"::",
"EXTENDS_NAME",
"]",
")",
";",
"}",
"}",
"}",
"$",
"out",
"=",
"Zend_Json",
"::",
"encode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"this",
"->",
"prettyPrint",
"(",
")",
")",
"{",
"$",
"out",
"=",
"Zend_Json",
"::",
"prettyPrint",
"(",
"$",
"out",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Render a Zend_Config into a JSON config string.
@since 1.10
@return string | [
"Render",
"a",
"Zend_Config",
"into",
"a",
"JSON",
"config",
"string",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Config/Writer/Json.php#L75-L105 |
209,474 | matomo-org/matomo | libs/Zend/Cache/Backend/Sqlite.php | Zend_Cache_Backend_Sqlite.getIdsNotMatchingTags | public function getIdsNotMatchingTags($tags = array())
{
$res = $this->_query("SELECT id FROM cache");
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
$result = array();
foreach ($rows as $row) {
$id = $row['id'];
$matching = false;
foreach ($tags as $tag) {
$res = $this->_query("SELECT COUNT(*) AS nbr FROM tag WHERE name='$tag' AND id='$id'");
if (!$res) {
return array();
}
$nbr = (int) @sqlite_fetch_single($res);
if ($nbr > 0) {
$matching = true;
}
}
if (!$matching) {
$result[] = $id;
}
}
return $result;
} | php | public function getIdsNotMatchingTags($tags = array())
{
$res = $this->_query("SELECT id FROM cache");
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
$result = array();
foreach ($rows as $row) {
$id = $row['id'];
$matching = false;
foreach ($tags as $tag) {
$res = $this->_query("SELECT COUNT(*) AS nbr FROM tag WHERE name='$tag' AND id='$id'");
if (!$res) {
return array();
}
$nbr = (int) @sqlite_fetch_single($res);
if ($nbr > 0) {
$matching = true;
}
}
if (!$matching) {
$result[] = $id;
}
}
return $result;
} | [
"public",
"function",
"getIdsNotMatchingTags",
"(",
"$",
"tags",
"=",
"array",
"(",
")",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"_query",
"(",
"\"SELECT id FROM cache\"",
")",
";",
"$",
"rows",
"=",
"@",
"sqlite_fetch_all",
"(",
"$",
"res",
",",
"SQLITE_ASSOC",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"id",
"=",
"$",
"row",
"[",
"'id'",
"]",
";",
"$",
"matching",
"=",
"false",
";",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"tag",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"_query",
"(",
"\"SELECT COUNT(*) AS nbr FROM tag WHERE name='$tag' AND id='$id'\"",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"nbr",
"=",
"(",
"int",
")",
"@",
"sqlite_fetch_single",
"(",
"$",
"res",
")",
";",
"if",
"(",
"$",
"nbr",
">",
"0",
")",
"{",
"$",
"matching",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"matching",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"id",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Return an array of stored cache ids which don't match given tags
In case of multiple tags, a logical OR is made between tags
@param array $tags array of tags
@return array array of not matching cache ids (string) | [
"Return",
"an",
"array",
"of",
"stored",
"cache",
"ids",
"which",
"don",
"t",
"match",
"given",
"tags"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/Sqlite.php#L302-L325 |
209,475 | matomo-org/matomo | libs/Zend/Cache/Backend/Sqlite.php | Zend_Cache_Backend_Sqlite._getConnection | private function _getConnection()
{
if (is_resource($this->_db)) {
return $this->_db;
} else {
$this->_db = @sqlite_open($this->_options['cache_db_complete_path']);
if (!(is_resource($this->_db))) {
Zend_Cache::throwException("Impossible to open " . $this->_options['cache_db_complete_path'] . " cache DB file");
}
return $this->_db;
}
} | php | private function _getConnection()
{
if (is_resource($this->_db)) {
return $this->_db;
} else {
$this->_db = @sqlite_open($this->_options['cache_db_complete_path']);
if (!(is_resource($this->_db))) {
Zend_Cache::throwException("Impossible to open " . $this->_options['cache_db_complete_path'] . " cache DB file");
}
return $this->_db;
}
} | [
"private",
"function",
"_getConnection",
"(",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"_db",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_db",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_db",
"=",
"@",
"sqlite_open",
"(",
"$",
"this",
"->",
"_options",
"[",
"'cache_db_complete_path'",
"]",
")",
";",
"if",
"(",
"!",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"_db",
")",
")",
")",
"{",
"Zend_Cache",
"::",
"throwException",
"(",
"\"Impossible to open \"",
".",
"$",
"this",
"->",
"_options",
"[",
"'cache_db_complete_path'",
"]",
".",
"\" cache DB file\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_db",
";",
"}",
"}"
] | Return the connection resource
If we are not connected, the connection is made
@throws Zend_Cache_Exception
@return resource Connection resource | [
"Return",
"the",
"connection",
"resource"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/Sqlite.php#L489-L500 |
209,476 | matomo-org/matomo | libs/Zend/Cache/Backend/Sqlite.php | Zend_Cache_Backend_Sqlite._query | private function _query($query)
{
$db = $this->_getConnection();
if (is_resource($db)) {
$res = @sqlite_query($db, $query);
if ($res === false) {
return false;
} else {
return $res;
}
}
return false;
} | php | private function _query($query)
{
$db = $this->_getConnection();
if (is_resource($db)) {
$res = @sqlite_query($db, $query);
if ($res === false) {
return false;
} else {
return $res;
}
}
return false;
} | [
"private",
"function",
"_query",
"(",
"$",
"query",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"_getConnection",
"(",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"db",
")",
")",
"{",
"$",
"res",
"=",
"@",
"sqlite_query",
"(",
"$",
"db",
",",
"$",
"query",
")",
";",
"if",
"(",
"$",
"res",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"$",
"res",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Execute an SQL query silently
@param string $query SQL query
@return mixed|false query results | [
"Execute",
"an",
"SQL",
"query",
"silently"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/Sqlite.php#L508-L520 |
209,477 | matomo-org/matomo | libs/Zend/Cache/Backend/Sqlite.php | Zend_Cache_Backend_Sqlite._automaticVacuum | private function _automaticVacuum()
{
if ($this->_options['automatic_vacuum_factor'] > 0) {
$rand = rand(1, $this->_options['automatic_vacuum_factor']);
if ($rand == 1) {
$this->_query('VACUUM');
}
}
} | php | private function _automaticVacuum()
{
if ($this->_options['automatic_vacuum_factor'] > 0) {
$rand = rand(1, $this->_options['automatic_vacuum_factor']);
if ($rand == 1) {
$this->_query('VACUUM');
}
}
} | [
"private",
"function",
"_automaticVacuum",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'automatic_vacuum_factor'",
"]",
">",
"0",
")",
"{",
"$",
"rand",
"=",
"rand",
"(",
"1",
",",
"$",
"this",
"->",
"_options",
"[",
"'automatic_vacuum_factor'",
"]",
")",
";",
"if",
"(",
"$",
"rand",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"_query",
"(",
"'VACUUM'",
")",
";",
"}",
"}",
"}"
] | Deal with the automatic vacuum process
@return void | [
"Deal",
"with",
"the",
"automatic",
"vacuum",
"process"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/Sqlite.php#L527-L535 |
209,478 | matomo-org/matomo | libs/Zend/Cache/Backend/Sqlite.php | Zend_Cache_Backend_Sqlite._registerTag | private function _registerTag($id, $tag) {
$res = $this->_query("DELETE FROM TAG WHERE name='$tag' AND id='$id'");
$res = $this->_query("INSERT INTO tag (name, id) VALUES ('$tag', '$id')");
if (!$res) {
$this->_log("Zend_Cache_Backend_Sqlite::_registerTag() : impossible to register tag=$tag on id=$id");
return false;
}
return true;
} | php | private function _registerTag($id, $tag) {
$res = $this->_query("DELETE FROM TAG WHERE name='$tag' AND id='$id'");
$res = $this->_query("INSERT INTO tag (name, id) VALUES ('$tag', '$id')");
if (!$res) {
$this->_log("Zend_Cache_Backend_Sqlite::_registerTag() : impossible to register tag=$tag on id=$id");
return false;
}
return true;
} | [
"private",
"function",
"_registerTag",
"(",
"$",
"id",
",",
"$",
"tag",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"_query",
"(",
"\"DELETE FROM TAG WHERE name='$tag' AND id='$id'\"",
")",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"_query",
"(",
"\"INSERT INTO tag (name, id) VALUES ('$tag', '$id')\"",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"this",
"->",
"_log",
"(",
"\"Zend_Cache_Backend_Sqlite::_registerTag() : impossible to register tag=$tag on id=$id\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Register a cache id with the given tag
@param string $id Cache id
@param string $tag Tag
@return boolean True if no problem | [
"Register",
"a",
"cache",
"id",
"with",
"the",
"given",
"tag"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/Sqlite.php#L544-L552 |
209,479 | matomo-org/matomo | libs/Zend/Cache/Backend/Sqlite.php | Zend_Cache_Backend_Sqlite._buildStructure | private function _buildStructure()
{
$this->_query('DROP INDEX tag_id_index');
$this->_query('DROP INDEX tag_name_index');
$this->_query('DROP INDEX cache_id_expire_index');
$this->_query('DROP TABLE version');
$this->_query('DROP TABLE cache');
$this->_query('DROP TABLE tag');
$this->_query('CREATE TABLE version (num INTEGER PRIMARY KEY)');
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
$this->_query('CREATE TABLE tag (name TEXT, id TEXT)');
$this->_query('CREATE INDEX tag_id_index ON tag(id)');
$this->_query('CREATE INDEX tag_name_index ON tag(name)');
$this->_query('CREATE INDEX cache_id_expire_index ON cache(id, expire)');
$this->_query('INSERT INTO version (num) VALUES (1)');
} | php | private function _buildStructure()
{
$this->_query('DROP INDEX tag_id_index');
$this->_query('DROP INDEX tag_name_index');
$this->_query('DROP INDEX cache_id_expire_index');
$this->_query('DROP TABLE version');
$this->_query('DROP TABLE cache');
$this->_query('DROP TABLE tag');
$this->_query('CREATE TABLE version (num INTEGER PRIMARY KEY)');
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
$this->_query('CREATE TABLE tag (name TEXT, id TEXT)');
$this->_query('CREATE INDEX tag_id_index ON tag(id)');
$this->_query('CREATE INDEX tag_name_index ON tag(name)');
$this->_query('CREATE INDEX cache_id_expire_index ON cache(id, expire)');
$this->_query('INSERT INTO version (num) VALUES (1)');
} | [
"private",
"function",
"_buildStructure",
"(",
")",
"{",
"$",
"this",
"->",
"_query",
"(",
"'DROP INDEX tag_id_index'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'DROP INDEX tag_name_index'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'DROP INDEX cache_id_expire_index'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'DROP TABLE version'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'DROP TABLE cache'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'DROP TABLE tag'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'CREATE TABLE version (num INTEGER PRIMARY KEY)'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'CREATE TABLE tag (name TEXT, id TEXT)'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'CREATE INDEX tag_id_index ON tag(id)'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'CREATE INDEX tag_name_index ON tag(name)'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'CREATE INDEX cache_id_expire_index ON cache(id, expire)'",
")",
";",
"$",
"this",
"->",
"_query",
"(",
"'INSERT INTO version (num) VALUES (1)'",
")",
";",
"}"
] | Build the database structure
@return false | [
"Build",
"the",
"database",
"structure"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Cache/Backend/Sqlite.php#L559-L574 |
209,480 | matomo-org/matomo | plugins/UserCountry/LocationProvider/GeoIp/Php.php | Php.getGeoIpInstance | private function getGeoIpInstance($key)
{
if (empty($this->geoIpCache[$key])) {
// make sure region names are loaded & saved first
parent::getRegionNames();
require_once PIWIK_INCLUDE_PATH . '/libs/MaxMindGeoIP/geoipcity.inc';
$pathToDb = self::getPathToGeoIpDatabase($this->customDbNames[$key]);
if ($pathToDb !== false) {
$this->geoIpCache[$key] = geoip_open($pathToDb, GEOIP_STANDARD); // TODO support shared memory
}
}
return empty($this->geoIpCache[$key]) ? false : $this->geoIpCache[$key];
} | php | private function getGeoIpInstance($key)
{
if (empty($this->geoIpCache[$key])) {
// make sure region names are loaded & saved first
parent::getRegionNames();
require_once PIWIK_INCLUDE_PATH . '/libs/MaxMindGeoIP/geoipcity.inc';
$pathToDb = self::getPathToGeoIpDatabase($this->customDbNames[$key]);
if ($pathToDb !== false) {
$this->geoIpCache[$key] = geoip_open($pathToDb, GEOIP_STANDARD); // TODO support shared memory
}
}
return empty($this->geoIpCache[$key]) ? false : $this->geoIpCache[$key];
} | [
"private",
"function",
"getGeoIpInstance",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"geoIpCache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// make sure region names are loaded & saved first",
"parent",
"::",
"getRegionNames",
"(",
")",
";",
"require_once",
"PIWIK_INCLUDE_PATH",
".",
"'/libs/MaxMindGeoIP/geoipcity.inc'",
";",
"$",
"pathToDb",
"=",
"self",
"::",
"getPathToGeoIpDatabase",
"(",
"$",
"this",
"->",
"customDbNames",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"$",
"pathToDb",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"geoIpCache",
"[",
"$",
"key",
"]",
"=",
"geoip_open",
"(",
"$",
"pathToDb",
",",
"GEOIP_STANDARD",
")",
";",
"// TODO support shared memory",
"}",
"}",
"return",
"empty",
"(",
"$",
"this",
"->",
"geoIpCache",
"[",
"$",
"key",
"]",
")",
"?",
"false",
":",
"$",
"this",
"->",
"geoIpCache",
"[",
"$",
"key",
"]",
";",
"}"
] | Returns a GeoIP instance. Creates it if necessary.
@param string $key 'loc', 'isp' or 'org'. Determines the type of GeoIP database
to load.
@return object|false | [
"Returns",
"a",
"GeoIP",
"instance",
".",
"Creates",
"it",
"if",
"necessary",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/UserCountry/LocationProvider/GeoIp/Php.php#L372-L386 |
209,481 | matomo-org/matomo | core/Db/Schema.php | Schema.getSchemaClassName | private static function getSchemaClassName($schemaName)
{
// Upgrade from pre 2.0.4
if (strtolower($schemaName) == 'myisam'
|| empty($schemaName)) {
$schemaName = self::DEFAULT_SCHEMA;
}
$class = str_replace(' ', '\\', ucwords(str_replace('_', ' ', strtolower($schemaName))));
return '\Piwik\Db\Schema\\' . $class;
} | php | private static function getSchemaClassName($schemaName)
{
// Upgrade from pre 2.0.4
if (strtolower($schemaName) == 'myisam'
|| empty($schemaName)) {
$schemaName = self::DEFAULT_SCHEMA;
}
$class = str_replace(' ', '\\', ucwords(str_replace('_', ' ', strtolower($schemaName))));
return '\Piwik\Db\Schema\\' . $class;
} | [
"private",
"static",
"function",
"getSchemaClassName",
"(",
"$",
"schemaName",
")",
"{",
"// Upgrade from pre 2.0.4",
"if",
"(",
"strtolower",
"(",
"$",
"schemaName",
")",
"==",
"'myisam'",
"||",
"empty",
"(",
"$",
"schemaName",
")",
")",
"{",
"$",
"schemaName",
"=",
"self",
"::",
"DEFAULT_SCHEMA",
";",
"}",
"$",
"class",
"=",
"str_replace",
"(",
"' '",
",",
"'\\\\'",
",",
"ucwords",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"strtolower",
"(",
"$",
"schemaName",
")",
")",
")",
")",
";",
"return",
"'\\Piwik\\Db\\Schema\\\\'",
".",
"$",
"class",
";",
"}"
] | Get schema class name
@param string $schemaName
@return string | [
"Get",
"schema",
"class",
"name"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Db/Schema.php#L38-L48 |
209,482 | matomo-org/matomo | core/Http/Router.php | Router.filterUrl | public function filterUrl($url)
{
$path = parse_url($url, PHP_URL_PATH);
if (strpos($path, 'index.php/') !== false) {
return preg_replace('#index\.php/([^\?]*)#', 'index.php', $url, 1);
}
return null;
} | php | public function filterUrl($url)
{
$path = parse_url($url, PHP_URL_PATH);
if (strpos($path, 'index.php/') !== false) {
return preg_replace('#index\.php/([^\?]*)#', 'index.php', $url, 1);
}
return null;
} | [
"public",
"function",
"filterUrl",
"(",
"$",
"url",
")",
"{",
"$",
"path",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_PATH",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'index.php/'",
")",
"!==",
"false",
")",
"{",
"return",
"preg_replace",
"(",
"'#index\\.php/([^\\?]*)#'",
",",
"'index.php'",
",",
"$",
"url",
",",
"1",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Filters some malformed URL by suggesting to redirect them.
E.g. /index.php/.html?... can be interpreted as HTML by old browsers
even though the Content-Type says JSON.
@link https://github.com/piwik/piwik/issues/6156
@param string $url The URL to filter.
@return string|null If not null, then the application should redirect to that URL. | [
"Filters",
"some",
"malformed",
"URL",
"by",
"suggesting",
"to",
"redirect",
"them",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Http/Router.php#L29-L38 |
209,483 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Abstract.php | Zend_Db_Adapter_Pdo_Abstract.exec | public function exec($sql)
{
if ($sql instanceof Zend_Db_Select) {
$sql = $sql->assemble();
}
try {
$affected = $this->getConnection()->exec($sql);
if ($affected === false) {
$errorInfo = $this->getConnection()->errorInfo();
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($errorInfo[2]);
}
return $affected;
} catch (PDOException $e) {
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
}
} | php | public function exec($sql)
{
if ($sql instanceof Zend_Db_Select) {
$sql = $sql->assemble();
}
try {
$affected = $this->getConnection()->exec($sql);
if ($affected === false) {
$errorInfo = $this->getConnection()->errorInfo();
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($errorInfo[2]);
}
return $affected;
} catch (PDOException $e) {
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
}
} | [
"public",
"function",
"exec",
"(",
"$",
"sql",
")",
"{",
"if",
"(",
"$",
"sql",
"instanceof",
"Zend_Db_Select",
")",
"{",
"$",
"sql",
"=",
"$",
"sql",
"->",
"assemble",
"(",
")",
";",
"}",
"try",
"{",
"$",
"affected",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"exec",
"(",
"$",
"sql",
")",
";",
"if",
"(",
"$",
"affected",
"===",
"false",
")",
"{",
"$",
"errorInfo",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"errorInfo",
"(",
")",
";",
"/**\n * @see Zend_Db_Adapter_Exception\n */",
"// require_once 'Zend/Db/Adapter/Exception.php';",
"throw",
"new",
"Zend_Db_Adapter_Exception",
"(",
"$",
"errorInfo",
"[",
"2",
"]",
")",
";",
"}",
"return",
"$",
"affected",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"/**\n * @see Zend_Db_Adapter_Exception\n */",
"// require_once 'Zend/Db/Adapter/Exception.php';",
"throw",
"new",
"Zend_Db_Adapter_Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Executes an SQL statement and return the number of affected rows
@param mixed $sql The SQL statement with placeholders.
May be a string or Zend_Db_Select.
@return integer Number of rows that were modified
or deleted by the SQL statement | [
"Executes",
"an",
"SQL",
"statement",
"and",
"return",
"the",
"number",
"of",
"affected",
"rows"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Abstract.php#L256-L282 |
209,484 | matomo-org/matomo | libs/Zend/Db/Adapter/Pdo/Abstract.php | Zend_Db_Adapter_Pdo_Abstract.setFetchMode | public function setFetchMode($mode)
{
//check for PDO extension
if (!extension_loaded('pdo')) {
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}
switch ($mode) {
case PDO::FETCH_LAZY:
case PDO::FETCH_ASSOC:
case PDO::FETCH_NUM:
case PDO::FETCH_BOTH:
case PDO::FETCH_NAMED:
case PDO::FETCH_OBJ:
$this->_fetchMode = $mode;
break;
default:
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Invalid fetch mode '$mode' specified");
break;
}
} | php | public function setFetchMode($mode)
{
//check for PDO extension
if (!extension_loaded('pdo')) {
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}
switch ($mode) {
case PDO::FETCH_LAZY:
case PDO::FETCH_ASSOC:
case PDO::FETCH_NUM:
case PDO::FETCH_BOTH:
case PDO::FETCH_NAMED:
case PDO::FETCH_OBJ:
$this->_fetchMode = $mode;
break;
default:
/**
* @see Zend_Db_Adapter_Exception
*/
// require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception("Invalid fetch mode '$mode' specified");
break;
}
} | [
"public",
"function",
"setFetchMode",
"(",
"$",
"mode",
")",
"{",
"//check for PDO extension",
"if",
"(",
"!",
"extension_loaded",
"(",
"'pdo'",
")",
")",
"{",
"/**\n * @see Zend_Db_Adapter_Exception\n */",
"// require_once 'Zend/Db/Adapter/Exception.php';",
"throw",
"new",
"Zend_Db_Adapter_Exception",
"(",
"'The PDO extension is required for this adapter but the extension is not loaded'",
")",
";",
"}",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"PDO",
"::",
"FETCH_LAZY",
":",
"case",
"PDO",
"::",
"FETCH_ASSOC",
":",
"case",
"PDO",
"::",
"FETCH_NUM",
":",
"case",
"PDO",
"::",
"FETCH_BOTH",
":",
"case",
"PDO",
"::",
"FETCH_NAMED",
":",
"case",
"PDO",
"::",
"FETCH_OBJ",
":",
"$",
"this",
"->",
"_fetchMode",
"=",
"$",
"mode",
";",
"break",
";",
"default",
":",
"/**\n * @see Zend_Db_Adapter_Exception\n */",
"// require_once 'Zend/Db/Adapter/Exception.php';",
"throw",
"new",
"Zend_Db_Adapter_Exception",
"(",
"\"Invalid fetch mode '$mode' specified\"",
")",
";",
"break",
";",
"}",
"}"
] | Set the PDO fetch mode.
@todo Support FETCH_CLASS and FETCH_INTO.
@param int $mode A PDO fetch mode.
@return void
@throws Zend_Db_Adapter_Exception | [
"Set",
"the",
"PDO",
"fetch",
"mode",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/Zend/Db/Adapter/Pdo/Abstract.php#L334-L361 |
209,485 | matomo-org/matomo | core/API/DataTableGenericFilter.php | DataTableGenericFilter.applyGenericFilters | protected function applyGenericFilters($datatable)
{
if ($datatable instanceof DataTable\Map) {
$tables = $datatable->getDataTables();
foreach ($tables as $table) {
$this->applyGenericFilters($table);
}
return;
}
$tableDisabledFilters = $datatable->getMetadata(DataTable::GENERIC_FILTERS_TO_DISABLE_METADATA_NAME) ?: [];
$genericFilters = $this->getGenericFiltersHavingDefaultValues();
$filterApplied = false;
foreach ($genericFilters as $filterMeta) {
$filterName = $filterMeta[0];
$filterParams = $filterMeta[1];
$filterParameters = array();
$exceptionRaised = false;
if (in_array($filterName, $this->disabledFilters)
|| in_array($filterName, $tableDisabledFilters)
) {
continue;
}
foreach ($filterParams as $name => $info) {
if (!is_array($info)) {
// hard coded value that cannot be changed via API, see eg $naturalSort = true in 'Sort'
$filterParameters[] = $info;
} else {
// parameter type to cast to
$type = $info[0];
// default value if specified, when the parameter doesn't have a value
$defaultValue = null;
if (isset($info[1])) {
$defaultValue = $info[1];
}
try {
$value = Common::getRequestVar($name, $defaultValue, $type, $this->request);
settype($value, $type);
$filterParameters[] = $value;
} catch (Exception $e) {
$exceptionRaised = true;
break;
}
}
}
if (!$exceptionRaised) {
$datatable->filter($filterName, $filterParameters);
$filterApplied = true;
}
}
return $filterApplied;
} | php | protected function applyGenericFilters($datatable)
{
if ($datatable instanceof DataTable\Map) {
$tables = $datatable->getDataTables();
foreach ($tables as $table) {
$this->applyGenericFilters($table);
}
return;
}
$tableDisabledFilters = $datatable->getMetadata(DataTable::GENERIC_FILTERS_TO_DISABLE_METADATA_NAME) ?: [];
$genericFilters = $this->getGenericFiltersHavingDefaultValues();
$filterApplied = false;
foreach ($genericFilters as $filterMeta) {
$filterName = $filterMeta[0];
$filterParams = $filterMeta[1];
$filterParameters = array();
$exceptionRaised = false;
if (in_array($filterName, $this->disabledFilters)
|| in_array($filterName, $tableDisabledFilters)
) {
continue;
}
foreach ($filterParams as $name => $info) {
if (!is_array($info)) {
// hard coded value that cannot be changed via API, see eg $naturalSort = true in 'Sort'
$filterParameters[] = $info;
} else {
// parameter type to cast to
$type = $info[0];
// default value if specified, when the parameter doesn't have a value
$defaultValue = null;
if (isset($info[1])) {
$defaultValue = $info[1];
}
try {
$value = Common::getRequestVar($name, $defaultValue, $type, $this->request);
settype($value, $type);
$filterParameters[] = $value;
} catch (Exception $e) {
$exceptionRaised = true;
break;
}
}
}
if (!$exceptionRaised) {
$datatable->filter($filterName, $filterParameters);
$filterApplied = true;
}
}
return $filterApplied;
} | [
"protected",
"function",
"applyGenericFilters",
"(",
"$",
"datatable",
")",
"{",
"if",
"(",
"$",
"datatable",
"instanceof",
"DataTable",
"\\",
"Map",
")",
"{",
"$",
"tables",
"=",
"$",
"datatable",
"->",
"getDataTables",
"(",
")",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"applyGenericFilters",
"(",
"$",
"table",
")",
";",
"}",
"return",
";",
"}",
"$",
"tableDisabledFilters",
"=",
"$",
"datatable",
"->",
"getMetadata",
"(",
"DataTable",
"::",
"GENERIC_FILTERS_TO_DISABLE_METADATA_NAME",
")",
"?",
":",
"[",
"]",
";",
"$",
"genericFilters",
"=",
"$",
"this",
"->",
"getGenericFiltersHavingDefaultValues",
"(",
")",
";",
"$",
"filterApplied",
"=",
"false",
";",
"foreach",
"(",
"$",
"genericFilters",
"as",
"$",
"filterMeta",
")",
"{",
"$",
"filterName",
"=",
"$",
"filterMeta",
"[",
"0",
"]",
";",
"$",
"filterParams",
"=",
"$",
"filterMeta",
"[",
"1",
"]",
";",
"$",
"filterParameters",
"=",
"array",
"(",
")",
";",
"$",
"exceptionRaised",
"=",
"false",
";",
"if",
"(",
"in_array",
"(",
"$",
"filterName",
",",
"$",
"this",
"->",
"disabledFilters",
")",
"||",
"in_array",
"(",
"$",
"filterName",
",",
"$",
"tableDisabledFilters",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"filterParams",
"as",
"$",
"name",
"=>",
"$",
"info",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"info",
")",
")",
"{",
"// hard coded value that cannot be changed via API, see eg $naturalSort = true in 'Sort'",
"$",
"filterParameters",
"[",
"]",
"=",
"$",
"info",
";",
"}",
"else",
"{",
"// parameter type to cast to",
"$",
"type",
"=",
"$",
"info",
"[",
"0",
"]",
";",
"// default value if specified, when the parameter doesn't have a value",
"$",
"defaultValue",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"1",
"]",
")",
")",
"{",
"$",
"defaultValue",
"=",
"$",
"info",
"[",
"1",
"]",
";",
"}",
"try",
"{",
"$",
"value",
"=",
"Common",
"::",
"getRequestVar",
"(",
"$",
"name",
",",
"$",
"defaultValue",
",",
"$",
"type",
",",
"$",
"this",
"->",
"request",
")",
";",
"settype",
"(",
"$",
"value",
",",
"$",
"type",
")",
";",
"$",
"filterParameters",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionRaised",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"exceptionRaised",
")",
"{",
"$",
"datatable",
"->",
"filter",
"(",
"$",
"filterName",
",",
"$",
"filterParameters",
")",
";",
"$",
"filterApplied",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"filterApplied",
";",
"}"
] | Apply generic filters to the DataTable object resulting from the API Call.
Disable this feature by setting the parameter disable_generic_filters to 1 in the API call request.
@param DataTable $datatable
@return bool | [
"Apply",
"generic",
"filters",
"to",
"the",
"DataTable",
"object",
"resulting",
"from",
"the",
"API",
"Call",
".",
"Disable",
"this",
"feature",
"by",
"setting",
"the",
"parameter",
"disable_generic_filters",
"to",
"1",
"in",
"the",
"API",
"call",
"request",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/API/DataTableGenericFilter.php#L148-L206 |
209,486 | matomo-org/matomo | plugins/DevicesDetection/API.php | API.getBrand | public function getBrand($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_brands', $idSite, $period, $date, $segment);
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getDeviceBrandLabel'));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrandLogo'));
$dataTable->filter('AddSegmentByLabel', array('deviceBrand'));
return $dataTable;
} | php | public function getBrand($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_brands', $idSite, $period, $date, $segment);
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getDeviceBrandLabel'));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrandLogo'));
$dataTable->filter('AddSegmentByLabel', array('deviceBrand'));
return $dataTable;
} | [
"public",
"function",
"getBrand",
"(",
"$",
"idSite",
",",
"$",
"period",
",",
"$",
"date",
",",
"$",
"segment",
"=",
"false",
")",
"{",
"$",
"dataTable",
"=",
"$",
"this",
"->",
"getDataTable",
"(",
"'DevicesDetection_brands'",
",",
"$",
"idSite",
",",
"$",
"period",
",",
"$",
"date",
",",
"$",
"segment",
")",
";",
"$",
"dataTable",
"->",
"filter",
"(",
"'GroupBy'",
",",
"array",
"(",
"'label'",
",",
"__NAMESPACE__",
".",
"'\\getDeviceBrandLabel'",
")",
")",
";",
"$",
"dataTable",
"->",
"filter",
"(",
"'ColumnCallbackAddMetadata'",
",",
"array",
"(",
"'label'",
",",
"'logo'",
",",
"__NAMESPACE__",
".",
"'\\getBrandLogo'",
")",
")",
";",
"$",
"dataTable",
"->",
"filter",
"(",
"'AddSegmentByLabel'",
",",
"array",
"(",
"'deviceBrand'",
")",
")",
";",
"return",
"$",
"dataTable",
";",
"}"
] | Gets datatable displaying number of visits by device manufacturer name
@param int $idSite
@param string $period
@param string $date
@param bool|string $segment
@return DataTable | [
"Gets",
"datatable",
"displaying",
"number",
"of",
"visits",
"by",
"device",
"manufacturer",
"name"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/DevicesDetection/API.php#L94-L101 |
209,487 | matomo-org/matomo | plugins/DevicesDetection/API.php | API.getModel | public function getModel($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_models', $idSite, $period, $date, $segment);
$dataTable->filter(function (DataTable $table) {
foreach ($table->getRowsWithoutSummaryRow() as $row) {
$label = $row->getColumn('label');
if (strpos($label, ';') !== false) {
list($brand, $model) = explode(';', $label, 2);
$brand = getDeviceBrandLabel($brand);
} else {
$brand = null;
$model = $label;
}
$segment = sprintf('deviceBrand==%s;deviceModel==%s', urlencode($brand), urlencode($model));
$row->setMetadata('segment', $segment);
}
});
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getModelName'));
return $dataTable;
} | php | public function getModel($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_models', $idSite, $period, $date, $segment);
$dataTable->filter(function (DataTable $table) {
foreach ($table->getRowsWithoutSummaryRow() as $row) {
$label = $row->getColumn('label');
if (strpos($label, ';') !== false) {
list($brand, $model) = explode(';', $label, 2);
$brand = getDeviceBrandLabel($brand);
} else {
$brand = null;
$model = $label;
}
$segment = sprintf('deviceBrand==%s;deviceModel==%s', urlencode($brand), urlencode($model));
$row->setMetadata('segment', $segment);
}
});
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getModelName'));
return $dataTable;
} | [
"public",
"function",
"getModel",
"(",
"$",
"idSite",
",",
"$",
"period",
",",
"$",
"date",
",",
"$",
"segment",
"=",
"false",
")",
"{",
"$",
"dataTable",
"=",
"$",
"this",
"->",
"getDataTable",
"(",
"'DevicesDetection_models'",
",",
"$",
"idSite",
",",
"$",
"period",
",",
"$",
"date",
",",
"$",
"segment",
")",
";",
"$",
"dataTable",
"->",
"filter",
"(",
"function",
"(",
"DataTable",
"$",
"table",
")",
"{",
"foreach",
"(",
"$",
"table",
"->",
"getRowsWithoutSummaryRow",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"label",
"=",
"$",
"row",
"->",
"getColumn",
"(",
"'label'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"label",
",",
"';'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"brand",
",",
"$",
"model",
")",
"=",
"explode",
"(",
"';'",
",",
"$",
"label",
",",
"2",
")",
";",
"$",
"brand",
"=",
"getDeviceBrandLabel",
"(",
"$",
"brand",
")",
";",
"}",
"else",
"{",
"$",
"brand",
"=",
"null",
";",
"$",
"model",
"=",
"$",
"label",
";",
"}",
"$",
"segment",
"=",
"sprintf",
"(",
"'deviceBrand==%s;deviceModel==%s'",
",",
"urlencode",
"(",
"$",
"brand",
")",
",",
"urlencode",
"(",
"$",
"model",
")",
")",
";",
"$",
"row",
"->",
"setMetadata",
"(",
"'segment'",
",",
"$",
"segment",
")",
";",
"}",
"}",
")",
";",
"$",
"dataTable",
"->",
"filter",
"(",
"'GroupBy'",
",",
"array",
"(",
"'label'",
",",
"__NAMESPACE__",
".",
"'\\getModelName'",
")",
")",
";",
"return",
"$",
"dataTable",
";",
"}"
] | Gets datatable displaying number of visits by device model
@param int $idSite
@param string $period
@param string $date
@param bool|string $segment
@return DataTable | [
"Gets",
"datatable",
"displaying",
"number",
"of",
"visits",
"by",
"device",
"model"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/DevicesDetection/API.php#L111-L136 |
209,488 | matomo-org/matomo | plugins/DevicesDetection/API.php | API.mergeDataTables | protected function mergeDataTables(DataTable\DataTableInterface $dataTable, DataTable\DataTableInterface $dataTable2)
{
if ($dataTable instanceof DataTable\Map) {
$dataTables = $dataTable->getDataTables();
foreach ($dataTables as $label => $table) {
$versionDataTables = $dataTable2->getDataTables();
if (!array_key_exists($label, $versionDataTables)) {
continue;
}
$newDataTable = $this->mergeDataTables($table, $versionDataTables[$label]);
$dataTable->addTable($newDataTable, $label);
}
} else if (!$dataTable->getRowsCount() && $dataTable2->getRowsCount()) {
$dataTable2->filter('GroupBy', array('label', function ($label) {
if (preg_match("/(.+) [0-9]+(?:\.[0-9]+)?$/", $label, $matches)) {
return $matches[1]; // should match for browsers
}
if (strpos($label, ';')) {
return substr($label, 0, 3); // should match for os
}
return $label;
}));
return $dataTable2;
}
return $dataTable;
} | php | protected function mergeDataTables(DataTable\DataTableInterface $dataTable, DataTable\DataTableInterface $dataTable2)
{
if ($dataTable instanceof DataTable\Map) {
$dataTables = $dataTable->getDataTables();
foreach ($dataTables as $label => $table) {
$versionDataTables = $dataTable2->getDataTables();
if (!array_key_exists($label, $versionDataTables)) {
continue;
}
$newDataTable = $this->mergeDataTables($table, $versionDataTables[$label]);
$dataTable->addTable($newDataTable, $label);
}
} else if (!$dataTable->getRowsCount() && $dataTable2->getRowsCount()) {
$dataTable2->filter('GroupBy', array('label', function ($label) {
if (preg_match("/(.+) [0-9]+(?:\.[0-9]+)?$/", $label, $matches)) {
return $matches[1]; // should match for browsers
}
if (strpos($label, ';')) {
return substr($label, 0, 3); // should match for os
}
return $label;
}));
return $dataTable2;
}
return $dataTable;
} | [
"protected",
"function",
"mergeDataTables",
"(",
"DataTable",
"\\",
"DataTableInterface",
"$",
"dataTable",
",",
"DataTable",
"\\",
"DataTableInterface",
"$",
"dataTable2",
")",
"{",
"if",
"(",
"$",
"dataTable",
"instanceof",
"DataTable",
"\\",
"Map",
")",
"{",
"$",
"dataTables",
"=",
"$",
"dataTable",
"->",
"getDataTables",
"(",
")",
";",
"foreach",
"(",
"$",
"dataTables",
"as",
"$",
"label",
"=>",
"$",
"table",
")",
"{",
"$",
"versionDataTables",
"=",
"$",
"dataTable2",
"->",
"getDataTables",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"label",
",",
"$",
"versionDataTables",
")",
")",
"{",
"continue",
";",
"}",
"$",
"newDataTable",
"=",
"$",
"this",
"->",
"mergeDataTables",
"(",
"$",
"table",
",",
"$",
"versionDataTables",
"[",
"$",
"label",
"]",
")",
";",
"$",
"dataTable",
"->",
"addTable",
"(",
"$",
"newDataTable",
",",
"$",
"label",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"$",
"dataTable",
"->",
"getRowsCount",
"(",
")",
"&&",
"$",
"dataTable2",
"->",
"getRowsCount",
"(",
")",
")",
"{",
"$",
"dataTable2",
"->",
"filter",
"(",
"'GroupBy'",
",",
"array",
"(",
"'label'",
",",
"function",
"(",
"$",
"label",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/(.+) [0-9]+(?:\\.[0-9]+)?$/\"",
",",
"$",
"label",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"// should match for browsers",
"}",
"if",
"(",
"strpos",
"(",
"$",
"label",
",",
"';'",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"label",
",",
"0",
",",
"3",
")",
";",
"// should match for os",
"}",
"return",
"$",
"label",
";",
"}",
")",
")",
";",
"return",
"$",
"dataTable2",
";",
"}",
"return",
"$",
"dataTable",
";",
"}"
] | That methods handles the fallback to version datatables to calculate those without versions.
Unlike DevicesDetection plugin now, the UserSettings plugin did not store archives holding the os and browser data without
their version number. The "version-less" reports were always generated out of the "version-containing" archives .
For big archives (month/year) that ment that some of the data was truncated, due to the datatable entry limit.
To avoid that data loss / inaccuracy in the future, DevicesDetection plugin will also store archives without the version.
For data archived before DevicesDetection plugin was enabled, those archives do not exist, so we try to calculate
them here from the "version-containing" reports if possible.
@param DataTable\DataTableInterface $dataTable
@param DataTable\DataTableInterface $dataTable2
@return DataTable\DataTableInterface | [
"That",
"methods",
"handles",
"the",
"fallback",
"to",
"version",
"datatables",
"to",
"calculate",
"those",
"without",
"versions",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/DevicesDetection/API.php#L176-L206 |
209,489 | matomo-org/matomo | plugins/CorePluginsAdmin/Controller.php | Controller.isAllowedToTroubleshootAsSuperUser | protected function isAllowedToTroubleshootAsSuperUser()
{
$isAllowedToTroubleshootAsSuperUser = false;
$salt = SettingsPiwik::getSalt();
if (!empty($salt)) {
$saltFromRequest = Common::getRequestVar('i_am_super_user', '', 'string');
$isAllowedToTroubleshootAsSuperUser = ($salt == $saltFromRequest);
}
return $isAllowedToTroubleshootAsSuperUser;
} | php | protected function isAllowedToTroubleshootAsSuperUser()
{
$isAllowedToTroubleshootAsSuperUser = false;
$salt = SettingsPiwik::getSalt();
if (!empty($salt)) {
$saltFromRequest = Common::getRequestVar('i_am_super_user', '', 'string');
$isAllowedToTroubleshootAsSuperUser = ($salt == $saltFromRequest);
}
return $isAllowedToTroubleshootAsSuperUser;
} | [
"protected",
"function",
"isAllowedToTroubleshootAsSuperUser",
"(",
")",
"{",
"$",
"isAllowedToTroubleshootAsSuperUser",
"=",
"false",
";",
"$",
"salt",
"=",
"SettingsPiwik",
"::",
"getSalt",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"salt",
")",
")",
"{",
"$",
"saltFromRequest",
"=",
"Common",
"::",
"getRequestVar",
"(",
"'i_am_super_user'",
",",
"''",
",",
"'string'",
")",
";",
"$",
"isAllowedToTroubleshootAsSuperUser",
"=",
"(",
"$",
"salt",
"==",
"$",
"saltFromRequest",
")",
";",
"}",
"return",
"$",
"isAllowedToTroubleshootAsSuperUser",
";",
"}"
] | Let Super User troubleshoot in safe mode, even when Login is broken, with this special trick
@return bool
@throws Exception | [
"Let",
"Super",
"User",
"troubleshoot",
"in",
"safe",
"mode",
"even",
"when",
"Login",
"is",
"broken",
"with",
"this",
"special",
"trick"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/plugins/CorePluginsAdmin/Controller.php#L588-L597 |
209,490 | matomo-org/matomo | core/UrlHelper.php | UrlHelper.getArrayFromQueryString | public static function getArrayFromQueryString($urlQuery)
{
if (strlen($urlQuery) == 0) {
return array();
}
// TODO: this method should not use a cache. callers should instead have their own cache, configured through DI.
// one undesirable side effect of using a cache here, is that this method can now init the StaticContainer, which makes setting
// test environment for RequestCommand more complicated.
$cache = Cache::getTransientCache();
$cacheKey = 'arrayFromQuery' . $urlQuery;
if ($cache->contains($cacheKey)) {
return $cache->fetch($cacheKey);
}
if ($urlQuery[0] == '?') {
$urlQuery = substr($urlQuery, 1);
}
$separator = '&';
$urlQuery = $separator . $urlQuery;
// $urlQuery = str_replace(array('%20'), ' ', $urlQuery);
$referrerQuery = trim($urlQuery);
$values = explode($separator, $referrerQuery);
$nameToValue = array();
foreach ($values as $value) {
$pos = strpos($value, '=');
if ($pos !== false) {
$name = substr($value, 0, $pos);
$value = substr($value, $pos + 1);
if ($value === false) {
$value = '';
}
} else {
$name = $value;
$value = false;
}
if (!empty($name)) {
$name = Common::sanitizeInputValue($name);
}
if (!empty($value)) {
$value = Common::sanitizeInputValue($value);
}
// if array without indexes
$count = 0;
$tmp = preg_replace('/(\[|%5b)(]|%5d)$/i', '', $name, -1, $count);
if (!empty($tmp) && $count) {
$name = $tmp;
if (isset($nameToValue[$name]) == false || is_array($nameToValue[$name]) == false) {
$nameToValue[$name] = array();
}
array_push($nameToValue[$name], $value);
} elseif (!empty($name)) {
$nameToValue[$name] = $value;
}
}
$cache->save($cacheKey, $nameToValue);
return $nameToValue;
} | php | public static function getArrayFromQueryString($urlQuery)
{
if (strlen($urlQuery) == 0) {
return array();
}
// TODO: this method should not use a cache. callers should instead have their own cache, configured through DI.
// one undesirable side effect of using a cache here, is that this method can now init the StaticContainer, which makes setting
// test environment for RequestCommand more complicated.
$cache = Cache::getTransientCache();
$cacheKey = 'arrayFromQuery' . $urlQuery;
if ($cache->contains($cacheKey)) {
return $cache->fetch($cacheKey);
}
if ($urlQuery[0] == '?') {
$urlQuery = substr($urlQuery, 1);
}
$separator = '&';
$urlQuery = $separator . $urlQuery;
// $urlQuery = str_replace(array('%20'), ' ', $urlQuery);
$referrerQuery = trim($urlQuery);
$values = explode($separator, $referrerQuery);
$nameToValue = array();
foreach ($values as $value) {
$pos = strpos($value, '=');
if ($pos !== false) {
$name = substr($value, 0, $pos);
$value = substr($value, $pos + 1);
if ($value === false) {
$value = '';
}
} else {
$name = $value;
$value = false;
}
if (!empty($name)) {
$name = Common::sanitizeInputValue($name);
}
if (!empty($value)) {
$value = Common::sanitizeInputValue($value);
}
// if array without indexes
$count = 0;
$tmp = preg_replace('/(\[|%5b)(]|%5d)$/i', '', $name, -1, $count);
if (!empty($tmp) && $count) {
$name = $tmp;
if (isset($nameToValue[$name]) == false || is_array($nameToValue[$name]) == false) {
$nameToValue[$name] = array();
}
array_push($nameToValue[$name], $value);
} elseif (!empty($name)) {
$nameToValue[$name] = $value;
}
}
$cache->save($cacheKey, $nameToValue);
return $nameToValue;
} | [
"public",
"static",
"function",
"getArrayFromQueryString",
"(",
"$",
"urlQuery",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"urlQuery",
")",
"==",
"0",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"// TODO: this method should not use a cache. callers should instead have their own cache, configured through DI.",
"// one undesirable side effect of using a cache here, is that this method can now init the StaticContainer, which makes setting",
"// test environment for RequestCommand more complicated.",
"$",
"cache",
"=",
"Cache",
"::",
"getTransientCache",
"(",
")",
";",
"$",
"cacheKey",
"=",
"'arrayFromQuery'",
".",
"$",
"urlQuery",
";",
"if",
"(",
"$",
"cache",
"->",
"contains",
"(",
"$",
"cacheKey",
")",
")",
"{",
"return",
"$",
"cache",
"->",
"fetch",
"(",
"$",
"cacheKey",
")",
";",
"}",
"if",
"(",
"$",
"urlQuery",
"[",
"0",
"]",
"==",
"'?'",
")",
"{",
"$",
"urlQuery",
"=",
"substr",
"(",
"$",
"urlQuery",
",",
"1",
")",
";",
"}",
"$",
"separator",
"=",
"'&'",
";",
"$",
"urlQuery",
"=",
"$",
"separator",
".",
"$",
"urlQuery",
";",
"//\t\t$urlQuery = str_replace(array('%20'), ' ', $urlQuery);",
"$",
"referrerQuery",
"=",
"trim",
"(",
"$",
"urlQuery",
")",
";",
"$",
"values",
"=",
"explode",
"(",
"$",
"separator",
",",
"$",
"referrerQuery",
")",
";",
"$",
"nameToValue",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"value",
",",
"'='",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"$",
"pos",
"+",
"1",
")",
";",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"$",
"value",
"=",
"''",
";",
"}",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"Common",
"::",
"sanitizeInputValue",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"Common",
"::",
"sanitizeInputValue",
"(",
"$",
"value",
")",
";",
"}",
"// if array without indexes",
"$",
"count",
"=",
"0",
";",
"$",
"tmp",
"=",
"preg_replace",
"(",
"'/(\\[|%5b)(]|%5d)$/i'",
",",
"''",
",",
"$",
"name",
",",
"-",
"1",
",",
"$",
"count",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tmp",
")",
"&&",
"$",
"count",
")",
"{",
"$",
"name",
"=",
"$",
"tmp",
";",
"if",
"(",
"isset",
"(",
"$",
"nameToValue",
"[",
"$",
"name",
"]",
")",
"==",
"false",
"||",
"is_array",
"(",
"$",
"nameToValue",
"[",
"$",
"name",
"]",
")",
"==",
"false",
")",
"{",
"$",
"nameToValue",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"}",
"array_push",
"(",
"$",
"nameToValue",
"[",
"$",
"name",
"]",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"nameToValue",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"cache",
"->",
"save",
"(",
"$",
"cacheKey",
",",
"$",
"nameToValue",
")",
";",
"return",
"$",
"nameToValue",
";",
"}"
] | Returns a URL query string as an array.
@param string $urlQuery The query string, eg, `'?param1=value1¶m2=value2'`.
@return array eg, `array('param1' => 'value1', 'param2' => 'value2')`
@api | [
"Returns",
"a",
"URL",
"query",
"string",
"as",
"an",
"array",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/UrlHelper.php#L203-L268 |
209,491 | matomo-org/matomo | core/UrlHelper.php | UrlHelper.getParameterFromQueryString | public static function getParameterFromQueryString($urlQuery, $parameter)
{
$nameToValue = self::getArrayFromQueryString($urlQuery);
if (isset($nameToValue[$parameter])) {
return $nameToValue[$parameter];
}
return null;
} | php | public static function getParameterFromQueryString($urlQuery, $parameter)
{
$nameToValue = self::getArrayFromQueryString($urlQuery);
if (isset($nameToValue[$parameter])) {
return $nameToValue[$parameter];
}
return null;
} | [
"public",
"static",
"function",
"getParameterFromQueryString",
"(",
"$",
"urlQuery",
",",
"$",
"parameter",
")",
"{",
"$",
"nameToValue",
"=",
"self",
"::",
"getArrayFromQueryString",
"(",
"$",
"urlQuery",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"nameToValue",
"[",
"$",
"parameter",
"]",
")",
")",
"{",
"return",
"$",
"nameToValue",
"[",
"$",
"parameter",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the value of a single query parameter from the supplied query string.
@param string $urlQuery The query string.
@param string $parameter The query parameter name to return.
@return string|null Parameter value if found (can be the empty string!), null if not found.
@api | [
"Returns",
"the",
"value",
"of",
"a",
"single",
"query",
"parameter",
"from",
"the",
"supplied",
"query",
"string",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/UrlHelper.php#L278-L286 |
209,492 | matomo-org/matomo | core/UrlHelper.php | UrlHelper.getPathAndQueryFromUrl | public static function getPathAndQueryFromUrl($url)
{
$parsedUrl = parse_url($url);
$result = '';
if (isset($parsedUrl['path'])) {
if (substr($parsedUrl['path'], 0, 1) == '/') {
$parsedUrl['path'] = substr($parsedUrl['path'], 1);
}
$result .= $parsedUrl['path'];
}
if (isset($parsedUrl['query'])) {
$result .= '?' . $parsedUrl['query'];
}
return $result;
} | php | public static function getPathAndQueryFromUrl($url)
{
$parsedUrl = parse_url($url);
$result = '';
if (isset($parsedUrl['path'])) {
if (substr($parsedUrl['path'], 0, 1) == '/') {
$parsedUrl['path'] = substr($parsedUrl['path'], 1);
}
$result .= $parsedUrl['path'];
}
if (isset($parsedUrl['query'])) {
$result .= '?' . $parsedUrl['query'];
}
return $result;
} | [
"public",
"static",
"function",
"getPathAndQueryFromUrl",
"(",
"$",
"url",
")",
"{",
"$",
"parsedUrl",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"result",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"parsedUrl",
"[",
"'path'",
"]",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"parsedUrl",
"[",
"'path'",
"]",
",",
"0",
",",
"1",
")",
"==",
"'/'",
")",
"{",
"$",
"parsedUrl",
"[",
"'path'",
"]",
"=",
"substr",
"(",
"$",
"parsedUrl",
"[",
"'path'",
"]",
",",
"1",
")",
";",
"}",
"$",
"result",
".=",
"$",
"parsedUrl",
"[",
"'path'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"parsedUrl",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"result",
".=",
"'?'",
".",
"$",
"parsedUrl",
"[",
"'query'",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the path and query string of a URL.
@param string $url The URL.
@return string eg, `/test/index.php?module=CoreHome` if `$url` is `http://piwik.org/test/index.php?module=CoreHome`.
@api | [
"Returns",
"the",
"path",
"and",
"query",
"string",
"of",
"a",
"URL",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/UrlHelper.php#L295-L309 |
209,493 | matomo-org/matomo | core/UrlHelper.php | UrlHelper.getQueryFromUrl | public static function getQueryFromUrl($url, array $additionalParamsToAdd = array())
{
$url = @parse_url($url);
$query = '';
if (!empty($url['query'])) {
$query .= $url['query'];
}
if (!empty($additionalParamsToAdd)) {
if (!empty($query)) {
$query .= '&';
}
$query .= Url::getQueryStringFromParameters($additionalParamsToAdd);
}
return $query;
} | php | public static function getQueryFromUrl($url, array $additionalParamsToAdd = array())
{
$url = @parse_url($url);
$query = '';
if (!empty($url['query'])) {
$query .= $url['query'];
}
if (!empty($additionalParamsToAdd)) {
if (!empty($query)) {
$query .= '&';
}
$query .= Url::getQueryStringFromParameters($additionalParamsToAdd);
}
return $query;
} | [
"public",
"static",
"function",
"getQueryFromUrl",
"(",
"$",
"url",
",",
"array",
"$",
"additionalParamsToAdd",
"=",
"array",
"(",
")",
")",
"{",
"$",
"url",
"=",
"@",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"query",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"url",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"query",
".=",
"$",
"url",
"[",
"'query'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"additionalParamsToAdd",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
")",
")",
"{",
"$",
"query",
".=",
"'&'",
";",
"}",
"$",
"query",
".=",
"Url",
"::",
"getQueryStringFromParameters",
"(",
"$",
"additionalParamsToAdd",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Returns the query part from any valid url and adds additional parameters to the query part if needed.
@param string $url Any url eg `"http://example.com/piwik/?foo=bar"`
@param array $additionalParamsToAdd If not empty the given parameters will be added to the query.
@return string eg. `"foo=bar&foo2=bar2"`
@api | [
"Returns",
"the",
"query",
"part",
"from",
"any",
"valid",
"url",
"and",
"adds",
"additional",
"parameters",
"to",
"the",
"query",
"part",
"if",
"needed",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/UrlHelper.php#L320-L338 |
209,494 | matomo-org/matomo | libs/HTML/QuickForm2/Controller/SessionContainer.php | HTML_QuickForm2_Controller_SessionContainer.getValidationStatus | public function getValidationStatus($pageId)
{
return array_key_exists($pageId, $this->data['valid'])
? $this->data['valid'][$pageId]: null;
} | php | public function getValidationStatus($pageId)
{
return array_key_exists($pageId, $this->data['valid'])
? $this->data['valid'][$pageId]: null;
} | [
"public",
"function",
"getValidationStatus",
"(",
"$",
"pageId",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"pageId",
",",
"$",
"this",
"->",
"data",
"[",
"'valid'",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"'valid'",
"]",
"[",
"$",
"pageId",
"]",
":",
"null",
";",
"}"
] | Returns the page validation status kept in session
@param string Page ID
@return bool | [
"Returns",
"the",
"page",
"validation",
"status",
"kept",
"in",
"session"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Controller/SessionContainer.php#L129-L134 |
209,495 | matomo-org/matomo | libs/HTML/QuickForm2/Controller/SessionContainer.php | HTML_QuickForm2_Controller_SessionContainer.storeDatasources | public function storeDatasources(array $datasources)
{
foreach ($datasources as $ds) {
if (!$ds instanceof HTML_QuickForm2_DataSource) {
throw new HTML_QuickForm2_InvalidArgumentException(
'Array should contain only DataSource instances'
);
}
}
$this->data['datasources'] = $datasources;
} | php | public function storeDatasources(array $datasources)
{
foreach ($datasources as $ds) {
if (!$ds instanceof HTML_QuickForm2_DataSource) {
throw new HTML_QuickForm2_InvalidArgumentException(
'Array should contain only DataSource instances'
);
}
}
$this->data['datasources'] = $datasources;
} | [
"public",
"function",
"storeDatasources",
"(",
"array",
"$",
"datasources",
")",
"{",
"foreach",
"(",
"$",
"datasources",
"as",
"$",
"ds",
")",
"{",
"if",
"(",
"!",
"$",
"ds",
"instanceof",
"HTML_QuickForm2_DataSource",
")",
"{",
"throw",
"new",
"HTML_QuickForm2_InvalidArgumentException",
"(",
"'Array should contain only DataSource instances'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"data",
"[",
"'datasources'",
"]",
"=",
"$",
"datasources",
";",
"}"
] | Stores the controller data sources
@param array A new data source list
@throws HTML_QuickForm2_InvalidArgumentException if given array
contains something that is not a valid data source | [
"Stores",
"the",
"controller",
"data",
"sources"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Controller/SessionContainer.php#L143-L153 |
209,496 | matomo-org/matomo | libs/HTML/QuickForm2/Controller/SessionContainer.php | HTML_QuickForm2_Controller_SessionContainer.storeOpaque | public function storeOpaque($name, $value)
{
if (!array_key_exists('opaque', $this->data)) {
$this->data['opaque'] = array();
}
$this->data['opaque'][$name] = $value;
} | php | public function storeOpaque($name, $value)
{
if (!array_key_exists('opaque', $this->data)) {
$this->data['opaque'] = array();
}
$this->data['opaque'][$name] = $value;
} | [
"public",
"function",
"storeOpaque",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'opaque'",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"'opaque'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"'opaque'",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Stores some user-supplied parameter alongside controller data
It is sometimes useful to pass some additional user data between pages
of the form, thus this method. It will be removed with all the other
data by {@link HTML_QuickForm2_Controller::destroySessionContainer()}
@param string Parameter name
@param string Parameter value | [
"Stores",
"some",
"user",
"-",
"supplied",
"parameter",
"alongside",
"controller",
"data"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Controller/SessionContainer.php#L175-L181 |
209,497 | matomo-org/matomo | libs/HTML/QuickForm2/Controller/SessionContainer.php | HTML_QuickForm2_Controller_SessionContainer.getOpaque | public function getOpaque($name)
{
return (array_key_exists('opaque', $this->data)
&& array_key_exists($name, $this->data['opaque']))
? $this->data['opaque'][$name]: null;
} | php | public function getOpaque($name)
{
return (array_key_exists('opaque', $this->data)
&& array_key_exists($name, $this->data['opaque']))
? $this->data['opaque'][$name]: null;
} | [
"public",
"function",
"getOpaque",
"(",
"$",
"name",
")",
"{",
"return",
"(",
"array_key_exists",
"(",
"'opaque'",
",",
"$",
"this",
"->",
"data",
")",
"&&",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"data",
"[",
"'opaque'",
"]",
")",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"'opaque'",
"]",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Returns a user-supplied parameter
@param string Parameter name
@return mixed | [
"Returns",
"a",
"user",
"-",
"supplied",
"parameter"
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/libs/HTML/QuickForm2/Controller/SessionContainer.php#L189-L194 |
209,498 | matomo-org/matomo | core/Columns/Dimension.php | Dimension.getMetricId | public function getMetricId()
{
if (!empty($this->metricId)) {
return $this->metricId;
}
$id = $this->getId();
return str_replace(array('.', ' ', '-'), '_', strtolower($id));
} | php | public function getMetricId()
{
if (!empty($this->metricId)) {
return $this->metricId;
}
$id = $this->getId();
return str_replace(array('.', ' ', '-'), '_', strtolower($id));
} | [
"public",
"function",
"getMetricId",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"metricId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"metricId",
";",
"}",
"$",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"return",
"str_replace",
"(",
"array",
"(",
"'.'",
",",
"' '",
",",
"'-'",
")",
",",
"'_'",
",",
"strtolower",
"(",
"$",
"id",
")",
")",
";",
"}"
] | Get the metricId which is used to generate metric names based on this dimension.
@return string | [
"Get",
"the",
"metricId",
"which",
"is",
"used",
"to",
"generate",
"metric",
"names",
"based",
"on",
"this",
"dimension",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Columns/Dimension.php#L220-L229 |
209,499 | matomo-org/matomo | core/Columns/Dimension.php | Dimension.getName | public function getName()
{
if (!empty($this->nameSingular)) {
return Piwik::translate($this->nameSingular);
}
return $this->nameSingular;
} | php | public function getName()
{
if (!empty($this->nameSingular)) {
return Piwik::translate($this->nameSingular);
}
return $this->nameSingular;
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"nameSingular",
")",
")",
"{",
"return",
"Piwik",
"::",
"translate",
"(",
"$",
"this",
"->",
"nameSingular",
")",
";",
"}",
"return",
"$",
"this",
"->",
"nameSingular",
";",
"}"
] | Returns the translated name of this dimension which is typically in singular.
@return string | [
"Returns",
"the",
"translated",
"name",
"of",
"this",
"dimension",
"which",
"is",
"typically",
"in",
"singular",
"."
] | 72df150735664275a60a7861e468c6ff3b152a14 | https://github.com/matomo-org/matomo/blob/72df150735664275a60a7861e468c6ff3b152a14/core/Columns/Dimension.php#L344-L351 |
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.