gamuMail/action/creer_slug.php

50 lines
1.1 KiB
PHP

<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
/**
* créer un slug Gamumail
*
* @plugin GamuMail
*
* @copyright 2020
* @author cy_altern
* @licence GNU/GPL
*
**/
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');
if (!autoriser('creer','gamumail')) {
return false;
}
$set = [
'slug' => '',
'titre' => 'Le titre du modèle',
'sujet' => 'Le sujet du mail',
'texte' => 'Le texte du mail',
'statut' => 'publie',
];
if ($id_slug = objet_inserer('gamumail', null, $set)) {
$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 = array_merge($set, $opt);
$set['editable'] = '';
}
sql_updateq('spip_gamumails', $set, 'id_gamumail = '.$id_slug);
}
// Cache
include_spip('inc/invalideur');
suivre_invalideur("id='id_gamumail/1'");
}