NF_WP_Editor_Ajax

The Ninja Forms NF WP Editor Ajax class.

Defined (1)

The class is defined in the following location(s).

/deprecated/includes/admin/edit-field/li.php  
  1. class NF_WP_Editor_Ajax { 
  2.  
  3. /** 
  4. * AJAX Call Used to Generate the WP Editor 
  5. */ 
  6.  
  7. public static function output_js( $field_id = '', $editors = array() ) { 
  8.  
  9. if ( empty( $field_id ) or empty( $editors ) ) 
  10. return false; 
  11.  
  12. $mce_init = ''; 
  13. $qt_init = ''; 
  14.  
  15. foreach ( $editors as $id ) { 
  16. $mce_init .= self::get_mce_init($id); 
  17. $qt_init .= self::get_qt_init($id); 
  18.  
  19. $mce_init = '{' . trim( $mce_init, ', ' ) . '}'; 
  20. $qt_init = '{' . trim( $qt_init, ', ' ) . '}'; 
  21.  
  22. ?> 
  23. <script type="text/javascript"> 
  24. tinyMCEPreInit.mceInit = jQuery.extend( tinyMCEPreInit.mceInit, <?php echo $mce_init ?>); 
  25. tinyMCEPreInit.qtInit = jQuery.extend( tinyMCEPreInit.qtInit, <?php echo $qt_init ?>); 
  26. nf_ajax_rte_editors = <?php echo json_encode( $editors ); ?>; 
  27. </script> 
  28. <?php 
  29.  
  30. /** 
  31. * Used to retrieve the javascript settings that the editor generates 
  32. */ 
  33.  
  34. private static $mce_settings = array(); 
  35. private static $qt_settings = array(); 
  36.  
  37. public static function quicktags_settings( $qtInit, $editor_id ) { 
  38. self::$qt_settings[ $editor_id ] = $qtInit; 
  39. return $qtInit; 
  40.  
  41. public static function tiny_mce_before_init( $mceInit, $editor_id ) { 
  42. self::$mce_settings[ $editor_id ] = $mceInit; 
  43. return $mceInit; 
  44.  
  45. /** 
  46. * Code copied from _WP_Editors class (modified a little) 
  47. */ 
  48. private static function get_qt_init($editor_id) { 
  49. if ( ! empty( self::$qt_settings[ $editor_id ] ) ) { 
  50. $options = self::_parse_init( self::$qt_settings[ $editor_id ] ); 
  51. $qtInit = "'$editor_id':{$options}, "; 
  52. } else { 
  53. $qtInit = '{}'; 
  54. return $qtInit; 
  55.  
  56. private static function get_mce_init($editor_id) { 
  57. if ( !empty(self::$mce_settings[ $editor_id ]) ) { 
  58. $options = self::_parse_init( self::$mce_settings[ $editor_id ] ); 
  59. $mceInit = "'$editor_id':{$options}, "; 
  60. } else { 
  61. $mceInit = '{}'; 
  62. return $mceInit; 
  63.  
  64. private static function _parse_init($init) { 
  65. $options = ''; 
  66.  
  67. foreach ( $init as $k => $v ) { 
  68. if ( is_bool($v) ) { 
  69. $val = $v ? 'true' : 'false'; 
  70. $options .= $k . ':' . $val . ', '; 
  71. continue; 
  72. } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) { 
  73. $options .= $k . ':' . $v . ', '; 
  74. continue; 
  75. $options .= $k . ':"' . $v . '", '; 
  76.  
  77. return '{' . trim( $options, ' , ' ) . '}';