} $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']); } if (!isset($existing_values['limit']) || $existing_values['limit'] == 0) { $existing_values['limit'] = 5; } $Form->set_placeholder('custom_fields', $custom_field_options); $Form->set_placeholder('cctm_url', CCTM_URL); $Form->set_placeholder('storage_field', $storage_field); // I18n for the widget $Form->set_placeholder('widget_desc', __('Dynamically list posts according to the criteria below.', CCTM_TXTDOMAIN)); $Form->set_placeholder('post_title_label', __('Post Title', CCTM_TXTDOMAIN)); $Form->set_placeholder('author_id_label', __('Author ID', CCTM_TXTDOMAIN)); $Form->set_placeholder('add_filter_label', __('Add Filter', CCTM_TXTDOMAIN));
/** * This should return (not print) form elements that handle all the controls required to define this * type of field. The default properties correspond to this class's public variables, * e.g. name, label, etc. The form elements you create should have names that correspond * with the public $props variable. A populated array of $props will be stored alongside * the custom-field data for the containing post-type. * * @param array $def * @return string HTML input fields */ public function get_edit_field_definition($def) { // Used to fetch the default value. require_once CCTM_PATH . '/includes/GetPostsQuery.php'; // So we can arrange the metafields $out = '<script> jQuery(function() { jQuery( "#sortable" ).sortable(); jQuery( "#sortable" ).disableSelection(); }); </script>'; // Standard $out .= $this->format_standard_fields($def); // Options $Q = new GetPostsQuery(); $out .= ' <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div> <h3 class="hndle"><span>' . __('Options', CCTM_TXTDOMAIN) . '</span></h3> <div class="inside">'; // Note fieldtype: used to set the default value on new fields $out .= '<input type="hidden" id="fieldtype" value="image" />'; // Initialize / defaults $preview_html = ''; $click_label = __('Choose Relation'); $label = __('Default Value', CCTM_TXTDOMAIN); $remove_label = __('Remove'); // Handle the display of the default value if (!empty($def['default_value'])) { $hash = CCTM::get_thumbnail($def['default_value']); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->type . '.tpl', 'fields/elements/_relation.tpl')); $preview_html = CCTM::parse($fieldtpl, $hash); } // Button Label $out .= '<div class="' . self::wrapper_css_class . '" id="button_label_wrapper"> <label for="button_label" class="' . self::label_css_class . '">' . __('Button Label', CCTM_TXTDOMAIN) . '</label> <input type="text" name="button_label" class="' . self::css_class_prefix . 'text" id="button_label" value="' . htmlspecialchars($def['button_label']) . '"/> ' . $this->get_translation('button_label') . ' </div>'; // Set Search Parameters $seach_parameters_str = ''; if (isset($def['search_parameters'])) { $search_parameters_str = $def['search_parameters']; } $search_parameters_visible = $this->_get_search_parameters_visible($seach_parameters_str); $out .= ' <div class="cctm_element_wrapper" id="search_parameters_wrapper"> <label for="name" class="cctm_label cctm_text_label" id="search_parameters_label">' . __('Search Parameters', CCTM_TXTDOMAIN) . '</label> <span class="cctm_description">' . __('Define which posts are available for selection by narrowing your search parameters.', CCTM_TXTDOMAIN) . '</span> <br/> <span class="button" onclick="javascript:search_form_display(\'' . $def['name'] . '\',\'' . $def['type'] . '\');">' . __('Set Search Parameters', CCTM_TXTDOMAIN) . '</span> <div id="cctm_thickbox"></div> <span id="search_parameters_visible">' . $search_parameters_visible . '</span> <input type="hidden" id="search_parameters" name="search_parameters" value="' . $search_parameters_str . '" /> <br/> </div>'; $out .= '</div><!-- /inside --> </div><!-- /postbox -->'; // Validations / Required $out .= $this->format_validators($def, false); $defs = CCTM::get_custom_field_defs(); $li = '<li><input type="checkbox" name="metafields[]" class="cctm_checkbox" id="metafield_%s" value="%s"%s/> <label for="metafield_%s"><strong>%s</strong> (%s)</label> </li>'; //$out .= '<pre>'.print_r($defs,true).'</pre>'; $out .= '<div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div> <h3 class="hndle"><span>' . __('Meta Fields', CCTM_TXTDOMAIN) . '</span></h3> <div class="inside"> <p>' . __('Select which fields should appear as meta data for this relation.', CCTM_TXTDOMAIN) . '</p> <ul id="sortable">'; // First show the ones already assigned here foreach ($this->props['metafields'] as $fieldname) { $out .= sprintf($li, $fieldname, $fieldname, ' checked="checked"', $fieldname, $defs[$fieldname]['label'], $fieldname); } // Grab all the others foreach ($defs as $fieldname => $d) { if ($d['type'] == 'relationmeta' || in_array($fieldname, $this->props['metafields'])) { continue; } $out .= sprintf($li, $fieldname, $fieldname, '', $fieldname, $d['label'], $fieldname); } $out .= '</ul> </div><!-- /inside --> </div><!-- /postbox -->'; // Output Filter $out .= $this->format_available_output_filters($def); return $out; }