PluginProbe ʕ •ᴥ•ʔ
Rich Showcase for Google Reviews / 3.1
Rich Showcase for Google Reviews v3.1
6.9.9 6.9.8 6.9.7 6.9.6 trunk 1.4 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.5 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.7 1.6.8 1.6.9 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.4 2.4.1 2.4.2 2.5 2.5.1 2.6 2.6.1 2.6.2 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.6.1 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.8.1 4.8.2 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.7.1 5.8 5.9 5.9.1 5.9.2 5.9.3 5.9.7 6.0 6.1 6.2 6.3 6.4 6.4.1 6.5 6.6 6.6.1 6.6.2 6.7 6.8 6.8.1 6.8.2 6.9 6.9.1 6.9.2 6.9.3 6.9.4 6.9.4.1 6.9.4.2 6.9.4.3 6.9.4.4 6.9.5
widget-google-reviews / assets / src / js / admin-builder.js
widget-google-reviews / assets / src / js Last commit date
admin-apexcharts.js 3 years ago admin-builder.js 2 years ago admin-main.js 2 years ago public-blazy.min.js 4 years ago public-main.js 2 years ago public-time.js 3 years ago
admin-builder.js
947 lines
1 const GRW_AUTOSAVE_KEYUP_TIMEOUT = 1500;
2 var GRW_AUTOSAVE_TIMEOUT = null;
3
4 const GRW_LANGS = [
5 ['ar', 'Arabic'],
6 ['bg', 'Bulgarian'],
7 ['bn', 'Bengali'],
8 ['ca', 'Catalan'],
9 ['cs', 'Czech'],
10 ['da', 'Danish'],
11 ['de', 'German'],
12 ['el', 'Greek'],
13 ['en', 'English'],
14 ['es', 'Spanish'],
15 ['eu', 'Basque'],
16 ['eu', 'Basque'],
17 ['fa', 'Farsi'],
18 ['fi', 'Finnish'],
19 ['fil', 'Filipino'],
20 ['fr', 'French'],
21 ['gl', 'Galician'],
22 ['gu', 'Gujarati'],
23 ['hi', 'Hindi'],
24 ['hr', 'Croatian'],
25 ['hu', 'Hungarian'],
26 ['id', 'Indonesian'],
27 ['it', 'Italian'],
28 ['iw', 'Hebrew'],
29 ['ja', 'Japanese'],
30 ['kn', 'Kannada'],
31 ['ko', 'Korean'],
32 ['lt', 'Lithuanian'],
33 ['lv', 'Latvian'],
34 ['ml', 'Malayalam'],
35 ['mr', 'Marathi'],
36 ['nl', 'Dutch'],
37 ['no', 'Norwegian'],
38 ['pl', 'Polish'],
39 ['pt', 'Portuguese'],
40 ['pt-BR', 'Portuguese (Brazil)'],
41 ['pt-PT', 'Portuguese (Portugal)'],
42 ['ro', 'Romanian'],
43 ['ru', 'Russian'],
44 ['sk', 'Slovak'],
45 ['sl', 'Slovenian'],
46 ['sr', 'Serbian'],
47 ['sv', 'Swedish'],
48 ['ta', 'Tamil'],
49 ['te', 'Telugu'],
50 ['th', 'Thai'],
51 ['tl', 'Tagalog'],
52 ['tr', 'Turkish'],
53 ['uk', 'Ukrainian'],
54 ['vi', 'Vietnamese'],
55 ['zh', 'Chinese (Simplified)'],
56 ['zh-Hant', 'Chinese (Traditional)']
57 ];
58
59 var GRW_HTML_CONTENT = '' +
60
61 '<div class="grw-builder-platforms grw-builder-inside">' +
62
63 '<div class="grw-builder-connect grw-connect-google">Google Connection</div>' +
64 '<div id="grw-connect-wizard" title="Easy steps to connect Google Reviews" style="display:none;">' +
65 '<p>' +
66 '<span>1</span> ' +
67 'Find your Google place on the map below (<u class="grw-wiz-arr">Enter a location</u>) and copy found <u><b>Place ID</b></u>' +
68 '</p>' +
69 '<iframe src="https://geo-devrel-javascript-samples.web.app/samples/places-placeid-finder/app/dist" loading="lazy" style="width:100%;height:250px"></iframe>' +
70 '<small style="font-size:13px;color:#555">If you can\'t find your place on this map, please read <a href="' + GRW_VARS.supportUrl + '&grw_tab=fig#place_id" target="_blank">this manual how to find any Google Place ID</a>.</small>' +
71 '<p>' +
72 '<span>2</span> ' +
73 'Paste copied <u><b>Place ID</b></u> in this field and select language if needed' +
74 '</p>' +
75 '<p>' +
76 '<input type="text" class="grw-connect-id" value="" placeholder="Place ID" />' +
77 '<select class="grw-connect-lang"><option value="" selected="selected">Choose language if needed</option><option value="ar">Arabic</option><option value="bg">Bulgarian</option><option value="bn">Bengali</option><option value="ca">Catalan</option><option value="cs">Czech</option><option value="da">Danish</option><option value="de">German</option><option value="el">Greek</option><option value="en">English</option><option value="es">Spanish</option><option value="eu">Basque</option><option value="eu">Basque</option><option value="fa">Farsi</option><option value="fi">Finnish</option><option value="fil">Filipino</option><option value="fr">French</option><option value="gl">Galician</option><option value="gu">Gujarati</option><option value="hi">Hindi</option><option value="hr">Croatian</option><option value="hu">Hungarian</option><option value="id">Indonesian</option><option value="it">Italian</option><option value="iw">Hebrew</option><option value="ja">Japanese</option><option value="kn">Kannada</option><option value="ko">Korean</option><option value="lt">Lithuanian</option><option value="lv">Latvian</option><option value="ml">Malayalam</option><option value="mr">Marathi</option><option value="nl">Dutch</option><option value="no">Norwegian</option><option value="pl">Polish</option><option value="pt">Portuguese</option><option value="pt-BR">Portuguese (Brazil)</option><option value="pt-PT">Portuguese (Portugal)</option><option value="ro">Romanian</option><option value="ru">Russian</option><option value="sk">Slovak</option><option value="sl">Slovenian</option><option value="sr">Serbian</option><option value="sv">Swedish</option><option value="ta">Tamil</option><option value="te">Telugu</option><option value="th">Thai</option><option value="tl">Tagalog</option><option value="tr">Turkish</option><option value="uk">Ukrainian</option><option value="vi">Vietnamese</option><option value="zh">Chinese (Simplified)</option><option value="zh-Hant">Chinese (Traditional)</option></select>' +
78 '</p>' +
79 '<p><span>3</span> Click CONNECT GOOGLE button</p>' +
80 '<button class="grw-connect-btn">Connect Google</button>' +
81 '<small class="grw-connect-error"></small>' +
82 '</div>' +
83 '<div class="grw-connections"></div>' +
84 '</div>' +
85
86 '<div class="grw-connect-options">' +
87
88 '<div class="grw-builder-inside">' +
89
90 '<div class="grw-builder-option">' +
91 'Layout' +
92 '<select id="view_mode" name="view_mode">' +
93 '<option value="slider" selected="selected">Slider</option>' +
94 '<option value="grid">Grid</option>' +
95 '<option value="list">List</option>' +
96 '</select>' +
97 '</div>' +
98
99 '</div>' +
100
101 /* Common Options */
102 '<div class="grw-builder-top grw-toggle">Common Options</div>' +
103 '<div class="grw-builder-inside" style="display:none">' +
104 '<div class="grw-builder-option">' +
105 'Pagination' +
106 '<input type="text" name="pagination" value="">' +
107 '</div>' +
108 '<div class="grw-builder-option">' +
109 'Maximum characters before \'read more\' link' +
110 '<input type="text" name="text_size" value="">' +
111 '</div>' +
112 '<div class="grw-builder-option">' +
113 '<label>' +
114 '<input type="checkbox" name="header_center" value="">' +
115 'Show rating by center' +
116 '</label>' +
117 '</div>' +
118 '<div class="grw-builder-option">' +
119 '<label>' +
120 '<input type="checkbox" name="header_hide_photo" value="">' +
121 'Hide business photo' +
122 '</label>' +
123 '</div>' +
124 '<div class="grw-builder-option">' +
125 '<label>' +
126 '<input type="checkbox" name="header_hide_name" value="">' +
127 'Hide business name' +
128 '</label>' +
129 '</div>' +
130 '<div class="grw-builder-option">' +
131 '<label>' +
132 '<input type="checkbox" name="hide_based_on" value="">' +
133 'Hide \'Based on ... reviews\'' +
134 '</label>' +
135 '</div>' +
136 '<div class="grw-builder-option">' +
137 '<label>' +
138 '<input type="checkbox" name="hide_writereview" value="">' +
139 'Hide \'review us on G\' button' +
140 '</label>' +
141 '</div>' +
142 '<div class="grw-builder-option">' +
143 '<label>' +
144 '<input type="checkbox" name="header_hide_social" value="">' +
145 'Hide rating header, leave only reviews' +
146 '</label>' +
147 '</div>' +
148 '<div class="grw-builder-option">' +
149 '<label>' +
150 '<input type="checkbox" name="hide_reviews" value="">' +
151 'Hide reviews, leave only rating header' +
152 '</label>' +
153 '</div>' +
154 '</div>' +
155
156 /* Slider Options */
157 '<div class="grw-builder-top grw-toggle">Slider Options</div>' +
158 '<div class="grw-builder-inside" style="display:none">' +
159 '<div class="grw-builder-option">' +
160 'Speed in second' +
161 '<input type="text" name="slider_speed" value="" placeholder="Default: 5">' +
162 '</div>' +
163 '<div class="grw-builder-option">' +
164 'Text height' +
165 '<input type="text" name="slider_text_height" value="" placeholder="Default: 100px">' +
166 '</div>' +
167 '<div class="grw-builder-option">' +
168 '<label>' +
169 '<input type="checkbox" name="slider_autoplay" value="" checked>' +
170 'Auto-play' +
171 '</label>' +
172 '</div>' +
173 '<div class="grw-builder-option">' +
174 '<label>' +
175 '<input type="checkbox" name="slider_hide_prevnext" value="">' +
176 'Hide prev & next buttons' +
177 '</label>' +
178 '</div>' +
179 '<div class="grw-builder-option">' +
180 '<label>' +
181 '<input type="checkbox" name="slider_hide_dots" value="">' +
182 'Hide dots' +
183 '</label>' +
184 '</div>' +
185 '</div>' +
186
187 /* Style Options */
188 '<div class="grw-builder-top grw-toggle">Style Options</div>' +
189 '<div class="grw-builder-inside" style="display:none">' +
190 '<div class="grw-builder-option">' +
191 '<label>' +
192 '<input type="checkbox" name="dark_theme">' +
193 'Dark background' +
194 '</label>' +
195 '</div>' +
196 '<div class="grw-builder-option">' +
197 '<label>' +
198 '<input type="checkbox" name="hide_backgnd" value="">' +
199 'Hide reviews background' +
200 '</label>' +
201 '</div>' +
202 '<div class="grw-builder-option">' +
203 '<label>' +
204 '<input type="checkbox" name="show_round" value="">' +
205 'Round reviews borders' +
206 '</label>' +
207 '</div>' +
208 '<div class="grw-builder-option">' +
209 '<label>' +
210 '<input type="checkbox" name="show_shadow" value="">' +
211 'Show reviews shadow' +
212 '</label>' +
213 '</div>' +
214 '<div class="grw-builder-option">' +
215 '<label>' +
216 '<input type="checkbox" name="centered" value="">' +
217 'Place by center (only if max-width is set)' +
218 '</label>' +
219 '</div>' +
220 '<div class="grw-builder-option">' +
221 'Container max-width' +
222 '<input type="text" name="max_width" value="" placeholder="for instance: 300px">' +
223 '<small>Be careful: this will make reviews unresponsive</small>' +
224 '</div>' +
225 '<div class="grw-builder-option">' +
226 'Container max-height' +
227 '<input type="text" name="max_height" value="" placeholder="for instance: 500px">' +
228 '</div>' +
229 '</div>' +
230
231 /* Advance Options */
232 '<div class="grw-builder-top grw-toggle">Advance Options</div>' +
233 '<div class="grw-builder-inside" style="display:none">' +
234 '<div class="grw-builder-option">' +
235 '<label>' +
236 '<input type="checkbox" name="lazy_load_img" checked>' +
237 'Lazy load images' +
238 '</label>' +
239 '</div>' +
240 '<div class="grw-builder-option">' +
241 '<label>' +
242 '<input type="checkbox" name="google_def_rev_link">' +
243 'Use default Google reviews link' +
244 '</label>' +
245 '<span class="grw-quest grw-quest-top grw-toggle" title="Click to help">?</span>' +
246 '<div class="grw-quest-help" style="display:none;">If the direct link to all reviews <b>https://search.google.com/local/reviews?placeid=&lt;PLACE_ID&gt;</b> does not work with your Google place (leads to 404), please use this option to use the default reviews link to Google map.</div>' +
247 '</div>' +
248 '<div class="grw-builder-option">' +
249 '<label>' +
250 '<input type="checkbox" name="open_link" checked>' +
251 'Open links in new Window' +
252 '</label>' +
253 '</div>' +
254 '<div class="grw-builder-option">' +
255 '<label>' +
256 '<input type="checkbox" name="nofollow_link" checked>' +
257 'Use no follow links' +
258 '</label>' +
259 '</div>' +
260 '<div class="grw-builder-option">' +
261 'Reviewer avatar size' +
262 '<select name="reviewer_avatar_size">' +
263 '<option value="56" selected="selected">Small: 56px</option>' +
264 '<option value="128">Medium: 128px</option>' +
265 '<option value="256">Large: 256px</option>' +
266 '</select>' +
267 '</div>' +
268 '<div class="grw-builder-option">' +
269 'Cache data' +
270 '<select name="cache">' +
271 '<option value="1">1 Hour</option>' +
272 '<option value="3">3 Hours</option>' +
273 '<option value="6">6 Hours</option>' +
274 '<option value="12" selected="selected">12 Hours</option>' +
275 '<option value="24">1 Day</option>' +
276 '<option value="48">2 Days</option>' +
277 '<option value="168">1 Week</option>' +
278 '<option value="">Disable (NOT recommended)</option>' +
279 '</select>' +
280 '</div>' +
281 '<div class="grw-builder-option">' +
282 'Reviews limit' +
283 '<input type="text" name="reviews_limit" value="">' +
284 '</div>' +
285 '</div>' +
286
287 '</div>';
288
289 function grw_builder_init($, data) {
290
291 var el = document.querySelector(data.el);
292 if (!el) return;
293
294 el.innerHTML = GRW_HTML_CONTENT;
295
296 var $connect_wizard_el = $('#grw-connect-wizard');
297 //connect_google_el = el.querySelector('.grw-connect-google-inside'),
298 //google_pid_el = el.querySelector('.grw-connect-id');
299
300 if (data.conns && data.conns.connections && data.conns.connections.length) {
301 grw_deserialize_connections($, el, data);
302 } else {
303 $('.grw-connect-google').hide();
304 $connect_wizard_el.dialog({
305 modal: true,
306 width: '50%',
307 maxWidth: '600px',
308 closeOnEscape: false,
309 open: function() { $(".ui-dialog-titlebar-close").hide() }
310 });
311 //connect_google_el.style = '';
312 //google_pid_el.focus();
313 }
314
315 // Google Connect
316 grw_connection($, /*connect_google_el*/$connect_wizard_el[0], 'google', data.authcode);
317
318 $('.grw-connect-options input[type="text"],.grw-connect-options textarea').keyup(function() {
319 clearTimeout(GRW_AUTOSAVE_TIMEOUT);
320 GRW_AUTOSAVE_TIMEOUT = setTimeout(grw_serialize_connections, GRW_AUTOSAVE_KEYUP_TIMEOUT);
321 });
322 $('.grw-connect-options input[type="checkbox"],.grw-connect-options select').change(function() {
323 grw_serialize_connections();
324 });
325
326 $('.grw-toggle', el).unbind('click').click(function () {
327 $(this).toggleClass('toggled');
328 $(this).next().slideToggle();
329 });
330
331 $('.grw-builder-connect.grw-connect-google').click(function () {
332 //google_pid_el.focus();
333 $connect_wizard_el.dialog({modal: true, width: '50%', maxWidth: '600px'});
334 });
335
336 if ($('.grw-connections').sortable) {
337 $('.grw-connections').sortable({
338 stop: function(event, ui) {
339 grw_serialize_connections();
340 }
341 });
342 $('.grw-connections').disableSelection();
343 }
344
345 $('.wp-review-hide').click(function() {
346 grw_review_hide($(this));
347 return false;
348 });
349
350 $('#grw_save').click(function() {
351 //grw_feed_save_ajax();
352 grw_serialize_connections();
353 return false;
354 });
355
356 window.addEventListener('beforeunload', function(e) {
357 if (!GRW_AUTOSAVE_TIMEOUT) return undefined;
358
359 var msg = 'It looks like you have been editing something. If you leave before saving, your changes will be lost.';
360 (e || window.event).returnValue = msg;
361 return msg;
362 });
363 }
364
365 function grw_feed_save_ajax() {
366 if (!window.grw_title.value) {
367 window.grw_title.focus();
368 return false;
369 }
370
371 window.grw_save.innerText = 'Auto save, wait';
372 window.grw_save.disabled = true;
373
374 jQuery.post(ajaxurl, {
375
376 post_id : window.grw_post_id.value,
377 title : window.grw_title.value,
378 content : document.getElementById('grw-builder-connection').value,
379 action : 'grw_feed_save_ajax',
380 grw_nonce : jQuery('#grw_nonce').val()
381
382 }, function(res) {
383
384 var wpgr = document.querySelectorAll('.wp-gr');
385 for (var i = 0; i < wpgr.length; i++) {
386 wpgr[i].parentNode.removeChild(wpgr[i]);
387 }
388
389 window.grw_collection_preview.innerHTML = res;
390
391 jQuery('.wp-review-hide').unbind('click').click(function() {
392 grw_review_hide(jQuery(this));
393 return false;
394 });
395
396 if (!window.grw_post_id.value) {
397 var post_id = document.querySelector('.wp-gr').getAttribute('data-id');
398 window.grw_post_id.value = post_id;
399 window.location.href = window.location.href + '&grw_feed_id=' + post_id + '&grw_feed_new=1';
400 } else {
401 var $rateus = jQuery('#grw-rate_us');
402 if ($rateus.length && !$rateus.hasClass('grw-flash-visible')) {
403 $rateus.addClass('grw-flash-visible');
404 }
405 }
406
407 window.grw_save.innerText = 'Save & Update';
408 window.grw_save.disabled = false;
409 GRW_AUTOSAVE_TIMEOUT = null;
410 });
411 }
412
413 function grw_feed_save() {
414 if (!window.grw_title.value) {
415 window.grw_title.focus();
416 return false;
417 }
418
419 var content = document.getElementById('grw-builder-connection').value;
420 if (content) {
421 var json = JSON.parse(content)
422 if (json) {
423 if (json.connections && json.connections.length) {
424 return true;
425 }
426 }
427 }
428
429 alert("Please click 'CONNECT GOOGLE' and connect your Google reviews then save this widget");
430 return false;
431 }
432
433 function grw_review_hide($this) {
434
435 jQuery.post(ajaxurl, {
436
437 id : $this.attr('data-id'),
438 feed_id : jQuery('input[name="grw_feed[post_id]"]').val(),
439 grw_wpnonce : jQuery('#grw_nonce').val(),
440 action : 'grw_hide_review'
441
442 }, function(res) {
443 var parent = $this.parent().parent();
444 if (res.hide) {
445 $this.text('show review');
446 parent.addClass('wp-review-hidden');
447 } else {
448 $this.text('hide review');
449 parent.removeClass('wp-review-hidden');
450 }
451 }, 'json');
452 }
453
454 function grw_connection($, el, platform, authcode) {
455 var connect_btn = el.querySelector('.grw-connect-btn');
456 $(connect_btn).click(function() {
457
458 var connect_id_el = el.querySelector('.grw-connect-id');
459 //connect_key_el = el.querySelector('.grw-connect-key');
460
461 if (!connect_id_el.value) {
462 connect_id_el.focus();
463 return false;
464 }/* else if (!connect_key_el.value) {
465 connect_key_el.focus();
466 return false;
467 }*/
468
469 var id = (platform == 'yelp' ? /.+\/biz\/(.*?)(\?|\/|$)/.exec(connect_id_el.value)[1] : connect_id_el.value),
470 lang = el.querySelector('.grw-connect-lang').value;
471 //key = connect_key_el.value;
472
473 connect_btn.innerHTML = 'Please wait...';
474 connect_btn.disabled = true;
475
476 grw_connect_ajax($, el, {id: id, lang: lang, platform: platform, local_img: true}, authcode, 1);
477 return false;
478 });
479 }
480
481 function grw_connect_ajax($, el, params, authcode, attempt) {
482
483 var platform = params.platform,
484 connect_btn = el.querySelector('.grw-connect-btn');
485
486 window.grw_save.innerText = 'Auto save, wait';
487 window.grw_save.disabled = true;
488
489 $.post(ajaxurl, {
490
491 id : decodeURIComponent(params.id),
492 lang : params.lang,
493 local_img : params.local_img,
494 feed_id : $('input[name="grw_feed[post_id]"]').val(),
495 grw_wpnonce : $('#grw_nonce').val(),
496 action : 'grw_connect_google',
497 v : new Date().getTime()
498
499 }, function(res) {
500
501 console.log('grw_connect_debug:', res);
502
503 connect_btn.innerHTML = 'Connect ' + (platform.charAt(0).toUpperCase() + platform.slice(1));
504 connect_btn.disabled = false;
505
506 var error_el = el.querySelector('.grw-connect-error');
507
508 if (res.status == 'success') {
509
510 error_el.innerHTML = '';
511
512 try { $('#grw-connect-wizard').dialog('close'); } catch (e) {}
513
514 var connection_params = {
515 id : res.result.id,
516 lang : params.lang,
517 name : res.result.name,
518 photo : res.result.photo,
519 refresh : true,
520 local_img : params.local_img,
521 platform : platform,
522 props : {
523 default_photo : res.result.photo
524 }
525 };
526
527 grw_connection_add($, el, connection_params, authcode);
528 grw_serialize_connections();
529
530 } else {
531
532 switch (res.result.error_message) {
533
534 case 'usage_limit':
535 $('#dialog').dialog({width: '50%', maxWidth: '600px'});
536 break;
537
538 case 'bot_check':
539 if (attempt > 1) {
540 return;
541 }
542 grw_popup('https://app.richplugins.com/gpaw/botcheck?authcode=' + authcode, 640, 480, function() {
543 grw_connect_ajax($, el, params, authcode, attempt + 1);
544 });
545 break;
546
547 default:
548 if (res.result.error_message.indexOf('The provided Place ID is no longer valid') >= 0) {
549 error_el.innerHTML = 'It seems Google place which you are trying to connect ' +
550 'does not have a physical address (it\'s virtual or service area), ' +
551 'unfortunately, Google Places API does not support such locations, it\'s a limitation of Google, not the plugin.<br><br>' +
552 'However, you can try to connect your Google reviews in our new cloud service ' +
553 '<a href="https://trust.reviews" target="_blank">Trust.Reviews</a> ' +
554 'and show it on your WordPress site through universal <b>HTML/JavaScript</b> code.';
555 } else {
556 error_el.innerHTML = '<b>Error</b>: ' + res.result.error_message;
557 }
558 }
559 }
560
561 }, 'json');
562 }
563
564 function grw_connection_add($, el, conn, authcode, checked) {
565
566 var connected_id = grw_connection_id(conn),
567 connected_el = $('#' + connected_id);
568
569 if (!connected_el.length) {
570 connected_el = $('<div class="grw-connection"></div>')[0];
571 connected_el.id = connected_id;
572 if (conn.lang != undefined) {
573 connected_el.setAttribute('data-lang', conn.lang);
574 }
575 connected_el.setAttribute('data-platform', conn.platform);
576 connected_el.innerHTML = grw_connection_render(conn, checked);
577
578 var connections_el = $('.grw-connections')[0];
579 connections_el.appendChild(connected_el);
580
581 jQuery('.grw-toggle', connected_el).unbind('click').click(function () {
582 jQuery(this).toggleClass('toggled');
583 jQuery(this).next().slideToggle();
584 });
585
586 var file_frame;
587 jQuery('.grw-connect-photo-change', connected_el).on('click', function(e) {
588 e.preventDefault();
589 grw_upload_photo(connected_el, file_frame, function() {
590 grw_serialize_connections();
591 });
592 return false;
593 });
594
595 jQuery('.grw-connect-photo-default', connected_el).on('click', function(e) {
596 grw_change_photo(connected_el, conn.props.default_photo);
597 grw_serialize_connections();
598 return false;
599 });
600
601 $('input[type="text"]', connected_el).keyup(function() {
602 clearTimeout(GRW_AUTOSAVE_TIMEOUT);
603 GRW_AUTOSAVE_TIMEOUT = setTimeout(grw_serialize_connections, GRW_AUTOSAVE_KEYUP_TIMEOUT);
604 });
605
606 $('input[type="checkbox"]', connected_el).click(function() {
607 grw_serialize_connections();
608 });
609
610 $('select.grw-connect-lang', connected_el).change(function() {
611 conn.lang = this.value;
612 connected_el.id = grw_connection_id(conn);
613 connected_el.setAttribute('data-lang', this.value);
614 grw_connect_ajax($, el, conn, authcode, 1);
615 return false;
616 });
617
618 $('input[name="local_img"]', connected_el).unbind('click').click(function() {
619 conn.local_img = this.checked;
620 grw_connect_ajax($, el, conn, authcode, 1);
621 });
622
623 $('.grw-connect-reconnect', connected_el).click(function() {
624 grw_connect_ajax($, el, conn, authcode, 1);
625 return false;
626 });
627
628 $('.grw-connect-delete', connected_el).click(function() {
629 if (confirm('Are you sure to delete this business?')) {
630 $(connected_el).remove();
631 grw_serialize_connections();
632 }
633 return false;
634 });
635 }
636 }
637
638 function grw_connection_id(conn) {
639 var id = 'grw-' + conn.platform + '-' + conn.id.replace(/\//g, '');
640 if (conn.lang != null) {
641 id += conn.lang;
642 }
643 return id;
644 }
645
646 function grw_connection_render(conn, checked) {
647 var name = conn.name;
648 if (conn.lang) {
649 name += ' (' + conn.lang + ')';
650 }
651
652 conn.photo = conn.photo || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
653
654 var option = document.createElement('option');
655 if (conn.platform == 'google' && conn.props && conn.props.place_id) {
656 option.value = conn.props.place_id;
657 } else {
658 option.value = conn.id;
659 }
660 option.text = grw_capitalize(conn.platform) + ': ' + conn.name;
661
662 return '' +
663 '<div class="grw-toggle grw-builder-connect grw-connect-business">' +
664 '<input type="checkbox" class="grw-connect-select" onclick="event.stopPropagation();" ' + (checked?'checked':'') + ' /> ' +
665 name + (conn.address ? ' (' + conn.address + ')' : '') +
666 '</div>' +
667 '<div style="display:none">' +
668 (function(props) {
669 var result = '';
670 for (prop in props) {
671 if (prop != 'platform' && Object.prototype.hasOwnProperty.call(props, prop)) {
672 result += '<input type="hidden" name="' + prop + '" value="' + props[prop] + '" class="grw-connect-prop" readonly />';
673 }
674 }
675 return result;
676 })(conn.props) +
677 '<input type="hidden" name="id" value="' + conn.id + '" readonly />' +
678 (conn.address ? '<input type="hidden" name="address" value="' + conn.address + '" readonly />' : '') +
679 (conn.access_token ? '<input type="hidden" name="access_token" value="' + conn.access_token + '" readonly />' : '') +
680 '<div class="grw-builder-option">' +
681 '<img src="' + conn.photo + '" alt="' + conn.name + '" class="grw-connect-photo">' +
682 '<a href="#" class="grw-connect-photo-change">Change</a>' +
683 '<a href="#" class="grw-connect-photo-default">Default</a>' +
684 '<input type="hidden" name="photo" class="grw-connect-photo-hidden" value="' + conn.photo + '" tabindex="2"/>' +
685 '</div>' +
686 '<div class="grw-builder-option">' +
687 '<input type="text" name="name" value="' + conn.name + '" />' +
688 '</div>' +
689 (conn.website != undefined ?
690 '<div class="grw-builder-option">' +
691 '<input type="text" name="website" value="' + conn.website + '" />' +
692 '</div>'
693 : '' ) +
694 (conn.lang != undefined ?
695 '<div class="grw-builder-option">' +
696 //'<input type="text" name="lang" value="' + conn.lang + '" placeholder="Default language (English)" />' +
697 grw_lang('Show all connected languages', conn.lang) +
698 '</div>'
699 : '' ) +
700 (conn.review_count != undefined ?
701 '<div class="grw-builder-option">' +
702 '<input type="text" name="review_count" value="' + conn.review_count + '" placeholder="Total number of reviews" />' +
703 '<span class="grw-quest grw-toggle" title="Click to help">?</span>' +
704 '<div class="grw-quest-help">Google return only 5 most helpful reviews and does not return information about total number of reviews and you can type here it manually.</div>' +
705 '</div>'
706 : '' ) +
707 (conn.refresh != undefined ?
708 '<div class="grw-builder-option">' +
709 '<label>' +
710 '<input type="checkbox" name="refresh" ' + (conn.refresh ? 'checked' : '') + '>' +
711 'Update reviews daily' +
712 '</label>' +
713 '<span class="grw-quest grw-quest-top grw-toggle" title="Click to help">?</span>' +
714 '<div class="grw-quest-help">' +
715 (conn.platform == 'google' ? 'The plugin uses the Google Places API to get your reviews. <b>The API only returns the 5 most helpful reviews (it\'s a limitation of Google, not the plugin)</b>. This option calls the Places API once in 24 hours (to keep the plugin\'s free and avoid a Google Billing) to check for a new reviews and if there are, adds to the plugin. Thus slowly building up a database of reviews.<br><br>Also if you see the new reviews on Google map, but after some time it\'s not added to the plugin, it means that Google does not include these reviews to the API and the plugin can\'t get this.<br><br>If you need to show <b>all reviews</b>, please use <a href="https://richplugins.com/business-reviews-bundle-wordpress-plugin?promo=GRGROW23" target="_blank">Business plugin</a> which uses a Google My Business API without API key and billing.' : '') +
716 (conn.platform == 'yelp' ? 'The plugin uses the Yelp API to get your reviews. <b>The API only returns the 3 most helpful reviews without sorting possibility.</b> When Yelp changes the 3 most helpful the plugin will automatically add the new one to your database. Thus slowly building up a database of reviews.' : '') +
717 '</div>' +
718 '</div>'
719 : '' ) +
720 '<div class="grw-builder-option">' +
721 '<label>' +
722 '<input type="checkbox" name="local_img" ' + (conn.local_img ? 'checked' : '') + '>' +
723 'Save images locally (GDPR)' +
724 '</label>' +
725 '</div>' +
726 '<div class="grw-builder-option">' +
727 '<button class="grw-connect-reconnect">Reconnect</button>' +
728 '</div>' +
729 '<div class="grw-builder-option">' +
730 '<button class="grw-connect-delete">Delete connection</button>' +
731 '</div>' +
732 '</div>';
733 }
734
735 function grw_serialize_connections() {
736
737 var connections = [],
738 connections_el = document.querySelectorAll('.grw-connection');
739
740 for (var i in connections_el) {
741 if (Object.prototype.hasOwnProperty.call(connections_el, i)) {
742
743 var select_el = connections_el[i].querySelector('.grw-connect-select');
744 if (select_el && !grw_is_hidden(select_el) && !select_el.checked) {
745 continue;
746 }
747
748 var connection = {},
749 lang = connections_el[i].getAttribute('data-lang'),
750 platform = connections_el[i].getAttribute('data-platform'),
751 inputs = connections_el[i].querySelectorAll('input');
752
753 //connections[platform] = connections[platform] || [];
754
755 if (lang != undefined) {
756 connection.lang = lang;
757 }
758
759 for (var j in inputs) {
760 if (Object.prototype.hasOwnProperty.call(inputs, j)) {
761 var input = inputs[j],
762 name = input.getAttribute('name');
763
764 if (!name) continue;
765
766 if (input.className == 'grw-connect-prop') {
767 connection.props = connection.props || {};
768 connection.props[name] = input.value;
769 } else {
770 connection[name] = (input.type == 'checkbox' ? input.checked : input.value);
771 }
772 }
773 }
774 connection.platform = platform;
775 connections.push(connection);
776 }
777 }
778
779 var options = {},
780 options_el = document.querySelector('.grw-connect-options').querySelectorAll('input[name],select,textarea');
781
782 for (var o in options_el) {
783 if (Object.prototype.hasOwnProperty.call(options_el, o)) {
784 var input = options_el[o],
785 name = input.getAttribute('name');
786
787 if (input.type == 'checkbox') {
788 options[name] = input.checked;
789 } else if (input.value != undefined) {
790 options[name] = (
791 input.type == 'textarea' ||
792 name == 'word_filter' ||
793 name == 'word_exclude' ?
794 encodeURIComponent(input.value) : input.value
795 );
796 }
797 }
798 }
799
800 document.getElementById('grw-builder-connection').value = JSON.stringify({connections: connections, options: options});
801
802 if (connections.length) {
803 var first = connections[0],
804 title = window.grw_title.value;
805
806 if (!title) {
807 window.grw_title.value = first.name;
808 }
809 grw_feed_save_ajax();
810 } else {
811 /*var connect_google_el = document.querySelector('.grw-connect-google-inside'),
812 google_pid_el = document.querySelector('.grw-connect-id');
813
814 connect_google_el.style = '';
815 google_pid_el.focus();*/
816 }
817 }
818
819 function grw_deserialize_connections($, el, data) {
820 var connections = data.conns,
821 options = connections.options;
822
823 if (Array.isArray(connections.connections)) {
824 connections = connections.connections;
825 } else {
826 var temp_conns = [];
827 if (Array.isArray(connections.google)) {
828 for (var c = 0; c < connections.google.length; c++) {
829 connections.google[c].platform = 'google';
830 }
831 temp_conns = temp_conns.concat(connections.google);
832 }
833 if (Array.isArray(connections.facebook)) {
834 for (var c = 0; c < connections.facebook.length; c++) {
835 connections.facebook[c].platform = 'facebook';
836 }
837 temp_conns = temp_conns.concat(connections.facebook);
838 }
839 if (Array.isArray(connections.yelp)) {
840 for (var c = 0; c < connections.yelp.length; c++) {
841 connections.yelp[c].platform = 'yelp';
842 }
843 temp_conns = temp_conns.concat(connections.yelp);
844 }
845 connections = temp_conns;
846 }
847
848 for (var i = 0; i < connections.length; i++) {
849 grw_connection_add($, el.querySelector('.grw-builder-platforms'), connections[i], data.authcode, true);
850 }
851
852 for (var opt in options) {
853 if (Object.prototype.hasOwnProperty.call(options, opt)) {
854 var control = el.querySelector('input[name="' + opt + '"],select[name="' + opt + '"],textarea[name="' + opt + '"]');
855 if (control) {
856 var name = control.getAttribute('name');
857 if (typeof(options[opt]) === 'boolean') {
858 control.checked = options[opt];
859 } else {
860 control.value = (
861 control.type == 'textarea' ||
862 name == 'word_filter' ||
863 name == 'word_exclude' ?
864 decodeURIComponent(options[opt]) : options[opt]
865 );
866 if (opt.indexOf('_photo') > -1 && control.value) {
867 control.parentNode.querySelector('img').src = control.value;
868 }
869 }
870 }
871 }
872 }
873 }
874
875 function grw_upload_photo(el, file_frame, cb) {
876 if (file_frame) {
877 file_frame.open();
878 return;
879 }
880
881 file_frame = wp.media.frames.file_frame = wp.media({
882 title: jQuery(this).data('uploader_title'),
883 button: {text: jQuery(this).data('uploader_button_text')},
884 multiple: false
885 });
886
887 file_frame.on('select', function() {
888 var attachment = file_frame.state().get('selection').first().toJSON();
889 grw_change_photo(el, attachment.url);
890 cb && cb(attachment.url);
891 });
892 file_frame.open();
893 }
894
895 function grw_change_photo(el, photo_url) {
896 var place_photo_hidden = jQuery('.grw-connect-photo-hidden', el),
897 place_photo_img = jQuery('.grw-connect-photo', el);
898
899 place_photo_hidden.val(photo_url);
900 place_photo_img.attr('src', photo_url);
901 place_photo_img.show();
902
903 grw_serialize_connections();
904 }
905
906 function grw_popup(url, width, height, cb) {
907 var top = top || (screen.height/2)-(height/2),
908 left = left || (screen.width/2)-(width/2),
909 win = window.open(url, '', 'location=1,status=1,resizable=yes,width='+width+',height='+height+',top='+top+',left='+left);
910 function check() {
911 if (!win || win.closed != false) {
912 cb();
913 } else {
914 setTimeout(check, 100);
915 }
916 }
917 setTimeout(check, 100);
918 }
919
920 function grw_randstr(len) {
921 var result = '',
922 chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
923 charsLen = chars.length;
924 for ( var i = 0; i < len; i++ ) {
925 result += chars.charAt(Math.floor(Math.random() * charsLen));
926 }
927 return result;
928 }
929
930 function grw_is_hidden(el) {
931 return el.offsetParent === null;
932 }
933
934 function grw_capitalize(str) {
935 return str.charAt(0).toUpperCase() + str.slice(1);
936 }
937
938 function grw_lang(defname, lang) {
939 var html = '';
940 for (var i = 0; i < GRW_LANGS.length; i++) {
941 html += '<option value="' + GRW_LANGS[i][0] + '"' + (lang == GRW_LANGS[i][0] ? ' selected="selected"' : '') + '>' + GRW_LANGS[i][1] + '</option>';
942 }
943 return '<select class="grw-connect-lang" name="lang">' +
944 '<option value=""' + (lang ? '' : ' selected="selected"') + '>' + defname + '</option>' +
945 html +
946 '</select>';
947 }