| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services; |
| 4 |
|
| 5 |
use FluentCart\App\App; |
| 6 |
use FluentCart\App\Models\Subscription; |
| 7 |
use FluentCart\App\Vite; |
| 8 |
|
| 9 |
class FrontendView |
| 10 |
{ |
| 11 |
public static function make($title, $content = '', $params = []) |
| 12 |
{ |
| 13 |
$params['title'] = $title; |
| 14 |
$params['content'] = $content; |
| 15 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in view template |
| 16 |
echo App::view()->make('frontend/index.php')->with($params); |
| 17 |
} |
| 18 |
|
| 19 |
public static function makeForBlock($title, $view) |
| 20 |
{ |
| 21 |
$blocks = parse_blocks($view); |
| 22 |
|
| 23 |
$content = ''; |
| 24 |
foreach ($blocks as $block) { |
| 25 |
$renderedBlock = render_block($block); |
| 26 |
$content .= do_shortcode($renderedBlock); |
| 27 |
} |
| 28 |
|
| 29 |
echo wp_kses_post( |
| 30 |
App::view()->make('frontend/index.php')->with([ |
| 31 |
'title' => esc_html($title), |
| 32 |
'content' => $content, |
| 33 |
]) |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
// public static function loadView(string $path, $data = []) |
| 38 |
// { |
| 39 |
// return App::view()->make('frontend/' . $path)->with($data); |
| 40 |
// } |
| 41 |
|
| 42 |
public static function loadView(string $pageTitle, array $data, string $filePath = '') |
| 43 |
{ |
| 44 |
$view = App::view()->make('frontend/' . $filePath)->with($data); |
| 45 |
|
| 46 |
return self::make($pageTitle, $view, $data); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
public static function enqueueNotFoundPageAssets(): void |
| 51 |
{ |
| 52 |
Vite::enqueueStyle( |
| 53 |
'fluent-cart-not-found-style', |
| 54 |
'public/not-found.css', |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
public static function renderNotFoundPage($pageTitle = null, $title = null, $text = null, $buttonText = null, $notFoundImg = null, $buttonUrl = null) |
| 59 |
{ |
| 60 |
$pageTitle = $pageTitle ?? __('404 - Page not found', 'fluent-cart'); |
| 61 |
$title = $title ?? __('404 - Page not found', 'fluent-cart'); |
| 62 |
$text = $text ?? __('The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.', 'fluent-cart'); |
| 63 |
$buttonText = $buttonText ?? __('Go Back to Home Page', 'fluent-cart'); |
| 64 |
$notFoundImg = empty($notFoundImg) ? Vite::getAssetUrl() . 'images/404.svg': $notFoundImg; |
| 65 |
|
| 66 |
$data = [ |
| 67 |
'title' => $title, |
| 68 |
'text' => $text, |
| 69 |
'buttonText' => $buttonText, |
| 70 |
'notFoundImg' => $notFoundImg, |
| 71 |
'buttonUrl' => $buttonUrl |
| 72 |
]; |
| 73 |
|
| 74 |
self::enqueueNotFoundPageAssets(); |
| 75 |
|
| 76 |
return self::loadView($pageTitle, $data, 'not-found.php'); |
| 77 |
} |
| 78 |
|
| 79 |
public static function renderFileNotFoundPage() |
| 80 |
{ |
| 81 |
return static::renderNotFoundPage( |
| 82 |
__('File Not Found', 'fluent-cart'), |
| 83 |
__('404 - File Not Found', 'fluent-cart'), |
| 84 |
__('The requested file is unavailable or the download link has expired.', 'fluent-cart') |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
public static function renderForPrint($content, $params = []) |
| 89 |
{ |
| 90 |
|
| 91 |
$params['content'] = $content; |
| 92 |
$app = fluentCart(); |
| 93 |
$slug = $app->config->get('app.slug'); |
| 94 |
Vite::enqueueStaticScript( |
| 95 |
$slug . '-fluentcart-print-this-plugin', |
| 96 |
'public/lib/printThis-2.0.0.min.js', |
| 97 |
[] |
| 98 |
); |
| 99 |
|
| 100 |
Vite::enqueueScript( |
| 101 |
$slug . '-fluentcart-print-js2', |
| 102 |
'public/print/Print.js', |
| 103 |
[] |
| 104 |
)->with([ |
| 105 |
'fct_receipt_data' => self::getLocalizeData() |
| 106 |
]); |
| 107 |
|
| 108 |
return self::loadView('', $params, 'print/index.php'); |
| 109 |
} |
| 110 |
|
| 111 |
public static function getLocalizeData(): array |
| 112 |
{ |
| 113 |
return [ |
| 114 |
'translations' => [ |
| 115 |
'FluentCart Receipt' => __('FluentCart Receipt', 'fluent-cart'), |
| 116 |
'Receipt Number' => __('Receipt Number', 'fluent-cart'), |
| 117 |
] |
| 118 |
]; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
} |
| 124 |
|