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

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

https://bitbucket.org/dkrzos/phc
PHP | 4139 lines | 3640 code | 431 blank | 68 comment | 1293 complexity | 60e8c3c8e03db0d6fad14c3fa3048630 MD5 | raw file
Possible License(s): GPL-2.0

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

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