function get_notice_by_meta($name, $filename) { global $pmb_keyword_sep; global $pmb_type_audit; global $webdav_current_user_name, $webdav_current_user_id; \create_tableau_mimetype(); $mimetype = \trouve_mimetype($filename, extension_fichier($name)); //on commence avec la gymnatisque des métas... if ($mimetype == "application/epub+zip") { //pour les ebook, on gère ca directement ici ! $epub = new \epubData(realpath($filename)); $metas = $epub->metas; $img = imagecreatefromstring($epub->getCoverContent()); $file = tempnam(sys_get_temp_dir(), "vign"); imagepng($img, $file); $metas['thumbnail_content'] = file_get_contents($file); unlink($file); } else { $metas = \extract_metas(realpath($filename), $mimetype); } if ($this->config['metasMapper_class']) { $className = "Sabre\\PMB\\" . $this->config['metasMapper_class']; if (class_exists($className)) { $metasMapper = new $className($this->config, $metas, $mimetype, $name); } } if (!is_object($metasMapper)) { $metasMapper = new metasMapper($this->config, $metas, $mimetype, $name); } return $metasMapper->get_notice_id(); }
function get_notice_by_meta($name, $filename) { \create_tableau_mimetype(); $mimetype = \trouve_mimetype($filename, extension_fichier($name)); //on commence avec la gymnatisque des métas... if ($mimetype == "application/epub+zip") { //pour les ebook, on gère ca directement ici ! $epub = new \epubData(realpath($filename)); $metas = $epub->metas; $img = imagecreatefromstring($epub->getCoverContent()); $file = tempnam(sys_get_temp_dir(), "vign"); imagepng($img, $file); $metas['thumbnail_content'] = file_get_contents($file); unlink($file); } else { $metas = \extract_metas(realpath($filename), $mimetype); } $metasMapper = $this->load_metas_mapper(); return $metasMapper->get_notice_id($metas, $mimetype, $name); }
function extract_metas($filename, $mimetype, $tmp = false) { global $base_path, $class_path; global $charset; //$metas = array(); switch ($mimetype) { //EPub case "application/epub+zip": //Exiftool ne donnerait rien, mais un Epub contient toutes les infos qui nous faut ! require_once $class_path . "/epubData.class.php"; $epub = new epubData($filename); $metas = $epub->metas; break; case "application/pdf": // exec("exiftool -struct -J -q ".$filename,$metas); // $metas = json_decode(implode("\n",$metas),true); exec("exiftool " . $filename, $tab); $metas = array(); foreach ($tab as $row) { $elem = explode(":", $row); $key = trim(str_replace(" ", "", array_shift($elem))); $value = trim(implode(":", $elem)); if ($charset != "utf-8") { $key = utf8_decode($key); $value = utf8_decode($value); } $metas[$key] = $value; } break; default: $type = substr($mimetype, 0, strpos($mimetype, "/")); switch ($type) { case "image": case "video": case "audio": exec("exiftool " . $filename, $tab); $metas = array(); foreach ($tab as $row) { $elem = explode(":", $row); $key = trim(str_replace(" ", "", array_shift($elem))); $value = trim(implode(":", $elem)); if ($charset != "utf-8" && mb_detect_encoding($value) == 'UTF-8') { $key = utf8_decode($key); $value = utf8_decode($value); } $metas[$key] = $value; } break; case "text": //pas de métas pertinantes sur une fichier texte... break; default: if (!extension_fichier(basename($filename))) { $new_name = basename($filename) . "temp"; //Pour éviter que si pas d'extension on perde le fichier } else { $new_name = str_replace(extension_fichier(basename($filename)), "pdf", basename($filename)); } $new_path = dirname($filename) . "/" . $new_name; exec("curl http://localhost:8080/converter/converted/" . $new_name . " -F \"inputDocument=@{$filename}\" > " . $new_path); //Ne doit marcher que dans un cas très précis, pas vrai Arnaud $metas = extract_metas($new_path, "application/pdf", true); break; } break; } if ($tmp) { unlink($filename); } return $metas; }
/** * @param $name : file name * @param $filename : file name with path * @return Array : le tableau des métadonnées du fichier */ static function getMetadata($filename, $name) { \create_tableau_mimetype(); $mimetype = \trouve_mimetype($filename, extension_fichier($name)); if ($mimetype == "application/epub+zip") { //récupération de l'image $epub = new \epubData(realpath($filename)); //TODO : Vérifier la récupération des métadonnées d'un epub avec \extract_metas(), sinon rétablir les commentaires ici et le else plus bas // $tmp=array(); // $tmp=$epub->metas; // foreach($tmp as $key=>$val){ // $metas[strtoupper(substr($key,0,1)).substr($key,1)]=$val; // } $img = imagecreatefromstring($epub->getCoverContent()); $file = tempnam(sys_get_temp_dir(), "vign"); imagepng($img, $file); $entry['thumbnail_url'] = 'data:image/png;base64,' . base64_encode(file_get_contents($file)); unlink($file); } // else{ return \extract_metas(realpath($filename), $mimetype); // } }
function get_notice_by_meta($name, $filename) { global $pmb_keyword_sep; global $pmb_type_audit; global $webdav_current_user_name, $webdav_current_user_id; \create_tableau_mimetype(); $mimetype = \trouve_mimetype($filename, extension_fichier($name)); $notice_id = 0; $title = $cplt = $code = $pages = $year = $keywords = $url = $thumbnail_content = ""; //on commence avec la gymnatisque des métas... if ($mimetype == "application/epub+zip") { //pour les ebook, on gère ca directement ici ! $epub = new \epubData(realpath($filename)); $title = $epub->metas['title'][0]; $authors = $epub->metas['creator']; $co_authors = $epub->metas['contributor']; if ($epub->metas['identifier']['isbn']) { $code = \formatISBN($epub->metas['identifier']['isbn'], 13); } else { if ($epub->metas['identifier']['ean']) { $code = \EANtoISBN($epub->metas['identifier']['ean']); $code = \formatISBN($code, 13); } } if ($epub->metas['identifier']['uri']) { $url = \clean_string($epub->metas['identifier']['uri']); } $publisher = $epub->metas['publisher'][0]; $year = $epub->metas['date'][0]['value']; if (strlen($year) && strlen($year) != 4) { $year = \formatdate(detectFormatDate($year)); } $lang = $epub->metas['language']; $resume = implode("\n", $epub->metas['description']); $keywords = implode($pmb_keyword_sep, $epub->metas['subject']); //jouons à et si on trouvait a vignette... $img = imagecreatefromstring($epub->getCoverContent()); $file = tempnam(sys_get_temp_dir(), "vign"); imagepng($img, $file); $thumbnail_content = file_get_contents($file); unlink($file); } else { $metas = \extract_metas(realpath($filename), $mimetype); if ($metas['Title'] && $metas['Author'] && $metas['Subject']) { $title = $metas['Title']; $author = $metas['Author']; $cplt = $metas['Subject']; } else { // métas non fiable, on regarde avec le titre... $title = $name; } //date de création... if ($metas["CreateDate"]) { $year = substr($metas["CreateDate"], 0, 4); } //pages if ($metas['PageCount']) { $pages = $metas['PageCount']; } //keywords if ($metas['Keywords']) { foreach ($metas['Keywords'] as $keyword) { if ($keywords != "") { $keywords .= $pmb_keyword_sep; } $keywords .= $keyword; } } } $query = "select notice_id from notices where tit1 = '" . addslashes($title) . "'"; $result = mysql_query($query); if (mysql_num_rows($result)) { $notice_id = mysql_result($result, 0, 0); } if (!$notice_id) { //en cas d'une leture moyenne des infos, on s'assure d'avoir au moins un titre.... if (!$title) { $title = $name; } if ($publisher) { $ed_1 = \editeur::import(array('name' => $publisher)); } else { $ed_1 = 0; } $ind_wew = $title . " " . $cplt; $ind_sew = \strip_empty_words($ind_wew); $query = "insert into notices set \n\t\t\t\ttit1 = '" . addslashes($title) . "'," . ($code ? "code='" . $code . "'," : "") . "ed1_id = '" . $ed_1 . "'," . ($cplt ? "tit4 = '" . addslashes($cplt) . "'," : "") . ($pages ? "npages = '" . addslashes($pages) . "'," : "") . ($keywords ? "index_l = '" . addslashes($keywords) . "'," : "") . "\n\t\t\t\tyear = '" . $year . "',\n\t\t\t\tniveau_biblio='m', \n\t\t\t\tniveau_hierar='0',\n\t\t\t\tstatut = '" . $this->config['default_statut'] . "',\n\t\t\t\tindex_wew = '" . $ind_wew . "',\n\t\t\t\tindex_sew = '" . $ind_sew . "',\n\t\t\t\tn_resume = '" . addslashes($resume) . "',\n\t\t\t\tlien = '" . addslashes($url) . "',\n\t\t\t\tindex_n_resume = '" . \strip_empty_words($resume) . "'," . ($thumbnail_content ? "thumbnail_url = 'data:image/png;base64," . base64_encode($thumbnail_content) . "'," : "") . "create_date = sysdate(), \n\t\t\t\tupdate_date = sysdate()"; mysql_query($query); $notice_id = mysql_insert_id(); $sign = new \notice_doublon(); mysql_query("update notices set signature = '" . $sign->gen_signature($notice_id) . "' where notice_id = " . $notice_id); //traitement audit if ($pmb_type_audit) { $query = "INSERT INTO audit SET "; $query .= "type_obj='1', "; $query .= "object_id='{$notice_id}', "; $query .= "user_id='{$webdav_current_user_id}', "; $query .= "user_name='{$webdav_current_user_name}', "; $query .= "type_modif=1 "; $result = @mysql_query($query); } if (count($authors)) { $i = 0; foreach ($authors as $author) { $aut = array(); if ($author['file-as']) { $infos = explode(",", $author['file-as']); $aut = array('name' => $infos[0], 'rejete' => $infos[1], 'type' => 70); } if (!$aut['name']) { $aut = array('name' => $author['value'], 'type' => 70); } $aut_id = \auteur::import($aut); if ($aut_id) { $query = "insert into responsability set \n\t\t\t\t\t\t\tresponsability_author = '" . $aut_id . "',\n\t\t\t\t\t\t\tresponsability_notice = '" . $notice_id . "',\n\t\t\t\t\t\t\tresponsability_type = '0'"; mysql_query($query); $i++; } } } if (count($co_authors)) { foreach ($co_authors as $author) { $aut = array(); if ($author['file-as']) { $infos = explode(",", $author['file-as']); $aut = array('name' => $infos[0], 'rejete' => $infos[1], 'type' => 70); } if (!$aut['name']) { $aut = array('name' => $author['value'], 'type' => 70); } $aut_id = \auteur::import($aut); if ($aut_id) { $query = "insert into responsability set \n\t\t\t\t\t\t\tresponsability_author = '" . $aut_id . "',\n\t\t\t\t\t\t\tresponsability_notice = '" . $notice_id . "',\n\t\t\t\t\t\t\tresponsability_type = '0',\n\t\t\t\t\t\t\trepsonsability_ordre = '" . $i . "'"; mysql_query($query); $i++; } } } } return $notice_id; }