WYSIJA_control_front_subscribers

The MailPoet Newsletters WYSIJA control front subscribers class.

Defined (1)

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

/controllers/front/subscribers.php  
  1. class WYSIJA_control_front_subscribers extends WYSIJA_control_front{ 
  2. var $model='user'; 
  3. var $view='widget_nl'; 
  4.  
  5. function __construct() { 
  6. parent::__construct(); 
  7. if(isset($_REQUEST['message_success'])) { 
  8. $this->messages['insert'][true]=$_REQUEST['message_success']; 
  9. }else{ 
  10. $this->messages['insert'][true]=__('User has been inserted.', WYSIJA); 
  11.  
  12. $this->messages['insert'][false]=__('User has not been inserted.', WYSIJA); 
  13. $this->messages['update'][true]=__('User has been updated.', WYSIJA); 
  14. $this->messages['update'][false]=__('User has not been updated.', WYSIJA); 
  15.  
  16. function save() { 
  17. $config=WYSIJA::get('config', 'model'); 
  18.  
  19. if(!$config->getValue('allow_no_js')) { 
  20. $this->notice(__('Subscription without JavaScript is disabled.', WYSIJA)); 
  21. return false; 
  22.  
  23. if(isset($_REQUEST['wysija']['user_list']['list_id'])) { 
  24. $_REQUEST['wysija']['user_list']['list_ids']=$_REQUEST['wysija']['user_list']['list_id']; 
  25. unset($_REQUEST['wysija']['user_list']['list_id']); 
  26. }elseif(isset($_REQUEST['wysija']['user_list']['list_ids'])) { 
  27. $_REQUEST['wysija']['user_list']['list_ids']=explode(', ', $_REQUEST['wysija']['user_list']['list_ids']); 
  28. $_REQUEST['wysija']['user_field'] = $_REQUEST['wysija']['field']; 
  29. $data=$_REQUEST['wysija']; 
  30. unset($_REQUEST['wysija']); 
  31.  
  32. foreach($_REQUEST as $key => $val) { 
  33. if(!isset($data[$key])) $data[$key]=$val; 
  34.  
  35. $helperUser=WYSIJA::get('user', 'helper'); 
  36. if(!$helperUser->checkData($data))return false; 
  37.  
  38. $helperUser->addSubscriber($data); 
  39.  
  40. return true; 
  41.  
  42. /** 
  43. * handles the form generation in iframe mode, basically wysija's iframes call that action to generate the html of the body 
  44. */ 
  45. function wysija_outter() { 
  46.  
  47. //params used to generate the html in the widget class 
  48. $widget_data=array(); 
  49.  
  50. if(isset($_REQUEST['wysija_form']) && (int)$_REQUEST['wysija_form'] > 0) { 
  51. // this a wysija form made with the form editor 
  52. // if it's a preview, we need to dynamically render the form 
  53. // get form data 
  54.  
  55. $widget_data['form']=(int)$_REQUEST['wysija_form']; 
  56. $widget_data['form_type']='iframe'; 
  57.  
  58. } else { 
  59.  
  60. //this is the old way, we need to keep it for backward compatibility 
  61. if(isset($_REQUEST['encodedForm'])) { 
  62. $encoded_form=json_decode(base64_decode(urldecode($_REQUEST['encodedForm']))); 
  63. } else { 
  64. if(isset($_REQUEST['fullWysijaForm'])) { 
  65. $encoded_form=json_decode(base64_decode(urldecode($_REQUEST['fullWysijaForm']))); 
  66. } else { 
  67. if(isset($_REQUEST['widgetnumber'])) { 
  68.  
  69. $widgets=get_option('widget_wysija'); 
  70. if(isset($widgets[$_REQUEST['widgetnumber']])) { 
  71. $encoded_form=$widgets[$_REQUEST['widgetnumber']]; 
  72.  
  73. }else{ 
  74. $encoded_form=$_REQUEST['formArray']; 
  75. $encoded_form=stripslashes_deep($encoded_form); 
  76.  
  77.  
  78.  
  79. //fill the widget data array based on the parameters found earlier 
  80. if($encoded_form) { 
  81. foreach($encoded_form as $key =>$val) { 
  82. if (in_array($key, array('before_widget', 'after_widget', 'before_title', 'title', 'after_title'))) { 
  83. $val = sanitize_text_field($val); 
  84. $widget_data[$key]=$val; 
  85.  
  86. //if the value is an object we need to loop through and make an array of it 
  87. //I think we could simply cast the object as an array not sure if that works on objects within objects... 
  88. if(is_object($val)) { 
  89. $object_to_array=array(); 
  90. foreach($val as $key_in =>$val_in) { 
  91. $object_to_array[$key_in]=$val_in; 
  92. if(is_object($val_in)) { 
  93. $object_to_array_second_level=array(); 
  94. foreach($val_in as $k_in => $v_in) { 
  95. $object_to_array_second_level[$k_in]=$v_in; 
  96. $object_to_array[$key_in]=$object_to_array_second_level; 
  97. $widget_data[$key]=$object_to_array; 
  98. }else{ 
  99. if(current_user_can('switch_themes')) echo '<b>'.str_replace(array('[link]', '[/link]'), array('<a target="_blank" href="'. admin_url('widgets.php').'">', '</a>'), __('It seems your widget has been deleted from the WordPress\' [link]widgets area[/link].', WYSIJA)).'</b>'; 
  100. exit; 
  101.  
  102. //create a unique identifier for the form (the old way) 
  103. if(isset($_REQUEST['widgetnumber'])) $form_identifier=$_REQUEST['widgetnumber']; 
  104. else $form_identifier=rand(5, 1500); 
  105. $widget_data['widget_id']='wysija-nl-iframe-'.$form_identifier; 
  106.  
  107.  
  108. require_once(WYSIJA_WIDGETS.'wysija_nl.php'); 
  109. $widget_NL=new WYSIJA_NL_Widget(true); 
  110. $widget_NL->iFrame=true; 
  111. $subscription_form = $widget_NL->widget($widget_data, $widget_data); 
  112. $subscription_form = str_replace("</head>", '<script type="text/javascript"> 
  113. /* <![CDATA[ */ 
  114. var wysijaAJAX = {"action":"wysija_ajax", "controller":"subscribers", "ajaxurl":"'.admin_url('admin-ajax.php', 'absolute').'", "loadingTrans":"'.__('Loading...', WYSIJA).'"}; 
  115. /* ]]> */ 
  116. </script></head>', $subscription_form); 
  117. echo $subscription_form; 
  118. exit; 
  119.