diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-07-31 01:31:17 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-07-31 01:31:17 +0400 |
commit | c35e613b7ff66c6c86a712f0fd3250692ed9d8a9 (patch) | |
tree | 4e56d45743fc85f80014518e5c5bd419cc4a8f7b /plugins | |
parent | 765be0dc8f92a6d4bb3e678a0c23f2d4b95e0e18 (diff) | |
parent | 13f657ccfa6b58864291a173a0849d7169b031b2 (diff) |
Merge branch 'master' into php-5.3-namespaces
Conflicts:
core/Access.php
core/Config.php
core/EventDispatcher.php
core/JqplotDataGenerator/Evolution.php
core/Piwik.php
core/Plugin/MetadataLoader.php
core/ViewDataTable.php
core/ViewDataTable/Cloud.php
core/ViewDataTable/GenerateGraphHTML.php
core/ViewDataTable/HtmlTable.php
core/ViewDataTable/HtmlTable/AllColumns.php
core/ViewDataTable/HtmlTable/Goals.php
plugins/Actions/Controller.php
plugins/CoreHome/Controller.php
plugins/CoreHome/DataTableRowAction/RowEvolution.php
plugins/CoreHome/templates/_dataTable.twig
plugins/CustomVariables/Controller.php
plugins/DBStats/Controller.php
plugins/DevicesDetection/Controller.php
plugins/ExampleUI/Controller.php
plugins/Goals/Controller.php
plugins/Live/Controller.php
plugins/Provider/Controller.php
plugins/Referers/Controller.php
plugins/UserCountry/Controller.php
plugins/UserCountryMap/Controller.php
plugins/UserSettings/Archiver.php
plugins/UserSettings/Controller.php
plugins/VisitTime/Controller.php
plugins/VisitTime/VisitTime.php
plugins/VisitorInterest/Controller.php
plugins/VisitsSummary/Controller.php
tests/PHPUnit/proxy/index.php
Diffstat (limited to 'plugins')
65 files changed, 1991 insertions, 1360 deletions
diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php index fdc75d1891..f7bcef4b1f 100644 --- a/plugins/Actions/Actions.php +++ b/plugins/Actions/Actions.php @@ -627,27 +627,21 @@ class Piwik_Actions extends Plugin } } - public function getReportDisplayProperties(&$properties, $apiAction) + public function getReportDisplayProperties(&$properties) { - $reportViewProperties = array( - 'Actions.getPageUrls' => $this->getDisplayPropertiesForPageUrls(), - 'Actions.getEntryPageUrls' => $this->getDisplayPropertiesForEntryPageUrls(), - 'Actions.getExitPageUrls' => $this->getDisplayPropertiesForExitPageUrls(), - 'Actions.getSiteSearchKeywords' => $this->getDisplayPropertiesForSiteSearchKeywords(), - 'Actions.getSiteSearchNoResultKeywords' => $this->getDisplayPropertiesForSiteSearchNoResultKeywords(), - 'Actions.getSiteSearchCategories' => $this->getDisplayPropertiesForSiteSearchCategories(), - 'Actions.getPageUrlsFollowingSiteSearch' => $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(false), - 'Actions.getPageTitlesFollowingSiteSearch' => $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(true), - 'Actions.getPageTitles' => $this->getDisplayPropertiesForGetPageTitles(), - 'Actions.getEntryPageTitles' => $this->getDisplayPropertiesForGetEntryPageTitles(), - 'Actions.getExitPageTitles' => $this->getDisplayPropertiesForGetExitPageTitles(), - 'Actions.getDownloads' => $this->getDisplayPropertiesForGetDownloads(), - 'Actions.getOutlinks' => $this->getDisplayPropertiesForGetOutlinks(), - ); - - if (isset($reportViewProperties[$apiAction])) { - $properties = $reportViewProperties[$apiAction]; - } + $properties['Actions.getPageUrls'] = $this->getDisplayPropertiesForPageUrls(); + $properties['Actions.getEntryPageUrls'] = $this->getDisplayPropertiesForEntryPageUrls(); + $properties['Actions.getExitPageUrls'] = $this->getDisplayPropertiesForExitPageUrls(); + $properties['Actions.getSiteSearchKeywords'] = $this->getDisplayPropertiesForSiteSearchKeywords(); + $properties['Actions.getSiteSearchNoResultKeywords'] = $this->getDisplayPropertiesForSiteSearchNoResultKeywords(); + $properties['Actions.getSiteSearchCategories'] = $this->getDisplayPropertiesForSiteSearchCategories(); + $properties['Actions.getPageUrlsFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(false); + $properties['Actions.getPageTitlesFollowingSiteSearch'] = $this->getDisplayPropertiesForGetPageUrlsOrTitlesFollowingSiteSearch(true); + $properties['Actions.getPageTitles'] = $this->getDisplayPropertiesForGetPageTitles(); + $properties['Actions.getEntryPageTitles'] = $this->getDisplayPropertiesForGetEntryPageTitles(); + $properties['Actions.getExitPageTitles'] = $this->getDisplayPropertiesForGetExitPageTitles(); + $properties['Actions.getDownloads'] = $this->getDisplayPropertiesForGetDownloads(); + $properties['Actions.getOutlinks'] = $this->getDisplayPropertiesForGetOutlinks(); } private function addBaseDisplayProperties(&$result) diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php index 8d52088cae..52539d400e 100644 --- a/plugins/CoreHome/Controller.php +++ b/plugins/CoreHome/Controller.php @@ -134,20 +134,11 @@ class Piwik_CoreHome_Controller extends Controller // evolution of a singe or multiple rows in a data table // -------------------------------------------------------- - /** - * This static cache is necessary because the signature cannot be modified - * if the method renders a ViewDataTable. So we use it to pass information - * to getRowEvolutionGraph() - * @var Piwik_CoreHome_DataTableAction_Evolution - */ - private static $rowEvolutionCache = null; - /** Render the entire row evolution popover for a single row */ public function getRowEvolutionPopover() { $rowEvolution = $this->makeRowEvolution($isMulti = false); - self::$rowEvolutionCache = $rowEvolution; - $view = new View('@CoreHome/getRowEvolutionPopover'); + $view = new Piwik_View('@CoreHome/getRowEvolutionPopover'); echo $rowEvolution->renderPopover($this, $view); } @@ -155,22 +146,19 @@ class Piwik_CoreHome_Controller extends Controller public function getMultiRowEvolutionPopover() { $rowEvolution = $this->makeRowEvolution($isMulti = true); - self::$rowEvolutionCache = $rowEvolution; - $view = new View('@CoreHome/getMultiRowEvolutionPopover'); + $view = new Piwik_View('@CoreHome/getMultiRowEvolutionPopover'); echo $rowEvolution->renderPopover($this, $view); } /** Generic method to get an evolution graph or a sparkline for the row evolution popover */ - public function getRowEvolutionGraph($fetch = false) + public function getRowEvolutionGraph($fetch = false, $rowEvolution = null) { - $rowEvolution = self::$rowEvolutionCache; - if ($rowEvolution === null) { + if (empty($rowEvolution)) { $paramName = Piwik_CoreHome_DataTableRowAction_MultiRowEvolution::IS_MULTI_EVOLUTION_PARAM; $isMultiRowEvolution = Common::getRequestVar($paramName, false, 'int'); $rowEvolution = $this->makeRowEvolution($isMultiRowEvolution, $graphType = 'graphEvolution'); $rowEvolution->useAvailableMetrics(); - self::$rowEvolutionCache = $rowEvolution; } $view = $rowEvolution->getRowEvolutionGraph(); diff --git a/plugins/CoreHome/CoreHome.php b/plugins/CoreHome/CoreHome.php index 75d50a2f2e..003cf6ee91 100644 --- a/plugins/CoreHome/CoreHome.php +++ b/plugins/CoreHome/CoreHome.php @@ -49,6 +49,7 @@ class Piwik_CoreHome extends Plugin $cssFiles[] = "plugins/CoreHome/stylesheets/jquery.ui.autocomplete.css"; $cssFiles[] = "plugins/CoreHome/stylesheets/jqplot.css"; $cssFiles[] = "plugins/CoreHome/stylesheets/promo.less"; + $cssFiles[] = "plugins/CoreHome/stylesheets/color_manager.css"; } public function getJsFiles(&$jsFiles) @@ -77,6 +78,7 @@ class Piwik_CoreHome extends Plugin $jsFiles[] = "plugins/CoreHome/javascripts/jqplot.js"; $jsFiles[] = "libs/jqplot/jqplot-custom.min.js"; $jsFiles[] = "plugins/CoreHome/javascripts/promo.js"; + $jsFiles[] = "plugins/CoreHome/javascripts/color_manager.js"; } } diff --git a/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php b/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php index bbfc80832f..fa6478c167 100644 --- a/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php +++ b/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php @@ -79,9 +79,9 @@ class Piwik_CoreHome_DataTableRowAction_MultiRowEvolution * * @return ViewDataTable */ - public function getRowEvolutionGraph() + public function getRowEvolutionGraph($graphType = false, $metrics = false) { - $view = parent::getRowEvolutionGraph(); + $view = parent::getRowEvolutionGraph($graphType, $metrics); $view->setCustomParameter(self::IS_MULTI_EVOLUTION_PARAM, 1); // set in JS return $view; } diff --git a/plugins/CoreHome/DataTableRowAction/RowEvolution.php b/plugins/CoreHome/DataTableRowAction/RowEvolution.php index 694a64c641..7b2c908bd1 100644 --- a/plugins/CoreHome/DataTableRowAction/RowEvolution.php +++ b/plugins/CoreHome/DataTableRowAction/RowEvolution.php @@ -99,7 +99,7 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution list($this->date, $lastN) = Piwik_ViewDataTable_GenerateGraphHTML_ChartEvolution::getDateRangeAndLastN($this->period, $end); } - $this->segment = ViewDataTable::getRawSegmentFromRequest(); + $this->segment = \Piwik\API\Request::getRawSegmentFromRequest(); $this->loadEvolutionReport(); } @@ -114,10 +114,10 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution // render main evolution graph $this->graphType = 'graphEvolution'; $this->graphMetrics = $this->availableMetrics; - $view->graph = $controller->getRowEvolutionGraph(true); + $view->graph = $controller->getRowEvolutionGraph($fetch = true, $rowEvolution = $this); // render metrics overview - $view->metrics = $this->getMetricsToggles($controller); + $view->metrics = $this->getMetricsToggles(); // available metrics text $metricsText = Piwik_Translate('RowEvolution_AvailableMetrics'); @@ -180,40 +180,39 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution * Do as much as possible from outside the controller. * @return ViewDataTable */ - public function getRowEvolutionGraph() + public function getRowEvolutionGraph($graphType = false, $metrics = false) { // set up the view data table - $view = ViewDataTable::factory($this->graphType); + $view = ViewDataTable::factory( + $graphType ?: $this->graphType, $this->apiMethod, $controllerAction = 'CoreHome.getRowEvolutionGraph'); $view->setDataTable($this->dataTable); - $view->init('CoreHome', 'getRowEvolutionGraph', $this->apiMethod); - if (!empty($this->graphMetrics)) // In row Evolution popover, this is empty - { - $view->setColumnsToDisplay(array_keys($this->graphMetrics)); + if (!empty($this->graphMetrics)) { // In row Evolution popover, this is empty + $view->columns_to_display = array_keys($metrics ?: $this->graphMetrics); } - $view->hideAllViewsIcons(); + + $view->show_all_views_icons = false; + $view->show_active_view_icon = false; + $view->show_related_reports = false; foreach ($this->availableMetrics as $metric => $metadata) { - $view->setColumnTranslation($metric, $metadata['name']); + $view->translations[$metric] = $metadata['name']; } - if (method_exists($view, 'addRowEvolutionSeriesToggle')) { - $view->addRowEvolutionSeriesToggle($this->initiallyShowAllMetrics); - } + $view->external_series_toggle = 'RowEvolutionSeriesToggle'; + $view->external_series_toggle_show_all = $this->initiallyShowAllMetrics; return $view; } /** * Prepare metrics toggles with spark lines - * @param $controller * @return array */ - protected function getMetricsToggles($controller) + protected function getMetricsToggles() { $chart = new Piwik_Visualization_Chart_Evolution; - $colors = $chart->getSeriesColors(); - + $i = 0; $metrics = array(); foreach ($this->availableMetrics as $metric => $metricData) { @@ -247,12 +246,10 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution $details .= ', ' . Piwik_Translate('RowEvolution_MetricChangeText', $change); } - $color = $colors[$i % count($colors)]; $newMetric = array( 'label' => $metricData['name'], - 'color' => $color, 'details' => $details, - 'sparkline' => $this->getSparkline($metric, $controller), + 'sparkline' => $this->getSparkline($metric), ); // Multi Rows, each metric can be for a particular row and display an icon if (!empty($metricData['logo'])) { @@ -266,14 +263,14 @@ class Piwik_CoreHome_DataTableRowAction_RowEvolution } /** Get the img tag for a sparkline showing a single metric */ - protected function getSparkline($metric, $controller) + protected function getSparkline($metric) { - $this->graphType = 'sparkline'; - $this->graphMetrics = array($metric => $metric); - // sparkline is always echoed, so we need to buffer the output + $view = $this->getRowEvolutionGraph($graphType = 'sparkline', $metrics = array($metric => $metric)); + $view->main(); + ob_start(); - $controller->getRowEvolutionGraph(); + $view->getView()->render(); $spark = ob_get_contents(); ob_end_clean(); diff --git a/plugins/CoreHome/javascripts/color_manager.js b/plugins/CoreHome/javascripts/color_manager.js new file mode 100644 index 0000000000..cfdc26bbff --- /dev/null +++ b/plugins/CoreHome/javascripts/color_manager.js @@ -0,0 +1,132 @@ +/*! + * Piwik - Web Analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +(function ($) { + + /** + * The ColorManager class allows JS code to grab colors defined in CSS for + * components that don't manage HTML (like jqPlot or sparklines). Such components + * can't use CSS colors directly since the colors are used to generate images + * or by <canvas> elements. + * + * Colors obtained via ColorManager are defined in CSS like this: + * + * .my-color-namespace[data-name=color-name] { + * color: #fff + * } + * + * and can be accessed in JavaScript like this: + * + * piwik.ColorManager.getColor("my-color-namespace", "color-name"); + * + * The singleton instance of this class can be accessed via piwik.ColorManager. + */ + var ColorManager = function () { + // empty + }; + + ColorManager.prototype = { + + /** + * Returns the color for a namespace and name. + * + * @param {String} namespace The string identifier that groups related colors + * together. For example, 'sparkline-colors'. + * @param {String} name The name of the color to retrieve. For example, 'lineColor'. + * @return {String} A hex color, eg, '#fff'. + */ + getColor: function (namespace, name) { + var element = this._getElement(); + + element.attr('class', 'color-manager ' + namespace).attr('data-name', name); + return this._normalizeColor(element.css('color')); + }, + + /** + * Returns the colors for a namespace and a list of names. + * + * @param {String} namespace The string identifier that groups related colors + * together. For example, 'sparkline-colors'. + * @param {Array} names An array of color names to retrieve. + * @param {Boolean} asArray Whether the result should be an array or an object. + * @return {Object|Array} An object mapping color names with color values or an + * array of colors. + */ + getColors: function (namespace, names, asArray) { + var colors = asArray ? [] : {}; + for (var i = 0; i != names.length; ++i) { + var name = names[i], + color = this.getColor(namespace, name); + if (color) { + if (asArray) { + colors.push(color); + } else { + colors[name] = color; + } + } + } + return colors; + }, + + /** + * Turns a color string that might be an rgb value rgb(12, 34, 56) into + * a hex color string. + */ + _normalizeColor: function (color) { + if (color == this._getTransparentColor()) { + return null; + } + + if (color + && color[0] != '#' + ) { + // parse rgb(#, #, #) and get rgb numbers + var parts = color.split(/[()rgb,\s]+/); + parts = [+parts[1], +parts[2], +parts[3]]; + + // convert parts to hex with one leading 0 + for (var i = 0; i != parts.length; ++i) { + parts[i] = ("00" + parts[i].toString(16)).slice(-2); + } + + // create hex string + color = '#' + parts.join(''); + } + return color; + }, + + /** + * Returns the manufactured <div> element used to obtain color data. When + * getting color data the class and data-name attribute of this element are + * changed. + */ + _getElement: function () { + if (!this.$element) { + $('body').append('<div id="color-manager"></div>'); + this.$element = $('#color-manager'); + } + + return this.$element; + }, + + /** + * Returns this browser's representation of the 'transparent' color. Used to + * compare against colors obtained in getColor. If a color is 'transparent' + * it means there's no color for that namespace/name combination. + */ + _getTransparentColor: function () { + if (!this.transparentColor) { + this.transparentColor = $('<div style="color:transparent;"></div>').appendTo($('body')).css('color'); + } + + return this.transparentColor; + } + }; + + piwik.ColorManager = new ColorManager(); + +}(jQuery)); diff --git a/plugins/CoreHome/javascripts/datatable.js b/plugins/CoreHome/javascripts/datatable.js index 82b9ab5df6..bf85c07d1c 100644 --- a/plugins/CoreHome/javascripts/datatable.js +++ b/plugins/CoreHome/javascripts/datatable.js @@ -532,7 +532,7 @@ dataTable.prototype = // set position of evolution annotation icons annotations.css({ top: -datatableFeatures.height() - annotationAxisHeight + noteSize / 2, - left: 6 // padding-left of .jqplot-evolution element (in graph.tpl) + left: 6 // padding-left of .jqplot-graph element (in _dataTableViz_jqplotGraph.tpl) }); piwik.annotations.placeEvolutionIcons(annotations, domElem); diff --git a/plugins/CoreHome/javascripts/datatable_manager.js b/plugins/CoreHome/javascripts/datatable_manager.js index 5db471eb18..a1ea816484 100644 --- a/plugins/CoreHome/javascripts/datatable_manager.js +++ b/plugins/CoreHome/javascripts/datatable_manager.js @@ -131,7 +131,7 @@ // render the graph (setTimeout is required, otherwise the graph will not // render initially) setTimeout(function () { - plot.render(graphElement.attr('data-graph-type'), graphId, { + plot.render(graphId, { noData: _pk_translate('General_NoDataForGraph_js'), exportTitle: _pk_translate('General_ExportAsImage_js'), exportText: _pk_translate('General_SaveImageOnYourComputer_js'), diff --git a/plugins/CoreHome/javascripts/datatable_rowactions.js b/plugins/CoreHome/javascripts/datatable_rowactions.js index 233fa34683..ab5fb7b7b2 100644 --- a/plugins/CoreHome/javascripts/datatable_rowactions.js +++ b/plugins/CoreHome/javascripts/datatable_rowactions.js @@ -376,6 +376,7 @@ DataTable_RowActions_RowEvolution.prototype.showRowEvolution = function (apiMeth requestParams.module = 'CoreHome'; requestParams.action = action; + requestParams.colors = JSON.stringify(piwik.getSparklineColors()); var ajaxRequest = new ajaxHelper(); ajaxRequest.addParams(requestParams, 'get'); diff --git a/plugins/CoreHome/javascripts/jqplot.js b/plugins/CoreHome/javascripts/jqplot.js index d77d7f582f..5153b19a26 100644 --- a/plugins/CoreHome/javascripts/jqplot.js +++ b/plugins/CoreHome/javascripts/jqplot.js @@ -8,7 +8,6 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ - /** * Constructor function * @@ -27,33 +26,31 @@ JQPlot.prototype = { this.originalData = data; this.data = data.data; - defaultParams = {}; - defaultParams.grid = { - drawGridLines: false, - background: '#fff', - borderColor: '#f00', - borderWidth: 0, - shadow: false - }; - - defaultParams.title = { - show: false - }; - - defaultParams.axesDefaults = { - pad: 1.0, - tickRenderer: $.jqplot.CanvasAxisTickRenderer, - tickOptions: { - showMark: false, - fontSize: '11px', - fontFamily: 'Arial' + defaultParams = { + grid: { + drawGridLines: false, + borderWidth: 0, + shadow: false }, - rendererOptions: { - drawBaseline: false + title: { + show: false + }, + axesDefaults: { + pad: 1.0, + tickRenderer: $.jqplot.CanvasAxisTickRenderer, + tickOptions: { + showMark: false, + fontSize: '11px', + fontFamily: 'Arial' + }, + rendererOptions: { + drawBaseline: false + } } }; this.params = $.extend(true, {}, defaultParams, data.params); + this._setColors(); this.tooltip = data.tooltip; this.seriesPicker = data.seriesPicker; @@ -61,6 +58,7 @@ JQPlot.prototype = { if (typeof this.params.axes.yaxis == 'undefined') { this.params.axes.yaxis = {}; } + if (typeof this.params.axes.yaxis.tickOptions == 'undefined') { this.params.yaxis.tickOptions = { formatString: '%d' @@ -69,16 +67,18 @@ JQPlot.prototype = { }, /** Generic render function */ - render: function (type, targetDivId, lang) { + render: function (targetDivId, lang) { + var type = $('#' + targetDivId).closest('div.dataTable').data('dataTableInstance').param['viewDataTable']; + // preapare the appropriate chart type switch (type) { - case 'evolution': + case 'graphEvolution': this.prepareEvolutionChart(targetDivId, lang); break; - case 'bar': + case 'graphVerticalBar': this.prepareBarChart(targetDivId, lang); break; - case 'pie': + case 'graphPie': this.preparePieChart(targetDivId, lang); break; default: @@ -100,7 +100,7 @@ JQPlot.prototype = { this.innerHTML = ''; } - (new JQPlot(data, self.dataTableId)).render(type, targetDivId, lang); + (new JQPlot(data, self.dataTableId)).render(targetDivId, lang); }); // show loading @@ -217,7 +217,7 @@ JQPlot.prototype = { plotWidth = width; target.trigger('piwikDestroyPlot'); (new JQPlot(self.originalData, self.dataTableId)) - .render(type, targetDivId, lang); + .render(targetDivId, lang); } }); var resizeListener = function () { @@ -302,26 +302,26 @@ JQPlot.prototype = { }); var popover = $(document.createElement('div')); - - popover.append('<div style="font-size: 13px; margin-bottom: 10px;">' + + popover.append('<div style="font-size: 13px; margin-bottom: 10px;">' + lang.exportText + '</div>').append($(img)) - - popover.dialog({ - title: lang.exportTitle, - modal: true, - width: 'auto', - position: ['center', 'center'], - resizable: false, - autoOpen: true, - open: function (event, ui) { - $('.ui-widget-overlay').on('click.popover', function () { - popover.dialog('close'); - }); - }, - close: function (event, ui) { - $(this).dialog("destroy").remove(); - } - }); + + popover.dialog({ + title: lang.exportTitle, + modal: true, + width: 'auto', + position: ['center', 'center'], + resizable: false, + autoOpen: true, + open: function (event, ui) { + $('.ui-widget-overlay').on('click.popover', function () { + popover.dialog('close'); + }); + }, + close: function (event, ui) { + $(this).dialog("destroy").remove(); + } + }); }, @@ -355,7 +355,8 @@ JQPlot.prototype = { defaultParams.piwikTicks = { showTicks: true, showGrid: true, - showHighlight: true + showHighlight: true, + tickColor: this.tickColor }; this.params = $.extend(true, {}, defaultParams, this.params); @@ -433,18 +434,21 @@ JQPlot.prototype = { this.params.piwikTicks = { showTicks: false, showGrid: false, - showHighlight: false + showHighlight: false, + tickColor: this.tickColor }; this.params.legend = { show: false }; this.params.pieLegend = { - show: true + show: true, + labelColor: this.singleMetricColor }; this.params.canvasLegend = { show: true, - singleMetric: true + singleMetric: true, + singleMetricColor: this.singleMetricColor }; // pie charts have a different data format @@ -477,7 +481,8 @@ JQPlot.prototype = { this.params.piwikTicks = { showTicks: true, showGrid: false, - showHighlight: false + showHighlight: false, + tickColor: this.tickColor }; this.params.axes.xaxis.renderer = $.jqplot.CategoryAxisRenderer; @@ -592,8 +597,35 @@ JQPlot.prototype = { this.data = [this.data[0]]; this.params.series = [this.params.series[0]]; } - } + }, + /** + * Sets the colors used to render this graph. + */ + _setColors: function () { + var colorManager = piwik.ColorManager, + seriesColorNames = ['series1', 'series2', 'series3', 'series4', 'series5', + 'series6', 'series7', 'series8', 'series9', 'series10']; + + var viewDataTable = $('#' + this.dataTableId).data('dataTableInstance').param['viewDataTable']; + + var graphType; + if (viewDataTable == 'graphEvolution') { + graphType = 'evolution'; + } else if (viewDataTable == 'graphPie') { + graphType = 'pie'; + } else if (viewDataTable == 'graphVerticalBar') { + graphType = 'bar'; + } + + var namespace = graphType + '-graph-colors'; + + this.params.seriesColors = colorManager.getColors(namespace, seriesColorNames, true); + this.params.grid.background = colorManager.getColor(namespace, 'grid-background'); + this.params.grid.borderColor = colorManager.getColor(namespace, 'grid-border'); + this.tickColor = colorManager.getColor(namespace, 'ticks'); + this.singleMetricColor = colorManager.getColor(namespace, 'single-metric-label') + } }; @@ -831,7 +863,7 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () { for (var i = 0; i < ticks.length; i++) { var pos = Math.round(i * tickWidth + tickWidth / 2); var full = xaxisLabels[i] && xaxisLabels[i] != ' '; - drawLine(ctx, pos, full, c.showGrid); + drawLine(ctx, pos, full, c.showGrid, c.tickColor); } } }; @@ -840,9 +872,9 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () { $.jqplot.postDrawHooks.push($.jqplot.PiwikTicks.postDraw); // draw a 1px line - function drawLine(ctx, x, full, showGrid) { + function drawLine(ctx, x, full, showGrid, color) { ctx.save(); - ctx.strokeStyle = '#cccccc'; + ctx.strokeStyle = color; ctx.beginPath(); ctx.lineWidth = 2; @@ -987,7 +1019,7 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () { ctx.fillStyle = s.color; if (legend.singleMetric) { - ctx.fillStyle = '#666666'; + ctx.fillStyle = legend.singleMetricColor; } ctx.fillRect(x, 10, 10, 2); @@ -1387,7 +1419,7 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () { var x = x2 - 9 - ctx.measureText(label).width; } - ctx.fillStyle = '#666666'; + ctx.fillStyle = legend.labelColor; ctx.fillText(label, x, y2 + 3); } diff --git a/plugins/CoreHome/javascripts/sparkline.js b/plugins/CoreHome/javascripts/sparkline.js index 712dd0e7a5..6093955eeb 100644 --- a/plugins/CoreHome/javascripts/sparkline.js +++ b/plugins/CoreHome/javascripts/sparkline.js @@ -5,7 +5,29 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -function initializeSparklines() { +(function ($) { + +var sparklineColorNames = ['lineColor', 'red', 'blue', 'green']; + +piwik.getSparklineColors = function () { + return piwik.ColorManager.getColors('sparkline-colors', sparklineColorNames); +}; + +// initializes each sparkline so they use colors defined in CSS +piwik.initSparklines = function () { + $('img.sparkline').each(function () { + var $self = $(this); + + if ($self.attr('src')) { + return; + } + + var colors = JSON.stringify(piwik.getSparklineColors()); + $self.attr('src', $self.attr('data-src') + '&colors=' + encodeURIComponent(colors)); + }); +}; + +window.initializeSparklines = function () { var sparklineUrlParamsToIgnore = ['module', 'action', 'idSite', 'period', 'date', 'viewDataTable']; $("[data-graph-id]").each(function () { @@ -14,7 +36,7 @@ function initializeSparklines() { // try to find sparklines and add them clickable behaviour graph.parent().find('div.sparkline').each(function () { // find the sparkline and get it's src attribute - var sparklineUrl = $('img.sparkline', this).attr('src'); + var sparklineUrl = $('img.sparkline', this).attr('data-src'); if (sparklineUrl != "") { var params = broadcast.getValuesFromUrl(sparklineUrl); @@ -32,32 +54,23 @@ function initializeSparklines() { // on click, reload the graph with the new url $(this).click(function () { - var idDataTable = graph.attr('data-graph-id'), - dataTable = $('#' + idDataTable); + var reportId = graph.attr('data-graph-id'), + dataTable = $(piwik.DataTableManager.getDataTableByReport(reportId)); // when the metrics picker is used, the id of the data table might be updated (which is correct behavior). // for example, in goal reports it might change from GoalsgetEvolutionGraph to GoalsgetEvolutionGraph1. // if this happens, we can't find the graph using $('#'+idDataTable+"Chart"); // instead, we just use the first evolution graph we can find. if (dataTable.length == 0) { - dataTable = $('div.dataTableGraphEvolutionWrapper').first().closest('.dataTable'); + dataTable = $('div.dataTableEvolutionGraph'); } // reload the datatable w/ a new column & scroll to the graph dataTable.trigger('reload', params); }); - $(this).hover( - function () { - $(this).css({ - "cursor": "pointer", - "border-bottom": "1px dashed #C3C3C3" - }); - }, - function () { - $(this).css({"border-bottom": "1px solid white"}); - } - ); } }); }); -} +}; + +}(jQuery)); diff --git a/plugins/CoreHome/stylesheets/cloud.less b/plugins/CoreHome/stylesheets/cloud.less index b17741e1cf..2d490de3d0 100644 --- a/plugins/CoreHome/stylesheets/cloud.less +++ b/plugins/CoreHome/stylesheets/cloud.less @@ -1,56 +1,55 @@ .tagCloud { padding: 10px; -} - -.tagCloud img { - border: 0; -} - -.tagCloud .word a { - text-decoration: none; -} - -.tagCloud .word { - padding: 4px 8px 4px 0; - white-space: nowrap; -} - -.tagCloud .valueIsZero { - text-decoration: line-through; -} - -.tagCloud span.size0, .tagCloud span.size0 a { - color: #255792; - font-size: 28px; -} - -.tagCloud span.size1, .tagCloud span.size1 a { - color: #255792; - font-size: 24px; -} - -.tagCloud span.size2, .tagCloud span.size2 a { - color: #255792; - font-size: 20px; -} - -.tagCloud span.size3, .tagCloud span.size3 a { - color: #255792; - font-size: 16px; -} - -.tagCloud span.size4, .tagCloud span.size4 a { - color: #255792; - font-size: 15px; -} - -.tagCloud span.size5, .tagCloud span.size5 a { - color: #255792; - font-size: 14px; -} - -.tagCloud span.size6, .tagCloud span.size6 a { - color: #255792; - font-size: 11px; -} + img { + border: 0; + } + + .word a { + text-decoration: none; + } + + .word { + padding: 4px 8px 4px 0; + white-space: nowrap; + } + + .valueIsZero { + text-decoration: line-through; + } + + span.size0, span.size0 a { + color: #255792; + font-size: 28px; + } + + span.size1, span.size1 a { + color: #255792; + font-size: 24px; + } + + span.size2, span.size2 a { + color: #255792; + font-size: 20px; + } + + span.size3, span.size3 a { + color: #255792; + font-size: 16px; + } + + span.size4, span.size4 a { + color: #255792; + font-size: 15px; + } + + span.size5, span.size5 a { + color: #255792; + font-size: 14px; + } + + span.size6, span.size6 a { + color: #255792; + font-size: 11px; + } +}
\ No newline at end of file diff --git a/plugins/CoreHome/stylesheets/color_manager.css b/plugins/CoreHome/stylesheets/color_manager.css new file mode 100644 index 0000000000..725d3df59a --- /dev/null +++ b/plugins/CoreHome/stylesheets/color_manager.css @@ -0,0 +1,3 @@ +.color-manager { + color: transparent; +}
\ No newline at end of file diff --git a/plugins/CoreHome/stylesheets/dataTable.less b/plugins/CoreHome/stylesheets/dataTable.less index 8124a50586..04e82f539c 100644 --- a/plugins/CoreHome/stylesheets/dataTable.less +++ b/plugins/CoreHome/stylesheets/dataTable.less @@ -25,20 +25,17 @@ width: 95%; } -.dataTableGraphWrapper { +.dataTableGraph > .dataTableWrapper { width: 500px; min-height: 1px; } -.dataTableGraphEvolutionWrapper { +.dataTableEvolutionGraph > .dataTableWrapper { width: 100%; } /*Overriding some dataTable css for better dashboard display*/ -.widget .dataTableWrapper, -.widget .dataTableGraphWrapper, -.widget .dataTableActionsWrapper, -.widget .dataTableGraphEvolutionWrapper { +.widget .dataTableWrapper { width: 100%; } @@ -774,3 +771,11 @@ a.tableConfigurationIcon.highlighted { table.dataTable span.cell-tooltip { cursor: default; } + +.dataTable .jqplot-graph { + padding-left: 6px; + + > div { + position: relative; + } +}
\ No newline at end of file diff --git a/plugins/CoreHome/templates/_dataTable.twig b/plugins/CoreHome/templates/_dataTable.twig index 73eb6f1143..9aa0757f28 100644 --- a/plugins/CoreHome/templates/_dataTable.twig +++ b/plugins/CoreHome/templates/_dataTable.twig @@ -5,7 +5,7 @@ data-report="{{ properties.report_id }}" data-params="{{ javascriptVariablesToSet|json_encode }}"> <div class="reportDocumentation"> - {% if reportDocumentation|default is not empty %}<p>{{ reportDocumentation|raw }}</p>{% endif %} + {% if properties.documentation|default is not empty %}<p>{{ properties.documentation|raw }}</p>{% endif %} {% if properties.metadata.archived_date is defined %}<span class='helpDate'>{{ properties.metadata.archived_date }}</span>{% endif %} </div> <div class="dataTableWrapper"> @@ -21,33 +21,7 @@ {% endif %} </div> {% else %} - <table cellspacing="0" class="dataTable"> - {% include "@CoreHome/_dataTableHead.twig" %} - - <tbody> - {% for rowId, row in dataTable.getRows() %} - {%- set rowHasSubtable = row.getIdSubDataTable() and javascriptVariablesToSet.controllerActionCalledWhenRequestSubTable is not null -%} - {%- set shouldHighlightRow = rowId == summaryRowId and properties.highlight_summary_row -%} - - {# display this row if it doesn't have a subtable or if we don't replace the row with the subtable #} - {% if not rowHasSubtable or not properties.show_expanded|default(false) or not properties.replace_row_with_subtable|default(false) %} - <tr {% if rowHasSubtable %}id="{{ row.getIdSubDataTable() }}"{% endif %} - class="{{ row.getMetadata('css_class') }} {% if rowHasSubtable %}subDataTable{% endif %}{% if shouldHighlightRow %} highlight{% endif %}"> - {% for column in dataTableColumns %} - <td> - {% include "@CoreHome/_dataTableCell.twig" with properties %} - </td> - {% endfor %} - </tr> - {% endif %} - - {# display subtable if present and showing expanded datatable #} - {% if properties.show_expanded|default(false) and rowHasSubtable %} - {% include properties.subtable_template with {'dataTable': row.getSubtable()} %} - {% endif %} - {% endfor %} - </tbody> - </table> + {{ visualization.render(dataTable, properties)|raw }} {% endif %} {% if properties.show_footer %} diff --git a/plugins/CoreHome/templates/_dataTableActions_subDataTable.twig b/plugins/CoreHome/templates/_dataTableActions_subDataTable.twig index 4f4789d49e..72bf6607c1 100644 --- a/plugins/CoreHome/templates/_dataTableActions_subDataTable.twig +++ b/plugins/CoreHome/templates/_dataTableActions_subDataTable.twig @@ -3,7 +3,7 @@ {% else %} {% if (dataTable is empty or dataTable.getRowsCount() == 0) and not properties.show_expanded|default(false) %} <tr> - <td colspan="{{ nbColumns }}">{{ 'CoreHome_CategoryNoData'|translate }}</td> + <td colspan="{{ properties.columns_to_display|length }}">{{ 'CoreHome_CategoryNoData'|translate }}</td> </tr> {% else %} {% for row in dataTable.getRows() %} @@ -11,9 +11,9 @@ {% if not row.getIdSubDataTable() or not properties.show_expanded|default(false) or not properties.replace_row_with_subtable|default(false) %} <tr {% if row.getIdSubDataTable() %}id="{{ row.getIdSubDataTable() }}"{% endif %} class="{{ row.getMetadata('css_class') }} {% if row.getIdSubDataTable() %}subDataTable{% endif %}"> - {% for column in dataTableColumns %} + {% for column in properties.columns_to_display %} <td> - {% include "@CoreHome/_dataTableCell.twig" with {'column': column} %} + {% include "@CoreHome/_dataTableCell.twig" %} </td> {% endfor %} </tr> diff --git a/plugins/CoreHome/templates/_dataTableCell.twig b/plugins/CoreHome/templates/_dataTableCell.twig index 1d012d1248..4cd40ef68b 100644 --- a/plugins/CoreHome/templates/_dataTableCell.twig +++ b/plugins/CoreHome/templates/_dataTableCell.twig @@ -14,7 +14,7 @@ <span class='label{% if row.getMetadata('is_aggregate') %} highlighted{% endif %}' {% if properties is defined and properties.tooltip_metadata_name is not empty %}title="{{ row.getMetadata(properties.tooltip_metadata_name) }}"{% endif %}> {%- if row.getMetadata('html_label_suffix') %}<span class='label-suffix'>{{ row.getMetadata('html_label_suffix') | raw }}</span>{% endif -%} -{% endif %}{% if row.getColumn(column) %}{{- row.getColumn(column)|raw -}}{% else %}{{ defaultWhenColumnValueNotDefined }}{% endif %} +{% endif %}{% if row.getColumn(column) %}{{- row.getColumn(column)|raw -}}{% else %}-{% endif %} {% if column=='label' %}</span>{% endif %} {% if not row.getIdSubDataTable() and column=='label' and row.getMetadata('url') %} </a> diff --git a/plugins/CoreHome/templates/_dataTableCloud.twig b/plugins/CoreHome/templates/_dataTableCloud.twig deleted file mode 100644 index 4c70887307..0000000000 --- a/plugins/CoreHome/templates/_dataTableCloud.twig +++ /dev/null @@ -1,34 +0,0 @@ -<div class="dataTable" data-report="{{ properties.report_id }}" data-params="{{ javascriptVariablesToSet|json_encode }}"> - {% if reportDocumentation is not empty and javascriptVariablesToSet.viewDataTable != 'tableGoals' %} - <div class="reportDocumentation"><p>{{ reportDocumentation|raw }}</p></div> - {% endif %} - <div class="tagCloud"> - {% if cloudValues|length == 0 %} - {% if showReportDataWasPurgedMessage %} - <div class="pk-emptyDataTable">{{ 'General_DataForThisTagCloudHasBeenPurged'|translate(deleteReportsOlderThan) }}</div> - {% else %} - <div class="pk-emptyDataTable">{{ 'General_NoDataForTagCloud'|translate }}</div> - {% endif %} - {% else %} - {% for word,value in cloudValues %} - <span title="{{ value.word }} ({{ value.value }} {{ columnTranslation }})" class="word size{{ value.size }} - {# we strike tags with 0 hits #} - {% if value.value == 0 %}valueIsZero{% endif %}"> - {% if labelMetadata[value.word].url is not sameas(false) %} - <a href="{{ labelMetadata[value.word].url }}" target="_blank"> - {% endif %} - {% if labelMetadata[value.word].logo is not sameas(false) %} - <img src="{{ labelMetadata[value.word].logo }}" width="{{ value.logoWidth }}" /> - {% else %} - {{ value.wordTruncated }} - {% endif %} - {% if labelMetadata[value.word].url is not sameas(false) %}</a>{% endif %} - </span> - {% endfor %} - {% endif %} - </div> - {% if properties.show_footer %} - {% include "@CoreHome/_dataTableFooter.twig" %} - {% endif %} - {% include "@CoreHome/_dataTableJS.twig" %} -</div> diff --git a/plugins/CoreHome/templates/_dataTableFooter.twig b/plugins/CoreHome/templates/_dataTableFooter.twig index 8d6f1f1469..5a74cf4a74 100644 --- a/plugins/CoreHome/templates/_dataTableFooter.twig +++ b/plugins/CoreHome/templates/_dataTableFooter.twig @@ -24,7 +24,7 @@ {% if properties.show_footer_icons %} <div class="dataTableFooterIcons"> <div class="dataTableFooterWrap" var="{{ javascriptVariablesToSet.viewDataTable }}"> - {% if not properties.hide_all_views_icons %} + {% if properties.show_active_view_icon %} <img src="plugins/Zeitgeist/images/data_table_footer_active_item.png" class="dataTableFooterActiveItem"/> {% endif %} <div class="tableIconsGroup"> @@ -77,14 +77,6 @@ {% endif %} </span> </div> - {% elseif not properties.hide_all_views_icons and javascriptVariablesToSet.viewDataTable == "generateDataChartEvolution" %} - <div class="tableIconsGroup"> - <span class="tableGraphViews"> - <a class="tableIcon" format="graphEvolution" var="graphEvolution"> - <img width="16" height="16" src="plugins/Zeitgeist/images/chart_bar.png" title="{{ 'General_VBarGraph'|translate }}"/> - </a> - </span> - </div> {% endif %} <div class="tableIconsGroup"> <span class="exportToFormatIcons"> diff --git a/plugins/CoreHome/templates/_dataTableGraph.twig b/plugins/CoreHome/templates/_dataTableGraph.twig deleted file mode 100644 index 2ebd657959..0000000000 --- a/plugins/CoreHome/templates/_dataTableGraph.twig +++ /dev/null @@ -1,40 +0,0 @@ -<div class="dataTable" data-report="{{ properties.report_id }}" data-params="{{ javascriptVariablesToSet|json_encode }}"> - - <div class="reportDocumentation"> - {% if reportDocumentation is not empty %}<p>{{ reportDocumentation|raw }}</p>{% endif %} - {% if properties.metadata.archived_date is defined %}<p>{{ properties.metadata.archived_date }}</p>{% endif %} - </div> - - <div class="{% if graphType=='evolution' %}dataTableGraphEvolutionWrapper{% else %}dataTableGraphWrapper{% endif %}"> - - {% if isDataAvailable %} - <div class="jqplot-{{ graphType }}" style="padding-left: 6px;"> - <div class="piwik-graph" - style="position: relative; width: {{ width }}{% if width|slice(-1,1) != '%' %}px{% endif %}; height: {{ height }}{% if height|slice(-1,1) != '%' %}px{% endif %};" - data-data="{{ data|e('html') }}" - data-graph-type="{{ graphType }}" - {% if properties.externalSeriesToggle is defined and properties.externalSeriesToggle %} - data-external-series-toggle="{{ properties.externalSeriesToggle }}" - data-external-series-show-all="{% if properties.externalSeriesToggleShowAll %}1{% else %}0{% endif %}" - {% endif %}> - </div> - </div> - {% else %} - <div> - <div class="pk-emptyGraph"> - {% if showReportDataWasPurgedMessage %} - {{ 'General_DataForThisGraphHasBeenPurged'|translate(deleteReportsOlderThan) }} - {% else %} - {{ 'General_NoDataForGraph_js'|translate }} - {% endif %} - </div> - </div> - {% endif %} - - {% if properties.show_footer %} - {% include "@CoreHome/_dataTableFooter.twig" %} - {% endif %} - - {% include "@CoreHome/_dataTableJS.twig" %} - </div> -</div> diff --git a/plugins/CoreHome/templates/_dataTableHead.twig b/plugins/CoreHome/templates/_dataTableHead.twig index c147aa4df0..caec789b93 100644 --- a/plugins/CoreHome/templates/_dataTableHead.twig +++ b/plugins/CoreHome/templates/_dataTableHead.twig @@ -1,16 +1,16 @@ <thead> <tr> - {% for column in dataTableColumns %} + {% for column in properties.columns_to_display %} <th class="sortable {% if loop.first %}first{% elseif loop.last %}last{% endif %}" id="{{ column }}"> - {% if columnDocumentation[column] is not empty %} + {% if properties.metrics_documentation[column]|default is not empty %} <div class="columnDocumentation"> <div class="columnDocumentationTitle"> - {{ columnTranslations[column] }} + {{ properties.translations[column]|default(column) }} </div> - {{ columnDocumentation[column] }} + {{ properties.metrics_documentation[column] }} </div> {% endif %} - <div id="thDIV">{{ columnTranslations[column] }}</div> + <div id="thDIV">{{ properties.translations[column]|default(column) }}</div> </th> {% endfor %} </tr> diff --git a/plugins/CoreHome/templates/_dataTableViz_htmlTable.twig b/plugins/CoreHome/templates/_dataTableViz_htmlTable.twig new file mode 100644 index 0000000000..825fb6b6a5 --- /dev/null +++ b/plugins/CoreHome/templates/_dataTableViz_htmlTable.twig @@ -0,0 +1,27 @@ +<table cellspacing="0" class="dataTable"> + {% include "@CoreHome/_dataTableHead.twig" %} + + <tbody> + {% for rowId, row in dataTable.getRows() %} + {%- set rowHasSubtable = row.getIdSubDataTable() and properties.subtable_controller_action is not null -%} + {%- set shouldHighlightRow = rowId == constant("Piwik_DataTable::ID_SUMMARY_ROW") and properties.highlight_summary_row -%} + + {# display this row if it doesn't have a subtable or if we don't replace the row with the subtable #} + {% if not rowHasSubtable or not properties.show_expanded|default(false) or not properties.replace_row_with_subtable|default(false) %} + <tr {% if rowHasSubtable %}id="{{ row.getIdSubDataTable() }}"{% endif %} + class="{{ row.getMetadata('css_class') }} {% if rowHasSubtable %}subDataTable{% endif %}{% if shouldHighlightRow %} highlight{% endif %}"> + {% for column in properties.columns_to_display %} + <td> + {% include "@CoreHome/_dataTableCell.twig" with properties %} + </td> + {% endfor %} + </tr> + {% endif %} + + {# display subtable if present and showing expanded datatable #} + {% if properties.show_expanded|default(false) and rowHasSubtable %} + {% include properties.subtable_template with {'dataTable': row.getSubtable()} %} + {% endif %} + {% endfor %} + </tbody> +</table>
\ No newline at end of file diff --git a/plugins/CoreHome/templates/_dataTableViz_jqplotGraph.twig b/plugins/CoreHome/templates/_dataTableViz_jqplotGraph.twig new file mode 100644 index 0000000000..65e9f7a43c --- /dev/null +++ b/plugins/CoreHome/templates/_dataTableViz_jqplotGraph.twig @@ -0,0 +1,10 @@ +<div class="jqplot-graph"> + <div class="piwik-graph" + style="width: {{ properties.graph_width }}; height: {{ properties.graph_height }};" + data-data="{{ data|e('html') }}" + {% if properties.external_series_toggle is defined and properties.external_series_toggle %} + data-external-series-toggle="{{ properties.external_series_toggle }}" + data-external-series-show-all="{% if properties.external_series_toggle_show_all %}1{% else %}0{% endif %}" + {% endif %}> + </div> +</div>
\ No newline at end of file diff --git a/plugins/CoreHome/templates/_dataTableViz_tagCloud.twig b/plugins/CoreHome/templates/_dataTableViz_tagCloud.twig new file mode 100644 index 0000000000..1513daca34 --- /dev/null +++ b/plugins/CoreHome/templates/_dataTableViz_tagCloud.twig @@ -0,0 +1,18 @@ +{% set cloudColumn = properties.columns_to_display[1] %} +<div class="tagCloud"> +{% for word,value in cloudValues %} + <span title="{{ value.word }} ({{ value.value }} {{ properties.translations[cloudColumn]|default(cloudColumn) }})" class="word size{{ value.size }} + {# we strike tags with 0 hits #} + {% if value.value == 0 %}valueIsZero{% endif %}"> + {% if labelMetadata[value.word].url is not sameas(false) %} + <a href="{{ labelMetadata[value.word].url }}" target="_blank"> + {% endif %} + {% if labelMetadata[value.word].logo is not sameas(false) %} + <img src="{{ labelMetadata[value.word].logo }}" width="{{ value.logoWidth }}" /> + {% else %} + {{ value.wordTruncated }} + {% endif %} + {% if labelMetadata[value.word].url is not sameas(false) %}</a>{% endif %} + </span> +{% endfor %} +</div>
\ No newline at end of file diff --git a/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig b/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig index daf93f91b7..7f027b458e 100644 --- a/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig +++ b/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig @@ -1,3 +1,4 @@ +{% set seriesColorCount = constant("Piwik_Visualization_Chart_Evolution::SERIES_COLOR_COUNT") %} <div class="rowevolution multirowevolution"> <div class="popover-title">{{ 'RowEvolution_MultiRowEvolutionTitle'|translate }}</div> <div class="graph"> @@ -6,7 +7,7 @@ <div class="metrics-container"> <h2>{{ availableRecordsText|translate }}</h2> <table class="metrics" border="0" cellpadding="0" cellspacing="0"> - {% for metric in metrics %} + {% for i, metric in metrics %} <tr> <td class="sparkline"> {{ metric.sparkline|raw }} @@ -14,7 +15,9 @@ <td class="text"> {% import 'macros.twig' as piwik %} {{ piwik.logoHtml(metric, "") }} - <span style="color:{{ metric.color }}">{{ metric.label|raw }}</span><br/> + <span class="evolution-graph-colors" data-name="series{{ (i % seriesColorCount) + 1 }}"> + {{- metric.label|raw -}} + </span> <span class="details">{{ metric.details }}</span> </td> </tr> diff --git a/plugins/CoreHome/templates/getRowEvolutionPopover.twig b/plugins/CoreHome/templates/getRowEvolutionPopover.twig index 6179cfd5cf..4c38c80ac7 100644 --- a/plugins/CoreHome/templates/getRowEvolutionPopover.twig +++ b/plugins/CoreHome/templates/getRowEvolutionPopover.twig @@ -1,3 +1,4 @@ +{% set seriesColorCount = constant("Piwik_Visualization_Chart_Evolution::SERIES_COLOR_COUNT") %} <div class="rowevolution"> <div class="popover-title">{{ popoverTitle | raw }}</div> <div class="graph"> @@ -9,14 +10,16 @@ <div class="rowevolution-documentation"> {{ 'RowEvolution_Documentation'|translate }} </div> - <table class="metrics" border="0" cellpadding="0" cellspacing="0"> - {% for metric in metrics %} - <tr> + <table class="metrics" border="0" cellpadding="0" cellspacing="0" data-thing="{{ seriesColorCount }}"> + {% for i, metric in metrics %} + <tr data-i="{{ i }}"> <td class="sparkline"> - {{ metric.sparkline | raw }} + {{ metric.sparkline|raw }} </td> <td class="text"> - <span style="color:{{ metric.color }}">{{ metric.label|raw }}</span> + <span class="evolution-graph-colors" data-name="series{{ (i % seriesColorCount) + 1 }}"> + {{- metric.label|raw -}} + </span> {% if metric.details %}: <span class="details">{{ metric.details }}</span> {% endif %} diff --git a/plugins/CustomVariables/Controller.php b/plugins/CustomVariables/Controller.php index 6c6054f418..9734c0883b 100644 --- a/plugins/CustomVariables/Controller.php +++ b/plugins/CustomVariables/Controller.php @@ -26,39 +26,12 @@ class Piwik_CustomVariables_Controller extends Controller public function getCustomVariables($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, "CustomVariables.getCustomVariables", "getCustomVariablesValuesFromNameId"); - - $this->setPeriodVariablesView($view); - $this->setMetricsVariablesView($view); - - $this->configureView($view); - $view->setColumnTranslation('label', Piwik_Translate('CustomVariables_ColumnCustomVariableName')); - - $view->setFooterMessage(Piwik_Translate('CustomVariables_TrackingHelp', array('<a target="_blank" href="http://piwik.org/docs/custom-variables/">', '</a>'))); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getCustomVariablesValuesFromNameId($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'CustomVariables.getCustomVariablesValuesFromNameId'); - - $this->configureView($view); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->setColumnTranslation('label', Piwik_Translate('CustomVariables_ColumnCustomVariableValue')); - return $this->renderView($view, $fetch); - } - - protected function configureView($view) - { - $view->setColumnsToDisplay(array('label', 'nb_actions', 'nb_visits')); - $view->setSortedColumn('nb_actions'); - $view->enableShowGoals(); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - - } diff --git a/plugins/CustomVariables/CustomVariables.php b/plugins/CustomVariables/CustomVariables.php index 055ce64993..30ebb6b580 100644 --- a/plugins/CustomVariables/CustomVariables.php +++ b/plugins/CustomVariables/CustomVariables.php @@ -31,13 +31,14 @@ class Piwik_CustomVariables extends Plugin public function getListHooksRegistered() { $hooks = array( - 'ArchiveProcessing_Day.compute' => 'archiveDay', - 'ArchiveProcessing_Period.compute' => 'archivePeriod', - 'WidgetsList.add' => 'addWidgets', - 'Menu.add' => 'addMenus', - 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', - 'API.getReportMetadata' => 'getReportMetadata', - 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ArchiveProcessing_Day.compute' => 'archiveDay', + 'ArchiveProcessing_Period.compute' => 'archivePeriod', + 'WidgetsList.add' => 'addWidgets', + 'Menu.add' => 'addMenus', + 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', + 'API.getReportMetadata' => 'getReportMetadata', + 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; } @@ -149,4 +150,40 @@ class Piwik_CustomVariables extends Plugin $archiving->archivePeriod(); } } + + public function getReportDisplayProperties(&$properties) + { + $properties['CustomVariables.getCustomVariables'] = $this->getDisplayPropertiesForGetCustomVariables(); + $properties['CustomVariables.getCustomVariablesValuesFromNameId'] = + $this->getDisplayPropertiesForGetCustomVariablesValuesFromNameId(); + } + + private function getDisplayPropertiesForGetCustomVariables() + { + $footerMessage = Piwik_Translate('CustomVariables_TrackingHelp', + array('<a target="_blank" href="http://piwik.org/docs/custom-variables/">', '</a>')); + + return array( + 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), + 'filter_sort_column' => 'nb_actions', + 'filter_sort_order' => 'desc', + 'show_goals' => true, + 'subtable_controller_action' => 'getCustomVariablesValuesFromNameId', + 'translations' => array('label' => Piwik_Translate('CustomVariables_ColumnCustomVariableName')), + 'show_footer_message' => $footerMessage + ); + } + + private function getDisplayPropertiesForGetCustomVariablesValuesFromNameId() + { + return array( + 'columns_to_display' => array('label', 'nb_actions', 'nb_visits'), + 'filter_sort_column' => 'nb_actions', + 'filter_sort_order' => 'desc', + 'show_goals' => true, + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate('CustomVariables_ColumnCustomVariableValue')) + ); + } } diff --git a/plugins/DBStats/Controller.php b/plugins/DBStats/Controller.php index 8194c29cc4..51f2a00ae6 100644 --- a/plugins/DBStats/Controller.php +++ b/plugins/DBStats/Controller.php @@ -57,21 +57,7 @@ class Piwik_DBStats_Controller extends Admin public function getDatabaseUsageSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'graphPie', $orderDir = 'desc', - $addPercentColumn = true); - $view->disableOffsetInformationAndPaginationControls(); - - if ($view instanceof Piwik_ViewDataTable_GenerateGraphHTML) { - $view->showAllTicks(); - } - - // translate the labels themselves - $translateSummaryLabel = array($this, 'translateSummarylabel'); - $view->queueFilter('ColumnCallbackReplace', array(array('label'), $translateSummaryLabel), - $runBeforeGenericFilters = true); - - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -85,10 +71,7 @@ class Piwik_DBStats_Controller extends Admin public function getTrackerDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - - $view = $this->getDataTableView(__FUNCTION__); - $view->disableOffsetInformationAndPaginationControls(); - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -102,11 +85,7 @@ class Piwik_DBStats_Controller extends Admin public function getMetricDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc'); - $view->addRelatedReports(Piwik_Translate('DBStats_MetricTables'), array( - 'DBStats.getMetricDataSummaryByYear' => Piwik_Translate('DBStats_MetricDataByYear') - )); - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -120,12 +99,7 @@ class Piwik_DBStats_Controller extends Admin public function getMetricDataSummaryByYear($fetch = false) { Piwik::checkUserIsSuperUser(); - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc', - $addPercentColumn = false, $labelKey = 'CoreHome_PeriodYear'); - $view->addRelatedReports(Piwik_Translate('DBStats_MetricDataByYear'), array( - 'DBStats.getMetricDataSummary' => Piwik_Translate('DBStats_MetricTables') - )); - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -139,11 +113,7 @@ class Piwik_DBStats_Controller extends Admin public function getReportDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc'); - $view->addRelatedReports(Piwik_Translate('DBStats_ReportTables'), array( - 'DBStats.getReportDataSummaryByYear' => Piwik_Translate('DBStats_ReportDataByYear') - )); - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -157,12 +127,7 @@ class Piwik_DBStats_Controller extends Admin public function getReportDataSummaryByYear($fetch = false) { Piwik::checkUserIsSuperUser(); - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'desc', - $addPercentColumn = false, $labelKey = 'CoreHome_PeriodYear'); - $view->addRelatedReports(Piwik_Translate('DBStats_ReportDataByYear'), array( - 'DBStats.getReportDataSummary' => Piwik_Translate('DBStats_ReportTables') - )); - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -178,18 +143,7 @@ class Piwik_DBStats_Controller extends Admin public function getIndividualReportsSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'asc', - $addPercentColumn = false, $labelKey = 'General_Report', - $sizeColumns = array('estimated_size')); - - // this report table has some extra columns that shouldn't be shown - if ($view instanceof Piwik_ViewDataTable_HtmlTable) { - $view->setColumnsToDisplay(array('label', 'row_count', 'estimated_size')); - } - - $this->setIndividualSummaryFooterMessage($view); - - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -205,13 +159,7 @@ class Piwik_DBStats_Controller extends Admin public function getIndividualMetricsSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table', $orderDir = 'asc', - $addPercentColumn = false, $labelKey = 'General_Metric', - $sizeColumns = array('estimated_size')); - - $this->setIndividualSummaryFooterMessage($view); - - return $this->renderView($view, $fetch); + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -228,151 +176,6 @@ class Piwik_DBStats_Controller extends Admin public function getAdminDataSummary($fetch = false) { Piwik::checkUserIsSuperUser(); - $view = $this->getDataTableView(__FUNCTION__, $viewType = 'table'); - $view->disableOffsetInformationAndPaginationControls(); - return $this->renderView($view, $fetch); - } - - /** - * Utility function that creates and prepares a ViewDataTable for this plugin. - */ - private function getDataTableView($function, $viewType = 'table', $orderDir = 'asc', $addPercentColumn = false, - $labelKey = 'DBStats_Table', $sizeColumns = array('data_size', 'index_size'), - $limit = 25) - { - $columnTranslations = array( - 'label' => Piwik_Translate($labelKey), - 'year' => Piwik_Translate('CoreHome_PeriodYear'), - 'data_size' => Piwik_Translate('DBStats_DataSize'), - 'index_size' => Piwik_Translate('DBStats_IndexSize'), - 'total_size' => Piwik_Translate('DBStats_TotalSize'), - 'row_count' => Piwik_Translate('DBStats_RowCount'), - 'percent_total' => '% ' . Piwik_Translate('DBStats_DBSize'), - 'estimated_size' => Piwik_Translate('DBStats_EstimatedSize') - ); - - $view = ViewDataTable::factory($viewType); - $view->init($this->pluginName, $function, "DBStats.$function"); - $view->setSortedColumn('label', $orderDir); - $view->setLimit($limit); - $view->setHighlightSummaryRow(true); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->disableTagCloud(); - $view->disableShowAllColumns(); - $view->alwaysShowSummaryRow(); - - // translate columns - foreach ($columnTranslations as $columnName => $translation) { - $view->setColumnTranslation($columnName, $translation); - } - - // add total_size column (if necessary columns are present) - if (in_array('data_size', $sizeColumns) && in_array('index_size', $sizeColumns)) { - $getTotalTableSize = array($this, 'getTotalTableSize'); - $view->queueFilter('ColumnCallbackAddColumn', - array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize), - $runBeforeGenericFilters = true); - - $sizeColumns[] = 'total_size'; - } - - $runPrettySizeFilterBeforeGeneric = false; - $fixedMemoryUnit = false; - if ($view instanceof Piwik_ViewDataTable_HtmlTable) { // if displaying a table - $view->disableRowEvolution(); - - // add summary row only if displaying a table - $view->queueFilter('AddSummaryRow', array(0, Piwik_Translate('General_Total'), 'label', false), - $runBeforeGenericFilters = true); - - // add other filters - if ($addPercentColumn && in_array('total_size', $sizeColumns)) { - $view->queueFilter('ColumnCallbackAddColumnPercentage', - array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, $shouldSkipRows = false, - $getDivisorFromSummaryRow = true), - $runBeforeGenericFilters = true); - $view->setSortedColumn('percent_total', $orderDir); - } - } else if ($view instanceof Piwik_ViewDataTable_GenerateGraphHtml) { // if displaying a graph - if (in_array('total_size', $sizeColumns)) { - $view->setColumnsToDisplay(array('label', 'total_size')); - - // when displaying a graph, we force sizes to be shown as the same unit so axis labels - // will be readable. NOTE: The unit should depend on the smallest value of the data table, - // however there's no way to know this information, short of creating a custom filter. For - // now, just assume KB. - $fixedMemoryUnit = 'K'; - $view->setAxisYUnit(' K'); - - $view->setSortedColumn('total_size', 'desc'); - - $runPrettySizeFilterBeforeGeneric = true; - } else { - $view->setColumnsToDisplay(array('label', 'row_count')); - $view->setAxisYUnit(' ' . Piwik_Translate('General_Rows')); - - $view->setSortedColumn('row_count', 'desc'); - } - } - - $getPrettySize = '\Piwik\Piwik::getPrettySizeFromBytes'; - $params = $fixedMemoryUnit === false ? array() : array($fixedMemoryUnit); - $view->queueFilter( - 'ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric); - - // jqPlot will display as, well, ' ', so don't replace the spaces when rendering as a graph - if (!($view instanceof Piwik_ViewDataTable_GenerateGraphHtml)) { - $replaceSpaces = array($this, 'replaceColumnSpaces'); - $view->queueFilter('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces)); - } - - $view->queueFilter('ColumnCallbackReplace', array(array('row_count'), '\Piwik\Piwik::getPrettyNumber')); - - return $view; - } - - /** - * Replaces spaces w/ for correct HTML output. - */ - public function replaceColumnSpaces($value) - { - return str_replace(' ', ' ', $value); - } - - /** - * Row callback function that calculates a tables total size. - */ - public function getTotalTableSize($dataSize, $indexSize) - { - return $dataSize + $indexSize; - } - - /** - * Column callback used to translate the column values in the database usage summary table. - */ - public function translateSummarylabel($value) - { - static $valueToTranslationStr = array( - 'tracker_data' => 'DBStats_TrackerTables', - 'report_data' => 'DBStats_ReportTables', - 'metric_data' => 'DBStats_MetricTables', - 'other_data' => 'DBStats_OtherTables' - ); - - return isset($valueToTranslationStr[$value]) - ? Piwik_Translate($valueToTranslationStr[$value]) - : $value; - } - - /** - * Sets the footer message for the Individual...Summary reports. - */ - private function setIndividualSummaryFooterMessage($view) - { - $lastGenerated = Piwik_DBStats::getDateOfLastCachingRun(); - if ($lastGenerated !== false) { - $view->setFooterMessage(Piwik_Translate('Mobile_LastUpdated', $lastGenerated)); - } + return ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/DBStats/DBStats.php b/plugins/DBStats/DBStats.php index 955c0b6812..467933d1e3 100644 --- a/plugins/DBStats/DBStats.php +++ b/plugins/DBStats/DBStats.php @@ -27,9 +27,10 @@ class Piwik_DBStats extends Plugin public function getListHooksRegistered() { return array( - 'AssetManager.getCssFiles' => 'getCssFiles', - 'AdminMenu.add' => 'addMenu', - 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', + 'AssetManager.getCssFiles' => 'getCssFiles', + 'AdminMenu.add' => 'addMenu', + 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); } @@ -80,4 +81,281 @@ class Piwik_DBStats extends Plugin { return Piwik_GetOption(self::TIME_OF_LAST_TASK_RUN_OPTION); } + + public function getReportDisplayProperties(&$properties) + { + $properties['DBStats.getDatabaseUsageSummary'] = $this->getDisplayPropertiesForGetDatabaseUsageSummary(); + $properties['DBStats.getTrackerDataSummary'] = $this->getDisplayPropertiesForGetTrackerDataSummary(); + $properties['DBStats.getMetricDataSummary'] = $this->getDisplayPropertiesForGetMetricDataSummary(); + $properties['DBStats.getMetricDataSummaryByYear'] = $this->getDisplayPropertiesForGetMetricDataSummaryByYear(); + $properties['DBStats.getReportDataSummary'] = $this->getDisplayPropertiesForGetReportDataSummary(); + $properties['DBStats.getReportDataSummaryByYear'] = $this->getDisplayPropertiesForGetReportDataSummaryByYear(); + $properties['DBStats.getIndividualReportsSummary'] = $this->getDisplayPropertiesForGetIndividualReportsSummary(); + $properties['DBStats.getIndividualMetricsSummary'] = $this->getDisplayPropertiesForGetIndividualMetricsSummary(); + $properties['DBStats.getAdminDataSummary'] = $this->getDisplayPropertiesForGetAdminDataSummary(); + } + + private function getDisplayPropertiesForGetDatabaseUsageSummary() + { + $result = array('default_view_type' => 'graphPie'); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result, $addTotalSizeColumn = true, $addPercentColumn = true); + + $result['show_offset_information'] = false; + $result['show_pagination_control'] = false; + $result['show_all_ticks'] = true; + + // translate the labels themselves + $valueToTranslationStr = array( + 'tracker_data' => 'DBStats_TrackerTables', + 'report_data' => 'DBStats_ReportTables', + 'metric_data' => 'DBStats_MetricTables', + 'other_data' => 'DBStats_OtherTables' + ); + + $translateSummaryLabel = function ($value) use ($valueToTranslationStr) { + return isset($valueToTranslationStr[$value]) + ? Piwik_Translate($valueToTranslationStr[$value]) + : $value; + }; + + $result['filters'][] = array('ColumnCallbackReplace', array('label', $translateSummaryLabel), $isPriority = true); + + return $result; + } + + private function getDisplayPropertiesForGetTrackerDataSummary() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result); + + $result['filter_sort_order'] = 'asc'; + $result['show_offset_information'] = false; + $result['show_pagination_control'] = false; + + return $result; + } + + private function getDisplayPropertiesForGetMetricDataSummary() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result); + + $result['title'] = Piwik_Translate('DBStats_MetricTables'); + $result['relatedReports'] = array( + 'DBStats.getMetricDataSummaryByYear' => Piwik_Translate('DBStats_MetricDataByYear') + ); + + return $result; + } + + private function getDisplayPropertiesForGetMetricDataSummaryByYear() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result); + + $result['translations']['label'] = Piwik_Translate('CoreHome_PeriodYear'); + $result['title'] = Piwik_Translate('DBStats_MetricDataByYear'); + $result['relatedReports'] = array( + 'DBStats.getMetricDataSummary' => Piwik_Translate('DBStats_MetricTables') + ); + + return $result; + } + + private function getDisplayPropertiesForGetReportDataSummary() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result); + + $result['title'] = Piwik_Translate('DBStats_ReportTables'); + $result['relatedReports'] = array( + 'DBStats.getReportDataSummaryByYear' => Piwik_Translate('DBStats_ReportDataByYear') + ); + + return $result; + } + + private function getDisplayPropertiesForGetReportDataSummaryByYear() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result); + + $result['translations']['label'] = Piwik_Translate('CoreHome_PeriodYear'); + $result['title'] = Piwik_Translate('DBStats_ReportDataByYear'); + $result['relatedReports'] = array( + 'DBStats.getReportDataSummary' => Piwik_Translate('DBStats_ReportTables') + ); + + return $result; + } + + private function getDisplayPropertiesForGetIndividualReportsSummary() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $viewDataTable = $this->addPresentationFilters($result, $addTotalSizeColumn = false, $addPercentColumn = false, + $sizeColumns = array('estimated_size')); + + $result['filter_sort_order'] = 'asc'; + $result['translations']['label'] = Piwik_Translate('General_Report'); + + // this report table has some extra columns that shouldn't be shown + if ($viewDataTable == 'table') { + $result['columns_to_display'] = array('label', 'row_count', 'estimated_size'); + } + + $this->setIndividualSummaryFooterMessage($result); + + return $result; + } + + private function getDisplayPropertiesForGetIndividualMetricsSummary() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result, $addTotalSizeColumn = false, $addPercentColumn = false, + $sizeColumns = array('estimated_size')); + + $result['filter_sort_order'] = 'asc'; + $result['translations']['label'] = Piwik_Translate('General_Metric'); + + $this->setIndividualSummaryFooterMessage($result); + + return $result; + } + + private function getDisplayPropertiesForGetAdminDataSummary() + { + $result = array(); + $this->addBaseDisplayProperties($result); + $this->addPresentationFilters($result); + + $result['filter_sort_order'] = 'asc'; + $result['show_offset_information'] = false; + $result['show_pagination_control'] = false; + + return $result; + } + + private function addBaseDisplayProperties(&$properties) + { + $properties['filter_sort_column'] = 'label'; + $properties['filter_sort_order'] = 'desc'; + $properties['filter_limit'] = 25; + $properties['highlight_summary_row'] = true; + $properties['show_search'] = false; + $properties['show_exclude_low_population'] = false; + $properties['show_tag_cloud'] = false; + $properties['show_table_all_columns'] = false; + $properties['keep_summary_row'] = true; + $properties['disable_row_evolution'] = true; + $properties['translations'] = array( + 'label' => Piwik_Translate('DBStats_Table'), + 'year' => Piwik_Translate('CoreHome_PeriodYear'), + 'data_size' => Piwik_Translate('DBStats_DataSize'), + 'index_size' => Piwik_Translate('DBStats_IndexSize'), + 'total_size' => Piwik_Translate('DBStats_TotalSize'), + 'row_count' => Piwik_Translate('DBStats_RowCount'), + 'percent_total' => '% ' . Piwik_Translate('DBStats_DBSize'), + 'estimated_size' => Piwik_Translate('DBStats_EstimatedSize') + ); + } + + private function addPresentationFilters(&$properties, $addTotalSizeColumn = true, $addPercentColumn = false, + $sizeColumns = array('data_size', 'index_size')) + { + // add total_size column + if ($addTotalSizeColumn) { + $getTotalTableSize = function ($dataSize, $indexSize) { + return $dataSize + $indexSize; + }; + + $properties['filters'][] = array('ColumnCallbackAddColumn', + array(array('data_size', 'index_size'), 'total_size', $getTotalTableSize), $isPriority = true); + + $sizeColumns[] = 'total_size'; + } + + $runPrettySizeFilterBeforeGeneric = false; + + $viewDataTable = empty($properties['default_view_type']) ? 'table' : $properties['default_view_type']; + $viewDataTable = Piwik_Common::getRequestVar('viewDataTable', $viewDataTable); + + if ($viewDataTable == 'table') { + // add summary row only if displaying a table + $properties['filters'][] = array( + 'AddSummaryRow', array(0, Piwik_Translate('General_Total'), 'label', false), $isPriority = true); + + // add percentage column if desired + if ($addPercentColumn + && $addTotalSizeColumn + ) { + $properties['filters'][] = array('ColumnCallbackAddColumnPercentage', + array('percent_total', 'total_size', 'total_size', $quotientPrecision = 0, + $shouldSkipRows = false, $getDivisorFromSummaryRow = true), + $isPriority = true + ); + + $properties['filter_sort_column'] = 'percent_total'; + } + } else if (strpos($viewDataTable, 'graph') === 0) { + if ($addTotalSizeColumn) { + $properties['columns_to_display'] = array('label', 'total_size'); + + // when displaying a graph, we force sizes to be shown as the same unit so axis labels + // will be readable. NOTE: The unit should depend on the smallest value of the data table, + // however there's no way to know this information, short of creating a custom filter. For + // now, just assume KB. + $fixedMemoryUnit = 'K'; + $properties['y_axis_unit'] = ' K'; + + $properties['filter_sort_column'] = 'total_size'; + $properties['filter_sort_order'] = 'desc'; + + $runPrettySizeFilterBeforeGeneric = true; + } else { + $properties['columns_to_display'] = array('label', 'row_count'); + $properties['y_axis_unit'] = ' ' . Piwik_Translate('General_Rows'); + + $properties['filter_sort_column'] = 'row_count'; + $properties['filter_sort_order'] = 'desc'; + } + } + + $getPrettySize = array('Piwik', 'getPrettySizeFromBytes'); + $params = !isset($fixedMemoryUnit) ? array() : array($fixedMemoryUnit); + $properties['filters'][] = array( + 'ColumnCallbackReplace', array($sizeColumns, $getPrettySize, $params), $runPrettySizeFilterBeforeGeneric); + + // jqPlot will display as, well, ' ', so don't replace the spaces when rendering as a graph + if ($viewDataTable == 'table') { + $replaceSpaces = function ($value) { + return str_replace(' ', ' ', $value); + }; + + $properties['filters'][] = array('ColumnCallbackReplace', array($sizeColumns, $replaceSpaces)); + } + + $getPrettyNumber = array('Piwik', 'getPrettyNumber'); + $properties['filters'][] = array('ColumnCallbackReplace', array('row_count', $getPrettyNumber)); + + return $viewDataTable; + } + + /** + * Sets the footer message for the Individual...Summary reports. + */ + private function setIndividualSummaryFooterMessage($result) + { + $lastGenerated = self::getDateOfLastCachingRun(); + if ($lastGenerated !== false) { + $result['show_footer_message'] = Piwik_Translate('Mobile_LastUpdated', $lastGenerated); + } + } } diff --git a/plugins/DevicesDetection/Controller.php b/plugins/DevicesDetection/Controller.php index 8b90751400..848483af24 100644 --- a/plugins/DevicesDetection/Controller.php +++ b/plugins/DevicesDetection/Controller.php @@ -18,24 +18,6 @@ use Piwik\Db; */ class Piwik_DevicesDetection_Controller extends Controller { - - /** The set of related reports displayed under the 'Operating Systems' header. */ - private $osRelatedReports = null; - private $browserRelatedReports = null; - - public function __construct() - { - parent::__construct(); - $this->osRelatedReports = array( - 'DevicesDetection.getOsFamilies' => Piwik_Translate('DeviceDetection_OperatingSystemFamilies'), - 'DevicesDetection.getOsVersions' => Piwik_Translate('DeviceDetection_OperatingSystemVersions') - ); - $this->browserRelatedReports = array( - 'DevicesDetection.getBrowserFamilies' => Piwik_Translate('DevicesDetection_BrowsersFamily'), - 'DevicesDetection.getBrowserVersions' => Piwik_Translate('DevicesDetection_BrowserVersions') - ); - } - public function index($fetch = false) { $view = new View('@DevicesDetection/index'); @@ -50,88 +32,37 @@ class Piwik_DevicesDetection_Controller extends Controller public function getType($fetch = false) { - $view = $this->getStandardDataTableUserSettings( - __FUNCTION__, 'DevicesDetection.getType' - ); - - $view->setColumnTranslation('label', Piwik_Translate("DevicesDetection_dataTableLabelTypes")); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrand($fetch = false) { - $view = $this->getStandardDataTableUserSettings( - __FUNCTION__, 'DevicesDetection.getBrand' - ); - - $view->setColumnTranslation('label', Piwik_Translate("DevicesDetection_dataTableLabelBrands")); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getModel($fetch = false) { - $view = $this->getStandardDataTableUserSettings( - __FUNCTION__, 'DevicesDetection.getModel' - ); - - $view->setColumnTranslation('label', Piwik_Translate("DevicesDetection_dataTableLabelModels")); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOsFamilies($fetch = false) { - $view = $this->getStandardDataTableUserSettings( - __FUNCTION__, 'DevicesDetection.getOsFamilies' - ); - - $view->setColumnTranslation('label', Piwik_Translate("DevicesDetection_dataTableLabelSystemFamily")); - $view->addRelatedReports(Piwik_Translate('DeviceDetection_OperatingSystemFamilies'), $this->osRelatedReports); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOsVersions($fetch = false) { - $view = $this->getStandardDataTableUserSettings( - __FUNCTION__, 'DevicesDetection.getOsVersions' - ); - - $view->setColumnTranslation('label', Piwik_Translate("DevicesDetection_dataTableLabelSystemVersion")); - $view->addRelatedReports(Piwik_Translate('DeviceDetection_OperatingSystemVersions'), $this->osRelatedReports); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserFamilies($fetch = false) { - $view = $this->getStandardDataTableUserSettings( - __FUNCTION__, 'DevicesDetection.getBrowserFamilies' - ); - - $view->setColumnTranslation('label', Piwik_Translate("DevicesDetection_dataTableLabelBrowserFamily")); - $view->addRelatedReports(Piwik_Translate('DevicesDetection_BrowsersFamily'), $this->browserRelatedReports); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserVersions($fetch = false) { - $view = $this->getStandardDataTableUserSettings( - __FUNCTION__, 'DevicesDetection.getBrowserVersions' - ); - - $view->setColumnTranslation('label', Piwik_Translate("DevicesDetection_dataTableLabelBrowserVersion")); - $view->addRelatedReports(Piwik_Translate('DevicesDetection_BrowserVersions'), $this->browserRelatedReports); - return $this->renderView($view, $fetch); - } - - protected function getStandardDataTableUserSettings($currentControllerAction, $APItoCall, $defaultDatatableType = null) - { - $view = ViewDataTable::factory($defaultDatatableType); - $view->init($this->pluginName, $currentControllerAction, $APItoCall); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $this->setPeriodVariablesView($view); - $this->setMetricsVariablesView($view); - return $view; + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -181,5 +112,4 @@ class Piwik_DevicesDetection_Controller extends Controller WHERE idvisit = " . $idVisit; Db::query($q); } - } diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php index 4af04a5678..8adc51141c 100644 --- a/plugins/DevicesDetection/DevicesDetection.php +++ b/plugins/DevicesDetection/DevicesDetection.php @@ -22,6 +22,23 @@ require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php'; class Piwik_DevicesDetection extends Plugin { + /** The set of related reports displayed under the 'Operating Systems' header. */ + private $osRelatedReports = null; + private $browserRelatedReports = null; + + public function __construct() + { + parent::__construct(); + $this->osRelatedReports = array( + 'DevicesDetection.getOsFamilies' => Piwik_Translate('DeviceDetection_OperatingSystemFamilies'), + 'DevicesDetection.getOsVersions' => Piwik_Translate('DeviceDetection_OperatingSystemVersions') + ); + $this->browserRelatedReports = array( + 'DevicesDetection.getBrowserFamilies' => Piwik_Translate('DevicesDetection_BrowsersFamily'), + 'DevicesDetection.getBrowserVersions' => Piwik_Translate('DevicesDetection_BrowserVersions') + ); + } + /** * @see Piwik_Plugin::getInformation */ @@ -49,6 +66,7 @@ class Piwik_DevicesDetection extends Plugin 'WidgetsList.add' => 'addWidgets', 'API.getReportMetadata' => 'getReportMetadata', 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); } @@ -254,4 +272,101 @@ class Piwik_DevicesDetection extends Plugin { Piwik_AddMenu('General_Visitors', 'DevicesDetection_submenu', array('module' => 'DevicesDetection', 'action' => 'index')); } + + public function getReportDisplayProperties(&$properties) + { + $properties['DevicesDetection.getType'] = $this->getDisplayPropertiesForGetType(); + $properties['DevicesDetection.getBrand'] = $this->getDisplayPropertiesForGetBrand(); + $properties['DevicesDetection.getModel'] = $this->getDisplayPropertiesForGetModel(); + $properties['DevicesDetection.getOsFamilies'] = $this->getDisplayPropertiesForGetOsFamilies(); + $properties['DevicesDetection.getOsVersions'] = $this->getDisplayPropertiesForGetOsVersions(); + $properties['DevicesDetection.getBrowserFamilies'] = $this->getDisplayPropertiesForGetBrowserFamilies(); + $properties['DevicesDetection.getBrowserVersions'] = $this->getDisplayPropertiesForGetBrowserVersions(); + } + + private function getDisplayPropertiesForGetType() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelTypes")) + ); + } + + private function getDisplayPropertiesForGetBrand() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelBrands")) + ); + } + + private function getDisplayPropertiesForGetModel() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelModels")) + ); + } + + private function getDisplayPropertiesForGetOsFamilies() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelSystemFamily")), + 'title' => Piwik_Translate('DeviceDetection_OperatingSystemFamilies'), + 'relatedReports' => $this->getOsRelatedReports() + ); + } + + private function getDisplayPropertiesForGetOsVersions() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelSystemVersion")), + 'title' => Piwik_Translate('DeviceDetection_OperatingSystemVersions'), + 'relatedReports' => $this->getOsRelatedReports() + ); + } + + private function getDisplayPropertiesForGetBrowserFamilies() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelBrowserFamily")), + 'title' => Piwik_Translate('DevicesDetection_BrowsersFamily'), + 'relatedReports' => $this->getBrowserRelatedReports() + ); + } + + private function getDisplayPropertiesForGetBrowserVersions() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate("DevicesDetection_dataTableLabelBrowserVersion")), + 'relatedReports' => $this->getBrowserRelatedReports() + ); + } + + private function getOsRelatedReports() + { + return array( + 'DevicesDetection.getOsFamilies' => Piwik_Translate('DeviceDetection_OperatingSystemFamilies'), + 'DevicesDetection.getOsVersions' => Piwik_Translate('DeviceDetection_OperatingSystemVersions') + ); + } + + private function getBrowserRelatedReports() + { + return array( + 'DevicesDetection.getBrowserFamilies' => Piwik_Translate('DevicesDetection_BrowsersFamily'), + 'DevicesDetection.getBrowserVersions' => Piwik_Translate('DevicesDetection_BrowserVersions') + ); + } } diff --git a/plugins/ExampleUI/API.php b/plugins/ExampleUI/API.php index 3730c54eba..4fc0c513f8 100644 --- a/plugins/ExampleUI/API.php +++ b/plugins/ExampleUI/API.php @@ -23,6 +23,9 @@ class Piwik_ExampleUI_API { static private $instance = null; + /** + * @return Piwik_ExampleUI_API + */ static public function getInstance() { if (self::$instance == null) { diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php index ffb9342830..0656b8d3a5 100644 --- a/plugins/ExampleUI/Controller.php +++ b/plugins/ExampleUI/Controller.php @@ -18,61 +18,61 @@ use Piwik\View; */ class Piwik_ExampleUI_Controller extends Controller { - function dataTables() + public function dataTables() { - $view = ViewDataTable::factory('table'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures'); - $view->setColumnTranslation('value', "Temperature in °C"); - $view->setColumnTranslation('label', "Hour of day"); - $view->setSortedColumn('label', 'asc'); - $view->setGraphLimit(24); - $view->setLimit(24); - $view->disableExcludeLowPopulation(); - $view->disableShowAllColumns(); - $view->disableRowEvolution(); - $view->setAxisYUnit('°C'); // useful if the user requests the bar graph - return $this->renderView($view); + $view = Piwik_ViewDataTable::factory('table', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.dataTables'); + $view->translations['value'] = "Temperature in °C"; + $view->translations['label'] = "Hour of day"; + $view->filter_sort_column = 'label'; + $view->filter_sort_order = 'asc'; + $view->graph_limit = 24; + $view->filter_limit = 24; + $view->show_exclude_low_population = false; + $view->show_table_all_columns = false; + $view->disable_row_evolution = true; + $view->y_axis_unit = '°C'; // useful if the user requests the bar graph + echo $view->render(); } - function evolutionGraph() + public function evolutionGraph() { echo "<h2>Evolution of server temperatures over the last few days</h2>"; $this->echoEvolutionGraph(); } - function echoEvolutionGraph() + public function echoEvolutionGraph() { - $view = ViewDataTable::factory('graphEvolution'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution'); - $view->setColumnTranslation('server1', "Temperature server piwik.org"); - $view->setColumnTranslation('server2', "Temperature server dev.piwik.org"); - $view->setAxisYUnit('°C'); // useful if the user requests the bar graph - return $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'graphEvolution', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.echoEvolutionGraph'); + $view->translations['server1'] = "Temperature server piwik.org"; + $view->translations['server2'] = "Temperature server dev.piwik.org"; + $view->y_axis_unit = '°C'; // useful if the user requests the bar graph + echo $view->render(); } - function barGraph() + public function barGraph() { - $view = ViewDataTable::factory('graphVerticalBar'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperatures'); - $view->setColumnTranslation('value', "Temperature"); - $view->setAxisYUnit('°C'); - $view->setGraphLimit(24); - $view->disableFooter(); - return $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'graphVerticalBar', 'ExampleUI.getTemperatures', $controllerAction = 'ExampleUI.barGraph'); + $view->translations['value'] = "Temperature"; + $view->y_axis_unit = '°C'; + $view->graph_limit = 24; + $view->show_footer = false; + echo $view->render(); } - function pieGraph() + public function pieGraph() { - $view = ViewDataTable::factory('graphPie'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios'); - $view->setColumnsToDisplay('value'); - $view->setColumnTranslation('value', "times the diameter of Earth"); - $view->setGraphLimit(10); - $view->disableFooterIcons(); - return $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'graphPie', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.pieGraph'); + $view->columns_to_display = array('value'); + $view->translations['value'] = "times the diameter of Earth"; + $view->graph_limit = 10; + $view->show_footer_icons = false; + echo $view->render(); } - function tagClouds() + public function tagClouds() { echo "<h2>Simple tag cloud</h2>"; $this->echoSimpleTagClouds(); @@ -85,28 +85,27 @@ class Piwik_ExampleUI_Controller extends Controller $this->echoAdvancedTagClouds(); } - function echoSimpleTagClouds() + public function echoSimpleTagClouds() { - $view = ViewDataTable::factory('cloud'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatios'); - $view->setColumnsToDisplay(array('label', 'value')); - $view->setColumnTranslation('value', "times the diameter of Earth"); - $view->disableFooter(); - $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'cloud', 'ExampleUI.getPlanetRatios', $controllerAction = 'ExampleUI.echoSimpleTagClouds'); + $view->columns_to_display = array('label', 'value'); + $view->translations['value'] = "times the diameter of Earth"; + $view->show_footer = false; + echo $view->render(); } - function echoAdvancedTagClouds() + public function echoAdvancedTagClouds() { - $view = ViewDataTable::factory('cloud'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getPlanetRatiosWithLogos'); - $view->setDisplayLogoInTagCloud(true); - $view->disableFooterExceptExportIcons(); - $view->setColumnsToDisplay(array('label', 'value')); - $view->setColumnTranslation('value', "times the diameter of Earth"); - $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'cloud', 'ExampleUI.getPlanetRatiosWithLogos', $controllerAction = 'ExampleUI.echoAdvancedTagClouds'); + $view->display_logo_instead_of_label = true; + $view->columns_to_display = array('label', 'value'); + $view->translations['value'] = "times the diameter of Earth"; + echo $view->render(); } - function sparklines() + public function sparklines() { $view = new View('@ExampleUI/sparklines'); $view->urlSparkline1 = $this->getUrlSparkline('generateSparkline', array('server' => 'server1', 'rand' => mt_rand())); @@ -114,13 +113,17 @@ class Piwik_ExampleUI_Controller extends Controller echo $view->render(); } - function generateSparkline() + public function generateSparkline() { - $serverRequested = Common::getRequestVar('server', ''); - $view = ViewDataTable::factory('sparkline'); - $view->init($this->pluginName, __FUNCTION__, 'ExampleUI.getTemperaturesEvolution'); - $view->setColumnsToDisplay($serverRequested); - $this->renderView($view); + $view = Piwik_ViewDataTable::factory( + 'sparkline', 'ExampleUI.getTemperaturesEvolution', $controllerAction = 'ExampleUI.generateSparkline'); + + $serverRequested = Piwik_Common::getRequestVar('server', false); + if ($serverRequested !== false) { + $view->columns_to_display = array($serverRequested); + } + + echo $view->render(); } // Example use diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php index 953f73cf51..a75dcd76f3 100644 --- a/plugins/Goals/Controller.php +++ b/plugins/Goals/Controller.php @@ -131,7 +131,7 @@ class Piwik_Goals_Controller extends Controller $view->goalName = $goalDefinition['name']; $view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple']; $view->graphEvolution = $this->getEvolutionGraph(true, array('nb_conversions'), $idGoal); - $view->nameGraphEvolution = 'GoalsgetEvolutionGraph' . $idGoal; + $view->nameGraphEvolution = 'Goals.getEvolutionGraph' . $idGoal; $view->topDimensions = $this->getTopDimensions($idGoal); // conversion rate for new and returning visitors @@ -459,26 +459,26 @@ class Piwik_Goals_Controller extends Controller public function getItemsSku($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getItemsName($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getItemsCategory($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getVisitsUntilConversion($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getDaysToConversion($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index 7c9b006477..1ae77ed879 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -504,19 +504,13 @@ class Piwik_Goals extends Plugin } } - public function getReportDisplayProperties(&$properties, $apiAction) + public function getReportDisplayProperties(&$properties) { - $reportViewProperties = array( - 'Goals.getItemsSku' => $this->getDisplayPropertiesForGetItemsSku(), - 'Goals.getItemsName' => $this->getDisplayPropertiesForGetItemsName(), - 'Goals.getItemsCategory' => $this->getDisplayPropertiesForGetItemsCategory(), - 'Goals.getVisitsUntilConversion' => $this->getDisplayPropertiesForGetVisitsUntilConversion(), - 'Goals.getDaysToConversion' => $this->getDisplayPropertiesForGetDaysToConversion(), - ); - - if (isset($reportViewProperties[$apiAction])) { - $properties = $reportViewProperties[$apiAction]; - } + $properties['Goals.getItemsSku'] = $this->getDisplayPropertiesForGetItemsSku(); + $properties['Goals.getItemsName'] = $this->getDisplayPropertiesForGetItemsName(); + $properties['Goals.getItemsCategory'] = $this->getDisplayPropertiesForGetItemsCategory(); + $properties['Goals.getVisitsUntilConversion'] = $this->getDisplayPropertiesForGetVisitsUntilConversion(); + $properties['Goals.getDaysToConversion'] = $this->getDisplayPropertiesForGetDaysToConversion(); } private function getDisplayPropertiesForGetItemsSku() diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php index 0420f85615..1ebfacd951 100644 --- a/plugins/Live/Controller.php +++ b/plugins/Live/Controller.php @@ -83,49 +83,23 @@ class Piwik_Live_Controller extends Controller public function indexVisitorLog() { - $view = new View('@Live/indexVisitorLog.twig'); + $view = new Piwik_View('@Live/indexVisitorLog.twig'); $view->filterEcommerce = Common::getRequestVar('filterEcommerce', 0, 'int'); - $view->visitorLog = $this->getVisitorLog($fetch = true); + $view->visitorLog = $this->getLastVisitsDetails($fetch = true); echo $view->render(); } - public function getVisitorLog($fetch = false) + public function getLastVisitsDetails($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, - __FUNCTION__, - 'Live.getLastVisitsDetails' - ); - $view->disableGenericFilters(); - $view->disableSort(); - $view->setTemplate("@Live/getVisitorLog.twig"); - $view->setSortedColumn('idVisit', 'ASC'); - $view->disableSearchBox(); - $view->setLimit(20); - $view->disableOffsetInformation(); - $view->disableExcludeLowPopulation(); - - // disable the tag cloud, pie charts, bar chart icons - $view->disableShowAllViewsIcons(); - // disable the button "show more data" - $view->disableShowAllColumns(); - // disable the RSS feed - $view->disableShowExportAsRssFeed(); - - // disable all row actions - if ($view instanceof Piwik_ViewDataTable_HtmlTable) { - $view->disableRowActions(); - } - - $view->setReportDocumentation(Piwik_Translate('Live_VisitorLogDocumentation', array('<br />', '<br />'))); - - // set a very high row count so that the next link in the footer of the data table is always shown - $view->setCustomParameter('totalRows', 10000000); - - $view->setCustomParameter('filterEcommerce', Common::getRequestVar('filterEcommerce', 0, 'int')); - $view->setCustomParameter('pageUrlNotDefined', Piwik_Translate('General_NotDefined', Piwik_Translate('Actions_ColumnPageURL'))); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); + } - return $this->renderView($view, $fetch); + /** + * @deprecated + */ + public function getVisitorLog($fetch = false) + { + return $this->getLastVisitsDetails($fetch); } public function getLastVisitsStart($fetch = false) @@ -145,7 +119,7 @@ class Piwik_Live_Controller extends Controller private function setCounters($view) { - $segment = ViewDataTable::getRawSegmentFromRequest(); + $segment = Piwik_API_Request::getRawSegmentFromRequest(); $last30min = Piwik_Live_API::getInstance()->getCounters($this->idSite, $lastMinutes = 30, $segment); $last30min = $last30min[0]; $today = Piwik_Live_API::getInstance()->getCounters($this->idSite, $lastMinutes = 24 * 60, $segment); @@ -156,5 +130,4 @@ class Piwik_Live_Controller extends Controller $view->pisToday = $today['actions']; return $view; } - -} +}
\ No newline at end of file diff --git a/plugins/Live/Live.php b/plugins/Live/Live.php index d4b6865039..c7fe556fe0 100644 --- a/plugins/Live/Live.php +++ b/plugins/Live/Live.php @@ -27,6 +27,7 @@ class Piwik_Live extends Plugin 'AssetManager.getCssFiles' => 'getCssFiles', 'WidgetsList.add' => 'addWidget', 'Menu.add' => 'addMenu', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); } @@ -52,4 +53,35 @@ class Piwik_Live extends Plugin WidgetsList::add('Live!', 'Live_RealTimeVisitorCount', 'Live', 'getSimpleLastVisitCount'); } + public function getReportDisplayProperties(&$properties) + { + $properties['Live.getLastVisitsDetails'] = $this->getDisplayPropertiesForGetLastVisitsDetails(); + } + + private function getDisplayPropertiesForGetLastVisitsDetails() + { + return array( + 'datatable_template' => "@Live/getVisitorLog.twig", + 'disable_generic_filters' => true, + 'enable_sort' => false, + 'filter_sort_column' => 'idVisit', + 'filter_sort_order' => 'asc', + 'show_search' => false, + 'filter_limit' => 20, + 'show_offset_information' => false, + 'show_exclude_low_population' => false, + 'show_all_views_icons' => false, + 'show_table_all_columns' => false, + 'show_export_as_rss_feed' => false, + 'disable_row_actions' => true, + 'documentation' => Piwik_Translate('Live_VisitorLogDocumentation', array('<br />', '<br />')), + 'custom_parameters' => array( + // set a very high row count so that the next link in the footer of the data table is always shown + 'totalRows' => 10000000, + + 'filterEcommerce' => Piwik_Common::getRequestVar('filterEcommerce', 0, 'int'), + 'pageUrlNotDefined' => Piwik_Translate('General_NotDefined', Piwik_Translate('Actions_ColumnPageURL')) + ), + ); + } } diff --git a/plugins/Live/templates/getVisitorLog.twig b/plugins/Live/templates/getVisitorLog.twig index 4294dbfa06..9c9a520acc 100644 --- a/plugins/Live/templates/getVisitorLog.twig +++ b/plugins/Live/templates/getVisitorLog.twig @@ -2,12 +2,12 @@ data-report="{{ properties.report_id }}" data-params="{{ javascriptVariablesToSet|json_encode }}"> -{% if reportDocumentation is not empty %} - <div class="reportDocumentation"><p>{{ reportDocumentation|raw }}</p></div> +{% if properties.documentation|default is not empty %} + <div class="reportDocumentation"><p>{{ properties.documentation|raw }}</p></div> {% endif %} {% set displayVisitorsInOwnColumn %}{% if isWidget %}0{% else %}1{% endif %}{% endset %} -<span data-graph-id="VisitsSummarygetEvolutionGraph"></span> +<span data-graph-id="VisitsSummary.getEvolutionGraph"></span> {% if error is defined %} {{ error.message }} diff --git a/plugins/Provider/Controller.php b/plugins/Provider/Controller.php index 078e10fb52..afb1e0f41c 100644 --- a/plugins/Provider/Controller.php +++ b/plugins/Provider/Controller.php @@ -22,23 +22,9 @@ class Piwik_Provider_Controller extends Controller * @param bool $fetch * @return string|void */ - function getProvider($fetch = false) + public function getProvider($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, "Provider.getProvider"); - - $this->setPeriodVariablesView($view); - $column = 'nb_visits'; - if ($view->period == 'day') { - $column = 'nb_uniq_visitors'; - } - $view->setColumnsToDisplay(array('label', $column)); - $view->setColumnTranslation('label', Piwik_Translate('Provider_ColumnProvider')); - $view->setSortedColumn($column); - $view->setLimit(5); - $this->setMetricsVariablesView($view); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - } diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php index 1d7b0b0a99..f20e823b95 100644 --- a/plugins/Provider/Provider.php +++ b/plugins/Provider/Provider.php @@ -35,6 +35,7 @@ class Piwik_Provider extends Plugin 'Menu.add' => 'addMenu', 'API.getReportMetadata' => 'getReportMetadata', 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; } @@ -64,7 +65,7 @@ class Piwik_Provider extends Plugin ); } - function install() + public function install() { // add column hostname / hostname ext in the visit table $query = "ALTER IGNORE TABLE `" . Common::prefixTable('log_visit') . "` ADD `location_provider` VARCHAR( 100 ) NULL"; @@ -80,25 +81,25 @@ class Piwik_Provider extends Plugin } - function uninstall() + public function uninstall() { // add column hostname / hostname ext in the visit table $query = "ALTER TABLE `" . Common::prefixTable('log_visit') . "` DROP `location_provider`"; Db::exec($query); } - function addWidget() + public function addWidget() { WidgetsList::add('General_Visitors', 'Provider_WidgetProviders', 'Provider', 'getProvider'); } - function addMenu() + public function addMenu() { Piwik_RenameMenuEntry('General_Visitors', 'UserCountry_SubmenuLocations', 'General_Visitors', 'Provider_SubmenuLocationsProvider'); } - function postLoad() + public function postLoad() { Piwik_AddAction('template_footerUserCountry', array('Piwik_Provider', 'footerUserCountry')); } @@ -213,4 +214,17 @@ class Piwik_Provider extends Plugin $archiving->archivePeriod(); } } + + public function getReportDisplayProperties(&$properties) + { + $properties['Provider.getProvider'] = $this->getDisplayPropertiesForGetProvider(); + } + + private function getDisplayPropertiesForGetProvider() + { + return array( + 'translations' => array('label' => Piwik_Translate('Provider_ColumnProvider')), + 'filter_limit' => 5 + ); + } } diff --git a/plugins/Referers/Controller.php b/plugins/Referers/Controller.php index 072fc1ec4a..e2fe4976d4 100644 --- a/plugins/Referers/Controller.php +++ b/plugins/Referers/Controller.php @@ -24,12 +24,12 @@ use Piwik\Url; */ class Piwik_Referers_Controller extends Controller { - function index() + public function index() { $view = new View('@Referers/index'); $view->graphEvolutionReferers = $this->getEvolutionGraph(true, Common::REFERER_TYPE_DIRECT_ENTRY, array('nb_visits')); - $view->nameGraphEvolutionReferers = 'ReferersgetEvolutionGraph'; + $view->nameGraphEvolutionReferers = 'Referers.getEvolutionGraph'; // building the referers summary report $view->dataTableRefererType = $this->getRefererType(true); @@ -127,7 +127,7 @@ class Piwik_Referers_Controller extends Controller return $result; } - function getSearchEnginesAndKeywords() + public function getSearchEnginesAndKeywords() { $view = new View('@Referers/getSearchEnginesAndKeywords'); $view->searchEngines = $this->getSearchEngines(true); @@ -135,43 +135,9 @@ class Piwik_Referers_Controller extends Controller echo $view->render(); } - function getRefererType($fetch = false) + public function getRefererType($fetch = false) { - $view = ViewDataTable::factory('tableAllColumns'); - $view->init($this->pluginName, - __FUNCTION__, - 'Referers.getRefererType', - 'getRefererType' - ); - $view->disableSearchBox(); - $view->disableOffsetInformationAndPaginationControls(); - $view->disableExcludeLowPopulation(); - $view->disableSubTableWhenShowGoals(); - $view->enableShowGoals(); - $view->setLimit(10); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - - $idSubtable = Common::getRequestVar('idSubtable', false); - $labelColumnTitle = Piwik_Translate('Referers_ColumnRefererType'); - if ($idSubtable !== false) { - switch ($idSubtable) { - case Common::REFERER_TYPE_SEARCH_ENGINE: - $labelColumnTitle = Piwik_Translate('Referers_ColumnSearchEngine'); - break; - case Common::REFERER_TYPE_WEBSITE: - $labelColumnTitle = Piwik_Translate('Referers_ColumnWebsite'); - break; - case Common::REFERER_TYPE_CAMPAIGN: - $labelColumnTitle = Piwik_Translate('Referers_ColumnCampaign'); - break; - default: - break; - } - } - $view->setColumnTranslation('label', $labelColumnTitle); - - $this->setMetricsVariablesView($view); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -184,127 +150,32 @@ class Piwik_Referers_Controller extends Controller */ public function getAll($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Referers.getAll'); - $view->disableExcludeLowPopulation(); - $view->setColumnTranslation('label', Piwik_Translate('Referers_Referrer')); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->enableShowGoals(); - $view->setLimit(20); - $view->setCustomParameter('disable_row_actions', '1'); - - $setGetAllHtmlPrefix = array($this, 'setGetAllHtmlPrefix'); - $view->queueFilter( - 'MetadataCallbackAddMetadata', array('referrer_type', 'html_label_prefix', $setGetAllHtmlPrefix)); - - $view->setMetricsVariablesView($view); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - /** - * DataTable filter callback that returns the HTML prefix for a label in the - * 'getAll' report based on the row's referrer type. - * - * @param int $referrerType The referrer type. - * @return string - */ - public function setGetAllHtmlPrefix($referrerType) + public function getKeywords($fetch = false) { - // get singular label for referrer type - $indexTranslation = ''; - switch ($referrerType) { - case Common::REFERER_TYPE_DIRECT_ENTRY: - $indexTranslation = 'Referers_DirectEntry'; - break; - case Common::REFERER_TYPE_SEARCH_ENGINE: - $indexTranslation = 'Referers_ColumnKeyword'; - break; - case Common::REFERER_TYPE_WEBSITE: - $indexTranslation = 'Referers_ColumnWebsite'; - break; - case Common::REFERER_TYPE_CAMPAIGN: - $indexTranslation = 'Referers_ColumnCampaign'; - break; - default: - // case of newsletter, partners, before Piwik 0.2.25 - $indexTranslation = 'General_Others'; - break; - } - - $label = strtolower(Piwik_Translate($indexTranslation)); - - // return html that displays it as grey & italic - return '<span style="color:#999"><em>(' . $label . ')</em></span>'; - } - - function getKeywords($fetch = false) - { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getKeywords', - 'getSearchEnginesFromKeywordId' - ); - $view->disableExcludeLowPopulation(); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnKeyword')); - $view->enableShowGoals(); - $view->setLimit(25); - $view->disableSubTableWhenShowGoals(); - - $this->setMetricsVariablesView($view); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getSearchEnginesFromKeywordId($fetch = false) + public function getSearchEnginesFromKeywordId($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getSearchEnginesFromKeywordId' - ); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnSearchEngine')); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - - function getSearchEngines($fetch = false) + public function getSearchEngines($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getSearchEngines', - 'getKeywordsFromSearchEngineId' - ); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->enableShowGoals(); - $view->setLimit(25); - $view->disableSubTableWhenShowGoals(); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnSearchEngine')); - - $this->setMetricsVariablesView($view); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getKeywordsFromSearchEngineId($fetch = false) + public function getKeywordsFromSearchEngineId($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getKeywordsFromSearchEngineId' - ); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnKeyword')); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function indexWebsites($fetch = false) + public function indexWebsites($fetch = false) { - $view = new View('@Referers/indexWebsites'); + $view = new Piwik_View('@Referers/indexWebsites'); $view->websites = $this->getWebsites(true); $view->socials = $this->getSocials(true); if ($fetch) { @@ -314,113 +185,41 @@ class Piwik_Referers_Controller extends Controller } } - function getWebsites($fetch = false) + public function getWebsites($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getWebsites', - 'getUrlsFromWebsiteId' - ); - $view->disableExcludeLowPopulation(); - $view->enableShowGoals(); - $view->setLimit(25); - $view->disableSubTableWhenShowGoals(); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnWebsite')); - - $this->setMetricsVariablesView($view); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getSocials($fetch = false) + public function getSocials($fetch = false) { - $view = ViewDataTable::factory('graphPie'); - $view->init($this->pluginName, __FUNCTION__, 'Referers.getSocials', 'getUrlsForSocial'); - $view->disableExcludeLowPopulation(); - $view->setLimit(10); - $view->enableShowGoals(); - $view->disableSubTableWhenShowGoals(); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnSocial')); - - if (empty($_REQUEST['widget'])) { - $view->setFooterMessage(Piwik_Translate('Referers_SocialFooterMessage')); - } - - $this->setMetricsVariablesView($view); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getUrlsForSocial($fetch = false) + public function getUrlsForSocial($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'Referers.getUrlsForSocial'); - $view->disableExcludeLowPopulation(); - $view->setLimit(10); - $view->enableShowGoals(); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnWebsitePage')); - - $this->setMetricsVariablesView($view); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function indexCampaigns($fetch = false) + public function indexCampaigns($fetch = false) { return View::singleReport( Piwik_Translate('Referers_Campaigns'), $this->getCampaigns(true), $fetch); } - function getCampaigns($fetch = false) + public function getCampaigns($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getCampaigns', - 'getKeywordsFromCampaignId' - ); - $view->disableExcludeLowPopulation(); - $view->enableShowGoals(); - $view->setLimit(25); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnCampaign')); - - $help = Piwik_Translate('Referers_CampaignFooterHelp', array('<a target="_blank" href="http://piwik.org/docs/tracking-campaigns/">', - '</a> - <a target="_blank" href="http://piwik.org/docs/tracking-campaigns/url-builder/">', - '</a>' - )); - $view->setFooterMessage($help); - $this->setMetricsVariablesView($view); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getKeywordsFromCampaignId($fetch = false) + public function getKeywordsFromCampaignId($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getKeywordsFromCampaignId' - ); - - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnKeyword')); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getUrlsFromWebsiteId($fetch = false) + public function getUrlsFromWebsiteId($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, - 'Referers.getUrlsFromWebsiteId' - ); - $view->disableSearchBox(); - $view->disableExcludeLowPopulation(); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setColumnTranslation('label', Piwik_Translate('Referers_ColumnWebsitePage')); - $view->setTooltipMetadataName('url'); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } protected function getReferersVisitorsByType($date = false) diff --git a/plugins/Referers/Referers.php b/plugins/Referers/Referers.php index bf87a719ce..abda5df50e 100644 --- a/plugins/Referers/Referers.php +++ b/plugins/Referers/Referers.php @@ -36,6 +36,7 @@ class Piwik_Referers extends Plugin 'Goals.getReportsWithGoalMetrics' => 'getReportsWithGoalMetrics', 'API.getReportMetadata' => 'getReportMetadata', 'API.getSegmentsMetadata' => 'getSegmentsMetadata', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; } @@ -289,4 +290,224 @@ class Piwik_Referers extends Plugin $archiving->archivePeriod(); } } + + public function getReportDisplayProperties(&$properties) + { + $properties['Referers.getRefererType'] = $this->getDisplayPropertiesForGetRefererType(); + $properties['Referers.getAll'] = $this->getDisplayPropertiesForGetAll(); + $properties['Referers.getKeywords'] = $this->getDisplayPropertiesForGetKeywords(); + $properties['Referers.getSearchEnginesFromKeywordId'] = $this->getDisplayPropertiesForGetSearchEnginesFromKeywordId(); + $properties['Referers.getSearchEngines'] = $this->getDisplayPropertiesForGetSearchEngines(); + $properties['Referers.getKeywordsFromSearchEngineId'] = $this->getDisplayPropertiesForGetKeywordsFromSearchEngineId(); + $properties['Referers.getWebsites'] = $this->getDisplayPropertiesForGetWebsites(); + $properties['Referers.getSocials'] = $this->getDisplayPropertiesForGetSocials(); + $properties['Referers.getUrlsForSocial'] = $this->getDisplayPropertiesForGetUrlsForSocial(); + $properties['Referers.getCampaigns'] = $this->getDisplayPropertiesForGetCampaigns(); + $properties['Referers.getKeywordsFromCampaignId'] = $this->getDisplayPropertiesForGetKeywordsFromCampaignId(); + $properties['Referers.getUrlsFromWebsiteId'] = $this->getDisplayPropertiesForGetUrlsFromWebsiteId(); + } + + private function getDisplayPropertiesForGetRefererType() + { + $idSubtable = Piwik_Common::getRequestVar('idSubtable', false); + $labelColumnTitle = Piwik_Translate('Referers_ColumnRefererType'); + switch ($idSubtable) { + case Piwik_Common::REFERER_TYPE_SEARCH_ENGINE: + $labelColumnTitle = Piwik_Translate('Referers_ColumnSearchEngine'); + break; + case Piwik_Common::REFERER_TYPE_WEBSITE: + $labelColumnTitle = Piwik_Translate('Referers_ColumnWebsite'); + break; + case Piwik_Common::REFERER_TYPE_CAMPAIGN: + $labelColumnTitle = Piwik_Translate('Referers_ColumnCampaign'); + break; + default: + break; + } + + return array( + 'default_view_type' => 'tableAllColumns', + 'show_search' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'show_exclude_low_population' => false, + 'disable_subtable_when_show_goals' => true, + 'show_goals' => true, + 'filter_limit' => 10, + 'translations' => array('label' => $labelColumnTitle) + ); + } + + private function getDisplayPropertiesForGetAll() + { + $setGetAllHtmlPrefix = array($this, 'setGetAllHtmlPrefix'); + return array( + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate('Referers_Referrer')), + 'show_goals' => true, + 'filter_limit' => 20, + 'custom_parameters' => array('disable_row_actions' => '1'), + 'filters' => array( + array('MetadataCallbackAddMetadata', array('referrer_type', 'html_label_prefix', $setGetAllHtmlPrefix)) + ) + ); + } + + private function getDisplayPropertiesForGetKeywords() + { + return array( + 'subtable_controller_action' => 'getSearchEnginesFromKeywordId', + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnKeyword')), + 'show_goals' => true, + 'filter_limit' => 25, + 'disable_subtable_when_show_goals' => true, + ); + } + + private function getDisplayPropertiesForGetSearchEnginesFromKeywordId() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnSearchEngine')) + ); + } + + private function getDisplayPropertiesForGetSearchEngines() + { + return array( + 'subtable_controller_action' => 'getKeywordsFromSearchEngineId', + 'show_search' => false, + 'show_exclude_low_population' => false, + 'show_goals' => true, + 'filter_limit' => 25, + 'disable_subtable_when_show_goals' => true, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnSearchEngine')) + ); + } + + private function getDisplayPropertiesForGetKeywordsFromSearchEngineId() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnKeyword')) + ); + } + + private function getDisplayPropertiesForGetWebsites() + { + return array( + 'subtable_controller_action' => 'getUrlsFromWebsiteId', + 'show_exclude_low_population' => false, + 'show_goals' => true, + 'filter_limit' => 25, + 'disable_subtable_when_show_goals' => true, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnWebsite')) + ); + } + + private function getDisplayPropertiesForGetSocials() + { + $result = array( + 'default_view_type' => 'graphPie', + 'subtable_controller_action' => 'getUrlsForSocial', + 'show_exclude_low_population' => false, + 'filter_limit' => 10, + 'show_goals' => true, + 'disable_subtable_when_show_goals' => true, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnSocial')) + ); + + $widget = Piwik_Common::getRequestVar('widget', false); + if (empty($widget)) { + $result['show_footer_message'] = Piwik_Translate('Referers_SocialFooterMessage'); + } + + return $result; + } + + private function getDisplayPropertiesForGetUrlsForSocial() + { + return array( + 'show_exclude_low_population' => false, + 'filter_limit' => 10, + 'show_goals' => true, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnWebsitePage')) + ); + } + + private function getDisplayPropertiesForGetCampaigns() + { + $help = Piwik_Translate('Referers_CampaignFooterHelp', + array('<a target="_blank" href="http://piwik.org/docs/tracking-campaigns/">', + '</a> - <a target="_blank" href="http://piwik.org/docs/tracking-campaigns/url-builder/">', + '</a>') + ); + + return array( + 'subtable_controller_action' => 'getKeywordsFromCampaignId', + 'show_exclude_low_population' => false, + 'show_goals' => true, + 'filter_limit' => 25, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnCampaign')), + 'show_footer_message' => $help, + ); + } + + private function getDisplayPropertiesForGetKeywordsFromCampaignId() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnKeyword')) + ); + } + + private function getDisplayPropertiesForGetUrlsFromWebsiteId() + { + return array( + 'show_search' => false, + 'show_exclude_low_population' => false, + 'translations' => array('label' => Piwik_Translate('Referers_ColumnWebsitePage')), + 'tooltip_metadata_name' => 'url' + ); + } + + /** + * DataTable filter callback that returns the HTML prefix for a label in the + * 'getAll' report based on the row's referrer type. + * + * @param int $referrerType The referrer type. + * @return string + */ + public function setGetAllHtmlPrefix($referrerType) + { + // get singular label for referrer type + $indexTranslation = ''; + switch ($referrerType) { + case Piwik_Common::REFERER_TYPE_DIRECT_ENTRY: + $indexTranslation = 'Referers_DirectEntry'; + break; + case Piwik_Common::REFERER_TYPE_SEARCH_ENGINE: + $indexTranslation = 'Referers_ColumnKeyword'; + break; + case Piwik_Common::REFERER_TYPE_WEBSITE: + $indexTranslation = 'Referers_ColumnWebsite'; + break; + case Piwik_Common::REFERER_TYPE_CAMPAIGN: + $indexTranslation = 'Referers_ColumnCampaign'; + break; + default: + // case of newsletter, partners, before Piwik 0.2.25 + $indexTranslation = 'General_Others'; + break; + } + + $label = strtolower(Piwik_Translate($indexTranslation)); + + // return html that displays it as grey & italic + return '<span class="datatable-label-category"><em>(' . $label . ')</em></span>'; + } } diff --git a/plugins/Transitions/javascripts/transitions.js b/plugins/Transitions/javascripts/transitions.js index 6f0a633bec..da6c8a8bc2 100644 --- a/plugins/Transitions/javascripts/transitions.js +++ b/plugins/Transitions/javascripts/transitions.js @@ -415,10 +415,10 @@ Piwik_Transitions.prototype.renderLoops = function () { Piwik_Transitions.prototype.renderEntries = function (onlyBg) { if (this.model.directEntries > 0) { var self = this; - var gradient = this.canvas.createHorizontalGradient('#FFFFFF', '#BACFE8', 'left'); - if (this.highlightedGroup == 'directEntries') { - gradient = this.canvas.createHorizontalGradient('#FFFFFF', '#FAD293', 'left'); - } + + var isHighlighted = this.highlightedGroup == 'directEntries'; + var gradient = this.canvas.createHorizontalGradient('entries', 'left', isHighlighted); + this.canvas.renderBox({ side: 'left', onlyBg: onlyBg, @@ -442,10 +442,10 @@ Piwik_Transitions.prototype.renderEntries = function (onlyBg) { Piwik_Transitions.prototype.renderExits = function (onlyBg) { if (this.model.exits > 0) { var self = this; - var gradient = this.canvas.createHorizontalGradient('#FFFFFF', '#BACFE8', 'right'); - if (this.highlightedGroup == 'exits') { - gradient = this.canvas.createHorizontalGradient('#FFFFFF', '#FAD293', 'right'); - } + + var isHighlighted = this.highlightedGroup == 'exits'; + var gradient = this.canvas.createHorizontalGradient('exits', 'right', isHighlighted); + this.canvas.renderBox({ side: 'right', onlyBg: onlyBg, @@ -481,12 +481,10 @@ Piwik_Transitions.prototype.renderOpenGroup = function (groupName, side, onlyBg) var details = self.model.getDetailsForGroup(groupName); // prepare gradients - var gradientItems = this.canvas.createHorizontalGradient('#E3DFD1', '#E8E4D5', side); - var gradientOthers = this.canvas.createHorizontalGradient('#F5F3EB', '#E8E4D5', side); - var gradientBackground = this.canvas.createHorizontalGradient('#FFFFFF', '#BACFE8', side); - if (groupName == this.highlightedGroup) { - gradientBackground = this.canvas.createHorizontalGradient('#FFFFFF', '#FAD293', side); - } + var gradientItems = this.canvas.createHorizontalGradient('items', side); + var gradientOthers = this.canvas.createHorizontalGradient('others', side); + var gradientBackground = + this.canvas.createHorizontalGradient('background', side, groupName == this.highlightedGroup); // remember current offsets to reset them later for drawing the background var boxPositionBefore, curvePositionBefore; @@ -600,10 +598,9 @@ Piwik_Transitions.prototype.renderOpenGroup = function (groupName, side, onlyBg) /** Render a closed group without detailed data, only one box for the sum */ Piwik_Transitions.prototype.renderClosedGroup = function (groupName, side, onlyBg) { var self = this; - var gradient = this.canvas.createHorizontalGradient('#DDE4ED', '#9BBADE', side); - if (groupName == this.highlightedGroup) { - gradient = this.canvas.createHorizontalGradient('#FAE2C0', '#FAD293', side); - } + + var isHighlighted = groupName == this.highlightedGroup; + var gradient = this.canvas.createHorizontalGradient('closed-group', side, isHighlighted); var nbTransitionsVarName = groupName + 'NbTransitions'; @@ -782,6 +779,16 @@ function Piwik_Transitions_Canvas(canvasBgLeft, canvasBgRight, canvasLeft, canva this.rightBoxEndX = this.width; this.rightBoxBeginX = this.rightCurveEndX = this.rightBoxEndX - this.boxWidth; this.rightCurveBeginX = this.rightCurveEndX - this.curveWidth; + + // load gradient colors from CSS + this.colors = {}; + + var transitionsColorNamespaces = ['entries', 'exits', 'background', 'closed-group', 'items', 'others', 'loops']; + var gradientColorNames = ['light', 'dark', 'light-highlighted', 'dark-highlighted']; + for (var i = 0; i != transitionsColorNamespaces.length; ++i) { + var namespace = 'transition-' + transitionsColorNamespaces[i]; + this.colors[namespace] = piwik.ColorManager.getColors(namespace, gradientColorNames); + } } /** @@ -800,13 +807,22 @@ Piwik_Transitions_Canvas.prototype.isNarrowMode = function () { /** * Helper to create horizontal gradients - * + * TODO * @param lightColor * @param darkColor * @param position left|right */ -Piwik_Transitions_Canvas.prototype.createHorizontalGradient = function (lightColor, darkColor, position) { - var fromX, toX, fromColor, toColor; +Piwik_Transitions_Canvas.prototype.createHorizontalGradient = function (colorGroup, position, isHighlighted) { + var fromX, toX, fromColor, toColor, lightColor, darkColor; + + colorGroup = 'transition-' + colorGroup; + if (isHighlighted) { + lightColor = this.colors[colorGroup]['light-highlighted']; + darkColor = this.colors[colorGroup]['dark-highlighted']; + } else { + lightColor = this.colors[colorGroup]['light']; + darkColor = this.colors[colorGroup]['dark']; + } if (position == 'left') { // gradient is used to fill a box on the left @@ -1109,8 +1125,8 @@ Piwik_Transitions_Canvas.prototype.renderLoops = function (share) { // create gradient var gradient = this.contextLoops.createLinearGradient(this.leftCurveEndX - 50, 0, this.rightCurveBeginX + 50, 0); - var light = '#F5F3EB'; - var dark = '#E8E4D5'; + var light = this.colors['transition-loops']['light']; + var dark = this.colors['transition-loops']['dark']; gradient.addColorStop(0, dark); gradient.addColorStop(.5, light); gradient.addColorStop(1, dark); diff --git a/plugins/UserCountry/Controller.php b/plugins/UserCountry/Controller.php index 1fcd911832..0faed8db82 100644 --- a/plugins/UserCountry/Controller.php +++ b/plugins/UserCountry/Controller.php @@ -24,7 +24,7 @@ use Piwik\Url; */ class Piwik_UserCountry_Controller extends Admin { - function index() + public function index() { $view = new View('@UserCountry/index'); @@ -39,7 +39,7 @@ class Piwik_UserCountry_Controller extends Admin echo $view->render(); } - function adminIndex() + public function adminIndex() { Piwik::checkUserIsSuperUser(); $view = new View('@UserCountry/adminIndex'); @@ -319,23 +319,14 @@ class Piwik_UserCountry_Controller extends Admin echo $location; } - function getCountry($fetch = false) + public function getCountry($fetch = false) { - $view = $this->getStandardDataTableUserCountry(__FUNCTION__, "UserCountry.getCountry"); - $view->setLimit(5); - $view->setColumnTranslation('label', Piwik_Translate('UserCountry_Country')); - $view->setReportDocumentation(Piwik_Translate('UserCountry_getCountryDocumentation')); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getContinent($fetch = false) + public function getContinent($fetch = false) { - $view = $this->getStandardDataTableUserCountry(__FUNCTION__, "UserCountry.getContinent", 'table'); - $view->disableSearchBox(); - $view->disableOffsetInformationAndPaginationControls(); - $view->setColumnTranslation('label', Piwik_Translate('UserCountry_Continent')); - $view->setReportDocumentation(Piwik_Translate('UserCountry_getContinentDocumentation')); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -346,13 +337,7 @@ class Piwik_UserCountry_Controller extends Admin */ public function getRegion($fetch = false) { - $view = $this->getStandardDataTableUserCountry(__FUNCTION__, "UserCountry.getRegion"); - $view->setLimit(5); - $view->setColumnTranslation('label', Piwik_Translate('UserCountry_Region')); - $view->setReportDocumentation(Piwik_Translate('UserCountry_getRegionDocumentation') . '<br/>' - . $this->getGeoIPReportDocSuffix()); - $this->checkIfNoDataForGeoIpReport($view); - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -363,47 +348,15 @@ class Piwik_UserCountry_Controller extends Admin */ public function getCity($fetch = false) { - $view = $this->getStandardDataTableUserCountry(__FUNCTION__, "UserCountry.getCity"); - $view->setLimit(5); - $view->setColumnTranslation('label', Piwik_Translate('UserCountry_City')); - $view->setReportDocumentation(Piwik_Translate('UserCountry_getCityDocumentation') . '<br/>' - . $this->getGeoIPReportDocSuffix()); - $this->checkIfNoDataForGeoIpReport($view); - return $this->renderView($view, $fetch); - } - - private function getGeoIPReportDocSuffix() - { - return Piwik_Translate('UserCountry_GeoIPDocumentationSuffix', array( - '<a target="_blank" href="http://www.maxmind.com/?rId=piwik">', - '</a>', - '<a target="_blank" href="http://www.maxmind.com/en/city_accuracy?rId=piwik">', - '</a>' - )); - } - - protected function getStandardDataTableUserCountry($currentControllerAction, - $APItoCall, - $defaultDatatableType = null) - { - $view = ViewDataTable::factory($defaultDatatableType); - $view->init($this->pluginName, $currentControllerAction, $APItoCall); - $view->disableExcludeLowPopulation(); - - $this->setPeriodVariablesView($view); - $this->setMetricsVariablesView($view); - - $view->enableShowGoals(); - - return $view; + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } - function getNumberOfDistinctCountries($fetch = false) + public function getNumberOfDistinctCountries($fetch = false) { return $this->getNumericValue('UserCountry.getNumberOfDistinctCountries'); } - function getLastDistinctCountriesGraph($fetch = false) + public function getLastDistinctCountriesGraph($fetch = false) { $view = $this->getLastUnitGraph('UserCountry', __FUNCTION__, "UserCountry.getNumberOfDistinctCountries"); $view->setColumnsToDisplay('UserCountry_distinctCountries'); @@ -411,50 +364,6 @@ class Piwik_UserCountry_Controller extends Admin } /** - * Checks if a datatable for a view is empty and if so, displays a message in the footer - * telling users to configure GeoIP. - */ - private function checkIfNoDataForGeoIpReport($view) - { - // only display on HTML tables since the datatable for HTML graphs aren't accessible - if (!($view instanceof Piwik_ViewDataTable_HtmlTable)) { - return; - } - - // if there's only one row whose label is 'Unknown', display a message saying there's no data - $view->main(); - $dataTable = $view->getDataTable(); - if ($dataTable->getRowsCount() == 1 - && $dataTable->getFirstRow()->getColumn('label') == Piwik_Translate('General_Unknown') - ) { - $footerMessage = Piwik_Translate('UserCountry_NoDataForGeoIPReport1'); - - // if GeoIP is working, don't display this part of the message - if (!$this->isGeoIPWorking()) { - $params = array('module' => 'UserCountry', 'action' => 'adminIndex'); - $footerMessage .= ' ' . Piwik_Translate('UserCountry_NoDataForGeoIPReport2', array( - '<a target="_blank" href="' . Url::getCurrentQueryStringWithParametersModified($params) . '">', - '</a>', - '<a target="_blank" href="http://dev.maxmind.com/geoip/geolite?rId=piwik">', - '</a>' - )); - } else { - $footerMessage .= ' ' . Piwik_Translate('UserCountry_ToGeolocateOldVisits', array( - '<a target="_blank" href="http://piwik.org/faq/how-to/#faq_167">', - '</a>' - )); - } - - // HACK! Can't use setFooterMessage because the view gets built in the main function, - // so instead we set the property by hand. - $realView = $view->getView(); - $properties = $realView->properties; - $properties['show_footer_message'] = $footerMessage; - $realView->properties = $properties; - } - } - - /** * Gets information for the first missing GeoIP database (if any). * * @return bool @@ -476,17 +385,4 @@ class Piwik_UserCountry_Controller extends Admin } return false; } - - /** - * Returns true if a GeoIP provider is installed & working, false if otherwise. - * - * @return bool - */ - private function isGeoIPWorking() - { - $provider = Piwik_UserCountry_LocationProvider::getCurrentProvider(); - return $provider instanceof Piwik_UserCountry_LocationProvider_GeoIp - && $provider->isAvailable() === true - && $provider->isWorking() === true; - } -} +}
\ No newline at end of file diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index bd970a6ec7..37566f19d6 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -43,6 +43,7 @@ class Piwik_UserCountry extends Plugin 'AssetManager.getJsFiles' => 'getJsFiles', 'Tracker.getVisitorLocation' => 'getVisitorLocation', 'TaskScheduler.getScheduledTasks' => 'getScheduledTasks', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; } @@ -88,7 +89,7 @@ class Piwik_UserCountry extends Plugin Common::printDebug("GEO: Found IP location (provider '" . $id . "'): " . var_export($location, true)); } - function addWidgets() + public function addWidgets() { $widgetContinentLabel = Piwik_Translate('UserCountry_WidgetLocation') . ' (' . Piwik_Translate('UserCountry_Continent') . ')'; @@ -105,7 +106,7 @@ class Piwik_UserCountry extends Plugin WidgetsList::add('General_Visitors', $widgetCityLabel, 'UserCountry', 'getCity'); } - function addMenu() + public function addMenu() { Piwik_AddMenu('General_Visitors', 'UserCountry_SubmenuLocations', array('module' => 'UserCountry', 'action' => 'index')); } @@ -113,7 +114,7 @@ class Piwik_UserCountry extends Plugin /** * Event handler. Adds menu items to the Admin menu. */ - function addAdminMenu() + public function addAdminMenu() { Piwik_AddAdminSubMenu('General_Settings', 'UserCountry_Geolocation', array('module' => 'UserCountry', 'action' => 'adminIndex'), @@ -282,4 +283,119 @@ class Piwik_UserCountry extends Plugin return array('SQL' => "'" . implode("', '", $result) . "', ?", 'bind' => '-'); // HACK: SegmentExpression requires a $bind, even if there's nothing to bind } + + public function getReportDisplayProperties(&$properties) + { + $properties['UserCountry.getCountry'] = $this->getDisplayPropertiesForGetCountry(); + $properties['UserCountry.getContinent'] = $this->getDisplayPropertiesForGetContinent(); + $properties['UserCountry.getRegion'] = $this->getDisplayPropertiesForGetRegion(); + $properties['UserCountry.getCity'] = $this->getDisplayPropertiesForGetCity(); + } + + private function getDisplayPropertiesForGetCountry() + { + return array( + 'show_exclude_low_population' => false, + 'show_goals' => true, + 'filter_limit' => 5, + 'translations' => array('label' => Piwik_Translate('UserCountry_Country')), + 'documentation' => Piwik_Translate('UserCountry_getCountryDocumentation') + ); + } + + private function getDisplayPropertiesForGetContinent() + { + return array( + 'show_exclude_low_population' => false, + 'show_goals' => true, + 'show_search' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'translations' => array('label' => Piwik_Translate('UserCountry_Continent')), + 'documentation' => Piwik_Translate('UserCountry_getContinentDocumentation') + ); + } + + private function getDisplayPropertiesForGetRegion() + { + $result = array( + 'show_exclude_low_population' => false, + 'show_goals' => true, + 'filter_limit' => 5, + 'translations' => array('label' => Piwik_Translate('UserCountry_Region')), + 'documentation' => Piwik_Translate('UserCountry_getRegionDocumentation') . '<br/>' + . $this->getGeoIPReportDocSuffix() + ); + $this->checkIfNoDataForGeoIpReport($result); + return $result; + } + + private function getDisplayPropertiesForGetCity() + { + $result = array( + 'show_exclude_low_population' => false, + 'show_goals' => true, + 'filter_limit' => 5, + 'translations' => array('label' => Piwik_Translate('UserCountry_City')), + 'documentation' => Piwik_Translate('UserCountry_getCityDocumentation') . '<br/>' + . $this->getGeoIPReportDocSuffix() + ); + $this->checkIfNoDataForGeoIpReport($result); + return $result; + } + + private function getGeoIPReportDocSuffix() + { + return Piwik_Translate('UserCountry_GeoIPDocumentationSuffix', + array('<a target="_blank" href="http://www.maxmind.com/?rId=piwik">', + '</a>', + '<a target="_blank" href="http://www.maxmind.com/en/city_accuracy?rId=piwik">', + '</a>') + ); + } + + /** + * Checks if a datatable for a view is empty and if so, displays a message in the footer + * telling users to configure GeoIP. + */ + private function checkIfNoDataForGeoIpReport(&$properties) + { + $self = $this; + $properties['filters'][] = function ($dataTable, $view) use ($self) { + // if there's only one row whose label is 'Unknown', display a message saying there's no data + if ($dataTable->getRowsCount() == 1 + && $dataTable->getFirstRow()->getColumn('label') == Piwik_Translate('General_Unknown') + ) { + $footerMessage = Piwik_Translate('UserCountry_NoDataForGeoIPReport1'); + + // if GeoIP is working, don't display this part of the message + if (!$self->isGeoIPWorking()) { + $params = array('module' => 'UserCountry', 'action' => 'adminIndex'); + $footerMessage .= ' ' . Piwik_Translate('UserCountry_NoDataForGeoIPReport2', + array('<a target="_blank" href="' . Piwik_Url::getCurrentQueryStringWithParametersModified($params) . '">', + '</a>', + '<a target="_blank" href="http://dev.maxmind.com/geoip/geolite?rId=piwik">', + '</a>')); + } else { + $footerMessage .= ' ' . Piwik_Translate('UserCountry_ToGeolocateOldVisits', + array('<a target="_blank" href="http://piwik.org/faq/how-to/#faq_167">', '</a>')); + } + + $view->setFooterMessage($footerMessage); + } + }; + } + + /** + * Returns true if a GeoIP provider is installed & working, false if otherwise. + * + * @return bool + */ + public function isGeoIPWorking() + { + $provider = Piwik_UserCountry_LocationProvider::getCurrentProvider(); + return $provider instanceof Piwik_UserCountry_LocationProvider_GeoIp + && $provider->isAvailable() === true + && $provider->isWorking() === true; + } } diff --git a/plugins/UserCountryMap/Controller.php b/plugins/UserCountryMap/Controller.php index a70e3a83d7..1470a5e4cf 100644 --- a/plugins/UserCountryMap/Controller.php +++ b/plugins/UserCountryMap/Controller.php @@ -157,7 +157,7 @@ class Piwik_UserCountryMap_Controller extends Controller { $params['format'] = 'json'; $params['showRawMetrics'] = 1; - $segment = ViewDataTable::getRawSegmentFromRequest(); + $segment = \Piwik\API\Request::getRawSegmentFromRequest(); if(!empty($segment)) { $params['segment'] = $segment; } @@ -207,7 +207,7 @@ class Piwik_UserCountryMap_Controller extends Controller . "&period=" . $period . "&date=" . $date . "&token_auth=" . $token_auth - . "&segment=" . ViewDataTable::getRawSegmentFromRequest() + . "&segment=" . \Piwik\API\Request::getRawSegmentFromRequest() . "&enable_filter_excludelowpop=1" . "&showRawMetrics=1"; diff --git a/plugins/UserSettings/Archiver.php b/plugins/UserSettings/Archiver.php index cdfa858d6e..8ce5c83b88 100644 --- a/plugins/UserSettings/Archiver.php +++ b/plugins/UserSettings/Archiver.php @@ -18,7 +18,12 @@ use Piwik\PluginsArchiver; require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php'; -class Piwik_UserSettings_Archiver extends PluginsArchiver +/** + * Archiver for UserSettings Plugin + * + * @see Piwik_PluginsArchiver + */ +class Piwik_UserSettings_Archiver extends Piwik_PluginsArchiver { const LANGUAGE_RECORD_NAME = 'UserSettings_language'; const PLUGIN_RECORD_NAME = 'UserSettings_plugin'; diff --git a/plugins/UserSettings/Controller.php b/plugins/UserSettings/Controller.php index 086cd020e7..b064e3b5b8 100644 --- a/plugins/UserSettings/Controller.php +++ b/plugins/UserSettings/Controller.php @@ -36,56 +36,56 @@ class Piwik_UserSettings_Controller extends Controller public function getResolution($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getConfiguration($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOS($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getOSFamily($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getMobileVsDesktop($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserVersion($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowser($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getBrowserType($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getWideScreen($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getPlugin($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getLanguage($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/UserSettings/UserSettings.php b/plugins/UserSettings/UserSettings.php index 1c71dc5a1e..3795d0d6fd 100644 --- a/plugins/UserSettings/UserSettings.php +++ b/plugins/UserSettings/UserSettings.php @@ -173,7 +173,7 @@ class Piwik_UserSettings extends Plugin return $hooks; } - public function getReportDisplayProperties(&$properties, $apiAction) + public function getReportDisplayProperties(&$properties) { $basicUserSettingsProperties = array('show_search' => false, 'show_exclude_low_population' => false, @@ -195,94 +195,88 @@ class Piwik_UserSettings extends Plugin 'UserSettings.getWideScreen' => Piwik_Translate('UserSettings_ColumnTypeOfScreen') ); - $reportViewProperties = array( - 'UserSettings.getResolution' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnResolution')) - )), + $properties['UserSettings.getResolution'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnResolution')) + )); - 'UserSettings.getConfiguration' => array_merge($basicUserSettingsProperties, array( - 'filter_limit' => 3, - 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnConfiguration')) - )), + $properties['UserSettings.getConfiguration'] = array_merge($basicUserSettingsProperties, array( + 'filter_limit' => 3, + 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnConfiguration')) + )); - 'UserSettings.getOS' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnOperatingSystem')), - 'title' => Piwik_Translate('UserSettings_OperatingSystems'), - 'relatedReports' => $osRelatedReports - )), + $properties['UserSettings.getOS'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnOperatingSystem')), + 'title' => Piwik_Translate('UserSettings_OperatingSystems'), + 'relatedReports' => $osRelatedReports + )); - 'UserSettings.getOSFamily' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_OperatingSystemFamily')), - 'title' => Piwik_Translate('UserSettings_OperatingSystemFamily'), - 'relatedReports' => $osRelatedReports - )), + $properties['UserSettings.getOSFamily'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_OperatingSystemFamily')), + 'title' => Piwik_Translate('UserSettings_OperatingSystemFamily'), + 'relatedReports' => $osRelatedReports + )); - 'UserSettings.getBrowserVersion' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnBrowserVersion')), - 'graph_limit' => 7, - 'title' => Piwik_Translate('UserSettings_ColumnBrowserVersion'), - 'relatedReports' => $browserRelatedReports - )), + $properties['UserSettings.getBrowserVersion'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnBrowserVersion')), + 'graph_limit' => 7, + 'title' => Piwik_Translate('UserSettings_ColumnBrowserVersion'), + 'relatedReports' => $browserRelatedReports + )); - 'UserSettings.getBrowser' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnBrowser')), - 'graph_limit' => 7, - 'title' => Piwik_Translate('UserSettings_Browsers'), - 'relatedReports' => $browserRelatedReports - )), + $properties['UserSettings.getBrowser'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnBrowser')), + 'graph_limit' => 7, + 'title' => Piwik_Translate('UserSettings_Browsers'), + 'relatedReports' => $browserRelatedReports + )); - 'UserSettings.getBrowserType' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnBrowserFamily')), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'default_view_type' => 'graphPie', - )), + $properties['UserSettings.getBrowserType'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnBrowserFamily')), + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'default_view_type' => 'graphPie', + )); - 'UserSettings.getWideScreen' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnTypeOfScreen')), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'title' => Piwik_Translate('UserSettings_ColumnTypeOfScreen'), - 'relatedReports' => $wideScreenDeviceTypeRelatedReports - )), + $properties['UserSettings.getWideScreen'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_ColumnTypeOfScreen')), + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'title' => Piwik_Translate('UserSettings_ColumnTypeOfScreen'), + 'relatedReports' => $wideScreenDeviceTypeRelatedReports + )); - 'UserSettings.getMobileVsDesktop' => array_merge($basicUserSettingsProperties, array( - 'translations' => array('label' => Piwik_Translate('UserSettings_MobileVsDesktop')), - 'title' => Piwik_Translate('UserSettings_MobileVsDesktop'), - 'relatedReports' => $wideScreenDeviceTypeRelatedReports - )), - - 'UserSettings.getPlugin' => array_merge($basicUserSettingsProperties, array( - 'translations' => array( - 'label' => Piwik_Translate('UserSettings_ColumnPlugin'), - 'nb_visits_percentage' => - str_replace(' ', ' ', Piwik_Translate('General_ColumnPercentageVisits')) - ), - 'show_offset_information' => false, - 'show_pagination_control' => false, - 'show_all_views_icons' => false, - 'show_table_all_columns' => false, - 'columns_to_display' => array('label', 'nb_visits_percentage', 'nb_visits'), - 'filter_sort_column' => 'nb_visits_percentage', - 'filter_sort_order' => 'desc', - 'filter_limit' => 10, - 'show_footer_message' => Piwik_Translate('UserSettings_PluginDetectionDoesNotWorkInIE'), - )), - - 'UserSettings.getLanguage' => array( - 'translations' => array('label' => Piwik_Translate('General_Language')), - 'filter_sort_column' => 'nb_visits', - 'filter_sort_order' => 'desc', - 'show_search' => false, - 'filter_limit' => false, - 'columns_to_display' => array('label', 'nb_visits'), - 'show_exclude_low_population' => false, + $properties['UserSettings.getMobileVsDesktop'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array('label' => Piwik_Translate('UserSettings_MobileVsDesktop')), + 'title' => Piwik_Translate('UserSettings_MobileVsDesktop'), + 'relatedReports' => $wideScreenDeviceTypeRelatedReports + )); + + $properties['UserSettings.getPlugin'] = array_merge($basicUserSettingsProperties, array( + 'translations' => array( + 'label' => Piwik_Translate('UserSettings_ColumnPlugin'), + 'nb_visits_percentage' => + str_replace(' ', ' ', Piwik_Translate('General_ColumnPercentageVisits')) ), + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'show_all_views_icons' => false, + 'show_table_all_columns' => false, + 'columns_to_display' => array('label', 'nb_visits_percentage', 'nb_visits'), + 'filter_sort_column' => 'nb_visits_percentage', + 'filter_sort_order' => 'desc', + 'filter_limit' => 10, + 'show_footer_message' => Piwik_Translate('UserSettings_PluginDetectionDoesNotWorkInIE'), + )); + + $properties['UserSettings.getLanguage'] = array( + 'translations' => array('label' => Piwik_Translate('General_Language')), + 'filter_sort_column' => 'nb_visits', + 'filter_sort_order' => 'desc', + 'show_search' => false, + 'filter_limit' => false, + 'columns_to_display' => array('label', 'nb_visits'), + 'show_exclude_low_population' => false, ); - - if (isset($reportViewProperties[$apiAction])) { - $properties = $reportViewProperties[$apiAction]; - } } /** diff --git a/plugins/VisitFrequency/templates/index.twig b/plugins/VisitFrequency/templates/index.twig index f3af02c1ad..d701bdae33 100644 --- a/plugins/VisitFrequency/templates/index.twig +++ b/plugins/VisitFrequency/templates/index.twig @@ -1,6 +1,6 @@ {{ postEvent("template_headerVisitsFrequency") }} -<h2 data-graph-id="VisitFrequencygetEvolutionGraph">{{ 'VisitFrequency_ColumnReturningVisits'|translate }}</h2> +<h2 data-graph-id="VisitFrequency.getEvolutionGraph">{{ 'VisitFrequency_ColumnReturningVisits'|translate }}</h2> {{ graphEvolutionVisitFrequency|raw }} <br/> diff --git a/plugins/VisitTime/Controller.php b/plugins/VisitTime/Controller.php index 1cc2169741..97698e1de8 100644 --- a/plugins/VisitTime/Controller.php +++ b/plugins/VisitTime/Controller.php @@ -28,16 +28,16 @@ class Piwik_VisitTime_Controller extends Controller public function getVisitInformationPerServerTime($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getVisitInformationPerLocalTime($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getByDayOfWeek($fetch = false) { - return ViewDataTable::render($this->pluginName, __FUNCTION__, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index f4e4232d39..c1285f61cd 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -117,7 +117,7 @@ class Piwik_VisitTime extends Plugin ); } - public function getReportDisplayProperties(&$properties, $apiAction) + public function getReportDisplayProperties(&$properties) { $commonProperties = array( 'filter_sort_column' => 'label', @@ -129,45 +129,39 @@ class Piwik_VisitTime extends Plugin 'default_view_type' => 'graphVerticalBar' ); - $reportViewProperties = array( - 'VisitTime.getVisitInformationPerServerTime' => array_merge($commonProperties, array( - 'filter_limit' => 24, - 'graph_limit' => null, - 'show_goals' => true, - 'translations' => array('label' => Piwik_Translate('VisitTime_ColumnServerTime')), - - // custom parameter - 'hideFutureHoursWhenToday' => 1, - )), + $properties['VisitTime.getVisitInformationPerServerTime'] = array_merge($commonProperties, array( + 'filter_limit' => 24, + 'graph_limit' => null, + 'show_goals' => true, + 'translations' => array('label' => Piwik_Translate('VisitTime_ColumnServerTime')), - 'VisitTime.getVisitInformationPerLocalTime' => array_merge($commonProperties, array( - 'filter_limit' => 24, - 'graph_limit' => null, - 'title' => Piwik_Translate('VisitTime_ColumnLocalTime'), - 'translations' => array('label' => Piwik_Translate('VisitTime_LocalTime')), - )), + // custom parameter + 'hideFutureHoursWhenToday' => 1, + )); - 'VisitTime.getByDayOfWeek' => array_merge($commonProperties, array( - 'filter_limit' => 7, - 'graph_limit' => null, - 'enable_sort' => false, - 'show_all_ticks' => true, - 'show_footer_message' => - Piwik_Translate('General_ReportGeneratedFrom', self::getDateRangeForFooterMessage()), - 'translations' => array('label' => Piwik_Translate('VisitTime_DayOfWeek')), - )), - ); + $properties['VisitTime.getVisitInformationPerLocalTime'] = array_merge($commonProperties, array( + 'filter_limit' => 24, + 'graph_limit' => null, + 'title' => Piwik_Translate('VisitTime_ColumnLocalTime'), + 'translations' => array('label' => Piwik_Translate('VisitTime_LocalTime')), + )); + + $properties['VisitTime.getByDayOfWeek'] = array_merge($commonProperties, array( + 'filter_limit' => 7, + 'graph_limit' => null, + 'enable_sort' => false, + 'show_all_ticks' => true, + 'show_footer_message' => + Piwik_Translate('General_ReportGeneratedFrom', self::getDateRangeForFooterMessage()), + 'translations' => array('label' => Piwik_Translate('VisitTime_DayOfWeek')), + )); // add the visits by day of week as a related report, if the current period is not 'day' if (Common::getRequestVar('period', 'day') != 'day') { - $reportViewProperties['VisitTime.getVisitInformationPerLocalTime']['relatedReports'] = array( + $properties['VisitTime.getVisitInformationPerLocalTime']['relatedReports'] = array( 'VisitTime.getByDayOfWeek' => Piwik_Translate('VisitTime_VisitsByDayOfWeek') ); } - - if (isset($reportViewProperties[$apiAction])) { - $properties = $reportViewProperties[$apiAction]; - } } public function archivePeriod(ArchiveProcessor\Period $archiveProcessor) @@ -190,12 +184,16 @@ class Piwik_VisitTime extends Plugin private static function getDateRangeForFooterMessage() { // get query params - $idSite = Common::getRequestVar('idSite'); - $date = Common::getRequestVar('date'); - $period = Common::getRequestVar('period'); + $idSite = Common::getRequestVar('idSite', false); + $date = Common::getRequestVar('date', false); + $period = Common::getRequestVar('period', false); // create a period instance - $oPeriod = Period::makePeriodFromQueryParams(Site::getTimezoneFor($idSite), $period, $date); + try { + $oPeriod = Period::makePeriodFromQueryParams(Piwik_Site::getTimezoneFor($idSite), $period, $date); + } catch (Exception $ex) { + return ''; // if query params are incorrect, forget about the footer message + } // set the footer message using the period start & end date $start = $oPeriod->getDateStart()->toString(); diff --git a/plugins/VisitorInterest/Controller.php b/plugins/VisitorInterest/Controller.php index b3a658f5c8..4b601ca9fd 100644 --- a/plugins/VisitorInterest/Controller.php +++ b/plugins/VisitorInterest/Controller.php @@ -30,37 +30,12 @@ class Piwik_VisitorInterest_Controller extends Controller public function getNumberOfVisitsPerVisitDuration($fetch = false) { - $view = ViewDataTable::factory('cloud'); - $view->init($this->pluginName, __FUNCTION__, "VisitorInterest.getNumberOfVisitsPerVisitDuration"); - - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setSortedColumn('label', 'asc'); - $view->setColumnTranslation('label', Piwik_Translate('VisitorInterest_ColumnVisitDuration')); - $view->setGraphLimit(10); - $view->disableSort(); - $view->disableExcludeLowPopulation(); - $view->disableOffsetInformationAndPaginationControls(); - $view->disableSearchBox(); - $view->disableShowAllColumns(); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } public function getNumberOfVisitsPerPage($fetch = false) { - $view = ViewDataTable::factory('cloud'); - $view->init($this->pluginName, __FUNCTION__, "VisitorInterest.getNumberOfVisitsPerPage"); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setSortedColumn('label', 'asc'); - $view->setColumnTranslation('label', Piwik_Translate('VisitorInterest_ColumnPagesPerVisit')); - $view->setGraphLimit(10); - $view->disableExcludeLowPopulation(); - $view->disableOffsetInformationAndPaginationControls(); - $view->disableSearchBox(); - $view->disableSort(); - $view->disableShowAllColumns(); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -72,21 +47,7 @@ class Piwik_VisitorInterest_Controller extends Controller */ public function getNumberOfVisitsByVisitCount($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, "VisitorInterest.getNumberOfVisitsByVisitCount"); - $view->setColumnsToDisplay(array('label', 'nb_visits', 'nb_visits_percentage')); - $view->setSortedColumn('label', 'asc'); - $view->setColumnTranslation('label', Piwik_Translate('VisitorInterest_VisitNum')); - $view->setColumnTranslation('nb_visits_percentage', Metrics::getPercentVisitColumn()); - $view->disableExcludeLowPopulation(); - $view->disableOffsetInformationAndPaginationControls(); - $view->disableShowAllViewsIcons(); - $view->setLimit(15); - $view->disableSearchBox(); - $view->disableSort(); - $view->disableShowAllColumns(); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } /** @@ -98,19 +59,6 @@ class Piwik_VisitorInterest_Controller extends Controller */ public function getNumberOfVisitsByDaysSinceLast($fetch = false) { - $view = ViewDataTable::factory(); - $view->init($this->pluginName, __FUNCTION__, 'VisitorInterest.getNumberOfVisitsByDaysSinceLast'); - $view->setColumnsToDisplay(array('label', 'nb_visits')); - $view->setSortedColumn('label', 'asc'); - $view->setColumnTranslation('label', Piwik_Translate('General_DaysSinceLastVisit')); - $view->disableExcludeLowPopulation(); - $view->disableOffsetInformationAndPaginationControls(); - $view->disableShowAllViewsIcons(); - $view->setLimit(15); - $view->disableSearchBox(); - $view->disableSort(); - $view->disableShowAllColumns(); - - return $this->renderView($view, $fetch); + return Piwik_ViewDataTable::renderReport($this->pluginName, __FUNCTION__, $fetch); } } diff --git a/plugins/VisitorInterest/VisitorInterest.php b/plugins/VisitorInterest/VisitorInterest.php index f61bbeabd0..a46eae1104 100644 --- a/plugins/VisitorInterest/VisitorInterest.php +++ b/plugins/VisitorInterest/VisitorInterest.php @@ -30,6 +30,7 @@ class Piwik_VisitorInterest extends Plugin 'WidgetsList.add' => 'addWidgets', 'Menu.add' => 'addMenu', 'API.getReportMetadata' => 'getReportMetadata', + 'ViewDataTable.getReportDisplayProperties' => 'getReportDisplayProperties', ); return $hooks; } @@ -95,7 +96,7 @@ class Piwik_VisitorInterest extends Plugin ); } - function addWidgets() + public function addWidgets() { WidgetsList::add('General_Visitors', 'VisitorInterest_WidgetLengths', 'VisitorInterest', 'getNumberOfVisitsPerVisitDuration'); WidgetsList::add('General_Visitors', 'VisitorInterest_WidgetPages', 'VisitorInterest', 'getNumberOfVisitsPerPage'); @@ -103,7 +104,7 @@ class Piwik_VisitorInterest extends Plugin WidgetsList::add('General_Visitors', 'VisitorInterest_WidgetVisitsByDaysSinceLast', 'VisitorInterest', 'getNumberOfVisitsByDaysSinceLast'); } - function addMenu() + public function addMenu() { Piwik_RenameMenuEntry('General_Visitors', 'VisitFrequency_SubmenuFrequency', 'General_Visitors', 'VisitorInterest_Engagement'); @@ -144,4 +145,86 @@ class Piwik_VisitorInterest extends Plugin $out .= FrontController::getInstance()->fetchDispatch('VisitorInterest', 'index'); $out .= '</div>'; } + + public function getReportDisplayProperties(&$properties) + { + $properties['VisitorInterest.getNumberOfVisitsPerVisitDuration'] = + $this->getDisplayPropertiesForGetNumberOfVisitsPerVisitDuration(); + $properties['VisitorInterest.getNumberOfVisitsPerPage'] = + $this->getDisplayPropertiesForGetNumberOfVisitsPerPage(); + $properties['VisitorInterest.getNumberOfVisitsByVisitCount'] = + $this->getDisplayPropertiesForGetNumberOfVisitsByVisitCount(); + $properties['VisitorInterest.getNumberOfVisitsByDaysSinceLast'] = + $this->getDisplayPropertiesForGetNumberOfVisitsByDaysSinceLast(); + } + + private function getDisplayPropertiesForGetNumberOfVisitsPerVisitDuration() + { + return array( + 'default_view_type' => 'cloud', + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array('label' => Piwik_Translate('VisitorInterest_ColumnVisitDuration')), + 'graph_limit' => 10, + 'enable_sort' => false, + 'show_exclude_low_population' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'show_search' => false, + 'show_table_all_columns' => false, + ); + } + + private function getDisplayPropertiesForGetNumberOfVisitsPerPage() + { + return array( + 'default_view_type' => 'cloud', + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array('label' => Piwik_Translate('VisitorInterest_ColumnPagesPerVisit')), + 'graph_limit' => 10, + 'enable_sort' => false, + 'show_exclude_low_population' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'show_search' => false, + 'show_table_all_columns' => false, + ); + } + + private function getDisplayPropertiesForGetNumberOfVisitsByVisitCount() + { + return array( + 'columns_to_display' => array('label', 'nb_visits', 'nb_visits_percentage'), + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array('label' => Piwik_Translate('VisitorInterest_VisitNum'), + 'nb_visits_percentage' => Piwik_Metrics::getPercentVisitColumn()), + 'show_exclude_low_population' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'filter_limit' => 15, + 'show_search' => false, + 'enable_sort' => false, + 'show_table_all_columns' => false, + 'show_all_views_icons' => false, + ); + } + + private function getDisplayPropertiesForGetNumberOfVisitsByDaysSinceLast() + { + return array( + 'filter_sort_column' => 'label', + 'filter_sort_order' => 'asc', + 'translations' => array('label' => Piwik_Translate('General_DaysSinceLastVisit')), + 'show_exclude_low_population' => false, + 'show_offset_information' => false, + 'show_pagination_control' => false, + 'show_all_views_icons' => false, + 'filter_limit' => 15, + 'show_search' => false, + 'enable_sort' => false, + 'show_table_all_columns' => false + ); + } } diff --git a/plugins/VisitsSummary/Controller.php b/plugins/VisitsSummary/Controller.php index fc32e77e9e..c67b850249 100644 --- a/plugins/VisitsSummary/Controller.php +++ b/plugins/VisitsSummary/Controller.php @@ -138,7 +138,7 @@ class Piwik_VisitsSummary_Controller extends Controller $dataTableVisit = self::getVisitsSummary(); $dataRow = $dataTableVisit->getRowsCount() == 0 ? new Row() : $dataTableVisit->getFirstRow(); - $dataTableActions = Piwik_Actions_API::getInstance()->get($idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), ViewDataTable::getRawSegmentFromRequest()); + $dataTableActions = Piwik_Actions_API::getInstance()->get($idSite, Piwik_Common::getRequestVar('period'), Piwik_Common::getRequestVar('date'), Piwik_API_Request::getRawSegmentFromRequest()); $dataActionsRow = $dataTableActions->getRowsCount() == 0 ? new Row() : $dataTableActions->getFirstRow(); diff --git a/plugins/VisitsSummary/templates/index.twig b/plugins/VisitsSummary/templates/index.twig index fad6c86bff..cd0ca19ade 100644 --- a/plugins/VisitsSummary/templates/index.twig +++ b/plugins/VisitsSummary/templates/index.twig @@ -1,5 +1,5 @@ {# This graphId must be unique for this report #} -<h2 data-graph-id="VisitsSummarygetEvolutionGraph">{{ 'Referers_Evolution'|translate }}</h2> +<h2 data-graph-id="VisitsSummary.getEvolutionGraph">{{ 'Referers_Evolution'|translate }}</h2> {{ graphEvolutionVisitsSummary|raw }} diff --git a/plugins/Zeitgeist/colors.piwik.json b/plugins/Zeitgeist/colors.piwik.json deleted file mode 100644 index d2ca30e80e..0000000000 --- a/plugins/Zeitgeist/colors.piwik.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "colors": {} -} diff --git a/plugins/Zeitgeist/stylesheets/base.less b/plugins/Zeitgeist/stylesheets/base.less index d4a014f807..4f593a9c92 100644 --- a/plugins/Zeitgeist/stylesheets/base.less +++ b/plugins/Zeitgeist/stylesheets/base.less @@ -2,7 +2,7 @@ /* base.css is automatically generated. DO NOT MODIFY */ -/* Genreral styles */ +/* General styles */ @import "general/_default.less"; @import "general/_utils.less"; @@ -11,6 +11,7 @@ @import "general/_jqueryUI.less"; +@import "general/_misc.less"; /* Component styles */ @import "ui/_header.less"; @@ -25,6 +26,11 @@ @import "ui/_loading.less"; +@import "ui/_sparkline.less"; + +@import "ui/_jqplot.less"; + +@import "ui/_transitions.less"; /* Remote components */ @import "../../CoreHome/stylesheets/_donate.less"; diff --git a/plugins/Zeitgeist/stylesheets/general/_misc.less b/plugins/Zeitgeist/stylesheets/general/_misc.less new file mode 100644 index 0000000000..38ef9f463f --- /dev/null +++ b/plugins/Zeitgeist/stylesheets/general/_misc.less @@ -0,0 +1,7 @@ +#topApiRef { + color: #95AECB; +} + +.exception-backtrace { + color: #888; +}
\ No newline at end of file diff --git a/plugins/Zeitgeist/stylesheets/general/_utils.less b/plugins/Zeitgeist/stylesheets/general/_utils.less index ae8f0915b5..0077685734 100644 --- a/plugins/Zeitgeist/stylesheets/general/_utils.less +++ b/plugins/Zeitgeist/stylesheets/general/_utils.less @@ -45,6 +45,14 @@ html.old-ie .ie-hide { opacity: 0.75; } +.metricEvolution > .positive-evolution { + color: green; +} + +.metricEvolution > .negative-evolution { + color: #e02a3b; +} + .reportsByDimensionView > .entityList { float: left; width: 220px; diff --git a/plugins/Zeitgeist/stylesheets/ui/_dataTable.less b/plugins/Zeitgeist/stylesheets/ui/_dataTable.less new file mode 100644 index 0000000000..f4303658c0 --- /dev/null +++ b/plugins/Zeitgeist/stylesheets/ui/_dataTable.less @@ -0,0 +1,3 @@ +.datatable-label-category { + color:#999; +}
\ No newline at end of file diff --git a/plugins/Zeitgeist/stylesheets/ui/_jqplot.less b/plugins/Zeitgeist/stylesheets/ui/_jqplot.less new file mode 100644 index 0000000000..b8f47543d2 --- /dev/null +++ b/plugins/Zeitgeist/stylesheets/ui/_jqplot.less @@ -0,0 +1,150 @@ +// evolution graph colors +.evolution-graph-colors[data-name=series1] { + color: #5170AE; +} + +.evolution-graph-colors[data-name=series2] { + color: #F29007; +} + +.evolution-graph-colors[data-name=series3] { + color: #CC3399; +} + +.evolution-graph-colors[data-name=series4] { + color: #9933CC; +} + +.evolution-graph-colors[data-name=series5] { + color: #80a033; +} + +.evolution-graph-colors[data-name=series6] { + color: #246AD2; +} + +.evolution-graph-colors[data-name=series7] { + color: #FD16EA; +} + +.evolution-graph-colors[data-name=series8] { + color: #49C100; +} + +.evolution-graph-colors[data-name=grid-background] { + color: #fff; +} + +.evolution-graph-colors[data-name=grid-border] { + color: #f00; +} + +.evolution-graph-colors[data-name=ticks] { + color: #ccc; +} + +.evolution-graph-colors[data-name=single-metric-label] { + color: #666; +} + +// bar graph colors +.bar-graph-colors[data-name=series1] { + color: #5170AE; +} + +.bar-graph-colors[data-name=series2] { + color: #F3A010; +} + +.bar-graph-colors[data-name=series3] { + color: #CC3399; +} + +.bar-graph-colors[data-name=series4] { + color: #9933CC; +} + +.bar-graph-colors[data-name=series5] { + color: #80a033; +} + +.bar-graph-colors[data-name=series6] { + color: #246AD2; +} + +.bar-graph-colors[data-name=series7] { + color: #FD16EA; +} + +.bar-graph-colors[data-name=series8] { + color: #49C100; +} + +.bar-graph-colors[data-name=grid-background] { + color: #fff; +} + +.bar-graph-colors[data-name=grid-border] { + color: #f00; +} + +.bar-graph-colors[data-name=ticks] { + color: #ccc; +} + +.bar-graph-colors[data-name=single-metric-label] { + color: #666; +} + +// pie graph colors +.pie-graph-colors[data-name=series1] { + color: #59727F; +} + +.pie-graph-colors[data-name=series2] { + color: #7DAAC0; +} + +.pie-graph-colors[data-name=series3] { + color: #7F7259; +} + +.pie-graph-colors[data-name=series4] { + color: #C09E7D; +} + +.pie-graph-colors[data-name=series5] { + color: #9BB39B; +} + +.pie-graph-colors[data-name=series6] { + color: #B1D8B3; +} + +.pie-graph-colors[data-name=series7] { + color: #B39BA7; +} + +.pie-graph-colors[data-name=series8] { + color: #D8B1C5; +} + +.pie-graph-colors[data-name=series9] { + color: #A5A5A5; +} + +.pie-graph-colors[data-name=grid-background] { + color: #fff; +} + +.pie-graph-colors[data-name=grid-border] { + color: #f00; +} + +.pie-graph-colors[data-name=ticks] { + color: #ccc; +} + +.pie-graph-colors[data-name=single-metric-label] { + color: #666; +} diff --git a/plugins/Zeitgeist/stylesheets/ui/_sparkline.less b/plugins/Zeitgeist/stylesheets/ui/_sparkline.less new file mode 100644 index 0000000000..7d2b9c7c8b --- /dev/null +++ b/plugins/Zeitgeist/stylesheets/ui/_sparkline.less @@ -0,0 +1,26 @@ +// sparkline styles +div.sparkline { + border-bottom: 1px solid white; +} + +div.sparkline:hover { + cursor: pointer; + border-bottom: 1px dashed #c3c3c3; +} + +// sparkline colors +.sparkline-colors[data-name=lineColor] { + color: rgb(22, 44, 74); +} + +.sparkline-colors[data-name=red] { + color: #ff7f7f; +} + +.sparkline-colors[data-name=blue] { + color: #55AAFF; +} + +.sparkline-colors[data-name=green] { + color: #75BF7C; +} diff --git a/plugins/Zeitgeist/stylesheets/ui/_transitions.less b/plugins/Zeitgeist/stylesheets/ui/_transitions.less new file mode 100644 index 0000000000..e74d16b341 --- /dev/null +++ b/plugins/Zeitgeist/stylesheets/ui/_transitions.less @@ -0,0 +1,98 @@ +// +// transitions colors +// + +// colors for entries gradients +.transition-entries[data-name=light] { + color: #fff; +} + +.transition-entries[data-name=dark] { + color: #BACFE8; +} + +.transition-entries[data-name=light-highlighted] { + color: #fff; +} + +.transition-entries[data-name=dark-highlighted] { + color: #FAD293; +} + +// colors for exits gradients +.transition-exits[data-name=light] { + color: #fff; +} + +.transition-exits[data-name=dark] { + color: #BACFE8; +} + +.transition-exits[data-name=light-highlighted] { + color: #fff; +} + +.transition-exits[data-name=dark-highlighted] { + color: #FAD293; +} + +// background gradients colors +.transition-background[data-name=light] { + color: #fff; +} + +.transition-background[data-name=dark] { + color: #BACFE8; +} + +.transition-background[data-name=light-highlighted] { + color: #fff; +} + +.transition-background[data-name=dark-highlighted] { + color: #FAD293; +} + +// closed group gradient colors +.transition-closed-group[data-name=light] { + color: #DDE4ED; +} + +.transition-closed-group[data-name=dark] { + color: #9BBADE; +} + +.transition-closed-group[data-name=light-highlighted] { + color: #FAE2C0; +} + +.transition-closed-group[data-name=dark-highlighted] { + color: #FAD293; +} + +// items gradient colors +.transition-items[data-name=light] { + color: #E3DFD1; +} + +.transition-items[data-name=dark] { + color: #E8E4D5; +} + +// 'others' gradients colors +.transition-others[data-name=light] { + color: #F5F3EB; +} + +.transition-others[data-name=dark] { + color: #E8E4D5; +} + +// loop gradient colors +.transition-loops[data-name=light] { + color: #F5F3EB; +} + +.transition-loops[data-name=dark] { + color: #E8E4D5; +}
\ No newline at end of file |