-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.php
More file actions
72 lines (50 loc) · 1.73 KB
/
check.php
File metadata and controls
72 lines (50 loc) · 1.73 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once('includes/functions.php');
require_once("includes/keys.php");
$un = $DB_ID;
$pw = $DB_KEY;
$db = "texts";
$col = "messages";
$collection = mongoCollection( $un, $pw, $db, $col );
////////////////////////////////////////////////////////////////////
//-------------------- CHECK FOR A MESSAGE -----------------------//
////////////////////////////////////////////////////////////////////
if( isset($_GET['phrase']) ){
//id of the group ALGO
//might change this to pass group name via oF
//search joins DB get ID search messages DB -
//is that worth it? Two db calls for every message check?
$id = new MongoId('4ee769d6d1c3cd407a130420');
$object = array(
"group_id" => $id,
'$where' => "this.delivered<1"
);
$sort = array("timestamp"=>1 );
$cursor = $collection->find($object)->sort($sort)->limit(1);
$c = iterator_count($cursor);
if($c < 1){
echo "no";
}else{
foreach($cursor as $c){
$string = trim($c["_id"]).'|'.trim($c["message"]).'|'.trim($c["visual"]);
echo $string;
}
}
////////////////////////////////////////////////////////////////////
//------------------ MARK RECIEVED MESSAGE -----------------------//
////////////////////////////////////////////////////////////////////
} elseif( isset($_GET['id']) || isset($_POST['id']) ){
if( isset($_GET['id']) ) $id = $_GET['id'];
else $id = $_POST['id'];
$mid = new MongoId($id);
$_id = array("_id"=> $mid);
$delivered = array( '$inc' => array( "delivered" => 1 ) );
$upsert = array('upsert' => true);
try{
$collection->update($_id, $delivered, $upsert);
echo "DELIVERY_SUCCESS";
} catch(Exception $e){
echo 'Caught exception:', $e->getMessage(), "\n";
}
}
?>