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.4 KiB

<?php
if (!defined('_ECRIRE_INC_VERSION')) {
6 years ago
return;
}
6 years ago
function inserer_modeles_header_prive($flux) {
$js = find_in_path('javascript/autosize.min.js');
$flux .= "\n<script type='text/javascript' src='$js'></script>\n";
return $flux;
}
function inserer_modeles_insert_head($flux){
if(lire_config('barre_outils_public') == 'oui'){
$js = find_in_path('javascript/autosize.min.js');
$flux .= "\n<script type='text/javascript' src='$js'></script>\n";
}
return $flux;
}
6 years ago
function inserer_modeles_affiche_droite($flux) {
$objets = inserer_modeles_objets();
if (in_array($flux['args']['exec'], $objets)) {
6 years ago
include_spip('inc/inserer_modeles');
if (count(inserer_modeles_lister_formulaires_modeles(true)) > 0) {
6 years ago
$flux['data'] .= recuperer_fond('inserer_modeles', $flux['args']);
}
}
6 years ago
return $flux;
}
// Insertion dans le porte-plume
6 years ago
function inserer_modeles_porte_plume_barre_pre_charger($barres) {
include_spip('inc/inserer_modeles');
$formulaires_modeles = inserer_modeles_lister_formulaires_modeles(true);
6 years ago
if (count($formulaires_modeles) > 0) {
$barre = &$barres['edition'];
$barre->ajouterApres('grpCaracteres', array(
'id' => 'sepInsMod',
'separator' => '---------------',
'display' => true,
));
6 years ago
$sous_menu = array();
foreach ($formulaires_modeles as $nom => $formulaire) {
if (substr($nom, -5) == '.yaml') {
$nom = substr($nom, 0, -5);
}
$sous_menu[] = array(
'id' => 'inserer_modele_'.$nom,
'name' => $formulaire['nom'],
6 years ago
'className' => 'outil_inserer_modele_'.$nom,
'beforeInsert' => "function(markitup) {
url = $(\"input[type=hidden][name='url_inserer_modeles']\", $(markitup.textarea.form)).val() + '&formulaire_modele=$nom';
jQuery.modalboxload(url,{minHeight: '90%', type: 'ajax'});}
",
6 years ago
'display' => true,
);
}
6 years ago
$barre->ajouterApres('sepInsMod', array(
//groupe inserer_modeles et bouton inserer_modeles
'id' => 'inserer_modeles',
'name' => _T('inserer_modeles:outil_inserer_modeles'),
'key' => 'M',
'className' => 'outil_inserer_modeles',
'beforeInsert' => "function(markitup) {
url = $(\"input[type=hidden][name='url_inserer_modeles']\", $(markitup.textarea.form)).val();
jQuery.modalboxload(url,{minHeight: '90%', type: 'ajax'});}
",
6 years ago
'display' => true,
'dropMenu' => $sous_menu,
));
}
6 years ago
return $barres;
}
6 years ago
// Icones pour le porte-plume
6 years ago
function inserer_modeles_porte_plume_lien_classe_vers_icone($flux) {
include_spip('inc/inserer_modeles');
$formulaires_modeles = inserer_modeles_lister_formulaires_modeles(true);
6 years ago
if (count($formulaires_modeles) > 0) {
$icones = array();
$icones['outil_inserer_modeles'] = inserer_modeles_find_icone_barre_path('modele-xx.svg');
6 years ago
foreach ($formulaires_modeles as $nom => $formulaire) {
if (substr($nom, -5) == '.yaml') {
$nom = substr($nom, 0, -5);
}
$icones['outil_inserer_modele_'.$nom] = $formulaire['icone_barre'];
}
6 years ago
return array_merge($flux, $icones);
} else {
return $flux;
}
}
/**
* Retourner la liste des pages où insérer le formulaire du plugin
**/
function inserer_modeles_objets() {
include_spip('inc/config');
$objets = lire_config('inserer_modeles/objets',
array('spip_articles', 'spip_breves', 'spip_rubriques', 'spip_mots')
6 years ago
);
// Comme on utilise la saisie choisir_objets,
// on retravaille les objets selectionnes pour avoir leur url_edit
foreach ($objets as $key => $objet) {
$objets[$key] = objet_info($objet, 'url_edit');
}
return $objets;
}
/**
* Sur les formulaires d'édition d'objet
* Inserer dans un champ caché l'url de la mediabox d'inserer_modeles en prenant en compte l'object concerné
**/
function inserer_modeles_formulaire_fond($flux) {
if (stripos($flux['data'], '<textarea') === false) {
return $flux;
}
if (substr($flux['args']['form'], 0, 7) === 'editer_') {
if (isset($flux['args']['args']['type']) and isset($flux['args']['args']['id'])) {
$objet = $flux['args']['args']['type'];
$id = $flux['args']['args']['id'];
$hidden = inserer_modele_generer_hidden_url_modalbox($objet, $id);
} else {
$hidden = inserer_modele_generer_hidden_url_modalbox();
}
} else {
$hidden = inserer_modele_generer_hidden_url_modalbox();
}
$flux['data'] = str_replace('</form>', "$hidden</form>", $flux['data']);
return $flux;
}
/**
* Sur les formulaires de crayons
* Inserer dans un champ caché l'url de la mediabox d'inserer_modeles en prenant en compte l'object concerné
**/
function inserer_modeles_recuperer_fond($flux) {
if (stripos($flux['data']['texte'], '<textarea') === false) {
return $flux;
}
if (substr($flux['args']['fond'], 0, 12) === 'controleurs/') {
$objet = $flux['args']['contexte']['crayon_type'];
if (isset($flux['args']['contexte']["id_$objet"])) {
$id = $flux['args']['contexte']["id_$objet"];
$hidden = inserer_modele_generer_hidden_url_modalbox($objet, $id);
$flux['data']['texte'] .= $hidden;
}
}
return $flux;
}
/**
* Return un hidden contenant l'url de la modalbox
* @param str $objet
* @param int|str $id
* @return str champ hidden
**/
function inserer_modele_generer_hidden_url_modalbox($objet = '', $id = '') {
$url_inserer_modeles = url_absolue(generer_url_public('inserer_modeles'));
$url_inserer_modeles = parametre_url($url_inserer_modeles, 'modalbox', 'oui');
if ($objet and $id) {
$url_inserer_modeles = parametre_url($url_inserer_modeles, "id_$objet", $id);
}
$hidden = "<input type='hidden' disabled='disabled' name='url_inserer_modeles' value='$url_inserer_modeles' />";
return $hidden;
}