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

140 lines 5.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 for WordPress
4 Version: 1.2.0
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 $valid_embed_types = array('crossword', 'sudoku', 'wordsearch', 'quiz', 'krisskross', 'wordf', 'codeword', 'wordrow', 'jigsaw', 'date-picker');
71
72 $embed_html = '
73
74 <div class="pm-embed-div" $id data-set="$set" $embed_type data-height="700px" data-mobileMargin="10px" $embed_params></div>
75
76 ';
77
78 $embed_html_attributions = '
79 <div style="position: relative; text-align: center;">
80 <div class="pm-embed-div" $id data-set="$set" $embed_type data-height="700px" data-mobileMargin="10px" $embed_params></div>
81 <div class="pm-attribution-div" style="font-family: sans-serif; font-size: 12px; color:#666666; padding-top: 5px; width: 100%;">$attribution_text</div>
82 </div>
83 ';
84
85 $embed_variables = array(
86 '$embed_type' => '',
87 '$set' => '',
88 '$embed_params' => '',
89 '$id' => '',
90 '$attribution_text' => '',
91 );
92
93 if (empty($attributes)) {
94 return "Parameters are missing in the shortcode. Please copy the correct shortcode from your PuzzleMe dashboard.";
95 } else {
96 if (isset($attributes['set'])) {
97 if (isset($attributes['type'])) {
98 if (in_array($attributes['type'], $valid_embed_types)) {
99
100 $embed_variables['$embed_type'] = sanitize_text_field($attributes['type']);
101 $embed_variables['$set'] = sanitize_text_field($attributes['set']);
102 if (isset($attributes['embedparams'])) {
103 $embed_variables['$embed_params'] = 'data-embedparams="embed=wp&' . sanitize_text_field($attributes['embedparams']) . '"';
104 } else {
105 $embed_variables['$embed_params'] = 'data-embedparams="embed=wp"' ;
106 }
107 if ($attributes['type'] != 'date-picker') {
108 $embed_variables['$embed_type'] = 'data-puzzleType="' . sanitize_text_field($attributes['type']) . '"';
109 if (isset($attributes['id'])) {
110 $embed_variables['$id'] = 'data-id="' . sanitize_text_field($attributes['id']) . '"';
111 } else {
112 return "Puzzle ID is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
113 }
114 } else {
115 $embed_variables['$embed_type'] = 'data-page="date-picker"';
116 }
117 if (isset($attributes['attribution'])) {
118 $embed_variables['$attribution_text'] = $attributes['attribution'];
119 return wp_kses(strtr($embed_html_attributions, $embed_variables), $allowedHTMLtags);
120 } else {
121 return wp_kses(strtr($embed_html, $embed_variables), $allowedHTMLtags);
122 }
123
124 } else {
125 return "Invalid puzzle type is present in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
126 }
127
128 } else {
129 return "Puzzle type is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
130 }
131
132 } else {
133 return "Set is missing in the shortcode. Please use the correct shortcode from your PuzzleMe dashboard.";
134 }
135 }
136 }
137
138 add_shortcode('puzzleme', 'puzzleme_iframe_generator');
139
140 ?>