Browse Source

gestion auto des services avec plusieurs paramètres

pull/19/head
Chancellier Pierre-Jean 9 months ago
parent
commit
23cc8facc7
  1. 2
      action/tarteaucitron_installer_service.php
  2. 15
      formulaires/configurer_tarteaucitron_services.php
  3. 43
      inc/tarteaucitron.php
  4. 30
      tarteaucitron_administrations.php

2
action/tarteaucitron_installer_service.php

@ -58,7 +58,7 @@ function action_tarteaucitron_installer_service_dist(){
$services_installes = lire_config("tarteaucitron/services_installes/");
if (!$services_installes[$service]) {
$services_installes[$service] = ($code['hasKey']) ? "haskey" : "nokey";
$services_installes[$service] = $code['params'];
}
ecrire_config("tarteaucitron/services_installes/", $services_installes);

15
formulaires/configurer_tarteaucitron_services.php

@ -17,9 +17,7 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
)
);
foreach($liste_services as $service => $hasKey) {
foreach($liste_services as $service => $params) {
$champ = array(
'saisie' => 'checkbox',
'options' => array(
@ -32,18 +30,19 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
$fieldset['saisies'][] = $champ;
if ($hasKey) {
foreach($params as $param) {
$fieldset['saisies'][] = array(
'saisie' => 'input',
'options' => array(
'nom' => $service . 'key',
'label' => $service . ' APIkey',
'explication' => 'Enter your API Key',
'placeholder' => 'YOUR_ID',
'nom' => $service . '_' . $param,
'label' => $service . '_' . $param,
'explication' => 'Enter your parameter',
'placeholder' => $param,
'afficher_si' => '@' . $service . '@ == "' . $service . '"'
)
);
}
}
$saisies[] = $fieldset;

43
inc/tarteaucitron.php

@ -78,7 +78,7 @@ function tarteaucitron_liste_services() {
$list_services[$service] = array(
'type' => $type,
'statut' => $statut,
'hasKey' => ($services_installes[$service] == 'haskey')
'params' => $services_installes[$service]
);
}
$i++;
@ -100,7 +100,7 @@ function tarteaucitron_liste_types_installes() {
foreach($services as $service => $prop) {
if ($prop['statut']=='installe') {
$list_types[$prop['type']][$service] = $prop['hasKey'];
$list_types[$prop['type']][$service] = $prop['params'];
}
}
@ -126,34 +126,42 @@ function tarteaucitron_scrap_service($service) {
$html = file_get_contents($tarteaucitron_url);
$ret['JS'] = '';
$ret['html'] = '';
$ret['params'] = array();
$doc = new DOMDocument('1.0', 'UTF-8');
$internalErrors = libxml_use_internal_errors(true);
$doc->loadHTML($html);
libxml_use_internal_errors($internalErrors);
$elem = $doc->getElementById('s_' . $service);
$id = $elem->lastChild->attributes['id']->value;
$elem = $doc->getElementById('m' . $id);
$span_elements = $elem->getElementsByTagName('span');
$div_service = $doc->getElementById('s_' . $service);
$id = $div_service->lastChild->attributes['id']->value;
$div_code = $doc->getElementById('m' . $id);
$span_list = $div_code->getElementsByTagName('span');
$is_code_js_found = false;
$nb_items = $span_elements->length;
$nb_items = $span_list->length;
for($i=0; $i<$nb_items; $i++) {
$child = $span_elements->item($i);
$attributes = $child->attributes;
$span = $span_list->item($i);
$attributes = $span->attributes;
foreach($attributes as $attr_name => $attr) {
if ($attr_name == "class" && $attr->value == "code" && !$is_code_js_found) {
$b = $child->getElementsByTagName('b');
if ($b->length != 0) {
$newelement = $doc->createTextNode("'#CONFIG{tarteaucitron/services/" . $service . "key}'");
$child->replaceChild($newelement,$b[0]);
$ret['hasKey'] = true;
$param_list = $span->getElementsByTagName('b');
$j = $param_list->length -1;
while ($j > -1) {
$param = $param_list[$j];
$nom_param = str_replace(" ","_",$param->textContent);
$newelement = $doc->createTextNode("'#CONFIG{tarteaucitron/services/" . $service . "_" . $nom_param . "}'");
$span->replaceChild($newelement,$param);
$ret['params'][] = $nom_param;
$j--;
}
$s = $child->getElementsByTagName('s');
$child->removeChild($s[0]);
$script = trim(strip_tags($child->nodeValue));
$s = $span->getElementsByTagName('s');
$span->removeChild($s[0]);
$script = trim(strip_tags($span->nodeValue));
$script = preg_replace('/(\n\s+)/', "\n", $script);
$script = str_replace("''","'",$script);
$ret['JS'] = $script;
@ -165,7 +173,6 @@ function tarteaucitron_scrap_service($service) {
// TODO : récupérer le HTML pour le modèle
$ret['html'] = "<p>Placez votre code HTML</p>";
return $ret;
}

30
tarteaucitron_administrations.php

@ -72,19 +72,19 @@ function maj_tarteaucitron_cfg() {
switch ($service) {
case "gtag" :
if (!empty($value)) {
$cfg['services']['gtagkey'] = $value;
$cfg['services']['gtag_UA-XXXXXXXX-X'] = $value;
$cfg['services']['gtag'] = array("gtag");
}
break;
case "gmap" :
if (!empty($value)) {
$cfg['services']['googlemapskey'] = $value;
$cfg['services']['googlemaps_API_KEY'] = $value;
$cfg['services']['googlemaps'] = array("googlemaps");
}
break;
case "fb_pixel" :
if (!empty($value)) {
$cfg['services']['facebookpixelkey'] = $value;
$cfg['services']['facebookpixel_YOUR-ID'] = $value;
$cfg['services']['facebookpixel'] = array("facebookpixel");
}
break;
@ -98,18 +98,18 @@ function maj_tarteaucitron_cfg() {
// TODO : ajouter Matomo
$cfg['services_installes'] = array(
'canalu' => 'nokey',
'dailymotion' => 'nokey',
'facebook' => 'nokey',
'facebookpixel' => 'haskey',
'gagenda' => 'nokey',
'googlemaps' => 'haskey',
'gtag' => 'haskey',
'twitter' => 'nokey',
'twitterembed' => 'nokey',
'vimeo' => 'nokey',
'webtvnu' => 'nokey',
'youtube' => 'nokey'
'canalu' => array(),
'dailymotion' => array(),
'facebook' => array(),
'facebookpixel' => array('YOUR-ID'),
'gagenda' => array(),
'googlemaps' => array('API_KEY'),
'gtag' => array('UA-XXXXXXXX-X'),
'twitter' => array(),
'twitterembed' => array(),
'vimeo' => array(),
'webtvnu' => array(),
'youtube' => array()
);
ecrire_config('tarteaucitron',$cfg);

Loading…
Cancel
Save