function send_test_editor($dataPost = false) { $modelQ =& WYSIJA::get("queue", "model"); $config =& WYSIJA::get("config", "model"); $premium = $config->getValue('premium_key'); $subscribers = (int) $config->getValue('total_subscribers'); if ($subscribers < 2000 || $premium && $subscribers >= 2000) { if ($modelQ->count() > 0) { $helperQ =& WYSIJA::get("queue", "helper"); $emailid = false; if ($_REQUEST['emailid']) { $emailid = $_REQUEST['emailid']; } WYSIJA::log('Don\'t wait and send now queue process', array('email_id' => $emailid)); $helperQ->process($emailid); } else { echo "<strong>" . __("Queue is empty!", WYSIJA) . "</strong>"; } } else { echo "<strong>" . __("Go premium, you cannot send anymore!", WYSIJA) . "</strong>"; } exit; }
/** * erase an array of queue elements from the database * @param array $queue_delete * @return boolean */ function _deleteQueue($queue_delete) { if (empty($queue_delete)) { return true; } $status = true; $modelQ = WYSIJA::get('queue', 'model'); foreach ($queue_delete as $email_id => $subscribers) { $nbsub = count($subscribers); //$res=$modelQ->delete(array("email_id"=>intval($email_id),"user_id"=>$subscribers)); //$realquery='DELETE a.* FROM `[wysija]queue` as a LEFT JOIN `[wysija]email` as b on a.email_id = b.email_id WHERE b.email_id IS NULL'; $real_query = 'DELETE FROM `[wysija]queue` WHERE email_id = ' . intval($email_id) . ' AND user_id IN (' . implode(',', $subscribers) . ') LIMIT ' . $nbsub; WYSIJA::log('helpers -> Queue ->process ->deleteQueue', $real_query, 'queue_process'); $res = $modelQ->query($real_query); if (!$res) { $status = false; WYSIJA::log('helpers -> Queue ->process ->deleteQueue failed', true, 'queue_process'); //$this->_display($this->db->getErrorNum.' : '.$this->db->getErrorMsg()); } else { WYSIJA::log('deleting queue ok', array('email_id' => $email_id, 'subscribers' => $subscribers), 'queue_process'); $nbdeleted = $modelQ->getAffectedRows(); if ($nbdeleted != $nbsub) { $status = false; $this->_display(__('Newsletters are already being sent. Your latest newsletter will be sent afterwards.', WYSIJA)); } } } return $status; }
function insertAutoQueue($user_id, $email_id, $email_params_autonl) { $model_queue =& WYSIJA::get('queue', 'model'); $queueData = array('priority' => '-1', 'email_id' => $email_id, 'user_id' => $user_id); $delay = $model_queue->calculate_delay($email_params_autonl); $queueData['send_at'] = time() + $delay; if (!$model_queue->exists(array('email_id' => $email_id, 'user_id' => $user_id))) { if (isset($email_params_autonl['unique_send']) && $email_params_autonl['unique_send']) { $modelEUS =& WYSIJA::get('email_user_stat', 'model'); if (!$modelEUS->exists(array('email_id' => $email_id, 'user_id' => $user_id))) { $model_queue->insert($queueData, true); } } else { $model_queue->insert($queueData, true); } } if ($delay == 0) { $queueH =& WYSIJA::get('queue', 'helper'); $queueH->report = false; WYSIJA::log('insertAutoQueue queue process', array('email_id' => $email_id, 'user_id' => $user_id), 'queue_process'); $queueH->process($email_id, $user_id); } }
function send_preview($spamtest = false) { $mailer =& WYSIJA::get('mailer', 'helper'); $email_id = $_REQUEST['id']; $resultarray = array(); // update data in DB $modelEmail =& WYSIJA::get('email', 'model'); $modelEmail->getFormat = OBJECT; $emailObject = $modelEmail->getOne(false, array('email_id' => $email_id)); $mailer->testemail = true; if (isset($_REQUEST['data'])) { $dataTemp = $_REQUEST['data']; $_REQUEST['data'] = array(); foreach ($dataTemp as $val) { $_REQUEST['data'][$val['name']] = $val['value']; } $dataTemp = null; foreach ($_REQUEST['data'] as $k => $v) { $newkey = str_replace(array('wysija[email][', ']'), '', $k); $configVal[$newkey] = $v; } if (isset($configVal['from_name'])) { $params = array('from_name' => $configVal['from_name'], 'from_email' => $configVal['from_email'], 'replyto_name' => $configVal['replyto_name'], 'replyto_email' => $configVal['replyto_email']); if (isset($configVal['subject'])) { $emailObject->subject = $configVal['subject']; } } } else { $params = array('from_name' => $emailObject->from_name, 'from_email' => $emailObject->from_email, 'replyto_name' => $emailObject->replyto_name, 'replyto_email' => $emailObject->replyto_email); } if (strpos($_REQUEST['receiver'], ',')) { $receivers = explode(',', $_REQUEST['receiver']); } else { if (strpos($_REQUEST['receiver'], ';')) { $receivers = explode(';', $_REQUEST['receiver']); } else { $receivers = array($_REQUEST['receiver']); } } foreach ($receivers as $key => $receiver) { $receivers[$key] = trim($receiver); $dummyReceiver = new stdClass(); $dummyReceiver->user_id = 0; $dummyReceiver->email = $receiver; $dummyReceiver->status = 1; $dummyReceiver->lastname = $dummyReceiver->firstname = $langextra = ''; if ($spamtest) { $dummyReceiver->firstname = 'Mail Tester'; if (defined('WPLANG') && WPLANG) { $langextra = '&lang=' . WPLANG; } $resultarray['urlredirect'] = 'http://www.mail-tester.com/check.php?id=' . urlencode($dummyReceiver->email) . $langextra; } $receivers[$key] = $dummyReceiver; } $emailClone = array(); foreach ($emailObject as $kk => $vv) { $emailClone[$kk] = $vv; } $wjEngine =& WYSIJA::get('wj_engine', 'helper'); // set data & styles if (isset($emailClone['wj_data'])) { $wjEngine->setData($emailClone['wj_data'], true); } else { $wjEngine->setData(); } if (isset($emailClone['wj_styles'])) { $wjEngine->setStyles($emailClone['wj_styles'], true); } else { $wjEngine->setStyles(); } // generate email html body $body = $wjEngine->renderEmail($emailClone); // get back email data as it will be updated during the rendering (articles ids + articles count) $emailChild = $wjEngine->getEmailData(); if ((int) $emailChild['type'] === 2 && isset($emailChild['params']['autonl']['articles'])) { $itemCount = 0; $totalCount = 1; $firstSubject = ''; if (isset($emailChild['params']['autonl']['articles']['count'])) { $itemCount = (int) $emailChild['params']['autonl']['articles']['count']; } if (isset($emailChild['params']['autonl']['articles']['first_subject'])) { $firstSubject = $emailChild['params']['autonl']['articles']['first_subject']; } if (isset($emailClone['params']['autonl']['total_child'])) { $totalCount = (int) $emailClone['params']['autonl']['total_child'] + 1; } if (empty($firstSubject)) { $this->error(__('There are no articles to be sent in this email.', WYSIJA), 1); return array('result' => false); } $emailObject->subject = str_replace(array('[total]', '[number]', '[post_title]'), array($itemCount, $totalCount, $firstSubject), $emailChild['subject']); } $successmsg = __('Your email preview has been sent to %1$s', WYSIJA); if (isset($emailObject->params)) { $params['params'] = $emailObject->params; if (isset($configVal['params[googletrackingcode'])) { $paramsemail = array(); if (!is_array($emailObject->params)) { $paramsemail = unserialize(base64_decode($emailObject->params)); } if (trim($configVal['params[googletrackingcode'])) { $paramsemail['googletrackingcode'] = $configVal['params[googletrackingcode']; } else { unset($paramsemail['googletrackingcode']); } $params['params'] = base64_encode(serialize($paramsemail)); } } $params['email_id'] = $emailObject->email_id; $receiversList = array(); $res = false; foreach ($receivers as $receiver) { if ($mailer->sendSimple($receiver, stripslashes($emailObject->subject), $emailObject->body, $params)) { $res = true; $receiversList[] = $receiver->email; } WYSIJA::log('preview_sent', $mailer, 'manual'); } if ($res === true) { $this->notice(sprintf($successmsg, implode(', ', $receiversList))); } $resultarray['result'] = $res; return $resultarray; }
function insertAutoQueue($user_id, $email_id, $emailparams) { $modelQueue =& WYSIJA::get('queue', 'model'); $queueData = array('priority' => '-1', 'email_id' => $email_id, 'user_id' => $user_id); $delay = 0; if (isset($emailparams['numberafter']) && (int) $emailparams['numberafter'] > 0) { switch ($emailparams['numberofwhat']) { case 'immediate': $delay = 0; break; case 'hours': $delay = (int) $emailparams['numberafter'] * 3600; break; case 'days': $delay = (int) $emailparams['numberafter'] * 3600 * 24; break; case 'weeks': $delay = (int) $emailparams['numberafter'] * 3600 * 24 * 7; break; } $queueData['send_at'] = time() + $delay; } if (isset($emailparams['unique_send']) && $emailparams['unique_send']) { $modelEUS =& WYSIJA::get('email_user_stat', 'model'); if (!$modelEUS->exists(array('email_id' => $email_id, 'user_id' => $user_id))) { $modelQueue->insert($queueData); } } else { $modelQueue->insert($queueData); } if ($delay == 0) { $queueH =& WYSIJA::get('queue', 'helper'); $queueH->report = false; WYSIJA::log('insertAutoQueue queue process', array('email_id' => $email_id, 'user_id' => $user_id)); $queueH->process($email_id, $user_id); } return true; }
/** * used in post notification scheme, it uses the model email to create a child to send when ready * @param array $email * @param boolean $immediatePostNotif * @return int next send value */ function give_birth($email, $immediatePostNotif = false) { WYSIJA::log('give_birth_starts', $email['params']['autonl']['nextSend'], 'post_notif'); //duplicate email with the right body and title set it as type 1 if (isset($email['params']) && !is_array($email['params'])) { $this->getParams($email); } $emailChild = $email; $paramsVal = $email['params']; if (!isset($paramsVal['autonl']['total_child'])) { $paramsVal['autonl']['total_child'] = 0; } $paramsVal['autonl']['total_child']++; unset($emailChild['email_id']); unset($emailChild['created_at']); $emailChild['type'] = 1; $emailChild['status'] = 99; $emailChild['sent_at'] = time(); $this->reset(); unset($emailChild['params']['autonl']); // get articles ids used in previously sent childs $ids = !empty($paramsVal['autonl']['articles']['ids']) ? $paramsVal['autonl']['articles']['ids'] : array(); // build autonl articles params for child $emailChild['params']['autonl']['articles'] = array('ids' => $ids, 'count' => 0, 'first_subject' => ''); if (isset($email['params']['autonl']['firstSend'])) { $emailChild['params']['autonl']['firstSend'] = $email['params']['autonl']['firstSend']; } if (isset($email['params']['autonl']['lastSend'])) { $emailChild['params']['autonl']['lastSend'] = $email['params']['autonl']['lastSend']; } //if it's an immediate post notif let know the render email if ($immediatePostNotif) { $emailChild['params']['autonl']['articles']['immediatepostid'] = (int) $immediatePostNotif; //if this article is already set there is no reason to give birth to a child email if (isset($email['params']['autonl']['articles']['ids']) && in_array($immediatePostNotif, $email['params']['autonl']['articles']['ids'])) { return false; } } $wjEngine = WYSIJA::get('wj_engine', 'helper'); // set data & styles if (isset($emailChild['wj_data'])) { $wjEngine->setData($emailChild['wj_data'], true); } else { $wjEngine->setData(); } if (isset($emailChild['wj_styles'])) { $wjEngine->setStyles($emailChild['wj_styles'], true); } else { $wjEngine->setStyles(); } // generate email html body $body = $wjEngine->renderEmail($emailChild); // get back email data as it will be updated during the rendering (articles ids + articles count) $emailChild = $wjEngine->getEmailData(); $emailChild['body'] = $body; // update parent email articles' ids to reflect the ones added in the child email $paramsVal['autonl']['articles']['ids'] = $emailChild['params']['autonl']['articles']['ids']; // added new_ids parameter in order to know which articles are being used in that newsletter for instance with shortcodes if (!empty($email['params']['autonl']['articles']['ids'])) { $emailChild['params']['autonl']['articles']['new_ids'] = array_diff($emailChild['params']['autonl']['articles']['ids'], $email['params']['autonl']['articles']['ids']); } else { $emailChild['params']['autonl']['articles']['new_ids'] = $emailChild['params']['autonl']['articles']['ids']; } $donotsend = false; // if there's no article, do not send if ((int) $emailChild['params']['autonl']['articles']['count'] === 0) { $donotsend = true; } // we send if not told to not do it if (!$donotsend) { // Parse old subject shortcodes. $emailChild['subject'] = str_replace(array('[total]', '[number]', '[post_title]'), array((int) $emailChild['params']['autonl']['articles']['count'], (int) $paramsVal['autonl']['total_child'], $emailChild['params']['autonl']['articles']['first_subject']), $emailChild['subject']); $emailChild['params']['autonl']['total_child'] = (int) $paramsVal['autonl']['total_child']; // Get the email object, needed for the shortcode class. $current_email_object = (object) $emailChild; // Parse subject shortcodes. $helper_mailer = WYSIJA::get('mailer', 'helper'); $helper_mailer->parseSubjectUserTags($current_email_object); // Replace subject shortcodes. $helper_shortcodes = WYSIJA::get('shortcodes', 'helper'); $emailChild['subject'] = $helper_shortcodes->replace_subject($current_email_object); // save the child email $emailChild['params']['autonl']['parent'] = $email['email_id']; $this->dbg = false; //this line is to correct the crazy color so that it doesn't use the keepQry function. $emailChild['email_id'] = $this->insert($emailChild); $this->reset(); WYSIJA::log('check_post_notif_give_birth_before_send', $emailChild, 'post_notif'); $this->send_activate($emailChild); } WYSIJA::log('prev_send_value_give_birth', $email['params']['autonl']['nextSend'], 'post_notif'); // update the parent with the new nextSend date $auton = WYSIJA::get('autonews', 'helper'); $nextSendValue = $auton->getNextSend($email); WYSIJA::log('next_send_value_give_birth', $nextSendValue, 'post_notif'); //update the parent email only it has been sent if (!$donotsend) { $paramsVal['autonl']['nextSend'] = $nextSendValue; if (isset($paramsVal['autonl']['late_send'])) { unset($paramsVal['autonl']['late_send']); } $this->reset(); //we use to have a filter compared to the first send date, but we should have a filter to the lastSend date instead if (!isset($email['params']['autonl']['firstSend'])) { $paramsVal['autonl']['firstSend'] = time(); } $paramsVal['autonl']['lastSend'] = time(); $this->update(array('params' => $paramsVal), array('email_id' => $email['email_id'])); } return $nextSendValue; }
/** * email has a late post notification which needs to be cancelled and postponed * @param array $email * @param int $how_late * @return boolean */ function cancel_late_post_notification($email, $how_late) { $cancel_it = false; switch ($email['params']['autonl']['when-article']) { case 'daily': //cancel a daily notification with more than two hours delay if ($how_late > 2 * 3600) { $cancel_it = true; } break; case 'weekly': //cancel a weekly notification with more than half a day delay if ($how_late > 12 * 3600) { $cancel_it = true; } break; case 'monthly': //cancel a monthly notification with more than a day delay if ($how_late > 24 * 3600) { $cancel_it = true; } break; case 'monthlyevery': //cancel a monthly notification with more than a day delay if ($how_late > 24 * 3600) { $cancel_it = true; } break; } //if the notification is being cancelled then we store the value of that late notification and update the nextSend if ($cancel_it) { $late_send = $email['params']['autonl']['nextSend']; WYSIJA::log('cancel_late_post_notification_late_send', $late_send, 'post_notif'); $next_send = $this->getNextSend($email); $email['params']['autonl']['nextSend'] = $next_send; $email['params']['autonl']['late_send'] = $late_send; $model_email = WYSIJA::get('email', 'model'); $model_email->reset(); $model_email->update(array('params' => $email['params']), array('email_id' => $email['email_id'])); return true; } return false; }
/** * this is used when we want to send the email immediately after inserting it into the queue * @param int $user_id * @param int $email_id * @param array $email_params_autonl * @return void */ function insertAutoQueue($user_id,$email_id,$email_params_autonl){ $model_queue=WYSIJA::get('queue','model'); $queueData=array('priority'=>'-1','email_id'=>$email_id,'user_id'=>$user_id); $delay=$model_queue->calculate_delay($email_params_autonl); $queueData['send_at']=time()+$delay; if(!$model_queue->exists(array('email_id'=>$email_id,'user_id'=>$user_id))){ //check if the email can be sent more than once if(isset($email_params_autonl['unique_send']) && $email_params_autonl['unique_send']){ //check if the email has been sent to the user email_user_stat $modelEUS=WYSIJA::get('email_user_stat','model'); if(!$modelEUS->exists(array('email_id'=>$email_id,'user_id'=>$user_id))) $model_queue->insert($queueData,true); }else{ $model_queue->insert($queueData,true); } } //if delay is = to 0 then we need to try to send the email straight away if($delay==0){ $queueH=WYSIJA::get('queue','helper'); $queueH->report=false; WYSIJA::log('insertAutoQueue queue process',array('email_id'=>$email_id,'user_id'=>$user_id),'queue_process'); $queueH->process($email_id,$user_id); } }
function _deleteQueue($queueDelete) { if (empty($queueDelete)) { return true; } $status = true; $modelQ =& WYSIJA::get("queue", "model"); foreach ($queueDelete as $email_id => $subscribers) { $nbsub = count($subscribers); $realquery = 'DELETE FROM `[wysija]queue` WHERE email_id = ' . intval($email_id) . ' AND user_id IN (' . implode(',', $subscribers) . ') LIMIT ' . $nbsub; WYSIJA::log('helpers -> Queue ->process ->deleteQueue', $realquery); $res = $modelQ->query($realquery); if (!$res) { $status = false; WYSIJA::log('helpers -> Queue ->process ->deleteQueue failed', true); } else { WYSIJA::log('deleting queue ok', array('email_id' => $email_id, 'subscribers' => $subscribers)); $nbdeleted = $modelQ->getAffectedRows(); if ($nbdeleted != $nbsub) { $status = false; $this->_display(__("Newsletters are already being sent. Your latest newsletter will be sent afterwards.", WYSIJA)); } } } return $status; }
function logError(){ if(defined('WYSIJA_DBG') && WYSIJA_DBG>1){ global $wysija_queries_errors, $wpdb; if(!$wysija_queries_errors) $wysija_queries_errors=array(); $this->sql_error=mysql_error($wpdb->dbh); if($this->sql_error) { $wysija_queries_errors[]=$this->sql_error; WYSIJA::log('queries_errors',$this->sql_error,'query_errors'); } } }
/** * post notification transition hook, know when a post really gets published * @param type $new_status * @param type $old_status * @param type $post * @return type */ public static function hook_postNotification_transition($new_status, $old_status, $post) { //we run some process only if the status of the post changes from something to publish if ($new_status === 'publish' && $old_status !== $new_status) { $model_email = WYSIJA::get('email', 'model'); $emails = $model_email->get(false, array('type' => 2, 'status' => array(1, 3, 99))); if (!empty($emails)) { //we loop through all of the automatic emails foreach ($emails as $key => $email) { //we will try to give birth to a child email only if the automatic newsletter is a post notification email and in immediate mode if (is_array($email) && $email['params']['autonl']['event'] === 'new-articles' && $email['params']['autonl']['when-article'] === 'immediate') { // set default include/exclude categories $include_category_ids = array(); $exclude_category_ids = array(); // ALC need to check for post_type on each block of the autoposts $wj_data = maybe_unserialize(base64_decode($email['wj_data'])); $post_types = array(); $has_alc_blocks = false; foreach ($wj_data['body'] as $block_key => $block) { if ($block['type'] !== 'auto-post') { continue; } $has_alc_blocks = true; // get post type and post categories from block parameters foreach ($block['params'] as $param_data) { if (in_array($param_data['key'], array('post_type', 'cpt')) && strlen(trim($param_data['value'])) > 0) { // store post type $post_types[] = trim($param_data['value']); } else { if ($param_data['key'] === 'category_ids' && strlen(trim($param_data['value'])) > 0) { // store post category ids $include_category_ids = array_map('intval', explode(',', trim($param_data['value']))); } } } } if ($has_alc_blocks === true && !in_array($post->post_type, $post_types)) { continue; } // get post categories $helper_wp_tools = WYSIJA::get('wp_tools', 'helper'); $taxonomies = $helper_wp_tools->get_post_category_ids($post); // assume the post has to be sent $do_send_post = true; // post categories have to match at least one of the email's included categories $include_intersection = array_intersect($taxonomies, $include_category_ids); if (!empty($include_category_ids) && empty($include_intersection)) { $do_send_post = false; } $exclude_intersection = array_intersect($taxonomies, $exclude_category_ids); // post categories should not match any one of the email's excluded categories if (!empty($exclude_category_ids) && !empty($exclude_intersection)) { $do_send_post = false; } if ($do_send_post) { WYSIJA::log('post_transition_hook_give_birth', array('post_id' => $post->ID, 'post_title' => $post->post_title, 'newsletter' => $email, 'old_status' => $old_status, 'new_status' => $new_status), 'post_notif'); $model_email->reset(); $model_email->give_birth($email, $post->ID); } } } } // we check for automatic latest content widget in automatic newsletter $helper_autonews = WYSIJA::get('autonews', 'helper'); $helper_autonews->refresh_automatic_content(); } return true; }
function logError() { if (defined('WYSIJA_DBG') && WYSIJA_DBG > 1) { global $wysija_queries_errors, $wpdb; if (!$wysija_queries_errors) { $wysija_queries_errors = array(); } $this->sql_error = $wpdb->last_error; if ($this->sql_error && (empty($this->last_error) || $this->last_error != $this->sql_error)) { $this->last_error = $wysija_queries_errors[] = $this->sql_error; $this->sql_error = false; WYSIJA::log('queries_errors', $this->sql_error, 'query_errors'); } } }
function get_posts($args = array()) { if (!$args) { return false; } $customQuery = ''; /** * SELECT A.ID, A.post_title, A.post_content, A.post_date FROM `wp_posts` A * LEFT JOIN `wp_term_relationships` B ON (A.ID = B.object_id) * LEFT JOIN `wp_term_taxonomy` C ON (C.term_taxonomy_id = B.term_taxonomy_id) * WHERE C.term_id IN (326) AND A.post_type IN ('post') AND A.post_status IN ('publish') ORDER BY post_date DESC LIMIT 0,10; * */ $customQuery = 'SELECT DISTINCT A.ID, A.post_title, A.post_content, A.post_excerpt FROM `[wp]' . $this->table_name . '` A '; if (isset($args['category']) && $args['category']) { $customQuery .= 'JOIN `[wp]term_relationships` as B ON (A.ID = B.object_id) '; $customQuery .= 'JOIN `[wp]term_taxonomy` C ON (C.term_taxonomy_id = B.term_taxonomy_id) '; } $conditionsOut = $conditionsIn = array(); foreach ($args as $col => $val) { if (!$val) { continue; } switch ($col) { case 'category': //$conditionsIn['B.term_taxonomy_id']=array('sign'=>'IN','val' =>$val, 'cast' => 'int'); $conditionsIn['C.term_id'] = array('sign' => 'IN', 'val' => $val, 'cast' => 'int'); break; case 'include': $conditionsIn['A.ID'] = array('sign' => 'IN', 'val' => $val, 'cast' => 'int'); break; case 'exclude': $conditionsIn['A.ID'] = array('sign' => 'NOT IN', 'val' => $val, 'cast' => 'int'); break; case 'post_type': $conditionsIn['A.post_type'] = array('sign' => 'IN', 'val' => $val); break; case 'post_status': $conditionsIn['A.post_status'] = array('sign' => 'IN', 'val' => $val); break; case 'post_date': //convert the date $toob =& WYSIJA::get('toolbox', 'helper'); $val = $toob->time_tzed($val); if ($val !== '') { $conditionsIn['A.post_date'] = array('sign' => '>', 'val' => $val); } break; default: } } $customQuery .= 'WHERE '; $customQuery .= $this->setWhereCond($conditionsIn); if (isset($args['orderby'])) { $customQuery .= ' ORDER BY ' . $args['orderby']; if (isset($args['order'])) { $customQuery .= ' ' . $args['order']; } } if (isset($args['numberposts'])) { $customQuery .= ' LIMIT 0,' . $args['numberposts']; } WYSIJA::log('post notif qry', $customQuery, 'post_notif'); return $this->query('get_res', $customQuery); }
function hook_postNotification_transition($new_status, $old_status, $post) { WYSIJA::log('pn_transition_post', array('postID' => $post->ID, 'postID' => $post->post_title, 'old_status' => $old_status, 'new_status' => $new_status)); if ($post->post_type == 'post' && $new_status == 'publish' && $old_status != $new_status) { $modelEmail =& WYSIJA::get('email', 'model'); $emails = $modelEmail->get(false, array('type' => 2, 'status' => array(1, 3, 99))); foreach ($emails as $key => $email) { if ($email['params']['autonl']['event'] === 'new-articles' && $email['params']['autonl']['when-article'] === 'immediate') { $modelEmail->reset(); $modelEmail->giveBirth($email, $post->ID); } } } return true; }
function logError() { if (defined('WYSIJA_DBG') && WYSIJA_DBG > 1) { global $wysija_queries_errors, $wpdb; if (!$wysija_queries_errors) { $wysija_queries_errors = array(); } $mysqlerror = mysql_error($wpdb->dbh); /* dbg($wpdb->last_query,0); dbg($wpdb,0);*/ if ($mysqlerror) { $wysija_queries_errors[] = $mysqlerror; WYSIJA::log('queries_errors', $mysqlerror, 'query_errors'); } } }
/** * this is used when we want to send the email immediately after inserting it into the queue * @param int $user_id * @param int $email_id * @param array $email_params_autonl * @return void */ function insertAutoQueue($user_id, $email_id, $email_params_autonl) { $model_queue = WYSIJA::get('queue', 'model'); $queueData = array('priority' => '-1', 'email_id' => $email_id, 'user_id' => $user_id); $delay = $model_queue->calculate_delay($email_params_autonl); $queueData['send_at'] = time() + $delay; // if the email is already queued for that autoresponder, we don't queue it if (!$model_queue->exists(array('email_id' => $email_id, 'user_id' => $user_id))) { // if the email has already been sent and is now in the stat table, we don't queue it either $modelEUS = WYSIJA::get('email_user_stat', 'model'); if (!$modelEUS->exists(array('email_id' => $email_id, 'user_id' => $user_id))) { $model_queue->insert($queueData, true); } } //if delay is = to 0 then we need to try to send the email straight away if ($delay == 0) { $queueH = WYSIJA::get('queue', 'helper'); $queueH->report = false; WYSIJA::log('insertAutoQueue queue process', array('email_id' => $email_id, 'user_id' => $user_id), 'queue_process'); $queueH->process($email_id, $user_id); } }
/** * post notification transition hook, know when a post really gets published * @param type $new_status * @param type $old_status * @param type $post * @return type */ public static function hook_postNotification_transition($new_status, $old_status, $post) { //we run some process only if the status of the post changes from something to publish if ($new_status == 'publish' && $old_status != $new_status) { $modelEmail =& WYSIJA::get('email', 'model'); $emails = $modelEmail->get(false, array('type' => 2, 'status' => array(1, 3, 99))); if (!empty($emails)) { //we loop through all of the automatic emails foreach ($emails as $key => $email) { //we will try to give birth to a child email only if the automatic newsletter is a post notification email and in immediate mode if (is_array($email) && $email['params']['autonl']['event'] === 'new-articles' && $email['params']['autonl']['when-article'] === 'immediate') { WYSIJA::log('post_transition_hook_give_birth', array('postID' => $post->ID, 'postID' => $post->post_title, 'old_status' => $old_status, 'new_status' => $new_status), 'post_notif'); $modelEmail->reset(); $modelEmail->give_birth($email, $post->ID); } } } } return true; }
function cancel_late_post_notification($email, $how_late) { $cancel_it = false; switch ($email['params']['autonl']['when-article']) { case 'daily': if ($how_late > 2 * 3600) { $cancel_it = true; } break; case 'weekly': if ($how_late > 12 * 3600) { $cancel_it = true; } break; case 'monthly': if ($how_late > 24 * 3600) { $cancel_it = true; } break; case 'monthlyevery': if ($how_late > 24 * 3600) { $cancel_it = true; } break; } if ($cancel_it) { $late_send = $email['params']['autonl']['nextSend']; WYSIJA::log('cancel_late_post_notification_late_send', $late_send, 'post_notif'); $next_send = $this->getNextSend($email); $email['params']['autonl']['nextSend'] = $next_send; $email['params']['autonl']['late_send'] = $late_send; $model_email =& WYSIJA::get('email', 'model'); $model_email->reset(); $model_email->update(array('params' => $email['params']), array('email_id' => $email['email_id'])); return true; } return false; }