OSDN Git Service

Merge branch 'skinnable-master'
[nucleus-jp/nucleus-next.git] / nucleus / convert / wordpress.php
index 9e5a78c..3d933c4 100644 (file)
 
 include("../../config.php");
 
+<<<<<<< HEAD
+function def($s)
+{
+       if ( isset($_POST[$s]) )
+               echo addslashes(stripslashes($_POST[$s]));
+       else
+       {
+               if ( i18n::strpos($s, 'host') !== FALSE ) echo "localhost";
+               if ( i18n::strpos($s, 'username') !== FALSE ) echo "root";
+               if ( i18n::strpos($s, 'wpprefix') !== FALSE ) echo "wp_";
+       }
+}
+
+function error($s)
+{
+       global $isok;
+       $isok = false;
+       echo "<h3>Error: $s</h3>";
+}
+
+// line breaks into properly formatted paragraphs
+function paragraph($text, $br = false)
+{
+       $text = trim($text);
+       $text = str_replace("\r", '', $text);
+       $text = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&amp;$1', $text);
+       if ( $text == "" ) return "";
+       $text = $text . "\n"; // just to make things a little easier, pad the end
+       $text = preg_replace('|<br/>\s*<br/>|', "\n\n", $text);
+       $text = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $text); // Space things out a little
+       $text = preg_replace('!(</(?:table|ul|ol|li|pre|form|blockquote|h[1-6])>)!', "$1\n", $text); // Space things out a little
+       $text = preg_replace("/(\r\n|\r)/", "\n", $text); // cross-platform newlines 
+       $text = preg_replace("/\n\n+/", "\n\n", $text); // take care of duplicates
+       $text = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n", $text); // make paragraphs, including one at the end 
+       $text = preg_replace('|<p>\s*?</p>|', '', $text); // under certain strange conditions it could create a P of entirely whitespace 
+       $text = preg_replace("|<p>(<li.+?)</p>|", "$1", $text); // problem with nested lists
+       // blockquote
+       $text = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $text);
+       $text = str_replace('</blockquote></p>', '</p></blockquote>', $text);
+       // now the hard work
+       $text = preg_replace('!<p>\s*(</?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!', "$1", $text);
+       $text = preg_replace('!(</?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>|</div>"!', "$1", $text);
+       if ( $br ) $text = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $text);
+       // optionally make line breaks
+       $text = preg_replace('!(</?(?:table|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*<br/>!', "$1", $text);
+       $text = preg_replace('!<br/>(\s*</?(?:p|li|div|th|pre|td|ul|ol)>)!', '$1', $text);
+       // some cleanup
+       $text = str_replace('</p><br />', '</p>', $text);
+       $text = str_replace("<br />\n</p>", '</p>', $text);
+       return $text;
+}
+
+function encoding($s)
+{
+       global $input;
+       if ( is_callable("iconv") )
+               return iconv($input, 'utf-8', $s);
+       else
+               return $s;
+}
+=======
   function def($s){ 
     if (isset($_POST[$s])) 
       echo Entity::hsc($_POST[$s]); 
@@ -70,15 +131,8 @@ include("../../config.php");
     $text = str_replace("<br />\n</p>",'</p>',$text);
     return $text; 
   }
+>>>>>>> skinnable-master
 
-  function encoding($s){
-    global $input;
-    if (is_callable("iconv"))
-      return iconv($input,'utf-8',$s);
-    else 
-      return $s;
-  }
-  
 ?>
 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='cs' lang='cs'>
@@ -124,6 +178,67 @@ else
        {
                @mysql_select_db($_POST['wpdatabase'], $linkwp) or error("Cannot select WordPress DB...");
        }
+<<<<<<< HEAD
+
+       // connect to Nucleus CMS database
+       /*
+       $linkblogcms = @mysql_connect($_POST['blogcmshost'],$_POST['blogcmsusername'],$_POST['blogcmspassword'],true);
+       if($linkblogcms==false) 
+         error("Cannot connect to Nucleus DB..");
+       else {
+         @mysql_select_db($_POST['blogcmsdatabase'],$linkblogcms) or error("Cannot select Nucleus DB...");
+       }
+        */
+
+       if ( !$isok )
+       {
+               echo "<p>Please correct these errors first!</p><hr />";
+       }
+       else
+       {
+               /*                 */
+               /* transfer data ! */
+               /*                 */
+               $prefixwp = $_POST['wpprefix'];
+
+               /* *********************************************** */
+               echo "<h2>Getting encoding...</h2>";
+               $query = "SELECT option_value FROM " . $prefixwp . "options WHERE option_name='blog_charset'";
+               $querywp = mysql_query($query, $linkwp) or die($query);
+               if ( $row = mysql_fetch_object($querywp) )
+                       $input = $row->option_value;
+               else
+                       $input = "utf-8";
+               echo "<p>Encoding: $input</p>";
+
+               /* *********************************************** */
+               echo "<h2>Transfering categories...</h2>";
+               DB::execute("DELETE FROM " . sql_table('category') . " WHERE cdesc='@wordpress'");
+               $total_num = DB::getValue("SELECT count(*) as result FROM " . sql_table('category'));
+               $catdd = $total_num;
+               $total_num++;
+
+               $query = "SELECT * FROM " . $prefixwp . "term_taxonomy , " . $prefixwp . "terms WHERE " . $prefixwp . "term_taxonomy.term_taxonomy_id = "
+                       . $prefixwp . "terms.term_id AND " . $prefixwp . "term_taxonomy.taxonomy='category'";
+               $querywp = mysql_query($query, $linkwp) or die($query);
+               echo "<p>rows to transfer: " . mysql_num_rows($querywp) . "</p>";
+               echo "<p>";
+               $cate_map = array();
+               while ( $row = mysql_fetch_object($querywp) )
+               {
+                       echo $total_num . ", ";
+                       $cate_map[$row->term_id] = $total_num;
+                       $query = sprintf("INSERT INTO %s (catid,cblog,cname,cdesc) VALUES (%d,1,'%s','@wordpress')"
+                               , sql_table('category'), intval($total_num), encoding($row->name));
+                       if ( DB::execute($query) === FALSE )
+                       {
+                               die($query);
+                       }
+                       $total_num++;
+               }
+               echo "</p>";
+
+=======
 
        // connect to Nucleus CMS database
        /*
@@ -183,6 +298,7 @@ else
                }
                echo "</p>";
 
+>>>>>>> skinnable-master
                /* *********************************************** */
                echo "<h2>Transfering posts and comments...</h2>";
                DB::execute("DELETE FROM " . sql_table('comment') . " WHERE chost='@wordpress'");