Fork me on GitHub
» Making the world a better place, one byte at a time…

Elgg 1.0 gatekeeper functions

May 29th, 2008 by Marcus Povey

This is just a quick post to introduce a pair of functions I wrote today while working on some of the Elgg 1.0 access control code.

Namely, call_gatekeeper($function, $file = "") and callpath_gatekeeper($path, $include_subdirs = true), both of which return a boolean value.

call_gatekeeper()

This function tests to see whether it has the given method/function (optionally also test that it is defined in a specified file) exists on the call stack.

The function will return true if the called by the named function (or its parent was called by the named function).

Here is an example of its usage:

function my_secure_function()
{
if (!call_gatekeeper("my_call_function"))
return false;
... do secure stuff ...
}

function my_call_function()
{
// will work
my_secure_function();
}

function bad_function()
{
// Will not work
my_secure_function();
}

To specify a method instead of a function, pass an array to $function containing the classname and method name.

callpath_gatekeeper()

This function is similar to call_gatekeeper() but returns true if it is being called by a method or function which has been defined on a given path or by a specified file.

The function accepts two parameters:

$path, which is either the full path of the desired file or a partial path. If a partial path is given and $include_subdirs is true, then the function will return true if called by any function in or below the specified path.

OpenDD over Atom

May 20th, 2008 by Marcus Povey

One of the often repeated comments that people have had regarding OpenDD was that we should do a version of it embedded in Atom 1.

I would therefore like to introduce the first draft of OpenDD over Atom, submitted for discussion.

In a nutshell, OpenDD over Atom makes use of Atom’s ability to embed other formats within the content tag and simply wraps a OpenDD element within an Atom entry with some additional data from the ODD element used in the Atom “envelope”

This seemed like the simplest solution, but let me know what you think!

OpenDD PHP library

May 9th, 2008 by Marcus Povey

I have just uploaded a PHP library for importing and exporting OpenDD documents. It is version 0.1 so it is still very much under development, but it should still be usable.

Import example

The import function accepts an OpenDD XML document and returns an ODDDocument object, which can then be iterated through to obtain access to the ODD* classes.

The XML file:

<odd version="1.0" generated="Fri, 09 May 2008 18:53:37 +0100">
<entity uuid="http://www.example.com/a" class="foo" subclass="http://www.example.com/b" />
<metadata uuid="http://www.example.com/c" entity_uuid="http://www.example.com/a" name="Squid" >paper</metadata>
<relationship uuid1="http://www.example.com/a" type="hates" uuid2="http://www.example.com/b" />
</odd>

Example code to process it:

$doc = ODD_Import($in);

foreach ($doc as $element)
print_r($element); // Just echo, but you should probably do something meaningful.

Export example

Export involves constructing an ODDDocument object and populating it with various classes, each one representing one of the OpenDD elements.

This object is then serialised.

Here is some example code:

$out = new ODDDocument(); // Create new document

$entity = new ODDEntity("http://www.example.com/a", "foo", "http://www.example.com/b");
$out->addElement($entity);

$meta = new ODDMetaData("http://www.example.com/c", "http://www.example.com/a", "Squid", "paper");
$out->addElement($meta);

$rel = new ODDRelationship("http://www.example.com/a", "hates", "http://www.example.com/b");
$out->addElement($rel);

echo ODD_Export($out); // Export

When I get a chance I’ll upload some libraries in other languages, but if you feel inclined then feel free to implement your own!

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