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.
182 lines
5.2 KiB
182 lines
5.2 KiB
<?php |
|
/** |
|
* Utilisations de pipelines par Tarteaucitron |
|
* |
|
* @plugin Tarteaucitron |
|
* @copyright 2019 |
|
* @author Peetdu |
|
* @licence GNU/GPL |
|
* @package SPIP\Tarteaucitron\Pipelines |
|
*/ |
|
|
|
if (!defined('_ECRIRE_INC_VERSION')) { |
|
return; |
|
} |
|
|
|
include_spip('inc/tarteaucitron'); |
|
|
|
/** |
|
* Inserer tarteaucitron.js + le javascript contenant les paramètres venant de la config du plugin |
|
* |
|
* @pipeline insert_head |
|
* @pipeline recuperer_fond |
|
* |
|
* @param string $flux |
|
* Le contenu de la balise #INSERT_HEAD |
|
* @return mixed |
|
*/ |
|
function tarteaucitron_insert_head($flux) { |
|
if (tarteaucitron_actif()) { |
|
$css = generer_url_public('tarteaucitron_custom.css'); |
|
$flux.= "<link rel='stylesheet' href='" . $css . "' type='text/css' />"; |
|
|
|
$tarteaucitron = find_in_path('lib/tarteaucitron/tarteaucitron.js'); |
|
$tarteaucitron_config = recuperer_fond('javascript/tarteaucitron_config'); |
|
// Note importante : ici on ajoute un id à la déclaration du script pour que celui-ci ne soit pas compressé par le Compresseur de SPIP si ce dernier est activé. |
|
$flux .= "<script type='text/javascript' src='$tarteaucitron' id='tauc'></script>\n" |
|
."$tarteaucitron_config\n"; |
|
} |
|
return $flux; |
|
} |
|
|
|
/** |
|
* Inserer les JS correspondants aux services activés |
|
* |
|
* @pipeline affichage_final |
|
* |
|
* @param string $flux |
|
* @return mixed |
|
*/ |
|
function tarteaucitron_affichage_final($html) { |
|
if ($GLOBALS['html'] and !test_espace_prive() and tarteaucitron_actif()) { |
|
$ajouter_services = '<script type="text/javascript">'; |
|
$json_source = find_in_path('json/services.json'); |
|
$json = file_get_contents($json_source); |
|
$parsed_json = json_decode($json); |
|
$services_actifs = lire_config('tarteaucitron/services'); |
|
|
|
foreach($services_actifs as $service => $params) { |
|
$codejs = $parsed_json->{$service}->{'JS'}; |
|
|
|
if (is_array($params)) { |
|
foreach($params as $param => $value) { |
|
$codejs = preg_replace("#" . $param . "#",$value,$codejs); |
|
} |
|
} |
|
|
|
$ajouter_services .= $codejs . "\n"; |
|
|
|
} |
|
|
|
$ajouter_services .= '</script>'; |
|
|
|
$html = str_replace('</body>', $ajouter_services. '</body>', $html); |
|
} |
|
return $html; |
|
} |
|
|
|
/** |
|
* Ajouter des entrées dans le porte-plume |
|
* |
|
* @pipeline porte_plume_barre_pre_charger |
|
* |
|
* @param array $barres |
|
* @return array |
|
*/ |
|
function tarteaucitron_porte_plume_barre_pre_charger($barres){ |
|
$menu_items = array(); |
|
$services_actifs = lire_config('tarteaucitron/services', array()); |
|
$json_source = find_in_path('json/services.json'); |
|
$json = file_get_contents($json_source); |
|
$parsed_json = json_decode($json); |
|
$liste_modeles = scandir(_DIR_PLUGIN_TARTEAUCITRON . "modeles"); |
|
|
|
foreach ($services_actifs as $service => $params) { |
|
$params_modele = (!empty($parsed_json->{$service}->{'params_modele'})) ? $parsed_json->{$service}->{'params_modele'} : array(); |
|
|
|
foreach($liste_modeles as $nom_fichier) { |
|
$create_item = false; |
|
$close = ''; |
|
|
|
if (($nom_fichier == 'tac_' . $service . '.html') && (find_in_path('icones_barre/' . $service . '.png'))) { |
|
$nom_modele = $service; |
|
$create_item = true; |
|
|
|
foreach($params_modele as $param_modele) { |
|
$close .= '|' . $param_modele . '=[![' . $param_modele . ' :]!]'; |
|
} |
|
} elseif (strpos($nom_fichier,'tac_' . $service . '_') !== false) { |
|
$nom_modele = substr($nom_fichier,0, strpos($nom_fichier,'.html')); |
|
$nom_modele = substr($nom_modele,4, strlen($nom_modele)-4); |
|
|
|
if (find_in_path('icones_barre/' . $nom_modele . '.png')) { |
|
$create_item = true; |
|
|
|
foreach($params_modele->{$nom_modele} as $param_modele) { |
|
$close .= '|' . $param_modele . '=[![' . $param_modele . ' :]!]'; |
|
} |
|
} |
|
} |
|
|
|
if ($create_item) { |
|
$menu_items[] = array( |
|
"id" => $nom_modele, |
|
"name" => $nom_modele, |
|
"className" => 'tac_' . $nom_modele, |
|
"openWith" => "<tac_" . $nom_modele, |
|
'closeWith' => $close . '>', |
|
"display" => true |
|
); |
|
} |
|
} |
|
} |
|
|
|
if (count($menu_items) != 0) { |
|
$new_button = array( |
|
"id" => 'tac_drop', |
|
"name" => 'TarteAuCitron', |
|
"className" => 'tac_drop', |
|
"replaceWith" => '', |
|
"display" => true |
|
); |
|
|
|
$new_button["dropMenu"] = $menu_items; |
|
$barre = &$barres['edition']; |
|
$barre->ajouterApres('grpCaracteres', $new_button); |
|
} |
|
|
|
return $barres; |
|
} |
|
|
|
/** |
|
* Définir des images pour les classes CSS utilisées dans le porte-plume |
|
* |
|
* @pipeline porte_plume_lien_classe_vers_icone |
|
* |
|
* @param array $flux |
|
* @return array |
|
*/ |
|
function tarteaucitron_porte_plume_lien_classe_vers_icone($flux){ |
|
$icons = array('tac_drop' => 'tac.png'); |
|
$services_actifs = lire_config('tarteaucitron/services', array()); |
|
$liste_modeles = scandir(_DIR_PLUGIN_TARTEAUCITRON . "modeles"); |
|
|
|
foreach ($services_actifs as $service => $value) { |
|
foreach($liste_modeles as $nom_fichier) { |
|
$nom_modele = ""; |
|
|
|
if ($nom_fichier == 'tac_' . $service . '.html') { |
|
$nom_modele = $service; |
|
} elseif (strpos($nom_fichier,'tac_' . $service . '_') !== false) { |
|
$nom_modele = substr($nom_fichier,0, strpos($nom_fichier,'.html')); |
|
$nom_modele = substr($nom_modele,4, strlen($nom_modele)-4); |
|
} |
|
|
|
if (($nom_modele != "") && (find_in_path('icones_barre/' . $nom_modele . '.png'))) { |
|
$icons['tac_' . $nom_modele] = $nom_modele . '.png'; |
|
} |
|
} |
|
} |
|
|
|
return array_merge($flux, $icons); |
|
} |