| 1 |
<?php |
| 2 |
/* |
| 3 |
* Accessibility: Wordpress Accessibility Plugin |
| 4 |
* |
| 5 |
* Plugin Name: Accessibility |
| 6 |
* Description: Accessibility Utility Widget - A high quality solution for making your WordPress website accessible ready. |
| 7 |
* Version: 1.0.3 |
| 8 |
* Author: Octa Code |
| 9 |
* Author URI: http://octa-code.com |
| 10 |
* Plugin URI: http://acc.magixite.com |
| 11 |
* Copyright: 2015 Octa Code |
| 12 |
* Last Update: 10/18/2022 |
| 13 |
* |
| 14 |
* Text Domain: accessibility |
| 15 |
* Domain Path: /languages/ |
| 16 |
*/ |
| 17 |
|
| 18 |
if (!defined('ABSPATH')) { |
| 19 |
exit; // disable direct access |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
if (!class_exists('OcAccessibilityPlugin')) : |
| 24 |
|
| 25 |
/** |
| 26 |
* Register the plugin. |
| 27 |
* |
| 28 |
* Display the administration panel, insert JavaScript etc. |
| 29 |
*/ |
| 30 |
class OcAccessibilityPlugin { |
| 31 |
|
| 32 |
protected $loader; |
| 33 |
protected $version; |
| 34 |
protected $plugin_slug; |
| 35 |
|
| 36 |
private function __cleanInput($str) { |
| 37 |
// Using str_replace() function |
| 38 |
// to replace the word |
| 39 |
$res = str_replace( array( '\'', '"', |
| 40 |
',' , ';', '<', '>' ), ' ', $str); |
| 41 |
|
| 42 |
// Returning the result |
| 43 |
return $res; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Constructor |
| 48 |
*/ |
| 49 |
public function __construct() { |
| 50 |
$this->plugin_slug = 'accessibility'; |
| 51 |
load_plugin_textdomain($this->plugin_slug, false, basename(dirname(__FILE__)) . '/languages/'); |
| 52 |
$this->version = '1.0.0'; |
| 53 |
|
| 54 |
|
| 55 |
$this->define_constants(); |
| 56 |
$this->setup_actions(); |
| 57 |
$this->load_dependencies(); |
| 58 |
|
| 59 |
add_action('admin_menu', array($this, 'accessibility_create_menu')); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Hook WC Brands into WordPress |
| 64 |
*/ |
| 65 |
private function setup_actions() { |
| 66 |
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
| 67 |
add_action('admin_enqueue_scripts', array($this, 'enqueue_adminscripts')); |
| 68 |
add_action('wp_footer', array($this, 'magixite_script')); |
| 69 |
} |
| 70 |
|
| 71 |
public function magixite_script() { |
| 72 |
if (get_option('oc-accessibility-status', 0) < 1) { |
| 73 |
echo '<script type="text/javascript" src="' . OCACCESSIBILITY_PLUGINURL . '/freeCode?oatk=w0rdpre55"></script>'; |
| 74 |
} |
| 75 |
else { |
| 76 |
echo '<script type="text/javascript" src="' . OCACCESSIBILITY_PLUGINURL . '/license/lw?litk=' . get_option('oc-accessibility') . '"></script>'; |
| 77 |
} |
| 78 |
$language_setting = ""; |
| 79 |
if (get_option('oc-accessibility-language', "en_us") !== 'oc_system') { |
| 80 |
$language_setting = "'language': '" . get_option('oc-accessibility-language', "en_us") . "'"; |
| 81 |
} |
| 82 |
echo "<script type=\"text/javascript\">setTimeout(function(){octLoader({" . $language_setting . "})}, 1000);</script>"; |
| 83 |
} |
| 84 |
|
| 85 |
// Styles Handling |
| 86 |
public function enqueue_styles() { |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
public function enqueue_adminscripts() { |
| 91 |
wp_enqueue_style('admin-style', OCACCESSIBILITY_ASSETS_URL . '/css/admin-style.css', array(), OCACCESSIBILITY_VERSION); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Define Accessibilty constants |
| 96 |
*/ |
| 97 |
private function define_constants() { |
| 98 |
define('OCACCESSIBILITY_VERSION', $this->version); |
| 99 |
define('OCACCESSIBILITY_BASE_URL', trailingslashit(plugins_url('accessibility'))); |
| 100 |
define('OCACCESSIBILITY_ASSETS_URL', trailingslashit(OCACCESSIBILITY_BASE_URL . 'assets')); |
| 101 |
define('OCACCESSIBILITY_PATH', plugin_dir_path(__FILE__)); |
| 102 |
define('OCACCESSIBILITY_PLUGINURL', '//acc.magixite.com'); |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* WP Admin menu links. |
| 107 |
*/ |
| 108 |
public function accessibility_create_menu() { |
| 109 |
//create new top-level menu |
| 110 |
add_menu_page( |
| 111 |
__('Accessibility Settings', $this->plugin_slug), __('Accessibility', $this->plugin_slug), 'manage_options', 'oc-accessibility-admin', array($this, 'accessibility_settings_page'), 'dashicons-universal-access-alt' |
| 112 |
); |
| 113 |
add_submenu_page( |
| 114 |
'oc-accessibility-admin', __('Attachments alt', $this->plugin_slug), __('Attachments alt', $this->plugin_slug), 'manage_options', 'oc-accessibility-media', array($this, 'accessibility_admin_media_page'), 'dashicons-admin-media' |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* General Settings. |
| 120 |
*/ |
| 121 |
public function accessibility_settings_page() { |
| 122 |
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == "save_accessibility_settings") { |
| 123 |
$this->_admin_update_accessibility_settings(); |
| 124 |
} |
| 125 |
|
| 126 |
include("includes/accessibility-settings.php"); |
| 127 |
} |
| 128 |
/** |
| 129 |
* Attachments media handler. |
| 130 |
*/ |
| 131 |
public function accessibility_admin_media_page() { |
| 132 |
// update_post_meta($pid, '_wp_attachment_image_alt', $palt); |
| 133 |
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == "save_accessibility_attachments_settings") { |
| 134 |
$this->_admin_update_attachments(); |
| 135 |
} |
| 136 |
include("includes/accessibility-attachments-alt.php"); |
| 137 |
} |
| 138 |
|
| 139 |
private function load_dependencies() { |
| 140 |
require_once OCACCESSIBILITY_PATH . 'includes/class-accesibility-loader.php'; |
| 141 |
|
| 142 |
$this->loader = new OcAccessibility_Loader(); |
| 143 |
} |
| 144 |
|
| 145 |
public function run() { |
| 146 |
$this->loader->run(); |
| 147 |
} |
| 148 |
|
| 149 |
public function get_version() { |
| 150 |
return $this->version; |
| 151 |
} |
| 152 |
|
| 153 |
public function _admin_update_attachments() { |
| 154 |
$alt_data = $this->__cleanInput($_POST['attachments_alt']); |
| 155 |
$title_data = $this->__cleanInput($_POST['attachments_title']); |
| 156 |
foreach($alt_data as $pid => $p_alt) { |
| 157 |
update_post_meta($pid, '_wp_attachment_image_alt', $p_alt); |
| 158 |
} |
| 159 |
foreach($title_data as $pid => $p_title) { |
| 160 |
$post = array( |
| 161 |
'ID' => $pid, |
| 162 |
'post_title' => $p_title, |
| 163 |
); |
| 164 |
wp_update_post($post); |
| 165 |
} |
| 166 |
$class = "update-nag"; |
| 167 |
|
| 168 |
// Validate the license. |
| 169 |
$message = __("Saved Changes Successfully", $this->plugin_slug); |
| 170 |
$message_two = ""; |
| 171 |
echo "<div class=\"$class\"> <p>$message</p><p>$message_two</p></div>"; |
| 172 |
} |
| 173 |
|
| 174 |
public function get_language_options() { |
| 175 |
$languages = array(); |
| 176 |
|
| 177 |
$languages['auto_detect'] = (object) array('name' => 'Auto Detect'); |
| 178 |
$languages['he_il'] = (object) array('name' => 'Hebrew'); |
| 179 |
$languages['en_us'] = (object) array('name' => 'English'); |
| 180 |
$languages['es_es'] = (object) array('name' => 'Spanish'); |
| 181 |
$languages['ru_ru'] = (object) array('name' => 'Russian'); |
| 182 |
$languages['oc_system'] = (object) array('name' => '- From License'); |
| 183 |
|
| 184 |
return $languages; |
| 185 |
} |
| 186 |
|
| 187 |
private function _get_license_data($lkey) { |
| 188 |
if ($lkey == "") { |
| 189 |
return new stdClass(); |
| 190 |
} |
| 191 |
|
| 192 |
$jsonRsp = file_get_contents("http:" . OCACCESSIBILITY_PLUGINURL . "/license/v?litk=" . $lkey); |
| 193 |
|
| 194 |
$licenseData = json_decode($jsonRsp); |
| 195 |
return $licenseData; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Post form action for the update prices for brand. |
| 200 |
*/ |
| 201 |
function _admin_update_accessibility_settings() { |
| 202 |
$lkey = sanitize_text_field($_POST["magixite_license"]); |
| 203 |
update_option('oc-accessibility', $lkey); |
| 204 |
update_option('oc-accessibility-language', $_POST["ac_language"]); |
| 205 |
if ($lkey == '') { |
| 206 |
$status = 0; |
| 207 |
} |
| 208 |
else { |
| 209 |
$licenseData = $this->_get_license_data($lkey); |
| 210 |
if ($licenseData->status == 'Success') { |
| 211 |
$status = 1; |
| 212 |
} |
| 213 |
else { |
| 214 |
$status = -1; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
update_option('oc-accessibility-status', $status); |
| 219 |
$class = "update-nag"; |
| 220 |
|
| 221 |
// Validate the license. |
| 222 |
$message = __("Saved Settings Successfully", $this->plugin_slug); |
| 223 |
$message_two = ""; |
| 224 |
echo "<div class=\"$class\"> <p>$message</p><p>$message_two</p></div>"; |
| 225 |
} |
| 226 |
|
| 227 |
function _get_license_message($license_data) { |
| 228 |
if (!$license_data) { |
| 229 |
return "Get your <strong>free</strong> license <a href=\"https:" . OCACCESSIBILITY_PLUGINURL . "?wp-ref\" target=\"_blank\">here</a> to unlock more design options."; |
| 230 |
} |
| 231 |
if ($license_data->status == 'Failure') { |
| 232 |
return "<span style=\"color: red;\">License Did not validate</span>"; |
| 233 |
} |
| 234 |
if (isset($license_data->data->expiry)) { |
| 235 |
$daysLeft = (intval($license_data->data->expiry) - time()) / (3600 * 24); |
| 236 |
if ($daysLeft > 0) { |
| 237 |
return "Success! <strong>" . round($daysLeft) . "</strong> days for license renewal."; |
| 238 |
} |
| 239 |
else { |
| 240 |
return "Oh Oh! <strong> Your license has expired " . round($daysLeft * (-1)) . " days ago.</strong><br/>Please go ahead and renew."; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
return "Nothing to tell ya.."; |
| 245 |
} |
| 246 |
|
| 247 |
public function get_attachments($all = false) { |
| 248 |
global $wpdb; |
| 249 |
|
| 250 |
// $query_only_with_alt = "SELECT `wp`.`ID`, `wp`.`post_author`, `wp`.`post_date`, `wp`.`post_title`, `wp`.`post_name`, |
| 251 |
// `wp`.`guid`, `wp`.`post_parent`, `wpm`.`meta_key`, `wpm`.`meta_value` |
| 252 |
// FROM $wpdb->posts `wp` |
| 253 |
// LEFT JOIN $wpdb->postmeta `wpm` ON `wp`.`ID` = `wpm`.`post_id` |
| 254 |
// WHERE `wp`.`post_type` = 'attachment' AND `wpm`.`meta_key` = \"_wp_attachment_image_alt\" AND `wpm`.`meta_value` != ''"; |
| 255 |
|
| 256 |
$query_all_attachments = "SELECT `wp`.`ID`, `wp`.`post_author`, `wp`.`post_date`, `wp`.`post_title`, `wp`.`post_name`, |
| 257 |
`wp`.`guid`, `wp`.`post_parent`, `wpp`.`post_title` `parent_title` FROM $wpdb->posts `wp` " |
| 258 |
. " LEFT JOIN $wpdb->posts `wpp` ON `wp`.`post_parent` = `wpp`.`ID`" |
| 259 |
. " WHERE `wp`.`post_type` = 'attachment' ORDER BY `wp`.`ID` DESC"; |
| 260 |
|
| 261 |
$posts = $wpdb->get_results($query_all_attachments); |
| 262 |
|
| 263 |
return $posts; |
| 264 |
} |
| 265 |
|
| 266 |
} |
| 267 |
|
| 268 |
endif; |
| 269 |
|
| 270 |
function run_accessibility_plugin() { |
| 271 |
$plugin = new OcAccessibilityPlugin(); |
| 272 |
$plugin->run(); |
| 273 |
} |
| 274 |
|
| 275 |
run_accessibility_plugin(); |
| 276 |
|