Skip to content

Commit 5098f99

Browse files
committed
Update to 1.2.0
1 parent ff884ad commit 5098f99

181 files changed

Lines changed: 4480 additions & 1648 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/admin/class-maxi-dashboard.php

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -560,60 +560,60 @@ public function maxi_blocks_settings()
560560
// $content .= '</div>'; // maxi-dashboard_main-content_accordion-item-content
561561
// $content .= '</div>'; // maxi-dashboard_main-content_accordion-item
562562

563-
// $content .= $this->generate_item_header('Fonts and files', false);
563+
$content .= $this->generate_item_header('Fonts and files', false);
564564

565-
// $description =
566-
// '<h4>' .
567-
// __('Serve Google fonts locally', self::$maxi_text_domain) .
568-
// '</h4>';
569-
// $description .=
570-
// '<p>' .
571-
// __(
572-
// ' Local storage: Download, store and serve font files from a WordPress directory on your site. This method blocks Google’s tracking for web visitors. It can improve or degrade performance, depending on hosting quality or resource usage. Please test and monitor carefully. Unused font files are removed periodically to conserve space.',
573-
// self::$maxi_text_domain,
574-
// ) .
575-
// '</p>';
576-
// $description .=
577-
// '<p>' .
578-
// __(
579-
// 'Google servers: Serve Google font files directly from Google’s servers. It may impact
580-
// privacy (GDPR) if a web visitor’s IP address is revealed to Google.',
581-
// self::$maxi_text_domain,
582-
// );
583-
// $description .=
584-
// '<i> ' . __('(Default)', self::$maxi_text_domain) . '</i></p>';
585-
// $content .= $this->generate_setting(
586-
// $description,
587-
// 'local_fonts',
588-
// $this->local_fonts_upload(),
589-
// );
590-
// if ($font_uploads_dir_size > 0) {
591-
// $content .=
592-
// '<p>' .
593-
// __('Size of the local fonts:', 'maxi-blocks') .
594-
// ' ' .
595-
// $font_uploads_dir_size .
596-
// __('MB', 'maxi-blocks') .
597-
// '</p>';
598-
599-
// if (!(bool) get_option('local_fonts')) {
600-
// update_option('local_fonts_uploaded', false);
601-
// $description =
602-
// '<h4>' .
603-
// __('Remove local fonts', 'maxi-blocks') .
604-
// '</h4>';
605-
// $content .= $this->generate_setting(
606-
// $description,
607-
// 'remove_local_fonts',
608-
// $this->remove_local_fonts(),
609-
// );
610-
// }
611-
// }
565+
$description =
566+
'<h4>' .
567+
__('Serve Google fonts locally', self::$maxi_text_domain) .
568+
'</h4>';
569+
$description .=
570+
'<p>' .
571+
__(
572+
' Local storage: Download, store and serve font files from a WordPress directory on your site. This method blocks Google’s tracking for web visitors. It can improve or degrade performance, depending on hosting quality or resource usage. Please test and monitor carefully. Unused font files are removed periodically to conserve space.',
573+
self::$maxi_text_domain,
574+
) .
575+
'</p>';
576+
$description .=
577+
'<p>' .
578+
__(
579+
'Google servers: Serve Google font files directly from Google’s servers. It may impact
580+
privacy (GDPR) if a web visitor’s IP address is revealed to Google.',
581+
self::$maxi_text_domain,
582+
);
583+
$description .=
584+
'<i> ' . __('(Default)', self::$maxi_text_domain) . '</i></p>';
585+
$content .= $this->generate_setting(
586+
$description,
587+
'local_fonts',
588+
$this->local_fonts_upload(),
589+
);
590+
if ($font_uploads_dir_size > 0) {
591+
$content .=
592+
'<p>' .
593+
__('Size of the local fonts:', 'maxi-blocks') .
594+
' ' .
595+
$font_uploads_dir_size .
596+
__('MB', 'maxi-blocks') .
597+
'</p>';
598+
599+
if (!(bool) get_option('local_fonts')) {
600+
update_option('local_fonts_uploaded', false);
601+
$description =
602+
'<h4>' .
603+
__('Remove local fonts', 'maxi-blocks') .
604+
'</h4>';
605+
$content .= $this->generate_setting(
606+
$description,
607+
'remove_local_fonts',
608+
$this->remove_local_fonts(),
609+
);
610+
}
611+
}
612612

613-
// $content .= get_submit_button(__('Save changes', 'maxi-blocks'));
613+
$content .= get_submit_button(__('Save changes', 'maxi-blocks'));
614614

615-
// $content .= '</div>'; // maxi-dashboard_main-content_accordion-item-content
616-
// $content .= '</div>'; // maxi-dashboard_main-content_accordion-item
615+
$content .= '</div>'; // maxi-dashboard_main-content_accordion-item-content
616+
$content .= '</div>'; // maxi-dashboard_main-content_accordion-item
617617

618618
$content .= $this->generate_item_header(
619619
'Documentation & support',

core/class-maxi-api.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,8 @@ public function post_maxi_blocks_styles($data, $is_json = true)
447447
}
448448
}
449449

450-
// Temporary disable local fonts
451-
// if ((bool) get_option('local_fonts')) {
452-
if (false) {
450+
451+
if ((bool) get_option('local_fonts')) {
453452
new MaxiBlocks_Local_Fonts();
454453
}
455454

core/class-maxi-dynamic-content.php

Lines changed: 134 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
require_once MAXI_PLUGIN_DIR_PATH . 'core/class-maxi-styles.php';
23

34
/**
45
* Server side part of MaxiBlocks_DynamicContent Gutenberg component
@@ -27,22 +28,21 @@ public static function register()
2728
/**
2829
* Variables
2930
*/
31+
private static $custom_data = null;
32+
3033
private static $dynamic_content_attributes = [
3134
'dc-error' => [
3235
'type' => 'string',
3336
'default' => '',
3437
],
3538
'dc-status' => [
3639
'type' => 'boolean',
37-
'default' => false,
3840
],
3941
'dc-type' => [
4042
'type' => 'string',
41-
'default' => 'posts',
4243
],
4344
'dc-relation' => [
4445
'type' => 'string',
45-
'default' => 'by-id',
4646
],
4747
'dc-id' => [
4848
'type' => 'number',
@@ -146,6 +146,12 @@ public static function register()
146146
'type' => 'string',
147147
'default' => '',
148148
],
149+
'dc-order' => [
150+
'type' => 'string',
151+
],
152+
'dc-accumulator' => [
153+
'type' => 'number',
154+
],
149155
];
150156

151157
/**
@@ -183,6 +189,23 @@ public function render_dc($attributes, $content)
183189
return $content;
184190
}
185191

192+
if (self::$custom_data === null) {
193+
if (class_exists('MaxiBlocks_Styles')) {
194+
$styles = new MaxiBlocks_Styles();
195+
self::$custom_data = $styles->custom_meta('dynamic_content');
196+
} else {
197+
self::$custom_data = [];
198+
}
199+
}
200+
201+
$context_loop = [];
202+
203+
if (array_key_exists($attributes['uniqueID'], self::$custom_data)) {
204+
$context_loop = self::$custom_data[$attributes['uniqueID']];
205+
}
206+
207+
$attributes = array_merge($attributes, $this->get_dc_values($attributes, $context_loop));
208+
186209
if (array_key_exists('dc-link-status', $attributes)) {
187210
$dc_link_status = $attributes['dc-link-status'];
188211

@@ -233,6 +256,10 @@ public function render_dc_content($attributes, $content)
233256
'dc-field' => $dc_field,
234257
) = $attributes;
235258

259+
if ($attributes['dc-field'] === 'static_text') {
260+
return $content;
261+
}
262+
236263
if (empty($dc_type)) {
237264
$dc_type = 'posts';
238265
}
@@ -274,6 +301,7 @@ public function render_dc_image($attributes, $content)
274301
'dc-relation' => $dc_relation,
275302
'dc-field' => $dc_field,
276303
'dc-id' => $dc_id,
304+
'dc-author' => $dc_author,
277305
) = $attributes;
278306

279307
if (empty($dc_type)) {
@@ -374,7 +402,7 @@ public function get_post($attributes)
374402
} elseif ($is_random) {
375403
$args['orderby'] = 'rand';
376404
} elseif ($is_sort_relation) {
377-
$args = array_merge($args, $this->get_order_by_args($dc_relation, $dc_order_by, $dc_accumulator));
405+
$args = array_merge($args, $this->get_order_by_args($dc_relation, $dc_order_by, $dc_accumulator, $dc_type));
378406
}
379407

380408
$query = new WP_Query($args);
@@ -397,7 +425,7 @@ public function get_post($attributes)
397425
];
398426
} elseif ($is_sort_relation) {
399427
$args['post_status'] = 'inherit';
400-
$args = array_merge($args, $this->get_order_by_args($dc_relation, $dc_order_by, $dc_accumulator));
428+
$args = array_merge($args, $this->get_order_by_args($dc_relation, $dc_order_by, $dc_accumulator, $dc_type));
401429
}
402430

403431
$query = new WP_Query($args);
@@ -436,21 +464,22 @@ public function get_post($attributes)
436464
return $terms[0];
437465
} elseif ($dc_type === 'users') {
438466
$args = [
439-
// 'role' => 'author',
440-
// 'number' => 1,
467+
'capability' => 'edit_posts',
441468
];
442469

443-
if ($dc_relation == 'random') {
444-
$args['orderby'] = 'rand';
445-
} elseif ($is_sort_relation) {
446-
$args = array_merge($args, $this->get_order_by_args($dc_relation, $dc_order_by, $dc_accumulator));
447-
} else {
448-
$args['include'] = $dc_id;
470+
if ($is_sort_relation) {
471+
$args = array_merge($args, $this->get_order_by_args($dc_relation, $dc_order_by, $dc_accumulator, $dc_type));
472+
} elseif ($dc_relation === 'by-id') {
473+
$args['include'] = $dc_author ?? $dc_id;
449474
}
450475

451476
$users = get_users($args);
452477

453-
return $users[0];
478+
if ($dc_relation === 'random') {
479+
return $users[array_rand($users)];
480+
}
481+
482+
return end($users);
454483
} elseif ($dc_type === 'settings') {
455484
return null;
456485
}
@@ -729,12 +758,100 @@ public function get_limited_string($string, $limit)
729758
return $string;
730759
}
731760

732-
public function get_order_by_args($relation, $order, $accumulator)
761+
public function get_default_dc_value($target, $obj, $defaults)
762+
{
763+
if(!is_array($defaults) || !isset($defaults[$target]) || !is_array($obj)) {
764+
return false;
765+
}
766+
767+
if (is_callable($defaults[$target])) {
768+
return $defaults[$target]($obj);
769+
}
770+
771+
return $defaults[$target];
772+
}
773+
774+
public function get_dc_value($target, $dynamic_content, $context_loop, $defaults, $result)
733775
{
776+
$context_loop_status = isset($context_loop['cl-status']) ? $context_loop['cl-status'] : false;
777+
778+
$dc_value = isset($dynamic_content['dc-' . $target]) ? $dynamic_content['dc-' . $target] : null;
779+
$context_loop_value = isset($context_loop['cl-' . $target]) ? $context_loop['cl-' . $target] : null;
780+
781+
if ($target === 'status') {
782+
return $dc_value !== null ? $dc_value : $this->get_default_dc_value($target, $result, $defaults);
783+
}
784+
785+
if ($dc_value !== null) {
786+
return $dc_value;
787+
}
788+
789+
if ($context_loop_status && $context_loop_value !== null) {
790+
return $context_loop_value;
791+
}
792+
793+
return $this->get_default_dc_value($target, $result, $defaults);
794+
}
795+
796+
public function order_callback($attributes)
797+
{
798+
$relation = $attributes['dc-relation'] ?? null;
799+
return $relation === 'by-date' ? 'desc' : 'asc';
800+
}
801+
802+
/**
803+
* Combines `attributes` with `context_loop` and `defaults`
804+
* to get the final values for dynamic content.
805+
*/
806+
public function get_dc_values($attributes, $context_loop)
807+
{
808+
$defaults = [
809+
'status' => false,
810+
'type' => 'posts',
811+
'relation' => 'by-id',
812+
'order' => [$this, 'order_callback'],
813+
'accumulator' => 0,
814+
];
815+
816+
$dynamic_content = array_filter($attributes, function ($key) {
817+
return strpos($key, 'dc-') === 0;
818+
}, ARRAY_FILTER_USE_KEY);
819+
820+
$dynamic_content_keys = array_keys($dynamic_content);
821+
$context_loop_keys = array_map(function ($key) {
822+
return str_replace('cl-', 'dc-', $key);
823+
}, array_keys($context_loop));
824+
$defaults_keys = array_map(function ($key) {
825+
return 'dc-' . $key;
826+
}, array_keys($defaults));
827+
828+
$values_keys = array_merge($dynamic_content_keys, $context_loop_keys, $defaults_keys);
829+
830+
$result = [];
831+
832+
foreach ($values_keys as $key) {
833+
$target = str_replace('dc-', '', $key);
834+
$dc_value = $this->get_dc_value($target, $dynamic_content, $context_loop, $defaults, $result);
835+
$result[$key] = $dc_value;
836+
}
837+
838+
return $result;
839+
}
840+
841+
public function get_order_by_args($relation, $order, $accumulator, $dc_type)
842+
{
843+
if ($dc_type === 'users') {
844+
$order_by = $relation === 'by-date' ? 'user_registered' : 'display_name';
845+
$limit_key = 'number';
846+
} else {
847+
$order_by = $relation === 'by-date' ? 'date' : 'title';
848+
$limit_key = 'posts_per_page';
849+
}
850+
734851
return [
735-
'orderby' => $relation === 'by-date' ? 'date' : 'title',
852+
'orderby' => $order_by,
736853
'order' => $order,
737-
'posts_per_page' => $accumulator + 1,
854+
$limit_key => $accumulator + 1,
738855
];
739856
}
740857
}

0 commit comments

Comments
 (0)