6.0.0-git
2019-08-21

Diff for CreatingYourFirstModule between 6 and 7

+ Creating a Horde Module



Note: 

The HEAD skeleton module will not work with the stable FRAMEWORK_3 or H3 Horde framework and Horde base library. It uses API calls which are not available in FRAMEWORK_3.
Don't use Skeleton from CVS. Use Skeleton from horde-hatchery (git) as outlined below.
There is currently no usable version of skeleton which is tagged FRAMEWORK_3. An older revision of the CVS HEAD version may work though.



1.
1. Check out the skeleton module from horde CVS


horde-hatchery Git

<code type="sh">

export CVSROOT=:pserver:cvsread@anoncvs.horde.org:/repository

# The following password is horde

cvs login

cvs export -d modulename -r HEAD skeleton
 git clone --depth 1 git://dev.horde.org/horde/git/horde-hatchery/
 cd horde-hatchery
 cp -R skeleton/ /your/install/path/to/horde/
</code>



2.
2. Create the following script as prjrename.php - save it somewhere sensible, like your home directory:



<code type="php">

#!/usr/bin/php -q

<?

function analysedir( $path_, $list_ )

{
{
  // Read dir

  $handle = opendir($path_);

  while (false !== ($file = readdir($handle)))

  {

    if( $file!='.' && $file!='..')

    {

        $file = $path_ . DIRECTORY_SEPARATOR . $file;

        //echo "$filen";



        if( !is_dir( $file ) )  // If File: Append

        {

          $list_[count($list_)]=$file;

        }

        else   // If Folder: scan recursively

        {

          $list_ += analysedir($file, $list_ );

        }

   }

 }      // While END

 return $list_;

}



function substitute_skeleton( $filename, $modulname )

{

  $prjUC=strtoupper(trim($modulname));

  $prjLC=strtolower($prjUC);

  $prjMC=substr($prjUC,  $prjMC=substr($prjUC, 0, 1) . substr($prjLC, 1, strlen($prjLC)-1);



  $filehandle=fopen(trim($filename), 'r');

  $file=fread($filehandle, filesize($filename));

  fclose($filehandle);

  $newfile=str_replace(array('SKELETON', 'Skeleton', 'skeleton'), array($prjUC, $prjMC, $prjLC), $file);

  $filehandle=fopen(trim($filename), 'w');

  fwrite($filehandle, $newfile);

  fclose($filehandle);

}



function help()

{

  echo  echo "projectrename.php </path/to/skeleton-folder/> <modulname>n";

}


}

//

// ------------------- Main-Code --------------------

//



if (count($_SERVER['argv'])==3)

{

  // Preparation

  $list = array();

  $path = trim($_SERVER[argv][1]);

  $modul = trim($_SERVER[argv][2]);



  // Fetch Filelist

  $list  $list = analysedir( $path, $list );



  // Modify each File

  foreach( $list as $file )

  {

        //echo $modul.": ".$file."n";

        substitute_skeleton( $file, $modul );

  }

}

else

  help();
?>
</code>

3. On a unix system, use the following command to replace all skeleton strings with your project name (Not tested on Windows, but should work):

?>

</code>



3. On a unix system, use the following command to replace all skeleton strings with your project name (Not tested on Windows, but should work):



<code type="sh">

projectrename.php /path/to/skeleton/Checkout/ modulname

</code>



4.</code>

4. Perform some file modifications:




<code type="sh">

mv /path/to/modulename/lib/Skeleton.php /path/to/modulename/lib/Modulename.php

mkdir /path/to/modulename/themes/graphics

</code>



5. Upload a PNG icon at 16x16 for the module to the path created above, this one is available if you're stuck:



http://spriggs.org.uk/projects/horde_dev/fitlog/themes/graphics/fitlog.png



6.6. In /path/to/horde/config/registry.d/ create a file called modulename.php. Please note the lack of ?> at the end of the php block, and also the menu parent. If you want your object to go *ANYWHERE ELSE* you will need to change this!



<code type="php">

<?php

$this->applications['modulename'] = array(

    'fileroot' => dirname(__FILE__) . '/../../modulename',

    'webroot' => $this->applications['horde']['webroot'] . '/modulename',

    'name' => _("A description of your module"),

    'status' => 'active',

    'menu_parent' => 'horde'

);

</code>



OK, so you now have your first module. Now, you need to populate it with content. This will be the subject of the next section: PopulatingYourFirstModule