\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{Horde\_Shares}
Some performance charts with the sql driver:

\includegraphics{http://chart.apis.google.com/chart?chxl=0:|pdo\_sqlite|pdo\_pgsql|pdo\_mysql|mysqli|mysql\&chxp=0,4,3,2,1,0\&chxr=0,0,4\&chxt=x\&chs=440x220\&cht=lxy\&chco=008000,FF9900,AA0033,3072F3\&chd=s:\_,NPNpH,\_,PPPQH,\_,OOQuJ,\_,BBBBB\&chdl=Share+creation+(Sql)|listShares()+(Sql)|Share+creation+(Sqlng)|listShares()+(Sqlng)\&chdlp=b\&chls=1|1|1|1\&chma=15,15,5,25|0,10\&chtt=Horde\_Share+performance+(less+is+better)}

Note: the sqlite driver was test with an in-memory database

\section{How to use horde shares in your custom application}
\textit{work in progress}

Let's assume you followed the  <a href="https://wiki.horde.org/CreatingYourFirstModule">Creating your first module</a> 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.

\subsection{basic setup in 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.

<pre><code class="language-php">
    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></pre>
\subsection{List of safes in Application.php menu()}
Next we want to add a page with a list of safes (shares) in the menu.<br />
Go to the menu() function in Application.php

<pre><code class="language-php">
        \$menu->add(Horde::url('safes.php'), \_("Password Safes"), 'user.png');
</code></pre>
\subsection{migrations script (database setup) for shares and sharesng driver tables}
Create a directory hort/migrations/ with a file 1\_hort\_tables.php

<pre><code class="language-php">
class HortBaseTables extends Horde\_Db\_Migration\_Base
\{
    /**
     * Upgrade.
     */
    public function up()
    \{
        \$tableList = \$this->tables();


        \$t = \$this->createTable('hort\_sharesng', array('primaryKey' => 'share\_id'));
        \$t->column('share\_name', 'string', array('limit' => 255, 'null' => false));
        \$t->column('share\_owner', 'string', array('limit' => 255));
        \$t->column('share\_flags', 'integer', array('default' => 0, 'null' => false));
        \$t->column('perm\_creator\_' . Horde\_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_creator\_' . Horde\_Perms::READ, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_creator\_' . Horde\_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_creator\_' . Horde\_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_default\_' . Horde\_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_default\_' . Horde\_Perms::READ, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_default\_' . Horde\_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_default\_' . Horde\_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_guest\_' . Horde\_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_guest\_' . Horde\_Perms::READ, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_guest\_' . Horde\_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_guest\_' . Horde\_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
        \$t->column('attribute\_name', 'string', array('limit' => 255, 'null' => false));
        \$t->column('attribute\_desc', 'string', array('limit' => 255));
        \$t->column('attribute\_params', 'text');
        \$t->column('share\_parents','text');
        \$t->end();

        \$this->addIndex('hort\_sharesng', array('share\_name'));
        \$this->addIndex('hort\_sharesng', array('share\_owner'));
        \$this->addIndex('hort\_sharesng', array('perm\_creator\_' . Horde\_Perms::SHOW));
        \$this->addIndex('hort\_sharesng', array('perm\_creator\_' . Horde\_Perms::READ));
        \$this->addIndex('hort\_sharesng', array('perm\_creator\_' . Horde\_Perms::EDIT));
        \$this->addIndex('hort\_sharesng', array('perm\_creator\_' . Horde\_Perms::DELETE));
        \$this->addIndex('hort\_sharesng', array('perm\_default\_' . Horde\_Perms::SHOW));
        \$this->addIndex('hort\_sharesng', array('perm\_default\_' . Horde\_Perms::READ));
        \$this->addIndex('hort\_sharesng', array('perm\_default\_' . Horde\_Perms::EDIT));
        \$this->addIndex('hort\_sharesng', array('perm\_default\_' . Horde\_Perms::DELETE));
        \$this->addIndex('hort\_sharesng', array('perm\_guest\_' . Horde\_Perms::SHOW));
        \$this->addIndex('hort\_sharesng', array('perm\_guest\_' . Horde\_Perms::READ));
        \$this->addIndex('hort\_sharesng', array('perm\_guest\_' . Horde\_Perms::EDIT));
        \$this->addIndex('hort\_sharesng', array('perm\_guest\_' . Horde\_Perms::DELETE));

        \$t = \$this->createTable('hort\_sharesng\_groups', array('primaryKey' => false));
        \$t->column('share\_id', 'integer', array('null' => false));
        \$t->column('group\_uid', 'string', array('limit' => 255, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::READ, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
        \$t->end();

        \$this->addIndex('hort\_sharesng\_groups', array('share\_id'));
        \$this->addIndex('hort\_sharesng\_groups', array('group\_uid'));
        \$this->addIndex('hort\_sharesng\_groups', array('perm\_' . Horde\_Perms::SHOW));
        \$this->addIndex('hort\_sharesng\_groups', array('perm\_' . Horde\_Perms::READ));
        \$this->addIndex('hort\_sharesng\_groups', array('perm\_' . Horde\_Perms::EDIT));
        \$this->addIndex('hort\_sharesng\_groups', array('perm\_' . Horde\_Perms::DELETE));

        \$t = \$this->createTable('hort\_sharesng\_users', array('primaryKey' => false));
        \$t->column('share\_id', 'integer', array('null' => false));
        \$t->column('user\_uid', 'string', array('limit' => 255, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::READ, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
        \$t->column('perm\_' . Horde\_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
        \$t->end();

        \$this->addIndex('hort\_sharesng\_users', array('share\_id'));
        \$this->addIndex('hort\_sharesng\_users', array('user\_uid'));
        \$this->addIndex('hort\_sharesng\_users', array('perm\_' . Horde\_Perms::SHOW));
        \$this->addIndex('hort\_sharesng\_users', array('perm\_' . Horde\_Perms::READ));
        \$this->addIndex('hort\_sharesng\_users', array('perm\_' . Horde\_Perms::EDIT));
        \$this->addIndex('hort\_sharesng\_users', array('perm\_' . Horde\_Perms::DELETE));


        if (!in\_array('hort\_shares', \$tableList)) \{
            \$t = \$this->createTable('hort\_shares', array('primaryKey' => false));
            \$t->column('share\_id', 'integer', array('null' => false));
            \$t->column('share\_name', 'string', array('limit' => 255, 'null' => false));
            \$t->column('share\_owner', 'string', array('limit' => 255, 'null' => false));
            \$t->column('share\_flags', 'integer', array('default' => 0, 'null' => false));
            \$t->column('perm\_creator', 'integer', array('default' => 0, 'null' => false));
            \$t->column('perm\_default', 'integer', array('default' => 0, 'null' => false));
            \$t->column('perm\_guest', 'integer', array('default' => 0, 'null' => false));
            \$t->column('attribute\_name', 'string', array('limit' => 255, 'null' => false));
            \$t->column('attribute\_desc', 'string', array('limit' => 255));
            \$t->primaryKey(array('share\_id'));
            \$t->end();

            \$this->addIndex('hort\_shares', array('share\_name'));
            \$this->addIndex('hort\_shares', array('share\_owner'));
            \$this->addIndex('hort\_shares', array('perm\_creator'));
            \$this->addIndex('hort\_shares', array('perm\_default'));
            \$this->addIndex('hort\_shares', array('perm\_guest'));
        \}

        if (!in\_array('hort\_shares\_groups', \$tableList)) \{
            \$t = \$this->createTable('hort\_shares\_groups');
            \$t->column('share\_id', 'integer', array('null' => false));
            \$t->column('group\_uid', 'string', array('limit' => 255, 'null' => false));
            \$t->column('perm', 'integer', array('null' => false));
            \$t->end();

            \$this->addIndex('hort\_shares\_groups', array('share\_id'));
            \$this->addIndex('hort\_shares\_groups', array('group\_uid'));
            \$this->addIndex('hort\_shares\_groups', 'perm');
        \}

        if (!in\_array('hort\_shares\_users', \$tableList)) \{
            \$t = \$this->createTable('hort\_shares\_users');
            \$t->column('share\_id', 'integer', array('null' => false));
            \$t->column('user\_uid', 'string', array('limit' => 255, 'null' => false));
            \$t->column('perm', 'integer', array('null' => false));
            \$t->end();

            \$this->addIndex('hort\_shares\_users', array('share\_id'));
            \$this->addIndex('hort\_shares\_users', array('user\_uid'));
            \$this->addIndex('hort\_shares\_users', array('perm'));
        \}

    \}

    /**
     * Downgrade
     *
     */
    public function down()
    \{
        \$this->dropTable('hort\_shares');
        \$this->dropTable('hort\_shares\_groups');
        \$this->dropTable('hort\_shares\_users');
        \$this->dropTable('hort\_sharesng');
        \$this->dropTable('hort\_sharesng\_groups');
        \$this->dropTable('hort\_sharesng\_users');
    \}

\}
</code></pre>
\end{document}
