Créer un module

De PGVWiki
Sauter à la navigation Sauter à la recherche

Structure de fichiers du module

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

Copiez le code suivant dans votre fichier et sauvegardez-le:

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

Ce code signifiera à PGV que votre module est un module de PGV.




/modules/votre_module/menu.php

Remplacez les instances de votre_module par le nom de votre module et remplacez ym par les initiales de votre 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;
        }
}
?>