Nothing Special   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
Implemented receiving webmentions for which I added php-mf2 and more …
Browse files Browse the repository at this point in the history
…RSSB stuff like showing mention type counts.
  • Loading branch information
sandeepshetty committed Jun 10, 2013
1 parent 705cc0d commit 2141426
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 55 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"phpish/template": "dev-master",
"phpish/mysql": "dev-master",
"phpish/http": "dev-master",
"michelf/php-markdown": "1.3.*@dev"
"michelf/php-markdown": "1.3.*@dev",
"mf2/mf2": "0.1.*"
}
}
172 changes: 152 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions data.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,31 @@ function db_delete_post_channels($post_id, $channels_to_delete)
return mysql\query("DELETE FROM channels WHERE post_id = %d and name in ('".implode("','", $channels_to_delete)."')", array($post_id));
}

//TODO: Do an upsert here; add only if it doesn't exist.
function db_add_post_channel($post_id, $channel_name, $now, $is_private)
{
return mysql\query("INSERT INTO channels (name, post_id, created_at, private) VALUES ('%s', %d, '%s', %d)", array($channel_name, $post_id, $now, $is_private));
}


function db_add_webmention($post_id, $source, $source_hash, $target, $target_hash, $now, $type, $content)
{
return mysql\query("INSERT INTO webmentions (post_id, source, source_hash, target, target_hash, created_at, updated_at, type, content) VALUES ('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE updated_at = '%s', content = '%s'", array($post_id, $source, $source_hash, $target, $target_hash, $now, $now, $type, $content, $now, $content));
}

function db_get_webmentions($post_id, $type)
{
return mysql\rows("SELECT source FROM webmentions where post_id = %d and type = '%s' ORDER BY created_at", array($post_id, $type));
}

function db_get_webmention_type_counts($post_id)
{
return mysql\rows('SELECT type, count(type) as count FROM webmentions where post_id = %d GROUP BY type', array($post_id));
}


function db_error()
{
return mysql\error();
}
?>
25 changes: 13 additions & 12 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@

function send_webmention($source, $target)
{
$response_headers = $matches = array();
$target_webmention_endpoint = false;
if ($target_webmention_endpoint = discover_webmention_endpoint($target))
{
$response_body = http\request("POST $target_webmention_endpoint", array(), array('source'=>$source, 'target'=>$target), $response_headers);
print_r(compact('source', 'target', 'target_webmention_endpoint', 'response_headers', 'response_body'));
}


}

function discover_webmention_endpoint($target)
{
$response_body = http\request("GET $target", array(), array(), $response_headers);
if (isset($response_headers['link']) and preg_match('#<(https?://[^>]+)>; rel="http://webmention.org/"#', $response_headers['link'], $matches))
{
$target_webmention_endpoint = $matches[1];
return $matches[1];
}
elseif (preg_match('#<link href="([^"]+)" rel="http://webmention.org/" ?/?>#i', $response_body, $matches) or preg_match('#<link rel="http://webmention.org/" href="([^"]+)" ?/?>#i', $response_body, $matches))
{
$target_webmention_endpoint = $matches[1];
}

if ($target_webmention_endpoint)
{
$response_body = http\request("POST $target_webmention_endpoint", array(), array('source'=>$source, 'target'=>$target), $response_headers);
print_r($response_headers);
print_r($response_body);
return $matches[1];
}

}

function gravatar_url($email, $s=80, $d='mm', $r='g', $img=false)
Expand Down
Loading

0 comments on commit 2141426

Please sign in to comment.