egroupware_official/phpgwapi/inc/class.hooks.inc.php

114 lines
3.6 KiB
PHP
Raw Normal View History

<?php
/**************************************************************************\
2001-01-13 11:18:50 +01:00
* phpGroupWare API - Hooks *
* This file written by Dan Kuykendall <seek3r@phpgroupware.org> *
* Allows applications to "hook" into each other *
* Copyright (C) 2000, 2001 Dan Kuykendall *
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
2001-01-13 11:18:50 +01:00
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
2001-05-06 15:40:04 +02:00
/*!
@class hooks
2001-12-24 05:55:24 +01:00
@abstract class which gives ability for applications to set and use hooks to communicate with each other
@author Dan Kuykendall
2001-08-16 08:32:22 +02:00
@copyright LGPL
2001-12-24 05:55:24 +01:00
@package phpgwapi
@access public
2001-05-06 15:40:04 +02:00
*/
class hooks
{
/*!
@function read()
@abstract currently not being used
2001-03-13 19:30:21 +01:00
*/
2001-05-06 15:40:04 +02:00
function read()
{
2001-09-23 21:23:49 +02:00
$db = $GLOBALS['phpgw']->db;
2001-05-06 15:40:04 +02:00
2001-09-23 21:23:49 +02:00
$db->query('select * from phpgw_hooks');
2001-05-06 15:40:04 +02:00
while ($db->next_record())
{
2001-09-23 21:23:49 +02:00
$return_array[$db->f('hook_id')]['app'] = $db->f('hook_appname');
$return_array[$db->f('hook_id')]['location'] = $db->f('hook_location');
$return_array[$db->f('hook_id')]['filename'] = $db->f('hook_filename');
2001-05-06 15:40:04 +02:00
}
if(isset($return_array))
{
return $return_array;
}
else
{
return False;
}
2001-05-06 15:40:04 +02:00
}
2001-03-13 19:30:21 +01:00
/*!
2001-05-06 15:40:04 +02:00
@function process
2001-03-13 19:30:21 +01:00
@abstract process the hooks
@discussion not currently being used
2001-08-16 08:32:22 +02:00
@param \$type
@param \$where
2001-03-13 19:30:21 +01:00
*/
2001-09-23 21:23:49 +02:00
function process($type,$where='')
2001-05-06 15:40:04 +02:00
{
2001-09-23 21:23:49 +02:00
$currentapp = $GLOBALS['phpgw_info']['flags']['currentapp'];
2001-05-06 15:40:04 +02:00
$type = strtolower($type);
2001-09-23 21:23:49 +02:00
if ($type != 'location' && $type != 'app')
2001-05-06 15:40:04 +02:00
{
return False;
}
2001-05-06 15:40:04 +02:00
// Add a check to see if that location/app has a hook
// This way it doesn't have to loop everytime
2001-09-23 21:23:49 +02:00
while ($hook = each($GLOBALS['phpgw_info']['hooks']))
2001-05-06 15:40:04 +02:00
{
2001-09-23 21:23:49 +02:00
if ($type == 'app')
2001-05-06 15:40:04 +02:00
{
2001-09-23 21:23:49 +02:00
if ($hook[1]['app'] == $currentapp)
2001-05-06 15:40:04 +02:00
{
2001-09-23 21:23:49 +02:00
$include_file = $GLOBALS['phpgw_info']['server']['server_root'] . '/'
. $currentapp . '/hooks/'
. $hook[1]['app'] . $hook[1]['filename'];
2001-05-06 15:40:04 +02:00
include($include_file);
}
}
elseif ($type == "location")
{
if ($hook[1]["location"] == $where)
{
2001-09-23 21:23:49 +02:00
$include_file = $GLOBALS['phpgw_info']['server']['server_root'] . '/'
. $hook[1]['app'] . '/hooks/'
. $hook[1]['filename'];
2001-05-06 15:40:04 +02:00
if (! is_file($include_file))
{
2001-09-23 21:23:49 +02:00
$GLOBALS['phpgw']->common->phpgw_error('Failed to include hook: ' . $include_file);
2001-05-06 15:40:04 +02:00
}
else
{
include($include_file);
}
}
}
}
}
}
?>