Code

- fix for debian bug 535872
[gosa.git] / doc / README.devel
1 * How to get plugged in
3 Independently of beeing an LDAP style or LDAP unrelated plugin, you may start a new plugin,
4 by creating a new directory below the plugin directory structure. To be up to date, get a
5 fresh SVN checkout:
7 Change to the directory which will contain your GOsa checkout, then get the source:
9 # svn co https://oss.gonicus.de/repositories/gosa/branches/2.5 gosa
11 for the current 2.5 development line or
13 # svn co https://oss.gonicus.de/repositories/gosa/trunk gosa
15 for the bleeding edge development tree.
18 The gosa directory will contain your initial checkout now. In order to update from SVN
19 you simply can call "svn up".
21 Now you've an up to date GOsa. Note that there may be most obviously something broken if
22 you use trunk.
25 * First example
27 Lets explain how to create a simple GOsa plugin. The example shows a dummy plugin which is not
28 directly related with LDAP.
30 # cd plugins/addons
31 # mkdir dummyplug && cd dummyplug
33 GOsa expects a file named "main.inc" inside of this plugin directory. It is needed because some
34 plugins may need no standard handling and GOsa itself may not know how to initialize the plugin
35 classes. Here's our example:
37 ---
38 <?php
39         /* All page output must be placed inside the display variable. Please do not output anything
40            from within your plugin directly. GOsa will take the display variable after things got processed
41            and assemble the final page after that. */
43         /* print_header generates the page header including the headline and the icon, get template
44             path looks for eventually overloaded files. You don't have to take care of this - it's only important
45             for theming artists. Copy the icon (as .png) to the html/images directory, if you don't care about
46             the image, just copy the personal.png to dummy.png. */
47         $display= print_header(get_template_path('images/dummy.png'), _("A nice dummy plugin"));
49         /* All plugin objects get stored inside the PHP session. Here we create the object if it doesn't
50             exist yet. It is recreated if "reset" is set. */
51         if (!isset($_SESSION['dummy']) || (isset($_GET['reset']) && $_GET['reset'] == 1)){
52                 $_SESSION['dummy']= new dummy ($config);
53         }
54         $dummy= $_SESSION['dummy'];
56         /* Execute plugin. This calls your plugin class and appends its output to the display variable. */
57         $display.= $dummy->execute ();
59         /* The ignore field controls if GOsa should ignore the users tries to leave the plugin without
60            saving. For the dummy plugin, you can leave all the time without loosing data. */
61         $display.= "<input type=\"hidden\" name=\"ignore\">\n";
63         /* After executing the plugin, some data may have changed, so we need to put the plugin back
64            to the session. */
65         $_SESSION['export']= $export;
66 ?>
67 ---
69 The basic starter for your plugin is ready now. We're missing the plugin itself currently. To create it,
70 you need to create a file starting with class_ and ending with .inc. These files get sourced automatically.
72 Here's the class_dummy.inc:
74 ---
75 <?php
77 /* Create a class (name must be unique inside GOsa) which extends plugin. The plugin base
78     class contains all methods that are used by GOsa and it provides the mechanism to load data
79     from LDAP to local variables and prepare the save to ldap routine for you. */
80 class dummy extends plugin
81 {
83   /* These contain attributes to be loaded. We're not doing an LDAP plugin currently, so we don't
84      care... */
85   var $attributes= array();
86   var $objectclasses= array();
88   /* The constructor just saves a copy of the config. You may add what ever you need. */
89   function dummy ($config, $dn= NULL)
90   {
91         /* Include config object */
92         $this->config= $config;
93   }
95   /* Execute is the function all plugins need. It fills the plugin with life and produces the output. */
96   function execute()
97   {
98         /* Use the smarty templating engine here... */
99         $smarty= get_smarty();
101         /* Normally you would react to user input here. */
103         /* Let smarty fetch and process the page. Always seperate PHP and HTML as much as
104            you can. */
105         return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
106   }
109 ?>
110 ---
112 There are two things missing now. The template file and an entry in your gosa.conf. Lets finish the
113 work in the plugin directory, first.
115 Here is the contents.tpl file:
117 ---
118 <p>
119   {t}This is a dummy plugin. It really does nothing. The tags around this text do automatic translations to the desired language. Please don't include linefeeds here, or it will not work at all!{/t}
120 </p>
122 <p class="plugbottom">
123   &nbsp;
124 </p>
125 ---
127 Now add the following entry to your Addons section in gosa.conf:
128 --
129                         <plugin acl="dummy" class="dummy" icon="dummy.png"
130                                 path="plugins/addons/dummy" />
131 --
133 After logging into GOsa, you'll see your plugin in the addons section.