예제 #1
0
 /**
  * Convert segment expression to an action ID or an SQL expression.
  *
  * This method is used as a sqlFilter-callback for the segments of this plugin.
  * Usually, these callbacks only return a value that should be compared to the
  * column in the database. In this case, that doesn't work since multiple IDs
  * can match an expression (e.g. "pageUrl=@foo").
  * @param string $valueToMatch
  * @param string $sqlField
  * @param string $matchType
  * @param string $segmentName
  * @throws \Exception
  * @return array|int|string
  */
 public static function getIdActionFromSegment($valueToMatch, $sqlField, $matchType, $segmentName)
 {
     $actionType = self::guessActionTypeFromSegment($segmentName);
     if ($actionType == Action::TYPE_PAGE_URL) {
         // for urls trim protocol and www because it is not recorded in the db
         $valueToMatch = preg_replace('@^http[s]?://(www\\.)?@i', '', $valueToMatch);
     }
     $valueToMatch = self::normaliseActionString($actionType, $valueToMatch);
     if ($matchType == SegmentExpression::MATCH_EQUAL || $matchType == SegmentExpression::MATCH_NOT_EQUAL) {
         $idAction = self::getModel()->getIdActionMatchingNameAndType($valueToMatch, $actionType);
         // Action is not found (eg. &segment=pageTitle==Větrnásssssss)
         if (empty($idAction)) {
             $idAction = null;
         }
         return $idAction;
     }
     // "name contains $string" match can match several idaction so we cannot return yet an idaction
     // special case
     $sql = TableLogAction::getSelectQueryWhereNameContains($matchType, $actionType);
     return array('SQL' => $sql, 'bind' => $valueToMatch);
 }
예제 #2
0
 /**
  * Convert segment expression to an action ID or an SQL expression.
  *
  * This method is used as a sqlFilter-callback for the segments of this plugin.
  * Usually, these callbacks only return a value that should be compared to the
  * column in the database. In this case, that doesn't work since multiple IDs
  * can match an expression (e.g. "pageUrl=@foo").
  * @param string $valueToMatch
  * @param string $sqlField
  * @param string $matchType
  * @param string $segmentName
  * @throws \Exception
  * @return array|int|string
  */
 public static function getIdActionFromSegment($valueToMatch, $sqlField, $matchType, $segmentName)
 {
     $actionType = self::guessActionTypeFromSegment($segmentName);
     if ($actionType == Action::TYPE_PAGE_URL) {
         // for urls trim protocol and www because it is not recorded in the db
         $valueToMatch = preg_replace('@^http[s]?://(www\\.)?@i', '', $valueToMatch);
     }
     $valueToMatch = Common::sanitizeInputValue(Common::unsanitizeInputValue($valueToMatch));
     if ($matchType == SegmentExpression::MATCH_EQUAL || $matchType == SegmentExpression::MATCH_NOT_EQUAL) {
         $idAction = self::getIdActionMatchingNameAndType($valueToMatch, $actionType);
         // if the action is not found, we hack -100 to ensure it tries to match against an integer
         // otherwise binding idaction_name to "false" returns some rows for some reasons (in case &segment=pageTitle==Větrnásssssss)
         if (empty($idAction)) {
             $idAction = -100;
         }
         return $idAction;
     }
     // "name contains $string" match can match several idaction so we cannot return yet an idaction
     // special case
     $sql = TableLogAction::getSelectQueryWhereNameContains($matchType, $actionType);
     return array('SQL' => $sql, 'bind' => $valueToMatch);
 }