1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: BLAZE Retail Widget |
---|
4 | Plugin URI: |
---|
5 | Description: Plugin to add and edit BLAZE API Key. |
---|
6 | Author: BLAZE |
---|
7 | Version: 2.5.3 |
---|
8 | Author URI: http://blaze.me/ |
---|
9 | */ |
---|
10 | define('BLAZE_URL',plugin_dir_url( __FILE__)); |
---|
11 | |
---|
12 | // this is the table prefix |
---|
13 | global $wpdb; |
---|
14 | $wp_prefix=$wpdb->prefix; |
---|
15 | define('BLAZE_TABLE_PREFIX', $wp_prefix); |
---|
16 | |
---|
17 | register_activation_hook(__FILE__,'installBlazeWidget'); |
---|
18 | register_deactivation_hook(__FILE__ , 'uninstallBlazeWidget' ); |
---|
19 | |
---|
20 | function installBlazeWidget() |
---|
21 | { |
---|
22 | global $wpdb; |
---|
23 | $table = BLAZE_TABLE_PREFIX."blaze_widget"; |
---|
24 | $structure = "CREATE TABLE $table ( |
---|
25 | id INT(30) NOT NULL AUTO_INCREMENT, |
---|
26 | blazeAPIKey VARCHAR(200), |
---|
27 | blazeWidgetURL TEXT, |
---|
28 | UNIQUE KEY id (id) |
---|
29 | );"; |
---|
30 | $wpdb->query($structure); // Execute query |
---|
31 | $query = $wpdb->insert( $table, array( |
---|
32 | 'blazeAPIKey' =>' ', |
---|
33 | 'blazeWidgetURL' =>' ' |
---|
34 | )); |
---|
35 | wp_reset_query(); // Reset wordpress query |
---|
36 | } |
---|
37 | function uninstallBlazeWidget() |
---|
38 | { |
---|
39 | global $wpdb; |
---|
40 | $table = BLAZE_TABLE_PREFIX."blaze_widget"; |
---|
41 | $wpdb->query( "DROP TABLE IF EXISTS $table" ); |
---|
42 | delete_option("my_plugin_db_version"); |
---|
43 | } |
---|
44 | add_action('admin_menu','blaze_menu'); // Admin menu hook |
---|
45 | |
---|
46 | /* Function is used to add a new menu in plugin */ |
---|
47 | function blaze_menu() |
---|
48 | { |
---|
49 | add_menu_page("BLAZE Widget","BLAZE Widget","manage_options","blaze-widget","blazewidget",BLAZE_URL."blaze.png"); |
---|
50 | } |
---|
51 | function blazewidget() |
---|
52 | { |
---|
53 | global $wpdb; |
---|
54 | $table_name= $wpdb->prefix .'blaze_widget'; |
---|
55 | |
---|
56 | if(isset($_POST['submit'])) |
---|
57 | { |
---|
58 | $blazeAPIKey= sanitize_text_field($_POST['blazeAPIKey']); |
---|
59 | $blazeWidgetURL= esc_url($_POST['blazeWidgetURL']); |
---|
60 | if ( ! isset( $_POST['blaze_nonce_field'] ) || ! wp_verify_nonce( $_POST['blaze_nonce_field'], 'name_of_my_action' ) AND current_user_can('administrator')) |
---|
61 | { |
---|
62 | echo "<script>jQuery(document).ready(function(){ jQuery('#setting-error-settings_updated').addClass('error'); jQuery('#setting-error-settings_updated').removeClass('updated'); jQuery('#setting-error-settings_updated').show(); jQuery('#setting-error-settings_updated').find('strong').text('You have not permission to access '); });</script>"; |
---|
63 | |
---|
64 | |
---|
65 | } else { |
---|
66 | $sql2="SELECT * FROM $table_name"; |
---|
67 | $resuth1=$wpdb->get_results($sql2); |
---|
68 | $resuth2= $wpdb->num_rows; |
---|
69 | |
---|
70 | if($resuth2=='1'){ |
---|
71 | foreach($resuth1 as $resuth){ |
---|
72 | $id = $resuth ->id; |
---|
73 | } |
---|
74 | $query =$wpdb->update( $table_name, |
---|
75 | array('blazeAPIKey' => $blazeAPIKey, 'blazeWidgetURL' => $blazeWidgetURL), |
---|
76 | array('id' => $id), array('%s', '%s'), |
---|
77 | array('%d',) |
---|
78 | ); |
---|
79 | |
---|
80 | if($query == 1) |
---|
81 | { |
---|
82 | echo "<script>jQuery(document).ready(function(){ jQuery('#setting-error-settings_updated').addClass('updated'); jQuery('#setting-error-settings_updated').removeClass('error'); jQuery('#setting-error-settings_updated').show(); jQuery('#setting-error-settings_updated').find('strong').text('Record updated.'); });</script>"; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | echo "<script>jQuery(document).ready(function(){ jQuery('#setting-error-settings_updated').addClass('error'); jQuery('#setting-error-settings_updated').removeClass('updated'); jQuery('#setting-error-settings_updated').show(); jQuery('#setting-error-settings_updated').find('strong').text('Record has not been saved. Please try again!'); });</script>"; |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | } else { |
---|
91 | $query = $wpdb->insert( $table_name, array( |
---|
92 | 'blazeAPIKey' =>$blazeAPIKey, |
---|
93 | 'blazeWidgetURL' =>$blazeWidgetURL |
---|
94 | )); |
---|
95 | if($query == 1) |
---|
96 | { |
---|
97 | echo "<script>jQuery(document).ready(function(){ jQuery('#setting-error-settings_updated').addClass('updated'); jQuery('#setting-error-settings_updated').removeClass('error'); jQuery('#setting-error-settings_updated').show(); jQuery('#setting-error-settings_updated').find('strong').text('Record saved.'); });</script>"; |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | echo "<script>jQuery(document).ready(function(){ jQuery('#setting-error-settings_updated').addClass('error'); jQuery('#setting-error-settings_updated').removeClass('updated'); jQuery('#setting-error-settings_updated').show(); jQuery('#setting-error-settings_updated').find('strong').text('Record has not been saved. Please try again!'); });</script>"; |
---|
102 | |
---|
103 | } |
---|
104 | }}} |
---|
105 | $sql2="SELECT * FROM $table_name"; |
---|
106 | $resuth1=$wpdb->get_results($sql2); |
---|
107 | |
---|
108 | foreach($resuth1 as $resuth){ |
---|
109 | $blazeAPIKey = $resuth ->blazeAPIKey; |
---|
110 | $blazeWidgetURL = $resuth ->blazeWidgetURL; |
---|
111 | } |
---|
112 | ?> |
---|
113 | <script> |
---|
114 | jQuery(document).ready(function(){ |
---|
115 | jQuery(".notice-dismiss").click(function(){ |
---|
116 | jQuery(this).parent.hide(); |
---|
117 | }); |
---|
118 | }); |
---|
119 | </script> |
---|
120 | |
---|
121 | <div id="wpbody" role="main"> |
---|
122 | |
---|
123 | <div id="wpbody-content" aria-label="Main content" tabindex="0"> |
---|
124 | |
---|
125 | <div class="wrap"> |
---|
126 | <h1> Please add BLAZE Widget Store Key</h1> |
---|
127 | |
---|
128 | <div id="setting-error-settings_updated" class="updated settings-error notice is-dismissible" style="display:none;"> |
---|
129 | <p> |
---|
130 | <strong></strong> |
---|
131 | </p> |
---|
132 | <button type="button" class="notice-dismiss"> |
---|
133 | <span class="screen-reader-text">Dismiss this notice.</span> |
---|
134 | </button> |
---|
135 | </div> |
---|
136 | <div class="blaze-form" style="display: inline-block; vertical-align: middle; width: 60%;"> |
---|
137 | <form method="post" action=""> |
---|
138 | <?php wp_nonce_field( 'name_of_my_action', 'blaze_nonce_field' ); ?> |
---|
139 | <table class="form-table"> |
---|
140 | <tbody> |
---|
141 | <tr> |
---|
142 | <th scope="row"><label for="blazeAPIKey">BLAZE API Key</label></th> |
---|
143 | <td> |
---|
144 | <input type="text" name="blazeAPIKey" value="<?php if($blazeAPIKey !=''){ echo $blazeAPIKey ;} ?>" class="regular-text" required/> |
---|
145 | </td> |
---|
146 | </tr> |
---|
147 | <tr> |
---|
148 | <th scope="row"><!--<label for="blazeWidgetURL">Blaze Widget URL</label>--></th> |
---|
149 | <td> |
---|
150 | <input type="hidden" name="blazeWidgetURL" value="https://store.blaze.me" class="regular-text" required/> |
---|
151 | </td> |
---|
152 | </tr> |
---|
153 | </tbody> |
---|
154 | </table> |
---|
155 | <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save"></p> |
---|
156 | </form> |
---|
157 | </div> |
---|
158 | <div class="blaze-logo" style="display: inline-block;"> |
---|
159 | <img src="<?php echo BLAZE_URL ?>side_Logo.png" alt="blaze-logo"> |
---|
160 | </div> |
---|
161 | </div> |
---|
162 | <h4>Please copy and paste this shortcode on a page/post: [blaze_widget]</h4> |
---|
163 | <div class="clear"></div></div><!-- wpbody-content --> |
---|
164 | <div class="clear"></div></div> |
---|
165 | <?php } |
---|
166 | |
---|
167 | function blaze_me_widget_front($params, $content = null){ |
---|
168 | global $wpdb; |
---|
169 | extract(shortcode_atts(array( |
---|
170 | 'type' => 'style1' |
---|
171 | ), $params)); |
---|
172 | |
---|
173 | ob_start(); |
---|
174 | $table_name= $wpdb->prefix .'blaze_widget'; |
---|
175 | $sql2="SELECT * FROM $table_name"; |
---|
176 | $resuth1=$wpdb->get_results($sql2); |
---|
177 | $resuth2= $wpdb->num_rows; |
---|
178 | if($resuth2==''){ |
---|
179 | echo "<h1>Please add Blaze Widget detail in the admin section</h1>"; |
---|
180 | } else { |
---|
181 | foreach($resuth1 as $resuth) |
---|
182 | { |
---|
183 | |
---|
184 | $blazeAPIKey = $resuth ->blazeAPIKey; |
---|
185 | $blazeWidgetURL = $resuth ->blazeWidgetURL; |
---|
186 | } |
---|
187 | ?> |
---|
188 | |
---|
189 | <iframe id="blazeIframe" frameborder="0" style></iframe> |
---|
190 | <script type="text/javascript"> |
---|
191 | var blazeAPIKey = '<?php echo $blazeAPIKey; ?>'; |
---|
192 | var blazeWidgetURL = 'https://store.blaze.me'; |
---|
193 | window.blazeKey = blazeAPIKey; |
---|
194 | var maxHeight = window.innerHeight; |
---|
195 | |
---|
196 | const googleMapScript = `<script type="text/javascript" src="https://maps.google.com/maps/api/js?key=AIzaSyCZj40Co5f9FJF6rnkvYccVW1x-k3DgBDQ&libraries=places"><\/script>` |
---|
197 | |
---|
198 | window.onload = function () { |
---|
199 | var frame = document.getElementById('blazeIframe'); |
---|
200 | frame.style.width="1px" |
---|
201 | frame.style.minWidth="100%" |
---|
202 | frame.style.transition="all 0.4s" |
---|
203 | frame.contentWindow.blazeKey = blazeAPIKey; |
---|
204 | frame.contentWindow.document.write(`<!DOCTYPE html><html><head><title>Blaze retail widget</title><link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css'><meta charset='utf8'/><meta content='width=device-width , initial-scale=1.0, maximum-scale=1, user-scalable=no' name='viewport'></head><body><div id='RetailConnectBlazeApp'></div>${googleMapScript}</body></html>`) |
---|
205 | |
---|
206 | var head = frame.contentWindow.document.head, |
---|
207 | script = frame.contentWindow.document.createElement("script"); |
---|
208 | script.src = blazeWidgetURL + "/bundle.js"; |
---|
209 | |
---|
210 | var css = frame.contentWindow.document.createElement('link'); |
---|
211 | css.href = blazeWidgetURL + '/styles.css'; |
---|
212 | css.type = 'text/css'; |
---|
213 | css.rel = 'stylesheet'; |
---|
214 | |
---|
215 | var link = frame.contentWindow.document.createElement("link"); |
---|
216 | link.rel = "icon"; |
---|
217 | link.href = blazeWidgetURL + "/images/28x34_Logo@2x.ico" |
---|
218 | |
---|
219 | var script2 = frame.contentWindow.document.createElement("script"); |
---|
220 | script2.text = "window.blazeKey = '"+blazeAPIKey+"';" |
---|
221 | |
---|
222 | head.appendChild(css); |
---|
223 | head.appendChild(script); |
---|
224 | head.appendChild(link); |
---|
225 | head.appendChild(script2); |
---|
226 | |
---|
227 | var parenthead = document.head; |
---|
228 | |
---|
229 | var parentiframeScript = document.createElement("script"); |
---|
230 | |
---|
231 | parentiframeScript.src = blazeWidgetURL + "/vendor/iframe.js"; |
---|
232 | parenthead.appendChild(parentiframeScript); |
---|
233 | |
---|
234 | parentiframeScript.addEventListener('load', function () { |
---|
235 | var iframeScript = frame.contentWindow.document.createElement("script"); |
---|
236 | iframeScript.type = "text/javascript"; |
---|
237 | iframeScript.src = blazeWidgetURL + "/vendor/iframeSizer.contentWindow.min.js"; |
---|
238 | |
---|
239 | head.appendChild(iframeScript); |
---|
240 | |
---|
241 | iframeScript.addEventListener('load', function () { |
---|
242 | iFrameResize({checkOrigin: false,minHeight: maxHeight, enablePublicMethods: true, resizedCallback: function (data) {frame.contentWindow.postMessage(data.height, '*')}},'#blazeIframe'); |
---|
243 | }) |
---|
244 | |
---|
245 | }) |
---|
246 | } |
---|
247 | </script> |
---|
248 | <?php |
---|
249 | } |
---|
250 | return ob_get_clean(); |
---|
251 | } |
---|
252 | //Add ShortCode for "front end" |
---|
253 | add_shortcode('blaze_widget', 'blaze_me_widget_front'); |
---|
254 | ?> |
---|