//print '<pre>'.print_r($_POST,true).'</pre>'; exit; // Template Variables Initialization $d = array(); $d['search_parameters'] = ''; $d['fieldname'] = ''; $d['fieldtype'] = ''; $d['menu'] = ''; $d['search_form'] = ''; $d['content'] = ''; $d['page_number'] = '0'; $d['orderby'] = 'ID'; $d['order'] = 'ASC'; $d['exclude'] = CCTM::get_value($_POST, 'exclude'); // Generate a search form // we do this AFTER the get_posts() function so the form can access the GetPostsQuery->args/defaults $Form = new GetPostsForm(); //! Validation // Some Tests first to see if the request is valid... $raw_fieldname = CCTM::get_value($_POST, 'fieldname'); $d['fieldtype'] = CCTM::get_value($_POST, 'fieldtype'); if (empty($raw_fieldname) && empty($d['fieldtype'])) { print '<pre>' . sprintf(__('Invalid fieldname: %s', CCTM_TXTDOMAIN), '<em>' . htmlspecialchars($raw_fieldname) . '</em>') . '</pre>'; return; } // More Template Variables $d['fieldname'] = $raw_fieldname; $fieldname = preg_replace('/^' . CCTM_FormElement::css_id_prefix . '/', '', $raw_fieldname); $def = CCTM::get_value(CCTM::$data['custom_field_defs'], $fieldname); //print '<pre>'.print_r($def, true).'</pre>'; if (!empty($d['fieldtype'])) { $def['type'] = $d['fieldtype'];
Remember: the output here MUST be wrapped in HTML tags, otherwise jQuery's .html() method will kack. ------------------------------------------------------------------------------*/ require_once CCTM_PATH . '/includes/SummarizePosts.php'; require_once CCTM_PATH . '/includes/GetPostsQuery.php'; require_once CCTM_PATH . '/includes/GetPostsForm.php'; // Id of the field that will store the values (we need to pass it through here // because it is not static: there may be multiple instances of the widget) $storage_field = CCTM::get_value($_POST, 'storage_field', 'storage_field'); $search_parameters_str = ''; if (isset($_POST['search_parameters'])) { $search_parameters_str = $_POST['search_parameters']; } $existing_values = array(); parse_str($search_parameters_str, $existing_values); $Form = new GetPostsForm(); // What options should be displayed on the form that defines the search? // Load up the config... $possible_configs = array(); $possible_configs[] = '/config/search_parameters/_widget.php'; if (!CCTM::load_file($possible_configs)) { print '<p>' . __('Search parameter configuration file not found.', CCTM_TXTDOMAIN) . '</p>'; } $form_tpl = CCTM::load_tpl('summarize_posts/widget.tpl'); $Form->set_name_prefix(''); $Form->set_id_prefix(''); $Form->set_tpl($form_tpl); $custom_fields = CCTM::get_custom_field_defs(); $custom_field_options = ''; foreach ($custom_fields as $cf) { $custom_field_options .= sprintf('<option value="%s:%s">%s</option>', $cf['name'], $cf['label'], $cf['label']);
/** * This is the tie-into the GetPostsForm object: it returns (not prints) a form * OR it handles form submissions and returns results. * * @param array $args (optional) defines which controls should be displayed * @param string $content_tpl (optional) passed to the get_posts() function, this defines how each result will be formatted. * @return string HTML form, or HTML results if the form was property submitted. */ public static function search($args = array(), $content_tpl = null) { $Form = new GetPostsForm($args); $nonce = self::get_from_array($_POST, $Form->nonce_name); // Draw the search form if (empty($_POST)) { return $Form->generate(); } elseif (wp_verify_nonce($nonce, $Form->nonce_action)) { unset($_POST[$Form->nonce_name]); unset($_POST['_wp_http_referer']); $search_args = array(); foreach ($_POST as $k => $v) { // Strip the prefix $new_key = preg_replace('/^' . $Form->name_prefix . '/', '', $k); $search_args[$new_key] = $v; } $results = self::get_posts($search_args); if (empty($results)) { print $Form->get_no_results_msg(); } else { print $results; } } else { return "Invalid Submission."; } }
$type = $fieldtype; } else { $type = CCTM::get_value($def, 'type'); } $search_parameters_str = ''; if (isset($_POST['search_parameters'])) { $search_parameters_str = $_POST['search_parameters']; } //print '<pre>'.$search_parameters_str. '</pre>'; return; $existing_values = array(); parse_str($search_parameters_str, $existing_values); //print '<pre>'.print_r($existing_values, true) . '</pre>'; require_once CCTM_PATH . '/includes/SummarizePosts.php'; require_once CCTM_PATH . '/includes/GetPostsQuery.php'; require_once CCTM_PATH . '/includes/GetPostsForm.php'; $Form = new GetPostsForm(); // What options should be displayed on the form that defines the search? // Load up the config... $possible_configs = array(); $possible_configs[] = '/config/search_parameters/' . $fieldname . '.php'; // e.g. my_field.php $possible_configs[] = '/config/search_parameters/_' . $type . '.php'; // e.g. _image.php $possible_configs[] = '/config/search_parameters/_default.php'; if (!CCTM::load_file($possible_configs)) { print '<p>' . sprintf(__('Search parameter configuration file not found. Check config/search_parameters/ for a valid configuration file for the %s field or the %s field-type.', CCTM_TXTDOMAIN), "<code>{$fieldname}</code>", "<code>{$type}</code>") . '</p>'; } $Form->set_placeholder('description', __('This form will determine which posts will be selectable when users create or edit a post that uses this field. WARNING: supplying incorrect or overly restrictive criteria will result in an empty list!', CCTM_TXTDOMAIN)); $Form->set_placeholder('save', __('Save', CCTM_TXTDOMAIN)); $Form->set_placeholder('cancel', __('Cancel', CCTM_TXTDOMAIN)); $form_tpl = CCTM::load_tpl('post_selector/search_forms/_modal.tpl');
$d['search_parameters'] = ''; $d['menu'] = ''; $d['fieldname'] = ''; // needed for thickbox.php $d['fieldtype'] = ''; // needed for thickbox.php $d['search_form'] = ''; $d['content'] = ''; $d['page_number'] = '0'; $d['orderby'] = 'ID'; $d['order'] = 'ASC'; ///print '<pre>'.print_r($_POST, true).'</pre>'; //return; // Generate a search form // we do this AFTER the get_posts() function so the form can access the GetPostsQuery->args/defaults $Form = new GetPostsForm(); //$d['content'] = '<pre>'.print_r($_POST, true) . '</pre>'; //! Validation $args = array(); $post_id_field = CCTM::get_value($_POST, 'post_id_field'); $target_id = CCTM::get_value($_POST, 'target_id'); $args['post_type'] = CCTM::get_value($_POST, 'post_type'); // This gets subsequent search data that gets passed when the user refines the search. if (isset($_POST['search_parameters'])) { //print '<pre> HERE...'. print_r($_POST['search_parameters'], true).'</pre>'; // $d['content'] .= '<pre>HERE... '. print_r($_POST['search_parameters'], true).'</pre>'; parse_str($_POST['search_parameters'], $args); // Pass the "view" parameters to the view $d['page_number'] = CCTM::get_value($args, 'page_number', 0); $d['orderby'] = CCTM::get_value($args, 'orderby', 'ID'); $d['order'] = CCTM::get_value($args, 'order', 'ASC');
function testSearchBy3() { $Q = new GetPostsForm(); $Q->set_nonce_field(''); // override nonce $Q->set_css('', false); // blank out CSS $Q->set_tpl('[+post_type.options+]'); $actual = $Q->generate(array('post_type')); //print $Q->placeholders['post_type.options']; exit; //print $actual; exit; //print '<pre>'; print_r($Q->placeholders); print '</pre>';exit; $expected = '<option value="" >Select post-type</option> <option value="attachment" >attachment</option> <option value="house" >house</option> <option value="movie" >movie</option> <option value="page" >page</option> <option value="people" >people</option> <option value="post" >post</option> <option value="room" >room</option> <option value="snake" >snake</option> <option value="test" >test</option>'; $this->assertTrue(in_html($expected, $actual)); }