/**
  * Method to generate the email subject
  *
  * @param     object     $lang         Instance of the default user language
  * @param     object     $receiveer    Instance of the the receiving user
  * @param     object     $user         Instance of the user who made the change
  * @param     object     $after        Instance of the item table after it was updated
  * @param     object     $before       Instance of the item table before it was updated
  * @param     boolean    $is_new       True if the item is new ($before will be null)
  *
  * @return    string
  */
 public static function getReplySubject($lang, $receiver, $user, $after, $before, $is_new)
 {
     if (!$is_new) {
         return false;
     }
     $txt_prefix = 'COM_PROJECTFORK_REPLY_EMAIL_' . ($is_new ? 'NEW' : 'UPD');
     $format = $lang->_($txt_prefix . '_SUBJECT');
     $project = PFnotificationsHelper::translateValue('project_id', $after->project_id);
     $topic = PFnotificationsHelper::translateValue('topic_id', $after->topic_id);
     $txt = sprintf($format, $project, $user->name, $topic);
     return $txt;
 }
 /**
  * Method to generate the email subject
  *
  * @param     object     $lang         Instance of the default user language
  * @param     object     $receiveer    Instance of the the receiving user
  * @param     object     $user         Instance of the user who made the change
  * @param     object     $after        Instance of the item table after it was updated
  * @param     object     $before       Instance of the item table before it was updated
  * @param     boolean    $is_new       True if the item is new ($before will be null)
  *
  * @return    string
  */
 public static function getCommentSubject($lang, $receiver, $user, $after, $before, $is_new)
 {
     if (!$is_new) {
         return false;
     }
     list($component, $item) = explode('.', $after->context, 2);
     $class_name = 'PF' . str_replace('com_pf', '', $component) . 'NotificationsHelper';
     $value = null;
     if (class_exists($class_name)) {
         $methods = get_class_methods($class_name);
         if (in_array('getItemName', $methods)) {
             $item = call_user_func(array($class_name, 'getItemName'), $after->context);
         }
         if (in_array('translateItem', $methods)) {
             $value = call_user_func_array(array($class_name, 'translateItem'), array($after->context, $after->item_id));
         }
     }
     $txt_prefix = self::$prefix . '_' . ($is_new ? 'NEW' : 'UPD');
     $format = $lang->_($txt_prefix . '_SUBJECT_' . strtoupper($item));
     $project = PFnotificationsHelper::translateValue('project_id', $after->project_id);
     if (!$value) {
         $value = PFnotificationsHelper::translateValue($item . '_id', $after->item_id);
     }
     if ($item != 'project') {
         $txt = sprintf($format, $project, $user->name, $value);
     } else {
         $txt = sprintf($format, $project, $user->name);
     }
     return $txt;
 }
 /**
  * Method to generate the email message
  *
  * @param     object     $lang         Instance of the default user language
  * @param     object     $receiveer    Instance of the the receiving user
  * @param     object     $user         Instance of the user who made the change
  * @param     object     $after        Instance of the item table after it was updated
  * @param     object     $before       Instance of the item table before it was updated
  * @param     boolean    $is_new       True if the item is new ($before will be null)
  *
  * @return    string
  */
 public static function getMilestoneMessage($lang, $receiver, $user, $after, $before, $is_new)
 {
     // Get the changed fields
     $props = array('description', 'created_by', 'access', array('start_date', 'NE-SQLDATE'), array('end_date', 'NE-SQLDATE'));
     $changes = array();
     if (is_object($before) && is_object($after)) {
         $changes = PFObjectHelper::getDiff($before, $after, $props);
     }
     if ($is_new) {
         $changes = PFObjectHelper::toArray($after, $props);
     }
     $txt_prefix = self::$prefix . '_' . ($is_new ? 'NEW' : 'UPD');
     $format = $lang->_($txt_prefix . '_MESSAGE');
     $changes = PFnotificationsHelper::formatChanges($lang, $changes);
     $footer = sprintf($lang->_('COM_PROJECTFORK_EMAIL_FOOTER'), JURI::root());
     $link = JRoute::_(JURI::root() . PFmilestonesHelperRoute::getMilestoneRoute($after->id, $after->project_id));
     $txt = sprintf($format, $receiver->name, $user->name, $changes, $link);
     $txt = str_replace('\\n', "\n", $txt . "\n\n" . $footer);
     return $txt;
 }
Exemplo n.º 4
0
 /**
  * Method to generate the email message
  *
  * @param     object     $lang         Instance of the default user language
  * @param     object     $receiveer    Instance of the the receiving user
  * @param     object     $user         Instance of the user who made the change
  * @param     object     $after        Instance of the item table after it was updated
  * @param     object     $before       Instance of the item table before it was updated
  * @param     boolean    $is_new       True if the item is new ($before will be null)
  *
  * @return    string
  */
 public static function getRevisionMessage($lang, $receiver, $user, $after, $before, $is_new)
 {
     if (!$is_new) {
         if (isset($after->approved)) {
             $fields = array('title' => $after->title, 'file_name' => $after->file_name, 'file_size' => $after->file_size . 'kb', 'created_by' => $after->created_by, 'description' => $after->description);
             $format = $lang->_('COM_PROJECTFORK_DESIGN_REV_EMAIL_' . ($after->approved ? 'APPROVED' : 'DECLINED') . '_MESSAGE');
         } else {
             return false;
         }
     } else {
         // Get the changed fields
         $fields = array('title' => $after->title, 'file_name' => $after->file_name, 'file_size' => $after->file_size . 'kb', 'description' => $after->description);
         $txt_prefix = 'COM_PROJECTFORK_DESIGN_REV_EMAIL_' . ($is_new ? 'NEW' : 'UPD');
         $format = $lang->_($txt_prefix . '_MESSAGE');
     }
     $album = self::getAlbumId($after->parent_id);
     $changes = PFnotificationsHelper::formatChanges($lang, $fields);
     $footer = sprintf($lang->_('COM_PROJECTFORK_EMAIL_FOOTER'), JURI::root());
     $link = JURI::base(false) . JRoute::_(PFdesignsHelperRoute::getDesignRoute($after->parent_id, $after->project_id, $album, $after->id));
     $txt = sprintf($format, $receiver->name, $user->name, $changes, $link);
     $txt = str_replace('\\n', "\n", $txt . "\n\n" . $footer);
     return $txt;
 }
Exemplo n.º 5
0
 /**
  * Method to generate the email message
  *
  * @param     object     $lang         Instance of the default user language
  * @param     object     $receiveer    Instance of the the receiving user
  * @param     object     $user         Instance of the user who made the change
  * @param     object     $after        Instance of the item table after it was updated
  * @param     object     $before       Instance of the item table before it was updated
  * @param     boolean    $is_new       True if the item is new ($before will be null)
  *
  * @return    string
  */
 public static function getProjectMessage($lang, $receiver, $user, $after, $before, $is_new)
 {
     $txt_prefix = self::$prefix . '_' . ($is_new ? 'NEW' : 'UPD');
     // Get the changed fields
     $props = array('description', 'catid', 'created_by', 'access', 'start_date', 'end_date');
     $changes = array();
     if (is_object($before) && is_object($after)) {
         $changes = PFObjectHelper::getDiff($before, $after, $props);
     }
     if (!count($changes)) {
         return false;
     }
     $format = $lang->_($txt_prefix . '_MESSAGE');
     $changes = PFnotificationsHelper::formatChanges($lang, $changes);
     $footer = sprintf($lang->_('COM_PROJECTFORK_EMAIL_FOOTER'), JURI::root());
     $link = JRoute::_(JURI::root() . PFprojectsHelperRoute::getDashboardRoute($after->id . ':' . $after->alias));
     $txt = sprintf($format, $receiver->name, $user->name, $changes, $link);
     $txt = str_replace('\\n', "\n", $txt . "\n\n" . $footer);
     return $txt;
 }
 public function onContentAfterSave($context, $table, $is_new = false)
 {
     // Check if the plugin is disabled. Return true if it is not.
     if (!JPluginHelper::isEnabled('content', 'pfnotifications')) {
         return true;
     }
     // Component name must start with com_pf
     if (substr($context, 0, 6) != 'com_pf') {
         return true;
     }
     // Check config if sending is enabled for this type of event (new/update)
     $send_type = (int) $this->params->get('send_type');
     if ($is_new && $send_type == 2 || !$is_new && $send_type == 1) {
         return;
     }
     // Import PF library, just to be sure
     jimport('projectfork.library');
     // Make sure the item is supported
     if (!PFnotificationsHelper::isSupported($context)) {
         return true;
     }
     list($component, $item) = explode('.', $context, 2);
     $class_name = 'PF' . str_replace('com_pf', '', $component) . 'NotificationsHelper';
     $methods = get_class_methods($class_name);
     if (in_array('getItemName', $methods)) {
         $item = call_user_func(array($class_name, 'getItemName'), $context);
     }
     $subject_method = 'get' . ucfirst($item) . 'Subject';
     $message_method = 'get' . ucfirst($item) . 'Message';
     $users_method = 'getObservers';
     // Check if the item is active or not
     if (isset($table->state)) {
         if (intval($table->state) !== 1) {
             return true;
         }
     }
     // Check if the methods are available
     if (!in_array($subject_method, $methods) || !in_array($message_method, $methods) || !in_array($users_method, $methods)) {
         return true;
     }
     $users = call_user_func_array(array($class_name, $users_method), array($context, $table, $is_new));
     $dupe = array();
     if (count($users) == 0) {
         return true;
     }
     // Load user objects and perform access check
     if (isset($table->access)) {
         foreach ($users as $i => $u) {
             if (in_array($u, $dupe)) {
                 unset($users[$i]);
                 continue;
             }
             $dupe[] = $u;
             $user = JFactory::getUser((int) $u);
             if (!$user->authorise('core.admin', $component)) {
                 $allowed = $user->getAuthorisedViewLevels();
                 if (!in_array($table->access, $allowed)) {
                     unset($users[$i]);
                     continue;
                 }
             }
             $users[$i] = $user;
         }
     } else {
         foreach ($users as $i => $u) {
             if (in_array($u, $dupe)) {
                 unset($users[$i]);
                 continue;
             }
             $dupe[] = $u;
             $users[$i] = JFactory::getUser((int) $u);
         }
     }
     if (count($users) == 0) {
         return true;
     }
     $def_lang = JComponentHelper::getParams('com_languages')->get('administrator');
     $debug = JFactory::getConfig()->get('debug_lang');
     $mailfrom = JFactory::getConfig()->get('mailfrom');
     $fromname = JFactory::getConfig()->get('fromname');
     $user = JFactory::getUser();
     $is_site = JFactory::getApplication()->isSite();
     $date = new JDate();
     $now = $date->toSql();
     $store = $this->params->get('send_method');
     $db = JFactory::getDbo();
     $this->table_after = $table;
     foreach ($users as $receiver) {
         // Make sure we have a user object and an email address
         if (!is_object($receiver) || empty($receiver->email)) {
             continue;
         }
         if ($receiver->id == $user->id) {
             // Don't mail own actions to self
             continue;
         }
         // Load the default language of the component
         $lang = JLanguage::getInstance($receiver->getParam('language', $receiver->getParam('site_language', $def_lang)), $debug);
         $lang->load("com_projectfork", JPATH_SITE);
         $lang->load($component, JPATH_SITE);
         if ($is_site) {
             $lang->load("com_projectfork", JPATH_ADMINISTRATOR);
             $lang->load($component, JPATH_ADMINISTRATOR);
         }
         // Generate the subject and body
         $subject = call_user_func_array(array($class_name, $subject_method), array($lang, $receiver, $user, $this->table_after, $this->table_before, $is_new));
         $message = call_user_func_array(array($class_name, $message_method), array($lang, $receiver, $user, $this->table_after, $this->table_before, $is_new));
         if ($subject === false || $message === false) {
             // Abort if the subject or message is False
             break;
         }
         if (!$store) {
             // Send directly
             $mailer = JFactory::getMailer();
             $mailer->sendMail($mailfrom, $fromname, $receiver->email, $subject, $message);
         } else {
             // Store in db
             $data = new stdClass();
             $data->id = null;
             $data->email = $receiver->email;
             $data->subject = $subject;
             $data->message = $message;
             $data->created = $now;
             $db->insertObject('#__pf_emailqueue', $data);
         }
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * Method to generate the email message
  *
  * @param     object     $lang         Instance of the default user language
  * @param     object     $receiveer    Instance of the the receiving user
  * @param     object     $user         Instance of the user who made the change
  * @param     object     $after        Instance of the item table after it was updated
  * @param     object     $before       Instance of the item table before it was updated
  * @param     boolean    $is_new       True if the item is new ($before will be null)
  *
  * @return    string
  */
 public static function getAttachmentMessage($lang, $receiver, $user, $after, $before, $is_new)
 {
     if (!$is_new) {
         return false;
     }
     list($component, $item) = explode('.', $after->item_type, 2);
     $txt_prefix = self::$prefix . '_' . ($is_new ? 'NEW' : 'UPD');
     $class_name = 'PF' . str_replace('com_pf', '', $component) . 'NotificationsHelper';
     $value = null;
     if (class_exists($class_name)) {
         $methods = get_class_methods($class_name);
         if (in_array('getItemName', $methods)) {
             $item = call_user_func(array($class_name, 'getItemName'), $after->context);
         }
         if (in_array('translateItem', $methods)) {
             $value = call_user_func_array(array($class_name, 'translateItem'), array($after->item_type, $after->item_id));
         }
     }
     if (!$value) {
         $value = PFnotificationsHelper::translateValue($item . '_id', $after->item_id);
     }
     switch ($item) {
         case 'project':
             $link = PFprojectsHelperRoute::getDashboardRoute($after->project_id);
             break;
         default:
             $class_name = 'PF' . str_replace('com_pf', '', $component) . 'HelperRoute';
             $method = 'get' . ucfirst($item) . 'Route';
             $link = '';
             if (class_exists($class_name)) {
                 if (in_array($method, get_class_methods($class_name))) {
                     $link = call_user_func_array(array($class_name, $method), array($after->item_id, $after->project_id));
                 }
             }
             break;
     }
     $format = $lang->_($txt_prefix . '_MESSAGE');
     $footer = sprintf($lang->_('COM_PROJECTFORK_EMAIL_FOOTER'), JURI::root());
     $link = JRoute::_(JURI::root() . $link);
     $txt = sprintf($format, $receiver->name, $user->name, $value, $link);
     $txt = str_replace('\\n', "\n", $txt . "\n\n" . $footer);
     return $txt;
 }