maj fonction creation d'un slug

This commit is contained in:
Christophe 2021-04-26 10:56:42 +02:00
parent bc4922f87d
commit 2e60b096f6

View file

@ -11,16 +11,14 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
* @licence GNU/GPL * @licence GNU/GPL
* *
**/ **/
function action_creer_slug_dist($slug = null, $opt = [], $ecraser = false){
include_spip('inc/editer');
include_spip('action/editer_objet');
include_spip('inc/autoriser');
function action_creer_slug_dist($slug = null, $opt = []){
include_spip('inc/autoriser'); include_spip('inc/autoriser');
if (!autoriser('creer','gamumail')) { if (!autoriser('creer','gamumail')) {
return false; return false;
} }
// Arrive d'une action SPIP
if ($slug === null) {
$set = [ $set = [
'slug' => '', 'slug' => '',
'titre' => 'Le titre du modèle', 'titre' => 'Le titre du modèle',
@ -32,18 +30,26 @@ function action_creer_slug_dist($slug = null, $opt = []){
if ($id_slug = objet_inserer('gamumail', null, $set)) { if ($id_slug = objet_inserer('gamumail', null, $set)) {
$set = ['slug' => 'slug_'.$id_slug]; $set = ['slug' => 'slug_'.$id_slug];
if (
$slug !== null
and !sql_countsel('slug', 'spip_gamumails', 'slug='.sql_quote($slug))
) {
$set['slug'] = $slug;
}
if (is_array($opt) and count($opt)) {
$set['editable'] = 'non';
$set = array_merge($set, $opt);
}
sql_updateq('spip_gamumails', $set, 'id_gamumail = '.$id_slug); sql_updateq('spip_gamumails', $set, 'id_gamumail = '.$id_slug);
} }
} else {
// Appel de la fonction via charger_fonction("creer_slug", 'action');
// Création d'un slug à l'installation d'un plugin
// remplacement d'un slug, il faut l'option $ecraser=true
$id_slug = sql_getfetsel('id_gamumail', 'spip_gamumails', 'slug='.sql_quote($slug));
if (
intval($id_slug)
and $ecraser
) {
sql_updateq('spip_gamumails', $opt, 'id_gamumail='.intval($id_slug));
}
// creation d'un nouveau slug
if (!intval($id_slug)) {
sql_insertq('spip_gamumails', $opt);
}
}
// Cache // Cache
include_spip('inc/invalideur'); include_spip('inc/invalideur');