function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $categories = array(); $entries = array(); if (!extension_loaded('mysqli')) { return MYSQL_REQUIRED; } $pmdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$pmdb || mysqli_connect_error()) { return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host'])); } if (!@mysqli_select_db($pmdb, $this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysqli_error($pmdb)); } /* Users */ $res = @$this->nativeQuery("SELECT id AS ID,\n username AS user_login,\n `password` AS user_pass,\n email AS user_email,\n status AS user_level,\n url AS url\n FROM {$this->data['prefix']}members", $pmdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysqli_error($pmdb)); } for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysqli_fetch_assoc($res); $data = array('right_publish' => $users[$x]['user_level'] >= 3 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']); // pMachine uses md5, too. if ($users[$x]['user_level'] < 12) { $data['userlevel'] = USERLEVEL_EDITOR; } else { $data['userlevel'] = USERLEVEL_ADMIN; } if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ $res = @$this->nativeQuery("SELECT id AS cat_ID,\n category AS cat_name,\n category AS category_description\n FROM {$this->data['prefix']}categories ORDER BY id", $pmdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($pmdb)); } // Get all the info we need for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $categories[] = mysqli_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) { $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}weblog ORDER BY t_stamp;", $pmdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($pmdb)); } for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysqli_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['status'] == 'open' ? 'false' : 'true', 'allow_comments' => $entries[$x]['showcomments'] == '1' ? 'true' : 'false', 'timestamp' => $entries[$x]['t_stamp'], 'extended' => $this->strtr($entries[$x]['more']), 'body' => $this->strtr($entries[$x]['body'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['member_id']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['username']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } /* Entry/category */ foreach ($categories as $category) { if ($category['cat_ID'] == $entries[$x]['category']) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $pmdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($pmdb)); } while ($a = mysqli_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['post_id'] == $a['post_id']) { $author = ''; $mail = ''; $url = ''; if (!empty($a['member_id'])) { foreach ($users as $user) { if ($user['ID'] == $a['member_id']) { $author = $user['user_login']; $mail = $user['user_email']; $url = $user['url']; break; } } } $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['t_stamp'], 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['comment_ip'], 'status' => $a['status'] == 'open' ? 'approved' : 'pending', 'body' => $a['body'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); if ($a['status'] == 'open') { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $users = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $ltdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$ltdb) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($ltdb)); } /* Users */ $res = @$this->nativeQuery("SELECT \n user AS user_login,\n `password` AS user_pass,\n email AS user_email,\n full_name AS user_name,\n site_admin AS user_level,\n id AS ID\n FROM lt_users", $ltdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($ltdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => true, 'realname' => $users[$x]['user_name'], 'username' => $users[$x]['user_login'], 'userlevel' => $users[$x]['user_level'] > 0 ? USERLEVEL_ADMIN : USERLEVEL_EDITOR, 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']); // MD5 compatible if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ if (!$this->importCategories(null, 0, $ltdb)) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($ltdb)); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT \n article_id AS ID,\n UNIX_TIMESTAMP(`date`) AS tstamp, \n user_id AS post_author, \n status AS post_status,\n text AS post_content,\n topic AS post_title\n FROM lt_articles \n JOIN lt_articles_text\n ON lt_articles_text.article_id = lt_articles.id\n ORDER BY ID;", $ltdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($ltdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == '1' ? 'false' : 'true', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['tstamp'], 'body' => $this->strtr($entries[$x]['post_content'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['post_author']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } } /* Even more category stuff */ $res = @$this->nativeQuery("SELECT article_id AS postcat_post_ID, \n category_id AS postcat_cat_ID \n FROM lt_article_categories_link", $ltdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($ltdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entrycat = mysql_fetch_assoc($res); $entryid = 0; $categoryid = 0; foreach ($entries as $entry) { if ($entry['ID'] == $entrycat['postcat_post_ID']) { $entryid = $entry['entryid']; break; } } foreach ($this->categories as $category) { if ($category['cat_ID'] == $entrycat['postcat_cat_ID']) { $categoryid = $category['categoryid']; } } if ($entryid > 0 && $categoryid > 0) { $data = array('entryid' => $entryid, 'categoryid' => $categoryid); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); } } /* Comments */ $res = @$this->nativeQuery("SELECT article_id AS comment_post_ID,\n topic AS title,\n text AS comment_content,\n user_email AS comment_author_email,\n user_url AS comment_author_url,\n user_name AS comment_author,\n user_id AS comment_author_ID,\n UNIX_TIMESTAMP(`date`) AS tstamp,\n client_ip AS comment_author_IP,\n status AS comment_status\n FROM lt_articles_comments;", $ltdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($ltdb)); } while ($a = mysql_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['ID'] == $a['comment_post_ID']) { $author = ''; $mail = ''; $url = ''; if (!empty($a['comment_author_ID']) && $a['comment_author_ID'] > 0) { foreach ($users as $user) { if ($user['ID'] == $a['comment_author_ID']) { $author = $user['user_login']; $mail = $user['user_email']; $url = $user['user_url']; break; } } } if (empty($author) && empty($mail)) { $author = $a['comment_author']; $mail = $a['comment_author_email']; $url = $a['comment_author_url']; } $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['tstamp'], 'author' => $author, 'email' => $mail, 'url' => $url, 'title' => $a['title'], 'ip' => $a['comment_author_IP'], 'status' => $a['comment_status'] == '2' ? 'pending' : 'approved', 'body' => $a['comment_content'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); if ($a['comment_status'] != '2') { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
/** * Rebuild the Category Nested Set tree * * @access public * @see Based on http://www.sitepoint.com/article/hierarchical-data-database/1 * @param int The ID of the parent category to rebuild * @param int The ID of the next left category * @return int Returns the new ID */ function serendipity_rebuildCategoryTree($parent = 0, $left = 0) { global $serendipity; $right = $left + 1; $result = serendipity_db_query("SELECT categoryid FROM {$serendipity['dbPrefix']}category WHERE parentid = '" . (int) $parent . "'"); if (is_array($result)) { foreach ($result as $category) { $right = serendipity_rebuildCategoryTree($category['categoryid'], $right); } } if ($parent > 0) { serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category SET category_left='{$left}', category_right='{$right}' WHERE categoryid='{$parent}'"); } return $right + 1; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $categories = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $nucdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$nucdb) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($nucdb)); } /* Users */ $res = @$this->nativeQuery("SELECT mnumber AS ID, mname AS user_login, mpassword AS user_pass, memail AS user_email, madmin AS user_level FROM {$this->data['prefix']}member;", $nucdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($nucdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => $users[$x]['user_level'] >= 1 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']); // Nucleus uses md5, too. if ($users[$x]['user_level'] < 1) { $data['userlevel'] = USERLEVEL_EDITOR; } else { $data['userlevel'] = USERLEVEL_ADMIN; } if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ $res = @$this->nativeQuery("SELECT catid AS cat_ID, cname AS cat_name, cdesc AS category_description FROM {$this->data['prefix']}category ORDER BY catid;", $nucdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($nucdb)); } // Get all the info we need for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $categories[] = mysql_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) { $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}item ORDER BY itime;", $nucdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($nucdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['ititle']), 'isdraft' => $entries[$x]['idraft'] != '1' ? 'false' : 'true', 'allow_comments' => $entries[$x]['iclosed'] == '1' ? 'false' : 'true', 'timestamp' => strtotime($entries[$x]['itime']), 'extended' => $this->strtr($entries[$x]['imore']), 'body' => $this->strtr($entries[$x]['ibody'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['iauthor']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['realname']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } /* Entry/category */ foreach ($categories as $category) { if ($category['cat_ID'] == $entries[$x]['icat']) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comment;", $nucdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($nucdb)); } while ($a = mysql_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['inumber'] == $a['citem']) { $author = ''; $mail = ''; if (!empty($a['cmember'])) { foreach ($users as $user) { if ($user['ID'] == $a['cmember']) { $author = $user['user_login']; $mail = $user['user_email']; break; } } } if (empty($author) && empty($mail)) { $author = $a['cuser']; $mail = $a['cmail']; } $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['ctime']), 'author' => $author, 'email' => $mail, 'url' => $a['chost'], 'ip' => $a['cip'], 'status' => 'approved', 'body' => $a['cbody'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import_cat(&$s9ydb) { global $serendipity; $this->import_table($s9ydb, 'category', array('categoryid'), ' ORDER BY parentid ASC', false, array('authorid' => array('authors' => 'authorid'), 'parentid' => array('category' => 'categoryid'))); $this->import_table($s9ydb, 'entrycat', false, null, false, array('entryid' => array('entries' => 'id'), 'categoryid' => array('category' => 'categoryid'))); $this->import_table($s9ydb, 'permalinks', false, ' WHERE type = "category" ', false, array('entry_id' => array('category' => 'categoryid'))); $this->import_table($s9ydb, 'access', false, ' WHERE artifact_type = "category" ', false, array('groupid' => array('groups' => 'id'), 'artifact_id' => array('category' => 'categoryid'))); serendipity_rebuildCategoryTree(); }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $users = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $b2db = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$b2db) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($b2db)); } /* Users */ $res = @$this->nativeQuery("SELECT ID AS ID,\n user_login AS user_login,\n user_pass AS user_pass,\n user_email AS user_email,\n user_level AS user_level,\n user_url AS user_url\n FROM evo_users", $b2db); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($b2db)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => $users[$x]['user_level'] >= 2 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => $users[$x]['user_pass']); // MD5 compatible if ($users[$x]['user_level'] <= 2) { $data['userlevel'] = USERLEVEL_EDITOR; } elseif ($users[$x]['user_level'] <= 9) { $data['userlevel'] = USERLEVEL_CHIEF; } else { $data['userlevel'] = USERLEVEL_ADMIN; } if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ if (!$this->importCategories(null, 0, $b2db)) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($b2db)); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT * FROM evo_posts ORDER BY ID;", $b2db); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($b2db)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == 'published' ? 'false' : 'true', 'allow_comments' => $entries[$x]['post_comments'] == 'open' ? 'true' : 'false', 'timestamp' => strtotime(isset($entries[$x]['post_issue_date']) ? $entries[$x]['post_issue_date'] : $entries[$x]['post_date']), 'body' => $this->strtr($entries[$x]['post_content'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['post_author']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } /* Entry/category */ foreach ($this->categories as $category) { if ($category['cat_ID'] == $entries[$x]['post_category']) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } } /* Even more category stuff */ $res = @$this->nativeQuery("SELECT * FROM evo_postcats;", $b2db); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($b2db)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entrycat = mysql_fetch_assoc($res); $entryid = 0; $categoryid = 0; foreach ($entries as $entry) { if ($entry['ID'] == $entrycat['postcat_post_ID']) { $entryid = $entry['entryid']; break; } } foreach ($this->categories as $category) { if ($category['cat_ID'] == $entrycat['postcat_cat_ID']) { $categoryid = $category['categoryid']; } } if ($entryid > 0 && $categoryid > 0) { $data = array('entryid' => $entryid, 'categoryid' => $categoryid); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); } } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM evo_comments;", $b2db); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($b2db)); } while ($a = mysql_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['ID'] == $a['comment_post_ID']) { $author = ''; $mail = ''; $url = ''; if (!empty($a['comment_author_ID'])) { foreach ($users as $user) { if ($user['ID'] == $a['comment_author_ID']) { $author = $user['user_login']; $mail = $user['user_email']; $url = $user['user_url']; break; } } } if (empty($author) && empty($mail)) { $author = $a['comment_author']; $mail = $a['comment_author_email']; $url = $a['comment_author_url']; } $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['comment_date']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['comment_author_IP'], 'status' => $a['comment_status'] == 'published' ? 'approved' : 'pending', 'body' => $a['comment_content'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); if ($a['comment_status'] == 'published') { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; static $debug = true; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $categories = array(); $entries = array(); if (!extension_loaded('mysqli')) { return MYSQL_REQUIRED; } if (function_exists('set_time_limit')) { @set_time_limit(300); } $wpdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$wpdb || mysqli_connect_error()) { return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host'])); } if (!@mysqli_select_db($wpdb, $this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysqli_error($wpdb)); } // This will hold the s9y <-> WP ID associations. $assoc = array(); /* Users */ // Fields: ID, user_login, user_pass, user_email, user_level $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}users;", $wpdb); if (!$res) { printf(COULDNT_SELECT_USER_INFO, mysqli_error($wpdb)); } else { if ($debug) { echo "<span class='block_level'>Importing users...</span>"; } for ($x = 0, $c = mysqli_num_rows($res); $x < $c; $x++) { $users[$x] = mysqli_fetch_assoc($res); $data = array('right_publish' => !isset($users[$x]['user_level']) || $users[$x]['user_level'] >= 1 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'password' => $users[$x]['user_pass']); // WP uses md5, too. if (isset($users[$x]['user_level']) && $users[$x]['user_level'] <= 1) { $data['userlevel'] = USERLEVEL_EDITOR; } elseif (isset($users[$x]['user_level']) && $users[$x]['user_level'] < 5) { $data['userlevel'] = USERLEVEL_CHIEF; } else { $data['userlevel'] = USERLEVEL_ADMIN; } if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); // Set association. $assoc['users'][$users[$x]['ID']] = $users[$x]['authorid']; } if ($debug) { echo "<span class='msg_success'>Imported users.</span>"; } // Clean memory unset($users); } $no_cat = false; /* Categories (WP < 2.3 style) */ $res = @$this->nativeQuery("SELECT cat_ID, cat_name, category_description, category_parent \n FROM {$this->data['prefix']}categories \n ORDER BY category_parent, cat_ID;", $wpdb); if (!$res) { $no_cat = mysqli_error($wpdb); } else { if ($debug) { echo "<span class='block_level'>Importing categories (WP 2.2 style)...</span>"; } // Get all the info we need for ($x = 0; $x < mysqli_num_rows($res); $x++) { $categories[] = mysqli_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0, $c = sizeof($categories); $x < $c; $x++) { $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); // Set association. $assoc['categories'][$categories[$x]['cat_ID']] = $categories[$x]['categoryid']; } foreach ($categories as $cat) { if ($cat['category_parent'] != 0) { // Find the parent $par_id = 0; foreach ($categories as $possible_par) { if ($possible_par['cat_ID'] == $cat['category_parent']) { $par_id = $possible_par['categoryid']; break; } } if ($par_id != 0) { serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category \n SET parentid={$par_id} \n WHERE categoryid={$cat['categoryid']};"); } } } // Clean memory unset($categories); if ($debug) { echo "<span class='block_level'>Imported categories.</span>"; } if ($debug) { echo "<span class='block_level'>Rebuilding category tree...</span>"; } serendipity_rebuildCategoryTree(); if ($debug) { echo "<span class='block_level'>Rebuilt category tree.</span>"; } } /* Categories (WP >= 2.3 style) */ $res = @$this->nativeQuery("SELECT taxonomy.description AS category_description, \n taxonomy.parent AS category_parent, \n taxonomy.term_taxonomy_id AS cat_ID, \n terms.name AS cat_name\n\n FROM {$this->data['prefix']}term_taxonomy AS taxonomy\n\n JOIN {$this->data['prefix']}terms AS terms\n ON taxonomy.term_id = terms.term_id\n\n WHERE taxonomy.taxonomy = 'category' \n ORDER BY taxonomy.parent, taxonomy.term_taxonomy_id", $wpdb); if (!$res && !$no_cat) { $no_cat = mysqli_error($wpdb); } elseif ($res) { $no_cat = false; if ($debug) { echo "<span class='block_level'>Importing categories (WP 2.3 style)...</span>"; } // Get all the info we need for ($x = 0; $x < mysqli_num_rows($res); $x++) { $categories[] = mysqli_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0, $c = sizeof($categories); $x < $c; $x++) { $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); // Set association. $assoc['categories'][$categories[$x]['cat_ID']] = $categories[$x]['categoryid']; } foreach ($categories as $cat) { if ($cat['category_parent'] != 0) { // Find the parent $par_id = 0; foreach ($categories as $possible_par) { if ($possible_par['cat_ID'] == $cat['category_parent']) { $par_id = $possible_par['categoryid']; break; } } if ($par_id != 0) { serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category \n SET parentid={$par_id} \n WHERE categoryid={$cat['categoryid']};"); } } } // Clean memory unset($categories); if ($debug) { echo "<span class='block_level'>Imported categories.</span>"; } if ($debug) { echo "<span class='block_level'>Rebuilding category tree...</span>"; } serendipity_rebuildCategoryTree(); if ($debug) { echo "<span class='block_level'>Rebuilt category tree.</span>"; } } if ($no_cat) { printf(COULDNT_SELECT_CATEGORY_INFO, $no_cat); } /* Entries */ if (serendipity_db_bool($this->data['import_all'])) { $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts WHERE post_status IN ('publish', 'draft') ORDER BY post_date;", $wpdb); } else { $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;", $wpdb); } if (!$res) { printf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($wpdb)); } else { if ($debug) { echo "<span class='block_level'>Importing entries...</span>"; } for ($x = 0, $c = mysqli_num_rows($res); $x < $c; $x++) { $entries[$x] = mysqli_fetch_assoc($res); $content = explode('<!--more-->', $entries[$x]['post_content'], 2); $body = $content[0]; $extended = $content[1]; $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == 'publish' ? 'false' : 'true', 'allow_comments' => $entries[$x]['comment_status'] == 'open' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['post_date']), 'body' => $this->strtr($body), 'extended' => $this->strtr($extended), 'authorid' => $assoc['users'][$entries[$x]['post_author']]); if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { printf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($wpdb)); echo "<span class='block_level'>ID: {$entries[$x]['ID']} - {$entry['title']}</span>"; return $entries[$x]['entryid']; } $assoc['entries'][$entries[$x]['ID']] = $entries[$x]['entryid']; } if ($debug) { echo "<span class='msg_success'>Imported entries...</span>"; } // Clean memory unset($entries); } /* Entry/category (WP < 2.3 style)*/ $no_entrycat = false; $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}post2cat;", $wpdb); if (!$res) { $no_entrycat = mysqli_error($wpdb); } else { if ($debug) { echo "<span class='block_level'>Importing category associations (WP 2.2 style)...</span>"; } while ($a = mysqli_fetch_assoc($res)) { $data = array('entryid' => $assoc['entries'][$a['post_id']], 'categoryid' => $assoc['categories'][$a['category_id']]); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); } if ($debug) { echo "<span class='msg_success'>Imported category associations.</span>"; } } /* Entry/category (WP > 2.3 style)*/ $res = @$this->nativeQuery("SELECT rel.object_id AS post_id, \n rel.term_taxonomy_id AS category_id \n FROM {$this->data['prefix']}term_relationships AS rel;", $wpdb); if (!$res && !$no_entrycat) { $no_entrycat = mysqli_error($wpdb); } elseif ($res) { $no_entrycat = false; if ($debug) { echo "<span class='block_level'>Importing category associations (WP 2.3 style)...</span>"; } while ($a = mysqli_fetch_assoc($res)) { $data = array('entryid' => $assoc['entries'][$a['post_id']], 'categoryid' => $assoc['categories'][$a['category_id']]); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); } if ($debug) { echo "<span class='msg_success'>Imported category associations.</span>"; } } if ($no_entrycat) { printf(COULDNT_SELECT_ENTRY_INFO, $no_entrycat); } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $wpdb); if (!$res) { printf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($wpdb)); } else { $serendipity['allowSubscriptions'] = false; if ($debug) { echo "<span class='block_level'>Importing comments...</span>"; } while ($a = mysqli_fetch_assoc($res)) { $comment = array('entry_id ' => $assoc['entries'][$a['comment_post_ID']], 'parent_id' => 0, 'timestamp' => strtotime($a['comment_date']), 'author' => $a['comment_author'], 'email' => $a['comment_author_email'], 'url' => $a['comment_author_url'], 'ip' => $a['comment_author_IP'], 'status' => empty($a['comment_approved']) || $a['comment_approved'] == '1' ? 'approved' : 'pending', 'subscribed' => 'false', 'body' => $a['comment_content'], 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); if ($comment['status'] == 'approved') { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $assoc['entries'][$a['comment_post_ID']], true); } } if ($debug) { echo "<span class='msg_success'>Imported comments.</span>"; } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
if (!serendipity_checkPermission('adminCategoriesMaintainOthers') && !serendipity_ACLCheck($serendipity['authorid'], $serendipity['GET']['cid'], 'category', 'write')) { $data['editPermission'] = false; } else { /* Check to make sure parent is not a child of self */ $r = serendipity_db_query("SELECT categoryid FROM {$serendipity['dbPrefix']}category c\n WHERE c.categoryid = " . (int) $parentid . "\n AND c.category_left BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange((int) $serendipity['GET']['cid']))); if (is_array($r)) { $r = serendipity_db_query("SELECT category_name FROM {$serendipity['dbPrefix']}category\n WHERE categoryid = " . (int) $parentid); $data['subcat'] = sprintf(ALREADY_SUBCATEGORY, serendipity_specialchars($r[0]['category_name']), serendipity_specialchars($name)); } else { serendipity_updateCategory($serendipity['GET']['cid'], $name, $desc, $authorid, $icon, $parentid, $serendipity['POST']['cat']['sort_order'], $serendipity['POST']['cat']['hide_sub'], $admin_category); serendipity_ACLGrant($serendipity['GET']['cid'], 'category', 'read', $serendipity['POST']['cat']['read_authors']); serendipity_ACLGrant($serendipity['GET']['cid'], 'category', 'write', $serendipity['POST']['cat']['write_authors']); } } } serendipity_rebuildCategoryTree(); $serendipity['GET']['adminAction'] = 'view'; } /* Delete a category */ if ($serendipity['GET']['adminAction'] == 'doDelete' && serendipity_checkFormToken()) { $data['doDelete'] = true; if ($serendipity['GET']['cid'] != 0) { $remaining_cat = (int) $serendipity['POST']['cat']['remaining_catid']; $category_ranges = serendipity_fetchCategoryRange((int) $serendipity['GET']['cid']); $category_range = implode(' AND ', $category_ranges); if ($serendipity['dbType'] == 'postgres' || $serendipity['dbType'] == 'sqlite' || $serendipity['dbType'] == 'sqlite3' || $serendipity['dbType'] == 'sqlite3oo' || $serendipity['dbType'] == 'pdo-sqlite') { $query = "UPDATE {$serendipity['dbPrefix']}entrycat\n SET categoryid={$remaining_cat} WHERE entryid IN\n (\n SELECT DISTINCT(e.id) FROM {$serendipity['dbPrefix']}entries e,\n {$serendipity['dbPrefix']}category c,\n {$serendipity['dbPrefix']}entrycat ec\n WHERE e.id=ec.entryid AND c.categoryid=ec.categoryid\n AND c.category_left BETWEEN {$category_range} {$admin_category}\n )"; } else { $query = "UPDATE {$serendipity['dbPrefix']}entries e,\n {$serendipity['dbPrefix']}entrycat ec,\n {$serendipity['dbPrefix']}category c\n SET ec.categoryid={$remaining_cat}\n WHERE e.id = ec.entryid\n AND c.categoryid = ec.categoryid\n AND c.category_left BETWEEN {$category_range}\n {$admin_category}"; } serendipity_db_query($query);
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $gdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$gdb) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($gdb)); } /* Users */ $res = @$this->nativeQuery("SELECT uid AS ID,\n username AS user_login,\n passwd AS user_pass,\n email AS user_email,\n homepage AS user_url\n FROM {$this->data['prefix']}users", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($gdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => USERLEVEL_ADMIN, 'password' => $users[$x]['user_pass']); // MD5 compatible if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); echo mysql_error(); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ $res = @$this->nativeQuery("SELECT tid AS cat_ID, topic AS cat_name, topic AS category_description FROM {$this->data['prefix']}topics ORDER BY tid;", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb)); } // Get all the info we need for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $categories[] = mysql_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) { $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}stories ORDER BY sid;", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($gdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['draft_flag'] == '0' ? 'false' : 'true', 'allow_comments' => $entries[$x]['comments'] == '1' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['date']), 'body' => $this->strtr($entries[$x]['introtext']), 'extended' => $this->strtr($entries[$x]['bodytext'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['uid']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } /* Entry/category */ foreach ($categories as $category) { if ($category['cat_ID'] == $entries[$x]['tid']) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($gdb)); } while ($a = mysql_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['sid'] == $a['sid']) { $author = ''; $mail = ''; $url = ''; foreach ($users as $user) { if ($user['ID'] == $a['uid']) { $author = $user['user_login']; $mail = $user['user_email']; $url = $user['user_url']; break; } } $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['date']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['comment'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $txpdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$txpdb) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($txpdb)); } /* Users */ $res = @$this->nativeQuery("SELECT user_id AS ID,\n name AS user_login,\n `pass` AS user_pass,\n email AS user_email,\n privs AS user_level\n FROM {$this->data['prefix']}txp_users", $txpdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($txpdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => $users[$x]['user_level'] <= 4 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'password' => md5('txp')); // blame TXP for using PASSWORD(). if ($users[$x]['user_level'] == 1) { $data['userlevel'] = USERLEVEL_EDITOR; } elseif ($users[$x]['user_level'] == 2) { $data['userlevel'] = USERLEVEL_CHIEF; } else { $data['userlevel'] = USERLEVEL_ADMIN; } if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ if (!$this->importCategories('root', 0, $txpdb)) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($txpdb)); } serendipity_rebuildCategoryTree(); /* Entries */ // Notice: Textpattern doesn't honor the prefix for this table. Wicked system. $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}textpattern ORDER BY Posted;", $txpdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($txpdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['Title']), 'isdraft' => $entries[$x]['Status'] == '4' ? 'false' : 'true', 'allow_comments' => $entries[$x]['Annotate'] == '1' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['Posted']), 'extended' => $this->strtr($entries[$x]['Body_html']), 'body' => $this->strtr($entries[$x]['Excerpt'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['user_login'] == $entries[$x]['AuthorID']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } /* Entry/category */ foreach ($this->categories as $category) { if ($category['name'] == $entries[$x]['Category1'] || $category['name'] == $entries[$x]['Category2']) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}txp_discuss;", $txpdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($txpdb)); } while ($a = mysql_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['ID'] == $a['parentid']) { $author = $a['name']; $mail = $a['email']; $url = $a['web']; $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['posted']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => $a['ip'], 'status' => $a['visible'] == '1' ? 'approved' : 'pending', 'body' => $a['message'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); if ($a['visible'] == '1') { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function importOPML() { $tree = $this->importFeeds(); if (!$tree) { return; } $this->removeFeeds(); $this->cats = serendipity_fetchCategories(); foreach ($tree as $xml_base) { if ($xml_base['tag'] != 'opml' || !is_array($xml_base['children'])) { continue; } foreach ($xml_base['children'] as $xml_body) { if ($xml_body['tag'] != 'body' || !is_array($xml_body['children'])) { continue; } foreach ($xml_body['children'] as $xml_outline) { $this->parseOutline($xml_outline); } } } serendipity_rebuildCategoryTree(); }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $gdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$gdb) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($gdb)); } /* Users */ $res = @$this->nativeQuery("SELECT ID_MEMBER AS ID,\r\n memberName AS user_login,\r\n passwd AS user_pass,\r\n emailAddress AS user_email,\r\n ID_GROUP AS user_level\r\n FROM {$this->data['prefix']}members\r\n WHERE is_activated = 1", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($gdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => $users[$x]['user_level'] == 1 ? USERLEVEL_ADMIN : USERLEVEL_EDITO, 'password' => $users[$x]['user_pass']); // MD5 compatible if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); echo mysql_error(); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ $res = @$this->nativeQuery("SELECT ID_CAT AS cat_ID,\r\n name AS cat_name\r\n FROM {$this->data['prefix']}categories", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb)); } // Get all the info we need for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $parent_categories[] = mysql_fetch_assoc($res); } for ($x = 0, $max_x = sizeof($parent_categories); $x < $max_x; $x++) { $cat = array('category_name' => $parent_categories[$x]['cat_name'], 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $parent_categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } /* Categories */ $res = @$this->nativeQuery("SELECT ID_BOARD AS cat_ID,\r\n ID_CAT AS parent_cat_id,\r\n name AS cat_name,\r\n description AS category_description\r\n FROM {$this->data['prefix']}boards ORDER BY boardOrder;", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb)); } // Get all the info we need for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $categories[] = mysql_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) { $pcatid = 0; foreach ($parent_categories as $pcat) { if ($pcat['cat_ID'] == $categories[$x]['parent_cat_id']) { $pcatid = $pcat['cat_ID']; break; } } $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => $pcatid, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT\r\n\r\n tm.subject AS post_subject,\r\n t.ID_MEMBER_STARTED AS topic_poster,\r\n t.ID_BOARD AS forum_id,\r\n tm.posterTime AS post_time,\r\n tm.body AS post_text,\r\n t.ID_TOPIC AS topic_id,\r\n t.ID_FIRST_MSG AS post_id,\r\n t.numReplies AS ccount\r\n\r\n FROM {$this->data['prefix']}topics AS t\r\n JOIN {$this->data['prefix']}messages AS tm\r\n ON tm.ID_MSG = t.ID_FIRST_MSG\r\n\r\n GROUP BY t.ID_TOPIC", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($gdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['post_subject']), 'isdraft' => 'false', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['post_time'], 'body' => $this->strtr($entries[$x]['post_text']), 'extended' => ''); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['topic_poster']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } /* Entry/category */ foreach ($categories as $category) { if ($category['cat_ID'] == $entries[$x]['forum_id']) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } $topic_id = $entries[$x]['topic_id']; // Store original ID, we might need it at some point. serendipity_db_insert('entryproperties', array('entryid' => $entries[$x]['entryid'], 'property' => 'foreign_import_id', 'value' => $entries[$x]['topic_id'])); // Convert SMF tags $t_res = @$this->nativeQuery("SELECT t.tag\r\n FROM {$this->data['prefix']}tags_log AS tl\r\n JOIN {$this->data['prefix']}tags AS t\r\n ON tl.ID_TAG = t.ID_TAG\r\n WHERE tl.ID_TOPIC = {$topic_id}\r\n AND t.approved = 1"); if (mysql_num_rows($t_res) > 0) { while ($a = mysql_fetch_assoc($t_res)) { serendipity_db_insert('entrytags', array('entryid' => $entries[$x]['entryid'], 'tag' => $t_res['tag'])); } } /* Comments */ $c_res = @$this->nativeQuery("SELECT\r\n tm.subject AS post_subject,\r\n tm.body AS post_text,\r\n tm.ID_MSG AS post_id,\r\n tm.posterTime AS post_time,\r\n tm.ID_BOARD AS forum_id,\r\n tm.posterName AS poster_name,\r\n tm.posterEmail AS poster_email\r\n\r\n FROM {$this->data['prefix']}topics AS t\r\n JOIN {$this->data['prefix']}messages AS tm\r\n ON tm.ID_TOPIC = t.ID_TOPIC\r\n WHERE t.ID_TOPIC = {$topic_id}\r\n ", $gdb); if (!$c_res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($gdb)); } while ($a = mysql_fetch_assoc($c_res)) { if ($a['post_id'] == $entries[$x]['post_id']) { continue; } $author = $a['poster_name']; $mail = $a['poster_email']; $url = ''; foreach ($users as $user) { if ($user['ID'] == $a['poster_id']) { $author = $user['user_login']; $mail = $user['user_email']; $url = $user['user_url']; break; } } $a['post_text'] = html_entity_decode($a['post_text']); $comment = array('entry_id ' => $entries[$x]['entryid'], 'parent_id' => 0, 'timestamp' => $a['post_time'], 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => '', 'status' => 'approved', 'body' => $a['post_text'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entries[$x]['entryid'], true); } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $users = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $nukedb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$nukedb) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($nukedb)); } /* Users: Authors */ $res = @$this->nativeQuery("SELECT\n aid AS user_login,\n `pwd` AS user_pass,\n email AS user_email,\n name AS user_name,\n radminsuper AS user_level,\n aid AS ID\n FROM nuke_authors", $nukedb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($nukedb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => true, 'realname' => $users[$x]['user_name'], 'username' => $users[$x]['user_login'], 'userlevel' => $users[$x]['user_level'] > 0 ? USERLEVEL_ADMIN : USERLEVEL_EDITOR, 'email' => $users[$x]['user_email'], 'password' => md5($users[$x]['user_pass'])); if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Users: Users */ $res = @$this->nativeQuery("SELECT\n u.uname AS user_login,\n u.pass AS user_pass,\n u.email AS user_email,\n u.name AS user_name,\n s.user_level AS user_level,\n uname AS ID\n FROM nuke_users AS u\n JOIN nuke_users_status AS s\n ON u.uid = s.user_id\n ", $nukedb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($nukedb)); } for ($x = $x, $max_x = $x + mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); if (empty($users[$x]['user_name'])) { $users[$x]['user_name'] = $users[$x]['user_login']; } $data = array('right_publish' => true, 'realname' => $users[$x]['user_name'], 'username' => $users[$x]['user_login'], 'userlevel' => $users[$x]['user_level'] > 1 ? USERLEVEL_ADMIN : USERLEVEL_EDITOR, 'email' => $users[$x]['user_email'], 'password' => md5($users[$x]['user_pass'])); if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ if (!$this->importCategories($nukedb)) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($nukedb)); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT\n sid AS ID,\n UNIX_TIMESTAMP(`time`) AS tstamp,\n aid AS post_author,\n informant AS informant,\n \n title AS post_title,\n hometext AS post_content,\n bodytext AS extended\n FROM nuke_stories", $nukedb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($nukedb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); if (!empty($entries[$x]['informant'])) { $entries[$x]['post_author'] = $entries[$x]['informant']; } $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => 'false', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['tstamp'], 'body' => $this->strtr($entries[$x]['post_content']), 'extended' => $this->strtr($entries[$x]['extended'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['post_author']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } } /* Even more category stuff */ $res = @$this->nativeQuery("SELECT sid AS postcat_post_ID,\n topic AS postcat_cat_ID\n FROM nuke_stories", $nukedb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($nukedb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entrycat = mysql_fetch_assoc($res); $entryid = 0; $categoryid = 0; foreach ($entries as $entry) { if ($entry['ID'] == $entrycat['postcat_post_ID']) { $entryid = $entry['entryid']; break; } } foreach ($this->categories as $category) { if ($category['cat_ID'] == $entrycat['postcat_cat_ID']) { $categoryid = $category['categoryid']; } } if ($entryid > 0 && $categoryid > 0) { $data = array('entryid' => $entryid, 'categoryid' => $categoryid); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); } } /* Comments */ $res = @$this->nativeQuery("SELECT sid AS comment_post_ID,\n subject AS title,\n comment AS comment_content,\n email AS comment_author_email,\n url AS comment_author_url,\n name AS comment_author,\n UNIX_TIMESTAMP(`date`) AS tstamp\n FROM nuke_comments", $nukedb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($nukedb)); } while ($a = mysql_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['ID'] == $a['comment_post_ID']) { $author = $a['comment_author']; $mail = $a['comment_author_email']; $url = $a['comment_author_url']; $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['tstamp'], 'author' => $author, 'email' => $mail, 'url' => $url, 'title' => $a['title'], 'ip' => '', 'status' => 'approved', 'body' => $a['comment_content'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $categories = array(); $entries = array(); if (!extension_loaded('pgsql')) { return PGSQL_REQUIRED; } $wpdb = pg_connect("{$this->data}['host'], {$this->data}['port'], {$this->data}['user'], {$this->data}['pass'], {$this->data}['name']"); if (!$wpdb) { return sprintf(PGSQL_COULDNT_CONNECT, $this->data['pass']); } /* Users */ $res = pg_query($wpdb, "SELECT ID, user_login, user_pass, user_email, user_level FROM {$this->data['prefix']}users;"); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, pg_last_error($wpdb)); } for ($x = 0; $x < pg_num_rows($res); $x++) { $users[$x] = pg_fetch_assoc($res); $data = array('right_publish' => $users[$x]['user_level'] >= 1 ? 1 : 0, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'password' => $users[$x]['user_pass']); // WP uses md5, too. if ($users[$x]['user_level'] <= 1) { $data['userlevel'] = USERLEVEL_EDITOR; } elseif ($users[$x]['user_level'] < 5) { $data['userlevel'] = USERLEVEL_CHIEF; } else { $data['userlevel'] = USERLEVEL_ADMIN; } if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ $res = @pg_query($wpdb, "SELECT cat_ID, cat_name, category_description, category_parent FROM {$this->data['prefix']}categories ORDER BY category_parent, cat_ID;"); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, pg_last_error($wpdb)); } // Get all the info we need for ($x = 0; $x < pg_num_rows($res); $x++) { $categories[] = pg_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0; $x < sizeof($categories); $x++) { $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } // There has to be a more efficient way of doing this... foreach ($categories as $cat) { if ($cat['category_parent'] != 0) { // Find the parent $par_id = 0; foreach ($categories as $possible_par) { if ($possible_par['cat_ID'] == $cat['category_parent']) { $par_id = $possible_par['categoryid']; break; } } if ($par_id != 0) { serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category SET parentid={$par_id} WHERE categoryid={$cat['categoryid']};"); } // else { echo "D'oh! " . random_string_of_profanity(); } } } serendipity_rebuildCategoryTree(); /* Entries */ $res = @pg_query($wpdb, "SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;"); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, pg_last_error($wpdb)); } for ($x = 0; $x < pg_num_rows($res); $x++) { $entries[$x] = pg_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['post_title']), 'isdraft' => $entries[$x]['post_status'] == 'publish' ? 'false' : 'true', 'allow_comments' => $entries[$x]['comment_status'] == 'open' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['post_date']), 'body' => $this->strtr($entries[$x]['post_content'])); foreach ($users as $user) { if ($user['ID'] == $entries[$x]['post_author']) { $entry['authorid'] = $user['authorid']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } } /* Entry/category */ $res = @pg_query($wpdb, "SELECT * FROM {$this->data['prefix']}post2cat;"); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, pg_last_error($wpdb)); } while ($a = pg_fetch_assoc($res)) { foreach ($categories as $category) { if ($category['cat_ID'] == $a['category_id']) { foreach ($entries as $entry) { if ($a['post_id'] == $entry['ID']) { $data = array('entryid' => $entry['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } break; } } } /* Comments */ $res = @pg_query($wpdb, "SELECT * FROM {$this->data['prefix']}comments;"); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, pg_last_error($wpdb)); } while ($a = pg_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['ID'] == $a['comment_post_ID']) { $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['comment_date']), 'author' => $a['comment_author'], 'email' => $a['comment_author_email'], 'url' => $a['comment_author_url'], 'ip' => $a['comment_author_IP'], 'status' => empty($a['comment_approved']) || $a['comment_approved'] == '1' ? 'approved' : 'pending', 'subscribed' => 'false', 'body' => $a['comment_content'], 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); if ($comment['status'] == 'approved') { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $entries = array(); if (!extension_loaded('mysqli')) { return MYSQL_REQUIRED; } $gdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$gdb || mysqli_connect_error()) { return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host'])); } if (!@mysqli_select_db($gdb, $this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysqli_error($gdb)); } /* Users */ $res = @$this->nativeQuery("SELECT user_id AS ID,\n username AS user_login,\n user_password AS user_pass,\n user_email AS user_email,\n user_website AS user_url,\n user_level\n FROM {$this->data['prefix']}users\n WHERE user_active = 1", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysqli_error($gdb)); } for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysqli_fetch_assoc($res); $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => $users[$x]['user_level'] == 0 ? USERLEVEL_EDITOR : USERLEVEL_ADMIN, 'password' => $users[$x]['user_pass']); // MD5 compatible if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); echo mysqli_error(); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ $res = @$this->nativeQuery("SELECT cat_id AS cat_ID, \n cat_title AS cat_name \n FROM {$this->data['prefix']}categories", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($gdb)); } // Get all the info we need for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $parent_categories[] = mysqli_fetch_assoc($res); } for ($x = 0, $max_x = sizeof($parent_categories); $x < $max_x; $x++) { $cat = array('category_name' => $parent_categories[$x]['cat_name'], 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $parent_categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } /* Categories */ $res = @$this->nativeQuery("SELECT forum_id AS cat_ID,\n cat_id AS parent_cat_id, \n forum_name AS cat_name, \n forum_desc AS category_description \n FROM {$this->data['prefix']}forums ORDER BY forum_order;", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($gdb)); } // Get all the info we need for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $categories[] = mysqli_fetch_assoc($res); } // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). for ($x = 0, $max_x = sizeof($categories); $x < $max_x; $x++) { $pcatid = 0; foreach ($parent_categories as $pcat) { if ($pcat['cat_ID'] == $categories[$x]['parent_cat_id']) { $pcatid = $pcat['cat_ID']; break; } } $cat = array('category_name' => $categories[$x]['cat_name'], 'category_description' => $categories[$x]['category_description'], 'parentid' => $pcatid, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT t.topic_title, \n t.topic_poster,\n t.forum_id,\n p.post_time,\n pt.post_subject,\n pt.post_text,\n count(p.topic_id) AS ccount,\n p.topic_id,\n MIN(p.post_id) AS post_id\n FROM {$this->data['prefix']}topics AS t\n LEFT OUTER JOIN {$this->data['prefix']}posts AS p\n ON t.topic_id = p.topic_id\n LEFT OUTER JOIN {$this->data['prefix']}posts_text AS pt\n ON pt.post_id = p.post_id\n GROUP BY p.topic_id\n ", $gdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($gdb)); } for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysqli_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['post_subject']), 'isdraft' => 'false', 'allow_comments' => 'true', 'timestamp' => $entries[$x]['post_time'], 'body' => $this->strtr($entries[$x]['post_text']), 'extended' => ''); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['topic_poster']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } /* Entry/category */ foreach ($categories as $category) { if ($category['cat_ID'] == $entries[$x]['forum_id']) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $category['categoryid']); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); break; } } /* Comments */ $topic_id = $entries[$x]['topic_id']; $c_res = @$this->nativeQuery("SELECT t.topic_title, \n t.topic_poster,\n p.poster_id,\n t.forum_id,\n p.post_time,\n pt.post_subject,\n pt.post_text,\n pt.post_id\n FROM {$this->data['prefix']}topics AS t\n LEFT OUTER JOIN {$this->data['prefix']}posts AS p\n ON t.topic_id = p.topic_id\n LEFT OUTER JOIN {$this->data['prefix']}posts_text AS pt\n ON pt.post_id = p.post_id\n WHERE p.topic_id = {$topic_id} \n ", $gdb); if (!$c_res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($gdb)); } while ($a = mysqli_fetch_assoc($c_res)) { if ($a['post_id'] == $entries[$x]['post_id']) { continue; } $author = ''; $mail = ''; $url = ''; foreach ($users as $user) { if ($user['ID'] == $a['poster_id']) { $author = $user['user_login']; $mail = $user['user_email']; $url = $user['user_url']; break; } } $comment = array('entry_id ' => $entries[$x]['entryid'], 'parent_id' => 0, 'timestamp' => $a['post_time'], 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => '', 'status' => 'approved', 'body' => $a['post_text'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entries[$x]['entryid'], true); } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $entries = array(); if (!extension_loaded('mysql')) { return MYSQL_REQUIRED; } $sunlogdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$sunlogdb) { return sprintf(COULDNT_CONNECT, $this->data['host']); } if (!@mysql_select_db($this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysql_error($sunlogdb)); } /* Users */ $res = @$this->nativeQuery("SELECT id AS ID,\n name AS user_login,\n email AS user_email,\n homepage AS user_url\n FROM {$this->data['prefix']}users", $sunlogdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($sunlogdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysql_fetch_assoc($res); $data = array('right_publish' => 1, 'realname' => $users[$x]['user_login'], 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => USERLEVEL_ADMIN, 'password' => md5('sunlog')); if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); echo mysql_error(); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ if (!$this->importCategories(null, 0, $sunlogdb)) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb)); } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}articles ORDER BY id;", $sunlogdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($sunlogdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysql_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['draft'] == '0' ? 'false' : 'true', 'allow_comments' => $entries[$x]['c_comments'] == '1' ? 'true' : 'false', 'timestamp' => strtotime($entries[$x]['timestamp']), 'body' => $this->strtr($entries[$x]['lead_converted']), 'extended' => $this->strtr($entries[$x]['article_converted'])); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['author']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } } /* Even more category stuff */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}transfer_c;", $sunlogdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb)); } for ($x = 0, $max_x = mysql_num_rows($res); $x < $max_x; $x++) { $entrycat = mysql_fetch_assoc($res); $entryid = 0; $categoryid = 0; foreach ($entries as $entry) { if ($entry['id'] == $entrycat['article']) { $entryid = $entry['entryid']; break; } } foreach ($this->categories as $category) { if ($category['id'] == $entrycat['category']) { $categoryid = $category['categoryid']; } } if ($entryid > 0 && $categoryid > 0) { $data = array('entryid' => $entryid, 'categoryid' => $categoryid); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); } } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}c_comments;", $sunlogdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($sunlogdb)); } while ($a = mysql_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['id'] == $a['for_entry']) { $author = ''; $mail = ''; $url = ''; foreach ($users as $user) { if ($user['ID'] == $a['user']) { $author = $user['user_login']; $mail = $user['user_email']; $url = $user['user_url']; break; } } $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => strtotime($a['insertdate']), 'author' => $author, 'email' => $mail, 'url' => $url, 'ip' => '', 'status' => 'approved', 'body' => $a['comment'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }
function import() { global $serendipity; // Save this so we can return it to its original value at the end of this method. $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } $this->getTransTable(); $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']); $users = array(); $entries = array(); if (!extension_loaded('mysqli')) { return MYSQL_REQUIRED; } $bblogdb = @mysqli_connect($this->data['host'], $this->data['user'], $this->data['pass']); if (!$bblogdb || mysqli_connect_error()) { return sprintf(COULDNT_CONNECT, serendipity_specialchars($this->data['host'])); } if (!@mysqli_select_db($bblogdb, $this->data['name'])) { return sprintf(COULDNT_SELECT_DB, mysqli_error($bblogdb)); } /* Users */ $res = @$this->nativeQuery("SELECT id AS ID,\n password AS pw,\n nickname AS user_login,\n email AS user_email,\n url AS user_url\n FROM {$this->data['prefix']}authors", $bblogdb); if (!$res) { return sprintf(COULDNT_SELECT_USER_INFO, mysqli_error($bblogdb)); } for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $users[$x] = mysqli_fetch_assoc($res); $data = array('right_publish' => 1, 'username' => $users[$x]['user_login'], 'email' => $users[$x]['user_email'], 'userlevel' => USERLEVEL_ADMIN, 'password' => md5($users[$x]['pw'])); // Wicked. This is the first blog I've seen storing cleartext passwords :-D if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { $data['userlevel'] = $serendipity['serendipityUserlevel']; } serendipity_db_insert('authors', $this->strtrRecursive($data)); echo mysqli_error(); $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); } /* Categories */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}sections", $bblogdb); if (!$res) { return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysqli_error($bblogdb)); } // Get all the info we need for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $row = mysqli_fetch_assoc($res); $cat = array('category_name' => $row['nicename'], 'category_description' => $row['nicename'], 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); serendipity_db_insert('category', $this->strtrRecursive($cat)); $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); $this->categories[] = $row; } serendipity_rebuildCategoryTree(); /* Entries */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY postid;", $bblogdb); if (!$res) { return sprintf(COULDNT_SELECT_ENTRY_INFO, mysqli_error($bblogdb)); } for ($x = 0, $max_x = mysqli_num_rows($res); $x < $max_x; $x++) { $entries[$x] = mysqli_fetch_assoc($res); $entry = array('title' => $this->decode($entries[$x]['title']), 'isdraft' => $entries[$x]['status'] == 'live' ? 'false' : 'true', 'allow_comments' => $entries[$x]['allowcomments'] == 'allow' ? 'true' : 'false', 'timestamp' => $entries[$x]['posttime'], 'body' => $this->strtr($entries[$x]['body']), 'extended' => ''); $entry['authorid'] = ''; $entry['author'] = ''; foreach ($users as $user) { if ($user['ID'] == $entries[$x]['author']) { $entry['authorid'] = $user['authorid']; $entry['author'] = $user['user_login']; break; } } if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { return $entries[$x]['entryid']; } $sections = explode(':', $entries[$x]['sections']); foreach ($sections as $section) { if (empty($section)) { continue; } foreach ($this->categories as $category) { if ($category['sectionid'] == $section) { $categoryid = $category['categoryid']; } } if ($categoryid > 0) { $data = array('entryid' => $entries[$x]['entryid'], 'categoryid' => $categoryid); serendipity_db_insert('entrycat', $this->strtrRecursive($data)); } } } /* Comments */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'comment';", $bblogdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($bblogdb)); } while ($a = mysqli_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['postid'] == $a['postid']) { $comment = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['posttime'], 'author' => $a['postername'], 'email' => $a['posteremail'], 'url' => $a['posterwebsite'], 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['commenttext'], 'subscribed' => 'false', 'type' => 'NORMAL'); serendipity_db_insert('comments', $this->strtrRecursive($comment)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } /* Trackbacks */ $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'trackback';", $bblogdb); if (!$res) { return sprintf(COULDNT_SELECT_COMMENT_INFO, mysqli_error($bblogdb)); } while ($a = mysqli_fetch_assoc($res)) { foreach ($entries as $entry) { if ($entry['postid'] == $a['postid']) { $trackback = array('entry_id ' => $entry['entryid'], 'parent_id' => 0, 'timestamp' => $a['posttime'], 'title' => $a['title'], 'author' => $a['postername'], 'email' => $a['posteremail'], 'url' => $a['posterwebsite'], 'ip' => $a['ip'], 'status' => 'approved', 'body' => $a['commenttext'], 'subscribed' => 'false', 'type' => 'TRACKBACK'); serendipity_db_insert('comments', $this->strtrRecursive($trackback)); $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['entryid'], true); } } } $serendipity['noautodiscovery'] = $noautodiscovery; // That was fun. return true; }