WYSIJA_control_front_stats

The MailPoet Newsletters WYSIJA control front stats class.

Defined (1)

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

/controllers/front/stats.php  
  1. class WYSIJA_control_front_stats extends WYSIJA_control_front{ 
  2. var $model='' ; 
  3. var $view=''; 
  4.  
  5. /** 
  6. * Possible characters to be url encoded 
  7. * @var array 
  8. */ 
  9. protected $characters_to_encode = array( 
  10. '@' 
  11. ); 
  12.  
  13. function __construct() { 
  14. parent::__construct(); 
  15.  
  16. /** 
  17. * count the click statistic and redirect to the right url 
  18. * @return boolean 
  19. */ 
  20. function analyse() { 
  21. if(isset($_REQUEST['email_id']) && isset($_REQUEST['user_id'])) { 
  22. $WJ_Stats = new WJ_Stats(); 
  23. if(!empty($WJ_Stats->clicked_url)) { 
  24. // clicked stats 
  25. $url = $this->encode_url($WJ_Stats->subscriber_clicked()); 
  26. $external_url_unescaped_and_without_utm = preg_replace('!/?\?utm.*!i', '', $url); 
  27. $external_url_escaped_and_without_utm = preg_replace('!/?\?utm.*!i', '', htmlentities($WJ_Stats->subscriber_clicked())); // remove anything that starts with ?utm or /?utm 
  28. $internal_site_url = preg_replace('!https?://!i', '', htmlentities(get_site_url())); 
  29. $internal_home_url = preg_replace('!https?://!i', '', htmlentities(get_home_url())); 
  30. $model_email = WYSIJA::get('email', 'model'); 
  31. $email_object = $model_email->getOne(false, array('email_id' => $_REQUEST['email_id'])); 
  32. if (preg_match('!'. preg_quote($external_url_unescaped_and_without_utm, '!') .'!i', $email_object['body']) || 
  33. preg_match('!'. preg_quote($external_url_escaped_and_without_utm, '!') .'!i', $email_object['body']) || 
  34. preg_match('!^https?://'. preg_quote($internal_site_url, '!') .'!i', $url) || 
  35. preg_match('!^https?://'. preg_quote($internal_home_url, '!') .'!i', $url) 
  36.  
  37. ) { 
  38. do_action('mpoet_click_stats', $WJ_Stats); 
  39. $this->redirect($url); 
  40. header('HTTP/1.0 404 Not Found'); 
  41. echo '<h1>404 Not Found</h1>'; 
  42. echo 'The page that you have requested could not be found.'; 
  43. exit(); 
  44. }else{ 
  45. // opened stat 
  46. $WJ_Stats->subscriber_opened(); 
  47.  
  48. return true; 
  49.  
  50. /** 
  51. * Encode some special characters in url 
  52. * @param string $url 
  53. * @return string 
  54. */ 
  55. protected function encode_url($url) { 
  56. return str_replace( 
  57. $this->characters_to_encode,  
  58. array_map('urlencode', $this->characters_to_encode),  
  59. $url 
  60. ); 
  61.