0) { $resultat .= '"'; } if (strpos($texte, 'dev-spip') > 0) { if (strlen($texte) > 0) { $resultat .= ', '; } $resultat .= 'dev-spip'; } if (strlen($resultat) > 0) { $resultat = 'Contient : '.$resultat; } return $resultat; } /****************************************************************************************** * Balises spécifiques au site * Toutes les balises commencent par LIBREASSO_ */ /** * Balise qui ne retourne rien mais qui initialise des paramètres, elle doit être placée * en début de squelette * elle récupère les informations sur l'élément principal (article ou rubrique appelé) * et applique ensuite la fonction libreasso_init */ function balise_LIBREASSO_INIT($p){ $_id_objet = $p->boucles[$p->id_boucle]->primary; $id_objet = champ_sql($_id_objet, $p); $objet = $p->boucles[$p->id_boucle]->id_table; $id_rubrique = champ_sql('id_rubrique',$p); $p->code = "libreasso_initGlobal('$objet', $id_objet, $id_rubrique)"; return $p; } /** * Balise qui renvoie le numéro d'identifiant de l'axe en cours (Comprendre, Discuter ou Agir). */ function balise_LIBREASSO_AXE($p){ $p->code = "\$GLOBALS['LIBREASSO']['AXE']" ; $p->interdire_scripts = false; return $p; } /** * Test si le numéro de la rubrique dans la boucle est celui de l'axe en cours */ function balise_LIBREASSO_EST_AXE($p){ $on = "' '"; $off= "''"; if (($v = interprete_argument_balise(1,$p))!==NULL){ $on = $v; if (($v = interprete_argument_balise(2,$p))!==NULL) { $off = $v; } } $_id_objet = $p->boucles[$p->id_boucle]->primary; $id_objet = champ_sql($_id_objet, $p); $objet = $p->boucles[$p->id_boucle]->id_table; $id_rubrique = champ_sql('id_rubrique',$p); $p->code = "libreasso_testEstAxe($id_rubrique, $on, $off)"; $p->interdire_scripts = false; return $p; } /** * Test s'il s'agit de l'élément principal de la page */ function balise_LIBREASSO_EST_ELEMENTPRINCIPAL($p) { $on = "' '"; $off= "''"; if (($v = interprete_argument_balise(1,$p))!==NULL){ $on = $v; if (($v = interprete_argument_balise(2,$p))!==NULL) { $off = $v; } } $_id_objet = $p->boucles[$p->id_boucle]->primary; $id_objet = champ_sql($_id_objet, $p); $objet = $p->boucles[$p->id_boucle]->id_table; $p->code = "libreasso_testEstElementPrincipal('$objet', $id_objet, $on, $off)"; return $p; } /** * Test s'il s'agit de la rubrique principale de la page */ function balise_LIBREASSO_EST_RUBRIQUEPRINCIPALE($p) { $on = "' '"; $off= "''"; if (($v = interprete_argument_balise(1,$p))!==NULL){ $on = $v; if (($v = interprete_argument_balise(2,$p))!==NULL) { $off = $v; } } $_id_objet = $p->boucles[$p->id_boucle]->primary; $id_objet = champ_sql($_id_objet, $p); $objet = $p->boucles[$p->id_boucle]->id_table; $p->code = "libreasso_testEstRubriquePrincipale('$objet', $id_objet, $on, $off)"; return $p; } /****************************************************************************************** * Formatage du geojson de l'agenda du libre */ function inc_agendajson_to_array($u) { $array = json_decode($u, true); $result = array(); $count = count($array); $nombre_evenements = 3; if ($count < $nombre_evenements) { $nombre_evenements = $count; } $a_faire = array(); for($i = 0; $i < $count; $i++) { $a_faire[] = $i; } date_default_timezone_set('Europe/Paris'); for($i = 0; $i < $nombre_evenements; $i++) { $random_i = rand(0, count($a_faire) -1); $index = $a_faire[$random_i]; $a_faire = libreasso_reduceArray($a_faire, $random_i); $feature = $array[$index]; $properties = $feature["properties"]; $objet = array("titre" => $properties["name"], "url" => "http://www.agendadulibre.org/events/".$properties["id"]); $datetime = DateTime::createFromFormat('Y-m-d\TH:i:s+', $properties["start_time"]); if(!$datetime) { $datetime = DateTime::createFromFormat('Y-m-d H:i:s+ \U\T\C', $properties["start_time"]); } if($datetime) { $objet["date"] = libreasso_getJour(date('j', $datetime->getTimestamp()))." ".libreasso_getMois(date('m', $datetime->getTimestamp())); $objet["start_time"] = $properties["start_time"]; $objet["ville"] = $properties["city"]; $result[] = $objet; } } return $result; } function libreasso_reduceArray($array, $index) { if ($index == (count($array) - 1)) { array_pop($array); return $array; } $result = array(); for($i = 0; $i < $index; $i++) { $result[] = $array[$i]; } for($i = $index + 1; $i < count($array); $i++) { $result[] = $array[$i]; } return $result; } function libreasso_getJour($jour) { if ($jour == '1') { return "1er"; } else { return $jour; } } function libreasso_getMois($mois) { switch($mois) { case "01": return "janvier"; case "02": return "février"; case "03": return "mars"; case "04": return "avril"; case "05": return "mai"; case "06": return "juin"; case "07": return "juillet"; case "08": return "août"; case "09": return "septembre"; case "10": return "octobre"; case "11": return "novembre"; case "12": return "décembre"; } return ""; } /****************************************************************************************** * Fonctions php spécifiques au site, elles commencent toutes par libreasso_ * Toutes les balises commencent par LIBREASSO_ */ /** * Initialisation de paramètres globaux utilisés par la suite */ function libreasso_initGlobal($objet, $id_objet, $id_rubrique){ $GLOBALS['LIBREASSO']['type_element_principal'] = objet_type($objet); //conserve le type de l'élément principal $GLOBALS['LIBREASSO']['id_element_principal'] = $id_objet; //conserve l'identifiant de l'élément principal $GLOBALS['LIBREASSO']['id_rubrique_principale'] = $id_rubrique; //conserve l'identifiant de la rubrique principale (si c'est une rubrique, il s'agit d'elle-même, si c'est un article, il s'agit de sa rubrique) $GLOBALS['LIBREASSO']['AXE'] = libreasso_initAxe($id_rubrique); //conserve l'identifiant de l'axe (les axex sont les sous-rubriques du secteur « tronc commun ») return ''; } /** * Récupération de l'axe en fonction de la rubrique * Appelée récursivement. */ function libreasso_initAxe($idrubrique) { $query = sql_select('id_parent, id_secteur', 'spip_rubriques', 'id_rubrique = '.$idrubrique); $row = sql_fetch($query); $idparent = $row[0]; $idsecteur = $row[1]; if ($idparent == $idsecteur) return $idrubrique; return libreasso_initAxe($idparent, $idsecteur); } /** * Retourne le numéro de la rubrique s'il s'agit de l'axe ou une chaine vide */ function libreasso_testEstAxe($id_rubrique, $on, $off) { if ($id_rubrique == $GLOBALS['LIBREASSO']['AXE']) { return $on; } else { return $off; } } /** * Test s'il s'agit de l'élément principal */ function libreasso_testEstElementPrincipal($objet, $id_objet, $on, $off){ $type = objet_type($objet); if ($GLOBALS['LIBREASSO']['type_element_principal'] != $type) { return $off; } if ($GLOBALS['LIBREASSO']['id_element_principal'] != $id_sobjet) { return $off; } return $on; } /** * Test s'il s'agit de l'élément principal */ function libreasso_testEstRubriquePrincipale($objet, $id_objet, $on, $off){ $type = objet_type($objet); if ($type != 'rubrique') { return $off; } if ($GLOBALS['LIBREASSO']['id_rubrique_principale'] != $id_objet) { return $off; } return $on; } ?>