PageRenderTime 86ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-content/plugins/custom-field-template/custom-field-template.php

https://bitbucket.org/mahoutsukai/bookandbeer_since20120718
PHP | 3996 lines | 3519 code | 409 blank | 68 comment | 1221 complexity | a6f2ed25f6e6b8101b958d3c516ec76c MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, GPL-3.0
  1. <?php
  2. /*
  3. Plugin Name: Custom Field Template
  4. Plugin URI: http://wpgogo.com/development/custom-field-template.html
  5. Description: This plugin adds the default custom fields on the Write Post/Page.
  6. Author: Hiroaki Miyashita
  7. Version: 2.0.4
  8. Author URI: http://wpgogo.com/
  9. */
  10. /*
  11. This program is based on the rc:custom_field_gui plugin written by Joshua Sigar.
  12. I appreciate your efforts, Joshua.
  13. */
  14. /* Copyright 2008 -2012 Hiroaki Miyashita
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2 of the License, or
  18. (at your option) any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. class custom_field_template {
  28. var $is_excerpt;
  29. function custom_field_template() {
  30. add_action( 'init', array(&$this, 'custom_field_template_init'), 100 );
  31. add_action( 'admin_menu', array(&$this, 'custom_field_template_admin_menu') );
  32. add_action( 'admin_print_scripts', array(&$this, 'custom_field_template_admin_scripts') );
  33. add_action( 'admin_head', array(&$this, 'custom_field_template_admin_head'), 100 );
  34. add_action( 'dbx_post_sidebar', array(&$this, 'custom_field_template_dbx_post_sidebar') );
  35. //add_action( 'edit_post', array(&$this, 'edit_meta_value'), 100 );
  36. add_action( 'save_post', array(&$this, 'edit_meta_value'), 100, 2 );
  37. //add_action( 'publish_post', array(&$this, 'edit_meta_value'), 100 );
  38. add_action( 'delete_post', array(&$this, 'custom_field_template_delete_post'), 100 );
  39. add_filter( 'media_send_to_editor', array(&$this, 'media_send_to_custom_field'), 15 );
  40. add_filter( 'plugin_action_links', array(&$this, 'wpaq_filter_plugin_actions'), 100, 2 );
  41. add_filter( 'get_the_excerpt', array(&$this, 'custom_field_template_get_the_excerpt'), 1 );
  42. add_filter( 'the_content', array(&$this, 'custom_field_template_the_content') );
  43. add_filter( 'the_content_rss', array(&$this, 'custom_field_template_the_content') );
  44. add_filter( 'attachment_fields_to_edit', array(&$this, 'custom_field_template_attachment_fields_to_edit'), 10, 2 );
  45. if ( isset($_REQUEST['cftsearch_submit']) ) :
  46. if ( !empty($_REQUEST['limit']) )
  47. add_action( 'post_limits', array(&$this, 'custom_field_template_post_limits'));
  48. add_filter( 'posts_join', array(&$this, 'custom_field_template_posts_join') );
  49. add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where'), 100 );
  50. add_filter( 'posts_orderby', array(&$this, 'custom_field_template_posts_orderby' ) );
  51. endif;
  52. if ( function_exists('add_shortcode') ) :
  53. add_shortcode( 'cft', array(&$this, 'output_custom_field_values') );
  54. add_shortcode( 'cftsearch', array(&$this, 'search_custom_field_values') );
  55. endif;
  56. }
  57. function custom_field_template_init() {
  58. global $wp_version;
  59. $options = $this->get_custom_field_template_data();
  60. if ( function_exists('load_plugin_textdomain') ) {
  61. if ( !defined('WP_PLUGIN_DIR') ) {
  62. load_plugin_textdomain('custom-field-template', str_replace( ABSPATH, '', dirname(__FILE__) ) );
  63. } else {
  64. load_plugin_textdomain('custom-field-template', false, dirname( plugin_basename(__FILE__) ) );
  65. }
  66. }
  67. if ( is_user_logged_in() && isset($_REQUEST['post']) && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'selectbox' ) {
  68. echo $this->custom_field_template_selectbox();
  69. exit();
  70. }
  71. if ( is_user_logged_in() && isset($_REQUEST['post']) && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'ajaxsave' ) {
  72. if ( $_REQUEST['post'] > 0 )
  73. $this->edit_meta_value( $_REQUEST['post'], '' );
  74. exit();
  75. }
  76. if ( is_user_logged_in() && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'ajaxload') {
  77. if ( isset($_REQUEST['id']) ) :
  78. $id = $_REQUEST['id'];
  79. elseif ( isset($options['posts'][$_REQUEST['post']]) ) :
  80. $id = $options['posts'][$_REQUEST['post']];
  81. else :
  82. $filtered_cfts = $this->custom_field_template_filter();
  83. if ( count($filtered_cfts)>0 ) :
  84. $id = $filtered_cfts[0]['id'];
  85. else :
  86. $id = 0;
  87. endif;
  88. endif;
  89. list($body, $init_id) = $this->load_custom_field( $id );
  90. echo $body;
  91. exit();
  92. }
  93. if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/plugins.php') && ((isset($_GET['activate']) && $_GET['activate'] == 'true') || (isset($_GET['activate-multi']) && $_GET['activate-multi'] == 'true') ) ) {
  94. $options = $this->get_custom_field_template_data();
  95. if( !$options ) {
  96. $this->install_custom_field_template_data();
  97. $this->install_custom_field_template_css();
  98. }
  99. }
  100. if ( function_exists('current_user_can') && current_user_can('edit_plugins') ) :
  101. if ( isset($_POST['custom_field_template_export_options_submit']) ) :
  102. $filename = "cft".date('Ymd');
  103. header("Accept-Ranges: none");
  104. header("Content-Disposition: attachment; filename=$filename");
  105. header('Content-Type: application/octet-stream');
  106. echo maybe_serialize($options);
  107. exit();
  108. endif;
  109. endif;
  110. if ( !empty($options['custom_field_template_widget_shortcode']) )
  111. add_filter('widget_text', 'do_shortcode');
  112. if ( substr($wp_version, 0, 3) >= '2.7' ) {
  113. if ( empty($options['custom_field_template_disable_custom_field_column']) ) :
  114. add_action( 'manage_posts_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 );
  115. add_filter( 'manage_posts_columns', array(&$this, 'add_manage_posts_columns') );
  116. add_action( 'manage_pages_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 );
  117. add_filter( 'manage_pages_columns', array(&$this, 'add_manage_pages_columns') );
  118. endif;
  119. if ( empty($options['custom_field_template_disable_quick_edit']) )
  120. add_action( 'quick_edit_custom_box', array(&$this, 'add_quick_edit_custom_box'), 10, 2 );
  121. }
  122. if ( substr($wp_version, 0, 3) < '2.5' ) {
  123. add_action( 'simple_edit_form', array(&$this, 'insert_custom_field'), 1 );
  124. add_action( 'edit_form_advanced', array(&$this, 'insert_custom_field'), 1 );
  125. add_action( 'edit_page_form', array(&$this, 'insert_custom_field'), 1 );
  126. } else {
  127. if ( substr($wp_version, 0, 3) >= '3.3' && file_exists(ABSPATH . 'wp-admin/includes/screen.php') ) :
  128. require_once(ABSPATH . 'wp-admin/includes/screen.php');
  129. endif;
  130. require_once(ABSPATH . 'wp-admin/includes/template.php');
  131. if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) :
  132. remove_meta_box('postcustom', 'post', 'normal');
  133. remove_meta_box('postcustom', 'page', 'normal');
  134. remove_meta_box('pagecustomdiv', 'page', 'normal');
  135. endif;
  136. if ( !empty($options['custom_field_template_deploy_box']) ) :
  137. if ( !empty($options['custom_fields']) ) :
  138. $i = 0;
  139. foreach ( $options['custom_fields'] as $key => $val ) :
  140. if ( empty($options['custom_field_template_replace_the_title']) ) $title = __('Custom Field Template', 'custom-field-template');
  141. else $title = $options['custom_fields'][$key]['title'];
  142. if ( empty($options['custom_fields'][$key]['custom_post_type']) ) :
  143. if ( empty($options['custom_fields'][$key]['post_type']) ) :
  144. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', $key);
  145. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', $key);
  146. elseif ( $options['custom_fields'][$key]['post_type']=='post' ) :
  147. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', $key);
  148. elseif ( $options['custom_fields'][$key]['post_type']=='page' ) :
  149. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', $key);
  150. endif;
  151. else :
  152. $tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']);
  153. $tmp_custom_post_type = array_filter( $tmp_custom_post_type );
  154. $tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type)));
  155. foreach ( $tmp_custom_post_type as $type ) :
  156. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), $type, 'normal', 'core', $key);
  157. endforeach;
  158. endif;
  159. $i++;
  160. endforeach;
  161. endif;
  162. else :
  163. add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'post', 'normal', 'core');
  164. add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'page', 'normal', 'core');
  165. endif;
  166. if ( empty($options['custom_field_template_deploy_box']) && is_array($options['custom_fields']) ) :
  167. $custom_post_type = array();
  168. foreach($options['custom_fields'] as $key => $val ) :
  169. if ( isset($options['custom_fields'][$key]['custom_post_type']) ) :
  170. $tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']);
  171. $tmp_custom_post_type = array_filter( $tmp_custom_post_type );
  172. $tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type)));
  173. $custom_post_type = array_merge($custom_post_type, $tmp_custom_post_type);
  174. endif;
  175. endforeach;
  176. if ( isset($custom_post_type) && is_array($custom_post_type) ) :
  177. foreach( $custom_post_type as $val ) :
  178. if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) :
  179. remove_meta_box('postcustom', $val, 'normal');
  180. endif;
  181. add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), $val, 'normal', 'core');
  182. if ( empty($options['custom_field_template_disable_custom_field_column']) ) :
  183. add_filter( 'manage_'.$val.'_posts_columns', array(&$this, 'add_manage_pages_columns') );
  184. endif;
  185. endforeach;
  186. endif;
  187. endif;
  188. }
  189. 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') ) :
  190. add_action('admin_head', array(&$this, 'custom_field_template_admin_head_buffer') );
  191. add_action('admin_footer', array(&$this, 'custom_field_template_admin_footer_buffer') );
  192. endif;
  193. }
  194. function custom_field_template_attachment_fields_to_edit($form_fields, $post) {
  195. $form_fields["custom_field_template"]["label"] = __('Media Picker', 'custom-field-template');
  196. $form_fields["custom_field_template"]["input"] = "html";
  197. $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>';
  198. return $form_fields;
  199. }
  200. function custom_field_template_add_enctype($buffer) {
  201. $buffer = preg_replace('/<form name="post"/', '<form enctype="multipart/form-data" name="post"', $buffer);
  202. return $buffer;
  203. }
  204. function custom_field_template_admin_head_buffer() {
  205. ob_start(array(&$this, 'custom_field_template_add_enctype'));
  206. }
  207. function custom_field_template_admin_footer_buffer() {
  208. ob_end_flush();
  209. }
  210. function has_meta( $postid ) {
  211. global $wpdb;
  212. 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 );
  213. }
  214. function get_post_meta($post_id, $key, $single = false) {
  215. if ( !$post_id || !$key )
  216. return '';
  217. $post_id = (int) $post_id;
  218. $meta_cache = wp_cache_get($post_id, 'cft_post_meta');
  219. if ( !$meta_cache ) {
  220. if ( $meta_list = $this->has_meta( $post_id ) ) {
  221. foreach ( (array) $meta_list as $metarow) {
  222. $mpid = (int) $metarow['post_id'];
  223. $mkey = $metarow['meta_key'];
  224. $mval = $metarow['meta_value'];
  225. if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) )
  226. $cache[$mpid] = array();
  227. if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) )
  228. $cache[$mpid][$mkey] = array();
  229. $cache[$mpid][$mkey][] = $mval;
  230. }
  231. }
  232. /*foreach ( (array) $ids as $id ) {
  233. if ( ! isset($cache[$id]) )
  234. $cache[$id] = array();
  235. }*/
  236. if ( !empty($cache) && is_array($cache) ) :
  237. foreach ( (array) array_keys($cache) as $post)
  238. wp_cache_set($post, $cache[$post], 'cft_post_meta');
  239. $meta_cache = wp_cache_get($post_id, 'cft_post_meta');
  240. endif;
  241. }
  242. if ( isset($meta_cache[$key]) ) {
  243. if ( $single ) {
  244. return maybe_unserialize( $meta_cache[$key][0] );
  245. } else {
  246. return array_map('maybe_unserialize', $meta_cache[$key]);
  247. }
  248. }
  249. return '';
  250. }
  251. function add_quick_edit_custom_box($column_name, $type) {
  252. if( $column_name == 'custom-fields' ) :
  253. global $wp_version;
  254. $options = $this->get_custom_field_template_data();
  255. if( $options == null)
  256. return;
  257. if ( !$options['css'] ) {
  258. $this->install_custom_field_template_css();
  259. $options = $this->get_custom_field_template_data();
  260. }
  261. $out .= '<fieldset style="clear:both;">' . "\n";
  262. $out .= '<div class="inline-edit-group">';
  263. $out .= '<style type="text/css">' . "\n" .
  264. '<!--' . "\n";
  265. $out .= $options['css'] . "\n";
  266. $out .= '-->' . "\n" .
  267. '</style>';
  268. if ( count($options['custom_fields'])>1 ) {
  269. $out .= '<select id="custom_field_template_select">';
  270. for ( $i=0; $i < count($options['custom_fields']); $i++ ) {
  271. if ( $i == $options['posts'][$_REQUEST['post']] ) {
  272. $out .= '<option value="' . $i . '" selected="selected">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
  273. } else
  274. $out .= '<option value="' . $i . '">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
  275. }
  276. $out .= '</select>';
  277. $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);" />';
  278. }
  279. $out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />';
  280. $out .= '<div id="cft" class="cft">';
  281. $out .= '</div>';
  282. $out .= '</div>' . "\n";
  283. $out .= '</fieldset>' . "\n";
  284. echo $out;
  285. endif;
  286. }
  287. function custom_field_template_admin_head() {
  288. global $wp_version;
  289. $options = $this->get_custom_field_template_data();
  290. if ( !defined('WP_PLUGIN_DIR') )
  291. $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
  292. else
  293. $plugin_dir = dirname( plugin_basename(__FILE__) );
  294. echo '<link rel="stylesheet" type="text/css" href="' . wp_guess_url() . '/' . PLUGINDIR . '/' . $plugin_dir . '/js/datePicker.css" />'."\n";
  295. if ( !empty($options['custom_field_template_use_validation']) ) :
  296. 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') ) :
  297. ?>
  298. <script type="text/javascript">
  299. // <![CDATA[
  300. jQuery(document).ready(function() {
  301. jQuery("#post").validate();
  302. });
  303. //-->
  304. </script>
  305. <style type="text/css">
  306. <!--
  307. label.error { color:#FF0000; }
  308. -->
  309. </style>
  310. <?php
  311. endif;
  312. endif;
  313. 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=') ) {
  314. ?>
  315. <script type="text/javascript">
  316. // <![CDATA[
  317. jQuery(document).ready(function() {
  318. jQuery('.hide-if-no-js-cft').show();
  319. jQuery('.hide-if-js-cft').hide();
  320. inlineEditPost.addEvents = function(r) {
  321. r.each(function() {
  322. var row = jQuery(this);
  323. jQuery('a.editinline', row).click(function() {
  324. inlineEditPost.edit(this);
  325. post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-','');
  326. inlineEditPost.cft_load(post_id);
  327. return false;
  328. });
  329. });
  330. }
  331. inlineEditPost.save = function(id) {
  332. if( typeof(id) == 'object' )
  333. id = this.getId(id);
  334. jQuery('table.widefat .inline-edit-save .waiting').show();
  335. var params = {
  336. action: 'inline-save',
  337. post_type: <?php if ( substr($wp_version, 0, 3) >= '3.0' ) echo 'typenow'; else echo 'this.type'; ?>,
  338. post_ID: id,
  339. edit_date: 'true'
  340. };
  341. var fields = jQuery('#edit-'+id+' :input').fieldSerialize();
  342. params = fields + '&' + jQuery.param(params);
  343. // make ajax request
  344. jQuery.post('admin-ajax.php', params,
  345. function(r) {
  346. jQuery('table.widefat .inline-edit-save .waiting').hide();
  347. if (r) {
  348. if ( -1 != r.indexOf('<tr') ) {
  349. jQuery(inlineEditPost.what+id).remove();
  350. jQuery('#edit-'+id).before(r).remove();
  351. var row = jQuery(inlineEditPost.what+id);
  352. row.hide();
  353. if ( 'draft' == jQuery('input[name="post_status"]').val() )
  354. row.find('td.column-comments').hide();
  355. row.find('.hide-if-no-js').removeClass('hide-if-no-js');
  356. jQuery('.hide-if-no-js-cft').show();
  357. jQuery('.hide-if-js-cft').hide();
  358. inlineEditPost.addEvents(row);
  359. row.fadeIn();
  360. } else {
  361. r = r.replace( /<.[^<>]*?>/g, '' );
  362. jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
  363. }
  364. } else {
  365. jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
  366. }
  367. }
  368. , 'html');
  369. return false;
  370. }
  371. jQuery('.editinline').click(function () {post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-',''); inlineEditPost.cft_load(post_id);});
  372. inlineEditPost.cft_load = function (post_id) {
  373. 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);}});
  374. };
  375. });
  376. //-->
  377. </script>
  378. <style type="text/css">
  379. <!--
  380. div.cft_list p.key { font-weight:bold; margin: 0; }
  381. div.cft_list p.value { margin: 0 0 0 10px; }
  382. .cft-actions { visibility: hidden; padding: 2px 0 0; }
  383. tr:hover .cft-actions { visibility: visible; }
  384. .inline-edit-row fieldset label { display:inline; }
  385. label.error { color:#FF0000; }
  386. -->
  387. </style>
  388. <?php
  389. }
  390. }
  391. function custom_field_template_dbx_post_sidebar() {
  392. global $wp_version;
  393. $options = $this->get_custom_field_template_data();
  394. if ( !empty($options['custom_field_template_deploy_box']) ) :
  395. $suffix = '"+win.jQuery("#cft_current_template").val()+"';
  396. else :
  397. $suffix = '';
  398. endif;
  399. $out = '';
  400. $out .= '<script type="text/javascript">' . "\n" .
  401. '// <![CDATA[' . "\n";
  402. $out .= 'function cft_use_this(file_id) {
  403. var win = window.dialogArguments || opener || parent || top;
  404. win.jQuery("#"+win.jQuery("#cft_clicked_id").val()+"_hide").val(file_id);
  405. var fields = win.jQuery("#cft'.$suffix.' :input").fieldSerialize();
  406. 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();}});}});
  407. }';
  408. $out .= 'function qt_set(new_id) { eval("qt_"+new_id+" = new QTags(\'qt_"+new_id+"\', \'"+new_id+"\', \'editorcontainer_"+new_id+"\', \'more\');");}';
  409. $out .= 'function _edInsertContent(myField, myValue) {
  410. var sel, startPos, endPos, scrollTop;
  411. //IE support
  412. if (document.selection) {
  413. myField.focus();
  414. sel = document.selection.createRange();
  415. sel.text = myValue;
  416. myField.focus();
  417. }
  418. //MOZILLA/NETSCAPE support
  419. else if (myField.selectionStart || myField.selectionStart == "0") {
  420. startPos = myField.selectionStart;
  421. endPos = myField.selectionEnd;
  422. scrollTop = myField.scrollTop;
  423. myField.value = myField.value.substring(0, startPos)
  424. + myValue
  425. + myField.value.substring(endPos, myField.value.length);
  426. myField.focus();
  427. myField.selectionStart = startPos + myValue.length;
  428. myField.selectionEnd = startPos + myValue.length;
  429. myField.scrollTop = scrollTop;
  430. } else {
  431. myField.value += myValue;
  432. myField.focus();
  433. }
  434. }';
  435. $out .= 'function send_to_custom_field(h) {' . "\n" .
  436. ' if ( tmpFocus ) ed = tmpFocus;' . "\n" .
  437. ' else if ( typeof tinyMCE == "undefined" ) ed = document.getElementById("content");' . "\n" .
  438. ' else { ed = tinyMCE.get("content"); if(ed) {if(!ed.isHidden()) isTinyMCE = true;}}' . "\n" .
  439. ' if ( typeof tinyMCE != "undefined" && isTinyMCE && !ed.isHidden() ) {' . "\n" .
  440. ' ed.focus();' . "\n" .
  441. ' if ( tinymce.isIE && ed.windowManager.insertimagebookmark )' . "\n" .
  442. ' ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);' . "\n" .
  443. ' if ( h.indexOf("[caption") === 0 ) {' . "\n" .
  444. ' if ( ed.plugins.wpeditimage )' . "\n" .
  445. ' h = ed.plugins.wpeditimage._do_shcode(h);' . "\n" .
  446. ' } else if ( h.indexOf("[gallery") === 0 ) {' . "\n" .
  447. ' if ( ed.plugins.wpgallery )' . "\n" .
  448. ' h = ed.plugins.wpgallery._do_gallery(h);' . "\n" .
  449. ' } else if ( h.indexOf("[embed") === 0 ) {' . "\n" .
  450. ' if ( ed.plugins.wordpress )' . "\n" .
  451. ' h = ed.plugins.wordpress._setEmbed(h);' . "\n" .
  452. ' }' . "\n" .
  453. ' ed.execCommand("mceInsertContent", false, h);' . "\n" .
  454. ' } else {' . "\n" .
  455. ' if ( tmpFocus ) _edInsertContent(tmpFocus, h);' . "\n" .
  456. ' else edInsertContent(edCanvas, h);' . "\n" .
  457. ' }' . "\n";
  458. if ( empty($options['custom_field_template_use_multiple_insert']) ) {
  459. $out .= ' tb_remove();' . "\n" .
  460. ' tmpFocus = undefined;' . "\n" .
  461. ' isTinyMCE = false;' . "\n";
  462. }
  463. if ( substr($wp_version, 0, 3) < '3.3' ) :
  464. $qt_position = 'jQuery(\'#editorcontainer_\'+id).prev()';
  465. $load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, id);';
  466. else :
  467. $qt_position = 'jQuery(\'#qt_\'+id+\'_toolbar\')';
  468. $load_tinyMCE = 'var ed = new tinyMCE.Editor(id, tinyMCEPreInit.mceInit[\'content\']); ed.render();';
  469. endif;
  470. $out .= '}' . "\n" .
  471. 'jQuery(".thickbox").bind("click", function (e) {' . "\n" .
  472. ' tmpFocus = undefined;' . "\n" .
  473. ' isTinyMCE = false;' . "\n" .
  474. '});' . "\n" .
  475. 'var isTinyMCE;' . "\n" .
  476. 'var tmpFocus;' . "\n" .
  477. 'function focusTextArea(id) {' . "\n" .
  478. ' jQuery(document).ready(function() {' . "\n" .
  479. ' if ( typeof tinyMCE != "undefined" ) {' . "\n" .
  480. ' var elm = tinyMCE.get(id);' . "\n" .
  481. ' }' . "\n" .
  482. ' if ( ! elm || elm.isHidden() ) {' . "\n" .
  483. ' elm = document.getElementById(id);' . "\n" .
  484. ' isTinyMCE = false;' . "\n" .
  485. ' }else isTinyMCE = true;' . "\n" .
  486. ' tmpFocus = elm' . "\n" .
  487. ' elm.focus();' . "\n" .
  488. ' if (elm.createTextRange) {' . "\n" .
  489. ' var range = elm.createTextRange();' . "\n" .
  490. ' range.move("character", elm.value.length);' . "\n" .
  491. ' range.select();' . "\n" .
  492. ' } else if (elm.setSelectionRange) {' . "\n" .
  493. ' elm.setSelectionRange(elm.value.length, elm.value.length);' . "\n" .
  494. ' }' . "\n" .
  495. ' });' . "\n" .
  496. '}' . "\n" .
  497. 'function switchMode(id) {' . "\n" .
  498. ' var ed = tinyMCE.get(id);' . "\n" .
  499. ' if ( ! ed || ed.isHidden() ) {' . "\n" .
  500. ' document.getElementById(id).value = switchEditors.wpautop(document.getElementById(id).value);' . "\n" .
  501. ' if ( ed ) { '.$qt_position.'.hide(); ed.show(); }' . "\n" .
  502. ' else {'.$load_tinyMCE.'}' . "\n" .
  503. ' } else {' . "\n" .
  504. ' ed.hide(); '.$qt_position.'.show(); document.getElementById(id).style.color="#000000";' . "\n" .
  505. ' }' . "\n" .
  506. '}' . "\n";
  507. $out .= 'function thickbox(link) {' . "\n" .
  508. ' var t = link.title || link.name || null;' . "\n" .
  509. ' var a = link.href || link.alt;' . "\n" .
  510. ' var g = link.rel || false;' . "\n" .
  511. ' tb_show(t,a,g);' . "\n" .
  512. ' link.blur();' . "\n" .
  513. ' return false;' . "\n" .
  514. '}' . "\n";
  515. $out .= '//--></script>';
  516. $out .= '<input type="hidden" id="cft_current_template" value="" />';
  517. $out .= '<input type="hidden" id="cft_clicked_id" value="" />';
  518. $out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />';
  519. $out .= '<style type="text/css">' . "\n" .
  520. '<!--' . "\n";
  521. $out .= $options['css'] . "\n";
  522. $out .= '.editorcontainer { overflow:hidden; background:#FFFFFF; }
  523. .content { width:98%; }
  524. .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; }
  525. .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; }
  526. .quicktags { padding: 0; margin-bottom: -1px; border-bottom-width:1px; background-image: url("images/ed-bg.gif"); background-position: left top; background-repeat: repeat; }
  527. .quicktags div div { padding: 2px 4px 0; }
  528. .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";
  529. $out .= '-->' . "\n" .
  530. '</style>';
  531. echo $out;
  532. }
  533. function add_manage_posts_custom_column($column_name, $post_id) {
  534. $data = get_post_custom($post_id);
  535. if( is_array($data) && $column_name == 'custom-fields' ) :
  536. $flag = 0;
  537. $content = $output = '';
  538. foreach($data as $key => $val) :
  539. if ( substr($key, 0, 1) == '_' || !$val[0] ) continue;
  540. $content .= '<p class="key">' . $key . '</p>' . "\n";
  541. foreach($val as $val2) :
  542. $val2 = htmlspecialchars($val2, ENT_QUOTES);
  543. if ( $flag ) :
  544. $content .= '<p class="value">' . $val2 . '</p>' . "\n";
  545. else :
  546. if ( function_exists('mb_strlen') ) :
  547. if ( mb_strlen($val2) > 50 ) :
  548. $before_content = mb_substr($val2, 0, 50);
  549. $after_content = mb_substr($val2, 50);
  550. $content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n";
  551. $flag = 1;
  552. else :
  553. $content .= '<p class="value">' . $val2 . '</p>' . "\n";
  554. endif;
  555. else :
  556. if ( strlen($val2) > 50 ) :
  557. $before_content = substr($val2, 0, 50);
  558. $after_content = substr($val2, 50);
  559. $content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n";
  560. $flag = 1;
  561. else :
  562. $content .= '<p class="value">' . $val2 . '</p>' . "\n";
  563. endif;
  564. endif;
  565. endif;
  566. endforeach;
  567. endforeach;
  568. if ( $content ) :
  569. $content = preg_replace('/([^\n]+)\n([^\n]+)\n([^\n]+)\n([^\n]+)\n([^$]+)/', '\1\2\3\4[[[break]]]\5', $content);
  570. @list($before, $after) = explode('[[[break]]]', $content, 2);
  571. $after = preg_replace('/\[\[\[break\]\]\]/', '', $after);
  572. $output .= '<div class="cft_list">';
  573. $output .= balanceTags($before, true);
  574. if ( $after ) :
  575. $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>';
  576. $output .= '<span class="hide-if-js-cft">' . balanceTags($after, true) . '</span>';
  577. $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>';
  578. endif;
  579. $output .= '</div>';
  580. else :
  581. $output .= '&nbsp;';
  582. endif;
  583. endif;
  584. if ( isset($output) ) echo $output;
  585. }
  586. function add_manage_posts_columns($columns) {
  587. $new_columns = array();
  588. foreach($columns as $key => $val) :
  589. $new_columns[$key] = $val;
  590. if ( $key == 'tags' )
  591. $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template');
  592. endforeach;
  593. return $new_columns;
  594. }
  595. function add_manage_pages_columns($columns) {
  596. $new_columns = array();
  597. foreach($columns as $key => $val) :
  598. $new_columns[$key] = $val;
  599. if ( $key == 'author' )
  600. $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template');
  601. endforeach;
  602. return $new_columns;
  603. }
  604. function media_send_to_custom_field($html) {
  605. $out = '<script type="text/javascript">' . "\n" .
  606. ' /* <![CDATA[ */' . "\n" .
  607. ' var win = window.dialogArguments || opener || parent || top;' . "\n" .
  608. ' if ( typeof win.send_to_custom_field == "function" ) ' . "\n" .
  609. ' win.send_to_custom_field("' . addslashes($html) . '");' . "\n" .
  610. ' else ' . "\n" .
  611. ' win.send_to_editor("' . addslashes($html) . '");' . "\n" .
  612. '/* ]]> */' . "\n" .
  613. '</script>' . "\n";
  614. echo $out;
  615. exit();
  616. /*if ($options['custom_field_template_use_multiple_insert']) {
  617. return;
  618. } else {
  619. exit();
  620. }*/
  621. }
  622. function wpaq_filter_plugin_actions($links, $file){
  623. static $this_plugin;
  624. if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
  625. if( $file == $this_plugin ){
  626. $settings_link = '<a href="options-general.php?page=custom-field-template.php">' . __('Settings') . '</a>';
  627. $links = array_merge( array($settings_link), $links);
  628. }
  629. return $links;
  630. }
  631. function custom_field_template_admin_scripts() {
  632. global $post;
  633. $options = $this->get_custom_field_template_data();
  634. if ( !defined('WP_PLUGIN_DIR') )
  635. $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
  636. else
  637. $plugin_dir = dirname( plugin_basename(__FILE__) );
  638. wp_enqueue_script( 'jquery' );
  639. wp_enqueue_script( 'jquery-form' );
  640. wp_enqueue_script( 'bgiframe', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.bgiframe.js', array('jquery') ) ;
  641. wp_enqueue_script( 'textarearesizer', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.textarearesizer.js', array('jquery') );
  642. 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') ) :
  643. wp_enqueue_script('date', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/date.js', array('jquery') );
  644. wp_enqueue_script('datePicker', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.datePicker.js', array('jquery') );
  645. wp_enqueue_script('editor');
  646. wp_enqueue_script('quicktags');
  647. if ( !empty($options['custom_field_template_use_validation']) ) :
  648. wp_enqueue_script( 'jquery-validate', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.validate.js', array('jquery') );
  649. wp_enqueue_script( 'additional-methods', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/additional-methods.js', array('jquery') );
  650. if ( file_exists(ABSPATH . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG . '.js') )
  651. wp_enqueue_script( 'messages_' . WPLANG, '/' . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG .'.js', array('jquery') );
  652. endif;
  653. endif;
  654. }
  655. function install_custom_field_template_data() {
  656. $options['custom_field_template_before_list'] = '<ul>';
  657. $options['custom_field_template_after_list'] = '</ul>';
  658. $options['custom_field_template_before_value'] = '<li>';
  659. $options['custom_field_template_after_value'] = '</li>';
  660. $options['custom_fields'][0]['title'] = __('Default Template', 'custom-field-template');
  661. $options['custom_fields'][0]['content'] = '[Plan]
  662. type = text
  663. size = 35
  664. label = Where are you going to go?
  665. [Plan]
  666. type = textfield
  667. size = 35
  668. hideKey = true
  669. [Favorite Fruits]
  670. type = checkbox
  671. value = apple # orange # banana # grape
  672. default = orange # grape
  673. [Miles Walked]
  674. type = radio
  675. value = 0-9 # 10-19 # 20+
  676. default = 10-19
  677. clearButton = true
  678. [Temper Level]
  679. type = select
  680. value = High # Medium # Low
  681. default = Low
  682. [Hidden Thought]
  683. type = textarea
  684. rows = 4
  685. cols = 40
  686. tinyMCE = true
  687. htmlEditor = true
  688. mediaButton = true
  689. [File Upload]
  690. type = file';
  691. $options['shortcode_format'][0] = '<table class="cft">
  692. <tbody>
  693. <tr>
  694. <th>Plan</th><td colspan="3">[Plan]</td>
  695. </tr>
  696. <tr>
  697. <th>Favorite Fruits</th><td>[Favorite Fruits]</td>
  698. <th>Miles Walked</th><td>[Miles Walked]</td>
  699. </tr>
  700. <tr>
  701. <th>Temper Level</th><td colspan="3">[Temper Level]</td>
  702. </tr>
  703. <tr>
  704. <th>Hidden Thought</th><td colspan="3">[Hidden Thought]</td>
  705. </tr>
  706. </tbody>
  707. </table>';
  708. update_option('custom_field_template_data', $options);
  709. }
  710. function install_custom_field_template_css() {
  711. $options = get_option('custom_field_template_data');
  712. $options['css'] = '.cft { overflow:hidden; }
  713. .cft:after { content:" "; clear:both; height:0; display:block; visibility:hidden; }
  714. .cft dl { margin:10px 0; }
  715. .cft dl:after { content:" "; clear:both; height:0; display:block; visibility:hidden; }
  716. .cft dt { width:20%; clear:both; float:left; display:inline; font-weight:bold; text-align:center; }
  717. .cft dt .hideKey { visibility:hidden; }
  718. .cft dd { margin:0 0 0 21%; }
  719. .cft dd p.label { font-weight:bold; margin:0; }
  720. .cft_instruction { margin:10px; }
  721. .cft fieldset { border:1px solid #CCC; margin:5px; padding:5px; }
  722. .cft .dl_checkbox { margin:0; }
  723. ';
  724. update_option('custom_field_template_data', $options);
  725. }
  726. function get_custom_field_template_data() {
  727. $options = get_option('custom_field_template_data');
  728. return $options;
  729. }
  730. function custom_field_template_admin_menu() {
  731. 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'));
  732. }
  733. function custom_field_template_get_the_excerpt($excerpt) {
  734. $options = $this->get_custom_field_template_data();
  735. if ( empty($excerpt) ) $this->is_excerpt = true;
  736. if ( !empty($options['custom_field_template_excerpt_shortcode']) ) return do_shortcode($excerpt);
  737. else return $excerpt;
  738. }
  739. function custom_field_template_the_content($content) {
  740. global $wp_query, $post, $shortcode_tags, $wp_version;
  741. $options = $this->get_custom_field_template_data();
  742. if ( $this->is_excerpt ) :
  743. $this->is_excerpt = false;
  744. return $post->post_excerpt ? $post->post_excerpt : strip_shortcodes($content);
  745. endif;
  746. if ( isset($options['hook']) && count($options['hook']) > 0 ) :
  747. $categories = get_the_category();
  748. $cats = array();
  749. foreach( $categories as $val ) :
  750. $cats[] = $val->cat_ID;
  751. endforeach;
  752. if ( !empty($options['custom_fields'][$id]['post_type']) ) :
  753. if ( substr($wp_version, 0, 3) < '3.0' ) :
  754. 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')) ) :
  755. return;
  756. endif;
  757. 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')) ) :
  758. return;
  759. endif;
  760. else :
  761. if ( $post->post_type!=$options['custom_fields'][$id]['post_type'] ) :
  762. return;
  763. endif;
  764. endif;
  765. endif;
  766. for ( $i=0; $i<count($options['hook']); $i++ ) :
  767. $options['hook'][$i]['content'] = stripslashes($options['hook'][$i]['content']);
  768. if ( is_feed() && !$options['hook'][$i]['feed'] ) break;
  769. if ( !empty($options['hook'][$i]['category']) ) :
  770. if ( is_category() || is_single() || is_feed() ) :
  771. if ( !empty($options['hook'][$i]['use_php']) ) :
  772. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  773. endif;
  774. $needle = explode(',', $options['hook'][$i]['category']);
  775. $needle = array_filter($needle);
  776. $needle = array_unique(array_filter(array_map('trim', $needle)));
  777. foreach ( $needle as $val ) :
  778. if ( in_array($val, $cats ) ) :
  779. if ( $options['hook'][$i]['position'] == 0 )
  780. $content .= $options['hook'][$i]['content'];
  781. elseif ( $options['hook'][$i]['position'] == 2 )
  782. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  783. else
  784. $content = $options['hook'][$i]['content'] . $content;
  785. break;
  786. endif;
  787. endforeach;
  788. endif;
  789. elseif ( $options['hook'][$i]['post_type']=='post' ) :
  790. if ( is_category() || is_single() ) :
  791. if ( !empty($options['hook'][$i]['use_php']) ) :
  792. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  793. endif;
  794. if ( $options['hook'][$i]['position'] == 0 )
  795. $content .= $options['hook'][$i]['content'];
  796. elseif ( $options['hook'][$i]['position'] == 2 )
  797. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  798. else
  799. $content = $options['hook'][$i]['content'] . $content;
  800. endif;
  801. elseif ( $options['hook'][$i]['post_type']=='page' ) :
  802. if ( is_page() ) :
  803. if ( !empty($options['hook'][$i]['use_php']) ) :
  804. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  805. endif;
  806. if ( $options['hook'][$i]['position'] == 0 )
  807. $content .= $options['hook'][$i]['content'];
  808. elseif ( $options['hook'][$i]['position'] == 2 )
  809. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  810. else
  811. $content = $options['hook'][$i]['content'] . $content;
  812. endif;
  813. elseif ( $options['hook'][$i]['custom_post_type'] ) :
  814. $custom_post_type = explode(',', $options['hook'][$i]['custom_post_type']);
  815. $custom_post_type = array_filter( $custom_post_type );
  816. array_walk( $custom_post_type, create_function('&$v', '$v = trim($v);') );
  817. if ( in_array($post->post_type, $custom_post_type) ) :
  818. if ( !empty($options['hook'][$i]['use_php']) ) :
  819. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  820. endif;
  821. if ( $options['hook'][$i]['position'] == 0 )
  822. $content .= $options['hook'][$i]['content'];
  823. elseif ( $options['hook'][$i]['position'] == 2 )
  824. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  825. else
  826. $content = $options['hook'][$i]['content'] . $content;
  827. endif;
  828. else :
  829. if ( !empty($options['hook'][$i]['use_php']) ) :
  830. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  831. endif;
  832. if ( $options['hook'][$i]['position'] == 0 )
  833. $content .= $options['hook'][$i]['content'];
  834. elseif ( $options['hook'][$i]['position'] == 2 )
  835. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  836. else
  837. $content = $options['hook'][$i]['content'] . $content;
  838. endif;
  839. endfor;
  840. endif;
  841. return do_shortcode($content);
  842. }
  843. function custom_field_template_admin() {
  844. global $wp_version;
  845. $options = $this->get_custom_field_template_data();
  846. if( !empty($_POST["custom_field_template_set_options_submit"]) ) :
  847. unset($options['custom_fields']);
  848. $j = 0;
  849. for($i=0;$i<count($_POST["custom_field_template_content"]);$i++) {
  850. if( $_POST["custom_field_template_content"][$i] ) {
  851. if ( preg_match('/\[content\]|\[post_title\]|\[excerpt\]|\[action\]/i', $_POST["custom_field_template_content"][$i]) ) :
  852. $errormessage = __('You can not use the following words as the field key: `content`, `post_title`, and `excerpt`, and `action`.', 'custom-field-template');
  853. endif;
  854. if ( isset($_POST["custom_field_template_title"][$i]) ) $options['custom_fields'][$j]['title'] = $_POST["custom_field_template_title"][$i];
  855. if ( isset($_POST["custom_field_template_content"][$i]) ) $options['custom_fields'][$j]['content'] = $_POST["custom_field_template_content"][$i];
  856. if ( isset($_POST["custom_field_template_instruction"][$i]) ) $options['custom_fields'][$j]['instruction'] = $_POST["custom_field_template_instruction"][$i];
  857. if ( isset($_POST["custom_field_template_category"][$i]) ) $options['custom_fields'][$j]['category'] = $_POST["custom_field_template_category"][$i];
  858. if ( isset($_POST["custom_field_template_post"][$i]) ) $options['custom_fields'][$j]['post'] = $_POST["custom_field_template_post"][$i];
  859. if ( isset($_POST["custom_field_template_post_type"][$i]) ) $options['custom_fields'][$j]['post_type'] = $_POST["custom_field_template_post_type"][$i];
  860. 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];
  861. if ( isset($_POST["custom_field_template_template_files"][$i]) ) $options['custom_fields'][$j]['template_files'] = $_POST["custom_field_template_template_files"][$i];
  862. if ( isset($_POST["custom_field_template_disable"][$i]) ) $options['custom_fields'][$j]['disable'] = $_POST["custom_field_template_disable"][$i];
  863. $j++;
  864. }
  865. }
  866. update_option('custom_field_template_data', $options);
  867. $message = __('Options updated.', 'custom-field-template');
  868. elseif( !empty($_POST["custom_field_template_global_settings_submit"]) ) :
  869. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  870. $options['custom_field_template_use_multiple_insert'] = isset($_POST['custom_field_template_use_multiple_insert']) ? 1 : '';
  871. $options['custom_field_template_use_wpautop'] = isset($_POST['custom_field_template_use_wpautop']) ? 1 : '';
  872. $options['custom_field_template_use_autosave'] = isset($_POST['custom_field_template_use_autosave']) ? 1 : '';
  873. $options['custom_field_template_use_disable_button'] = isset($_POST['custom_field_template_use_disable_button']) ? 1 : '';
  874. $options['custom_field_template_disable_initialize_button'] = isset($_POST['custom_field_template_disable_initialize_button']) ? 1 : '';
  875. $options['custom_field_template_disable_save_button'] = isset($_POST['custom_field_template_disable_save_button']) ? 1 : '';
  876. $options['custom_field_template_disable_default_custom_fields'] = isset($_POST['custom_field_template_disable_default_custom_fields']) ? 1 : '';
  877. $options['custom_field_template_disable_quick_edit'] = isset($_POST['custom_field_template_disable_quick_edit']) ? 1 : '';
  878. $options['custom_field_template_disable_custom_field_column'] = isset($_POST['custom_field_template_disable_custom_field_column']) ? 1 : '';
  879. $options['custom_field_template_replace_the_title'] = isset($_POST['custom_field_template_replace_the_title']) ? 1 : '';
  880. $options['custom_field_template_deploy_box'] = isset($_POST['custom_field_template_deploy_box']) ? 1 : '';
  881. if ( !empty($options['custom_field_template_deploy_box']) ) :
  882. $options['css'] = preg_replace('/#cft /', '.cft ', $options['css']);
  883. $options['css'] = preg_replace('/#cft_/', '.cft_', $options['css']);
  884. endif;
  885. $options['custom_field_template_widget_shortcode'] = isset($_POST['custom_field_template_widget_shortcode']) ? 1 : '';
  886. $options['custom_field_template_excerpt_shortcode'] = isset($_POST['custom_field_template_excerpt_shortcode']) ? 1 : '';
  887. $options['custom_field_template_use_validation'] = isset($_POST['custom_field_template_use_validation']) ? 1 : '';
  888. $options['custom_field_template_before_list'] = isset($_POST['custom_field_template_before_list']) ? $_POST['custom_field_template_before_list'] : '';
  889. $options['custom_field_template_after_list'] = isset($_POST['custom_field_template_after_list']) ? $_POST['custom_field_template_after_list'] : '';
  890. $options['custom_field_template_before_value'] = isset($_POST['custom_field_template_before_value']) ? $_POST['custom_field_template_before_value'] : '';
  891. $options['custom_field_template_after_value'] = isset($_POST['custom_field_template_after_value']) ? $_POST['custom_field_template_after_value'] : '';
  892. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  893. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  894. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  895. $options['custom_field_template_disable_ad'] = isset($_POST['custom_field_template_disable_ad']) ? 1 : '';
  896. update_option('custom_field_template_data', $options);
  897. $message = __('Options updated.', 'custom-field-template');
  898. elseif ( !empty($_POST['custom_field_template_css_submit']) ) :
  899. $options['css'] = $_POST['custom_field_template_css'];
  900. update_option('custom_field_template_data', $options);
  901. $message = __('Options updated.', 'custom-field-template');
  902. elseif ( !empty($_POST['custom_field_template_shortcode_format_submit']) ) :
  903. unset($options['shortcode_format'], $options['shortcode_format_use_php']);
  904. $j = 0;
  905. for($i=0;$i<count($_POST["custom_field_template_shortcode_format"]);$i++) {
  906. if( $_POST["custom_field_template_shortcode_format"][$i] ) :
  907. $options['shortcode_format'][$j] = $_POST["custom_field_template_shortcode_format"][$i];
  908. $options['shortcode_format_use_php'][$j] = $_POST["custom_field_template_shortcode_format_use_php"][$i];
  909. $j++;
  910. endif;
  911. }
  912. update_option('custom_field_template_data', $options);
  913. $message = __('Options updated.', 'custom-field-template');
  914. elseif ( !empty($_POST['custom_field_template_php_submit']) ) :
  915. unset($options['php']);
  916. for($i=0;$i<count($_POST["custom_field_template_php"]);$i++) {
  917. if( $_POST["custom_field_template_php"][$i] )
  918. $options['php'][] = $_POST["custom_field_template_php"][$i];
  919. }
  920. update_option('custom_field_template_data', $options);
  921. $message = __('Options updated.', 'custom-field-template');
  922. elseif( !empty($_POST["custom_field_template_hook_submit"]) ) :
  923. unset($options['hook']);
  924. $j = 0;
  925. for($i=0;$i<count($_POST["custom_field_template_hook_content"]);$i++) {
  926. if( $_POST["custom_field_template_hook_content"][$i] ) {
  927. $options['hook'][$j]['position'] = $_POST["custom_field_template_hook_position"][$i];
  928. $options['hook'][$j]['content'] = $_POST["custom_field_template_hook_content"][$i];
  929. $options['hook'][$j]['custom_post_type'] = preg_replace('/\s/', '', $_POST["custom_field_template_hook_custom_post_type"][$i]);
  930. $options['hook'][$j]['category'] = preg_replace('/\s/', '', $_POST["custom_field_template_hook_category"][$i]);
  931. $options['hook'][$j]['use_php'] = $_POST["custom_field_template_hook_use_php"][$i];
  932. $options['hook'][$j]['feed'] = $_POST["custom_field_template_hook_feed"][$i];
  933. $options['hook'][$j]['post_type'] = $_POST["custom_field_template_hook_post_type"][$i];
  934. $j++;
  935. }
  936. }
  937. update_option('custom_field_template_data', $options);
  938. $message = __('Options updated.', 'custom-field-template');
  939. elseif ( !empty($_POST['custom_field_template_rebuild_value_counts_submit']) ) :
  940. $this->custom_field_template_rebuild_value_counts();
  941. $options = $this->get_custom_field_template_data();
  942. $message = __('Value Counts rebuilt.', 'custom-field-template');
  943. elseif ( !empty($_POST['custom_field_template_rebuild_tags_submit']) ) :
  944. $options = $this->get_custom_field_template_data();
  945. $message = __('Tags rebuilt.', 'custom-field-template');
  946. elseif ( !empty($_POST['custom_field_template_import_options_submit']) ) :
  947. if ( is_uploaded_file($_FILES['cftfile']['tmp_name']) ) :
  948. ob_start();
  949. readfile ($_FILES['cftfile']['tmp_name']);
  950. $import = ob_get_contents();
  951. ob_end_clean();
  952. $import = maybe_unserialize($import);
  953. update_option('custom_field_template_data', $import);
  954. $message = __('Options imported.', 'custom-field-template');
  955. $options = $this->get_custom_field_template_data();
  956. endif;
  957. elseif ( !empty($_POST['custom_field_template_reset_options_submit']) ) :
  958. $this->install_custom_field_template_data();
  959. $this->install_custom_field_template_css();
  960. $options = $this->get_custom_field_template_data();
  961. $message = __('Options resetted.', 'custom-field-template');
  962. elseif ( !empty($_POST['custom_field_template_delete_options_submit']) ) :
  963. delete_option('custom_field_template_data');
  964. $options = $this->get_custom_field_template_data();
  965. $message = __('Options deleted.', 'custom-field-template');
  966. endif;
  967. if ( !defined('WP_PLUGIN_DIR') )
  968. $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
  969. else
  970. $plugin_dir = dirname( plugin_basename(__FILE__) );
  971. ?>
  972. <style type="text/css">
  973. div.grippie {
  974. background:#EEEEEE url(<?php echo '../' . PLUGINDIR . '/' . $plugin_dir . '/js/'; ?>grippie.png) no-repeat scroll center 2px;
  975. border-color:#DDDDDD;
  976. border-style:solid;
  977. border-width:0pt 1px 1px;
  978. cursor:s-resize;
  979. height:9px;
  980. overflow:hidden;
  981. }
  982. .resizable-textarea textarea {
  983. display:block;
  984. margin-bottom:0pt;
  985. }
  986. </style>
  987. <script type="text/javascript">
  988. jQuery(document).ready(function() {
  989. jQuery('textarea.resizable:not(.processed)').TextAreaResizer();
  990. });
  991. </script>
  992. <?php if ( !empty($message) ) : ?>
  993. <div id="message" class="updated"><p><?php echo $message; ?></p></div>
  994. <?php endif; ?>
  995. <?php if ( !empty($errormessage) ) : ?>
  996. <div id="errormessage" class="error"><p><?php echo $errormessage; ?></p></div>
  997. <?php endif; ?>
  998. <div class="wrap">
  999. <div id="icon-plugins" class="icon32"><br/></div>
  1000. <h2><?php _e('Custom Field Template', 'custom-field-template'); ?></h2>
  1001. <br class="clear"/>
  1002. <div id="poststuff" style="position: relative; margin-top:10px;">
  1003. <?php if ( empty($options['custom_field_template_disable_ad']) ) : ?><div style="width:75%; float:left;"><?php endif; ?>
  1004. <div class="postbox">
  1005. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1006. <h3><?php _e('Custom Field Template Options', 'custom-field-template'); ?></h3>
  1007. <div class="inside">
  1008. <form method="post">
  1009. <table class="form-table" style="margin-bottom:5px;">
  1010. <tbody>
  1011. <?php
  1012. for ( $i = 0; $i < count($options['custom_fields'])+1; $i++ ) {
  1013. ?>
  1014. <tr><td>
  1015. <p><strong>TEMPLATE #<?php echo $i; ?></strong>
  1016. <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>
  1017. </p>
  1018. <p><label for="custom_field_template_title[<?php echo $i; ?>]"><?php echo sprintf(__('Template Title', 'custom-field-template'), $i); ?></label>:<br />
  1019. <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>
  1020. <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 />
  1021. <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 stripcslashes($options['custom_fields'][$i]['instruction']); ?></textarea></p>
  1022. <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 />
  1023. <span<?php if ( empty($options['custom_fields'][$i]['post_type']) ) : echo ' style="display:none;"'; endif; ?>>
  1024. <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'); ?>
  1025. <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'); ?>
  1026. <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>
  1027. <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 />
  1028. <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>
  1029. <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 />
  1030. <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>
  1031. <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 />
  1032. <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>
  1033. <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 />
  1034. <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>
  1035. <p><label for="custom_field_template_content[<?php echo $i; ?>]"><?php echo sprintf(__('Template Content', 'custom-field-template'), $i); ?></label>:<br />
  1036. <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 stripcslashes($options['custom_fields'][$i]['content']); ?></textarea></p>
  1037. </td></tr>
  1038. <?php
  1039. }
  1040. ?>
  1041. <tr><td>
  1042. <p><input type="submit" name="custom_field_template_set_options_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1043. </td></tr>
  1044. </tbody>
  1045. </table>
  1046. </form>
  1047. </div>
  1048. </div>
  1049. <div class="postbox closed">
  1050. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1051. <h3><?php _e('Global Settings', 'custom-field-template'); ?></h3>
  1052. <div class="inside">
  1053. <form method="post">
  1054. <table class="form-table" style="margin-bottom:5px;">
  1055. <tbody>
  1056. <?php
  1057. /*
  1058. <tr><td>
  1059. <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 />
  1060. <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>
  1061. </td>
  1062. </tr>
  1063. */
  1064. ?>
  1065. <tr><td>
  1066. <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 />
  1067. <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>
  1068. </td></tr>
  1069. <tr><td>
  1070. <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 />
  1071. <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>
  1072. </td>
  1073. </tr>
  1074. <tr><td>
  1075. <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 />
  1076. <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>
  1077. </td>
  1078. </tr>
  1079. <tr><td>
  1080. <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 />
  1081. <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>
  1082. </td>
  1083. </tr>
  1084. <tr><td>
  1085. <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 />
  1086. <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>
  1087. </td>
  1088. </tr>
  1089. <tr><td>
  1090. <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 />
  1091. <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>
  1092. </td>
  1093. </tr>
  1094. <tr><td>
  1095. <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 />
  1096. <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>
  1097. </td>
  1098. </tr>
  1099. <tr><td>
  1100. <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 />
  1101. <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>
  1102. </td>
  1103. </tr>
  1104. <tr><td>
  1105. <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 />
  1106. <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>
  1107. </td>
  1108. </tr>
  1109. <tr><td>
  1110. <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 />
  1111. <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>
  1112. </td>
  1113. </tr>
  1114. <tr><td>
  1115. <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 />
  1116. <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>
  1117. </td>
  1118. </tr>
  1119. <tr><td>
  1120. <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 />
  1121. <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>
  1122. </td>
  1123. </tr>
  1124. <tr><td>
  1125. <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 />
  1126. <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>
  1127. </td>
  1128. </tr>
  1129. <tr><td>
  1130. <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 />
  1131. <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>
  1132. </td>
  1133. </tr>
  1134. <tr><td>
  1135. <?php
  1136. if ( !isset($options['custom_field_template_before_list']) ) $options['custom_field_template_before_list'] = '<ul>';
  1137. if ( !isset($options['custom_field_template_after_list']) ) $options['custom_field_template_after_list'] = '</ul>';
  1138. if ( !isset($options['custom_field_template_before_value']) ) $options['custom_field_template_before_value'] = '<li>';
  1139. if ( !isset($options['custom_field_template_after_value']) ) $options['custom_field_template_after_value'] = '</li>';
  1140. ?>
  1141. <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 />
  1142. <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>
  1143. <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 />
  1144. <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>
  1145. <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 />
  1146. <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>
  1147. <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 />
  1148. <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>
  1149. </td>
  1150. </tr>
  1151. <tr><td>
  1152. <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 />
  1153. <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>
  1154. </td>
  1155. </tr>
  1156. <tr><td>
  1157. <p><input type="submit" name="custom_field_template_global_settings_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1158. </td></tr>
  1159. </tbody>
  1160. </table>
  1161. </form>
  1162. </div>
  1163. </div>
  1164. <div class="postbox closed">
  1165. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1166. <h3><?php _e('ADMIN CSS', 'custom-field-template'); ?></h3>
  1167. <div class="inside">
  1168. <form method="post">
  1169. <table class="form-table" style="margin-bottom:5px;">
  1170. <tbody>
  1171. <tr><td>
  1172. <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 stripcslashes($options['css']); ?></textarea></p>
  1173. </td></tr>
  1174. <tr><td>
  1175. <p><input type="submit" name="custom_field_template_css_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1176. </td></tr>
  1177. </tbody>
  1178. </table>
  1179. </form>
  1180. </div>
  1181. </div>
  1182. <div class="postbox closed">
  1183. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1184. <h3><?php _e('[cft] and [cftsearch] Shortcode Format', 'custom-field-template'); ?></h3>
  1185. <div class="inside">
  1186. <form method="post">
  1187. <p><?php _e('For [cft], [key] will be converted into the value of [key].', 'custom-field-template'); ?><br />
  1188. <?php _e('For [cftsearch], [key] will be converted into the input field.', 'custom-field-template'); ?></p>
  1189. <table class="form-table" style="margin-bottom:5px;">
  1190. <tbody>
  1191. <?php
  1192. if ( isset($options['shortcode_format']) ) $count = count($options['shortcode_format']);
  1193. else $count = 0;
  1194. for ($i=0;$i<$count+1;$i++) :
  1195. ?>
  1196. <tr><th><strong>FORMAT #<?php echo $i; ?></strong></th></tr>
  1197. <tr><td>
  1198. <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 stripcslashes($options['shortcode_format'][$i]); ?></textarea></p>
  1199. <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>
  1200. </td></tr>
  1201. <?php
  1202. endfor;
  1203. ?>
  1204. <tr><td>
  1205. <p><input type="submit" name="custom_field_template_shortcode_format_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1206. </td></tr>
  1207. </tbody>
  1208. </table>
  1209. </form>
  1210. </div>
  1211. </div>
  1212. <div class="postbox closed">
  1213. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1214. <h3><?php _e('PHP CODE (Experimental Option)', 'custom-field-template'); ?></h3>
  1215. <div class="inside">
  1216. <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'); ?>');">
  1217. <dl><dt><?php _e('For `text` and `textarea`, you must set $value as an string.', 'custom-field-template'); ?><br />
  1218. ex. `text` and `textarea`:</dt><dd>$value = 'Yes we can.';</dd></dl>
  1219. <dl><dt><?php _e('For `checkbox`, `radio`, and `select`, you must set $values as an array.', 'custom-field-template'); ?><br />
  1220. ex. `radio` and `select`:</dt><dd>$values = array('dog', 'cat', 'monkey'); $default = 'cat';</dd>
  1221. <dt>ex. `checkbox`:</dt><dd>$values = array('dog', 'cat', 'monkey'); $defaults = array('dog', 'cat');</dd></dl>
  1222. <table class="form-table" style="margin-bottom:5px;">
  1223. <tbody>
  1224. <?php
  1225. if ( isset($options['php']) ) $count = count($options['php']);
  1226. else $count = 0;
  1227. for ($i=0;$i<$count+1;$i++) :
  1228. ?>
  1229. <tr><th><strong>CODE #<?php echo $i; ?></strong></th></tr>
  1230. <tr><td>
  1231. <p><textarea name="custom_field_template_php[]" class="large-text resizable" rows="10" cols="80"><?php if ( isset($options['php'][$i]) ) echo stripcslashes($options['php'][$i]); ?></textarea></p>
  1232. </td></tr>
  1233. <?php
  1234. endfor;
  1235. ?>
  1236. <tr><td>
  1237. <p><input type="submit" name="custom_field_template_php_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1238. </td></tr>
  1239. </tbody>
  1240. </table>
  1241. </form>
  1242. </div>
  1243. </div>
  1244. <div class="postbox closed">
  1245. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1246. <h3><?php _e('Auto Hook of `the_content()` (Experimental Option)', 'custom-field-template'); ?></h3>
  1247. <div class="inside">
  1248. <form method="post">
  1249. <table class="form-table" style="margin-bottom:5px;">
  1250. <tbody>
  1251. <?php
  1252. if ( isset($options['hook']) ) $count = count($options['hook']);
  1253. else $count = 0;
  1254. for ($i=0;$i<$count+1;$i++) :
  1255. ?>
  1256. <tr><th><strong>HOOK #<?php echo $i; ?></strong></th></tr>
  1257. <tr><td>
  1258. <p><label for="custom_field_template_hook_position[<?php echo $i; ?>]"><?php echo sprintf(__('Position', 'custom-field-template'), $i); ?></label>:<br />
  1259. <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'); ?>
  1260. <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'); ?>
  1261. <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); ?>
  1262. </p>
  1263. <p><label for="custom_field_template_hook_post_type[<?php echo $i; ?>]"><?php echo sprintf(__('Post Type', 'custom-field-template'), $i); ?></label>:<br />
  1264. <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'); ?>
  1265. <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'); ?>
  1266. <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'); ?></p>
  1267. <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 />
  1268. <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>
  1269. <p><label for="custom_field_template_hook_category[<?php echo $i; ?>]"><?php echo sprintf(__('Category ID (comma-deliminated)', 'custom-field-template'), $i); ?></label>:<br />
  1270. <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>
  1271. <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 stripcslashes($options['hook'][$i]['content']); ?></textarea></p>
  1272. <p><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'); ?></p>
  1273. <p><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'); ?></p>
  1274. </td></tr>
  1275. <?php
  1276. endfor;
  1277. ?>
  1278. <tr><td>
  1279. <p><input type="submit" name="custom_field_template_hook_submit" value="<?php _e('Update Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1280. </td></tr>
  1281. </tbody>
  1282. </table>
  1283. </form>
  1284. </div>
  1285. </div>
  1286. <div class="postbox closed">
  1287. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1288. <h3><?php _e('Rebuild Value Counts', 'custom-field-template'); ?></h3>
  1289. <div class="inside">
  1290. <form method="post" onsubmit="return confirm('<?php _e('Are you sure to rebuild all value counts?', 'custom-field-template'); ?>');">
  1291. <table class="form-table" style="margin-bottom:5px;">
  1292. <tbody>
  1293. <tr><td>
  1294. <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>
  1295. <p>global $custom_field_template;<br />
  1296. $value_count = $custom_field_template->get_value_count();<br />
  1297. echo $value_count[$meta_key][$meta_value];</p>
  1298. <p><input type="submit" name="custom_field_template_rebuild_value_counts_submit" value="<?php _e('Rebuild Value Counts &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1299. </td></tr>
  1300. </tbody>
  1301. </table>
  1302. </form>
  1303. </div>
  1304. </div>
  1305. <!--
  1306. <div class="postbox closed">
  1307. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1308. <h3><?php _e('Rebuild Tags', 'custom-field-template'); ?></h3>
  1309. <div class="inside">
  1310. <form method="post" onsubmit="return confirm('<?php _e('Are you sure to rebuild tags?', 'custom-field-template'); ?>');">
  1311. <table class="form-table" style="margin-bottom:5px;">
  1312. <tbody>
  1313. <tr><td>
  1314. <p><input type="submit" name="custom_field_template_rebuild_tags_submit" value="<?php _e('Rebuild Tags &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1315. </td></tr>
  1316. </tbody>
  1317. </table>
  1318. </form>
  1319. </div>
  1320. </div>
  1321. //-->
  1322. <div class="postbox closed">
  1323. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1324. <h3><?php _e('Option List', 'custom-field-template'); ?></h3>
  1325. <div class="inside">
  1326. ex.<br />
  1327. [Plan]<br />
  1328. type = textfield<br />
  1329. size = 35<br />
  1330. hideKey = true<br />
  1331. <table class="widefat" style="margin:10px 0 5px 0;">
  1332. <thead>
  1333. <tr>
  1334. <th>type</th><th>text or textfield</th><th>checkbox</th><th>radio</th><th>select</th><th>textarea</th><th>file</th>
  1335. </tr>
  1336. </thead>
  1337. <tbody>
  1338. <tr>
  1339. <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>
  1340. </tr>
  1341. <tr>
  1342. <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>
  1343. </tr>
  1344. <tr>
  1345. <th>size</th><td>size = 30</td><td></td><td></td><td></td><td></td><td>size = 30</td>
  1346. </tr>
  1347. <tr>
  1348. <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>
  1349. <td></td>
  1350. </tr>
  1351. <tr>
  1352. <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>
  1353. <td></td>
  1354. </tr>
  1355. <tr>
  1356. <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>
  1357. </tr>
  1358. <tr>
  1359. <th>clearButton</th><td></td><td></td><td>clearButton = true</td><td></td><td></td><td></td>
  1360. </tr>
  1361. <tr>
  1362. <th>selectLabel</th><td></td><td></td><td></td><td>selectLabel = Select a fruit</td><td></td><td></td>
  1363. </tr>
  1364. <tr>
  1365. <th>rows</th><td></td><td></td><td></td><td></td><td>rows = 4</td><td></td>
  1366. </tr>
  1367. <tr>
  1368. <th>cols</th><td></td><td></td><td></td><td></td><td>cols = 40</td><td></td>
  1369. </tr>
  1370. <tr>
  1371. <th>tinyMCE</th><td></td><td></td><td></td><td></td><td>tinyMCE = true</td><td></td>
  1372. </tr>
  1373. <tr>
  1374. <th>htmlEditor</th><td></td><td></td><td></td><td></td><td>htmlEditor = true</td><td></td>
  1375. </tr>
  1376. <tr>
  1377. <th>date</th><td>date = true</td><td></td><td></td><td></td><td></td><td></td>
  1378. </tr>
  1379. <tr>
  1380. <th>dateFirstDayOfWeek</th><td>dateFirstDayOfWeek = 0</td><td></td><td></td><td></td><td></td><td></td>
  1381. </tr>
  1382. <tr>
  1383. <th>dateFormat</th><td>dateFormat = yyyy/mm/dd</td><td></td><td></td><td></td><td></td><td></td>
  1384. </tr>
  1385. <tr>
  1386. <th>startDate</th><td>startDate = '1970/01/01'</td><td></td><td></td><td></td><td></td><td></td>
  1387. </tr>
  1388. <tr>
  1389. <th>endDate</th><td>endDate = (new Date()).asString()</td><td></td><td></td><td></td><td></td><td></td>
  1390. </tr>
  1391. <tr>
  1392. <th>readOnly</th><td>readOnly = true</td><td></td><td></td><td></td><td></td><td></td>
  1393. </tr>
  1394. <tr>
  1395. <th>mediaButton</th><td></td><td></td><td></td><td></td><td>mediaButton = true</td><td></td>
  1396. </tr>
  1397. <tr>
  1398. <th>mediaOffImage</th><td></td><td></td><td></td><td></td><td>mediaOffImage = true</td><td></td>
  1399. </tr>
  1400. <tr>
  1401. <th>mediaOffVideo</th><td></td><td></td><td></td><td></td><td>mediaOffVideo = true</td><td></td>
  1402. </tr>
  1403. <tr>
  1404. <th>mediaOffAudio</th><td></td><td></td><td></td><td></td><td>mediaOffAudio = true</td><td></td>
  1405. </tr>
  1406. <tr>
  1407. <th>mediaOffMedia</th><td></td><td></td><td></td><td></td><td>mediaOffMedia = true</td><td></td>
  1408. </tr>
  1409. <tr>
  1410. <th>relation</th><td></td><td></td><td></td><td></td><td></td><td>relation = true</td>
  1411. </tr>
  1412. <tr>
  1413. <th>mediaLibrary</th><td></td><td></td><td></td><td></td><td></td><td>mediaLibrary = true</td>
  1414. </tr>
  1415. <tr>
  1416. <th>mediaPicker</th><td></td><td></td><td></td><td></td><td></td><td>mediaPicker = true</td>
  1417. </tr>
  1418. <tr>
  1419. <th>mediaRemove</th><td></td><td></td><td></td><td></td><td></td><td>mediaRemove = true</td>
  1420. </tr>
  1421. <tr>
  1422. <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>
  1423. </tr>
  1424. <tr>
  1425. <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>
  1426. </tr>
  1427. <tr>
  1428. <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>
  1429. </tr>
  1430. <tr>
  1431. <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>
  1432. </tr>
  1433. <tr>
  1434. <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>
  1435. </tr>
  1436. <tr>
  1437. <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>
  1438. </tr>
  1439. <tr>
  1440. <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>
  1441. </tr>
  1442. <tr>
  1443. <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>
  1444. </tr>
  1445. <tr>
  1446. <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>
  1447. </tr>
  1448. <tr>
  1449. <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>
  1450. </tr>
  1451. <tr>
  1452. <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>
  1453. </tr>
  1454. <tr>
  1455. <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>
  1456. </tr>
  1457. <tr>
  1458. <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>
  1459. </tr>
  1460. <tr>
  1461. <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>
  1462. </tr>
  1463. <tr>
  1464. <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>
  1465. </tr>
  1466. <tr>
  1467. <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>
  1468. </tr>
  1469. <tr>
  1470. <th>search</th><td>search = true</td><td>search = true</td><td>search = true</td><td>search = true</td><td>search = true</td>
  1471. </tr>
  1472. <tr>
  1473. <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>
  1474. </tr>
  1475. <tr>
  1476. <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>
  1477. </tr>
  1478. <tr>
  1479. <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>
  1480. </tr>
  1481. <tr>
  1482. <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>
  1483. </tr>
  1484. <tr>
  1485. <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>
  1486. </tr>
  1487. <tr>
  1488. <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>
  1489. </tr>
  1490. </tbody>
  1491. </table>
  1492. </div>
  1493. </div>
  1494. <div class="postbox closed">
  1495. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1496. <h3><?php _e('Export Options', 'custom-field-template'); ?></h3>
  1497. <div class="inside">
  1498. <form method="post">
  1499. <table class="form-table" style="margin-bottom:5px;">
  1500. <tbody>
  1501. <tr><td>
  1502. <p><input type="submit" name="custom_field_template_export_options_submit" value="<?php _e('Export Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1503. </td></tr>
  1504. </tbody>
  1505. </table>
  1506. </form>
  1507. </div>
  1508. </div>
  1509. <div class="postbox closed">
  1510. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1511. <h3><?php _e('Import Options', 'custom-field-template'); ?></h3>
  1512. <div class="inside">
  1513. <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'); ?>');">
  1514. <table class="form-table" style="margin-bottom:5px;">
  1515. <tbody>
  1516. <tr><td>
  1517. <p><input type="file" name="cftfile" /> <input type="submit" name="custom_field_template_import_options_submit" value="<?php _e('Import Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1518. </td></tr>
  1519. </tbody>
  1520. </table>
  1521. </form>
  1522. </div>
  1523. </div>
  1524. <div class="postbox closed">
  1525. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1526. <h3><?php _e('Reset Options', 'custom-field-template'); ?></h3>
  1527. <div class="inside">
  1528. <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'); ?>');">
  1529. <table class="form-table" style="margin-bottom:5px;">
  1530. <tbody>
  1531. <tr><td>
  1532. <p><input type="submit" name="custom_field_template_reset_options_submit" value="<?php _e('Reset Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1533. </td></tr>
  1534. </tbody>
  1535. </table>
  1536. </form>
  1537. </div>
  1538. </div>
  1539. <div class="postbox closed">
  1540. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1541. <h3><?php _e('Delete Options', 'custom-field-template'); ?></h3>
  1542. <div class="inside">
  1543. <form method="post" onsubmit="return confirm('<?php _e('Are you sure to delete options? Options you set will be deleted.', 'custom-field-template'); ?>');">
  1544. <table class="form-table" style="margin-bottom:5px;">
  1545. <tbody>
  1546. <tr><td>
  1547. <p><input type="submit" name="custom_field_template_delete_options_submit" value="<?php _e('Delete Options &raquo;', 'custom-field-template'); ?>" class="button-primary" /></p>
  1548. </td></tr>
  1549. </tbody>
  1550. </table>
  1551. </form>
  1552. </div>
  1553. </div>
  1554. </div>
  1555. <?php if ( empty($options['custom_field_template_disable_ad']) ) : ?>
  1556. <div style="width:24%; float:right;">
  1557. <div class="postbox" style="min-width:200px;">
  1558. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1559. <h3><?php _e('Donation', 'custom-field-template'); ?></h3>
  1560. <div class="inside">
  1561. <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>
  1562. <form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="text-align:center;" target="_blank">
  1563. <input type="hidden" name="cmd" value="_s-xclick">
  1564. <input type="hidden" name="hosted_button_id" value="WN7Y2442JPRU6">
  1565. <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG_global.gif" border="0" name="submit" alt="PayPal">
  1566. </form>
  1567. </div>
  1568. </div>
  1569. <?php
  1570. if ( WPLANG == 'ja' ) :
  1571. ?>
  1572. <div class="postbox" style="min-width:200px;">
  1573. <div class="handlediv" title="<?php _e('Click to toggle', 'custom-field-template'); ?>"><br /></div>
  1574. <h3><?php _e('CMS x WP', 'custom-field-template'); ?></h3>
  1575. <div class="inside">
  1576. <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>
  1577. <p style="text-align:center"><a href="http://www.cmswp.jp/" target="_blank"><img src="<?php echo get_option('home') . '/' . PLUGINDIR . '/' . $plugin_dir . '/js/'; ?>cmswp.jpg" width="125" height="125" alt="CMSxWP" /></a><br /><a href="http://www.cmswp.jp/" target="_blank"><?php _e('WordPress plugin sales site: CMS x WP', 'custom-field-template'); ?></a></p>
  1578. </div>
  1579. </div>
  1580. <?php
  1581. endif;
  1582. ?>
  1583. </div>
  1584. <?php endif; ?>
  1585. <script type="text/javascript">
  1586. // <![CDATA[
  1587. <?php if ( version_compare( substr($wp_version, 0, 3), '2.7', '<' ) ) { ?>
  1588. jQuery('.postbox h3').prepend('<a class="togbox">+</a> ');
  1589. <?php } ?>
  1590. jQuery('.postbox div.handlediv').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); } );
  1591. jQuery('.postbox h3').click( function() { jQuery(jQuery(this).parent().get(0)).toggleClass('closed'); } );
  1592. jQuery('.postbox.close-me').each(function(){
  1593. jQuery(this).addClass("closed");
  1594. });
  1595. //-->
  1596. </script>
  1597. </div>
  1598. <?php
  1599. }
  1600. function sanitize_name( $name ) {
  1601. $name = sanitize_title( $name );
  1602. $name = str_replace( '-', '_', $name );
  1603. return $name;
  1604. }
  1605. function get_custom_fields( $id ) {
  1606. $options = $this->get_custom_field_template_data();
  1607. if ( empty($options['custom_fields'][$id]) )
  1608. return null;
  1609. $custom_fields = $this->parse_ini_str( $options['custom_fields'][$id]['content'], true );
  1610. return $custom_fields;
  1611. }
  1612. function make_textfield( $name, $sid, $data ) {
  1613. $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 = '';
  1614. $hide = $addfield = $out = '';
  1615. extract($data);
  1616. $options = $this->get_custom_field_template_data();
  1617. $title = $name;
  1618. $name = $this->sanitize_name( $name );
  1619. if ( isset($code) && is_numeric($code) ) :
  1620. eval(stripcslashes($options['php'][$code]));
  1621. endif;
  1622. if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
  1623. if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
  1624. $value = $this->get_post_meta( $_REQUEST[ 'post' ], $title, false );
  1625. if ( !empty($value) && is_array($value) ) {
  1626. $ct_value = count($value);
  1627. $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
  1628. }
  1629. } else {
  1630. $value = stripslashes($default);
  1631. }
  1632. if ( empty($ct_value) ) :
  1633. $ct_value = !empty($startNum) ? $startNum-1 : 1;
  1634. endif;
  1635. if ( isset($enforced_value) ) :
  1636. $value = $enforced_value;
  1637. endif;
  1638. if ( isset($hideKey) && $hideKey == true ) $hide = ' class="hideKey"';
  1639. if ( !empty($class) && $date == true ) $class = ' class="' . $class . ' datePicker"';
  1640. elseif ( empty($class) && isset($date) && $date == true ) $class = ' class="datePicker"';
  1641. elseif ( !empty($class) ) $class = ' class="' . $class . '"';
  1642. if ( !empty($style) ) $style = ' style="' . $style . '"';
  1643. if ( !empty($maxlength) ) $maxlength = ' maxlength="' . $maxlength . '"';
  1644. if ( !empty($readOnly) ) $readOnly = ' readonly="readonly"';
  1645. if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  1646. $title = stripcslashes($label);
  1647. $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);
  1648. $event_output = "";
  1649. foreach($event as $key => $val) :
  1650. if ( $val )
  1651. $event_output .= " " . $key . '="' . stripcslashes(trim($val)) . '"';
  1652. endforeach;
  1653. if ( isset($multipleButton) && $multipleButton == true && $date != true && $ct_value == $cftnum ) :
  1654. $addfield .= '<div style="margin-top:-1em;">';
  1655. $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>';
  1656. $addfield .= '</div>';
  1657. endif;
  1658. $out .=
  1659. '<dl id="dl_' . $name . $sid . '_' . $cftnum . '" class="dl_text">' .
  1660. '<dt><span' . $hide . '><label for="' . $name . $sid . '_' . $cftnum . '">' . $title . '</label></span>'.$addfield.'</dt>' .
  1661. '<dd>';
  1662. if ( !empty($label) && empty($options['custom_field_template_replace_keys_by_labels']) )
  1663. $out .= '<p class="label">' . stripcslashes($label) . '</p>';
  1664. $out .= trim($before).'<input id="' . $name . $sid . '_' . $cftnum . '" name="' . $name . '['. $sid . '][]" value="' . esc_attr(trim($value)) . '" type="text" size="' . $size . '"' . $class . $style . $maxlength . $event_output . $readOnly . ' />'.trim($after);
  1665. if ( $date == true ) :
  1666. $out .= '<script type="text/javascript">' . "\n" .
  1667. '// <![CDATA[' . "\n";
  1668. if ( is_numeric($dateFirstDayOfWeek) ) $out .= 'Date.firstDayOfWeek = ' . stripcslashes(trim($dateFirstDayOfWeek)) . ";\n";
  1669. if ( $dateFormat ) $out .= 'Date.format = "' . stripcslashes(trim($dateFormat)) . '"' . ";\n";
  1670. $out .= 'jQuery(document).ready(function() { jQuery(".datePicker").css("float", "left"); jQuery(".datePicker").datePicker({';
  1671. if ( $startDate ) $out .= "startDate: " . stripcslashes(trim($startDate));
  1672. if ( $startDate && $endDate ) $out .= ",";
  1673. if ( $endDate ) $out .= "endDate: " . stripcslashes(trim($endDate)) . "";
  1674. $out .= '}); });' . "\n" .
  1675. '// ]]>' . "\n" .
  1676. '</script>';
  1677. endif;
  1678. $out .= '</dd></dl>'."\n";
  1679. return $out;
  1680. }
  1681. function make_checkbox( $name, $sid, $data ) {
  1682. $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 = '';
  1683. $hide = $addfield = $out = '';
  1684. extract($data);
  1685. $options = $this->get_custom_field_template_data();
  1686. $title = $name;
  1687. $name = $this->sanitize_name( $name );
  1688. if ( !$value ) $value = "true";
  1689. if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
  1690. if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
  1691. $selected = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
  1692. if ( $selected ) {
  1693. if ( in_array(stripcslashes($value), $selected) ) $checked = 'checked="checked"';
  1694. }
  1695. } else {
  1696. if( $checked == true ) $checked = ' checked="checked"';
  1697. }
  1698. if ( $hideKey == true ) $hide = ' class="hideKey"';
  1699. if ( !empty($class) ) $class = ' class="' . $class . '"';
  1700. if ( !empty($style) ) $style = ' style="' . $style . '"';
  1701. if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  1702. $title = stripcslashes($label);
  1703. $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);
  1704. $event_output = "";
  1705. foreach($event as $key => $val) :
  1706. if ( $val )
  1707. $event_output .= " " . $key . '="' . stripcslashes(trim($val)) . '"';
  1708. endforeach;
  1709. $id = $name . '_' . $this->sanitize_name( $value ) . '_' . $sid . '_' . $cftnum;
  1710. $out .=
  1711. '<dl id="dl_' . $id . '" class="dl_checkbox">' .
  1712. '<dt><span' . $hide . '>' . $title . '</span></dt>' .
  1713. '<dd>';
  1714. if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] && $cftnum == 0 )
  1715. $out .= '<p class="label">' . stripcslashes($label) . '</p>';
  1716. $out .= '<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 . ' /> ';
  1717. if ( $valueLabel )
  1718. $out .= stripcslashes(trim($valueLabel));
  1719. else
  1720. $out .= stripcslashes(trim($value));
  1721. $out .= '</label>';
  1722. $out .= '</dd></dl>'."\n";
  1723. return $out;
  1724. }
  1725. function make_radio( $name, $sid, $data ) {
  1726. $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 = '';
  1727. $hide = $addfield = $out = '';
  1728. extract($data);
  1729. $options = $this->get_custom_field_template_data();
  1730. $title = $name;
  1731. $name = $this->sanitize_name( $name );
  1732. if ( isset($code) && is_numeric($code) ) :
  1733. eval(stripcslashes($options['php'][$code]));
  1734. if ( !empty($valueLabel) && is_array($valueLabel) ) $valueLabels = $valueLabel;
  1735. endif;
  1736. if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
  1737. if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
  1738. $selected = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
  1739. $ct_value = count($selected);
  1740. $selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : '';
  1741. } else {
  1742. $selected = stripslashes($default);
  1743. }
  1744. if ( empty($ct_value) ) :
  1745. $ct_value = !empty($startNum) ? $startNum-1 : 1;
  1746. endif;
  1747. if ( $hideKey == true ) $hide = ' class="hideKey"';
  1748. if ( !empty($class) ) $class = ' class="' . $class . '"';
  1749. if ( !empty($style) ) $style = ' style="' . $style . '"';
  1750. if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  1751. $title = stripcslashes($label);
  1752. $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);
  1753. $event_output = "";
  1754. foreach($event as $key => $val) :
  1755. if ( $val )
  1756. $event_output .= " " . $key . '="' . stripcslashes(trim($val)) . '"';
  1757. endforeach;
  1758. if ( $multipleButton == true && $ct_value == $cftnum ) :
  1759. $addfield .= '<div style="margin-top:-1em;">';
  1760. $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>';
  1761. $addfield .= '</div>';
  1762. endif;
  1763. $out .=
  1764. '<dl id="dl_' . $name . $sid . '_' . $cftnum . '" class="dl_radio">' .
  1765. '<dt><span' . $hide . '>' . $title . '</span>'.$addfield;
  1766. if( $clearButton == true ) {
  1767. $out .= '<div>';
  1768. $out .= '<a href="#clear" onclick="jQuery(this).parent().parent().parent().find(\'input\').attr(\'checked\', \'\'); return false;">' . __('Clear', 'custom-field-template') . '</a>';
  1769. $out .= '</div>';
  1770. }
  1771. $out .=
  1772. '</dt>' .
  1773. '<dd>';
  1774. if ( !empty($label) && empty($options['custom_field_template_replace_keys_by_labels']) )
  1775. $out .= '<p class="label">' . stripcslashes($label) . '</p>';
  1776. $i = 0;
  1777. $out .= trim($before).'<input name="' . $name . '[' . $sid . '][' . $cftnum . ']" value="" type="hidden" />';
  1778. if ( is_array($values) ) :
  1779. foreach( $values as $val ) {
  1780. $id = $name . '_' . $this->sanitize_name( $val ) . '_' . $sid . '_' . $cftnum;
  1781. $checked = ( stripcslashes(trim( $val )) == trim( $selected ) ) ? 'checked="checked"' : '';
  1782. $out .=
  1783. '<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 . ' /> ';
  1784. if ( isset($valueLabels[$i]) )
  1785. $out .= stripcslashes(trim($valueLabels[$i]));
  1786. else
  1787. $out .= stripcslashes(trim($val));
  1788. $out .= '</label><br />';
  1789. $i++;
  1790. }
  1791. endif;
  1792. $out .= trim($after).'</dd></dl>'."\n";
  1793. return $out;
  1794. }
  1795. function make_select( $name, $sid, $data ) {
  1796. $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 = '';
  1797. $hide = $addfield = $out = '';
  1798. extract($data);
  1799. $options = $this->get_custom_field_template_data();
  1800. $title = $name;
  1801. $name = $this->sanitize_name( $name );
  1802. if ( isset($code) && is_numeric($code) ) :
  1803. eval(stripcslashes($options['php'][$code]));
  1804. if ( !empty($valueLabel) && is_array($valueLabel) ) $valueLabels = $valueLabel;
  1805. endif;
  1806. if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
  1807. if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
  1808. $selected = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
  1809. $ct_value = count($selected);
  1810. $selected = isset($selected[ $cftnum ]) ? $selected[ $cftnum ] : '';
  1811. } else {
  1812. $selected = stripslashes($default);
  1813. }
  1814. if ( empty($ct_value) ) :
  1815. $ct_value = !empty($startNum) ? $startNum-1 : 1;
  1816. endif;
  1817. if ( $hideKey == true ) $hide = ' class="hideKey"';
  1818. if ( !empty($class) ) $class = ' class="' . $class . '"';
  1819. if ( !empty($style) ) $style = ' style="' . $style . '"';
  1820. if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  1821. $title = stripcslashes($label);
  1822. $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);
  1823. $event_output = "";
  1824. foreach($event as $key => $val) :
  1825. if ( $val )
  1826. $event_output .= " " . $key . '="' . stripcslashes(trim($val)) . '"';
  1827. endforeach;
  1828. if ( $multipleButton == true && $ct_value == $cftnum ) :
  1829. $addfield .= '<div style="margin-top:-1em;">';
  1830. $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>';
  1831. $addfield .= '</div>';
  1832. endif;
  1833. $out .=
  1834. '<dl id="dl_' . $name . $sid . '_' . $cftnum . '" class="dl_select">' .
  1835. '<dt><span' . $hide . '><label for="' . $name . $sid . '_' . $cftnum . '">' . $title . '</label></span>'.$addfield.'</dt>' .
  1836. '<dd>';
  1837. if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] )
  1838. $out .= '<p class="label">' . stripcslashes($label) . '</p>';
  1839. $out .= trim($before).'<select id="' . $name . $sid . '_' . $cftnum . '" name="' . $name . '[' . $sid . '][]"' . $class . $style . $event_output . '>';
  1840. if ( $selectLabel )
  1841. $out .= '<option value="">' . stripcslashes(trim($selectLabel)) . '</option>';
  1842. else
  1843. $out .= '<option value="">' . __('Select', 'custom-field-template') . '</option>';
  1844. $i = 0;
  1845. if ( is_array($values) ) :
  1846. foreach( $values as $val ) {
  1847. $checked = ( stripcslashes(trim( $val )) == trim( $selected ) ) ? 'selected="selected"' : '';
  1848. $out .= '<option value="' . esc_attr(stripcslashes(trim($val))) . '" ' . $checked . '>';
  1849. if ( isset($valueLabels[$i]) )
  1850. $out .= stripcslashes(trim($valueLabels[$i]));
  1851. else
  1852. $out .= stripcslashes(trim($val));
  1853. $out .= '</option>';
  1854. $i++;
  1855. }
  1856. endif;
  1857. $out .= '</select>'.trim($after).'</dd></dl>'."\n";
  1858. return $out;
  1859. }
  1860. function make_textarea( $name, $sid, $data ) {
  1861. $cftnum = $rows = $cols = $tinyMCE = $htmlEditor = $mediaButton = $default = $hideKey = $label = $code = $class = $style = $before = $after = $multipleButton = $mediaOffMedia = $mediaOffImage = $mediaOffVideo = $mediaOffAudio = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';
  1862. $hide = $addfield = $out = $media = $editorcontainer_class = '';
  1863. extract($data);
  1864. $options = $this->get_custom_field_template_data();
  1865. global $wp_version;
  1866. $title = $name;
  1867. $name = $this->sanitize_name( $name );
  1868. if ( is_numeric($code) ) :
  1869. eval(stripcslashes($options['php'][$code]));
  1870. endif;
  1871. if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
  1872. if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
  1873. $value = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
  1874. if ( !empty($value) && is_array($value) ) {
  1875. $ct_value = count($value);
  1876. $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
  1877. }
  1878. } else {
  1879. $value = stripslashes($default);
  1880. }
  1881. if ( empty($ct_value) ) :
  1882. $ct_value = !empty($startNum) ? $startNum-1 : 1;
  1883. endif;
  1884. $rand = rand();
  1885. if( $tinyMCE == true ) {
  1886. $out = '<script type="text/javascript">' . "\n" .
  1887. '// <![CDATA[' . "\n" .
  1888. 'jQuery(document).ready(function() {if ( typeof tinyMCE != "undefined" ) {' . "\n";
  1889. if ( substr($wp_version, 0, 3) < '3.3' ) :
  1890. $load_tinyMCE = 'tinyMCE.execCommand("mceAddControl", false, "'. sha1($name . $rand) . '");';
  1891. $editorcontainer_class = ' class="editorcontainer"';
  1892. else :
  1893. $load_tinyMCE = 'var ed = new tinyMCE.Editor("'. sha1($name . $rand) . '", tinyMCEPreInit.mceInit["content"]); ed.render();';
  1894. $editorcontainer_class = ' class="wp-editor-container"';
  1895. endif;
  1896. if ( !empty($options['custom_field_template_use_wpautop']) ) :
  1897. $out .= 'document.getElementById("'. sha1($name . $rand) . '").value = document.getElementById("'. sha1($name . $rand) . '").value; '.$load_tinyMCE.' tinyMCEID.push("'. sha1($name . $rand) . '");' . "\n";
  1898. else:
  1899. $out .= 'document.getElementById("'. sha1($name . $rand) . '").value = switchEditors.wpautop(document.getElementById("'. sha1($name . $rand) . '").value); '.$load_tinyMCE.' tinyMCEID.push("'. sha1($name . $rand) . '");' . "\n";
  1900. endif;
  1901. $out .= '}});' . "\n";
  1902. $out .= '// ]]>' . "\n" . '</script>';
  1903. }
  1904. if ( substr($wp_version, 0, 3) >= '2.5' ) {
  1905. if ( !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') && !strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) {
  1906. if ( $mediaButton == true ) :
  1907. $media_upload_iframe_src = "media-upload.php";
  1908. if ( substr($wp_version, 0, 3) < '3.3' ) :
  1909. if ( !$mediaOffImage ) :
  1910. $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src?type=image");
  1911. $image_title = __('Add an Image');
  1912. $media .= "<a href=\"{$image_upload_iframe_src}&TB_iframe=true\" id=\"add_image{$rand}\" title='$image_title' onclick=\"focusTextArea('".sha1($name.$rand)."'); 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> ";
  1913. endif;
  1914. if ( !$mediaOffVideo ) :
  1915. $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src?type=video");
  1916. $video_title = __('Add Video');
  1917. $media .= "<a href=\"{$video_upload_iframe_src}&amp;TB_iframe=true\" id=\"add_video{$rand}\" title='$video_title' onclick=\"focusTextArea('".sha1($name.$rand)."'); 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> ";
  1918. endif;
  1919. if ( !$mediaOffAudio ) :
  1920. $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src?type=audio");
  1921. $audio_title = __('Add Audio');
  1922. $media .= "<a href=\"{$audio_upload_iframe_src}&amp;TB_iframe=true\" id=\"add_audio{$rand}\" title='$audio_title' onclick=\"focusTextArea('".sha1($name.$rand)."'); 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> ";
  1923. endif;
  1924. if ( !$mediaOffMedia ) :
  1925. $media_title = __('Add Media');
  1926. $media .= "<a href=\"{$media_upload_iframe_src}?TB_iframe=true\" id=\"add_media{$rand}\" title='$media_title' onclick=\"focusTextArea('".sha1($name.$rand)."'); 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>";
  1927. endif;
  1928. else :
  1929. $media_title = __('Add Media');
  1930. $media .= "<a href=\"{$media_upload_iframe_src}?TB_iframe=true\" id=\"add_media{$rand}\" title='$media_title' onclick=\"focusTextArea('".sha1($name.$rand)."'); 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>";
  1931. endif;
  1932. endif;
  1933. $switch = '<div>';
  1934. if( $tinyMCE == true && user_can_richedit() ) {
  1935. $switch .= '<a href="#toggle" onclick="switchMode(jQuery(this).parent().parent().parent().find(\'textarea\').attr(\'id\')); return false;">' . __('Toggle', 'custom-field-template') . '</a>';
  1936. }
  1937. $switch .= '</div>';
  1938. }
  1939. }
  1940. if ( $hideKey == true ) $hide = ' class="hideKey"';
  1941. $content_class = ' class="';
  1942. if ( $htmlEditor == true || $tinyMCE == true ) :
  1943. if ( substr($wp_version, 0, 3) < '3.3' ) :
  1944. $content_class .= 'content';
  1945. else :
  1946. $content_class .= 'wp-editor-area';
  1947. endif;
  1948. endif;
  1949. if ( !empty($class) ) $content_class .= ' ' . $class;
  1950. $content_class .= '"';
  1951. if ( !empty($style) ) $style = ' style="' . $style . '"';
  1952. if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  1953. $title = stripcslashes($label);
  1954. $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);
  1955. $event_output = "";
  1956. foreach($event as $key => $val) :
  1957. if ( $val )
  1958. $event_output .= " " . $key . '="' . stripcslashes(trim($val)) . '"';
  1959. endforeach;
  1960. if ( $multipleButton == true && $ct_value == $cftnum ) :
  1961. $addfield .= '<div style="margin-top:-1em;">';
  1962. if ( !empty($htmlEditor) ) :
  1963. if ( substr($wp_version, 0, 3) < '3.3' ) :
  1964. $load_htmlEditor1 = 'jQuery(\'#qt_\'+original_id+\'_qtags\').remove();';
  1965. $load_htmlEditor2 = 'qt_set(original_id);qt_set(new_id);';
  1966. if( $tinyMCE == true ) : $load_htmlEditor2 .= ' jQuery(\'#qt_\'+original_id+\'_qtags\').hide(); jQuery(\'#qt_\'+new_id+\'_qtags\').hide();'; endif;
  1967. else :
  1968. $load_htmlEditor1 = 'jQuery(\'#qt_\'+original_id+\'_toolbar\').remove();';
  1969. $load_htmlEditor2 = 'new QTags(new_id);QTags._buttonsInit();';
  1970. if( $tinyMCE == true ) : $load_htmlEditor2 .= ' jQuery(\'#qt_\'+new_id+\'_toolbar\').hide();'; endif;
  1971. endif;
  1972. endif;
  1973. if ( !empty($tinyMCE) ) :
  1974. if ( substr($wp_version, 0, 3) < '3.3' ) :
  1975. $load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, original_id);tinyMCE.execCommand(' . "'mceAddControl'" . ',false, new_id);';
  1976. else :
  1977. $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();';
  1978. endif;
  1979. $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'" . ',false,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>';
  1980. else :
  1981. $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>';
  1982. endif;
  1983. $addfield .= '</div>';
  1984. endif;
  1985. $out .=
  1986. '<dl id="dl_' . $name . $sid . '_' . $cftnum . '" class="dl_textarea">' .
  1987. '<dt><span' . $hide . '><label for="' . $name . $sid . '_' . $cftnum . '">' . $title . '</label></span><br />' . $addfield . $media . $switch . '</dt>' .
  1988. '<dd>';
  1989. if ( !empty($label) && empty($options['custom_field_template_replace_keys_by_labels']) )
  1990. $out .= '<p class="label">' . stripcslashes($label) . '</p>';
  1991. $out .= trim($before);
  1992. if ( ($htmlEditor == true || $tinyMCE == true) && substr($wp_version, 0, 3) < '3.3' ) $out .= '<div class="quicktags">';
  1993. if ( $htmlEditor == true ) :
  1994. if ( substr($wp_version, 0, 3) < '3.3' ) :
  1995. if( $tinyMCE == true ) $quicktags_hide = ' jQuery(\'#qt_' . sha1($name . $rand) . '_qtags\').hide();';
  1996. $out .= '<script type="text/javascript">' . "\n" . '// <![CDATA[' . '
  1997. jQuery(document).ready(function() { qt_' . sha1($name . $rand) . ' = new QTags(\'qt_' . sha1($name . $rand) . '\', \'' . sha1($name . $rand) . '\', \'editorcontainer_' . sha1($name . $rand) . '\', \'more\'); ' . $quicktags_hide . ' });' . "\n" . '// ]]>' . "\n" . '</script>';
  1998. $editorcontainer_class = ' class="editorcontainer"';
  1999. else :
  2000. if( $tinyMCE == true ) $quicktags_hide = ' jQuery(\'#qt_' . sha1($name . $rand) . '_toolbar\').hide();';
  2001. $out .= '<script type="text/javascript">' . "\n" . '// <![CDATA[' . '
  2002. jQuery(document).ready(function() { new QTags(\'' . sha1($name . $rand) . '\'); QTags._buttonsInit(); ' . $quicktags_hide . ' }); ' . "\n";
  2003. $out .= '// ]]>' . "\n" . '</script>';
  2004. $editorcontainer_class = ' class="wp-editor-container"';
  2005. endif;
  2006. endif;
  2007. $out .= '<div' . $editorcontainer_class . ' id="editorcontainer_' . sha1($name . $rand) . '"><textarea id="' . sha1($name . $rand) . '" name="' . $name . '[' . $sid . '][]" rows="' .$rows. '" cols="' . $cols . '"' . $content_class . $style . $event_output . '>' . esc_attr(trim($value)) . '</textarea><input type="hidden" name="'.$name.'_rand['.$sid.']" value="'.$rand.'" /></div>';
  2008. if ( ($htmlEditor == true || $tinyMCE == true) && substr($wp_version, 0, 3) < '3.3' ) $out .= '</div>';
  2009. $out .= trim($after).'</dd></dl>'."\n";
  2010. return $out;
  2011. }
  2012. function make_file( $name, $sid, $data ) {
  2013. $cftnum = $size = $hideKey = $label = $class = $style = $before = $after = $multipleButton = $relation = $mediaLibrary = $mediaPicker = '';
  2014. $hide = $addfield = $out = $picker = '';
  2015. extract($data);
  2016. $options = $this->get_custom_field_template_data();
  2017. $title = $name;
  2018. $name = $this->sanitize_name( $name );
  2019. if ( !isset($_REQUEST['default']) || (isset($_REQUEST['default']) && $_REQUEST['default'] != true) ) $_REQUEST['default'] = false;
  2020. if( isset( $_REQUEST[ 'post' ] ) && $_REQUEST[ 'post' ] > 0 && $_REQUEST['default'] != true ) {
  2021. $value = $this->get_post_meta( $_REQUEST[ 'post' ], $title );
  2022. $ct_value = count($value);
  2023. $value = isset($value[ $cftnum ]) ? $value[ $cftnum ] : '';
  2024. }
  2025. if ( empty($ct_value) ) :
  2026. $ct_value = !empty($startNum) ? $startNum-1 : 1;
  2027. endif;
  2028. if ( $hideKey == true ) $hide = ' class="hideKey"';
  2029. if ( !empty($class) ) $class = ' class="' . $class . '"';
  2030. if ( !empty($style) ) $style = ' style="' . $style . '"';
  2031. if ( !empty($label) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  2032. $title = stripcslashes($label);
  2033. if ( $multipleButton == true && $ct_value == $cftnum ) :
  2034. $addfield .= '<div style="margin-top:-1em;">';
  2035. $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>';
  2036. $addfield .= '</div>';
  2037. endif;
  2038. if ( $relation == true ) $tab = 'gallery';
  2039. else $tab = 'library';
  2040. $media_upload_iframe_src = "media-upload.php";
  2041. $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src?type=image&tab=library");
  2042. if ( $mediaPicker == true ) :
  2043. $picker = __(' OR ', 'custom-field-template');
  2044. $picker .= '<a href="'.$image_upload_iframe_src.'&post_id='.$_REQUEST[ 'post' ].'&TB_iframe=1&tab='.$tab.'" class="thickbox" onclick="jQuery('."'#cft_current_template'".').val(jQuery(this).parent().parent().parent().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>';
  2045. endif;
  2046. $out .=
  2047. '<dl id="dl_' . $name . $sid . '_' . $cftnum . '" class="dl_file">' .
  2048. '<dt><span' . $hide . '><label for="' . $name . $sid . '_' . $cftnum . '">' . $title . '</label></span>'.$addfield.'</dt>' .
  2049. '<dd>';
  2050. if ( !empty($label) && !$options['custom_field_template_replace_keys_by_labels'] )
  2051. $out .= '<p class="label">' . stripcslashes($label) . '</p>';
  2052. $out .= trim($before).'<input id="' . $name . $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;
  2053. if ( isset($value) && ( $value = intval($value) ) && $thumb_url = wp_get_attachment_image_src( $value, 'thumbnail', true ) ) :
  2054. $thumb_url = $thumb_url[0];
  2055. $post = get_post($value);
  2056. $filename = basename($post->guid);
  2057. $title = esc_attr(trim($post->post_title));
  2058. if ( !empty($mediaLibrary) ) :
  2059. $title = '<a href="'.$image_upload_iframe_src.'&post_id='.$_REQUEST[ 'post' ].'&TB_iframe=1&tab='.$tab.'" class="thickbox">'.$title.'</a>';
  2060. endif;
  2061. $out .= '<p><label for="'.$name . $sid . '_' . $cftnum . '_delete"><input type="checkbox" name="'.$name . '_delete[' . $sid . '][' . $cftnum . ']" id="'.$name . $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>';
  2062. $out .= '<input type="hidden" id="' . $name . $sid . '_' . $cftnum . '_hide" name="'.$name . '[' . $sid . '][' . $cftnum . ']" value="' . $value . '" />';
  2063. else :
  2064. $out .= '<input type="hidden" id="' . $name . $sid . '_' . $cftnum . '_hide" name="'.$name . '[' . $sid . '][' . $cftnum . ']" value="" />';
  2065. endif;
  2066. $out .= '</dd></dl>'."\n";
  2067. return $out;
  2068. }
  2069. function load_custom_field( $id = 0 ) {
  2070. global $current_user, $post, $wp_version;
  2071. $level = $current_user->user_level;
  2072. $options = $this->get_custom_field_template_data();
  2073. if ( isset($_REQUEST['post']) ) $post = get_post($_REQUEST['post']);
  2074. if ( !empty($options['custom_fields'][$id]['disable']) )
  2075. return;
  2076. $fields = $this->get_custom_fields( $id );
  2077. if ( $fields == null )
  2078. return;
  2079. if ( (isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == 'page') || $post->post_type=='page' ) :
  2080. $post->page_template = get_post_meta( $post->ID, '_wp_page_template', true );
  2081. if ( !$post->page_template ) $post->page_template = 'default';
  2082. endif;
  2083. if ( !empty($options['custom_fields'][$id]['post_type']) ) :
  2084. if ( substr($wp_version, 0, 3) < '3.0' ) :
  2085. 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')) ) :
  2086. return;
  2087. endif;
  2088. 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')) ) :
  2089. return;
  2090. endif;
  2091. else :
  2092. if ( $_REQUEST['post_type']!=$options['custom_fields'][$id]['post_type'] && $post->post_type!=$options['custom_fields'][$id]['post_type'] ) :
  2093. return;
  2094. endif;
  2095. endif;
  2096. endif;
  2097. if ( !empty($options['custom_fields'][$id]['custom_post_type']) ) :
  2098. $custom_post_type = explode(',', $options['custom_fields'][$id]['custom_post_type']);
  2099. $custom_post_type = array_filter( $custom_post_type );
  2100. $custom_post_type = array_unique(array_filter(array_map('trim', $custom_post_type)));
  2101. if ( !in_array($post->post_type, $custom_post_type) )
  2102. return;
  2103. endif;
  2104. if ( substr($wp_version, 0, 3) < '3.0' ) :
  2105. 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']) ) :
  2106. return;
  2107. endif;
  2108. 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']) ) :
  2109. return;
  2110. endif;
  2111. else :
  2112. if ( !empty($options['custom_fields'][$id]['category']) && ($_REQUEST['post_type']=='page' || $post->post_type=='page') && empty($options['custom_fields'][$id]['template_files']) ) :
  2113. return;
  2114. endif;
  2115. if ( !empty($options['custom_fields'][$id]['template_files']) && ($_REQUEST['post_type']!='page' && $post->post_type!='page') && empty($options['custom_fields'][$id]['category']) ) :
  2116. return;
  2117. endif;
  2118. endif;
  2119. if ( (!isset($_REQUEST['post']) || $_REQUEST['post']<0) && !empty($options['custom_fields'][$id]['category']) && $_REQUEST['cft_mode'] != 'ajaxload' )
  2120. return;
  2121. if ( isset($_REQUEST['post']) && !empty($options['custom_fields'][$id]['category']) && !isset($options['posts'][$_REQUEST['post']]) && $options['posts'][$_REQUEST['post']] !== $id && $_REQUEST['cft_mode'] != 'ajaxload' )
  2122. return;
  2123. if ( !isset($_REQUEST['id']) && !empty($options['custom_fields'][$id]['category']) && $_REQUEST['cft_mode'] == 'ajaxload' ) :
  2124. $category = explode(',', $options['custom_fields'][$id]['category']);
  2125. $category = array_filter( $category );
  2126. $category = array_unique(array_filter(array_map('trim', $category)));
  2127. if ( !empty($_REQUEST['tax_input']) && is_array($_REQUEST['tax_input']) ) :
  2128. foreach($_REQUEST['tax_input'] as $key => $val) :
  2129. foreach($val as $key2 => $val2 ) :
  2130. if ( in_array($val2, $category) ) : $notreturn = 1; break; endif;;
  2131. endforeach;
  2132. endforeach;
  2133. else :
  2134. if ( !empty($_REQUEST['post_category']) && is_array($_REQUEST['post_category']) ) :
  2135. foreach($_REQUEST['post_category'] as $val) :
  2136. if ( in_array($val, $category) ) : $notreturn = 1; break; endif;;
  2137. endforeach;
  2138. endif;
  2139. endif;
  2140. if ( empty($notreturn) ) return;
  2141. endif;
  2142. if ( !empty($options['custom_fields'][$id]['post']) ) :
  2143. $post_ids = explode(',', $options['custom_fields'][$id]['post']);
  2144. $post_ids = array_filter( $post_ids );
  2145. $post_ids = array_unique(array_filter(array_map('trim', $post_ids)));
  2146. if ( !in_array($_REQUEST['post'], $post_ids) )
  2147. return;
  2148. endif;
  2149. if ( !empty($options['custom_fields'][$id]['template_files']) && (isset($post->page_template) || (isset($_REQUEST['page_template']) && $_REQUEST['page_template'])) ) :
  2150. $template_files = explode(',', $options['custom_fields'][$id]['template_files']);
  2151. $template_files = array_filter( $template_files );
  2152. $template_files = array_unique(array_filter(array_map('trim', $template_files)));
  2153. if ( isset($_REQUEST['page_template']) ) :
  2154. if ( !in_array($_REQUEST['page_template'], $template_files) ) :
  2155. return;
  2156. endif;
  2157. else :
  2158. if ( !in_array($post->page_template, $template_files) ) :
  2159. return;
  2160. endif;
  2161. endif;
  2162. endif;
  2163. if ( substr($wp_version, 0, 3) >= '3.3' && !post_type_supports($post->post_type, 'editor') && $post->post_type!='post' && $post->post_type!='page' ) :
  2164. wp_editor('', 'content', array('dfw' => true, 'tabindex' => 1) );
  2165. $out = '<style type="text/css">#wp-content-wrap { display:none; }</style>';
  2166. else :
  2167. $out = '';
  2168. endif;
  2169. if ( !empty($options['custom_fields'][$id]['instruction']) ) :
  2170. $instruction = $this->EvalBuffer(stripcslashes($options['custom_fields'][$id]['instruction']));
  2171. $out .= '<div id="cft_instruction'.$id.'" class="cft_instruction">' . $instruction . '</div>';
  2172. endif;
  2173. $out .= '<div id="cft_'.$id.'">';
  2174. $out .= '<div>';
  2175. $out .= '<input type="hidden" name="custom-field-template-id[]" id="custom-field-template-id" value="' . $id . '" />';
  2176. foreach( $fields as $field_key => $field_val ) :
  2177. foreach( $field_val as $title => $data ) {
  2178. $class = $style = $addfield = '';
  2179. if ( isset($data['parentSN']) && is_numeric($data['parentSN']) ) $parentSN = $data['parentSN'];
  2180. else $parentSN = $field_key;
  2181. if ( isset($data['level']) && is_numeric($data['level']) ) :
  2182. if ( $data['level'] > $level ) continue;
  2183. endif;
  2184. if( $data['type'] == 'break' ) {
  2185. if ( !empty($data['class']) ) $class = ' class="' . $data['class'] . '"';
  2186. if ( !empty($data['style']) ) $style = ' style="' . $data['style'] . '"';
  2187. $out .= '</div><div' . $class . $style . '>';
  2188. }
  2189. else if( $data['type'] == 'fieldset_open' ) {
  2190. if ( !empty($data['class']) ) $class = ' class="' . $data['class'] . '"';
  2191. if ( !empty($data['style']) ) $style = ' style="' . $data['style'] . '"';
  2192. $out .= '<fieldset' . $class . $style . '>'."\n";
  2193. $out .= '<input type="hidden" name="' . $this->sanitize_name( $title ) . '[]" value="1" />'."\n";
  2194. if ( isset($data['multipleButton']) && $data['multipleButton'] == true ) :
  2195. $addfield .= ' <span>';
  2196. if ( isset($_REQUEST['post']) ) $addbutton = $this->get_post_meta( $_REQUEST['post'], $title, true )-1;
  2197. if ( !isset($addbutton) || $addbutton<=0 ) $addbutton = 0;
  2198. if ( $data['cftnum']/2 == $addbutton ) :
  2199. if ( substr($wp_version, 0, 3) < '3.3' ) :
  2200. $load_htmlEditor1 = 'if ( jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_qtags\').html() ) {jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_qtags\').remove();';
  2201. $load_htmlEditor2 = 'qt_set(textarea_html_ids[i]);';
  2202. $load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, textarea_tmce_ids[i]); switchMode(textarea_tmce_ids[i]); switchMode(textarea_tmce_ids[i]);';
  2203. else :
  2204. $load_htmlEditor1 = 'if ( jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_toolbar\').html() ) {jQuery(\'#qt_\'+jQuery(this).attr('."'id'".')+\'_toolbar\').remove();';
  2205. $load_htmlEditor2 = 'new QTags(textarea_html_ids[i]);QTags._buttonsInit();';
  2206. $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]);';
  2207. endif;
  2208. $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>';
  2209. $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.'if ( jQuery(\'#'.$this->sanitize_name( $title ).'_count\').val() == 0 ) html_start++;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.execCommand(' . "'mceRemoveControl'" . ',false,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]+)$/)) {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 ) {matchval2 = RegExp.$1;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>';
  2210. else :
  2211. $addfield .= ' <a href="#clear" onclick="jQuery(this).parent().parent().parent().remove();return false;">' . __('Delete', 'custom-field-template') . '</a>';
  2212. endif;
  2213. $addfield .= '</span>';
  2214. endif;
  2215. if ( isset($data['legend']) || isset($addfield) ) :
  2216. if ( !isset($data['legend']) ) $data['legend'] = '';
  2217. if ( !isset($addfield) ) $addfield = '';
  2218. $out .= '<legend>' . stripcslashes(trim($data['legend'])) . $addfield . '</legend>';
  2219. endif;
  2220. }
  2221. else if( $data['type'] == 'fieldset_close' ) {
  2222. $out .= '</fieldset>';
  2223. }
  2224. else if( $data['type'] == 'textfield' || $data['type'] == 'text' ) {
  2225. $out .= $this->make_textfield( $title, $parentSN, $data );
  2226. }
  2227. else if( $data['type'] == 'checkbox' ) {
  2228. $out .= $this->make_checkbox( $title, $parentSN, $data );
  2229. }
  2230. else if( $data['type'] == 'radio' ) {
  2231. $data['values'] = explode( '#', $data['value'] );
  2232. if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] );
  2233. $out .= $this->make_radio( $title, $parentSN, $data );
  2234. }
  2235. else if( $data['type'] == 'select' ) {
  2236. $data['values'] = explode( '#', $data['value'] );
  2237. if ( isset($data['valueLabel']) ) $data['valueLabels'] = explode( '#', $data['valueLabel'] );
  2238. $out .= $this->make_select( $title, $parentSN, $data );
  2239. }
  2240. else if( $data['type'] == 'textarea' ) {
  2241. $out .= $this->make_textarea( $title, $parentSN, $data );
  2242. }
  2243. else if( $data['type'] == 'file' ) {
  2244. $out .= $this->make_file( $title, $parentSN, $data );
  2245. }
  2246. }
  2247. endforeach;
  2248. $out .= '<script type="text/javascript">' . "\n" .
  2249. '// <![CDATA[' . "\n";
  2250. $out .= ' jQuery(document).ready(function() {' . "\n" .
  2251. ' jQuery("#custom_field_template_select").val("' . $id . '");' . "\n" .
  2252. ' });' . "\n";
  2253. $out .= '// ]]>' . "\n" .
  2254. '</script>';
  2255. $out .= '</div>';
  2256. $out .= '</div>';
  2257. return array($out, $id);
  2258. }
  2259. function insert_custom_field($post, $args) {
  2260. global $wp_version, $post, $wpdb;
  2261. $options = $this->get_custom_field_template_data();
  2262. $out = '';
  2263. if( $options == null)
  2264. return;
  2265. if ( !$options['css'] ) {
  2266. $this->install_custom_field_template_css();
  2267. $options = $this->get_custom_field_template_data();
  2268. }
  2269. if ( substr($wp_version, 0, 3) < '2.5' ) {
  2270. $out .= '
  2271. <div class="dbx-b-ox-wrapper">
  2272. <fieldset id="seodiv" class="dbx-box">
  2273. <div class="dbx-h-andle-wrapper">
  2274. <h3 class="dbx-handle">' . __('Custom Field Template', 'custom-field-template') . '</h3>
  2275. </div>
  2276. <div class="dbx-c-ontent-wrapper">
  2277. <div class="dbx-content">';
  2278. }
  2279. if ( isset($args['args']) ) :
  2280. $init_id = $args['args'];
  2281. $suffix = $args['args'];
  2282. $suffix2 = '_'.$args['args'];
  2283. $suffix3 = $args['args'];
  2284. else :
  2285. if ( isset($_REQUEST['post']) ) $request_post = $_REQUEST['post'];
  2286. else $request_post = '';
  2287. if( isset($options['posts'][$request_post]) && count($options['custom_fields'])>$options['posts'][$request_post] ) :
  2288. $init_id = $options['posts'][$request_post];
  2289. else :
  2290. $filtered_cfts = $this->custom_field_template_filter();
  2291. if ( count($filtered_cfts)>0 ) :
  2292. $init_id = $filtered_cfts[0]['id'];
  2293. else :
  2294. $init_id = 0;
  2295. endif;
  2296. endif;
  2297. $suffix = '';
  2298. $suffix2 = '';
  2299. $suffix3 = '\'+jQuery(\'#custom-field-template-id\').val()+\'';
  2300. endif;
  2301. $out .= '<script type="text/javascript">' . "\n" .
  2302. '// <![CDATA[' . "\n";
  2303. $out .= 'jQuery(document).ready(function() {' . "\n";
  2304. $fields = $this->get_custom_fields( $init_id );
  2305. if ( user_can_richedit() ) :
  2306. if ( is_array($fields) ) :
  2307. foreach( $fields as $field_key => $field_val ) :
  2308. foreach( $field_val as $title => $data ) :
  2309. if( $data[ 'type' ] == 'textarea' && !empty($data['tinyMCE']) ) :
  2310. if ( substr($wp_version, 0, 3) >= '2.7' ) :
  2311. /*$out .= ' if ( getUserSetting( "editor" ) == "html" ) {
  2312. jQuery("#edButtonPreview").trigger("click"); }' . "\n";*/
  2313. else :
  2314. $out .= ' if(wpTinyMCEConfig) if(wpTinyMCEConfig.defaultEditor == "html") { jQuery("#edButtonPreview").trigger("click"); }' . "\n";
  2315. endif;
  2316. break;
  2317. endif;
  2318. endforeach;
  2319. endforeach;
  2320. endif;
  2321. endif;
  2322. if ( empty($options['custom_field_template_deploy_box']) && !empty($options['custom_fields']) ) :
  2323. if ( substr($wp_version, 0, 3) < '3.0' ) $taxonomy = 'categories';
  2324. else $taxonomy = 'category';
  2325. foreach ( $options['custom_fields'] as $key => $val ) :
  2326. if ( !empty($val['category']) ) :
  2327. $val['category'] = preg_replace('/\s/', '', $val['category']);
  2328. $categories = explode(',', $val['category']);
  2329. $categories = array_filter($categories);
  2330. array_walk( $categories, create_function('&$v', '$v = trim($v);') );
  2331. $query = $wpdb->prepare("SELECT * FROM `".$wpdb->prefix."term_taxonomy` WHERE term_id IN (".$val['category'].")");
  2332. $result = $wpdb->get_results($query, ARRAY_A);
  2333. $category_taxonomy = array();
  2334. if ( !empty($result) && is_array($result) ) :
  2335. for($i=0;$i<count($result);$i++) :
  2336. $category_taxonomy[$result[$i]['term_id']] = $result[$i]['taxonomy'];
  2337. endfor;
  2338. endif;
  2339. foreach($categories as $cat_id) :
  2340. if ( is_numeric($cat_id) ) :
  2341. if ( $taxonomy == 'category' ) $taxonomy = $category_taxonomy[$cat_id];
  2342. $out .= 'jQuery(\'#in-'.$category_taxonomy[$cat_id].'-' . $cat_id . '\').click(function(){if(jQuery(\'#in-'.$category_taxonomy[$cat_id].'-' . $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);';
  2343. if ( !empty($options['custom_field_template_use_autosave']) ) :
  2344. $out .= ' var fields = jQuery(\'#cft'.$suffix.' :input\').fieldSerialize();';
  2345. $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) {';
  2346. if ( !empty($options['custom_field_template_replace_the_title']) ) :
  2347. $out .= 'jQuery(\'#cftdiv'.$suffix.' h3 span\').text(\'' . $options['custom_fields'][$key]['title'] . '\');';
  2348. endif;
  2349. $out .= 'jQuery(\'#cft\').html(html);}});}});';
  2350. else :
  2351. $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) {';
  2352. if ( !empty($options['custom_field_template_replace_the_title']) ) :
  2353. $out .= 'jQuery(\'#cftdiv'.$suffix.' h3 span\').text(\'' . $options['custom_fields'][$key]['title'] . '\');';
  2354. endif;
  2355. $out .= 'jQuery(\'#cft\').html(html);}});';
  2356. endif;
  2357. $out .= ' });';
  2358. $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);}}); });';
  2359. if ( !empty($options['custom_field_template_replace_the_title']) ) :
  2360. $out .= 'jQuery(\'#cftdiv'.$suffix.' h3 span\').text(\'' . __('Custom Field Template', 'custom-field-template') . '\');';
  2361. endif;
  2362. $out .= '}});' . "\n";
  2363. endif;
  2364. endforeach;
  2365. endif;
  2366. endforeach;
  2367. endif;
  2368. if ( empty($options['custom_field_template_deploy_box']) && 0 != count( get_page_templates() ) ):
  2369. if ( empty($_REQUEST['post_type']) ) $_REQUEST['post_type'] = 'post';
  2370. $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='.$_REQUEST['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='.$_REQUEST['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);';
  2371. if ( !empty($options['custom_field_template_replace_the_title']) ) :
  2372. $out .= 'if(html) { jQuery(\'#cftdiv'.$suffix.' h3 span\').text(jQuery(\'#custom_field_template_select :selected\').text());}';
  2373. endif;
  2374. $out .= '}});});';
  2375. $out .= '});' . "\n";
  2376. endif;
  2377. $out .= ' jQuery(\'#cftloading_img'.$suffix.'\').ajaxStart(function() { jQuery(this).show();});';
  2378. $out .= ' jQuery(\'#cftloading_img'.$suffix.'\').ajaxStop(function() { jQuery(this).hide();});';
  2379. $out .= '});' . "\n";
  2380. $out .= 'var tinyMCEID = new Array();' . "\n" .
  2381. '// ]]>' . "\n" .
  2382. '</script>';
  2383. list($body, $init_id) = $this->load_custom_field($init_id);
  2384. if ( empty($options['custom_field_template_deploy_box']) ) :
  2385. $out .= '<div id="cft_selectbox">';
  2386. $out .= $this->custom_field_template_selectbox();
  2387. $out .= '</div>';
  2388. else :
  2389. $out .= '<div>&nbsp;</div>';
  2390. endif;
  2391. $out .= '<div id="cft'.$suffix.'" class="cft">';
  2392. $out .= $body;
  2393. $out .= '</div>';
  2394. if ( substr($wp_version, 0, 3) < '3.3' ) :
  2395. $top_margin = 30;
  2396. else :
  2397. $top_margin = 0;
  2398. endif;
  2399. $out .= '<div style="position:absolute; top:'.$top_margin.'px; right:5px;">';
  2400. $out .= '<img class="waiting" style="display:none; vertical-align:middle;" src="images/loading.gif" alt="" id="cftloading_img'.$suffix.'" /> ';
  2401. if ( !empty($options['custom_field_template_use_disable_button']) ) :
  2402. $out .= '<input type="hidden" id="disable_value" value="0" />';
  2403. $out .= '<input type="button" value="' . __('Disable', 'custom-field-template') . '" onclick="';
  2404. $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);}';
  2405. $out .= '" class="button" style="vertical-align:middle;" />';
  2406. endif;
  2407. if ( empty($options['custom_field_template_disable_initialize_button']) ) :
  2408. $out .= '<input type="button" value="' . __('Initialize', 'custom-field-template') . '" onclick="';
  2409. $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) {';
  2410. $out .= 'jQuery(\'#cft'.$suffix2.'\').html(html);}});}';
  2411. $out .= '" class="button" style="vertical-align:middle;" />';
  2412. endif;
  2413. if ( empty($options['custom_field_template_disable_save_button']) ) :
  2414. $out .= '<input type="button" id="cft_save_button'.$suffix.'" value="' . __('Save', 'custom-field-template') . '" onclick="';
  2415. if ( !empty($options['custom_field_template_use_validation']) ) :
  2416. $out .= 'if(!jQuery(\'#post\').valid()) return false;';
  2417. endif;
  2418. $out .= 'tinyMCE.triggerSave(); var fields = jQuery(\'#cft'.$suffix2.' :input\').fieldSerialize();';
  2419. $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().remove();});}});';
  2420. $out .= '" class="button" style="vertical-align:middle;" />';
  2421. endif;
  2422. $out .= '</div>';
  2423. if ( substr($wp_version, 0, 3) < '2.5' ) {
  2424. $out .= '</div></fieldset></div>';
  2425. } else {
  2426. if ( $body && !empty($options['custom_field_template_replace_the_title']) && empty($options['custom_field_template_deploy_box']) ) :
  2427. $out .= '<script type="text/javascript">' . "\n" . '// <![CDATA[' . "\n";
  2428. $out .= 'jQuery(document).ready(function() {jQuery(\'#cftdiv h3 span\').text(\'' . $options['custom_fields'][$init_id]['title'] . '\');});' . "\n";
  2429. $out .= '// ]]>' . "\n" . '</script>';
  2430. endif;
  2431. }
  2432. echo $out;
  2433. }
  2434. function custom_field_template_filter(){
  2435. global $post, $wp_version;
  2436. $options = $this->get_custom_field_template_data();
  2437. $filtered_cfts = array();
  2438. $post_id = isset($_REQUEST['post']) ? $_REQUEST['post'] : '';
  2439. if ( empty($post) ) $post = get_post($post_id);
  2440. $categories = get_the_category($post_id);
  2441. $cats = array();
  2442. if ( is_array($categories) ) foreach($categories as $category) $cats[] = $category->cat_ID;
  2443. if ( !empty($_REQUEST['tax_input']) && is_array($_REQUEST['tax_input']) ) :
  2444. foreach($_REQUEST['tax_input'] as $key => $val) :
  2445. $cats = array_merge($cats, $val);
  2446. endforeach;
  2447. elseif ( !empty($_REQUEST['post_category']) ) :
  2448. $cats = array_merge($cats, $_REQUEST['post_category']);
  2449. endif;
  2450. for ( $i=0; $i < count($options['custom_fields']); $i++ ) :
  2451. unset($cat_ids, $template_files, $post_ids);
  2452. if ( !empty($options['custom_fields'][$i]['post_type']) ) :
  2453. if ( substr($wp_version, 0, 3) < '3.0' ) :
  2454. 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')) ) :
  2455. continue;
  2456. endif;
  2457. 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')) ) :
  2458. continue;
  2459. endif;
  2460. else :
  2461. if ( $post->post_type!=$options['custom_fields'][$i]['post_type'] ) :
  2462. continue;
  2463. endif;
  2464. endif;
  2465. endif;
  2466. if ( !empty($options['custom_fields'][$i]['custom_post_type']) ) :
  2467. $custom_post_type = explode(',', $options['custom_fields'][$i]['custom_post_type']);
  2468. $custom_post_type = array_filter( $custom_post_type );
  2469. $custom_post_type = array_unique(array_filter(array_map('trim', $custom_post_type)));
  2470. if ( !in_array($post->post_type, $custom_post_type) )
  2471. continue;
  2472. endif;
  2473. $cat_ids = explode(',', $options['custom_fields'][$i]['category']);
  2474. $template_files = explode(',', $options['custom_fields'][$i]['template_files']);
  2475. $post_ids = explode(',', $options['custom_fields'][$i]['post']);
  2476. $cat_ids = array_filter( $cat_ids );
  2477. $template_files = array_filter( $template_files );
  2478. $post_ids = array_filter( $post_ids );
  2479. $cat_ids = array_unique(array_filter(array_map('trim', $cat_ids)));
  2480. $template_files = array_unique(array_filter(array_map('trim', $template_files)));
  2481. $post_ids = array_unique(array_filter(array_map('trim', $post_ids)));
  2482. if ( !empty($template_files) ) :
  2483. 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') ) :
  2484. if ( count($template_files) && (isset($post->page_template) || isset($_REQUEST['page_template'])) ) :
  2485. if( !in_array($post->page_template, $template_files) && (!isset($_REQUEST['page_template']) || (isset($_REQUEST['page_template']) && !in_array($_REQUEST['page_template'], $template_files))) ) :
  2486. continue;
  2487. endif;
  2488. else :
  2489. continue;
  2490. endif;
  2491. else :
  2492. continue;
  2493. endif;
  2494. endif;
  2495. if ( count($post_ids) && (!isset($_REQUEST['post']) || (isset($_REQUEST['post']) &&!in_array($_REQUEST['post'], $post_ids))) ) :
  2496. continue;
  2497. endif;
  2498. if ( !empty($cat_ids) ) :
  2499. 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')) ) :
  2500. if ( is_array($cat_ids) && count($cat_ids) && count($cats)>0 ) :
  2501. $cat_match = 0;
  2502. foreach ( $cat_ids as $cat_id ) :
  2503. if (in_array($cat_id, $cats) ) :
  2504. $cat_match = 1;
  2505. endif;
  2506. endforeach;
  2507. if($cat_match == 0) :
  2508. continue;
  2509. endif;
  2510. else :
  2511. continue;
  2512. endif;
  2513. else :
  2514. continue;
  2515. endif;
  2516. endif;
  2517. $options['custom_fields'][$i]['id'] = $i;
  2518. $filtered_cfts[] = $options['custom_fields'][$i];
  2519. endfor;
  2520. return $filtered_cfts;
  2521. }
  2522. function custom_field_template_selectbox() {
  2523. $options = $this->get_custom_field_template_data();
  2524. if( count($options['custom_fields']) < 2 ) :
  2525. return '&nbsp;';
  2526. endif;
  2527. $filtered_cfts = $this->custom_field_template_filter();
  2528. if( count($filtered_cfts) < 1 ) :
  2529. return '&nbsp;';
  2530. endif;
  2531. $out = '<select id="custom_field_template_select">';
  2532. foreach ( $filtered_cfts as $filtered_cft ) :
  2533. if ( isset($options['custom_fields'][$filtered_cft['id']]['disable']) ) :
  2534. elseif ( isset($_REQUEST['post']) && isset($options['posts'][$_REQUEST['post']]) && $filtered_cft['id'] == $options['posts'][$_REQUEST['post']] ) :
  2535. $out .= '<option value="' . $filtered_cft['id'] . '" selected="selected">' . stripcslashes($filtered_cft['title']) . '</option>';
  2536. else :
  2537. $out .= '<option value="' . $filtered_cft['id'] . '">' . stripcslashes($filtered_cft['title']) . '</option>';
  2538. endif;
  2539. endforeach;
  2540. $out .= '</select> ';
  2541. $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;};';
  2542. $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(), success: function(html) {';
  2543. if ( !empty($options['custom_field_template_replace_the_title']) ) :
  2544. $out .= 'jQuery(\'#cftdiv h3 span\').text(jQuery(\'#custom_field_template_select :selected\').text());';
  2545. endif;
  2546. $out .= 'jQuery(\'#cft\').html(html);}});};';
  2547. if ( !empty($options['custom_field_template_use_autosave']) ) :
  2548. $out .= 'var fields = jQuery(\'#cft :input\').fieldSerialize();';
  2549. $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});';
  2550. else :
  2551. $out .= 'cftloading_select();';
  2552. endif;
  2553. $out .= '" />';
  2554. return $out;
  2555. }
  2556. function edit_meta_value( $id, $post ) {
  2557. global $wpdb, $wp_version, $current_user;
  2558. $options = $this->get_custom_field_template_data();
  2559. if( !isset( $id ) || isset($_REQUEST['post_ID']) )
  2560. $id = $_REQUEST['post_ID'];
  2561. if( !current_user_can('edit_post', $id) )
  2562. return $id;
  2563. if( isset($_REQUEST['custom-field-template-verify-key']) && !wp_verify_nonce($_REQUEST['custom-field-template-verify-key'], 'custom-field-template') )
  2564. return $id;
  2565. if ( !isset($_REQUEST['custom-field-template-id']) ) :
  2566. unset($options['posts'][$id]);
  2567. update_option('custom_field_template_data', $options);
  2568. return $id;
  2569. endif;
  2570. if ($post->post_type == 'revision')
  2571. return;
  2572. if ( !empty($_REQUEST['custom-field-template-id']) && is_array($_REQUEST['custom-field-template-id']) ) :
  2573. foreach ( $_REQUEST['custom-field-template-id'] as $cft_id ) :
  2574. $fields = $this->get_custom_fields($cft_id);
  2575. if ( $fields == null )
  2576. continue;
  2577. if ( substr($wp_version, 0, 3) >= '2.8' ) {
  2578. if ( !class_exists('SimpleTags') && !empty($_POST['tax_input']['post_tag']) ) {
  2579. $tags_input = explode(",", $_POST['tax_input']['post_tag']);
  2580. }
  2581. } else {
  2582. if ( !class_exists('SimpleTags') && !empty($_POST['tags_input']) ) {
  2583. $tags_input = explode(",", $_POST['tags_input']);
  2584. }
  2585. }
  2586. $save_value = array();
  2587. if ( is_array($_FILES) ) :
  2588. foreach($_FILES as $key => $val ) :
  2589. foreach( $val as $key2 => $val2 ) :
  2590. if ( is_array($val2) ) :
  2591. foreach( $val2 as $key3 => $val3 ) :
  2592. foreach( $val3 as $key4 => $val4 ) :
  2593. if ( !empty($val['name'][$key3][$key4]) ) :
  2594. $tmpfiles[$key][$key3][$key4]['name'] = $val['name'][$key3][$key4];
  2595. $tmpfiles[$key][$key3][$key4]['type'] = $val['type'][$key3][$key4];
  2596. $tmpfiles[$key][$key3][$key4]['tmp_name'] = $val['tmp_name'][$key3][$key4];
  2597. $tmpfiles[$key][$key3][$key4]['error'] = $val['error'][$key3][$key4];
  2598. $tmpfiles[$key][$key3][$key4]['size'] = $val['size'][$key3][$key4];
  2599. endif;
  2600. endforeach;
  2601. endforeach;
  2602. break;
  2603. endif;
  2604. endforeach;
  2605. endforeach;
  2606. endif;
  2607. unset($_FILES);
  2608. foreach( $fields as $field_key => $field_val) :
  2609. foreach( $field_val as $title => $data) :
  2610. //if ( is_numeric($data['parentSN']) ) $field_key = $data['parentSN'];
  2611. $name = $this->sanitize_name( $title );
  2612. $title = $wpdb->escape(stripcslashes(trim($title)));
  2613. if ( isset($data['level']) && is_numeric($data['level']) && $current_user->user_level < $data['level'] ) :
  2614. $save_value[$title] = $this->get_post_meta($id, $title, false);
  2615. continue;
  2616. endif;
  2617. unset($field_key);
  2618. if ( isset($_REQUEST[$name]) && is_array($_REQUEST[$name]) ) :
  2619. foreach( $_REQUEST[$name] as $tmp_key => $tmp_val ) :
  2620. $field_key = $tmp_key;
  2621. if ( is_array($tmp_val) ) $_REQUEST[$name][$tmp_key] = array_values($tmp_val);
  2622. endforeach;
  2623. endif;
  2624. switch ( $data['type'] ) :
  2625. case 'fieldset_open' :
  2626. $save_value[$title][0] = count($_REQUEST[$name]);
  2627. break;
  2628. default :
  2629. $value = isset($_REQUEST[$name][$field_key][$data['cftnum']]) ? trim($_REQUEST[$name][$field_key][$data['cftnum']]) : '';
  2630. if ( !empty($options['custom_field_template_use_wpautop']) && $data['type'] == 'textarea' && !empty($value) )
  2631. $value = wpautop($value);
  2632. if ( isset($data['editCode']) && is_numeric($data['editCode']) ) :
  2633. eval(stripcslashes($options['php'][$data['editCode']]));
  2634. endif;
  2635. if ( $data['type'] != 'file' ) :
  2636. if( isset( $value ) && strlen( $value ) ) :
  2637. if ( isset($data['insertTag']) && $data['insertTag'] == true ) :
  2638. if ( !empty($data['tagName']) ) :
  2639. $tags_input[trim($data['tagName'])][] = $value;
  2640. else :
  2641. $tags_input['post_tag'][] = $value;
  2642. endif;
  2643. endif;
  2644. if ( isset($data['valueCount']) && $data['valueCount'] == true ) :
  2645. $options['value_count'][$title][$value] = $this->set_value_count($title, $value, $id)+1;
  2646. endif;
  2647. if ( $data['type'] == 'textarea' && isset($_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$field_key]) . '_size']) ) {
  2648. preg_match('/cw=[0-9]+&ch=([0-9]+)/', $_REQUEST['TinyMCE_' . $name . trim($_REQUEST[ $name."_rand" ][$field_key]) . '_size'], $matched);
  2649. $options['tinyMCE'][$id][$name][$field_key] = (int)($matched[1]/20);
  2650. }
  2651. $save_value[$title][] = $value;
  2652. elseif ( isset($data['blank']) && $data['blank'] == true ) :
  2653. $save_value[$title][] = '';
  2654. else :
  2655. $tmp_value = $this->get_post_meta( $id, $title, false );
  2656. if ( $data['type'] == 'checkbox' ) :
  2657. delete_post_meta($id, $title, $data['value']);
  2658. else :
  2659. if ( isset($tmp_value[$data['cftnum']]) ) delete_post_meta($id, $title, $tmp_value[$data['cftnum']]);
  2660. endif;
  2661. endif;
  2662. endif;
  2663. if ( $data['type'] == 'file' ) :
  2664. if ( isset($_REQUEST[$name.'_delete'][$field_key][$data['cftnum']]) ) :
  2665. if ( empty($data['mediaRemove']) ) wp_delete_attachment($value);
  2666. delete_post_meta($id, $title, $value);
  2667. unset($value);
  2668. endif;
  2669. if( isset($tmpfiles[$name][$field_key][$data['cftnum']]) ) :
  2670. $_FILES[$title] = $tmpfiles[$name][$field_key][$data['cftnum']];
  2671. if ( isset($value) ) :
  2672. if ( empty($data['mediaRemove']) ) wp_delete_attachment($value);
  2673. endif;
  2674. if ( isset($data['relation']) && $data['relation'] == true ) :
  2675. $upload_id = media_handle_upload($title, $id);
  2676. else :
  2677. $upload_id = media_handle_upload($title, '');
  2678. endif;
  2679. $save_value[$title][] = $upload_id;
  2680. unset($_FILES);
  2681. else :
  2682. if ( !get_post($value) && $value ) :
  2683. if ( isset($data['blank']) && $data['blank'] == true ) :
  2684. $save_value[$title][] = '';
  2685. endif;
  2686. elseif ( $value ) :
  2687. $save_value[$title][] = $value;
  2688. else :
  2689. if ( isset($data['blank']) && $data['blank'] == true ) :
  2690. $save_value[$title][] = '';
  2691. endif;
  2692. endif;
  2693. endif;
  2694. endif;
  2695. endswitch;
  2696. endforeach;
  2697. endforeach;
  2698. /*echo 'tmpfiles';
  2699. print_r($tmpfiles);
  2700. echo 'fields';
  2701. print_r($fields);
  2702. echo '_REQUEST';
  2703. print_r($_REQUEST);
  2704. echo 'save_value';
  2705. print_r($save_value);
  2706. echo 'get_post_custom';
  2707. print_r(get_post_custom($id));
  2708. exit();*/
  2709. foreach( $save_value as $title => $values ) :
  2710. unset($delete);
  2711. if ( count($values) == 1 ) :
  2712. if ( !add_post_meta( $id, $title, apply_filters('cft_'.rawurlencode($title), $values[0]), true ) ) :
  2713. if ( count($this->get_post_meta($id, $title, false))>1 ) :
  2714. delete_post_meta($id, $title);
  2715. add_post_meta( $id, $title, apply_filters('cft_'.rawurlencode($title), $values[0]) );
  2716. else :
  2717. update_post_meta( $id, $title, apply_filters('cft_'.rawurlencode($title), $values[0]) );
  2718. endif;
  2719. endif;
  2720. elseif ( count($values) > 1 ) :
  2721. $tmp = $this->get_post_meta( $id, $title, false );
  2722. if ( $tmp ) delete_post_meta($id, $title);
  2723. foreach($values as $val)
  2724. add_post_meta( $id, $title, apply_filters('cft_'.rawurlencode($title), $val) );
  2725. endif;
  2726. endforeach;
  2727. if ( !empty($tags_input) && is_array($tags_input) ) :
  2728. foreach ( $tags_input as $tags_key => $tags_value ) :
  2729. if ( class_exists('SimpleTags') && $tags_key == 'post_tag' ) :
  2730. wp_cache_flush();
  2731. $taxonomy = wp_get_object_terms($id, 'post_tag', array());
  2732. if ( $taxonomy ) foreach($taxonomy as $val) $tags[] = $val->name;
  2733. if ( is_array($tags) ) $tags_value = array_merge($tags, $tags_value);
  2734. endif;
  2735. if ( is_array($tags_value) )
  2736. $tags_input = array_unique($tags_value);
  2737. else
  2738. $tags_input = $tags_value;
  2739. if ( substr($wp_version, 0, 3) >= '2.8' )
  2740. wp_set_post_terms( $id, $tags_value, $tags_key );
  2741. else if ( substr($wp_version, 0, 3) >= '2.3' )
  2742. wp_set_post_tags( $id, $tags_value );
  2743. endforeach;
  2744. endif;
  2745. if ( empty($options['custom_field_template_deploy_box']) ) $options['posts'][$id] = $cft_id;
  2746. endforeach;
  2747. endif;
  2748. update_option('custom_field_template_data', $options);
  2749. wp_cache_flush();
  2750. }
  2751. function parse_ini_str($Str,$ProcessSections = TRUE) {
  2752. $options = $this->get_custom_field_template_data();
  2753. $Section = NULL;
  2754. $Data = array();
  2755. $Sections = array();
  2756. if ($Temp = strtok($Str,"\r\n")) {
  2757. $sn = -1;
  2758. do {
  2759. switch ($Temp{0}) {
  2760. case ';':
  2761. case '#':
  2762. break;
  2763. case '[':
  2764. if (!$ProcessSections) {
  2765. break;
  2766. }
  2767. $Pos = strpos($Temp,'[');
  2768. $Section = substr($Temp,$Pos+1,strpos($Temp,']',$Pos)-1);
  2769. $sn++;
  2770. $Data[$sn][$Section] = array();
  2771. if ( isset($cftnum[$Section]) ) $cftnum[$Section]++;
  2772. else $cftnum[$Section] = 0;
  2773. $Data[$sn][$Section]['cftnum'] = $cftnum[$Section];
  2774. if($Data[$sn][$Section])
  2775. break;
  2776. default:
  2777. $Pos = strpos($Temp,'=');
  2778. if ($Pos === FALSE) {
  2779. break;
  2780. }
  2781. $Value = array();
  2782. $Value["NAME"] = trim(substr($Temp,0,$Pos));
  2783. $Value["VALUE"] = trim(substr($Temp,$Pos+1));
  2784. if ($ProcessSections) {
  2785. $Data[$sn][$Section][$Value["NAME"]] = $Value["VALUE"];
  2786. }
  2787. else {
  2788. $Data[$Value["NAME"]] = $Value["VALUE"];
  2789. }
  2790. break;
  2791. }
  2792. } while ($Temp = strtok("\r\n"));
  2793. $gap = $key = 0;
  2794. $returndata = array();
  2795. foreach( $Data as $Data_key => $Data_val ) :
  2796. foreach( $Data_val as $title => $data) :
  2797. if ( isset($cftisexist[$title]) ) $tmp_parentSN = $cftisexist[$title];
  2798. else $tmp_parentSN = count($returndata);
  2799. switch ( $data["type"]) :
  2800. case 'checkbox' :
  2801. if ( isset($data["code"]) && is_numeric($data["code"]) ) :
  2802. eval(stripcslashes($options['php'][$data["code"]]));
  2803. else :
  2804. if ( isset($data["value"]) ) $values = explode( '#', $data["value"] );
  2805. if ( isset($data["valueLabel"]) ) $valueLabel = explode( '#', $data["valueLabel"] );
  2806. if ( isset($data["default"]) ) $defaults = explode( '#', $data["default"] );
  2807. endif;
  2808. if ( !empty($valueLabel) ) $valueLabels = $valueLabel;
  2809. if ( isset($defaults) && is_array($defaults) )
  2810. foreach($defaults as $dkey => $dval)
  2811. $defaults[$dkey] = trim($dval);
  2812. $tmp = $key;
  2813. $i = 0;
  2814. if ( isset($values) && is_array($values) ) :
  2815. foreach($values as $value) {
  2816. $count_key = count($returndata);
  2817. $Data[$Data_key][$title]["value"] = trim($value);
  2818. $Data[$Data_key][$title]["originalValue"] = $data["value"];
  2819. $Data[$Data_key][$title]['cftnum'] = $i;
  2820. if ( isset($valueLabels[$i]) )
  2821. $Data[$Data_key][$title]["valueLabel"] = trim($valueLabels[$i]);
  2822. if ( $tmp!=$key )
  2823. $Data[$Data_key][$title]["hideKey"] = true;
  2824. if ( isset($defaults) && is_array($defaults) ) :
  2825. if ( in_array(trim($value), $defaults) )
  2826. $Data[$Data_key][$title]["checked"] = true;
  2827. else
  2828. unset($Data[$Data_key][$title]["checked"]);
  2829. endif;
  2830. $Data[$Data_key][$title]['parentSN'] = $tmp_parentSN+$gap;
  2831. $returndata[$count_key] = $Data[$Data_key];
  2832. $key++;
  2833. $i++;
  2834. }
  2835. endif;
  2836. break;
  2837. default :
  2838. if ( $data['type'] == 'fieldset_open' ) :
  2839. $fieldset = array();
  2840. if ( isset($_REQUEST[$this->sanitize_name($title)]) ) $fieldsetcounter = count($_REQUEST[$this->sanitize_name($title)])-1;
  2841. else if ( isset($_REQUEST['post']) ) $fieldsetcounter = $this->get_post_meta( $_REQUEST['post'], $title, true )-1;
  2842. else $fieldsetcounter = 0;
  2843. if ( !empty($data['multiple']) ) : $fieldset_multiple = 1; endif;
  2844. endif;
  2845. if ( isset($fieldset) && is_array($fieldset) ) :
  2846. if ( empty($tmp_parentSN2[$title]) ) $tmp_parentSN2[$title] = $tmp_parentSN;
  2847. endif;
  2848. if ( isset($data['multiple']) && $data['multiple'] == true && $data['type'] != 'checkbox' && $data['type'] != 'fieldset_open' && !isset($fieldset) ) :
  2849. $counter = isset($_REQUEST[$this->sanitize_name($title)][$tmp_parentSN+$gap]) ? count($_REQUEST[$this->sanitize_name($title)][$tmp_parentSN+$gap]) : 0;
  2850. if ( $data['type'] == 'file' && $_FILES[$this->sanitize_name($title)] ) $counter = (int)count($_FILES[$this->sanitize_name($title)]['name'][$tmp_parentSN+$gap])+1;
  2851. if ( isset($_REQUEST['post_ID']) ) $org_counter = count($this->get_post_meta( $_REQUEST['post_ID'], $title ));
  2852. else if ( isset($_REQUEST['post']) ) $org_counter = count($this->get_post_meta( $_REQUEST['post'], $title ));
  2853. else $org_counter = 1;
  2854. if ( !$counter ) :
  2855. $counter = $org_counter;
  2856. $counter++;
  2857. else :
  2858. if ( empty($_REQUEST[$this->sanitize_name($title)][$tmp_parentSN+$gap][$counter-1]) ) $counter--;
  2859. endif;
  2860. if ( !$org_counter ) $org_counter = 2;
  2861. if ( isset($data['startNum']) && is_numeric($data['startNum']) && $data['startNum']>$counter ) $counter = $data['startNum'];
  2862. if ( isset($data['endNum']) && is_numeric($data['endNum']) && $data['endNum']<$counter ) $counter = $data['endNum'];
  2863. if ( $counter ) :
  2864. for($i=0;$i<$counter; $i++) :
  2865. $count_key = count($returndata);
  2866. if ( $i!=0 ) $Data[$Data_key][$title]["hideKey"] = true;
  2867. if ( $i!=0 ) unset($Data[$Data_key][$title]["label"]);
  2868. $Data[$Data_key][$title]['cftnum'] = $i;
  2869. $Data[$Data_key][$title]['parentSN'] = $tmp_parentSN+$gap;
  2870. $returndata[$count_key] = $Data[$Data_key];
  2871. if ( isset($fieldset) && is_array($fieldset) ) :
  2872. $fieldset[] = $Data[$Data_key];
  2873. endif;
  2874. endfor;
  2875. endif;
  2876. if ( $counter != $org_counter ) :
  2877. $gap += ($org_counter - $counter);
  2878. endif;
  2879. else :
  2880. if ( !isset($cftisexist[$title]) ) $Data[$Data_key][$title]['parentSN'] = $tmp_parentSN+$gap;
  2881. else $Data[$Data_key][$title]['parentSN'] = $tmp_parentSN;
  2882. $returndata[] = $Data[$Data_key];
  2883. if ( isset($fieldset) && is_array($fieldset) ) :
  2884. $Data[$Data_key][$title]['parentSN'] = $tmp_parentSN2[$title];
  2885. $fieldset[] = $Data[$Data_key];
  2886. endif;
  2887. endif;
  2888. if ( $data['type'] == 'fieldset_close' && is_array($fieldset) ) :
  2889. for($i=0;$i<$fieldsetcounter;$i++) :
  2890. $returndata = array_merge($returndata, $fieldset);
  2891. endfor;
  2892. if ( isset($_REQUEST['post_ID']) ) $groupcounter = (int)$this->get_post_meta( $_REQUEST['post_ID'], $title, true );
  2893. if ( !isset($groupcounter) || $groupcounter == 0 ) $groupcounter = $fieldsetcounter;
  2894. if ( isset($_REQUEST[$this->sanitize_name($title)]) && $fieldset_multiple ) :
  2895. $gap += ($groupcounter - count($_REQUEST[$this->sanitize_name($title)]))*count($fieldset);
  2896. unset($fieldset_multiple);
  2897. endif;
  2898. unset($fieldset, $tmp_parentSN2);
  2899. endif;
  2900. unset($counter);
  2901. endswitch;
  2902. if ( !isset($cftisexist[$title]) ) $cftisexist[$title] = $Data[$Data_key][$title]['parentSN'];
  2903. endforeach;
  2904. endforeach;
  2905. $cftnum = array();
  2906. if ( is_array($returndata) ) :
  2907. foreach( $returndata as $Data_key => $Data_val ) :
  2908. foreach( $Data_val as $title => $data ) :
  2909. if ( isset($cftnum[$title]) && is_numeric($cftnum[$title]) ) $cftnum[$title]++;
  2910. else $cftnum[$title] = 0;
  2911. $returndata[$Data_key][$title]['cftnum'] = $cftnum[$title];
  2912. endforeach;
  2913. endforeach;
  2914. endif;
  2915. }
  2916. return $returndata;
  2917. }
  2918. function output_custom_field_values($attr) {
  2919. global $post;
  2920. $options = $this->get_custom_field_template_data();
  2921. if ( empty($post->ID) ) $post_id = get_the_ID();
  2922. else $post_id = $post->ID;
  2923. if ( !isset($options['custom_field_template_before_list']) ) $options['custom_field_template_before_list'] = '<ul>';
  2924. if ( !isset($options['custom_field_template_after_list']) ) $options['custom_field_template_after_list'] = '</ul>';
  2925. if ( !isset($options['custom_field_template_before_value']) ) $options['custom_field_template_before_value'] = '<li>';
  2926. if ( !isset($options['custom_field_template_after_value']) ) $options['custom_field_template_after_value'] = '</li>';
  2927. extract(shortcode_atts(array(
  2928. 'post_id' => $post_id,
  2929. 'template' => 0,
  2930. 'format' => '',
  2931. 'key' => '',
  2932. 'single' => false,
  2933. 'before_list' => $options['custom_field_template_before_list'],
  2934. 'after_list' => $options['custom_field_template_after_list'],
  2935. 'before_value' => $options['custom_field_template_before_value'],
  2936. 'after_value' => $options['custom_field_template_after_value'],
  2937. 'image_size' => '',
  2938. 'image_src' => false,
  2939. 'image_width' => false,
  2940. 'image_height' => false,
  2941. 'value_count' => false,
  2942. 'value' => ''
  2943. ), $attr));
  2944. $metakey = $key;
  2945. if ( $metakey ) :
  2946. if ( $value_count && $value ) :
  2947. return number_format($options['value_count'][$metakey][$value]);
  2948. endif;
  2949. $metavalue = $this->get_post_meta($post_id, $key, $single);
  2950. if ( !is_array($metavalue) ) $metavalue = array($metavalue);
  2951. if ( $before_list ) : $output = $before_list . "\n"; endif;
  2952. foreach ( $metavalue as $val ) :
  2953. if ( !empty($image_size) ) :
  2954. if ( $image_src || $image_width || $image_height ) :
  2955. list($src, $width, $height) = wp_get_attachment_image_src($val, $image_size);
  2956. if ( $image_src ) : $val = $src; endif;
  2957. if ( $image_width ) : $val = $width; endif;
  2958. if ( $image_height ) : $val = $height; endif;
  2959. else :
  2960. $val = wp_get_attachment_image($val, $image_size);
  2961. endif;
  2962. endif;
  2963. $output .= $before_value . $val . $after_value . "\n";
  2964. endforeach;
  2965. if ( $after_list ) : $output .= $after_list . "\n"; endif;
  2966. return do_shortcode($output);
  2967. endif;
  2968. if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) :
  2969. $data = get_post_custom($post_id);
  2970. $output = stripcslashes($output);
  2971. if( $data == null)
  2972. return;
  2973. $count = count($options['custom_fields']);
  2974. if ( $count ) :
  2975. for ($i=0;$i<$count;$i++) :
  2976. $fields = $this->get_custom_fields( $i );
  2977. foreach ( $fields as $field_key => $field_val ) :
  2978. foreach ( $field_val as $key => $val ) :
  2979. if ( count($data[$key]) > 1 ) :
  2980. if ( $val['sort'] == 'asc' ) :
  2981. sort($data[$key]);
  2982. elseif ( $val['sort'] == 'desc' ) :
  2983. rsort($data[$key]);
  2984. endif;
  2985. if ( $before_list ) : $replace_val = $before_list . "\n"; endif;
  2986. foreach ( $data[$key] as $val2 ) :
  2987. $value = $val2;
  2988. if ( is_numeric($val['outputCode']) ) :
  2989. eval(stripcslashes($options['php'][$val['outputCode']]));
  2990. endif;
  2991. if ( $val['shortCode'] == true ) $value = do_shortcode($value);
  2992. $replace_val .= $before_value . $value . $after_value . "\n";
  2993. endforeach;
  2994. if ( $after_list ) : $replace_val .= $after_list . "\n"; endif;
  2995. elseif ( count($data[$key]) == 1 ) :
  2996. $value = $data[$key][0];
  2997. if ( is_numeric($val['outputCode']) ) :
  2998. eval(stripcslashes($options['php'][$val['outputCode']]));
  2999. endif;
  3000. if ( $val['shortCode'] == true ) $value = do_shortcode($value);
  3001. $replace_val = $value;
  3002. if ( $val['singleList'] == true ) :
  3003. if ( $before_list ) : $replace_val = $before_list . "\n"; endif;
  3004. $replace_val .= $before_value . $value . $after_value . "\n";
  3005. if ( $after_list ) : $replace_val .= $after_list . "\n"; endif;
  3006. endif;
  3007. else :
  3008. if ( $val['outputNone'] ) $replace_val = $val['outputNone'];
  3009. else $replace_val = '';
  3010. endif;
  3011. if ( isset($options['shortcode_format_use_php'][$format]) )
  3012. $output = $this->EvalBuffer($output);
  3013. $key = preg_quote($key, '/');
  3014. $replace_val = str_replace('\\', '\\\\', $replace_val);
  3015. $replace_val = str_replace('$', '\$', $replace_val);
  3016. $output = preg_replace('/\['.$key.'\]/', $replace_val, $output);
  3017. endforeach;
  3018. endforeach;
  3019. endfor;
  3020. endif;
  3021. else :
  3022. $fields = $this->get_custom_fields( $template );
  3023. if( $fields == null)
  3024. return;
  3025. $output = '<dl class="cft cft'.$template.'">' . "\n";
  3026. foreach ( $fields as $field_key => $field_val ) :
  3027. foreach ( $field_val as $key => $val ) :
  3028. if ( $keylist[$key] == true ) break;
  3029. $values = $this->get_post_meta( $post_id, $key );
  3030. if ( $values ):
  3031. if ( $val['sort'] == 'asc' ) :
  3032. sort($values);
  3033. elseif ( $val['sort'] == 'desc' ) :
  3034. rsort($values);
  3035. endif;
  3036. if ( $val['output'] == true ) :
  3037. foreach ( $values as $num => $value ) :
  3038. $value = str_replace('\\', '\\\\', $value);
  3039. if ( is_numeric($val['outputCode']) ) :
  3040. eval(stripcslashes($options['php'][$val['outputCode']]));
  3041. endif;
  3042. if ( empty($value) && $val['outputNone'] ) $value = $val['outputNone'];
  3043. if ( $val['shortCode'] == true ) $value = do_shortcode($value);
  3044. if ( !empty($val['label']) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  3045. $key_val = stripcslashes($val['label']);
  3046. else $key_val = $key;
  3047. if ( $val['hideKey'] != true && $num == 0 )
  3048. $output .= '<dt>' . $key_val . '</dt>' . "\n";
  3049. $output .= '<dd>' . $value . '</dd>' . "\n";
  3050. endforeach;
  3051. endif;
  3052. endif;
  3053. $keylist[$key] = true;
  3054. endforeach;
  3055. endforeach;
  3056. $output .= '</dl>' . "\n";
  3057. endif;
  3058. return do_shortcode(stripcslashes($output));
  3059. }
  3060. function search_custom_field_values($attr) {
  3061. global $post;
  3062. $options = $this->get_custom_field_template_data();
  3063. extract(shortcode_atts(array(
  3064. 'template' => 0,
  3065. 'format' => '',
  3066. 'search_label' => __('Search &raquo;', 'custom-field-template'),
  3067. 'button' => true
  3068. ), $attr));
  3069. if ( is_numeric($format) && $output = $options['shortcode_format'][$format] ) :
  3070. $output = stripcslashes($output);
  3071. $output = '<form method="get" action="'.get_option('home').'/" id="cftsearch'.(int)$format.'">' . "\n" . $output;
  3072. $count = count($options['custom_fields']);
  3073. if ( $count ) :
  3074. for ($t=0;$t<$count;$t++) :
  3075. $fields = $this->get_custom_fields( $t );
  3076. foreach ( $fields as $field_key => $field_val ) :
  3077. foreach ( $field_val as $key => $val ) :
  3078. unset($replace);
  3079. $replace[0] = $val;
  3080. $search = array();
  3081. if($val['searchType']) eval('$search["type"] =' . stripslashes($val['searchType']));
  3082. if($val['searchValue']) eval('$search["value"] =' . stripslashes($val['searchValue']));
  3083. if($val['searchOperator']) eval('$search["operator"] =' . stripslashes($val['searchOperator']));
  3084. if($val['searchValueLabel']) eval('$search["valueLabel"] =' . stripslashes($val['searchValueLabel']));
  3085. if($val['searchDefault']) eval('$search["default"] =' . stripslashes($val['searchDefault']));
  3086. if($val['searchClass']) eval('$search["class"] =' . stripslashes($val['searchClass']));
  3087. if($val['searchSelectLabel']) eval('$search["selectLabel"] =' . stripslashes($val['searchSelectLabel']));
  3088. foreach ( $search as $skey => $sval ) :
  3089. $j = 1;
  3090. foreach ( $sval as $sval2 ) :
  3091. $replace[$j][$skey] = $sval2;
  3092. $j++;
  3093. endforeach;
  3094. endforeach;
  3095. foreach( $replace as $rkey => $rval ) :
  3096. $replace_val[$rkey] = "";
  3097. $class = "";
  3098. $default = array();
  3099. switch ( $rval['type'] ) :
  3100. case 'text':
  3101. case 'textfield':
  3102. case 'textarea':
  3103. if ( $rval['class'] ) $class = ' class="' . $rval['class'] . '"';
  3104. $replace_val[$rkey] .= '<input type="text" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0]) . '"' . $class . ' />';
  3105. break;
  3106. case 'checkbox':
  3107. if ( $rval['class'] ) $class = ' class="' . $rval['class'] . '"';
  3108. $values = $valueLabel = array();
  3109. if ( $rkey != 0 )
  3110. $values = explode( '#', $rval['value'] );
  3111. else
  3112. $values = explode( '#', $rval['originalValue'] );
  3113. $valueLabel = explode( '#', $rval['valueLabel'] );
  3114. $default = explode( '#', $rval['default'] );
  3115. if ( is_numeric($rval['searchCode']) ) :
  3116. eval(stripcslashes($options['php'][$rval['searchCode']]));
  3117. endif;
  3118. if ( count($values) > 1 ) :
  3119. $replace_val[$rkey] .= '<ul' . $class . '>';
  3120. $j=0;
  3121. foreach( $values as $metavalue ) :
  3122. $checked = '';
  3123. $metavalue = trim($metavalue);
  3124. if ( is_array($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) :
  3125. if ( in_array($metavalue, $_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) )
  3126. $checked = ' checked="checked"';
  3127. else
  3128. $checked = '';
  3129. endif;
  3130. if ( in_array($metavalue, $default) && !$_REQUEST['cftsearch'][rawurlencode($key)][$rkey] )
  3131. $checked = ' checked="checked"';
  3132. $replace_val[$rkey] .= '<li><label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($metavalue) . '"' . $class . $checked . ' /> ';
  3133. if ( $valueLabel[$j] ) $replace_val[$rkey] .= stripcslashes($valueLabel[$j]);
  3134. else $replace_val[$rkey] .= stripcslashes($metavalue);
  3135. $replace_val[$rkey] .= '</label></li>';
  3136. $j++;
  3137. endforeach;
  3138. $replace_val[$rkey] .= '</ul>';
  3139. else :
  3140. if ( $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == esc_attr(trim($values[0])) )
  3141. $checked = ' checked="checked"';
  3142. $replace_val[$rkey] .= '<label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr(trim($values[0])) . '"' . $class . $checked . ' /> ';
  3143. if ( $valueLabel[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabel[0]));
  3144. else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
  3145. $replace_val[$rkey] .= '</label>';
  3146. endif;
  3147. break;
  3148. case 'radio':
  3149. if ( $rval['class'] ) $class = ' class="' . $rval['class'] . '"';
  3150. $values = explode( '#', $rval['value'] );
  3151. $valueLabel = explode( '#', $rval['valueLabel'] );
  3152. $default = explode( '#', $rval['default'] );
  3153. if ( is_numeric($rval['searchCode']) ) :
  3154. eval(stripcslashes($options['php'][$rval['searchCode']]));
  3155. endif;
  3156. if ( count($values) > 1 ) :
  3157. $replace_val[$rkey] .= '<ul' . $class . '>';
  3158. $j=0;
  3159. foreach ( $values as $metavalue ) :
  3160. $checked = '';
  3161. $metavalue = trim($metavalue);
  3162. if ( is_array($_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) ) :
  3163. if ( in_array($metavalue, $_REQUEST['cftsearch'][rawurlencode($key)][$rkey]) )
  3164. $checked = ' checked="checked"';
  3165. else
  3166. $checked = '';
  3167. endif;
  3168. if ( in_array($metavalue, $default) && !$_REQUEST['cftsearch'][rawurlencode($key)][$rkey] )
  3169. $checked = ' checked="checked"';
  3170. $replace_val[$rkey] .= '<li><label><input type="radio" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($metavalue) . '"' . $class . $checked . ' /> ';
  3171. if ( $valueLabel[$j] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabel[$j]));
  3172. else $replace_val[$rkey] .= stripcslashes($metavalue);
  3173. $replace_val[$rkey] .= '</label></li>';
  3174. $j++;
  3175. endforeach;
  3176. $replace_val[$rkey] .= '</ul>';
  3177. else :
  3178. if ( $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == esc_attr(trim($values[0])) )
  3179. $checked = ' checked="checked"';
  3180. $replace_val[$rkey] .= '<label><input type="radio" name="cftsearch[' . rawurlencode($key) . '][]" value="' . esc_attr(trim($values[0])) . '"' . $class . $checked . ' /> ';
  3181. if ( $valueLabel[0] ) $replace_val[$rkey] .= stripcslashes(trim($valueLabel[0]));
  3182. else $replace_val[$rkey] .= stripcslashes(trim($values[0]));
  3183. $replace_val[$rkey] .= '</label>';
  3184. endif;
  3185. break;
  3186. case 'select':
  3187. if ( $rval['class'] ) $class = ' class="' . $rval['class'] . '"';
  3188. $values = explode( '#', $rval['value'] );
  3189. $valueLabel = explode( '#', $rval['valueLabel'] );
  3190. $default = explode( '#', $rval['default'] );
  3191. $selectLabel= $rval['selectLabel'];
  3192. if ( is_numeric($rval['searchCode']) ) :
  3193. eval(stripcslashes($options['php'][$rval['searchCode']]));
  3194. endif;
  3195. $replace_val[$rkey] .= '<select name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]"' . $class . '>';
  3196. $replace_val[$rkey] .= '<option value="">'.$selectLabel.'</option>';
  3197. $j=0;
  3198. foreach ( $values as $metaval ) :
  3199. $metaval = trim($metaval);
  3200. if ( in_array($metavalue, $default) && !$_REQUEST['cftsearch'][rawurlencode($key)][$rkey] )
  3201. $checked = ' checked="checked"';
  3202. if ( $_REQUEST['cftsearch'][rawurlencode($key)][$rkey][0] == $metaval ) $selected = ' selected="selected"';
  3203. else $selected = "";
  3204. $replace_val[$rkey] .= '<option value="' . esc_attr($metaval) . '"' . $selected . '>';
  3205. if ( $valueLabel[$j] )
  3206. $replace_val[$rkey] .= stripcslashes(trim($valueLabel[$j]));
  3207. else
  3208. $replace_val[$rkey] .= stripcslashes($metaval);
  3209. $replace_val[$rkey] .= '</option>' . "\n";
  3210. $j++;
  3211. endforeach;
  3212. $replace_val[$rkey] .= '</select>' . "\n";
  3213. break;
  3214. endswitch;
  3215. endforeach;
  3216. if ( isset($options['shortcode_format_use_php'][$format]) )
  3217. $output = $this->EvalBuffer($output);
  3218. $key = preg_quote($key, '/');
  3219. $output = preg_replace('/\['.$key.'\](?!\[[0-9]+\])/', $replace_val[0], $output);
  3220. $output = preg_replace('/\['.$key.'\]\[([0-9]+)\](?!\[\])/e', '$replace_val[${1}]', $output);
  3221. endforeach;
  3222. endforeach;
  3223. endfor;
  3224. endif;
  3225. if ( $button === true )
  3226. $output .= '<p><input type="submit" value="' . $search_label . '" class="cftsearch_submit" /></p>' . "\n";
  3227. $output .= '<input type="hidden" name="cftsearch_submit" value="1" />' . "\n";
  3228. $output .= '</form>' . "\n";
  3229. else :
  3230. $fields = $this->get_custom_fields( $template );
  3231. if ( $fields == null )
  3232. return;
  3233. $output = '<form method="get" action="'.get_option('home').'/" id="cftsearch'.(int)$format.'">' . "\n";
  3234. foreach( $fields as $field_key => $field_val) :
  3235. foreach( $field_val as $key => $val) :
  3236. if ( $val['search'] == true ) :
  3237. if ( !empty($val['label']) && !empty($options['custom_field_template_replace_keys_by_labels']) )
  3238. $key = stripcslashes($val['label']);
  3239. $output .= '<dl>' ."\n";
  3240. if ( $val['hideKey'] != true) :
  3241. $output .= '<dt><label>' . $key . '</label></dt>' ."\n";
  3242. endif;
  3243. $class = "";
  3244. switch ( $val['type'] ) :
  3245. case 'text':
  3246. case 'textfield':
  3247. case 'textarea':
  3248. if ( $val['class'] ) $class = ' class="' . $val['class'] . '"';
  3249. $output .= '<dd><input type="text" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($_REQUEST['cftsearch'][rawurlencode($key)][0][0]) . '"' . $class . ' /></dd>';
  3250. break;
  3251. case 'checkbox':
  3252. unset($checked);
  3253. if ( $val['class'] ) $class = ' class="' . $val['class'] . '"';
  3254. if ( is_array($_REQUEST['cftsearch'][rawurlencode($key)]) )
  3255. foreach ( $_REQUEST['cftsearch'][rawurlencode($key)] as $values )
  3256. if ( $val['value'] == $values[0] ) $checked = ' checked="checked"';
  3257. $output .= '<dd><label><input type="checkbox" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($val['value']) . '"' . $class . $checked . ' /> ';
  3258. if ( $val['valueLabel'] )
  3259. $output .= stripcslashes($val['valueLabel']);
  3260. else
  3261. $output .= stripcslashes($val['value']);
  3262. $output .= '</label></dd>' . "\n";
  3263. break;
  3264. case 'radio':
  3265. if ( $val['class'] ) $class = ' class="' . $val['class'] . '"';
  3266. $values = explode( '#', $val['value'] );
  3267. $valueLabel = explode( '#', $val['valueLabel'] );
  3268. $i=0;
  3269. foreach ( $values as $metaval ) :
  3270. unset($checked);
  3271. $metaval = trim($metaval);
  3272. if ( $_REQUEST['cftsearch'][rawurlencode($key)][0][0] == $metaval ) $checked = 'checked="checked"';
  3273. $output .= '<dd><label>' . '<input type="radio" name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]" value="' . esc_attr($metaval) . '"' . $class . $checked . ' /> ';
  3274. if ( $val['valueLabel'] )
  3275. $output .= stripcslashes(trim($valueLabel[$i]));
  3276. else
  3277. $output .= stripcslashes($metaval);
  3278. $i++;
  3279. $output .= '</label></dd>' . "\n";
  3280. endforeach;
  3281. break;
  3282. case 'select':
  3283. if ( $val['class'] ) $class = ' class="' . $val['class'] . '"';
  3284. $values = explode( '#', $val['value'] );
  3285. $valueLabel = explode( '#', $val['valueLabel'] );
  3286. $output .= '<dd><select name="cftsearch[' . rawurlencode($key) . '][' . $rkey . '][]"' . $class . '>';
  3287. $output .= '<option value=""></option>';
  3288. $i=0;
  3289. foreach ( $values as $metaval ) :
  3290. unset($selected);
  3291. $metaval = trim($metaval);
  3292. if ( $_REQUEST['cftsearch'][rawurlencode($key)][0][0] == $metaval ) $selected = 'selected="selected"';
  3293. else $selected = "";
  3294. $output .= '<option value="' . esc_attr($metaval) . '"' . $selected . '>';
  3295. if ( $val['valueLabel'] )
  3296. $output .= stripcslashes(trim($valueLabel[$i]));
  3297. else
  3298. $output .= stripcslashes($metaval);
  3299. $output .= '</option>' . "\n";
  3300. $i++;
  3301. endforeach;
  3302. $output .= '</select></dd>' . "\n";
  3303. break;
  3304. endswitch;
  3305. $output .= '</dl>' ."\n";
  3306. endif;
  3307. endforeach;
  3308. endforeach;
  3309. if ( $button == true )
  3310. $output .= '<p><input type="submit" value="' . $search_label . '" class="cftsearch_submit" /></p>' . "\n";
  3311. $output .= '<input type="hidden" name="cftsearch_submit" value="1" /></p>' . "\n";
  3312. $output .= '</form>' . "\n";
  3313. endif;
  3314. return do_shortcode(stripcslashes($output));
  3315. }
  3316. function custom_field_template_posts_where($where) {
  3317. global $wp_query, $wp_version, $wpdb;
  3318. $options = $this->get_custom_field_template_data();
  3319. if ( isset($_REQUEST['no_is_search']) ) :
  3320. $wp_query->is_search = '';
  3321. else:
  3322. $wp_query->is_search = 1;
  3323. endif;
  3324. $wp_query->is_page = '';
  3325. $wp_query->is_singular = '';
  3326. $original_where = $where;
  3327. $where = '';
  3328. $count = count($options['custom_fields']);
  3329. if ( $count ) :
  3330. for ($i=0;$i<$count;$i++) :
  3331. $fields = $this->get_custom_fields( $i );
  3332. foreach ( $fields as $field_key => $field_val ) :
  3333. foreach ( $field_val as $key => $val ) :
  3334. $replace[$key] = $val;
  3335. $search = array();
  3336. if($val['searchType']) eval('$search["type"] =' . stripslashes($val['searchType']));
  3337. if($val['searchValue']) eval('$search["value"] =' . stripslashes($val['searchValue']));
  3338. if($val['searchOperator']) eval('$search["operator"] =' . stripslashes($val['searchOperator']));
  3339. foreach ( $search as $skey => $sval ) :
  3340. $j = 1;
  3341. foreach ( $sval as $sval2 ) :
  3342. $replace[$key][$j][$skey] = $sval2;
  3343. $j++;
  3344. endforeach;
  3345. endforeach;
  3346. endforeach;
  3347. endforeach;
  3348. endfor;
  3349. endif;
  3350. if ( is_array($_REQUEST['cftsearch']) ) :
  3351. foreach ( $_REQUEST['cftsearch'] as $key => $val ) :
  3352. $key = rawurldecode($key);
  3353. if ( is_array($val) ) :
  3354. $ch = 0;
  3355. foreach( $val as $key2 => $val2 ) :
  3356. if ( is_array($val2) ) :
  3357. foreach( $val2 as $val3 ) :
  3358. if ( $val3 ) :
  3359. if ( $ch == 0 ) : $where .= ' AND (';
  3360. else :
  3361. if ( $replace[$key][$key2]['type'] == 'checkbox' || !$replace[$key][$key2]['type'] ) $where .= ' OR ';
  3362. else $where .= ' AND ';
  3363. endif;
  3364. switch( $replace[$key][$key2]['operator'] ) :
  3365. case '<=' :
  3366. case '>=' :
  3367. case '<' :
  3368. case '>' :
  3369. case '=' :
  3370. case '<>' :
  3371. case '<=>':
  3372. if ( is_numeric($val3) ) :
  3373. $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) GROUP BY `" . $wpdb->postmeta . "`.post_id) ", $key, trim($val3));
  3374. else :
  3375. $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) GROUP BY `" . $wpdb->postmeta . "`.post_id) ", $key, trim($val3));
  3376. endif;
  3377. break;
  3378. default :
  3379. $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) GROUP BY `" . $wpdb->postmeta . "`.post_id) ", $key, '%'.trim($val3).'%');
  3380. break;
  3381. endswitch;
  3382. $ch++;
  3383. endif;
  3384. endforeach;
  3385. endif;
  3386. endforeach;
  3387. if ( $ch>0 ) $where .= ') ';
  3388. endif;
  3389. endforeach;
  3390. endif;
  3391. if ( $_REQUEST['s'] ) :
  3392. $where .= ' AND (';
  3393. if ( function_exists('mb_split') ) :
  3394. $s = mb_split('\s', $_REQUEST['s']);
  3395. else:
  3396. $s = split('\s', $_REQUEST['s']);
  3397. endif;
  3398. $i=0;
  3399. foreach ( $s as $v ) :
  3400. if ( !empty($v) ) :
  3401. if ( $i>0 ) $where .= ' AND ';
  3402. $where .= $wpdb->prepare(" ID IN (SELECT `" . $wpdb->postmeta . "`.post_id FROM `" . $wpdb->postmeta . "` WHERE (`" . $wpdb->postmeta . "`.meta_value LIKE %s) GROUP BY `" . $wpdb->postmeta . "`.post_id) ", '%'.trim($v).'%');
  3403. $i++;
  3404. endif;
  3405. endforeach;
  3406. $where .= $wpdb->prepare(" OR ((`" . $wpdb->posts . "`.post_title LIKE %s) OR (`" . $wpdb->posts . "`.post_content LIKE %s))", '%'.trim($_REQUEST['s']).'%', '%'.trim($_REQUEST['s']).'%');
  3407. $where .= ') ';
  3408. endif;
  3409. if ( is_array($_REQUEST['cftcategory_in']) ) :
  3410. $ids = get_objects_in_term($_REQUEST['cftcategory_in'], 'category');
  3411. if ( is_array($ids) && count($ids) > 0 ) :
  3412. $in_posts = "'" . implode("', '", $ids) . "'";
  3413. $where .= " AND ID IN (" . $in_posts . ")";
  3414. endif;
  3415. $where .= " AND `" . $wpdb->posts . "`.post_type = 'post'";
  3416. endif;
  3417. if ( is_array($_REQUEST['cftcategory_not_in']) ) :
  3418. $ids = get_objects_in_term($_REQUEST['cftcategory_not_in'], 'category');
  3419. if ( is_array($ids) && count($ids) > 0 ) :
  3420. $in_posts = "'" . implode("', '", $ids) . "'";
  3421. $where .= " AND ID NOT IN (" . $in_posts . ")";
  3422. endif;
  3423. endif;
  3424. if ( $_REQUEST['post_type'] ) :
  3425. $where .= $wpdb->prepare(" AND `" . $wpdb->posts . "`.post_type = %s", trim($_REQUEST['post_type']));
  3426. endif;
  3427. if ( $_REQUEST['no_is_search'] ) :
  3428. $where .= " AND `".$wpdb->posts."`.post_status = 'publish'";
  3429. else :
  3430. $where .= " AND `".$wpdb->posts."`.post_status = 'publish' GROUP BY `".$wpdb->posts."`.ID";
  3431. endif;
  3432. return $where;
  3433. }
  3434. function custom_field_template_posts_join($sql) {
  3435. if ( !in_array($_REQUEST['orderby'], array('post_author', 'post_date', 'post_title', 'post_modified', 'menu_order', 'post_parent', 'ID')) ):
  3436. if ( ($_REQUEST['order'] == 'ASC' || $_REQUEST['order'] == 'DESC') && $_REQUEST['orderby'] ) :
  3437. global $wpdb;
  3438. $sql = $wpdb->prepare(" LEFT JOIN `" . $wpdb->postmeta . "` AS meta ON (`" . $wpdb->posts . "`.ID = meta.post_id AND meta.meta_key = %s)", $_REQUEST['orderby']);
  3439. return $sql;
  3440. endif;
  3441. endif;
  3442. }
  3443. function custom_field_template_posts_orderby($sql) {
  3444. global $wpdb;
  3445. if ( empty($_REQUEST['order']) || ((strtoupper($_REQUEST['order']) != 'ASC') && (strtoupper($_REQUEST['order']) != 'DESC')) )
  3446. $_REQUEST['order'] = 'DESC';
  3447. if ( $_REQUEST['orderby'] ) :
  3448. if ( in_array($_REQUEST['orderby'], array('post_author', 'post_date', 'post_title', 'post_modified', 'menu_order', 'post_parent', 'ID')) ):
  3449. $sql = "`" . $wpdb->posts . "`." . $_REQUEST['orderby'] . " " . $_REQUEST['order'];
  3450. elseif ( $_REQUEST['orderby'] == 'rand' ):
  3451. $sql = "RAND()";
  3452. else:
  3453. if ( in_array($_REQUEST['cast'], array('binary', 'char', 'date', 'datetime', 'signed', 'time', 'unsigned')) ) :
  3454. $sql = " CAST(meta.meta_value AS " . $_REQUEST['cast'] . ") " . $_REQUEST['order'];
  3455. else :
  3456. $sql = " meta.meta_value " . $_REQUEST['order'];
  3457. endif;
  3458. endif;
  3459. return $sql;
  3460. endif;
  3461. $sql = "`" . $wpdb->posts . "`.post_date " . $_REQUEST['order'];
  3462. return $sql;
  3463. }
  3464. function custom_field_template_post_limits($sql_limit) {
  3465. global $wp_query;
  3466. if ( !$sql_limit ) return;
  3467. list($offset, $old_limit) = explode(',', $sql_limit);
  3468. $limit = (int)$_REQUEST['limit'];
  3469. if ( !$limit )
  3470. $limit = trim($old_limit);
  3471. $wp_query->query_vars['posts_per_page'] = $limit;
  3472. $offset = ($wp_query->query_vars['paged'] - 1) * $limit;
  3473. if ( $offset < 0 ) $offset = 0;
  3474. return ( $limit ? "LIMIT $offset, $limit" : '' );
  3475. }
  3476. function EvalBuffer($string) {
  3477. ob_start();
  3478. eval('?>'.$string);
  3479. $ret = ob_get_contents();
  3480. ob_end_clean();
  3481. return $ret;
  3482. }
  3483. function set_value_count($key, $value, $id) {
  3484. global $wpdb;
  3485. if ( $id ) $where = " AND `". $wpdb->postmeta."`.post_id<>".$id;
  3486. $query = $wpdb->prepare("SELECT COUNT(meta_id) FROM `". $wpdb->postmeta."` WHERE `". $wpdb->postmeta."`.meta_key = %s AND `". $wpdb->postmeta."`.meta_value = %s $where;", $key, $value);
  3487. $count = $wpdb->get_var($query);
  3488. return (int)$count;
  3489. }
  3490. function get_value_count($key = '', $value = '') {
  3491. $options = $this->get_custom_field_template_data();
  3492. if ( $key && $value ) :
  3493. return $options['value_count'][$key][$value];
  3494. else:
  3495. return $options['value_count'];
  3496. endif;
  3497. }
  3498. function custom_field_template_delete_post($post_id) {
  3499. global $wpdb;
  3500. $options = $this->get_custom_field_template_data();
  3501. $id = !empty($options['posts'][$post_id]) ? $options['posts'][$post_id] : '';
  3502. if ( is_numeric($id) ) :
  3503. $fields = $this->get_custom_fields($id);
  3504. if ( $fields == null )
  3505. return;
  3506. foreach( $fields as $field_key => $field_val) :
  3507. foreach( $field_val as $title => $data) :
  3508. $name = $this->sanitize_name( $title );
  3509. $title = $wpdb->escape(stripcslashes(trim($title)));
  3510. $value = $this->get_post_meta($post_id, $title);
  3511. if ( is_array($value) ) :
  3512. foreach ( $value as $val ) :
  3513. if ( $data['valueCount'] == true ) :
  3514. $count = $this->set_value_count($title, $val, '')-1;
  3515. if ( $count<=0 )
  3516. unset($options['value_count'][$title][$val]);
  3517. else
  3518. $options['value_count'][$title][$val] = $count;
  3519. endif;
  3520. endforeach;
  3521. else :
  3522. if ( $data['valueCount'] == true ) :
  3523. $count = $this->set_value_count($title, $value, '')-1;
  3524. if ( $count<=0 )
  3525. unset($options['value_count'][$title][$value]);
  3526. else
  3527. $options['value_count'][$title][$value] = $count;
  3528. endif;
  3529. endif;
  3530. endforeach;
  3531. endforeach;
  3532. endif;
  3533. update_option('custom_field_template_data', $options);
  3534. }
  3535. function custom_field_template_rebuild_value_counts() {
  3536. global $wpdb;
  3537. $options = $this->get_custom_field_template_data();
  3538. unset($options['value_count']);
  3539. if ( is_array($options['custom_fields']) ) :
  3540. for($j=0;$j<count($options['custom_fields']);$j++) :
  3541. $fields = $this->get_custom_fields($j);
  3542. if ( $fields == null )
  3543. return;
  3544. foreach( $fields as $field_key => $field_val) :
  3545. foreach( $field_val as $title => $data) :
  3546. $name = $this->sanitize_name( $title );
  3547. $title = $wpdb->escape(stripcslashes(trim($title)));
  3548. if ( $data['valueCount'] == true ) :
  3549. $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);
  3550. $result = $wpdb->get_results($query, ARRAY_A);
  3551. if ( $result ) :
  3552. foreach($result as $val) :
  3553. $options['value_count'][$title][$val['meta_value']] = $val['meta_count'];
  3554. endforeach;
  3555. endif;
  3556. endif;
  3557. endforeach;
  3558. endforeach;
  3559. endfor;
  3560. endif;
  3561. update_option('custom_field_template_data', $options);
  3562. }
  3563. }
  3564. if ( !function_exists('esc_html') ) :
  3565. function esc_html( $text ) {
  3566. $safe_text = wp_specialchars( $safe_text, ENT_QUOTES );
  3567. return apply_filters( 'esc_html', $safe_text, $text );
  3568. }
  3569. function esc_attr( $text ) {
  3570. return attribute_escape($text);
  3571. }
  3572. function esc_url( $url, $protocols = null ) {
  3573. return clean_url( $url, $protocols, 'display' );
  3574. }
  3575. endif;
  3576. $custom_field_template = new custom_field_template();
  3577. ?>