Beispiel #1
0
 private function _set_ajax_nonces()
 {
     if (isset($_GET['page']) && substr($_GET['page'], 0, 7) == 'wysija_') {
         $ajax_nonces = array('campaigns' => array('switch_theme' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'switch_theme'), true), 'save_editor' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'save_editor'), true), 'save_styles' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'save_styles'), true), 'deleteimg' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'deleteimg'), true), 'deleteTheme' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'deleteTheme'), true), 'save_IQS' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'save_IQS'), true), 'send_preview' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'send_preview'), true), 'send_spamtest' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'send_spamtest'), true), 'insert_articles' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'insert_articles'), true), 'set_divider' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'set_divider'), true), 'generate_social_bookmarks' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'generate_social_bookmarks'), true), 'install_theme' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'install_theme'), true), 'setDefaultTheme' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'setDefaultTheme'), true), 'deleteTheme' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'deleteTheme'), true), 'save_poll' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'save_poll'), true), 'sub_delete_image' => WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'sub_delete_image'), true)), 'config' => array('send_test_mail' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'send_test_mail'), true), 'send_test_mail_ms' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'send_test_mail_ms'), true), 'bounce_process' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'bounce_process'), true), 'share_analytics' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'share_analytics'), true), 'wysija_form_manage_field' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'wysija_form_manage_field'), true), 'form_field_delete' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'form_field_delete'), true), 'form_name_save' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'form_name_save'), true), 'form_save' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'form_save'), true), 'validate' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'validate'), true), 'linkignore' => WYSIJA_view::secure(array('controller' => 'wysija_config', 'action' => 'linkignore'), true)));
     } else {
         $ajax_nonces = array();
     }
     wp_localize_script('wysija-admin', 'wysijanonces', $ajax_nonces);
 }
Beispiel #2
0
 /**
  * Swap color schemes, to make sure, we don't use 2 colors in a same scheme continously
  * @return array()
  */
 protected function swap_color_schemes()
 {
     if (empty(self::$cache_color_schemes)) {
         // swap colors from axis X => Y, Y => X
         $x = count($this->color_schemes[0][0]);
         $y = count($this->color_schemes[0]);
         $tmp = array();
         foreach ($this->color_schemes as $y => $colors) {
             foreach ($colors as $x => $color) {
                 $tmp[$x][$y] = $color;
             }
         }
         self::$cache_color_schemes = $tmp;
     }
     return self::$cache_color_schemes;
 }
Beispiel #3
0
    /**
     *
     * @param int $email_id
     * @param int $user_id we can specify that parameter if we want to process the emails of only one specific user
     * @return boolean
     */
    function process($email_id = false, $user_id = false)
    {
        if ($email_id) {
            $this->email_id = (int) $email_id;
        }
        $model_queue = WYSIJA::get('queue', 'model');
        $queue_elements = $model_queue->getReady($this->send_limit, $this->email_id, $user_id);
        $this->total = count($queue_elements);
        $this->start = 0;
        // there is no elements queued
        if (empty($queue_elements)) {
            // there might be some delaied emails let's list those ones
            $queue_elements_delayed = $model_queue->getDelayed($this->email_id);
            // let's see if there are any delayed emails so that we display something about it
            if (empty($queue_elements_delayed)) {
                $this->clear();
            } else {
                // report is on let's print the details about those delayed elements
                if ($this->report) {
                    $html_response = '<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" />';
                    $html_response .= '<style>body{font-size:12px;font-family: Arial,Helvetica,sans-serif;}</style></head><body>';
                    $html_response .= '<div style="background-color : white;border : 1px solid grey; padding : 3px;font-size:14px">';
                    $html_response .= '<span id="divpauseinfo" style="padding:10px;margin:5px;font-size:16px;font-weight:bold;display:none;background-color:black;color:white;"> </span>';
                    $helper_toolbox = WYSIJA::get('toolbox', 'helper');
                    $html_response .= sprintf(__('There are %1$s pending email(s)', WYSIJA), count($queue_elements_delayed));
                    $html_response .= ' - <small>' . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $helper_toolbox->servertime_to_localtime(time())) . '</small>';
                    $html_response .= '</div>';
                    // for each elements let's calculate and print when the email is supposed to be sent
                    foreach ($queue_elements_delayed as $element) {
                        $html_response .= '<div id="divinfo">' . sprintf(__('Email will be sent to %1$s at %2$s', WYSIJA), '<b>' . $element['email'] . '</b>', '<em>' . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $helper_toolbox->servertime_to_localtime($element['send_at'])) . '</em>') . ' </div>';
                    }
                    echo $html_response;
                }
            }
            $this->finish = true;
            return true;
        }
        // report is on let's print the details about those delayed elements
        if ($this->report) {
            if (!headers_sent() and ob_get_level() > 0) {
                ob_end_flush();
            }
            $html_response = '<html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" />';
            $html_response .= '<title>' . addslashes(__('Send Process', WYSIJA)) . '</title>';
            $html_response .= '<style>body{font-size:12px;font-family: Arial,Helvetica,sans-serif;}</style></head><body>';
            $html_response .= "<div style='padding: 3px;'>";
            $html_response .= "<span id='divpauseinfo' style='padding:10px;margin:5px;font-size:16px;font-weight:bold;display:none;background-color:black;color:white;'> </span>";
            $html_response .= __('Total of batch', WYSIJA) . ': <span id="counter"/>' . $this->start . '</span> / ' . $this->total;
            $html_response .= '</div>';
            $html_response .= "<div id='divinfo' style='display:none; position:fixed; bottom:3px;left:3px;background-color : white; border : 1px solid grey; padding : 3px;'> </div>";
            $url = 'admin.php?page=wysija_campaigns&action=manual_send&emailid=' . $this->email_id . '&_wpnonce=' . WYSIJA_view::secure(array('action' => 'manual_send'), true) . '&totalsend=' . $this->total . '&alreadysent=';
            $html_response .= '<script type="text/javascript" language="javascript">';
            $html_response .= 'var mycounter = document.getElementById("counter");';
            $html_response .= 'var divinfo = document.getElementById("divinfo");
					var divpauseinfo = document.getElementById("divpauseinfo");
					function setInfo(message){ divinfo.style.display = \'block\';divinfo.innerHTML=message; }
					function setPauseInfo(nbpause){ divpauseinfo.style.display = \'\';divpauseinfo.innerHTML=nbpause;}
					function setCounter(val){ mycounter.innerHTML=val;}
					var scriptpause = ' . intval($this->pause) . ';
					function handlePause(){
						setPauseInfo(scriptpause);
						if(scriptpause > 0){
							scriptpause = scriptpause - 1;
							setTimeout(\'handlePause()\',1000);
						}else{
							document.location.href=\'' . $url . '\'+mycounter.innerHTML;
						}
					}
					</script>';
            echo $html_response;
            if (function_exists('ob_flush')) {
                @ob_flush();
            }
            @flush();
        }
        //endifreport
        $helper_mailer = WYSIJA::get('mailer', 'helper');
        $helper_mailer->report = false;
        if ($this->config->getValue('smtp_keepalive', 1)) {
            $helper_mailer->SMTPKeepAlive = true;
        } else {
            $helper_mailer->SMTPKeepAlive = false;
        }
        $queue_delete = array();
        $queue_update = array();
        $stats_add = array();
        $action_subscriber = array();
        $max_try = (int) $this->config->getValue('queue_try', 3);
        $current_mail = $this->start;
        $this->nbprocess = 0;
        if (count($queue_elements) < $this->send_limit) {
            $this->finish = true;
        }
        WYSIJA::log('helpers -> Queue ->process', $queue_elements, 'queue_process');
        // go through each queued element and process it
        foreach ($queue_elements as $queue_item) {
            $current_mail++;
            $this->nbprocess++;
            if ($this->report) {
                echo '<script type="text/javascript" language="javascript">setCounter(' . $current_mail . ')</script>';
                if (function_exists('ob_flush')) {
                    @ob_flush();
                }
                @flush();
            }
            WYSIJA::log('helpers -> Queue ->process ->sendOne', array('email_id' => $queue_item->email_id, 'oneQueue' => $queue_item), 'queue_process');
            $result = $helper_mailer->sendOne($queue_item->email_id, $queue_item);
            $queue_delete_ok = true;
            $other_message = '';
            // email has been sent ok let's make the process resulting after that
            if ($result) {
                $this->successSend++;
                $this->consecutiveError = 0;
                $queue_delete[$queue_item->email_id][] = $queue_item->user_id;
                $stats_add[$queue_item->email_id][1][(int) $helper_mailer->sendHTML][] = $queue_item->user_id;
                $queue_delete_ok = $this->_deleteQueue($queue_delete);
                WYSIJA::log('helpers -> Queue ->process ->sendOne resultOK(queue delete)', $queue_delete, 'queue_process');
                $queue_delete = array();
                // each 10 elements processed we record the statistics for that email and update the queue
                if ($this->nbprocess % 10 == 0) {
                    $this->_statsAdd($stats_add);
                    $this->_queueUpdate($queue_update);
                    $stats_add = array();
                    $queue_update = array();
                }
            } else {
                // email has not been sent and the mailer class returned an error
                $this->errorSend++;
                $new_try = false;
                if (in_array($helper_mailer->errorNumber, $helper_mailer->errorNewTry)) {
                    // we check if that's still possible to have a new try at sending the email
                    if (empty($max_try) or $queue_item->number_try < $max_try - 1) {
                        $new_try = true;
                        $other_message = sprintf(__('Next try in %s minutes.', WYSIJA), round($this->config->getValue('queue_delay') / 60));
                    }
                    if ($helper_mailer->errorNumber == 1) {
                        $this->consecutiveError++;
                    }
                    if ($this->consecutiveError == 2) {
                        sleep(1);
                    }
                }
                //if it's not possible to have a new try at sending the email then we delete the email from the queue and we add some stats
                if (!$new_try) {
                    $queue_delete[$queue_item->email_id][] = $queue_item->user_id;
                    $stats_add[$queue_item->email_id][0][(int) @$helper_mailer->sendHTML][] = $queue_item->user_id;
                    if ($helper_mailer->errorNumber == 1 and $this->config->getValue('bounce_action_maxtry')) {
                        $queue_delete_ok = $this->_deleteQueue($queue_delete);
                        $queue_delete = array();
                        // ADDED to add the stats immediately instead of waiting
                        $this->_statsAdd($stats_add);
                        $stats_add = array();
                        // this is not used actually it would be used if we had a rule for the bounce max try case scenario
                        // this is used in acy not in wysija
                        //$other_message .= $this->_subscriberAction($queue_item->user_id);
                        $other_message .= '';
                    }
                } else {
                    $queue_update[$queue_item->email_id][] = $queue_item->user_id;
                }
                WYSIJA::log('helpers -> Queue ->process ->sendOne resultFAILED(queue update)', $queue_update, 'queue_process');
            }
            //$messageOnScreen = '['.$oneQueue->email_id.'] '.$mailHelper->reportMessage;
            $message_on_screen = $helper_mailer->reportMessage;
            if (!empty($other_message)) {
                $message_on_screen .= ' => ' . $other_message;
            }
            $this->_display($message_on_screen, $result, $current_mail);
            if (!$queue_delete_ok) {
                $this->finish = true;
                break;
            }
            // when we reach the execution time limit we just refresh the screen
            if (!empty($this->stoptime) and $this->stoptime < time()) {
                $this->_display(__('Process refreshed to avoid a time limit.', WYSIJA));
                if ($this->nbprocess < count($queue_elements)) {
                    $this->finish = false;
                }
                break;
            }
            // too many consecutive errors compared to th enumber of success
            if ($this->consecutiveError > 2 and $this->successSend > 3) {
                $this->_display(__('Process refreshed to avoid a possible loss of connection.', WYSIJA));
                break;
            }
            // if there are too many consecutive errors or the connection has been aborted by the client we finish the request
            if ($this->consecutiveError > 5 or connection_aborted()) {
                $this->finish = true;
                break;
            }
        }
        //delete the elements from the queue and add statistics and update the queue
        $this->_deleteQueue($queue_delete);
        $this->_statsAdd($stats_add);
        $this->_queueUpdate($queue_update);
        if ($this->config->getValue('smtp_keepalive', 1)) {
            $helper_mailer->SmtpClose();
        }
        if (!empty($this->total) and $current_mail >= $this->total) {
            $this->finish = true;
        }
        if ($this->consecutiveError > 5) {
            $this->_handleError();
            return false;
        }
        if ($this->report && !$this->finish) {
            echo '<script type="text/javascript" language="javascript">handlePause();</script>';
        }
        if ($this->report) {
            echo '</body></html>';
            exit;
        }
        return true;
    }
Beispiel #4
0
 function export()
 {
     $this->requireSecurity();
     // select from email_user_stat left join user
     $query = $this->getListSubscriberQry('B.user_id');
     $result = $this->modelObj->query('get_res', $query);
     $user_ids = array();
     foreach ($result as $user) {
         $user_ids[] = $user['user_id'];
     }
     $helper_file = WYSIJA::get('file', 'helper');
     $tempfilename = $helper_file->temp(implode(',', $user_ids), 'export_userids', '.txt');
     $wpnonce = '&_wpnonce=' . WYSIJA_view::secure(array('controller' => 'wysija_subscribers', 'action' => 'exportcampaign'), true);
     $this->redirect('admin.php?page=wysija_subscribers&action=exportcampaign&camp_id=' . $_REQUEST['id'] . $wpnonce . '&file_name=' . base64_encode($tempfilename['name']));
 }
 /**
  * Render actions of a newsletter
  * @param type $data
  */
 public function hook_newsletter_action_buttons($data)
 {
     echo '<div class="actions right">';
     $classes = function_exists('wp_star_rating') ? 'add-new-h2' : 'button-secondary2';
     // view button
     $email_helper = WYSIJA::get('email', 'helper');
     $link_view = $email_helper->getVIB($data['email_object']);
     echo '<a id="action-view" target="_blank" href="' . $link_view . '" class="action-view ' . $classes . '">' . __('View', WYSIJA) . '</a>';
     //duplicate button
     $action = 'duplicate';
     $params = array('page' => 'wysija_campaigns', 'action' => $action, 'id' => $data['id'], 'email_id' => $data['email_id'], '_wpnonce' => WYSIJA_view::secure(array('action' => $action, 'id' => $data['id']), true));
     $link_duplicate = 'admin.php?' . http_build_query($params);
     echo '<a id="action-' . $action . '" href="' . $link_duplicate . '" class="action-' . $action . ' ' . $classes . '">' . __('Duplicate', WYSIJA) . '</a>';
     $alternate = false;
     echo '<table class="newsletter-stats-block widefat fixed">';
     // Google tracking code
     if (!empty($data['email_object']['params']['googletrackingcode'])) {
         // echo '<div class="googletrackingcode"><span>' . __('Google Analytics', WYSIJA) . ':</span> ' . $data['email_object']['params']['googletrackingcode'] . '</div>';
         echo '<tr class="' . ($alternate ? 'alternate' : '') . '"><td class="label">' . __('Google Analytics', WYSIJA) . '</td><td>' . $data['email_object']['params']['googletrackingcode'] . '</td></tr>';
         $alternate = !$alternate;
     }
     // Sent on:
     // echo '<div class="googletrackingcode"><span>' . __('Sent on', WYSIJA) . ':</span> ' . $this->fieldListHTML_created_at_time($data['email_object']['sent_at']) . '</div>';
     echo '<tr class="' . ($alternate ? 'alternate' : '') . '"><td class="label">' . __('Sent on', WYSIJA) . '</td><td>' . $this->fieldListHTML_created_at_time($data['email_object']['sent_at']) . '</td></tr>';
     $alternate = !$alternate;
     // Lists:
     if (!empty($data['lists'])) {
         // echo '<div class="googletrackingcode"><span>' . __('Lists', WYSIJA) . ':</span> ' . implode(', ',$data['lists']) . '</div>';
         echo '<tr class="' . ($alternate ? 'alternate' : '') . '"><td class="label">' . __('Lists', WYSIJA) . '</td><td>' . implode(', ', $data['lists']) . '</td></tr>';
         $alternate = !$alternate;
     }
     // From address:
     $_from_address = array();
     if (!empty($data['email_object']['from_name'])) {
         $_from_address[] = $data['email_object']['from_name'];
     }
     if (!empty($data['email_object']['from_email'])) {
         $_from_address[] = $data['email_object']['from_email'];
     }
     if (!empty($_from_address)) {
         // echo '<div class="googletrackingcode"><span>' . __('From', WYSIJA) . ':</span> ' . implode(', ',$_from_address) . '</div>';
         echo '<tr class="' . ($alternate ? 'alternate' : '') . '"><td class="label">' . __('From', WYSIJA) . '</td><td>' . implode(' &lt;', $_from_address) . (count($_from_address) > 1 ? '&gt;' : '') . '</td></tr>';
         $alternate = !$alternate;
     }
     // Reply-to address
     $_reply_to_address = array();
     if (!empty($data['email_object']['replyto_name'])) {
         $_reply_to_address[] = $data['email_object']['replyto_name'];
     }
     if (!empty($data['email_object']['replyto_email'])) {
         $_reply_to_address[] = $data['email_object']['replyto_email'];
     }
     if (!empty($_reply_to_address)) {
         // echo '<div class="googletrackingcode"><span>' . __('Reply-to', WYSIJA) . ':</span> ' . implode(', ',$_reply_to_address) . '</div>';
         echo '<tr class="' . ($alternate ? 'alternate' : '') . '"><td class="label">' . __('Reply-to', WYSIJA) . '</td><td>' . implode(' &lt;', $_reply_to_address) . (count($_reply_to_address) > 1 ? '&gt;' : '') . '</td></tr>';
         $alternate = !$alternate;
     }
     if (!empty($data['bounce'])) {
         // echo '<div class="googletrackingcode"><span>' . __('Bounce', WYSIJA) . ':</span> ' . $data['bounce'] . '</div>';
         echo '<tr class="' . ($alternate ? 'alternate' : '') . '"><td class="label">' . __('Bounce', WYSIJA) . '</td><td>' . $data['bounce'] . '</td></tr>';
         $alternate = !$alternate;
     }
     echo '</table>';
     echo '</div>';
 }
Beispiel #6
0
 /**
  *
  */
 function version()
 {
     $wysija_footer_links = '<div class="wysija-version">';
     $wysija_footer_links .= '<div class="social-foot">';
     $link_start = ' | <a target="_blank" id="switch_to_package" href="admin.php?page=wysija_campaigns&action=switch_to_package&plugin=wysija-newsletters&_wpnonce=' . WYSIJA_view::secure(array('controller' => 'wysija_campaigns', 'action' => 'switch_to_package'), true);
     if (WYSIJA::is_beta()) {
         $beta_link = $link_start . '&stable=1"  title="' . __('Switch back to stable', WYSIJA) . '">' . __('Switch back to stable', WYSIJA) . '</a>';
     } else {
         $beta_link = $link_start . '"   title="' . __('Switch to beta', WYSIJA) . '">' . __('Switch to beta', WYSIJA) . '</a>';
     }
     if (is_multisite() && !WYSIJA::current_user_can('manage_network') || !is_multisite() && !WYSIJA::current_user_can('switch_themes')) {
         $beta_link = '';
     }
     $wysija_footer_links .= '<div id="upperfoot"><div class="support"><a target="_blank" href="http://support.mailpoet.com/?utm_source=wpadmin&utm_campaign=footer" >' . __('Support', WYSIJA) . '</a>' . $beta_link;
     add_filter('wysija_footer_add_stars', array($this, 'footer_add_stars'), 10);
     $wysija_footer_links .= apply_filters('wysija_footer_add_stars', '');
     $wysija_footer_links .= '<div class="version">' . __('Wysija Version: ', WYSIJA) . '<a href="admin.php?page=wysija_campaigns&action=whats_new">' . WYSIJA::get_version() . '</a></div></div>';
     /*$config=WYSIJA::get('config','model');
       $msg=$config->getValue('ignore_msgs');
       if(!isset($msg['socialfoot'])){
           $wysijaversion .= $this->controller->__get_social_buttons();
       }*/
     $wysija_footer_links .= '</div></div>';
     echo $wysija_footer_links;
 }