PluginProbe
Float menu – awesome floating side menu / 6.1
Float menu – awesome floating side menu v6.1
7.2.5 trunk 2.1 2.2 3.0.1 3.1 3.2.2 3.3.1 3.5 3.5.1 3.5.2 3.5.3. 3.5.4 4.0 4.1 4.1.1 4.2 4.3 4.3.1 4.3.2 5.0 5.0.1 5.0.2 5.0.3 5.1 All 57 releases
float-menu / public / class-wowp-public.php

class-wowp-public.php in Float menu – awesome floating side menu 6.1, at public/class-wowp-public.php

185 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class WOWP_Public
5 *
6 * This class handles the public functionality of the Float Menu Pro plugin.
7 *
8 * @package FloatMenuLite
9 * @subpackage Public
10 * @author Dmytro Lobov <dev@wow-company.com>, Wow-Company
11 * @copyright 2024 Dmytro Lobov
12 * @license GPL-2.0+
13 */
14
15 namespace FloatMenuLite;
16
17 use FloatMenuLite\Admin\DBManager;
18 use FloatMenuLite\Publish\Conditions;
19 use FloatMenuLite\Publish\Display;
20
21 defined( 'ABSPATH' ) || exit;
22
23 class WOWP_Public {
24
25 private string $pefix;
26
27 public function __construct() {
28 $this->includes();
29 // prefix for plugin assets
30 $this->pefix = '.min';
31 add_shortcode( WOWP_Plugin::SHORTCODE, [ $this, 'shortcode' ] );
32 add_action( 'wp_footer', [ $this, 'footer' ] );
33 add_action( 'wp_enqueue_scripts', [ $this, 'assets' ] );
34 }
35
36 public function assets(): void {
37 $handle = WOWP_Plugin::SLUG;
38 $assets = plugin_dir_url( __FILE__ ) . 'assets/';
39 $version = WOWP_Plugin::info( 'version' );
40 $args = $this->check_display();
41 $url_fontawesome = WOWP_Plugin::url() . '/vendors/fontawesome/css/all.min.css';
42
43 if ( ! empty( $args ) ) {
44 wp_enqueue_style( $handle, $assets . 'css/style'.$this->pefix.'.css', [], $version, $media = 'all' );
45 wp_enqueue_script( $handle, $assets . 'js/floatMenu'.$this->pefix.'.js', array( 'jquery' ), $version, true );
46
47 foreach ( $args as $id => $param ) {
48 if ( empty( $param['fontawesome'] ) ) {
49 wp_enqueue_style( $handle . '-fontawesome', $url_fontawesome, null, '6.6' );
50 }
51
52 if ( empty( $param['velocity'] ) ) {
53 $url_velocity = $assets . 'js/velocity.min.js';
54 wp_enqueue_script( 'velocity', $url_velocity, array( 'jquery' ), $version, true );
55 }
56
57 $style = new Style_Maker( $id, $param );
58 $inline_style = $style->init();
59 wp_add_inline_style( $handle, $inline_style );
60
61 $script = new Script_Maker( $id, $param );
62 $inline_script = $script->init();
63 wp_add_inline_script( $handle, $inline_script, 'before' );
64
65 }
66
67 }
68
69 }
70
71
72
73 public function includes(): void {
74 require_once plugin_dir_path( __FILE__ ) . 'class-menu-maker.php';
75 require_once plugin_dir_path( __FILE__ ) . 'class-style-maker.php';
76 require_once plugin_dir_path( __FILE__ ) . 'class-script-maker.php';
77 }
78
79 public function shortcode( $atts ): string {
80
81 $atts = shortcode_atts(
82 [ 'id' => "", 'footer' => 'false' ],
83 $atts,
84 WOWP_Plugin::SHORTCODE
85 );
86
87 if ( empty( $atts['id'] ) ) {
88 return '';
89 }
90 $result = DBManager::get_data_by_id( $atts['id'] );
91
92 if ( empty( $result->param ) ) {
93 return '';
94 }
95
96 $conditions = Conditions::init( $result );
97 if ( $conditions === false ) {
98 return '';
99 }
100
101 $param = maybe_unserialize( $result->param );
102 $walker = new Menu_Maker( $atts['id'], $param );
103 $out = $walker->init();
104
105 if ( $atts['footer'] === 'false' ) {
106 $this->load_assets( $atts['id'], $param );
107 }
108
109
110 return $out;
111
112 }
113
114 public function load_assets( $id, $param ): void {
115
116 $handle = WOWP_Plugin::SLUG;
117 $assets = plugin_dir_url( __FILE__ ) . 'assets/';
118 $version = WOWP_Plugin::info( 'version' );
119 $url_fontawesome = WOWP_Plugin::url() . '/vendors/fontawesome/css/all.min.css';
120
121 if ( empty( $param['fontawesome'] ) ) {
122 wp_enqueue_style( $handle . '-fontawesome', $url_fontawesome, null, '6.6' );
123 }
124
125 $style = new Style_Maker( $id, $param );
126 $inline_style = $style->init();
127
128 if ( wp_style_is( $handle, 'enqueued' ) ) {
129 echo '<style type="text/css">' . esc_html( $inline_style ) . '</style>';
130 } else {
131 wp_enqueue_style( $handle, $assets . 'css/style'.$this->pefix.'.css', [], $version, $media = 'all' );
132 wp_add_inline_style( $handle, $inline_style );
133 }
134
135
136 if ( empty( $param['velocity'] ) ) {
137 $url_velocity = $assets . 'js/velocity.min.js';
138 wp_enqueue_script( 'velocity', $url_velocity, array( 'jquery' ), $version, true );
139 }
140
141 $url_script = $assets . 'js/floatMenu'.$this->pefix.'.js';
142 wp_enqueue_script( $handle, $url_script, array( 'jquery' ), $version, true );
143
144 $script = new Script_Maker( $id, $param );
145 $inline_script = $script->init();
146 wp_add_inline_script( $handle, $inline_script, 'before' );
147
148
149 }
150
151
152 public function footer(): void {
153
154 $args = $this->check_display();
155
156 if ( empty( $args ) ) {
157 return;
158 }
159 $shortcodes = '';
160 foreach ( $args as $id => $param ) {
161 $shortcodes .= '[' . WOWP_Plugin::SHORTCODE . ' id="' . absint( $id ) . '" footer="true"]';
162 }
163
164 echo do_shortcode( $shortcodes );
165 }
166
167 private function check_display(): array {
168 $args = [];
169 $results = DBManager::get_all_data();
170
171 if ( $results === false ) {
172 return $args;
173 }
174
175 foreach ( $results as $result ) {
176 $param = maybe_unserialize( $result->param );
177 if ( Display::init( $result->id, $param ) === true && Conditions::init( $result ) === true ) {
178 $args[ $result->id ] = $param;
179 }
180 }
181
182 return $args;
183 }
184
185 }