Plugins and Events


Plugin Cookbook

Contents

General Plugin Architecture

Erfurt or Onto Wiki Plugin?

Plugin Configuration

Overwrite Onto Wiki Strings / Add Plugin Strings

Simply put a strings.ini file in your plugin directory. The plugin manager will include that to the main strings data.


This is a sample strings.ini:

[english]
; this overwrites the title of the login box
auth.login.login = My own Login String
; this adds a new string to the strings object
myspecialplugin.info = This is my special plugin ...

[german : english]
auth.login.login = My eigener Login String
myspecialplugin.info = Dies ist mein spezielles Plugin ...

[default : english]


Simple Plugin Class

Access to Session Interna / Request Data / ...

all

Access to the Plugin Root Dir (Filesystem)

// e.g. /var/www/ontowiki/plugins/ExamplePlugin (without last slash)
$this->_getPluginRootDir();

Access to the Plugin Base URI

// e.g. http://localhost/ontowiki/plugins/ExamplePlugin
$this->_getPluginBaseUri();

Access to the Onto Wiki Base URI

// e.g. http://localhost/ontowiki
$this->_getOntoWikiBaseUri();

Access to the active resource / resource list

Addtional CSS / Java Scripts

Sidebar

Adding a special main window to the sidebar

PKM

Hiding an existing main window

Ontobuilder

Creating a completely new sidebar


Softwiki

Different Forms / Views

Adding my own Edit-Form for a specific resource-type

Softwiki, Ontobuilder

Adding my own Create-Form for a specific resource-type

Ontobuilder

public function niceForms (&$a) {
        if (isset($this->_view->properties['rdf:type']) && $this->_view->properties['rdf:type'] == 'http://purl.net/net/sempkm/Note') {
            #$this->_view->properties['dc:relation']='';
            $vr = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
            $this->_view->addScriptPath($this->_getPluginRootDir().'/templates/');
            $vr->setScriptAction('edit-notes');
        }
        return;
    }

<?php $this->placeholder('tabs')->set($this->tabs?>
<?php $this
->placeholder('title')->set($this->title?>
<?php $this
->placeholder('menu')->set($this->menu?>
<?php $this
->placeholder('statusTools')->set($this->statusTools?>
<!-- ... -->
<form method="post" action="<?php echo $this->actionUrl ?>" class="no-min-width">
    <!-- ... -->
    <fieldset><legend>Querverbindungen</legend>
        <div class="row-input">
            <label>Notiz verbunden mit:</label><br/>
            <?php echo OntoWiki_Util::editValues($this->type'dc:relation'?>
        </div>
    </fieldset>
</form>
<!-- ... -->

Adding my own List-View for a specific resource-type

Softwiki, Ontobuilder

Tabs

Hiding an existing Tab (e.g. Map / Calendar)

Ontobuilder (modified: resourcecontroller.php/getTabNavigation)

Adding a new Tab


public function changeTabs(&$tabs) {
    $action = 'ttt'; // define your action here
    $baseURI = 
    
    $tabs['tabs][$baseUri . 'exampleController/tttAction'] = 'New Tab Label'; 

}

Flashviz

Inner Windows

Creating my own inner window in a given view

PKM, Socializr

Menus

Adding an item to windows main menu (e.g. Extras)

DL-Learner, Socializr

Adding an item to a windows context menu

Adding an item to a class context menu

Controller

Adding a new controller


public function addNewController() {

    // get front controller
    $frontController = Zend_Controller_Front::getInstance();

    // get request object 
    $request = $frontController->getRequest();

    // add the plug-in dir as a controller dir
    $frontController->addControllerDirectory($this->_getPluginRootDir());

    // set dispatched to false so that default OntoWiki action will not be dispatched
    $request->setDispatched(false);

    // set the controller to softwiki
    $request->setControllerName('example');

    // set the action to view
    $request->setActionName('view');
}

class ExampleController extends OntoWiki_Controller_Action {

    /**
      * SoftWiki view action.
      * Overwrites the default OntoWiki view action and renders its own templates.
      */
    public function viewAction() {
        // set window title
        $this->view->placeholder('title')->set('Example Main Window');

        // ...
    }
}


DL-Learner, Flashviz?

Replacing a existing controller

Adding a new action to existing controller

Flashviz

Data Manipulation

How to create a new knowledge base template

Onto Builder (modified: modelcontroller.php/createaction, templates/model/create.php (new file))

Write Erfurt Plugins

It is also possible to write plugins for the Erfurt Semantic Web Framework. A Erfurt plugin is useful in case your Erfurt based application needs to do some additional things when data is manipulated through Erfurt. A good example for a usecase of such a plugin is cache invalidating when adding or removing statements or logging of the same.


The following example will give you a brief overview of the steps you will have to through in order to build such a plugin.


  1. First of all you have to decide, which events your plugin should handle. Have a look at the Event section of the EventPluginArchitecture page in order to get a up-to-date list of triggered events. Our example plugin will announce to the RDFSModel_add_pre and RDFSModel_add_post events. These Erfurt core events are triggered in the add-method of the RDFSModel-class. The first one is triggered before a statement is added and the second one after the addition of a statements to the model. When a plugin announces to one of these events, it gets a reference to the data, which actually is an array containing a key statement with the statement as payload. The RDFSModel_add_post event has a additional key success, which indicates whether the addition was successful or failed.
  2. Open the plugins/ folder, which is located under your Erfurt/ directory (Have a look at the PluginCookbook#h??? section to learn about setting up custom plugin directories.).
  3. Create a new folder with the name of your plugin. In our case this will be Erfurt Example Plugin.
  4. Create a new file called Erfurt Example Plugin.ini-dist. This file will contain the followin lines:
    [general]
    
    name = "Erfurt Example Plugin"
    description = "This is a example Erfurt plugin. It will do some example stuff when a statements is added."
    author = "Philipp Frischmuth"
    url = "http://ontowiki.net"
    
    switch = "on"; is plugin active? on|off
    
    folder.0 = "."
    
    announce.0.event = "RDFSModel_add_pre"
    announce.0.class = "ErfurtExamplePlugin"
    announce.0.method = "preAddAction"
    
    announce.1.event = "RDFSModel_add_post"
    announce.1.class = "ErfurtExamplePlugin"
    announce.1.method = "postAddAction"
    • The first section contains some metadata about the plugin, like author and description.
    • The switch directive is very important. It tells the plugin manager, whether the plugin is active or not
    • The folder directive announces the folders, which are needed by the plugin. This is in our case only the root of the plugin dir 
    • The last section is very important, too. Here you announce your plugin to one or more events and tell the plugin manager, which class(es) and method(s) to use.
  5. Now we have to implement the plugin. Therefor we need to create a file called Erfurt Example Plugin.php, which contains our preAddAction and postAddAction methods, that we defined in the configuration file.
    <?php
    class ErfurtExamplePlugin extends Erfurt_Plugin {

        public function 
    preAddAction(&$data) {
            
            
    // do some stuff before adding a statement
            
            // e.g.:
            // 1. check whether predicate is rdfs:label
            // 2a: false -> do nothing
            // 2b: true -> check whether object has a language
            // 3a: true -> do nothing
            // 3b: false -> add a standard language tag... e.g. 'de'
            
            
    $stm $data['statement'];
            if (
    $stm->getPredicate()->getURI() === EF_RDFS_LABEL) {
                
    $obj $stm->getObject();
                
                if (
    $obj->getLanguage() === null) {
                    
    $obj->setLanguage('de');
                }
            }
            
            return;
        }
        
        public function 
    postAddAction(&$data) {
            
            
    // do some stuff after adding a statement
            
            // e.g. log statement serialization and success status
            
    $stm $data['statement'];
            
    $success $data['success'];
            
            
    $logger Zend_Registry::get('erfurtLog')->info('ErfurtExamplePlugin - Statement added (' 
                            
    date('d.m.Y H:i:s') . '): ' $stm->toString() . 
                            (
    $success ' successfully added' ' addition failed'));
        }
    }
    ?>
  6. We are done. If we want to use our plugin, we need to copy the Erfurt Example Plugin.ini-dist file to Erfurt Example Plugin.ini. That's all, no our plugin should work as we expect.

Integration of new API components


Socializr, Flashviz


 
There are no files on this page. [Display files/form]
There is no comment on this page. [Display comments/form]

Information

Last Modification: 2008-07-22 19:26:14 by Michael Haschke