3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/presentation');
16 include_spip('inc/actions');
18 // L'ajout d'un auteur se fait par mini-navigateur dans la fourchette:
19 define('_SPIP_SELECT_MIN_AUTEURS', 30); // en dessous: balise Select
20 define('_SPIP_SELECT_MAX_AUTEURS', 30); // au-dessus: saisie + return
22 // http://doc.spip.org/@inc_editer_auteurs_dist
23 function inc_editer_auteurs_dist($type, $id, $flag, $cherche_auteur, $ids, $titre_boite = NULL, $script_edit_objet = NULL) {
25 $arg_ajax = "&id_{$type}=$id&type=$type";
26 if ($script_edit_objet===NULL) $script_edit_objet = $type.'s';
27 if ($titre_boite===NULL)
28 $titre_boite = _T('texte_auteurs'). aide("artauteurs");
30 $arg_ajax.= "&titre=".urlencode($titre_boite);
32 $aff_les_auteurs = afficher_auteurs_objet($type, $id, $flag, '', $script_edit_objet, $arg_ajax);
35 $futurs = ajouter_auteurs_objet($type, $id, '',$script_edit_objet, $arg_ajax, $cherche_auteur);
38 $ldap = isset($GLOBALS['meta']['ldap_statut_import']) ?
39 $GLOBALS['meta']['ldap_statut_import'] : '';
41 return editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $aff_les_auteurs, $futurs, $ldap,$titre_boite,$script_edit_objet, $arg_ajax);
44 // http://doc.spip.org/@editer_auteurs_objet
45 function editer_auteurs_objet($type, $id, $flag, $cherche_auteur, $ids, $les_auteurs, $futurs, $statut, $titre_boite,$script_edit_objet, $arg_ajax)
47 global $spip_lang_left, $spip_lang_right;
49 $bouton_creer_auteur = $GLOBALS['connect_toutes_rubriques'];
50 $clic = _T('icone_creer_auteur');
53 // complement de action/editer_auteurs.php pour notifier la recherche d'auteur
55 if ($cherche_auteur) {
57 $reponse ="<div style='text-align: $spip_lang_left'>"
58 . debut_boite_info(true)
59 . rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id,$script_edit_objet, $arg_ajax);
61 if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
63 $legende = generer_url_ecrire("auteur_infos", "new=oui&lier_id_article=$id");
64 if (isset($cherche_auteur))
65 $legende = parametre_url($legende, 'nom', $cherche_auteur);
66 $legende = parametre_url($legende, 'redirect',
67 generer_url_ecrire('articles', "id_article=$id", '&'));
69 $reponse .="<div style='width: 200px;'>"
70 . icone_horizontale($clic, $legende, "redacteurs-24.gif", "creer.gif", false)
73 $bouton_creer_auteur = false;
76 $reponse .= fin_boite_info(true)
80 $reponse .= $les_auteurs;
89 if ($type=='article' && $bouton_creer_auteur) { // pas generique pour le moment
91 $legende = generer_url_ecrire("auteur_infos", "new=oui&lier_id_article=$id");
92 if (isset($cherche_auteur))
93 $legende = parametre_url($legende, 'nom', $cherche_auteur);
94 $legende = parametre_url($legende, 'redirect',
95 generer_url_ecrire('articles', "id_article=$id", '&'));
97 $clic = "<span class='verdana1'><b>$clic</b></span>";
98 $res = icone_horizontale_display($clic, $legende, "redacteurs-24.gif", "creer.gif", false);
101 $res = "<div style='float:$spip_lang_right; width:280px;position:relative;display:inline;'>"
107 $idom = "auteurs_$type" . "_$id";
108 $bouton = bouton_block_depliable($titre_boite,$flag ?
($flag === 'ajax'):-1,$idom);
109 $res = debut_cadre_enfonce("auteur-24.gif", true, "", $bouton)
111 . debut_block_depliable($flag === 'ajax',$idom)
114 . fin_cadre_enfonce(true);
116 return ajax_action_greffe("editer_auteurs", $id, $res);
119 // Retourne les auteurs attaches a l'objet $id de type $type
120 // ou rien s'il y en a trop
122 // http://doc.spip.org/@determiner_auteurs_objet
123 function determiner_auteurs_objet($type, $id, $cond='', $limit=200)
125 if (!preg_match(',^[a-z]*$,',$type)) return array();
127 $jointure = 'spip_' . table_jointure('auteur', $type);
128 $cond = "id_{$type}=".sql_quote($id) . ($cond ?
" AND $cond" : '');
129 if (sql_countsel($jointure, $cond) > $limit)
131 else return array_map('array_shift', sql_allfetsel("id_auteur", $jointure, $cond));
134 // http://doc.spip.org/@determiner_non_auteurs
135 function determiner_non_auteurs($type, $id, $andcond='')
137 return auteurs_autorises(determiner_auteurs_objet($type, $id, $andcond));
140 // http://doc.spip.org/@rechercher_auteurs_objet
141 function rechercher_auteurs_objet($cherche_auteur, $ids, $type, $id, $script_edit_objet, $arg_ajax)
144 return "<b>"._T('texte_aucun_resultat_auteur', array('cherche_auteur' => $cherche_auteur)).".</b><br />";
146 elseif ($ids == -1) {
147 return "<b>"._T('texte_trop_resultats_auteurs', array('cherche_auteur' => $cherche_auteur))."</b><br />";
149 elseif (preg_match('/^\d+$/',$ids)) {
151 $nom = sql_getfetsel("nom", "spip_auteurs", "id_auteur=$ids");
152 return "<b>"._T('texte_ajout_auteur')."</b><br /><ul><li><span class='verdana1 spip_small'><b><span class='spip_medium'>".typo($nom)."</span></b></span></li></ul>";
155 $ids = preg_replace('/[^0-9,]/','',$ids); // securite
156 $result = sql_select("*", "spip_auteurs", "id_auteur IN ($ids)", "", "nom");
159 . _T('texte_plusieurs_articles', array('cherche_auteur' => $cherche_auteur))
161 . "<ul class='verdana1'>";
162 while ($row = sql_fetch($result)) {
163 $id_auteur = $row['id_auteur'];
164 $nom_auteur = $row['nom'];
165 $email_auteur = $row['email'];
166 $bio_auteur = $row['bio'];
168 $res .= "<li><b>".typo($nom_auteur)."</b>";
170 if ($email_auteur) $res .= " ($email_auteur)";
173 . ajax_action_auteur('editer_auteurs', "$id,$type,$id_auteur",$script_edit_objet,"id_{$type}=$id", array(_T('lien_ajouter_auteur')),$arg_ajax);
175 if (trim($bio_auteur)) {
176 $res .= "<br />".couper(propre($bio_auteur), 100)."\n";
185 // http://doc.spip.org/@afficher_auteurs_objet
186 function afficher_auteurs_objet($type, $id, $edit, $cond, $script, $arg_ajax)
189 $from = table_jointure('auteur', $type);
190 if (!$from) return '' ; // securite
191 $from = "spip_{$from}";
192 $where = "id_{$type}=".sql_quote($id) . ($cond ?
" AND $cond" : '');
194 $presenter_liste = charger_fonction('presenter_liste', 'inc');
196 $requete = array('SELECT' => "id_auteur", 'FROM' => $from, 'WHERE' => $where);
197 $tmp_var = "editer_auteurs-$id";
198 $url = generer_url_ecrire('editer_auteurs',$arg_ajax);
200 // charger ici meme si pas d'auteurs
201 // car inc_formater_auteur peut aussi redefinir
202 // determiner_non_auteurs qui sert plus loin
203 if (!$formater = charger_fonction("formater_auteur_$type", 'inc',true))
204 $formater = charger_fonction('formater_auteur', 'inc');
206 $retirer = array(_T('lien_retirer_auteur')." ". http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'"));
208 $styles = array(array('arial11', 14), array('arial2'), array('arial11'), array('arial11'), array('arial11'), array('arial1'));
210 $tableau = array(); // ne sert pas
211 $f = function_exists($edit) ?
$edit : 'ajouter_auteur_un';
212 return $presenter_liste($requete, $f, $tableau, array($formater, $retirer, $arg_ajax, $edit, $id, $type, $script), false, $styles, $tmp_var, '','', $url);
215 // http://doc.spip.org/@ajouter_auteur_un
216 function ajouter_auteur_un($row, $own) {
217 global $connect_statut, $connect_id_auteur;
218 list($formater, $retirer, $arg_ajax, $flag, $id, $type, $script_edit) = $own;
220 $id_auteur = $row['id_auteur'];
221 $vals = $formater($id_auteur);
222 $voir = ($flag AND ($connect_id_auteur != $id_auteur OR $connect_statut == '0minirezo'));
224 $vals[] = ajax_action_auteur('editer_auteurs', "$id,$type,-$id_auteur", $script_edit, "id_{$type}=$id", $retirer, $arg_ajax);
229 // http://doc.spip.org/@ajouter_auteurs_objet
230 function ajouter_auteurs_objet($type, $id, $cond_les_auteurs,$script_edit, $arg_ajax, $valeur='')
232 if (!$determiner_non_auteurs = charger_fonction('determiner_non_auteurs_'.$type,'inc',true))
233 $determiner_non_auteurs = 'determiner_non_auteurs';
235 $cond = $determiner_non_auteurs($type, $id, $cond_les_auteurs);
236 $all = objet_auteur_select($cond);
237 if (!$all) return '';
238 $idom = "auteur_$type" . "_$id";
239 $new = $idom . '_new';
240 $menu = $idom . '_sel';
241 $js = "findObj_forcer('$menu').style.visibility='visible';";
243 $text = "<span class='verdana1'><label for='$new'><b>"
244 . _T('titre_cadre_ajouter_auteur')
245 . "</b></label></span>\n";
247 if (!is_numeric($all)) {
248 $sel = "$text<select name='$new' id='$new' size='1' style='width:150px;' onchange=\"$js\">$all</select>";
249 $clic = _T('bouton_ajouter');
250 } else if ((_SPIP_AJAX
< 1) OR ($all >= _SPIP_SELECT_MAX_AUTEURS
)) {
251 $sel = "$text <input type='text' name='cherche_auteur' id='$new' onclick=\"$js\" value=\"" . entites_html($valeur) . "\" size='20' />";
252 $clic = _T('bouton_chercher');
254 $sel = selecteur_auteur_ajax($type, $id, $js, $text, $idom);
255 $clic = _T('bouton_ajouter');
258 return ajax_action_post('editer_auteurs', "$id,$type", $script_edit, "id_{$type}=$id", $sel, $clic, " class='visible_au_chargement' id='$menu'",'', $arg_ajax);
261 // http://doc.spip.org/@objet_auteur_select
262 function objet_auteur_select($cond)
264 $count = sql_countsel('spip_auteurs', $cond);
265 if (!$count) return '';
266 if ($count > _SPIP_SELECT_MIN_AUTEURS
) return $count;
268 $statuts = $GLOBALS['liste_des_statuts'];
269 $res = sql_allfetsel('*', 'spip_auteurs', $cond, '', "statut, nom");
270 foreach ($res as $k => $row) {
271 $statut = array_search($row["statut"], $statuts);
272 $id_auteur = $row["id_auteur"];
273 $email = $row["email"];
274 if (!autoriser('voir', 'auteur'))
275 if ($p = strpos($email, '@'))
276 $email = substr($email, 0, $p).'@...';
278 $email = " ($email)";
279 if ($statut != $statut_old) {
280 $opt = "</optgroup>\n<optgroup class='option_separateur_statut_auteur' label='" . _T($statut) . "'>";
281 $statut_old = $statut;
285 . "\n<option class='option_auteur' value='$id_auteur'>"
286 . supprimer_tags(couper(typo($row["nom"] . $email), 40))
289 return "<optgroup label=''><option value='0'>"
290 . _T('bouton_choisir')
296 // http://doc.spip.org/@selecteur_auteur_ajax
297 function selecteur_auteur_ajax($type, $id, $js, $text, $idom='')
299 include_spip('inc/chercher_rubrique');
300 $idom2 = $idom . '_new';
301 $idom1 = $idom . '_div';
302 $url = generer_url_ecrire('selectionner_auteur',"id_article=$id&type=$type");
303 return $text . construire_selecteur($url, $js, $idom1, $idom2, ' type="hidden"');