urlDecode() public static method

public static urlDecode ( $string )
Example #1
0
 /**
  * Converts given primary values from type string into proper normalized array definition.
  * This builds the array for the $pk for all of these methods inside this class.
  *
  * The primaryKey comes primarily from the REST API.
  *
  *    admin/object/news/1
  *    admin/objects?uri=news/1/2
  * where
  *    admin/object/news/<id>
  *    admin/objects?uri=news/<id>
  *
  * is this ID.
  *
  * 1/2/3 => array( array(id =>1),array(id =>2),array(id =>3) )
  * 1 => array(array(id => 1))
  * idFooBar => array( id => "idFooBar")
  * idFoo/Bar => array(array(id => idFoo), array(id2 => "Bar"))
  * 1,45/2,45 => array(array(id => 1, pid = 45), array(id => 2, pid=>45))
  *
  * @param  string $pk
  *
  * @return array  Always a array with primary keys as arrays too. So $return[0] is the first primary key array. Example array(array('id' => 4))
  */
 public function primaryStringToArray($pk)
 {
     if ($pk === '') {
         return false;
     }
     $groups = explode('/', $pk);
     $result = array();
     foreach ($groups as $group) {
         $item = array();
         if ('' === $group) {
             continue;
         }
         $primaryGroups = explode(',', $group);
         foreach ($primaryGroups as $pos => $value) {
             if ($ePos = strpos($value, '=')) {
                 $key = substr($value, 0, $ePos);
                 $value = substr($value, $ePos + 1);
                 if (!in_array($key, $this->primaryKeys)) {
                     continue;
                 }
             } elseif (!$this->primaryKeys[$pos]) {
                 continue;
             }
             $key = $this->primaryKeys[$pos];
             $item[$key] = Tools::urlDecode($value);
         }
         if (count($this->primaryKeys) > count($item)) {
             foreach ($this->primaryKeys as $pk2) {
                 if (!@$item[$pk2]) {
                     $item[$pk2] = null;
                 }
             }
         }
         if (count($item) > 0) {
             $result[] = $item;
         }
     }
     return $result;
 }
Example #2
0
 public function setValue($value)
 {
     parent::setValue(Tools::urlDecode($value));
 }
Example #3
0
 /**
  * Get a condition object for item listings.
  *
  * @param  string $objectKey
  *
  * @return Condition
  */
 public function getListingCondition($objectKey)
 {
     $objectKey = Objects::normalizeObjectKey($objectKey);
     $obj = $this->objects->getStorageController($objectKey);
     $rules = self::getRules($objectKey, static::MODE_LISTING);
     if (count($rules) === 0) {
         return null;
     }
     if ($this->getCaching()) {
         $cacheKey = md5($objectKey);
         $cached = $this->cacher->getDistributedCache('core/acl/listing/' . $cacheKey);
         if (null !== $cached) {
             return $cached;
         }
     }
     $condition = '';
     $primaryList = $this->objects->getPrimaryList($objectKey);
     $primaryKey = current($primaryList);
     $denyList = array();
     $conditionObject = new Condition(null, $this->jarves);
     foreach ($rules as $rule) {
         if ($rule['constraint_type'] === ACL::CONSTRAINT_EXACT) {
             //todo $rule['constraint_code'] can be a (urlencoded) composite pk
             //todo constraint_code is always urlencoded;
             $condition = Condition::create(array($primaryKey, '=', Tools::urlDecode($rule['constraint_code'])), $this->jarves);
         }
         if ($rule['constraint_type'] === ACL::CONSTRAINT_CONDITION) {
             $condition = Condition::create($rule['constraint_code'], $this->jarves);
         }
         if ($rule['constraint_type'] === ACL::CONSTRAINT_ALL) {
             $condition = array('1', '=', '1');
         } elseif ($rule['sub']) {
             $subCondition = $obj->getNestedSubCondition($condition);
             if ($subCondition) {
                 $condition = array($condition, 'OR', $subCondition);
             }
         }
         if ($rule['access'] === 1) {
             if ($denyList) {
                 $condition = array($condition, 'AND NOT', $denyList);
                 $conditionObject->addOr($condition);
                 //                    $conditionObject->add('AND NOT', $denyList);
             } else {
                 $conditionObject->addOr($condition);
             }
         }
         if ($rule['access'] !== 1) {
             if ($denyList) {
                 $denyList[] = 'AND NOT';
             }
             $denyList[] = $condition;
         }
     }
     if (!$conditionObject->hasRules()) {
         $conditionObject->addAnd(array('1', '!=', '1'));
     }
     if ($this->getCaching()) {
         $cacheKey = md5($objectKey);
         $this->cacher->setDistributedCache('core/acl/listing/' . $cacheKey, $conditionObject);
     }
     return $conditionObject;
 }
Example #4
0
 /**
  * {@inheritDoc}
  *
  * Same as parent method, except:
  * If we get the PK as path we convert it to internal ID.
  */
 public function primaryStringToArray($primaryKey)
 {
     if (is_array($primaryKey)) {
         return $primaryKey;
     }
     if ($primaryKey === '') {
         return false;
     }
     $groups = explode('/', $primaryKey);
     $result = array();
     foreach ($groups as $group) {
         $item = array();
         if ('' === $group) {
             continue;
         }
         $primaryGroups = explode(',', $group);
         foreach ($primaryGroups as $pos => $value) {
             if ($ePos = strpos($value, '=')) {
                 $key = substr($value, 0, $ePos);
                 $value = substr($value, $ePos + 1);
                 if (!in_array($key, $this->primaryKeys)) {
                     continue;
                 }
             } elseif (!$this->primaryKeys[$pos]) {
                 continue;
             }
             if (is_numeric($value)) {
                 $value = $this->webFilesystem->getPath($value);
             } else {
                 $value = Tools::urlDecode($value);
             }
             $item['path'] = $value;
         }
         if (count($item) > 0) {
             $result[] = $item;
         }
     }
     return $result;
 }
Example #5
0
 /**
  * Parse the internal object url scheme and return the information as array.
  *
  * Pattern:
  *    object://<object_key>[/<primay_values_url_encoded-1>][/<primay_values_url_encoded-n>][/?<options_as_querystring>]
  *
  * Examples:
  *
  * 1. object://news/1
  *   => returns the object news with primary value equal 1
  *
  * 2. object://news/id=1
  *   => equal as 1.
  *
  * 3. object://news/1/2
  *   => returns a list of the objects with primary value equal 1 or 2
  *
  * 4. object://news/id=1/id=2
  *   => equal as 3.
  *
  * 5. object://object_with_multiple_primary/2,54
  *   => returns the object with the first primary field equal 2 and second primary field equal 54
  *
  * 6. object://object_with_multiple_primary/2,54/34,55
  *   => returns a list of the objects
  *
  * 7. object://object_with_multiple_primary/id=2,parent_id=54/id=34,parent_id=55
  *   => equal as 6 if the first defined primary is 'id' and the second 'parent_id'
  *
  * 8. object://news/1?fields=title
  *   => equal as 1. but returns only the field title
  *
  * 9. object://news/1?fields=title,category_id
  *   => equal as 1. but returns only the field title and category_id
  *
  * 10. object://news?fields=title
  *   => returns all objects from type news
  *
  * 11. object://news?fields=title&limit=5
  *   => returns first 5 objects from type news
  *
  *
  * @static
  *
  * @param  string $internalUrl
  *
  * @return array  [object_key, object_id/s, queryParams]
  */
 public function parseUrl($internalUrl)
 {
     $internalUrl = trim($internalUrl);
     $list = false;
     $catch = 'object://';
     if (substr(strtolower($internalUrl), 0, strlen($catch)) == $catch) {
         $internalUrl = substr($internalUrl, strlen($catch));
     }
     $catch = 'objects://';
     if (substr(strtolower($internalUrl), 0, strlen($catch)) == $catch) {
         $list = true;
         $internalUrl = substr($internalUrl, strlen($catch));
     }
     $firstSlashPos = strpos($internalUrl, '/');
     $questionPos = strpos($internalUrl, '?');
     if ($firstSlashPos === false && $questionPos === false) {
         return array($internalUrl, false, array(), $list);
     }
     if ($firstSlashPos === false && $questionPos != false) {
         $objectKey = substr($internalUrl, 0, $questionPos);
     } else {
         $objectKey = $this->getObjectKey($internalUrl);
     }
     if (strpos($objectKey, '%')) {
         $objectKey = Tools::urlDecode($objectKey);
     }
     if (!$objectKey) {
         throw new \LogicException(sprintf('The url `%s` does not contain a object key.', $internalUrl));
     }
     $params = array();
     $objectIds = null;
     if ($questionPos !== false) {
         parse_str(substr($internalUrl, $questionPos + 1), $params);
         if ($firstSlashPos !== false) {
             $objectIds = substr($internalUrl, $firstSlashPos + 1, $questionPos - ($firstSlashPos + 1));
         }
     } else {
         $objectIds = substr($internalUrl, strlen($objectKey) + 1);
     }
     $objectIds = $this->parsePk($objectKey, $objectIds);
     if ($params && isset($params['condition'])) {
         $params['condition'] = json_decode($params['condition'], true);
     }
     return array($objectKey, !$objectIds ? false : $objectIds, $params, $list);
 }
Example #6
0
 /**
  * @param Request $request
  *
  * @return array
  */
 protected function extractPrimaryKey(Request $request)
 {
     $primaryKey = [];
     foreach ($this->getPrimary() as $pk) {
         $primaryKey[$pk] = Tools::urlDecode($request->attributes->get($pk));
     }
     return $primaryKey;
 }