public static function createNewsletter($newsletterInfo = array()) { global $wpdb; if (0 == count($newsletterInfo)) { $newsletterInfo = array('name' => md5(microtime() . "newsletter_name"), 'fromname' => md5(microtime() . "fromname"), 'fromemail' => md5(microtime() . 'somename') . '@' . md5(microtime() . "somedomain") . ".com", 'reply_to' => substr(self::randomString("reply"), 0, 5) . '@' . substr(self::randomString("domain"), 0, 5) . ".com"); } $createNewsletterQuery = sprintf("INSERT INTO %swpr_newsletters (`name`, `fromname`, `fromemail`, `reply_to`) VALUES ('%s', '%s', '%s', '%s')", $wpdb->prefix, $newsletterInfo['name'], $newsletterInfo['fromname'], $newsletterInfo['fromemail'], $newsletterInfo['reply_to']); $wpdb->query($createNewsletterQuery); $newsletterId = $wpdb->insert_id; return Newsletter::getNewsletter($newsletterId); }
function wpr_replace_tags($sid, &$subject, &$body, $additional = array()) { global $wpdb; $query = "SELECT * FROM " . $wpdb->prefix . "wpr_subscribers WHERE id='{$sid}'"; $subscriber = $wpdb->get_results($query); $subscriber = $subscriber[0]; $nid = $subscriber->nid; $newsletter = Newsletter::getNewsletter($nid); $parameters = array(); //newsletter name $newsletterName = $newsletter->getNewsletterName(); $parameters['newslettername'] = $newsletterName; $query = "SELECT * FROM " . $wpdb->prefix . "wpr_custom_fields where nid='{$nid}'"; $custom_fields = $wpdb->get_results($query); //blog name $parameters['sitename'] = get_bloginfo("name"); //blog url $parameters['homeurl'] = get_bloginfo("url"); //subscriber name $parameters['name'] = $subscriber->name; //the address of the sender (as required by can spam) $parameters['address'] = get_option("wpr_admin_address"); //the email address $parameters['email'] = $subscriber->email; //admin email $parameters['adminemail'] = get_option('admin_email'); $query = "select * from " . $wpdb->prefix . "wpr_subscribers_{$nid} where id={$id};"; $subscriber = $wpdb->get_results($query); $subscriber = $subscriber[0]; //custom fields defined by the administrator foreach ($custom_fields as $custom_field) { $name = $custom_field->name; $parameters[$custom_field->name] = $subscriber->{$name}; } $parameters = array_merge($parameters, $additional); foreach ($parameters as $name => $value) { $subject = str_replace("[!{$name}!]", $value, $subject); $body = str_replace("[!{$name}!]", $value, $body); } }
public static function getAllNewsletters() { global $wpdb; $getAllNewslettersQuery = sprintf("SELECT * FROM {$wpdb->prefix}wpr_newsletters"); $newsletters = $wpdb->get_results($getAllNewslettersQuery); $result = array(); foreach ($newsletters as $newsletter) { $result[] = Newsletter::getNewsletter($newsletter->id); } return $result; }
public function getNewsletter() { $newsletterId = $this->getNewsletterId(); return Newsletter::getNewsletter($newsletterId); }
function _wpr_newsletter_delete() { global $wpdb; $prefix = $wpdb->prefix; $nid = $_GET['nid']; try { $newsletter = Newsletter::getNewsletter($nid); } catch (Exception $excp) { _wpr_set("_wpr_view", "newsletter_delete_not_found"); return; } if (isset($_GET['confirmed']) && $_GET['confirmed'] == 'true') { $newsletter->delete(); $newsletter_home = "admin.php?page=_wpr/newsletter"; wp_redirect($newsletter_home); } $getEmailsPendingDeliveryQuery = sprintf("SELECT COUNT(*) number FROM %swpr_queue WHERE sid=(SELECT id FROM %swpr_subscribers WHERE nid=%d) AND sent=0;", $prefix, $prefix, $nid); $emails_pending_count_result = $wpdb->get_results($getEmailsPendingDeliveryQuery); $number_pending = $emails_pending_count_result[0]->number; _wpr_set("newsletter_name", $newsletter->getName()); _wpr_set("subscriber_count", $newsletter->getNumberOfActiveSubscribers()); _wpr_set("_wpr_view", "newsletter_delete"); _wpr_set("nid", $nid); _wpr_set("emailsPendingDelivery", $number_pending); }
function getNewsletter() { $newsletter = Newsletter::getNewsletter($this->getNewsletterId()); return $newsletter; }
public function testGetNewsletterFactoryFetchesExistentNewsletters() { global $wpdb; $addNewsletterQuery = sprintf("INSERT INTO %swpr_newsletters (`name`) VALUES ('%s')", $wpdb->prefix, 'Test Newsletter'); $wpdb->query($addNewsletterQuery); $newsletter = Newsletter::getNewsletter(intval($wpdb->insert_id)); $this->assertEquals($wpdb->insert_id, $newsletter->getId()); }