WYSIJA_control_back_config

The MailPoet Newsletters WYSIJA control back config class.

Defined (2)

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

/controllers/ajax/config.php  
  1. class WYSIJA_control_back_config extends WYSIJA_control{ 
  2.  
  3. function __construct() { 
  4. if(!WYSIJA::current_user_can('wysija_config')) die("Action is forbidden."); 
  5. parent::__construct(); 
  6.  
  7. function _displayErrors() { 
  8. if(version_compare(phpversion(), '5.4')>= 0) { 
  9. error_reporting(E_ALL ^ E_STRICT); 
  10.  
  11. }else{ 
  12. error_reporting(E_ALL); 
  13. @ini_set("display_errors", 1); 
  14.  
  15. function _hideErrors() { 
  16. error_reporting(0); 
  17. @ini_set('display_errors', '0'); 
  18.  
  19. function send_test_mail() { 
  20. $this->requireSecurity(); 
  21. $this->_displayErrors(); 
  22. /**switch the send method*/ 
  23. $configVal=$this->_convertPostedInarray(); 
  24.  
  25. /**send a test mail*/ 
  26. $hEmail=WYSIJA::get('email', 'helper'); 
  27. $res['result']=$hEmail->send_test_mail($configVal); 
  28.  
  29. if($res['result']) { 
  30. $modelConf=WYSIJA::get('config', 'model'); 
  31. $modelConf->save(array('sending_emails_ok'=>$res['result'])); 
  32. $this->_hideErrors(); 
  33. return $res; 
  34.  
  35. function send_test_mail_ms() { 
  36. $this->requireSecurity(); 
  37. $this->_displayErrors(); 
  38. /**switch the send method*/ 
  39. $configVal=$this->_convertPostedInarray(); 
  40.  
  41. /**send a test mail*/ 
  42. $hEmail=WYSIJA::get('email', 'helper'); 
  43. $res['result']=$hEmail->send_test_mail($configVal, true); 
  44. if($res['result']) { 
  45. $modelConf=WYSIJA::get('config', 'model'); 
  46. $modelConf->save(array('ms_sending_emails_ok'=>$res['result'])); 
  47. //$this->_hideErrors(); 
  48. return $res; 
  49.  
  50. function bounce_connect() { 
  51.  
  52. $configVal=$this->_convertPostedInarray(); 
  53. /**try to connect to thebounce server*/ 
  54. $bounceClass=WYSIJA::get('bounce', 'helper'); 
  55. $bounceClass->report = true; 
  56. $res['result']=false; 
  57. if($bounceClass->init($configVal)) { 
  58. if($bounceClass->connect()) { 
  59. $nbMessages = $bounceClass->getNBMessages(); 
  60. $this->notice(sprintf(__('Successfully connected to %1$s', WYSIJA), $bounceClass->config->getValue('bounce_login'))); 
  61. $this->notice(sprintf(__('There are %1$s messages in your mailbox', WYSIJA), $nbMessages)); 
  62. $bounceClass->close(); 
  63. if((int)$nbMessages >0) $res['result']=true; 
  64. else $this->notice(sprintf(__('There are no bounced messages to process right now!', WYSIJA), $nbMessages)); 
  65. if(!empty($nbMessages)) { 
  66. //$app->enqueueMessage('<a class="modal" style="text-decoration:blink" rel="{handler: \'iframe\', size: {x: 640, y: 480}}" href="'.acymailing_completeLink("bounces&task=process", true ).'">'.__("CLICK HERE to handle the messages", WYSIJA).'</a>'); 
  67. }else{ 
  68. $errors = $bounceClass->getErrors(); 
  69. if(!empty($errors)) { 
  70. $this->error($errors, true); 
  71. $errorString = implode(' ', $errors); 
  72. $port = $bounceClass->config->getValue('bounce_port', ''); 
  73. if(preg_match('#certificate#i', $errorString) && !$bounceClass->config->getValue('bounce_selfsigned', false)) { 
  74. $this->notice(__('You may need to turn ON the option <i>Self-signed certificates</i>', WYSIJA)); 
  75. }elseif(!empty($port) AND !in_array($port, array('993', '143', '110'))) { 
  76. $this->notice(__('Are you sure you selected the right port? You can leave it empty if you do not know what to specify', WYSIJA)); 
  77.  
  78.  
  79. return $res; 
  80.  
  81. /** 
  82. * processing the bounce manually through the config 
  83. * @return type 
  84. */ 
  85. function bounce_process() { 
  86. $this->requireSecurity(); 
  87. // bounce handling 
  88. $helper_bounce = WYSIJA::get('bounce', 'helper'); 
  89.  
  90. // in a multisite case we process first the bounce recording into the bounce table 
  91. if(is_multisite()) { 
  92. $helper_bounce->record_bounce_ms(); 
  93.  
  94. // then we take actions from what has been returned by the bounce 
  95. return $helper_bounce->process_bounce_ms(); 
  96. }else{ 
  97. return $helper_bounce->process_bounce(); 
  98.  
  99. function linkignore() { 
  100. $this->requireSecurity(); 
  101. $this->_displayErrors(); 
  102.  
  103. $modelConf=WYSIJA::get('config', 'model'); 
  104.  
  105. $ignore_msgs=$modelConf->getValue('ignore_msgs'); 
  106. if(!$ignore_msgs) $ignore_msgs=array(); 
  107.  
  108. $ignore_msgs[$_REQUEST['ignorewhat']]=1; 
  109. $modelConf->save(array('ignore_msgs'=>$ignore_msgs)); 
  110.  
  111. $res['result']=true; 
  112. $this->_hideErrors(); 
  113. return $res; 
  114.  
  115. // Ajax called function to enable analytics sharing from welcome page. 
  116. function share_analytics() { 
  117. $this->requireSecurity(); 
  118. $this->_displayErrors(); 
  119.  
  120. $model_config = WYSIJA::get('config', 'model'); 
  121. $model_config->save(array('analytics' => 1)); 
  122.  
  123. $res['result'] = true; 
  124. $this->_hideErrors(); 
  125. return $res; 
  126.  
  127. function validate() { 
  128. $this->requireSecurity(); 
  129. $helper_licence = WYSIJA::get('licence', 'helper'); 
  130. $result = $helper_licence->check(); 
  131.  
  132. if(!isset($result['result'])) { 
  133. $result['result']=false; 
  134.  
  135. return $result; 
  136.  
  137. function _convertPostedInarray() { 
  138. $_POST = stripslashes_deep($_POST); 
  139. $data_temp = $_POST['data']; 
  140. $_POST['data']=array(); 
  141. foreach($data_temp as $val) $_POST['data'][$val['name']]=$val['value']; 
  142. $data_temp = null; 
  143. foreach($_POST['data'] as $k =>$v) { 
  144. $new_key = str_replace(array('wysija[config][', ']'), '', $k); 
  145. $config_val[$new_key] = $v; 
  146. return $config_val; 
  147.  
  148. // WYSIJA Form Editor 
  149. function wysija_form_generate_template() { 
  150. $data = $this->_wysija_form_get_data(); 
  151.  
  152. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  153. return base64_encode($helper_form_engine->render_editor_template($data)); 
  154.  
  155. function wysija_form_manage_field() { 
  156. $this->requireSecurity(); 
  157. $response = array('result' => true, 'error' => null); 
  158.  
  159. // get data 
  160. $data = $this->_wysija_form_get_data(); 
  161. $form_id = (int)$_REQUEST['form_id']; 
  162.  
  163. // check for required fields 
  164. if(!isset($data['type']) || isset($data['type']) && strlen(trim($data['type'])) === 0) { 
  165. $response['error'] = __('You need to select a type for this field', WYSIJA); 
  166. $response['result'] = false; 
  167. if(!isset($data['name']) || isset($data['name']) && strlen(trim($data['name'])) === 0) { 
  168. $response['error'] = __('You need to specify a name for this field', WYSIJA); 
  169. $response['result'] = false; 
  170.  
  171. // only proceed if there is no error 
  172. if($response['error'] === null) { 
  173. $is_required = (isset($data['params']['required']) ? WJ_Utils::to_bool($data['params']['required']) : false); 
  174.  
  175. if(isset($data['field_id']) && (int)$data['field_id'] > 0) { 
  176. // it's an update 
  177. $custom_field = WJ_Field::get($data['field_id']); 
  178.  
  179. if($custom_field !== NULL) { 
  180. $data['params'] = array_merge($custom_field->settings, $data['params']); 
  181. // update fields 
  182. $custom_field->name = $data['name']; 
  183. $custom_field->type = $data['type']; 
  184. $custom_field->required = $is_required; 
  185. $custom_field->settings = $data['params']; 
  186. $custom_field->save(); 
  187. } else { 
  188. // throw error if field does not exist 
  189. $response['error'] = __('This field does not exist', WYSIJA); 
  190. $response['result'] = false; 
  191. } else { 
  192. // create new custom field 
  193. $custom_field = new WJ_Field(); 
  194. $custom_field->set(array( 
  195. 'name' => $data['name'],  
  196. 'type' => $data['type'],  
  197. 'required' => $is_required,  
  198. 'settings' => $data['params'] 
  199. )); 
  200. $custom_field->save(); 
  201.  
  202. if($response['error'] === null) { 
  203. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  204.  
  205. // need to update each block instance of this custom field 
  206. $block = $helper_form_engine->refresh_custom_field($form_id, array( 
  207. 'name' => $data['name'],  
  208. 'field' => $custom_field->user_column_name(),  
  209. 'type' => $data['type'],  
  210. 'required' => $is_required,  
  211. 'settings' => $data['params'] 
  212. )); 
  213.  
  214. // render editor toolbar & templates 
  215. $response['data'] = array( 
  216. 'toolbar' => base64_encode($helper_form_engine->render_editor_toolbar()),  
  217. 'templates' => base64_encode($helper_form_engine->render_editor_templates()) 
  218. ); 
  219.  
  220. if($block !== null) { 
  221. // refresh block using this custom field in the current form 
  222. $block_template = $helper_form_engine->render_editor_template($block); 
  223.  
  224. if($block_template !== null) { 
  225. $response['data']['block'] = base64_encode($block_template); 
  226.  
  227. return $response; 
  228.  
  229. // get wysija form data from post (auto decoding) 
  230. private function _wysija_form_get_data() { 
  231. if(isset($_POST['wysijaData'])) { 
  232. // decode the data string 
  233. $decoded_data = base64_decode($_POST['wysijaData']); 
  234.  
  235. // avoid using stripslashes as it's not reliable depending on the magic quotes settings 
  236. $json_data = str_replace('\"', '"', $decoded_data); 
  237. return json_decode($json_data, true); 
  238. return array(); 
  239.  
  240. // remove a custom field 
  241. function form_field_delete() { 
  242. $this->requireSecurity(); 
  243. $data = $this->_wysija_form_get_data(); 
  244.  
  245. // check for field_id parameter 
  246. if(isset($data['field_id']) && (int)$data['field_id'] > 0) { 
  247. // get custom field by id 
  248. $custom_field = WJ_Field::get($data['field_id']); 
  249.  
  250. // if the custom field exists 
  251. if($custom_field !== null) { 
  252. // we need to remove the field in any form 
  253. // get all forms 
  254. $model_forms = WYSIJA::get('forms', 'model'); 
  255. $forms = $model_forms->getRows(); 
  256.  
  257. // get custom field name 
  258. $field_name = $custom_field->user_column_name(); 
  259. if(is_array($forms) && count($forms) > 0) { 
  260. // loop through each form 
  261. foreach ($forms as $i => $form) { 
  262. $requires_update = false; 
  263.  
  264. // decode form data 
  265. $data = unserialize(base64_decode($form['data'])); 
  266.  
  267. // loop through each block 
  268. foreach($data['body'] as $j => $block) { 
  269. // in case we find a text block 
  270. if($block['field'] === $field_name) { 
  271. unset($data['body'][$j]); 
  272. // flag form to be updated 
  273. $requires_update = true; 
  274.  
  275. // if the form requires update, let's do it 
  276. if($requires_update === true) { 
  277. $model_forms->reset(); 
  278. $model_forms->update(array('data' => base64_encode(serialize($data))), array('form_id' => (int)$form['form_id'])); 
  279.  
  280. // delete custom field 
  281. $custom_field->delete(); 
  282.  
  283. function form_name_save() { 
  284. $this->requireSecurity(); 
  285. // get name from post and stripslashes it 
  286. $form_name = trim(stripslashes($_POST['name'])); 
  287. // get form_id from post 
  288. $form_id = (int)$_POST['form_id']; 
  289.  
  290. if(strlen($form_name) > 0 && $form_id > 0) { 
  291. // update the form name within the database 
  292. $model_forms = WYSIJA::get('forms', 'model'); 
  293. $model_forms->update(array('name' => $form_name), array('form_id' => $form_id)); 
  294. return array('name' => $form_name); 
  295.  
  296. function form_save() { 
  297. $this->requireSecurity(); 
  298. // get form id 
  299. $form_id = null; 
  300. if(isset($_POST['form_id']) && (int)$_POST['form_id'] > 0) { 
  301. $form_id = (int)$_POST['form_id']; 
  302.  
  303. // decode json data and convert to array 
  304. $raw_data = null; 
  305. if(isset($_POST['wysijaData'])) { 
  306. // decode the data string 
  307. $decoded_data = base64_decode($_POST['wysijaData']); 
  308.  
  309. // avoid using stripslashes as it's not reliable depending on the magic quotes settings 
  310. $json_data = str_replace('\"', '"', $decoded_data); 
  311. // decode JSON data 
  312. $raw_data = json_decode($json_data, true); 
  313.  
  314. if($form_id === null or $raw_data === null) { 
  315. $this->error('Error saving', false); 
  316. return array('result' => false); 
  317. } else { 
  318.  
  319. // flag to see if the user can select his own lists 
  320. $has_list_selection = false; 
  321. $raw_data['settings']['lists_selected_by'] = 'admin'; 
  322.  
  323. // special case for block params, as we base64_encode the values and serialize arrays, so let's decode it before saving it 
  324. foreach($raw_data['body'] as $block_id => $block) { 
  325. if(isset($block['params']) && !empty($block['params'])) { 
  326. $params = array(); 
  327.  
  328. foreach($block['params'] as $key => $value) { 
  329. $value = base64_decode($value); 
  330. if(is_serialized($value) === true) { 
  331. $value = (array) unserialize($value); 
  332. $params[$key] = $value; 
  333.  
  334. if(!empty($params)) { 
  335. $raw_data['body'][$block_id]['params'] = $params; 
  336. // special case when the list selection widget is present 
  337. if($block['type'] === 'list') { 
  338. $has_list_selection = true; 
  339.  
  340. $lists = array(); 
  341. foreach($params['values'] as $list) { 
  342. $lists[] = (int)$list['list_id']; 
  343.  
  344. // override lists in form settings 
  345. $raw_data['settings']['lists'] = $lists; 
  346. $raw_data['settings']['lists_selected_by'] = 'user'; 
  347.  
  348. // make sure the lists parameter is an array, otherwise it's not gonna work for a single list 
  349. if($has_list_selection === false) { 
  350. if(!is_array($raw_data['settings']['lists'])) { 
  351. $raw_data['settings']['lists'] = array((int)$raw_data['settings']['lists']); 
  352.  
  353. // set form id into data so we can track who subscribed through it 
  354. $raw_data['form_id'] = $form_id; 
  355.  
  356. // set data in form engine so we can generate the render the web version 
  357. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  358. $helper_form_engine->set_data($raw_data); 
  359.  
  360. // check if the form has already been inserted in a widget and therefore display different success message 
  361. $widgets = get_option('widget_wysija'); 
  362. $is_form_added_as_widget = false; 
  363. if($widgets !== false) { 
  364. foreach($widgets as $widget) { 
  365. if(is_array($widget) && isset($widget['form']) && (int)$widget['form'] === $form_id) { 
  366. $is_form_added_as_widget = true; 
  367.  
  368. if($is_form_added_as_widget === true) { 
  369. $save_message = __('Saved! The changes are already active in your widget.', WYSIJA); 
  370. } else { 
  371. $save_message = str_replace(array( 
  372. '[link_widget]',  
  373. '[/link_widget]' 
  374. ), array( 
  375. '<a href="'.admin_url('widgets.php').'" target="_blank">',  
  376. '</a>' 
  377. ),  
  378. __('Saved! Add this form to [link_widget]a widget[/link_widget].', WYSIJA) 
  379. ); 
  380.  
  381. // update form data in DB 
  382. $model_forms = WYSIJA::get('forms', 'model'); 
  383. $model_forms->reset(); 
  384. $result = $model_forms->update(array( 
  385. // get encoded data to store it in the database 
  386. 'data' => $helper_form_engine->get_encoded('data') 
  387. ), array('form_id' => $form_id)); 
  388.  
  389. // return response depending on db save result 
  390. if(!$result) { 
  391. // throw error 
  392. $this->error(__('Your form could not be saved.', WYSIJA)); 
  393. } else { 
  394. // save successful 
  395. $this->notice(__('Your form has been saved.', WYSIJA)); 
  396.  
  397. return array('result' => $result, 'save_message' => base64_encode($save_message), 'exports' => base64_encode($helper_form_engine->render_editor_export($form_id))); 
  398.  
  399. function wysija_dismiss_update_notice() { 
  400. WYSIJA::update_option('wysija_dismiss_update_notice', true); 
  401.  
  402. function wysija_dismiss_license_notice() { 
  403. WYSIJA::update_option('wysija_dismiss_license_notice', true); 
/controllers/back/config.php  
  1. class WYSIJA_control_back_config extends WYSIJA_control_back{ 
  2. var $view='config'; 
  3. var $model='config'; 
  4.  
  5. function __construct() { 
  6. parent::__construct(); 
  7.  
  8. function main() { 
  9. parent::__construct(); 
  10. wp_enqueue_style('thickbox'); 
  11.  
  12. if(!isset($_REQUEST['action'])) $this->action='main'; 
  13. else $this->action=$_REQUEST['action']; 
  14. $this->jsTrans['testemail'] = __('Sending a test email', WYSIJA); 
  15. $this->jsTrans['bounceconnect'] = __('Bounce handling connection test', WYSIJA); 
  16. $this->jsTrans['processbounceT'] = __('Bounce handling processing', WYSIJA); 
  17. $this->jsTrans['doubleoptinon'] = __('Subscribers will now need to activate their subscription by email in order to receive your newsletters. This is recommended.', WYSIJA); 
  18. $this->jsTrans['doubleoptinoff'] = __('Unconfirmed subscribers will receive your newsletters from now on without the need to activate their subscriptions.', WYSIJA); 
  19. $this->jsTrans['processbounce'] = __('Process bounce handling now!', WYSIJA); 
  20. $this->jsTrans['errorbounceforward'] = __('When setting up the bounce system, you need to have a different address for the bounce email and the forward to address', WYSIJA); 
  21.  
  22. // form list 
  23. $this->jsTrans['suredelete'] = __('Are you sure you want to delete this form?', WYSIJA); 
  24.  
  25. switch($this->action) { 
  26. case 'log': 
  27. case 'save': 
  28. case 'clearlog': 
  29. wp_enqueue_script('wysija-config-settings', WYSIJA_URL.'js/admin-config-settings.js', array('wysija-admin-js-global'), WYSIJA::get_version()); 
  30. wp_localize_script('wysija-config-settings', 'mpEmailCheck', WJ_Utils::get_tip_data()); 
  31. wp_enqueue_script('jquery-cookie', WYSIJA_URL.'js/jquery/jquery.cookie.js', array('jquery'), WYSIJA::get_version()); 
  32. case 'form_add': 
  33. case 'form_edit': 
  34. case 'form_duplicate': 
  35. case 'form_delete': 
  36. case 'form_widget_settings': 
  37. case 'form_add_field': 
  38. return $this->{$this->action}(); 
  39. break; 
  40. case 'reinstall': 
  41. $this->reinstall(); 
  42. return; 
  43. break; 
  44. case 'dkimcheck': 
  45. $this->dkimcheck(); 
  46. if(defined('WYSIJA_REDIRECT')) $this->redirectProcess(); 
  47. return; 
  48. break; 
  49. case 'doreinstall': 
  50. $this->doreinstall(); 
  51. if(defined('WYSIJA_REDIRECT')) { 
  52. global $wysi_location; 
  53. $wysi_location='admin.php?page=wysija_campaigns'; 
  54. $this->redirectProcess(); 
  55. return; 
  56. break; 
  57. default: 
  58. wp_enqueue_script( 'mailpoet.tooltip', WYSIJA_URL . 'js/vendor/bootstrap.tooltip.js', array( 'jquery' ), WYSIJA::get_version(), true ); 
  59. wp_enqueue_style( 'mailpoet.tooltip', WYSIJA_URL . 'css/vendor/bootstrap.tooltip.css', array(), WYSIJA::get_version(), 'screen' ); 
  60. wp_enqueue_script('wysija-config-settings', WYSIJA_URL.'js/admin-config-settings.js', array('wysija-admin-js-global'), WYSIJA::get_version(), true); 
  61. wp_localize_script('wysija-config-settings', 'mpEmailCheck', WJ_Utils::get_tip_data()); 
  62. wp_enqueue_script('jquery-cookie', WYSIJA_URL.'js/jquery/jquery.cookie.js', array('jquery'), WYSIJA::get_version()); 
  63.  
  64. if(WYSIJA_DBG > 1) { 
  65. $this->viewObj->arrayMenus = array('log' => 'View log'); 
  66.  
  67. $this->data = array(); 
  68. $hook_settings_super_advanced_params = array(); 
  69. $this->data['hooks']['hook_settings_super_advanced'] = apply_filters('hook_settings_super_advanced', WYSIJA_module::execute_hook('hook_settings_super_advanced', $hook_settings_super_advanced_params), $hook_settings_super_advanced_params); 
  70. $this->action='main'; 
  71.  
  72. if(isset($_REQUEST['validate'])) { 
  73. $this->notice(str_replace(array('[link]', '[/link]'),  
  74. array('<a title="'.__('Get Premium now', WYSIJA).'" class="premium-activate" href="javascript:;">', '</a>'),  
  75. __('You\'re almost there. Click this [link]link[/link] to activate the licence you have just purchased.', WYSIJA))); 
  76.  
  77.  
  78.  
  79. function dkimcheck() { 
  80. if(isset($_POST['xtz'])) { 
  81.  
  82. $dataconf=json_decode(base64_decode($_POST['xtz'])); 
  83. if(isset($dataconf->dkim_pubk->key) && isset($dataconf->dkim_privk)) { 
  84. $modelConf=WYSIJA::get('config', 'model'); 
  85. $dataconfsave=array('dkim_pubk'=>$dataconf->dkim_pubk->key, 'dkim_privk'=>$dataconf->dkim_privk, 'dkim_1024'=>1); 
  86.  
  87. $modelConf->save($dataconfsave); 
  88. WYSIJA::update_option('dkim_autosetup', false); 
  89.  
  90. $this->redirect('admin.php?page=wysija_config'); 
  91. return true; 
  92.  
  93. function save() { 
  94. $_REQUEST = stripslashes_deep($_REQUEST); 
  95. $_POST = stripslashes_deep($_POST); 
  96. $this->requireSecurity(); 
  97.  
  98. $hook_settings_before_save = array( 
  99. 'REQUEST' =>& $_REQUEST 
  100. ); 
  101. apply_filters('hook_settings_before_save', WYSIJA_module::execute_hook('hook_settings_before_save', $hook_settings_before_save), $hook_settings_before_save); 
  102.  
  103. $this->modelObj->save($_REQUEST['wysija']['config'], true); 
  104.  
  105. $hook_settings_super_advanced_params = array(); 
  106. $this->data['hooks']['hook_settings_super_advanced'] = apply_filters('hook_settings_super_advanced', WYSIJA_module::execute_hook('hook_settings_super_advanced', $hook_settings_super_advanced_params), $hook_settings_super_advanced_params); 
  107. // redirect so that javascript values get updated 
  108. wp_redirect('admin.php?page=wysija_config'.$_REQUEST['redirecttab']); 
  109.  
  110. function reinstall() { 
  111. $this->viewObj->title=__('Reinstall MailPoet?', WYSIJA); 
  112. return true; 
  113.  
  114. function doreinstall() { 
  115. $this->requireSecurity(); 
  116. if(isset($_REQUEST['postedfrom']) && $_REQUEST['postedfrom'] === 'reinstall') { 
  117. $uninstaller=WYSIJA::get('uninstall', 'helper'); 
  118. $uninstaller->reinstall(); 
  119. $this->redirect('admin.php?page=wysija_config'); 
  120. return true; 
  121.  
  122. function render() { 
  123. $this->checkTotalSubscribers(); 
  124. $this->viewObj->render($this->action, $this->data); 
  125.  
  126. function log() { 
  127. $this->viewObj->arrayMenus=array('clearlog'=>'Clear log'); 
  128. $this->viewObj->title='MailPoet\'s log'; 
  129. return true; 
  130.  
  131. function clearlog() { 
  132. $this->requireSecurity(); 
  133. update_option('wysija_log', array()); 
  134. $this->redirect('admin.php?page=wysija_config&action=log'); 
  135. return true; 
  136.  
  137. // WYSIJA Form Editor 
  138. function form_add() { 
  139. $this->requireSecurity(); 
  140. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  141. // set default form data 
  142. $helper_form_engine->set_data(); 
  143.  
  144. // create form in database with default data 
  145. $form = array('name' => __('New Form', WYSIJA)); 
  146.  
  147. // insert into form table 
  148. $model_forms = WYSIJA::get('forms', 'model'); 
  149. $form_id = $model_forms->insert($form); 
  150.  
  151. if($form_id !== null && (int)$form_id > 0) { 
  152. // merge form_id into form data for later use 
  153. $data = array_merge(array('form_id' => $form_id), $helper_form_engine->get_data()); 
  154. // update form data in form engine 
  155. $helper_form_engine->set_data($data); 
  156. // update form data in database 
  157. $model_forms->update(array('data' => $helper_form_engine->get_encoded('data')), array('form_id' => (int)$form_id)); 
  158.  
  159. // redirect to form editor, passing along the newly created form id 
  160. WYSIJA::redirect('admin.php?page=wysija_config&action=form_edit&id='.$form_id); 
  161. } else { 
  162. WYSIJA::redirect('admin.php?page=wysija_config#tab-forms'); 
  163. return true; 
  164.  
  165. function form_duplicate() { 
  166. $this->requireSecurity(); 
  167. if(isset($_GET['id']) && (int)$_GET['id'] > 0) { 
  168. $form_id = (int)$_GET['id']; 
  169.  
  170. $model_forms = WYSIJA::get('forms', 'model'); 
  171.  
  172. // get form data 
  173. $form = $model_forms->getOne(array('name', 'data', 'styles'), array('form_id' => $form_id)); 
  174.  
  175. if(empty($form)) { 
  176. $this->error(__('This form does not exist', WYSIJA), true); 
  177. } else { 
  178. // reset model forms 
  179. $model_forms->reset(); 
  180.  
  181. // add "copy" to the name 
  182. $form['name'] = $form['name'].' - '.__('Copy', WYSIJA); 
  183.  
  184. // insert form (duplicated) 
  185. $model_forms->insert($form); 
  186.  
  187. // display notice 
  188. $this->notice(sprintf(__('The form named "%1$s" has been created.', WYSIJA), $form['name'])); 
  189.  
  190. WYSIJA::redirect('admin.php?page=wysija_config#tab-forms'); 
  191.  
  192. function form_delete() { 
  193.  
  194. $this->requireSecurity(); 
  195.  
  196. if(isset($_GET['id']) && (int)$_GET['id'] > 0) { 
  197. $form_id = (int)$_GET['id']; 
  198.  
  199. $model_forms = WYSIJA::get('forms', 'model'); 
  200.  
  201. // get form data 
  202. $form = $model_forms->getOne(array('name'), array('form_id' => $form_id)); 
  203.  
  204. if(empty($form)) { 
  205. $this->error(__('This form has already been deleted.', WYSIJA), true); 
  206. } else { 
  207. // delete the form in the database 
  208. $model_forms->reset(); 
  209. $model_forms->delete(array('form_id' => $form_id)); 
  210.  
  211. // display notice 
  212. $this->notice(sprintf(__('The form named "%1$s" has been deleted.', WYSIJA), $form['name'])); 
  213.  
  214. WYSIJA::redirect('admin.php?page=wysija_config#tab-forms'); 
  215.  
  216. function form_edit() { 
  217. // define whether the form can be edited 
  218. $this->data['can_edit'] = true; 
  219.  
  220. // wysija form editor javascript files 
  221. $this->js[]='wysija-form-editor'; 
  222. $this->js[]='wysija-admin-ajax-proto'; 
  223. // $this->js[]='wysija-admin-ajax'; 
  224. $this->js[]='wysija-base-script-64'; 
  225. $this->js[] = 'mailpoet-select2'; 
  226.  
  227. // make sure the editor content is not cached 
  228. //header('Cache-Control: no-cache, max-age=0, must-revalidate, no-store'); // HTTP/1.1 
  229. //header('Expires: Fri, 9 Mar 1984 00:00:00 GMT'); 
  230.  
  231. // get form id 
  232. $form_id = (isset($_REQUEST['id']) && (int)$_REQUEST['id'] > 0) ? (int)$_REQUEST['id'] : null; 
  233. $form = array('name' => __('New form', WYSIJA)); 
  234.  
  235. // if no form id was specified, then it's a new form 
  236. if($form_id !== null) { 
  237. // try to get form data based on form id 
  238. $model_forms = WYSIJA::get('forms', 'model'); 
  239. $form = $model_forms->getOne($form_id); 
  240.  
  241. // if the form does not exist 
  242. if(empty($form)) { 
  243. // redirect to forms list 
  244. $this->error(__('This form does not exist.', WYSIJA), true); 
  245. WYSIJA::redirect('admin.php?page=wysija_config#tab-forms'); 
  246. } else { 
  247. // pass form id to the view 
  248. $this->data['form_id'] = (int)$form['form_id']; 
  249. // pass form to the view 
  250. $this->data['form'] = $form; 
  251.  
  252. $helper_form_engine = WYSIJA::get('form_engine', 'helper'); 
  253. $lists = $helper_form_engine->get_lists(); 
  254. $this->data['lists'] = $lists; 
  255.  
  256. // disable editing capability when there is no list 
  257. if(empty($lists)) { 
  258. $this->data['can_edit'] = false; 
  259.  
  260. // get custom fields 
  261. $this->data['custom_fields'] = $helper_form_engine->get_custom_fields(); 
  262.  
  263. // translations 
  264. $this->jsTrans = array_merge($this->jsTrans, $helper_form_engine->get_translations()); 
  265.  
  266. /** 
  267. * Handles the settings popup of wysija form widgets 
  268. */ 
  269. function form_widget_settings() { 
  270. $this->iframeTabs = array('form_widget_settings' => __('Widget Settings', WYSIJA)); 
  271. $this->js[] = 'wysija-admin-ajax'; 
  272. $this->js[] = 'wysija-base-script-64'; 
  273. $this->js[] = 'wysija-scriptaculous'; 
  274.  
  275. $_GET['tab'] = 'form_widget_settings'; 
  276.  
  277. // if there is a field id, let's get all that from this field 
  278. if(isset($_REQUEST['field_id'])) { 
  279. $field_id = ((int)$_REQUEST['field_id'] > 0) ? (int)$_REQUEST['field_id'] : 0; 
  280.  
  281. // if the id is positive then try to fetch field data 
  282. $custom_field = WJ_Field::get($field_id); 
  283.  
  284. // if field has been found 
  285. if($custom_field !== NULL) { 
  286. $this->data['name'] = (isset($_REQUEST['name'])) ? $_REQUEST['name'] : $custom_field->name; 
  287. $this->data['type'] = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $custom_field->type; 
  288. $this->data['field'] = $custom_field->user_column_name(); 
  289. $this->data['params'] = $custom_field->settings; 
  290. } else { 
  291. $this->data['name'] = (isset($_REQUEST['name'])) ? $_REQUEST['name'] : null; 
  292. $this->data['type'] = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : null; 
  293. $this->data['field'] = null; 
  294. $this->data['params'] = null; 
  295.  
  296. $this->data['field_id'] = $field_id; 
  297. } else { 
  298. // extract parameters from url 
  299. $params = array(); 
  300. if(isset($_REQUEST['params']) && trim(strlen($_REQUEST['params'])) > 0) { 
  301. $pairs = explode('|', $_REQUEST['params']); 
  302. if(count($pairs) > 0) { 
  303. foreach($pairs as $pair) { 
  304. // extract both key and value 
  305. list($key, $value) = explode(':', $pair); 
  306.  
  307. // decode value 
  308. $value = base64_decode($value); 
  309. // unserialize if necessary (using is_serialized from WordPress) and making sure we only unserialize arrays not objects 
  310. if(is_serialized($value) === true && preg_match('/^a:[0-9]+:{/', $value) && !preg_match('/(^|;|{|})O:\+?[0-9]+:"/', $value) ) { 
  311. $value = (array) unserialize($value); 
  312. $params[$key] = $value; 
  313.  
  314. // common widget data 
  315. $this->data['name'] = (isset($_REQUEST['name'])) ? $_REQUEST['name'] : null; 
  316. $this->data['type'] = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : null; 
  317. $this->data['field'] = (isset($_REQUEST['field'])) ? $_REQUEST['field'] : null; 
  318.  
  319. // widget params 
  320. $this->data['params'] = $params; 
  321.  
  322. // extra data that needs to be fetched for some widget 
  323. $extra = array(); 
  324.  
  325. switch($this->data['type']) { 
  326. // in case of the list widget, we need to pass an array of all available lists 
  327. case 'list': 
  328. $model_list = WYSIJA::get('list', 'model'); 
  329.  
  330. // get lists users can subscribe to (aka "enabled list") 
  331. $extra['lists'] = $model_list->get(array('name', 'list_id', 'is_public'), array('is_enabled' => 1)); 
  332. break; 
  333.  
  334. $this->data['extra'] = $extra; 
  335.  
  336. return $this->popupContent(); 
  337. exit; 
  338. // End: WYSIJA Form Editor