How to create new Addons

From MemHT Wiki

Jump to: navigation, search

Contents

Simple addon

1. Create a folder with the addon name (no spaces or special characters) in root/pages/

Example: root/pages/pagename

2. The main file into the folder must be named "index.php"

3. Language files should be placed in root/pages/pagename/lang/ and must have the name of the language

Example: root/pages/pagename/lang/english.php
If the site language (example: italian) is different from the default one (usually english) and italian.php doesn't exist, the default language (set in the site configuration) will be included

4. root/pages/pagename/index.php should have the following code structure:


<?php
 
if (!defined("_LOAD_PAGE_")) { die("Error: This file cannot be opened directly!"); }
 
openTable();
 
     echo "Page content";
 
closeTable();
 
?>


More complicated addon

Usually addons are not used just to write "Hello World!" and we need an efficient way to manage different operations


MemHT Portal use the following structure:

<?php
 
if (!defined("_LOAD_PAGE_")) { die("Error: This file cannot be opened directly!"); }
openTable();
 
switch($op) {
     case "printStr": myFunction(); break;
     default: salute(); break;
}
 
closeTable();
 
function myFunction() {
     if (isset($_GET['text'])) {
          $text = inCode($_GET['text']);
          echo $text;
     } else {
          echo "No arguments!";
     }
}
 
function salute() {
          echo "Hi, this function will be executed if no operation is specified";
}
 
?>


By calling (fox example) "index.php?page=pagename&op=printStr&text=Hello" the script will execute the function "printStr" with the $_GET variable "text" that contains "Hello" as an argument.


Files structure

Administration side

http://www.example.com/admin/pages/addon_name/index.php
http://www.example.com/admin/pages/addon_name/lang/english.php
http://www.example.com/admin/menu/addon_name.php

Client side

http://www.example.com/pages/addon_name/index.php
http://www.example.com/pages/addon_name/lang/english.php


Image:Globe.png Languages العربيةBahasa IndonesiaBosanskiБългарскиDanskDeutschEnglishEspañolفارسیFrançaisGalegoעבריתItalianoMagyarМакедонскиNederlandsPortuguêsРусскийСрпски/SrpskiSvenskaTürkçeУкраїнськаTiếng Việt
Personal tools