Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-01-18 00:37:46

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Thumbnail creating problem with smd_thumbnail

Hi all

I have Multiple photo upload section in front end system of my website.

After uploading i have code as below

include_once txpath . '/include/txp_image.php';  

for($i = 0; $i<$tolFiles;$i++){		
$cap = explode('.',$_FILES["files"]["name"][$i]);
$file['name'] =  $_FILES["files"]["name"][$i];
$file['tmp_name'] = $_FILES["files"]["tmp_name"][$i];

if(isset($_POST['caption'.$cap[0]])){
	$caption =  $_POST['caption'.$cap[0]];
	$meta['caption'] = filter_input(INPUT_POST,'caption'.$cap[0],FILTER_SANITIZE_STRING);
	$meta['alt'] = $meta['caption']; 
}
image_data($file, $meta);
}

Went through image_data function it has callback as below
callback_event('image_uploaded', $event, false, $id);

This should have generate smd thumbnail automatically but its not working.
Currently i am able upload original image and have to create smd thumbnail manually by clicking ‘create’ button.

Anything thing wrong with the code.

Any help appreciated

Thanks

{Edited to add some Textile for better code display. – Uli}

Last edited by uli (2013-01-18 13:24:33)

Offline

#2 2013-01-18 09:50:54

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,270
Website GitHub

Re: Thumbnail creating problem with smd_thumbnail

piyashrija wrote:

This should have generate smd thumbnail automatically but its not working.

As a stab in the dark, if you’re doing that from the public site then I don’t think the smd_thumbnail callbacks will fire because the plugin only registers those callbacks on the admin side. I may be wrong.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2013-01-18 13:29:35

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Thumbnail creating problem with smd_thumbnail

Just for me to learn:
I’ve never seen spaces around a dot in a path concatenation, like here:
include_once txpath . '/include/txp_image.php';

Would that work?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2013-01-18 14:39:56

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Thumbnail creating problem with smd_thumbnail

uli wrote:

Would that work?

Yes. The spaces aren’t in the path string, but in the source code.

Offline

#5 2013-01-18 15:12:54

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Thumbnail creating problem with smd_thumbnail

Kiitos, Jukka!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2013-01-21 04:09:42

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: Thumbnail creating problem with smd_thumbnail

Thanks for reply.
Here is basic step what i have done so far.

1. Simple Plugin(admin+public) is developed that generates image upload form.
2. Form validation.
3. If validated includes Txp_images and calls function image_data($file , $meta).
4. Related function is called with textpattern tag from public site.

and this does not fire callback event register by smb_thumbnail on image upload

I am new to textpattern plugin development.
I guess my concept about callback event must be wrong.

Any help ??

Thanks

Last edited by piyashrija (2013-01-21 04:10:01)

Offline

#7 2013-01-21 05:57:14

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: Thumbnail creating problem with smd_thumbnail

Additional…

callback_event(‘image_uploaded’, ‘image’, false, $id);
Also, i did manual addition of image in the database without using image_data but still no luck have to create smb_thumbnail manually.

Last edited by piyashrija (2013-01-21 05:57:40)

Offline

#8 2013-01-21 07:35:33

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,270
Website GitHub

Re: Thumbnail creating problem with smd_thumbnail

piyashrija wrote:

If validated includes Txp_images and calls function image_data($file , $meta).

That won’t be enough to invoke smd_thumbnail’s admin side code. Textpattern has five types of plugin, although the distinction between two sets of them are fairly close so for all intents and purposes there are three types:

  1. public
  2. admin
  3. library

Library plugins always stand alone and have to explicitly be included by other plugins to load. The other types get loaded in combination dependent on which “side” of Textpattern you are using: admin and/or public. smd_thumbnail is loaded on both sides because it’s a Type 5 plugin, but if you look at its code, one of the first things it does is:

if (@txpinterface == 'admin') {
   // register callbacks for the admin side hooks
}

So, even though the plugin is loaded, the callbacks are not registered unless you are using the admin side. To try and prove this hypothesis, you can hack the plugin and remove the conditional check I mentioned above so all the callbacks are registered regardless of which side you are on. Not sure if it’ll have any other consequences because it adds privileges (you could always put the conditional check just around the first 6 lines including the add_privs() bits I suppose).

You’ll probably find the plugin’s callbacks will then fire, although I’m not exactly sure if they will or not. because I’ve never tried it.

Alternatively you could also detect if the plugin is loaded (maybe via if function_exists('smd_thumbnail')) and then manually register the smd_thumbnail callback(s) you need inside your own plugin. Again, not sure how future proof this is or whether it’ll work, but it might.

Hope that helps.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2013-01-21 23:26:56

piyashrija
Member
Registered: 2012-05-17
Posts: 30

Re: Thumbnail creating problem with smd_thumbnail

Thanks Stef…Got it clear now :)

Offline

Board footer

Powered by FluxBB