WYSIJA_view_front_widget_nl

The MailPoet Newsletters WYSIJA view front widget nl class.

Defined (1)

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

/views/front/widget_nl.php  
  1. class WYSIJA_view_front_widget_nl extends WYSIJA_view_front { 
  2.  
  3. function __construct() { 
  4. $this->model=WYSIJA::get('user', 'model'); 
  5.  
  6. function wrap( $content ) { 
  7. $attributes = array(); 
  8.  
  9. if ( function_exists( 'is_rtl' ) && is_rtl() ) { 
  10. $attributes[] = 'dir="rtl"'; 
  11.  
  12. if ( $lang = get_bloginfo( 'language' ) ) { 
  13. if ( get_option( 'html_type' ) == 'text/html' ) { 
  14. $attributes[] = "lang=\"$lang\""; 
  15.  
  16. /** 
  17. * Filter the language attributes for display in the html tag. 
  18. * @since 2.6.7.1 
  19. * @param string $output A space-separated list of language attributes. 
  20. */ 
  21. $language_attributes = apply_filters( 'language_attributes', implode( ' ', $attributes ) ); 
  22.  
  23.  
  24. // We need to find a way to remove this ob_start... 
  25. ob_start(); 
  26. wp_print_scripts('jquery'); 
  27. wp_print_styles('validate-engine-css'); 
  28. if(isset($_REQUEST['external_site'])) { 
  29. $iframeJsUrl=$iframeCssUrl=false; 
  30. //check if an iframe.css file exists in the site uploads/wysija/css/iframe.css or in MS blogs.dir/5/files/wysija/css/iframe.css 
  31. if(file_exists(WYSIJA_UPLOADS_DIR.'css'.DS.'iframe.css')) { 
  32. $iframeCssUrl=WYSIJA_UPLOADS_URL.'css/iframe.css'; 
  33. }else{ 
  34. //if we are in a multisite check to see if there is a file defined in the main site 
  35. if(is_multisite() && file_exists(WYSIJA_UPLOADS_MS_DIR.'css'.DS.'iframe.css')) { 
  36. $iframeCssUrl=WYSIJA_UPLOADS_MS_URL.'css/iframe.css'; 
  37. $iframeCssUrl = apply_filters('wysija_iframe_css_url', $iframeCssUrl); 
  38.  
  39. //check if an iframe.js file exists in the site uploads/wysija/js/iframe.js or in MS blogs.dir/5/files/wysija/js/iframe.js 
  40. if(file_exists(WYSIJA_UPLOADS_DIR.'js'.DS.'iframe.js')) { 
  41. $iframeJsUrl=WYSIJA_UPLOADS_URL.'js/iframe.js'; 
  42. }else{ 
  43. //if we are in a multisite check to see if there is a file defined in the main site 
  44. if(is_multisite() && file_exists(WYSIJA_UPLOADS_MS_DIR.'js'.DS.'iframe.js')) { 
  45. $iframeJsUrl=WYSIJA_UPLOADS_MS_URL.'js/iframe.js'; 
  46. $iframeJsUrl = apply_filters('wysija_iframe_js_url', $iframeJsUrl); 
  47.  
  48. //if an iframe file has been detected then load it 
  49. if($iframeCssUrl) { 
  50. wp_register_style('wysija-iframe-css', $iframeCssUrl, array(), WYSIJA::get_version()); 
  51. wp_print_styles('wysija-iframe-css'); 
  52.  
  53. //if an iframe js file has been detected then load it 
  54. if($iframeJsUrl) { 
  55. wp_register_style('wysija-iframe-js', $iframeJsUrl, array(), WYSIJA::get_version()); 
  56. wp_print_styles('wysija-iframe-js'); 
  57. wp_print_scripts('wysija-validator-lang'); 
  58. wp_print_scripts('wysija-validator'); 
  59. wp_print_scripts('wysija-front-subscribers'); 
  60. wp_print_scripts('jquery-ui-datepicker'); 
  61.  
  62. $scripts_html .= ob_get_contents(); 
  63. ob_end_clean(); 
  64.  
  65. $html = 
  66. '<!DOCTYPE html>' . 
  67. '<!--[if lt IE 7]> <html class="no-js ie6 oldie" ' . $language_attributes . '> <![endif]-->' . 
  68. '<!--[if IE 7]> <html class="no-js ie7 oldie" ' . $language_attributes . '> <![endif]-->' . 
  69. '<!--[if IE 8]> <html class="no-js ie8 oldie" ' . $language_attributes . '> <![endif]-->' . 
  70. '<!--[if gt IE 8]><!--> <html ' . $language_attributes . '> <!--<![endif]-->' . 
  71. '<head>' . 
  72. '<meta name="robots" content="noindex, nofollow">' . 
  73. '<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">' . 
  74. '<meta charset="' . get_bloginfo( 'charset' ) . '" />' . 
  75. '<title>' . __( 'MailPoet Subscription Form', WYSIJA ) . '</title>' . 
  76. $scripts_html . 
  77. '</head>' . 
  78. '<body>' . 
  79. '<div class="' . esc_attr( implode( ' ', array( 'wysija-frame', ( isset( $_REQUEST['external_site'] ) ? '' : 'iframe-hidden' ) ) ) ) . '" >' . 
  80. $content . 
  81. '</div>' . 
  82. '</body>' . 
  83. '</html>'; 
  84.  
  85. return $html; 
  86.  
  87. function display($title='', $params, $echo=true, $iframe=false) { 
  88.  
  89. if ( ! $iframe ) { 
  90. wp_enqueue_script( 'wysija-validator-lang' ); 
  91. wp_enqueue_script( 'wysija-validator' ); 
  92. wp_enqueue_script( 'wysija-front-subscribers' ); 
  93. wp_enqueue_style( 'validate-engine-css' ); 
  94. $data = ''; 
  95. $label_email = ''; 
  96. $form_id_real = 'form-'.$params['id_form']; 
  97.  
  98. $data.= $title; 
  99. $list_fields_hidden=$list_fields=''; 
  100. $disabled_submit=$msg_success_preview=''; 
  101.  
  102. // set specific class depending on form type (shortcode, iframe, html) 
  103. $extra_class = ''; 
  104. if(isset($params['form_type'])) { 
  105. $extra_class = ' '.$params['form_type'].'_wysija'; 
  106.  
  107. $data.='<div class="widget_wysija_cont'.$extra_class.'">'; 
  108.  
  109. //if data has been posted the classique php/HTML way we display the result straight in good old HTML 
  110. if(isset($_POST['wysija']['user']['email']) && isset($_POST['formid']) && $form_id_real==$_POST['formid']) { 
  111. $data.= str_replace ('class="wysija-msg', 'id="msg-'.$form_id_real.'" class="wysija-msg', $this->messages()); 
  112. }else{ 
  113. $data.='<div id="msg-'.$form_id_real.'" class="wysija-msg ajax">'.$msg_success_preview.'</div>'; 
  114.  
  115. // A form built with the form editor has been selected 
  116. if(isset($params['form']) && (int)$params['form'] > 0) { 
  117.  
  118. // get form data 
  119. $model_forms = WYSIJA::get('forms', 'model'); 
  120. $form = $model_forms->getOne(array('form_id' => (int)$params['form'])); 
  121.  
  122. // if the form exists 
  123. if(!empty($form)) { 
  124. // load form data into form engine 
  125. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  126. $helper_form_engine->set_data($form['data'], true); 
  127.  
  128. // get html rendering of form 
  129. $form_html = $helper_form_engine->render_web(); 
  130.  
  131. // replace shortcodes 
  132. if(strpos($form_html, '[total_subscribers]') !== FALSE) { 
  133. $model_config = WYSIJA::get('config', 'model'); 
  134. // replace total subscribers shortcode by actual value 
  135. $form_html = str_replace('[total_subscribers]', number_format($model_config->getValue('total_subscribers'), 0, '.', ' '), $form_html); 
  136.  
  137. // IMPORTANT: we remove the ones that could break our subscription form 
  138. // These resolve the conflict with Ultimate Shortcodes 
  139. remove_shortcode('user'); 
  140. remove_shortcode('user_list'); 
  141. remove_shortcode('list_ids'); 
  142. remove_shortcode('list_id'); 
  143. remove_shortcode('firstname'); 
  144. remove_shortcode('lastname'); 
  145. remove_shortcode('email'); 
  146. remove_shortcode('custom'); 
  147. remove_shortcode('required'); 
  148.  
  149. // These resolve the conflict with Ultimate TinyMCE 
  150. remove_shortcode('field'); 
  151.  
  152. // interpret shortcodes 
  153. $form_html = do_shortcode($form_html); 
  154.  
  155. $data .= '<form id="'.$form_id_real.'" method="post" action="#wysija" class="widget_wysija'.$extra_class.'">'; 
  156. $data .= $form_html; 
  157. $data .= '</form>'; 
  158. } else { 
  159.  
  160. // What is included in this Else condition is only for retrocompatibility we should move it maybe to another file at some point as deprecated 
  161.  
  162. $data .= '<form id="'.$form_id_real.'" method="post" action="#wysija" class="widget_wysija form-valid-sub">'; 
  163.  
  164. if(isset($params['instruction']) && $params['instruction']) { 
  165. if(strpos($params['instruction'], '[total_subscribers') !== false) { 
  166. $modelC=WYSIJA::get('config', 'model'); 
  167. $totalsubscribers= str_replace(', ', ' ', number_format($modelC->getValue('total_subscribers'))); 
  168.  
  169. $params['instruction']=str_replace('[total_subscribers]', $totalsubscribers, $params['instruction']); 
  170. $data.='<p class="wysija-instruct">'.$params['instruction'].'</p>'; 
  171.  
  172.  
  173. if(isset($params['autoregister']) && $params['autoregister']=='auto_register') { 
  174. $list_fields='<div class="wysija_lists">'; 
  175. $i=0; 
  176. foreach($params['lists'] as $list_id) { 
  177. $list_fields.='<p class="wysija_list_check"> 
  178. <label for="'.$form_id_real.'_list_id_'.$list_id.'"><input id="'.$form_id_real.'_list_id_'.$list_id.'" class="validate[minCheckbox[1]] checkbox checklists" type="checkbox" name="wysija[user_list][list_id][]" value="'.$list_id.'" checked="checked" /> '.$params['lists_name'][$list_id].' </label> 
  179. </p>'; 
  180. $i++; 
  181. $list_fields.='</div>'; 
  182.  
  183. }else{ 
  184.  
  185. if(isset($params['lists'])) $list_exploded=esc_attr(implode(', ', $params['lists'])); 
  186. else $list_exploded=''; 
  187.  
  188. $list_fields_hidden='<input type="hidden" name="wysija[user_list][list_ids]" value="'.$list_exploded.'" />'; 
  189.  
  190. $submit_value = (!empty($params['submit'])) ? $params['submit'] : __('Submit', WYSIJA); 
  191. $submitbutton=$list_fields.'<input type="submit" '.$disabled_submit.' class="wysija-submit wysija-submit-field" name="submit" value="'.esc_attr($submit_value).'"/>'; 
  192. $dataCf=$this->customFields($params, $form_id_real, $submitbutton); 
  193.  
  194. if($dataCf) { 
  195. $data.=$dataCf; 
  196.  
  197. }else{ 
  198. $user_email=WYSIJA::wp_get_userdata('user_email'); 
  199. $value_attribute=''; 
  200. if(is_user_logged_in() && !current_user_can('switch_themes') && !is_admin() && $user_email && is_string($user_email)) { 
  201. $value_attribute=$user_email; 
  202.  
  203. $classValidate='wysija-email '.$this->getClassValidate($this->model->columns['email'], true); 
  204. $data.='<p><input type="text" id="'.$form_id_real.'-wysija-to" class="'.$classValidate.'" value="'.$value_attribute.'" name="wysija[user][email]" />'; 
  205. $data.=$this->honey($params, $form_id_real); 
  206. $data.=$submitbutton.'</p>'; 
  207.  
  208. $success_value = (!empty($params['success'])) ? $params['success'] : __('Success', WYSIJA); 
  209. // few hiddn field 
  210. $data.='<input type="hidden" name="formid" value="'.esc_attr($form_id_real).'" /> 
  211. <input type="hidden" name="action" value="save" /> 
  212. '.$list_fields_hidden.' 
  213. <input type="hidden" name="message_success" value="'.esc_attr($success_value).'" /> 
  214. <input type="hidden" name="controller" value="subscribers" />'; 
  215. $data.='<input type="hidden" value="1" name="wysija-page" />'; 
  216.  
  217. $data.='</form>'; 
  218.  
  219. //hook to let plugins modify our html the way they want 
  220. $data = apply_filters('wysija_subscription_form', $data); 
  221. $data.='</div>'; 
  222. if($echo) echo $data; 
  223. else return $data; 
  224.  
  225. function customFields($params, $formidreal, $submitbutton) { 
  226. $html=''; 
  227. $validationsCF=array( 
  228. 'email' => array('req'=>true, 'type'=>'email', 'defaultLabel'=>__('Email', WYSIJA)),  
  229. 'firstname' => array('req'=>true, 'defaultLabel'=>__('First name', WYSIJA)),  
  230. 'lastname' => array('req'=>true, 'defaultLabel'=>__('Last name', WYSIJA)),  
  231. ); 
  232.  
  233. $wp_user_values=array(); 
  234. if(is_user_logged_in() && !is_admin() && !current_user_can('switch_themes')) { 
  235. $data_user_wp=WYSIJA::wp_get_userdata(); 
  236. if(isset($data_user_wp->user_email))$wp_user_values['email']=$data_user_wp->user_email; 
  237. if(isset($data_user_wp->user_firstname))$wp_user_values['firstname']=$data_user_wp->user_firstname; 
  238. if(isset($data_user_wp->user_lastname))$wp_user_values['lastname']=$data_user_wp->user_lastname; 
  239.  
  240.  
  241. if(isset($params['customfields']) && $params['customfields']) { 
  242. foreach($params['customfields'] as $fieldKey=> $field) { 
  243.  
  244. //autofill logged in user data 
  245. $value_attribute=''; 
  246. if(isset($wp_user_values[$fieldKey])) { 
  247. $value_attribute=$wp_user_values[$fieldKey]; 
  248.  
  249. $classField='wysija-'.$fieldKey; 
  250. $classValidate=$classField." ".$this->getClassValidate($validationsCF[$fieldKey], true); 
  251. if(!isset($field['label']) || !$field['label']) $field['label']=$validationsCF[$fieldKey]['defaultLabel']; 
  252. if($fieldKey=='email') $fieldid=$formidreal.'-wysija-to'; 
  253. else $fieldid=$formidreal.'-'.$fieldKey; 
  254. if(isset($params['form_type']) && $params['form_type']=='html') { 
  255. $titleplaceholder='placeholder="'.$field['label'].'" title="'.$field['label'].'"'; 
  256. }else{ 
  257. $titleplaceholder='title="'.$field['label'].'"'; 
  258.  
  259. $value_attribute=' value="'.$value_attribute.'" '; 
  260. if(count($params['customfields'])>1) { 
  261. if(isset($params['labelswithin'])) { 
  262. if($params['labelswithin']=='labels_within') { 
  263. $fieldstring='<input type="text" id="'.$fieldid.'" '.$titleplaceholder.' class="defaultlabels '.$classValidate.'" name="wysija[user]['.$fieldKey.']" '.$value_attribute.'/>'; 
  264. }else{ 
  265. $fieldstring='<label for="'.$fieldid.'">'.$field['label'].'</label><input type="text" id="'.$fieldid.'" class="'.$classValidate.'" name="wysija[user]['.$fieldKey.']" />'; 
  266. }else{ 
  267. $fieldstring='<label for="'.$fieldid.'">'.$field['label'].'</label><input type="text" id="'.$fieldid.'" class="'.$classValidate.'" name="wysija[user]['.$fieldKey.']" />'; 
  268. }else{ 
  269. if(isset($params['labelswithin'])) { 
  270. if($params['labelswithin']=='labels_within') { 
  271. $fieldstring='<input type="text" id="'.$fieldid.'" '.$titleplaceholder.' class="defaultlabels '.$classValidate.'" name="wysija[user]['.$fieldKey.']" '.$value_attribute.'/>'; 
  272. }else{ 
  273. $fieldstring='<input type="text" id="'.$fieldid.'" class="'.$classValidate.'" name="wysija[user]['.$fieldKey.']" '.$value_attribute.'/>'; 
  274. }else{ 
  275. $fieldstring='<input type="text" id="'.$fieldid.'" class="'.$classValidate.'" name="wysija[user]['.$fieldKey.']" '.$value_attribute.'/>'; 
  276.  
  277.  
  278. $html.='<p class="wysija-p-'.$fieldKey.'">'.$fieldstring.'</p>'; 
  279.  
  280. $html.=$this->honey($params, $formidreal); 
  281.  
  282. if($html) $html.=$submitbutton; 
  283.  
  284. return $html; 
  285.  
  286. function honey($params, $formidreal) { 
  287. $arrayhoney=array( 
  288. 'firstname'=>array('label'=>__('First name', WYSIJA), 'type'=>'req'),  
  289. 'lastname'=>array('label'=>__('Last name', WYSIJA), 'type'=>'req'),  
  290. 'email'=>array('label'=>__('Email', WYSIJA), 'type'=>'email') 
  291.  
  292. ); 
  293. $html=''; 
  294. foreach($arrayhoney as $fieldKey=> $field) { 
  295. $fieldid=$formidreal.'-abs-'.$fieldKey; 
  296.  
  297. if(isset($params['labelswithin'])) { 
  298. $fieldstring='<input type="text" id="'.$fieldid.'" value="" class="defaultlabels validated[abs]['.$field['type'].']" name="wysija[user][abs]['.$fieldKey.']" />'; 
  299. }else{ 
  300. $fieldstring='<label for="'.$fieldid.'">'.$field['label'].'</label><input type="text" id="'.$fieldid.'" class="validated[abs]['.$field['type'].']" name="wysija[user][abs]['.$fieldKey.']" />'; 
  301. $html.='<span class="wysija-p-'.$fieldKey.' abs-req">'.$fieldstring.'</span>'; 
  302. return $html; 
  303.