diff options
-rw-r--r-- | core/API/ResponseBuilder.php | 40 | ||||
-rw-r--r-- | core/DataTable/Filter.php | 3 | ||||
-rw-r--r-- | core/ViewDataTable.php | 12 | ||||
-rw-r--r-- | core/ViewDataTable/Html.php | 11 | ||||
-rw-r--r-- | libs/jquery/truncate/jquery.truncate.js | 33 |
5 files changed, 65 insertions, 34 deletions
diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php index 09b117dded..25e855f563 100644 --- a/core/API/ResponseBuilder.php +++ b/core/API/ResponseBuilder.php @@ -129,12 +129,17 @@ class Piwik_API_ResponseBuilder * Returns an array containing the information of the generic Piwik_DataTable_Filter * to be applied automatically to the data resulting from the API calls. * + * Order to apply the filters: + * 1 - Filter that remove filtered rows + * 2 - Filter that sort the remaining rows + * 3 - Filter that keep only a subset of the results + * 4 - Presentation filters + * * @return array See the code for spec */ public static function getGenericFiltersInformation() { $genericFilters = array( - 'Pattern' => array( 'filter_column' => array('string'), 'filter_pattern' => array('string'), @@ -143,6 +148,10 @@ class Piwik_API_ResponseBuilder 'filter_column_recursive' => array('string'), 'filter_pattern_recursive' => array('string'), ), + 'ExactMatch' => array( + 'filter_exact_column' => array('string'), + 'filter_exact_pattern' => array('array'), + ), 'ExcludeLowPopulation' => array( 'filter_excludelowpop' => array('string'), 'filter_excludelowpop_value'=> array('float'), @@ -155,9 +164,8 @@ class Piwik_API_ResponseBuilder 'filter_offset' => array('integer', '0'), 'filter_limit' => array('integer', Zend_Registry::get('config')->General->dataTable_default_limit), ), - 'ExactMatch' => array( - 'filter_exact_column' => array('string'), - 'filter_exact_pattern' => array('array'), + 'SafeDecodeLabel' => array( + 'filter_safe_decode_label' => array('integer') ), ); @@ -337,6 +345,12 @@ class Piwik_API_ResponseBuilder */ protected function applyDataTableGenericFilters($dataTable) { + // if the flag disable_generic_filters is defined we skip the generic filters + if(Piwik_Common::getRequestVar('disable_generic_filters', 'false', 'string', $this->request) != 'false') + { + return; + } + if($dataTable instanceof Piwik_DataTable_Array ) { $tables = $dataTable->getArray(); @@ -347,22 +361,8 @@ class Piwik_API_ResponseBuilder return; } - // Generic filters - // PatternFileName => Parameter names to match to constructor parameters - /* - * Order to apply the filters: - * 1 - Filter that remove filtered rows - * 2 - Filter that sort the remaining rows - * 3 - Filter that keep only a subset of the results - */ $genericFilters = self::getGenericFiltersInformation(); - // if the flag disable_generic_filters is defined we skip the generic filters - if(Piwik_Common::getRequestVar('disable_generic_filters', 'false', 'string', $this->request) != 'false') - { - return; - } - foreach($genericFilters as $filterName => $parameters) { $filterParameters = array(); @@ -405,10 +405,8 @@ class Piwik_API_ResponseBuilder // build the set of parameters for the filter $filterParameters = array_merge(array($dataTable), $filterParameters); - // make a reflection object + // use Reflection to create a new instance of the filter, given parameters $filterParameters $reflectionObj = new ReflectionClass($class); - - // use Reflection to create a new instance, using the $args $filter = $reflectionObj->newInstanceArgs($filterParameters); } } diff --git a/core/DataTable/Filter.php b/core/DataTable/Filter.php index 86afcba3e6..b3fe5cc70e 100644 --- a/core/DataTable/Filter.php +++ b/core/DataTable/Filter.php @@ -57,4 +57,5 @@ require_once "DataTable/Filter/ReplaceColumnNames.php"; require_once "DataTable/Filter/Sort.php"; require_once "DataTable/Filter/AddSummaryRow.php"; require_once "DataTable/Filter/ReplaceSummaryRowLabel.php"; -require_once "DataTable/Filter/ExactMatch.php";
+require_once "DataTable/Filter/ExactMatch.php"; +require_once "DataTable/Filter/SafeDecodeLabel.php";
diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php index 7f95c4b544..0123d03644 100644 --- a/core/ViewDataTable.php +++ b/core/ViewDataTable.php @@ -287,6 +287,7 @@ abstract class Piwik_ViewDataTable $this->showFooter = Piwik_Common::getRequestVar('showDataTableFooter', true); $this->variablesDefault['filter_excludelowpop_default'] = 'false'; $this->variablesDefault['filter_excludelowpop_value_default'] = 'false'; + $this->setSafeDecodeLabel(); } /** @@ -366,6 +367,7 @@ abstract class Piwik_ViewDataTable 'filter_exact_column',
'disable_generic_filters', 'disable_queued_filters', + 'filter_safe_decode_label' ); foreach($toSetEventually as $varToSet) { @@ -765,6 +767,16 @@ abstract class Piwik_ViewDataTable } /** + * The 'label' column in the datatable will be safely url decoded. + * + * @return void + */ + public function setSafeDecodeLabel() + { + $this->variablesDefault['filter_safe_decode_label'] = '1'; + } + + /** * Sets a custom parameter, that will be printed in the javascript array associated with each datatable * * @param string parameter name diff --git a/core/ViewDataTable/Html.php b/core/ViewDataTable/Html.php index 6062339923..21e99910ef 100644 --- a/core/ViewDataTable/Html.php +++ b/core/ViewDataTable/Html.php @@ -76,18 +76,9 @@ class Piwik_ViewDataTable_Html extends Piwik_ViewDataTable $this->mainAlreadyExecuted = true; $this->loadDataTableFromAPI(); - - // We apply a filter to the DataTable, decoding the label column (useful for keywords for example) - $filter = new Piwik_DataTable_Filter_ColumnCallbackReplace( - $this->dataTable, - 'label', - create_function('$txt', 'return htmlspecialchars(urldecode($txt));') - ); - + $view = new Piwik_View($this->dataTableTemplate); - - // We get the PHP array converted from the DataTable $phpArray = $this->getPHPArrayFromDataTable(); $view->arrayDataTable = $phpArray; diff --git a/libs/jquery/truncate/jquery.truncate.js b/libs/jquery/truncate/jquery.truncate.js index 8285e687bf..21e0180352 100644 --- a/libs/jquery/truncate/jquery.truncate.js +++ b/libs/jquery/truncate/jquery.truncate.js @@ -1,3 +1,32 @@ -jQuery.fn.truncate=function(max){return this.each(function(){var trail='...';if(jQuery(this).children().length==0) -{v=jQuery.trim(jQuery(this).text());while(max<v.length){c=v.charAt(max);newStringTruncated=v.substring(0,max)+trail;charToRemove='"';regExp=new RegExp("["+charToRemove+"]","g");vCleaned=v.replace(regExp,"'");html='<span class="truncated" title="'+vCleaned+'">'+newStringTruncated+'</span>';jQuery(this).html(html);break;max--;}}});};
\ No newline at end of file +jQuery.fn.truncate = function(max) { + return this.each( + function() { + var trail='...'; + if(jQuery(this).children().length==0) { + v=jQuery.trim(jQuery(this).text()); + while(max<v.length) { + c=v.charAt(max); + newStringTruncated=v.substring(0,max)+trail; + charToRemove='"'; + regExp=new RegExp("["+charToRemove+"]","g"); + vCleaned = v + .replace(regExp,"&quot;") + .replace(/</g, '&lt;') + .replace(/>/g, '&gt;'); + newStringTruncated = newStringTruncated + .replace(regExp,"'") + .replace(/</g, '<') + .replace(/>/g, '>'); + html='<span class="truncated" title="'+vCleaned+'">'+newStringTruncated+'</span>'; + console.log(vCleaned); + console.log(newStringTruncated); + console.log(html); + jQuery(this).html(html); + break; + max--; + } + } + } + ); +};
\ No newline at end of file |