Adding Kaltura's video as a type for "More Fields" plug-in

18 replies [Last post]
Joined: 06/16/2009
Points: 21

Hi everyone !

Our implementation of Wordpress is video centric, meaning a post only makes sense if there is a video in it, and we would like to treat the video separately from the rest of the content of the post.

An idea is to use the "More Fields" plug-in, it allows to add custom fields to the write page of Wordpress. There is a little example on how you can add your own type of field, based on a date picker.

http://labs.dagensskiva.com/plugins/more-fields/#id5

It looks very simple, but sadly I'm missing some pieces to put it all together. Here is how this plug-in looks like

function mf_kaltura_init($types) {
                $language = ($a = substr(WPLANG, 0, 2)) ? $a : 'en';
                $select->title = 'Kaltura video';
                $select->html_before = "";
                $select->html_item = "<input id='%key%' name='%key%' value='%value%' class=%class% style='width: 160px;'>";
                $select->html_after = '';
                $select->html_selected = '';
                $select->values = false;               
                $types[]  = $select;
                return $types;
}
add_filter('more_fields_field_types', 'mf_kaltura_init');

In this case, I only have a simple text field. How could I have a link to the uploader, and get the wid back in order to add it to my template ???

Thanks for checking out :-)

Joined: 04/05/2009
Points: 354

So, just to clarify, you want to add a button that activates the KCW, allows you to select a media item, and then closes the KCW, adding the media to the current Wordpress post...?

Joined: 06/16/2009
Points: 21

Yes, pretty much like what it does with the WYSIWYG editor with the all-in-one-video-plugin, but I want it separate from the WYSIWYG editor, and not inserted into the post, but in a separate meta field.

If I could understand how all-in-one-video-plugin works, I could do the same, but it's a little too confusing for me.

Joined: 06/16/2009
Points: 21

Any input on that subject ? Or an other idea than customizing the plug-in ?

Is there any other way so far in Wordpress to add a Kaltura entry to a post without going through the WYSIWYG ???

Joined: 04/05/2009
Points: 354

You could easily modify your Wordpress template so that all you would need to do is put the entry ID in one of the Custom Fields. Have a read of:

http://codex.wordpress.org/Custom_Fields

You could then create your own little plugin (or modify the existing Kaltura plugin) that adds a button to the bottom of each post editing page that activates a javascript function that launches the KCW, allows you to add entries, and then tell you what the entry IDs are. You can then either manually copy and paste the entry ID into the custom field, or do some javascript magic that automatically does it.

One limitation I can see is that I don't think you can limit the KCW to only allow one file to upload, so you might need to do some array trickery.

Does this help at all?

Joined: 06/16/2009
Points: 21

Hi Chris, thanks for your answer !

That's pretty much exactly what I'm trying to do ! Planned to use the existing plug-in "more-fields" which would be quite pretty because then I could create a Kaltura type to it, and from the setting of that plug-in, you could even add, move around, Kaltura's medias the way you want. But definitely I could also make my own plug-in. One way or an other is fine for me.

My problem is to manage to create that javascript call to KCW, I tried a bit to write one from the scratch based on this guide http://corp.kaltura.com/wiki/index.php/Guides:Upload but I get all kinds of error, I'm not so in ease with your API and Javascript. It would be great to have a full example in the guide of a simple page calling KCW and displaying the uploaded video.

I also tried to modify the existing plug-in... but I don't really get how the files are organized, what's going on, it would be nice with some more comments in there.

I'll try some more today, but if you have any hint, or example that could help me, that would be great. I could definitely publish the plug-in when I get it to work.

Thanks a lot, Jonathan

Joined: 06/16/2009
Points: 21

Sorry, I should be more precise to get some help, I will try again to do my own thing from the scratch out of the guide, it's fairly well detailed after all. And I'll get back to you with more precise issues.

Thanks for you patience Chris ;-)

Joined: 06/16/2009
Points: 21

After a day of debugging, it finally works :-)

Should this code be published as a project ?

It allows you to add a KCW uploader to your Wordpress write page as a "More fields" item. Meaning you can have it among other extra fields, position it by drag&drop in the user interface. It's a lot more visible than the all-in-one-video-pack and it puts the ID of the item in a meta data instead of the post. Allowing the template to display in a different way then in the middle of the post content.

Should that become a project ? It could help others.

Joined: 06/16/2009
Points: 21

Mmmh, I got a little too excited... It worked very well on my local server (which doesn't have any Kaltura video published), but when I published it on the server (which has a bunch of video published), I get this error :

Fatal error: Cannot redeclare class KalturaClient in /home/www/1921a2a02c7f5f42e61bc90b74d5ac41/web/wp-content/plugins/mf_kaltura/kaltura-php5-client/kaltura_client.php on line 2023

I suppose it's a conflict between the all-in-one-video-pack plugin which creates it's own object KalturaClient.

What it the best thing to do ??? Can I reuse the class from the all-in-one-video-pack plug-in ? Or is there a way to create a new instance of KalturaClient ?

Following, the code up to the call of the new instance of KalturaClient :

        require_once('kaltura-php5-client/kaltura_client.php');
       
       
        define(KALTURA_PARTNER_ID, get_option("kaltura_partner_id"));
        define(KALTURA_SUBP_ID, get_option("kaltura_subp_id"));
        define(KALTURA_SECRET, get_option("kaltura_secret"));

        $config = new KalturaConfiguration(KALTURA_PARTNER_ID,KALTURA_SUBP_ID);

        $kalt_user = new KalturaSessionUser();
        $kalt_user->userId = get_option("kaltura_cms_user");
        $kalt_user->screenName = get_option("kaltura_cms_user");

        $client = new KalturaClient($config);

Joined: 03/29/2009
Points: 764

Hi,

This direction is very exciting. I think the best way to proceed would be to create a project, so the community (and ourselves) would have the chance to take a look and move it forward. What do you say?

Joined: 06/16/2009
Points: 21

That sounds good to me, how do we proceed, I didn't find any way to open a project, I guess you're in charge of that ? As soon as you open it I can publish the piece of code I have, and give some comments on it.

Joined: 06/16/2009
Points: 21

Since there was a conflict between the instances open by all-in-one-video-pack and my little plug-in, I decided to dive into your plug-in, and merge mine in there. Good news, after some code tweaking, it finally works !

Now my add-on is in your plug-in, but appears as an extra plug-in in the plug-in list.

Maybe after some improvement it could be integrated in the all-in-one-video-pack ? Then we would need to discuss if it's better to create our own plug-in or create a field type for the more-fields plug-in as I do now (I kind of like it since more-fields let you do a whole lot of things out of the box).

Tomorrow I'll do some further tests to see if it works well. It would be great if we had a project open to publish it and let the community contribute to it.

Wish you all a great new week !

Jonathan

Joined: 04/05/2009
Points: 354

Fantastic work Jonathan! Glad to see that you were able to work things out all by yourself!

Joined: 03/29/2009
Points: 764

Hi Jonathan,

Sounds really really great! Could you post it as a feature request here and attach the code? We would really like to take a look into it.

Joined: 06/16/2009
Points: 21

No problem, but how do I attach the code, the forum doesn't take .zip files. It involves a couple of file, I can still describe it but it would be easier to be able to attach a zip. Any hint ? Otherwise I copy paste the code from each file and describe it.

Joined: 03/29/2009
Points: 764

Please try now, it should work.

Joined: 06/16/2009
Points: 21

Sadly it still doesn't work to upload a zip file, see the attachment

AttachmentSize
Picture 1.png19.52 KB
Joined: 06/16/2009
Points: 21

In order to be able to publish the code, I renamed the .zip in .txt and it went through. I hope it will work the other way around too. You'll find the code and a detailed description in this post :
http://www.kaltura.org/visible-uploader-kaltura-entry-field-type-wordpre...

Joined: 03/29/2009
Points: 764

Thanks - downloaded it, and re-uploaded as zip. Permissions will be changed so users can upload zip files (and not only admins).