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-05-28 10:25:45 +02:00
|
|
|
function balise_LIBREAVOUS_IMPORT($p) {
|
2021-05-11 22:18:36 +02:00
|
|
|
$id_rubrique = "''";
|
|
|
|
$id_secteur = "''";
|
|
|
|
if (($v = interprete_argument_balise(1,$p))!==NULL){
|
|
|
|
$id_rubrique = $v;
|
|
|
|
if (($v = interprete_argument_balise(2,$p))!==NULL) {
|
|
|
|
$id_secteur = $v;
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 10:25:45 +02:00
|
|
|
$p->code = "libreavous_Import()";
|
2021-05-11 22:18:36 +02:00
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
2021-05-28 10:25:45 +02:00
|
|
|
function libreavous_Import_Historique() {
|
2021-05-11 22:18:36 +02:00
|
|
|
$historique = simplexml_load_file ("/var/www/exemole.fr/libreavous/historique.xml");
|
|
|
|
foreach ($historique->item as $item) {
|
|
|
|
$code = $item['code'];
|
|
|
|
$array = array(
|
|
|
|
'drupal_guid' => $item['guid'],
|
|
|
|
'drupal_pubdate' => $item['pubdate']
|
|
|
|
);
|
|
|
|
$type = $item['type'];
|
|
|
|
if ($type == 'emission') {
|
|
|
|
$existant = sql_select("id_article","spip_articles","podcast_code=".sql_quote($code));
|
|
|
|
if ($existant and sql_count($existant)>0) {
|
|
|
|
$r = sql_fetch($existant);
|
|
|
|
$id_article = $r["id_article"];
|
|
|
|
sql_updateq("spip_articles", $array, "id_article=".$id_article);
|
|
|
|
} else {
|
|
|
|
echo "Émission inconnue = $code<br>" ;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$chapitreExistant = sql_select("id_chapitre","spip_chapitres",array("code_podcast=".sql_quote($code), "code_fichier=".sql_quote($item['chapitre'])));
|
|
|
|
if ($chapitreExistant and sql_count($chapitreExistant)>0) {
|
|
|
|
$r = sql_fetch($chapitreExistant);
|
|
|
|
$id_chapitre = $r["id_chapitre"];
|
|
|
|
sql_updateq("spip_chapitres", $array, "id_chapitre=".$id_chapitre);
|
|
|
|
} else {
|
|
|
|
echo "Chapitre inconnu = $code / fichier = ".$item['chapitre']."<br>" ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 10:25:45 +02:00
|
|
|
function libreavous_Import($id_rubrique, $id_secteur) {
|
2021-05-11 22:18:36 +02:00
|
|
|
$emissions = simplexml_load_file ("/var/www/exemole.fr/libreavous/verspip.xml");
|
|
|
|
foreach ($emissions->emission as $emission) {
|
|
|
|
$code = $emission["code"];
|
|
|
|
$emissionArray = array(
|
|
|
|
'lang' => 'fr',
|
|
|
|
'surtitre' => $emission["numero"],
|
|
|
|
'titre' => $emission["numero"].' - '.$emission["titre"],
|
|
|
|
'soustitre' => "",
|
|
|
|
'id_rubrique' => $id_rubrique,
|
|
|
|
'id_secteur' => $id_secteur,
|
|
|
|
'descriptif' => $emission["description"],
|
|
|
|
'chapo' => $emission["programme"],
|
|
|
|
'texte' => $emission["references"],
|
|
|
|
'ps' => "",
|
|
|
|
'statut' => 'publie',
|
|
|
|
'accepter_forum' => 'non',
|
2021-05-28 10:25:45 +02:00
|
|
|
'date' => libreavous_toDateIso($emission["code"]),
|
2021-05-11 22:18:36 +02:00
|
|
|
'podcast_code' => $emission["code"],
|
|
|
|
'podcast_duree' => $emission["duree"],
|
|
|
|
'podcast_mp3' => $emission["mp3"],
|
|
|
|
'podcast_ogg' => $emission["ogg"],
|
|
|
|
'podcast_transcription' => $emission["transcription"],
|
|
|
|
'podcast_personnes' => $emission["personnes"],
|
|
|
|
'podcast_galeriephotos' => $emission["galeriephotos"],
|
|
|
|
'podcast_musique' => $emission["musique"]
|
|
|
|
);
|
|
|
|
$existant = sql_select("id_article","spip_articles","podcast_code=".sql_quote($code));
|
|
|
|
if ($existant and sql_count($existant)>0) {
|
|
|
|
$r = sql_fetch($existant);
|
|
|
|
$id_article = $r["id_article"];
|
|
|
|
sql_updateq("spip_articles", $emissionArray, "id_article=".$id_article);
|
|
|
|
} else {
|
|
|
|
$id_article = sql_insertq("spip_articles", $emissionArray);
|
|
|
|
}
|
|
|
|
foreach ($emission->chapitre as $chapitre) {
|
|
|
|
$code_chapitre = $chapitre["code"];
|
|
|
|
$chapitreArray = array(
|
|
|
|
'titre' => $chapitre["titre"],
|
|
|
|
'code' => $chapitre["code"],
|
|
|
|
'id_article' => $id_article,
|
|
|
|
'code_fichier' => $chapitre["fichier"],
|
|
|
|
'code_podcast' => $emission["code"],
|
|
|
|
'debut' => $chapitre["debut"],
|
|
|
|
'fin' => $chapitre["fin"],
|
|
|
|
'type_sujet' => $chapitre["type"],
|
|
|
|
'chronique' => $chapitre["chronique"],
|
|
|
|
'mp3' => $chapitre["mp3"],
|
|
|
|
'ogg' => $chapitre["ogg"],
|
|
|
|
'references_sujet' => $chapitre["references"]
|
|
|
|
);
|
|
|
|
$chapitreExistant = sql_select("id_chapitre","spip_chapitres",array("id_article=".$id_article, "code=".sql_quote($code_chapitre)));
|
|
|
|
if ($chapitreExistant and sql_count($chapitreExistant)>0) {
|
|
|
|
$r = sql_fetch($chapitreExistant);
|
|
|
|
$id_chapitre = $r["id_chapitre"];
|
|
|
|
sql_updateq("spip_chapitres", $chapitreArray, "id_chapitre=".$id_chapitre);
|
|
|
|
} else {
|
|
|
|
$id_nouveau_chapitre = sql_insertq("spip_chapitres", $chapitreArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 10:25:45 +02:00
|
|
|
function libreavous_toDateIso($code) {
|
2021-05-11 22:18:36 +02:00
|
|
|
$texte = substr($code, 0, 4)."-".substr($code,4,2)."-".substr($code,6,2)." 15:30:00";
|
|
|
|
return $texte;
|
|
|
|
}
|
|
|
|
|
2021-06-21 10:00:24 +02:00
|
|
|
function libreavous_conversionDrupal($shortdate) {
|
2021-05-11 22:18:36 +02:00
|
|
|
$annee = substr($shortdate, 0, 4);
|
|
|
|
$mois = substr($shortdate, 4, 2);
|
|
|
|
$jour = substr($shortdate, 6, 2);
|
|
|
|
if (substr($jour, 0, 1) == "0") {
|
|
|
|
$jour = substr($jour, 1, 1);
|
|
|
|
}
|
2021-05-28 10:25:45 +02:00
|
|
|
return $jour."-".libreavous_conversionMoisDrupal($mois)."-".$annee;
|
2021-05-11 22:18:36 +02:00
|
|
|
}
|
|
|
|
|
2021-05-28 10:25:45 +02:00
|
|
|
function libreavous_conversionMoisDrupal($mois) {
|
2021-05-11 22:18:36 +02:00
|
|
|
switch($mois) {
|
|
|
|
case "01":
|
|
|
|
return "janvier";
|
|
|
|
case "02":
|
|
|
|
return "fevrier";
|
|
|
|
case "03":
|
|
|
|
return "mars";
|
|
|
|
case "04":
|
|
|
|
return "avril";
|
|
|
|
case "05":
|
|
|
|
return "mai";
|
|
|
|
case "06":
|
|
|
|
return "juin";
|
|
|
|
case "07":
|
|
|
|
return "juillet";
|
|
|
|
case "08":
|
|
|
|
return "aout";
|
|
|
|
case "09":
|
|
|
|
return "septembre";
|
|
|
|
case "10":
|
|
|
|
return "octobre";
|
|
|
|
case "11":
|
|
|
|
return "novembre";
|
|
|
|
case "12":
|
|
|
|
return "decembre";
|
|
|
|
default:
|
|
|
|
return "XX";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 10:25:45 +02:00
|
|
|
function libreavous_nomtypesujet($abbr) {
|
|
|
|
switch($abbr) {
|
|
|
|
case "CH":
|
|
|
|
return "Chronique";
|
|
|
|
case "SL":
|
|
|
|
return "Sujet libre";
|
|
|
|
case "AN":
|
|
|
|
return "Annonce";
|
|
|
|
default:
|
|
|
|
return $abbr;
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 22:18:36 +02:00
|
|
|
|
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.');
|
|
|
|
|
|
|
|
return $duree;
|
|
|
|
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
return $chaineaveczero;
|
|
|
|
}
|
|
|
|
|