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

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

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