/** * Adds notification data into the mailq table * */ public static function addMultiple($command, $actorId, $recipients, $subject, $body, $templateFile = '', $mailParams = '', $sendEmail = true, $favicon = '') { //CFactory::load( 'helpers' , 'validate' ); // Need to make sure actor is NULL, so default user will be returned // from getUser if (empty($actorId)) { $actorId = null; } $mailq = CFactory::getModel('Mailq'); $actor = CFactory::getUser($actorId); $config = CFactory::getConfig(); if (!is_array($recipients)) { $recipientsArray = array(); $recipientsArray[] = $recipients; } else { $recipientsArray = $recipients; } $contents = ''; // If template file is given, we shall extract the email from the template file. if (!empty($templateFile)) { $tmpl = new CTemplate(); preg_match('/email/i', $templateFile, $matches); if (empty($matches)) { $templateFile = 'email.' . $templateFile; $templateFile .= $config->get('htmlemail') ? '.html' : '.text'; } if (is_object($mailParams)) { $dataArray = $mailParams->toArray(); foreach ($dataArray as $key => $value) { $tmpl->set($key, $value); } } elseif (is_array($mailParams)) { foreach ($mailParams as $key => $val) { $tmpl->set($key, $val); } } $contents = $tmpl->fetch($templateFile); } else { $contents = $body; } $cmdData = explode('_', $command); //check and add some default tags to params if (is_object($mailParams)) { if (is_null($mailParams->get('actor', null))) { $mailParams->set('actor', $actor->getDisplayName()); } if (is_null($mailParams->get('actor_url', null))) { $mailParams->set('actor_url', 'index.php?option=com_community&view=profile&userid=' . $actor->id); } } $notificationTypes = new CNotificationTypes(); if (empty($recipientsArray)) { return; } //prevent sending duplicate notification to the same users $recipientsArray = array_unique($recipientsArray); // check for privacy setting for each user foreach ($recipientsArray as $recipient) { //we process the receipient emails address differently from the receipient id. $recipientEmail = ''; $recipientName = ''; $sendIt = false; if (CValidateHelper::email($recipient)) { // Check if the recipient email same with actor email $self = self::filterActor($actorId, $recipient); // If same, skip to next email if ($self) { continue; } $recipientName = ''; $sendIt = true; $recipientEmail = $recipient; } else { $userTo = CFactory::getUser($recipient); // Check if the recipient email same with actor email $self = self::filterActor($actorId, $userTo->email); // If same, skip to next email if ($self) { continue; } $params = $userTo->getParams(); $recipientName = $userTo->getDisplayName(); $recipientEmail = $userTo->email; $sendIt = false; if (isset($cmdData[1])) { switch ($cmdData[0]) { case 'inbox': case 'photos': case 'groups': case 'events': case 'friends': case 'profile': // $sendIt = $params->get('notifyEmailSystem'); // break; // $sendIt = $params->get('notifyEmailSystem'); // break; case 'system': default: $sendIt = true; break; } } //add global notification $notifType = $notificationTypes->getType('', $command); $type = $notifType->requiredAction ? '1' : '0'; $model = CFactory::getModel('Notification'); $model->add($actorId, $recipient, $subject, CNotificationTypesHelper::convertNotifId($command), $type, $mailParams); } if ($sendIt) { // Porcess the message and title $search = array('{actor}', '{target}'); $replace = array($actor->getDisplayName(), $recipientName); $emailSubject = CString::str_ireplace($search, $replace, $subject); $body = CString::str_ireplace($search, $replace, $contents); //inject params value to subject $params = is_object($mailParams) && method_exists($mailParams, 'toString') ? $mailParams->toString() : ''; $emailSubject = CContentHelper::injectTags($emailSubject, $params, false); $mailq->addMultiple($recipientEmail, $emailSubject, $body, $templateFile, $mailParams, 0, CNotificationTypesHelper::convertEmailId($command)); } } /* have done adding multiple than now do send */ $mailq->send(); }
/** * Inititalize the user JUser object * return true if the user is a new */ public function init($initObj = null) { $isNewUser = false; if (!$this->_init) { $config = CFactory::getConfig(); $db = JFactory::getDBO(); $obj = $initObj; if ($initObj == null) { $query = 'SELECT ' . ' a.' . $db->quoteName('userid') . ' as _userid , ' . ' a.' . $db->quoteName('status') . ' as _status , ' . ' a.' . $db->quoteName('points') . ' as _points, ' . ' a.' . $db->quoteName('posted_on') . ' as _posted_on, ' . ' a.' . $db->quoteName('avatar') . ' as _avatar , ' . ' a.' . $db->quoteName('cover') . ' as _cover , ' . ' a.' . $db->quoteName('thumb') . ' as _thumb , ' . ' a.' . $db->quoteName('invite') . ' as _invite, ' . ' a.' . $db->quoteName('params') . ' as _cparams, ' . ' a.' . $db->quoteName('view') . ' as _view, ' . ' a.' . $db->quoteName('friends') . ' as _friends, ' . ' a.' . $db->quoteName('groups') . ' as _groups, ' . ' a.' . $db->quoteName('events') . ' as _events, ' . ' a.' . $db->quoteName('friendcount') . ' as _friendcount, ' . ' a.' . $db->quoteName('alias') . ' as _alias, ' . ' a.' . $db->quoteName('profile_id') . ' as _profile_id, ' . ' a.' . $db->quoteName('storage') . ' as _storage, ' . ' a.' . $db->quoteName('watermark_hash') . ' as _watermark_hash, ' . ' a.' . $db->quoteName('search_email') . ' as _search_email, ' . ' s.' . $db->quoteName('userid') . ' as _isonline, u.* ' . ' FROM ' . $db->quoteName('#__community_users') . ' as a ' . ' LEFT JOIN ' . $db->quoteName('#__users') . ' u ' . ' ON u.' . $db->quoteName('id') . '=a.' . $db->quoteName('userid') . ' LEFT OUTER JOIN ' . $db->quoteName('#__session') . ' s ' . ' ON s.' . $db->quoteName('userid') . '=a.' . $db->quoteName('userid') . ' AND s.' . $db->quoteName('client_id') . ' !=' . $db->Quote('1') . ' WHERE a.' . $db->quoteName('userid') . '=' . $db->Quote($this->id); $db->setQuery($query); $obj = $db->loadObject(); if ($db->getErrorNum()) { JError::raiseError(500, $db->stderr()); } } // Initialise new user if (empty($obj)) { if (!$obj && $this->id != 0) { // @rule: ensure that the id given is correct and exists in #__users $existQuery = 'SELECT COUNT(1) FROM ' . $db->quoteName('#__users') . ' ' . 'WHERE ' . $db->quoteName('id') . '=' . $db->Quote($this->id); $db->setQuery($existQuery); $isValid = $db->loadResult() > 0 ? true : false; if ($isValid) { // We need to create a new record for this specific user first. $obj = new stdClass(); $obj->userid = $this->id; $obj->points = $this->_points; $obj->thumb = ''; $obj->avatar = ''; // Load default params $obj->params = "notifyEmailSystem=" . $config->get('privacyemail') . "\n" . "privacyProfileView=" . $config->get('privacyprofile') . "\n" . "privacyPhotoView=" . $config->get('privacyphotos') . "\n" . "privacyFriendsView=" . $config->get('privacyfriends') . "\n" . "privacyGroupsView=" . $config->get('privacy_groups_list') . "\n" . "privacyVideoView=" . $config->get('privacyvideos') . "\n" . "notifyEmailMessage=" . $config->get('privacyemailpm') . "\n" . "notifyEmailApps=" . $config->get('privacyapps') . "\n" . "notifyWallComment=" . $config->get('privacywallcomment') . "\n"; //load default email privacy settings //CFactory::load( 'libraries' , 'notificationtypes' ); $notificationtypes = new CNotificationTypes(); $obj->params .= $notificationtypes->convertToParamsString(); $db->insertObject('#__community_users', $obj); if ($db->getErrorNum()) { JError::raiseError(500, $db->stderr()); } // Reload the object $db->setQuery($query); $obj = $db->loadObject(); $isNewUser = true; } } } if ($obj) { $thisVars = get_object_vars($this); // load cparams $this->_cparams = new CParameter($obj->_cparams); // fix a bug where privacyVideoView = 1 if ($this->_cparams->get('privacyVideoView') == 1) { $this->_cparams->set('privacyVideoView', 0); } unset($obj->_cparams); // load user params $this->_params = new CParameter($obj->params); unset($obj->params); foreach ($thisVars as $key => $val) { if (isset($obj->{$key})) { $this->{$key} = $obj->{$key}; } } #correct the friendcount here because blocked user are still counted in "friendcount" //$model = CFactory::getModel( 'friends' ); //$realfriendcount = $model->getFriendsCount($this->id); //$this->_friendcount = $realfriendcount; // Update group list if we haven't get if ($this->_params->get('update_cache_list', 0) == 0) { //dont load updateGroupList in the backend if (strpos(JURI::current(), 'administrator') == false) { $this->updateGroupList(); $this->updateEventList(); } $this->_params->set('update_cache_list', 1); /* Temporary fix for Joomla! 3.2 when save user without groups array in object */ if (is_array($this->groups) && count($this->groups) == 0 && (JVERSION > 3.1 && JVERSION < 3.3)) { $params = JComponentHelper::getParams('com_users'); /** * @todo Should we remove these when Joomla! fixed their issue */ if (isset($query)) { unset($query); } if (isset($result)) { unset($result); } $query = $db->getQuery(true); $query = 'SELECT ' . $db->quoteName('group_id') . ' FROM ' . $db->quoteName('#__user_usergroup_map') . ' WHERE ' . $db->quoteName('user_id') . '=' . (int) $this->id; $db->setQuery($query); $result = $db->loadColumn(); if (is_null($result)) { // Get the default new user group, Registered if not specified. $result = array($params->get('new_usertype', 2)); } $this->groups = $result; } $this->save(); } // Set FB post param to default system value if it is not yet set if (is_null($this->_cparams->get('postFacebookStatus', null))) { $this->_cparams->set('postFacebookStatus', $config->get('fbconnectpoststatus')); } } else { // this is a visitor, we still have to create params object for them $this->_cparams = new CParameter(''); $this->_params = new CParameter(''); } $this->_init = true; } return $isNewUser; }