/** * @param $message * @param $actor * @param $object * @param array $info * @return bool */ static function parseTaggedUserNotification($message, $actor, $object = null, $info = array()) { $pattern = '/@\\[\\[(\\d+):([a-z]+):([^\\]]+)\\]\\]/'; preg_match_all($pattern, $message, $matches); if (isset($matches[1]) && count($matches[1]) > 0) { //lets count total recipients and blast notifications $taggedIds = array(); foreach ($matches[1] as $uid) { $taggedIds[] = CFactory::getUser($uid)->get('id') != 0 ? $uid : null; } if ($info['type'] == 'discussion-comment') { //link to lead the user to the discussion $url = CRoute::emailLink('index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $info['group_id'] . '&topicid=' . $info['discussion_id'] . '#activity-stream-container'); $params = new CParameter(); $params->set('url', $url); $params->set('content', $message); $params->set('discussion', '<a href="' . $url . '">' . JText::_('COM_COMMUNITY_DISCUSSION') . '</a>'); $emailSubject = JText::sprintf('COM_COMMUNITY_DISCUSSION_USER_TAGGED_EMAIL_SUBJECT'); $emailContent = JText::sprintf('COM_COMMUNITY_USER_TAGGED_COMMENT_EMAIL_CONTENT', $url); $notificationMessage = JText::_('COM_COMMUNITY_NOTIFICATION_DISCUSSION_USER_TAGGED'); } else { if ($info['type'] == 'album-comment') { //link to lead the user to the album $url = CRoute::emailLink('index.php?option=com_community&view=photos&task=album&userid=' . $info['album_creator_id'] . '&albumid=' . $info['album_id'] . '#activity-stream-container'); $params = new CParameter(); $params->set('url', $url); $params->set('content', $message); $params->set('album', '<a href="' . $url . '">' . JText::_('COM_COMMUNITY_SINGULAR_ALBUM') . '</a>'); $emailSubject = JText::sprintf('COM_COMMUNITY_ALBUM_USER_TAGGED_EMAIL_SUBJECT'); $emailContent = JText::sprintf('COM_COMMUNITY_USER_TAGGED_COMMENT_EMAIL_CONTENT', $url); $notificationMessage = JText::_('COM_COMMUNITY_NOTIFICATION_ALBUM_USER_TAGGED'); } else { if ($info['type'] == 'video-comment') { //link to lead the user to the video $url = CRoute::emailLink('index.php?option=com_community&view=videos&task=video&userid=' . $actor->id . '&videoid=' . $info['video_id'] . '#activity-stream-container'); $params = new CParameter(); $params->set('url', $url); $params->set('content', $message); $params->set('video', '<a href="' . $url . '">' . JText::_('COM_COMMUNITY_SINGULAR_PHOTO') . '</a>'); $emailSubject = JText::sprintf('COM_COMMUNITY_VIDEO_USER_TAGGED_EMAIL_SUBJECT'); $emailContent = JText::sprintf('COM_COMMUNITY_USER_TAGGED_COMMENT_EMAIL_CONTENT', $url); $notificationMessage = JText::_('COM_COMMUNITY_NOTIFICATION_VIDEO_USER_TAGGED'); } else { if ($info['type'] == 'image-comment') { //link to lead the user to the picture $url = CRoute::emailLink('index.php?option=com_community&view=photos&task=photo&userid=' . $actor->id . '&albumid=' . $info['album_id'] . '&photoid=' . $info['image_id'] . '#activity-stream-container'); $params = new CParameter(); $params->set('url', $url); $params->set('content', $message); $params->set('photo', '<a href="' . $url . '">' . JText::_('COM_COMMUNITY_SINGULAR_PHOTO') . '</a>'); $emailSubject = JText::sprintf('COM_COMMUNITY_PHOTO_USER_TAGGED_EMAIL_SUBJECT'); $emailContent = JText::sprintf('COM_COMMUNITY_USER_TAGGED_COMMENT_EMAIL_CONTENT', $url); $notificationMessage = JText::_('COM_COMMUNITY_NOTIFICATION_PHOTO_USER_TAGGED'); } else { if ($info['type'] == 'post-comment' && $object != null) { //default notification, and object is activity //set parameter to be replaced in the template $url = CRoute::emailLink('index.php?option=com_community&view=profile&userid=' . $object->actor . '&actid=' . $object->id . '#activity-stream-container'); $params = new CParameter(); $params->set('url', $url); $params->set('content', $message); $params->set('post', '<a href="' . $url . '">' . JText::_('COM_COMMUNITY_SINGULAR_POST') . '</a>'); $emailSubject = JText::sprintf('COM_COMMUNITY_PROFILE_USER_TAGGED_EMAIL_SUBJECT'); $emailContent = JText::sprintf('COM_COMMUNITY_PROFILE_USER_TAGGED_COMMENT_EMAIL_CONTENT', $url); $notificationMessage = JText::_('COM_COMMUNITY_NOTIFICATION_USER_TAGGED'); } else { return false; } } } } } //add to notifications CNotificationLibrary::add('users_tagged', $actor->id, $taggedIds, $emailSubject, $emailContent, '', $params, true, '', $notificationMessage); return true; } return false; }
function savecomment($response, $id, $value) { require_once JPATH_PLUGINS . DS . 'community' . DS . 'activitycomment' . DS . 'helper.php'; JPlugin::loadLanguage('plg_activitycomment', JPATH_ADMINISTRATOR); $my =& CFactory::getUser(); if ($my->id == 0) { return 'invalid'; } if (empty($value)) { $response->addScriptCall(ActivityComments::getjs() . '("#activity-' . $id . '-comment-errors").html("' . JText::_('COMMENT CANNOT BE EMPTY') . '").css("color","red");'); return $response->sendResponse(); } $my =& CFactory::getUser(); require_once JPATH_ROOT . DS . 'components' . DS . 'com_community' . DS . 'models' . DS . 'wall.php'; $wall =& JTable::getInstance('Wall', 'CTable'); CFactory::load('helpers', 'linkgenerator'); $params = ActivityComments::getParams(); $value = strip_tags($value); $value = cGenerateURILinks($value, true, $params->get('shareurltarget')); // Get current date $date =& JFactory::getDate(); $now = $date->toMySQL(); $wall->type = 'activity'; $wall->contentid = $id; $wall->post_by = $my->id; $wall->comment = $value; $wall->date = $now; $wall->published = 1; $wall->ip = $_SERVER['REMOTE_ADDR']; $wall->store(); $params = ActivityComments::getParams(); $sendEmail = $params->get('notifycomment', 0); $db =& JFactory::getDBO(); if ($sendEmail == 1) { $query = 'select actor from #__community_activities where id=' . $db->Quote($id); $db->setQuery($query); $actorId = $db->loadResult(); if ($actorId != $my->id) { $actor =& CFactory::getUser($actorId); CFactory::load('libraries', 'notification'); $notification = new CNotificationLibrary(); $current = CRoute::emailLink(ActivityComments::getCurrent(), false) . '#profile-newsfeed-item' . $id; $notification->add('profile.activity.comment', $my->id, $actorId, JText::sprintf('SOMEONE COMMENTED MAIL SUBJECT', $my->getDisplayName()), JText::sprintf('SOMEONE COMMENTED MAIL CONTENT', $actor->getDisplayName(), $my->getDisplayName(), $current)); } } // send emails to subscribers $a = 'select * from #__activity_subscribe where ' . '`activity_id`=' . $db->Quote($id) . ' ' . 'and `type`=' . $db->Quote('profile'); $db->setQuery($a); $subscribers = $db->loadObjectList(); if ($subscribers) { $emails = array(); foreach ($subscribers as $subscriber) { $emails[] = $subscriber->user_id; } CFactory::load('libraries', 'notification'); $notification = new CNotificationLibrary(); $current = CRoute::emailLink(ActivityComments::getCurrent(), false) . '#profile-newsfeed-item' . $id; $notification->add('profile.activity.comment', $my->id, $emails, JText::sprintf('SUBSCRIBE SOMEONE COMMENTED MAIL SUBJECT', $my->getDisplayName()), JText::sprintf('SUBSCRIBE SOMEONE COMMENTED MAIL CONTENT', $my->getDisplayName(), $current)); } $joomla = JFactory::getConfig(); $offset = $my->getParam('timezone', $joomla->getValue('offset')); $config = CFactory::getConfig(); $date->setOffset($offset + $config->get('daylightsavingoffset')); ob_start(); ?> <div class="wallcmt small" id="activity-comment-item-<?php echo $wall->id; ?> "> <a href="<?php echo CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id); ?> "><img class="wall-coc-avatar" src="<?php echo $my->getThumbAvatar(); ?> "/></a> <a href="<?php echo CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id); ?> " class="wall-coc-author"><?php echo $my->getDisplayName(); ?> </a> <?php echo JText::_('POST ON'); ?> <span class="wall-coc-date"><?php echo $date->toFormat(JText::_('DATE_FORMAT_LC2')); ?> </span> <?php if (ActivityComments::isSiteAdmin()) { ?> | <span class="coc-remove"><a href="javascript:void(0);" onclick="jax.call('community','plugins,activitycomment,removecomment','<?php echo $wall->id; ?> ');"><?php echo JText::_('REMOVE COMMENT'); ?> </a></span> <?php } ?> <p><?php echo $wall->comment; ?> </p> </div> <?php $contents = ob_get_contents(); ob_end_clean(); $closeComment = $params->get('autoclose', 0); if ($closeComment) { $response->addScriptCall('activityHideComment', $id); } $response->addScriptCall(ActivityComments::getjs() . '("#activity-' . $id . '-comment-errors").html("' . JText::_('COMMENT ADDED') . '").css("color","green");'); $response->addScriptCall('activityInsertComment', $id, $contents, $params->get('commentordering', 'asc')); return $response->sendResponse(); }
/** * Automatically hyperlink a user's link * * @param $userId User's id. * @param $userName Username of user. * * return $urlLink HTML codes that hyperlink to users profile. **/ public static function getUserURL($userId, $userName, $email = false) { if ($email) { $url = CRoute::emailLink('index.php?option=com_community&view=profile&userid=' . $userId, true); } else { $url = CRoute::_('index.php?option=com_community&view=profile&userid=' . $userId); } $urlLink = '<a href="' . $url . '" rel="nofollow">' . $userName . '</a>'; return $urlLink; }
/** * Automatically link username in the provided message when message contains @username * @param $message * @param bool $email * @param bool $usernameOnly only pass username without hyperlink * @return mixed $message A modified copy of the message with the proper hyperlinks or username. */ public static function replaceAliasURL($message, $email = false, $usernameOnly = false) { $pattern = '/@\\[\\[(\\d+):([a-z]+):([^\\]]+)\\]\\]/'; preg_match_all($pattern, $message, $matches); if (isset($matches[1]) && count($matches[1]) > 0) { foreach ($matches[1] as $key => $uid) { $id = CFactory::getUser($uid)->get('id'); $username = $matches[3][$key]; if ($id != 0) { if ($email) { $profileLink = CRoute::emailLink('index.php?option=com_community&view=profile&userid=' . $id, true); $message = CString::str_ireplace('@' . $username, $profileLink, $message); } elseif ($usernameOnly) { $message = CString::str_ireplace($matches[0][$key], $username, $message); } else { $message = CString::str_ireplace($matches[0][$key], CLinkGeneratorHelper::getUserURL($id, $username), $message); } } } } return $message; }