-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathping.php
More file actions
54 lines (54 loc) · 2.06 KB
/
ping.php
File metadata and controls
54 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/* mantiene sesión "viva" */
if(isset($_POST['ping'])) {
session_start();
require_once("config.php");
$msg = new stdclass;
$msg->new = 0;
if(isset($_SESSION[ME])) {
$sql->Query("UPDATE seen=now() WHERE id = '".$_SESSION[ME]."'");
$q = sprintf("SELECT count(M.cid) as no from mensajes M,posts P where P.id = M.msgid and P.me='%d' and M.enviado='1' and M.visto='0'",$_SESSION[ME]);
$no = $sql->Query($q);
$no = $no->fetch_object();
$msg->new = (int)$no->no;
}
if(!isset($_SESSION['pong'])) $_SESSION['pong']=1;
$_SESSION['pong']++;
$msg->pong = number_format($_SESSION['pong']/60,2);
//
echo json_encode($msg);
} elseif(isset($_POST['actualiza'])) {
session_start();
require_once("config.php");
$msg = new stdclass;
//allow
$allow = ['frecuencia'];
if(in_array($_POST['actualiza'],$allow)) {
$msg->ok = true;
$q = sprintf("UPDATE users SET %s='%s' WHERE id = '%d'",__($_POST['actualiza']),__($_POST['data']),$_SESSION[ME]);
$sql->Query($q);
if($_POST['actualiza']=='frecuencia') $_SESSION['data']->frecuencia = __($_POST['data']);
} else {
$msg->error = "error";
}
echo json_encode($msg);
} else {
?>
<script>
var pong=0; $(document).ready(function(){ var pong = setTimeout("pingPong()",500); });
function pingPong() {
if(pong) { clearTimeout(pong); }
$.post("<?php echo $sitio;?>ping.php",{ping:1,ts:<?php echo time();?>},function(m) {
$(".pingpong").html(m.pong);
if(m.new>0) {
$("#nuevos").html('mensajes <span class="badge badge-warning">'+m.new+'</span>');
}
},'json');
pong = setTimeout("pingPong()",1000*60);
}
</script>
<?php
if(!isset($_SESSION['pong'])) $_SESSION['pong']=1;
echo '<span class="text-muted muted pingpong">¿ping? ¡pong '.number_format($_SESSION['pong']/60,2).'!</span>';
}
?>