Copyright 2011-2016 Horde LLC (http://www.horde.org/)
See the enclosed file COPYING for license information (LGPL). If you did not
receive this file, see http://www.horde.org/licenses/lgpl21.
public function testTwitterPretend() { $push = new Horde_Push(); $stub = new Horde_Push_Stub_Twitter(); $result = $push->addRecipient(new Horde_Push_Recipient_Twitter($stub))->setSummary('TWEET')->push(array('pretend' => true)); $this->assertEquals(array('Would push tweet "TWEET" to twitter.'), $result); }
/** * 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()) { $this->pushed[] = $content; if (empty($options['pretend'])) { return sprintf('Pushed "%s".', $content->getSummary()); } else { return sprintf('Would push "%s".', $content->getSummary()); } }
/** * Push content to the recipient. * * @param Horde_Push $content The content element. * @param array $options Additional options. * * @return string The result description. */ public function push(Horde_Push $content, $options = array()) { $text = $content->getSummary(); if (empty($options['pretend'])) { $options = array(); $acl = $this->getAcl(); if (!empty($acl)) { $options['privacy'] = $acl; } $this->_facebook->streams->post('me', $text, $options); return 'Pushed to facebook stream.'; } else { return sprintf('Would push "%s" to the facebook stream.', $text); } }
/** * 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']); }
/** * Push content to the recipient. * * @param Horde_Push $content The content element. * @param array $options Additional options. * * @return string The result description. */ public function push(Horde_Push $content, $options = array()) { $tweet = $content->getSummary(); if ($content->hasReferences() && strlen($tweet) < 116 && class_exists('Horde_Service_UrlShortener_Base') && $this->_client !== null) { $shortener = new Horde_Service_UrlShortener_TinyUrl($this->_client); foreach ($content->getReferences() as $reference) { $tweet .= ' ' . $shortener->shorten($reference); if (strlen($tweet) > 115) { break; } } } if ($content->hasTags()) { foreach ($content->getTags() as $tag) { if (strlen($tweet) + strlen($tag) < 139) { $tweet .= ' #' . $tag; } } } if (empty($options['pretend'])) { $this->_twitter->statuses->update($tweet); return 'Pushed tweet to twitter.'; } else { return sprintf('Would push tweet "%s" to twitter.', $tweet); } }
/** * 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()) { $contents = $content->getContent(); $types = $content->getMimeTypes(); $mail = new Horde_Mime_Mail(); // @todo Append references if (isset($types['text/plain'])) { $mail->setBody($content->getStringContent($types['text/plain'][0])); unset($contents[$types['text/plain'][0]]); } if (isset($types['text/html'])) { $mail->setHtmlBody($content->getStringContent($types['text/html'][0]), 'UTF-8', !isset($types['text/plain'])); unset($contents[$types['text/html'][0]]); } foreach ($contents as $part) { $mail->addPart($part['mime_type'], $part['content'], 'UTF-8'); } $mail->addRecipients(explode(',', $this->getAcl())); $mail->addHeader('subject', $content->getSummary()); if (!empty($this->_params['from'])) { $mail->addHeader('from', $this->_params['from']); } $mail->addHeader('to', $this->getAcl()); if (!empty($options['pretend'])) { $mock = new Horde_Mail_Transport_Mock(); $mail->send($mock); return sprintf("Would push mail \n\n%s\n\n%s\n to %s.", $mock->sentMessages[0]['header_text'], $mock->sentMessages[0]['body'], $this->getAcl()); } $mail->send($this->_mail); return sprintf('Pushed mail to %s.', $this->getAcl()); }
public function testPretend() { $push = new Horde_Push(); $mx = new Horde_Mail_Transport_Mock(); $recipient = new Horde_Push_Recipient_Mail($mx, array('from' => '*****@*****.**')); $recipient->setAcl('*****@*****.**'); $return = $push->addRecipient($recipient)->setSummary('E-MAIL')->push(array('pretend' => true)); $this->assertContains('Would push mail', $return[0]); }
/** * @expectedException Horde_Push_Exception */ public function testBadResponse() { $push = new Horde_Push(); $request = new Horde_Http_Request_Mock(); $request->addResponse('Auth=X'); $request->addResponse('', 201); $client = new Horde_Http_Client(array('request' => $request)); $result = $push->addRecipient(new Horde_Push_Recipient_Blogger($client, array('url' => 'http://blogger.com', 'username' => 'test', 'password' => 'pass')))->setSummary('BLOG')->push(); }
public function testPretend() { $push = new Horde_Push(); $mock = new Horde_Push_Recipient_Mock(); $result = $push->addRecipient($mock)->setSummary('Test')->push(array('pretend' => true)); $this->assertEquals(array('Would push "Test".'), $result); }
public function testToConfiguredHeader() { $factory = new Horde_Push_Factory_Recipients(); $recipients = $factory->create(array(), array('recipients' => array('mail-me'), 'recipient' => array('mail-me' => array('type' => 'mail', 'acl' => '*****@*****.**', 'mailer' => array('type' => 'mock', 'from' => '*****@*****.**'))))); $push = new Horde_Push(); $push->setSummary('E-MAIL'); foreach ($recipients as $recipient) { $push->addRecipient($recipient); } $result = $push->push(array('pretend' => true)); $this->assertContains('to: recipient@example.com', $result[0]); }
/** * 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; }