Witam.
Z gory przepraszam za dziecinne pytania, ale jestem zupelnie zielony, a siedze nad tym skryptem juz szmat czasu i juz nie moge.

skrypt konwertuje archiwum jogger.pl do bazy wordpressa. oto skrypt:
  1. <?php
  2.  
  3. mysql_connect('localhost','skiner','skinersql') or die("błąd łączenia z bazÄ…");
  4.  
  5. mysql_select_db('sndi') or die("błąd wybierania bazy");
  6. /* the three SET database statements below ensure proper UTF-8 handling
  7. for MySQL 4.1+ */
  8. if (!@mysql_query("SET character_set_client = 'utf8'")
  9. || !@mysql_query("SET collation_connection = 'utf8_polish_ci'")
  10. || !@mysql_query("SET character_set_results = NULL"))
  11. {
  12. die("dupa");
  13. }
  14.  
  15. $kategoria = 2; // id kategori do której polecą domyślnie wpisy :)
  16.  
  17. /* od tego miejsca nie zmieniamy */
  18.  
  19. $ent = Array();
  20.  
  21. $dom = new DOMDocument();
  22.  
  23. if (!$dom->load("jogger.xml")) {
  24.  
  25. echo "Error while parsing the documentn";
  26.  
  27.  
  28. }
  29.  
  30. $root = $dom->documentElement;
  31.  
  32. $entries = $root->getElementsByTagname("entry");
  33.  
  34. foreach($entries as $k => $v)
  35.  
  36. {
  37.  
  38. $a = $v->getElementsByTagname("date");
  39.  
  40. $date = $a->item(0)->nodeValue; 
  41.  
  42.  
  43.  
  44. $ent[$date]['date'] = $date;
  45.  
  46.  
  47. $a = $v->getElementsByTagname("subject");
  48.  
  49. $ent[$date]['subject'] = $a->item(0)->nodeValue;
  50.  
  51. $a = $v->getElementsByTagname("level");
  52.  
  53. $ent[$date]['post_status'] = ($a->item(0)->nodeValue > 1)?("private"):("publish");
  54.  
  55. $z = $v->getElementsByTagname("body");
  56.  
  57. $ent[$date]['body'] = $z->item(0)->nodeValue;
  58.  
  59. $ent[$date]['comment'] = Array();
  60.  
  61. $comment = $v->getElementsByTagname("comment");
  62.  
  63. foreach($comment as $kk => $vv)
  64.  
  65. {
  66.  
  67. $a = $vv->getElementsByTagname("date");
  68.  
  69. $cdate = $a->item(0)->nodeValue;
  70.  
  71. $ent[$date]['comment'][$cdate][date] = $cdate;
  72.  
  73. $a = $vv->getElementsByTagname("nick");
  74.  
  75. $ent[$date]['comment'][$cdate][nick] = $a->item(0)->nodeValue;
  76. $a = $vv->getElementsByTagname("nick_url");
  77.  
  78. $ent[$date]['comment'][$cdate][nick_url] = $a->item(0)->nodeValue;
  79.  
  80. $a = $vv->getElementsByTagname("body");
  81.  
  82. $ent[$date]['comment'][$cdate][body] = $a->item(0)->nodeValue;
  83.  
  84. }
  85.  
  86. }
  87.  
  88.  
  89. foreach($ent as $k => $v)
  90.  
  91. {
  92.  
  93. $sql = sprintf("INSERT INTO `wp_posts` (`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, 
    `post_status`, `post_modified`, `post_modified_gmt`, `guid`, `post_name`) VALUES"
    .
  94.  
  95. " (1, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $v[date],$v[date],mysql_escape_string($v[body]),mysql_escape_string($v[subject]), $v[post_status], $v[date], $v[date],'',md5($v[subject]));
  96.  
  97. mysql_query($sql) or die (mysql_error());
  98.  
  99. $id = mysql_insert_id();
  100.  
  101. mysql_query("INSERT INTO `wp_post2cat` (`post_id`, `category_id`) VALUES($id, $kategoria)") or die (mysql_error());
  102.  
  103. foreach($v['comment'] as $kk => $vv)
  104.  
  105. {
  106.  
  107. $sql = sprintf("INSERT INTO `wp_comments` (`comment_post_ID`, `comment_author`, `comment_author_url`, `comment_date`, 
    `comment_date_gmt`, `comment_content`, `comment_approved`) VALUES"
    .
  108.  
  109. "(%d, '%s', '%s', '%s', '%s', '%s', '1')", $id, mysql_escape_string($vv[nick]), mysql_escape_string($vv[nick_url]), $vv[date], $vv[date], mysql_escape_string($vv[body]));
  110.  
  111. mysql_query($sql) or die (mysql_error());
  112.  
  113. }
  114.  
  115. }
  116.  
  117. echo "SKOŃCZONE!!!!";
  118. ?>


oto kawalek archiwum:
  1. jogger>
  2.    <user>
  3. <jid>sir_skiner@chrome.pl</jid>
  4. <domain>antyidiot</domain>
  5. <alias/>
  6. </user>
  7.    <entry>
  8. <date>2004-11-01 16:30:00</date>
  9. <jid>sir_skiner@chrome.pl</jid>
  10. <level_id>0</level_id>
  11. <comment_mode>0</comment_mode>
  12. <subject>Z czym się to je?</subject>
  13.    <body>
  14. <p>Próbuje to "obczaić", zwłaszcza czemu Gaim mi nie chce działać z Joggerem...</p>
  15. </body>
  16. <tags/>
  17. <permalink>z-czym-sie-to-je</permalink>
  18. <trackback/>
  19. <category>Kapusta z grochem</category>
  20. <category>Życie jogga</category>
  21.    <comment>
  22. <date>2004-11-01 16:30:41</date>
  23. <nick>Paul_1981@jabberpl.org</nick>
  24. <nick_url>http://ocean.jogger.pl</nick_url>
  25. <body><p>Właśnie zadziałało :-(</p></body>
  26. <ip>213.25.55.***</ip>
  27. <trackback/>
  28. </comment>
  29.    <comment>
  30. <date>2004-11-01 16:33:48</date>
  31. <nick>sir_skiner</nick>
  32. <nick_url/>
  33.    <body>
  34. <p>a nie, bo to poszlo z innego komunikatora;]</p>
  35. </body>
  36. <ip>172.16.8.***</ip>
  37. <trackback/>
  38. </comment>
  39.    <comment>
  40. <date>2004-11-01 16:52:04</date>
  41. <nick>da.killa</nick>
  42. <nick_url>http://dakilla.jogger.pl</nick_url>
  43. <body><p>Bo Gaim ogólnie jest kiepski :)</p></body>
  44. <ip>213.77.163.***</ip>
  45. <trackback/>
  46. </comment>
  47.    <comment>
  48. <date>2004-11-01 19:18:58</date>
  49. <nick>insider</nick>
  50. <nick_url/>
  51.    <body>
  52. <p>a tam kiepski zaraz;P To jogger jest kiepski bo nie chce działać z gaimem;>
  53. <br />
  54. <br /></p>
  55. </body>
  56. <ip>83.29.133.***</ip>
  57. <trackback/>
  58. </comment>
  59. </entry>
  60.    <entry>


a teraz co trzeba zrobic, zeby:
  1. skrypt utworzy w bazie podkategorie lub kategorie na podstawie tagow xml i przyporzadowal je do postow, zamiast pakowac wsio do 1 kategorii wpisow
  2. dodal do pola comment_count w tabeli wp_posts liczbe komentarzy o tej samej wartosci pola comment_post_ID w tabeli wp_comments
questionmark.gif