Beispiel #1
1
 function postContent()
 {
     $this->adminGatekeeper();
     $request = $this->getInput('request');
     $key = $this->getInput('key');
     $username = $this->getInput('username');
     $json = $this->getInput('json');
     $follow_redirects = $this->getInput('follow_redirects');
     $method = $this->getInput('method', 'GET');
     $url = \Idno\Core\Idno::site()->config()->getURL();
     if (strripos($url, '/') == strlen($url) - 1) {
         $url = substr($url, 0, strlen($url) - 1);
     }
     $url .= $request;
     $client = new Webservice();
     if ($method == 'POST') {
         $result = $client->post($url, $json, array('X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
     } else {
         $result = $client->get($url, null, array('X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
     }
     $response = Webservice::getLastResponse();
     $sent_request = Webservice::getLastRequest() . $json;
     $api_request = array('request' => $request, 'key' => $key, 'username' => $username, 'json' => $json, 'sent_request' => $sent_request, 'response' => gzencode($response, 9), 'method' => $method);
     \Idno\Core\Idno::site()->session()->set('api_request', $api_request);
     $this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'admin/apitester/');
 }
Beispiel #2
0
 /**
  * If this idno installation has a PubSubHubbub hub, send a publish notification to the hub
  * @param string $url
  * @return array
  */
 static function publish($url)
 {
     if ($hub = \Idno\Core\site()->config()->hub) {
         return \Idno\Core\Webservice::post($hub, ['hub.mode' => 'publish', 'hub.url' => $url]);
     }
     return false;
 }
Beispiel #3
0
 public function getAccessToken($endpointUrl, $grant_type = 'authorization_code', array $parameters)
 {
     if ($parameters['state'] != \Idno\Core\site()->plugins()->get('AppNet')->getState()) {
         throw new \Exception('State value not correct, possible CSRF attempt.');
     }
     unset($parameters['state']);
     $parameters['client_id'] = $this->key;
     $parameters['client_secret'] = $this->secret;
     $parameters['grant_type'] = $grant_type;
     return \Idno\Core\Webservice::post(\IdnoPlugins\AppNet\Main::$TOKEN_ENDPOINT, $parameters);
 }
Beispiel #4
0
 public function testAuthenticated()
 {
     $user = \Tests\KnownTestCase::user();
     $result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'status/edit', ['body' => "Making a nice test post via the api"], ['Accept: application/json', 'X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/status/edit', $user->getAPIkey(), true))]);
     print_r($result);
     $content = json_decode($result['content']);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue(!empty($content));
     $this->assertTrue(!empty($content->location));
     $this->assertTrue($response == 200);
 }
Beispiel #5
0
 public function testUpload()
 {
     $user = \Tests\KnownTestCase::user();
     $result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'photo/edit', ['title' => 'A Photo upload', 'body' => "Uploading a pretty picture via the api", 'photo' => \Idno\Core\WebserviceFile::createFromCurlString("@" . dirname(__FILE__) . "/" . self::$file . ";filename=Photo.jpg;type=image/jpeg")], ['Accept: application/json', 'X-KNOWN-USERNAME: '******'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/photo/edit', $user->getAPIkey(), true))]);
     print_r($result);
     $content = json_decode($result['content']);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue(!empty($content));
     $this->assertTrue(!empty($content->location));
     $this->assertTrue($response == 200);
 }
Beispiel #6
0
 function postContent()
 {
     $this->createGatekeeper();
     // Logged-in only please
     $email = $this->getInput('email');
     $message = $this->getInput('message');
     if (!empty($email) && !empty($message)) {
         $results = Webservice::post('https://withknown.com/vendor-services/feedback/', array('url' => \Idno\Core\Idno::site()->config()->getURL(), 'title' => \Idno\Core\Idno::site()->config()->getTitle(), 'version' => \Idno\Core\Idno::site()->getVersion(), 'public' => \Idno\Core\Idno::site()->config()->isPublicSite(), 'hub' => \Idno\Core\Idno::site()->config()->known_hub, 'email' => $email, 'message' => $message));
         \Idno\Core\Idno::site()->session()->addMessage("Thanks! We received your feedback.");
     }
     $this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'account/settings/feedback/confirm/');
 }
Beispiel #7
0
 function registerEventHooks()
 {
     \Idno\Core\site()->syndication()->registerService('webhooks', function () {
         return $this->hasWebhooks();
     }, array('note', 'bookmark', 'event', 'article'));
     if ($this->hasWebhooks()) {
         if (!empty(\Idno\Core\site()->config()->webhook_syndication)) {
             foreach (\Idno\Core\site()->config()->webhook_syndication as $hook) {
                 \Idno\Core\site()->syndication()->registerServiceAccount('webhooks', $hook['url'], $hook['title']);
             }
         }
         if (\Idno\Core\site()->session()->isLoggedIn()) {
             if (!empty(\Idno\Core\site()->session()->currentUser()->webhook_syndication)) {
                 foreach (\Idno\Core\site()->session()->currentUser()->webhook_syndication as $hook) {
                     \Idno\Core\site()->syndication()->registerServiceAccount('webhooks', $hook['url'], $hook['title']);
                 }
             }
         }
     }
     $hook_function = function (\Idno\Core\Event $event) {
         $eventdata = $event->data();
         if ($this->hasWebhooks()) {
             $object = $eventdata['object'];
             if (!empty($object) && $object instanceof Entity && !empty($eventdata['syndication_account'])) {
                 $payload = array();
                 $hook_url = $eventdata['syndication_account'];
                 if ($owner = $object->getOwner()) {
                     $payload['icon_url'] = $owner->getIcon();
                     $payload['username'] = $owner->getHandle();
                 }
                 $payload['content_type'] = $object->getActivityStreamsObjectType();
                 $payload['text'] = $object->getTitle() . ' <' . $object->getURL() . '>';
                 $payload['title'] = $object->getTitle();
                 $client = new Webservice();
                 $client->post($hook_url, json_encode($payload));
             }
         }
     };
     \Idno\Core\site()->addEventHook('post/note/webhooks', $hook_function);
     \Idno\Core\site()->addEventHook('post/article/webhooks', $hook_function);
     \Idno\Core\site()->addEventHook('post/bookmark/webhooks', $hook_function);
     \Idno\Core\site()->addEventHook('post/event/webhooks', $hook_function);
 }
Beispiel #8
0
 public function getAccessToken($endpointUrl, $grant_type = 'authorization_code', array $parameters)
 {
     if ($parameters['state'] != \Idno\Core\site()->plugins()->get('LinkedIn')->getState()) {
         throw new \Exception('State value not correct, possible CSRF attempt.');
     }
     unset($parameters['state']);
     $parameters['client_id'] = $this->key;
     $parameters['client_secret'] = $this->secret;
     $parameters['grant_type'] = $grant_type;
     /**
      * Note from the original OAuth 2 library:
      * 
      * Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data,
      * while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
      * http://php.net/manual/en/function.curl-setopt.php
      * 
      * ... Linked in API will only accept the latter at this stage.
      */
     $result = \Idno\Core\Webservice::post(\IdnoPlugins\LinkedIn\Main::$TOKEN_ENDPOINT, http_build_query($parameters, null, '&'));
     return json_decode($result['content']);
 }
Beispiel #9
0
 function post()
 {
     // Get parameters
     $code = $this->getInput('code');
     $me = $this->getInput('me');
     $redirect_uri = $this->getInput('redirect_uri');
     $state = $this->getInput('state');
     $client_id = $this->getInput('client_id');
     // Verify code
     $response = Webservice::post('https://indieauth.com/auth', array('me' => $me, 'code' => $code, 'redirect_uri' => $redirect_uri, 'state' => $state, 'client_id' => $client_id));
     if ($response['response'] == 200) {
         parse_str($response['content'], $content);
         if (!empty($content['me']) && (parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\site()->config()->getURL(), PHP_URL_HOST) || 'www.' . parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\site()->config()->getURL(), PHP_URL_HOST))) {
             // Get user & existing tokens
             $user = \Idno\Entities\User::getOne(array('admin' => true));
             $indieauth_tokens = $user->indieauth_tokens;
             if (empty($indieauth_tokens)) {
                 $indieauth_tokens = array();
             }
             // Generate access token and save it to the user
             $token = md5(rand(0, 99999) . time() . $user->getUUID() . $client_id . $state . rand(0, 999999));
             $indieauth_tokens[$token] = array('me' => $me, 'redirect_uri' => $redirect_uri, 'scope' => 'post', 'client_id' => $client_id, 'issued_at' => time(), 'nonce' => mt_rand(1000000, pow(2, 30)));
             $user->indieauth_tokens = $indieauth_tokens;
             $user->save();
             if (\Idno\Core\site()->session()->isLoggedOn() && $user->getUUID() == \Idno\Core\site()->session()->currentUser()->getUUID()) {
                 \Idno\Core\site()->session()->refreshSessionUser($user);
             }
             // Output to the browser
             $this->setResponse(200);
             header('Content-Type: application/x-www-form-urlencoded');
             echo http_build_query(array('access_token' => $token, 'scope' => 'post', 'me' => $me));
             exit;
         } else {
             $this->setResponse(404);
             echo "Client mismatch.";
         }
     }
 }
Beispiel #10
0
 function getContent()
 {
     $user = \Idno\Entities\User::getOne(array('admin' => true));
     // This is for single user sites; will retrieve the main user
     $code = $this->getInput('code');
     if (!empty($code)) {
         $client = new Webservice();
         $response = Webservice::post('http://indieauth.com/auth', array('code' => $code, 'redirect_uri' => \Idno\Core\Idno::site()->config()->getURL(), 'client_id' => \Idno\Core\Idno::site()->config()->getURL()));
         if ($response['response'] == 200) {
             parse_str($response['content'], $content);
             if (!empty($content['me']) && parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\Idno::site()->config()->getURL, PHP_URL_HOST)) {
                 $user = \Idno\Core\Idno::site()->session()->currentUser();
                 $user->indieauth_code = $code;
                 $user->save();
                 \Idno\Core\Idno::site()->session()->logUserOn($user);
             } else {
                 \Idno\Core\Idno::site()->session()->addMessage("Couldn't log you in: the token hostname didn't match.");
             }
         } else {
             \Idno\Core\Idno::site()->session()->addMessage("Uh oh! We got a " . $response['response'] . " response.");
         }
     }
 }
Beispiel #11
0
 /**
  * Makes a call to the hub
  *
  * @param $endpoint
  * @param $contents
  * @param bool $user
  * @return array|bool
  */
 function makeCall($endpoint, $contents, $user = false)
 {
     if (!$user) {
         $user = site()->session()->currentUser();
     }
     if ($user instanceof User) {
         if ($this->userIsRegistered($user)) {
             $web_client = new Webservice();
             $contents = json_encode($contents);
             $time = time();
             $details = $user->hub_settings;
             $results = $web_client->post($this->server . $endpoint, array('content' => $contents, 'time' => $time, 'auth_token' => $details['token'], 'signature' => hash_hmac('sha1', $contents . $time . $details['token'], $details['secret'])));
             return $results;
         }
     }
     return false;
 }
Beispiel #12
0
    function registerEventHooks()
    {
        // Register syndication services
        \Idno\Core\site()->syndication()->registerService('linkedin', function () {
            return $this->hasLinkedIn();
        }, ['note', 'article', 'image']);
        if ($this->hasLinkedIn()) {
            if (is_array(\Idno\Core\site()->session()->currentUser()->linkedin)) {
                foreach (\Idno\Core\site()->session()->currentUser()->linkedin as $id => $details) {
                    if ($id != 'access_token') {
                        \Idno\Core\site()->syndication()->registerServiceAccount('linkedin', $id, $details['name']);
                    } else {
                        \Idno\Core\site()->syndication()->registerServiceAccount('linkedin', $id, 'LinkedIn');
                    }
                }
            }
        }
        // Push "notes" to LinkedIn
        \Idno\Core\site()->addEventHook('post/note/linkedin', function (\Idno\Core\Event $event) {
            $eventdata = $event->data();
            $object = $eventdata['object'];
            if ($this->hasLinkedIn()) {
                if ($linkedinAPI = $this->connect($eventdata['syndication_account'])) {
                    if (!empty(\Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'])) {
                        $name = \Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'];
                    } else {
                        $name = 'LinkedIn';
                    }
                    $message = strip_tags($object->getDescription());
                    //$message .= "\n\n" . $object->getURL();
                    if (!empty($message) && substr($message, 0, 1) != '@') {
                        try {
                            $result = \Idno\Core\Webservice::post(self::$SHARE_URL . '?oauth2_access_token=' . $linkedinAPI->access_token, '
<share>
<comment>' . htmlentities($message) . '</comment>
<visibility> 
<code>anyone</code> 
</visibility>
</share>
', ["Content-Type: application/xml"]);
                            if ($result['response'] == 201) {
                                // Success
                                $link = "";
                                if (preg_match('/<update-url>(.*?)<\\/update-url>/', $result['content'], $matches)) {
                                    $link = $matches[1];
                                }
                                $object->setPosseLink('linkedin', $link, $name);
                                $object->save();
                            } else {
                                if (preg_match('/<message>(.*?)<\\/message>/', $result['content'], $matches)) {
                                    $message = $matches[1];
                                }
                                \Idno\Core\site()->logging->log("LinkedIn Syndication: " . print_r($result, true), LOGLEVEL_ERROR);
                                \Idno\Core\site()->session()->addErrorMessage("Linkedin returned error code: {$result['response']} - {$message}");
                            }
                        } catch (\Exception $e) {
                            \Idno\Core\site()->session()->addErrorMessage('There was a problem posting to LinkedIn: ' . $e->getMessage());
                        }
                    }
                }
            }
        });
        // Push "articles" to LinkedIn
        \Idno\Core\site()->addEventHook('post/article/linkedin', function (\Idno\Core\Event $event) {
            $eventdata = $event->data();
            $object = $eventdata['object'];
            if ($this->hasLinkedIn()) {
                if ($linkedinAPI = $this->connect($eventdata['syndication_account'])) {
                    if (!empty(\Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'])) {
                        $name = \Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'];
                    } else {
                        $name = 'LinkedIn';
                    }
                    $result = \Idno\Core\Webservice::post(self::$SHARE_URL . '?oauth2_access_token=' . $linkedinAPI->access_token, '
<share>
<content>
<title>' . htmlentities(strip_tags($object->getTitle())) . '</title>
<submitted-url>' . htmlentities($object->getUrl()) . '</submitted-url>
</content>
<visibility> 
<code>anyone</code> 
</visibility>
</share>
', ["Content-Type: application/xml"]);
                    if ($result['response'] == 201) {
                        // Success
                        $link = "";
                        if (preg_match('/<update-url>(.*?)<\\/update-url>/', $result['content'], $matches)) {
                            $link = $matches[1];
                        }
                        $object->setPosseLink('linkedin', $link, $name);
                        $object->save();
                    } else {
                        if (preg_match('/<message>(.*?)<\\/message>/', $result['content'], $matches)) {
                            $message = $matches[1];
                        }
                        \Idno\Core\site()->session()->addErrorMessage("Linkedin returned error code: {$result['response']} - {$message}");
                        \Idno\Core\site()->logging->log("LinkedIn Syndication: " . print_r($result, true), LOGLEVEL_ERROR);
                    }
                }
            }
        });
        // Push "images" to LinkedIn
        \Idno\Core\site()->addEventHook('post/image/linkedin', function (\Idno\Core\Event $event) {
            $eventdata = $event->data();
            $object = $eventdata['object'];
            if ($attachments = $object->getAttachments()) {
                foreach ($attachments as $attachment) {
                    if ($this->hasLinkedIn()) {
                        if ($linkedinAPI = $this->connect($eventdata['syndication_account'])) {
                            if (!empty(\Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'])) {
                                $name = \Idno\Core\site()->session()->currentUser()->linkedin[$eventdata['syndication_account']]['name'];
                            } else {
                                $name = 'LinkedIn';
                            }
                            $message = strip_tags($object->getDescription());
                            $message .= "\n\nOriginal: " . $object->getURL();
                            $result = \Idno\Core\Webservice::post(self::$SHARE_URL . '?oauth2_access_token=' . $linkedinAPI->access_token, '
	<share>
	<content>
	<title>' . htmlentities(strip_tags($object->getTitle())) . '</title>
	<description>' . htmlentities($message) . '</description>
	<submitted-url>' . htmlentities($object->getUrl()) . '</submitted-url>
	<submitted-image-url>' . $attachment['url'] . '</submitted-image-url>
	</content>
	<visibility> 
	<code>anyone</code> 
	</visibility>
	</share>
	', ["Content-Type: application/xml"]);
                            if ($result['response'] == 201) {
                                // Success
                                $link = "";
                                if (preg_match('/<update-url>(.*?)<\\/update-url>/', $result['content'], $matches)) {
                                    $link = $matches[1];
                                }
                                $object->setPosseLink('linkedin', $link, $name);
                                $object->save();
                            } else {
                                if (preg_match('/<message>(.*?)<\\/message>/', $result['content'], $matches)) {
                                    $message = $matches[1];
                                }
                                \Idno\Core\site()->session()->addErrorMessage("Linkedin returned error code: {$result['response']} - {$message}");
                                \Idno\Core\site()->logging->log("LinkedIn Syndication: " . print_r($result, true), LOGLEVEL_ERROR);
                            }
                        }
                    }
                }
            }
        });
    }
Beispiel #13
0
 private function doMicropub($syndacct, $object, $params)
 {
     if ($details = $this->getAccountDetails($syndacct)) {
         $headers = ['Authorization: Bearer ' . $details['access_token']];
         Idno::site()->logging()->debug('sending micropub request', ['endpoint' => $details['micropub_endpoint'], 'params' => $params]);
         $resp = Webservice::post($details['micropub_endpoint'], self::filterEmpty($params), $headers);
         $header = $resp['header'];
         $content = $resp['content'];
         $status = $resp['response'];
         $error = $resp['error'];
         // status should be a 200 or a 300
         if ($status >= 200 && $status < 400) {
             if (preg_match('/Location:(.*)/i', $header, $matches)) {
                 $syndurl = trim($matches[1]);
                 $object->setPosseLink('indiesyndicate', $syndurl, $details['name'], $syndurl, $syndacct, ['icon' => $details['icon'], 'style' => $details['style']]);
                 $object->save();
                 Idno::site()->session()->addMessage("Syndicated to <a href=\"{$syndurl}\">{$syndurl}</a>.");
             } else {
                 $msg = "Received {$status} from micropub endpoint but no Location header";
                 Idno::site()->logging()->log($msg, LOGLEVEL_ERROR);
                 Idno::site()->session()->addErrorMessage($msg);
             }
         } else {
             if (empty($error) && !empty($content)) {
                 $error = $content;
             }
             $msg = "Error contacting micropub endpoint ({$status}): {$error}";
             Idno::site()->logging()->error($msg);
             Idno::site()->session()->addErrorMessage($msg);
         }
     } else {
         $msg = "Could not get account details for syndication account {$syndacct}";
         Idno::site()->logging()->error($msg);
         Idno::site()->session()->addErrorMessage($msg);
     }
 }
Beispiel #14
0
 /**
  * Retrieve notices (eg notifications that a new version has been released) from Known HQ
  * @return mixed
  */
 function getVendorMessages()
 {
     if (!empty(site()->config()->noping)) {
         return '';
     }
     $results = Webservice::post('https://withknown.com/vendor-services/messages/', array('url' => site()->config()->getURL(), 'title' => site()->config()->getTitle(), 'version' => site()->getVersion(), 'public' => site()->config()->isPublicSite(), 'phpversion' => phpversion(), 'dbengine' => get_class(site()->db()), 'hub' => site()->config()->known_hub));
     if ($results['response'] == 200) {
         return $results['content'];
     }
 }
Beispiel #15
0
 /**
  * Facebook is silly and needs to have its cache warmed up before you post.
  * @param $url
  */
 function warmFacebookCache($url)
 {
     $client = new Webservice();
     $result = $client->post('https://graph.facebook.com/', ['id' => $url, 'scrape' => 'true']);
     error_log('Facebook cache result: ' . json_encode($result));
 }
Beispiel #16
0
 function registerEventHooks()
 {
     // Register syndication services
     \Idno\Core\site()->syndication()->registerService('appnet', function () {
         return $this->hasAppNet();
     }, ['note', 'article']);
     // Push "notes" to AppNet
     \Idno\Core\site()->addEventHook('post/note/appnet', function (\Idno\Core\Event $event) {
         $object = $event->data()['object'];
         if ($this->hasAppNet()) {
             if ($appnetAPI = $this->connect()) {
                 $appnetAPI->setAccessToken(\Idno\Core\site()->session()->currentUser()->appnet['access_token']);
                 $message = strip_tags($object->getDescription());
                 if (!empty($message) && substr($message, 0, 1) != '@') {
                     try {
                         $entity = new \stdClass();
                         $entity->text = $message;
                         $entity->entities = $this->getEntities($message);
                         $entity->parse_links = true;
                         $result = \Idno\Core\Webservice::post('https://api.app.net/posts?access_token=' . $appnetAPI->access_token, json_encode($entity), ['Content-Type: application/json']);
                         $content = json_decode($result['content']);
                         if ($result['response'] < 400) {
                             // Success
                             $link = $content->data->canonical_url;
                             // We don't have a full posse link here, so we have to link to appnet account
                             $object->setPosseLink('appnet', $link);
                             $object->save();
                         } else {
                             \Idno\Core\site()->logging->log("AppNet Syndication: " . $content->meta->error_message, LOGLEVEL_ERROR);
                             throw new \Exception($content->meta->error_message);
                         }
                     } catch (\Exception $e) {
                         \Idno\Core\site()->session()->addMessage($e->getMessage());
                     }
                 }
             }
         }
     });
     // Push "articles" to AppNet
     \Idno\Core\site()->addEventHook('post/article/appnet', function (\Idno\Core\Event $event) {
         $object = $event->data()['object'];
         if ($this->hasAppNet()) {
             if ($appnetAPI = $this->connect()) {
                 $appnetAPI->setAccessToken(\Idno\Core\site()->session()->currentUser()->appnet['access_token']);
                 try {
                     $status = $object->getTitle();
                     if (strlen($status) > 110) {
                         // Trim status down if required
                         $status = substr($status, 0, 106) . ' ...';
                     }
                     $status .= ': ' . $object->getURL();
                     $attachment_list = [];
                     $cross = new \stdClass();
                     $cross->type = 'net.app.core.crosspost';
                     $cross->value = new \stdClass();
                     $cross->value->canonical_url = $object->getUrl();
                     $attachment_list[] = $cross;
                     $entity = new \stdClass();
                     $entity->text = $status;
                     $entity->entities = $this->getEntities($status);
                     $entity->annotations = $attachment_list;
                     $entity->parse_links = true;
                     $result = \Idno\Core\Webservice::post('https://api.app.net/posts?access_token=' . $appnetAPI->access_token, json_encode($entity), ['Content-Type: application/json']);
                     $content = json_decode($result['content']);
                     if ($result['response'] < 400) {
                         // Success
                         $link = $content->data->canonical_url;
                         // We don't have a full posse link here, so we have to link to appnet account
                         $object->setPosseLink('appnet', $link);
                         $object->save();
                     } else {
                         \Idno\Core\site()->logging->log("AppNet Syndication: " . $content->meta->error_message, LOGLEVEL_ERROR);
                         throw new \Exception($content->meta->error_message);
                     }
                 } catch (\Exception $e) {
                     \Idno\Core\site()->session()->addMessage('There was a problem posting to AppNet: ' . $e->getMessage());
                 }
             }
         }
     });
     // Push "images" to AppNet (NOT IMPLEMENTED YET)
     \Idno\Core\site()->addEventHook('post/image/appnet', function (\Idno\Core\Event $event) {
         $object = $event->data()['object'];
         if ($attachments = $object->getAttachments()) {
             $attachment_list = [];
             foreach ($attachments as $attachment) {
                 $tmp = new \stdClass();
                 $tmp->type = 'net.app.core.oembed';
                 $tmp->value = new \stdClass();
                 $tmp->value->type = 'photo';
                 $tmp->value->version = '1.0';
                 $tmp->value->title = '1.0';
                 $tmp->value->width = $object->width;
                 $tmp->value->height = $object->height;
                 $tmp->value->url = $attachment['url'];
                 if (!empty($object->thumbnail_large)) {
                     $src = $object->thumbnail_large;
                 } else {
                     if (!empty($object->small)) {
                         $src = $object->thumbnail_small;
                     } else {
                         if (!empty($object->thumbnail)) {
                             // Backwards compatibility
                             $src = $object->thumbnail;
                         } else {
                             $src = $attachment['url'];
                         }
                     }
                 }
                 $tmp->value->thumbnail_url = $src;
                 $tmp->value->thumbnail_width = $width;
                 $tmp->value->thumbnail_height = $height;
                 $attachment_list[] = $tmp;
             }
             if ($this->hasAppNet()) {
                 if ($appnetAPI = $this->connect()) {
                     $appnetAPI->setAccessToken(\Idno\Core\site()->session()->currentUser()->appnet['access_token']);
                     try {
                         $status = $object->getTitle();
                         $status .= ': ' . $object->getURL();
                         $entity = new \stdClass();
                         $entity->text = $status;
                         $entity->entities = $this->getEntities($status);
                         $entity->annotations = $attachment_list;
                         $result = \Idno\Core\Webservice::post('https://api.app.net/posts?include_annotations=1&access_token=' . $appnetAPI->access_token, json_encode($entity), ['Content-Type: application/json']);
                         $content = json_decode($result['content']);
                         if ($result['response'] < 400) {
                             // Success
                             $link = $content->data->canonical_url;
                             // We don't have a full posse link here, so we have to link to appnet account
                             $object->setPosseLink('appnet', $link);
                             $object->save();
                         } else {
                             \Idno\Core\site()->logging->log("AppNet Syndication: " . $content->meta->error_message, LOGLEVEL_ERROR);
                             throw new \Exception($content->meta->error_message);
                         }
                     } catch (\Exception $e) {
                         \Idno\Core\site()->session()->addMessage('There was a problem posting to AppNet: ' . $e->getMessage());
                     }
                 }
             }
         }
     });
 }
Beispiel #17
0
 /**
  * If this Known installation has a PubSubHubbub hub, send a publish notification to the hub
  * @param ActivityStreamPost $act_stream_post
  * @return array
  */
 static function publish($act_stream_post)
 {
     if ($hub = \Idno\Core\Idno::site()->config()->hub) {
         if (!$act_stream_post instanceof ActivityStreamPost) {
             return false;
         }
         $object = $act_stream_post->getObject();
         $base = \Idno\Core\Idno::site()->config()->getDisplayURL();
         $feeds = array();
         // Check to make sure there's an entity
         if (!$object instanceof Entity) {
             return false;
         }
         // homepage feed
         $homepage_types = \Idno\Core\Idno::site()->config()->getHomepageContentTypes();
         $type_in_homepage = false;
         if ($object instanceof Entity) {
             if (in_array($object->getContentType(), $homepage_types)) {
                 $type_in_homepage = true;
             }
         }
         if (empty($homepage_types) || $type_in_homepage) {
             $feeds[] = $base;
         }
         // type-specific feeds
         if ($object instanceof Entity) {
             $feeds[] = $base . 'content/' . $object->getContentTypeCategorySlug() . '/';
         }
         $feeds[] = $base . 'content/all/';
         // tag feeds
         foreach ($object->getTags() as $tag) {
             $feeds[] = $base . 'tag/' . $tag;
         }
         if (!empty($feeds)) {
             // encode the feeds and their RSS counterparts
             $encurls = array();
             foreach ($feeds as $feed) {
                 $encurls[] = urlencode($feed);
                 $encurls[] = urlencode(\Idno\Core\Idno::site()->template()->getURLWithVar('_t', 'rss', $feed));
             }
             $formdata = 'hub.mode=publish&hub.url=' . implode(',', $encurls);
             \Idno\Core\Idno::site()->logging()->log('Pinging ' . $hub . ' with data ' . $formdata);
             \Idno\Core\Webservice::post($hub, $formdata, array('Content-Type' => 'application/x-www-form-urlencoded'));
         }
         return true;
     }
     return false;
 }
Beispiel #18
0
 /**
  * Retrieve notices (eg notifications that a new version has been released) from Known HQ
  * @return mixed
  */
 function getVendorMessages()
 {
     if (!empty(site()->config()->noping)) {
         return '';
     }
     $web_client = new Webservice();
     $results = $web_client->post('https://withknown.com/vendor-services/messages/', array('url' => site()->config()->getURL(), 'title' => site()->config()->getTitle(), 'version' => site()->getVersion(), 'public' => site()->config()->isPublicSite(), 'hub' => site()->config()->known_hub));
     if ($results['response'] == 200) {
         return $results['content'];
     }
 }