Passed
Push — master ( e95921...ddbd1b )
by Dimas
13:28 queued 05:15
created

fab()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 42
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 26
nc 18
nop 1
dl 0
loc 42
rs 8.8817
c 0
b 0
f 0
1
<?php
2
3
$GLOBALS['fab-creator'] = '';
4
5
/**
6
 * Floating action bar creator
7
 * ```php
8
 * echo fab(['href' => '#', 'icon' => 'fa-question', 'attributes' => 'title="#href" rel="nofollow"'], ['href' => '#user', 'icon' => 'fa-user', 'attributes' => 'title="#user" rel="nofollow"']);
9
 * ```
10
 * @param array $c1 max 4 options
11
 */
12
function fab(...$c1)
13
{
14
    $return = '';
15
    $id_wrapper = uniqid('fab-wrapper-');
16
    $id_checkbox = uniqid('fab-checkbox-');
17
18
    $return .= '
19
<div class="fab-wrapper" id="' . $id_wrapper . '">
20
    <input id="' . $id_checkbox . '" name="' . $id_checkbox . '" type="checkbox" class="fab-checkbox" />
21
    <label class="fab-label" for="' . $id_checkbox . '">
22
        <span class="fab-dots fab-dots-1"></span>
23
        <span class="fab-dots fab-dots-2"></span>
24
        <span class="fab-dots fab-dots-3"></span>
25
    </label>
26
    <div class="fab-wheel"> ';
27
    for ($i = 0; $i < count($c1); $i++) {
28
        $id = "fAb$i";
29
        if (!isset($c1[$i]['href'])) {
30
            $c1[$i]['href'] = "#$id";
31
        }
32
        if (!isset($c1[$i]['attributes'])) {
33
            $c1[$i]['attributes'] = "";
34
        }
35
        if (!isset($c1[$i]['icon'])) {
36
            $c1[$i]['icon'] = "fa-question";
37
        }
38
        $return .= '
39
        <a id="' . $id . '" class="fab-action fab-action-' . $i . '" href="' . $c1[$i]['href'] . '" ' . trim($c1[$i]['attributes']) . '>
40
            <i class="fas ' . $c1[$i]['icon'] . '"></i>
41
        </a>';
42
    }
43
    $return .= '
44
    </div>
45
</div>';
46
    if (empty($GLOBALS['fab-creator'])) {
47
        $css = read_file(ROOT . '/src/MVC/themes/assets/partial/fab.min.css');
48
        $return .= '<style>' . $css . '</style>';
49
        $js = \MVC\helper::get_url_path(ROOT . '/src/MVC/themes/assets/partial/fab.min.js', true);
50
        $return .= "<script>const id_fab = '$id_wrapper';const id_fab_checkbox = '$id_checkbox';</script><script src='$js' async='true'></script>";
51
        $GLOBALS['fab-creator'] = 'true';
52
    }
53
    return $return;
54
}
55