Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

管理画面操作時のAjax通信エラーについて、エラーダイアログ等をできるだけ出すように修正 #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/config/fc2_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
];

$template_vars = [
'<%server_url>' => '<?php echo \Fc2blog\Web\Html::getServerUrl() . \'/\'; ?>',
'<%server_url>' => '<?php echo \Fc2blog\Web\Html::getServerUrl($request) . \'/\'; ?>',
'<%blog_id>' => '<?php echo $blog_id; ?>',
// タイトルリスト一覧
'<%titlelist_eno>' => '<?php if(isset($entry[\'id\'])) echo $entry[\'id\']; ?>',
Expand Down Expand Up @@ -189,8 +189,8 @@
'<%topentry_image>' => '<?php if(!empty($entry[\'first_image\'])) echo \'<img src="\' . $entry[\'first_image\'] . \'" />\'; ?>',
'<%topentry_image_72>' => '<?php if(!empty($entry[\'first_image\'])) echo \'<img src="\' . \Fc2blog\App::getThumbnailPath($entry[\'first_image\'], 72) . \'" />\'; ?>',
'<%topentry_image_w300>' => '<?php if(!empty($entry[\'first_image\'])) echo \'<img src="\' . \Fc2blog\App::getThumbnailPath($entry[\'first_image\'], 300, \'w\') . \'" />\'; ?>',
'<%topentry_image_url>' => '<?php if(!empty($entry[\'first_image\'])) echo \Fc2blog\Web\Html::getServerUrl() . $entry[\'first_image\']; ?>',
'<%topentry_image_url_760x420>' => '<?php if(!empty($entry[\'first_image\'])) echo \Fc2blog\Web\Html::getServerUrl() . \Fc2blog\App::getCenterThumbnailPath($entry[\'first_image\'], 760, 420, \'wh\'); ?>',
'<%topentry_image_url>' => '<?php if(!empty($entry[\'first_image\'])) echo \Fc2blog\Web\Html::getServerUrl($request) . $entry[\'first_image\']; ?>',
'<%topentry_image_url_760x420>' => '<?php if(!empty($entry[\'first_image\'])) echo \Fc2blog\Web\Html::getServerUrl($request) . \Fc2blog\App::getCenterThumbnailPath($entry[\'first_image\'], 760, 420, \'wh\'); ?>',
'<%topentry_comment_num>' => '<?php if(isset($entry[\'comment_count\'])) echo $entry[\'comment_count\']; ?>',
// 記事のカテゴリー系
'<%topentry_category_no>' => '<?php if(!isset($entry[\'categories\'][0][\'id\'])){}else if(!empty($category) && $category[\'entry_id\']==$entry[\'categories\'][0][\'entry_id\']){'
Expand Down
2 changes: 1 addition & 1 deletion app/src/Web/Controller/Admin/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function delete(Request $request)
}

/**
* ajax用のカテゴリ追加
* ajax用のカテゴリ追加 admin/entries/create からインクルード
* @param Request $request
* @return string
*/
Expand Down
1 change: 1 addition & 0 deletions app/src/Web/Controller/Admin/CommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function install(Request $request): string
// ドメイン確認
$is_domain = DOMAIN != 'domain';
$this->set('is_domain', $is_domain);
$this->set('example_server_name', $request->server['SERVER_NAME'] ?? 'example.jp');

// GDインストール済み確認
$is_gd = function_exists('gd_info');
Expand Down
2 changes: 1 addition & 1 deletion app/src/Web/Controller/Admin/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FilesController extends AdminController
{

/**
* 一覧表示
* 一覧表示 /admin/files/upload からPartial読み込み
* @param Request $request
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions app/src/Web/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions app/src/Web/Controller/User/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 8 additions & 6 deletions app/src/Web/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions app/src/Web/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/Web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/Web/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion app/twig_templates/admin/blog_plugins/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
});
});

Expand Down
8 changes: 8 additions & 0 deletions app/twig_templates/admin/categories/ajax_add.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# include from admin/entries/create #}
<table>
<tbody>
<tr>
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions app/twig_templates/admin/categories/ajax_add_sp.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# include from admin/entries/create #}
<h3><span class="h3_inner">{{ _('Categories') }}</span></h3>

<div class="checkbox_list">
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion app/twig_templates/admin/comments/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
// コメントを閉じる処理
Expand All @@ -170,6 +175,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.");
}
});
};
Expand All @@ -193,6 +202,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.");
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion app/twig_templates/admin/common/install.twig
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<p class="ng">
{{ _('Domain is set to the current domain') }}<br/>
{{ _('Please change to the appropriate domain') }}<br/>
{{ _('Example') }}) <?php echo $_SERVER["SERVER_NAME"]; ?>
{{ _('Example') }}) {{ example_server_name }}
</p>
{% endif %}
</li>
Expand Down
1 change: 1 addition & 0 deletions app/twig_templates/admin/entries/ajax_media_load.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# 新規記事追加ページ /admin/entries/create から読み込み #}
{% if files %}

<ul class="sys-form-add-media">
Expand Down
1 change: 1 addition & 0 deletions app/twig_templates/admin/entries/ajax_media_load_sp.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# 新規記事追加ページ /admin/entries/create SP から読み込み #}
{% if files %}

<div class="form_contents">
Expand Down
12 changes: 11 additions & 1 deletion app/twig_templates/admin/files/ajax_index.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# /admin/files/upload からPartial読み込み #}
<h3 id="entry_count">
{{ _('File search') }}[{{ _('Hits') }}&nbsp;{{ paging.count }}{{ _(' results') }}]
{{ input(req, 'limit', 'select', {'options': page_list_file, 'default': file_default_limit}) }}
Expand Down Expand Up @@ -79,7 +80,7 @@
return false;
});

// ファイル削除ボタン
// 複数ファイル削除ボタン
$('#sys-delete-button').click(function () {
if (!confirm('{{ _('Are you sure you want to delete?') }}')) {
return;
Expand Down Expand Up @@ -107,6 +108,15 @@
// 削除完了後検索処理を実行
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;
Expand Down
16 changes: 13 additions & 3 deletions app/twig_templates/admin/files/upload.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});

// ページ数初期化有無フラグ
Expand All @@ -64,7 +64,8 @@
success: function (res) {
$('#sys-ajax-files-index').html(res);
isAjaxSubmit = true;
}
},
error: writeErrToSysAjaxFilesIndex
});
return;
}
Expand All @@ -85,7 +86,8 @@
success: function (res) {
$('#sys-ajax-files-index').html(res);
isAjaxSubmit = true;
}
},
error: writeErrToSysAjaxFilesIndex
});
}

Expand All @@ -102,5 +104,13 @@
$('input[name=order]').val(order);
ajaxSubmit();
}

function writeErrToSysAjaxFilesIndex( response, status, xhr ) {
if ( status === "error" ) {
$('#sys-ajax-files-index')
.html("<div style='text-align: center; font-size: 2em; font-weight:bold'>エラーが発生しました、ページをリロードしてください。<br>" +
"Loading error. Please reload page.</div>");
}
}
</script>
{% endblock %}
6 changes: 3 additions & 3 deletions e2e_test/tests/blog_crawl_sp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading