Location: PHPKode > projects > Work Tracker > work-tracker-0.1/includes/functions/module_api.func.php
<?php
/* $Id: module_api.func.php 2 2004-08-05 21:42:03Z eroberts $ */

/* {{{ Function: module_includes */
/**
 * Create array of files to include from modules
 *
 * @param string $hook Name of file to match
 * @param boolean $short Determines how to match filename
 * @returns string
 */
function module_includes($hook,$short = TRUE)
{
  $includes = array();

  if ($dir = @opendir(_MODULES_)) {
    while (($item = readdir($dir)) !== false) {
      if ($item == "." or $item == ".." or $item == "CVS") {
        continue;
      }
		
      if (is_dir(_MODULES_.$item)) {
        if ($short) {
          $filename = "$hook.php";
        } else {
          if (!empty($_GET['module'])) {
            $filename = $_GET['module']."/";
          }
          if (!empty($_GET['action'])) {
            $filename .= $_GET['action']."/";
          }
          $filename .= "$hook.php";
        }

        if (file_exists(_MODULES_.$item."/hooks/$filename")) {
          $include = _MODULES_.$item."/hooks/$filename";
          array_push($includes,$include);
        }
      }
    }
    closedir($dir);
  }

  return $includes;
}
/* }}} */

/* {{{ Function: module_setup */
/**
 * Retrieves any module setup scripts and runs them, deleting the setup
 * script afterwards
 */
function module_setup()
{
  if ($dir = @opendir(_MODULES_)) {
    while (($item = readdir($dir)) !== false) {
      if ($item == "." or $item == ".." or $item == "CVS") {
        continue;
      }

      if (is_dir(_MODULES_.$item)) {
        if (file_exists(_MODULES_.$item."/setup.$item.php")) {
          include_once(_MODULES_.$item."/setup.$item.php");
          
          if (!unlink(_MODULES_.$item."/setup.$item.php")) {
            logger("Could not remove setup file for $item module.","module_errors");
          }
        }
      }
    }
    closedir($dir);
  }
}
/* }}} */

/* {{{ Function: gen_cache */
/**
 * Generate cache files
 *
 * @param string $table Table to pull data from
 * @param string $id Unique id field of table
 * @param string $data Data field of table to cache
 */
function gen_cache($table,$id,$data)
{
  global $dbi,$cache_data;

  if (!in_array($table,$cache_data)) {
    return;
  }

  if ($fp = fopen(_CACHE_."$table-$data-cache.php","w")) {
    fwrite($fp,"<?php\n");
    fwrite($fp,"\n// DO NOT EDIT THIS FILE\n\n");
    fwrite($fp,"\${$table}_{$data}_cache = array(\n");
    
    $sql  = "SELECT $id,$data ";
    $sql .= "FROM $table ";
    $sql .= "ORDER BY $id ASC";
    $result = $dbi->query($sql);
    if ($dbi->num_rows($result) > 0) {
      $count = $dbi->num_rows($result);

      for ($x = 0;$x < $count;$x++) {
        list($key,$val) = $dbi->fetch($result);

        // We stripslashes here and then addslashes later
        // for any value that might have made it into the database
        // without having special characters escaped
        $val = stripslashes($val);

        fwrite($fp,sprintf("\t%5.5d => '%s'%s\n",
          $key,addslashes($val),$x != ($count - 1) ? "," : ""));
      }
    }

    fwrite($fp,");\n");
    fwrite($fp,"?>");
    fclose($fp);
  }
}
/* }}} */
?>
Return current item: Work Tracker