1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php

class BFIPagemediaNivoModel extends BFIPagemediaModel implements iBFIPagemedia {
    
    /*
     * Get Meta data via $this->getValue()
     */
    
    const SLUG = 'nivo';
    
    function __construct() {
        $this->slug = self::SLUG;
        $this->name = 'Nivo Slider';
    }
    
    public function getHeader() {
        bfi_wp_enqueue_script('nivo', '//cdnjs.cloudflare.com/ajax/libs/jquery-nivoslider/3.1/jquery.nivo.slider.pack.js', array('jquery'), NULL, true);
        bfi_wp_enqueue_style('nivocss', '//cdnjs.cloudflare.com/ajax/libs/jquery-nivoslider/3.1/nivo-slider.css', array(), NULL);

        $numSlides = 0;
        $style = '';
        for ($i = 1; $i <= 10; $i++) {
            $image = "getImage$i";
            $caption = "getCaption$i";
            $subcaption = "getSubcaption$i";
            $location = "getCaptionlocation$i";
            if (!$this->$image()) continue;
            $numSlides++;
            $textcolor = "getTextcolor$i";
            $captionbg = "getCaptionbg$i";
            $bg = str_replace('#', '', $this->$captionbg());
        $bg = hexdec(substr($bg, 0, 2)) .','. hexdec(substr($bg, 2, 2)) .','. hexdec(substr($bg, 4, 2));
            if ($this->$location() == "tr") {
                $location = "top: 0; bottom: auto; left: auto; right: 0; text-align: right";
            } else if ($this->$location() == "tl") {
                $location = "top: 0; bottom: auto; left: 0; right: auto;";
            } else if ($this->$location() == "bl") {
                $location = "top: auto; bottom: 0; left: 0; right: auto;";
            } else { // br
                $location = "top: auto; bottom: 0; left: auto; right: 0; text-align: right";
            }
            $style .= ".nivo-caption.slide-".($numSlides-1).", .nivo-caption.slide-".($numSlides-1)." h4{
                    color: ".$this->$textcolor().";
                }
                .nivo-caption.slide-".($numSlides-1)." {
                    background: rgba(".$bg.",.6);
                    $location
                }";
        }
        $style = $style ? "<style>$style</style>" : $style;
        return $style;
    }
    
    public function getBody() {
        $sideWidth = 1;
        $numSlides = 0;
        $slides = '';
        $wrapperWidth = $this->getCaptiontype() == "side" ? $sideWidth * 100 : 100;
        for ($i = 1; $i <= 10; $i++) {
            $image = "getImage$i";
            $caption = "getCaption$i";
            $subcaption = "getSubcaption$i";
            if (!$this->$image()) continue;
            $numSlides++;
            $title = '';
            if ($this->$caption()) {
                $title .= "<h4>".$this->$caption()."</h4>";
            }
            if ($this->$subcaption()) {
                $title .= do_shortcode($this->$subcaption());
            }
            $title = str_replace("'", '&#39;', $title); // '
            $title = str_replace('"', '&#34;', $title); // "
            $title = str_replace('<', '&lt;', $title); // <
            $slides .= sprintf("<img src='%s' title='%s'/>", 
                bfi_thumb($this->$image(), array('width' => $this->getCaptiontype() == "side" ? $this->getWidth() * $sideWidth : $this->getWidth(), 'height' => $this->getHeight(), 'crop' => true)),
                addslashes($title)
                );
        }
                $controlNav = $numSlides > 1 ? "true" : "false";
        $content = "
        <div class='slider-wrapper theme-default' style='width: $wrapperWidth%;'>
            <div class='nivoSlider'>{content}</div>
            <div class='nivoCaptionSpacer'></div>
        </div>
        <script>
        jQuery(document).ready(function($) {
            \$('#heading-box .nivoSlider').nivoSlider({
                effect: '{$this->getEffect()}',
                animSpeed: {$this->getAnimation()},
                pauseTime: {$this->getPause()},
                controlNav: {$controlNav},
                    directionNav: false,
                    controlNavThumbs: false,
                captionOpacity: 1.0,
                afterLoad: function() {
                    slide = \$('#heading-box .nivoSlider').data('nivo:vars').currentSlide;
                    \$('#heading-box .nivo-caption').attr('class', 'nivo-caption slide-'+slide);
                    Cufon('#heading-box .nivo-caption h4');
                    \$('header .nivoSlider').fadeIn();
                },
                beforeChange: function() {      
                    slide = \$('#heading-box .nivoSlider').data('nivo:vars').currentSlide;                      
                    var nextSlide = slide + 1 >= \$('#heading-box .nivoSlider').data('nivo:vars').totalSlides ? 0 : slide+1;
                    \$('#heading-box .nivo-caption').attr('class', 'nivo-caption slide-'+(nextSlide));
                    if (\$('#heading-box .nivoSlider img:eq('+slide+')').attr('title') != '') {
                        \$('#heading-box .nivo-caption').hide(); // just hide asap since colors will flicker
                    }
                    setTimeout(\"Cufon('#heading-box .nivo-caption h4');\", 100);
                },
                afterChange: function() {
                        slide = \$('#heading-box .nivoSlider').data('nivo:vars').currentSlide;
                        \$('#heading-box .nivo-caption').attr('class', 'nivo-caption slide-'+slide);
                        if (\$('#heading-box .nivoSlider img:eq('+slide+')').attr('title') != '') {
                            \$('#heading-box .nivo-caption').fadeIn();
                        }
                        setTimeout(\"Cufon('#heading-box .nivo-caption h4');\", 100);
                }
                //$('.nivoSlider').data('nivo:vars').currentSlide
            });
        });
        </script>
        ";
        $content = str_replace('{content}', $slides, $content);
        return $content;
    }
}