function reduire_image($userfile_name) { global $pmb_vignette_x; global $pmb_vignette_y; global $base_path; global $pmb_curl_available; if (!$pmb_vignette_x) { $pmb_vignette_x = 100; } if (!$pmb_vignette_y) { $pmb_vignette_y = 100; } $src_image = ''; if (file_exists("{$base_path}/temp/{$userfile_name}")) { $bidon = "{$base_path}/temp/{$userfile_name}"; $source_file = $bidon . "[0]"; } else { $bidon = $userfile_name; //Il s'agit d'une url, on copie le fichier en local $nom_temp = session_id() . microtime(); $nom_temp = str_replace(' ', '_', $nom_temp); $nom_temp = str_replace('.', '_', $nom_temp); $fichier_tmp = "{$base_path}/temp/" . $nom_temp; if ($pmb_curl_available) { $aCurl = new Curl(); $aCurl->save_file_name = $fichier_tmp; $aCurl->get($userfile_name); } else { $handle = fopen($userfile_name, "rb"); $filecontent = stream_get_contents($handle); fclose($handle); $fd = fopen($fichier_tmp, "w"); fwrite($fd, $filecontent); fclose($fd); } $source_file = $fichier_tmp . "[0]"; } $error = true; if (extension_loaded('imagick')) { mysql_set_wait_timeout(3600); $error = false; try { $img = new Imagick(); $img->readImage($source_file); if ($img->getImageWidth() > $pmb_vignette_x || $img->getImageHeight() > $pmb_vignette_y) { // Si l'image est trop grande on la réduit $img->thumbnailimage($pmb_vignette_x, $pmb_vignette_y, true); } $img->setImageFormat("png"); $img->setCompression(Imagick::COMPRESSION_LZW); $img->setCompressionQuality(90); $contenu_vignette = $img->getImageBlob(); } catch (Exception $ex) { $error = true; } unlink($fichier_tmp); } if ($error) { $size = @getimagesize($bidon); /* ".gif"=>"1", ".jpg"=>"2", ".jpeg"=>"2", ".png"=>"3", ".swf"=>"4", ".psd"=>"5", ".bmp"=>"6"); */ switch ($size[2]) { case 1: $src_img = imagecreatefromgif($bidon); break; case 2: $src_img = imagecreatefromjpeg($bidon); break; case 3: $src_img = imagecreatefrompng($bidon); break; case 6: $src_img = imagecreatefromwbmp($bidon); break; default: break; } $erreur_vignette = 0; if ($src_img) { $rs = $pmb_vignette_x / $pmb_vignette_y; $taillex = imagesx($src_img); $tailley = imagesy($src_img); if (!$taillex || !$tailley) { return ""; } if ($taillex > $pmb_vignette_x || $tailley > $pmb_vignette_y) { $r = $taillex / $tailley; if ($r < 1 && $rs < 1) { //Si x plus petit que y et taille finale portrait //Si le format final est plus large en proportion if ($rs > $r) { $new_h = $pmb_vignette_y; $new_w = $new_h * $r; } else { $new_w = $pmb_vignette_x; $new_h = $new_w / $r; } } else { if ($r < 1 && $rs >= 1) { //Si x plus petit que y et taille finale paysage $new_h = $pmb_vignette_y; $new_w = $new_h * $r; } else { if ($r > 1 && $rs < 1) { //Si x plus grand que y et taille finale portrait $new_w = $pmb_vignette_x; $new_h = $new_w / $r; } else { //Si x plus grand que y et taille finale paysage if ($rs < $r) { $new_w = $pmb_vignette_x; $new_h = $new_w / $r; } else { $new_h = $pmb_vignette_y; $new_w = $new_h * $r; } } } } } else { $new_h = $tailley; $new_w = $taillex; } $dst_img = imagecreatetruecolor($pmb_vignette_x, $pmb_vignette_y); ImageSaveAlpha($dst_img, true); ImageAlphaBlending($dst_img, false); imagefilledrectangle($dst_img, 0, 0, $pmb_vignette_x, $pmb_vignette_y, imagecolorallocatealpha($dst_img, 0, 0, 0, 127)); imagecopyresized($dst_img, $src_img, round(($pmb_vignette_x - $new_w) / 2), round(($pmb_vignette_y - $new_h) / 2), 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img)); imagepng($dst_img, "{$base_path}/temp/" . SESSid); $fp = fopen("{$base_path}/temp/" . SESSid, "r"); $contenu_vignette = fread($fp, filesize("{$base_path}/temp/" . SESSid)); if (!$fp || $contenu_vignette == "") { $erreur_vignette++; } fclose($fp); unlink("{$base_path}/temp/" . SESSid); } else { $contenu_vignette = ''; } } return $contenu_vignette; }
function maj_entrepot($source_id, $callback_progress = "", $recover = false, $recover_env = "") { global $charset, $base_path, $dbh; $this->fetch_global_properties(); $keys = unserialize($this->parameters); $this->callback_progress = $callback_progress; $params = $this->unserialize_source_params($source_id); $p = $params["PARAMETERS"]; $this->source_id = $source_id; $this->n_recu = 0; //Récupération du fichier XML distant en cURL $xml = ""; if (strpos($p["url"], "?")) { $url = substr($p["url"], 0, strpos($p["url"], "?")); } else { $url = $p["url"]; } $aCurl = new Curl(); $aCurl->timeout = 60; @mysql_set_wait_timeout(); //Authentification Basic if (substr($url, 0, 7) == "http://") { $auth_basic = "http://" . $keys["accesskey"] . ":" . $keys["secretkey"] . "@" . substr($url, 7); } elseif (substr($url, 0, 8) == "https://") { $auth_basic = "https://" . $keys["accesskey"] . ":" . $keys["secretkey"] . "@" . substr($url, 8); } else { $auth_basic = $keys["accesskey"] . ":" . $keys["secretkey"] . "@" . $url; } //On fait un premier appel pour récupérer le nombre total de documents $url_temp_auth_basic = $auth_basic . "?partial=0&page_size=0"; $content = $aCurl->get($url_temp_auth_basic); $xml_content = $content->body; if ($xml_content && $content->headers['Status-Code'] == 200) { $xsl_transform = $p["xsl_transform"]["code"]; if ($xsl_transform) { if ($xsl_transform['code']) { $xsl_transform_content = $xsl_transform['code']; } else { $xsl_transform_content = ""; } } if ($xsl_transform_content == "") { // $xsl_transform_content = file_get_contents($base_path."/admin/connecteurs/in/artevod/xslt/artevod_to_pmbxmlunimarc.xsl"); $xsl_transform_content = file_get_contents($base_path . "/admin/connecteurs/in/artevod/xslt/artevod2uni.xsl"); } $params = _parser_text_no_function_($xml_content, "WSOBJECTLISTQUERY"); if ($params["TOTAL_COUNT"]) { $this->n_total = $params["TOTAL_COUNT"]; $nb = 0; $nb_per_pass = 50; $page_nb = 1; $query = "select name from notices_custom where idchamp = " . $p['cp_field']; $result = pmb_mysql_query($query, $dbh); if ($row = pmb_mysql_fetch_object($result)) { $cp_artevod = array('cp_artevod' => $row->name); } else { $cp_artevod = array(); } while ($nb <= $params["TOTAL_COUNT"]) { $url_temp_auth_basic = $auth_basic . "?partial=0&page_size=" . $nb_per_pass . "&page_nb=" . $page_nb; $content = $aCurl->get($url_temp_auth_basic); $xml_content = $content->body; if ($xml_content && $content->headers['Status-Code'] == 200) { $pmbxmlunimarc = $this->apply_xsl_to_xml($xml_content, $xsl_transform_content, $cp_artevod); $this->rec_records($pmbxmlunimarc, $this->source_id, ''); } $page_nb++; $nb = $nb + $nb_per_pass; } } } else { $this->error = true; $this->error_message = $this->msg["artevod_error_auth"]; } return $this->n_recu; }
function diffuser() { global $dbh; global $msg, $charset, $base_path, $opac_connexion_phrase, $pmb_mail_delay; global $PMBusernom; global $PMBuserprenom; global $PMBuseremail; if (!$this->id_bannette) { return $msg['dsi_ban_no_access'] . "<br />"; } // impossible d'accéder à cette bannette if (!$this->nb_notices && $this->diffusion_email) { return $msg['dsi_ban_empty'] . "<br />"; } // On demande à diffuser le contenu et la bannette vide : pas question d'envoyer du vide mysql_set_wait_timeout(3600); $this->construit_diff(); $texte_base = $this->texte_diffuse; if ($this->export_contenu) { $fic_params = $base_path . "/admin/convert/imports/" . $this->typeexport . "/params.xml"; $temppar = file_get_contents($fic_params); $params = _parser_text_no_function_($temppar, "PARAMS"); if ($params["OUTPUT"][0]["SUFFIX"]) { $ext = $params["OUTPUT"][0]["SUFFIX"]; } else { $ext = "fic"; } $pieces_jointes[0]["nomfichier"] = $this->prefixe_fichier . today() . "." . $ext; $pieces_jointes[0]["contenu"] = $this->export_contenu; } $nb_dest = 0; $nb_echec = 0; $nb_no_email = 0; $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=" . $charset . "\n"; $requete = "select id_empr, empr_cb, empr_mail, empr_nom, empr_prenom, empr_login, empr_password, if(empr_sexe=2,'" . $msg["civilite_madame"] . "',"; $requete .= "if(empr_sexe=1,'" . $msg["civilite_monsieur"] . "','" . $msg["civilite_unknown"] . "')) as empr_sexe, empr_adr1, empr_adr2, empr_cp, empr_ville,"; $requete .= "empr_pays, empr_tel1, empr_tel2, date_format(empr_date_adhesion, '" . $msg["format_date"] . "') as aff_empr_date_adhesion, date_format(empr_date_expiration, '" . $msg["format_date"] . "') as aff_empr_date_expiration,"; $requete .= "statut_libelle, allow_dsi, allow_dsi_priv, proprio_bannette, bannette_mail from empr, empr_statut, bannette_abon, bannettes "; $requete .= "where num_bannette='" . $this->id_bannette . "' and num_empr=id_empr and empr_statut=idstatut and num_bannette=id_bannette "; $requete .= "order by empr_nom, empr_prenom "; $res = pmb_mysql_query($requete, $dbh); while ($empr = pmb_mysql_fetch_object($res)) { $emaildest = $empr->empr_mail; if ($empr->bannette_mail && $emaildest) { $destinataires = explode(";", $emaildest); $found = 0; foreach ($destinataires as $mail) { if ($mail == $empr->bannette_mail) { $found = 1; break; } } if ($found) { $emaildest = $empr->bannette_mail; } } $texte = $texte_base; if ($emaildest) { if (!$empr->allow_dsi && !$empr->proprio_bannette || !$empr->allow_dsi_priv && $empr->proprio_bannette) { //si la dsi n'est pas autorisée pour ce lecteur, affichage de l'info mais pas d'envoi $nb_echec++; $echec_email .= "- " . $empr->empr_nom . " " . $empr->empr_prenom . " (" . $msg["statut_empr"] . "' " . $empr->statut_libelle . "')<br />"; } else { //function mailpmb($to_nom="", $to_mail, $obj="", $corps="", $from_name="", $from_mail, $headers, $copie_CC="", $copie_BCC="", $faire_nl2br=0, $pieces_jointes=array()) { $dates = time(); $login = $empr->empr_login; $code = md5($opac_connexion_phrase . $login . $dates); $texte = str_replace('!!code!!', $code, $texte); $texte = str_replace('!!login!!', $login, $texte); $texte = str_replace('!!empr_login!!', $login, $texte); $texte = str_replace('!!date_conex!!', $dates, $texte); $texte = str_replace('!!empr_name!!', $empr->empr_nom, $texte); $texte = str_replace('!!empr_first_name!!', $empr->empr_prenom, $texte); $texte = str_replace('!!empr_sexe!!', $empr->empr_sexe, $texte); $texte = str_replace('!!empr_cb!!', $empr->empr_cb, $texte); $texte = str_replace('!!empr_mail!!', $empr->empr_mail, $texte); if (strpos($texte, "!!empr_name_and_adress!!")) { $texte = str_replace("!!empr_name_and_adress!!", nl2br($this->m_lecteur_adresse($empr)), $texte); } if (strpos($texte, "!!empr_all_information!!")) { $texte = str_replace("!!empr_all_information!!", nl2br($this->m_lecteur_info($empr)), $texte); } $res_envoi = @mailpmb($empr->empr_prenom . " " . $empr->empr_nom, $emaildest, $this->comment_public, $texte, $PMBuserprenom . " " . $PMBusernom, $PMBuseremail, $headers, "", "", 0, $pieces_jointes); if ($pmb_mail_delay * 1) { sleep((int) $pmb_mail_delay * 1 / 1000); } if ($res_envoi) { $nb_dest++; } else { $nb_echec++; $echec_email .= "- " . $empr->empr_nom . " " . $empr->empr_prenom . "<br />"; } } } else { $nb_no_email++; $no_email .= "- " . $empr->empr_nom . " " . $empr->empr_prenom . "<br />"; } } // remplissage du panier avec le contenu de la bannette if ($this->num_panier) { $temp_requete = "delete from caddie_content where caddie_id='" . $this->num_panier . "'"; pmb_mysql_query($temp_requete, $dbh); $temp_requete = "insert into caddie_content (caddie_id, object_id) (select " . $this->num_panier . ", num_notice from bannette_contenu where num_bannette=" . $this->id_bannette . ")"; pmb_mysql_query($temp_requete, $dbh) or die(pmb_mysql_error() . $temp_requete); } /* A commenter pour tests */ $temp_requete = "update bannettes set date_last_envoi=sysdate() where id_bannette='" . $this->id_bannette . "' "; $res = pmb_mysql_query($temp_requete, $dbh); $res_envoi = $msg["dsi_dif_res_dif"] . "<ul><li>" . $msg["dsi_dif_res_dif_mail_ok"] . ": {$nb_dest} </li>"; if ($nb_echec) { $res_envoi .= "<li>" . $msg["dsi_dif_res_dif_mail_echec"] . ": {$nb_echec} <blockquote>{$echec_email}</blockquote></li>"; } if ($nb_no_email) { $res_envoi .= "<li>" . $msg["dsi_dif_res_dif_no_mail"] . ": {$nb_no_email} <blockquote>{$no_email}</blockquote></li>"; } $res_envoi .= "</ul>"; if ($nb_echec || $nb_no_email) { $res_envoi .= "<script>openPopUp('./print_dsi.php?id_bannette={$this->id_bannette}', 'Impression de DSI', 500, 400, -2, -2, 'toolbar=no, infobar=no, resizable=yes, scrollbars=yes')</script>"; } return $res_envoi; }
function analyse_response($url, $rcallback = "") { //Remise à zéro des erreurs $this->error = false; $this->error_message = ""; //remise à zero des enregistrements if ($url != $this->next_request) { $this->records = array(); } $this->next_request = ""; $this->rtoken = ""; //Initialisation de la ressource $this->remainder = ''; $ch = curl_init(); // configuration des options CURL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_WRITEFUNCTION, array(&$this, "parse_xml")); curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this, "verif_header")); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if ($this->time_out) { curl_setopt($ch, CURLOPT_TIMEOUT, $this->time_out); mysql_set_wait_timeout($this->time_out); } //Réinitialisation du "retry_after" $this->retry_after = ""; configurer_proxy_curl($ch); //Explosion des arguments de la requête pour ceux qui ne respectent pas la norme !! $query = substr($url, strpos($url, "?") + 1); $query = explode("&", $query); for ($i = 0; $i < count($query); $i++) { if (strpos($query[$i], "verb") !== false) { $verb = substr($query[$i], 5); break; } } //Initialisation de l'environnement d'état du parser $s = new oai_parser($rcallback, $this->charset); //Si le verb est affecté, on prérempli histoire d'aider un peu... :-) if ($verb) { $s->verb = $verb; } //Initialisation du parser $this->xml_parser = xml_parser_create("utf-8"); xml_set_object($this->xml_parser, $s); xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($this->xml_parser, XML_OPTION_SKIP_WHITE, 1); xml_set_element_handler($this->xml_parser, "oai_startElement", "oai_endElement"); xml_set_character_data_handler($this->xml_parser, "oai_charElement"); $n_try = 0; $cexec = curl_exec($ch); while ($cexec && $this->retry_after && $n_try < 3) { $n_try++; sleep((int) $this->retry_after * 1); $this->retry_after = ""; $cexec = curl_exec($ch); } if (!$cexec) { $this->error = true; $this->error_message = curl_error($ch); } xml_parser_free($this->xml_parser); $this->xml_parser = ""; curl_close($ch); if ($this->error) { $this->error_message .= " - " . $url; unset($s); return; } //Affectation des éléments de réponse if (stripos($this->charset, 'iso-8859-1') !== false) { $c = true; } else { $c = false; } //Test de l'url base if ($this->clean_base_url) { $p = strpos($s->tree[1][1]["CHAR"], "?"); if ($p !== false) { $s->tree[1][1]["CHAR"] = substr($s->tree[1][1]["CHAR"], 0, $p); } } $this->response_date = $c ? utf8_decode($s->tree[1][0]["CHAR"]) : $s->tree[1][0]["CHAR"]; $this->url_base = $c ? utf8_decode($s->tree[1][1]["CHAR"]) : $s->tree[1][1]["CHAR"]; $this->request["URL_BASE"] = $c ? utf8_decode($s->tree[1][1]["CHAR"]) : $s->tree[1][1]["CHAR"]; foreach ($s->tree[1][1]["ATTRIB"] as $key => $val) { if ($key != "resumptionToken") { $this->request["ATTRIBS"][$key] = $c ? utf8_decode($val) : $val; } } $this->verb = $c ? utf8_decode($s->tree[1][1]["ATTRIB"]["verb"]) : $s->tree[1][1]["ATTRIB"]["verb"]; $this->rtoken = $s->rtoken; if ($s->tree[1][2]["NAME"] == "error") { $this->error = true; $this->error_message = "OAI Error, the server tell : " . $s->tree[1][2]["ATTRIB"]["code"] . " : " . $s->tree[1][2]["CHAR"]; $this->error_oai_code = $s->tree[1][2]["ATTRIB"]["code"]; } //Si c'est la requête identify if ($this->verb == "Identify") { $this->records[0] = $c ? utf8_decode($s->cur_elt) : $s->cur_elt; } else { if (!$rcallback) { for ($i = 0; $i < count($s->records); $i++) { $this->records[] = $c ? utf8_decode($s->records[$i]) : $s->records[$i]; } } } //Si on a un resumptionToken if (is_array($this->rtoken) && $this->rtoken["token"]) { $t_nr = explode('?', $this->request['URL_BASE']); $this->next_request = $t_nr[0] . "?verb=" . $s->verb . "&resumptionToken=" . rawurlencode($this->rtoken["token"]); } //Supression de l'environnement d'état ! unset($s); }