PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.7
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.7
5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / DataTable / Renderer / Console.php
matomo / app / core / DataTable / Renderer Last commit date
Console.php 2 years ago Csv.php 2 years ago Html.php 2 years ago Json.php 2 years ago Rss.php 2 years ago Tsv.php 2 years ago Xml.php 2 years ago
Console.php
150 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\DataTable\Renderer;
11
12 use Piwik\DataTable;
13 use Piwik\DataTable\Renderer;
14 /**
15 * Simple output
16 */
17 class Console extends Renderer
18 {
19 /**
20 * Prefix
21 *
22 * @var string
23 */
24 protected $prefixRows = '#';
25 /**
26 * Computes the dataTable output and returns the string/binary
27 *
28 * @return string
29 */
30 public function render()
31 {
32 return $this->renderTable($this->table);
33 }
34 /**
35 * Sets the prefix to be used
36 *
37 * @param string $str new prefix
38 */
39 public function setPrefixRow($str)
40 {
41 $this->prefixRows = $str;
42 }
43 /**
44 * Computes the output of the given array of data tables
45 *
46 * @param DataTable\Map $map data tables to render
47 * @param string $prefix prefix to output before table data
48 * @return string
49 */
50 protected function renderDataTableMap(DataTable\Map $map, $prefix)
51 {
52 $output = "Set<hr />";
53 $prefix = $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
54 foreach ($map->getDataTables() as $descTable => $table) {
55 $output .= $prefix . "<b>" . $descTable . "</b><br />";
56 $output .= $prefix . $this->renderTable($table, $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
57 $output .= "<hr />";
58 }
59 return $output;
60 }
61 /**
62 * Computes the given dataTable output and returns the string/binary
63 *
64 * @param DataTable $table data table to render
65 * @param string $prefix prefix to output before table data
66 * @return string
67 */
68 protected function renderTable($table, $prefix = "")
69 {
70 if (is_array($table)) {
71 // convert array to DataTable
72 $table = DataTable::makeFromSimpleArray($table);
73 }
74 if ($table instanceof DataTable\Map) {
75 return $this->renderDataTableMap($table, $prefix);
76 }
77 if ($table->getRowsCount() === 0) {
78 return "Empty table<br />\n";
79 }
80 static $depth = 0;
81 $output = '';
82 $i = 1;
83 foreach ($table->getRows() as $row) {
84 $dataTableMapBreak = false;
85 $columns = array();
86 foreach ($row->getColumns() as $column => $value) {
87 if ($value instanceof DataTable\Map) {
88 $output .= $this->renderDataTableMap($value, $prefix);
89 $dataTableMapBreak = true;
90 break;
91 }
92 if (is_string($value)) {
93 $value = "'{$value}'";
94 } elseif (is_array($value)) {
95 $value = var_export($value, true);
96 }
97 $columns[] = "'{$column}' => {$value}";
98 }
99 if ($dataTableMapBreak === true) {
100 continue;
101 }
102 $columns = implode(", ", $columns);
103 $metadata = array();
104 foreach ($row->getMetadata() as $name => $value) {
105 if (is_string($value)) {
106 $value = "'{$value}'";
107 } elseif (is_array($value)) {
108 $value = var_export($value, true);
109 }
110 $metadata[] = "'{$name}' => {$value}";
111 }
112 $metadata = implode(", ", $metadata);
113 $output .= str_repeat($this->prefixRows, $depth) . "- {$i} [" . $columns . "] [" . $metadata . "] [idsubtable = " . $row->getIdSubDataTable() . "]<br />\n";
114 if (!is_null($row->getIdSubDataTable())) {
115 $subTable = $row->getSubtable();
116 if ($subTable) {
117 $depth++;
118 $output .= $this->renderTable($subTable, $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
119 $depth--;
120 } else {
121 $output .= "-- Sub DataTable not loaded<br />\n";
122 }
123 }
124 $i++;
125 }
126 $metadata = $table->getAllTableMetadata();
127 if (!empty($metadata)) {
128 $output .= "<hr />Metadata<br />";
129 foreach ($metadata as $id => $metadataIn) {
130 $output .= "<br />";
131 $output .= $prefix . " <b>{$id}</b><br />";
132 if (is_array($metadataIn)) {
133 foreach ($metadataIn as $name => $value) {
134 if (is_object($value) && !method_exists($value, '__toString')) {
135 $value = 'Object [' . get_class($value) . ']';
136 } elseif (is_array($value)) {
137 $value = 'Array ' . json_encode($value);
138 }
139 if (is_array($value)) {
140 $value = json_encode($value);
141 }
142 $output .= $prefix . $prefix . "{$name} => {$value}";
143 }
144 }
145 }
146 }
147 return $output;
148 }
149 }
150