This may be an interesting approach for internal functionality and trying to be consistent

git-svn-id: file:///svn/phpbb/trunk@9278 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2009-01-19 15:23:43 +00:00
parent 5a263f76a9
commit abee782518
3 changed files with 95 additions and 115 deletions

View file

@ -59,6 +59,13 @@ $mode = request_var('mode', '');
phpbb::$template->set_custom_template(PHPBB_ADMIN_PATH . 'style', 'admin'); phpbb::$template->set_custom_template(PHPBB_ADMIN_PATH . 'style', 'admin');
phpbb::$template->assign_var('T_TEMPLATE_PATH', PHPBB_ADMIN_PATH . 'style'); phpbb::$template->assign_var('T_TEMPLATE_PATH', PHPBB_ADMIN_PATH . 'style');
// Define page header/footer to use
phpbb::$plugins->register_function('page_header', 'adm_page_header', phpbb::FUNCTION_OVERRIDE);
phpbb::$plugins->register_function('page_footer', 'adm_page_footer', phpbb::FUNCTION_OVERRIDE);
// And make the calls available
phpbb::$plugins->setup();
// Instantiate new module // Instantiate new module
$module = new p_master(); $module = new p_master();
@ -76,13 +83,13 @@ $module->assign_tpl_vars(phpbb::$url->append_sid(PHPBB_ADMIN_PATH . 'index.' . P
$module->load_active(); $module->load_active();
// Generate the page // Generate the page
adm_page_header($module->get_page_title()); page_header($module->get_page_title());
phpbb::$template->set_filenames(array( phpbb::$template->set_filenames(array(
'body' => $module->get_tpl_name(), 'body' => $module->get_tpl_name(),
)); ));
adm_page_footer(); page_footer();
/** /**
* Header for acp pages * Header for acp pages

View file

@ -1305,14 +1305,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo
// generate activation key // generate activation key
$confirm_key = gen_rand_string(10); $confirm_key = gen_rand_string(10);
if (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin'])
{
adm_page_header((!isset(phpbb::$user->lang[$title])) ? phpbb::$user->lang['CONFIRM'] : phpbb::$user->lang[$title]);
}
else
{
page_header((!isset(phpbb::$user->lang[$title])) ? phpbb::$user->lang['CONFIRM'] : phpbb::$user->lang[$title]); page_header((!isset(phpbb::$user->lang[$title])) ? phpbb::$user->lang['CONFIRM'] : phpbb::$user->lang[$title]);
}
$template->set_filenames(array( $template->set_filenames(array(
'body' => $html_body) 'body' => $html_body)
@ -1343,14 +1336,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo
WHERE user_id = " . phpbb::$user->data['user_id']; WHERE user_id = " . phpbb::$user->data['user_id'];
phpbb::$db->sql_query($sql); phpbb::$db->sql_query($sql);
if (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin'])
{
adm_page_footer();
}
else
{
page_footer(); page_footer();
}
} }
/** /**
@ -1358,10 +1344,6 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo
*/ */
function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = false, $s_display = true) function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = false, $s_display = true)
{ {
global $template, $auth;
include(PHPBB_ROOT_PATH . 'includes/captcha/captcha_factory.' . PHP_EXT);
$err = ''; $err = '';
// Make sure user->setup() has been called // Make sure user->setup() has been called
@ -1370,23 +1352,17 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
phpbb::$user->setup(); phpbb::$user->setup();
} }
if (defined('ADMIN_START'))
{
// Set custom template for admin area
$template->set_custom_template(PHPBB_ADMIN_PATH . 'style', 'admin');
$template->assign_var('T_TEMPLATE_PATH', PHPBB_ADMIN_PATH . 'style');
}
// Print out error if user tries to authenticate as an administrator without having the privileges... // Print out error if user tries to authenticate as an administrator without having the privileges...
if ($admin && !$auth->acl_get('a_')) if ($admin && !phpbb::$acl->acl_get('a_'))
{ {
// Not authd // Not authd
// anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions // anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions
if (phpbb::$user->data['is_registered']) if (phpbb::$user->is_registered)
{ {
add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
} }
trigger_error('NO_AUTH_ADMIN');
$admin = false;
} }
if (phpbb_request::is_set_post('login')) if (phpbb_request::is_set_post('login'))
@ -1398,10 +1374,11 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
if (strspn($credential, 'abcdef0123456789') !== strlen($credential) || strlen($credential) != 32) if (strspn($credential, 'abcdef0123456789') !== strlen($credential) || strlen($credential) != 32)
{ {
if (phpbb::$user->data['is_registered']) if (phpbb::$user->is_registered)
{ {
add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
} }
trigger_error('NO_AUTH_ADMIN'); trigger_error('NO_AUTH_ADMIN');
} }
@ -1441,7 +1418,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
{ {
// Only log the failed attempt if a real user tried to. // Only log the failed attempt if a real user tried to.
// anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions // anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions
if (phpbb::$user->data['is_registered']) if (phpbb::$user->is_registered)
{ {
add_log('admin', 'LOG_ADMIN_AUTH_FAIL'); add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
} }
@ -1451,9 +1428,10 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
// The result parameter is always an array, holding the relevant information... // The result parameter is always an array, holding the relevant information...
if ($result['status'] == LOGIN_SUCCESS) if ($result['status'] == LOGIN_SUCCESS)
{ {
$redirect = request_var('redirect', PHPBB_ROOT_PATH . 'index.' . PHP_EXT); $redirect = request_var('redirect', phpbb::$user->page['page']);
$message = ($l_success) ? $l_success : phpbb::$user->lang['LOGIN_REDIRECT']; $message = ($l_success) ? $l_success : phpbb::$user->lang['LOGIN_REDIRECT'];
$l_redirect = ($admin) ? phpbb::$user->lang['PROCEED_TO_ACP'] : (($redirect === PHPBB_ROOT_PATH . 'index.' . PHP_EXT || $redirect === "index." . PHP_EXT) ? phpbb::$user->lang['RETURN_INDEX'] : phpbb::$user->lang['RETURN_PAGE']); $l_redirect = ($admin) ? phpbb::$user->lang['PROCEED_TO_ACP'] : (($redirect === PHPBB_ROOT_PATH . 'index.' . PHP_EXT || $redirect === 'index.' . PHP_EXT) ? phpbb::$user->lang['RETURN_INDEX'] : phpbb::$user->lang['RETURN_PAGE']);
// append/replace SID (may change during the session for AOL users) // append/replace SID (may change during the session for AOL users)
$redirect = phpbb::$url->reapply_sid($redirect); $redirect = phpbb::$url->reapply_sid($redirect);
@ -1464,7 +1442,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
return; return;
} }
$redirect = phpbb::$url->meta_refresh(3, $redirect); // $redirect = phpbb::$url->meta_refresh(3, $redirect);
trigger_error($message . '<br /><br />' . sprintf($l_redirect, '<a href="' . $redirect . '">', '</a>')); trigger_error($message . '<br /><br />' . sprintf($l_redirect, '<a href="' . $redirect . '">', '</a>'));
} }
@ -1531,7 +1509,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
} }
// Assign credential for username/password pair // Assign credential for username/password pair
$credential = ($admin) ? md5(unique_id()) : false; $credential = ($admin) ? md5(phpbb::$security->unique_id()) : false;
$s_hidden_fields = array( $s_hidden_fields = array(
'redirect' => $redirect, 'redirect' => $redirect,
@ -1545,17 +1523,17 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
$s_hidden_fields = build_hidden_fields($s_hidden_fields); $s_hidden_fields = build_hidden_fields($s_hidden_fields);
$template->assign_vars(array( phpbb::$template->assign_vars(array(
'LOGIN_ERROR' => $err, 'LOGIN_ERROR' => $err,
'LOGIN_EXPLAIN' => $l_explain, 'LOGIN_EXPLAIN' => $l_explain,
'U_SEND_PASSWORD' => (phpbb::$config['email_enable']) ? append_sid('ucp', 'mode=sendpassword') : '', 'U_SEND_PASSWORD' => (phpbb::$config['email_enable']) ? phpbb::$url->append_sid('ucp', 'mode=sendpassword') : '',
'U_RESEND_ACTIVATION' => (phpbb::$config['require_activation'] != USER_ACTIVATION_NONE && phpbb::$config['email_enable']) ? append_sid('ucp', 'mode=resend_act') : '', 'U_RESEND_ACTIVATION' => (phpbb::$config['require_activation'] != USER_ACTIVATION_NONE && phpbb::$config['email_enable']) ? phpbb::$url->append_sid('ucp', 'mode=resend_act') : '',
'U_TERMS_USE' => append_sid('ucp', 'mode=terms'), 'U_TERMS_USE' => phpbb::$url->append_sid('ucp', 'mode=terms'),
'U_PRIVACY' => append_sid('ucp', 'mode=privacy'), 'U_PRIVACY' => phpbb::$url->append_sid('ucp', 'mode=privacy'),
'S_DISPLAY_FULL_LOGIN' => ($s_display) ? true : false, 'S_DISPLAY_FULL_LOGIN' => ($s_display) ? true : false,
'S_LOGIN_ACTION' => (!$admin && !defined('ADMIN_START')) ? append_sid('ucp', 'mode=login') : append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, false, true, phpbb::$user->session_id), 'S_LOGIN_ACTION' => (!$admin && !defined('ADMIN_START')) ? phpbb::$url->append_sid('ucp', 'mode=login') : phpbb::$url->append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, false, true, phpbb::$user->session_id),
'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_ADMIN_AUTH' => $admin, 'S_ADMIN_AUTH' => $admin,
@ -1566,36 +1544,14 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
'PASSWORD_CREDENTIAL' => ($admin) ? 'password_' . $credential : 'password', 'PASSWORD_CREDENTIAL' => ($admin) ? 'password_' . $credential : 'password',
)); ));
if (defined('ADMIN_START')) phpbb::$template->set_filenames(array(
{
$template->set_filenames(array(
'body' => 'acp_login.html')
);
$template->assign_block_vars('t_block1', array(
'L_TITLE' => phpbb::$user->lang['LOGIN'],
'S_SELECTED' => true,
'U_TITLE' => '',
));
adm_page_header(phpbb::$user->lang['LOGIN'], false);
}
else
{
$template->set_filenames(array(
'body' => 'login_body.html') 'body' => 'login_body.html')
); );
page_header(phpbb::$user->lang['LOGIN'], false); page_header(phpbb::$user->lang['LOGIN'], false);
} make_jumpbox('viewforum');
make_jumpbox(append_sid('viewforum'));
if (defined('ADMIN_START') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin'])
{
adm_page_footer();
}
else
{
page_footer(); page_footer();
}
} }
/** /**
@ -2212,16 +2168,9 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
$msg_title = (!isset($msg_title)) ? phpbb::$user->lang['INFORMATION'] : ((!empty(phpbb::$user->lang[$msg_title])) ? phpbb::$user->lang[$msg_title] : $msg_title); $msg_title = (!isset($msg_title)) ? phpbb::$user->lang['INFORMATION'] : ((!empty(phpbb::$user->lang[$msg_title])) ? phpbb::$user->lang[$msg_title] : $msg_title);
if (!defined('HEADER_INC')) if (!defined('HEADER_INC'))
{
if (defined('ADMIN_START') || (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin']))
{
adm_page_header($msg_title);
}
else
{ {
page_header($msg_title); page_header($msg_title);
} }
}
phpbb::$template->set_filenames(array( phpbb::$template->set_filenames(array(
'body' => 'message_body.html') 'body' => 'message_body.html')
@ -2237,14 +2186,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
// We do not want the cron script to be called on error messages // We do not want the cron script to be called on error messages
define('IN_CRON', true); define('IN_CRON', true);
if (defined('ADMIN_START') || (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin']))
{
adm_page_footer();
}
else
{
page_footer(); page_footer();
}
exit_handler(); exit_handler();
break; break;
@ -2298,6 +2240,7 @@ function page_header($page_title = '', $display_online_list = true)
// Get users online list ... if required // Get users online list ... if required
$online_userlist = array(); $online_userlist = array();
$l_online_users = $l_online_record = '';
$forum = request_var('f', 0); $forum = request_var('f', 0);
if (phpbb::$config['load_online'] && phpbb::$config['load_online_time'] && $display_online_list) if (phpbb::$config['load_online'] && phpbb::$config['load_online_time'] && $display_online_list)

View file

@ -132,6 +132,16 @@ class phpbb_plugins
*/ */
private $current_plugin = false; private $current_plugin = false;
/**
* Plugins/Functions already set up
*/
private $already_parsed_plugins = array();
/**
* @var array Collection of assigned functions and their params (merged from plugins and custom additions)
*/
private $functions = array();
/** /**
* Init plugins * Init plugins
* *
@ -159,6 +169,8 @@ class phpbb_plugins
} }
closedir($dh); closedir($dh);
} }
$this->already_parsed_plugins = array('plugin' => array(), 'hook' => array());
} }
/** /**
@ -196,13 +208,13 @@ class phpbb_plugins
*/ */
public function setup() public function setup()
{ {
if (empty($this->plugins))
{
return false;
}
foreach ($this->plugins as $name => $plugin) foreach ($this->plugins as $name => $plugin)
{ {
if (isset($this->already_parsed_plugins['plugin'][$name]))
{
continue;
}
// Add includes // Add includes
foreach ($plugin->includes as $file) foreach ($plugin->includes as $file)
{ {
@ -244,10 +256,16 @@ class phpbb_plugins
// Setup/Register plugin... // Setup/Register plugin...
$object->setup_plugin($instance); $object->setup_plugin($instance);
} }
}
// Now setup hooks... this is a special case... // Now setup hooks... this is a special case...
foreach ($plugin->functions as $params) foreach ($this->functions as $key => $params)
{ {
if (isset($this->already_parsed_plugins['hook'][$key]))
{
continue;
}
$function = array_shift($params); $function = array_shift($params);
$hook = array_shift($params); $hook = array_shift($params);
$mode = (!empty($params)) ? array_shift($params) : phpbb::FUNCTION_INJECT; $mode = (!empty($params)) ? array_shift($params) : phpbb::FUNCTION_INJECT;
@ -267,6 +285,16 @@ class phpbb_plugins
{ {
$this->hooks[$function][$mode][$action][] = $hook; $this->hooks[$function][$mode][$action][] = $hook;
} }
$this->already_parsed_plugins['hook'][$key] = true;
}
// Init method call and setting as finished
foreach ($this->plugins as $name => $plugin)
{
if (isset($this->already_parsed_plugins['plugin'][$name]))
{
continue;
} }
// Call plugins init method? // Call plugins init method?
@ -274,6 +302,8 @@ class phpbb_plugins
{ {
$plugin->setup->init(); $plugin->setup->init();
} }
$this->already_parsed_plugins['plugin'][$name] = true;
} }
} }
@ -332,7 +362,7 @@ class phpbb_plugins
public function register_function() public function register_function()
{ {
$arguments = func_get_args(); $arguments = func_get_args();
$this->current_plugin->functions[] = $arguments; $this->current_plugin->functions[] = $this->functions[] = $arguments;
} }
/** /**