/** * function to save field instance to the database * call $this->update inside * @param array $params for update field */ public function do_update($params = array()) { $input = !empty($params) ? $params : $_POST['field-' . $this->id_base][$this->number]; // remove all slashed from values foreach ($input as $var => $value) { if (is_string($value)) { $input[$var] = stripslashes($value); } } // validate: title should be always there if (empty($input['title'])) { return array('status' => '0', 'error' => __('Title field is required.', JCF_TEXTDOMAIN)); } // get values from real class: $instance = $this->update($input, $this->instance); $instance['title'] = strip_tags($instance['title']); $instance['slug'] = strip_tags($input['slug']); $instance['enabled'] = (int) @$input['enabled']; // starting from vers. 1.4 all new fields should be marked with version of the plugin if ($this->is_new) { $instance['_version'] = JCF_VERSION; } // for old records: set 1.34 - last version without versioning the fields if (empty($instance['_version'])) { $instance['_version'] = 1.34; } // new from version 1.4: validation/normalization $this->validate_instance($instance); // check for errors // IMPORTANT: experimental function if (!empty($this->field_errors)) { $errors = implode('\\n', $this->field_errors); return array('status' => '0', 'error' => $errors); } if ($this->is_new) { $this->number = jcf_get_fields_index($this->id_base); $this->id = $this->id_base . '-' . $this->number; } if (!$this->is_collection_field()) { // update fieldset $fieldset = jcf_fieldsets_get($this->fieldset_id); $fieldset['fields'][$this->id] = $instance['enabled']; jcf_fieldsets_update($this->fieldset_id, $fieldset); // check slug field if (empty($instance['slug'])) { $instance['slug'] = '_field_' . $this->id_base . '__' . $this->number; } // save jcf_field_settings_update($this->id, $instance, $this->fieldset_id); // return status $res = array('status' => '1', 'id' => $this->id, 'id_base' => $this->id_base, 'fieldset_id' => $this->fieldset_id, 'is_new' => $this->is_new, 'instance' => $instance); } else { $collection = jcf_init_field_object($this->collection_id, $this->fieldset_id); // check slug field if (empty($instance['slug'])) { $instance['slug'] = '_field_' . $this->id_base . '__' . $this->number; } $instance['field_width'] = $input['field_width']; if (isset($input['group_title'])) { $instance['group_title'] = true; } $collection->instance['fields'][$this->id] = $instance; // save jcf_field_settings_update($this->collection_id, $collection->instance, $this->fieldset_id); // return status $res = array('status' => '1', 'id' => $this->id, 'id_base' => $this->id_base, 'fieldset_id' => $this->fieldset_id, 'collection_id' => $this->collection_id, 'is_new' => $this->is_new, 'instance' => $instance); } return $res; }
/** * function to save field instance to the database * call $this->update inside */ function do_update() { $input = $_POST['field-' . $this->id_base][$this->number]; // remove all slashed from values foreach ($input as $var => $value) { if (is_string($value)) { $input[$var] = stripslashes($value); } } // validate: title should be always there if (empty($input['title'])) { return array('status' => '0', 'error' => __('Title field is required.', JCF_TEXTDOMAIN)); } // get values from real class: $instance = $this->update($input, $this->instance); $instance['title'] = strip_tags($instance['title']); $instance['slug'] = strip_tags($input['slug']); $instance['enabled'] = (int) @$input['enabled']; // check for errors // IMPORTANT: experimental function if (!empty($this->field_errors)) { $errors = implode('\\n', $this->field_errors); return array('status' => '0', 'error' => $errors); } if ($this->is_new) { $this->number = jcf_get_fields_index($this->id_base); $this->id = $this->id_base . '-' . $this->number; } // update fieldset $fieldset = jcf_fieldsets_get($this->fieldset_id); $fieldset['fields'][$this->id] = $instance['enabled']; jcf_fieldsets_update($this->fieldset_id, $fieldset); // check slug field if (empty($instance['slug'])) { $instance['slug'] = 'field_' . $this->id_base . '__' . $this->number; } // save jcf_field_settings_update($this->id, $instance); // return status $res = array('status' => '1', 'id' => $this->id, 'id_base' => $this->id_base, 'fieldset_id' => $this->fieldset_id, 'is_new' => $this->is_new, 'instance' => $instance); return $res; }