/core/controllers/input.php

  1. <?php  
  2.  
  3. /** 
  4. * acf_controller_input 
  5. * 
  6. * This class contains the functionality for input actions used throughout ACF 
  7. * 
  8. * @type class 
  9. * @date 5/09/13 
  10. * @since 3.1.8 
  11. * 
  12. */ 
  13.  
  14. class acf_controller_input 
  15.  
  16. /** 
  17. * __construct 
  18. * 
  19. * @description:  
  20. * @since 3.1.8 
  21. * @created: 23/06/12 
  22. */ 
  23.  
  24. function __construct() 
  25. // actions 
  26. add_action('acf/input/admin_head', array($this, 'input_admin_head')); 
  27. add_action('acf/input/admin_enqueue_scripts', array($this, 'input_admin_enqueue_scripts')); 
  28.  
  29.  
  30. /** 
  31. * input_admin_head 
  32. * 
  33. * action called when rendering the head of an admin screen. Used primarily for passing PHP to JS 
  34. * 
  35. * @type action 
  36. * @date 27/05/13 
  37. * 
  38. * @param N/A 
  39. * @return N/A 
  40. */ 
  41.  
  42. function input_admin_head() 
  43. // global 
  44. global $wp_version, $post; 
  45.  
  46.  
  47. // vars 
  48. $toolbars = apply_filters( 'acf/fields/wysiwyg/toolbars', array() ); 
  49. $post_id = 0; 
  50. if( $post ) 
  51. $post_id = intval( $post->ID ); 
  52.  
  53.  
  54. // l10n 
  55. $l10n = apply_filters( 'acf/input/admin_l10n', array( 
  56. 'core' => array( 
  57. 'expand_details' => __("Expand Details", 'acf'),  
  58. 'collapse_details' => __("Collapse Details", 'acf') 
  59. ),  
  60. 'validation' => array( 
  61. 'error' => __("Validation Failed. One or more fields below are required.", 'acf') 
  62. )); 
  63.  
  64.  
  65. // options 
  66. $o = array( 
  67. 'post_id' => $post_id,  
  68. 'nonce' => wp_create_nonce( 'acf_nonce' ),  
  69. 'admin_url' => admin_url(),  
  70. 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  71. 'wp_version' => $wp_version 
  72. ); 
  73.  
  74.  
  75. // toolbars 
  76. $t = array(); 
  77.  
  78. if( is_array($toolbars) ) { foreach( $toolbars as $label => $rows ) { 
  79.  
  80. $label = sanitize_title( $label ); 
  81. $label = str_replace('-', '_', $label); 
  82.  
  83. $t[ $label ] = array(); 
  84.  
  85. if( is_array($rows) ) { foreach( $rows as $k => $v ) { 
  86.  
  87. $t[ $label ][ 'theme_advanced_buttons' . $k ] = implode(', ', $v); 
  88.  
  89. }} 
  90. }} 
  91.  
  92.  
  93. ?> 
  94. <script type="text/javascript"> 
  95. (function($) { 
  96.  
  97. // vars 
  98. acf.post_id = <?php echo is_numeric($post_id) ? $post_id : '"' . $post_id . '"'; ?>; 
  99. acf.nonce = "<?php echo wp_create_nonce( 'acf_nonce' ); ?>"; 
  100. acf.admin_url = "<?php echo admin_url(); ?>"; 
  101. acf.ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; 
  102. acf.wp_version = "<?php echo $wp_version; ?>"; 
  103.  
  104.  
  105. // new vars 
  106. acf.o = <?php echo json_encode( $o ); ?>; 
  107. acf.l10n = <?php echo json_encode( $l10n ); ?>; 
  108. acf.fields.wysiwyg.toolbars = <?php echo json_encode( $t ); ?>; 
  109.  
  110. })(jQuery);  
  111. </script> 
  112. <?php 
  113.  
  114.  
  115.  
  116. /** 
  117. * input_admin_enqueue_scripts 
  118. * 
  119. * @description:  
  120. * @since: 3.6 
  121. * @created: 30/01/13 
  122. */ 
  123.  
  124. function input_admin_enqueue_scripts() 
  125.  
  126. // scripts 
  127. wp_enqueue_script(array( 
  128. 'jquery',  
  129. 'jquery-ui-core',  
  130. 'jquery-ui-tabs',  
  131. 'jquery-ui-sortable',  
  132. 'wp-color-picker',  
  133. 'thickbox',  
  134. 'media-upload',  
  135. 'acf-input',  
  136. 'acf-datepicker',  
  137. )); 
  138.  
  139.  
  140. // 3.5 media gallery 
  141. if( function_exists('wp_enqueue_media') && !did_action( 'wp_enqueue_media' )) 
  142. wp_enqueue_media(); 
  143.  
  144.  
  145. // styles 
  146. wp_enqueue_style(array( 
  147. 'thickbox',  
  148. 'wp-color-picker',  
  149. 'acf-global',  
  150. 'acf-input',  
  151. 'acf-datepicker',  
  152. )); 
  153.  
  154.  
  155. new acf_controller_input(); 
  156.  
  157. ?> 
.