/** * Called by status box to add new stream data * * @param type $message * @param type $attachment * @return type */ public function ajaxStreamAdd($message, $attachment, $streamFilter = FALSE) { $streamHTML = ''; // $attachment pending filter $cache = CFactory::getFastCache(); $cache->clean(array('activities')); $my = CFactory::getUser(); $userparams = $my->getParams(); if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } //@rule: In case someone bypasses the status in the html, we enforce the character limit. $config = CFactory::getConfig(); if (JString::strlen($message) > $config->get('statusmaxchar')) { $message = JHTML::_('string.truncate', $message, $config->get('statusmaxchar')); } $message = JString::trim($message); $objResponse = new JAXResponse(); $rawMessage = $message; // @rule: Autolink hyperlinks // @rule: Autolink to users profile when message contains @username // $message = CUserHelper::replaceAliasURL($message); // the processing is done on display side $emailMessage = CUserHelper::replaceAliasURL($rawMessage, true); // @rule: Spam checks if ($config->get('antispam_akismet_status')) { $filter = CSpamFilter::getFilter(); $filter->setAuthor($my->getDisplayName()); $filter->setMessage($message); $filter->setEmail($my->email); $filter->setURL(CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id)); $filter->setType('message'); $filter->setIP($_SERVER['REMOTE_ADDR']); if ($filter->isSpam()) { $objResponse->addAlert(JText::_('COM_COMMUNITY_STATUS_MARKED_SPAM')); return $objResponse->sendResponse(); } } $attachment = json_decode($attachment, true); switch ($attachment['type']) { case 'message': //if (!empty($message)) { switch ($attachment['element']) { case 'profile': //only update user status if share messgage is on his profile if (COwnerHelper::isMine($my->id, $attachment['target'])) { //save the message $status = $this->getModel('status'); /* If no privacy in attachment than we apply default: Public */ if (!isset($attachment['privacy'])) { $attachment['privacy'] = COMMUNITY_STATUS_PRIVACY_PUBLIC; } $status->update($my->id, $rawMessage, $attachment['privacy']); //set user status for current session. $today = JFactory::getDate(); $message2 = empty($message) ? ' ' : $message; $my->set('_status', $rawMessage); $my->set('_posted_on', $today->toSql()); // Order of replacement $order = array("\r\n", "\n", "\r"); $replace = '<br />'; // Processes \r\n's first so they aren't converted twice. $messageDisplay = str_replace($order, $replace, $message); $messageDisplay = CKses::kses($messageDisplay, CKses::allowed()); //update user status $objResponse->addScriptCall("joms.jQuery('#profile-status span#profile-status-message').html('" . addslashes($messageDisplay) . "');"); } //if actor posted something to target, the privacy should be under target's profile privacy settings if (!COwnerHelper::isMine($my->id, $attachment['target']) && $attachment['target'] != '') { $attachment['privacy'] = CFactory::getUser($attachment['target'])->getParams()->get('privacyProfileView'); } //push to activity stream $act = new stdClass(); $act->cmd = 'profile.status.update'; $act->actor = $my->id; $act->target = $attachment['target']; $act->title = $message; $act->content = ''; $act->app = $attachment['element']; $act->cid = $my->id; $act->access = $attachment['privacy']; $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'profile.status'; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'profile.status'; $activityParams = new CParameter(''); /* Save cords if exists */ if (isset($attachment['location'])) { /* Save geo name */ $act->location = $attachment['location'][0]; $act->latitude = $attachment['location'][1]; $act->longitude = $attachment['location'][2]; } $headMeta = new CParameter(''); if (isset($attachment['fetch'])) { $headMeta->set('title', $attachment['fetch'][2]); $headMeta->set('description', $attachment['fetch'][3]); $headMeta->set('image', $attachment['fetch'][1]); $headMeta->set('link', $attachment['fetch'][0]); //do checking if this is a video link $video = JTable::getInstance('Video', 'CTable'); $isValidVideo = @$video->init($attachment['fetch'][0]); if ($isValidVideo) { $headMeta->set('type', 'video'); $headMeta->set('video_provider', $video->type); $headMeta->set('video_id', $video->getVideoId()); $headMeta->set('height', $video->getHeight()); $headMeta->set('width', $video->getWidth()); } $activityParams->set('headMetas', $headMeta->toString()); } //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $activityParams->set('mood', $attachment['mood']); } $act->params = $activityParams->toString(); //CActivityStream::add($act); //check if the user points is enabled if (CUserPoints::assignPoint('profile.status.update')) { /* Let use our new CApiStream */ $activityData = CApiActivities::add($act); CTags::add($activityData); $recipient = CFactory::getUser($attachment['target']); $params = new CParameter(''); $params->set('actorName', $my->getDisplayName()); $params->set('recipientName', $recipient->getDisplayName()); $params->set('url', CUrlHelper::userLink($act->target, false)); $params->set('message', $message); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id)); CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::sprintf('COM_COMMUNITY_FRIEND_WALL_POST', $my->getDisplayName()), '', 'wall.post', $params); //email and add notification if user are tagged CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment')); } break; // Message posted from Group page // Message posted from Group page case 'groups': // $groupLib = new CGroups(); $group = JTable::getInstance('Group', 'CTable'); $group->load($attachment['target']); // Permission check, only site admin and those who has // mark their attendance can post message if (!COwnerHelper::isCommunityAdmin() && !$group->isMember($my->id) && $config->get('lockgroupwalls')) { $objResponse->addScriptCall("alert('permission denied');"); return $objResponse->sendResponse(); } $act = new stdClass(); $act->cmd = 'groups.wall'; $act->actor = $my->id; $act->target = 0; $act->title = $message; $act->content = ''; $act->app = 'groups.wall'; $act->cid = $attachment['target']; $act->groupid = $group->id; $act->group_access = $group->approvals; $act->eventid = 0; $act->access = 0; $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'groups.wall'; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'groups.wall'; $activityParams = new CParameter(''); /* Save cords if exists */ if (isset($attachment['location'])) { /* Save geo name */ $act->location = $attachment['location'][0]; $act->latitude = $attachment['location'][1]; $act->longitude = $attachment['location'][2]; } $headMeta = new CParameter(''); if (isset($attachment['fetch'])) { $headMeta->set('title', $attachment['fetch'][2]); $headMeta->set('description', $attachment['fetch'][3]); $headMeta->set('image', $attachment['fetch'][1]); $headMeta->set('link', $attachment['fetch'][0]); //do checking if this is a video link $video = JTable::getInstance('Video', 'CTable'); $isValidVideo = @$video->init($attachment['fetch'][0]); if ($isValidVideo) { $headMeta->set('type', 'video'); $headMeta->set('video_provider', $video->type); $headMeta->set('video_id', $video->getVideoId()); $headMeta->set('height', $video->getHeight()); $headMeta->set('width', $video->getWidth()); } $activityParams->set('headMetas', $headMeta->toString()); } //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $activityParams->set('mood', $attachment['mood']); } $act->params = $activityParams->toString(); $activityData = CApiActivities::add($act); CTags::add($activityData); CUserPoints::assignPoint('group.wall.create'); $recipient = CFactory::getUser($attachment['target']); $params = new CParameter(''); $params->set('message', $emailMessage); $params->set('group', $group->name); $params->set('group_url', 'index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id); $params->set('url', CRoute::getExternalURL('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id, false)); //Get group member emails $model = CFactory::getModel('Groups'); $members = $model->getMembers($attachment['target'], null, true, false, true); $membersArray = array(); if (!is_null($members)) { foreach ($members as $row) { if ($my->id != $row->id) { $membersArray[] = $row->id; } } } $groupParams = new CParameter($group->params); if ($groupParams->get('wallnotification')) { CNotificationLibrary::add('groups_wall_create', $my->id, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_WALL_POST_NOTIFICATION_EMAIL_SUBJECT', $my->getDisplayName(), $group->name), '', 'groups.post', $params); } //@since 4.1 when a there is a new post in group, dump the data into group stats $statsModel = CFactory::getModel('stats'); $statsModel->addGroupStats($group->id, 'post'); // Add custom stream // Reload the stream with new stream data $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true)); break; // Message posted from Event page // Message posted from Event page case 'events': $eventLib = new CEvents(); $event = JTable::getInstance('Event', 'CTable'); $event->load($attachment['target']); // Permission check, only site admin and those who has // mark their attendance can post message if (!COwnerHelper::isCommunityAdmin() && !$event->isMember($my->id) && $config->get('lockeventwalls')) { $objResponse->addScriptCall("alert('permission denied');"); return $objResponse->sendResponse(); } // If this is a group event, set the group object $groupid = $event->type == 'group' ? $event->contentid : 0; // $groupLib = new CGroups(); $group = JTable::getInstance('Group', 'CTable'); $group->load($groupid); $act = new stdClass(); $act->cmd = 'events.wall'; $act->actor = $my->id; $act->target = 0; $act->title = $message; $act->content = ''; $act->app = 'events.wall'; $act->cid = $attachment['target']; $act->groupid = $event->type == 'group' ? $event->contentid : 0; $act->group_access = $group->approvals; $act->eventid = $event->id; $act->event_access = $event->permission; $act->access = 0; $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'events.wall'; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'events.wall'; $activityParams = new CParameter(''); /* Save cords if exists */ if (isset($attachment['location'])) { /* Save geo name */ $act->location = $attachment['location'][0]; $act->latitude = $attachment['location'][1]; $act->longitude = $attachment['location'][2]; } $headMeta = new CParameter(''); if (isset($attachment['fetch'])) { $headMeta->set('title', $attachment['fetch'][2]); $headMeta->set('description', $attachment['fetch'][3]); $headMeta->set('image', $attachment['fetch'][1]); $headMeta->set('link', $attachment['fetch'][0]); //do checking if this is a video link $video = JTable::getInstance('Video', 'CTable'); $isValidVideo = @$video->init($attachment['fetch'][0]); if ($isValidVideo) { $headMeta->set('type', 'video'); $headMeta->set('video_provider', $video->type); $headMeta->set('video_id', $video->getVideoId()); $headMeta->set('height', $video->getHeight()); $headMeta->set('width', $video->getWidth()); } $activityParams->set('headMetas', $headMeta->toString()); } //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $activityParams->set('mood', $attachment['mood']); } $act->params = $activityParams->toString(); $activityData = CApiActivities::add($act); CTags::add($activityData); // add points CUserPoints::assignPoint('event.wall.create'); $params = new CParameter(''); $params->set('message', $emailMessage); $params->set('event', $event->title); $params->set('event_url', 'index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id); $params->set('url', CRoute::getExternalURL('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id, false)); //Get event member emails $members = $event->getMembers(COMMUNITY_EVENT_STATUS_ATTEND, 12, CC_RANDOMIZE); $membersArray = array(); if (!is_null($members)) { foreach ($members as $row) { if ($my->id != $row->id) { $membersArray[] = $row->id; } } } CNotificationLibrary::add('events_wall_create', $my->id, $membersArray, JText::sprintf('COM_COMMUNITY_NEW_WALL_POST_NOTIFICATION_EMAIL_SUBJECT_EVENTS', $my->getDisplayName(), $event->title), '', 'events.post', $params); //@since 4.1 when a there is a new post in event, dump the data into event stats $statsModel = CFactory::getModel('stats'); $statsModel->addEventStats($event->id, 'post'); // Reload the stream with new stream data $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true)); break; } $objResponse->addScriptCall('__callback', ''); // /} break; case 'photo': switch ($attachment['element']) { case 'profile': $photoIds = $attachment['id']; //use User Preference for Privacy //$privacy = $userparams->get('privacyPhotoView'); //$privacy = $attachment['privacy']; $photo = JTable::getInstance('Photo', 'CTable'); if (!isset($photoIds[0]) || $photoIds[0] <= 0) { //$objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption)); exit; } //always get album id from the photo itself, do not let it assign by params from user post data $photoModel = CFactory::getModel('photos'); $photo = $photoModel->getPhoto($photoIds[0]); /* OK ! If album_id is not provided than we use album id from photo ( it should be default album id ) */ $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid; $album = JTable::getInstance('Album', 'CTable'); $album->load($albumid); $privacy = $album->permissions; //limit checking // $photoModel = CFactory::getModel( 'photos' ); // $config = CFactory::getConfig(); // $total = $photoModel->getTotalToday( $my->id ); // $max = $config->getInt( 'limit_photo_perday' ); // $remainingUploadCount = $max - $total; $params = array(); foreach ($photoIds as $key => $photoId) { if (CLimitsLibrary::exceedDaily('photos')) { unset($photoIds[$key]); continue; } $photo->load($photoId); $photo->permissions = $privacy; $photo->published = 1; $photo->status = 'ready'; $photo->albumid = $albumid; /* We must update this photo into correct album id */ $photo->store(); $params[] = clone $photo; } if ($config->get('autoalbumcover') && !$album->photoid) { $album->photoid = $photoIds[0]; $album->store(); } // Break if no photo added, which is likely because of daily limit. if (count($photoIds) < 1) { $objResponse->addScriptCall('__throwError', JText::_('COM_COMMUNITY_PHOTO_UPLOAD_LIMIT_EXCEEDED')); return $objResponse->sendResponse(); } // Trigger onPhotoCreate // $apps = CAppPlugins::getInstance(); $apps->loadApplications(); $apps->triggerEvent('onPhotoCreate', array($params)); $act = new stdClass(); $act->cmd = 'photo.upload'; $act->actor = $my->id; $act->access = $privacy; //$attachment['privacy']; $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target']; $act->title = $message; $act->content = ''; // Generated automatically by stream. No need to add anything $act->app = 'photos'; $act->cid = $albumid; $act->location = $album->location; /* Comment and like for individual photo upload is linked * to the photos itsel */ $act->comment_id = $photo->id; $act->comment_type = 'photos'; $act->like_id = $photo->id; $act->like_type = 'photo'; $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id; $albumUrl = CRoute::_($albumUrl); $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id; $photoUrl = CRoute::_($photoUrl); $params = new CParameter(''); $params->set('multiUrl', $albumUrl); $params->set('photoid', $photo->id); $params->set('action', 'upload'); $params->set('stream', '1'); $params->set('photo_url', $photoUrl); $params->set('style', COMMUNITY_STREAM_STYLE); $params->set('photosId', implode(',', $photoIds)); if (count($photoIds > 1)) { $params->set('count', count($photoIds)); $params->set('batchcount', count($photoIds)); } //Store mood in param if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $params->set('mood', $attachment['mood']); } // Add activity logging // CActivityStream::remove($act->app, $act->cid); $activityData = CActivityStream::add($act, $params->toString()); // Add user points CUserPoints::assignPoint('photo.upload'); //add a notification to the target user if someone posted photos on target's profile if ($my->id != $attachment['target']) { $recipient = CFactory::getUser($attachment['target']); $params = new CParameter(''); $params->set('actorName', $my->getDisplayName()); $params->set('recipientName', $recipient->getDisplayName()); $params->set('url', CUrlHelper::userLink($act->target, false)); $params->set('message', $message); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id)); CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::sprintf('COM_COMMUNITY_NOTIFICATION_STREAM_PHOTO_POST', count($photoIds)), '', 'wall.post', $params); } //email and add notification if user are tagged CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment')); $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption)); break; case 'events': $event = JTable::getInstance('Event', 'CTable'); $event->load($attachment['target']); $privacy = 0; //if this is a group event, we need to follow the group privacy if ($event->type == 'group' && $event->contentid) { $group = JTable::getInstance('Group', 'CTable'); $group->load(${$event}->contentid); $privacy = $group->approvals ? PRIVACY_GROUP_PRIVATE_ITEM : 0; } $photoIds = $attachment['id']; $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoIds[0]); $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid; $album = JTable::getInstance('Album', 'CTable'); $album->load($albumid); $params = array(); foreach ($photoIds as $photoId) { $photo->load($photoId); $photo->caption = $message; $photo->permissions = $privacy; $photo->published = 1; $photo->status = 'ready'; $photo->albumid = $albumid; $photo->store(); $params[] = clone $photo; } // Trigger onPhotoCreate // $apps = CAppPlugins::getInstance(); $apps->loadApplications(); $apps->triggerEvent('onPhotoCreate', array($params)); $act = new stdClass(); $act->cmd = 'photo.upload'; $act->actor = $my->id; $act->access = $privacy; $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target']; $act->title = $message; //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name ); $act->content = ''; // Generated automatically by stream. No need to add anything $act->app = 'photos'; $act->cid = $album->id; $act->location = $album->location; $act->eventid = $event->id; $act->group_access = $privacy; // just in case this event belongs to a group //$act->access = $attachment['privacy']; /* Comment and like for individual photo upload is linked * to the photos itsel */ $act->comment_id = $photo->id; $act->comment_type = 'photos'; $act->like_id = $photo->id; $act->like_type = 'photo'; $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id; $albumUrl = CRoute::_($albumUrl); $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id; $photoUrl = CRoute::_($photoUrl); $params = new CParameter(''); $params->set('multiUrl', $albumUrl); $params->set('photoid', $photo->id); $params->set('action', 'upload'); $params->set('stream', '1'); // this photo uploaded from status stream $params->set('photo_url', $photoUrl); $params->set('style', COMMUNITY_STREAM_STYLE); // set stream style $params->set('photosId', implode(',', $photoIds)); // Add activity logging if (count($photoIds > 1)) { $params->set('count', count($photoIds)); $params->set('batchcount', count($photoIds)); } //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $params->set('mood', $attachment['mood']); } // CActivityStream::remove($act->app, $act->cid); $activityData = CActivityStream::add($act, $params->toString()); // Add user points CUserPoints::assignPoint('photo.upload'); // Reload the stream with new stream data $eventLib = new CEvents(); $event = JTable::getInstance('Event', 'CTable'); $event->load($attachment['target']); $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true)); $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption)); break; case 'groups': // $groupLib = new CGroups(); $group = JTable::getInstance('Group', 'CTable'); $group->load($attachment['target']); $photoIds = $attachment['id']; $privacy = $group->approvals ? PRIVACY_GROUP_PRIVATE_ITEM : 0; $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoIds[0]); $albumid = isset($attachment['album_id']) ? $attachment['album_id'] : $photo->albumid; $album = JTable::getInstance('Album', 'CTable'); $album->load($albumid); $params = array(); foreach ($photoIds as $photoId) { $photo->load($photoId); $photo->caption = $message; $photo->permissions = $privacy; $photo->published = 1; $photo->status = 'ready'; $photo->albumid = $albumid; $photo->store(); $params[] = clone $photo; } // Trigger onPhotoCreate // $apps = CAppPlugins::getInstance(); $apps->loadApplications(); $apps->triggerEvent('onPhotoCreate', array($params)); $act = new stdClass(); $act->cmd = 'photo.upload'; $act->actor = $my->id; $act->access = $privacy; $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target']; $act->title = $message; //JText::sprintf('COM_COMMUNITY_ACTIVITIES_UPLOAD_PHOTO' , '{photo_url}', $album->name ); $act->content = ''; // Generated automatically by stream. No need to add anything $act->app = 'photos'; $act->cid = $album->id; $act->location = $album->location; $act->groupid = $group->id; $act->group_access = $group->approvals; $act->eventid = 0; //$act->access = $attachment['privacy']; /* Comment and like for individual photo upload is linked * to the photos itsel */ $act->comment_id = $photo->id; $act->comment_type = 'photos'; $act->like_id = $photo->id; $act->like_type = 'photo'; $albumUrl = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $my->id; $albumUrl = CRoute::_($albumUrl); $photoUrl = 'index.php?option=com_community&view=photos&task=photo&albumid=' . $album->id . '&userid=' . $photo->creator . '&photoid=' . $photo->id; $photoUrl = CRoute::_($photoUrl); $params = new CParameter(''); $params->set('multiUrl', $albumUrl); $params->set('photoid', $photo->id); $params->set('action', 'upload'); $params->set('stream', '1'); // this photo uploaded from status stream $params->set('photo_url', $photoUrl); $params->set('style', COMMUNITY_STREAM_STYLE); // set stream style $params->set('photosId', implode(',', $photoIds)); // Add activity logging if (count($photoIds > 1)) { $params->set('count', count($photoIds)); $params->set('batchcount', count($photoIds)); } //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $params->set('mood', $attachment['mood']); } // CActivityStream::remove($act->app, $act->cid); $activityData = CActivityStream::add($act, $params->toString()); // Add user points CUserPoints::assignPoint('photo.upload'); // Reload the stream with new stream data $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true)); $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_PHOTO_UPLOADED_SUCCESSFULLY', $photo->caption)); break; dafault: return; } break; case 'video': switch ($attachment['element']) { case 'profile': // attachment id $fetch = $attachment['fetch']; $cid = $fetch[0]; $privacy = isset($attachment['privacy']) ? $attachment['privacy'] : COMMUNITY_STATUS_PRIVACY_PUBLIC; $video = JTable::getInstance('Video', 'CTable'); $video->load($cid); $video->set('creator_type', VIDEO_USER_TYPE); $video->set('status', 'ready'); $video->set('permissions', $privacy); $video->set('title', $fetch[3]); $video->set('description', $fetch[4]); $video->set('category_id', $fetch[5]); /* Save cords if exists */ if (isset($attachment['location'])) { $video->set('location', $attachment['location'][0]); $video->set('latitude', $attachment['location'][1]); $video->set('longitude', $attachment['location'][2]); } // Add activity logging $url = $video->getViewUri(false); $act = new stdClass(); $act->cmd = 'videos.linking'; $act->actor = $my->id; $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target']; $act->access = $privacy; //filter empty message $act->title = $message; $act->app = 'videos.linking'; $act->content = ''; $act->cid = $video->id; $act->location = $video->location; /* Save cords if exists */ if (isset($attachment['location'])) { /* Save geo name */ $act->location = $attachment['location'][0]; $act->latitude = $attachment['location'][1]; $act->longitude = $attachment['location'][2]; } $act->comment_id = $video->id; $act->comment_type = 'videos.linking'; $act->like_id = $video->id; $act->like_type = 'videos.linking'; $params = new CParameter(''); $params->set('video_url', $url); $params->set('style', COMMUNITY_STREAM_STYLE); // set stream style //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $params->set('mood', $attachment['mood']); } // $activityData = CActivityStream::add($act, $params->toString()); //this video must be public because it's posted on someone else's profile if ($my->id != $attachment['target']) { $video->set('permissions', COMMUNITY_STATUS_PRIVACY_PUBLIC); $params = new CParameter(); $params->set('activity_id', $activityData->id); // activity id is used to remove the activity if someone deleted this video $params->set('target_id', $attachment['target']); $video->params = $params->toString(); //also send a notification to the user $recipient = CFactory::getUser($attachment['target']); $params = new CParameter(''); $params->set('actorName', $my->getDisplayName()); $params->set('recipientName', $recipient->getDisplayName()); $params->set('url', CUrlHelper::userLink($act->target, false)); $params->set('message', $message); $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM')); $params->set('stream_url', CRoute::_('index.php?option=com_community&view=profile&userid=' . $activityData->actor . '&actid=' . $activityData->id)); CNotificationLibrary::add('profile_status_update', $my->id, $attachment['target'], JText::_('COM_COMMUNITY_NOTIFICATION_STREAM_VIDEO_POST'), '', 'wall.post', $params); } $video->store(); // @rule: Add point when user adds a new video link // CUserPoints::assignPoint('video.add', $video->creator); //email and add notification if user are tagged CUserHelper::parseTaggedUserNotification($message, $my, $activityData, array('type' => 'post-comment')); // Trigger for onVideoCreate // $apps = CAppPlugins::getInstance(); $apps->loadApplications(); $params = array(); $params[] = $video; $apps->triggerEvent('onVideoCreate', $params); $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title)); break; case 'groups': // attachment id $fetch = $attachment['fetch']; $cid = $fetch[0]; $privacy = 0; //$attachment['privacy']; $video = JTable::getInstance('Video', 'CTable'); $video->load($cid); $video->set('status', 'ready'); $video->set('groupid', $attachment['target']); $video->set('permissions', $privacy); $video->set('creator_type', VIDEO_GROUP_TYPE); $video->set('title', $fetch[3]); $video->set('description', $fetch[4]); $video->set('category_id', $fetch[5]); /* Save cords if exists */ if (isset($attachment['location'])) { $video->set('location', $attachment['location'][0]); $video->set('latitude', $attachment['location'][1]); $video->set('longitude', $attachment['location'][2]); } $video->store(); // $groupLib = new CGroups(); $group = JTable::getInstance('Group', 'CTable'); $group->load($attachment['target']); // Add activity logging $url = $video->getViewUri(false); $act = new stdClass(); $act->cmd = 'videos.linking'; $act->actor = $my->id; $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target']; $act->access = $privacy; //filter empty message $act->title = $message; $act->app = 'videos'; $act->content = ''; $act->cid = $video->id; $act->groupid = $video->groupid; $act->group_access = $group->approvals; $act->location = $video->location; /* Save cords if exists */ if (isset($attachment['location'])) { /* Save geo name */ $act->location = $attachment['location'][0]; $act->latitude = $attachment['location'][1]; $act->longitude = $attachment['location'][2]; } $act->comment_id = $video->id; $act->comment_type = 'videos'; $act->like_id = $video->id; $act->like_type = 'videos'; $params = new CParameter(''); $params->set('video_url', $url); $params->set('style', COMMUNITY_STREAM_STYLE); // set stream style //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $params->set('mood', $attachment['mood']); } $activityData = CActivityStream::add($act, $params->toString()); // @rule: Add point when user adds a new video link CUserPoints::assignPoint('video.add', $video->creator); // Trigger for onVideoCreate $apps = CAppPlugins::getInstance(); $apps->loadApplications(); $params = array(); $params[] = $video; $apps->triggerEvent('onVideoCreate', $params); $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title)); // Reload the stream with new stream data $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true)); break; case 'events': //event videos $fetch = $attachment['fetch']; $cid = $fetch[0]; $privacy = 0; //$attachment['privacy']; $video = JTable::getInstance('Video', 'CTable'); $video->load($cid); $video->set('status', 'ready'); $video->set('eventid', $attachment['target']); $video->set('permissions', $privacy); $video->set('creator_type', VIDEO_EVENT_TYPE); $video->set('title', $fetch[3]); $video->set('description', $fetch[4]); $video->set('category_id', $fetch[5]); /* Save cords if exists */ if (isset($attachment['location'])) { $video->set('location', $attachment['location'][0]); $video->set('latitude', $attachment['location'][1]); $video->set('longitude', $attachment['location'][2]); } $video->store(); // $eventLib = new CEvents(); $event = JTable::getInstance('Event', 'CTable'); $event->load($attachment['target']); $group = new stdClass(); if ($event->type == 'group' && $event->contentid) { // check if this a group event, and follow the permission $group = JTable::getInstance('Group', 'CTable'); $group->load($event->contentid); } // Add activity logging $url = $video->getViewUri(false); $act = new stdClass(); $act->cmd = 'videos.linking'; $act->actor = $my->id; $act->target = $attachment['target'] == $my->id ? 0 : $attachment['target']; $act->access = $privacy; //filter empty message $act->title = $message; $act->app = 'videos'; $act->content = ''; $act->cid = $video->id; $act->groupid = 0; $act->group_access = isset($group->approvals) ? $group->approvals : 0; // if this is a group event $act->location = $video->location; /* Save cords if exists */ if (isset($attachment['location'])) { /* Save geo name */ $act->location = $attachment['location'][0]; $act->latitude = $attachment['location'][1]; $act->longitude = $attachment['location'][2]; } $act->eventid = $event->id; $act->comment_id = $video->id; $act->comment_type = 'videos'; $act->like_id = $video->id; $act->like_type = 'videos'; $params = new CParameter(''); $params->set('video_url', $url); $params->set('style', COMMUNITY_STREAM_STYLE); // set stream style //Store mood in paramm if (isset($attachment['mood']) && $attachment['mood'] != 'Mood') { $params->set('mood', $attachment['mood']); } $activityData = CActivityStream::add($act, $params->toString()); // @rule: Add point when user adds a new video link CUserPoints::assignPoint('video.add', $video->creator); // Trigger for onVideoCreate $apps = CAppPlugins::getInstance(); $apps->loadApplications(); $params = array(); $params[] = $video; $apps->triggerEvent('onVideoCreate', $params); $this->cacheClean(array(COMMUNITY_CACHE_TAG_VIDEOS, COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_VIDEOS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); $objResponse->addScriptCall('__callback', JText::sprintf('COM_COMMUNITY_VIDEOS_UPLOAD_SUCCESS', $video->title)); // Reload the stream with new stream data $streamHTML = $eventLib->getStreamHTML($event, array('showLatestActivityOnTop' => true)); break; default: return; } break; case 'event': switch ($attachment['element']) { case 'profile': require_once COMMUNITY_COM_PATH . '/controllers/events.php'; $eventController = new CommunityEventsController(); // Assign default values where necessary $attachment['description'] = $message; $attachment['ticket'] = 0; $attachment['offset'] = 0; $event = $eventController->ajaxCreate($attachment, $objResponse); $objResponse->addScriptCall('window.location="' . $event->getLink() . '";'); if (CFactory::getConfig()->get('event_moderation')) { $objResponse->addAlert(JText::sprintf('COM_COMMUNITY_EVENTS_MODERATION_NOTICE', $event->title)); } break; case 'groups': require_once COMMUNITY_COM_PATH . '/controllers/events.php'; $eventController = new CommunityEventsController(); // $groupLib = new CGroups(); $group = JTable::getInstance('Group', 'CTable'); $group->load($attachment['target']); // Assign default values where necessary $attachment['description'] = $message; $attachment['ticket'] = 0; $attachment['offset'] = 0; $event = $eventController->ajaxCreate($attachment, $objResponse); CEvents::addGroupNotification($event); $objResponse->addScriptCall('window.location="' . $event->getLink() . '";'); // Reload the stream with new stream data $streamHTML = $groupLib->getStreamHTML($group, array('showLatestActivityOnTop' => true)); if (CFactory::getConfig()->get('event_moderation')) { $objResponse->addAlert(JText::sprintf('COM_COMMUNITY_EVENTS_MODERATION_NOTICE', $event->title)); } break; } break; case 'link': break; } //no matter what kind of message it is, always filter the hashtag if there's any if (!empty($act->title) && isset($activityData->id) && $activityData->id) { //use model to check if this has a tag in it and insert into the table if possible $hashtags = CContentHelper::getHashTags($act->title); if (count($hashtags)) { //$hashTag $hashtagModel = CFactory::getModel('hashtags'); foreach ($hashtags as $tag) { $hashtagModel->addActivityHashtag($tag, $activityData->id); } } } // Frontpage filter if ($streamFilter != false) { $streamFilter = json_decode($streamFilter); $filter = $streamFilter->filter; $value = $streamFilter->value; $extra = false; // Append added data to the list. if (isset($activityData) && $activityData->id) { $model = CFactory::getModel('Activities'); $extra = $model->getActivity($activityData->id); } switch ($filter) { case 'privacy': if ($value == 'me-and-friends' && $my->id != 0) { $streamHTML = CActivities::getActivitiesByFilter('active-user-and-friends', $my->id, 'frontpage', true, array(), $extra); } else { $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array(), $extra); } break; case 'apps': $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array('apps' => array($value)), $extra); break; case 'hashtag': $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array($filter => $value), $extra); break; default: $defaultFilter = $config->get('frontpageactivitydefault'); if ($defaultFilter == 'friends' && $my->id != 0) { $streamHTML = CActivities::getActivitiesByFilter('active-user-and-friends', $my->id, 'frontpage', true, array(), $extra); } else { $streamHTML = CActivities::getActivitiesByFilter('all', $my->id, 'frontpage', true, array(), $extra); } break; } } if (!isset($attachment['filter'])) { $attachment['filter'] = ''; $filter = $config->get('frontpageactivitydefault'); $filter = explode(':', $filter); $attachment['filter'] = isset($filter[1]) ? $filter[1] : $filter[0]; } if (empty($streamHTML)) { if (!isset($attachment['target'])) { $attachment['target'] = ''; } if (!isset($attachment['element'])) { $attachment['element'] = ''; } $streamHTML = CActivities::getActivitiesByFilter($attachment['filter'], $attachment['target'], $attachment['element'], true, array('show_featured' => true, 'showLatestActivityOnTop' => true)); } $objResponse->addAssign('activity-stream-container', 'innerHTML', $streamHTML); // Log user engagement CEngagement::log($attachment['type'] . '.share', $my->id); return $objResponse->sendResponse(); }
public function ajaxSaveStatus($actId, $value) { $my = CFactory::getUser(); $json = array(); if ($my->id == 0) { $this->ajaxBlockUnregister(); } $filter = JFilterInput::getInstance(); $actId = $filter->clean($actId, 'int'); $value = trim($value); $activity = JTable::getInstance('Activity', 'CTable'); $activity->load($actId); if (empty($value)) { $json['error'] = JText::_('COM_COMMUNITY_CANNOT_EDIT_POST_ERROR'); die(json_encode($json)); } else { //before storing, check if there is any hashtag, if yes, remove the hash tag before adding a new one $hashtags = CContentHelper::getHashTags($value); // check current title or message has any hashtag $oldHashtags = CContentHelper::getHashTags($activity->title); //old hashtag from the prebious message or title if there is any $removeTags = array_diff($oldHashtags, $hashtags); // this are the tags need to be removed $addTags = array_diff($hashtags, $oldHashtags); // tags that need to be added // remove tags if there's any if (count($removeTags)) { $hashtagModel = CFactory::getModel('hashtags'); foreach ($removeTags as $tag) { $hashtagModel->removeActivityHashtag($tag, $activity->id); } } // add new tags if there's any if (count($addTags)) { $hashtagModel = CFactory::getModel('hashtags'); foreach ($addTags as $tag) { $hashtagModel->addActivityHashtag($tag, $activity->id); } } $activity->title = $value; $activity->store(); $status = $this->getModel('status'); $status->update($my->id, $value, $activity->access); $today = JFactory::getDate(); $my->set('_status', $value); $my->set('_posted_on', $today->toSql()); } $params = new CParameter($activity->params); $mood = $params->get('mood', null); $value = CActivities::format($activity->title, $mood); $json['success'] = true; $json['data'] = $value; $json['unparsed'] = $activity->title; die(json_encode($json)); }
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)); }
?> " /> </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);
/** * 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(); }
/** * 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(); } }
/** * Add new activity, * @access static * */ public static function add($activity, $params = '', $points = 1) { CError::assert($activity, '', '!empty', __FILE__, __LINE__); $cmd = !empty($activity->cmd) ? $activity->cmd : ''; if (!empty($cmd)) { $userPointModel = CFactory::getModel('Userpoints'); $point = $userPointModel->getPointData($cmd); //no reason to disable activity if no points is given if ($point) { if (!$point->published) { return; } } } // If params is an object, instead of a string, we convert it to string $cmd = !empty($activity->cmd) ? $activity->cmd : ''; $actor = !empty($activity->actor) ? $activity->actor : ''; $actors = !empty($activity->actors) ? $activity->actors : ''; $target = !empty($activity->target) ? $activity->target : 0; $title = !empty($activity->title) ? $activity->title : ''; $content = !empty($activity->content) ? $activity->content : ''; $appname = !empty($activity->app) ? $activity->app : ''; $cid = !empty($activity->cid) ? $activity->cid : 0; $groupid = !empty($activity->groupid) ? $activity->groupid : 0; $group_access = !empty($activity->group_access) ? $activity->group_access : 0; $event_access = !empty($activity->event_access) ? $activity->event_access : 0; $eventid = !empty($activity->eventid) ? $activity->eventid : 0; $points = !empty($activity->points) ? $activity->points : $points; $access = !empty($activity->access) ? $activity->access : 0; $location = !empty($activity->location) ? $activity->location : ''; $comment_id = !empty($activity->comment_id) ? $activity->comment_id : 0; $comment_type = !empty($activity->comment_type) ? $activity->comment_type : ''; $like_id = !empty($activity->like_id) ? $activity->like_id : 0; $like_type = !empty($activity->like_type) ? $activity->like_type : ''; $latitude = !empty($activity->latitude) ? $activity->latitude : null; $longitude = !empty($activity->longitude) ? $activity->longitude : null; // If the params in embedded within the activity object, use it // if it is not explicitly overriden if (empty($params) && !empty($activity->params)) { $params = $activity->params; } // Update access for activity based on the user's profile privacy // since 2.4.2 if access is provided, dont use the default if (!empty($actor) && $actor != 0 && !isset($access)) { $user = CFactory::getUser($actor); $userParams = $user->getParams(); $profileAccess = $userParams->get('privacyProfileView'); // Only overwrite access if the user global profile privacy is higher // BUT, if access is defined as PRIVACY_FORCE_PUBLIC, do not modify it if ($access != PRIVACY_FORCE_PUBLIC && $profileAccess > $access) { $access = $profileAccess; } } $table = JTable::getInstance('Activity', 'CTable'); //before adding we must aggregate the videos/album/photo comments $aggregateApps = array('videos.comment', 'albums.comment', 'photos.comment'); if (in_array($appname, $aggregateApps)) { //we need to check if this activity exists $filter = array('app' => $appname, 'cid' => $cid); $activitiesModel = CFactory::getModel('activities'); $activityId = $activitiesModel->getActivityId($filter); if ($activityId) { $table->load($activityId); $passedParams = new JRegistry($params); // update wall id if needed $wallid = $passedParams->get('wallid'); $params = new JRegistry($table->params); $params->set('wallid', $wallid); $act = $params->get('actors'); if (!is_array($act)) { $params->set('actors', array($actor)); } else { array_unshift($act, $actor); $act = array_unique($act); // latest user must be on the first $params->set('actors', $act); } $table->created = JFactory::getDate()->toSql(); $table->params = $params->toString(); $table->store(); return $table; } else { //if this is the first creation $params = new JRegistry($params); $params->set('actors', array($actor)); $params = $params->toString(); } } $table->actor = $actor; $table->actors = $actors; $table->target = $target; $table->title = $title; $table->content = $content; $table->app = $appname; $table->cid = $cid; $table->groupid = $groupid; $table->group_access = $group_access; $table->eventid = $eventid; $table->event_access = $event_access; $table->points = $points; $table->access = $access; $table->location = $location; $table->params = $params; $table->comment_id = $comment_id; $table->comment_type = $comment_type; $table->like_id = $like_id; $table->like_type = $like_type; $table->latitude = $latitude; $table->longitude = $longitude; $table->store(); //no matter what kind of message it is, always filter the hashtag if there's any if (!empty($table->title) && isset($table->id)) { //use model to check if this has a tag in it and insert into the table if possible $hashtags = CContentHelper::getHashTags($table->title); if (count($hashtags)) { //$hashTag $hashtagModel = CFactory::getModel('hashtags'); foreach ($hashtags as $tag) { $hashtagModel->addActivityHashtag($tag, $table->id); } } } // Update comment id, if we comment on the stream itself if ($comment_id == CActivities::COMMENT_SELF) { $table->comment_id = $table->id; } // Update comment id, if we like on the stream itself if ($like_id == CActivities::LIKE_SELF) { $table->like_id = $table->id; } if ($comment_id == CActivities::COMMENT_SELF || $like_id == CActivities::LIKE_SELF) { $table->store($table); } return $table; }