123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- class Salmon
- {
- const REL_SALMON = 'salmon';
- const REL_MENTIONED = 'mentioned';
-
- const NS_REPLIES = "http://salmon-protocol.org/ns/salmon-replies";
- const NS_MENTIONS = "http://salmon-protocol.org/ns/salmon-mention";
-
- public static function post($endpoint_uri, $xml, User $user)
- {
- if (empty($endpoint_uri)) {
- common_debug('No endpoint URI for Salmon post to '.$user->getUri());
- return false;
- }
- try {
- $magic_env = MagicEnvelope::signAsUser($xml, $user);
- $envxml = $magic_env->toXML();
- } catch (Exception $e) {
- common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage());
- return false;
- }
- $headers = array('Content-Type: application/magic-envelope+xml');
- try {
- $client = new HTTPClient();
- $client->setBody($envxml);
- $response = $client->post($endpoint_uri, $headers);
- } catch (HTTP_Request2_Exception $e) {
- common_log(LOG_ERR, "Salmon post to $endpoint_uri failed: " . $e->getMessage());
- return false;
- }
- if ($response->getStatus() != 200) {
- common_log(LOG_ERR, sprintf('Salmon (from profile %d) endpoint %s returned status %s: %s',
- $user->id, $endpoint_uri, $response->getStatus(), $response->getBody()));
- return false;
- }
-
- return true;
- }
- }
|