From 58a99c97cadd6a16b138e4de4f8fd1aa172e4eed Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 20:54:01 +0100 Subject: [feature/event-dispatcher] Add a sample hook in page_header PHPBB3-9550 --- phpBB/includes/functions.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 753795b7cf..03376bf906 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4461,6 +4461,7 @@ function phpbb_http_login($param) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; + global $phpbb_dispatcher; if (defined('HEADER_INC')) { @@ -4744,6 +4745,9 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); + $event = new phpbb_event(); + $phpbb_dispatcher->dispatch('page_header', $event); + // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From 03be9761375a082c2a43aceaa1b34661f87d702b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 21:42:19 +0100 Subject: [feature/event-dispatcher] Support setting data on an event PHPBB3-9550 --- phpBB/includes/functions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 03376bf906..109f5b0366 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4745,7 +4745,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); - $event = new phpbb_event(); + $event = new phpbb_event_data(); + $event->set_data(compact('page_title', 'display_online_list', 'item_id', 'item')); $phpbb_dispatcher->dispatch('page_header', $event); // application/xhtml+xml not used because of IE -- cgit v1.2.1 From 80f6f2b96f1ef0c3a3bf5637cac85a3c1fa229db Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 21:50:16 +0100 Subject: [feature/event-dispatcher] Prefix event name with 'core.' PHPBB3-9550 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 109f5b0366..45958d1a0d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4747,7 +4747,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $event = new phpbb_event_data(); $event->set_data(compact('page_title', 'display_online_list', 'item_id', 'item')); - $phpbb_dispatcher->dispatch('page_header', $event); + $phpbb_dispatcher->dispatch('core.page_header', $event); // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From 43899ffdf3e36cf2d107bf5a09c5f37faffdf3c2 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 3 Feb 2012 02:25:32 -0500 Subject: [feature/event-dispatcher] Implement mutation for page_header ledge. PHPBB3-9550 --- phpBB/includes/functions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 024fa612f0..bd7ed71dcb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4762,9 +4762,10 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); - $event = new phpbb_event_data(); - $event->set_data(compact('page_title', 'display_online_list', 'item_id', 'item')); + $vars = array('page_title', 'display_online_list', 'item_id', 'item'); + $event = new phpbb_event_data(compact($vars)); $phpbb_dispatcher->dispatch('core.page_header', $event); + extract($event->get_data_filtered($vars)); // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From 0d6a5cb6ae29348a247c8f42e2046c8b84741aa5 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 30 Mar 2012 11:02:48 +0100 Subject: [feature/event-dispatcher] Update core.page_header event Update it to the new correct format. PHPBB3-9550 --- phpBB/includes/functions.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index bd7ed71dcb..7a96dd3609 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4763,9 +4763,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 )); $vars = array('page_title', 'display_online_list', 'item_id', 'item'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.page_header', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From d420ceb9c717b83ba29dde3734b563881051e51a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 14 Jul 2011 13:33:42 +0100 Subject: [ticket/10270] Added JavaScript popups and basic AJAX functionality to PHP. This commit adds the phpbb object (JavaScript), and alert and confirm box methods. It also adds the first basic AJAX functionality, to deleting posts in viewtopic. PHPBB3-10270 --- phpBB/includes/functions.php | 53 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7a96dd3609..572986bb4b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2448,15 +2448,25 @@ function build_url($strip_vars = false) */ function meta_refresh($time, $url, $disable_cd_check = false) { - global $template; + global $template, $refresh_data; - $url = redirect($url, true, $disable_cd_check); - $url = str_replace('&', '&', $url); + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + $refresh_data = array( + 'time' => $time, + 'url' => str_replace('&', '&', $url) + ); + } + else + { + $url = redirect($url, true, $disable_cd_check); + $url = str_replace('&', '&', $url); - // For XHTML compatibility we change back & to & - $template->assign_vars(array( - 'META' => '') - ); + // For XHTML compatibility we change back & to & + $template->assign_vars(array( + 'META' => '') + ); + } return $url; } @@ -2699,6 +2709,21 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo WHERE user_id = " . $user->data['user_id']; $db->sql_query($sql); + + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; + echo json_encode(array( + 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title], + 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], + + 'YES_VALUE' => $user->lang['YES'], + 'S_CONFIRM_ACTION' => str_replace('&', '&', $u_action), //inefficient, rewrite whole function + 'S_HIDDEN_FIELDS' => $hidden . $s_hidden_fields + )); + exit; + } + if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) { adm_page_footer(); @@ -3922,6 +3947,20 @@ function msg_handler($errno, $msg_text, $errfile, $errline) 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false) ); + if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + global $refresh_data; + + echo json_encode(array( + 'MESSAGE_TITLE' => $msg_title, + 'MESSAGE_TEXT' => $msg_text, + 'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false, + 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false, + 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null + )); + exit; + } + // We do not want the cron script to be called on error messages define('IN_CRON', true); -- cgit v1.2.1 From 94172b54dd09b28e19b4b12933b3f96e498d264a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 19 Aug 2011 09:38:57 +0100 Subject: [ticket/10271] Changed AJAX functions to $request->is_ajax(). PHPBB3-10271 --- phpBB/includes/functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 572986bb4b..b126fcc709 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2448,9 +2448,9 @@ function build_url($strip_vars = false) */ function meta_refresh($time, $url, $disable_cd_check = false) { - global $template, $refresh_data; + global $template, $refresh_data, $request; - if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { $refresh_data = array( 'time' => $time, @@ -2629,7 +2629,7 @@ function check_form_key($form_name, $timespan = false, $return_page = '', $trigg */ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_body.html', $u_action = '') { - global $user, $template, $db; + global $user, $template, $db, $request; global $phpEx, $phpbb_root_path, $request; if (isset($_POST['cancel'])) @@ -2710,7 +2710,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo $db->sql_query($sql); - if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; echo json_encode(array( @@ -3748,7 +3748,7 @@ function phpbb_checkdnsrr($host, $type = 'MX') */ function msg_handler($errno, $msg_text, $errfile, $errline) { - global $cache, $db, $auth, $template, $config, $user; + global $cache, $db, $auth, $template, $config, $user, $request; global $phpEx, $phpbb_root_path, $msg_title, $msg_long_text; // Do not display notices if we suppress them via @ @@ -3947,7 +3947,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false) ); - if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { global $refresh_data; -- cgit v1.2.1 From dce38f44de04bd7a1f91f8e57f6d266bd5e1af86 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 19 Aug 2011 10:45:03 +0100 Subject: [ticket/10328] Added a JSON class. The JSON class adds a consistent way to send JSON to the client, making it perfect for AJAX (jQuery automatically parses it). PHPBB3-10328 --- phpBB/includes/functions.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b126fcc709..b9ca30279f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2713,7 +2713,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo if ($request->is_ajax()) { $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; - echo json_encode(array( + JSON::send(array( 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title], 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], @@ -2721,7 +2721,6 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo 'S_CONFIRM_ACTION' => str_replace('&', '&', $u_action), //inefficient, rewrite whole function 'S_HIDDEN_FIELDS' => $hidden . $s_hidden_fields )); - exit; } if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) @@ -3951,14 +3950,13 @@ function msg_handler($errno, $msg_text, $errfile, $errline) { global $refresh_data; - echo json_encode(array( + JSON::send(array( 'MESSAGE_TITLE' => $msg_title, 'MESSAGE_TEXT' => $msg_text, 'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false, 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false, 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null )); - exit; } // We do not want the cron script to be called on error messages -- cgit v1.2.1 From 7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 12:25:54 +0100 Subject: [ticket/10328] Renamed the JSON class, also now using autoloading. It is no longer static, and uses autoloading. It has also been renamed from JSON to phpbb_json_response. PHPBB3-10328 --- phpBB/includes/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b9ca30279f..afd901a296 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2713,7 +2713,8 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo if ($request->is_ajax()) { $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; - JSON::send(array( + $json_response = new phpbb_json_response; + $json_response->send(array( 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title], 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], @@ -3950,7 +3951,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline) { global $refresh_data; - JSON::send(array( + $json_response = new phpbb_json_response; + $json_response->send(array( 'MESSAGE_TITLE' => $msg_title, 'MESSAGE_TEXT' => $msg_text, 'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false, -- cgit v1.2.1