Changeset 93607 in spip-zone for _core_/plugins/breves/breves_pipelines.php
- Timestamp:
- Dec 13, 2015, 11:31:30 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_core_/plugins/breves/breves_pipelines.php
r93170 r93607 12 12 13 13 /** 14 * Utilisations de pipelines 14 * Utilisations de pipelines 15 15 * 16 16 * @package SPIP\Breves\Pipelines 17 **/ 18 if (!defined("_ECRIRE_INC_VERSION")) return; 17 **/ 18 if (!defined("_ECRIRE_INC_VERSION")) { 19 return; 20 } 19 21 20 22 … … 28 30 * Couples nom de la méta => valeur par défaut 29 31 */ 30 function breves_configurer_liste_metas($metas){ 31 $metas['activer_breves'] = 'non'; 32 function breves_configurer_liste_metas($metas) { 33 $metas['activer_breves'] = 'non'; 34 32 35 return $metas; 33 36 } 34 37 35 38 /** 36 * Ajouter les brèves à valider sur les rubriques 39 * Ajouter les brèves à valider sur les rubriques 37 40 * 38 41 * @pipeline rubrique_encours 39 * 40 * @param array $flux 41 * @return array Données du pipeline 42 **/43 function breves_rubrique_encours($flux) {42 * 43 * @param array $flux Données du pipeline 44 * @return array Données du pipeline 45 **/ 46 function breves_rubrique_encours($flux) { 44 47 if ($flux['args']['type'] == 'rubrique') { 45 $lister_objets = charger_fonction('lister_objets', 'inc');48 $lister_objets = charger_fonction('lister_objets', 'inc'); 46 49 47 50 $id_rubrique = $flux['args']['id_objet']; … … 51 54 // 52 55 $flux['data'] .= $lister_objets('breves', array( 53 'titre' =>_T('breves:info_breves_valider'),54 'statut' =>array('prepa','prop'),55 'id_rubrique' =>$id_rubrique,56 'par' =>'date_heure'));57 }58 return $flux;59 } 60 61 56 'titre' => _T('breves:info_breves_valider'), 57 'statut' => array('prepa', 'prop'), 58 'id_rubrique' => $id_rubrique, 59 'par' => 'date_heure' 60 )); 61 } 62 63 return $flux; 64 } 62 65 63 66 … … 66 69 * 67 70 * @pipeline affiche_enfants 68 * 69 * @param array $flux 70 * @return array Données du pipeline 71 **/71 * 72 * @param array $flux Données du pipeline 73 * @return array Données du pipeline 74 **/ 72 75 function breves_affiche_enfants($flux) { 73 76 if (isset($flux['args']['exec']) 74 AND $e = trouver_objet_exec($flux['args']['exec']) 75 AND $e['type'] == 'rubrique' 76 AND $e['edition'] == false) { 77 AND $e = trouver_objet_exec($flux['args']['exec']) 78 AND $e['type'] == 'rubrique' 79 AND $e['edition'] == false 80 ) { 77 81 $id_rubrique = $flux['args']['id_rubrique']; 78 82 79 83 if ($GLOBALS['meta']["activer_breves"] == 'oui') { 80 $lister_objets = charger_fonction('lister_objets', 'inc');84 $lister_objets = charger_fonction('lister_objets', 'inc'); 81 85 $bouton_breves = ''; 82 $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.$id_rubrique); 83 if (autoriser('creerbrevedans','rubrique',$id_rubrique,NULL,array('id_parent'=>$id_parent))) { 84 $bouton_breves .= icone_verticale(_T('breves:icone_nouvelle_breve'), generer_url_ecrire("breve_edit","id_rubrique=$id_rubrique&new=oui"), "breve-24.png","new", 'right') 85 . "<br class='nettoyeur' />"; 86 $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . $id_rubrique); 87 if (autoriser('creerbrevedans', 'rubrique', $id_rubrique, null, array('id_parent' => $id_parent))) { 88 $bouton_breves .= icone_verticale(_T('breves:icone_nouvelle_breve'), 89 generer_url_ecrire("breve_edit", "id_rubrique=$id_rubrique&new=oui"), "breve-24.png", "new", 'right') 90 . "<br class='nettoyeur' />"; 86 91 } 87 92 88 $flux['data'] .= $lister_objets('breves', array('titre'=>_T('breves:icone_ecrire_nouvel_article'), 'where'=>"statut != 'prop' AND statut != 'prepa'", 'id_rubrique'=>$id_rubrique, 'par'=>'date_heure')); 93 $flux['data'] .= $lister_objets('breves', array( 94 'titre' => _T('breves:icone_ecrire_nouvel_article'), 95 'where' => "statut != 'prop' AND statut != 'prepa'", 96 'id_rubrique' => $id_rubrique, 97 'par' => 'date_heure' 98 )); 89 99 $flux['data'] .= $bouton_breves; 90 100 } 91 101 } 92 return $flux; 93 } 94 95 102 103 return $flux; 104 } 96 105 97 106 98 107 /** 99 108 * Ajoute le nombre de brèves sur l'accueil privé 100 * 109 * 101 110 * @pipeline accueil_informations 102 * 111 * 103 112 * @param string $texte 104 113 * HTML des informations générales concernant chaque type d'objet … … 108 117 * sur la page d'accueil privée 109 118 */ 110 function breves_accueil_informations($texte) {119 function breves_accueil_informations($texte) { 111 120 include_spip('base/abstract_sql'); 112 121 113 $q = sql_select("COUNT(*) AS cnt, statut", 'spip_breves', '', 'statut', '', '', "COUNT(*)<>0");122 $q = sql_select("COUNT(*) AS cnt, statut", 'spip_breves', '', 'statut', '', '', "COUNT(*)<>0"); 114 123 115 124 $cpt = array(); 116 125 $cpt2 = array(); 117 126 $where = false; 118 if ($GLOBALS['visiteur_session']['statut']=='0minirezo'){ 119 $where = sql_allfetsel('id_objet','spip_auteurs_liens',"objet='rubrique' AND id_auteur=".intval($GLOBALS['visiteur_session']['id_auteur'])); 120 if ($where){ 121 $where = sql_in('id_rubrique',array_map('reset',$where)); 127 if ($GLOBALS['visiteur_session']['statut'] == '0minirezo') { 128 $where = sql_allfetsel('id_objet', 'spip_auteurs_liens', 129 "objet='rubrique' AND id_auteur=" . intval($GLOBALS['visiteur_session']['id_auteur'])); 130 if ($where) { 131 $where = sql_in('id_rubrique', array_map('reset', $where)); 122 132 } 123 133 } 124 134 $defaut = $where ? '0/' : ''; 125 while ($row = sql_fetch($q)) {126 127 135 while ($row = sql_fetch($q)) { 136 $cpt[$row['statut']] = $row['cnt']; 137 $cpt2[$row['statut']] = $defaut; 128 138 } 129 139 … … 131 141 if ($where) { 132 142 $q = sql_select("COUNT(*) AS cnt, statut", 'spip_breves', $where, "statut"); 133 while ($row = sql_fetch($q)) {143 while ($row = sql_fetch($q)) { 134 144 $r = $row['statut']; 135 145 $cpt2[$r] = intval($row['cnt']) . '/'; … … 139 149 $texte .= "<h4>" . afficher_plus_info(generer_url_ecrire("breves"), "", _T('breves:info_breves_02')) . "</h4>"; 140 150 $texte .= "<ul class='liste-items'>"; 141 if (isset($cpt['prop'])) $texte .= "<li class='item'>"._T("texte_statut_attente_validation").": ".$cpt2['prop'].$cpt['prop'] . '</li>'; 142 if (isset($cpt['publie'])) $texte .= "<li class='item on'>"._T("texte_statut_publies").": ".$cpt2['publie'] .$cpt['publie'] . '</li>'; 151 if (isset($cpt['prop'])) { 152 $texte .= "<li class='item'>" . _T("texte_statut_attente_validation") . ": " . $cpt2['prop'] . $cpt['prop'] . '</li>'; 153 } 154 if (isset($cpt['publie'])) { 155 $texte .= "<li class='item on'>" . _T("texte_statut_publies") . ": " . $cpt2['publie'] . $cpt['publie'] . '</li>'; 156 } 143 157 $texte .= "</ul>"; 144 158 $texte .= "</div>"; 145 159 } 160 146 161 return $texte; 147 162 } … … 150 165 /** 151 166 * Compter les brèves dans une rubrique 152 * 167 * 153 168 * @pipeline objet_compte_enfants 154 * 155 * @param array $flux Données du pipeline 156 * @return array Données du pipeline 157 */ 158 function breves_objet_compte_enfants($flux){ 159 if ($flux['args']['objet']=='rubrique' 160 AND $id_rubrique=intval($flux['args']['id_objet'])) { 169 * 170 * @param array $flux Données du pipeline 171 * @return array Données du pipeline 172 */ 173 function breves_objet_compte_enfants($flux) { 174 if ($flux['args']['objet'] == 'rubrique' 175 AND $id_rubrique = intval($flux['args']['id_objet']) 176 ) { 161 177 // juste les publies ? 162 178 if (array_key_exists('statut', $flux['args']) and ($flux['args']['statut'] == 'publie')) { 163 $flux['data']['breve'] = sql_countsel('spip_breves', "id_rubrique=".intval($id_rubrique)." AND (statut='publie')"); 179 $flux['data']['breve'] = sql_countsel('spip_breves', 180 "id_rubrique=" . intval($id_rubrique) . " AND (statut='publie')"); 164 181 } else { 165 $flux['data']['breve'] = sql_countsel('spip_breves', "id_rubrique=".intval($id_rubrique)." AND (statut='publie' OR statut='prop')"); 166 } 167 } 182 $flux['data']['breve'] = sql_countsel('spip_breves', 183 "id_rubrique=" . intval($id_rubrique) . " AND (statut='publie' OR statut='prop')"); 184 } 185 } 186 168 187 return $flux; 169 188 } … … 172 191 /** 173 192 * Changer la langue des brèves si la rubrique change 174 * 193 * 175 194 * @pipeline trig_calculer_langues_rubriques 176 * 177 * @param array $flux Données du pipeline 178 * @return array Données du pipeline 179 */ 180 function breves_trig_calculer_langues_rubriques($flux){ 181 182 $s = sql_select("A.id_breve AS id_breve, R.lang AS lang", "spip_breves AS A, spip_rubriques AS R", "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (A.lang='' OR R.lang<>'') AND R.lang<>A.lang"); 195 * 196 * @param array $flux Données du pipeline 197 * @return array Données du pipeline 198 */ 199 function breves_trig_calculer_langues_rubriques($flux) { 200 201 $s = sql_select("A.id_breve AS id_breve, R.lang AS lang", "spip_breves AS A, spip_rubriques AS R", 202 "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (A.lang='' OR R.lang<>'') AND R.lang<>A.lang"); 183 203 while ($row = sql_fetch($s)) { 184 204 $id_breve = $row['id_breve']; 185 sql_updateq('spip_breves', array("lang" =>$row['lang'], 'langue_choisie'=>'non'), "id_breve=$id_breve");205 sql_updateq('spip_breves', array("lang" => $row['lang'], 'langue_choisie' => 'non'), "id_breve=$id_breve"); 186 206 } 187 207 … … 192 212 /** 193 213 * Publier et dater les rubriques qui ont une brève publiée 194 * 214 * 195 215 * @pipeline calculer_rubriques 196 * 197 * @param array $flux 198 * @return array Données du pipeline 199 */ 200 function breves_calculer_rubriques($flux) {216 * 217 * @param array $flux Données du pipeline 218 * @return array Données du pipeline 219 */ 220 function breves_calculer_rubriques($flux) { 201 221 202 222 $r = sql_select( … … 204 224 "spip_rubriques AS R JOIN spip_breves AS A ON R.id_rubrique = A.id_rubrique", 205 225 "A.date_heure>R.date_tmp AND A.statut='publie' ", "R.id_rubrique"); 206 while ($row = sql_fetch($r)) 207 sql_updateq('spip_rubriques', array('statut_tmp'=>'publie', 'date_tmp'=>$row['date_h']), "id_rubrique=".$row['id']); 208 209 return $flux; 210 } 211 212 213 214 /** 215 * Ajouter les brèves à valider sur la page d'accueil 226 while ($row = sql_fetch($r)) { 227 sql_updateq('spip_rubriques', array('statut_tmp' => 'publie', 'date_tmp' => $row['date_h']), 228 "id_rubrique=" . $row['id']); 229 } 230 231 return $flux; 232 } 233 234 235 /** 236 * Ajouter les brèves à valider sur la page d'accueil 216 237 * 217 238 * @pipeline accueil_encours 218 * 219 * @param string $flux 239 * 240 * @param string $flux HTML du bloc encours sur la page d'accueil privée 220 241 * @return string HTML du bloc encours sur la page d'accueil privée 221 **/222 function breves_accueil_encours($flux) {223 $lister_objets = charger_fonction('lister_objets', 'inc');242 **/ 243 function breves_accueil_encours($flux) { 244 $lister_objets = charger_fonction('lister_objets', 'inc'); 224 245 225 246 226 247 $flux .= $lister_objets('breves', array( 227 'titre' =>afficher_plus_info(generer_url_ecrire('breves'))._T('breves:info_breves_valider'),228 'statut' =>array('prepa','prop'),229 'par' =>'date_heure'));230 231 return $flux; 232 } 233 248 'titre' => afficher_plus_info(generer_url_ecrire('breves')) . _T('breves:info_breves_valider'), 249 'statut' => array('prepa', 'prop'), 250 'par' => 'date_heure' 251 )); 252 253 return $flux; 254 } 234 255 235 256 … … 238 259 * 239 260 * @pipeline optimiser_base_disparus 240 * 241 * @param array $flux 242 * @return array Données du pipeline 243 */ 244 function breves_optimiser_base_disparus($flux) {261 * 262 * @param array $flux Données du pipeline 263 * @return array Données du pipeline 264 */ 265 function breves_optimiser_base_disparus($flux) { 245 266 $n = &$flux['data']; 246 267 $mydate = $flux['args']['date']; … … 249 270 # les breves qui sont dans une id_rubrique inexistante 250 271 $res = sql_select("B.id_breve AS id", 251 272 "spip_breves AS B 252 273 LEFT JOIN spip_rubriques AS R 253 274 ON B.id_rubrique=R.id_rubrique", 254 255 AND B.maj < " .sql_quote($mydate));256 257 $n += optimiser_sansref('spip_breves', 'id_breve', $res);275 "R.id_rubrique IS NULL 276 AND B.maj < " . sql_quote($mydate)); 277 278 $n += optimiser_sansref('spip_breves', 'id_breve', $res); 258 279 259 280 … … 272 293 * 273 294 * @pipeline boite_infos 274 * 275 * @param array $flux 276 * @return array Données du pipeline 277 */ 278 function breves_boite_infos($flux) {295 * 296 * @param array $flux Données du pipeline 297 * @return array Données du pipeline 298 */ 299 function breves_boite_infos($flux) { 279 300 if ( 280 301 isset($flux['args']['type']) and $flux['args']['type'] == 'rubrique' 281 and isset($flux['args']['id']) and $id_rubrique = $flux['args']['id'] 282 ){ 283 if ($nb = sql_countsel('spip_breves',"statut='publie' AND id_rubrique=".intval($id_rubrique))){ 284 $nb = "<div>". singulier_ou_pluriel($nb, "breves:info_1_breve", "breves:info_nb_breves") . "</div>"; 285 if ($p = strpos($flux['data'],"<!--nb_elements-->")) 286 $flux['data'] = substr_replace($flux['data'],$nb,$p,0); 287 } 288 } 302 and isset($flux['args']['id']) and $id_rubrique = $flux['args']['id'] 303 ) { 304 if ($nb = sql_countsel('spip_breves', "statut='publie' AND id_rubrique=" . intval($id_rubrique))) { 305 $nb = "<div>" . singulier_ou_pluriel($nb, "breves:info_1_breve", "breves:info_nb_breves") . "</div>"; 306 if ($p = strpos($flux['data'], "<!--nb_elements-->")) { 307 $flux['data'] = substr_replace($flux['data'], $nb, $p, 0); 308 } 309 } 310 } 311 289 312 return $flux; 290 313 } … … 293 316 * Ajoute le formulaire de configuration des brèves sur la page de 294 317 * configuration des contenus 295 * 318 * 296 319 * @pipeline affiche_milieu 297 * 298 * @param array $flux 299 * @return array Données du pipeline 300 */ 301 function breves_affiche_milieu($flux) {320 * 321 * @param array $flux Données du pipeline 322 * @return array Données du pipeline 323 */ 324 function breves_affiche_milieu($flux) { 302 325 if ($flux["args"]["exec"] == "configurer_contenu") { 303 $flux["data"] .= recuperer_fond('prive/squelettes/inclure/configurer',array('configurer'=>'configurer_breves')); 304 } 326 $flux["data"] .= recuperer_fond('prive/squelettes/inclure/configurer', array('configurer' => 'configurer_breves')); 327 } 328 305 329 return $flux; 306 330 }
Note: See TracChangeset
for help on using the changeset viewer.