Example #1
0
}
// Disable floating tab in component view
if ($app->input->get('tmpl') == 'component' and $params->get('position') != 'static') {
    return;
}
require_once dirname(__FILE__) . '/helper.php';
// Community Builder
if ($params->get('comprofiler') == 2) {
    if (!modPWebContactComprofilerHelper::isUserProfileView()) {
        if ($params->get('debug')) {
            $app->enqueueMessage(JText::_('MOD_PWEBCONTACT_INTEGRATION_COMPONENT_VIEW_WARNING'), 'warning');
        }
        return;
    }
} elseif ($params->get('jomsocial') == 2) {
    if (!modPWebContactJomSocialHelper::isUserProfileView()) {
        if ($params->get('debug')) {
            $app->enqueueMessage(JText::_('MOD_PWEBCONTACT_INTEGRATION_COMPONENT_VIEW_WARNING'), 'warning');
        }
        return;
    }
} elseif ($params->get('sobipro') == 2) {
    if (!modPWebContactSobiProHelper::isEntryView()) {
        if ($params->get('debug')) {
            $app->enqueueMessage(JText::_('MOD_PWEBCONTACT_INTEGRATION_COMPONENT_VIEW_WARNING'), 'warning');
        }
        return;
    }
} elseif ($params->get('zoo') == 2) {
    if (!modPWebContactZooHelper::isItemView()) {
        if ($params->get('debug')) {
Example #2
0
File: helper.php Project: 01J/topm
 public static function sendEmail()
 {
     jimport('joomla.mail.helper');
     jimport('joomla.filesystem.file');
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $params = self::getParams();
     $module_id = (int) $params->get('id');
     // mail from
     $global_name = $app->getCfg('fromname', $app->getCfg('sitename'));
     $global_email = $params->get('email_from', $app->getCfg('mailfrom'));
     if (!$global_email) {
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'Invalid Global Configuration';
         }
         return array('status' => 303, 'msg' => JText::_('MOD_PWEBCONTACT_GLOBAL_CONFIG_ERR'));
     }
     $data =& self::$data;
     $email_vars =& self::$email_vars;
     // Get inputs
     $data = $app->input->getArray(array('fields' => 'array', 'mailto' => 'int', 'title' => 'string', 'url' => 'string', 'screen_resolution' => 'string', 'attachments' => 'array'));
     $data['ip_address'] = self::detectIP();
     $data['browser'] = self::detectBrowser();
     $data['os'] = self::detectOS();
     $data['user_id'] = $user->id;
     $data['user_subject'] = '';
     // init email variables
     $email_vars = array('name' => '', 'email' => '', 'username' => $user->username, 'ip_address' => $data['ip_address'], 'browser' => $data['browser'], 'os' => $data['os'], 'screen_resolution' => $data['screen_resolution'], 'title' => $data['title'], 'url' => $data['url'], 'site_name' => $app->getCfg('sitename'), 'mailto_name' => '', 'ticket' => '');
     $fields = self::getFields();
     $user_email = null;
     $user_name = null;
     $user_cc = array();
     $email_to = array();
     $invalid_fields = array();
     // init email variables for fields and validate them
     foreach ($fields as $field) {
         // skip all separators which does not have any data
         if (strpos($field->type, 'separator') !== false) {
             continue;
         }
         // get field from request
         if (isset($data['fields'][$field->alias])) {
             $value = $data['fields'][$field->alias];
         } else {
             $data['fields'][$field->alias] = $value = null;
         }
         // is required
         if ($field->required and ($value === null or $value === '')) {
             // required field is empty
             $invalid_fields[] = 'field-' . $field->alias;
             continue;
         }
         if ($field->type == 'email') {
             // Validate email
             if ($value and JMailHelper::isEmailAddress($value) === false) {
                 $invalid_fields[] = 'field-' . $field->alias;
             } else {
                 if (!$user_email) {
                     $email_vars['email'] = $user_email = $value;
                 } else {
                     $user_cc[] = $value;
                 }
             }
         } else {
             if ($field->type == 'name') {
                 if (!$user_name) {
                     $email_vars['name'] = $user_name = $value;
                 }
             } elseif ($field->type == 'subject') {
                 $data['user_subject'] .= ' ' . $value;
             }
             // validate fields with regular expression
             if (in_array($field->type, array('text', 'name', 'phone', 'subject', 'password')) and $field->params and $value and !preg_match($field->params, $value)) {
                 $invalid_fields[] = 'field-' . $field->alias;
             }
         }
     }
     // mailto list
     if ($params->get('email_to_list')) {
         if ($data['mailto'] > 0) {
             $rows = @explode(PHP_EOL, $params->get('email_to_list'));
             if (array_key_exists($data['mailto'] - 1, $rows)) {
                 $row = @explode('|', $rows[$data['mailto'] - 1]);
                 if ($row[0]) {
                     $email_to[] = $row[0];
                     $email_vars['mailto_name'] = $row[1];
                 }
             }
         } else {
             // required field is empty
             $invalid_fields[] = 'mailto';
         }
     } else {
         $data['mailto'] = null;
     }
     if ($params->get('show_upload') == 2 and !count($data['attachments'])) {
         $invalid_fields[] = 'uploader';
     }
     // invalid fields
     if (count($invalid_fields)) {
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'Invalid fields';
         }
         return array('status' => 200, 'msg' => JText::_('MOD_PWEBCONTACT_INVALID_FIELDS_ERR'), 'invalid' => $invalid_fields);
     }
     // Community Builder
     if ($params->get('comprofiler') and ($profile_id = $app->input->getInt('comprofiler', 0)) > 0) {
         $email = modPWebContactComprofilerHelper::getEmail($profile_id);
         if ($email === false) {
             return array('status' => 500, 'msg' => JText::_('MOD_PWEBCONTACT_NO_RECIPIENT'));
         } else {
             $email_to[] = $email;
         }
     } elseif ($params->get('jomsocial') and ($profile_id = $app->input->getInt('jomsocial', 0)) > 0) {
         $email = modPWebContactJomSocialHelper::getEmail($profile_id);
         if ($email === false) {
             return array('status' => 510, 'msg' => JText::_('MOD_PWEBCONTACT_NO_RECIPIENT'));
         } else {
             $email_to[] = $email;
         }
     } elseif ($params->get('sobipro') and ($entry_id = $app->input->getInt('sobipro', 0)) > 0) {
         $email = modPWebContactSobiProHelper::getEmail($entry_id);
         if ($email === false) {
             return array('status' => 520, 'msg' => JText::_('MOD_PWEBCONTACT_NO_RECIPIENT'));
         } else {
             $email_to[] = $email;
         }
     }
     // Joomla
     if ($params->get('email_to')) {
         $email_to = array_merge($email_to, @explode(',', $params->get('email_to')));
     }
     if ($params->get('email_user')) {
         $db = JFactory::getDBO();
         $query = $db->getQuery(true);
         $query->select('email')->from('#__users')->where('id = ' . (int) $params->get('email_user'));
         $db->setQuery($query);
         try {
             if ($email = $db->loadResult()) {
                 $email_to[] = $email;
             }
         } catch (RuntimeException $e) {
         }
     }
     if (!count($email_to)) {
         $email_to[] = $global_email;
     }
     // ticket
     $data['ticket'] = '';
     if ($ticket_type = $params->get('ticket_enable', 0)) {
         if ($ticket_type == 1) {
             $data['ticket'] = JFactory::getDate()->format('YmdHis');
             $email_vars['ticket'] = sprintf($params->get('ticket_format', '[#%s]'), $data['ticket']);
         } elseif ($ticket_type == 2) {
             $ticket_file = $params->get('media_path') . 'tickets/ticket_' . sprintf('%03d', $module_id) . '.txt';
             $ticket_counter = JFile::exists($ticket_file) ? (int) file_get_contents($ticket_file) : 0;
             $ticket_counter++;
             JFile::write($ticket_file, $ticket_counter);
             $data['ticket'] = $ticket_counter;
             $email_vars['ticket'] = sprintf($params->get('ticket_format', '[#%06d]'), $ticket_counter);
         }
         if ($data['ticket']) {
             // success message with ticket
             $success_msg = JText::sprintf($params->get('msg_success', 'MOD_PWEBCONTACT_MAIL_SUCCESS_TICKET'), $email_vars['ticket']);
             // email subject with ticket
             $data['subject'] = JText::sprintf($params->get('email_subject', 'MOD_PWEBCONTACT_EMAIL_SUBJECT_TICKET'), $email_vars['ticket']);
         }
     }
     // success message
     if (!isset($success_msg)) {
         $success_msg = JText::_($params->get('msg_success', 'MOD_PWEBCONTACT_MAIL_SUCCESS'));
     }
     // clean subject
     //$success_msg = str_replace(array('"','\\'), '', $success_msg);
     // email subject
     if (!isset($data['subject'])) {
         $data['subject'] = JText::_($params->get('email_subject', 'MOD_PWEBCONTACT_EMAIL_SUBJECT'));
     }
     // email subject suffix
     //TODO test RTL if suffix should be before subject
     switch ($params->get('email_subject_sfx', 2)) {
         case 1:
             $data['subject'] .= ' ' . $email_vars['site_name'];
             break;
         case 2:
             $data['subject'] .= ' ' . $data['title'];
             break;
         case 3:
             $data['subject'] .= $data['user_subject'];
     }
     // HOOK PROCCESS DATA - here you can add custom code to proccess variables: $data, $email_vars
     // HTML emails path
     $tmpl_path = $params->get('media_path') . 'email_tmpl/';
     // User email copy and auto-reply
     $email_copy = $params->get('email_copy', 0) and $app->input->getInt('copy', 0);
     $email_autoreply = $params->get('email_autoreply', 0);
     if ($user_email and ($email_copy or $email_autoreply)) {
         $mail = JFactory::getMailer();
         // add recipient
         $mail->addRecipient($user_email);
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'User email: ' . $user_email;
         }
         // Add carbon copy recipients
         if (count($user_cc)) {
             $mail->addCC($user_cc);
             if (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'User email: ' . implode(', ', $user_cc);
             }
         }
         // set subject
         $mail->setSubject($data['subject']);
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'User email subject: ' . $data['subject'];
         }
         // set sender
         $mail->setSender(array($global_email, $global_name));
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'User email sender: ' . $global_email;
         }
         // set reply to
         if ($params->get('email_replyto')) {
             $mail->ClearReplyTos();
             $mail->addReplyTo($params->get('email_replyto'), $params->get('email_replyto_name', $global_name));
             if (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'User email reply to: ' . $params->get('email_replyto');
             }
         }
         // Auto-reply
         if ($email_autoreply) {
             // load email body template
             $tmpl = $params->get('email_tmpl_html_autoreply');
             $is_html = $tmpl ? true : false;
             $mail->IsHTML($is_html);
             if ($is_html) {
                 $body = file_get_contents($tmpl_path . $tmpl . '.html');
             } else {
                 $body = $params->get('email_tmpl_text_autoreply');
             }
             self::parseTmplVars($body, $is_html, $lang->getTag());
             // set body text direction
             $body = ($params->get('rtl', 0) ? "‏" : "‎") . $body;
             // set body text
             $mail->setBody($body);
             if (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'User auto-reply email ready';
             }
             // send auto-reply email
             if ($mail->Send() !== true) {
                 return array('status' => 304, 'msg' => JText::_('MOD_PWEBCONTACT_MAIL_AUTOREPLY_ERR'));
             } elseif (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'User auto-reply email sent successfully';
             }
         }
         // User email copy
         if ($email_copy) {
             // set attachments as files
             if ($params->get('attachment_type', 1) == 1 and count($data['attachments'])) {
                 $path = $params->get('upload_path');
                 foreach ($data['attachments'] as $file) {
                     $mail->addAttachment($path . $file, $file);
                 }
                 if (PWEBCONTACT_DEBUG) {
                     self::$logs[] = 'User email attachments: ' . implode(', ', $data['attachments']);
                 }
             }
             // load email body template
             $tmpl = $params->get('email_tmpl_html_user');
             $is_html = $tmpl ? true : false;
             $mail->IsHTML($is_html);
             if ($is_html) {
                 $body = file_get_contents($tmpl_path . $tmpl . '.html');
             } else {
                 $body = $params->get('email_tmpl_text_user');
             }
             self::parseTmplVars($body, $is_html, $lang->getTag());
             // set body text direction
             $body = ($params->get('rtl', 0) ? "‏" : "‎") . $body;
             // set body text
             $mail->setBody($body);
             if (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'User email ready';
             }
             // send User email
             if ($mail->Send() !== true) {
                 return array('status' => 305, 'msg' => JText::_('MOD_PWEBCONTACT_MAIL_USER_ERR'));
             } elseif (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'User email sent successfully';
             }
         }
     }
     // Demo: do not send email to Admin
     if ($params->get('demo', 0)) {
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'DEMO mode is not sending email to Admin';
         }
         return array('status' => 102, 'msg' => $success_msg, 'ticket' => $data['ticket']);
     }
     // Administrator email language
     $email_lang = $params->get('email_lang');
     if ($email_lang) {
         if ($email_lang != $lang->getTag()) {
             $lang->setLanguage($email_lang);
             $lang->load();
             $lang->load('mod_pwebcontact');
             $params->set('rtl', $lang->isRTL());
             if (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'Admin email language loaded: ' . $email_lang;
             }
         } else {
             $params->set('email_lang', false);
         }
     }
     // Administrator email
     $mail = JFactory::getMailer();
     // add recipient
     $mail->addRecipient($email_to);
     if (PWEBCONTACT_DEBUG) {
         self::$logs[] = 'Admin emails: ' . implode(', ', $email_to);
     }
     // set subject
     $mail->setSubject($data['subject']);
     if (PWEBCONTACT_DEBUG) {
         self::$logs[] = 'Admin email subject: ' . $data['subject'];
     }
     // set sender
     if ($user_email and !$params->get('server_sender', 0)) {
         $mail->setSender(array($user_email, $user_name));
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'Admin email Sender: ' . $user_email;
         }
     } else {
         $mail->setSender(array($global_email, $global_name));
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'Admin email Sender: ' . $global_email;
         }
         // set reply to
         if ($user_email) {
             $mail->ClearReplyTos();
             $mail->addReplyTo(array($user_email, $user_name));
             if (PWEBCONTACT_DEBUG) {
                 self::$logs[] = 'Admin email reply to: ' . $user_email;
             }
         }
     }
     // Add blind carbon copy recipients
     if ($params->get('email_bcc')) {
         $email_bcc = @explode(',', $params->get('email_bcc'));
         $mail->addBCC($email_bcc);
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'Admin BCC recipients: ' . $params->get('email_bcc');
         }
     }
     // Add User email as blind carbon copy in debug mode
     if (PWEBCONTACT_DEBUG and $user_email) {
         $mail->addBCC($user_email);
         self::$logs[] = 'Admin BCC debug recipient: ' . $user_email;
     }
     // set attachments as files
     if ($params->get('attachment_type', 1) == 1 and count($data['attachments'])) {
         $path = $params->get('upload_path');
         foreach ($data['attachments'] as $file) {
             $mail->addAttachment($path . $file, $file);
         }
         if (PWEBCONTACT_DEBUG) {
             self::$logs[] = 'Admin email attachments: ' . implode(', ', $data['attachments']);
         }
     }
     // load email body template
     $tmpl = $params->get('email_tmpl_html_admin');
     $is_html = $tmpl ? true : false;
     $mail->IsHTML($is_html);
     if ($is_html) {
         $body = file_get_contents($tmpl_path . $tmpl . '.html');
     } else {
         $body = $params->get('email_tmpl_text_admin');
     }
     self::parseTmplVars($body, $is_html, $lang->getTag());
     // set body text direction
     $body = ($params->get('rtl', 0) ? "‏" : "‎") . $body;
     // set body text
     $mail->setBody($body);
     if (PWEBCONTACT_DEBUG) {
         self::$logs[] = 'Admin email ready';
     }
     // send Admin email
     if ($mail->Send() !== true) {
         return array('status' => 306, 'msg' => JText::_('MOD_PWEBCONTACT_MAIL_ADMIN_ERR'));
     } elseif (PWEBCONTACT_DEBUG) {
         self::$logs[] = 'Admin email sent successfully';
     }
     return array('status' => 100, 'msg' => $success_msg, 'ticket' => $data['ticket']);
 }