From 268d54be79ff8f61919677f0d543a752e00b6ceb Mon Sep 17 00:00:00 2001 From: uzulla Date: Sun, 14 Feb 2021 20:10:05 +0900 Subject: [PATCH 01/18] Avoid super global. remove unnecessary $_SERVER #99 --- app/config/fc2_template.php | 6 +++--- app/src/Web/Controller/Admin/CommonController.php | 1 + app/src/Web/Controller/Controller.php | 4 ++-- app/src/Web/Html.php | 4 ++-- app/src/Web/Request.php | 8 ++++---- app/twig_templates/admin/common/install.twig | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/config/fc2_template.php b/app/config/fc2_template.php index 4e3838c4..143688ee 100644 --- a/app/config/fc2_template.php +++ b/app/config/fc2_template.php @@ -111,7 +111,7 @@ ]; $template_vars = [ - '<%server_url>' => '', + '<%server_url>' => '', '<%blog_id>' => '', // タイトルリスト一覧 '<%titlelist_eno>' => '', @@ -189,8 +189,8 @@ '<%topentry_image>' => '\'; ?>', '<%topentry_image_72>' => '\'; ?>', '<%topentry_image_w300>' => '\'; ?>', - '<%topentry_image_url>' => '', - '<%topentry_image_url_760x420>' => '', + '<%topentry_image_url>' => '', + '<%topentry_image_url_760x420>' => '', '<%topentry_comment_num>' => '', // 記事のカテゴリー系 '<%topentry_category_no>' => 'set('is_domain', $is_domain); + $this->set('example_server_name', $request->server['SERVER_NAME'] ?? 'example.jp'); // GDインストール済み確認 $is_gd = function_exists('gd_info'); diff --git a/app/src/Web/Controller/Controller.php b/app/src/Web/Controller/Controller.php index 0f7d8e7e..9d033783 100644 --- a/app/src/Web/Controller/Controller.php +++ b/app/src/Web/Controller/Controller.php @@ -174,8 +174,8 @@ protected function redirect(Request $request, $url, $hash = '', bool $full_url = protected function redirectBack(Request $request, $url, $hash = '') { // 元のURLに戻す - if (!empty($_SERVER['HTTP_REFERER'])) { - $this->redirect($request, $_SERVER['HTTP_REFERER']); + if (!empty($request->server['HTTP_REFERER'])) { + $this->redirect($request, $request->server['HTTP_REFERER']); } // リファラーが取れなければメインへ飛ばす $this->redirect($request, $url, $hash); diff --git a/app/src/Web/Html.php b/app/src/Web/Html.php index 6eaad83c..e37a61ef 100644 --- a/app/src/Web/Html.php +++ b/app/src/Web/Html.php @@ -244,9 +244,9 @@ public static function input(Request $request, $name, $type, $attrs = array(), $ return $html; } - public static function getServerUrl() + public static function getServerUrl(Request $request): string { - $url = (empty($_SERVER["HTTPS"])) ? 'http://' : 'https://'; + $url = (isset($request->server["HTTPS"]) && $request->server["HTTPS"] === "on") ? 'http://' : 'https://'; $url .= Config::get('DOMAIN'); return $url; } diff --git a/app/src/Web/Request.php b/app/src/Web/Request.php index e4881009..8b591bcb 100644 --- a/app/src/Web/Request.php +++ b/app/src/Web/Request.php @@ -100,12 +100,12 @@ public function __construct( /** * リファラーを返却 存在しない場合は空文字を返却 + * @return string */ - public static function getReferer() + public function getReferer(): string { - // TODO - if (!empty($_SERVER['HTTP_REFERER'])) { - return $_SERVER['HTTP_REFERER']; + if (isset($this->server['HTTP_REFERER'])) { + return $this->server['HTTP_REFERER']; } return ''; } diff --git a/app/twig_templates/admin/common/install.twig b/app/twig_templates/admin/common/install.twig index a9f79c47..fc5f8f16 100644 --- a/app/twig_templates/admin/common/install.twig +++ b/app/twig_templates/admin/common/install.twig @@ -146,7 +146,7 @@

{{ _('Domain is set to the current domain') }}
{{ _('Please change to the appropriate domain') }}
- {{ _('Example') }}) + {{ _('Example') }}) {{ example_server_name }}

{% endif %} From e74e2a9eb7a130420663fe52bcecfd4fbb7e9854 Mon Sep 17 00:00:00 2001 From: uzulla Date: Sun, 14 Feb 2021 20:20:29 +0900 Subject: [PATCH 02/18] Avoid super global. remove unnecessary $_COOKIE #99 --- app/src/Web/Cookie.php | 14 ++++++++------ app/src/Web/Session.php | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/Web/Cookie.php b/app/src/Web/Cookie.php index 1e9c865c..2a908a62 100644 --- a/app/src/Web/Cookie.php +++ b/app/src/Web/Cookie.php @@ -13,14 +13,15 @@ class Cookie /** * クッキーから情報を取得する - * @param $key - * @param null $default - * @return mixed|null + * @param Request $request + * @param string $key + * @param ?string $default + * @return mixed */ - public static function get($key, $default = null) + public static function get(Request $request, string $key, $default = null) { - if (isset($_COOKIE[$key])) { - return $_COOKIE[$key]; + if (isset($request->cookie[$key])) { + return $request->cookie[$key]; } return $default; } @@ -106,6 +107,7 @@ public static function set( if(defined("THIS_IS_TEST")){ $request->cookie[$key] = $value; }else{ + $request->cookie[$key] = $value; setcookie( $key, $value, diff --git a/app/src/Web/Session.php b/app/src/Web/Session.php index d0d2e1f8..ca6ed9b9 100644 --- a/app/src/Web/Session.php +++ b/app/src/Web/Session.php @@ -104,7 +104,7 @@ public static function destroy(Request $request) { $_SESSION = []; $request->session = []; - if (isset($_COOKIE[Config::get('SESSION_NAME')])) { + if (isset($request->cookie[Config::get('SESSION_NAME')])) { Cookie::remove($request, Config::get('SESSION_NAME')); } if (session_status() === PHP_SESSION_ACTIVE) { From 0a691203665fb40db1f8b83eb44bab902fa0f9cb Mon Sep 17 00:00:00 2001 From: uzulla Date: Sun, 14 Feb 2021 22:03:49 +0900 Subject: [PATCH 03/18] add todo comment. --- tests/Helper/ClientTrait.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Helper/ClientTrait.php b/tests/Helper/ClientTrait.php index 77db97e6..c3e20d48 100644 --- a/tests/Helper/ClientTrait.php +++ b/tests/Helper/ClientTrait.php @@ -66,8 +66,11 @@ public function reqBase( array $filesParams = [] ): AppController { + // TODO $_をテストからも可能ならば排除する $_SESSION = $this->clientTraitSession; + // TODO $_COOKIEをテストからも可能ならば排除する $_COOKIE = $this->clientTraitCookie; + // TODO $_SERVERをテストからも可能ならば排除する $_SERVER = []; if ($https) { $_SERVER['HTTPS'] = "on"; From 341f2767b225954e4eb26bc2b0488654e55c98ee Mon Sep 17 00:00:00 2001 From: uzulla Date: Mon, 15 Feb 2021 10:18:46 +0900 Subject: [PATCH 04/18] Fix missing title. #223 --- app/src/Web/Controller/User/EntriesController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/Web/Controller/User/EntriesController.php b/app/src/Web/Controller/User/EntriesController.php index 972f357d..e4af3158 100644 --- a/app/src/Web/Controller/User/EntriesController.php +++ b/app/src/Web/Controller/User/EntriesController.php @@ -885,6 +885,7 @@ public function comment_edit(Request $request): string // FC2用のテンプレートで表示 $this->setAreaData(['edit_area']); + $this->set('sub_title', __("Edit a comment")); return $this->getFc2TemplatePath($blog_id); } From 945d13eb48a95f12c6435594e3e60419ad91a57d Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 12:27:44 +0900 Subject: [PATCH 05/18] Fix broken tests --- e2e_test/tests/blog_crawl_sp.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e_test/tests/blog_crawl_sp.test.ts b/e2e_test/tests/blog_crawl_sp.test.ts index be7005af..8fe7b067 100644 --- a/e2e_test/tests/blog_crawl_sp.test.ts +++ b/e2e_test/tests/blog_crawl_sp.test.ts @@ -172,7 +172,7 @@ describe("crawl some blog with smartphone", () => { it("comment list - open comment form", async () => { const response = await c.clickElement(await getEditLinkByTitle(post_comment_title)); expect(response.url()).toEqual(expect.stringContaining(start_url + "index.php?mode=entries&process=comment_edit&id=")); - expect(await c.page.title()).toEqual("- testblog2"); // TODO issue #223 + expect(await c.page.title()).toEqual("コメントの編集 - testblog2"); await c.getSS("comment_edit_before_sp"); }); @@ -214,7 +214,7 @@ describe("crawl some blog with smartphone", () => { await c.getSS("comment_form_delete_before2_sp"); expect(response.status()).toEqual(200); expect(response.url()).toEqual(expect.stringContaining(start_url + "index.php?mode=entries&process=comment_edit&id=")); - expect(await c.page.title()).toEqual("- testblog2"); // TODO issue #223 + expect(await c.page.title()).toEqual("コメントの編集 - testblog2"); }); it("user template comment form - delete fail by wrong password", async () => { @@ -250,7 +250,7 @@ describe("crawl some blog with smartphone", () => { await c.getSS("comment_form_delete_before2_sp"); expect(response.status()).toEqual(200); expect(response.url()).toEqual(expect.stringContaining(start_url + "index.php?mode=entries&process=comment_edit&id=")); - expect(await c.page.title()).toEqual("- testblog2"); // TODO issue #223 + expect(await c.page.title()).toEqual("コメントの編集 - testblog2"); }); it("user template comment form - comment delete success", async () => { From b4bc05448565631b1195e98e82936b8c99ac0c2e Mon Sep 17 00:00:00 2001 From: uzulla Date: Tue, 16 Feb 2021 22:48:33 +0900 Subject: [PATCH 06/18] Changed to executable in cli. --- tests/cli_generate_sample_upload_image.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cli_generate_sample_upload_image.php b/tests/cli_generate_sample_upload_image.php index 4829b88c..bea57899 100755 --- a/tests/cli_generate_sample_upload_image.php +++ b/tests/cli_generate_sample_upload_image.php @@ -6,6 +6,7 @@ use Fc2blog\Tests\LoaderHelper; define("TEST_APP_DIR", __DIR__ . "/../app"); +define("THIS_IS_TEST", true); require_once __DIR__ . "/../app/vendor/autoload.php"; From 7bcd2ea37d85c87ac60077b895fa8ad9148196fa Mon Sep 17 00:00:00 2001 From: uzulla Date: Tue, 16 Feb 2021 22:49:37 +0900 Subject: [PATCH 07/18] Add comments. --- app/src/Web/Controller/Admin/FilesController.php | 2 +- app/twig_templates/admin/files/ajax_index.twig | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/Web/Controller/Admin/FilesController.php b/app/src/Web/Controller/Admin/FilesController.php index 08ac5fb2..f9be1a60 100644 --- a/app/src/Web/Controller/Admin/FilesController.php +++ b/app/src/Web/Controller/Admin/FilesController.php @@ -13,7 +13,7 @@ class FilesController extends AdminController { /** - * 一覧表示 + * 一覧表示 /admin/files/upload からPartial読み込み * @param Request $request * @return string */ diff --git a/app/twig_templates/admin/files/ajax_index.twig b/app/twig_templates/admin/files/ajax_index.twig index 0865a4e7..e3d3bf2a 100644 --- a/app/twig_templates/admin/files/ajax_index.twig +++ b/app/twig_templates/admin/files/ajax_index.twig @@ -1,3 +1,4 @@ +{# /admin/files/upload からPartial読み込み #}

{{ _('File search') }}[{{ _('Hits') }} {{ paging.count }}{{ _(' results') }}] {{ input(req, 'limit', 'select', {'options': page_list_file, 'default': file_default_limit}) }} From e8437d8036992abc0d56f85661b3612b5c1d50d4 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 10:33:02 +0900 Subject: [PATCH 08/18] Add JavaScript error handling in upload #140 --- app/twig_templates/admin/files/ajax_index.twig | 10 +++++++++- app/twig_templates/admin/files/upload.twig | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/twig_templates/admin/files/ajax_index.twig b/app/twig_templates/admin/files/ajax_index.twig index e3d3bf2a..0cc39c7d 100644 --- a/app/twig_templates/admin/files/ajax_index.twig +++ b/app/twig_templates/admin/files/ajax_index.twig @@ -80,7 +80,7 @@ return false; }); - // ファイル削除ボタン + // 複数ファイル削除ボタン $('#sys-delete-button').click(function () { if (!confirm('{{ _('Are you sure you want to delete?') }}')) { return; @@ -108,6 +108,14 @@ // 削除完了後検索処理を実行 isAjaxSubmit = isPageChange = true; ajaxSubmit(); + }, + error: function( response, status, xhr ) { + if (status === "error") { + alert("エラーが発生しました、ページをリロードしてください。\n" + + "Request failed. Please reload page and retry."); + isAjaxSubmit = isPageChange = true; + ajaxSubmit(); + } } }); return false; diff --git a/app/twig_templates/admin/files/upload.twig b/app/twig_templates/admin/files/upload.twig index abfbd5c9..e705a0b2 100644 --- a/app/twig_templates/admin/files/upload.twig +++ b/app/twig_templates/admin/files/upload.twig @@ -42,7 +42,7 @@ common.formEnterNonSubmit('sys-file-form'); // ajaxで一覧情報をロード - $('#sys-ajax-files-index').load('{{ url(req, 'Files', 'ajax_index') }}') + $('#sys-ajax-files-index').load('{{ url(req, 'Files', 'ajax_index') }}', writeErrToSysAjaxFilesIndex) }); // ページ数初期化有無フラグ @@ -64,7 +64,8 @@ success: function (res) { $('#sys-ajax-files-index').html(res); isAjaxSubmit = true; - } + }, + error: writeErrToSysAjaxFilesIndex }); return; } @@ -85,7 +86,8 @@ success: function (res) { $('#sys-ajax-files-index').html(res); isAjaxSubmit = true; - } + }, + error: writeErrToSysAjaxFilesIndex }); } @@ -102,5 +104,13 @@ $('input[name=order]').val(order); ajaxSubmit(); } + + function writeErrToSysAjaxFilesIndex( response, status, xhr ) { + if ( status === "error" ) { + $('#sys-ajax-files-index') + .html("
エラーが発生しました、ページをリロードしてください。
" + + "Loading error. Please reload page.
"); + } + } {% endblock %} \ No newline at end of file From ee3f6394da7135ba34acda34fee339efe662f84d Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 12:02:57 +0900 Subject: [PATCH 09/18] Add JavaScript error handling in create entry(category) #140 --- app/src/Web/Controller/Admin/CategoriesController.php | 2 +- app/twig_templates/admin/categories/ajax_add.twig | 8 ++++++++ app/twig_templates/admin/categories/ajax_add_sp.twig | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/src/Web/Controller/Admin/CategoriesController.php b/app/src/Web/Controller/Admin/CategoriesController.php index 77927b9c..94be4b92 100644 --- a/app/src/Web/Controller/Admin/CategoriesController.php +++ b/app/src/Web/Controller/Admin/CategoriesController.php @@ -138,7 +138,7 @@ public function delete(Request $request) } /** - * ajax用のカテゴリ追加 + * ajax用のカテゴリ追加 admin/entries/create からインクルード * @param Request $request * @return string */ diff --git a/app/twig_templates/admin/categories/ajax_add.twig b/app/twig_templates/admin/categories/ajax_add.twig index 95477bec..13e089a8 100644 --- a/app/twig_templates/admin/categories/ajax_add.twig +++ b/app/twig_templates/admin/categories/ajax_add.twig @@ -1,3 +1,4 @@ +{# include from admin/entries/create #} @@ -152,6 +153,13 @@ $('#sys-category-add-name').val(''); $('#sys-category-add').removeAttr('disabled'); $('#sys-category-add').val('{{ _('Add') }}'); + }, + error: function (data, status, xhr){ + alert("カテゴリ追加時にエラーが発生しました、時間をおいてから再度試行してください。\n" + + "An error occurred when adding the category, please wait a while and try again."); + $('#sys-category-add-name').val(''); + $('#sys-category-add').removeAttr('disabled'); + $('#sys-category-add').val('{{ _('Add') }}'); } }); return false; diff --git a/app/twig_templates/admin/categories/ajax_add_sp.twig b/app/twig_templates/admin/categories/ajax_add_sp.twig index e872c4e0..4183b904 100644 --- a/app/twig_templates/admin/categories/ajax_add_sp.twig +++ b/app/twig_templates/admin/categories/ajax_add_sp.twig @@ -1,3 +1,4 @@ +{# include from admin/entries/create #}

{{ _('Categories') }}

@@ -137,6 +138,13 @@ $('#sys-category-add-name').val(''); $('#sys-category-add').removeAttr('disabled'); $('#sys-category-add').val('{{ _('Add') }}'); + }, + error: function (data, status, xhr){ + alert("カテゴリ追加時にエラーが発生しました、時間をおいてから再度試行してください。\n" + + "An error occurred when adding the category, please wait a while and try again."); + $('#sys-category-add-name').val(''); + $('#sys-category-add').removeAttr('disabled'); + $('#sys-category-add').val('{{ _('Add') }}'); } }); return false; From 09270be7612c7bcdd1e131d4f363cff2270b7138 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 12:03:15 +0900 Subject: [PATCH 10/18] add comment --- app/twig_templates/admin/files/ajax_index.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/app/twig_templates/admin/files/ajax_index.twig b/app/twig_templates/admin/files/ajax_index.twig index 0cc39c7d..e6851db2 100644 --- a/app/twig_templates/admin/files/ajax_index.twig +++ b/app/twig_templates/admin/files/ajax_index.twig @@ -113,6 +113,7 @@ if (status === "error") { alert("エラーが発生しました、ページをリロードしてください。\n" + "Request failed. Please reload page and retry."); + // 失敗しているが、画面を復帰させるために検索処理を実行 isAjaxSubmit = isPageChange = true; ajaxSubmit(); } From 2fee25143f4fff59e2bd4d8e4ea25f02039ecef8 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 12:03:49 +0900 Subject: [PATCH 11/18] Add JavaScript error handling in blog plugins #140 --- app/twig_templates/admin/blog_plugins/index.twig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/twig_templates/admin/blog_plugins/index.twig b/app/twig_templates/admin/blog_plugins/index.twig index d03d97c6..70bbc4bf 100644 --- a/app/twig_templates/admin/blog_plugins/index.twig +++ b/app/twig_templates/admin/blog_plugins/index.twig @@ -77,7 +77,11 @@ display: $(this).prop('checked') ? 1 : 0, sig: "{{ sig }}" }), - cache: false + cache: false, + error: function (data, status, xhr){ + alert("エラーが発生しました、ページをリロードしてやり直してください。\n" + + "An error occurred, please reload page and try again."); + } }); }); From d4461d3acf1717d9a0dc44b7fb0e2679c0f4c93a Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 12:18:26 +0900 Subject: [PATCH 12/18] Add JavaScript error handling in comments #140 --- app/twig_templates/admin/comments/index.twig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/twig_templates/admin/comments/index.twig b/app/twig_templates/admin/comments/index.twig index 47d849cd..0499b338 100644 --- a/app/twig_templates/admin/comments/index.twig +++ b/app/twig_templates/admin/comments/index.twig @@ -170,6 +170,10 @@ $('#sys-reply-message').hide(); $('#sys-reply-error').html(json.error); $('#sys-reply-error').show(); + }, + error: function (data, status, xhr){ + alert("エラーが発生しました、ページをリロードしてください。\n" + + "An error occurred, please reload page and try again."); } }); }; @@ -193,6 +197,10 @@ $('#sys-open-status-' + id + ' > *').show(); $('#sys-comment-approval').show(); alert(json.error); + }, + error: function (data, status, xhr){ + alert("エラーが発生しました、ページをリロードしてやり直してください。\n" + + "An error occurred, please reload page and try again."); } }); }); From 9ab7d735e9f2089bdc136ce0b5d7dfc4899121ff Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 13:16:34 +0900 Subject: [PATCH 13/18] Fix support cli execution. --- tests/cli_generate_sample_comment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cli_generate_sample_comment.php b/tests/cli_generate_sample_comment.php index cc5b7e27..77a8a874 100755 --- a/tests/cli_generate_sample_comment.php +++ b/tests/cli_generate_sample_comment.php @@ -6,6 +6,7 @@ use Fc2blog\Tests\LoaderHelper; define("TEST_APP_DIR", __DIR__ . "/../app"); +define("THIS_IS_TEST", true); require_once __DIR__ . "/../app/vendor/autoload.php"; From 8e68db4aecf190faf46b985a7d9b0008ae385740 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 13:17:00 +0900 Subject: [PATCH 14/18] add comment --- app/twig_templates/admin/entries/ajax_media_load.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/app/twig_templates/admin/entries/ajax_media_load.twig b/app/twig_templates/admin/entries/ajax_media_load.twig index 61d84c7f..cbe566c7 100644 --- a/app/twig_templates/admin/entries/ajax_media_load.twig +++ b/app/twig_templates/admin/entries/ajax_media_load.twig @@ -1,3 +1,4 @@ +{# 新規記事追加ページ /admin/entries/create から読み込み #} {% if files %}
    From 800ed07f9ac8ef8f2a303ba366be505ba1d81b85 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 13:17:07 +0900 Subject: [PATCH 15/18] add comment --- app/twig_templates/admin/entries/ajax_media_load_sp.twig | 1 + 1 file changed, 1 insertion(+) diff --git a/app/twig_templates/admin/entries/ajax_media_load_sp.twig b/app/twig_templates/admin/entries/ajax_media_load_sp.twig index 42ac3d68..0253fcd7 100644 --- a/app/twig_templates/admin/entries/ajax_media_load_sp.twig +++ b/app/twig_templates/admin/entries/ajax_media_load_sp.twig @@ -1,3 +1,4 @@ +{# 新規記事追加ページ /admin/entries/create SP から読み込み #} {% if files %}
    From 4441d9b6964ac28a2405f2bed08bef6b9f981e18 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 13:18:04 +0900 Subject: [PATCH 16/18] Add JavaScript error handling #140 --- public/js/admin/entry_editor.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/public/js/admin/entry_editor.js b/public/js/admin/entry_editor.js index 57db59f2..7f91e814 100644 --- a/public/js/admin/entry_editor.js +++ b/public/js/admin/entry_editor.js @@ -22,18 +22,27 @@ var addMedia = { $('#sys-add-media-dialog').dialog('option', {width: $(window).width() - 100}); }); }, - load: function(params){ - $('#sys-add-media-load').fadeOut('fast', function(){ - $('#sys-add-media-load').load(common.fwURL('Entries', 'ajax_media_load', params), function(){ - $('#sys-add-media-load').fadeIn('fast'); - $('#sys-add-media-load').find('input[type=checkbox]').on('click', function(){ - if ($(this).prop('checked')) { - $(this).closest('li').addClass('selected'); + load: function (params) { + $('#sys-add-media-load').fadeOut('fast', function () { + $('#sys-add-media-load').load( + common.fwURL('Entries', 'ajax_media_load', params), + function (response, status, xhr) { + if (status === "error") { + alert("エラーが発生しました、ページをリロードしてください。\n" + + "Loading error. Please reload page."); + } else { - $(this).closest('li').removeClass('selected'); + $('#sys-add-media-load').fadeIn('fast'); + $('#sys-add-media-load').find('input[type=checkbox]').on('click', function () { + if ($(this).prop('checked')) { + $(this).closest('li').addClass('selected'); + } else { + $(this).closest('li').removeClass('selected'); + } + }); } - }) - }); + } + ); }); }, open: function(key, config){ From fce2583f41ca3e802add2a2ededd92a42d5cd9a1 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 13:19:16 +0900 Subject: [PATCH 17/18] Add JavaScript error handling #140 --- app/twig_templates/admin/comments/index.twig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/twig_templates/admin/comments/index.twig b/app/twig_templates/admin/comments/index.twig index 0499b338..f64acad7 100644 --- a/app/twig_templates/admin/comments/index.twig +++ b/app/twig_templates/admin/comments/index.twig @@ -143,7 +143,12 @@ }; $('#sys-comment-reply-dialog').dialog(option); $('#sys-comment-reply-dialog').html('now loading..'); - $('#sys-comment-reply-dialog').load(common.fwURL('Comments', 'ajax_reply', {id: id})) + $('#sys-comment-reply-dialog').load(common.fwURL('Comments', 'ajax_reply', {id: id}), function(data, status, xhr){ + if(status === "error") { + alert("エラーが発生しました、ページをリロードしてください。\n" + + "An error occurred, please reload page and try again."); + } + }); reply.updateReadStatus(is_private); }; // コメントを閉じる処理 From 16fbabb09cb99cd9c492814e3210002c198fbad4 Mon Sep 17 00:00:00 2001 From: uzulla Date: Wed, 17 Feb 2021 13:20:17 +0900 Subject: [PATCH 18/18] Remove unnecessary code, add comment/todo. --- public/js/admin/entry_editor.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/js/admin/entry_editor.js b/public/js/admin/entry_editor.js index 7f91e814..4db6ff30 100644 --- a/public/js/admin/entry_editor.js +++ b/public/js/admin/entry_editor.js @@ -1,7 +1,7 @@ // メディア追加関数 var addMedia = { target_id: null, - elrte: true, // elRTEの使用,不使用 + elrte: true, // elRTEの使用,不使用 init: function(){ if (this.target_id!=null) { return ; @@ -9,7 +9,7 @@ var addMedia = { // 検索ボタン $('#sys-add-media-search-button').on('click', function(){ var keyword = $('#sys-add-media-search-keyword').val(); - $('#sys-add-media-load').load(addMedia.load({keyword: keyword})); + addMedia.load({keyword: keyword}); }); // Enterキーで検索 $('#sys-add-media-search-keyword').keypress(function(e){ @@ -71,7 +71,7 @@ var addMedia = { } $('#sys-add-media-dialog').dialog(option); $('#sys-add-media-load').html('

    Now loading...

    '); - $('#sys-add-media-load').load(addMedia.load({})); + addMedia.load({}); }, add: function(){ var textarea_id = addMedia.target_id; @@ -100,7 +100,7 @@ var addMedia = { // 位置情報取得 getSelection: function(dom) { var pos = {}; - if (/*@cc_on!@*/false) { + if (/*@cc_on!@*/false) { // TODO remove, It's hack for IE<=10 #235 dom.focus(); var range = document.selection.createRange(); var clone = range.duplicate();