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(); $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; // 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 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; }
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; $force = $this->data['mt_force'] == 'true'; if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } // Rewritten to parse the file line by line. Can save quite some // memory on large blogs //$contents = file_get_contents($_FILES['serendipity']['tmp_name']['import']['mt_dat']); $this->categories = serendipity_fetchCategories(); $tasks = array(); $entries = array(); if (empty($_FILES['serendipity']['tmp_name']['import']['mt_dat'])) { $fh = fopen('/tmp/mt.dat', 'r'); } else { $fh = fopen($_FILES['serendipity']['tmp_name']['import']['mt_dat'], 'r'); } $entry = array(); $el = ""; $c_el = ""; $skip = false; $is_comment = false; $is_trackback = false; $nofetch = false; while (!feof($fh)) { if ($nofetch === false) { $this->debug('Next line'); $line = $this->decode(fgets($fh, 8192)); } else { $this->debug('NO Next line'); // Keep line from previous run. $nofetch = false; } if ($is_comment || $is_trackback) { $this->debug("COMMENT/TRACKBACK mode is active."); if (preg_match('/^--------/', $line)) { $this->debug("Next full section requested."); $is_comment = $is_trackback = false; } elseif (preg_match('/^-----/', $line)) { $this->debug("Next partial section requested."); if ($is_trackback) { $this->debug("Parsing trackback."); $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'TRACKBACK'); } elseif ($is_comment) { $this->debug("Parsing comment."); $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'NORMAL'); } $el = $c_el = ""; } } if ($skip && !preg_match('/^--------/', $line)) { $this->debug("No next section match, and skip is activated. Skipping '{$line}'"); continue; } if (preg_match('/^--------/', $line)) { // We found the end marker of the current entry. Add to entries-Array $this->debug("End marker found. Parsing full entry."); $entries[] = $this->doEntryWork($entry, $tasks); $entry = array(); $el = ""; $c_el = ""; $skip = false; $is_comment = false; $is_trackback = false; } elseif (preg_match('/^-----/', $line)) { $this->debug("New section match. Current EL: {$el}"); unset($el); # DEBUG! if (empty($el)) { $line = $this->decode(fgets($fh, 8192)); $this->debug("Inspecting next line: {$line}"); $tline = trim($line); while (($is_comment || $is_trackback) && empty($tline)) { $line = $this->decode(fgets($fh, 8192)); $tline = trim($line); $this->debug("Continuing inspecting next line: {$line}"); } if (preg_match('/^--------/', $line)) { $this->debug('Next line is new element. End marker found. Parsing full entry.'); $entries[] = $this->doEntryWork($entry, $tasks); $entry = array(); $el = ""; $c_el = ""; $skip = false; $is_comment = false; $is_trackback = false; } elseif (preg_match('/^([A-Z\\s]+):/', $line, $matches)) { $this->debug("Match result: {$matches['1']}"); if ($matches[1] == 'COMMENT') { $this->debug("Marking COMMENT."); $is_comment = true; $is_trackback = false; $comment = array(); $skip = false; } elseif ($matches[1] == 'PING') { $this->debug("Marking TRACKBACK"); $is_comment = false; $is_trackback = true; $comment = array(); $skip = false; } $this->debug("Setting EL to {$matches[1]}"); $el = $matches[1]; $c_el = ""; } else { $this->debug("Could not parse next line. Keeping it for next cycle."); $nofetch = true; } } else { $this->debug("Resetting EL to an empty string"); $el = $c_el = ""; } } elseif (empty($el)) { $this->debug("EL is empty. Line is '{$line}'"); $content = ""; if (preg_match('/^([A-Z\\s]+):\\s+(.*)$/s', $line, $matches)) { $this->debug("Section match {$matches[1]} found, input: {$matches[2]}"); $c_el = $matches[1]; $content = $matches[2]; } elseif (!empty($c_el)) { $this->debug("Still in subsection of previous run: {$c_el}."); $content = trim($line); } if (!empty($content)) { if ($is_comment || $is_trackback) { $this->debug("Appending to comments: {$line}"); $comment[$c_el] = $content; } else { $this->debug("Appending to entry: {$line}"); if (isset($entry[$c_el])) { $entry[$c_el] .= "" . $content; } else { $entry[$c_el] = $content; } } } } elseif ($is_comment || $is_trackback) { $this->debug("Appending Line in current Element {$el} to comments: {$line}"); $comment[$el] .= $line; } else { $this->debug("Appending Line in current Element {$el} to entries: {$line}"); $entry[$el] .= $line; } } fclose($fh); if (!sizeof($tasks) || $force == true) { serendipity_db_begin_transaction(); foreach ($entries as $entry) { #echo '<pre>' . printR_($entry, true) . '</pre><br />'; #continue; if (empty($entry['authorid'])) { $entry['authorid'] = $serendipity['authorid']; $entry['author'] = $serendipity['realname']; } if (!isset($entry['isdraft'])) { $entry['isdraft'] = 'false'; } if (!isset($entry['allow_comments'])) { $entry['allow_comments'] = 'true'; } $comments = $entry['s9y_comments']; $entryprops = $entry['props']; unset($entry['props']); unset($entry['s9y_comments']); if (!is_int($r = serendipity_updertEntry($entry))) { echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . $r . '</div>'; } else { $this->debug('Saved entry ' . $r . ' (' . $entry['title'] . ')'); $entry['id'] = $r; foreach ((array) $comments as $comment) { $comment['entry_id'] = $r; if ($rc = serendipity_db_insert('comments', $comment)) { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['id'], true); } else { echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . $rc . '</div>'; } } // Let the plugins do some additional stuff. Here it's used with // event_entryproperties in mind to setup the nl2br-stuff serendipity_plugin_api::hook_event('backend_import_entry', $entry, $entryprops); } } serendipity_db_end_transaction(true); return true; } else { return '<ul><li>' . implode('</li><li>', array_unique($tasks)) . '</li></ul>'; } }
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(); $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; } $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; }
$sql = "SELECT c.*, e.title, a.email as authoremail, a.mail_comments\n FROM {$serendipity['dbPrefix']}comments c\n LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)\n LEFT JOIN {$serendipity['dbPrefix']}authors a ON (e.authorid = a.authorid)\n WHERE c.id = " . (int) $serendipity['GET']['id'] . " AND (status = 'pending' OR status LIKE 'confirm%')"; $rs = serendipity_db_query($sql, true); if ($rs === false) { $errormsg .= ERROR . ': ' . sprintf(COMMENT_ALREADY_APPROVED, (int) $serendipity['GET']['id']); } else { serendipity_approveComment((int) $serendipity['GET']['id'], (int) $rs['entry_id']); $msg .= DONE . ': ' . sprintf(COMMENT_APPROVED, (int) $serendipity['GET']['id']); } } if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'pending' && serendipity_checkFormToken()) { $sql = "SELECT c.*, e.title, a.email as authoremail, a.mail_comments\n FROM {$serendipity['dbPrefix']}comments c\n LEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)\n LEFT JOIN {$serendipity['dbPrefix']}authors a ON (e.authorid = a.authorid)\n WHERE c.id = " . (int) $serendipity['GET']['id'] . " AND status = 'approved'"; $rs = serendipity_db_query($sql, true); if ($rs === false) { $errormsg .= ERROR . ': ' . sprintf(COMMENT_ALREADY_APPROVED, (int) $serendipity['GET']['id']); } else { serendipity_approveComment((int) $serendipity['GET']['id'], (int) $rs['entry_id'], true, true); $msg .= DONE . ': ' . sprintf(COMMENT_MODERATED, (int) $serendipity['GET']['id']); } } /* We are asked to delete a comment */ if (isset($serendipity['GET']['adminAction']) && $serendipity['GET']['adminAction'] == 'delete' && serendipity_checkFormToken()) { serendipity_deleteComment($serendipity['GET']['id'], $serendipity['GET']['entry_id']); $msg .= DONE . ': ' . sprintf(COMMENT_DELETED, (int) $serendipity['GET']['id']); } /* We are either in edit mode, or preview mode */ if (isset($serendipity['GET']['adminAction']) && ($serendipity['GET']['adminAction'] == 'edit' || $serendipity['GET']['adminAction'] == 'reply') || isset($serendipity['POST']['preview'])) { $serendipity['smarty_raw_mode'] = true; // Force output of Smarty stuff in the backend serendipity_smarty_init(); if ($serendipity['GET']['adminAction'] == 'reply' || $serendipity['GET']['adminAction'] == 'doReply') { $c = serendipity_fetchComments($serendipity['GET']['entry_id'], 1, 'co.id', false, 'NORMAL', ' AND co.id=' . (int) $serendipity['GET']['id']);
function import_wpxrss() { // TODO: Backtranscoding to NATIVE charset. Currently only works with UTF-8. $dry_run = false; $serendipity['noautodiscovery'] = 1; $uri = $this->data['url']; require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; serendipity_request_start(); $req = new HTTP_Request($uri, array('allowRedirects' => true, 'maxRedirects' => 5)); $res = $req->sendRequest(); if (PEAR::isError($res) || $req->getResponseCode() != '200') { serendipity_request_end(); echo IMPORT_FAILED . ': ' . htmlspecialchars($this->data['url']); echo "<br />\n"; return false; } $fContent = $req->getResponseBody(); serendipity_request_end(); echo strlen($fContent) . " Bytes<br />\n"; if (version_compare(PHP_VERSION, '5.0') === -1) { printf(UNMET_REQUIREMENTS, 'PHP >= 5.0'); echo "<br />\n"; return false; } $xml = simplexml_load_string($fContent); unset($fContent); /* ************* USERS **********************/ $_s9y_users = serendipity_fetchUsers(); $s9y_users = array(); if (is_array($s9y_users)) { foreach ($_s9y_users as $v) { $s9y_users[$v['realname']] = $v; } } /* ************* CATEGORIES **********************/ $_s9y_cat = serendipity_fetchCategories('all'); $s9y_cat = array(); if (is_array($s9y_cat)) { foreach ($_s9y_cat as $v) { $s9y_cat[$v['category_name']] = $v['categoryid']; } } $wp_ns = 'http://wordpress.org/export/1.0/'; $dc_ns = 'http://purl.org/dc/elements/1.1/'; $content_ns = 'http://purl.org/rss/1.0/modules/content/'; $wp_core = $xml->channel->children($wp_ns); foreach ($wp_core->category as $idx => $cat) { //TODO: Parent generation unknown. $cat_name = (string) $cat->cat_name; if (!isset($s9y_cat[$cat_name])) { $cat = array('category_name' => $cat_name, 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0); printf(CREATE_CATEGORY, htmlspecialchars($cat_name)); echo "<br />\n"; if ($dry_run) { $s9y_cat[$cat_name] = time(); } else { serendipity_db_insert('category', $cat); $s9y_cat[$cat_name] = serendipity_db_insert_id('category', 'categoryid'); } } } /* ************* ITEMS **********************/ foreach ($xml->channel->item as $idx => $item) { $wp_items = $item->children($wp_ns); $dc_items = $item->children($dc_ns); $content_items = $item->children($content_ns); // TODO: Attachments not handled if ((string) $wp_items->post_type == 'attachment' or (string) $wp_items->post_type == 'page') { continue; } $entry = array('title' => (string) $item->title, 'isdraft' => (string) $wp_items->status == 'publish' ? 'false' : 'true', 'allow_comments' => (string) $wp_items->comment_status == 'open' ? true : false, 'categories' => array(), 'body' => (string) $content_items->encoded); if (preg_match('@^([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$@', (string) $wp_items->post_date, $timematch)) { $entry['timestamp'] = mktime($timematch[4], $timematch[5], $timematch[6], $timematch[2], $timematch[3], $timematch[1]); } else { $entry['timestamp'] = time(); } if (isset($item->category[1])) { foreach ($item->category as $idx => $category) { $cstring = (string) $category; if (!isset($s9y_cat[$cstring])) { echo "WARNING: {$category} unset!<br />\n"; } else { $entry['categories'][] = $s9y_cat[$cstring]; } } } else { $cstring = (string) $item->category; $entry['categories'][] = $s9y_cat[$cstring]; } $wp_user = (string) $dc_items->creator; if (!isset($s9y_users[$wp_user])) { if ($dry_run) { $s9y_users[$wp_user]['authorid'] = time(); } else { $s9y_users[$wp_user]['authorid'] = serendipity_addAuthor($wp_user, md5(time()), $wp_user, '', USERLEVEL_EDITOR); } printf(CREATE_AUTHOR, htmlspecialchars($wp_user)); echo "<br />\n"; } $entry['authorid'] = $s9y_users[$wp_user]['authorid']; if ($dry_run) { $id = time(); } else { $id = serendipity_updertEntry($entry); } $s9y_cid = array(); // Holds comment ids to s9y ids association. $c_i = 0; foreach ($wp_items->comment as $comment) { $c_i++; $c_id = (string) $comment->comment_id; $c_pid = (string) $comment->comment_parent; $c_type = (string) $comment->comment_type; if ($c_type == 'pingback') { $c_type2 = 'PINGBACK'; } elseif ($c_type == 'trackback') { $c_type2 = 'TRACKBACK'; } else { $c_type2 = 'NORMAL'; } $s9y_comment = array('entry_id ' => $id, 'parent_id' => $s9y_cid[$c_pd], 'author' => (string) $comment->comment_author, 'email' => (string) $comment->comment_author_email, 'url' => (string) $comment->comment_author_url, 'ip' => (string) $comment->comment_author_IP, 'status' => empty($comment->comment_approved) || $comment->comment_approved == '1' ? 'approved' : 'pending', 'subscribed' => 'false', 'body' => (string) $comment->comment_content, 'type' => $c_type2); if (preg_match('@^([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$@', (string) $comment->comment_date, $timematch)) { $s9y_comment['timestamp'] = mktime($timematch[4], $timematch[5], $timematch[6], $timematch[2], $timematch[3], $timematch[1]); } else { $s9y_comment['timestamp'] = time(); } if ($dry_run) { $cid = time(); } else { serendipity_db_insert('comments', $s9y_comment); $cid = serendipity_db_insert_id('comments', 'id'); if ($s9y_comment['status'] == 'approved') { serendipity_approveComment($cid, $id, true); } } $s9y_cid[$c_id] = $cid; } echo "Entry '" . htmlspecialchars($entry['title']) . "' ({$c_i} comments) imported.<br />\n"; } return true; }
function learnAction($id, $category, $action, $entry_id) { $comment = $this->getComment($id); if (is_array($comment)) { $comment = $comment['0']; } $this->startLearn($comment, $category); if ($action == 'delete') { serendipity_deleteComment($id, $entry_id); } else { if ($action == 'approve') { serendipity_approveComment($id, $entry_id); } } }
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; }
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() { 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; }
/** * Store the comment made by a visitor in the database * * @access public * @param int The ID of an entry * @param array An array that holds the input data from the visitor * @param string The type of a comment (normal/trackback) * @param string Where did a comment come from? (internal|trackback|plugin) * @param string Additional plugin data (spamblock plugin etc.) * @return boolean Returns true if the comment could be added */ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source = 'internal', $ca = array()) { global $serendipity; if (!empty($ca['status'])) { $commentInfo['status'] = $ca['status']; } $title = serendipity_db_escape_string(isset($commentInfo['title']) ? $commentInfo['title'] : ''); $comments = $commentInfo['comment']; $ip = serendipity_db_escape_string(isset($commentInfo['ip']) ? $commentInfo['ip'] : $_SERVER['REMOTE_ADDR']); $commentsFixed = serendipity_db_escape_string($commentInfo['comment']); $name = serendipity_db_escape_string($commentInfo['name']); $url = serendipity_db_escape_string($commentInfo['url']); $email = serendipity_db_escape_string($commentInfo['email']); $parentid = isset($commentInfo['parent_id']) && is_numeric($commentInfo['parent_id']) ? $commentInfo['parent_id'] : 0; $status = serendipity_db_escape_string(isset($commentInfo['status']) ? $commentInfo['status'] : (serendipity_db_bool($ca['moderate_comments']) ? 'pending' : 'approved')); $t = serendipity_db_escape_string(isset($commentInfo['time']) ? $commentInfo['time'] : time()); $referer = substr(isset($_SESSION['HTTP_REFERER']) ? serendipity_db_escape_string($_SESSION['HTTP_REFERER']) : '', 0, 200); $query = "SELECT a.email, e.title, a.mail_comments, a.mail_trackbacks\n FROM {$serendipity['dbPrefix']}entries AS e\n LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a\n ON a.authorid = e.authorid\n WHERE e.id = '" . (int) $id . "'\n AND e.isdraft = 'false'"; if (!serendipity_db_bool($serendipity['showFutureEntries'])) { $query .= " AND e.timestamp <= " . serendipity_db_time(); } $row = serendipity_db_query($query, true); // Get info on author/entry if (!is_array($row) || empty($id)) { // No associated entry found. if ($GLOBALS['tb_logging']) { $fp = fopen('trackback2.log', 'a'); fwrite($fp, '[' . date('d.m.Y H:i') . '] entry reference not found: ' . $query . "\n"); fclose($fp); } return false; } $send_optin = false; if (isset($commentInfo['subscribe'])) { if (!isset($serendipity['allowSubscriptionsOptIn']) || $serendipity['allowSubscriptionsOptIn']) { $subscribe = 'false'; $send_optin = true; } else { $subscribe = 'true'; } } else { $subscribe = 'false'; } $dbhash = md5(uniqid(rand(), true)); if ($status == 'confirm') { $dbstatus = 'confirm' . $dbhash; } elseif ($status == 'confirm1') { $auth = serendipity_db_query("SELECT *\n FROM {$serendipity['dbPrefix']}options\n WHERE okey = 'mail_confirm'\n AND name = '" . $email . "'\n AND value = '" . $name . "'", true); if (!is_array($auth)) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)\n VALUES ('mail_confirm{$dbhash}', '{$email}', '{$name}')"); $dbstatus = 'confirm' . $dbhash; } else { $serendipity['csuccess'] = 'true'; $status = $dbstatus = 'approved'; } } else { $dbstatus = $status; } $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)"; $query .= " VALUES ('" . (int) $id . "', '{$parentid}', '{$ip}', '{$name}', '{$email}', '{$url}', '{$commentsFixed}', '{$type}', '{$t}', '{$title}', '{$subscribe}', '{$dbstatus}', '{$referer}')"; if ($GLOBALS['tb_logging']) { $fp = fopen('trackback2.log', 'a'); fwrite($fp, '[' . date('d.m.Y H:i') . '] SQL: ' . $query . "\n"); } serendipity_db_query($query); $cid = serendipity_db_insert_id('comments', 'id'); // Send mail to the author if he chose to receive these mails, or if the comment is awaiting moderation if ($status != 'confirm' && (serendipity_db_bool($ca['moderate_comments']) || $type == 'NORMAL' && serendipity_db_bool($row['mail_comments']) || $type == 'TRACKBACK' && serendipity_db_bool($row['mail_trackbacks']))) { serendipity_sendComment($cid, $row['email'], $name, $email, $url, $id, $row['title'], $comments, $type, serendipity_db_bool($ca['moderate_comments'])); } // Approve with force, if moderation is disabled if ($GLOBALS['tb_logging']) { fwrite($fp, '[' . date('d.m.Y H:i') . '] status: ' . $status . ', moderate: ' . $ca['moderate_comments'] . "\n"); } if ($status != 'confirm' && (empty($ca['moderate_comments']) || serendipity_db_bool($ca['moderate_comments']) == false)) { if ($GLOBALS['tb_logging']) { fwrite($fp, '[' . date('d.m.Y H:i') . '] Approving...' . "\n"); } serendipity_approveComment($cid, $id, true); } elseif ($GLOBALS['tb_logging']) { fwrite($fp, '[' . date('d.m.Y H:i') . '] No need to approve...' . "\n"); } if ($status == 'confirm') { $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']); $message = sprintf(CONFIRMATION_MAIL_ALWAYS, $name, $row['title'], $commentsFixed, $serendipity['baseURL'] . 'comment.php?c=' . $cid . '&hash=' . $dbhash); serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']); } elseif ($status == 'confirm1') { $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']); $message = sprintf(CONFIRMATION_MAIL_ONCE, $name, $row['title'], $commentsFixed, $serendipity['baseURL'] . 'comment.php?c=' . $cid . '&hash=' . $dbhash); serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']); } if ($send_optin) { $dupe_check = serendipity_db_query("SELECT count(entry_id) AS counter\n FROM {$serendipity['dbPrefix']}comments\n WHERE entry_id = " . (int) $id . "\n AND email = '{$email}'\n AND subscribed = 'true'", true); if (!is_array($dupe_check) || $dupe_check['counter'] < 1) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)\n VALUES ('commentsub_{$dbhash}', '" . time() . "', '{$cid}')"); $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']); $message = sprintf(CONFIRMATION_MAIL_SUBSCRIPTION, $name, $row['title'], serendipity_archiveURL($id, $row['title'], 'baseURL'), $serendipity['baseURL'] . 'comment.php?optin=' . $dbhash); serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']); } } serendipity_purgeEntry($id, $t); if ($GLOBALS['tb_logging']) { fclose($fp); } return $cid; }
serendipity_checkCommentTokenModeration($uri); if (preg_match(PAT_DELETE, $uri, $res) && $serendipity['serendipityAuthedUser'] === true) { if ($res[1] == 'comment' && serendipity_deleteComment($res[2], $res[3], 'comments')) { define('DATA_COMMENT_DELETED', sprintf(COMMENT_DELETED, $res[2])); } elseif ($res[1] == 'trackback' && serendipity_deleteComment($res[2], $res[3], 'trackbacks')) { define('DATA_TRACKBACK_DELETED', sprintf(TRACKBACK_DELETED, $res[2])); } } else { define('DATA_COMMENT_DELETED', false); define('DATA_TRACKBACK_DELETED', false); } if (preg_match(PAT_APPROVE, $uri, $res) && $serendipity['serendipityAuthedUser'] === true) { if ($res[1] == 'comment' && serendipity_approveComment($res[2], $res[3])) { define('DATA_COMMENT_APPROVED', sprintf(COMMENT_APPROVED, $res[2])); define('DATA_TRACKBACK_APPROVED', false); } elseif ($res[1] == 'trackback' && serendipity_approveComment($res[2], $res[3])) { define('DATA_COMMENT_APPROVED', false); define('DATA_TRACKBACK_APPROVED', sprintf(TRACKBACK_APPROVED, $res[2])); } } else { define('DATA_COMMENT_APPROVED', false); define('DATA_TRACKBACK_APPROVED', false); } if (isset($serendipity['POST']['isMultiCat']) && is_array($serendipity['POST']['multiCat'])) { $is_multicat = true; } else { $is_multicat = false; } if (isset($serendipity['POST']['isMultiAuth']) && is_array($serendipity['POST']['multiAuth'])) { $is_multiauth = true; } else {
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; }
/** * This will update the comment and approve/moderate it. * @param unknown_type $message */ function wp_editComment($message) { global $serendipity; $val = $message->params[1]; $username = $val->getval(); $val = $message->params[2]; $password = $val->getval(); if (!serendipity_authenticate_author($username, $password)) { return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED); } $val = $message->params[3]; $comment_id = $val->getval(); $val = $message->params[4]; $rpccomment = $val->getval(); if (!empty($comment_id)) { ob_start(); $asureEntryId = ""; if ($rpccomment['post_id']) { $asureEntryId = " AND entry_id=" . $rpccomment['post_id']; } // We need the entryid, so fetch it: $commentInfo = serendipity_db_query("SELECT c.entry_id as entry_id, c.body as content, c.email as author_email, c.author as comment_author, c.status as comment_status, c.url as author_url, e.authorid AS entry_authorid\n \tFROM {$serendipity['dbPrefix']}comments c\n \tLEFT JOIN {$serendipity['dbPrefix']}entries e ON (e.id = c.entry_id)\n \tWHERE c.id = {$comment_id}", true); // If we fetched a row, process it if (is_array($commentInfo)) { $entry_id = $commentInfo['entry_id']; $entry_authorid = $commentInfo['entry_authorid']; $comment_status = $commentInfo['comment_status']; if (!empty($serendipity['xmlrpc_asureauthor']) && $serendipity['xmlrpc_asureauthor'] != 'default') { $rpccomment['author'] = $serendipity[$serendipity['xmlrpc_asureauthor']]; } // Setup new comment to save. Preserve old values, if nothing is given by the client. $comment = array('author' => empty($rpccomment['author']) ? $commentInfo['comment_author'] : $rpccomment['author'], 'url' => empty($rpccomment['author_url']) ? $commentInfo['author_url'] : $rpccomment['author_url'], 'email' => empty($rpccomment['author_email']) ? $commentInfo['author_email'] : $rpccomment['author_email'], 'body' => empty($rpccomment['content']) ? $commentInfo['content'] : $rpccomment['content']); $result = universal_updateComment($comment_id, $entry_id, $entry_authorid, $comment); if ($result) { $rpc_comment_status = $rpccomment['status']; $moderate_comment = $rpc_comment_status !== 'approve' && $rpc_comment_status !== 'approved'; $result = !serendipity_approveComment($comment_id, $entry_id, false, $moderate_comment) == $moderate_comment; if ($result || $rpc_comment_status == 'spam') { $result = true; $addData['id'] = $entry_id; $addData['eid'] = $entry_id; $addData['cid'] = $comment_id; $event_type = ""; // Sent out plugin hooks, perhaps someone is interested? if ($rpc_comment_status == 'spam') { $event_type = $serendipity['xmlrpc_event_spam']; } elseif ($rpc_comment_status == 'hold' && $comment_status != 'pending') { $event_type = $serendipity['xmlrpc_event_pending']; } elseif ($rpc_comment_status == 'approve' && $comment_status != 'approved') { $event_type = $serendipity['xmlrpc_event_approved']; } if (!empty($event_type) && 'none' != $event_type) { serendipity_plugin_api::hook_event('xmlrpc_comment_' . $event_type, $comment, $addData); } } } } else { $result = false; } $errs = ob_get_contents(); if (!empty($errs)) { universal_debug("errors: {$errs}"); } ob_clean(); } else { $result = false; } return new XML_RPC_Response(new XML_RPC_Value($result, 'boolean')); }
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 workComment($id, $commentInfo, $type = 'NORMAL', $source = 'internal') { global $serendipity; $query = "SELECT id, allow_comments, moderate_comments, last_modified, timestamp, title FROM {$serendipity['dbPrefix']}entries WHERE id = '" . (int) $id . "'"; $ca = serendipity_db_query($query, true); $commentInfo['type'] = $type; $commentInfo['source'] = $source; // serendipity_plugin_api::hook_event('frontend_saveComment', $ca, $commentInfo); if (!is_array($ca) || serendipity_db_bool($ca['allow_comments'])) { $title = serendipity_db_escape_string(isset($commentInfo['title']) ? $commentInfo['title'] : ''); $comments = $commentInfo['comment']; $ip = serendipity_db_escape_string(isset($commentInfo['ip']) ? $commentInfo['ip'] : $_SERVER['REMOTE_ADDR']); $commentsFixed = serendipity_db_escape_string($commentInfo['comment']); $name = serendipity_db_escape_string($commentInfo['name']); $url = serendipity_db_escape_string($commentInfo['url']); $email = serendipity_db_escape_string($commentInfo['email']); $parentid = isset($commentInfo['parent_id']) && is_numeric($commentInfo['parent_id']) ? $commentInfo['parent_id'] : 0; $status = serendipity_db_escape_string(isset($commentInfo['status']) ? $commentInfo['status'] : (serendipity_db_bool($ca['moderate_comments']) ? 'pending' : 'approved')); $t = serendipity_db_escape_string(isset($commentInfo['time']) ? $commentInfo['time'] : time()); $referer = substr(isset($_SESSION['HTTP_REFERER']) ? serendipity_db_escape_string($_SESSION['HTTP_REFERER']) : '', 0, 200); $query = "SELECT a.email, e.title, a.mail_comments, a.mail_trackbacks\n FROM {$serendipity['dbPrefix']}entries e, {$serendipity['dbPrefix']}authors a\n WHERE e.id = '" . (int) $id . "'\n AND e.isdraft = 'false'\n AND e.authorid = a.authorid"; if (!serendipity_db_bool($serendipity['showFutureEntries'])) { $query .= " AND e.timestamp <= " . serendipity_db_time(); } $row = serendipity_db_query($query, true); // Get info on author/entry if (!is_array($row) || empty($id)) { // No associated entry found. return false; } if (isset($commentInfo['subscribe'])) { $subscribe = 'true'; } else { $subscribe = 'false'; } $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)"; $query .= " VALUES ('" . (int) $id . "', '{$parentid}', '{$ip}', '{$name}', '{$email}', '{$url}', '{$commentsFixed}', '{$type}', '{$t}', '{$title}', '{$subscribe}', '{$status}', '{$referer}')"; serendipity_db_query($query); $cid = serendipity_db_insert_id('comments', 'id'); // Send mail to the author if he chose to receive these mails, or if the comment is awaiting moderation if (serendipity_db_bool($ca['moderate_comments']) || $type == 'NORMAL' && serendipity_db_bool($row['mail_comments']) || $type == 'TRACKBACK' && serendipity_db_bool($row['mail_trackbacks'])) { serendipity_sendComment($cid, $row['email'], $name, $email, $url, $id, $row['title'], $comments, $type, serendipity_db_bool($ca['moderate_comments'])); } serendipity_approveComment($cid, $id, true); serendipity_purgeEntry($id, $t); return $cid; } else { return false; } }