[Cartoweb-users] MyFirst Plugin

Yves Jacolin yjacolin at free.fr
Sun Aug 12 12:57:38 EDT 2007


Le dimanche 12 août 2007 18:45, Milo van der Linden a écrit :
> Hello list,
>
> I am trying to write a simple, static plugin that displays a dropdownbox
> on the cartoweb GUI, for now it doesn't have to do anything. I just want
> to check if I am capable of taking the first steps in writing plugins.
>
> I did the following:
>
> I created the required directories:
>
> <myProject>/plugins/myplugin
> <myProject>/plugins/myplugin/client
> <myProject>/plugins/myplugin/templates
>
> in client I created a file Clientmyplugin.php
> in templates I created a file myplugin.tpl
>
> In the myplugin.tpl I have the following code:
>
> <div id="mypluginSelect">
> <SELECT NAME="myplugin_select">
> <OPTION VALUE="">
> <OPTION VALUE="1"> Project 1
> <OPTION VALUE="2"> Project 2
> <OPTION VALUE="3"> Project 3
> </SELECT>
> </div>
>
> As you can see, it is very static.
>
> In Clientmyplugin.php I have the following code:
>
> class Clientmyplugin extends ClientPlugin
> implements Sessionable, GuiProvider
> {
>
>     /* here comes your plugin client class definition */
>
> }
>
>
> In the client.ini.in; I added myplugin to the loadplugins= line
>
> In my customized cartoclient.php I added
>
> {if $myplugin_active|default:''}
>    {$myplugin}
>    {/if}
>
> As you can see, I just want cartoclient to load the dropdown when it
> starts up.
>
> Problems I run in to:
>
> - Setting the activation parameter for a plugin in cartoclient.php is
> not documented
> - A simple method in the client to parse the template to cartoclient.php
> is not documented
>
> Is there anybody that can help me with these simple steps?
Hi,

First of all, I think you mean cartoclient.tpl instead of cartoclient.php ;)

A simple methode to parse the template could be something like : 
   /**
    * @see GuiProvider::renderForm()
    */
    public function renderForm(Smarty $template) {
        // authentification
        $editRoles = $this->getArrayFromIni('general.allowedRoles', true);
        $allowed = SecurityManager::getInstance()->hasRole($editRoles);
        $smarty = new Smarty_Plugin($this->getCartoclient(), $this);
        $smarty->assign(array('manager_allowed' => $allowed,
                        'layersManagerMessage' => $this->Message));
        $template->assign('layersManager', 
$smarty->fetch('layersManager.tpl'));
    }
/************************************
'layersManager' was the name of the plugin where I took this function.
'manager_allowed' and 'layersManagerMessage' are two variable you can send to 
the template file via smarty function  (assign function first define some 
variable you can use into the template file then it assign variable to the 
template file)

You will need this function :
    /**
     * Returns an array from a comma-separated list of a ini parameter.
     * @param string name of ini parameter
     * @param boolean (default: false) true: returns a simplified array
     * @return array
     */
    protected function getArrayFromIni($name, $simple = false) {
        $data = $this->getConfig()->$name;
        if (!$data) return array();

        return $this->getArrayFromList($data, $simple);
    }

Which allow you to get parameter from your myPlugin.ini file (don't seem you 
need it yet ;) 

Hope this will help you. You can drop an eye to the cw3 plugins to get some 
information. If you read the french, you can drop an eye as well to the 
cartoweb-community?net, documentation chapter, I begin to write something 
about developing a plugin ionto cw3.

Finally, I don't understand this :
>- Setting the activation parameter for a plugin in cartoclient.php is
> not documented

Regards,

Y.
-- 
Yves Jacolin
-------------
http://yjacolin.gloobe.org
http://softlibre.gloobe.org



More information about the Cartoweb-users mailing list