PageRenderTime 43ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

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

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