t('PDF thumbnail'), 'type' => MENU_LOCAL_TASK, 'access callback'=>'user_access', 'access arguments' => array('thumbnail_admin'), 'page callback' => 'drupal_get_form', 'page arguments' => array('thumbnail_admin_settings'), 'file' => 'thumbnail.admin.inc', 'file path' => drupal_get_path('module', 'thumbnail'), ); $items['thumbnail/debug'] = array ( 'title'=>t('PDF thumbnail'), 'type' => MENU_LOCAL_TASK, 'access callback'=>'user_access', 'access arguments' => array('thumbnail_admin'), 'page callback' => 'thumbnail_debug', ); return $items; } function thumbnail_permission() { return array( 'thumbnail_admin' => array( 'title' => t('Thumbnail admin'), 'description' => t("Allow user to administrate the Thumbnail client"), ) ); } function thumbnail_get_thumbnail($url){ $conf = thumbnail_get_conf(); if(empty($conf)){ drupal_set_message("Le module thumbnail n'est pas configuré", "warning"); return false; } //dsm($conf); $request['output']='json'; $request['pdf']=$url; $request['format']='png'; $json = thumbnail_get_file($conf['thumbnail_url'], $request, 320); return json_decode($json); } function thumbnail_save_thumbnail($thumbnail){ if(isset($thumbnail->thumbnail) && $thumbnail->thumbnail!=''){ $conf = thumbnail_get_conf(); file_prepare_directory($conf['thumbnail_local_store'], FILE_CREATE_DIRECTORY); $destination = $conf['thumbnail_local_store'].'/'.drupal_basename($thumbnail->thumbnail); $data = drupal_http_request($thumbnail->thumbnail); if((integer)$data->code < 400){ $file = file_save_data($data->data, $destination); return $file; } } return false; } //Cette fonction permet d'aller chercher un fichier à distance function thumbnail_get_file($url, $post_request, $timeout=45){ //file_get_contents pose des problèmes de time out on utilise donc préférentiellelement curl if(in_array ('curl', get_loaded_extensions())){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$post_request); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); //tps max d'execution du service curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); //tps max de connexion au service en seconde $r = curl_exec($ch); curl_close($ch); return $r; } else return $false; //return sandre_removeBOM($r); } function thumbnail_debug(){ $node = node_load(231); //$uri = $node->field_file['und'][0]['uri']; //dsm(url(, array('absolute'=>true))); //$url = file_create_url($uri); //dsm($url); if(isset($node->field_document_distant) && !empty($node->field_document_distant['und'])){ foreach($node->field_document_distant['und'] as $delta=>$link){ if(strtolower(substr($link['url'], -3))=='pdf'){ dsm($node); $info = thumbnail_get_thumbnail($link['url']); dsm($info); /* $file = thumbnail_save_thumbnail($info); if($file){ $node->field_page_de_garde['und'][0] = (array)$file; node_save($node); } */ break; } } } return "debug"; } //Fonction de chargement de la configuration du module function thumbnail_get_conf(){ return variable_get('thumbnail_configurations', array()); } //Fonction d'enregistrement de la configuration du module function thumbnail_set_conf($conf){ return variable_set('thumbnail_configurations', $conf); }