Skip to content

Commit

Permalink
Update to 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
elzadj committed Aug 8, 2023
1 parent 075996b commit ce9d062
Show file tree
Hide file tree
Showing 259 changed files with 16,324 additions and 5,249 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _Updates: 7 August 2023_
* Update: Dynamic content link provided for context loop blocks
* Update: Interaction builder background transitions implemented
* Update: Hover colour added for the search close icon
* Update: Text strings allowed in number inputs
* Update: Text strings disallowed in number inputs
* Update: Repeater functionality implemented
* Fix: Issue with tags and categories links on the editor addressed
* Fix: Styles on Gutenberg's responsive preview improved
Expand Down
3 changes: 3 additions & 0 deletions core/admin/class-maxi-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,9 @@ public function register_maxi_blocks_settings()
'maxi_rollback_version',
$args_rollback,
);
register_setting('maxi-blocks-settings-group', 'maxi_rollback_version', $args_rollback);
register_setting('maxi-blocks-settings-group', 'maxi_sc_gutenberg_blocks', $args);
register_setting('maxi-blocks-settings-group', 'maxi_show_indicators', $args);
}

public function get_folder_size($folder)
Expand Down
87 changes: 86 additions & 1 deletion core/class-maxi-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,41 @@ public function mb_register_routes()
return current_user_can('edit_posts');
},
]);
register_rest_route($this->namespace, '/acf/get-field-groups', [
'methods' => 'GET',
'callback' => [$this, 'get_acf_field_groups'],
'permission_callback' => function () {
return current_user_can('edit_posts');
},
]);
register_rest_route($this->namespace, '/acf/get-group-fields/(?P<id>\d+)', [
'methods' => 'GET',
'callback' => [$this, 'get_acf_group_fields'],
'args' => [
'id' => [
'validate_callback' => function ($param) {
return is_numeric($param);
},
],
],
'permission_callback' => function () {
return current_user_can('edit_posts');
},
]);
register_rest_route($this->namespace, '/acf/get-field-value/(?P<field_id>\w+)/(?P<post_id>\d+)', [
'methods' => 'GET',
'callback' => [$this, 'get_acf_field_value'],
'args' => [
'id' => [
'validate_callback' => function ($param) {
return is_numeric($param);
},
],
],
'permission_callback' => function () {
return current_user_can('edit_posts');
},
]);
register_rest_route($this->namespace, '/pro', [
'methods' => 'GET',
'callback' => [$this, 'get_maxi_blocks_pro_status'],
Expand Down Expand Up @@ -447,7 +482,6 @@ public function post_maxi_blocks_styles($data, $is_json = true)
}
}


if ((bool) get_option('local_fonts')) {
new MaxiBlocks_Local_Fonts();
}
Expand Down Expand Up @@ -759,6 +793,57 @@ public function set_maxi_blocks_current_custom_data($data, $is_json = true)
return $new_custom_data;
}

public function get_acf_field_groups()
{
if (!class_exists('ACF')) {
return [];
}

$acf_field_groups = get_posts(array(
'post_type' => 'acf-field-group',
'posts_per_page' => -1,
'post_status' => 'publish',
));

$acf_field_groups = array_map(function ($acf_field_group) {
return array(
'id' => $acf_field_group->ID,
'title' => $acf_field_group->post_title,
);
}, $acf_field_groups);

return json_encode($acf_field_groups);
}

public function get_acf_group_fields($request)
{
if (!class_exists('ACF')) {
return [];
}

$group_id = $request['id'];
$fields = acf_get_fields($group_id);

$fields = array_map(function ($field) {
return array(
'id' => $field['key'],
'title' => $field['label'],
'type' => $field['type'],
);
}, $fields);

return json_encode($fields);
}

public function get_acf_field_value($request)
{
if (!class_exists('ACF')) {
return null;
}

return json_encode(get_field_object($request['field_id'], $request['post_id'])['value']);
}

public function get_maxi_blocks_pro_status()
{
$pro = get_option('maxi_pro');
Expand Down
52 changes: 49 additions & 3 deletions core/class-maxi-blocks.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-style-cards.php';

/**
* MaxiBlocks Core Class
*
Expand Down Expand Up @@ -45,6 +47,14 @@ public function __construct()

// Register MaxiBlocks category
add_filter('block_categories_all', [$this, 'maxi_block_category']);

$style_cards = new MaxiBlocks_StyleCards();
$current_style_cards = $style_cards->get_maxi_blocks_active_style_card();

if($current_style_cards && array_key_exists('gutenberg_blocks_status', $current_style_cards) && $current_style_cards['gutenberg_blocks_status']) {
add_filter("render_block", [$this, "maxi_add_sc_native_blocks"], 10, 3);
}

}

public function enqueue_blocks_assets()
Expand Down Expand Up @@ -100,7 +110,7 @@ public function maxi_add_image_taxonomy()
'add_new_item' => __('Add New Maxi Image', 'max-blocks'),
'new_item_name' => __('New Maxi Image Name', 'max-blocks'),
);

$args = array(
'labels' => $labels,
'hierarchical' => false,
Expand All @@ -111,10 +121,10 @@ public function maxi_add_image_taxonomy()
'show_ui' => false,
'show_in_rest' => true
);

register_taxonomy('maxi-image-type', 'attachment', $args);
}

public function maxi_add_image_taxonomy_term()
{
if (!term_exists(__('Maxi Image', 'max-blocks'), 'maxi-image-type')) {
Expand All @@ -141,5 +151,41 @@ public function maxi_block_category($categories)
$categories
);
}

public function maxi_add_sc_native_blocks($block_content, $block, $instance)
{
if (str_contains($block['blockName'], 'core/') && isset($block_content) && !empty($block_content)) {
// We create a new DOMDocument object
$dom = new DOMDocument();
@$dom->loadHTML(mb_convert_encoding($block_content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

// Using XPath to find the elements we want to change
$xpath = new DOMXPath($dom);

// Look for all elements
$elements = $xpath->query('//*');

// Pick the first element
$element = $elements[0];

$classes = $element->getAttribute('class');

if(!str_contains($classes, 'maxi') || !isset($classes) || empty($classes)) {
if(!str_contains($classes, 'maxi-block--use-sc')) {
$element->setAttribute('class', $element->getAttribute('class') . ' maxi-block--use-sc');
}

if(!isset($classes) || empty($classes)) {
$element->setAttribute('class', 'maxi-block--use-sc');
}
}

$block_content = $dom->saveHTML();

return $block_content;
}

return $block_content;
}
}
endif;
26 changes: 21 additions & 5 deletions core/class-maxi-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,26 @@ public function __construct()
// Add All Images - Maxi Images filter to the media library
add_action('wp_enqueue_media', function () {
if (term_exists('maxi-image', 'maxi-image-type')) {
wp_enqueue_script('maxi-media-images-filter', plugin_dir_url(__DIR__) . 'js/mediaFilter.min.js', array( 'media-editor', 'media-views' ));
wp_localize_script('maxi-media-images-filter', 'maxiImagesFilterTerms', array(
'terms' => get_terms('maxi-image-type', array( 'hide_empty' => false )),
));
wp_enqueue_script(
'maxi-media-images-filter',
plugin_dir_url(__DIR__) . 'js/mediaFilter.min.js',
array(
'media-editor',
'media-views'
),
);
wp_localize_script(
'maxi-media-images-filter',
'maxiImagesFilterTerms',
array(
'terms' => get_terms(
'maxi-image-type',
array(
'hide_empty' => false
)
),
)
);
}
});
}
Expand All @@ -69,4 +85,4 @@ public function maxi_blocks_body_class($classes)
return $classes;
}
}
endif;
endif;
Loading

0 comments on commit ce9d062

Please sign in to comment.