From 7962c0e3671eeebf33ed6c5913925d1fc7c2f8b5 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Thu, 4 Oct 2007 16:52:23 +0000 Subject: [PATCH] =?UTF-8?q?Abstraction=20de=20WHERE,=20et=20correction=20d?= =?UTF-8?q?'une=20erreur=20dans=20le=20d=C3=A9pot=20pr=C3=A9c=C3=A9dent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecrire/action/editer_article.php | 11 +++++------ ecrire/action/editer_breve.php | 6 +++--- ecrire/action/editer_site.php | 20 +++++++++----------- ecrire/exec/breves_edit.php | 4 ++-- ecrire/exec/controle_forum.php | 11 ++++++----- ecrire/exec/naviguer.php | 20 ++++++++++---------- ecrire/exec/rubriques_edit.php | 4 +--- ecrire/inc/auth.php | 2 +- 8 files changed, 37 insertions(+), 41 deletions(-) diff --git a/ecrire/action/editer_article.php b/ecrire/action/editer_article.php index 590633758b..9f429e5ba2 100644 --- a/ecrire/action/editer_article.php +++ b/ecrire/action/editer_article.php @@ -193,7 +193,7 @@ function instituer_article($id_article, $c, $calcul_rub=true) { // de la rubrique actuelle if ($id_parent = _request('id_parent', $c) AND $id_parent != $id_rubrique - AND (sql_fetch(spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_rubrique=$id_parent")))) { + AND (sql_countsel("spip_rubriques", "id_rubrique=$id_parent"))) { $champs['id_rubrique'] = $id_parent; // si l'article etait publie @@ -307,16 +307,15 @@ function article_referent ($id_article, $c) { // selectionner l'article cible, qui doit etre different de nous-meme, // et quitter s'il n'existe pas - if (!$row = sql_fetch( - spip_query("SELECT id_trad FROM spip_articles WHERE id_article=$lier_trad AND NOT(id_article=$id_article)"))) + $id_lier = sql_getfetsel('id_trad', 'spip_articles', "id_article=$lier_trad AND NOT(id_article=$id_article)"); + + if ($id_lier === NULL) { - spip_log("echec lien de trad vers article inexistant ($lier_trad)"); + spip_log("echec lien de trad vers article incorrect ($lier_trad)"); return '&trad_err=1'; } // $id_lier est le numero du groupe de traduction - $id_lier = $row['id_trad']; - // Si l'article vise n'est pas deja traduit, son identifiant devient // le nouvel id_trad de ce nouveau groupe et on l'affecte aux deux // articles diff --git a/ecrire/action/editer_breve.php b/ecrire/action/editer_breve.php index 8b3afaf4aa..7825944d3c 100644 --- a/ecrire/action/editer_breve.php +++ b/ecrire/action/editer_breve.php @@ -115,12 +115,12 @@ function revisions_breves ($id_breve, $c=false) { // de la rubrique actuelle if ($id_parent = intval(_request('id_parent', $c)) AND $id_parent != $id_rubrique - AND ($r=sql_fetch(spip_query("SELECT lang FROM spip_rubriques WHERE id_parent=0 AND id_rubrique=$id_parent")))) { + AND (NULL !== ($lang=sql_getfetsel('lang', 'spip_rubriques', "id_parent=0 AND id_rubrique=$id_parent")))) { $champs['id_rubrique'] = $id_parent; // - changer sa langue (si heritee) if ($langue_choisie_old != "oui") { - if ($r['lang'] != $langue_old) - $champs['lang'] = $r['lang']; + if ($lang != $langue_old) + $champs['lang'] = $lang; } // si la breve est publiee // et que le demandeur n'est pas admin de la rubrique diff --git a/ecrire/action/editer_site.php b/ecrire/action/editer_site.php index f1a235fdae..5b4e809e13 100644 --- a/ecrire/action/editer_site.php +++ b/ecrire/action/editer_site.php @@ -26,12 +26,10 @@ function action_editer_site_dist() { $resyndiquer = editer_site_options($id_syndic); // Envoi depuis le formulaire d'edition d'un site existant } else if ($id_syndic = intval($arg)) { - // reload si on change une des valeurs de syndication if ( (_request('url_syndic') OR _request('resume') OR _request('syndication')) - AND $s = spip_query("SELECT url_syndic,syndication,resume FROM spip_syndic WHERE id_syndic="._q($id_syndic)) - AND $t = sql_fetch($s) + AND $t = sql_fetsel('url_syndic,syndication,resume', 'spip_syndic', "id_syndic="._q($id_syndic)) AND ( (_request('url_syndic') AND _request('url_syndic') != $t['url_syndic']) OR @@ -41,7 +39,6 @@ function action_editer_site_dist() { ) ) set_request('reload', 'oui'); - revisions_sites($id_syndic); // Envoi normal depuis le formulaire de creation d'un site @@ -86,13 +83,13 @@ function action_editer_site_dist() { if (_request('syndication') == 'non') sql_delete("spip_syndic_articles", "id_syndic="._q($id_syndic)); - $s = spip_query("SELECT id_syndic, descriptif FROM spip_syndic WHERE id_syndic=$id_syndic AND syndication IN ('oui', 'sus', 'off') LIMIT 1"); - if ($t = sql_fetch($s)) { + $t = sql_getfetsel('descriptif', 'spip_syndic', "id_syndic=$id_syndic AND syndication IN ('oui', 'sus', 'off')", '','', 1); + if ($t !== NULL) { - // Si on n'a pas de descriptif ou pas de logo, on va le chercher + // Si descriptif vide, chercher le logo si pas deja la $chercher_logo = charger_fonction('chercher_logo', 'inc'); if (!$logo = $chercher_logo($id_syndic, 'id_syndic', 'on') - OR $t['descriptif'] == '') { + OR !$t) { $auto = analyser_site(_request('url_syndic')); revisions_sites($id_syndic, array('descriptif' => $auto['descriptif']) @@ -127,6 +124,7 @@ function action_editer_site_dist() { // http://doc.spip.org/@genie_syndic function genie_syndic($t) { include_spip('genie/syndic'); + define('_GENIE_SYNDIC', 2); // Pas de faux message d'erreur $t = syndic_a_jour(_GENIE_SYNDIC_NOW); return $t ? 0 : _GENIE_SYNDIC_NOW; } @@ -212,10 +210,10 @@ function revisions_sites ($id_syndic, $c=false) { if ($id_parent = intval(_request('id_parent', $c)) AND $id_parent != $id_rubrique - AND ($r = sql_fetch(spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_parent")))) { + AND ($id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', "id_rubrique=$id_parent"))) { $champs['id_rubrique'] = $id_parent; - if ($id_secteur_old != $r['id_secteur']) - $champs['id_secteur'] = $r['id_secteur']; + if ($id_secteur_old != $id_secteur) + $champs['id_secteur'] = $id_secteur; // si le site est publie // et que le demandeur n'est pas admin de la rubrique // repasser le site en statut 'prop'. diff --git a/ecrire/exec/breves_edit.php b/ecrire/exec/breves_edit.php index 8ee1547bb9..3ea909908e 100644 --- a/ecrire/exec/breves_edit.php +++ b/ecrire/exec/breves_edit.php @@ -31,8 +31,8 @@ function exec_breves_edit_dist() if (!$id_rubrique) { $in = !$connect_id_rubrique ? '' : (' AND id_rubrique IN (' . join(',', $connect_id_rubrique) . ')'); - $row_rub = sql_fetch(spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_parent=0$in ORDER BY id_rubrique DESC LIMIT 1")); - $id_rubrique = $row_rub['id_rubrique']; + $id_rubrique = sql_getfetsel('id_rubrique','spip_rubriques', "id_parent=0$in",'', "id_rubrique DESC", 1); + if (!autoriser('creerbrevedans','rubrique',$id_rubrique )){ // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises $res = sql_select("id_rubrique", "spip_rubriques", "id_parent=0"); diff --git a/ecrire/exec/controle_forum.php b/ecrire/exec/controle_forum.php index 4b1e973e7b..8d66a7db32 100644 --- a/ecrire/exec/controle_forum.php +++ b/ecrire/exec/controle_forum.php @@ -214,9 +214,10 @@ function exec_controle_forum_dist() list($from,$where)=critere_statut_controle_forum($type, $id_rubrique, $recherche); // Si un id_controle_forum est demande, on adapte le debut - if ($debut_id_forum = intval(_request('debut_id_forum')) - AND $d = sql_fetch(spip_query("SELECT date_heure FROM spip_forum WHERE id_forum=$debut_id_forum"))) { - $debut = sql_countsel($from, $where . (!$d ? '' : (" AND F.date_heure > '".$d['date_heure']."'"))); + if (!$debut_id_forum = intval(_request('debut_id_forum')) + AND (NULL !== ($d = sql_getfetsel('date_heure', 'spip_forum', "id_forum=$debut_id_forum")))) { + + $debut = sql_countsel($from, $where . (" AND F.date_heure > '$d'")); } $pack = 20; // nb de forums affiches par page @@ -251,11 +252,11 @@ function exec_controle_forum_dist() echo onglet(_T('onglet_messages_internes'), generer_url_ecrire('controle_forum', $args . "interne"), "interne", $type=='interne', "forum-interne-24.gif"); list($from,$where) = critere_statut_controle_forum('vide', $id_rubrique); - $n = sql_fetch(spip_query("SELECT id_forum FROM $from WHERE $where LIMIT 1")); + $n = sql_countsel($from, $where,'','', 1); if ($n) echo onglet(_T('onglet_messages_vide'), generer_url_ecrire('controle_forum', $args . "vide"), "vide", $type=='vide'); list($from,$where) = critere_statut_controle_forum('prop', $id_rubrique); - $f = sql_fetch(spip_query("SELECT F.id_forum FROM $from " . (!$where ? '' : "WHERE $where ") . " LIMIT 1")); + $f = sql_countsel($from, $where, "", "", 1); if ($f) echo onglet(_T('texte_statut_attente_validation'), generer_url_ecrire('controle_forum', $args . "prop"), "prop", $type=='prop'); diff --git a/ecrire/exec/naviguer.php b/ecrire/exec/naviguer.php index 9982efa302..829d0a0ea3 100644 --- a/ecrire/exec/naviguer.php +++ b/ecrire/exec/naviguer.php @@ -448,20 +448,20 @@ function montre_naviguer($id_rubrique, $titre, $id_parent, $ze_logo, $flag_edita // http://doc.spip.org/@tester_rubrique_vide function tester_rubrique_vide($id_rubrique) { - $n = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_rubriques WHERE id_parent=$id_rubrique LIMIT 1")); - if ($n['n'] > 0) return false; + if (sql_countsel('spip_rubriques', "id_parent=$id_rubrique")) + return false; - $n = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_articles WHERE id_rubrique=$id_rubrique AND (statut='publie' OR statut='prepa' OR statut='prop') LIMIT 1")); - if ($n['n'] > 0) return false; + if (sql_countsel('spip_articles', "id_rubrique=$id_rubrique AND (statut='publie' OR statut='prepa' OR statut='prop')")) + return false; - $n = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_breves WHERE id_rubrique=$id_rubrique AND (statut='publie' OR statut='prop') LIMIT 1")); - if ($n['n'] > 0) return false; + if (sql_countsel('spip_breves', "id_rubrique=$id_rubrique AND (statut='publie' OR statut='prop')")) + return false; - $n = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_syndic WHERE id_rubrique=$id_rubrique AND (statut='publie' OR statut='prop') LIMIT 1")); - if ($n['n'] > 0) return false; + if (sql_countsel('spip_syndic', "id_rubrique=$id_rubrique AND (statut='publie' OR statut='prop')")) + return false; - $n = sql_fetch(spip_query("SELECT COUNT(*) AS n FROM spip_documents_rubriques WHERE id_rubrique=$id_rubrique LIMIT 1")); - if ($n['n'] > 0) return false; + if (sql_countsel('spip_documents_rubriques', "id_rubrique=$id_rubrique")) + return false; return true; } diff --git a/ecrire/exec/rubriques_edit.php b/ecrire/exec/rubriques_edit.php index dd6a5e0ccd..d3debf470b 100644 --- a/ecrire/exec/rubriques_edit.php +++ b/ecrire/exec/rubriques_edit.php @@ -116,9 +116,7 @@ function exec_rubriques_edit_dist() // si c'est une rubrique-secteur contenant des breves, demander la // confirmation du deplacement - $contient_breves = sql_fetch(spip_query("SELECT COUNT(*) AS cnt FROM spip_breves WHERE id_rubrique=$id_rubrique LIMIT 1")); - - $contient_breves = $contient_breves['cnt']; + $contient_breves = sql_countsel('spip_breves', "id_rubrique=$id_rubrique",'',2); if ($contient_breves > 0) { $scb = ($contient_breves>1? 's':''); diff --git a/ecrire/inc/auth.php b/ecrire/inc/auth.php index d935412830..db4aad8b68 100644 --- a/ecrire/inc/auth.php +++ b/ecrire/inc/auth.php @@ -33,7 +33,7 @@ function auteurs_article($id_article, $cond='') // http://doc.spip.org/@auteurs_autorises function auteurs_autorises($cond='', $order='') { - return sql_select('*', 'spip_auteurs', "statut IN ('0minirezo','1comite')" . ($cond ? " AND $cond" : ''),'', ($order ? " ORDER BY $order" : '')); + return sql_select('*', 'spip_auteurs', "statut IN ('0minirezo','1comite')" . ($cond ? " AND $cond" : ''),'', $order); } // Un nouvel inscrit prend son statut definitif a la 1ere connexion. -- GitLab