PluginProbe
PuzzleMe – Interactive Puzzles for WordPress – Easily publish crosswords, quizzes, word searches and more / 1.3.0
PuzzleMe – Interactive Puzzles for WordPress – Easily publish crosswords, quizzes, word searches and more v1.3.0
1.4.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1
puzzleme / puzzleme.php

puzzleme.php in PuzzleMe – Interactive Puzzles for WordPress – Easily publish crosswords, quizzes, word searches and more 1.3.0, at puzzleme.php

218 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: PuzzleMe - Interactive Puzzles for WordPress - Easily publish crosswords, quizzes, word searches and more
4 Version: 1.3.0
5 Description: PuzzleMe makes it easy to add interactive games to your WordPress website - no coding required.
6 Author: Amuse Labs
7 Author URI: https://www.amuselabs.com/
8 License: GPLv2 or later
9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if (!defined('ABSPATH')) {
13 exit;
14 }
15
16 if (!defined('PUZZLEME_PLUGIN_VERSION')) {
17 define('PUZZLEME_PLUGIN_VERSION', '1.3.0');
18 }
19
20 function puzzleme_get_logged_in_user_embed_attributes($attributes)
21 {
22 if (!isset($attributes['uidsalt'])) {
23 return array(
24 '$user_attributes' => '',
25 );
26 }
27
28 if (!is_user_logged_in()) {
29 return array(
30 '$user_attributes' => '',
31 );
32 }
33
34 $user = wp_get_current_user();
35 if (empty($user->user_email)) {
36 return array(
37 '$user_attributes' => '',
38 );
39 }
40
41 $salt = sanitize_text_field($attributes['uidsalt']);
42 if ($salt === '') {
43 return array(
44 '$user_attributes' => '',
45 );
46 }
47
48 $email = strtolower(trim($user->user_email));
49 $hash = hash('sha256', wp_salt($salt) . $email);
50 $uid = $hash;
51
52 if (isset($attributes['uidprefix'])) {
53 $prefix = sanitize_text_field($attributes['uidprefix']);
54 if ($prefix !== '') {
55 $uid = $prefix . substr($hash, strlen($prefix));
56 }
57 }
58
59 return array(
60 '$user_attributes' => 'data-uid="' . esc_attr($uid) . '" data-display-name="' . esc_attr($user->display_name) . '"',
61 );
62 }
63
64 function load_puzzle_scripts() {
65
66 global $puzzleme_base_path;
67
68 $footer_script_HTML = '
69
70 <script nowprocket data-no-minify="1" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
71 <script nowprocket data-no-minify="1" id="pm-script" src="' . $puzzleme_base_path . 'js/puzzleme-embed.js"></script>
72 <script nowprocket>
73 PM_Config.PM_BasePath = "' . $puzzleme_base_path . '";
74 </script>
75
76 ';
77 echo($footer_script_HTML);
78 }
79
80
81 function puzzleme_iframe_generator($attributes)
82 {
83
84 global $puzzleme_base_path;
85
86 if (isset($attributes['basepath'])) {
87 $puzzleme_base_path = esc_url_raw($attributes['basepath']);
88 } else if (defined('PuzzleMe_BasePath')) {
89 $puzzleme_base_path = PuzzleMe_BasePath;
90 } else {
91 $puzzleme_base_path = 'https://puzzleme.amuselabs.com/pmm/';
92 }
93
94 add_action('wp_footer', 'load_puzzle_scripts');
95
96 $allowedHTMLtags = array(
97 'div' => array(
98 'class' => true,
99 'data-id' => true,
100 'data-set' => true,
101 'data-puzzletype' => true,
102 'data-uid' => true,
103 'data-display-name' => true,
104 'data-height' => true,
105 'data-mobilemargin' => true,
106 'data-embedparams' => true,
107 'data-page' => true,
108 'style' => true
109 ),
110 'script' => array(
111 'id' => true,
112 'src' => true,
113 'nowprocket' => true
114 ),
115 'a' => array(
116 'href' => true,
117 'target' => true,
118 'style' => true,
119 'title' => true,
120 'rel' => true
121 )
122 );
123
124 $attributionHTMLTags = array(
125 'a' => array(
126 'href' => true,
127 'target' => true,
128 'style' => true
129 )
130 );
131
132 $valid_embed_types = array('crossword', 'sudoku', 'wordsearch', 'quiz', 'krisskross', 'wordf', 'codeword', 'wordrow', 'jigsaw', 'date-picker', 'group-picker');
133
134 $embed_html = '
135
136 <div class="pm-embed-div" $id data-set="$set" $embed_type data-height="$height" data-mobilemargin="$mobile_margin" $embed_params $user_attributes></div>
137
138 ';
139
140 $embed_html_attributions = '
141 <div style="position: relative; text-align: center;">
142 <div class="pm-embed-div" $id data-set="$set" $embed_type data-height="$height" data-mobilemargin="$mobile_margin" $embed_params $user_attributes></div>
143 <div class="pm-attribution-div" style="font-family: sans-serif; font-size: 12px; color:#666666; padding-top: 5px; width: 100%;">$attribution_text</div>
144 </div>
145 ';
146
147 $embed_variables = array(
148 '$embed_type' => '',
149 '$set' => '',
150 '$embed_params' => '',
151 '$id' => '',
152 '$attribution_text' => '',
153 '$height' => '700px',
154 '$mobile_margin' => '10px',
155 '$user_attributes' => '',
156 );
157
158 if (empty($attributes)) {
159 return "Parameters are missing in the shortcode. Please copy the correct shortcode from your PuzzleMe dashboard.";
160 } else {
161 if (isset($attributes['set'])) {
162 if (isset($attributes['type'])) {
163 if (in_array($attributes['type'], $valid_embed_types)) {
164
165 $embed_variables['$embed_type'] = sanitize_text_field($attributes['type']);
166 $embed_variables['$set'] = sanitize_text_field($attributes['set']);
167 $embed_variables = array_merge($embed_variables, puzzleme_get_logged_in_user_embed_attributes($attributes));
168 if (isset($attributes['height'])) {
169 $embed_variables['$height'] = sanitize_text_field($attributes['height']);
170 }
171 if (isset($attributes['mobilemargin'])) {
172 $embed_variables['$mobile_margin'] = sanitize_text_field($attributes['mobilemargin']);
173 }
174 if (isset($attributes['embedparams'])) {
175 $embed_variables['$embed_params'] = 'data-embedparams="embed=wp&' . sanitize_text_field($attributes['embedparams']) . '"';
176 } else {
177 $embed_variables['$embed_params'] = 'data-embedparams="embed=wp"' ;
178 }
179 if ($attributes['type'] != 'date-picker' && $attributes['type'] != 'group-picker') {
180 $embed_variables['$embed_type'] = 'data-puzzleType="' . sanitize_text_field($attributes['type']) . '"';
181 if (isset($attributes['id'])) {
182 $embed_variables['$id'] = 'data-id="' . sanitize_text_field($attributes['id']) . '"';
183 } else {
184 return "Puzzle ID is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
185 }
186 } else {
187 $embed_variables['$embed_type'] = 'data-page="' . sanitize_text_field($attributes['type']) . '"';
188 }
189 if (isset($attributes['attribution'])) {
190 $embed_variables['$attribution_text'] = wp_kses($attributes['attribution'], $attributionHTMLTags);
191 return wp_kses(strtr($embed_html_attributions, $embed_variables), $allowedHTMLtags);
192 } else {
193 return wp_kses(strtr($embed_html, $embed_variables), $allowedHTMLtags);
194 }
195
196 } else {
197 return "Invalid puzzle type is present in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
198 }
199
200 } else {
201 return "Puzzle type is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
202 }
203
204 } else {
205 return "Set is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
206 }
207 }
208 }
209
210 add_shortcode('puzzleme', 'puzzleme_iframe_generator');
211
212 if (is_admin()) {
213 require_once plugin_dir_path(__FILE__) . 'admin/class-puzzleme-admin.php';
214 new PuzzleMe_Admin(__FILE__);
215 }
216
217 ?>
218