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