summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Parecki <aaron@parecki.com>2014-07-06 18:28:18 -0700
committerAaron Parecki <aaron@parecki.com>2014-07-06 18:28:18 -0700
commit592eac5d8dc4c704bfb34915c0703fc2aecc6d46 (patch)
treea9875ed88b33674da0571c0ad8007c01eda07f23 /lib
parentb2337158a38b7dfda6d5c4e3c5f0dd4ae9f4845d (diff)
Adds support for querying your micropub endpoint to check for syndication targets.
This changes the value of "in-reply-to" to use hyphens instead of underscore separators!! Also shows you the full request made to your micropub endpoint.
Diffstat (limited to 'lib')
-rw-r--r--lib/helpers.php71
1 files changed, 69 insertions, 2 deletions
diff --git a/lib/helpers.php b/lib/helpers.php
index 7748c4e..60eda75 100644
--- a/lib/helpers.php
+++ b/lib/helpers.php
@@ -73,20 +73,87 @@ function micropub_post($endpoint, $params, $access_token) {
'Authorization: Bearer ' . $access_token
));
curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array_merge(array(
+ $post = http_build_query(array_merge(array(
'h' => 'entry'
- ), $params)));
+ ), $params));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
+ curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$response = curl_exec($ch);
$error = curl_error($ch);
+ $sent_headers = curl_getinfo($ch, CURLINFO_HEADER_OUT);
+ $request = $sent_headers . $post;
return array(
+ 'request' => $request,
'response' => $response,
'error' => $error,
'curlinfo' => curl_getinfo($ch)
);
}
+function micropub_get($endpoint, $params, $access_token) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $endpoint . '?' . http_build_query($params));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'Authorization: Bearer ' . $access_token
+ ));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ $response = curl_exec($ch);
+ $data = array();
+ if($response) {
+ parse_str($response, $data);
+ }
+ $error = curl_error($ch);
+ return array(
+ 'response' => $response,
+ 'data' => $data,
+ 'error' => $error,
+ 'curlinfo' => curl_getinfo($ch)
+ );
+}
+
+function get_syndication_targets(&$user) {
+ $targets = array();
+
+ $r = micropub_get($user->micropub_endpoint, array('q'=>'syndicate-to'), $user->micropub_access_token);
+ if($r['data'] && array_key_exists('syndicate-to', $r['data'])) {
+ $targetURLs = preg_split('/, ?/', $r['data']['syndicate-to']);
+ foreach($targetURLs as $t) {
+
+ // If the syndication target doesn't have a scheme, add http
+ if(!preg_match('/^http/', $t))
+ $tmp = 'http://' . $t;
+
+ // Parse the target expecting it to be a URL
+ $url = parse_url($tmp);
+
+ // If there's a host, and the host contains a . then we can assume there's a favicon
+ // parse_url will parse strings like http://twitter into an array with a host of twitter, which is not resolvable
+ if(array_key_exists('host', $url) && strpos($url['host'], '.') !== false) {
+ $targets[] = array(
+ 'target' => $t,
+ 'favicon' => 'http://' . $url['host'] . '/favicon.ico'
+ );
+ } else {
+ $targets[] = array(
+ 'target' => $t,
+ 'favicon' => false
+ );
+ }
+ }
+ }
+ if(count($targets)) {
+ $user->syndication_targets = json_encode($targets);
+ $user->save();
+ }
+
+ return array(
+ 'targets' => $targets,
+ 'response' => $r
+ );
+}
+
function static_map($latitude, $longitude, $height=180, $width=700, $zoom=14) {
return 'http://static-maps.pdx.esri.com/img.php?marker[]=lat:' . $latitude . ';lng:' . $longitude . ';icon:small-blue-cutout&basemap=gray&width=' . $width . '&height=' . $height . '&zoom=' . $zoom;
}