[commits] [Wiki] created: Doc/Dev/SharesHowtoH4

Ralf Lang lang at b1-systems.de
Mon Mar 7 20:24:08 UTC 2011


rlang  Mon, 07 Mar 2011 20:24:08 +0000

Created page: http://wiki.horde.org/Doc/Dev/SharesHowtoH4

(wip)
++ How to use horde shares in your custom application ++

Let's assume you followed the  [CreatingYourFirstModule Creating your  
first module] guide as far as it applies to horde4 and created a new  
horde app called "hort". Hort is an old German word for treasure as  
well as the place where the treasure is kept. Hort should keep safes  
which hold user/password pairs or other secret credentials. Those  
safes should be shareable among users. This is where horde_shares  
comes into play.


+++ Application.php _init()

We want to add an injector for the shares API whenever the app is  
initialized and we want to auto-create an initial "home" share for  
users which do not yet own one.

<code>
     protected function _init()
     {
         // Create a share instance.
         $GLOBALS['hort_shares'] =  
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Share')->create();

         /* If the user doesn't own a safe, create one. */
         if (!empty($GLOBALS['conf']['share']['auto_create']) &&
             $GLOBALS['registry']->getAuth() &&
              
!$GLOBALS['hort_shares']->countShares($GLOBALS['registry']->getAuth()))  
{
             $identity =  
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
             $share = $GLOBALS['hort_shares']->newShare(
                 $GLOBALS['registry']->getAuth(),
                 strval(new Horde_Support_Randomid()),
                 sprintf(_("Default safe of %s"), $identity->getName())
             );
             $GLOBALS['hort_shares']->addShare($share);
         }

     }
</code>



Next we want to add a link to the shares administration screen in the menu.
Go to the menu() function in Application.php

<code>

         if (!empty($GLOBALS['hort_shares']) &&  
empty($GLOBALS['conf']['share']['no_sharing'])) {
             $menu->add('#', _("_Permissions"), 'perms.png', null, '',
              
Horde::popupJs(Horde::url($GLOBALS['registry']->get('webroot',  
'horde') . '/services/shares/edit.php', true),
             array('params' => array('app' => 'ingo',
                   'share' => $GLOBALS['session']->get('ingo',  
'backend/id') . ':' . $GLOBALS['registry']->getAuth()),
                   'urlencode' => true)) . 'return false;');
         }

</code>


* add migrations for shares and sharesng driver tables





More information about the commits mailing list