WYSIJA_control_back_campaigns

The MailPoet Newsletters WYSIJA control back campaigns class.

Defined (2)

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

/controllers/ajax/campaigns.php  
  1. class WYSIJA_control_back_campaigns extends WYSIJA_control{ 
  2.  
  3. function __construct() { 
  4. if(!WYSIJA::current_user_can('wysija_newsletters')) die('Action is forbidden.'); 
  5. parent::__construct();; 
  6.  
  7. function save_poll() { 
  8. $this->requireSecurity(); 
  9.  
  10. if( in_array($_REQUEST['how'], array('repository' , 'search_engine' , 'friend', 'url' )) ) { 
  11.  
  12. $data_conf = array( 'poll_origin' => $_REQUEST['how'] ); 
  13. if( !empty( $_REQUEST['where'] ) ) { 
  14. $data_conf['poll_origin_url'] = esc_url($_REQUEST['where']); 
  15. $model_config = WYSIJA::get('config', 'model'); 
  16. $model_config->save( $data_conf ); 
  17.  
  18. $res['result'] = true; 
  19. $res['msg'] = '<span><span class="checkmark">---</span>'. __('Thanks!', WYSIJA). '</span>'; 
  20. return $res; 
  21.  
  22. $res['result'] = false; 
  23. return $res; 
  24.  
  25.  
  26. function switch_theme() { 
  27. $this->requireSecurity(); 
  28. if(isset($_POST['wysijaData'])) { 
  29. $rawData = $_POST['wysijaData']; 
  30. // avoid using stripslashes as it's not reliable depending on the magic quotes settings 
  31. $rawData = str_replace('\"', '"', $rawData); 
  32. // decode JSON data 
  33. $rawData = json_decode($rawData, true); 
  34.  
  35. $theme = (isset($rawData['theme'])) ? $rawData['theme'] : 'default'; 
  36.  
  37. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  38. $res['templates'] = $helper_wj_engine->renderTheme($theme); 
  39.  
  40. $email_id = (int)$_REQUEST['id']; 
  41.  
  42. $campaignsHelper = WYSIJA::get('campaigns', 'helper'); 
  43.  
  44. if(isset($res['templates']['divider_options'])) { 
  45. // save divider 
  46. $campaignsHelper->saveParameters($email_id, 'divider', $res['templates']['divider_options']); 
  47.  
  48. // save theme used 
  49. $campaignsHelper->saveParameters($email_id, 'theme', $theme); 
  50.  
  51. $res['templates']['theme'] = $theme; 
  52. $res['styles'] = $helper_wj_engine->renderThemeStyles($theme); 
  53. } else { 
  54. $res['msg'] = __("The theme you selected could not be loaded.", WYSIJA); 
  55. $res['result'] = false; 
  56. return $res; 
  57.  
  58. function save_editor() { 
  59. $this->requireSecurity(); 
  60. // decode json data and convert to array 
  61. $rawData = ''; 
  62. if(isset($_POST['wysijaData'])) { 
  63. $rawData = $_POST['wysijaData']; 
  64. // avoid using stripslashes as it's not reliable depending on the magic quotes settings 
  65. $rawData = str_replace('\"', '"', $rawData); 
  66. // decode JSON data 
  67. $rawData = json_decode($rawData, true); 
  68.  
  69. if(!$rawData) { 
  70. $this->error('Error saving', false); 
  71. return array('result' => false); 
  72.  
  73. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  74. $helper_wj_engine->setData( $rawData ); 
  75. $result = false; 
  76.  
  77. // get email id 
  78. $email_id = (int)$_REQUEST['id']; 
  79.  
  80. $model_email = WYSIJA::get('email', 'model'); 
  81. $emailData = $model_email->getOne(array('wj_styles', 'subject', 'params', 'email_id', 'campaign_id'), array('email_id' => $email_id)); 
  82.  
  83. $helper_wj_engine->setStyles($emailData['wj_styles'], true); 
  84.  
  85. $values = array('wj_data' => $helper_wj_engine->getEncoded('data')); 
  86. $values['body'] = $helper_wj_engine->renderEmail($emailData); 
  87. $values['email_id'] = $email_id; 
  88.  
  89. $updated_email = $helper_wj_engine->getEmailData(); 
  90.  
  91. // update modified_at timestamp 
  92. $model_email->columns['modified_at']['autoup']=1; 
  93.  
  94. // update data in DB 
  95. $result = $model_email->update($values, array('email_id' => $email_id)); 
  96.  
  97. if(!$result) { 
  98. // throw error 
  99. $this->error(__('Your email could not be saved', WYSIJA)); 
  100. } else { 
  101. // save successful 
  102. $this->notice(__('Your email has been saved', WYSIJA)); 
  103.  
  104. return array('result' => $result); 
  105.  
  106. function save_styles() { 
  107. $this->requireSecurity(); 
  108. // decode json data and convert to array 
  109. $rawData = ''; 
  110. if(isset($_POST['wysijaStyles'])) { 
  111. $rawData = $_POST['wysijaStyles']; 
  112. // avoid using stripslashes as it's not reliable depending on the magic quotes settings 
  113. $rawData = str_replace('\"', '"', $rawData); 
  114. // decode JSON data 
  115. $rawData = json_decode($rawData, true); 
  116.  
  117.  
  118. // handle checkboxes 
  119. if(array_key_exists('a-underline', $rawData) === false) { 
  120. $rawData['a-underline'] = -1; 
  121.  
  122. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  123. $helper_wj_engine->setStyles($helper_wj_engine->formatStyles($rawData)); 
  124.  
  125. $result = false; 
  126.  
  127. $values = array( 
  128. 'wj_styles' => $helper_wj_engine->getEncoded('styles') 
  129. ); 
  130.  
  131. // get email id 
  132. $email_id = (int)$_REQUEST['id']; 
  133.  
  134. // update data in DB 
  135. $model_email = WYSIJA::get('email', 'model'); 
  136. $result = $model_email->update($values, array('email_id' => $email_id)); 
  137.  
  138. if(!$result) { 
  139. // throw error 
  140. $this->error(__('Styles could not be saved', WYSIJA)); 
  141. } else { 
  142. // save successful 
  143. $this->notice(__('Styles have been saved', WYSIJA)); 
  144.  
  145. return array( 
  146. 'styles' => $helper_wj_engine->renderStyles(),  
  147. 'result' => $result 
  148. ); 
  149.  
  150. function deleteimg() { 
  151. $this->requireSecurity(); 
  152. if(isset($_REQUEST['imgid']) && $_REQUEST['imgid']>0) { 
  153. /** delete the image with id imgid */ 
  154. $result=wp_delete_attachment($_REQUEST['imgid'], true); 
  155. if($result) { 
  156. $this->notice(__('Image has been deleted.', WYSIJA)); 
  157.  
  158. $res=array(); 
  159. $res['result'] = $result; 
  160. return $res; 
  161.  
  162. function deleteTheme() { 
  163. $this->requireSecurity(); 
  164. if(isset($_REQUEST['themekey']) && $_REQUEST['themekey']) { 
  165. /** delete the image with id imgid */ 
  166. $helperTheme=WYSIJA::get('themes', 'helper'); 
  167. $result=$helperTheme->delete($_REQUEST['themekey']); 
  168.  
  169. $res=array(); 
  170. $res['result'] = $result; 
  171. return $res; 
  172.  
  173. // set newsletter default theme 
  174. function setDefaultTheme() { 
  175. $this->requireSecurity(); 
  176. if(isset($_REQUEST['theme']) && $_REQUEST['theme']) { 
  177. // check that the theme exists 
  178. // TODO 
  179. $theme_exists = true; 
  180. if($theme_exists === true) { 
  181. // update config 
  182. $model_config = WYSIJA::get('config', 'model'); 
  183. $model_config->save(array('newsletter_default_theme' => $_REQUEST['theme'])); 
  184.  
  185. $result = true; 
  186. } else { 
  187. $result = false; 
  188.  
  189. return array('result' => $result); 
  190.  
  191. function save_IQS() { 
  192. $this->requireSecurity(); 
  193. // decode json data and convert to array 
  194. $wysijaIMG = ''; 
  195. if(isset($_POST['wysijaIMG'])) { 
  196. $wysijaIMG = json_decode(stripslashes($_POST['wysijaIMG']), TRUE); 
  197. $values = array( 
  198. 'params' => array('quickselection'=>$wysijaIMG) 
  199. ); 
  200.  
  201. // get email id 
  202. $email_id = (int)$_REQUEST['id']; 
  203. $values['email_id']=$email_id; 
  204.  
  205. // update data in DB 
  206. $model_email = WYSIJA::get('email', 'model'); 
  207. $result = $model_email->update($values, array('email_id' => $email_id)); 
  208.  
  209. if(!$result) { 
  210. // throw error 
  211. $this->error(__('Image selection has not been saved.', WYSIJA)); 
  212. } else { 
  213. // save successful 
  214. $this->notice(__('Image selection has been saved.', WYSIJA)); 
  215.  
  216. return array('result' => $result); 
  217.  
  218. function insert_articles() { 
  219. $this->requireSecurity(); 
  220. // get raw params 
  221. $raw_params = $_REQUEST['data']; 
  222.  
  223. // format params 
  224. $params = array(); 
  225. foreach($raw_params as $value) { 
  226. $params[$value['name']] = $value['value']; 
  227.  
  228. if($params['show_divider'] === 'yes') { 
  229. // get divider 
  230. $divider = $_REQUEST['divider']; 
  231. } else { 
  232. $divider = null; 
  233. $params['divider'] = $divider; 
  234.  
  235. // get post ids 
  236. $post_ids = array(); 
  237. if(isset($_REQUEST['post_ids']) && strlen(trim($_REQUEST['post_ids'])) > 0) { 
  238. $post_ids = explode(', ', $_REQUEST['post_ids']); 
  239.  
  240. if(empty($post_ids)) { 
  241. // return error 
  242. $res['msg'] = __('Please select an article.', WYSIJA); 
  243. $res['result'] = false; 
  244. return $res; 
  245.  
  246. // specify custom fields to get from posts 
  247. $post_params = array('include' => $post_ids); 
  248.  
  249. // include sort by parameter into post params 
  250. $post_params['sort_by'] = $params['sort_by']; 
  251.  
  252. // get posts 
  253. $model_wp_posts = WYSIJA::get('wp_posts', 'model'); 
  254. $posts = $model_wp_posts->get_posts($post_params); 
  255.  
  256. // check if we need to interpret shortcodes 
  257. $model_config = WYSIJA::get('config', 'model'); 
  258. $interpret_shortcode = (bool)$model_config->getValue('interp_shortcode'); 
  259.  
  260. // get some model and helpers 
  261. $helper_articles = WYSIJA::get('articles', 'helper'); 
  262. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  263.  
  264. $output = ''; 
  265.  
  266. // save parameters for next time 
  267. $model_config->save(array('insert_post_parameters' => $helper_wj_engine->encodeParameters($params))); 
  268.  
  269. foreach($posts as $key => $post) { 
  270. if($interpret_shortcode === true) { 
  271. // interpret shortcodes 
  272. $posts[$key]['post_content'] = apply_filters('the_content', $post['post_content']); 
  273. // get thumbnail 
  274. $posts[$key]['post_image'] = $helper_articles->getImage($post); 
  275.  
  276. $output .= base64_encode($helper_wj_engine->renderPostsToBlocks($posts, $params)); 
  277.  
  278. if(strlen($output) > 0) { 
  279. $res['result'] = true; 
  280. $res['posts'] = $output; 
  281. }else { 
  282. $res['msg'] = __('There are no posts corresponding to that search.', WYSIJA); 
  283. $res['result'] = false; 
  284.  
  285. return $res; 
  286.  
  287. function send_preview($spamtest=false) { 
  288. $this->requireSecurity(); 
  289. $mailer=WYSIJA::get('mailer', 'helper'); 
  290. $email_id = $_REQUEST['id']; 
  291. $resultarray=array(); 
  292.  
  293. // update data in DB 
  294. $model_email = WYSIJA::get('email', 'model'); 
  295. $model_email->getFormat=OBJECT; 
  296. $email_object = $model_email->getOne(false, array('email_id' => $email_id)); 
  297. $mailer->testemail=true; 
  298.  
  299.  
  300. if(isset($_REQUEST['data'])) { 
  301. $dataTemp=$_REQUEST['data']; 
  302. $_REQUEST['data']=array(); 
  303. foreach($dataTemp as $val) $_REQUEST['data'][$val['name']]=$val['value']; 
  304. unset($dataTemp); 
  305. foreach($_REQUEST['data'] as $k =>$v) { 
  306. $newkey=str_replace(array('wysija[email][', ']'), '', $k); 
  307. $configVal[$newkey]=$v; 
  308. if(isset($configVal['from_name'])) { 
  309. $params=array( 
  310. 'from_name'=>$configVal['from_name'],  
  311. 'from_email'=>$configVal['from_email'],  
  312. 'replyto_name'=>$configVal['replyto_name'],  
  313. 'replyto_email'=>$configVal['replyto_email']); 
  314. if(isset($configVal['subject'])) $email_object->subject=$configVal['subject']; 
  315.  
  316. }else{ 
  317. $params=array( 
  318. 'from_name'=>$email_object->from_name,  
  319. 'from_email'=>$email_object->from_email,  
  320. 'replyto_name'=>$email_object->replyto_name,  
  321. 'replyto_email'=>$email_object->replyto_email 
  322. ); 
  323. if(strpos($_REQUEST['receiver'], ', ')) { 
  324. $receivers = explode(', ', $_REQUEST['receiver']); 
  325. } else if(strpos($_REQUEST['receiver'], ';')) { 
  326. $receivers = explode(';', $_REQUEST['receiver']); 
  327. } else { 
  328. $receivers = array($_REQUEST['receiver']); 
  329.  
  330. $user_model = WYSIJA::get('user', 'model'); 
  331. foreach($receivers as $key => $receiver) { 
  332. $receiver = trim($receiver); 
  333. $dummy_receiver = $user_model->get_object_by_email($receiver); 
  334. if(empty($dummy_receiver)) { 
  335. $dummy_receiver = new stdClass(); 
  336. $dummy_receiver->user_id = 0; 
  337. $dummy_receiver->email = $receiver; 
  338. $dummy_receiver->status = 1; 
  339. $dummy_receiver->lastname = $dummy_receiver->firstname = ''; 
  340.  
  341. if($spamtest) { 
  342. $langextra = ''; 
  343. $dummy_receiver->firstname ='Mail Tester'; 
  344.  
  345. $wp_lang = get_locale(); 
  346. if(!empty($wp_lang)) $langextra ='&lang='.$wp_lang; 
  347. $resultarray['urlredirect']='http://www.mail-tester.com/check.php?id='.urlencode($dummy_receiver->email).$langextra; 
  348. $receivers[$key] = $dummy_receiver; 
  349.  
  350.  
  351. $email_clone=array(); 
  352. foreach($email_object as $kk=>$vv) $email_clone[$kk]=$vv; 
  353.  
  354.  
  355. $wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  356. // set data & styles 
  357. if(isset($email_clone['wj_data'])) { $wj_engine->setData($email_clone['wj_data'], true); } else { $wj_engine->setData(); } 
  358. if(isset($email_clone['wj_styles'])) { $wj_engine->setStyles($email_clone['wj_styles'], true); } else { $wj_engine->setStyles(); } 
  359.  
  360. // generate email html body 
  361. $body = $wj_engine->renderEmail($email_clone); 
  362.  
  363. // get back email data as it will be updated during the rendering (articles ids + articles count) 
  364. $email_child = $wj_engine->getEmailData(); 
  365.  
  366. // [total] [number] and [post_title] are only valid for post notifications newsletter 
  367. if((int)$email_child['type'] === 2 && isset($email_child['params']['autonl']['event']) && 
  368. $email_child['params']['autonl']['event'] === 'new-articles' && isset($email_child['params']['autonl']['articles'])) { 
  369.  
  370. $item_count = 0; 
  371. $total_count = 1; 
  372. $first_subject = ''; 
  373.  
  374. if(isset($email_child['params']['autonl']['articles']['count'])) $item_count = (int)$email_child['params']['autonl']['articles']['count']; 
  375. if(isset($email_child['params']['autonl']['articles']['first_subject'])) $first_subject = $email_child['params']['autonl']['articles']['first_subject']; 
  376. if(isset($email_child['params']['autonl']['total_child'])) $total_count = (int)$email_child['params']['autonl']['total_child'] + 1; 
  377.  
  378. $email_object->subject = str_replace( 
  379. array('[total]', '[number]', '[post_title]'),  
  380. array($item_count, $total_count, $first_subject),  
  381. $email_child['subject'] 
  382. ); 
  383. $successmsg = __('Your email preview has been sent to %1$s', WYSIJA); 
  384.  
  385. // correction added for post notifications with the tag [newsletter:post_title] failing to send 
  386. if(isset($email_object->params['autonl']) && isset($email_child['params']['autonl'])) { 
  387. $email_object->params['autonl']=$email_child['params']['autonl']; 
  388.  
  389. if(isset($email_object->params)) { 
  390. $params['params']=$email_object->params; 
  391.  
  392. if(isset($configVal['params[googletrackingcode'])) { 
  393. $paramsemail=array(); 
  394. if(!is_array($email_object->params)) $paramsemail=unserialize(base64_decode($email_object->params)); 
  395.  
  396. if(trim($configVal['params[googletrackingcode'])) { 
  397. $paramsemail['googletrackingcode']=$configVal['params[googletrackingcode']; 
  398. else { 
  399. unset($paramsemail['googletrackingcode']); 
  400. $params['params'] = base64_encode(serialize($paramsemail)); 
  401.  
  402. $params['email_id'] = $email_object->email_id; 
  403. $receiversList = array(); 
  404. $res = false; 
  405. foreach($receivers as $receiver) { 
  406. if($mailer->sendSimple($receiver, stripslashes($email_object->subject), $email_object->body, $params)) { 
  407. $res = true; 
  408. $receiversList[] = $receiver->email; 
  409. WYSIJA::log('preview_sent', $mailer, 'manual'); 
  410.  
  411. if($res === true) { 
  412. $this->notice(sprintf($successmsg, implode(', ', $receiversList))); 
  413.  
  414. $resultarray['result'] = $res; 
  415.  
  416. return $resultarray; 
  417.  
  418. /** 
  419. * send spam test function step 2 of the newsletter edition process 
  420. */ 
  421. function send_spamtest() { 
  422. $this->requireSecurity(); 
  423. return apply_filters('wysija_send_spam_test', '', $this); 
  424.  
  425. function set_divider() 
  426. $this->requireSecurity(); 
  427. $src = isset($_POST['wysijaData']['src']) ? $_POST['wysijaData']['src'] : NULL; 
  428. $width = isset($_POST['wysijaData']['width']) ? (int)$_POST['wysijaData']['width'] : NULL; 
  429. $height = isset($_POST['wysijaData']['height']) ? (int)$_POST['wysijaData']['height'] : NULL; 
  430.  
  431. if($src === NULL OR $width === NULL OR $height === NULL) { 
  432. // there is a least one missing parameter, fallback to default divider 
  433. $dividersHelper = WYSIJA::get('dividers', 'helper'); 
  434. $divider = $dividersHelper->getDefault(); 
  435. } else { 
  436. // use provided params 
  437. $divider = array( 
  438. 'src' => $src,  
  439. 'width' => $width,  
  440. 'height' => $height 
  441. ); 
  442.  
  443. // update campaign parameters 
  444. $email_id = (int)$_REQUEST['id']; 
  445. $campaignsHelper = WYSIJA::get('campaigns', 'helper'); 
  446. $campaignsHelper->saveParameters($email_id, 'divider', $divider); 
  447.  
  448. // set params 
  449. $block = array_merge(array('no-block' => true, 'type' => 'divider'), $divider); 
  450.  
  451. $helper_wj_engine=WYSIJA::get('wj_engine', 'helper'); 
  452. return base64_encode($helper_wj_engine->renderEditorBlock($block)); 
  453.  
  454. function generate_social_bookmarks() { 
  455. $this->requireSecurity(); 
  456. $size = 'medium'; 
  457. $iconset = '01'; 
  458.  
  459. if(isset($_POST['wysijaData']) && !empty($_POST['wysijaData'])) { 
  460. $data = $_POST['wysijaData']; 
  461. $items = array(); 
  462.  
  463. foreach($data as $key => $values) { 
  464. if($values['name'] === 'bookmarks-size') { 
  465. // get size 
  466. $size = $values['value']; 
  467. } else if($values['name'] === 'bookmarks-theme') { 
  468. // get theme name 
  469. $theme = $values['value']; 
  470. } else if($values['name'] === 'bookmarks-iconset') { 
  471. // get iconset 
  472. $iconset = $values['value']; 
  473. if(strlen(trim($iconset)) === 0) { 
  474. $this->error('No iconset specified', false); 
  475. return false; 
  476. } else { 
  477. $keys = explode('-', $values['name']); 
  478. $network = $keys[1]; 
  479. $property = $keys[2]; 
  480. if(array_key_exists($network, $items)) { 
  481. $items[$network][$property] = $values['value']; 
  482. } else { 
  483. $items[$network] = array($property => $values['value']); 
  484.  
  485. $urls = array(); 
  486. // check data and remove network with an empty url 
  487. foreach($items as $network => $item) { 
  488. if(strlen(trim($item['url'])) === 0) { 
  489. // empty url 
  490. unset($items[$network]); 
  491. } else { 
  492. // url specified 
  493. $urls[$network] = $item['url']; 
  494.  
  495. // check if there's at least one url left 
  496. if(empty($urls)) { 
  497. $this->error('No url specified', false); 
  498. return false; 
  499.  
  500. // save url in config 
  501. $config=WYSIJA::get('config', 'model'); 
  502. $config->save(array('social_bookmarks' => $urls)); 
  503.  
  504. // get iconset icons 
  505. $bookmarksHelper = WYSIJA::get('bookmarks', 'helper'); 
  506.  
  507. // if the iconset is 00, then it's the theme's bookmarks 
  508. if($iconset === '00') { 
  509. $icons = $bookmarksHelper->getAllByTheme($theme); 
  510. } else { 
  511. // otherwise it's a basic iconset 
  512. $icons = $bookmarksHelper->getAllByIconset($size, $iconset); 
  513.  
  514.  
  515. // format data 
  516. $block = array( 
  517. 'position' => 1,  
  518. 'type' => 'gallery',  
  519. 'items' => array(),  
  520. 'alignment' => 'center' 
  521. ); 
  522.  
  523. $width = 0; 
  524. foreach($items as $key => $item) { 
  525. $block['items'][] = array_merge($item, $icons[$key], array('alt' => ucfirst($key))); 
  526. $width += (int)$icons[$key]['width']; 
  527. // add margin between icons 
  528. $width += (count($block['items']) - 1) * 10; 
  529. // set optimal width 
  530. $block['width'] = max(0, min($width, 564)); 
  531.  
  532. $helper_wj_engine=WYSIJA::get('wj_engine', 'helper'); 
  533. return base64_encode($helper_wj_engine->renderEditorBlock($block)); 
  534.  
  535. function install_theme() { 
  536. $this->requireSecurity(); 
  537. if( isset($_REQUEST['theme_id'])) { 
  538. global $wp_version; 
  539. //check if theme is premium if you have the premium licence 
  540. if(isset($_REQUEST['premium']) && $_REQUEST['premium']) { 
  541. $getpremiumtheme=apply_filters('wysija_install_theme_premium', false); 
  542.  
  543. if(!$getpremiumtheme) { 
  544. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  545. $themes = $helper_wj_engine->renderThemes(); 
  546. return array('result'=>false, 'themes' => $themes); 
  547.  
  548. $helperToolbox = WYSIJA::get('toolbox', 'helper'); 
  549. $domain_name = $helperToolbox->_make_domain_name(admin_url('admin.php')); 
  550.  
  551. $request = 'http://api.mailpoet.com/download/zip/'.$_REQUEST['theme_id'].'?domain='.$domain_name; 
  552.  
  553. $args = array( 
  554. 'timeout' => 30,  
  555. 'body' => array( ),  
  556. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 
  557. ); 
  558. $raw_response = wp_remote_post( $request, $args ); 
  559.  
  560. if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { 
  561. if(method_exists($raw_response, 'get_error_messages')) { 
  562. $this->error($raw_response->get_error_messages()); 
  563. $ZipfileResult = false; 
  564. }else{ 
  565. $ZipfileResult = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 
  566.  
  567. if($ZipfileResult === false) { 
  568. $result = false; 
  569. $this->error(__('We were unable to contact the API, the site may be down. Please try again later.', WYSIJA), true); 
  570. }else{ 
  571. $themesHelp=WYSIJA::get('themes', 'helper'); 
  572. $result = $themesHelp->installTheme($ZipfileResult); 
  573.  
  574. // refresh themes list 
  575. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  576. $themes = $helper_wj_engine->renderThemes(); 
  577. }else{ 
  578. $result = false; 
  579. $themes = ''; 
  580. $this->notice('missing info'); 
  581.  
  582. return array('result' => $result, 'themes' => $themes); 
  583.  
  584. function get_social_bookmarks() { 
  585. $size = isset($_POST['wysijaData']['size']) ? $_POST['wysijaData']['size'] : NULL; 
  586. $theme = isset($_POST['wysijaData']['theme']) ? $_POST['wysijaData']['theme'] : NULL; 
  587.  
  588. $bookmarksHelper = WYSIJA::get('bookmarks', 'helper'); 
  589. $bookmarks = $bookmarksHelper->getAll($size, $theme); 
  590. return json_encode(array('icons' => $bookmarks)); 
  591.  
  592. function refresh_themes() { 
  593. // refresh themes list 
  594. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  595. return array('result'=>true, 'themes' => $helper_wj_engine->renderThemes()); 
  596.  
  597. function generate_auto_post() { 
  598. // get params and generate html 
  599. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  600. $helper_articles = WYSIJA::get('articles', 'helper'); 
  601.  
  602. // get parameters 
  603. $block_params = array(); 
  604. if(isset($_POST['wysijaData'])) { 
  605. // store category ids (TBR) 
  606. $category_ids = array(); 
  607.  
  608. foreach($_POST['wysijaData'] as $pairs) { 
  609. // special cases 
  610. switch($pairs['name']) { 
  611. case 'author_label': 
  612. case 'category_label': 
  613. case 'readmore': 
  614. case 'nopost_message': 
  615. $block_params[] = array('key' => $pairs['name'], 'value' => base64_encode(stripslashes($pairs['value']))); 
  616. break; 
  617. case 'category_ids': 
  618. $category_ids = array_filter( array_map( 'absint', explode( ', ', $pairs['value'] ) ) ); 
  619. break; 
  620. default: 
  621. $block_params[] = array('key' => $pairs['name'], 'value' => $pairs['value']); 
  622.  
  623. // make sure we have only unique ids in categories 
  624. $block_params[] = array('key' => 'category_ids', 'value' => join(', ', array_unique($category_ids))); 
  625.  
  626. if(empty($block_params)) { 
  627. // an error occurred, do something! 
  628. return false; 
  629. } else { 
  630. $data = array( 
  631. 'type' => 'auto-post',  
  632. 'params' => $block_params 
  633. ); 
  634. return base64_encode($helper_wj_engine->renderEditorBlock($data)); 
  635.  
  636. function load_auto_post() { 
  637. $params = array(); 
  638.  
  639. if(isset($_POST['wysijaData'])) { 
  640.  
  641. $pairs = explode('&', $_POST['wysijaData']); 
  642.  
  643. foreach($pairs as $pair) { 
  644. list($key, $value) = explode('=', $pair); 
  645. switch($key) { 
  646. case 'autopost_count': 
  647. $params[$key] = (int)$value; 
  648. break; 
  649. case 'readmore': 
  650. case 'author_label': 
  651. case 'category_label': 
  652. case 'nopost_message': 
  653. $params[$key] = base64_decode($value); 
  654. break; 
  655. case 'exclude': 
  656. $params[$key] = explode(', ', $value); 
  657. break; 
  658. default: 
  659. $params[$key] = $value; 
  660.  
  661. if(empty($params)) { 
  662. // an error occurred, do something! 
  663. return false; 
  664. } else { 
  665.  
  666. // get email params 
  667. $email_id = (int)$_REQUEST['id']; 
  668. $model_email = WYSIJA::get('email', 'model'); 
  669. $email = $model_email->getOne(array('params', 'sent_at', 'campaign_id'), array('email_id' => $email_id)); 
  670.  
  671. $helper_articles = WYSIJA::get('articles', 'helper'); 
  672. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  673.  
  674. // see if posts have already been sent 
  675. if(!empty($email['params']['autonl']['articles']['ids'])) { 
  676. if(!isset($params['exclude'])) { $params['exclude'] = array(); } 
  677.  
  678. $params['exclude'] = array_unique(array_merge($email['params']['autonl']['articles']['ids'], $params['exclude'])); 
  679.  
  680. //we set the post_date to filter articles only older than that one 
  681. if(isset($email['params']['autonl']['firstSend'])) { 
  682. $params['post_date'] = $email['params']['autonl']['firstSend']; 
  683.  
  684. // if immediate let it know to the get post 
  685. if(isset($email['params']['autonl']['articles']['immediatepostid'])) { 
  686. $params['include'] = $email['params']['autonl']['articles']['immediatepostid']; 
  687. $params['post_limit'] = 1; 
  688. }else{ 
  689. //we set the post_date to filter articles only older than the last time we sent articles 
  690. if(isset($email['params']['autonl']['lastSend'])) { 
  691. $params['post_date'] = $email['params']['autonl']['lastSend']; 
  692. }else{ 
  693. //get the latest child newsletter sent_at value 
  694. $mEmail=WYSIJA::get('email', 'model'); 
  695. $mEmail->reset(); 
  696. $mEmail->orderBy('email_id', 'DESC'); 
  697. $lastEmailSent=$mEmail->getOne(false, array('campaign_id'=>$email['campaign_id'], 'type'=>'1')); 
  698.  
  699. if(!empty($lastEmailSent)) $params['post_date'] = $lastEmailSent['sent_at']; 
  700.  
  701. // get posts 
  702. $model_wp_posts = WYSIJA::get('wp_posts', 'model'); 
  703. $posts = $model_wp_posts->get_posts($params); 
  704.  
  705. if(empty($posts)) { 
  706. // nothing to display 
  707. $posts = array(); 
  708. } else { 
  709. // used to keep track of post ids present in the auto post 
  710. $post_ids = array(); 
  711.  
  712. // cleanup post and get image 
  713. foreach($posts as $key => $post) { 
  714. if($params['image_alignment'] !== 'none') { 
  715. // attempt to get post image 
  716. $posts[$key]['post_image'] = $helper_articles->getImage($post); 
  717.  
  718. // store article id 
  719. $post_ids[] = $post['ID']; 
  720. // store article ids 
  721. $params['post_ids'] = join(', ', $post_ids); 
  722.  
  723. // get divider if necessary (for immediate post notification, the "show_divider" parameter is not available) 
  724. if(isset($params['show_divider']) && $params['show_divider'] === 'yes') { 
  725. if(isset($email['params']['divider'])) { 
  726. $params['divider'] = $email['params']['divider']; 
  727. } else { 
  728. $helper_dividers = WYSIJA::get('dividers', 'helper'); 
  729. $params['divider'] = $helper_dividers->getDefault(); 
  730.  
  731. return base64_encode($helper_wj_engine->renderEditorAutoPost($posts, $params)); 
  732.  
  733. function search_terms( $request = null ) { 
  734. $response = (object) array( 
  735. 'status' => false,  
  736. 'message' => __( 'Your request has failed', WYSIJA ),  
  737. 'results' => array(),  
  738. 'more' => true,  
  739. ); 
  740.  
  741. if ( ( ! defined( 'DOING_AJAX' ) && is_null( $request ) ) || ! is_user_logged_in() ) { 
  742. return $response; 
  743.  
  744. $request = (object) wp_parse_args( 
  745. $request,  
  746. array( 
  747. 'search' => isset( $_GET['search'] ) ? $_GET['search'] : '',  
  748. 'post_type' => isset( $_GET['post_type'] ) ? $_GET['post_type'] : null,  
  749. 'page' => absint( isset( $_GET['page'] ) ? $_GET['page'] : 0 ),  
  750. 'page_limit' => absint( isset( $_GET['page_limit'] ) ? $_GET['page_limit'] : 10 ),  
  751. ); 
  752.  
  753. if ( is_null( $request->post_type ) ) { 
  754. return $response; 
  755.  
  756. $response->status = true; 
  757. $response->message = __( 'Request successful', WYSIJA ); 
  758.  
  759. $response->post_type = get_post_types( array( 'name' => $request->post_type ) ); 
  760. $response->post_type = reset( $response->post_type ); 
  761.  
  762. preg_match( '/@(\w+)/i', $request->search, $response->regex ); 
  763.  
  764. if ( ! empty( $response->regex ) ) { 
  765. $request->search = array_filter( array_map( 'trim', explode( '|', str_replace( $response->regex[0], '|', $request->search ) ) ) ); 
  766. $request->search = reset( $request->search ); 
  767. $taxonomies = $response->regex[1]; 
  768. } else { 
  769. $taxonomies = get_object_taxonomies( $response->post_type ); 
  770. $response->taxonomies = get_object_taxonomies( $response->post_type, 'objects' ); 
  771.  
  772. $response->results = get_terms( 
  773. (array) $taxonomies,  
  774. array( 
  775. 'hide_empty' => false,  
  776. 'search' => $request->search,  
  777. 'number' => $request->page_limit,  
  778. 'offset' => $request->page_limit * ( $request->page - 1 ),  
  779. ); 
  780.  
  781. if ( empty( $response->results ) || count( $response->results ) < $request->page_limit ) { 
  782. $response->more = false; 
  783.  
  784. return $response; 
  785.  
  786. /** 
  787. * returns a list of articles to the popup in the visual editor 
  788. * @global type $wpdb 
  789. * @return boolean 
  790. */ 
  791. function get_articles() { 
  792. // fixes issue with pcre functions 
  793. @ini_set('pcre.backtrack_limit', 1000000); 
  794.  
  795. // get parameters 
  796. $raw_data = $_REQUEST['data']; 
  797. $params = array(); 
  798. foreach ($raw_data as $value) { 
  799. $params[$value['name']] = $value['value']; 
  800.  
  801. // get options 
  802. $model_config = WYSIJA::get('config', 'model'); 
  803. $interpret_shortcode = (bool)$model_config->getValue('interp_shortcode'); 
  804.  
  805. // post statuses 
  806. $helper_wp_tools = WYSIJA::get('wp_tools', 'helper'); 
  807. $post_statuses = $helper_wp_tools->get_post_statuses(); 
  808. $post_types = $helper_wp_tools->get_post_types(); 
  809.  
  810. // filter by post_type 
  811. if(isset($params['post_type'])) { 
  812. $post_types_filter = array(); 
  813. if(strlen(trim($params['post_type'])) === 0) { 
  814. $post_types_filter = array_keys($post_types); 
  815. $post_types_filter[] = 'post'; 
  816. $post_types_filter[] = 'page'; 
  817. } else { 
  818. $post_types_filter = trim($params['post_type']); 
  819. // set condition on post type 
  820. $params['post_type'] = $post_types_filter; 
  821.  
  822. // query offset when doing incremental loading 
  823. $query_offset = (isset($_REQUEST['query_offset']) && (int)$_REQUEST['query_offset'] >= 0) ? (int)$_REQUEST['query_offset'] : 0; 
  824. $params['query_offset'] = $query_offset; 
  825.  
  826. // fetch posts 
  827. $helper_articles = WYSIJA::get('articles', 'helper'); 
  828.  
  829. // set is_search_query (true) to get a count in addition to the results 
  830. $params['is_search_query'] = true; 
  831.  
  832. $model_wp_posts = WYSIJA::get('wp_posts', 'model'); 
  833. $data = $model_wp_posts->get_posts($params); 
  834.  
  835. // extract data 
  836. $posts = $data['rows']; 
  837. // contains the total number of rows available 
  838. $count = $data['count']; 
  839.  
  840. // return results 
  841. $result = array( 
  842. 'result' => true,  
  843. 'append' => ($query_offset > 0) 
  844. ); 
  845.  
  846. if(empty($posts) === false) { 
  847. foreach($posts as $key => $post) { 
  848. // interpret shortcodes 
  849. if($interpret_shortcode === true) { 
  850. $posts[$key]['post_content'] = apply_filters('the_content', $posts[$key]['post_content']); 
  851.  
  852. // get thumbnail 
  853. $posts[$key]['post_image'] = $helper_articles->getImage($post); 
  854.  
  855. // set post status 
  856. $post_status_label = ''; 
  857. if(isset($post_statuses[$posts[$key]['post_status']])) { 
  858. $post_status_label = $post_statuses[$posts[$key]['post_status']]; 
  859. $posts[$key]['post_status'] = $post_status_label; 
  860. $result['posts'] = $posts; 
  861. $result['total'] = (int)$count['total']; 
  862. }else { 
  863. $result['msg'] = __('There are no posts corresponding to that search.', WYSIJA); 
  864. $result['result'] = false; 
  865.  
  866. return $result; 
/controllers/back/campaigns.php  
  1. class WYSIJA_control_back_campaigns extends WYSIJA_control_back { 
  2.  
  3. var $model = 'campaign'; 
  4. var $view = 'campaigns'; 
  5. var $list_columns = array('campaign_id', 'name', 'description'); 
  6. var $searchable = array('name', 'subject'); 
  7. var $filters = array(); 
  8. var $base_url = 'admin.php'; 
  9.  
  10. function __construct() { 
  11. global $wpdb; 
  12. parent::__construct(); 
  13. $this->wpdb = $wpdb; 
  14.  
  15. private function _wysija_subaction() { 
  16. if (isset($_REQUEST['subaction'])) { 
  17. if ($_REQUEST['subaction'] === 'delete') { 
  18. $this->_verify_nonce_subaction(); 
  19. if (isset($_REQUEST['imgid']) && (int) $_REQUEST['imgid'] > 0) { 
  20. // delete the image with id imgid 
  21. $res = wp_delete_attachment((int) $_REQUEST['imgid'], true); 
  22. if ($res) { 
  23. $this->notice(__('Image has been deleted.', WYSIJA)); 
  24. return true; 
  25.  
  26. private function _verify_nonce_subaction() { 
  27. if(!wp_verify_nonce($_REQUEST['_wpnonce'], $_REQUEST['page'].'-action_sub_delete_image') ) { 
  28. wp_die("<h2>" . __('Security failure during request') . "</h2>", __("Security Problem"), array( 
  29. 'response' => 403,  
  30. 'back_link' => false 
  31. )); 
  32.  
  33. private function _getLists($enabled = true, $count = false, $simple_query = false) { 
  34. $model_list = WYSIJA::get('list', 'model'); 
  35. //get lists which have users and are enabled */ 
  36. if ($enabled) { 
  37. $sql_enabled_condition = ' is_enabled>0 and'; 
  38. }else{ 
  39. $sql_enabled_condition = ''; 
  40.  
  41. $extra_sql = ''; 
  42. if (!$simple_query) { 
  43. $extra_sql = 'WHERE list_id in (SELECT distinct(list_id) from [wysija]user_list )'; 
  44.  
  45. $query = 'SELECT * FROM [wysija]list ' . $extra_sql; 
  46. $listres = $model_list->query('get_res', $query); 
  47.  
  48. if ($count) { 
  49. $model_config = WYSIJA::get('config', 'model'); 
  50. $condition = '>='; 
  51. if ($model_config->getValue('confirm_dbleoptin')) 
  52. $condition = '>'; 
  53. $qry1 = "SELECT count(distinct A.user_id) as nbsub, A.list_id FROM `[wysija]user_list` as A LEFT JOIN `[wysija]user` as B on A.user_id=B.user_id WHERE B.status $condition 0 and A.unsub_date=0 GROUP BY list_id"; 
  54.  
  55. $total = $model_list->getResults($qry1); 
  56.  
  57. foreach ($total as $tot) { 
  58. foreach ($listres as $key => $res) { 
  59. if ($tot['list_id'] == $res['list_id']) 
  60. $listres[$key]['count'] = $tot['nbsub']; 
  61. foreach ($listres as $key => $res) { 
  62. if (!isset($res['count'])) 
  63. $listres[$key]['count'] = 0; 
  64. return $listres; 
  65.  
  66. /** 
  67. * Welcome page first time install 
  68. * @return boolean 
  69. */ 
  70. function welcome_new() { 
  71. $this->title = $this->viewObj->title = __('Welcome Page!', WYSIJA); 
  72. $this->jsTrans['instalwjp'] = __('Installing MailPoet Newsletter Premium plugin', WYSIJA); 
  73. $helper_readme = WYSIJA::get('readme', 'helper'); 
  74. $helper_readme->scan(); 
  75. $this->data = array(); 
  76. $this->data['abouttext'] = __('A Brand New MailPoet. Let the Fun Begin.', WYSIJA); 
  77.  
  78. $model_config = WYSIJA::get('config', 'model'); 
  79. $is_multisite = is_multisite(); 
  80. $is_network_admin = WYSIJA::current_user_can('manage_network'); 
  81. if ($is_multisite && $is_network_admin) { 
  82. $model_config->save(array('ms_wysija_whats_new' => WYSIJA::get_version())); 
  83. } else { 
  84. $model_config->save(array('wysija_whats_new' => WYSIJA::get_version())); 
  85.  
  86. //add a new language code with a new video 
  87. $video_language=array(); 
  88. $video_language['en_EN'] = '<iframe src="//player.vimeo.com/video/130224536" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; 
  89.  
  90. $wp_lang = get_locale(); 
  91. if (!empty($wp_lang) && isset($video_language[$wp_lang])) { 
  92. $welcome_video_link = $video_language[$wp_lang]; 
  93. } else { 
  94. $welcome_video_link = $video_language['en_EN']; 
  95.  
  96. $this->data['sections'][] = array( 
  97. 'title' => __('Stay up to date! Subscribe to our newsletters', WYSIJA) . '<span id="poll_result"></span>',  
  98. 'format' => 'normal',  
  99. 'paragraphs' => array('<div class="mpoet-update-subscribe" ><h4></h4><div class="mpoet-update-subscribe-left"> <p>'.__('We send a monthly newsletter with the following:', WYSIJA).'</p>' . 
  100. '<ul>' . 
  101. '<li>'.__('Important plugin updates', WYSIJA).'</li>' . 
  102. '<li>'.__('Coupons', WYSIJA).'</li>' . 
  103. '<li>'.__('Tips for you, or your customers', WYSIJA).'</li>' . 
  104. '<li>'.__('What we*re working on', WYSIJA).'</li>' . 
  105. '<li>'.__('News from us, the team', WYSIJA).'</li>' . 
  106. '</ul> 
  107. <p>View <a target="_blank" href="http://www.mailpoet.com/?wysija-page=1&controller=email&action=view&email_id=1181&wysijap=subscriptions-3">an example blog post email</a> and <a target="_blank" href="http://www.mailpoet.com/?wysija-page=1&controller=email&action=view&email_id=64&wysijap=subscriptions-2">an example newsletter</a>.</p> 
  108. </div>' . 
  109. '<div class="mpoet-update-subscribe-right">' . 
  110.  
  111. '<iframe width="380" scrolling="no" frameborder="0" src="http://www.mailpoet.com/?wysija-page=1&controller=subscribers&action=wysija_outter&wysija_form=5&external_site=1&wysijap=subscriptions-3" class="iframe-wysija" vspace="0" tabindex="0" style="position: static; top: 0pt; margin: 0px; border-style: none; height: 180px; left: 0pt; visibility: visible; background-color: #f1f1f1!important;" marginwidth="0" marginheight="0" hspace="0" allowtransparency="true" title="Subscription Wysija"></iframe> 
  112. </div> 
  113. <div style="clear:both;"></div> 
  114.  
  115. </div>',  
  116. ); 
  117.  
  118. $this->data['sections'][]=array( 
  119. 'title'=>__('First Time? See it in Action', WYSIJA),  
  120. 'format'=>'normal',  
  121. 'paragraphs'=>array( 
  122. __('You can start by watching this video by one of our users.', WYSIJA),  
  123. $welcome_video_link 
  124. ); 
  125.  
  126. // Check if user is already sharing data, and hide the share link. 
  127. if (!$model_config->getValue('analytics')) { 
  128. $share_section = array( 
  129. 'title' => __('Share your data', WYSIJA),  
  130. 'content' => str_replace( 
  131. array('[link]', '[/link]', '[ajaxlink]', '[/ajaxlink]'), array('<a title="Anonymous Data" target="_blank" href="http://support.mailpoet.com/knowledgebase/share-your-data/?utm_source=wpadmin&utm_campaign=welcome_page">', '</a>', '<a id="share_analytics" href="javascript:;">', '</a>'), __("We know too little about our users. We're looking for [link]anonymous data[/link] to build a better plugin. [ajaxlink]Yes, count me in![/ajaxlink]", WYSIJA)) 
  132. ); 
  133. } else { 
  134. $share_section = array( 
  135. 'title' => __('Share your data', WYSIJA),  
  136. 'content' => str_replace( 
  137. array('[link]', '[/link]'), array('<a title="Anonymous Data" target="_blank" href="http://support.mailpoet.com/knowledgebase/share-your-data/?utm_source=wpadmin&utm_campaign=welcome_page">', '</a>', '<a id="share_analytics" href="javascript:;">', '</a>'), __("We know too little about our users. We're looking for [link]anonymous data[/link] to build a better plugin. Thanks, you're already sharing!", WYSIJA)) 
  138. ); 
  139.  
  140. $this->data['sections'][] = array( 
  141. 'title' => __('What You Can Do', WYSIJA),  
  142. 'cols' => array( 
  143. array( 
  144. 'title' => __('5 minute newbie guide', WYSIJA),  
  145. 'content' => __('Your MailPoet comes with an example newsletter. You\'ll see it when you close this welcome page. Edit it to start playing with it.', WYSIJA) 
  146. ),  
  147. $share_section,  
  148. array( 
  149. 'title' => __('Help yourself. Or let us help you.', WYSIJA),  
  150. 'content' => str_replace( 
  151. array('[link]', '[/link]'), array('<a href="http://support.mailpoet.com/" target="_blank" title="On our blog!">', '</a>'), __('We got documentation and a ticket system on [link]support.mailpoet.com[/link]. We answer within 24h.', WYSIJA)) 
  152. ),  
  153. 'format' => 'three-col',  
  154. ); 
  155.  
  156. $this->viewObj->skip_header = true; 
  157.  
  158. return true; 
  159.  
  160. /** 
  161. * Welcome page for updaters 
  162. * @return boolean 
  163. */ 
  164. function whats_new() { 
  165.  
  166. $this->title = $this->viewObj->title = __('What\'s new?', WYSIJA); 
  167. $this->jsTrans['instalwjp'] = __('Installing MailPoet Newsletter Premium plugin', WYSIJA); 
  168. wp_enqueue_style('wysija-admin-css-premium', WYSIJA_URL.'css/admin-premium.css', array(), WYSIJA::get_version()); 
  169.  
  170. $this->viewObj->skip_header = true; 
  171. return true; 
  172.  
  173.  
  174.  
  175. /** START prem check hook */ 
  176.  
  177. // when curl or any php remote function not available mailpoet.com returns lcheck to that function 
  178. function licok() { 
  179. parent::__construct(); 
  180. $dt = get_option('wysijey'); 
  181.  
  182. if (isset($_REQUEST['xtz']) && $dt === $_REQUEST['xtz']) { 
  183. $dataconf = array( 
  184. 'premium_key' => base64_encode(get_option('home') . time()),  
  185. 'premium_val' => time(),  
  186. 'premium_expire_at' => (int)$_REQUEST['expire_at'] 
  187. ); 
  188. $this->notice(__('Premium version is valid for your site.', WYSIJA)); 
  189. } else { 
  190. $dataconf = array('premium_key' => '', 'premium_val' => ''); 
  191. if(!empty($_REQUEST['expire_at'])) { 
  192. $dataconf['premium_expire_at'] = (int)$_REQUEST['expire_at']; 
  193. }else{ 
  194. $url_premium = 'http://www.mailpoet.com/checkout/?wysijadomain=' . $dt . '&nc=1&utm_source=wpadmin&utm_campaign=error_licence_activation'; 
  195. $this->error(str_replace(array('[link]', '[/link]'), array('<a href="' . $url_premium . '" target="_blank">', '</a>'), __('Premium licence does not exist for your site. Purchase it [link]here[/link].', WYSIJA)), 1); 
  196.  
  197. WYSIJA::update_option('wysicheck', false); 
  198. $modelConf = WYSIJA::get('config', 'model'); 
  199. $modelConf->save($dataconf); 
  200.  
  201. $this->redirect('admin.php?page=wysija_config#tab-premium'); 
  202.  
  203. /** END prem check hook */ 
  204.  
  205. function validateLic() { 
  206. $helpLic = WYSIJA::get('licence', 'helper'); 
  207. $res = $helpLic->check(); 
  208.  
  209. $this->redirect(); 
  210.  
  211. /** 
  212. * this function is triggered when sending manually the emails with the "Don't wait and send right now" button 
  213. * @param type $dataPost 
  214. */ 
  215. function manual_send($dataPost = false) { 
  216. $this->requireSecurity(); 
  217. $modelQ = WYSIJA::get('queue', 'model'); 
  218. $config = WYSIJA::get('config', 'model'); 
  219. if ((int) $config->getValue('total_subscribers') < 2000) { 
  220. if ($modelQ->count() > 0) { 
  221. $helperQ = WYSIJA::get('queue', 'helper'); 
  222. $emailid = false; 
  223. if ($_REQUEST['emailid']) { 
  224. $emailid = (int)$_REQUEST['emailid']; 
  225. $helperQ->process($emailid); 
  226. } else { 
  227. echo '<strong style="font-family: Arial; font-weight: bold; font-size: 12px;">' . __('Queue is empty!', WYSIJA) . '</strong>'; 
  228. exit; 
  229. } else { 
  230. //deprecated 
  231. do_action('wysija_send_test_editor'); 
  232.  
  233. do_action('wysija_manual_send'); 
  234.  
  235. exit; 
  236.  
  237. /** 
  238. * test the bounce handling maybe this should move somewhere else like config controller 
  239. * @return boolean 
  240. */ 
  241. function test_bounce() { 
  242. // bounce handling 
  243. $helper_bounce = WYSIJA::get('bounce', 'helper'); 
  244.  
  245. // in a multisite case we process first the bounce recording into the bounce table 
  246. if (is_multisite()) { 
  247. $helper_bounce->record_bounce_ms(); 
  248.  
  249. // then we take actions from what has been returned by the bounce 
  250. $helper_bounce->process_bounce_ms(); 
  251. } else { 
  252. $helper_bounce->process_bounce(); 
  253. exit; 
  254.  
  255. function add($dataPost = false) { 
  256. $this->title = sprintf(__('Step %1$s', WYSIJA), 1); 
  257. $this->js[] = 'wysija-validator'; 
  258.  
  259. $this->js[] = 'wysija-edit-autonl'; 
  260. $this->js['admin-campaigns-edit'] = 'admin-campaigns-edit'; 
  261. $this->jsTrans['descauto'] = str_replace(array('[newsletter:number]', '[newsletter:total]', '[newsletter:post_title]'), array('<b>[newsletter:number]</b>', '<b>[newsletter:total]</b>', '<b>[newsletter:post_title]</b>'), __('Insert [newsletter:total] to show number of posts, [newsletter:post_title] to show the latest post\'s title & [newsletter:number] to display the issue number.', WYSIJA)); 
  262. $this->jsTrans['descstandard'] = __('The first thing your subscribers see. Be creative and increase your open rate!', WYSIJA); 
  263. $this->immediateWarning(); 
  264. $this->viewObj->title = __('First step: main details', WYSIJA); 
  265. $this->viewShow = 'add'; 
  266. $this->data = array(); 
  267. $this->data['campaign'] = array('name' => '', 'description' => ''); 
  268. $modelConfig = WYSIJA::get('config', 'model'); 
  269. $this->data['email'] = array('subject' => '', 'from_email' => $modelConfig->getValue('from_email'), 'from_name' => $modelConfig->getValue('from_name')); 
  270. $this->data['lists'] = $this->_getLists(false, true, true); 
  271.  
  272. $this->dataAutoNl(); 
  273. $this->jsLoc['admin-campaigns-edit']['autofields'] = $this->data['autonl']['fields']; 
  274.  
  275. /** 
  276. * get the fields and fields value necessary when dealing with automatic newsletters 
  277. */ 
  278. function dataAutoNl() { 
  279. $dataFrequencyNoImmediate = $dataFrequency = array('daily' => __('once a day at...', WYSIJA),  
  280. 'weekly' => __('weekly on...', WYSIJA),  
  281. 'monthly' => __('monthly on the...', WYSIJA),  
  282. 'monthlyevery' => __('monthly every...', WYSIJA),  
  283. 'immediate' => __('immediately.', WYSIJA)); 
  284.  
  285. unset($dataFrequencyNoImmediate['immediate']); 
  286.  
  287. $times = array(); 
  288. $time = strtotime('00:00:00'); 
  289. $toolboxH = WYSIJA::get('toolbox', 'helper'); 
  290. $times['00:00:00'] = $toolboxH->localtime($time); 
  291.  
  292. for ($i = 1; $i < 24; $i++) { 
  293. $time = strtotime('+ 1hour', $time); 
  294. $key = date('H:i:s', $time); 
  295. $times[$key] = $toolboxH->localtime($time); 
  296.  
  297. $daysvalues = $toolboxH->getday(); 
  298.  
  299. $numberweeks = $toolboxH->getweeksnumber(); 
  300. $daynumbers = $toolboxH->getdaynumber(); 
  301.  
  302.  
  303. $dataLists = array(); 
  304.  
  305. foreach ($this->data['lists'] as $datal) { 
  306. if ($datal['is_enabled']) 
  307. $dataLists[$datal['list_id']] = $datal['name']; 
  308.  
  309. // Get all available roles 
  310. $wptoolsH = WYSIJA::get('wp_tools', 'helper'); 
  311. $roles = $wptoolsH->wp_get_all_roles(); 
  312. $available_roles = array('any' => __('in any WordPress role', WYSIJA)); 
  313. foreach ($roles as $role => $name) { 
  314. $available_roles[$role] = $name; 
  315.  
  316. $this->data['autonl']['fields'] = array( 
  317. 'event' => array( 
  318. 'values' => array( 
  319. 'new-articles' => __('When there\'s new content...', WYSIJA),  
  320. 'subs-2-nl' => __('When someone subscribes to the list...', WYSIJA),  
  321. 'new-user' => __('When a new WordPress user is added to your site...', WYSIJA),  
  322. ),  
  323. 'valueshow' => array( 
  324. 'new-articles' => array('when-article'),  
  325. 'subs-2-nl' => array('subscribetolist', 'numberafter', 'numberofwhat', 'unique_send'),  
  326. 'new-user' => array('roles', 'numberafter', 'numberofwhat', 'unique_send'),  
  327. ),  
  328. 'style' => 'width:300px;' 
  329. ),  
  330. 'when-article' => array( 
  331. 'values' => $dataFrequency,  
  332. 'valueshow' => array( 
  333. 'daily' => array('time'),  
  334. 'weekly' => array('dayname', 'time'),  
  335. 'monthly' => array('daynumber', 'time'),  
  336. 'monthlyevery' => array('dayevery', 'dayname', 'time'),  
  337. ),  
  338. 'subscribetolist' => array( 
  339. 'values' => $dataLists,  
  340. 'style' => 'width:300px;' 
  341. ),  
  342. 'roles' => array( 
  343. 'values' => $available_roles 
  344. ),  
  345. 'numberafter' => array( 
  346. 'type' => 'input',  
  347. 'style' => 'width:35px;',  
  348. 'class' => 'validate[required, custom[integer], min[1]]',  
  349. ),  
  350. 'numberofwhat' => array( 
  351. 'values' => array( 
  352. 'immediate' => __('immediately.', WYSIJA),  
  353. 'hours' => __('hour(s) after.', WYSIJA),  
  354. 'days' => __('day(s) after.', WYSIJA),  
  355. 'weeks' => __('week(s) after.', WYSIJA) 
  356. ),  
  357. 'valuesunit' => array( 
  358. 'immediate' => __('immediately', WYSIJA),  
  359. 'hours' => __('hour(s)', WYSIJA),  
  360. 'days' => __('day(s)', WYSIJA),  
  361. 'weeks' => __('week(s)', WYSIJA) 
  362. ),  
  363. ),  
  364. 'dayevery' => array( 
  365. 'values' => $numberweeks,  
  366. ),  
  367. 'dayname' => array( 
  368. 'values' => $daysvalues,  
  369. ),  
  370. 'daynumber' => array( 
  371. 'values' => $daynumbers,  
  372. ),  
  373. 'time' => array( 
  374. 'values' => $times,  
  375. ),  
  376. /** 'unique_send'=>array( 
  377. 'label_before'=>__('Send this email only once.', WYSIJA),  
  378. 'type'=>'checkbox' 
  379. ), */ 
  380. ); 
  381. $helpersEvent = WYSIJA::get('autonews', 'helper'); 
  382. $extraEvents = $helpersEvent->events(); 
  383.  
  384. /** if there are plugin to add autonewsletter event they are adding their customized field over here */ 
  385. if ($extraEvents) { 
  386. foreach ($extraEvents as $k => $v) { 
  387.  
  388. $this->data['autonl']['fields']['event']['values'][$k] = $v['title']; 
  389. foreach ($v['fields'] as $fieldCKEY => $fieldCVAL) { 
  390. if (isset($this->data['autonl']['fields'][$fieldCKEY])) 
  391. continue; 
  392. $this->data['autonl']['fields']['event']['valueshow'][$k] = array_keys($v['fields']); 
  393.  
  394.  
  395. function edit($dataPost = false) { 
  396. if (!$this->_checkEmailExists($_REQUEST['id'])) 
  397. return; 
  398. $this->add(); 
  399.  
  400. $modelEmail = WYSIJA::get('email', 'model'); 
  401.  
  402. $this->data['email'] = $modelEmail->getOne(false, array('email_id' => $_REQUEST['id'])); 
  403.  
  404. if ($this->data['email']['status'] > 0) { 
  405. $this->redirect(); 
  406. $this->title = sprintf(__('Step %1$s', WYSIJA), 1) . ' | ' . $this->data['email']['subject']; 
  407. $modelCamp = WYSIJA::get('campaign', 'model'); 
  408. $this->data['campaign'] = $modelCamp->getOne(false, array('campaign_id' => $this->data['email']['campaign_id'])); 
  409.  
  410. $modelCL = WYSIJA::get('campaign_list', 'model'); 
  411. $this->data['campaign_list'] = $modelCL->get(false, array('campaign_id' => $this->data['email']['campaign_id'])); 
  412.  
  413. function editTemplate() { 
  414. // make sure the editor content is not cached 
  415. header('Cache-Control: no-cache, max-age=0, must-revalidate, no-store'); // HTTP/1.1 
  416. header('Expires: Fri, 9 Mar 1984 00:00:00 GMT'); 
  417.  
  418. if (!$this->_checkEmailExists($_REQUEST['id'])) 
  419. return; 
  420. $this->viewShow = 'editTemplate'; 
  421.  
  422. wp_enqueue_style('thickbox'); 
  423.  
  424. $wjEngine = WYSIJA::get('wj_engine', 'helper'); 
  425. /** WJ editor translations */ 
  426. $this->jsTrans = array_merge($this->jsTrans, $wjEngine->getTranslations(), $wjEngine->getApplicationData()); 
  427.  
  428. $this->jsTrans['savingnl'] = __('Saving newsletter...', WYSIJA); 
  429. $this->jsTrans['errorsavingnl'] = __('Error Saving newsletter...', WYSIJA); 
  430. $this->jsTrans['savednl'] = __('Newsletter has been saved.', WYSIJA); 
  431. $this->jsTrans['previewemail'] = __('Sending preview...', WYSIJA); 
  432. $this->jsTrans['spamtestresult'] = __('Spam test results', WYSIJA); 
  433.  
  434. /** WJ editor JS */ 
  435. $this->js[] = 'wysija-editor'; 
  436. $this->js[] = 'wysija-admin-ajax-proto'; 
  437. $this->js[] = 'wysija-admin-ajax'; 
  438. $this->js[] = 'wysija-base-script-64'; 
  439. $this->js[] = 'media-upload'; 
  440. $this->js['admin-campaigns-editDetails'] = 'admin-campaigns-editDetails'; 
  441. $modelEmail = WYSIJA::get('email', 'model'); 
  442. $this->data = array(); 
  443. $this->data['email'] = $modelEmail->getOne(false, array('email_id' => $_REQUEST['id'])); 
  444.  
  445. $this->checkIsEditable(); 
  446.  
  447. $this->viewObj->title = sprintf(__('Second step: "%1$s"', WYSIJA), $this->data['email']['subject']); 
  448. $this->title = sprintf(__('Step %1$s', WYSIJA), 2) . " | " . $this->data['email']['subject']; 
  449.  
  450. // check if html source is enabled in the config (this will add the "html source" button in tinymce) 
  451. $model_config = WYSIJA::get('config', 'model'); 
  452. $this->jsTrans['html_source_enabled'] = (int) $model_config->getValue('html_source'); 
  453.  
  454. function checkIsEditable() { 
  455. if ( 
  456. !($this->data['email'] == 2 || isset($this->data['email']['params']['schedule']['isscheduled'])) && $this->data['email']['status'] > 0 
  457. ) { 
  458. $this->redirect(); 
  459.  
  460. function pause() { 
  461. /** pause the campaign entry */ 
  462. $this->requireSecurity(); 
  463. if (isset($_REQUEST['id']) && $_REQUEST['id']) { 
  464. $modelEmail = WYSIJA::get('email', 'model'); 
  465. $myemail = $modelEmail->getOne(false, array('email_id' => $_REQUEST['id'])); 
  466. $modelEmail->reset(); 
  467. $modelEmail->columns['modified_at']['autoup'] = 1; 
  468. $modelEmail->update(array('status' => -1), array('email_id' => $_REQUEST['id'])); 
  469.  
  470. if ($myemail['type'] == 2) { 
  471. return $this->redirect('admin.php?page=wysija_campaigns&id=' . $myemail['email_id'] . '&action=edit'); 
  472. } else { 
  473. $this->notice(__('Sending is now paused.', WYSIJA)); 
  474.  
  475. $this->redirect(); 
  476.  
  477. function resume() { 
  478. /** pause the campaign entry */ 
  479. $this->requireSecurity(); 
  480. if (isset($_REQUEST['id']) && $_REQUEST['id']) { 
  481. $modelEmail = WYSIJA::get('email', 'model'); 
  482. $modelEmail->columns['modified_at']['autoup'] = 1; 
  483. $modelEmail->update(array('status' => 99), array('email_id' => $_REQUEST['id'])); 
  484. $this->notice(__('Sending has resumed.', WYSIJA)); 
  485.  
  486. $this->redirect(); 
  487.  
  488. function duplicate() { 
  489. /** 1 - copy the campaign entry */ 
  490. $this->requireSecurity(); 
  491. $model = WYSIJA::get( 'campaign', 'model' ); 
  492. $query = 'INSERT INTO `[wysija]campaign` (`name`, `description`) 
  493. SELECT concat("' . $this->wpdb->_real_escape( __( 'Copy of ', WYSIJA ) ) . '", `name`), `description` FROM [wysija]campaign 
  494. WHERE campaign_id=' . (int) $_REQUEST['id']; 
  495. $campaignid = $model->query( $query ); 
  496.  
  497. /** 2 - copy the email entry */ 
  498. $query = 'INSERT INTO `[wysija]email` (`campaign_id`, `subject`, `body`, `type`, `params`, `wj_data`, `wj_styles`, `from_email`, `from_name`, `replyto_email`, `replyto_name`, `attachments`, `status`, `created_at`, `modified_at`) 
  499. SELECT ' . $campaignid . ', concat("' . $this->wpdb->_real_escape( __( 'Copy of ', WYSIJA ) ) . '", `subject`), `body`, `type`, `params`, `wj_data`, `wj_styles`, `from_email`, `from_name`, `replyto_email`, `replyto_name`, `attachments`, 0, ' . time() . ', ' . time() . ' FROM [wysija]email 
  500. WHERE email_id=' . (int) $_REQUEST['email_id']; 
  501. $emailid = $model->query( $query ); 
  502.  
  503. //let's reset the count of total childs for auto newsletter 
  504. $mEmail = WYSIJA::get( 'email', 'model' ); 
  505. $emailData = $mEmail->getOne( false, array( 'email_id' => $emailid ) ); 
  506.  
  507. if ( $emailData['type'] == 1 ) { 
  508. $params = $emailData['params']; 
  509.  
  510. if ( isset( $params['schedule'] ) ) { 
  511. $date_scheduled = strtotime( $params['schedule']['day'] . ' ' . $params['schedule']['time'] ); 
  512.  
  513. if ( $date_scheduled === false || $date_scheduled < time() ) { 
  514. unset( $params['schedule'] ); 
  515. $mEmail->update( array( 'params' => $params ), array( 'email_id' => $emailid ) ); 
  516. } elseif ( $emailData['type'] == 2 ) { 
  517. $paramsReseted = $emailData['params']; 
  518. if ( isset( $paramsReseted['autonl']['total_child'] ) ) { 
  519. $paramsReseted['autonl']['total_child'] = 0; 
  520.  
  521. if ( isset( $paramsReseted['autonl']['nextSend'] ) ) { 
  522. $paramsReseted['autonl']['nextSend'] = 0; 
  523.  
  524. if ( isset( $paramsReseted['autonl']['firstSend'] ) ) { 
  525. unset( $paramsReseted['autonl']['firstSend'] ); 
  526.  
  527. if ( isset( $paramsReseted['autonl']['lastSend'] ) ) { 
  528. unset( $paramsReseted['autonl']['lastSend'] ); 
  529.  
  530. if ( isset( $paramsReseted['autonl']['articles']['ids'] ) ) { 
  531. unset( $paramsReseted['autonl']['articles']['ids'] ); 
  532.  
  533. $mEmail->update( array( 'params' => $paramsReseted ), array( 'email_id' => $emailid ) ); 
  534.  
  535. /** 3 - copy the campaign_list entry */ 
  536. $query = "INSERT INTO `[wysija]campaign_list` (`campaign_id`, `list_id`, `filter`) 
  537. SELECT $campaignid, `list_id`, `filter` FROM [wysija]campaign_list 
  538. WHERE campaign_id=" . (int) $_REQUEST['id']; 
  539. $model->query( $query ); 
  540.  
  541. $this->notice( __( 'The newsletter has been duplicated.', WYSIJA ) ); 
  542.  
  543. $this->redirect( 'admin.php?page=wysija_campaigns&id=' . $emailid . '&action=edit' ); 
  544.  
  545. function immediateWarning() { 
  546. $model_config = WYSIJA::get('config', 'model'); 
  547. $is_multisite = is_multisite(); 
  548.  
  549. //$is_multisite=true;//PROD comment that line 
  550. if ($is_multisite && $model_config->getValue('sending_method') == 'network') { 
  551. $sending_emails_each = $model_config->getValue('ms_sending_emails_each'); 
  552. $number = $model_config->getValue('ms_sending_emails_number'); 
  553. } else { 
  554. $sending_emails_each = $model_config->getValue('sending_emails_each'); 
  555. $number = $model_config->getValue('sending_emails_number'); 
  556.  
  557. $formsHelp = WYSIJA::get('forms', 'helper'); 
  558.  
  559. $timespan = $formsHelp->eachValuesSec[$sending_emails_each]; 
  560. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  561.  
  562. $this->immediatewarning = str_replace( 
  563. array('[link]', '[/link]', '[settings]'), array('<a href="#">', '</a>', sprintf(__('%1$s emails every %2$s', WYSIJA), $number, trim($helper_toolbox->duration_string($timespan, true)))), __('Your sending settings ([settings]) can\'t send that quickly to [number] subscribers. Expect delivery delays. [link]Read more[/link]', WYSIJA)); 
  564. $this->viewObj->immediatewarning = '<span class="warning-msg" id="immediatewarning">' . $this->immediatewarning . '</span>'; 
  565.  
  566. $this->jsTrans['immediatewarning'] = $this->immediatewarning; 
  567.  
  568. //how many emails can be sent in 12 hours 
  569. //if the frequency is less than 12hours 
  570. if ($timespan < 43200) { 
  571. $ratio = floor(43200 / $timespan); 
  572. $this->jsTrans['possibleemails'] = $ratio * $number; 
  573. } else { 
  574. if ($timespan == 43200) { 
  575. $this->jsTrans['possibleemails'] = $number; 
  576. } else { 
  577. $ratio = floor($timespan / 43200); 
  578. $this->jsTrans['possibleemails'] = $number / $ratio; 
  579.  
  580. function editDetails() { 
  581. if (!$this->_checkEmailExists($_REQUEST['id'])) 
  582. return; 
  583.  
  584. $this->viewObj->title = __('Final step: last details', WYSIJA); 
  585. $this->viewShow = 'editDetails'; 
  586. $this->js[] = 'wysija-validator'; 
  587. $this->jsTrans['previewemail'] = __('Sending preview...', WYSIJA); 
  588. $this->jsTrans['pickadate'] = __('Pick a date', WYSIJA); 
  589. $this->jsTrans['saveclose'] = __('Save & close', WYSIJA); 
  590. $this->jsTrans['sendlater'] = __('Send later', WYSIJA); 
  591.  
  592. $this->jsTrans['schedule'] = __('Schedule', WYSIJA); 
  593.  
  594. $this->jsTrans['emailCheck'] = WJ_Utils::get_tip_data(); 
  595.  
  596.  
  597. $this->js[] = 'jquery-ui-datepicker'; 
  598. $this->js[] = 'wysija-tooltip'; 
  599.  
  600. $model_list = WYSIJA::get('list', 'model'); 
  601. $model_list->limitON = false; 
  602. $this->data = array(); 
  603. $this->data['lists'] = $this->_getLists(false, true, true); 
  604.  
  605. $model_email = WYSIJA::get('email', 'model'); 
  606. $this->data['email'] = $model_email->getOne(false, array('email_id' => $_REQUEST['id'])); 
  607.  
  608. // The first newsletter, we don't have replyto_email and replyto_name 
  609. if (empty($this->data['email']['replyto_email']) || empty($this->data['email']['replyto_name'])) { 
  610. $current_user = wp_get_current_user(); 
  611. $this->data['email']['replyto_email'] = $current_user->data->user_email; 
  612. $this->data['email']['replyto_name'] = $current_user->data->display_name; 
  613.  
  614. if ((int) $this->data['email']['type'] == 2) { 
  615. $this->js['wysija-edit-autonl'] = 'wysija-edit-autonl'; 
  616. $this->jsTrans['autonl'] = true; 
  617. $this->immediateWarning(); 
  618. $this->jsTrans['send'] = __('Activate now', WYSIJA); 
  619. } else { 
  620. $this->jsTrans['autonl'] = true; 
  621. $this->viewObj->immediatewarning = ''; 
  622. $this->jsTrans['send'] = __('Send', WYSIJA); 
  623.  
  624. if ((int) $this->data['email']['type'] == 1) { 
  625. $this->jsTrans['alertsend'] = __('You are about to send this newsletter. Please confirm.', WYSIJA); 
  626. } else { 
  627. if (isset($this->data['email']['params']['autonl']['event']) && $this->data['email']['params']['autonl']['event'] == 'subs-2-nl') { 
  628. $this->data['autoresponder'] = 1; 
  629. foreach ($this->data['lists'] as $list) { 
  630. if ($list['list_id'] == $this->data['email']['params']['autonl']['subscribetolist']) { 
  631. break; 
  632.  
  633. $this->jsTrans['ignoreprevious'] = sprintf(__('Are you sure you want to ignore the %1$s subscribers of the list %2$s?', WYSIJA), '"' . $list['count'] . '"', '"' . $list['name'] . '"'); 
  634.  
  635. $this->checkIsEditable(); 
  636.  
  637. $this->title = sprintf(__('Step %1$s', WYSIJA), 3) . " | " . $this->data['email']['subject']; 
  638. $this->dataAutoNl(); 
  639.  
  640. $this->jsLoc['wysija-edit-autonl']['autofields'] = $this->data['autonl']['fields']; 
  641.  
  642. $modelCL = WYSIJA::get('campaign_list', 'model'); 
  643. $this->data['campaign_list'] = $modelCL->get(false, array('campaign_id' => $this->data['email']['campaign_id'])); 
  644.  
  645. function delete() { 
  646. $this->requireSecurity(); 
  647.  
  648. $campaign_ids = array(); 
  649. if(isset($_REQUEST['id'])) $campaign_ids[] = $_REQUEST['id']; 
  650. if(isset($_REQUEST['campaign']['campaign_id'])) $campaign_ids[] = $_REQUEST['campaign']['campaign_id']; 
  651. if(isset($_REQUEST['wysija']['campaign']['campaign_id'][0])) { 
  652. $campaign_ids = array_merge($campaign_ids, $_REQUEST['wysija']['campaign']['campaign_id']); 
  653.  
  654. if (!empty($campaign_ids)) { 
  655. foreach($campaign_ids as $campaign_id) { 
  656. if($campaign_id > 0) { 
  657. $model_campaign = WYSIJA::get('campaign', 'model'); 
  658. $model_campaign->delete(array('campaign_id' => $campaign_id)); 
  659.  
  660. $model_campaign_list = WYSIJA::get('campaign_list', 'model'); 
  661. $model_campaign_list->delete(array('campaign_id' => $campaign_id)); 
  662.  
  663. $modelEmail = WYSIJA::get('email', 'model'); 
  664. $modelEmail->delete(array('campaign_id' => $campaign_id)); 
  665.  
  666. $this->notice(_n(__('Newsletter deleted.', WYSIJA), __('Newsletters deleted.', WYSIJA), count($campaign_ids), WYSIJA)); 
  667. } else { 
  668. $this->notice(__('Newsletter can\'t be deleted.', WYSIJA)); 
  669.  
  670. // retrieve saved filter 
  671. if (!empty($_REQUEST['action'])) 
  672. unset($_REQUEST['action']); 
  673. if (!empty($_REQUEST['id'])) 
  674. unset($_REQUEST['id']); 
  675. if (!empty($_REQUEST['_wpnonce'])) 
  676. unset($_REQUEST['_wpnonce']); 
  677. $redirect = $this->base_url . '?' . http_build_query($_REQUEST); 
  678. $this->redirect($redirect); 
  679.  
  680. /** 
  681. * this function is to delete an email that belongs to a campaign 
  682. * when we have a post notification all emails belong to the same campaign 
  683. * we don't want to delete an entire campaign when we delete a single email 
  684. */ 
  685. function deleteEmail() { 
  686. $this->requireSecurity(); 
  687. if(!$this->_checkEmailExists($_REQUEST['id'])) return; 
  688.  
  689. if(isset($_REQUEST['id'])) { 
  690. $modelEmail=WYSIJA::get('email', 'model'); 
  691. $modelEmail->delete(array('email_id'=>$_REQUEST['id'])); 
  692. $this->notice(__('Newsletter deleted.', WYSIJA)); 
  693. }else{ 
  694. $this->notice(__('Newsletter can\'t be deleted.', WYSIJA)); 
  695.  
  696. $this->redirect(); 
  697.  
  698. function savecamp() { 
  699. $this->redirectAfterSave = false; 
  700. $this->requireSecurity(); 
  701. /** update email */ 
  702. $data = array(); 
  703. // in case the newsletter already exists 
  704. if (isset($_REQUEST['id'])) { 
  705. $modelEmail = WYSIJA::get('email', 'model'); 
  706. $modelEmail->fieldValid = false; 
  707. $emaildataarr = $modelEmail->getOne(false, array('email_id' => $_REQUEST['id'])); 
  708.  
  709. $model_campaign = WYSIJA::get('campaign', 'model'); 
  710. $model_campaign->update(array('name' => $_POST['wysija']['email']['subject'], 'description' => ''), array('campaign_id' => $emaildataarr['campaign_id'])); 
  711.  
  712. $campaign_id = $emaildataarr['campaign_id']; 
  713. $email_id = $emaildataarr['email_id']; 
  714. $dataEmail = array( 
  715. 'campaign_id' => $campaign_id,  
  716. 'subject' => $_POST['wysija']['email']['subject'],  
  717. 'type' => $_POST['wysija']['email']['type']); 
  718.  
  719. if((int)$dataEmail['type'] === 2) { 
  720. // set autonl params 
  721. $dataEmail['params'] = array('autonl' => $_POST['wysija']['email']['params']['autonl']); 
  722.  
  723. // WTF? 
  724. if(!isset($newparams['autonl']['unique_send'])) { 
  725. unset($dataEmail['params']['autonl']['unique_send']); 
  726. } else { 
  727. $dataEmail['params']['autonl']['unique_send'] = true; 
  728.  
  729. // check if the newsletter used to be an automatic newsletter (if ) 
  730. if((int)$dataEmail['type'] === 1 && (int)$emaildataarr['type'] === 2) { 
  731. // make sure we remove any kind of auto-post block 
  732. $helper_autonews = WYSIJA::get('autonews', 'helper'); 
  733. $updated_email_data = $helper_autonews->remove_autopost_blocks($emaildataarr['wj_data']); 
  734. if($updated_email_data !== false) { 
  735. // if the email data has been changed, make sure to update it in the DB 
  736. $dataEmail['wj_data'] = $updated_email_data; 
  737.  
  738. $modelEmail->columns['modified_at']['autoup'] = 1; 
  739. $modelEmail->debugupdate = true; 
  740. $dataEmail['email_id'] = $_REQUEST['id']; 
  741.  
  742. if(isset($_REQUEST['save-reactivate'])) { 
  743. //if the button save and reactivate has been clicked then we reactivate and redirect to the newsletter page 
  744. $dataEmail['status'] = 99; 
  745. $_REQUEST['return'] = 1; 
  746.  
  747. $data['email']['email_id'] = $modelEmail->update($dataEmail, array('email_id' => (int)$_REQUEST['id'])); 
  748. } else { 
  749. // get default theme 
  750. $model_config = WYSIJA::get('config', 'model'); 
  751. $default_theme = $model_config->getValue('newsletter_default_theme', 'default'); 
  752.  
  753. $helper_themes = WYSIJA::get('themes', 'helper'); 
  754. $theme_data = $helper_themes->getData($default_theme); 
  755.  
  756. // get campaign data 
  757. $model_campaign = WYSIJA::get('campaign', 'model'); 
  758. $campaign_id = $model_campaign->insert(array('name' => $_POST['wysija']['email']['subject'], 'description' => '')); 
  759.  
  760. $modelEmail = WYSIJA::get('email', 'model'); 
  761. $modelEmail->fieldValid = false; 
  762. $emaildata = array( 
  763. 'campaign_id' => $campaign_id,  
  764. 'subject' => $_POST['wysija']['email']['subject'],  
  765. 'type' => (int) $_POST['wysija']['email']['type'] 
  766. ); 
  767.  
  768.  
  769. // create autonl parameters if necessary 
  770. if ((int) $_POST['wysija']['email']['type'] === 2 && isset($_POST['wysija']['email']['params']['autonl'])) { 
  771. $emaildata['params'] = array('autonl' => $_POST['wysija']['email']['params']['autonl']); 
  772.  
  773. // create sample data depending on newsletter's type 
  774. if ((int) $_POST['wysija']['email']['type'] === 2 && $_POST['wysija']['email']['params']['autonl']['event'] === 'new-articles') { 
  775.  
  776. // if immediate, post_limit is set to 1 
  777. if ($emaildata['params']['autonl']['when-article'] === 'immediate') { 
  778. $autopostParams = array( 
  779. array('key' => 'category_ids', 'value' => null),  
  780. array('key' => 'title_tag', 'value' => 'h2'),  
  781. array('key' => 'title_alignment', 'value' => 'left'),  
  782. array('key' => 'title_position', 'value' => 'inside'),  
  783. array('key' => 'image_alignment', 'value' => 'alternate'),  
  784. array('key' => 'image_width', 'value' => 325),  
  785. array('key' => 'post_content', 'value' => 'excerpt'),  
  786. array('key' => 'readmore', 'value' => base64_encode(__('Read more.', WYSIJA))),  
  787. array('key' => 'show_divider', 'value' => 'yes'),  
  788. array('key' => 'post_limit', 'value' => 1),  
  789. array('key' => 'post_type', 'value' => 'post'),  
  790. array('key' => 'author_show', 'value' => 'no'),  
  791. array('key' => 'author_label', 'value' => base64_encode(__('Author:', WYSIJA))),  
  792. array('key' => 'category_show', 'value' => 'no'),  
  793. array('key' => 'category_label', 'value' => base64_encode(__('Categories:', WYSIJA))),  
  794. array('key' => 'nopost_message', 'value' => base64_encode(__('Latest content already sent.', WYSIJA))),  
  795. array('key' => 'bgcolor1', 'value' => null),  
  796. array('key' => 'bgcolor2', 'value' => null),  
  797. array('key' => 'sort_by', 'value' => 'newest') 
  798. ); 
  799. } else { 
  800. $autopostParams = array( 
  801. array('key' => 'category_ids', 'value' => null),  
  802. array('key' => 'title_tag', 'value' => 'h2'),  
  803. array('key' => 'title_alignment', 'value' => 'left'),  
  804. array('key' => 'title_position', 'value' => 'inside'),  
  805. array('key' => 'image_alignment', 'value' => 'alternate'),  
  806. array('key' => 'image_width', 'value' => 325),  
  807. array('key' => 'post_content', 'value' => 'excerpt'),  
  808. array('key' => 'readmore', 'value' => base64_encode(__('Read more.', WYSIJA))),  
  809. array('key' => 'show_divider', 'value' => 'yes'),  
  810. array('key' => 'post_limit', 'value' => 2),  
  811. array('key' => 'post_type', 'value' => 'post'),  
  812. array('key' => 'author_show', 'value' => 'no'),  
  813. array('key' => 'author_label', 'value' => base64_encode(__('Author:', WYSIJA))),  
  814. array('key' => 'category_show', 'value' => 'no'),  
  815. array('key' => 'category_label', 'value' => base64_encode(__('Categories:', WYSIJA))),  
  816. array('key' => 'nopost_message', 'value' => base64_encode(__('Latest content already sent.', WYSIJA))),  
  817. array('key' => 'bgcolor1', 'value' => null),  
  818. array('key' => 'bgcolor2', 'value' => null),  
  819. array('key' => 'sort_by', 'value' => 'newest') 
  820. ); 
  821.  
  822. // sample data for post notifications 
  823. $newwjdata = array( 
  824. 'version' => WYSIJA::get_version(),  
  825. 'header' => array( 
  826. 'text' => NULL,  
  827. 'image' => array( 
  828. 'src' => WYSIJA_EDITOR_IMG . 'transparent.png',  
  829. 'width' => 600,  
  830. 'height' => 86,  
  831. 'alignment' => 'center',  
  832. 'static' => true,  
  833. ),  
  834. 'alignment' => 'center',  
  835. 'static' => true,  
  836. 'type' => 'header' 
  837. ),  
  838. 'body' => array( 
  839. 'block-1' => array( 
  840. 'text' => array( 
  841. 'value' => '<h3 class="align-right">' . sprintf(__("The posts below were added with the widget %sAutomatic latest content%s", WYSIJA), '<strong>', '</strong>') . '</h3>' 
  842. ),  
  843. 'image' => array( 
  844. 'src' => WYSIJA_EDITOR_IMG . 'default-newsletter/autonewsletter/arrow-up.png',  
  845. 'width' => 45,  
  846. 'height' => 45,  
  847. 'alignment' => 'right',  
  848. 'static' => false 
  849. ),  
  850. 'alignment' => 'right',  
  851. 'static' => false,  
  852. 'position' => '1',  
  853. 'type' => 'content' 
  854. ),  
  855. 'block-2' => array( 
  856. 'text' => array( 
  857. 'value' => '<h3>' . sprintf(__('%sTo edit%s, mouse over to show edit button below.', WYSIJA), '<strong>', '</strong>') . '</h3>' 
  858. ),  
  859. 'image' => array( 
  860. 'src' => WYSIJA_EDITOR_IMG . 'default-newsletter/autonewsletter/arrow-down.png',  
  861. 'width' => 150,  
  862. 'height' => 53,  
  863. 'alignment' => 'left',  
  864. 'static' => false 
  865. ),  
  866. 'alignment' => 'left',  
  867. 'static' => false,  
  868. 'position' => '2',  
  869. 'type' => 'content' 
  870. ),  
  871. 'block-3' => array( 
  872. 'params' => $autopostParams,  
  873. 'position' => '3',  
  874. 'type' => 'auto-post' 
  875. ),  
  876. 'footer' => array( 
  877. 'text' => NULL,  
  878. 'image' => array( 
  879. 'src' => WYSIJA_EDITOR_IMG . 'transparent.png',  
  880. 'width' => 600,  
  881. 'height' => 86,  
  882. 'alignment' => 'center',  
  883. 'static' => true,  
  884. ),  
  885. 'alignment' => 'center',  
  886. 'static' => true,  
  887. 'type' => 'footer' 
  888. ); 
  889. } else { 
  890. if(!isset($emaildata['params'])) { 
  891. $emaildata['params'] = array(); 
  892.  
  893. $emaildata['params']['quickselection'] = array( 
  894. 'wp-301' => array( 
  895. 'identifier' => 'wp-301',  
  896. 'width' => 281,  
  897. 'height' => 190,  
  898. 'url' => WYSIJA_EDITOR_IMG . 'default-newsletter/newsletter/pigeon.png',  
  899. 'thumb_url' => WYSIJA_EDITOR_IMG . 'default-newsletter/newsletter/pigeon-150x150.png' 
  900. ); 
  901.  
  902. if($theme_data['divider'] === null) { 
  903. // default theme does not exist anymore or there is no divider associated to the theme 
  904. // we need to get the default divider in this case 
  905. $helper_dividers = WYSIJA::get('dividers', 'helper'); 
  906. $default_divider = $helper_dividers->getDefault(); 
  907. } else { 
  908. // set default divider 
  909. $default_divider = $theme_data['divider']; 
  910. // set default divider in email parameters 
  911. $emaildata['params']['divider'] = $default_divider; 
  912.  
  913. // get bookmarks from iconset 2 
  914. $helper_bookmarks = WYSIJA::get('bookmarks', 'helper'); 
  915. $bookmarks = $helper_bookmarks->getAllByIconset('medium', '02'); 
  916.  
  917. // sample data for regular newsletter 
  918. $newwjdata = array( 
  919. 'version' => WYSIJA::get_version(),  
  920. 'header' => array( 
  921. 'text' => null,  
  922. 'image' => array( 
  923. // 'src' => WYSIJA_EDITOR_IMG.'default-newsletter/newsletter/header.png',  
  924. 'src' => WYSIJA_EDITOR_IMG . 'transparent.png',  
  925. 'width' => 600,  
  926. 'height' => 86,  
  927. 'alignment' => 'center',  
  928. 'static' => true 
  929. ),  
  930. 'alignment' => 'center',  
  931. 'static' => true,  
  932. 'type' => 'header' 
  933. ),  
  934. 'body' => array( 
  935. 'block-1' => array( 
  936. 'text' => array( 
  937. 'value' => '<h2><strong>' . __('Step 1:', WYSIJA) . '</strong> ' . __('hey, click on this text!', WYSIJA) . '</h2>' . '<p>' . __('To edit, simply click on this block of text.', WYSIJA) . '</p>' 
  938. ),  
  939. 'image' => null,  
  940. 'alignment' => 'left',  
  941. 'static' => false,  
  942. 'position' => 1,  
  943. 'type' => 'content' 
  944. ),  
  945. 'block-2' => array_merge(array( 
  946. 'position' => 2,  
  947. 'type' => 'divider' 
  948. ),  
  949. $default_divider 
  950. ),  
  951. 'block-3' => array( 
  952. 'text' => array( 
  953. 'value' => '<h2><strong>' . __('Step 2:', WYSIJA) . '</strong> ' . __('play with this image', WYSIJA) . '</h2>' 
  954. ),  
  955. 'image' => null,  
  956. 'alignment' => 'left',  
  957. 'static' => false,  
  958. 'position' => 3,  
  959. 'type' => 'content' 
  960. ),  
  961. 'block-4' => array( 
  962. 'text' => array( 
  963. 'value' => '<p>' . __('Position your mouse over the image to the left.', WYSIJA) . '</p>' 
  964. ),  
  965. 'image' => array( 
  966. 'src' => WYSIJA_EDITOR_IMG . 'default-newsletter/newsletter/pigeon.png',  
  967. 'width' => 281,  
  968. 'height' => 190,  
  969. 'alignment' => 'left',  
  970. 'static' => false 
  971. ),  
  972. 'alignment' => 'left',  
  973. 'static' => false,  
  974. 'position' => 4,  
  975. 'type' => 'content' 
  976. ),  
  977. 'block-5' => array_merge(array( 
  978. 'position' => 5,  
  979. 'type' => 'divider' 
  980. ), $default_divider 
  981. ),  
  982. 'block-6' => array( 
  983. 'text' => array( 
  984. 'value' => '<h2><strong>' . __('Step 3:', WYSIJA) . '</strong> ' . __('drop content here', WYSIJA) . '</h2>' . 
  985. '<p>' . sprintf(__('Drag and drop %1$stext, posts, dividers.%2$s Look on the right!', WYSIJA), '<strong>', '</strong>') . '</p>' . 
  986. '<p>' . sprintf(__('You can even %1$ssocial bookmarks%2$s like these:', WYSIJA), '<strong>', '</strong>') . '</p>' 
  987. ),  
  988. 'image' => null,  
  989. 'alignment' => 'left',  
  990. 'static' => false,  
  991. 'position' => 6,  
  992. 'type' => 'content' 
  993. ),  
  994. 'block-7' => array( 
  995. 'width' => 184,  
  996. 'alignment' => 'center',  
  997. 'items' => array( 
  998. array_merge(array( 
  999. 'url' => 'http://www.facebook.com/mailpoetplugin',  
  1000. 'alt' => 'Facebook',  
  1001. 'cellWidth' => 61,  
  1002. 'cellHeight' => 32 
  1003. ), $bookmarks['facebook']),  
  1004. array_merge(array( 
  1005. 'url' => 'http://www.twitter.com/mail_poet',  
  1006. 'alt' => 'Twitter',  
  1007. 'cellWidth' => 61,  
  1008. 'cellHeight' => 32 
  1009. ), $bookmarks['twitter']),  
  1010. array_merge(array( 
  1011. 'url' => 'https://plus.google.com/+Mailpoet',  
  1012. 'alt' => 'Google',  
  1013. 'cellWidth' => 61,  
  1014. 'cellHeight' => 32 
  1015. ), $bookmarks['google']) 
  1016. ),  
  1017. 'position' => 7,  
  1018. 'type' => 'gallery' 
  1019. ),  
  1020. 'block-8' => array_merge(array( 
  1021. 'position' => 8,  
  1022. 'type' => 'divider' 
  1023. ), $default_divider 
  1024. ),  
  1025. 'block-9' => array( 
  1026. 'text' => array( 
  1027. 'value' => '<h2><strong>' . __('Step 4:', WYSIJA) . '</strong> ' . __('and the footer?', WYSIJA) . '</h2>' . 
  1028. '<p>' . sprintf(__('Change the footer\'s content in MailPoet\'s %1$sSettings%2$s page.', WYSIJA), '<strong>', '</strong>') . '</p>' 
  1029. ),  
  1030. 'image' => null,  
  1031. 'alignment' => 'left',  
  1032. 'static' => false,  
  1033. 'position' => 9,  
  1034. 'type' => 'content' 
  1035. ),  
  1036. 'footer' => array( 
  1037. 'text' => NULL,  
  1038. 'image' => array( 
  1039. // 'src' => WYSIJA_EDITOR_IMG.'default-newsletter/newsletter/footer.png',  
  1040. 'src' => WYSIJA_EDITOR_IMG . 'transparent.png',  
  1041. 'width' => 600,  
  1042. 'height' => 86,  
  1043. 'alignment' => 'center',  
  1044. 'static' => true,  
  1045. ),  
  1046. 'alignment' => 'center',  
  1047. 'static' => true,  
  1048. 'type' => 'footer' 
  1049. ); 
  1050.  
  1051. // set default styles 
  1052. $helper_engine = WYSIJA::get('wj_engine', 'helper'); 
  1053. $styles = $helper_engine->getDefaultStyles(); 
  1054. // end - set default styles 
  1055.  
  1056. // set theme specific data 
  1057. if($theme_data['header'] !== null) { 
  1058. $newwjdata['header'] = $theme_data['header']; 
  1059. if($theme_data['footer'] !== null) { 
  1060. $newwjdata['footer'] = $theme_data['footer']; 
  1061. if($theme_data['divider'] !== null) { 
  1062. $newwjdata['widgets'] = array('divider' => $theme_data['divider']); 
  1063. // end - set theme specific data 
  1064.  
  1065. $emaildata['wj_data'] = base64_encode(serialize($newwjdata)); 
  1066. $emaildata['wj_styles'] = base64_encode(serialize($styles)); 
  1067.  
  1068. $email_id = $data['email']['email_id'] = $modelEmail->insert($emaildata); 
  1069.  
  1070. $this->notice(__('Newsletter successfully created.', WYSIJA)); 
  1071.  
  1072. $this->_saveLists($campaign_id, true); 
  1073.  
  1074. if (isset($_REQUEST['return'])) 
  1075. $this->redirect(); 
  1076. else { 
  1077. $this->redirect('admin.php?page=wysija_campaigns&action=editTemplate&id=' . $email_id); 
  1078.  
  1079. function saveemail() { 
  1080. $this->redirectAfterSave = false; 
  1081. $this->requireSecurity(); 
  1082. $modelEmail = WYSIJA::get("email", "model"); 
  1083. $modelEmail->fieldValid = false; 
  1084. $emaildataarr = $modelEmail->getOne(array('email_id' => $_REQUEST['id'])); 
  1085.  
  1086. if (isset($_REQUEST['save-reactivate'])) { 
  1087. //if the button save and reactivate has been clicked then we reactivate and redirect to the newsletter page 
  1088. $dataEmail['status'] = 99; 
  1089. $_REQUEST['return'] = 1; 
  1090.  
  1091. if (isset($_REQUEST['return'])) 
  1092. $this->redirect(); 
  1093. else { 
  1094. $this->redirect('admin.php?page=wysija_campaigns&action=editDetails&id=' . $emaildataarr['email_id']); 
  1095.  
  1096. function savelast() { 
  1097. $this->redirectAfterSave = false; 
  1098. $post_notification = false; 
  1099. $this->requireSecurity(); 
  1100.  
  1101. if (!isset($_POST['wysija']['email']['from_name']) || !isset($_POST['wysija']['email']['from_email']) || !isset($_POST['wysija']['email']['replyto_name']) || !isset($_POST['wysija']['email']['replyto_email'])) { 
  1102. $this->error(__('Information is missing.', WYSIJA)); 
  1103. return $this->editDetails(); 
  1104. if (isset($_REQUEST['wysija']['email']['params']['googletrackingcode']) && $_REQUEST['wysija']['email']['params']['googletrackingcode'] && 
  1105. (!is_string($_REQUEST['wysija']['email']['params']['googletrackingcode']) OR 
  1106. preg_match('#[^a-z0-9_\-\s]#i', $_REQUEST['wysija']['email']['params']['googletrackingcode']) !== 0 )) { 
  1107. //force to simple text 
  1108. $_REQUEST['wysija']['email']['params']['googletrackingcode'] = preg_replace('#[^a-z0-9_\-\s]#i', '_', $_REQUEST['wysija']['email']['params']['googletrackingcode']); 
  1109. $this->error(__('Your Google Campaign can only contain latin characters, numbers, spaces and hyphens!', WYSIJA), 1); 
  1110. return $this->editDetails(); 
  1111.  
  1112. $update_email = array( 
  1113. 'email_id' => $_POST['wysija']['email']['email_id'],  
  1114. 'from_name' => $_POST['wysija']['email']['from_name'],  
  1115. 'from_email' => $_POST['wysija']['email']['from_email'],  
  1116. 'replyto_name' => $_POST['wysija']['email']['replyto_name'],  
  1117. 'replyto_email' => $_POST['wysija']['email']['replyto_email'],  
  1118. 'subject' => $_POST['wysija']['email']['subject'],  
  1119. ); 
  1120. $model_email = WYSIJA::get('email', 'model'); 
  1121. if (isset($_POST['wysija']['email']['params'])) 
  1122. $update_email['params'] = $_POST['wysija']['email']['params']; 
  1123.  
  1124. //insert into campaigns lists 
  1125. $this->_saveLists($_POST['wysija']['campaign']['campaign_id']); 
  1126. $email_data = $model_email->getOne($_POST['wysija']['email']['email_id']); 
  1127.  
  1128. // if we just save the draf we don't go through the big sending process setup 
  1129. if (isset($_POST['submit-draft']) || isset($_POST['submit-pause']) || (isset($_REQUEST['wj_redir']) && $_REQUEST['wj_redir'] == 'savelastback')) { 
  1130. if (isset($_POST['wysija']['email']['params']['schedule']['isscheduled'])) 
  1131. $this->notice(__('Newsletter has been scheduled.', WYSIJA)); 
  1132. else 
  1133. $this->notice(__('Newsletter has been saved as a draft.', WYSIJA)); 
  1134.  
  1135. if (isset($_POST['submit-draft'])) { 
  1136.  
  1137. $update_email['status'] = 0;// Email is being stored as draft 
  1138.  
  1139. if (isset($update_email['params']['schedule']['isscheduled'])) { 
  1140. // draft emails should not be scheduled, clear any schedules 
  1141. unset($update_email['params']['schedule']['isscheduled']); 
  1142. }else { 
  1143. // we update the param attribute with what's has been posted 
  1144. foreach ($update_email as $ki => $vi) { 
  1145. if ($ki == 'params') { 
  1146. foreach ($vi as $parake => $paraval) { 
  1147. $email_data['params'][$parake] = $paraval; 
  1148. $update_email[$ki] = $email_data[$ki]; 
  1149. else 
  1150. $email_data[$ki] = $vi; 
  1151.  
  1152. // if the checkbox to ignore retroactivity is here we just tell the class 
  1153. if (isset($_POST['wysija']['email']['ignore_subscribers'])) { 
  1154. $model_email->retro_active_autoresponders = false; 
  1155.  
  1156. // activate or send the email depending on the typ 
  1157. $model_email->send_activate($email_data); 
  1158.  
  1159. // update email 
  1160. $update_email['type'] = $email_data['type']; 
  1161.  
  1162. if ($post_notification) { 
  1163. $helper_autonews = WYSIJA::get('autonews', 'helper'); 
  1164. $update_email['params']['autonl']['nextSend'] = $helper_autonews->getNextSend($update_email); 
  1165.  
  1166. $model_email->reset(); 
  1167. $model_email->columns['modified_at']['autoup'] = 1; 
  1168.  
  1169. // re-render and save newsletter body (title may change during the last newsletter creation step) 
  1170. $wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  1171. // set data & styles 
  1172. $wj_engine->setData($email_data['wj_data'], true); 
  1173. $wj_engine->setStyles($email_data['wj_styles'], true); 
  1174. $email_data['subject'] = $_POST['wysija']['email']['subject']; 
  1175. $update_email['body'] = $wj_engine->renderEmail($email_data); 
  1176. // update some fields of the email 
  1177. $model_email->update($update_email); 
  1178.  
  1179. // update the campaign subject which ispretty much useless but good to keep in sync with the email 
  1180. $model_campaign = WYSIJA::get('campaign', 'model'); 
  1181. $model_campaign->reset(); 
  1182. $update_campaign = array('campaign_id' => $_REQUEST['id'], 'name' => $_POST['wysija']['email']['subject']); 
  1183. $model_campaign->update($update_campaign); 
  1184.  
  1185. if (isset($_REQUEST['wj_redir']) && $_REQUEST['wj_redir'] == 'savelastback') { 
  1186. return $this->redirect('admin.php?page=wysija_campaigns&action=editTemplate&id=' . $_POST['wysija']['email']['email_id']); 
  1187. else 
  1188. return $this->redirect(); 
  1189.  
  1190. function _saveLists($campaignId, $flagup = false) { 
  1191. //record the list that we have in that campaign 
  1192. $modelCampL = WYSIJA::get('campaign_list', 'model'); 
  1193. if ($flagup || (int) $campaignId > 0) { 
  1194. $modelCampL->delete(array('equal' => array('campaign_id' => $campaignId))); 
  1195. $modelCampL->reset(); 
  1196.  
  1197. if (isset($_POST['wysija']['campaign_list']['list_id'])) { 
  1198. //$modelCampL=WYSIJA::get("campaign_list", "model"); 
  1199. foreach ($_POST['wysija']['campaign_list']['list_id'] as $listid) { 
  1200. $modelCampL->insert(array('campaign_id' => $campaignId, "list_id" => $listid)); 
  1201.  
  1202. function _addLinkFilter($status, $type = 'status') { 
  1203. switch ($type) { 
  1204. case 'status': 
  1205. switch ($status) { 
  1206. case 'draft': 
  1207. $this->filters['equal'] = array('status' => 0); 
  1208. break; 
  1209. case 'sending': 
  1210. $this->filters['equal'] = array('status' => 99); 
  1211. break; 
  1212. case 'sent': 
  1213. $this->filters['equal'] = array('status' => 2); 
  1214. break; 
  1215. case 'paused': 
  1216. $this->filters['equal'] = array('status' => -1); 
  1217. break; 
  1218. case 'scheduled': 
  1219. $this->filters['equal'] = array('status' => 4); 
  1220. break; 
  1221. break; 
  1222. case 'type': 
  1223. switch ($status) { 
  1224. case 'regular': 
  1225. $this->filters['equal'] = array('type' => 1); 
  1226. break; 
  1227. case 'autonl': 
  1228. $this->filters['equal'] = array('type' => 2); 
  1229. break; 
  1230. break; 
  1231.  
  1232. /** 
  1233. * Get all campaigns, based on the filters 
  1234. */ 
  1235. protected function get_campaigns() { 
  1236. $order_by = ' ORDER BY '; 
  1237.  
  1238. if (isset($_REQUEST['orderby'])) { 
  1239. if (!is_string($_REQUEST['orderby']) OR preg_match('|[^a-z0-9#_.-]|i', $_REQUEST['orderby']) !== 0) { 
  1240. $_REQUEST['orderby'] = ''; 
  1241. if (!in_array(strtoupper($_REQUEST['ordert']), array('DESC', 'ASC'))) { 
  1242. $_REQUEST['ordert'] = 'DESC'; 
  1243. $order_by.=$_REQUEST['orderby'] . ' ' . $_REQUEST['ordert']; 
  1244. }else { 
  1245. $order_by.='FIELD(B.status, 99, 3, 1, 0, 2), '; 
  1246. $order_by.='B.status desc, '; 
  1247. $order_by.='B.modified_at desc, '; 
  1248. $order_by.='B.sent_at desc, '; 
  1249. $order_by.='B.type desc, '; 
  1250. $order_by.='A.' . $this->modelObj->getPk() . ' DESC'; 
  1251.  
  1252. $query = ' 
  1253. SELECT 
  1254. A.`campaign_id`,  
  1255. A.`name` as `campaign_name`,  
  1256. B.`subject` as `name`,  
  1257. A.`description`,  
  1258. B.`params`,  
  1259. B.`type`,  
  1260. B.`number_sent`,  
  1261. B.`number_opened`,  
  1262. B.`number_clicked`,  
  1263. B.`number_unsub`,  
  1264. (B.`number_sent` + 
  1265. B.`number_opened` + 
  1266. B.`number_clicked` + 
  1267. B.`number_unsub` + 
  1268. B.`number_bounce` + 
  1269. B.`number_forward` 
  1270. ) AS `number_total`,  
  1271. B.`status`,  
  1272. B.`created_at`,  
  1273. B.`modified_at`,  
  1274. B.`sent_at`,  
  1275. B.`email_id` 
  1276. FROM 
  1277. `[wysija]' . $this->modelObj->table_name . '` AS A 
  1278. LEFT JOIN 
  1279. `[wysija]email` AS B on A.`campaign_id` = B.`campaign_id` 
  1280. LEFT JOIN 
  1281. `[wysija]campaign_list` AS C on A.`campaign_id` = C.`campaign_id`'; 
  1282. $campaigns = $this->modelObj->getResults($query . $this->modelObj->makeWhere() . ' GROUP BY B.email_id' . $order_by . $this->modelObj->setLimit()); 
  1283.  
  1284. // calculate percetange of open / click / unsubscribe 
  1285. $helper_numbers = WYSIJA::get('numbers', 'helper'); 
  1286. foreach ($campaigns as &$campaign) { 
  1287. // open rate, based on sent number 
  1288. $campaign['rate_opened'] = $helper_numbers->calculate_percetage($campaign['number_opened'], $campaign['number_total'], 1); 
  1289. // click rate, based on opened number 
  1290. $campaign['rate_clicked'] = $helper_numbers->calculate_percetage($campaign['number_clicked'], $campaign['number_total'], 1); 
  1291. // unsubscribe rate, based on opened number 
  1292. $campaign['rate_unsub'] = $helper_numbers->calculate_percetage($campaign['number_unsub'], $campaign['number_total'], 1); 
  1293. return $campaigns; 
  1294.  
  1295. /** 
  1296. * Get the first campaign in history 
  1297. */ 
  1298. protected function get_oldest_compaign() { 
  1299. $query = ' 
  1300. SELECT 
  1301. MIN(B.created_at) as datemin 
  1302. FROM `[wysija]' . $this->modelObj->table_name . '` as A 
  1303. LEFT JOIN 
  1304. `[wysija]email` AS B on A.campaign_id = B.campaign_id 
  1305. LEFT JOIN 
  1306. `[wysija]campaign_list` as C on A.campaign_id = C.campaign_id'; 
  1307.  
  1308. return $this->modelObj->query('get_row', $query . $this->modelObj->makeWhere()); 
  1309.  
  1310. /** 
  1311. * Count ALL emails of each email-status 
  1312. * @todo: move to model 
  1313. */ 
  1314. protected function count_emails_by_status() { 
  1315. $query = ' 
  1316. SELECT 
  1317. COUNT(`email_id`) AS `campaigns`,  
  1318. `status` 
  1319. FROM 
  1320. `[wysija]email` 
  1321. WHERE 
  1322. `campaign_id` > 0 
  1323. GROUP BY `status`'; 
  1324.  
  1325. $countss = $this->modelObj->query('get_res', $query); 
  1326. $counts = array(); 
  1327. $total = 0; 
  1328.  
  1329. foreach ($countss as $count) { 
  1330. switch ($count['status']) { 
  1331. case '0': 
  1332. $type = 'draft'; 
  1333. break; 
  1334. case '1': 
  1335. case '3': 
  1336. case '99': 
  1337. $type = 'sending'; 
  1338. break; 
  1339. case '2': 
  1340. $type = 'sent'; 
  1341. break; 
  1342. case '-1': 
  1343. $type = 'paused'; 
  1344. break; 
  1345. case '4': 
  1346. $type = 'scheduled'; 
  1347. break; 
  1348. $total = $total + $count['campaigns']; 
  1349. $counts['status-' . $type] = $count['campaigns']; 
  1350. return $counts; 
  1351.  
  1352. /** 
  1353. * Count emails which matched the filters 
  1354. */ 
  1355. protected function count_emails() { 
  1356. $query = ' 
  1357. SELECT 
  1358. COUNT(DISTINCT B.`email_id`) AS `campaigns` 
  1359. FROM 
  1360. `[wysija]' . $this->modelObj->table_name . '` AS A 
  1361. LEFT JOIN 
  1362. `[wysija]email` AS B ON A.`campaign_id` = B.`campaign_id` 
  1363. LEFT JOIN 
  1364. `[wysija]campaign_list` AS C ON A.`campaign_id` = C.`campaign_id`'; 
  1365. return $this->modelObj->count($query . $this->modelObj->makeWhere(), 'campaigns'); 
  1366.  
  1367. /** 
  1368. * Count ALL emails of each type of email 
  1369. */ 
  1370. protected function count_emails_by_type() { 
  1371. $query = ' 
  1372. SELECT 
  1373. COUNT(`email_id`) AS `campaigns`,  
  1374. `type` 
  1375. FROM 
  1376. `[wysija]email` 
  1377. WHERE 
  1378. `campaign_id` > 0 
  1379. GROUP BY `type`'; 
  1380. $countss = $this->modelObj->query('get_res', $query, ARRAY_A); 
  1381. $counts = array(); 
  1382. foreach ($countss as $count) { 
  1383. switch ($count['type']) { 
  1384. case '1': 
  1385. $type = 'regular'; 
  1386. break; 
  1387. case '2': 
  1388. $type = 'autonl'; 
  1389. break; 
  1390. $counts['type-' . $type] = $count['campaigns']; 
  1391. return $counts; 
  1392.  
  1393. /** 
  1394. * Get all existing lists 
  1395. */ 
  1396. protected function get_lists() { 
  1397. $model_list = WYSIJA::get('list', 'model'); 
  1398. $query = ' 
  1399. SELECT 
  1400. A.`list_id`,  
  1401. A.`name`,  
  1402. A.`is_enabled`,  
  1403. COUNT( B.`campaign_id` ) AS `users` 
  1404. FROM 
  1405. `[wysija]' . $model_list->table_name . '` as A 
  1406. LEFT JOIN 
  1407. `[wysija]campaign_list` AS B on A.`list_id` = B.`list_id` 
  1408. GROUP BY A.`list_id`'; 
  1409. $result = $model_list->getResults($query); 
  1410. $lists = array(); 
  1411. foreach ($result as $list_obj) { 
  1412. $lists[$list_obj['list_id']] = $list_obj; 
  1413. return $lists; 
  1414.  
  1415. function defaultDisplay() { 
  1416. $this->data['base_url'] = $this->base_url . '?' . http_build_query($_REQUEST); // saved filter 
  1417. $this->title = __('Newsletters', WYSIJA); 
  1418. $this->viewShow = $this->action = 'main'; 
  1419. $this->js[] = 'wysija-admin-list'; 
  1420. $this->jsTrans["selecmiss"] = __('Please select a newsletter.', WYSIJA); 
  1421. $this->jsTrans['suredelete'] = __('Delete this newsletter for ever?', WYSIJA); 
  1422. $this->jsTrans['suredelete_bulk'] = __('Delete these newsletters for ever?', WYSIJA); 
  1423. $this->jsTrans['processqueue'] = __('Sending batch of emails...', WYSIJA); 
  1424. $this->jsTrans['viewnews'] = __('View newsletter', WYSIJA); 
  1425. $this->jsTrans['confirmpauseedit'] = __('The newsletter will be deactivated, you will need to reactivate it once you\'re over editing it. Do you want to proceed?', WYSIJA); 
  1426.  
  1427.  
  1428. //get the filters 
  1429. if (isset($_REQUEST['search']) && $_REQUEST['search']) { 
  1430. $this->filters['like'] = array(); 
  1431. foreach ($this->searchable as $field) 
  1432. $this->filters['like'][$field] = $_REQUEST['search']; 
  1433.  
  1434. if (isset($_REQUEST['filter-list']) && $_REQUEST['filter-list']) { 
  1435. $this->filters['equal'] = array('C.list_id' => $_REQUEST['filter-list']); 
  1436.  
  1437. if (isset($_REQUEST['filter-date']) && $_REQUEST['filter-date']) { 
  1438. $this->filters['greater_eq'] = array('created_at' => $_REQUEST['filter-date']); 
  1439. $this->filters['less_eq'] = array('created_at' => strtotime('+1 month', $_REQUEST['filter-date'])); 
  1440.  
  1441. $this->filters['is'] = array('type' => 'IS NOT NULL'); 
  1442.  
  1443.  
  1444. if (isset($_REQUEST['link_filter']) && $_REQUEST['link_filter']) { 
  1445. $linkfilters = explode('-', $_REQUEST['link_filter']); 
  1446.  
  1447. if (count($linkfilters) > 1) { 
  1448. $this->_addLinkFilter($linkfilters[1], $linkfilters[0]); 
  1449. } else { 
  1450. $this->_addLinkFilter($_REQUEST['link_filter']); 
  1451.  
  1452. $this->modelObj->noCheck = true; 
  1453. $this->modelObj->reset(); 
  1454. if ($this->filters) { 
  1455. $this->modelObj->setConditions($this->filters); 
  1456.  
  1457.  
  1458. // Count emails by status and type 
  1459. $emails_by_status = $this->count_emails_by_status(); 
  1460. $emails_by_type = $this->count_emails_by_type(); 
  1461. $counts = array_merge($emails_by_status, $emails_by_type); 
  1462. $counts['all'] = array_sum($emails_by_status); 
  1463.  
  1464. // collect data 
  1465. $this->data['campaigns'] = $this->get_campaigns(); 
  1466. $this->data['datemin'] = $this->get_oldest_compaign(); 
  1467. $lists = $this->get_lists(); // $lists is in use later within this scope 
  1468. $this->data['lists'] = $lists; 
  1469.  
  1470. // for paging 
  1471. $this->modelObj->countRows = $counts['all']; 
  1472. if ($this->filters) { 
  1473. $count_emails = $this->count_emails(); 
  1474. if( !empty($count_emails) ) { 
  1475. $this->modelObj->countRows = $count_emails; 
  1476.  
  1477. // count queue 
  1478. $email_ids = array(); 
  1479. foreach ($this->data['campaigns'] as $emailcamp) { 
  1480. if (in_array($emailcamp['status'], array(1, 3, 99))) 
  1481. $email_ids[] = $emailcamp['email_id']; 
  1482. $model_queue = WYSIJA::get('queue', 'model'); 
  1483. $model_queue->setConditions(array("email_id" => $email_ids)); 
  1484. $model_queue->groupBy('email_id'); 
  1485. $queue = $model_queue->count(); 
  1486. if ($queue) { 
  1487. $this->viewObj->queuedemails = $queue; 
  1488.  
  1489. $this->modelObj->reset(); 
  1490.  
  1491. //make a loop from the first created to now and increment an array of months 
  1492. $now = time(); 
  1493. $this->data['dates'] = array(); 
  1494.  
  1495. if ((int) $this->data['datemin']['datemin'] > 1) { 
  1496. setlocale(LC_TIME, 'en_US'); 
  1497. $formtlettres = "1 " . date('F', $this->data['datemin']['datemin']) . ' ' . date("Y", $this->data['datemin']['datemin']); 
  1498. $month_start = strtotime($formtlettres); 
  1499.  
  1500. if ($month_start > 0) { 
  1501. for ($i = $month_start; $i < $now; $i = strtotime('+1 month', $i)) { 
  1502. $this->data['dates'][$i] = date_i18n('F Y', $i); //date('F Y', $i); 
  1503.  
  1504.  
  1505.  
  1506. $campaign_ids_sent = $campaign_ids = array(); 
  1507. foreach ($this->data['campaigns'] as &$campaign) { 
  1508. $campaign_ids[] = $campaign['campaign_id']; 
  1509. $model_email = WYSIJA::get('email', 'model'); 
  1510. $model_email->getParams($campaign); 
  1511. if (in_array((int) $campaign['status'], array(-1, 1, 2, 3, 99))) 
  1512. $campaign_ids_sent[] = $campaign['campaign_id']; 
  1513.  
  1514. // 3 - campaign_list request & count request for queue */ 
  1515. if ($campaign_ids) { 
  1516. $model_campaign_list = WYSIJA::get('campaign_list', 'model'); 
  1517. $userlists = $model_campaign_list->get(array('list_id', 'campaign_id'), array('campaign_id' => $campaign_ids)); 
  1518.  
  1519. if ($campaign_ids_sent) { 
  1520. $model_campaign_list = WYSIJA::get("email_user_stat", "model"); 
  1521. $statstotal = $model_campaign_list->getResults("SELECT COUNT(A.user_id) as count, B.email_id FROM `[wysija]queue` as A 
  1522. JOIN `[wysija]email` as B on A.email_id=B.email_id 
  1523. WHERE B.campaign_id IN (" . implode(", ", $campaign_ids_sent) . ") group by B.email_id"); 
  1524.  
  1525. $senttotalgroupedby = $model_campaign_list->getResults("SELECT COUNT(A.user_id) as count, B.campaign_id, B.email_id, B.type, B.status, A.status as statususer FROM `[wysija]" . $model_campaign_list->table_name . "` as A 
  1526. JOIN `[wysija]email` as B on A.email_id=B.email_id 
  1527. WHERE B.campaign_id IN (" . implode(", ", $campaign_ids_sent) . ") group by A.status, B.email_id"); //, A.status 
  1528.  
  1529.  
  1530. $updateEmail = array(); 
  1531. $columnnamestatus = array(0 => "number_sent", 1 => "number_opened", 2 => "number_clicked", 3 => "number_unsub", -1 => "number_bounce"); 
  1532. foreach ($senttotalgroupedby as $sentbystatus) { 
  1533. if ($sentbystatus['statususer'] != "-2") 
  1534. $updateEmail[$sentbystatus['email_id']][$columnnamestatus[$sentbystatus['statususer']]] = $sentbystatus['count']; 
  1535. if (isset($senttotal[$sentbystatus['email_id']])) { 
  1536. $senttotal[$sentbystatus['email_id']]['count'] = (int) $senttotal[$sentbystatus['email_id']]['count'] + (int) $sentbystatus['count']; 
  1537. } else { 
  1538. unset($sentbystatus['statususer']); 
  1539. $senttotal[$sentbystatus['email_id']] = $sentbystatus; 
  1540.  
  1541. $model_email = WYSIJA::get('email', 'model'); 
  1542.  
  1543. foreach ($updateEmail as $emailid => $update) { 
  1544.  
  1545. foreach ($columnnamestatus as $v) { 
  1546. if (!isset($update[$v])) 
  1547. $update[$v] = 0; 
  1548.  
  1549. $model_email->update($update, array('email_id' => $emailid)); 
  1550. $model_email->reset(); 
  1551.  
  1552.  
  1553. $model_config = WYSIJA::get('config', 'model'); 
  1554. $running = false; 
  1555.  
  1556. $is_multisite = is_multisite(); 
  1557.  
  1558. if ($is_multisite && $model_config->getValue('sending_method') == 'network') { 
  1559. $sending_emails_each = $model_config->getValue('ms_sending_emails_each'); 
  1560. } else { 
  1561. $sending_emails_each = $model_config->getValue('sending_emails_each'); 
  1562.  
  1563. if ($model_config->getValue('cron_manual')) { 
  1564. $formsHelp = WYSIJA::get('forms', 'helper'); 
  1565. $queue_frequency = $formsHelp->eachValuesSec[$sending_emails_each]; 
  1566. $queue_scheduled = WYSIJA::get_cron_schedule('queue'); 
  1567.  
  1568. $next_scheduled_queue = $queue_scheduled['next_schedule']; 
  1569. $running = $queue_scheduled['running']; 
  1570.  
  1571. if ($running) { 
  1572. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  1573. $running = time() - $running; 
  1574. $running = $helper_toolbox->duration_string($running, true, 4); 
  1575. } else { 
  1576. $schedules = wp_get_schedules(); 
  1577. $queue_frequency = $schedules[wp_get_schedule('wysija_cron_queue')]['interval']; 
  1578. $next_scheduled_queue = wp_next_scheduled('wysija_cron_queue'); 
  1579.  
  1580.  
  1581.  
  1582. $status_sent_complete = array(); 
  1583. if (isset($senttotal) && $senttotal) { 
  1584. foreach ($senttotal as $sentot) { 
  1585. if ($sentot) { 
  1586. $this->data['sent'][$sentot['email_id']]['total'] = $sentot['count']; 
  1587. $this->data['sent'][$sentot['email_id']]['to'] = $sentot['count']; 
  1588. } else { 
  1589. $this->data['sent'][$sentot['email_id']]['total'] = $this->data['sent'][$sentot['email_id']]['to'] = 0; 
  1590. $this->data['sent'][$sentot['email_id']]['status'] = $sentot['status']; 
  1591. $this->data['sent'][$sentot['email_id']]['type'] = $sentot['type']; 
  1592. $this->data['sent'][$sentot['email_id']]['left'] = (int) $this->data['sent'][$sentot['email_id']]['total'] - (int) $this->data['sent'][$sentot['email_id']]['to']; 
  1593.  
  1594. foreach ($statstotal as $sentot) { 
  1595. if (!isset($this->data['sent'][$sentot['email_id']])) { 
  1596. $this->data['sent'][$sentot['email_id']]['total'] = 0; 
  1597. $this->data['sent'][$sentot['email_id']]['to'] = 0; 
  1598. $this->data['sent'][$sentot['email_id']]['total'] = $this->data['sent'][$sentot['email_id']]['total'] + $sentot['count']; 
  1599. $this->data['sent'][$sentot['email_id']]['left'] = (int) $this->data['sent'][$sentot['email_id']]['total'] - (int) $this->data['sent'][$sentot['email_id']]['to']; 
  1600.  
  1601. if ($is_multisite && $model_config->getValue('sending_method') == 'network') { 
  1602. $sending_emails_number = $model_config->getValue('ms_sending_emails_number'); 
  1603. } else { 
  1604. $sending_emails_number = $model_config->getValue('sending_emails_number'); 
  1605.  
  1606. if (isset($this->data['sent'])) { 
  1607. foreach ($this->data['sent'] as $key => &$camp) { 
  1608. if ($this->data['sent'][$key]['left'] > 0) { 
  1609. $cronsneeded = ceil($this->data['sent'][$key]['left'] / $sending_emails_number); 
  1610. $this->data['sent'][$key]['remaining_time'] = $cronsneeded * $queue_frequency; 
  1611. $this->data['sent'][$key]['running_for'] = $running; 
  1612. $this->data['sent'][$key]['next_batch'] = $next_scheduled_queue - time(); 
  1613. $this->data['sent'][$key]['remaining_time'] = $this->data['sent'][$key]['remaining_time'] - ($queue_frequency) + $this->data['sent'][$key]['next_batch']; 
  1614. } else { 
  1615. if ((in_array($this->data['sent'][$key]['status'], array(1, 3, 99))) && $this->data['sent'][$key]['type'] == 1) 
  1616. $status_sent_complete[] = $key; 
  1617.  
  1618.  
  1619. // status update to sent for the one that are sent 
  1620. if (count($status_sent_complete) > 0) { 
  1621. $model_email = WYSIJA::get('email', 'model'); 
  1622. $model_email->noCheck = true; 
  1623. $model_email->reset(); 
  1624. $model_email->update(array('status' => 2), array('equal' => array('email_id' => $status_sent_complete))); 
  1625.  
  1626. $this->data['counts'] = array_reverse($counts); 
  1627.  
  1628. // regrouping all the data in the same array 
  1629. foreach ($this->data['campaigns'] as &$campaign) { 
  1630. // default key while we don't have the data 
  1631. //TODO add data for stats about emails opened clicked etc 
  1632. $campaign["emails"] = 0; 
  1633. $campaign["opened"] = 0; 
  1634. $campaign["clicked"] = 0; 
  1635.  
  1636. if ($userlists) { 
  1637. foreach ($userlists as $key => $userlist) { 
  1638. if ($campaign["campaign_id"] == $userlist["campaign_id"] && isset($lists[$userlist["list_id"]])) { 
  1639. if (!isset($campaign["lists"])) 
  1640. $campaign["lists"] = $lists[$userlist["list_id"]]["name"]; 
  1641. else 
  1642. $campaign["lists"].=", " . $lists[$userlist["list_id"]]["name"]; 
  1643. if (isset($campaign["lists"]) && !$campaign["lists"]) 
  1644. unset($campaign["lists"]); 
  1645.  
  1646. if (((isset($campaign['params']['schedule']['isscheduled']) || 
  1647. ($campaign['type'] == 2 && isset($campaign['params']['autonl']['event']) && in_array($campaign['params']['autonl']['event'], array('new-articles'/** , 'subs-2-nl' */))) 
  1648. ) && $campaign['status'] != 2 && !isset($campaign["lists"])) || ($campaign['type'] == 2 && isset($campaign['params']['autonl']['event']) && in_array($campaign['params']['autonl']['event'], array('subs-2-nl')) && $campaign['status'] != 2 && (!isset($campaign['params']['autonl']['subscribetolist']) || !isset($lists[$campaign['params']['autonl']['subscribetolist']]) )) 
  1649. ) { 
  1650. $campaign['classRow'] = " listmissing "; 
  1651. $campaign['msgListEdit'] = '<strong>' . __('The list has been deleted.', WYSIJA) . '</strong>'; 
  1652. $campaign['msgSendSuspended'] = '<strong>' . __('Sending suspended.', WYSIJA) . '</strong>'; 
  1653.  
  1654. $this->dataAutoNl(); 
  1655. if (!$this->data['campaigns']) { 
  1656. $this->notice(__('There are no newsletters.', WYSIJA)); 
  1657.  
  1658. function setviewStatsfilter() { 
  1659. // get the filters 
  1660. $this->searchable = array("email", "firstname", "lastname"); 
  1661. $this->filters = array(); 
  1662. if (isset($_REQUEST['search']) && $_REQUEST['search']) { 
  1663. $this->filters["like"] = array(); 
  1664. foreach ($this->searchable as $field) 
  1665. $this->filters["like"][$field] = $_REQUEST['search']; 
  1666. $this->tableQuery = 'email_user_stat'; 
  1667. $this->statusemail = 'B.status as umstatus'; 
  1668. if (isset($_REQUEST['link_filter']) && $_REQUEST['link_filter']) { 
  1669. switch ($_REQUEST['link_filter']) { 
  1670. case 'inqueue': 
  1671. $this->tableQuery = 'queue'; 
  1672. $this->statusemail = '-2 as umstatus'; 
  1673. break; 
  1674. case 'sent': 
  1675. $this->filters['equal'] = array('B.status' => 0); 
  1676. break; 
  1677. case 'bounced': 
  1678. $this->filters['equal'] = array('B.status' => -1); 
  1679. break; 
  1680. case 'opened': 
  1681. $this->filters['equal'] = array('B.status' => 1); 
  1682. break; 
  1683. case 'clicked': 
  1684. $this->filters['equal'] = array('B.status' => 2); 
  1685. break; 
  1686. case 'unsubscribe': 
  1687. $this->filters['equal'] = array('B.status' => 3); 
  1688. break; 
  1689. case 'notsent': 
  1690. $this->filters['equal'] = array('B.status' => -2); 
  1691. break; 
  1692. // filter by url id 
  1693. if (isset($_REQUEST['url_id']) && (int) $_REQUEST['url_id'] > 0) { 
  1694. $this->tableQuery = 'email_user_url'; 
  1695. $this->filters['equal'] = array('B.url_id' => (int) $_REQUEST['url_id']); 
  1696. $this->statusemail = '2 as umstatus'; //by default, when filter by url_id, all subscribers had clicked 
  1697.  
  1698. function viewstats() { 
  1699. $this->js[] = 'wysija-admin-list'; 
  1700. $this->js[] = 'wysija-charts'; 
  1701. $this->viewShow = 'viewstats'; 
  1702.  
  1703. $this->modelObj = WYSIJA::get("email", "model"); 
  1704. $this->modelObj->limitON = false; 
  1705.  
  1706. $email_object = $this->modelObj->getOne(false, array("email_id" => $_REQUEST['id'])); 
  1707. if(empty($email_object)) { 
  1708. $this->redirect('admin.php?page=wysija_campaigns'); 
  1709. return; 
  1710. $this->viewObj->model = $this->modelObj; 
  1711. $this->viewObj->namecampaign = $email_object['subject']; 
  1712. $this->viewObj->title = sprintf(__('Stats : %1$s', WYSIJA), $email_object['subject']); 
  1713.  
  1714. $modelObjCamp = WYSIJA::get("campaign", "model"); 
  1715. $limit_pp = false; 
  1716. if (isset($modelObjCamp->limit_pp)) 
  1717. $limit_pp = $modelObjCamp->limit_pp; 
  1718. $modelObjCamp->limitON = false; 
  1719. $campaign = $modelObjCamp->getOne(false, array("campaign_id" => $email_object['campaign_id'])); 
  1720.  
  1721.  
  1722. $this->setviewStatsfilter(); 
  1723.  
  1724. $this->modelObj->reset(); 
  1725. $this->modelObj->noCheck = true; 
  1726.  
  1727. // 0 - counting request 
  1728. $queryCmmonStart = 'SELECT count(distinct B.user_id) as users FROM `[wysija]user` as A'; 
  1729. $queryCmmonStart.=' LEFT JOIN `[wysija]' . $this->tableQuery . '` as B on A.user_id=B.user_id'; 
  1730.  
  1731. // all the counts query 
  1732. $query = "SELECT count(user_id) as users, status FROM `[wysija]email_user_stat` as A 
  1733. WHERE A.email_id=" . $email_object['email_id'] . " GROUP BY status"; 
  1734. $countss = $this->modelObj->query("get_res", $query, ARRAY_A); 
  1735.  
  1736. // we also count what is in the queue 
  1737. $query = "SELECT count(user_id) as users FROM `[wysija]queue` as A 
  1738. WHERE A.email_id=" . $email_object['email_id']; 
  1739. $countss[-2]['status'] = -3; 
  1740. $countss[-2]['users'] = $this->modelObj->count($query, 'users'); 
  1741.  
  1742. $counts = array(); 
  1743. $truetotal = $total = 0; 
  1744.  
  1745. foreach ($countss as $count) { 
  1746. switch ($count['status']) { 
  1747. case "-3": 
  1748. $type = 'inqueue'; 
  1749. break; 
  1750. case "-2": 
  1751. $type = 'notsent'; 
  1752. break; 
  1753. case "-1": 
  1754. $type = 'bounced'; 
  1755. break; 
  1756. case "0": 
  1757. $type = 'sent'; 
  1758. break; 
  1759. case "1": 
  1760. $type = 'opened'; 
  1761. break; 
  1762. case "2": 
  1763. $type = 'clicked'; 
  1764. break; 
  1765. case "3": 
  1766. $type = 'unsubscribe'; 
  1767. break; 
  1768. if ($count['status'] != "-2") 
  1769. $total = $total + $count['users']; 
  1770. $truetotal = $truetotal + $count['users']; 
  1771. $counts[$type] = $count['users']; 
  1772.  
  1773. $counts['allsent'] = $total; 
  1774. $counts['all'] = $truetotal; 
  1775.  
  1776. $this->modelObj->reset(); 
  1777. $this->filters['equal']["B.email_id"] = $email_object['email_id']; 
  1778.  
  1779. $this->modelObj->noCheck = true; 
  1780. if ($this->filters) { 
  1781. $this->modelObj->setConditions($this->filters); 
  1782.  
  1783.  
  1784. // 1 - subscriber request 
  1785. $query = 'SELECT A.user_id, A.firstname, A.lastname, A.status as ustatus, ' . $this->statusemail . ' , A.email, B.* FROM `[wysija]user` as A'; 
  1786. $query.=' LEFT JOIN `[wysija]' . $this->tableQuery . '` as B on A.user_id=B.user_id'; 
  1787. $queryFinal = $this->modelObj->makeWhere(); 
  1788.  
  1789. // without filter we already have the total number of subscribers 
  1790. if ($this->filters) 
  1791. $this->modelObj->countRows = $this->modelObj->count($queryCmmonStart . $queryFinal, 'users'); 
  1792. else 
  1793. $this->modelObj->countRows = $counts['all']; 
  1794.  
  1795. $orderby = ''; 
  1796. /** 
  1797. * Until now, we have 
  1798. * - 3 possible values of $this->tableQuery (queue, email_user_url, email_user_stat), set by $this->setviewStatsfilter() 
  1799. * - 2 possible values of $_REQUEST['orderby'] 
  1800. * => 3x2 = 6 cases 
  1801. */ 
  1802. if (isset($_REQUEST['orderby'])) { 
  1803. switch ($this->tableQuery) { 
  1804. case 'email_user_url': 
  1805. case 'email_user_stat': 
  1806. if (!is_string($_REQUEST['orderby']) OR preg_match('|[^a-z0-9#_.-]|i', $_REQUEST['orderby']) !== 0) { 
  1807. $_REQUEST['orderby'] = ''; 
  1808. break; 
  1809. if (!in_array(strtoupper($_REQUEST['ordert']), array('DESC', 'ASC'))) { 
  1810. $_REQUEST['ordert'] = 'DESC'; 
  1811.  
  1812. $orderby = ' ORDER BY ' . $_REQUEST['orderby'] . ' ' . $_REQUEST['ordert']; 
  1813. break; 
  1814.  
  1815. case 'queue': 
  1816. default: 
  1817. $orderby .= ' ORDER BY A.user_id DESC'; 
  1818. break; 
  1819. } else { 
  1820. switch ($this->tableQuery) { 
  1821. case 'email_user_url': 
  1822. $orderby = ' ORDER BY B.clicked_at DESC, B.number_clicked DESC'; // by default, sort by last clicked and biggest hit 
  1823. break; 
  1824.  
  1825. case 'email_user_stat': 
  1826. $orderby = ' ORDER BY B.opened_at DESC, B.status DESC'; // by default, sort by last open and its staus value 
  1827. break; 
  1828.  
  1829. case 'queue': 
  1830. default: 
  1831. $orderby = ' ORDER BY A.user_id DESC'; 
  1832. break; 
  1833. $this->data['tableQuery'] = $this->tableQuery; 
  1834. $this->modelObj->limitON = true; 
  1835.  
  1836. $subscribers = array(); 
  1837. $hook_params = array( 
  1838. 'email_id' => $email_object['email_id'],  
  1839. 'url_id' => isset($_REQUEST['url_id']) && $_REQUEST['url_id'] ? $_REQUEST['url_id'] : false,  
  1840. 'subscribers' => &$subscribers,  
  1841. 'id' => $email_object['campaign_id'] 
  1842. ); 
  1843. $this->data['subscribers'] = $this->modelObj->getResults($query . $queryFinal . " GROUP BY A.user_id" . $orderby . $this->modelObj->setLimit(0, (int)$limit_pp)); 
  1844. $this->modelObj->reset(); 
  1845.  
  1846. // make the data object for the listing view 
  1847. $modelList = WYSIJA::get("list", "model"); 
  1848.  
  1849. // 2 - list request 
  1850. $query = "SELECT A.list_id, A.name, A.is_enabled, count( B.user_id ) AS users FROM `[wysija]" . $modelList->table_name . "` as A"; 
  1851. $query.=" LEFT JOIN `[wysija]user_list` as B on A.list_id = B.list_id"; 
  1852. $query.=" GROUP BY A.list_id"; 
  1853. $listsDB = $modelList->getResults($query); 
  1854.  
  1855. $lists = array(); 
  1856. foreach ($listsDB as $listobj) { 
  1857. $lists[$listobj["list_id"]] = $listobj; 
  1858.  
  1859. $listsDB = null; 
  1860.  
  1861. $user_ids = array(); 
  1862. foreach ($this->data['subscribers'] as $subscriber) { 
  1863. $user_ids[] = $subscriber['user_id']; 
  1864.  
  1865. // 3 - user_list request 
  1866. if ($user_ids) { 
  1867. $modeluList = WYSIJA::get("user_list", "model"); 
  1868. $userlists = $modeluList->get(array("list_id", "user_id"), array("user_id" => $user_ids)); 
  1869.  
  1870.  
  1871. $this->data['lists'] = $lists; 
  1872. $this->data['counts'] = array_reverse($counts); 
  1873.  
  1874. // regrouping all the data in the same array 
  1875. foreach ($this->data['subscribers'] as $keysus => $subscriber) { 
  1876. // default key while we don't have the data 
  1877. //TODO add data for stats about emails opened clicked etc 
  1878. $this->data['subscribers'][$keysus]["emails"] = 0; 
  1879. $this->data['subscribers'][$keysus]["opened"] = 0; 
  1880. $this->data['subscribers'][$keysus]["clicked"] = 0; 
  1881.  
  1882. if ($userlists) { 
  1883. foreach ($userlists as $key => $userlist) { 
  1884. if ($subscriber["user_id"] == $userlist["user_id"] && isset($lists[$userlist["list_id"]])) { 
  1885. if (!isset($this->data['subscribers'][$keysus]["lists"])) 
  1886. $this->data['subscribers'][$keysus]["lists"] = $lists[$userlist["list_id"]]["name"]; 
  1887. else 
  1888. $this->data['subscribers'][$keysus]["lists"].=", " . $lists[$userlist["list_id"]]["name"]; 
  1889.  
  1890. $this->data['email'] = $email_object; 
  1891.  
  1892. if (!$this->data['subscribers']) { 
  1893. $this->notice(__("Your request can't retrieve any subscribers. Change your filters!", WYSIJA)); 
  1894.  
  1895. // execute hooks 
  1896. $hook_params = array( 
  1897. 'email_id' => $_REQUEST['id'],  
  1898. 'email_object' => $email_object,  
  1899. 'url_id' => !empty($_REQUEST['url_id']) ? (int)$_REQUEST['url_id'] : null,  
  1900. 'id' => $email_object['campaign_id'] 
  1901. ); 
  1902.  
  1903. $this->data['hooks']['hook_newsletter_top'] = apply_filters('hook_newsletter_top', WYSIJA_module::execute_hook('hook_newsletter_top', $hook_params), $hook_params); 
  1904. $this->data['hooks']['hook_newsletter_bottom'] = apply_filters('hook_newsletter_bottom', WYSIJA_module::execute_hook('hook_newsletter_bottom', $hook_params), $hook_params); 
  1905.  
  1906. function getListSubscriberQry($selectcolumns) { 
  1907. $this->modelObj = WYSIJA::get("email", "model"); 
  1908. $this->emailObj = $this->modelObj->getOne(false, array('email_id' => $_REQUEST['id'])); 
  1909.  
  1910. // use the filter if there is 
  1911. $this->setviewStatsfilter(); 
  1912.  
  1913. if ($selectcolumns == "B.user_id") { 
  1914. //unset($this->filters["like"]); 
  1915.  
  1916. $this->filters['equal']["B.email_id"] = $this->emailObj['email_id']; 
  1917. $this->modelObj->noCheck = true; 
  1918. if ($this->filters) 
  1919. $this->modelObj->setConditions($this->filters); 
  1920.  
  1921. // select insert all the subscribers from that campaign into user_list 
  1922. if ($selectcolumns == "B.user_id") { 
  1923. $query = "SELECT $selectcolumns FROM `[wysija]" . $this->tableQuery . "` as B"; 
  1924. $query.=$this->modelObj->makeWhere(); 
  1925. } else { 
  1926. $query = "SELECT $selectcolumns FROM `[wysija]user` as A"; 
  1927. $query.=" LEFT JOIN `[wysija]" . $this->tableQuery . "` as B on A.user_id=B.user_id"; 
  1928. $query.=$this->modelObj->makeWhere(); 
  1929.  
  1930. return $query; 
  1931.  
  1932. function createnewlist() { 
  1933.  
  1934. $this->requireSecurity(); 
  1935. // get the email subject 
  1936. $emailModel = WYSIJA::get('email', 'model'); 
  1937. $email = $emailModel->getOne(array('subject'), array('email_id' => $_REQUEST['id'])); 
  1938.  
  1939. $this->modelObj->reset(); 
  1940.  
  1941. // set the name of the new list 
  1942. $prefix = ""; 
  1943. if (isset($_REQUEST['link_filter'])) 
  1944. $prefix = ' (' . $this->viewObj->getTransStatusEmail($_REQUEST['link_filter']) . ')'; 
  1945. $listname = sprintf(__('Segment of %1$s', WYSIJA), $email['subject'] . $prefix); 
  1946.  
  1947. // insert new list 
  1948. $modelL = WYSIJA::get('list', 'model'); 
  1949. $listid = $modelL->insert(array('is_enabled' => 1, 'name' => $listname, 'description' => __('List created based on a newsletter segment.', WYSIJA))); 
  1950.  
  1951. // get list of subscribers filtered or not 
  1952. $query = $this->getListSubscriberQry($listid . ', A.user_id, ' . time() . ', 0'); 
  1953.  
  1954. $query2 = 'INSERT INTO `[wysija]user_list` (`list_id`, `user_id`, `sub_date`, `unsub_date`) ' . $query; 
  1955.  
  1956. $this->modelObj->query($query2); 
  1957.  
  1958. $this->notice(sprintf(__('A new list "%1$s" has been created out of this segment.', WYSIJA), $listname)); 
  1959. $this->redirect('admin.php?page=wysija_campaigns&action=viewstats&id=' . $_REQUEST['id']); 
  1960.  
  1961. function unsubscribeall() { 
  1962. // Update user_list, set unsubdate and sub_date 
  1963. $query = $this->getListSubscriberQry('B.user_id'); 
  1964. $query1 = " 
  1965. UPDATE `[wysija]user_list` 
  1966. SET 
  1967. `unsub_date` = ".time().",  
  1968. `sub_date` = 0 
  1969. WHERE 
  1970. `user_id` IN ($query) 
  1971. AND `list_id` NOT IN (SELECT `list_id` FROM `[wysija]list` WHERE `is_enabled` < 1) 
  1972. "; 
  1973. $this->modelObj->query($query1); 
  1974.  
  1975. // unsubscribe from user where select from email_user_stat 
  1976. $query2 = "UPDATE `[wysija]user` SET `status`=-1 WHERE `user_id` IN ($query)"; 
  1977. $this->modelObj->query($query2); 
  1978.  
  1979. $this->notice(__('The segment has been unsubscribed from all the lists.', WYSIJA)); 
  1980. $this->redirect('admin.php?page=wysija_campaigns&action=viewstats&id=' . $_REQUEST['id']); 
  1981.  
  1982. function removequeue() { 
  1983. $this->requireSecurity(); 
  1984. // delete from queue where select from email_user_stat 
  1985. $query = $this->getListSubscriberQry('B.user_id'); 
  1986. $query2 = "DELETE FROM `[wysija]queue` where user_id IN ($query) AND email_id=" . $this->emailObj['email_id']; 
  1987. $this->modelObj->query($query2); 
  1988.  
  1989. $this->notice(__('The segment has been removed from the queue of this newsletter.', WYSIJA)); 
  1990. $this->redirect('admin.php?page=wysija_campaigns&action=viewstats&id=' . $_REQUEST['id']); 
  1991.  
  1992. function export() { 
  1993. $this->requireSecurity(); 
  1994. // select from email_user_stat left join user 
  1995. $query = $this->getListSubscriberQry('B.user_id'); 
  1996. $result = $this->modelObj->query('get_res', $query); 
  1997. $user_ids = array(); 
  1998. foreach ($result as $user) { 
  1999. $user_ids[] = $user['user_id']; 
  2000.  
  2001. $helper_file = WYSIJA::get('file', 'helper'); 
  2002. $tempfilename = $helper_file->temp(implode(', ', $user_ids), 'export_userids', '.txt'); 
  2003.  
  2004. $wpnonce = '&_wpnonce='.WYSIJA_view::secure(array('controller' => 'wysija_subscribers' , 'action' => 'exportcampaign' ), true); 
  2005.  
  2006. $this->redirect('admin.php?page=wysija_subscribers&action=exportcampaign&camp_id=' . $_REQUEST['id'] .$wpnonce .'&file_name=' . base64_encode($tempfilename['name'])); 
  2007.  
  2008. function unsubscribelist($data) { 
  2009. $this->requireSecurity(); 
  2010. $modelL = WYSIJA::get('list', 'model'); 
  2011. $list = $modelL->getOne(false, array('list_id' => $data['listid'])); 
  2012. if ($list['is_enabled']) { 
  2013. /** delete from user_lists where select from email_user_stat */ 
  2014. $query = $this->getListSubscriberQry("B.user_id"); 
  2015. $query2 = "DELETE FROM `[wysija]user_list` where user_id IN ($query) and list_id=" . $data['listid']; 
  2016. $this->modelObj->query($query2); 
  2017.  
  2018. $this->notice(sprintf(__('The segment has been unsubscribed from the list "%1$s".', WYSIJA), $list['name'])); 
  2019. } else { 
  2020. $this->notice(sprintf(__('The segment cannot be unsubscribed from an [IMPORT] list.', WYSIJA), $list['name'])); 
  2021.  
  2022. $this->redirect('admin.php?page=wysija_campaigns&action=viewstats&id=' . $_REQUEST['id']); 
  2023.  
  2024. function articles() { 
  2025. $this->iframeTabs = array('articles' => __("Post Selection", WYSIJA)); 
  2026.  
  2027. // required js files 
  2028. $this->js[] = 'wysija-admin-ajax'; 
  2029. $this->js[] = 'wysija-base-script-64'; 
  2030. $this->js[] = 'wysija-scriptaculous'; 
  2031. $this->js[] = 'wysija-colorpicker'; 
  2032. $this->js[] = 'mailpoet-select2'; 
  2033. $this->js[] = 'mailpoet-field-select2-terms'; 
  2034. $this->js[] = 'mailpoet-field-select2-simple'; 
  2035.  
  2036. // translations 
  2037. $this->jsTrans['show_advanced'] = __('Display and insert options', WYSIJA); 
  2038. $this->jsTrans['hide_advanced'] = __('Back to selection', WYSIJA); 
  2039. $this->jsTrans['loading_results'] = __('Loading results...', WYSIJA); 
  2040. $this->jsTrans['inserting_selection'] = __('Inserting selected articles...', WYSIJA); 
  2041. $this->jsTrans['post_selected'] = __('selected', WYSIJA); 
  2042.  
  2043. // default tab in popup (this needs to be removed at some point) 
  2044. $_GET['tab'] = 'articles'; 
  2045.  
  2046. // get parameters 
  2047. $params = array( 
  2048. 'category_ids' => null,  
  2049. 'category' => null,  
  2050. 'title_tag' => 'h2',  
  2051. 'title_alignment' => 'left',  
  2052. 'title_position' => 'inside',  
  2053. 'image_alignment' => 'alternate',  
  2054. 'image_width' => 325,  
  2055. 'post_content' => 'excerpt',  
  2056. 'readmore' => __('Read more.', WYSIJA),  
  2057. 'show_divider' => 'yes',  
  2058. 'post_limit' => 5,  
  2059. 'post_type' => 'post',  
  2060. 'author_show' => 'no',  
  2061. 'author_label' => __('Author:', WYSIJA),  
  2062. 'category_show' => 'no',  
  2063. 'category_label' => __('Categories:', WYSIJA),  
  2064. 'nopost_message' => __('Latest content already sent.', WYSIJA),  
  2065. 'bgcolor1' => null,  
  2066. 'bgcolor2' => null,  
  2067. 'sort_by' => 'newest' 
  2068. ); 
  2069.  
  2070. // check if GET parameters are specified 
  2071. foreach($params as $key => $value) { 
  2072. if(array_key_exists($key, $_GET)) { 
  2073. switch($key) { 
  2074. case 'autopost_count': 
  2075. $params[$key] = (int)$_GET[$key]; 
  2076. break; 
  2077. case 'readmore': 
  2078. case 'nopost_message': 
  2079. $params[$key] = base64_decode($_GET[$key]); 
  2080. break; 
  2081. default: 
  2082. $params[$key] = $_GET[$key]; 
  2083.  
  2084. $model_config = WYSIJA::get('config', 'model'); 
  2085. $insert_post_parameters = $model_config->getValue('insert_post_parameters'); 
  2086. $helper_wj_engine = WYSIJA::get('wj_engine', 'helper'); 
  2087.  
  2088. if($insert_post_parameters !== false) { 
  2089. // there are user params 
  2090. $params = $helper_wj_engine->decodeParameters(array_merge($params, $insert_post_parameters)); 
  2091.  
  2092. // get autopost count 
  2093. $this->data['autopost_count'] = (array_key_exists('autopost_count', $_GET)) ? (int) $_GET['autopost_count'] : 0; 
  2094.  
  2095. // get autopost type (single or multiple) 
  2096. $this->data['autopost_type'] = (array_key_exists('autopost_type', $_GET)) ? $_GET['autopost_type'] : 'multiple'; 
  2097.  
  2098. // if only one group of post can be added, change default alignment to left 
  2099. if($this->data['autopost_type'] === 'single' && $params['image_alignment'] === 'alternate') { 
  2100. $params['image_alignment'] = 'left'; 
  2101.  
  2102. // get post categories (even when there's no post) 
  2103. $post_categories = get_categories(array('hide_empty' => 0)); 
  2104. $categories = array(); 
  2105. foreach ($post_categories as $category) { 
  2106. $categories[] = array('id' => $category->cat_ID, 'name' => $category->name); 
  2107. $this->data['categories'] = $categories; 
  2108.  
  2109. // max number of posts 
  2110. $this->data['post_limits'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 50); 
  2111.  
  2112. $this->data['params'] = $params; 
  2113.  
  2114. return $this->popupContent(); 
  2115.  
  2116. function themeupload() { 
  2117. $this->requireSecurity(); 
  2118. $helperNumbers = WYSIJA::get('numbers', 'helper'); 
  2119. $bytes = $helperNumbers->get_max_file_upload(); 
  2120.  
  2121. if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $bytes['maxbytes']) { 
  2122. if (isset($_FILES['my-theme']['name']) && $_FILES['my-theme']['name']) { 
  2123. $filename = $_FILES['my-theme']['name']; 
  2124. } else { 
  2125. $filename = ""; 
  2126.  
  2127. $this->error(sprintf(__('Upload error, file %1$s is too large! (MAX:%2$s)', WYSIJA), $filename, $bytes['maxmegas']), true); 
  2128. $this->redirect('admin.php?page=wysija_campaigns&action=themes'); 
  2129.  
  2130. return false; 
  2131.  
  2132. if (!$_FILES['my-theme']['tmp_name'] || !is_file($_FILES['my-theme']['tmp_name'])) { 
  2133. $this->error(__('This file is empty. Please try another.', WYSIJA)); 
  2134. $this->redirect('admin.php?page=wysija_campaigns&action=themes'); 
  2135. return false; 
  2136.  
  2137. $ZipfileResult = trim(file_get_contents($_FILES['my-theme']['tmp_name'])); 
  2138.  
  2139. $themesHelp = WYSIJA::get('themes', 'helper'); 
  2140. $result = $themesHelp->installTheme($_FILES['my-theme']['tmp_name'], true); 
  2141. $this->redirect('admin.php?page=wysija_campaigns&action=themes&reload=1'); 
  2142.  
  2143. return true; 
  2144.  
  2145. function themes() { 
  2146. $this->iframeTabs = array('themes' => __('Install Themes', WYSIJA)); 
  2147. $this->js[] = 'wysija-admin-ajax'; 
  2148. $this->js[] = 'wysija-base-script-64'; 
  2149. $this->jsTrans['viewinfos'] = __('Details & PSD', WYSIJA); 
  2150. $this->jsTrans['viewback'] = __('<< Back', WYSIJA); 
  2151. $this->jsTrans['install'] = __('Download', WYSIJA); 
  2152. $this->jsTrans['reinstall'] = __('Reinstall', WYSIJA); 
  2153. $this->jsTrans['premiumonly'] = __('Premium', WYSIJA); 
  2154.  
  2155. $model_config = WYSIJA::get('config', 'model'); 
  2156. //change the translation of the button when it's premium 
  2157. if ($model_config->getValue('premium_key')) 
  2158. $this->jsTrans['ispremium'] = 1; 
  2159. else 
  2160. $this->jsTrans['ispremium'] = 0; 
  2161.  
  2162. $this->jsTrans['premiumfiles'] = __('Photoshop file available as part of [link]Premium features[/link].', WYSIJA); 
  2163.  
  2164. $helper_licence = WYSIJA::get('licence', 'helper'); 
  2165. $url_checkout = $helper_licence->get_url_checkout('themes'); 
  2166. $this->jsTrans['premiumfiles'] = str_replace(array('[link]', '[/link]'), array('<a href="' . $url_checkout . '" target="_blank" >', '</a>'), $this->jsTrans['premiumfiles']); 
  2167.  
  2168. $this->jsTrans['showallthemes'] = __('Show all themes', WYSIJA); 
  2169. $this->jsTrans['totalvotes'] = __('(%1$s votes)', WYSIJA); 
  2170. $this->jsTrans['voterecorded'] = __("Your vote has been recorded.", WYSIJA); 
  2171. $this->jsTrans['votenotrecorded'] = __("Your vote could not be recorded.", WYSIJA); 
  2172. $this->jsTrans['reinstallwarning'] = __('Watch out! If you reinstall this theme all the files which are in the folder:/wp-content/uploads/wysija/themes/%1$s will be overwritten. Are you sure you want to reinstall?', WYSIJA); 
  2173. $this->jsTrans['errorconnecting'] = __("We were unable to contact the API, the site may be down. Please try again later.", WYSIJA); 
  2174.  
  2175. $this->jsTrans['viewallthemes'] = __('View all themes by %1$s', WYSIJA); 
  2176. $this->jsTrans['downloadpsd'] = __("Download original Photoshop file", WYSIJA); 
  2177. $this->jsTrans['downloadzip'] = __("Download as .zip", WYSIJA); 
  2178. $this->jsTrans['viewauthorsite'] = __("View author's website", WYSIJA); 
  2179. $this->jsTrans['stars'] = __('Average rating: %1$s', WYSIJA); 
  2180. $this->jsTrans['starsyr'] = __('My rating: %1$s', WYSIJA); 
  2181. $this->jsTrans['downloads'] = __('Downloads: %1$s', WYSIJA); 
  2182. $this->jsTrans['tags'] = __('Tags: %1$s', WYSIJA); 
  2183. $this->jsTrans['lastupdated'] = __('Last updated: %1$s', WYSIJA); 
  2184. $this->jsTrans['includes'] = __('Includes: %1$s', WYSIJA); 
  2185.  
  2186. $helper_themes = WYSIJA::get('themes', 'helper'); 
  2187.  
  2188. $this->jsTrans['installedthemes'] = $helper_themes->getInstalled(); 
  2189.  
  2190. $url = admin_url('admin.php'); 
  2191. $helper_toolbox = WYSIJA::get("toolbox", "helper"); 
  2192. $domain_name = $helper_toolbox->_make_domain_name($url); 
  2193. $this->jsTrans['domainname'] = $domain_name; 
  2194.  
  2195. $_GET['tab'] = 'themes'; 
  2196.  
  2197. return $this->popupContent(); 
  2198.  
  2199. function bookmarks() { 
  2200. $this->iframeTabs = array('bookmarks' => __('Bookmarks Selection', WYSIJA)); 
  2201. $this->js[] = 'wysija-admin-ajax'; 
  2202.  
  2203. $_GET['tab'] = 'bookmarks'; 
  2204.  
  2205. $networks = array( 
  2206. 'facebook' => array( 
  2207. 'label' => 'Facebook',  
  2208. 'url' => null,  
  2209. 'placeholder' => 'https://www.facebook.com/mailpoetplugin' 
  2210. ),  
  2211. 'twitter' => array( 
  2212. 'label' => 'Twitter',  
  2213. 'url' => null,  
  2214. 'placeholder' => 'http://www.twitter.com/mail_poet' 
  2215. ),  
  2216. 'google' => array( 
  2217. 'label' => 'Google+',  
  2218. 'url' => null,  
  2219. 'placeholder' => null 
  2220. ),  
  2221. 'linkedin' => array( 
  2222. 'label' => 'LinkedIn',  
  2223. 'url' => null,  
  2224. 'placeholder' => null 
  2225. ); 
  2226.  
  2227. // get networks' url from config 
  2228. $model_config = WYSIJA::get('config', 'model'); 
  2229. $urls = $model_config->getValue('social_bookmarks'); 
  2230.  
  2231. // set url from config for each network if specified 
  2232. foreach ($networks as $network => $values) { 
  2233. if (isset($urls[$network]) and strlen(trim($urls[$network])) > 0) { 
  2234. $networks[$network]['url'] = $urls[$network]; 
  2235.  
  2236. $this->data['networks'] = $networks; 
  2237. $this->data['size'] = 'medium'; 
  2238. $this->data['theme'] = isset($_REQUEST['theme']) ? $_REQUEST['theme'] : 'default'; 
  2239.  
  2240. return $this->popupContent(); 
  2241.  
  2242. function dividers() { 
  2243. $this->iframeTabs = array('dividers' => __("Dividers Selection", WYSIJA)); 
  2244. $this->js[] = 'wysija-admin-ajax'; 
  2245. $this->js[] = 'wysija-base-script-64'; 
  2246.  
  2247. $_GET['tab'] = 'dividers'; 
  2248.  
  2249. $model_email = WYSIJA::get('email', 'model'); 
  2250. $this->data['email'] = $email = $model_email->getOne(false, array('email_id' => $_REQUEST['emailId'])); 
  2251.  
  2252. // get dividers 
  2253. $helper_dividers = WYSIJA::get('dividers', 'helper'); 
  2254. $dividers = $helper_dividers->getAll(); 
  2255.  
  2256. // get theme divider if it's not the default theme 
  2257. if (isset($email['params']['theme'])) { 
  2258. $helper_themes = WYSIJA::get('themes', 'helper'); 
  2259. $themeDivider = $helper_themes->getDivider($email['params']['theme']); 
  2260. if ($themeDivider !== NULL) { 
  2261. array_unshift($dividers, $themeDivider); 
  2262.  
  2263. // get selected divider 
  2264. if (isset($email['params']['divider'])) { 
  2265. $selected_divider = $email['params']['divider']; 
  2266. } else { 
  2267. $helper_dividers = WYSIJA::get('dividers', 'helper'); 
  2268. $selected_divider = $helper_dividers->getDefault(); 
  2269.  
  2270. // set selected divider in first position 
  2271. array_unshift($dividers, $selected_divider); 
  2272.  
  2273. // remove selected divider if present in the list 
  2274. for ($i = 1; $i < count($dividers); $i++) { 
  2275. if ($dividers[$i]['src'] === $selected_divider['src']) { 
  2276. unset($dividers[$i]); 
  2277. break; 
  2278.  
  2279. $this->data['selected'] = $selected_divider; 
  2280. $this->data['dividers'] = $dividers; 
  2281. return $this->popupContent(); 
  2282.  
  2283. function autopost() { 
  2284. $this->iframeTabs = array('autopost' => __("Add / Edit group of posts", WYSIJA)); 
  2285. $this->js[] = 'wysija-admin-ajax'; 
  2286. $this->js[] = 'wysija-base64'; 
  2287. $this->js[] = 'wysija-scriptaculous'; 
  2288. $this->js[] = 'wysija-colorpicker'; 
  2289. $this->js[] = 'mailpoet-select2'; 
  2290. $this->js[] = 'mailpoet-field-select2-terms'; 
  2291.  
  2292. // translations 
  2293. $this->jsTrans['show_advanced'] = __('Show display options', WYSIJA); 
  2294. $this->jsTrans['hide_advanced'] = __('Hide display options', WYSIJA); 
  2295.  
  2296. $_GET['tab'] = 'autopost'; 
  2297.  
  2298. // get parameters 
  2299. $params = array( 
  2300. 'category_ids' => null,  
  2301. 'category_condition' => 'include',  
  2302. 'title_tag' => 'h2',  
  2303. 'title_alignment' => 'left',  
  2304. 'title_position' => 'inside',  
  2305. 'image_alignment' => 'alternate',  
  2306. 'image_width' => 325,  
  2307. 'post_content' => 'excerpt',  
  2308. 'readmore' => __('Read more.', WYSIJA),  
  2309. 'show_divider' => 'yes',  
  2310. 'post_limit' => 5,  
  2311. 'post_type' => 'post',  
  2312. 'author_show' => 'no',  
  2313. 'author_label' => __('Author:', WYSIJA),  
  2314. 'category_show' => 'no',  
  2315. 'category_label' => __('Categories:', WYSIJA),  
  2316. 'nopost_message' => __('Latest content already sent.', WYSIJA),  
  2317. 'bgcolor1' => null,  
  2318. 'bgcolor2' => null,  
  2319. 'sort_by' => 'newest' 
  2320. ); 
  2321.  
  2322. // backwards compatibility since we replaced the 'cpt' parameter by 'post_type' in 2.6 
  2323. if(isset($_GET['cpt']) && strlen(trim($_GET['cpt'])) > 0) { 
  2324. $params['post_type'] = trim($_GET['cpt']); 
  2325.  
  2326. // check if GET parameters are specified 
  2327. foreach ($params as $key => $value) { 
  2328. if (array_key_exists($key, $_GET)) { 
  2329. switch ($key) { 
  2330. case 'autopost_count': 
  2331. $params[$key] = (int)$_GET[$key]; 
  2332. break; 
  2333. case 'author_label': 
  2334. case 'category_label': 
  2335. case 'readmore': 
  2336. case 'nopost_message': 
  2337. $params[$key] = base64_decode($_GET[$key]); 
  2338. break; 
  2339. default: 
  2340. $params[$key] = trim($_GET[$key]); 
  2341.  
  2342. // get autopost count 
  2343. $this->data['autopost_count'] = (array_key_exists('autopost_count', $_GET)) ? (int) $_GET['autopost_count'] : 0; 
  2344.  
  2345. // get autopost type (single or multiple) 
  2346. $this->data['autopost_type'] = (array_key_exists('autopost_type', $_GET)) ? $_GET['autopost_type'] : 'multiple'; 
  2347.  
  2348. // if only one group of post can be added, change default alignment to left 
  2349. if ($this->data['autopost_type'] === 'single') { 
  2350. if ($params['image_alignment'] === 'alternate') 
  2351. $params['image_alignment'] = 'left'; 
  2352.  
  2353. // we use that now, because categories from a post are different than categories from a CPT 
  2354. // $helper_wp_tools = WYSIJA::get('wp_tools', 'helper'); 
  2355. // $this->data['categories'] = $helper_wp_tools->get_categories(); 
  2356.  
  2357. // max number of posts 
  2358. $this->data['post_limits'] = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 50); 
  2359.  
  2360. $this->data['params'] = $params; 
  2361.  
  2362. return $this->popupContent(); 
  2363.  
  2364. function image_data() { 
  2365. $this->data['url'] = (isset($_GET['url']) && $_GET['url'] !== '') ? trim(urldecode($_GET['url'])) : null; 
  2366. $this->data['alt'] = (isset($_GET['alt'])) ? trim(urldecode($_GET['alt'])) : ''; 
  2367.  
  2368. $this->iframeTabs = array('image_data' => __("Image Parameters", WYSIJA)); 
  2369. $_GET['tab'] = 'image_data'; 
  2370. return $this->popupContent(); 
  2371.  
  2372. function medias() { 
  2373. $this->popupContent(); 
  2374.  
  2375. function special_wysija_browse() { 
  2376. $this->_wysija_subaction(); 
  2377. $this->jsTrans['deleteimg'] = __('Delete image for all newsletters?', WYSIJA); 
  2378. return wp_iframe(array($this->viewObj, 'popup_wysija_browse'), array()); 
  2379.  
  2380. function special_wordp_browse() { 
  2381. $this->_wysija_subaction(); 
  2382. $this->jsTrans['deleteimg'] = __('This image might be in an article. Delete anyway?', WYSIJA); 
  2383. return wp_iframe(array($this->viewObj, 'popup_wp_browse'), array()); 
  2384.  
  2385. function special_new_wordp_upload() { 
  2386.  
  2387. wp_enqueue_script('wysija-plupload-handlers', WYSIJA_URL . 'js/jquery/pluploadHandler.js', array('plupload-all', 'jquery')); 
  2388. $uploader_l10n = array( 
  2389. 'queue_limit_exceeded' => __('You have attempted to queue too many files.'),  
  2390. 'file_exceeds_size_limit' => __('%s exceeds the maximum upload size for this site.'),  
  2391. 'zero_byte_file' => __('This file is empty. Please try another.'),  
  2392. 'invalid_filetype' => __('This file type is not allowed. Please try another.'),  
  2393. 'not_an_image' => __('This file is not an image. Please try another.'),  
  2394. 'image_memory_exceeded' => __('Memory exceeded. Please try another smaller file.'),  
  2395. 'image_dimensions_exceeded' => __('This is larger than the maximum size. Please try another.'),  
  2396. 'default_error' => __('An error occurred in the upload. Please try again later.'),  
  2397. 'missing_upload_url' => __('There was a configuration error. Please contact the server administrator.'),  
  2398. 'upload_limit_exceeded' => __('You may only upload 1 file.'),  
  2399. 'http_error' => __('HTTP error.'),  
  2400. 'upload_failed' => __('Upload failed.'),  
  2401. 'big_upload_failed' => __('Please try uploading this file with the %1$sbrowser uploader%2$s.'),  
  2402. 'big_upload_queued' => __('%s exceeds the maximum upload size for the multi-file uploader when used in your browser.'),  
  2403. 'io_error' => __('IO error.'),  
  2404. 'security_error' => __('Security error.'),  
  2405. 'file_cancelled' => __('File canceled.'),  
  2406. 'upload_stopped' => __('Upload stopped.'),  
  2407. 'dismiss' => __('Dismiss'),  
  2408. 'crunching' => __('Crunching…'),  
  2409. 'deleted' => __('moved to the trash.'),  
  2410. 'error_uploading' => __('“%s” has failed to upload.'),  
  2411. 'files_successfully_uploaded' => __('%d file(s) have been successfully uploaded.') 
  2412. ); 
  2413.  
  2414. wp_localize_script('wysija-plupload-handlers', 'pluploadL10n', $uploader_l10n); 
  2415.  
  2416. wp_enqueue_script('image-edit'); 
  2417. wp_enqueue_script('set-post-thumbnail'); 
  2418. wp_enqueue_style('imgareaselect'); 
  2419. wp_enqueue_script('media-gallery'); 
  2420.  
  2421. $errors = array(); 
  2422. return wp_iframe(array($this->viewObj, 'popup_new_wp_upload'), $errors); 
  2423.  
  2424. function special_wordp_upload() { 
  2425.  
  2426. wp_enqueue_script('swfupload-all'); 
  2427. wp_enqueue_script('swfupload-handlers'); 
  2428. wp_enqueue_script('wysija-upload-handlers', WYSIJA_URL . "js/jquery/uploadHandlers.js"); 
  2429. wp_enqueue_script('image-edit'); 
  2430. wp_enqueue_script('set-post-thumbnail'); 
  2431. wp_enqueue_style('imgareaselect'); 
  2432.  
  2433. $errors = array(); 
  2434. $id = 0; 
  2435. if (isset($_GET['flash'])) 
  2436. $_GET['flash'] = 1; 
  2437. if (isset($_POST['html-upload']) && !empty($_FILES)) { 
  2438. // Upload File button was clicked 
  2439. $id = media_handle_upload('async-upload', $_REQUEST['post_id']); 
  2440. unset($_FILES); 
  2441. if (is_wp_error($id)) { 
  2442. $errors['upload_error'] = $id; 
  2443. $id = false; 
  2444.  
  2445. if (!empty($_POST['insertonlybutton'])) { 
  2446. $href = $_POST['insertonly']['href']; 
  2447. if (!empty($href) && !strpos($href, '://')) 
  2448. $href = "http://$href"; 
  2449.  
  2450. $title = esc_attr($_POST['insertonly']['title']); 
  2451. if (empty($title)) 
  2452. $title = basename($href); 
  2453. if (!empty($title) && !empty($href)) 
  2454. $html = "<a href='" . esc_url($href) . "' >$title</a>"; 
  2455. $html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title); 
  2456. return media_send_to_editor($html); 
  2457.  
  2458. if (!empty($_POST)) { 
  2459. $return = media_upload_form_handler(); 
  2460.  
  2461. if (is_string($return)) 
  2462. return $return; 
  2463. if (is_array($return)) 
  2464. $errors = $return; 
  2465.  
  2466. if (isset($_POST['save'])) { 
  2467. $errors['upload_notice'] = __('Saved.', WYSIJA); 
  2468. return media_upload_gallery(); 
  2469.  
  2470.  
  2471. return wp_iframe(array($this->viewObj, 'popup_wp_upload'), $errors); 
  2472.  
  2473. function _checkEmailExists($emailId) { 
  2474. $result = false; 
  2475. $model_email = WYSIJA::get('email', 'model'); 
  2476.  
  2477. if ($model_email->exists(array('email_id' => $emailId))) { 
  2478. $result = true; 
  2479.  
  2480. if (!$result) { 
  2481. $this->error(__("The newsletter doesn't exist.", WYSIJA), 1); 
  2482. $this->redirect('admin.php?page=wysija_campaigns'); 
  2483. }else{ 
  2484. return true; 
  2485.  
  2486.