Shortcode_Helpers.php
7.62 KB
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
<?php
namespace Wpo\Core;
use \Wpo\Core\Extensions_Helpers;
use \Wpo\Core\WordPress_Helpers;
use \Wpo\Services\Options_Service;
use \Wpo\Services\Error_Service;
// Prevent public access to this script
defined('ABSPATH') or die();
if (!class_exists('\Wpo\Core\Shortcode_Helpers')) {
class Shortcode_Helpers
{
/**
* Helper method to ensure that short codes are initialized
*
* @since 7.0
*
* @return void
*/
public static function ensure_pintra_short_code()
{
if (!shortcode_exists('pintra')) {
add_shortcode('pintra', '\Wpo\Core\Shortcode_Helpers::add_pintra_shortcode');
}
}
/**
* Adds a pintra app launcher into the page
*
* @since 5.0
*
* @param array short code parameters according to Wordpress codex
* @param string content found in between the short code start and end tag
* @param string text domain
*/
public static function add_pintra_shortcode($atts = array(), $content = null, $tag = '')
{
$atts = array_change_key_case((array)$atts, CASE_LOWER);
$props = '[]';
if (
isset($atts['props'])
&& strlen(trim($atts['props'])) > 0
) {
$result = array();
$props = html_entity_decode($atts['props']);
$prop_kv_pairs = explode(';', $props);
foreach ($prop_kv_pairs as $prop_kv_pair) {
$first_separator = WordPress_Helpers::stripos($prop_kv_pair, ',');
if (false === $first_separator) {
continue;
}
$result[\substr($prop_kv_pair, 0, $first_separator)] = \substr($prop_kv_pair, $first_separator + 1);
}
$props = json_encode($result);
}
$script_url = isset($atts['script_url']) ? html_entity_decode($atts['script_url']) : '';
ob_start();
include($GLOBALS['WPO_CONFIG']['plugin_dir'] . '/templates/pintra.php');
$content = ob_get_clean();
return wp_kses($content, WordPress_Helpers::get_allowed_html());
}
/**
* Helper method to ensure that short codes are initialized
*
* @since 8.0
*
* @return void
*/
public static function ensure_login_button_short_code_V2()
{
if ((class_exists('\Wpo\Premium') || class_exists('\Wpo\Intranet')) && !shortcode_exists('wpo365-sign-in-with-microsoft-v2-sc')) {
add_shortcode('wpo365-sign-in-with-microsoft-v2-sc', '\Wpo\Core\Shortcode_Helpers::add_sign_in_with_microsoft_shortcode_V2');
}
}
/**
* Adds the Sign in with Microsoft short code V2
*
* @since 8.0
*
* @param array short code parameters according to Wordpress codex
* @param string content found in between the short code start and end tag
* @param string text domain
*/
public static function add_sign_in_with_microsoft_shortcode_V2($params = array(), $content = null, $tag = '')
{
if (empty($content)) {
return $content;
}
$site_url = $GLOBALS['WPO_CONFIG']['url_info']['wp_site_url'];
// Load the js dependency
ob_start();
include(Extensions_Helpers::get_active_extension_dir(array('wpo365-login-premium/wpo365-login.php', 'wpo365-login-intranet/wpo365-login.php')) . '/templates/openid-ssolink.php');
$js_lib = ob_get_clean();
// Sanitize the HTML template
$dom = new \DOMDocument();
@$dom->loadHTML($content);
$script = $dom->getElementsByTagName('script');
$remove = array();
foreach ($script as $item)
$remove[] = $item;
foreach ($remove as $item)
$item->parentNode->removeChild($item);
// Concatenate the two
$output = $js_lib . $dom->saveHTML();
return str_replace("__##PLUGIN_BASE_URL##__", $GLOBALS['WPO_CONFIG']['plugin_url'], $output);
}
/**
* Helper method to ensure that short code for login button is initialized
*
* @since 11.0
*/
public static function ensure_login_button_short_code()
{
if (!shortcode_exists('wpo365-login-button')) {
add_shortcode('wpo365-login-button', '\Wpo\Core\Shortcode_Helpers::login_button');
}
}
/**
* Helper to display the Sign in with Microsoft button on a login form.
*
* @since 10.6
*
* @param
*
* @return void
*/
public static function login_button()
{
// Don't render a login button when sso is disabled
if (Options_Service::get_global_boolean_var('no_sso')) {
return;
}
// Used by the template that is rendered
$hide_login_button = Options_Service::get_global_boolean_var('hide_login_button');
$sign_in_with_microsoft = Options_Service::get_global_string_var('sign_in_with_microsoft');
if (empty($sign_in_with_microsoft) || $sign_in_with_microsoft == 'Sign in with Microsoft') {
$sign_in_with_microsoft = __('Sign in with Microsoft', 'wpo365-login');
}
ob_start();
include($GLOBALS['WPO_CONFIG']['plugin_dir'] . '/templates/login-button.php');
$content = ob_get_clean();
echo wp_kses($content, WordPress_Helpers::get_allowed_html());
}
/**
* Helper method to ensure that short code for displaying errors is initialized
*
* @since 7.8
*/
public static function ensure_display_error_message_short_code()
{
if ((class_exists('\Wpo\Professional') || class_exists('\Wpo\Premium') || class_exists('\Wpo\Intranet')) && !shortcode_exists('wpo365-display-error-message-sc'))
add_shortcode('wpo365-display-error-message-sc', '\Wpo\Core\Shortcode_Helpers::add_display_error_message_shortcode');
}
/**
* Adds the error message encapsulated in a div into the page
*
* @since 7.8
*
* @param array short code parameters according to Wordpress codex
* @param string content found in between the short code start and end tag
* @param string text domain
*/
public static function add_display_error_message_shortcode($atts = array(), $content = null, $tag = '')
{
$error_code = isset($_GET['login_errors'])
? sanitize_text_field($_GET['login_errors'])
: '';
$error_message = Error_Service::get_error_message($error_code);
if (empty($error_message)) {
return;
}
ob_start();
include(Extensions_Helpers::get_active_extension_dir(array('wpo365-login-professional/wpo365-login.php', 'wpo365-login-premium/wpo365-login.php', 'wpo365-login-intranet/wpo365-login.php')) . '/templates/error-message.php');
$content = ob_get_clean();
return wp_kses($content, WordPress_Helpers::get_allowed_html());
}
}
}