Skip to content
Extraits de code Groupes Projets
Valider ab58fe9d rédigé par mattab's avatar mattab
Parcourir les fichiers

Fixes #4659 Fix if statement logic ftw.

Let's see if build is still passing
parent 32015796
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -141,9 +141,9 @@ class GoalManager ...@@ -141,9 +141,9 @@ class GoalManager
foreach ($goals as $goal) { foreach ($goals as $goal) {
$attribute = $goal['match_attribute']; $attribute = $goal['match_attribute'];
// if the attribute to match is not the type of the current action // if the attribute to match is not the type of the current action
if (($actionType == Action::TYPE_PAGE_URL && $attribute != 'url' && $attribute != 'title') if ( (($attribute == 'url' || $attribute == 'title') && $actionType != Action::TYPE_PAGE_URL)
|| ($actionType == Action::TYPE_DOWNLOAD && $attribute != 'file') || ($attribute == 'file' && $actionType != Action::TYPE_DOWNLOAD)
|| ($actionType == Action::TYPE_OUTLINK && $attribute != 'external_website') || ($attribute == 'external_website' && $actionType != Action::TYPE_OUTLINK)
|| ($attribute == 'manually') || ($attribute == 'manually')
) { ) {
continue; continue;
...@@ -156,40 +156,7 @@ class GoalManager ...@@ -156,40 +156,7 @@ class GoalManager
} }
$pattern_type = $goal['pattern_type']; $pattern_type = $goal['pattern_type'];
switch ($pattern_type) { $match = $this->isUrlMatchingGoal($goal, $pattern_type, $url);
case 'regex':
$pattern = $goal['pattern'];
if (strpos($pattern, '/') !== false
&& strpos($pattern, '\\/') === false
) {
$pattern = str_replace('/', '\\/', $pattern);
}
$pattern = '/' . $pattern . '/';
if (!$goal['case_sensitive']) {
$pattern .= 'i';
}
$match = (@preg_match($pattern, $url) == 1);
break;
case 'contains':
if ($goal['case_sensitive']) {
$matched = strpos($url, $goal['pattern']);
} else {
$matched = stripos($url, $goal['pattern']);
}
$match = ($matched !== false);
break;
case 'exact':
if ($goal['case_sensitive']) {
$matched = strcmp($goal['pattern'], $url);
} else {
$matched = strcasecmp($goal['pattern'], $url);
}
$match = ($matched == 0);
break;
default:
throw new Exception(Piwik::translate('General_ExceptionInvalidGoalPattern', array($pattern_type)));
break;
}
if ($match) { if ($match) {
$goal['url'] = $decodedActionUrl; $goal['url'] = $decodedActionUrl;
$this->convertedGoals[] = $goal; $this->convertedGoals[] = $goal;
...@@ -887,4 +854,50 @@ class GoalManager ...@@ -887,4 +854,50 @@ class GoalManager
} }
} }
} }
/**
* @param $goal
* @param $pattern_type
* @param $url
* @return bool
* @throws \Exception
*/
protected function isUrlMatchingGoal($goal, $pattern_type, $url)
{
switch ($pattern_type) {
case 'regex':
$pattern = $goal['pattern'];
if (strpos($pattern, '/') !== false
&& strpos($pattern, '\\/') === false
) {
$pattern = str_replace('/', '\\/', $pattern);
}
$pattern = '/' . $pattern . '/';
if (!$goal['case_sensitive']) {
$pattern .= 'i';
}
$match = (@preg_match($pattern, $url) == 1);
break;
case 'contains':
if ($goal['case_sensitive']) {
$matched = strpos($url, $goal['pattern']);
} else {
$matched = stripos($url, $goal['pattern']);
}
$match = ($matched !== false);
break;
case 'exact':
if ($goal['case_sensitive']) {
$matched = strcmp($goal['pattern'], $url);
} else {
$matched = strcasecmp($goal['pattern'], $url);
}
$match = ($matched == 0);
break;
default:
throw new Exception(Piwik::translate('General_ExceptionInvalidGoalPattern', array($pattern_type)));
break;
}
return $match;
}
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter