PluginProbe
EasyMega / 1.1.8
EasyMega v1.1.8
trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.9 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9
easymega / easymega.php

easymega.php in EasyMega 1.1.8, at easymega.php

285 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: EasyMega
4 Plugin URI: https://www.famethemes.com
5 Description: The EasyMega plugin helps you create mega menu easily, beautifully in any themes. Using the lightweight live Customizer system.
6 Author: famethemes
7 Author URI: https://www.famethemes.com
8 Version: 1.1.8
9 Text Domain: easymega
10 License: GPLv2 or later
11 License URI: http://www.gnu.org/licenses/gpl-2.0.html
12 */
13
14 if (! defined('ABSPATH')) exit; // Exit if accessed directly
15
16
17
18 if (! class_exists('EasyMega')) {
19 class EasyMega
20 {
21
22 function __construct()
23 {
24 include EASYMEGA_PATH . 'inc/admin.php';
25 include EASYMEGA_PATH . 'inc/class-mega-item.php';
26 include EASYMEGA_PATH . 'inc/menu.php';
27 include EASYMEGA_PATH . 'inc/settings.php';
28 include EASYMEGA_PATH . 'inc/theme-supports.php';
29
30 if (is_admin()) {
31 include EASYMEGA_PATH . 'inc/dashboard.php';
32 }
33 if (! is_admin()) {
34 add_action('wp_enqueue_scripts', array($this, 'scripts'), 3);
35 }
36
37 add_action('wp_ajax_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts'));
38 add_action('wp_ajax_nopriv_megamneu_wp_load_posts', array(__CLASS__, 'ajax_load_posts'));
39 add_filter('widget_text', 'do_shortcode');
40 }
41
42 static function get_theme_support($feature = null, $default = null)
43 {
44 $options = array(
45 'mobile_mod' => 0, // Break point when toggle mobile mod
46 'disable_auto_css' => 0, // Do not apply auto css
47 'disable_css' => 0, // Do not load plugin css
48 'parent_level' => 0, // Default parent Level
49 'content_right' => 0, // Content right
50 'content_left' => 0, // Content left
51 'margin_top' => 0, // Content left
52 'animation' => '', // Animation
53 'child_li' => '', // Use ul li for menu item children
54 'ul_css' => '', // Css of child mega `ul.mega-content` element
55 'li_css' => '', // Css of child mega `ul.mega-conten li.mega-content-li` element
56 );
57
58 $support = apply_filters('easymega_wp_get_theme_support_args', get_theme_support('easymega'));
59
60 if (is_array($support) && ! empty($support)) {
61 $sp = current($support);
62 if (! $feature) {
63 $sp = wp_parse_args($sp, $default);
64 return apply_filters('easymega_wp_get_theme_support', $sp, $feature, $sp);
65 }
66
67 if (is_array($sp)) {
68 if (isset($sp[$feature])) {
69 return apply_filters('easymega_wp_get_theme_support', $sp[$feature], $feature, $sp);
70 } else {
71 return apply_filters('easymega_wp_get_theme_support', false, $feature, $options);
72 }
73 }
74 }
75
76 if ($feature) {
77 return apply_filters('easymega_wp_get_theme_support', false, $feature, $options);
78 }
79 return apply_filters('easymega_wp_get_theme_support', wp_parse_args($default, $options), $feature, $options);
80 }
81
82 static function get_pro_url()
83 {
84 return apply_filters('megamenuwp-pro-url', 'https://www.famethemes.com/plugins/easymega-pro/');
85 }
86
87 function scripts()
88 {
89 $support = $this->get_theme_support();
90 if (! isset($support['disable_css']) || ! $support['disable_css']) {
91 $css_file = EASYMEGA_PATH . 'assets/css/style.css';
92 if (file_exists($css_file)) {
93 $v = filemtime($css_file);
94 wp_enqueue_style('easymega', EASYMEGA_URL . 'assets/css/style.css', false, $v);
95 }
96 }
97 $js_file = EASYMEGA_PATH . 'assets/js/easymega-wp.js';
98 $v = filemtime($js_file);
99 wp_enqueue_script('easymega', EASYMEGA_URL . 'assets/js/easymega-wp.js', array('jquery'), $v, true);
100
101 $args = array(
102 'ajax_url' => admin_url('admin-ajax.php'),
103 'loading_icon' => apply_filters('easymega_wp_loading_icon', '<div class="mega-spinner"><div class="uil-squares-css" style="transform:scale(0.4);"><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div></div></div>'),
104 'theme_support' => $support,
105 );
106
107 if (! $args['theme_support']['mobile_mod']) {
108 $args['theme_support']['mobile_mod'] = absint(get_theme_mod('mega_mobile_break_points', 720));
109 }
110
111 if (! isset($args['theme_support']['disable_auto_css']) || ! $args['theme_support']['disable_auto_css']) {
112 $args['theme_support']['disable_auto_css'] = absint(get_theme_mod('mega_disable_css', false));
113 }
114
115 if (isset($support['parent_level']) && $support['parent_level']) {
116 $args['mega_parent_level'] = absint($support['parent_level']);
117 } else {
118 $args['mega_parent_level'] = absint(get_theme_mod('mega_parent_level'));
119 }
120
121 if (isset($support['content_left']) && $support['content_left']) {
122 $args['mega_content_left'] = floatval($support['content_left']);
123 } else {
124 $args['mega_content_left'] = floatval(get_theme_mod('mega_content_left'));
125 }
126
127 if (isset($support['content_right']) && $support['content_right']) {
128 $args['mega_content_right'] = floatval($support['content_right']);
129 } else {
130 $args['mega_content_right'] = floatval(get_theme_mod('mega_content_right'));
131 }
132
133 $args['mega_content_right'] = floatval(get_theme_mod('mega_content_right'));
134
135 if (! isset($support['animation']) || ! $support['animation']) {
136 $args['animation'] = get_theme_mod('mega_animation');
137 if (! $args['animation']) { // shift-up, shift-down, shift-left, shift-right, fade, flip, animation-none
138 $args['animation'] = 'shift-up';
139 }
140 } else {
141 $args['animation'] = $support['animation'];
142 }
143
144 wp_localize_script('easymega', 'MegamenuWp', apply_filters('easymega_wp_localize_script_args', $args));
145
146 if ($support['margin_top']) {
147 $margin_top = $support['margin_top'];
148 } else {
149 $margin_top = get_theme_mod('mega_content_margin_top');
150 }
151
152 $margin_top = floatval($margin_top);
153 $css = '.easymega-wp-desktop #easymega-wp-page .easymega-wp .mega-item .mega-content li.mega-content-li { margin-top: ' . $margin_top . 'px; }';
154 if (isset($support['ul_css']) && $support['ul_css']) {
155 $css .= '.easymega-wp-desktop #easymega-wp-page .easymega-wp .mega-item .mega-content li.mega-content-li{ ' . $support['ul_css'] . ' }';
156 }
157
158 if (isset($support['li_css']) && $support['li_css']) {
159 $css .= '.easymega-wp-desktop .easymega-wp .mega-item .mega-content li.mega-content-li{ ' . $support['li_css'] . ' }';
160 }
161
162 if (isset($support['custom_css'])) {
163 $css .= $support['custom_css'];
164 }
165
166 wp_add_inline_style('easymega', $css);
167 }
168
169 static function get_template($template)
170 {
171 $template_folders = array(
172 get_stylesheet_directory() . '/', // Child theme
173 get_stylesheet_directory() . '/templates/', // child theme
174 get_template_directory() . '/', // Parent theme
175 get_template_directory() . '/templates/', // Parent theme
176 EASYMEGA_PATH . 'templates/', // Plugin
177 );
178
179
180
181 foreach ($template_folders as $folder) {
182 $file = $folder . $template;
183 if (file_exists($file)) {
184 return apply_filters('easymega_get_nav_template', $file, $template);
185 }
186 }
187
188 return apply_filters('easymega_get_nav_template', false, $template);
189 }
190
191 static function get_previewing_data($key, $default = null)
192 {
193 if (! isset($GLOBALS['_customized_decode']) || ! is_array($GLOBALS['_customized_decode'])) {
194 return $default;
195 }
196 if (is_array($key)) {
197 if (isset($GLOBALS['_customized_decode'][$key[0]]) && is_array($GLOBALS['_customized_decode'][$key[0]])) {
198 if ($GLOBALS['_customized_decode'][$key[0]][$key[1]]) {
199 return $GLOBALS['_customized_decode'][$key[0]][$key[1]];
200 }
201 }
202 } else {
203 if (isset($GLOBALS['_customized_decode'][$key])) {
204 return $GLOBALS['_customized_decode'][$key];
205 }
206 }
207
208 return $default;
209 }
210
211 static function is_mega_nav_active($nav_id)
212 {
213 if (isset($GLOBALS['_mega_menu_enable_' . $nav_id])) {
214 return $GLOBALS['_mega_menu_enable_' . $nav_id];
215 }
216
217 $key = 'nav_menu[' . $nav_id . ']';
218 if (self::is_preview(array($key, 'mega_enable'))) {
219 $mega_enable = self::get_previewing_data(array($key, 'mega_enable'));
220 } else {
221 $mega_enable = get_term_meta($nav_id, '_mega_enable', true);
222 }
223
224 $GLOBALS['_mega_menu_enable_' . $nav_id] = $mega_enable;
225 return $GLOBALS['_mega_menu_enable_' . $nav_id];
226 }
227
228 static function is_preview($key_check = false)
229 {
230 if (is_customize_preview()) {
231 if (isset($_POST['wp_customize']) && $_POST['wp_customize'] == 'on') { // phpcs:ignore WordPress.Security.NonceVerification.Missing
232 if (! isset($GLOBALS['easymega_customized_decode'])) {
233 if (isset($_POST['customized'])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
234 $GLOBALS['easymega_customized_decode'] = map_deep(json_decode(wp_unslash($_POST['customized']), true), 'wp_kses_post'); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
235 } else {
236 $GLOBALS['easymega_customized_decode'] = array();
237 }
238 }
239
240 if ($key_check) {
241 if (is_array($key_check)) {
242 if (isset($GLOBALS['easymega_customized_decode'][$key_check[0]])) {
243 return isset($GLOBALS['easymega_customized_decode'][$key_check[0]][$key_check[1]]);
244 }
245 } else {
246 return isset($GLOBALS['easymega_customized_decode'][$key_check]);
247 }
248 }
249 }
250 }
251 return false;
252 }
253
254 static function ajax_load_posts()
255 {
256 $args = EasyMega_Menu_Item::get_post_query_args($_REQUEST); // phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended
257 $content = EasyMega_Menu_Item::posts_content($args);
258 wp_send_json_success($content);
259 die();
260 }
261 }
262 }
263
264
265
266 function EasyMega__Init()
267 {
268 if (! defined('EASYMEGA_PATH')) {
269 define('EASYMEGA_URL', trailingslashit(plugins_url('', __FILE__)));
270 define('EASYMEGA_PATH', trailingslashit(dirname(__FILE__)));
271 $GLOBALS['EasyMega'] = new EasyMega();
272 }
273 }
274 add_action('init', 'EasyMega__Init', 35);
275
276
277 function easymega_activation_redirect($plugin)
278 {
279 if ($plugin == plugin_basename(__FILE__)) {
280 wp_redirect(admin_url('options-general.php?page=easymega'));
281 die();
282 }
283 }
284 add_action('activated_plugin', 'easymega_activation_redirect');
285