示例#1
0
文件: Post.php 项目: relisher/chyrp
 /**
  * Function: add
  * Adds a post to the database.
  *
  * Most of the function arguments will fall back to various POST values.
  *
  * Calls the @add_post@ trigger with the inserted post and extra options.
  *
  * Note: The default parameter values are empty here so that the fallbacks work properly.
  *
  * Parameters:
  *     $values - The data to insert.
  *     $clean - The sanitized URL (or empty to default to "(feather).(new post's id)").
  *     $url - The unique URL (or empty to default to "(feather).(new post's id)").
  *     $feather - The feather to post as.
  *     $user - <User> to set as the post's author.
  *     $pinned - Pin the post?
  *     $status - Post status
  *     $created_at - New @created_at@ timestamp for the post.
  *     $updated_at - New @updated_at@ timestamp for the post, or @false@ to not updated it.
  *     $trackbacks - URLs separated by " " to send trackbacks to.
  *     $pingbacks - Send pingbacks?
  *     $options - Options for the post.
  *
  * Returns:
  *     The newly created <Post>.
  *
  * See Also:
  *     <update>
  */
 static function add($values = array(), $clean = "", $url = "", $feather = null, $user = null, $pinned = null, $status = "", $created_at = null, $updated_at = null, $trackbacks = "", $pingbacks = true, $options = array())
 {
     $user_id = $user instanceof User ? $user->id : $user;
     $sql = SQL::current();
     $visitor = Visitor::current();
     $trigger = Trigger::current();
     fallback($feather, oneof(@$_POST['feather'], ""));
     fallback($user_id, oneof(@$_POST['user_id'], Visitor::current()->id));
     fallback($pinned, !empty($_POST['pinned']));
     fallback($status, isset($_POST['draft']) ? "draft" : oneof(@$_POST['status'], "public"));
     fallback($created_at, (!empty($_POST['created_at']) and (!isset($_POST['original_time']) or $_POST['created_at'] != $_POST['original_time'])) ? datetime($_POST['created_at']) : datetime());
     fallback($updated_at, oneof(@$_POST['updated_at'], null));
     fallback($trackbacks, oneof(@$_POST['trackbacks'], ""));
     fallback($options, oneof(@$_POST['option'], array()));
     if (isset($clean) and !isset($url)) {
         $url = self::check_url($clean);
     }
     if (isset($_POST['bookmarklet'])) {
         $trigger->filter($values, "bookmarklet_submit_values");
         $trigger->filter($options, "bookmarklet_submit_options");
     }
     $new_values = array("feather" => $feather, "user_id" => $user_id, "pinned" => (int) $pinned, "status" => $status, "clean" => $clean, "url" => $url, "created_at" => $created_at, "updated_at" => $updated_at);
     $trigger->filter($new_values, "before_add_post");
     $sql->insert("posts", $new_values);
     $id = $sql->latest("posts");
     if (empty($clean) or empty($url)) {
         $sql->update("posts", array("id" => $id), array("clean" => $feather . "." . $id, "url" => $feather . "." . $id));
     }
     # Insert the post attributes.
     foreach (array_merge($values, $options) as $name => $value) {
         $sql->insert("post_attributes", array("post_id" => $id, "name" => $name, "value" => $value));
     }
     $post = new self($id, array("drafts" => true));
     if ($trackbacks !== "") {
         $trackbacks = explode(",", $trackbacks);
         $trackbacks = array_map("trim", $trackbacks);
         $trackbacks = array_map("strip_tags", $trackbacks);
         $trackbacks = array_unique($trackbacks);
         $trackbacks = array_diff($trackbacks, array(""));
         foreach ($trackbacks as $url) {
             trackback_send($post, $url);
         }
     }
     if (Config::current()->send_pingbacks and $pingbacks) {
         foreach ($values as $key => $value) {
             send_pingbacks($value, $post);
         }
     }
     $post->redirect = isset($_POST['bookmarklet']) ? url("/admin/?action=bookmarklet&done") : $post->url();
     $trigger->call("add_post", $post, $options);
     return $post;
 }
示例#2
0
文件: xmlrpc.php 项目: relisher/chyrp
 public function metaWeblog_newPost($args)
 {
     $this->auth($args[1], $args[2], 'add');
     global $user;
     # Support for extended body
     $body = $args[3]['description'];
     if (!empty($args[3]['mt_text_more'])) {
         $body .= '<!--more-->' . $args[3]['mt_text_more'];
     }
     # Add excerpt to body so it isn't lost
     if (!empty($args[3]['mt_excerpt'])) {
         $body = $args[3]['mt_excerpt'] . "\n\n" . $body;
     }
     if (trim($body) === '') {
         return new IXR_Error(500, __("Body can't be blank."));
     }
     $clean = sanitize(oneof(@$args[3]['mt_basename'], $args[3]['title']));
     $url = Post::check_url($clean);
     $_POST['user_id'] = $user->id;
     $_POST['feather'] = XML_RPC_FEATHER;
     $_POST['created_at'] = oneof($this->convertFromDateCreated($args[3]), datetime());
     if ($user->group->can('add_post')) {
         $_POST['status'] = $args[4] ? 'public' : 'draft';
     } else {
         $_POST['status'] = 'draft';
     }
     $trigger = Trigger::current();
     $trigger->call('metaWeblog_newPost_preQuery', $args[3]);
     $post = Post::add(array('title' => $args[3]['title'], 'body' => $body), $clean, $url);
     if ($post->no_results) {
         return new IXR_Error(500, __("Post not found."));
     }
     $trigger->call('metaWeblog_newPost', $args[3], $post);
     # Send any and all pingbacks to URLs in the body
     if (Config::current()->send_pingbacks) {
         send_pingbacks($args[3]['description'], $post);
     }
     return $post->id;
 }