2021-02-06 22:22:13 +01:00
|
|
|
<?php
|
|
|
|
if (!defined('_ECRIRE_INC_VERSION')) {
|
2021-05-11 22:18:36 +02:00
|
|
|
return;
|
2021-02-06 22:22:13 +01:00
|
|
|
}
|
|
|
|
|
2021-05-11 22:18:36 +02:00
|
|
|
function filtre_escape_json($texte) {
|
|
|
|
return str_replace("\"", "\\\"", str_replace("\n", "\\n", str_replace("\n\n", "\n<br><br>\n", $texte)));
|
|
|
|
}
|
|
|
|
|
|
|
|
function filtre_decode_html($texte) {
|
|
|
|
return html_entity_decode($texte);
|
|
|
|
}
|
|
|
|
|
2021-05-28 10:25:45 +02:00
|
|
|
function filtre_libreavous_supp_numero($texte) {
|
2021-05-11 22:18:36 +02:00
|
|
|
$idx = strpos($texte, "-");
|
|
|
|
return trim(substr($texte, $idx +1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-21 10:00:24 +02:00
|
|
|
// plutot utiliser la fonction spip taille_en_octets
|
|
|
|
function libreavous_mio($number) {
|
|
|
|
$mio = round($number / (1024 * 1024), 1);
|
|
|
|
if ($mio < 10) {
|
|
|
|
$mio = round($mio, 2);
|
|
|
|
return number_format($mio, 2, ',', ' ');
|
|
|
|
} else if ($mio < 100) {
|
|
|
|
$mio = round($mio, 1);
|
|
|
|
return number_format($mio, 1, ',', ' ');
|
|
|
|
} else {
|
|
|
|
$mio = round($mio, 0);
|
|
|
|
return number_format($mio, 0, ',', ' ');
|
|
|
|
}
|
|
|
|
return $mio;
|
|
|
|
}
|
|
|
|
|
2021-09-02 20:04:44 +02:00
|
|
|
function titre_chronique_court($titre) {
|
2021-09-15 16:16:10 +02:00
|
|
|
// annuler le filtre
|
|
|
|
return $titre;
|
2021-09-02 20:04:44 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 00:40:12 +02:00
|
|
|
// calculer la durée d'un chapitre
|
|
|
|
// $start et $end sous form hh:mm:ss
|
2021-10-05 18:19:43 +02:00
|
|
|
function libreavous_duree($start,$end) {
|
2021-09-24 00:40:12 +02:00
|
|
|
|
|
|
|
$timestart = new DateTime($start);
|
|
|
|
$timeend = new DateTime($end);
|
|
|
|
$timeduree = $timestart->diff($timeend);
|
|
|
|
$duree = $timeduree->format('%h h %i min. %s s.');
|
2023-03-01 19:36:29 +01:00
|
|
|
|
2021-09-24 00:40:12 +02:00
|
|
|
return $duree;
|
|
|
|
|
2021-11-07 21:38:12 +01:00
|
|
|
}
|
|
|
|
// calculer la durée d'un chapitre
|
|
|
|
// $start et $end sous form hh:mm:ss
|
|
|
|
// renvoi dans un format hh:mm:ss (pour le champ itunes:duration
|
|
|
|
function libreavous_duree_podcast($start,$end) {
|
|
|
|
|
|
|
|
$timestart = new DateTime($start);
|
|
|
|
$timeend = new DateTime($end);
|
|
|
|
$timeduree = $timestart->diff($timeend);
|
|
|
|
$duree = $timeduree->format('%H:%I:%S');
|
2023-03-01 19:36:29 +01:00
|
|
|
|
2021-11-07 21:38:12 +01:00
|
|
|
return $duree;
|
|
|
|
|
2021-09-24 00:40:12 +02:00
|
|
|
}
|
2021-11-08 09:37:23 +01:00
|
|
|
// retirer les microseconds d'une durée
|
|
|
|
function libreavous_remove_microseconds ($duration) {
|
|
|
|
|
|
|
|
$durationobject = new DateTime($duration);
|
|
|
|
$newduration = $durationobject->format('H:i:s');
|
|
|
|
|
|
|
|
return $newduration;
|
|
|
|
}
|
2021-09-24 00:40:12 +02:00
|
|
|
// retirer l'heure si 0 h dans la duree
|
2021-10-05 18:19:43 +02:00
|
|
|
function libreavous_sanszeroh($chaine) {
|
2021-09-24 00:40:12 +02:00
|
|
|
$chaine = str_replace('0 h ','',$chaine);
|
|
|
|
return $chaine;
|
|
|
|
}
|
2021-10-05 18:19:43 +02:00
|
|
|
// ajoute un 0 si un seul chiffre (date du jour < à 10)
|
|
|
|
function libreavous_aveczerod($chaine) {
|
2021-10-12 17:06:22 +02:00
|
|
|
$chaineaveczero = $chaine;
|
2021-10-05 18:19:43 +02:00
|
|
|
if (strlen($chaine) == '1') {
|
|
|
|
$chaineaveczero = '0'.$chaine;
|
|
|
|
}
|
2022-02-01 17:14:13 +01:00
|
|
|
if ($chaine == '1er') {
|
|
|
|
$chaineaveczero = '01';
|
|
|
|
}
|
2021-10-05 18:19:43 +02:00
|
|
|
return $chaineaveczero;
|
|
|
|
}
|
2022-10-01 00:18:32 +02:00
|
|
|
|
2023-03-01 19:36:29 +01:00
|
|
|
// renvoie $chaine seulement si $chaine commence par http
|
|
|
|
function libreavous_sihttp($chaine) {
|
|
|
|
if (preg_match('/media.april.org/',$chaine)) {
|
|
|
|
return $chaine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// renvoie $chaine seulement si $chaine commence par #EXTINF
|
|
|
|
// et retire le debut indesirable
|
|
|
|
function libreavous_siextinf($chaine) {
|
|
|
|
if (preg_match('/^#EXTINF/',$chaine)) {
|
|
|
|
$pattern = '/^#EXTINF(.*),/';
|
|
|
|
$replace = preg_replace($pattern, '', $chaine);
|
|
|
|
return $replace;
|
|
|
|
}
|
2022-10-01 00:18:32 +02:00
|
|
|
}
|