| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\Modules\Gutenberg; |
| 4 |
|
| 5 |
use FluentCommunity\App\Services\Helper; |
| 6 |
use FluentCommunity\App\Vite; |
| 7 |
|
| 8 |
class EditorBlock |
| 9 |
{ |
| 10 |
public function register($app) |
| 11 |
{ |
| 12 |
add_action('init', [$this, 'registerBlock']); |
| 13 |
} |
| 14 |
|
| 15 |
public function registerBlock() |
| 16 |
{ |
| 17 |
global $pagenow; |
| 18 |
if ($pagenow == 'site-editor.php') { |
| 19 |
$asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php'); |
| 20 |
wp_register_style( |
| 21 |
'custom-layout-block-editor-style', |
| 22 |
plugins_url('build/index.css', __FILE__), |
| 23 |
array(), |
| 24 |
$asset_file['version'] |
| 25 |
); |
| 26 |
|
| 27 |
wp_register_style('fluent_community_global', Vite::getDynamicSrcUrl('global.scss'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, 'screen'); |
| 28 |
|
| 29 |
wp_register_script( |
| 30 |
'custom-layout-block-editor', |
| 31 |
plugins_url('build/index.js', __FILE__), |
| 32 |
$asset_file['dependencies'], |
| 33 |
$asset_file['version'] |
| 34 |
); |
| 35 |
} |
| 36 |
if (function_exists('\register_block_type')) { |
| 37 |
\register_block_type( |
| 38 |
'fluent-community/page-layout', |
| 39 |
array( |
| 40 |
'editor_script' => 'custom-layout-block-editor', |
| 41 |
'editor_style' => 'custom-layout-block-editor-style', |
| 42 |
'style' => 'fluent_community_global', |
| 43 |
'render_callback' => [$this, 'render'], |
| 44 |
'supports' => [ |
| 45 |
'html' => false |
| 46 |
], |
| 47 |
'attributes' => array( |
| 48 |
'showPageHeader' => array( |
| 49 |
'type' => 'boolean', |
| 50 |
'default' => true, |
| 51 |
), |
| 52 |
'useFullWidth' => array( |
| 53 |
'type' => 'boolean', |
| 54 |
'default' => false, |
| 55 |
), |
| 56 |
'hideCommunityHeader' => array( |
| 57 |
'type' => 'boolean', |
| 58 |
'default' => false, |
| 59 |
), |
| 60 |
'useBuildInTheme' => array( |
| 61 |
'type' => 'boolean', |
| 62 |
'default' => true, |
| 63 |
), |
| 64 |
), |
| 65 |
) |
| 66 |
); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
public function render($attributes, $content) |
| 71 |
{ |
| 72 |
static $isLoaded; |
| 73 |
if ($isLoaded) { |
| 74 |
return 'Space Layout is already loaded before'; |
| 75 |
} |
| 76 |
|
| 77 |
if (!$isLoaded) { |
| 78 |
$isLoaded = true; |
| 79 |
} |
| 80 |
|
| 81 |
$contenx = 'wp'; |
| 82 |
if (isset($_REQUEST['context']) && $_REQUEST['context'] == 'edit' && Helper::isSiteAdmin()) { |
| 83 |
$contenx = 'block_editor'; |
| 84 |
} |
| 85 |
|
| 86 |
$useBuildInTheme = $attributes['useBuildInTheme'] ?? false; |
| 87 |
|
| 88 |
do_action('fluent_community/enqueue_global_assets', $useBuildInTheme); |
| 89 |
$showHeader = $attributes['showPageHeader'] ?? true; |
| 90 |
$useFullWidth = $attributes['useFullWidth'] ?? true; |
| 91 |
$hideCommunityHeader = $attributes['hideCommunityHeader'] ?? false; |
| 92 |
|
| 93 |
ob_start(); |
| 94 |
?> |
| 95 |
<div class="fluent_com fluent_com_wp_pages"> |
| 96 |
<div class="fhr_wrap"> |
| 97 |
<?php if (!$hideCommunityHeader): ?> |
| 98 |
<?php do_action('fluent_community/portal_header', $contenx); ?> |
| 99 |
<?php endif; ?> |
| 100 |
<div class="fhr_content"> |
| 101 |
<div class="fhr_home"> |
| 102 |
<div class="feed_layout"> |
| 103 |
<div class="spaces"> |
| 104 |
<div id="fluent_community_sidebar_menu" class="space_contents"> |
| 105 |
<!-- start--> |
| 106 |
<?php do_action('fluent_community/portal_sidebar', $contenx); ?> |
| 107 |
<!-- end--> |
| 108 |
</div> |
| 109 |
</div> |
| 110 |
<div class="fcom_wp_page"> |
| 111 |
<?php if ($showHeader): ?> |
| 112 |
<div class="fhr_content_layout_header"> |
| 113 |
<?php if ($contenx == 'block_editor'): ?> |
| 114 |
<div class="fhr_page_title">{{ Page Title }}</div> |
| 115 |
<?php else: ?> |
| 116 |
<div class="fhr_page_title"><?php the_title(); ?></div> |
| 117 |
<?php endif; ?> |
| 118 |
</div> |
| 119 |
<?php endif; ?> |
| 120 |
<div |
| 121 |
class="wp_content_wrapper <?php echo $useFullWidth ? 'wp_content_wrapper_full' : ''; ?>"> |
| 122 |
<div class="wp_content"> |
| 123 |
<?php if ($contenx == 'block_editor'): ?> |
| 124 |
<p>Your page content will be shown here</p> |
| 125 |
<?php else: ?> |
| 126 |
<?php the_content(); ?> |
| 127 |
<?php endif; ?> |
| 128 |
</div> |
| 129 |
</div> |
| 130 |
</div> |
| 131 |
</div> |
| 132 |
</div> |
| 133 |
</div> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
<?php |
| 138 |
return ob_get_clean(); |
| 139 |
} |
| 140 |
|
| 141 |
public function useCommunityTemplate($title, $contentCallback = null) |
| 142 |
{ |
| 143 |
do_action('fluent_community/enqueue_global_assets', true); |
| 144 |
$useFullWidth = false; |
| 145 |
$hideCommunityHeader = false; |
| 146 |
|
| 147 |
ob_start(); |
| 148 |
?> |
| 149 |
<div class="fluent_com"> |
| 150 |
<div class="fhr_wrap"> |
| 151 |
<?php if (!$hideCommunityHeader): ?> |
| 152 |
<?php do_action('fluent_community/portal_header', 'headless'); ?> |
| 153 |
<?php endif; ?> |
| 154 |
<div class="fhr_content"> |
| 155 |
<div class="fhr_home"> |
| 156 |
<div class="feed_layout"> |
| 157 |
<div class="spaces"> |
| 158 |
<div id="fluent_community_sidebar_menu" class="space_contents"> |
| 159 |
<!-- start--> |
| 160 |
<?php do_action('fluent_community/portal_sidebar', 'headless'); ?> |
| 161 |
<!-- end--> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
<div class="fcom_wp_page"> |
| 165 |
<?php if ($title): ?> |
| 166 |
<div class="fhr_content_layout_header"> |
| 167 |
<div class="fhr_page_title"><?php echo wp_kses_post($title); ?></div> |
| 168 |
</div> |
| 169 |
<?php endif; ?> |
| 170 |
<div class="wp_content_wrapper <?php echo $useFullWidth ? 'wp_content_wrapper_full' : ''; ?>"> |
| 171 |
<div class="wp_content"> |
| 172 |
<?php if ($contentCallback): ?> |
| 173 |
<?php call_user_func($contentCallback); ?> |
| 174 |
<?php endif; ?> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
</div> |
| 178 |
</div> |
| 179 |
</div> |
| 180 |
</div> |
| 181 |
</div> |
| 182 |
</div> |
| 183 |
</div> |
| 184 |
<?php |
| 185 |
return ob_get_clean(); |
| 186 |
} |
| 187 |
} |
| 188 |
|