Skip to content

Commit

Permalink
Diaspora profile, and receiving basic messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBojda committed Dec 11, 2011
1 parent 7e18210 commit 84b0cc5
Show file tree
Hide file tree
Showing 13 changed files with 1,020 additions and 0 deletions.
39 changes: 39 additions & 0 deletions diasporainwp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/*
Plugin Name: Diaspora in Wordpress
Plugin URI: http://wordpress.org/extend/plugins/diasporainwp/
Description: Diaspora Pod implementation for Wordpress
Author: Laszlo Fazekas
Author URI: http://lf.estontorise.com
Version: 1.0
Text Domain: diasporainwp
License: GPL
*/

define("DIASPORAINWP_VERSION", "0.1");

$dh = opendir(WP_PLUGIN_DIR . '/diasporainwp/modules');
while (false !== ($file = readdir($dh))) {
if(strpos($file, '.') === 0)
continue;
if(file_exists(WP_PLUGIN_DIR . "/diasporainwp/modules/$file/plugin.php"))
{
include(WP_PLUGIN_DIR . "/diasporainwp/modules/$file/plugin.php");
}
else if(file_exists(WP_PLUGIN_DIR . "/diasporainwp/modules/$file/$file.php"))
{
include(WP_PLUGIN_DIR . "/diasporainwp/modules/$file/$file.php");
}
}
closedir($dh);

register_activation_hook( __FILE__, 'activation_hook' );

function activation_hook() {
//if( get_option("diasporainwp_version") != DIASPORAINWP_VERSION) {
do_action("diasporainwp_activation_hook");
update_option("diasporainwp_version", DIASPORAINWP_VERSION);
//}
}

?>
177 changes: 177 additions & 0 deletions modules/activitystream-extension/activitystream-extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/*
Plugin Name: ActivityStream extension
Plugin URI: http://wordpress.org/extend/plugins/activitystream-extension/
Description: An extensions which adds the ActivityStream (<a href="http://www.activitystrea.ms">activitystrea.ms</a>) syntax to your Atom-Feed
Author: Matthias Pfefferle
Version: 0.8
Author URI: http://notizblog.org
*/

add_action('atom_ns', array('ActivityExtension', 'addActivityNamespace'));
add_action('atom_entry', array('ActivityExtension', 'addActivityObject'));
add_action('atom_author', array('ActivityExtension', 'addActivityAuthor')); // run before output
add_action('comment_atom_ns', array('ActivityExtension', 'addActivityNamespace'));
add_action('comment_atom_entry', array('ActivityExtension', 'addCommentActivityObject'));
add_action('wp_head', array('ActivityExtension', 'addHtmlHeader'), 5);
add_filter('query_vars', array('ActivityExtension', 'queryVars'));

// add 'json' as feed
add_action('do_feed_json', array('ActivityExtension', 'doFeedJson'));
add_action('init', array('ActivityExtension', 'init'));

// push json feed
//add_filter('pshb_feed_urls', array('ActivityExtension', 'publishToHub'));

register_activation_hook(__FILE__, array('ActivityExtension', 'flushRewriteRules'));
register_deactivation_hook(__FILE__, array('ActivityExtension', 'flushRewriteRules'));



/**
* ActivityStream Extension
*
* @author Matthias Pfefferle
*/
class ActivityExtension {
/**
* init function
*/
function init() {
add_feed('json', array('ActivityExtension', 'doFeedJson'));
}

/**
* reset rewrite rules
*/
function flushRewriteRules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}

/**
* echos the activitystream namespace
*/
function addActivityNamespace() {
echo 'xmlns:activity="http://activitystrea.ms/spec/1.0/"'." \n";
echo 'xmlns:media="http://purl.org/syndication/atommedia"'." \n";
echo 'xmlns:poco="http://portablecontacts.net/spec/1.0"'." \n";
}

/**
* echos autodiscovery links
*/
function addHtmlHeader() {
echo '<link rel="activities" type="application/atom+xml" href="'.get_bloginfo('atom_url').'" />'."\n";
echo '<link rel="alternate activities" type="application/activitystream+json" href="'.get_feed_link('json').'" />'."\n";
}

/**
* echos the activity verb and object for the wordpress entries
*/
function addActivityObject() {
switch (get_post_type()) {
case "aside":
case "status":
case "quote":
case "note":
$post_type = "note";
break;
default:
$post_type = "article";
break;
}
?>

<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<activity:object>
<activity:object-type>http://activitystrea.ms/schema/1.0/<?php echo $post_type; ?></activity:object-type>
<id><?php the_guid(); ?></id>
<title type="<?php html_type_rss(); ?>"><![CDATA[<?php the_title(); ?>]]></title>
<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary>
<link rel="alternate" type="text/html" href="<?php the_permalink_rss() ?>" />
</activity:object>
<?php
}

/**
* echos the activity verb and object for the wordpress comments
*/
function addCommentActivityObject() {
?>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<activity:object>
<activity:object-type>http://activitystrea.ms/schema/1.0/comment</activity:object-type>
<id><?php comment_guid(); ?></id>
<content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php comment_text(); ?>]]></content>
<link rel="alternate" href="<?php comment_link(); ?>" type="<?php bloginfo_rss('html_type'); ?>" />
<thr:in-reply-to ref="<?php the_guid() ?>" href="<?php the_permalink_rss() ?>" type="<?php bloginfo_rss('html_type'); ?>" />
</activity:object>
<activity:target>
<activity:object-type>http://activitystrea.ms/schema/1.0/article</activity:object-type>
<id><?php the_guid(); ?></id>
<title type="<?php html_type_rss(); ?>"><![CDATA[<?php the_title(); ?>]]></title>
<summary type="<?php html_type_rss(); ?>"><![CDATA[<?php the_excerpt_rss(); ?>]]></summary>
<link rel="alternate" type="text/html" href="<?php the_permalink_rss() ?>" />
</activity:target>
<?php
}

/**
* adds a json feed
*/
function doFeedJson() {
// load template
load_template(dirname(__FILE__) . '/feed-json.php');
}

/**
* Add 'callback' as a valid query variables.
*
* @param array $vars
* @return array
*/
function queryVars($vars) {
$vars[] = 'callback';
$vars[] = 'feed';

return $vars;
}

/**
* adds the json feed to PubsubHubBub
*
* @param array $feeds
* @return array
*/
function publishToHub($feeds) {
$feeds[] = get_feed_link('json');
return $feeds;
}

function addActivityAuthor() {
if (is_author()) {
if(get_query_var('author_name')) :
$user = get_user_by('slug', get_query_var('author_name'));
else :
$user = get_userdata(get_query_var('author'));
endif;

$gravatar = "http://www.gravatar.com/avatar/".md5(strtolower($user->user_email));

$author = "<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>\n";
$author .= "<link rel='alternate' type='text/html' href='" . get_author_posts_url($user->ID, $user->user_nicename) . "' />\n";
$author .= "<link rel='avatar' type='image/jpeg' media:width='300' media:height='300' href='$gravatar?s=300' />\n";
$author .= "<link rel='avatar' type='image/jpeg' media:width='96' media:height='96' href='$gravatar?s=96'/>\n";
$author .= "<link rel='avatar' type='image/jpeg' media:width='48' media:height='48' href='$gravatar?s=48'/>\n";
$author .= "<link rel='avatar' type='image/jpeg' media:width='24' media:height='24' href='$gravatar?s=24'/>\n";
$author .= "<poco:preferredUsername>".$user->user_nicename."</poco:preferredUsername>\n";
$author .= "<poco:displayName>".$user->display_name."</poco:displayName>\n";
if ($description = $user->user_description) {
$author .= "<poco:note><![CDATA[$description]]></poco:note>\n";
}

echo $author;
}
}
}
65 changes: 65 additions & 0 deletions modules/activitystream-extension/feed-json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* json template
*/
$output = array();
while (have_posts()) {
the_post();

switch (get_post_type()) {
case "aside":
case "status":
case "quote":
case "note":
$post_type = "note";
break;
default:
$post_type = "article";
break;
}

$temp = array('published' => get_post_modified_time('Y-m-d\TH:i:s\Z', true),
'verb' => 'post',
'target' => array('id' => get_feed_link('json'),
'url' => get_feed_link('json'),
'objectType' => 'blog',
'displayName' => get_bloginfo('name')
),
'object' => array('id' => get_the_guid(),
'displayName' => get_the_title(),
'objectType' => $post_type,
'summary' => get_the_excerpt(),
'url' => get_permalink()
),
'actor' => array('id' => get_author_posts_url(get_the_author_meta('id'), get_the_author_meta('nicename')),
'displayName' => get_the_author(),
'objectType' => 'person',
'url' => get_author_posts_url(get_the_author_meta('id'), get_the_author_meta('nicename')),
'image' => array('width' => 80,
'height' => 80,
'url' => 'http://www.gravatar.com/avatar/'.md5( get_the_author_meta('email') ).'.jpg')
)
);

if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
$image = wp_get_attachment_image_src(get_post_thumbnail_id());
$temp['object']['image']['url'] = $image[0];
$temp['object']['image']['width'] = $image[1];
$temp['object']['image']['height'] = $image[2];
}

$output['items'][] = $temp;
}

// add your own data
$output = apply_filters('activitystream_json', $output);

header('Content-Type: application/json; charset=' . get_option('blog_charset'), true);

// check callback param
if ($callback = get_query_var('callback')) {
echo $callback.'('.json_encode($output).');';
} else {
echo json_encode($output);
}
?>
93 changes: 93 additions & 0 deletions modules/activitystream-extension/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
=== ActivityStream extension ===
Contributors: pfefferle
Donate link: http://notizblog.org
Tags: Activities, Activity Stream, Feed, RSS, Atom, OStatus, OStatus Stack, JSON
Requires at least: 3.2
Tested up to: 3.2.1
Stable tag: 0.8

ActivityStrea.ms syntax for WordPress (Atom and JSON)

== Description ==

An extensions which ActivityStream ([activitystrea.ms](http://www.activitystrea.ms)) support to your WordPress-blog

Atom Example:

` <entry>
<id>http://notizblog.org/?p=1775</id>
<author>
<name>Matthias Pfefferle</name>
<uri>http://notizblog.org</uri>
</author>
.
.
.
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>

<activity:object>
<activity:object-type>http://activitystrea.ms/schema/1.0/article</activity:object-type>
<id>tag:notizblog.org,2009-07-13:/post/1775</id>
<title type="html"><![CDATA[Matthias Pfefferle posted a new blog-entry]]></title>
<link rel="alternate" type="text/html" href="http://notizblog.org/2009/07/14/webstandards-kolumne/" />
</activity:object>
</entry>`

JSON Example:

`{
items: [{
published: "2011-01-30T21:34:48Z",
verb: "post",
target: {
id: http://notizblog.org/feed/json,
url: http://notizblog.org/feed/json,
objectType: "blog",
displayName: "notizBlog"
},
object: {
id: http://notizblog.org/?p=322
displayName: "wsn?",
objectType: "article",
summary: "wasn?",
url: http://notizblog.org/?p=322
},
.
.
.
}]
}`

== Installation ==

* Upload the whole folder to your `wp-content/plugins` folder
* Activate it at the admin interface

Thats it

== Changelog ==

= 0.8 =
* some JSON changes to match spec 1.0
* changed the HTML discovery-links
* added post_thumbnail support

= 0.7.1 =
* updated to new JSON-Activity changes

= 0.7 =
* deprecated `<activity:subject>`
* enriched Atom `<author />`

= 0.6 =
* added json feed
* pubsubhubbub for json

= 0.5 =
* some OStatus compatibility fixes
* added `<activity:subject>`
* added `<activity:target>`

= 0.3 =
* Fixed a namespace bug
* Added autodiscovery link
Loading

0 comments on commit 84b0cc5

Please sign in to comment.