====== Feng Office Plugin Tutorial: Hello World ====== In this tutorial we will create a minimal plugin that shows a simple message in a Feng Office tab. This should provide a basic understanding of how the Feng Office Plugin System works. //A tutorial for a less "trivial" example is being developed and can be found [[Advanced Plugin Tutorial|here]].// ===== Creating the plugin Structure ===== First, choose a plugin name, and create a folder with that name in the Feng Office plugins folder: FENGOFFICE_ROOT/plugins/PLUGIN_NAME where FENGOFFICE_ROOT is the document root for Feng Office on your server and PLUGIN_NAME is the name of your new plugin, in our case 'helloworld', for example: /public_html/fengoffice/plugins/helloworld All the necessary resources and code for your plugin will be placed in this folder, including javascripts, css, images and, of course, the application php (templates, views, controllers, models). One exception is the theme-specific CSS, which must be inserted in the relevant CSS stylesheet within your theme. ===== Plugin Metadata ===== The first file you need to create is the plugin metadata 'info.php'. Create this file under your plugin root folder 'plugins/PLUGIN_NAME/info.php' containing this php code: "helloworld", // plugin name "version" => "1", // plugin version "author" => "Feng Office", // author name "website" => "http://fengoffice.com", // author website URL "description" => "My first Feng plugin" // brief description );?> This will provide information about the plugin version, description, order, dependencies, category, author and other metadata necessary for third party plugin management. However, if you want to create a new tab along with your plugin, you will need to specify it with a tab definition follows: "helloworld", // plugin name "version" => "1", // plugin version "author" => "Feng Office", // author name "website" => "http://fengoffice.com", // author website URL "description" => "My first Feng plugin", // brief description "tabs" => array( // tab definition array( "id" => "helloworld-panel", //tab id "ordering" => 2, //tab ordering position "title" => "helloworld tab", //tab title (lookup key for lang file) "icon_cls" => "ico-world", //CSS class for tab's icon "refresh_on_context_change" => true, //re-run the controller if e.g. new workspace is chosen "default_controller" => "helloworld", //default controller "default_action" => "say_hello" , //default action(method) called when tab is selected or context changes - used to list objects, etc. "initial_controller" => "" , //initial controller "initial_action" => "" , //initial action(method) called once per session - can be used to load js scripts, etc. "type" => "plugin", //type - use "plugin" "object_type_id" => 0 //id of the content object if it is related to one, otherwise 0 ) ) );?> Note: Please look below at the 'Email' plugin example for further details regarding a content object association. This tells the installer that it will have to create a new tab in the system, specifying id, title and many other configuration options, but the most important ones are default_controller and default_action. The tab title will be looked up in a language file. In our case the lookup string will be "helloworld tab". We need to provide a return string in the language file. Create the language folder 'plugins/PLUGIN_NAME/language/LANGUAGE', in our case 'plugins/helloworld/language/en_us'. Two files are placed into this folder: 'lang.js' and 'lang.php'. Simply copy the lang.js script from another plugin, and create 'lang.php' as follows: 'World', ); This will display 'World' as the our new tab's title. For multi-lingual support you may repeat this process for other languages. ===== Creating the Controller – The business layer ===== At this point we assume that you are familiar with MVC concepts. If not, we strongly suggest you explore the topic before proceeding. Create the folder 'application/controllers' under your plugin structure: FENGOFFICE_ROOT/plugins/PLUGIN_NAME/application/controllers Then create the following class under this folder: [PLUGIN_NAME]Controller.class.php That is, in our example (note the CamelCase): HelloworldController.class.php ...with the following content: In this case the controller loads the data, and assigns it to the view in a variable called 'message'. //Notes:// * We have not spoken about models yet, so the data is hard-coded in order to simplify the example. * This is not what the actual Mail plugin does, but it has been used this way to explain it better ===== Creating the View – The Presentation Layer ===== Create the folders 'application/views/helloworld' under your plugin structure so that it looks like: FENG_ROOT/plugin/PLUGIN_NAME/application/views/OBJECT_NAME i.e.: FENG_ROOT/plugin/helloworld/application/views/helloworld Within the last folder, create the following file: 'say_hello.php' with the following content:

Congratulations ! ! !

This is your first hello world application.

Note: When invoking a controller action (or method talking in OOP), the system automatically loads the view with the same name; controller function 'ACTION()' will invoke view 'ACTION.php'. ==== Configuring the Tab Icon ==== In info.php we set the array element "icon_cls" => "ico-world" and now we need to create a CSS class .ico-world that styles a background with the desired icon image. Create CSS stylesheet for the theme's tab at [FENG_ROOT]/plugins/helloworld/public/assets/css/helloworld.css and insert the class .ico-world. You may also create your an image folder for your plugin at [FENGOFFICE_ROOT]/plugins/helloworld/public/assets/images or, if suitable images are already available, simply use them instead, as we do here, i.e., the default theme's 16x16 sprites with a vertical offset of -357 pixels. .ico-world { background: transparent url('/public/assets/themes/default/images/16x16/all_16_16_vertical.png') no-repeat scroll 0 -357px !important; } ==== Custom CSS and JS ==== Custom CSS and JS can be done in many ways: **INLINE (not recommended): ** Each view can make use of