function hubbub2_loadurl($url) { $content = HubbubEndpoint::request($url); $html = trim($content['body']); $entity = array(); // case 1, this is a json array if (substr($html, 0, 1) == '{') { $entity = json_decode($html); } else { if (stristr($html, '<!-- hubbub2:{') != '') { CutSegment('<!-- hubbub2:{', $html); $seg = '{' . trim(CutSegment('-->', $html)); $entity = json_decode($seg, true); } } return $entity; }
/** * sends the current message to a server URL * @param string $url * @return */ function sendToUrl($url, $forceKey = null) { if (trim($url) == '') { logError('', 'Message[' . $this->type . ']::sendToUrl(empty)'); return array('result' => 'fail', 'reason' => 'Server URL cannot be empty'); } $this->sanitizeDataset(); $this->toServer = new HubbubServer($url, true); if (!$this->toServer->isTrusted() && !strStartsWith($this->type, 'trust')) { $r = $this->toServer->msg_trust_sendkey1(); if ($r['result'] != 'OK') { return $r; } else { return array('result' => 'fail', 'reason' => 'waiting for server key'); } } $this->executeHandler('before_sendtourl', array('url' => $url)); $this->payload = json_encode($this->data); if ($this->toServer->outboundKey() != '' || $forceKey != null) { $this->signForServer($this->toServer, $forceKey); } $result = HubbubEndpoint::request($url, array('hubbub_msg' => $this->payload, 'hubbub_sig' => $this->signature)); $this->responseData = $result['data']; $this->executeHandler('after_sendtourl', array('url' => $url, 'result' => $result)); h2_audit_log('msg/send', array('to' => array($url), 'text' => $this->data['text'], 'result' => $result['result']), $this->data['msgid']); return $result['data']; }