PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.2.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.2.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 1 year ago Csv.php 1 year ago Html.php 1 year ago Json.php 1 year ago Rss.php 1 year ago Tsv.php 2 years ago Xml.php 1 year ago
Console.php
149 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\DataTable\Renderer;
10
11 use Piwik\DataTable;
12 use Piwik\DataTable\Renderer;
13 /**
14 * Simple output
15 */
16 class Console extends Renderer
17 {
18 /**
19 * Prefix
20 *
21 * @var string
22 */
23 protected $prefixRows = '#';
24 /**
25 * Computes the dataTable output and returns the string/binary
26 *
27 * @return string
28 */
29 public function render()
30 {
31 return $this->renderTable($this->table);
32 }
33 /**
34 * Sets the prefix to be used
35 *
36 * @param string $str new prefix
37 */
38 public function setPrefixRow($str)
39 {
40 $this->prefixRows = $str;
41 }
42 /**
43 * Computes the output of the given array of data tables
44 *
45 * @param DataTable\Map $map data tables to render
46 * @param string $prefix prefix to output before table data
47 * @return string
48 */
49 protected function renderDataTableMap(DataTable\Map $map, $prefix)
50 {
51 $output = "Set<hr />";
52 $prefix = $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
53 foreach ($map->getDataTables() as $descTable => $table) {
54 $output .= $prefix . "<b>" . $descTable . "</b><br />";
55 $output .= $prefix . $this->renderTable($table, $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
56 $output .= "<hr />";
57 }
58 return $output;
59 }
60 /**
61 * Computes the given dataTable output and returns the string/binary
62 *
63 * @param DataTable $table data table to render
64 * @param string $prefix prefix to output before table data
65 * @return string
66 */
67 protected function renderTable($table, $prefix = "")
68 {
69 if (is_array($table)) {
70 // convert array to DataTable
71 $table = DataTable::makeFromSimpleArray($table);
72 }
73 if ($table instanceof DataTable\Map) {
74 return $this->renderDataTableMap($table, $prefix);
75 }
76 if ($table->getRowsCount() === 0) {
77 return "Empty table<br />\n";
78 }
79 static $depth = 0;
80 $output = '';
81 $i = 1;
82 foreach ($table->getRows() as $row) {
83 $dataTableMapBreak = \false;
84 $columns = array();
85 foreach ($row->getColumns() as $column => $value) {
86 if ($value instanceof DataTable\Map) {
87 $output .= $this->renderDataTableMap($value, $prefix);
88 $dataTableMapBreak = \true;
89 break;
90 }
91 if (is_string($value)) {
92 $value = "'{$value}'";
93 } elseif (is_array($value)) {
94 $value = var_export($value, \true);
95 }
96 $columns[] = "'{$column}' => {$value}";
97 }
98 if ($dataTableMapBreak === \true) {
99 continue;
100 }
101 $columns = implode(", ", $columns);
102 $metadata = array();
103 foreach ($row->getMetadata() as $name => $value) {
104 if (is_string($value)) {
105 $value = "'{$value}'";
106 } elseif (is_array($value)) {
107 $value = var_export($value, \true);
108 }
109 $metadata[] = "'{$name}' => {$value}";
110 }
111 $metadata = implode(", ", $metadata);
112 $output .= str_repeat($this->prefixRows, $depth) . "- {$i} [" . $columns . "] [" . $metadata . "] [idsubtable = " . $row->getIdSubDataTable() . "]<br />\n";
113 if (!is_null($row->getIdSubDataTable())) {
114 $subTable = $row->getSubtable();
115 if ($subTable) {
116 $depth++;
117 $output .= $this->renderTable($subTable, $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
118 $depth--;
119 } else {
120 $output .= "-- Sub DataTable not loaded<br />\n";
121 }
122 }
123 $i++;
124 }
125 $metadata = $table->getAllTableMetadata();
126 if (!empty($metadata)) {
127 $output .= "<hr />Metadata<br />";
128 foreach ($metadata as $id => $metadataIn) {
129 $output .= "<br />";
130 $output .= $prefix . " <b>{$id}</b><br />";
131 if (is_array($metadataIn)) {
132 foreach ($metadataIn as $name => $value) {
133 if (is_object($value) && !method_exists($value, '__toString')) {
134 $value = 'Object [' . get_class($value) . ']';
135 } elseif (is_array($value)) {
136 $value = 'Array ' . json_encode($value);
137 }
138 if (is_array($value)) {
139 $value = json_encode($value);
140 }
141 $output .= $prefix . $prefix . "{$name} => {$value}";
142 }
143 }
144 }
145 }
146 return $output;
147 }
148 }
149