osaris/hoablog — pull request #6 by Hywan (2013-01-30 23:12:06+00:00)
Title: Allow XYL in post content

Hi,

This is a proposal to allow XYL to be interpreted in a post content.

You need to be up-to-date with `Hoa\Core`, `Hoa\Stream` and `Hoa\StringBuffer`. This [patch (1)](https://github.com/hoaproject/Core/commit/b15995714ce74505b8c0b3aecbb64bcf06c1127b) on `Hoa\Core\Protocol` allows complex ID (e.g. `hoa://Foo/Bar#comp/lex/id`). This [patch (2)](https://github.com/hoaproject/Stream/commit/67f6cf8a812b10112667d2a87316305095ca209a), added earlier today (and not with this PR in mind, funny aye?), allows to get stream meta data. This [patch (3)](https://github.com/hoaproject/Stream/commit/ba7a7b1e29c7dfaa7c80707ec32b5b029fdb2f46) allows to retrieve any objects (handlers) by using the `resolve('hoa://Library/Stream#')` operation; please see the commit message for more informations. Finally, [this patch (4)](https://github.com/hoaproject/StringBuffer/commit/9852f3a2c0c62c70b5e625cb5b19af7f73790a05) exploits previous patches by resolving URI such as `hoa://Library/StringBuffer#` as a filename, because `Hoa\StringBuffer` uses temporary files as backends (in the same time, the streamname of `Hoa\StringBuffer` objects has been simplify, please see [patch (5)](https://github.com/hoaproject/StringBuffer/commit/87a0d250c7236ea2d856845ebb40e61a58b476d9)).

Patch (4) is quite clever (yes, we are the best). Look, I explain:

$sb = new Hoa\StringBuffer\Read();
$sb->initializeWith('foobar');
var_dump($sb->getStreamName());

Here, we start a stringbuffer and initialize it. The result of the dump would probably look like `hoa://Library/StringBuffer#0`. The ID is `0`, it means the first stringbuffer (it is a way to distinguish from each other). If we resolve this URI:

var_dump(resolve($sb->getStreamName());

The method `reachId` in `Hoa\StringBuffer\_Protocol` introduced in patch (4) will be executed with `0` as value of the `$id` argument. Then, we will retrieve the object (because we don't have any multiton structure around `Hoa\StringBuffer`… except in `Hoa\Stream::$_register`! look patch (3)). If the object is null, it means it has been closed or something else, just return null. Else, we get the stream meta data and ask the `uri` index to get the temporary filename used by the stringbuffer `0`.

Thus, when we create a stringbuffer and uses its streamname (with `getStreamName()`) in a `@href` attribute of a ``, it will be resolved automatically (by `Hoa\Core\Protocol\Wrapper` to be self-explained) into the temporary filename used by the stringbuffer. This is soo *modular* and (not so surprisingly) *very fast*. It is also not hacky any more for the end-user. Thoughts?

I have disabled validation in the model for the moment. Please, accept these modifications, I will restore them later (very soon).

We also need to check that XYL will not throw any errors before saving the post content in the database. Same when reading from the database/showing the post content (if the XYL fragment used links from the router that have been removed for example).