Beispiel #1
0
 /**
  * Adds a new mail notification into the system or send an email immediately.
  *
  * Example:
  * <code>
  * <?php
  * $mailer 	= FD::getInstance( 'Mailer' );
  * $data 	= new SocialMailerData();
  * $data->set( 'title' 		, 'Some title' );
  * $data->set( 'template'	, 'email.template.file' );
  * $data->set( 'recipient_name'	, 'Recipient' );
  * $data->set( 'recipient_email', '*****@*****.**' );
  * $data->set( 'html'		, true );
  *
  * // Returns a bool value. True if success.
  * $state = $mailer->create( $data );
  * ?>
  * </code>
  *
  * @since	1.0
  * @access	public
  * @param	SocialMailerData	The required mailer data object.
  *
  * @return  boolean True on success, false otherwise
  */
 public function create(SocialMailerData $mailData)
 {
     // Convert the mail data to an array.
     $data = $mailData->toArray();
     $mailer = FD::table('Mailer');
     $mailer->bind($data);
     // If mail object is configured to send immediately, we shouldn't store it.
     if ($mailer->priority == SOCIAL_MAILER_PRIORITY_IMMEDIATE) {
         // If environment is development, then we store this for checking purposes
         if (FD::config()->get('general.environment') === 'development') {
             $mailer->store();
         }
         // Send the mail immediately.
         $state = $this->send(array($mailer));
         return $state;
     }
     return $mailer->store();
 }
Beispiel #2
0
 /**
  * Apps email title (assuming that app itself have already loaded the language file before calling this function)
  * APP_{ELEMENT}_{RULENAME}_EMAIL_TITLE
  *
  * Apps email template namespace
  * apps/{group}/{element}/alerts.{rulename}
  *
  * Apps email template path
  * apps/{group}/{element}/themes/{default/themeName}/emails/{html/text}/alerts.{rulename}
  *
  * Core email title
  * COM_EASYSOCIAL_{ELEMENT}_{RULENAME}_EMAIL_TITLE
  *
  * Core email template namespace
  * site/{element}/alerts.{rulename}
  *
  * Core email template path
  * site/themes/{wireframe/themeName}/emails/{html/text}/{element}/alert.{rulename}
  *
  * @since 1.0
  * @access	public
  * @param	array	$participants	The array of participants (user id) of the action
  * @param	array	$options		Custom options of the email notification
  *
  * @return	boolean		State of the email notification
  *
  * @author	Jason Rey <*****@*****.**>
  */
 public function sendEmail($participants, $options = array())
 {
     $users = $this->getUsers('email', $participants);
     if (empty($users)) {
         return true;
     }
     if (is_object($options)) {
         $options = FD::makeArray($options);
     }
     // If params is not set, just give it an empty array
     if (!isset($options['params'])) {
         $options['params'] = array();
     } else {
         // If params is already set, it is possible that it might be object or registry object
         $options['params'] = FD::makeArray($options['params']);
     }
     // Assign any non-table key into params automatically
     $columns = FD::db()->getTableColumns('#__social_mailer');
     foreach ($options as $key => $val) {
         if (!in_array($key, $columns)) {
             $options['params'][$key] = $val;
         }
     }
     // Set default title if no title is passed in
     if (!isset($options['title'])) {
         $options['title'] = $this->getNotificationTitle('email');
     }
     // Set default template if no template is passed in
     if (!isset($options['template'])) {
         $options['template'] = $this->getMailTemplateName();
     }
     if (!isset($options['html'])) {
         $options['html'] = 1;
     }
     $mailer = FD::mailer();
     $data = new SocialMailerData();
     $data->set('title', $options['title']);
     $data->set('template', $options['template']);
     $data->set('html', $options['html']);
     if (isset($options['params'])) {
         $data->setParams($options['params']);
     }
     // If priority is set, set the priority
     if (isset($options['priority'])) {
         $data->set('priority', $options['priority']);
     }
     if (isset($options['sender_name'])) {
         $data->set('sender_name', $options['sender_name']);
     }
     if (isset($options['sender_email'])) {
         $data->set('sender_email', $options['sender_email']);
     }
     if (isset($options['replyto_email'])) {
         $data->set('replyto_email', $options['replyto_email']);
     }
     // The caller might be passing in 'params' as a SocialRegistry object. Just need to standardize them here.
     // Ensure that the params if set is a valid array
     if (isset($options['params']) && is_object($options['params'])) {
         $options['params'] = FD::makeArray($options['params']);
     }
     // Init a few default widely used parameter
     $user = FD::user();
     if (!isset($options['params']['actor'])) {
         $options['params']['actor'] = $user->getName();
     }
     if (!isset($options['params']['posterName'])) {
         $options['params']['posterName'] = $user->getName();
     }
     if (!isset($options['params']['posterAvatar'])) {
         $options['params']['posterAvatar'] = $user->getAvatar();
     }
     if (!isset($options['params']['posterLink'])) {
         $options['params']['posterLink'] = $user->getPermalink(true, true);
     }
     foreach ($users as $uid) {
         $user = FD::user($uid);
         // If user has been blocked, skip this altogether.
         if ($user->block) {
             continue;
         }
         // If user do not have community access, skip this altogether.
         if (!$user->hasCommunityAccess()) {
             continue;
         }
         // Get the params
         $params = $options['params'];
         // Set the language of the email
         $data->setLanguage($user->getLanguage());
         // Detect the "name" in the params. If it doesn't exist, set the target's name.
         if (is_array($params)) {
             if (!isset($params['recipientName'])) {
                 $params['recipientName'] = $user->getName();
             }
             if (!isset($params['recipientAvatar'])) {
                 $params['recipientAvatar'] = $user->getAvatar();
             }
             $data->setParams($params);
         }
         $data->set('recipient_name', $user->getName());
         $data->set('recipient_email', $user->email);
         $mailer->create($data);
     }
     return true;
 }