WYSIJA_help_front

Class managing the admin vital part to integrate.

Defined (1)

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

/helpers/front.php  
  1. class WYSIJA_help_front extends WYSIJA_help{ 
  2.  
  3. function __construct() { 
  4. parent::__construct(); 
  5.  
  6. // wysija form shortcode 
  7. add_shortcode('wysija_form', array($this, 'scan_form_shortcode')); 
  8. // wysija total of subscribers shortcode 
  9. add_shortcode('wysija_subscribers_count', array($this, 'scan_subscribers_count_shortcode')); 
  10.  
  11. // init shortcode [wysija_archive] 
  12. require_once(WYSIJA_CORE.'controller.php'); 
  13. require_once(WYSIJA_CORE.'module'.DS.'module.php');// @todo: move to autoloader 
  14. $archive_std = WYSIJA_module::get_instance_by_name('archive_std');// implement hook "wysija_front_init() 
  15. if (!empty($archive_std) && is_a($archive_std, 'WYSIJA_module')) 
  16. $archive_std->front_init(); 
  17.  
  18. /** We try to process the least possible code */ 
  19. if(isset($_REQUEST['wysija-page']) || isset($_REQUEST['wysija-launch'])) { 
  20.  
  21. if(defined('DOING_AJAX')) { 
  22. add_action('wp_ajax_nopriv_wysija_ajax', array($this, 'ajax')); 
  23. }else{ 
  24. $paramscontroller=$_REQUEST['controller']; 
  25. //this is an exception on one server this params stats was not accepted 
  26. if($paramscontroller=='stat') $paramscontroller='stats'; 
  27.  
  28. $this->controller=WYSIJA::get($paramscontroller, 'controller'); 
  29. if(isset($_REQUEST['action']) && method_exists($this->controller, $_REQUEST['action'])) { 
  30. add_action('init', array($this->controller, $_REQUEST['action'])); 
  31. //$this->controller->$_REQUEST['action'](); 
  32. }else $this->error('Action does not exist.'); 
  33.  
  34. if(isset($_REQUEST['wysija-page'])) { 
  35. /** set the content filter to replace the shortcode */ 
  36. add_filter('wp_title', array($this, 'meta_page_title')); 
  37. add_filter( 'the_title', array($this, 'scan_title')); 
  38. add_filter( 'the_content', array($this, 'scan_content'), 98); 
  39. if(isset($_REQUEST['message_success'])) { 
  40. add_filter( 'the_content', array($this, 'scan_content_NLform'), 99 ); 
  41. }else{ 
  42. add_filter('the_content', array($this, 'scan_content_NLform'), 99 ); 
  43. //if the comment form checkbox option is activated we add some hooks to process it 
  44. $model_config = WYSIJA::get('config', 'model'); 
  45. if($model_config->getValue('commentform')) { 
  46. add_action('comment_form', array($this, 'comment_form_extend')); 
  47. add_action('comment_post', array($this, 'comment_posted'), 60, 2); 
  48.  
  49. // if the register form checkbox option is activated we add some hooks to process it 
  50. if($model_config->getValue('registerform')) { 
  51. if(is_multisite()) { 
  52. add_action('signup_extra_fields', array($this, 'register_form_extend')); 
  53. // we need this condition otherwise we will send two confirmation emails when on ms with buddypress 
  54. if(!WYSIJA::is_plugin_active('buddypress/bp-loader.php')) { 
  55. add_filter('wpmu_validate_user_signup', array($this, 'registerms_posted'), 60, 3); 
  56. }else{ 
  57. add_action('register_form', array($this, 'register_form_extend')); 
  58. add_action('register_post', array($this, 'register_posted'), 60, 3); 
  59.  
  60. // special case when buddypress is activated 
  61. if(WYSIJA::is_plugin_active('buddypress/bp-loader.php')) { 
  62. add_action('bp_after_signup_profile_fields', array($this, 'register_form_bp_extend')); 
  63. add_action('bp_signup_validate', array($this, 'register_bp'), 60, 3); 
  64.  
  65. // we can have just one confirmation email for the wp user and the wysija confirmation when bp and multisite are activated 
  66. if(is_multisite()) { 
  67. add_action('wpmu_activate_user', array($this, 'wpmu_activate_user')); 
  68.  
  69. /** 
  70. * In MS when user account is activated we auto confirm the subscriber 
  71. * @param type $wpuser_id 
  72. * @return boolean 
  73. */ 
  74. function wpmu_activate_user($wpuser_id) { 
  75. if((int)$wpuser_id>0) { 
  76. $model_user = WYSIJA::get('user', 'model'); 
  77. $result_subscriber = $model_user->getOne(false , array('wpuser_id'=>$wpuser_id)); 
  78.  
  79. if(!empty($result_subscriber)) { 
  80. $helper_user = WYSIJA::get('user', 'helper'); 
  81. $helper_user->confirm_user($result_subscriber['user_id']); 
  82. return true; 
  83.  
  84. function meta_page_title($title) { 
  85. //Here I can echo the result and see that it's actually triggered 
  86. if($this->is_default_mailpoet_page()) { 
  87. // when user have kept the default page we modify the title based on the controller 
  88. if(!empty($this->controller->title)) return $this->controller->title; 
  89.  
  90. return $title; 
  91.  
  92.  
  93.  
  94. function register_form_bp_extend() { 
  95. if ( !is_user_logged_in()) { 
  96. $this->register_form_extend(); 
  97.  
  98. function register_form_extend() { 
  99. $checkbox= '<p class="wysija-after-register">'; 
  100. $checkbox.='<label for="wysija-box-after-register">'; 
  101. $checkbox.='<input type="checkbox" id="wysija-box-after-register" value="1" name="wysija[register_subscribe]">'; 
  102. $mConfig=WYSIJA::get('config', 'model'); 
  103. $checkbox.=$mConfig->getValue('registerform_linkname').'</label></p>'; 
  104.  
  105. echo '<div class="register-section" id="profile-details-section-wysija"><div class="editfield">'.$checkbox.'</div></div>'; 
  106.  
  107.  
  108. function register_bp() { 
  109. global $bp; 
  110.  
  111. if ( !isset($bp->signup->errors) && isset($_POST['wysija']['register_subscribe']) && $_POST['wysija']['register_subscribe'] ) { 
  112. $model_config=WYSIJA::get('config', 'model'); 
  113. $helper_user=WYSIJA::get('user', 'helper'); 
  114. $data=array('user'=>array('email'=>$bp->signup->email), 'user_list'=>array('list_ids'=>$model_config->getValue('registerform_lists'))); 
  115.  
  116. if(is_multisite()) { 
  117. $helper_user->no_confirmation_email=true; 
  118.  
  119. $helper_user->addSubscriber($data); 
  120.  
  121. function registerms_posted($result) { 
  122. if ( empty($result['errors']->errors) && isset($_POST['wysija']['register_subscribe']) && $_POST['wysija']['register_subscribe']) { 
  123. $mConfig=WYSIJA::get('config', 'model'); 
  124. $userHelper=WYSIJA::get('user', 'helper'); 
  125. $data=array('user'=>array('email'=>$result['user_email']), 'user_list'=>array('list_ids'=>$mConfig->getValue('registerform_lists'))); 
  126. $userHelper->addSubscriber($data); 
  127.  
  128. return $result; 
  129.  
  130. function register_posted($login, $email, $errors) { 
  131.  
  132. if ( empty($errors->errors) && isset($_POST['wysija']['register_subscribe']) && $_POST['wysija']['register_subscribe']) { 
  133. $mConfig=WYSIJA::get('config', 'model'); 
  134. $userHelper=WYSIJA::get('user', 'helper'); 
  135. $data=array('user'=>array('email'=>$email), 'user_list'=>array('list_ids'=>$mConfig->getValue('registerform_lists'))); 
  136. $userHelper->addSubscriber($data); 
  137.  
  138.  
  139. function comment_form_extend() { 
  140. echo '<p class="wysija-after-comment">'; 
  141. echo '<label for="wysija-box-after-comment">'; 
  142. echo '<input type="checkbox" id="wysija-box-after-comment" value="1" name="wysija[comment_subscribe]">'; 
  143. $mConfig=WYSIJA::get('config', 'model'); 
  144. echo $mConfig->getValue('commentform_linkname').'</label></p>'; 
  145.  
  146. function comment_posted($cid, $comment) { 
  147. $cid = (int) $cid; 
  148. if ( !is_object($comment) ) 
  149. $comment = get_comment($cid); 
  150.  
  151. //before recording the subscriber, make sure that it is not a spam comment or it needs to be approved first 
  152. if($comment->comment_approved=='spam') return; 
  153.  
  154. if(isset($_POST['wysija']['comment_subscribe']) && $_POST['wysija']['comment_subscribe']) { 
  155. if($comment->comment_approved=='0') add_comment_meta($cid, 'wysija_comment_subscribe', 1); 
  156. else{ 
  157. $mConfig=WYSIJA::get('config', 'model'); 
  158. $userHelper=WYSIJA::get('user', 'helper'); 
  159. $data=array('user'=>array('email'=>$comment->comment_author_email, 'firstname'=>$comment->comment_author), 'user_list'=>array('list_ids'=>$mConfig->getValue('commentform_lists'))); 
  160. $userHelper->addSubscriber($data); 
  161.  
  162. function scan_title($title) { 
  163. /**careful WordPress global*/ 
  164. global $post; 
  165.  
  166. if($this->is_default_mailpoet_page()) { 
  167. // when user have kept the default page we modify the title based on the controller 
  168. if(trim($title)==trim(single_post_title( '', false )) && !empty($this->controller->title)) { 
  169. $post->comment_status='close'; 
  170. $post->post_password=''; 
  171. return $this->controller->title; 
  172.  
  173. return $title; 
  174.  
  175.  
  176. function scan_content($content) { 
  177. $wysija_content = $wysija_undo = ''; 
  178. if(!empty($this->controller->subtitle)) $wysija_content = $this->controller->subtitle; 
  179. if(!empty($this->controller->optional_subtitle)) $wysija_content = $this->controller->optional_subtitle; 
  180. if(!empty($this->controller->undo_unsubscribe)) { 
  181. $wysija_undo = $this->controller->undo_unsubscribe; 
  182.  
  183. // only force our edit subscription screen at the bottom of the content of the page 
  184. // if it's the right action and there is no wysija_page shortcode in teh page 
  185. if(!empty($_REQUEST['action']) && $_REQUEST['action'] == 'subscriptions' && strpos($content, '[wysija_page]') === false) { 
  186. // we append the subscription form at the bottom of the page if we can't detect it 
  187. return $content.'<div class="mpoet_profile_edit">'.$wysija_content.'</div>'; 
  188. }else{ 
  189. // we replace the shortcode by our automatic content, other wise if there is no shortcode the page stays the same 
  190. return str_replace('[wysija_page]', $wysija_content.$wysija_undo, $content); 
  191.  
  192.  
  193. function is_default_mailpoet_page() { 
  194. global $post; 
  195. $model_config = WYSIJA::get('config', 'model'); 
  196. if($post->ID == $model_config->getValue('confirm_email_link')) return true; 
  197. else return false; 
  198.  
  199. /** 
  200. * this is for the new kind of shortcodes [wysija_form form="1"] 
  201. * @param array $attributes 
  202. * @return string html 
  203. */ 
  204. function scan_form_shortcode($attributes) { 
  205. // IMPORTANT: this is to make sure MagicMember won't scan our form and find [user_list] as a code they should replace. 
  206. remove_shortcode('user_list'); 
  207.  
  208. if(isset($attributes['id']) && (int)$attributes['id']>0) { 
  209. $widget_data=array(); 
  210. $widget_data['form']=(int)$attributes['id']; 
  211. $widget_data['form_type'] = 'shortcode'; 
  212.  
  213. $widget_NL=new WYSIJA_NL_Widget(true); 
  214. return $widget_NL->widget($widget_data); 
  215.  
  216. return ''; 
  217.  
  218.  
  219. /** 
  220. * this is for the new kind of shortcodes [wysija_form form="1"] 
  221. * @param array $attributes 
  222. * @return string html 
  223. */ 
  224. function scan_subscribers_count_shortcode($attributes) { 
  225. $user = WYSIJA::get('user', 'model'); 
  226. $list_ids = !empty($attributes['list_id']) ? explode(', ', $attributes['list_id']) : array(); 
  227.  
  228. // if double optin is on we count only the confirmed subscribers, otherwise we count both confirmed and unconfirmed 
  229. $confirmed_subscribers = false; 
  230. $model_config = WYSIJA::get('config', 'model'); 
  231. if ($model_config->getValue('confirm_dbleoptin')) { 
  232. $confirmed_subscribers = true; 
  233.  
  234. return $user->countSubscribers($list_ids, $confirmed_subscribers); 
  235.  
  236. function scan_content_NLform($content) { 
  237. preg_match_all('/\<div class="wysija-register">(.*?)\<\/div>/i', $content, $matches); 
  238. if(!empty($matches[1]) && count($matches[1])>0) require_once(WYSIJA_WIDGETS.'wysija_nl.php'); 
  239. foreach($matches[1] as $key => $mymatch) { 
  240. if($mymatch) { 
  241. $widgetdata=unserialize(base64_decode($mymatch)); 
  242. $widgetNL=new WYSIJA_NL_Widget(true); 
  243. $contentTABLE= $widgetNL->widget($widgetdata, $widgetdata); 
  244. $content=str_replace($matches[0][$key], $contentTABLE, $content); 
  245. }//endif 
  246. }//endforeach 
  247. return $content; 
  248.