| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin to refresh PilotPress session to prevent expiration before wordpress timeout |
| 4 |
* |
| 5 |
* This plugin will mimic a keep-alive ping by performing an ajax request to |
| 6 |
* ping.php which will update the "rehash" session token tied to PilotPress. |
| 7 |
* Session Slap will also provide a settings interface to allow admins to |
| 8 |
* configure smaller end details |
| 9 |
* |
| 10 |
* @package Session Slap |
| 11 |
* @subpackage PilotPress |
| 12 |
* @since 3.5.1 |
| 13 |
* |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* jQuery Ping Hooks |
| 18 |
* |
| 19 |
* Necessary jQuery to do ajax requests to this same file in order |
| 20 |
* to commit session updates to PilotPress. |
| 21 |
* |
| 22 |
* @since 1.7.1 |
| 23 |
* |
| 24 |
*/ |
| 25 |
function pilotpress_sessionslap_face($options){ |
| 26 |
$options = get_option("pilotpress-settings"); |
| 27 |
|
| 28 |
//turn on to check if the session slap is working propelry with an alert message |
| 29 |
$options["alerts"] = 0; |
| 30 |
$options['hang_duration'] = 5; |
| 31 |
|
| 32 |
$options["pilotpress_logout_duration"] = ini_get("session.gc_maxlifetime") / 2; |
| 33 |
if (!isset($options["pilotpress_logout_duration"]) || empty($options["pilotpress_logout_duration"]) || is_null($options["pilotpress_logout_duration"])){ |
| 34 |
$options["pilotpress_logout_duration"] = (24 * 60) / 2; // If the value is empty, or access restricted, use PHP's 24 minute default settings. |
| 35 |
} |
| 36 |
|
| 37 |
?> |
| 38 |
<script type="text/javascript"> |
| 39 |
jQuery(function($){ |
| 40 |
window.sessionslap = { |
| 41 |
// Show alerts in top right corner? |
| 42 |
"alerts": <?php echo ( $options['alerts'] == 'on' ? 1 : 0 ); ?>, |
| 43 |
// Duration alerts should hang for, in ms |
| 44 |
"alert_hang_time": <?php echo (int) $options['hang_duration'] * 1000; ?>, // 5 seconds |
| 45 |
// Interval of time between each keep-alive ping |
| 46 |
"interval_time": <?php echo (int) $options['pilotpress_logout_duration'] * (60*1000); ?>, //1800000 == 30 min, |
| 47 |
"init": function(){ |
| 48 |
window.sessionslap.pinger_interval_id = setInterval( this.pinger, this.interval_time); |
| 49 |
}, |
| 50 |
"pinger": function(){ |
| 51 |
$(document).trigger("sessionslap.ping.start"); |
| 52 |
jQuery.ajax({ |
| 53 |
url: "?", |
| 54 |
type: "GET", |
| 55 |
data: { |
| 56 |
update: true, |
| 57 |
r: Math.random() |
| 58 |
}, |
| 59 |
success: function(data){ |
| 60 |
if (window.sessionslap.alerts){ |
| 61 |
window.sessionslap.alert("Your session has been updated!", true ); |
| 62 |
} |
| 63 |
$(document).trigger("sessionslap.ping.end.success"); |
| 64 |
console.log("Your session has been updated!"); |
| 65 |
}, |
| 66 |
error: function(data){ |
| 67 |
if (window.sessionslap.alerts){ |
| 68 |
window.sessionslap.alert("There was an issue with your session getting updated!"); |
| 69 |
} |
| 70 |
$(document).trigger("sessionslap.ping.end.error"); |
| 71 |
console.log("There was an issue with your session getting updated!"); |
| 72 |
} |
| 73 |
}); |
| 74 |
}, |
| 75 |
"alert": function(msg, good){ |
| 76 |
$alert = $("<div>").text( msg ).addClass("sessionslap-alert " + ( good ? "sessionslap-success" : "sessionslap-error" ) ).bind("click", function(e){ |
| 77 |
$(this).stop(); |
| 78 |
}); |
| 79 |
$("body").append( $alert ).find(".sessionslap-alert").delay( this.alert_hang_time ).fadeOut(1500, function(e){ |
| 80 |
$(this).remove(); |
| 81 |
}); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
<?php |
| 86 |
if (array_key_exists("pilotpress_logout_users", $options) && $options['pilotpress_logout_users']){ |
| 87 |
?> |
| 88 |
window.sessionslap.init(); |
| 89 |
<?php |
| 90 |
} |
| 91 |
?> |
| 92 |
}); |
| 93 |
</script> |
| 94 |
<?php |
| 95 |
} |