PageSourceSearch

https://wildernessprincess.net/wp-content/plugins/wp-photo-album-plus/js/wppa-ajax-front.js?ver=260930-14053

js wildernessprincess.net collected 2026-10-04 21:25:45 UTC 53,607 bytes, 1,689 lines download raw bytes

1// wppa-ajax-front.js
2//
3// Contains frontend ajax modules
4// Dependancies: wppa.js and default wp $ library
5//
6var wppaJsAjaxVersion = '9.3.01.002';
7
8// The new AJAX rendering routine Async
9function wppaDoAjaxRender(event, mocc, ajaxurl, newurl, addHilite ) {
10
11	event.stopPropagation();
12
13	// Fix the url
14	if ( wppaLang != '' ) ajaxurl += '&lang='+wppaLang;
15	if ( wppaAutoColumnWidth[mocc] ) ajaxurl += '&resp=1';
16	ajaxurl += '&wppa-cw='+wppaGetContainerWidth(mocc);
17	if ( addHilite && _wppaCurIdx[mocc] && _wppaId[mocc][_wppaCurIdx[mocc]] ) ajaxurl += '&wppa-hilite=' + _wppaId[mocc][_wppaCurIdx[mocc]];
18
19	// Ajax possible, or no newurl defined ?
20	if ( wppaCanAjaxRender || ! newurl ) {
21
22		jQuery.ajax( { 	url: 		ajaxurl,
23						async: 		true,
24						type: 		'GET',
25						timeout: 	60000,
26						beforeSend: function( xhr ) {
27
28										if ( wppaAjaxMethod == 'rest' ) {
29											xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
30										}
31
32										// If it is a slideshow: Stop slideshow before pushing it on the stack
33										if ( _wppaSSRuns[mocc] ) _wppaStop( mocc );
34
35										// Display the spinner
36										jQuery( '#wppa-ajax-spin-'+mocc ).fadeIn();
37									},
38						success: 	function( xresult, status, xhr ) {
39
40
41										if ( typeof( xresult ) == 'string' && xresult.substr( 0, 1 ) != '{' ) {
42							//				console.log( 'Ajax render result starts with ' + xresult.substr(0,9) );
43											if ( xresult.substr( 0, 9 ) == '<!DOCTYPE' || xresult.substr( 0, 5 ) == '<html' ) {
44												if ( newurl.length > 0 ) {
45													document.location.href = newurl;
46												}
47												else {
48													alert( __( 'Frontend Ajax request failed. Try a different setting in Advanced settings -> System -> I -> Item 5', 'wp-photo-album-plus' ) );
49												}
50											}
51											else {
52												alert( __( 'Unexpected output', 'wp-photo-album-plus' )+': '+xresult.substr(0,100)+'...' );
53											}
54										}
55
56										else {
57
58											if ( typeof( xresult ) == 'string' ) {
59												var theResult = JSON.parse(xresult);
60												var result = theResult.html + '<script>' + theResult.js + '</script>';
61											}
62											else {
63												var result = xresult.html + '<script>' + xresult.js + '</script>';
64											}
65
66											// Do not render modal if behind button. When behind button, there is no newurl,
67											// so we test on the existence of newurl to see if it is behind button
68											if ( wppaRenderModal && newurl ) {
69
70												// Init dialog options
71												var opt = {
72													modal:		true,
73													resizable: 	true,
74													width:		wppaGetContainerWidth( mocc ),
75													show: 		{
76																	effect: 	"fadeIn",
77																	duration: 	400
78																},
79													closeText: 	"",
80													classes: 	"wppa-dialog",
81												};
82
83												// Open modal dialog
84												wppaPrepareModal(mocc);
85												jQuery( '#wppa-modal-container-'+mocc ).html( result );
86												jQuery( '#wppa-modal-container-'+mocc ).dialog( opt );
87
88												var isSlide = result.indexOf('slide-frame') != -1;
89												var theTop;
90												if (isSlide) {
91													if (wppaAreaMaxFracSlide == 1) {
92														theTop = wppaWindowHeight() / 20;
93													}
94													else {
95														theTop = ((wppaWindowHeight() - wppaWindowHeight() * wppaAreaMaxFracSlide)/2);
96													}
97												}
98												else {
99													if (wppaAreaMaxFrac == 1) {
100														theTop = wppaWindowHeight() / 20;
101													}
102													else {
103														theTop = ((wppaWindowHeight() - wppaWindowHeight() * wppaAreaMaxFrac)/2);
104													}
105												}
106
107												// Adjust styles
108												jQuery( '.ui-dialog' ).css( {
109																				boxShadow: 			'0px 0px 5px 5px #aaaaaa',
110																				borderRadius: 		wppaBoxRadius+'px',
111																				padding: 			'8px',
112																				backgroundColor: 	wppaModalBgColor,
113																				boxSizing: 			'content-box',
114																				zIndex: 			100000,
115																				margin: 			'auto',
116																				overflow: 			'hidden',
117																				position: 			'fixed',
118																				left: 				((wppaWindowWidth() - wppaGetContainerWidth(mocc))/2)+'px',
119																				top: 				theTop+'px',
120																			});
121												jQuery( '.ui-dialog-titlebar' ).css(
122																						{
123																							lineHeight: '0px',
124																							height: 	'32px',
125																						}
126																					);
127												jQuery( '.ui-button' ).css(
128																			{
129																				backgroundImage: 	wppaModalQuitImg,
130																				padding:			0,
131																				position: 			'absolute',
132																				right: 				'8px',
133																				top: 				'8px',
134																				width: 				'16px',
135																				height: 			'16px',
136																			});
137												jQuery( '.ui-button' ).attr( 'title', 'Close' );
138
139												// Stop a possible slideshow
140												jQuery( '.ui-button' ).on( 'click', function() { _wppaStop( mocc ); } );
141
142												// Remove spinner
143												jQuery( '.wppa-ajax-spin' ).stop().fadeOut();
144
145												// Adjust modal container max height
146									//			jQuery("#wppa-modal-container-"+mocc).css({maxHeight:wppaWindowHeight()});
147
148												// Add nicescroller optionally
149												setTimeout(function() {
150													if (jQuery().niceScroll) {
151														jQuery(".wppa-albumlist-"+mocc).niceScroll(".wppa-nicewrap",{});
152														jQuery(".wppa-slidelist-"+mocc).niceScroll(".wppa-nicewrap",{});
153													};
154												}, 1000);
155												jQuery(document).trigger('resize');
156
157											}
158
159											// Not modal or behind button
160											else {
161												jQuery( '#wppa-container-'+mocc ).html( result );
162
163												// If behind button: show hide buttton
164												jQuery( '#wppa-button-hide-'+mocc ).show();
165											}
166
167
168											// Push the stack
169											if ( wppaCanPushState && wppaUpdateAddressLine && newurl ) {
170
171												newurl = newurl.split('&amp;').join('&');
172												history.pushState( {type: 'ajax'}, "", newurl ); //wppaCurrentUrl );
173										//		console.log( 'ajax history pushed ' + newurl ); //wppaCurrentUrl );
174											}
175
176											// If lightbox is on board, refresh the imagelist. It has just changed, you know!
177											wppaUpdateLightboxes();
178
179											// Update qrcode
180											if ( typeof( wppaQRUpdate ) != 'undefined' ) {
181												wppaQRUpdate( newurl );
182											}
183
184											// Run Autocol?
185											wppaColWidth[mocc] = 0;
186											_wppaDoAutocol( mocc, 'ajax' );
187										}
188									},
189						error: 		function( xhr, status, error ) {
190										wppaConsoleLog( 'wppaDoAjaxRender failed. Error = ' + error + ', status = ' + status );
191
192										// Do it by reload
193										if ( newurl ) {
194											document.location.href = newurl;
195										}
196										else {
197											document.location.reload(true);
198										}
199									},
200						complete: 	function( xhr, status, newurl ) {
201
202										if ( ! wppaRenderModal && wppaAjaxScroll ) {
203											jQuery('html, body').animate({ scrollTop: jQuery("#wppa-container-"+mocc).offset().top - 32 - wppaStickyHeaderHeight }, 1000);
204										}
205
206										// Remove spinner
207										jQuery( '.wppa-ajax-spin' ).stop().fadeOut();
208
209										// Fake resize
210										window.dispatchEvent(new Event('resize'));
211
212										// Hide rightclick optionally
213										wppaProtect();
214
215										// Init handlers
216										wppaDoInit();
217									}
218					} );
219	}
220
221	// Ajax NOT possible
222	else {
223		document.location.href = newurl;
224
225		// Run Autocol?
226		wppaColWidth[mocc] = 0;	// force a recalc and triggers autocol if needed
227		_wppaDoAutocol( mocc, 'nonajax' );
228	}
229}
230
231function wppaDoFetchShortcodeRendered( mocc, shortcode, page ) {
232
233	jQuery.ajax( { 	url: 		wppaAjaxUrl+'?action=wppa&wppa-action=getshortcodedrenderedfenodelay&wppa-shortcode='+shortcode+'&wppa-nonce='+jQuery('#wppa-nonce').val()+'&wppa-occur='+mocc+'&wppa-fromp='+page,
234				async: 		true,
235				type: 		'GET',
236				timeout: 	60000,
237				beforeSend: function(xhr) {
238								if ( wppaAjaxMethod == 'rest' ) {
239									xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
240								}
241					//			wppaConsoleLog('Fetching delayed shortcode content for mocc = '+mocc);
242								jQuery('#wppa-ajax-spin-'+mocc).show();
243							},
244				success: 	function(xresult, status, xhr) {
245								var theResult;
246								var result;
247								try {
248									if ( wppaAjaxMethod == 'rest' ) {
249										result = xresult.html + '<script>' + xresult.js + '</script>';
250									}
251									else {
252										theResult = JSON.parse( xresult );
253										result = theResult.html + '<script>' + theResult.js + '</script>';
254									}
255						//			wppaConsoleLog('Recieved delayed shortcode content for mocc = '+mocc);
256									jQuery('#wppa-container-'+mocc).html(result);
257						//			wppaConsoleLog('Applied delayed shortcode content for mocc = '+mocc);
258								}
259								catch(e) {
260									wppaConsoleLog('wppaDoFetchShortcodeRendered failed. Invalid json data');
261								}
262							},
263				error: 		function(xhr,status,error) {
264								wppaConsoleLog('wppaDoFetchShortcodeRendered failed. Error = '+error+', status = '+status);
265							},
266				complete: 	function(xhr, status) {
267								jQuery(document).trigger('resize');
268								wppaProtect();
269								jQuery('#wppa-ajax-spin-'+mocc).hide();
270								wppaInitOverlay();
271							}
272	});
273}
274
275// Set photo status to 'publish'
276function wppaAjaxApprovePhoto( photo ) {
277
278	jQuery.ajax( { 	url: 		wppaAjaxUrl,
279					data: 		'action=wppa' +
280								'&wppa-action=approve' +
281								'&photo-id=' + photo,
282					async: 		true,
283					type: 		'GET',
284					timeout: 	60000,
285					beforeSend: function(xhr) {
286									if ( wppaAjaxMethod == 'rest' ) {
287										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
288									}
289								},
290					success: 	function( xresult, status, xhr ) {
291									var result;
292									if ( wppaAjaxMethod == 'rest' ) {
293										result = xresult.txt;
294									}
295									else {
296										theResult = JSON.parse( xresult );
297										result = theResult.txt;
298									}
299									if ( result == 'OK' ) {
300										jQuery( '.wppa-approve-' + photo ).css( 'display', 'none' );
301									}
302								},
303					error: 		function( xhr, status, error ) {
304									wppaConsoleLog( 'wppaAjaxApprovePhoto failed. Error = ' + error + ', status = ' + status );
305								},
306				} );
307}
308
309// Remove photo
310function wppaAjaxRemovePhoto( mocc, photo, isslide ) {
311
312	jQuery.ajax( { 	url: 		wppaAjaxUrl,
313					data: 		'action=wppa' +
314								'&wppa-action=remove' +
315								'&photo-id=' + photo,
316					async: 		true,
317					type: 		'GET',
318					timeout: 	60000,
319					beforeSend: function(xhr) {
320									if ( wppaAjaxMethod == 'rest' ) {
321										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
322									}
323								},
324					success: 	function( xresult, status, xhr ) {
325
326									var result;
327									if ( wppaAjaxMethod == 'rest' ) {
328										result = xresult.txt;
329									}
330									else {
331										theResult = JSON.parse( xresult );
332										result = theResult.txt;
333									}
334
335									// Remove succeeded?
336									rtxt = result.split( '||' );
337									if ( rtxt[0] == 'OK' ) {
338
339										// Slide?
340										if ( isslide ) {
341											jQuery( '#wppa-film-'+_wppaCurIdx[mocc]+'-'+mocc ).attr( 'src', '' );
342											jQuery( '#wppa-pre-'+_wppaCurIdx[mocc]+'-'+mocc ).attr( 'src', '' );
343											jQuery( '#wppa-film-'+_wppaCurIdx[mocc]+'-'+mocc ).attr( 'alt', 'removed' );
344											jQuery( '#wppa-pre-'+_wppaCurIdx[mocc]+'-'+mocc ).attr( 'alt', 'removed' );
345											wppaNext( mocc );
346										}
347
348										// Thumbnail
349										else {
350											jQuery( '.wppa-approve-'+photo ).css( 'display', 'none' );
351											jQuery( '.thumbnail-frame-photo-'+photo ).css( 'display', 'none' );
352										}
353									}
354
355									// Remove failed
356									else {
357										if ( rtxt[3] ) {
358											alert( rtxt[3] );
359											jQuery( '#wppa-delete-'+photo ).css('text-decoration', 'line-through' );
360										}
361										else {
362											alert( result );
363										}
364									}
365								},
366					error: 		function( xhr, status, error ) {
367									wppaConsoleLog( 'wppaAjaxRemovePhoto failed. Error = ' + error + ', status = ' + status );
368								}
369				} );
370}
371
372// Set comment status to 'pblish'
373function wppaAjaxApproveComment( comment ) {
374
375	jQuery.ajax( { 	url: 		wppaAjaxUrl,
376					data: 		'action=wppa' +
377								'&wppa-action=approve' +
378								'&comment-id=' + comment,
379					async: 		true,
380					type: 		'GET',
381					timeout: 	60000,
382					beforeSend: function(xhr) {
383									if ( wppaAjaxMethod == 'rest' ) {
384										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
385									}
386								},
387					success: 	function( xresult, status, xhr ) {
388									var result;
389									if ( wppaAjaxMethod == 'rest' ) {
390										result = xresult.txt;
391									}
392									else {
393										theResult = JSON.parse( xresult );
394										result = theResult.txt;
395									}
396
397									// Approve succeeded?
398									if ( result == 'OK' ) {
399										jQuery( '.wppa-approve-'+comment ).css( 'display', 'none' );
400									}
401
402									// Approve failed
403									else {
404										alert( result );
405									}
406								},
407					error: 		function( xhr, status, error ) {
408									wppaConsoleLog( 'wppaAjaxApproveComment failed. Error = ' + error + ', status = ' + status );
409								}
410				} );
411
412}
413
414// Remove comment
415function wppaAjaxRemoveComment( comment ) {
416
417	jQuery.ajax( { 	url: 		wppaAjaxUrl,
418					data: 		'action=wppa' +
419								'&wppa-action=remove' +
420								'&comment-id=' + comment,
421					async: 		true,
422					type: 		'GET',
423					timeout: 	60000,
424					beforeSend: function(xhr) {
425									if ( wppaAjaxMethod == 'rest' ) {
426										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
427									}
428								},
429					success: 	function( xresult, status, xhr ) {
430									var result;
431									if ( wppaAjaxMethod == 'rest' ) {
432										result = xresult.txt;
433									}
434									else {
435										theResult = JSON.parse( xresult );
436										result = theResult.txt;
437									}
438
439									// Remove succeeded?
440									var rtxt = result.split( '||' );
441									if ( rtxt[0] == 'OK' ) {
442										jQuery( '.wppa-approve-'+comment ).css( 'display', 'none' );
443										jQuery( '.wppa-comment-'+comment ).css( 'display', 'none' );
444									}
445									else {
446										alert( result );
447									}
448								},
449					error: 		function( xhr, status, error ) {
450									wppaConsoleLog( 'wppaAjaxRemoveComment failed. Error = ' + error + ', status = ' + status );
451								},
452				} );
453}
454
455// Add photo to zip
456function wppaAjaxAddPhotoToZip( mocc, id, reload ) {
457
458	jQuery.ajax( { 	url: 		wppaAjaxUrl,
459				data: 		'action=wppa' +
460							'&wppa-action=addtozip' +
461							'&photo-id=' + id,
462				async: 		true,
463				type: 		'GET',
464				timeout: 	60000,
465				beforeSend: function(xhr) {
466								if ( wppaAjaxMethod == 'rest' ) {
467									xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
468								}
469							},
470				success: 	function( xresult, status, xhr ) {
471								var result;
472								if ( wppaAjaxMethod == 'rest' ) {
473									result = xresult.txt;
474								}
475								else {
476									theResult = JSON.parse( xresult );
477									result = theResult.txt;
478								}
479
480								// Adding succeeded?
481								var rtxt = result.split( '||' );
482								if ( rtxt[0] == 'OK' ) {
483
484									// For the thumbnails
485									jQuery('#admin-choice-'+id+'-'+mocc).html(rtxt[2]);
486
487									// For the slideshow
488									jQuery('#admin-choice-'+id+'-'+mocc).val(rtxt[2]);
489									jQuery('#admin-choice-'+id+'-'+mocc).prop('disabled', true);
490								}
491								alert( rtxt[1] );
492
493								// Reload
494								if ( reload ) {
495									document.location.reload( true );
496								}
497							},
498				error: 		function( xhr, status, error ) {
499								wppaConsoleLog( 'wppaAjaxAddPhotoToZip failed. Error = ' + error + ', status = ' + status );
500							},
501			} );
502}
503
504// Remove photo from zip
505function wppaAjaxRemovePhotoFromZip( mocc, id, reload ) {
506
507	jQuery.ajax( { 	url: 		wppaAjaxUrl,
508					data: 		'action=wppa' +
509								'&wppa-action=removefromzip' +
510								'&photo-id=' + id,
511					async: 		true,
512					type: 		'GET',
513					timeout: 	60000,
514					beforeSend: function(xhr) {
515									if ( wppaAjaxMethod == 'rest' ) {
516										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
517									}
518								},
519					success: 	function( xresult, status, xhr ) {
520									var result;
521									if ( wppaAjaxMethod == 'rest' ) {
522										result = xresult.txt;
523									}
524									else {
525										theResult = JSON.parse( xresult );
526										result = theResult.txt;
527									}
528
529									// Removing succeeded?
530									var rtxt = result.split( '||' );
531									if ( rtxt[0] == 'OK' ) {
532
533										// For the slideshow
534										jQuery('#admin-choice-rem-'+id+'-'+mocc).val(rtxt[1]);
535										jQuery('#admin-choice-rem-'+id+'-'+mocc).prop('disabled', true);
536										jQuery('#admin-choice-rem-'+id+'-'+mocc).css('text-decoration', '');
537									}
538									else {
539										alert( result );
540									}
541
542									// Reload
543									if ( reload ) {
544										document.location.reload( true );
545									}
546								},
547					error: 		function( xhr, status, error ) {
548									wppaConsoleLog( 'wppaAjaxRemovePhotoFromZip failed. Error = ' + error + ', status = ' + status, 'force' );
549								},
550				} );
551}
552
553// Remove admins choice zipfile
554function wppaAjaxDeleteMyZip(nonce,login) {
555
556	jQuery.ajax( { 	url: 		wppaAjaxUrl,
557				data: 		'action=wppa' +
558							'&wppa-action=delmyzip'+
559							'&wppa-nonce=' + nonce,
560				async: 		true,
561				type: 		'GET',
562				timeout: 	60000,
563				beforeSend: function(xhr) {
564								if ( wppaAjaxMethod == 'rest' ) {
565									xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
566								}
567							},
568				success: 	function( xresult, status, xhr ) {
569								var result;
570								if ( wppaAjaxMethod == 'rest' ) {
571									result = xresult.txt;
572								}
573								else {
574									theResult = JSON.parse( xresult );
575									result = theResult.txt;
576								}
577
578								jQuery('#'+login).html(result);
579								// Reload
580								//document.location.reload( true );
581
582							},
583				error: 		function( xhr, status, error ) {
584								wppaConsoleLog( 'wppaAjaxDeleteMyZip failed. Error = ' + error + ', status = ' + status );
585							},
586			} );
587}
588
589// Request Info
590function wppaAjaxRequestInfo( mocc, id, reload ) {
591
592
593	dialogHtml =
594	'<div class="wppa-modal">'+
595	'<h3>' + __( 'Please specify your question', 'wp-photo-album-plus' ) + '</h3>' +
596	'<textarea id="wppa-request-info-text-'+mocc+'" style="width:98%;" ></textarea>' +
597	'<div style="clear:both;" ></div>' +
598	'<input type="button" style="float:left;margin-top:8px;margin-right:8px;" value="' + __( 'Send', 'wp-photo-album-plus' ) + '" onclick="wppaAjaxRequestInfoSend( '+mocc+', \''+id+'\', '+reload+' )" />' +
599	'<input type="button" style="float:left;margin-top:8px;margin-right:8px;" value="' + __( 'Cancel', 'wp-photo-album-plus' ) + '" onclick="jQuery( \'#wppa-modal-container-'+mocc+'\' ).dialog( \'close\' );" />'+
600	'<div style="clear:both;" ></div></div>';
601
602	// Show dialog first
603	var opt = {
604				modal:		true,
605				resizable: 	true,
606				width:		wppaGetContainerWidth( mocc ),
607				show: 		{
608								effect: 	"fadeIn",
609								duration: 	400
610							},
611				closeText: 	"",
612				classes: 	"wppa-dialog",
613			};
614			wppaPrepareModal(mocc);
615			jQuery( '#wppa-modal-container-'+mocc ).html( dialogHtml );
616			jQuery( '#wppa-modal-container-'+mocc ).dialog( opt );
617
618			jQuery( '.ui-dialog' ).css( {
619											boxShadow: 			'0px 0px 5px 5px #aaaaaa',
620											borderRadius: 		wppaBoxRadius+'px',
621											padding: 			'8px',
622											backgroundColor: 	wppaModalBgColor,
623											boxSizing: 			'content-box',
624											zIndex: 			100000,
625											position: 			'fixed',
626											top: 				(wppaWindowHeight()/10)+'px',
627										});
628			jQuery( '.ui-dialog-titlebar' ).css(
629													{
630														lineHeight: '0px',
631														height: 	'24px',
632													}
633												)
634			jQuery( '.ui-button' ).css(
635										{
636											backgroundImage: 	wppaModalQuitImg,
637											padding:			0,
638											position: 			'absolute',
639											right: 				'8px',
640											top: 				'8px',
641											width: 				'16px',
642											height: 			'16px',
643										});
644			jQuery( '.ui-button' ).attr( 'title', 'Close' );
645			jQuery(document).trigger('resize');
646}
647
648function wppaAjaxRequestInfoSend( mocc, id, reload ) {
649
650	jQuery.ajax( { 	url: 		wppaAjaxUrl,
651				data: 		'action=wppa' +
652							'&wppa-action=requestinfo' +
653							'&photo-id=' + id +
654							'&emailtext=' + jQuery('#wppa-request-info-text-'+mocc).val(),
655				async: 		true,
656				type: 		'GET',
657				timeout: 	60000,
658				beforeSend: function(xhr) {
659								if ( wppaAjaxMethod == 'rest' ) {
660									xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
661								}
662							},
663				success: 	function( xresult, status, xhr ) {
664
665								var result;
666								if ( wppaAjaxMethod == 'rest' ) {
667									result = xresult.txt;
668								}
669								else {
670									theResult = JSON.parse( xresult );
671									result = theResult.txt;
672								}
673
674								// Request succeeded?
675								var rtxt = result.split( '||' );
676								if ( rtxt[0] == 'OK' ) {
677
678									// For the slideshow
679									jQuery('#request-info-'+id+'-'+mocc).val(rtxt[1]);
680									jQuery('#request-info-'+id+'-'+mocc).prop('disabled', true);
681//									jQuery('#wppa-modal-container-'+mocc).dialog('close');
682								}
683								else {
684									alert( result );
685								}
686
687								// Reload
688								if ( reload ) {
689									document.location.reload( true );
690								}
691								else {
692									jQuery( '#wppa-modal-container-'+mocc ).dialog( 'close' );
693									jQuery( '#wppa-modal-container-'+mocc ).html('');
694								}
695							},
696				error: 		function( xhr, status, error ) {
697								wppaConsoleLog( 'wppaAjaxRequestInfoSend failed. Error = ' + error + ', status = ' + status );
698							},
699			} );
700}
701
702// Frontend Edit Photo
703function wppaEditPhoto( mocc, id ) {
704
705//	var id 		= String(xid);
706//	var name 	= 'Edit Photo '+id;
707//	var desc 	= '';
708//	var width 	= 500;
709//	var height 	= 512;
710
711//	if ( screen.availWidth < width ) width = screen.availWidth;
712
713//	var wnd;
714
715	jQuery.ajax( { 	url: 		wppaAjaxUrl,
716					data: 		'action=wppa' +
717								'&wppa-action=front-edit' +
718								'&photo-id=' + id +
719								'&occur=' + mocc,
720					async: 		true,
721					type: 		'POST',
722					timeout: 	60000,
723					beforeSend: function(xhr) {
724									if ( wppaAjaxMethod == 'rest' ) {
725										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
726									}
727								},
728					success: 	function( xresult, status, xhr ) {
729
730									var result;
731									if ( wppaAjaxMethod == 'rest' ) {
732										result = xresult.txt;
733									}
734									else {
735										theResult = JSON.parse( xresult );
736										result = theResult.txt;
737									}
738
739									var opt = {
740										modal:		true,
741										resizable: 	true,
742										width:		wppaGetContainerWidth( mocc ),
743										show: 		{
744														effect: 	"fadeIn",
745														duration: 	400
746													},
747										closeText: 	"",
748										classes: 	"wppa-dialog",
749									};
750
751									wppaPrepareModal(mocc);
752									jQuery( '#wppa-modal-container-'+mocc ).html( result );
753									jQuery( '#wppa-modal-container-'+mocc ).dialog( opt );
754									jQuery( '.ui-dialog' ).css( {
755																	boxShadow: 			'0px 0px 5px 5px #aaaaaa',
756																	borderRadius: 		wppaBoxRadius+'px',
757																	padding: 			'8px',
758																	backgroundColor: 	wppaModalBgColor,
759																	boxSizing: 			'content-box',
760																	zIndex: 			100000,
761																	position: 			'fixed',
762																	top: 				(wppaWindowHeight()/10)+'px',
763																});
764									jQuery( '.ui-dialog-titlebar' ).css(
765																			{
766																				lineHeight: '0px',
767																				height: 	'24px',
768																			}
769																		)
770									jQuery( '.ui-button' ).css(
771																{
772																	backgroundImage: 	wppaModalQuitImg,
773																	padding:			0,
774																	position: 			'absolute',
775																	right: 				'8px',
776																	top: 				'8px',
777																	width: 				'16px',
778																	height: 			'16px',
779																});
780									jQuery( '.ui-button' ).attr( 'title', 'Close' );
781									jQuery(document).trigger('resize');
782
783									jQuery('.ui-dialog').on('scroll wheel', function(event){event.stopPropagation();});
784								},
785					error: 		function( xhr, status, error ) {
786
787									wppaConsoleLog( 'wppaEditPhoto failed. Error = ' + error + ', status = ' + status );
788								},
789					complete: 	function( xhr, status, newurl ) {
790
791								}
792				} );
793}
794
795// Preview tags in frontend upload dialog
796function wppaPrevTags( tagsSel1, tagsSel2, tagsSel3, tagsEdit, tagsAlbum, tagsPrev, tagsNewval, buttonId, waitText ) {
797
798	var sel1 		= jQuery( '#'+tagsSel1 ).val() || '';
799	var sel2 		= jQuery( '#'+tagsSel2 ).val() || '';
800	var sel3 		= jQuery( '#'+tagsSel3 ).val() || '';
801	var edit		= jQuery( '#'+tagsEdit ).val() || '';
802	var album 		= jQuery( '#'+tagsAlbum ).val() || '';
803	var i 			= 0;
804	var j 			= 0;
805	var tags 		= '';
806
807	// Disable sumit button
808	var buttonText = jQuery( '#'+buttonId ).val() || '';
809	jQuery( '#'+buttonId ).val( waitText );
810	jQuery( '#'+buttonId ).attr('disabled','disabled');
811
812	var data = 'action=wppa&wppa-action=sanitizetags&tags=' + sel1 + ',' + sel2 + ',' + sel3 + ',' + edit + '&album=' + album;
813
814	// Sanitize if edit field is not empty or album known and put result in preview field
815	jQuery.ajax( { 	url: 		wppaAjaxUrl,
816					data: 		data,
817					async: 		true,
818					type: 		'GET',
819					timeout: 	60000,
820					beforeSend: function(xhr) {
821									if ( wppaAjaxMethod == 'rest' ) {
822										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
823									}
824									jQuery( '#'+tagsPrev ).html( 'Working...' );
825		//							wppaConsoleLog(data);
826								},
827					success: 	function( xresult, status, xhr ) {
828									var result;
829									if ( wppaAjaxMethod == 'rest' ) {
830										result = xresult.txt;
831									}
832									else {
833										theResult = JSON.parse( xresult );
834										result = theResult.txt;
835									}
836									jQuery( '#'+tagsNewval ).attr( 'value', wppaTrim( result, ',' ) );
837									jQuery( '#'+tagsPrev ).html( wppaTrim( result, ',' ) );
838									jQuery( '#'+buttonId ).val( buttonText );
839									jQuery( '#'+buttonId ).removeAttr('disabled');
840						//			wppaConsoleLog(result+' gepleurt op '+tagsPrev);
841								},
842					error: 		function( xhr, status, error ) {
843									jQuery( '#'+tagsPrev ).html( '<span style="color:red" >' + error + '</span>' );
844									wppaConsoleLog( 'wppaPrevTags failed. Error = ' + error + ', status = ' + status );
845								},
846				} );
847}
848
849// Delete album
850function wppaAjaxDestroyAlbum( album, nonce ) {
851
852	// Are you sure?
853	if ( confirm('Are you sure you want to delete this album?') ) {
854
855		jQuery.ajax( { 	url: 		wppaAjaxUrl,
856						data: 		'action=wppa' +
857									'&wppa-action=destroyalbum' +
858									'&album=' + album +
859									'&nonce=' + nonce,
860						async: 		true,
861						type: 		'GET',
862						timeout: 	60000,
863						beforeSend: function(xhr) {
864										if ( wppaAjaxMethod == 'rest' ) {
865											xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
866										}
867									},
868						success: 	function( xresult, status, xhr ) {
869										var result;
870										if ( wppaAjaxMethod == 'rest' ) {
871											result = xresult.txt;
872										}
873										else {
874											theResult = JSON.parse( xresult );
875											result = theResult.txt;
876										}
877										alert( result+'\n'+__( 'Page will be reloaded', 'wp-photo-album-plus' ) );
878										document.location.reload( true );
879									},
880						error: 		function( xhr, status, error ) {
881										wppaConsoleLog( 'wppaAjaxDestroyAlbum failed. Error = ' + error + ', status = ' + status );
882									},
883					} );
884	}
885	return false;
886}
887
888// Bump click counter
889function _bumpClickCount( photo ) {
890
891	// Feature enabled?
892	if ( ! wppaBumpClickCount ) return;
893
894	jQuery.ajax( { 	url: 		wppaAjaxUrl,
895					data: 		'action=wppa' +
896								'&wppa-action=bumpclickcount' +
897								'&wppa-photo=' + photo +
898								'&wppa-nonce=' + jQuery( '#wppa-nonce' ).val(),
899					async: 		false,
900					type: 		'GET',
901					timeout: 	60000,
902					beforeSend: function(xhr) {
903									if ( wppaAjaxMethod == 'rest' ) {
904										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
905									}
906								},
907					success: 	function( xresult, status, xhr ) {
908									var result;
909									if ( wppaAjaxMethod == 'rest' ) {
910										result = xresult.txt;
911									}
912									else {
913										theResult = JSON.parse( xresult );
914										result = theResult.txt;
915									}
916								},
917					error: 		function( xhr, status, error ) {
918									wppaConsoleLog( '_bumpClickCount failed. Error = ' + error + ', status = ' + status );
919								},
920				} );
921}
922
923// Bump view counter
924function _bumpViewCount( photo ) {
925
926	// Feature enabled?
927	if ( ! wppaBumpViewCount ) return;
928
929	// Already bumped?
930	if ( wppaPhotoView[photo] ) {
931		return;
932	}
933
934	// No photo?
935	if ( photo == 0 ) {
936		return;
937	}
938
939	jQuery.ajax( { 	url: 		wppaAjaxUrl,
940					data: 		'action=wppa' +
941								'&wppa-action=bumpviewcount' +
942								'&wppa-photo=' + photo +
943								'&wppa-nonce=' + jQuery( '#wppa-nonce' ).val(),
944					async: 		true,
945					type: 		'GET',
946					timeout: 	60000,
947					beforeSend: function(xhr) {
948									if ( wppaAjaxMethod == 'rest' ) {
949										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
950									}
951								},
952					success: 	function( xresult, status, xhr ) {
953									var result;
954									if ( wppaAjaxMethod == 'rest' ) {
955										result = xresult.txt;
956									}
957									else {
958										theResult = JSON.parse( xresult );
959										result = theResult.txt;
960									}
961									wppaPhotoView[photo] = true;
962								},
963					error: 		function( xhr, status, error ) {
964									wppaConsoleLog( '_bumpViewCount failed. Error = ' + error + ', status = ' + status );
965								},
966				} );
967}
968
969// Vote a thumbnail
970function wppaVoteThumb( mocc, photo ) {
971
972	jQuery.ajax( { 	url: 		wppaAjaxUrl,
973					data: 		'action=wppa' +
974								'&wppa-action=rate' +
975								'&wppa-rating=1' +
976								'&wppa-rating-id=' + photo +
977								'&wppa-occur=' + mocc +
978								'&wppa-index=0' +
979								'&wppa-nonce=' + jQuery( '#wppa-nonce' ).val(),
980					async: 		true,
981					type: 		'GET',
982					timeout: 	60000,
983					beforeSend: function(xhr) {
984									if ( wppaAjaxMethod == 'rest' ) {
985										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
986									}
987								},
988					success: 	function( xresult, status, xhr ) {
989									var result;
990									if ( wppaAjaxMethod == 'rest' ) {
991										result = xresult.txt;
992									}
993									else {
994										theResult = JSON.parse( xresult );
995										result = theResult.txt;
996									}
997									jQuery( '#wppa-vote-button-'+mocc+'-'+photo ).val( wppaVotedForMe );
998								},
999					error: 		function( xhr, status, error ) {
1000									wppaConsoleLog( 'wppaVoteThumb failed. Error = ' + error + ', status = ' + status );
1001								},
1002				} );
1003}
1004
1005// Rate a photo
1006function _wppaRateIt( mocc, value ) {
1007
1008	// No value, no vote
1009	if ( value == 0 ) return;
1010
1011	// Do not rate a running show
1012	if ( _wppaSSRuns[mocc] ) return;
1013
1014	// Init vars
1015	var photo 		= _wppaId[mocc][_wppaCurIdx[mocc]];
1016	var oldval  	= _wppaMyr[mocc][_wppaCurIdx[mocc]];
1017	var waittext  	= _wppaWaitTexts[mocc][_wppaCurIdx[mocc]];
1018
1019	// If wait text, alert and exit
1020	if ( waittext.length > 0 ) {
1021		alert( waittext );
1022		return;
1023	}
1024
1025	// Already rated, and once allowed only?
1026	if ( oldval != 0 && wppaRatingOnce ) {
1027//		alert('exit 2');
1028		return;
1029	}
1030
1031	// Disliked aleady?
1032	if ( oldval < 0 ) return;
1033
1034	// Set Vote in progress flag
1035	_wppaVoteInProgress = true;
1036
1037	// Do the voting
1038	jQuery.ajax( { 	url: 		wppaAjaxUrl,
1039					data: 		'action=wppa' +
1040								'&wppa-action=rate' +
1041								'&wppa-rating=' + value +
1042								'&wppa-rating-id=' + photo +
1043								'&wppa-occur=' + mocc +
1044								'&wppa-index=' + _wppaCurIdx[mocc] +
1045								'&wppa-nonce=' + jQuery( '#wppa-nonce' ).val(),
1046					async: 		true,
1047					type: 		'GET',
1048					timeout: 	60000,
1049					beforeSend: function( xhr ) {
1050
1051									if ( wppaAjaxMethod == 'rest' ) {
1052										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1053									}
1054
1055									// Set icon
1056									jQuery( '#wppa-rate-'+mocc+'-'+value ).attr( 'src', wppaImageDirectory+'tick.png' );
1057
1058									// Fade in fully
1059									jQuery( '#wppa-rate-'+mocc+'-'+value ).stop().fadeTo( 100, 1.0 );
1060
1061									// Likes
1062									jQuery( '#wppa-like-'+mocc ).attr( 'src', wppaImageDirectory+'spinner.gif' );
1063								},
1064					success: 	function( xresult, status, xhr ) {
1065									var result;
1066									if ( wppaAjaxMethod == 'rest' ) {
1067										result = xresult.txt;
1068									}
1069									else {
1070										theResult = JSON.parse( xresult );
1071										result = theResult.txt;
1072									}
1073									var ArrValues = result.split( "||" );
1074
1075									// Error from rating algorithm?
1076									if ( ArrValues[0] == 0 ) {
1077										if ( ArrValues[1] == 900 ) {		// Recoverable error
1078											alert( ArrValues[2] );
1079											_wppaSetRatingDisplay( mocc );	// Restore display
1080										}
1081										else {
1082											alert( __( 'Error Code', 'wp-photo-album-plus' ) + ' = '+ArrValues[1]+'\n\n'+ArrValues[2] );
1083										}
1084									}
1085
1086									// No rating error
1087									else {
1088
1089										// Is it likes sytem?
1090										if ( ArrValues[7] && ArrValues[7] == 'likes' ) {
1091											var likeText = ArrValues[4].split( "|" );
1092
1093											// Slide
1094											jQuery( '#wppa-like-'+mocc ).attr( 'title', likeText[0] );
1095											jQuery( '#wppa-liketext-'+mocc ).html( likeText[1] );
1096											if ( ArrValues[3] == '1' ) {
1097												jQuery( '#wppa-like-'+mocc ).attr( 'src', wppaImageDirectory+'thumbdown.png' );
1098											}
1099											else { // == '0'
1100												jQuery( '#wppa-like-'+mocc ).attr( 'src', wppaImageDirectory+'thumbup.png' );
1101											}
1102											_wppaMyr[ArrValues[0]][ArrValues[2]] = ArrValues[3];
1103											_wppaAvg[ArrValues[0]][ArrValues[2]] = ArrValues[4];
1104										}
1105
1106										// Not likes system
1107										else {
1108											// Store new values
1109											_wppaMyr[ArrValues[0]][ArrValues[2]] = ArrValues[3];
1110											_wppaAvg[ArrValues[0]][ArrValues[2]] = ArrValues[4];
1111											_wppaDisc[ArrValues[0]][ArrValues[2]] = ArrValues[5];
1112
1113											// Update display
1114											_wppaSetRatingDisplay( mocc );
1115
1116											// If commenting required and not done so far...
1117											if ( wppaCommentRequiredAfterVote ) {
1118												if ( ArrValues[6] == 0 ) {
1119													alert( ArrValues[7] );
1120												}
1121											}
1122										}
1123
1124										// Shift to next slide?
1125										if ( wppaNextOnCallback ) _wppaNextOnCallback( mocc );
1126									}
1127								},
1128					error: 		function( xhr, status, error ) {
1129									wppaConsoleLog( '_wppaRateIt failed. Error = ' + error + ', status = ' + status );
1130								},
1131				} );
1132}
1133
1134// Rate from lightbox
1135function _wppaOvlRateIt( id, value, mocc, reloadAfter ) {
1136
1137	// No value, no vote
1138	if ( value == 0 ) return;
1139
1140	// Do the voting
1141	jQuery.ajax( { 	url: 		wppaAjaxUrl,
1142					data: 		'action=wppa' +
1143								'&wppa-action=rate' +
1144								'&wppa-rating=' + value +
1145								'&wppa-rating-id=' + id +
1146								'&wppa-occur=1' + // Must be <> 0 to indicate no error
1147								'&wppa-nonce=' + jQuery( '#wppa-nonce' ).val(),
1148					async: 		true,
1149					type: 		'GET',
1150					timeout: 	60000,
1151					beforeSend: function( xhr ) {
1152
1153									if ( wppaAjaxMethod == 'rest' ) {
1154										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1155									}
1156
1157									// Set icon
1158									jQuery( '.wppa-rate-'+mocc+'-'+value ).attr( 'src', wppaImageDirectory+'tick.png' );
1159
1160									// Fade in fully
1161									jQuery( '.wppa-rate-'+mocc+'-'+value ).stop().fadeTo( 100, 1.0 );
1162
1163									// Likes
1164									jQuery( '#wppa-like-'+id+'-'+mocc ).attr( 'src', wppaImageDirectory+'spinner.gif' );
1165									jQuery( '#wppa-like-0' ).attr( 'src', wppaImageDirectory+'spinner.gif' );
1166								},
1167					success: 	function( xresult, status, xhr ) {
1168									var result;
1169									if ( xresult.txt ) {
1170										result = xresult.txt;
1171									}
1172									else {
1173										theResult = JSON.parse( xresult );
1174										result = theResult.txt;
1175									}
1176
1177									var ArrValues = result.split( "||" );
1178
1179									// Error from rating algorithm?
1180									if ( ArrValues[0] == 0 ) {
1181										if ( ArrValues[1] == 900 ) {		// Recoverable error
1182											alert( ArrValues[2] );
1183										}
1184										else {
1185											alert( __( 'Error Code', 'wp-photo-album-plus' )+' = '+ArrValues[1]+'\n\n'+ArrValues[2] );
1186										}
1187
1188										// Set icon
1189										jQuery( '.wppa-rate-'+mocc+'-'+value ).attr( 'src', wppaImageDirectory+'cross.png' );
1190									}
1191
1192									// No rating error
1193									else {
1194
1195										// Is it likes sytem?
1196										if ( ArrValues[7] && ArrValues[7] == 'likes' ) {
1197											var likeText = ArrValues[4].split( "|" );
1198
1199											// Lightbox
1200											jQuery( '#wppa-like-0' ).attr( 'title', likeText[0] );
1201											jQuery( '#wppa-liketext-0' ).html( likeText[1] );
1202											if ( ArrValues[3] == '1' ) {
1203												jQuery( '#wppa-like-0' ).attr( 'src', wppaImageDirectory+'thumbdown.png' );
1204											}
1205											else { // == '0'
1206												jQuery( '#wppa-like-0' ).attr( 'src', wppaImageDirectory+'thumbup.png' );
1207											}
1208
1209											// Thumbnail
1210											jQuery( '#wppa-like-'+id+'-'+mocc ).attr( 'title', likeText[0] );
1211											jQuery( '#wppa-liketext-'+id+'-'+mocc ).html( likeText[1] );
1212											if ( ArrValues[3] == '1' ) {
1213												jQuery( '#wppa-like-'+id+'-'+mocc ).attr( 'src', wppaImageDirectory+'thumbdown.png' );
1214											}
1215											else { // == '0'
1216												jQuery( '#wppa-like-'+id+'-'+mocc ).attr( 'src', wppaImageDirectory+'thumbup.png' );
1217											}
1218
1219											return;
1220										}
1221
1222// result = $occur.'||'.$photo.'||'.$index.'||'.$myavgrat.'||'.$allavgratcombi.'||'.$distext.'||'.$hascommented.'||'.$message;
1223// ArrValues[3] = my avg rating
1224// ArrValues[4] = all avg rating
1225//
1226// All avg stars have class 	.wppa-avg-'+mocc+'-'+value
1227// My stars have class 			.wppa-rate-'+mocc+'-'+value
1228										_wppaSetRd( mocc, ArrValues[4], '.wppa-avg-' );
1229										_wppaSetRd( mocc, ArrValues[3], '.wppa-rate-' );
1230
1231										// Reload?
1232										if ( reloadAfter ) {
1233			//								document.location.reload(true);
1234											return;
1235										}
1236
1237										// Shift to next slide?
1238										if ( wppaNextOnCallback ) wppaOvlShowNext();
1239									}
1240								},
1241					error: 		function( xhr, status, error ) {
1242									wppaConsoleLog( '_wppaOvlRateIt failed. Error = ' + error + ', status = ' + status );
1243								},
1244				} );
1245
1246}
1247
1248// Download an album
1249function wppaAjaxDownloadAlbum( mocc, id ) {
1250
1251	jQuery.ajax( { 	url: 		wppaAjaxUrl,
1252					data: 		'action=wppa' +
1253								'&wppa-action=downloadalbum' +
1254								'&album-id=' + id,
1255					async: 		true,
1256					type: 		'GET',
1257					timeout: 	120000,
1258					beforeSend: function( xhr ) {
1259
1260									if ( wppaAjaxMethod == 'rest' ) {
1261										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1262									}
1263
1264									// Show spinner
1265									jQuery( '#dwnspin-'+mocc+'-'+id ).css( 'display', '' );
1266								},
1267					success: 	function( xresult, status, xhr ) {
1268									var result;
1269									if ( xresult.txt ) {
1270										result = xresult.txt;
1271									}
1272									else {
1273										theResult = JSON.parse( xresult );
1274										result = theResult.txt;
1275									}
1276
1277									// Analyze the result
1278									var ArrValues = result.split( "||" );
1279									var url 	= ArrValues[0];
1280									var erok 	= ArrValues[1];
1281									var text 	= ArrValues[2];
1282
1283									if ( ArrValues.length == 3 && text != '' ) {
1284										alert( __( 'Attention', 'wp-photo-album-plus' )+':\n\n'+text );
1285									}
1286
1287									if ( erok == 'OK' ) {
1288										document.location = url;
1289									}
1290
1291									else {	// See if a ( partial ) zipfile has been created
1292										alert( __( 'The server could not complete the request. Please try again.', 'wp-photo-album-plus' ) );
1293									}
1294								},
1295					error: 		function( xhr, status, error ) {
1296									alert( 'An error occurred:\n'+error+'\nPlease try again' );
1297								},
1298					complete: 	function( xhr, status, newurl ) {
1299
1300									// Hide spinner
1301									jQuery( '#dwnspin-'+mocc+'-'+id ).css( 'display', 'none' );
1302								}
1303				} );
1304}
1305
1306// Enter a comment to a photo
1307function wppaAjaxComment( mocc, id ) {
1308
1309	// Validate comment else return
1310	if ( ! _wppaValidateComment( mocc, id ) ) return;
1311
1312	// Make the Ajax send data
1313	var theComment = jQuery( "#wppa-comment-"+mocc ).val();
1314	theComment = theComment.replace(/&/g,'%26');
1315	theComment = theComment.replace(/</g,'\\<');
1316	theComment = theComment.replace(/>/g,'\\>');
1317
1318	var data = { photoid: id,
1319				 comname: jQuery( "#wppa-comname-"+mocc ).val(),
1320				 comment: theComment,
1321				 captcha: jQuery( "#wppa-captcha-"+mocc ).val(),
1322				 nonce: jQuery( "#wppa-nonce" ).val(),
1323				 occur: mocc,
1324				 comemail: jQuery( "#wppa-comemail-"+mocc ).val(),
1325				 comid: jQuery( "#wppa-comment-edit-"+mocc ).val(),
1326				 returnurl: encodeURIComponent(jQuery( "#wppa-returnurl-"+mocc ).val()),
1327				 dbagree: jQuery( "#db-agree-" + mocc ).prop( 'checked' ) ? 'yes' : 'no'
1328	};
1329	var theData = JSON.stringify( data );
1330
1331	// Do the ajax commit
1332	jQuery.ajax( { 	url: 		wppaAjaxUrl + '?action=wppa&wppa-action=do-comment',
1333					data: 		'data='+theData,
1334					async: 		true,
1335					type: 		'POST',
1336					timeout: 	60000,
1337					beforeSend: function( xhr ) {
1338
1339									if ( wppaAjaxMethod == 'rest' ) {
1340										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1341									}
1342
1343									// Show spinner
1344									jQuery( "#wppa-comment-spin-"+mocc ).css( 'display', 'inline' );
1345								},
1346					success: 	function( xresult, status, xhr ) {
1347									var result;
1348									if ( xresult.txt ) {
1349										result = xresult.txt;
1350									}
1351									else {
1352										theResult = JSON.parse( xresult );
1353										result = theResult.txt;
1354									}
1355
1356									// sanitize
1357									if ( result ) {
1358										result = result.replace( /\\/g, '' );
1359
1360										// Show result
1361										jQuery( "#wppa-comments-"+mocc ).html( result );
1362
1363										// if from slideshow, update memory data array
1364										if ( _wppaCurIdx[mocc] ) {
1365											_wppaCommentHtml[mocc][_wppaCurIdx[mocc]] = result;
1366										}
1367									}
1368
1369									// Make sure comments are visible
1370									wppaOpenComments( mocc );
1371								},
1372					error: 		function( xhr, status, error ) {
1373									wppaConsoleLog( 'wppaAjaxComment failed. Error = ' + error + ', status = ' + status );
1374								},
1375					complete: 	function( xhr, status, newurl ) {
1376
1377									// Hide spinner
1378									jQuery( "#wppa-comment-spin-"+mocc ).css( 'display', 'none' );
1379								}
1380				} );
1381}
1382
1383// New style front-end edit photo
1384function wppaUpdatePhotoNew(id,mocc) {
1385
1386	var myItems = [ 'upn-album',
1387					'upn-name',
1388					'upn-description',
1389					'upn-tags',
1390					'custom_0',
1391					'custom_1',
1392					'custom_2',
1393					'custom_3',
1394					'custom_4',
1395					'custom_5',
1396					'custom_6',
1397					'custom_7',
1398					'custom_8',
1399					'custom_9',
1400					];
1401
1402	var myData = 	'action=wppa' +
1403					'&wppa-action=update-photo-new' +
1404					'&photo-id=' + id +
1405					'&wppa-nonce=' + jQuery('#wppa-nonce-'+id).val();
1406
1407	var i = 0;
1408	var tMceContent = '';
1409	while ( i < myItems.length ) {
1410		if ( typeof(jQuery('#'+myItems[i] ).val() ) != 'undefined' ) {
1411			myData += '&' + myItems[i] + '=' + jQuery('#'+myItems[i]).val();
1412		}
1413
1414		tMceContent = wppaGetTinyMceContent(myItems[i]);
1415		if ( typeof(tMceContent) != 'undefined' ) {
1416			myData += '&' + myItems[i] + '=' + tMceContent;
1417		}
1418
1419		i++;
1420	}
1421	if ( jQuery('#upn-reload').prop('checked') ) {
1422		myData += '&upn-reload=on';
1423	}
1424// console.log(myData);
1425myData.replaceAll("'", "%047");
1426// console.log(myData);
1427
1428	jQuery.ajax( { 	url: 		wppaAjaxUrl,
1429					data: 		myData,
1430					async: 		true,
1431					type: 		'POST',
1432					timeout: 	10000,
1433					beforeSend: function(xhr) {
1434									if ( wppaAjaxMethod == 'rest' ) {
1435										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1436									}
1437								},
1438					success: 	function( xresult, status, xhr ) {
1439									var result;
1440									if ( typeof( xresult ) == 'object' ) {
1441										result = xresult;
1442									}
1443									else {
1444										result = JSON.parse( xresult );
1445									}
1446
1447									if ( result.error ) {
1448										wppaConsoleLog('Failed to report updates', 'force' );
1449										alert(result.error);
1450									}
1451									else {
1452
1453										if ( typeof(result.description) != 'undefined' ) jQuery('.sdd-'+mocc).html(result.description);
1454										if ( typeof(result.name) != 'undefined' ) jQuery('.sdn-'+mocc).html(result.name);
1455										if ( typeof(result.fullname) != 'undefined' ) jQuery('.sdf-'+mocc).html(result.fullname);
1456
1457										if ( _wppaNames[mocc] ) { // For slideshow only
1458											if ( typeof(result.name) != 'undefined' ) _wppaNames[mocc][_wppaCurIdx[mocc]] 	= wppaFixHtml(result.name);
1459											if ( typeof(result.fullname) != 'undefined' ) _wppaFullNames[mocc][_wppaCurIdx[mocc]] = wppaFixHtml(result.fullname);
1460											if ( typeof(result.description) != 'undefined' ) _wppaDsc[mocc][_wppaCurIdx[mocc]] 		= wppaFixHtml(result.description);
1461
1462											jQuery( "#imagetitle-"+mocc ).html( wppaMakeNameHtml( mocc ) );
1463										}
1464									}
1465								},
1466					error: 		function( xhr, status, error ) {
1467
1468									wppaConsoleLog( 'wppaUpdatePhotoNew failed. Error = ' + error + ', status = ' + status );
1469								},
1470					complete: 	function( xhr, status, newurl ) {
1471
1472									if ( jQuery('#upn-reload').prop('checked') ) {
1473										document.location.reload(true);
1474									}
1475									else {
1476										jQuery('#wppa-modal-container-'+mocc).dialog('close');
1477										jQuery('#wppa-modal-container-'+mocc).html('');
1478									}
1479								}
1480				} );
1481}
1482
1483function wppaFixHtml( txt ) {
1484
1485	if ( ! txt ) return '';
1486
1487	txt = txt.replace(/\[/g, '<'); // [ to <
1488	txt = txt.replace(/\]/g, '>'); // ] to >
1489	txt = txt.replace(/&quot;/g, '"'); //
1490	txt = txt.replace(/\\n/g, ' '); // \n to space
1491
1492	return txt;
1493}
1494
1495var wppaLastQrcodeUrl = '';
1496// Get qrcode and put it as src in elm
1497function wppaAjaxSetQrCodeSrc( url, elm ) {
1498
1499	// Does target element exist?
1500	if ( jQuery(elm).length == 0 ) {
1501		return;
1502	}
1503
1504	// Been here before with this url?
1505	if ( wppaLastQrcodeUrl == url ) {
1506		return;
1507	}
1508
1509	// Remember this
1510	wppaLastQrcodeUrl = url;
1511
1512	var myData = 	'action=wppa' +
1513					'&wppa-action=getqrcode' +
1514					'&wppa-qr-nonce=' + jQuery( '#wppa-qr-nonce' ).val() +
1515					'&url=' + encodeURIComponent( url );
1516
1517	jQuery.ajax( {	url: 		wppaAjaxUrl,
1518					data: 		myData,
1519					async: 		true,
1520					type: 		'POST',
1521					timeout: 	10000,
1522					beforeSend: function(xhr) {
1523									if ( wppaAjaxMethod == 'rest' ) {
1524										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1525									}
1526								},
1527					success: 	function( xresult, status, xhr ) {
1528									var result;
1529									if ( wppaAjaxMethod == 'rest' ) {
1530										result = xresult.txt;
1531									}
1532									else {
1533										theResult = JSON.parse( xresult );
1534										result = theResult.txt;
1535									}
1536									var temp = result.split('|');
1537									jQuery( elm ).attr( 'src', temp[0] ); //document.getElementById( elm ).src = temp[0];
1538									jQuery( elm ).attr( 'title', temp[1] );
1539								},
1540					error: 		function( xhr, status, error ) {
1541									wppaConsoleLog( 'wppaAjaxSetQrCodeSrc failed. Error = ' + error + ', status = ' + status );
1542								}
1543				} );
1544}
1545
1546// Add/remove a user to a mailinglist
1547function wppaAjaxNotify( elm, list, user ) {
1548
1549	var onoff  = 	jQuery( elm ).prop( 'checked' ) ? 'on' : 'off';
1550	var myData = 	'action=wppa' +
1551					'&wppa-action=mailinglist' +
1552					'&wppa-ntfy-nonce=' + jQuery( '#wppa-ntfy-nonce' ).val() +
1553					'&list=' + list +
1554					'&onoff=' + onoff;
1555					if ( user ) {
1556						myData += '&wppa-user='+user;
1557					}
1558
1559	jQuery.ajax( {	url: 		wppaAdminAjaxUrl,
1560					data: 		myData,
1561					async: 		true,
1562					type: 		'POST',
1563					timeout: 	10000,
1564					beforeSend: function(xhr) {
1565
1566						//			if ( wppaAjaxMethod == 'rest' ) {
1567						//				xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1568						//			}
1569
1570									if ( user ) {
1571										jQuery("#img_"+list+"-"+user).attr('src',wppaImageDirectory+'spinner.gif');
1572									}
1573								},
1574					success: 	function( result, status, xhr ) {
1575						/*
1576									var result;
1577									if ( wppaAjaxMethod == 'rest' ) {
1578										result = xresult.txt;
1579									}
1580									else {
1581										theResult = JSON.parse( xresult );
1582										result = theResult.txt;
1583									}
1584						*/
1585									if ( user ) {
1586						//				wppaConsoleLog( result, 'force' );
1587										jQuery("#img_"+list+"-"+user).attr('src',wppaImageDirectory+'tick.png');
1588									}
1589								},
1590					error: 		function( xhr, status, error ) {
1591									wppaConsoleLog( 'wppaAjaxNotify failed. Error = ' + error + ', status = ' + status );
1592									jQuery("#img_"+list+"-"+user).attr('src',wppaImageDirectory+'cross.png');
1593								}
1594				} );
1595}
1596
1597// Supersearch function get iptc list
1598function wppaAjaxGetSsIptcList( mocc, s3, selid, retry ) {
1599
1600	wppaAjaxGetSsIptcExifList( mocc, s3, selid, retry, 'iptc' );
1601}
1602
1603// Supersearch function get exif list
1604function wppaAjaxGetSsExifList( mocc, s3, selid, retry ) {
1605
1606	wppaAjaxGetSsIptcExifList( mocc, s3, selid, retry, 'exif' );
1607}
1608
1609// Common function that does the job
1610function wppaAjaxGetSsIptcExifList( mocc, s3, selid, retry, tagtype ) {
1611
1612	ajaxurl = wppaAjaxUrl;
1613
1614	ajaxurl += '?action=wppa&wppa-action=getss' + tagtype + 'list&' + tagtype + 'tag=' + s3 + '&occur=' + mocc;
1615	jQuery.ajax( { 	url: 		ajaxurl,
1616					async: 		true,
1617					type: 		'GET',
1618					timeout: 	10000,
1619					beforeSend: function( xhr ) {
1620
1621									if ( wppaAjaxMethod == 'rest' ) {
1622										xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1623									}
1624
1625									jQuery( '#wppa-ss-spinner-'+mocc ).css('display', '');
1626								},
1627					success: 	function( xresult, status, xhr ) {
1628									var result;
1629									if ( wppaAjaxMethod == 'rest' ) {
1630										result = xresult.txt;
1631									}
1632									else {
1633										theResult = JSON.parse( xresult );
1634										result = theResult.txt;
1635									}
1636									jQuery( '#'+selid ).html( result );
1637									jQuery( '#wppa-ss-'+tagtype+'opts-'+mocc ).css('display', '');
1638									wppaSuperSearchSelect( mocc );
1639									setTimeout('wppaSetIptcExifSize( ".wppa-'+tagtype+'list-'+mocc+'", "#'+selid+'" )', 10 );
1640									if (retry) {
1641										wppaConsoleLog('wppaAjaxGetSs'+tagtype+'List success after retry.');
1642									}
1643								},
1644					error: 		function( xhr, status, error ) {
1645									wppaConsoleLog('wppaAjaxGetSs'+tagtype+'List failed. Error = ' + error + ', status = ' + status );
1646									if (!retry) wppaAjaxGetSsIptcExifList( mocc, s3, selid, true, tagtype );
1647								},
1648					complete: 	function( xhr, status, newurl ) {
1649									jQuery( '#wppa-ss-spinner-'+mocc ).css('display', 'none');
1650								}
1651				} );
1652}
1653
1654// If a dialog is already open, close it first
1655function wppaPrepareModal(mocc) {
1656
1657	try {
1658		jQuery('#wppa-modal-container-'+mocc).dialog('destroy');
1659		jQuery('#wppa-modal-container-'+mocc).html('');
1660	}
1661	catch(e) {
1662		jQuery('#wppa-modal-container-'+mocc).html('');
1663	}
1664}
1665
1666// Register a download
1667function wppaAjaxBumpDownloadCount(id) {
1668
1669	jQuery.ajax( { 	url: 	wppaAjaxUrl,
1670				data: 		'action=wppa' +
1671							'&wppa-action=bumpdownloadcount' +
1672							'&wppa-photo=' + id +
1673							'&wppa-nonce=' + jQuery( '#wppa-nonce' ).val(),
1674				async: 		true,
1675				type: 		'GET',
1676				timeout: 	60000,
1677				beforeSend: function(xhr) {
1678								if ( wppaAjaxMethod == 'rest' ) {
1679									xhr.setRequestHeader( 'X-WP-NONCE', wppaObj.restNonce );
1680								}
1681							},
1682				success: 	function( result, status, xhr ) {
1683								// wppaPhotoView[photo] = true;
1684							},
1685				error: 		function( xhr, status, error ) {
1686								wppaConsoleLog( 'wppaAjaxBumpDownloadCount. Error = ' + error + ', status = ' + status );
1687							},
1688			} );
1689}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.