PluginProbe
PuzzleMe – Interactive Puzzles for WordPress – Easily publish crosswords, quizzes, word searches and more / trunk
PuzzleMe – Interactive Puzzles for WordPress – Easily publish crosswords, quizzes, word searches and more vtrunk
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 trunk, at puzzleme.php

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