Sharing

Summary

Data catchers are part of the [sharing in Novius OS](http://novius-os.github.com/docs/applications.html#sharing).

Novius OS is a CMS built around data. One of its main roles is to allow the data to flow between applications and in/out of the the OS.

Standardised data types are defined, such as name, URL and image. They are called shared data. Each application indicates the data it releases. The blog application, for instance, provides a name, an URL, an image and a text for every blog post.

Some applications are able to make use of the shared data thanks to their data catchers. These components watch the shared data and interact with the pieces they’re able to exploit (e.g. the Twitter application will only need a name and a URL to tweet). Some data catchers require a user action whereas others operate automatically.

Content nuggets: made of shared data

Taxonomy (standardised data type which are part of a content nugget)

  • Title
  • URL
  • Text
  • Image

Nos\Orm_Behaviour_Sharable (creating content nuggets)

Shared data are defined using the Sharable Behaviour on a Model.

The data configuration from the Sharable behaviour defines how the default data are generated for the item.

Examples

1. Use a column value as default data
<?php
array(
        \Nos\DataCatcher::TYPE_TITLE => array(
                'value' => 'monk_name',
        ),
);
2. Use a callback function to compute the default value
<?php
array(
        \Nos\DataCatcher::TYPE_TITLE => array(
                'value' => function($monkey) {
                        return $monkey->monk_name;
                },
        ),
);
3. Real-world example (found in the Monkey sample application)
<?php

class Model_Monkey extends \Nos\Orm\Model
{
        protected static $_behaviours = array(
                'Nos\Orm_Behaviour_Sharable' => array(
                        'data' => array(
                                \Nos\DataCatcher::TYPE_TITLE => array(
                                        'value' => 'monk_name',
                                        'useTitle' => __('Use monkey name'),
                                ),
                                \Nos\DataCatcher::TYPE_URL => array(
                                        'value' => function($monkey) {
                                                $urls = $monkey->urls();
                                                if (empty($urls)) {
                                                        return null;
                                                }
                                                reset($urls);

                                                return key($urls);
                                        },
                                        'options' => function($monkey) {
                                                return $monkey->urls();
                                        },
                                ),
                                \Nos\DataCatcher::TYPE_TEXT => array(
                                        'value' => function($monkey) {
                                                return $monkey->monk_summary;
                                        },
                                        'useTitle' => __('Use monkey summary'),
                                ),
                                \Nos\DataCatcher::TYPE_IMAGE => array(
                                        'value' => function($monkey) {
                                                $possible = $monkey->possible_medias();

                                                return Arr::get(array_keys($possible), 0, null);
                                        },
                                        'possibles' => function($monkey) {
                                                return $monkey->possible_medias();
                                        },
                                ),
                        ),
                ),
        );
}

Some data types, like url or image have additional parameters.

options is used to give a list of all possible values that can be used by the shared data.

For example, if multiple URL are available for a given item, the user will be able to choose which URL he wants to use when sharing the item.

Data catchers (use content nuggets)

Data catchers are components which use content nuggets generated by the models.

Data catchers are defined by applications in the metadata.config.php file, the same way as templates, enhancers and launchers.

Included data catchers

Requires user action

  • Twitter
  • Facebook
  • Blog

The Blog data catcher can be used to create new blog posts from other items, such as monkeys (see bootstrap application) or books (this application does not exists, it’s just an example).

Operate automatically

  • RSS item
  • RSS channel

The RSS data catchers operate automatically, but they won’t be available for all models, as they require some extra configuration on a per-model & per-enhancer basis. This first draft of the documentation won’t cover this functionality.

How the Twitter data catcher is defined

<?php
return array(
        'data_catchers' => array(
                'noviusos_twitter_intent' => array(
                        'title' => 'Twitter',
                        'description'  => '',
                        'iconUrl' => 'static/apps/noviusos_twitter/img/twitter.png',
                        // Which action is triggered when the user click on the button
                        // Replacements are made using the shared data (content nugget)
                        'action' => array(
                                'action' => 'window.open',
                                'url' => 'https://twitter.com/intent/tweet?text={{'.\Nos\DataCatcher::TYPE_TITLE.'}}&url={{'.\Nos\DataCatcher::TYPE_URL.'}}',
                        ),
                        'onDemand' => true, // Requires user action
                        'specified_models' => false, // Apply on every model (with the sharable behaviour)
                        'required_data' => array(
                                \Nos\DataCatcher::TYPE_TITLE,
                        ),
                        'optional_data' => array(
                                \Nos\DataCatcher::TYPE_URL,
                        ),
                ),
        ),
);

So the Twitter data catcher only requires the content nugget to have a title. The URL is optional (but will be used if provided).

Read the Docs v: 0.1
Versions
latest
chiba.2
chiba.1
0.2
0.1
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.