"Thumbnail not yet available"
nirvanajyothi - July 11, 2008 - 15:29
| Project: | iPaper |
| Version: | 6.x-1.0-rc2 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
have uploaded a powerpoint as Ipaper content type and the node is listed with a white thumbnail and not the powerpoint thumbnail and when the pointer hovers over this white thumbnail it says
Thumbnail not yet available'
is this a bug?

#1
See http://drupal.org/node/265278#comment-880162. Thumbnails are fetched on cron runs, and only if the document is available in the search index on scribd. I'll make a not about this in the next version of the readme file.
#2
ok.Have run cron and it showed "The directory sites/default/files/ipaper_thumbs has been created."
But the thumbnail is not available still.
will the documents be indexed on scribd as you mentioned if they have been set to private and so will the thumbnails be created for private documents.
#3
can something be done about thumbnail for private documents?
#4
the thumbnail foor a document i uploaded at my site as private using iPaper has become available today...so i think its possible(it took long though..)
"Give me a place to stand and I shall move the Earth"
-Archimedes
#5
it takes a while, but there is no way around this unfortunately.
#6
k.i have changed the emmpty.jpg into a ppt icon...its better to have a sumdin than a white photo i thought...is that alright?
#7
have set cron to run automatically every 5 minutes.Now the thumbnails appear much faster.thats wonderful.
#8
#9
Automatically closed -- issue fixed for two weeks with no activity.
#10
I was having these same problems, except NONE of my thumbnails would load for days, and I figured to do something about it. After some research into the API, it turns out that the proper function to ask the Scribd API for information about specific documents is "getSettings". By first making a list of the published doc_ids, then sendign that to scribd for each one, you can return the thumbnail for each one. I wrapped this around the already existing loop function inside ipaper_cron and, TADA! near instant thumbnails.
In truth, I have not been able to test what happens when the thumbnail is not yet available, but the original code had plenty of error catches, which should cover this.
I haven't yet made a proper patch, so for now, this just replaces the entire ipaper_cron hook function in the 6.x-1-beta version
This also applies a quick string replace to grab the "large" thumbnail version.
<?php
function ipaper_cron(){
//save thumbnails
$scribd = ipaper_scribd_init();
$count = 0;
//Grab the list of published iPaper nodes' doc_ids
$doc_list = db_query('SELECT doc_id FROM {ipaper} LEFT JOIN {node} on {node}.nid = {ipaper}.nid WHERE {node}.status = 1');
while ($row = db_fetch_object($doc_list)) {
$doc_id = $row->doc_id;
$result = $scribd->getSettings($doc_id);
if (!is_array($result))
break;
//Trim is VERY important, cURL will break if this is not cleaned
$source = str_replace('thumb','large',trim($result['thumbnail_url'])); //Get "large" version of thumbnail
//$source = trim($result['thumbnail_url']); //Uncomment for regular tiny version of thumbnail
$destination = _ipaper_get_thumb_path($doc_id);
if (!file_exists($destination)){
$request = _ipaper_request($source);
if ($request) {
// Check that the files directory is writable
if (file_check_directory(dirname($destination), FILE_CREATE_DIRECTORY)) {
file_save_data($request, $destination, FILE_EXISTS_REPLACE);
$count += 1;
}
else{
watchdog('ipaper', "Could not write thumbnails.", NULL, WATCHDOG_ERROR);
return;
}
}
else{
return;
}
}//if !file_exists
}//while doc_list
if (variable_get('ipaper_log_requests', 0)){
watchdog('ipaper', "Cron run: stored $count thumbnails.");
}
}
?>
If anyone wants to test (Though it seems to work pretty darn well for me) let me know how it goes.
This code currently doesn't implement any means of checking to see what images have already been grabbed, making cron loads inefficient. With a little tweaking, the images listed in the folder could be added as a not in list to the query and we'd be spot on. If I get a request for that, i'd be glad to add it.
#11
this is great! I had never seen the thumbnail being returned anywhere other than docs.search(). Apparently getSettings does it too, which will hopefully put an end to one of the module's greatest drawbacks.
I will test this and make a new release.
#12
Great!
The code I mentioned to fix the update to check to see if there were any images made yet (instead of going and getting all of them regardless of if they existed or not), I went ahead and made anyway, so the code below should work more efficiently :)
<?php
function ipaper_cron(){
//save thumbnails
$scribd = ipaper_scribd_init();
$count = 0;
//Get list of doc_ids already with images
$done_list = array(0); //Default array in case there are no images
foreach (glob(file_directory_path().'/ipaper_thumbs/*.jpg') as $filename) {
$path_parts= pathinfo($filename); //Split the filename up
$done_list[] = substr($path_parts['basename'], 0,strpos($path_parts['basename'],'.')); //parse out just the filename, sans extension
}
//Grab the list of published iPaper nodes' doc_ids, not matching the list of fetched image names
$doc_list = db_query('SELECT doc_id FROM {ipaper} LEFT JOIN {node} on {node}.nid = {ipaper}.nid WHERE {node}.status = 1 AND doc_id NOT IN (%s)', implode(',',$done_list));
while ($row = db_fetch_object($doc_list)) {
$doc_id = $row->doc_id;
$result = $scribd->getSettings($doc_id);
if (!is_array($result))
break;
//Trim is VERY important, cURL will break if this is not cleaned
$source = str_replace('thumb','large',trim($result['thumbnail_url'])); //Get "large" version of thumbnail
//$source = trim($result['thumbnail_url']); //Uncomment for regular tiny version of thumbnail
$destination = _ipaper_get_thumb_path($doc_id);
if (!file_exists($destination)){
$request = _ipaper_request($source);
if ($request) {
// Check that the files directory is writable
if (file_check_directory(dirname($destination), FILE_CREATE_DIRECTORY)) {
file_save_data($request, $destination, FILE_EXISTS_REPLACE);
$count += 1;
}
else{
watchdog('ipaper', "Could not write thumbnails.", NULL, WATCHDOG_ERROR);
return;
}
}
else{
return;
}
}//if !file_exists
}//while doc_list
if (variable_get('ipaper_log_requests', 0)){
watchdog('ipaper', "Cron run: stored $count thumbnails.");
}
}
?>
#13
So I figured that since it's so easy to get a thumbnail, why not get it when the node is saved.
I also added a function to allow the user to clear all the thumbnails.
<?php
//in ipaper_upload(), add
_ipaper_save_thumb($node->doc_id, $scribd);
/**
* Cache thumbnails from scribd server.
* Parameter $scribd represents an API object obtained through ipaper_scribd_init()
*/
function _ipaper_save_thumb($doc_id, $scribd){
$result = $scribd->getSettings($doc_id);
//drupal_set_message("d $doc_id");
//Trim is VERY important, cURL will break if this is not cleaned
$source = trim($result['thumbnail_url']);
//Get "large" version of thumbnail
if(variable_get('ipaper_thumbnail_size', 'small') == 'large')
$source = str_replace('thumb', 'large', $source);
$destination = _ipaper_get_thumb_path($doc_id);
if (!file_exists($destination)){
$request = _ipaper_request($source);
if ($request) {
// Check that the files directory is writable
if (file_check_directory(dirname($destination), FILE_CREATE_DIRECTORY)) {
file_save_data($request, $destination, FILE_EXISTS_REPLACE);
}
else{
watchdog('ipaper', "Could not write thumbnail for doc_id $doc_id.", NULL, WATCHDOG_ERROR);
return;
}
}//if $request
}//if !file_exists
}
/**
* Implementation of hook_flush_caches().
*/
function ipaper_flush_caches(){
file_scan_directory(file_directory_path() .'/ipaper_thumbs', '.*', array('.', '..', 'CVS'), 'file_delete');
$query = db_query("SELECT doc_id FROM {ipaper} WHERE doc_id<>0");
$scribd = ipaper_scribd_init();
while ($result = db_fetch_array($query)){
_ipaper_save_thumb($result['doc_id'], $scribd);
}
}
?>
#14
#15
immediate thumbnail downloads and custom thumbnail sizes have been included in release candidate 2. Please go to the module settings page after you upgrade the module.
#16
tested iPaper 6.x-rc2 locally.working alright.
-thank you techninja and rares!
#17
Thanks again, and great work rares getting those changes in so quickly!
Though, if you could add one more option to the setup form.. One of my servers is acting up and refuses to grab the images properly using cURL, but will work just fine with the fsockopen fallback. Perhaps a "don't use curl for grabbing thumbnails" option?
Thanks again!
#18
Oh and not to be picky or anything, if the image is grabbed too soon before the document has completed converting, the thumbnail will only return an appropriate icon of the document type being converted. Perfectly appropriate for momentary presentation! But fairly inappropriate for a module that assumes the first image that is returned with the function is the one and only image for the node :P
I have personally not come up with any solutions for this, other than perhaps paying attention to the conversion status flag inside the getSettings return data, and not saving the thumbnail then, grabbing it only with a cleanup cron hook to later. And to think we were out of cron land for a little while!
I'd imagine grabbing the fulltext for a document would have to work similarly for longer conversion time documents.
#19
I am having the same issue as techninja. The thumb is coming back as the pdf logo or even blank, as its pulling the thumbnail before its fully processed. Anyone have any suggestions for a delay or pause before it grabs the thumbnail? Thanks
PS. Going back after and clicking the rebuild cache button seems to grab the thumbnail.
#20
I'm adding code to -dev (there will be a rc3 release shortly) that waits for two minutes before attempting to pull the thumbnail. if you want a different value search for 120 in ipaper.module. in my tests it has been enough. i think it only really needs a few seconds.
also, now, if you save the ipaper again (go to edit, click submit), it will get the thumbnail again - just in case you got the word or pdf icon.
#21
Automatically closed -- issue fixed for 2 weeks with no activity.