コード例 #1
0
 /**
  * Method to filter the form data.
  *
  * @param	array	$data	An array of field values to filter.
  * @param	string	$group	The dot-separated form group path on which to filter the fields.
  *
  * @return	mixed	boolean	True on sucess.
  * @since	1.6
  */
 public function filter($data, $group = null)
 {
     // Make sure there is a valid GantryForm XML document.
     if (!$this->xml instanceof GantrySimpleXMLElement) {
         return false;
     }
     // Initialize variables.
     $input = new GantryRegistry($data);
     $output = new GantryRegistry();
     // Get the fields for which to filter the data.
     $fields = $this->findFieldsByGroup($group);
     if (!$fields) {
         // PANIC!
         return false;
     }
     // Filter the fields.
     foreach ($fields as $field) {
         // Initialise variables.
         $name = (string) $field['name'];
         // Get the field groups for the element.
         $attrs = $field->xpath('ancestor::fields[@name]/@name');
         $groups = array_map('strval', $attrs ? $attrs : array());
         $group = implode('.', $groups);
         // Get the field value from the data input.
         if ($group) {
             // Filter the value if it exists.
             if ($input->exists($group . '.' . $name)) {
                 $output->set($group . '.' . $name, $this->filterField($field, $input->get($group . '.' . $name, (string) $field['default'])));
             }
         } else {
             // Filter the value if it exists.
             if ($input->exists($name)) {
                 $output->set($name, $this->filterField($field, $input->get($name, (string) $field['default'])));
             }
         }
     }
     return $output->toArray();
 }
コード例 #2
0
ファイル: gantrytemplate.class.php プロジェクト: Rikisha/proj
 /**
  * @param $param_name
  * @param $default
  *
  * @return mixed
  */
 protected function _getParamValue($param_name, $default)
 {
     $original_param_name = $param_name;
     $value = $default;
     $exists = false;
     if ($this->_params_reg->exists($param_name)) {
         $exists = true;
     }
     // try forward dashes
     if (!$exists && strstr($param_name, '-') !== false) {
         $param_name_parts = explode('-', $param_name);
         $parts_count = count($param_name_parts);
         $dots = array();
         for ($i = 0; $i < $parts_count; $i++) {
             array_unshift($dots, array_pop($param_name_parts));
             $param_name = implode('-', $param_name_parts) . '.' . implode('.', $dots);
             if ($this->_params_reg->exists($param_name)) {
                 $exists = true;
                 break;
             }
         }
         // try backwards dashes
         if (!$exists) {
             $param_name = $original_param_name;
             $param_name_parts = explode('-', $param_name);
             $parts_count = count($param_name_parts);
             $dots = array();
             for ($i = 0; $i < $parts_count; $i++) {
                 array_unshift($dots, array_pop($param_name_parts));
                 $param_name = implode('.', $param_name_parts) . '.' . implode('-', $dots);
                 if ($this->_params_reg->exists($param_name)) {
                     $exists = true;
                     break;
                 }
             }
         }
     }
     if ($exists) {
         $value = $this->_params_reg->get($param_name, $default);
     }
     return $value;
 }