本文整理汇总了PHP中Post::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::insert方法的具体用法?PHP Post::insert怎么用?PHP Post::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
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);
}
示例2: run
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);
}
示例3: insertProcess
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);
}
示例4: action_auth_ajax_wp_import_posts
//.........这里部分代码省略.........
// 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);
}
示例5: action_auth_ajax_mt_file_import_all
/**
* 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']);
//.........这里部分代码省略.........
示例6: action_auth_ajax_blogger_import_all
/**
* 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;
//.........这里部分代码省略.........
示例7: action_auth_ajax_drupal_import_posts
/**
* 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: "{$db_user}",
\t\t\t\t\t\t\tdb_pass: "{$db_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(
//.........这里部分代码省略.........
示例8: action_auth_ajax_chyrp_import_posts
/**
* 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: "{$vars['user']}",
\t\t\t\t\t\t\tdb_pass: "{$vars['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 . '"');
//.........这里部分代码省略.........
示例9: create
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');
}
示例10: jkcomics_import_comic_from_file
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);
}
示例11: filter_handle_thread_reply
/**
* 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 '...';
}
示例12: action_auth_ajax_hab_import_posts
/**
* 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);
}
示例13: saveNewPost
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);
}
}
示例14: User
$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>
示例15: action_auth_ajax_wp_import_posts
//.........这里部分代码省略.........
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: "{$vars['user']}",
\t\t\t\t\t\t\tdb_pass: "{$vars['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: "{$vars['user']}",
\t\t\t\t\t\t\tdb_pass: "{$vars['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>';
}
}