class-wpchill-welcome.php
267 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! class_exists( 'WPChill_Welcome' ) ) { |
| 4 | |
| 5 | class WPChill_Welcome { |
| 6 | |
| 7 | /** |
| 8 | * Contains the instance of the Class |
| 9 | * |
| 10 | * @since 1.0.0 |
| 11 | * @param WPChill_Welcome $instance |
| 12 | */ |
| 13 | private static $instance = null; |
| 14 | |
| 15 | /** |
| 16 | * @since 1.0.0 |
| 17 | * @param string $textdomain - wpchill textdomain |
| 18 | */ |
| 19 | public $textdomain = 'wpchill'; |
| 20 | |
| 21 | private function __construct() { |
| 22 | add_action( 'admin_footer', array( $this, 'welcome_style' ) ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @since 1.0.0 |
| 27 | * Singleton |
| 28 | */ |
| 29 | public static function get_instance() { |
| 30 | |
| 31 | if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPChill_Welcome ) ) { |
| 32 | self::$instance = new WPChill_Welcome(); |
| 33 | } |
| 34 | |
| 35 | return self::$instance; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @since 1.0.0 |
| 40 | * Enqueue admin Wellcome style |
| 41 | */ |
| 42 | public function welcome_style() { |
| 43 | wp_enqueue_style( 'wpchill-welcome-style', plugins_url( '/assets/css/wpchill-welcome.css', __FILE__ ), null, '1.0.0' ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Display button function. |
| 48 | * |
| 49 | * @param string $text Button text. |
| 50 | * @param string $link Button URL. |
| 51 | * @param string $class Button class. |
| 52 | * @param bool $fill Show style. |
| 53 | * @param string $color Button color. |
| 54 | * @param string $text_color Text color. |
| 55 | * @param string $border_color Border color. |
| 56 | * |
| 57 | * @since 1.0.0 |
| 58 | */ |
| 59 | public function display_button( $text, $link, $class = 'button-primary', $fill = true, $color = '#5D3CE4', $text_color = '#fff', $border_color = '' ) { |
| 60 | $border_color = empty( $border_color ) ? $color : $border_color; |
| 61 | $style = 'style="border:1px solid;background-color:' . ( 'transparent' !== $color ? sanitize_hex_color( $color ) : 'transparent' ) . ';border-color:' . sanitize_hex_color( $border_color ) . ';color:' . sanitize_hex_color( $text_color ) . ';"'; |
| 62 | echo '<a href="' . esc_attr( $link ) . '" ' . ( $fill ? $style : '' ) . ' class="button ' . esc_attr( $class ) . '">' . esc_html( $text ) . '</a>'; |
| 63 | //wpmtst-btn wpmtst-btn-block wpmtst-btn-lg - former button classes |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @since 1.0.0 |
| 68 | * Renders extension html |
| 69 | * |
| 70 | * @param string $title |
| 71 | * |
| 72 | * @param string $description |
| 73 | * |
| 74 | * @param string $icon (icon URL) |
| 75 | * |
| 76 | * @param bool $pro |
| 77 | * @param string $link The URL to unlock the extension |
| 78 | */ |
| 79 | public function display_extension( $title, $description = '', $icon = '', $pro = false, $pro_color = '#5333ED', $extension_name = false ) { |
| 80 | |
| 81 | echo '<div class="feature-block">'; |
| 82 | echo '<div class="feature-block__header">'; |
| 83 | if ( '' != $icon ) { |
| 84 | echo '<img src="' . esc_attr( $icon ) . '">'; |
| 85 | } |
| 86 | echo '<h5>' . esc_html( $title ) . ( ( $pro ) ? '<div style="background-color:' . esc_attr( $pro_color ) . '" class="pro-label">PREMIUM</div>' : '' ) . '</h5>'; |
| 87 | echo '</div>'; |
| 88 | echo '<p>' . wp_kses_post( $description ) . '</p>'; |
| 89 | echo $extension_name ? '<a href="https://www.download-monitor.com/pricing/?utm_source=plugin&utm_medium=extension-block&utm_campaign=' . esc_attr( $extension_name ) . '">' . esc_html__( 'Upgrade to unlock', 'strong-testimonials' ) . '</a>' : ''; |
| 90 | echo '</div>'; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @since 1.0.0 |
| 95 | * Displays h1 heading |
| 96 | * |
| 97 | * @param string $text |
| 98 | * |
| 99 | * @param string $position |
| 100 | */ |
| 101 | public function display_heading( $text, $position = 'center' ) { |
| 102 | echo '<h1 style="text-align: ' . esc_attr( $position ) . ';" >' . esc_html( $text ) . '</h1>'; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @since 1.0.0 |
| 107 | * Displays h6 subheading |
| 108 | * |
| 109 | * @param string $text |
| 110 | * |
| 111 | * @param string $position |
| 112 | */ |
| 113 | public function display_subheading( $text, $position = 'center' ) { |
| 114 | echo '<h6 style="text-align: ' . esc_attr( $position ) . '" >' . esc_html( $text ) . '</h6>'; |
| 115 | } |
| 116 | |
| 117 | |
| 118 | /** |
| 119 | * @since 1.0.0 |
| 120 | * Renders testimonial block |
| 121 | * |
| 122 | * @param string $text |
| 123 | * |
| 124 | * @param string $icon |
| 125 | * |
| 126 | * @param string $name |
| 127 | * |
| 128 | * @param string $job (reviewer's job or company) |
| 129 | */ |
| 130 | public function display_testimonial( $text, $icon = '', $name = '', $job = '', $star_color = '' ) { |
| 131 | |
| 132 | echo '<div class="testimonial-block">'; |
| 133 | if ( '' != $icon ) { |
| 134 | echo '<img src=" ' . esc_url( $icon ) . ' "/>'; |
| 135 | } |
| 136 | echo '<p>' . esc_html( $text ) . '</p>'; |
| 137 | |
| 138 | $this->display_stars( $star_color ); |
| 139 | |
| 140 | if ( '' !== $name || '' !== $job ) { |
| 141 | echo '<p>'; |
| 142 | |
| 143 | if ( '' !== $name ) { |
| 144 | echo '<strong>' . esc_html( $name ) . '</strong><br/>'; |
| 145 | } |
| 146 | if ( '' !== $job ) { |
| 147 | echo esc_html( $job ); |
| 148 | } |
| 149 | echo '</p>'; |
| 150 | } |
| 151 | |
| 152 | echo '</div>'; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @since 1.0.0 |
| 157 | * Renders a UL list |
| 158 | * |
| 159 | * @param array $items - array of list items |
| 160 | */ |
| 161 | public function display_listing( $items ) { |
| 162 | echo '<ul>'; |
| 163 | |
| 164 | foreach ( $items as $item ) { |
| 165 | echo '<li>' . esc_html( $item ) . '</li>'; |
| 166 | } |
| 167 | |
| 168 | echo '</ul>'; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /** |
| 173 | * @since 1.0.0 |
| 174 | * Renders a UL list |
| 175 | * |
| 176 | * @param string $url - youtube.com url |
| 177 | */ |
| 178 | public function display_video( $url ) { |
| 179 | parse_str( wp_parse_url( esc_url( $url ), PHP_URL_QUERY ), $video_vars ); |
| 180 | echo '<div class="container"><iframe src="https://www.youtube.com/embed/' . esc_attr( $video_vars['v'] ) . '" frameborder="0" allowfullscreen class="video"></iframe></div>'; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @since 1.0.0 |
| 185 | * Renders rating stars block |
| 186 | * |
| 187 | * @param string $color - code of the star color fill |
| 188 | */ |
| 189 | public function display_stars( $color ) { |
| 190 | $color = ( '' === $color ) ? '#FFD700' : sanitize_hex_color( $color ); |
| 191 | $id = wp_rand( 0, 9999999 ); |
| 192 | $star = '<svg version="1.1" class="svg-' . absint( $id ) . '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="-274 399.8 53 43.1" style="enable-background:new -274 399.8 53 43.1;" xml:space="preserve"> |
| 193 | <g> |
| 194 | <path class="st0" d="M-234.8,415h-11.5l-3.6-11c-1.4-4.3-3.7-4.3-5.1,0l-3.6,11h-11.5c-4.5,0-5.3,2.2-1.6,4.8l9.3,6.8l-3.6,11 |
| 195 | c-1.4,4.3,0.4,5.7,4.1,3l9.3-6.8l9.3,6.8c3.7,2.7,5.5,1.3,4.1-3l-3.6-11l9.3-6.8C-229.6,417.1-230.3,415-234.8,415z"/> |
| 196 | </g> |
| 197 | </svg>'; |
| 198 | |
| 199 | $svg_args = array( |
| 200 | 'svg' => array( |
| 201 | 'class' => true, |
| 202 | 'aria-hidden' => true, |
| 203 | 'aria-labelledby' => true, |
| 204 | 'role' => true, |
| 205 | 'xmlns' => true, |
| 206 | 'width' => true, |
| 207 | 'height' => true, |
| 208 | 'viewbox' => true, // <= Must be lower case! |
| 209 | 'id' => true, |
| 210 | ), |
| 211 | 'g' => array( 'fill' => true ), |
| 212 | 'title' => array( 'title' => true ), |
| 213 | 'path' => array( |
| 214 | 'd' => true, |
| 215 | 'fill' => true, |
| 216 | ), |
| 217 | 'style' => array( 'type' => true ), |
| 218 | ); |
| 219 | |
| 220 | echo '<style>'; |
| 221 | echo '.svg-' . absint( $id ) . '{ fill:' . sanitize_hex_color( $color ) . ';}'; |
| 222 | echo '</style>'; |
| 223 | echo '<div class="stars_wrapper">' . wp_kses( $star . $star . $star . $star . $star, $svg_args ) . '</div>'; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * @since 1.0.0 |
| 228 | * Columns wrapper start |
| 229 | * |
| 230 | * @param int $cols - # of columns the contained objects should be displayed as. (1/2/3) |
| 231 | */ |
| 232 | public function layout_start( $cols = 2, $class = '' ) { |
| 233 | echo '<div class="' . esc_attr( $class ) . ' block-row block-row-' . absint( $cols ) . '">'; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * @since 1.0.0 |
| 238 | * Columns wrapper end |
| 239 | */ |
| 240 | public function layout_end() { |
| 241 | echo '</div>'; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * @since 1.0.0 |
| 246 | * Renders empty space block |
| 247 | * |
| 248 | * @param int $height - height(px) of space |
| 249 | */ |
| 250 | public function display_empty_space( $height = 25 ) { |
| 251 | |
| 252 | echo '<div class="wpchill_empty_space" style="height:' . esc_attr( $height ) . 'px;"></div>'; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Horizontal delimiter |
| 257 | * |
| 258 | * @return void |
| 259 | * @since 1.0.0 |
| 260 | */ |
| 261 | public function horizontal_delimiter() { |
| 262 | echo '<hr class="wpchill_horizontal_delimiter">'; |
| 263 | } |
| 264 | |
| 265 | } |
| 266 | } |
| 267 |