Inheritance: extends Horde_Feed_Entry_Base
Exemplo n.º 1
0
 public function __set($var, $value)
 {
     switch ($var) {
         case 'myUpdated':
             // Translate myUpdated to myns:updated.
             return parent::__set('myns:updated', $value);
     }
     return parent::__set($var, $value);
 }
Exemplo n.º 2
0
 /**
  * Push content to the recipient.
  *
  * @param Horde_Push $content The content element.
  * @param array      $options Additional options.
  *
  * @return NULL
  */
 public function push(Horde_Push $content, $options = array())
 {
     $entry = new Horde_Feed_Entry_Atom(null, $this->_client);
     $types = $content->getMimeTypes();
     if (isset($types['text/html'])) {
         $body = $content->getStringContent($types['text/html'][0]);
     } else {
         if (isset($types['text/plain'])) {
             $body = $content->getStringContent($types['text/plain'][0]);
         } else {
             $body = '';
         }
     }
     /* Give the entry its initial values. */
     $entry->{'atom:title'} = $content->getSummary();
     $entry->{'atom:title'}['type'] = 'text';
     $entry->{'atom:content'} = $body;
     $entry->{'atom:content'}['type'] = 'text';
     if (!empty($options['pretend'])) {
         return sprintf("Would push \n\n%s\n\n to %s.", (string) $entry, $this->_params['url']);
     }
     /* Authenticate. */
     $response = $this->_client->post('https://www.google.com/accounts/ClientLogin', 'accountType=GOOGLE&service=blogger&source=horde-push&Email=' . $this->_params['username'] . '&Passwd=' . $this->_params['password'], array('Content-type', 'application/x-www-form-urlencoded'));
     if ($response->code !== 200) {
         throw new Horde_Push_Exception('Expected response code 200, got ' . $response->code);
     }
     $auth = null;
     foreach (explode("\n", $response->getBody()) as $line) {
         $param = explode('=', $line);
         if ($param[0] == 'Auth') {
             $auth = $param[1];
         }
     }
     if (empty($auth)) {
         throw new Horde_Push_Exception('Missing authentication token in the response!');
     }
     /* Do the initial post. */
     try {
         $entry->save($this->_params['url'], array('Authorization' => 'GoogleLogin auth=' . $auth));
         $reference = $entry->link('alternate');
         if (!empty($reference)) {
             $content->addReference($reference);
         }
     } catch (Horde_Exception $e) {
         throw new Horde_Push_Exception($e);
     }
     return sprintf('Pushed blog entry to %s.', $this->_params['url']);
 }
Exemplo n.º 3
0
 public function testEdit()
 {
     $mock = new Horde_Http_Request_Mock();
     $mock->setResponse(new Horde_Http_Response_Mock('', fopen(__DIR__ . '/fixtures/AtomPublishingTest-updated-entry.xml', 'r'), array('HTTP/1.1 200')));
     $httpClient = new Horde_Http_Client(array('request' => $mock));
     // The base feed URI is the same as the POST URI, so just supply the
     // Horde_Feed_Entry_Atom object with that.
     $contents = file_get_contents(__DIR__ . '/fixtures/AtomPublishingTest-before-update.xml');
     $entry = new Horde_Feed_Entry_Atom($contents, $httpClient);
     // Initial state.
     $this->assertEquals('2005-05-23T16:26:00-08:00', $entry->updated(), 'Initial state of updated timestamp does not match');
     $this->assertEquals('http://example.com/Feed/1/1/', $entry->link('edit'), 'Initial state of edit link does not match');
     // Just change the entry's properties directly.
     $entry->content = '1.2';
     // Then save the changes.
     $entry->save();
     // New state.
     $this->assertEquals('1.2', $entry->content(), 'Content change did not stick');
     $this->assertEquals('2005-05-23T16:27:00-08:00', $entry->updated(), 'New updated link is not correct');
     $this->assertEquals('http://example.com/Feed/1/2/', $entry->link('edit'), 'New edit link is not correct');
 }
Exemplo n.º 4
0
} catch (Horde_Feed_Exception $e) {
    die('An error occurred authenticating: ' . $e->getMessage() . "\n");
}
$auth = null;
foreach (explode("\n", $response->getBody()) as $line) {
    $param = explode('=', $line);
    if ($param[0] == 'Auth') {
        $auth = $param[1];
    }
}
if (empty($auth)) {
    throw new Horde_Feed_Exception('Missing authentication token in the response!');
}
/* The base feed URI is the same as the POST URI, so just supply the
 * Horde_Feed_Entry_Atom object with that. */
$entry = new Horde_Feed_Entry_Atom();
/* Give the entry its initial values. */
$entry->{'atom:title'} = 'Entry 1';
$entry->{'atom:title'}['type'] = 'text';
$entry->{'atom:content'} = '1.1';
$entry->{'atom:content'}['type'] = 'text';
/* Do the initial post. */
try {
    $entry->save($blogUri, array('Authorization' => 'GoogleLogin auth=' . $auth));
} catch (Horde_Feed_Exception $e) {
    die('An error occurred posting: ' . $e->getMessage() . "\n");
}
/* $entry will be filled in with any elements returned by the
 * server (id, updated, link rel="edit", etc). */
echo "new id is: {$entry->id()}\n";
echo "entry last updated at: {$entry->updated()}\n";