[ Index ] |
|
Code source de SPIP 1.9.2c |
1 <?php 2 3 /***************************************************************************\ 4 * SPIP, Systeme de publication pour l'internet * 5 * * 6 * Copyright (c) 2001-2007 * 7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * 8 * * 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 \***************************************************************************/ 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; 14 15 16 // http://doc.spip.org/@action_editer_site_dist 17 function action_editer_site_dist() { 18 19 $securiser_action = charger_fonction('securiser_action', 'inc'); 20 $arg = $securiser_action(); 21 22 if (preg_match(',options/(\d+),',$arg, $r)) { 23 $id_syndic = $r[1]; 24 editer_site_options($id_syndic); 25 // Envoi depuis le formulaire d'edition d'un site existant 26 } else if ($id_syndic = intval($arg)) { 27 28 // reload si on change une des valeurs de syndication 29 if ( 30 (_request('url_syndic') OR _request('resume') OR _request('syndication')) 31 AND $s = spip_query("SELECT url_syndic,syndication,resume FROM spip_syndic WHERE id_syndic="._q($id_syndic)) 32 AND $t = spip_fetch_array($s) 33 AND ( 34 (_request('url_syndic') AND _request('url_syndic') != $t['url_syndic']) 35 OR 36 (_request('syndication') AND _request('syndication') != $t['syndication']) 37 OR 38 (_request('resume') AND _request('resume') != $t['resume']) 39 ) 40 ) 41 set_request('reload', 'oui'); 42 43 revisions_sites($id_syndic); 44 } 45 // Envoi depuis le formulaire de creation d'un site 46 else if ($arg == 'oui') { 47 set_request('reload', 'oui'); 48 $id_syndic = insert_syndic(_request('id_parent')); 49 revisions_sites($id_syndic); 50 } 51 // Envoi depuis le formulaire d'analyse automatique d'un site 52 else if ($arg == 'auto') { 53 if ($auto = analyser_site(_request('url'))) { 54 $id_syndic = insert_syndic(_request('id_parent')); 55 revisions_sites($id_syndic, $auto); 56 if ($auto['syndication'] == 'oui') 57 set_request('reload', 'oui'); 58 59 // Enregistrer le logo s'il existe 60 if ($auto['logo'] AND $auto['format_logo']) 61 @rename($auto['logo'], 62 _DIR_IMG . 'siteon'.$id_syndic.'.'.$auto['format_logo']); 63 } 64 else 65 redirige_par_entete( 66 generer_url_ecrire('sites_edit', 'id_rubrique='._request('id_parent'),'&') 67 ); 68 } 69 // Erreur 70 else { 71 redirige_par_entete('./'); 72 } 73 74 // Re-syndiquer le site 75 if (_request('reload') == 'oui') { 76 // Effacer les messages si on supprime la syndication 77 if (_request('syndication') == 'non') 78 spip_query("DELETE FROM spip_syndic_articles WHERE id_syndic="._q($id_syndic)); 79 80 $s = spip_query("SELECT id_syndic, descriptif FROM spip_syndic WHERE id_syndic=$id_syndic AND syndication IN ('oui', 'sus', 'off') LIMIT 1"); 81 if ($t = spip_fetch_array($s)) { 82 include_spip('inc/syndic'); 83 syndic_a_jour($id_syndic); 84 85 // Si on n'a pas de descriptif ou pas de logo, on va le chercher 86 $chercher_logo = charger_fonction('chercher_logo', 'inc'); 87 if (!$logo = $chercher_logo($id_syndic, 'id_syndic', 'on') 88 OR $t['descriptif'] == '') { 89 $auto = analyser_site(_request('url_syndic')); 90 revisions_sites($id_syndic, 91 array('descriptif' => $auto['descriptif']) 92 ); 93 if (!$logo 94 AND $auto['logo'] AND $auto['format_logo']) 95 @rename($auto['logo'], 96 _DIR_IMG . 'siteon'.$id_syndic.'.'.$auto['format_logo']); 97 } 98 } 99 } 100 101 // Rediriger le navigateur 102 $redirect = parametre_url(urldecode(_request('redirect')), 103 'id_syndic', $id_syndic, '&'); 104 redirige_par_entete($redirect); 105 } 106 107 // http://doc.spip.org/@insert_syndic 108 function insert_syndic($id_rubrique) { 109 110 include_spip('base/abstract_sql'); 111 include_spip('inc/rubriques'); 112 113 // Si id_rubrique vaut 0 ou n'est pas definie, creer le site 114 // dans la premiere rubrique racine 115 if (!$id_rubrique = intval($id_rubrique)) { 116 $row = spip_fetch_array(spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_parent=0 ORDER by 0+titre,titre LIMIT 1")); 117 $id_rubrique = $row['id_rubrique']; 118 } 119 120 121 // Le secteur a la creation : c'est le secteur de la rubrique 122 $row = spip_fetch_array(spip_query("SELECT id_secteur FROM spip_rubriques WHERE id_rubrique=$id_rubrique")); 123 $id_secteur = $row['id_secteur']; 124 125 $id_syndic = spip_abstract_insert("spip_syndic", 126 "(id_rubrique, id_secteur, statut, date)", 127 "($id_rubrique, $id_secteur, 'prop', NOW())"); 128 129 return $id_syndic; 130 } 131 132 133 // Enregistre une revision de syndic 134 // $new indique si c'est un INSERT 135 // $c est un contenu (par defaut on prend le contenu via _request()) 136 // http://doc.spip.org/@revisions_sites 137 function revisions_sites ($id_syndic, $c=false) { 138 139 include_spip('inc/filtres'); 140 include_spip('inc/autoriser'); 141 include_spip('inc/rubriques'); 142 143 // Ces champs seront pris nom pour nom (_POST[x] => spip_syndic.x) 144 $champs_normaux = array('nom_site', 'url_site', 'descriptif', 'url_syndic', 'syndication', 'url_propre'); 145 146 // ne pas accepter de titre vide 147 if (_request('nom_site', $c) === '') 148 $c = set_request('nom_site', _T('ecrire:info_sans_titre'), $c); 149 150 $champs = array(); 151 foreach ($champs_normaux as $champ) { 152 $val = _request($champ, $c); 153 if ($val !== NULL) 154 $champs[$champ] = corriger_caracteres($val); 155 } 156 157 // Changer le statut du site ? 158 include_spip('inc/auth'); 159 auth_rubrique($GLOBALS['auteur_session']['id_auteur'], $GLOBALS['auteur_session']['statut']); 160 161 $s = spip_query("SELECT statut, id_rubrique FROM spip_syndic WHERE id_syndic=$id_syndic"); 162 $row = spip_fetch_array($s); 163 $id_rubrique = $row['id_rubrique']; 164 $statut = $row['statut']; 165 166 if (_request('statut', $c) 167 AND _request('statut', $c) != $statut 168 AND autoriser('publierdans','rubrique',$id_rubrique)) { 169 $statut = $champs['statut'] = _request('statut', $c); 170 } 171 172 // Changer de rubrique ? 173 // Verifier que la rubrique demandee est differente 174 // de la rubrique actuelle 175 if ($id_parent = intval(_request('id_parent', $c)) 176 AND $id_parent != $id_rubrique 177 AND (spip_fetch_array(spip_query("SELECT id_rubrique FROM spip_rubriques WHERE id_rubrique=$id_parent")))) { 178 $champs['id_rubrique'] = $id_parent; 179 180 // si le site est publie 181 // et que le demandeur n'est pas admin de la rubrique 182 // repasser le site en statut 'prop'. 183 if ($statut == 'publie') { 184 if (!autoriser('publierdans','rubrique',$id_parent)) 185 $champs['statut'] = $statut = 'prop'; 186 } 187 } 188 189 // recuperer les extras 190 if ($GLOBALS['champs_extra']) { 191 include_spip('inc/extra'); 192 if ($extra = extra_update('syndic', $id_syndic, $c)) 193 $champs['extra'] = $extra; 194 } 195 196 // Envoyer aux plugins 197 include_spip('inc/modifier'); # temporaire pour eviter un bug 198 $champs = pipeline('pre_edition', 199 array( 200 'args' => array( 201 'table' => 'spip_syndic', 202 'id_objet' => $id_syndic 203 ), 204 'data' => $champs 205 ) 206 ); 207 208 $update = array(); 209 foreach ($champs as $champ => $val) 210 $update[] = $champ . '=' . _q($val); 211 212 if (!count($update)) return; 213 214 // Enregistrer les modifications 215 spip_query("UPDATE spip_syndic SET ".join(', ',$update)." WHERE id_syndic=$id_syndic"); 216 217 // marquer le fait que le site est travaille par toto a telle date 218 // une alerte sera donnee aux autres redacteurs sur exec=sites 219 if ($GLOBALS['meta']['articles_modif'] != 'non') { 220 include_spip('inc/drapeau_edition'); 221 signale_edition ($id_syndic, $GLOBALS['auteur_session'], 'syndic'); 222 } 223 224 // Si on deplace le site 225 // - propager les secteurs 226 // - changer sa langue (si heritee) 227 if (isset($champs['id_rubrique'])) { 228 propager_les_secteurs(); 229 230 $row = spip_fetch_array(spip_query("SELECT lang, langue_choisie FROM spip_syndic WHERE id_syndic=$id_syndic")); 231 $langue_old = $row['lang']; 232 $langue_choisie_old = $row['langue_choisie']; 233 234 if ($langue_choisie_old != "oui") { 235 $row = spip_fetch_array(spip_query("SELECT lang FROM spip_rubriques WHERE id_rubrique=$id_rubrique")); 236 $langue_new = $row['lang']; 237 if ($langue_new != $langue_old) 238 spip_query("UPDATE spip_syndic SET lang = '$langue_new' WHERE id_syndic = $id_syndic"); 239 } 240 } 241 242 // 243 // Post-modifications 244 // 245 246 // Invalider les caches 247 if ($statut == 'publie') { 248 include_spip('inc/invalideur'); 249 suivre_invalideur("id='id_syndic/$id_syndic'"); 250 } 251 252 // Demander une reindexation du site 253 if ($statut == 'publie') { 254 include_spip('inc/indexation'); 255 marquer_indexer('spip_syndic', $id_syndic); 256 } 257 258 // Recalculer les rubriques (statuts et dates) si l'on deplace 259 // un site publie ou si on le publie/depublie 260 if (isset($champs['statut']) 261 OR ($statut == 'publie' AND isset($champ['id_rubrique'])) 262 ) { 263 calculer_rubriques(); 264 } 265 266 // Notification ? 267 pipeline('post_edition', 268 array( 269 'args' => array( 270 'table' => 'spip_syndic', 271 'id_objet' => $id_syndic 272 ), 273 'data' => $champs 274 ) 275 ); 276 } 277 278 279 // http://doc.spip.org/@analyser_site 280 function analyser_site($url) { 281 include_spip('inc/filtres'); # pour filtrer_entites() 282 include_spip('inc/distant'); 283 284 // Accepter les URLs au format feed:// ou qui ont oublie le http:// 285 $url = preg_replace(',^feed://,i', 'http://', $url); 286 if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://'.$url; 287 288 $texte = recuperer_page($url, true); 289 if (!$texte) return false; 290 291 if (preg_match(',<(channel|feed)([:[:space:]][^>]*)?' 292 .'>(.*)</\1>,ims', $texte, $regs)) { 293 $result['syndication'] = 'oui'; 294 $result['url_syndic'] = $url; 295 $channel = $regs[3]; 296 297 list($header) = preg_split( 298 ',<(entry|item)([:[:space:]][^>]*)?'.'>,Uims', $channel,2); 299 if (preg_match(',<title[^>]*>(.*)</title>,Uims', $header, $r)) 300 $result['nom_site'] = supprimer_tags(filtrer_entites(trim($r[1]))); 301 if (preg_match( 302 ',<link[^>]*[[:space:]]rel=["\']?alternate[^>]*>(.*)</link>,Uims', 303 $header, $regs)) 304 $result['url_site'] = filtrer_entites($regs[1]); 305 else if (preg_match(',<link[^>]*[[:space:]]rel=.alternate[^>]*>,Uims', 306 $header, $regs)) 307 $result['url_site'] = filtrer_entites(extraire_attribut($regs[0], 'href')); 308 else if (preg_match(',<link[^>]*>(.*)</link>,Uims', $header, $regs)) 309 $result['url_site'] = filtrer_entites($regs[1]); 310 else if (preg_match(',<link[^>]*>,Uims', $header, $regs)) 311 $result['url_site'] = filtrer_entites(extraire_attribut($regs[0], 'href')); 312 $result['url_site'] = url_absolue($result['url_site'], $url); 313 314 if (preg_match(',<(description|tagline)([[:space:]][^>]*)?' 315 .'>(.*)</\1>,Uims', $header, $r)) 316 $result['descriptif'] = supprimer_tags(filtrer_entites($r[3])); 317 318 if (preg_match(',<image.*<url.*>(.*)</url>.*</image>,Uims', 319 $header, $r) 320 AND preg_match(',(https?://.*/.*(gif|png|jpg)),ims', $r[1], $r) 321 AND $image = recuperer_infos_distantes($r[1])) { 322 if (in_array($image['extension'], array('gif', 'jpg', 'png'))) { 323 $result['format_logo'] = $image['extension']; 324 $result['logo'] = $image['fichier']; 325 } 326 else if ($image['fichier']) { 327 @unlink($image['fichier']); 328 } 329 } 330 } 331 else { 332 $result['syndication'] = 'non'; 333 $result['url_site'] = $url; 334 if (eregi('<head>(.*)', $texte, $regs)) 335 $head = filtrer_entites(eregi_replace('</head>.*', '', $regs[1])); 336 else 337 $head = $texte; 338 if (eregi('<title[^>]*>(.*)', $head, $regs)) 339 $result['nom_site'] = filtrer_entites(supprimer_tags(eregi_replace('</title>.*', '', $regs[1]))); 340 if (eregi('<meta[[:space:]]+(name|http\-equiv)[[:space:]]*=[[:space:]]*[\'"]?description[\'"]?[[:space:]]+(content|value)[[:space:]]*=[[:space:]]*[\'"]([^>]+)[\'"]>', $head, $regs)) 341 $result['descriptif'] = filtrer_entites(supprimer_tags($regs[3])); 342 343 // Cherchons quand meme un backend 344 include_spip('inc/distant'); 345 include_spip('inc/feedfinder'); 346 $feeds = get_feed_from_url($url, $texte); 347 // si on a a trouve un (ou plusieurs) on le note avec select: 348 // ce qui constitue un signal pour exec=sites qui proposera de choisir 349 // si on syndique, et quelle url. 350 if (count($feeds)>=1) { 351 spip_log("feedfinder.php :\n".join("\n", $feeds)); 352 $result['url_syndic'] = "select: ".join(' ',$feeds); 353 } 354 } 355 return $result; 356 } 357 358 // http://doc.spip.org/@editer_site_options 359 function editer_site_options($id_syndic) 360 { 361 $moderation = _request('moderation'); 362 $miroir = _request('miroir'); 363 $oubli = _request('oubli'); 364 $resume = _request('resume'); 365 366 if ($moderation == 'oui' OR $moderation == 'non') 367 spip_query("UPDATE spip_syndic SET moderation='$moderation' WHERE id_syndic=$id_syndic"); 368 if ($miroir == 'oui' OR $miroir == 'non') 369 spip_query("UPDATE spip_syndic SET miroir='$miroir' WHERE id_syndic=$id_syndic"); 370 if ($oubli == 'oui' OR $oubli == 'non') 371 spip_query("UPDATE spip_syndic SET oubli='$oubli' WHERE id_syndic=$id_syndic"); 372 373 if ($resume == 'oui' OR $resume == 'non') { 374 spip_query("UPDATE spip_syndic SET resume='$resume' WHERE id_syndic=$id_syndic"); 375 include_spip('inc/syndic'); 376 syndic_a_jour($id_syndic); 377 } 378 } 379 380 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 10:20:27 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |