1
1
<?php
2
- /**
3
- * アプリ用の便利関数群
4
- */
2
+ declare (strict_types=1 );
5
3
6
4
namespace Fc2blog ;
7
5
15
13
16
14
class App
17
15
{
18
-
19
16
/**
20
17
* ブログIDから階層別フォルダ作成
21
18
* @param string $blog_id
@@ -33,7 +30,7 @@ public static function getBlogLayer(string $blog_id): string
33
30
* @param bool $timestamp
34
31
* @return string
35
32
*/
36
- public static function getUserFilePath (array $ file , $ abs = false , $ timestamp = false ): string
33
+ public static function getUserFilePath (array $ file , bool $ abs = false , bool $ timestamp = false ): string
37
34
{
38
35
$ file_path = static ::getBlogLayer ($ file ['blog_id ' ]) . '/file/ ' . $ file ['id ' ] . '. ' . $ file ['ext ' ];
39
36
return ($ abs ? Config::get ('WWW_UPLOAD_DIR ' ) : '/uploads/ ' ) . $ file_path . ($ timestamp ? '?t= ' . strtotime ($ file ['updated_at ' ]) : '' );
@@ -55,7 +52,7 @@ public static function getThumbnailPath(string $url, int $size = 72, string $whs
55
52
if (!preg_match ('{(/uploads/[0-9a-zA-Z]/[0-9a-zA-Z]/[0-9a-zA-Z]/[0-9a-zA-Z]+/file/[0-9]+)\.(png|gif|jpe?g)(\?t=[0-9]+)?$} ' , $ url , $ matches )) {
56
53
return $ url ;
57
54
}
58
- return $ matches [1 ] . '_ ' . $ whs . $ size . '. ' . $ matches [2 ] . (isset ( $ matches [3 ]) ? $ matches [ 3 ] : '' );
55
+ return $ matches [1 ] . '_ ' . $ whs . $ size . '. ' . $ matches [2 ] . ($ matches [3 ] ?? '' );
59
56
}
60
57
61
58
/**
@@ -67,15 +64,15 @@ public static function getThumbnailPath(string $url, int $size = 72, string $whs
67
64
* @param string $whs
68
65
* @return string
69
66
*/
70
- public static function getCenterThumbnailPath (string $ url , $ width = 760 , $ height = 420 , $ whs = '' ): string
67
+ public static function getCenterThumbnailPath (string $ url , int $ width = 760 , int $ height = 420 , string $ whs = '' ): string
71
68
{
72
69
if (empty ($ url )) {
73
70
return $ url ;
74
71
}
75
72
if (!preg_match ('{(/uploads/[0-9a-zA-Z]/[0-9a-zA-Z]/[0-9a-zA-Z]/[0-9a-zA-Z]+/file/[0-9]+)\.(png|gif|jpe?g)(\?t=[0-9]+)?$} ' , $ url , $ matches )) {
76
73
return $ url ;
77
74
}
78
- return $ matches [1 ] . '_ ' . $ whs . $ width . '_ ' . $ height . '. ' . $ matches [2 ] . (isset ( $ matches [3 ]) ? $ matches [ 3 ] : '' );
75
+ return $ matches [1 ] . '_ ' . $ whs . $ width . '_ ' . $ height . '. ' . $ matches [2 ] . ($ matches [3 ] ?? '' );
79
76
}
80
77
81
78
/**
@@ -105,14 +102,14 @@ public static function deleteFile(string $blog_id, string $id): void
105
102
* @param string $id
106
103
* @return string
107
104
*/
108
- public static function getPluginFilePath (string $ blog_id , string $ id )
105
+ public static function getPluginFilePath (string $ blog_id , string $ id ): string
109
106
{
110
107
return Config::get ('BLOG_TEMPLATE_DIR ' ) . static ::getBlogLayer ($ blog_id ) . '/plugins/ ' . $ id . '.php ' ;
111
108
}
112
109
113
110
/**
114
111
* ファイルパスまでのフォルダを作成する
115
- * @param $file_path
112
+ * @param string $file_path
116
113
*/
117
114
public static function mkdir (string $ file_path ): void
118
115
{
@@ -167,7 +164,7 @@ public static function calcStartAndEndDate(int $year = 0, int $month = 0, int $d
167
164
$ end .= '12-31 ' ;
168
165
}
169
166
$ dates = explode ('- ' , $ start );
170
- if (!checkdate ($ dates [1 ], $ dates [2 ], $ dates [0 ])) {
167
+ if (!checkdate (( int ) $ dates [1 ], ( int ) $ dates [2 ], ( int ) $ dates [0 ])) {
171
168
// 存在日付の場合は本日を開始、終了日時として割り当てる
172
169
$ start = $ end = date ('Y-m-d ' );
173
170
}
@@ -179,9 +176,9 @@ public static function calcStartAndEndDate(int $year = 0, int $month = 0, int $d
179
176
/**
180
177
* デバイスタイプを取得する
181
178
* @param Request $request
182
- * @return string|null
179
+ * @return int
183
180
*/
184
- public static function getDeviceType (Request $ request ): string
181
+ public static function getDeviceType (Request $ request ): int
185
182
{
186
183
// パラメータによりデバイスタイプを変更(FC2の引数順守)
187
184
if ($ request ->isArgs ('pc ' )) {
@@ -198,7 +195,7 @@ public static function getDeviceType(Request $request): string
198
195
Config::get ('DEVICE_SP ' ),
199
196
];
200
197
if (!empty ($ device_type ) && in_array ($ device_type , $ devices )) {
201
- return $ device_type ;
198
+ return ( int ) $ device_type ;
202
199
}
203
200
204
201
// ユーザーエージェントからデバイスタイプを取得
@@ -321,7 +318,7 @@ public static function userURL(Request $request, array $args = [], bool $reused
321
318
$ args = array_merge ($ gets , $ args );
322
319
}
323
320
324
- $ controller = $ controller = $ request ->shortControllerName ;
321
+ $ controller = $ request ->shortControllerName ;
325
322
if (isset ($ args ['controller ' ])) {
326
323
$ controller = $ args ['controller ' ];
327
324
unset($ args ['controller ' ]);
@@ -366,8 +363,7 @@ public static function userURL(Request $request, array $args = [], bool $reused
366
363
if ($ blog_id && $ blog_id !== Config::get ('DEFAULT_BLOG_ID ' )) {
367
364
$ url = '/ ' . $ blog_id . $ url ;
368
365
}
369
- $ url = ($ abs ? $ full_domain : '' ) . $ url ;
370
- return $ url ;
366
+ return ($ abs ? $ full_domain : '' ) . $ url ;
371
367
}
372
368
373
369
// 記事の場合
@@ -388,8 +384,7 @@ public static function userURL(Request $request, array $args = [], bool $reused
388
384
if ($ blog_id && $ blog_id !== Config::get ('DEFAULT_BLOG_ID ' )) {
389
385
$ url = '/ ' . $ blog_id . $ url ;
390
386
}
391
- $ url = ($ abs ? $ full_domain : '' ) . $ url ;
392
- return $ url ;
387
+ return ($ abs ? $ full_domain : '' ) . $ url ;
393
388
}
394
389
395
390
$ params = [];
@@ -409,14 +404,13 @@ public static function userURL(Request $request, array $args = [], bool $reused
409
404
if ($ blog_id && $ blog_id !== Config::get ('DEFAULT_BLOG_ID ' )) {
410
405
$ url = '/ ' . $ blog_id . $ url ;
411
406
}
412
- $ url = ($ abs ? $ full_domain : '' ) . $ url ;
413
- return $ url ;
407
+ return ($ abs ? $ full_domain : '' ) . $ url ;
414
408
}
415
409
416
410
/**
417
411
* ページ毎、デバイス毎の初期制限件数
418
412
* @param Request $request
419
- * @param $key
413
+ * @param string $key
420
414
* @return int
421
415
*/
422
416
public static function getPageLimit (Request $ request , string $ key ): int
@@ -427,7 +421,7 @@ public static function getPageLimit(Request $request, string $key): int
427
421
/**
428
422
* ページ毎、デバイス毎の件数一覧
429
423
* @param Request $request
430
- * @param $key
424
+ * @param string $key
431
425
* @return array
432
426
*/
433
427
public static function getPageList (Request $ request , string $ key ): array
@@ -441,6 +435,7 @@ public static function getPageList(Request $request, string $key): array
441
435
* @param array|string params = array('entries/create', 'entries/edit', ...),
442
436
* @return bool
443
437
* TODO Configの削減
438
+ * @noinspection PhpUnused
444
439
*/
445
440
public static function isActiveMenu (Request $ request , $ params ): bool
446
441
{
0 commit comments