· 6 years ago · Apr 10, 2019, 01:22 PM
1<?php
2defined( 'ABSPATH' ) or die( 'No direct access allowed!' );
3/**
4 * Plugin Name: GetSmokin' Reviews
5 * Version: 1
6 * Description: Een simpele plugin om gemakkelijk reviews van GetSmokin' op je eigen website te publiceren.
7 * Author: GetSmokin'
8 * Author URI: https://getsmokin.nl
9 * License: GPLv2 or later
10 * Text Domain: getsmokin-reviews
11 */
12
13global $wpdb;
14define('ZPT_DEBUG', true);
15
16define('gsr_config', $wpdb->prefix."gsr_config");
17define('gsr_ratings', $wpdb->prefix."gsr_ratings");
18$posts_table = $wpdb->prefix."posts";
19$postsmeta_table = $wpdb->prefix."postmeta";
20/*
21* Holding notify messages to display page visitor
22*/
23$zpt_message = array(
24 'mcg' => null,
25 'type'=> null,
26);
27
28
29/*
30* Loading helper file
31**/
32include(plugin_dir_path( __FILE__ ).'_functions.php');
33
34
35/*
36* ACTIVATION/DE-ACTIVATION HOOKS REGISTERATION
37*/
38register_activation_hook( __FILE__, 'gsr_install_hook' );
39register_deactivation_hook(__FILE__,'gsr_un_install_hook');
40
41/*
42* ACTIVATION HOOK
43*/
44function gsr_install_hook () {
45 global $wpdb;
46 $charset_collate = $wpdb->get_charset_collate();
47 $creds_sql = "CREATE TABLE ".gsr_config." (
48 id int(11) NOT NULL AUTO_INCREMENT,
49 _type varchar(50) NOT NULL,
50 _value varchar(50) NOT NULL,
51 _value2 varchar(50) NOT NULL,
52 last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
53 PRIMARY KEY (id)
54 ) $charset_collate";
55
56 $rating_sql = "CREATE TABLE ".gsr_ratings." (
57 id int(11) NOT NULL AUTO_INCREMENT,
58 rating int(11) NOT NULL,
59 name varchar(50) NOT NULL,
60 review text NOT NULL,
61 date TIMESTAMP NOT NULL,
62 PRIMARY KEY (id)
63 ) $charset_collate";
64
65 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
66 dbDelta( $creds_sql );
67 dbDelta( $rating_sql );
68}
69
70
71/*
72* DE-ACTIVATION HOOK
73*/
74function gsr_un_install_hook(){
75 if(_ZPT_DEBUG_){
76 global $wpdb;
77 $sql = "DROP TABLE IF EXISTS ".gsr_config.",".gsr_ratings;
78 $wpdb->query($sql);
79 }
80}
81
82
83/*
84* ADMIN AREA OF PLUGIN
85*/
86add_action('admin_menu', 'gsr_starter_admin_hook');
87
88function gsr_starter_admin_hook(){
89 add_menu_page( 'GetSmokin’ Reviews | ADMIN PANEL', 'GetSmokin’ Reviews', 'manage_options', 'gsr-manage-reviews', 'gsr_init_reviews',plugin_dir_url( __FILE__ ).'/assets/icons/favicon.ico' );
90}
91
92
93function gsr_init_reviews(){
94 global $wpdb, $zpt_message;
95 if(isset($_POST['update_reviews'])){
96 zpt_gsr_cron_run('alert');
97 }
98 if(isset($_POST['save_business_id']) && trim($_POST['save_business_id']) == 'gsr-zpt'){
99 $insert_id = $wpdb->query("INSERT INTO ".gsr_config." (_type, _value, _value2) VALUES ('business_id', '".$_POST['place-id']."', '".$_POST['place-name']."')");
100 zpt_gsr_cron_run('alert');
101 }
102
103 if(isset($_POST['save_settings'])){
104 foreach($_POST as $index => $value){
105 if($index != 'save_settings'){
106 if($index == 'cron_time'){
107 wp_clear_scheduled_hook('zpt_gsr_cron_event');
108 }
109 $fetch_settings = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type = '".$index."' LIMIT 1");
110 $fetch_settings = $fetch_settings[0];
111 if($fetch_settings && !empty($fetch_settings)){
112 $wpdb->query("UPDATE ".gsr_config." SET _value = '".$value."', last_update = '".date('Y-m-d h:i A')."' WHERE _type = '".$index."' LIMIT 1");
113 }else{
114 $wpdb->query("INSERT INTO ".gsr_config." SET _value = '".$value."', last_update = '".date('Y-m-d h:i A')."', _type = '".$index."'");
115 }
116 }
117 }
118 $zpt_message['type'] = 'success';
119 $zpt_message['mcg'] = 'Instellingen opgeslagen';
120 }
121 $saved_creds = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type = 'business_id' LIMIT 1");
122 $saved_creds = $saved_creds[0];
123 $user_settings = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type != 'business_id' ");
124 if($user_settings && !empty($user_settings)){
125 foreach($user_settings as $setting){
126 if($setting->_type == 'cron_time'){
127 $cron_time = (int)$user_settings->_value;
128 }else{
129 ${$setting->_type} = $setting->_value;
130 }
131 }
132 }
133?>
134<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
135<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/2.5.3/css/bootstrap-colorpicker.css" />
136<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
137<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-colorpicker/2.5.3/js/bootstrap-colorpicker.js"></script>
138<style>
139 <?php include(plugin_dir_path( __FILE__ ).'assets/css/GetSmokin.css'); ?>
140 .zpt-title {
141 cursor: inherit;
142 }
143 #preview-inner, #settings-inner {
144 padding: 30px;
145 border: 1px solid black;
146 }
147</style>
148<div class="zpt-smm-main margin-top">
149 <?php if($zpt_message['type'] != null && trim($zpt_message['type']) !=''){ echo '<div class="zpt-notify col-md-6">';gsrNotify($zpt_message); echo '</div>';} ?>
150 <?php if($saved_creds){ ?>
151
152 <h1 id="getsmokin_title">GetSmokin' Reviews</h1>
153 <p id="getsmokin_para">Gebruik de shortcode [gsr_show_reviews] op een pagina om de reviews weer te geven, of gebruik de widget.</p>
154
155 <div class="col-md-12">
156 <div class="col-md-6">
157 <h4 class="zpt-thread-title">Instellingen</h4>
158 <div id="settings-inner">
159 <form method="post" >
160 <div class="">
161 <div class="form-group row">
162 <div class="col-md-5 col-xs-12 text-left">
163 <label>Update reviews <span class="dashicons dashicons-warning" data-toggle="tooltip" title="De interval voor het updaten van de reviews"></span></label>
164 </div>
165 <div class="col-md-7 col-xs-12">
166 <select name="cron_time" class="form-control form-group">
167 <option value="1" <?=$cron_time == 1 ? 'selected' : ''?>>Ieder uur</option>
168 <option value="12"<?=$cron_time == 12 ? 'selected' : ''?>>Iedere 12 uur</option>
169 <option value="24"<?=$cron_time == 24 ? 'selected' : ''?>>Iedere 24 uur</option>
170 </select>
171 </div>
172 </div>
173 <div class="form-group row">
174 <div class="col-md-5 col-xs-12 text-left">
175 <label>Highlight kleur <span class="dashicons dashicons-warning" data-toggle="tooltip" title="De primaire kleur voor de visuele weergave"></span></label>
176 </div>
177 <div class="form-group col-md-7 col-xs-12">
178 <div class="input-group colorpicker-component gsr_colorpicker">
179 <input type="text" name="main_background_color" id="gscolorinput" value="<?=$main_background_color ? $main_background_color : '#53a500'?>" class="form-control"/>
180 <span class="input-group-addon"><i></i></span>
181 </div>
182 </div>
183 </div>
184
185 <div class="row form-group">
186 <div class="col-md-5 col-xs-12 text-left">
187 <label>Titel kleur <span class="dashicons dashicons-warning" data-toggle="tooltip" title="Pas de kleur van de 'XX Reviews'-titel aan"></span></label>
188 </div>
189 <div class="col-md-7 col-xs-12">
190 <div class="input-group colorpicker-component gsr_colorpicker">
191 <input type="text" name="title_background_color" value="<?=$title_background_color ? $title_background_color : '#23282d'?>" class="form-control" id="getsmokin_titlecolor"/>
192 <span class="input-group-addon"><i></i></span>
193 </div>
194 </div>
195 </div>
196
197 <div class="form-group">
198 <button type="submit" name="save_settings" class="btn btn-success">Instellingen opslaan</button>
199 </div>
200
201 <div class="form-group">
202 <button type="submit" name="update_reviews" class="btn btn-primary">Update reviews</button>
203 </div>
204 <div class="form-group">
205 <h3 class="getsmokininfo">Gebruik de shortcode [gsr_show_reviews] op een pagina om de reviews weer te geven. Om opnieuw een coffeeshop te selecteren dien je de plugin uit en weer aan te zetten.</h3>
206 </div>
207 </div>
208 </form>
209 </div>
210 </div>
211 <div class="col-md-6">
212
213 <h4 class="zpt-thread-title">Voorbeeld</h4>
214
215 <div id="preview-inner">
216 <?php global $wpdb;
217 $get_reviews = $wpdb->get_results("SELECT * FROM ".gsr_ratings);
218 $user_settings = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type != 'business_id' ");
219 if($user_settings && !empty($user_settings)){
220 foreach($user_settings as $setting){
221 ${$setting->_type} = $setting->_value;
222 }
223 }
224 ?>
225
226 <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600" rel="stylesheet">
227
228 <style>
229 <?php include(plugin_dir_path( __FILE__ ).'assets/css/GetSmokin.css'); ?>
230
231 <?php if($main_background_color){ ?>
232 .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:hover, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:focus {
233 color: <?=$main_background_color ?>;
234 border: 1px solid <?=$main_background_color ?>;
235 }
236 .tns-outer [aria-controls]:hover:before, .tns-outer [aria-controls]:hover:after, .tns-outer [aria-controls]:focus:before, .tns-outer [aria-controls]:focus:after {
237 background: <?=$main_background_color ?>;
238 }
239 .getsmokin-comment-stars svg path{
240 fill: <?=$main_background_color ?>;
241 }
242 <?php } ?>
243
244 <?php if($title_background_color){ ?>
245 .getsmokin-reviews-heading {
246 color: <?=$title_background_color ?>;
247 }
248 <?php } ?>
249 </style>
250
251 <link rel="stylesheet" href="<?=plugin_dir_url( __FILE__ )?>assets/css/tinyslider.css">
252 <!--[if (lt IE 9)]><script src="href="<?=plugin_dir_url( __FILE__ )?>assets/js/tinyslider-ie8fix.js""></script><![endif]-->
253
254
255 <?php
256 $randId = rand();
257 $shopSlug = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type = 'business_id' LIMIT 1");
258 $shopSlug = $shopSlug[0]
259 ?>
260
261 <div class="getsmokin-wrapper nomargin">
262 <div class="getsmokin-reviews-header">
263 <div>
264 <h3 class="getsmokin-reviews-heading"><?=count($get_reviews)?> reviews</h3>
265 </div>
266 <a class="getsmokin-reviews-button" rel="noopener" href="https://getsmokin.nl/coffeeshop/<?=$shopSlug->_value?>#newreview" target="blank">schrijf een review</a>
267 </div>
268 <div class="rating-main-div gsr_reviews_background gsreviewswrapper<?=$randId?>">
269 <?php foreach($get_reviews as $review){ ?>
270 <div class="getsmokin-comment">
271 <div class="getsmokin-comment-inner">
272 <div class="getsmokin-comment-header">
273 <span class="getsmokin-comment-author"><?=$review->name?></span>
274 <span class="getsmokin-comment-date"><?=date('d F Y', strtotime($review->date))?></span>
275 </div>
276
277 <div class="getsmokin-comment-rating">
278 <div class="getsmokin-comment-stars">
279 <?php
280 for($stars=0; $stars<5; $stars++){
281 if($review->rating > $stars){
282 echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 55.867 55.867" style="enable-background:new 0 0 55.867 55.867;" xml:space="preserve" width="24px" height="24px"><path d="M55.818,21.578c-0.118-0.362-0.431-0.626-0.808-0.681L36.92,18.268L28.83,1.876c-0.168-0.342-0.516-0.558-0.896-0.558 s-0.729,0.216-0.896,0.558l-8.091,16.393l-18.09,2.629c-0.377,0.055-0.689,0.318-0.808,0.681c-0.117,0.361-0.02,0.759,0.253,1.024 l13.091,12.76l-3.091,18.018c-0.064,0.375,0.09,0.754,0.397,0.978c0.309,0.226,0.718,0.255,1.053,0.076l16.182-8.506l16.18,8.506 c0.146,0.077,0.307,0.115,0.466,0.115c0.207,0,0.413-0.064,0.588-0.191c0.308-0.224,0.462-0.603,0.397-0.978l-3.09-18.017 l13.091-12.761C55.838,22.336,55.936,21.939,55.818,21.578z" fill="#53a500"/><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g></svg>';
283 }else{
284 echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 55.867 55.867" style="enable-background:new 0 0 55.867 55.867;" xml:space="preserve" width="24px" height="24px"> <path d="M11.287,54.548c-0.207,0-0.414-0.064-0.588-0.191c-0.308-0.224-0.462-0.603-0.397-0.978l3.091-18.018L0.302,22.602 c-0.272-0.266-0.37-0.663-0.253-1.024c0.118-0.362,0.431-0.626,0.808-0.681l18.09-2.629l8.091-16.393 c0.168-0.342,0.516-0.558,0.896-0.558l0,0c0.381,0,0.729,0.216,0.896,0.558l8.09,16.393l18.091,2.629 c0.377,0.055,0.689,0.318,0.808,0.681c0.117,0.361,0.02,0.759-0.253,1.024L42.475,35.363l3.09,18.017 c0.064,0.375-0.09,0.754-0.397,0.978c-0.308,0.226-0.717,0.255-1.054,0.076l-16.18-8.506l-16.182,8.506 C11.606,54.51,11.446,54.548,11.287,54.548z M3.149,22.584l12.016,11.713c0.235,0.229,0.343,0.561,0.287,0.885L12.615,51.72 l14.854-7.808c0.291-0.154,0.638-0.154,0.931,0l14.852,7.808l-2.836-16.538c-0.056-0.324,0.052-0.655,0.287-0.885l12.016-11.713 l-16.605-2.413c-0.326-0.047-0.607-0.252-0.753-0.547L27.934,4.578l-7.427,15.047c-0.146,0.295-0.427,0.5-0.753,0.547L3.149,22.584z " fill="#53a500"/> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> </svg>';
285 }
286 }
287 ?>
288 </div>
289 </div>
290
291 <p class="getsmokin-comment-text">
292 <?=mb_strimwidth($review->review, 0, 200, "...");?>
293 </p>
294
295 </div>
296 </div>
297 <?php } ?>
298 </div>
299 <p class="getsmokin-credits">
300 Bekijk alle reviews op <a rel="noopener" href="https://getsmokin.nl/coffeeshop/<?=$shopSlug->_value?>" target="blank"><span>GetSmokin</span>.nl</a>
301 </p>
302 </div>
303
304 <script src="<?=plugin_dir_url( __FILE__ )?>assets/js/tinyslider.js"></script>
305
306
307 <script>
308 var gsReviewsSlider = tns({
309 container: '.gsreviewswrapper<?=$randId?>',
310 autoplay: true,
311 controlsPosition: 'top',
312 autoHeight: false,
313 nav: false,
314 controlsText: ['', '']
315 });
316 </script>
317
318 <script>
319 jQuery( document ).ready(function($) {
320 $('#gscolorinput').change(function(){
321 var newColor = $('#gscolorinput').val();
322 $('.getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:hover, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:focus').css('color', newColor).css('border', '1px solid '+newColor);
323
324
325 $('body').append("<style>.getsmokin-wrapper .tns-outer [aria-controls]:hover:before, .getsmokin-wrapper .tns-outer [aria-controls]:hover:after, .getsmokin-wrapper .tns-outer [aria-controls]:focus:before, .getsmokin-wrapper .tns-outer [aria-controls]:focus:after {background:"+newColor+";}</style>");
326
327
328 $('.getsmokin-comment-stars svg path').css('fill', newColor);
329 });
330
331 $('#getsmokin_titlecolor').change(function(){
332 var newColor = $('#getsmokin_titlecolor').val();
333 $('.getsmokin-reviews-heading').css('color', newColor);
334 });
335
336 });
337
338 </script>
339
340 </div>
341 </div>
342 <?php }else{ ?>
343
344 <style>
345 .zpt-title {
346 background-color: #53a500;
347 }
348 button.btn.btn-primary.margin-btm.search_for_biz {
349 background-color: #53a500;
350 border-color: #53a500;
351 margin-top: 30px;
352 }
353 #getsmokin-instructies {
354 margin: 0 auto 30px auto;
355 font-size: 15px;
356 color: #000;
357 max-width: 90%;
358 }
359
360 </style>
361
362 <div class="parent-div">
363
364 <div class="col-xs-12 zpt-pad-0 form-group">
365 <label class="zpt-title">Instellen</label>
366 </div>
367 <div class="col-xs-12 zpt-pad-t-b-20">
368 <p id="getsmokin-instructies">Zoek uw coffeeshop op naam en selecteer de juiste coffeeshop:</p>
369 <div class="zpt-input-wrapper">
370 <div class="form-group zpt-inp-search-box">
371 <input class="form-control form-group" type="text" placeholder="Voer naam coffeeshop in" id="gsr_biz_name" name="biz_name" value="<?=isset($saved_creds->user_name) ? $saved_creds->user_name : ''; ?>" autocomplete="off">
372 <img src="<?=plugin_dir_url( __FILE__ );?>assets/icons/loader.svg" class="zpt-inp-loader hidden">
373 <input type="hidden" id="searched_biz_id" class="hidden" value="">
374 <div class="col-xs-12 autocomplete-div">
375 <div class="autocomplete-items hidden">
376 </div>
377 </div>
378 <p id="gsr_length_error" class="error_div hidden"></p>
379 </div>
380 <button class="btn btn-success margin-btm search_for_biz" type="button" name="save_creds">Zoek coffeeshop</button>
381 <form method="post" id="gsr_save_biz_form">
382 <input type="hidden" name="place-id" id="gsr_searched_id">
383 <input type="hidden" name="place-name" id="gsr_searched_name">
384 <input type="hidden" class="hidden" name="save_business_id" value="gsr-zpt">
385 </form>
386 </div>
387 </div>
388 </div>
389 <?php } ?>
390</div>
391<script>
392 jQuery( document ).ready(function($) {
393 $('[data-toggle="tooltip"]').tooltip();
394
395 $('.gsr_colorpicker').colorpicker();
396
397 $(document).on('click','.search_for_biz', function(){
398 __zpt_search_biz();
399 });
400
401 $(document).on('keyup','#gsr_biz_name', function(){
402 __zpt_search_biz();
403 });
404
405 function __zpt_search_biz(){
406 $('#gsr_length_error').addClass('hidden');
407 var biz_name = $('#gsr_biz_name').val();
408 if(biz_name && biz_name.length > 2 && biz_name.length < 20 ){
409 $('.search_for_biz').attr('disabled','disabled');
410 $('.zpt-inp-loader').removeClass('hidden');
411 $.ajax({
412 'url': 'https://getsmokin.nl/reviewsapi/getcoffeeshopid',
413 'type':'post',
414 'data':{
415 'search':biz_name,
416 },
417 success: function (_x) {
418 $('.search_for_biz').removeAttr('disabled');
419 if(_x !== undefined && _x !== null){
420 var __html = '';
421 $.each(_x, function( index, value ) {
422 __html += '<div class="biz-found" data-place-id="'+value.id+'">'+value.title+' <em>'+value.city+'</em></div>';
423 });
424 $('.autocomplete-items').removeClass('hidden');
425 $('.autocomplete-items').html(__html);
426 }else{
427 $('.autocomplete-items').addClass('hidden');
428 $('.autocomplete-items').html('');
429 }
430 $('.zpt-inp-loader').addClass('hidden');
431 },
432 });
433 }else{
434 $('#gsr_length_error').removeClass('hidden');
435 $('#gsr_length_error').html('Name length must be greater then 2 and less then 20 characters');
436 $('.autocomplete-items').addClass('hidden');
437 $('.autocomplete-items').html('');
438 $('.zpt-inp-loader').addClass('hidden');
439 }
440 }
441
442 $(document).on('click','#gsr_biz_name', function(){
443 $('#gsr_length_error').addClass('hidden');
444 });
445
446 $(document).on('keyup','#gsr_biz_name', function(){
447 var biz_name = $('#gsr_biz_name').val();
448 if(biz_name && biz_name.length < 3 ){
449 $('.autocomplete-items').addClass('hidden');
450 $('.autocomplete-items').html('');
451 }
452 });
453
454 $(document).on('click','.biz-found',function(){
455 $('#gsr_searched_name').val($(this).html());
456 $('#gsr_searched_id').val($(this).data('place-id'));
457 $('.autocomplete-items').addClass('hidden');
458 $('#gsr_save_biz_form').submit();
459 });
460 });
461</script>
462<?php
463}
464
465
466function zpt_gsr_4_cron_schedule( $schedules ) {
467 global $wpdb;
468 $cron_query = $wpdb->get_results( "SELECT * FROM ".gsr_config." WHERE _type = 'cron_time' LIMIT 1");
469 $cron_query = $cron_query[0];
470 if($cron_query && !empty($cron_query)){
471 $cron_time = (int)$cron_query->_value;
472 if(trim($cron_time) != ''){
473 $cron_time = $cron_time * 2600;
474 }else{
475 $cron_time = 3600;
476 }
477 $schedules['_cron_time_'] = array(
478 'interval' => $cron_time,
479 'display' => __( 'Every '.$cron_query->_value.' hour' ),
480 );
481
482 }else{
483 $schedules['_cron_time_'] = array(
484 'interval' => 60,
485 'display' => __( 'Every 1 hour' ),
486 );
487 }
488 return $schedules;
489}
490
491add_filter( 'cron_schedules', 'zpt_gsr_4_cron_schedule' );
492
493if (! wp_next_scheduled ( 'zpt_gsr_cron_event' )) {
494
495 wp_schedule_event(time(), _cron_time_, 'zpt_gsr_cron_event');
496}
497add_action('zpt_gsr_cron_event', 'zpt_gsr_cron_run', 10);
498
499function zpt_gsr_cron_run(){
500 global $wpdb,$zpt_message;
501 $log = '----------------------------------------------------------'.PHP_EOL.'
502 CRON RUNNING AT(server time): '.date('Y-m-d h:i:s A').PHP_EOL;
503 file_put_contents(plugin_dir_path( __FILE__ ).'logs/cron_job_'.date("d-m-Y").'.txt', $log, FILE_APPEND);
504 $log = '';
505 $saved_creds = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type = 'business_id' LIMIT 1");
506 $saved_creds = $saved_creds[0];
507 if($saved_creds && !empty($saved_creds)){
508 $ch = curl_init("https://getsmokin.nl/reviewsapi/getcoffeeshopreviews?coffeeshopid=".$saved_creds->_value);
509 curl_setopt($ch, CURLOPT_HEADER, 0);
510 curl_setopt($ch, CURLOPT_POST, 0);
511 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
512 $response = json_decode(curl_exec($ch),true);
513 if(isset($response['success']) && trim($response['success']) == '1'){
514 $check_review_entry = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type = 'review_details' LIMIT 1");
515 if($check_review_entry && !empty($check_review_entry)){
516 $wpdb->query("UPDATE ".gsr_config." SET _value = '".$response['averageRating']."', _value2 = '".$response['ratingPerc']."', last_update = '".date('Y-m-d h:i:s')."' WHERE _type = 'review_details' LIMIT 1");
517 }else{
518 $wpdb->query("INSERT INTO ".gsr_config." SET _value = '".$response['averageRating']."', _value2 = '".$response['ratingPerc']."', last_update = '".date('Y-m-d h:i:s')."', _type = 'review_details'");
519 }
520 if($response['reviews'] && !empty($response['reviews'])){
521 $wpdb->query("TRUNCATE TABLE ".gsr_ratings);
522 $total_reviews = 0;
523 foreach($response['reviews'] as $this_review){
524 $wpdb->query("INSERT INTO ".gsr_ratings." SET rating = '".$this_review['rating']."', name = '".esc_sql($this_review['name'])."', review = '".esc_sql($this_review['review'])."', date = '".date('Y-m-d',strtotime($this_review['date']))."'");
525 $total_reviews++;
526 }
527 $log = ' Gelukt! '.$total_reviews.' Reviews opgeslagen'.PHP_EOL;
528 $zpt_message['type'] = 'success';
529 $zpt_message['mcg'] = $total_reviews.' reviews opgeslagen';
530 }else{
531 $zpt_message['type'] = 'info';
532 $log = ' No review found'.PHP_EOL;
533 $zpt_message['mcg'] = ' Geen reviews gevonden'.PHP_EOL;
534 }
535 }else{
536 $zpt_message['type'] = 'failure';
537 if(isset($response['error']) && trim($response['error']) != ''){
538 $log = ' ERROR! '.$response['error'].PHP_EOL;
539 $zpt_message['mcg'] = ' ERROR! '.$response['error'].PHP_EOL;
540
541 }else{
542 $log = ' An unknown error has occured'.PHP_EOL;
543 $zpt_message['mcg'] = ' An unknown error has occured'.PHP_EOL;
544 }
545 }
546 curl_close($ch);
547
548 }
549 file_put_contents(plugin_dir_path( __FILE__ ).'logs/cron_job_'.date("d-m-Y").'.txt', $log, FILE_APPEND);
550 $log = '';
551}
552
553add_shortcode('gsr_show_reviews', 'reviews_shortcode');
554//function here to use ob
555function reviews_shortcode(){
556 global $wpdb;
557 $get_reviews = $wpdb->get_results("SELECT * FROM ".gsr_ratings);
558 $user_settings = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type != 'business_id' ");
559 if($user_settings && !empty($user_settings)){
560 foreach($user_settings as $setting){
561 ${$setting->_type} = $setting->_value;
562 }
563 }
564
565 if($get_reviews && !empty($get_reviews) && (is_front_page() || is_singular() || is_archive())){ ?>
566
567 <?php ob_start(); ?>
568
569 <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600" rel="stylesheet">
570
571 <style>
572 <?php include(plugin_dir_path( __FILE__ ).'assets/css/GetSmokin.css'); ?>
573
574 <?php if($main_background_color){ ?>
575 .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:hover, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:focus {
576 color: <?=$main_background_color ?>;
577 border: 1px solid <?=$main_background_color ?>;
578 }
579 .tns-outer [aria-controls]:hover:before, .tns-outer [aria-controls]:hover:after, .tns-outer [aria-controls]:focus:before, .tns-outer [aria-controls]:focus:after {
580 background: <?=$main_background_color ?>;
581 }
582 .getsmokin-comment-stars svg path{
583 fill: <?=$main_background_color ?>;
584 }
585 <?php } ?>
586
587 <?php if($title_background_color){ ?>
588 .getsmokin-reviews-heading {
589 color: <?=$title_background_color ?>;
590 }
591 <?php } ?>
592 </style>
593
594 <link rel="stylesheet" href="<?=plugin_dir_url( __FILE__ )?>assets/css/tinyslider.css">
595 <!--[if (lt IE 9)]><script src="href="<?=plugin_dir_url( __FILE__ )?>assets/js/tinyslider-ie8fix.js""></script><![endif]-->
596
597
598 <?php
599 $randId = rand();
600 $shopSlug = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type = 'business_id' LIMIT 1");
601 $shopSlug = $shopSlug[0];
602 ?>
603
604 <div class="getsmokin-wrapper">
605 <div class="getsmokin-reviews-header">
606 <div>
607 <h3 class="getsmokin-reviews-heading"><?=count($get_reviews)?> reviews</h3>
608 </div>
609 <a class="getsmokin-reviews-button" rel="noopener" href="https://getsmokin.nl/coffeeshop/<?=$shopSlug->_value?>#newreview" target="blank">schrijf een review</a>
610 </div>
611 <div class="rating-main-div gsr_reviews_background gsreviewswrapper<?=$randId?>">
612 <?php foreach($get_reviews as $review){ ?>
613 <div class="getsmokin-comment">
614 <div class="getsmokin-comment-inner">
615 <div class="getsmokin-comment-header">
616 <span class="getsmokin-comment-author"><?=$review->name?></span>
617 <span class="getsmokin-comment-date"><?=date('d F Y', strtotime($review->date))?></span>
618 </div>
619
620 <div class="getsmokin-comment-rating">
621 <div class="getsmokin-comment-stars">
622 <?php
623 for($stars=0; $stars<5; $stars++){
624 if($review->rating > $stars){
625 echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 55.867 55.867" style="enable-background:new 0 0 55.867 55.867;" xml:space="preserve" width="24px" height="24px"><path d="M55.818,21.578c-0.118-0.362-0.431-0.626-0.808-0.681L36.92,18.268L28.83,1.876c-0.168-0.342-0.516-0.558-0.896-0.558 s-0.729,0.216-0.896,0.558l-8.091,16.393l-18.09,2.629c-0.377,0.055-0.689,0.318-0.808,0.681c-0.117,0.361-0.02,0.759,0.253,1.024 l13.091,12.76l-3.091,18.018c-0.064,0.375,0.09,0.754,0.397,0.978c0.309,0.226,0.718,0.255,1.053,0.076l16.182-8.506l16.18,8.506 c0.146,0.077,0.307,0.115,0.466,0.115c0.207,0,0.413-0.064,0.588-0.191c0.308-0.224,0.462-0.603,0.397-0.978l-3.09-18.017 l13.091-12.761C55.838,22.336,55.936,21.939,55.818,21.578z" fill="#53a500"/><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g></svg>';
626 }else{
627 echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 55.867 55.867" style="enable-background:new 0 0 55.867 55.867;" xml:space="preserve" width="24px" height="24px"> <path d="M11.287,54.548c-0.207,0-0.414-0.064-0.588-0.191c-0.308-0.224-0.462-0.603-0.397-0.978l3.091-18.018L0.302,22.602 c-0.272-0.266-0.37-0.663-0.253-1.024c0.118-0.362,0.431-0.626,0.808-0.681l18.09-2.629l8.091-16.393 c0.168-0.342,0.516-0.558,0.896-0.558l0,0c0.381,0,0.729,0.216,0.896,0.558l8.09,16.393l18.091,2.629 c0.377,0.055,0.689,0.318,0.808,0.681c0.117,0.361,0.02,0.759-0.253,1.024L42.475,35.363l3.09,18.017 c0.064,0.375-0.09,0.754-0.397,0.978c-0.308,0.226-0.717,0.255-1.054,0.076l-16.18-8.506l-16.182,8.506 C11.606,54.51,11.446,54.548,11.287,54.548z M3.149,22.584l12.016,11.713c0.235,0.229,0.343,0.561,0.287,0.885L12.615,51.72 l14.854-7.808c0.291-0.154,0.638-0.154,0.931,0l14.852,7.808l-2.836-16.538c-0.056-0.324,0.052-0.655,0.287-0.885l12.016-11.713 l-16.605-2.413c-0.326-0.047-0.607-0.252-0.753-0.547L27.934,4.578l-7.427,15.047c-0.146,0.295-0.427,0.5-0.753,0.547L3.149,22.584z " fill="#53a500"/> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> </svg>';
628 }
629 }
630 ?>
631 </div>
632 </div>
633
634 <p class="getsmokin-comment-text">
635 <?=mb_strimwidth($review->review, 0, 200, "...");?>
636 </p>
637
638 </div>
639 </div>
640 <?php } ?>
641 </div>
642 <p class="getsmokin-credits">
643 Bekijk alle reviews op <a rel="noopener" href="https://getsmokin.nl/coffeeshop/<?=$shopSlug->_value?>" target="blank"><span>GetSmokin</span>.nl</a>
644 </p>
645 </div>
646
647 <script src="<?=plugin_dir_url( __FILE__ )?>assets/js/tinyslider.js"></script>
648
649
650 <script>
651 var gsReviewsSlider = tns({
652 container: '.gsreviewswrapper<?=$randId?>',
653 autoplay: true,
654 controlsPosition: 'top',
655 autoHeight: false,
656 nav: false,
657 controlsText: ['', '']
658 });
659 </script>
660
661
662 <?php
663 return ob_get_clean();
664 }
665}
666
667// The widget class
668class gsr_widgets extends WP_Widget {
669
670 // Main constructor
671 public function __construct() {
672 parent::__construct(
673 'gsr_reviews_widget', // Base ID
674 esc_html__( 'GetSmokin Reviews Widget', 'text_domain' ), // Name
675 array( 'description' => esc_html__( 'Display all your "GetSmokin Reviews" anywhere in your website', 'text_domain' ), ) // Args
676 );
677 }
678
679 /**
680 * Front-end display of widget.
681 *
682 * @see WP_Widget::widget()
683 *
684 * @param array $args Widget arguments.
685 * @param array $instance Saved values from database.
686 */
687 public function widget( $args, $instance ) {
688 echo $args['before_widget'];
689 if ( ! empty( $instance['title'] ) ) {
690 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
691 }
692 gsr_get_review();
693 echo $args['after_widget'];
694 }
695
696 /**
697 * Back-end widget form.
698 *
699 * @see WP_Widget::form()
700 *
701 * @param array $instance Previously saved values from database.
702 */
703 public function form( $instance ) {
704 $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'GetSmokin Reviews', 'text_domain' );
705 ?>
706 <p>
707 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'text_domain' ); ?></label>
708 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
709 </p>
710 <?php
711 }
712
713 /**
714 * Sanitize widget form values as they are saved.
715 *
716 * @see WP_Widget::update()
717 *
718 * @param array $new_instance Values just sent to be saved.
719 * @param array $old_instance Previously saved values from database.
720 *
721 * @return array Updated safe values to be saved.
722 */
723 public function update( $new_instance, $old_instance ) {
724 $instance = array();
725 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
726
727 return $instance;
728 }
729
730}
731
732// Register the widget
733function gsr_reviews_widget() {
734 register_widget( 'gsr_widgets' );
735}
736add_action( 'widgets_init', 'gsr_reviews_widget');
737
738
739//only for widget
740function gsr_get_review(){
741
742 global $wpdb;
743 $get_reviews = $wpdb->get_results("SELECT * FROM ".gsr_ratings);
744 $user_settings = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type != 'business_id' ");
745 if($user_settings && !empty($user_settings)){
746 foreach($user_settings as $setting){
747 ${$setting->_type} = $setting->_value;
748 }
749 }
750
751 if($get_reviews && !empty($get_reviews) && (is_front_page() || is_singular() || is_archive())){ ?>
752
753
754 <style>
755 <?php include(plugin_dir_path( __FILE__ ).'assets/css/GetSmokin.css'); ?>
756
757 <?php if($main_background_color){ ?>
758 .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:hover, .getsmokin-wrapper .getsmokin-reviews-header a.getsmokin-reviews-button:focus {
759 color: <?=$main_background_color ?>;
760 border: 1px solid <?=$main_background_color ?>;
761 }
762 .tns-outer [aria-controls]:hover:before, .tns-outer [aria-controls]:hover:after, .tns-outer [aria-controls]:focus:before, .tns-outer [aria-controls]:focus:after {
763 background: <?=$main_background_color ?>;
764 }
765 .getsmokin-comment-stars svg path{
766 fill: <?=$main_background_color ?>;
767 }
768 <?php } ?>
769 </style>
770
771 <link rel="stylesheet" href="<?=plugin_dir_url( __FILE__ )?>assets/css/tinyslider.css">
772 <!--[if (lt IE 9)]><script src="href="<?=plugin_dir_url( __FILE__ )?>assets/js/tinyslider-ie8fix.js""></script><![endif]-->
773
774
775 <?php
776 $randId = rand();
777 $shopSlug = $wpdb->get_results("SELECT * FROM ".gsr_config." WHERE _type = 'business_id' LIMIT 1");
778 $shopSlug = $shopSlug[0]
779 ?>
780
781 <div class="getsmokin-wrapper nomargin">
782 <div class="rating-main-div gsr_reviews_background gsreviewswrapper<?=$randId?>">
783 <?php foreach($get_reviews as $review){ ?>
784 <div class="getsmokin-comment">
785 <div class="getsmokin-comment-inner">
786 <div class="getsmokin-comment-header">
787 <span class="getsmokin-comment-author"><?=$review->name?></span>
788 <span class="getsmokin-comment-date"><?=date('d F Y', strtotime($review->date))?></span>
789 </div>
790
791 <div class="getsmokin-comment-rating">
792 <div class="getsmokin-comment-stars">
793 <?php
794 for($stars=0; $stars<5; $stars++){
795 if($review->rating > $stars){
796 echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 55.867 55.867" style="enable-background:new 0 0 55.867 55.867;" xml:space="preserve" width="24px" height="24px"><path d="M55.818,21.578c-0.118-0.362-0.431-0.626-0.808-0.681L36.92,18.268L28.83,1.876c-0.168-0.342-0.516-0.558-0.896-0.558 s-0.729,0.216-0.896,0.558l-8.091,16.393l-18.09,2.629c-0.377,0.055-0.689,0.318-0.808,0.681c-0.117,0.361-0.02,0.759,0.253,1.024 l13.091,12.76l-3.091,18.018c-0.064,0.375,0.09,0.754,0.397,0.978c0.309,0.226,0.718,0.255,1.053,0.076l16.182-8.506l16.18,8.506 c0.146,0.077,0.307,0.115,0.466,0.115c0.207,0,0.413-0.064,0.588-0.191c0.308-0.224,0.462-0.603,0.397-0.978l-3.09-18.017 l13.091-12.761C55.838,22.336,55.936,21.939,55.818,21.578z" fill="#53a500"/><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g></svg>';
797 }else{
798 echo '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 55.867 55.867" style="enable-background:new 0 0 55.867 55.867;" xml:space="preserve" width="24px" height="24px"> <path d="M11.287,54.548c-0.207,0-0.414-0.064-0.588-0.191c-0.308-0.224-0.462-0.603-0.397-0.978l3.091-18.018L0.302,22.602 c-0.272-0.266-0.37-0.663-0.253-1.024c0.118-0.362,0.431-0.626,0.808-0.681l18.09-2.629l8.091-16.393 c0.168-0.342,0.516-0.558,0.896-0.558l0,0c0.381,0,0.729,0.216,0.896,0.558l8.09,16.393l18.091,2.629 c0.377,0.055,0.689,0.318,0.808,0.681c0.117,0.361,0.02,0.759-0.253,1.024L42.475,35.363l3.09,18.017 c0.064,0.375-0.09,0.754-0.397,0.978c-0.308,0.226-0.717,0.255-1.054,0.076l-16.18-8.506l-16.182,8.506 C11.606,54.51,11.446,54.548,11.287,54.548z M3.149,22.584l12.016,11.713c0.235,0.229,0.343,0.561,0.287,0.885L12.615,51.72 l14.854-7.808c0.291-0.154,0.638-0.154,0.931,0l14.852,7.808l-2.836-16.538c-0.056-0.324,0.052-0.655,0.287-0.885l12.016-11.713 l-16.605-2.413c-0.326-0.047-0.607-0.252-0.753-0.547L27.934,4.578l-7.427,15.047c-0.146,0.295-0.427,0.5-0.753,0.547L3.149,22.584z " fill="#53a500"/> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> </svg>';
799 }
800 }
801 ?>
802 </div>
803 </div>
804
805 <p class="getsmokin-comment-text">
806 <?=mb_strimwidth($review->review, 0, 100, "(...)");?>
807 </p>
808
809 </div>
810 </div>
811 <?php } ?>
812 </div>
813 <p class="getsmokin-credits">
814 Bekijk alle reviews op <a rel="noopener" href="https://getsmokin.nl/coffeeshop/<?=$shopSlug->_value?>" target="blank"><span>GetSmokin</span>.nl</a>
815 </p>
816 </div>
817
818 <script src="<?=plugin_dir_url( __FILE__ )?>assets/js/tinyslider.js"></script>
819
820
821 <script>
822 var gsReviewsSlider = tns({
823 container: '.gsreviewswrapper<?=$randId?>',
824 autoplay: true,
825 controlsPosition: 'top',
826 autoHeight: false,
827 nav: false,
828 controlsText: ['', '']
829 });
830 </script>
831
832
833 <?php
834
835 }
836
837}
838### DEPENDENCIES -------------------------
839# _functions.php
840# @assets/icons/...
841# @assets/images/...