Add a URL reference for this element.
public addReference ( string $reference ) : Horde_Push | ||
$reference | string | The link. |
return | Horde_Push | This content element. |
/** * 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']); }
/** * Generate a Horde_Push element based on the provided data. * * @param array $data The data to be pushed. * * @return Horde_Push The element to be pushed. */ private function _createFromData($data) { if (!isset($data['summary'])) { throw new Horde_Push_Exception('Data is lacking a summary element!'); } $push = new Horde_Push(); $push->setSummary($data['summary']); if (isset($data['body'])) { if (htmlspecialchars($data['body']) != $data['body']) { $push->addContent($data['body'], 'text/html'); } else { $push->addContent($data['body']); } } if (isset($data['tags'])) { foreach ($data['tags'] as $tag) { $push->addTag($tag); } } if (isset($data['references'])) { foreach ($data['references'] as $reference) { $push->addReference($reference); } } return $push; }