Keyword

Contentplugins running om catItemVideoBlock

  • Ruud van Lent
  • Ruud van Lent's Avatar Topic Author
  • Offline
  • New Member
More
7 years 11 months ago #158403 by Ruud van Lent
Contentplugins running om catItemVideoBlock was created by Ruud van Lent
Hi,

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 11 months ago #158407 by Krikor Boghossian
Replied by Krikor Boghossian on topic Contentplugins running om catItemVideoBlock
Hello,

On which K2 event is your plugin being fired?

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Ruud van Lent
  • Ruud van Lent's Avatar Topic Author
  • Offline
  • New Member
More
7 years 11 months ago - 7 years 11 months ago #158408 by Ruud van Lent
Replied by Ruud van Lent on topic Contentplugins running om catItemVideoBlock
It's not, it is fired via
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
Last edit: 7 years 11 months ago by Ruud van Lent. Reason: added debug info

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 11 months ago #158412 by Krikor Boghossian
Replied by Krikor Boghossian on topic Contentplugins running om catItemVideoBlock
I would suggest based on the option (com_k2) firing the plugin in a designated K2 plugin event so that you can control over the layout.

This will help you a lot.
getk2.org/extend/extensions/90-example-k2-plugin-for-developers

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Ruud van Lent
  • Ruud van Lent's Avatar Topic Author
  • Offline
  • New Member
More
7 years 11 months ago #158415 by Ruud van Lent
Replied by Ruud van Lent on topic Contentplugins running om catItemVideoBlock
Thanks Krikor,

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
  • Ruud van Lent's Avatar Topic Author
  • Offline
  • New Member
More
7 years 11 months ago #158421 by Ruud van Lent
Replied by Ruud van Lent on topic Contentplugins running om catItemVideoBlock
@krikor,

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
  • Ruud van Lent's Avatar Topic Author
  • Offline
  • New Member
More
7 years 11 months ago #158437 by Ruud van Lent
Replied by Ruud van Lent on topic Contentplugins running om catItemVideoBlock
Hi, finally managed to get this working :)

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
7 years 11 months ago #158439 by Krikor Boghossian
Replied by Krikor Boghossian on topic Contentplugins running om catItemVideoBlock
Yes it is an improvement.
Can you send me a link to the extension? Github would be great as well.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Ruud van Lent
  • Ruud van Lent's Avatar Topic Author
  • Offline
  • New Member
More
7 years 11 months ago #158440 by Ruud van Lent
Replied by Ruud van Lent on topic Contentplugins running om catItemVideoBlock
Hi, I will do a PR on github although my last PR (github.com/getk2/k2/pull/311) is still open and growing a beard :)
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
  • Ruud van Lent's Avatar Topic Author
  • Offline
  • New Member
More
7 years 11 months ago #158441 by Ruud van Lent
Replied by Ruud van Lent on topic Contentplugins running om catItemVideoBlock

Sharing = Caring

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum