コード例 #1
0
ファイル: base.php プロジェクト: sontv1003/fashionbeans
 /**
  * this function get and sets the cron schedules when Wysija's own cron system is active
  * @staticvar type $cron_schedules
  * @param type $schedule
  * @return type
  */
 public static function get_cron_schedule($schedule = 'queue')
 {
     static $cron_schedules;
     //if the cron schedules are already loaded statically then we just have to return the right schedule value
     if (!empty($cron_schedules)) {
         if ($schedule == 'all') {
             return $cron_schedules;
         }
         if (isset($cron_schedules[$schedule])) {
             return $cron_schedules[$schedule];
         } else {
             WYSIJA::set_cron_schedule($schedule);
             return false;
         }
     } else {
         //this is the first time this function is executed so let's get them from the db and store them statically
         $cron_schedules = get_option('wysija_schedules', array());
         if (!empty($cron_schedules)) {
             if (isset($cron_schedules[$schedule])) {
                 return $cron_schedules[$schedule];
             } else {
                 return false;
             }
         } else {
             WYSIJA::set_cron_schedule();
             return false;
         }
     }
     return false;
 }
コード例 #2
0
ファイル: config.php プロジェクト: duboisGeof/deliciousMeals
 /**
  * we have a specific save for option since we are saving it in wordpress options table
  * @param array $data of data to save
  * @param boolean $saved_through_interfaces telling us whether
  */
 function save($data = false, $saved_through_interfaces = false)
 {
     if ($data) {
         // when saving configuration from the settings page we need to make sure that if checkboxes have been unticked we remove the corresponding option
         $bouncing_freq_has_changed = $sending_freq_has_changed = $ms_sending_freq_has_changed = false;
         if ($saved_through_interfaces) {
             $helper_wp_tools = WYSIJA::get('wp_tools', 'helper', false, 'wysija-newsletters', false);
             $editable_roles = $helper_wp_tools->wp_get_roles();
             foreach ($this->capabilities as $keycap => $capability) {
                 foreach ($editable_roles as $role) {
                     $this->cboxes[] = 'rolescap---' . $role['key'] . '---' . $keycap;
                 }
             }
             // if the wysija's cron option has just been turned on from an off value
             // then we check the licence from mailpoet.com to share the cron url with us
             if (isset($data['cron_manual']) && $data['cron_manual'] != $this->getValue('cron_manual')) {
                 $helper_licence = WYSIJA::get('licence', 'helper');
                 $helper_licence->check(true);
             }
             // loop through all of the checkboxes values
             foreach ($this->cboxes as $checkbox) {
                 // set the value as false if the value doesn't exist in the array (happens when checkbox is unchecked)
                 if (!isset($data[$checkbox])) {
                     $data[$checkbox] = $this->values[$checkbox] = false;
                 } else {
                     // otherwise we set it as value 1
                     $data[$checkbox] = $this->values[$checkbox] = 1;
                 }
                 // identify all of the roles checkboxes to update the WP user roles live when changed
                 if (strpos($checkbox, 'rolescap---') !== false) {
                     $role_capability = str_replace('rolescap---', '', $checkbox);
                     $role_capability_exploded = explode('---', $role_capability);
                     $role = get_role($role_capability_exploded[0]);
                     $capability = 'wysija_' . $role_capability_exploded[1];
                     // added for invalid roles ...
                     // this is a rolecap let's add or remove the cap to the role
                     if ($role) {
                         if ($this->values[$checkbox]) {
                             $role->add_cap($capability);
                         } else {
                             // remove cap only for roles different of admins
                             if ($role->has_cap($capability) && !in_array($role_capability_exploded[0], array('administrator', 'super_admin'))) {
                                 $role->remove_cap($capability);
                             }
                         }
                     }
                     // no need to keep these role values in our option, they already are saved in WordPress' roles options
                     unset($this->values[$checkbox]);
                 }
             }
             $helper_user = WYSIJA::get('user', 'helper', false, 'wysija-newsletters', false);
             // validating the from email
             if (isset($data['from_email']) && !$helper_user->validEmail($data['from_email'])) {
                 if (!$data['from_email']) {
                     $data['from_email'] = __('empty', WYSIJA);
                 }
                 $this->error(sprintf(__('The <strong>from email</strong> value you have entered (%1$s) is not a valid email address.', WYSIJA), ''), true);
                 $data['from_email'] = $this->values['from_email'];
             }
             // validating the replyto email
             if (isset($data['replyto_email']) && !$helper_user->validEmail($data['replyto_email'])) {
                 if (!$data['replyto_email']) {
                     $data['replyto_email'] = __('empty', WYSIJA);
                 }
                 $this->error(sprintf(__('The <strong>reply to</strong> email value you have entered (%1$s) is not a valid email address.', WYSIJA), ''), true);
                 $data['replyto_email'] = $this->values['replyto_email'];
             }
             if (isset($data['bounce_rule_action_required_forwardto']) && !$helper_user->validEmail($data['bounce_rule_action_required_forwardto'])) {
                 $this->error('Invalid bounce forward email');
                 $data['bounce_rule_action_required_forwardto'] = $this->values['bounce_rule_action_required_forwardto'];
             }
             if (isset($data['bounce_rule_blocked_ip_forwardto']) && !$helper_user->validEmail($data['bounce_rule_blocked_ip_forwardto'])) {
                 $this->error('Invalid bounce forward email');
                 $data['bounce_rule_blocked_ip_forwardto'] = $this->values['bounce_rule_blocked_ip_forwardto'];
             }
             if (isset($data['bounce_rule_nohandle_forwardto']) && !$helper_user->validEmail($data['bounce_rule_nohandle_forwardto'])) {
                 $this->error('Invalid bounce forward email');
                 $data['bounce_rule_nohandle_forwardto'] = $this->values['bounce_rule_nohandle_forwardto'];
             }
             // in that case the admin changed the frequency of the wysija cron meaning that we need to clear it
             // network's method frequency has changed
             if (isset($data['ms_sending_emails_each']) && $data['ms_sending_emails_each'] != $this->getValue('ms_sending_emails_each')) {
                 $ms_sending_freq_has_changed = true;
                 $data['last_save'] = time();
             }
             // we're on a single site and the sending frequency has been modified
             // we need to refresh the sending scheduled task down below
             if (isset($data['sending_emails_each']) && $data['sending_emails_each'] != $this->getValue('sending_emails_each')) {
                 $sending_freq_has_changed = true;
                 $data['last_save'] = time();
             }
             // we're on a single site and the bounce frequency has been changed
             // we need to refresh the bounce scheduled task down below
             if (isset($data['bouncing_emails_each']) && $data['bouncing_emails_each'] != $this->getValue('bouncing_emails_each')) {
                 $bouncing_freq_has_changed = true;
                 $data['last_save'] = time();
             }
             // if saved with gmail then we set up the smtp settings
             // @deprecated since 2.6.12
             if (isset($data['sending_method'])) {
                 if ($data['sending_method'] == 'gmail') {
                     $data['smtp_host'] = 'smtp.gmail.com';
                     $data['smtp_port'] = '465';
                     $data['smtp_secure'] = 'ssl';
                     $data['smtp_auth'] = true;
                 }
             }
             // basic validation of the smtp_host field
             if (isset($data['smtp_host'])) {
                 $data['smtp_host'] = trim($data['smtp_host']);
             }
             // specific case to identify common action to different rules there some that don't appear in the interface, yet we use them.
             // BEN: this code needs to be reviewed and retested... I know what is the purpose but I don't understand $indexrule and $ruleMain
             foreach ($data as $key => $value) {
                 $fs = 'bounce_rule_';
                 if (strpos($key, $fs) !== false) {
                     if (strpos($key, '_forwardto') === false) {
                         $indexrule = str_replace($fs, '', $key);
                         $helper_rules = WYSIJA::get('rules', 'helper', false, 'wysija-newsletters', false);
                         $rules = $helper_rules->getRules();
                         foreach ($rules as $keyy => $vals) {
                             if (isset($vals['behave'])) {
                                 $ruleMain = $helper_rules->getRules($vals['behave']);
                                 $data[$fs . $vals['key']] = $value;
                             }
                         }
                     }
                 }
             }
             // the regenerate box appeared for old versions of MailPoet where we had to switch from a 512 bits DKIM key to a 1024 for better score with Gmail
             // if the dkim_regenerate box has been ticked then we unset the dkim values so that they are regenerated in the next page load
             if (isset($data['dkim_regenerate']) && $data['dkim_regenerate'] == 'regenerate') {
                 if (isset($this->values['dkim_pubk'])) {
                     unset($data['dkim_pubk']);
                     unset($this->values['dkim_pubk']);
                     unset($data['dkim_privk']);
                     unset($this->values['dkim_privk']);
                     unset($data['dkim_regenerate']);
                 }
             }
             // when we switch the double optin value on to off or off to on, we refresh the total user count which is different in both cases
             if (isset($data['confirm_dbleoptin']) && isset($this->values['confirm_dbleoptin']) && $data['confirm_dbleoptin'] != $this->values['confirm_dbleoptin']) {
                 $helper_user = WYSIJA::get('user', 'helper');
                 $helper_user->refreshUsers();
             }
         }
         $is_multisite = is_multisite();
         $is_network_admin = WYSIJA::current_user_can('manage_network');
         $global_MS_settings = array();
         foreach ($data as $key => $value) {
             // we detect a ms value, so we put it in a separate array to store it somewhere else central
             if ($is_multisite && $is_network_admin && strpos($key, 'ms_') !== false) {
                 $global_MS_settings[$key] = $value;
                 continue;
             }
             // verify that the confirm email body contains an activation link
             // if it doesn't add it at the end of the email
             if ($key == 'confirm_email_body' && strpos($value, '[activation_link]') === false) {
                 $value .= "\n" . '[activation_link]Click here to confirm your subscription.[/activation_link]';
             }
             // I'm not sure why do we do that, we separate the DKIm wrappers from teh value saved in the option.. why not, there must be a reason
             if ($key == 'dkim_pubk') {
                 $value = str_replace(array('-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----', "\n"), '', $value);
             }
             if (is_string($value)) {
                 $value = preg_replace('#< *script(?:(?!< */ *script *>).)*< */ *script *>#isU', '', $value);
                 $value = preg_replace("#<([^><]+?)([^a-z_\\-]on\\w*|xmlns)(\\s*=\\s*[^><]*)([><]*)#i", "<\\1\\4", $value);
             }
             // for the manage subscription option you can select which list appear publicy to the user in their subscription page.
             // this piece of code  make sure that they appear or not
             if ($key == 'manage_subscriptions_lists') {
                 $model_list = WYSIJA::get('list', 'model');
                 $model_list->update(array('is_public' => 0), array('is_public' => 1));
                 $model_list->reset();
                 $model_list->update(array('is_public' => 1), array('list_id' => $value));
                 unset($this->values[$key]);
             }
             // we have a variable in this class which is defaults
             // we save the option only if its value is different than the default one: no need to overload the db.
             if (!isset($this->defaults[$key]) || isset($this->defaults[$key]) && $value != $this->defaults[$key]) {
                 $this->values[$key] = $value;
             } else {
                 unset($this->values[$key]);
             }
         }
         // save the confirmation email in the email table
         // IMPORTANT: once we move the confirmation email to the newsletter listing we can get rid of that
         if (isset($data['confirm_email_title']) && isset($data['confirm_email_body'])) {
             $model_email = WYSIJA::get('email', 'model', false, 'wysija-newsletters', false);
             $is_multisite = is_multisite();
             // the from email on a multisite with the network method on is coming from the ms value
             if ($is_multisite && $data['sending_method'] == 'network') {
                 $from_email = $data['ms_from_email'];
             } else {
                 $from_email = $data['from_email'];
             }
             // updating email
             $model_email->update(array('from_name' => $data['from_name'], 'from_email' => $from_email, 'replyto_name' => $data['replyto_name'], 'replyto_email' => $data['replyto_email'], 'subject' => $data['confirm_email_title'], 'body' => $data['confirm_email_body']), array('email_id' => $this->values['confirm_email_id']));
         }
         unset($this->values['confirm_email_title']);
         unset($this->values['confirm_email_body']);
     }
     // serialize and encode the option's values and save them in WP's options
     update_option($this->name_option, base64_encode(serialize($this->values)));
     // when we are on a multisite, part of the options need to be saved into a global option common to all of the sites
     if ($is_multisite) {
         // the network admin has access to that extra information through the interfaces when does interfaces are generated then $dataMultisite is filled with values
         if (!empty($global_MS_settings)) {
             if ($ms_sending_freq_has_changed) {
                 // if the sending frequency on the network method has changed, we need to update each single cron task on all of the child sites
                 // we reset an array to clear the cron of every single site using the multisite method
                 update_site_option('ms_wysija_sending_cron', array());
             }
             // get the data which was saved in the global option before
             $data_saved_ms_before = unserialize(base64_decode(get_site_option('ms_' . $this->name_option)));
             // if it's not empty we just merge both sets of values
             if (!empty($data_saved_ms_before)) {
                 $global_MS_settings = array_merge($data_saved_ms_before, $global_MS_settings);
             }
             // we save the global ms option
             update_site_option('ms_' . $this->name_option, base64_encode(serialize($global_MS_settings)));
         }
         // let's merge the latest MS modified values with the values of the site's config, this is to avoid a bug after saving
         $data_saved_ms_fresh = unserialize(base64_decode(get_site_option('ms_' . $this->name_option)));
         if (!empty($data_saved_ms_fresh)) {
             $this->values = array_merge($this->values, $data_saved_ms_fresh);
         }
     }
     // the sending frequency has changed on that site's settings let's clear the frequency recorded in WP's and wysija's crons
     if ($sending_freq_has_changed) {
         // WordPress cron clearing
         wp_clear_scheduled_hook('wysija_cron_queue');
         // MailPoet's cron reset
         WYSIJA::set_cron_schedule('queue');
     }
     // same than above but with the bounce frequency
     if ($bouncing_freq_has_changed) {
         // WordPress cron clearing
         wp_clear_scheduled_hook('wysija_cron_bounce');
         // MailPoet's cron reset
         WYSIJA::set_cron_schedule('bounce');
     }
     // if it has been saved through the interface we notify the admin
     if ($saved_through_interfaces) {
         $this->notice(__('Your settings are saved.', WYSIJA));
     }
 }
コード例 #3
0
function wysija_exec_process($process = 'queue')
{
    $scheduled_times = WYSIJA::get_cron_schedule($process);
    if (isset($scheduled_times['running']) && $scheduled_times['running'] && $scheduled_times['running'] + 900 > time()) {
        echo 'already running : ' . $process . '<br/>';
        return;
    }
    //set schedule as running
    WYSIJA::set_cron_schedule($process, 0, time());
    //execute schedule
    switch ($process) {
        case 'queue':
            WYSIJA::croned_queue($process);
            $hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
            if (is_object($hPremium)) {
                $hPremium->splitVersion_croned_queue_process();
            }
            break;
        case 'bounce':
            $hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
            if (is_object($hPremium)) {
                $hPremium->croned_bounce();
            }
            break;
        case 'daily':
            WYSIJA::croned_daily();
            break;
        case 'weekly':
            if (is_object($hPremium)) {
                $hPremium->croned_weekly();
            }
            break;
        case 'monthly':
            WYSIJA::croned_monthly();
            break;
    }
    //set next_schedule
    WYSIJA::set_cron_schedule($process);
    if ($report) {
        echo 'processed : ' . $process . '<br/>';
    }
}
コード例 #4
0
ファイル: cron.php プロジェクト: namwoody/SAAZINDIAN.COM
 /**
  * run process if it's not detected as already running
  * @param type $process
  * @return type
  */
 function run_scheduled_task($process = 'queue')
 {
     //first let's make sure that the process asked to be run is not already running
     $scheduled_times = WYSIJA::get_cron_schedule($process);
     $processes = WYSIJA::get_cron_frequencies();
     $process_frequency = $processes[$process];
     // check if the scheduled task is already being processed,
     // we consider it timed out once the started running time plus the frequency has been passed
     if (!empty($scheduled_times['running']) && $scheduled_times['running'] + $process_frequency > time()) {
         if ($this->report) {
             echo 'already running : ' . $process . '<br/>';
         }
         return;
     }
     // set schedule as running
     WYSIJA::set_cron_schedule($process, 0, time());
     // execute schedule
     switch ($process) {
         case 'queue':
             // check if there are any scheduled newsletters ready for action
             WYSIJA::check_scheduled_newsletters();
             // if premium is activated we execute the premium cron process
             if (defined('WYSIJANLP')) {
                 $helper_premium = WYSIJA::get('premium', 'helper', false, WYSIJANLP);
                 $helper_premium->croned_queue_process();
             } else {
                 // run the standard queue process no scheduled tasks will be check since it has already been checked above
                 WYSIJA::croned_queue(false);
             }
             break;
         case 'bounce':
             $helper_premium = WYSIJA::get('premium', 'helper', false, WYSIJANLP);
             $model_config = WYSIJA::get('config', 'model');
             // if premium is activated we launch the premium function
             if (is_multisite()) {
                 $multisite_prefix = 'ms_';
             }
             // we don't process the bounce automatically unless the option is ticked
             if (defined('WYSIJANLP') && $model_config->getValue($multisite_prefix . 'bounce_process_auto')) {
                 $helper_premium->croned_bounce();
             } else {
                 $process .= ' (bounce handling not activated)';
             }
             break;
         case 'daily':
             WYSIJA::croned_daily();
             break;
         case 'weekly':
             if (defined('WYSIJANLP')) {
                 $helper_premium = WYSIJA::get('premium', 'helper', false, WYSIJANLP);
                 $helper_premium->croned_weekly();
             }
             WYSIJA::croned_weekly();
             break;
         case 'monthly':
             WYSIJA::croned_monthly();
             break;
     }
     // set next_schedule details
     WYSIJA::set_cron_schedule($process);
     if ($this->report) {
         echo 'processed : ' . $process . '<br/>';
     }
 }
コード例 #5
0
ファイル: CONFIG.PHP プロジェクト: pauEscarcia/AIMM
    /**
     * we have a specific save for option since we are saving it in wordpress options table
     * @param type $data
     * @param type $savedThroughInterface
     */
    function save($data=false,$savedThroughInterface=false) {

        if($data){
            //when saving configuration from the settings page we need to make sure that if checkboxes have been unticked we remove the corresponding option
            $bouncing_freq_has_changed=$sending_freq_has_changed=$ms_sending_freq_has_changed=false;
            if($savedThroughInterface){
                $wptools=WYSIJA::get('wp_tools','helper',false,'wysija-newsletters',false);
                $editable_roles=$wptools->wp_get_roles();
                foreach($this->capabilities as $keycap=>$capability){
                    foreach($editable_roles as $role){
                        $this->cboxes[]='rolescap---'.$role['key'].'---'.$keycap;
                    }
                }

                foreach($this->cboxes as $cbox){
                    if(!isset($data[$cbox])){
                        $data[$cbox]=$this->values[$cbox]=false;
                    }else $data[$cbox]=$this->values[$cbox]=1;

                    //this checkbox is of a role type
                    if(strpos($cbox, 'rolescap---')!==false){

                        $rolecap=str_replace('rolescap---','',$cbox);
                        //this is a rolecap let's add or remove the cap to the role
                        $rolecapexp=explode('---', $rolecap);
                        $role=get_role($rolecapexp[0]);
                        $capab='wysija_'.$rolecapexp[1];
                        //added for invalid roles ...
                        if($role){
                            if($this->values[$cbox]){
                                $role->add_cap($capab);
                            }else{
                                //remove cap only for roles different of admins
                                if($role->has_cap($capab) && !in_array($rolecapexp[0], array('administrator','super_admin'))){
                                    $role->remove_cap($capab);
                                }
                            }
                        }
                        //no need to save those values which are already saved in wordpress
                        unset($this->values[$cbox]);
                    }


                }

                $userHelper = WYSIJA::get('user','helper',false,'wysija-newsletters',false);
                if(isset($data['from_email']) && !$userHelper->validEmail($data['from_email'])){
                    if(!$data['from_email']) $data['from_email']=__('empty',WYSIJA);
                    $this->error(sprintf(__('The <strong>from email</strong> value you have entered (%1$s) is not a valid email address.',WYSIJA),$data['from_email']),true);
                    $data['from_email']=$this->values['from_email'];
                }

                if(isset($data['replyto_email']) && !$userHelper->validEmail($data['replyto_email'])){
                    if(!$data['replyto_email']) $data['replyto_email']=__('empty',WYSIJA);
                    $this->error(sprintf(__('The <strong>reply to</strong> email value you have entered (%1$s) is not a valid email address.',WYSIJA),$data['replyto_email']),true);
                    $data['replyto_email']=$this->values['replyto_email'];
                }

                //in that case the admin changed the frequency of the wysija cron meaning that we need to clear it
                //network's method frequency has changed
                if(isset($data['ms_sending_emails_each']) && $data['ms_sending_emails_each']!=$this->getValue('ms_sending_emails_each')){
                    $ms_sending_freq_has_changed=true;
                    $data['last_save']=time();
                }

                //single site sending frequency has been modified
                if(isset($data['sending_emails_each']) && $data['sending_emails_each']!=$this->getValue('sending_emails_each')){
                    $sending_freq_has_changed=true;
                    $data['last_save']=time();
                }

                //bounce frequency has been changed
                if(isset($data['bouncing_emails_each']) && $data['bouncing_emails_each'] != $this->getValue('bouncing_emails_each')){
                    $bouncing_freq_has_changed=true;
                    $data['last_save'] = time();
                }

                //if saved with gmail then we set up the smtp settings
                if(isset($data['sending_method'])){
                    if($data['sending_method']=='gmail') {
                        $data['smtp_host']='smtp.gmail.com';
                        $data['smtp_port']='465';
                        $data['smtp_secure']='ssl';
                        $data['smtp_auth']=true;
                    }
                }

                if(isset($data['smtp_host']))   $data['smtp_host']=trim($data['smtp_host']);

                //specific case to identify common action to different rules there some that doesnt show in the interface, yet we use them.
                foreach($data as $key => $value){
                    $fs='bounce_rule_';
                    if(strpos($key,$fs)!== false){
                        if(strpos($key,'_forwardto')===false){
                            $indexrule=str_replace($fs, '', $key);
                            $helpRules=WYSIJA::get('rules','helper',false,'wysija-newsletters',false);
                            $rules=$helpRules->getRules();
                            foreach($rules as $keyy => $vals){
                                if(isset($vals['behave'])){
                                    $ruleMain=$helpRules->getRules($vals['behave']);
                                    $data[$fs.$vals['key']]=$value;
                                }
                            }
                        }
                    }
                }

                if(!isset($data['emails_notified_when_unsub'])){
                    $data['emails_notified_when_unsub']=false;
                }

                //if the dkim_regenerate box has been ticked then we unset the dkim values so that they are regenerated in the next page load
                if(isset($data['dkim_regenerate']) && $data['dkim_regenerate']=='regenerate'){
                    if(isset($this->values['dkim_pubk']))   {
                        unset($data['dkim_pubk']);
                        unset($this->values['dkim_pubk']);
                        unset($data['dkim_privk']);
                        unset($this->values['dkim_privk']);
                        unset($data['dkim_regenerate']);
                    }
                }
            }
            $is_multisite=is_multisite();
            $is_network_admin=WYSIJA::current_user_can('manage_network');
            $dataMultisite=array();
            foreach($data as $key => $value){
                //store the ms values somewhere central
                //$is_multisite=$is_network_admin=true;//PROD comment that line
                if($is_multisite && $is_network_admin && strpos($key, 'ms_')!==false){
                    $dataMultisite[$key]=$value;
                    continue;
                }

                //verify that the confirm email body contains an activation link if it doesn't add i at the end of the email
                if($key=='confirm_email_body' && strpos($value, '[activation_link]')=== false){
                    //the activation link was not found
                    $value.="\n".'[activation_link]Click here to confirm your subscription.[/activation_link]';
                }

                if($key=='dkim_pubk'){
                    $value = str_replace(array('-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----',"\n"),'',$value);
                }

                if($key=='manage_subscriptions_lists'){
                    $mList=WYSIJA::get('list','model');
                    $mList->update(array('is_public'=>0),array('is_public'=>1));
                    $mList->reset();
                    $mList->update(array('is_public'=>1),array('list_id'=>$value));

                    unset($this->values[$key]);
                }

                if(is_string($value)) $value=$value;
                //we save it only if it is different than the default no need to overload the db
                if(!isset($this->defaults[$key]) || (isset($this->defaults[$key]) && $value!=$this->defaults[$key])){
                    $this->values[$key]=  $value;
                }else{
                    unset($this->values[$key]);
                }
            }


            //save the confirmation email in the email table
            if(isset($data['confirm_email_title']) && isset($data['confirm_email_body'])){
                $mailModel=WYSIJA::get('email','model',false,'wysija-newsletters',false);
                $is_multisite=is_multisite();

                //$is_multisite=true;//PROD comment that line
                if($is_multisite && $data['sending_method']=='network') {

                    $from_email=$data['ms_from_email'];
                }
                else $from_email=$data['from_email'];
                $mailModel->update(array('from_name'=>$data['from_name'],'from_email'=>$from_email, 'replyto_name'=>$data['replyto_name'],'replyto_email'=>$data['replyto_email'],
                    'subject'=>$data['confirm_email_title'],'body'=>$data['confirm_email_body']),array('email_id'=>$this->values['confirm_email_id']));
            }
            unset($this->values['confirm_email_title']);
            unset($this->values['confirm_email_body']);
        }

        //serialize and encode the option's values and save them in WP's options
        update_option($this->name_option,base64_encode(serialize($this->values)));

        //we are in a multisite case
        if($is_multisite){
            //the network admin has access to that extra information through the interfaces when does interfaces are generated then $dataMultisite is filled with values
            if(!empty($dataMultisite)){
                if($ms_sending_freq_has_changed){
                    //we reset an array to clear the cron of every single site using the multisite method
                    update_site_option('ms_wysija_sending_cron',array());
                }
                $data_saved_ms_before= unserialize(base64_decode(get_site_option('ms_'.$this->name_option)));
                if(!empty($data_saved_ms_before))   $dataMultisite=array_merge($data_saved_ms_before, $dataMultisite);
                update_site_option('ms_'.$this->name_option,base64_encode(serialize($dataMultisite)));
            }

            //let's merge the latest MS modified values with the values of the site's config, this is to avoid a bug after saving
            $data_saved_ms_fresh=unserialize(base64_decode(get_site_option('ms_'.$this->name_option)));
            if(!empty($data_saved_ms_fresh))    $this->values=array_merge($this->values, $data_saved_ms_fresh);
        }

        //the sending frequency has changed on that site's settings let's clear the frequency recorded in WP's and wysija's crons
        if($sending_freq_has_changed){
            wp_clear_scheduled_hook('wysija_cron_queue');
            WYSIJA::set_cron_schedule('queue');
        }

        //same than above but with the bounce frequency
        if($bouncing_freq_has_changed){
            wp_clear_scheduled_hook('wysija_cron_bounce');
            WYSIJA::set_cron_schedule('bounce');
        }

        //if it has been saved through the interface we notify the admin
        if($savedThroughInterface)  $this->notice(__('Your settings are saved.',WYSIJA));
    }
コード例 #6
0
ファイル: cron.php プロジェクト: sontv1003/fashionbeans
 function run_scheduled_task($process = 'queue')
 {
     $scheduled_times = WYSIJA::get_cron_schedule($process);
     if (isset($scheduled_times['running']) && $scheduled_times['running'] && $scheduled_times['running'] + 900 > time()) {
         if ($this->report) {
             echo 'already running : ' . $process . '<br/>';
         }
         return;
     }
     WYSIJA::set_cron_schedule($process, 0, time());
     switch ($process) {
         case 'queue':
             WYSIJA::croned_queue($process);
             if (defined('WYSIJANLP')) {
                 $hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
                 $hPremium->croned_queue_process();
             }
             break;
         case 'bounce':
             if (defined('WYSIJANLP')) {
                 $hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
                 $hPremium->croned_bounce();
             }
             break;
         case 'daily':
             WYSIJA::croned_daily();
             break;
         case 'weekly':
             if (defined('WYSIJANLP')) {
                 $hPremium =& WYSIJA::get('premium', 'helper', false, WYSIJANLP);
                 $hPremium->croned_weekly();
             }
             WYSIJA::croned_weekly();
             break;
         case 'monthly':
             WYSIJA::croned_monthly();
             break;
     }
     WYSIJA::set_cron_schedule($process);
     if ($this->report) {
         echo 'processed : ' . $process . '<br/>';
     }
 }
コード例 #7
0
ファイル: config.php プロジェクト: fwelections/fwelections
 /**
  * we have a specific save for option since we are saving it in wordpress options table
  * @param type $data
  * @param type $savedThroughInterface
  */
 function save($data = false, $savedThroughInterface = false)
 {
     if ($data) {
         /* when saving configuration from the settings page we need to make sure that if checkboxes have been unticked we remove the corresponding option */
         if ($savedThroughInterface) {
             $bouncing_freq_has_changed = $sending_freq_has_changed = false;
             $wptools =& WYSIJA::get('wp_tools', 'helper', false, 'wysija-newsletters', false);
             $editable_roles = $wptools->wp_get_roles();
             foreach ($this->capabilities as $keycap => $capability) {
                 foreach ($editable_roles as $role) {
                     $this->cboxes[] = 'rolescap---' . $role['key'] . '---' . $keycap;
                 }
             }
             foreach ($this->cboxes as $cbox) {
                 if (!isset($data[$cbox])) {
                     $this->values[$cbox] = false;
                 } else {
                     $this->values[$cbox] = 1;
                 }
                 /*this checkbox is of a role type*/
                 if (strpos($cbox, 'rolescap---') !== false) {
                     $rolecap = str_replace('rolescap---', '', $cbox);
                     //this is a rolecap let's add or remove the cap to the role
                     $rolecapexp = explode('---', $rolecap);
                     $role = get_role($rolecapexp[0]);
                     $capab = 'wysija_' . $rolecapexp[1];
                     //added for invalid roles ...
                     if ($role) {
                         if ($this->values[$cbox]) {
                             $role->add_cap($capab);
                         } else {
                             //remove cap only for roles different of admins
                             if ($role->has_cap($capab) && !in_array($rolecapexp[0], array('administrator', 'super_admin'))) {
                                 $role->remove_cap($capab);
                             }
                         }
                     }
                     //no need to save those values which are already saved in wordpress
                     unset($this->values[$cbox]);
                 }
             }
             $userHelper =& WYSIJA::get('user', 'helper', false, 'wysija-newsletters', false);
             if (isset($data['from_email']) && !$userHelper->validEmail($data['from_email'])) {
                 if (!$data['from_email']) {
                     $data['from_email'] = __('empty', WYSIJA);
                 }
                 $this->error(sprintf(__('The <strong>from email</strong> value you have entered (%1$s) is not a valid email address.', WYSIJA), $data['from_email']), true);
                 $data['from_email'] = $this->values['from_email'];
             }
             if (isset($data['replyto_email']) && !$userHelper->validEmail($data['replyto_email'])) {
                 if (!$data['replyto_email']) {
                     $data['replyto_email'] = __('empty', WYSIJA);
                 }
                 $this->error(sprintf(__('The <strong>reply to</strong> email value you have entered (%1$s) is not a valid email address.', WYSIJA), $data['replyto_email']), true);
                 $data['replyto_email'] = $this->values['replyto_email'];
             }
             /* in that case the admin changed the frequency of the wysija cron meaning that we need to clear it */
             if ($data['sending_emails_each'] != $this->getValue('sending_emails_each')) {
                 $sending_freq_has_changed = true;
                 $data['last_save'] = time();
             }
             if (isset($data['bouncing_emails_each']) && $data['bouncing_emails_each'] != $this->getValue('bouncing_emails_each')) {
                 $bouncing_freq_has_changed = true;
                 $data['last_save'] = time();
             }
             /* if saved with gmail then we set up the smtp settings */
             if ($data['sending_method'] == 'gmail') {
                 $data['smtp_host'] = 'smtp.gmail.com';
                 $data['smtp_port'] = '465';
                 $data['smtp_secure'] = 'ssl';
                 $data['smtp_auth'] = true;
             }
             $data['smtp_host'] = trim($data['smtp_host']);
             /* specific case to identify common action to different rules there some that doesnt show in the interface, yet we use them.*/
             foreach ($data as $key => $value) {
                 $fs = 'bounce_rule_';
                 if (strpos($key, $fs) !== false) {
                     if (strpos($key, '_forwardto') === false) {
                         $indexrule = str_replace($fs, '', $key);
                         $helpRules =& WYSIJA::get('rules', 'helper', false, 'wysija-newsletters', false);
                         $rules = $helpRules->getRules();
                         foreach ($rules as $keyy => $vals) {
                             if (isset($vals['behave'])) {
                                 $ruleMain = $helpRules->getRules($vals['behave']);
                                 $data[$fs . $vals['key']] = $value;
                             }
                         }
                     }
                 }
             }
             if (!isset($data['emails_notified_when_unsub'])) {
                 $data['emails_notified_when_unsub'] = false;
             }
         }
         foreach ($data as $key => $value) {
             /*verify that the confirm email body contains an activation link if it doesn't add i at the end of the email*/
             if ($key == 'confirm_email_body' && strpos($value, '[activation_link]') === false) {
                 /*the activation link was not found*/
                 $value .= "\n" . '[activation_link]Click here to confirm your subscription.[/activation_link]';
             }
             if ($key == 'dkim_pubk') {
                 $value = str_replace(array('-----BEGIN PUBLIC KEY-----', '-----END PUBLIC KEY-----', "\n"), '', $value);
             }
             if ($key == 'manage_subscriptions_lists') {
                 $mList =& WYSIJA::get('list', 'model');
                 $mList->update(array('is_public' => 0), array('is_public' => 1));
                 $mList->reset();
                 $mList->update(array('is_public' => 1), array('list_id' => $value));
                 unset($this->values[$key]);
             }
             if (is_string($value)) {
                 $value = $value;
             }
             /* we save it only if it is different than the default no need to overload the db*/
             if (!isset($this->defaults[$key]) || isset($this->defaults[$key]) && $value != $this->defaults[$key]) {
                 $this->values[$key] = $value;
             } else {
                 unset($this->values[$key]);
             }
         }
         /* save the confirmation email in the email table */
         if (isset($data['confirm_email_title']) && isset($data['confirm_email_body'])) {
             $mailModel =& WYSIJA::get('email', 'model', false, 'wysija-newsletters', false);
             $mailModel->update(array('from_name' => $data['from_name'], 'from_email' => $data['from_email'], 'replyto_name' => $data['replyto_name'], 'replyto_email' => $data['replyto_email'], 'subject' => $data['confirm_email_title'], 'body' => $data['confirm_email_body']), array('email_id' => $this->values['confirm_email_id']));
         }
         unset($this->values['confirm_email_title']);
         unset($this->values['confirm_email_body']);
     }
     update_option($this->name_option, base64_encode(serialize($this->values)));
     if ($savedThroughInterface) {
         if ($bouncing_freq_has_changed) {
             wp_clear_scheduled_hook('wysija_cron_bounce');
             WYSIJA::set_cron_schedule('bounce');
         }
         if ($sending_freq_has_changed) {
             wp_clear_scheduled_hook('wysija_cron_queue');
             WYSIJA::set_cron_schedule('queue');
         }
         $this->notice(__('Your Wysija settings have been updated!', WYSIJA));
     }
 }
コード例 #8
0
ファイル: base.php プロジェクト: fwelections/fwelections
 public static function get_cron_schedule($schedule = 'queue')
 {
     static $cron_schedules;
     if (!empty($cron_schedules)) {
         if ($schedule == 'all') {
             return $cron_schedules;
         }
         if (isset($cron_schedules[$schedule])) {
             return $cron_schedules[$schedule];
         } else {
             WYSIJA::set_cron_schedule($schedule);
             return false;
         }
     } else {
         $cron_schedules = get_option('wysija_schedules', array());
         if (!empty($cron_schedules)) {
             if (isset($cron_schedules[$schedule])) {
                 return $cron_schedules[$schedule];
             } else {
                 return false;
             }
         } else {
             WYSIJA::set_cron_schedule();
             return false;
         }
     }
     return false;
 }