Changeset 50256 in spip-zone
- Timestamp:
- Aug 4, 2011, 8:34:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_plugins_/importer_blog/action/importer_blog.php
r47691 r50256 73 73 } 74 74 75 $texte = importer_texte($a['content']); 75 76 76 77 $p = sql_updateq('spip_articles', 77 78 array( 78 79 'titre' => $a['title'], 79 'texte' => $ a['content'],80 'texte' => $texte, 80 81 'date' => $a['date'], 81 82 'id_rubrique' => $rub, … … 85 86 'id_article='.$id 86 87 ); 88 87 89 88 90 if (_MODE_AUTEURS) { /* SPIP 3 */ … … 150 152 } 151 153 154 $texte = importer_texte($a['content']); 155 152 156 $f = array( 153 157 'titre' => '', ## $a['title'], sur blogspot le titre n'est que le debut du content 154 'texte' => $ a['content'],158 'texte' => $texte, 155 159 'date_heure' => $a['date'], 156 160 'date_thread' => $a['date'], … … 327 331 328 332 } 333 334 335 336 function importer_texte($t) { 337 338 ecrire_fichier('../tmp/x.html', $t); 339 #$a = `/opt/local/bin/pandoc ../tmp/x.html -t mediawiki`; 340 #echo "<pre>".htmlspecialchars($a)."</pre>\n"; 341 #exit; 342 343 344 # italiques 345 #<span style="font-style: italic;">...</span> 346 $t = preg_replace(',<span style="font-style: italic;">(.*)</span>,Ums', '{\1}', $t); 347 $t = preg_replace(',<i>(.*)</i>,Ums', '{\1}', $t); 348 349 # images 350 foreach (extraire_balises($t, 'a') as $l) { 351 if (preg_match(',^<a [^>]*><img [^>]*></a>$,Uims', $l) 352 AND $href = extraire_attribut($l, 'href') 353 AND $src = extraire_attribut(extraire_balise($l, 'img'), 'src') 354 #AND $height = extraire_attribut(extraire_balise($l, 'img'), 'height') 355 #AND $width = extraire_attribut(extraire_balise($l, 'img'), 'width') 356 AND preg_match(',\.(jpg|gif|png)$,i', $src, $r) 357 AND $extension = $r[1] 358 ) { 359 $doc = importer_doc(array('fichier' => $src, 'extension' => strtolower($extension), 'distant' => 'oui', 'mode' => 'image')); 360 361 if (preg_match('@<div style="text-align: center;">'.preg_quote($l,'@').'((?:.*?\n){0,5})</div>@ms', $t, $r)) { 362 $legende = trim($r[1]); 363 sql_updateq('spip_documents', array('descriptif' => $legende), 'id_document='.$doc); 364 $repl = "\n".'<doc'.$doc.'|center>'."\n"; 365 $t = str_replace($r[0], $repl, $t); 366 } 367 else { 368 $repl = "\n".'<img'.$doc.'|center>'."\n"; 369 $t = str_replace($l, $repl, $t); 370 } 371 } else 372 if (preg_match(',^<a [^>]*>(.*)</a>$,Uims', $l, $r) 373 AND $href = extraire_attribut($l, 'href') 374 ) { 375 $repl = '['.$r[1].'->'.$href.']'; 376 $t = str_replace($l, $repl, $t); 377 } 378 } 379 380 # sauts de lignes 381 $t = preg_replace(',<br />,', "\n_ ", $t); 382 $t = preg_replace(',{\n_ },', "\n_ ", $t); 383 $t = preg_replace(',\n_ \n_ ,', "\n\n", $t); 384 385 ## videos 386 387 # youtube 388 foreach (extraire_balises($t, 'object') as $l) { 389 if (preg_match(',http://(www\.)?youtube.com/v/[^"\']*,', $l, $r) 390 AND $a = extraire_balise($l, 'embed') 391 AND $height=extraire_attribut($a, 'height') 392 AND $width=extraire_attribut($a, 'width') 393 ) 394 { 395 $doc = importer_doc(array('fichier' => $r[0], 'hauteur' => $height, 'largeur' => $width, 'extension' => 'swf', 'distant' => 'oui', 'mode' => 'document')); 396 $t = str_replace($l, '<emb'.$doc.'|center>', $t); 397 } 398 } 399 400 401 $t = preg_replace(",\n_ </div>,S", "</div>\n_ ", $t); 402 $t = preg_replace(',<div style="text-align: center;"></div>,S', '', $t); 403 404 $t = preg_replace(',(\n_ )*<div class="blogger-post-footer">.*$,Sms', '', $t); 405 $t = str_replace("\n\n</span>", "</span>\n\n", $t); 406 $t = str_replace("\n\n</div>", "</div>\n\n", $t); 407 $t = str_replace("\n\n_ ", "\n\n\n", $t); 408 409 410 411 return $t; 412 413 } 414 415 416 function importer_doc($doc) { 417 $s = sql_query($q = "SELECT id_document FROM spip_documents WHERE fichier=".sql_quote($doc['fichier'])); 418 if ($t = sql_fetch($s)) 419 $id = $t['id_document']; 420 else { 421 $id = sql_insertq('spip_documents', array( 422 'fichier' => $doc['fichier'], 423 'date' => date('Y-m-d H:i:s') 424 )); 425 } 426 427 $p = sql_updateq('spip_documents', 428 $doc, 429 'id_document='.$id 430 ); 431 432 return $id; 433 }
Note: See TracChangeset
for help on using the changeset viewer.