Ejemplo n.º 1
0
 function email_to_a_friend($article_id, $to, $bcc, $your_email, $message)
 {
     require_once VIVVO_FS_FRAMEWORK . 'PEAR/Mail.php';
     if (!vivvo_hooks_manager::call('article_mail', array(&$article_id, &$to, &$bcc, &$your_email, &$message))) {
         return vivvo_hooks_manager::get_status();
     }
     if (VIVVO_EMAIL_ENABLE == 1) {
         if (isset($_SESSION['vivvo']['email_to_friend_time']) && $_SESSION['vivvo']['email_to_friend_time'] + VIVVO_EMAIL_FLOOD_CHECK > VIVVO_START_TIME) {
             $this->set_error_code(2202);
             return false;
         }
         $article_list = new Articles_list();
         $article = $article_list->get_article_by_id($article_id);
         $lang = vivvo_lang::get_instance();
         if ($article !== false) {
             $to = strip_tags($to);
             $bcc = strip_tags($bcc);
             if (!preg_match('/^[a-zA-Z0-9_\\-\\/\\.]+@[a-zA-Z0-9_\\-\\/]{2,}([\\.][a-zA-Z0-9_\\-\\/]{2,}){1,}$/', $your_email)) {
                 $this->set_error_code(2032);
                 return false;
             }
             if (!preg_match('/^[a-zA-Z0-9_\\-\\/\\.]+@[a-zA-Z0-9_\\-\\/]{2,}([\\.][a-zA-Z0-9_\\-\\/]{2,}){1,}$/', $bcc)) {
                 $bcc = '';
             }
             if (VIVVO_EMAIL_SEND_BCC) {
                 if ($bcc) {
                     $bcc .= ', ' . VIVVO_EMAIL_SEND_BCC;
                 } else {
                     $bcc = VIVVO_EMAIL_SEND_BCC;
                 }
             }
             if (VIVVO_EMAIL_SEND_CC) {
                 $headers['Cc'] = VIVVO_EMAIL_SEND_CC;
             }
             if (preg_match('/^[a-zA-Z0-9_\\-\\/\\.]+@[a-zA-Z0-9_\\-\\/]{2,}([\\.][a-zA-Z0-9_\\-\\/]{2,}){1,}$/', $to)) {
                 $body_template = new template();
                 $template_sting = xml_template_node::xmlentities_decode(VIVVO_EMAIL_TO_A_FRIEND_BODY);
                 $body_template->set_string_template($template_sting);
                 $body_template->assign('article', $article);
                 $body_template->assign('user_email_address', $your_email);
                 $body_template->assign('message', $message);
                 $body = $body_template->get_output() . "\n\n";
                 $headers['From'] = $your_email;
                 $recipients = array();
                 $recipients[] = $to;
                 if ($bcc != '') {
                     $headers['Bcc'] = $bcc;
                 }
                 $headers['Subject'] = "=?UTF-8?B?" . base64_encode(VIVVO_EMAIL_TO_A_FRIEND_SUBJECT) . "?=";
                 $headers['Content-Type'] = "text/plain; charset=UTF-8;";
                 if (VIVVO_EMAIL_SMTP_PHP == 1) {
                     $mail_object = new Mail();
                     $mail_object->send($to, $headers, $body);
                 } else {
                     $mail_options['driver'] = 'smtp';
                     $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST;
                     $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT;
                     $mail_options['localhost'] = 'localhost';
                     if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') {
                         $mail_options['auth'] = true;
                         $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME;
                         $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD;
                     } else {
                         $mail_options['auth'] = false;
                         $mail_options['username'] = '';
                         $mail_options['password'] = '';
                     }
                     $mail_object = Mail::factory('smtp', $mail_options);
                     $mail_object->send($to, $headers, $body);
                 }
                 $article->set_emailed($article->emailed + 1);
                 $this->_post_master->set_data_object($article);
                 if ($this->_post_master->sql_update()) {
                     $_SESSION['vivvo']['email_to_friend_time'] = time();
                     return true;
                 } else {
                     $this->set_error_code(2033);
                     return false;
                 }
             } else {
                 $this->set_error_code(2034);
                 return false;
             }
         } else {
             $this->set_error_code(2035);
             return false;
         }
     }
 }
Ejemplo n.º 2
0
 function forgot_mail($username, $email)
 {
     if (!$this->check_token()) {
         return false;
     }
     if (!vivvo_hooks_manager::call('login_forgotMail', array(&$username, &$email))) {
         return vivvo_hooks_manager::get_status();
     }
     if (isset($_SESSION['vivvo']['register_time']) && $_SESSION['vivvo']['register_time'] + 60 > VIVVO_START_TIME) {
         $this->set_error_code(2755);
         return false;
     }
     require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Users.class.php';
     $lang = vivvo_lang::get_instance();
     $user_list = new Users_list();
     if (!$username && !$email) {
         $this->set_error_code(2712);
         return false;
     } else {
         if ($username) {
             $user_list->search(array('search_username' => $username));
             $user = current($user_list->list);
         } elseif ($email) {
             $user_list->search(array('search_email_address' => $email));
             $user = current($user_list->list);
         }
         if ($user) {
             $search = array('(', ')', '<', '>', '@', ';', ':', '\\', '"', '.', '[', ']');
             $replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
             $vivvo_website_title = str_replace($search, $replace, VIVVO_WEBSITE_TITLE);
             $vivvo_website_title = "=?UTF-8?B?" . base64_encode($vivvo_website_title) . "?=";
             $headers['From'] = $vivvo_website_title . '<' . VIVVO_EMAIL_SEND_FROM . '>';
             $recipients = array();
             $recipients[] = $user->email_address;
             $headers['Subject'] = "=?UTF-8?B?" . base64_encode(VIVVO_EMAIL_FORGOT_SUBJECT) . "?=";
             $headers['Content-Type'] = "text/plain; charset=UTF-8;";
             $body_template = new template();
             $template_sting = xml_template_node::xmlentities_decode(VIVVO_EMAIL_FORGOT_BODY);
             $body_template->set_string_template($template_sting);
             $confirm_url = make_absolute_url('login.html?activation_key=' . md5($user->username . $user->email_address . $user->password));
             $body_template->assign('activation_url', $confirm_url);
             $body_template->assign('user', $user);
             $body = $body_template->get_output() . "\n\n";
             if (VIVVO_EMAIL_SMTP_PHP == 1) {
                 $mail_object = new Mail();
                 $mail_object->send($recipients, $headers, $body);
             } else {
                 $mail_options['driver'] = 'smtp';
                 $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST;
                 $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT;
                 $mail_options['localhost'] = 'localhost';
                 if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') {
                     $mail_options['auth'] = true;
                     $mail_options['username'] = VIVVO_EMAIL_SMTP_PASSWORD;
                     $mail_options['password'] = VIVVO_EMAIL_SMTP_USERNAME;
                 } else {
                     $mail_options['auth'] = false;
                     $mail_options['username'] = '';
                     $mail_options['password'] = '';
                 }
                 $mail_object = Mail::factory('smtp', $mail_options);
                 $mail_object->send($recipients, $headers, $body);
             }
         }
         $_SESSION['vivvo']['register_time'] = time();
         return true;
     }
 }
Ejemplo n.º 3
0
    function send_newsletter($newsletter_id)
    {
        $sm = vivvo_lite_site::get_instance();
        $db = $sm->get_db();
        if ($sm->user) {
            if ($sm->user->is_admin()) {
                $newsletter_list = new newsletter_list();
                $newsletter = $newsletter_list->get_newsletter_by_id($newsletter_id);
                if ($newsletter !== false) {
                    if ($newsletter->test == 1) {
                        $to = $newsletter->test_email;
                        if ($newsletter->vte_template == '1') {
                            $body_template = new template();
                            $template_sting = xml_template_node::xmlentities_decode($newsletter->body);
                            $body_template->set_string_template($template_sting);
                            $body = $body_template->get_output() . "\n\n";
                        } else {
                            $body = xml_template_node::xmlentities_decode($newsletter->body);
                        }
                        $unsubscribe_url = VIVVO_PROXY_URL . 'newsletter/index.html?&action=newsletter&cmd=subscriberUnSubscribe&dack=' . md5('test');
                        if (!preg_match('/^[^:]+:/', $unsubscribe_url)) {
                            $unsubscribe_url = VIVVO_URL . $unsubscribe_url;
                        }
                        $body = $body . "\n\n\n" . VIVVO_PLUGIN_NEWSLETTER_UNSUBSCRIBE_TEXT . "\n" . $unsubscribe_url;
                        $from = VIVVO_ADMINISTRATORS_EMAIL;
                        $search = array('(', ')', '<', '>', '@', ';', ':', '\\', '"', '.', '[', ']');
                        $replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
                        $from_name = str_replace($search, $replace, VIVVO_WEBSITE_TITLE);
                        $from_name = "=?UTF-8?B?" . base64_encode($from_name) . "?=";
                        $from_params = !empty($from_name) ? '"' . $from_name . '" <' . $from . '>' : '<' . $from . '>';
                        $headers['From'] = $from_params;
                        $recipients = array();
                        $recipients[] = $to;
                        $subject = "=?UTF-8?B?" . base64_encode($newsletter->subject) . "?=";
                        $headers['Subject'] = $subject;
                        $headers['Content-Type'] = "text/plain; charset=UTF-8;";
                        if (VIVVO_EMAIL_SMTP_PHP == 1) {
                            $mail_object = new Mail();
                            $mail_object->send($to, $headers, $body);
                        } else {
                            $mail_options['driver'] = 'smtp';
                            $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST;
                            $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT;
                            $mail_options['localhost'] = 'localhost';
                            if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') {
                                $mail_options['auth'] = true;
                                $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME;
                                $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD;
                            } else {
                                $mail_options['auth'] = false;
                                $mail_options['username'] = '';
                                $mail_options['password'] = '';
                            }
                            $mail_object =& Mail::factory('smtp', $mail_options);
                            $mail_object->send($to, $headers, $body);
                        }
                    } else {
                        $container_options = array('type' => 'mdb2', 'dsn' => VIVVO_DB_TYPE . '://' . VIVVO_DB_USER . ':' . VIVVO_DB_PASSWORD . '@' . VIVVO_DB_HOST . '/' . VIVVO_DB_DATABASE, 'mail_table' => VIVVO_DB_PREFIX . 'mail_queue');
                        $mail_options['driver'] = 'smtp';
                        $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST;
                        $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT;
                        $mail_options['localhost'] = 'localhost';
                        if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') {
                            $mail_options['auth'] = true;
                            $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME;
                            $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD;
                        } else {
                            $mail_options['auth'] = false;
                            $mail_options['username'] = '';
                            $mail_options['password'] = '';
                        }
                        $mail_queue = new Mail_Queue($container_options, $mail_options);
                        $from = VIVVO_ADMINISTRATORS_EMAIL;
                        $search = array('(', ')', '<', '>', '@', ';', ':', '\\', '"', '.', '[', ']');
                        $replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
                        $from_name = str_replace($search, $replace, VIVVO_WEBSITE_TITLE);
                        $from_name = "=?UTF-8?B?" . base64_encode($from_name) . "?=";
                        $from_params = !empty($from_name) ? '"' . $from_name . '" <' . $from . '>' : '<' . $from . '>';
                        if ($newsletter->vte_template == '1') {
                            $body_template = new template();
                            $template_sting = xml_template_node::xmlentities_decode($newsletter->body);
                            $body_template->set_string_template($template_sting);
                            $body = $body_template->get_output() . "\n\n";
                        } else {
                            $body = xml_template_node::xmlentities_decode($newsletter->body);
                        }
                        $groups = explode(',', $newsletter->groups);
                        foreach ($groups as $key) {
                            if ($key == -1) {
                                $res =& $db->query('SELECT email, ip, time FROM ' . VIVVO_DB_PREFIX . 'maillist WHERE `confirm` = \'1\'');
                                if (!is_a($res, 'mdb2_error')) {
                                    while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
                                        $subject = "=?UTF-8?B?" . base64_encode($newsletter->subject) . "?=";
                                        $recipient = $row['email'];
                                        $hdrs = array('From' => $from_params, 'To' => $recipient, 'Subject' => $subject, 'Content-Type' => "text/plain; charset=UTF-8;");
                                        $body_all = $body . "\n\n\n" . VIVVO_PLUGIN_NEWSLETTER_UNSUBSCRIBE_TEXT . "\n" . VIVVO_URL . 'newsletter/index.html?action=newsletter&cmd=subscriberUnSubscribe&dack=' . md5($row['ip'] . $row['time'] . $row['email']);
                                        $mail_queue->put($from, $recipient, $hdrs, $body_all);
                                    }
                                }
                            } elseif ($key >= 0) {
                                $res = $db->query('SELECT email_address, userid, created FROM ' . VIVVO_DB_PREFIX . 'users as u
														INNER JOIN ' . VIVVO_DB_PREFIX . 'group_user  as gu
														ON gu.user_id=u.userid
														WHERE gu.group_id = \'' . $key . '\' and `subscriber` = \'1\'');
                                if (!is_a($res, 'mdb2_error')) {
                                    while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
                                        $recipient = $row['email_address'];
                                        $subject = "=?UTF-8?B?" . base64_encode($newsletter->subject) . "?=";
                                        $hdrs = array('From' => $from_params, 'To' => $recipient, 'Subject' => $subject, 'Content-Type' => "text/plain; charset=UTF-8;");
                                        $unsubscribe_url = VIVVO_PROXY_URL . 'newsletter/index.html?action=newsletter&cmd=userUnSubscribe&dack=' . md5($row['email_address'] . $row['userid'] . $row['created']);
                                        if (!preg_match('/^[^:]+:/', $unsubscribe_url)) {
                                            $unsubscribe_url = VIVVO_URL . $unsubscribe_url;
                                        }
                                        $body_all = $body . "\n\n\n" . VIVVO_PLUGIN_NEWSLETTER_UNSUBSCRIBE_TEXT . "\n" . $unsubscribe_url;
                                        $mail_queue->put($from, $recipient, $hdrs, $body_all);
                                    }
                                }
                            }
                        }
                    }
                    return true;
                } else {
                    $this->set_error_code(10225);
                    return false;
                }
            } else {
                $this->set_error_code(10226);
                return false;
            }
        } else {
            $this->set_error_code(10227);
            return false;
        }
    }