Plugin Directory

source: modal-window/tags/5.3.5/public/class-public.php

Last change on this file was 2915607, checked in by Wpcalc, 2 years ago

Update to version 5.3.5

File size: 5.3 KB
Line 
1<?php
2/**
3 * Public Class
4 *
5 * @package     Wow_Plugin
6 * @subpackage  Public
7 * @copyright   Copyright (c) 2018, Dmytro Lobov
8 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since       1.0
10 */
11
12namespace modal_window;
13
14if ( ! defined( 'ABSPATH' ) ) {
15        exit;
16}
17
18class Wow_Plugin_Public {
19
20        private $info;
21
22        public function __construct( $info ) {
23
24                $this->plugin = $info['plugin'];
25                $this->url    = $info['url'];
26                $this->rating = $info['rating'];
27
28                add_shortcode( 'Wow-Modal-Windows', array( $this, 'shortcode' ) );
29                add_shortcode( $this->plugin['shortcode'], array( $this, 'shortcode' ) );
30
31                add_shortcode( 'videoBox', array( $this, 'video_shortcode' ) );
32                add_shortcode( 'buttonBox', array( $this, 'button_shortcode' ) );
33                add_shortcode( 'iframeBox', array( $this, 'iframe_shortcode' ) );
34
35                // Shortcodes for columns
36                add_shortcode( 'w-row', array( $this, 'shortcode_row' ) );
37                add_shortcode( 'w-column', array( $this, 'shortcode_columns' ) );
38
39                // shortcode for icon
40                add_shortcode( 'wow-icon', array( $this, 'shortcode_icon' ) );
41
42                add_action( 'wp_footer', array( $this, 'display' ) );
43
44        }
45
46        function shortcode( $atts ) {
47                ob_start();
48                require plugin_dir_path( __FILE__ ) . 'shortcode.php';
49                $shortcode = ob_get_contents();
50                ob_end_clean();
51
52                return $shortcode;
53        }
54
55        function shortcode_icon( $atts ) {
56                ob_start();
57                require plugin_dir_path( __FILE__ ) . 'shortcode_icon.php';
58                $shortcode = ob_get_contents();
59                ob_end_clean();
60
61                return $shortcode;
62        }
63
64        function shortcode_row( $atts, $content = null ) {
65                return '<div class="wow-col">' . do_shortcode( $content ) . '</div>';
66        }
67
68        function shortcode_columns( $atts, $content = null ) {
69                extract( shortcode_atts( array( 'width' => "", 'align' => '' ), $atts ) );
70                $width = ! empty( $width ) ? $width : '12';
71                $align = ! empty( $align ) ? $align : 'left';
72
73                return '<div class="wow-col-' . $width . '" style="text-align: ' . $align . '">' . do_shortcode( $content ) . '</div>';
74        }
75
76        function button_shortcode( $atts, $content ) {
77                $atts = shortcode_atts( array(
78                        'type'      => 'close',
79                        'link'      => '',
80                        'target'    => '_blank',
81                        'color'     => 'white',
82                        'bgcolor'   => 'mediumaquamarine',
83                        'size'      => 'normal',
84                        'fullwidth' => 'no',
85                ), $atts, 'buttonBox' );
86
87                $size      = 'is-' . $atts['size'];
88                $button    = '';
89                $fullwidth = ( $atts['fullwidth'] === 'yes' ) ? 'is-fullwidth' : '';
90                if ( $atts['type'] === 'close' ) {
91                        $button = '<button class="ds-button ds-close-popup ' . esc_attr( $size ) . ' ' . esc_attr( $fullwidth ) . '" style="color:' . esc_attr( $atts['color'] ) . '; background:' . esc_attr( $atts['bgcolor'] ) . '">' . esc_attr( $content ) . '</button>';
92                } elseif ( $atts['type'] === 'link' ) {
93                        $button = '<a href="' . esc_url( $atts['link'] ) . '" target="' . esc_attr( $atts['target'] ) . '" class="ds-button ' . esc_attr( $size ) . ' ' . esc_attr( $fullwidth ) . '" style="color:' . esc_attr( $atts['color'] ) . '; background:' . esc_attr( $atts['bgcolor'] ) . '">' . esc_attr( $content ) . '</a>';
94                }
95
96                return $button;
97        }
98
99        function video_shortcode( $atts ) {
100                $atts = shortcode_atts( array(
101                        'id'     => '',
102                        'from'   => 'youtube',
103                        'width'  => '560',
104                        'height' => '315',
105                ), $atts, 'videoBox' );
106
107                if ( empty( $atts['id'] ) ) {
108                        return false;
109                }
110
111                if ( $atts['from'] === 'youtube' ) {
112                        $url = 'https://www.youtube.com/embed/';
113                } elseif ( $atts['from'] === 'vimeo' ) {
114                        $url = 'https://player.vimeo.com/video/';
115                }
116
117                $video = '<iframe width="' . absint( $atts['width'] ) . '" height="' . absint( $atts['height'] ) . '" src="' . esc_url( $url ) . esc_attr( $atts['id'] ) . '" allow=autoplay frameborder="0" ></iframe>';
118
119                return $video;
120        }
121
122        function iframe_shortcode( $atts ) {
123                $atts = shortcode_atts( array(
124                        'link'   => '',
125                        'width'  => '560',
126                        'height' => '450',
127                        'id'     => '',
128                        'class'  => '',
129                        'style'  => '',
130                ), $atts, 'iframeBox' );
131
132                $extra = ! empty( $atts['id'] ) ? ' id="' . esc_attr( $atts['id'] ) . '"' : '';
133                $extra .= ! empty( $atts['class'] ) ? ' class="' . esc_attr( $atts['class'] ) . '"' : '';
134                $extra .= ! empty( $atts['style'] ) ? ' style="' . esc_attr( $atts['style'] ) . '"' : '';
135
136                $iframe = '<iframe width="' . absint( $atts['width'] ) . '" height="' . absint( $atts['height'] ) . '" src="' . esc_url( $atts['link'] ) . '"' . wp_kses_post($extra) . '></iframe>';
137
138                return $iframe;
139        }
140
141
142
143        function display() {
144                require plugin_dir_path( __FILE__ ) . 'display.php';
145        }
146
147
148        private function check_cookie( $param, $id ) {
149                $popupcookie = true;
150                if ( $param['use_cookies'] === 'yes' ) {
151                        $namecookie = 'wow-modal-id-' . $id;
152                        if ( ! isset( $_COOKIE[ $namecookie ] ) ) {
153                                $popupcookie = true;
154                        } else {
155                                $popupcookie = false;
156                        }
157                }
158                if ( $param['use_cookies'] === 'no' ) {
159                        $popupcookie = true;
160                }
161
162                return $popupcookie;
163        }
164
165
166
167        private function check( $param, $id ) {
168                $check   = true;
169                $cookie  = $this->check_cookie( $param, $id );
170
171                if ( empty($param['test_mode']) ) {
172                        if ( $cookie === false ) {
173                                $check = false;
174                        }
175
176                } else {
177                        if ( ! current_user_can( 'administrator' ) ) {
178                                $check = false;
179                        }
180                }
181
182                return $check;
183        }
184
185}
Note: See TracBrowser for help on using the repository browser.