Plugin Tutorials 101 - Basic Menu plugin

From e107 Wiki
Jump to: navigation, search

e107 Wiki: English | Русский | Deutsch | Français | Magyar | Português | Български | Česky | Nederlands | Ελληνικά | Italiano | Norske | Polska | Slovenščina | Español | Svenska | Translate: Wiki | Page


Current Release 1.0.4 | | Download | Changelog | Forum | Plugins | Themes | RSS Feed of Latest Changes | Atom Feed of Latest Changes

How to write a plugin
Main page > I : First Aid > II : Development > III : Administration > IV : How To's > V : Plugin Writing > VI : Theming & Shortcodes

Tutorial 101 - a basic menu plugin

Plugins are installable features, such as a calendar, a menu or an application of any sort.

Just like with Mr. Potato Head, you can put on these ears and that nose, then change your mind and put on different ears. With e107 you don’t have to reprogram or modify the code... if someone has written a plugin, you can use it too.

How do I write one?

This hands-on tutorial will help you write the simplest plugin so that you can get the idea. It is missing many features and safety checks but it works.

The task

The task this plugin will perform will add a promotion link on your web site. The plugin will show a pretty picture under a title. Click an the picture to link to a page you wish to promote.

This plugin will be a menu plugin. It goes in the menu pane (the side menus) and not in the content pane (the middle section).

The tutorial promo is for a tent sale. It will look like this;

Buy our tents.



Go to your website directory. Go to the e107_plugin directory. Create a new directory called promo_menu.

mkdir promo_menu
chmod 777 promo_menu <-- this is only required for scripts needing to write in the folder. 

Go into the directory. Copy a small picture into this directory. Rename it to “tents.jpg”
(mv your.jpg tents.jpg)

The code

Create a new file called promo_menu.php Insert the following code.

Code: promo_menu.php
 $promo_title   = 'Buy our tents.';
 $promo_link    = e_BASE.'index.php';
 $promo_picture = e_PLUGIN.'promo_menu/tents.jpg';
 $promo_alt     = 'our tents';

 $text  = '<a href="'.$promo_link.'">';
 $text .= '<img src="'.$promo_picture.'" alt="'.$promo_alt.'" />';
 $text .= '</a>';



Note that e_BASE will be converted into the root dir path of your e107 installation and e_PLUGIN the plugins folder path. Now, upload your files to the promo_menu folder and then go to your admin -> menus area and enable 'promo' in one of the menu areas. If you wish to add admin configuration options, database tables and preferences etc please read on - you will need to make a plugin.php file.

How to make it install (Optional for Menus)

There is only one file needed to get this plugin to install into the admin interface. plugin.php contains the instructions needed by the plugin manager. The plugin.php file looks like this;

Code: plugin.php
 if (!defined('e107_INIT')) { exit; }
 // Plugin info  
 $eplug_name    = "promo";
 $eplug_version = "1.0";
 $eplug_author  = "Strider22";
 $eplug_description="A simple promo. A title, a picture, a  link.";
 $eplug_compatible  = "e107 v0.7";
 $eplug_readme      = "";        
 // Name of the plugin's folder
 $eplug_folder = "promo_menu";
 // Name of menu item for plugin  
 $eplug_menu_name = "promo_menu";
 // Name of the admin configuration file  
 $eplug_conffile = "";
 // List of preferences 
 $eplug_prefs       = "";
 $eplug_table_names = ""; 
 // Create a link in main menu (yes=TRUE, no=FALSE) 
 $eplug_link = TRUE;
 $eplug_link_name  = "promo";
 $eplug_link_perms = "Everyone";
 // Text to display after plugin successfully installed 
 $eplug_done           = "Installation Successful..";
 $eplug_uninstall_done = "Uninstalled Successfully..";

Are you ready?

Make sure you have the following three files in the promo directory.


Let's install

Pull up your website. Login as an administrator. Select the plugin manager. Promo will show in the uninstalled list, but does not have an Install button as it does not need to be installed.

This makes promo available to e107. We need to activate it before it will show up.

Activating the promo

Click Content/Menus. Locate Promo in the inactive list. Activate it in area 1. Find promo in area 1 and using the dropdown box move to top.

et voila

Go to your home page and observe the fruits of your labour.

--Written by Strider22 01:03, 30 July 2006 (CDT)