Test Failed
Push — develop ( 9873ab...1da57b )
by Paul
13:43
created

Controller::filterInlineWooStyles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Divi;
4
5
use GeminiLabs\SiteReviews\Contracts\BuilderContract;
6
use GeminiLabs\SiteReviews\Controllers\AbstractController;
7
use GeminiLabs\SiteReviews\Helpers\Arr;
8
use GeminiLabs\SiteReviews\Helpers\Cast;
9
use GeminiLabs\SiteReviews\Modules\Paginate;
10
11
class Controller extends AbstractController
12
{
13
    /**
14
     * Fix compatibility with the Divi Dynamic CSS option.
15
     *
16
     * @param array  $shortcodes
17
     * @param string $content
18
     *
19
     * @filter et_dynamic_assets_modules_atf
20
     */
21
    public function filterDynamicAssets($shortcodes, $content): array
22
    {
23
        if (1 === preg_match('/site_reviews/', Cast::toString($content))) {
24
            add_filter('et_required_module_assets', function ($assets) {
25
                $assets[] = 'et_pb_contact_form';
26
                $assets[] = 'et_pb_gallery';
27
                $assets[] = 'et_pb_search';
28
                return array_values(array_unique($assets));
29
            });
30
        }
31
        return Arr::consolidate($shortcodes);
32
    }
33
34
    /**
35
     * @action site-reviews/enqueue/public/inline-styles
36
     */
37
    public function filterInlineWooStyles(string $css): string
38
    {
39
        $css .= file_get_contents(glsr()->path('assets/styles/integrations/divi-woo-inline.css'));
40
        return $css;
41
    }
42
43
    /**
44
     * @see filterPaginationLinks
45
     *
46
     * @filter site-reviews/paginate_link
47
     */
48
    public function filterPaginationLink(array $link, array $args, BuilderContract $builder): array
49
    {
50
        if ('current' === $link['type']) {
51
            $args['class'] = 'active';
52
        }
53
        if ('prev' === $link['type']) {
54
            $args['class'] = 'page-prev';
55
            $class = 'prev';
56
        }
57
        if ('next' === $link['type']) {
58
            $args['class'] = 'page-next';
59
            $class = 'next';
60
        }
61
        $link['link'] = $builder->li([
62
            'text' => $builder->a($args),
63
            'class' => $class ?? 'page',
64
        ]);
65
        return $link;
66
    }
67
68
    /**
69
     * @filter site-reviews/paginate_links
70
     */
71
    public function filterPaginationLinks(string $links, array $args): string
72
    {
73
        if ('divi' !== glsr_get_option('general.style')) {
74
            return $links;
75
        }
76
        $args = wp_parse_args(['end_size' => 0, 'mid_size' => 2], $args);
77
        add_filter('site-reviews/paginate_link', [$this, 'filterPaginationLink'], 10, 3);
78
        $links = (new Paginate($args))->links();
79
        remove_filter('site-reviews/paginate_link', [$this, 'filterPaginationLink']);
80
        $links = wp_list_pluck($links, 'link');
81
        return implode("\n", $links);
82
    }
83
84
    /**
85
     * @action divi_extensions_init
86
     */
87
    public function registerDiviModules(): void
88
    {
89
        // new DiviFormWidget();
90
        // new DiviReviewsWidget();
91
        // new DiviSummaryWidget();
92
    }
93
}
94