PluginProbe
Float menu – awesome floating side menu / 3.5
Float menu – awesome floating side menu v3.5
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 / admin / class-admin.php

class-admin.php in Float menu – awesome floating side menu 3.5, at admin/class-admin.php

361 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Admin Class
5 *
6 * @package Wow_Plugin
7 * @subpackage Admin
8 * @author Dmytro Lobov <d@dayes.dev>
9 * @copyright 2019 Wow-Company
10 * @license GNU Public License
11 * @version 1.0
12 */
13
14 namespace float_menu_free;
15
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Class Wow_Plugin_Admin
23 *
24 * @package wow_plugin
25 *
26 * @property array plugin - base information about the plugin
27 * @property array url - home, pro and other URL for plugin
28 * @property array rating - website and link for rating
29 *
30 */
31 class Wow_Plugin_Admin {
32
33 /**
34 * Setup to admin panel of the plugin
35 *
36 * @param array $info general information about the plugin
37 *
38 * @since 1.0
39 */
40 public function __construct( $info ) {
41 $this->plugin = $info['plugin'];
42 $this->url = $info['url'];
43 $this->rating = $info['rating'];
44
45 add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 );
46 add_action( 'admin_menu', array( $this, 'add_admin_page' ) );
47 add_filter( 'admin_footer_text', array( $this, 'rate_us' ) );
48 // add_action( 'plugins_loaded', array( $this, 'plugin_check' ) );
49 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); // add admin script
50
51 add_action( 'wp_ajax_' . $this->plugin['prefix'] . '_item_save', array( $this, 'item_save' ) );
52
53 }
54
55 /**
56 * @param string|array $arg text which need show in the tooltip
57 *
58 * @return string tooltip for the element
59 */
60 static function tooltip( $arg ) {
61 $tooltip = '';
62 foreach ( $arg as $key => $value ) {
63 if ( $key == 'title' ) {
64 $tooltip .= $value . '<p/>';
65 } elseif ( $key == 'ul' ) {
66 $tooltip .= '<ul>';
67 $arr = $value;
68 foreach ( $arr as $val ) {
69 $tooltip .= '<li>' . $val . '</li>';
70 }
71 $tooltip .= '</ul>';
72 } else {
73 $tooltip .= $value;
74 }
75 }
76 $tooltip = "<span class='wow-help dashicons dashicons-editor-help' title='" . $tooltip . "'></span>";
77
78 return $tooltip;
79 }
80
81 /**
82 * @param array $arg parameters for creating field in the backend
83 *
84 * @return string field for displaying
85 */
86 static function option( $arg ) {
87 $id = isset( $arg['id'] ) ? $arg['id'] : null;
88 $name = isset( $arg['name'] ) ? $arg['name'] : '';
89 $type = isset( $arg['type'] ) ? $arg['type'] : '';
90 $func = ! empty( $arg['func'] ) ? ' onchange="' . $arg['func'] . '"' : '';
91 $options = isset( $arg['option'] ) ? $arg['option'] : '';
92 $val = $arg['val'];
93 $separator = isset( $arg['sep'] ) ? $arg['sep'] : '';
94 $class = isset( $arg['class'] ) ? ' class="' . $arg['class'] . '"' : '';
95 $field = '';
96
97 if ( $type == 'radio' ) {
98 // create radio fields
99 $option = '';
100 foreach ( $options as $key => $value ) {
101 $select = ( $key == $val ) ? ' checked="checked"' : '';
102 $option .= '<input name="' . $name . '" type="radio" value="' . $key . '" id="' . $id . '_' . $key . '" ' . $select . $func . $class . '><label for="' . $id . '_' . $key . '"> ' . $value
103 . '</label>' . $separator;
104 }
105 $field = $option;
106 } elseif ( $type == 'checkbox' ) {
107 // create checkbox field
108 $select = ! empty( $val ) ? ' checked="checked"' : '';
109 $id = ( $id === null ) ? '' : ' id="' . $id . '"';
110 $field = '<input type="checkbox" ' . $id . $select . $func . $class . '>' . $separator;
111 $field .= '<input type="hidden" name="' . $name . '" value="">';
112 } elseif ( $type == 'text' || $type == 'number' || $type == 'hidden' ) {
113 // create text field
114 $option = '';
115 if ( is_array( $options ) ) {
116 foreach ( $options as $key => $value ) {
117 $option .= ' ' . $key . '="' . $value . '"';
118 }
119 }
120 $id = ( $id === null ) ? '' : ' id="' . $id . '"';
121 $field
122 = '<input name="' . $name . '" type="' . $type . '" value="' . $val . '"' . $id . $func
123 . $option . $class . '>' . $separator;
124 } elseif ( $type == 'color' ) {
125 // create color field
126 $id = ( $id === null ) ? '' : ' id="' . $id . '"';
127 $field = '<input name="' . $name . '" type="text" value="' . $val
128 . '" class="wp-color-picker-field" data-alpha="true"' . $id . '>' . $separator;
129 } // create select field
130 elseif ( $type == 'select' ) {
131 $disabled = isset( $arg['disabled'] ) ? ' disabled' : '';
132 $readonly = isset( $arg['readonly'] ) ? ' readonly' : '';
133 $option = '';
134 foreach ( $options as $key => $value ) {
135 if ( strrpos( $key, '_start' ) != false ) {
136 $option .= '<optgroup label="' . $value . '">';
137 } elseif ( strrpos( $key, '_end' ) != false ) {
138 $option .= '</optgroup>';
139 } else {
140 $select = ( $key == $val ) ? 'selected="selected"' : '';
141 $option .= '<option value="' . $key . '" ' . $select . '>' . $value . '</option>';
142 }
143 }
144 $id = ( $id === null ) ? '' : ' id="' . $id . '"';
145 $field = '<select name="' . $name . '"' . $func . $class . $disabled . $readonly . $id . '>';
146 $field .= $option;
147 $field .= '</select>' . $separator;
148 } elseif ( $type == 'editor' ) {
149 // create editor field
150 $settings = array(
151 'wpautop' => 0,
152 'textarea_name' => '' . $name . '',
153 'textarea_rows' => 15,
154 );
155 $field = wp_editor( $val, $id, $settings );
156 } elseif ( $type == 'textarea' ) {
157 // create textarea field
158 $id = ( $id === null ) ? '' : ' id="' . $id . '"';
159 $field = '<textarea name="' . $name . '"' . $id . '>' . $val . '</textarea>' . $separator;
160 }
161
162 return $field;
163 }
164
165 /**
166 * @param string $tooltip tooltip for element
167 *
168 * @return string
169 */
170 public function pro( $tooltip = null ) {
171 $link = admin_url() . 'admin.php?page=' . $this->plugin['slug'] . '&tab=extension';
172 $title = esc_attr__( 'More features in the PRO version', $this->plugin['text'] );
173 $classes = 'wow-help dashicons dashicons-lock';
174 $tooltip = ! empty( $tooltip ) ? $title . '<br/>' . $tooltip : $title;
175 $pro = '<a href="' . $link . '" class="' . $classes . '" title="' . $tooltip . '"></a>';
176
177 return $pro;
178 }
179
180 /**
181 * Add the plugin page in admin menu
182 *
183 * @since 1.0
184 */
185 public function add_admin_page() {
186 $parent = 'wow-company';
187 $title = $this->plugin['name'] . ' version ' . $this->plugin['version'];
188 $menu_title = $this->plugin['menu'];
189 $capability = 'manage_options';
190 $slug = $this->plugin['slug'];
191 $function = array( $this, 'plugin_page' );
192 add_submenu_page( $parent, $title, $menu_title, $capability, $slug, $function );
193 }
194
195 /**
196 * Include main plugin page with Style and Script
197 *
198 * @since 1.0
199 */
200 public function plugin_page() {
201 global $wow_plugin_page;
202 $wow_plugin_page = $this->plugin['slug'];
203 require_once 'partials/main.php';
204 }
205
206 /**
207 * Include Styles and Scripts on the plugin admin page
208 *
209 * @since 1.0
210 */
211 public function admin_scripts( $hook ) {
212 $page = 'wow-plugins_page_' . $this->plugin['slug'];
213
214 if ( $page != $hook ) {
215 return false;
216 }
217
218 $slug = $this->plugin['slug'];
219 $version = $this->plugin['version'];
220 $url_assets = $this->plugin['url'] . 'assets/';
221 $pre_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
222
223 // include the main style
224 wp_enqueue_style( $slug . '-admin', $url_assets . 'css/admin-style' . $pre_suffix . '.css', false, $version );
225
226 // include fontAwesome icon
227 $url_fontawesome = $url_assets . 'vendors/fontawesome/css/fontawesome-all' . $pre_suffix . '.css';
228 wp_enqueue_style( $slug . '-fontawesome', $url_fontawesome, null, '5.14' );
229
230 // include fonticonpicker styles & scripts
231 $fonticonpicker_js = $url_assets . 'vendors/fonticonpicker/fonticonpicker.min.js';
232 wp_enqueue_script( $slug . '-fonticonpicker', $fonticonpicker_js, array( 'jquery' ) );
233
234 $fonticonpicker_css = $url_assets . 'vendors/fonticonpicker/css/fonticonpicker.min.css';
235 wp_enqueue_style( $slug . '-fonticonpicker', $fonticonpicker_css );
236
237 $fonticonpicker_dark_css = $url_assets . 'vendors/fonticonpicker/fonticonpicker.darkgrey.min.css';
238 wp_enqueue_style( $slug . '-fonticonpicker-darkgrey', $fonticonpicker_dark_css );
239
240 // include the color picker
241 wp_enqueue_style( 'wp-color-picker' );
242 wp_enqueue_script( 'wp-color-picker' );
243 $color_picker = $url_assets . 'js/wp-color-picker-alpha' . $pre_suffix . '.js';
244
245 wp_enqueue_script( $slug . '-alpha', $color_picker, array( 'wp-color-picker' ) );
246
247 // include tooltip script
248 wp_enqueue_script( 'jquery-ui-tooltip' );
249 wp_enqueue_script( 'jquery-ui-sortable' );
250
251 // include the plugin admin script
252 $url_script = $url_assets . 'js/admin-script' . $pre_suffix . '.js';
253 wp_enqueue_script( $slug . '-admin', $url_script, array( 'jquery' ), $version );
254
255
256 }
257
258 /**
259 * Add the link to the plugin page on Plugins page
260 *
261 * @param $actions
262 * @param $plugin_file - the plugin main file
263 *
264 * @return mixed
265 */
266 public function action_links( $actions, $plugin_file ) {
267 if ( false === strpos( $plugin_file, plugin_basename( $this->plugin['file'] ) ) ) {
268 return $actions;
269 }
270 $settings_link
271 = '<a href="admin.php?page=' . $this->plugin['slug'] . '">' . esc_attr__( 'Settings',
272 $this->plugin['text'] ) . '</a>';
273 array_unshift( $actions, $settings_link );
274
275 return $actions;
276 }
277
278 /**
279 * Add custom text in the footer on the wow plugin page
280 *
281 * @param $footer_text - text in the footer
282 *
283 * @return string - end text in the footer
284 * @since 1.0
285 */
286 public function rate_us( $footer_text ) {
287 global $wow_plugin_page;
288 if ( $wow_plugin_page == $this->plugin['slug'] ) {
289 $rate_text = sprintf( __( 'Thank you for using <a href="%1$s" target="_blank">' . $this->plugin['name']
290 . '</a>! Please <a href="%2$s" target="_blank">rate us on '
291 . $this->rating['website'] . '</a>', $this->plugin['text'] ), $this->url['home'],
292 $this->rating['url'] );
293
294 return str_replace( '</span>', '', $footer_text ) . ' | ' . $rate_text . '</span>';
295 } else {
296 return $footer_text;
297 }
298 }
299
300 function item_save() {
301
302 $response = 'No';
303 if ( isset( $_POST[ $this->plugin['slug'] . '_nonce' ] ) ) {
304 if ( ! empty( $_POST )
305 && wp_verify_nonce( $_POST[ $this->plugin['slug'] . '_nonce' ], $this->plugin['slug'] . '_action' )
306 && current_user_can( 'manage_options' )
307 ) {
308 $response = self:: save_data();
309 }
310 }
311
312 wp_send_json( $response );
313
314 wp_die();
315
316 }
317
318 /**
319 * Save and Update the Item into the plugin Database
320 *
321 * @return array response from DB
322 *
323 * @since 1.0
324 */
325 public function save_data() {
326 global $wpdb;
327 $add = ( isset( $_REQUEST['add'] ) ) ? absint( $_REQUEST['add'] ) : '';
328 $table = $wpdb->prefix . 'wow_' . $this->plugin['prefix'];
329 $id = absint( $_POST['tool_id'] );
330 $data = array(
331 'title' => sanitize_text_field( $_POST['title'] ),
332 'param' => serialize( $_POST['param'] ),
333 );
334
335 $response = array(
336 'status' => 'NO',
337 'message' => esc_attr__( 'Something went wrong. Contact the plugin developer', $this->plugin['text'] ),
338 );
339 if ( 1 === $add ) {
340 $insert = $wpdb->insert( $table, $data, [ '%d', '%s', '%s' ] );
341 if ( $insert ) {
342 $response = array(
343 'status' => 'OK',
344 'message' => esc_attr__( 'Item Added', $this->plugin['text'] ),
345 );
346 }
347
348 } elseif ( 2 === $add ) {
349 $update = $wpdb->update( $table, $data, [ 'id' => $id ], [ '%s', '%s' ], [ '%d' ] );
350 if ( ! empty( $update ) ) {
351 $response = array(
352 'status' => 'OK',
353 'message' => esc_attr__( 'Item Updated', $this->plugin['text'] ),
354 );
355 }
356 }
357
358 return $response;
359 }
360 }
361