Passed
Push — master ( 79c4f7...80a53d )
by Guillaume
12:18
created

Tiki::removeFullscreenButton()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Docsets;
4
5
use Illuminate\Support\Collection;
6
use Wa72\HtmlPageDom\HtmlPageCrawler;
7
use Illuminate\Support\Facades\Storage;
8
9
class Tiki extends BaseDocset
10
{
11
    public const CODE = 'tiki';
12
    public const NAME = 'Tiki';
13
    public const URL = 'doc.tiki.org';
14
    public const INDEX = 'PluginList-output-control-block.html';
15
    public const PLAYGROUND = '';
16
    public const ICON_16 = '../icon.png';
17
    public const ICON_32 = '../[email protected]';
18
    public const EXTERNAL_DOMAINS = [];
19
20
21 1
    public function entries(string $file): Collection
22
    {
23 1
        $entries = collect();
24
25 1
        $crawler = HtmlPageCrawler::create(Storage::get($file));
26
27
        $crawler->filter('link[rel=canonical]')->each(static function (HtmlPageCrawler $node) use ($entries) {
28 1
            $entries->push([
29 1
                'name' => $node->attr('href'),
30 1
                'type' => 'Guide',
31 1
                'path' => $node->attr('href')
32
            ]);
33 1
        });
34
35 1
        return $entries;
36
    }
37
38 1
    public function format(string $html): string
39
    {
40 1
        $crawler = HtmlPageCrawler::create($html);
41
42 1
        $this->removeNavbar($crawler);
43 1
        $this->removeLeftSidebarButton($crawler);
44 1
        $this->removeFullscreenButton($crawler);
45 1
        $this->removePageTopModules($crawler);
46 1
        $this->removeWikiActionsWrapper($crawler);
47 1
        $this->removeBreadcrumb($crawler);
48 1
        $this->removeTopbar($crawler);
49 1
        $this->removeLeftSidebar($crawler);
50 1
        $this->removeRightSidebar($crawler);
51 1
        $this->removePagebar($crawler);
52 1
        $this->removeFooter($crawler);
53
54 1
        $this->updateCss($crawler);
55
56 1
        return $crawler->saveHTML();
57
    }
58
59 1
    protected function removeNavbar(HtmlPageCrawler $crawler)
60
    {
61 1
        $crawler->filter('nav.navbar')->remove();
62 1
    }
63
64 1
    protected function removeLeftSidebarButton(HtmlPageCrawler $crawler)
65
    {
66 1
        $crawler->filter('#row-middle > div.side-col-toggle-container')->remove();
67 1
    }
68
69 1
    protected function removeFullscreenButton(HtmlPageCrawler $crawler)
70
    {
71 1
        $crawler->filter('#fullscreenbutton')->remove();
72 1
    }
73
74 1
    protected function removePageTopModules(HtmlPageCrawler $crawler)
75
    {
76 1
        $crawler->filter('#pagetop_modules')->remove();
77 1
    }
78
79 1
    protected function removeWikiActionsWrapper(HtmlPageCrawler $crawler)
80
    {
81 1
        $crawler->filter('#col1 > div.wikiactions_wrapper')->remove();
82 1
    }
83
84 1
    protected function removeBreadcrumb(HtmlPageCrawler $crawler)
85
    {
86 1
        $crawler->filter('nav.nav-breadcrumb')->remove();
87 1
    }
88
89 1
    protected function removeTopbar(HtmlPageCrawler $crawler)
90
    {
91 1
        $crawler->filter('#topbar')->remove();
92 1
    }
93
94 1
    protected function removeLeftSidebar(HtmlPageCrawler $crawler)
95
    {
96 1
        $crawler->filter('#col2')->remove();
97 1
    }
98
99 1
    protected function removeRightSidebar(HtmlPageCrawler $crawler)
100
    {
101 1
        $crawler->filter('script[src="autoToc.js"]')->remove();
102 1
    }
103
104 1
    protected function removePagebar(HtmlPageCrawler $crawler)
105
    {
106 1
        $crawler->filter('#page-bar')->remove();
107 1
    }
108
109 1
    protected function removeFooter(HtmlPageCrawler $crawler)
110
    {
111 1
        $crawler->filter('#footer')->remove();
112 1
    }
113
114 1
    protected function updateCSS(HtmlPageCrawler $crawler)
115
    {
116 1
        $this->updateTopPadding($crawler);
117 1
        $this->updateArticlePadding($crawler);
118
119
        // $this->updateHeader($crawler);
120
        // $this->updateContainerWidth($crawler);
121
        // $this->updateBottomPadding($crawler);
122 1
    }
123
124 1
    protected function updateTopPadding(HtmlPageCrawler $crawler)
125
    {
126 1
        $crawler->filter('body')
127 1
            ->removeClass('navbar-padding')
128 1
            ->addClass('hide_zone_left')
129 1
            ->css('padding-top', '0')
130
        ;
131 1
    }
132
133 1
    protected function updateArticlePadding(HtmlPageCrawler $crawler)
134
    {
135 1
        $crawler->filter('article#top')
136 1
            ->css('padding-top', '44px')
137
        ;
138 1
    }
139
}
140