| 1 |
<?php |
| 2 |
/* |
| 3 |
* Accessibility: Wordpress Accessibility Plugin |
| 4 |
* |
| 5 |
* Plugin Name: Accessibility |
| 6 |
* Description: Accessibility Utility |
| 7 |
* Version: 1.0.0 |
| 8 |
* Author: Octa Code |
| 9 |
* Author URI: http://magixite.com |
| 10 |
* Copyright: 2015 Octa Code |
| 11 |
* Last Update: 24/12/2015 |
| 12 |
* |
| 13 |
* Domain Path: /languages/ |
| 14 |
*/ |
| 15 |
|
| 16 |
if (!defined('ABSPATH')) { |
| 17 |
exit; // disable direct access |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
if (!class_exists('OcAccessibilityPlugin')) : |
| 22 |
|
| 23 |
/** |
| 24 |
* Register the plugin. |
| 25 |
* |
| 26 |
* Display the administration panel, insert JavaScript etc. |
| 27 |
*/ |
| 28 |
class OcAccessibilityPlugin { |
| 29 |
|
| 30 |
protected $loader; |
| 31 |
protected $version; |
| 32 |
protected $plugin_slug; |
| 33 |
|
| 34 |
/** |
| 35 |
* Constructor |
| 36 |
*/ |
| 37 |
public function __construct() { |
| 38 |
load_plugin_textdomain('accesibility', false, dirname(plugin_basename(__FILE__)) . '/languages'); |
| 39 |
$this->version = '1.0.0'; |
| 40 |
$this->plugin_slug = 'oc-accesibility'; |
| 41 |
|
| 42 |
$this->define_constants(); |
| 43 |
$this->setup_actions(); |
| 44 |
$this->load_dependencies(); |
| 45 |
|
| 46 |
add_action('admin_menu', array($this, 'accessibility_create_menu')); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Hook WC Brands into WordPress |
| 51 |
*/ |
| 52 |
private function setup_actions() { |
| 53 |
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
| 54 |
add_action('admin_enqueue_scripts', array($this, 'enqueue_adminscripts')); |
| 55 |
add_action('wp_footer', array($this, 'magixite_script')); |
| 56 |
} |
| 57 |
|
| 58 |
public function magixite_script() { |
| 59 |
if (get_option('oc-accessibility-status', 0) < 1) { |
| 60 |
echo '<script type="text/javascript" src="' . OCACCESSIBILITY_PLUGINURL . '/freeCode?oatk=w0rdpre55"></script>'; |
| 61 |
} |
| 62 |
else { |
| 63 |
echo '<script type="text/javascript" src="' . OCACCESSIBILITY_PLUGINURL . '/license/lw?litk=' . get_option('oc-accessibility') . '"></script>'; |
| 64 |
} |
| 65 |
$language_setting = ""; |
| 66 |
if (get_option('oc-accessibility-language', "en_us") !== 'oc_system') { |
| 67 |
$language_setting = "'language': '" . get_option('oc-accessibility-language', "en_us") . "'"; |
| 68 |
} |
| 69 |
echo "<script type=\"text/javascript\">setTimeout(function(){octLoader({".$language_setting."})}, 1000);</script>"; |
| 70 |
} |
| 71 |
|
| 72 |
// Styles Handling |
| 73 |
public function enqueue_styles() { |
| 74 |
} |
| 75 |
|
| 76 |
public function enqueue_adminscripts() { |
| 77 |
wp_enqueue_style('admin-style', OCACCESSIBILITY_ASSETS_URL . '/css/admin-style.css', array(), OCACCESSIBILITY_VERSION); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Define Accessibilty constants |
| 82 |
*/ |
| 83 |
private function define_constants() { |
| 84 |
define('OCACCESSIBILITY_VERSION', $this->version); |
| 85 |
define('OCACCESSIBILITY_BASE_URL', trailingslashit(plugins_url('accessibility'))); |
| 86 |
define('OCACCESSIBILITY_ASSETS_URL', trailingslashit(OCACCESSIBILITY_BASE_URL . 'assets')); |
| 87 |
define('OCACCESSIBILITY_PATH', plugin_dir_path(__FILE__)); |
| 88 |
define('OCACCESSIBILITY_PLUGINURL', '//acc.magixite.com'); |
| 89 |
} |
| 90 |
|
| 91 |
public function accessibility_create_menu() { |
| 92 |
//create new top-level menu |
| 93 |
add_menu_page('Accesibility Settings', 'Accesibility', 'manage_options', 'oc-accessibility-admin', array($this, 'accesibility_settings_page'), 'dashicons-universal-access-alt'); |
| 94 |
} |
| 95 |
|
| 96 |
public function accesibility_settings_page() { |
| 97 |
?> |
| 98 |
<div class="wrap"> |
| 99 |
<h2>Accessibility Options</h2> |
| 100 |
|
| 101 |
<?php if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == "save_accessibility_settings"): ?> |
| 102 |
<?php $this->_admin_update_accessibility_settings(); ?> |
| 103 |
<?php |
| 104 |
endif; |
| 105 |
$magixiteLicense = get_option('oc-accessibility', ""); |
| 106 |
$license_data = $this->_get_license_data($magixiteLicense); |
| 107 |
?> |
| 108 |
<form class="oc-accessibilty-form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> |
| 109 |
<h2>General Options</h2> |
| 110 |
<input type="hidden" name="action" value="save_accessibility_settings"> |
| 111 |
<a class="oc-accessibilty-tabletop" href="<?php echo OCACCESSIBILITY_PLUGINURL; ?>" alt="MagiXite" title="MagiXite"><img src="<?php echo OCACCESSIBILITY_ASSETS_URL; ?>/images/logo.png" /></a> |
| 112 |
<table class="form-table oc-accessibilty-style"> |
| 113 |
<tbody> |
| 114 |
<tr valign="top"> |
| 115 |
<th scope="row"><?php echo __('Magixite License'); ?></th> |
| 116 |
<td> |
| 117 |
<input type="text" name="magixite_license" placeholder="Paste your license key" value="<?php echo $magixiteLicense; ?>" /> |
| 118 |
<?php if ($magixiteLicense == ""): ?> |
| 119 |
<p> |
| 120 |
|
| 121 |
</p> |
| 122 |
<?php else: ?> |
| 123 |
<p><?php echo $this->_get_license_message($license_data); ?></p> |
| 124 |
<?php endif; ?> |
| 125 |
</td> |
| 126 |
</tr> |
| 127 |
|
| 128 |
<tr valign="top"> |
| 129 |
<th scope="row"><?php echo __('Select Preferred Language'); ?></th> |
| 130 |
<?php $language_options = $this->get_language_options(); ?> |
| 131 |
<td> |
| 132 |
<select name="ac_language"> |
| 133 |
<?php foreach ($language_options as $key => $l): ?> |
| 134 |
<option <?php if ($key == get_option('oc-accessibility-language', "")): echo "selected=\"selected\""; |
| 135 |
endif; |
| 136 |
?> value="<?php echo $key; ?>"><?php echo $l->name; ?></option> |
| 137 |
<?php endforeach; ?> |
| 138 |
</select> |
| 139 |
<p>* <strong>Auto Detect</strong> - Automatically choose language by user browser language setting.</p> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
|
| 143 |
<tr class="creditRow"><th colspan="2">Brought To You By <a href="<?php echo OCACCESSIBILITY_PLUGINURL; ?>" alt="MagiXite"><img src="<?php echo OCACCESSIBILITY_ASSETS_URL; ?>/images/text_logo.png" /></a></th></tr> |
| 144 |
</tbody> |
| 145 |
</table> |
| 146 |
<p class="submit"> |
| 147 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
| 148 |
</p> |
| 149 |
|
| 150 |
</form> |
| 151 |
</div> |
| 152 |
<?php |
| 153 |
} |
| 154 |
|
| 155 |
private function load_dependencies() { |
| 156 |
require_once OCACCESSIBILITY_PATH . 'includes/class-accesibility-loader.php'; |
| 157 |
|
| 158 |
$this->loader = new OcAcceibility_Loader(); |
| 159 |
} |
| 160 |
|
| 161 |
public function run() { |
| 162 |
$this->loader->run(); |
| 163 |
} |
| 164 |
|
| 165 |
public function get_version() { |
| 166 |
return $this->version; |
| 167 |
} |
| 168 |
|
| 169 |
public function get_language_options() { |
| 170 |
$languages = array(); |
| 171 |
|
| 172 |
$languages['auto_detect'] = (object) array('name' => 'Auto Detect'); |
| 173 |
$languages['he_il'] = (object) array('name' => 'Hebrew'); |
| 174 |
$languages['en_us'] = (object) array('name' => 'English'); |
| 175 |
$languages['ru_ru'] = (object) array('name' => 'Russian'); |
| 176 |
// $languages['custom'] = (object) array('name' => 'Custom'); |
| 177 |
|
| 178 |
return $languages; |
| 179 |
} |
| 180 |
|
| 181 |
private function _get_license_data($lkey) { |
| 182 |
if ($lkey == "") { |
| 183 |
return new stdClass(); |
| 184 |
} |
| 185 |
|
| 186 |
$jsonRsp = file_get_contents("http:" . OCACCESSIBILITY_PLUGINURL . "/license/v?litk=" . $lkey); |
| 187 |
|
| 188 |
$licenseData = json_decode($jsonRsp); |
| 189 |
return $licenseData; |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Post form action for the update prices for brand. |
| 194 |
*/ |
| 195 |
function _admin_update_accessibility_settings() { |
| 196 |
$lkey = sanitize_text_field($_POST["magixite_license"]); |
| 197 |
update_option('oc-accessibility', $lkey); |
| 198 |
update_option('oc-accessibility-language', $_POST["ac_language"]); |
| 199 |
if ($lkey == '') { |
| 200 |
$status = 0; |
| 201 |
} |
| 202 |
else { |
| 203 |
$licenseData = $this->_get_license_data($lkey); |
| 204 |
if ($licenseData->status == 'Success') { |
| 205 |
$status = 1; |
| 206 |
} |
| 207 |
else { |
| 208 |
$status = -1; |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
update_option('oc-accessibility-status', $status); |
| 213 |
$class = "update-nag"; |
| 214 |
|
| 215 |
// Validate the license. |
| 216 |
$message = "Saved Settings"; |
| 217 |
$message_two = ""; |
| 218 |
echo "<div class=\"$class\"> <p>$message</p><p>$message_two</p></div>"; |
| 219 |
} |
| 220 |
|
| 221 |
function _get_license_message($license_data) { |
| 222 |
if (!$license_data) { |
| 223 |
return "Get your <strong>free</strong> license <a href=\"https:" . OCACCESSIBILITY_PLUGINURL . "?wp-ref\" target=\"_blank\">here</a> to unlock more design options."; |
| 224 |
} |
| 225 |
if ($license_data->status == 'Failure') { |
| 226 |
return "<span style=\"color: red;\">License Did not validate</span>"; |
| 227 |
} |
| 228 |
if (isset($license_data->data->expiry)) { |
| 229 |
$daysLeft = (intval($license_data->data->expiry) - time()) / (3600 * 24); |
| 230 |
if ($daysLeft > 0) { |
| 231 |
return "Success! <strong>" . round($daysLeft) . "</strong> days for license renewal."; |
| 232 |
} |
| 233 |
else { |
| 234 |
return "Oh Oh! <strong> Your license has expired " . round($daysLeft * (-1)) . " days ago.</strong><br/>Please go ahead and renew."; |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
return "Nothing to tell ya.."; |
| 239 |
} |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
endif; |
| 244 |
|
| 245 |
function run_accessibility_plugin() { |
| 246 |
$plugin = new OcAccessibilityPlugin(); |
| 247 |
$plugin->run(); |
| 248 |
} |
| 249 |
|
| 250 |
run_accessibility_plugin(); |
| 251 |
|