Thanks for the explanation, I thought that I got it but cannot make it to work
I have corrected the modified php file as per your indications and left it in the k2 content plugin, then set the activity auto action like screenshots attached without any conditions.
Nothing is added and I have no error messages. Difficult to debug as a click to execute would only give [varx]
Can you help to find out what needs to be changed in all this to make it work ?
Code:
<?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;
}
}