Commit 7f660cc1 authored by Dave Lane's avatar Dave Lane

tentatively saying this plugin is now working - requires full test

parent 718d533e
......@@ -34,9 +34,6 @@ class OREMain extends OREBase {
// this starts everything...
public function init() {
//$this->log('in init');
//$this->log('setting up scripts');
// jsquery validate script
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
// add the ajax handlers
......@@ -48,9 +45,6 @@ class OREMain extends OREBase {
add_action('wp_ajax_nopriv_ore_submit', array($this, 'ajax_submit'));
add_action('wp_ajax_nopriv_ore_email_check', array($this, 'ajax_email_check'));
add_action('wp_ajax_nopriv_ore_username_check', array($this, 'ajax_username_check'));
// bypass the "Are you sure" log out confirmation
//add_action('check_admin_referer', array($this, 'logout_without_confirmation'), 10, 2);
//add_action('wp_logout', array($this, 'process_logout'),10, 1);
}
public function enqueue_scripts() {
......@@ -146,9 +140,6 @@ class OREMain extends OREBase {
$this->log('ore-submit-nonce all good.');
}
$this->log("processing submit form...");
/*$this->log("sleeping briefly for debugging purposes");
sleep(5);
//$this->log("done sleeping");*/
// generate the response
header( "Content-Type: application/json" );
$response = $this->process();
......@@ -212,11 +203,11 @@ class OREMain extends OREBase {
break;
}
// if response isn't 'true'
if (is_wp_error($response)) {
/*if (is_wp_error($response)) {
//$this->log('failed to complete '.$form_action);
//$this->log('response is '.print_r($response, true));
//$this->ajax_response(array('success' => $response));
}
}*/
return $response;
}
// login process
......@@ -245,19 +236,9 @@ class OREMain extends OREBase {
public function logout() {
$this->log('logging user out');
$response = wp_logout();
//$this->log('login: '.print_r($login, true));
// if login fails
// if logout fails
if (!is_wp_error($response)) {
$this->log('logged user out!');
/*$this->log('logged user out! Now redirecting back to last page');
$redirect = '';
if (isset($_REQUEST['redirect_to'])) {
$redirect = $_REQUEST['redirect_to'];
} else {
$redirect = "default_redirect";
}
$this->log('redirect = '.$redirect);
wp_safe_redirect($redirect);*/
return true;
}
return $response;
......@@ -717,7 +698,6 @@ class OREMain extends OREBase {
}
// unenrol a user from a course
public function leave() {
$this->log('user '.$user_id.' leaving course '.$course_id);
$errors = $this->get_errors();
if (empty($_POST['user_id']) || empty($_POST['course_id'])) {
if (empty($_POST['user_id'])) {
......@@ -730,6 +710,7 @@ class OREMain extends OREBase {
}
$user_id = $_POST['user_id'];
$course_id = $_POST['course_id'];
$this->log('user '.$user_id.' leaving course '.$course_id);
//$this->log('user '.$user_id.' leaving course '.$course_id);
$response = remove_user_from_blog($user_id, $course_id);
$check = is_user_member_of_blog($user_id, $course_id);
......@@ -856,19 +837,6 @@ class OREMain extends OREBase {
return false;
}
/*public function get_menus() {
$this->log('in get_menus');
global $menus;
if (!is_array($menus)) {
return false;
}
$menu_data = array();
foreach($menus as $menu => $val) {
$menu_data[$menu][] = $val;
}
return $menu_data;
}*/
// get validation messages in a form that can be injected into javascript
public function get_validation_messages() {
global $validation_messages;
......@@ -1000,44 +968,4 @@ class OREMain extends OREBase {
asort($countries);
return $countries;
}
// bypass logout confirmation
// see
/*public function logout_without_confirmation($action, $result) {
$this->redirect_counter++;
$this->log('another redirect... '.$this->redirect_counter);
$this->log('cookie info :'.print_r($_COOKIE, true));
if ($action == "log-out" && is_user_logged_in()) {
$this->log('request array: '. print_r($_REQUEST, true));
if (isset($_REQUEST['redirect_to'])) {
$this->log('in logout without confirmation: action = '.$action.
', redirect_to = '.$_REQUEST['redirect_to'].'...');
}
if (isset($_REQUEST['amp;_wpnonce'])) {
$_REQUEST['_wpnonce'] = $_REQUEST['amp;_wpnonce'];
unset($_REQUEST['amp;_wpnonce']);
$this->log('fixed request array: '.print_r($_REQUEST, true));
}
// Allow logout without confirmation
//if ($action == "logout" && !isset($_GET['_wpnonce'])) {
$this->log('logging out without confirmation...');
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '' ;
$this->log('redirect_to = '.$redirect_to);
$location = str_replace('&', '&', wp_logout_url($redirect_to));
$this->log('location 1: '.$location);
//wp_safe_redirect($location);
wp_redirect($location);
exit;
//header("Location: $location");
//die();
} else {
$this->log('something else must have happened');
}
}
// confirm user is logged out...
public function process_logout($user_id) {
$this->log('process_logout: request array: ', print_r($_REQUEST, true));
$this->log("user $user_id has been logged out with URL: $url");
}*/
}
......@@ -394,31 +394,10 @@ jQuery(document).ready(function() {
LOG("we've got a user! ");
form_markup = replace_dialog_tokens(form_markup, ore_data.user);
title = replace_dialog_tokens(title, ore_data.user);
/*LOG('Replacing user tokens with contents of ', ore_data.user);
// replace values in forms based on the user values
form_markup = replace_user_tokens(form_markup, ore_data.user);
title = replace_user_tokens(title, ore_data.user);*/
} else {
user = null;
LOG('no user object!');
}
// if there're some arguments provided, substitute those!
/*if (current_hash_args != null) {
//LOG('replacing tokens with args - ', current_hash_args);
form_markup = replace_args_tokens(form_markup, current_hash_args);
title = replace_args_tokens(title, current_hash_args);
//LOG('after replace_args_tokens - '+form_markup);
}*/
//LOG('after replace_user_tokens - '+form_markup);
/*if (id == 'edit_profile' || id == 'register') {
LOG('adding countries');
form_markup = add_countries(form_markup, ore_data.country_select);
}*/
// tidy up any residual tokens
//form_markup = replace_unused_tokens(form_markup);
//title = replace_unused_tokens(title);
LOG('appending form to parent');
// at this point, the form should appear!
// here form is a DOM node...
if (id == 'edit_profile' || id == 'register') {
LOG('Setting the country');
......@@ -528,7 +507,6 @@ jQuery(document).ready(function() {
// set this up to submit on 'enter',
// close dialogs on ESC,
// and handle keyboard navigation within a dialog (prevent focus from shifting away!)
//$('input').keypress( function (e) {
$(document).keyup( function(e) {
if (e.key === 'Escape') { // ESCape pressed
LOG('document keyup (ESC)');
......@@ -591,17 +569,22 @@ jQuery(document).ready(function() {
function get_form() {
if (form = $(form_container).find(form_class)) {
LOG('found a stub form: ', form);
inputs = form.find(':input');
if (inputs.length) {
LOG('got some inputs! ', inputs.length);
} else {
LOG('no inputs in form');
}
return form;
}
return false;
}
function has_inputs(form) {
inputs = form.find(':input');
if (inputs.length) {
return true;
LOG('got some inputs! ', inputs.length);
} else {
return false;
LOG('no inputs in form');
}
}
// get the values from a form
function get_form_values(form) {
var values = {};
......@@ -680,15 +663,16 @@ jQuery(document).ready(function() {
return false;
}
}
// if we've got a valid form... proceed.
valid_form = form.valid();
if (valid_form) {
LOG('form is valid...');
} else {
LOG('form is not valid!');
// if we've got a form with inputs...
if (has_inputs(form)) {
valid_form = form.valid();
// check if the form's valid...
if (!valid_form) {
LOG('form is not valid!');
return false;
}
}
if (valid_form && special_data != null) {
LOG('form is valid');
if (special_data != null) {
// process the ajax call...
if (ajax_submit(action, special_data)) {
LOG('completed ajax call for', action);
......@@ -703,30 +687,14 @@ jQuery(document).ready(function() {
LOG('failed to complete ajax call for', action);
}
} else {
LOG('form is not valid!');
LOG('no special data defined!');
return false;
}
return true;
} /*else {
if (check_purpose(action, 'confirmation')) {
LOG('no form - purpose is confirmation! Closing dialog.');
close_dialog();
clear_hash();
return true;
} else {
LOG('no form - purpose is not confirmation');
}
LOG('no form to process for ', action);
return false;
}*/
}
return false;
}
// replace country selector tag with country selector
/*function add_countries(markup, select) {
//LOG('adding country selector', form);
return markup.replace('{country_selector}', select);
}*/
// set the country of the current user
function set_country(form, country) {
LOG('setting country to ', country);
......@@ -749,7 +717,7 @@ jQuery(document).ready(function() {
// find the variable
variable = parts[0];
var obj = eval(variable);
value = null;
value = false;
length = parts.length;
//LOG('length: ', length);
if (length == 5) {
......@@ -764,54 +732,17 @@ jQuery(document).ready(function() {
value = obj;
}
//LOG('value: ', value)
LOG('REPLACE: match '+match+' => ', value);
// if we found something...
if (typeof value == 'undefined') {
LOG('value for match '+match+' is undefined. Returning empty string.');
value = '';
}
return value;
});
//LOG('REPLACE: string '+string+' - returning: ', second);
return second;
}
// replace user tokens
/*function replace_user_tokens(string, user) {
for (var key in user) {
if (key === 'course') {
for (var course_key in user['course']) {
replacement = user['course'][course_key];
if (replacement != null && replacement != "") {
//LOG('replacement (course) '+replacement);
string = string.replace('{'+course_key+'}', replacement);
}
}
} else {
replacement = user[key];
if (replacement != null && replacement != "") {
//LOG('replacement (user) '+replacement);
string = string.replace('{'+key+'}', replacement);
}
}
}
return string;
}*/
/*function replace_args_tokens(string, args) {
LOG('in replace_args_tokens');
for (var key in args) {
replacement = args[key];
if (replacement != null && replacement != "") {
LOG('replacing '+key+' with '+replacement);
string = string.replace('{'+key+'}', replacement);
}
}
return string;
}*/
/*function replace_unused_tokens(string) {
//LOG('in replace_unused_tokens');
pattern = /{.+}/gm;
string = string.replace(pattern, "");
return string;
}*/
function value_in_object(obj, needle) {
match = false;
obj.forEach(function(value, key) {
......@@ -840,28 +771,8 @@ jQuery(document).ready(function() {
} else {
LOG('failed to complete ajax call for', action);
}
/*// fix the entity, returning to a pure &
//var goto = ore_data.user.log_out_url+'&redirect_to='+href;
var goto = ore_data.user.log_out_url;
goto = goto.replace('&', '&');
LOG('going to url', goto);
if (window.location.href !== goto ) {
LOG('redirecting to ', goto);
window.location.href = goto;
} else {
LOG('done redirecting... ');
}
return true;*/
/*LOG('returning last_focus to #ore-login-dialog');
last_focus = $(document).find('#ore-login-dialog');
return true;*/
}
/*
* Set up the default menu link/trigger textarea
*/
/*
* form validation, e.g. uniqueness of username and email
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment