COMMUNITY FORUM
Contentplugins running om catItemVideoBlock
- Ruud van Lent
-
Topic Author
- Offline
- New Member
I am maintaining a content plugin that will add socials sharing buttons on configured position on K2 (and Joomla / Easyblog) articles.
I have a user who had strange behavior on his site.
I have been able to pinpoint it back to the routine that adds catItemVideoBlock'
What my plugin does:
When component = com_k2 and view is item / itemlist / latest
the plugin will add the code for the soical sharing buttons on the configured position: top / bottom / readmore.
So far so good.
But what appears to be happening is that content plugins are also run on Media box (in this case the CatItemVideoBlock that is utilized by (e.g.) AllVideos, this routine identifies itself to the Joomla content plugins as component com_k2, view item (or itemlist / latest) > thus adding the social sharing buttons a second time! Even if no video is configured for the item, the plugin is run and an empty box (with social sharing buttons) is shown on the view.
Is there a way to differentiate between the media box running the content plugin and the actual com_k2 / item/itemlist/latest?
How can I learn my plugin that it is not com_k2 / item calling the routine but the mediabox?
imgur.com/a/TZhOb
imgur.com/a/hOzlC
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
On which K2 event is your plugin being fired?
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
public function onContentPrepare($context, &$article, &$params, $page = 0)
because $content is not a good guarantee of what component is triggering I read the component and view via:
$component = $app->input->get('option');
$view = $app->input->get('view');
this is some debug info return from with the catItemVideoBlock call:
Context: com_k2.itemlist
Component: com_k2
View: itemlist
Id: 675
Category: 317
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
This will help you a lot.
getk2.org/extend/extensions/90-example-k2-plugin-for-developers
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
this would be a 'huge' change for me: need to investigate (as this is a free plugin, time is an issue :))
The way you have implemented this now in K2 impacts the performance of the website > all (content) plugins are called and run twice: once for the media box and once for the item / itemlist / latest view.
Why is that?
When not separately running the content plugins on the media box and on contentprepare but only on the complete page (item / itemlist / latest) would have the same effect and all plugins would only run once... or am I missing something?
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
what I could do is create a K2 plugin that adds {jssocials} tag(s) on configured positions
My Joomla! plugin would then replace {jssocials} tags with the actual buttons.
This only works if the Joomla! oncontentprepare function runs AFTER the K2 onk2contentprepare function adds the tags..
Do you know if this is the case?
If not and the tags are added but not replaced (by oncontentprepare function), then I will have to abandon K2 as I do not want to recreate my complete plugins functionality into a K2 plugin (and do double maintence) :(
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
Just needed a small 'fix' in K2.
current: in .components/com_k2/models/item.php in function execPlugins($item, $view, $task)
$item->text = $item->gallery;
if (K2_JVERSION == '15')
{
$dispatcher->trigger('onPrepareContent', array(
&$item,
&$params,
$limitstart
));
}
else
{
$dispatcher->trigger('onContentPrepare', array(
'com_k2.'.$view,
&$item,
&$params,
$limitstart
));
}
$item->gallery = $item->text;
and changed that to
$item->text = $item->gallery;
if (K2_JVERSION == '15')
{
$dispatcher->trigger('onPrepareContent', array(
&$item,
&$params,
$limitstart
));
}
else
{
$dispatcher->trigger('onContentPrepare', array(
'com_k2.'.$view.'-gallery',
&$item,
&$params,
$limitstart
));
}
$item->gallery = $item->text;
The same for video where I added '-video' to the context variable
what this will do is enable (content) plugin creators to differentiate their action based on the context.
K2 triggers onContentPrepare on the article ($item) contents and does this as context 'com_k2.item' / 'com_k2.itemlist'
It also triggers onContentPrepare on video and gallery text under the same context 'com_k2.item' / 'com_k2.itemlist'
So the developer reads the context, gets e.g. 'com_k2.item' but is in fact not getting the item (blog) but the video text...
With this change, K2 still triggers onContentPrepare on the article ($item) contents and does this as context 'com_k2.item' / 'com_k2.itemlist'
But it triggers onContentPrepare on video and gallery text under the new context 'com_k2.item-video' / 'com_k2.itemlist-video'
The developer now 'knows' by reading the $context in his plugin that he is NOT receiving the item (blog) but the video string and can act accordingly
(Same for Gallery)
I have tested these changes on several test environments, but also on a production site of one of my users.
On these sites, multiple content plugins are running including the JW AllVideos plugin and JW Simple Image Gallery > everything is still working correct!
I think this is an improvement, what do you think?
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Can you send me a link to the extension? Github would be great as well.
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
No feedback / sign of life whatsoever other then from users saying it works like a charm :)
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
I merged your other PR btw.
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
What are the next steps for this last PR to get merged?
Is there something I can do to help?
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Quite possibly it will be reviewed prior to 2.7.2's release.
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
My own plugin is pending your review :)
It is dependent on how the proposed code changes will be implemented :)
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Once again thank you!
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
Looking forward to merge!
Keep up the good work guys (and girls?)
regards,
Ruud.
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Ruud van Lent
-
Topic Author
- Offline
- New Member
Looking forward to merge!
Keep up the good work guys (and girls?)
regards,
Ruud.
Sharing = Caring
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Unfortunately at this moment only guys :)
Please Log in or Create an account to join the conversation.