WYSIJA_model_config

The MailPoet Newsletters WYSIJA model config class.

Defined (1)

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

/models/config.php  
  1. class WYSIJA_model_config extends WYSIJA_object{ 
  2. // the name of our option in the settings 
  3. var $name_option = 'wysija'; 
  4.  
  5. /** Check boxes are cheeky depending on the browser, some browser, won't post it, so it won't appear in the global _POST variable 
  6. * SO in order to identify unchecked value, we list all of the fields which are checkboxes 
  7. */ 
  8. var $cboxes = array( 
  9. 'emails_notified_when_sub',  
  10. 'emails_notified_when_unsub',  
  11. 'emails_notified_when_bounce',  
  12. 'emails_notified_when_dailysummary',  
  13. 'bounce_process_auto',  
  14. 'ms_bounce_process_auto',  
  15. 'sharedata',  
  16. 'manage_subscriptions',  
  17. 'viewinbrowser',  
  18. 'dkim_active',  
  19. 'cron_manual',  
  20. 'commentform',  
  21. 'smtp_rest',  
  22. 'ms_smtp_rest',  
  23. 'registerform',  
  24. 'ms_allow_admin_sending_method',  
  25. 'ms_allow_admin_toggle_signup_confirmation',  
  26. 'debug_log_cron',  
  27. 'debug_log_post_notif',  
  28. 'debug_log_query_errors',  
  29. 'debug_log_queue_process',  
  30. 'debug_log_manual',  
  31.  
  32. ); 
  33.  
  34. /** 
  35. * all of the default values in that option 
  36. */ 
  37. var $defaults = array( 
  38. 'limit_listing' => 10,  
  39. 'role_campaign' => 'switch_themes',  
  40. 'role_subscribers' => 'switch_themes',  
  41. 'emails_notified_when_unsub' => true,  
  42. 'sending_method' => 'gmail',  
  43. 'sending_emails_number' => '70',  
  44. 'sending_method' => 'site',  
  45. 'sending_emails_site_method' => 'phpmail',  
  46. 'smtp_port' => '',  
  47. 'smtp_auth' => true,  
  48. 'bounce_port' => '',  
  49. 'confirm_dbleoptin' => 1,  
  50. 'bounce_selfsigned' => 0,  
  51. 'bounce_email_notexists' => 'unsub',  
  52. 'bouncing_emails_each' => 'daily',  
  53. 'bounce_inbox_full' => 'not',  
  54. 'pluginsImportedEgg' => false,  
  55. 'advanced_charset' => 'UTF-8',  
  56. 'sendmail_path' => '/usr/sbin/sendmail',  
  57. 'sending_emails_each' => 'hourly',  
  58. 'bounce_max' => 8,  
  59. 'debug_new' => false,  
  60. 'analytics' => 0,  
  61. 'send_analytics_now' => 0,  
  62. 'industry' => 'other',  
  63. 'manage_subscriptions' => false,  
  64. 'editor_fullarticle' => false,  
  65. 'allow_no_js' => true,  
  66. 'urlstats_base64' => true,  
  67. 'viewinbrowser' => true,  
  68. 'commentform' => false,  
  69. 'registerform' => false,  
  70. 'ms_sending_config' => 'one-each',  
  71. 'ms_sending_method' => 'site',  
  72. 'ms_sending_emails_site_method' => 'phpmail',  
  73. 'ms_sending_emails_each' => 'hourly',  
  74. 'ms_sending_emails_number' => '100',  
  75. 'ms_allow_admin_sending_method' => false,  
  76. 'ms_allow_admin_toggle_signup_confirmation' => false,  
  77. 'ms_bouncing_emails_each' => 'daily',  
  78. 'cron_page_hit_trigger' => 1,  
  79. 'beta_mode' => false,  
  80. 'cron_manual' => true,  
  81. 'email_cyrillic' => false,  
  82. 'allow_wpmail' => false,  
  83. ); 
  84.  
  85. var $capabilities = array(); 
  86. var $values = array(); 
  87.  
  88. function __construct() { 
  89. // global telling us if we're currently running the installation process install/helper 
  90. global $wysija_installing; 
  91. // get our WordPress option containing all of our settings 
  92. $encoded_option = get_option( $this->name_option ); 
  93. // we set a flag to identify whether we need to run the helpers/install.php 
  94. $plugin_needs_installing = $plugin_needs_fixing = false; 
  95.  
  96. // 1 - "Is our plugin installed?" we make all of the checks to be sure that the plugin has been installed already 
  97. if ( $encoded_option ) { 
  98. // our settings option needs to be a base64 encoded string containing a serialized array 
  99. $this->values = unserialize( base64_decode( $encoded_option ) ); 
  100.  
  101. // we make sure that the installation of the plugin has been complete 
  102. if ( ! isset( $this->values['installed'] ) ) { 
  103. if ( defined( 'WP_ADMIN' ) && isset( $_GET['page'] ) && substr( $_GET['page'], 0, 7 ) == 'wysija_' && get_option( 'installation_step' ) == 16 ) { 
  104. // if we fall in that situation, there has been a problem 
  105. // the step 16 of the installation has to set the "installed" and "installed_time" parameters in our config option 
  106. // how could that happen? 
  107. // let's determine the real version number of this installation so that the proper update sequence are run 
  108. // let's run a hooked action the function cannot be run directly otherwise some missing WP functions will run a crash 
  109. $plugin_needs_fixing = true; 
  110. } else { 
  111. // when we come to that step, we know the plugin has not been installed so we tell it to run the installation helper 
  112. $plugin_needs_installing = true; 
  113. } else { 
  114. // our settings option is not set, that means the plugin is not installed 
  115. $plugin_needs_installing = true; 
  116.  
  117. // regenerate the DKIM key 
  118. // dkim is not active that means the dkim_keys are not used so we can reinitialize them as 1024 if they are not already 1024 
  119. // (we use to have a 512 DKIM which is not good enough for Gmail's spam filters) 
  120. if ( ! isset( $this->values['dkim_active'] ) && ! empty( $this->values['dkim_pubk'] ) && ! isset( $this->values['dkim_1024'] ) ) { 
  121. unset($this->values['dkim_pubk']); 
  122. unset($this->values['dkim_privk']); 
  123.  
  124. // in multisite some options are global and need to have just one value accross all of the sites. 
  125. // for instance (multisite sending method and multisite bounce handling) 
  126. if ( is_multisite() ) { 
  127. // safety net for accidentaly saved ms values in the child site option 
  128. foreach ( $this->values as $key => $val ) { 
  129. // if we have a key prefixed by ms_ in that option then we just unset it. 
  130. // the real ms value is loaded right after and comes from a global get_site_option 
  131. if ( substr( $key, 0, 3 ) === 'ms_' ) { 
  132. unset( $this->values[ $key ] ); 
  133. $encoded_option = get_site_option( 'ms_' . $this->name_option ); 
  134. // let's merge the global multisite options to our child site settings so that they can be fetched through getValue() 
  135. if ( $encoded_option ) { 
  136. $this->values = array_merge( $this->values, unserialize( base64_decode( $encoded_option ) ) ); 
  137.  
  138. // in multisite the default sending method is the network one 
  139. $this->defaults['sending_method'] = 'network'; 
  140.  
  141. // install the application because there is no option setup it's safer than the classic activation scheme 
  142. if ( defined( 'WP_ADMIN' ) ) { 
  143.  
  144. if ( $plugin_needs_installing && $wysija_installing !== true ) { 
  145. $wysija_installing = true; 
  146. $helper_install = WYSIJA::get( 'install', 'helper', false, 'wysija-newsletters', false ); 
  147. add_action( 'admin_menu', array( $helper_install, 'install' ), 97 ); 
  148. } else { 
  149. $helper_update = WYSIJA::get( 'update' , 'helper' ); 
  150. if ( $plugin_needs_fixing ) { 
  151. // plugin needs fixing 
  152. add_action( 'admin_menu', array( $helper_update, 'repair_settings' ), 103 ); 
  153. } else { 
  154. // plugin is clean let's look for update request 
  155. // the plugin has already been installed, so we check if there are some update query to be run 
  156. add_action( 'admin_menu', array( $helper_update, 'check' ), 103 ); 
  157. // wait until the translation files are loaded and load our strings 
  158. // From the backend we load the translated strings for that function at admin_menu level 
  159. // Ben: there is a reason for that, I just don't remember which 
  160. add_action( 'admin_menu', array( $this, 'add_translated_default' ) ); 
  161. } else { 
  162. // wait until the translation files are loaded and load our strings 
  163. add_action( 'init', array( $this, 'add_translated_default' ), 96 ); 
  164.  
  165. // we're already loading our translation files through hooks, this said 
  166. $this->add_translated_default(); 
  167. /** 
  168. * to make sure the translation is not screwed by an empty space or so 
  169. */ 
  170. function cleanTrans( $string ) { 
  171. return str_replace( 
  172. array( 
  173. '[ link]',  
  174. '[link ]',  
  175. '[ link ]',  
  176. '[/ link]',  
  177. '[/link ]',  
  178. '[ /link]',  
  179. '[/ link ]',  
  180. ),  
  181. array( 
  182. '[link]',  
  183. '[link]',  
  184. '[link]',  
  185. '[/link]',  
  186. '[/link]',  
  187. '[/link]',  
  188. '[/link]',  
  189. ),  
  190. trim( $string ) 
  191. ); 
  192.  
  193. /** 
  194. * this is translatable text we use in the plugin which needs to be loaded through a hook so that the translation files are already there 
  195. */ 
  196. function add_translated_default() { 
  197. // definition of extra translated defaults fields 
  198. $this->defaults['confirm_email_title'] = sprintf( __( 'Confirm your subscription to %1$s', WYSIJA ), get_option( 'blogname' ) ); 
  199. $this->defaults['confirm_email_body'] = __( "Hello!\n\nHurray! You've subscribed to our site.\nWe need you to activate your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you, \n\n The team!\n", WYSIJA ); 
  200. $this->defaults['subscribed_title'] = __( 'You\'ve subscribed to: %1$s', WYSIJA ); 
  201. $this->defaults['subscribed_subtitle'] = __( 'Yup, we\'ve added you to our list. You\'ll hear from us shortly.', WYSIJA ); 
  202. $this->defaults['unsubscribed_title'] = __( 'You\'ve unsubscribed!', WYSIJA ); 
  203. $this->defaults['unsubscribed_subtitle'] = __( 'Great, you\'ll never hear from us again!', WYSIJA ); 
  204. $this->defaults['unsubscribe_linkname'] = __( 'Unsubscribe', WYSIJA ); 
  205. $this->defaults['manage_subscriptions_linkname'] = __( 'Edit your subscription', WYSIJA ); 
  206. $this->defaults['viewinbrowser_linkname'] = $this->cleanTrans( __( 'Display problems? [link]View this newsletter in your browser.[/link]', WYSIJA ) ); 
  207. $this->defaults['registerform_linkname'] = $this->defaults['commentform_linkname'] = __( 'Yes, add me to your mailing list.', WYSIJA ); 
  208.  
  209. $this->capabilities['newsletters'] = array( 
  210. 'label' => __( 'Who can create newsletters?', WYSIJA ) 
  211. ); 
  212. $this->capabilities['subscribers'] = array( // if this role (name) is changed, please change at the filter "wysija_capabilities" as well 
  213. 'label' => __( 'Who can manage subscribers?', WYSIJA ) 
  214. ); 
  215. $this->capabilities['config'] = array( 
  216. 'label' => __( 'Who can change MailPoet\'s settings?', WYSIJA ) 
  217. ); 
  218. $this->capabilities['theme_tab'] = array( 
  219. 'label' => __( 'Who can see the themes tab in the visual editor?', WYSIJA ) 
  220. ); 
  221. $this->capabilities['style_tab'] = array( 
  222. 'label' => __( 'Who can see the styles tab in the visual editor?', WYSIJA ) 
  223. ); 
  224.  
  225. $this->capabilities = apply_filters( 'wysija_capabilities', $this->capabilities ); 
  226.  
  227.  
  228. /** 
  229. * we have a specific save for option since we are saving it in wordpress options table 
  230. * @param array $data of data to save 
  231. * @param boolean $saved_through_interfaces telling us whether 
  232. */ 
  233. function save( $data = false, $saved_through_interfaces = false ) { 
  234.  
  235. if ( $data ) { 
  236. // when saving configuration from the settings page we need to make sure that if checkboxes have been unticked we remove the corresponding option 
  237. $bouncing_freq_has_changed = $sending_freq_has_changed = $ms_sending_freq_has_changed = false; 
  238. if ( $saved_through_interfaces ) { 
  239. $helper_wp_tools = WYSIJA::get( 'wp_tools', 'helper', false, 'wysija-newsletters', false ); 
  240. $editable_roles = $helper_wp_tools->wp_get_roles(); 
  241. foreach ( $this->capabilities as $keycap => $capability ) { 
  242. foreach ( $editable_roles as $role ) { 
  243. $this->cboxes[] = 'rolescap---' . $role['key'] . '---' . $keycap; 
  244.  
  245. // if the wysija's cron option has just been turned on from an off value 
  246. // then we check the licence from mailpoet.com to share the cron url with us 
  247. if ( isset( $data['cron_manual'] ) && $data['cron_manual'] != $this->getValue( 'cron_manual' ) ) { 
  248. $helper_licence = WYSIJA::get( 'licence', 'helper' ); 
  249. $helper_licence->check( true ); 
  250.  
  251. // loop through all of the checkboxes values 
  252. foreach ( $this->cboxes as $checkbox ) { 
  253. // set the value as false if the value doesn't exist in the array (happens when checkbox is unchecked) 
  254. if ( ! isset( $data[ $checkbox ] ) ) { 
  255. $data[ $checkbox ] = $this->values[ $checkbox ] = false; 
  256. } else { 
  257. // otherwise we set it as value 1 
  258. $data[ $checkbox ] = $this->values[ $checkbox ] = 1; 
  259.  
  260. // identify all of the roles checkboxes to update the WP user roles live when changed 
  261. if ( strpos( $checkbox, 'rolescap---' ) !== false ) { 
  262.  
  263. $role_capability = str_replace( 'rolescap---', '', $checkbox ); 
  264.  
  265. $role_capability_exploded = explode( '---', $role_capability ); 
  266. $role = get_role( $role_capability_exploded[0] ); 
  267. $capability = 'wysija_' . $role_capability_exploded[1]; 
  268. // added for invalid roles ... 
  269.  
  270. // this is a rolecap let's add or remove the cap to the role 
  271. if ( $role ) { 
  272. if ( $this->values[ $checkbox ] ) { 
  273. $role->add_cap( $capability ); 
  274. } else { 
  275. // remove cap only for roles different of admins 
  276. if ( $role->has_cap( $capability ) && ! in_array( $role_capability_exploded[0], array( 'administrator', 'super_admin' ) ) ) { 
  277. $role->remove_cap( $capability ); 
  278.  
  279. // no need to keep these role values in our option, they already are saved in WordPress' roles options 
  280. unset( $this->values[ $checkbox ] ); 
  281.  
  282. $helper_user = WYSIJA::get( 'user', 'helper', false, 'wysija-newsletters', false ); 
  283.  
  284. // validating the from email 
  285. if ( isset( $data['from_email'] ) && ! $helper_user->validEmail( $data['from_email'] ) ) { 
  286. if ( ! $data['from_email'] ) { 
  287. $data['from_email'] = __( 'empty', WYSIJA ); 
  288. $this->error( sprintf( __( 'The <strong>from email</strong> value you have entered (%1$s) is not a valid email address.', WYSIJA ), '' ), true ); 
  289. $data['from_email'] = $this->values['from_email']; 
  290.  
  291. // validating the replyto email 
  292. if ( isset( $data['replyto_email'] ) && ! $helper_user->validEmail( $data['replyto_email'] ) ) { 
  293. if ( ! $data['replyto_email'] ) { 
  294. $data['replyto_email'] = __( 'empty', WYSIJA ); 
  295. $this->error( sprintf( __( 'The <strong>reply to</strong> email value you have entered (%1$s) is not a valid email address.', WYSIJA ), '' ), true ); 
  296. $data['replyto_email'] = $this->values['replyto_email']; 
  297.  
  298. if ( isset( $data['bounce_rule_action_required_forwardto'] ) && ! $helper_user->validEmail( $data['bounce_rule_action_required_forwardto'] ) ) { 
  299. $this->error('Invalid bounce forward email'); 
  300. $data['bounce_rule_action_required_forwardto'] = $this->values['bounce_rule_action_required_forwardto']; 
  301.  
  302. if ( isset( $data['bounce_rule_blocked_ip_forwardto'] ) && ! $helper_user->validEmail( $data['bounce_rule_blocked_ip_forwardto'] ) ) { 
  303. $this->error('Invalid bounce forward email'); 
  304. $data['bounce_rule_blocked_ip_forwardto'] = $this->values['bounce_rule_blocked_ip_forwardto']; 
  305.  
  306. if ( isset( $data['bounce_rule_nohandle_forwardto'] ) && ! $helper_user->validEmail( $data['bounce_rule_nohandle_forwardto'] ) ) { 
  307. $this->error('Invalid bounce forward email'); 
  308. $data['bounce_rule_nohandle_forwardto'] = $this->values['bounce_rule_nohandle_forwardto']; 
  309.  
  310. // in that case the admin changed the frequency of the wysija cron meaning that we need to clear it 
  311. // network's method frequency has changed 
  312. if ( isset( $data['ms_sending_emails_each'] ) && $data['ms_sending_emails_each'] != $this->getValue( 'ms_sending_emails_each' ) ) { 
  313. $ms_sending_freq_has_changed = true; 
  314. $data['last_save'] = time(); 
  315.  
  316. // we're on a single site and the sending frequency has been modified 
  317. // we need to refresh the sending scheduled task down below 
  318. if ( isset( $data['sending_emails_each'] ) && $data['sending_emails_each'] != $this->getValue( 'sending_emails_each' ) ) { 
  319. $sending_freq_has_changed = true; 
  320. $data['last_save'] = time(); 
  321.  
  322. // we're on a single site and the bounce frequency has been changed 
  323. // we need to refresh the bounce scheduled task down below 
  324. if ( isset( $data['bouncing_emails_each'] ) && $data['bouncing_emails_each'] != $this->getValue( 'bouncing_emails_each' ) ) { 
  325. $bouncing_freq_has_changed = true; 
  326. $data['last_save'] = time(); 
  327.  
  328. // if saved with gmail then we set up the smtp settings 
  329. // @deprecated since 2.6.12 
  330. if ( isset( $data['sending_method'] ) ) { 
  331. if ( $data['sending_method'] == 'gmail' ) { 
  332. $data['smtp_host'] = 'smtp.gmail.com'; 
  333. $data['smtp_port'] = '465'; 
  334. $data['smtp_secure'] = 'ssl'; 
  335. $data['smtp_auth'] = true; 
  336.  
  337. // basic validation of the smtp_host field 
  338. if ( isset( $data['smtp_host'] ) ) { 
  339. $data['smtp_host'] = trim( $data['smtp_host'] ); 
  340.  
  341. // specific case to identify common action to different rules there some that don't appear in the interface, yet we use them. 
  342. // BEN: this code needs to be reviewed and retested... I know what is the purpose but I don't understand $indexrule and $ruleMain 
  343. foreach ( $data as $key => $value ) { 
  344. $fs = 'bounce_rule_'; 
  345. if ( strpos( $key, $fs ) !== false ) { 
  346. if ( strpos( $key, '_forwardto' ) === false ) { 
  347. $indexrule = str_replace( $fs, '', $key ); 
  348. $helper_rules = WYSIJA::get( 'rules', 'helper', false, 'wysija-newsletters', false ); 
  349. $rules = $helper_rules->getRules(); 
  350. foreach ( $rules as $keyy => $vals ) { 
  351. if ( isset( $vals['behave'] ) ) { 
  352. $ruleMain = $helper_rules->getRules( $vals['behave'] ); 
  353. $data[ $fs . $vals['key'] ] = $value; 
  354.  
  355. // the regenerate box appeared for old versions of MailPoet where we had to switch from a 512 bits DKIM key to a 1024 for better score with Gmail 
  356. // if the dkim_regenerate box has been ticked then we unset the dkim values so that they are regenerated in the next page load 
  357. if ( isset( $data['dkim_regenerate'] ) && $data['dkim_regenerate'] == 'regenerate' ) { 
  358. if ( isset( $this->values['dkim_pubk'] ) ) { 
  359. unset($data['dkim_pubk']); 
  360. unset($this->values['dkim_pubk']); 
  361. unset($data['dkim_privk']); 
  362. unset($this->values['dkim_privk']); 
  363. unset($data['dkim_regenerate']); 
  364.  
  365. // when we switch the double optin value on to off or off to on, we refresh the total user count which is different in both cases 
  366. if ( isset( $data['confirm_dbleoptin'] ) && isset( $this->values['confirm_dbleoptin'] ) && $data['confirm_dbleoptin'] != $this->values['confirm_dbleoptin'] ) { 
  367. $helper_user = WYSIJA::get( 'user', 'helper' ); 
  368. $helper_user->refreshUsers(); 
  369.  
  370.  
  371. $is_multisite = is_multisite(); 
  372. $is_network_admin = WYSIJA::current_user_can( 'manage_network' ); 
  373. $global_MS_settings = array(); 
  374. foreach ( $data as $key => $value ) { 
  375. // we detect a ms value, so we put it in a separate array to store it somewhere else central 
  376. if ( $is_multisite && $is_network_admin && strpos( $key, 'ms_' ) !== false ) { 
  377. $global_MS_settings[ $key ] = $value; 
  378. continue; 
  379.  
  380. // verify that the confirm email body contains an activation link 
  381. // if it doesn't add it at the end of the email 
  382. if ( $key == 'confirm_email_body' && strpos( $value, '[activation_link]' ) === false ) { 
  383. $value .= "\n" . '[activation_link]Click here to confirm your subscription.[/activation_link]'; 
  384.  
  385. // I'm not sure why do we do that, we separate the DKIm wrappers from teh value saved in the option.. why not, there must be a reason 
  386. if ( $key == 'dkim_pubk' ) { 
  387. $value = str_replace( array( '-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----', "\n" ), '', $value ); 
  388.  
  389. if( is_string($value) ) { 
  390. $value = preg_replace( '#< *script(?:(?!< */ *script *>).)*< */ *script *>#isU', '', $value ); 
  391. $value = preg_replace("#<([^><]+?)([^a-z_\-]on\w*|xmlns)(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $value); 
  392.  
  393. // for the manage subscription option you can select which list appear publicy to the user in their subscription page. 
  394. // this piece of code make sure that they appear or not 
  395. if ( $key == 'manage_subscriptions_lists' ) { 
  396. $model_list = WYSIJA::get( 'list', 'model' ); 
  397. $model_list->update( array( 'is_public' => 0 ), array( 'is_public' => 1 ) ); 
  398. $model_list->reset(); 
  399. $model_list->update( array( 'is_public' => 1 ), array( 'list_id' => $value ) ); 
  400.  
  401. unset( $this->values[ $key ] ); 
  402.  
  403. // we have a variable in this class which is defaults 
  404. // we save the option only if its value is different than the default one: no need to overload the db. 
  405. if ( ! isset( $this->defaults[ $key ] ) || ( isset( $this->defaults[ $key ] ) && $value != $this->defaults[ $key ] ) ) { 
  406. $this->values[ $key ] = $value; 
  407. } else { 
  408. unset( $this->values[ $key ] ); 
  409.  
  410.  
  411. // save the confirmation email in the email table 
  412. // IMPORTANT: once we move the confirmation email to the newsletter listing we can get rid of that 
  413. if ( isset( $data['confirm_email_title'] ) && isset( $data['confirm_email_body'] ) ) { 
  414. $model_email = WYSIJA::get( 'email', 'model', false, 'wysija-newsletters', false ); 
  415. $is_multisite = is_multisite(); 
  416. // the from email on a multisite with the network method on is coming from the ms value 
  417. if ( $is_multisite && $data['sending_method'] == 'network' ) { 
  418. $from_email = $data['ms_from_email']; 
  419. } else { 
  420. $from_email = $data['from_email']; 
  421. // updating email 
  422. $model_email->update( 
  423. array( 
  424. 'from_name' => $data['from_name'],  
  425. 'from_email' => $from_email,  
  426. 'replyto_name' => $data['replyto_name'],  
  427. 'replyto_email' => $data['replyto_email'],  
  428. 'subject' => $data['confirm_email_title'],  
  429. 'body' => $data['confirm_email_body'],  
  430. ),  
  431. array( 
  432. 'email_id' => $this->values['confirm_email_id'],  
  433. ); 
  434. unset($this->values['confirm_email_title']); 
  435. unset($this->values['confirm_email_body']); 
  436.  
  437. // serialize and encode the option's values and save them in WP's options 
  438. update_option( $this->name_option, base64_encode( serialize( $this->values ) ) ); 
  439.  
  440. // when we are on a multisite, part of the options need to be saved into a global option common to all of the sites 
  441. if ( $is_multisite ) { 
  442. // the network admin has access to that extra information through the interfaces when does interfaces are generated then $dataMultisite is filled with values 
  443. if ( ! empty( $global_MS_settings ) ) { 
  444. if ( $ms_sending_freq_has_changed ) { 
  445. // if the sending frequency on the network method has changed, we need to update each single cron task on all of the child sites 
  446. // we reset an array to clear the cron of every single site using the multisite method 
  447. update_site_option( 'ms_wysija_sending_cron', array() ); 
  448.  
  449. // get the data which was saved in the global option before 
  450. $data_saved_ms_before = unserialize( base64_decode( get_site_option( 'ms_' . $this->name_option ) ) ); 
  451.  
  452. // if it's not empty we just merge both sets of values 
  453. if ( ! empty( $data_saved_ms_before ) ) { 
  454. $global_MS_settings = array_merge( $data_saved_ms_before, $global_MS_settings ); 
  455. // we save the global ms option 
  456. update_site_option( 'ms_' . $this->name_option, base64_encode( serialize( $global_MS_settings ) ) ); 
  457.  
  458. // let's merge the latest MS modified values with the values of the site's config, this is to avoid a bug after saving 
  459. $data_saved_ms_fresh = unserialize( base64_decode( get_site_option( 'ms_' . $this->name_option ) ) ); 
  460. if ( ! empty( $data_saved_ms_fresh ) ) { 
  461. $this->values = array_merge( $this->values, $data_saved_ms_fresh ); 
  462.  
  463. // the sending frequency has changed on that site's settings let's clear the frequency recorded in WP's and wysija's crons 
  464. if ( $sending_freq_has_changed ) { 
  465. // WordPress cron clearing 
  466. wp_clear_scheduled_hook( 'wysija_cron_queue' ); 
  467. // MailPoet's cron reset 
  468. WYSIJA::set_cron_schedule( 'queue' ); 
  469.  
  470. // same than above but with the bounce frequency 
  471. if ( $bouncing_freq_has_changed ) { 
  472. // WordPress cron clearing 
  473. wp_clear_scheduled_hook( 'wysija_cron_bounce' ); 
  474.  
  475. // MailPoet's cron reset 
  476. WYSIJA::set_cron_schedule( 'bounce' ); 
  477.  
  478. // if it has been saved through the interface we notify the admin 
  479. if ( $saved_through_interfaces ) { 
  480. $this->notice( __( 'Your settings are saved.', WYSIJA ) ); 
  481.  
  482.  
  483. /** 
  484. * some values in the settings needs to be overridden by ms values this is used in the getValue function 
  485. * it's a filter because of the premium plugin interacting with it 
  486. * eg bounce with ms_bounce 
  487. * @param array $ms_overriden 
  488. * @return array 
  489. */ 
  490. function ms_override( $ms_overriden ) { 
  491. if ( $this->getValue( 'premium_key' ) ) { 
  492. $bounce_value = array( 'bounce', 'bouncing' ); 
  493. return array_merge( $ms_overriden, $bounce_value ); 
  494. return $ms_overriden; 
  495.  
  496. /** 
  497. * Return a setting value from our encoded config WordPress' option 
  498. * @param string $key 
  499. * @param type $default 
  500. * @return mixed 
  501. */ 
  502. function getValue( $key, $default = false ) { 
  503.  
  504. // special case for multisite 
  505. if ( is_multisite() && $key != 'premium_key' ) { 
  506.  
  507. // if we're getting the from email value we set a default value for the ms FROM 
  508. if ( $key == 'ms_from_email' && ! isset( $this->defaults['ms_from_email'] ) ) { 
  509. $helper_toolbox = WYSIJA::get( 'toolbox', 'helper' ); 
  510. if ( is_object( $helper_toolbox ) ) { 
  511. $this->defaults['ms_from_email'] = 'info@' . $helper_toolbox->_make_domain_name( network_site_url() ); 
  512.  
  513. $values_overridden_by_multisite = array(); 
  514.  
  515. // apply a filter to add key/values to 
  516. add_filter( 'mpoet_ms_override', array( $this, 'ms_override' ), 1 ); 
  517. $values_overidden_by_bounce = apply_filters( 'mpoet_ms_override', $values_overridden_by_multisite ); 
  518.  
  519. foreach ( $values_overidden_by_bounce as $key_part_bounce ) { 
  520. if ( strpos( $key, $key_part_bounce . '_' ) !== false && strpos( $key, 'ms_' . $key_part_bounce . '_' ) === false ) { 
  521. $key = 'ms_' . $key; 
  522. break; 
  523. if ( $key == 'beta_mode' ) { 
  524. $key = 'ms_'.$key; 
  525.  
  526. if ( isset( $this->values[ $key ] ) ) { 
  527. if ( $key == 'pluginsImportableEgg' ) { 
  528. $helperImport = WYSIJA::get( 'plugins_import', 'helper', false, 'wysija-newsletters', false ); 
  529. foreach ( $this->values[ $key ] as $tablename => $plugInfosExtras ) { 
  530. $extra_data = $helperImport->getPluginsInfo( $tablename ); 
  531. if ( $extra_data ) { 
  532. $this->values[ $key ][ $tablename ] = array_merge( $extra_data, $this->values[ $key ][ $tablename ] ); 
  533. return $this->values[ $key ]; 
  534. } else { 
  535. // special case for the confirmation email 
  536. if ( in_array( $key, array( 'confirm_email_title', 'confirm_email_body' ) ) ) { 
  537. $model_email = WYSIJA::get( 'email', 'model', false, 'wysija-newsletters', false ); 
  538. $result_email = $model_email->getOne( $this->getValue( 'confirm_email_id' ) ); 
  539. if ( $result_email ) { 
  540. $this->values['confirm_email_title'] = $result_email['subject']; 
  541. $this->values['confirm_email_body'] = $result_email['body']; 
  542. return $this->values[ $key ]; 
  543. } else { 
  544. if ( $default === false && isset( $this->defaults[ $key ] ) ) { 
  545. return $this->defaults[ $key ]; 
  546. } elseif ( ! ( $default === false ) ) { 
  547. return $default; 
  548. } else { 
  549. if ( $default === false && isset( $this->defaults[ $key ] ) ) { 
  550. return $this->defaults[ $key ]; 
  551. } elseif ( ! ( $default === false ) ) { 
  552. return $default; 
  553. return false; 
  554.  
  555. /** 
  556. * TODO should this method really be here? It is used when rendering an email or when sending one 
  557. * @param type $editor 
  558. */ 
  559. function emailFooterLinks( $editor = false ) { 
  560. $unsubscribe = array(); 
  561. $unsubscribetxt = $editsubscriptiontxt = ''; 
  562.  
  563. if ( ! isset( $this->values['unsubscribe_linkname'] ) ) { 
  564. $unsubscribetxt = __( 'Unsubscribe', WYSIJA ); 
  565. } else { 
  566. $unsubscribetxt = $this->getValue( 'unsubscribe_linkname' ); 
  567.  
  568. if ( ! isset( $this->values['manage_subscriptions_linkname'] ) ) { 
  569. $editsubscriptiontxt = __( 'Edit your subscription', WYSIJA ); 
  570. } else { 
  571. $editsubscriptiontxt = $this->getValue( 'manage_subscriptions_linkname' ); 
  572.  
  573.  
  574. $unsubscribe[0] = array( 
  575. 'link' => '[unsubscribe_link]',  
  576. 'label' => $unsubscribetxt,  
  577. ); 
  578.  
  579. if ( $this->getValue( 'manage_subscriptions' ) ) { 
  580. $unsubscribe[1] = array( 
  581. 'link' => '[subscriptions_link]',  
  582. 'label' => $editsubscriptiontxt,  
  583. ); 
  584.  
  585. if ( $editor ) { 
  586. $modelU = WYSIJA::get( 'user', 'model', false, 'wysija-newsletters', false ); 
  587.  
  588. $unsubscribe[0]['link'] = $modelU->getConfirmLink( false, 'unsubscribe', false, true ) . '&demo=1'; 
  589. if ( $this->getValue( 'manage_subscriptions' ) ) { 
  590. $unsubscribe[1]['link'] = $modelU->getConfirmLink( false, 'subscriptions', false, true ); 
  591.  
  592. return $unsubscribe; 
  593.  
  594. /** 
  595. * TODO should this method really be here? 
  596. * It is used when rendering an email in the editor or before sending it 
  597. * @param boolean $editor if the link is in the editor, then it will be a demo link 
  598. * @return type 
  599. */ 
  600. function view_in_browser_link( $editor = false ) { 
  601. $data = array(); 
  602.  
  603. if(!$this->getValue('viewinbrowser')) { 
  604. return $data; 
  605.  
  606. if ( isset( $this->values['viewinbrowser_linkname'] ) ) { 
  607. // Grab the value for the view in browser link 
  608. $link = $this->values['viewinbrowser_linkname']; 
  609.  
  610. // If we don't have the value from DB load a default 
  611. if ( ! isset( $link ) || empty( $link ) || ! $link ) { 
  612. $link = esc_attr__( 'Display problems? [link]View this newsletter in your browser.[/link]', WYSIJA ); 
  613.  
  614. // if we spot a link tag in the text we decompose the text in different parts pre rendering 
  615. if ( strpos( $link, '[link]' ) !== false ) { 
  616. $linkpre = explode( '[link]', $link ); 
  617. $data['pretext'] = $linkpre[0]; 
  618. $linkpost = explode( '[/link]', $linkpre[1] ); 
  619. $data['posttext'] = $linkpost[1]; 
  620. $data['label'] = $linkpost[0]; 
  621. $data['link'] = '[view_in_browser_link]'; 
  622. }else{ 
  623. $data['pretext'] = $data['posttext'] = ''; 
  624. $data['label'] = $link; 
  625. $data['link'] = '[view_in_browser_link]'; 
  626.  
  627. if ( $editor ) { 
  628. $params_url = array( 
  629. 'wysija-page' => 1,  
  630. 'controller' => 'email',  
  631. 'action' => 'view',  
  632. 'email_id' => 0,  
  633. 'user_id' => 0,  
  634. ); 
  635. if ( ! empty( $_REQUEST['id'] ) ) { 
  636. $params_url['email_id'] = (int)$_REQUEST['id']; 
  637. $data['link'] = WYSIJA::get_permalink( $this->getValue( 'confirm_email_link' ), $params_url ); 
  638.  
  639. return $data; 
  640.  
  641. // Add a deprecation warning for this Method. 
  642. function viewInBrowserLink( $editor = false ) { 
  643. _doing_it_wrong( 'WYSIJA_model_config->viewInBrowserLink()', __( 'Use `view_in_browser_link` instead.', WYSIJA ), '2.6.10' ); 
  644. return $this->view_in_browser_link( $editor ); 
  645.