0

I am using k2 to buildg my Joomla 3.5 site. My k2 items are basically youtube videos, every youtube video has a URL pattern for its preview image and I want it to be the item's image. But I don't want to bother with the repetitive job (copying the video ID, fitting it into the URL, and saving it as the item's image) every time I create an item. So I am thinking maybe I can write some script to automatically get the images(it is easy to do once the video's id is provided). The problem is, this script has to be exectued every time I create an item.

I just start to learn some basic things about Joomla extension developing, my question is, which category does the thing I want to fall into? Shall it be a plugin? Or a k2 plugin? Or there is totally no interface for this kind of thing and I will have to hack some PHP file?

Furthermore, I also have some node.js script to scrape the description of the Youtube videos(Yes I am being lazy again, I don't want to copy and paste those descriptions every time I create an item). How do I get Joomla to run these node.js scripts?

2

You need a K2 plugin if you are not yet using K2 V3, otherwise a regular Joomla plugin, if I remember correctly.

Basic sceleton for what you need would be something like

<?php
defined('_JEXEC') or die ('Restricted access');

JLoader::register('K2Plugin', JPATH_ADMINISTRATOR . '/components/com_k2/lib/k2plugin.php');
JLoader::register('K2HelperUtilities', JPATH_COMPONENT . '/helpers/utilities.php');
JLoader::register('K2ModelItemlist', JPATH_COMPONENT . '/models/itemlist.php');
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');

class plgK2Myplugin extends K2Plugin {

   //params needed for K2
   public $pluginName = 'myplugin';
   public $pluginNameHumanReadable = 'My plugin';

   public function __construct(&$subject, $params) {
      parent::__construct($subject, $params);
   }

   public function onAfterK2Save(&$item, $isNew) 
   {
       // this is where your logic goes
   }
}

Then you can edit the $item variable and change the image variable to what you want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.