/** * Create only form elements. */ public function form($instance) { require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $args_str = ''; // formatted args for the user to look at so they remember what they searched for. if (!isset($instance['title'])) { $instance['title'] = ''; // default value } if (!isset($instance['parameters'])) { $instance['parameters'] = ''; // default value } if (!isset($instance['formatting_string'])) { $instance['formatting_string'] = '<li><a href="[+permalink+]">[+post_title+]</a></li>'; // default value } $args = array(); $search_parameters_str = $instance['parameters']; parse_str($search_parameters_str, $args); $Q = new GetPostsQuery($args); $args_str = $Q->get_args(); print '<p>' . $this->description . '<a href="http://code.google.com/p/wordpress-custom-content-type-manager/wiki/Widget"><img src="' . CCTM_URL . '/images/question-mark.gif" width="16" height="16" /></a></p> <label class="cctm_label" for="' . $this->get_field_id('title') . '">' . __('Title', CCTM_TXTDOMAIN) . '</label> <input type="text" name="' . $this->get_field_name('title') . '" id="' . $this->get_field_id('title') . '" value="' . $instance['title'] . '" /> <p style="margin-top:10px;"><strong>' . __('Search Criteria', CCTM_TXTDOMAIN) . '</strong> <span class="button" onclick="javascript:widget_summarize_posts(\'' . $this->get_field_id('parameters') . '\');">' . __('Define Search', CCTM_TXTDOMAIN) . '</span></p> <!-- also target for Ajax writes --> <div id="existing_' . $this->get_field_id('parameters') . '" style="padding-left:10px;">' . $args_str . '</div> <input type="hidden" name="' . $this->get_field_name('parameters') . '" id="' . $this->get_field_id('parameters') . '" value="' . $instance['parameters'] . '" /> <div id="target_' . $this->get_field_id('selector') . '"></div> <label class="cctm_label" for="' . $this->get_field_id('formatting_string') . '">' . __('Formatting String', CCTM_TXTDOMAIN) . '</label> <textarea name="' . $this->get_field_name('formatting_string') . '" id="' . $this->get_field_id('formatting_string') . '" rows="3" cols="30">' . $instance['formatting_string'] . '</textarea> '; }
<?php /*------------------------------------------------------------------------------ This controller takes serialized arguments meant for the GetPostsQuery class and formats them to be easily readible. This helps users know what search criteria they have defined for a widget or other search parameter. ------------------------------------------------------------------------------*/ if (!defined('CCTM_PATH')) { exit('No direct script access allowed'); } require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $search_parameters_str = ''; if (isset($_POST['search_parameters'])) { $search_parameters_str = $_POST['search_parameters']; } $args = array(); parse_str($search_parameters_str, $args); $Q = new GetPostsQuery($args); print $Q->get_args(); /*EOF*/
/** * 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 unknown $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'; // 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 Image'); $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/_media.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 $search_parameters_str = CCTM::get_value($def, 'search_parameters'); parse_str($search_parameters_str, $args); $Q = new GetPostsQuery($args); $search_parameters_visible = $Q->get_args(); $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="' . CCTM::get_value($def, 'search_parameters') . '" /> <br/> </div>'; $out .= '</div><!-- /inside --> </div><!-- /postbox -->'; // Validations / Required $out .= $this->format_validators($def, false); // Output Filter $out .= $this->format_available_output_filters($def); return $out; }
/** * Get a visible listing of what the search parameters are for a relation field * @param string $search_parameters_str URL encoded * @return string */ protected function _get_search_parameters_visible($search_parameters_str) { require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $Q = new GetPostsQuery(); parse_str($search_parameters_str, $args); $Q = new GetPostsQuery($args); return $Q->get_args(); }