Recent Topics

Add skin_container( ) from plugin

started by on Apr 06, 2015 – Last touched: Jun 21, 2015

Apr 06, 2015 15:54    

Is there a way to add a skin container from a plugin?

PHP

skin_containerNT_('Some Name'), array());

Apr 06, 2015 17:28

... actually looking at it I see that the only way to do this is to add it in a file and copy it to the skins folder:

PHP

Plugin::BeforeEnable()

this way it will be automatically added on container reload action:

admin.php?ctrl=widgets&blog=1&action=reload

PHP

<?php
 
/**
*  this file was created for the skin by plugin:
*/
 
if( !defined('EVO_MAIN_INIT' ) ) die'Please, do not access this page directly.' );
 
skin_containerNT_('Some Name'), array());
?>

and remove it if the plugin is uninstalled

PHP

Plugin::BeforeUninstall()

wouldbe nice though if Plugins had a Handle for this..

Apr 06, 2015 20:39

Hi @achillis,

That's right, the containers are defined in the skins and loaded from there, so it makes sense to create them from the plugin. However, a new containers mechanism is on the way and I guess these kind of things might be possible.

Regards!

Apr 06, 2015 23:18

Err... does it really make sense?

Can you please describe a use case for when you need to create a container in a plugin?

Apr 07, 2015 08:39

I developed a plugin for downloads. (Based on your very cool download.php function)

I am a photographer and use B2evolution exclusively. I often get bookings in different parts of my country (South Africa) and have found delivering my clients photography products challenging. After some consideration I decided that I wish to, in addition to sending my clients their photography package via express delivery, have it available on my website. This way they can download their images. But I also needed to make these downloads a secret, so that only the intended client have access.

I needed to make it very simple for clients to find the download location. I used to upload files to a folder and send a link, but it is impossible to effectively manage it this way. So I wanted a single page clients could visit, and if logged in, find downloads specifically for them.

After a photography session for clients I edit, zip and upload the files into a specific directory via B2evo's awesome drag and drop upload function. (See also http://forums.b2evolution.net/files-zip-files)

The Plugin:

I created a plugin which includes a Disp handle for a download page (http://www.somesite.com/?disp=downloads) where users can go to download files specifically for them. When the plugin is installed it create/ register the download handle. The download page contains:

PHP

skin_containerNT_('Downloads'), array());

This container allows one to add the plugin widget into the download page.
The plugin registers a new widget listed with the widgets: Download link plugin.
It can be added multiple times into a container. Each instance permits one to select multiple files (or only a single file) and assign it to specific users and make it available only to the selected users.

They have to be logged in to see if there are any downloads available. Files are downloaded by its $File->ID and users can only download files allocated, and the plugin ensures that a user can't change a download ID, ie from [?disp=downloads&download=121] to [?disp=downloads&download=101]

The plugin is completed now and works really well. During its development I discovered that skin_container is only registered if it's included in the skins folder. The only way to achieve this was to include a function in the plugin install routine which looks at skins used by the collections and then creates a new file which includes the line skin_container( NT_('Downloads'), array()); into the relevant skins folders, to ensure the container is available in the back office to add the widget.

Having a hook to help with this would make coding plugins easier. There is a potential for plugins which handles custom display events which requires containers.

At the moment I am using said plugin on B2e V6.1.2, and you can check it out at the link below, but since you are not a member and have no downloadable files allocated, you won't see much...

http://www.midnightstudios.co.za/?disp=downloads

Apr 07, 2015 15:32

Okay, so I have a question: if you are implementing custom functionality via a custom disp which is handled by the plugin, why don't you do everything you need in the custom disp? Why do you need to go through a container and a widget?

Beyond the fact I don't fully understand the use case here, it's not a good time for us to commit to something like this as we are changing the container implementation heavily in the next version (think nested containers) and this plugin thing would create additional compatibility constraints.

No matter what, an immediate workaround for you would probably be to create a /skins/dummy.php file which contains the container you want. b2evo will scan this unused file like all the others in the skins directory and extract the container.

Finally, on a loosely related note: have you thought about uploading each client's files into their private file root? This might simplify some things in the access management part.

Apr 07, 2015 15:45

I get what you are saying I.T.O. the dummy file, and that is exactly what I did. I understand that I do not have the foresight of the direction the core is moving to, and therefore won't know what is practical or not. I trust, like all other folks and their input, that the dev team will consider suggestions and implement what is practical and productive to the development of the core.

I.T.O. your final note. I will look into it. Thanks

Jun 19, 2015 22:41

I just did a new install on V6.4.4 and discovered an issue with skin containers.... a possible bug?

when I go to the Widget Tab (/admin.php?ctrl=widgets&blog=1) and click on reload containers, the expected message is displayed saying it found the containers.... but the new containers doesn't render on the Widget page [Back-Office]?!

This worked without issues before, what changed?

Jun 20, 2015 21:24

I confirm this bug (no display of empty containers). I actually fixed it yesterday. Next release will be back to normal.

Jun 20, 2015 22:49

Is the next release soon, and if not could you share the changes you made so that I can fix it on my side on the interim?


Form is loading...

blog software – This forum is powered by b2evolution CMS, a complete engine for your website.