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

148 lines 5.4 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 for WordPress
4 Version: 1.2.2
5 Description: Embed PuzzleMe puzzles in your posts and pages with a shortcode
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 function load_puzzle_scripts() {
13
14 global $puzzleme_base_path;
15
16 $footer_script_HTML = '
17
18 <script nowprocket data-no-minify="1" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
19 <script nowprocket data-no-minify="1" id="pm-script" src="' . $puzzleme_base_path . 'js/puzzleme-embed.js"></script>
20 <script nowprocket>
21 PM_Config.PM_BasePath = "' . $puzzleme_base_path . '";
22 </script>
23
24 ';
25 echo($footer_script_HTML);
26 }
27
28
29 function puzzleme_iframe_generator($attributes)
30 {
31
32 global $puzzleme_base_path;
33
34 if (isset($attributes['basepath'])) {
35 $puzzleme_base_path = esc_url_raw($attributes['basepath']);
36 } else if (defined('PuzzleMe_BasePath')) {
37 $puzzleme_base_path = PuzzleMe_BasePath;
38 } else {
39 $puzzleme_base_path = 'https://puzzleme.amuselabs.com/pmm/';
40 }
41
42 add_action('wp_footer', 'load_puzzle_scripts');
43
44 $allowedHTMLtags = array(
45 'div' => array(
46 'class' => true,
47 'data-id' => true,
48 'data-set' => true,
49 'data-puzzletype' => true,
50 'data-height' => true,
51 'data-mobileMargin' => true,
52 'data-embedparams' => true,
53 'data-page' => true,
54 'style' => true
55 ),
56 'script' => array(
57 'id' => true,
58 'src' => true,
59 'nowprocket' => true
60 ),
61 'a' => array(
62 'href' => true,
63 'target' => true,
64 'style' => true,
65 'title' => true,
66 'rel' => true
67 )
68 );
69
70 $attributionHTMLTags = array(
71 'a' => array(
72 'href' => true,
73 'target' => true,
74 'style' => true
75 )
76 );
77
78 $valid_embed_types = array('crossword', 'sudoku', 'wordsearch', 'quiz', 'krisskross', 'wordf', 'codeword', 'wordrow', 'jigsaw', 'date-picker');
79
80 $embed_html = '
81
82 <div class="pm-embed-div" $id data-set="$set" $embed_type data-height="700px" data-mobileMargin="10px" $embed_params></div>
83
84 ';
85
86 $embed_html_attributions = '
87 <div style="position: relative; text-align: center;">
88 <div class="pm-embed-div" $id data-set="$set" $embed_type data-height="700px" data-mobileMargin="10px" $embed_params></div>
89 <div class="pm-attribution-div" style="font-family: sans-serif; font-size: 12px; color:#666666; padding-top: 5px; width: 100%;">$attribution_text</div>
90 </div>
91 ';
92
93 $embed_variables = array(
94 '$embed_type' => '',
95 '$set' => '',
96 '$embed_params' => '',
97 '$id' => '',
98 '$attribution_text' => '',
99 );
100
101 if (empty($attributes)) {
102 return "Parameters are missing in the shortcode. Please copy the correct shortcode from your PuzzleMe dashboard.";
103 } else {
104 if (isset($attributes['set'])) {
105 if (isset($attributes['type'])) {
106 if (in_array($attributes['type'], $valid_embed_types)) {
107
108 $embed_variables['$embed_type'] = sanitize_text_field($attributes['type']);
109 $embed_variables['$set'] = sanitize_text_field($attributes['set']);
110 if (isset($attributes['embedparams'])) {
111 $embed_variables['$embed_params'] = 'data-embedparams="embed=wp&' . sanitize_text_field($attributes['embedparams']) . '"';
112 } else {
113 $embed_variables['$embed_params'] = 'data-embedparams="embed=wp"' ;
114 }
115 if ($attributes['type'] != 'date-picker') {
116 $embed_variables['$embed_type'] = 'data-puzzleType="' . sanitize_text_field($attributes['type']) . '"';
117 if (isset($attributes['id'])) {
118 $embed_variables['$id'] = 'data-id="' . sanitize_text_field($attributes['id']) . '"';
119 } else {
120 return "Puzzle ID is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
121 }
122 } else {
123 $embed_variables['$embed_type'] = 'data-page="date-picker"';
124 }
125 if (isset($attributes['attribution'])) {
126 $embed_variables['$attribution_text'] = wp_kses($attributes['attribution'], $attributionHTMLTags);
127 return wp_kses(strtr($embed_html_attributions, $embed_variables), $allowedHTMLtags);
128 } else {
129 return wp_kses(strtr($embed_html, $embed_variables), $allowedHTMLtags);
130 }
131
132 } else {
133 return "Invalid puzzle type is present in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
134 }
135
136 } else {
137 return "Puzzle type is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
138 }
139
140 } else {
141 return "Set is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
142 }
143 }
144 }
145
146 add_shortcode('puzzleme', 'puzzleme_iframe_generator');
147
148 ?>