public function send() { $author = !empty($_POST['author']) ? strip_tags($_POST['author']) : ''; $content = !empty($_POST['content']) ? htmlspecialchars($_POST['content']) : ''; $errors = array(); if (!empty($_POST)) { $post = new Post(); foreach ($_POST as $key => $value) { try { $post->{$key} = $value; } catch (Exception $e) { $errors[$key] = $e->getMessage(); } } if (empty($errors)) { $result_id = $post->insert(); if ($result_id > 0) { header('Location: post.php?id=' . $result_id); exit; } $errors['internal error'] = 'An error occured, please try again later'; } } $vars = array('author' => $author, 'content' => $content, 'errors' => $errors); Post::displayTemplate('send.tpl', $vars); }
public function run() { // Common data $common = array('user_id' => 1, 'content' => file_get_contents(__DIR__ . '/post-content.txt')); // Initialize empty array $posts = array(); // Blog post 1 $date = new DateTime(); $posts[] = array_merge($common, array('title' => 'Lorem ipsum dolor sit amet', 'slug' => 'lorem-ipsum-dolor-sit-amet', 'created_at' => $date->modify('-10 day'), 'updated_at' => $date->modify('-10 day'))); // Blog post 2 $date = new DateTime(); $posts[] = array_merge($common, array('title' => 'Vivendo suscipiantur vim te vix', 'slug' => 'vivendo-suscipiantur-vim-te-vix', 'created_at' => $date->modify('-4 day'), 'updated_at' => $date->modify('-4 day'))); // Blog post 3 $date = new DateTime(); $posts[] = array_merge($common, array('title' => 'In iisque similique reprimique eum', 'slug' => 'in-iisque-similique-reprimique-eum', 'created_at' => $date->modify('-2 day'), 'updated_at' => $date->modify('-2 day'))); // Delete all the blog posts DB::table('posts')->truncate(); // Insert the blog posts Post::insert($posts); }
function insertProcess() { $send = Request::get('send'); $valid = Validator::make(array('send.title' => 'min:1|slashes', 'send.keywords' => 'slashes', 'tags' => 'slashes', 'send.catid' => 'slashes', 'send.type' => 'slashes', 'send.allowcomment' => 'slashes')); if (!$valid) { throw new Exception("Error Processing Request: " . Validator::getMessage()); } $friendlyUrl = trim(String::makeFriendlyUrl($send['title'])); $getData = Post::get(array('where' => "where friendly_url='{$friendlyUrl}'")); if (isset($getData[0]['postid'])) { throw new Exception("This post exists in database."); } $uploadMethod = Request::get('uploadMethod'); switch ($uploadMethod) { case 'frompc': if (Request::hasFile('imageFromPC')) { if (Request::isImage('imageFromPC')) { $send['image'] = File::upload('imageFromPC'); } } break; case 'fromurl': if (Request::isImage('imageFromUrl')) { $url = Request::get('imageFromUrl'); $send['image'] = File::upload('uploadFromUrl'); } break; } $send['userid'] = Users::getCookieUserId(); if (!Request::has('send.catid')) { $loadCat = Categories::get(array('limitShow' => 1)); if (isset($loadCat[0]['catid'])) { $send['catid'] = $loadCat[0]['catid']; } } if (!($id = Post::insert($send))) { throw new Exception("Error. " . Database::$error); } $tags = trim(Request::get('tags')); $parse = explode(',', $tags); $total = count($parse); $insertData = array(); for ($i = 0; $i < $total; $i++) { $insertData[$i]['title'] = trim($parse[$i]); $insertData[$i]['postid'] = $id; } PostTags::insert($insertData); }
public function action_auth_ajax_wp_import_posts() { // get the values post'd in $inputs = $_POST->filter_keys(array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'category_import', 'import_index')); $inputs = $inputs->getArrayCopy(); // make sure we have all our default values $inputs = array_merge($this->default_values, $inputs); // get the wpdb $wpdb = $this->wp_connect($inputs['db_host'], $inputs['db_name'], $inputs['db_user'], $inputs['db_pass']); // if we couldn't connect, error out if (!$wpdb) { EventLog::log(_t('Failed to import from "%s"', array($inputs['db_name']))); Session::error(_t('Failed to import from "%s"', array($inputs['db_name']))); echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>'; } // we connected just fine, let's get moving! // begin a transaction. if we error out at any point, we want to roll back to before import began DB::begin_transaction(); // fetch the number of posts from the wordpress database so we can batch things up $num_posts = $wpdb->get_value('select count(id) from ' . $inputs['db_prefix'] . 'posts'); // figure out the LIMIT we're at $min = $inputs['import_index'] * IMPORT_BATCH; $max = min($min + IMPORT_BATCH, $num_posts); // for display only echo '<p>' . _t('Importing posts %1$d - %2$d of %3$d.', array($min, $max, $num_posts)) . '</p>'; // get all the imported users so we can link old post authors to new post authors $users = DB::get_results('select user_id, value from {userinfo} where name = :name', array(':name' => 'wp_id')); // create an easy user map of old ID -> new ID $user_map = array(); foreach ($users as $info) { $user_map[$info->value] = $info->user_id; } // get all the post IDs we've imported so far to make sure we don't duplicate any $post_map = DB::get_column('select value from {postinfo} where name = :name', array(':name' => 'wp_id')); // now we're ready to start importing posts $posts = $wpdb->get_results('select id, post_author, post_date, post_content, post_title, post_status, comment_status, post_name, post_modified, guid, post_type from ' . $inputs['db_prefix'] . 'posts order by id asc limit ' . $min . ', ' . IMPORT_BATCH); foreach ($posts as $post) { // if this post is already in the list we've imported, skip it if (in_array($post->id, $post_map)) { continue; } // set up the big taxonomy sql query // if this turns out to be incredibly slow we should refactor it into a big join, but they're all keys so it seems zippy enough for me $taxonomy_query = 'select name, slug from ' . $inputs['db_prefix'] . 'terms where term_id in ( select term_id from ' . $inputs['db_prefix'] . 'term_taxonomy where taxonomy = :taxonomy and term_taxonomy_id in ( select term_taxonomy_id from ' . $inputs['db_prefix'] . 'term_relationships where object_id = :object_id ) )'; // get all the textual tag names for this post $tags = $wpdb->get_results($taxonomy_query, array(':taxonomy' => 'post_tag', ':object_id' => $post->id)); // should we import categories as tags too? if ($inputs['category_import']) { // then do the same as above for the category taxonomy $categories = $wpdb->get_results($taxonomy_query, array(':taxonomy' => 'category', ':object_id' => $post->id)); } // create the new post $p = new Post(array('title' => MultiByte::convert_encoding($post->post_title), 'content' => MultiByte::convert_encoding($post->post_content), 'user_id' => $user_map[$post->post_author], 'pubdate' => HabariDateTime::date_create($post->post_date), 'updated' => HabariDateTime::date_create($post->post_modified), 'slug' => MultiByte::convert_encoding($post->post_name))); // figure out the post type switch ($post->post_type) { case 'post': $p->content_type = Post::type('entry'); break; case 'page': $p->content_type = Post::type('page'); break; default: // we're not importing other types - continue 2 to break out of the switch and the loop and continue to the next post continue 2; } // figure out the post status switch ($post->post_status) { case 'publish': $p->status = Post::status('published'); break; case 'future': $p->status = Post::status('scheduled'); break; case 'pending': // means pending-review, not pending as in scheduled // means pending-review, not pending as in scheduled case 'draft': $p->status = Post::status('draft'); break; default: // Post::status() returns false if it doesn't recognize the status type $status = Post::status($post->post_status); // store in a temp value because if you try and set ->status to an invalid value the Post class freaks if ($status == false) { // we're not importing statuses we don't recognize - continue 2 to break out of the switch and the loop and continue to the next post continue 2; } else { $p->status = $status; } break; } // if comments are closed, disable them on the new post if ($post->comment_status == 'closed') { $p->info->comments_disabled = true; } // save the old post ID in info $p->info->wp_id = $post->id; // since we're not using it, save the old GUID too $p->info->wp_guid = $post->guid; // now that we've got all the pieces in place, save the post try { $p->insert(); // now that the post is in the db we can add tags to it // first, if we want to import categories as tags, add them to the array if ($inputs['category_import']) { $tags = array_merge($tags, $categories); } // now for the tags! foreach ($tags as $tag) { // try to get the tag by slug, which is the key and therefore the most unique $t = Tags::get_by_slug($tag->slug); // if we didn't get back a tag, create a new one if ($t == false) { $t = Tag::create(array('term' => $tag->slug, 'term_display' => $tag->name)); } // now that we have a tag (one way or the other), associate this post with it $t->associate('post', $p->id); } } catch (Exception $e) { EventLog::log($e->getMessage(), 'err'); echo '<p class="error">' . _t('There was an error importing post %s. See the EventLog for the error message.', array($post->post_title)); echo '<p>' . _t('Rolling back changes…') . '</p>'; // rollback all changes before we return so the import hasn't changed anything yet DB::rollback(); // and return so they don't get AJAX to send them on to the next step return false; } } // if we've finished without an error, commit the import DB::commit(); if ($max < $num_posts) { // if there are more posts to import // get the next ajax url $ajax_url = URL::get('auth_ajax', array('context' => 'wp_import_posts')); // bump the import index by one so we get a new batch next time $inputs['import_index']++; } else { // move on to importing comments // get the next ajax url $ajax_url = URL::get('auth_ajax', array('context' => 'wp_import_comments')); // reset the import index so we start at the first comment $inputs['import_index'] = 0; } // and spit out ajax to send them to the next step - posts! echo $this->get_ajax($ajax_url, $inputs); }
/** * action: auth_ajax_mt_file_import_all * * @access public * @param array $handler */ public function action_auth_ajax_mt_file_import_all($handler) { $text = file_get_contents($_SESSION['mtimport_mt_file']); try { $parser = new MTFileParser($text); } catch (Exception $e) { echo '<p>' . _t('Failed parsing File: ') . $e->getMessage() . '</p>'; return; } $posts = $parser->getResult(); @reset($posts); while (list(, $mt_post) = @each($posts)) { // Post $t_post = array(); $tags = array(); if (isset($mt_post['_META']['BASENAME'])) { $t_post['slug'] = $mt_post['_META']['BASENAME']; } $t_post['content_type'] = Post::type('entry'); $t_post['title'] = strip_tags(htmlspecialchars_decode(MultiByte::convert_encoding($mt_post['_META']['TITLE']))); if (isset($mt_post['EXTENDED BODY']['_BODY'])) { $t_post['content'] = MultiByte::convert_encoding($mt_post['BODY']['_BODY'] . $mt_post['EXTENDED BODY']['_BODY']); } else { $t_post['content'] = MultiByte::convert_encoding($mt_post['BODY']['_BODY']); } if (!isset($mt_post['_META']['STATUS']) || $mt_post['_META']['STATUS'] == 'Publish') { $t_post['status'] = Post::status('published'); } else { $t_post['status'] = Post::status('draft'); } $t_post['pubdate'] = $t_post['updated'] = HabariDateTime::date_create($mt_post['_META']['DATE']); if (isset($mt_post['_META']['CATEGORY'])) { $tags = array_merge($tags, $mt_post['_META']['CATEGORY']); } if (isset($mt_post['_META']['TAGS'])) { $t_tags = explode(',', $mt_post['_META']['TAGS']); $t_tags = array_map('trim', $t_tags, array('"')); $tags = array_merge($tags, $t_tags); } $post = new Post($t_post); if (isset($mt_post['_META']['ALLOW COMMENTS']) && $mt_post['_META']['ALLOW COMMENTS'] != 1) { $post->info->comments_disabled = 1; } $post->tags = array_unique($tags); $post->user_id = User::identify()->id; // TODO: import MT author try { $post->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $p->title . ' : ' . $e->getMessage(); Options::set('import_errors', $errors); } // Comments if (isset($mt_post['COMMENT'])) { @reset($mt_post['COMMENT']); while (list(, $mt_comment) = @each($mt_post['COMMENT'])) { $t_comment = array(); $t_comment['post_id'] = $post->id; $t_comment['name'] = MultiByte::convert_encoding($mt_comment['AUTHOR']); if (isset($mt_comment['EMAIL'])) { $t_comment['email'] = $mt_comment['EMAIL']; } if (isset($mt_comment['URL'])) { $t_comment['url'] = strip_tags($mt_comment['URL']); } if (isset($mt_comment['IP'])) { $t_comment['ip'] = $mt_comment['IP']; } $t_comment['content'] = MultiByte::convert_encoding($mt_comment['_BODY']); $t_comment['status'] = Comment::STATUS_APPROVED; $t_comment['date'] = HabariDateTime::date_create($mt_comment['DATE']); $t_comment['type'] = Comment::COMMENT; $comment = new Comment($t_comment); try { $comment->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } } } // Trackbacks if (isset($mt_post['PING'])) { @reset($mt_post['PING']); while (list(, $mt_comment) = @each($mt_post['PING'])) { $t_comment = array(); $t_comment['post_id'] = $post->id; $t_comment['name'] = MultiByte::convert_encoding($mt_comment['BLOG NAME'] . ' - ' . $mt_comment['TITLE']); if (isset($mt_comment['EMAIL'])) { $t_comment['email'] = $mt_comment['EMAIL']; } if (isset($mt_comment['URL'])) { $t_comment['url'] = strip_tags($mt_comment['URL']); } if (isset($mt_comment['IP'])) { $t_comment['ip'] = $mt_comment['IP']; } $t_comment['content'] = MultiByte::convert_encoding($mt_comment['_BODY']); $t_comment['status'] = Comment::STATUS_APPROVED; $t_comment['date'] = HabariDateTime::date_create($mt_comment['DATE']); $t_comment['type'] = Comment::TRACKBACK; $comment = new Comment($t_comment); try { $comment->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } } } } EventLog::log(_t('Import complete from MT Export File', 'mtimport')); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } }
/** * action: auth_ajax_blogger_import_all * * @access public * @param array $handler */ public function action_auth_ajax_blogger_import_all($handler) { $feed = simplexml_load_file($_SESSION['bloggerimport_file']); if (!$feed) { echo '<p>' . _t('Failed parsing File', 'bloggerimport') . '</p>'; return; } $post_id_map = array(); $post_map = array(); $result = DB::get_results("SELECT post_id,value FROM " . DB::table('postinfo') . " WHERE name='blogger_id';"); for ($i = 0; $i < count($result); $i++) { $post_id_map[$result[$i]->value] = $result[$i]->post_id; $post_map[] = $result[$i]->value; } $comment_map = DB::get_column("SELECT value FROM " . DB::table('commentinfo') . " WHERE name='blogger_id';"); $entry_count = count($feed->entry); for ($i = 0; $i < $entry_count; $i++) { $entry = $feed->entry[$i]; switch ((string) $entry->category[0]['term']) { // post case 'http://schemas.google.com/blogger/2008/kind#post': // already exists skipped if (in_array((string) $entry->id, $post_map)) { continue; } $t_post = array(); $t_post['title'] = MultiByte::convert_encoding((string) $entry->title); $t_post['content'] = MultiByte::convert_encoding((string) $entry->content); $t_post['user_id'] = User::identify()->id; // TODO: import Blogger author $t_post['pubdate'] = HabariDateTime::date_create((string) $entry->published); $t_post['content_type'] = Post::type('entry'); $entry->registerXPathNamespace('app', 'http://purl.org/atom/app#'); $result = $entry->xpath('//app:draft'); if (!empty($result) && (string) $result[0] == 'yes') { $t_post['status'] = Post::status('draft'); } else { $t_post['status'] = Post::status('published'); } $tags = array(); $category_count = count($entry->category); for ($j = 0; $j < count($category_count); $j++) { $tags[] = (string) $entry->category[$i]['term']; } $post = new Post($t_post); $post->tags = array_unique($tags); $post->info->blogger_id = (string) $entry->id; try { $post->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $post->title . ' : ' . $e->getMessage(); Options::set('import_errors', $errors); } $post_id_map[(string) $entry->id] = $post->id; break; // comment // comment case 'http://schemas.google.com/blogger/2008/kind#comment': // already exists skipped if (in_array((string) $entry->id, $comment_map)) { continue; } $result = $entry->xpath('//thr:in-reply-to'); if (empty($result) || !isset($post_id_map[(string) $result[0]['ref']])) { continue; } $t_comment = array(); $t_comment['post_id'] = $post_id_map[(string) $result[0]['ref']]; $t_comment['name'] = MultiByte::convert_encoding((string) $entry->author->name); if (isset($entry->author->email)) { $t_comment['email'] = (string) $entry->author->email; } if (isset($entry->author->uri)) { $t_comment['url'] = (string) $entry->author->uri; } $t_comment['content'] = MultiByte::convert_encoding((string) $entry->content); $t_comment['status'] = Comment::STATUS_APPROVED; $t_comment['date'] = HabariDateTime::date_create((string) $entry->published); $t_comment['type'] = Comment::COMMENT; $comment = new Comment($t_comment); $comment->info->blogger_id = (string) $entry->id; try { $comment->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } break; default: break; } } EventLog::log(_t('Import complete from Blogger Export File', 'bloggerimport')); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } }
/** * The plugin sink for the auth_ajax_drupal_import_posts hook. * Responds via authenticated ajax to requests for post importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_drupal_import_posts($handler) { $valid_fields = array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'import_comments', 'postindex', 'entry_type', 'page_type', 'tag_vocab'); $inputs = array_intersect_key($_POST->getArrayCopy(), array_flip($valid_fields)); extract($inputs); $drupaldb = $this->drupal_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix); if ($drupaldb) { $postcount = $drupaldb->get_value("SELECT count( nid ) FROM {$db_prefix}node WHERE type IN ( '{$entry_type}', '{$page_type}' );"); $min = $postindex * DRUPAL_IMPORT_BATCH + ($postindex == 0 ? 0 : 1); $max = min(($postindex + 1) * DRUPAL_IMPORT_BATCH, $postcount); $user_map = array(); $userinfo = DB::table('userinfo'); $user_info = DB::get_results("SELECT user_id, value FROM {$userinfo} WHERE name= 'drupal_uid';"); foreach ($user_info as $info) { $user_map[$info->value] = $info->user_id; } echo "<p>Importing posts {$min}-{$max} of {$postcount}.</p>"; $posts = $drupaldb->get_results("\n\t\t\t\tSELECT\n\t\t\t\t\tn.nid,\n\t\t\t\t\tnr.body as content,\n\t\t\t\t\tn.title,\n\t\t\t\t\tn.uid as user_id,\n\t\t\t\t\tFROM_UNIXTIME( n.created ) as pubdate,\n\t\t\t\t\tFROM_UNIXTIME( n.changed ) as updated,\n\t\t\t\t\tn.status as post_status,\n\t\t\t\t\tn.type as post_type\n\t\t\t\tFROM {$db_prefix}node AS n\n\t\t\t\tINNER JOIN {$db_prefix}node_revisions AS nr ON (nr.vid = n.vid)\n\t\t\t\tORDER BY n.nid DESC\n\t\t\t\tLIMIT {$min}, " . DRUPAL_IMPORT_BATCH, array(), 'Post'); $post_map = DB::get_column("SELECT value FROM {postinfo} WHERE name='drupal_nid';"); foreach ($posts as $post) { if (in_array($post->nid, $post_map)) { continue; } if ($tag_vocab) { $tags = $drupaldb->get_column("SELECT DISTINCT td.name\n\t\t\t\t\t\tFROM {$db_prefix}term_node AS tn\n\t\t\t\t\t\tINNER JOIN {$db_prefix}term_data AS td ON (td.tid = tn.tid AND td.vid = {$tag_vocab})\n\t\t\t\t\t\tWHERE tn.nid = {$post->nid}"); } else { $tags = array(); } $post->content = MultiByte::convert_encoding($post->content); $post->title = MultiByte::convert_encoding($post->title); $post_array = $post->to_array(); switch ($post_array['post_status']) { case '1': $post_array['status'] = Post::status('published'); break; default: $post_array['status'] = Post::status('draft'); break; } unset($post_array['post_status']); switch ($post_array['post_type']) { case $entry_type: $post_array['content_type'] = Post::type('entry'); break; case $page_type: $post_array['content_type'] = Post::type('page'); break; } unset($post_array['post_type']); $post_array['content'] = preg_replace('/<!--\\s*break\\s*-->/', '<!--more-->', $post_array['content']); $p = new Post($post_array); $p->id = null; $p->user_id = $user_map[$p->user_id]; $p->tags = $tags; $p->info->drupal_nid = $post_array['nid']; // Store the Drupal post id in the post_info table for later $p->exclude_fields(array('nid')); try { $p->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1)); $errors = Options::get('import_errors'); $errors[] = $p->title . ' : ' . $e->getMessage(); Options::set('import_errors', $errors); } } if ($max < $postcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'drupal_import_posts')); $postindex++; echo <<<DRUPAL_IMPORT_AJAX1 \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_host: "{$db_host}", \t\t\t\t\t\t\tdb_name: "{$db_name}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tdb_prefix: "{$db_prefix}", \t\t\t\t\t\t\timport_comments: "{$import_comments}", \t\t\t\t\t\t\tentry_type: "{$entry_type}", \t\t\t\t\t\t\tpage_type: "{$page_type}", \t\t\t\t\t\t\ttag_vocab: "{$tag_vocab}", \t\t\t\t\t\t\tpostindex: {$postindex} \t\t\t\t\t\t} \t\t\t\t\t ); \t\t\t\t</script> DRUPAL_IMPORT_AJAX1; } else { $ajax_url = URL::get('auth_ajax', array('context' => 'drupal_import_comments')); echo <<<DRUPAL_IMPORT_AJAX2 \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_host: "{$db_host}", \t\t\t\t\t\t\tdb_name: "{$db_name}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tdb_prefix: "{$db_prefix}", \t\t\t\t\t\t\timport_comments: "{$import_comments}", \t\t\t\t\t\t\tentry_type: "{$entry_type}", \t\t\t\t\t\t\tpage_type: "{$page_type}", \t\t\t\t\t\t\ttag_vocab: "{$tag_vocab}", \t\t\t\t\t\t\tcommentindex: 0 \t\t\t\t\t\t} \t\t\t\t\t ); \t\t\t\t</script> DRUPAL_IMPORT_AJAX2; } } else { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); echo '<p>' . _t('The database connection details have failed to connect.') . '</p>'; } }
/** * The plugin sink for the auth_ajax_chyrp_import_posts hook. * Responds via authenticated ajax to requests for post importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_chyrp_import_posts($handler) { $inputs = $_POST->filter_keys('db_type', 'db_name', 'db_host', 'db_user', 'db_pass', 'postindex'); foreach ($inputs as $key => $value) { ${$key} = $value; } $connect_string = $this->get_connect_string($db_type, $db_host, $db_name); $db = $this->chryp_connect($connect_string, $db_user, $db_pass); if ($db) { DB::begin_transaction(); $postcount = $db->get_value("SELECT count(id) FROM posts;"); $min = $postindex * IMPORT_BATCH + ($postindex == 0 ? 0 : 1); $max = min(($postindex + 1) * IMPORT_BATCH, $postcount); // old_id was set when we imported the users $user_map = array(); $user_info = DB::get_results("SELECT user_id, value FROM {userinfo} WHERE name='old_id';"); foreach ($user_info as $info) { $user_map[$info->value] = $info->user_id; } // Posts // id INTEGER PRIMARY KEY AUTOINCREMENT, // feather VARCHAR(32) DEFAULT '', // clean VARCHAR(128) DEFAULT '', // url VARCHAR(128) DEFAULT '', // pinned BOOLEAN DEFAULT FALSE, // status VARCHAR(32) DEFAULT 'public', // user_id INTEGER DEFAULT 0, // created_at DATETIME DEFAULT NULL, // updated_at DATETIME DEFAULT NULL // // Post attributes // post_id INTEGER NOT NULL , // name VARCHAR(100) DEFAULT '', // value LONGTEXT, echo "<p>Importing posts {$min}-{$max} of {$postcount}.</p>"; $posts = $db->get_results("\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tattr_body.value as content,\r\n\t\t\t\t\tid,\r\n\t\t\t\t\tattr_title.value as title,\r\n\t\t\t\t\tuser_id,\r\n\t\t\t\t\tcreated_at as pubdate,\r\n\t\t\t\t\tupdated_at as updated,\r\n\t\t\t\t\tupdated_at as modified,\r\n\t\t\t\t\tstatus\r\n\t\t\t\tFROM posts\r\n\t\t\t\tINNER JOIN post_attributes attr_title ON posts.id = attr_title.post_id AND attr_title.name = 'title'\r\n\t\t\t\tINNER JOIN post_attributes attr_body ON posts.id = attr_body.post_id AND attr_body.name = 'body'\r\n\t\t\t\tORDER BY id DESC\r\n\t\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Post'); $post_map = DB::get_column("SELECT value FROM {postinfo} WHERE name='old_id';"); foreach ($posts as $post) { if (in_array($post->id, $post_map)) { continue; } $post_array = $post->to_array(); $post_array['content_type'] = Post::type('entry'); $p = new Post($post_array); $p->slug = $post->slug; if (isset($user_map[$p->user_id])) { $p->user_id = $user_map[$p->user_id]; } else { $errors = Options::get('import_errors'); $errors[] = _t('Post author id %s was not found in the external database, assigning post "%s" (external post id #%d) to current user.', array($p->user_id, $p->title, $post_array['id'])); Options::set('import_errors', $errors); $p->user_id = User::identify()->id; } $p->guid = $p->guid; // Looks fishy, but actually causes the guid to be set. $p->info->old_id = $post_array['id']; // Store the old post id in the post_info table for later try { $p->insert(); $p->updated = $post_array['updated']; $p->update(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $p->title . ' : ' . $e->getMessage(); Options::set('import_errors', $errors); } } if (DB::in_transaction()) { DB::commit(); } if ($max < $postcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'chyrp_import_posts')); $postindex++; $vars = Utils::addslashes(array('host' => $db_host, 'name' => $db_name, 'user' => $db_user, 'pass' => $db_pass)); echo <<<IMPORT_POSTS \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_type: "{$db_type}", \t\t\t\t\t\t\tdb_host: "{$vars['host']}", \t\t\t\t\t\t\tdb_name: "{$vars['name']}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tpostindex: {$postindex} \t\t\t\t\t\t} \t\t\t\t\t); \t\t\t\t</script> IMPORT_POSTS; } else { EventLog::log('Import complete from "' . $db_name . '"'); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } } } else { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); Session::error($e->getMessage()); echo '<p>' . _t('The database connection details have failed to connect.') . '</p>'; } }
public function create($router, $user_id, $category_id, $category, $title, $content, $tag) { if ($user_id) { if ($category) { $cate = (new Category())->eq('name', $category)->find(); if (!$cate->id) { $cate->name = $category; $cate->count = 0; $cate->insert(); } $category_id = $cate->id; } $post = new Post(array('user_id' => (int) $user_id, 'category_id' => intval($category_id), 'title' => $title, 'content' => $content, 'time' => time())); $post->insert()->updateTag($tag)->updateCategory(); $router->error(302, '/post/' . $post->id . '/view', true); } $this->initSilder(); $this->cates = (new Category())->findAll(); $this->user = (new User())->find(1); $this->render('post.html'); }
function jkcomics_import_comic_from_file($file, $categoryId, $path) { $output = array(); $fullFilePath = $path . '/' . $file; $output[] = $fullFilePath; //$output[] = $file; $fileWithoutExtension = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file); $post_filename_parts = explode('_', $fileWithoutExtension); if (count($post_filename_parts) != 2) { $output[] = 'file error'; return implode("\n", $output); } $comic_date = array('y' => '', 'm' => '', 'd' => ''); $comic_date['y'] = $post_filename_parts[0]; $comic_date['m'] = substr($post_filename_parts[1], 0, -2); $comic_date['m'] = sprintf('%02d', $comic_date['m']); $comic_date['d'] = substr($post_filename_parts[1], -2); $comic_date['d'] = sprintf('%02d', $comic_date['d']); $comic_title = $comic_date['m'] . '-' . $comic_date['d'] . '-' . $comic_date['y']; //see if comic exists $existingPage = get_page_by_title($comic_title, 'OBJECT', 'jkcomic'); if ($existingPage) { $output[] = $comic_title . ' post exists'; } else { $output[] = $comic_title . ' post does not exist'; $post = new Post(); $post->type = 'jkcomic'; $post->title = $comic_title; $post->setDate($comic_date['y'] . '-' . $comic_date['m'] . '-' . $comic_date['d']); $existingPage = $post->insert(); } if ($existingPage) { //Attach taxonomy wp_set_post_terms($existingPage->ID, array($categoryId), 'comic_types'); //Attach image $existingAttachmentId = get_post_meta($existingPage->ID, '_thumbnail_id', true); $output[] = '<br/>' . $existingAttachmentId . '<br/>'; if (empty($existingAttachmentId)) { $attachment = new Attachment(); $output[] = $attachment->uploadFeaturedImage($fullFilePath, $existingPage->ID); } } //return return implode("\n", $output); }
/** * Handler thread creation form */ public function filter_handle_thread_reply($output, $form, $thread, $forum) { if (!self::has_permission('reply', $thread)) { return _t('<p>You are not authorized to reply to this thread.</p>'); } $postdata = array('user_id' => User::identify()->id, 'pubdate' => HabariDateTime::date_create(), 'content_type' => Post::type('reply'), 'content' => $form->content->value, 'status' => Post::status('published')); $reply = new Post($postdata); $reply->insert(); if (self::$anonymity && $form->anonymous->value == TRUE) { $reply->info->anonymous = TRUE; } // Do vocab stuff $vocab = Vocabulary::get(self::$vocab); $parent_term = $vocab->get_term($thread->slug); $reply_term = $vocab->add_term($reply->slug, $parent_term); $reply->update(); Utils::redirect($reply->permalink); return '...'; }
/** * The plugin sink for the auth_ajax_hab_import_posts hook. * Responds via authenticated ajax to requests for post importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_hab_import_posts($handler) { $inputs = $_POST->filter_keys('db_type', 'db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'postindex', 'tag_import'); $inputs = $inputs->getArrayCopy($inputs); $inputs = array_merge($this->default_values, $inputs); $connect_string = $this->get_connect_string($inputs['db_type'], $inputs['db_host'], $inputs['db_name']); $db = $this->hab_connect($connect_string, $inputs['db_user'], $inputs['db_pass']); if (!$db) { EventLog::log(sprintf(_t('Failed to import from "%s"'), $inputs['db_name']), 'crit'); Session::error($e->getMessage()); echo '<p>' . _t('The database connection details have failed to connect.') . '</p>'; } DB::begin_transaction(); $old_db_version = (int) $db->get_value("SELECT value FROM {$inputs['db_prefix']}options WHERE name = ?", array('db_version')); $postcount = $db->get_value("SELECT count( id ) FROM {$inputs['db_prefix']}posts;"); $min = $inputs['import_index'] * IMPORT_BATCH + ($inputs['import_index'] == 0 ? 0 : 1); $max = min(($inputs['import_index'] + 1) * IMPORT_BATCH, $postcount); $user_map = array(); $user_info = DB::get_results("SELECT user_id, value FROM {userinfo} WHERE name= 'old_id';"); foreach ($user_info as $info) { $user_map[$info->value] = $info->user_id; } echo "<p>Importing posts {$min}-{$max} of {$postcount}.</p>"; $posts = $db->get_results("\r\n\t\t\tSELECT\r\n\t\t\t\tcontent,\r\n\t\t\t\tid,\r\n\t\t\t\ttitle,\r\n\t\t\t\tslug,\r\n\t\t\t\tuser_id,\r\n\t\t\t\tguid,\r\n\t\t\t\tpubdate,\r\n\t\t\t\tupdated,\r\n\t\t\t\tmodified,\r\n\t\t\t\tstatus,\r\n\t\t\t\tcontent_type\r\n\t\t\tFROM {$inputs['db_prefix']}posts\r\n\t\t\tORDER BY id DESC\r\n\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Post'); $post_map = DB::get_column("SELECT value FROM {$inputs['db_prefix']}postinfo WHERE name='old_id';"); foreach ($posts as $post) { if (in_array($post->id, $post_map)) { continue; } if ($inputs['tag_import'] == 1) { // Import tags if ($old_db_version < 3749) { $tags = $db->get_column("SELECT tag_text\r\n\t\t\t\t\t\tFROM {$inputs['db_prefix']}tags\r\n\t\t\t\t\t\tINNER JOIN {$inputs['db_prefix']}tag2post\r\n\t\t\t\t\t\tON {$inputs['db_prefix']}tags.id = {$inputs['db_prefix']}tag2post.tag_id\r\n\t\t\t\t\t\tWHERE post_id = {$post->id}"); } else { $tags = $db->get_column("SELECT term_display\r\n\t\t\t\t\t\tFROM {$inputs['db_prefix']}terms\r\n\t\t\t\t\t\tINNER JOIN {$inputs['db_prefix']}object_terms\r\n\t\t\t\t\t\tON {$inputs['db_prefix']}terms.id = {$inputs['db_prefix']}object_terms.term_id\r\n\t\t\t\t\t\tWHERE object_id = ? AND object_type_id = ?", array($post->id, Vocabulary::object_type_id('post'))); } } else { $tags = array(); } $tags = implode(',', $tags); $post_array = $post->to_array(); $p = new Post($post_array); $p->slug = $post->slug; if (isset($user_map[$p->user_id])) { $p->user_id = $user_map[$p->user_id]; } else { $errors = Options::get('import_errors'); $errors[] = _t('Post author id %s was not found in the external database, assigning post "%s" (external post id #%d) to current user.', array($p->user_id, $p->title, $post_array['id'])); Options::set('import_errors', $errors); $p->user_id = User::identify()->id; } $p->guid = $p->guid; // Looks fishy, but actually causes the guid to be set. $p->tags = $tags; $infos = $db->get_results("SELECT name, value, type FROM {$inputs['db_prefix']}postinfo WHERE post_id = ?", array($post_array['id'])); $p->info->old_id = $post_array['id']; // Store the old post id in the post_info table for later try { $p->insert(); $p->updated = $post_array['updated']; $p->update(); foreach ($infos as $info) { $fields = $info->get_url_args(); $fields['post_id'] = $p->id; DB::insert(DB::table('postinfo'), $fields); } } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $p->title . ' : ' . $e->getMessage(); Options::set('import_errors', $errors); } } if (DB::in_transaction()) { DB::commit(); } if ($max < $postcount) { $inputs['import_index']++; $ajax_url = URL::get('auth_ajax', array('context' => 'hab_import_posts')); } else { $inputs['import_index'] = 0; $ajax_url = URL::get('auth_ajax', array('context' => 'hab_import_comments')); } echo $this->get_ajax($ajax_url, $inputs); }
function saveNewPost() { Doo::loadHelper('DooValidator'); $_POST['content'] = trim($_POST['content']); //get defined rules and add show some error messages $validator = new DooValidator(); $validator->checkMode = DooValidator::CHECK_SKIP; if ($error = $validator->validate($_POST, 'post_create.rules')) { $data['rootUrl'] = Doo::conf()->APP_URL; $data['title'] = 'Error Occured!'; $data['content'] = '<p style="color:#ff0000;">' . $error . '</p>'; $data['content'] .= '<p>Go <a href="javascript:history.back();">back</a> to edit.</p>'; $this->render('admin_msg', $data); } else { Doo::loadModel('Post'); Doo::loadModel('Tag'); Doo::autoload('DooDbExpression'); $p = new Post($_POST); $p->createtime = new DooDbExpression('NOW()'); //insert the post along with the tags if (self::$tags != Null) { $tags = array(); foreach (self::$tags as $t) { $tg = new Tag(); $tg->name = $t; $tags[] = $tg; } $id = $p->relatedInsert($tags); } else { $id = $p->insert(); } //clear the sidebar cache Doo::cache('front')->flushAllParts(); $data['rootUrl'] = Doo::conf()->APP_URL; $data['title'] = 'Post Created!'; $data['content'] = '<p>Your post is created successfully!</p>'; if ($p->status == 1) { $data['content'] .= '<p>Click <a href="' . $data['rootUrl'] . 'article/' . $id . '">here</a> to view the published post.</p>'; } $this->render('admin_msg', $data); } }
$user = User::getByName($userName); if ($user == null) { $user = new User(); $user->setUserName($userName); $user->setRegistryDate(date('Y-m-d H:i:s')); $user->insert(); } $thread->setUserId($user->getUserId()); $thread->setCreated(date('Y-m-d H:i:s')); $thread->insert(); $post = new Post(); $post->setUserId($user->getUserId()); $post->setThreadId($thread->getThreadId()); $post->setCreated(date('Y-m-d H:i:s')); $post->setContent(trim($_POST['content'])); $post->insert(); header("Location: /index.php?thread=" . $thread->getThreadId()); die; } ?> <html> <head> <title>Форум</title> <meta charset="utf-8"/> </head> <body> <?php $view = View::getView(View::VIEW_MAIN); $view->show(); ?> </body> </html>
/** * The plugin sink for the auth_ajax_wp_import_posts hook. * Responds via authenticated ajax to requests for post importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_wp_import_posts($handler) { $valid_fields = array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'postindex', 'category_import', 'utw_import'); $inputs = array_intersect_key($_POST->getArrayCopy(), array_flip($valid_fields)); extract($inputs); if (!isset($inputs['category_import'])) { $inputs['category_import'] = 0; } if (!isset($inputs['utw_import'])) { $inputs['utw_import'] = 0; } $wpdb = $this->wp_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix); if ($wpdb) { if (!DB::in_transaction()) { DB::begin_transaction(); } $has_taxonomy = count($wpdb->get_column("SHOW TABLES LIKE '{$db_prefix}term_taxonomy';")); $postcount = $wpdb->get_value("SELECT count( id ) FROM {$db_prefix}posts;"); $min = $postindex * IMPORT_BATCH + ($postindex == 0 ? 0 : 1); $max = min(($postindex + 1) * IMPORT_BATCH, $postcount); $user_map = array(); $userinfo = DB::table('userinfo'); $user_info = DB::get_results("SELECT user_id, value FROM {$userinfo} WHERE name= 'wp_id';"); foreach ($user_info as $info) { $user_map[$info->value] = $info->user_id; } echo "<p>Importing posts {$min}-{$max} of {$postcount}.</p>"; $posts = $wpdb->get_results("\n\t\t\t\tSELECT\n\t\t\t\t\tpost_content as content,\n\t\t\t\t\tID as id,\n\t\t\t\t\tpost_title as title,\n\t\t\t\t\tpost_name as slug,\n\t\t\t\t\tpost_author as user_id,\n\t\t\t\t\tguid as guid,\n\t\t\t\t\tpost_date as pubdate,\n\t\t\t\t\tpost_modified as updated,\n\t\t\t\t\tpost_status,\n\t\t\t\t\tpost_type\n\t\t\t\tFROM {$db_prefix}posts\n\t\t\t\tWHERE post_type != 'revision' AND post_type != 'attachment'\n\t\t\t\tORDER BY ID DESC\n\t\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Post'); $post_map = DB::get_column("SELECT value FROM {postinfo} WHERE name='wp_id';"); foreach ($posts as $post) { if (in_array($post->id, $post_map)) { continue; } if ($has_taxonomy) { // Importing from >= WP2.3 if ($category_import == 1) { // Import WP category and tags as tags $taxonomies = "({$db_prefix}term_taxonomy.taxonomy= 'category' OR {$db_prefix}term_taxonomy.taxonomy= 'post_tag')"; } else { // Import WP tags as tags $taxonomies = "{$db_prefix}term_taxonomy.taxonomy= 'post_tag'"; } $tags = $wpdb->get_column("SELECT DISTINCT name\n\t\t\t\t\t\tFROM {$db_prefix}terms\n\t\t\t\t\t\tINNER JOIN {$db_prefix}term_taxonomy\n\t\t\t\t\t\tON ( {$db_prefix}terms.term_id= {$db_prefix}term_taxonomy.term_id AND {$taxonomies} )\n\t\t\t\t\t\tINNER JOIN {$db_prefix}term_relationships\n\t\t\t\t\t\tON ({$db_prefix}term_taxonomy.term_taxonomy_id= {$db_prefix}term_relationships.term_taxonomy_id)\n\t\t\t\t\t\tWHERE {$db_prefix}term_relationships.object_id= {$post->id}"); } else { // Importing from < WP2.3 if ($category_import == 1) { // Import WP category as tags $tags = $wpdb->get_column("SELECT category_nicename\n\t\t\t\t\t\t\tFROM {$db_prefix}post2cat\n\t\t\t\t\t\t\tINNER JOIN {$db_prefix}categories\n\t\t\t\t\t\t\tON ( {$db_prefix}categories.cat_ID= {$db_prefix}post2cat.category_id )\n\t\t\t\t\t\t\tWHERE post_id= {$post->id}"); } else { $tags = array(); } } // we want to include the Ultimate Tag Warrior in that list of tags if ($utw_import == 1 && count(DB::get_results("show tables like 'post2tag'"))) { $utw_tags = $wpdb->get_column("SELECT tag\n\t\t\t\t\tFROM {$db_prefix}post2tag\n\t\t\t\t\tINNER JOIN {$db_prefix}tags\n\t\t\t\t\tON ( {$db_prefix}tags.tag_ID= {$db_prefix}post2tag.tag_id )\n\t\t\t\t\tWHERE post_id= {$post->id}"); // UTW substitutes underscores and hyphens for spaces, so let's do the same $utw_tag_formatter = create_function('$a', 'return preg_replace( "/_|-/", " ", $a );'); // can this be done in just two calls instead of three? I think so. $tags = array_unique(array_merge($tags, array_map($utw_tag_formatter, $utw_tags))); } $post->content = MultiByte::convert_encoding($post->content); $post->title = MultiByte::convert_encoding($post->title); $tags = implode(',', $tags); $tags = MultiByte::convert_encoding($tags); $post_array = $post->to_array(); switch ($post_array['post_status']) { case 'publish': $post_array['status'] = Post::status('published'); break; default: $post_array['status'] = Post::status($post_array['post_status']); break; } unset($post_array['post_status']); switch ($post_array['post_type']) { case 'post': $post_array['content_type'] = Post::type('entry'); break; case 'page': $post_array['content_type'] = Post::type('page'); break; default: // We're not inserting WP's media records. That would be silly. continue; } unset($post_array['post_type']); $p = new Post($post_array); $p->slug = $post->slug; if (isset($user_map[$p->user_id])) { $p->user_id = $user_map[$p->user_id]; } else { $errors = Options::get('import_errors'); $errors[] = _t('Post author id %s was not found in WP database, assigning post "%s" (WP post id #%d) to current user.', array($p->user_id, $p->title, $post_array['id'])); Options::set('import_errors', $errors); $p->user_id = User::identify()->id; } $p->guid = $p->guid; // Looks fishy, but actually causes the guid to be set. $p->tags = $tags; $p->info->wp_id = $post_array['id']; // Store the WP post id in the post_info table for later try { $p->insert(); $p->updated = $post_array['updated']; $p->update(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $p->title . ' : ' . $e->getMessage(); Options::set('import_errors', $errors); } } if (DB::in_transaction()) { DB::commit(); } if ($max < $postcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'wp_import_posts')); $postindex++; $vars = Utils::addslashes(array('host' => $db_host, 'name' => $db_name, 'user' => $db_user, 'pass' => $db_pass, 'prefix' => $db_prefix)); echo <<<WP_IMPORT_AJAX1 \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_host: "{$vars['host']}", \t\t\t\t\t\t\tdb_name: "{$vars['name']}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tdb_prefix: "{$vars['prefix']}", \t\t\t\t\t\t\tcategory_import: "{$category_import}", \t\t\t\t\t\t\tutw_import: "{$utw_import}", \t\t\t\t\t\t\tpostindex: {$postindex} \t\t\t\t\t\t} \t\t\t\t\t ); \t\t\t\t</script> WP_IMPORT_AJAX1; } else { $ajax_url = URL::get('auth_ajax', array('context' => 'wp_import_comments')); $vars = Utils::addslashes(array('host' => $db_host, 'name' => $db_name, 'user' => $db_user, 'pass' => $db_pass, 'prefix' => $db_prefix)); echo <<<WP_IMPORT_AJAX2 \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_host: "{$vars['host']}", \t\t\t\t\t\t\tdb_name: "{$vars['name']}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tdb_prefix: "{$vars['prefix']}", \t\t\t\t\t\t\tcategory_import: "{$category_import}", \t\t\t\t\t\t\tutw_import: "{$utw_import}", \t\t\t\t\t\t\tcommentindex: 0 \t\t\t\t\t\t} \t\t\t\t\t ); \t\t\t\t</script> WP_IMPORT_AJAX2; } } else { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); Session::error($e->getMessage()); echo '<p>' . _t('The database connection details have failed to connect.') . '</p>'; } }
$mail->From = '*****@*****.**'; $mail->FromName = 'Selenium分享'; foreach ($user_list as $ldap_name => $name) { $mail->addAddress($ldap_name . "@rd.xxx.com", $name); // Add a recipient } $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); // Set email format to HTML $mail->Subject = "[Selenium有新分享]: " . $subject; $mail->Body = "<b>{$user}于{$time}在<a href='http://selenium.iyoudao.net'>论坛</a>分享了他的心得:</b><br><pre>" . $body . "</pre>"; if (!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; return false; } return true; } $post = new Post(); if ($postid == "-1") { $result = $post->insert($title, $author, $type, $tag, $content); if ($mail_send == "1") { send_mail($user_list, $title, $content, $author); } echo "1"; } else { $post->update($postid, $title, $author, $type, $tag, $content); echo "1"; } $post->closeDB();
/** * Create a post and save it. * * @param array $paramarray An associative array of post fields * @return Post The new Post object */ static function create( $paramarray ) { $post = new Post( $paramarray ); $post->insert(); return $post; }
/** * Imports a single post from the s9y database into the * habari database. * * Note that this function calls import_comment() for each * comment attached to the imported post * * @param post_info QueryRecord of imported post information * @param habari_user_id The habari user ID of the post's author * @return TRUE or FALSE if import of post succeeded */ private function import_post($post_info = array(), $habari_user_id) { /* * Import the post itself */ $post = new Post(); $post->user_id = $habari_user_id; $post->guid = $post->guid; /* @TODO: This works to create a GUID, but man, it's weird. */ $post->info->s9y_id = $post_info->id; $post->title = $this->transcode($post_info->title); $content = empty($post_info->extended) ? $post_info->body : $post_info->body . $post_info->extended; $post->content = $this->transcode($content); $post->status = $post_info->isdraft == "true" ? Post::status('draft') : Post::status('published'); $post->content_type = Post::type('entry'); $post->updated = date('Y-m-d H:i:s', $post_info->last_modified); $post->pubdate = $post_info->isdraft == "false" ? date('Y-m-d H:i:s', $post_info->timestamp) : NULL; if ($this->category_import && isset($categories) && $categories instanceof QueryRecord) { $post->tags = $categories->to_array(); } if ($post->insert()) { if ($this->port_rewrites) { $rewrite = new RewriteRule(array('name' => 'from_s9yimporter_' . $post_info->id, 'parse_regex' => '%^archives/' . $post_info->id . '-(?P<r>.*)$%i', 'build_str' => $post->slug . '(/{$p})', 'handler' => 'actionHandler', 'action' => 'redirect', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'redirects /archives/' . $post_info->id . ' to /' . $post->slug)); $rewrite->insert(); } /* * If we are going to import taxonomy, , then first check to see if * this post has any categories attached to it, and import the relationship * using the cached habari->s9y tag map. * * mysql> desc s9y_entrycat; * +------------+---------+------+-----+---------+-------+ * | Field | Type | Null | Key | Default | Extra | * +------------+---------+------+-----+---------+-------+ * | entryid | int(11) | NO | PRI | 0 | | * | categoryid | int(11) | NO | PRI | 0 | | * +------------+---------+------+-----+---------+-------+ */ $result = TRUE; if ($this->category_import) { $sql = <<<ENDOFSQL SELECT c.categoryid FROM {$this->s9y_db_prefix}category c INNER JOIN {$this->s9y_db_prefix}entrycat ec ON c.categoryid = ec.categoryid AND ec.entryid = ? ENDOFSQL; if (FALSE !== ($categories = $this->s9ydb->get_results($sql, array($post_info->id), 'QueryRecord'))) { foreach ($categories as $category) { $result &= $this->import_post_category($post->id, $this->imported_categories[$category->categoryid]); if ($this->port_rewrites && !isset($this->rewritten_categories[$category->categoryid])) { // rss feed link: $this->rewritten_categories[$category->categoryid] = 1; $rew_url = URL::get('atom_feed_tag', array('tag' => $this->imported_category_names[$category->categoryid]), true, false, false); $rewrite = new RewriteRule(array('name' => 'from_s9yimporter_category_feed', 'parse_regex' => '%^feeds/categories/' . $category->categoryid . '-(?P<r>.*)$%i', 'build_str' => $rew_url . '(/{$p})', 'handler' => 'actionHandler', 'action' => 'redirect', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'redirects s9y category feed to habari feed')); $rewrite->insert(); } } } } /* * Grab the comments and insert `em * * mysql> desc s9y_comments; * +------------+----------------------+------+-----+---------+----------------+ * | Field | Type | Null | Key | Default | Extra | * +------------+----------------------+------+-----+---------+----------------+ * | id | int(11) | NO | PRI | NULL | auto_increment | * | entry_id | int(10) unsigned | NO | MUL | 0 | | * | parent_id | int(10) unsigned | NO | MUL | 0 | | * | timestamp | int(10) unsigned | YES | | NULL | | * | title | varchar(150) | YES | | NULL | | * | author | varchar(80) | YES | | NULL | | * | email | varchar(200) | YES | | NULL | | * | url | varchar(200) | YES | | NULL | | * | ip | varchar(15) | YES | | NULL | | * | body | text | YES | | NULL | | * | type | varchar(100) | YES | MUL | regular | | * | subscribed | enum('true','false') | NO | | true | | * | status | varchar(50) | NO | MUL | | | * | referer | varchar(200) | YES | | NULL | | * +------------+----------------------+------+-----+---------+----------------+ */ $sql = <<<ENDOFSQL SELECT \tid , parent_id , `timestamp` , title , author , email , url , ip , body , type , subscribed , status , referer FROM {$this->s9y_db_prefix}comments WHERE entry_id = ? ENDOFSQL; if ($this->comments_ignore_unapproved) { $sql .= " AND status = 'Approved' "; } $comments = $this->s9ydb->get_results($sql, array($post_info->id), 'QueryRecord'); if (count($comments) > 0) { echo "Starting import of <b>" . count($comments) . "</b> comments for post \"" . $post->title . "\"..."; foreach ($comments as $comment) { $result &= $this->import_comment($comment, $post->id); } if ($result) { echo $this->success_html() . "<br />"; } else { echo $this->fail_html() . "<br />"; } return $result; } else { return TRUE; } } else { /* Something went wrong on $post->insert() */ EventLog::log($e->getMessage(), 'err', null, null, print_r(array($post, $e), 1)); Session::error($e->getMessage()); return FALSE; } }