@@ -125,6 +125,7 @@ public function index($request, $page_id, $frame_id, $errors = null)
125
125
$ rss = $ this ->getRsses ($ frame_id );
126
126
127
127
$ setting_error_messages = null ;
128
+ $ parse_errors = null ;
128
129
$ rss_urls = new Collection ();
129
130
if ($ rss ) {
130
131
$ rss_urls = RssUrls::query ()
@@ -156,12 +157,19 @@ public function index($request, $page_id, $frame_id, $errors = null)
156
157
}
157
158
// xmlレスポンスエラーの場合がある
158
159
if ($ xml_response ) {
159
- // Connect-CMS用にパース
160
- $ xmlitems = $ this ->xmlParse ($ xml_response );
161
- // 出力数を調整
162
- $ xmlitems = array_splice ($ xmlitems , 0 , $ urls ->item_count );
163
- // 画面様に変数にセット
164
- $ urls ->items = $ xmlitems ;
160
+ try {
161
+ // Connect-CMS用にパース
162
+ $ xmlitems = $ this ->xmlParse ($ xml_response , $ urls ->url );
163
+ // 出力数を調整
164
+ $ xmlitems = array_splice ($ xmlitems , 0 , $ urls ->item_count );
165
+ // 画面様に変数にセット
166
+ $ urls ->items = $ xmlitems ;
167
+ } catch (\Exception $ e ) {
168
+ // パースエラー時はparse_errorsに格納
169
+ $ urls ->items = [];
170
+ $ parse_errors ['message ' ] = $ e ->getMessage ();
171
+ $ parse_errors ['url ' ][] = $ urls ->url ;
172
+ }
165
173
}
166
174
}
167
175
@@ -183,7 +191,7 @@ public function index($request, $page_id, $frame_id, $errors = null)
183
191
}
184
192
185
193
186
- if (empty ($ setting_error_messages )) {
194
+ if (empty ($ setting_error_messages ) && empty ( $ parse_errors ) ) {
187
195
// 表示テンプレートを呼び出す。
188
196
return $ this ->view ('rsses ' , [
189
197
'request ' => $ request ,
@@ -197,6 +205,7 @@ public function index($request, $page_id, $frame_id, $errors = null)
197
205
// エラーあり
198
206
return $ this ->view ('rsses_error_messages ' , [
199
207
'error_messages ' => $ setting_error_messages ,
208
+ 'parse_errors ' => $ parse_errors ,
200
209
]);
201
210
}
202
211
}
@@ -251,7 +260,29 @@ private function getXml($url)
251
260
private function xmlParse ($ response )
252
261
{
253
262
// SimpleXMLを使用してXMLデータをオブジェクトに変換
254
- $ xml = simplexml_load_string ($ response );
263
+ libxml_use_internal_errors (true );
264
+ try {
265
+ $ xml = simplexml_load_string ($ response );
266
+ if ($ xml === false ) {
267
+ $ error_message = "simplexml_load_string error: " ;
268
+ foreach (libxml_get_errors () as $ error ) {
269
+ $ error_message .= $ error ->message . " " ;
270
+ }
271
+ throw new \Exception (trim ($ error_message ));
272
+ }
273
+ } catch (\Exception $ e ) {
274
+ // 管理権限があるか判定
275
+ $ is_admin = Auth::check () && Auth::user ()->can ('role_article_admin ' );
276
+ $ display_message = $ is_admin
277
+ ? 'RSSフィードの取得に失敗しました。URLが正しいか、またはフィードが有効であるかご確認ください。 '
278
+ : 'RSSフィードの読み込みに失敗しました。しばらくしてから再度お試しください。 ' ;
279
+ // ログ出力
280
+ Log::error ($ e ->getMessage ());
281
+ // 画面用に例外を投げる
282
+ throw new \Exception ($ display_message );
283
+ } finally {
284
+ libxml_clear_errors ();
285
+ }
255
286
256
287
// フィードのバージョンに応じてアイテムを取得
257
288
if (isset ($ xml ->channel ->item )) {
0 commit comments