WYSIJA_help

The MailPoet Newsletters WYSIJA help class.

Defined (1)

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

/core/base.php  
  1. class WYSIJA_help extends WYSIJA_object{ 
  2. var $controller = null; 
  3.  
  4. static $admin_body_class_runner = false; 
  5.  
  6. function __construct() { 
  7. add_action( 'widgets_init', array( $this, 'widgets_init' ), 1 ); 
  8.  
  9. // Only load this when ajax is not used 
  10. if ( !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 
  11. add_action( 'init', array( $this, 'register_scripts' ), 1 ); 
  12.  
  13. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); 
  14. add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); 
  15.  
  16. function WYSIJA_help() { // TODO: remove in next version 
  17. add_action( 'widgets_init', array( $this, 'widgets_init' ), 1 ); 
  18.  
  19. // Only load this when ajax is not used 
  20. if ( !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 
  21. add_action( 'init', array( $this, 'register_scripts' ), 1 ); 
  22.  
  23. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); 
  24. add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); 
  25.  
  26. function widgets_init() { 
  27. //load the widget file 
  28. require_once(WYSIJA_WIDGETS.'wysija_nl.php'); 
  29. register_widget( 'WYSIJA_NL_Widget' ); 
  30.  
  31. public function admin_enqueue_scripts() { 
  32. if ( WYSIJA_ITF ) { 
  33. wp_enqueue_script( 'mailpoet-global' ); 
  34.  
  35. public function admin_body_class( $body_class_str ) { 
  36.  
  37. if ( WYSIJA_help::$admin_body_class_runner === true ) { 
  38. return $body_class_str; 
  39.  
  40. WYSIJA_help::$admin_body_class_runner = true; 
  41.  
  42. global $wp_version; 
  43.  
  44. $class = array(); 
  45. if ( ! empty( $body_class_str ) ) { 
  46. $class = explode( ' ', $body_class_str ); 
  47.  
  48. if ( '3.8' === $wp_version ) { 
  49. $class[] = 'mp-menu-icon-font'; 
  50.  
  51. if ( version_compare( $wp_version, '3.8', '<' ) ) { 
  52. $class[] = 'mp-menu-icon-bg'; 
  53. } else { 
  54. $class[] = 'mpoet-ui'; 
  55.  
  56. return implode( ' ', $class ); 
  57.  
  58. function register_scripts() { 
  59. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  60. $wp_language_code = $helper_toolbox->get_language_code(); 
  61. $valid_language = array( 
  62. 'ar',  
  63. 'ca',  
  64. 'cs',  
  65. 'cz',  
  66. 'da',  
  67. 'de',  
  68. 'el',  
  69. 'es',  
  70. 'et',  
  71. 'fa',  
  72. 'fi',  
  73. 'fr',  
  74. 'he',  
  75. 'hr',  
  76. 'hu',  
  77. 'id',  
  78. 'it',  
  79. 'ja',  
  80. 'lt',  
  81. 'nl',  
  82. 'no',  
  83. 'pl',  
  84. 'pt',  
  85. 'pt_BR',  
  86. 'ro',  
  87. 'ru',  
  88. 'sv',  
  89. 'tr',  
  90. 'uk',  
  91. 'vi',  
  92. 'zh_CN',  
  93. 'zh_TW',  
  94. ); 
  95.  
  96.  
  97. if ( in_array( $wp_language_code, $valid_language ) ) { 
  98. wp_register_script('wysija-validator-lang', WYSIJA_URL.'js/validate/languages/jquery.validationEngine-'.$wp_language_code.'.js', array( 'jquery' ), WYSIJA::get_version(), true ); 
  99. }else{ 
  100. wp_register_script('wysija-validator-lang', WYSIJA_URL.'js/validate/languages/jquery.validationEngine-en.js', array( 'jquery' ), WYSIJA::get_version(), true ); 
  101. wp_register_script('wysija-validator', WYSIJA_URL.'js/validate/jquery.validationEngine.js', array( 'jquery' ), WYSIJA::get_version(), true ); 
  102. wp_register_script('wysija-front-subscribers', WYSIJA_URL.'js/front-subscribers.js', array( 'jquery' ), WYSIJA::get_version(), true); 
  103.  
  104. wp_register_script('wysija-form', WYSIJA_URL.'js/forms.js', array( 'jquery' ), WYSIJA::get_version()); 
  105. wp_register_style('validate-engine-css', WYSIJA_URL.'css/validationEngine.jquery.css', array(), WYSIJA::get_version()); 
  106. wp_register_script('wysija-admin-ajax', WYSIJA_URL.'js/admin-ajax.js', array(), WYSIJA::get_version()); 
  107. wp_register_script('wysija-admin-ajax-proto', WYSIJA_URL.'js/admin-ajax-proto.js', array(), WYSIJA::get_version()); 
  108. wp_register_script( 'mailpoet-global', WYSIJA_URL.'js/admin-global.js', array( 'jquery', 'underscore' ), WYSIJA::get_version() ); 
  109.  
  110. if(defined('WYSIJA_SIDE') && WYSIJA_SIDE=='front') wp_enqueue_style('validate-engine-css'); 
  111.  
  112.  
  113.  
  114. /** 
  115. * All the ajax requests are routed through here 
  116. */ 
  117. function ajax() { 
  118.  
  119. $result_array = array(); 
  120. if( !$_REQUEST || !isset( $_REQUEST['controller'] ) || !isset( $_REQUEST['task'] ) ) { 
  121. $result_array = array( 'result' => false ); 
  122. }else{ 
  123. $plugin_requesting_ajax = 'wysija-newsletters'; 
  124.  
  125. // we override the plugin resquesting ajax if specified in the request 
  126. if( !empty( $_REQUEST['wysijaplugin'] ) ) { 
  127. $plugin_requesting_ajax = preg_replace('#[^a-z0-9\-_]#i', '', $_REQUEST['wysijaplugin']); 
  128.  
  129. // fetching the right controller 
  130. $this->controller = WYSIJA::get( $_REQUEST['controller'] , 'controller' , false, $plugin_requesting_ajax ); 
  131.  
  132. // let's make sure the requested task exist 
  133. if( method_exists( $this->controller , $_REQUEST['task'] ) ) { 
  134. $result_array['result'] = call_user_func(array($this->controller, $_REQUEST['task'])); 
  135. }else{ 
  136. $this->error( 'Method "' . esc_html($_REQUEST['task']) . '" doesn\'t exist for controller : "'.esc_html($_REQUEST['controller']) ); 
  137.  
  138. // get the appended messages triggerred during the task execution 
  139. $result_array['msgs'] = $this->getMsgs(); 
  140.  
  141. // this header will allow ajax request from the home domain, this can be a lifesaver when domain mapping is on 
  142. if(function_exists('home_url')) { 
  143. header('Access-Control-Allow-Origin: '.home_url()); 
  144.  
  145. // let's encode our response in the json format 
  146. $json_data = json_encode($result_array); 
  147.  
  148. // in some case scenarios our client will have jQuery forcing the jsonp so we need to adapt ourselves 
  149. if(isset($_REQUEST['callback'])) { 
  150. // special header for json-p 
  151. header('Content-type: application/javascript'); 
  152.  
  153. $helper_jsonp = WYSIJA::get('jsonp', 'helper'); 
  154. if($helper_jsonp->isValidCallback($_REQUEST['callback'])) { 
  155. print $_REQUEST['callback'] . '('.$json_data.');'; 
  156. } else { 
  157. // standard header for unwrapped classic json response 
  158. header('Content-type: application/json'); 
  159. print $json_data; 
  160. // our ajax response is printed, no need to let WordPress or 3rd party plugin execute more code 
  161. die();