/** * 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; }
/** * 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; }
// <-- read custom search parameters, if defined. if (isset($def['search_parameters'])) { $search_parameters_str = $def['search_parameters']; } $additional_defaults = array(); parse_str($search_parameters_str, $additional_defaults); foreach ($additional_defaults as $k => $v) { if (!empty($v)) { CCTM::$post_selector[$k] = $v; } } //print '<pre>'.print_r(CCTM::$post_selector,true).'</pre>'; exit; //------------------------------------------------------------------------------ // Begin! //------------------------------------------------------------------------------ $Q = new GetPostsQuery(); foreach (CCTM::$post_selector as $k => $v) { if (!isset($args[$k]) || empty($args[$k])) { $args[$k] = $v; } } $args['offset'] = 0; // assume 0, unless we got a page number // Calculate offset based on page number if (is_numeric($d['page_number']) && $d['page_number'] > 1) { $args['offset'] = ($d['page_number'] - 1) * CCTM::$post_selector['limit']; } //print '<pre>'.print_r($args,true).'</pre>'; exit; // Set pagination tpls $tpls = array('firstTpl' => '<span class="linklike" onclick="javascript:change_page(1);">« First</span> ', 'lastTpl' => ' <span class="linklike" onclick="javascript:change_page([+page_number+]);" >Last »</span>', 'prevTpl' => '<span class="linklike" onclick="javascript:change_page([+page_number+]);">‹ Prev.</span> ', 'nextTpl' => ' <span class="linklike" onclick="javascript:change_page([+page_number+]);">Next ›</span>', 'currentPageTpl' => ' <span class="post_selector_pagination_active_page">[+page_number+]</span> ', 'pageTpl' => ' <span class="linklike" title="[+page_number+]" onclick="javascript:change_page([+page_number+]);">[+page_number+]</span> ', 'outerTpl' => '<div id="pagination">[+content+] Page [+current_page+] of [+page_count+]<br/>
/** * 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; }
?> <img src="<?php echo esc_url(get_template_directory_uri()); ?> /images/bcg_slide-5.jpg"> <?php } } ?> </div><!-- #preload --> <main id="para-template"> <div id="skrollr-body"> <?php $Q = new GetPostsQuery(); $args = array(); $args['post_type'] = 'frontpage'; $args['orderby'] = 'priority'; $args['order'] = 'ASC'; $results = $Q->get_posts($args); $titlepage = true; // get_custom_field('my_field'); foreach ($results as $r) { $slide_bg = wp_get_attachment_image_src($r['backgroundimage'], 'full')[0]; ?> <section id="slide-<?php print $r['priority']; ?> " class="slide" <?php if ($titlepage == false) {
function test_get_posts_operators7() { $Q = new GetPostsQuery(); $args = array(); $args['post_type'] = 'movie'; $args['rating']['like'] = array('PG', 'R'); $results = $Q->get_posts($args); $this->assertTrue(count($results) == 4); }
/** * * * @param mixed $current_value current value for this field (an integer ID). * @return string */ public function get_edit_field_instance($current_value) { require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $Q = new GetPostsQuery(); // Populate the values (i.e. properties) of this field $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $this->content = ''; if (empty($this->button_label)) { $this->button_label = __('Choose Relation', CCTM_TXTDOMAIN); } $this->post_id = $this->value; $fieldtpl = ''; $wrappertpl = ''; // Multi field? if ($this->is_repeatable) { $this->remove_label = __('Remove All'); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_relation_multi.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_relation_multi.tpl')); $values = $this->get_value($current_value, 'to_array'); foreach ($values as $v) { $hash = $this->get_props(); $hash['post_id'] = (int) $v; $hash['thumbnail_url'] = CCTM::get_thumbnail($hash['post_id']); // Look up all the data on that foreign key // We gotta watch out: what if the related post has custom fields like "description" or // anything that would conflict with the definition? $post = $Q->get_post($hash['post_id']); if (empty($post)) { $this->content .= '<div class="cctm_error"><p>' . sprintf(__('Post %s not found.', CCTM_TXTDOMAIN), $v) . '</p></div>'; } else { foreach ($post as $k => $v) { // Don't override the def's attributes! if (!isset($hash[$k])) { $hash[$k] = $v; } } $this->content .= CCTM::parse($fieldtpl, $hash); } } } else { $this->remove_label = __('Remove'); $this->post_id = $this->get_value($current_value, 'to_string'); $this->thumbnail_url = CCTM::get_thumbnail($this->post_id); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_relation.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_relation.tpl')); if ($this->post_id) { // Look up all the data on that foriegn key // We gotta watch out: what if the related post has custom fields like "description" or // anything that would conflict with the definition? $post = $Q->get_post($this->post_id); if (empty($post)) { $this->content = '<div class="cctm_error"><p>' . sprintf(__('Post %s not found.', CCTM_TXTDOMAIN), $this->post_id) . '</p></div>'; } else { foreach ($post as $k => $v) { // Don't override the def's attributes! if (!isset($this->{$k})) { $this->{$k} = $v; } } $this->content = CCTM::parse($fieldtpl, $this->get_props()); } } } if (empty($this->button_label)) { $this->button_label = __('Choose Relation', 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; }
/** * 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; }
<?php /*------------------------------------------------------------------------------ This controller takes serialized arguments meant for the GetPostsQuery class and formats them to be easily readible. This helps users know what search criteria they have defined for a widget or other search parameter. ------------------------------------------------------------------------------*/ if (!defined('CCTM_PATH')) { exit('No direct script access allowed'); } require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $search_parameters_str = ''; if (isset($_POST['search_parameters'])) { $search_parameters_str = $_POST['search_parameters']; } $args = array(); parse_str($search_parameters_str, $args); $Q = new GetPostsQuery($args); print $Q->get_args(); /*EOF*/
/** * * * @param mixed $current_value current value for this field (an integer ID). * @return string */ public function get_edit_field_instance($current_value) { require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $Q = new GetPostsQuery(); // Populate the values (i.e. properties) of this field $this->id = str_replace(array('[', ']', ' '), '_', $this->name); $this->content = ''; if (empty($this->button_label)) { $this->button_label = __('Choose Relation', CCTM_TXTDOMAIN); } $this->post_id = $this->value; $fieldtpl = ''; $wrappertpl = ''; $relationmeta_tpl = CCTM::load_tpl(array('fields/options/' . $this->name . '.tpl', 'fields/options/_relationmeta.tpl')); // Multi field? if ($this->is_repeatable) { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_relationmeta_multi.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_relationmeta_multi.tpl', 'fields/wrappers/_relation_multi.tpl')); } else { $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_relationmeta.tpl')); $wrappertpl = CCTM::load_tpl(array('fields/wrappers/' . $this->name . '.tpl', 'fields/wrappers/_relation.tpl')); } $data = $this->get_value($current_value, 'ignored'); if ($data) { foreach ($data as $post_id => $metafields) { // Look up all the data on those foriegn keys // We gotta watch out: what if the related post has custom fields like "description" or // anything that would conflict with the definition? // I'm using $post as my hash for $fieldtpl... I think $wrappertpl is what I need to watch out for. $post = $Q->get_post($post_id); $post['thumbnail_url'] = CCTM::get_thumbnail($post_id); if (empty($post)) { $this->content = '<div class="cctm_error"><p>' . sprintf(__('Post %s not found.', CCTM_TXTDOMAIN), $post_id) . '</p></div>'; } else { // Warning: $metafields that is set on this post may not containt fields // that were newly added to the def, so we flesh it out from the $this->metafields def. $content = ''; if (is_array($this->metafields)) { foreach ($this->metafields as $mf) { if (!isset($metafields[$mf])) { $metafields[$mf] = ''; } } } // Look up data for each of the metafields foreach ($metafields as $mf => $v) { if (!isset(CCTM::$data['custom_field_defs'][$mf])) { continue; } $d = CCTM::$data['custom_field_defs'][$mf]; if (!($FieldObj = CCTM::load_object($d['type'], 'fields'))) { continue; } $d['name'] = $this->name . '[' . $post_id . '][' . $d['name'] . ']'; $d['value'] = $v; $d['is_repeatable'] = false; // override $FieldObj->set_props($d); $output_this_field = $FieldObj->get_edit_field_instance($v); $content .= CCTM::parse($relationmeta_tpl, array('content' => $output_this_field)); } $post['metafields'] = $content; $this->content .= CCTM::parse($fieldtpl, $post); } } // endforeach } // end $data if (empty($this->button_label)) { $this->button_label = __('Choose Relation', 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 unknown $def * @return string HTML input fields */ public function get_edit_field_definition($def) { // Used to fetch the default value. require_once CCTM_PATH . '/includes/GetPostsQuery.php'; // Standard $out = $this->format_standard_fields($def); // Options $Q = new GetPostsQuery(); $out .= ' <div class="postbox"> <div class="handlediv" title="Click to toggle"><br /></div> <h3 class="hndle"><span>' . __('Options', CCTM_TXTDOMAIN) . '</span></h3> <div class="inside">'; // Note fieldtype: used to set the default value on new fields $out .= '<input type="hidden" id="fieldtype" value="image" />'; // Initialize / defaults $preview_html = ''; $click_label = __('Choose Image'); $label = __('Default Value', CCTM_TXTDOMAIN); $remove_label = __('Remove'); // Handle the display of the default value if (!empty($def['default_value'])) { $hash = CCTM::get_thumbnail($def['default_value']); $fieldtpl = CCTM::load_tpl(array('fields/elements/' . $this->name . '.tpl', 'fields/elements/_media.tpl', 'fields/elements/_relation.tpl')); $preview_html = CCTM::parse($fieldtpl, $hash); } // Button Label $out .= '<div class="' . self::wrapper_css_class . '" id="button_label_wrapper"> <label for="button_label" class="' . self::label_css_class . '">' . __('Button Label', CCTM_TXTDOMAIN) . '</label> <input type="text" name="button_label" class="' . self::css_class_prefix . 'text" id="button_label" value="' . htmlspecialchars($def['button_label']) . '"/> ' . $this->get_translation('button_label') . ' </div>'; // Set Search Parameters $search_parameters_str = CCTM::get_value($def, 'search_parameters'); parse_str($search_parameters_str, $args); $Q = new GetPostsQuery($args); $search_parameters_visible = $Q->get_args(); $out .= ' <div class="cctm_element_wrapper" id="search_parameters_wrapper"> <label for="name" class="cctm_label cctm_text_label" id="search_parameters_label">' . __('Search Parameters', CCTM_TXTDOMAIN) . '</label> <span class="cctm_description">' . __('Define which posts are available for selection by narrowing your search parameters.', CCTM_TXTDOMAIN) . '</span> <br/> <span class="button" onclick="javascript:search_form_display(\'' . $def['name'] . '\',\'' . $def['type'] . '\');">' . __('Set Search Parameters', CCTM_TXTDOMAIN) . '</span> <div id="cctm_thickbox"></div> <span id="search_parameters_visible">' . $search_parameters_visible . '</span> <input type="hidden" id="search_parameters" name="search_parameters" value="' . CCTM::get_value($def, 'search_parameters') . '" /> <br/> </div>'; $out .= '</div><!-- /inside --> </div><!-- /postbox -->'; // Validations / Required $out .= $this->format_validators($def, false); // Output Filter $out .= $this->format_available_output_filters($def); return $out; }
<?php //------------------------------------------------------------------------------ /** * Gets the shortcode for the TinyMCE editor. When the summarize_posts_form.php * form is posted, it does an AJAX submit to this controller, with the form * data serialized inside of $_POST['search_parameters'] * it arrives something like this: * post_type%5B%5D=attachment&taxonomy=&taxonomy_term=&post_parent=&meta_key=model&meta_value=Ford * */ require_once CCTM_PATH . '/includes/SummarizePosts.php'; require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $args = array(); // initialize parse_str($_POST['search_parameters'], $args); //print '<pre>'.print_r($args,true) . '</pre>'; $Q = new GetPostsQuery($args); //print $Q->debug(); print $Q->get_shortcode(); /*EOF*/
/** * We use this to print out the large icon at the top of the page when editing a post/page * and to enforce field validation (including required fields). * http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=188 * https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=544 */ public static function print_admin_header() { $file = substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1); if (!in_array($file, array('post.php', 'post-new.php', 'edit.php'))) { return; } $post_type = CCTM::get_value($_GET, 'post_type'); if (empty($post_type)) { $post_id = (int) CCTM::get_value($_GET, 'post'); if (empty($post_id)) { return; } $post = get_post($post_id); $post_type = $post->post_type; } // Only do this stuff for active post-types (is_active can be 1 for built-in or 2 for foreign) if (!isset(CCTM::$data['post_type_defs'][$post_type]['is_active']) || !CCTM::$data['post_type_defs'][$post_type]['is_active']) { return; } // Show the big icon: http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=136 if (isset(CCTM::$data['post_type_defs'][$post_type]['use_default_menu_icon']) && CCTM::$data['post_type_defs'][$post_type]['use_default_menu_icon'] == 0) { $baseimg = basename(CCTM::$data['post_type_defs'][$post_type]['menu_icon']); // die($baseimg); if (file_exists(CCTM_PATH . '/images/icons/32x32/' . $baseimg)) { printf(' <style> #icon-edit, #icon-post { background-image:url(%s); background-position: 0px 0px; } </style>', CCTM_URL . '/images/icons/32x32/' . $baseimg); } } // Validate the custom fields when a page is first printed (e.g. the validation rule was // created or updated, then the post is edited) $file = substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1); if (in_array($file, array('post.php'))) { global $post; $Q = new GetPostsQuery(); $full_post = $Q->get_post($post->ID); if (!self::validate_fields($post_type, $full_post)) { // Print any validation errors. $output = '<div class="error"><img src="' . CCTM_URL . '/images/warning-icon.png" width="50" height="44" style="float:left; padding:10px; vertical-align:middle;"/><p style=""><strong>' . __('This post has validation errors. The post will remain in draft status until they are corrected.', CCTM_TXTDOMAIN) . '</strong></p> <ul style="clear:both;">'; foreach (CCTM::$post_validation_errors as $fieldname => $e) { $output .= '<li>' . $e . '</li>'; } $output .= '</ul></div>'; // You have to print the style because WP overrides styles after the cctm manager.css is included. // This isn't helpful during the admin head event because you'd have to also check validation at the time when // the fields are printed in print_custom_fields(), which fires later on. // We can use this variable to pass data to a point later in the page request. // global $cctm_validation; // CCTM::$errors // CCTM::$errors['my_field'] = 'This is the validation error with that field'; $output .= '<style>'; $output .= file_get_contents(CCTM_PATH . '/css/validation.css'); $output .= '</style>'; print $output; // Override!! set post to draft status if there were validation errors. // See https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=544 global $wpdb; $post_id = (int) CCTM::get_value($_GET, 'post'); $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $post_id), array('%s'), array('%d')); } } }
/** * 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!"); }
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*/
/** * Get a visible listing of what the search parameters are for a relation field * @param string $search_parameters_str URL encoded * @return string */ protected function _get_search_parameters_visible($search_parameters_str) { require_once CCTM_PATH . '/includes/GetPostsQuery.php'; $Q = new GetPostsQuery(); parse_str($search_parameters_str, $args); $Q = new GetPostsQuery($args); return $Q->get_args(); }