protected function gapi::processFilter in Google Analytics Statistics 7
Same name and namespace in other branches
- 7.2 includes/gapi.class.php \gapi::processFilter()
- 7.x inc/gapi.class.php \gapi::processFilter()
Process filter string, clean parameters and convert to Google Analytics compatible format
Parameters
String $filter:
Return value
String Compatible filter string
1 call to gapi::processFilter()
- gapi::requestReportData in includes/
gapi.class.php - Request report data from Google Analytics
File
- includes/
gapi.class.php, line 230
Class
- gapi
- GAPI - Google Analytics PHP Interface
Code
protected function processFilter($filter) {
$valid_operators = '(!~|=~|==|!=|>|<|>=|<=|=@|!@)';
$filter = preg_replace('/\\s\\s+/', ' ', trim($filter));
//Clean duplicate whitespace
$filter = str_replace(array(
',',
';',
), array(
'\\,',
'\\;',
), $filter);
//Escape Google Analytics reserved characters
$filter = preg_replace('/(&&\\s*|\\|\\|\\s*|^)([a-z]+)(\\s*' . $valid_operators . ')/i', '$1ga:$2$3', $filter);
//Prefix ga: to metrics and dimensions
$filter = preg_replace('/[\'\\"]/i', '', $filter);
//Clear invalid quote characters
$filter = preg_replace(array(
'/\\s*&&\\s*/',
'/\\s*\\|\\|\\s*/',
'/\\s*' . $valid_operators . '\\s*/',
), array(
';',
',',
'$1',
), $filter);
//Clean up operators
if (strlen($filter) > 0) {
return urlencode($filter);
}
else {
return false;
}
}