[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> addon.php (source)

   1  <?php
   2  
   3  ///////////////////////////////////////////////////////////////////////////////
   4  //                                                                           //
   5  // Copyright (C) 2006  Phorum Development Team                               //
   6  // http://www.phorum.org                                                     //
   7  //                                                                           //
   8  // This program is free software. You can redistribute it and/or modify      //
   9  // it under the terms of either the current Phorum License (viewable at      //
  10  // phorum.org) or the Phorum License that was distributed with this file     //
  11  //                                                                           //
  12  // This program is distributed in the hope that it will be useful,           //
  13  // but WITHOUT ANY WARRANTY, without even the implied warranty of            //
  14  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                      //
  15  //                                                                           //
  16  // You should have received a copy of the Phorum License                     //
  17  // along with this program.                                                  //
  18  ///////////////////////////////////////////////////////////////////////////////
  19  
  20  // This script can be used for implementing addon scripts, using the
  21  // Phorum module system. This allows for full featured scripts, that
  22  // run on their own (outside the hooks in the Phorum code), but which
  23  // do not need to be copied to the Phorum main directory to be run.
  24  // By containing addon scripts in the modules this way, installation and
  25  // maintaining them is easier for the users.
  26  //
  27  //
  28  // IMPLEMENTING AN ADDON SCRIPT:
  29  // -----------------------------
  30  //
  31  // To implement an addon script, the following needs to be done:
  32  //
  33  // 1) Create a module, which contains a function that has to be 
  34  //    called for running the addon code. For example:
  35  //    
  36  //    function phorum_mod_yourmod_youraddonfunction() {
  37  //      # Code for implementing the addon goes here.
  38  //      # This can of course also be an include of a script
  39  //      # to run, using include("./mods/yourmod/yourscript.php").
  40  //      # ...
  41  //    }
  42  // 
  43  // 2) In the module information, register an addon hook for the function:
  44  //
  45  //    hook: addon|phorum_mod_yourmod_youraddonfunction
  46  //
  47  // 3) Call the addon code through the addon.php script (where 1 in the
  48  //    URL indicates the current forum id):
  49  //
  50  //    http://your.phorum.site/addon.php?1,module=yourmod
  51  //
  52  //
  53  // LINKING TO AN ADDON SCRIPT:
  54  // ---------------------------
  55  //
  56  // If you want to link to the addon script, then always use the 
  57  // phorum_get_url() function for generating the URL to link to.
  58  //
  59  //    $url = phorum_get_url(PHORUM_ADDON_URL, "yourmod");
  60  //
  61  //
  62  // IMPLEMENTING MULTIPLE ADDON ACTIONS:
  63  // ------------------------------------
  64  // 
  65  // Only one addon hook is allowed per module. If your module needs to 
  66  // implement multiple addon script actions, then handle this by means
  67  // of extra custom parameters for the addon.php URL, for example:
  68  //
  69  //    http://your.phorum.site/addon.php?1,module=yourmod,action=myaction
  70  //
  71  // Using this, your addon function can check $PHORUM["args"]["action"]
  72  // to see what action to perform. Generating an URL for this example
  73  // would look like this:
  74  //
  75  //    $url = phorum_get_url(PHORUM_ADDON_URL, "yourmod", "action=myaction");
  76  // 
  77  
  78  define('phorum_page','addon');
  79  
  80  include_once ( "./common.php" );
  81  
  82  // Bail out early if there are no modules enabled that implement
  83  // the addon hook.
  84  if (! isset($PHORUM["hooks"]["addon"])) die(
  85      '<h1>Modscript Error</h1><br/>' .
  86      'There are no addon hook enabled modules active.');
  87  
  88  // Parse the module=<module> argument.
  89  if (! isset($PHORUM["args"]["module"])) die (
  90      '<h1>Modscript Error</h1><br/>' .
  91      'Missing "module" argument.');
  92  $module = basename($PHORUM["args"]["module"]);
  93  
  94  // Check if the mod is enabled and does implement the addon hook.
  95  // Filter the list of hooks, so we only keep the one for the
  96  // requested module.
  97  $avail_hooks = $PHORUM["hooks"]["addon"];
  98  $filtered_hooks = array("mods" => array(), "funcs" => array());
  99  foreach ($avail_hooks["mods"] as $id => $checkmodule) {
 100      if ($module == $checkmodule) {
 101          $filtered_hooks["mods"][] = $module;
 102          $filtered_hooks["funcs"][] = $avail_hooks["funcs"][$id];
 103      }
 104  }
 105  
 106  if (count($filtered_hooks["mods"]) == 0) die(
 107      '<h1>Modscript Error</h1>' .
 108      'No addon hook enabled for module "'. htmlspecialchars($module) .'"');
 109  
 110  if (count($filtered_hooks["mods"]) > 1) die(
 111      '<h1>Modsript Error</h1>' .
 112      'More than one addon hook was registered ' .
 113      'in the info for module "' . htmlspecialchars($module) . '".<br/>Only ' .
 114      'one addon hook is allowed per module.');
 115  
 116  // Run the hook function.
 117  $PHORUM["hooks"]["addon"] = $filtered_hooks;
 118  phorum_hook("addon");
 119  
 120  ?>


Généré le : Thu Nov 29 12:22:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics