/** * Creates a dropdown select of blocks and when selected, will display fields related to that block * * @access public * @param array Fields parameters * @return string */ public function block($params) { $form_builder =& $params['instance']; // check to make sure there is no conflict between page columns and layout vars if (!empty($params['block_name'])) { // check to make sure there is no conflict between page columns and layout vars $layout = $this->fuel->layouts->get($params['block_name'], 'block'); if (!$layout) { return; } if (!isset($params['context'])) { $params['context'] = $params['key']; } $layout->set_context($params['context']); $fields = $layout->fields(); $fb = new Form_builder(); $fb->load_custom_fields(APPPATH . 'config/custom_fields.php'); $fb->question_keys = array(); $fb->submit_value = ''; $fb->cancel_value = ''; $fb->use_form_tag = FALSE; $fb->name_prefix = 'vars'; $fb->set_fields($fields); $fb->display_errors = FALSE; if (!empty($params['value'])) { $fb->set_field_values($params['value']); } $form = $fb->render(); return $form; } else { $params['type'] = 'select'; if (!isset($params['options'])) { // if a folder is specified, we will look in that directory to get the list of blocks if (isset($params['folder'])) { if (!isset($params['where'])) { $params['where'] = array(); } if (!isset($params['filter'])) { $params['filter'] = '^_(.*)|\\.html$'; } if (!isset($params['order'])) { $params['order'] = TRUE; } // set options_list to not be recursive since block layout names won't have slashes in them (e.g. sections/right_image... it would just be right_image) if (!isset($params['recursive'])) { $params['recursive'] = FALSE; } $params['options'] = $this->CI->fuel->blocks->options_list($params['where'], $params['folder'], $params['filter'], $params['order'], $params['recursive']); } else { if (!isset($params['group'])) { $params['group'] = ''; } $params['options'] = $this->CI->fuel->layouts->options_list(TRUE, $params['group']); } } $select_class = 'block_layout_select'; $params['class'] = !empty($params['class']) ? $params['class'] . ' ' . $select_class : $select_class; if (!empty($params['ajax_url'])) { $params['data']['url'] = rawurlencode($params['ajax_url']); } $value = (is_array($params['value']) and isset($params['value']['block_name'])) ? $params['value']['block_name'] : (isset($params['value']) ? $params['value'] : ''); $params['value'] = $value; $params['style'] = 'margin-bottom: 10px;'; $field = $form_builder->create_select($params); $field = $field . '<div class="block_layout_fields"></div><div class="loader hidden"></div>'; return $field; } }
protected function _process() { $this->load->helper('security'); $this->_orig_post = $_POST; // filter placeholder $_POST values $callback = create_function('$matches', ' if (isset($_POST[$matches["2"]])) { $str = $matches[1].$_POST[$matches["2"]].$matches[3]; } else { $str = $matches[0]; } return $str; '); // first loop through and create simple non-namespaced $_POST values if they don't exist for convenience' foreach ($_POST as $key => $val) { $key_parts = explode('--', $key); $tmp_key = end($key_parts); $_POST[$tmp_key] = $val; } // now loop through and do any substitution foreach ($_POST as $key => $val) { if (is_string($val)) { $_POST[$key] = preg_replace_callback('#(.*)\\{(.+)\\}(.*)#U', $callback, $val); } } // set boolean fields if (!empty($this->model->boolean_fields) and is_array($this->model->boolean_fields)) { foreach ($this->model->boolean_fields as $val) { $_POST[$val] = isset($_POST[$val]) ? $_POST[$val] : 0; } } // if no permission to publish, then we revoke if (!$this->fuel->auth->has_permission($this->permission, 'publish')) { unset($_POST['published']); } // set key_field if it is not id if (!empty($_POST['id']) and $this->model->key_field() != 'id') { $_POST[$this->model->key_field()] = $_POST['id']; } // run any form field post processing hooks $this->load->library('form_builder'); // use a new instance to prevent problems when duplicating $fb = new Form_builder(); $fb->load_custom_fields(APPPATH . 'config/custom_fields.php'); // $fields = $this->model->form_fields($_POST); $fields = $this->_block_processing($this->model->form_fields(), $_POST); $fb->set_fields($fields); $fb->post_process_field_values(); // manipulates the $_POST values directly // sanitize input if set in module configuration $posted = $this->_sanitize($_POST); return $posted; }