Exemplo n.º 1
0
 /**
  * mergeArrayWithFooter()
  * like the default merge array but add the footer accordingly.
  * It requires in the fields values: idcontact, firstname and lastname of the receiver
  * Merge an Array with a currently loaded email template
  * @param array $fields_values fields in format $fields['fieldname']=value;
  */
 function mergeArrayWithFooter($fields_values)
 {
     $bodytext = $this->getTemplateBodyText();
     $bodyhtml = $this->getTemplateBodyHtml();
     $msg = new Message();
     $unsubscribe_url = $GLOBALS['cfg_ofuz_site_http_base'] . 'unsub/' . $fields_values['idcontact'] . '/' . $_SESSION['do_User']->iduser;
     $fields_values['unsubscribe_url'] = $unsubscribe_url;
     $fields_values['sender_name'] = $_SESSION['do_User']->getFullName();
     $fields_values['receiver_name'] = $fields_values['firstname'] . " " . $fields_values['lastname'];
     if ($fields_values["flag"]) {
         if ($fields_values["flag"] == "unsubscribe_autoresponder") {
             //$unsubsribe_auto_responder = $this->getUnsubscribeAutoResponderLink($fields_values);
             //$bodytext .= $unsubsribe_auto_responder;
             //$bodyhtml .= $unsubsribe_auto_responder;
             $bodyhtml .= $this->getUnsubscribeAutoResponderLinkHTML($fields_values);
             $bodytext .= $this->getUnsubscribeAutoResponderLinkText($fields_values);
         }
     }
     $bodytext .= $msg->getMessage("email footer text");
     $bodyhtml .= $msg->getMessage("email footer html");
     $this->setBodyText(MergeString::withArray($bodytext, $fields_values));
     if (strlen($this->getTemplateBodyHtml()) > 5) {
         $this->setBodyHtml(MergeString::withArray($bodyhtml, $fields_values));
     }
     $this->setSubject(MergeString::withArray($this->getTemplateSubject(), $fields_values));
 }
Exemplo n.º 2
0
 /**
  * The secret sauce.
  * Take a string, extract the fields in [] and replace the fields in [] with
  * their respective values from the $values array.
  * @param string with fields to merge in []
  * @param array $values array with format $values[field_name] = $value
  * @return string merged
  */
 static function withArray($thestring, $values)
 {
     $fields = MergeString::getField($thestring);
     if (is_array($fields)) {
         foreach ($fields as $field) {
             $thestring = str_replace('[' . $field . ']', $values[$field], $thestring);
         }
     }
     return $thestring;
 }
 function eventTranslateLanguage(EventControler $evtcl)
 {
     $src_lang = explode("_", $this->src_lng);
     $dest_lng = explode("_", $this->dest_lng);
     $fields_content = MergeString::getField($evtcl->et_content_src);
     $arr_fields_content = array();
     foreach ($fields_content as $fields_cont) {
         $arr_fields_content[$fields_cont] = "AB" . rand(1, 9999) . "YZ";
     }
     $content = htmlspecialchars($evtcl->et_content_src, ENT_QUOTES);
     $content = MergeString::withArray($content, $arr_fields_content);
     $trans_content = parent::translate($content, $src_lang[0], $dest_lng[0]);
     $trans_content = htmlspecialchars_decode($trans_content);
     $content = $this->withField($trans_content, $arr_fields_content);
     $_SESSION["et_content_src"] = $content;
 }
Exemplo n.º 4
0
 /**
  *  sendMessage
  *  This abstract the message sending so we use a general function
  *  that will send email or facebook or twitter based on the user
  *  preferences and settings.
  *  its possible to generate an EmailTemplate on the fly with no records in the DB
  *  Here is an exemple:
  *  <code php>
  *  $do_template = new EmailTemplate();
  *  $do_template->senderemail = "*****@*****.**";
  *  $do_template->sendername = "Philippe Lewicki";
  *  $do_template->subject = "This is an example";
  *  $do_template->bodytext = "This is the content of the sample message";
  *  $do_template->bodyhtml = nl2br($do_template->bodytext);
  *  </code>
  * 
  *  An other example more OO / stylish
  *  <code php>
  *  $do_template = new EmailTemplate();
  *  $do_template->setFrom("*****@*****.**", "Philippe Lewicki")
  *              ->setSubject("This is an example")
  *              ->setMessage("This is the content of the sample message");
  *  </code>
  *  setFrom() is optional, if not provided it takes the do_User data
  *  
  *  Then send the message with:  $contact->sendMessage($do_template);
  * 
  *  If you used a saved EmailTemplate like
  *  $do_template = new EmailTemplate("my template in email template table");
  *  and want the sender to be the currently signed in user, make sure the senderemail field
  *  is empty.
  * 
  *  @param $message an EmailTemplate object.
  *  @param $values an array with values to merge, optional.
  *  
  */
 function sendMessage($template, $values = array())
 {
     if (!is_object($template)) {
         return false;
     }
     if (empty($values)) {
         $values = $this->getValues();
     }
     $this->last_message_sent = false;
     $do_contact_email = $this->getChildContactEmail();
     $email_to = $do_contact_email->getDefaultEmail();
     $this->setLog("\n Sending message to:" . $email_to);
     $contact_link = '<a href="/Contact/' . $this->idcontact . '">' . $this->firstname . ' ' . $this->lastname . '</a>';
     if (strlen($email_to) > 4) {
         if ($this->email_optout != 'y') {
             $emailer = new Ofuz_Emailer('UTF-8');
             if (strlen($template->senderemail) == 0) {
                 $template->setFrom($_SESSION['do_User']->email, $_SESSION['do_User']->getFullName());
             }
             $emailer->setEmailTemplate($template);
             $emailer->mergeArrayWithFooter($values);
             $emailer->addTo($email_to);
             $this->last_message_sent = true;
             return $emailer->send();
         } else {
             $_SESSION['in_page_message'] .= _("<br>" . $contact_link . " has opt-out and will not receive this email");
         }
     } elseif (strlen($this->tw_user_id) > 0) {
         // send direct message using twitter api.
         try {
             $do_twitter = new OfuzTwitter();
             $tw_config = $do_twitter->getTwitterConfig();
             $serialized_token = $do_twitter->getAccessToken();
             $token = unserialize($serialized_token);
             $ofuz_twitter = new Ofuz_Service_Twitter($token->getParam('user_id'), $tw_config, $token);
             $followers = $ofuz_twitter->userFollowers(false);
             if (is_object($followers) && count($followers->user) > 0) {
                 foreach ($followers->user as $follower) {
                     if ($follower->id == $this->tw_user_id) {
                         $merge = new MergeString();
                         $message = $merge->withArray($template->bodytext, $values);
                         $ofuz_twitter->directMessageNew($this->tw_user_id, $message);
                         $do_contact_notes = new ContactNotes();
                         $do_contact_notes->iduser = $_SESSION['do_User']->iduser;
                         $do_contact_notes->note = $message;
                         $do_contact_notes->date_added = date('Y-m-d');
                         $do_contact_notes->idcontact = $this->idcontact;
                         $do_contact_notes->add();
                         return true;
                     }
                 }
             }
             $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to " . $contact_link);
         } catch (Exception $e) {
             $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to " . $contact_link);
         }
     } elseif ($this->fb_userid && $_SESSION["do_User"]->global_fb_connected) {
         // send message using facebook api.
         include_once 'facebook_client/facebook.php';
         include_once 'class/OfuzFacebook.class.php';
         $facebook = new Facebook(FACEBOOK_API_KEY, FACEBOOK_APP_SECRET);
         try {
             $msg = _(' has sent the following message using ofuz') . '<br />';
             $msg .= '<b>' . $template->subject . '</b><br/>' . $template->bodyhtml;
             $facebook->api_client->notifications_send($this->fb_userid, $msg, 'user_to_user');
             //$this->last_message_sent = true;
         } catch (Exception $e) {
             $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to " . $contact_link);
         }
     } else {
         $_SESSION['in_page_message'] .= _("<br>" . $contact_link . " doesn't have a valid email address, facebook account, or twitter id.");
     }
     if ($this->last_message_sent) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 5
0
 /**
  * getMessage 
  * get message using message  key string
  */
 function getMessage($message_key, $lang = '')
 {
     if (empty($lang)) {
         $lang = $this->getLanguage();
     }
     $this->query("SELECT * FROM " . $this->getTable() . " where key_name='" . $this->quote($message_key) . "' AND language='" . $lang . "'");
     $content = "";
     if ($this->next()) {
         if (!empty($this->message_data)) {
             $this->content = MergeString::withArray($this->content, $this->message_data);
             return $this->content;
         } else {
             return $this->content;
         }
     } else {
         $this->query("SELECT * FROM " . $this->getTable() . " where key_name='" . $this->quote($message_key) . "' AND language='" . $this->fallback_language . "'");
         if ($this->next()) {
             if (!empty($this->message_data)) {
                 $this->content = MergeString::withArray($this->content, $this->message_data);
                 return $this->content;
             } else {
                 return $this->content;
             }
         } else {
             return false;
         }
     }
 }
Exemplo n.º 6
0
 /**
  * mergeArray()
  * Merge an Array with a currently loaded email template
  * @param $fields_values Array of fields in format $fields['fieldname']=value;
  */
 function mergeArray($fields_values)
 {
     $this->setBodyText(MergeString::withArray($this->getTemplateBodyText(), $fields_values));
     if (strlen($this->getTemplateBodyHtml()) > 5) {
         $this->setBodyHtml(MergeString::withArray($this->getTemplateBodyHtml(), $fields_values));
     }
     $this->setSubject(MergeString::withArray($this->getTemplateSubject(), $fields_values));
 }
 function eventTranslateLanguage(EventControler $evtcl)
 {
     //$src_lang = explode("_",$evtcl->src_lang);
     //$dest_lng = explode("_",$evtcl->dest_lang);
     $src_lang = explode("_", $this->src_lng);
     $dest_lng = explode("_", $this->dest_lng);
     $fields_subject = MergeString::getField($evtcl->et_sub_src);
     $arr_fields_subject = array();
     foreach ($fields_subject as $fields_sub) {
         $arr_fields_subject[$fields_sub] = "AB" . rand(1, 9999) . "YZ";
     }
     $subject = htmlspecialchars($evtcl->et_sub_src, ENT_QUOTES);
     $subject = MergeString::withArray($subject, $arr_fields_subject);
     $fields_bodytext = MergeString::getField($evtcl->et_body_text_src);
     $arr_bodytext = array();
     foreach ($fields_bodytext as $fields_body_text) {
         $arr_bodytext[$fields_body_text] = "AB" . rand(1, 9999) . "YZ";
     }
     $bodytext = htmlspecialchars($evtcl->et_body_text_src, ENT_QUOTES);
     $bodytext = MergeString::withArray($bodytext, $arr_bodytext);
     $fields_bodyhtml = MergeString::getField($evtcl->et_body_html_src);
     $arr_bodyhtml = array();
     foreach ($fields_bodyhtml as $fields_body_html) {
         $arr_bodyhtml[$fields_body_html] = "AB" . rand(1, 9999) . "YZ";
     }
     $bodyhtml = htmlspecialchars($evtcl->et_body_html_src, ENT_QUOTES);
     $bodyhtml = MergeString::withArray($bodyhtml, $arr_bodyhtml);
     $trans_subject = parent::translate($subject, $src_lang[0], $dest_lng[0]);
     $trans_bodytext = parent::translate($bodytext, $src_lang[0], $dest_lng[0]);
     $trans_bodyhtml = parent::translate($bodyhtml, $src_lang[0], $dest_lng[0]);
     $trans_subject = htmlspecialchars_decode($trans_subject);
     $trans_bodytext = htmlspecialchars_decode($trans_bodytext);
     $trans_bodyhtml = htmlspecialchars_decode($trans_bodyhtml);
     $subject = $this->withField($trans_subject, $arr_fields_subject);
     $bodytext = $this->withField($trans_bodytext, $arr_bodytext);
     $bodyhtml = $this->withField($trans_bodyhtml, $arr_bodyhtml);
     $_SESSION["et_sub_src"] = $subject;
     $_SESSION["et_body_text_src"] = $bodytext;
     $_SESSION["et_body_html_src"] = $bodyhtml;
 }