| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Custom Field Template |
| 4 |
Plugin URI: https://www.wpcft.com/ |
| 5 |
Description: This plugin adds the default custom fields on the Write Post/Page. |
| 6 |
Author: Hiroaki Miyashita |
| 7 |
Author URI: https://wpgogo.com/ |
| 8 |
Version: 2.8.1 |
| 9 |
Text Domain: custom-field-template |
| 10 |
Domain Path: / |
| 11 |
*/ |
| 12 |
|
| 13 |
/* |
| 14 |
This program is based on the rc:custom_field_gui plugin written by Joshua Sigar. |
| 15 |
I appreciate your efforts, Joshua. |
| 16 |
*/ |
| 17 |
|
| 18 |
/* Copyright 2008 - 2026 Hiroaki Miyashita |
| 19 |
|
| 20 |
This program is free software; you can redistribute it and/or modify |
| 21 |
it under the terms of the GNU General Public License as published by |
| 22 |
the Free Software Foundation; either version 2 of the License, or |
| 23 |
(at your option) any later version. |
| 24 |
|
| 25 |
This program is distributed in the hope that it will be useful, |
| 26 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
GNU General Public License for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU General Public License |
| 31 |
along with this program; if not, write to the Free Software |
| 32 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 33 |
*/ |
| 34 |
|
| 35 |
class custom_field_template { |
| 36 |
var $is_excerpt, $format_post_id; |
| 37 |
private $replace_val; |
| 38 |
|
| 39 |
function __construct() { |
| 40 |
register_activation_hook( __FILE__, array(&$this, 'custom_field_template_register_activation_hook') ); |
| 41 |
add_action( 'plugins_loaded', array(&$this, 'custom_field_template_plugins_loaded') ); |
| 42 |
add_action( 'init', array(&$this, 'custom_field_template_init'), 100 ); |
| 43 |
add_action( 'admin_init', array(&$this, 'custom_field_template_admin_init') ); |
| 44 |
add_action( 'admin_menu', array(&$this, 'custom_field_template_admin_menu') ); |
| 45 |
add_action( 'admin_print_scripts', array(&$this, 'custom_field_template_admin_scripts') ); |
| 46 |
add_action( 'admin_head', array(&$this, 'custom_field_template_admin_head'), 100 ); |
| 47 |
add_action( 'admin_notices', array( &$this, 'custom_field_template_admin_notices' ) ); |
| 48 |
add_action( 'wp_ajax_dismiss_admin_notices', array(&$this, 'custom_field_template_dismiss_admin_notices') ); |
| 49 |
add_action( 'add_meta_boxes', array(&$this, 'custom_field_template_add_meta_boxes') ); |
| 50 |
add_action( 'edit_form_advanced', array(&$this, 'custom_field_template_edit_form_advanced') ); |
| 51 |
add_action( 'edit_page_form', array(&$this, 'custom_field_template_edit_form_advanced') ); |
| 52 |
add_action( 'block_editor_meta_box_hidden_fields', array( &$this, 'custom_field_template_edit_form_advanced' ) ); |
| 53 |
|
| 54 |
//add_action( 'edit_post', array(&$this, 'edit_meta_value'), 100 ); |
| 55 |
add_action( 'save_post', array(&$this, 'edit_meta_value'), 100, 2 ); |
| 56 |
//add_action( 'publish_post', array(&$this, 'edit_meta_value'), 100 ); |
| 57 |
|
| 58 |
add_action( 'delete_post', array(&$this, 'custom_field_template_delete_post'), 100 ); |
| 59 |
|
| 60 |
add_filter( 'media_send_to_editor', array(&$this, 'media_send_to_custom_field'), 15 ); |
| 61 |
add_filter( 'plugin_action_links', array(&$this, 'wpaq_filter_plugin_actions'), 100, 2 ); |
| 62 |
|
| 63 |
add_filter( 'get_the_excerpt', array(&$this, 'custom_field_template_get_the_excerpt'), 1 ); |
| 64 |
add_filter( 'the_content', array(&$this, 'custom_field_template_the_content') ); |
| 65 |
add_filter( 'the_content_rss', array(&$this, 'custom_field_template_the_content') ); |
| 66 |
|
| 67 |
add_filter( 'attachment_fields_to_edit', array(&$this, 'custom_field_template_attachment_fields_to_edit'), 10, 2 ); |
| 68 |
add_filter( '_wp_post_revision_fields', array(&$this, 'custom_field_template_wp_post_revision_fields'), 1 ); |
| 69 |
add_filter( 'edit_form_after_title', array(&$this, 'custom_field_template_edit_form_after_title') ); |
| 70 |
|
| 71 |
if ( isset($_REQUEST['cftsearch_submit']) ) : |
| 72 |
add_action( 'post_limits', array(&$this, 'custom_field_template_post_limits'), 100); |
| 73 |
add_filter( 'posts_join', array(&$this, 'custom_field_template_posts_join'), 100 ); |
| 74 |
add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where'), 100 ); |
| 75 |
add_filter( 'posts_orderby', array(&$this, 'custom_field_template_posts_orderby'), 100 ); |
| 76 |
endif; |
| 77 |
|
| 78 |
if ( function_exists('add_shortcode') ) : |
| 79 |
add_shortcode( 'cft', array(&$this, 'output_custom_field_values') ); |
| 80 |
add_shortcode( 'cftsearch', array(&$this, 'search_custom_field_values') ); |
| 81 |
endif; |
| 82 |
|
| 83 |
add_filter( 'get_post_metadata', array(&$this, 'get_preview_postmeta'), 10, 4 ); |
| 84 |
add_filter( 'wp_list_table_class_name', array(&$this, 'custom_field_template_wp_list_table_class_name'), 10, 2 ); |
| 85 |
add_action( 'custom_field_template_premium_code_update', array(&$this, 'custom_field_template_premium_code_update') ); |
| 86 |
} |
| 87 |
|
| 88 |
function custom_field_template_register_activation_hook() { |
| 89 |
delete_option( 'cft_admin_notices' ); |
| 90 |
} |
| 91 |
|
| 92 |
function custom_field_template_plugins_loaded() { |
| 93 |
load_plugin_textdomain('custom-field-template', false, plugin_basename( dirname( __FILE__ ) ) ); |
| 94 |
} |
| 95 |
|
| 96 |
function custom_field_template_init() { |
| 97 |
global $wp_version; |
| 98 |
$options = $this->get_custom_field_template_data(); |
| 99 |
|
| 100 |
$cft_mode = isset( $_REQUEST['cft_mode'] ) && is_scalar( $_REQUEST['cft_mode'] ) ? sanitize_key( wp_unslash( $_REQUEST['cft_mode'] ) ) : ''; |
| 101 |
$cft_page = isset( $_REQUEST['page'] ) && is_scalar( $_REQUEST['page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) : ''; |
| 102 |
$request_post_id = isset( $_REQUEST['post'] ) && is_scalar( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : 0; |
| 103 |
|
| 104 |
if ( is_user_logged_in() && current_user_can('edit_posts') && $request_post_id && $cft_page == 'custom-field-template/custom-field-template.php' && $cft_mode == 'selectbox' ) { |
| 105 |
echo $this->custom_field_template_selectbox(); |
| 106 |
exit(); |
| 107 |
} |
| 108 |
|
| 109 |
if ( is_user_logged_in() && $request_post_id && $cft_page == 'custom-field-template/custom-field-template.php' && $cft_mode == 'ajaxsave' ) { |
| 110 |
if ( $request_post_id > 0 && current_user_can( 'edit_post', $request_post_id ) ) |
| 111 |
$this->edit_meta_value( $request_post_id, '' ); |
| 112 |
exit(); |
| 113 |
} |
| 114 |
|
| 115 |
if ( is_user_logged_in() && current_user_can('edit_posts') && $cft_page == 'custom-field-template/custom-field-template.php' && $cft_mode == 'ajaxload') { |
| 116 |
if ( $request_post_id && ! current_user_can( 'edit_post', $request_post_id ) ) { |
| 117 |
exit(); |
| 118 |
} |
| 119 |
if ( isset($_REQUEST['id']) ) : |
| 120 |
$id = is_scalar( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0; |
| 121 |
elseif ( $request_post_id && isset($options['posts'][$request_post_id]) ) : |
| 122 |
$id = absint( $options['posts'][$request_post_id] ); |
| 123 |
else : |
| 124 |
$filtered_cfts = $this->custom_field_template_filter(); |
| 125 |
if ( count($filtered_cfts)>0 ) : |
| 126 |
$id = absint( $filtered_cfts[0]['id'] ); |
| 127 |
else : |
| 128 |
$id = 0; |
| 129 |
endif; |
| 130 |
endif; |
| 131 |
list($body, $init_id) = $this->load_custom_field( $id ); |
| 132 |
echo $body; |
| 133 |
exit(); |
| 134 |
} |
| 135 |
|
| 136 |
if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/plugins.php') && ((isset($_GET['activate']) && $_GET['activate'] == 'true') || (isset($_GET['activate-multi']) && $_GET['activate-multi'] == 'true') ) ) { |
| 137 |
$options = $this->get_custom_field_template_data(); |
| 138 |
if( !$options ) { |
| 139 |
$this->install_custom_field_template_data(); |
| 140 |
$this->install_custom_field_template_css(); |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
if ( function_exists('current_user_can') && current_user_can('edit_plugins') ) : |
| 145 |
if ( isset($_POST['custom_field_template_export_options_submit']) ) : |
| 146 |
check_admin_referer( 'cft', '_wpnonce' ); |
| 147 |
$filename = "cft".date('Ymd'); |
| 148 |
header("Accept-Ranges: none"); |
| 149 |
header("Content-Disposition: attachment; filename=$filename"); |
| 150 |
header('Content-Type: application/octet-stream'); |
| 151 |
echo maybe_serialize($options); |
| 152 |
exit(); |
| 153 |
endif; |
| 154 |
endif; |
| 155 |
|
| 156 |
if ( !empty($options['custom_field_template_widget_shortcode']) ) |
| 157 |
add_filter('widget_text', 'do_shortcode'); |
| 158 |
|
| 159 |
if ( substr($wp_version, 0, 3) >= '2.7' ) { |
| 160 |
if ( empty($options['custom_field_template_disable_custom_field_column']) ) : |
| 161 |
add_action( 'manage_posts_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 ); |
| 162 |
add_filter( 'manage_posts_columns', array(&$this, 'add_manage_posts_columns') ); |
| 163 |
add_action( 'manage_pages_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 ); |
| 164 |
add_filter( 'manage_pages_columns', array(&$this, 'add_manage_pages_columns') ); |
| 165 |
endif; |
| 166 |
if ( empty($options['custom_field_template_disable_quick_edit']) ) |
| 167 |
add_action( 'quick_edit_custom_box', array(&$this, 'add_quick_edit_custom_box'), 10, 2 ); |
| 168 |
} |
| 169 |
|
| 170 |
if ( substr($wp_version, 0, 3) < '2.5' ) { |
| 171 |
add_action( 'simple_edit_form', array(&$this, 'insert_custom_field'), 1 ); |
| 172 |
add_action( 'edit_form_advanced', array(&$this, 'insert_custom_field'), 1 ); |
| 173 |
add_action( 'edit_page_form', array(&$this, 'insert_custom_field'), 1 ); |
| 174 |
} |
| 175 |
|
| 176 |
if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') ) : |
| 177 |
add_action('admin_head', array(&$this, 'custom_field_template_admin_head_buffer') ); |
| 178 |
add_action('admin_footer', array(&$this, 'custom_field_template_admin_footer_buffer') ); |
| 179 |
endif; |
| 180 |
} |
| 181 |
|
| 182 |
function custom_field_template_admin_init() { |
| 183 |
add_thickbox(); |
| 184 |
|
| 185 |
if ( ! wp_next_scheduled( 'custom_field_template_premium_code_update' ) ) : |
| 186 |
wp_schedule_event( time(), 'daily', 'custom_field_template_premium_code_update' ); |
| 187 |
endif; |
| 188 |
} |
| 189 |
|
| 190 |
function custom_field_template_premium_code_update() { |
| 191 |
$options = $this->get_custom_field_template_data(); |
| 192 |
$authentication_key = $options['custom_field_template_premium_code']; |
| 193 |
|
| 194 |
if ( ! empty( $authentication_key ) ) : |
| 195 |
$check_value = $this->custom_field_template_check_authentication_key( $authentication_key ); |
| 196 |
if ( $check_value == false ) : |
| 197 |
$options['custom_field_template_premium_code'] = ''; |
| 198 |
update_option( 'custom_field_template_data', $options ); |
| 199 |
endif; |
| 200 |
endif; |
| 201 |
} |
| 202 |
|
| 203 |
function custom_field_template_add_meta_boxes() { |
| 204 |
$options = $this->get_custom_field_template_data(); |
| 205 |
|
| 206 |
if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) : |
| 207 |
remove_meta_box('postcustom', 'post', 'normal'); |
| 208 |
remove_meta_box('postcustom', 'page', 'normal'); |
| 209 |
remove_meta_box('pagecustomdiv', 'page', 'normal'); |
| 210 |
endif; |
| 211 |
|
| 212 |
if ( !empty($options['custom_field_template_deploy_box']) ) : |
| 213 |
if ( !empty($options['custom_fields']) ) : |
| 214 |
$i = 0; |
| 215 |
foreach ( $options['custom_fields'] as $key => $val ) : |
| 216 |
if ( empty($options['custom_field_template_replace_the_title']) ) $title = __('Custom Field Template', 'custom-field-template'); |
| 217 |
else $title = $options['custom_fields'][$key]['title']; |
| 218 |
if ( empty($options['custom_fields'][$key]['custom_post_type']) ) : |
| 219 |
if ( empty($options['custom_fields'][$key]['post_type']) ) : |
| 220 |
add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', array('cft_id' => $key)); |
| 221 |
add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', array('cft_id' => $key)); |
| 222 |
elseif ( $options['custom_fields'][$key]['post_type']=='post' ) : |
| 223 |
add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', array('cft_id' => $key)); |
| 224 |
elseif ( $options['custom_fields'][$key]['post_type']=='page' ) : |
| 225 |
add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', array('cft_id' => $key)); |
| 226 |
endif; |
| 227 |
else : |
| 228 |
$tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']); |
| 229 |
$tmp_custom_post_type = array_filter( $tmp_custom_post_type ); |
| 230 |
$tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type))); |
| 231 |
foreach ( $tmp_custom_post_type as $type ) : |
| 232 |
add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), $type, 'normal', 'core', array('cft_id' => $key)); |
| 233 |
endforeach; |
| 234 |
endif; |
| 235 |
$i++; |
| 236 |
endforeach; |
| 237 |
endif; |
| 238 |
else : |
| 239 |
add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'post', 'normal', 'core'); |
| 240 |
add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'page', 'normal', 'core'); |
| 241 |
endif; |
| 242 |
|
| 243 |
if ( empty($options['custom_field_template_deploy_box']) && is_array($options['custom_fields']) ) : |
| 244 |
$custom_post_type = array(); |
| 245 |
foreach($options['custom_fields'] as $key => $val ) : |
| 246 |
if ( isset($options['custom_fields'][$key]['custom_post_type']) ) : |
| 247 |
$tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']); |
| 248 |
$tmp_custom_post_type = array_filter( $tmp_custom_post_type ); |
| 249 |
$tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type))); |
| 250 |
$custom_post_type = array_merge($custom_post_type, $tmp_custom_post_type); |
| 251 |
endif; |
| 252 |
endforeach; |
| 253 |
if ( isset($custom_post_type) && is_array($custom_post_type) ) : |
| 254 |
foreach( $custom_post_type as $val ) : |
| 255 |
if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) : |
| 256 |
remove_meta_box('postcustom', $val, 'normal'); |
| 257 |
endif; |
| 258 |
add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), $val, 'normal', 'core'); |
| 259 |
if ( empty($options['custom_field_template_disable_custom_field_column']) ) : |
| 260 |
add_filter( 'manage_'.$val.'_posts_columns', array(&$this, 'add_manage_pages_columns') ); |
| 261 |
endif; |
| 262 |
endforeach; |
| 263 |
endif; |
| 264 |
endif; |
| 265 |
} |
| 266 |
|
| 267 |
function custom_field_template_attachment_fields_to_edit($form_fields, $post) { |
| 268 |
$form_fields["custom_field_template"]["label"] = __('Media Picker', 'custom-field-template'); |
| 269 |
$form_fields["custom_field_template"]["input"] = "html"; |
| 270 |
$form_fields["custom_field_template"]["html"] = '<a href="javascript:void(0);" onclick="var win = window.dialogArguments || opener || parent || top;win.cft_use_this('.$post->ID.');return false;">'.__('Use this', 'custom-field-template').'</a>'; |
| 271 |
|
| 272 |
return $form_fields; |
| 273 |
} |
| 274 |
|
| 275 |
function custom_field_template_add_enctype($buffer) { |
| 276 |
$buffer = preg_replace('/<form name="post"/', '<form enctype="multipart/form-data" name="post"', $buffer); |
| 277 |
return $buffer; |
| 278 |
} |
| 279 |
|
| 280 |
function custom_field_template_admin_head_buffer() { |
| 281 |
ob_start(array(&$this, 'custom_field_template_add_enctype')); |
| 282 |
} |
| 283 |
|
| 284 |
function custom_field_template_admin_footer_buffer() { |
| 285 |
ob_end_flush(); |
| 286 |
} |
| 287 |
|
| 288 |
function has_meta( $postid ) { |
| 289 |
global $wpdb; |
| 290 |
|
| 291 |
return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, post_id FROM $wpdb->postmeta WHERE post_id = %d ORDER BY meta_key,meta_id", $postid), ARRAY_A ); |
| 292 |
} |
| 293 |
|
| 294 |
function get_post_meta($post_id, $key = '', $single = false) { |
| 295 |
if ( !$post_id ) return ''; |
| 296 |
|
| 297 |
if ( $preview_id = $this->get_preview_id( $post_id ) ) $post_id = $preview_id; |
| 298 |
|
| 299 |
$post_id = (int) $post_id; |
| 300 |
|
| 301 |
$meta_cache = wp_cache_get($post_id, 'cft_post_meta'); |
| 302 |
|
| 303 |
if ( !$meta_cache ) { |
| 304 |
if ( $meta_list = $this->has_meta( $post_id ) ) { |
| 305 |
foreach ( (array) $meta_list as $metarow) { |
| 306 |
$mpid = (int) $metarow['post_id']; |
| 307 |
$mkey = $metarow['meta_key']; |
| 308 |
$mval = $metarow['meta_value']; |
| 309 |
|
| 310 |
if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) |
| 311 |
$cache[$mpid] = array(); |
| 312 |
if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) |
| 313 |
$cache[$mpid][$mkey] = array(); |
| 314 |
|
| 315 |
$cache[$mpid][$mkey][] = $mval; |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
/*foreach ( (array) $ids as $id ) { |
| 320 |
if ( ! isset($cache[$id]) ) |
| 321 |
$cache[$id] = array(); |
| 322 |
}*/ |
| 323 |
|
| 324 |
if ( !empty($cache) && is_array($cache) ) : |
| 325 |
foreach ( (array) array_keys($cache) as $post) |
| 326 |
wp_cache_set($post, $cache[$post], 'cft_post_meta'); |
| 327 |
|
| 328 |
$meta_cache = wp_cache_get($post_id, 'cft_post_meta'); |
| 329 |
endif; |
| 330 |
} |
| 331 |
|
| 332 |
if ( $key ) : |
| 333 |
if ( $single && isset($meta_cache[$key][0]) ) : |
| 334 |
return maybe_unserialize( $meta_cache[$key][0] ); |
| 335 |
else : |
| 336 |
if ( isset($meta_cache[$key]) ) : |
| 337 |
if ( is_array($meta_cache[$key]) ) : |
| 338 |
return array_map('maybe_unserialize', $meta_cache[$key]); |
| 339 |
else : |
| 340 |
return $meta_cache[$key]; |
| 341 |
endif; |
| 342 |
endif; |
| 343 |
endif; |
| 344 |
else : |
| 345 |
if ( is_array($meta_cache) ) : |
| 346 |
return array_map('maybe_unserialize', $meta_cache); |
| 347 |
endif; |
| 348 |
endif; |
| 349 |
|
| 350 |
return ''; |
| 351 |
} |
| 352 |
|
| 353 |
function add_quick_edit_custom_box($column_name, $type) { |
| 354 |
if( $column_name == 'custom-fields' ) : |
| 355 |
global $wp_version; |
| 356 |
$options = $this->get_custom_field_template_data(); |
| 357 |
|
| 358 |
if( $options == null) |
| 359 |
return; |
| 360 |
|
| 361 |
if ( !$options['css'] ) { |
| 362 |
$this->install_custom_field_template_css(); |
| 363 |
$options = $this->get_custom_field_template_data(); |
| 364 |
} |
| 365 |
|
| 366 |
$out = ''; |
| 367 |
$out .= '<fieldset style="clear:both;">' . "\n"; |
| 368 |
$out .= '<div class="inline-edit-group">'; |
| 369 |
$out .= '<style type="text/css">' . "\n" . |
| 370 |
'<!--' . "\n"; |
| 371 |
$out .= esc_html( $options['css'] ) . "\n"; |
| 372 |
$out .= '-->' . "\n" . |
| 373 |
'</style>'; |
| 374 |
|
| 375 |
if ( count($options['custom_fields'])>1 ) { |
| 376 |
$out .= '<select id="custom_field_template_select">'; |
| 377 |
for ( $i=0; $i < count($options['custom_fields']); $i++ ) { |
| 378 |
if ( isset($_REQUEST['post']) && isset($options['posts'][$_REQUEST['post']]) && $i == $options['posts'][$_REQUEST['post']] ) { |
| 379 |
$out .= '<option value="' . $i . '" selected="selected">' . esc_html(stripcslashes($options['custom_fields'][$i]['title'])) . '</option>'; |
| 380 |
} else |
| 381 |
$out .= '<option value="' . $i . '">' . esc_html(stripcslashes($options['custom_fields'][$i]['title'])) . '</option>'; |
| 382 |
} |
| 383 |
$out .= '</select>'; |
| 384 |
$out .= '<input type="button" class="button" value="' . __('Load', 'custom-field-template') . '" onclick="var post = jQuery(this).parent().parent().parent().parent().attr(\'id\').replace(\'edit-\',\'\'); var cftloading_select = function() {jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=\'+jQuery(\'#custom_field_template_select\').val()+\'&post=\'+post, success: function(html) {jQuery(\'#cft\').html(html);}});};cftloading_select(post);" />'; |
| 385 |
} |
| 386 |
|
| 387 |
$out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />'; |
| 388 |
$out .= '<div id="cft" class="cft">'; |
| 389 |
$out .= '</div>'; |
| 390 |
|
| 391 |
$out .= '</div>' . "\n"; |
| 392 |
$out .= '</fieldset>' . "\n"; |
| 393 |
|
| 394 |
echo $out; |
| 395 |
endif; |
| 396 |
} |
| 397 |
|
| 398 |
function custom_field_template_admin_head() { |
| 399 |
global $wp_version, $post; |
| 400 |
$options = $this->get_custom_field_template_data(); |
| 401 |
|
| 402 |
if ( !empty($options['custom_field_template_use_validation']) ) : |
| 403 |
if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || (is_object($post) && $post->post_type=='page') ) : |
| 404 |
?> |
| 405 |
<script type="text/javascript"> |
| 406 |
// <![CDATA[ |
| 407 |
jQuery(document).ready(function() { |
| 408 |
jQuery("#post").validate(); |
| 409 |
}); |
| 410 |
//--> |
| 411 |
</script> |
| 412 |
<style type="text/css"> |
| 413 |
<!-- |
| 414 |
label.error { color:#FF0000; } |
| 415 |
--> |
| 416 |
</style> |
| 417 |
|
| 418 |
<?php |
| 419 |
endif; |
| 420 |
endif; |
| 421 |
|
| 422 |
if ( substr($wp_version, 0, 3) >= '2.7' && is_user_logged_in() && ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) && !strstr($_SERVER['REQUEST_URI'], 'page=') ) { |
| 423 |
?> |
| 424 |
<script type="text/javascript"> |
| 425 |
// <![CDATA[ |
| 426 |
jQuery(document).ready(function() { |
| 427 |
jQuery('.hide-if-no-js-cft').show(); |
| 428 |
jQuery('.hide-if-js-cft').hide(); |
| 429 |
|
| 430 |
inlineEditPost.addEvents = function(r) { |
| 431 |
r.each(function() { |
| 432 |
var row = jQuery(this); |
| 433 |
jQuery('a.editinline', row).click(function() { |
| 434 |
inlineEditPost.edit(this); |
| 435 |
post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-',''); |
| 436 |
inlineEditPost.cft_load(post_id); |
| 437 |
return false; |
| 438 |
}); |
| 439 |
}); |
| 440 |
} |
| 441 |
|
| 442 |
inlineEditPost.save = function(id) { |
| 443 |
if( typeof(id) == 'object' ) |
| 444 |
id = this.getId(id); |
| 445 |
|
| 446 |
jQuery('table.widefat .inline-edit-save .waiting').show(); |
| 447 |
|
| 448 |
var params = { |
| 449 |
action: 'inline-save', |
| 450 |
post_type: <?php if ( substr($wp_version, 0, 3) >= '3.0' ) echo 'typenow'; else echo 'this.type'; ?>, |
| 451 |
post_ID: id, |
| 452 |
edit_date: 'true' |
| 453 |
}; |
| 454 |
|
| 455 |
var fields = jQuery('#edit-'+id+' :input').fieldSerialize(); |
| 456 |
params = fields + '&' + jQuery.param(params); |
| 457 |
|
| 458 |
// make ajax request |
| 459 |
jQuery.post('admin-ajax.php', params, |
| 460 |
function(r) { |
| 461 |
jQuery('table.widefat .inline-edit-save .waiting').hide(); |
| 462 |
|
| 463 |
if (r) { |
| 464 |
if ( -1 != r.indexOf('<tr') ) { |
| 465 |
jQuery(inlineEditPost.what+id).remove(); |
| 466 |
jQuery('#edit-'+id).before(r).remove(); |
| 467 |
|
| 468 |
var row = jQuery(inlineEditPost.what+id); |
| 469 |
row.hide(); |
| 470 |
|
| 471 |
if ( 'draft' == jQuery('input[name="post_status"]').val() ) |
| 472 |
row.find('td.column-comments').hide(); |
| 473 |
|
| 474 |
row.find('.hide-if-no-js').removeClass('hide-if-no-js'); |
| 475 |
jQuery('.hide-if-no-js-cft').show(); |
| 476 |
jQuery('.hide-if-js-cft').hide(); |
| 477 |
|
| 478 |
inlineEditPost.addEvents(row); |
| 479 |
row.fadeIn(); |
| 480 |
} else { |
| 481 |
r = r.replace( /<.[^<>]*?>/g, '' ); |
| 482 |
jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>'); |
| 483 |
} |
| 484 |
} else { |
| 485 |
jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>'); |
| 486 |
} |
| 487 |
} |
| 488 |
, 'html'); |
| 489 |
return false; |
| 490 |
} |
| 491 |
|
| 492 |
jQuery('.editinline').click(function () {post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-',''); inlineEditPost.cft_load(post_id);}); |
| 493 |
inlineEditPost.cft_load = function (post_id) { |
| 494 |
jQuery.ajax({type: 'GET', url: '?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&post='+post_id, success: function(html) {jQuery('#cft').html(html);}}); |
| 495 |
}; |
| 496 |
}); |
| 497 |
//--> |
| 498 |
</script> |
| 499 |
<style type="text/css"> |
| 500 |
<!-- |
| 501 |
div.cft_list p.key { font-weight:bold; margin: 0; } |
| 502 |
div.cft_list p.value { margin: 0 0 0 10px; } |
| 503 |
.cft-actions { visibility: hidden; padding: 2px 0 0; } |
| 504 |
tr:hover .cft-actions { visibility: visible; } |
| 505 |
.inline-edit-row fieldset label { display:inline; } |
| 506 |
label.error { color:#FF0000; } |
| 507 |
--> |
| 508 |
</style> |
| 509 |
<?php |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
function custom_field_template_admin_notices() { |
| 514 |
$options = $this->get_custom_field_template_data(); |
| 515 |
$cft_admin_notices = get_transient( 'cft_admin_notices' ); |
| 516 |
$locale = get_locale(); |
| 517 |
|
| 518 |
if ( empty( $cft_admin_notices ) && empty( $options['custom_field_template_disable_donation'] ) ) : |
| 519 |
?> |
| 520 |
<div class="notice notice-info is-dismissible" id="cft_admin_notices"> |
| 521 |
<?php |
| 522 |
if ( $locale == 'ja' ) : |
| 523 |
?> |
| 524 |
<p><a href="https://www.cmswp.jp/" target="_blank"><?php _e( 'Please use CMSxWP Subsc, which is a collection of WordPress plugins useful for various businesses such as EC, membership site, reservation site, event site, attendance management, and so on.', 'custom-field-template' ); ?></a></p> |
| 525 |
<p><a href="https://www.wpcft.com/" target="_blank"><?php _e( 'We have finally published a manual site for the custom field template plugin. You can also use the custom field refinement search for posts in the admin panel. Please check here.', 'custom-field-template' ); ?></a></p> |
| 526 |
<?php |
| 527 |
else : |
| 528 |
?> |
| 529 |
<p><a href="https://www.wpcft.com/" target="_blank"><?php _e( 'We have finally published a manual site for the custom field template plugin. You can also use the custom field refinement search for posts in the admin panel. Please check here.', 'custom-field-template' ); ?></a></p> |
| 530 |
<?php |
| 531 |
endif; |
| 532 |
?> |
| 533 |
<button type="button" class="notice-dismiss"></button> |
| 534 |
<script type="text/javascript"> |
| 535 |
// <![CDATA[ |
| 536 |
jQuery(document).ready(function() { |
| 537 |
jQuery('#cft_admin_notices button').click(function(){jQuery('#cft_admin_notices').hide();jQuery.getJSON('<?php echo site_url(); ?>/wp-admin/admin-ajax.php', { action:'dismiss_admin_notices', _wpnonce:'<?php echo wp_create_nonce( 'cft_admin_notices' ); ?>' }); }); |
| 538 |
}); |
| 539 |
//--> |
| 540 |
</script></div> |
| 541 |
<?php |
| 542 |
endif; |
| 543 |
} |
| 544 |
|
| 545 |
function custom_field_template_dismiss_admin_notices() { |
| 546 |
if ( !check_ajax_referer( 'cft_admin_notices' ) ) exit(); |
| 547 |
|
| 548 |
set_transient( 'cft_admin_notices', '1', 7 * DAY_IN_SECONDS ); |
| 549 |
//set_transient( 'cft_admin_notices', '1', 60 ); |
| 550 |
} |
| 551 |
|
| 552 |
function custom_field_template_edit_form_advanced() { |
| 553 |
global $wp_version; |
| 554 |
$options = $this->get_custom_field_template_data(); |
| 555 |
|
| 556 |
if ( !empty($options['custom_field_template_deploy_box']) ) : |
| 557 |
$suffix = '"+win.jQuery("#cft_current_template").val()+"'; |
| 558 |
else : |
| 559 |
$suffix = ''; |
| 560 |
endif; |
| 561 |
|
| 562 |
$out = ''; |
| 563 |
$out .= '<script type="text/javascript">' . "\n" . |
| 564 |
'// <![CDATA[' . "\n"; |
| 565 |
$out .= 'function cft_use_this(file_id) { |
| 566 |
var win = window.dialogArguments || opener || parent || top; |
| 567 |
win.jQuery("#"+win.jQuery("#cft_clicked_id").val()+"_hide").val(file_id); |
| 568 |
var fields = win.jQuery("#cft'.$suffix.' :input").fieldSerialize(); |
| 569 |
win.jQuery.ajax({type: "POST", url: "?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post="+win.jQuery(\'#post_ID\').val()+"&custom-field-template-verify-key="+win.jQuery("#custom-field-template-verify-key").val(), data: fields, success: function() {win.jQuery.ajax({type: "GET", url: "?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id="+win.jQuery("#cft_current_template").val()+"&post="+win.jQuery(\'#post_ID\').val(), success: function(html) {win.jQuery("#cft'.$suffix.'").html(html);win.tb_remove();}});}}); |
| 570 |
}'; |
| 571 |
|
| 572 |
$out .= 'function qt_set(new_id) { eval("qt_"+new_id+" = new QTags(\'qt_"+new_id+"\', \'"+new_id+"\', \'editorcontainer_"+new_id+"\', \'more\');");}'; |
| 573 |
|
| 574 |
$out .= 'function _edInsertContent(myField, myValue) { |
| 575 |
var sel, startPos, endPos, scrollTop; |
| 576 |
|
| 577 |
//IE support |
| 578 |
if (document.selection) { |
| 579 |
myField.focus(); |
| 580 |
sel = document.selection.createRange(); |
| 581 |
sel.text = myValue; |
| 582 |
myField.focus(); |
| 583 |
} |
| 584 |
//MOZILLA/NETSCAPE support |
| 585 |
else if (myField.selectionStart || myField.selectionStart == "0") { |
| 586 |
startPos = myField.selectionStart; |
| 587 |
endPos = myField.selectionEnd; |
| 588 |
scrollTop = myField.scrollTop; |
| 589 |
myField.value = myField.value.substring(0, startPos) |
| 590 |
+ myValue |
| 591 |
+ myField.value.substring(endPos, myField.value.length); |
| 592 |
myField.focus(); |
| 593 |
myField.selectionStart = startPos + myValue.length; |
| 594 |
myField.selectionEnd = startPos + myValue.length; |
| 595 |
myField.scrollTop = scrollTop; |
| 596 |
} else { |
| 597 |
myField.value += myValue; |
| 598 |
myField.focus(); |
| 599 |
} |
| 600 |
}'; |
| 601 |
|
| 602 |
$out .= 'function send_to_custom_field(h) {' . "\n" . |
| 603 |
' if ( tmpFocus ) ed = tmpFocus;' . "\n" . |
| 604 |
' else if ( typeof tinyMCE == "undefined" ) ed = document.getElementById("content");' . "\n" . |
| 605 |
' else { ed = tinyMCE.get("content"); if(ed) {if(!ed.isHidden()) isTinyMCE = true;}}' . "\n" . |
| 606 |
' if ( typeof tinyMCE != "undefined" && isTinyMCE && !ed.isHidden() ) {' . "\n" . |
| 607 |
' ed.focus();' . "\n" . |
| 608 |
' if ( tinymce.isIE && ed.windowManager.insertimagebookmark )' . "\n" . |
| 609 |
' ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);' . "\n" . |
| 610 |
' if ( h.indexOf("[caption") === 0 ) {' . "\n" . |
| 611 |
' if ( ed.plugins.wpeditimage )' . "\n" . |
| 612 |
' h = ed.plugins.wpeditimage._do_shcode(h);' . "\n" . |
| 613 |
' } else if ( h.indexOf("[gallery") === 0 ) {' . "\n" . |
| 614 |
' if ( ed.plugins.wpgallery )' . "\n" . |
| 615 |
' h = ed.plugins.wpgallery._do_gallery(h);' . "\n" . |
| 616 |
' } else if ( h.indexOf("[embed") === 0 ) {' . "\n" . |
| 617 |
' if ( ed.plugins.wordpress )' . "\n" . |
| 618 |
' h = ed.plugins.wordpress._setEmbed(h);' . "\n" . |
| 619 |
' }' . "\n" . |
| 620 |
' ed.execCommand("mceInsertContent", false, h);' . "\n" . |
| 621 |
' } else {' . "\n" . |
| 622 |
' if ( tmpFocus ) _edInsertContent(tmpFocus, h);' . "\n" . |
| 623 |
' else edInsertContent(edCanvas, h);' . "\n" . |
| 624 |
' }' . "\n"; |
| 625 |
|
| 626 |
if ( empty($options['custom_field_template_use_multiple_insert']) ) { |
| 627 |
$out .= ' tb_remove();' . "\n" . |
| 628 |
' tmpFocus = undefined;' . "\n" . |
| 629 |
' isTinyMCE = false;' . "\n"; |
| 630 |
} |
| 631 |
|
| 632 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 633 |
$qt_position = 'jQuery(\'#editorcontainer_\'+id).prev()'; |
| 634 |
$load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, id);'; |
| 635 |
elseif ( substr($wp_version, 0, 3) < '3.9' ) : |
| 636 |
$qt_position = 'jQuery(\'#qt_\'+id+\'_toolbar\')'; |
| 637 |
$load_tinyMCE = 'var ed = new tinyMCE.Editor(id, tinyMCEPreInit.mceInit[\'content\']); ed.render();'; |
| 638 |
else : |
| 639 |
$qt_position = 'jQuery(\'#qt_\'+id+\'_toolbar\')'; |
| 640 |
$load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddEditor'" . ', true, id);'; |
| 641 |
endif; |
| 642 |
|
| 643 |
$out .= '}' . "\n" . |
| 644 |
'jQuery(".thickbox").bind("click", function (e) {' . "\n" . |
| 645 |
' tmpFocus = undefined;' . "\n" . |
| 646 |
' isTinyMCE = false;' . "\n" . |
| 647 |
'});' . "\n" . |
| 648 |
'var isTinyMCE;' . "\n" . |
| 649 |
'var tmpFocus;' . "\n" . |
| 650 |
'function focusTextArea(id) {' . "\n" . |
| 651 |
' jQuery(document).ready(function() {' . "\n" . |
| 652 |
' if ( typeof tinyMCE != "undefined" ) {' . "\n" . |
| 653 |
' var elm = tinyMCE.get(id);' . "\n" . |
| 654 |
' }' . "\n" . |
| 655 |
' if ( ! elm || elm.isHidden() ) {' . "\n" . |
| 656 |
' elm = document.getElementById(id);' . "\n" . |
| 657 |
' isTinyMCE = false;' . "\n" . |
| 658 |
' }else isTinyMCE = true;' . "\n" . |
| 659 |
' tmpFocus = elm' . "\n" . |
| 660 |
' elm.focus();' . "\n" . |
| 661 |
' if (elm.createTextRange) {' . "\n" . |
| 662 |
' var range = elm.createTextRange();' . "\n" . |
| 663 |
' range.move("character", elm.value.length);' . "\n" . |
| 664 |
' range.select();' . "\n" . |
| 665 |
' } else if (elm.setSelectionRange) {' . "\n" . |
| 666 |
' elm.setSelectionRange(elm.value.length, elm.value.length);' . "\n" . |
| 667 |
' }' . "\n" . |
| 668 |
' });' . "\n" . |
| 669 |
'}' . "\n" . |
| 670 |
'function switchMode(id) {' . "\n" . |
| 671 |
' var ed = tinyMCE.get(id);' . "\n" . |
| 672 |
' if ( ! ed || ed.isHidden() ) {' . "\n" . |
| 673 |
' document.getElementById(id).value = switchEditors.wpautop(document.getElementById(id).value);' . "\n" . |
| 674 |
' if ( ed ) { '.$qt_position.'.hide(); ed.show(); }' . "\n" . |
| 675 |
' else {'.$load_tinyMCE.'}' . "\n" . |
| 676 |
' } else {' . "\n" . |
| 677 |
' ed.hide(); '.$qt_position.'.show(); document.getElementById(id).style.color="#000000";' . "\n" . |
| 678 |
' }' . "\n" . |
| 679 |
'}' . "\n"; |
| 680 |
|
| 681 |
$out .= 'function thickbox(link) {' . "\n" . |
| 682 |
' var t = link.title || link.name || null;' . "\n" . |
| 683 |
' var a = link.href || link.alt;' . "\n" . |
| 684 |
' var g = link.rel || false;' . "\n" . |
| 685 |
' tb_show(t,a,g);' . "\n" . |
| 686 |
' link.blur();' . "\n" . |
| 687 |
' return false;' . "\n" . |
| 688 |
'}' . "\n"; |
| 689 |
$out .= '//--></script>'; |
| 690 |
$out .= '<input type="hidden" id="cft_current_template" value="" />'; |
| 691 |
$out .= '<input type="hidden" id="cft_clicked_id" value="" />'; |
| 692 |
$out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />'; |
| 693 |
|
| 694 |
$out .= '<style type="text/css">' . "\n" . |
| 695 |
'<!--' . "\n"; |
| 696 |
$out .= esc_html( $options['css'] ) . "\n"; |
| 697 |
$out .= '.editorcontainer { overflow:hidden; background:#FFFFFF; } |
| 698 |
.content { width:98%; } |
| 699 |
.editorcontainer .content { padding: 6px; line-height: 150%; border: 0 none; outline: none; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -khtml-box-sizing: border-box; box-sizing: border-box; } |
| 700 |
.quicktags { border:1px solid #DFDFDF; border-collapse: separate; -moz-border-radius: 6px 6px 0 0; -webkit-border-top-right-radius: 6px; -webkit-border-top-left-radius: 6px; -khtml-border-top-right-radius: 6px; -khtml-border-top-left-radius: 6px; border-top-right-radius: 6px; border-top-left-radius: 6px; } |
| 701 |
.quicktags { padding: 0; margin-bottom: -1px; border-bottom-width:1px; background-image: url("images/ed-bg.gif"); background-position: left top; background-repeat: repeat; } |
| 702 |
.quicktags div div { padding: 2px 4px 0; } |
| 703 |
.quicktags div div input { margin: 3px 1px 4px; line-height: 18px; display: inline-block; border-width: 1px; border-style: solid; min-width: 26px; padding: 2px 4px; font-size: 12px; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; background:#FFFFFF url(images/fade-butt.png) repeat-x scroll 0 -2px; overflow: visible; }' . "\n"; |
| 704 |
$out .= '-->' . "\n" . |
| 705 |
'</style>'; |
| 706 |
echo $out; |
| 707 |
} |
| 708 |
|
| 709 |
function add_manage_posts_custom_column($column_name, $post_id) { |
| 710 |
$data = $this->get_post_meta($post_id); |
| 711 |
|
| 712 |
if( is_array($data) && $column_name == 'custom-fields' ) : |
| 713 |
$flag = 0; |
| 714 |
$content = $output = ''; |
| 715 |
foreach($data as $key => $val) : |
| 716 |
if ( is_protected_meta($key) ) continue; |
| 717 |
$content .= '<p class="key">' . esc_html( $key ) . '</p>' . "\n"; |
| 718 |
foreach($val as $val2) : |
| 719 |
$val2 = htmlspecialchars($val2, ENT_QUOTES); |
| 720 |
if ( $flag ) : |
| 721 |
$content .= '<p class="value">' . $val2 . '</p>' . "\n"; |
| 722 |
else : |
| 723 |
if ( function_exists('mb_strlen') ) : |
| 724 |
if ( mb_strlen($val2) > 50 ) : |
| 725 |
$before_content = mb_substr($val2, 0, 50); |
| 726 |
$after_content = mb_substr($val2, 50); |
| 727 |
$content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n"; |
| 728 |
$flag = 1; |
| 729 |
else : |
| 730 |
$content .= '<p class="value">' . $val2 . '</p>' . "\n"; |
| 731 |
endif; |
| 732 |
else : |
| 733 |
if ( strlen($val2) > 50 ) : |
| 734 |
$before_content = substr($val2, 0, 50); |
| 735 |
$after_content = substr($val2, 50); |
| 736 |
$content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n"; |
| 737 |
$flag = 1; |
| 738 |
else : |
| 739 |
$content .= '<p class="value">' . $val2 . '</p>' . "\n"; |
| 740 |
endif; |
| 741 |
endif; |
| 742 |
endif; |
| 743 |
endforeach; |
| 744 |
endforeach; |
| 745 |
if ( $content ) : |
| 746 |
$content = preg_replace('/([^\n]+)\n([^\n]+)\n([^\n]+)\n([^\n]+)\n([^$]+)/', '\1\2\3\4[[[break]]]\5', $content); |
| 747 |
@list($before, $after) = explode('[[[break]]]', $content, 2); |
| 748 |
$after = preg_replace('/\[\[\[break\]\]\]/', '', $after); |
| 749 |
$output .= '<div class="cft_list">'; |
| 750 |
$output .= balanceTags($before, true); |
| 751 |
if ( $after ) : |
| 752 |
$output .= '<span class="hide-if-no-js-cft"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().show(); jQuery(this).parent().next().next().show(); jQuery(this).parent().hide();">... ' . __('read more', 'custom-field-template') . '</a></span>'; |
| 753 |
$output .= '<span class="hide-if-js-cft">' . balanceTags($after, true) . '</span>'; |
| 754 |
$output .= '<span style="display:none;"><a href="javascript:void(0);" onclick="jQuery(this).parent().prev().hide(); jQuery(this).parent().prev().prev().show(); jQuery(this).parent().hide();">[^]</a></span>'; |
| 755 |
endif; |
| 756 |
$output .= '</div>'; |
| 757 |
else : |
| 758 |
$output .= ' '; |
| 759 |
endif; |
| 760 |
endif; |
| 761 |
|
| 762 |
if ( isset($output) ) echo $output; |
| 763 |
} |
| 764 |
|
| 765 |
function add_manage_posts_columns($columns) { |
| 766 |
/*$new_columns = array(); |
| 767 |
foreach($columns as $key => $val) : |
| 768 |
$new_columns[$key] = $val; |
| 769 |
if ( $key == 'tags' ) |
| 770 |
$new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template'); |
| 771 |
endforeach;*/ |
| 772 |
|
| 773 |
$columns['custom-fields'] = __('Custom Fields', 'custom-field-template'); |
| 774 |
return $columns; |
| 775 |
} |
| 776 |
|
| 777 |
function add_manage_pages_columns($columns) { |
| 778 |
/*$new_columns = array(); |
| 779 |
foreach($columns as $key => $val) : |
| 780 |
$new_columns[$key] = $val; |
| 781 |
if ( $key == 'author' ) |
| 782 |
$new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template'); |
| 783 |
endforeach;*/ |
| 784 |
|
| 785 |
$columns['custom-fields'] = __('Custom Fields', 'custom-field-template'); |
| 786 |
return $columns; |
| 787 |
} |
| 788 |
|
| 789 |
function media_send_to_custom_field($html) { |
| 790 |
if ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/admin-ajax.php') ) return $html; |
| 791 |
$html_json = wp_json_encode( $html, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); |
| 792 |
$out = '<script type="text/javascript">' . "\n" . |
| 793 |
' /* <![CDATA[ */' . "\n" . |
| 794 |
' var win = window.dialogArguments || opener || parent || top;' . "\n" . |
| 795 |
' if ( typeof win.send_to_custom_field == "function" ) ' . "\n" . |
| 796 |
' win.send_to_custom_field(' . $html_json . ');' . "\n" . |
| 797 |
' else ' . "\n" . |
| 798 |
' win.send_to_editor(' . $html_json . ');' . "\n" . |
| 799 |
'/* ]]> */' . "\n" . |
| 800 |
'</script>' . "\n"; |
| 801 |
|
| 802 |
echo $out; |
| 803 |
exit(); |
| 804 |
} |
| 805 |
function wpaq_filter_plugin_actions($links, $file){ |
| 806 |
static $this_plugin; |
| 807 |
|
| 808 |
if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__); |
| 809 |
|
| 810 |
if( $file == $this_plugin ){ |
| 811 |
$settings_link = '<a href="options-general.php?page=custom-field-template.php">' . __('Settings') . '</a>'; |
| 812 |
$links = array_merge( array($settings_link), $links); |
| 813 |
} |
| 814 |
return $links; |
| 815 |
} |
| 816 |
|
| 817 |
function custom_field_template_admin_scripts() { |
| 818 |
global $post, $wp_version; |
| 819 |
$options = $this->get_custom_field_template_data(); |
| 820 |
$locale = get_locale(); |
| 821 |
|
| 822 |
if ( !defined('WP_PLUGIN_DIR') ) |
| 823 |
$plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) ); |
| 824 |
else |
| 825 |
$plugin_dir = dirname( plugin_basename(__FILE__) ); |
| 826 |
|
| 827 |
wp_enqueue_script( 'jquery' ); |
| 828 |
if ( substr($wp_version, 0, 3) >= '5.5' ) : |
| 829 |
wp_enqueue_script( 'jquery-migrate', '/'.PLUGINDIR.'/'.$plugin_dir.'/jquery-migrate-1.4.1.min.js', array('jquery')); |
| 830 |
endif; |
| 831 |
wp_enqueue_script( 'jquery-form' ); |
| 832 |
//wp_enqueue_script( 'bgiframe', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.bgiframe.js', array('jquery') ) ; |
| 833 |
if (strpos($_SERVER['REQUEST_URI'], 'custom-field-template') !== false ) |
| 834 |
wp_enqueue_script( 'textarearesizer', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.textarearesizer.js', array('jquery') ); |
| 835 |
if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || (is_object($post) && $post->post_type=='page') ) : |
| 836 |
wp_enqueue_script('date', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/date.js', array('jquery') ); |
| 837 |
wp_enqueue_script('datePicker', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.datePicker.js', array('jquery') ); |
| 838 |
wp_enqueue_style('datePicker', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/datePicker.css' ); |
| 839 |
wp_enqueue_script('editor'); |
| 840 |
wp_enqueue_script('quicktags'); |
| 841 |
|
| 842 |
if ( !empty($options['custom_field_template_use_validation']) ) : |
| 843 |
wp_enqueue_script( 'jquery-validate', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.validate.js', array('jquery') ); |
| 844 |
wp_enqueue_script( 'additional-methods', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/additional-methods.js', array('jquery') ); |
| 845 |
if ( file_exists(ABSPATH . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . $locale . '.js') ) |
| 846 |
wp_enqueue_script( 'messages_' . $locale, '/' . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . $locale .'.js', array('jquery') ); |
| 847 |
endif; |
| 848 |
endif; |
| 849 |
|
| 850 |
} |
| 851 |
|
| 852 |
function install_custom_field_template_data() { |
| 853 |
$options['custom_field_template_before_list'] = '<ul>'; |
| 854 |
$options['custom_field_template_after_list'] = '</ul>'; |
| 855 |
$options['custom_field_template_before_value'] = '<li>'; |
| 856 |
$options['custom_field_template_after_value'] = '</li>'; |
| 857 |
$options['custom_fields'][0]['title'] = __('Default Template', 'custom-field-template'); |
| 858 |
$options['custom_fields'][0]['content'] = '[Plan] |
| 859 |
type = text |
| 860 |
size = 35 |
| 861 |
label = Where are you going to go? |
| 862 |
|
| 863 |
[Plan] |
| 864 |
type = textfield |
| 865 |
size = 35 |
| 866 |
hideKey = true |
| 867 |
|
| 868 |
[Favorite Fruits] |
| 869 |
type = checkbox |
| 870 |
value = apple # orange # banana # grape |
| 871 |
default = orange # grape |
| 872 |
|
| 873 |
[Miles Walked] |
| 874 |
type = radio |
| 875 |
value = 0-9 # 10-19 # 20+ |
| 876 |
default = 10-19 |
| 877 |
clearButton = true |
| 878 |
|
| 879 |
[Temper Level] |
| 880 |
type = select |
| 881 |
value = High # Medium # Low |
| 882 |
default = Low |
| 883 |
|
| 884 |
[Hidden Thought] |
| 885 |
type = textarea |
| 886 |
rows = 4 |
| 887 |
cols = 40 |
| 888 |
tinyMCE = true |
| 889 |
htmlEditor = true |
| 890 |
mediaButton = true |
| 891 |
|
| 892 |
[File Upload] |
| 893 |
type = file'; |
| 894 |
$options['shortcode_format'][0] = '<table class="cft"> |
| 895 |
<tbody> |
| 896 |
<tr> |
| 897 |
<th>Plan</th><td colspan="3">[Plan]</td> |
| 898 |
</tr> |
| 899 |
<tr> |
| 900 |
<th>Favorite Fruits</th><td>[Favorite Fruits]</td> |
| 901 |
<th>Miles Walked</th><td>[Miles Walked]</td> |
| 902 |
</tr> |
| 903 |
<tr> |
| 904 |
<th>Temper Level</th><td colspan="3">[Temper Level]</td> |
| 905 |
</tr> |
| 906 |
<tr> |
| 907 |
<th>Hidden Thought</th><td colspan="3">[Hidden Thought]</td> |
| 908 |
</tr> |
| 909 |
</tbody> |
| 910 |
</table>'; |
| 911 |
update_option('custom_field_template_data', $options); |
| 912 |
} |
| 913 |
|
| 914 |
function install_custom_field_template_css() { |
| 915 |
$options = get_option('custom_field_template_data'); |
| 916 |
$options['css'] = '.cft { overflow:hidden; } |
| 917 |
.cft:after { content:" "; clear:both; height:0; display:block; visibility:hidden; } |
| 918 |
.cft dl { margin:10px 0; } |
| 919 |
.cft dl:after { content:" "; clear:both; height:0; display:block; visibility:hidden; } |
| 920 |
.cft dt { width:20%; clear:both; float:left; display:inline; font-weight:bold; text-align:center; } |
| 921 |
.cft dt .hideKey { visibility:hidden; } |
| 922 |
.cft dd { margin:0 0 0 21%; } |
| 923 |
.cft dd p.label { font-weight:bold; margin:0; } |
| 924 |
.cft_instruction { margin:10px; } |
| 925 |
.cft fieldset { border:1px solid #CCC; margin:5px; padding:5px; } |
| 926 |
.cft .dl_checkbox { margin:0; } |
| 927 |
'; |
| 928 |
update_option('custom_field_template_data', $options); |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
function get_custom_field_template_data() { |
| 933 |
$options = get_option('custom_field_template_data'); |
| 934 |
if ( !empty($options) && !is_array($options) ) $options = array(); |
| 935 |
return $options; |
| 936 |
} |
| 937 |
|
| 938 |
function custom_field_template_admin_menu() { |
| 939 |
$options = $this->get_custom_field_template_data(); |
| 940 |
add_options_page(__('Custom Field Template', 'custom-field-template'), __('Custom Field Template', 'custom-field-template'), 'manage_options', basename(__FILE__), array(&$this, 'custom_field_template_admin')); |
| 941 |
if ( empty($options['custom_field_template_disable_admin_search']) ) : |
| 942 |
//add_action('load-edit.php', array(&$this, 'custom_field_template_add_help_tab') ); |
| 943 |
endif; |
| 944 |
} |
| 945 |
|
| 946 |
function custom_field_template_add_help_tab() { |
| 947 |
$screen = get_current_screen(); |
| 948 |
|
| 949 |
} |
| 950 |
|
| 951 |
function custom_field_template_get_the_excerpt($excerpt) { |
| 952 |
$options = $this->get_custom_field_template_data(); |
| 953 |
|
| 954 |
if ( empty($excerpt) ) $this->is_excerpt = true; |
| 955 |
if ( !empty($options['custom_field_template_excerpt_shortcode']) ) return do_shortcode($excerpt); |
| 956 |
else return $excerpt; |
| 957 |
} |
| 958 |
|
| 959 |
function custom_field_template_the_content($content) { |
| 960 |
global $wp_query, $post, $shortcode_tags, $wp_version; |
| 961 |
$options = $this->get_custom_field_template_data(); |
| 962 |
|
| 963 |
if ( isset($options['hook']) && count($options['hook']) > 0 ) : |
| 964 |
$categories = get_the_category(); |
| 965 |
$cats = array(); |
| 966 |
foreach( $categories as $val ) : |
| 967 |
$cats[] = $val->cat_ID; |
| 968 |
endforeach; |
| 969 |
|
| 970 |
for ( $i=0; $i<count($options['hook']); $i++ ) : |
| 971 |
|
| 972 |
if ( $this->is_excerpt && empty($options['hook'][$i]['excerpt']) ) : |
| 973 |
$this->is_excerpt = false; |
| 974 |
$content = $post->post_excerpt ? $post->post_excerpt : strip_shortcodes($content); |
| 975 |
$strip_shortcode = 1; |
| 976 |
continue; |
| 977 |
endif; |
| 978 |
|
| 979 |
$options['hook'][$i]['content'] = stripslashes($options['hook'][$i]['content']); |
| 980 |
if ( is_feed() && empty($options['hook'][$i]['feed']) ) break; |
| 981 |
if ( !empty($options['hook'][$i]['category']) ) : |
| 982 |
if ( is_category() || is_single() || is_feed() ) : |
| 983 |
if ( !empty($options['hook'][$i]['use_php']) ) : |
| 984 |
$options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content'])); |
| 985 |
endif; |
| 986 |
$needle = explode(',', $options['hook'][$i]['category']); |
| 987 |
$needle = array_filter($needle); |
| 988 |
$needle = array_unique(array_filter(array_map('trim', $needle))); |
| 989 |
foreach ( $needle as $val ) : |
| 990 |
if ( in_array($val, $cats ) ) : |
| 991 |
if ( $options['hook'][$i]['position'] == 0 ) : |
| 992 |
$content .= $options['hook'][$i]['content']; |
| 993 |
elseif ( $options['hook'][$i]['position'] == 2 ) : |
| 994 |
$content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content); |
| 995 |
elseif ( $options['hook'][$i]['position'] == 3 ) : |
| 996 |
$content = preg_replace('/(<span id="more-[0-9]+"><\/span>)/', $options['hook'][$i]['content']."$1", $content); |
| 997 |
else : |
| 998 |
$content = $options['hook'][$i]['content'] . $content; |
| 999 |
endif; |
| 1000 |
break; |
| 1001 |
endif; |
| 1002 |
endforeach; |
| 1003 |
endif; |
| 1004 |
elseif ( $options['hook'][$i]['post_type']=='post' ) : |
| 1005 |
if ( is_single() ) : |
| 1006 |
if ( !empty($options['hook'][$i]['use_php']) ) : |
| 1007 |
$options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content'])); |
| 1008 |
endif; |
| 1009 |
if ( $options['hook'][$i]['position'] == 0 ) : |
| 1010 |
$content .= $options['hook'][$i]['content']; |
| 1011 |
elseif ( $options['hook'][$i]['position'] == 2 ) : |
| 1012 |
$content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content); |
| 1013 |
elseif ( $options['hook'][$i]['position'] == 3 ) : |
| 1014 |
$content = preg_replace('/(<span id="more-[0-9]+"><\/span>)/', $options['hook'][$i]['content']."$1", $content); |
| 1015 |
else : |
| 1016 |
$content = $options['hook'][$i]['content'] . $content; |
| 1017 |
endif; |
| 1018 |
endif; |
| 1019 |
elseif ( $options['hook'][$i]['post_type']=='page' ) : |
| 1020 |
if ( is_page() ) : |
| 1021 |
if ( !empty($options['hook'][$i]['use_php']) ) : |
| 1022 |
$options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content'])); |
| 1023 |
endif; |
| 1024 |
if ( $options['hook'][$i]['position'] == 0 ) : |
| 1025 |
$content .= $options['hook'][$i]['content']; |
| 1026 |
elseif ( $options['hook'][$i]['position'] == 2 ) : |
| 1027 |
$content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content); |
| 1028 |
elseif ( $options['hook'][$i]['position'] == 3 ) : |
| 1029 |
$content = preg_replace('/(<span id="more-[0-9]+"><\/span>)/', $options['hook'][$i]['content']."$1", $content); |
| 1030 |
else : |
| 1031 |
$content = $options['hook'][$i]['content'] . $content; |
| 1032 |
endif; |
| 1033 |
endif; |
| 1034 |
elseif ( $options['hook'][$i]['custom_post_type'] ) : |
| 1035 |
$custom_post_type = explode(',', $options['hook'][$i]['custom_post_type']); |
| 1036 |
$custom_post_type = array_filter( $custom_post_type ); |
| 1037 |
$custom_post_type = array_map( 'trim', $custom_post_type ); |
| 1038 |
if ( in_array($post->post_type, $custom_post_type) ) : |
| 1039 |
if ( !empty($options['hook'][$i]['use_php']) ) : |
| 1040 |
$options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content'])); |
| 1041 |
endif; |
| 1042 |
if ( $options['hook'][$i]['position'] == 0 ) : |
| 1043 |
$content .= $options['hook'][$i]['content']; |
| 1044 |
elseif ( $options['hook'][$i]['position'] == 2 ) : |
| 1045 |
$content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content); |
| 1046 |
elseif ( $options['hook'][$i]['position'] == 3 ) : |
| 1047 |
$content = preg_replace('/(<span id="more-[0-9]+"><\/span>)/', $options['hook'][$i]['content']."$1", $content); |
| 1048 |
else : |
| 1049 |
$content = $options['hook'][$i]['content'] . $content; |
| 1050 |
endif; |
| 1051 |
endif; |
| 1052 |
else : |
| 1053 |
if ( !empty($options['hook'][$i]['use_php']) ) : |
| 1054 |
$options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content'])); |
| 1055 |
endif; |
| 1056 |
if ( $options['hook'][$i]['position'] == 0 ) : |
| 1057 |
$content .= $options['hook'][$i]['content']; |
| 1058 |
elseif ( $options['hook'][$i]['position'] == 2 ) : |
| 1059 |
$content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content); |
| 1060 |
elseif ( $options['hook'][$i]['position'] == 3 ) : |
| 1061 |
$content = preg_replace('/(<span id="more-[0-9]+"><\/span>)/', $options['hook'][$i]['content']."$1", $content); |
| 1062 |
else : |
| 1063 |
$content = $options['hook'][$i]['content'] . $content; |
| 1064 |
endif; |
| 1065 |
endif; |
| 1066 |
endfor; |
| 1067 |
return !empty($strip_shortcode)? $content : do_shortcode($content); |
| 1068 |
else : |
| 1069 |
return $content; |
| 1070 |
endif; |
| 1071 |
} |
| 1072 |
|
| 1073 |
function custom_field_template_check_premium_code( $premium_code, $functionality ) { |
| 1074 |
$host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : ''; |
| 1075 |
if ( password_verify( $host.$functionality, $premium_code ) ) : |
| 1076 |
return 1; |
| 1077 |
else : |
| 1078 |
return 0; |
| 1079 |
endif; |
| 1080 |
} |
| 1081 |
|
| 1082 |
function custom_field_template_check_authentication_key( $auth_key ) { |
| 1083 |
$host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : parse_url( home_url(), PHP_URL_HOST ); |
| 1084 |
$auth_url = add_query_arg( |
| 1085 |
array( |
| 1086 |
'domain' => sanitize_text_field( $host ), |
| 1087 |
'auth_key' => sanitize_text_field( $auth_key ), |
| 1088 |
), |
| 1089 |
'https://www.wpcft.com/auth/' |
| 1090 |
); |
| 1091 |
$request = wp_remote_get( esc_url_raw( $auth_url ) ); |
| 1092 |
if ( ! is_wp_error( $request ) && $request['response']['code'] == 200 ) : |
| 1093 |
if ( $request['body'] == 1 ) : |
| 1094 |
return true; |
| 1095 |
else : |
| 1096 |
return false; |
| 1097 |
endif; |
| 1098 |
else : |
| 1099 |
return false; |
| 1100 |
endif; |
| 1101 |
} |
| 1102 |
function custom_field_template_wp_list_table_class_name( $class_name, $args ) { |
| 1103 |
$options = $this->get_custom_field_template_data(); |
| 1104 |
$adminsearch = isset( $options['premium_settings']['adminsearch'][$args['screen']->post_type] ) ? $options['premium_settings']['adminsearch'][$args['screen']->post_type] : ''; |
| 1105 |
if ( ! empty( $options['custom_field_template_premium_code'] ) && $adminsearch != '' && strstr( $_SERVER['REQUEST_URI'], 'wp-admin/edit.php') ) : |
| 1106 |
return 'CFT_WP_Posts_List_Table'; |
| 1107 |
else : |
| 1108 |
return $class_name; |
| 1109 |
endif; |
| 1110 |
} |
| 1111 |
|
| 1112 |
function custom_field_template_admin() { |
| 1113 |
global $wp_version; |
| 1114 |
$locale = get_locale(); |
| 1115 |
|
| 1116 |
$options = $this->get_custom_field_template_data(); |
| 1117 |
|
| 1118 |
if ( !empty($_POST['_wpnonce']) ) : |
| 1119 |
if ( !wp_verify_nonce( $_POST['_wpnonce'], 'cft' ) ) : |
| 1120 |
$errormessage = __('Options were not updated.', 'custom-field-template'); |
| 1121 |
else : |
| 1122 |
if( !empty($_POST["custom_field_template_set_options_submit"]) ) : |
| 1123 |
unset($options['custom_fields']); |
| 1124 |
$j = 0; |
| 1125 |
for($i=0;$i<count($_POST["custom_field_template_content"]);$i++) { |
| 1126 |
if( $_POST["custom_field_template_content"][$i] ) { |
| 1127 |
if ( preg_match('/\[content\]|\[post_title\]|\[excerpt\]|\[action\]/i', $_POST["custom_field_template_content"][$i]) ) : |
| 1128 |
$errormessage = __('You can not use the following words as the field key: `content`, `post_title`, and `excerpt`, and `action`.', 'custom-field-template'); |
| 1129 |
endif; |
| 1130 |
if ( isset($_POST["custom_field_template_title"][$i]) ) $options['custom_fields'][$j]['title'] = $_POST["custom_field_template_title"][$i]; |
| 1131 |
if ( isset($_POST["custom_field_template_content"][$i]) ) $options['custom_fields'][$j]['content'] = $_POST["custom_field_template_content"][$i]; |
| 1132 |
if ( isset($_POST["custom_field_template_instruction"][$i]) ) $options['custom_fields'][$j]['instruction'] = $_POST["custom_field_template_instruction"][$i]; |
| 1133 |
if ( isset($_POST["custom_field_template_category"][$i]) ) $options['custom_fields'][$j]['category'] = $_POST["custom_field_template_category"][$i]; |
| 1134 |
if ( isset($_POST["custom_field_template_post"][$i]) ) $options['custom_fields'][$j]['post'] = $_POST["custom_field_template_post"][$i]; |
| 1135 |
if ( isset($_POST["custom_field_template_post_type"][$i]) ) $options['custom_fields'][$j]['post_type'] = $_POST["custom_field_template_post_type"][$i]; |
| 1136 |
if ( isset($_POST["custom_field_template_custom_post_type"][$i]) ) $options['custom_fields'][$j]['custom_post_type'] = $_POST["custom_field_template_custom_post_type"][$i]; |
| 1137 |
if ( isset($_POST["custom_field_template_template_files"][$i]) ) $options['custom_fields'][$j]['template_files'] = $_POST["custom_field_template_template_files"][$i]; |
| 1138 |
if ( isset($_POST["custom_field_template_user_id"][$i]) ) $options['custom_fields'][$j]['user_id'] = $_POST["custom_field_template_user_id"][$i]; |
| 1139 |
if ( isset($_POST["custom_field_template_user_login"][$i]) ) $options['custom_fields'][$j]['user_login'] = $_POST["custom_field_template_user_login"][$i]; |
| 1140 |
if ( isset($_POST["custom_field_template_user_role"][$i]) ) $options['custom_fields'][$j]['user_role'] = $_POST["custom_field_template_user_role"][$i]; |
| 1141 |
if ( isset($_POST["custom_field_template_disable"][$i]) ) $options['custom_fields'][$j]['disable'] = $_POST["custom_field_template_disable"][$i]; |
| 1142 |
$options['custom_fields'][$j]['format'] = isset($_POST["custom_field_template_format"][$i]) ? $_POST["custom_field_template_format"][$i] : ''; |
| 1143 |
$j++; |
| 1144 |
} |
| 1145 |
} |
| 1146 |
update_option('custom_field_template_data', $options); |
| 1147 |
$message = __('Options updated.', 'custom-field-template'); |
| 1148 |
elseif( !empty($_POST["custom_field_template_global_settings_submit"]) ) : |
| 1149 |
$options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : ''; |
| 1150 |
$options['custom_field_template_use_multiple_insert'] = isset($_POST['custom_field_template_use_multiple_insert']) ? 1 : ''; |
| 1151 |
$options['custom_field_template_use_wpautop'] = isset($_POST['custom_field_template_use_wpautop']) ? 1 : ''; |
| 1152 |
$options['custom_field_template_use_autosave'] = isset($_POST['custom_field_template_use_autosave']) ? 1 : ''; |
| 1153 |
$options['custom_field_template_use_disable_button'] = isset($_POST['custom_field_template_use_disable_button']) ? 1 : ''; |
| 1154 |
$options['custom_field_template_disable_initialize_button'] = isset($_POST['custom_field_template_disable_initialize_button']) ? 1 : ''; |
| 1155 |
$options['custom_field_template_disable_save_button'] = isset($_POST['custom_field_template_disable_save_button']) ? 1 : ''; |
| 1156 |
$options['custom_field_template_disable_default_custom_fields'] = isset($_POST['custom_field_template_disable_default_custom_fields']) ? 1 : ''; |
| 1157 |
$options['custom_field_template_disable_quick_edit'] = isset($_POST['custom_field_template_disable_quick_edit']) ? 1 : ''; |
| 1158 |
$options['custom_field_template_disable_admin_search'] = isset($_POST['custom_field_template_disable_admin_search']) ? 1 : ''; |
| 1159 |
$options['custom_field_template_disable_custom_field_column'] = isset($_POST['custom_field_template_disable_custom_field_column']) ? 1 : ''; |
| 1160 |
$options['custom_field_template_replace_the_title'] = isset($_POST['custom_field_template_replace_the_title']) ? 1 : ''; |
| 1161 |
$options['custom_field_template_deploy_box'] = isset($_POST['custom_field_template_deploy_box']) ? 1 : ''; |
| 1162 |
if ( !empty($options['custom_field_template_deploy_box']) ) : |
| 1163 |
$options['css'] = preg_replace('/#cft /', '.cft ', $options['css']); |
| 1164 |
$options['css'] = preg_replace('/#cft_/', '.cft_', $options['css']); |
| 1165 |
endif; |
| 1166 |
$options['custom_field_template_widget_shortcode'] = isset($_POST['custom_field_template_widget_shortcode']) ? 1 : ''; |
| 1167 |
$options['custom_field_template_excerpt_shortcode'] = isset($_POST['custom_field_template_excerpt_shortcode']) ? 1 : ''; |
| 1168 |
$options['custom_field_template_use_validation'] = isset($_POST['custom_field_template_use_validation']) ? 1 : ''; |
| 1169 |
$options['custom_field_template_before_list'] = isset($_POST['custom_field_template_before_list']) ? $_POST['custom_field_template_before_list'] : ''; |
| 1170 |
$options['custom_field_template_after_list'] = isset($_POST['custom_field_template_after_list']) ? $_POST['custom_field_template_after_list'] : ''; |
| 1171 |
$options['custom_field_template_before_value'] = isset($_POST['custom_field_template_before_value']) ? $_POST['custom_field_template_before_value'] : ''; |
| 1172 |
$options['custom_field_template_after_value'] = isset($_POST['custom_field_template_after_value']) ? $_POST['custom_field_template_after_value'] : ''; |
| 1173 |
$options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : ''; |
| 1174 |
$options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : ''; |
| 1175 |
$options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : ''; |
| 1176 |
$options['custom_field_template_output_direct_meta'] = isset($_POST['custom_field_template_output_direct_meta']) ? 1 : ''; |
| 1177 |
$options['custom_field_template_output_protected_meta'] = isset($_POST['custom_field_template_output_protected_meta']) ? 1 : ''; |
| 1178 |
$options['custom_field_template_disable_ad'] = isset($_POST['custom_field_template_disable_ad']) ? 1 : ''; |
| 1179 |
$options['custom_field_template_disable_donation'] = isset($_POST['custom_field_template_disable_donation']) ? 1 : ''; |
| 1180 |
update_option('custom_field_template_data', $options); |
| 1181 |
$message = __('Options updated.', 'custom-field-template'); |
| 1182 |
elseif( !empty($_POST["custom_field_template_premium_settings_submit"]) ) : |
| 1183 |
if ( ! empty( $_POST['custom_field_template_premium_code'] ) ) : |
| 1184 |
$check_value = $this->custom_field_template_check_authentication_key( $_POST['custom_field_template_premium_code'] ); |
| 1185 |
if ( $check_value == false ) : |
| 1186 |
$custom_field_template_premium_code = ''; |
| 1187 |
else : |
| 1188 |
$custom_field_template_premium_code = sanitize_text_field( $_POST['custom_field_template_premium_code'] ); |
| 1189 |
endif; |
| 1190 |
$options['custom_field_template_premium_code'] = $custom_field_template_premium_code; |
| 1191 |
if ( ! empty( $_POST["adminsearch"] ) ) : |
| 1192 |
foreach( $_POST["adminsearch"] as $key => $val ) : |
| 1193 |
if( isset( $val ) && is_numeric( $val ) ) : |
| 1194 |
$options['premium_settings']['adminsearch'][$key] = $val; |
| 1195 |
endif; |
| 1196 |
endforeach; |
| 1197 |
endif; |
| 1198 |
update_option('custom_field_template_data', $options); |
| 1199 |
$message = __('Options updated.', 'custom-field-template'); |
| 1200 |
endif; |
| 1201 |
elseif ( !empty($_POST['custom_field_template_css_submit']) ) : |
| 1202 |
$options['css'] = $_POST['custom_field_template_css']; |
| 1203 |
update_option('custom_field_template_data', $options); |
| 1204 |
$message = __('Options updated.', 'custom-field-template'); |
| 1205 |
elseif ( !empty($_POST['custom_field_template_shortcode_format_submit']) ) : |
| 1206 |
unset($options['shortcode_format'], $options['shortcode_format_use_php']); |
| 1207 |
$j = 0; |
| 1208 |
for($i=0;$i<count($_POST["custom_field_template_shortcode_format"]);$i++) { |
| 1209 |
if( !empty($_POST["custom_field_template_shortcode_format"][$i]) ) : |
| 1210 |
$options['shortcode_format'][$j] = $_POST["custom_field_template_shortcode_format"][$i]; |
| 1211 |
$options['shortcode_format_use_php'][$j] = isset($_POST["custom_field_template_shortcode_format_use_php"][$i]) ? $_POST["custom_field_template_shortcode_format_use_php"][$i] : ''; |
| 1212 |
$j++; |
| 1213 |
endif; |
| 1214 |
} |
| 1215 |
update_option('custom_field_template_data', $options); |
| 1216 |
$message = __('Options updated.', 'custom-field-template'); |
| 1217 |
elseif ( !empty($_POST['custom_field_template_php_submit']) ) : |
| 1218 |
unset($options['php']); |
| 1219 |
for($i=0;$i<count($_POST["custom_field_template_php"]);$i++) { |
| 1220 |
if( !empty($_POST["custom_field_template_php"][$i]) ) |
| 1221 |
$options['php'][] = $_POST["custom_field_template_php"][$i]; |
| 1222 |
} |
| 1223 |
update_option('custom_field_template_data', $options); |
| 1224 |
$message = __('Options updated.', 'custom-field-template'); |
| 1225 |
elseif( !empty($_POST["custom_field_template_hook_submit"]) ) : |
| 1226 |
unset($options['hook']); |
| 1227 |
$j = 0; |
| 1228 |
for($i=0;$i<count($_POST["custom_field_template_hook_content"]);$i++) { |
| 1229 |
if( $_POST["custom_field_template_hook_content"][$i] ) { |
| 1230 |
$options['hook'][$j]['position'] = !empty($_POST["custom_field_template_hook_position"][$i]) ? $_POST["custom_field_template_hook_position"][$i] : ''; |
| 1231 |
$options['hook'][$j]['content'] = $_POST["custom_field_template_hook_content"][$i]; |
| 1232 |
$options['hook'][$j]['custom_post_type'] = preg_replace('/\s/', '', $_POST["custom_field_template_hook_custom_post_type"][$i]); |
| 1233 |
$options['hook'][$j]['category'] = preg_replace('/\s/', '', $_POST["custom_field_template_hook_category"][$i]); |
| 1234 |
$options['hook'][$j]['use_php'] = !empty($_POST["custom_field_template_hook_use_php"][$i]) ? $_POST["custom_field_template_hook_use_php"][$i] : ''; |
| 1235 |
$options['hook'][$j]['feed'] = !empty($_POST["custom_field_template_hook_feed"][$i]) ? $_POST["custom_field_template_hook_feed"][$i] : ''; |
| 1236 |
$options['hook'][$j]['post_type'] = !empty($_POST["custom_field_template_hook_post_type"][$i]) ? $_POST["custom_field_template_hook_post_type"][$i] : ''; |
| 1237 |
$options['hook'][$j]['excerpt'] = !empty($_POST["custom_field_template_hook_excerpt"][$i]) ? $_POST["custom_field_template_hook_excerpt"][$i] : ''; |
| 1238 |
$j++; |
| 1239 |
} |
| 1240 |
} |
| 1241 |
update_option('custom_field_template_data', $options); |
| 1242 |
$message = __('Options updated.', 'custom-field-template'); |
| 1243 |
elseif ( !empty($_POST['custom_field_template_rebuild_value_counts_submit']) ) : |
| 1244 |
$this->custom_field_template_rebuild_value_counts(); |
| 1245 |
$options = $this->get_custom_field_template_data(); |
| 1246 |
$message = __('Value Counts rebuilt.', 'custom-field-template'); |
| 1247 |
elseif ( !empty($_POST['custom_field_template_rebuild_tags_submit']) ) : |
| 1248 |
$options = $this->get_custom_field_template_data(); |
| 1249 |
$message = __('Tags rebuilt.', 'custom-field-template'); |
| 1250 |
elseif ( !empty($_POST['custom_field_template_import_options_submit']) ) : |
| 1251 |
if ( is_uploaded_file($_FILES['cftfile']['tmp_name']) ) : |
| 1252 |
ob_start(); |
| 1253 |
readfile ($_FILES['cftfile']['tmp_name']); |
| 1254 |
$import = ob_get_contents(); |
| 1255 |
ob_end_clean(); |
| 1256 |
if ( is_serialized( $import ) ) : |
| 1257 |
$import = @unserialize( trim( $import ), ['allowed_classes' => false]); |
| 1258 |
if ( 'array' == gettype( $import ) ) : |
| 1259 |
update_option('custom_field_template_data', $import); |
| 1260 |
$message = __('Options imported.', 'custom-field-template'); |
| 1261 |
$options = $this->get_custom_field_template_data(); |
| 1262 |
endif; |
| 1263 |
endif; |
| 1264 |
endif; |
| 1265 |
elseif ( !empty($_POST['custom_field_template_reset_options_submit']) ) : |
| 1266 |
$this->install_custom_field_template_data(); |
| 1267 |
$this->install_custom_field_template_css(); |
| 1268 |
$options = $this->get_custom_field_template_data(); |
| 1269 |
$message = __('Options resetted.', 'custom-field-template'); |
| 1270 |
elseif ( !empty($_POST['custom_field_template_delete_options_submit']) ) : |
| 1271 |
delete_option('custom_field_template_data'); |
| 1272 |
$options = $this->get_custom_field_template_data(); |
| 1273 |
$message = __('Options deleted.', 'custom-field-template'); |
| 1274 |
endif; |
| 1275 |
endif; |
| 1276 |
endif; |
| 1277 |
|
| 1278 |
if ( !defined('WP_PLUGIN_DIR') ) |
| 1279 |
$plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) ); |
| 1280 |
else |
| 1281 |
$plugin_dir = dirname( plugin_basename(__FILE__) ); |
| 1282 |
?> |
| 1283 |
<style type="text/css"> |
| 1284 |
.postbox.closed { border-bottom:1px solid #ccd0d4; } |
| 1285 |
.postbox .handlediv { display: block; float: right; width: 36px; height: 36px; margin: 0; padding: 0; border: 0; background: 0 0; cursor: pointer; } |
| 1286 |
.postbox.closed .handlediv::before { content: '\f140'; } |
| 1287 |
.postbox .handlediv::before { content: '\f142'; } |
| 1288 |
.postbox .handlediv::before { font: normal 20px/1 'dashicons'; display: inline-block; padding: 8px 10px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-decoration: none !important; } |
| 1289 |
#poststuff h3 { font-size: 14px; line-height: 1.4; margin: 0; padding: 8px 12px; } |
| 1290 |
div.grippie { |
| 1291 |
background:#EEEEEE url(<?php echo '../' . PLUGINDIR . '/' . $plugin_dir . '/js/'; ?>grippie.png) no-repeat scroll center 2px; |
| 1292 |
border-color:#DDDDDD; |
| 1293 |
border-style:solid; |
| 1294 |
border-width:0pt 1px 1px; |
| 1295 |
cursor:s-resize; |
| 1296 |
height:9px; |
| 1297 |
overflow:hidden; |
| 1298 |
} |
| 1299 |
.resizable-textarea textarea { |
| 1300 |
display:block; |
| 1301 |
margin-bottom:0pt; |
| 1302 |
} |
| 1303 |
</style> |
| 1304 |
<script type="text/javascript"> |
| 1305 |
jQuery(document).ready(function() { |
| 1306 |
jQuery('textarea.resizable:not(.processed)').TextAreaResizer(); |
| 1307 |
}); |
| 1308 |
</script> |
| 1309 |
<?php if ( !empty($message) ) : ?> |
| 1310 |
<div id="message" class="updated"><p><?php echo $message; ?></p></div> |
| 1311 |
<?php endif; ?> |
| 1312 |
<?php if ( !empty($errormessage) ) : ?> |
| 1313 |
<div id="errormessage" class="error"><p><?php echo $errormessage; ?></p></div> |
| 1314 |
<?php endif; ?> |
| 1315 |
<div class="wrap"> |
| 1316 |
<div id="icon-plugins" class="icon32"><br/></div> |
| 1317 |
<h2><?php _e('Custom Field Template', 'custom-field-template'); ?></h2> |
| 1318 |
|
| 1319 |
<br class="clear"/> |
| 1320 |
|
| 1321 |
<div id="poststuff" style="position: relative; margin-top:10px;"> |
| 1322 |
<?php if ( empty($options['custom_field_template_disable_ad']) ) : ?><div style="width:75%; float:left;"><?php endif; ?> |
| 1323 |
<div class="postbox"> |
| 1324 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1325 |
<h3><?php _e('Custom Field Template Options', 'custom-field-template'); ?></h3> |
| 1326 |
<div class="inside"> |
| 1327 |
<form method="post"> |
| 1328 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1329 |
<tbody> |
| 1330 |
<?php |
| 1331 |
$cf_count = isset($options['custom_fields']) && is_array($options['custom_fields']) ? count($options['custom_fields'])+1 : 1; |
| 1332 |
for ( $i = 0; $i < $cf_count; $i++ ) { |
| 1333 |
?> |
| 1334 |
<tr><td> |
| 1335 |
<p><strong>TEMPLATE #<?php echo $i; ?></strong> |
| 1336 |
<label for="custom_field_template_disable[<?php echo $i; ?>]"><input type="checkbox" name="custom_field_template_disable[<?php echo $i; ?>]" id="custom_field_template_disable[<?php echo $i; ?>]" value="1" <?php if ( isset($options['custom_fields'][$i]['disable']) ) checked(1, $options['custom_fields'][$i]['disable']); ?> /> <?php _e('Disable', 'custom-field-template'); ?></label> |
| 1337 |
</p> |
| 1338 |
<p><label for="custom_field_template_title[<?php echo $i; ?>]"><?php echo sprintf(__('Template Title', 'custom-field-template'), $i); ?></label>:<br /> |
| 1339 |
<input type="text" name="custom_field_template_title[<?php echo $i; ?>]" id="custom_field_template_title[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['title']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['title'])); ?>" size="80" /></p> |
| 1340 |
<p><label for="custom_field_template_instruction[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Template Instruction', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1341 |
<textarea class="large-text" name="custom_field_template_instruction[<?php echo $i; ?>]" id="custom_field_template_instruction[<?php echo $i; ?>]" rows="5" cols="80"<?php if ( empty($options['custom_fields'][$i]['instruction']) ) : echo ' style="display:none;"'; endif; ?>><?php if ( isset($options['custom_fields'][$i]['instruction']) ) echo htmlspecialchars(stripcslashes($options['custom_fields'][$i]['instruction'])); ?></textarea></p> |
| 1342 |
<p><label for="custom_field_template_post_type[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Post Type', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1343 |
<span<?php if ( empty($options['custom_fields'][$i]['post_type']) ) : echo ' style="display:none;"'; endif; ?>> |
| 1344 |
<input type="radio" name="custom_field_template_post_type[<?php echo $i; ?>]" id="custom_field_template_post_type[<?php echo $i; ?>]" value=""<?php if ( !isset($options['custom_fields'][$i]['post_type']) ) : echo ' checked="checked"'; endif; ?> /> <?php _e('Both', 'custom-field-template'); ?> |
| 1345 |
<input type="radio" name="custom_field_template_post_type[<?php echo $i; ?>]" id="custom_field_template_post_type[<?php echo $i; ?>]" value="post"<?php if ( !empty($options['custom_fields'][$i]['post_type']) && $options['custom_fields'][$i]['post_type']=='post') : echo ' checked="checked"'; endif; ?> /> <?php _e('Post', 'custom-field-template'); ?> |
| 1346 |
<input type="radio" name="custom_field_template_post_type[<?php echo $i; ?>]" id="custom_field_template_post_type[<?php echo $i; ?>]" value="page"<?php if ( !empty($options['custom_fields'][$i]['post_type']) && $options['custom_fields'][$i]['post_type']=='page') : echo ' checked="checked"'; endif; ?> /> <?php _e('Page', 'custom-field-template'); ?></span></p> |
| 1347 |
<p><label for="custom_field_template_custom_post_type[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Custom Post Type (comma-deliminated)', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1348 |
<input type="text" name="custom_field_template_custom_post_type[<?php echo $i; ?>]" id="custom_field_template_custom_post_type[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['custom_post_type']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['custom_post_type'])); ?>" size="80"<?php if ( empty($options['custom_fields'][$i]['custom_post_type']) ) : echo ' style="display:none;"'; endif; ?> /></p> |
| 1349 |
<p><label for="custom_field_template_post[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Post ID (comma-deliminated)', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1350 |
<input type="text" name="custom_field_template_post[<?php echo $i; ?>]" id="custom_field_template_post[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['post']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['post'])); ?>" size="80"<?php if ( empty($options['custom_fields'][$i]['post']) ) : echo ' style="display:none;"'; endif; ?> /></p> |
| 1351 |
<p><label for="custom_field_template_category[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Category ID (comma-deliminated)', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1352 |
<input type="text" name="custom_field_template_category[<?php echo $i; ?>]" id="custom_field_template_category[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['category']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['category'])); ?>" size="80"<?php if ( empty($options['custom_fields'][$i]['category']) ) : echo ' style="display:none;"'; endif; ?> /></p> |
| 1353 |
<p><label for="custom_field_template_template_files[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Page Template file name(s) (comma-deliminated)', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1354 |
<input type="text" name="custom_field_template_template_files[<?php echo $i; ?>]" id="custom_field_template_template_files[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['template_files']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['template_files'])); ?>" size="80"<?php if ( empty($options['custom_fields'][$i]['template_files']) ) : echo ' style="display:none;"'; endif; ?> /></p> |
| 1355 |
<p><label for="custom_field_template_user_id[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('User ID (comma-deliminated)', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1356 |
<input type="text" name="custom_field_template_user_id[<?php echo $i; ?>]" id="custom_field_template_user_id[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['user_id']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['user_id'])); ?>" size="80"<?php if ( empty($options['custom_fields'][$i]['user_id']) ) : echo ' style="display:none;"'; endif; ?> /></p> |
| 1357 |
<p><label for="custom_field_template_user_login[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('User Login (comma-deliminated)', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1358 |
<input type="text" name="custom_field_template_user_login[<?php echo $i; ?>]" id="custom_field_template_user_login[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['user_login']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['user_login'])); ?>" size="80"<?php if ( empty($options['custom_fields'][$i]['user_login']) ) : echo ' style="display:none;"'; endif; ?> /></p> |
| 1359 |
<p><label for="custom_field_template_user_role[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('User Role (comma-deliminated)', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1360 |
<input type="text" name="custom_field_template_user_role[<?php echo $i; ?>]" id="custom_field_template_user_role[<?php echo $i; ?>]" value="<?php if ( isset($options['custom_fields'][$i]['user_role']) ) echo esc_attr(stripcslashes($options['custom_fields'][$i]['user_role'])); ?>" size="80"<?php if ( empty($options['custom_fields'][$i]['user_role']) ) : echo ' style="display:none;"'; endif; ?> /></p> |
| 1361 |
<p><label for="custom_field_template_format[<?php echo $i; ?>]"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().next().toggle();"><?php echo sprintf(__('Template Format', 'custom-field-template'), $i); ?></a></label>:<br /> |
| 1362 |
<select name="custom_field_template_format[<?php echo $i; ?>]" <?php if ( !isset($options['custom_fields'][$i]['format']) || !is_numeric($options['custom_fields'][$i]['format']) ) : echo ' style="display:none;"'; endif; ?>> |
| 1363 |
<option value=""></option> |
| 1364 |
<?php |
| 1365 |
if ( isset($options['shortcode_format']) ) $count = count($options['shortcode_format']); |
| 1366 |
else $count = 0; |
| 1367 |
for ($j=0;$j<$count;$j++) : |
| 1368 |
?> |
| 1369 |
<option value="<?php echo $j; ?>"<?php if ( isset($options['custom_fields'][$i]['format']) && is_numeric($options['custom_fields'][$i]['format']) ) selected($j, $options['custom_fields'][$i]['format']); ?>>FORMAT #<?php echo $j; ?></option> |
| 1370 |
<?php |
| 1371 |
endfor; |
| 1372 |
?> |
| 1373 |
</select></p> |
| 1374 |
<p><label for="custom_field_template_content[<?php echo $i; ?>]"><?php echo sprintf(__('Template Content', 'custom-field-template'), $i); ?></label>:<br /> |
| 1375 |
<textarea name="custom_field_template_content[<?php echo $i; ?>]" class="resizable large-text" id="custom_field_template_content[<?php echo $i; ?>]" rows="10" cols="80"><?php if ( isset($options['custom_fields'][$i]['content']) ) echo htmlspecialchars(stripcslashes($options['custom_fields'][$i]['content'])); ?></textarea></p> |
| 1376 |
</td></tr> |
| 1377 |
<?php |
| 1378 |
} |
| 1379 |
?> |
| 1380 |
<tr><td> |
| 1381 |
<p><input type="submit" name="custom_field_template_set_options_submit" value="<?php _e('Update Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1382 |
</td></tr> |
| 1383 |
</tbody> |
| 1384 |
</table> |
| 1385 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1386 |
</form> |
| 1387 |
</div> |
| 1388 |
</div> |
| 1389 |
|
| 1390 |
<div class="postbox closed"> |
| 1391 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1392 |
<h3><?php _e('Premium Settings', 'custom-field-template'); ?></h3> |
| 1393 |
<div class="inside"> |
| 1394 |
<form method="post"> |
| 1395 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1396 |
<tbody> |
| 1397 |
<tr><td> |
| 1398 |
<p><?php _e('Please <a href="https://www.wpcft.com/">purchase the premium code</a> in order to use following functionalities.', 'custom-field-template'); ?></p> |
| 1399 |
</td> |
| 1400 |
</tr> |
| 1401 |
<tr><td> |
| 1402 |
<p><label for="custom_field_template_premium_code"><?php _e('Premium Code', 'custom-field-template'); ?>: <input type="text" name="custom_field_template_premium_code" id="custom_field_template_premium_code" value="<?php echo !empty($options['custom_field_template_premium_code']) ? esc_attr($options['custom_field_template_premium_code']) : ''; ?>" class="large-text" /></label></p> |
| 1403 |
</td> |
| 1404 |
</tr> |
| 1405 |
<tr><td> |
| 1406 |
<p><?php _e('Custom Field Refinement Search', 'custom-field-template'); ?>:</p> |
| 1407 |
<?php |
| 1408 |
$args = [ |
| 1409 |
'public' => true, |
| 1410 |
'_builtin' => false |
| 1411 |
]; |
| 1412 |
$post_types = get_post_types( $args ); |
| 1413 |
$post_types = array_merge( ['post', 'page'], array_values( $post_types ) ); |
| 1414 |
foreach ( $post_types as $post_type ) : |
| 1415 |
?> |
| 1416 |
<p><?php echo $post_type; ?>: <select name="adminsearch[<?php echo $post_type; ?>]"> |
| 1417 |
<option value=""></option> |
| 1418 |
<?php |
| 1419 |
$cf_count = isset($options['custom_fields']) && is_array($options['custom_fields']) ? count($options['custom_fields']) : 1; |
| 1420 |
for ( $i = 0; $i < $cf_count; $i++ ) : |
| 1421 |
?> |
| 1422 |
<option value="<?php echo $i; ?>"<?php if ( isset( $options['premium_settings']['adminsearch'][$post_type] ) && $options['premium_settings']['adminsearch'][$post_type] == $i ) echo ' selected="selected"'; ?>>TEMPLATE #<?php echo $i; ?></option> |
| 1423 |
<?php |
| 1424 |
endfor; |
| 1425 |
?></select></p> |
| 1426 |
<?php |
| 1427 |
endforeach; |
| 1428 |
?> |
| 1429 |
</td> |
| 1430 |
</tr> |
| 1431 |
<tr><td> |
| 1432 |
<p><input type="submit" name="custom_field_template_premium_settings_submit" value="<?php _e('Update Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1433 |
</td></tr> |
| 1434 |
</tbody> |
| 1435 |
</table> |
| 1436 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1437 |
</form> |
| 1438 |
</div> |
| 1439 |
</div> |
| 1440 |
|
| 1441 |
<div class="postbox closed"> |
| 1442 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1443 |
<h3><?php _e('Global Settings', 'custom-field-template'); ?></h3> |
| 1444 |
<div class="inside"> |
| 1445 |
<form method="post"> |
| 1446 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1447 |
<tbody> |
| 1448 |
<?php |
| 1449 |
/* |
| 1450 |
<tr><td> |
| 1451 |
<p><label for="custom_field_template_use_multiple_insert"><?php _e('In case that you would like to insert multiple images at once in use of the custom field media buttons', 'custom-field-template'); ?></label>:<br /> |
| 1452 |
<input type="checkbox" name="custom_field_template_use_multiple_insert" id="custom_field_template_use_multiple_insert" value="1" <?php if ($options['custom_field_template_use_multiple_insert']) { echo 'checked="checked"'; } ?> /> <?php _e('Use multiple image inset', 'custom-field-template'); ?><br /><span style="color:#FF0000; font-weight:bold;"><?php _e('Caution:', 'custom-field-teplate'); ?> <?php _e('You need to edit `wp-admin/includes/media.php`. Delete or comment out the code in the function media_send_to_editor.', 'custom-field-template'); ?></span></p> |
| 1453 |
</td> |
| 1454 |
</tr> |
| 1455 |
*/ |
| 1456 |
?> |
| 1457 |
<tr><td> |
| 1458 |
<p><label for="custom_field_template_replace_keys_by_labels"><?php _e('In case that you would like to replace custom keys by labels if `label` is set', 'custom-field-template'); ?>:<br /> |
| 1459 |
<input type="checkbox" name="custom_field_template_replace_keys_by_labels" id="custom_field_template_replace_keys_by_labels" value="1" <?php if ( !empty($options['custom_field_template_replace_keys_by_labels']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Use labels in place of custom keys', 'custom-field-template'); ?></label></p> |
| 1460 |
</td></tr> |
| 1461 |
<tr><td> |
| 1462 |
<p><label for="custom_field_template_use_wpautop"><?php _e('In case that you would like to add p and br tags in textareas automatically', 'custom-field-template'); ?>:<br /> |
| 1463 |
<input type="checkbox" name="custom_field_template_use_wpautop" id="custom_field_template_use_wpautop" value="1" <?php if ( !empty($options['custom_field_template_use_wpautop']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Use wpautop function', 'custom-field-template'); ?></label></p> |
| 1464 |
</td> |
| 1465 |
</tr> |
| 1466 |
<tr><td> |
| 1467 |
<p><label for="custom_field_template_use_autosave"><?php _e('In case that you would like to save values automatically in switching templates', 'custom-field-template'); ?>:<br /> |
| 1468 |
<input type="checkbox" name="custom_field_template_use_autosave" id="custom_field_template_use_autosave" value="1" <?php if ( !empty($options['custom_field_template_use_autosave']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Use the auto save in switching templates', 'custom-field-template'); ?></label></p> |
| 1469 |
</td> |
| 1470 |
</tr> |
| 1471 |
<tr><td> |
| 1472 |
<p><label for="custom_field_template_use_disable_button"><?php _e('In case that you would like to disable input fields of the custom field template temporarily', 'custom-field-template'); ?>:<br /> |
| 1473 |
<input type="checkbox" name="custom_field_template_use_disable_button" id="custom_field_template_use_disable_button" value="1" <?php if ( !empty($options['custom_field_template_use_disable_button']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Use the `Disable` button. The default custom fields will be superseded.', 'custom-field-template'); ?></label></p> |
| 1474 |
</td> |
| 1475 |
</tr> |
| 1476 |
<tr><td> |
| 1477 |
<p><label for="custom_field_template_disable_initialize_button"><?php _e('In case that you would like to forbid to use the initialize button.', 'custom-field-template'); ?>:<br /> |
| 1478 |
<input type="checkbox" name="custom_field_template_disable_initialize_button" id="custom_field_template_disable_initialize_button" value="1" <?php if ( !empty($options['custom_field_template_disable_initialize_button']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Disable the initialize button', 'custom-field-template'); ?></label></p> |
| 1479 |
</td> |
| 1480 |
</tr> |
| 1481 |
<tr><td> |
| 1482 |
<p><label for="custom_field_template_disable_save_button"><?php _e('In case that you would like to forbid to use the save button.', 'custom-field-template'); ?>:<br /> |
| 1483 |
<input type="checkbox" name="custom_field_template_disable_save_button" id="custom_field_template_disable_save_button" value="1" <?php if ( !empty($options['custom_field_template_disable_save_button']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Disable the save button', 'custom-field-template'); ?></label></p> |
| 1484 |
</td> |
| 1485 |
</tr> |
| 1486 |
<tr><td> |
| 1487 |
<p><label for="custom_field_template_disable_default_custom_fields"><?php _e('In case that you would like to forbid to use the default custom fields.', 'custom-field-template'); ?>:<br /> |
| 1488 |
<input type="checkbox" name="custom_field_template_disable_default_custom_fields" id="custom_field_template_disable_default_custom_fields" value="1" <?php if ( !empty($options['custom_field_template_disable_default_custom_fields']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Disable the default custom fields', 'custom-field-template'); ?></label></p> |
| 1489 |
</td> |
| 1490 |
</tr> |
| 1491 |
<tr><td> |
| 1492 |
<p><label for="custom_field_template_disable_quick_edit"><?php _e('In case that you would like to forbid to use the quick edit.', 'custom-field-template'); ?>:<br /> |
| 1493 |
<input type="checkbox" name="custom_field_template_disable_quick_edit" id="custom_field_template_disable_quick_edit" value="1" <?php if ( !empty($options['custom_field_template_disable_quick_edit']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Disable the quick edit', 'custom-field-template'); ?></label></p> |
| 1494 |
</td> |
| 1495 |
</tr> |
| 1496 |
<tr><td> |
| 1497 |
<p><label for="custom_field_template_disable_admin_search"><?php _e('In case that you would like to forbid to use the admin search.', 'custom-field-template'); ?>:<br /> |
| 1498 |
<input type="checkbox" name="custom_field_template_disable_admin_search" id="custom_field_template_disable_admin_search" value="1" <?php if ( !empty($options['custom_field_template_disable_admin_search']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Disable the admin search', 'custom-field-template'); ?></label></p> |
| 1499 |
</td> |
| 1500 |
</tr> |
| 1501 |
<tr><td> |
| 1502 |
<p><label for="custom_field_template_disable_custom_field_column"><?php _e('In case that you would like to forbid to display the custom field column on the edit post list page.', 'custom-field-template'); ?>:<br /> |
| 1503 |
<input type="checkbox" name="custom_field_template_disable_custom_field_column" id="custom_field_template_disable_custom_field_column" value="1" <?php if ( !empty($options['custom_field_template_disable_custom_field_column']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Disable the custom field column (The quick edit also does not work.)', 'custom-field-template'); ?></label></p> |
| 1504 |
</td> |
| 1505 |
</tr> |
| 1506 |
<tr><td> |
| 1507 |
<p><label for="custom_field_template_replace_the_title"><?php _e('In case that you would like to replace the box title with the template title.', 'custom-field-template'); ?>:<br /> |
| 1508 |
<input type="checkbox" name="custom_field_template_replace_the_title" id="custom_field_template_replace_the_title" value="1" <?php if ( !empty($options['custom_field_template_replace_the_title']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Replace the box title', 'custom-field-template'); ?></label></p> |
| 1509 |
</td> |
| 1510 |
</tr> |
| 1511 |
<tr><td> |
| 1512 |
<p><label for="custom_field_template_deploy_box"><?php _e('In case that you would like to deploy the box in each template.', 'custom-field-template'); ?>:<br /> |
| 1513 |
<input type="checkbox" name="custom_field_template_deploy_box" id="custom_field_template_deploy_box" value="1" <?php if ( !empty($options['custom_field_template_deploy_box']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Deploy the box in each template', 'custom-field-template'); ?></label></p> |
| 1514 |
</td> |
| 1515 |
</tr> |
| 1516 |
<tr><td> |
| 1517 |
<p><label for="custom_field_template_widget_shortcode"><?php _e('In case that you would like to use the shortcode in the widget.', 'custom-field-template'); ?>:<br /> |
| 1518 |
<input type="checkbox" name="custom_field_template_widget_shortcode" id="custom_field_template_widget_shortcode" value="1" <?php if ( !empty($options['custom_field_template_widget_shortcode']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Use the shortcode in the widget', 'custom-field-template'); ?></label></p> |
| 1519 |
</td> |
| 1520 |
</tr> |
| 1521 |
<tr><td> |
| 1522 |
<p><label for="custom_field_template_excerpt_shortcode"><?php _e('In case that you would like to use the shortcode in the excerpt.', 'custom-field-template'); ?>:<br /> |
| 1523 |
<input type="checkbox" name="custom_field_template_excerpt_shortcode" id="custom_field_template_excerpt_shortcode" value="1" <?php if ( !empty($options['custom_field_template_excerpt_shortcode']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Use the shortcode in the excerpt', 'custom-field-template'); ?></label></p> |
| 1524 |
</td> |
| 1525 |
</tr> |
| 1526 |
<tr><td> |
| 1527 |
<p><label for="custom_field_template_use_validation"><?php _e('In case that you would like to use the jQuery validation.', 'custom-field-template'); ?>:<br /> |
| 1528 |
<input type="checkbox" name="custom_field_template_use_validation" id="custom_field_template_use_validation" value="1" <?php if ( !empty($options['custom_field_template_use_validation']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Use the jQuery validation', 'custom-field-template'); ?></label></p> |
| 1529 |
</td> |
| 1530 |
</tr> |
| 1531 |
<tr><td> |
| 1532 |
<?php |
| 1533 |
if ( !isset($options['custom_field_template_before_list']) ) $options['custom_field_template_before_list'] = '<ul>'; |
| 1534 |
if ( !isset($options['custom_field_template_after_list']) ) $options['custom_field_template_after_list'] = '</ul>'; |
| 1535 |
if ( !isset($options['custom_field_template_before_value']) ) $options['custom_field_template_before_value'] = '<li>'; |
| 1536 |
if ( !isset($options['custom_field_template_after_value']) ) $options['custom_field_template_after_value'] = '</li>'; |
| 1537 |
?> |
| 1538 |
<p><label for="custom_field_template_before_list"><?php _e('Text to place before every list which is called by the cft shortcode', 'custom-field-template'); ?></label>:<br /> |
| 1539 |
<input type="text" name="custom_field_template_before_list" id="custom_field_template_before_list" value="<?php echo esc_attr(stripcslashes($options['custom_field_template_before_list'])); ?>" /></p> |
| 1540 |
<p><label for="custom_field_template_after_list"><?php _e('Text to place after every list which is called by the cft shortcode', 'custom-field-template'); ?></label>:<br /> |
| 1541 |
<input type="text" name="custom_field_template_after_list" id="custom_field_template_after_list" value="<?php echo esc_attr(stripcslashes($options['custom_field_template_after_list'])); ?>" /></p> |
| 1542 |
<p><label for="custom_field_template_before_value"><?php _e('Text to place before every value which is called by the cft shortcode', 'custom-field-template'); ?></label>:<br /> |
| 1543 |
<input type="text" name="custom_field_template_before_value" id="custom_field_template_before_value" value="<?php echo esc_attr(stripcslashes($options['custom_field_template_before_value'])); ?>" /></p> |
| 1544 |
<p><label for="custom_field_template_after_value"><?php _e('Text to place after every value which is called by the cft shortcode', 'custom-field-template'); ?></label>:<br /> |
| 1545 |
<input type="text" name="custom_field_template_after_value" id="custom_field_template_after_value" value="<?php echo esc_attr(stripcslashes($options['custom_field_template_after_value'])); ?>" /></p> |
| 1546 |
</td> |
| 1547 |
</tr> |
| 1548 |
<tr><td> |
| 1549 |
<p><label for="custom_field_template_output_direct_meta"><?php _e('In case that you would like to output the direct meta in the cft shortcode (Enabled for admin user only)', 'custom-field-template'); ?>:<br /> |
| 1550 |
<input type="checkbox" name="custom_field_template_output_direct_meta" id="custom_field_template_output_direct_meta" value="1" <?php if ( !empty($options['custom_field_template_output_direct_meta']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Output the direct meta', 'custom-field-template'); ?></label></p> |
| 1551 |
</td> |
| 1552 |
</tr> |
| 1553 |
<tr><td> |
| 1554 |
<p><label for="custom_field_template_output_protected_meta"><?php _e('In case that you would like to output the protected meta in the cft shortcode', 'custom-field-template'); ?>:<br /> |
| 1555 |
<input type="checkbox" name="custom_field_template_output_protected_meta" id="custom_field_template_output_protected_meta" value="1" <?php if ( !empty($options['custom_field_template_output_protected_meta']) ) { echo 'checked="checked"'; } ?> /> <?php _e('Output the protected meta', 'custom-field-template'); ?></label></p> |
| 1556 |
</td> |
| 1557 |
</tr> |
| 1558 |
<tr><td> |
| 1559 |
<p><label for="custom_field_template_disable_ad"><?php _e('In case that you would like to hide the advertisement right column.', 'custom-field-template'); ?>:<br /> |
| 1560 |
<input type="checkbox" name="custom_field_template_disable_ad" id="custom_field_template_disable_ad" value="1" <?php if ( !empty($options['custom_field_template_disable_ad']) ) { echo 'checked="checked"'; } ?> /> <?php _e('I want to use a wider screen.', 'custom-field-template'); ?></label></p> |
| 1561 |
</td> |
| 1562 |
</tr> |
| 1563 |
<tr><td> |
| 1564 |
<p><label for="custom_field_template_disable_donation"><?php _e('In case that you would like to hide the donatione header notice.', 'custom-field-template'); ?>:<br /> |
| 1565 |
<input type="checkbox" name="custom_field_template_disable_donation" id="custom_field_template_disable_donation" value="1" <?php if ( !empty($options['custom_field_template_disable_donation']) ) { echo 'checked="checked"'; } ?> /> <?php _e('I have already donated.', 'custom-field-template'); ?></label></p> |
| 1566 |
</td> |
| 1567 |
</tr> |
| 1568 |
<tr><td> |
| 1569 |
<p><input type="submit" name="custom_field_template_global_settings_submit" value="<?php _e('Update Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1570 |
</td></tr> |
| 1571 |
</tbody> |
| 1572 |
</table> |
| 1573 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1574 |
</form> |
| 1575 |
</div> |
| 1576 |
</div> |
| 1577 |
|
| 1578 |
<div class="postbox closed"> |
| 1579 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1580 |
<h3><?php _e('ADMIN CSS', 'custom-field-template'); ?></h3> |
| 1581 |
<div class="inside"> |
| 1582 |
<form method="post"> |
| 1583 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1584 |
<tbody> |
| 1585 |
<tr><td> |
| 1586 |
<p><textarea name="custom_field_template_css" class="large-text resizable" id="custom_field_template_css" rows="10" cols="80"><?php if ( isset($options['css']) ) echo htmlspecialchars(stripcslashes($options['css'])); ?></textarea></p> |
| 1587 |
</td></tr> |
| 1588 |
<tr><td> |
| 1589 |
<p><input type="submit" name="custom_field_template_css_submit" value="<?php _e('Update Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1590 |
</td></tr> |
| 1591 |
</tbody> |
| 1592 |
</table> |
| 1593 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1594 |
</form> |
| 1595 |
</div> |
| 1596 |
</div> |
| 1597 |
|
| 1598 |
<div class="postbox closed"> |
| 1599 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1600 |
<h3><?php _e('[cft] and [cftsearch] Shortcode Format', 'custom-field-template'); ?></h3> |
| 1601 |
<div class="inside"> |
| 1602 |
<form method="post"> |
| 1603 |
<p><?php _e('For [cft], [key] will be converted into the value of [key].', 'custom-field-template'); ?><br /> |
| 1604 |
<?php _e('For [cftsearch], [key] will be converted into the input field.', 'custom-field-template'); ?></p> |
| 1605 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1606 |
<tbody> |
| 1607 |
<?php |
| 1608 |
if ( isset($options['shortcode_format']) ) $count = count($options['shortcode_format']); |
| 1609 |
else $count = 0; |
| 1610 |
for ($i=0;$i<$count+1;$i++) : |
| 1611 |
?> |
| 1612 |
<tr><th><strong>FORMAT #<?php echo $i; ?></strong></th></tr> |
| 1613 |
<tr><td> |
| 1614 |
<p><textarea name="custom_field_template_shortcode_format[<?php echo $i; ?>]" class="large-text resizable" rows="10" cols="80"><?php if ( isset($options['shortcode_format'][$i]) ) echo htmlspecialchars(stripcslashes($options['shortcode_format'][$i])); ?></textarea></p> |
| 1615 |
<p><label><input type="checkbox" name="custom_field_template_shortcode_format_use_php[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['shortcode_format_use_php'][$i]) ) { echo ' checked="checked"'; } ?> /> <?php _e('Use PHP', 'custom-field-template'); ?></label></p> |
| 1616 |
</td></tr> |
| 1617 |
<?php |
| 1618 |
endfor; |
| 1619 |
?> |
| 1620 |
<tr><td> |
| 1621 |
<p><input type="submit" name="custom_field_template_shortcode_format_submit" value="<?php _e('Update Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1622 |
</td></tr> |
| 1623 |
</tbody> |
| 1624 |
</table> |
| 1625 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1626 |
</form> |
| 1627 |
</div> |
| 1628 |
</div> |
| 1629 |
|
| 1630 |
<div class="postbox closed"> |
| 1631 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1632 |
<h3><?php _e('PHP CODE (Experimental Option)', 'custom-field-template'); ?></h3> |
| 1633 |
<div class="inside"> |
| 1634 |
<form method="post" onsubmit="return confirm('<?php _e('Are you sure to save PHP codes? Please do it at your own risk.', 'custom-field-template'); ?>');"> |
| 1635 |
<dl><dt><?php _e('For `text` and `textarea`, you must set $value as an string.', 'custom-field-template'); ?><br /> |
| 1636 |
ex. `text` and `textarea`:</dt><dd>$value = 'Yes we can.';</dd></dl> |
| 1637 |
<dl><dt><?php _e('For `checkbox`, `radio`, and `select`, you must set $values as an array.', 'custom-field-template'); ?><br /> |
| 1638 |
ex. `radio` and `select`:</dt><dd>$values = array('dog', 'cat', 'monkey'); $default = 'cat';</dd> |
| 1639 |
<dt>ex. `checkbox`:</dt><dd>$values = array('dog', 'cat', 'monkey'); $defaults = array('dog', 'cat');</dd></dl> |
| 1640 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1641 |
<tbody> |
| 1642 |
<?php |
| 1643 |
if ( isset($options['php']) ) $count = count($options['php']); |
| 1644 |
else $count = 0; |
| 1645 |
for ($i=0;$i<$count+1;$i++) : |
| 1646 |
?> |
| 1647 |
<tr><th><strong>CODE #<?php echo $i; ?></strong></th></tr> |
| 1648 |
<tr><td> |
| 1649 |
<p><textarea name="custom_field_template_php[]" class="large-text resizable" rows="10" cols="80"><?php if ( isset($options['php'][$i]) ) echo htmlspecialchars(stripcslashes($options['php'][$i])); ?></textarea></p> |
| 1650 |
</td></tr> |
| 1651 |
<?php |
| 1652 |
endfor; |
| 1653 |
?> |
| 1654 |
<tr><td> |
| 1655 |
<p><input type="submit" name="custom_field_template_php_submit" value="<?php _e('Update Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1656 |
</td></tr> |
| 1657 |
</tbody> |
| 1658 |
</table> |
| 1659 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1660 |
</form> |
| 1661 |
</div> |
| 1662 |
</div> |
| 1663 |
|
| 1664 |
<div class="postbox closed"> |
| 1665 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1666 |
<h3><?php _e('Auto Hook of `the_content()` (Experimental Option)', 'custom-field-template'); ?></h3> |
| 1667 |
<div class="inside"> |
| 1668 |
<form method="post"> |
| 1669 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1670 |
<tbody> |
| 1671 |
<?php |
| 1672 |
if ( isset($options['hook']) ) $count = count($options['hook']); |
| 1673 |
else $count = 0; |
| 1674 |
for ($i=0;$i<$count+1;$i++) : |
| 1675 |
?> |
| 1676 |
<tr><th><strong>HOOK #<?php echo $i; ?></strong></th></tr> |
| 1677 |
<tr><td> |
| 1678 |
<p><label for="custom_field_template_hook_position[<?php echo $i; ?>]"><?php echo sprintf(__('Position', 'custom-field-template'), $i); ?></label>:<br /> |
| 1679 |
<label><input type="radio" name="custom_field_template_hook_position[<?php echo $i; ?>]" value="1" <?php if( isset($options['hook'][$i]['position']) && $options['hook'][$i]['position']==1 ) echo ' checked="checked"'; ?> /> <?php _e('Before the content', 'custom-field-template'); ?></label> |
| 1680 |
<label><input type="radio" name="custom_field_template_hook_position[<?php echo $i; ?>]" value="3" <?php if( isset($options['hook'][$i]['position']) && $options['hook'][$i]['position']==3 ) echo ' checked="checked"'; ?> /> <?php _e('Before the more tag', 'custom-field-template'); ?></label> |
| 1681 |
<label><input type="radio" name="custom_field_template_hook_position[<?php echo $i; ?>]" value="0" <?php if( isset($options['hook'][$i]['position']) && $options['hook'][$i]['position']==0) echo ' checked="checked"'; ?> /> <?php _e('After the content', 'custom-field-template'); ?></label> |
| 1682 |
<label><input type="radio" name="custom_field_template_hook_position[<?php echo $i; ?>]" value="2" <?php if( isset($options['hook'][$i]['position']) && $options['hook'][$i]['position']==2) echo ' checked="checked"'; ?> /> <?php echo sprintf(__('Inside the content ([cfthook hook=%d])', 'custom-field-template'), $i); ?></label> |
| 1683 |
</p> |
| 1684 |
<p><label for="custom_field_template_hook_post_type[<?php echo $i; ?>]"><?php echo sprintf(__('Post Type', 'custom-field-template'), $i); ?></label>:<br /> |
| 1685 |
<label><input type="radio" name="custom_field_template_hook_post_type[<?php echo $i; ?>]" id="custom_field_template_hook_post_type[<?php echo $i; ?>]" value=""<?php if ( !isset($options['hook'][$i]['post_type']) ) : echo ' checked="checked"'; endif; ?> /> <?php _e('Both', 'custom-field-template'); ?></label> |
| 1686 |
<label><input type="radio" name="custom_field_template_hook_post_type[<?php echo $i; ?>]" id="custom_field_template_hook_post_type[<?php echo $i; ?>]" value="post"<?php if ( isset($options['hook'][$i]['post_type']) && $options['hook'][$i]['post_type']=='post') : echo ' checked="checked"'; endif; ?> /> <?php _e('Post', 'custom-field-template'); ?></label> |
| 1687 |
<label><input type="radio" name="custom_field_template_hook_post_type[<?php echo $i; ?>]" id="custom_field_template_hook_post_type[<?php echo $i; ?>]" value="page"<?php if ( isset($options['hook'][$i]['post_type']) && $options['hook'][$i]['post_type']=='page') : echo ' checked="checked"'; endif; ?> /> <?php _e('Page', 'custom-field-template'); ?></label></p> |
| 1688 |
<p><label for="custom_field_template_hook_custom_post_type[<?php echo $i; ?>]"><?php echo sprintf(__('Custom Post Type (comma-deliminated)', 'custom-field-template'), $i); ?></label>:<br /> |
| 1689 |
<input type="text" name="custom_field_template_hook_custom_post_type[<?php echo $i; ?>]" id="custom_field_template_hook_custom_post_type[<?php echo $i; ?>]" value="<?php if ( isset($options['hook'][$i]['custom_post_type']) ) echo esc_attr(stripcslashes($options['hook'][$i]['custom_post_type'])); ?>" size="80" /></p> |
| 1690 |
<p><label for="custom_field_template_hook_category[<?php echo $i; ?>]"><?php echo sprintf(__('Category ID (comma-deliminated)', 'custom-field-template'), $i); ?></label>:<br /> |
| 1691 |
<input type="text" name="custom_field_template_hook_category[<?php echo $i; ?>]" id="custom_field_template_hook_category[<?php echo $i; ?>]" value="<?php if ( isset($options['hook'][$i]['category']) ) echo esc_attr(stripcslashes($options['hook'][$i]['category'])); ?>" size="80" /></p> |
| 1692 |
<p><label for="custom_field_template_hook_content[<?php echo $i; ?>]"><?php echo sprintf(__('Content', 'custom-field-template'), $i); ?></label>:<br /><textarea name="custom_field_template_hook_content[<?php echo $i; ?>]" class="large-text resizable" rows="5" cols="80"><?php if ( isset($options['hook'][$i]['content']) ) echo htmlspecialchars(stripcslashes($options['hook'][$i]['content'])); ?></textarea></p> |
| 1693 |
<p><label><input type="checkbox" name="custom_field_template_hook_use_php[<?php echo $i; ?>]" id="custom_field_template_hook_use_php[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['hook'][$i]['use_php']) ) { echo ' checked="checked"'; } ?> /> <?php _e('Use PHP', 'custom-field-template'); ?></label></p> |
| 1694 |
<p><label><input type="checkbox" name="custom_field_template_hook_feed[<?php echo $i; ?>]" id="custom_field_template_hook_feed[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['hook'][$i]['feed']) ) { echo ' checked="checked"'; } ?> /> <?php _e('Apply to feeds', 'custom-field-template'); ?></label></p> |
| 1695 |
<p><label><input type="checkbox" name="custom_field_template_hook_excerpt[<?php echo $i; ?>]" id="custom_field_template_hook_excerpt[<?php echo $i; ?>]" value="1" <?php if ( !empty($options['hook'][$i]['excerpt']) ) { echo ' checked="checked"'; } ?> /> <?php _e('Apply also to excerpts', 'custom-field-template'); ?></label></p> |
| 1696 |
</td></tr> |
| 1697 |
<?php |
| 1698 |
endfor; |
| 1699 |
?> |
| 1700 |
<tr><td> |
| 1701 |
<p><input type="submit" name="custom_field_template_hook_submit" value="<?php _e('Update Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1702 |
</td></tr> |
| 1703 |
</tbody> |
| 1704 |
</table> |
| 1705 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1706 |
</form> |
| 1707 |
</div> |
| 1708 |
</div> |
| 1709 |
|
| 1710 |
<div class="postbox closed"> |
| 1711 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1712 |
<h3><?php _e('Rebuild Value Counts', 'custom-field-template'); ?></h3> |
| 1713 |
<div class="inside"> |
| 1714 |
<form method="post" onsubmit="return confirm('<?php _e('Are you sure to rebuild all value counts?', 'custom-field-template'); ?>');"> |
| 1715 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1716 |
<tbody> |
| 1717 |
<tr><td> |
| 1718 |
<p><?php _e('Value Counts are used for temporarily saving how many values in each key. Set `valueCount = true` into fields.', 'custom-field-template'); ?></p> |
| 1719 |
<p>global $custom_field_template;<br /> |
| 1720 |
$value_count = $custom_field_template->get_value_count();<br /> |
| 1721 |
echo $value_count[$meta_key][$meta_value];</p> |
| 1722 |
<p><input type="submit" name="custom_field_template_rebuild_value_counts_submit" value="<?php _e('Rebuild Value Counts »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1723 |
</td></tr> |
| 1724 |
</tbody> |
| 1725 |
</table> |
| 1726 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1727 |
</form> |
| 1728 |
</div> |
| 1729 |
</div> |
| 1730 |
|
| 1731 |
<!-- |
| 1732 |
<div class="postbox closed"> |
| 1733 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1734 |
<h3><?php _e('Rebuild Tags', 'custom-field-template'); ?></h3> |
| 1735 |
<div class="inside"> |
| 1736 |
<form method="post" onsubmit="return confirm('<?php _e('Are you sure to rebuild tags?', 'custom-field-template'); ?>');"> |
| 1737 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1738 |
<tbody> |
| 1739 |
<tr><td> |
| 1740 |
<p><input type="submit" name="custom_field_template_rebuild_tags_submit" value="<?php _e('Rebuild Tags »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1741 |
</td></tr> |
| 1742 |
</tbody> |
| 1743 |
</table> |
| 1744 |
</form> |
| 1745 |
</div> |
| 1746 |
</div> |
| 1747 |
//--> |
| 1748 |
|
| 1749 |
<div class="postbox closed"> |
| 1750 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1751 |
<h3><?php _e('Option List', 'custom-field-template'); ?></h3> |
| 1752 |
<div class="inside"> |
| 1753 |
ex.<br /> |
| 1754 |
[Plan]<br /> |
| 1755 |
type = textfield<br /> |
| 1756 |
size = 35<br /> |
| 1757 |
hideKey = true<br /> |
| 1758 |
|
| 1759 |
<table class="widefat" style="margin:10px 0 5px 0;"> |
| 1760 |
<thead> |
| 1761 |
<tr> |
| 1762 |
<th>type</th><th>text or textfield</th><th>checkbox</th><th>radio</th><th>select</th><th>textarea</th><th>file</th> |
| 1763 |
</tr> |
| 1764 |
</thead> |
| 1765 |
<tbody> |
| 1766 |
<tr> |
| 1767 |
<th>hideKey</th><td>hideKey = true</td><td>hideKey = true</td><td>hideKey = true</td><td>hideKey = true</td><td>hideKey = true</td><td>hideKey = true</td> |
| 1768 |
</tr> |
| 1769 |
<tr> |
| 1770 |
<th>label</th><td>label = ABC</td><td>label = DEF</td><td>label = GHI</td><td>label = JKL</td><td>label = MNO</td><td>label = PQR</td> |
| 1771 |
</tr> |
| 1772 |
<tr> |
| 1773 |
<th>size</th><td>size = 30</td><td></td><td></td><td></td><td></td><td>size = 30</td> |
| 1774 |
</tr> |
| 1775 |
<tr> |
| 1776 |
<th>value</th><td></td><td>value = apple # orange # banana</td><td>value = apple # orange # banana</td><td>value = apple # orange # banana</td><td></td> |
| 1777 |
<td></td> |
| 1778 |
</tr> |
| 1779 |
<tr> |
| 1780 |
<th>valueLabel</th><td></td><td>valueLabel = apples # oranges # bananas</td><td>valueLabel = apples # oranges # bananas</td><td>valueLabel = apples # oranges # bananas</td><td></td> |
| 1781 |
<td></td> |
| 1782 |
</tr> |
| 1783 |
<tr> |
| 1784 |
<th>default</th><td>default = orange</td><td>default = orange # banana</td><td>default = orange</td><td>default = orange</td><td>default = orange</td><td></td> |
| 1785 |
</tr> |
| 1786 |
<tr> |
| 1787 |
<th>clearButton</th><td></td><td></td><td>clearButton = true</td><td></td><td></td><td></td> |
| 1788 |
</tr> |
| 1789 |
<tr> |
| 1790 |
<th>selectLabel</th><td></td><td></td><td></td><td>selectLabel = Select a fruit</td><td></td><td></td> |
| 1791 |
</tr> |
| 1792 |
<tr> |
| 1793 |
<th>rows</th><td></td><td></td><td></td><td></td><td>rows = 4</td><td></td> |
| 1794 |
</tr> |
| 1795 |
<tr> |
| 1796 |
<th>cols</th><td></td><td></td><td></td><td></td><td>cols = 40</td><td></td> |
| 1797 |
</tr> |
| 1798 |
<tr> |
| 1799 |
<th>wrap</th><td></td><td></td><td></td><td></td><td>wrap = off</td><td></td> |
| 1800 |
</tr> |
| 1801 |
<tr> |
| 1802 |
<th>tinyMCE</th><td></td><td></td><td></td><td></td><td>tinyMCE = true</td><td></td> |
| 1803 |
</tr> |
| 1804 |
<tr> |
| 1805 |
<th>htmlEditor</th><td></td><td></td><td></td><td></td><td>htmlEditor = true</td><td></td> |
| 1806 |
</tr> |
| 1807 |
<tr> |
| 1808 |
<th>date</th><td>date = true</td><td></td><td></td><td></td><td></td><td></td> |
| 1809 |
</tr> |
| 1810 |
<tr> |
| 1811 |
<th>dateFirstDayOfWeek</th><td>dateFirstDayOfWeek = 0</td><td></td><td></td><td></td><td></td><td></td> |
| 1812 |
</tr> |
| 1813 |
<tr> |
| 1814 |
<th>dateFormat</th><td>dateFormat = yyyy/mm/dd</td><td></td><td></td><td></td><td></td><td></td> |
| 1815 |
</tr> |
| 1816 |
<tr> |
| 1817 |
<th>startDate</th><td>startDate = '1970/01/01'</td><td></td><td></td><td></td><td></td><td></td> |
| 1818 |
</tr> |
| 1819 |
<tr> |
| 1820 |
<th>endDate</th><td>endDate = (new Date()).asString()</td><td></td><td></td><td></td><td></td><td></td> |
| 1821 |
</tr> |
| 1822 |
<tr> |
| 1823 |
<th>readOnly</th><td>readOnly = true</td><td></td><td></td><td></td><td></td><td></td> |
| 1824 |
</tr> |
| 1825 |
<tr> |
| 1826 |
<th>mediaButton</th><td></td><td></td><td></td><td></td><td>mediaButton = true</td><td></td> |
| 1827 |
</tr> |
| 1828 |
<tr> |
| 1829 |
<th>mediaOffImage</th><td></td><td></td><td></td><td></td><td>mediaOffImage = true</td><td></td> |
| 1830 |
</tr> |
| 1831 |
<tr> |
| 1832 |
<th>mediaOffVideo</th><td></td><td></td><td></td><td></td><td>mediaOffVideo = true</td><td></td> |
| 1833 |
</tr> |
| 1834 |
<tr> |
| 1835 |
<th>mediaOffAudio</th><td></td><td></td><td></td><td></td><td>mediaOffAudio = true</td><td></td> |
| 1836 |
</tr> |
| 1837 |
<tr> |
| 1838 |
<th>mediaOffMedia</th><td></td><td></td><td></td><td></td><td>mediaOffMedia = true</td><td></td> |
| 1839 |
</tr> |
| 1840 |
<tr> |
| 1841 |
<th>relation</th><td></td><td></td><td></td><td></td><td></td><td>relation = true</td> |
| 1842 |
</tr> |
| 1843 |
<tr> |
| 1844 |
<th>mediaLibrary</th><td></td><td></td><td></td><td></td><td></td><td>mediaLibrary = true</td> |
| 1845 |
</tr> |
| 1846 |
<tr> |
| 1847 |
<th>mediaPicker</th><td></td><td></td><td></td><td></td><td></td><td>mediaPicker = true</td> |
| 1848 |
</tr> |
| 1849 |
<tr> |
| 1850 |
<th>mediaRemove</th><td></td><td></td><td></td><td></td><td></td><td>mediaRemove = true</td> |
| 1851 |
</tr> |
| 1852 |
<tr> |
| 1853 |
<th>code</th><td>code = 0</td><td>code = 0</td><td>code = 0</td><td>code = 0</td><td>code = 0</td><td></td> |
| 1854 |
</tr> |
| 1855 |
<tr> |
| 1856 |
<th>editCode</th><td>editCode = 0</td><td>editCode = 0</td><td>editCode = 0</td><td>editCode = 0</td><td>editCode = 0</td><td>editCode = 0</td> |
| 1857 |
</tr> |
| 1858 |
<tr> |
| 1859 |
<th>level</th><td>level = 1</td><td>level = 3</td><td>level = 5</td><td>level = 7</td><td>level = 9</td><td>level = 10</td> |
| 1860 |
</tr> |
| 1861 |
<tr> |
| 1862 |
<th>insertTag</th><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td>insertTag = true</td><td></td> |
| 1863 |
</tr> |
| 1864 |
<tr> |
| 1865 |
<th>tagName</th><td>tagName = movie_tag</td><td>tagName = book_tag</td><td>tagName = img_tag</td><td>tagName = dvd_tag</td><td>tagName = bd_tag</td><td></td> |
| 1866 |
</tr> |
| 1867 |
<tr> |
| 1868 |
<th>output</th><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td><td>output = true</td><td></td> |
| 1869 |
</tr> |
| 1870 |
<tr> |
| 1871 |
<th>outputCode</th><td>outputCode = 0</td><td>outputCode = 0</td><td>outputCode = 0</td><td>outputCode = 0</td><td>outputCode = 0</td><td></td> |
| 1872 |
</tr> |
| 1873 |
<tr> |
| 1874 |
<th>outputNone</th><td>outputNone = No Data</td><td>outputNone = No Data</td><td>outputNone = No Data</td><td>outputNone = No Data</td><td>outputNone = No Data</td><td></td> |
| 1875 |
</tr> |
| 1876 |
<tr> |
| 1877 |
<th>singleList</th><td>singleList = true</td><td>singleList = true</td><td>singleList = true</td><td>singleList = true</td><td>singleList = true</td><td></td> |
| 1878 |
</tr> |
| 1879 |
<tr> |
| 1880 |
<th>shortCode</th><td>shortCode = true</td><td>shortCode = true</td><td>shortCode = true</td><td>shortCode = true</td><td>shortCode = true</td><td></td> |
| 1881 |
</tr> |
| 1882 |
<tr> |
| 1883 |
<th>multiple</th><td>multiple = true</td><td></td><td>multiple = true</td><td>multiple = true</td><td>multiple = true</td><td>multiple = true</td> |
| 1884 |
</tr> |
| 1885 |
<tr> |
| 1886 |
<th>startNum</th><td>startNum = 5</td><td></td><td>startNum = 5</td><td>startNum = 5</td><td>startNum = 5</td><td>startNum = 5</td> |
| 1887 |
</tr> |
| 1888 |
<tr> |
| 1889 |
<th>endNum</th><td>endNum = 10</td><td></td><td>endNum = 10</td><td>endNum = 10</td><td>endNum = 10</td><td>endNum = 10</td> |
| 1890 |
</tr> |
| 1891 |
<tr> |
| 1892 |
<th>multipleButton</th><td>multipleButton = true</td><td></td><td>multipleButton = true</td><td>multipleButton = true</td><td>multipleButton = true</td><td>multipleButton = true</td> |
| 1893 |
</tr> |
| 1894 |
<tr> |
| 1895 |
<th>blank</th><td>blank = true</td><td>blank = true</td><td>blank = true</td><td>blank = true</td><td>blank = true</td><td>blank = true</td> |
| 1896 |
</tr> |
| 1897 |
<tr> |
| 1898 |
<th>sort</th><td>sort = asc</td><td>sort = desc</td><td>sort = asc</td><td>sort = desc</td><td>sort = asc</td><td></td> |
| 1899 |
</tr> |
| 1900 |
<tr> |
| 1901 |
<th>search</th><td>search = true</td><td>search = true</td><td>search = true</td><td>search = true</td><td>search = true</td> |
| 1902 |
</tr> |
| 1903 |
<tr> |
| 1904 |
<th>class</th><td>class = text</td><td>class = checkbox</td><td>class = radio</td><td>class = select</td><td>class = textarea</td><td>class = file</td> |
| 1905 |
</tr> |
| 1906 |
<tr> |
| 1907 |
<th>style</th><td>style = color:#FF0000;</td><td>style = color:#FF0000;</td><td>style = color:#FF0000;</td><td>style = color:#FF0000;</td><td>style = color:#FF0000;</td><td>style = color:#FF0000;</td> |
| 1908 |
</tr> |
| 1909 |
<tr> |
| 1910 |
<th>before</th><td>before = abcde</td><td></td><td>before = abcde</td><td>before = abcde</td><td>before = abcde</td><td>before = abcde</td> |
| 1911 |
</tr> |
| 1912 |
<tr> |
| 1913 |
<th>after</th><td>after = abcde</td><td></td><td>after = abcde</td><td>after = abcde</td><td>after = abcde</td><td>after = abcde</td> |
| 1914 |
</tr> |
| 1915 |
<tr> |
| 1916 |
<th>valueCount</th><td>valueCount = true</td><td>valueCount = true</td><td>valueCount = true</td><td>valueCount = true</td><td>valueCount = true</td><td></td> |
| 1917 |
</tr> |
| 1918 |
<tr> |
| 1919 |
<th>JavaScript Event Handlers</th><td>onclick = alert('ok');</td><td>onchange = alert('ok');</td><td>onchange = alert('ok');</td><td>onchange = alert('ok');</td><td>onfocus = alert('ok');</td><td></td> |
| 1920 |
</tr> |
| 1921 |
</tbody> |
| 1922 |
</table> |
| 1923 |
</div> |
| 1924 |
</div> |
| 1925 |
|
| 1926 |
<div class="postbox closed"> |
| 1927 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1928 |
<h3><?php _e('Export Options', 'custom-field-template'); ?></h3> |
| 1929 |
<div class="inside"> |
| 1930 |
<form method="post"> |
| 1931 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1932 |
<tbody> |
| 1933 |
<tr><td> |
| 1934 |
<p><input type="submit" name="custom_field_template_export_options_submit" value="<?php _e('Export Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1935 |
</td></tr> |
| 1936 |
</tbody> |
| 1937 |
</table> |
| 1938 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1939 |
</form> |
| 1940 |
</div> |
| 1941 |
</div> |
| 1942 |
|
| 1943 |
<div class="postbox closed"> |
| 1944 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1945 |
<h3><?php _e('Import Options', 'custom-field-template'); ?></h3> |
| 1946 |
<div class="inside"> |
| 1947 |
<form method="post" enctype="multipart/form-data" onsubmit="return confirm('<?php _e('Are you sure to import options? Options you set will be overwritten.', 'custom-field-template'); ?>');"> |
| 1948 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1949 |
<tbody> |
| 1950 |
<tr><td> |
| 1951 |
<p><input type="file" name="cftfile" /> <input type="submit" name="custom_field_template_import_options_submit" value="<?php _e('Import Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1952 |
</td></tr> |
| 1953 |
</tbody> |
| 1954 |
</table> |
| 1955 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1956 |
</form> |
| 1957 |
</div> |
| 1958 |
</div> |
| 1959 |
|
| 1960 |
<div class="postbox closed"> |
| 1961 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1962 |
<h3><?php _e('Reset Options', 'custom-field-template'); ?></h3> |
| 1963 |
<div class="inside"> |
| 1964 |
<form method="post" onsubmit="return confirm('<?php _e('Are you sure to reset options? Options you set will be reset to the default settings.', 'custom-field-template'); ?>');"> |
| 1965 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1966 |
<tbody> |
| 1967 |
<tr><td> |
| 1968 |
<p><input type="submit" name="custom_field_template_reset_options_submit" value="<?php _e('Reset Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1969 |
</td></tr> |
| 1970 |
</tbody> |
| 1971 |
</table> |
| 1972 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1973 |
</form> |
| 1974 |
</div> |
| 1975 |
</div> |
| 1976 |
|
| 1977 |
<div class="postbox closed"> |
| 1978 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1979 |
<h3><?php _e('Delete Options', 'custom-field-template'); ?></h3> |
| 1980 |
<div class="inside"> |
| 1981 |
<form method="post" onsubmit="return confirm('<?php _e('Are you sure to delete options? Options you set will be deleted.', 'custom-field-template'); ?>');"> |
| 1982 |
<table class="form-table" style="margin-bottom:5px;"> |
| 1983 |
<tbody> |
| 1984 |
<tr><td> |
| 1985 |
<p><input type="submit" name="custom_field_template_delete_options_submit" value="<?php _e('Delete Options »', 'custom-field-template'); ?>" class="button-primary" /></p> |
| 1986 |
</td></tr> |
| 1987 |
</tbody> |
| 1988 |
</table> |
| 1989 |
<?php wp_nonce_field( 'cft', '_wpnonce', true, true ); ?> |
| 1990 |
</form> |
| 1991 |
</div> |
| 1992 |
</div> |
| 1993 |
</div> |
| 1994 |
|
| 1995 |
<?php if ( empty($options['custom_field_template_disable_ad']) ) : ?> |
| 1996 |
<div style="width:24%; float:right;"> |
| 1997 |
<div class="postbox" style="min-width:200px;"> |
| 1998 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 1999 |
<h3><?php _e('Donation', 'custom-field-template'); ?></h3> |
| 2000 |
<div class="inside"> |
| 2001 |
<p><?php _e('If you liked this plugin, please make a donation via paypal! Any amount is welcome. Your support is much appreciated.', 'custom-field-template'); ?></p> |
| 2002 |
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="text-align:center;" target="_blank"> |
| 2003 |
<input type="hidden" name="cmd" value="_s-xclick"> |
| 2004 |
<input type="hidden" name="hosted_button_id" value="WN7Y2442JPRU6"> |
| 2005 |
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" border="0" name="submit" alt="PayPal"> |
| 2006 |
</form> |
| 2007 |
</div> |
| 2008 |
</div> |
| 2009 |
|
| 2010 |
<div class="postbox" style="min-width:200px;"> |
| 2011 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 2012 |
<h3><?php _e('Custom Field Template Manual', 'custom-field-template'); ?></h3> |
| 2013 |
<div class="inside"> |
| 2014 |
<p><?php _e( 'We have finally published a manual site for the custom field template plugin. You can also use the custom field refinement search for posts in the admin panel. Please check here.', 'custom-field-template' ); ?></p> |
| 2015 |
<p style="text-align:center"><a href="https://www.wpcft.com/" target="_blank"><?php _e('Custom Field Template Manual', 'custom-field-template'); ?></a><br /><?php _e('For English', 'custom-field-template'); ?></p> |
| 2016 |
</div> |
| 2017 |
</div> |
| 2018 |
|
| 2019 |
<?php |
| 2020 |
if ( $locale == 'ja' ) : |
| 2021 |
?> |
| 2022 |
<div class="postbox" style="min-width:200px;"> |
| 2023 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 2024 |
<h3><?php _e('Custom Field Template Manual', 'custom-field-template'); ?></h3> |
| 2025 |
<div class="inside"> |
| 2026 |
<p><?php _e('Do you have any trouble with the plugin setup? Please visit the following manual site.', 'custom-field-template'); ?></p> |
| 2027 |
<p style="text-align:center"><a href="http://ja.wpcft.com/" target="_blank"><?php _e('Custom Field Template Manual', 'custom-field-template'); ?></a></p> |
| 2028 |
</div> |
| 2029 |
</div> |
| 2030 |
|
| 2031 |
<div class="postbox" style="min-width:200px;"> |
| 2032 |
<div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div> |
| 2033 |
<h3><?php _e('CMS x WP', 'custom-field-template'); ?></h3> |
| 2034 |
<div class="inside"> |
| 2035 |
<p><?php _e('There are much more plugins which are useful for developing business websites such as membership sites or ec sites. You could totally treat WordPress as CMS by use of CMS x WP plugins.', 'custom-field-template'); ?></p> |
| 2036 |
<p style="text-align:center"><a href="https://www.cmswp.jp/" target="_blank"><img src="<?php echo get_option('siteurl') . '/' . PLUGINDIR . '/' . $plugin_dir . '/js/'; ?>cmswp.jpg" width="125" height="125" alt="CMSxWP" /></a><br /><a href="https://www.cmswp.jp/" target="_blank"><?php _e('WordPress plugin sales site: CMS x WP', 'custom-field-template'); ?></a></p> |
| 2037 |
</div> |
| 2038 |
</div> |
| 2039 |
<?php |
| 2040 |
endif; |
| 2041 |
?> |
| 2042 |
</div> |
| 2043 |
<?php endif; ?> |
| 2044 |
|
| 2045 |
<script type="text/javascript"> |
| 2046 |
// <![CDATA[ |
| 2047 |
<?php if ( version_compare( substr($wp_version, 0, 3), '2.7', '<' ) ) { ?> |
| 2048 |
jQuery('.postbox h3').prepend('<a class="togbox">+</a> '); |
| 2049 |
<?php } ?> |
| 2050 |
jQuery('.postbox div.handlediv').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); } ); |
| 2051 |
jQuery('.postbox h3').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); } ); |
| 2052 |
jQuery('.postbox.close-me').each(function(){ |
| 2053 |
jQuery(this).addClass("closed"); |
| 2054 |
}); |
| 2055 |
//--> |
| 2056 |
</script> |
| 2057 |
|
| 2058 |
</div> |
| 2059 |
<?php |
| 2060 |
} |
| 2061 |
|
| 2062 |
function sanitize_name( $name ) { |
| 2063 |
$name = sanitize_title( $name ); |
| 2064 |
$name = str_replace( '-', '_', $name ); |
| 2065 |
|
| 2066 |
return $name; |
| 2067 |
} |
| 2068 |
|
| 2069 |
function sanitize_datepicker_date_expression( $value ) { |
| 2070 |
$value = trim( stripcslashes( (string) $value ) ); |
| 2071 |
if ( $value === '' ) return ''; |
| 2072 |
|
| 2073 |
if ( preg_match( '/^([\'"])(.*)\1$/s', $value, $matches ) ) : |
| 2074 |
if ( preg_match( '/[\r\n]/', $matches[2] ) ) return ''; |
| 2075 |
return wp_json_encode( $matches[2], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); |
| 2076 |
endif; |
| 2077 |
|
| 2078 |
if ( preg_match( '/^[0-9]{4}[\/.-][0-9]{1,2}[\/.-][0-9]{1,2}$/', $value ) ) : |
| 2079 |
return wp_json_encode( $value, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); |
| 2080 |
endif; |
| 2081 |
|
| 2082 |
if ( preg_match( '/^(?:\(?\s*new\s+Date\s*\(\s*\)\s*\)?|Date\.today\s*\(\s*\))(?:\s*\.\s*addDays\s*\(\s*-?[0-9]+\s*\))?\s*\.\s*asString\s*\(\s*\)$/', $value ) ) : |
| 2083 |
return $value; |
| 2084 |
endif; |
| 2085 |
|
| 2086 |
return ''; |
| 2087 |
} |
| 2088 |
|
| 2089 |
function sanitize_integer_list( $values ) { |
| 2090 |
$values = is_array( $values ) ? $values : explode( ',', (string) $values ); |
| 2091 |
$values = array_filter( array_map( 'absint', $values ) ); |
| 2092 |
return array_values( array_unique( $values ) ); |
| 2093 |
} |
| 2094 |
|
| 2095 |
function get_custom_fields( $id ) { |
| 2096 |
$options = $this->get_custom_field_template_data(); |
| 2097 |
|
| 2098 |
if ( empty($options['custom_fields'][$id]) ) |
| 2099 |
return null; |
| 2100 |
|
| 2101 |
$custom_fields = $this->parse_ini_str( $options['custom_fields'][$id]['content'], true ); |
| 2102 |
return $custom_fields; |
| 2103 |
} |
| 2104 |
|
| 2105 |
function make_textfield( $name, $sid, $data, $post_id ) { |
| 2106 |
$cftnum = $size = $default = $hideKey = $label = $code = $class = $style = $before = $after = $maxlength = $multipleButton = $date = $dateFirstDayOfWeek = $dateFormat = $startDate = $endDate = $readOnly = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = ''; |
| 2107 |
$hide = $addfield = $out = $out_key = $out_value = ''; |
| 2108 |
extract($data); |
| 2109 |
$options = $this->get_custom_field_template_data(); |
| 2110 |
|
| 2111 |
$name = stripslashes($name); |
| 2112 |
|
| 2113 |
$title = $name; |
| 2114 |
$name = $this->sanitize_name( $name ); |
| 2115 |
$name_id = preg_replace( '/%/', '', (string) $name ); |
| 2116 |
|
| 2117 |
if ( isset($code) && is_numeric($code) ) : |
| 2118 |
eval(stripcslashes($options['php'][$code])); |
| 2119 |
endif; |
| 2120 |
|
| 2121 |
if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false; |
| 2122 |
|
| 2123 |
if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) { |
| 2124 |
$value = $this->get_post_meta( $post_id, $title, false ); |
| 2125 |
if ( !empty($value) && is_array($value) ) { |
| 2126 |
$ct_value = count($value); |
| 2127 |
$value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : ''; |
| 2128 |
} |
| 2129 |
} else { |
| 2130 |
$value = stripslashes($default); |
| 2131 |
} |
| 2132 |
if ( empty($ct_value) ) : |
| 2133 |
$ct_value = !empty($startNum) ? $startNum-1 : 1; |
| 2134 |
endif; |
| 2135 |
|
| 2136 |
if ( isset($enforced_value) ) : |
| 2137 |
$value = $enforced_value; |
| 2138 |
endif; |
| 2139 |
|
| 2140 |
if ( isset($hideKey) && $hideKey == true ) $hide = ' class="hideKey"'; |
| 2141 |
if ( !empty($class) && $date == true ) $class = ' class="' . $class . ' datePicker"'; |
| 2142 |
elseif ( empty($class) && isset($date) && $date == true ) $class = ' class="datePicker"'; |
| 2143 |
elseif ( !empty($class) ) $class = ' class="' . $class . '"'; |
| 2144 |
if ( !empty($style) ) $style = ' style="' . $style . '"'; |
| 2145 |
if ( !empty($maxlength) ) $maxlength = ' maxlength="' . $maxlength . '"'; |
| 2146 |
if ( !empty($readOnly) ) $readOnly = ' readonly="readonly"'; |
| 2147 |
|
| 2148 |
if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2149 |
$title = wp_kses_post( stripcslashes($label) ); |
| 2150 |
|
| 2151 |
$event = array('onclick' => $onclick, 'ondblclick' => $ondblclick, 'onkeydown' => $onkeydown, 'onkeypress' => $onkeypress, 'onkeyup' => $onkeyup, 'onmousedown' => $onmousedown, 'onmouseup' => $onmouseup, 'onmouseover' => $onmouseover, 'onmouseout' => $onmouseout, 'onmousemove' => $onmousemove, 'onfocus' => $onfocus, 'onblur' => $onblur, 'onchange' => $onchange, 'onselect' => $onselect); |
| 2152 |
$event_output = ""; |
| 2153 |
foreach($event as $key => $val) : |
| 2154 |
if ( $val ) |
| 2155 |
$event_output .= " " . $key . '="' . esc_attr(stripcslashes(trim($val))) . '"'; |
| 2156 |
endforeach; |
| 2157 |
|
| 2158 |
if ( isset($multipleButton) && $multipleButton == true && $date != true && $ct_value == $cftnum ) : |
| 2159 |
$addfield .= '<div style="margin-top:-1em;">'; |
| 2160 |
$addfield .= '<a href="#clear" onclick="jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent()).find('."'input'".').val('."''".');jQuery(this).parent().css('."'visibility','hidden'".');jQuery(this).parent().prev().css('."'visibility','hidden'".'); return false;">' . __('Add New', 'custom-field-template') . '</a>'; |
| 2161 |
$addfield .= '</div>'; |
| 2162 |
endif; |
| 2163 |
|
| 2164 |
$out_key = '<span' . $hide . '><label for="' . $name_id . $sid . '_' . $cftnum . '">' . $title . '</label></span>'.$addfield; |
| 2165 |
|
| 2166 |
$out = |
| 2167 |
'<dl id="dl_' . $name_id . $sid . '_' . $cftnum . '" class="dl_text">' . |
| 2168 |
'<dt>'.$out_key.'</dt>' . |
| 2169 |
'<dd>'; |
| 2170 |
|
| 2171 |
if ( !empty($label) && empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2172 |
$out_value .= '<p class="label">' . wp_kses_post( stripcslashes($label) ) . '</p>'; |
| 2173 |
$out_value .= trim($before).'<input id="' . $name_id . $sid . '_' . $cftnum . '" name="' . $name . '['. $sid . '][]" value="' . esc_attr(trim($value)) . '" type="text" size="' . $size . '"' . $class . $style . $maxlength . $event_output . $readOnly . ' />'.trim($after); |
| 2174 |
|
| 2175 |
if ( $date == true ) : |
| 2176 |
$out_value .= '<script type="text/javascript">' . "\n" . |
| 2177 |
'// <![CDATA[' . "\n"; |
| 2178 |
if ( is_numeric($dateFirstDayOfWeek) ) $out_value .= 'Date.firstDayOfWeek = ' . intval($dateFirstDayOfWeek) . ";\n"; |
| 2179 |
if ( $dateFormat ) $out_value .= 'Date.format = "' . esc_js(stripcslashes(trim($dateFormat))) . '"' . ";\n"; |
| 2180 |
$out_value .= 'jQuery(document).ready(function() { jQuery(".datePicker").css("float", "left"); jQuery(".datePicker").datePicker({'; |
| 2181 |
$start_date_expression = $this->sanitize_datepicker_date_expression( $startDate ); |
| 2182 |
$end_date_expression = $this->sanitize_datepicker_date_expression( $endDate ); |
| 2183 |
if ( $start_date_expression !== '' ) $out_value .= "startDate: " . $start_date_expression; |
| 2184 |
if ( $start_date_expression !== '' && $end_date_expression !== '' ) $out_value .= ","; |
| 2185 |
if ( $end_date_expression !== '' ) $out_value .= "endDate: " . $end_date_expression; |
| 2186 |
$out_value .= '}); });' . "\n" . |
| 2187 |
'// ]]>' . "\n" . |
| 2188 |
'</script>'; |
| 2189 |
endif; |
| 2190 |
|
| 2191 |
$out .= $out_value.'</dd></dl>'."\n"; |
| 2192 |
|
| 2193 |
return array($out, $out_key, $out_value); |
| 2194 |
} |
| 2195 |
|
| 2196 |
function make_checkbox( $name, $sid, $data, $post_id ) { |
| 2197 |
$cftnum = $value = $valueLabel = $checked = $hideKey = $label = $code = $class = $style = $before = $after = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = ''; |
| 2198 |
$hide = $addfield = $out = $out_key = $out_value = ''; |
| 2199 |
extract($data); |
| 2200 |
$options = $this->get_custom_field_template_data(); |
| 2201 |
|
| 2202 |
$name = stripslashes($name); |
| 2203 |
|
| 2204 |
$title = $name; |
| 2205 |
$name = $this->sanitize_name( $name ); |
| 2206 |
$name_id = preg_replace( '/%/', '', (string) $name ); |
| 2207 |
|
| 2208 |
if ( !$value ) $value = "true"; |
| 2209 |
|
| 2210 |
if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false; |
| 2211 |
|
| 2212 |
if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) { |
| 2213 |
$selected = $this->get_post_meta( $post_id, $title ); |
| 2214 |
if ( $selected ) { |
| 2215 |
if ( in_array(stripcslashes($value), $selected) ) $checked = 'checked="checked"'; |
| 2216 |
} |
| 2217 |
} else { |
| 2218 |
if( $checked == true ) $checked = ' checked="checked"'; |
| 2219 |
} |
| 2220 |
|
| 2221 |
if ( $hideKey == true ) $hide = ' class="hideKey"'; |
| 2222 |
if ( !empty($class) ) $class = ' class="' . $class . '"'; |
| 2223 |
if ( !empty($style) ) $style = ' style="' . $style . '"'; |
| 2224 |
|
| 2225 |
if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2226 |
$title = wp_kses_post( stripcslashes($label) ); |
| 2227 |
|
| 2228 |
$event = array('onclick' => $onclick, 'ondblclick' => $ondblclick, 'onkeydown' => $onkeydown, 'onkeypress' => $onkeypress, 'onkeyup' => $onkeyup, 'onmousedown' => $onmousedown, 'onmouseup' => $onmouseup, 'onmouseover' => $onmouseover, 'onmouseout' => $onmouseout, 'onmousemove' => $onmousemove, 'onfocus' => $onfocus, 'onblur' => $onblur, 'onchange' => $onchange, 'onselect' => $onselect); |
| 2229 |
$event_output = ""; |
| 2230 |
foreach($event as $key => $val) : |
| 2231 |
if ( $val ) |
| 2232 |
$event_output .= " " . $key . '="' . esc_attr(stripcslashes(trim($val))) . '"'; |
| 2233 |
endforeach; |
| 2234 |
|
| 2235 |
$id = $name_id . '_' . $this->sanitize_name( $value ) . '_' . $sid . '_' . $cftnum; |
| 2236 |
|
| 2237 |
$out_key = '<span' . $hide . '>' . $title . '</span>'; |
| 2238 |
|
| 2239 |
$out .= |
| 2240 |
'<dl id="dl_' . $id . '" class="dl_checkbox">' . |
| 2241 |
'<dt>'.$out_key.'</dt>' . |
| 2242 |
'<dd>'; |
| 2243 |
|
| 2244 |
if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] && $cftnum == 0 ) |
| 2245 |
$out_value .= '<p class="label">' . wp_kses_post( stripcslashes($label) ) . '</p>'; |
| 2246 |
$out_value .= '<label for="' . $id . '" class="selectit"><input id="' . $id . '" name="' . $name . '[' . $sid . '][' . $cftnum . ']" value="' . esc_attr(stripcslashes(trim($value))) . '"' . $checked . ' type="checkbox"' . $class . $style . $event_output . ' /> '; |
| 2247 |
if ( $valueLabel ) |
| 2248 |
$out_value .= esc_html(stripcslashes(trim($valueLabel))); |
| 2249 |
else |
| 2250 |
$out_value .= esc_html(stripcslashes(trim($value))); |
| 2251 |
$out_value .= '</label> '; |
| 2252 |
|
| 2253 |
$out .= $out_value.'</dd></dl>'."\n"; |
| 2254 |
|
| 2255 |
return array($out, $out_key, $out_value); |
| 2256 |
} |
| 2257 |
|
| 2258 |
function make_radio( $name, $sid, $data, $post_id ) { |
| 2259 |
$cftnum = $values = $valueLabels = $clearButton = $default = $hideKey = $label = $code = $class = $style = $before = $after = $multipleButton = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = ''; |
| 2260 |
$hide = $addfield = $out = $out_key = $out_value = ''; |
| 2261 |
extract($data); |
| 2262 |
$options = $this->get_custom_field_template_data(); |
| 2263 |
|
| 2264 |
$name = stripslashes($name); |
| 2265 |
|
| 2266 |
$title = $name; |
| 2267 |
$name = $this->sanitize_name( $name ); |
| 2268 |
$name_id = preg_replace( '/%/', '', (string) $name ); |
| 2269 |
|
| 2270 |
if ( isset($code) && is_numeric($code) ) : |
| 2271 |
eval(stripcslashes($options['php'][$code])); |
| 2272 |
if ( !empty($valueLabel) && is_array($valueLabel) ) $valueLabels = $valueLabel; |
| 2273 |
endif; |
| 2274 |
|
| 2275 |
if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false; |
| 2276 |
|
| 2277 |
if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) { |
| 2278 |
$selected = $this->get_post_meta( $post_id, $title ); |
| 2279 |
$ct_value = is_array($selected) ? count($selected) : 0; |
| 2280 |
$selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : ''; |
| 2281 |
} else { |
| 2282 |
$selected = stripslashes($default); |
| 2283 |
} |
| 2284 |
if ( empty($ct_value) ) : |
| 2285 |
$ct_value = !empty($startNum) ? $startNum-1 : 1; |
| 2286 |
endif; |
| 2287 |
|
| 2288 |
if ( $hideKey == true ) $hide = ' class="hideKey"'; |
| 2289 |
$class .= ' '.$name_id . $sid; |
| 2290 |
if ( !empty($class) ) $class = ' class="' . trim($class) . '"'; |
| 2291 |
if ( !empty($style) ) $style = ' style="' . $style . '"'; |
| 2292 |
|
| 2293 |
if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2294 |
$title = wp_kses_post( stripcslashes($label) ); |
| 2295 |
|
| 2296 |
$event = array('onclick' => $onclick, 'ondblclick' => $ondblclick, 'onkeydown' => $onkeydown, 'onkeypress' => $onkeypress, 'onkeyup' => $onkeyup, 'onmousedown' => $onmousedown, 'onmouseup' => $onmouseup, 'onmouseover' => $onmouseover, 'onmouseout' => $onmouseout, 'onmousemove' => $onmousemove, 'onfocus' => $onfocus, 'onblur' => $onblur, 'onchange' => $onchange, 'onselect' => $onselect); |
| 2297 |
$event_output = ""; |
| 2298 |
foreach($event as $key => $val) : |
| 2299 |
if ( $val ) |
| 2300 |
$event_output .= " " . $key . '="' . esc_attr(stripcslashes(trim($val))) . '"'; |
| 2301 |
endforeach; |
| 2302 |
|
| 2303 |
if ( $multipleButton == true && $ct_value == $cftnum ) : |
| 2304 |
$addfield .= '<div style="margin-top:-1em;">'; |
| 2305 |
$addfield .= '<a href="#clear" onclick="var tmp = jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent());tmp.find('."'input'".').attr('."'checked',false".');if(tmp.find('."'input'".').attr('."'name'".').match(/\[([0-9]+)\]$/)) { matchval = RegExp.$1; matchval++;tmp.find('."'input'".').attr('."'name',".'tmp.find('."'input'".').attr('."'name'".').replace(/\[([0-9]+)\]$/, \'[\'+matchval+\']\'));}jQuery(this).parent().css('."'visibility','hidden'".');jQuery(this).parent().prev().css('."'visibility','hidden'".'); return false;">' . __('Add New', 'custom-field-template') . '</a>'; |
| 2306 |
$addfield .= '</div>'; |
| 2307 |
endif; |
| 2308 |
|
| 2309 |
$out_key = '<span' . $hide . '>' . $title . '</span>'.$addfield; |
| 2310 |
|
| 2311 |
if( $clearButton == true ) { |
| 2312 |
$out_key .= '<div>'; |
| 2313 |
$out_key .= '<a href="#clear" onclick="jQuery(\'.'.$name_id . $sid.'\').attr(\'checked\', false); return false;">' . __('Clear', 'custom-field-template') . '</a>'; |
| 2314 |
$out_key .= '</div>'; |
| 2315 |
} |
| 2316 |
|
| 2317 |
$out .= |
| 2318 |
'<dl id="dl_' . $name_id . $sid . '_' . $cftnum . '" class="dl_radio">' . |
| 2319 |
'<dt>'.$out_key.'</dt>' . |
| 2320 |
'<dd>'; |
| 2321 |
|
| 2322 |
if ( !empty($label) && empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2323 |
$out_value .= '<p class="label">' . wp_kses_post( stripcslashes($label) ) . '</p>'; |
| 2324 |
$i = 0; |
| 2325 |
|
| 2326 |
$out_value .= trim($before).'<input name="' . $name . '[' . $sid . '][' . $cftnum . ']" value="" type="hidden" />'; |
| 2327 |
|
| 2328 |
if ( is_array($values) ) : |
| 2329 |
foreach( $values as $val ) { |
| 2330 |
$value_id = preg_replace( '/%/', '', $this->sanitize_name( $val ) ); |
| 2331 |
$id = $name_id . '_' . $value_id . '_' . $sid . '_' . $cftnum; |
| 2332 |
|
| 2333 |
$checked = ( stripcslashes(trim( $val )) == trim( $selected ) ) ? 'checked="checked"' : ''; |
| 2334 |
|
| 2335 |
$out_value .= |
| 2336 |
'<label for="' . $id . '" class="selectit"><input id="' . $id . '" name="' . $name . '[' . $sid . '][' . $cftnum . ']" value="' . esc_attr(trim(stripcslashes($val))) . '" ' . $checked . ' type="radio"' . $class . $style . $event_output . ' /> '; |
| 2337 |
if ( isset($valueLabels[$i]) ) |
| 2338 |
$out_value .= esc_html(stripcslashes(trim($valueLabels[$i]))); |
| 2339 |
else |
| 2340 |
$out_value .= esc_html(stripcslashes(trim($val))); |
| 2341 |
$out_value .= '</label> '; |
| 2342 |
$i++; |
| 2343 |
} |
| 2344 |
endif; |
| 2345 |
$out_value .= trim($after); |
| 2346 |
$out .= $out_value.'</dd></dl>'."\n"; |
| 2347 |
|
| 2348 |
return array($out, $out_key, $out_value); |
| 2349 |
} |
| 2350 |
|
| 2351 |
function make_select( $name, $sid, $data, $post_id ) { |
| 2352 |
$cftnum = $values = $valueLabels = $default = $hideKey = $label = $code = $class = $style = $before = $after = $selectLabel = $multipleButton = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = ''; |
| 2353 |
$hide = $addfield = $out = $out_key = $out_value = ''; |
| 2354 |
extract($data); |
| 2355 |
$options = $this->get_custom_field_template_data(); |
| 2356 |
|
| 2357 |
$name = stripslashes($name); |
| 2358 |
|
| 2359 |
$title = $name; |
| 2360 |
$name = $this->sanitize_name( $name ); |
| 2361 |
$name_id = preg_replace( '/%/', '', (string) $name ); |
| 2362 |
|
| 2363 |
if ( isset($code) && is_numeric($code) ) : |
| 2364 |
eval(stripcslashes($options['php'][$code])); |
| 2365 |
if ( !empty($valueLabel) && is_array($valueLabel) ) $valueLabels = $valueLabel; |
| 2366 |
endif; |
| 2367 |
|
| 2368 |
if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false; |
| 2369 |
|
| 2370 |
if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) { |
| 2371 |
$selected = $this->get_post_meta( $post_id, $title ); |
| 2372 |
$ct_value = is_array($selected) ? count($selected) : 0; |
| 2373 |
$selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : ''; |
| 2374 |
} else { |
| 2375 |
$selected = stripslashes($default); |
| 2376 |
} |
| 2377 |
if ( empty($ct_value) ) : |
| 2378 |
$ct_value = !empty($startNum) ? $startNum-1 : 1; |
| 2379 |
endif; |
| 2380 |
|
| 2381 |
if ( $hideKey == true ) $hide = ' class="hideKey"'; |
| 2382 |
if ( !empty($class) ) $class = ' class="' . $class . '"'; |
| 2383 |
if ( !empty($style) ) $style = ' style="' . $style . '"'; |
| 2384 |
|
| 2385 |
if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2386 |
$title = wp_kses_post( stripcslashes($label) ); |
| 2387 |
|
| 2388 |
$event = array('onclick' => $onclick, 'ondblclick' => $ondblclick, 'onkeydown' => $onkeydown, 'onkeypress' => $onkeypress, 'onkeyup' => $onkeyup, 'onmousedown' => $onmousedown, 'onmouseup' => $onmouseup, 'onmouseover' => $onmouseover, 'onmouseout' => $onmouseout, 'onmousemove' => $onmousemove, 'onfocus' => $onfocus, 'onblur' => $onblur, 'onchange' => $onchange, 'onselect' => $onselect); |
| 2389 |
$event_output = ""; |
| 2390 |
foreach($event as $key => $val) : |
| 2391 |
if ( $val ) |
| 2392 |
$event_output .= " " . $key . '="' . esc_attr(stripcslashes(trim($val))) . '"'; |
| 2393 |
endforeach; |
| 2394 |
|
| 2395 |
if ( $multipleButton == true && $ct_value == $cftnum ) : |
| 2396 |
$addfield .= '<div style="margin-top:-1em;">'; |
| 2397 |
$addfield .= '<a href="#clear" onclick="jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent()).find('."'select'".').val('."''".');jQuery(this).parent().css('."'visibility','hidden'".');jQuery(this).parent().prev().css('."'visibility','hidden'".'); return false;">' . __('Add New', 'custom-field-template') . '</a>'; |
| 2398 |
$addfield .= '</div>'; |
| 2399 |
endif; |
| 2400 |
|
| 2401 |
$out_key = '<span' . $hide . '><label for="' . $name_id . $sid . '_' . $cftnum . '">' . $title . '</label></span>'.$addfield; |
| 2402 |
|
| 2403 |
$out .= |
| 2404 |
'<dl id="dl_' . $name_id . $sid . '_' . $cftnum . '" class="dl_select">' . |
| 2405 |
'<dt>'.$out_key.'</dt>' . |
| 2406 |
'<dd>'; |
| 2407 |
|
| 2408 |
if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] ) |
| 2409 |
$out_value .= '<p class="label">' . wp_kses_post( stripcslashes($label) ) . '</p>'; |
| 2410 |
$out_value .= trim($before).'<select id="' . $name_id . $sid . '_' . $cftnum . '" name="' . $name . '[' . $sid . '][]"' . $class . $style . $event_output . '>'; |
| 2411 |
|
| 2412 |
if ( $selectLabel ) |
| 2413 |
$out_value .= '<option value="">' . esc_html(stripcslashes(trim($selectLabel))) . '</option>'; |
| 2414 |
else |
| 2415 |
$out_value .= '<option value="">' . __('Select', 'custom-field-template') . '</option>'; |
| 2416 |
|
| 2417 |
$i = 0; |
| 2418 |
if ( is_array($values) ) : |
| 2419 |
foreach( $values as $val ) { |
| 2420 |
$checked = ( stripcslashes(trim( $val )) == trim( $selected ) ) ? 'selected="selected"' : ''; |
| 2421 |
|
| 2422 |
$out_value .= '<option value="' . esc_attr(stripcslashes(trim($val))) . '" ' . $checked . '>'; |
| 2423 |
if ( isset($valueLabels[$i]) ) |
| 2424 |
$out_value .= esc_html(stripcslashes(trim($valueLabels[$i]))); |
| 2425 |
else |
| 2426 |
$out_value .= esc_html(stripcslashes(trim($val))); |
| 2427 |
$out_value .= '</option>'; |
| 2428 |
$i++; |
| 2429 |
} |
| 2430 |
endif; |
| 2431 |
$out_value .= '</select>'.trim($after); |
| 2432 |
$out .= $out_value.'</dd></dl>'."\n"; |
| 2433 |
|
| 2434 |
return array($out, $out_key, $out_value); |
| 2435 |
} |
| 2436 |
|
| 2437 |
function make_textarea( $name, $sid, $data, $post_id ) { |
| 2438 |
$cftnum = $rows = $cols = $tinyMCE = $htmlEditor = $mediaButton = $default = $hideKey = $label = $code = $class = $style = $wrap = $before = $after = $multipleButton = $mediaOffMedia = $mediaOffImage = $mediaOffVideo = $mediaOffAudio = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = ''; |
| 2439 |
$hide = $addfield = $out = $out_key = $out_value = $media = $editorcontainer_class = $quicktags_hide = ''; |
| 2440 |
extract($data); |
| 2441 |
$options = $this->get_custom_field_template_data(); |
| 2442 |
|
| 2443 |
global $wp_version; |
| 2444 |
|
| 2445 |
$name = stripslashes($name); |
| 2446 |
|
| 2447 |
$title = $name; |
| 2448 |
$name = $this->sanitize_name( $name ); |
| 2449 |
$name_id = preg_replace( '/%/', '', (string) $name ); |
| 2450 |
|
| 2451 |
if ( is_numeric($code) ) : |
| 2452 |
eval(stripcslashes($options['php'][$code])); |
| 2453 |
endif; |
| 2454 |
|
| 2455 |
if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false; |
| 2456 |
|
| 2457 |
if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) { |
| 2458 |
$value = $this->get_post_meta( $post_id, $title ); |
| 2459 |
if ( !empty($value) && is_array($value) ) { |
| 2460 |
$ct_value = count($value); |
| 2461 |
$value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : ''; |
| 2462 |
} |
| 2463 |
} else { |
| 2464 |
$value = stripslashes($default); |
| 2465 |
} |
| 2466 |
|
| 2467 |
if ( empty($ct_value) ) : |
| 2468 |
$ct_value = !empty($startNum) ? $startNum-1 : 1; |
| 2469 |
endif; |
| 2470 |
|
| 2471 |
$rand = rand(); |
| 2472 |
$switch = ''; |
| 2473 |
$textarea_id = sha1($name . $rand).rand(0,9); |
| 2474 |
|
| 2475 |
if( $tinyMCE == true ) { |
| 2476 |
$out_value = '<script type="text/javascript">' . "\n" . |
| 2477 |
'// <![CDATA[' . "\n" . |
| 2478 |
'jQuery(document).ready(function() {if ( typeof tinyMCE != "undefined" ) {' . "\n"; |
| 2479 |
|
| 2480 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 2481 |
$load_tinyMCE = 'tinyMCE.execCommand('."'mceAddControl'".', false, "'. $textarea_id . '");'; |
| 2482 |
$editorcontainer_class = ' class="editorcontainer"'; |
| 2483 |
elseif ( substr($wp_version, 0, 3) < '3.9' ) : |
| 2484 |
$load_tinyMCE = 'var ed = new tinyMCE.Editor("'. $textarea_id . '", tinyMCEPreInit.mceInit["content"]); ed.render();'; |
| 2485 |
$editorcontainer_class = ' class="wp-editor-container"'; |
| 2486 |
else : |
| 2487 |
$load_tinyMCE = ''; |
| 2488 |
if ( wp_default_editor() == 'html' ) $load_tinyMCE .= 'tinyMCE.init({"convert_urls": false, "relative_urls": false, "remove_script_host": false});'; |
| 2489 |
$load_tinyMCE .= 'tinyMCE.execCommand('."'mceAddEditor'".', false, "'. $textarea_id . '");'; |
| 2490 |
$editorcontainer_class = ' class="wp-editor-container"'; |
| 2491 |
endif; |
| 2492 |
if ( !empty($options['custom_field_template_use_wpautop']) ) : |
| 2493 |
$out_value .= 'document.getElementById("'. $textarea_id . '").value = document.getElementById("'. $textarea_id . '").value; '.$load_tinyMCE.' tinyMCEID.push("'. $textarea_id . '");' . "\n"; |
| 2494 |
else: |
| 2495 |
$out_value .= 'document.getElementById("'. $textarea_id . '").value = switchEditors.wpautop(document.getElementById("'. $textarea_id . '").value); '.$load_tinyMCE.' tinyMCEID.push("'. $textarea_id . '");' . "\n"; |
| 2496 |
endif; |
| 2497 |
$out_value .= '}});' . "\n"; |
| 2498 |
$out_value .= '// ]]>' . "\n" . '</script>'; |
| 2499 |
} |
| 2500 |
|
| 2501 |
if ( substr($wp_version, 0, 3) >= '2.5' ) { |
| 2502 |
|
| 2503 |
if ( !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') && !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) { |
| 2504 |
|
| 2505 |
if ( $mediaButton == true ) : |
| 2506 |
$media_upload_iframe_src = "media-upload.php"; |
| 2507 |
|
| 2508 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 2509 |
if ( !$mediaOffImage ) : |
| 2510 |
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src?type=image"); |
| 2511 |
$image_title = __('Add an Image'); |
| 2512 |
$media .= "<a href=\"{$image_upload_iframe_src}&TB_iframe=true\" id=\"add_image{$rand}\" title='$image_title' onclick=\"focusTextArea('".$textarea_id."'); jQuery(this).attr('href',jQuery(this).attr('href').replace('\?','?post_id='+jQuery('#post_ID').val())); return thickbox(this);\"><img src='images/media-button-image.gif' alt='$image_title' /></a> "; |
| 2513 |
endif; |
| 2514 |
if ( !$mediaOffVideo ) : |
| 2515 |
$video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src?type=video"); |
| 2516 |
$video_title = __('Add Video'); |
| 2517 |
$media .= "<a href=\"{$video_upload_iframe_src}&TB_iframe=true\" id=\"add_video{$rand}\" title='$video_title' onclick=\"focusTextArea('".$textarea_id."'); jQuery(this).attr('href',jQuery(this).attr('href').replace('\?','?post_id='+jQuery('#post_ID').val())); return thickbox(this);\"><img src='images/media-button-video.gif' alt='$video_title' /></a> "; |
| 2518 |
endif; |
| 2519 |
if ( !$mediaOffAudio ) : |
| 2520 |
$audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src?type=audio"); |
| 2521 |
$audio_title = __('Add Audio'); |
| 2522 |
$media .= "<a href=\"{$audio_upload_iframe_src}&TB_iframe=true\" id=\"add_audio{$rand}\" title='$audio_title' onclick=\"focusTextArea('".$textarea_id."'); jQuery(this).attr('href',jQuery(this).attr('href').replace('\?','?post_id='+jQuery('#post_ID').val())); return thickbox(this);\"><img src='images/media-button-music.gif' alt='$audio_title' /></a> "; |
| 2523 |
endif; |
| 2524 |
if ( !$mediaOffMedia ) : |
| 2525 |
$media_title = __('Add Media'); |
| 2526 |
$media .= "<a href=\"{$media_upload_iframe_src}?TB_iframe=true\" id=\"add_media{$rand}\" title='$media_title' onclick=\"focusTextArea('".$textarea_id."'); jQuery(this).attr('href',jQuery(this).attr('href').replace('\?','?post_id='+jQuery('#post_ID').val())); return thickbox(this);\"><img src='images/media-button-other.gif' alt='$media_title' /></a>"; |
| 2527 |
endif; |
| 2528 |
else : |
| 2529 |
$media_title = __('Add Media'); |
| 2530 |
$media .= "<a href=\"{$media_upload_iframe_src}?TB_iframe=true\" id=\"add_media{$rand}\" title='$media_title' onclick=\"focusTextArea('".$textarea_id."'); jQuery(this).attr('href',jQuery(this).attr('href').replace('\?','?post_id='+jQuery('#post_ID').val())); return thickbox(this);\"><img src='images/media-button.png' alt='$media_title' /></a>"; |
| 2531 |
endif; |
| 2532 |
endif; |
| 2533 |
|
| 2534 |
$switch = '<div>'; |
| 2535 |
if( $tinyMCE == true && user_can_richedit() ) { |
| 2536 |
$switch .= '<a href="#toggle" onclick="switchMode(jQuery(this).parent().parent().parent().find(\'textarea\').attr(\'id\')); return false;">' . __('Toggle', 'custom-field-template') . '</a>'; |
| 2537 |
} |
| 2538 |
$switch .= '</div>'; |
| 2539 |
} |
| 2540 |
|
| 2541 |
} |
| 2542 |
|
| 2543 |
if ( $hideKey == true ) $hide = ' class="hideKey"'; |
| 2544 |
$content_class = ' class="'; |
| 2545 |
if ( $htmlEditor == true || $tinyMCE == true ) : |
| 2546 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 2547 |
$content_class .= 'content'; |
| 2548 |
else : |
| 2549 |
$content_class .= 'wp-editor-area'; |
| 2550 |
endif; |
| 2551 |
endif; |
| 2552 |
if ( !empty($class) ) $content_class .= ' ' . $class; |
| 2553 |
$content_class .= '"'; |
| 2554 |
if ( !empty($style) ) $style = ' style="' . $style . '"'; |
| 2555 |
if ( !empty($wrap) && ($wrap == 'soft' || $wrap == 'hard' || $wrap == 'off') ) $wrap = ' wrap="' . $wrap . '"'; |
| 2556 |
|
| 2557 |
if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2558 |
$title = wp_kses_post( stripcslashes($label) ); |
| 2559 |
|
| 2560 |
$event = array('onclick' => $onclick, 'ondblclick' => $ondblclick, 'onkeydown' => $onkeydown, 'onkeypress' => $onkeypress, 'onkeyup' => $onkeyup, 'onmousedown' => $onmousedown, 'onmouseup' => $onmouseup, 'onmouseover' => $onmouseover, 'onmouseout' => $onmouseout, 'onmousemove' => $onmousemove, 'onfocus' => $onfocus, 'onblur' => $onblur, 'onchange' => $onchange, 'onselect' => $onselect); |
| 2561 |
$event_output = ""; |
| 2562 |
foreach($event as $key => $val) : |
| 2563 |
if ( $val ) |
| 2564 |
$event_output .= " " . $key . '="' . esc_attr(stripcslashes(trim($val))) . '"'; |
| 2565 |
endforeach; |
| 2566 |
|
| 2567 |
if ( $multipleButton == true && $ct_value == $cftnum ) : |
| 2568 |
$addfield .= '<div style="margin-top:-1em;">'; |
| 2569 |
if ( !empty($htmlEditor) ) : |
| 2570 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 2571 |
$load_htmlEditor1 = 'jQuery(\'#qt_\'+original_id+\'_qtags\').remove();'; |
| 2572 |
$load_htmlEditor2 = 'qt_set(original_id);qt_set(new_id);'; |
| 2573 |
if( $tinyMCE == true ) : $load_htmlEditor2 .= ' jQuery(\'#qt_\'+original_id+\'_qtags\').hide(); jQuery(\'#qt_\'+new_id+\'_qtags\').hide();'; endif; |
| 2574 |
else : |
| 2575 |
$load_htmlEditor1 = 'jQuery(\'#qt_\'+original_id+\'_toolbar\').remove();'; |
| 2576 |
$load_htmlEditor2 = 'new QTags(new_id);QTags._buttonsInit();'; |
| 2577 |
if( $tinyMCE == true ) : $load_htmlEditor2 .= ' jQuery(\'#qt_\'+new_id+\'_toolbar\').hide();'; endif; |
| 2578 |
endif; |
| 2579 |
endif; |
| 2580 |
if ( !empty($tinyMCE) ) : |
| 2581 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 2582 |
$load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, original_id);tinyMCE.execCommand(' . "'mceAddControl'" . ',false, new_id);'; |
| 2583 |
elseif ( substr($wp_version, 0, 3) < '3.9' ) : |
| 2584 |
$load_tinyMCE = 'var ed = new tinyMCE.Editor(original_id, tinyMCEPreInit.mceInit[\'content\']); ed.render(); var ed = new tinyMCE.Editor(new_id, tinyMCEPreInit.mceInit[\'content\']); ed.render();'; |
| 2585 |
else : |
| 2586 |
$load_tinyMCE = 'tinyMCE.execCommand('."'mceAddEditor'".', false, original_id);tinyMCE.execCommand('."'mceAddEditor'".', false, new_id);'; |
| 2587 |
endif; |
| 2588 |
|
| 2589 |
$addfield .= '<a href="#clear" onclick="var original_id; var new_id; jQuery(this).parent().parent().parent().find('."'textarea'".').each(function(){original_id = jQuery(this).attr('."'id'".');'.$load_htmlEditor1.'tinyMCE.execCommand(' . "'mceRemoveControl'" . ',true,jQuery(this).attr('."'id'".'));});var clone = jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent()); clone.find('."'textarea'".').val('."''".');if(original_id.match(/([0-9])$/)) {var matchval = RegExp.$1;re = new RegExp(matchval, '."'ig'".');clone.html(clone.html().replace(re, parseInt(matchval)+1)); new_id = original_id.replace(/([0-9])$/, parseInt(matchval)+1);}if ( tinyMCE.get(jQuery(this).attr('."original_id".')) ) {'.$load_tinyMCE.'}jQuery(this).parent().css('."'visibility','hidden'".');'.$load_htmlEditor2.'jQuery(this).parent().prev().css('."'visibility','hidden'".'); return false;">' . __('Add New', 'custom-field-template') . '</a>'; |
| 2590 |
else : |
| 2591 |
$addfield .= '<a href="#clear" onclick="var original_id; var new_id; jQuery(this).parent().parent().parent().find('."'textarea'".').each(function(){original_id = jQuery(this).attr('."'id'".');});'.$load_htmlEditor1.'var clone = jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent()); clone.find('."'textarea'".').val('."''".');if(original_id.match(/([0-9]+)$/)) {var matchval = RegExp.$1;re = new RegExp(matchval, '."'ig'".');clone.html(clone.html().replace(re, parseInt(matchval)+1)); new_id = original_id.replace(/([0-9]+)$/, parseInt(matchval)+1);}'.$load_htmlEditor2.'jQuery(this).parent().css('."'visibility','hidden'".');jQuery(this).parent().prev().css('."'visibility','hidden'".'); return false;">' . __('Add New', 'custom-field-template') . '</a>'; |
| 2592 |
endif; |
| 2593 |
$addfield .= '</div>'; |
| 2594 |
endif; |
| 2595 |
|
| 2596 |
$out_key = '<span' . $hide . '><label for="' . $name_id . $sid . '_' . $cftnum . '">' . $title . '</label></span><br />' . $addfield . $media . $switch; |
| 2597 |
|
| 2598 |
$out .= |
| 2599 |
'<dl id="dl_' . $name_id . $sid . '_' . $cftnum . '" class="dl_textarea">' . |
| 2600 |
'<dt>'.$out_key.'</dt>' . |
| 2601 |
'<dd>'; |
| 2602 |
|
| 2603 |
if ( !empty($label) && empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2604 |
$out_value .= '<p class="label">' . wp_kses_post( stripcslashes($label) ) . '</p>'; |
| 2605 |
|
| 2606 |
$out_value .= trim($before); |
| 2607 |
|
| 2608 |
if ( ($htmlEditor == true || $tinyMCE == true) && substr($wp_version, 0, 3) < '3.3' ) $out_value .= '<div class="quicktags">'; |
| 2609 |
|
| 2610 |
if ( $htmlEditor == true ) : |
| 2611 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 2612 |
if( $tinyMCE == true ) $quicktags_hide = ' jQuery(\'#qt_' . $textarea_id . '_qtags\').hide();'; |
| 2613 |
$out_value .= '<script type="text/javascript">' . "\n" . '// <![CDATA[' . ' |
| 2614 |
jQuery(document).ready(function() { qt_' . $textarea_id . ' = new QTags(\'qt_' . $textarea_id . '\', \'' . $textarea_id . '\', \'editorcontainer_' . $textarea_id . '\', \'more\'); ' . $quicktags_hide . ' });' . "\n" . '// ]]>' . "\n" . '</script>'; |
| 2615 |
$editorcontainer_class = ' class="editorcontainer"'; |
| 2616 |
else : |
| 2617 |
if( $tinyMCE == true ) $quicktags_hide = ' jQuery(\'#qt_' . $textarea_id . '_toolbar\').hide();'; |
| 2618 |
$out_value .= '<script type="text/javascript">' . "\n" . '// <![CDATA[' . ' |
| 2619 |
jQuery(document).ready(function() { new QTags(\'' . $textarea_id . '\'); QTags._buttonsInit(); ' . $quicktags_hide . ' }); ' . "\n"; |
| 2620 |
$out_value .= '// ]]>' . "\n" . '</script>'; |
| 2621 |
$editorcontainer_class = ' class="wp-editor-container"'; |
| 2622 |
endif; |
| 2623 |
endif; |
| 2624 |
|
| 2625 |
$out_value .= '<div' . $editorcontainer_class . ' id="editorcontainer_' . $textarea_id . '" style="clear:none;"><textarea id="' . $textarea_id . '" name="' . $name . '[' . $sid . '][]" rows="' .$rows. '" cols="' . $cols . '"' . $content_class . $style . $event_output . $wrap . '>' . htmlspecialchars(trim($value)) . '</textarea><input type="hidden" name="'.$name.'_rand['.$sid.']" value="'.$rand.'" /></div>'; |
| 2626 |
if ( ($htmlEditor == true || $tinyMCE == true) && substr($wp_version, 0, 3) < '3.3' ) $out_value .= '</div>'; |
| 2627 |
$out_value .= trim($after); |
| 2628 |
$out .= $out_value.'</dd></dl>'."\n"; |
| 2629 |
|
| 2630 |
return array($out, $out_key, $out_value); |
| 2631 |
} |
| 2632 |
|
| 2633 |
function make_file( $name, $sid, $data, $post_id ) { |
| 2634 |
$cftnum = $size = $hideKey = $label = $class = $style = $before = $after = $multipleButton = $relation = $mediaLibrary = $mediaPicker = ''; |
| 2635 |
$hide = $addfield = $out = $out_key = $out_value = $picker = $inside_fieldset = ''; |
| 2636 |
extract($data); |
| 2637 |
$options = $this->get_custom_field_template_data(); |
| 2638 |
|
| 2639 |
$name = stripslashes($name); |
| 2640 |
|
| 2641 |
$title = $name; |
| 2642 |
$name = $this->sanitize_name( $name ); |
| 2643 |
$name_id = preg_replace( '/%/', '', (string) $name ); |
| 2644 |
|
| 2645 |
if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false; |
| 2646 |
|
| 2647 |
if( isset( $post_id ) && $post_id > 0 && $_REQUEST['default'] != true ) { |
| 2648 |
$value = $this->get_post_meta( $post_id, $title ); |
| 2649 |
$ct_value = (!empty($value) && is_array($value)) ? count($value) : 0; |
| 2650 |
$value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : ''; |
| 2651 |
} |
| 2652 |
|
| 2653 |
if ( empty($ct_value) ) : |
| 2654 |
$ct_value = !empty($startNum) ? $startNum-1 : 1; |
| 2655 |
endif; |
| 2656 |
|
| 2657 |
if ( $hideKey == true ) $hide = ' class="hideKey"'; |
| 2658 |
if ( !empty($class) ) $class = ' class="' . $class . '"'; |
| 2659 |
if ( !empty($style) ) $style = ' style="' . $style . '"'; |
| 2660 |
|
| 2661 |
if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2662 |
$title = wp_kses_post( stripcslashes($label) ); |
| 2663 |
|
| 2664 |
if ( $multipleButton == true && $ct_value == $cftnum ) : |
| 2665 |
$addfield .= '<div style="margin-top:-1em;">'; |
| 2666 |
$addfield .= '<a href="#clear" onclick="var tmp = jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent());if(tmp.find('."'input[type=file]'".').attr('."'id'".').match(/([0-9]+)$/)) { matchval = RegExp.$1; matchval++;tmp.find('."'input[type=file]'".').attr('."'id',".'tmp.find('."'input[type=file]'".').attr('."'id'".').replace(/([0-9]+)$/, matchval));}if(tmp.find('."'input[type=hidden]'".').attr('."'id'".').match(/([0-9]+)_hide$/)) { matchval = RegExp.$1; matchval++;tmp.find('."'input[type=hidden]'".').attr('."'id',".'tmp.find('."'input[type=hidden]'".').attr('."'id'".').replace(/([0-9]+)_hide$/, matchval+'."'_hide'".'));}if(tmp.find('."'input[type=hidden]'".').attr('."'name'".').match(/\[([0-9]+)\]$/)) { matchval = RegExp.$1; matchval++;tmp.find('."'input[type=hidden]'".').attr('."'name',".'tmp.find('."'input[type=hidden]'".').attr('."'name'".').replace(/\[([0-9]+)\]$/, \'[\'+matchval+\']\'));}jQuery(this).parent().css('."'visibility','hidden'".');jQuery(this).parent().prev().css('."'visibility','hidden'".'); return false;">' . __('Add New', 'custom-field-template') . '</a>'; |
| 2667 |
$addfield .= '</div>'; |
| 2668 |
endif; |
| 2669 |
|
| 2670 |
if ( $relation == true ) $tab = 'gallery'; |
| 2671 |
else $tab = 'library'; |
| 2672 |
$media_upload_iframe_src = "media-upload.php"; |
| 2673 |
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src?type=image&tab=library"); |
| 2674 |
|
| 2675 |
if ( $mediaPicker == true ) : |
| 2676 |
$picker = __(' OR ', 'custom-field-template'); |
| 2677 |
$picker .= '<a href="'.$image_upload_iframe_src.'&post_id='.$post_id.'&TB_iframe=1&tab='.$tab.'" class="thickbox" onclick="jQuery('."'#cft_current_template'".').val(jQuery(this).parent().parent().parent().'; |
| 2678 |
if ( $inside_fieldset ) $picker .= 'parent().'; |
| 2679 |
$picker .= 'parent().attr(\'id\').replace(\'cft_\',\'\'));jQuery('."'#cft_clicked_id'".').val(jQuery(this).parent().find(\'input\').attr(\'id\'));">'.__('Select by Media Picker', 'custom-field-template').'</a>'; |
| 2680 |
endif; |
| 2681 |
|
| 2682 |
$out_key = '<span' . $hide . '><label for="' . $name_id . $sid . '_' . $cftnum . '">' . $title . '</label></span>'.$addfield; |
| 2683 |
|
| 2684 |
$out .= |
| 2685 |
'<dl id="dl_' . $name_id . $sid . '_' . $cftnum . '" class="dl_file">' . |
| 2686 |
'<dt>'.$out_key.'</dt>' . |
| 2687 |
'<dd>'; |
| 2688 |
|
| 2689 |
if ( !empty($label) && empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 2690 |
$out_value .= '<p class="label">' . wp_kses_post( stripcslashes($label) ) . '</p>'; |
| 2691 |
$out_value .= trim($before).'<input id="' . $name_id . $sid . '_' . $cftnum . '" name="' . $name . '['.$sid.'][]" type="file" size="' . $size . '"' . $class . $style . ' onchange="if (jQuery(this).val()) { jQuery(\'#cft_save_button\'+jQuery(this).parent().parent().parent().parent().attr(\'id\').replace(\'cft_\',\'\')).attr(\'disabled\', true); jQuery(\'#post-preview\').hide(); } else { jQuery(\'#cft_save_button\').attr(\'disabled\', false); jQuery(\'#post-preview\').show(); }" />'.trim($after).$picker; |
| 2692 |
|
| 2693 |
if ( isset($value) && ( $value = intval($value) ) && $thumb_url = wp_get_attachment_image_src( $value, 'thumbnail', true ) ) : |
| 2694 |
$thumb_url = $thumb_url[0]; |
| 2695 |
|
| 2696 |
$post = get_post($value); |
| 2697 |
$filename = basename($post->guid); |
| 2698 |
$title = esc_attr(trim($post->post_title)); |
| 2699 |
|
| 2700 |
if ( !empty($mediaLibrary) ) : |
| 2701 |
$title = '<a href="'.$image_upload_iframe_src.'&post_id='.$post_id.'&TB_iframe=1&tab='.$tab.'" class="thickbox">'.$title.'</a>'; |
| 2702 |
endif; |
| 2703 |
|
| 2704 |
$out_value .= '<p><label for="'.$name . $sid . '_' . $cftnum . '_delete"><input type="checkbox" name="'.$name . '_delete[' . $sid . '][' . $cftnum . ']" id="'.$name_id . $sid . '_' . $cftnum . '_delete" value="1" class="delete_file_checkbox" /> ' . __('Delete', 'custom-field-template') . '</label> <img src="'.$thumb_url.'" width="32" height="32" style="vertical-align:middle;" /> ' . $title . ' </p>'; |
| 2705 |
$out_value .= '<input type="hidden" id="' . $name_id . $sid . '_' . $cftnum . '_hide" name="'.$name . '[' . $sid . '][' . $cftnum . ']" value="' . $value . '" />'; |
| 2706 |
else : |
| 2707 |
$out_value .= '<input type="hidden" id="' . $name_id . $sid . '_' . $cftnum . '_hide" name="'.$name . '[' . $sid . '][' . $cftnum . ']" value="" />'; |
| 2708 |
endif; |
| 2709 |
|
| 2710 |
$out .= $out_value.'</dd></dl>'."\n"; |
| 2711 |
|
| 2712 |
return array($out, $out_key, $out_value); |
| 2713 |
} |
| 2714 |
|
| 2715 |
|
| 2716 |
function load_custom_field( $id = 0 ) { |
| 2717 |
global $current_user, $post, $wp_version; |
| 2718 |
$id = absint( $id ); |
| 2719 |
$level = $current_user->user_level; |
| 2720 |
|
| 2721 |
$options = $this->get_custom_field_template_data(); |
| 2722 |
|
| 2723 |
$post_id = isset($_REQUEST['post']) && is_scalar( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : 0; |
| 2724 |
|
| 2725 |
if ( $post_id ) $post = get_post($post_id); |
| 2726 |
|
| 2727 |
if ( isset($_REQUEST['revision']) && is_scalar( $_REQUEST['revision'] ) ) $post_id = absint( $_REQUEST['revision'] ); |
| 2728 |
|
| 2729 |
if ( !empty($options['custom_fields'][$id]['disable']) ) |
| 2730 |
return; |
| 2731 |
|
| 2732 |
$fields = $this->get_custom_fields( $id ); |
| 2733 |
|
| 2734 |
if ( $fields == null ) |
| 2735 |
return; |
| 2736 |
|
| 2737 |
if ( (isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == 'page') || $post->post_type=='page' ) : |
| 2738 |
$post->page_template = get_post_meta( $post->ID, '_wp_page_template', true ); |
| 2739 |
if ( !$post->page_template ) $post->page_template = 'default'; |
| 2740 |
endif; |
| 2741 |
|
| 2742 |
if ( !empty($options['custom_fields'][$id]['post_type']) ) : |
| 2743 |
if ( substr($wp_version, 0, 3) < '3.0' ) : |
| 2744 |
if ( $options['custom_fields'][$id]['post_type'] == 'post' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php')) ) : |
| 2745 |
return; |
| 2746 |
endif; |
| 2747 |
if ( $options['custom_fields'][$id]['post_type'] == 'page' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php')) ) : |
| 2748 |
return; |
| 2749 |
endif; |
| 2750 |
else : |
| 2751 |
if ( (isset($_REQUEST['post_type']) && $_REQUEST['post_type']!=$options['custom_fields'][$id]['post_type']) && $post->post_type!=$options['custom_fields'][$id]['post_type'] ) : |
| 2752 |
return; |
| 2753 |
endif; |
| 2754 |
endif; |
| 2755 |
endif; |
| 2756 |
|
| 2757 |
if ( !empty($options['custom_fields'][$id]['custom_post_type']) ) : |
| 2758 |
$custom_post_type = explode(',', $options['custom_fields'][$id]['custom_post_type']); |
| 2759 |
$custom_post_type = array_filter( $custom_post_type ); |
| 2760 |
$custom_post_type = array_unique(array_filter(array_map('trim', $custom_post_type))); |
| 2761 |
if ( !in_array($post->post_type, $custom_post_type) ) |
| 2762 |
return; |
| 2763 |
endif; |
| 2764 |
|
| 2765 |
if ( substr($wp_version, 0, 3) < '3.0' ) : |
| 2766 |
if ( !empty($options['custom_fields'][$id]['category']) && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php')) && empty($options['custom_fields'][$id]['template_files']) ) : |
| 2767 |
return; |
| 2768 |
endif; |
| 2769 |
if ( !empty($options['custom_fields'][$id]['template_files']) && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php')) && empty($options['custom_fields'][$id]['category']) ) : |
| 2770 |
return; |
| 2771 |
endif; |
| 2772 |
else : |
| 2773 |
if ( !empty($options['custom_fields'][$id]['category']) && ((isset($_REQUEST['post_type']) && $_REQUEST['post_type']=='page') || $post->post_type=='page') && empty($options['custom_fields'][$id]['template_files']) ) : |
| 2774 |
return; |
| 2775 |
endif; |
| 2776 |
if ( !empty($options['custom_fields'][$id]['template_files']) && ($_REQUEST['post_type']!='page' && $post->post_type!='page') && empty($options['custom_fields'][$id]['category']) ) : |
| 2777 |
return; |
| 2778 |
endif; |
| 2779 |
endif; |
| 2780 |
|
| 2781 |
if ( !empty($options['custom_fields'][$id]['user_id']) ) : |
| 2782 |
$user_ids = explode(',', $options['custom_fields'][$id]['user_id']); |
| 2783 |
$user_ids = array_filter( $user_ids ); |
| 2784 |
$user_ids = array_unique(array_filter(array_map('trim', $user_ids))); |
| 2785 |
if ( !in_array($current_user->ID, $user_ids) ) |
| 2786 |
return; |
| 2787 |
endif; |
| 2788 |
|
| 2789 |
if ( !empty($options['custom_fields'][$id]['user_login']) ) : |
| 2790 |
$user_logins = explode(',', $options['custom_fields'][$id]['user_login']); |
| 2791 |
$user_logins = array_filter( $user_logins ); |
| 2792 |
$user_logins = array_unique(array_filter(array_map('trim', $user_logins))); |
| 2793 |
if ( !in_array($current_user->user_login, $user_logins) ) |
| 2794 |
return; |
| 2795 |
endif; |
| 2796 |
|
| 2797 |
if ( !empty($options['custom_fields'][$id]['user_role']) ) : |
| 2798 |
$user_roles = explode(',', $options['custom_fields'][$id]['user_role']); |
| 2799 |
$user_roles = array_filter( $user_roles ); |
| 2800 |
$user_roles = array_unique(array_filter(array_map('trim', $user_roles))); |
| 2801 |
$user_role_flag = false; |
| 2802 |
foreach ( $user_roles as $user_role ) : |
| 2803 |
if ( current_user_can($user_role) ) : |
| 2804 |
$user_role_flag = true; |
| 2805 |
endif; |
| 2806 |
endforeach; |
| 2807 |
if ( $user_role_flag == false ) return; |
| 2808 |
endif; |
| 2809 |
|
| 2810 |
if ( (!isset($post_id) || $post_id<0) && !empty($options['custom_fields'][$id]['category']) && (isset($_REQUEST['cft_mode']) && $_REQUEST['cft_mode'] != 'ajaxload') ) |
| 2811 |
return; |
| 2812 |
|
| 2813 |
if ( isset($post_id) && !empty($options['custom_fields'][$id]['category']) && (!isset($options['posts'][$post_id]) || (isset($options['posts'][$post_id]) && $options['posts'][$post_id] !== $id)) && ((isset($_REQUEST['cft_mode']) && $_REQUEST['cft_mode'] != 'ajaxload') || (!isset($_REQUEST['cft_mode']) && empty($options['custom_field_template_deploy_box']))) ) |
| 2814 |
return; |
| 2815 |
|
| 2816 |
if ( !isset($_REQUEST['id']) && !empty($options['custom_fields'][$id]['category']) && ((isset($_REQUEST['cft_mode']) && $_REQUEST['cft_mode'] == 'ajaxload') || (!isset($_REQUEST['cft_mode']) && !empty($options['custom_field_template_deploy_box']))) ) : |
| 2817 |
$category = explode(',', $options['custom_fields'][$id]['category']); |
| 2818 |
$category = array_filter( $category ); |
| 2819 |
$category = array_unique(array_filter(array_map('trim', $category))); |
| 2820 |
|
| 2821 |
if ( !empty($options['custom_field_template_deploy_box']) ) : |
| 2822 |
$categories = get_the_category($post_id); |
| 2823 |
$cats = array(); |
| 2824 |
if ( is_array($categories) ) foreach($categories as $cat) $_REQUEST['post_category'][] = $cat->cat_ID; |
| 2825 |
endif; |
| 2826 |
|
| 2827 |
if ( !empty($_REQUEST['tax_input']) && is_array($_REQUEST['tax_input']) ) : |
| 2828 |
foreach($_REQUEST['tax_input'] as $key => $val) : |
| 2829 |
foreach($val as $key2 => $val2 ) : |
| 2830 |
if ( in_array($val2, $category) ) : $notreturn = 1; break; endif; |
| 2831 |
endforeach; |
| 2832 |
endforeach; |
| 2833 |
else : |
| 2834 |
if ( !empty($_REQUEST['post_category']) && is_array($_REQUEST['post_category']) ) : |
| 2835 |
foreach($_REQUEST['post_category'] as $val) : |
| 2836 |
if ( in_array($val, $category) ) : $notreturn = 1; break; endif; |
| 2837 |
endforeach; |
| 2838 |
endif; |
| 2839 |
endif; |
| 2840 |
if ( empty($notreturn) ) return; |
| 2841 |
endif; |
| 2842 |
|
| 2843 |
if ( !empty($options['custom_fields'][$id]['post']) ) : |
| 2844 |
$post_ids = explode(',', $options['custom_fields'][$id]['post']); |
| 2845 |
$post_ids = array_filter( $post_ids ); |
| 2846 |
$post_ids = array_unique(array_filter(array_map('trim', $post_ids))); |
| 2847 |
if ( !in_array($post_id, $post_ids) ) |
| 2848 |
return; |
| 2849 |
endif; |
| 2850 |
|
| 2851 |
if ( !empty($options['custom_fields'][$id]['template_files']) && (isset($post->page_template) || (isset($_REQUEST['page_template']) && $_REQUEST['page_template'])) ) : |
| 2852 |
$template_files = explode(',', $options['custom_fields'][$id]['template_files']); |
| 2853 |
$template_files = array_filter( $template_files ); |
| 2854 |
$template_files = array_unique(array_filter(array_map('trim', $template_files))); |
| 2855 |
if ( isset($_REQUEST['page_template']) ) : |
| 2856 |
if ( !in_array($_REQUEST['page_template'], $template_files) ) : |
| 2857 |
return; |
| 2858 |
endif; |
| 2859 |
else : |
| 2860 |
if ( !in_array($post->page_template, $template_files) ) : |
| 2861 |
return; |
| 2862 |
endif; |
| 2863 |
endif; |
| 2864 |
endif; |
| 2865 |
|
| 2866 |
if ( substr($wp_version, 0, 3) >= '3.3' && !post_type_supports($post->post_type, 'editor') && $post->post_type!='post' && $post->post_type!='page' ) : |
| 2867 |
wp_editor('', 'content', array('dfw' => true, 'tabindex' => 1) ); |
| 2868 |
$out = '<style type="text/css">#wp-content-wrap { display:none; }</style>'; |
| 2869 |
else : |
| 2870 |
$out = ''; |
| 2871 |
endif; |
| 2872 |
|
| 2873 |
if ( !empty($options['custom_fields'][$id]['instruction']) ) : |
| 2874 |
$instruction = $this->EvalBuffer(stripcslashes($options['custom_fields'][$id]['instruction'])); |
| 2875 |
$out .= '<div id="cft_instruction'.$id.'" class="cft_instruction">' . $instruction . '</div>'; |
| 2876 |
endif; |
| 2877 |
|
| 2878 |
$out .= '<div id="cft_'.$id.'">'; |
| 2879 |
$out .= '<div>'; |
| 2880 |
$out .= '<input type="hidden" name="custom-field-template-id[]" id="custom-field-template-id" value="' . $id . '" />'; |
| 2881 |
|
| 2882 |
if ( isset($options['custom_fields'][$id]['format']) && is_numeric($options['custom_fields'][$id]['format']) ) |
| 2883 |
$format = stripslashes($options['shortcode_format'][$options['custom_fields'][$id]['format']]); |
| 2884 |
|
| 2885 |
$last_title = ''; |
| 2886 |
$fieldset_open = 0; |
| 2887 |
$require_from_group = array(); |
| 2888 |
$require_from_group_count = 0; |
| 2889 |
foreach( $fields as $field_key => $field_val ) : |
| 2890 |
foreach( $field_val as $title => $data ) { |
| 2891 |
$class = $style = $addfield = $tmpout = $out_all = $out_key = $out_value = $duplicator = ''; |
| 2892 |
if ( isset($data['parentSN']) && is_numeric($data['parentSN']) ) $parentSN = $data['parentSN']; |
| 2893 |
else $parentSN = $field_key; |
| 2894 |
if ( $fieldset_open ) $data['inside_fieldset'] = 1; |
| 2895 |
if ( isset($data['level']) && is_numeric($data['level']) ) : |
| 2896 |
if ( $data['level'] > $level ) continue; |
| 2897 |
endif; |
| 2898 |
if( $data['type'] == 'break' ) { |
| 2899 |
if ( !empty($data['class']) ) $class = ' class="' . $data['class'] . '"'; |
| 2900 |
if ( !empty($data['style']) ) $style = ' style="' . $data['style'] . '"'; |
| 2901 |
$tmpout .= '</div><div' . $class . $style . '>'; |
| 2902 |
} |
| 2903 |
else if( $data['type'] == 'fieldset_open' ) { |
| 2904 |
$fieldset_open = 1; |
| 2905 |
if ( !empty($data['class']) ) $class = ' class="' . $data['class'] . '"'; |
| 2906 |
if ( !empty($data['style']) ) $style = ' style="' . $data['style'] . '"'; |
| 2907 |
$tmpout .= '<fieldset' . $class . $style . '>'."\n"; |
| 2908 |
$tmpout .= '<input type="hidden" name="' . $this->sanitize_name( $title ) . '[]" value="1" />'."\n"; |
| 2909 |
|
| 2910 |
if ( isset($data['multipleButton']) && $data['multipleButton'] == true ) : |
| 2911 |
$addfield .= ' <span>'; |
| 2912 |
if ( isset($post_id) ) $addbutton = (int)$this->get_post_meta( $post_id, $title, true )-1; |
| 2913 |
if ( !isset($addbutton) || $addbutton<=0 ) $addbutton = 0; |
| 2914 |
if ( $data['cftnum']/2 == $addbutton ) : |
| 2915 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 2916 |
$load_htmlEditor1 = 'if ( jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_qtags\').html() ) {jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_qtags\').remove();'; |
| 2917 |
$load_htmlEditor2 = 'qt_set(textarea_html_ids[i]);'; |
| 2918 |
$load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, textarea_tmce_ids[i]); switchMode(textarea_tmce_ids[i]); switchMode(textarea_tmce_ids[i]);'; |
| 2919 |
elseif ( substr($wp_version, 0, 3) < '3.9' ) : |
| 2920 |
$load_htmlEditor1 = 'if ( jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_toolbar\').html() ) {jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_toolbar\').remove();'; |
| 2921 |
$load_htmlEditor2 = 'new QTags(textarea_html_ids[i]);QTags._buttonsInit();'; |
| 2922 |
$load_tinyMCE = 'var ed = new tinyMCE.Editor(textarea_tmce_ids[i], tinyMCEPreInit.mceInit[\'content\']); ed.render(); switchMode(textarea_tmce_ids[i]); switchMode(textarea_tmce_ids[i]);'; |
| 2923 |
else : |
| 2924 |
$load_htmlEditor1 = 'if ( jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_toolbar\').html() ) {jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_toolbar\').remove();'; |
| 2925 |
$load_htmlEditor2 = 'new QTags(textarea_html_ids[i]);QTags._buttonsInit();'; |
| 2926 |
$load_tinyMCE = 'tinyMCE.execCommand('."'mceAddEditor'".', true, textarea_tmce_ids[i]); switchMode(textarea_tmce_ids[i]); switchMode(textarea_tmce_ids[i]);'; |
| 2927 |
endif; |
| 2928 |
$addfield .= '<input type="hidden" id="' . $this->sanitize_name( $title ) . '_count" value="0" /><script type="text/javascript">jQuery(document).ready(function() {jQuery(\'#' . $this->sanitize_name( $title ) . '_count\').val(0); });</script>'; |
| 2929 |
$addfield .= ' <a href="#clear" onclick="var textarea_tmce_ids = new Array();var textarea_html_ids = new Array();var html_start = 0;jQuery(this).parent().parent().parent().find('."'textarea'".').each(function(){if ( jQuery(this).attr('."'id'".') ) {'.$load_htmlEditor1.'textarea_html_ids.push(jQuery(this).attr('."'id'".'));}}ed = tinyMCE.get(jQuery(this).attr('."'id'".')); if(ed) {textarea_tmce_ids.push(jQuery(this).attr('."'id'".'));tinymce.remove('."'#'".'+jQuery(this).attr('."'id'".'));}});var checked_ids = new Array();jQuery(this).parent().parent().parent().find('."'input[type=radio]:checked'".').each(function(){checked_ids.push(jQuery(this).attr('."'id'".'));});var tmp = jQuery(this).parent().parent().parent().clone().insertAfter(jQuery(this).parent().parent().parent());tmp.find('."'input'".').attr('."'checked',false".');for( var i=0;i<checked_ids.length;i++) { jQuery('."'#'+checked_ids[i]".').attr('."'checked'".', true); }tmp.find('."'input[type=text],input[type=hidden],input[type=file]'".').val('."''".');tmp.find('."'select'".').val('."''".');tmp.find('."'textarea'".').text('."''".');tmp.find('."'p'".').remove();tmp.find('."'dl'".').each(function(){if(jQuery(this).attr('."'id'".')){if(jQuery(this).attr('."'id'".').match(/_([0-9]+)$/)) {matchval = RegExp.$1;matchval++;jQuery(this).attr('."'id',".'jQuery(this).attr('."'id'".').replace(/_([0-9]+)$/, \'_\'+matchval));jQuery(this).find('."'textarea'".').each(function(){if(jQuery(this).attr('."'id'".').match(/([0-9]+)$/)) { matchval2 = RegExp.$1; var tmce_check = false;var html_check = false; for( var i=0;i<textarea_tmce_ids.length;i++) { if ( jQuery(this).attr('."'id'".')==textarea_tmce_ids[i] ) { tmce_check = true; } }for( var i=0;i<textarea_html_ids.length;i++) { if ( jQuery(this).attr('."'id'".')==textarea_html_ids[i] ) { html_check = true; } } if ( tmce_check || html_check ) {jQuery(this).attr('."'id',".'jQuery(this).attr('."'id'".').replace(/([0-9]+)$/, parseInt(matchval2)+1));re = new RegExp(matchval2, '."'ig'".');jQuery(this).parent().parent().parent().html(jQuery(this).parent().parent().parent().html().replace(re, parseInt(matchval2)+1));if ( tmce_check ) textarea_tmce_ids.push(jQuery(this).attr('."'id'".'));if ( html_check ) textarea_html_ids.push(jQuery(this).attr('."'id'".')); }}jQuery(this).attr('."'name',".'jQuery(this).attr('."'name'".').replace(/\[([0-9]+)\]$/, \'[\'+matchval+\']\'));}); jQuery(this).find('."'input'".').each(function(){if(jQuery(this).attr('."'id'".')){jQuery(this).attr('."'id',".'jQuery(this).attr('."'id'".').replace(/_([0-9]+)_/, \'_\'+matchval+\'_\'));jQuery(this).attr('."'id',".'jQuery(this).attr('."'id'".').replace(/_([0-9]+)$/, \'_\'+matchval));}if(jQuery(this).attr('."'name'".')){jQuery(this).attr('."'name',".'jQuery(this).attr('."'name'".').replace(/\[([0-9]+)\]$/, \'[\'+matchval+\']\'));}});jQuery(this).find('."'label'".').each(function(){jQuery(this).attr('."'for',".'jQuery(this).attr('."'for'".').replace(/_([0-9]+)_/, \'_\'+matchval+\'_\'));jQuery(this).attr('."'for',".'jQuery(this).attr('."'for'".').replace(/_([0-9]+)$/, \'_\'+matchval));jQuery(this).attr('."'for',".'jQuery(this).attr('."'for'".').replace(/\[([0-9]+)\]$/, \'[\'+matchval+\']\'));});}}}); for( var i=html_start;i<textarea_html_ids.length;i++) { '.$load_htmlEditor2.' } for( var i=html_start;i<textarea_tmce_ids.length;i++) { '.$load_tinyMCE.' }jQuery(this).parent().css('."'visibility','hidden'".');jQuery(\'#'.$this->sanitize_name( $title ).'_count\').val(parseInt(jQuery(\'#'.$this->sanitize_name( $title ).'_count\').val())+1);return false;">' . __('Add New', 'custom-field-template') . '</a>'; |
| 2930 |
else : |
| 2931 |
$addfield .= ' <a href="#clear" onclick="jQuery(this).parent().parent().parent().remove();return false;">' . __('Delete', 'custom-field-template') . '</a>'; |
| 2932 |
endif; |
| 2933 |
$addfield .= '</span>'; |
| 2934 |
endif; |
| 2935 |
|
| 2936 |
if ( isset($data['legend']) || isset($addfield) ) : |
| 2937 |
if ( !isset($data['legend']) ) $data['legend'] = ''; |
| 2938 |
if ( !isset($addfield) ) $addfield = ''; |
| 2939 |
$tmpout .= '<legend>' . esc_html(stripcslashes(trim($data['legend']))) . $addfield . '</legend>'; |
| 2940 |
endif; |
| 2941 |
} |
| 2942 |
else if( $data['type'] == 'fieldset_close' ) { |
| 2943 |
$fieldset_open = 0; |
| 2944 |
$tmpout .= '</fieldset>'; |
| 2945 |
} |
| 2946 |
else if( $data['type'] == 'textfield' || $data['type'] == 'text' ) { |
| 2947 |
list($out_all,$out_key,$out_value) = $this->make_textfield( $title, $parentSN, $data, $post_id ); |
| 2948 |
} |
| 2949 |
else if( $data['type'] == 'checkbox' ) { |
| 2950 |
list($out_all,$out_key,$out_value) = $this->make_checkbox( $title, $parentSN, $data, $post_id ); |
| 2951 |
} |
| 2952 |
else if( $data['type'] == 'radio' ) { |
| 2953 |
$data['values'] = explode( '#', $data['value'] ); |
| 2954 |
if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] ); |
| 2955 |
list($out_all,$out_key,$out_value) = $this->make_radio( $title, $parentSN, $data, $post_id ); |
| 2956 |
} |
| 2957 |
else if( $data['type'] == 'select' ) { |
| 2958 |
if ( isset($data['value']) ) $data['values'] = explode( '#', $data['value'] ); |
| 2959 |
if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] ); |
| 2960 |
list($out_all,$out_key,$out_value) = $this->make_select( $title, $parentSN, $data, $post_id ); |
| 2961 |
} |
| 2962 |
else if( $data['type'] == 'textarea' ) { |
| 2963 |
list($out_all,$out_key,$out_value) = $this->make_textarea( $title, $parentSN, $data, $post_id ); |
| 2964 |
} |
| 2965 |
else if( $data['type'] == 'file' ) { |
| 2966 |
if ( !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') ) : |
| 2967 |
list($out_all,$out_key,$out_value) = $this->make_file( $title, $parentSN, $data, $post_id ); |
| 2968 |
endif; |
| 2969 |
} |
| 2970 |
if ( isset($options['custom_fields'][$id]['format']) && is_numeric($options['custom_fields'][$id]['format']) ) : |
| 2971 |
$duplicator = '['.$title.']'; |
| 2972 |
$preg_key = preg_quote($title, '/'); |
| 2973 |
$out_key = str_replace('\\', '\\\\', $out_key); |
| 2974 |
$out_key = str_replace('$', '\$', $out_key); |
| 2975 |
$out_value = str_replace('\\', '\\\\', $out_value); |
| 2976 |
$out_value = str_replace('$', '\$', $out_value); |
| 2977 |
$format = preg_replace('/\[\['.$preg_key.'\]\]/', $out_key, $format); |
| 2978 |
$format = preg_replace('/\['.$preg_key.'\]/', $out_value.$duplicator, $format); |
| 2979 |
if ( !empty($last_title) && $last_title != $title ) $format = preg_replace('/\['.preg_quote($last_title,'/').'\]/', '', $format); |
| 2980 |
$last_title = $title; |
| 2981 |
else : |
| 2982 |
$out .= $tmpout.$out_all; |
| 2983 |
endif; |
| 2984 |
if ( isset($data['class']) && preg_match('/required_([0-9]+)_([0-9]+)/', $data['class'], $required_match) ) : |
| 2985 |
$require_from_group[$require_from_group_count]['name'] = $title.'['.$parentSN.'][]'; |
| 2986 |
$require_from_group[$require_from_group_count]['identifier'] = $required_match[1]; |
| 2987 |
$require_from_group[$require_from_group_count]['partnumber'] = $required_match[2]; |
| 2988 |
$require_from_group_count++; |
| 2989 |
endif; |
| 2990 |
} |
| 2991 |
endforeach; |
| 2992 |
if ( !empty($last_title) ) $format = preg_replace('/\['.preg_quote($last_title,'/').'\]/', '', $format); |
| 2993 |
if ( isset($options['custom_fields'][$id]['format']) && is_numeric($options['custom_fields'][$id]['format']) ) $out .= $format; |
| 2994 |
|
| 2995 |
$out .= '<script type="text/javascript">' . "\n" . |
| 2996 |
'// <![CDATA[' . "\n"; |
| 2997 |
$out .= ' jQuery(document).ready(function() {' . "\n" . |
| 2998 |
' jQuery("#custom_field_template_select").val("' . $id . '");' . "\n"; |
| 2999 |
if ( !empty($require_from_group) ) : |
| 3000 |
for ( $i=0; $i<$require_from_group_count; $i++ ) : |
| 3001 |
$out .= ' jQuery('."'[name='+ |
| 3002 |
jQuery.escapeSelector('".$require_from_group[$i]['name']."')+']'".').rules("add", { require_from_group: ['.$require_from_group[$i]['partnumber'].', ".required_'.$require_from_group[$i]['identifier'].'_'.$require_from_group[$i]['partnumber'].'"] });'."\n"; |
| 3003 |
endfor; |
| 3004 |
endif; |
| 3005 |
$out .= ' });' . "\n"; |
| 3006 |
$out .= '// ]]>' . "\n" . |
| 3007 |
'</script>'; |
| 3008 |
$out .= '</div>'; |
| 3009 |
$out .= '</div>'; |
| 3010 |
|
| 3011 |
return array($out, $id); |
| 3012 |
} |
| 3013 |
|
| 3014 |
function insert_custom_field($post, $args) { |
| 3015 |
global $wp_version, $post, $wpdb; |
| 3016 |
$options = $this->get_custom_field_template_data(); |
| 3017 |
$out = ''; |
| 3018 |
|
| 3019 |
if( $options == null) |
| 3020 |
return; |
| 3021 |
|
| 3022 |
if ( empty($options['css']) ) { |
| 3023 |
$this->install_custom_field_template_css(); |
| 3024 |
$options = $this->get_custom_field_template_data(); |
| 3025 |
} |
| 3026 |
|
| 3027 |
if ( substr($wp_version, 0, 3) < '2.5' ) { |
| 3028 |
$out .= ' |
| 3029 |
<div class="dbx-b-ox-wrapper"> |
| 3030 |
<fieldset id="seodiv" class="dbx-box"> |
| 3031 |
<div class="dbx-h-andle-wrapper"> |
| 3032 |
<h3 class="dbx-handle">' . __('Custom Field Template', 'custom-field-template') . '</h3> |
| 3033 |
</div> |
| 3034 |
<div class="dbx-c-ontent-wrapper"> |
| 3035 |
<div class="dbx-content">'; |
| 3036 |
} |
| 3037 |
|
| 3038 |
if ( isset($args['args']['cft_id']) ) : |
| 3039 |
$init_id = $args['args']['cft_id']; |
| 3040 |
$suffix = $args['args']['cft_id']; |
| 3041 |
$suffix2 = '_'.$args['args']['cft_id']; |
| 3042 |
$suffix3 = $args['args']['cft_id']; |
| 3043 |
else : |
| 3044 |
if ( isset($_REQUEST['post']) ) $request_post = $_REQUEST['post']; |
| 3045 |
else $request_post = ''; |
| 3046 |
if( isset($options['posts'][$request_post]) && count($options['custom_fields'])>$options['posts'][$request_post] ) : |
| 3047 |
$init_id = $options['posts'][$request_post]; |
| 3048 |
else : |
| 3049 |
$filtered_cfts = $this->custom_field_template_filter(); |
| 3050 |
if ( count($filtered_cfts)>0 ) : |
| 3051 |
$init_id = $filtered_cfts[0]['id']; |
| 3052 |
else : |
| 3053 |
$init_id = 0; |
| 3054 |
endif; |
| 3055 |
endif; |
| 3056 |
$suffix = ''; |
| 3057 |
$suffix2 = ''; |
| 3058 |
$suffix3 = '\'+jQuery(\'#custom-field-template-id\').val()+\''; |
| 3059 |
endif; |
| 3060 |
|
| 3061 |
$out .= '<script type="text/javascript">' . "\n" . |
| 3062 |
'// <![CDATA[' . "\n"; |
| 3063 |
$out .= 'jQuery(document).ready(function() {' . "\n"; |
| 3064 |
|
| 3065 |
$fields = $this->get_custom_fields( $init_id ); |
| 3066 |
if ( user_can_richedit() ) : |
| 3067 |
if ( is_array($fields) ) : |
| 3068 |
foreach( $fields as $field_key => $field_val ) : |
| 3069 |
foreach( $field_val as $title => $data ) : |
| 3070 |
if( $data[ 'type' ] == 'textarea' && !empty($data['tinyMCE']) ) : |
| 3071 |
if ( substr($wp_version, 0, 3) >= '2.7' ) : |
| 3072 |
/*$out .= ' if ( getUserSetting( "editor" ) == "html" ) { |
| 3073 |
jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/ |
| 3074 |
else : |
| 3075 |
$out .= ' if(wpTinyMCEConfig) if(wpTinyMCEConfig.defaultEditor == "html") { jQuery("#edButtonPreview").trigger("click"); }' . "\n"; |
| 3076 |
endif; |
| 3077 |
break; |
| 3078 |
endif; |
| 3079 |
endforeach; |
| 3080 |
endforeach; |
| 3081 |
endif; |
| 3082 |
endif; |
| 3083 |
|
| 3084 |
if ( empty($options['custom_field_template_deploy_box']) && !empty($options['custom_fields']) ) : |
| 3085 |
if ( substr($wp_version, 0, 3) < '3.0' ) $taxonomy = 'categories'; |
| 3086 |
else $taxonomy = 'category'; |
| 3087 |
|
| 3088 |
foreach ( $options['custom_fields'] as $key => $val ) : |
| 3089 |
if ( !empty($val['category']) ) : |
| 3090 |
$categories = $this->sanitize_integer_list( $val['category'] ); |
| 3091 |
if ( empty( $categories ) ) continue; |
| 3092 |
|
| 3093 |
$placeholders = implode( ',', array_fill( 0, count( $categories ), '%d' ) ); |
| 3094 |
$query_args = array_merge( array( "SELECT * FROM `".$wpdb->prefix."term_taxonomy` WHERE term_id IN (" . $placeholders . ")" ), $categories ); |
| 3095 |
$query = call_user_func_array( array( $wpdb, 'prepare' ), $query_args ); |
| 3096 |
$result = $wpdb->get_results($query, ARRAY_A); |
| 3097 |
$category_taxonomy = array(); |
| 3098 |
if ( !empty($result) && is_array($result) ) : |
| 3099 |
for($i=0;$i<count($result);$i++) : |
| 3100 |
$category_taxonomy[absint($result[$i]['term_id'])] = sanitize_key($result[$i]['taxonomy']); |
| 3101 |
endfor; |
| 3102 |
endif; |
| 3103 |
foreach($categories as $cat_id) : |
| 3104 |
$cat_id = absint( $cat_id ); |
| 3105 |
if ( $cat_id && ! empty( $category_taxonomy[$cat_id] ) ) : |
| 3106 |
$cat_taxonomy = $category_taxonomy[$cat_id]; |
| 3107 |
if ( $taxonomy == 'category' ) $taxonomy = $cat_taxonomy; |
| 3108 |
$out .= 'jQuery(\'#in-'.$cat_taxonomy.'-' . $cat_id . '\').click(function(){if(jQuery(\'#in-'.$cat_taxonomy.'-' . $cat_id . '\').attr(\'checked\') == true) { if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID.length=0;}; jQuery.get(\'?page=custom-field-template/custom-field-template.php&cft_mode=selectbox&post=\'+jQuery(\'#post_ID\').val()+\'&\'+jQuery(\'#'.$taxonomy.'-all :input\').fieldSerialize(), function(html) { jQuery(\'#cft_selectbox\').html(html);'; |
| 3109 |
if ( !empty($options['custom_field_template_use_autosave']) ) : |
| 3110 |
$out .= ' var fields = jQuery(\'#cft'.$suffix.' :input\').fieldSerialize();'; |
| 3111 |
$out .= 'jQuery.ajax({type: \'POST\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post=\'+jQuery(\'#post_ID\').val()+\'&custom-field-template-verify-key=\'+jQuery(\'#custom-field-template-verify-key\').val()+\'&\'+fields, success: function(){jQuery(\'#custom_field_template_select\').val(\'' . $key . '\');jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=' . $key . '&post=\'+jQuery(\'#post_ID\').val(), success: function(html) {'; |
| 3112 |
if ( !empty($options['custom_field_template_replace_the_title']) ) : |
| 3113 |
$out .= 'jQuery(\'#cftdiv'.$suffix.' h3 span\').text(\'' . esc_js( stripcslashes( $options['custom_fields'][$key]['title'] ) ) . '\');'; |
| 3114 |
endif; |
| 3115 |
$out .= 'jQuery(\'#cft\').html(html);}});}});'; |
| 3116 |
else : |
| 3117 |
$out .= ' jQuery(\'#custom_field_template_select\').val(\'' . $key . '\');jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=' . $key . '&post=\'+jQuery(\'#post_ID\').val()+\'&\'+jQuery(\'#'.$taxonomy.'-all :input\').fieldSerialize(), success: function(html) {'; |
| 3118 |
if ( !empty($options['custom_field_template_replace_the_title']) ) : |
| 3119 |
$out .= 'jQuery(\'#cftdiv'.$suffix.' h3 span\').text(\'' . esc_js( stripcslashes( $options['custom_fields'][$key]['title'] ) ) . '\');'; |
| 3120 |
endif; |
| 3121 |
$out .= 'jQuery(\'#cft\').html(html);}});'; |
| 3122 |
endif; |
| 3123 |
$out .= ' });'; |
| 3124 |
|
| 3125 |
$out .= ' }else{ jQuery(\'#cft\').html(\'\');jQuery.get(\'?page=custom-field-template/custom-field-template.php&cft_mode=selectbox&post=\'+jQuery(\'#post_ID\').val()+\'&\'+jQuery(\'#'.$taxonomy.'-all :input\').fieldSerialize(), function(html) { jQuery(\'#cft_selectbox\').html(html); jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&post=\'+jQuery(\'#post_ID\').val()+\'&\'+jQuery(\'#'.$taxonomy.'-all :input\').fieldSerialize(), success: function(html) { jQuery(\'#cft\').html(html);}}); });'; |
| 3126 |
if ( !empty($options['custom_field_template_replace_the_title']) ) : |
| 3127 |
$out .= 'jQuery(\'#cftdiv'.$suffix.' h3 span\').text(\'' . esc_js( __('Custom Field Template', 'custom-field-template') ) . '\');'; |
| 3128 |
endif; |
| 3129 |
$out .= '}});' . "\n"; |
| 3130 |
endif; |
| 3131 |
endforeach; |
| 3132 |
endif; |
| 3133 |
endforeach; |
| 3134 |
endif; |
| 3135 |
|
| 3136 |
if ( empty($options['custom_field_template_deploy_box']) && 0 != count( get_page_templates() ) ): |
| 3137 |
$post_type = empty($_REQUEST['post_type']) || ! is_scalar( $_REQUEST['post_type'] ) ? 'post' : sanitize_key( wp_unslash( $_REQUEST['post_type'] ) ); |
| 3138 |
$out .= 'jQuery(\'#page_template\').change(function(){ if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID.length=0;}; jQuery.get(\'?post_type='.rawurlencode($post_type).'&page=custom-field-template/custom-field-template.php&cft_mode=selectbox&post=\'+jQuery(\'#post_ID\').val()+\'&page_template=\'+jQuery(\'#page_template\').val(), function(html) { jQuery(\'#cft_selectbox\').html(html); jQuery.ajax({type: \'GET\', url: \'?post_type='.rawurlencode($post_type).'&page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&page_template=\'+jQuery(\'#page_template\').val()+\'&post=\'+jQuery(\'#post_ID\').val(), success: function(html) { jQuery(\'#cft\').html(html);'; |
| 3139 |
if ( !empty($options['custom_field_template_replace_the_title']) ) : |
| 3140 |
$out .= 'if(html) { jQuery(\'#cftdiv'.$suffix.' h3 span\').text(jQuery(\'#custom_field_template_select :selected\').text());}'; |
| 3141 |
endif; |
| 3142 |
$out .= '}});});'; |
| 3143 |
$out .= '});' . "\n"; |
| 3144 |
endif; |
| 3145 |
|
| 3146 |
$out .= ' jQuery(\'#cftloading_img'.$suffix.'\').ajaxStart(function() { jQuery(this).show();});'; |
| 3147 |
$out .= ' jQuery(\'#cftloading_img'.$suffix.'\').ajaxStop(function() { jQuery(this).hide();});'; |
| 3148 |
$out .= '});' . "\n"; |
| 3149 |
|
| 3150 |
$out .= 'var tinyMCEID = new Array();' . "\n" . |
| 3151 |
'// ]]>' . "\n" . |
| 3152 |
'</script>'; |
| 3153 |
list($body, $init_id) = $this->load_custom_field($init_id); |
| 3154 |
|
| 3155 |
if ( empty($options['custom_field_template_deploy_box']) ) : |
| 3156 |
$out .= '<div id="cft_selectbox">'; |
| 3157 |
$out .= $this->custom_field_template_selectbox(); |
| 3158 |
$out .= '</div>'; |
| 3159 |
else : |
| 3160 |
$out .= '<div> </div>'; |
| 3161 |
endif; |
| 3162 |
|
| 3163 |
$out .= '<div id="cft'.$suffix.'" class="cft">'; |
| 3164 |
$out .= $body; |
| 3165 |
$out .= '</div>'; |
| 3166 |
|
| 3167 |
if ( substr($wp_version, 0, 3) < '3.3' ) : |
| 3168 |
$top_margin = 30; |
| 3169 |
else : |
| 3170 |
$top_margin = 0; |
| 3171 |
endif; |
| 3172 |
|
| 3173 |
$out .= '<div style="position:absolute; top:'.$top_margin.'px; right:5px;">'; |
| 3174 |
$out .= '<img class="waiting" style="display:none; vertical-align:middle;" src="images/loading.gif" alt="" id="cftloading_img'.$suffix.'" /> '; |
| 3175 |
if ( !empty($options['custom_field_template_use_disable_button']) ) : |
| 3176 |
$out .= '<input type="hidden" id="disable_value" value="0" />'; |
| 3177 |
$out .= '<input type="button" value="' . __('Disable', 'custom-field-template') . '" onclick="'; |
| 3178 |
$out .= 'if(jQuery(\'#disable_value\').val()==0) { jQuery(\'#disable_value\').val(1);jQuery(this).val(\''.__('Enable', 'custom-field-template').'\');jQuery(\'#cft'.$suffix2.' input, #cft'.$suffix2.' select, #cft'.$suffix2.' textarea\').attr(\'disabled\',true);}else{ jQuery(\'#disable_value\').val(0);jQuery(this).val(\''.__('Disable', 'custom-field-template').'\');jQuery(\'#cft'.$suffix2.' input, #cft_'.$init_id.' select, #cft'.$suffix2.' textarea\').attr(\'disabled\',false);}'; |
| 3179 |
$out .= '" class="button" style="vertical-align:middle;" />'; |
| 3180 |
endif; |
| 3181 |
if ( empty($options['custom_field_template_disable_initialize_button']) ) : |
| 3182 |
$out .= '<input type="button" value="' . __('Initialize', 'custom-field-template') . '" onclick="'; |
| 3183 |
$out .= 'if(confirm(\''.__('Are you sure to reset current values? Default values will be loaded.', 'custom-field-template').'\')){if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID.length=0;};jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&default=true&id='.$suffix3.'&post=\'+jQuery(\'#post_ID\').val(), success: function(html) {'; |
| 3184 |
$out .= 'jQuery(\'#cft'.$suffix2.'\').html(html);}});}'; |
| 3185 |
$out .= '" class="button" style="vertical-align:middle;" />'; |
| 3186 |
endif; |
| 3187 |
if ( empty($options['custom_field_template_disable_save_button']) ) : |
| 3188 |
$out .= '<input type="button" id="cft_save_button'.$suffix.'" value="' . __('Save', 'custom-field-template') . '" onclick="'; |
| 3189 |
if ( !empty($options['custom_field_template_use_validation']) ) : |
| 3190 |
$out .= 'if(!jQuery(\'#post\').valid()) return false;'; |
| 3191 |
endif; |
| 3192 |
$out .= 'tinyMCE.triggerSave(); var fields = jQuery(\'#cft'.$suffix2.' :input\').fieldSerialize();'; |
| 3193 |
$out .= 'jQuery.ajax({type: \'POST\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post=\'+jQuery(\'#post_ID\').val()+\'&custom-field-template-verify-key=\'+jQuery(\'#custom-field-template-verify-key\').val(), data: fields, success: function() {jQuery(\'.delete_file_checkbox:checked\').each(function() {jQuery(this).parent().parent().next().val(\'\');jQuery(this).parent().parent().remove();});}});'; |
| 3194 |
$out .= '" class="button" style="vertical-align:middle;" />'; |
| 3195 |
endif; |
| 3196 |
$out .= '</div>'; |
| 3197 |
|
| 3198 |
if ( substr($wp_version, 0, 3) < '2.5' ) { |
| 3199 |
$out .= '</div></fieldset></div>'; |
| 3200 |
} else { |
| 3201 |
if ( $body && !empty($options['custom_field_template_replace_the_title']) && empty($options['custom_field_template_deploy_box']) ) : |
| 3202 |
$out .= '<script type="text/javascript">' . "\n" . '// <![CDATA[' . "\n"; |
| 3203 |
$out .= 'jQuery(document).ready(function() {jQuery(\'#cftdiv h3 span\').text(\'' . esc_js( stripcslashes( $options['custom_fields'][$init_id]['title'] ) ) . '\');});' . "\n"; |
| 3204 |
$out .= '// ]]>' . "\n" . '</script>'; |
| 3205 |
endif; |
| 3206 |
} |
| 3207 |
|
| 3208 |
$out .= '<div style="clear:both;"></div>'; |
| 3209 |
echo $out; |
| 3210 |
} |
| 3211 |
|
| 3212 |
function custom_field_template_filter(){ |
| 3213 |
global $current_user, $post, $wp_version; |
| 3214 |
|
| 3215 |
$options = $this->get_custom_field_template_data(); |
| 3216 |
$filtered_cfts = array(); |
| 3217 |
|
| 3218 |
$post_id = isset($_REQUEST['post']) && is_scalar( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : 0; |
| 3219 |
if ( empty($post) && $post_id ) $post = get_post($post_id); |
| 3220 |
|
| 3221 |
$categories = get_the_category($post_id); |
| 3222 |
$cats = array(); |
| 3223 |
if ( is_array($categories) ) foreach($categories as $category) $cats[] = $category->cat_ID; |
| 3224 |
|
| 3225 |
if ( !empty($_REQUEST['tax_input']) && is_array($_REQUEST['tax_input']) ) : |
| 3226 |
foreach($_REQUEST['tax_input'] as $key => $val) : |
| 3227 |
if ( is_array( $val ) ) $cats = array_merge($cats, $this->sanitize_integer_list( $val ) ); |
| 3228 |
endforeach; |
| 3229 |
elseif ( !empty($_REQUEST['post_category']) && is_array( $_REQUEST['post_category'] ) ) : |
| 3230 |
$cats = array_merge($cats, $this->sanitize_integer_list( $_REQUEST['post_category'] ) ); |
| 3231 |
endif; |
| 3232 |
|
| 3233 |
for ( $i=0; $i < count($options['custom_fields']); $i++ ) : |
| 3234 |
unset($cat_ids, $template_files, $post_ids); |
| 3235 |
if ( !empty($options['custom_fields'][$i]['post_type']) ) : |
| 3236 |
if ( substr($wp_version, 0, 3) < '3.0' ) : |
| 3237 |
if ( $options['custom_fields'][$i]['post_type'] == 'post' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php')) ) : |
| 3238 |
continue; |
| 3239 |
endif; |
| 3240 |
if ( $options['custom_fields'][$i]['post_type'] == 'page' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php')) ) : |
| 3241 |
continue; |
| 3242 |
endif; |
| 3243 |
else : |
| 3244 |
if ( $post->post_type!=$options['custom_fields'][$i]['post_type'] ) : |
| 3245 |
continue; |
| 3246 |
endif; |
| 3247 |
endif; |
| 3248 |
endif; |
| 3249 |
|
| 3250 |
if ( !empty($options['custom_fields'][$i]['custom_post_type']) ) : |
| 3251 |
$custom_post_type = explode(',', $options['custom_fields'][$i]['custom_post_type']); |
| 3252 |
$custom_post_type = array_filter( $custom_post_type ); |
| 3253 |
$custom_post_type = array_unique(array_filter(array_map('trim', $custom_post_type))); |
| 3254 |
if ( !in_array($post->post_type, $custom_post_type) ) |
| 3255 |
continue; |
| 3256 |
endif; |
| 3257 |
|
| 3258 |
$cat_ids = isset($options['custom_fields'][$i]['category']) ? explode(',', $options['custom_fields'][$i]['category']) : array(); |
| 3259 |
$template_files = isset($options['custom_fields'][$i]['template_files']) ? explode(',', $options['custom_fields'][$i]['template_files']) : array(); |
| 3260 |
$post_ids = isset($options['custom_fields'][$i]['post']) ? explode(',', $options['custom_fields'][$i]['post']) : array(); |
| 3261 |
$user_ids = isset($options['custom_fields'][$i]['user_id']) ? explode(',', $options['custom_fields'][$i]['user_id']) : array(); |
| 3262 |
$user_logins = isset($options['custom_fields'][$i]['user_login']) ? explode(',', $options['custom_fields'][$i]['user_login']) : array(); |
| 3263 |
$user_roles = isset($options['custom_fields'][$i]['user_role']) ? explode(',', $options['custom_fields'][$i]['user_role']) : array(); |
| 3264 |
$cat_ids = array_filter( $cat_ids ); |
| 3265 |
$template_files = array_filter( $template_files ); |
| 3266 |
$post_ids = array_filter( $post_ids ); |
| 3267 |
$user_ids = array_filter( $user_ids ); |
| 3268 |
$user_logins = array_filter( $user_logins ); |
| 3269 |
$user_roles = array_filter( $user_roles ); |
| 3270 |
$cat_ids = array_unique(array_filter(array_map('trim', $cat_ids))); |
| 3271 |
$template_files = array_unique(array_filter(array_map('trim', $template_files))); |
| 3272 |
$post_ids = array_unique(array_filter(array_map('trim', $post_ids))); |
| 3273 |
$user_ids = array_unique(array_filter(array_map('trim', $user_ids))); |
| 3274 |
$user_logins = array_unique(array_filter(array_map('trim', $user_logins))); |
| 3275 |
$user_roles = array_unique(array_filter(array_map('trim', $user_roles))); |
| 3276 |
|
| 3277 |
if ( !empty($template_files) ) : |
| 3278 |
if ( (strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') || strstr($_SERVER['REQUEST_URI'], 'post_type=page') || $post->post_type=='page') ) : |
| 3279 |
if ( count($template_files) && (isset($post->page_template) || isset($_REQUEST['page_template'])) ) : |
| 3280 |
if( !in_array($post->page_template, $template_files) && (!isset($_REQUEST['page_template']) || (isset($_REQUEST['page_template']) && !in_array($_REQUEST['page_template'], $template_files))) ) : |
| 3281 |
continue; |
| 3282 |
endif; |
| 3283 |
else : |
| 3284 |
continue; |
| 3285 |
endif; |
| 3286 |
else : |
| 3287 |
continue; |
| 3288 |
endif; |
| 3289 |
endif; |
| 3290 |
|
| 3291 |
if ( !empty($user_ids) ) : |
| 3292 |
if ( !in_array($current_user->ID, $user_ids) ) |
| 3293 |
continue; |
| 3294 |
endif; |
| 3295 |
|
| 3296 |
if ( !empty($user_logins) ) : |
| 3297 |
if ( !in_array($current_user->user_login, $user_logins) ) |
| 3298 |
continue; |
| 3299 |
endif; |
| 3300 |
|
| 3301 |
if ( !empty($user_roles) ) : |
| 3302 |
$user_role_flag = false; |
| 3303 |
foreach ( $user_roles as $user_role ) : |
| 3304 |
if ( current_user_can($user_role) ) : |
| 3305 |
$user_role_flag = true; |
| 3306 |
endif; |
| 3307 |
endforeach; |
| 3308 |
if ( $user_role_flag == false ) continue; |
| 3309 |
endif; |
| 3310 |
|
| 3311 |
if ( count($post_ids) && (!isset($_REQUEST['post']) || (isset($_REQUEST['post']) && !in_array($_REQUEST['post'], $post_ids))) ) : |
| 3312 |
continue; |
| 3313 |
endif; |
| 3314 |
|
| 3315 |
if ( !empty($cat_ids) ) : |
| 3316 |
if ( (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php')) ) : |
| 3317 |
if ( is_array($cat_ids) && count($cat_ids) && count($cats)>0 ) : |
| 3318 |
$cat_match = 0; |
| 3319 |
foreach ( $cat_ids as $cat_id ) : |
| 3320 |
if (in_array($cat_id, $cats) ) : |
| 3321 |
$cat_match = 1; |
| 3322 |
endif; |
| 3323 |
endforeach; |
| 3324 |
if($cat_match == 0) : |
| 3325 |
continue; |
| 3326 |
endif; |
| 3327 |
else : |
| 3328 |
continue; |
| 3329 |
endif; |
| 3330 |
else : |
| 3331 |
continue; |
| 3332 |
endif; |
| 3333 |
endif; |
| 3334 |
|
| 3335 |
$options['custom_fields'][$i]['id'] = $i; |
| 3336 |
$filtered_cfts[] = $options['custom_fields'][$i]; |
| 3337 |
endfor; |
| 3338 |
return $filtered_cfts; |
| 3339 |
} |
| 3340 |
|
| 3341 |
function custom_field_template_selectbox() { |
| 3342 |
$options = $this->get_custom_field_template_data(); |
| 3343 |
|
| 3344 |
if( count($options['custom_fields']) < 2 ) : |
| 3345 |
return ' '; |
| 3346 |
endif; |
| 3347 |
|
| 3348 |
$filtered_cfts = $this->custom_field_template_filter(); |
| 3349 |
|
| 3350 |
if( count($filtered_cfts) < 1 ) : |
| 3351 |
return ' '; |
| 3352 |
endif; |
| 3353 |
|
| 3354 |
$request_post = isset( $_REQUEST['post'] ) && is_scalar( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : 0; |
| 3355 |
$out = '<select id="custom_field_template_select">'; |
| 3356 |
foreach ( $filtered_cfts as $filtered_cft ) : |
| 3357 |
if ( isset($options['custom_fields'][$filtered_cft['id']]['disable']) ) : |
| 3358 |
|
| 3359 |
elseif ( $request_post && isset($options['posts'][$request_post]) && $filtered_cft['id'] == $options['posts'][$request_post] ) : |
| 3360 |
$out .= '<option value="' . $filtered_cft['id'] . '" selected="selected">' . esc_html(stripcslashes($filtered_cft['title'])) . '</option>'; |
| 3361 |
else : |
| 3362 |
$out .= '<option value="' . $filtered_cft['id'] . '">' . esc_html(stripcslashes($filtered_cft['title'])) . '</option>'; |
| 3363 |
endif; |
| 3364 |
endforeach; |
| 3365 |
$out .= '</select> '; |
| 3366 |
|
| 3367 |
$post_type = ''; |
| 3368 |
if ( !empty($_REQUEST['post_type']) && is_scalar( $_REQUEST['post_type'] ) ) $post_type = '+\'&post_type='.rawurlencode( sanitize_key( wp_unslash( $_REQUEST['post_type'] ) ) ).'\''; |
| 3369 |
|
| 3370 |
$out .= '<input type="button" class="button" value="' . __('Load', 'custom-field-template') . '" onclick="if(tinyMCEID.length) { for(i=0;i<tinyMCEID.length;i++) {tinyMCE.execCommand(\'mceRemoveControl\', false, tinyMCEID[i]);} tinyMCEID.length=0;};'; |
| 3371 |
$out .= ' var cftloading_select = function() {jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=\'+jQuery(\'#custom_field_template_select\').val()+\'&post=\'+jQuery(\'#post_ID\').val()'.$post_type.'+\'&page_template=\'+jQuery(\'#page_template\').val(), success: function(html) {'; |
| 3372 |
if ( !empty($options['custom_field_template_replace_the_title']) ) : |
| 3373 |
$out .= 'jQuery(\'#cftdiv h3 span\').text(jQuery(\'#custom_field_template_select :selected\').text());'; |
| 3374 |
endif; |
| 3375 |
$out .= 'jQuery(\'#cft\').html(html);}});};'; |
| 3376 |
if ( !empty($options['custom_field_template_use_autosave']) ) : |
| 3377 |
$out .= 'var fields = jQuery(\'#cft :input\').fieldSerialize();'; |
| 3378 |
$out .= 'jQuery.ajax({type: \'POST\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post=\'+jQuery(\'#post_ID\').val()+\'&custom-field-template-verify-key=\'+jQuery(\'#custom-field-template-verify-key\').val()+\'&\'+fields, success: cftloading_select});'; |
| 3379 |
else : |
| 3380 |
$out .= 'cftloading_select();'; |
| 3381 |
endif; |
| 3382 |
$out .= '" />'; |
| 3383 |
|
| 3384 |
return $out; |
| 3385 |
} |
| 3386 |
|
| 3387 |
function can_delete_cft_attachment( $attachment_id, $post_id, $meta_key ) { |
| 3388 |
$attachment_id = absint( $attachment_id ); |
| 3389 |
$post_id = absint( $post_id ); |
| 3390 |
|
| 3391 |
if ( !$attachment_id || !$post_id || get_post_type( $attachment_id ) !== 'attachment' ) return false; |
| 3392 |
if ( !current_user_can( 'delete_post', $attachment_id ) ) return false; |
| 3393 |
if ( absint( get_post_field( 'post_parent', $attachment_id ) ) === $post_id ) return true; |
| 3394 |
|
| 3395 |
$stored_values = array_map( 'absint', (array) get_post_meta( $post_id, $meta_key, false ) ); |
| 3396 |
return in_array( $attachment_id, $stored_values, true ); |
| 3397 |
} |
| 3398 |
|
| 3399 |
function edit_meta_value( $id, $post ) { |
| 3400 |
global $wpdb, $wp_version, $current_user; |
| 3401 |
$options = $this->get_custom_field_template_data(); |
| 3402 |
|
| 3403 |
if ( empty( $id ) ) : |
| 3404 |
$id = ( isset( $_REQUEST['post_ID'] ) && is_scalar( $_REQUEST['post_ID'] ) ) ? absint( $_REQUEST['post_ID'] ) : 0; |
| 3405 |
else : |
| 3406 |
$id = absint( $id ); |
| 3407 |
endif; |
| 3408 |
|
| 3409 |
if( ! $id || ! current_user_can('edit_post', $id) ) |
| 3410 |
return $id; |
| 3411 |
|
| 3412 |
if ( empty($_REQUEST['custom-field-template-verify-key']) ) |
| 3413 |
return $id; |
| 3414 |
|
| 3415 |
$verify_key = is_scalar( $_REQUEST['custom-field-template-verify-key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['custom-field-template-verify-key'] ) ) : ''; |
| 3416 |
if( !wp_verify_nonce($verify_key, 'custom-field-template') ) |
| 3417 |
return $id; |
| 3418 |
|
| 3419 |
if ( !empty($_POST['wp-preview']) && is_object( $post ) && $id != $post->ID ) : |
| 3420 |
/*$revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $id ) ); |
| 3421 |
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN (" . implode( ',', $revision_ids ) . ")" ); |
| 3422 |
|
| 3423 |
wp_cache_flush(); |
| 3424 |
$original_data = $this->get_post_meta($id); |
| 3425 |
|
| 3426 |
if ( !empty($original_data) && is_array($original_data) ) : |
| 3427 |
foreach ( $original_data as $key => $val ) : |
| 3428 |
if ( is_array($val) ) : |
| 3429 |
foreach ( $val as $val2 ) : |
| 3430 |
add_metadata( 'post', $post->ID, $key, $val2 ); |
| 3431 |
endforeach; |
| 3432 |
else : |
| 3433 |
add_metadata( 'post', $post->ID, $key, $val ); |
| 3434 |
endif; |
| 3435 |
endforeach; |
| 3436 |
endif;*/ |
| 3437 |
|
| 3438 |
$id = $post->ID; |
| 3439 |
endif; |
| 3440 |
|
| 3441 |
/*if ( $post->post_type == 'revision' ) |
| 3442 |
return $id;*/ |
| 3443 |
|
| 3444 |
if ( !isset($_REQUEST['custom-field-template-id']) ) : |
| 3445 |
if ( isset($options['posts'][$id]) ) unset($options['posts'][$id]); |
| 3446 |
update_option('custom_field_template_data', $options); |
| 3447 |
return $id; |
| 3448 |
endif; |
| 3449 |
|
| 3450 |
if ( !empty($_REQUEST['custom-field-template-id']) && is_array($_REQUEST['custom-field-template-id']) ) : |
| 3451 |
foreach ( $_REQUEST['custom-field-template-id'] as $cft_id ) : |
| 3452 |
$cft_id = is_scalar( $cft_id ) ? absint( $cft_id ) : 0; |
| 3453 |
$fields = $this->get_custom_fields($cft_id); |
| 3454 |
|
| 3455 |
if ( $fields == null ) |
| 3456 |
continue; |
| 3457 |
|
| 3458 |
if ( substr($wp_version, 0, 3) >= '2.8' ) { |
| 3459 |
if ( !class_exists('SimpleTags') && !empty($_POST['tax_input']['post_tag']) && is_string($_POST['tax_input']['post_tag']) ) { |
| 3460 |
$tags_input = explode(",", $_POST['tax_input']['post_tag']); |
| 3461 |
} |
| 3462 |
} else { |
| 3463 |
if ( !class_exists('SimpleTags') && !empty($_POST['tags_input']) ) { |
| 3464 |
$tags_input = explode(",", $_POST['tags_input']); |
| 3465 |
} |
| 3466 |
} |
| 3467 |
|
| 3468 |
$save_value = array(); |
| 3469 |
|
| 3470 |
if ( !empty($_FILES) && is_array($_FILES) ) : |
| 3471 |
foreach($_FILES as $key => $val ) : |
| 3472 |
foreach( $val as $key2 => $val2 ) : |
| 3473 |
if ( is_array($val2) ) : |
| 3474 |
foreach( $val2 as $key3 => $val3 ) : |
| 3475 |
foreach( $val3 as $key4 => $val4 ) : |
| 3476 |
if ( !empty($val['name'][$key3][$key4]) ) : |
| 3477 |
$tmpfiles[$key][$key3][$key4]['name'] = $val['name'][$key3][$key4]; |
| 3478 |
$tmpfiles[$key][$key3][$key4]['type'] = $val['type'][$key3][$key4]; |
| 3479 |
$tmpfiles[$key][$key3][$key4]['tmp_name'] = $val['tmp_name'][$key3][$key4]; |
| 3480 |
$tmpfiles[$key][$key3][$key4]['error'] = $val['error'][$key3][$key4]; |
| 3481 |
$tmpfiles[$key][$key3][$key4]['size'] = $val['size'][$key3][$key4]; |
| 3482 |
endif; |
| 3483 |
endforeach; |
| 3484 |
endforeach; |
| 3485 |
break; |
| 3486 |
endif; |
| 3487 |
endforeach; |
| 3488 |
endforeach; |
| 3489 |
endif; |
| 3490 |
unset($_FILES); |
| 3491 |
|
| 3492 |
foreach( $fields as $field_key => $field_val) : |
| 3493 |
foreach( $field_val as $title => $data) : |
| 3494 |
//if ( is_numeric($data['parentSN']) ) $field_key = $data['parentSN']; |
| 3495 |
$name = $this->sanitize_name( $title ); |
| 3496 |
$title = esc_sql(stripcslashes(trim($title))); |
| 3497 |
|
| 3498 |
if ( isset($data['level']) && is_numeric($data['level']) && $current_user->user_level < $data['level'] ) : |
| 3499 |
$save_value[$title] = $this->get_post_meta($id, $title, false); |
| 3500 |
continue; |
| 3501 |
endif; |
| 3502 |
|
| 3503 |
$field_key = 0; |
| 3504 |
if ( isset($_REQUEST[$name]) && is_array($_REQUEST[$name]) ) : |
| 3505 |
foreach( $_REQUEST[$name] as $tmp_key => $tmp_val ) : |
| 3506 |
$field_key = $tmp_key; |
| 3507 |
if ( is_array($tmp_val) ) $_REQUEST[$name][$tmp_key] = array_values($tmp_val); |
| 3508 |
endforeach; |
| 3509 |
endif; |
| 3510 |
|
| 3511 |
switch ( $data['type'] ) : |
| 3512 |
case 'fieldset_open' : |
| 3513 |
$save_value[$title][0] = count($_REQUEST[$name]); |
| 3514 |
break; |
| 3515 |
default : |
| 3516 |
|
| 3517 |
$value = isset($_REQUEST[$name][$field_key][$data['cftnum']]) ? trim($_REQUEST[$name][$field_key][$data['cftnum']]) : ''; |
| 3518 |
|
| 3519 |
if ( !empty($options['custom_field_template_use_wpautop']) && $data['type'] == 'textarea' && !empty($value) ) |
| 3520 |
$value = wpautop($value); |
| 3521 |
if ( isset($data['editCode']) && is_numeric($data['editCode']) ) : |
| 3522 |
eval(stripcslashes($options['php'][$data['editCode']])); |
| 3523 |
endif; |
| 3524 |
if ( $data['type'] != 'file' ) : |
| 3525 |
if( isset( $value ) && strlen( $value ) ) : |
| 3526 |
if ( isset($data['insertTag']) && $data['insertTag'] == true ) : |
| 3527 |
if ( !empty($data['tagName']) ) : |
| 3528 |
$tags_input[trim($data['tagName'])][] = $value; |
| 3529 |
else : |
| 3530 |
$tags_input['post_tag'][] = $value; |
| 3531 |
endif; |
| 3532 |
endif; |
| 3533 |
if ( isset($data['valueCount']) && $data['valueCount'] == true ) : |
| 3534 |
$options['value_count'][$title][$value] = $this->set_value_count($title, $value, $id)+1; |
| 3535 |
endif; |
| 3536 |
if ( $data['type'] == 'textarea' && isset($_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$field_key]) . '_size']) ) { |
| 3537 |
preg_match('/cw=[0-9]+&ch=([0-9]+)/', $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$field_key]) . '_size'], $matched); |
| 3538 |
$options['tinyMCE'][$id][$name][$field_key] = (int)($matched[1]/20); |
| 3539 |
} |
| 3540 |
$save_value[$title][] = $value; |
| 3541 |
elseif ( isset($data['blank']) && $data['blank'] == true ) : |
| 3542 |
$save_value[$title][] = ''; |
| 3543 |
else : |
| 3544 |
$tmp_value = $this->get_post_meta( $id, $title, false ); |
| 3545 |
if ( $data['type'] == 'checkbox' ) : |
| 3546 |
delete_post_meta($id, $title, $data['value']); |
| 3547 |
else : |
| 3548 |
if ( isset($tmp_value[$data['cftnum']]) ) delete_post_meta($id, $title, $tmp_value[$data['cftnum']]); |
| 3549 |
endif; |
| 3550 |
endif; |
| 3551 |
endif; |
| 3552 |
|
| 3553 |
if ( $data['type'] == 'file' ) : |
| 3554 |
if ( isset($_REQUEST[$name.'_delete'][$field_key][$data['cftnum']]) ) : |
| 3555 |
if ( empty($data['mediaRemove']) && $this->can_delete_cft_attachment($value, $id, $title) ) wp_delete_attachment(absint($value)); |
| 3556 |
delete_post_meta($id, $title, $value); |
| 3557 |
unset($value); |
| 3558 |
endif; |
| 3559 |
if( isset($tmpfiles[$name][$field_key][$data['cftnum']]) ) : |
| 3560 |
$_FILES[$title] = $tmpfiles[$name][$field_key][$data['cftnum']]; |
| 3561 |
if ( isset($value) ) : |
| 3562 |
if ( empty($data['mediaRemove']) && $this->can_delete_cft_attachment($value, $id, $title) ) wp_delete_attachment(absint($value)); |
| 3563 |
endif; |
| 3564 |
|
| 3565 |
if ( isset($data['relation']) && $data['relation'] == true ) : |
| 3566 |
$upload_id = media_handle_upload($title, $id); |
| 3567 |
else : |
| 3568 |
$upload_id = media_handle_upload($title, ''); |
| 3569 |
endif; |
| 3570 |
$save_value[$title][] = $upload_id; |
| 3571 |
unset($_FILES); |
| 3572 |
else : |
| 3573 |
if ( !get_post($value) && $value ) : |
| 3574 |
if ( isset($data['blank']) && $data['blank'] == true ) : |
| 3575 |
$save_value[$title][] = ''; |
| 3576 |
endif; |
| 3577 |
elseif ( $value ) : |
| 3578 |
$save_value[$title][] = $value; |
| 3579 |
else : |
| 3580 |
if ( isset($data['blank']) && $data['blank'] == true ) : |
| 3581 |
$save_value[$title][] = ''; |
| 3582 |
endif; |
| 3583 |
endif; |
| 3584 |
endif; |
| 3585 |
endif; |
| 3586 |
endswitch; |
| 3587 |
endforeach; |
| 3588 |
endforeach; |
| 3589 |
|
| 3590 |
/*echo 'tmpfiles'; |
| 3591 |
print_r($tmpfiles); |
| 3592 |
echo 'fields'; |
| 3593 |
print_r($fields); |
| 3594 |
echo '_REQUEST'; |
| 3595 |
print_r($_REQUEST); |
| 3596 |
echo 'save_value'; |
| 3597 |
print_r($save_value); |
| 3598 |
echo 'get_post_custom'; |
| 3599 |
print_r(get_post_custom($id)); |
| 3600 |
exit();*/ |
| 3601 |
|
| 3602 |
foreach( $save_value as $title => $values ) : |
| 3603 |
unset($delete); |
| 3604 |
if ( empty( $values ) ) break; |
| 3605 |
if ( count($values) == 1 ) : |
| 3606 |
if ( !add_metadata( 'post', $id, $title, apply_filters('cft_'.rawurlencode($title), $values[0]), true ) ) : |
| 3607 |
if ( count($this->get_post_meta($id, $title, false))>1 ) : |
| 3608 |
delete_metadata( 'post', $id, $title ); |
| 3609 |
add_metadata( 'post', $id, $title, apply_filters('cft_'.rawurlencode($title), $values[0]) ); |
| 3610 |
else : |
| 3611 |
update_metadata( 'post', $id, $title, apply_filters('cft_'.rawurlencode($title), $values[0]) ); |
| 3612 |
endif; |
| 3613 |
endif; |
| 3614 |
elseif ( count($values) > 1 ) : |
| 3615 |
$tmp = $this->get_post_meta( $id, $title, false ); |
| 3616 |
if ( $tmp ) delete_metadata( 'post', $id, $title ); |
| 3617 |
foreach($values as $val) |
| 3618 |
add_metadata( 'post', $id, $title, apply_filters('cft_'.rawurlencode($title), $val) ); |
| 3619 |
endif; |
| 3620 |
endforeach; |
| 3621 |
|
| 3622 |
if ( !empty($tags_input) && is_array($tags_input) ) : |
| 3623 |
foreach ( $tags_input as $tags_key => $tags_value ) : |
| 3624 |
if ( class_exists('SimpleTags') && $tags_key == 'post_tag' ) : |
| 3625 |
wp_cache_flush(); |
| 3626 |
$taxonomy = wp_get_object_terms($id, 'post_tag', array()); |
| 3627 |
if ( $taxonomy ) foreach($taxonomy as $val) $tags[] = $val->name; |
| 3628 |
if ( is_array($tags) ) $tags_value = array_merge($tags, $tags_value); |
| 3629 |
endif; |
| 3630 |
|
| 3631 |
if ( is_array($tags_value) ) |
| 3632 |
$tags_input = array_unique($tags_value); |
| 3633 |
else |
| 3634 |
$tags_input = $tags_value; |
| 3635 |
if ( substr($wp_version, 0, 3) >= '2.8' ) |
| 3636 |
wp_set_post_terms( $id, $tags_value, $tags_key, true ); |
| 3637 |
else if ( substr($wp_version, 0, 3) >= '2.3' ) |
| 3638 |
wp_set_post_tags( $id, $tags_value ); |
| 3639 |
endforeach; |
| 3640 |
endif; |
| 3641 |
|
| 3642 |
if ( empty($options['custom_field_template_deploy_box']) ) $options['posts'][$id] = $cft_id; |
| 3643 |
|
| 3644 |
endforeach; |
| 3645 |
endif; |
| 3646 |
|
| 3647 |
update_option('custom_field_template_data', $options); |
| 3648 |
wp_cache_flush(); |
| 3649 |
|
| 3650 |
do_action('cft_save_post', $id, $post); |
| 3651 |
} |
| 3652 |
|
| 3653 |
function parse_ini_str($Str,$ProcessSections = TRUE) { |
| 3654 |
$options = $this->get_custom_field_template_data(); |
| 3655 |
|
| 3656 |
$Section = NULL; |
| 3657 |
$Data = array(); |
| 3658 |
$Sections = array(); |
| 3659 |
if ($Temp = strtok($Str,"\r\n")) { |
| 3660 |
$sn = -1; |
| 3661 |
do { |
| 3662 |
switch ($Temp[0]) { |
| 3663 |
case ';': |
| 3664 |
case '#': |
| 3665 |
break; |
| 3666 |
case '[': |
| 3667 |
if (!$ProcessSections) { |
| 3668 |
break; |
| 3669 |
} |
| 3670 |
$Pos = strpos($Temp,'['); |
| 3671 |
$Section = substr($Temp,$Pos+1,strpos($Temp,']',$Pos)-1); |
| 3672 |
$sn++; |
| 3673 |
$Data[$sn][$Section] = array(); |
| 3674 |
if ( isset($cftnum[$Section]) ) $cftnum[$Section]++; |
| 3675 |
else $cftnum[$Section] = 0; |
| 3676 |
$Data[$sn][$Section]['cftnum'] = $cftnum[$Section]; |
| 3677 |
if($Data[$sn][$Section]) |
| 3678 |
break; |
| 3679 |
default: |
| 3680 |
$Pos = strpos($Temp,'='); |
| 3681 |
if ($Pos === FALSE) { |
| 3682 |
break; |
| 3683 |
} |
| 3684 |
$Value = array(); |
| 3685 |
$Value["NAME"] = trim(substr($Temp,0,$Pos)); |
| 3686 |
$Value["VALUE"] = trim(substr($Temp,$Pos+1)); |
| 3687 |
|
| 3688 |
if ($ProcessSections) { |
| 3689 |
$Data[$sn][$Section][$Value["NAME"]] = $Value["VALUE"]; |
| 3690 |
} |
| 3691 |
else { |
| 3692 |
$Data[$Value["NAME"]] = $Value["VALUE"]; |
| 3693 |
} |
| 3694 |
break; |
| 3695 |
} |
| 3696 |
} while ($Temp = strtok("\r\n")); |
| 3697 |
|
| 3698 |
$gap = $key = 0; |
| 3699 |
$returndata = array(); |
| 3700 |
foreach( $Data as $Data_key => $Data_val ) : |
| 3701 |
foreach( $Data_val as $title => $data) : |
| 3702 |
if ( isset($cftisexist[$title]) ) $tmp_parentSN = $cftisexist[$title]; |
| 3703 |
else $tmp_parentSN = count($returndata); |
| 3704 |
switch ( $data["type"]) : |
| 3705 |
case 'checkbox' : |
| 3706 |
if ( isset($data["code"]) && is_numeric($data["code"]) ) : |
| 3707 |
eval(stripcslashes($options['php'][$data["code"]])); |
| 3708 |
else : |
| 3709 |
if ( isset($data["value"]) ) $values = explode( '#', $data["value"] ); |
| 3710 |
if ( isset($data["valueLabel"]) ) $valueLabel = explode( '#', $data["valueLabel"] ); |
| 3711 |
if ( isset($data["default"]) ) $defaults = explode( '#', $data["default"] ); |
| 3712 |
endif; |
| 3713 |
|
| 3714 |
if ( !empty($valueLabel) ) $valueLabels = $valueLabel; |
| 3715 |
|
| 3716 |
if ( isset($defaults) && is_array($defaults) ) |
| 3717 |
foreach($defaults as $dkey => $dval) |
| 3718 |
$defaults[$dkey] = trim($dval); |
| 3719 |
|
| 3720 |
$tmp = $key; |
| 3721 |
$i = 0; |
| 3722 |
if ( isset($values) && is_array($values) ) : |
| 3723 |
foreach($values as $value) { |
| 3724 |
$count_key = count($returndata); |
| 3725 |
$Data[$Data_key][$title]["value"] = trim($value); |
| 3726 |
$Data[$Data_key][$title]["originalValue"] = $data["value"]; |
| 3727 |
$Data[$Data_key][$title]['cftnum'] = $i; |
| 3728 |
if ( isset($valueLabels[$i]) ) |
| 3729 |
$Data[$Data_key][$title]["valueLabel"] = trim($valueLabels[$i]); |
| 3730 |
if ( $tmp!=$key ) |
| 3731 |
$Data[$Data_key][$title]["hideKey"] = true; |
| 3732 |
if ( isset($defaults) && is_array($defaults) ) : |
| 3733 |
if ( in_array(trim($value), $defaults) ) |
| 3734 |
$Data[$Data_key][$title]["checked"] = true; |
| 3735 |
else |
| 3736 |
unset($Data[$Data_key][$title]["checked"]); |
| 3737 |
endif; |
| 3738 |
$Data[$Data_key][$title]['parentSN'] = $tmp_parentSN+$gap; |
| 3739 |
$returndata[$count_key] = $Data[$Data_key]; |
| 3740 |
$key++; |
| 3741 |
$i++; |
| 3742 |
} |
| 3743 |
endif; |
| 3744 |
break; |
| 3745 |
default : |
| 3746 |
if ( $data['type'] == 'fieldset_open' ) : |
| 3747 |
$fieldset = array(); |
| 3748 |
if ( isset($_REQUEST[$this->sanitize_name($title)]) ) $fieldsetcounter = count($_REQUEST[$this->sanitize_name($title)])-1; |
| 3749 |
else if ( isset($_REQUEST['post']) ) $fieldsetcounter = (int)$this->get_post_meta( $_REQUEST['post'], $title, true )-1; |
| 3750 |
else $fieldsetcounter = 0; |
| 3751 |
if ( !empty($data['multiple']) ) : $fieldset_multiple = 1; endif; |
| 3752 |
endif; |
| 3753 |
if ( isset($fieldset) && is_array($fieldset) ) : |
| 3754 |
if ( empty($tmp_parentSN2[$title]) ) $tmp_parentSN2[$title] = $tmp_parentSN; |
| 3755 |
endif; |
| 3756 |
if ( isset($data['multiple']) && $data['multiple'] == true && $data['type'] != 'checkbox' && $data['type'] != 'fieldset_open' && !isset($fieldset) ) : |
| 3757 |
$counter = isset($_REQUEST[$this->sanitize_name($title)][$tmp_parentSN+$gap]) ? count($_REQUEST[$this->sanitize_name($title)][$tmp_parentSN+$gap]) : 0; |
| 3758 |
if ( $data['type'] == 'file' && !empty($_FILES[$this->sanitize_name($title)]) ) $counter = (int)count($_FILES[$this->sanitize_name($title)]['name'][$tmp_parentSN+$gap])+1; |
| 3759 |
if ( isset($_REQUEST['post_ID']) ) : |
| 3760 |
$tmp = $this->get_post_meta( $_REQUEST['post_ID'], $title ); |
| 3761 |
$org_counter = !empty($tmp) ? count($tmp) : 0; |
| 3762 |
elseif ( isset($_REQUEST['post']) ) : |
| 3763 |
$tmp = $this->get_post_meta( $_REQUEST['post'], $title ); |
| 3764 |
$org_counter = !empty($tmp) ? count($tmp) : 0; |
| 3765 |
else : |
| 3766 |
$org_counter = 1; |
| 3767 |
endif; |
| 3768 |
if ( !$counter ) : |
| 3769 |
$counter = $org_counter; |
| 3770 |
$counter++; |
| 3771 |
else : |
| 3772 |
if ( empty($_REQUEST[$this->sanitize_name($title)][$tmp_parentSN+$gap][$counter-1]) ) $counter--; |
| 3773 |
endif; |
| 3774 |
if ( !$org_counter ) $org_counter = 2; |
| 3775 |
if ( isset($data['startNum']) && is_numeric($data['startNum']) && $data['startNum']>$counter ) $counter = $data['startNum']; |
| 3776 |
if ( isset($data['endNum']) && is_numeric($data['endNum']) && $data['endNum']<$counter ) $counter = $data['endNum']; |
| 3777 |
if ( $counter ) : |
| 3778 |
for($i=0;$i<$counter; $i++) : |
| 3779 |
$count_key = count($returndata); |
| 3780 |
if ( $i!=0 ) $Data[$Data_key][$title]["hideKey"] = true; |
| 3781 |
if ( $i!=0 ) unset($Data[$Data_key][$title]["label"]); |
| 3782 |
$Data[$Data_key][$title]['cftnum'] = $i; |
| 3783 |
$Data[$Data_key][$title]['parentSN'] = $tmp_parentSN+$gap; |
| 3784 |
$returndata[$count_key] = $Data[$Data_key]; |
| 3785 |
if ( isset($fieldset) && is_array($fieldset) ) : |
| 3786 |
$fieldset[] = $Data[$Data_key]; |
| 3787 |
endif; |
| 3788 |
endfor; |
| 3789 |
endif; |
| 3790 |
if ( $counter != $org_counter ) : |
| 3791 |
$gap += ($org_counter - $counter); |
| 3792 |
endif; |
| 3793 |
else : |
| 3794 |
if ( !isset($cftisexist[$title]) && !isset($fieldset) ) $Data[$Data_key][$title]['parentSN'] = $tmp_parentSN+$gap; |
| 3795 |
else $Data[$Data_key][$title]['parentSN'] = $tmp_parentSN; |
| 3796 |
$returndata[] = $Data[$Data_key]; |
| 3797 |
if ( isset($fieldset) && is_array($fieldset) ) : |
| 3798 |
$Data[$Data_key][$title]['parentSN'] = $tmp_parentSN2[$title]; |
| 3799 |
$fieldset[] = $Data[$Data_key]; |
| 3800 |
endif; |
| 3801 |
endif; |
| 3802 |
if ( $data['type'] == 'fieldset_close' && is_array($fieldset) ) : |
| 3803 |
for($i=0;$i<$fieldsetcounter;$i++) : |
| 3804 |
$returndata = array_merge($returndata, $fieldset); |
| 3805 |
endfor; |
| 3806 |
if ( isset($_REQUEST['post_ID']) ) $groupcounter = (int)$this->get_post_meta( $_REQUEST['post_ID'], $title, true ); |
| 3807 |
if ( !isset($groupcounter) || $groupcounter == 0 ) $groupcounter = $fieldsetcounter; |
| 3808 |
if ( isset($_REQUEST[$this->sanitize_name($title)]) && $fieldset_multiple ) : |
| 3809 |
$gap += ($groupcounter - count($_REQUEST[$this->sanitize_name($title)]))*count($fieldset); |
| 3810 |
unset($fieldset_multiple); |
| 3811 |
endif; |
| 3812 |
unset($fieldset, $tmp_parentSN2); |
| 3813 |
endif; |
| 3814 |
unset($counter); |
| 3815 |
endswitch; |
| 3816 |
if ( !isset($cftisexist[$title]) ) $cftisexist[$title] = $Data[$Data_key][$title]['parentSN']; |
| 3817 |
endforeach; |
| 3818 |
endforeach; |
| 3819 |
|
| 3820 |
$cftnum = array(); |
| 3821 |
if ( is_array($returndata) ) : |
| 3822 |
foreach( $returndata as $Data_key => $Data_val ) : |
| 3823 |
foreach( $Data_val as $title => $data ) : |
| 3824 |
if ( isset($cftnum[$title]) && is_numeric($cftnum[$title]) ) $cftnum[$title]++; |
| 3825 |
else $cftnum[$title] = 0; |
| 3826 |
$returndata[$Data_key][$title]['cftnum'] = $cftnum[$title]; |
| 3827 |
endforeach; |
| 3828 |
endforeach; |
| 3829 |
endif; |
| 3830 |
} |
| 3831 |
|
| 3832 |
return $returndata; |
| 3833 |
} |
| 3834 |
|
| 3835 |
function output_custom_field_values($attr) { |
| 3836 |
global $post; |
| 3837 |
$options = $this->get_custom_field_template_data(); |
| 3838 |
|
| 3839 |
if ( empty($post->ID) ) $post_id = get_the_ID(); |
| 3840 |
else $post_id = $post->ID; |
| 3841 |
|
| 3842 |
if ( !isset($options['custom_field_template_before_list']) ) $options['custom_field_template_before_list'] = '<ul>'; |
| 3843 |
if ( !isset($options['custom_field_template_after_list']) ) $options['custom_field_template_after_list'] = '</ul>'; |
| 3844 |
if ( !isset($options['custom_field_template_before_value']) ) $options['custom_field_template_before_value'] = '<li>'; |
| 3845 |
if ( !isset($options['custom_field_template_after_value']) ) $options['custom_field_template_after_value'] = '</li>'; |
| 3846 |
|
| 3847 |
if ( !empty($attr['post_id']) ) $this->format_post_id = $attr['post_id']; |
| 3848 |
if ( empty($attr['post_id']) && $this->format_post_id ) $post_id = $this->format_post_id; |
| 3849 |
|
| 3850 |
extract(shortcode_atts(array( |
| 3851 |
'post_id' => $post_id, |
| 3852 |
'template' => 0, |
| 3853 |
'format' => '', |
| 3854 |
'key' => '', |
| 3855 |
'single' => false, |
| 3856 |
'before_list' => $options['custom_field_template_before_list'], |
| 3857 |
'after_list' => $options['custom_field_template_after_list'], |
| 3858 |
'before_value' => $options['custom_field_template_before_value'], |
| 3859 |
'after_value' => $options['custom_field_template_after_value'], |
| 3860 |
'image_size' => '', |
| 3861 |
'image_src' => false, |
| 3862 |
'image_width' => false, |
| 3863 |
'image_height' => false, |
| 3864 |
'value_count' => false, |
| 3865 |
'value' => '' |
| 3866 |
), $attr)); |
| 3867 |
|
| 3868 |
if ( empty( $options['custom_field_template_output_protected_meta'] ) && is_protected_meta( $key ) ) return; |
| 3869 |
|
| 3870 |
$metakey = $key; |
| 3871 |
$output = ''; |
| 3872 |
if ( $metakey ) : |
| 3873 |
if ( $value_count && $value ) : |
| 3874 |
return number_format($options['value_count'][$metakey][$value]); |
| 3875 |
endif; |
| 3876 |
$metavalue = $this->get_post_meta($post_id, $key, $single); |
| 3877 |
if ( !is_array($metavalue) ) $metavalue = array($metavalue); |
| 3878 |
if ( $before_list ) : $output = wp_kses_post( $before_list ) . "\n"; endif; |
| 3879 |
foreach ( $metavalue as $val ) : |
| 3880 |
if ( !empty($image_size) ) : |
| 3881 |
if ( $image_src || $image_width || $image_height ) : |
| 3882 |
list($src, $width, $height) = wp_get_attachment_image_src($val, $image_size); |
| 3883 |
if ( $image_src ) : $val = $src; endif; |
| 3884 |
if ( $image_width ) : $val = $width; endif; |
| 3885 |
if ( $image_height ) : $val = $height; endif; |
| 3886 |
else : |
| 3887 |
$val = wp_get_attachment_image($val, $image_size); |
| 3888 |
endif; |
| 3889 |
endif; |
| 3890 |
if ( empty( $options['custom_field_template_output_direct_meta'] ) || ! user_can( $post->post_author, 'unfiltered_html' ) ) $val = wp_kses_post( $val ); |
| 3891 |
$output .= (isset($before_value) ? wp_kses_post( $before_value ) : '') . $val . (isset($after_value) ? wp_kses_post( $after_value ) : '') . "\n"; |
| 3892 |
endforeach; |
| 3893 |
if ( $after_list ) : $output .= wp_kses_post( $after_list ) . "\n"; endif; |
| 3894 |
return do_shortcode($output); |
| 3895 |
endif; |
| 3896 |
|
| 3897 |
if ( is_numeric($format) && !empty($options['shortcode_format'][$format]) && $output = $options['shortcode_format'][$format] ) : |
| 3898 |
$data = $this->get_post_meta($post_id); |
| 3899 |
$output = stripcslashes($output); |
| 3900 |
|
| 3901 |
if( $data == null) |
| 3902 |
return; |
| 3903 |
|
| 3904 |
$count = count($options['custom_fields']); |
| 3905 |
if ( $count ) : |
| 3906 |
for ($i=0;$i<$count;$i++) : |
| 3907 |
$fields = $this->get_custom_fields( $i ); |
| 3908 |
foreach ( $fields as $field_key => $field_val ) : |
| 3909 |
foreach ( $field_val as $key => $val ) : |
| 3910 |
$replace_val = ''; |
| 3911 |
if ( isset($data[$key]) && count($data[$key]) > 1 ) : |
| 3912 |
if ( isset($val['sort']) && $val['sort'] == 'asc' ) : |
| 3913 |
sort($data[$key]); |
| 3914 |
elseif ( isset($val['sort']) && $val['sort'] == 'desc' ) : |
| 3915 |
rsort($data[$key]); |
| 3916 |
endif; |
| 3917 |
if ( $before_list ) : $replace_val = wp_kses_post( $before_list ) . "\n"; endif; |
| 3918 |
foreach ( $data[$key] as $val2 ) : |
| 3919 |
$value = $val2; |
| 3920 |
if ( isset($val['outputCode']) && is_numeric($val['outputCode']) ) : |
| 3921 |
eval(stripcslashes($options['php'][$val['outputCode']])); |
| 3922 |
endif; |
| 3923 |
if ( isset($val['shortCode']) && $val['shortCode'] == true ) $value = do_shortcode($value); |
| 3924 |
if ( empty( $options['custom_field_template_output_direct_meta'] ) || ! user_can( $post->post_author, 'unfiltered_html' ) ) $value = wp_kses_post( $value ); |
| 3925 |
$replace_val .= wp_kses_post( $before_value ) . $value . wp_kses_post( $after_value ) . "\n"; |
| 3926 |
endforeach; |
| 3927 |
if ( $after_list ) : $replace_val .= wp_kses_post( $after_list ) . "\n"; endif; |
| 3928 |
elseif ( isset($data[$key]) && count($data[$key]) == 1 ) : |
| 3929 |
$value = $data[$key][0]; |
| 3930 |
if ( isset($val['outputCode']) && is_numeric($val['outputCode']) ) : |
| 3931 |
eval(stripcslashes($options['php'][$val['outputCode']])); |
| 3932 |
endif; |
| 3933 |
if ( isset($val['shortCode']) && $val['shortCode'] == true ) $value = do_shortcode($value); |
| 3934 |
$replace_val = $value; |
| 3935 |
if ( isset($val['singleList']) && $val['singleList'] == true ) : |
| 3936 |
if ( $before_list ) : $replace_val = wp_kses_post( $before_list ) . "\n"; endif; |
| 3937 |
if ( empty( $options['custom_field_template_output_direct_meta'] ) || ! user_can( $post->post_author, 'unfiltered_html' ) ) $value = wp_kses_post( $value ); |
| 3938 |
$replace_val .= wp_kses_post( $before_value ) . $value . wp_kses_post( $after_value ) . "\n"; |
| 3939 |
if ( $after_list ) : $replace_val .= wp_kses_post( $after_list ) . "\n"; endif; |
| 3940 |
endif; |
| 3941 |
else : |
| 3942 |
if ( isset($val['outputNone']) ) $replace_val = $val['outputNone']; |
| 3943 |
else $replace_val = ''; |
| 3944 |
endif; |
| 3945 |
if ( isset($options['shortcode_format_use_php'][$format]) ) |
| 3946 |
$output = $this->EvalBuffer($output); |
| 3947 |
|
| 3948 |
$key = preg_quote($key, '/'); |
| 3949 |
$replace_val = str_replace('\\', '\\\\', $replace_val); |
| 3950 |
$replace_val = str_replace('$', '\$', $replace_val); |
| 3951 |
$output = preg_replace('/\['.$key.'\]/', $replace_val, $output); |
| 3952 |
endforeach; |
| 3953 |
endforeach; |
| 3954 |
endfor; |
| 3955 |
endif; |
| 3956 |
else : |
| 3957 |
$fields = $this->get_custom_fields( $template ); |
| 3958 |
|
| 3959 |
if( $fields == null) |
| 3960 |
return; |
| 3961 |
|
| 3962 |
$output = '<dl class="cft cft'.$template.'">' . "\n"; |
| 3963 |
foreach ( $fields as $field_key => $field_val ) : |
| 3964 |
foreach ( $field_val as $key => $val ) : |
| 3965 |
if ( isset($keylist[$key]) && $keylist[$key] == true ) break; |
| 3966 |
$values = $this->get_post_meta( $post_id, $key ); |
| 3967 |
if ( $values ): |
| 3968 |
if ( isset($val['sort']) && $val['sort'] == 'asc' ) : |
| 3969 |
sort($values); |
| 3970 |
elseif ( isset($val['sort']) && $val['sort'] == 'desc' ) : |
| 3971 |
rsort($values); |
| 3972 |
endif; |
| 3973 |
if ( isset($val['output']) && $val['output'] == true ) : |
| 3974 |
foreach ( $values as $num => $value ) : |
| 3975 |
$value = str_replace('\\', '\\\\', $value); |
| 3976 |
if ( isset($val['outputCode']) && is_numeric($val['outputCode']) ) : |
| 3977 |
eval(stripcslashes($options['php'][$val['outputCode']])); |
| 3978 |
endif; |
| 3979 |
if ( empty($value) && $val['outputNone'] ) $value = $val['outputNone']; |
| 3980 |
if ( isset($val['shortCode']) && $val['shortCode'] == true ) $value = do_shortcode($value); |
| 3981 |
if ( !empty($val['label']) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 3982 |
$key_val = wp_kses_post(stripcslashes($val['label'])); |
| 3983 |
else $key_val = $key; |
| 3984 |
if ( isset($val['hideKey']) && $val['hideKey'] != true && $num == 0 ) |
| 3985 |
$output .= '<dt>' . $key_val . '</dt>' . "\n"; |
| 3986 |
if ( empty( $options['custom_field_template_output_direct_meta'] ) || ! user_can( $post->post_author, 'unfiltered_html' ) ) $value = wp_kses_post( $value ); |
| 3987 |
$output .= '<dd>' . $value . '</dd>' . "\n"; |
| 3988 |
endforeach; |
| 3989 |
endif; |
| 3990 |
endif; |
| 3991 |
$keylist[$key] = true; |
| 3992 |
endforeach; |
| 3993 |
endforeach; |
| 3994 |
$output .= '</dl>' . "\n"; |
| 3995 |
endif; |
| 3996 |
|
| 3997 |
return do_shortcode($output); |
| 3998 |
} |
| 3999 |
|
| 4000 |
function search_custom_field_values($attr) { |
| 4001 |
global $post; |
| 4002 |
$options = $this->get_custom_field_template_data(); |
| 4003 |
|
| 4004 |
extract(shortcode_atts(array( |
| 4005 |
'template' => 0, |
| 4006 |
'format' => '', |
| 4007 |
'search_label' => __('Search »', 'custom-field-template'), |
| 4008 |
'button' => true |
| 4009 |
), $attr)); |
| 4010 |
|
| 4011 |
$search_label = wp_strip_all_tags( $search_label ); |
| 4012 |
$format = sanitize_text_field( $format ); |
| 4013 |
$template = absint( $template ); |
| 4014 |
|
| 4015 |
if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) : |
| 4016 |
$output = stripcslashes($output); |
| 4017 |
$output = do_shortcode($output); |
| 4018 |
$output = '<form method="get" action="'.get_option('home').'/" id="cftsearch'.(int)$format.'">' . "\n" . $output; |
| 4019 |
|
| 4020 |
$count = count($options['custom_fields']); |
| 4021 |
if ( $count ) : |
| 4022 |
for ($t=0;$t<$count;$t++) : |
| 4023 |
$fields = $this->get_custom_fields( $t ); |
| 4024 |
foreach ( $fields as $field_key => $field_val ) : |
| 4025 |
foreach ( $field_val as $key => $val ) : |
| 4026 |
unset($replace); |
| 4027 |
$replace[0] = $val; |
| 4028 |
|
| 4029 |
$search = array(); |
| 4030 |
if( isset($val['searchType']) ) eval('$search["type"] =' . stripslashes($val['searchType'])); |
| 4031 |
if( isset($val['searchValue']) ) eval('$search["value"] =' . stripslashes($val['searchValue'])); |
| 4032 |
if( isset($val['searchOperator']) ) eval('$search["operator"] =' . stripslashes($val['searchOperator'])); |
| 4033 |
if( isset($val['searchValueLabel']) ) eval('$search["valueLabel"] =' . stripslashes($val['searchValueLabel'])); |
| 4034 |
if( isset($val['searchDefault']) ) eval('$search["default"] =' . stripslashes($val['searchDefault'])); |
| 4035 |
if( isset($val['searchClass']) ) eval('$search["class"] =' . stripslashes($val['searchClass'])); |
| 4036 |
if( isset($val['searchSelectLabel']) ) eval('$search["selectLabel"] =' . stripslashes($val['searchSelectLabel'])); |
| 4037 |
|
| 4038 |
foreach ( $search as $skey => $sval ) : |
| 4039 |
$j = 1; |
| 4040 |
foreach ( $sval as $sval2 ) : |
| 4041 |
$replace[$j][$skey] = $sval2; |
| 4042 |
$j++; |
| 4043 |
endforeach; |
| 4044 |
endforeach; |
| 4045 |
|
| 4046 |
foreach( $replace as $rkey => $rval ) : |
| 4047 |
$replace_val[$rkey] = ""; |
| 4048 |
$class = ""; |
| 4049 |
$checked = ""; |
| 4050 |
$default = array(); |
| 4051 |
switch ( $rval['type'] ) : |
| 4052 |
case 'text': |
| 4053 |
case 'textfield': |
| 4054 |
case 'textarea': |
| 4055 |
if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; |
| 4056 |
$replace_val[$rkey] .= '<input type="text" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . (isset($_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0]) ? esc_attr($_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0]) : '') . '"' . $class . ' />'; |
| 4057 |
break; |
| 4058 |
case 'checkbox': |
| 4059 |
if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; |
| 4060 |
$values = $valueLabel = array(); |
| 4061 |
if ( $rkey != 0 ) |
| 4062 |
$values = explode( '#', $rval['value'] ); |
| 4063 |
else |
| 4064 |
$values = explode( '#', $rval['originalValue'] ); |
| 4065 |
$valueLabel = isset($rval['valueLabel']) ? explode( '#', $rval['valueLabel'] ) : array(); |
| 4066 |
$default = isset($rval['default']) ? explode( '#', $rval['default'] ) : array(); |
| 4067 |
if ( isset($rval['searchCode']) && is_numeric($rval['searchCode']) ) : |
| 4068 |
eval(stripcslashes($options['php'][$rval['searchCode']])); |
| 4069 |
endif; |
| 4070 |
if ( count($values) > 1 ) : |
| 4071 |
$replace_val[$rkey] .= '<ul' . $class . '>'; |
| 4072 |
$j=0; |
| 4073 |
foreach( $values as $metavalue ) : |
| 4074 |
$checked = ''; |
| 4075 |
$metavalue = trim($metavalue); |
| 4076 |
if ( isset($_REQUEST['cftsearch']) && is_array($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) : |
| 4077 |
if ( in_array($metavalue, $_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) |
| 4078 |
$checked = ' checked="checked"'; |
| 4079 |
else |
| 4080 |
$checked = ''; |
| 4081 |
endif; |
| 4082 |
if ( in_array($metavalue, $default) && !$_REQUEST['cftsearch'][rawurlencode($key)][$rkey] ) |
| 4083 |
$checked = ' checked="checked"'; |
| 4084 |
|
| 4085 |
$replace_val[$rkey] .= '<li><label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($metavalue) . '"' . $class . $checked . ' /> '; |
| 4086 |
if ( isset($valueLabel[$j]) ) $replace_val[$rkey] .= esc_html(stripcslashes($valueLabel[$j])); |
| 4087 |
else $replace_val[$rkey] .= esc_html(stripcslashes($metavalue)); |
| 4088 |
$replace_val[$rkey] .= '</label></li>'; |
| 4089 |
$j++; |
| 4090 |
endforeach; |
| 4091 |
$replace_val[$rkey] .= '</ul>'; |
| 4092 |
else : |
| 4093 |
if ( isset($_REQUEST['cftsearch']) && $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == esc_attr(trim($values[0])) ) |
| 4094 |
$checked = ' checked="checked"'; |
| 4095 |
$replace_val[$rkey] .= '<label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr(trim($values[0])) . '"' . $class . $checked . ' /> '; |
| 4096 |
if ( $valueLabel[0] ) $replace_val[$rkey] .= esc_html(stripcslashes(trim($valueLabel[0]))); |
| 4097 |
else $replace_val[$rkey] .= esc_html(stripcslashes(trim($values[0]))); |
| 4098 |
$replace_val[$rkey] .= '</label>'; |
| 4099 |
endif; |
| 4100 |
break; |
| 4101 |
case 'radio': |
| 4102 |
if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; |
| 4103 |
$values = explode( '#', $rval['value'] ); |
| 4104 |
$valueLabel = isset($rval['valueLabel']) ? explode( '#', $rval['valueLabel'] ) : array(); |
| 4105 |
$default = isset($rval['default']) ? explode( '#', $rval['default'] ) : array(); |
| 4106 |
if ( isset($rval['searchCode']) && is_numeric($rval['searchCode']) ) : |
| 4107 |
eval(stripcslashes($options['php'][$rval['searchCode']])); |
| 4108 |
endif; |
| 4109 |
if ( count($values) > 1 ) : |
| 4110 |
$replace_val[$rkey] .= '<ul' . $class . '>'; |
| 4111 |
$j=0; |
| 4112 |
foreach ( $values as $metavalue ) : |
| 4113 |
$checked = ''; |
| 4114 |
$metavalue = trim($metavalue); |
| 4115 |
if ( isset($_REQUEST['cftsearch']) && is_array($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) : |
| 4116 |
if ( in_array($metavalue, $_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) |
| 4117 |
$checked = ' checked="checked"'; |
| 4118 |
else |
| 4119 |
$checked = ''; |
| 4120 |
endif; |
| 4121 |
if ( in_array($metavalue, $default) && (isset($_REQUEST['cftsearch']) && !$_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) |
| 4122 |
$checked = ' checked="checked"'; |
| 4123 |
$replace_val[$rkey] .= '<li><label><input type="radio" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($metavalue) . '"' . $class . $checked . ' /> '; |
| 4124 |
if ( isset($valueLabel[$j]) ) $replace_val[$rkey] .= esc_html(stripcslashes(trim($valueLabel[$j]))); |
| 4125 |
else $replace_val[$rkey] .= esc_html(stripcslashes($metavalue)); |
| 4126 |
$replace_val[$rkey] .= '</label></li>'; |
| 4127 |
$j++; |
| 4128 |
endforeach; |
| 4129 |
$replace_val[$rkey] .= '</ul>'; |
| 4130 |
else : |
| 4131 |
if ( isset($_REQUEST['cftsearch']) && $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == esc_attr(trim($values[0])) ) |
| 4132 |
$checked = ' checked="checked"'; |
| 4133 |
$replace_val[$rkey] .= '<label><input type="radio" name="cftsearch[' . rawurlencode($key) . '][]" value="' . esc_attr(trim($values[0])) . '"' . $class . $checked . ' /> '; |
| 4134 |
if ( $valueLabel[0] ) $replace_val[$rkey] .= esc_html(stripcslashes(trim($valueLabel[0]))); |
| 4135 |
else $replace_val[$rkey] .= esc_html(stripcslashes(trim($values[0]))); |
| 4136 |
$replace_val[$rkey] .= '</label>'; |
| 4137 |
endif; |
| 4138 |
break; |
| 4139 |
case 'select': |
| 4140 |
if ( !empty($rval['class']) ) $class = ' class="' . $rval['class'] . '"'; |
| 4141 |
$values = explode( '#', $rval['value'] ); |
| 4142 |
$valueLabel = isset($rval['valueLabel']) ? explode( '#', $rval['valueLabel'] ) : array(); |
| 4143 |
$default = isset($rval['default']) ? explode( '#', $rval['default'] ) : array(); |
| 4144 |
$selectLabel= isset($rval['selectLabel']) ? $rval['selectLabel'] : ''; |
| 4145 |
|
| 4146 |
if ( isset($rval['searchCode']) && is_numeric($rval['searchCode']) ) : |
| 4147 |
eval(stripcslashes($options['php'][$rval['searchCode']])); |
| 4148 |
endif; |
| 4149 |
$replace_val[$rkey] .= '<select name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]"' . $class . '>'; |
| 4150 |
$replace_val[$rkey] .= '<option value="">'.$selectLabel.'</option>'; |
| 4151 |
$j=0; |
| 4152 |
foreach ( $values as $metaval ) : |
| 4153 |
$metaval = trim($metaval); |
| 4154 |
if ( in_array($metaval, $default) && !isset($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) |
| 4155 |
$checked = ' checked="checked"'; |
| 4156 |
|
| 4157 |
if ( isset($_REQUEST['cftsearch']) && $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == $metaval ) $selected = ' selected="selected"'; |
| 4158 |
else $selected = ""; |
| 4159 |
$replace_val[$rkey] .= '<option value="' . esc_attr($metaval) . '"' . $selected . '>'; |
| 4160 |
if ( isset($valueLabel[$j]) ) |
| 4161 |
$replace_val[$rkey] .= esc_html(stripcslashes(trim($valueLabel[$j]))); |
| 4162 |
else |
| 4163 |
$replace_val[$rkey] .= esc_html(stripcslashes($metaval)); |
| 4164 |
$replace_val[$rkey] .= '</option>' . "\n"; |
| 4165 |
$j++; |
| 4166 |
endforeach; |
| 4167 |
$replace_val[$rkey] .= '</select>' . "\n"; |
| 4168 |
break; |
| 4169 |
endswitch; |
| 4170 |
endforeach; |
| 4171 |
|
| 4172 |
if ( isset($options['shortcode_format_use_php'][$format]) ) |
| 4173 |
$output = $this->EvalBuffer($output); |
| 4174 |
$key = preg_quote($key, '/'); |
| 4175 |
$output = preg_replace('/\['.$key.'\](?!\[[0-9]+\])/', $replace_val[0], $output); |
| 4176 |
$this->replace_val = $replace_val; |
| 4177 |
$output = preg_replace_callback('/\['.$key.'\]\[([0-9]+)\](?!\[\])/', array($this, 'search_custom_field_values_callback'), $output); |
| 4178 |
endforeach; |
| 4179 |
endforeach; |
| 4180 |
endfor; |
| 4181 |
endif; |
| 4182 |
|
| 4183 |
if ( $button === true ) |
| 4184 |
$output .= '<p><input type="submit" value="' . esc_attr( $search_label ) . '" class="cftsearch_submit" /></p>' . "\n"; |
| 4185 |
$output .= '<input type="hidden" name="cftsearch_submit" value="1" />' . "\n"; |
| 4186 |
$output .= '</form>' . "\n"; |
| 4187 |
else : |
| 4188 |
$fields = $this->get_custom_fields( $template ); |
| 4189 |
|
| 4190 |
if ( $fields == null ) |
| 4191 |
return; |
| 4192 |
|
| 4193 |
$output = '<form method="get" action="'.get_option('home').'/" id="cftsearch'.(int)$format.'">' . "\n"; |
| 4194 |
foreach( $fields as $field_key => $field_val) : |
| 4195 |
foreach( $field_val as $key => $val) : |
| 4196 |
if ( isset($val['search']) && $val['search'] == true ) : |
| 4197 |
if ( !empty($val['label']) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 4198 |
$label = esc_html(stripcslashes($val['label'])); |
| 4199 |
else $label = $key; |
| 4200 |
$output .= '<dl>' ."\n"; |
| 4201 |
if ( !isset($val['hideKey']) || $val['hideKey'] != true) : |
| 4202 |
$output .= '<dt><label>' . $label . '</label></dt>' ."\n"; |
| 4203 |
endif; |
| 4204 |
|
| 4205 |
$class = ""; |
| 4206 |
switch ( $val['type'] ) : |
| 4207 |
case 'text': |
| 4208 |
case 'textfield': |
| 4209 |
case 'textarea': |
| 4210 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4211 |
$output .= '<dd><input type="text" name="cftsearch[' . rawurlencode($key) . '][0][]" value="' . (isset($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) ? esc_attr($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) : '') . '"' . $class . ' /></dd>'; |
| 4212 |
break; |
| 4213 |
case 'checkbox': |
| 4214 |
$checked = ''; |
| 4215 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4216 |
if ( isset($_REQUEST['cftsearch'][rawurlencode($key)]) && is_array($_REQUEST['cftsearch'][rawurlencode($key)]) ) |
| 4217 |
foreach ( $_REQUEST['cftsearch'][rawurlencode($key)] as $values ) |
| 4218 |
if ( $val['value'] == $values[0] ) $checked = ' checked="checked"'; |
| 4219 |
$output .= '<dd><label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][0][]" value="' . esc_attr($val['value']) . '"' . $class . $checked . ' /> '; |
| 4220 |
if ( !empty($val['valueLabel']) ) |
| 4221 |
$output .= esc_html(stripcslashes($val['valueLabel'])); |
| 4222 |
else |
| 4223 |
$output .= esc_html(stripcslashes($val['value'])); |
| 4224 |
$output .= '</label></dd>' . "\n"; |
| 4225 |
break; |
| 4226 |
case 'radio': |
| 4227 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4228 |
$values = explode( '#', $val['value'] ); |
| 4229 |
$valueLabel = isset($val['valueLabel']) ? explode( '#', $val['valueLabel'] ) : ''; |
| 4230 |
$i=0; |
| 4231 |
foreach ( $values as $metaval ) : |
| 4232 |
$checked = ''; |
| 4233 |
$metaval = trim($metaval); |
| 4234 |
if ( isset($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) && $_REQUEST['cftsearch'][rawurlencode($key)][0][0] == $metaval ) $checked = 'checked="checked"'; |
| 4235 |
$output .= '<dd><label>' . '<input type="radio" name="cftsearch[' . rawurlencode($key) . '][0][]" value="' . esc_attr($metaval) . '"' . $class . $checked . ' /> '; |
| 4236 |
if ( !empty($val['valueLabel']) ) |
| 4237 |
$output .= esc_html(stripcslashes(trim($valueLabel[$i]))); |
| 4238 |
else |
| 4239 |
$output .= esc_html(stripcslashes($metaval)); |
| 4240 |
$i++; |
| 4241 |
$output .= '</label></dd>' . "\n"; |
| 4242 |
endforeach; |
| 4243 |
break; |
| 4244 |
case 'select': |
| 4245 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4246 |
$values = explode( '#', $val['value'] ); |
| 4247 |
$valueLabel = isset($val['valueLabel']) ? explode( '#', $val['valueLabel'] ) : ''; |
| 4248 |
$output .= '<dd><select name="cftsearch[' . rawurlencode($key) . '][0][]"' . $class . '>'; |
| 4249 |
$output .= '<option value=""></option>'; |
| 4250 |
$i=0; |
| 4251 |
foreach ( $values as $metaval ) : |
| 4252 |
$selected = ''; |
| 4253 |
$metaval = trim($metaval); |
| 4254 |
if ( isset($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) && $_REQUEST['cftsearch'][rawurlencode($key)][0][0] == $metaval ) $selected = 'selected="selected"'; |
| 4255 |
else $selected = ""; |
| 4256 |
$output .= '<option value="' . esc_attr($metaval) . '"' . $selected . '>'; |
| 4257 |
if ( !empty($val['valueLabel']) ) |
| 4258 |
$output .= esc_html(stripcslashes(trim($valueLabel[$i]))); |
| 4259 |
else |
| 4260 |
$output .= esc_html(stripcslashes($metaval)); |
| 4261 |
$output .= '</option>' . "\n"; |
| 4262 |
$i++; |
| 4263 |
endforeach; |
| 4264 |
$output .= '</select></dd>' . "\n"; |
| 4265 |
break; |
| 4266 |
endswitch; |
| 4267 |
$output .= '</dl>' ."\n"; |
| 4268 |
endif; |
| 4269 |
endforeach; |
| 4270 |
endforeach; |
| 4271 |
if ( $button == true ) |
| 4272 |
$output .= '<p><input type="submit" value="' . esc_attr( $search_label ) . '" class="cftsearch_submit" /></p>' . "\n"; |
| 4273 |
$output .= '<input type="hidden" name="cftsearch_submit" value="1" />' . "\n"; |
| 4274 |
$output .= '</form>' . "\n"; |
| 4275 |
endif; |
| 4276 |
|
| 4277 |
return $output; |
| 4278 |
} |
| 4279 |
|
| 4280 |
function search_custom_field_values_callback ( $m ) { |
| 4281 |
return $this->replace_val[$m[1]]; |
| 4282 |
} |
| 4283 |
|
| 4284 |
function custom_field_template_posts_where($where) { |
| 4285 |
global $wp_query, $wp_version, $wpdb; |
| 4286 |
$options = $this->get_custom_field_template_data(); |
| 4287 |
|
| 4288 |
if ( isset($_REQUEST['no_is_search']) ) : |
| 4289 |
$wp_query->is_search = ''; |
| 4290 |
else: |
| 4291 |
$wp_query->is_search = 1; |
| 4292 |
endif; |
| 4293 |
$wp_query->is_page = ''; |
| 4294 |
$wp_query->is_singular = ''; |
| 4295 |
|
| 4296 |
$original_where = $where; |
| 4297 |
|
| 4298 |
$where = ''; |
| 4299 |
|
| 4300 |
$count = count($options['custom_fields']); |
| 4301 |
if ( $count ) : |
| 4302 |
for ($i=0;$i<$count;$i++) : |
| 4303 |
$fields = $this->get_custom_fields( $i ); |
| 4304 |
foreach ( $fields as $field_key => $field_val ) : |
| 4305 |
foreach ( $field_val as $key => $val ) : |
| 4306 |
$replace[$key] = $val; |
| 4307 |
$search = array(); |
| 4308 |
if( isset($val['searchType']) ) eval('$search["type"] =' . stripslashes($val['searchType'])); |
| 4309 |
if( isset($val['searchValue']) ) eval('$search["value"] =' . stripslashes($val['searchValue'])); |
| 4310 |
if( isset($val['searchOperator']) ) eval('$search["operator"] =' . stripslashes($val['searchOperator'])); |
| 4311 |
|
| 4312 |
foreach ( $search as $skey => $sval ) : |
| 4313 |
$j = 1; |
| 4314 |
foreach ( $sval as $sval2 ) : |
| 4315 |
$replace[$key][$j][$skey] = $sval2; |
| 4316 |
$j++; |
| 4317 |
endforeach; |
| 4318 |
endforeach; |
| 4319 |
endforeach; |
| 4320 |
endforeach; |
| 4321 |
endfor; |
| 4322 |
endif; |
| 4323 |
|
| 4324 |
if ( isset($_REQUEST['cftsearch']) && is_array($_REQUEST['cftsearch']) ) : |
| 4325 |
foreach ( $_REQUEST['cftsearch'] as $key => $val ) : |
| 4326 |
$key = rawurldecode($key); |
| 4327 |
if ( is_array($val) ) : |
| 4328 |
$ch = 0; |
| 4329 |
foreach( $val as $key2 => $val2 ) : |
| 4330 |
if ( is_array($val2) ) : |
| 4331 |
foreach( $val2 as $val3 ) : |
| 4332 |
if ( $val3 ) : |
| 4333 |
if ( $ch == 0 ) : $where .= ' AND ('; |
| 4334 |
else : |
| 4335 |
if ( empty($replace[$key][$key2]['type']) || $replace[$key][$key2]['type'] == 'checkbox' ) $where .= ' OR '; |
| 4336 |
else $where .= ' AND '; |
| 4337 |
endif; |
| 4338 |
if ( !isset($replace[$key][$key2]['operator']) ) $replace[$key][$key2]['operator'] = ''; |
| 4339 |
switch( $replace[$key][$key2]['operator'] ) : |
| 4340 |
case '<=' : |
| 4341 |
case '>=' : |
| 4342 |
case '<' : |
| 4343 |
case '>' : |
| 4344 |
case '=' : |
| 4345 |
case '<>' : |
| 4346 |
case '<=>': |
| 4347 |
if ( is_numeric($val3) ) : |
| 4348 |
$where .= $wpdb->prepare(" ID IN (SELECT `" . $wpdb->postmeta . "`.post_id FROM `" . $wpdb->postmeta . "` WHERE (`" . $wpdb->postmeta . "`.meta_key = %s AND `" . $wpdb->postmeta . "`.meta_value " . $replace[$key][$key2]['operator'] . " %d) ) ", $key, trim($val3)); |
| 4349 |
else : |
| 4350 |
$where .= $wpdb->prepare(" ID IN (SELECT `" . $wpdb->postmeta . "`.post_id FROM `" . $wpdb->postmeta . "` WHERE (`" . $wpdb->postmeta . "`.meta_key = %s AND `" . $wpdb->postmeta . "`.meta_value " . $replace[$key][$key2]['operator'] . " %s) ) ", $key, trim($val3)); |
| 4351 |
endif; |
| 4352 |
break; |
| 4353 |
default : |
| 4354 |
$where .= $wpdb->prepare(" ID IN (SELECT `" . $wpdb->postmeta . "`.post_id FROM `" . $wpdb->postmeta . "` WHERE (`" . $wpdb->postmeta . "`.meta_key = %s AND `" . $wpdb->postmeta . "`.meta_value LIKE %s) ) ", $key, '%'.trim($val3).'%'); |
| 4355 |
break; |
| 4356 |
endswitch; |
| 4357 |
$ch++; |
| 4358 |
endif; |
| 4359 |
endforeach; |
| 4360 |
endif; |
| 4361 |
endforeach; |
| 4362 |
if ( $ch>0 ) $where .= ') '; |
| 4363 |
endif; |
| 4364 |
endforeach; |
| 4365 |
endif; |
| 4366 |
|
| 4367 |
if ( isset($_REQUEST['s']) && $_REQUEST['s'] != '' ) : |
| 4368 |
$where .= ' AND ('; |
| 4369 |
$s = preg_split('/[\s|\x{3000}]+/u', $_REQUEST['s']); |
| 4370 |
$i=0; |
| 4371 |
foreach ( $s as $v ) : |
| 4372 |
if ( !empty($v) ) : |
| 4373 |
if ( $i>0 ) $where .= ' AND '; |
| 4374 |
$where .= $wpdb->prepare(" ID IN (SELECT `" . $wpdb->postmeta . "`.post_id FROM `" . $wpdb->postmeta . "` WHERE (`" . $wpdb->postmeta . "`.meta_value LIKE %s) ) ", '%'.trim($v).'%'); |
| 4375 |
$i++; |
| 4376 |
endif; |
| 4377 |
endforeach; |
| 4378 |
$where .= $wpdb->prepare(" OR ((`" . $wpdb->posts . "`.post_title LIKE %s) OR (`" . $wpdb->posts . "`.post_excerpt LIKE %s) OR (`" . $wpdb->posts . "`.post_content LIKE %s))", '%'.trim($_REQUEST['s']).'%', '%'.trim($_REQUEST['s']).'%', '%'.trim($_REQUEST['s']).'%'); |
| 4379 |
$where .= ') '; |
| 4380 |
endif; |
| 4381 |
|
| 4382 |
if ( isset($_REQUEST['cftcategory_in']) && is_array($_REQUEST['cftcategory_in']) ) : |
| 4383 |
$term_ids = $this->sanitize_integer_list( $_REQUEST['cftcategory_in'] ); |
| 4384 |
$ids = $term_ids ? get_objects_in_term($term_ids, 'category') : array(); |
| 4385 |
$ids = $this->sanitize_integer_list( $ids ); |
| 4386 |
if ( count($ids) > 0 ) : |
| 4387 |
$where .= " AND ID IN (" . implode(',', $ids) . ")"; |
| 4388 |
endif; |
| 4389 |
$where .= " AND `" . $wpdb->posts . "`.post_type = 'post'"; |
| 4390 |
endif; |
| 4391 |
if ( isset($_REQUEST['cftcategory_not_in']) && is_array($_REQUEST['cftcategory_not_in']) ) : |
| 4392 |
$term_ids = $this->sanitize_integer_list( $_REQUEST['cftcategory_not_in'] ); |
| 4393 |
$ids = $term_ids ? get_objects_in_term($term_ids, 'category') : array(); |
| 4394 |
$ids = $this->sanitize_integer_list( $ids ); |
| 4395 |
if ( count($ids) > 0 ) : |
| 4396 |
$where .= " AND ID NOT IN (" . implode(',', $ids) . ")"; |
| 4397 |
endif; |
| 4398 |
endif; |
| 4399 |
|
| 4400 |
if ( !empty($_REQUEST['post_type']) && is_scalar( $_REQUEST['post_type'] ) ) : |
| 4401 |
$where .= $wpdb->prepare(" AND `" . $wpdb->posts . "`.post_type = %s", sanitize_key( wp_unslash( $_REQUEST['post_type'] ) ) ); |
| 4402 |
endif; |
| 4403 |
|
| 4404 |
if ( !empty($_REQUEST['no_is_search']) ) : |
| 4405 |
$where .= " AND `".$wpdb->posts."`.post_status = 'publish'"; |
| 4406 |
elseif ( is_admin() ) : |
| 4407 |
$where .= " AND (`".$wpdb->posts."`.post_status = 'publish' OR `".$wpdb->posts."`.post_status = 'future' OR `".$wpdb->posts."`.post_status = 'draft' OR `".$wpdb->posts."`.post_status = 'pending' OR `".$wpdb->posts."`.post_status = 'private') GROUP BY `".$wpdb->posts."`.ID"; |
| 4408 |
else : |
| 4409 |
$where .= " AND `".$wpdb->posts."`.post_status = 'publish' GROUP BY `".$wpdb->posts."`.ID"; |
| 4410 |
endif; |
| 4411 |
|
| 4412 |
return $where; |
| 4413 |
} |
| 4414 |
|
| 4415 |
function custom_field_template_posts_join($sql) { |
| 4416 |
$orderby = ! empty($_REQUEST['orderby']) && is_scalar( $_REQUEST['orderby'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ) : ''; |
| 4417 |
$order = ! empty($_REQUEST['order']) && is_scalar( $_REQUEST['order'] ) ? strtoupper( sanitize_key( $_REQUEST['order'] ) ) : 'DESC'; |
| 4418 |
if ( $orderby && !in_array($orderby, array('post_author', 'post_date', 'post_title', 'post_modified', 'menu_order', 'post_parent', 'ID', 'rand'), true) ): |
| 4419 |
if ( $order == 'ASC' || $order == 'DESC' ) : |
| 4420 |
global $wpdb; |
| 4421 |
|
| 4422 |
$sql = $wpdb->prepare(" LEFT JOIN `" . $wpdb->postmeta . "` AS meta ON (`" . $wpdb->posts . "`.ID = meta.post_id AND meta.meta_key = %s)", $orderby); |
| 4423 |
return $sql; |
| 4424 |
endif; |
| 4425 |
endif; |
| 4426 |
} |
| 4427 |
|
| 4428 |
function custom_field_template_posts_orderby($sql) { |
| 4429 |
global $wpdb; |
| 4430 |
|
| 4431 |
$order = ! empty($_REQUEST['order']) && is_scalar( $_REQUEST['order'] ) ? strtoupper( sanitize_key( $_REQUEST['order'] ) ) : 'DESC'; |
| 4432 |
if ( $order != 'ASC' && $order != 'DESC' ) $order = 'DESC'; |
| 4433 |
$orderby = ! empty($_REQUEST['orderby']) && is_scalar( $_REQUEST['orderby'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ) : ''; |
| 4434 |
|
| 4435 |
if ( $orderby ) : |
| 4436 |
if ( in_array($orderby, array('post_author', 'post_date', 'post_title', 'post_modified', 'menu_order', 'post_parent', 'ID'), true) ): |
| 4437 |
$sql = "`" . $wpdb->posts . "`." . $orderby . " " . $order; |
| 4438 |
elseif ( $orderby == 'rand' ): |
| 4439 |
$sql = "RAND()"; |
| 4440 |
else: |
| 4441 |
$cast = ! empty($_REQUEST['cast']) && is_scalar( $_REQUEST['cast'] ) ? strtolower( sanitize_key( $_REQUEST['cast'] ) ) : ''; |
| 4442 |
if ( $cast && in_array($cast, array('binary', 'char', 'date', 'datetime', 'signed', 'time', 'unsigned'), true) ) : |
| 4443 |
$sql = " CAST(meta.meta_value AS " . strtoupper( $cast ) . ") " . $order; |
| 4444 |
else : |
| 4445 |
$sql = " meta.meta_value " . $order; |
| 4446 |
endif; |
| 4447 |
endif; |
| 4448 |
|
| 4449 |
return $sql; |
| 4450 |
endif; |
| 4451 |
|
| 4452 |
$sql = "`" . $wpdb->posts . "`.post_date " . $order; |
| 4453 |
return $sql; |
| 4454 |
} |
| 4455 |
|
| 4456 |
function custom_field_template_post_limits($sql_limit) { |
| 4457 |
global $wp_query; |
| 4458 |
|
| 4459 |
if ( !$sql_limit ) return; |
| 4460 |
list($offset, $old_limit) = explode(',', $sql_limit); |
| 4461 |
$limit = isset($_REQUEST['limit']) && is_scalar( $_REQUEST['limit'] ) ? absint($_REQUEST['limit']) : absint($old_limit); |
| 4462 |
|
| 4463 |
$wp_query->query_vars['posts_per_page'] = $limit; |
| 4464 |
$wp_query->query_vars['paged'] = isset($wp_query->query['paged']) ? absint($wp_query->query['paged']) : 1; |
| 4465 |
$offset = ($wp_query->query_vars['paged'] - 1) * $limit; |
| 4466 |
if ( $offset < 0 ) $offset = 0; |
| 4467 |
|
| 4468 |
return ( $limit ? "LIMIT $offset, $limit" : '' ); |
| 4469 |
} |
| 4470 |
|
| 4471 |
function get_preview_id( $post_id ) { |
| 4472 |
global $post; |
| 4473 |
$preview_id = 0; |
| 4474 |
if ( isset($post) && $post->ID == $post_id && is_preview() && $preview = wp_get_post_autosave( $post->ID ) ) : |
| 4475 |
$preview_id = $preview->ID; |
| 4476 |
endif; |
| 4477 |
return $preview_id; |
| 4478 |
} |
| 4479 |
|
| 4480 |
function get_preview_postmeta( $return, $post_id, $meta_key, $single ) { |
| 4481 |
if ( $preview_id = $this->get_preview_id( $post_id ) ) : |
| 4482 |
if ( $post_id != $preview_id ) : |
| 4483 |
$return = $this->get_post_meta( $preview_id, $meta_key, $single ); |
| 4484 |
/*if ( empty($return) && !empty($post_id) ) : |
| 4485 |
$return = $this->get_post_meta( $post_id, $meta_key, $single ); |
| 4486 |
endif;*/ |
| 4487 |
endif; |
| 4488 |
endif; |
| 4489 |
return $return; |
| 4490 |
} |
| 4491 |
|
| 4492 |
function EvalBuffer($string) { |
| 4493 |
ob_start(); |
| 4494 |
eval('?>'.$string); |
| 4495 |
$ret = ob_get_contents(); |
| 4496 |
ob_end_clean(); |
| 4497 |
return $ret; |
| 4498 |
} |
| 4499 |
|
| 4500 |
function set_value_count($key, $value, $id) { |
| 4501 |
global $wpdb; |
| 4502 |
|
| 4503 |
$id = absint( $id ); |
| 4504 |
|
| 4505 |
if ( $id ) : |
| 4506 |
$query = $wpdb->prepare( |
| 4507 |
"SELECT COUNT(meta_id) FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s AND `". $wpdb->postmeta."`.meta_value = %s AND `". $wpdb->postmeta."`.post_id <> %d;", |
| 4508 |
$key, |
| 4509 |
$value, |
| 4510 |
$id |
| 4511 |
); |
| 4512 |
else : |
| 4513 |
$query = $wpdb->prepare( |
| 4514 |
"SELECT COUNT(meta_id) FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s AND `". $wpdb->postmeta."`.meta_value = %s;", |
| 4515 |
$key, |
| 4516 |
$value |
| 4517 |
); |
| 4518 |
endif; |
| 4519 |
|
| 4520 |
$count = $wpdb->get_var($query); |
| 4521 |
return (int)$count; |
| 4522 |
} |
| 4523 |
|
| 4524 |
function get_value_count($key = '', $value = '') { |
| 4525 |
$options = $this->get_custom_field_template_data(); |
| 4526 |
|
| 4527 |
if ( $key && $value ) : |
| 4528 |
return $options['value_count'][$key][$value]; |
| 4529 |
else: |
| 4530 |
return $options['value_count']; |
| 4531 |
endif; |
| 4532 |
} |
| 4533 |
|
| 4534 |
function custom_field_template_delete_post($post_id) { |
| 4535 |
global $wpdb; |
| 4536 |
$options = $this->get_custom_field_template_data(); |
| 4537 |
|
| 4538 |
if ( is_numeric($post_id) ) |
| 4539 |
$id = !empty($options['posts'][$post_id]) ? $options['posts'][$post_id] : ''; |
| 4540 |
|
| 4541 |
if ( is_numeric($id) ) : |
| 4542 |
$fields = $this->get_custom_fields($id); |
| 4543 |
|
| 4544 |
if ( $fields == null ) |
| 4545 |
return; |
| 4546 |
|
| 4547 |
foreach( $fields as $field_key => $field_val) : |
| 4548 |
foreach( $field_val as $title => $data) : |
| 4549 |
$name = $this->sanitize_name( $title ); |
| 4550 |
$title = esc_sql(stripcslashes(trim($title))); |
| 4551 |
$value = $this->get_post_meta($post_id, $title); |
| 4552 |
if ( is_array($value) ) : |
| 4553 |
foreach ( $value as $val ) : |
| 4554 |
if ( $data['valueCount'] == true ) : |
| 4555 |
$count = $this->set_value_count($title, $val, '')-1; |
| 4556 |
if ( $count<=0 ) |
| 4557 |
unset($options['value_count'][$title][$val]); |
| 4558 |
else |
| 4559 |
$options['value_count'][$title][$val] = $count; |
| 4560 |
endif; |
| 4561 |
endforeach; |
| 4562 |
else : |
| 4563 |
if ( $data['valueCount'] == true ) : |
| 4564 |
$count = $this->set_value_count($title, $value, '')-1; |
| 4565 |
if ( $count<=0 ) |
| 4566 |
unset($options['value_count'][$title][$value]); |
| 4567 |
else |
| 4568 |
$options['value_count'][$title][$value] = $count; |
| 4569 |
endif; |
| 4570 |
endif; |
| 4571 |
endforeach; |
| 4572 |
endforeach; |
| 4573 |
endif; |
| 4574 |
update_option('custom_field_template_data', $options); |
| 4575 |
} |
| 4576 |
|
| 4577 |
function custom_field_template_rebuild_value_counts() { |
| 4578 |
global $wpdb; |
| 4579 |
$options = $this->get_custom_field_template_data(); |
| 4580 |
unset($options['value_count']); |
| 4581 |
set_time_limit(0); |
| 4582 |
|
| 4583 |
if ( is_array($options['custom_fields']) ) : |
| 4584 |
for($j=0;$j<count($options['custom_fields']);$j++) : |
| 4585 |
|
| 4586 |
$fields = $this->get_custom_fields($j); |
| 4587 |
|
| 4588 |
if ( $fields == null ) |
| 4589 |
return; |
| 4590 |
|
| 4591 |
foreach( $fields as $field_key => $field_val) : |
| 4592 |
foreach( $field_val as $title => $data) : |
| 4593 |
$name = $this->sanitize_name( $title ); |
| 4594 |
$title = esc_sql(stripcslashes(trim($title))); |
| 4595 |
if ( $data['valueCount'] == true ) : |
| 4596 |
$query = $wpdb->prepare("SELECT COUNT(meta_id) as meta_count, `". $wpdb->postmeta."`.meta_value FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s GROUP BY `". $wpdb->postmeta."`.meta_value;", $title); |
| 4597 |
$result = $wpdb->get_results($query, ARRAY_A); |
| 4598 |
if ( $result ) : |
| 4599 |
foreach($result as $val) : |
| 4600 |
$options['value_count'][$title][$val['meta_value']] = $val['meta_count']; |
| 4601 |
endforeach; |
| 4602 |
endif; |
| 4603 |
endif; |
| 4604 |
endforeach; |
| 4605 |
endforeach; |
| 4606 |
endfor; |
| 4607 |
endif; |
| 4608 |
update_option('custom_field_template_data', $options); |
| 4609 |
} |
| 4610 |
|
| 4611 |
function custom_field_template_wp_post_revision_fields($fields) { |
| 4612 |
$fields['cft_debug_preview'] = 'cft_debug_preview'; |
| 4613 |
return $fields; |
| 4614 |
} |
| 4615 |
|
| 4616 |
function custom_field_template_edit_form_after_title() { |
| 4617 |
echo '<input type="hidden" name="cft_debug_preview" value="cft_debug_preview" />'; |
| 4618 |
} |
| 4619 |
} |
| 4620 |
|
| 4621 |
if ( !function_exists('esc_html') ) : |
| 4622 |
function esc_html( $text ) { |
| 4623 |
$safe_text = wp_specialchars( $safe_text, ENT_QUOTES ); |
| 4624 |
return apply_filters( 'esc_html', $safe_text, $text ); |
| 4625 |
} |
| 4626 |
function esc_attr( $text ) { |
| 4627 |
return attribute_escape($text); |
| 4628 |
} |
| 4629 |
function esc_url( $url, $protocols = null ) { |
| 4630 |
return clean_url( $url, $protocols, 'display' ); |
| 4631 |
} |
| 4632 |
endif; |
| 4633 |
|
| 4634 |
if ( ! class_exists( 'WP_List_Table' ) ) { |
| 4635 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
| 4636 |
} |
| 4637 |
|
| 4638 |
if ( ! class_exists( 'WP_Posts_List_Table' ) ) { |
| 4639 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php' ); |
| 4640 |
} |
| 4641 |
|
| 4642 |
class CFT_WP_Posts_List_Table extends WP_Posts_List_Table { |
| 4643 |
public function __construct() { |
| 4644 |
parent::__construct(); |
| 4645 |
} |
| 4646 |
|
| 4647 |
public function search_box( $text, $input_id ) { |
| 4648 |
global $custom_field_template; |
| 4649 |
|
| 4650 |
/*if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
| 4651 |
return; |
| 4652 |
}*/ |
| 4653 |
|
| 4654 |
$input_id = $input_id . '-search-input'; |
| 4655 |
|
| 4656 |
if ( ! empty( $_REQUEST['orderby'] ) ) { |
| 4657 |
echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
| 4658 |
} |
| 4659 |
if ( ! empty( $_REQUEST['order'] ) ) { |
| 4660 |
echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
| 4661 |
} |
| 4662 |
if ( ! empty( $_REQUEST['post_mime_type'] ) ) { |
| 4663 |
echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />'; |
| 4664 |
} |
| 4665 |
if ( ! empty( $_REQUEST['detached'] ) ) { |
| 4666 |
echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />'; |
| 4667 |
} |
| 4668 |
?> |
| 4669 |
<p class="search-box"> |
| 4670 |
<?php |
| 4671 |
$fields = $custom_field_template->get_custom_fields( 0 ); |
| 4672 |
|
| 4673 |
$output = ''; |
| 4674 |
foreach( $fields as $field_key => $field_val) : |
| 4675 |
foreach( $field_val as $key => $val) : |
| 4676 |
if ( isset($val['adminsearch']) && $val['adminsearch'] == true ) : |
| 4677 |
if ( !empty($val['label']) && !empty($options['custom_field_template_replace_keys_by_labels']) ) |
| 4678 |
$label = esc_html(stripcslashes($val['label'])); |
| 4679 |
else $label = $key; |
| 4680 |
if ( !isset($val['hideKey']) || $val['hideKey'] != true) : |
| 4681 |
$output .= '<label>' . $label . '</label>' ."\n"; |
| 4682 |
endif; |
| 4683 |
|
| 4684 |
$class = ""; |
| 4685 |
switch ( $val['type'] ) : |
| 4686 |
case 'text': |
| 4687 |
case 'textfield': |
| 4688 |
case 'textarea': |
| 4689 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4690 |
$output .= '<input type="text" name="cftsearch[' . rawurlencode($key) . '][0][]" value="' . (isset($_REQUEST['cftsearch'][$key][0][0]) ? esc_attr($_REQUEST['cftsearch'][$key][0][0]) : '') . '"' . $class . ' /></dd>'; |
| 4691 |
break; |
| 4692 |
case 'checkbox': |
| 4693 |
$checked = ''; |
| 4694 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4695 |
if ( isset($_REQUEST['cftsearch'][$key]) && is_array($_REQUEST['cftsearch'][$key]) ) |
| 4696 |
foreach ( $_REQUEST['cftsearch'][$key] as $values ) |
| 4697 |
if ( $val['value'] == $values[0] ) $checked = ' checked="checked"'; |
| 4698 |
$output .= '<label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][0][]" value="' . esc_attr($val['value']) . '"' . $class . $checked . ' /> '; |
| 4699 |
if ( !empty($val['valueLabel']) ) |
| 4700 |
$output .= esc_html(stripcslashes($val['valueLabel'])); |
| 4701 |
else |
| 4702 |
$output .= esc_html(stripcslashes($val['value'])); |
| 4703 |
$output .= '</label>' . "\n"; |
| 4704 |
break; |
| 4705 |
case 'radio': |
| 4706 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4707 |
$values = explode( '#', $val['value'] ); |
| 4708 |
$valueLabel = isset($val['valueLabel']) ? explode( '#', $val['valueLabel'] ) : ''; |
| 4709 |
$i=0; |
| 4710 |
foreach ( $values as $metaval ) : |
| 4711 |
$checked = ''; |
| 4712 |
$metaval = trim($metaval); |
| 4713 |
if ( isset($_REQUEST['cftsearch'][$key][0][0]) && $_REQUEST['cftsearch'][$key][0][0] == $metaval ) $checked = 'checked="checked"'; |
| 4714 |
$output .= '<label>' . '<input type="radio" name="cftsearch[' . rawurlencode($key) . '][0][]" value="' . esc_attr($metaval) . '"' . $class . $checked . ' /> '; |
| 4715 |
if ( !empty($val['valueLabel']) ) |
| 4716 |
$output .= esc_html(stripcslashes(trim($valueLabel[$i]))); |
| 4717 |
else |
| 4718 |
$output .= esc_html(stripcslashes($metaval)); |
| 4719 |
$i++; |
| 4720 |
$output .= '</label>' . "\n"; |
| 4721 |
endforeach; |
| 4722 |
break; |
| 4723 |
case 'select': |
| 4724 |
if ( !empty($val['class']) ) $class = ' class="' . $val['class'] . '"'; |
| 4725 |
$values = explode( '#', $val['value'] ); |
| 4726 |
$valueLabel = isset($val['valueLabel']) ? explode( '#', $val['valueLabel'] ) : ''; |
| 4727 |
$output .= '<select name="cftsearch[' . rawurlencode($key) . '][0][]"' . $class . '>'; |
| 4728 |
$output .= '<option value=""></option>'; |
| 4729 |
$i=0; |
| 4730 |
foreach ( $values as $metaval ) : |
| 4731 |
$selected = ''; |
| 4732 |
$metaval = trim($metaval); |
| 4733 |
if ( isset($_REQUEST['cftsearch'][$key][0][0]) && $_REQUEST['cftsearch'][$key][0][0] == $metaval ) $selected = 'selected="selected"'; |
| 4734 |
else $selected = ""; |
| 4735 |
$output .= '<option value="' . esc_attr($metaval) . '"' . $selected . '>'; |
| 4736 |
if ( !empty($val['valueLabel']) ) |
| 4737 |
$output .= esc_html(stripcslashes(trim($valueLabel[$i]))); |
| 4738 |
else |
| 4739 |
$output .= esc_html(stripcslashes($metaval)); |
| 4740 |
$output .= '</option>' . "\n"; |
| 4741 |
$i++; |
| 4742 |
endforeach; |
| 4743 |
$output .= '</select>' . "\n"; |
| 4744 |
break; |
| 4745 |
endswitch; |
| 4746 |
endif; |
| 4747 |
endforeach; |
| 4748 |
endforeach; |
| 4749 |
echo $output; |
| 4750 |
?> |
| 4751 |
<input type="hidden" name="cftsearch_submit" value="1" /> |
| 4752 |
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label> |
| 4753 |
<input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
| 4754 |
<?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?> |
| 4755 |
</p> |
| 4756 |
<?php |
| 4757 |
} |
| 4758 |
} |
| 4759 |
|
| 4760 |
global $custom_field_template; |
| 4761 |
$custom_field_template = new custom_field_template(); |
| 4762 |
?> |