• Home
  • Consultancy
  • Contact
  • Import and Export in Elgg 1.0

    July 31st, 2008 by Marcus Povey

    Perhaps one of the most useful and unique features about Elgg 1.0 is its ability to import and export data. Initially this is accomplished via OpenDD, but we have added hooks which make it very easy to add other formats.

    I’m going to talk a little bit about how this works. Firstly, Export.

    Export works via the views system, and involves creating a brand new view hierarchy for your new format.

    We first need to create a plugin, and in this plugin we create a “views” directory. We need to then create a new directory for your format, and then create a couple of views underneath.

    The image to the left shows the necessary file hierarchy that you need to create – in this instance to export “myformat”.

    Create a directory called “export”. In this directory place the three php files – entity.php, metadata.php and relationship.php – which handle entities, metadata (and annotations) and relationships respectively.

    Each of these files are passed objects via $vars. Depending on which file you are in, this might be $vars['entity'], $vars['metadata'] or $vars['relationship'].

    It is then up to you to encode and output the object according to your format.

    All that remains is to provide the pageshell which handles how the overall page is displayed. This file may set the content-type header or provide wrapping tags (e.g. for XML output).

    pageshell.php is passed $vars['body'] containing the output of your other files.

    Providing a handler to deal with importing data is also fairly simple, and works through the action interface.

    In your plugin’s init function register the action “import/YOURFORMAT”, and point it to your actions/import/myformat.php, e.g.

    <?php
    
    	function myformatplugin_init()
    	{
    		global $CONFIG;
    
    		// Register import action
    		register_action('import/myformat', false,
    		  $CONFIG->pluginspath . "myformatplugin_init/actions/import/myformat.php");
    	}
    
    	// Initialise
    	register_elgg_event_handler('init','system','myformatplugin_init');
    ?>

    This will then register an import action which will be picked up by the administrator import export utility. Your action can access the information it needs to import with the call:

    $data = get_input('data');

    Elgg 1.0 will ship with native support for OpenDD (both import and export) which will allow administrators to migrate between Elgg classic and the new codebase with a minimum amount of effort.

    Elgg 1.0 also offers export views in JSON and PHP native, making it easier to reference the data directly and create mashups.

    Over time we will be adding more import and export functionality, and I hope you will be too!

    Push messaging with OpenDD

    July 26th, 2008 by Marcus Povey

    Federated networks are the future for social networks. Realistically, nobody is going to come along any time soon to challenge the big players like Facebook. But what we can do is allow users to move themselves and their data seamlessly between niche networks, or better yet provide a way of linking up users and data between networks.

    There are technologies around that are all working on bits of the puzzle; OpenID, OAuth etc. I think OpenDD solves a key part of the problem by providing a way to link between and move arbitrary data about in a generic and easily understandable way.

    In my last post I illustrated the syndication usecase for OpenDD; how you can subscribe to a feed for a user and get a list of their activity in the form of a river. One important thing that I forgot to mention of course is there is absolutely no reason why you couldn’t use the same technique to subscribe to and receive updates about any resource.

    Another powerful use case for OpenDD is its use in a live push context, and that is what I’m going to write a bit about today. Now we have already touched on the fact that OpenDD components are all atomic; they do not require a great deal of context or state around them, so for example if you establish a relationship between two entities you do not need to include the complete description of the entities in question – just the relationship.

    In the latest specifications I have introduced the concept of being able to unset and remove things, so as well as creating a relationship it is also possible to remove it. This turns OpenDD into quite a powerful tool in your arsenal.

    If you take Elgg as an example, Elgg has an events system which we have touched on in previous articles and as well as providing a syndication of an events log in the form of a river, we can also look at pushing those events as they happen out to interesting parties as a sequence of OpenDD components.

    So, for example, you could request to be notified when a user joins a group or when something changes on a file (or indeed any other resource) and this can then be pushed out to you in a way that is simple to understand – and again, because we have the concept of an UUID, it isn’t necessary to have the complete context in order for the message to be useful. Everything else can be worked out.

    So, using OpenDD, it is now possible to subscribe to users and resources on different networks and receive a feed of updates, but it is also now possible to push messages between networks in an open way that is understood by both platforms.

    One of the cool things you can do with that is for example Sharing. In one network you could create a resource, for example a photo of you at a party or a URL you were interested in. Then you could select between the friends on the network you are in but also from friends elsewhere to share the resource with.

    The user on the foreign network would then receive an OpenDD push update message saying that you have created a resource and have shared it with them (or rather the platform would receive and interpret it), and because users and the resource are all addressed by UUID the user would be able to see this seamlessly on their own network.

    Syndicating friends activity using OpenDD

    July 21st, 2008 by Marcus Povey

    You are probably all aware of the concept of the River in terms of social networking platforms; being able to see what your friends have been up to as a list of events – what they have been doing, who they have made their friend etc.

    This feature – made popular by the facebook “mini-feed” – has become one of the things that users expect from any platform they use and is rather compelling.

    What if you want to see what they have been doing on other networks? Would it not be a pretty neat thing to be able to subscribe to their activity in order to receive updates about what they have been up to in a similar way as you would be able to subscribe to their blog via RSS?

    This turns out to be a simple yet powerful use case for OpenDD, and this is how we’re doing it in the new version of Elgg.

    I talked a bit about how the river was implemented in Elgg 1.0 in previous articles. In a nutshell we have a system log which stores events as they happen in terms of a simple relationship, e.g. “User X CREATED BlogPost”, “User X UPDATED profile”, etc.

    Once you have that information it becomes very easy to mine that for extra information and turn it into a River event. Essentially, a plugin would create a view on the specific event and entity and then be able to render it as a river item and provide new views on existing data.

    If you remember, I also talked about how I changed the river code to use this thing called ElggRiverStatement, which lets you construct the river in a much more linguistic way and also provides all the information needed by the river views.

    Creating a “Friends activity elsewhere” syndication view becomes quite easy. Essentially, all you need to do is export the system log for a user, which you can do very easily using OpenDD as a sequence of OpenDD Relationships. This is because “User X CREATED BlogPost” can be thought of in terms of a relationship.

    Once this is done, an aggregation client can retrieve the feeds of all the friends that you’ve signed up to and then sort the relationships by published data, and then – because everything has a UUID – you can then drill down and pull the extra information required – details about the user who initiated the action, the object the event was performed on, metadata etc.

    This essentially means you can construct a succession of ElggRiverStatement objects out of an OpenDD feed. This is quite cool, because it means you can take those objects and inject them into the already existing river views and get a river entry back. This means that for absolutely zero extra work, every plugin has the ability to render a “Friend elsewhere” event… and it becomes seamless!

    Additionally, you can look to digging further and getting extra information about the entities involved and actually be able to see the entity in question – whether by linking to the entity elsewhere or using the information you have about it to render it locally.

    This is quite a simple example, but it shows some of the power of OpenDD. Additionally, I should point out that since OpenDD is atomic, you don’t ever have to get all the information in one go!

    Changes to the river code

    July 18th, 2008 by Marcus Povey

    The latest Elgg 1.0 code changes how the river works slightly from that discussed in my previous article on the subject. These changes are entirely under the hood so they’ll only be noticeable to plugin writers, however it simplifies matters immeasurably and makes it possible to do some quite funky things.

    In a nutshell, the river generation function now passes a variable called "statement" to your river views instead of passing the object, event etc as separate values. "statement" is a class called ElggRiverStatement.

    Loosely speaking all river items are in the form of “X does something to Y”, where X is usually a user and Y is either an entity or another statement. I borrowed a bit from linguistics, and X is called the Subject and Y is the Object.

    Subject, as I said, is the user, so this is easy. The ElggRiverStatement will provide you with a fully created user entity.

    The statement “does something to” translates to the event in the system which you will be used to if you’ve implemented plugins for Elgg 1.0 already… so that’s “create”, “update”, etc.

    Object will either by an ElggEntity in the case of simple statements like “User X updated their Profile”, or an array which represents compound statements.

    What do I mean by compound statements? Well, take the following for example:

    “User X is now friends with User Y”

    As far as the system is concerned, what you are actually saying is:

    “User X created a new friend relationship between User X and User Y”

    In terms of language, User X is the Subject and “a new friend relationship between User X and User Y” (yes, the whole thing) is the Object (and yes, before someone jumps in I am aware this is highly simplified!).

    I use the terms Subject and Object again in the array, so to take the above example our array would look something like this:

    Array (
        "subject" => User X (ElggUser object),
        "relationship" => "friend",
        "object" => User Y (ElggUser object again)
    )

    If you take the example of adding some metadata (writing a note on a file for example), you’ve got another compound query. You are making the statement:

    “User X has created some metadata which relates to File Y”

    In this instance “some metadata which relates to File Y” is our Object, and the array returned would look something like this:

    Array (
        "subject" => Metadata object,
        "object" => File Y
    )

    In summary then, the ElggRiverStatement provides a pretty flexible way of representing diverse river statements with a common interface. The entities referenced are provided in full to your view so that you do not have to load them yourself.

    Although this is a small change under the hood it makes it possible to do some other cool stuff (which I will discuss a little bit later).

    Elgg 1.0 almost ready!

    July 7th, 2008 by Marcus Povey

    It has been an exciting (not to mention very busy) few weeks, and we are now entering the final approach towards the release of Elgg 1.0.

    We have had some very positive initial response from our beta tester group, and from the screenshots that Dave posted the other day.

    Elgg 1.0 features some rather advanced features such as the much improved object model which I’ve blogged about before (also see Ben’s post) as well as native support for OpenDD.

    A lot of work has been done to make development for the new platform a breeze; with a view system separating code and logic, widgets and streams virtually for free, and many more functions in core that take much of the strain.

    As well as all the work done under the hood, Pete has done great work in making the new version graphically pleasing. There has been a big focus on the UI experience which everyone so far has said is a big improvement over Elgg Classic.

    Watch this space for more!

    All content is © Copyright Marcus Povey 2008-2010 and released under a Creative Commons licence unless otherwise stated.

    Creative Commons License