27 changed files with 331 additions and 363 deletions
@ -0,0 +1,53 @@
|
||||
<?php |
||||
/** |
||||
* Plugin TarteAuCitron |
||||
* Licence GPL3 |
||||
* |
||||
*/ |
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')){ |
||||
return; |
||||
} |
||||
|
||||
/** |
||||
* Active un service |
||||
* appelé avec ?action=tarteaucitron_activer_service&service=service |
||||
* autorisé pour les seuls webmestres |
||||
*/ |
||||
function action_tarteaucitron_activer_service_dist(){ |
||||
include_spip('inc/autoriser'); |
||||
|
||||
if (!autoriser('webmestre')){ |
||||
die('Pas autorise'); |
||||
} |
||||
|
||||
include_spip('inc/tarteaucitron'); |
||||
|
||||
$service = _request('service'); |
||||
$list_services = tarteaucitron_liste_services(); |
||||
|
||||
if (!array_key_exists($service,$list_services)) { |
||||
die('Service inexistant'); |
||||
} |
||||
|
||||
if ($list_services[$service]['statut']=='actif') { |
||||
die('Service déjà actif'); |
||||
} |
||||
|
||||
include_spip('inc/config'); |
||||
|
||||
$services_actifs = lire_config("tarteaucitron/services"); |
||||
$services_actifs[$service] = array(); |
||||
|
||||
// TODO : récupérer les params dans le fichier JSON |
||||
$json_source = find_in_path('json/services.json'); |
||||
$json = file_get_contents($json_source); |
||||
$parsed_json = json_decode($json); |
||||
$params = $parsed_json->{$service}->{'params'}; |
||||
|
||||
foreach($params as $param) { |
||||
$services_actifs[$service][$param] = $param; |
||||
} |
||||
|
||||
ecrire_config("tarteaucitron/services/", $services_actifs); |
||||
} |
@ -0,0 +1,45 @@
|
||||
<?php |
||||
/** |
||||
* Plugin TarteAuCitron |
||||
* Licence GPL3 |
||||
* |
||||
*/ |
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')){ |
||||
return; |
||||
} |
||||
|
||||
/** |
||||
* Désactive un service |
||||
* appelé avec ?action=tarteaucitron_desactiver_service&service=service |
||||
* autorisé pour les seuls webmestres |
||||
*/ |
||||
function action_tarteaucitron_desactiver_service_dist(){ |
||||
include_spip('inc/autoriser'); |
||||
|
||||
if (!autoriser('webmestre')){ |
||||
die('Pas autorise'); |
||||
} |
||||
|
||||
include_spip('inc/tarteaucitron'); |
||||
|
||||
$service = _request('service'); |
||||
$list_services = tarteaucitron_liste_services(); |
||||
|
||||
if (!array_key_exists($service,$list_services)) { |
||||
die('Service inexistant'); |
||||
} |
||||
|
||||
if ($list_services[$service]['statut']=='inactif') { |
||||
die('Service déjà inactif'); |
||||
} |
||||
|
||||
include_spip('inc/config'); |
||||
$services_actifs = lire_config("tarteaucitron/services"); |
||||
|
||||
if ($services_actifs[$service]) { |
||||
unset($services_actifs[$service]); |
||||
} |
||||
|
||||
ecrire_config("tarteaucitron/services", $services_actifs); |
||||
} |
@ -1,73 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* Plugin TarteAuCitron |
||||
* Licence GPL3 |
||||
* |
||||
*/ |
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')){ |
||||
return; |
||||
} |
||||
|
||||
/** |
||||
* Désinstalle un service |
||||
* appelé avec ?action=tarteaucitron_desinstaller_service&service=service |
||||
* autorisé pour les seuls webmestres |
||||
*/ |
||||
function action_tarteaucitron_desinstaller_service_dist(){ |
||||
include_spip('inc/tarteaucitron'); |
||||
include_spip('inc/autoriser'); |
||||
|
||||
if (!autoriser('webmestre')){ |
||||
die('Pas autorise'); |
||||
} |
||||
|
||||
$service = _request('service'); |
||||
$list_services = tarteaucitron_liste_services(); |
||||
|
||||
if (!array_key_exists($service,$list_services)) { |
||||
die('Service inexistant'); |
||||
} |
||||
|
||||
if ($list_services[$service]['statut']=='desinstalle') { |
||||
die('Service déjà désinstallé'); |
||||
} |
||||
|
||||
$services_folder = _DIR_PLUGIN_TARTEAUCITRON . "services/"; |
||||
$modeles_folder = _DIR_PLUGIN_TARTEAUCITRON . "modeles/"; |
||||
|
||||
// $squelettes_folder = tarteaucitron_dossier_squelettes(); |
||||
// $services_folder = $squelettes_folder . "services/"; |
||||
// $modeles_folder = $squelettes_folder . "modeles/"; |
||||
// $icones_folder = $squelettes_folder . "icones_barre/"; |
||||
|
||||
$file = $services_folder . $service . ".html"; |
||||
if (file_exists($file)) { |
||||
unlink($file); |
||||
} |
||||
|
||||
$file = $modeles_folder . "tac_" . $service . ".html"; |
||||
if (file_exists($file)) { |
||||
unlink($file); |
||||
} |
||||
|
||||
$file = $icones_folder . $service . ".png"; |
||||
if (file_exists($file)) { |
||||
unlink($file); |
||||
} |
||||
|
||||
include_spip('inc/config'); |
||||
$cfg = lire_config("tarteaucitron"); |
||||
|
||||
if ($cfg['services_installes'][$service]) { |
||||
unset($cfg['services_installes'][$service]); |
||||
} |
||||
|
||||
foreach($cfg['services'] as $service_option => $value) { |
||||
if (preg_match("#^" . $service . "_?#",$service_option)) { |
||||
unset($cfg['services'][$service_option]); |
||||
} |
||||
} |
||||
|
||||
ecrire_config("tarteaucitron", $cfg); |
||||
} |
@ -1,65 +0,0 @@
|
||||
<?php |
||||
/** |
||||
* Plugin TarteAuCitron |
||||
* Licence GPL3 |
||||
* |
||||
*/ |
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')){ |
||||
return; |
||||
} |
||||
|
||||
/** |
||||
* Installe un service |
||||
* appelé avec ?action=tarteaucitron_installer_service&service=service |
||||
* autorisé pour les seuls webmestres |
||||
*/ |
||||
function action_tarteaucitron_installer_service_dist(){ |
||||
include_spip('inc/tarteaucitron'); |
||||
include_spip('inc/autoriser'); |
||||
|
||||
if (!autoriser('webmestre')){ |
||||
die('Pas autorise'); |
||||
} |
||||
|
||||
$service = _request('service'); |
||||
$list_services = tarteaucitron_liste_services(); |
||||
|
||||
if (!array_key_exists($service,$list_services)) { |
||||
die('Service inexistant'); |
||||
} |
||||
|
||||
if ($list_services[$service]['statut']=='installe') { |
||||
die('Service déjà installé'); |
||||
} |
||||
|
||||
// $squelettes_folder = tarteaucitron_dossier_squelettes(); |
||||
// $services_folder = $squelettes_folder . "services/"; |
||||
// $modeles_folder = $squelettes_folder . "modeles/"; |
||||
|
||||
$services_folder = _DIR_PLUGIN_TARTEAUCITRON . "services/"; |
||||
$modeles_folder = _DIR_PLUGIN_TARTEAUCITRON . "modeles/"; |
||||
|
||||
// if (!is_dir($services_folder)) { |
||||
// mkdir($services_folder,0755); |
||||
// } |
||||
|
||||
// if (!is_dir($modeles_folder)) { |
||||
// mkdir($modeles_folder,0755); |
||||
// } |
||||
|
||||
$code = tarteaucitron_scrap_service($service); |
||||
file_put_contents($services_folder . $service . ".html", $code['JS']); |
||||
file_put_contents($modeles_folder . 'tac_' . $service . '.html', $code['html']); |
||||
|
||||
// TODO : créer un fichier icones_barre/monservice.png en 17px de côté avec le nom du service pour le porte-plume ? |
||||
|
||||
include_spip('inc/config'); |
||||
$services_installes = lire_config("tarteaucitron/services_installes/"); |
||||
|
||||
if (!$services_installes[$service]) { |
||||
$services_installes[$service] = $code['params']; |
||||
} |
||||
|
||||
ecrire_config("tarteaucitron/services_installes/", $services_installes); |
||||
} |
@ -0,0 +1,98 @@
|
||||
<?php |
||||
/** |
||||
* Plugin TarteAuCitron |
||||
* Licence GPL3 |
||||
* |
||||
*/ |
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')){ |
||||
return; |
||||
} |
||||
|
||||
/** |
||||
* Mise à jour du fichier services/services.html |
||||
* appelé avec ?action=tarteaucitron_referencer_services |
||||
* autorisé pour les seuls webmestres |
||||
*/ |
||||
function action_tarteaucitron_referencer_services_dist(){ |
||||
include_spip('inc/autoriser'); |
||||
if (!autoriser('webmestre')){ |
||||
die('Pas autorise'); |
||||
} |
||||
|
||||
$list_services = array(); |
||||
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]; |
||||
|
||||
$list_services[$service] = array(); |
||||
|
||||
if (preg_match('/"type": "(\w+)",/', $lines[$i+2], $matches)) { |
||||
$type = $matches[1]; |
||||
$list_services[$service]['type'] = $type; |
||||
} |
||||
} |
||||
$i++; |
||||
} |
||||
} |
||||
|
||||
$tarteaucitron_url = 'https://tarteaucitron.io/fr/install/'; |
||||
$html = file_get_contents($tarteaucitron_url); |
||||
$doc = new DOMDocument('1.0', 'UTF-8'); |
||||
$internalErrors = libxml_use_internal_errors(true); |
||||
$doc->loadHTML($html); |
||||
libxml_use_internal_errors($internalErrors); |
||||
|
||||
foreach($list_services as $service => $prop) { |
||||
$div_service = $doc->getElementById('s_' . $service); |
||||
|
||||
if (!empty($div_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_list->length; |
||||
|
||||
for($i=0; $i<$nb_items; $i++) { |
||||
$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) { |
||||
$param_list = $span->getElementsByTagName('b'); |
||||
$j = $param_list->length -1; |
||||
$list_services[$service]['params'] = array(); |
||||
|
||||
while ($j > -1) { |
||||
$param = $param_list[$j]; |
||||
$nom_param = str_replace(" ","_",$param->textContent); |
||||
$newelement = $doc->createTextNode("'" . $nom_param . "'"); |
||||
$span->replaceChild($newelement,$param); |
||||
array_unshift($list_services[$service]['params'],$nom_param); |
||||
$j--; |
||||
} |
||||
|
||||
$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); |
||||
$list_services[$service]['JS'] = $script; |
||||
$is_code_js_found = true; |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
unset($list_services[$service]); |
||||
} |
||||
} |
||||
|
||||
// Création du JSON avec les services, leur type, leur(s) paramètre(s) et le code JS associé |
||||
$file_json = find_in_path('json/services.json'); |
||||
file_put_contents($file_json, json_encode($list_services)); |
||||
|
||||
echo "Opération réussie !<br>"; |
||||
echo "Le fichier <b>" . $file_json . "</b> a été mis à jour."; |
||||
} |
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('canalu'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('dailymotion'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('facebook'); |
@ -1,3 +0,0 @@
|
||||
tarteaucitron.user.facebookpixelId = '[(#CONFIG{tarteaucitron/services/facebookpixelkey})]'; |
||||
tarteaucitron.user.facebookpixelMore = function () { /* add here your optionnal facebook pixel function */ }; |
||||
(tarteaucitron.job = tarteaucitron.job || []).push('facebookpixel'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('gagenda'); |
@ -1,2 +0,0 @@
|
||||
tarteaucitron.user.googlemapsKey = '#CONFIG{tarteaucitron/services/googlemapskey}'; |
||||
(tarteaucitron.job = tarteaucitron.job || []).push('googlemaps'); |
@ -1,3 +0,0 @@
|
||||
tarteaucitron.user.gtagUa = '[(#CONFIG{tarteaucitron/services/gtagkey})]'; |
||||
tarteaucitron.user.gtagMore = function () { /* add here your optionnal gtag() */ }; |
||||
(tarteaucitron.job = tarteaucitron.job || []).push('gtag'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('instagram'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('twitter'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('twitterembed'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('vimeo'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('webtvnu'); |
@ -1 +0,0 @@
|
||||
(tarteaucitron.job = tarteaucitron.job || []).push('youtube'); |
Loading…
Reference in new issue