/** * <label for="[+name+]" class="cctm_label cctm_textarea_label" id="cctm_label_[+name+]">[+label+]</label> * <textarea name="[+name+]" class="cctm_textarea" id="[+name+]" [+extra+]>[+value+]</textarea> * * @param string $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $fieldtpl = ''; $wrappertpl = ''; // Multi-versions if ($this->is_repeatable) { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->type . '_multi.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '_multi.tpl')); $this->i = 0; $values = $this->get_value($current_value, 'to_array'); foreach ($values as $v) { $this->value = htmlspecialchars(html_entity_decode($v), ENT_QUOTES); $this->content .= CCTM::parse($fieldtpl, $this->get_props()); $this->i = $this->i + 1; } } else { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->type . '.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '.tpl', 'fields/wrappers/_default.tpl')); $this->value = htmlspecialchars($this->get_value($current_value, 'to_string'), ENT_QUOTES); $this->content = CCTM::parse($fieldtpl, $this->get_props()); } // wrap it. $this->add_label = __('Add', CCTM_TXTDOMAIN); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * This is somewhat tricky if the values the user wants to store are HTML/JS. * See http://www.php.net/manual/en/function.htmlspecialchars.php#99185 * * @param mixed $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { // Format for multi-select if ($this->is_repeatable) { $current_value = $this->get_value($current_value, 'to_array'); $optiontpl = CCTM::load_tpl(array('fields/options/' . $this->name . '.tpl', 'fields/options/_user_multi.tpl', 'fields/options/_user.tpl')); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_user_multi.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_user_multi.tpl', 'fields/wrappers/_default.tpl')); } else { $current_value = $this->get_value($current_value, 'to_string'); $optiontpl = CCTM::load_tpl(array('fields/options/' . $this->name . '.tpl', 'fields/options/_user.tpl')); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_user.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_user.tpl', 'fields/wrappers/_default.tpl')); } // Get the options. This currently is not skinnable. $this->all_options = ''; if (!isset($this->required) || !$this->required) { $hash['value'] = ''; $hash['option'] = ''; $this->all_options .= CCTM::parse($optiontpl, $hash); // '<option value="">'.__('Pick One').'</option>'; } $this->options = get_users(); // WP: http://codex.wordpress.org/Function_Reference/get_users $opt_cnt = count($this->options); $i = 1; // Populate the options foreach ($this->options as $o) { //die(print_r($o, true)); $hash = $this->get_props(); // We hardcode this one because we always need to store the user ID as the value for normalization $hash['value'] = $o->data->ID; foreach ($o->data as $k => $v) { if (!isset($hash[$k])) { $hash[$k] = $v; } } $hash['is_checked'] = ''; if ($this->is_repeatable) { if (in_array(trim($hash['value']), $current_value)) { $hash['is_selected'] = 'selected="selected"'; } } else { if (trim($current_value) == trim($hash['value'])) { $hash['is_selected'] = 'selected="selected"'; } } $hash['i'] = $i; $hash['id'] = $this->name; $this->all_options .= CCTM::parse($optiontpl, $hash); } // Populate the values (i.e. properties) of this field $this->id = str_replace(array('[', ']', ' '), '_', $this->name); // wrap $this->set_prop('value', $current_value); $this->content = CCTM::parse($fieldtpl, $this->get_props()); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * See Issue http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=138 * and this one: http://keighl.com/2010/04/switching-visualhtml-modes-with-tinymce/ * * @param string $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '.tpl', 'fields/wrappers/_default.tpl')); $settings = array(); $settings['editor_class'] = $this->class; $settings['textarea_name'] = $this->name_prefix . $this->name; // see http://nacin.com/tag/wp_editor/ ob_start(); wp_editor($current_value, $this->id_prefix . $this->id, $settings); $this->content = ob_get_clean(); $this->add_label = __('Add', CCTM_TXTDOMAIN); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * * * @param string $current_value * @return string */ public function get_edit_field_instance($current_value) { $this->is_checked = ''; $current_value = $this->get_value($current_value, 'to_string'); if ($current_value == $this->checked_value) { $this->is_checked = 'checked="checked"'; } $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->type . '.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '.tpl', 'fields/wrappers/_default.tpl')); $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $this->value = htmlspecialchars($this->checked_value); $this->content = CCTM::parse($fieldtpl, $this->get_props()); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * This is somewhat tricky if the values the user wants to store are HTML/JS. * See http://www.php.net/manual/en/function.htmlspecialchars.php#99185 * * @param mixed $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { // Populate the values (i.e. properties) of this field $this->id = $this->name; $upload_dir = wp_upload_dir(); $file = $upload_dir['basedir'] . '/' . CCTM::base_storage_dir . '/fields/' . $this->id . '/onedit.php'; if (file_exists($file)) { $this->value = (include $file); } else { $this->value = htmlspecialchars(html_entity_decode($this->get_value($current_value, 'to_string'))); } $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_hidden.tpl', 'fields/elements/_default.tpl')); return CCTM::parse($fieldtpl, $this->get_props()); }
$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']); } 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
/** * This is the odd duck... it could (should?) be implemented as a variation of * the dropbox field (it is so similar), but conceptually, the multi-select is a * different animal. It doesn't get "repeated" like the other fields, instead * it _always_ stores an array of values. Notably, this field uses only the * option and wrapper .tpl's. * * This is hands-down the most complex field due to the way we have to do * literal comparisions of foreign comparisons. Whereas the other fields * are fine if we store a "à" or "ˆ" so long as it displays correctly, * the multiselect fields must get the $current_value to be EXACTLY equal * to the available options, otherwise we won't know whether or not * to check the checkbox. * * See http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=88 * * @param string $current_value json-encoded array of selected values for the current post * @return string */ public function get_edit_field_instance($current_value) { $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $optiontpl = ''; $fieldtpl = ''; $wrappertpl = ''; // Multi-select if (isset($this->display) && $this->display == 'multiselect') { $optiontpl = CCTM::load_tpl(array('fields/options/' . $this->name . '.tpl', 'fields/options/_option.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_multiselect.tpl')); } else { $optiontpl = CCTM::load_tpl(array('fields/options/' . $this->name . '.tpl', 'fields/options/_' . $this->type . '.tpl', 'fields/options/_checkbox.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_multi_checkboxes.tpl', 'fields/wrappers/_default.tpl')); } // See https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=463 if ($this->is_sql) { if (empty($this->alternate_input)) { return __('Alternate input must not be empty if SQL box is checked.', CCTM_TXTDOMAIN); } else { global $wpdb; global $table_prefix; $wpdb->hide_errors(); $query = CCTM::parse($this->alternate_input, array('table_prefix' => $table_prefix)); //return $query; $results = $wpdb->get_results($query, ARRAY_N); if ($wpdb->last_error) { return $wpdb->last_error; } $options = array(); $values = array(); foreach ($results as $r_i => $r) { $options[$r_i] = $r[0]; if (isset($r[1])) { $values[$r_i] = $r[1]; } else { $values[$r_i] = $r[0]; } } $this->use_key_values = 1; // see https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=541 $this->set_prop('options', $options); $this->set_prop('values', $values); } } elseif (!$this->is_sql && !empty($this->alternate_input)) { $options = array(); $values = array(); $mixed = explode("\n", $this->alternate_input); foreach ($mixed as $m_i => $m) { $line = explode('||', $m); $options[$m_i] = trim($line[0]); if (isset($line[1])) { $values[$m_i] = trim($line[1]); } else { $values[$m_i] = trim($line[0]); } } $this->set_prop('options', $options); $this->set_prop('values', $values); } // $current_values_arr: represents what's actually been selected. //$current_values_arr = (array) json_decode(html_entity_decode($current_value), true ); $current_values_arr = $this->get_value(html_entity_decode($current_value), 'to_array'); // Bring the foreign characters back from the dead. We need this extra step // because we have to do exact comparisons to see if the options are selected or not. if ($current_values_arr and is_array($current_values_arr)) { foreach ($current_values_arr as $i => $v) { $current_values_arr[$i] = trim(CCTM::charset_decode_utf_8($v)); } } // $this->options: represents what's _available_ to be selected. // Some error messaging: the options thing is enforced at time of def creation too, // but we're doing it here too just to play it safe. if (!isset($this->options) || !is_array($this->options)) { return sprintf('<p><strong>%$1s</strong> %$2s %$3s</p>', __('Custom Content Error', CCTM_TXTDOMAIN), __('No options supplied for the following custom field: ', CCTM_TXTDOMAIN), $this->name); } // Get the options! // we use a for loop so we can read places out of 2 similar arrays: values & options $opt_cnt = count($this->options); for ($i = 0; $i < $opt_cnt; $i++) { // initialize $hash = $this->get_props(); $hash['is_checked'] = ''; $hash['is_selected'] = ''; $hash['option'] = ''; $hash['value'] = ''; $hash['i'] = $i; if (isset($this->options[$i])) { $hash['option'] = CCTM::charset_decode_utf_8($this->options[$i]); } if (isset($this->values[$i])) { $hash['value'] = CCTM::charset_decode_utf_8($this->values[$i]); } // Simplistic behavior if we don't use key=>value pairs if (!$this->use_key_values) { $hash['value'] = $hash['option']; } if (is_array($current_values_arr) && in_array(trim($hash['value']), $current_values_arr)) { $hash['is_checked'] = 'checked="checked"'; $hash['is_selected'] = 'selected="selected"'; } $this->content .= CCTM::parse($optiontpl, $hash); } $this->set_prop('value', $current_value); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * Get an instance of this field (used when you are creating or editing a post * that uses this type of custom field). * * @param string $current_value of the field for the current post * @return string */ public function get_edit_field_instance($current_value) { $current_value = $this->get_value($current_value, 'to_string'); // Format for Radio buttons if ($this->display_type == 'radio') { $optiontpl = CCTM::load_tpl(array('fields/options/' . $this->name . '.tpl', 'fields/options/_radio.tpl')); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_radio.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_radio.tpl', 'fields/wrappers/_default.tpl')); } else { $optiontpl = CCTM::load_tpl(array('fields/options/' . $this->name . '.tpl', 'fields/options/_option.tpl')); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_dropdown.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->type . '.tpl', 'fields/wrappers/_default.tpl')); } // Some error messaging: the options thing is enforced at time of def creation, so // we shouldn't ever need to enforce it here, but just in case... if (!isset($this->options) || !is_array($this->options)) { return sprintf('<p><strong>%$1s</strong> %$2s %$3s</p>', __('Custom Content Error', CCTM_TXTDOMAIN), __('No options supplied for the following custom field: ', CCTM_TXTDOMAIN), $data['name']); } // Get the options. This currently is not skinnable. // $this->props['options'] is already bogarted by the definition. // Add an empty <option> for non-required dropdowns $this->all_options = ''; if ($this->display_type != 'radio' && !$this->required) { $hash['value'] = ''; $hash['option'] = ''; $this->all_options .= CCTM::parse($optiontpl, $hash); } // Handle SQL queries if ($this->is_sql) { if (empty($this->alternate_input)) { return __('Alternate input must not be empty if SQL box is checked.', CCTM_TXTDOMAIN); } else { global $wpdb; global $table_prefix; $wpdb->hide_errors(); $query = CCTM::parse($this->alternate_input, array('table_prefix' => $table_prefix)); //return $query; $results = $wpdb->get_results($query, ARRAY_N); if ($wpdb->last_error) { return $wpdb->last_error; } $options = array(); $values = array(); foreach ($results as $r_i => $r) { $options[$r_i] = $r[0]; if (isset($r[1])) { $values[$r_i] = $r[1]; } else { $values[$r_i] = $r[0]; } } $this->use_key_values = 1; // see https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=541 $this->set_prop('options', $options); $this->set_prop('values', $values); } } elseif (!$this->is_sql && !empty($this->alternate_input)) { $options = array(); $values = array(); $mixed = explode("\n", $this->alternate_input); foreach ($mixed as $m_i => $m) { $line = explode('||', $m); $options[$m_i] = trim($line[0]); if (isset($line[1])) { $values[$m_i] = trim($line[1]); } else { $values[$m_i] = trim($line[0]); } } $this->set_prop('options', $options); $this->set_prop('values', $values); } $opt_cnt = count($this->options); // Populate the options for ($i = 0; $i < $opt_cnt; $i++) { $hash = $this->get_props(); // just in case the array isn't set $hash['option'] = ''; if (isset($this->options[$i])) { $hash['option'] = htmlspecialchars($this->options[$i]); } $hash['value'] = ''; if (isset($this->values[$i])) { $hash['value'] = htmlspecialchars($this->values[$i]); } // Simplistic behavior if we don't use key=>value pairs if (!$this->use_key_values) { $hash['value'] = $hash['option']; } $hash['is_selected'] = ''; $hash['is_checked'] = ''; if (trim($current_value) == trim($hash['value'])) { $hash['is_checked'] = 'checked="checked"'; $hash['is_selected'] = 'selected="selected"'; } $hash['i'] = $i; $hash['id'] = $this->name; $this->all_options .= CCTM::parse($optiontpl, $hash); } // Populate the values (i.e. properties) of this field $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $this->value = htmlspecialchars(html_entity_decode($current_value)); // wrap $this->set_prop('value', $current_value); $this->content = CCTM::parse($fieldtpl, $this->get_props()); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * Print Custom Fields inside the given metabox inside the WP manager. * * @param object $post passed to this callback function by WP. * @param object $callback_args; $callback_args['args'] contains the * 7th parameter from the add_meta_box() function, an array with * the metabox_id and fields. * * @return null this function should print form fields. */ public static function print_custom_fields($post, $callback_args = '') { $metabox_id = CCTM::get_value($callback_args['args'], 'metabox_id'); $custom_fields = CCTM::get_value($callback_args['args'], 'fields', array()); $post_type = $post->post_type; // Output hash for parsing $output = array('content' => ''); foreach ($custom_fields as $cf) { if (!isset(CCTM::$data['custom_field_defs'][$cf])) { // throw error!! continue; } $def = CCTM::$data['custom_field_defs'][$cf]; if (isset($def['required']) && $def['required'] == 1) { $def['label'] = $def['label'] . '*'; // Add asterisk } $output_this_field = ''; if (!($FieldObj = CCTM::load_object($def['type'], 'fields'))) { continue; } if (self::_is_new_post()) { $FieldObj->set_props($def); $output_this_field = $FieldObj->get_create_field_instance(); } else { $current_value = get_post_meta($post->ID, $def['name'], true); // Check for validation errors. if (isset(CCTM::$post_validation_errors[$def['name']])) { $def['error_msg'] = sprintf('<span class="cctm_validation_error">%s</span>', CCTM::$post_validation_errors[$def['name']]); if (isset($def['class'])) { $def['class'] .= 'cctm_validation_error'; } else { $def['class'] = 'cctm_validation_error'; } } $FieldObj->set_props($def); $output_this_field = $FieldObj->get_edit_field_instance($current_value); } $output[$cf] = $output_this_field; $output['content'] .= $output_this_field; } // TODO: Print the nonce only once (currently it will print once for each metabox) $output['nonce'] = '<input type="hidden" name="_cctm_nonce" value="' . wp_create_nonce('cctm_create_update_post') . '" />'; $output['content'] .= $output['nonce']; // Print the form $metaboxtpl = CCTM::load_tpl(array('metaboxes/' . $metabox_id . '.tpl', 'metaboxes/_default.tpl')); print CCTM::parse($metaboxtpl, $output); }
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'); $Form->set_name_prefix(''); $Form->set_id_prefix(''); $Form->set_tpl($form_tpl); print $Form->generate(CCTM::$search_by, $existing_values); /*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 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; }
return; } $fieldname = preg_replace('/^' . CCTM_FormElement::css_id_prefix . '/', '', $raw_fieldname); $def = CCTM::get_value(CCTM::$data['custom_field_defs'], $fieldname); if (empty($def)) { print '<p>' . sprintf(__('Invalid fieldname: %s', CCTM_TXTDOMAIN), '<em>' . htmlspecialchars($fieldname) . '</em>') . '</p>'; return; } $instance = CCTM::get_value($_POST, 'instance'); // Will be either the single or the multi, depending. $tpl = ''; // Use multi - tpls if (CCTM::get_value($def, 'is_repeatable')) { $tpl = CCTM::load_tpl(array('fields/elements/' . $def['name'] . '.tpl', 'fields/elements/_' . $def['type'] . '_multi.tpl')); } else { $tpl = CCTM::load_tpl(array('fields/elements/' . $def['name'] . '.tpl', 'fields/elements/_' . $def['type'] . '.tpl')); } // Just in case... if (empty($tpl)) { print '<p>' . __('Formatting template not found!', CCTM_TXTDOMAIN) . '</p>'; return; } $FieldObj = CCTM::load_object($def['type'], 'fields'); if (!$FieldObj) { return; } $def['id'] = $fieldname; $def['i'] = $instance; $FieldObj->set_props($def); print CCTM::parse($tpl, $FieldObj->get_props()); /*EOF*/
$results = $Q->get_posts($args); $search_form_tpl = CCTM::load_tpl(array('post_selector/search_forms/_post_content_widget.tpl')); $Form->set_tpl($search_form_tpl); $Form->set_name_prefix(''); // blank out the prefixes $Form->set_id_prefix(''); $search_by = array('search_term', 'yearmonth'); // Pass these to hidden fields so jQuery can read them $Form->set_placeholder('post_type', $args['post_type']); $Form->set_placeholder('post_id_field', $post_id_field); $Form->set_placeholder('target_id', $target_id); $d['search_form'] = $Form->generate($search_by, $args); $item_tpl = ''; $wrapper_tpl = ''; $item_tpl = CCTM::load_tpl(array('post_selector/items/_widget.tpl')); $wrapper_tpl = CCTM::load_tpl(array('post_selector/wrappers/_default.tpl')); // Placeholders for the wrapper tpl $hash = array(); $hash['post_title'] = __('Title', CCTM_TXTDOMAIN); $hash['post_date'] = __('Date', CCTM_TXTDOMAIN); $hash['post_status'] = __('Status', CCTM_TXTDOMAIN); $hash['post_parent'] = __('Parent', CCTM_TXTDOMAIN); $hash['post_type'] = __('Post Type', CCTM_TXTDOMAIN); $hash['fieldname'] = ''; // needed for thickbox_inner.php //$hash['filter'] = __('Filter', CCTM_TXTDOMAIN); //$hash['show_all'] = __('Show All', CCTM_TXTDOMAIN); $hash['content'] = ''; // And the items //$results = array(); foreach ($results as $r) {
$r['thumbnail_url'] = CCTM::get_thumbnail($r['ID']); $r['id'] = $fieldname; $r['name'] = $fieldname; $r['id_prefix'] = CCTM_FormElement::css_id_prefix; $r['name_prefix'] = CCTM_FormElement::post_name_prefix; // Translate stuff (issue 279) $r['post_title'] = __($r['post_title']); $r['post_content'] = __($r['post_content']); $r['post_excerpt'] = __($r['post_excerpt']); // Special Stuff for RelationMeta fields: generate the other form elements // TODO: put this as a method in CCTM_FormElement to make it extendable? if ($def['type'] == 'relationmeta') { $r['metafields'] = ''; // Custom fields $custom_fields = CCTM::get_value($def, 'metafields', array()); $relationmeta_tpl = CCTM::load_tpl(array('fields/options/' . $def['name'] . '.tpl', 'fields/options/_relationmeta.tpl')); foreach ($custom_fields as $cf) { // skip the field if it no longer exists if (!isset(CCTM::$data['custom_field_defs'][$cf])) { continue; } $d = CCTM::$data['custom_field_defs'][$cf]; if (isset($d['required']) && $d['required'] == 1) { $d['label'] = $d['label'] . '*'; // Add asterisk } $output_this_field = ''; if (!($FieldObj = CCTM::load_object($d['type'], 'fields'))) { continue; } $d['name'] = $fieldname . '[' . $r['ID'] . '][' . $d['name'] . ']';
/** * Create only form elements. */ public function form($instance) { require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $formatted_post = ''; // Formatted post if (!isset($instance['title'])) { $instance['title'] = ''; // default value } if (isset($instance['post_id']) && !empty($instance['post_id'])) { $Q = new GetPostsQuery(); $post = $Q->get_post($instance['post_id']); $tpl = CCTM::load_tpl('widgets/post_item.tpl'); $post['edit_selected_post_label'] = __('Edit Selected Post', CCTM_TXTDOMAIN); $post['post_icon'] = CCTM::get_thumbnail($instance['post_id']); if ($post['post_type'] == 'attachment') { $post['edit_url'] = get_admin_url('', 'media.php') . "?attachment_id={$post['ID']}&action=edit"; } else { $post['edit_url'] = get_admin_url('', 'post.php') . "?post={$post['ID']}&action=edit"; } $post['target_id'] = $this->get_field_id('target_id'); $formatted_post = CCTM::parse($tpl, $post); } else { $instance['post_id'] = ''; } if (!isset($instance['formatting_string'])) { $instance['formatting_string'] = '[+post_content+]'; // default value } if (!isset($instance['post_type'])) { $instance['post_type'] = 'post'; // default value } $post_types = get_post_types(array('public' => 1)); $post_type_options = ''; foreach ($post_types as $k => $v) { $is_selected = ''; if ($k == $instance['post_type']) { $is_selected = ' selected="selected"'; } $post_type_options .= sprintf('<option value="%s" %s>%s</option>', $k, $is_selected, $v); } $is_checked = ''; if (isset($instance['override_title']) && $instance['override_title'] == 1) { $is_checked = ' checked="checked"'; } print '<p>' . $this->description . '<a href="http://code.google.com/p/wordpress-custom-content-type-manager/wiki/Post_Widget"><img src="' . CCTM_URL . '/images/question-mark.gif" width="16" height="16" /></a></p> <label class="cctm_label" for="' . $this->get_field_id('post_type') . '">Post Type</label> <input type="hidden" id="' . $this->get_field_id('post_id') . '" name="' . $this->get_field_name('post_id') . '" value="' . $instance['post_id'] . '" /> <select name="' . $this->get_field_name('post_type') . '" id="' . $this->get_field_id('post_type') . '"> ' . $post_type_options . ' </select><br/><br/> <span class="button" onclick="javascript:select_post(\'' . $this->get_field_id('post_id') . '\',\'' . $this->get_field_id('target_id') . '\',\'' . $this->get_field_id('post_type') . '\');">' . __('Choose Post', CCTM_TXTDOMAIN) . '</span> <br/><br/> <strong>Selected Post</strong><br/> <!-- This is where we wrote the preview HTML --> <div id="' . $this->get_field_id('target_id') . '">' . $formatted_post . '</div> <!-- Thickbox ID --> <div id="thickbox_' . $this->get_field_id('target_id') . '"></div> <br/><br/> <input type="checkbox" name="' . $this->get_field_name('override_title') . '" id="' . $this->get_field_id('override_title') . '" value="1" ' . $is_checked . '/> <label class="" for="' . $this->get_field_id('override_title') . '">' . __('Override Post Title', CCTM_TXTDOMAIN) . '</label><br/><br/> <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'] . '" /> <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> '; }
/** * Prints a form to the end user so that the users on the front-end can create * posts (beware security!). * * [cctm_post_form post_type="property" thank_you_url="" on_save="default-action-here"] * * @param array $raw_args: parameters from the shortcode: name, filter * @param string $options (optional) * @return string (printed) */ public static function cctm_post_form($raw_args = array(), $options = null) { $post_type = CCTM::get_value($raw_args, 'post_type'); $output = array('content' => '', 'errors' => ''); $defaults = array('post_type' => '', 'post_status' => 'draft', 'post_author' => CCTM::get_user_identifier(), 'post_date' => date('Y-m-d H:i:s'), 'post_date_gmt' => gmdate('Y-m-d H:i:s'), 'post_modified' => date('Y-m-d H:i:s'), 'post_modified_gmt' => gmdate('Y-m-d H:i:s'), '_label_title' => __('Title'), '_label_content' => __('Content'), '_label_excerpt' => __('Excerpt'), '_callback_pre' => null, '_callback' => 'CCTM::post_form_handler', '_action' => get_permalink(), '_tpl' => '_default', '_id_prefix' => 'cctm_', '_name_prefix' => 'cctm_', '_css' => CCTM_URL . '/css/manager.css,' . CCTM_URL . '/css/validation.css', '_fields' => '', '_debug' => 0); $args = array_merge($defaults, $raw_args); // Call the _callback_pre function (if present). if ($args['_callback_pre']) { if (function_exists($args['_callback_pre'])) { $output['content'] .= call_user_func($args['_callback_pre'], $args); } else { return '_callback_pre function does not exist: ' . $args['_callback_pre']; } } // Load CSS $css = explode(',', $args['_css']); foreach ($css as $c) { $css_id = basename($c); wp_register_style($css_id, $c); wp_enqueue_style($css_id); } // Hard error if (empty($post_type)) { return __('cctm_post_form shortcode requires the "post_type" parameter.', CCTM_TXTDOMAIN); } elseif (in_array($post_type, array('attachment', 'revision', 'nav_menu_item'))) { return sprintf(__('cctm_post_form shortcode does not support that post_type: %s', CCTM_TXTDOMAIN), $post_type); } // WTF? if (!post_type_exists($post_type)) { return sprintf(__('cctm_post_form shortcode post_type not found: %s', CCTM_TXTDOMAIN), $post_type); } //------------------------------ // Process the form on submit //------------------------------ $nonce = CCTM::get_value($_POST, '_cctm_nonce'); if (!empty($_POST)) { // Bogus submission if (!wp_verify_nonce($nonce, 'cctm_post_form_nonce')) { die('Your form could not be submitted. Please reload the page and try again.'); } // Strip prefix from post keys: only collect those with the given prefix. // This should allow mulitiple forms on one page. $vals = array(); foreach ($_POST as $k => $v) { if (preg_match('/^' . preg_quote($args['_name_prefix']) . '/', $k)) { $k = preg_replace('/^' . preg_quote($args['_name_prefix']) . '/', '', $k); $vals[$k] = wp_kses($v, array()); // TODO: options for this? } } // Validate fields StandardizedCustomFields::validate_fields($post_type, $vals); $vals = array_merge($vals, $args); if ($args['_debug']) { print '<div style="background-color:orange; padding:10px;"><h3>[cctm_post_form] DEBUG MODE</h3>' . '<h4>Posted Data</h4><pre>' . print_r($vals, true) . '</pre>' . '</div>'; return; } // Save data if it was properly submitted if (empty(CCTM::$post_validation_errors)) { return call_user_func($args['_callback'], $vals); } else { $error_item_tpl = CCTM::load_tpl(array('forms/_error_item.tpl')); $hash = array(); $hash['errors'] = ''; $hash['error_msg'] = __('This form has validation errors.', CCTM_TXTDOMAIN); $hash['cctm_url'] = CCTM_URL; foreach (CCTM::$post_validation_errors as $k => $v) { $hash['errors'] .= CCTM::parse($error_item_tpl, array('error' => $v)); } $error_wrapper_tpl = CCTM::load_tpl(array('forms/_error_wrapper.tpl')); $output['errors'] = CCTM::parse($error_wrapper_tpl, $hash); } } //------------------------------ // Generate the form. //------------------------------ $output['_action'] = $args['_action']; // Custom fields $explicit_fields = false; $custom_fields = array(); if ($args['_fields']) { $explicit_fields = true; $tmp = explode(',', $args['_fields']); foreach ($tmp as $t) { $custom_fields[] = trim($t); } $args['_fields'] = $custom_fields; } elseif (isset(CCTM::$data['post_type_defs'][$post_type]['custom_fields'])) { $custom_fields = CCTM::$data['post_type_defs'][$post_type]['custom_fields']; } // Post Title if (!$explicit_fields && post_type_supports($args['post_type'], 'title') && !isset($args['post_title']) || $explicit_fields && in_array('post_title', $custom_fields)) { $FieldObj = CCTM::load_object('text', 'fields'); $post_title_def = array('label' => $args['_label_title'], 'name' => 'post_title', 'default_value' => wp_kses(CCTM::get_value($_POST, $args['_name_prefix'] . 'post_title'), array()), 'extra' => '', 'class' => '', 'description' => '', 'validator' => '', 'output_filter' => '', 'type' => 'text'); $FieldObj->set_props($post_title_def); $output_this_field = $FieldObj->get_create_field_instance(); $output['post_title'] = $output_this_field; $output['content'] .= $output_this_field; } // Post Content (editor) if (!$explicit_fields && post_type_supports($args['post_type'], 'editor') && !isset($args['post_content']) || $explicit_fields && in_array('post_content', $custom_fields)) { $FieldObj = CCTM::load_object('textarea', 'fields'); // TODO: change to wysiwyg $post_title_def = array('label' => $args['_label_content'], 'name' => 'post_content', 'default_value' => wp_kses(CCTM::get_value($_POST, $args['_name_prefix'] . 'post_content'), array()), 'extra' => 'cols="80" rows="10"', 'class' => '', 'description' => '', 'validator' => '', 'output_filter' => '', 'type' => 'textarea'); $FieldObj->set_props($post_title_def); $output_this_field = $FieldObj->get_create_field_instance(); $output['post_content'] = $output_this_field; $output['content'] .= $output_this_field; } // Post Excerpt if (!$explicit_fields && post_type_supports($args['post_type'], 'excerpt') && !isset($args['post_excerpt']) || $explicit_fields && in_array('post_excerpt', $custom_fields)) { $FieldObj = CCTM::load_object('textarea', 'fields'); $post_title_def = array('label' => $args['_label_excerpt'], 'name' => 'post_excerpt', 'default_value' => wp_kses(CCTM::get_value($_POST, $args['_name_prefix'] . 'post_excerpt'), array()), 'extra' => 'cols="80" rows="10"', 'class' => '', 'description' => '', 'validator' => '', 'output_filter' => '', 'type' => 'textarea'); $FieldObj->set_props($post_title_def); $output_this_field = $FieldObj->get_create_field_instance(); $output['post_excerpt'] = $output_this_field; $output['content'] .= $output_this_field; } foreach ($custom_fields as $cf) { // skip the field if its value is hard-coded if (!isset(CCTM::$data['custom_field_defs'][$cf]) || isset($args[$cf])) { continue; } $def = CCTM::$data['custom_field_defs'][$cf]; if (isset($def['required']) && $def['required'] == 1) { $def['label'] = $def['label'] . '*'; // Add asterisk } // SECURITY OVERRIDES!!! // See https://code.google.com/p/wordpress-custom-content-type-manager/wiki/cctm_post_form if ($def['type'] == 'wysiwyg') { $def['type'] = 'textarea'; } elseif (in_array($def['type'], array('relation', 'image', 'media'))) { $output['errors'] .= ' ' . $def['type'] . ' fields not allowed.'; continue; } $output_this_field = ''; if (!($FieldObj = CCTM::load_object($def['type'], 'fields'))) { continue; } // Repopulate if (isset($_POST[$args['_name_prefix'] . $def['name']])) { $def['default_value'] = wp_kses($_POST[$args['_name_prefix'] . $def['name']], array()); } if (empty(CCTM::$post_validation_errors)) { $FieldObj->set_props($def); $output_this_field = $FieldObj->get_create_field_instance(); } else { $current_value = wp_kses(CCTM::get_value($_POST, $args['_name_prefix'] . $def['name']), array()); if (isset(CCTM::$post_validation_errors[$def['name']])) { $def['error_msg'] = sprintf('<span class="cctm_validation_error">%s</span>', CCTM::$post_validation_errors[$def['name']]); if (isset($def['class'])) { $def['class'] .= 'cctm_validation_error'; } else { $def['class'] = 'cctm_validation_error'; } } $FieldObj->set_props($def); $output_this_field = $FieldObj->get_edit_field_instance($current_value); } $output[$cf] = $output_this_field; $output['content'] .= $output_this_field; } // Add Nonce $output['nonce'] = '<input type="hidden" name="_cctm_nonce" value="' . wp_create_nonce('cctm_post_form_nonce') . '" />'; $output['content'] .= $output['nonce']; // Add Submit $output['submit'] = '<input type="submit" value="' . __('Submit', CCTM_TXTDOMAIN) . '" />'; $output['content'] .= $output['submit']; $formtpl = CCTM::load_tpl(array('forms/' . $args['_tpl'] . '.tpl', 'forms/_' . $post_type . '.tpl', 'forms/_default.tpl')); if ($args['_debug']) { $formtpl = '<div style="background-color:orange; padding:10px;"><h3>[cctm_post_form] DEBUG MODE</h3>' . '<h4>Arguments</h4><pre>' . print_r($args, true) . '</pre>' . '</div>' . $formtpl; } return CCTM::parse($formtpl, $output); }
//print '<pre>'.$Q->debug().'</pre>'; $search_form_tpl = CCTM::load_tpl(array('post_selector/search_forms/' . $fieldname . '.tpl', 'post_selector/search_forms/_' . $def['type'] . '.tpl', 'post_selector/search_forms/_default.tpl')); $Form->set_tpl($search_form_tpl); $Form->set_name_prefix(''); // blank out the prefixes $Form->set_id_prefix(''); $d['search_form'] = $Form->generate(CCTM::$search_by, $args); $item_tpl = ''; $wrapper_tpl = ''; // Multi Field (contains an array of values. if (isset($def['is_repeatable']) && $def['is_repeatable'] == 1) { $item_tpl = CCTM::load_tpl(array('post_selector/items/' . $fieldname . '.tpl', 'post_selector/items/_' . $def['type'] . '_multi.tpl', 'post_selector/items/_relation_multi.tpl')); $wrapper_tpl = CCTM::load_tpl(array('post_selector/wrappers/' . $fieldname . '.tpl', 'post_selector/wrappers/_' . $def['type'] . '_multi.tpl', 'post_selector/wrappers/_relation_multi.tpl')); } else { $item_tpl = CCTM::load_tpl(array('post_selector/items/' . $fieldname . '.tpl', 'post_selector/items/_' . $def['type'] . '.tpl', 'post_selector/items/_default.tpl')); $wrapper_tpl = CCTM::load_tpl(array('post_selector/wrappers/' . $fieldname . '.tpl', 'post_selector/wrappers/_' . $def['type'] . '.tpl', 'post_selector/wrappers/_default.tpl')); } // Placeholders for the wrapper tpl $hash = array(); $hash['post_title'] = __('Title', CCTM_TXTDOMAIN); $hash['post_date'] = __('Date', CCTM_TXTDOMAIN); $hash['post_status'] = __('Status', CCTM_TXTDOMAIN); $hash['post_parent'] = __('Parent', CCTM_TXTDOMAIN); $hash['post_type'] = __('Post Type', CCTM_TXTDOMAIN); $hash['add_to_post'] = __('Add to Post', CCTM_TXTDOMAIN); $hash['add_to_post_and_close'] = __('Add to Post and Close', CCTM_TXTDOMAIN); //$hash['filter'] = __('Filter', CCTM_TXTDOMAIN); //$hash['show_all'] = __('Show All', CCTM_TXTDOMAIN); $hash['content'] = ''; // And the items //$results = array();
/** * This is somewhat tricky if the values the user wants to store are HTML/JS. * See http://www.php.net/manual/en/function.htmlspecialchars.php#99185 * * @param mixed $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { // Populate the values (i.e. properties) of this field $this->id = $this->name; $fieldtpl = ''; $wrappertpl = ''; if ($this->evaluate_update_value) { $this->value = eval($this->update_value_code); } else { $this->value = htmlspecialchars(html_entity_decode($this->get_value($current_value, 'to_string'))); } $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_hidden.tpl', 'fields/elements/_default.tpl')); return CCTM::parse($fieldtpl, $this->get_props()); }
/** * * * @param mixed $current_value current value for this field. * @return string */ public function get_edit_field_instance($current_value) { $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $fieldtpl = ''; $wrappertpl = ''; // Figure out which tpls to load if (in_array($this->date_format, array('yyyy-mm-dd hh:mm:ss', 'mm/dd/yy hh:mm', 'mm/dd/yy hh:mm am'))) { $this->datetype = 'datetime'; } elseif (in_array($this->date_format, array('show24Hours: true, step: 10', 'show24Hours: true, step: 15', 'show24Hours: true, step: 30', 'show24Hours: false, step: 10', 'show24Hours: false, step: 15', 'show24Hours: false, step: 30'))) { $this->datetype = 'time'; } else { $this->datetype = 'date'; } // Multi-version of the field if ($this->is_repeatable) { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->datetype . '_multi.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->datetype . '_multi.tpl', 'fields/wrappers/_text_multi.tpl')); $this->i = 0; $values = $this->get_value($current_value, 'to_array'); //die(print_r($values,true)); $this->content = ''; foreach ($values as $v) { $this->value = htmlspecialchars(html_entity_decode($v)); $this->content .= CCTM::parse($fieldtpl, $this->get_props()); $this->i = $this->i + 1; } } else { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_' . $this->datetype . '.tpl', 'fields/elements/_default.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_' . $this->datetype . '.tpl', 'fields/wrappers/_default.tpl')); $this->value = htmlspecialchars(html_entity_decode($this->get_value($current_value, 'to_string'))); $this->content = CCTM::parse($fieldtpl, $this->get_props()); } $this->add_label = __('Add', CCTM_TXTDOMAIN); return CCTM::parse($wrappertpl, $this->get_props()); }
/** * 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'; // 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); $this->remove_label = __('Remove All'); // 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); // Output Filter $out .= $this->format_available_output_filters($def); return $out; }
// See https://code.google.com/p/wordpress-summarize-posts/issues/detail?id=39 $post_type = CCTM::get_value($_POST, 'post_type', 'post'); $cap = 'edit_posts'; if (isset($GLOBALS['wp_post_types'][$post_type]->cap->edit_posts)) { $cap = $GLOBALS['wp_post_types'][$post_type]->cap->edit_posts; } if (!current_user_can($cap)) { die('<pre>You do not have permission to do that.</pre>'); } require_once CCTM_PATH . '/includes/GetPostsQuery.php'; //print '<div>'. print_r($_POST, true).'</div>'; $post_id = CCTM::get_value($_POST, 'post_id'); $target_id = CCTM::get_value($_POST, 'target_id'); // Will be either the single or the multi, depending. $tpl = ''; $tpl = CCTM::load_tpl('widgets/post_item.tpl'); // Just in case... if (empty($tpl)) { print '<p>' . __('Formatting template not found!', CCTM_TXTDOMAIN) . '</p>'; return; } $Q = new GetPostsQuery(); $post = $Q->get_post($post_id); $post['edit_selected_post_label'] = __('Edit Selected Post', CCTM_TXTDOMAIN); $post_type = $post['post_type']; $post['post_icon'] = CCTM::get_thumbnail($post_id); if ($post_type == 'attachment') { $post['edit_url'] = get_admin_url('', 'media.php') . "?attachment_id={$post_id}&action=edit"; } else { $post['edit_url'] = get_admin_url('', 'post.php') . "?post={$post_id}&action=edit"; }
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'; $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/_summarize_posts.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/search.tpl'); $Form->set_name_prefix(''); $Form->set_id_prefix(''); $Form->set_placeholder('cctm_url', CCTM_URL); $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']); } $Form->set_placeholder('custom_fields', $custom_field_options); // I18n for the search form $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));