WYSIJA_help_backloader

Class managing the admin vital part to integrate wordpress.

Defined (1)

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

/helpers/backloader.php  
  1. class WYSIJA_help_backloader extends WYSIJA_help{ 
  2.  
  3. var $jsVariables = ''; 
  4.  
  5. function __construct() { 
  6. parent::__construct(); 
  7.  
  8. /** 
  9. * @param type $controller 
  10. */ 
  11. function init( &$controller ) { 
  12. wp_enqueue_style( 'wysija-admin-css', WYSIJA_URL . 'css/admin.css', array(), WYSIJA::get_version() ); 
  13. wp_enqueue_script( 'wysija-admin', WYSIJA_URL . 'js/admin.js', array( 'jquery' ), true, WYSIJA::get_version() ); 
  14.  
  15. /** default script on all wysija interfaces in admin */ 
  16. wp_enqueue_script( 'wysija-admin-if ', WYSIJA_URL . 'js/admin-wysija.js', array( 'jquery' ), WYSIJA::get_version() ); 
  17.  
  18. // TO IMPROVE: This has NOTHING TO DO HERE. It has to be moved to the subscribers controller 
  19. if ( ! $controller->jsTrans ) { 
  20. $controller->jsTrans['selecmiss'] = __( 'Please make a selection first!', WYSIJA ); 
  21. $controller->jsTrans['suredelete'] = __( 'Deleting a list will not delete any subscribers.', WYSIJA ); 
  22.  
  23. $controller->jsTrans['sure_to_switch_package'] = __( 'Do you want to install that version?', WYSIJA ); 
  24. $controller->js[] = 'wysija-admin-ajax'; 
  25. $controller->js[] = 'thickbox'; 
  26. wp_enqueue_style( 'thickbox' ); 
  27.  
  28. /** 
  29. * help to automatically loads scripts and stylesheets based on the request 
  30. * @param type $pagename 
  31. * @param type $dirname 
  32. * @param type $urlname 
  33. * @param type $controller 
  34. * @param type $extension 
  35. * @return type 
  36. */ 
  37. function load_assets( $pagename, $dirname, $urlname, &$controller, $extension = 'newsletter' ) { 
  38.  
  39. if ( isset( $_REQUEST['action'] ) ) { 
  40. $action = $_REQUEST['action']; 
  41.  
  42. //add form validators script for add and edit 
  43. if ( ( $action == 'edit' || $action == 'add' ) && is_object( $controller ) ) { 
  44. $controller->js[] = 'wysija-validator'; 
  45. } else { 
  46. $action = 'default'; 
  47.  
  48. //load the listing script 
  49. if ( $pagename != 'config' ) { 
  50. wp_enqueue_script( 'wysija-admin-list' ); 
  51. //check for files based on this combinations of parameters pagename or pagename and action 
  52. $possibleParameters = array( array( $pagename ), array( $pagename, $action ) ); 
  53. $enqueueFileTypes = array( 'wp_enqueue_script' => array( 'js' => 'js', 'php' => 'js' ), 'wp_enqueue_style' => array( 'css' => 'css' ) ); 
  54.  
  55. // Files that we have, don't use file_exists if we know which files we have 
  56. $files = (object) array( 
  57. 'css' => array( 
  58. 'add-ons',  
  59. 'admin-campaigns-articles',  
  60. 'admin-campaigns-autopost',  
  61. 'admin-campaigns-bookmarks',  
  62. 'admin-campaigns-dividers',  
  63. 'admin-campaigns-editDetails',  
  64. 'admin-campaigns-editTemplate',  
  65. 'admin-campaigns-medias',  
  66. 'admin-campaigns-themes',  
  67. 'admin-campaigns-viewstats',  
  68. 'admin-campaigns-welcome_new',  
  69. 'admin-campaigns',  
  70. 'admin-global',  
  71. 'admin-premium',  
  72. 'admin-statistics',  
  73. 'admin-subscribers-addlist',  
  74. 'admin-subscribers-edit',  
  75. 'admin-subscribers-export',  
  76. 'admin-subscribers-exportlist',  
  77. 'admin-subscribers-import',  
  78. 'admin-subscribers-importmatch',  
  79. 'admin-subscribers-lists',  
  80. 'admin-widget',  
  81. 'admin-config',  
  82. 'admin-config-form_widget_settings',  
  83. ),  
  84. 'js' => array( 
  85. 'admin-ajax-proto',  
  86. 'admin-ajax',  
  87. 'admin-campaigns-articles',  
  88. 'admin-campaigns-autopost',  
  89. 'admin-campaigns-bookmarks',  
  90. 'admin-campaigns-default',  
  91. 'admin-campaigns-dividers',  
  92. 'admin-campaigns-edit',  
  93. 'admin-campaigns-editAutonl',  
  94. 'admin-campaigns-editDetails',  
  95. 'admin-campaigns-editTemplate',  
  96. 'admin-campaigns-image_data',  
  97. 'admin-campaigns-medias',  
  98. 'admin-campaigns-themes',  
  99. 'admin-campaigns-viewstats',  
  100. 'admin-campaigns-welcome_new',  
  101. 'admin-config-form_widget_settings',  
  102. 'admin-config-settings',  
  103. 'admin-global',  
  104. 'admin-listing',  
  105. 'admin-statistics-filter',  
  106. 'admin-statistics',  
  107. 'admin-subscribers-export',  
  108. 'admin-subscribers-import',  
  109. 'admin-subscribers-importmatch',  
  110. 'admin-subscribers',  
  111. 'admin-tmce',  
  112. 'admin-wysija-global',  
  113. 'admin-wysija',  
  114. ); 
  115.  
  116. foreach ( $possibleParameters as $params ) { 
  117. foreach ( $enqueueFileTypes as $method => $types ) { 
  118. foreach ( $types as $file_type => $file_ext ) { 
  119. $file_slug = 'admin-' . implode( '-', $params ); 
  120. if ( in_array( $file_slug, $files->{ $file_ext } ) ) { 
  121. $file_id = "wysija-autoinc-{$extension}-{$file_slug}-{$file_ext}"; 
  122. $file_url = "{$urlname}{$file_ext}/{$file_slug}.{$file_ext}"; 
  123. call_user_func_array( $method, array( $file_id, $file_url, array(), WYSIJA::get_version() ) ); 
  124.  
  125. return true; 
  126.  
  127. /** 
  128. * enqueue and load dif ferent scripts and style based on one script being requested in the controller 
  129. * @param type $controller 
  130. * @param type $pagename 
  131. * @param string $urlbase 
  132. */ 
  133. function parse_js( &$controller, $pagename, $urlbase = WYSIJA_URL ) { 
  134.  
  135. // find out the name of the plugin based on the urlbase parameter 
  136. $plugin = substr( strrchr( substr( $urlbase, 0, strlen( $urlbase ) - 1 ), '/' ), 1 ); 
  137.  
  138. /** enqueue all the scripts that have been declared in the controller */ 
  139. if ( $controller->js ) { 
  140. foreach ( $controller->js as $kjs => $js ) { 
  141. switch ( $js ) { 
  142. case 'jquery-ui-tabs': 
  143. wp_enqueue_script( $js ); 
  144. wp_enqueue_style( 'wysija-tabs-css', WYSIJA_URL . 'css/smoothness/jquery-ui-1.8.20.custom.css', array(), WYSIJA::get_version() ); 
  145. break; 
  146.  
  147. case 'wysija-validator': 
  148. wp_enqueue_script( 'wysija-validator-lang' ); 
  149. wp_enqueue_script( $js ); 
  150. wp_enqueue_script( 'wysija-form' ); 
  151. wp_enqueue_style( 'validate-engine-css' ); 
  152. break; 
  153.  
  154. case 'wysija-admin-ajax': 
  155. if ( $plugin != 'wysija-newsletters' ) { 
  156. $ajaxvarname = $plugin; 
  157. } else { 
  158. $ajaxvarname = 'wysija'; 
  159.  
  160. $dataajaxxx = array( 
  161. 'action' => 'wysija_ajax',  
  162. 'controller' => $pagename,  
  163. 'wysijaplugin' => $plugin,  
  164. 'dataType' => 'json',  
  165. 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),  
  166. // 'ajaxurl' => plugins_url( 'wysija-newsletters' ).'/core/ajax.php',  
  167. 'pluginurl' => plugins_url( 'wysija-newsletters' ),  
  168. 'loadingTrans' => __( 'Loading...', WYSIJA ) 
  169. ); 
  170.  
  171. if ( is_user_logged_in() ) { 
  172. $dataajaxxx['adminurl'] = admin_url( 'admin.php' ); 
  173.  
  174. wp_localize_script( 'wysija-admin-ajax', $ajaxvarname.'AJAX', $dataajaxxx ); 
  175. wp_enqueue_script( 'jquery-ui-dialog' ); 
  176. wp_enqueue_script( $js ); 
  177. wp_enqueue_style( 'wysija-tabs-css', WYSIJA_URL . 'css/smoothness/jquery-ui-1.8.20.custom.css', array(), WYSIJA::get_version() ); 
  178. break; 
  179.  
  180. case 'wysija-admin-ajax-proto': 
  181. wp_enqueue_script( $js ); 
  182. break; 
  183.  
  184. case 'wysija-edit-autonl': 
  185. wp_enqueue_script( 'wysija-edit-autonl', WYSIJA_URL . 'js/admin-campaigns-editAutonl.js', array( 'jquery' ), WYSIJA::get_version() ); 
  186. break; 
  187.  
  188. case 'wysija-scriptaculous': 
  189. // include prototypeJS + scriptaculous & addons 
  190. wp_enqueue_script( 'wysija-prototype', WYSIJA_URL . 'js/prototype/prototype.js', array(), WYSIJA::get_version() ); 
  191. wp_enqueue_script( 'wysija-proto-scriptaculous', WYSIJA_URL . 'js/prototype/scriptaculous.js', array( 'wysija-prototype' ), WYSIJA::get_version() ); 
  192. wp_enqueue_script( 'wysija-proto-dragdrop', WYSIJA_URL . 'js/prototype/dragdrop.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  193. wp_enqueue_script( 'wysija-proto-controls', WYSIJA_URL . 'js/prototype/controls.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  194. wp_enqueue_script( 'wysija-proto-slider', WYSIJA_URL . 'js/prototype/slider.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  195. break; 
  196.  
  197. case 'mailpoet-select2': 
  198.  
  199. wp_enqueue_script( 'mailpoet-select2', WYSIJA_URL . 'js/select2/select2.min.js', array( 'jquery' ), WYSIJA::get_version() ); 
  200. wp_enqueue_script( 'mailpoet-select2-l10n', WYSIJA_URL . 'js/select2/select2-l10n.js', array( 'mailpoet-select2', 'underscore' ), WYSIJA::get_version() ); 
  201.  
  202. wp_enqueue_style( 'mailpoet-select2', WYSIJA_URL . 'css/select2/select2.css', array(), WYSIJA::get_version() ); 
  203.  
  204. wp_localize_script( 
  205. 'mailpoet-select2-l10n',  
  206. 'mailpoet_l10n_select2',  
  207. array( 
  208. 'noMatches' => __( 'No Results were found', WYSIJA ),  
  209. 'inputTooShort' => __( 'Please enter <%= chars %> more character<%= plural %>', WYSIJA ),  
  210. 'inputTooLong' => __( 'Please delete <%= chars %> character<%= plural %>', WYSIJA ),  
  211. 'selectionTooBig' => __( 'You can only select <%= chars %> item<%= plural %>', WYSIJA ),  
  212. 'loadMore' => __( 'Loading more Results...', WYSIJA ),  
  213. 'searching' => __( 'Searching...', WYSIJA ),  
  214. ); 
  215.  
  216. break; 
  217.  
  218. case 'mailpoet-field-select2-terms': 
  219. wp_enqueue_script( 'mailpoet-field-select2-terms', WYSIJA_URL . 'js/fields/select2-terms.js', array( 'jquery', 'underscore', 'mailpoet-select2' ), WYSIJA::get_version() ); 
  220.  
  221. break; 
  222.  
  223. case 'mailpoet-field-select2-simple': 
  224. wp_enqueue_script( 'mailpoet-field-select2-simple', WYSIJA_URL . 'js/fields/select2-simple.js', array( 'jquery', 'underscore', 'mailpoet-select2' ), WYSIJA::get_version() ); 
  225.  
  226. break; 
  227.  
  228. case 'wysija-form-editor': 
  229. wp_enqueue_script( 'wysija-prototype', WYSIJA_URL . 'js/prototype/prototype.js', array(), WYSIJA::get_version() ); 
  230. wp_enqueue_script( 'wysija-proto-scriptaculous', WYSIJA_URL . 'js/prototype/scriptaculous.js', array( 'wysija-prototype' ), WYSIJA::get_version() ); 
  231. wp_enqueue_script( 'wysija-proto-dragdrop', WYSIJA_URL . 'js/prototype/dragdrop.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  232. wp_enqueue_script( 'wysija-proto-controls', WYSIJA_URL . 'js/prototype/controls.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  233. wp_enqueue_script( 'wysija-proto-slider', WYSIJA_URL . 'js/prototype/slider.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  234.  
  235. // include form editor 
  236. wp_enqueue_script( $js, WYSIJA_URL . 'js/' . $js . '.js', array(), WYSIJA::get_version() ); 
  237.  
  238. /** MailPoet form editor i18n */ 
  239. wp_localize_script( 'wysija-form-editor', 'Wysija_i18n', $controller->jsTrans ); 
  240.  
  241. // form editor css 
  242. wp_enqueue_style( 'wysija-form-editor-css', WYSIJA_URL . 'css/wysija-form-editor.css', array(), WYSIJA::get_version() ); 
  243. break; 
  244.  
  245. case 'wysija-amcharts': 
  246. // MailPoet chart 
  247. wp_enqueue_script( 'amcharts', WYSIJA_URL . 'js/amcharts/amcharts.js', array(), WYSIJA::get_version() ); 
  248. wp_enqueue_script( 'wysija-amcharts', WYSIJA_URL . 'js/wysija-charts.js', array(), WYSIJA::get_version() ); 
  249. break; 
  250.  
  251. case 'wysija-editor': 
  252.  
  253. wp_enqueue_script( 'wysija-prototype', WYSIJA_URL . 'js/prototype/prototype.js', array(), WYSIJA::get_version() ); 
  254. wp_deregister_script( 'thickbox' ); 
  255.  
  256. wp_register_script( 'thickbox', WYSIJA_URL . 'js/thickbox/thickbox.js', array( 'jquery' ), WYSIJA::get_version() ); 
  257.  
  258. wp_localize_script( 
  259. 'thickbox',  
  260. 'thickboxL10n',  
  261. array( 
  262. 'next' => __( 'Next >' ),  
  263. 'prev' => __( '< Prev' ),  
  264. 'image' => __( 'Image' ),  
  265. 'of' => __( 'of' ),  
  266. 'close' => __( 'Close' ),  
  267. 'noif rames' => __( 'This feature requires inline frames. You have iframes disabled or your browser does not support them.' ),  
  268. 'l10n_print_after' => 'try{convertEntities( thickboxL10n );}catch( e ) {};',  
  269. ); 
  270.  
  271. wp_enqueue_script( 'wysija-proto-scriptaculous', WYSIJA_URL . 'js/prototype/scriptaculous.js' , array( 'wysija-prototype' ), WYSIJA::get_version() ); 
  272. wp_enqueue_script( 'wysija-proto-dragdrop', WYSIJA_URL . 'js/prototype/dragdrop.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  273. wp_enqueue_script( 'wysija-proto-controls', WYSIJA_URL . 'js/prototype/controls.js', array( 'wysija-proto-scriptaculous' ), WYSIJA::get_version() ); 
  274. wp_enqueue_script( 'wysija-timer', WYSIJA_URL . 'js/timer.js', array(), WYSIJA::get_version() ); 
  275. wp_enqueue_script( $js, WYSIJA_URL . 'js/' . $js . '.js', array(), WYSIJA::get_version() ); 
  276. wp_enqueue_script( 'wysija-konami', WYSIJA_URL . 'js/konami.js', array(), WYSIJA::get_version() ); 
  277. wp_enqueue_script( 'wysija-tinymce', WYSIJA_URL . 'js/tinymce/tiny_mce.js', array(), WYSIJA::get_version() ); 
  278.  
  279. wp_enqueue_script( 'wysija-tinymce-init', WYSIJA_URL . 'js/tinymce_init.js', array(), WYSIJA::get_version() ); 
  280. wp_enqueue_style( 'wysija-editor-css', WYSIJA_URL . 'css/wysija-editor.css', array(), WYSIJA::get_version() ); 
  281. wp_enqueue_script( 'wysija-colorpicker', WYSIJA_URL . 'js/excolor/jquery.modcoder.excolor.js', array(), WYSIJA::get_version() ); 
  282.  
  283. if ( version_compare( $GLOBALS['wp_version'], '3.9', '>=' ) ) { 
  284. wp_enqueue_style( 'mailpoet-tinymce', WYSIJA_URL . 'css/tmce/editor.css', array(), WYSIJA::get_version() ); 
  285.  
  286. /** MailPoet editor i18n */ 
  287. wp_localize_script( 'wysija-editor', 'Wysija_i18n', $controller->jsTrans ); 
  288. break; 
  289.  
  290. case 'wysija-colorpicker': 
  291. wp_enqueue_script( 'wysija-colorpicker', WYSIJA_URL . 'js/excolor/jquery.modcoder.excolor.js', array(), WYSIJA::get_version() ); 
  292. break; 
  293.  
  294. case 'wysija-tooltip': 
  295. wp_enqueue_script( 'mailpoet.tooltip', WYSIJA_URL . 'js/vendor/bootstrap.tooltip.js', array( 'jquery' ), WYSIJA::get_version(), true ); 
  296. wp_enqueue_style( 'mailpoet.tooltip', WYSIJA_URL . 'css/vendor/bootstrap.tooltip.css', array(), WYSIJA::get_version(), 'screen' ); 
  297. break; 
  298.  
  299. case 'wysija-import-match': 
  300. wp_enqueue_script('jquery-matchColumn', WYSIJA_URL.'js/jquery/jquery.matchColumn.js', array('jquery'), WYSIJA::get_version()); 
  301. wp_enqueue_script('jquery-userStatusMapping', WYSIJA_URL.'js/jquery/jquery.userStatusMapping.js', array('jquery'), WYSIJA::get_version()); 
  302. break; 
  303.  
  304. default: 
  305. if ( is_string( $kjs ) ) { 
  306. // check if there's a trailing slash in the urlbase 
  307. if ( substr( $urlbase, -1 ) !== '/' ) { 
  308. $urlbase .= '/'; 
  309. // check if there's already an extension specif ied for the file 
  310. if ( substr( $urlbase, -3 ) !== '.js' ) { 
  311. $js .= '.js'; 
  312. // enqueue script 
  313.  
  314. wp_enqueue_script( $kjs, $urlbase . 'js/' . $js, array(), WYSIJA::get_version() ); 
  315. } else { 
  316. wp_enqueue_script( $js ); 
  317.  
  318. /** 
  319. * add some js defined variable per script 
  320. * @param type $pagename 
  321. * @param type $dirname 
  322. * @param type $urlname 
  323. * @param type $controller 
  324. * @param type $extension 
  325. */ 
  326. function localize( $pagename, $dirname, $urlname, &$controller, $extension = 'newsletter' ) { 
  327. if ( $controller->jsLoc ) { 
  328. foreach ( $controller->jsLoc as $key => $value ) { 
  329. foreach ( $value as $kf => $local ) { 
  330.  
  331. //this function accepts multidimensional array some version like wp3.2.1 couldn't do that 
  332. $this->localizeme( $key, $kf, $local ); 
  333.  
  334. /** 
  335. * multidimensional array are possible here 
  336. * @param type $handle 
  337. * @param type $object_name 
  338. * @param type $l10n 
  339. */ 
  340. function localizeme( $handle, $object_name, $l10n ) { 
  341.  
  342. foreach ( (array) $l10n as $key => $value ) { 
  343. if ( ! is_scalar( $value ) ) { 
  344. continue; 
  345. $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); 
  346.  
  347. $this->jsVariables .= "var $object_name = " . json_encode( $l10n ) . ';'; 
  348. add_action( 'admin_head', array( $this, 'localize_print' ) ); 
  349.  
  350. /** 
  351. * load the variables in the html 
  352. */ 
  353. function localize_print() { 
  354. echo "<script type='text/javascript' id='mailpoet-localized'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5 
  355. echo "/* <![CDATA[ */\n"; 
  356. echo esc_attr( '' ) . $this->jsVariables . "\n"; // To comply with PHP Code Sniffer WordPress Standards before we "hack" the echo 
  357. echo "/* ]]> */\n"; 
  358. echo "</script>\n"; 
  359.  
  360.  
  361.  
  362. /** 
  363. * this is for backward compatibility and avoid blank screen on older version of the premium plugin 
  364. */ 
  365. function loadScriptsStyles( $pagename, $dirname, $urlname, &$controller, $extension = 'newsletter' ) { 
  366. return $this->load_assets( $pagename, $dirname, $urlname, $controller, $extension ); 
  367.  
  368. /** 
  369. * this is for backward compatibility and avoid blank screen on older version of the premium plugin 
  370. */ 
  371. function initLoad( &$controller ) { 
  372. return $this->init( $controller ); 
  373.  
  374. function jsParse( &$controller, $pagename, $urlbase = WYSIJA_URL ) { 
  375. $this->parse_js( $controller, $pagename, $urlbase ); 
  376.