la fonction creer_slug peut fonctionner par un appel via charger_fonction()
This commit is contained in:
parent
c576301511
commit
ebd12aa1e8
1 changed files with 16 additions and 5 deletions
|
@ -3,7 +3,7 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
|
|||
|
||||
/**
|
||||
* créer un slug Gamumail
|
||||
*
|
||||
*
|
||||
* @plugin GamuMail
|
||||
*
|
||||
* @copyright 2020
|
||||
|
@ -16,12 +16,11 @@ include_spip('inc/editer');
|
|||
include_spip('action/editer_objet');
|
||||
include_spip('inc/autoriser');
|
||||
|
||||
function action_creer_slug_dist(){
|
||||
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',
|
||||
|
@ -29,11 +28,23 @@ function action_creer_slug_dist(){
|
|||
'texte' => 'Le texte du mail',
|
||||
'statut' => 'publie',
|
||||
];
|
||||
|
||||
if ($id_slug = objet_inserer('gamumail', null, $set)) {
|
||||
sql_updateq('spip_gamumails', ['slug' => 'slug_'.$id_slug], 'id_gamumail = '.$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 = 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/$id_gamumail'");
|
||||
suivre_invalideur("id='id_gamumail/1'");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue