PageRenderTime 70ms 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

Large files files are truncated, but you can click here to view the full file

  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 `lab…

Large files files are truncated, but you can click here to view the full file