From 27cfa4aeba0121f55884ab054537aeb30afcb0c2 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 2 Mar 2016 10:03:48 +0900 Subject: [PATCH 1/5] Redirect to short URL after insertDocument, insertComment, etc. --- classes/module/ModuleObject.class.php | 2 +- modules/board/board.controller.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/classes/module/ModuleObject.class.php b/classes/module/ModuleObject.class.php index b6e994f30..5a656854c 100644 --- a/classes/module/ModuleObject.class.php +++ b/classes/module/ModuleObject.class.php @@ -60,7 +60,7 @@ class ModuleObject extends Object function setRedirectUrl($url = './', $output = NULL) { $ajaxRequestMethod = array_flip($this->ajaxRequestMethod); - if(!isset($ajaxRequestMethod[Context::getRequestMethod()])) + if(isset($ajaxRequestMethod[Context::getRequestMethod()])) { $this->add('redirect_url', $url); } diff --git a/modules/board/board.controller.php b/modules/board/board.controller.php index e1646246c..9a6660d1f 100644 --- a/modules/board/board.controller.php +++ b/modules/board/board.controller.php @@ -191,6 +191,7 @@ class boardController extends board } // return the results + $this->setRedirectUrl(getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '', 'document_srl', $output->get('document_srl'))); $this->add('mid', Context::get('mid')); $this->add('document_srl', $output->get('document_srl')); @@ -399,6 +400,7 @@ class boardController extends board } $this->setMessage('success_registed'); + $this->setRedirectUrl(getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '', 'document_srl', $obj->document_srl) . '#comment_' . $obj->comment_srl); $this->add('mid', Context::get('mid')); $this->add('document_srl', $obj->document_srl); $this->add('comment_srl', $obj->comment_srl); @@ -449,6 +451,7 @@ class boardController extends board $this->add('page', Context::get('page')); $this->add('document_srl', $output->get('document_srl')); $this->setMessage('success_deleted'); + $this->setRedirectUrl(getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '', 'page', Context::get('page'), 'document_srl', $output->get('document_srl'))); } /** @@ -473,6 +476,7 @@ class boardController extends board $this->add('page', Context::get('page')); $this->add('document_srl', $output->get('document_srl')); $this->setMessage('success_deleted'); + $this->setRedirectUrl(getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '', 'page', Context::get('page'), 'document_srl', $output->get('document_srl'))); } /** From 1b372375a4629a5e0616137908a4fba607ffbe3e Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 2 Mar 2016 10:10:10 +0900 Subject: [PATCH 2/5] Always set redirect_url if a module calls setRedirectUrl() --- classes/module/ModuleObject.class.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/classes/module/ModuleObject.class.php b/classes/module/ModuleObject.class.php index 5a656854c..99ee0b6a7 100644 --- a/classes/module/ModuleObject.class.php +++ b/classes/module/ModuleObject.class.php @@ -59,11 +59,7 @@ class ModuleObject extends Object * */ function setRedirectUrl($url = './', $output = NULL) { - $ajaxRequestMethod = array_flip($this->ajaxRequestMethod); - if(isset($ajaxRequestMethod[Context::getRequestMethod()])) - { - $this->add('redirect_url', $url); - } + $this->add('redirect_url', $url); if($output !== NULL && is_object($output)) { From 54fc1da600f03784aaf790e3dc1d0dd86083174a Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 4 Mar 2016 10:57:56 +0900 Subject: [PATCH 3/5] Fix no redirect after writing a comment --- common/js/xml_handler.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/common/js/xml_handler.js b/common/js/xml_handler.js index 0b4f03775..65eba4976 100644 --- a/common/js/xml_handler.js +++ b/common/js/xml_handler.js @@ -102,9 +102,18 @@ } // If the response contains a redirect URL, redirect immediately. - if (result.redirect_url) { - window.location = result.redirect_url.replace(/&/g, "&"); - return null; + if (data.redirect_url) { + data.redirect_url = data.redirect_url.replace(/&/g, "&"); + if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) + { + window.location = data.redirect_url; + window.location.reload(); + } + else + { + window.location = data.redirect_url; + } + return; } // If there was a success callback, call it. @@ -220,6 +229,21 @@ } } + // If the response contains a redirect URL, redirect immediately. + if (data.redirect_url) { + data.redirect_url = data.redirect_url.replace(/&/g, "&"); + if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) + { + window.location = data.redirect_url; + window.location.reload(); + } + else + { + window.location = data.redirect_url; + } + return; + } + // If there was a success callback, call it. if($.isFunction(callback_success)) { callback_success(data); From 006474cb989c83dc2db53eefc52d350d18c2b058 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 4 Mar 2016 15:07:03 +0900 Subject: [PATCH 4/5] Fix unnecessary redirect on comment insertion in some skins --- common/js/xml_handler.js | 4 ++ modules/board/tpl/js/board.js | 93 ++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/common/js/xml_handler.js b/common/js/xml_handler.js index 65eba4976..74173f756 100644 --- a/common/js/xml_handler.js +++ b/common/js/xml_handler.js @@ -104,6 +104,8 @@ // If the response contains a redirect URL, redirect immediately. if (data.redirect_url) { data.redirect_url = data.redirect_url.replace(/&/g, "&"); + } + if (data.redirect_url && !$.isFunction(callback_success)) { if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) { window.location = data.redirect_url; @@ -232,6 +234,8 @@ // If the response contains a redirect URL, redirect immediately. if (data.redirect_url) { data.redirect_url = data.redirect_url.replace(/&/g, "&"); + } + if (data.redirect_url && !$.isFunction(callback_success)) { if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) { window.location = data.redirect_url; diff --git a/modules/board/tpl/js/board.js b/modules/board/tpl/js/board.js index 9e344c435..a4fbc0621 100644 --- a/modules/board/tpl/js/board.js +++ b/modules/board/tpl/js/board.js @@ -13,19 +13,21 @@ function completeDocumentInserted(ret_obj) var document_srl = ret_obj.document_srl; var category_srl = ret_obj.category_srl; - //alert(message); - - var url; - if(!document_srl) - { - url = current_url.setQuery('mid',mid).setQuery('act',''); + if (ret_obj.redirect_url) { + location.href = ret_obj.redirect_url; + } else { + var url; + if(!document_srl) + { + url = current_url.setQuery('mid',mid).setQuery('act',''); + } + else + { + url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); + } + if(category_srl) url = url.setQuery('category',category_srl); + location.href = url; } - else - { - url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); - } - if(category_srl) url = url.setQuery('category',category_srl); - location.href = url; } /* delete the document */ @@ -38,9 +40,6 @@ function completeDeleteDocument(ret_obj) var url = current_url.setQuery('mid',mid).setQuery('act','').setQuery('document_srl',''); if(page) url = url.setQuery('page',page); - - //alert(message); - location.href = url; } @@ -75,13 +74,21 @@ function completeInsertComment(ret_obj) var mid = ret_obj.mid; var document_srl = ret_obj.document_srl; var comment_srl = ret_obj.comment_srl; - - var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); - if(comment_srl) url = url.setQuery('rnd',comment_srl)+"#comment_"+comment_srl; - - //alert(message); - - location.href = url; + if (ret_obj.redirect_url) { + if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) + { + window.location = ret_obj.redirect_url; + window.location.reload(); + } + else + { + window.location = ret_obj.redirect_url; + } + } else { + var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); + if (comment_srl) url = url.setQuery('rnd',comment_srl)+"#comment_"+comment_srl; + window.location.href = url; + } } /* delete the comment */ @@ -93,12 +100,21 @@ function completeDeleteComment(ret_obj) var document_srl = ret_obj.document_srl; var page = ret_obj.page; - var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); - if(page) url = url.setQuery('page',page); - - //alert(message); - - location.href = url; + if (ret_obj.redirect_url) { + if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) + { + window.location = ret_obj.redirect_url; + window.location.reload(); + } + else + { + window.location = ret_obj.redirect_url; + } + } else { + var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); + if (page) url = url.setQuery('page',page); + window.location.href = url; + } } /* delete the trackback */ @@ -110,12 +126,21 @@ function completeDeleteTrackback(ret_obj) var document_srl = ret_obj.document_srl; var page = ret_obj.page; - var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); - if(page) url = url.setQuery('page',page); - - //alert(message); - - location.href = url; + if (ret_obj.redirect_url) { + if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) + { + window.location = ret_obj.redirect_url; + window.location.reload(); + } + else + { + window.location = ret_obj.redirect_url; + } + } else { + var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); + if (page) url = url.setQuery('page',page); + window.location.href = url; + } } /* change category */ From 9b5a17fb597e96cb83179fd22165e50cd18bd3d3 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 7 Mar 2016 08:34:06 +0900 Subject: [PATCH 5/5] Clean up repeating code and add redirect() function --- common/js/common.js | 17 ++++++++++++- common/js/xml_handler.js | 22 ++-------------- modules/board/tpl/js/board.js | 48 ++++++++--------------------------- 3 files changed, 29 insertions(+), 58 deletions(-) diff --git a/common/js/common.js b/common/js/common.js index 08b0d6688..a617209f6 100644 --- a/common/js/common.js +++ b/common/js/common.js @@ -377,6 +377,21 @@ function sendMailTo(to) { location.href="mailto:"+to; } +/** + * @brief url이동 (Rhymix 개선된 버전) + */ +function redirect(url) { + if (url === window.location.href || url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) + { + window.location.href = url; + window.location.reload(); + } + else + { + window.location.href = url; + } +} + /** * @brief url이동 (open_window 값이 N 가 아니면 새창으로 띄움) **/ @@ -394,7 +409,7 @@ function move_url(url, open_window) { if(open_window) { winopen(url); } else { - location.href=url; + redirect(url); } return false; diff --git a/common/js/xml_handler.js b/common/js/xml_handler.js index 74173f756..9d246a88b 100644 --- a/common/js/xml_handler.js +++ b/common/js/xml_handler.js @@ -106,16 +106,7 @@ data.redirect_url = data.redirect_url.replace(/&/g, "&"); } if (data.redirect_url && !$.isFunction(callback_success)) { - if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) - { - window.location = data.redirect_url; - window.location.reload(); - } - else - { - window.location = data.redirect_url; - } - return; + return redirect(data.redirect_url); } // If there was a success callback, call it. @@ -236,16 +227,7 @@ data.redirect_url = data.redirect_url.replace(/&/g, "&"); } if (data.redirect_url && !$.isFunction(callback_success)) { - if (data.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) - { - window.location = data.redirect_url; - window.location.reload(); - } - else - { - window.location = data.redirect_url; - } - return; + return redirect(data.redirect_url); } // If there was a success callback, call it. diff --git a/modules/board/tpl/js/board.js b/modules/board/tpl/js/board.js index a4fbc0621..d0e7fa165 100644 --- a/modules/board/tpl/js/board.js +++ b/modules/board/tpl/js/board.js @@ -14,7 +14,7 @@ function completeDocumentInserted(ret_obj) var category_srl = ret_obj.category_srl; if (ret_obj.redirect_url) { - location.href = ret_obj.redirect_url; + redirect(ret_obj.redirect_url); } else { var url; if(!document_srl) @@ -26,7 +26,7 @@ function completeDocumentInserted(ret_obj) url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); } if(category_srl) url = url.setQuery('category',category_srl); - location.href = url; + redirect(url); } } @@ -40,7 +40,7 @@ function completeDeleteDocument(ret_obj) var url = current_url.setQuery('mid',mid).setQuery('act','').setQuery('document_srl',''); if(page) url = url.setQuery('page',page); - location.href = url; + redirect(url); } /* document search */ @@ -53,8 +53,7 @@ function completeVote(ret_obj) { var error = ret_obj.error; var message = ret_obj.message; - alert(message); - location.href = location.href; + redirect(window.location.href); } // current page reload @@ -62,8 +61,7 @@ function completeReload(ret_obj) { var error = ret_obj.error; var message = ret_obj.message; - - location.href = location.href; + redirect(window.location.href); } /* complete to insert comment*/ @@ -75,19 +73,11 @@ function completeInsertComment(ret_obj) var document_srl = ret_obj.document_srl; var comment_srl = ret_obj.comment_srl; if (ret_obj.redirect_url) { - if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) - { - window.location = ret_obj.redirect_url; - window.location.reload(); - } - else - { - window.location = ret_obj.redirect_url; - } + redirect(ret_obj.redirect_url); } else { var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); if (comment_srl) url = url.setQuery('rnd',comment_srl)+"#comment_"+comment_srl; - window.location.href = url; + redirect(url); } } @@ -101,19 +91,11 @@ function completeDeleteComment(ret_obj) var page = ret_obj.page; if (ret_obj.redirect_url) { - if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) - { - window.location = ret_obj.redirect_url; - window.location.reload(); - } - else - { - window.location = ret_obj.redirect_url; - } + redirect(ret_obj.redirect_url); } else { var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); if (page) url = url.setQuery('page',page); - window.location.href = url; + redirect(url); } } @@ -127,19 +109,11 @@ function completeDeleteTrackback(ret_obj) var page = ret_obj.page; if (ret_obj.redirect_url) { - if (ret_obj.redirect_url.indexOf(window.location.href.replace(/#.+$/, "") + "#") === 0) - { - window.location = ret_obj.redirect_url; - window.location.reload(); - } - else - { - window.location = ret_obj.redirect_url; - } + redirect(ret_obj.redirect_url); } else { var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act',''); if (page) url = url.setQuery('page',page); - window.location.href = url; + redirect(url); } }