/** * Inserts activity stream for JomSocial * * @since 5.0 * @access public * @param EasyBlogTableBlog * @return */ public function insertActivity(EasyBlogPost $post, $command = '', $content = '') { // Determine which command to use for this stream if (empty($command)) { $command = $post->isNew() ? 'easyblog.blog.add' : 'easyblog.blog.update'; } // Check if Jomsocial exists if (!$this->exists()) { return false; } // If this is a feed source and the settings doesn't allow this, skip this if ($command == 'easyblog.blog.add' && $post->isNew() && $post->isFromFeed() && !$this->config->get('integrations_jomsocial_rss_import_activity')) { return false; } // Ensure that the configuration allows user to publish new feed if ($command == 'easyblog.blog.add' && $post->isNew() && !$this->config->get('integrations_jomsocial_blog_new_activity')) { return false; } // Ensure that the configuration allows user to publish new feed when blog is updated if ($command == 'easyblog.blog.update' && !$post->isNew() && !$this->config->get('integrations_jomsocial_blog_update_activity')) { return false; } // Determine the post title $title = $this->getPostTitle($post); // Get the category the post is associated to $category = $post->getPrimaryCategory(); $categoryLink = $category->getExternalPermalink(); // Get the permalink of the blog post $permalink = $post->getExternalPermalink(); // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls. if ($this->app->isAdmin() && EB::router()->isSh404Enabled()) { $itemId = EBR::getItemId('latest'); $itemId = '&Itemid=' . $itemId; $permalink = rtrim(JURI::root(), '/') . '/index.php?option=com_easyblog&view=entry&id=' . $post->id . $itemId; $categoryLink = rtrim(JURI::root(), '/') . '/index.php?option=com_easyblog&view=categories&layout=listings&id=' . $category->id . $itemId; } // If there is no content provided, we assume that the user wants to use the blog post if (!$content) { $content = $this->prepareBlogContent($post, $permalink); } // Prepare the title of the post $streamTitle = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_BLOG_ADDED_NON_CATEGORY', $permalink, $title); // If this is not a new post, we need to use a different title if (!$post->isNew() && $command == 'easyblog.blog.update') { $streamTitle = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_BLOG_UPDATED_NON_CATEGORY', $permalink, $title); } // Determines which stream title to use if ($this->config->get('integrations_jomsocial_show_category') && $post->isNew() && $command == 'easyblog.blog.add') { $streamTitle = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_BLOG_ADDED', $permalink, $title, $categoryLink, JText::_($category->title)); } if (!$post->isNew() && $command == 'easyblog.blog.update') { $streamTitle = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_BLOG_UPDATED', $permalink, $title, $categoryLink, JText::_($category->title)); } // Featuring of a blog post if ($command == 'easyblog.blog.featured') { $streamTitle = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_BLOG_FEATURED', $permalink, $title); } // Insert the object into the stream now $obj = new stdClass(); $obj->access = $post->access; $obj->title = $streamTitle; $obj->content = $content; $obj->cmd = $command; // Should we enable likes if ($this->config->get('integrations_jomsocial_activity_likes')) { $obj->like_id = $post->id; $obj->like_type = 'com_easyblog'; } // Should we link the comments if ($this->config->get('integrations_jomsocial_activity_comments')) { $obj->comment_id = $post->id; $obj->comment_type = 'com_easyblog'; } $obj->actor = $post->created_by; $obj->target = 0; $obj->app = 'easyblog'; $obj->cid = $post->id; // If this post is contributed in an event or a group, update it accordingly. if ($post->getBlogContribution()) { // Get the event object // $contribution = $post->getBlogContribution(); // Event type if ($post->source_type == EASYBLOG_POST_SOURCE_JOMSOCIAL_EVENT) { JTable::addIncludePath(JPATH_ROOT . '/components/com_community/tables'); // Load the event $event = JTable::getInstance('Event', 'CTable'); $event->load($post->source_id); // Set the stream title $eventLink = CRoute::_('index.php?option=com_community&view=events&task=viewevent&eventid=' . $event->id); $obj->title = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_EVENT_BLOG_ADDED', $permalink, $title, $eventLink, $event->title); // Set a new command $obj->cmd = 'event.blog.added'; $obj->target = $event->id; $obj->cid = $event->id; $obj->eventid = $event->id; } // Group type if ($post->source_type == EASYBLOG_POST_SOURCE_JOMSOCIAL_GROUP) { JTable::addIncludePath(JPATH_ROOT . '/components/com_community/tables'); // Load the group $group = JTable::getInstance('Group', 'CTable'); $group->load($post->source_id); // Set the stream title $groupLink = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $group->id); $obj->title = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_GROUP_BLOG_ADDED', $permalink, $title, $groupLink, $group->name); $obj->group_access = $group->approvals; $obj->target = $group->id; $obj->cid = $group->id; $obj->groupid = $group->id; $obj->cmd = 'group.blog.added'; } } // Ensure that the likes and comment uses the correct type if (!$post->isNew()) { $obj->like_type = 'com_easyblog.update'; $obj->comment_type = 'com_easyblog.update'; } // Insert into jomsocial now CFactory::load('libraries', 'activities'); CActivityStream::add($obj); }