[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins / odt2spip_32 / inc / convertir_avec_libreoffice.php
1 <?php
2
3 /**
4 * Convertit un fichier en utilisant l’application libreoffice.
5 *
6 * @note : nécessite que libreoffice soit installée sur le serveur.
7 */
8
9 if (!defined('_ECRIRE_INC_VERSION')) {
10 return;
11 }
12
13
14 /**
15 * Convertit un document transmis dans le format spécifié.
16 *
17 * @param string $fichier (chemin)
18 * @param string $format_destination
19 * @return bool|string
20 */
21 function convertir_avec_libreoffice($fichier, $format_destination = 'odt') {
22 if (!file_exists($fichier) or !is_readable($fichier)) {
23 return false;
24 }
25
26 include_spip('inc/libreoffice');
27 $destination = odt2spip_get_repertoire_temporaire();
28
29 try {
30 $libreoffice = (new LibreOffice($fichier))
31 ->setConvertTo($format_destination)
32 ->setOutputDir($destination)
33 ->execute();
34 } catch (\Exception $e) {
35 spip_log($e->getMessage(), 'odtspip.' . _LOG_ERREUR);
36 return false;
37 }
38
39 if ($libreoffice->getErrors()) {
40 return false;
41 }
42
43 return $libreoffice->getConvertedFile();
44 }