PageRenderTime 99ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

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