PluginProbe
Accessibility / 1.0.6
Accessibility v1.0.6
trunk 1.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
accessibility / accessibility.php

accessibility.php in Accessibility 1.0.6, at accessibility.php

326 lines 11.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.6
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/28/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
33 protected $loader;
34 protected $version;
35 protected $plugin_slug;
36
37 private function __cleanInput($str)
38 {
39 // Using str_replace() function
40 // to replace the word
41 $res = str_replace(
42 array( '\'', '"',
43 ',' , ';', '<', '>' ), ' ', $str
44 );
45
46 // Returning the result
47 return $res;
48 }
49
50 /**
51 * Constructor
52 */
53 public function __construct()
54 {
55 $this->plugin_slug = 'accessibility';
56 load_plugin_textdomain($this->plugin_slug, false, basename(dirname(__FILE__)) . '/languages/');
57 $this->version = '1.0.6';
58
59
60 $this->define_constants();
61 $this->setup_actions();
62 $this->load_dependencies();
63
64 add_action('admin_menu', array($this, 'accessibility_create_menu'));
65 }
66
67 /**
68 * Hook WC Brands into WordPress
69 */
70 private function setup_actions()
71 {
72 add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
73 add_action('wp_enqueue_scripts', array($this, 'enqueue_adminscripts'));
74 add_action('admin_enqueue_scripts', array($this, 'enqueue_adminscripts'));
75 add_action('wp_footer', array($this, 'magixite_script'));
76 }
77
78 public function magixite_script()
79 {
80 if (get_option('oc-accessibility-status', 0) < 1) {
81 $licenseUrl = OCACCESSIBILITY_PLUGINURL . '/freeCode?oatk=w0rdpre55';
82 }
83 else {
84 $licenseUrl = OCACCESSIBILITY_PLUGINURL . '/license/lw?litk=' . $this->__cleanInput(get_option('oc-accessibility'));
85 }
86 wp_enqueue_script(
87 'accessibility',
88 $licenseUrl,
89 array(),
90 $this->version,
91 true
92 );
93 $language_setting = "";
94 if (get_option('oc-accessibility-language', "en_us") !== 'oc_system') {
95 $language_setting = "'language': '" . get_option('oc-accessibility-language', "en_us") . "'";
96 }
97
98 wp_register_script('accessibility-init', '', [], '', true);
99 wp_enqueue_script('accessibility-init');
100 wp_add_inline_script('accessibility-init', "setTimeout(function(){octLoader({" . $language_setting . "})}, 1000);");
101 }
102
103 // Styles Handling
104 public function enqueue_styles()
105 {
106
107 }
108
109 public function enqueue_adminscripts()
110 {
111 wp_enqueue_style('admin-style', OCACCESSIBILITY_ASSETS_URL . '/css/admin-style.css', array(), OCACCESSIBILITY_VERSION);
112 }
113
114 /**
115 * Define Accessibility constants
116 */
117 private function define_constants()
118 {
119 define('OCACCESSIBILITY_VERSION', $this->version);
120 define('OCACCESSIBILITY_BASE_URL', trailingslashit(plugins_url('accessibility')));
121 define('OCACCESSIBILITY_ASSETS_URL', trailingslashit(OCACCESSIBILITY_BASE_URL . 'assets'));
122 define('OCACCESSIBILITY_PATH', plugin_dir_path(__FILE__));
123 define('OCACCESSIBILITY_PLUGINURL', '//acc.magixite.com');
124 }
125
126 /**
127 * WP Admin menu links.
128 */
129 public function accessibility_create_menu()
130 {
131 //create new top-level menu
132 add_menu_page(
133 __('Accessibility Settings', $this->plugin_slug), __('Accessibility', $this->plugin_slug), 'manage_options', 'oc-accessibility-admin', array($this, 'accessibility_settings_page'), 'dashicons-universal-access-alt'
134 );
135 add_submenu_page(
136 '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'
137 );
138 }
139
140 /**
141 * General Settings.
142 */
143 public function accessibility_settings_page()
144 {
145 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == "save_accessibility_settings") {
146 $this->_admin_update_accessibility_settings();
147 }
148
149 include "includes/accessibility-settings.php";
150 }
151 /**
152 * Attachments media handler.
153 */
154 public function accessibility_admin_media_page()
155 {
156 // update_post_meta($pid, '_wp_attachment_image_alt', $palt);
157 if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == "save_accessibility_attachments_settings") {
158 $this->_admin_update_attachments();
159 }
160 include "includes/accessibility-attachments-alt.php";
161 }
162
163 private function load_dependencies()
164 {
165 include_once OCACCESSIBILITY_PATH . 'includes/class-accessibility-loader.php';
166
167 $this->loader = new OcAccessibility_Loader();
168 }
169
170 public function run()
171 {
172 $this->loader->run();
173 }
174
175 public function get_version()
176 {
177 return $this->version;
178 }
179
180 public function _admin_update_attachments()
181 {
182 $alt_data = $this->__cleanInput($_POST['attachments_alt']);
183 $title_data = $this->__cleanInput($_POST['attachments_title']);
184 if ($alt_data == "" && $title_data == "") {
185 $message = __("Nothing Changed", $this->plugin_slug);
186 echo "<div class=\"".esc_attr($class)."\"> <p>".esc_html($message)."</p></div>";
187 return;
188 }
189 foreach($alt_data as $pid => $p_alt) {
190 update_post_meta($pid, '_wp_attachment_image_alt', $p_alt);
191 }
192 foreach($title_data as $pid => $p_title) {
193 $post = array(
194 'ID' => $pid,
195 'post_title' => $p_title,
196 );
197 wp_update_post($post);
198 }
199 $class = "update-nag";
200
201 // Validate the license.
202 $message = __("Saved Changes Successfully", $this->plugin_slug);
203 $message_two = "";
204 echo "<div class=\"".esc_attr($class)."\"> <p>".esc_html($message)."</p><p>".esc_html($message_two)."</p></div>";
205 }
206
207 public function get_language_options()
208 {
209 $languages = array();
210
211 $languages['auto_detect'] = (object) array('name' => 'Auto Detect');
212 $languages['he_il'] = (object) array('name' => 'Hebrew');
213 $languages['en_us'] = (object) array('name' => 'English');
214 $languages['es_es'] = (object) array('name' => 'Spanish');
215 $languages['ru_ru'] = (object) array('name' => 'Russian');
216 $languages['oc_system'] = (object) array('name' => '- From License');
217
218 return $languages;
219 }
220
221 private function _get_license_data($lkey)
222 {
223 if ($lkey == "") {
224 return new stdClass();
225 }
226
227 $siteSrc = urlencode(site_url());
228 $remoteGetOptions = array('sslverify' => false);
229 $rsp = wp_safe_remote_get("http:" . OCACCESSIBILITY_PLUGINURL . "/license/v?litk=" . $lkey . "&utm_source=" . $siteSrc, $remoteGetOptions);
230
231 $jsonRsp = wp_remote_retrieve_body($rsp);
232
233 $licenseData = json_decode($jsonRsp);
234 return $licenseData;
235 }
236
237 /**
238 * Post form action for the update prices for brand.
239 */
240 function _admin_update_accessibility_settings()
241 {
242 $lkey = sanitize_text_field($_POST["magixite_license"]);
243 update_option('oc-accessibility', $lkey);
244 update_option('oc-accessibility-language', sanitize_text_field($_POST["ac_language"]));
245 if ($lkey == '') {
246 $status = 0;
247 }
248 else {
249 $licenseData = $this->_get_license_data($lkey);
250 if ($licenseData->status == 'Success') {
251 $status = 1;
252 }
253 else {
254 $status = -1;
255 }
256 }
257
258 update_option('oc-accessibility-status', $status);
259 $class = "update-nag";
260
261 // Validate the license.
262 $message = __("Saved Settings Successfully", $this->plugin_slug);
263 $message_two = "";
264 echo "<div class=\"".esc_attr($class)."\"> <p>".esc_html($message)."</p><p>".esc_html($message_two)."</p></div>";
265 }
266
267 function _get_license_message($license_data)
268 {
269 if (!$license_data) {
270 $licenseObtainLink = 'https:' . OCACCESSIBILITY_PLUGINURL . '?wp-ref';
271 return "Get your <strong>free</strong> license <a href=\"".esc_attr($licenseObtainLink)."\" target=\"_blank\">here</a> to unlock more design options.";
272 }
273 if ($license_data->status == 'Failure') {
274 return "<span style=\"color: red;\">License Did not validate</span>";
275 }
276 if (isset($license_data->data->expiry)) {
277 $daysLeft = (intval($license_data->data->expiry) - time()) / (3600 * 24);
278 if ($daysLeft > 0) {
279 return "Success! <strong>" . esc_html(round($daysLeft)) . "</strong> days for license renewal.";
280 }
281 else {
282 return "Oh Oh! <strong> Your license has expired " . esc_html(round($daysLeft * (-1))) . " days ago.</strong><br/>Please go ahead and renew.";
283 }
284 }
285
286 return "Nothing to tell ya..";
287 }
288
289 public function get_attachments($all = false)
290 {
291 global $wpdb;
292
293 // $query_only_with_alt = "SELECT `wp`.`ID`, `wp`.`post_author`, `wp`.`post_date`, `wp`.`post_title`, `wp`.`post_name`,
294 // `wp`.`guid`, `wp`.`post_parent`, `wpm`.`meta_key`, `wpm`.`meta_value`
295 // FROM $wpdb->posts `wp`
296 // LEFT JOIN $wpdb->postmeta `wpm` ON `wp`.`ID` = `wpm`.`post_id`
297 // WHERE `wp`.`post_type` = 'attachment' AND `wpm`.`meta_key` = \"_wp_attachment_image_alt\" AND `wpm`.`meta_value` != ''";
298
299 $query_all_attachments = "SELECT `wp`.`ID`, `wp`.`post_author`, `wp`.`post_date`, `wp`.`post_title`, `wp`.`post_name`,
300 `wp`.`guid`, `wp`.`post_parent`, `wpp`.`post_title` `parent_title` FROM $wpdb->posts `wp` "
301 . " LEFT JOIN $wpdb->posts `wpp` ON `wp`.`post_parent` = `wpp`.`ID`"
302 . " WHERE `wp`.`post_type` = 'attachment' ORDER BY `wp`.`ID` DESC";
303
304 $posts = $wpdb->get_results($query_all_attachments);
305
306 return $posts;
307 }
308
309 }
310
311 endif;
312
313 /**
314 * Runs the main instance of OC_Accessibility to prevent the need to use globals.
315 *
316 * @since 1.0.0
317 * @return object OC_Accessibility
318 */
319 function Run_Accessibility_plugin()
320 {
321 $plugin = new OcAccessibilityPlugin();
322 $plugin->run();
323 }
324
325 Run_Accessibility_plugin();
326