PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wysija-newsletters/views/front/widget_nl.php

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