WYSIJA_view_back_config

The MailPoet Newsletters WYSIJA view back config class.

Defined (1)

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

/views/back/config.php  
  1. class WYSIJA_view_back_config extends WYSIJA_view_back { 
  2.  
  3. var $title = 'Settings'; 
  4.  
  5. var $icon = 'icon-options-general'; 
  6.  
  7. var $skip_header = true; 
  8.  
  9. function reinstall() { 
  10. ?> 
  11. <form name="wysija-settings" method="post" id="wysija-settings" action="" class="form-valid" autocomplete="off"> 
  12. <input type="hidden" value="doreinstall" name="action" /> 
  13. <input type="hidden" value="reinstall" name="postedfrom" /> 
  14. <h3><?php _e('If you confirm this, all your current MailPoet data will be erased (newsletters, themes, statistics, lists, subscribers, etc.)', WYSIJA); ?></h3> 
  15. <p class="submit"> 
  16. <input type="submit" value="<?php _e('Confirm Reinstallation', WYSIJA) ?>" class="button-secondary" id="submit" name="submit" /> 
  17. <?php $this->secure(array( 'action' => 'doreinstall' )); ?> 
  18. </p> 
  19. </form> 
  20. <?php 
  21.  
  22. function fieldFormHTML_commentform($key, $value, $model, $paramsex) { 
  23. // second part concerning the checkbox 
  24. $formsHelp = WYSIJA::get('forms', 'helper'); 
  25. $checked = false; 
  26. if ($this->model->getValue($key)) 
  27. $checked = true; 
  28. $checkboxDetails = array( 'id' => $key, 'name' => 'wysija['.$model.']['.$key.']', 'class' => 'activateInput' ); 
  29. $contentAfter = ''; 
  30.  
  31. // if it's the commentform field and jetpacks is activated with its comment module then we disable the box 
  32. if ($key == 'commentform' && WYSIJA::is_plugin_active('jetpack/jetpack.php') && in_array('comments', Jetpack::get_active_modules())) { 
  33. $checkboxDetails['disabled'] = 'disabled'; 
  34. $contentAfter = '<p>'.__('This feature cannot work because the "Comments" feature of the plugin JetPack is enabled.', WYSIJA).'</p>'; 
  35.  
  36. // if it's the register form field and registration is not allowed on the site then we just disable it 
  37. $active_signup = false; 
  38. if (is_multisite()) { 
  39. $active_signup = get_site_option('registration'); 
  40. if (!$active_signup) 
  41. $active_signup = 'all'; 
  42.  
  43. $active_signup = apply_filters('wpmu_active_signup', $active_signup); 
  44. if (in_array($active_signup, array( 'none', 'blog' ))) 
  45. $active_signup = false; 
  46. else 
  47. $active_signup = true; 
  48. else 
  49. $active_signup = get_option('users_can_register'); 
  50.  
  51. if ($key == 'registerform' && !$active_signup) { 
  52. $checkboxDetails['disabled'] = 'disabled'; 
  53.  
  54. $contentAfter = '<p>'.__('Registration is disabled on this site.', WYSIJA).'</p>'; 
  55.  
  56. $fieldHTML = '<label class="checkbox_optin_label" for="'.$key.'">'; 
  57. $fieldHTML.=$formsHelp->checkbox($checkboxDetails, 1, $checked); 
  58. $fieldHTML.='</label>'; 
  59.  
  60. $value = $this->model->getValue($key.'_linkname'); 
  61.  
  62. $fieldHTML.='<div id="'.$key.'_linkname'.'" class="checkbox_optin_value">'; 
  63.  
  64. if ($contentAfter) { 
  65. $fieldHTML.='</div>'; 
  66. $fieldHTML.=$contentAfter; 
  67. else { 
  68. $fieldHTML.=$formsHelp->input(array( 'name' => 'wysija['.$model.']['.$key.'_linkname]', 'size' => '75' ), $value); 
  69. $model_list = WYSIJA::get('list', 'model'); 
  70. $lists = $model_list->get(array( 'name', 'list_id' ), array( 'is_enabled' => 1 )); 
  71. $valuefield = $this->model->getValue($key.'_lists'); 
  72. if (!$valuefield) 
  73. $valuefield = array( ); 
  74. foreach ($lists as $list) { 
  75. if (in_array($list['list_id'], $valuefield)) 
  76. $checked = true; 
  77. else 
  78. $checked = false; 
  79.  
  80. $fieldHTML.= '<p class="labelcheck"><label for="list-'.$list['list_id'].'">'.$formsHelp->checkbox(array( 'id' => 'list-'.$list['list_id'],  
  81. 'name' => 'wysija[config]['.$key.'_lists][]', 'class' => 'validate[minCheckbox[1]]' ), $list['list_id'], $checked).$list['name'].'</label></p>'; 
  82. $fieldHTML.='</div>'; 
  83.  
  84.  
  85. return $fieldHTML; 
  86.  
  87. function fieldFormHTML_subscribers_count($key, $value, $model, $paramsex) { 
  88. // second part concerning the checkbox 
  89. $formsHelp = WYSIJA::get('forms', 'helper'); 
  90. $checked = false; 
  91. if ($this->model->getValue($key)) { 
  92. $checked = true; 
  93. $fieldHTML = ''; 
  94. $fieldHTML .= '<div id="'.$key.'_linkname'.'" class="checkbox_optin_value">'; 
  95. $fieldHTML .= $formsHelp->input(array( 'name' => 'wysija['.$model.']['.$key.'_linkname]', 'size' => '75', 'class' => 'subscribers-count-shortcode', 'readonly' => 'readonly' ), '[wysija_subscribers_count]').'</p>'; 
  96. $model_list = WYSIJA::get('list', 'model'); 
  97. $lists = $model_list->get(array( 'name', 'list_id', 'is_public' ), array( 'is_enabled' => 1 )); 
  98.  
  99.  
  100. foreach ($lists as $list) { 
  101. $fieldHTML.= '<p class="labelcheck"><label for="'.$key.'list-'.$list['list_id'].'">'.$formsHelp->checkbox(array( 'id' => $key.'list-'.$list['list_id'],  
  102. 'name' => 'wysija[config]['.$key.'_lists][]', 'class' => 'subscribers-count-list' ), $list['list_id']).$list['name'].'</label></p>'; 
  103. $fieldHTML.='</div>'; 
  104.  
  105.  
  106. return $fieldHTML; 
  107.  
  108. function fieldFormHTML_managesubscribe($key, $value, $model, $paramsex) { 
  109. // second part concerning the checkbox 
  110. $formsHelp = WYSIJA::get('forms', 'helper'); 
  111. $checked = false; 
  112. if ($this->model->getValue($key)) 
  113. $checked = true; 
  114. $fieldHTML = '<label class="checkbox_optin_label" for="'.$key.'">'; 
  115. $fieldHTML .= $formsHelp->checkbox(array( 'id' => $key, 'name' => 'wysija['.$model.']['.$key.']', 'class' => 'activateInput' ), 1, $checked); 
  116. $fieldHTML .= '</label>'; 
  117. $value = $this->model->getValue($key.'_linkname'); 
  118.  
  119. $fieldHTML .= '<div id="'.$key.'_linkname'.'" class="checkbox_optin_value">'; 
  120. $fieldHTML .= $formsHelp->input(array( 'name' => 'wysija['.$model.']['.$key.'_linkname]', 'size' => '75' ), $value); 
  121. $fieldHTML .= '<p style="margin-bottom:0px;">'.__('Subscribers can choose from these lists :', WYSIJA).'</p>'; 
  122. $model_list = WYSIJA::get('list', 'model'); 
  123. $lists = $model_list->get(array( 'name', 'list_id', 'is_public' ), array( 'is_enabled' => 1 )); 
  124.  
  125. usort($lists, array( $this, 'sort_by_name' )); 
  126. foreach ($lists as $list) { 
  127. if ($list['is_public']) 
  128. $checked = true; 
  129. else 
  130. $checked = false; 
  131.  
  132. $fieldHTML.= '<p class="labelcheck"><label for="'.$key.'list-'.$list['list_id'].'">'.$formsHelp->checkbox(array( 'id' => $key.'list-'.$list['list_id'],  
  133. 'name' => 'wysija[config]['.$key.'_lists][]' ), $list['list_id'], $checked).$list['name'].'</label></p>'; 
  134. $fieldHTML.='</div>'; 
  135.  
  136.  
  137. return $fieldHTML; 
  138.  
  139. function fieldFormHTML_viewinbrowser($key, $value, $model, $paramsex) { 
  140. /** second part concerning the checkbox */ 
  141. $formsHelp = WYSIJA::get('forms', 'helper'); 
  142. $checked = false; 
  143. if ($this->model->getValue($key)) 
  144. $checked = true; 
  145. $field = '<p><label for="'.$key.'">'; 
  146. $field.=$formsHelp->checkbox(array( 'id' => $key, 'name' => 'wysija['.$model.']['.$key.']', 'class' => 'activateInput' ), 1, $checked); 
  147. $field.='</label>'; 
  148. $value = $this->model->getValue($key.'_linkname'); 
  149.  
  150. $field.=$formsHelp->input(array( "id" => $key.'_linkname', 'name' => 'wysija['.$model.']['.$key.'_linkname]', 'size' => '75' ), $value).'</p>'; 
  151.  
  152. return $field; 
  153.  
  154. function fieldFormHTML_page_selection($key, $value, $model, $paramsex) { 
  155. $model_user = WYSIJA::get('user', 'model'); 
  156. $action_takens = array( 'confirmation_page' => 'subscribe', 'unsubscribe_page' => 'unsubscribe', 'subscriptions_page' => 'subscriptions' ); 
  157. $pages = array( $this->model->getValue('confirm_email_link') => __('MailPoet page', WYSIJA) ); 
  158. $pages_objects = get_pages(); 
  159.  
  160.  
  161. foreach ($pages_objects as $page_object) { 
  162. $pages[$page_object->ID] = $page_object->post_title; 
  163.  
  164. $preview_edit_links = '<span id="'.$key.'-links">'; 
  165. foreach ($pages as $page_id => $page_title) { 
  166.  
  167. $preview_link = $model_user->getConfirmLink(false, $action_takens[$key], false, true, '_blank', $page_id); 
  168. $edit_link = get_edit_post_link($page_id); 
  169.  
  170. $preview_edit_links .= '<span id="'.$key.'-links-'.$page_id.'" class="links-page">'; 
  171. $preview_edit_links .= '<a href="'.$preview_link.'" target="_blank" title="'.__('Preview', WYSIJA).'">'.__('Preview', WYSIJA).'</a>'; 
  172. $preview_edit_links .= ' | <a href="'.$edit_link.'" target="_blank" title="'.__('Edit', WYSIJA).'">'.__('Edit', WYSIJA).'</a>'; 
  173. $preview_edit_links .= '</span>'; 
  174. $preview_edit_links .= '</span>'; 
  175.  
  176. $helper_forms = WYSIJA::get('forms', 'helper'); 
  177. $field = $helper_forms->dropdown(array( 'id' => $key, 'class' => 'page_select', 'name' => 'wysija['.$model.']['.$key.']' ), $pages, $this->model->getValue($key)); 
  178. $field .= $preview_edit_links; 
  179.  
  180. return $field; 
  181.  
  182. function fieldFormHTML_cron($key, $value, $model) { 
  183. //second part concerning the checkbox 
  184. $helper_forms = WYSIJA::get('forms', 'helper'); 
  185. $checked = false; 
  186. if ($this->model->getValue($key)) 
  187. $checked = true; 
  188.  
  189. $field = '<div><div class="cronleft"><label for="'.$key.'">'; 
  190. $field .= $helper_forms->checkbox(array( 'id' => $key, 'name' => 'wysija['.$model.']['.$key.']', 'class' => 'activateInput' ), 1, $checked); 
  191. $field .= '</label></div>'; 
  192.  
  193. $url_cron = site_url('wp-cron.php').'?'.WYSIJA_CRON.'&action=wysija_cron&process=all'; 
  194. $field .= '<div class="cronright" id="'.$key.'_linkname">'; 
  195.  
  196. $text_cron_manual_trigger = __('I\'ll setup a cron job on my server to execute at the frequency I want. Read about [link]setting up a cron job yourself[/link].', WYSIJA).'<br/><span>'.__('Use this URL in your cron job: [cron_url]').'</span>'; 
  197. $text_cron_manual_trigger = str_replace(array( '[link]', '[/link]', '[cron_url]' ), array( '<a href="http://support.mailpoet.com/knowledgebase/configure-cron-job/?utm_source=wpadmin&utm_campaign=advanced_settings" title="Seting up cron job" target="_blank">', '</a>', '<a href="'.$url_cron.'" target="_blank">'.$url_cron.'</a>' ), $text_cron_manual_trigger); 
  198.  
  199. $text_cron_page_view = __('No thanks! I have enough visitors on my site. Their visits will trigger MailPoet\'s cron automatically.', WYSIJA); 
  200. $values_page_view_trigger = array( 2 => $text_cron_manual_trigger, 1 => $text_cron_page_view ); 
  201.  
  202. $value = 2; 
  203. if ((int)$this->model->getValue('cron_page_hit_trigger') === 1) 
  204. $value = 1; 
  205.  
  206. $key = 'cron_page_hit_trigger'; 
  207.  
  208. $content_radios = $helper_forms->radios(array( 'id' => $key, 'name' => 'wysija['.$model.']['.$key.']' ), $values_page_view_trigger, $value); 
  209. add_filter('wysija_extend_cron_config', array( $this, 'add_text_cron_premium' )); 
  210. $field .= apply_filters('wysija_extend_cron_config', $content_radios); 
  211.  
  212. $field .= '</div></div>'; 
  213.  
  214. // replace the variable in the text 
  215. $field = str_replace(array( '[link]', '[/link]', '[cron_url]' ), array( '<a href="http://support.mailpoet.com/knowledgebase/configure-cron-job/?utm_source=wpadmin&utm_campaign=advanced_settings" title="Seting up cron job" target="_blank">', '</a>', '<a href="'.$url_cron.'" target="_blank">'.$url_cron.'</a>' ), $field); 
  216.  
  217. return $field; 
  218.  
  219. // TODO remove that function which is in the premium plugin 
  220. function add_text_cron_premium($content) { 
  221. if (WYSIJA::is_plugin_active('wysija-newsletters-premium/index.php') && $this->model->getValue('premium_key')) { 
  222.  
  223. $content = __('I\'m a premium user, MailPoet.com will make sure my emails get sent on time.', WYSIJA).'<br/>'; 
  224. $content .= __('If I want I can [link]create an additional cron job[/link] on my end to increase the sending frequency.', WYSIJA).'<br/><span>'.__('Use this URL in your cron job: [cron_url]').'</span>'; 
  225. return $content; 
  226.  
  227. function fieldFormHTML_cron_prem($key, $value, $model) { 
  228.  
  229. $url_cron = site_url('wp-cron.php').'?'.WYSIJA_CRON.'&action=wysija_cron&process=all'; 
  230. $field = '<p>'; 
  231.  
  232. $text_cron_manual_trigger = __('If I want I can [link]create an additional cron job[/link] on my end to increase the frequency.', WYSIJA).'<br/><span>'.__('Use this URL in your cron job: [cron_url]').'</span>'; 
  233. $field .= str_replace(array( '[link]', '[/link]', '[cron_url]' ), array( '<a href="http://support.mailpoet.com/knowledgebase/configure-cron-job/?utm_source=wpadmin&utm_campaign=advanced_settings" title="Seting up cron job" target="_blank">', '</a>', '<a href="'.$url_cron.'" target="_blank">'.$url_cron.'</a>' ), $text_cron_manual_trigger); 
  234.  
  235. $field .= '</p>'; 
  236.  
  237. // $model_config = WYSIJA::get('config', 'model'); 
  238. // if ($model_config->getValue('cron_manual') !== true) { 
  239. // $model_config->save(array('cron_manual' => true)); 
  240. // 
  241. // $helper_licence = WYSIJA::get('licence', 'helper'); 
  242. // $helper_licence->check(true); 
  243. // } 
  244.  
  245. return $field; 
  246.  
  247. function fieldFormHTML_debugnew($key, $value, $model, $paramsex) { 
  248. /** second part concerning the checkbox */ 
  249. $formsHelp = WYSIJA::get('forms', 'helper'); 
  250. $selected = $this->model->getValue($key); 
  251. if (!$selected) 
  252. $selected = 0; 
  253. $field = '<p><label for="'.$key.'">'; 
  254. $options = array( 0 => 'off', 1 => 'SQL queries', 2 => ' +extra data', 3 => '  +safe PHP errors' ); 
  255. $field.=$formsHelp->dropdown(array( 'id' => $key, 'name' => 'wysija['.$model.']['.$key.']' ), $options, $selected); 
  256. $field.='</label></p>'; 
  257.  
  258. return $field; 
  259.  
  260. function fieldFormHTML_debuglog($key, $value, $model, $paramsex) { 
  261. /** second part concerning the checkbox */ 
  262. $formsHelp = WYSIJA::get('forms', 'helper'); 
  263.  
  264. $lists = array( 'cron', 'post_notif', 'query_errors', 'queue_process', 'manual' ); 
  265.  
  266. $fieldHTML = '<div id="'.$key.'_linkname'.'" class="checkbox_optin_value">'; 
  267. foreach ($lists as $list) { 
  268. $checked = false; 
  269. if ($this->model->getValue($key.'_'.$list)) 
  270. $checked = true; 
  271.  
  272. $fieldHTML.= '<p class="labelcheck"><label for="'.$key.'list-'.$list.'">'.$formsHelp->checkbox(array( 'id' => $key.'list-'.$list,  
  273. 'name' => 'wysija[config]['.$key.'_'.$list.'][]' ), 1, $checked).$list.'</label></p>'; 
  274. $fieldHTML.='</div>'; 
  275.  
  276. return $fieldHTML; 
  277.  
  278. function fieldFormHTML_dkim($key, $value, $model, $paramsex) { 
  279.  
  280. $field = ''; 
  281. $keypublickey = $key.'_pubk'; 
  282.  
  283. //there is no public key, this is the first time we load that function so we need to generate the dkim 
  284. if (!$this->model->getValue($keypublickey)) { 
  285. //refresh the public key private key generation 
  286. $helpersLi = WYSIJA::get('licence', 'helper'); 
  287. $helpersLi->dkim_config(); 
  288.  
  289. WYSIJA::update_option('dkim_autosetup', false); 
  290. $formsHelp = WYSIJA::get('forms', 'helper'); 
  291.  
  292. $realkey = $key.'_active'; 
  293. $checked = false; 
  294. if ($this->model->getValue($realkey)) 
  295. $checked = true; 
  296.  
  297. $field.='<p>'; 
  298. $field.=$formsHelp->checkbox(array( 'id' => $realkey, 'name' => 'wysija['.$model.']['.$realkey.']', 'style' => 'margin-left:0px;', 'class' => 'activateInput' ), 1, $checked); 
  299. $field.='</p>'; 
  300.  
  301. $field.='<div id="'.$realkey.'_linkname" >'; 
  302. //$titlelink=str_replace(array('[link]', '[\link]'), array('<a href="">', '</a>'), ''); 
  303. $titlelink = __('Configure your DNS by adding a key/value record in TXT as shown below.', WYSIJA).' <a href="http://support.mailpoet.com/knowledgebase/guide-to-dkim-in-wysija/?utm_source=wpadmin&utm_campaign=settings" target="_blank">'.__('Read more', WYSIJA).'</a>'; 
  304. $field.='<fieldset style=" border: 1px solid #ccc;margin: 0;padding: 10px;"><legend>'.$titlelink.'</legend>'; 
  305.  
  306. $field.='<label id="drlab" for="domainrecord">'.__('Key', WYSIJA).' <input readonly="readonly" id="domainrecord" style="margin-right:10px;" type="text" value="wys._domainkey"/></label><label id="drpub" for="dkimpub">'.__('Value', WYSIJA).' <input readonly="readonly" id="dkimpub" type="text" size="70" value="v=DKIM1;s=email;t=s;p='.$this->model->getValue($keypublickey).'"/></label>'; 
  307.  
  308. //the DKIM key is not a 1024 bits it is therefore obsolete 
  309. if (!$this->model->getValue('dkim_1024')) { 
  310. $stringRegenerate = __('You\'re using an older DKIM key which is unsupported by Gmail.', WYSIJA).' '.__('You\'ll need to update your DNS if you upgrade.', WYSIJA); 
  311. $field.='<p><strong>'.$stringRegenerate.'</strong></p>'; 
  312. $field.='<p><input type="hidden" id="dkim_regenerate" value="0" name="wysija[config][dkim_regenerate]"><a id="button-regenerate-dkim" class="button-secondary" href="javascript:;">'.__('Upgrade DKIM key', WYSIJA).'</a></p>'; 
  313.  
  314. $field.='</fieldset>'; 
  315. $realkey = $key.'_domain'; 
  316. $field.='<p><label class="dkim" for="'.$realkey.'">'.__('Domain', WYSIJA).'</label>'; 
  317.  
  318. $field.=$formsHelp->input(array( 'id' => $realkey, 'name' => 'wysija['.$model.']['.$realkey.']' ), $this->model->getValue($realkey)); 
  319. $field.='</p>'; 
  320.  
  321. $field.='</div>'; 
  322.  
  323. return $field; 
  324.  
  325. function fieldFormHTML_debug($key, $value, $model, $paramsex) { 
  326. /** second part concerning the checkbox */ 
  327. $formsHelp = WYSIJA::get('forms', 'helper'); 
  328. $checked = false; 
  329. if ($this->model->getValue($key)) 
  330. $checked = true; 
  331. $field = '<p><label for="'.$key.'">'; 
  332. $field.=$formsHelp->checkbox(array( 'id' => $key, 'name' => 'wysija['.$model.']['.$key.']' ), 1, $checked); 
  333. $field.='</label></p>'; 
  334.  
  335. return $field; 
  336.  
  337. function fieldFormHTML_capabilities($key, $value, $model, $paramsex) { 
  338. /** second part concerning the checkbox */ 
  339. $formsHelp = WYSIJA::get('forms', 'helper'); 
  340.  
  341. $field = '<table cellspacing="0" cellpadding="3" class="wp-list-table widefat fixed capabilities_form"> 
  342. <thead> 
  343. <tr> 
  344. <th class="rolestitle" style="width:200px">'.__('Roles and permissions', WYSIJA).'</th>'; 
  345.  
  346. $wptools = WYSIJA::get('wp_tools', 'helper'); 
  347. $editable_roles = $wptools->wp_get_roles(); 
  348.  
  349.  
  350. foreach ($editable_roles as $role) { 
  351. $field.='<th class="rolestable" >'.translate_user_role($role['name']).'</th>'; 
  352.  
  353. $field.='</tr></thead><tbody>'; 
  354.  
  355. $alternate = true; 
  356. $count = 1; 
  357. $is_hidden = false; 
  358. foreach ($this->model->capabilities as $keycap => $capability) { 
  359. $classAlternate = array( ); 
  360. if ($alternate) 
  361. $classAlternate[] = 'alternate'; 
  362. if ($count > 2) { 
  363. $classAlternate[] = 'hidden'; 
  364. $is_hidden = true; 
  365. $classAlternate = implode(' ', $classAlternate); 
  366. $classAlternate = ' class="'.$classAlternate.'" '; 
  367. $field.='<tr'.$classAlternate.'><td class="title"><p class="description">'.$capability['label'].'</p></td>'; 
  368.  
  369. foreach ($editable_roles as $role) { 
  370. $checked = false; 
  371. $keycheck = 'rolescap---'.$role['key'].'---'.$keycap; 
  372.  
  373. //if($this->model->getValue($keycheck)) $checked=true; 
  374. $checkboxparams = array( 'id' => $keycheck, 'name' => 'wysija['.$model.']['.$keycheck.']' ); 
  375. if (in_array($role['key'], array( 'administrator', 'super_admin' ))) { 
  376. $checkboxparams['disabled'] = 'disabled'; 
  377.  
  378. $roling = get_role($role['key']); 
  379.  
  380. // add "organize_gallery" to this role object 
  381. if ($roling->has_cap('wysija_'.$keycap)) { 
  382. $checked = true; 
  383.  
  384. $field.='<td class="rolestable" >'.$formsHelp->checkbox($checkboxparams, 1, $checked).'</td>'; 
  385.  
  386. $field.='</tr>'; 
  387. $alternate = !$alternate; 
  388. $count++; 
  389. if ($is_hidden) { 
  390. $classAlternate = ''; 
  391. if ($alternate) 
  392. $classAlternate = ' class="alternate" '; 
  393. $field.= '<tr'.$classAlternate.'><td colspan="'.(count($editable_roles) + 1).'"><a class="view_all" href="javascript:void(0);">'.__('View all', WYSIJA).'</a></td></tr>'; 
  394.  
  395. $field.='</tbody></table>'; 
  396. return $field; 
  397.  
  398. function fieldFormHTML_email_notifications($key, $value, $model, $paramsex) { 
  399. /** first part concerning the field itself */ 
  400. $params = array( ); 
  401. $params['type'] = 'default'; 
  402. $params['size'] = 38; 
  403. $field = $this->fieldHTML($key, $value, $model, $params); 
  404.  
  405. /** second part concerning the checkbox */ 
  406. $threecheck = array( 
  407. '_when_sub' => __('When someone subscribes', WYSIJA) 
  408. , '_when_unsub' => __('When someone unsubscribes', WYSIJA),  
  409. '_when_dailysummary' => __('Daily summary of emails sent', WYSIJA) 
  410. //, "_when_bounce"=>__('When an email bounces', WYSIJA) 
  411. ); 
  412. $formsHelp = WYSIJA::get('forms', 'helper'); 
  413. foreach ($threecheck as $keycheck => $checkobj) { 
  414. $checked = false; 
  415. if ($this->model->getValue($key.$keycheck)) 
  416. $checked = true; 
  417. $field.='<p><label for="'.$key.$keycheck.'">'; 
  418. $field.=$formsHelp->checkbox(array( "id" => $key.$keycheck, 'name' => 'wysija['.$model.']['.$key.$keycheck.']' ), 1, $checked); 
  419. $field.=$checkobj.'</label></p>'; 
  420.  
  421. return $field; 
  422.  
  423. function fieldFormHTML_selfsigned($key, $value, $model, $params) { 
  424.  
  425. $formsHelp = WYSIJA::get('forms', 'helper'); 
  426.  
  427. $realvalue = $this->model->getValue($key); 
  428.  
  429. $value = 0; 
  430. $checked = false; 
  431. if ($value == $realvalue) 
  432. $checked = true; 
  433. $id = str_replace('_', '-', $key).'-'.$value; 
  434. $field = '<label for="'.$id.'">'; 
  435. $field.=$formsHelp->radio(array( "id" => $id, 'name' => 'wysija['.$model.']['.$key.']' ), $value, $checked); 
  436. $field.=__('No', WYSIJA).'</label>'; 
  437.  
  438. $value = 1; 
  439. $checked = false; 
  440. if ($value == $realvalue) 
  441. $checked = true; 
  442. $id = str_replace('_', '-', $key).'-'.$value; 
  443. $field.='<label for="'.$id.'">'; 
  444. $field.=$formsHelp->radio(array( "id" => $id, 'name' => 'wysija['.$model.']['.$key.']' ), $value, $checked); 
  445. $field.=__('Yes', WYSIJA).'</label>'; 
  446.  
  447. return $field; 
  448.  
  449. function tabs($current = null) { 
  450. $tabs = array( 
  451. 'basics' => _x('Basics', 'settings tab title', WYSIJA),  
  452. 'forms' => _x('Forms', 'settings tab title', WYSIJA),  
  453. 'signupconfirmation' => _x('Signup Confirmation', 'settings tab title', WYSIJA),  
  454. 'sendingmethod' => _x('Send With...', 'settings tab title', WYSIJA),  
  455. 'advanced' => _x('Advanced', 'settings tab title', WYSIJA),  
  456. 'add-ons' => _x('Add-ons', 'settings tab title', WYSIJA),  
  457. ); 
  458.  
  459. if (!$this->_user_can('change_sending_method')) 
  460. unset($tabs['sendingmethod']); 
  461.  
  462. $tabs = apply_filters('wysija_extend_settings', $tabs); 
  463. echo '<div id="icon-options-general" class="icon32"><br /></div>'; 
  464. echo '<h2 id="wysija-tabs" class="nav-tab-wrapper">'; 
  465.  
  466. foreach ($tabs as $tab => $name) { 
  467. $class = ($tab === $current) ? ' nav-tab-active' : ''; 
  468. $extra = ($tab === 'premium') ? ' premium' : ''; 
  469. echo "<a class='nav-tab$class$extra' href='#$tab'>$name</a>"; 
  470. echo '</h2>'; 
  471.  
  472. function save($data) { 
  473. $this->main($data); 
  474.  
  475. /** 
  476. * @param string $action 
  477. * @return boolean 
  478. */ 
  479. function _user_can($action) { 
  480. if (empty($action)) 
  481. return false; 
  482. $is_network_admin = WYSIJA::current_user_can('manage_network'); 
  483.  
  484. //$is_network_admin=true;//PROD comment that line 
  485. if ($is_network_admin) 
  486. return true; 
  487.  
  488. $is_multisite = is_multisite(); 
  489.  
  490. //$is_multisite=true;//PROD comment that line 
  491. switch ($action) { 
  492. case 'change_sending_method': 
  493. if ((!$is_multisite || ($is_multisite && $this->model->getValue('ms_allow_admin_sending_method'))) && WYSIJA::current_user_can('switch_themes') 
  494. ) { 
  495. return true; 
  496. return false; 
  497. break; 
  498. case 'toggle_signup_confirmation': 
  499. if ((!$is_multisite || ($is_multisite && $this->model->getValue('ms_allow_admin_toggle_signup_confirmation'))) && WYSIJA::current_user_can('switch_themes')) { 
  500. return true; 
  501. return false; 
  502. break; 
  503.  
  504. function main($data) { 
  505. $is_multisite = is_multisite(); 
  506. $is_network_admin = WYSIJA::current_user_can('manage_network'); 
  507. //$is_network_admin=$is_multisite=true;//PROD comment that line 
  508.  
  509. if ($is_multisite && $is_network_admin) { 
  510. add_filter('wysija_extend_settings', array( $this, 'ms_tab_name' ), 12); 
  511. add_filter('wysija_extend_settings_content', array( $this, 'ms_tab_content' ), 12, 2); 
  512.  
  513. // check for debug 
  514. if (isset($_REQUEST['wysija_debug'])) { 
  515. switch ((int)$_REQUEST['wysija_debug']) { 
  516. // turn off debug 
  517. case 0: 
  518. WYSIJA::update_option('debug_on', false); 
  519. WYSIJA::update_option('debug_new', false); 
  520. break; 
  521.  
  522. // turn on debug (with debug level as value) 
  523. case 1: 
  524. case 2: 
  525. case 3: 
  526. case 4: 
  527. case 99: 
  528. WYSIJA::update_option('debug_on', true); 
  529. WYSIJA::update_option('debug_new', (int)$_REQUEST['wysija_debug']); 
  530. break; 
  531.  
  532. echo $this->messages(); 
  533. ?> 
  534. <div id="wysija-config"> 
  535. <?php $this->tabs(); ?> 
  536. <form name="wysija-settings" method="post" id="wysija-settings" action="" class="form-valid" autocomplete="off"> 
  537. <div id="basics" class="wysija-panel hidden"> 
  538. <?php $this->basics(); ?> 
  539. <p class="submit"> 
  540. <input type="submit" value="<?php echo esc_attr(__('Save settings', WYSIJA)); ?>" class="button-primary wysija" /> 
  541. </p> 
  542. </div> 
  543. <div id="forms" class="wysija-panel hidden"> 
  544. <?php /** if(WYSIJA::is_wysija_admin()) */ $this->form_list(); ?> 
  545. </div> 
  546.  
  547. <div id="signupconfirmation" class="wysija-panel hidden"> 
  548. <?php $this->signupconfirmation(); ?> 
  549. <p class="submit"> 
  550. <input type="submit" value="<?php echo esc_attr(__('Save settings', WYSIJA)); ?>" class="button-primary wysija" /> 
  551. </p> 
  552. </div> 
  553. <?php 
  554. if ($this->_user_can('change_sending_method')) { 
  555. ?> 
  556. <div id="sendingmethod" class="wysija-panel hidden"> 
  557. <?php $this->sendingmethod(); ?> 
  558. <p class="submit"> 
  559. <input type="submit" value="<?php echo esc_attr(__('Save settings', WYSIJA)); ?>" class="button-primary wysija" /> 
  560. </p> 
  561. </div> 
  562. <?php 
  563. ?> 
  564.  
  565.  
  566. <div id="advanced" class="wysija-panel hidden"> 
  567. <?php $this->advanced($data); ?> 
  568. <p class="submit"> 
  569. <input type="submit" value="<?php echo esc_attr(__('Save settings', WYSIJA)); ?>" class="button-primary wysija" /> 
  570. </p> 
  571. </div> 
  572.  
  573. <div id="add-ons" class="wysija-panel hidden"> 
  574. <?php $this->add_ons(); ?> 
  575. </div> 
  576.  
  577. <?php 
  578. echo apply_filters('wysija_extend_settings_content', '', array( 'viewObj' => &$this )); 
  579. ?> 
  580.  
  581. <?php $this->secure(array( 'action' => "save" )); ?> 
  582. <input type="hidden" value="save" name="action" /> 
  583. <input type="hidden" value="" name="redirecttab" id="redirecttab" /> 
  584. </form> 
  585. </div> 
  586. <?php 
  587.  
  588. function basics() { 
  589. $step = array( ); 
  590.  
  591. $step['company_address'] = array( 
  592. 'type' => 'textarea',  
  593. 'label' => __("Your company's address", WYSIJA),  
  594. 'desc' => __("The address will be added to your newsletter's footer. This helps avoid spam filters.", WYSIJA),  
  595. 'rows' => "3",  
  596. 'cols' => "40", ); 
  597.  
  598. $step['emails_notified'] = array( 
  599. 'type' => 'email_notifications',  
  600. 'label' => __('Email notifications', WYSIJA),  
  601. 'desc' => __('Enter the email addresses that should receive notifications (separate by comma).', WYSIJA) ); 
  602.  
  603. $step['from_name'] = array( 
  604. 'type' => 'fromname',  
  605. 'class' => 'validate[required]',  
  606. 'label' => __('Sender of notifications', WYSIJA),  
  607. 'desc' => __('Choose a FROM name and email address for notifications emails.', WYSIJA) ); 
  608.  
  609. $step['commentform'] = array( 
  610. 'type' => 'commentform',  
  611. 'label' => __('Subscribe in comments', WYSIJA),  
  612. 'desc' => __('Visitors who submit a comment on a post can click on a checkbox to subscribe.', WYSIJA),  
  613. ); 
  614.  
  615. $showregisteroption = true; 
  616. //this option is only available for the main site 
  617. if (is_multisite()) { 
  618. $mpoet_allow_register_option_on_all_sites = false; 
  619. $mpoet_allow_register_option_on_all_sites = apply_filters( 'mpoet_allow_register_option_on_all_sites', $mpoet_allow_register_option_on_all_sites ); 
  620. if( $mpoet_allow_register_option_on_all_sites === false && !is_main_site() ) { 
  621. $showregisteroption = false; 
  622.  
  623. if ($showregisteroption) { 
  624. $step ['registerform'] = array( 
  625. 'type' => 'commentform',  
  626. 'label' => __('Subscribe in registration form', WYSIJA),  
  627. 'desc' => __('Allow users who register to your site to subscribe on a list of your choice.', WYSIJA) 
  628. ); 
  629.  
  630. $modelU = WYSIJA::get('user', 'model'); 
  631. $objUser = $modelU->getCurrentSubscriber(); 
  632. $step['viewinbrowser'] = array( 
  633. 'type' => 'viewinbrowser',  
  634. 'label' => __('Link to browser version', WYSIJA),  
  635. 'desc' => __('Displays at the top of your newsletters. Don\'t forget to include the link tag, ie: [link]The link[/link]', WYSIJA),  
  636. ); 
  637.  
  638. $step['unsubscribe_linkname'] = array( 
  639. 'type' => 'input',  
  640. 'label' => __('Text of "Unsubscribe" link', WYSIJA),  
  641. 'desc' => __('This changes the label for the unsubscribe link in the footer of your newsletters.', WYSIJA) ); 
  642.  
  643. $step['unsubscribe_page'] = array( 
  644. 'type' => 'page_selection',  
  645. 'label' => __('Unsubscribe page', WYSIJA),  
  646. 'desc' => __('A subscriber is directed to a page of your choice after clicking on the unsubscribe link, at the bottom of a newsletter.', WYSIJA),  
  647. ); 
  648.  
  649. $model_config = WYSIJA::get('config', 'model'); 
  650. ?> 
  651. <table class="form-table"> 
  652. <tbody> 
  653. <?php 
  654. do_action('mailpoet_pre_config_screen'); 
  655. echo $this->buildMyForm($step, $model_config->values, 'config'); 
  656. ?> 
  657. </tbody> 
  658. </table> 
  659. <?php 
  660.  
  661. function signupconfirmation() { 
  662. $step = array( ); 
  663.  
  664. $step['confirm_dbleoptin'] = array( 
  665. 'type' => 'radio',  
  666. 'values' => array( true => __('Yes', WYSIJA), false => __('No', WYSIJA) ),  
  667. 'label' => __('Enable signup confirmation', WYSIJA),  
  668. 'desc' => __('Prevent people from being subscribed to your list unwillingly, this option ensures you to keep a clean list.', WYSIJA).' <a href="http://support.mailpoet.com/knowledgebase/why-you-should-enforce-email-activation/?utm_source=wpadmin&utm_campaign=activation email" target="_blank">'.__('Learn more.', WYSIJA).'</a>' ); 
  669.  
  670. if (!$this->_user_can('toggle_signup_confirmation')) { 
  671. $step['confirm_dbleoptin']['type'] = 'disabled_radio'; 
  672.  
  673. $step['confirm_email_title'] = array( 
  674. 'type' => 'input',  
  675. 'label' => __('Email subject', WYSIJA),  
  676. 'rowclass' => 'confirmemail' ); 
  677.  
  678. $step['confirm_email_body'] = array( 
  679. 'type' => 'textarea',  
  680. 'label' => __('Email content', WYSIJA),  
  681. 'desc' => __('Don\'t forget to include: <br><br>[activation_link]Confirm your subscription.[/activation_link]. <br><br>Optional: [lists_to_confirm].', WYSIJA),  
  682. 'rowclass' => 'confirmemail' ); 
  683.  
  684. $step['confirmation_page'] = array( 
  685. 'type' => 'page_selection',  
  686. 'label' => __('Confirmation page', WYSIJA),  
  687. 'desc' => __('When subscribers click on the activation link, they are redirected to a page of your choice.', WYSIJA),  
  688. 'rowclass' => 'confirmemail' ); 
  689. ?> 
  690.  
  691. <table class="form-table"> 
  692. <tbody> 
  693. <?php 
  694. echo $this->buildMyForm($step, '', 'config'); 
  695. ?> 
  696. </tbody> 
  697. </table> 
  698. <?php 
  699.  
  700. function sendingmethod() { 
  701. $key = 'sending_method'; 
  702. $realvalue = $this->model->getValue($key); 
  703. // Since 2.6.12, remove gmail and use stmp instead 
  704. if ($realvalue == 'gmail') 
  705. $realvalue = 'smtp'; 
  706.  
  707. $helper_forms = WYSIJA::get('forms', 'helper'); 
  708. $current_user = WYSIJA::wp_get_userdata(); 
  709. ?> 
  710. <table class="form-table" id="ms-sendingmethod"> 
  711. <tbody> 
  712. <tr class="methods"> 
  713. <?php 
  714. $is_multisite = is_multisite(); 
  715.  
  716. if (is_multisite()) { 
  717. $field = '<th scope="row">'; 
  718. $checked = false; 
  719. $value = 'network'; 
  720. $id = str_replace('_', '-', $key).'-'.$value; 
  721. if ($value == $realvalue) { 
  722. $checked = true; 
  723. $field .= '<label for="'.$id.'" class="clearfix">'; 
  724. $field .= $helper_forms->radio( 
  725. array( 
  726. 'id' => $id,  
  727. 'class' => 'mailpoet-delivery-method',  
  728. 'name' => 'wysija[config]['.$key.']',  
  729. ), $value, $checked 
  730. ); 
  731. $field .= '<h3>'.__('Network\'s Method', WYSIJA).'</h3></label>'; 
  732. $field .= '<p>'.__('Method set by the network admin.', WYSIJA).'</p>'; 
  733. if (!$this->model->getValue('ms_sending_emails_ok')) { 
  734. $field .= '<strong'.__('Not Configured!', WYSIJA).'</strong>'; 
  735. $field .= '</th>'; 
  736. echo $field; 
  737. ?> 
  738.  
  739. <th scope="row"> 
  740. <?php 
  741. $checked = false; 
  742. $value = 'site'; 
  743. $id = str_replace('_', '-', $key).'-'.$value; 
  744. if ($value == $realvalue) 
  745. $checked = true; 
  746. $field = '<label for="'.$id.'" class="clearfix">'; 
  747. $field.=$helper_forms->radio(array( "id" => $id, 'class' => 'mailpoet-delivery-method', 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  748. $field.='<h3>'.__('Your own website', WYSIJA).'</h3></label>'; 
  749. $field.='<p>'.__('The simplest solution for small lists. Your web host sets a daily email limit.', WYSIJA).'</p>'; 
  750. echo $field; 
  751. ?> 
  752. </th> 
  753. <th scope="row"> 
  754. <?php 
  755. $checked = false; 
  756. $value = 'smtp'; 
  757. if ($value === $realvalue) 
  758. $checked = true; 
  759.  
  760. $id = str_replace('_', '-', $key).'-'.$value; 
  761. $field = '<label for="'.$id.'" class="clearfix">'; 
  762. $field.= $helper_forms->radio(array( 'id' => $id, 'class' => 'mailpoet-delivery-method', 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  763. $field.= '<h3>'.__('Third party', WYSIJA).'</h3></label>'; 
  764. $field.='<p>'.__('Send with a professional SMTP provider, a great choice for big and small lists. We\'ve negotiated promotional offers with a few providers for you.', WYSIJA).' <a href="http://support.mailpoet.com/knowledgebase/send-with-smtp-when-using-a-professional-sending-provider/?utm_source=wpadmin&utm_campaign=sending method" target="_blank">'.__('Read more', WYSIJA).'</a>.</p>'; 
  765. echo $field; 
  766. ?> 
  767. </th> 
  768. </tr> 
  769.  
  770. <tr class="hidechoice choice-sending-method-site"> 
  771. <th scope="row"> 
  772. <?php 
  773. $field = __('Delivery method', WYSIJA); 
  774. $field.='<p class="description">'.__('Send yourself some test emails to confirm which method works with your server.', WYSIJA).'</p>'; 
  775. echo $field; 
  776. ?> 
  777. </th> 
  778. <td colspan="2"> 
  779. <?php 
  780. $key = "sending_emails_site_method"; 
  781. $checked = false; 
  782. $realvalue = $this->model->getValue($key); 
  783. $value = "phpmail"; 
  784. if ($value == $realvalue) 
  785. $checked = true; 
  786.  
  787. $id = str_replace("_", '-', $key).'-'.$value; 
  788. $field = '<p class="title"><label for="'.$id.'">'; 
  789. $field.=$helper_forms->radio(array( "id" => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  790. $field.='PHP Mail</label></p>'; 
  791. $field.='<p class="description">'.__('This email engine works on 95% of servers', WYSIJA).'</p>'; 
  792.  
  793.  
  794. $value = "sendmail"; 
  795. $checked = false; 
  796. if ($value == $realvalue) 
  797. $checked = true; 
  798.  
  799. $id = str_replace("_", '-', $key).'-'.$value; 
  800. $field.='<p class="title"><label for="'.$id.'">'; 
  801. $field.=$helper_forms->radio(array( "id" => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  802. $field.='Sendmail</label>'; 
  803. $field.='<p class="description">'.__('This method works on 5% of servers', WYSIJA).'</p>'; 
  804.  
  805. $id = str_replace("_", '-', $key).'-'.$value."-path"; 
  806. $field.='<p class="title" id="p-'.$id.'"><label for="'.$id.'">'; 
  807. $field.=__("Sendmail path", WYSIJA).'</label>'.$helper_forms->input(array( "id" => $id, 'name' => 'wysija[config][sendmail_path]' ), $this->model->getValue("sendmail_path")).'</p>'; 
  808.  
  809.  
  810. if ($this->model->getValue('allow_wpmail')) { 
  811. $checked = false; 
  812. $value = 'wpmail'; 
  813. if ($value == $realvalue) 
  814. $checked = true; 
  815.  
  816. $id = str_replace('_', '-', $key).'-'.$value; 
  817. $field.='<p class="title"><label for="'.$id.'">'; 
  818. $field.=$helper_forms->radio(array( "id" => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  819. $field.='WP Mail</label></p>'; 
  820. $field.='<p class="description">'.__('Use the same method as the one used for your WP site.', WYSIJA).'</p>'; 
  821.  
  822.  
  823. echo $field; 
  824. ?> 
  825. </td> 
  826. </tr> 
  827.  
  828. <tr class="hidechoice choice-sending-method-smtp"> 
  829. <th scope="row"> 
  830. <?php 
  831. $key = "smtp_host"; 
  832. $id = str_replace("_", '-', $key); 
  833. $field = '<label for="'.$id.'">'.__('SMTP Hostname', WYSIJA)."</label>"; 
  834. $field.='<p class="description">'.__('e.g.:smtp.mydomain.com', WYSIJA).'</p>'; 
  835. echo $field; 
  836. ?> 
  837. </th> 
  838. <td> 
  839. <?php 
  840. $value = $this->model->getValue($key); 
  841. $field = $helper_forms->input(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '40' ), $value, $checked); 
  842. echo $field; 
  843. ?> 
  844. </td> 
  845. </tr> 
  846. <tr class="hidechoice choice-sending-method-smtp choice-sending-method-gmail"> 
  847. <th scope="row"> 
  848. <?php 
  849. $key = "smtp_login"; 
  850. $id = str_replace("_", '-', $key); 
  851. $field = '<label for="'.$id.'">'.__('Login', WYSIJA)."</label>"; 
  852. echo $field; 
  853. ?> 
  854. </th> 
  855. <td colspan="2"> 
  856. <?php 
  857. $value = $this->model->getValue($key); 
  858. $field = $helper_forms->input(array( "id" => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '40' ), $value, $checked); 
  859. echo $field; 
  860. ?> 
  861. </td> 
  862. </tr> 
  863. <tr class="hidechoice choice-sending-method-smtp choice-sending-method-gmail"> 
  864. <th scope="row"> 
  865. <?php 
  866. $key = "smtp_password"; 
  867. $id = str_replace("_", '-', $key); 
  868. $field = '<label for="'.$id.'">'.__('Password', WYSIJA)."</label>"; 
  869. echo $field; 
  870. ?> 
  871. </th> 
  872. <td colspan="2"> 
  873. <?php 
  874. $value = $this->model->getValue($key); 
  875. $field = $helper_forms->input(array( "type" => "password", "id" => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '40' ), $value, $checked); 
  876. echo $field; 
  877. ?> 
  878. </td> 
  879. </tr> 
  880. <tr id="restapipossible" class="hidechoice"> 
  881. <th scope="row"> 
  882. <?php 
  883. $key = 'smtp_rest'; 
  884. $id = str_replace('_', '-', $key); 
  885. $field = '<label for="'.$id.'">web API</label>'; 
  886. $field.='<p class="description">'.__('Activate if your SMTP ports are blocked.', WYSIJA).'</p>'; 
  887. echo $field; 
  888. ?> 
  889. </th> 
  890. <td> 
  891. <?php 
  892. $value = $this->model->getValue($key); 
  893. $checked = false; 
  894. if ($this->model->getValue('smtp_rest')) 
  895. $checked = true; 
  896. $field = $helper_forms->checkbox(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '3' ), 1, $checked); 
  897.  
  898. echo $field; 
  899. ?> 
  900. </td> 
  901. </tr> 
  902.  
  903. <tr class="hidechoice choice-sending-method-smtp choice-no-restapi"> 
  904. <th scope="row"> 
  905. <?php 
  906. $key = 'smtp_port'; 
  907. $id = str_replace('_', '-', $key); 
  908. $field = '<label for="'.$id.'">'.__('SMTP port', WYSIJA)."</label>"; 
  909.  
  910. echo $field; 
  911. ?> 
  912. </th> 
  913. <td> 
  914. <?php 
  915. $value = $this->model->getValue($key); 
  916. $field = $helper_forms->input(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '3' ), $value, $checked); 
  917.  
  918. echo $field; 
  919. ?> 
  920. </td> 
  921. </tr> 
  922.  
  923. <tr class="hidechoice choice-sending-method-smtp choice-no-restapi"> 
  924. <th scope="row"> 
  925. <?php 
  926. $key = "smtp_secure"; 
  927. $id = str_replace("_", '-', $key); 
  928. $field = '<label for="'.$id.'">'.__('Secure connection', WYSIJA)."</label>"; 
  929. echo $field; 
  930. ?> 
  931. </th> 
  932. <td colspan="2"> 
  933. <?php 
  934. $value = $this->model->getValue($key); 
  935.  
  936. $field = $helper_forms->dropdown(array( 'name' => 'wysija[config]['.$key.']', "id" => $id ), array( false => __("No"), "ssl" => "SSL", "tls" => "TLS" ), $value); 
  937. echo $field; 
  938. ?> 
  939. </td> 
  940. </tr> 
  941.  
  942. <tr class="hidechoice choice-sending-method-smtp choice-no-restapi"> 
  943. <th scope="row"> 
  944. <?php 
  945. $field = __('Authentication', WYSIJA); 
  946. echo $field.'<p class="description">'.__("Leave this option to Yes. Only a tiny portion of SMTP services ask Authentication to be turned off.", WYSIJA).'</p>'; 
  947. ?> 
  948. </th> 
  949. <td colspan="2"> 
  950. <?php 
  951. $key = 'smtp_auth'; 
  952. $realvalue = $this->model->getValue($key); 
  953.  
  954. $value = false; 
  955. $checked = false; 
  956. if ($value == $realvalue) 
  957. $checked = true; 
  958. $id = str_replace('_', '-', $key).'-'.$value; 
  959. $field = '<label for="'.$id.'">'; 
  960. $field.=$helper_forms->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  961. $field.=__('No', WYSIJA).'</label>'; 
  962.  
  963. $value = true; 
  964. $checked = false; 
  965. if ($value == $realvalue) 
  966. $checked = true; 
  967. $id = str_replace('_', '-', $key).'-'.$value; 
  968. $field.='<label for="'.$id.'">'; 
  969. $field.=$helper_forms->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  970. $field.=__('Yes', WYSIJA).'</label>'; 
  971.  
  972.  
  973. $value = false; 
  974. $checked = false; 
  975. if ($value == $realvalue) 
  976. $checked = true; 
  977. $id = str_replace('_', '-', $key).'-'.$value; 
  978. $field = '<label for="'.$id.'">'; 
  979. $field.=$helper_forms->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  980. $field.=__('No', WYSIJA).'</label>'; 
  981.  
  982. $value = true; 
  983. $checked = false; 
  984. if ($value == $realvalue) 
  985. $checked = true; 
  986. $id = str_replace('_', '-', $key).'-'.$value; 
  987. $field.='<label for="'.$id.'">'; 
  988. $field.=$helper_forms->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  989. $field.=__('Yes', WYSIJA).'</label>'; 
  990.  
  991.  
  992. echo $field; 
  993. ?> 
  994. </td> 
  995. </tr> 
  996.  
  997. <tr class="hidechoice choice-sending-method-smtp choice-sending-method-site choice-sending-method-gmail choice-sending-method-network"> 
  998. <th scope="row"> 
  999. <?php _e('Test method'); ?> 
  1000. </th> 
  1001. <td colspan="<?php echo ( is_multisite() ? 3 : 2 ); ?>"> 
  1002. <input type="text" value="<?php echo esc_attr($current_user->data->user_email); ?>" class="mailpoet-test-emails" name="wysija[config][test_mails]" /> 
  1003. <a class="button-secondary mailpoet-test-delivery"><?php _e('Send a test mail', WYSIJA); ?></a> 
  1004. </td> 
  1005. </tr> 
  1006.  
  1007. <tr class="hidechoice choice-sending-method-smtp choice-sending-method-site choice-sending-method-gmail"> 
  1008. <th scope="row"> 
  1009. <?php 
  1010. $field = __('Send...', WYSIJA); 
  1011.  
  1012. echo $field.'<p class="description">'.str_replace(array( '[link]', '[/link]' ), array( '<a href="http://support.mailpoet.com/knowledgebase/wp-cron-batch-emails-sending-frequency/?utm_source=wpadmin&utm_campaign=choosing%20frequency" target="_blank">', '</a>' ), __('Your web host has limits. We suggest 70 emails per hour to be safe. [link]Find out more[/link].', WYSIJA)).'</p>'; 
  1013. ?> 
  1014. </th> 
  1015. <td colspan="<?php echo ( is_multisite() ? 3 : 2 ); ?>"> 
  1016.  
  1017. <?php 
  1018. $name = 'sending_emails_number'; 
  1019. $id = str_replace('_', '-', $name); 
  1020. $value = $this->model->getValue($name); 
  1021. $params = array( "id" => $id, 'name' => 'wysija[config]['.$name.']', 'size' => '6' ); 
  1022. //if($this->model->getValue("smtp_host")=="smtp.gmail.com") $params["readonly"]="readonly"; 
  1023. $field = $helper_forms->input($params, $value); 
  1024. $field.= '<span class="mailpoet-frequency_inner_texting">'.__('emails', WYSIJA).'</span>'; 
  1025.  
  1026.  
  1027. $name = 'sending_emails_each'; 
  1028. $id = str_replace('_', '-', $name); 
  1029. $value = $this->model->getValue($name); 
  1030. $field .=$helper_forms->dropdown(array( 'name' => 'wysija[config]['.$name.']', 'id' => $id ), $helper_forms->eachValues, $value); 
  1031. echo $field; 
  1032. echo '<div class="mailpoet-frequency_warning hidden"><b>'.__('This is fast!', WYSIJA).'</b> '.str_replace(array( '[link]', '[/link]' ), array( '<a href="http://support.mailpoet.com/knowledgebase/wp-cron-batch-emails-sending-frequency/?utm_source=wpadmin&utm_campaign=cron" target="_blank">', '</a>' ), __('We suggest you setup a cron job. [link]Read more[/link] on support.mailpoet.com', WYSIJA)).'</span>'; 
  1033. ?> 
  1034. </td> 
  1035. </tr> 
  1036.  
  1037. </tbody> 
  1038. </table> 
  1039. <script> 
  1040. wysija_translations = {}; 
  1041. wysija_translations.api = "<?php _e('API Key', WYSIJA); ?>"; 
  1042. wysija_translations.password = "<?php _e('Password', WYSIJA); ?>"; 
  1043. </script> 
  1044. <?php 
  1045.  
  1046. function clearlog() { 
  1047.  
  1048. echo '<h3>Logs have been cleared</h3>'; 
  1049.  
  1050. function log() { 
  1051. $option_log = get_option('wysija_log'); 
  1052.  
  1053. foreach ($option_log as $key => $data) { 
  1054. echo '<h3>'.$key.'</h3>'; 
  1055. dbg($data, 0); 
  1056.  
  1057. function advanced($data) { 
  1058.  
  1059. $advanced_fields = $super_advanced_fields = array( ); 
  1060. $advanced_fields ['role_campaign'] = array( 
  1061. 'type' => 'capabilities',  
  1062. '1col' => 1 ); 
  1063.  
  1064. $advanced_fields['replyto_name'] = array( 
  1065. 'type' => 'fromname',  
  1066. 'class' => 'validate[required]',  
  1067. 'label' => __('Reply-to name & email', WYSIJA),  
  1068. 'desc' => __('You can change the default reply-to name and email for your newsletters. This option is also used for the activation emails and Admin notifications (in Basics).', WYSIJA) ); 
  1069.  
  1070. $helper_licence = WYSIJA::get('licence', 'helper'); 
  1071. $url_checkout = $helper_licence->get_url_checkout('bounce_address_automated'); 
  1072. $advanced_fields ['bounce_email'] = array( 
  1073. 'type' => 'input',  
  1074. 'label' => __('Bounce Email', WYSIJA),  
  1075. 'desc' => __('To which address should all the bounced emails go? Get the [link]Premium version[/link] to automatically handle these.', WYSIJA),  
  1076. 'link' => '<a href="'.$url_checkout.'" target="_blank" title="'.__('Purchase the premium version.', WYSIJA).'">' ); 
  1077.  
  1078. $advanced_fields = apply_filters('wysija_settings_advanced', $advanced_fields); 
  1079.  
  1080. $modelU = WYSIJA::get('user', 'model'); 
  1081.  
  1082. $advanced_fields ['manage_subscriptions'] = array( 
  1083. 'type' => 'managesubscribe',  
  1084. 'label' => __('Subscribers can edit their profile', WYSIJA),  
  1085. 'desc' => __('Add a link in the footer of all your newsletters so subscribers can edit their profile and lists. [link]See your own subscriber profile page.[/link]', WYSIJA),  
  1086. 'link' => '<a href="'.$modelU->getConfirmLink(false, 'subscriptions', false, true).'" target="_blank" title="'.__('Preview page', WYSIJA).'">', ); 
  1087.  
  1088. $advanced_fields['subscriptions_page'] = array( 
  1089. 'type' => 'page_selection',  
  1090. 'label' => __('Subscriber profile page', WYSIJA),  
  1091. 'desc' => __('Select the page to display the subscriber\'s profile.', WYSIJA),  
  1092. 'rowclass' => 'manage_subscriptions',  
  1093. ); 
  1094.  
  1095. $advanced_fields ['html_source'] = array( 
  1096. 'label' => __('Allow HTML edits', WYSIJA),  
  1097. 'type' => 'radio',  
  1098. 'values' => array( true => __('Yes', WYSIJA), false => __('No', WYSIJA) ),  
  1099. 'desc' => __('This allows you to modify the HTML of text blocks in the visual editor.', WYSIJA) 
  1100. ); 
  1101.  
  1102. $advanced_fields ['analytics'] = array( 
  1103. 'rowclass' => 'analytics',  
  1104. 'type' => 'radio',  
  1105. 'values' => array( true => __('Yes', WYSIJA), false => __('No', WYSIJA) ),  
  1106. 'label' => __('Share anonymous data', WYSIJA),  
  1107. 'desc' => __('Share anonymous data and help us improve the plugin. [link]Read more[/link].', WYSIJA),  
  1108. 'link' => '<a target="_blank" href="http://support.mailpoet.com/knowledgebase/share-your-data/?utm_source=wpadmin&utm_campaign=advanced_settings">' 
  1109. ); 
  1110.  
  1111. $advanced_fields ['industry'] = array( 
  1112. 'rowclass' => 'industry',  
  1113. 'type' => 'dropdown_keyval',  
  1114. 'values' => array( 
  1115. 'other' => __('other', WYSIJA),  
  1116. 'art' => __('art', WYSIJA),  
  1117. 'business' => __('business', WYSIJA),  
  1118. 'education' => __('education', WYSIJA),  
  1119. 'e-commerce' => __('e-commerce', WYSIJA),  
  1120. 'food' => __('food', WYSIJA),  
  1121. 'insurance' => __('insurance', WYSIJA),  
  1122. 'government' => __('government', WYSIJA),  
  1123. 'health and sports' => __('health and sports', WYSIJA),  
  1124. 'manufacturing' => __('manufacturing', WYSIJA),  
  1125. 'marketing and media' => __('marketing and media', WYSIJA),  
  1126. 'non profit' => __('non profit', WYSIJA),  
  1127. 'photography' => __('photography', WYSIJA),  
  1128. 'travel' => __('travel', WYSIJA),  
  1129. 'real estate' => __('real estate', WYSIJA),  
  1130. 'religious' => __('religious', WYSIJA),  
  1131. 'technology' => __('technology', WYSIJA) 
  1132. ),  
  1133. 'label' => __('Industry', WYSIJA),  
  1134. 'desc' => __('Select your industry.', WYSIJA) ); 
  1135.  
  1136. $super_advanced_fields ['subscribers_count'] = array( 
  1137. 'type' => 'subscribers_count',  
  1138. 'label' => __('Shortcode to display total number of subscribers', WYSIJA),  
  1139. 'desc' => __('Paste this shortcode to display the number of confirmed subscribers in post or page.', WYSIJA) 
  1140. ); 
  1141.  
  1142.  
  1143.  
  1144. $super_advanced_fields ['advanced_charset'] = array( 
  1145. 'type' => 'dropdown_keyval',  
  1146. 'values' => array( 'UTF-8', 'UTF-7', 'BIG5', 'ISO-2022-JP',  
  1147. 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3',  
  1148. 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6',  
  1149. 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',  
  1150. 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14',  
  1151. 'ISO-8859-15', 'Windows-1251', 'Windows-1252' ),  
  1152. 'label' => __('Charset', WYSIJA),  
  1153. 'desc' => __('Squares or weird characters are displayed in your emails? Select the encoding for your language.', WYSIJA) ); 
  1154.  
  1155. $super_advanced_fields = apply_filters('wysija_settings_advancednext', $super_advanced_fields); 
  1156.  
  1157. $super_advanced_fields ['cron_manual'] = array( 
  1158. 'type' => 'cron',  
  1159. 'label' => __('Enable MailPoet\'s Cron', WYSIJA),  
  1160. 'desc' => __('None of your queued emails have been sent? Then activate this option.', WYSIJA) ); 
  1161.  
  1162.  
  1163. $super_advanced_fields ['debug_new'] = array( 
  1164. 'type' => 'debugnew',  
  1165. 'label' => __('Debug mode', WYSIJA),  
  1166. 'desc' => __('Enable this to show MailPoet\'s errors. Our support might ask you to enable this if you seek their help.', WYSIJA) ); 
  1167.  
  1168. if (WYSIJA_DBG > 1) { 
  1169. $advanced_fields ['debug_log'] = array( 
  1170. 'type' => 'debuglog',  
  1171. 'label' => 'Logs',  
  1172. 'desc' => str_replace(array( '[link]', '[linkclear]', '[/link]', '[/linkclear]' ), array( '<a href="admin.php?page=wysija_config&action=log" target="_blank">', '<a target="_blank" href="admin.php?page=wysija_config&action=clearlog&_wpnonce='.$this->secure(array( 'action' => 'clearlog' ), true).'">', '</a>', '</a>' ), 'View them [link]here[/link]. Clear them [linkclear]here[/linkclear]') ); 
  1173.  
  1174. //attach 'super-advanced' class to super_advanced_fields 
  1175. $super_advanced_field_class = 'super-advanced'; 
  1176. foreach ($super_advanced_fields as $key => $field) { 
  1177. if (!empty($super_advanced_fields[$key]['rowclass'])) 
  1178. $super_advanced_fields[$key]['rowclass'] = $super_advanced_fields[$key]['rowclass'].' '.$super_advanced_field_class; 
  1179. else 
  1180. $super_advanced_fields[$key]['rowclass'] = $super_advanced_field_class; 
  1181. ?> 
  1182. <table class="form-table"> 
  1183. <tbody> 
  1184. <?php echo $this->buildMyForm($advanced_fields, '', 'config'); ?> 
  1185. <tr class='title_row'> 
  1186. <td colspan="2"> 
  1187. <h3 class='title' alt='<?php esc_attr_e('Do or do not. There is no try.', WYSIJA); ?>'> 
  1188. <?php _e("Geeky Options", WYSIJA); ?> 
  1189. <a href='#geeky_options' alt='<?php esc_attr_e("Toggle Geeky Options", WYSIJA); ?>' data-hide='<?php esc_attr_e("Hide", WYSIJA); ?>' class='add-new-h2 mailpoet-geeky-toggle is_toggled'><?php esc_attr_e("Show", WYSIJA); ?></a> 
  1190. </h3> 
  1191. </td> 
  1192. </tr> 
  1193. <?php if (!empty($data['hooks']['hook_settings_super_advanced'])) echo $data['hooks']['hook_settings_super_advanced']; ?> 
  1194. <?php echo $this->buildMyForm($super_advanced_fields, '', 'config'); ?> 
  1195. <?php if (current_user_can('delete_plugins')): ?> 
  1196. <tr class="<?php echo $super_advanced_field_class ?>"> 
  1197. <th scope="row"> 
  1198. <div class="label"><?php _e('Reinstall from scratch', WYSIJA) ?> 
  1199. <p class="description"><?php _e('Want to start all over again? This will wipe out MailPoet and reinstall anew.', WYSIJA) ?></p> 
  1200. </div> 
  1201. </th> 
  1202. <td> 
  1203. <p> 
  1204. <a class="button" href="admin.php?page=wysija_config&action=reinstall"><?php _e('Reinstall now...', WYSIJA); ?></a> 
  1205. </p> 
  1206. </td> 
  1207. </tr> 
  1208. <?php endif ?> 
  1209. </tbody> 
  1210. </table> 
  1211. <?php 
  1212.  
  1213. /** 
  1214. * Add-ons Manager developed by Sebs Studio 
  1215. */ 
  1216. function add_ons() { 
  1217. include_once(WYSIJA_DIR.'/add-ons/add-ons.php'); 
  1218.  
  1219. /** 
  1220. * filter adding its own tab to wysija's config(this deals with the name of the tab) 
  1221. * @param string $tabs 
  1222. * @return string 
  1223. */ 
  1224. function ms_tab_name($tabs) { 
  1225. $tabs['multisite'] = 'MS'; 
  1226. return $tabs; 
  1227.  
  1228. /** 
  1229. * filter adding its own tab to wysija's config (this deals with the content of the tab) 
  1230. * @param type $htmlContent 
  1231. * @param type $arg 
  1232. * @return string 
  1233. */ 
  1234. function ms_tab_content($htmlContent, $arg) { 
  1235. $this->viewObj = $arg['viewObj']; 
  1236. $mConfig = WYSIJA::get('config', 'model'); 
  1237. $formsHelp = WYSIJA::get('forms', 'helper'); 
  1238.  
  1239. $htmlContent .='<div id="multisite" class="wysija-panel hidden">'; //start multisite div 
  1240. $htmlContent.= '<div class="intro"><h3>'.__('Pick your prefered configuration?', WYSIJA).'</h3></div>'; 
  1241.  
  1242. $htmlContent.= '<table class="form-table" id="form-ms-config"> 
  1243. <tbody> 
  1244. <tr class="methods"> 
  1245. <th scope="row">'; 
  1246.  
  1247. $checked = false; 
  1248. $key = 'ms_sending_config'; 
  1249. $realvalue = $mConfig->getValue($key); 
  1250. $value = 'one-for-all'; 
  1251. $id = str_replace('_', '-', $key).'-'.$value; 
  1252. if ($value == $realvalue) 
  1253. $checked = true; 
  1254. $field = '<label for="'.$id.'" class="clearfix">'; 
  1255. $field.=$formsHelp->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1256. $field.='<p class="title"><strong>'.__('One configuration for all sites', WYSIJA).'</strong></p></label>'; 
  1257. $field.='<p>'.__('Enforce all sites to send with a unique FROM email address. You only need to configure the Automated Bounce Handling (Premium), SPF & DKIM only once.', WYSIJA).'</p>'; 
  1258. $field.='<p>'.__('Users can still change their reply-to address for their newsletter. Network admins can still edit sending method for each site.', WYSIJA).'</p>'; 
  1259. $htmlContent.= $field; 
  1260.  
  1261. $htmlContent.= '</th><th scope="row">'; 
  1262.  
  1263. $checked = false; 
  1264. $value = 'one-each'; 
  1265. $id = str_replace('_', '-', $key).'-'.$value; 
  1266. if ($value == $realvalue) 
  1267. $checked = true; 
  1268. $field = '<label for="'.$id.'" class="clearfix">'; 
  1269. $field.=$formsHelp->radio(array( "id" => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1270. $field.='<p class="title"><strong>'.__('Configure each site manually', WYSIJA).'</strong></p></label>'; 
  1271. $field.='<p>'.__('Configure SPF and DKIM independently for each site.', WYSIJA).'</p>'; 
  1272. $htmlContent.= $field; 
  1273.  
  1274. $htmlContent.= '</th><td> 
  1275. </td> 
  1276. </tr>'; 
  1277.  
  1278. $htmlContent.='</tbody></table>'; 
  1279.  
  1280. $htmlContent.='<div class="intro"><h3>'.__('Configuration and Permissions', WYSIJA).'</h3></div>'; 
  1281.  
  1282. $fields = array( ); 
  1283.  
  1284.  
  1285. $fields['ms_allow_admin_sending_method'] = array( 
  1286. 'type' => 'debug',  
  1287. 'label' => __('Allow site admins to change the sending method', WYSIJA) ); 
  1288. $fields['ms_allow_admin_toggle_signup_confirmation'] = array( 
  1289. 'type' => 'debug',  
  1290. 'label' => __('Allow site admins to deactivate Signup Confirmation', WYSIJA) ); 
  1291.  
  1292. $htmlContent.='<table class="form-table"><tbody>'; 
  1293. $htmlContent.=$this->viewObj->buildMyForm($fields, '', 'config'); 
  1294. $htmlContent.='</tbody></table>'; 
  1295.  
  1296. $htmlContent.='<div class="intro"><h3>'.__('Network\'s Default Sending Method', WYSIJA).'</h3></div>'; 
  1297. $htmlContent.=$this->ms_sending_method(); 
  1298. if (false) { 
  1299. $htmlContent.= '<div class="intro"><h3>'.__('SPF and DKIM', WYSIJA).'</h3></div>'; 
  1300.  
  1301. $htmlContent.= '<table class="form-table"> 
  1302. <tbody> 
  1303. <tr class="methods"> 
  1304. <th scope="row">'; 
  1305.  
  1306. $htmlContent.='<p>'.__('Your SPF record', WYSIJA).'</p>'; 
  1307.  
  1308. $htmlContent.= '</th>'; 
  1309. $htmlContent.= '<th scope="row"></th><td></td></tr>'; 
  1310.  
  1311. $htmlContent.='</tbody></table>'; 
  1312.  
  1313.  
  1314. $htmlContent .='<p class="submit"><input type="submit" value="'.esc_attr(__('Save settings', WYSIJA)).'" class="button-primary wysija" /></p>'; 
  1315. $htmlContent.='</div>'; //end multisite div 
  1316.  
  1317. return $htmlContent; 
  1318.  
  1319. function ms_sending_method() { 
  1320. $prefix = 'ms_'; 
  1321. $model_config = WYSIJA::get('config', 'model'); 
  1322. $helper_forms = WYSIJA::get('forms', 'helper'); 
  1323. $html_content = '<table class="form-table" id="ms-sendingmethod"> 
  1324. <tbody>'; 
  1325.  
  1326.  
  1327.  
  1328. $key = $prefix.'sending_method'; 
  1329.  
  1330. $realvalue = $model_config->getValue($key); 
  1331. $html_content .= '<tr class="methods"> 
  1332. <th scope="row">'; 
  1333.  
  1334. $checked = false; 
  1335. $value = 'site'; 
  1336. $id = str_replace("_", '-', $key).'-'.$value; 
  1337. if ($value == $realvalue) 
  1338. $checked = true; 
  1339. $field = '<label for="'.$id.'" class="clearfix">'; 
  1340. $field.=$helper_forms->radio(array( "id" => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1341. $field.='<h3>'.__('Your own website', WYSIJA).'</h3></label>'; 
  1342. $html_content.=$field; 
  1343. $html_content.='</th> 
  1344. <th scope="row">'; 
  1345.  
  1346. $checked = false; 
  1347. $value = 'smtp'; 
  1348. if ($value === $realvalue) 
  1349. $checked = true; 
  1350.  
  1351. $id = str_replace('_', '-', $key).'-'.$value; 
  1352. $field = '<label for="'.$id.'" class="clearfix">'; 
  1353. $field.= $helper_forms->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1354. $field.= '<h3>'.__('Third party', WYSIJA).'</h3></label>'; 
  1355. $html_content.=$field; 
  1356. $html_content.='</th> 
  1357.  
  1358. <td> 
  1359. </td> 
  1360. </tr>'; 
  1361.  
  1362.  
  1363. $html_content.='<tr> 
  1364. <th scope="row">'; 
  1365.  
  1366. $key = $prefix.'from_email'; 
  1367. $id = str_replace('_', '-', $key); 
  1368. $field = '<label for="'.$id.'">'.__('FROM email address for sites using this method', WYSIJA)."</label>"; 
  1369. $html_content.=$field; 
  1370. $html_content.=' 
  1371. </th> 
  1372. <td colspan="2">'; 
  1373. $html_content.=$helper_forms->input(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '40' ), $model_config->getValue($key)); 
  1374. $html_content.='</td> 
  1375. </tr>'; 
  1376.  
  1377. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-site"> 
  1378. <th scope="row">'; 
  1379. $field = __('Delivery method', WYSIJA); 
  1380. $field.='<p class="description">'.__('Send yourself some test emails to confirm which method works with your server.', WYSIJA).'</p>'; 
  1381. $html_content.=$field; 
  1382.  
  1383. $html_content.='</th> 
  1384. <td colspan="2">'; 
  1385.  
  1386. $key = $prefix.'sending_emails_site_method'; 
  1387. $checked = false; 
  1388. $realvalue = $model_config->getValue($key); 
  1389. $value = 'phpmail'; 
  1390. if ($value == $realvalue) 
  1391. $checked = true; 
  1392.  
  1393. $id = str_replace('_', '-', $key).'-'.$value; 
  1394. $field = '<p class="title"><label for="'.$id.'">'; 
  1395. $field.=$helper_forms->radio(array( "id" => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1396. $field.='PHP Mail</label></p>'; 
  1397. $field.='<p class="description">'.__('This email engine works on 95% of servers', WYSIJA).'</p>'; 
  1398.  
  1399.  
  1400. if ($model_config->getValue('allow_wpmail')) { 
  1401. $checked = false; 
  1402. $value = 'wpmail'; 
  1403. if ($value == $realvalue) 
  1404. $checked = true; 
  1405.  
  1406. $id = str_replace('_', '-', $key).'-'.$value; 
  1407. $field.='<p class="title"><label for="'.$id.'">'; 
  1408. $field.=$helper_forms->radio(array( "id" => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1409. $field.='WP Mail</label></p>'; 
  1410. $field.='<p class="description">'.__('Use the same method as the one used for your WP site.', WYSIJA).'</p>'; 
  1411.  
  1412.  
  1413. $html_content.=$field; 
  1414. $html_content.='</td> 
  1415. </tr>'; 
  1416.  
  1417. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-smtp"> 
  1418. <th scope="row">'; 
  1419.  
  1420. $key = $prefix.'smtp_host'; 
  1421. $id = str_replace('_', '-', $key); 
  1422. $field = '<label for="'.$id.'">'.__('SMTP Hostname', WYSIJA)."</label>"; 
  1423. $field.='<p class="description">'.__('e.g.:smtp.mydomain.com', WYSIJA).'</p>'; 
  1424. $html_content.=$field; 
  1425. $html_content.=' 
  1426. </th> 
  1427. <td colspan="2">'; 
  1428.  
  1429. $value = $model_config->getValue($key); 
  1430. $field = $helper_forms->input(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '40' ), $value, $checked); 
  1431. $html_content.=$field; 
  1432. $html_content.='</td> 
  1433. </tr>'; 
  1434.  
  1435. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-smtp"> 
  1436. <th scope="row">'; 
  1437.  
  1438. $key = $prefix.'smtp_login'; 
  1439. $id = str_replace('_', '-', $key); 
  1440. $field = '<label for="'.$id.'">'.__('Login', WYSIJA)."</label>"; 
  1441.  
  1442. $html_content.=$field; 
  1443.  
  1444. $html_content.='</th> 
  1445. <td colspan="2">'; 
  1446.  
  1447. $value = $model_config->getValue($key); 
  1448. $field = $helper_forms->input(array( "id" => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '40' ), $value, $checked); 
  1449. $html_content.=$field; 
  1450. $html_content.='</td> 
  1451. </tr>'; 
  1452.  
  1453. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-smtp"> 
  1454. <th scope="row">'; 
  1455.  
  1456. $key = $prefix.'smtp_password'; 
  1457. $id = str_replace('_', '-', $key); 
  1458. $field = '<label for="'.$id.'">'.__('Password', WYSIJA)."</label>"; 
  1459. $html_content.=$field; 
  1460.  
  1461. $html_content.='</th> 
  1462. <td colspan="2">'; 
  1463.  
  1464. $value = $model_config->getValue($key); 
  1465. $field = $helper_forms->input(array( "type" => "password", "id" => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '40' ), $value, $checked); 
  1466. $html_content.=$field; 
  1467.  
  1468. $html_content.='</td> 
  1469. </tr>'; 
  1470.  
  1471. $html_content.='<tr id="ms-restapipossible" class="hidechoice"> 
  1472. <th scope="row">'; 
  1473.  
  1474. $key = $prefix.'smtp_rest'; 
  1475. $id = str_replace('_', '-', $key); 
  1476. $field = '<label for="'.$id.'">web API</label>'; 
  1477. $field.='<p class="description">'.__('Activate if your SMTP ports are blocked.', WYSIJA).'</p>'; 
  1478. $html_content.=$field; 
  1479.  
  1480. $html_content.='</th> 
  1481. <td colspan="2">'; 
  1482.  
  1483. $value = $model_config->getValue($key); 
  1484. $checked = false; 
  1485. if ($value) 
  1486. $checked = true; 
  1487. $field = $helper_forms->checkbox(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '3' ), 1, $checked); 
  1488.  
  1489. $html_content.=$field; 
  1490.  
  1491. $html_content.='</td> 
  1492. </tr>'; 
  1493.  
  1494. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-smtp ms-choice-no-restapi"> 
  1495. <th scope="row">'; 
  1496.  
  1497. $key = $prefix.'smtp_port'; 
  1498. $id = str_replace('_', '-', $key); 
  1499. $field = '<label for="'.$id.'">'.__('SMTP port', WYSIJA)."</label>"; 
  1500.  
  1501. $html_content.=$field; 
  1502.  
  1503. $html_content.='</th> 
  1504. <td colspan="2">'; 
  1505.  
  1506. $value = $model_config->getValue($key); 
  1507. $field = $helper_forms->input(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']', 'size' => '3' ), $value, $checked); 
  1508.  
  1509. $html_content.=$field; 
  1510. $html_content.='</td> 
  1511. </tr>'; 
  1512.  
  1513. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-smtp ms-choice-no-restapi"> 
  1514. <th scope="row">'; 
  1515.  
  1516. $key = $prefix.'smtp_secure'; 
  1517. $id = str_replace('_', '-', $key); 
  1518. $field = '<label for="'.$id.'">'.__('Secure connection', WYSIJA)."</label>"; 
  1519. $html_content.=$field; 
  1520. $html_content.='</th> 
  1521. <td colspan="2">'; 
  1522.  
  1523. $value = $model_config->getValue($key); 
  1524.  
  1525. $field = $helper_forms->dropdown(array( 'name' => 'wysija[config]['.$key.']', "id" => $id ), array( false => __("No"), "ssl" => "SSL", "tls" => "TLS" ), $value); 
  1526. $html_content.=$field; 
  1527.  
  1528. $html_content.='</td> 
  1529. </tr>'; 
  1530.  
  1531. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-smtp ms-choice-no-restapi"> 
  1532. <th scope="row">'; 
  1533.  
  1534. $field = __('Authentication', WYSIJA); 
  1535. $html_content.=$field.'<p class="description">'.__("Leave this option to Yes. Only a tiny portion of SMTP services ask Authentication to be turned off.", WYSIJA).'</p>'; 
  1536. $html_content.='</th> 
  1537. <td colspan="2">'; 
  1538.  
  1539. $key = $prefix.'smtp_auth'; 
  1540. $realvalue = $model_config->getValue($key); 
  1541.  
  1542. $value = false; 
  1543. $checked = false; 
  1544. if ($value == $realvalue) 
  1545. $checked = true; 
  1546. $id = str_replace('_', '-', $key).'-'.$value; 
  1547. $field = '<label for="'.$id.'">'; 
  1548. $field.=$helper_forms->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1549. $field.=__('No', WYSIJA).'</label>'; 
  1550.  
  1551. $value = true; 
  1552. $checked = false; 
  1553. if ($value == $realvalue) 
  1554. $checked = true; 
  1555. $id = str_replace('_', '-', $key).'-'.$value; 
  1556. $field.='<label for="'.$id.'">'; 
  1557. $field.=$helper_forms->radio(array( 'id' => $id, 'name' => 'wysija[config]['.$key.']' ), $value, $checked); 
  1558. $field.=__('Yes', WYSIJA).'</label>'; 
  1559.  
  1560.  
  1561. $html_content.=$field; 
  1562. $html_content.='</td> 
  1563. </tr>'; 
  1564.  
  1565. $current_user = wp_get_current_user(); 
  1566. $html_content .= 
  1567. '<tr class="ms-hidechoice ms-choice-sending-method-smtp ms-choice-sending-method-site">'. 
  1568. '<th scope="row">'. 
  1569. __('Test method'). 
  1570. '</th>'. 
  1571. '<td colspan="'.( is_multisite() ? 3 : 2 ).'">'. 
  1572. '<input type="text" value="'.esc_attr($current_user->data->user_email).'" class="mailpoet-test-emails" name="wysija[config][test_mails]" />'. 
  1573. '<a class="button-secondary mailpoet-test-delivery" data-multisite="'.( is_multisite() ? 'true' : 'false' ).'">'.esc_attr__('Send a test mail', WYSIJA).'</a>'. 
  1574. '</td>'. 
  1575. '</tr>'; 
  1576.  
  1577.  
  1578. $html_content.='<tr class="ms-hidechoice ms-choice-sending-method-smtp ms-choice-sending-method-site"> 
  1579. <th scope="row">'; 
  1580.  
  1581. $field = __('Send...', WYSIJA); 
  1582.  
  1583. $html_content.=$field.'<p class="description">'.str_replace(array( '[link]', '[/link]' ), array( '<a href="http://support.mailpoet.com/knowledgebase/wp-cron-batch-emails-sending-frequency/?utm_source=wpadmin&utm_campaign=choosing%20frequency" target="_blank">', '</a>' ), __('Your web host has limits. We suggest 70 emails per hour to be safe. [link]Find out more[/link].', WYSIJA)).'</p>'; 
  1584. $html_content.='</th> 
  1585. <td colspan="2">'; 
  1586.  
  1587. $name = $prefix.'sending_emails_number'; 
  1588. $id = str_replace('_', '-', $name); 
  1589. $value = $model_config->getValue($name); 
  1590. $params = array( 'id' => $id, 'name' => 'wysija[config]['.$name.']', 'size' => '6' ); 
  1591. $field = $helper_forms->input($params, $value); 
  1592. $field.= ' '.__('emails', WYSIJA).' '; 
  1593.  
  1594.  
  1595. $name = $prefix.'sending_emails_each'; 
  1596. $id = str_replace('_', '-', $name); 
  1597. $value = $model_config->getValue($name); 
  1598. $field.=$helper_forms->dropdown(array( 'name' => 'wysija[config]['.$name.']', 'id' => $id ), $helper_forms->eachValues, $value); 
  1599. $field.='<span class="ms-choice-under15"><b>'.__('This is fast!', WYSIJA).'</b> '.str_replace(array( '[link]', '[/link]' ), array( '<a href="http://support.mailpoet.com/knowledgebase/wp-cron-batch-emails-sending-frequency/?utm_source=wpadmin&utm_campaign=cron" target="_blank">', '</a>' ), __('We suggest you setup a cron job. [link]Read more[/link] on support.mailpoet.com', WYSIJA)).'</span>'; 
  1600. $html_content.=$field; 
  1601.  
  1602.  
  1603. $html_content.='</td> 
  1604. </tr> 
  1605. </tbody> 
  1606. </table>'; 
  1607. return $html_content; 
  1608.  
  1609. // WYSIJA Form Editor 
  1610. function form_list() { 
  1611. $model_forms = WYSIJA::get('forms', 'model'); 
  1612.  
  1613. $forms = $model_forms->getRows(); 
  1614.  
  1615. // get available lists which users can subscribe to 
  1616. $model_list = WYSIJA::get('list', 'model'); 
  1617.  
  1618. // get lists users can subscribe to (aka "enabled list") 
  1619. $lists = $model_list->get(array( 'name', 'list_id', 'is_public' ), array( 'is_enabled' => 1 )); 
  1620.  
  1621. // generate table header/footer 
  1622. $table_headers = ' 
  1623. <th class="manage-column" scope="col"><span>'.__('Name', WYSIJA).'</span></th> 
  1624. <th class="manage-column" scope="col"><span>'.__('Lists', WYSIJA).'</span></th> 
  1625. '; 
  1626.  
  1627. $classes = function_exists('wp_star_rating') ? 'add-new-h2' : 'button-secondary2'; 
  1628. ?> 
  1629.  
  1630. <!-- Create a new form --> 
  1631. <p class="new_form"> 
  1632. <a class="<?php echo $classes; ?>" href="admin.php?page=wysija_config&action=form_add&_wpnonce=<?php echo $this->secure(array( "action" => "form_add" ), true); ?>"><?php _e('Create a new form', WYSIJA); ?></a> 
  1633. </p> 
  1634.  
  1635. <?php 
  1636. if (count($forms) > 0) { 
  1637. ?> 
  1638. <!-- List of forms --> 
  1639. <div class="list"> 
  1640. <table cellspacing="0" class="widefat fixed"> 
  1641. <thead> 
  1642. <tr> 
  1643. <?php echo $table_headers; ?> 
  1644. </tr> 
  1645. </thead> 
  1646. <tfoot> 
  1647. <tr> 
  1648. <?php echo $table_headers; ?> 
  1649. </tr> 
  1650. </tfoot> 
  1651.  
  1652. <tbody> 
  1653. <?php 
  1654. for ($i = 0, $count = count($forms); $i < $count; $i++) { 
  1655. // set current row 
  1656. $row = $forms[$i]; 
  1657.  
  1658. // get lists in settings and build list of lists (separated by ", " for display only) 
  1659. $form_data = unserialize(base64_decode($row['data'])); 
  1660.  
  1661. $form_lists = array( ); 
  1662. if (isset($form_data['settings']['lists']) && !empty($form_data['settings']['lists'])) { 
  1663. for ($j = 0, $list_count = count($lists); $j < $list_count; $j++) { 
  1664. if (in_array($lists[$j]['list_id'], $form_data['settings']['lists'])) { 
  1665. $form_lists[] = $lists[$j]['name']; 
  1666.  
  1667. // format list of lists depending on who's choosing the list to subscribe to (admin OR user) 
  1668. if (empty($form_lists)) { 
  1669. $form_lists_display = '<strong>'.__('No list specified', WYSIJA).'</strong>'; 
  1670. else { 
  1671. if ($form_data['settings']['lists_selected_by'] === 'user') { 
  1672. // user can select his own lists 
  1673. $form_lists_display = sprintf(__('User choice: %s', WYSIJA), join(', ', $form_lists)); 
  1674. else { 
  1675. // admin has selected which lists the user subscribes to 
  1676. $form_lists_display = join(', ', $form_lists); 
  1677. ?> 
  1678. <tr class="<?php echo (($i % 2) ? 'alternate' : ''); ?>"> 
  1679. <td> 
  1680. <?php echo $row['name']; ?> 
  1681. <div class="row-actions"> 
  1682. <span class="edit"> 
  1683. <a href="admin.php?page=wysija_config&action=form_edit&id=<?php echo $row['form_id'] ?>"><?php _e('Edit', WYSIJA); ?></a> 
  1684. </span> | 
  1685. <span class="duplicate"> 
  1686. <a href="admin.php?page=wysija_config&action=form_duplicate&id=<?php echo $row['form_id'] ?>&_wpnonce=<?php echo $this->secure(array( 'action' => 'form_duplicate', 'id' => $row['form_id'] ), true); ?>"><?php _e('Duplicate', WYSIJA) ?></a> 
  1687. </span> | 
  1688. <span class="delete"> 
  1689. <a href="admin.php?page=wysija_config&action=form_delete&id=<?php echo $row['form_id'] ?>&_wpnonce=<?php echo $this->secure(array( 'action' => 'form_delete', 'id' => $row['form_id'] ), true); ?>" class="submitdelete"><?php _e('Delete', WYSIJA) ?></a> 
  1690. </span> 
  1691. </div> 
  1692. </td> 
  1693. <td> 
  1694. <?php echo $form_lists_display ?> 
  1695. </td> 
  1696. </tr><?php 
  1697. }//endfor 
  1698. ?> 
  1699. </tbody> 
  1700. </table> 
  1701. </div> 
  1702. <?php 
  1703. } //endif 
  1704.  
  1705. function form_edit($data) { 
  1706. // get form editor rendering engine 
  1707. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  1708. $helper_form_engine->set_lists($data['lists']); 
  1709. $helper_form_engine->set_data($data['form']['data'], true); 
  1710. $classes = function_exists('wp_star_rating') ? 'add-new-h2' : 'button-secondary2'; 
  1711. ?> 
  1712. <div class="icon32"><img src="<?php echo WYSIJA_URL ?>img/form-icon.png" alt="" /></div> 
  1713.  
  1714. <?php 
  1715. if ($data['can_edit'] === false) { 
  1716. echo '<h2 class="title clearfix">'; 
  1717. echo '<span>'.__('Edit form', WYSIJA).'</span>'; 
  1718. echo '</h2>'; 
  1719. echo __('Yikes! To edit a form, you need to have at least 1 list.', WYSIJA); 
  1720. echo '<a href="admin.php?page=wysija_subscribers&action=addlist" class="button-secondary2">'.__('Add List', WYSIJA).'</a>'; 
  1721. else { 
  1722. echo '<h2 class="title clearfix">'; 
  1723. echo '<span>'.__('Edit', WYSIJA).'</span>'; 
  1724. echo '<span id="form-name">'.$data['form']['name'].'</span>'; 
  1725. echo '<span id="form-name-default">'.$data['form']['name'].'</span>'; 
  1726. ?> 
  1727. <span> 
  1728. <a id="edit-form-name" class="button" href="javascript:;"><?php echo __('Edit name', WYSIJA); ?></a> 
  1729. <a class="<?php echo $classes; ?>" href="admin.php?page=wysija_config#tab-forms"><?php echo __('List of forms', WYSIJA); ?></a> 
  1730. </span> 
  1731. </h2> 
  1732.  
  1733. <div class="clearfix"> 
  1734. <!-- Form Editor Container --> 
  1735. <div id="wysija_form_container"> 
  1736. <!-- Form Editor --> 
  1737. <div id="wysija_form_editor"> 
  1738. <?php 
  1739. // render form editor 
  1740. echo $helper_form_engine->render_editor(); 
  1741. ?> 
  1742. </div> 
  1743.  
  1744. <!-- Form settings --> 
  1745. <form id="wysija-form-settings" action="" method="POST"> 
  1746. <input type="hidden" name="form_id" value="<?php echo (int)$data['form_id']; ?>" /> 
  1747.  
  1748. <!-- Form settings: list selection --> 
  1749. <div id="list-selection" class="clearfix"> 
  1750. <p> 
  1751. <strong><?php _e('This form adds subscribers to these lists:', WYSIJA) ?></strong> 
  1752. </p> 
  1753. <?php 
  1754. if (!empty($data['lists'])) { 
  1755. $form_lists = $helper_form_engine->get_setting('lists'); 
  1756. // make sure that form_lists is an array 
  1757. if ($form_lists === null or is_array($form_lists) === false) 
  1758. $form_lists = array( ); 
  1759.  
  1760. usort($data['lists'], array( $this, 'sort_by_name' )); 
  1761.  
  1762. print '<select id="lists-selection" name="lists" data-placeholder="'.__('Choose a list', WYSIJA).'" multiple class="chosen_select">'; 
  1763.  
  1764. for ($i = 0, $count = count($data['lists']); $i < $count; $i++) { 
  1765. $list = $data['lists'][$i]; 
  1766. $is_checked = (in_array($list['list_id'], $form_lists)) ? 'selected="selected"' : ''; 
  1767. //print '<label><input type="checkbox" class="checkbox" name="lists" value="' . $list['list_id'] . '" ' . $is_checked . ' />' . $list['name'] . '</label>'; 
  1768. print '<option value="'.$list['list_id'].'" '.$is_checked.' />'.$list['name'].'</option>'; 
  1769.  
  1770. print '</select>'; 
  1771. ?> 
  1772. </div> 
  1773.  
  1774. <!-- Form settings: after submit --> 
  1775. <div id="after-submit"> 
  1776. <p> 
  1777. <strong><?php _e('After submit...', WYSIJA) ?></strong> 
  1778. <input type="hidden" name="on_success" value="message" /> 
  1779. <!--<label><input type="radio" name="on_success" value="message" checked="checked" /><?php _e('show message', WYSIJA); ?></label> 
  1780. <label><input type="radio" name="on_success" value="page" /><?php _e('go to page', WYSIJA); ?></label>--> 
  1781. </p> 
  1782. <textarea name="success_message"><?php echo $helper_form_engine->get_setting('success_message'); ?></textarea> 
  1783. </div> 
  1784.  
  1785. <p id="form-error" style="display:none;"></p> 
  1786.  
  1787. <p class="submit"> 
  1788. <a href="javascript:;" id="form-save" class="button-primary wysija" ><?php echo esc_attr(__('Save', WYSIJA)); ?></a> 
  1789. </p> 
  1790.  
  1791. <p id="form-notice" style="display:none;"></p> 
  1792. </form> 
  1793.  
  1794. <!-- Form export links --> 
  1795. <div id="form-export-links"><p><?php echo str_replace(array( '[link]', '[/link]' ), array( '<a href="widgets.php" target="_blank">', '</a>' ), __('You can easily add this form to your theme\'s [link]Widgets areas[/link].', WYSIJA)); ?></p> 
  1796. <p><?php 
  1797. $text = __('[link_html]HTML[/link_html], [link_php]PHP[/link_php], [link_iframe]iframe[/link_iframe] and [link_shortcode]shortcode[/link_shortcode] versions are also available.', WYSIJA); 
  1798. echo str_replace( 
  1799. array( '[link_html]', '[link_php]', '[link_iframe]', '[link_shortcode]', '[/link_html]', '[/link_php]', '[/link_iframe]', '[/link_shortcode]' ), array( '<a target="javascript:;" class="expand-code" title="html">', '<a target="javascript:;" class="expand-code" title="php">', '<a target="javascript:;" class="expand-code" title="iframe">', '<a target="javascript:;" class="expand-code" title="shortcode">', '</a>', '</a>', '</a>', '</a>' ), $text); 
  1800. ?></p></div> 
  1801.  
  1802. <!-- Form export --> 
  1803. <div id="form-export"> 
  1804. <?php echo $helper_form_engine->render_editor_export($data['form_id']); ?> 
  1805. </div> 
  1806. </div> 
  1807. <!-- Form Editor: Toolbar --> 
  1808. <div id="wysija_form_toolbar"> 
  1809. <!-- <ul class="wysija_form_toolbar_tabs"> 
  1810. <li class="wjt-content"> 
  1811. <a class="selected" href="javascript:;" rel="wj_content"><?php _e('Content', WYSIJA) ?></a> 
  1812. </li> 
  1813. </ul> --> 
  1814.  
  1815. <!-- CONTENT BAR --> 
  1816. <ul class="wj_content"> 
  1817. <?php 
  1818. // render editor toolbar 
  1819. echo $helper_form_engine->render_editor_toolbar(); 
  1820. ?> 
  1821. </ul> 
  1822.  
  1823. <!-- WIDGET TEMPLATES --> 
  1824. <div id="wysija_widget_templates"> 
  1825. <?php 
  1826. // render editor widget templates 
  1827. echo $helper_form_engine->render_editor_templates(); 
  1828. ?> 
  1829. </div> 
  1830.  
  1831. <div id="wysija_notices" style="display:none;"><span id="wysija_notice_msg"></span><img alt="loader" style="display:none;" id="ajax-loading" src="<?php echo WYSIJA_URL ?>img/wpspin_light.gif" /></div> 
  1832. </div> 
  1833. </div> 
  1834. <script type="text/javascript" charset="utf-8"> 
  1835. wysijaAJAX.form_id = <?php echo (int)$_REQUEST['id'] ?>; 
  1836.  
  1837. function formEditorSave(callback) { 
  1838. wysijaAJAX.task = 'form_save'; 
  1839. wysijaAJAX._wpnonce = wysijanonces.config.form_save; 
  1840. wysijaAJAX.wysijaData = WysijaForm.save(); 
  1841. WYSIJA_SYNC_AJAX({ 
  1842. success: callback 
  1843. }); 
  1844.  
  1845. function refreshToolbar(data) { 
  1846. // update toolbar 
  1847. $('wysija_form_toolbar').down('.wj_content').innerHTML = Base64.decode(data.toolbar); 
  1848.  
  1849. // update templates 
  1850. $('wysija_widget_templates').innerHTML = Base64.decode(data.templates); 
  1851.  
  1852. // setup events on widgets 
  1853. setupToolbar(); 
  1854.  
  1855. function refreshBlocks(field_name, block) { 
  1856. var elements = $$('#wysija_form_editor .wysija_form_block[wysija_field="'+ field_name +'"]'); 
  1857.  
  1858. if(elements.length > 0) { 
  1859. $(elements).each(function(element) { 
  1860. // replace each block by new block 
  1861. refreshBlock(element, block); 
  1862. }); 
  1863.  
  1864. // init wysija form 
  1865. setTimeout(function() { 
  1866. formEditorSave(function() { WysijaForm.init() }); 
  1867. }, 1); 
  1868.  
  1869. function refreshBlock(element, block) { 
  1870. element.replace(Base64.decode(block)); 
  1871.  
  1872. function setupToolbar() { 
  1873. // add custom field button 
  1874. $('wysija-add-field').observe('click', function() { 
  1875. WysijaPopup.open(wysijatrans.add_field, $(this).readAttribute('href2'), function(data) { 
  1876. refreshToolbar(data); 
  1877.  
  1878. // make sure disabled widgets stay disabled after editing 
  1879. WysijaForm.toggleWidgets(); 
  1880. }); 
  1881. return false; 
  1882. }); 
  1883.  
  1884. // edit custom field settings 
  1885. $$('.wysija_form_item_settings').invoke('stopObserving', 'click'); 
  1886. $$('.wysija_form_item_settings').invoke('observe', 'click', function() { 
  1887. var self = this; 
  1888. // get field type 
  1889. var field_type = $(this).previous('.wysija_form_item').readAttribute('wysija_field'); 
  1890. toggleBlocksHighlight('on', field_type); 
  1891. WysijaPopup.open(wysijatrans.edit_field, $(this).readAttribute('href2'), function(data) { 
  1892. refreshToolbar(data); 
  1893.  
  1894. // get field type 
  1895. var field_name = $(self).previous('.wysija_form_item').readAttribute('wysija_field'); 
  1896. refreshBlocks(field_name, data.block); 
  1897.  
  1898. // make sure disabled widgets stay disabled after editing 
  1899. WysijaForm.toggleWidgets(); 
  1900.  
  1901. toggleBlocksHighlight('off', field_type); 
  1902. }, function() { 
  1903. toggleBlocksHighlight('off', field_type); 
  1904. }); 
  1905. return false; 
  1906. }); 
  1907.  
  1908. // remove custom field 
  1909. $$('.wysija_form_item_delete').invoke('stopObserving', 'click'); 
  1910. $$('.wysija_form_item_delete').invoke('observe', 'click', function(e) { 
  1911. // get field type 
  1912. var field_type = $(this).previous('.wysija_form_item').readAttribute('wysija_field'); 
  1913.  
  1914. // highlight blocks using this field type 
  1915. toggleBlocksHighlight('on', field_type); 
  1916.  
  1917. if(window.confirm(wysijatrans.delete_field_confirmation)) { 
  1918. // make ajax request 
  1919. wysijaAJAX.task = 'form_field_delete'; 
  1920. wysijaAJAX._wpnonce = wysijanonces.config.form_field_delete; 
  1921. // build data with field id 
  1922. var data = { field_id: parseInt($(this).readAttribute('data-field-id'), 10) },  
  1923. self = this; 
  1924. wysijaAJAX.wysijaData = Base64.encode(Object.toJSON(data).gsub('\\"', '"').gsub('"[{', '[{').gsub('}]"', '}]')); 
  1925.  
  1926. new Ajax.Request(wysijaAJAX.ajaxurl, { 
  1927. method: 'post',  
  1928. parameters: wysijaAJAX,  
  1929. onSuccess:function(response) { 
  1930. // remove widget from list 
  1931. $(self).up('li').remove(); 
  1932.  
  1933. // remove all blocks from the same type 
  1934. $$('.wysija_form_block[wysija_field="'+ field_type +'"]').each(function(element) { 
  1935. // get block id 
  1936. var block = WysijaForm.get($(element)); 
  1937. block.removeBlock(); 
  1938. }); 
  1939.  
  1940. // save form 
  1941. formEditorSave(); 
  1942. },  
  1943. onFailure:function(response) { 
  1944. // nothing we can do about it. 
  1945. }); 
  1946.  
  1947. // highlight blocks using this field type 
  1948. toggleBlocksHighlight('off', field_type); 
  1949. return false; 
  1950. }); 
  1951.  
  1952. function toggleBlocksHighlight(toggle, field_type) { 
  1953. if(field_type === undefined) return false; 
  1954.  
  1955. if(toggle === 'on') { 
  1956. // turn highlight on 
  1957. $$('.wysija_form_block[wysija_field="'+ field_type +'"]').invoke('addClassName', 'highlighted'); 
  1958. } else { 
  1959. // turn highlight off 
  1960. $$('.wysija_form_block[wysija_field="'+ field_type +'"]').invoke('removeClassName', 'highlighted'); 
  1961.  
  1962.  
  1963. $('form-save').observe('click', function() { 
  1964. // hide any previous error 
  1965. $('form-error').hide(); 
  1966. // hide any previous notice 
  1967. $('form-notice').hide(); 
  1968. $('form-export-links').hide(); 
  1969.  
  1970. // make sure a list has been selected or that we have a list selection widget inserted 
  1971. if ($F('lists-selection').length === 0 && $$('#wysija_form_body div[wysija_field="list"]').length === 0) { 
  1972. $('form-error').update(wysijatrans.list_cannot_be_empty).show(); 
  1973. } else { 
  1974. // hide export options while saving 
  1975. WysijaForm.hideExport(); 
  1976.  
  1977. formEditorSave(function(response) { 
  1978. // regenerate export methods and show 
  1979. $('form-export').innerHTML = Base64.decode(response.responseJSON.result.exports); 
  1980.  
  1981. // display save message 
  1982. $('form-notice').update(Base64.decode(response.responseJSON.result.save_message)); 
  1983. $('form-export-links').show(); 
  1984. $('form-notice').show(); 
  1985.  
  1986. WysijaForm.showExport(); 
  1987. }); 
  1988. return false; 
  1989. }); 
  1990.  
  1991. $(document).observe('dom:loaded', function() { 
  1992. // setup widget events 
  1993. setupToolbar(); 
  1994.  
  1995. // Setups the jQuery Select2 
  1996. jQuery('#lists-selection').select2({ 
  1997. 'width': 640 
  1998. }); 
  1999.  
  2000. // in place editor for form name 
  2001. new Ajax.InPlaceEditor('form-name', wysijaAJAX.ajaxurl, { 
  2002. okControl: false,  
  2003. cancelControl: false,  
  2004. clickToEditText: '',  
  2005. submitOnBlur: true,  
  2006. highlightColor: '#f9f9f9',  
  2007. externalControl: 'edit-form-name',  
  2008. callback: function(form, value) { 
  2009. wysijaAJAX.task = 'form_name_save'; 
  2010. wysijaAJAX._wpnonce = wysijanonces.config.form_name_save; 
  2011.  
  2012. return Object.toQueryString(wysijaAJAX) + '&id=' + wysijaAJAX.form_id + '&name=' + encodeURIComponent(WysijaForm.stripHtmlValue(value)); 
  2013. },  
  2014. onComplete: function(response, element) { 
  2015. if(response.responseJSON.result.name.length === 0) { 
  2016. $(element).innerHTML = $('form-name-default').innerHTML; 
  2017. } else { 
  2018. var sanitized_name = WysijaForm.stripHtmlValue(response.responseJSON.result.name); 
  2019. $(element).innerHTML = sanitized_name; 
  2020. $('form-name-default').innerHTML = sanitized_name; 
  2021.  
  2022. // remove observe on input field 
  2023. $('form-name-inplaceeditor').down('.editor_field').stopObserving('keypress'); 
  2024. },  
  2025. onEnterEditMode: function(form, value) { 
  2026. setTimeout(function() { 
  2027. $('form-name-inplaceeditor').down('.editor_field').observe('keypress', function(e) { 
  2028. // prevent form from submitting on enter key press 
  2029. if (e.keyCode == 13) { 
  2030. e.preventDefault(); 
  2031. }); 
  2032. }, 1); 
  2033. }); 
  2034. }); 
  2035. </script> 
  2036. <?php 
  2037.  
  2038. // Wysija Form Editor: Widget Settings 
  2039. function popup_form_widget_settings($data = array( )) { 
  2040. $type = (isset($data['type']) && strlen(trim($data['type'])) > 0) ? $data['type'] : 'new'; 
  2041. ?> 
  2042. <div class="popup_content inline_form form_widget_settings widget_<?php echo $type; ?>"> 
  2043. <?php 
  2044. // it means it's a new field if we have a field_id parameter with a 0 value 
  2045. $is_editing_field = (bool)(isset($data['field_id'])); 
  2046.  
  2047. if (isset($data['field_id'])) { 
  2048. $valid_types = array( 
  2049. 'input' => __('Text Input', WYSIJA),  
  2050. 'textarea' => __('Text Area', WYSIJA),  
  2051. 'radio' => __('Radio buttons', WYSIJA),  
  2052. 'checkbox' => __('Checkbox', WYSIJA),  
  2053. 'select' => __('Select', WYSIJA),  
  2054. 'date' => __('Date', WYSIJA) 
  2055. //'country' => __('Country', WYSIJA) 
  2056. ); 
  2057. ?> 
  2058. <form id="field-settings-form" method="get" action=""> 
  2059. <input type="hidden" name="action" value="<?php echo esc_attr($_REQUEST['action']); ?>" /> 
  2060. <input type="hidden" name="page" value="<?php echo esc_attr($_REQUEST['page']); ?>" /> 
  2061. <input type="hidden" name="field_id" value="<?php echo (int)$data['field_id']; ?>" /> 
  2062.  
  2063. <p class="clearfix"> 
  2064. <label for="field-type-select"><?php _e('Select a field type:', WYSIJA) ?></label> 
  2065. <select id="field-type-select" name="type"> 
  2066. <option value=""></option> 
  2067. <?php 
  2068. foreach ($valid_types as $type => $label) { 
  2069. $is_selected = ($data['type'] === $type) ? ' selected="selected"' : ''; 
  2070.  
  2071. echo '<option value="'.$type.'"'.$is_selected.'>'.$label.'</option>'; 
  2072. ?> 
  2073. </select> 
  2074. </p> 
  2075. <hr /> 
  2076. </form> 
  2077.  
  2078. <?php 
  2079.  
  2080. if (method_exists($this, 'form_widget_'.$data['type']) === false) { 
  2081. // display warning because the widget has no form built in 
  2082. // print 'missing method "' . 'form_widget_' . $data['type'] . '"'; 
  2083. else { 
  2084. // get widget form 
  2085. $data['is_editing_field'] = $is_editing_field; 
  2086. $widget_form = $this->{'form_widget_'.$data['type']}($data); 
  2087. // check whether the field is a custom field 
  2088. $form_engine = WYSIJA::get('form_engine', 'helper'); 
  2089. $is_custom_field = $form_engine->is_custom_field($data); 
  2090. ?> 
  2091.  
  2092. <!-- this is to display error messages --> 
  2093. <p id="widget-settings-error" style="display:none;"></p> 
  2094.  
  2095. <!-- common form for every wysija form widget --> 
  2096. <form enctype="multipart/form-data" method="post" action="" class="" id="widget-settings-form"> 
  2097. <input type="hidden" name="type" value="<?php echo $data['type']; ?>" /> 
  2098. <input type="hidden" name="field" value="<?php echo $data['field']; ?>" /> 
  2099. <?php 
  2100. if ($is_editing_field === true) { 
  2101. ?> 
  2102. <p class="clearfix"> 
  2103. <label for="name"><?php _e("Field's name:", WYSIJA); ?></label> 
  2104. <input type="text" id="name" name="name" value="<?php echo stripslashes(esc_attr($data['name'])); ?>" /> 
  2105. </p> 
  2106. <?php 
  2107. else { 
  2108. ?> 
  2109. <input type="hidden" name="name" value="<?php echo esc_attr($data['name']); ?>" /> 
  2110. <?php 
  2111. ?> 
  2112. <?php echo $widget_form; ?> 
  2113.  
  2114. <p class="submit_button"> 
  2115. <input id="widget-settings-submit" type="submit" name="submit" value="<?php echo esc_attr(__('Done', WYSIJA)) ?>" class="button-primary" /> 
  2116. <?php 
  2117. if ($is_editing_field === false && $is_custom_field === true) { 
  2118. $field_id = (int)substr($data['field'], 3); 
  2119. ?> 
  2120. <a id="widget-field-settings" wysija_field="<?php echo $field_id; ?>" href="javascript:;"><?php echo __('Edit field', WYSIJA); ?></a> 
  2121. <?php 
  2122. ?> 
  2123. </p> 
  2124. </form> 
  2125. </div> 
  2126. <?php 
  2127.  
  2128. function form_widget_html($data = array( )) { 
  2129. $output = ''; 
  2130.  
  2131. // get widget params from data, this will contain all user editable parameters 
  2132. $params = $data['params']; 
  2133.  
  2134. // text 
  2135. $text = isset($params['text']) ? $params['text'] : ''; 
  2136. $output .= '<textarea name="text">'.$text.'</textarea>'; 
  2137.  
  2138. // nl2br? 
  2139. $is_checked = (isset($params['nl2br']) && (bool)$params['nl2br'] === true) ? 'checked="checked"' : ''; 
  2140. $output .= '<label for="field-nl2br"><input id="field-nl2br" type="checkbox" class="checkbox" name="nl2br" '.$is_checked.' value="1" />'.__('Automatically add paragraphs', WYSIJA).'</label>'; 
  2141.  
  2142. return $output; 
  2143.  
  2144. function form_widget_submit($data = array( )) { 
  2145. $output = ''; 
  2146.  
  2147. // label 
  2148. $output .= $this->_widget_label($data); 
  2149.  
  2150. return $output; 
  2151.  
  2152. function form_widget_input($data = array( )) { 
  2153. $output = ''; 
  2154.  
  2155. // label 
  2156. $output .= $this->_widget_label($data); 
  2157.  
  2158. // inline label 
  2159. $output .= $this->_widget_label_inline($data); 
  2160.  
  2161. // extra validation 
  2162. $output .= $this->_widget_validation($data); 
  2163.  
  2164. return $output; 
  2165.  
  2166. function form_widget_textarea($data = array( )) { 
  2167. $output = ''; 
  2168.  
  2169. // label 
  2170. $output .= $this->_widget_label($data); 
  2171.  
  2172. // inline label 
  2173. $output .= $this->_widget_label_inline($data); 
  2174.  
  2175. // extra validation 
  2176. $output .= $this->_widget_validation($data); 
  2177.  
  2178. if ($data['is_editing_field'] === false) { 
  2179. // number of lines (defaults to 1) 
  2180. $number_of_lines = (isset($data['params']['lines']) && (int)$data['params']['lines'] > 0) ? (int)$data['params']['lines'] : 1; 
  2181.  
  2182. $output .= '<p class="clearfix"><label for="number-lines-select">'.__('Number of lines:', WYSIJA).'</label>'; 
  2183. $output .= ' <select id="number-lines-select" name="lines">'; 
  2184. for ($i = 1; $i < 6; $i++) { 
  2185. $is_selected = ($number_of_lines === $i) ? ' selected="selected"' : ''; 
  2186. $output .= ' <option value="'.$i.'" '.$is_selected.'>'.sprintf(_n('1 line', '%d lines', $i, WYSIJA), $i).'</option>'; 
  2187. $output .= ' </select>'; 
  2188. $output .= '</p>'; 
  2189.  
  2190. return $output; 
  2191.  
  2192. function form_widget_list($data = array( )) { 
  2193. $output = ''; 
  2194.  
  2195. // get widget params from data, this will contain all user editable parameters 
  2196. $params = $data['params']; 
  2197.  
  2198. // get widget extra data, this will contain all the available lists 
  2199. $extra = $data['extra']; 
  2200.  
  2201. // label 
  2202. $output .= $this->_widget_label($data); 
  2203.  
  2204. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  2205. // get list names 
  2206. $list_names = $helper_form_engine->get_formatted_lists(); 
  2207.  
  2208. // display select lists 
  2209. $output .= '<ul id="lists-selection" class="selection sortable">'; 
  2210.  
  2211. if (!empty($params['values'])) { 
  2212. for ($i = 0, $count = count($params['values']); $i < $count; $i++) { 
  2213. $list = $params['values'][$i]; 
  2214. $is_checked = ((int)$list['is_checked'] > 0) ? 'checked="checked"' : ''; 
  2215. if (isset($list_names[$list['list_id']])) { 
  2216. $output .= '<li class="clearfix">'; 
  2217. $output .= ' <input class="is_selected" id="list-'.$list['list_id'].'" type="checkbox" data-list="'.$list['list_id'].'" value="1" '.$is_checked.' />'; 
  2218. $output .= ' <label for="list-'.$list['list_id'].'">'.$list_names[$list['list_id']].'</label>'; 
  2219. $output .= ' <a class="icon remove" href="javascript:;"><span></span></a>'; 
  2220. $output .= ' <a class="icon handle" href="javascript:;"><span></span></a>'; 
  2221. $output .= '</li>'; 
  2222.  
  2223. $output .= '</ul>'; 
  2224.  
  2225. // available lists container 
  2226. $output .= '<div id="lists-add-container" class="clearfix">'; 
  2227. $output .= '<h3>'.__('Select the list you want to add:', WYSIJA).'</h3>'; 
  2228.  
  2229. // available lists select 
  2230. $output .= '<select id="lists-available" class="mp-select-sort">'; 
  2231. for ($j = 0, $count = count($extra['lists']); $j < $count; $j++) { 
  2232. // set current list 
  2233. $list = $extra['lists'][$j]; 
  2234. // generate select option 
  2235. $output .= '<option value="'.$list['list_id'].'">'.$list['name'].'</option>'; 
  2236. $output .= '</select>'; 
  2237.  
  2238. // add button to add currently selected list to selected lists 
  2239. $output .= '<a href="javascript:;" class="icon add"><span></span></a>'; 
  2240. $output .= '</div>'; 
  2241.  
  2242. // generate prototypeJS template for list selection so we can dynamically add/remove elements 
  2243. $output .= '<div id="selection-template">'; 
  2244. $output .= '<li class="clearfix">'; 
  2245. $output .= '<input class="is_selected" id="list-#{list_id}" type="checkbox" data-list="#{list_id}" value="1" /><label for="list-#{list_id}">#{name}</label>'; 
  2246. $output .= '<a class="icon remove" href="javascript:;"><span></span></a>'; 
  2247. $output .= '<a class="icon handle" href="javascript:;"><span></span></a>'; 
  2248. $output .= '</li>'; 
  2249. $output .= '</div>'; 
  2250.  
  2251. return $output; 
  2252.  
  2253. function form_widget_radio($data = array( )) { 
  2254. return $this->form_widget_multiple($data, 'radio'); 
  2255.  
  2256. function form_widget_checkbox($data = array( )) { 
  2257. return $this->form_widget_multiple($data, 'checkbox'); 
  2258.  
  2259. function form_widget_select($data = array( )) { 
  2260. return $this->form_widget_multiple($data, 'select'); 
  2261.  
  2262. // Country selection widget 
  2263. function form_widget_country($data = array( )) { 
  2264. $output = ''; 
  2265.  
  2266. // TODO: JSON data coming from API 
  2267. //$country_data = json_decode(file_get_contents('http://localhost/countries.json'), true); 
  2268. $country_data = array( ); 
  2269.  
  2270. // format countries for select widget 
  2271. $countries = array( ); 
  2272. foreach ($country_data as $country) { 
  2273. $countries[] = array( 
  2274. 'value' => $country['name'],  
  2275. 'is_checked' => false 
  2276. ); 
  2277. $data['params']['values'] = $countries; 
  2278.  
  2279. // render select widget form 
  2280. $output .= $this->form_widget_multiple($data, 'select'); 
  2281.  
  2282. return $output; 
  2283.  
  2284. public function form_widget_date($data = array( )) { 
  2285. $output = ''; 
  2286.  
  2287. // label 
  2288. $output .= $this->_widget_label($data); 
  2289.  
  2290. // date types 
  2291. $date_types = array( 
  2292. 'year_month_day' => __('Year, month, day', WYSIJA),  
  2293. 'year_month' => __('Year, month', WYSIJA),  
  2294. 'month' => __('Month (January, February, ...)', WYSIJA),  
  2295. 'year' => __('Year', WYSIJA) 
  2296. ); 
  2297.  
  2298. if ($data['is_editing_field'] === false) { 
  2299. $date_type_value = (isset($data['params']['date_type']) && strlen(trim($data['params']['date_type'])) > 0) ? trim($data['params']['date_type']) : $date_types[0]; 
  2300. $output .= '<input type="hidden" name="date_type" value="'.$date_type_value.'">'; 
  2301. else { 
  2302.  
  2303. // date type selection 
  2304. $output .= '<p class="clearfix"><label for="date_type">'.__('Type of date:', WYSIJA).'</label>'; 
  2305. $output .= ' <select id="date_type" name="date_type">'; 
  2306. foreach ($date_types as $key => $label) { 
  2307. $is_selected = (isset($data['params']['date_type']) && $data['params']['date_type'] === $key) ? ' selected="selected"' : ''; 
  2308. $output .= ' <option value="'.$key.'" '.$is_selected.'>'.$label.'</option>'; 
  2309. $output .= ' </select>'; 
  2310. $output .= '</p>'; 
  2311.  
  2312. // date set default as today 
  2313. $output .= $this->_widget_date_default_today($data); 
  2314.  
  2315. // date display order 
  2316. $output .= $this->_widget_date_order($data); 
  2317.  
  2318. return $output; 
  2319.  
  2320. // generic widget for handling multiple choices (radio, checkbox, select) 
  2321. private function form_widget_multiple($data = array( ), $type = false) { 
  2322. $output = ''; 
  2323.  
  2324. if ($type === false) 
  2325. return $output; 
  2326.  
  2327. // get widget params from data, this will contain all user editable parameters 
  2328. $params = $data['params']; 
  2329.  
  2330. // label 
  2331. $output .= $this->_widget_label($data); 
  2332.  
  2333. // label inline 
  2334. $output .= $this->_widget_label_inline($data); 
  2335.  
  2336. // flag to know whether to allow multiple values or not 
  2337. $is_multiple = true; 
  2338.  
  2339. // checkbox only allow one value (for now...) 
  2340. if ($type === 'checkbox') { 
  2341. $is_multiple = false; 
  2342.  
  2343. // make sure we have one value 
  2344. if (empty($params['values'])) { 
  2345. $params['values'][] = array( 'value' => '', 'is_checked' => false ); 
  2346. else { 
  2347. // restrict to 1 value 
  2348. if (count($params['values']) > 1) { 
  2349. $value = $params['values'][0]; 
  2350. $params['values'] = array( $value ); 
  2351.  
  2352. // set CSS classes for list 
  2353. $list_classes = array( 'selection' ); 
  2354. if ($is_multiple === true) { 
  2355. $list_classes[] = 'sortable'; 
  2356.  
  2357. // hide values when no editing CF global settings 
  2358. if ($data['is_editing_field'] === false) { 
  2359. $output .= '<div class="hidden">'; 
  2360.  
  2361. // display values 
  2362. $output .= '<ul id="items-selection" class="'.join(' ', $list_classes).'">'; 
  2363.  
  2364. if (!empty($params['values'])) { 
  2365. for ($i = 0, $count = count($params['values']); $i < $count; $i++) { 
  2366. $item = $params['values'][$i]; 
  2367. $is_checked = ((int)$item['is_checked'] > 0) ? 'checked="checked"' : ''; 
  2368.  
  2369. $output .= '<li class="clearfix">'; 
  2370. if ($type === 'checkbox') { 
  2371. $output .= '<input type="checkbox" class="is_checked" value="1" '.$is_checked.' />'; 
  2372. else { 
  2373. $output .= '<input type="radio" name="is_checked" class="is_checked" value="1" '.$is_checked.' />'; 
  2374.  
  2375. $output .= ' <input type="text" class="value" value="'.$item['value'].'" tabindex="'.($i + 1).'" />'; 
  2376.  
  2377. if ($is_multiple === true) { 
  2378. $output .= ' <a class="icon remove" href="javascript:;"><span></span></a>'; 
  2379. $output .= ' <a class="icon handle" href="javascript:;"><span></span></a>'; 
  2380. $output .= '</li>'; 
  2381.  
  2382. $output .= '</ul>'; 
  2383.  
  2384. if ($is_multiple === true) { 
  2385. // add a new option 
  2386. $output .= '<a id="items-selection-add" href="javascript:;" class="icon add"><span></span>'.__('Add item', WYSIJA).'</a>'; 
  2387.  
  2388. // generate prototypeJS template for list selection so we can dynamically add/remove elements 
  2389. $output .= '<div id="selection-template">'; 
  2390. $output .= '<li class="clearfix">'; 
  2391. if ($type === 'checkbox') { 
  2392. $output .= '<input type="checkbox" class="is_checked" value="1" />'; 
  2393. else { 
  2394. $output .= '<input type="radio" name="is_checked" class="is_checked" value="1" />'; 
  2395. $output .= ' <input type="text" class="value" value="" tabindex="#{item_index}" />'; 
  2396. $output .= ' <a class="icon remove" href="javascript:;"><span></span></a>'; 
  2397. $output .= ' <a class="icon handle" href="javascript:;"><span></span></a>'; 
  2398. $output .= '</li>'; 
  2399. $output .= '</div>'; 
  2400.  
  2401. // hide values when no editing CF global settings 
  2402. if ($data['is_editing_field'] === false) { 
  2403. $output .= '</div>'; 
  2404.  
  2405. $output .= $this->_widget_validation($data); 
  2406.  
  2407. return $output; 
  2408.  
  2409. // widget feature: ability to specify a label 
  2410. private function _widget_label($data = array( )) { 
  2411. $output = ''; 
  2412.  
  2413. if ($data['is_editing_field'] === false) { 
  2414. // label 
  2415. $label = (isset($data['params']['label'])) ? $data['params']['label'] : ''; 
  2416. $output .= '<p class="clearfix"><label for="label">'.__('Label:', WYSIJA).'</label>'; 
  2417. $output .= '<input id="label" type="text" name="label" value="'.$label.'" /></p>'; 
  2418.  
  2419. return $output; 
  2420.  
  2421. // widget feature: ability to choose whether the label should be inline (a placeholder) 
  2422. private function _widget_label_inline($data = array( )) { 
  2423. $output = ''; 
  2424.  
  2425. // only show extra validation for these types 
  2426. if (in_array($data['type'], array( 'input', 'textarea', 'select' )) && $data['is_editing_field'] === false) { 
  2427. // inline 
  2428. $is_label_within = (bool)(isset($data['params']['label_within']) && (int)$data['params']['label_within'] > 0); 
  2429. $output .= '<p class="clearfix">'; 
  2430. $output .= '<label>'.__('Display label within input:', WYSIJA).'</label>'; 
  2431. $output .= ' <span class="group">'; 
  2432. $output .= ' <label class="radio"><input type="radio" name="label_within" value="1" '.(($is_label_within === true) ? 'checked="checked"' : '').' />'.__('Yes', WYSIJA).'</label>'; 
  2433. $output .= ' <label class="radio"><input type="radio" name="label_within" value="0" '.(($is_label_within === false) ? 'checked="checked"' : '').' />'.__('No', WYSIJA).'</label>'; 
  2434. $output .= ' </span>'; 
  2435. $output .= '</p>'; 
  2436.  
  2437. return $output; 
  2438.  
  2439. private function _widget_date_order($data = array( )) { 
  2440. // date order 
  2441. $date_orders = array( 
  2442. 'year_month_day' => array( 'mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy/mm/dd' ),  
  2443. 'year_month' => array( 'mm/yyyy', 'yyyy/mm' ),  
  2444. 'year' => array( 'yyyy' ),  
  2445. 'month' => array( 'mm' ) 
  2446. ); 
  2447.  
  2448. $output = ''; 
  2449.  
  2450. // get date orders from date type 
  2451. $orders = array( ); 
  2452. if (isset($date_orders[$data['params']['date_type']])) { 
  2453. $orders = $date_orders[$data['params']['date_type']]; 
  2454. else { 
  2455. $orders = $date_orders['year_month_day']; 
  2456.  
  2457. if ($data['is_editing_field'] === false) { 
  2458. if (count($orders) === 1) { 
  2459. // show as hidden input 
  2460. $output .= '<input type="hidden" name="date_order" value="'.$orders[0].'" />'; 
  2461. else { 
  2462. $output .= '<p class="clearfix">'; 
  2463. $output .= '<label for="date_order">'.__('Order:', WYSIJA).'</label>'; 
  2464. $output .= '<select id="date_order" class="date_order" name="date_order">'; 
  2465.  
  2466. foreach ($orders as $date_order) { 
  2467. $is_selected = (isset($data['params']['date_order']) && $data['params']['date_order'] === $date_order) ? ' selected="selected"' : ''; 
  2468. $output .= '<option value="'.$date_order.'" '.$is_selected.'>'.$date_order.'</option>'; 
  2469. $output .= '</select>'; 
  2470. $output .= '</p>'; 
  2471. else { 
  2472. if (isset($data['params']['date_order'])) { 
  2473. $output .= '<input type="hidden" name="date_order" value="'.$data['params']['date_order'].'" />'; 
  2474. else { 
  2475. $output .= '<input type="hidden" name="date_order" value="'.$orders[0].'" />'; 
  2476.  
  2477. return $output; 
  2478.  
  2479. private function _widget_date_default_today($data = array( )) { 
  2480. $output = ''; 
  2481.  
  2482. $display_default_today = true; 
  2483. $is_default_today = (bool)(isset($data['params']['is_default_today']) && (int)$data['params']['is_default_today'] > 0); 
  2484.  
  2485.  
  2486. // in the case of a "year", we don't offer the possibility to select today's date as the default 
  2487. if ($data['params']['date_type'] === 'year') { 
  2488. $display_default_today = false; 
  2489. $is_default_today = false; 
  2490.  
  2491. if ($data['is_editing_field'] === false && $display_default_today === true) { 
  2492. $output .= '<p class="clearfix">'; 
  2493. $output .= '<label>'.__("Preselect today's date:", WYSIJA).'</label>'; 
  2494. $output .= ' <span class="group">'; 
  2495. $output .= ' <label class="radio"><input type="radio" name="is_default_today" value="1" '.(($is_default_today === true) ? 'checked="checked"' : '').' />'.__('Yes', WYSIJA).'</label>'; 
  2496. $output .= ' <label class="radio"><input type="radio" name="is_default_today" value="0" '.(($is_default_today === false) ? 'checked="checked"' : '').' />'.__('No', WYSIJA).'</label>'; 
  2497. $output .= ' </span>'; 
  2498. $output .= '</p>'; 
  2499. else { 
  2500. $output .= '<input type="hidden" name="is_default_today" value="'.(int)$is_default_today.'" />'; 
  2501.  
  2502. return $output; 
  2503.  
  2504. // widget feature: data validation - is_required checkbox 
  2505. private function _widget_validation_is_required($data = array( )) { 
  2506. // is the field mandatory? 
  2507. $is_required = (bool)(isset($data['params']['required']) && (int)$data['params']['required'] > 0); 
  2508. $output = '<p class="clearfix">'; 
  2509. $output .= ' <label>'.__('Is this field mandatory?', WYSIJA).'</label>'; 
  2510. $output .= ' <span class="group">'; 
  2511. $output .= ' <label class="radio"><input type="radio" name="required" value="1" '.(($is_required === true) ? 'checked="checked"' : '').' />'.__('Yes', WYSIJA).'</label>'; 
  2512. $output .= ' <label class="radio"><input type="radio" name="required" value="0" '.(($is_required === false) ? 'checked="checked"' : '').' />'.__('No', WYSIJA).'</label>'; 
  2513. $output .= ' </span>'; 
  2514. $output .= '</p>'; 
  2515. return $output; 
  2516.  
  2517. // widget feature: data validation 
  2518. private function _widget_validation($data = array( )) { 
  2519.  
  2520. $output = ''; 
  2521.  
  2522. // display hidden parameters in case we're editing display settings 
  2523. if ($data['is_editing_field'] === false) { 
  2524.  
  2525. // special case for firstname & lastname 
  2526. // we need to display the "is_required" in the form since they're not actual custom fields, they don't have "field settings" 
  2527. if (in_array($data['field'], array( 'firstname', 'lastname' ))) { 
  2528. $output .= $this->_widget_validation_is_required($data); 
  2529. else { 
  2530. // display hidden input since these settings are set on the custom field itself 
  2531. if (isset($data['params']['required'])) { 
  2532. $required_value = (isset($data['params']['required']) && (int)$data['params']['required'] > 0) ? 1 : 0; 
  2533. $output .= '<input type="hidden" name="required" value="'.$required_value.'" />'; 
  2534.  
  2535. if (isset($data['params']['validate'])) { 
  2536. $validate_value = (isset($data['params']['validate']) && strlen(trim($data['params']['validate'])) > 0) ? trim($data['params']['validate']) : ''; 
  2537. $output .= '<input type="hidden" name="validate" value="'.$validate_value.'" />'; 
  2538. else { 
  2539. // validation 
  2540. if ($data['field'] === 'email') { 
  2541. // the email field is always mandatory, no questions asked 
  2542. $output .= '<input type="hidden" name="required" value="1" />'; 
  2543. else { 
  2544. $output .= $this->_widget_validation_is_required($data); 
  2545.  
  2546. // extra validation rules 
  2547. $rules = array( 
  2548. 'onlyNumberSp' => __('Numbers only', WYSIJA),  
  2549. 'onlyLetterSp' => __('Letters only', WYSIJA),  
  2550. 'onlyLetterNumber' => __('Alphanumerical ', WYSIJA),  
  2551. 'phone' => __('Phone number, (+, -, #, (, ) and spaces allowed)', WYSIJA) 
  2552. ); 
  2553.  
  2554. // only show extra validation for these types 
  2555. if (in_array($data['type'], array( 'input', 'textarea' ))) { 
  2556. $output .= '<p class="clearfix">'; 
  2557. $output .= ' <label>'.__('Validate for:', WYSIJA).'</label>'; 
  2558. $output .= ' <select name="validate">'; 
  2559. $output .= ' <option value="">'.__('Nothing', WYSIJA).'</option>'; 
  2560. foreach ($rules as $rule => $label) { 
  2561. $is_selected = (isset($data['params']['validate']) && ($rule === $data['params']['validate'])) ? ' selected="selected"' : ''; 
  2562. $output .= ' <option value="'.$rule.'"'.$is_selected.'>'.$label.'</option>'; 
  2563. $output .= ' </select>'; 
  2564. $output .= '</p>'; 
  2565.  
  2566. return $output; 
  2567.