Permalink
Browse files

Implemented receiving webmentions for which I added php-mf2 and more …

…RSSB stuff like showing mention type counts.
  • Loading branch information...
sandeepshetty committed Jun 10, 2013
1 parent 705cc0d commit 2141426413658bc9340ab4ca6406c8e3a9ab97c1
Showing with 331 additions and 55 deletions.
  1. +2 −1 composer.json
  2. +152 −20 composer.lock
  3. +22 −0 data.php
  4. +13 −12 helpers.php
  5. +69 −8 index.php
  6. +27 −2 models/posts.php
  7. +24 −1 mysql.md
  8. +17 −8 templates/index.html.php
  9. +4 −2 templates/layout.html.php
  10. +1 −1 templates/link_preview.html.php
View
@@ -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.*"
}
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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();
}
?>
View
@@ -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)
Oops, something went wrong.

0 comments on commit 2141426

Please sign in to comment.