From: garvinhicking Date: Tue, 11 Apr 2006 09:55:59 +0000 (+0000) Subject: Add Pivot importer X-Git-Tag: 1.0~51 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=91ca680bcf20343a91fa60f2fd9c623d530a9d3b;p=s9y.git Add Pivot importer --- diff --git a/docs/NEWS b/docs/NEWS index 45de028..bd5ea34 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,11 +3,13 @@ Version 1.0 () ------------------------------------------------------------------------ + * Added Pivot importer (garvinhicking) + * The spamblock plugin now continues to check any comment/trackback set to MODERATE if maybe other rules override the status to REJECTED. This should reduce the amount of moderation mails that definitely are spam. (Bug #1467707) (garvinhicking) - + * Fix UTF-8 encoding of $i18n_filename_* variables for building permalinks (Bug #1461754, Thanks to Kim Sullivan) (garvinhicking) diff --git a/include/admin/importers/pivot.inc.php b/include/admin/importers/pivot.inc.php new file mode 100644 index 0000000..11edf7f --- /dev/null +++ b/include/admin/importers/pivot.inc.php @@ -0,0 +1,202 @@ + 'Pivot'); + var $data = array(); + var $inputFields = array(); + + function Serendipity_Import_Pivot($data) { + $this->data = $data; + $this->inputFields = array(array('text' => PARENT_DIRECTORY, + 'type' => 'input', + 'name' => 'pivot_path', + 'default' => '/path/to/pivot/db/'), + ); + } + + function validateData() { + return sizeof($this->data); + } + + function getInputFields() { + return $this->inputFields; + } + + function _getCategoryList() { + $res = serendipity_fetchCategories('all'); + $ret = array(0 => NO_CATEGORY); + if (is_array($res)) { + foreach ($res as $v) { + $ret[$v['categoryid']] = $v['category_name']; + } + } + return $ret; + } + + function toTimestamp($string) { + if (empty($string)) { + return time(); + } + + $parts = explode('-', $string); + return mktime($parts[3], $parts[4], 0, $parts[1], $parts[2], $parts[0]); + } + + function &unserialize($file) { + $c = file_get_contents($file); + $entrydata = str_replace(array('', "\r"), array('', ''), $c); + $entrydata = unserialize($entrydata); + + if (empty($entrydata) || !is_array($entrydata)) { + $entrydata = str_replace(array(''), array(''), $c); + $entrydata = unserialize($entrydata); + } + + return $entrydata; + } + + function import() { + global $serendipity; + + $max_import = 9999; + + $serendipity['noautodiscovery'] = true; + if (!is_dir($this->data['pivot_path']) || !is_readable($this->data['pivot_path'])) { + $check_dir = $serendipity['serendipityPath'] . $this->data['pivot_path']; + if (!is_dir($check_dir) || !is_readable($check_dir)) { + return sprintf(ERROR_NO_DIRECTORY, $this->data['pivot_path']); + } + $this->data['pivot_path'] = $check_dir; + } + + printf('
' . CHECKING_DIRECTORY . '

', $this->data['pivot_path']); + if ($root = opendir($this->data['pivot_path'])) { + // Fetch category data: + $s9y_categories = serendipity_fetchCategories('all'); + $categories = $this->unserialize($this->data['pivot_path'] . '/ser-cats.php'); + $pivot_to_s9y = array( + 'categories' => array() + ); + + foreach($categories AS $pivot_category_id => $category) { + $found = false; + $pivot_category = trim(stripslashes($category[0])); + foreach($s9y_categories AS $idx => $item) { + if ($pivot_category == $item['category_name']) { + $found = $item['categoryid']; + break; + } + } + + if ($found) { + echo '· Pivot Category "' . htmlspecialchars($pivot_category) . '" mapped to Serendipity ID ' . $found . '
'; + $pivot_to_s9y['categories'][$pivot_category] = $found; + } else { + echo '· Created Pivot Category "' . htmlspecialchars($pivot_category) . '".
'; + $cat = array('category_name' => $pivot_category, + 'category_description' => '', + 'parentid' => 0, + 'category_left' => 0, + 'category_right' => 0); + + + serendipity_db_insert('category', $cat); + $pivot_to_s9y['categories'][$pivot_category] = serendipity_db_insert_id('category', 'categoryid'); + } + } + + $i = 0; + while (false !== ($dir = readdir($root))) { + if ($dir{0} == '.') continue; + if (substr($dir, 0, 8) == 'standard') { + printf('  · ' . CHECKING_DIRECTORY . '...
', $dir); + $data = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/index-' . $dir . '.php'); + + if (empty($data) || !is_array($data) || count($data) < 1) { + echo '    · FATAL: File ' . $dir . '/index-' . $dir . '.php has no data!
'; + flush(); + ob_flush(); + continue; + } + + foreach($data as $entry) { + $entryid = str_pad($entry['code'], 5, '0', STR_PAD_LEFT); + + if ($i >= $max_import) { + echo '    · Skipping entry data for #' . $entryid . '
'; + continue; + } + + echo '    · Fetching entry data for #' . $entryid . '
'; + $entrydata = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/' . $entryid . '.php'); + if (empty($entrydata) || !is_array($entrydata) || count($entrydata) < 1) { + echo '    · FATAL: File ' . $dir . '/' . $entryid . '.php has no data!
'; + flush(); + ob_flush(); + continue; + } + + $entry = array(); + $entry['title'] = trim(stripslashes($entrydata['title'])); + $entry['categories'] = array(); + if (is_array($entrydata['category'])) { + foreach($entrydata['category'] AS $pivot_category) { + $entry['categories'][] = $pivot_to_s9y['categories'][$pivot_category]; + } + } + $entry['timestamp'] = $this->toTimestamp($entrydata['date']); + $entry['last_modified'] = (!empty($entrydata['edit_date']) ? $this->toTimestamp($entrydata['edit_date']) : $entry['timestamp']); + $entry['isdraft'] = ($entrydata['status'] == 'publish' ? 'false' : 'true'); + $entry['body'] = stripslashes($entrydata['introduction']); + $entry['extended'] = stripslashes($entrydata['body']); + $entry['title'] = stripslashes($entrydata['title']); + $entry['authorid'] = $serendipity['authorid']; + $entry['author'] = $serendipity['serendipityUser']; + $entry['allow_comments'] = ($entrydata['allow_comments'] ? 'true' : 'false'); + $entry['moderate_comments'] = 'false'; + $entry['exflag'] = (!empty($entry['extended']) ? 1 : 0); + $entry['trackbacks'] = 0; + $entry['comments'] = (isset($entrydata['comments']) ? count($entrydata['comments']) : 0); + serendipity_updertEntry($entry); + $i++; + + if (isset($entrydata['comments']) && count($entrydata['comments']) > 0) { + foreach($entrydata['comments'] as $comment) { + $comment = array('entry_id ' => $entry['id'], + 'parent_id' => 0, + 'timestamp' => $this->toTimestamp($comment['date']), + 'author' => stripslashes($comment['name']), + 'email' => stripslashes($comment['email']), + 'url' => stripslashes($comment['url']), + 'ip' => stripslashes($comment['ip']), + 'status' => 'approved', + 'body' => stripslashes($comment['comment']), + 'subscribed'=> ($comment['notify'] ? 'true' : 'false'), + 'type' => 'NORMAL'); + + serendipity_db_insert('comments', $comment); + } + } + echo '    · Entry #' . $entryid . ' imported
'; + flush(); + ob_flush(); + } + } + } + } else { + return sprintf(ERROR_NO_DIRECTORY, $this->data['pivot_path']); + } + + return true; + } +} + +return 'Serendipity_Import_Pivot'; + +/* vim: set sts=4 ts=4 expandtab : */ +?>