/
talandewebb.php
234 lines (174 loc) · 5.38 KB
/
talandewebb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/*
* Plugin Name: Talande Webb
* Plugin URI: https://github.com/johnie/talandewebb
* Description: WordPress plugin for FunkaNU screen reader application Talande Webb
* Version: 1.0.0
* Author: Johnie Hjelm
* Author URI: http://johnie.se
* License: GPL2
*/
/*
Copyright 2015 Johnie Hjelm <johniehjelm@me.com> (http://johnie.se)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Require API
require_once(__DIR__ . '/inc/api.php');
if ( ! class_exists( 'TalandeWebb' ) ) {
class TalandeWebb {
private static $instance;
/**
* Tag identifier used by file includes and selector attributes.
* @var string
*/
public $tag;
/**
* User friendly name used to identify the plugin.
* @var string
*/
public $name;
/**
* Current version of the plugin.
* @var string
*/
public $version;
/**
* Languages codes.
* @var array
*/
public $languages;
/**
* The default language.
* @var string
*/
protected $defaultLanguage;
/**
* Talandewebb loader instance.
*
* @since 1.2.1
*
* @return object
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new static;
self::$instance->setup_globals();
self::$instance->setup_actions();
}
return self::$instance;
}
/**
* Add plugin settings menu
* @access public
*/
function _tw_settings_menu() {
add_options_page( __( $this->name, $this->tag ), __( $this->name, $this->tag ), 'manage_options', 'tw-plugin-options', array( $this, '_tw_render_plugin_options' ) );
}
/**
* Render plugin settings page
* @access public
*/
function _tw_render_plugin_options() {
include_once __DIR__ . '/views/plugin-options.php';
}
/**
* Initiate the plugin by setting the default values and assigning any
* required actions and filters.
*
* @access private
*/
private function setup_actions() {
// Don't load Talande Webb in admin
if ( ! is_admin() ):
add_action( 'wp_head', array( $this, '_tw_enqueue') );
endif;
if ( is_admin() ):
// Add options page
add_action( 'admin_menu', array( $this, '_tw_settings_menu') );
endif;
// Add shortcode
add_shortcode( $this->tag, array( $this, '_tw_shortcode' ) );
}
/**
* Global variables
*/
private function setup_globals() {
$this->tag = 'talandewebb';
$this->name = 'Talande Webb Plus';
$this->description = 'För att Talande Webb Plus ska fungera optimalt för dina besökare lägger du in ett script som sätter en cookie (kaka) på webbplatsen. På sidan där du beskriver hur Talande Webb fungerar lägger du till en förklarande text om Talande Webb Plus och en länk som tänder själva verktygsfältet för Talande Webb Plus.';
$this->version = '1.2.1';
$this->languages = array(
'sv-SE' => 'se',
'nb-NO' => 'no',
'fi' => 'fi',
'de-DE' => 'de',
'en-GB' => 'uk',
'en-US' => 'en'
);
$this->defaultLanguage = 'se';
}
/**
* Allow the talandewebb shortcode to be used.
*
* @access public
* @param array $atts
* @param string $content
* @return string
*/
public function _tw_shortcode( $atts, $content = null ) {
shortcode_atts( array(
'class' => false
), $atts );
// Build the list of class names
$classes = array(
$this->tag
);
if ( ! empty( $atts['class'] ) ) {
$classes[] = esc_attr( $atts['class'] );
}
// Output the terminal
ob_start();
?>
<a href="#" class="<?php esc_attr_e( implode( ' ', $classes ) ); ?>" onclick="toggleBar();"><?php echo $content; ?></a>
<?php
return ob_get_clean();
}
/**
* Enqueue the required scripts.
*
* @access public
*/
public function _tw_enqueue() {
$lang = get_bloginfo( 'language' );
if ( isset( $this->language[$lang] ) ) {
$lang = $this->language[$lang];
} else {
$lang = $this->defaultLanguage;
}
$activate_talandewebb = talandewebb_get_plugin_option( 'activation' );
if ( $activate_talandewebb == 'on' ) {
echo '<script type="text/javascript">var _baLocale = "' . $lang . '", _baMode = " ";</script>';
echo '<script type="text/javascript" src="https://www.browsealoud.com/plus/scripts/ba.js"></script>';
}
}
}
}
if ( !function_exists( 'talandewebb' ) ) {
function talandewebb() {
return TalandeWebb::instance();
}
}
add_action( 'plugins_loaded', 'talandewebb' );