diff options
author | Callum Macrae <callum@lynxphp.com> | 2011-07-14 13:33:42 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-03-31 02:00:22 +0200 |
commit | d420ceb9c717b83ba29dde3734b563881051e51a (patch) | |
tree | 9edac83794c76485d758ce60ad5a5327096deee4 /phpBB/includes/functions.php | |
parent | 4f97cc12951b2be6fa8d7962beaf631f7c82fb43 (diff) | |
download | forums-d420ceb9c717b83ba29dde3734b563881051e51a.tar forums-d420ceb9c717b83ba29dde3734b563881051e51a.tar.gz forums-d420ceb9c717b83ba29dde3734b563881051e51a.tar.bz2 forums-d420ceb9c717b83ba29dde3734b563881051e51a.tar.xz forums-d420ceb9c717b83ba29dde3734b563881051e51a.zip |
[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
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r-- | phpBB/includes/functions.php | 53 |
1 files changed, 46 insertions, 7 deletions
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' => '<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '" />') - ); + // For XHTML compatibility we change back & to & + $template->assign_vars(array( + 'META' => '<meta http-equiv="refresh" content="' . $time . ';url=' . $url . '" />') + ); + } 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); |