some additional performance improvements, including a switch to the hooks class which I finished up

This commit is contained in:
seek3r 2002-01-02 14:33:05 +00:00
parent 70261207f3
commit 32306abaf6
25 changed files with 203 additions and 191 deletions

View File

@ -19,7 +19,7 @@
$app = $HTTP_GET_VARS['app'];
if ($app)
{
$included = $GLOBALS['phpgw']->common->hook_single('about',$app);
$included = $GLOBALS['phpgw']->hooks->single('about',$app);
}
else
{

View File

@ -1001,7 +1001,7 @@
$this->template->pfp('out','view_t');
$GLOBALS['phpgw']->common->hook('addressbook_view');
$GLOBALS['phpgw']->hooks->process('addressbook_view');
}
function html_1button_form($name,$lang,$link)

View File

@ -141,13 +141,13 @@
if($appname <> 'admin')
{
$GLOBALS['phpgw']->common->hook_single('deleteaccount', $appname);
$GLOBALS['phpgw']->hooks->single('deleteaccount', $appname);
}
}
}
$GLOBALS['phpgw']->common->hook_single('deleteaccount','preferences');
$GLOBALS['phpgw']->common->hook_single('deleteaccount','admin');
$GLOBALS['phpgw']->hooks->single('deleteaccount','preferences');
$GLOBALS['phpgw']->hooks->single('deleteaccount','admin');
$basedir = $GLOBALS['phpgw_info']['server']['files_dir'] . SEP . 'users' . SEP;
@ -261,7 +261,7 @@
{
if (!$t[($app_name=='admin'?'common':$app_name)])
{
$GLOBALS['phpgw']->common->hook_single('add_def_pref', $app_name);
$GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name);
$docommit = True;
}
}
@ -478,7 +478,7 @@
{
if (!$t[($app_name=='admin'?'common':$app_name)])
{
$GLOBALS['phpgw']->common->hook_single('add_def_pref', $app_name);
$GLOBALS['phpgw']->hooks->single('add_def_pref', $app_name);
$docommit = True;
}
}

View File

@ -96,12 +96,12 @@
/* if ($apps_after)
{
$GLOBALS['pref'] = CreateObject('phpgwapi.preferences',$userData['account_id']);
$GLOBALS['phpgw']->common->hook_single('add_def_pref','admin');
$GLOBALS['phpgw']->hooks->single('add_def_pref','admin');
while ($apps = each($apps_after))
{
if (strcasecmp ($apps[0], 'admin') != 0)
{
$GLOBALS['phpgw']->common->hook_single('add_def_pref', $apps[1]);
$GLOBALS['phpgw']->hooks->single('add_def_pref', $apps[1]);
}
}
$GLOBALS['pref']->save_repository(False);
@ -116,7 +116,7 @@
// start inlcuding other admin tools
while($app = each($apps_after))
{
$GLOBALS['phpgw']->common->hook_single('add_user_data', $value);
$GLOBALS['phpgw']->hooks->single('add_user_data', $value);
}
*/
return $userData['account_id'];

View File

@ -36,7 +36,7 @@
{
$this->common_header();
$GLOBALS['phpgw']->common->hook('acl_manager',array('preferences'));
$GLOBALS['phpgw']->hooks->process('acl_manager',array('preferences'));
$this->template->set_file(array(
'app_list' => 'acl_applist.tpl'
@ -99,7 +99,7 @@
function access_form()
{
$GLOBALS['phpgw']->common->hook_single('acl_manager',$GLOBALS['acl_app']);
$GLOBALS['phpgw']->hooks->single('acl_manager',$GLOBALS['acl_app']);
$location = base64_decode($GLOBALS['location']);
$acl_manager = $GLOBALS['acl_manager'][$GLOBALS['acl_app']][$location];

View File

@ -70,7 +70,7 @@
if ($GLOBALS['HTTP_POST_VARS']['submit'])
{
/* Load hook file with functions to validate each config (one/none/all) */
$GLOBALS['phpgw']->common->hook_single('config_validate',$appname);
$GLOBALS['phpgw']->hooks->single('config_validate',$appname);
while (list($key,$config) = each($GLOBALS['HTTP_POST_VARS']['newsettings']))
{
@ -145,7 +145,7 @@
$vars = $t->get_undefined('body');
$GLOBALS['phpgw']->common->hook_single('config',$appname);
$GLOBALS['phpgw']->hooks->single('config',$appname);
while (list($null,$value) = each($vars))
{

View File

@ -92,7 +92,7 @@
break;
}
$GLOBALS['phpgw']->common->hook($_hookname);
$GLOBALS['phpgw']->hooks->process($_hookname);
if (count($GLOBALS['menuData']) > 1)
{

View File

@ -72,7 +72,7 @@
section_end();
}
$GLOBALS['phpgw']->common->hook('admin');
$GLOBALS['phpgw']->hooks->process('admin');
$GLOBALS['admin_tpl']->pparse('out','list');
$GLOBALS['phpgw']->common->phpgw_footer();

View File

@ -323,7 +323,7 @@
$returndoc['value']['file'][] = $fn;
}
}
if (isset($returndoc['value']) && is_array($returndoc['value']))
if (@isset($returndoc['value']) && is_array($returndoc['value']))
{
$doc_array[$startstop[$key]][0] = $returndoc['value'];
}

View File

@ -506,7 +506,7 @@ if ($messages)
if (!is_array ($GLOBALS['settings']))
{
$pref = CreateObject ('phpgwapi.preferences', $GLOBALS['userinfo']['username']);
$GLOBALS['phpgw']->common->hook_single ('add_def_pref', $GLOBALS['appname']);
$GLOBALS['phpgw']->hooks->single ('add_def_pref', $GLOBALS['appname']);
$pref->save_repository (True);
$pref_array = $pref->read_repository ();
$GLOBALS['settings'] = $pref_array[$GLOBALS['appname']];

View File

@ -239,7 +239,7 @@
);
}
@reset($sorted_apps);
$GLOBALS['phpgw']->common->hook('home',$sorted_apps);
$GLOBALS['phpgw']->hooks->process('home',$sorted_apps);
if($GLOBALS['portal_order'])
{

View File

@ -41,7 +41,7 @@
}
rmdir($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']);
}
$GLOBALS['phpgw']->common->hook('logout');
$GLOBALS['phpgw']->hooks->process('logout');
$GLOBALS['phpgw']->session->destroy($GLOBALS['sessionid'],$GLOBALS['kp3']);
}
else

View File

@ -38,7 +38,7 @@
<table>
<tr><td><a href="<?php echo $GLOBALS['phpgw']->link('/notify.php'); ?>">Check Now</a></td></tr>
<?php
$GLOBALS['phpgw']->common->hook('notifywindow',array('email'));
$GLOBALS['phpgw']->hooks->process('notifywindow',array('email'));
?>
</table>
</body>

View File

@ -20,6 +20,6 @@
include('./header.inc.php');
echo '<html><body>';
$GLOBALS['phpgw']->common->hook('simple',array('email'));
$GLOBALS['phpgw']->hooks->process('simple',array('email'));
echo '</body></html>';
?>

View File

@ -535,11 +535,11 @@
$appdir = PHPGW_INCLUDE_ROOT . '/'.$appname;
$appdir_default = PHPGW_SERVER_ROOT . '/'.$appname;
if (is_dir ($appdir))
if (@is_dir ($appdir))
{
return $appdir;
}
elseif (is_dir ($appdir_default))
elseif (@is_dir ($appdir_default))
{
return $appdir_default;
}
@ -569,11 +569,11 @@
$incdir = PHPGW_INCLUDE_ROOT . '/' . $appname . '/inc';
$incdir_default = PHPGW_SERVER_ROOT . '/' . $appname . '/inc';
if (is_dir ($incdir))
if (@is_dir ($incdir))
{
return $incdir;
}
elseif (is_dir ($incdir_default))
elseif (@is_dir ($incdir_default))
{
return $incdir_default;
}
@ -1113,116 +1113,33 @@
/*!
@function hook
@abstract hooking function which allows applications to 'hook' into each other
@discussion Someone flesh this out please
@abstract temp wrapper to new hooks class
*/
// Note: $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo)
function hook($location, $order = '', $no_permission_check = False)
function hook($location, $appname = '', $no_permission_check = False)
{
if ($order == '')
{
settype($order,'array');
$order[] = $GLOBALS['phpgw_info']['flags']['currentapp'];
}
/* First include the ordered apps hook file */
reset ($order);
while (list(,$appname) = each($order))
{
$f = PHPGW_SERVER_ROOT . '/' . $appname . '/inc/hook_' . $location . '.inc.php';
if (file_exists($f) &&
( $GLOBALS['phpgw_info']['user']['apps'][$appname] || (($no_permission_check || $appname == 'preferences') && $appname)) )
{
include($f);
}
$completed_hooks[$appname] = True;
}
/* Then add the rest */
if ($no_permission_check)
{
reset($GLOBALS['phpgw_info']['apps']);
while (list(,$p) = each($GLOBALS['phpgw_info']['apps']))
{
$appname = $p['name'];
if (! isset($completed_hooks[$appname]) || $completed_hooks[$appname] != True)
{
$f = PHPGW_SERVER_ROOT . '/' . $appname . '/inc/hook_' . $location . '.inc.php';
if (file_exists($f))
{
include($f);
}
}
}
}
else
{
reset ($GLOBALS['phpgw_info']['user']['apps']);
while (list(,$p) = each($GLOBALS['phpgw_info']['user']['apps']))
{
$appname = $p['name'];
if (! isset($completed_hooks[$appname]) || $completed_hooks[$appname] != True)
{
$f = PHPGW_SERVER_ROOT . '/' . $appname . '/inc/hook_' . $location . '.inc.php';
if (file_exists($f))
{
include($f);
}
}
}
}
echo '$'."GLOBALS['phpgw']common->hook()".' has been replaced. Please change to the new $'."GLOBALS['phpgw']hooks->process()".'. For now this will act as a wrapper<br>';
return $GLOBALS['phpgw']->hooks->process($location, $order, $no_permission_check);
}
/*!
@function hook_single
@abstract call the hooks for a single application
@param $location hook location - required
@param $appname application name - optional
@abstract temp wrapper to new hooks class
*/
// Note: $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo)
function hook_single($location, $appname = '', $no_permission_check = False)
{
if (! $appname)
{
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
}
$SEP = filesystem_separator();
/* First include the ordered apps hook file */
$f = PHPGW_SERVER_ROOT . $SEP . $appname . $SEP . 'inc' . $SEP . 'hook_' . $location . '.inc.php';
if (file_exists($f) &&
( $GLOBALS['phpgw_info']['user']['apps'][$appname] || (($no_permission_check || $location == 'config' || $appname == 'phpgwapi') && $appname)) )
{
include($f);
return True;
}
else
{
return False;
}
echo '$'."GLOBALS['phpgw']common->hook_single()".' has been replaced. Please change to the new $'."GLOBALS['phpgw']hooks->single()".'. For now this will act as a wrapper<br>';
return $GLOBALS['phpgw']->hooks->single($location, $order, $no_permission_check);
}
/*!
@function hook_count
@abstract loop through the applications and count the hooks
@abstract temp wrapper to new hooks class
*/
function hook_count($location)
{
$count = 0;
reset($GLOBALS['phpgw_info']['user']['apps']);
$SEP = filesystem_separator();
while ($permission = each($GLOBALS['phpgw_info']['user']['apps']))
{
$f = PHPGW_SERVER_ROOT . $SEP . $permission[0] . $SEP . 'inc' . $SEP . 'hook_' . $location . '.inc.php';
if (file_exists($f))
{
++$count;
}
}
return $count;
echo '$'."GLOBALS['phpgw']common->hook_count()".' has been replaced. Please change to the new $'."GLOBALS['phpgw']hooks->count()".'. For now this will act as a wrapper<br>';
return $GLOBALS['phpgw']->hooks->count($location);
}
/* Wrapper to the session->appsession() */

View File

@ -31,26 +31,125 @@
@package phpgwapi
@access public
*/
class hooks
{
/*!
@function read()
@abstract currently not being used
*/
function read()
var $found_hooks = Array();
function hooks()
{
$db = $GLOBALS['phpgw']->db;
$db->query('select * from phpgw_hooks');
while ($db->next_record())
//$GLOBALS['phpgw']->db->query("SELECT hook_appname, hook_location, hook_filename FROM phpgw_hooks WHERE hook_location='".$location."'",__LINE__,__FILE__);
$GLOBALS['phpgw']->db->query("SELECT hook_appname, hook_location, hook_filename FROM phpgw_hooks",__LINE__,__FILE__);
while( $GLOBALS['phpgw']->db->next_record() )
{
$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');
$this->found_hooks[$GLOBALS['phpgw']->db->f('hook_appname')][$GLOBALS['phpgw']->db->f('hook_location')] = $GLOBALS['phpgw']->db->f('hook_filename');
}
if(isset($return_array))
//echo '<pre>';
//print_r($this->found_hooks);
//echo '</pre>';
}
/*!
@function process
@abstract loads up all the hooks the user has rights to
@discussion Someone flesh this out please
*/
// Note: $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo)
function process($location, $order = '', $no_permission_check = False)
{
$SEP = filesystem_separator();
if ($order == '')
{
return $return_array;
settype($order,'array');
$order[] = $GLOBALS['phpgw_info']['flags']['currentapp'];
}
/* First include the ordered apps hook file */
reset ($order);
while (list(,$appname) = each($order))
{
if (isset($this->found_hooks[$appname][$location]))
{
$f = PHPGW_SERVER_ROOT . $SEP . $appname . $SEP . 'inc' . $SEP . $this->found_hooks[$appname][$location];
if (file_exists($f) &&
( $GLOBALS['phpgw_info']['user']['apps'][$appname] || (($no_permission_check || $appname == 'preferences') && $appname)) )
{
include($f);
}
}
$completed_hooks[$appname] = True;
}
/* Then add the rest */
if ($no_permission_check)
{
reset($GLOBALS['phpgw_info']['apps']);
while (list(,$p) = each($GLOBALS['phpgw_info']['apps']))
{
$appname = $p['name'];
if (! isset($completed_hooks[$appname]) || $completed_hooks[$appname] != True)
{
if (isset($this->found_hooks[$appname][$location]))
{
$f = PHPGW_SERVER_ROOT . $SEP . $appname . $SEP . 'inc' . $SEP . $this->found_hooks[$appname][$location];
if (file_exists($f))
{
include($f);
}
}
}
}
}
else
{
reset ($GLOBALS['phpgw_info']['user']['apps']);
while (list(,$p) = each($GLOBALS['phpgw_info']['user']['apps']))
{
$appname = $p['name'];
if (! isset($completed_hooks[$appname]) || $completed_hooks[$appname] != True)
{
if (isset($this->found_hooks[$appname][$location]))
{
$f = PHPGW_SERVER_ROOT . $SEP . $appname . $SEP . 'inc' . $SEP . $this->found_hooks[$appname][$location];
if (file_exists($f))
{
include($f);
}
}
}
}
}
}
/*!
@function single
@abstract call the hooks for a single application
@param $location hook location - required
@param $appname application name - optional
*/
// Note: $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo)
function single($location, $appname = '', $no_permission_check = False)
{
if (! $appname)
{
$appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
}
$SEP = filesystem_separator();
/* First include the ordered apps hook file */
if (isset($this->found_hooks[$appname][$location]))
{
$f = PHPGW_SERVER_ROOT . $SEP . $appname . $SEP . 'inc' . $SEP . $this->found_hooks[$appname][$location];
if (file_exists($f) &&
( $GLOBALS['phpgw_info']['user']['apps'][$appname] || (($no_permission_check || $location == 'config' || $appname == 'phpgwapi') && $appname)) )
{
include($f);
return True;
}
else
{
return False;
}
}
else
{
@ -59,55 +158,36 @@
}
/*!
@function process
@abstract process the hooks
@discussion not currently being used
@param \$type
@param \$where
@function count
@abstract loop through the applications and count the hooks
*/
function process($type,$where='')
function count($location)
{
$currentapp = $GLOBALS['phpgw_info']['flags']['currentapp'];
$type = strtolower($type);
if ($type != 'location' && $type != 'app')
$count = 0;
reset($GLOBALS['phpgw_info']['user']['apps']);
$SEP = filesystem_separator();
while ($permission = each($GLOBALS['phpgw_info']['user']['apps']))
{
return False;
}
// Add a check to see if that location/app has a hook
// This way it doesn't have to loop everytime
while ($hook = each($GLOBALS['phpgw_info']['hooks']))
{
if ($type == 'app')
if (isset($this->found_hooks[$permission[0]][$location]))
{
if ($hook[1]['app'] == $currentapp)
{
$include_file = $GLOBALS['phpgw_info']['server']['server_root'] . '/'
. $currentapp . '/hooks/'
. $hook[1]['app'] . $hook[1]['filename'];
include($include_file);
}
}
elseif ($type == "location")
{
if ($hook[1]["location"] == $where)
{
$include_file = $GLOBALS['phpgw_info']['server']['server_root'] . '/'
. $hook[1]['app'] . '/hooks/'
. $hook[1]['filename'];
if (! is_file($include_file))
{
$GLOBALS['phpgw']->common->phpgw_error('Failed to include hook: ' . $include_file);
}
else
{
include($include_file);
}
}
++$count;
}
}
return $count;
}
/*!
@function read()
@abstract currently not being used
*/
function read()
{
//if (!is_array($this->found_hooks))
//{
$this->hooks();
//}
return $this->found_hooks;
}
}
?>

View File

@ -120,7 +120,7 @@
$GLOBALS[$class]->header();
}
}
$GLOBALS['phpgw']->common->hook('after_navbar');
$GLOBALS['phpgw']->hooks->process('after_navbar');
return;
}
@ -142,7 +142,7 @@
'version' => $GLOBALS['phpgw_info']['server']['versions']['phpgwapi']
);
$tpl->set_var($var);
$GLOBALS['phpgw']->common->hook('navbar_end');
$GLOBALS['phpgw']->hooks->process('navbar_end');
$tpl->pfp('out','footer');
}
}

View File

@ -212,7 +212,7 @@
$GLOBALS[$class]->header();
}
}
$GLOBALS['phpgw']->common->hook('after_navbar');
$GLOBALS['phpgw']->hooks->process('after_navbar');
return;
}
@ -241,6 +241,6 @@
$tpl->set_var('V_powered_bottom','');
}
$GLOBALS['phpgw']->common->hook('navbar_end');
$GLOBALS['phpgw']->hooks->process('navbar_end');
$tpl->pfp('out','footer');
}

View File

@ -113,6 +113,21 @@
$var['messages'] = $api_messages . "<br>" . checkcode($cd);
}
*/
/*
function display_section($appname,$title,$file)
{
$GLOBALS['prefs'][$appname]['title'] = $title;
$GLOBALS['prefs'][$appname]['file'][] = $file;
}
$temp_common = CreateObject('phpgwapi.common');
$temp_hooks->process('preferences',array('preferences'));
*/
// echo '>prefs<pre>';
// print_r($GLOBALS['prefs']);
// echo '</pre>';
$tpl->set_var($var);
$tpl->pfp('out','navbar');
// If the application has a header include, we now include it
@ -124,7 +139,7 @@
$GLOBALS[$class]->header();
}
}
$GLOBALS['phpgw']->common->hook('after_navbar');
$GLOBALS['phpgw']->hooks->process('after_navbar');
return;
}
@ -147,6 +162,6 @@
. $GLOBALS['phpgw']->common->show_date(time(),'d, Y')
);
$tpl->set_var($var);
$GLOBALS['phpgw']->common->hook('navbar_end');
$GLOBALS['phpgw']->hooks->process('navbar_end');
echo $tpl->pfp('out','footer');
}

View File

@ -133,7 +133,7 @@
$GLOBALS[$class]->header();
}
}
$GLOBALS['phpgw']->common->hook('after_navbar');
$GLOBALS['phpgw']->hooks->process('after_navbar');
return;
}
@ -162,6 +162,6 @@
$tpl->set_var('V_powered_bottom','');
}
$GLOBALS['phpgw']->common->hook('navbar_end');
$GLOBALS['phpgw']->hooks->process('navbar_end');
$tpl->pfp('out','footer');
}

View File

@ -131,7 +131,7 @@
$GLOBALS[$class]->header();
}
}
$GLOBALS['phpgw']->common->hook('after_navbar');
$GLOBALS['phpgw']->hooks->process('after_navbar');
return;
}
@ -150,6 +150,6 @@
'version' => $GLOBALS['phpgw_info']['server']['versions']['phpgwapi']
);
$tpl->set_var($var);
$GLOBALS['phpgw']->common->hook('navbar_end');
$GLOBALS['phpgw']->hooks->process('navbar_end');
echo $tpl->pfp('out','footer');
}

View File

@ -133,7 +133,7 @@
section_end();
}
$phpgw->common->hook('preferences',array('preferences'));
$phpgw->hooks->process('preferences',array('preferences'));
$pref_tpl->pfp('out','list');
$phpgw->common->phpgw_footer();
?>

View File

@ -292,14 +292,14 @@
if ($GLOBALS['HTTP_GET_VARS']['appname'] == 'preferences')
{
if (! $GLOBALS['phpgw']->common->hook_single('settings','preferences',True))
if (! $GLOBALS['phpgw']->hooks->single('settings','preferences',True))
{
$error = True;
}
}
else
{
if (! $GLOBALS['phpgw']->common->hook_single('settings',$GLOBALS['HTTP_GET_VARS']['appname']))
if (! $GLOBALS['phpgw']->hooks->single('settings',$GLOBALS['HTTP_GET_VARS']['appname']))
{
$error = True;
}

View File

@ -176,7 +176,7 @@
$t->set_var('row_off', 'EEEEEE');
$vars = $t->get_undefined('body');
$GLOBALS['phpgw']->common->hook_single('config',$cfg_app);
$GLOBALS['phpgw']->hooks->single('config',$cfg_app);
while (list($null,$value) = each($vars))
{

View File

@ -326,7 +326,7 @@
@reset($s_apps);
while (list($key,$app) = each($s_apps))
{
$phpgw->common->hook_single('add_def_pref',$app);
$phpgw->hooks->single('add_def_pref',$app);
}
$pref->save_repository();
}