2
2
3
3
namespace App \Http \Controllers \Core ;
4
4
5
- use Illuminate \Http \Request ;
6
- use Illuminate \Support \Facades \Auth ;
7
- use Illuminate \Support \Facades \File ;
8
- use Illuminate \Support \Facades \Storage ;
9
-
10
- use App \Http \Controllers \Core \ConnectController ;
11
-
12
5
use App \Enums \LinkOfPdfThumbnail ;
13
6
use App \Enums \ResizedImageSize ;
14
7
use App \Enums \WidthOfPdfThumbnail ;
15
8
use App \Enums \UseType ;
16
-
9
+ use App \ Http \ Controllers \ Core \ ConnectController ;
17
10
use App \Models \Common \Categories ;
18
11
use App \Models \Common \Page ;
19
- // use App\Models\Common\PageRole;
20
12
use App \Models \Common \Uploads ;
21
13
use App \Models \Core \Configs ;
22
-
23
14
use App \Traits \ConnectCommonTrait ;
24
-
15
+ use Carbon \Carbon ;
16
+ use Illuminate \Http \Request ;
17
+ use Illuminate \Support \Facades \Auth ;
18
+ use Illuminate \Support \Facades \File ;
19
+ use Illuminate \Support \Facades \Storage ;
25
20
use Intervention \Image \Facades \Image ;
26
21
27
22
/**
30
25
* ルーティング処理から呼び出されるもの
31
26
*
32
27
* @author 永原 篤 <nagahara@opensource-workshop.jp>
28
+ * @author 牟田口 満 <mutaguchi@opensource-workshop.jp>
33
29
* @copyright OpenSource-WorkShop Co.,Ltd. All Rights Reserved
34
30
* @category コア
35
31
* @package Controller
@@ -358,45 +354,145 @@ private function callCheckMethod($request, $upload)
358
354
}
359
355
360
356
/**
361
- * CSS送出
357
+ * (CSS No1) サイト全体のCSS送出
362
358
*/
363
- public function getCss (Request $ request, $ page_id = null )
359
+ public function getSiteCss (Request $ request): void
364
360
{
365
361
$ configs = Configs::getSharedConfigs ();
366
362
367
- // 自分のページと親ページを遡って取得し、ページの背景色を探す。
368
- // 最下位に設定されているものが採用される。
363
+ // 背景色
364
+ $ background_color = Configs::getConfigsValue ($ configs , 'base_background_color ' , null );
365
+
366
+ // ヘッダーの背景色
367
+ $ header_color = Configs::getConfigsValue ($ configs , 'base_header_color ' , null );
368
+
369
+ header ('Content-Type: text/css ' );
370
+ header ("Content-Disposition: inline; filename=site.css " );
371
+ header ('Cache-Control: ' . config ('connect.CACHE_CONTROL ' ));
369
372
370
373
// 背景色
371
- $ background_color = null ;
374
+ if ($ background_color ) {
375
+ echo "body {background-color: " . $ background_color . "; } \n" ;
376
+ }
372
377
373
378
// ヘッダーの背景色
374
- $ header_color = null ;
379
+ if ($ header_color ) {
380
+ echo ".bg-dark { background-color: " . $ header_color . " !important; } \n" ;
381
+ }
375
382
376
- if (!empty ($ page_id )) {
377
- $ page_tree = Page::reversed ()->ancestorsAndSelf ($ page_id );
378
- foreach ($ page_tree as $ page ) {
379
- // 背景色
380
- if (empty ($ background_color ) && $ page ->background_color ) {
381
- $ background_color = $ page ->background_color ;
382
- }
383
- // ヘッダーの背景色
384
- if (empty ($ header_color ) && $ page ->header_color ) {
385
- $ header_color = $ page ->header_color ;
386
- }
387
- }
383
+ // 画像の保存機能の無効化(スマホ長押し禁止)
384
+ if (Configs::getConfigsValue ($ configs , 'base_touch_callout ' ) == '1 ' ) {
385
+ echo <<<EOD
386
+ img {
387
+ -webkit-touch-callout: none;
388
+ }
389
+
390
+ EOD ;
391
+ }
392
+
393
+ // カテゴリーCSS
394
+ $ categories = Categories::orderBy ('target ' , 'asc ' )->orderBy ('display_sequence ' , 'asc ' )->get ();
395
+ $ categories = $ categories ->unique ("classname " );
396
+ foreach ($ categories as $ category ) {
397
+ echo ".cc_category_ " . $ category ->classname . " { \n" ;
398
+ echo " background-color: " . $ category ->background_color . "; \n" ;
399
+ echo " color: " . $ category ->color . "; \n" ;
400
+ echo "} \n" ;
388
401
}
402
+ exit ;
403
+ }
404
+
405
+ /**
406
+ * サイト全体のCSSタイムスタンプ(最大更新日時のTIMESTAMP)取得
407
+ * (サイト全体のCSSのクエリストリングに使用。CSSをキャッシュしても、クエリストリングを変える事で設定更新時に新しいCSSを反映させる仕組み)
408
+ */
409
+ public static function getSiteCssTimestamp ()
410
+ {
411
+ $ configs = Configs::getSharedConfigs ();
389
412
390
- // ページ設定で背景色が指定されていなかった場合は、基本設定を使用する。
413
+ $ max_updated_at = null ;
391
414
392
415
// 背景色
393
- if (empty ($ background_color )) {
394
- $ background_color = Configs::getConfigsValue ($ configs , 'base_background_color ' , null );
416
+ $ max_updated_at = self ::getConfigsMaxUpdatedAt ($ configs , 'base_background_color ' , $ max_updated_at );
417
+
418
+ // ヘッダーの背景色
419
+ $ max_updated_at = self ::getConfigsMaxUpdatedAt ($ configs , 'base_header_color ' , $ max_updated_at );
420
+
421
+ // 画像の保存機能の無効化(スマホ長押し禁止)
422
+ $ max_updated_at = self ::getConfigsMaxUpdatedAt ($ configs , 'base_touch_callout ' , $ max_updated_at );
423
+
424
+ // カテゴリーCSS
425
+ $ max_updated_at_category = Categories::max ('updated_at ' );
426
+ if ($ max_updated_at_category ) {
427
+ $ max_updated_at_category = new Carbon ($ max_updated_at_category );
428
+
429
+ $ max_updated_at = self ::getMaxUpdatedAt ($ max_updated_at_category , $ max_updated_at );
430
+ }
431
+
432
+ // format('U') でUNIXタイムスタンプへ変換
433
+ $ unix_timestamp = $ max_updated_at ? $ max_updated_at ->format ('U ' ) : null ;
434
+ return $ unix_timestamp ;
435
+ }
436
+
437
+ /**
438
+ * 設定のmax updated_at取得
439
+ */
440
+ private static function getConfigsMaxUpdatedAt ($ configs , $ key , ?Carbon $ max_updated_at ): ?Carbon
441
+ {
442
+ $ config = $ configs ->firstWhere ('name ' , $ key ) ?? new Configs ();
443
+
444
+ // 設定値あり
445
+ if ($ config ->value ) {
446
+ $ max_updated_at = self ::getMaxUpdatedAt ($ config ->updated_at , $ max_updated_at );
395
447
}
396
448
449
+ return $ max_updated_at ;
450
+ }
451
+
452
+ /**
453
+ * 日付比較してより大きい updated_at 取得
454
+ */
455
+ private static function getMaxUpdatedAt (Carbon $ target_updated_at , ?Carbon $ max_updated_at ): Carbon
456
+ {
457
+ // max_updated_at がある場合は、日付比較
458
+ if ($ max_updated_at ) {
459
+ // 大きい? a > b
460
+ if ($ target_updated_at ->gt ($ max_updated_at )) {
461
+ $ max_updated_at = $ target_updated_at ;
462
+ }
463
+ } else {
464
+ // max_updated_at が null の場合は、updated_atを設定
465
+ $ max_updated_at = $ target_updated_at ;
466
+ }
467
+
468
+ return $ max_updated_at ;
469
+ }
470
+
471
+ /**
472
+ * (CSS No2) ページ毎のCSS送出
473
+ * getSiteCss() の後に呼び出し、もし同じcss classがあっても「ページ毎のCSS送出」が優先される。
474
+ */
475
+ public function getPageCss (Request $ request , $ page_id ): void
476
+ {
477
+ // 自分のページと親ページを遡って取得し、ページの背景色を探す。
478
+ // 最下位に設定されているものが採用される。
479
+
480
+ // 背景色
481
+ $ background_color = null ;
482
+
397
483
// ヘッダーの背景色
398
- if (empty ($ header_color )) {
399
- $ header_color = Configs::getConfigsValue ($ configs , 'base_header_color ' , null );
484
+ $ header_color = null ;
485
+
486
+ $ page_tree = Page::reversed ()->ancestorsAndSelf ($ page_id );
487
+ foreach ($ page_tree as $ page ) {
488
+ // 背景色
489
+ if (empty ($ background_color ) && $ page ->background_color ) {
490
+ $ background_color = $ page ->background_color ;
491
+ }
492
+ // ヘッダーの背景色
493
+ if (empty ($ header_color ) && $ page ->header_color ) {
494
+ $ header_color = $ page ->header_color ;
495
+ }
400
496
}
401
497
402
498
// セッションにヘッダーの背景色がある場合(テーマ・チェンジャーで選択時の動き)
@@ -406,10 +502,7 @@ public function getCss(Request $request, $page_id = null)
406
502
407
503
header ('Content-Type: text/css ' );
408
504
header ("Content-Disposition: inline; filename= {$ page_id }.css " );
409
- // cssを no_cache に変更
410
- // header('Cache-Control: ' . config('connect.CACHE_CONTROL'));
411
- header ('Cache-Control: no-store ' );
412
- header ('Expires: Thu, 01 Dec 1994 16:00:00 GMT ' );
505
+ header ('Cache-Control: ' . config ('connect.CACHE_CONTROL ' ));
413
506
414
507
// 背景色
415
508
if ($ background_color ) {
@@ -421,25 +514,69 @@ public function getCss(Request $request, $page_id = null)
421
514
echo ".bg-dark { background-color: " . $ header_color . " !important; } \n" ;
422
515
}
423
516
424
- // 画像の保存機能の無効化(スマホ長押し禁止)
425
- if (Configs::getConfigsValue ($ configs , 'base_touch_callout ' ) == '1 ' ) {
426
- echo <<<EOD
427
- img {
428
- -webkit-touch-callout: none;
429
- }
517
+ exit ;
518
+ }
430
519
431
- EOD ;
520
+ /**
521
+ * ページ毎のCSSタイムスタンプ(最大更新日時のTIMESTAMP)取得
522
+ * (ページ毎のCSSのクエリストリングに使用。CSSをキャッシュしても、クエリストリングを変える事で設定更新時に新しいCSSを反映させる仕組み)
523
+ */
524
+ public static function getPageCssTimestamp ($ page_id )
525
+ {
526
+ $ max_updated_at = null ;
527
+
528
+ $ request = app ('request ' );
529
+
530
+ // セッションにヘッダーの背景色がある場合(テーマ・チェンジャーで選択時の動き)は、最新の日時を返して強制表示
531
+ if ($ request && $ request ->session ()->get ('session_header_black ' ) == true ) {
532
+ $ max_updated_at = new Carbon ();
533
+
534
+ // format('U') でUNIXタイムスタンプへ変換
535
+ $ unix_timestamp = $ max_updated_at ->format ('U ' );
536
+ return $ unix_timestamp ;
432
537
}
433
538
434
- // カテゴリーCSS
435
- $ categories = Categories::orderBy ('target ' , 'asc ' )->orderBy ('display_sequence ' , 'asc ' )->get ();
436
- foreach ($ categories as $ category ) {
437
- echo ".cc_category_ " . $ category ->classname . " { \n" ;
438
- echo " background-color: " . $ category ->background_color . "; \n" ;
439
- echo " color: " . $ category ->color . "; \n" ;
440
- echo "} \n" ;
539
+ // 自分のページと親ページを遡って取得し、ページの背景色を探す。
540
+ // 最下位に設定されているものが採用される。
541
+
542
+ // 背景色
543
+ $ background_color_updated_at = null ;
544
+
545
+ // ヘッダーの背景色
546
+ $ header_color_updated_at = null ;
547
+
548
+ if (!empty ($ page_id )) {
549
+ $ page_tree = Page::reversed ()->ancestorsAndSelf ($ page_id );
550
+ foreach ($ page_tree as $ page ) {
551
+ // 背景色
552
+ if (empty ($ background_color ) && $ page ->background_color ) {
553
+ // $background_color = $page->background_color;
554
+ $ background_color_updated_at = $ page ->updated_at ;
555
+
556
+ }
557
+ // ヘッダーの背景色
558
+ if (empty ($ header_color ) && $ page ->header_color ) {
559
+ // $header_color = $page->header_color;
560
+ $ header_color_updated_at = $ page ->updated_at ;
561
+ }
562
+ }
441
563
}
442
- exit ;
564
+
565
+ // 背景色
566
+ if ($ background_color_updated_at ) {
567
+ // echo "body {background-color: " . $background_color . "; }\n";
568
+ $ max_updated_at = $ background_color_updated_at ;
569
+ }
570
+
571
+ // ヘッダーの背景色
572
+ if ($ header_color_updated_at ) {
573
+ // echo ".bg-dark { background-color: " . $header_color . " !important; }\n";
574
+ $ max_updated_at = self ::getMaxUpdatedAt ($ header_color_updated_at , $ max_updated_at );
575
+ }
576
+
577
+ // format('U') でUNIXタイムスタンプへ変換
578
+ $ unix_timestamp = $ max_updated_at ? $ max_updated_at ->format ('U ' ) : null ;
579
+ return $ unix_timestamp ;
443
580
}
444
581
445
582
/**
0 commit comments