Piwik\Common::unsanitizeInputValues PHP Méthode

unsanitizeInputValues() public static méthode

This method should be used when you need to unescape data that was obtained from the user. Some data in Piwik is stored sanitized (such as site name). In this case you may have to use this method to unsanitize it in order to, for example, output it in JSON.
public static unsanitizeInputValues ( string | array $value ) : string | array
$value string | array The data to unsanitize. If an array is passed, the array is sanitized recursively. Key values are not unsanitized.
Résultat string | array The unsanitized data.
    public static function unsanitizeInputValues($value)
    {
        if (is_array($value)) {
            $result = array();
            foreach ($value as $key => $arrayValue) {
                $result[$key] = self::unsanitizeInputValues($arrayValue);
            }
            return $result;
        } else {
            return self::unsanitizeInputValue($value);
        }
    }

Usage Example

 public function getCustomVariables($scope)
 {
     if ($scope == 'visit') {
         $parameter = '_cvar';
     } else {
         $parameter = 'cvar';
     }
     $customVar = Common::unsanitizeInputValues(Common::getRequestVar($parameter, '', 'json', $this->params));
     if (!is_array($customVar)) {
         return array();
     }
     $customVariables = array();
     foreach ($customVar as $id => $keyValue) {
         $id = (int) $id;
         if ($id < 1 || $id > Tracker::MAX_CUSTOM_VARIABLES || count($keyValue) != 2 || !is_string($keyValue[0]) && !is_numeric($keyValue[0])) {
             Common::printDebug("Invalid custom variables detected (id={$id})");
             continue;
         }
         if (strlen($keyValue[1]) == 0) {
             $keyValue[1] = "";
         }
         // We keep in the URL when Custom Variable have empty names
         // and values, as it means they can be deleted server side
         $key = self::truncateCustomVariable($keyValue[0]);
         $value = self::truncateCustomVariable($keyValue[1]);
         $customVariables['custom_var_k' . $id] = $key;
         $customVariables['custom_var_v' . $id] = $value;
     }
     return $customVariables;
 }
All Usage Examples Of Piwik\Common::unsanitizeInputValues