Creating a Module

From PGVWiki
Revision as of 00:17, 16 October 2009 by Nigelo (talk | contribs) (→‎/modules/your_module.php)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Modules File Structure

modules (dir)
|
+--your_module (dir)
|  |
|  +--languages (dir)
|  |  +--ym_lang.en.php
|  |
|  +--images (dir)
|  |  +--icon.gif
|  |
|  +--your_module.php
|  +--menu.php
|  +--ym_privacy.php
|  +--ym_functions.php
|
+--your_module.php


/modules/your_module.php

Copy the following code into your file and save it:

;<?php exit; ?>
[Module]
type = PGV_MOD_OO

As far as I can tell, this will tell PGV that your module is a PGV module.



/modules/your_module/menu.php

Replace instances of your_module with your module's name and ym with the initials for your module

<?php

//-- security check, only allow access from module.php. Include this code in each of your module files
if (strstr($_SERVER["SCRIPT_NAME"],"menu.php")) {
   print "Now, why would you want to do that.  You're not hacking are you?";
   exit;
}

class your_module_ModuleMenu {
   /**  
     * get the Your Module menu
     * @return Menu 	the menu item
     */
  function &getMenu() {
      global $TEXT_DIRECTION, $PGV_IMAGE_DIR, $PGV_IMAGES, $GEDCOM, $pgv_lang;
      global $PRIV_USER, $PRIV_PUBLIC;

      include('ym_privacy.php');

      if (!file_exists("modules/your_module.php")) return null;
      if ($PRIV_USER<getUserAccessLevel()) return null;  

      if (!file_exists('modules/your_module/languages/ym_lang.en.php')) return null;

      require_once 'modules/your_module/languages/ym_lang.en.php';
      if ($TEXT_DIRECTION=="rtl") $ff="_rtl"; else $ff="";

      //-- main menu item - this uses the icon as the Welcome Page menu
      $menu = new Menu($pgv_lang["your_module"], "module.php?mod=your_module", "down");
      if (!empty($PGV_IMAGES["gedcom"]["large"]))
      $menu->addIcon($PGV_IMAGE_DIR."/".$PGV_IMAGES["gedcom"]["large"]);
      $menu->addClass("menuitem$ff", "menuitem_hover$ff", "submenu$ff");
   
      //'First Task' ddl menu item //this is the first sub menu option
      if (getUserAccessLevel(getUserName())<= $SHOW_FIRST_OPTION)//set $SHOW_FIRST_OPTION is set in ym_privacy.php
       {
           $submenu= new Menu($pgv_lang["first_option"], "module.php?mod=your_module&action=firstop");
           $submenu->addIcon('modules/your_module/images/icon.gif');
           $submenu->addClass("submenuitem$ff", "submenuitem_hover$ff");
           $menu->addSubmenu($submenu);
        }
          //Additional sub menu options can be added by repeating the code above
          
         return $menu;
        }
}
?>