/** * <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()); }
/** * * * @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()); }
/** * 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()); }
/** * Apply the filter. * * @param mixed input: an integer, an array of integers, or a JSON string representing an array of integers. * @param string optional formatting tpl * @return mixed */ public function filter($input, $options = null) { $required_functions = array('getimagesize', 'imagecreatefromjpeg', 'imagecreatefromgif', 'imagecreatefrompng'); foreach ($required_functions as $f) { if (!function_exists($f)) { return sprintf(__('Missing required function %s'), '<code>' . $f . '</code>'); } } require_once CCTM_PATH . '/includes/SummarizePosts.php'; require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $tpl = '<div class="cctm_gallery" id="cctm_gallery_[+i+]"><img height="[+height+]" width="[+width+]" src="[+guid+]" title="[+post_title+]" alt="[+alt+]" class="cctm_image" id="cctm_image_[+i+]"/></div>'; if (!empty($options)) { $tpl = $options; } if (empty($input)) { return ''; } $inputs = $this->to_array($input); $Q = new GetPostsQuery(); $Q->set_include_hidden_fields(true); // We can't use $Q->get_posts() because MySQL will return results in an arbitrary order. boo. $output = ''; $i = 1; foreach ($inputs as $image_id) { $r = $Q->get_post($image_id); // Translate $r['post_title'] = __($r['post_title']); $r['post_content'] = __($r['post_content']); $r['post_excerpt'] = __($r['post_excerpt']); $image_info = getimagesize($r['guid']); $image_type = $image_info[2]; if ($image_type == IMAGETYPE_JPEG) { $this_image = imagecreatefromjpeg($r['guid']); } elseif ($image_type == IMAGETYPE_GIF) { $this_image = imagecreatefromgif($r['guid']); } elseif ($image_type == IMAGETYPE_PNG) { $this_image = imagecreatefrompng($r['guid']); } if (isset($r['_wp_attachment_image_alt'])) { $r['alt'] = $r['_wp_attachment_image_alt']; } $r['i'] = $i; $r['width'] = imagesx($this_image); $r['height'] = imagesy($this_image); $output .= CCTM::parse($tpl, $r); $i++; } return $output; }
/** * Apply the filter. * * @param mixed user id or an array of them * @param mixed optional formatting string * @return mixed */ public function filter($input, $options = null) { $tpl = '<div class="cctm_userinfo" id="cctm_user_[+ID+]">[+user_nicename+]: [+user_email+]</div>'; if (!empty($options)) { $tpl = $options; } $inputs = $this->to_array($input); $output = ''; foreach ($inputs as $input) { $input = (int) $input; // Retrieve from CCTM request cache? (this caches data for a single request) // we cache the userdata array, keyed to a user ID if (isset(CCTM::$cache['userinfo'][$input])) { $output .= CCTM::parse($tpl, CCTM::$cache['userinfo'][$input]); continue; } global $wpdb; $userdata = array(); $query = $wpdb->prepare("SELECT ID, user_login, user_nicename, user_email, \n\t\t\t\tuser_url, user_registered, user_activation_key, user_status, \n\t\t\t\tdisplay_name FROM " . $wpdb->prefix . "users WHERE ID = %s", $input); $results = $wpdb->get_results($query, ARRAY_A); // No data for this user? if (!isset($results[0])) { CCTM::$cache['userinfo'][$input] = array(); // blank: prevents multiple queries continue; // $output .= CCTM::parse($tpl, $userdata); // ??? should we??? } // shift off the first (and only) result $userdata = $results[0]; // Get metadata $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "usermeta WHERE user_id = %s", $input); $results = $wpdb->get_results($query, ARRAY_A); // No metadata (don't know how'd you get here, but just in case...) if (empty($results)) { CCTM::$cache['userinfo'][$input] = $userdata; $output .= CCTM::parse($tpl, $userdata); continue; // next user... } foreach ($results as $r) { $userdata[$r['meta_key']] = $r['meta_value']; } CCTM::$cache['userinfo'][$input] = $userdata; $output .= CCTM::parse($tpl, $userdata); } return $output; }
/** * Apply the filter. * * @param mixed input: a single post ID or an array of them * @param string formatting string OR clickable title * @return mixed */ public function filter($input, $options = null) { $output = ''; // Gotta set the default here due to how print_custom_field calls get_custom_field if (empty($options)) { $options = '<a href="[+permalink+]" title="[+post_title+]">[+post_title+]</a>'; } elseif (strpos($options, '[+') === false) { $options = '<a href="[+permalink+]" title="[+post_title+]">' . $options . '</a>'; } $input = $this->to_array($input); if (empty($input)) { return ''; } $output = ''; if ($this->is_array_input) { foreach ($input as &$item) { if ($item) { //$post = get_post($item); if (!is_numeric($item)) { $item = sprintf(__('Invalid input. %s operates on post IDs only.', CCTM_TXTDOMAIN), 'to_link'); continue; } $post = get_post_complete($item); if (!is_array($post)) { $item = __('Referenced post not found.', CCTM_TXTDOMAIN); continue; } $link_text = $post['post_title']; $item = CCTM::parse($options, $post); } } return implode(', ', $input); } else { if (!is_numeric($input[0])) { return sprintf(__('Invalid input. %s operates on post IDs only.', CCTM_TXTDOMAIN), 'to_link'); } $post = get_post_complete($input[0]); if (!is_array($post)) { return _e('Referenced post not found.', CCTM_TXTDOMAIN); } return CCTM::parse($options, $post); } }
/** * Convert a post id to an array represent the post and all its data. * * @param mixed integer post_id or an array of post_id's * @param string optional field name to return OR a formatting string with [+placeholders+] * @return mixed */ public function filter($input, $options = null) { $input = $this->to_array($input); if ($options && is_scalar($options)) { $output = ''; } else { $output = array(); } if (empty($input)) { return false; } if ($this->is_array_input) { foreach ($input as $k => $item) { $item = (int) $item; $post = get_post_complete($item); if ($options && is_scalar($options)) { if (isset($post[$options])) { $output .= $post[$options]; } else { $output .= CCTM::parse($options, $post); } } else { $output[] = $post; } } return $output; } else { $input = (int) $input[0]; if ($options && is_scalar($options)) { $post = get_post_complete($input); if (isset($post[$options])) { return $post[$options]; } return CCTM::parse($options, $post); } else { return get_post_complete($input); } } }
/** * Format an array of values. * * @param mixed $input, e.g. a json_encoded array like '["cat","dog","bird"]' OR a real PHP array, e.g. array('cat','dog','bird') * @param mixed $options (optional)formatting parameters * @return string */ public function filter($input, $options = null) { $array = $this->to_array($input); // Return an empty string if the input is empty: // http://wordpress.org/support/topic/plugin-custom-content-type-manager-displaying-custom-fields-in-conditional-tags?replies=4#post-2537738 if (empty($array)) { return ''; } if (!empty($options) && is_array($options)) { $out = ''; // format each value if (isset($options[0])) { foreach ($array as $k => $v) { $hash['key'] = $k; $hash['value'] = $v; $out .= CCTM::parse($options[0], $hash); } } else { // ??? user supplied an associative array for options??? return __('Options array in incorrect format!', CCTM_TXTDOMAIN); } // wrap the output if (isset($options[1])) { $hash['content'] = $out; return CCTM::parse($options[1], $hash); } } elseif (!empty($options) && !is_array($options)) { //foreach ( $array as $i => $item ) { // $array[$i] = htmlspecialchars($item); // we apply this //} if ($this->_is_assoc($array)) { $array = array_values($array); } return implode($options, $array); } else { return implode(', ', $array); } }
/** * Apply the filter. * * @param mixed input * @param mixed optional arguments defining how to wrap the input * @return mixed */ public function filter($input, $options = null) { $inputs = $this->to_array($input); $output = ''; foreach ($inputs as $input) { if (empty($options) || empty($input)) { $output .= $input; } elseif (is_array($options)) { $before = ''; $after = ''; if (isset($options[0])) { $before = $options[0]; } if (isset($options[1])) { $after = $options[1]; } $output .= $before . $input . $after; } else { $output .= CCTM::parse($options, array('content' => $input)); } } return $output; }
// 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'] . ']'; $d['is_repeatable'] = false; // override $FieldObj->set_props($d); $output_this_field = $FieldObj->get_create_field_instance(); $r['metafields'] .= CCTM::parse($relationmeta_tpl, array('content' => $output_this_field)); } } print CCTM::parse($tpl, $r); } /*EOF*/
/** * Process the $args to something GetPostsQuery. */ function widget($args, $instance) { if (!isset($instance['parameters']) || empty($instance['parameters'])) { return; // don't do anything until the search is defined. } require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $q_args = array(); $search_parameters_str = $instance['parameters']; parse_str($search_parameters_str, $q_args); //print_r($q_args); exit; if (isset($q_args['include']) && empty($q_args['include'])) { unset($q_args['include']); } $Q = new GetPostsQuery(); $results = $Q->get_posts($q_args); //print $Q->debug(); return; $output = $args['before_widget'] . $args['before_title'] . $instance['title'] . $args['after_title'] . '<ul>'; foreach ($results as $r) { $output .= CCTM::parse($instance['formatting_string'], $r); } $output .= '</ul>' . $args['after_widget']; print $output; }
/** * 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; }
/** * 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()); }
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"; } $post['target_id'] = $target_id; print CCTM::parse($tpl, $post); /*EOF*/
/** * Print posts that link to this post via a relation field. * @param string $tpl * @return void -- this actually prints data. */ function print_incoming_links($tpl = null) { if (empty($tpl)) { $tpl = '<span><a href="[+permalink+]">[+post_title+] ([+ID+])</a></span> '; } $Q = new GetPostsQuery(); $args = array(); $args['include'] = get_incoming_links(); // $args['post_status'] = 'draft,publish,inherit'; $results = $Q->get_posts($args); $output = ''; foreach ($results as $r) { $output .= CCTM::parse($tpl, $r); } print $output; }
/** * Note that the HTML in $option_html should match the JavaScript version of * the same HTML in js/dropdown.js (see the append_dropdown_option() function). * I couldn't think of a clean way to do this, but the fundamental problem is * that both PHP and JS need to draw the same HTML into this form: * PHP draws it when an existing definition is *edited*, whereas JS draws it * when you dynamically *create* new dropdown options. * * @param array $def nested array of existing definition. * @return string */ public function get_edit_field_definition($def) { // Standard $out = $this->format_standard_fields($def, false); $is_checked = ''; $is_sql_checked = ''; $readonly_str = ' readonly="readonly"'; if (isset($def['use_key_values']) && $def['use_key_values']) { $is_checked = 'checked="checked"'; $readonly_str = ''; } if (isset($def['is_sql']) && $def['is_sql']) { $is_sql_checked = 'checked="checked"'; } // Options $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"> <table><tr><td width="600" style="vertical-align:top">'; // Use Key => Value Pairs? (if not, the simple usage is simple options) $out .= ' <input type="hidden" name="use_key_values" value="0"/> <div class="' . self::wrapper_css_class . '" id="use_key_values_wrapper"> <label for="use_key_values" class="cctm_label cctm_checkbox_label" id="use_key_values_label">' . __('Distinct options/values?', CCTM_TXTDOMAIN) . '</label> <br /> <input type="checkbox" name="use_key_values" class="cctm_checkbox" id="use_key_values" value="1" onclick="javascript:toggle_readonly();" ' . $is_checked . '/> <span>' . $this->descriptions['use_key_values'] . '</span> </div>'; // OPTIONS $option_cnt = 0; if (isset($def['options'])) { $option_cnt = count($def['options']); } // using the parse function because this got too crazy with escaping single quotes $hash = array(); $hash['option_cnt'] = $option_cnt; $hash['delete'] = __('Delete'); $hash['options'] = __('Options', CCTM_TXTDOMAIN); $hash['values'] = __('Stored Values', CCTM_TXTDOMAIN); $hash['add_option'] = __('Add Option', CCTM_TXTDOMAIN); $hash['set_as_default'] = __('Set as Default', CCTM_TXTDOMAIN); $tpl = ' <script type="text/javascript"> jQuery(function() { jQuery( "#dropdown_options2" ).sortable(); // jQuery( "#dropdown_options2" ).disableSelection(); }); </script> <table id="dropdown_options"> <thead> <td scope="col" id="sorter" class="" style=""> </td> <td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+options+]</label></td> <td width="200"><label for="options" class="cctm_label cctm_select_label" id="cctm_label_options">[+values+]</label></td> <td> <span class="button" onclick="javascript:append_dropdown_option(\'dropdown_options\',\'[+delete+]\',\'[+set_as_default+]\',\'[+option_cnt+]\');">[+add_option+]</span> </td> </thead> <tbody id="dropdown_options2">'; $out .= CCTM::parse($tpl, $hash); // this html should match up with the js html in dropdown.js $option_html = ' <tr id="%s"> <td><span class="ui-icon ui-icon-arrowthick-2-n-s"></span></td> <td><input type="text" name="options[]" id="option_%s" value="%s"/></td> <td><input type="text" name="values[]" id="value_%s" value="%s" class="possibly_gray"' . $readonly_str . '/></td> <td><span class="button" onclick="javascript:remove_html(\'%s\');">%s</span> <span class="button" onclick="javascript:set_as_default(\'%s\');">%s</span></td> </tr>'; $opt_i = 0; // used to uniquely ID options. if (!empty($def['options']) && is_array($def['options'])) { $opt_cnt = count($def['options']); for ($i = 0; $i < $opt_cnt; $i++) { // just in case the array isn't set $option_txt = ''; if (isset($def['options'][$i])) { $option_txt = htmlspecialchars(trim($def['options'][$i])); } $value_txt = ''; if (isset($def['values'][$i])) { $value_txt = htmlspecialchars(trim($def['values'][$i])); } $option_css_id = 'cctm_dropdown_option' . $opt_i; $out .= sprintf($option_html, $option_css_id, $opt_i, $option_txt, $opt_i, $value_txt, $option_css_id, __('Delete'), $opt_i, __('Set as Default')); $opt_i = $opt_i + 1; } } $out .= ' </tbody> </table>'; // close id="dropdown_options" // Display as Radio Button or as Dropdown? $out .= '<div class="' . self::wrapper_css_class . '" id="display_type_wrapper"> <label class="cctm_label cctm_checkbox_label" id="display_type_label">' . __('How should the field display?', CCTM_TXTDOMAIN) . '</label> <br /> <input type="radio" name="display_type" class="cctm_radio" id="display_type_dropdown" value="dropdown" ' . CCTM::is_radio_selected('dropdown', CCTM::get_value($this->props, 'display_type', 'dropdown')) . '/> <label for="display_type_dropdown" class="cctm_label cctm_radio_label" id="display_type_dropdown_label">' . __('Dropdown', CCTM_TXTDOMAIN) . '</label><br /> <input type="radio" name="display_type" class="cctm_radio" id="display_type_radio" value="radio" ' . CCTM::is_radio_selected('radio', CCTM::get_value($this->props, 'display_type', 'dropdown')) . '/> <label for="display_type_radio" class="cctm_label cctm_radio_label" id="display_type_radio_label">' . __('Radio Button', CCTM_TXTDOMAIN) . '</label><br /> </div>'; // Secondary Input options $out .= '</td><td style="vertical-align:top"> <label class="cctm_label cctm_textarea_label" id="advanced_label">' . __('Alternate Input', CCTM_TXTDOMAIN) . '</label> <span>' . __('Use this input if you want to options in bulk. Separate options and values using double-pipes "||" with the visible option on the left, the corresponding value to be stored on the right (if present). You may also enter a valid MySQL query. This field overrides other inputs!', CCTM_TXTDOMAIN) . '</span><br/> <textarea name="alternate_input" id="alternate_input" cols="50" rows="10">' . CCTM::get_value($def, 'alternate_input') . '</textarea>'; // Execute as MySQL? $out .= '<div class="' . self::wrapper_css_class . '" id="is_sql_wrapper"> <input type="hidden" name="is_sql" value="0"/> <input type="checkbox" name="is_sql" class="cctm_checkbox" id="is_sql" value="1"' . $is_sql_checked . '/> <label for="is_sql" class="cctm_label cctm_checkbox_label" id="is_sql_label">' . __('Execute as a MySQL query?', CCTM_TXTDOMAIN) . '</label> <span>' . __('Select up to 2 columns: the 1st column will be the visible label and the 2nd column (if present) will represent the value stored in the database. Use [+table_prefix+] instead of hard-coding your WordPress database table prefix.', CCTM_TXTDOMAIN) . '</span> </div>'; $out .= ' </td></tr></table> </div><!-- /inside --> </div><!-- /postbox -->'; // Validations / Required $out .= $this->format_validators($def, false); // Output Filter $out .= $this->format_available_output_filters($def); return $out; }
function testParser12() { $tpl = '[+post_id:get_post==post_title:wrapper==<strong>{{content}}</strong>+]'; $hash = array('post_id' => 80); $output = CCTM::parse($tpl, $hash); $this->assertTrue($output == '<strong>Harry Potter</strong>'); }
$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(); foreach ($results as $r) { $r['name'] = $raw_fieldname; $r['preview'] = __('Preview', CCTM_TXTDOMAIN); $r['select'] = __('Select', CCTM_TXTDOMAIN); $r['field_id'] = $raw_fieldname; $r['thumbnail_url'] = CCTM::get_thumbnail($r['ID']); // Translate stuff (issue 279) $r['post_title'] = __($r['post_title']); $r['post_content'] = __($r['post_content']); $r['post_excerpt'] = __($r['post_excerpt']); $hash['content'] .= CCTM::parse($item_tpl, $r); } $d['content'] .= CCTM::parse($wrapper_tpl, $hash); $d['content'] .= '<div class="cctm_pagination_links">' . $Q->get_pagination_links() . '</div>'; if (isset($_POST['wrap_thickbox'])) { print CCTM::load_view('templates/thickbox.php', $d); } else { //print CCTM::load_view('templates/thickbox_inner.php', $d); print $d['content']; } exit; /*EOF*/
/** * 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()); }
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*/
/** * Process the $args to something GetPostsQuery. */ function widget($args, $instance) { // Avoid placing empty widgets if (!isset($instance['post_id']) || empty($instance['post_id'])) { return; } require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $post_id = (int) $instance['post_id']; $Q = new GetPostsQuery(); $post = $Q->get_post($post_id); $post['post_content'] = do_shortcode(wpautop($post['post_content'])); $output = $args['before_widget']; if (isset($instance['override_title']) && $instance['override_title'] == 1) { $title = $instance['title']; } else { $title = $post['post_title']; // default is to use the post's title } if (!empty($title)) { $output .= $args['before_title'] . $title . $args['after_title']; } if (!empty($instance['formatting_string'])) { $output .= CCTM::parse($instance['formatting_string'], $post); } else { $output .= $post['post_content']; } $output .= $args['after_widget']; print $output; }
/** * 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; }
/** * 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); }
/** * Callback function used by the cctm_post_form() function. This is what gets * called * * @param array $args: parameters from the shortcode and posted data * @return string (printed) */ public static function post_form_handler($args) { //return print_r($args,true); // Strip out the control stuff (keys begin with underscore) $vals = array(); foreach ($args as $k => $v) { if ($k[0] == '_') { continue; } $vals[$k] = $v; } // Insert into Database $email_only = CCTM::get_value($args, '_email_only'); if (!$email_only) { require_once CCTM_PATH . '/includes/SP_Post.php'; $P = new SP_Post(); CCTM::$post_id = $P->insert($vals); } // Email stuff if (isset($args['_email_to']) && !empty($args['_email_to']) && isset($args['_email_tpl']) && !empty($args['_email_tpl'])) { $Q = new GetPostsQuery(); $P = $Q->get_post($args['_email_tpl']); //return print_r($P, true); $subject = $P['post_title']; $message_tpl = wpautop($P['post_content']); // If the 'My User' <*****@*****.**> format is used, we have to manipulate the string // to keep WP from tripping over itself $from = CCTM::get_value($args, '_email_from', get_bloginfo('admin_email')); $from = str_replace(array(''', '"', '"', '<', '>'), array("'", '"', '"', '<', '>'), $from); // die(print_r($args,true)); $subject = CCTM::get_value($args, '_email_subject', $subject); $headers = 'From: ' . $from . "\r\n"; $headers .= 'content-type: text/html' . "\r\n"; $message = CCTM::parse($message_tpl, $vals); if (!wp_mail($args['_email_to'], $subject, $message, $headers)) { return "There was a problem sending the email."; } } // Redirect or show a simple message. $redirect = CCTM::get_value($args, '_redirect'); if ($redirect) { $url = get_permalink($redirect); CCTM::redirect($url, true); } // Else, return message: return CCTM::get_value($args, '_msg', "Thanks for submitting the form!"); }
/** * * * @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()); }
/** * http://codex.wordpress.org/Template_Tags/get_posts * sample usage * shortcode params: * 'numberposts' => 5, * 'offset' => 0, * 'category' => , * 'orderby' => any valid column from the wp_posts table (minus the "post_") * ID * author * date * date_gmt * content * title * excerpt * status * comment_status * ping_status * password * name * to_ping * pinged * modified * modified_gmt * content_filtered * parent * guid * menu_order * type * mime_type * comment_count * rand -- randomly sort results. This is not compatible with the paginate options! If set, * the 'paginate' option will be ignored! * 'order' => 'DESC', * 'include' => , * 'exclude' => , * 'meta_key' => , * 'meta_value' => , * 'post_type' => 'post', * 'post_mime_type' => , * 'post_parent' => , * 'post_status' => 'publish' * * CUSTOM ** * before * after * paginate true|false * placeholders: * [+help+] * [shortcode x="1" y="2"]<ul>Formatting template goes here</ul>[/shortcode] * The $content comes from what's between the tags. * A standard post has the following attributes: * [ID] => 6 * [post_author] => 2 * [post_date] => 2010-11-13 20:13:28 * [post_date_gmt] => 2010-11-13 20:13:28 * [post_content] => http://pretasurf.com/blog/wp-content/uploads/2010/11/cropped-LIFE_04_DSC_0024.bw_.jpg * [post_title] => cropped-LIFE_04_DSC_0024.bw_.jpg * [post_excerpt] => * [post_status] => inherit * [comment_status] => closed * [ping_status] => open * [post_password] => * [post_name] => cropped-life_04_dsc_0024-bw_-jpg * [to_ping] => * [pinged] => * [post_modified] => 2010-11-13 20:13:28 * [post_modified_gmt] => 2010-11-13 20:13:28 * [post_content_filtered] => * [post_parent] => 0 * [guid] => http://pretasurf.com/blog/wp-content/uploads/2010/11/cropped-LIFE_04_DSC_0024.bw_.jpg * [menu_order] => 0 * [post_type] => attachment * [post_mime_type] => image/jpeg * [comment_count] => 0 * [filter] => raw * But notice that some of these are not very friendly. E.g. post_author, the user expects the author's name. So we do some duplicating, tweaking to make this easier on the user. * Placeholders: * Generally, these correspond to the names of the database columns in the wp_posts table, but some * convenience placeholders were added. * drwxr-xr-x 8 everett2 staff 272 Feb 5 20:16 . * [+ID+] * [+post_author+] * [+post_date+] * [+post_date_gmt+] * [+post_content+] * [+post_title+] * [+post_excerpt+] * [+post_status+] * [+comment_status+] * [+ping_status+] * [+post_password+] * [+post_name+] * [+to_ping+] * [+pinged+] * [+post_modified+] * [+post_modified_gmt+] * [+post_content_filtered+] * [+post_parent+] * [+guid+] * [+menu_order+] * [+post_type+] * [+post_mime_type+] * [+comment_count+] * [+filter+] * Convenience: * [+permalink+] * [+the_content+] * [+the_author+] * [+title+] * [+date+] * [+excerpt+] * [+mime_type+] * [+modified+] * [+parent+] * [+modified_gmt+] * ; * * @param array $raw_args (optional) * @param string $content_str (optional) * @return array */ public static function get_posts($raw_args = array(), $content_str = null) { // See http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=389 $content_str = preg_replace('#^</p>#', '', $content_str); $content_str = preg_replace('#<p>$#', '', $content_str); $content_str = trim($content_str); if (empty($content_str)) { $content_str = self::result_tpl; // default } if (empty($raw_args) || !is_array($raw_args)) { $raw_args = array(); } $formatting_args = shortcode_atts(self::$formatting_defaults, $raw_args); $formatting_args['tpl_str'] = self::_get_tpl($content_str, $formatting_args); $help_flag = false; if (isset($raw_args['help'])) { $help_flag = true; unset($raw_args['help']); } // see http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=427 // https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=483 foreach (self::$formatting_defaults as $k => $v) { unset($raw_args[$k]); } $output = ''; $Q = new GetPostsQuery(); $args = array_merge($Q->defaults, $raw_args); if ($args['paginate']) { require_once dirname(__FILE__) . '/CCTM_Pagination.conf.php'; $C = new CCTM_Pagination_Configuration(); $tpls = $C->tpls['default']; $args['offset'] = (int) isset($_GET['offset']) ? $_GET['offset'] : ''; $Q->set_tpls($tpls); } $results = $Q->get_posts($args); // Print help message. Should include the SQL statement, errors if ($help_flag) { return $Q->debug(); // this prints the results } if (empty($results)) { return ''; } $output = $formatting_args['before']; foreach ($results as $r) { $output .= CCTM::parse($formatting_args['tpl_str'], $r); } $output .= $formatting_args['after']; if ($args['paginate']) { $output .= '<div class="summarize-posts-pagination-links">' . $Q->get_pagination_links() . '</div>'; } return $output; }
$filter_included = CCTM::load_file("/filters/{$filter}.php"); } } // Show an example of the Output Filter if ($filter_included && $filter != 'raw') { $OutputFilter = new $filter_class(); $is_repeatable = false; if (isset(self::$data['custom_field_defs'][$cf]['is_repeatable'])) { $is_repeatable = self::$data['custom_field_defs'][$cf]['is_repeatable']; } $custom_fields_str .= sprintf("\t\t<strong>%s:</strong> %s<br />\n", self::$data['custom_field_defs'][$cf]['label'], $OutputFilter->get_example(self::$data['custom_field_defs'][$cf]['name'], self::$data['custom_field_defs'][$cf]['type'], $is_repeatable)); } else { $custom_fields_str .= sprintf("\t\t<strong>%s</strong> <?php print_custom_field('%s'); ?><br />\n", self::$data['custom_field_defs'][$cf]['label'], self::$data['custom_field_defs'][$cf]['name']); } } } } // Reminder to the users if (empty($custom_fields_str)) { $custom_fields_str = '<!-- ' . __('You have not associated any custom fields with this post-type. Be sure to add any desired custom fields to this post-type by clicking on the "Manage Custom Fields" link under the Custom Content Type menu and checking the fields that you want.', CCTM_TXTDOMAIN) . ' -->'; } // Populate placeholders $hash['post_type'] = $post_type; $hash['built_in_fields'] = $builtin_fields_str; $hash['custom_fields'] = $custom_fields_str; $hash['comments'] = $comments_str; $data['single_page_sample_code'] = CCTM::parse($tpl, $hash, true); //die('d.x.x.'); // include CCTM_PATH.'/views/sample_template.php'; $data['content'] = CCTM::load_view('sample_template.php', $data); print CCTM::load_view('templates/default.php', $data);
/** * 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()); }
/** * Generate a form. This is the main event. * * @param array (optional) $search_by specify which parameters you want to search by * @param array (optional) $existing_values to populate the form e.g. from $_POST. * @return string HTML form. */ public function generate($search_by = array(), $existing_values = array()) { foreach ($existing_values as $k => $v) { $this->Q->{$k} = $v; // to __set() on GetPostsQuery } $this->values = $this->Q->args; // from GetPostsQuery static $instantiation_count = 0; // used to generate a unique CSS for every form on the page $instantiation_count++; $this->placeholders['form_number'] = $instantiation_count; // Default CSS stuff if (!isset($this->placeholders['css'])) { $dir = dirname(dirname(__FILE__)); $this->set_css($dir . '/css/searchform.css'); } // Defaults if (!empty($search_by)) { // override $this->search_by = $search_by; } // Override to our EVERYTHING search. if ($search_by === true) { $this->search_by = $this->search_by_everything; } $output = ''; $this->placeholders['content'] = ''; // Each part of the form is generated by component functions that correspond // exactly to the $search_by arguments. foreach ($this->search_by as $p) { $function_name = '_' . $p; if (method_exists($this, $function_name)) { $this->placeholders[$p] = $this->{$function_name}(); // Keep the main 'content' bit populated: the content is the sum total of all generated elements. $this->placeholders['content'] .= $this->placeholders[$p]; } else { $this->placeholders[$p] = $this->__call($p, array()); // Keep the main 'content' bit populated. $this->placeholders['content'] .= $this->placeholders[$p]; $this->errors['invalid_searchby_parameter'] = sprintf(__('Possible invalid search_by parameter:'), "<em>{$p}</em>"); } } // Get help // $all_placeholders = array_keys($this->placeholders); $all_placeholders = array(); foreach ($this->placeholders as $key => $tmp) { $all_placeholders[$key] = "[+{$key}+]"; } $this->placeholders['nonce'] = $this->get_nonce_field(); // this won't show via [+help+] $this->placeholders['help'] = implode(', ', $all_placeholders); // Two passes. $this->form_tpl = CCTM::parse($this->form_tpl, $this->placeholders, true); $out = CCTM::parse($this->form_tpl, $this->placeholders); $this->stop_time = microtime(true); return $out; }
/** * Given an array of post_ids, look up all the metadata for those posts. This needs * to come back keyed off of post_id so we can merge it later. * * @param array $post_ids array of integer post ids * @return array associative array of associative arrays, keyed off post_id global $wpdb; if (empty($post_ids)) { return array(array()); } $id_str = implode(',',$post_ids); $query = "SELECT * FROM {$wpdb->postmeta} WHERE post_id IN($id_str)"; $results = $wpdb->get_results( $query, ARRAY_A ); $output = array(); foreach ($results as $r) { $output[ $r['post_id'] ][ $r['meta_key'] ] = $r['meta_value']; } return $output; */ public function _get_sql3($post_ids) { global $wpdb; $hash = array(); $hash['where'] = '1'; $id_str = implode(',', $post_ids); if (!empty($post_ids)) { $hash['where'] = "{$wpdb->postmeta}.post_id IN({$id_str})"; } $query = "SELECT {$wpdb->postmeta}.*\n\t\t\tFROM {$wpdb->postmeta}\n\t\t\t\t\t\t\n\t\t\tWHERE [+where+]\n\t\t\t[+hiddenfields+]\n\t\t\t"; if (!$this->include_hidden_fields) { $hash['hidden_fields'] = "AND {$wpdb->postmeta}.meta_key NOT LIKE '\\_%'"; } $this->SQL3 = CCTM::parse($query, $hash); return $this->SQL3; }