From d420ceb9c717b83ba29dde3734b563881051e51a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 14 Jul 2011 13:33:42 +0100 Subject: [PATCH 001/120] [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 ++++++++++-- .../prosilver/template/overall_footer.html | 3 + phpBB/styles/prosilver/theme/common.css | 30 ++++++- phpBB/styles/script.js | 80 +++++++++++++++++++ 4 files changed, 158 insertions(+), 8 deletions(-) create mode 100644 phpBB/styles/script.js 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); diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index 4456d6b37d..0d2fd4d27a 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -24,6 +24,9 @@
{DEBUG_OUTPUT}
{L_ACP} + + + diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 27a55caf7a..5cf12be1ce 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -468,7 +468,7 @@ table.info tbody th { /* Misc layout styles ---------------------------------------- */ -/* column[1-2] styles are containers for two column layouts +/* column[1-2] styles are containers for two column layouts Also see tweaks.css */ .column1 { float: left; @@ -580,6 +580,34 @@ li.pagination { background: none 0 50% no-repeat; } +.row .pagination span a, li.pagination span a { + background-color: #FFFFFF; +} + +.row .pagination span a:hover, li.pagination span a:hover { + background-color: #d2d2d2; +} + +/* jQuery popups +---------------------------------------- */ +.jalert { + background-color: #FFFFFF; + border: 1px solid #999999; + display: none; + position: fixed; + top: 100px; + left: 35%; + width: 30%; + z-index: 50; + padding: 25px; + padding: 0 25px 20px 25px; +} + +.jalert p { + margin: 8px 0; + padding-bottom: 8px; +} + /* Miscellaneous styles ---------------------------------------- */ #forum-permissions { diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js new file mode 100644 index 0000000000..9be3efd4ce --- /dev/null +++ b/phpBB/styles/script.js @@ -0,0 +1,80 @@ +var phpbb = {}; + +/** + * Display a simple alert. + * + * @param string title Title of the message, eg "Information" + * @param string msg Message to display. Can be HTML. + */ +phpbb.alert = function(title, msg) { + var div = $('

' + title + '

' + msg + '

'); + + $(document).bind('click', function(e) { + if ($(e.target).parents('.jalert').length) + { + return true; + } + div.hide(300, function() { + div.remove(); + }); + return false; + }); + + $('body').append(div); + div.show(300); +} + +/** + * Display a simple yes / no box to the user. + * + * @param string msg Message to display. Can be HTML. + * @param function callback Callback. + */ +phpbb.confirm = function(msg, callback) { + var div = $('

' + msg + '

\ +  \ +
'); + + $('body').append(div); + + $('.jalertbut').bind('click', function(event) { + div.hide(300, function() { + div.remove(); + }); + callback(this.value === 'Yes'); + return false; + }); + div.show(300); +} + + + +$('.delete-icon a').click(function() +{ + var pid = this.href.split('&p=')[1]; + var __self = this; + $.get(this.href, function(res) { + res = JSON.parse(res); + phpbb.confirm(res.MESSAGE_TEXT, function(del) { + if (del) + { + var p = res.S_CONFIRM_ACTION.split('?'); + p[1] += '&confirm=Yes' + $.post(p[0], p[1], function(res) { + res = JSON.parse(res); + phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT) + $(__self).parents('div #p' + pid).remove(); + + //if there is a refresh, check that it isn't to the same place + if (res.REFRESH_DATA && res.REFRESH_DATA.url.indexOf('t=') === -1) + { + setTimeout(function() { + window.location = res.REFRESH_DATA.url; + }, res.REFRESH_DATA.time * 1000); + } + }); + } + }); + }); + return false; +}); From e6401c081e2e7543db020d16271792d715571249 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 14 Jul 2011 14:41:24 +0100 Subject: [PATCH 002/120] [ticket/10271] Added phpbb.confirm_box (JavaScript). As well as adding the method, this commit also changes the previous commit so that deleting a post from viewtopic uses this method, too. This commit has also made some improvements to phpbb.alert and phpbb.confirm. PHPBB3-10271 --- phpBB/styles/script.js | 97 ++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 27 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 9be3efd4ce..ed10375cf1 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -5,11 +5,13 @@ var phpbb = {}; * * @param string title Title of the message, eg "Information" * @param string msg Message to display. Can be HTML. + * + * @return Returns the div created. */ phpbb.alert = function(title, msg) { var div = $('

' + title + '

' + msg + '

'); - $(document).bind('click', function(e) { + $(document).one('click', function(e) { if ($(e.target).parents('.jalert').length) { return true; @@ -22,6 +24,7 @@ phpbb.alert = function(title, msg) { $('body').append(div); div.show(300); + return div; } /** @@ -29,6 +32,8 @@ phpbb.alert = function(title, msg) { * * @param string msg Message to display. Can be HTML. * @param function callback Callback. + * + * @return Returns the div created. */ phpbb.confirm = function(msg, callback) { var div = $('

' + msg + '

\ @@ -45,36 +50,74 @@ phpbb.confirm = function(msg, callback) { return false; }); div.show(300); + return div; } - -$('.delete-icon a').click(function() +/** + * This function interacts via AJAX with phpBBs confirm_box function. + * + * @param string condition The element to capture. + * @param bool/function refresh If we are sent back a refresh, should it be + * acted upon? This can either be true / false / a function. + * @param function callback Callback. + */ +phpbb.confirm_box = function(condition, refresh, callback) { - var pid = this.href.split('&p=')[1]; - var __self = this; - $.get(this.href, function(res) { - res = JSON.parse(res); - phpbb.confirm(res.MESSAGE_TEXT, function(del) { - if (del) - { - var p = res.S_CONFIRM_ACTION.split('?'); - p[1] += '&confirm=Yes' - $.post(p[0], p[1], function(res) { - res = JSON.parse(res); - phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT) - $(__self).parents('div #p' + pid).remove(); + __self = this; + $(condition).click(function() { + var __self = this; + $.get(this.href, function(res) { + res = JSON.parse(res); + phpbb.confirm(res.MESSAGE_TEXT, function(del) { + if (del) + { + var p = res.S_CONFIRM_ACTION.split('?'); + p[1] += '&confirm=Yes'; + $.post(p[0], p[1], function(res) { + res = JSON.parse(res); + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + callback(__self); - //if there is a refresh, check that it isn't to the same place - if (res.REFRESH_DATA && res.REFRESH_DATA.url.indexOf('t=') === -1) - { - setTimeout(function() { - window.location = res.REFRESH_DATA.url; - }, res.REFRESH_DATA.time * 1000); - } - }); - } + if (res.REFRESH_DATA) + { + if (typeof refresh === 'function') + { + refresh = refresh(res.REFRESH_DATA.url) + } + else if (typeof refresh !== 'boolean') + { + refresh = false; + } + + if (refresh) + { + setTimeout(function() { + window.location = res.REFRESH_DATA.url; + }, res.REFRESH_DATA.time * 1000); + } + else + { + setTimeout(function() { + div.hide(300, function() { + div.remove(); + }); + }, res.REFRESH_DATA.time * 1000); + } + } + }); + } + }); }); + return false; }); - return false; -}); +} + +var refresh = function(url) { + return (url.indexOf('t=') === -1); +} +var callback = function(el) { + var pid = el.href.split('&p=')[1]; + $(el).parents('div #p' + pid).remove(); +} +phpbb.confirm_box('.delete-icon a', refresh, callback); From 2556f5fcc2df1dc51ddd5a97859a7325809b7837 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 14 Jul 2011 14:57:45 +0100 Subject: [PATCH 003/120] [ticket/10272] AJAXified most links. This commit makes some significant changes to the phpbb.confirm_box function (namely, removing some duplicate code), and also manually adds most link to the phpBB AJAX functions. PHPBB3-10272 --- phpBB/styles/script.js | 101 +++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 25 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index ed10375cf1..ee67768469 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -53,6 +53,39 @@ phpbb.confirm = function(msg, callback) { return div; } +/** + * Clearing up some duplicate code - don't use this. + */ +function handle_refresh(data, refresh, div) +{ + if (data) + { + if (typeof refresh === 'function') + { + refresh = refresh(data.url) + } + else if (typeof refresh !== 'boolean') + { + refresh = false; + } + + if (refresh) + { + setTimeout(function() { + window.location = data.url; + }, data.time * 1000); + } + else + { + setTimeout(function() { + div.hide(300, function() { + div.remove(); + }); + }, data.time * 1000); + } + } +} + /** * This function interacts via AJAX with phpBBs confirm_box function. @@ -77,34 +110,13 @@ phpbb.confirm_box = function(condition, refresh, callback) $.post(p[0], p[1], function(res) { res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - callback(__self); - if (res.REFRESH_DATA) + if (typeof callback !== 'undefined') { - if (typeof refresh === 'function') - { - refresh = refresh(res.REFRESH_DATA.url) - } - else if (typeof refresh !== 'boolean') - { - refresh = false; - } - - if (refresh) - { - setTimeout(function() { - window.location = res.REFRESH_DATA.url; - }, res.REFRESH_DATA.time * 1000); - } - else - { - setTimeout(function() { - div.hide(300, function() { - div.remove(); - }); - }, res.REFRESH_DATA.time * 1000); - } + callback(__self); } + + handle_refresh(res.REFRESH_DATA, refresh, alert); }); } }); @@ -113,6 +125,26 @@ phpbb.confirm_box = function(condition, refresh, callback) }); } +/** + * Makes a link use AJAX instead of loading an entire page. + */ +phpbb.ajaxify = function(selector, refresh, callback) { + $(selector).click(function() { + var __self = this; + $.get(this.href, function(res) { + res = JSON.parse(res); + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + if (typeof callback !== 'undefined') + { + callback(__self, res); + } + + handle_refresh(res.REFRESH_DATA, refresh, alert); + }); + return false; + }); +} + var refresh = function(url) { return (url.indexOf('t=') === -1); } @@ -121,3 +153,22 @@ var callback = function(el) { $(el).parents('div #p' + pid).remove(); } phpbb.confirm_box('.delete-icon a', refresh, callback); +phpbb.confirm_box('a[href$="ucp.php?mode=delete_cookies"]', true); + +phpbb.ajaxify('a[href*="&bookmark=1"]', false, function(el, res) { + var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); + text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; + $(el).text(el.title = text); +}); +phpbb.ajaxify('a[href*="&watch=topic"]', false, function(el, res) { + var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1); + text = (text) ? 'Unsubscribe topic' : 'Subscribe topic'; + $(el).text(el.title = text); +}); +phpbb.ajaxify('a[href*="watch=forum"]', false, function(el, res) { + var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1); + text = (text) ? 'Unsubscribe forum' : 'Subscribe forum'; + $(el).text(el.title = text); +}); +phpbb.ajaxify('a[href*="mode=bump"]'); +phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums From c4aaf3ae5a2b0a720227a0eadcb62bea5671056a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 14 Jul 2011 17:49:17 +0100 Subject: [PATCH 004/120] [feature/ajax] Cleaned up AJAX-related JavaScript. Mostly just added comments, but has cleaned up some actual code too. PHPBB3-10270 --- phpBB/styles/script.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index ee67768469..4e0566a9a5 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -1,7 +1,7 @@ var phpbb = {}; /** - * Display a simple alert. + * Display a simple alert similar to JSs native alert(). * * @param string title Title of the message, eg "Information" * @param string msg Message to display. Can be HTML. @@ -54,7 +54,7 @@ phpbb.confirm = function(msg, callback) { } /** - * Clearing up some duplicate code - don't use this. + * Works out what to do with the refresh. Don't use this. */ function handle_refresh(data, refresh, div) { @@ -97,7 +97,6 @@ function handle_refresh(data, refresh, div) */ phpbb.confirm_box = function(condition, refresh, callback) { - __self = this; $(condition).click(function() { var __self = this; $.get(this.href, function(res) { @@ -106,16 +105,13 @@ phpbb.confirm_box = function(condition, refresh, callback) if (del) { var p = res.S_CONFIRM_ACTION.split('?'); - p[1] += '&confirm=Yes'; - $.post(p[0], p[1], function(res) { + $.post(p[0], p[1] + '&confirm=Yes', function(res) { res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - if (typeof callback !== 'undefined') { callback(__self); } - handle_refresh(res.REFRESH_DATA, refresh, alert); }); } @@ -127,6 +123,11 @@ phpbb.confirm_box = function(condition, refresh, callback) /** * Makes a link use AJAX instead of loading an entire page. + * + * @param string condition The element to capture. + * @param bool/function refresh If we are sent back a refresh, should it be + * acted upon? This can either be true / false / a function. + * @param function callback Callback. */ phpbb.ajaxify = function(selector, refresh, callback) { $(selector).click(function() { @@ -138,23 +139,25 @@ phpbb.ajaxify = function(selector, refresh, callback) { { callback(__self, res); } - handle_refresh(res.REFRESH_DATA, refresh, alert); }); return false; }); } + +//bind the confirm_boxes var refresh = function(url) { return (url.indexOf('t=') === -1); } -var callback = function(el) { +phpbb.confirm_box('.delete-icon a', refresh, function(el) { var pid = el.href.split('&p=')[1]; $(el).parents('div #p' + pid).remove(); -} -phpbb.confirm_box('.delete-icon a', refresh, callback); +}); phpbb.confirm_box('a[href$="ucp.php?mode=delete_cookies"]', true); + +//AJAXify some links phpbb.ajaxify('a[href*="&bookmark=1"]', false, function(el, res) { var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; From 8a28456f759747fc34aaf9a6589102fcace3acb6 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 16 Jul 2011 17:53:22 +0100 Subject: [PATCH 005/120] [ticket/10273] AJAXified approve / disapprove posts (in viewtopic). This commit AJAXifies the moderator approval functionality, and adds it to viewtopic instead of the MCP. This commit has involved some language changes, which may affect fallbacks. PHPBB3-10273 --- phpBB/language/en/common.php | 2 +- phpBB/language/en/viewtopic.php | 2 + .../prosilver/template/viewtopic_body.html | 10 +++- phpBB/styles/prosilver/theme/common.css | 4 ++ phpBB/styles/script.js | 51 +++++++++++++++++++ phpBB/viewtopic.php | 1 + 6 files changed, 68 insertions(+), 2 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 94edddc6f5..19b801e585 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -476,7 +476,7 @@ $lang = array_merge($lang, array( 'POST_SUBJECT' => 'Post subject', 'POST_TIME' => 'Post time', 'POST_TOPIC' => 'Post a new topic', - 'POST_UNAPPROVED' => 'This post is waiting for approval', + 'POST_UNAPPROVED' => 'Post awaiting approval:', 'PREVIEW' => 'Preview', 'PREVIOUS' => 'Previous', // Used in pagination 'PREVIOUS_STEP' => 'Previous', diff --git a/phpBB/language/en/viewtopic.php b/phpBB/language/en/viewtopic.php index f47f8a076b..1460490672 100644 --- a/phpBB/language/en/viewtopic.php +++ b/phpBB/language/en/viewtopic.php @@ -35,6 +35,7 @@ if (empty($lang) || !is_array($lang)) // in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine $lang = array_merge($lang, array( + 'APPROVE' => 'Approve', 'ATTACHMENT' => 'Attachment', 'ATTACHMENT_FUNCTIONALITY_DISABLED' => 'The attachments feature has been disabled.', @@ -49,6 +50,7 @@ $lang = array_merge($lang, array( 'CODE' => 'Code', 'DELETE_TOPIC' => 'Delete topic', + 'DISAPPROVE' => 'Disapprove', 'DOWNLOAD_NOTICE' => 'You do not have the required permissions to view the files attached to this post.', 'EDITED_TIMES_TOTAL' => array( diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 59e464d22e..5571ce07c4 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -135,10 +135,18 @@

{postrow.MINI_POST_IMG}{postrow.MINI_POST_IMG}{L_POST_BY_AUTHOR} {postrow.POST_AUTHOR_FULL} » {postrow.POST_DATE}

+

- {UNAPPROVED_IMG} {L_POST_UNAPPROVED}
+ + {UNAPPROVED_IMG} {L_POST_UNAPPROVED}   +   + + + {S_FORM_TOKEN} +
{REPORTED_IMG} {L_POST_REPORTED}

+
{postrow.MESSAGE}
diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 5cf12be1ce..6b34bb1c3d 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -658,6 +658,10 @@ p.rules { p.rules img { vertical-align: middle; +} + +p.rules strong { + vertical-align: middle; padding-top: 5px; } diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 4e0566a9a5..b5dec2ca0a 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -86,6 +86,18 @@ function handle_refresh(data, refresh, div) } } +function parse_hidden(inputs) +{ + var end = []; + $(inputs).each(function() { + if (this.type === 'hidden') + { + end.push(this.name + '=' + this.value); + } + }); + return end.join('&'); +} + /** * This function interacts via AJAX with phpBBs confirm_box function. @@ -175,3 +187,42 @@ phpbb.ajaxify('a[href*="watch=forum"]', false, function(el, res) { }); phpbb.ajaxify('a[href*="mode=bump"]'); phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums + + + +/** + * Forms have to be captured manually, as they're all different. + */ +$('input[name^="action"]').click(function(e) { + var __self = this; + var path = $(this).parents('form')[0].action.replace('&', '&'); + var action = (this.name === 'action[approve]') ? 'approve' : 'disapprove'; + var data = { + action: action, + post_id_list: [$(this).siblings('input[name="post_id_list[]"]')[0].value] + }; + $.post(path, data, function(res) { + res = JSON.parse(res); + phpbb.confirm(res.MESSAGE_TEXT, function(del) { + if (del) + { + path = res.S_CONFIRM_ACTION; + data = parse_hidden(res.S_HIDDEN_FIELDS); + $.post(path, data + '&confirm=Yes', function(res) { + console.log(res); + res = JSON.parse(res); + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + + $(__self).parents((action === 'approve') ? '.rules' : '.post').remove(); + + setTimeout(function() { + alert.hide(300, function() { + alert.remove(); + }); + }, 5000); + }); + } + }); + }); + return false; +}); diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 8a95851b7e..1ce80568b6 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1534,6 +1534,7 @@ for ($i = 0, $end = sizeof($post_list); $i < $end; ++$i) 'U_YIM' => $user_cache[$poster_id]['yim'], 'U_JABBER' => $user_cache[$poster_id]['jabber'], + 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p={$row['post_id']}&f=$forum_id"), 'U_REPORT' => ($auth->acl_get('f_report', $forum_id)) ? append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $row['post_id']) : '', 'U_MCP_REPORT' => ($auth->acl_get('m_report', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '', 'U_MCP_APPROVE' => ($auth->acl_get('m_approve', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $forum_id . '&p=' . $row['post_id'], true, $user->session_id) : '', From 456e56144256f3d14d78b02b397d5f3838f0cfea Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 16 Jul 2011 18:20:04 +0100 Subject: [PATCH 006/120] [ticket/10270] Cleaned up code and made popups fade. This commit cleans up some code - mostly, replacing all instances of __self with "that", and also replacing the parse_hidden function with jQuerys built in .serialize. It also adds animations to the popups. PHPBB3-10270 --- phpBB/styles/script.js | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index b5dec2ca0a..17934ed6ae 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -16,14 +16,14 @@ phpbb.alert = function(title, msg) { { return true; } - div.hide(300, function() { + div.animate({opacity: 0}, 300, function() { div.remove(); }); return false; }); $('body').append(div); - div.show(300); + div.css('opacity', 0).show().animate({opacity: 1}, 300); return div; } @@ -43,13 +43,13 @@ phpbb.confirm = function(msg, callback) { $('body').append(div); $('.jalertbut').bind('click', function(event) { - div.hide(300, function() { + div.animate({opacity: 0}, 300, function() { div.remove(); }); callback(this.value === 'Yes'); return false; }); - div.show(300); + div.css('opacity', 0).show().animate({opacity: 1}, 300); return div; } @@ -78,7 +78,7 @@ function handle_refresh(data, refresh, div) else { setTimeout(function() { - div.hide(300, function() { + div.animate({opacity: 0}, 300, function() { div.remove(); }); }, data.time * 1000); @@ -86,18 +86,6 @@ function handle_refresh(data, refresh, div) } } -function parse_hidden(inputs) -{ - var end = []; - $(inputs).each(function() { - if (this.type === 'hidden') - { - end.push(this.name + '=' + this.value); - } - }); - return end.join('&'); -} - /** * This function interacts via AJAX with phpBBs confirm_box function. @@ -110,19 +98,20 @@ function parse_hidden(inputs) phpbb.confirm_box = function(condition, refresh, callback) { $(condition).click(function() { - var __self = this; + var that = this; $.get(this.href, function(res) { res = JSON.parse(res); phpbb.confirm(res.MESSAGE_TEXT, function(del) { if (del) { - var p = res.S_CONFIRM_ACTION.split('?'); - $.post(p[0], p[1] + '&confirm=Yes', function(res) { + var path = res.S_CONFIRM_ACTION; + var data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); + $.post(path, data + '&confirm=Yes', function(res) { res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); if (typeof callback !== 'undefined') { - callback(__self); + callback(that); } handle_refresh(res.REFRESH_DATA, refresh, alert); }); @@ -143,13 +132,13 @@ phpbb.confirm_box = function(condition, refresh, callback) */ phpbb.ajaxify = function(selector, refresh, callback) { $(selector).click(function() { - var __self = this; + var that = this; $.get(this.href, function(res) { res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); if (typeof callback !== 'undefined') { - callback(__self, res); + callback(that, res); } handle_refresh(res.REFRESH_DATA, refresh, alert); }); @@ -194,7 +183,7 @@ phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums * Forms have to be captured manually, as they're all different. */ $('input[name^="action"]').click(function(e) { - var __self = this; + var that = this; var path = $(this).parents('form')[0].action.replace('&', '&'); var action = (this.name === 'action[approve]') ? 'approve' : 'disapprove'; var data = { @@ -207,13 +196,12 @@ $('input[name^="action"]').click(function(e) { if (del) { path = res.S_CONFIRM_ACTION; - data = parse_hidden(res.S_HIDDEN_FIELDS); + data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); $.post(path, data + '&confirm=Yes', function(res) { - console.log(res); res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - $(__self).parents((action === 'approve') ? '.rules' : '.post').remove(); + $(that).parents((action === 'approve') ? '.rules' : '.post').remove(); setTimeout(function() { alert.hide(300, function() { From f42f6f19028fab5b047baae0df5004a43e946a30 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 17 Jul 2011 14:57:13 +0100 Subject: [PATCH 007/120] [ticket/10273] Added phpbb.ajaxify_form and converted accept / deny to it. Also made a few minor improvements to other JavaScript. PHPBB3-10273 --- .../prosilver/template/viewtopic_body.html | 4 +- phpBB/styles/script.js | 125 +++++++++++------- 2 files changed, 80 insertions(+), 49 deletions(-) diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 5571ce07c4..856ee6962c 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -139,8 +139,8 @@

{UNAPPROVED_IMG} {L_POST_UNAPPROVED}   -   - +   + {S_FORM_TOKEN}
diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 17934ed6ae..5d9b89e386 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -1,3 +1,26 @@ +/** + * Make some changes to the jQuery core. + */ +$.fn.hide = function() { + this.animate({opacity: 0}, 300, function() { + $(this).css('display', 'none') + .css('opacity', 1); + }); +} +$.fn.show = function() { + this.css('opacity', 0) + .css('display', 'block') + .animate({opacity: 1}, 300); +} + +$.fn.remove_old = $.fn.remove; +$.fn.remove = function() { + this.animate({opacity: 0}, 300, function() { + $(this).remove_old(); + }); +} + + var phpbb = {}; /** @@ -16,14 +39,12 @@ phpbb.alert = function(title, msg) { { return true; } - div.animate({opacity: 0}, 300, function() { - div.remove(); - }); + div.remove(); return false; }); $('body').append(div); - div.css('opacity', 0).show().animate({opacity: 1}, 300); + div.show(); return div; } @@ -37,19 +58,17 @@ phpbb.alert = function(title, msg) { */ phpbb.confirm = function(msg, callback) { var div = $('

' + msg + '

\ -  \ -
'); +  \ +
'); $('body').append(div); $('.jalertbut').bind('click', function(event) { - div.animate({opacity: 0}, 300, function() { - div.remove(); - }); + div.remove(); callback(this.value === 'Yes'); return false; }); - div.css('opacity', 0).show().animate({opacity: 1}, 300); + div.show(); return div; } @@ -101,12 +120,13 @@ phpbb.confirm_box = function(condition, refresh, callback) var that = this; $.get(this.href, function(res) { res = JSON.parse(res); + console.log(res); phpbb.confirm(res.MESSAGE_TEXT, function(del) { if (del) { var path = res.S_CONFIRM_ACTION; var data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); - $.post(path, data + '&confirm=Yes', function(res) { + $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); if (typeof callback !== 'undefined') @@ -135,6 +155,7 @@ phpbb.ajaxify = function(selector, refresh, callback) { var that = this; $.get(this.href, function(res) { res = JSON.parse(res); + console.log(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); if (typeof callback !== 'undefined') { @@ -146,6 +167,50 @@ phpbb.ajaxify = function(selector, refresh, callback) { }); } +/** + * AJAXifies a form. This will automatically get the action from the submit. + * + * @param string condition The element to capture. + * @param bool/function refresh If we are sent back a refresh, should it be + * acted upon? This can either be true / false / a function. + * @param function callback Callback. + */ +phpbb.ajaxify_form = function(selector, refresh, callback) +{ + $(selector + ' input:submit').click(function(e) { + var act = /action\[([a-z]+)\]/.exec(this.name), + data = decodeURI($(this).closest('form').serialize()), + path = $(this).closest('form').attr('action').replace('&', '&'), + that = this; + + if (act) + { + data += '&action=' + act[1]; + } + + $.post(path, data, function(res) { + res = JSON.parse(res); + phpbb.confirm(res.MESSAGE_TEXT, function(del) { + if (del) + { + path = res.S_CONFIRM_ACTION; + data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); + $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { + res = JSON.parse(res); + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + if (typeof callback !== 'undefined') + { + callback(that, act[1]); + } + handle_refresh(res.REFRESH_DATA, refresh, alert); + }); + } + }); + }); + return false; + }); +} + //bind the confirm_boxes var refresh = function(url) { @@ -177,40 +242,6 @@ phpbb.ajaxify('a[href*="watch=forum"]', false, function(el, res) { phpbb.ajaxify('a[href*="mode=bump"]'); phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums - - -/** - * Forms have to be captured manually, as they're all different. - */ -$('input[name^="action"]').click(function(e) { - var that = this; - var path = $(this).parents('form')[0].action.replace('&', '&'); - var action = (this.name === 'action[approve]') ? 'approve' : 'disapprove'; - var data = { - action: action, - post_id_list: [$(this).siblings('input[name="post_id_list[]"]')[0].value] - }; - $.post(path, data, function(res) { - res = JSON.parse(res); - phpbb.confirm(res.MESSAGE_TEXT, function(del) { - if (del) - { - path = res.S_CONFIRM_ACTION; - data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); - $.post(path, data + '&confirm=Yes', function(res) { - res = JSON.parse(res); - var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - - $(that).parents((action === 'approve') ? '.rules' : '.post').remove(); - - setTimeout(function() { - alert.hide(300, function() { - alert.remove(); - }); - }, 5000); - }); - } - }); - }); - return false; +phpbb.ajaxify_form('.mcp_approve', false, function(el, act) { + $(el).parents((act === 'approve') ? '.rules' : '.post').remove(); }); From fbad17f91202236d3b4ed5c1dacb844aaf2ddbff Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 17 Jul 2011 15:27:58 +0100 Subject: [PATCH 008/120] [feature/ajax] Reduced duplicate code by merging all AJAX function into one. This commit merges phpbb.confirm_box, phpbb.ajaxify and phpbb.ajaxify_form into one function which automatically detects what is happening and calls the correct code accordingly. This has removed a lot of duplicate code and generally made the code cleaner. PHPBB3-10270 --- phpBB/styles/script.js | 202 +++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 118 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 5d9b89e386..e893b84bf8 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -75,72 +75,7 @@ phpbb.confirm = function(msg, callback) { /** * Works out what to do with the refresh. Don't use this. */ -function handle_refresh(data, refresh, div) -{ - if (data) - { - if (typeof refresh === 'function') - { - refresh = refresh(data.url) - } - else if (typeof refresh !== 'boolean') - { - refresh = false; - } - if (refresh) - { - setTimeout(function() { - window.location = data.url; - }, data.time * 1000); - } - else - { - setTimeout(function() { - div.animate({opacity: 0}, 300, function() { - div.remove(); - }); - }, data.time * 1000); - } - } -} - - -/** - * This function interacts via AJAX with phpBBs confirm_box function. - * - * @param string condition The element to capture. - * @param bool/function refresh If we are sent back a refresh, should it be - * acted upon? This can either be true / false / a function. - * @param function callback Callback. - */ -phpbb.confirm_box = function(condition, refresh, callback) -{ - $(condition).click(function() { - var that = this; - $.get(this.href, function(res) { - res = JSON.parse(res); - console.log(res); - phpbb.confirm(res.MESSAGE_TEXT, function(del) { - if (del) - { - var path = res.S_CONFIRM_ACTION; - var data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); - $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { - res = JSON.parse(res); - var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - if (typeof callback !== 'undefined') - { - callback(that); - } - handle_refresh(res.REFRESH_DATA, refresh, alert); - }); - } - }); - }); - return false; - }); -} /** * Makes a link use AJAX instead of loading an entire page. @@ -151,62 +86,92 @@ phpbb.confirm_box = function(condition, refresh, callback) * @param function callback Callback. */ phpbb.ajaxify = function(selector, refresh, callback) { - $(selector).click(function() { - var that = this; - $.get(this.href, function(res) { - res = JSON.parse(res); - console.log(res); - var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - if (typeof callback !== 'undefined') - { - callback(that, res); - } - handle_refresh(res.REFRESH_DATA, refresh, alert); - }); - return false; - }); -} -/** - * AJAXifies a form. This will automatically get the action from the submit. - * - * @param string condition The element to capture. - * @param bool/function refresh If we are sent back a refresh, should it be - * acted upon? This can either be true / false / a function. - * @param function callback Callback. - */ -phpbb.ajaxify_form = function(selector, refresh, callback) -{ - $(selector + ' input:submit').click(function(e) { - var act = /action\[([a-z]+)\]/.exec(this.name), - data = decodeURI($(this).closest('form').serialize()), - path = $(this).closest('form').attr('action').replace('&', '&'), - that = this; - - if (act) + //private function to handle refreshes + function handle_refresh(data, refresh, div) + { + if (!data) { - data += '&action=' + act[1]; + return; } - $.post(path, data, function(res) { + refresh = ((typeof refresh === 'function') ? refresh(data.url) : + (typeof refresh === 'boolean') && refresh); + + setTimeout(function() { + if (refresh) + { + window.location = data.url; + } + else + { + div.remove(); + } + }, data.time * 1000); + } + + var is_form = $(selector).is('form'); + $(selector + ((is_form) ? ' input:submit' : '')).click(function() { + var act, data, path, that = this; + function return_handler(res) + { res = JSON.parse(res); - phpbb.confirm(res.MESSAGE_TEXT, function(del) { - if (del) + + if (typeof res.S_CONFIRM_ACTION === 'undefined') + { + /** + * It is a standard link, no confirm_box required. + */ + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + if (typeof callback !== 'undefined') { - path = res.S_CONFIRM_ACTION; - data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); - $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { - res = JSON.parse(res); - var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - if (typeof callback !== 'undefined') - { - callback(that, act[1]); - } - handle_refresh(res.REFRESH_DATA, refresh, alert); - }); + callback(that, res); } - }); - }); + handle_refresh(res.REFRESH_DATA, refresh, alert); + } + else + { + /** + * confirm_box - confirm with the user and send back + */ + phpbb.confirm(res.MESSAGE_TEXT, function(del) { + if (del) + { + data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); + path = res.S_CONFIRM_ACTION; + $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { + res = JSON.parse(res); + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + if (typeof callback !== 'undefined') + { + callback(that, (is_form) ? act : null); + } + handle_refresh(res.REFRESH_DATA, refresh, alert); + }); + } + }); + } + } + + if (is_form) + { + act = /action\[([a-z]+)\]/.exec(this.name); + data = decodeURI($(this).closest('form').serialize()); + path = $(this).closest('form').attr('action').replace('&', '&'); + + if (act) + { + act = act[1] + data += '&action=' + act; + } + + $.post(path, data, return_handler); + } + else + { + $.get(this.href, return_handler); + } + return false; }); } @@ -216,20 +181,21 @@ phpbb.ajaxify_form = function(selector, refresh, callback) var refresh = function(url) { return (url.indexOf('t=') === -1); } -phpbb.confirm_box('.delete-icon a', refresh, function(el) { +phpbb.ajaxify('.delete-icon a', refresh, function(el) { var pid = el.href.split('&p=')[1]; $(el).parents('div #p' + pid).remove(); }); -phpbb.confirm_box('a[href$="ucp.php?mode=delete_cookies"]', true); +phpbb.ajaxify('a[href$="ucp.php?mode=delete_cookies"]', true); //AJAXify some links phpbb.ajaxify('a[href*="&bookmark=1"]', false, function(el, res) { + console.log(res); var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; $(el).text(el.title = text); }); -phpbb.ajaxify('a[href*="&watch=topic"]', false, function(el, res) { +phpbb.ajaxify('a[href*="watch=topic"]', false, function(el, res) { var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1); text = (text) ? 'Unsubscribe topic' : 'Subscribe topic'; $(el).text(el.title = text); @@ -242,6 +208,6 @@ phpbb.ajaxify('a[href*="watch=forum"]', false, function(el, res) { phpbb.ajaxify('a[href*="mode=bump"]'); phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums -phpbb.ajaxify_form('.mcp_approve', false, function(el, act) { +phpbb.ajaxify('.mcp_approve', false, function(el, act) { $(el).parents((act === 'approve') ? '.rules' : '.post').remove(); }); From ac1b32c30772cd722c77694af83cb14b4581675f Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 17 Jul 2011 15:36:54 +0100 Subject: [PATCH 009/120] [ticket/10270] Changed function names of jQuery modifications. The code was modifying the jQuery code before, now the functions have been renamed to unused function names. PHPBB3-10270 --- phpBB/styles/script.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index e893b84bf8..959a41a643 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -1,22 +1,21 @@ /** * Make some changes to the jQuery core. */ -$.fn.hide = function() { +$.fn.hide_anim = function() { this.animate({opacity: 0}, 300, function() { $(this).css('display', 'none') .css('opacity', 1); }); } -$.fn.show = function() { +$.fn.show_anim = function() { this.css('opacity', 0) .css('display', 'block') .animate({opacity: 1}, 300); } -$.fn.remove_old = $.fn.remove; -$.fn.remove = function() { +$.fn.remove_anim = function() { this.animate({opacity: 0}, 300, function() { - $(this).remove_old(); + $(this).remove(); }); } @@ -39,12 +38,12 @@ phpbb.alert = function(title, msg) { { return true; } - div.remove(); + div.remove_anim(); return false; }); $('body').append(div); - div.show(); + div.show_anim(); return div; } @@ -64,11 +63,11 @@ phpbb.confirm = function(msg, callback) { $('body').append(div); $('.jalertbut').bind('click', function(event) { - div.remove(); + div.remove_anim(); callback(this.value === 'Yes'); return false; }); - div.show(); + div.show_anim(); return div; } @@ -105,7 +104,7 @@ phpbb.ajaxify = function(selector, refresh, callback) { } else { - div.remove(); + div.remove_anim(); } }, data.time * 1000); } @@ -183,14 +182,13 @@ var refresh = function(url) { } phpbb.ajaxify('.delete-icon a', refresh, function(el) { var pid = el.href.split('&p=')[1]; - $(el).parents('div #p' + pid).remove(); + $(el).parents('div #p' + pid).remove_anim(); }); phpbb.ajaxify('a[href$="ucp.php?mode=delete_cookies"]', true); //AJAXify some links phpbb.ajaxify('a[href*="&bookmark=1"]', false, function(el, res) { - console.log(res); var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; $(el).text(el.title = text); @@ -209,5 +207,5 @@ phpbb.ajaxify('a[href*="mode=bump"]'); phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums phpbb.ajaxify('.mcp_approve', false, function(el, act) { - $(el).parents((act === 'approve') ? '.rules' : '.post').remove(); + $(el).parents((act === 'approve') ? '.rules' : '.post').remove_anim(); }); From 2f2ec1096b6288c032e276c75c849bb1cc820674 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 17 Jul 2011 15:56:27 +0100 Subject: [PATCH 010/120] [ticket/10272] Made some jQuery selectors more specific to avoid conflicts. Before, a link to any URL with, say, "mode=bump" in the title would have been prevented from acting normally. PHPBB3-10272 --- phpBB/styles/script.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 959a41a643..32b12bdd34 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -184,27 +184,27 @@ phpbb.ajaxify('.delete-icon a', refresh, function(el) { var pid = el.href.split('&p=')[1]; $(el).parents('div #p' + pid).remove_anim(); }); -phpbb.ajaxify('a[href$="ucp.php?mode=delete_cookies"]', true); +phpbb.ajaxify('#page-footer a[href$="ucp.php?mode=delete_cookies"]', true); //AJAXify some links -phpbb.ajaxify('a[href*="&bookmark=1"]', false, function(el, res) { +phpbb.ajaxify('#page-footer a[href*="&bookmark=1"]', false, function(el, res) { var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; $(el).text(el.title = text); }); -phpbb.ajaxify('a[href*="watch=topic"]', false, function(el, res) { +phpbb.ajaxify('#page-footer a[href*="watch=topic"]', false, function(el, res) { var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1); text = (text) ? 'Unsubscribe topic' : 'Subscribe topic'; $(el).text(el.title = text); }); -phpbb.ajaxify('a[href*="watch=forum"]', false, function(el, res) { +phpbb.ajaxify('#page-footer a[href*="watch=forum"]', false, function(el, res) { var text = (res.MESSAGE_TEXT.indexOf('no longer subscribed') === -1); text = (text) ? 'Unsubscribe forum' : 'Subscribe forum'; $(el).text(el.title = text); }); -phpbb.ajaxify('a[href*="mode=bump"]'); -phpbb.ajaxify('a[href*="mark="]'); //captures topics and forums +phpbb.ajaxify('#page-footer a[href*="mode=bump"]'); +phpbb.ajaxify('.rightside a[href*="mark="]'); //captures topics and forums phpbb.ajaxify('.mcp_approve', false, function(el, act) { $(el).parents((act === 'approve') ? '.rules' : '.post').remove_anim(); From 8fd86717e1320cb3160515fe786869c80e6771f9 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 20 Jul 2011 18:28:14 +0100 Subject: [PATCH 011/120] [ticket/10271] Added ability for exceptions to phpbb.ajaxify. Also made it easy for additional options to be added in the future. PHPBB3-10271 --- .../prosilver/template/viewtopic_body.html | 2 +- phpBB/styles/script.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 856ee6962c..9e333cf5ec 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -263,7 +263,7 @@ -
+
  -   +  
diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index b73c392312..889db70f98 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -103,6 +103,11 @@ phpbb.ajaxify = function(options, refresh, callback) { $(selector).click(function() { var act, data, path, that = this; + if ($(this).data('ajax') == false) + { + return true; + } + function return_handler(res) { res = JSON.parse(res); @@ -157,7 +162,11 @@ phpbb.ajaxify = function(options, refresh, callback) { act = act[1] data += '&action=' + act; } - + else + { + data += '&' + this.name + '=' + this.value; + } + if (run_exception && options.exception($(this).parents('form'), act, data)) { return true; @@ -213,6 +222,10 @@ phpbb.add_ajax_callback('post_delete', function(el) { $(el).parents((act === 'approve') ? '.rules' : '.post').fadeOut(function() { $(this).remove(); }); +}).add_ajax_callback('qr-submit', function(el) { + $(el).parents('form').fadeOut(function() { + $(this).remove(); + }); }); From 7ccc18297af17dbc66fc5a28710af6970a17fb6e Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Mon, 25 Jul 2011 20:42:29 +0100 Subject: [PATCH 016/120] [ticket/10270] Makes page fade to dark on popup, and added $.querystring. PHPBB3-10270 --- phpBB/styles/prosilver/theme/common.css | 16 ++- phpBB/styles/script.js | 139 ++++++++++++++++++++---- 2 files changed, 133 insertions(+), 22 deletions(-) diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 6b34bb1c3d..a3d2c5660e 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -593,8 +593,8 @@ li.pagination { .jalert { background-color: #FFFFFF; border: 1px solid #999999; - display: none; position: fixed; + display: none; top: 100px; left: 35%; width: 30%; @@ -608,6 +608,20 @@ li.pagination { padding-bottom: 8px; } +#darkenwrapper { + display: none; +} + +#darken { + position: fixed; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: #000000; + opacity: 0.5; +} + /* Miscellaneous styles ---------------------------------------- */ #forum-permissions { diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 889db70f98..0b2d372db7 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -1,5 +1,47 @@ +$.querystring = function(string) { + var end = {}, i; + + string = string.split('&'); + for (i = 0; i < string.length; i++) + { + end[string[i].split('=')[0]] = decodeURIComponent(string[i].split('=')[1]); + } + return end; +} + + var phpbb = {}; +var dark = $('
 
'); +$('body').append(dark); + +var loading_alert = $('

Loading

Please wait.

'); +$(dark).append(loading_alert); + + +/** + * Display a loading screen. + */ +phpbb.loading_alert = function() { + if (dark.is(':visible')) + { + loading_alert.fadeIn(); + } + else + { + loading_alert.show(); + dark.fadeIn(); + } + + setTimeout(function() { + if (loading_alert.is(':visible')) + { + phpbb.alert('Error', 'Error processing your request. Please try again.'); + } + }, 3000); + return loading_alert; +} + /** * Display a simple alert similar to JSs native alert(). * @@ -8,22 +50,48 @@ var phpbb = {}; * * @return Returns the div created. */ -phpbb.alert = function(title, msg) { +phpbb.alert = function(title, msg, fadedark) { var div = $('

' + title + '

' + msg + '

'); - $(document).one('click', function(e) { - if ($(e.target).parents('.jalert').length) + $(div).bind('click', function(e) { + e.stopPropagation(); + return true; + }); + $(dark).one('click', function(e) { + if (typeof fadedark === 'undefined' || fadedark) { - return true; + dark.fadeOut(function() { + div.remove(); + }); + } + else + { + div.fadeOut(function() { + div.remove(); + }); } - div.fadeOut(function() { - div.remove(); - }); return false; }); - $('body').append(div); - div.fadeIn(); + if (loading_alert.is(':visible')) + { + loading_alert.fadeOut(function() { + $(dark).append(div); + div.fadeIn(); + }); + } + else if (dark.is(':visible')) + { + $(dark).append(div); + div.fadeIn(); + } + else + { + $(dark).append(div); + div.show(); + dark.fadeIn(); + } + return div; } @@ -35,21 +103,47 @@ phpbb.alert = function(title, msg) { * * @return Returns the div created. */ -phpbb.confirm = function(msg, callback) { +phpbb.confirm = function(msg, callback, fadedark) { var div = $('

' + msg + '

\  \
'); - - $('body').append(div); - - $('.jalertbut').bind('click', function(event) { - div.fadeOut(function() { - div.remove(); - }); + + div.find('.jalertbut').bind('click', function() { + if (typeof fadedark === 'undefined' || fadedark) + { + dark.fadeOut(function() { + div.remove(); + }); + } + else + { + div.fadeOut(function() { + div.remove(); + }); + } callback(this.value === 'Yes'); return false; }); - div.fadeIn(); + + if (loading_alert.is(':visible')) + { + loading_alert.fadeOut(function() { + $(dark).append(div); + div.fadeIn(); + }); + } + else if (dark.is(':visible')) + { + $(dark).append(div); + div.fadeIn(); + } + else + { + $(dark).append(div); + div.show(); + dark.fadeIn(); + } + return div; } @@ -82,7 +176,7 @@ phpbb.ajaxify = function(options, refresh, callback) { } else { - div.fadeOut(function() { + dark.fadeOut(function() { div.remove(); }); } @@ -135,6 +229,7 @@ phpbb.ajaxify = function(options, refresh, callback) { { data = $('' + res.S_HIDDEN_FIELDS + '').serialize(); path = res.S_CONFIRM_ACTION; + phpbb.loading_alert(); $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { res = JSON.parse(res); var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); @@ -146,7 +241,7 @@ phpbb.ajaxify = function(options, refresh, callback) { handle_refresh(res.REFRESH_DATA, refresh, alert); }); } - }); + }, false); } } @@ -171,6 +266,7 @@ phpbb.ajaxify = function(options, refresh, callback) { { return true; } + phpbb.loading_alert(); $.post(path, data, return_handler); } else @@ -179,6 +275,7 @@ phpbb.ajaxify = function(options, refresh, callback) { { return true; } + phpbb.loading_alert(); $.get(this.href, return_handler); } @@ -240,7 +337,7 @@ $('[data-ajax]').each(function() { phpbb.ajaxify({ selector: '#quickmodform', exception: function(el, act, data) { - var d = data.split('=')[1]; + var d = $.querystring(data).action; if (d == 'make_normal') { return !(el.find('select option[value="make_global"]').length); From 149daa0e4fbe5bf59a613caf850ecda083cc772a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 26 Jul 2011 11:46:49 +0100 Subject: [PATCH 017/120] [feature/ajax] Added code to avoid conflicts with other libraries using $ PHPBB3-10270 --- phpBB/styles/script.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 0b2d372db7..66e99a6a63 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -1,3 +1,6 @@ +;(function($) { //avoid conflicts with other libraries + + $.querystring = function(string) { var end = {}, i; @@ -345,3 +348,6 @@ phpbb.ajaxify({ return !(d == 'lock' || d == 'unlock' || d == 'delete_topic' || d.slice(0, 5) == 'make_'); } }, true); + + +})(jQuery); //avoid conflicts with other libraries From e4ea4d1c579477389349a06190643391ea8740fc Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 26 Jul 2011 12:13:09 +0100 Subject: [PATCH 018/120] [ticket/10270] Fixed a bug where fadedark wouldn't go. If the confirm box was submitted as yes, then the fadedark would stay until it was clicked. This commit fixes that. PHPBB3-10270 --- phpBB/styles/script.js | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 66e99a6a63..8c7324e39a 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -50,6 +50,8 @@ phpbb.loading_alert = function() { * * @param string title Title of the message, eg "Information" * @param string msg Message to display. Can be HTML. + * @param bool fadedark Remove the dark background when done? Defaults + * to yes. * * @return Returns the div created. */ @@ -61,18 +63,10 @@ phpbb.alert = function(title, msg, fadedark) { return true; }); $(dark).one('click', function(e) { - if (typeof fadedark === 'undefined' || fadedark) - { - dark.fadeOut(function() { - div.remove(); - }); - } - else - { - div.fadeOut(function() { - div.remove(); - }); - } + var fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; + fade.fadeOut(function() { + div.remove(); + }); return false; }); @@ -102,7 +96,10 @@ phpbb.alert = function(title, msg, fadedark) { * Display a simple yes / no box to the user. * * @param string msg Message to display. Can be HTML. - * @param function callback Callback. + * @param function callback Callback. Bool param, whether the user pressed + * yes or no (or whatever their language is). + * @param bool fadedark Remove the dark background when done? Defaults + * to yes. * * @return Returns the div created. */ @@ -112,19 +109,12 @@ phpbb.confirm = function(msg, callback, fadedark) { '); div.find('.jalertbut').bind('click', function() { - if (typeof fadedark === 'undefined' || fadedark) - { - dark.fadeOut(function() { - div.remove(); - }); - } - else - { - div.fadeOut(function() { - div.remove(); - }); - } - callback(this.value === 'Yes'); + var res = this.value === 'Yes'; + var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; + fade.fadeOut(function() { + div.remove(); + }); + callback(res); return false; }); From 22c6953c116e24cbe278f0fe63aabaf950c843e3 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 26 Jul 2011 16:25:04 +0100 Subject: [PATCH 019/120] [feature/ajax] Fixed a small bug in the JavaScript. The bug meant that code outside of the function that ran on document ready would not be able to access the phpbb object. PHPBB3-10270 --- phpBB/styles/script.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 8c7324e39a..72e3c59e75 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -1,4 +1,6 @@ -;(function($) { //avoid conflicts with other libraries +var phpbb = {}; + +(function($) { //avoid conflicts with other libraries $.querystring = function(string) { @@ -13,8 +15,6 @@ $.querystring = function(string) { } -var phpbb = {}; - var dark = $('
 
'); $('body').append(dark); From bb7a03f738c97dc225873691c459f2bf9e612ef6 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 27 Jul 2011 12:57:58 +0100 Subject: [PATCH 020/120] [ticket/10281] AJAXified reordering forums in the ACP. PHPBB3-10281 --- phpBB/adm/style/acp_forums.html | 18 ++++++++--------- phpBB/adm/style/overall_footer.html | 4 ++++ phpBB/includes/acp/acp_forums.php | 6 ++++++ phpBB/styles/script.js | 30 +++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/phpBB/adm/style/acp_forums.html b/phpBB/adm/style/acp_forums.html index 447c0ce466..b2b3ad6d40 100644 --- a/phpBB/adm/style/acp_forums.html +++ b/phpBB/adm/style/acp_forums.html @@ -443,7 +443,7 @@ - + {forums.FOLDER_IMAGE}
{forums.FORUM_IMAGE}
@@ -453,17 +453,17 @@ - {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} - {ICON_MOVE_UP} - {ICON_MOVE_DOWN_DISABLED} + {ICON_MOVE_UP} + {ICON_MOVE_DOWN_DISABLED} - {ICON_MOVE_UP_DISABLED} - {ICON_MOVE_DOWN_DISABLED} + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN_DISABLED} {ICON_EDIT} diff --git a/phpBB/adm/style/overall_footer.html b/phpBB/adm/style/overall_footer.html index f05e9c56c5..3740122d9b 100644 --- a/phpBB/adm/style/overall_footer.html +++ b/phpBB/adm/style/overall_footer.html @@ -17,6 +17,10 @@
{DEBUG_OUTPUT} + + + + diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index fad22fc285..d3e2dbd904 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -255,6 +255,12 @@ class acp_forums add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name); $cache->destroy('sql', FORUMS_TABLE); } + + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + echo json_encode(array('success' => ($move_forum_name !== false))); + exit; + } break; diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 72e3c59e75..35c99464bd 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -316,6 +316,36 @@ phpbb.add_ajax_callback('post_delete', function(el) { $(el).parents('form').fadeOut(function() { $(this).remove(); }); +}).add_ajax_callback('forum_down', function(el) { + var tr = $(el).parents('tr'); + if (tr.is(':first-child')) + { + $(el).parents('span').siblings('.up').html('Move up'); + tr.next().find('.up').html('Move up'); + phpbb.ajaxify({selector: $(el).parents('span').siblings('.up').children('a')}, false, 'forum_up'); + } + tr.insertAfter(tr.next()); + if (tr.is(':last-child')) + { + $(el).html('Move down'); + tr.prev().find('.down').html('Move down'); + phpbb.ajaxify({selector: tr.prev().find('.down').children('a')}, false, 'forum_down'); + } +}).add_ajax_callback('forum_up', function(el) { + var tr = $(el).parents('tr'); + if (tr.is(':last-child')) + { + $(el).parents('span').siblings('.down').html('Move down'); + tr.prev().find('.down').html('Move down'); + phpbb.ajaxify({selector: $(el).parents('span').siblings('.down').children('a')}, false, 'forum_down'); + } + tr.insertBefore(tr.prev()); + if (tr.is(':first-child')) + { + $(el).html('Move up'); + tr.next().find('.up').html('Move up'); + phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); + } }); From 59031fdc735a80502ea2cda3683a9276da5649cd Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 18 Aug 2011 18:34:09 +0100 Subject: [PATCH 021/120] [ticket/10272] AJAXified the add / remove friend / foe links. PHPBB3-10272 --- phpBB/styles/prosilver/template/memberlist_view.html | 8 ++++---- phpBB/styles/script.js | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/phpBB/styles/prosilver/template/memberlist_view.html b/phpBB/styles/prosilver/template/memberlist_view.html index f10ec64975..d8bb92a731 100644 --- a/phpBB/styles/prosilver/template/memberlist_view.html +++ b/phpBB/styles/prosilver/template/memberlist_view.html @@ -35,15 +35,15 @@
{custom_fields.PROFILE_FIELD_NAME}:
{custom_fields.PROFILE_FIELD_VALUE}
-
 
{L_REMOVE_FRIEND}
+
 
{L_REMOVE_FRIEND}
-
 
{L_REMOVE_FOE}
+
 
{L_REMOVE_FOE}
-
 
{L_ADD_FRIEND}
+
 
{L_ADD_FRIEND}
-
 
{L_ADD_FOE}
+
 
{L_ADD_FOE}
diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 35c99464bd..d17a2cdc10 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -346,7 +346,12 @@ phpbb.add_ajax_callback('post_delete', function(el) { tr.next().find('.up').html('Move up'); phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); } -}); +}).add_ajax_callback('zebra', function(el, res) { + if (res.MESSAGE_TEXT.indexOf('successfully') !== -1) { + $('.zebra').html(res.MESSAGE_TEXT.split(' Date: Thu, 18 Aug 2011 19:02:18 +0100 Subject: [PATCH 022/120] [ticket/10270] Added keyboard shortcuts to confirm and alert boxes. PHPBB3-10270 --- phpBB/styles/script.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index d17a2cdc10..54248cc31c 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -69,6 +69,14 @@ phpbb.alert = function(title, msg, fadedark) { }); return false; }); + + $(document).bind('keydown', function(e) { + if (e.keyCode === 13 || e.keyCode === 27) { + $(dark).trigger('click'); + return false; + } + return true; + }); if (loading_alert.is(':visible')) { @@ -118,6 +126,17 @@ phpbb.confirm = function(msg, callback, fadedark) { return false; }); + $(document).bind('keydown', function(e) { + if (e.keyCode === 13) { + $('.jalertbut.button1').trigger('click'); + return false; + } else if (e.keyCode === 27) { + $('.jalertbut.button2').trigger('click'); + return false; + } + return true; + }); + if (loading_alert.is(':visible')) { loading_alert.fadeOut(function() { From 94172b54dd09b28e19b4b12933b3f96e498d264a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 19 Aug 2011 09:38:57 +0100 Subject: [PATCH 023/120] [ticket/10271] Changed AJAX functions to $request->is_ajax(). PHPBB3-10271 --- phpBB/includes/acp/acp_forums.php | 4 ++-- phpBB/includes/functions.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index d3e2dbd904..cb410e361a 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -25,7 +25,7 @@ class acp_forums function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx; $user->add_lang('acp/forums'); @@ -256,7 +256,7 @@ class acp_forums $cache->destroy('sql', FORUMS_TABLE); } - if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { echo json_encode(array('success' => ($move_forum_name !== false))); exit; 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; From dce38f44de04bd7a1f91f8e57f6d266bd5e1af86 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 19 Aug 2011 10:45:03 +0100 Subject: [PATCH 024/120] [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/common.php | 1 + phpBB/includes/acp/acp_forums.php | 3 +- phpBB/includes/functions.php | 6 ++-- phpBB/includes/json.php | 59 +++++++++++++++++++++++++++++++ phpBB/styles/script.js | 3 -- 5 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 phpBB/includes/json.php diff --git a/phpBB/common.php b/phpBB/common.php index 129f7e4881..2c90ccf76c 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -74,6 +74,7 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); +require($phpbb_root_path . 'includes/json.' . $phpEx); require($phpbb_root_path . 'includes/session.' . $phpEx); require($phpbb_root_path . 'includes/auth.' . $phpEx); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index cb410e361a..6c05b1e108 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -258,8 +258,7 @@ class acp_forums if ($request->is_ajax()) { - echo json_encode(array('success' => ($move_forum_name !== false))); - exit; + JSON::send(array('success' => ($move_forum_name !== false))); } break; 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 diff --git a/phpBB/includes/json.php b/phpBB/includes/json.php new file mode 100644 index 0000000000..04472080d9 --- /dev/null +++ b/phpBB/includes/json.php @@ -0,0 +1,59 @@ + Date: Fri, 19 Aug 2011 17:39:35 +0100 Subject: [PATCH 025/120] [ticket/10270] Lengthened the timeout on the AJAX request error. It was at 3 seconds before, now it is at 5 seconds from when the popup has faded in. PHPBB3-10270 --- phpBB/styles/script.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 3ed12bfee8..04e768e21e 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -33,15 +33,16 @@ phpbb.loading_alert = function() { else { loading_alert.show(); - dark.fadeIn(); + dark.fadeIn(function() { + setTimeout(function() { + if (loading_alert.is(':visible')) + { + phpbb.alert('Error', 'Error processing your request. Please try again.'); + } + }, 5000); + }); } - - setTimeout(function() { - if (loading_alert.is(':visible')) - { - phpbb.alert('Error', 'Error processing your request. Please try again.'); - } - }, 3000); + return loading_alert; } From 082c5c5b328e10e3fa99beaff31c4bc28f73bbd0 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 19 Aug 2011 18:11:58 +0100 Subject: [PATCH 026/120] [ticket/10272] Zebra operations using AJAX are now less hacky. Before, they were splitting stuff by the
, and now JSON::add() is being used. PHPBB3-10272 --- phpBB/includes/ucp/ucp_zebra.php | 4 ++++ phpBB/styles/script.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index 004f3b80aa..3f0e97b48a 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -201,6 +201,10 @@ class ucp_zebra if ($updated) { + JSON::add(array( + 'message' => $user->lang[$l_mode . '_UPDATED'], + 'success' => true + )); meta_refresh(3, $this->u_action); $message = $user->lang[$l_mode . '_UPDATED'] . '
' . implode('
', $error) . ((sizeof($error)) ? '
' : '') . '
' . sprintf($user->lang['RETURN_UCP'], '', ''); trigger_error($message); diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 04e768e21e..f1fe2b9a10 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -364,8 +364,8 @@ phpbb.add_ajax_callback('post_delete', function(el) { phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); } }).add_ajax_callback('zebra', function(el, res) { - if (res.MESSAGE_TEXT.indexOf('successfully') !== -1) { - $('.zebra').html(res.MESSAGE_TEXT.split(' Date: Wed, 24 Aug 2011 11:31:17 +0100 Subject: [PATCH 027/120] [ticket/10271] Moved $.querystring to phpbb.parse_querystring. PHPBB3-10271 --- phpBB/styles/script.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index f1fe2b9a10..ceaf92672c 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -3,18 +3,6 @@ var phpbb = {}; (function($) { //avoid conflicts with other libraries -$.querystring = function(string) { - var end = {}, i; - - string = string.split('&'); - for (i = 0; i < string.length; i++) - { - end[string[i].split('=')[0]] = decodeURIComponent(string[i].split('=')[1]); - } - return end; -} - - var dark = $('
 
'); $('body').append(dark); @@ -160,6 +148,23 @@ phpbb.confirm = function(msg, callback, fadedark) { return div; } +/** + * Turn a querystring into an array. + * + * @argument string string The querystring to parse. + * @returns array The array created. + */ +phpbb.parse_querystring = function(string) { + var end = {}, i; + + string = string.split('&'); + for (i = 0; i < string.length; i++) + { + end[string[i].split('=')[0]] = decodeURIComponent(string[i].split('=')[1]); + } + return end; +} + /** * Makes a link use AJAX instead of loading an entire page. @@ -382,7 +387,7 @@ $('[data-ajax]').each(function() { phpbb.ajaxify({ selector: '#quickmodform', exception: function(el, act, data) { - var d = $.querystring(data).action; + var d = phpbb.parse_querystring(data).action; if (d == 'make_normal') { return !(el.find('select option[value="make_global"]').length); From 6efb9dd0b6e0119009d5b10d198722ba2b19f0e2 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 11:34:41 +0100 Subject: [PATCH 028/120] [ticket/10270] Added jQuery popup CSS to the ACP. It was missing previously, meaning that it displayed wrong and in the footer. PHPBB3-10270 --- phpBB/adm/style/admin.css | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index ceda824e5a..70c06f2d62 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -1070,6 +1070,40 @@ input.disabled { color: #666666; } +/* jQuery popups +---------------------------------------- */ +.jalert { + background-color: #FFFFFF; + border: 1px solid #999999; + position: fixed; + display: none; + top: 100px; + left: 35%; + width: 30%; + z-index: 50; + padding: 25px; + padding: 0 25px 20px 25px; +} + +.jalert p { + margin: 8px 0; + padding-bottom: 8px; +} + +#darkenwrapper { + display: none; +} + +#darken { + position: fixed; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: #000000; + opacity: 0.5; +} + /* Pagination ---------------------------------------- */ .pagination { From 420de9c9a0a638135da147a498436dbe7abfd4bd Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 11:42:39 +0100 Subject: [PATCH 029/120] [ticket/10270] Moved some HTML from the JavaScript to overall_footer. PHPBB3-10270 --- phpBB/adm/style/overall_footer.html | 5 +++++ phpBB/language/en/common.php | 2 ++ phpBB/styles/prosilver/template/overall_footer.html | 5 +++++ phpBB/styles/script.js | 7 ++----- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/phpBB/adm/style/overall_footer.html b/phpBB/adm/style/overall_footer.html index 3740122d9b..625121f1bd 100644 --- a/phpBB/adm/style/overall_footer.html +++ b/phpBB/adm/style/overall_footer.html @@ -18,6 +18,11 @@ {DEBUG_OUTPUT} +
+
 
+

{L_LOADING}

{L_PLEASE_WAIT}

+
+ diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 19b801e585..e8fff96e5a 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -314,6 +314,7 @@ $lang = array_merge($lang, array( 'LDAP_NO_SERVER_CONNECTION' => 'Could not connect to LDAP server.', 'LDAP_SEARCH_FAILED' => 'An error occured while searching the LDAP directory.', 'LEGEND' => 'Legend', + 'LOADING' => 'Loading', 'LOCATION' => 'Location', 'LOCK_POST' => 'Lock post', 'LOCK_POST_EXPLAIN' => 'Prevent editing', @@ -451,6 +452,7 @@ $lang = array_merge($lang, array( 2 => '%d pixels', ), 'PLAY_QUICKTIME_FILE' => 'Play Quicktime file', + 'PLEASE_WAIT' => 'Please wait.', 'PM' => 'PM', 'PM_REPORTED' => 'Click to view report', 'POSTING_MESSAGE' => 'Posting message in %s', diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index ffdb27be98..37caaf7cca 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -24,6 +24,11 @@
{DEBUG_OUTPUT}
{L_ACP} + +
+
 
+

{L_LOADING}

{L_PLEASE_WAIT}

+
diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index ceaf92672c..bf8c548df0 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -3,11 +3,8 @@ var phpbb = {}; (function($) { //avoid conflicts with other libraries -var dark = $('
 
'); -$('body').append(dark); - -var loading_alert = $('

Loading

Please wait.

'); -$(dark).append(loading_alert); +var dark = $('#darkenwrapper'), + loading_alert = $('#loadingalert'); /** From c92b30d66cbb2839369c04172eb5ae9bacd27a16 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 11:44:28 +0100 Subject: [PATCH 030/120] [feature/ajax] Changed JavaScript comments to follow coding guidelines. Also replaced a couple instances of "@return" with "@returns". PHPBB3-10270 --- phpBB/styles/script.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index bf8c548df0..1b9262f585 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -1,6 +1,6 @@ var phpbb = {}; -(function($) { //avoid conflicts with other libraries +(function($) { // Avoid conflicts with other libraries var dark = $('#darkenwrapper'), @@ -9,6 +9,8 @@ var dark = $('#darkenwrapper'), /** * Display a loading screen. + * + * @returns object Returns loading_alert. */ phpbb.loading_alert = function() { if (dark.is(':visible')) @@ -39,7 +41,7 @@ phpbb.loading_alert = function() { * @param bool fadedark Remove the dark background when done? Defaults * to yes. * - * @return Returns the div created. + * @returns object Returns the div created. */ phpbb.alert = function(title, msg, fadedark) { var div = $('

' + title + '

' + msg + '

'); @@ -95,7 +97,7 @@ phpbb.alert = function(title, msg, fadedark) { * @param bool fadedark Remove the dark background when done? Defaults * to yes. * - * @return Returns the div created. + * @returns object Returns the div created. */ phpbb.confirm = function(msg, callback, fadedark) { var div = $('

' + msg + '

\ @@ -173,7 +175,7 @@ phpbb.parse_querystring = function(string) { */ phpbb.ajaxify = function(options, refresh, callback) { - //private function to handle refreshes + // Private function to handle refreshes function handle_refresh(data, refresh, div) { if (!data) @@ -221,9 +223,7 @@ phpbb.ajaxify = function(options, refresh, callback) { { if (typeof res.S_CONFIRM_ACTION === 'undefined') { - /** - * It is a standard link, no confirm_box required. - */ + // It is a standard link, no confirm_box required. var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); callback = phpbb.ajax_callbacks[callback]; if (typeof callback === 'function') @@ -234,9 +234,7 @@ phpbb.ajaxify = function(options, refresh, callback) { } else { - /** - * confirm_box - confirm with the user and send back - */ + // confirm_box - confirm with the user and send back phpbb.confirm(res.MESSAGE_TEXT, function(del) { if (del) { @@ -394,4 +392,4 @@ phpbb.ajaxify({ }, true); -})(jQuery); //avoid conflicts with other libraries +})(jQuery); // Avoid conflicts with other libraries From 7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 12:25:54 +0100 Subject: [PATCH 031/120] [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/common.php | 1 - phpBB/includes/acp/acp_forums.php | 3 ++- phpBB/includes/functions.php | 6 +++-- .../includes/{json.php => json_response.php} | 23 +++--------------- phpBB/includes/ucp/ucp_zebra.php | 24 ++++++++++++++----- phpBB/styles/script.js | 2 +- 6 files changed, 28 insertions(+), 31 deletions(-) rename phpBB/includes/{json.php => json_response.php} (58%) diff --git a/phpBB/common.php b/phpBB/common.php index 2c90ccf76c..129f7e4881 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -74,7 +74,6 @@ if (!empty($load_extensions) && function_exists('dl')) // Include files require($phpbb_root_path . 'includes/class_loader.' . $phpEx); -require($phpbb_root_path . 'includes/json.' . $phpEx); require($phpbb_root_path . 'includes/session.' . $phpEx); require($phpbb_root_path . 'includes/auth.' . $phpEx); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 6c05b1e108..3a3b2021eb 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -258,7 +258,8 @@ class acp_forums if ($request->is_ajax()) { - JSON::send(array('success' => ($move_forum_name !== false))); + $json_response = new phpbb_json_response; + $json_response->send(array('success' => ($move_forum_name !== false))); } break; 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, diff --git a/phpBB/includes/json.php b/phpBB/includes/json_response.php similarity index 58% rename from phpBB/includes/json.php rename to phpBB/includes/json_response.php index 04472080d9..95d02e3c0e 100644 --- a/phpBB/includes/json.php +++ b/phpBB/includes/json_response.php @@ -20,25 +20,18 @@ if (!defined('IN_PHPBB')) * JSON class * @package phpBB3 */ -class JSON +class phpbb_json_response { - private static $data = array(); - /** * Send the data to the client and exit the script. * * @param array $data Any additional data to send. * @param bool $exit Will exit the script if true. */ - public static function send($data = false, $exit = true) + public function send($data, $exit = true) { - if ($data) - { - self::add($data); - } - header('Content-type: application/json'); - echo json_encode(self::$data); + echo json_encode($data); if ($exit) { @@ -46,14 +39,4 @@ class JSON exit_handler(); } } - - /** - * Saves some data to be written when JSON::send() is called. - * - * @param array $data Data to save to be sent. - */ - public static function add($data) - { - self::$data = array_merge(self::$data, $data); - } } diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index 3f0e97b48a..efe928b387 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -25,7 +25,7 @@ class ucp_zebra function main($id, $mode) { - global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; + global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $request; $submit = (isset($_POST['submit']) || isset($_GET['add']) || isset($_GET['remove'])) ? true : false; $s_hidden_fields = ''; @@ -198,13 +198,25 @@ class ucp_zebra } } } - - if ($updated) + + if ($request->is_ajax()) { - JSON::add(array( - 'message' => $user->lang[$l_mode . '_UPDATED'], - 'success' => true + $message = ($updated) ? $user->lang[$l_mode . '_UPDATED'] : implode('
', $error); + + $json_response = new phpbb_json_response; + $json_response->send(array( + 'success' => $updated, + + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => array( + 'time' => 3, + 'url' => $this->u_action + ) )); + } + else if ($updated) + { meta_refresh(3, $this->u_action); $message = $user->lang[$l_mode . '_UPDATED'] . '
' . implode('
', $error) . ((sizeof($error)) ? '
' : '') . '
' . sprintf($user->lang['RETURN_UCP'], '', ''); trigger_error($message); diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 1b9262f585..8814d105e1 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -365,7 +365,7 @@ phpbb.add_ajax_callback('post_delete', function(el) { } }).add_ajax_callback('zebra', function(el, res) { if (res.success) { - $('.zebra').html(res.message); + $('.zebra').html(res.MESSAGE_TEXT); $($('.zebra').get(1)).remove(); } });; From 11112314f757f4a6c65852817fba0f1a2f4526d2 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 12:46:33 +0100 Subject: [PATCH 032/120] [ticket/10271] AJAXified various deletions in the ACP. The following places have had deletion AJAXified: * Smilies and icons * Word censors * BBCodes * Attachment groups * Groups * Admin / User / Moderator / Forum roles * Report / denial reasons * Module management * Custom profile fields PHPBB3-10271 --- phpBB/adm/style/acp_attachments.html | 2 +- phpBB/adm/style/acp_bbcodes.html | 2 +- phpBB/adm/style/acp_groups.html | 2 +- phpBB/adm/style/acp_icons.html | 2 +- phpBB/adm/style/acp_modules.html | 2 +- phpBB/adm/style/acp_permission_roles.html | 2 +- phpBB/adm/style/acp_profile.html | 4 ++-- phpBB/adm/style/acp_ranks.html | 2 +- phpBB/adm/style/acp_reasons.html | 2 +- phpBB/adm/style/acp_words.html | 2 +- phpBB/includes/acp/acp_bbcodes.php | 14 +++++++++++++- phpBB/includes/acp/acp_icons.php | 12 ++++++++++++ phpBB/includes/acp/acp_ranks.php | 14 +++++++++++++- phpBB/language/en/acp/posting.php | 1 + phpBB/styles/script.js | 3 +++ 15 files changed, 53 insertions(+), 13 deletions(-) diff --git a/phpBB/adm/style/acp_attachments.html b/phpBB/adm/style/acp_attachments.html index 33ef8062a6..c2f8b34792 100644 --- a/phpBB/adm/style/acp_attachments.html +++ b/phpBB/adm/style/acp_attachments.html @@ -248,7 +248,7 @@
» {L_ALLOWED_IN_PM_POST} {groups.CATEGORY} -  {ICON_EDIT}  {ICON_DELETE}  +  {ICON_EDIT}  {ICON_DELETE}  diff --git a/phpBB/adm/style/acp_bbcodes.html b/phpBB/adm/style/acp_bbcodes.html index b85e8eca81..5939af24ae 100644 --- a/phpBB/adm/style/acp_bbcodes.html +++ b/phpBB/adm/style/acp_bbcodes.html @@ -101,7 +101,7 @@ {bbcodes.BBCODE_TAG} - {ICON_EDIT} {ICON_DELETE} + {ICON_EDIT} {ICON_DELETE} diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 158751623a..ed94fa985e 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -350,7 +350,7 @@ {groups.TOTAL_MEMBERS} {L_SETTINGS} {L_MEMBERS} - {L_DELETE}{L_DELETE} + {L_DELETE}{L_DELETE} diff --git a/phpBB/adm/style/acp_icons.html b/phpBB/adm/style/acp_icons.html index 85b5343666..a8864d42f7 100644 --- a/phpBB/adm/style/acp_icons.html +++ b/phpBB/adm/style/acp_icons.html @@ -245,7 +245,7 @@ {ICON_MOVE_UP_DISABLED}{ICON_MOVE_UP}  {ICON_MOVE_DOWN_DISABLED}{ICON_MOVE_DOWN} -  {ICON_EDIT} {ICON_DELETE} +  {ICON_EDIT} {ICON_DELETE} diff --git a/phpBB/adm/style/acp_modules.html b/phpBB/adm/style/acp_modules.html index 3f1c0bf50b..6c4645e80c 100644 --- a/phpBB/adm/style/acp_modules.html +++ b/phpBB/adm/style/acp_modules.html @@ -164,7 +164,7 @@ {ICON_MOVE_DOWN_DISABLED} {ICON_EDIT} - {ICON_DELETE} + {ICON_DELETE} diff --git a/phpBB/adm/style/acp_permission_roles.html b/phpBB/adm/style/acp_permission_roles.html index 658d8dd0c8..2ac77af25d 100644 --- a/phpBB/adm/style/acp_permission_roles.html +++ b/phpBB/adm/style/acp_permission_roles.html @@ -174,7 +174,7 @@ {ICON_MOVE_DOWN_DISABLED} {ICON_EDIT} - {ICON_DELETE} + {ICON_DELETE} diff --git a/phpBB/adm/style/acp_profile.html b/phpBB/adm/style/acp_profile.html index 0ac0d78a64..7804533d1a 100644 --- a/phpBB/adm/style/acp_profile.html +++ b/phpBB/adm/style/acp_profile.html @@ -195,7 +195,7 @@ {fields.FIELD_IDENT} {fields.FIELD_TYPE} - {fields.L_ACTIVATE_DEACTIVATE} | {L_TRANSLATE} + {fields.L_ACTIVATE_DEACTIVATE} | {L_TRANSLATE} @@ -213,7 +213,7 @@ {ICON_EDIT_DISABLED} - {ICON_DELETE} + {ICON_DELETE} diff --git a/phpBB/adm/style/acp_ranks.html b/phpBB/adm/style/acp_ranks.html index 2f77a256b1..7fb7da7095 100644 --- a/phpBB/adm/style/acp_ranks.html +++ b/phpBB/adm/style/acp_ranks.html @@ -80,7 +80,7 @@ {ranks.RANK_TITLE}  -   {ranks.RANK_TITLE}   -  {ranks.MIN_POSTS} - {ICON_EDIT} {ICON_DELETE} + {ICON_EDIT} {ICON_DELETE} diff --git a/phpBB/adm/style/acp_reasons.html b/phpBB/adm/style/acp_reasons.html index 522aec5930..7cf2cce4c9 100644 --- a/phpBB/adm/style/acp_reasons.html +++ b/phpBB/adm/style/acp_reasons.html @@ -99,7 +99,7 @@ {ICON_EDIT} - {ICON_DELETE} + {ICON_DELETE} {ICON_DELETE_DISABLED} diff --git a/phpBB/adm/style/acp_words.html b/phpBB/adm/style/acp_words.html index 113f58ef92..4acd75f933 100644 --- a/phpBB/adm/style/acp_words.html +++ b/phpBB/adm/style/acp_words.html @@ -60,7 +60,7 @@ {words.WORD} {words.REPLACEMENT} -  {ICON_EDIT}  {ICON_DELETE}  +  {ICON_EDIT}  {ICON_DELETE}  diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index a3822a982a..e537d7a8b9 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -24,7 +24,7 @@ class acp_bbcodes function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/posting'); @@ -272,6 +272,18 @@ class acp_bbcodes $db->sql_query('DELETE FROM ' . BBCODES_TABLE . " WHERE bbcode_id = $bbcode_id"); $cache->destroy('sql', BBCODES_TABLE); add_log('admin', 'LOG_BBCODE_DELETE', $row['bbcode_tag']); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $user->lang['BBCODE_DELETED'], + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else { diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php index 49a092f16b..bfe17c5007 100644 --- a/phpBB/includes/acp/acp_icons.php +++ b/phpBB/includes/acp/acp_icons.php @@ -782,6 +782,18 @@ class acp_icons $cache->destroy('_icons'); $cache->destroy('sql', $table); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $notice, + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else { diff --git a/phpBB/includes/acp/acp_ranks.php b/phpBB/includes/acp/acp_ranks.php index ec5a76df87..d9ed5b17f1 100644 --- a/phpBB/includes/acp/acp_ranks.php +++ b/phpBB/includes/acp/acp_ranks.php @@ -24,7 +24,7 @@ class acp_ranks function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/posting'); @@ -122,6 +122,18 @@ class acp_ranks $cache->destroy('_ranks'); add_log('admin', 'LOG_RANK_REMOVED', $rank_title); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $user->lang['RANK_REMOVED'], + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else { diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index 84cf640d1f..76d4869990 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -45,6 +45,7 @@ $lang = array_merge($lang, array( 'BBCODE_ADDED' => 'BBCode added successfully.', 'BBCODE_EDITED' => 'BBCode edited successfully.', + 'BBCODE_DELETED' => 'The BBCode has been removed successfully.', 'BBCODE_NOT_EXIST' => 'The BBCode you selected does not exist.', 'BBCODE_HELPLINE' => 'Help line', 'BBCODE_HELPLINE_EXPLAIN' => 'This field contains the mouse over text of the BBCode.', diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 8814d105e1..85dcdb25f5 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -363,6 +363,9 @@ phpbb.add_ajax_callback('post_delete', function(el) { tr.next().find('.up').html('Move up'); phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); } +}).add_ajax_callback('row_delete', function(el) { + var tr = $(el).parents('tr'); + tr.remove(); }).add_ajax_callback('zebra', function(el, res) { if (res.success) { $('.zebra').html(res.MESSAGE_TEXT); From 1cb3b595ec70730429a9c8654b248fc6d50cf1b3 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 15:45:51 +0100 Subject: [PATCH 033/120] [ticket/10271] AJAXified the styles tab in the ACP. PHPBB3-10271 --- phpBB/adm/style/acp_styles.html | 2 +- phpBB/includes/acp/acp_styles.php | 17 +++++++++++++++-- phpBB/language/en/acp/styles.php | 2 ++ phpBB/styles/script.js | 22 ++++++++++++++++------ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/phpBB/adm/style/acp_styles.html b/phpBB/adm/style/acp_styles.html index dc89aa247a..dfc8def646 100644 --- a/phpBB/adm/style/acp_styles.html +++ b/phpBB/adm/style/acp_styles.html @@ -288,7 +288,7 @@ - {installed.L_STYLE_ACT_DEACT} | + {installed.L_STYLE_ACT_DEACT} | {installed.S_ACTIONS} diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 7b449d3b35..a241dd3d10 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -28,7 +28,7 @@ class acp_styles function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; // Hardcoded template bitfield to add for new templates @@ -185,6 +185,18 @@ inherit_from = {INHERIT_FROM} WHERE forum_style = ' . $style_id; $db->sql_query($sql); } + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'text' => $user->lang['STYLE_' . (($action == 'activate') ? 'DE' : '') . 'ACTIVATE'], + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $user->lang['STYLE_' . strtoupper($action) . 'D'], + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else if ($action == 'deactivate') { @@ -335,7 +347,8 @@ inherit_from = {INHERIT_FROM} $s_actions = array(); foreach ($actions as $option) { - $s_actions[] = '' . $user->lang[strtoupper($option)] . ''; + $data_ajax = ($option == 'refresh') ? ' data-ajax="true"' : ''; + $s_actions[] = '' . $user->lang[strtoupper($option)] . ''; } $template->assign_block_vars('installed', array( diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index 59df82477e..3a96100947 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -295,9 +295,11 @@ $lang = array_merge($lang, array( 'SELECTED_THEME_FILE' => 'Selected theme file', 'STORE_FILESYSTEM' => 'Filesystem', 'STYLE_ACTIVATE' => 'Activate', + 'STYLE_ACTIVATED' => 'Style activated successfully', 'STYLE_ACTIVE' => 'Active', 'STYLE_ADDED' => 'Style added successfully.', 'STYLE_DEACTIVATE' => 'Deactivate', + 'STYLE_DEACTIVATED' => 'Style deactivated successfully', 'STYLE_DEFAULT' => 'Make default style', 'STYLE_DELETED' => 'Style deleted successfully.', 'STYLE_DETAILS_UPDATED' => 'Style edited successfully.', diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 85dcdb25f5..44b21906cc 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -225,10 +225,9 @@ phpbb.ajaxify = function(options, refresh, callback) { { // It is a standard link, no confirm_box required. var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - callback = phpbb.ajax_callbacks[callback]; - if (typeof callback === 'function') + if (typeof phpbb.ajax_callbacks[callback] === 'function') { - callback(that, (is_form) ? act : null); + phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null); } handle_refresh(res.REFRESH_DATA, refresh, alert); } @@ -243,10 +242,9 @@ phpbb.ajaxify = function(options, refresh, callback) { phpbb.loading_alert(); $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - callback = phpbb.ajax_callbacks[callback]; - if (typeof callback === 'function') + if (typeof phpbb.ajax_callbacks[callback] === 'function') { - callback(that, res, (is_form) ? act : null); + phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null); } handle_refresh(res.REFRESH_DATA, refresh, alert); }); @@ -363,6 +361,18 @@ phpbb.add_ajax_callback('post_delete', function(el) { tr.next().find('.up').html('Move up'); phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); } +}).add_ajax_callback('style_act_deact', function(el, res) { + $(el).text(res.text); + var new_href = $(el).attr('href'); + if (new_href.indexOf('deactivate') !== -1) + { + new_href = new_href.replace('deactivate', 'activate') + } + else + { + new_href = new_href.replace('activate', 'deactivate') + } + $(el).attr('href', new_href); }).add_ajax_callback('row_delete', function(el) { var tr = $(el).parents('tr'); tr.remove(); From 4ae74cd4b450ae4cca956f6f3e2371429f67deec Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 16:06:06 +0100 Subject: [PATCH 034/120] [ticket/10271] AJAXified buttons on acp_main. PHPBB3-10271 --- phpBB/adm/style/acp_main.html | 14 ++++++------ phpBB/includes/acp/acp_main.php | 38 ++++++++++++++++++++++++++++++-- phpBB/language/en/acp/common.php | 7 ++++++ 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/phpBB/adm/style/acp_main.html b/phpBB/adm/style/acp_main.html index 63ca3a1c79..d9f833d878 100644 --- a/phpBB/adm/style/acp_main.html +++ b/phpBB/adm/style/acp_main.html @@ -152,35 +152,35 @@
{L_STATISTIC_RESYNC_OPTIONS} -
+

 
-
+

 
-
+

{L_RESYNC_STATS_EXPLAIN}
-
+

{L_RESYNC_POSTCOUNTS_EXPLAIN}
-
+

{L_RESYNC_POST_MARKING_EXPLAIN}
@@ -188,7 +188,7 @@ -
+

{L_PURGE_SESSIONS_EXPLAIN}
@@ -196,7 +196,7 @@ -
+

{L_PURGE_CACHE_EXPLAIN}
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 4c9ee85982..144b225766 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -24,7 +24,7 @@ class acp_main function main($id, $mode) { - global $config, $db, $user, $auth, $template; + global $config, $db, $user, $auth, $template, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx; // Show restore permissions notice @@ -129,6 +129,11 @@ class acp_main set_config('record_online_users', 1, true); set_config('record_online_date', time(), true); add_log('admin', 'LOG_RESET_ONLINE'); + + if ($request->is_ajax()) + { + trigger_error('RESET_ONLINE_SUCCESS'); + } break; case 'stats': @@ -179,6 +184,11 @@ class acp_main update_last_username(); add_log('admin', 'LOG_RESYNC_STATS'); + + if ($request->is_ajax()) + { + trigger_error('RESYNC_STATS_SUCCESS'); + } break; case 'user': @@ -241,7 +251,11 @@ class acp_main } add_log('admin', 'LOG_RESYNC_POSTCOUNTS'); - + + if ($request->is_ajax()) + { + trigger_error('RESYNC_POSTCOUNTS_SUCCESS'); + } break; case 'date': @@ -252,6 +266,11 @@ class acp_main set_config('board_startdate', time() - 1); add_log('admin', 'LOG_RESET_DATE'); + + if ($request->is_ajax()) + { + trigger_error('RESET_DATE_SUCCESS'); + } break; case 'db_track': @@ -327,6 +346,11 @@ class acp_main } add_log('admin', 'LOG_RESYNC_POST_MARKING'); + + if ($request->is_ajax()) + { + trigger_error('RESYNC_POST_MARKING_SUCCESS'); + } break; case 'purge_cache': @@ -338,6 +362,11 @@ class acp_main cache_moderators(); add_log('admin', 'LOG_PURGE_CACHE'); + + if ($request->is_ajax()) + { + trigger_error('PURGE_CACHE_SUCCESS'); + } break; case 'purge_sessions': @@ -384,6 +413,11 @@ class acp_main $db->sql_query($sql); add_log('admin', 'LOG_PURGE_SESSIONS'); + + if ($request->is_ajax()) + { + trigger_error('PURGE_SESSIONS_SUCCESS'); + } break; } } diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 242329a041..f96947b580 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -368,25 +368,32 @@ $lang = array_merge($lang, array( 'PURGE_CACHE' => 'Purge the cache', 'PURGE_CACHE_CONFIRM' => 'Are you sure you wish to purge the cache?', 'PURGE_CACHE_EXPLAIN' => 'Purge all cache related items, this includes any cached template files or queries.', + 'PURGE_CACHE_SUCCESS' => 'Cache successfully purged.', 'PURGE_SESSIONS' => 'Purge all sessions', 'PURGE_SESSIONS_CONFIRM' => 'Are you sure you wish to purge all sessions? This will log out all users.', 'PURGE_SESSIONS_EXPLAIN' => 'Purge all sessions. This will log out all users by truncating the session table.', + 'PURGE_SESSIONS_SUCCESS' => 'Sessions successfully purged.', 'RESET_DATE' => 'Reset board’s start date', 'RESET_DATE_CONFIRM' => 'Are you sure you wish to reset the board’s start date?', + 'RESET_DATE_SUCCESS' => 'Board’s start date reset', 'RESET_ONLINE' => 'Reset most users ever online', 'RESET_ONLINE_CONFIRM' => 'Are you sure you wish to reset the most users ever online counter?', + 'RESET_ONLINE_SUCCESS' => 'Most users ever online reset', 'RESYNC_FILES_STATS_CONFIRM' => 'Are you sure you wish to resynchronise files statistics?', 'RESYNC_POSTCOUNTS' => 'Resynchronise post counts', 'RESYNC_POSTCOUNTS_EXPLAIN' => 'Only existing posts will be taken into consideration. Pruned posts will not be counted.', 'RESYNC_POSTCOUNTS_CONFIRM' => 'Are you sure you wish to resynchronise post counts?', + 'RESYNC_POSTCOUNTS_SUCCESS' => 'Resynchronised post counts', 'RESYNC_POST_MARKING' => 'Resynchronise dotted topics', 'RESYNC_POST_MARKING_CONFIRM' => 'Are you sure you wish to resynchronise dotted topics?', 'RESYNC_POST_MARKING_EXPLAIN' => 'First unmarks all topics and then correctly marks topics that have seen any activity during the past six months.', + 'RESYNC_POST_MARKING_SUCCESS' => 'Resynchronised dotted topics', 'RESYNC_STATS' => 'Resynchronise statistics', 'RESYNC_STATS_CONFIRM' => 'Are you sure you wish to resynchronise statistics?', 'RESYNC_STATS_EXPLAIN' => 'Recalculates the total number of posts, topics, users and files.', + 'RESYNC_STATS_SUCCESS' => 'Resynchronised statistics', 'RUN' => 'Run now', 'STATISTIC' => 'Statistic', From fc7cb6a70b9e0422bf5658bb9f49de831be08718 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 16:25:54 +0100 Subject: [PATCH 035/120] [ticket/10270] Made the alert after an AJAX operation optional. PHPBB3-10270 --- phpBB/styles/script.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 44b21906cc..16d64319d9 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -224,7 +224,11 @@ phpbb.ajaxify = function(options, refresh, callback) { if (typeof res.S_CONFIRM_ACTION === 'undefined') { // It is a standard link, no confirm_box required. - var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + if (typeof res.MESSAGE_TITLE !== 'undefined') + { + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + } + if (typeof phpbb.ajax_callbacks[callback] === 'function') { phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null); @@ -241,7 +245,11 @@ phpbb.ajaxify = function(options, refresh, callback) { path = res.S_CONFIRM_ACTION; phpbb.loading_alert(); $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { - var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + if (typeof res.MESSAGE_TITLE !== 'undefined') + { + var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); + } + if (typeof phpbb.ajax_callbacks[callback] === 'function') { phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null); From e7e09f8da26abf0d4e625653d14d68774050a244 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 16:39:25 +0100 Subject: [PATCH 036/120] [ticket/10272] AJAXified the bots page in the ACP. PHPBB3-10272 --- phpBB/adm/style/acp_bots.html | 4 ++-- phpBB/includes/acp/acp_bots.php | 10 +++++++++- phpBB/styles/script.js | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/phpBB/adm/style/acp_bots.html b/phpBB/adm/style/acp_bots.html index 886005caa3..e0e9588364 100644 --- a/phpBB/adm/style/acp_bots.html +++ b/phpBB/adm/style/acp_bots.html @@ -76,9 +76,9 @@ {bots.BOT_NAME}  {bots.LAST_VISIT}  -  {bots.L_ACTIVATE_DEACTIVATE}  +  {bots.L_ACTIVATE_DEACTIVATE}   {L_EDIT}  -  {L_DELETE}  +  {L_DELETE}  diff --git a/phpBB/includes/acp/acp_bots.php b/phpBB/includes/acp/acp_bots.php index f080b3c9fb..b9dd6664f4 100644 --- a/phpBB/includes/acp/acp_bots.php +++ b/phpBB/includes/acp/acp_bots.php @@ -24,7 +24,7 @@ class acp_bots function main($id, $mode) { - global $config, $db, $user, $auth, $template, $cache; + global $config, $db, $user, $auth, $template, $cache, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; $action = request_var('action', ''); @@ -352,6 +352,14 @@ class acp_bots break; } + + if ($request->is_ajax() && ($action == 'activate' || $action == 'deactivate')) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'text' => $user->lang['BOT_' . (($action == 'activate') ? 'DE' : '') . 'ACTIVATE'], + )); + } $s_options = ''; $_options = array('activate' => 'BOT_ACTIVATE', 'deactivate' => 'BOT_DEACTIVATE', 'delete' => 'DELETE'); diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 16d64319d9..59fe7cf8e2 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -228,6 +228,10 @@ phpbb.ajaxify = function(options, refresh, callback) { { var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); } + else + { + dark.fadeOut(); + } if (typeof phpbb.ajax_callbacks[callback] === 'function') { @@ -249,6 +253,10 @@ phpbb.ajaxify = function(options, refresh, callback) { { var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); } + else + { + dark.fadeOut(); + } if (typeof phpbb.ajax_callbacks[callback] === 'function') { From bcb824a9f2407523c84501ac1d4260bb27661ff1 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 16:59:05 +0100 Subject: [PATCH 037/120] [ticket/10272] Renamed AJAX callback "style_act_deact" to "act_deact". PHPBB3-10272 --- phpBB/adm/style/acp_bots.html | 2 +- phpBB/adm/style/acp_modules.html | 2 +- phpBB/adm/style/acp_profile.html | 2 +- phpBB/adm/style/acp_styles.html | 2 +- phpBB/styles/script.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/adm/style/acp_bots.html b/phpBB/adm/style/acp_bots.html index e0e9588364..3a5ef72acd 100644 --- a/phpBB/adm/style/acp_bots.html +++ b/phpBB/adm/style/acp_bots.html @@ -76,7 +76,7 @@ {bots.BOT_NAME}  {bots.LAST_VISIT}  -  {bots.L_ACTIVATE_DEACTIVATE}  +  {bots.L_ACTIVATE_DEACTIVATE}   {L_EDIT}   {L_DELETE}  diff --git a/phpBB/adm/style/acp_modules.html b/phpBB/adm/style/acp_modules.html index 6c4645e80c..380a037977 100644 --- a/phpBB/adm/style/acp_modules.html +++ b/phpBB/adm/style/acp_modules.html @@ -148,7 +148,7 @@ {modules.MODULE_IMAGE} {modules.MODULE_TITLE} [{L_HIDDEN_MODULE}] -  {L_DISABLE}{L_ENABLE}  +  {L_DISABLE}{L_ENABLE}  {ICON_MOVE_UP_DISABLED} diff --git a/phpBB/adm/style/acp_profile.html b/phpBB/adm/style/acp_profile.html index 7804533d1a..d0920774f1 100644 --- a/phpBB/adm/style/acp_profile.html +++ b/phpBB/adm/style/acp_profile.html @@ -195,7 +195,7 @@ {fields.FIELD_IDENT} {fields.FIELD_TYPE} - {fields.L_ACTIVATE_DEACTIVATE} | {L_TRANSLATE} + {fields.L_ACTIVATE_DEACTIVATE} | {L_TRANSLATE} diff --git a/phpBB/adm/style/acp_styles.html b/phpBB/adm/style/acp_styles.html index dfc8def646..0b98dea603 100644 --- a/phpBB/adm/style/acp_styles.html +++ b/phpBB/adm/style/acp_styles.html @@ -288,7 +288,7 @@ - {installed.L_STYLE_ACT_DEACT} | + {installed.L_STYLE_ACT_DEACT} | {installed.S_ACTIONS} diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 59fe7cf8e2..4630c4fed1 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -377,7 +377,7 @@ phpbb.add_ajax_callback('post_delete', function(el) { tr.next().find('.up').html('Move up'); phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); } -}).add_ajax_callback('style_act_deact', function(el, res) { +}).add_ajax_callback('act_deact', function(el, res) { $(el).text(res.text); var new_href = $(el).attr('href'); if (new_href.indexOf('deactivate') !== -1) From f85faf435da19f877b7633e208ae103a3d954355 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 22:29:52 +0100 Subject: [PATCH 038/120] [ticket/10271] Cleaned up phpbb.ajaxify. Reduced a lot of duplicate code and made it more efficient. PHPBB3-10271 --- phpBB/styles/script.js | 70 +++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 4630c4fed1..4d7d6e1425 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -174,32 +174,6 @@ phpbb.parse_querystring = function(string) { * @param function callback Callback. */ phpbb.ajaxify = function(options, refresh, callback) { - - // Private function to handle refreshes - function handle_refresh(data, refresh, div) - { - if (!data) - { - return; - } - - refresh = ((typeof refresh === 'function') ? refresh(data.url) : - (typeof refresh === 'boolean') && refresh); - - setTimeout(function() { - if (refresh) - { - window.location = data.url; - } - else - { - dark.fadeOut(function() { - div.remove(); - }); - } - }, data.time * 1000); - } - var selector = (typeof options === 'string') ? options : options.selector; var is_form = $(selector).is('form'); if (is_form && typeof selector === 'object') @@ -237,7 +211,29 @@ phpbb.ajaxify = function(options, refresh, callback) { { phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null); } - handle_refresh(res.REFRESH_DATA, refresh, alert); + + if (res.REFRESH_DATA) + { + if (typeof refresh === 'function') + { + refresh = refresh(res.REFRESH_DATA.url); + } + else if (typeof refresh !== 'boolean') + { + refresh = false; + } + + setTimeout(function() { + if (refresh) + { + window.location = res.REFRESH_DATA.url; + } + + dark.fadeOut(function() { + alert.remove(); + }); + }, res.REFRESH_DATA.time * 1000); + } } else { @@ -245,25 +241,9 @@ phpbb.ajaxify = function(options, refresh, callback) { phpbb.confirm(res.MESSAGE_TEXT, function(del) { if (del) { - data = $('' + res.S_HIDDEN_FIELDS + '').serialize(); - path = res.S_CONFIRM_ACTION; phpbb.loading_alert(); - $.post(path, data + '&confirm=' + res.YES_VALUE, function(res) { - if (typeof res.MESSAGE_TITLE !== 'undefined') - { - var alert = phpbb.alert(res.MESSAGE_TITLE, res.MESSAGE_TEXT); - } - else - { - dark.fadeOut(); - } - - if (typeof phpbb.ajax_callbacks[callback] === 'function') - { - phpbb.ajax_callbacks[callback](that, res, (is_form) ? act : null); - } - handle_refresh(res.REFRESH_DATA, refresh, alert); - }); + data = $('
' + res.S_HIDDEN_FIELDS + '
').serialize(); + $.post(res.S_CONFIRM_ACTION, data + '&confirm=' + res.YES_VALUE, return_handler); } }, false); } From 53201da98c7b9ca88d1b43f1b59b8d17208c2025 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 22:53:26 +0100 Subject: [PATCH 039/120] [ticket/10270] Increased the speed of the animations. PHPBB3-10270 --- phpBB/styles/script.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 4d7d6e1425..0e885bceed 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -15,12 +15,12 @@ var dark = $('#darkenwrapper'), phpbb.loading_alert = function() { if (dark.is(':visible')) { - loading_alert.fadeIn(); + loading_alert.fadeIn(200); } else { loading_alert.show(); - dark.fadeIn(function() { + dark.fadeIn(200, function() { setTimeout(function() { if (loading_alert.is(':visible')) { @@ -52,7 +52,7 @@ phpbb.alert = function(title, msg, fadedark) { }); $(dark).one('click', function(e) { var fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; - fade.fadeOut(function() { + fade.fadeOut(200, function() { div.remove(); }); return false; @@ -68,21 +68,21 @@ phpbb.alert = function(title, msg, fadedark) { if (loading_alert.is(':visible')) { - loading_alert.fadeOut(function() { + loading_alert.fadeOut(200, function() { $(dark).append(div); - div.fadeIn(); + div.fadeIn(200); }); } else if (dark.is(':visible')) { $(dark).append(div); - div.fadeIn(); + div.fadeIn(200); } else { $(dark).append(div); div.show(); - dark.fadeIn(); + dark.fadeIn(200); } return div; @@ -107,7 +107,7 @@ phpbb.confirm = function(msg, callback, fadedark) { div.find('.jalertbut').bind('click', function() { var res = this.value === 'Yes'; var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; - fade.fadeOut(function() { + fade.fadeOut(200, function() { div.remove(); }); callback(res); @@ -127,21 +127,21 @@ phpbb.confirm = function(msg, callback, fadedark) { if (loading_alert.is(':visible')) { - loading_alert.fadeOut(function() { + loading_alert.fadeOut(200, function() { $(dark).append(div); - div.fadeIn(); + div.fadeIn(200); }); } else if (dark.is(':visible')) { $(dark).append(div); - div.fadeIn(); + div.fadeIn(200); } else { $(dark).append(div); div.show(); - dark.fadeIn(); + dark.fadeIn(200); } return div; @@ -204,7 +204,7 @@ phpbb.ajaxify = function(options, refresh, callback) { } else { - dark.fadeOut(); + dark.fadeOut(200); } if (typeof phpbb.ajax_callbacks[callback] === 'function') @@ -229,7 +229,7 @@ phpbb.ajaxify = function(options, refresh, callback) { window.location = res.REFRESH_DATA.url; } - dark.fadeOut(function() { + dark.fadeOut(200, function() { alert.remove(); }); }, res.REFRESH_DATA.time * 1000); @@ -249,7 +249,7 @@ phpbb.ajaxify = function(options, refresh, callback) { } } - var run_exception = typeof options.exception === 'function'; + var run_exception = (typeof options.exception === 'function'); if (is_form) { act = /action\[([a-z]+)\]/.exec(this.name); From 431a78f34696707973f1c67f4417d6ee85713ee6 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 11 Sep 2011 15:42:00 +0100 Subject: [PATCH 040/120] [ticket/10270] Got rid of the temporary jQuery for the AJAX changes. The jQuery library wasn't included before, so a temporary one was included. Now that igorws jQuery patch has been merged, the temporary library can be removed. PHPBB3-10270 --- phpBB/adm/style/overall_footer.html | 5 +---- phpBB/styles/prosilver/template/overall_footer.html | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/phpBB/adm/style/overall_footer.html b/phpBB/adm/style/overall_footer.html index 625121f1bd..ec3e6a30d3 100644 --- a/phpBB/adm/style/overall_footer.html +++ b/phpBB/adm/style/overall_footer.html @@ -22,15 +22,12 @@
 

{L_LOADING}

{L_PLEASE_WAIT}

- - - - + diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index 37caaf7cca..20f6ee1f91 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -29,9 +29,6 @@
 

{L_LOADING}

{L_PLEASE_WAIT}

- - - @@ -43,6 +40,7 @@ + From 8c0e72cd9e52c754bd6a851de73862b3c6485840 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 11 Sep 2011 15:54:03 +0100 Subject: [PATCH 041/120] [ticket/10270] Sped up animations of popups. They were too slow and were hampering the user experience on boards with a fast connection such as local boards. PHPBB3-10270 --- phpBB/styles/script.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index 0e885bceed..cafb11c9e4 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -15,12 +15,12 @@ var dark = $('#darkenwrapper'), phpbb.loading_alert = function() { if (dark.is(':visible')) { - loading_alert.fadeIn(200); + loading_alert.fadeIn(100); } else { loading_alert.show(); - dark.fadeIn(200, function() { + dark.fadeIn(100, function() { setTimeout(function() { if (loading_alert.is(':visible')) { @@ -52,7 +52,7 @@ phpbb.alert = function(title, msg, fadedark) { }); $(dark).one('click', function(e) { var fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; - fade.fadeOut(200, function() { + fade.fadeOut(100, function() { div.remove(); }); return false; @@ -68,21 +68,21 @@ phpbb.alert = function(title, msg, fadedark) { if (loading_alert.is(':visible')) { - loading_alert.fadeOut(200, function() { + loading_alert.fadeOut(100, function() { $(dark).append(div); - div.fadeIn(200); + div.fadeIn(100); }); } else if (dark.is(':visible')) { $(dark).append(div); - div.fadeIn(200); + div.fadeIn(100); } else { $(dark).append(div); div.show(); - dark.fadeIn(200); + dark.fadeIn(100); } return div; @@ -107,7 +107,7 @@ phpbb.confirm = function(msg, callback, fadedark) { div.find('.jalertbut').bind('click', function() { var res = this.value === 'Yes'; var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; - fade.fadeOut(200, function() { + fade.fadeOut(100, function() { div.remove(); }); callback(res); @@ -127,21 +127,21 @@ phpbb.confirm = function(msg, callback, fadedark) { if (loading_alert.is(':visible')) { - loading_alert.fadeOut(200, function() { + loading_alert.fadeOut(100, function() { $(dark).append(div); - div.fadeIn(200); + div.fadeIn(100); }); } else if (dark.is(':visible')) { $(dark).append(div); - div.fadeIn(200); + div.fadeIn(100); } else { $(dark).append(div); div.show(); - dark.fadeIn(200); + dark.fadeIn(100); } return div; @@ -204,7 +204,7 @@ phpbb.ajaxify = function(options, refresh, callback) { } else { - dark.fadeOut(200); + dark.fadeOut(100); } if (typeof phpbb.ajax_callbacks[callback] === 'function') @@ -229,7 +229,7 @@ phpbb.ajaxify = function(options, refresh, callback) { window.location = res.REFRESH_DATA.url; } - dark.fadeOut(200, function() { + dark.fadeOut(100, function() { alert.remove(); }); }, res.REFRESH_DATA.time * 1000); From dbb81fbd2bfadf52502f2200b0420953d98ffb56 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 24 Sep 2011 16:35:46 +0100 Subject: [PATCH 042/120] [ticket/10328] Added capital to "Content-type" in phpbb_json_response. It was originally Content-type, but has been replaced with Content-Type, which is correct. PHPBB3-10328 --- phpBB/includes/json_response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/json_response.php b/phpBB/includes/json_response.php index 95d02e3c0e..dfddea98f2 100644 --- a/phpBB/includes/json_response.php +++ b/phpBB/includes/json_response.php @@ -30,7 +30,7 @@ class phpbb_json_response */ public function send($data, $exit = true) { - header('Content-type: application/json'); + header('Content-Type: application/json'); echo json_encode($data); if ($exit) From 233c2d51cfc1ffc33b03f1ab73c016d07828bab4 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 24 Sep 2011 16:42:22 +0100 Subject: [PATCH 043/120] [ticket/10270] Removed some unnecessary calls to $() in script.js. Sometimes, jQuery objects were being sent through the jQuery function again, wasting resources. PHPBB3-10270 --- phpBB/styles/script.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/phpBB/styles/script.js b/phpBB/styles/script.js index cafb11c9e4..dd9d2532cc 100644 --- a/phpBB/styles/script.js +++ b/phpBB/styles/script.js @@ -46,11 +46,11 @@ phpbb.loading_alert = function() { phpbb.alert = function(title, msg, fadedark) { var div = $('

' + title + '

' + msg + '

'); - $(div).bind('click', function(e) { + div.bind('click', function(e) { e.stopPropagation(); return true; }); - $(dark).one('click', function(e) { + dark.one('click', function(e) { var fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; fade.fadeOut(100, function() { div.remove(); @@ -60,7 +60,7 @@ phpbb.alert = function(title, msg, fadedark) { $(document).bind('keydown', function(e) { if (e.keyCode === 13 || e.keyCode === 27) { - $(dark).trigger('click'); + dark.trigger('click'); return false; } return true; @@ -69,18 +69,18 @@ phpbb.alert = function(title, msg, fadedark) { if (loading_alert.is(':visible')) { loading_alert.fadeOut(100, function() { - $(dark).append(div); + dark.append(div); div.fadeIn(100); }); } else if (dark.is(':visible')) { - $(dark).append(div); + dark.append(div); div.fadeIn(100); } else { - $(dark).append(div); + dark.append(div); div.show(); dark.fadeIn(100); } @@ -128,18 +128,18 @@ phpbb.confirm = function(msg, callback, fadedark) { if (loading_alert.is(':visible')) { loading_alert.fadeOut(100, function() { - $(dark).append(div); + dark.append(div); div.fadeIn(100); }); } else if (dark.is(':visible')) { - $(dark).append(div); + dark.append(div); div.fadeIn(100); } else { - $(dark).append(div); + dark.append(div); div.show(); dark.fadeIn(100); } @@ -174,18 +174,14 @@ phpbb.parse_querystring = function(string) { * @param function callback Callback. */ phpbb.ajaxify = function(options, refresh, callback) { - var selector = (typeof options === 'string') ? options : options.selector; - var is_form = $(selector).is('form'); - if (is_form && typeof selector === 'object') + var selector = $((typeof options === 'string') ? options : options.selector); + var is_form = selector.is('form'); + if (is_form) { - selector = $(selector).find('input:submit'); - } - else if (is_form) - { - selector += ' input:submit'; + selector = selector.find('input:submit'); } - $(selector).click(function() { + selector.click(function() { var act, data, path, that = this; if ($(this).data('ajax') == false) From 818d98916873945d7e0e7bf2855e982496c7fe35 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 24 Sep 2011 17:41:58 +0100 Subject: [PATCH 044/120] [feature/ajax] Moved script.js into a few different files. Seperated it into: assets/javascript/core.js, styles/prosilver/template/ajax.js and adm/style/ajax.js. PHPBB3-10270 --- phpBB/adm/style/ajax.js | 61 ++++++++++ phpBB/adm/style/overall_footer.html | 3 +- .../script.js => assets/javascript/core.js} | 104 +----------------- phpBB/styles/prosilver/template/ajax.js | 66 +++++++++++ .../prosilver/template/overall_footer.html | 3 +- 5 files changed, 133 insertions(+), 104 deletions(-) create mode 100644 phpBB/adm/style/ajax.js rename phpBB/{styles/script.js => assets/javascript/core.js} (61%) create mode 100644 phpBB/styles/prosilver/template/ajax.js diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js new file mode 100644 index 0000000000..407ef92110 --- /dev/null +++ b/phpBB/adm/style/ajax.js @@ -0,0 +1,61 @@ +(function($) { // Avoid conflicts with other libraries + + + +phpbb.add_ajax_callback('forum_down', function(el) { + var tr = $(el).parents('tr'); + if (tr.is(':first-child')) + { + $(el).parents('span').siblings('.up').html('Move up'); + tr.next().find('.up').html('Move up'); + phpbb.ajaxify({selector: $(el).parents('span').siblings('.up').children('a')}, false, 'forum_up'); + } + tr.insertAfter(tr.next()); + if (tr.is(':last-child')) + { + $(el).html('Move down'); + tr.prev().find('.down').html('Move down'); + phpbb.ajaxify({selector: tr.prev().find('.down').children('a')}, false, 'forum_down'); + } +}).add_ajax_callback('forum_up', function(el) { + var tr = $(el).parents('tr'); + if (tr.is(':last-child')) + { + $(el).parents('span').siblings('.down').html('Move down'); + tr.prev().find('.down').html('Move down'); + phpbb.ajaxify({selector: $(el).parents('span').siblings('.down').children('a')}, false, 'forum_down'); + } + tr.insertBefore(tr.prev()); + if (tr.is(':first-child')) + { + $(el).html('Move up'); + tr.next().find('.up').html('Move up'); + phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); + } +}).add_ajax_callback('act_deact', function(el, res) { + $(el).text(res.text); + var new_href = $(el).attr('href'); + if (new_href.indexOf('deactivate') !== -1) + { + new_href = new_href.replace('deactivate', 'activate') + } + else + { + new_href = new_href.replace('activate', 'deactivate') + } + $(el).attr('href', new_href); +}).add_ajax_callback('row_delete', function(el) { + var tr = $(el).parents('tr'); + tr.remove(); +}); + + + +$('[data-ajax]').each(function() { + var fn = ($(this).data('ajax') !== 'true') ? $(this).data('ajax') : null; + phpbb.ajaxify({selector: this}, $(this).data('refresh') !== undefined, fn); +}); + + + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/adm/style/overall_footer.html b/phpBB/adm/style/overall_footer.html index ec3e6a30d3..b57f8261a3 100644 --- a/phpBB/adm/style/overall_footer.html +++ b/phpBB/adm/style/overall_footer.html @@ -27,7 +27,8 @@ - + + diff --git a/phpBB/styles/script.js b/phpBB/assets/javascript/core.js similarity index 61% rename from phpBB/styles/script.js rename to phpBB/assets/javascript/core.js index dd9d2532cc..7337a7fbc0 100644 --- a/phpBB/styles/script.js +++ b/phpBB/assets/javascript/core.js @@ -3,6 +3,7 @@ var phpbb = {}; (function($) { // Avoid conflicts with other libraries + var dark = $('#darkenwrapper'), loading_alert = $('#loadingalert'); @@ -295,106 +296,5 @@ phpbb.add_ajax_callback = function(id, callback) } -phpbb.add_ajax_callback('post_delete', function(el) { - if ($(this).data('refresh') === undefined) - { - var pid = el.href.split('&p=')[1]; - $(el).parents('div #p' + pid).fadeOut(function() { - $(this).remove(); - }); - } -}).add_ajax_callback('bookmark', function(el, res) { - var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); - text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; - $(el).text(el.title = text); -}).add_ajax_callback('topic_subscribe', function(el) { - $(el).text(el.title = 'Unsubscribe topic'); -}).add_ajax_callback('topic_unsubscribe', function(el) { - $(el).text(el.title = 'Subscribe forum'); -}).add_ajax_callback('forum_subscribe', function(el) { - $(el).text(el.title = 'Unsubscribe topic'); -}).add_ajax_callback('forum_unsubscribe', function(el) { - $(el).text(el.title = 'Subscribe forum'); -}).add_ajax_callback('post_approve', function(el, res, act) { - $(el).parents((act === 'approve') ? '.rules' : '.post').fadeOut(function() { - $(this).remove(); - }); -}).add_ajax_callback('qr-submit', function(el) { - $(el).parents('form').fadeOut(function() { - $(this).remove(); - }); -}).add_ajax_callback('forum_down', function(el) { - var tr = $(el).parents('tr'); - if (tr.is(':first-child')) - { - $(el).parents('span').siblings('.up').html('Move up'); - tr.next().find('.up').html('Move up'); - phpbb.ajaxify({selector: $(el).parents('span').siblings('.up').children('a')}, false, 'forum_up'); - } - tr.insertAfter(tr.next()); - if (tr.is(':last-child')) - { - $(el).html('Move down'); - tr.prev().find('.down').html('Move down'); - phpbb.ajaxify({selector: tr.prev().find('.down').children('a')}, false, 'forum_down'); - } -}).add_ajax_callback('forum_up', function(el) { - var tr = $(el).parents('tr'); - if (tr.is(':last-child')) - { - $(el).parents('span').siblings('.down').html('Move down'); - tr.prev().find('.down').html('Move down'); - phpbb.ajaxify({selector: $(el).parents('span').siblings('.down').children('a')}, false, 'forum_down'); - } - tr.insertBefore(tr.prev()); - if (tr.is(':first-child')) - { - $(el).html('Move up'); - tr.next().find('.up').html('Move up'); - phpbb.ajaxify({selector: tr.next().find('.up').children('a')}, false, 'forum_up'); - } -}).add_ajax_callback('act_deact', function(el, res) { - $(el).text(res.text); - var new_href = $(el).attr('href'); - if (new_href.indexOf('deactivate') !== -1) - { - new_href = new_href.replace('deactivate', 'activate') - } - else - { - new_href = new_href.replace('activate', 'deactivate') - } - $(el).attr('href', new_href); -}).add_ajax_callback('row_delete', function(el) { - var tr = $(el).parents('tr'); - tr.remove(); -}).add_ajax_callback('zebra', function(el, res) { - if (res.success) { - $('.zebra').html(res.MESSAGE_TEXT); - $($('.zebra').get(1)).remove(); - } -});; - - -$('[data-ajax]').each(function() { - var fn = ($(this).data('ajax') !== 'true') ? $(this).data('ajax') : null; - phpbb.ajaxify({selector: this}, $(this).data('refresh') !== undefined, fn); -}); - - - -phpbb.ajaxify({ - selector: '#quickmodform', - exception: function(el, act, data) { - var d = phpbb.parse_querystring(data).action; - if (d == 'make_normal') - { - return !(el.find('select option[value="make_global"]').length); - } - return !(d == 'lock' || d == 'unlock' || d == 'delete_topic' || d.slice(0, 5) == 'make_'); - } -}, true); - - -})(jQuery); // Avoid conflicts with other libraries +})(jQuery); // Avoid conflicts with other libraries \ No newline at end of file diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js new file mode 100644 index 0000000000..38233ad0e0 --- /dev/null +++ b/phpBB/styles/prosilver/template/ajax.js @@ -0,0 +1,66 @@ +(function($) { // Avoid conflicts with other libraries + + + +phpbb.add_ajax_callback('post_delete', function(el) { + if ($(this).data('refresh') === undefined) + { + var pid = el.href.split('&p=')[1]; + $(el).parents('div #p' + pid).fadeOut(function() { + $(this).remove(); + }); + } +}).add_ajax_callback('bookmark', function(el, res) { + var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); + text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; + $(el).text(el.title = text); +}).add_ajax_callback('topic_subscribe', function(el) { + $(el).text(el.title = 'Unsubscribe topic'); +}).add_ajax_callback('topic_unsubscribe', function(el) { + $(el).text(el.title = 'Subscribe forum'); +}).add_ajax_callback('forum_subscribe', function(el) { + $(el).text(el.title = 'Unsubscribe topic'); +}).add_ajax_callback('forum_unsubscribe', function(el) { + $(el).text(el.title = 'Subscribe forum'); +}).add_ajax_callback('post_approve', function(el, res, act) { + $(el).parents((act === 'approve') ? '.rules' : '.post').fadeOut(function() { + $(this).remove(); + }); +}).add_ajax_callback('qr-submit', function(el) { + $(el).parents('form').fadeOut(function() { + $(this).remove(); + }); +}).add_ajax_callback('row_delete', function(el) { + var tr = $(el).parents('tr'); + tr.remove(); +}).add_ajax_callback('zebra', function(el, res) { + if (res.success) { + $('.zebra').html(res.MESSAGE_TEXT); + $($('.zebra').get(1)).remove(); + } +});; + + + +$('[data-ajax]').each(function() { + var fn = ($(this).data('ajax') !== 'true') ? $(this).data('ajax') : null; + phpbb.ajaxify({selector: this}, $(this).data('refresh') !== undefined, fn); +}); + + + +phpbb.ajaxify({ + selector: '#quickmodform', + exception: function(el, act, data) { + var d = phpbb.parse_querystring(data).action; + if (d == 'make_normal') + { + return !(el.find('select option[value="make_global"]').length); + } + return !(d == 'lock' || d == 'unlock' || d == 'delete_topic' || d.slice(0, 5) == 'make_'); + } +}, true); + + + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index 20f6ee1f91..a89cd7f04e 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -40,7 +40,8 @@ - + + From 0e55b2393dffa269a724f3090469dad563217dff Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 25 Sep 2011 16:02:26 +0100 Subject: [PATCH 045/120] [ticket/10270] Removed all the inline language and HTML from the JS. PHPBB3-10270 --- phpBB/assets/javascript/core.js | 23 ++++++++++++------- phpBB/language/en/common.php | 2 ++ phpBB/styles/prosilver/template/ajax.js | 12 ---------- .../prosilver/template/overall_footer.html | 13 ++++++++--- .../prosilver/template/overall_header.html | 2 +- phpBB/viewtopic.php | 2 ++ 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/phpBB/assets/javascript/core.js b/phpBB/assets/javascript/core.js index 7337a7fbc0..d685d28c81 100644 --- a/phpBB/assets/javascript/core.js +++ b/phpBB/assets/javascript/core.js @@ -25,7 +25,7 @@ phpbb.loading_alert = function() { setTimeout(function() { if (loading_alert.is(':visible')) { - phpbb.alert('Error', 'Error processing your request. Please try again.'); + phpbb.alert($('body').data('l-err'), $('body').data('l-err-processing-req')); } }, 5000); }); @@ -45,7 +45,9 @@ phpbb.loading_alert = function() { * @returns object Returns the div created. */ phpbb.alert = function(title, msg, fadedark) { - var div = $('

' + title + '

' + msg + '

'); + var div = $('#jalert_alert'); + div.find('h3').html(title); + div.find('p').html(msg); div.bind('click', function(e) { e.stopPropagation(); @@ -54,7 +56,7 @@ phpbb.alert = function(title, msg, fadedark) { dark.one('click', function(e) { var fade = (typeof fadedark !== 'undefined' && !fadedark) ? div : dark; fade.fadeOut(100, function() { - div.remove(); + div.hide(); }); return false; }); @@ -101,15 +103,14 @@ phpbb.alert = function(title, msg, fadedark) { * @returns object Returns the div created. */ phpbb.confirm = function(msg, callback, fadedark) { - var div = $('

' + msg + '

\ -  \ -
'); + var div = $('#jalert_confirm'); + div.find('p').html(msg); div.find('.jalertbut').bind('click', function() { var res = this.value === 'Yes'; var fade = (typeof fadedark !== 'undefined' && !fadedark && res) ? div : dark; fade.fadeOut(100, function() { - div.remove(); + div.hide(); }); callback(res); return false; @@ -227,7 +228,7 @@ phpbb.ajaxify = function(options, refresh, callback) { } dark.fadeOut(100, function() { - alert.remove(); + alert.hide(); }); }, res.REFRESH_DATA.time * 1000); } @@ -296,5 +297,11 @@ phpbb.add_ajax_callback = function(id, callback) } +phpbb.add_ajax_callback('alt_text', function(el) { + var alt_text = $(el).data('alt-text'); + $(el).data('alt-text', $(el).text()); + $(el).text(el.title = alt_text); +}); + })(jQuery); // Avoid conflicts with other libraries \ No newline at end of file diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index e8fff96e5a..ff3d229915 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -179,10 +179,12 @@ $lang = array_merge($lang, array( 'ERR_CONNECTING_SERVER' => 'Error connecting to the server.', 'ERR_JAB_AUTH' => 'Could not authorise on Jabber server.', 'ERR_JAB_CONNECT' => 'Could not connect to Jabber server.', + 'ERR_PROCESSING_REQ' => 'There was an error processing your request. Please try again.', 'ERR_UNABLE_TO_LOGIN' => 'The specified username or password is incorrect.', 'ERR_UNWATCHING' => 'An error occured while trying to unsubscribe.', 'ERR_WATCHING' => 'An error occured while trying to subscribe.', 'ERR_WRONG_PATH_TO_PHPBB' => 'The phpBB path specified appears to be invalid.', + 'ERROR' => 'Error', 'EXPAND_VIEW' => 'Expand view', 'EXTENSION' => 'Extension', 'EXTENSION_CONTROLLER_MISSING' => 'The extension %s is missing a controller class and cannot be accessed through the front-end.', diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index 38233ad0e0..58b765779e 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -10,18 +10,6 @@ phpbb.add_ajax_callback('post_delete', function(el) { $(this).remove(); }); } -}).add_ajax_callback('bookmark', function(el, res) { - var text = (res.MESSAGE_TEXT.indexOf('Removed') === -1); - text = (text) ? 'Remove from bookmarks' : 'Bookmark topic'; - $(el).text(el.title = text); -}).add_ajax_callback('topic_subscribe', function(el) { - $(el).text(el.title = 'Unsubscribe topic'); -}).add_ajax_callback('topic_unsubscribe', function(el) { - $(el).text(el.title = 'Subscribe forum'); -}).add_ajax_callback('forum_subscribe', function(el) { - $(el).text(el.title = 'Unsubscribe topic'); -}).add_ajax_callback('forum_unsubscribe', function(el) { - $(el).text(el.title = 'Subscribe forum'); }).add_ajax_callback('post_approve', function(el, res, act) { $(el).parents((act === 'approve') ? '.rules' : '.post').fadeOut(function() { $(this).remove(); diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index a89cd7f04e..362f8bc1cc 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -8,9 +8,9 @@