PageRenderTime 68ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 2ms

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

https://bitbucket.org/mahoutsukai/bookandbeer_since20120718
PHP | 3996 lines | 3519 code | 409 blank | 68 comment | 1221 complexity | a6f2ed25f6e6b8101b958d3c516ec76c MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, GPL-3.0

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: 2.0.4
  8. Author URI: http://wpgogo.com/
  9. */
  10. /*
  11. This program is based on the rc:custom_field_gui plugin written by Joshua Sigar.
  12. I appreciate your efforts, Joshua.
  13. */
  14. /* Copyright 2008 -2012 Hiroaki Miyashita
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2 of the License, or
  18. (at your option) any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. class custom_field_template {
  28. var $is_excerpt;
  29. function custom_field_template() {
  30. add_action( 'init', array(&$this, 'custom_field_template_init'), 100 );
  31. add_action( 'admin_menu', array(&$this, 'custom_field_template_admin_menu') );
  32. add_action( 'admin_print_scripts', array(&$this, 'custom_field_template_admin_scripts') );
  33. add_action( 'admin_head', array(&$this, 'custom_field_template_admin_head'), 100 );
  34. add_action( 'dbx_post_sidebar', array(&$this, 'custom_field_template_dbx_post_sidebar') );
  35. //add_action( 'edit_post', array(&$this, 'edit_meta_value'), 100 );
  36. add_action( 'save_post', array(&$this, 'edit_meta_value'), 100, 2 );
  37. //add_action( 'publish_post', array(&$this, 'edit_meta_value'), 100 );
  38. add_action( 'delete_post', array(&$this, 'custom_field_template_delete_post'), 100 );
  39. add_filter( 'media_send_to_editor', array(&$this, 'media_send_to_custom_field'), 15 );
  40. add_filter( 'plugin_action_links', array(&$this, 'wpaq_filter_plugin_actions'), 100, 2 );
  41. add_filter( 'get_the_excerpt', array(&$this, 'custom_field_template_get_the_excerpt'), 1 );
  42. add_filter( 'the_content', array(&$this, 'custom_field_template_the_content') );
  43. add_filter( 'the_content_rss', array(&$this, 'custom_field_template_the_content') );
  44. add_filter( 'attachment_fields_to_edit', array(&$this, 'custom_field_template_attachment_fields_to_edit'), 10, 2 );
  45. if ( isset($_REQUEST['cftsearch_submit']) ) :
  46. if ( !empty($_REQUEST['limit']) )
  47. add_action( 'post_limits', array(&$this, 'custom_field_template_post_limits'));
  48. add_filter( 'posts_join', array(&$this, 'custom_field_template_posts_join') );
  49. add_filter( 'posts_where', array(&$this, 'custom_field_template_posts_where'), 100 );
  50. add_filter( 'posts_orderby', array(&$this, 'custom_field_template_posts_orderby' ) );
  51. endif;
  52. if ( function_exists('add_shortcode') ) :
  53. add_shortcode( 'cft', array(&$this, 'output_custom_field_values') );
  54. add_shortcode( 'cftsearch', array(&$this, 'search_custom_field_values') );
  55. endif;
  56. }
  57. function custom_field_template_init() {
  58. global $wp_version;
  59. $options = $this->get_custom_field_template_data();
  60. if ( function_exists('load_plugin_textdomain') ) {
  61. if ( !defined('WP_PLUGIN_DIR') ) {
  62. load_plugin_textdomain('custom-field-template', str_replace( ABSPATH, '', dirname(__FILE__) ) );
  63. } else {
  64. load_plugin_textdomain('custom-field-template', false, dirname( plugin_basename(__FILE__) ) );
  65. }
  66. }
  67. if ( is_user_logged_in() && isset($_REQUEST['post']) && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'selectbox' ) {
  68. echo $this->custom_field_template_selectbox();
  69. exit();
  70. }
  71. if ( is_user_logged_in() && isset($_REQUEST['post']) && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'ajaxsave' ) {
  72. if ( $_REQUEST['post'] > 0 )
  73. $this->edit_meta_value( $_REQUEST['post'], '' );
  74. exit();
  75. }
  76. if ( is_user_logged_in() && isset($_REQUEST['page']) && $_REQUEST['page'] == 'custom-field-template/custom-field-template.php' && $_REQUEST['cft_mode'] == 'ajaxload') {
  77. if ( isset($_REQUEST['id']) ) :
  78. $id = $_REQUEST['id'];
  79. elseif ( isset($options['posts'][$_REQUEST['post']]) ) :
  80. $id = $options['posts'][$_REQUEST['post']];
  81. else :
  82. $filtered_cfts = $this->custom_field_template_filter();
  83. if ( count($filtered_cfts)>0 ) :
  84. $id = $filtered_cfts[0]['id'];
  85. else :
  86. $id = 0;
  87. endif;
  88. endif;
  89. list($body, $init_id) = $this->load_custom_field( $id );
  90. echo $body;
  91. exit();
  92. }
  93. if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/plugins.php') && ((isset($_GET['activate']) && $_GET['activate'] == 'true') || (isset($_GET['activate-multi']) && $_GET['activate-multi'] == 'true') ) ) {
  94. $options = $this->get_custom_field_template_data();
  95. if( !$options ) {
  96. $this->install_custom_field_template_data();
  97. $this->install_custom_field_template_css();
  98. }
  99. }
  100. if ( function_exists('current_user_can') && current_user_can('edit_plugins') ) :
  101. if ( isset($_POST['custom_field_template_export_options_submit']) ) :
  102. $filename = "cft".date('Ymd');
  103. header("Accept-Ranges: none");
  104. header("Content-Disposition: attachment; filename=$filename");
  105. header('Content-Type: application/octet-stream');
  106. echo maybe_serialize($options);
  107. exit();
  108. endif;
  109. endif;
  110. if ( !empty($options['custom_field_template_widget_shortcode']) )
  111. add_filter('widget_text', 'do_shortcode');
  112. if ( substr($wp_version, 0, 3) >= '2.7' ) {
  113. if ( empty($options['custom_field_template_disable_custom_field_column']) ) :
  114. add_action( 'manage_posts_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 );
  115. add_filter( 'manage_posts_columns', array(&$this, 'add_manage_posts_columns') );
  116. add_action( 'manage_pages_custom_column', array(&$this, 'add_manage_posts_custom_column'), 10, 2 );
  117. add_filter( 'manage_pages_columns', array(&$this, 'add_manage_pages_columns') );
  118. endif;
  119. if ( empty($options['custom_field_template_disable_quick_edit']) )
  120. add_action( 'quick_edit_custom_box', array(&$this, 'add_quick_edit_custom_box'), 10, 2 );
  121. }
  122. if ( substr($wp_version, 0, 3) < '2.5' ) {
  123. add_action( 'simple_edit_form', array(&$this, 'insert_custom_field'), 1 );
  124. add_action( 'edit_form_advanced', array(&$this, 'insert_custom_field'), 1 );
  125. add_action( 'edit_page_form', array(&$this, 'insert_custom_field'), 1 );
  126. } else {
  127. if ( substr($wp_version, 0, 3) >= '3.3' && file_exists(ABSPATH . 'wp-admin/includes/screen.php') ) :
  128. require_once(ABSPATH . 'wp-admin/includes/screen.php');
  129. endif;
  130. require_once(ABSPATH . 'wp-admin/includes/template.php');
  131. if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) :
  132. remove_meta_box('postcustom', 'post', 'normal');
  133. remove_meta_box('postcustom', 'page', 'normal');
  134. remove_meta_box('pagecustomdiv', 'page', 'normal');
  135. endif;
  136. if ( !empty($options['custom_field_template_deploy_box']) ) :
  137. if ( !empty($options['custom_fields']) ) :
  138. $i = 0;
  139. foreach ( $options['custom_fields'] as $key => $val ) :
  140. if ( empty($options['custom_field_template_replace_the_title']) ) $title = __('Custom Field Template', 'custom-field-template');
  141. else $title = $options['custom_fields'][$key]['title'];
  142. if ( empty($options['custom_fields'][$key]['custom_post_type']) ) :
  143. if ( empty($options['custom_fields'][$key]['post_type']) ) :
  144. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', $key);
  145. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', $key);
  146. elseif ( $options['custom_fields'][$key]['post_type']=='post' ) :
  147. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'post', 'normal', 'core', $key);
  148. elseif ( $options['custom_fields'][$key]['post_type']=='page' ) :
  149. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), 'page', 'normal', 'core', $key);
  150. endif;
  151. else :
  152. $tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']);
  153. $tmp_custom_post_type = array_filter( $tmp_custom_post_type );
  154. $tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type)));
  155. foreach ( $tmp_custom_post_type as $type ) :
  156. add_meta_box('cftdiv'.$i, $title, array(&$this, 'insert_custom_field'), $type, 'normal', 'core', $key);
  157. endforeach;
  158. endif;
  159. $i++;
  160. endforeach;
  161. endif;
  162. else :
  163. add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'post', 'normal', 'core');
  164. add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), 'page', 'normal', 'core');
  165. endif;
  166. if ( empty($options['custom_field_template_deploy_box']) && is_array($options['custom_fields']) ) :
  167. $custom_post_type = array();
  168. foreach($options['custom_fields'] as $key => $val ) :
  169. if ( isset($options['custom_fields'][$key]['custom_post_type']) ) :
  170. $tmp_custom_post_type = explode(',', $options['custom_fields'][$key]['custom_post_type']);
  171. $tmp_custom_post_type = array_filter( $tmp_custom_post_type );
  172. $tmp_custom_post_type = array_unique(array_filter(array_map('trim', $tmp_custom_post_type)));
  173. $custom_post_type = array_merge($custom_post_type, $tmp_custom_post_type);
  174. endif;
  175. endforeach;
  176. if ( isset($custom_post_type) && is_array($custom_post_type) ) :
  177. foreach( $custom_post_type as $val ) :
  178. if ( function_exists('remove_meta_box') && !empty($options['custom_field_template_disable_default_custom_fields']) ) :
  179. remove_meta_box('postcustom', $val, 'normal');
  180. endif;
  181. add_meta_box('cftdiv', __('Custom Field Template', 'custom-field-template'), array(&$this, 'insert_custom_field'), $val, 'normal', 'core');
  182. if ( empty($options['custom_field_template_disable_custom_field_column']) ) :
  183. add_filter( 'manage_'.$val.'_posts_columns', array(&$this, 'add_manage_pages_columns') );
  184. endif;
  185. endforeach;
  186. endif;
  187. endif;
  188. }
  189. if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') ) :
  190. add_action('admin_head', array(&$this, 'custom_field_template_admin_head_buffer') );
  191. add_action('admin_footer', array(&$this, 'custom_field_template_admin_footer_buffer') );
  192. endif;
  193. }
  194. function custom_field_template_attachment_fields_to_edit($form_fields, $post) {
  195. $form_fields["custom_field_template"]["label"] = __('Media Picker', 'custom-field-template');
  196. $form_fields["custom_field_template"]["input"] = "html";
  197. $form_fields["custom_field_template"]["html"] = '<a href="javascript:void(0);" onclick="var win = window.dialogArguments || opener || parent || top;win.cft_use_this('.$post->ID.');return false;">'.__('Use this', 'custom-field-template').'</a>';
  198. return $form_fields;
  199. }
  200. function custom_field_template_add_enctype($buffer) {
  201. $buffer = preg_replace('/<form name="post"/', '<form enctype="multipart/form-data" name="post"', $buffer);
  202. return $buffer;
  203. }
  204. function custom_field_template_admin_head_buffer() {
  205. ob_start(array(&$this, 'custom_field_template_add_enctype'));
  206. }
  207. function custom_field_template_admin_footer_buffer() {
  208. ob_end_flush();
  209. }
  210. function has_meta( $postid ) {
  211. global $wpdb;
  212. return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, post_id FROM $wpdb->postmeta WHERE post_id = %d ORDER BY meta_key,meta_id", $postid), ARRAY_A );
  213. }
  214. function get_post_meta($post_id, $key, $single = false) {
  215. if ( !$post_id || !$key )
  216. return '';
  217. $post_id = (int) $post_id;
  218. $meta_cache = wp_cache_get($post_id, 'cft_post_meta');
  219. if ( !$meta_cache ) {
  220. if ( $meta_list = $this->has_meta( $post_id ) ) {
  221. foreach ( (array) $meta_list as $metarow) {
  222. $mpid = (int) $metarow['post_id'];
  223. $mkey = $metarow['meta_key'];
  224. $mval = $metarow['meta_value'];
  225. if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) )
  226. $cache[$mpid] = array();
  227. if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) )
  228. $cache[$mpid][$mkey] = array();
  229. $cache[$mpid][$mkey][] = $mval;
  230. }
  231. }
  232. /*foreach ( (array) $ids as $id ) {
  233. if ( ! isset($cache[$id]) )
  234. $cache[$id] = array();
  235. }*/
  236. if ( !empty($cache) && is_array($cache) ) :
  237. foreach ( (array) array_keys($cache) as $post)
  238. wp_cache_set($post, $cache[$post], 'cft_post_meta');
  239. $meta_cache = wp_cache_get($post_id, 'cft_post_meta');
  240. endif;
  241. }
  242. if ( isset($meta_cache[$key]) ) {
  243. if ( $single ) {
  244. return maybe_unserialize( $meta_cache[$key][0] );
  245. } else {
  246. return array_map('maybe_unserialize', $meta_cache[$key]);
  247. }
  248. }
  249. return '';
  250. }
  251. function add_quick_edit_custom_box($column_name, $type) {
  252. if( $column_name == 'custom-fields' ) :
  253. global $wp_version;
  254. $options = $this->get_custom_field_template_data();
  255. if( $options == null)
  256. return;
  257. if ( !$options['css'] ) {
  258. $this->install_custom_field_template_css();
  259. $options = $this->get_custom_field_template_data();
  260. }
  261. $out .= '<fieldset style="clear:both;">' . "\n";
  262. $out .= '<div class="inline-edit-group">';
  263. $out .= '<style type="text/css">' . "\n" .
  264. '<!--' . "\n";
  265. $out .= $options['css'] . "\n";
  266. $out .= '-->' . "\n" .
  267. '</style>';
  268. if ( count($options['custom_fields'])>1 ) {
  269. $out .= '<select id="custom_field_template_select">';
  270. for ( $i=0; $i < count($options['custom_fields']); $i++ ) {
  271. if ( $i == $options['posts'][$_REQUEST['post']] ) {
  272. $out .= '<option value="' . $i . '" selected="selected">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
  273. } else
  274. $out .= '<option value="' . $i . '">' . stripcslashes($options['custom_fields'][$i]['title']) . '</option>';
  275. }
  276. $out .= '</select>';
  277. $out .= '<input type="button" class="button" value="' . __('Load', 'custom-field-template') . '" onclick="var post = jQuery(this).parent().parent().parent().parent().attr(\'id\').replace(\'edit-\',\'\'); var cftloading_select = function() {jQuery.ajax({type: \'GET\', url: \'?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id=\'+jQuery(\'#custom_field_template_select\').val()+\'&post=\'+post, success: function(html) {jQuery(\'#cft\').html(html);}});};cftloading_select(post);" />';
  278. }
  279. $out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />';
  280. $out .= '<div id="cft" class="cft">';
  281. $out .= '</div>';
  282. $out .= '</div>' . "\n";
  283. $out .= '</fieldset>' . "\n";
  284. echo $out;
  285. endif;
  286. }
  287. function custom_field_template_admin_head() {
  288. global $wp_version;
  289. $options = $this->get_custom_field_template_data();
  290. if ( !defined('WP_PLUGIN_DIR') )
  291. $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
  292. else
  293. $plugin_dir = dirname( plugin_basename(__FILE__) );
  294. echo '<link rel="stylesheet" type="text/css" href="' . wp_guess_url() . '/' . PLUGINDIR . '/' . $plugin_dir . '/js/datePicker.css" />'."\n";
  295. if ( !empty($options['custom_field_template_use_validation']) ) :
  296. if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || (is_object($post) && $post->post_type=='page') ) :
  297. ?>
  298. <script type="text/javascript">
  299. // <![CDATA[
  300. jQuery(document).ready(function() {
  301. jQuery("#post").validate();
  302. });
  303. //-->
  304. </script>
  305. <style type="text/css">
  306. <!--
  307. label.error { color:#FF0000; }
  308. -->
  309. </style>
  310. <?php
  311. endif;
  312. endif;
  313. if ( substr($wp_version, 0, 3) >= '2.7' && is_user_logged_in() && ( strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php') ) && !strstr($_SERVER['REQUEST_URI'], 'page=') ) {
  314. ?>
  315. <script type="text/javascript">
  316. // <![CDATA[
  317. jQuery(document).ready(function() {
  318. jQuery('.hide-if-no-js-cft').show();
  319. jQuery('.hide-if-js-cft').hide();
  320. inlineEditPost.addEvents = function(r) {
  321. r.each(function() {
  322. var row = jQuery(this);
  323. jQuery('a.editinline', row).click(function() {
  324. inlineEditPost.edit(this);
  325. post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-','');
  326. inlineEditPost.cft_load(post_id);
  327. return false;
  328. });
  329. });
  330. }
  331. inlineEditPost.save = function(id) {
  332. if( typeof(id) == 'object' )
  333. id = this.getId(id);
  334. jQuery('table.widefat .inline-edit-save .waiting').show();
  335. var params = {
  336. action: 'inline-save',
  337. post_type: <?php if ( substr($wp_version, 0, 3) >= '3.0' ) echo 'typenow'; else echo 'this.type'; ?>,
  338. post_ID: id,
  339. edit_date: 'true'
  340. };
  341. var fields = jQuery('#edit-'+id+' :input').fieldSerialize();
  342. params = fields + '&' + jQuery.param(params);
  343. // make ajax request
  344. jQuery.post('admin-ajax.php', params,
  345. function(r) {
  346. jQuery('table.widefat .inline-edit-save .waiting').hide();
  347. if (r) {
  348. if ( -1 != r.indexOf('<tr') ) {
  349. jQuery(inlineEditPost.what+id).remove();
  350. jQuery('#edit-'+id).before(r).remove();
  351. var row = jQuery(inlineEditPost.what+id);
  352. row.hide();
  353. if ( 'draft' == jQuery('input[name="post_status"]').val() )
  354. row.find('td.column-comments').hide();
  355. row.find('.hide-if-no-js').removeClass('hide-if-no-js');
  356. jQuery('.hide-if-no-js-cft').show();
  357. jQuery('.hide-if-js-cft').hide();
  358. inlineEditPost.addEvents(row);
  359. row.fadeIn();
  360. } else {
  361. r = r.replace( /<.[^<>]*?>/g, '' );
  362. jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
  363. }
  364. } else {
  365. jQuery('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
  366. }
  367. }
  368. , 'html');
  369. return false;
  370. }
  371. jQuery('.editinline').click(function () {post_id = jQuery(this).parent().parent().parent().parent().attr('id').replace('post-',''); inlineEditPost.cft_load(post_id);});
  372. inlineEditPost.cft_load = function (post_id) {
  373. jQuery.ajax({type: 'GET', url: '?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&post='+post_id, success: function(html) {jQuery('#cft').html(html);}});
  374. };
  375. });
  376. //-->
  377. </script>
  378. <style type="text/css">
  379. <!--
  380. div.cft_list p.key { font-weight:bold; margin: 0; }
  381. div.cft_list p.value { margin: 0 0 0 10px; }
  382. .cft-actions { visibility: hidden; padding: 2px 0 0; }
  383. tr:hover .cft-actions { visibility: visible; }
  384. .inline-edit-row fieldset label { display:inline; }
  385. label.error { color:#FF0000; }
  386. -->
  387. </style>
  388. <?php
  389. }
  390. }
  391. function custom_field_template_dbx_post_sidebar() {
  392. global $wp_version;
  393. $options = $this->get_custom_field_template_data();
  394. if ( !empty($options['custom_field_template_deploy_box']) ) :
  395. $suffix = '"+win.jQuery("#cft_current_template").val()+"';
  396. else :
  397. $suffix = '';
  398. endif;
  399. $out = '';
  400. $out .= '<script type="text/javascript">' . "\n" .
  401. '// <![CDATA[' . "\n";
  402. $out .= 'function cft_use_this(file_id) {
  403. var win = window.dialogArguments || opener || parent || top;
  404. win.jQuery("#"+win.jQuery("#cft_clicked_id").val()+"_hide").val(file_id);
  405. var fields = win.jQuery("#cft'.$suffix.' :input").fieldSerialize();
  406. win.jQuery.ajax({type: "POST", url: "?page=custom-field-template/custom-field-template.php&cft_mode=ajaxsave&post="+win.jQuery(\'#post_ID\').val()+"&custom-field-template-verify-key="+win.jQuery("#custom-field-template-verify-key").val(), data: fields, success: function() {win.jQuery.ajax({type: "GET", url: "?page=custom-field-template/custom-field-template.php&cft_mode=ajaxload&id="+win.jQuery("#cft_current_template").val()+"&post="+win.jQuery(\'#post_ID\').val(), success: function(html) {win.jQuery("#cft'.$suffix.'").html(html);win.tb_remove();}});}});
  407. }';
  408. $out .= 'function qt_set(new_id) { eval("qt_"+new_id+" = new QTags(\'qt_"+new_id+"\', \'"+new_id+"\', \'editorcontainer_"+new_id+"\', \'more\');");}';
  409. $out .= 'function _edInsertContent(myField, myValue) {
  410. var sel, startPos, endPos, scrollTop;
  411. //IE support
  412. if (document.selection) {
  413. myField.focus();
  414. sel = document.selection.createRange();
  415. sel.text = myValue;
  416. myField.focus();
  417. }
  418. //MOZILLA/NETSCAPE support
  419. else if (myField.selectionStart || myField.selectionStart == "0") {
  420. startPos = myField.selectionStart;
  421. endPos = myField.selectionEnd;
  422. scrollTop = myField.scrollTop;
  423. myField.value = myField.value.substring(0, startPos)
  424. + myValue
  425. + myField.value.substring(endPos, myField.value.length);
  426. myField.focus();
  427. myField.selectionStart = startPos + myValue.length;
  428. myField.selectionEnd = startPos + myValue.length;
  429. myField.scrollTop = scrollTop;
  430. } else {
  431. myField.value += myValue;
  432. myField.focus();
  433. }
  434. }';
  435. $out .= 'function send_to_custom_field(h) {' . "\n" .
  436. ' if ( tmpFocus ) ed = tmpFocus;' . "\n" .
  437. ' else if ( typeof tinyMCE == "undefined" ) ed = document.getElementById("content");' . "\n" .
  438. ' else { ed = tinyMCE.get("content"); if(ed) {if(!ed.isHidden()) isTinyMCE = true;}}' . "\n" .
  439. ' if ( typeof tinyMCE != "undefined" && isTinyMCE && !ed.isHidden() ) {' . "\n" .
  440. ' ed.focus();' . "\n" .
  441. ' if ( tinymce.isIE && ed.windowManager.insertimagebookmark )' . "\n" .
  442. ' ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);' . "\n" .
  443. ' if ( h.indexOf("[caption") === 0 ) {' . "\n" .
  444. ' if ( ed.plugins.wpeditimage )' . "\n" .
  445. ' h = ed.plugins.wpeditimage._do_shcode(h);' . "\n" .
  446. ' } else if ( h.indexOf("[gallery") === 0 ) {' . "\n" .
  447. ' if ( ed.plugins.wpgallery )' . "\n" .
  448. ' h = ed.plugins.wpgallery._do_gallery(h);' . "\n" .
  449. ' } else if ( h.indexOf("[embed") === 0 ) {' . "\n" .
  450. ' if ( ed.plugins.wordpress )' . "\n" .
  451. ' h = ed.plugins.wordpress._setEmbed(h);' . "\n" .
  452. ' }' . "\n" .
  453. ' ed.execCommand("mceInsertContent", false, h);' . "\n" .
  454. ' } else {' . "\n" .
  455. ' if ( tmpFocus ) _edInsertContent(tmpFocus, h);' . "\n" .
  456. ' else edInsertContent(edCanvas, h);' . "\n" .
  457. ' }' . "\n";
  458. if ( empty($options['custom_field_template_use_multiple_insert']) ) {
  459. $out .= ' tb_remove();' . "\n" .
  460. ' tmpFocus = undefined;' . "\n" .
  461. ' isTinyMCE = false;' . "\n";
  462. }
  463. if ( substr($wp_version, 0, 3) < '3.3' ) :
  464. $qt_position = 'jQuery(\'#editorcontainer_\'+id).prev()';
  465. $load_tinyMCE = 'tinyMCE.execCommand(' . "'mceAddControl'" . ',false, id);';
  466. else :
  467. $qt_position = 'jQuery(\'#qt_\'+id+\'_toolbar\')';
  468. $load_tinyMCE = 'var ed = new tinyMCE.Editor(id, tinyMCEPreInit.mceInit[\'content\']); ed.render();';
  469. endif;
  470. $out .= '}' . "\n" .
  471. 'jQuery(".thickbox").bind("click", function (e) {' . "\n" .
  472. ' tmpFocus = undefined;' . "\n" .
  473. ' isTinyMCE = false;' . "\n" .
  474. '});' . "\n" .
  475. 'var isTinyMCE;' . "\n" .
  476. 'var tmpFocus;' . "\n" .
  477. 'function focusTextArea(id) {' . "\n" .
  478. ' jQuery(document).ready(function() {' . "\n" .
  479. ' if ( typeof tinyMCE != "undefined" ) {' . "\n" .
  480. ' var elm = tinyMCE.get(id);' . "\n" .
  481. ' }' . "\n" .
  482. ' if ( ! elm || elm.isHidden() ) {' . "\n" .
  483. ' elm = document.getElementById(id);' . "\n" .
  484. ' isTinyMCE = false;' . "\n" .
  485. ' }else isTinyMCE = true;' . "\n" .
  486. ' tmpFocus = elm' . "\n" .
  487. ' elm.focus();' . "\n" .
  488. ' if (elm.createTextRange) {' . "\n" .
  489. ' var range = elm.createTextRange();' . "\n" .
  490. ' range.move("character", elm.value.length);' . "\n" .
  491. ' range.select();' . "\n" .
  492. ' } else if (elm.setSelectionRange) {' . "\n" .
  493. ' elm.setSelectionRange(elm.value.length, elm.value.length);' . "\n" .
  494. ' }' . "\n" .
  495. ' });' . "\n" .
  496. '}' . "\n" .
  497. 'function switchMode(id) {' . "\n" .
  498. ' var ed = tinyMCE.get(id);' . "\n" .
  499. ' if ( ! ed || ed.isHidden() ) {' . "\n" .
  500. ' document.getElementById(id).value = switchEditors.wpautop(document.getElementById(id).value);' . "\n" .
  501. ' if ( ed ) { '.$qt_position.'.hide(); ed.show(); }' . "\n" .
  502. ' else {'.$load_tinyMCE.'}' . "\n" .
  503. ' } else {' . "\n" .
  504. ' ed.hide(); '.$qt_position.'.show(); document.getElementById(id).style.color="#000000";' . "\n" .
  505. ' }' . "\n" .
  506. '}' . "\n";
  507. $out .= 'function thickbox(link) {' . "\n" .
  508. ' var t = link.title || link.name || null;' . "\n" .
  509. ' var a = link.href || link.alt;' . "\n" .
  510. ' var g = link.rel || false;' . "\n" .
  511. ' tb_show(t,a,g);' . "\n" .
  512. ' link.blur();' . "\n" .
  513. ' return false;' . "\n" .
  514. '}' . "\n";
  515. $out .= '//--></script>';
  516. $out .= '<input type="hidden" id="cft_current_template" value="" />';
  517. $out .= '<input type="hidden" id="cft_clicked_id" value="" />';
  518. $out .= '<input type="hidden" name="custom-field-template-verify-key" id="custom-field-template-verify-key" value="' . wp_create_nonce('custom-field-template') . '" />';
  519. $out .= '<style type="text/css">' . "\n" .
  520. '<!--' . "\n";
  521. $out .= $options['css'] . "\n";
  522. $out .= '.editorcontainer { overflow:hidden; background:#FFFFFF; }
  523. .content { width:98%; }
  524. .editorcontainer .content { padding: 6px; line-height: 150%; border: 0 none; outline: none; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; -khtml-box-sizing: border-box; box-sizing: border-box; }
  525. .quicktags { border:1px solid #DFDFDF; border-collapse: separate; -moz-border-radius: 6px 6px 0 0; -webkit-border-top-right-radius: 6px; -webkit-border-top-left-radius: 6px; -khtml-border-top-right-radius: 6px; -khtml-border-top-left-radius: 6px; border-top-right-radius: 6px; border-top-left-radius: 6px; }
  526. .quicktags { padding: 0; margin-bottom: -1px; border-bottom-width:1px; background-image: url("images/ed-bg.gif"); background-position: left top; background-repeat: repeat; }
  527. .quicktags div div { padding: 2px 4px 0; }
  528. .quicktags div div input { margin: 3px 1px 4px; line-height: 18px; display: inline-block; border-width: 1px; border-style: solid; min-width: 26px; padding: 2px 4px; font-size: 12px; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; background:#FFFFFF url(images/fade-butt.png) repeat-x scroll 0 -2px; overflow: visible; }' . "\n";
  529. $out .= '-->' . "\n" .
  530. '</style>';
  531. echo $out;
  532. }
  533. function add_manage_posts_custom_column($column_name, $post_id) {
  534. $data = get_post_custom($post_id);
  535. if( is_array($data) && $column_name == 'custom-fields' ) :
  536. $flag = 0;
  537. $content = $output = '';
  538. foreach($data as $key => $val) :
  539. if ( substr($key, 0, 1) == '_' || !$val[0] ) continue;
  540. $content .= '<p class="key">' . $key . '</p>' . "\n";
  541. foreach($val as $val2) :
  542. $val2 = htmlspecialchars($val2, ENT_QUOTES);
  543. if ( $flag ) :
  544. $content .= '<p class="value">' . $val2 . '</p>' . "\n";
  545. else :
  546. if ( function_exists('mb_strlen') ) :
  547. if ( mb_strlen($val2) > 50 ) :
  548. $before_content = mb_substr($val2, 0, 50);
  549. $after_content = mb_substr($val2, 50);
  550. $content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n";
  551. $flag = 1;
  552. else :
  553. $content .= '<p class="value">' . $val2 . '</p>' . "\n";
  554. endif;
  555. else :
  556. if ( strlen($val2) > 50 ) :
  557. $before_content = substr($val2, 0, 50);
  558. $after_content = substr($val2, 50);
  559. $content .= '<p class="value">' . $before_content . '[[[break]]]' . '<p class="value">' . $after_content . '</p>' . "\n";
  560. $flag = 1;
  561. else :
  562. $content .= '<p class="value">' . $val2 . '</p>' . "\n";
  563. endif;
  564. endif;
  565. endif;
  566. endforeach;
  567. endforeach;
  568. if ( $content ) :
  569. $content = preg_replace('/([^\n]+)\n([^\n]+)\n([^\n]+)\n([^\n]+)\n([^$]+)/', '\1\2\3\4[[[break]]]\5', $content);
  570. @list($before, $after) = explode('[[[break]]]', $content, 2);
  571. $after = preg_replace('/\[\[\[break\]\]\]/', '', $after);
  572. $output .= '<div class="cft_list">';
  573. $output .= balanceTags($before, true);
  574. if ( $after ) :
  575. $output .= '<span class="hide-if-no-js-cft"><a href="javascript:void(0);" onclick="jQuery(this).parent().next().show(); jQuery(this).parent().next().next().show(); jQuery(this).parent().hide();">... ' . __('read more', 'custom-field-template') . '</a></span>';
  576. $output .= '<span class="hide-if-js-cft">' . balanceTags($after, true) . '</span>';
  577. $output .= '<span style="display:none;"><a href="javascript:void(0);" onclick="jQuery(this).parent().prev().hide(); jQuery(this).parent().prev().prev().show(); jQuery(this).parent().hide();">[^]</a></span>';
  578. endif;
  579. $output .= '</div>';
  580. else :
  581. $output .= '&nbsp;';
  582. endif;
  583. endif;
  584. if ( isset($output) ) echo $output;
  585. }
  586. function add_manage_posts_columns($columns) {
  587. $new_columns = array();
  588. foreach($columns as $key => $val) :
  589. $new_columns[$key] = $val;
  590. if ( $key == 'tags' )
  591. $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template');
  592. endforeach;
  593. return $new_columns;
  594. }
  595. function add_manage_pages_columns($columns) {
  596. $new_columns = array();
  597. foreach($columns as $key => $val) :
  598. $new_columns[$key] = $val;
  599. if ( $key == 'author' )
  600. $new_columns['custom-fields'] = __('Custom Fields', 'custom-field-template');
  601. endforeach;
  602. return $new_columns;
  603. }
  604. function media_send_to_custom_field($html) {
  605. $out = '<script type="text/javascript">' . "\n" .
  606. ' /* <![CDATA[ */' . "\n" .
  607. ' var win = window.dialogArguments || opener || parent || top;' . "\n" .
  608. ' if ( typeof win.send_to_custom_field == "function" ) ' . "\n" .
  609. ' win.send_to_custom_field("' . addslashes($html) . '");' . "\n" .
  610. ' else ' . "\n" .
  611. ' win.send_to_editor("' . addslashes($html) . '");' . "\n" .
  612. '/* ]]> */' . "\n" .
  613. '</script>' . "\n";
  614. echo $out;
  615. exit();
  616. /*if ($options['custom_field_template_use_multiple_insert']) {
  617. return;
  618. } else {
  619. exit();
  620. }*/
  621. }
  622. function wpaq_filter_plugin_actions($links, $file){
  623. static $this_plugin;
  624. if( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
  625. if( $file == $this_plugin ){
  626. $settings_link = '<a href="options-general.php?page=custom-field-template.php">' . __('Settings') . '</a>';
  627. $links = array_merge( array($settings_link), $links);
  628. }
  629. return $links;
  630. }
  631. function custom_field_template_admin_scripts() {
  632. global $post;
  633. $options = $this->get_custom_field_template_data();
  634. if ( !defined('WP_PLUGIN_DIR') )
  635. $plugin_dir = str_replace( ABSPATH, '', dirname(__FILE__) );
  636. else
  637. $plugin_dir = dirname( plugin_basename(__FILE__) );
  638. wp_enqueue_script( 'jquery' );
  639. wp_enqueue_script( 'jquery-form' );
  640. wp_enqueue_script( 'bgiframe', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.bgiframe.js', array('jquery') ) ;
  641. wp_enqueue_script( 'textarearesizer', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.textarearesizer.js', array('jquery') );
  642. if( strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php') || (is_object($post) && $post->post_type=='page') ) :
  643. wp_enqueue_script('date', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/date.js', array('jquery') );
  644. wp_enqueue_script('datePicker', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.datePicker.js', array('jquery') );
  645. wp_enqueue_script('editor');
  646. wp_enqueue_script('quicktags');
  647. if ( !empty($options['custom_field_template_use_validation']) ) :
  648. wp_enqueue_script( 'jquery-validate', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/jquery.validate.js', array('jquery') );
  649. wp_enqueue_script( 'additional-methods', '/' . PLUGINDIR . '/' . $plugin_dir . '/js/additional-methods.js', array('jquery') );
  650. if ( file_exists(ABSPATH . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG . '.js') )
  651. wp_enqueue_script( 'messages_' . WPLANG, '/' . PLUGINDIR . '/' . $plugin_dir . '/js/messages_' . WPLANG .'.js', array('jquery') );
  652. endif;
  653. endif;
  654. }
  655. function install_custom_field_template_data() {
  656. $options['custom_field_template_before_list'] = '<ul>';
  657. $options['custom_field_template_after_list'] = '</ul>';
  658. $options['custom_field_template_before_value'] = '<li>';
  659. $options['custom_field_template_after_value'] = '</li>';
  660. $options['custom_fields'][0]['title'] = __('Default Template', 'custom-field-template');
  661. $options['custom_fields'][0]['content'] = '[Plan]
  662. type = text
  663. size = 35
  664. label = Where are you going to go?
  665. [Plan]
  666. type = textfield
  667. size = 35
  668. hideKey = true
  669. [Favorite Fruits]
  670. type = checkbox
  671. value = apple # orange # banana # grape
  672. default = orange # grape
  673. [Miles Walked]
  674. type = radio
  675. value = 0-9 # 10-19 # 20+
  676. default = 10-19
  677. clearButton = true
  678. [Temper Level]
  679. type = select
  680. value = High # Medium # Low
  681. default = Low
  682. [Hidden Thought]
  683. type = textarea
  684. rows = 4
  685. cols = 40
  686. tinyMCE = true
  687. htmlEditor = true
  688. mediaButton = true
  689. [File Upload]
  690. type = file';
  691. $options['shortcode_format'][0] = '<table class="cft">
  692. <tbody>
  693. <tr>
  694. <th>Plan</th><td colspan="3">[Plan]</td>
  695. </tr>
  696. <tr>
  697. <th>Favorite Fruits</th><td>[Favorite Fruits]</td>
  698. <th>Miles Walked</th><td>[Miles Walked]</td>
  699. </tr>
  700. <tr>
  701. <th>Temper Level</th><td colspan="3">[Temper Level]</td>
  702. </tr>
  703. <tr>
  704. <th>Hidden Thought</th><td colspan="3">[Hidden Thought]</td>
  705. </tr>
  706. </tbody>
  707. </table>';
  708. update_option('custom_field_template_data', $options);
  709. }
  710. function install_custom_field_template_css() {
  711. $options = get_option('custom_field_template_data');
  712. $options['css'] = '.cft { overflow:hidden; }
  713. .cft:after { content:" "; clear:both; height:0; display:block; visibility:hidden; }
  714. .cft dl { margin:10px 0; }
  715. .cft dl:after { content:" "; clear:both; height:0; display:block; visibility:hidden; }
  716. .cft dt { width:20%; clear:both; float:left; display:inline; font-weight:bold; text-align:center; }
  717. .cft dt .hideKey { visibility:hidden; }
  718. .cft dd { margin:0 0 0 21%; }
  719. .cft dd p.label { font-weight:bold; margin:0; }
  720. .cft_instruction { margin:10px; }
  721. .cft fieldset { border:1px solid #CCC; margin:5px; padding:5px; }
  722. .cft .dl_checkbox { margin:0; }
  723. ';
  724. update_option('custom_field_template_data', $options);
  725. }
  726. function get_custom_field_template_data() {
  727. $options = get_option('custom_field_template_data');
  728. return $options;
  729. }
  730. function custom_field_template_admin_menu() {
  731. add_options_page(__('Custom Field Template', 'custom-field-template'), __('Custom Field Template', 'custom-field-template'), 'manage_options', basename(__FILE__), array(&$this, 'custom_field_template_admin'));
  732. }
  733. function custom_field_template_get_the_excerpt($excerpt) {
  734. $options = $this->get_custom_field_template_data();
  735. if ( empty($excerpt) ) $this->is_excerpt = true;
  736. if ( !empty($options['custom_field_template_excerpt_shortcode']) ) return do_shortcode($excerpt);
  737. else return $excerpt;
  738. }
  739. function custom_field_template_the_content($content) {
  740. global $wp_query, $post, $shortcode_tags, $wp_version;
  741. $options = $this->get_custom_field_template_data();
  742. if ( $this->is_excerpt ) :
  743. $this->is_excerpt = false;
  744. return $post->post_excerpt ? $post->post_excerpt : strip_shortcodes($content);
  745. endif;
  746. if ( isset($options['hook']) && count($options['hook']) > 0 ) :
  747. $categories = get_the_category();
  748. $cats = array();
  749. foreach( $categories as $val ) :
  750. $cats[] = $val->cat_ID;
  751. endforeach;
  752. if ( !empty($options['custom_fields'][$id]['post_type']) ) :
  753. if ( substr($wp_version, 0, 3) < '3.0' ) :
  754. if ( $options['custom_fields'][$id]['post_type'] == 'post' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/page-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/page.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit-pages.php')) ) :
  755. return;
  756. endif;
  757. if ( $options['custom_fields'][$id]['post_type'] == 'page' && (strstr($_SERVER['REQUEST_URI'], 'wp-admin/post-new.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/post.php') || strstr($_SERVER['REQUEST_URI'], 'wp-admin/edit.php')) ) :
  758. return;
  759. endif;
  760. else :
  761. if ( $post->post_type!=$options['custom_fields'][$id]['post_type'] ) :
  762. return;
  763. endif;
  764. endif;
  765. endif;
  766. for ( $i=0; $i<count($options['hook']); $i++ ) :
  767. $options['hook'][$i]['content'] = stripslashes($options['hook'][$i]['content']);
  768. if ( is_feed() && !$options['hook'][$i]['feed'] ) break;
  769. if ( !empty($options['hook'][$i]['category']) ) :
  770. if ( is_category() || is_single() || is_feed() ) :
  771. if ( !empty($options['hook'][$i]['use_php']) ) :
  772. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  773. endif;
  774. $needle = explode(',', $options['hook'][$i]['category']);
  775. $needle = array_filter($needle);
  776. $needle = array_unique(array_filter(array_map('trim', $needle)));
  777. foreach ( $needle as $val ) :
  778. if ( in_array($val, $cats ) ) :
  779. if ( $options['hook'][$i]['position'] == 0 )
  780. $content .= $options['hook'][$i]['content'];
  781. elseif ( $options['hook'][$i]['position'] == 2 )
  782. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  783. else
  784. $content = $options['hook'][$i]['content'] . $content;
  785. break;
  786. endif;
  787. endforeach;
  788. endif;
  789. elseif ( $options['hook'][$i]['post_type']=='post' ) :
  790. if ( is_category() || is_single() ) :
  791. if ( !empty($options['hook'][$i]['use_php']) ) :
  792. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  793. endif;
  794. if ( $options['hook'][$i]['position'] == 0 )
  795. $content .= $options['hook'][$i]['content'];
  796. elseif ( $options['hook'][$i]['position'] == 2 )
  797. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  798. else
  799. $content = $options['hook'][$i]['content'] . $content;
  800. endif;
  801. elseif ( $options['hook'][$i]['post_type']=='page' ) :
  802. if ( is_page() ) :
  803. if ( !empty($options['hook'][$i]['use_php']) ) :
  804. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  805. endif;
  806. if ( $options['hook'][$i]['position'] == 0 )
  807. $content .= $options['hook'][$i]['content'];
  808. elseif ( $options['hook'][$i]['position'] == 2 )
  809. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  810. else
  811. $content = $options['hook'][$i]['content'] . $content;
  812. endif;
  813. elseif ( $options['hook'][$i]['custom_post_type'] ) :
  814. $custom_post_type = explode(',', $options['hook'][$i]['custom_post_type']);
  815. $custom_post_type = array_filter( $custom_post_type );
  816. array_walk( $custom_post_type, create_function('&$v', '$v = trim($v);') );
  817. if ( in_array($post->post_type, $custom_post_type) ) :
  818. if ( !empty($options['hook'][$i]['use_php']) ) :
  819. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  820. endif;
  821. if ( $options['hook'][$i]['position'] == 0 )
  822. $content .= $options['hook'][$i]['content'];
  823. elseif ( $options['hook'][$i]['position'] == 2 )
  824. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  825. else
  826. $content = $options['hook'][$i]['content'] . $content;
  827. endif;
  828. else :
  829. if ( !empty($options['hook'][$i]['use_php']) ) :
  830. $options['hook'][$i]['content'] = $this->EvalBuffer(stripcslashes($options['hook'][$i]['content']));
  831. endif;
  832. if ( $options['hook'][$i]['position'] == 0 )
  833. $content .= $options['hook'][$i]['content'];
  834. elseif ( $options['hook'][$i]['position'] == 2 )
  835. $content = preg_replace('/\[cfthook hook='.$i.'\]/', $options['hook'][$i]['content'], $content);
  836. else
  837. $content = $options['hook'][$i]['content'] . $content;
  838. endif;
  839. endfor;
  840. endif;
  841. return do_shortcode($content);
  842. }
  843. function custom_field_template_admin() {
  844. global $wp_version;
  845. $options = $this->get_custom_field_template_data();
  846. if( !empty($_POST["custom_field_template_set_options_submit"]) ) :
  847. unset($options['custom_fields']);
  848. $j = 0;
  849. for($i=0;$i<count($_POST["custom_field_template_content"]);$i++) {
  850. if( $_POST["custom_field_template_content"][$i] ) {
  851. if ( preg_match('/\[content\]|\[post_title\]|\[excerpt\]|\[action\]/i', $_POST["custom_field_template_content"][$i]) ) :
  852. $errormessage = __('You can not use the following words as the field key: `content`, `post_title`, and `excerpt`, and `action`.', 'custom-field-template');
  853. endif;
  854. if ( isset($_POST["custom_field_template_title"][$i]) ) $options['custom_fields'][$j]['title'] = $_POST["custom_field_template_title"][$i];
  855. if ( isset($_POST["custom_field_template_content"][$i]) ) $options['custom_fields'][$j]['content'] = $_POST["custom_field_template_content"][$i];
  856. if ( isset($_POST["custom_field_template_instruction"][$i]) ) $options['custom_fields'][$j]['instruction'] = $_POST["custom_field_template_instruction"][$i];
  857. if ( isset($_POST["custom_field_template_category"][$i]) ) $options['custom_fields'][$j]['category'] = $_POST["custom_field_template_category"][$i];
  858. if ( isset($_POST["custom_field_template_post"][$i]) ) $options['custom_fields'][$j]['post'] = $_POST["custom_field_template_post"][$i];
  859. if ( isset($_POST["custom_field_template_post_type"][$i]) ) $options['custom_fields'][$j]['post_type'] = $_POST["custom_field_template_post_type"][$i];
  860. if ( isset($_POST["custom_field_template_custom_post_type"][$i]) ) $options['custom_fields'][$j]['custom_post_type'] = $_POST["custom_field_template_custom_post_type"][$i];
  861. if ( isset($_POST["custom_field_template_template_files"][$i]) ) $options['custom_fields'][$j]['template_files'] = $_POST["custom_field_template_template_files"][$i];
  862. if ( isset($_POST["custom_field_template_disable"][$i]) ) $options['custom_fields'][$j]['disable'] = $_POST["custom_field_template_disable"][$i];
  863. $j++;
  864. }
  865. }
  866. update_option('custom_field_template_data', $options);
  867. $message = __('Options updated.', 'custom-field-template');
  868. elseif( !empty($_POST["custom_field_template_global_settings_submit"]) ) :
  869. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  870. $options['custom_field_template_use_multiple_insert'] = isset($_POST['custom_field_template_use_multiple_insert']) ? 1 : '';
  871. $options['custom_field_template_use_wpautop'] = isset($_POST['custom_field_template_use_wpautop']) ? 1 : '';
  872. $options['custom_field_template_use_autosave'] = isset($_POST['custom_field_template_use_autosave']) ? 1 : '';
  873. $options['custom_field_template_use_disable_button'] = isset($_POST['custom_field_template_use_disable_button']) ? 1 : '';
  874. $options['custom_field_template_disable_initialize_button'] = isset($_POST['custom_field_template_disable_initialize_button']) ? 1 : '';
  875. $options['custom_field_template_disable_save_button'] = isset($_POST['custom_field_template_disable_save_button']) ? 1 : '';
  876. $options['custom_field_template_disable_default_custom_fields'] = isset($_POST['custom_field_template_disable_default_custom_fields']) ? 1 : '';
  877. $options['custom_field_template_disable_quick_edit'] = isset($_POST['custom_field_template_disable_quick_edit']) ? 1 : '';
  878. $options['custom_field_template_disable_custom_field_column'] = isset($_POST['custom_field_template_disable_custom_field_column']) ? 1 : '';
  879. $options['custom_field_template_replace_the_title'] = isset($_POST['custom_field_template_replace_the_title']) ? 1 : '';
  880. $options['custom_field_template_deploy_box'] = isset($_POST['custom_field_template_deploy_box']) ? 1 : '';
  881. if ( !empty($options['custom_field_template_deploy_box']) ) :
  882. $options['css'] = preg_replace('/#cft /', '.cft ', $options['css']);
  883. $options['css'] = preg_replace('/#cft_/', '.cft_', $options['css']);
  884. endif;
  885. $options['custom_field_template_widget_shortcode'] = isset($_POST['custom_field_template_widget_shortcode']) ? 1 : '';
  886. $options['custom_field_template_excerpt_shortcode'] = isset($_POST['custom_field_template_excerpt_shortcode']) ? 1 : '';
  887. $options['custom_field_template_use_validation'] = isset($_POST['custom_field_template_use_validation']) ? 1 : '';
  888. $options['custom_field_template_before_list'] = isset($_POST['custom_field_template_before_list']) ? $_POST['custom_field_template_before_list'] : '';
  889. $options['custom_field_template_after_list'] = isset($_POST['custom_field_template_after_list']) ? $_POST['custom_field_template_after_list'] : '';
  890. $options['custom_field_template_before_value'] = isset($_POST['custom_field_template_before_value']) ? $_POST['custom_field_template_before_value'] : '';
  891. $options['custom_field_template_after_value'] = isset($_POST['custom_field_template_after_value']) ? $_POST['custom_field_template_after_value'] : '';
  892. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  893. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  894. $options['custom_field_template_replace_keys_by_labels'] = isset($_POST['custom_field_template_replace_keys_by_labels']) ? 1 : '';
  895. $options['custom_field_template_disable_ad'] = isset($_POST['custom_field_template_disable_ad']) ? 1 : '';
  896. update_option('custom_field_template_data', $options);
  897. $message = __('Options updated.', 'custom-field-template');
  898. elseif ( !empty($_POST['custom_field_template_css_submit']) ) :
  899. $options['css'] = $_POST['custom_field_template_css'];
  900. update_option('custom_field_template_data', $options);
  901. $message = __('Options updated.', 'custom-field-template');
  902. elseif ( !empty($_POST['custom_field_template_shortcode_format_submit']) ) :
  903. unset($options['shortcode_format'], $options['shortcode_format_use_php']);
  904. $j = 0;
  905. for($i=0;$i<count($_POST["custom_field_template_shortcode_format"]);$i++) {
  906. if( $_POST["custom_field_template_shortcode_format"][$i] ) :
  907. $options['shortcode_format'][$j] = $_POST["custom_field_template_shortcode_format"][$i];
  908. $options['shortcode_format_use_php'][$j] = $_POST["custom_field_template_shortcode_format_use_php"][$i];
  909. $j++;
  910. endif;
  911. }
  912. update_option('custom_field_template_data', $options);
  913. $message = __('Options updated.', 'custom-field-template');
  914. elseif ( !empty($_POST['custom_field_template_php_submit']) ) :
  915. unset($options['php']);
  916. for($i=0;$i<count($_POST["custom_field_template_php"]);$i++) {
  917. if( $_POST["custom_field_template_php"][$i] )
  918. $options['php'][] = $_POST["custom_field_template_php"][$i];
  919. }
  920. update_option('custom_field_template_data', $options);
  921. $message = __('Options updated.', 'custom-field-template');
  922. elseif( !empty($_POST["custom_field_template_hook_submit"]) ) :
  923. unset($options['hook']);
  924. $j = 0;
  925. for($i=0;$i<count($_POST["custom_field_template_hook_content"]);$i++) {
  926. if( $_POST["custom_field_template_hook_content"][$i] ) {
  927. $options['hook'][$j]['position'] = $_POST["custom_field_template_hook_position"][$i];
  928. $options['hook'][$j]['content'] = $_POST["custom_field_template_hook_content"][$i];
  929. $options['hook'][$j]['custom_post_type'] = preg_replace('/\s/', '', $_POST["custom_field_template_hook_custom_post_type"][$i]);
  930. $options['hook'][$j]['category'] = preg_replace('/\s/', '', $_POST["custom_field_template_hook_category"][$i]);
  931. $options['hook'][$j]['use_php'] = $_POST["custom_field_template_hook_use_php"][$i];
  932. $options['hook'][$j]['feed'] = $_POST["custom_field_template_hook_feed"][$i];

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