| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Class |
| 4 |
* |
| 5 |
* @package Wow_Plugin |
| 6 |
* @subpackage |
| 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 |
|
| 12 |
namespace float_menu_free; |
| 13 |
|
| 14 |
if ( !defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
class Wow_Admin_Class |
| 19 |
{ |
| 20 |
|
| 21 |
private $arg; |
| 22 |
|
| 23 |
public function __construct( $arg ) { |
| 24 |
$this->plugin_name = $arg[ 'plugin_name' ]; |
| 25 |
$this->plugin_menu = $arg[ 'plugin_menu' ]; |
| 26 |
$this->plugin_home_url = $arg[ 'plugin_home_url' ]; |
| 27 |
$this->plugin_version = $arg[ 'plugin_version' ]; |
| 28 |
$this->plugin_file = $arg[ 'plugin_file' ]; |
| 29 |
$this->plugin_slug = $arg[ 'plugin_slug' ]; |
| 30 |
$this->plugin_dir = $arg[ 'plugin_dir' ]; |
| 31 |
$this->plugin_url = $arg[ 'plugin_url' ]; |
| 32 |
$this->plugin_pref = $arg[ 'plugin_pref' ]; |
| 33 |
$this->author_url = $arg[ 'author_url' ]; |
| 34 |
$this->pro_url = $arg[ 'pro_url' ]; |
| 35 |
$this->shortcode = $arg[ 'shortcode' ]; |
| 36 |
$this->text_domain = $arg[ 'text_domain' ]; |
| 37 |
|
| 38 |
add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 ); |
| 39 |
add_action( 'admin_menu', array( $this, 'add_admin_page' ) ); |
| 40 |
add_filter( 'admin_footer_text', array( $this, 'rate_us' ) ); |
| 41 |
add_action( 'plugins_loaded', array( $this, 'plugin_check' ) ); |
| 42 |
|
| 43 |
if( get_option( 'wow_' . $this->plugin_pref . '_notice_action') != 'read') { |
| 44 |
add_action('admin_notices', array($this, 'general_admin_notice') ); |
| 45 |
add_action( 'admin_enqueue_scripts', array($this, 'admin_notice_assets') ); |
| 46 |
add_action( 'wp_ajax_float_menu_notice_action', array($this, 'wow_notice_action_callback' ) ); |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
static function tooltip( $arg ) { |
| 52 |
$tooltip = ''; |
| 53 |
foreach ( $arg as $key => $value ) { |
| 54 |
if ( $key == 'title' ) { |
| 55 |
$tooltip .= $value . '<p/>'; |
| 56 |
} elseif ( $key == 'ul' ) { |
| 57 |
$tooltip .= '<ul>'; |
| 58 |
$arr = $value; |
| 59 |
foreach ( $arr as $val ) { |
| 60 |
$tooltip .= '<li>' . $val . '</li>'; |
| 61 |
} |
| 62 |
$tooltip .= '</ul>'; |
| 63 |
} else { |
| 64 |
$tooltip .= $value; |
| 65 |
} |
| 66 |
} |
| 67 |
$tooltip = "<span class='wow-help dashicons dashicons-editor-help' title='" . $tooltip . "'></span>"; |
| 68 |
|
| 69 |
return $tooltip; |
| 70 |
} |
| 71 |
|
| 72 |
static function option( $arg ) { |
| 73 |
$id = isset( $arg[ 'id' ] ) ? $arg[ 'id' ] : null; |
| 74 |
$name = isset( $arg[ 'name' ] ) ? $arg[ 'name' ] : ''; |
| 75 |
$type = isset( $arg[ 'type' ] ) ? $arg[ 'type' ] : ''; |
| 76 |
$func = !empty( $arg[ 'func' ] ) ? ' onchange="' . $arg[ 'func' ] . '"' : ''; |
| 77 |
$options = isset( $arg[ 'option' ] ) ? $arg[ 'option' ] : ''; |
| 78 |
$val = $arg[ 'val' ]; |
| 79 |
$separator = isset( $arg[ 'sep' ] ) ? $arg[ 'sep' ] : ''; |
| 80 |
$class = isset( $arg[ 'class' ] ) ? ' class="' . $arg[ 'class' ] . '"' : ''; |
| 81 |
// create radio fields |
| 82 |
if ( $type == 'radio' ) { |
| 83 |
$disabled = isset( $arg[ 'disabled' ] ) ? ' disabled' : ''; |
| 84 |
$option = ''; |
| 85 |
foreach ( $options as $key => $value ) { |
| 86 |
$select = ($key == $val) ? 'checked="checked"' : ''; |
| 87 |
$option .= '<input name="' . $name . '" type="radio" value="' . $key . '" id="' . $id . '_' . $key . '" ' . $select . $func . $class . $disabled .'><label for="' . $id . '_' . $key . '"> ' . $value . '</label>' . $separator; |
| 88 |
} |
| 89 |
$field = $option; |
| 90 |
} // create checkbox field |
| 91 |
elseif ( $type == 'checkbox' ) { |
| 92 |
$disabled = isset( $arg[ 'disabled' ] ) ? ' disabled' : ''; |
| 93 |
$select = !empty( $val ) ? 'checked="checked"' : ''; |
| 94 |
$field = '<input type="checkbox" ' . $select . $func . $class . $disabled . ' id="' . $id . '" >' . $separator; |
| 95 |
$field .= '<input type="hidden" name="' . $name . '" value="">'; |
| 96 |
} // create text field |
| 97 |
elseif ( $type == 'text' || $type == 'number' || $type == 'hidden' ) { |
| 98 |
$option = ''; |
| 99 |
if ( is_array( $options ) ) { |
| 100 |
foreach ( $options as $key => $value ) { |
| 101 |
$option .= ' ' . $key . '="' . $value . '"'; |
| 102 |
} |
| 103 |
} |
| 104 |
$field = '<input name="' . $name . '" type="' . $type . '" value="' . $val . '" id="' . $id . '"' . $func . $option . $class . '>' . $separator; |
| 105 |
} // create color field |
| 106 |
elseif ( $type == 'color' ) { |
| 107 |
|
| 108 |
$field = '<input name="' . $name . '" type="text" value="' . $val . '" class="wp-color-picker-field" data-alpha="true" id="' . $id . '">' . $separator; |
| 109 |
} // create select field |
| 110 |
elseif ( $type == 'select' ) { |
| 111 |
$disabled = isset( $arg[ 'disabled' ] ) ? ' disabled' : ''; |
| 112 |
$option = ''; |
| 113 |
foreach ( $options as $key => $value ) { |
| 114 |
$select = ($key == $val) ? 'selected="selected"' : ''; |
| 115 |
$option .= '<option value="' . $key . '" ' . $select . '>' . $value . '</option>'; |
| 116 |
} |
| 117 |
$field = '<select name="' . $name . '"' . $func . $class . $disabled .' id="' . $id . '">'; |
| 118 |
$field .= $option; |
| 119 |
$field .= '</select>' . $separator; |
| 120 |
} // create editor field |
| 121 |
elseif ( $type == 'editor' ) { |
| 122 |
$settings = array( |
| 123 |
'wpautop' => 0, 'textarea_name' => '' . $name . '', 'textarea_rows' => 15, ); |
| 124 |
$field = wp_editor( $val, $id, $settings ); |
| 125 |
} // create textarea field |
| 126 |
elseif ( $type == 'textarea' ) { |
| 127 |
$field = '<textarea name="' . $name . '" id="' . $id . '">' . $val . '</textarea>' . $separator; |
| 128 |
} |
| 129 |
|
| 130 |
return $field; |
| 131 |
} |
| 132 |
|
| 133 |
public function add_admin_page() { |
| 134 |
$icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiIKICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAxL1JFQy1TVkctMjAwMTA5MDQvRFREL3N2ZzEwLmR0ZCI+CjxzdmcgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiB3aWR0aD0iNTEyLjAwMDAwMHB0IiBoZWlnaHQ9IjUxMi4wMDAwMDBwdCIgdmlld0JveD0iMCAwIDUxMi4wMDAwMDAgNTEyLjAwMDAwMCIKIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIG1lZXQiPgo8bWV0YWRhdGE+CkNyZWF0ZWQgYnkgcG90cmFjZSAxLjE1LCB3cml0dGVuIGJ5IFBldGVyIFNlbGluZ2VyIDIwMDEtMjAxNwo8L21ldGFkYXRhPgo8ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgwLjAwMDAwMCw1MTIuMDAwMDAwKSBzY2FsZSgwLjEwMDAwMCwtMC4xMDAwMDApIgpmaWxsPSIjMDAwMDAwIiBzdHJva2U9Im5vbmUiPgo8cGF0aCBkPSJNMjQ4MyA1MTAwIGMtNzEgLTQzIC02OCAtMTggLTcxIC01ODUgbC00IC01MTAgL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0yNTIgLTU3MCAtNTM1IC0xMSAtNjggLTE1IC0xNzEgLTE1IC00NDcKbDAgLTM1OSAyMTAgMCAyMTAgMCAwIDM2OCBjMCAzNjMgMCAzNjcgMjQgNDE3IDQxIDg5IDEyMiAxNDUgMjIzIDE1MyAxMTcgOQoyMTQgLTQxIDI2OCAtMTM5IGwzMCAtNTQgMyAtMzczIDMgLTM3MiAyMDQgMCAyMDUgMCAwIDM4OCBjMCA0MzQgLTIgNDQ5IC02OQo1ODcgLTg0IDE3MCAtMjQzIDI5NiAtNDQ2IDM1MSAtNjMgMTcgLTIxNSAyNSAtMjgwIDE1eiIvPgo8L2c+Cjwvc3ZnPgo='; |
| 135 |
|
| 136 |
add_submenu_page( 'wow-company', $this->plugin_name . ' version ' . $this->plugin_version, $this->plugin_menu, 'manage_options', $this->plugin_slug, array( |
| 137 |
$this, 'plugin_page' ) ); |
| 138 |
} |
| 139 |
|
| 140 |
public function plugin_page() { |
| 141 |
global $typenow; |
| 142 |
$typenow = $this->plugin_slug; |
| 143 |
require_once plugin_dir_path( __FILE__ ) . 'partials/main.php'; |
| 144 |
self:: admin_style_script(); |
| 145 |
} |
| 146 |
|
| 147 |
public function admin_style_script() { |
| 148 |
// wp_enqueue_style( $this->plugin_slug . '-admin', $this->plugin_url . 'assets/css/admin-style.min.css', false, $this->plugin_version ); |
| 149 |
wp_enqueue_style( $this->plugin_slug . '-admin', $this->plugin_url . 'assets/css/admin-style.css', false, $this->plugin_version ); |
| 150 |
|
| 151 |
wp_enqueue_style( 'wow-plugin-fontawesome', $this->plugin_url . 'assets/vendors/fontawesome/css/fontawesome-all.min.css', null, '5.6.3' ); |
| 152 |
// iconpicker |
| 153 |
wp_enqueue_script( 'wow-plugin-fonticonpicker', $this->plugin_url . 'assets/vendors/fonticonpicker/fonticonpicker.min.js', array( 'jquery' ) ); |
| 154 |
wp_enqueue_style( 'wow-plugin-fonticonpicker', $this->plugin_url . 'assets/vendors/fonticonpicker/css/fonticonpicker.min.css' ); |
| 155 |
wp_enqueue_style( 'wow-plugin-fonticonpicker-darkgrey', $this->plugin_url . 'assets/vendors/fonticonpicker/fonticonpicker.darkgrey.min.css' ); |
| 156 |
wp_enqueue_style( 'wp-color-picker' ); |
| 157 |
wp_enqueue_script( 'wp-color-picker' ); |
| 158 |
wp_enqueue_script( 'jquery-ui-tooltip' ); |
| 159 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 160 |
wp_enqueue_script( 'wp-color-picker-alpha', $this->plugin_url . 'assets/js/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ) ); |
| 161 |
// wp_enqueue_script( $this->plugin_slug . '-admin', $this->plugin_url . 'assets/js/admin-script.js', array( 'jquery' ), $this->plugin_version ); |
| 162 |
wp_enqueue_script( $this->plugin_slug . '-admin', $this->plugin_url . 'assets/js/admin-script.min.js', array( 'jquery' ), $this->plugin_version ); |
| 163 |
} |
| 164 |
|
| 165 |
public function action_links( $actions, $plugin_file ) { |
| 166 |
if ( false === strpos( $plugin_file, $this->plugin_file ) ) { |
| 167 |
return $actions; |
| 168 |
} |
| 169 |
$settings_link = '<a href="admin.php?page=' . $this->plugin_slug . '">' . __( 'Settings', $this->plugin_pref ) . '</a>'; |
| 170 |
array_unshift( $actions, $settings_link ); |
| 171 |
|
| 172 |
return $actions; |
| 173 |
} |
| 174 |
|
| 175 |
public function rate_us( $footer_text ) { |
| 176 |
global $typenow; |
| 177 |
if ( $typenow == $this->plugin_slug ) { |
| 178 |
$rate_text = sprintf( __( 'Thank you for using <a href="%1$s" target="_blank">' . $this->plugin_name . '</a>! Please <a href="%2$s" target="_blank">rate us on WordPress</a>', $this->plugin_pref ), $this->plugin_home_url, 'https://wordpress.org/support/plugin/float-menu/reviews/?filter=5' ); |
| 179 |
|
| 180 |
return str_replace( '</span>', '', $footer_text ) . ' | ' . $rate_text . '</span>'; |
| 181 |
} else { |
| 182 |
return $footer_text; |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
public function plugin_check() { |
| 188 |
if ( isset( $_POST[ $this->plugin_slug . '_nonce' ] ) ) { |
| 189 |
if ( !empty( $_POST ) && wp_verify_nonce( $_POST[ $this->plugin_slug . '_nonce' ], $this->plugin_slug . '_action' ) && current_user_can( 'manage_options' ) ) { |
| 190 |
self:: save_data(); |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
public function save_data() { |
| 196 |
global $wpdb; |
| 197 |
$save_class = __NAMESPACE__ . '\\Wow_DB_Update'; |
| 198 |
$objItem = new $save_class( $this->plugin_dir, $this->plugin_slug ); |
| 199 |
$add = (isset( $_REQUEST[ 'add' ] )) ? absint( $_REQUEST[ 'add' ] ) : ''; |
| 200 |
$data = (isset( $_REQUEST[ 'data' ] )) ? sanitize_text_field( $_REQUEST[ 'data' ] ) : ''; |
| 201 |
$page = sanitize_text_field( $_REQUEST[ 'page' ] ); |
| 202 |
$tool_id = absint( $_POST[ 'tool_id' ] ); |
| 203 |
$info = array(); |
| 204 |
$info[ 'id' ] = $tool_id; |
| 205 |
$info[ 'title' ] = sanitize_text_field( $_POST[ 'title' ] ); |
| 206 |
$info[ 'param' ] = $_POST[ 'param' ]; |
| 207 |
if ( isset( $_POST[ 'submit' ] ) ) { |
| 208 |
if ( absint( $_POST[ 'add' ] ) == '1' ) { |
| 209 |
$objItem->addNewItem( $data, $info ); |
| 210 |
header( 'Location:admin.php?page=' . $page . '&tab=add_new&act=update&id=' . $tool_id . '&info=saved' ); |
| 211 |
exit; |
| 212 |
} elseif ( absint( $_POST[ 'add' ] ) == '2' ) { |
| 213 |
$objItem->updItem( $data, $info ); |
| 214 |
header( 'Location:admin.php?page=' . $page . '&tab=add_new&act=update&id=' . $tool_id . '&info=update' ); |
| 215 |
exit; |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
public function delete_file ( $id = null) { |
| 221 |
$upload = wp_upload_dir(); |
| 222 |
$basedir = $upload['basedir'] . '/' . $this->plugin_slug . '/'; |
| 223 |
$file_style = $basedir . 'style-' . $id . '.css'; |
| 224 |
$file_script =$basedir . 'script-' . $id . '.js'; |
| 225 |
if (file_exists($file_style)) { |
| 226 |
wp_delete_file($file_style); |
| 227 |
} |
| 228 |
if (file_exists($file_script)) { |
| 229 |
wp_delete_file($file_script); |
| 230 |
} |
| 231 |
return; |
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
function general_admin_notice() { |
| 236 |
echo '<div class="notice notice-warning wow-plugin-notice is-dismissible"> |
| 237 |
<p><b>' . $this->plugin_name . '</b>! In connection with the upgrade of Font Awesome to version 5, we ask you to edit and update all previously created menus. <a href="' . admin_url() . 'admin.php?page=' . $this->plugin_slug . '">Go to the ' . $this->plugin_name . ' page</a></p> |
| 238 |
</div>'; |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
function admin_notice_assets() { |
| 243 |
wp_enqueue_script( 'wow-notice-update', $this->plugin_url . 'assets/js/notice-update.js', array( 'jquery' ), '1.0', true ); |
| 244 |
} |
| 245 |
|
| 246 |
function wow_notice_action_callback() { |
| 247 |
update_option( 'wow_' . $this->plugin_pref . '_notice_action', 'read' ); |
| 248 |
wp_die(); |
| 249 |
} |
| 250 |
|
| 251 |
function pro( $tooltip = null ){ |
| 252 |
$link = admin_url() . 'admin.php?page=' . $this->plugin_slug . '&tab=extension'; |
| 253 |
$title = __('More features in the PRO version', $this->text_domain ); |
| 254 |
$classes = 'wow-help dashicons dashicons-lock'; |
| 255 |
$tooltip = !empty( $tooltip ) ? $title . '<br/>' . $tooltip : $title; |
| 256 |
$pro = '<a href="' . $link . '" class="' . $classes . '" title="' . $tooltip . '"></a>'; |
| 257 |
return $pro; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
} |