示例#1
0
 public function ajaxGetNotification()
 {
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     $json = array();
     $my = CFactory::getUser();
     //$inboxModel       = CFactory::getModel( 'inbox' );
     $friendModel = CFactory::getModel('friends');
     $eventModel = CFactory::getModel('events');
     $groupModel = CFactory::getModel('groups');
     $notiTotal = 0;
     //getting pending event request
     $pendingEvent = $eventModel->getPending($my->id);
     $eventHtml = '';
     $event = JTable::getInstance('Event', 'CTable');
     if (!empty($pendingEvent)) {
         $notiTotal += count($pendingEvent);
         for ($i = 0; $i < count($pendingEvent); $i++) {
             $row = $pendingEvent[$i];
             $row->invitor = CFactory::getUser($row->invited_by);
             $event->load($row->eventid);
             // remove the notification if there is no longer seats available
             if (!CEventHelper::seatsAvailable($event)) {
                 unset($pendingEvent[$i]);
                 continue;
             }
             $row->eventAvatar = $event->getThumbAvatar();
             $row->url = CRoute::_('index.php?option=com_community&view=events&task=viewevent&eventid=' . $row->eventid . false);
             $row->isGroupEvent = $event->contentid ? true : false;
             if ($row->isGroupEvent) {
                 $group = JTable::getInstance('Group', 'CTable');
                 $group->load($event->contentid);
                 $row->groupname = $group->name;
                 $row->grouplink = CUrlHelper::groupLink($group->id);
             }
         }
         $tmpl = new CTemplate();
         $tmpl->set('rows', $pendingEvent);
         $tmpl->setRef('my', $my);
         $eventHtml = $tmpl->fetch('notification.event.invitations');
     }
     //getting pending group request
     $pendingGroup = $groupModel->getGroupInvites($my->id);
     $groupHtml = '';
     $group = JTable::getInstance('Group', 'CTable');
     $groupNotiTotal = 0;
     if (!empty($pendingGroup)) {
         $groupNotiTotal += count($pendingGroup);
         for ($i = 0; $i < count($pendingGroup); $i++) {
             $gRow = $pendingGroup[$i];
             $gRow->invitor = CFactory::getUser($gRow->creator);
             $group->load($gRow->groupid);
             $gRow->name = $group->name;
             $gRow->groupAvatar = $group->getThumbAvatar();
             $gRow->url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $gRow->groupid . false);
         }
         $tmpl = new CTemplate();
         $tmpl->set('gRows', $pendingGroup);
         $tmpl->setRef('my', $my);
         $groupHtml = $tmpl->fetch('notification.group.invitations');
     }
     //geting pending private group join request
     //Find Users Groups Admin
     $allGroups = $groupModel->getAdminGroups($my->id, COMMUNITY_PRIVATE_GROUP);
     $groupMemberApproveHTML = '';
     //Get unApproved member
     if (!empty($allGroups)) {
         foreach ($allGroups as $groups) {
             $member = $groupModel->getMembers($groups->id, 0, false);
             if (!empty($member)) {
                 for ($i = 0; $i < count($member); $i++) {
                     $oRow = $member[$i];
                     $group->load($groups->id);
                     $oRow->groupId = $groups->id;
                     $oRow->groupName = $groups->name;
                     $oRow->groupAvatar = $group->getThumbAvatar();
                     $oRow->url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id . false);
                     $members[] = $member[$i];
                 }
             }
         }
     }
     if (!empty($members)) {
         $tmpl = new CTemplate();
         $tmpl->set('oRows', $members);
         $tmpl->set('my', $my);
         $groupMemberApproveHTML = $tmpl->fetch('notification.group.request');
     }
     //non require action notification
     $itemHtml = '';
     $notifCount = 10;
     $notificationModel = CFactory::getModel('notification');
     $myParams = $my->getParams();
     $notifications = $notificationModel->getNotification($my->id, '0', $notifCount, $myParams->get('lastnotificationlist', ''));
     if (!empty($notifications)) {
         for ($i = 0; $i < count($notifications); $i++) {
             $iRow = $notifications[$i];
             $iRow->actorUser = CFactory::getUser($iRow->actor);
             $iRow->actorAvatar = $iRow->actorUser->getThumbAvatar();
             $iRow->actorName = $iRow->actorUser->getDisplayName();
             $iRow->timeDiff = CTimeHelper::timeLapse(CTimeHelper::getDate($iRow->created));
             $iRow->contentHtml = CContentHelper::injectTags($iRow->content, $iRow->params, true);
             $params = new CParameter($iRow->params);
             $iRow->url = $params->get('url', '');
         }
         $tmpl = new CTemplate();
         $tmpl->set('iRows', $notifications);
         $tmpl->setRef('my', $my);
         $itemHtml = $tmpl->fetch('notification.item');
     }
     $notiHtml = $eventHtml . $groupHtml . $groupMemberApproveHTML . $itemHtml;
     if (empty($notiHtml)) {
         $notiHtml .= '<li>';
         $notiHtml .= JText::_('COM_COMMUNITY_NO_NOTIFICATION');
         $notiHtml .= '</li>';
     }
     $date = JFactory::getDate();
     $myParams->set('lastnotificationlist', $date->toSql());
     $my->save('params');
     $url = CRoute::_('index.php?option=com_community&view=profile&task=notifications');
     $notiHtml .= '<div>';
     $notiHtml .= '<a href="' . $url . '" class="joms-button--neutral joms-button--full">' . JText::_('COM_COMMUNITY_VIEW_ALL') . '</a>';
     $notiHtml .= '</div>';
     $json['title'] = JText::_('COM_COMMUNITY_NOTIFICATIONS');
     $json['html'] = $notiHtml;
     die(json_encode($json));
 }
示例#2
0
 /**
  * 	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();
 }
        ?>
" />
					</a>
				</div>
				<div class="joms-stream__meta">
					<div class="joms-stream__time">
						<small><?php 
        echo CTimeHelper::timeLapse(CTimeHelper::getDate($row->created));
        ?>
</small>
					</div>
				</div>
			</div>
			<div class="joms-stream__body">
				<div class="cStream-Headline"><?php 
        $content = CContentHelper::injectTags($row->content, $row->params, true);
        if ($isPhotoModal && $row->cmd_type == 'notif_photos_like') {
            preg_match_all('/(albumid|photoid)=(\\d+)/', $content, $matches);
            // Get albumid and photoid.
            $albumid = false;
            $photoid = false;
            foreach ($matches[1] as $index => $varname) {
                if ($varname == 'albumid') {
                    $albumid = $matches[2][$index];
                } else {
                    if ($varname == 'photoid') {
                        $photoid = $matches[2][$index];
                    }
                }
            }
            preg_match('/href="[^"]+albumid[^"]+"/', $content, $matches);
示例#4
0
文件: mailq.php 项目: Jougito/DynWeb
 /**
  * Do a batch send
  */
 public function send($total = 100)
 {
     $app = JFactory::getApplication();
     $mailqModel = CFactory::getModel('mailq');
     $userModel = CFactory::getModel('user');
     $mails = $mailqModel->get($total);
     $mailer = JFactory::getMailer();
     $config = CFactory::getConfig();
     $senderEmail = $app->getCfg('mailfrom');
     $senderName = $app->getCfg('fromname');
     $sitename = $app->getCfg('config.sitename');
     if (empty($mails)) {
         return;
     }
     foreach ($mails as $row) {
         if ($row->email_type === 'etype_friends_invite_users') {
             /* for invite email */
             $raw = isset($row->params) ? $row->params : '';
             $rowParams = new CParameter($row->params);
             $userid = JUri::getInstance($rowParams->get('actor_url'))->getVar('userid');
         } else {
             // @rule: only send emails that is valid.
             // @rule: make sure recipient is not blocked!
             $userid = $userModel->getUserFromEmail($row->recipient);
         }
         $user = CFactory::getUser($userid);
         //verify user email list settting
         $user_params = $user->getParams();
         $validate = true;
         if (!empty($row->email_type)) {
             $validate = $user_params->get($row->email_type, $config->get($row->email_type)) == 1 ? true : false;
         }
         if (!$user->isBlocked() && !JString::stristr($row->recipient, 'foo.bar') && $validate) {
             $mailer->setSender(array($senderEmail, $senderName));
             $mailer->addRecipient($row->recipient);
             // Replace any occurences of custom variables within the braces scoe { }
             $row->subject = CContentHelper::injectTags($row->subject, $row->params, false);
             $mailer->setSubject($row->subject);
             $tmpl = new CTemplate();
             $raw = isset($row->params) ? $row->params : '';
             $params = new CParameter($row->params);
             $base = $config->get('htmlemail') ? 'email.html' : 'email.text';
             if ($config->get('htmlemail')) {
                 $row->body = CString::str_ireplace(array("<p>\r\n", "<p>\r", "<p>\n"), '<p>', $row->body);
                 $row->body = CString::str_ireplace(array("</p>\r\n", "</p>\r", "</p>\n"), '</p>', $row->body);
                 $row->body = CString::str_ireplace(array("\r\n", "\r", "\n"), '<br />', $row->body);
                 $mailer->IsHTML(true);
             } else {
                 //@rule: Some content might contain 'html' tags. Strip them out since this mail should never contain html tags.
                 $row->body = CStringHelper::escape(strip_tags($row->body));
             }
             $copyrightemail = JString::trim($config->get('copyrightemail'));
             $tmpl->set('email_type', $row->email_type);
             $tmpl->set('avatar', $user->getAvatar());
             $tmpl->set('thumbAvatar', $user->getThumbAvatar());
             $tmpl->set('name', $user->getDisplayName());
             $tmpl->set('email', $user->email);
             $tmpl->set('sitename', $sitename);
             $tmpl->set('unsubscribeLink', CRoute::getExternalURL('index.php?option=com_community&view=profile&task=email'), false);
             $tmpl->set('userid', $userid);
             $tmpl->set('copyrightemail', $copyrightemail);
             $tmpl->set('recepientemail', $row->recipient);
             $tmpl->set('content', $row->body);
             $tmpl->set('template', JURI::root(true) . '/components/com_community/templates/' . $config->get('template'));
             $tmpl->set('sitename', $config->get('sitename'));
             $row->body = $tmpl->fetch($base);
             // Replace any occurences of custom variables within the braces scoe { }
             if (!empty($row->body)) {
                 $row->body = CContentHelper::injectTags($row->body, $row->params, false);
             }
             unset($tmpl);
             $mailer->setBody($row->body);
             if ($mailer->send()) {
                 $validate = true;
             } else {
                 $validate = false;
             }
         }
         if (!$validate) {
             //email is blocked by user settings
             $mailqModel->markEmailStatus($row->id, 2);
         } else {
             $mailqModel->markSent($row->id);
         }
         $mailer->ClearAllRecipients();
     }
 }