| 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 wpcoder; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
class Wow_Admin_Class { |
| 19 |
|
| 20 |
private $arg; |
| 21 |
|
| 22 |
public function __construct( $arg ) { |
| 23 |
$this->plugin_name = $arg['plugin_name']; |
| 24 |
$this->plugin_menu = $arg['plugin_menu']; |
| 25 |
$this->plugin_home_url = $arg['plugin_home_url']; |
| 26 |
$this->plugin_version = $arg['plugin_version']; |
| 27 |
$this->plugin_file = $arg['plugin_file']; |
| 28 |
$this->plugin_slug = $arg['plugin_slug']; |
| 29 |
$this->plugin_dir = $arg['plugin_dir']; |
| 30 |
$this->plugin_url = $arg['plugin_url']; |
| 31 |
$this->plugin_pref = $arg['plugin_pref']; |
| 32 |
$this->author_url = $arg['author_url']; |
| 33 |
$this->pro_url = $arg['pro_url']; |
| 34 |
$this->shortcode = $arg['shortcode']; |
| 35 |
|
| 36 |
|
| 37 |
add_filter( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 ); |
| 38 |
add_action( 'admin_menu', array( $this, 'add_admin_page' ) ); |
| 39 |
add_filter( 'admin_footer_text', array( $this, 'rate_us' ) ); |
| 40 |
add_action( 'plugins_loaded', array( $this, 'plugin_check' ) ); |
| 41 |
add_action( 'wp_ajax_wp_coder_message', array( $this, 'wow_message_callback' ) ); |
| 42 |
|
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
public function add_admin_page() { |
| 47 |
$icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo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3ZnPgo='; |
| 48 |
|
| 49 |
if ( ! class_exists( 'Wow_Company' ) ) { |
| 50 |
add_menu_page( 'Wow Plugins', 'Wow Plugins', 'manage_options', 'wow-company', array( |
| 51 |
$this, |
| 52 |
'admin_main_page' |
| 53 |
), $icon ); |
| 54 |
add_submenu_page( 'wow-company', 'About Wow Plugins', 'About', 'manage_options', 'wow-company' ); |
| 55 |
add_submenu_page( 'wow-company', $this->plugin_name . ' version ' . $this->plugin_version, $this->plugin_menu, 'manage_options', $this->plugin_slug, array( |
| 56 |
$this, |
| 57 |
'plugin_page' |
| 58 |
) ); |
| 59 |
} else { |
| 60 |
add_submenu_page( 'wow-company', $this->plugin_name . ' version ' . $this->plugin_version, $this->plugin_menu, 'manage_options', $this->plugin_slug, array( |
| 61 |
$this, |
| 62 |
'plugin_page' |
| 63 |
) ); |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public function admin_main_page() { |
| 69 |
require_once plugin_dir_path( __FILE__ ) . 'general/main.php'; |
| 70 |
} |
| 71 |
|
| 72 |
public function plugin_page() { |
| 73 |
global $typenow; |
| 74 |
$typenow = $this->plugin_slug; |
| 75 |
require_once plugin_dir_path( __FILE__ ) . 'partials/main.php'; |
| 76 |
self:: admin_style_script(); |
| 77 |
} |
| 78 |
|
| 79 |
public function admin_style_script() { |
| 80 |
wp_enqueue_style( $this->plugin_slug . '-admin', $this->plugin_url . 'assets/css/admin.css', false, $this->plugin_version ); |
| 81 |
wp_enqueue_style( $this->plugin_slug . '-style', $this->plugin_url . 'assets/css/style.css', false, $this->plugin_version ); |
| 82 |
|
| 83 |
wp_enqueue_script( 'jquery-ui-tooltip' ); |
| 84 |
wp_enqueue_media(); |
| 85 |
wp_enqueue_script( 'code-editor' ); |
| 86 |
wp_enqueue_style( 'code-editor' ); |
| 87 |
wp_enqueue_script( 'htmlhint' ); |
| 88 |
wp_enqueue_script( 'csslint' ); |
| 89 |
wp_enqueue_script( 'jshint' ); |
| 90 |
|
| 91 |
wp_enqueue_script( $this->plugin_slug . '-script', $this->plugin_url . 'assets/js/script.js', array( 'jquery' ), $this->plugin_version ); |
| 92 |
wp_enqueue_script( $this->plugin_slug . '-codemirror', $this->plugin_url . 'assets/js/script-codemirror.js', array( 'code-editor' ), $this->plugin_version ); |
| 93 |
wp_enqueue_script( $this->plugin_slug . '-admin', $this->plugin_url . 'assets/js/admin.js', array( 'jquery' ), $this->plugin_version ); |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
public function action_links( $actions, $plugin_file ) { |
| 98 |
if ( false === strpos( $plugin_file, $this->plugin_file ) ) { |
| 99 |
return $actions; |
| 100 |
} |
| 101 |
$settings_link = '<a href="admin.php?page=' . $this->plugin_slug . '">' . __( 'Settings', $this->plugin_pref ) . '</a>'; |
| 102 |
array_unshift( $actions, $settings_link ); |
| 103 |
|
| 104 |
return $actions; |
| 105 |
} |
| 106 |
|
| 107 |
public function rate_us( $footer_text ) { |
| 108 |
global $typenow; |
| 109 |
if ( $typenow == $this->plugin_slug ) { |
| 110 |
$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 ), |
| 111 |
$this->plugin_home_url, |
| 112 |
$this->plugin_home_url . 'reviews/?rate=5#new-post' |
| 113 |
); |
| 114 |
|
| 115 |
return str_replace( '</span>', '', $footer_text ) . ' | ' . $rate_text . '</span>'; |
| 116 |
} else { |
| 117 |
return $footer_text; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
static function tooltip( $arg ) { |
| 122 |
$tooltip = ''; |
| 123 |
foreach ( $arg as $key => $value ) { |
| 124 |
if ( $key == 'title' ) { |
| 125 |
$tooltip .= $value . '<p/>'; |
| 126 |
} elseif ( $key == 'ul' ) { |
| 127 |
$tooltip .= '<ul>'; |
| 128 |
$arr = $value; |
| 129 |
foreach ( $arr as $val ) { |
| 130 |
$tooltip .= '<li>' . $val . '</li>'; |
| 131 |
} |
| 132 |
$tooltip .= '</ul>'; |
| 133 |
} else { |
| 134 |
$tooltip .= $value; |
| 135 |
} |
| 136 |
} |
| 137 |
$tooltip = "<span class='wow-help dashicons dashicons-editor-help' title='" . $tooltip . "'></span>"; |
| 138 |
|
| 139 |
return $tooltip; |
| 140 |
} |
| 141 |
|
| 142 |
static function option( $arg ) { |
| 143 |
$id = isset( $arg['id'] ) ? $arg['id'] : null; |
| 144 |
$name = isset( $arg['name'] ) ? $arg['name'] : ''; |
| 145 |
$type = isset( $arg['type'] ) ? $arg['type'] : ''; |
| 146 |
$func = ! empty( $arg['func'] ) ? ' onchange="' . $arg['func'] . '();"' : ''; |
| 147 |
$options = isset( $arg['option'] ) ? $arg['option'] : ''; |
| 148 |
$val = $arg['val']; |
| 149 |
$separator = isset( $arg['sep'] ) ? $arg['sep'] : ''; |
| 150 |
// create radio fields |
| 151 |
if ( $type == 'radio' ) { |
| 152 |
$option = ''; |
| 153 |
foreach ( $options as $key => $value ) { |
| 154 |
$select = ( $key == $val ) ? 'checked="checked"' : ''; |
| 155 |
$option .= '<input name="param[' . $name . ']" type="radio" value="' . $key . '" id="wow_' . $id . '_' . $key . '" ' . $select . $func . '><label for="wow_' . $id . '_' . $key . '"> ' . $value . '</label>' . $separator; |
| 156 |
} |
| 157 |
$field = $option; |
| 158 |
} // create checkbox field |
| 159 |
elseif ( $type == 'checkbox' ) { |
| 160 |
$select = ! empty( $val ) ? 'checked="checked"' : ''; |
| 161 |
$field = '<input type="checkbox" ' . $select . $func . ' id="wow_' . $id . '">' . $separator; |
| 162 |
$field .= '<input type="hidden" name="param[' . $name . ']" value="">'; |
| 163 |
} // create text field |
| 164 |
elseif ( $type == 'text' ) { |
| 165 |
$option = ''; |
| 166 |
if ( is_array( $options ) ) { |
| 167 |
foreach ( $options as $key => $value ) { |
| 168 |
$option .= ' ' . $key . '="' . $value . '"'; |
| 169 |
} |
| 170 |
} |
| 171 |
$field = '<input name="param[' . $name . ']" type="text" value="' . $val . '" id="wow_' . $id . '"' . $func . $option . '>' . $separator; |
| 172 |
} // create number field |
| 173 |
elseif ( $type == 'number' ) { |
| 174 |
$option = ''; |
| 175 |
if ( is_array( $options ) ) { |
| 176 |
foreach ( $options as $key => $value ) { |
| 177 |
$option .= ' ' . $key . '="' . $value . '"'; |
| 178 |
} |
| 179 |
} |
| 180 |
$field = '<input name="param[' . $name . ']" type="number" value="' . $val . '" id="wow_' . $id . '"' . $func . $option . '>' . $separator; |
| 181 |
} // create color field |
| 182 |
elseif ( $type == 'color' ) { |
| 183 |
$field = '<input name="param[' . $name . ']" type="text" value="' . $val . '" class="wp-color-picker-field" data-alpha="true" id="wow_' . $id . '">' . $separator; |
| 184 |
} // create select field |
| 185 |
elseif ( $type == 'select' ) { |
| 186 |
$option = ''; |
| 187 |
foreach ( $options as $key => $value ) { |
| 188 |
$select = ( $key == $val ) ? 'selected="selected"' : ''; |
| 189 |
$option .= '<option value="' . $key . '" ' . $select . '>' . $value . '</option>'; |
| 190 |
} |
| 191 |
$field = '<select name="param[' . $name . ']"' . $func . ' id="wow_' . $id . '">'; |
| 192 |
$field .= $option; |
| 193 |
$field .= '</select>' . $separator; |
| 194 |
} // create editor field |
| 195 |
elseif ( $type == 'editor' ) { |
| 196 |
$settings = array( |
| 197 |
'wpautop' => 0, |
| 198 |
'textarea_name' => 'param[' . $name . ']', |
| 199 |
'textarea_rows' => 15, |
| 200 |
); |
| 201 |
$field = wp_editor( $val, $id, $settings ); |
| 202 |
} // create textarea field |
| 203 |
elseif ( $type == 'textarea' ) { |
| 204 |
$field = '<textarea name="param[' . $name . ']" id="wow_' . $id . '">' . esc_html( $val ) . '</textarea>' . $separator; |
| 205 |
|
| 206 |
} |
| 207 |
|
| 208 |
return $field; |
| 209 |
} |
| 210 |
|
| 211 |
public function plugin_check() { |
| 212 |
if ( isset( $_POST[ $this->plugin_slug . '_nonce' ] ) ) { |
| 213 |
if ( ! empty( $_POST ) && wp_verify_nonce( $_POST[ $this->plugin_slug . '_nonce' ], $this->plugin_slug . '_action' ) && current_user_can( 'manage_options' ) ) { |
| 214 |
self:: save_data(); |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
public function save_data() { |
| 220 |
global $wpdb; |
| 221 |
$save_class = __NAMESPACE__ . '\\Wow_DB_Update'; |
| 222 |
$objItem = new $save_class( $this->plugin_dir, $this->plugin_slug ); |
| 223 |
$add = ( isset( $_REQUEST['add'] ) ) ? absint( $_REQUEST['add'] ) : ''; |
| 224 |
$data = ( isset( $_REQUEST['data'] ) ) ? sanitize_text_field( $_REQUEST['data'] ) : ''; |
| 225 |
$page = sanitize_text_field( $_REQUEST['page'] ); |
| 226 |
$tool_id = absint( $_POST['tool_id'] ); |
| 227 |
$info = array(); |
| 228 |
$info['id'] = $tool_id; |
| 229 |
$info['title'] = sanitize_text_field( $_POST['title'] ); |
| 230 |
$info['param'] = $_POST['param']; |
| 231 |
if ( isset( $_POST['submit'] ) ) { |
| 232 |
if ( absint( $_POST['add'] ) == '1' ) { |
| 233 |
$objItem->addNewItem( $data, $info ); |
| 234 |
header( 'Location:admin.php?page=' . $page . '&tab=add_new&act=update&id=' . $tool_id . '&info=saved' ); |
| 235 |
exit; |
| 236 |
} elseif ( absint( $_POST['add'] ) == '2' ) { |
| 237 |
$objItem->updItem( $data, $info ); |
| 238 |
header( 'Location:admin.php?page=' . $page . '&tab=add_new&act=update&id=' . $tool_id . '&info=update' ); |
| 239 |
exit; |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
public function wow_message_callback() { |
| 245 |
update_option( 'wp_coder_message', 'read' ); |
| 246 |
wp_die(); |
| 247 |
} |
| 248 |
} |