PageRenderTime 40ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://gitlab.com/f3z0/tc-site
PHP | 4168 lines | 3660 code | 434 blank | 74 comment | 1300 complexity | a8458803db6987638096932bde117630 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, Apache-2.0, LGPL-2.1

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

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