|
|||||||||||||||||||||||||||||||||||
Knowledgeroot Extension Interfacelast change: 4. November 2007 1. Create folders and filesAll extensions are located in the folder "system/extension". Each extension requires its own subfolder. This folder must be named like your extension! You have to arrange for the following 5 files in this folder: "info.php", "install.php", "language.php", "config.php" and the extension's php class. This last file must be named after your extensionname in the following fashion: "class-extensionname.php". Example: your extension is called "testextension", the filename should read "class-testextension.php". 1.1 info.phpFirst, we will take a look at info.php. $CONF = array ( "title" => "title for my extension", "description" => "discription for my extension", "version" => "0.1", "dependencies" => "", "state" => "devel", "author" => "your name", "author_email" => "your@name.tld", "author_company" => "your company", ); ?> info.php contains an array with a detailed discription of your extension. It is crucial to name the variable $CONF. dependencies to other extensions must be listed in the corresponding field "dependencies". List elements are separated by commas. 1.2 install.phpThis file is needed for clean installation and updates of your extension! It declares whether your extension is an adminextension, its current version and the version history. Here is an example: $CONF = array( "admin" => 0, "version" => "0.2", "version_history" => "0.1;0.2", ); Setting "admin" to 1 turns your extension into an Adminextension. The current version is noted in "version", and "version_history" takes a list of all prior versions, up to and including the current, seperated by ";". 1.3 config.phpThis file supplies a default configuration setting for your extension. It is defined in the variable $CONF. An example, with a single configuration value: $CONF = array ( "myconf" => "myvalue", ); ?> Your extension class retrieves values from this configuration using: $this->CONF['myconf'] Users can override your default settings by editing the config file ./config/config.inc.php. They should not modify your provided default file. Here is an example how to override the default myconf value from the example above: $CONF['ext']['extensionname']['myconf'] = "my new value"; Your extension code need not be modified to see the replaced value. 1.4 language.phpThis file contains the translated phrases for all languages your extension supports. The translations are arranged in a multi-dimensional array, as shown in the following example: $LANG = array( 'de' => array( 'translateme' => 'Übersetzung', ), 'en' => array( 'translateme' => 'translation', ), ); ?>
$this->CLASS['language']->get['ext']['extensionname']['translateme'] With that construct you can get you translation for the keyword. The language is set by the user or by the configfile. 1.5 class fileThe next step is to create your class in the "class-yourextension.php". Here is an example.
/******************************
* extensionname
* your name
* date
*
* version
* description
******************************/
class yourextension extends extension_base {
}
?>
This is a default class for your extension. This class should extends on the class "extension_base". So it is easy to have access to all other extensions and to have no problems if new things will be added to knowledgeroot. $this->CLASS in your extension to have access to all other extensions and classes and to your languages! 2. Create menu itemsNow, we will create menu items that you need for your extension. This should be a easy process and we use php arrays for this. top - for top navigation tree - for the tree navigation page - navigation for each page content - navigation for each content contentline - navigation on the horizontal line. toolbar - navigation in the toolbar at the bottom pagecontext - right click menu on tree elements contentcontext - right click menu on content elements This are the 8 menus in knowledgeroot you can use. You can create items to all of this menus and you can also order them! The default menus are create in "include/class-default-menu.php". In this file you found all the code that is needed to create the default menus in knowledgeroot. You can take a look at this file to get an impression of how this works. But now its time to create your own menu item. $this->menu['top']['myname']['name'] = "my name"; $this->menu['top']['myname']['admin'] = 1; $this->menu['top']['myname']['link'] = "index.php?action=myaction"; You see now a simple array of a menu item. The first section in this array contains the one name of the 8 menus. You can not use "config" as name for menu. This is used for settings for this menu. So here we use top. The next section must be a unique name at this menu section! Here we use "myname" for this. The last section in this array contains the options for this menu item. You should set a "name" and a "link" to each item! Here, the option "admin" is set to 1. That means that you need admin rights to display this item. With that short array you have create your first menu item.
$this->menu['top']['config']['wrap'] = "<div>|</div>";
3. Show contentAt this part you will create the output of your extension. This will only be a small example.
/******************************
* extensionname
* your name
* date
*
* version
* description
******************************/
class yourextension extends extension_base {
function main() {
$this->menu['top']['register']['name'] = "register";
$this->menu['top']['register']['link'] = "index.php?action=register";
$this->menu['top']['register']['priority'] = "1";
if($_GET['action'] == "register") {
$content =$this->show_register();
}
return $content;
}
function show_register() {
return "hello world!";
}
}
?>
This easy class will display a menu item to the top navigation. If you click on that link the text "hello world!" will be shown.
class yourextension extends extension_base {
function show_content($id) {
return "content for id " . $id;
}
}
?>
So this function will be display the text "content for id" and the id itself. So here you can do all you want with that id. For example you could can select other things from other tables. A good pratice example could be content element like a normal wikisyntax. For that we must display and convert the wiki syntax to display the htmlcode. Here you can use the table "content" in the database to save the content. So if you need more tables for your content you can create it with your extension. All is possible to do now. |
|||||||||||||||||||||||||||||||||||