Beispiel #1
0
 /**
  * Update attachment.
  *
  * @since 2.2.0
  *
  * @param int $postID Post ID.
  */
 function put_attachment($postID)
 {
     // checked for valid content-types (atom+xml)
     // quick check and exit
     $this->get_accepted_content_type($this->atom_content_types);
     $parser = new AtomParser();
     if (!$parser->parse()) {
         $this->bad_request();
     }
     $parsed = array_pop($parser->feed->entries);
     // check for not found
     global $entry;
     $this->set_current_entry($postID);
     if (!current_user_can('edit_post', $entry['ID'])) {
         $this->auth_required(__('Sorry, you do not have the right to edit this post.'));
     }
     extract($entry);
     $post_title = $parsed->title[1];
     $post_content = $parsed->summary[1];
     $pubtimes = $this->get_publish_time($parsed->updated);
     $post_modified = $pubtimes[0];
     $post_modified_gmt = $pubtimes[1];
     $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_modified', 'post_modified_gmt');
     $this->escape($postdata);
     $result = wp_update_post($postdata);
     if (!$result) {
         $this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.'));
     }
     log_app('function', "put_attachment({$postID})");
     $this->ok();
 }
Beispiel #2
0
    function testExtensiveAtomExampleFromRFC4287()
    {
        $fake_atom_file = <<<ATOM
<?xml version="1.0" encoding="utf-8"?>

<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">dive into mark</title>
  <subtitle type="html">
    A &lt;em&gt;lot&lt;/em&gt; of effort
    went into making this effortless
  </subtitle>

  <updated>2005-07-31T12:29:29Z</updated>
  <id>tag:example.org,2003:3</id>
  <link rel="alternate" type="text/html" 
   hreflang="en" href="http://example.org/"/>
  <link rel="self" type="application/atom+xml" 
   href="http://example.org/feed.atom"/>
  <rights>Copyright (c) 2003, Mark Pilgrim</rights>

  <generator uri="http://www.example.com/" version="1.0">
    Example Toolkit
  </generator>
  <entry>
    <title>Atom draft-07 snapshot</title>
    <link rel="alternate" type="text/html" 
     href="http://example.org/2005/04/02/atom"/>

    <link rel="enclosure" type="audio/mpeg" length="1337"
     href="http://example.org/audio/ph34r_my_podcast.mp3"/>
    <id>tag:example.org,2003:3.2397</id>
    <updated>2005-07-31T12:29:29Z</updated>
    <published>2003-12-13T08:29:29-04:00</published>

    <author>
      <name>Mark Pilgrim</name>
      <uri>http://example.org/</uri>
      <email>f8dy@example.com</email>

    </author>
    <contributor>
      <name>Sam Ruby</name>
    </contributor>
    <contributor>

      <name>Joe Gregorio</name>
    </contributor>
    <content type="xhtml" xml:lang="en" 
     xml:base="http://diveintomark.org/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><i>[Update: The Atom draft is finished.]</i></p>

      </div>
    </content>
  </entry>
</feed>
ATOM;
        $parser = new AtomParser();
        $parser->parse($fake_atom_file);
        $this->assertFalse(count($parser->feed) == 0);
        $current_feed = $parser->feed[0];
        $this->assertEquals("dive into mark", $current_feed["title"]);
        $this->assertEquals("Copyright (c) 2003, Mark Pilgrim", $current_feed["rights"]);
        $this->assertEquals("A <em>lot</em> of effort\n    went into making this effortless", $current_feed["subtitle"]);
        $this->assertEquals("2005-07-31T12:29:29Z", $current_feed["updated"]);
        $this->assertEquals("tag:example.org,2003:3", $current_feed["id"]);
        $this->assertEquals("Example Toolkit", $current_feed["generator"]);
        $this->assertTrue(count($current_feed["authors"]) == 0);
        $this->assertTrue(count($current_feed["contributors"]) == 0);
        $this->assertFalse(count($parser->entries) == 0);
        $current_entry = $parser->entries[0];
        $this->assertEquals("Atom draft-07 snapshot", $current_entry["title"]);
        $this->assertEquals("2005-07-31T12:29:29Z", $current_entry["updated"]);
        $this->assertEquals("2003-12-13T08:29:29-04:00", $current_entry["published"]);
        $this->assertEquals("tag:example.org,2003:3.2397", $current_entry["id"]);
        $this->assertEquals(2, count($current_entry["links"]));
        $this->assertTrue(count($current_entry["authors"]) == 1);
        $this->assertTrue(count($current_entry["contributors"]) == 2);
        $current_author = $current_entry["authors"][0];
        $this->assertEquals("Mark Pilgrim", $current_author["name"]);
        $this->assertEquals("*****@*****.**", $current_author["email"]);
        $first_contributor = $current_entry["contributors"][0];
        $second_contributor = $current_entry["contributors"][1];
        $this->assertEquals("Sam Ruby", $first_contributor["name"]);
        $this->assertEquals("Joe Gregorio", $second_contributor["name"]);
        $first_link = $current_entry["links"][0];
        $this->assertEquals("alternate", $first_link["rel"]);
        $this->assertEquals("text/html", $first_link["type"]);
        $this->assertEquals("http://example.org/2005/04/02/atom", $first_link["href"]);
        $second_link = $current_entry["links"][1];
        $this->assertEquals("enclosure", $second_link["rel"]);
        $this->assertEquals("audio/mpeg", $second_link["type"]);
        $this->assertEquals("1337", $second_link["length"]);
        $this->assertEquals("http://example.org/audio/ph34r_my_podcast.mp3", $second_link["href"]);
        $payload = <<<CONTENT
<div xmlns="http://www.w3.org/1999/xhtml">
        <p><i>[Update: The Atom draft is finished.]</i></p>

      </div>
CONTENT;
        $this->assertEquals($payload, $current_entry["content"]);
    }
Beispiel #3
0
 function import_blog($blogID)
 {
     global $importing_blog;
     $importing_blog = $blogID;
     if (isset($_GET['authors'])) {
         return print $this->get_author_form();
     }
     header('Content-Type: text/plain');
     if (isset($_GET['status'])) {
         die($this->get_js_status());
     }
     if (isset($_GET['saveauthors'])) {
         die($this->save_authors());
     }
     $blog = $this->blogs[$blogID];
     $total_results = $this->get_total_results('posts', $blog['host']);
     $this->blogs[$importing_blog]['total_posts'] = $total_results;
     $start_index = $total_results - MAX_RESULTS + 1;
     if (isset($this->blogs[$importing_blog]['posts_start_index'])) {
         $start_index = (int) $this->blogs[$importing_blog]['posts_start_index'];
     } elseif ($total_results > MAX_RESULTS) {
         $start_index = $total_results - MAX_RESULTS + 1;
     } else {
         $start_index = 1;
     }
     // This will be positive until we have finished importing posts
     if ($start_index > 0) {
         // Grab all the posts
         $this->blogs[$importing_blog]['mode'] = 'posts';
         $query = "start-index={$start_index}&max-results=" . MAX_RESULTS;
         do {
             $index = $struct = $entries = array();
             $headers = array("GET /feeds/posts/default?{$query} HTTP/1.0", "Host: {$blog['host']}", "Authorization: AuthSub token=\"{$this->token}\"");
             $request = join("\r\n", $headers) . "\r\n\r\n";
             $sock = $this->_get_blogger_sock($blog['host']);
             if (!$sock) {
                 return;
             }
             // TODO: Error handling
             $response = $this->_txrx($sock, $request);
             $response = $this->parse_response($response);
             // Extract the entries and send for insertion
             preg_match_all('/<entry[^>]*>.*?<\\/entry>/s', $response['body'], $matches);
             if (count($matches[0])) {
                 $entries = array_reverse($matches[0]);
                 foreach ($entries as $entry) {
                     $entry = "<feed>{$entry}</feed>";
                     $AtomParser = new AtomParser();
                     $AtomParser->parse($entry);
                     $result = $this->import_post($AtomParser->entry);
                     if (is_wp_error($result)) {
                         return $result;
                     }
                     unset($AtomParser);
                 }
             } else {
                 break;
             }
             // Get the 'previous' query string which we'll use on the next iteration
             $query = '';
             $links = preg_match_all('/<link([^>]*)>/', $response['body'], $matches);
             if (count($matches[1])) {
                 foreach ($matches[1] as $match) {
                     if (preg_match('/rel=.previous./', $match)) {
                         $query = html_entity_decode(preg_replace('/^.*href=[\'"].*\\?(.+)[\'"].*$/', '$1', $match));
                     }
                 }
             }
             if ($query) {
                 parse_str($query, $q);
                 $this->blogs[$importing_blog]['posts_start_index'] = (int) $q['start-index'];
             } else {
                 $this->blogs[$importing_blog]['posts_start_index'] = 0;
             }
             $this->save_vars();
         } while (!empty($query) && $this->have_time());
     }
     $total_results = $this->get_total_results('comments', $blog['host']);
     $this->blogs[$importing_blog]['total_comments'] = $total_results;
     if (isset($this->blogs[$importing_blog]['comments_start_index'])) {
         $start_index = (int) $this->blogs[$importing_blog]['comments_start_index'];
     } elseif ($total_results > MAX_RESULTS) {
         $start_index = $total_results - MAX_RESULTS + 1;
     } else {
         $start_index = 1;
     }
     if ($start_index > 0) {
         // Grab all the comments
         $this->blogs[$importing_blog]['mode'] = 'comments';
         $query = "start-index={$start_index}&max-results=" . MAX_RESULTS;
         do {
             $index = $struct = $entries = array();
             $headers = array("GET /feeds/comments/default?{$query} HTTP/1.0", "Host: {$blog['host']}", "Authorization: AuthSub token=\"{$this->token}\"");
             $request = join("\r\n", $headers) . "\r\n\r\n";
             $sock = $this->_get_blogger_sock($blog['host']);
             if (!$sock) {
                 return;
             }
             // TODO: Error handling
             $response = $this->_txrx($sock, $request);
             $response = $this->parse_response($response);
             // Extract the comments and send for insertion
             preg_match_all('/<entry[^>]*>.*?<\\/entry>/s', $response['body'], $matches);
             if (count($matches[0])) {
                 $entries = array_reverse($matches[0]);
                 foreach ($entries as $entry) {
                     $entry = "<feed>{$entry}</feed>";
                     $AtomParser = new AtomParser();
                     $AtomParser->parse($entry);
                     $this->import_comment($AtomParser->entry);
                     unset($AtomParser);
                 }
             }
             // Get the 'previous' query string which we'll use on the next iteration
             $query = '';
             $links = preg_match_all('/<link([^>]*)>/', $response['body'], $matches);
             if (count($matches[1])) {
                 foreach ($matches[1] as $match) {
                     if (preg_match('/rel=.previous./', $match)) {
                         $query = html_entity_decode(preg_replace('/^.*href=[\'"].*\\?(.+)[\'"].*$/', '$1', $match));
                     }
                 }
             }
             parse_str($query, $q);
             $this->blogs[$importing_blog]['comments_start_index'] = (int) $q['start-index'];
             $this->save_vars();
         } while (!empty($query) && $this->have_time());
     }
     $this->blogs[$importing_blog]['mode'] = 'authors';
     $this->save_vars();
     if (!$this->blogs[$importing_blog]['posts_done'] && !$this->blogs[$importing_blog]['comments_done']) {
         die('nothing');
     }
     do_action('import_done', 'blogger');
     die('done');
 }
	function put_attachment($postID) {

		// checked for valid content-types (atom+xml)
		// quick check and exit
		$this->get_accepted_content_type($this->atom_content_types);

		$parser = new AtomParser();
		if(!$parser->parse()) {
			$this->bad_request();
		}

		$parsed = $parser->entry;

		// check for not found
		global $entry;
		$this->set_current_entry($postID);
		$this->escape($entry);

		if(!current_user_can('edit_post', $entry['ID']))
			$this->auth_required(__('Sorry, you do not have the right to edit this post.'));

		$publish = (isset($parsed->draft) && trim($parsed->draft) == 'yes') ? false : true;

		extract($entry);

		$post_title = $parsed->title;
		$post_content = $parsed->content;

		$postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt');

		$result = wp_update_post($postdata);

		if (!$result) {
			$this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.'));
		}

		log_app('function',"put_attachment($postID)");
		$this->ok();
	}