Version Description
Download this release
Release Info
Developer | netweblogic |
Plugin | Login With Ajax |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- form.js +632 -0
- login-with-ajax-admin.php +105 -0
- login-with-ajax.js +45 -0
- login-with-ajax.php +145 -0
- readme.txt +58 -0
- screenshot-1.jpg +0 -0
- screenshot-2.jpg +0 -0
- screenshot-3.jpg +0 -0
- screenshot-4.jpg +0 -0
- screenshot-5.jpg +0 -0
- widget/loading.gif +0 -0
- widget/widget.css +15 -0
- widget/widget_in.php +82 -0
- widget/widget_out.php +69 -0
form.js
ADDED
@@ -0,0 +1,632 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* jQuery Form Plugin
|
3 |
+
* version: 2.18 (06-JAN-2009)
|
4 |
+
* @requires jQuery v1.2.2 or later
|
5 |
+
*
|
6 |
+
* Examples and documentation at: http://malsup.com/jquery/form/
|
7 |
+
* Dual licensed under the MIT and GPL licenses:
|
8 |
+
* http://www.opensource.org/licenses/mit-license.php
|
9 |
+
* http://www.gnu.org/licenses/gpl.html
|
10 |
+
*
|
11 |
+
* Revision: $Id: jquery.form.js 6061 2009-01-07 01:43:18Z malsup $
|
12 |
+
*/
|
13 |
+
;(function($) {
|
14 |
+
|
15 |
+
/*
|
16 |
+
Usage Note:
|
17 |
+
-----------
|
18 |
+
Do not use both ajaxSubmit and ajaxForm on the same form. These
|
19 |
+
functions are intended to be exclusive. Use ajaxSubmit if you want
|
20 |
+
to bind your own submit handler to the form. For example,
|
21 |
+
|
22 |
+
$(document).ready(function() {
|
23 |
+
$('#myForm').bind('submit', function() {
|
24 |
+
$(this).ajaxSubmit({
|
25 |
+
target: '#output'
|
26 |
+
});
|
27 |
+
return false; // <-- important!
|
28 |
+
});
|
29 |
+
});
|
30 |
+
|
31 |
+
Use ajaxForm when you want the plugin to manage all the event binding
|
32 |
+
for you. For example,
|
33 |
+
|
34 |
+
$(document).ready(function() {
|
35 |
+
$('#myForm').ajaxForm({
|
36 |
+
target: '#output'
|
37 |
+
});
|
38 |
+
});
|
39 |
+
|
40 |
+
When using ajaxForm, the ajaxSubmit function will be invoked for you
|
41 |
+
at the appropriate time.
|
42 |
+
*/
|
43 |
+
|
44 |
+
/**
|
45 |
+
* ajaxSubmit() provides a mechanism for immediately submitting
|
46 |
+
* an HTML form using AJAX.
|
47 |
+
*/
|
48 |
+
$.fn.ajaxSubmit = function(options) {
|
49 |
+
// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
|
50 |
+
if (!this.length) {
|
51 |
+
log('ajaxSubmit: skipping submit process - no element selected');
|
52 |
+
return this;
|
53 |
+
}
|
54 |
+
|
55 |
+
if (typeof options == 'function')
|
56 |
+
options = { success: options };
|
57 |
+
|
58 |
+
options = $.extend({
|
59 |
+
url: this.attr('action') || window.location.toString(),
|
60 |
+
type: this.attr('method') || 'GET'
|
61 |
+
}, options || {});
|
62 |
+
|
63 |
+
// hook for manipulating the form data before it is extracted;
|
64 |
+
// convenient for use with rich editors like tinyMCE or FCKEditor
|
65 |
+
var veto = {};
|
66 |
+
this.trigger('form-pre-serialize', [this, options, veto]);
|
67 |
+
if (veto.veto) {
|
68 |
+
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
|
69 |
+
return this;
|
70 |
+
}
|
71 |
+
|
72 |
+
// provide opportunity to alter form data before it is serialized
|
73 |
+
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
|
74 |
+
log('ajaxSubmit: submit aborted via beforeSerialize callback');
|
75 |
+
return this;
|
76 |
+
}
|
77 |
+
|
78 |
+
var a = this.formToArray(options.semantic);
|
79 |
+
if (options.data) {
|
80 |
+
options.extraData = options.data;
|
81 |
+
for (var n in options.data) {
|
82 |
+
if(options.data[n] instanceof Array) {
|
83 |
+
for (var k in options.data[n])
|
84 |
+
a.push( { name: n, value: options.data[n][k] } )
|
85 |
+
}
|
86 |
+
else
|
87 |
+
a.push( { name: n, value: options.data[n] } );
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
// give pre-submit callback an opportunity to abort the submit
|
92 |
+
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
|
93 |
+
log('ajaxSubmit: submit aborted via beforeSubmit callback');
|
94 |
+
return this;
|
95 |
+
}
|
96 |
+
|
97 |
+
// fire vetoable 'validate' event
|
98 |
+
this.trigger('form-submit-validate', [a, this, options, veto]);
|
99 |
+
if (veto.veto) {
|
100 |
+
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
|
101 |
+
return this;
|
102 |
+
}
|
103 |
+
|
104 |
+
var q = $.param(a);
|
105 |
+
|
106 |
+
if (options.type.toUpperCase() == 'GET') {
|
107 |
+
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
|
108 |
+
options.data = null; // data is null for 'get'
|
109 |
+
}
|
110 |
+
else
|
111 |
+
options.data = q; // data is the query string for 'post'
|
112 |
+
|
113 |
+
var $form = this, callbacks = [];
|
114 |
+
if (options.resetForm) callbacks.push(function() { $form.resetForm(); });
|
115 |
+
if (options.clearForm) callbacks.push(function() { $form.clearForm(); });
|
116 |
+
|
117 |
+
// perform a load on the target only if dataType is not provided
|
118 |
+
if (!options.dataType && options.target) {
|
119 |
+
var oldSuccess = options.success || function(){};
|
120 |
+
callbacks.push(function(data) {
|
121 |
+
$(options.target).html(data).each(oldSuccess, arguments);
|
122 |
+
});
|
123 |
+
}
|
124 |
+
else if (options.success)
|
125 |
+
callbacks.push(options.success);
|
126 |
+
|
127 |
+
options.success = function(data, status) {
|
128 |
+
for (var i=0, max=callbacks.length; i < max; i++)
|
129 |
+
callbacks[i].apply(options, [data, status, $form]);
|
130 |
+
};
|
131 |
+
|
132 |
+
// are there files to upload?
|
133 |
+
var files = $('input:file', this).fieldValue();
|
134 |
+
var found = false;
|
135 |
+
for (var j=0; j < files.length; j++)
|
136 |
+
if (files[j])
|
137 |
+
found = true;
|
138 |
+
|
139 |
+
// options.iframe allows user to force iframe mode
|
140 |
+
if (options.iframe || found) {
|
141 |
+
// hack to fix Safari hang (thanks to Tim Molendijk for this)
|
142 |
+
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
|
143 |
+
if ($.browser.safari && options.closeKeepAlive)
|
144 |
+
$.get(options.closeKeepAlive, fileUpload);
|
145 |
+
else
|
146 |
+
fileUpload();
|
147 |
+
}
|
148 |
+
else
|
149 |
+
$.ajax(options);
|
150 |
+
|
151 |
+
// fire 'notify' event
|
152 |
+
this.trigger('form-submit-notify', [this, options]);
|
153 |
+
return this;
|
154 |
+
|
155 |
+
|
156 |
+
// private function for handling file uploads (hat tip to YAHOO!)
|
157 |
+
function fileUpload() {
|
158 |
+
var form = $form[0];
|
159 |
+
|
160 |
+
if ($(':input[name=submit]', form).length) {
|
161 |
+
alert('Error: Form elements must not be named "submit".');
|
162 |
+
return;
|
163 |
+
}
|
164 |
+
|
165 |
+
var opts = $.extend({}, $.ajaxSettings, options);
|
166 |
+
var s = jQuery.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);
|
167 |
+
|
168 |
+
var id = 'jqFormIO' + (new Date().getTime());
|
169 |
+
var $io = $('<iframe id="' + id + '" name="' + id + '" />');
|
170 |
+
var io = $io[0];
|
171 |
+
|
172 |
+
if ($.browser.msie || $.browser.opera)
|
173 |
+
io.src = 'javascript:false;document.write("");';
|
174 |
+
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
175 |
+
|
176 |
+
var xhr = { // mock object
|
177 |
+
aborted: 0,
|
178 |
+
responseText: null,
|
179 |
+
responseXML: null,
|
180 |
+
status: 0,
|
181 |
+
statusText: 'n/a',
|
182 |
+
getAllResponseHeaders: function() {},
|
183 |
+
getResponseHeader: function() {},
|
184 |
+
setRequestHeader: function() {},
|
185 |
+
abort: function() {
|
186 |
+
this.aborted = 1;
|
187 |
+
$io.attr('src','about:blank'); // abort op in progress
|
188 |
+
}
|
189 |
+
};
|
190 |
+
|
191 |
+
var g = opts.global;
|
192 |
+
// trigger ajax global events so that activity/block indicators work like normal
|
193 |
+
if (g && ! $.active++) $.event.trigger("ajaxStart");
|
194 |
+
if (g) $.event.trigger("ajaxSend", [xhr, opts]);
|
195 |
+
|
196 |
+
if (s.beforeSend && s.beforeSend(xhr, s) === false) {
|
197 |
+
s.global && jQuery.active--;
|
198 |
+
return;
|
199 |
+
}
|
200 |
+
if (xhr.aborted)
|
201 |
+
return;
|
202 |
+
|
203 |
+
var cbInvoked = 0;
|
204 |
+
var timedOut = 0;
|
205 |
+
|
206 |
+
// add submitting element to data if we know it
|
207 |
+
var sub = form.clk;
|
208 |
+
if (sub) {
|
209 |
+
var n = sub.name;
|
210 |
+
if (n && !sub.disabled) {
|
211 |
+
options.extraData = options.extraData || {};
|
212 |
+
options.extraData[n] = sub.value;
|
213 |
+
if (sub.type == "image") {
|
214 |
+
options.extraData[name+'.x'] = form.clk_x;
|
215 |
+
options.extraData[name+'.y'] = form.clk_y;
|
216 |
+
}
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
// take a breath so that pending repaints get some cpu time before the upload starts
|
221 |
+
setTimeout(function() {
|
222 |
+
// make sure form attrs are set
|
223 |
+
var t = $form.attr('target'), a = $form.attr('action');
|
224 |
+
$form.attr({
|
225 |
+
target: id,
|
226 |
+
method: 'POST',
|
227 |
+
action: opts.url
|
228 |
+
});
|
229 |
+
|
230 |
+
// ie borks in some cases when setting encoding
|
231 |
+
if (! options.skipEncodingOverride) {
|
232 |
+
$form.attr({
|
233 |
+
encoding: 'multipart/form-data',
|
234 |
+
enctype: 'multipart/form-data'
|
235 |
+
});
|
236 |
+
}
|
237 |
+
|
238 |
+
// support timout
|
239 |
+
if (opts.timeout)
|
240 |
+
setTimeout(function() { timedOut = true; cb(); }, opts.timeout);
|
241 |
+
|
242 |
+
// add "extra" data to form if provided in options
|
243 |
+
var extraInputs = [];
|
244 |
+
try {
|
245 |
+
if (options.extraData)
|
246 |
+
for (var n in options.extraData)
|
247 |
+
extraInputs.push(
|
248 |
+
$('<input type="hidden" name="'+n+'" value="'+options.extraData[n]+'" />')
|
249 |
+
.appendTo(form)[0]);
|
250 |
+
|
251 |
+
// add iframe to doc and submit the form
|
252 |
+
$io.appendTo('body');
|
253 |
+
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
|
254 |
+
form.submit();
|
255 |
+
}
|
256 |
+
finally {
|
257 |
+
// reset attrs and remove "extra" input elements
|
258 |
+
$form.attr('action', a);
|
259 |
+
t ? $form.attr('target', t) : $form.removeAttr('target');
|
260 |
+
$(extraInputs).remove();
|
261 |
+
}
|
262 |
+
}, 10);
|
263 |
+
|
264 |
+
function cb() {
|
265 |
+
if (cbInvoked++) return;
|
266 |
+
|
267 |
+
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
|
268 |
+
|
269 |
+
var operaHack = 0;
|
270 |
+
var ok = true;
|
271 |
+
try {
|
272 |
+
if (timedOut) throw 'timeout';
|
273 |
+
// extract the server response from the iframe
|
274 |
+
var data, doc;
|
275 |
+
|
276 |
+
doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
|
277 |
+
|
278 |
+
if (doc.body == null && !operaHack && $.browser.opera) {
|
279 |
+
// In Opera 9.2.x the iframe DOM is not always traversable when
|
280 |
+
// the onload callback fires so we give Opera 100ms to right itself
|
281 |
+
operaHack = 1;
|
282 |
+
cbInvoked--;
|
283 |
+
setTimeout(cb, 100);
|
284 |
+
return;
|
285 |
+
}
|
286 |
+
|
287 |
+
xhr.responseText = doc.body ? doc.body.innerHTML : null;
|
288 |
+
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
289 |
+
xhr.getResponseHeader = function(header){
|
290 |
+
var headers = {'content-type': opts.dataType};
|
291 |
+
return headers[header];
|
292 |
+
};
|
293 |
+
|
294 |
+
if (opts.dataType == 'json' || opts.dataType == 'script') {
|
295 |
+
var ta = doc.getElementsByTagName('textarea')[0];
|
296 |
+
xhr.responseText = ta ? ta.value : xhr.responseText;
|
297 |
+
}
|
298 |
+
else if (opts.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
|
299 |
+
xhr.responseXML = toXml(xhr.responseText);
|
300 |
+
}
|
301 |
+
data = $.httpData(xhr, opts.dataType);
|
302 |
+
}
|
303 |
+
catch(e){
|
304 |
+
ok = false;
|
305 |
+
$.handleError(opts, xhr, 'error', e);
|
306 |
+
}
|
307 |
+
|
308 |
+
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
309 |
+
if (ok) {
|
310 |
+
opts.success(data, 'success');
|
311 |
+
if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
|
312 |
+
}
|
313 |
+
if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
|
314 |
+
if (g && ! --$.active) $.event.trigger("ajaxStop");
|
315 |
+
if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
|
316 |
+
|
317 |
+
// clean up
|
318 |
+
setTimeout(function() {
|
319 |
+
$io.remove();
|
320 |
+
xhr.responseXML = null;
|
321 |
+
}, 100);
|
322 |
+
};
|
323 |
+
|
324 |
+
function toXml(s, doc) {
|
325 |
+
if (window.ActiveXObject) {
|
326 |
+
doc = new ActiveXObject('Microsoft.XMLDOM');
|
327 |
+
doc.async = 'false';
|
328 |
+
doc.loadXML(s);
|
329 |
+
}
|
330 |
+
else
|
331 |
+
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
332 |
+
return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
|
333 |
+
};
|
334 |
+
};
|
335 |
+
};
|
336 |
+
|
337 |
+
/**
|
338 |
+
* ajaxForm() provides a mechanism for fully automating form submission.
|
339 |
+
*
|
340 |
+
* The advantages of using this method instead of ajaxSubmit() are:
|
341 |
+
*
|
342 |
+
* 1: This method will include coordinates for <input type="image" /> elements (if the element
|
343 |
+
* is used to submit the form).
|
344 |
+
* 2. This method will include the submit element's name/value data (for the element that was
|
345 |
+
* used to submit the form).
|
346 |
+
* 3. This method binds the submit() method to the form for you.
|
347 |
+
*
|
348 |
+
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
|
349 |
+
* passes the options argument along after properly binding events for submit elements and
|
350 |
+
* the form itself.
|
351 |
+
*/
|
352 |
+
$.fn.ajaxForm = function(options) {
|
353 |
+
return this.ajaxFormUnbind().bind('submit.form-plugin',function() {
|
354 |
+
$(this).ajaxSubmit(options);
|
355 |
+
return false;
|
356 |
+
}).each(function() {
|
357 |
+
// store options in hash
|
358 |
+
$(":submit,input:image", this).bind('click.form-plugin',function(e) {
|
359 |
+
var form = this.form;
|
360 |
+
form.clk = this;
|
361 |
+
if (this.type == 'image') {
|
362 |
+
if (e.offsetX != undefined) {
|
363 |
+
form.clk_x = e.offsetX;
|
364 |
+
form.clk_y = e.offsetY;
|
365 |
+
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
|
366 |
+
var offset = $(this).offset();
|
367 |
+
form.clk_x = e.pageX - offset.left;
|
368 |
+
form.clk_y = e.pageY - offset.top;
|
369 |
+
} else {
|
370 |
+
form.clk_x = e.pageX - this.offsetLeft;
|
371 |
+
form.clk_y = e.pageY - this.offsetTop;
|
372 |
+
}
|
373 |
+
}
|
374 |
+
// clear form vars
|
375 |
+
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10);
|
376 |
+
});
|
377 |
+
});
|
378 |
+
};
|
379 |
+
|
380 |
+
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
|
381 |
+
$.fn.ajaxFormUnbind = function() {
|
382 |
+
this.unbind('submit.form-plugin');
|
383 |
+
return this.each(function() {
|
384 |
+
$(":submit,input:image", this).unbind('click.form-plugin');
|
385 |
+
});
|
386 |
+
|
387 |
+
};
|
388 |
+
|
389 |
+
/**
|
390 |
+
* formToArray() gathers form element data into an array of objects that can
|
391 |
+
* be passed to any of the following ajax functions: $.get, $.post, or load.
|
392 |
+
* Each object in the array has both a 'name' and 'value' property. An example of
|
393 |
+
* an array for a simple login form might be:
|
394 |
+
*
|
395 |
+
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
396 |
+
*
|
397 |
+
* It is this array that is passed to pre-submit callback functions provided to the
|
398 |
+
* ajaxSubmit() and ajaxForm() methods.
|
399 |
+
*/
|
400 |
+
$.fn.formToArray = function(semantic) {
|
401 |
+
var a = [];
|
402 |
+
if (this.length == 0) return a;
|
403 |
+
|
404 |
+
var form = this[0];
|
405 |
+
var els = semantic ? form.getElementsByTagName('*') : form.elements;
|
406 |
+
if (!els) return a;
|
407 |
+
for(var i=0, max=els.length; i < max; i++) {
|
408 |
+
var el = els[i];
|
409 |
+
var n = el.name;
|
410 |
+
if (!n) continue;
|
411 |
+
|
412 |
+
if (semantic && form.clk && el.type == "image") {
|
413 |
+
// handle image inputs on the fly when semantic == true
|
414 |
+
if(!el.disabled && form.clk == el)
|
415 |
+
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
416 |
+
continue;
|
417 |
+
}
|
418 |
+
|
419 |
+
var v = $.fieldValue(el, true);
|
420 |
+
if (v && v.constructor == Array) {
|
421 |
+
for(var j=0, jmax=v.length; j < jmax; j++)
|
422 |
+
a.push({name: n, value: v[j]});
|
423 |
+
}
|
424 |
+
else if (v !== null && typeof v != 'undefined')
|
425 |
+
a.push({name: n, value: v});
|
426 |
+
}
|
427 |
+
|
428 |
+
if (!semantic && form.clk) {
|
429 |
+
// input type=='image' are not found in elements array! handle them here
|
430 |
+
var inputs = form.getElementsByTagName("input");
|
431 |
+
for(var i=0, max=inputs.length; i < max; i++) {
|
432 |
+
var input = inputs[i];
|
433 |
+
var n = input.name;
|
434 |
+
if(n && !input.disabled && input.type == "image" && form.clk == input)
|
435 |
+
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
436 |
+
}
|
437 |
+
}
|
438 |
+
return a;
|
439 |
+
};
|
440 |
+
|
441 |
+
/**
|
442 |
+
* Serializes form data into a 'submittable' string. This method will return a string
|
443 |
+
* in the format: name1=value1&name2=value2
|
444 |
+
*/
|
445 |
+
$.fn.formSerialize = function(semantic) {
|
446 |
+
//hand off to jQuery.param for proper encoding
|
447 |
+
return $.param(this.formToArray(semantic));
|
448 |
+
};
|
449 |
+
|
450 |
+
/**
|
451 |
+
* Serializes all field elements in the jQuery object into a query string.
|
452 |
+
* This method will return a string in the format: name1=value1&name2=value2
|
453 |
+
*/
|
454 |
+
$.fn.fieldSerialize = function(successful) {
|
455 |
+
var a = [];
|
456 |
+
this.each(function() {
|
457 |
+
var n = this.name;
|
458 |
+
if (!n) return;
|
459 |
+
var v = $.fieldValue(this, successful);
|
460 |
+
if (v && v.constructor == Array) {
|
461 |
+
for (var i=0,max=v.length; i < max; i++)
|
462 |
+
a.push({name: n, value: v[i]});
|
463 |
+
}
|
464 |
+
else if (v !== null && typeof v != 'undefined')
|
465 |
+
a.push({name: this.name, value: v});
|
466 |
+
});
|
467 |
+
//hand off to jQuery.param for proper encoding
|
468 |
+
return $.param(a);
|
469 |
+
};
|
470 |
+
|
471 |
+
/**
|
472 |
+
* Returns the value(s) of the element in the matched set. For example, consider the following form:
|
473 |
+
*
|
474 |
+
* <form><fieldset>
|
475 |
+
* <input name="A" type="text" />
|
476 |
+
* <input name="A" type="text" />
|
477 |
+
* <input name="B" type="checkbox" value="B1" />
|
478 |
+
* <input name="B" type="checkbox" value="B2"/>
|
479 |
+
* <input name="C" type="radio" value="C1" />
|
480 |
+
* <input name="C" type="radio" value="C2" />
|
481 |
+
* </fieldset></form>
|
482 |
+
*
|
483 |
+
* var v = $(':text').fieldValue();
|
484 |
+
* // if no values are entered into the text inputs
|
485 |
+
* v == ['','']
|
486 |
+
* // if values entered into the text inputs are 'foo' and 'bar'
|
487 |
+
* v == ['foo','bar']
|
488 |
+
*
|
489 |
+
* var v = $(':checkbox').fieldValue();
|
490 |
+
* // if neither checkbox is checked
|
491 |
+
* v === undefined
|
492 |
+
* // if both checkboxes are checked
|
493 |
+
* v == ['B1', 'B2']
|
494 |
+
*
|
495 |
+
* var v = $(':radio').fieldValue();
|
496 |
+
* // if neither radio is checked
|
497 |
+
* v === undefined
|
498 |
+
* // if first radio is checked
|
499 |
+
* v == ['C1']
|
500 |
+
*
|
501 |
+
* The successful argument controls whether or not the field element must be 'successful'
|
502 |
+
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
503 |
+
* The default value of the successful argument is true. If this value is false the value(s)
|
504 |
+
* for each element is returned.
|
505 |
+
*
|
506 |
+
* Note: This method *always* returns an array. If no valid value can be determined the
|
507 |
+
* array will be empty, otherwise it will contain one or more values.
|
508 |
+
*/
|
509 |
+
$.fn.fieldValue = function(successful) {
|
510 |
+
for (var val=[], i=0, max=this.length; i < max; i++) {
|
511 |
+
var el = this[i];
|
512 |
+
var v = $.fieldValue(el, successful);
|
513 |
+
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
|
514 |
+
continue;
|
515 |
+
v.constructor == Array ? $.merge(val, v) : val.push(v);
|
516 |
+
}
|
517 |
+
return val;
|
518 |
+
};
|
519 |
+
|
520 |
+
/**
|
521 |
+
* Returns the value of the field element.
|
522 |
+
*/
|
523 |
+
$.fieldValue = function(el, successful) {
|
524 |
+
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
|
525 |
+
if (typeof successful == 'undefined') successful = true;
|
526 |
+
|
527 |
+
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
|
528 |
+
(t == 'checkbox' || t == 'radio') && !el.checked ||
|
529 |
+
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
|
530 |
+
tag == 'select' && el.selectedIndex == -1))
|
531 |
+
return null;
|
532 |
+
|
533 |
+
if (tag == 'select') {
|
534 |
+
var index = el.selectedIndex;
|
535 |
+
if (index < 0) return null;
|
536 |
+
var a = [], ops = el.options;
|
537 |
+
var one = (t == 'select-one');
|
538 |
+
var max = (one ? index+1 : ops.length);
|
539 |
+
for(var i=(one ? index : 0); i < max; i++) {
|
540 |
+
var op = ops[i];
|
541 |
+
if (op.selected) {
|
542 |
+
// extra pain for IE...
|
543 |
+
var v = $.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value;
|
544 |
+
if (one) return v;
|
545 |
+
a.push(v);
|
546 |
+
}
|
547 |
+
}
|
548 |
+
return a;
|
549 |
+
}
|
550 |
+
return el.value;
|
551 |
+
};
|
552 |
+
|
553 |
+
/**
|
554 |
+
* Clears the form data. Takes the following actions on the form's input fields:
|
555 |
+
* - input text fields will have their 'value' property set to the empty string
|
556 |
+
* - select elements will have their 'selectedIndex' property set to -1
|
557 |
+
* - checkbox and radio inputs will have their 'checked' property set to false
|
558 |
+
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
559 |
+
* - button elements will *not* be effected
|
560 |
+
*/
|
561 |
+
$.fn.clearForm = function() {
|
562 |
+
return this.each(function() {
|
563 |
+
$('input,select,textarea', this).clearFields();
|
564 |
+
});
|
565 |
+
};
|
566 |
+
|
567 |
+
/**
|
568 |
+
* Clears the selected form elements.
|
569 |
+
*/
|
570 |
+
$.fn.clearFields = $.fn.clearInputs = function() {
|
571 |
+
return this.each(function() {
|
572 |
+
var t = this.type, tag = this.tagName.toLowerCase();
|
573 |
+
if (t == 'text' || t == 'password' || tag == 'textarea')
|
574 |
+
this.value = '';
|
575 |
+
else if (t == 'checkbox' || t == 'radio')
|
576 |
+
this.checked = false;
|
577 |
+
else if (tag == 'select')
|
578 |
+
this.selectedIndex = -1;
|
579 |
+
});
|
580 |
+
};
|
581 |
+
|
582 |
+
/**
|
583 |
+
* Resets the form data. Causes all form elements to be reset to their original value.
|
584 |
+
*/
|
585 |
+
$.fn.resetForm = function() {
|
586 |
+
return this.each(function() {
|
587 |
+
// guard against an input with the name of 'reset'
|
588 |
+
// note that IE reports the reset function as an 'object'
|
589 |
+
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
|
590 |
+
this.reset();
|
591 |
+
});
|
592 |
+
};
|
593 |
+
|
594 |
+
/**
|
595 |
+
* Enables or disables any matching elements.
|
596 |
+
*/
|
597 |
+
$.fn.enable = function(b) {
|
598 |
+
if (b == undefined) b = true;
|
599 |
+
return this.each(function() {
|
600 |
+
this.disabled = !b
|
601 |
+
});
|
602 |
+
};
|
603 |
+
|
604 |
+
/**
|
605 |
+
* Checks/unchecks any matching checkboxes or radio buttons and
|
606 |
+
* selects/deselects and matching option elements.
|
607 |
+
*/
|
608 |
+
$.fn.selected = function(select) {
|
609 |
+
if (select == undefined) select = true;
|
610 |
+
return this.each(function() {
|
611 |
+
var t = this.type;
|
612 |
+
if (t == 'checkbox' || t == 'radio')
|
613 |
+
this.checked = select;
|
614 |
+
else if (this.tagName.toLowerCase() == 'option') {
|
615 |
+
var $sel = $(this).parent('select');
|
616 |
+
if (select && $sel[0] && $sel[0].type == 'select-one') {
|
617 |
+
// deselect all other options
|
618 |
+
$sel.find('option').selected(false);
|
619 |
+
}
|
620 |
+
this.selected = select;
|
621 |
+
}
|
622 |
+
});
|
623 |
+
};
|
624 |
+
|
625 |
+
// helper fn for console logging
|
626 |
+
// set $.fn.ajaxSubmit.debug to true to enable debug logging
|
627 |
+
function log() {
|
628 |
+
if ($.fn.ajaxSubmit.debug && window.console && window.console.log)
|
629 |
+
window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
|
630 |
+
};
|
631 |
+
|
632 |
+
})(jQuery);
|
login-with-ajax-admin.php
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright (C) 2009 NetWebLogic LLC
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 3 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
+
*/
|
18 |
+
|
19 |
+
// Class initialization
|
20 |
+
class LWA{
|
21 |
+
// action function for above hook
|
22 |
+
function LWA() {
|
23 |
+
$page = add_options_page('Login With Ajax', 'Login With Ajax', 8, 'login-with-ajax', array(&$this,'options'));
|
24 |
+
}
|
25 |
+
|
26 |
+
function options() {
|
27 |
+
add_option('lwa_data');
|
28 |
+
$lwa_data = array();
|
29 |
+
|
30 |
+
if( is_admin() and $_POST['lwasubmitted']==1 ){
|
31 |
+
//Build the array of options here
|
32 |
+
if(!$errors){
|
33 |
+
foreach ($_POST as $postKey => $postValue){
|
34 |
+
if( substr($postKey, 0, 4) == 'lwa_' ){
|
35 |
+
//For now, no validation, since this is in admin area.
|
36 |
+
if($postValue != ''){
|
37 |
+
$lwa_data[substr($postKey, 4)] = $postValue;
|
38 |
+
}
|
39 |
+
}
|
40 |
+
}
|
41 |
+
update_option('lwa_data', $lwa_data);
|
42 |
+
?>
|
43 |
+
<div class="updated"><p><strong><?php _e('Options saved.'); ?></strong></p></div>
|
44 |
+
<?php
|
45 |
+
}else{
|
46 |
+
?>
|
47 |
+
<div class="error"><p><strong><?php _e('There were issues when saving your settings. Please try again.'); ?></strong></p></div>
|
48 |
+
<?php
|
49 |
+
}
|
50 |
+
}else{
|
51 |
+
$lwa_data = get_option('lwa_data');
|
52 |
+
}
|
53 |
+
?>
|
54 |
+
<div class="wrap">
|
55 |
+
<h2>Login With Ajax</h2>
|
56 |
+
<p>If you have any suggestions, come over to our plugin page and leave a comment. It may just happen!</p>
|
57 |
+
<form method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
|
58 |
+
<table class="form-table">
|
59 |
+
<tbody id="lwa-body">
|
60 |
+
<tr valign="top">
|
61 |
+
<td scope="row">
|
62 |
+
<label>Custom Login Redirect</label>
|
63 |
+
</td>
|
64 |
+
<td>
|
65 |
+
<input type="text" name="lwa_login_redirect" value='<?= $lwa_data['login_redirect'] ?>' />
|
66 |
+
<br/>
|
67 |
+
<i>If you'd like to send the user to a specific URL after login, enter it here (e.g. http://wordpress.org/)</i>
|
68 |
+
</td>
|
69 |
+
</tr>
|
70 |
+
<tr valign="top">
|
71 |
+
<td scope="row">
|
72 |
+
<label>Custom Logout Redirect</label>
|
73 |
+
</td>
|
74 |
+
<td>
|
75 |
+
<input type="text" name="lwa_logout_redirect" value='<?= $lwa_data['logout_redirect'] ?>' />
|
76 |
+
<br/>
|
77 |
+
<i>If you'd like to send the user to a specific URL after logout, enter it here (e.g. http://wordpress.org/)</i>
|
78 |
+
</td>
|
79 |
+
</tr>
|
80 |
+
</tbody>
|
81 |
+
<tfoot>
|
82 |
+
<tr valign="top">
|
83 |
+
<td colspan="2">
|
84 |
+
<input type="hidden" name="lwasubmitted" value="1" />
|
85 |
+
<p class="submit">
|
86 |
+
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
|
87 |
+
</p>
|
88 |
+
</td>
|
89 |
+
</tr>
|
90 |
+
</tfoot>
|
91 |
+
</table>
|
92 |
+
</form>
|
93 |
+
</div>
|
94 |
+
<?php
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
function LoginWithAjaxAdminInit(){
|
99 |
+
global $LoginWithAjaxAdmin;
|
100 |
+
$LoginWithAjaxAdmin = new LWA();
|
101 |
+
}
|
102 |
+
|
103 |
+
// Start this plugin once all other plugins are fully loaded
|
104 |
+
add_action( 'admin_menu', 'LoginWithAjaxAdminInit' );
|
105 |
+
?>
|
login-with-ajax.js
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(document).ready( function($) {
|
2 |
+
//Oh well... I guess we have to use jQuery ... if you are a javascript developer, consider MooTools if you have a choice, it's great!
|
3 |
+
//Kudos to those that made the jQuery Form Plugin, which is used for the AJAX calls.
|
4 |
+
//I'm biased, but form functionality already comes prepacked with MooTools :)
|
5 |
+
$('#LoginWithAjax_Form').ajaxForm({
|
6 |
+
dataType: 'json',
|
7 |
+
success: function(data){
|
8 |
+
$('#LoginWithAjax_Loading').remove();
|
9 |
+
if(data.result == '1'){
|
10 |
+
//Login Successful
|
11 |
+
if( $('#LoginWithAjax_Status').length > 0 ){
|
12 |
+
$('#LoginWithAjax_Status').attr('class','confirm').html("Login Successful, redirecting...");
|
13 |
+
}else{
|
14 |
+
$('<span id="LoginWithAjax_Status" class="confirm">Login Successful, redirecting...</span>').prependTo('#login-with-ajax');
|
15 |
+
}
|
16 |
+
if(data.redirect == null){
|
17 |
+
window.location.reload();
|
18 |
+
}else{
|
19 |
+
window.location = data.redirect;
|
20 |
+
}
|
21 |
+
}else{
|
22 |
+
//Login Failed
|
23 |
+
//If there already is an error element, replace text contents, otherwise create a new one and insert it
|
24 |
+
if( $('#LoginWithAjax_Status').length > 0 ){
|
25 |
+
$('#LoginWithAjax_Status').attr('class','invalid').html(data.error);
|
26 |
+
}else{
|
27 |
+
$('<span id="LoginWithAjax_Status" class="invalid">'+data.error+'</span>').prependTo('#login-with-ajax');
|
28 |
+
}
|
29 |
+
}
|
30 |
+
},
|
31 |
+
error: function(XMLHttpRequest, textStatus, errorThrown){
|
32 |
+
$('#LoginWithAjax_Loading').remove();
|
33 |
+
//If there already is an error element, replace text contents, otherwise create a new one and insert it
|
34 |
+
if( $('#LoginWithAjax_Status').length > 0 ){
|
35 |
+
$('#LoginWithAjax_Status').attr('class','invalid').html('An error has occured. Please try again.');
|
36 |
+
}else{
|
37 |
+
$('<span id="LoginWithAjax_Status" class="invalid">An error has occured. Please try again.</span>').prependTo('#login-with-ajax');
|
38 |
+
}
|
39 |
+
},
|
40 |
+
beforeSend: function(){
|
41 |
+
$('<div id="LoginWithAjax_Loading"></div>').prependTo('#login-with-ajax');
|
42 |
+
}
|
43 |
+
});
|
44 |
+
|
45 |
+
});
|
login-with-ajax.php
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Login With Ajax
|
4 |
+
Plugin URI: http://netweblogic.com/wordpress/plugins/login-with-ajax/
|
5 |
+
Description: Ajax driven login widget. Customisable from within your template folder, and advanced settings from the admin area.
|
6 |
+
Author: NetWebLogic
|
7 |
+
Version: 1.0
|
8 |
+
Author URI: http://netweblogic.com/
|
9 |
+
Tags: Login, Ajax, Redirect, BuddyPress, MU, WPMU, sidebar, admin, widget
|
10 |
+
|
11 |
+
Copyright (C) 2008 NetWebLogic LLC
|
12 |
+
|
13 |
+
This program is free software; you can redistribute it and/or modify
|
14 |
+
it under the terms of the GNU General Public License as published by
|
15 |
+
the Free Software Foundation; either version 3 of the License, or
|
16 |
+
(at your option) any later version.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
include_once('login-with-ajax-admin.php');
|
28 |
+
|
29 |
+
class LoginWithAjax {
|
30 |
+
|
31 |
+
// Class initialization
|
32 |
+
function LoginWithAjax() {
|
33 |
+
//Make decision on what to display
|
34 |
+
if ( function_exists('register_sidebar_widget') && !isset($_POST["login-with-ajax"]) ){
|
35 |
+
//Enqueue scripts
|
36 |
+
wp_enqueue_script( "login-with-ajax-form", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/form.js"), array( 'jquery' ) );
|
37 |
+
wp_enqueue_script( "login-with-ajax", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/login-with-ajax.js"), array( 'jquery', 'login-with-ajax-form' ) );
|
38 |
+
//Enqueue stylesheets
|
39 |
+
if( file_exists(get_template_directory().'/plugins/login-with-ajax/widget.css') ){
|
40 |
+
wp_enqueue_style( "login-with-ajax-css", get_template_directory_uri().'/plugins/login-with-ajax/widget.css' );
|
41 |
+
}else{
|
42 |
+
wp_enqueue_style( "login-with-ajax-css", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/widget/widget.css") );
|
43 |
+
}
|
44 |
+
//Register widget
|
45 |
+
register_sidebar_widget('Login With Ajax', array(&$this, 'widget'));
|
46 |
+
//Add logout/in redirection
|
47 |
+
add_action('wp_logout', array(&$this, 'logoutRedirect'));
|
48 |
+
add_action('wp_login', array(&$this, 'loginRedirect'));
|
49 |
+
|
50 |
+
}elseif ( isset($_POST["login-with-ajax"]) ) {
|
51 |
+
$this->ajax();
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
// Decides what action to take from the ajax request
|
56 |
+
function ajax(){
|
57 |
+
switch ( $_POST["login-with-ajax"] ) {
|
58 |
+
case 'login':
|
59 |
+
//A login has been requested
|
60 |
+
$this->ajaxLogin();
|
61 |
+
break;
|
62 |
+
default:
|
63 |
+
echo json_encode(array('result'=>0, 'error'=>'Unknown command requested'));
|
64 |
+
exit();
|
65 |
+
break;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
//Calls normal login and JSON encodes it
|
70 |
+
function ajaxLogin(){
|
71 |
+
echo json_encode($this->login());
|
72 |
+
exit();
|
73 |
+
}
|
74 |
+
|
75 |
+
// Reads ajax login creds via POSt, calls the login script and interprets the result
|
76 |
+
function login(){
|
77 |
+
$return = array(); //What we send back
|
78 |
+
$loginResult = wp_signon();
|
79 |
+
|
80 |
+
if ( get_class($loginResult) == 'WP_User' ) {
|
81 |
+
//User login successful
|
82 |
+
/* @var $result WP_User */
|
83 |
+
if(get_option('login-with-ajax_login-refresh') == 1){
|
84 |
+
//Refresh page - todo
|
85 |
+
}else{
|
86 |
+
//Return true value
|
87 |
+
$return['result'] = true;
|
88 |
+
}
|
89 |
+
} elseif ( get_class($loginResult) == 'WP_Error' ) {
|
90 |
+
//User login failed
|
91 |
+
/* @var $result WP_Error */
|
92 |
+
$return['result'] = false;
|
93 |
+
$return['error'] = $loginResult->get_error_message();
|
94 |
+
} else {
|
95 |
+
//Undefined Error
|
96 |
+
$return['result'] = false;
|
97 |
+
$return['error'] = 'An undefined error has ocurred';
|
98 |
+
}
|
99 |
+
|
100 |
+
//Return the result array with errors etc.
|
101 |
+
return $return;
|
102 |
+
}
|
103 |
+
|
104 |
+
// Generate the login template
|
105 |
+
function widget($args = array()) {
|
106 |
+
extract($args);
|
107 |
+
if(is_user_logged_in()){
|
108 |
+
if( file_exists(TEMPLATEPATH.'/plugins/login-with-ajax/widget_in.php') ){
|
109 |
+
include(TEMPLATEPATH.'/plugins/login-with-ajax/widget_in.php');
|
110 |
+
}else{
|
111 |
+
include('widget/widget_in.php');
|
112 |
+
}
|
113 |
+
}else{
|
114 |
+
if( file_exists(TEMPLATEPATH.'/plugins/login-with-ajax/widget_out.php') ){
|
115 |
+
include(TEMPLATEPATH.'/plugins/login-with-ajax/widget_out.php');
|
116 |
+
}else{
|
117 |
+
include('widget/widget_out.php');
|
118 |
+
}
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
function logoutRedirect(){
|
123 |
+
$data = get_option('lwa_data');
|
124 |
+
if( preg_match('/http(s)?:\/\//.+\.[a-zA-Z]{2,3}',$data['logout_redirect'])){
|
125 |
+
header("Location: {$data['logout_redirect']}");
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
function loginRedirect(){
|
130 |
+
$data = get_option('lwa_data');
|
131 |
+
if( preg_match('/http(s)?:\/\//.+\.[a-zA-Z]{2,3}',$data['login_redirect'])){
|
132 |
+
header("Location: {$data['login_redirect']}");
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
function LoginWithAjaxInit(){
|
138 |
+
global $LoginWithAjax;
|
139 |
+
$LoginWithAjax = new LoginWithAjax();
|
140 |
+
}
|
141 |
+
|
142 |
+
// Start this plugin once all other plugins are fully loaded
|
143 |
+
add_action( 'init', 'LoginWithAjaxInit' );
|
144 |
+
|
145 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Login With Ajax ===
|
2 |
+
|
3 |
+
Contributors: netweblogic
|
4 |
+
Tags: Login, Ajax, Redirect, BuddyPress, MU, WPMU, sidebar, admin, widget
|
5 |
+
Requires at least: 2.7
|
6 |
+
Tested up to: 2.8.2
|
7 |
+
Stable tag: 1.0
|
8 |
+
|
9 |
+
Add smooth ajax during login, avoid screen refreshes and choose where users get redirected to upon login/logout. Supports SSL, MU, and BuddyPress.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
For sites that need user logins and would like to avoid the normal wordpress login, this plugin adds the capability of placing a login widget in the sidebar with smooth AJAX login effects.
|
14 |
+
|
15 |
+
Compatible with Wordpress, Wordpress MU and BuddyPress. Will work with forced SSL logins.
|
16 |
+
|
17 |
+
This plugin allows full customization of your widget html by allowing you to create template files within your theme folder.
|
18 |
+
|
19 |
+
Another useful feature (which can be used without the widget) is login and logout redirects, so you control where the user is taken upon login and logout.
|
20 |
+
|
21 |
+
If you find this plugin useful and would like to donate something, all we ask is you please add a link on your site to the plugin page on our blog or digg our plugin page [http://netweblogic.com/wordpress/plugins/login-with-ajax/](http://netweblogic.com/wordpress/plugins/login-with-ajax/) thanks!
|
22 |
+
|
23 |
+
== Installation ==
|
24 |
+
|
25 |
+
1. Upload this plugin to the `/wp-content/plugins/` directory and unzip it, or simply upload the zip file within your wordpress installation.
|
26 |
+
|
27 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
28 |
+
|
29 |
+
3. If you want login/logout redirections, go to Settings > Login With Ajax in the admin area and fill out the form.
|
30 |
+
|
31 |
+
4. Add the login with ajax widget to your sidebar.
|
32 |
+
|
33 |
+
5. Happy logging in!
|
34 |
+
|
35 |
+
== Notes ==
|
36 |
+
|
37 |
+
When creating customized themes for your widget, there are a few points to consider:
|
38 |
+
|
39 |
+
* Start by copying the files in the /yourpluginpath/login-with-ajax/widget/ folder to /yourthemepath/plugins/login-with-ajax/
|
40 |
+
* If you want to customize the login-with-ajax.js javascript, you can also copy that into the same folder above.
|
41 |
+
* Unless you change the javascript, make sure you wrap your widget with an element with id="login-with-ajax". If you use the $before_widget ... variables, this should be done automatically.
|
42 |
+
* To force SSL, see [http://codex.wordpress.org/Administration_Over_SSL]("this page"). The plugin will automatically detect the wordpress settings.
|
43 |
+
|
44 |
+
== Screenshots ==
|
45 |
+
|
46 |
+
1. Add a login widget to your sidebars. Widget html is fully customizable and upgrade safe since they go in your theme files.
|
47 |
+
|
48 |
+
2. Smoothen the login process via ajax, avoid screen refreshes on login failures.
|
49 |
+
|
50 |
+
3. If your login is unsuccessful, user gets notified without loading a new page!
|
51 |
+
|
52 |
+
4. Customizable login/logout redirection settings. Control where users get directed to after login or logout (applicable to normal wp-login pages too).
|
53 |
+
|
54 |
+
5. Choose what your users see once logged in.
|
55 |
+
|
56 |
+
== Frequently Asked Questions ==
|
57 |
+
|
58 |
+
None yet!
|
screenshot-1.jpg
ADDED
Binary file
|
screenshot-2.jpg
ADDED
Binary file
|
screenshot-3.jpg
ADDED
Binary file
|
screenshot-4.jpg
ADDED
Binary file
|
screenshot-5.jpg
ADDED
Binary file
|
widget/loading.gif
ADDED
Binary file
|
widget/widget.css
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#login-with-ajax { margin-bottom:10px; position:relative; font-size:1em; }
|
2 |
+
#login-with-ajax td { padding-top:7px; vertical-align:top; }
|
3 |
+
|
4 |
+
/*Logged out CSS*/
|
5 |
+
#login-with-ajax .password_label, #login-with-ajax .username_label { padding-right:10px; vertical-align:middle; }
|
6 |
+
#LoginWithAjax_Password input, #LoginWithAjax_Username input { width:97%; }
|
7 |
+
|
8 |
+
#LoginWithAjax_Loading { position:absolute; width:100%; height:100%; background:#FFFFFF url(loading.gif) 50% 50% no-repeat; left:0px; top:0px; opacity:0.8; filter:alpha(opacity=80)}
|
9 |
+
|
10 |
+
#LoginWithAjax_Status.invalid, #LoginWithAjax_Status.confirm { display:block; background:none; margin:5px 0px; }
|
11 |
+
#LoginWithAjax_Status.invalid { color:#990000; }
|
12 |
+
#LoginWithAjax_Status.confirm { color:#009900; }
|
13 |
+
|
14 |
+
/*Logged In CSS*/
|
15 |
+
#LoginWithAjax_Avatar { width:60px; }
|
widget/widget_in.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* This is the page users will see logged in.
|
4 |
+
* You can edit this, but for upgrade safety you should copy and modify this file into your template folder.
|
5 |
+
* The location from within your template folder is plugins/login-with-ajax/ (create these directories if they don't exist)
|
6 |
+
*/
|
7 |
+
?>
|
8 |
+
<?php
|
9 |
+
global $current_user;
|
10 |
+
echo $before_widget . $before_title . __( 'Hi '. ucwords($current_user->display_name) ) . $after_title;
|
11 |
+
?>
|
12 |
+
<?php
|
13 |
+
global $current_user;
|
14 |
+
global $wpmu_version;
|
15 |
+
get_currentuserinfo();
|
16 |
+
?>
|
17 |
+
<table cellpadding="0" cellspacing="0" width="100%">
|
18 |
+
<tr>
|
19 |
+
<td class="avatar" id="LoginWithAjax_Avatar">
|
20 |
+
<?php if ( function_exists('bp_loggedinuser_avatar_thumbnail') ) : ?>
|
21 |
+
<?php bp_loggedinuser_avatar_thumbnail() ?>
|
22 |
+
<?php else: ?>
|
23 |
+
<?php echo get_avatar( $current_user->user_email, $size = '50' ); ?>
|
24 |
+
<?php endif; ?>
|
25 |
+
</td>
|
26 |
+
<td id="LoginWithAjax_Title">
|
27 |
+
<?php
|
28 |
+
/* Always add a log out list item to the end of the navigation */
|
29 |
+
if ( function_exists( 'wp_logout_url' ) ) {
|
30 |
+
?>
|
31 |
+
<a id="wp-logout" href="<?= wp_logout_url( site_url() ) ?>"><?= strtolower(__( 'Log Out' )) ?></a>
|
32 |
+
<?
|
33 |
+
} else {
|
34 |
+
?>
|
35 |
+
<a id="wp-logout" href="<?= site_url() . '/wp-login.php?action=logout&redirect_to=' . site_url() ?>"><?= strtolower(__( 'Log Out' )) ?></a>
|
36 |
+
<?php
|
37 |
+
}
|
38 |
+
?>
|
39 |
+
<?php
|
40 |
+
if( !empty($wpmu_version) ) {
|
41 |
+
global $bp;
|
42 |
+
foreach($bp->bp_nav as $nav_item){
|
43 |
+
if($nav_item['css_id'] == 'settings'){
|
44 |
+
?>
|
45 |
+
| <a href="<?= $nav_item['link'] ?>"><?= strtolower($nav_item['name']) ?></a>
|
46 |
+
<?
|
47 |
+
}
|
48 |
+
}
|
49 |
+
?>
|
50 |
+
| <a href="/wp-admin/">blog admin</a>
|
51 |
+
<?php
|
52 |
+
}
|
53 |
+
?>
|
54 |
+
</td>
|
55 |
+
</tr>
|
56 |
+
</table>
|
57 |
+
<?php if ( !empty($wpmu_version) ) : ?>
|
58 |
+
<div id="LoginWithAjax_Notifications">
|
59 |
+
<?php
|
60 |
+
$notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id );
|
61 |
+
?>
|
62 |
+
<h4>Notifications <?php echo ( count($notifications) > 0 && $notifications != false ) ? "(".count($notifications).")" : "" ?></h4>
|
63 |
+
<?php
|
64 |
+
echo '<ul>';
|
65 |
+
if ( $notifications ) { ?>
|
66 |
+
<?php $counter = 0; ?>
|
67 |
+
<?php for ( $i = 0; $i < count($notifications); $i++ ) { ?>
|
68 |
+
<?php $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
|
69 |
+
<li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
|
70 |
+
<?php $counter++; ?>
|
71 |
+
<?php } ?>
|
72 |
+
<?php } else { ?>
|
73 |
+
<li><?php _e( 'No new notifications.', 'buddypress' ); ?></li>
|
74 |
+
<?php
|
75 |
+
}
|
76 |
+
echo '</ul>';
|
77 |
+
?>
|
78 |
+
</div>
|
79 |
+
<?php endif; ?>
|
80 |
+
<?php
|
81 |
+
echo $after_widget;
|
82 |
+
?>
|
widget/widget_out.php
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* This is the page users will see logged out.
|
4 |
+
* You can edit this, but for upgrade safety you should copy and modify this file into your template folder.
|
5 |
+
* The location from within your template folder is plugins/login-with-ajax/ (create these directories if they don't exist)
|
6 |
+
*/
|
7 |
+
?>
|
8 |
+
<?php
|
9 |
+
echo $before_widget . $before_title . __('Log In') . $after_title;
|
10 |
+
?>
|
11 |
+
<span id="LoginWithAjax_Status"></span>
|
12 |
+
<form name="LoginWithAjax_Form" id="LoginWithAjax_Form" action="<?php echo site_url('wp-login.php') ?>" method="post">
|
13 |
+
<table width='100%' cellspacing="0" cellpadding="0">
|
14 |
+
<tr id="LoginWithAjax_Username">
|
15 |
+
<td class="username_label">
|
16 |
+
<label><?php _e( 'Username' ) ?></label>
|
17 |
+
</td>
|
18 |
+
<td class="username_input">
|
19 |
+
<input type="text" name="log" id="lwa_user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" />
|
20 |
+
</td>
|
21 |
+
</tr>
|
22 |
+
<tr id="LoginWithAjax_Password">
|
23 |
+
<td class="password_label">
|
24 |
+
<label><?php _e( 'Password' ) ?></label>
|
25 |
+
</td>
|
26 |
+
<td class="password_input">
|
27 |
+
<input type="password" name="pwd" id="lwa_user_pass" class="input" value="" />
|
28 |
+
</td>
|
29 |
+
</tr>
|
30 |
+
<tr id="LoginWithAjax_Submit">
|
31 |
+
<td id="LoginWithAjax_SubmitButton">
|
32 |
+
<input type="submit" name="wp-submit" id="lwa_wp-submit" value="<?php _e('Log In'); ?>" tabindex="100" />
|
33 |
+
<input type="hidden" name="redirect_to" value="http://<?php echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] ?>" />
|
34 |
+
<input type="hidden" name="testcookie" value="1" />
|
35 |
+
<input type="hidden" name="login-with-ajax" value="login" />
|
36 |
+
</td>
|
37 |
+
<td id="LoginWithAjax_Remember">
|
38 |
+
<input name="rememberme" type="checkbox" id="lwa_rememberme" value="forever" /> <label><?php _e( 'Remember Me' ) ?></label>
|
39 |
+
<br />
|
40 |
+
<a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a>
|
41 |
+
<?php
|
42 |
+
//Signup Links
|
43 |
+
if ( get_option('users_can_register')/*&& get_option('login-with-ajax_register')=='1'*/ ) {
|
44 |
+
echo "<br />";
|
45 |
+
// MU FIX
|
46 |
+
global $wpmu_version;
|
47 |
+
if (empty($wpmu_version)) {
|
48 |
+
?>
|
49 |
+
<a href="<?php echo site_url('wp-login.php?action=register', 'login') ?>"><?php _e('Register') ?></a>
|
50 |
+
<?php
|
51 |
+
} else {
|
52 |
+
?>
|
53 |
+
<a href="<?php echo site_url('wp-signup.php', 'login') ?>"><?php _e('Register') ?></a>
|
54 |
+
<?php
|
55 |
+
}
|
56 |
+
} elseif ( true/*&& get_option('login-with-ajax_register')=='1'*/ && function_exists('bp_signup_page') ){
|
57 |
+
echo "<br />";
|
58 |
+
?>
|
59 |
+
<a href="<?php echo bp_signup_page() ?>" title="<?php _e( 'Sign Up' ) ?>" rel="nofollow" /><?php _e( 'Sign Up' ) ?></a>
|
60 |
+
<?php
|
61 |
+
}
|
62 |
+
?>
|
63 |
+
</td>
|
64 |
+
</tr>
|
65 |
+
</table>
|
66 |
+
</form>
|
67 |
+
<?php
|
68 |
+
echo $after_widget;
|
69 |
+
?>
|