Portage pour SPIP de la solution de gestion de consentement aux cookies Tarteaucitron.js
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

121 lines
2.5 KiB

<?php
/**
* Fonctions internes du plugin
*/
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
include_spip('inc/config');
/**
* Détecter si au moins un service est actif.
*
* @return boolean
*/
function tarteaucitron_actif() {
$actif = false;
$liste_services = lire_config('tarteaucitron/services', array());
foreach ($liste_services as $value) {
if (!empty($value)) {
$actif = true;
}
}
return $actif;
}
/**
* Récupérer les js correspondants aux services activés
*
* @return boolean | string
*/
function tarteaucitron_liste_services_actifs($objet, $id_objet, $page, $recherche, $resultat_page) {
$services_actifs = array_filter(lire_config('tarteaucitron/services', array()));
$ajouter_services = '';
foreach ($services_actifs as $service => $value) {
if (strpos($service, "key",strlen($service)-3) === false){
$ajouter_services .= recuperer_fond('services/'.$service,
array(
'objet' => $objet,
'id_objet' => $id_objet,
'page' => $page,
'recherche' => $recherche,
'resultat_page' => $resultat_page
)
);
}
}
return $ajouter_services;
}
/**
* Retourne la liste des services TarteAuCitron et leur statut (enabled,disabled)
*
* @return Array
*/
function tarteaucitron_liste_services() {
$services_installes = array_filter(lire_config('tarteaucitron/services_installes', array()));
$list_services = [];
if ($lines=file(find_in_path('lib/tarteaucitron/tarteaucitron.services.js'))){
$i=0;
foreach($lines as $line) {
if(preg_match('/^tarteaucitron\.services\.(\w+)/', $line, $matches)) {
$service = $matches[1];
$statut = in_array($service,$services_installes) ? 'installe' : 'desinstalle';
if (preg_match('/"type": "(\w+)",/', $lines[$i+2], $matches)) {
$type = $matches[1];
}
$list_services[$service] = array(
'type' => $type,
'statut' => $statut
);
}
$i++;
}
}
return $list_services;
}
/**
* Retourne la liste des types des services TarteAuCitron installés
*
* @return Array
*/
function tarteaucitron_liste_types_installes() {
$list_types = [];
$services = tarteaucitron_liste_services();
foreach($services as $service => $prop) {
if ($prop['statut']=='installe') {
$list_types[$prop['type']][] = $service;
}
}
return $list_types;
}
/**
* Retourne le dossier squelettes du site
*
* @return String
*/
function tarteaucitron_dossier_squelettes() {
// Traiter le cas des sites mutualises
$dir_racine = (defined('_DIR_SITE')) ? _DIR_SITE : _DIR_RACINE;
$dir_squelettes = $dir_racine . 'squelettes/';
return $dir_squelettes;
}