<?php
defined('_JEXEC') or die;
require_once(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'helpers'.DS.'route.php');
//Load language file
$lang = JFactory::getLanguage();
$lang->load('plg_content_K2_cb_activitystream', JPATH_ADMINISTRATOR);
class PlgContentK2_cb_activitystream extends JPlugin
{
protected $autoloadLanguage = true;
//Add entry in activity stream
public function onContentAfterSave($context, $article, $isNew)
{
$user = JFactory::getUser();
//In k2 component
if(JRequest::getVar('option') == JText::_('PLG_CONTENT_K2CB_COM_NAME'))
{
//If edited
if(!$isNew)
{
//Check for article category from edit category parameter
if( in_array( $article->catid, $this->params->get('edit_article') ) )
$this->pushToCBActivity($user->id,'com_k2','edit',
JText::_('PLG_CONTENT_K2CB_EDIT_ART'),
K2HelperRoute::getItemRoute($article->id, $article->catid),$article->title,
$article->id,$article->introtext,$this->params->get('char'));
}
else // If new
{
//Check for article category from add category parameter
if( in_array( $article->catid, $this->params->get('add_article') ) )
$this->pushToCBActivity($user->id,'com_k2','add',JText::_('PLG_CONTENT_K2CB_ADD_ART'),
K2HelperRoute::getItemRoute($article->id, $article->catid),$article->title,
$article->id,$article->introtext,$this->params->get('char'));
}
}//if
}
//Function to add activity in CB
function pushToCBActivity($var1,$var2,$var3,$var4)
{
//load CB framework
global $_PLUGINS;
if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) {
echo 'CB not installed'; return;
}
include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
cbimport( 'cb.html' );
cbimport( 'language.front' );
$_PLUGINS->loadPluginGroup( 'user' );
//push activity
$linkHTML = '<a href="'.$act_link.'">'.$act_title.'</a>';
//article image
$message = '<div class="coverdiv">';
//If article has image then add it to activity
if($this->getArticleImage($articleid))
{
$message .= '<div class="article-image">
<a href="'.$act_link.'">
<img src="'.$this->getArticleImage($articleid).'" width="'.$this->params->get('width').'px" /></a>
</div>';
}
//If article has introtext then add it to activity
if($introtext)
{
//remove html tag from introtext
$introtext = strip_tags($introtext);
$introtext = substr( $introtext,0,$no_of_char);
$message .= '<div class="article-text">'.$introtext.'</div>';
}
$message .= '</div>';
$title = $act_description.' '.$linkHTML;
$var1 = $article;
$var2 = $message;
$var3 = $title;
$var4 = $user->id;
$_PLUGINS->trigger( 'k2_onContentAfterSave', array($var1,$var2,$var3,$var4) );
return true;
}
//Get an image for given k2 article id
function getArticleImage($articleid)
{
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$articleid).'_XS.jpg'))
{
$article_image = JURI::root(true).'/media/k2/items/cache/'.md5("Image".$articleid).'_XS.jpg';
}
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$articleid).'_S.jpg'))
{
$article_image = JURI::root(true).'/media/k2/items/cache/'.md5("Image".$articleid).'_S.jpg';
}
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$articleid).'_M.jpg'))
{
$article_image = JURI::root(true).'/media/k2/items/cache/'.md5("Image".$articleid).'_M.jpg';
}
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$articleid).'_L.jpg'))
{
$article_image = JURI::root(true).'/media/k2/items/cache/'.md5("Image".$articleid).'_L.jpg';
}
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$articleid).'_XL.jpg'))
{
$article_image = JURI::root(true).'/media/k2/items/cache/'.md5("Image".$articleid).'_XL.jpg';
}
if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$articleid).'_Generic.jpg'))
{
$article_image = JURI::root(true).'/media/k2/items/cache/'.md5("Image".$articleid).'_Generic.jpg';
}
return $article_image;
}
}
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Only status posts can have a location, action, or tags associated with them (this is to be improved in a later release). All activity types can have Links attached. A custom link type can be used to output custom HTML. See existing System Actions for several usage examples.- if it's possible to have several actions : adding a k2 plus adding a place plus adding a url in the same activity auto action ? (I tried to add a k2 and a place name with lat,lng but it failed)
You can't substitute in language strings. You just supply the string and it'll translate as needed.- what format of substitution to use for language strings in auto actions : only _UE_XXX_STRING or [STRING]
In CB Activity as done with all other CB plugins.- where to translate the action words laughing, smiling, watching.... etc. Several strings are not in the cb plugin language file
No.- if it is possible to have a module with all activities and comments concerning an item id ?
Please Log in to join the conversation.
Please Log in to join the conversation.
No idea, shouldn't matter as long as your trigger is working and firing correctly.I have noticed that my cb activity auto action did not work if debug was off. Do you have any idea why this behavior ?
CB Activity doesn't integrate with CB Privacy at this time. You can only control access to the entire stream it self by adjusting the menu item view access level and/or the activity tab view access level.I have also noticed that CB activity main page display did not follow the privacy rules. For instance mine are set to not display activities when people are not registered but main activity page does not respect this. Bug ?
Please Log in to join the conversation.