WYSIJA_control_front_confirm

The MailPoet Newsletters WYSIJA control front confirm class.

Defined (1)

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

/controllers/front/confirm.php  
  1. class WYSIJA_control_front_confirm extends WYSIJA_control_front{ 
  2. var $model='user'; 
  3. var $view='confirm'; 
  4.  
  5. function __construct() { 
  6. parent::__construct(); 
  7.  
  8. function _testKeyuser() { 
  9. $this->helperUser=WYSIJA::get('user', 'helper'); 
  10.  
  11. $this->userData=$this->helperUser->checkUserKey(); 
  12. add_action('init', array($this, 'testsession')); 
  13.  
  14. if(!$this->userData) { 
  15. $this->title=__('Page does not exist.', WYSIJA); 
  16. $this->subtitle=__('Please verify your link to this page.', WYSIJA); 
  17. return false; 
  18. return true; 
  19.  
  20. /** 
  21. * confirm subscription page 
  22. * return boolean 
  23. */ 
  24. function subscribe() { 
  25. $helper_user = WYSIJA::get('user', 'helper'); 
  26. if(!isset($_REQUEST['demo'])) { 
  27. $helper_user->confirm_user(); 
  28.  
  29. if(!empty($helper_user->title)) $this->title = $helper_user->title; 
  30. if(!empty($helper_user->subtitle)) $this->optional_subtitle = $helper_user->subtitle; 
  31. }else{ 
  32. $model_config=WYSIJA::get('config', 'model'); 
  33.  
  34. // we need to call the translation otherwise it will not be loaded and translated 
  35. $model_config->add_translated_default(); 
  36.  
  37. $this->title = sprintf($model_config->getValue('subscribed_title'), 'demo'); 
  38. $this->optional_subtitle=$model_config->getValue('subscribed_subtitle'); 
  39.  
  40. return true; 
  41.  
  42. function unsubscribe() { 
  43. remove_action( 'bp_get_request_unsubscribe', 'bp_email_unsubscribe_handler' ); 
  44. $model_config=WYSIJA::get('config', 'model'); 
  45.  
  46. // we need to call the translation otherwise it will not be loaded and translated 
  47. $model_config->add_translated_default(); 
  48.  
  49. $this->title = $model_config->getValue('unsubscribed_title'); 
  50. if(!isset($model_config->values['unsubscribed_title'])) $this->title = __("You've unsubscribed!", WYSIJA); 
  51.  
  52. $this->optional_subtitle = $model_config->getValue('unsubscribed_subtitle'); 
  53. if(!isset($model_config->values['unsubscribed_subtitle'])) $this->optional_subtitle = __("Great, you'll never hear from us again!", WYSIJA); 
  54.  
  55. $wysija_key = ''; 
  56. if(isset( $_GET['wysija-key'] )) { 
  57. $wysija_key = filter_var($_GET['wysija-key'], FILTER_SANITIZE_STRING); 
  58. $undo_paramsurl = array( 
  59. 'wysija-page' => 1,  
  60. 'controller' => 'confirm',  
  61. 'action' => 'undounsubscribe',  
  62. 'wysija-key' => $wysija_key 
  63. ); 
  64.  
  65. if(! isset($_GET['demo']) ) { 
  66. if($this->_testKeyuser()) { 
  67. $statusint=(int)$this->userData['details']['status']; 
  68. if( ($model_config->getValue('confirm_dbleoptin') && $statusint>0) || (!$model_config->getValue('confirm_dbleoptin') && $statusint>=0)) { 
  69. $listids=$this->helperUser->unsubscribe($this->userData['details']['user_id']); 
  70. $this->helperUser->uid=$this->userData['details']['user_id']; 
  71. if($model_config->getValue('emails_notified') && $model_config->getValue('emails_notified_when_unsub')) $this->helperUser->_notify($this->userData['details']['email'], false, $listids); 
  72. }else{ 
  73. $this->title=__('You are already unsubscribed.', WYSIJA); 
  74. return false; 
  75. }else{ 
  76. $undo_paramsurl['demo'] = 1; 
  77.  
  78. $link_undo = WYSIJA::get_permalink($model_config->getValue('unsubscribe_page'), $undo_paramsurl); 
  79.  
  80.  
  81. $this->undo_unsubscribe = str_replace( 
  82. array('[link]', '[/link]'),  
  83. array('<a href="'.$link_undo.'">', '</a>'),  
  84. '<p><b>'.__('You made a mistake? [link]Undo unsubscribe[/link].', WYSIJA)).'</b></p>'; 
  85. return true; 
  86.  
  87. function undounsubscribe() { 
  88. $model_config=WYSIJA::get('config', 'model'); 
  89.  
  90. // we need to call the translation otherwise it will not be loaded and translated 
  91. $model_config->add_translated_default(); 
  92.  
  93. $this->title =__("You've been subscribed!", WYSIJA); 
  94. $user_object = false; 
  95. if(!isset($_REQUEST['demo'])) { 
  96. if($this->_testKeyuser()) { 
  97. $user_object = (object)$this->userData['details']; 
  98. $this->helperUser->undounsubscribe($this->userData['details']['user_id']); 
  99.  
  100. //manage subcription link 
  101. if(($model_config->getValue('manage_subscriptions'))) { 
  102. $helper_user = WYSIJA::get('config', 'helper'); 
  103. $model_user = WYSIJA::get('user', 'model'); 
  104. $editsubscriptiontxt = $model_config->getValue('manage_subscriptions_linkname'); 
  105. if(empty($editsubscriptiontxt)) $editsubscriptiontxt =__('Edit your subscription', WYSIJA); 
  106. $this->subtitle = '<p>'.$model_user->getEditsubLink($user_object, false, '').'.</p>'; 
  107. return true; 
  108.  
  109. function subscriptions() { 
  110. $data=array(); 
  111.  
  112. //get the user_id out of the params passed 
  113. if($this->_testKeyuser()) { 
  114.  
  115. $data['user']=$this->userData; 
  116. //get the list of user 
  117. $model_list=WYSIJA::get('list', 'model'); 
  118. $model_list->orderBy('ordering', 'ASC'); 
  119. $data['list']=$model_list->get(array('list_id', 'name', 'description'), array('is_enabled'=>true, 'is_public'=>true)); 
  120.  
  121. $this->title=sprintf(__('Edit your subscriber profile: %1$s', WYSIJA), $data['user']['details']['email']); 
  122.  
  123. $this->subtitle=$this->viewObj->subscriptions($data); 
  124.  
  125. return true; 
  126.  
  127. function resend() { 
  128. $this->title = $this->subtitle = 'The link you clicked has expired'; 
  129.  
  130. function save() { 
  131.  
  132. //get the user_id out of the params passed */ 
  133. if($this->_testKeyuser()) { 
  134. //update the general details */ 
  135. if(! is_array($_REQUEST['wysija']) || !is_array($_REQUEST['wysija']['user'])) { 
  136. return false; 
  137. $userid = $this->userData['details']['user_id']; 
  138. unset($_REQUEST['wysija']['user']['user_id']); 
  139. $model_config=WYSIJA::get('config', 'model'); 
  140. // we need to call the translation otherwise it will not be loaded and translated 
  141. $model_config->add_translated_default(); 
  142. $this->helperUser->uid=$userid; 
  143. //if the status changed we might need to send notifications */ 
  144. if((int)$_REQUEST['wysija']['user']['status'] !=(int)$this->userData['details']['status']) { 
  145. if($_REQUEST['wysija']['user']['status']>0) { 
  146. if($model_config->getValue('emails_notified_when_sub')) $this->helperUser->_notify($this->userData['details']['email']); 
  147. }else{ 
  148. if($model_config->getValue('emails_notified_when_unsub')) $this->helperUser->_notify($this->userData['details']['email'], false); 
  149.  
  150. //check whether the email address has changed if so then we should make sure that the new address doesnt exists already 
  151. if(isset($_REQUEST['wysija']['user']['email'])) { 
  152. $_REQUEST['wysija']['user']['email']=trim($_REQUEST['wysija']['user']['email']); 
  153. if($this->userData['details']['email']!=$_REQUEST['wysija']['user']['email']) { 
  154. $this->modelObj->reset(); 
  155. $result=$this->modelObj->getOne(false, array('email'=>$_REQUEST['wysija']['user']['email'])); 
  156. if($result) { 
  157. $this->error(sprintf(__('Email %1$s already exists.', WYSIJA), $_REQUEST['wysija']['user']['email']), 1); 
  158. unset($_REQUEST['wysija']['user']['email']); 
  159.  
  160. $this->modelObj->update($_REQUEST['wysija']['user'], array('user_id'=>$userid)); 
  161. $id=$userid; 
  162.  
  163. $hUser=WYSIJA::get('user', 'helper'); 
  164. //update the list subscriptions */ 
  165. //run the unsubscribe process if needed 
  166. if((int)$_REQUEST['wysija']['user']['status']==-1) { 
  167. $hUser->unsubscribe($id); 
  168.  
  169. //update subscriptions */ 
  170. $modelUL=WYSIJA::get('user_list', 'model'); 
  171. $modelUL->backSave=true; 
  172. /** list of core list */ 
  173. $modelLIST=WYSIJA::get('list', 'model'); 
  174.  
  175. // Using "like" condition in order to force sql query to OR (instead of AND). It'll be incorrct if status contains other values than 0/1. 
  176. $results=$modelLIST->get(array('list_id'), array('like' => array('is_enabled'=>0, 'is_public' => 0))); 
  177. $static_listids=array(); 
  178. foreach($results as $res) { 
  179. $static_listids[]=$res['list_id']; 
  180.  
  181. //0 - get current lists of the user 
  182. $userlists=$modelUL->get(array('list_id', 'unsub_date'), array('user_id'=>$id)); 
  183.  
  184. $oldlistids=$new_list_ids=array(); 
  185. foreach($userlists as $listdata) $oldlistids[$listdata['list_id']]=$listdata['unsub_date']; 
  186.  
  187. $config=WYSIJA::get('config', 'model'); 
  188. $dbloptin=$config->getValue('confirm_dbleoptin'); 
  189. //1 - insert new user_list 
  190. if(!empty($_POST['wysija']['user_list']['list_id']) && is_array($_POST['wysija']['user_list']['list_id'])) { 
  191. $modelUL->reset(); 
  192. $modelUL->update(array('sub_date'=>time()), array('user_id'=>$id)); 
  193. foreach($_POST['wysija']['user_list']['list_id'] as $list_id) { 
  194. //if the list is not already recorded for the user then we will need to insert it 
  195. if(!isset($oldlistids[$list_id])) { 
  196. $modelUL->reset(); 
  197. $new_list_ids[]=$list_id; 
  198. $dataul=array('user_id'=>$id, 'list_id'=>$list_id, 'sub_date'=>time()); 
  199. //if double optin is on then we want to send a confirmation email for newly added subscription 
  200. if($dbloptin) { 
  201. unset($dataul['sub_date']); 
  202. $modelUL->nohook=true; 
  203. $modelUL->insert($dataul); 
  204. //if the list is recorded already then let's check the status, if it is an unsubed one then we update it 
  205. }else{ 
  206. if($oldlistids[$list_id]>0) { 
  207. $modelUL->reset(); 
  208. $modelUL->update(array('unsub_date'=>0, 'sub_date'=>time()), array('user_id'=>$id, 'list_id'=>$list_id)); 
  209. //$alreadysubscribelistids[]=$list_id; 
  210.  
  211.  
  212.  
  213.  
  214. //if a confirmation email needs to be sent then we send it 
  215.  
  216. if($dbloptin && !empty($new_list_ids)) { 
  217. $send_confirmation = true; 
  218. $send_confirmation = apply_filters('mpoet_confirm_new_list_subscriptions_page', $send_confirmation); 
  219.  
  220. if($send_confirmation === true) { 
  221. $hUser->sendConfirmationEmail($id, true, $new_list_ids); 
  222. }else{ 
  223. // this case has been made so that when subscribers add themselves to a 
  224. // list through the edit your subscription form they don't receive a confirmation email they already confirmed. 
  225. // so they receive also the autorespo, nders correspondign to that list immediately. 
  226. $helper_user = WYSIJA::get('user', 'helper'); 
  227. $_REQUEST['wysiconf'] = base64_encode(json_encode($new_list_ids)); 
  228. $helper_user->confirm_user(); 
  229.  
  230. // list ids 
  231. $list_ids = !empty($_POST['wysija']['user_list']['list_id']) ? $_POST['wysija']['user_list']['list_id'] : array(); 
  232. if(is_array($list_ids) === false) $list_ids = array(); 
  233.  
  234. $notEqual = array_merge($static_listids, $list_ids); 
  235.  
  236. //delete the lists from which you've removed yourself 
  237. $condiFirst = array('notequal'=>array('list_id'=> $notEqual), 'equal' => array('user_id' => $id, 'unsub_date' => 0)); 
  238. $modelUL=WYSIJA::get('user_list', 'model'); 
  239. $modelUL->update(array('unsub_date'=>time()), $condiFirst); 
  240. $modelUL->reset(); 
  241.  
  242. /** 
  243. Custom Fields. 
  244. */ 
  245. if (isset($_POST['wysija']['field'])) { 
  246. WJ_FieldHandler::handle_all( 
  247. $_POST['wysija']['field'], $id 
  248. ); 
  249.  
  250. $this->notice(__('Newsletter profile has been updated.', WYSIJA)); 
  251. $this->subscriptions(); 
  252.  
  253. //reset post otherwise wordpress will not recognise the post !!! 
  254. $_POST=array(); 
  255. return true;