public static function inc($userId, $counterId) { $blockIncrement = false; if ($counterId == "stream") { // Live updates for new stream items!! $context = new \ZMQContext(); // Notifiy events.php which send the notification via web sockets to the client. // Send notfication to events.php for push notification to user device. $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher'); $socket->connect("tcp://localhost:5555"); $socket->send(json_encode(array("type" => "newNotifications", "owner" => $userId))); $message = $socket->recv(); clog2($message); } if (!$blockIncrement) { $col = \App\DB\Get::Collection(); $col->users->update(array("userid" => $userId), array('$inc' => array('counter_' . $counterId => 1))); } }
public static function getConstraints($filterObject, $dbCollection, $onRemote = false) { $returnArray = array(); $locationUsed = false; // We can only use nearSphere once in mongoDB, therefore we have a variable indicating if it was used already $prefix = "post.metaData"; if ($onRemote) { $prefix = "postData.object.metaData"; } // post collection items and stream collection items differentiate slightly $const1 = array(); $const2 = array(); $const3 = array(); if (isset($filterObject) && isset($filterObject["context"])) { $const1 = array($prefix . ".type" => array('$in' => $filterObject["context"])); } if (isset($filterObject) && isset($filterObject["archived"]) && !$onRemote) { $const2 = array("archived" => true); return $const2; } if (isset($filterObject) && isset($filterObject["constraints"])) { // TODO: ensureIndex on GPS Location // clog2($filterObject["constraints"], "constraints are"); foreach ($filterObject["constraints"] as $constraint) { if ($constraint["type"] == "range") { if (isset($constraint["start"]) && is_numeric($constraint["start"])) { $const3[$prefix . "." . $constraint["name"]] = array('$gte' => doubleval($constraint["start"])); } if (isset($constraint["end"]) && is_numeric($constraint["end"])) { $const3[$prefix . "." . $constraint["name"]] = array('$lt' => doubleval($constraint["end"])); } } else { if ($constraint["type"] == "exact") { $const3[$prefix . "." . $constraint["name"]] = $constraint["value"]; } else { if ($constraint["type"] == "location") { // NOTE: Delete index if database layout changes if (false) { $dbCollection->streamitems->deleteIndex("post.metaData." . $constraint["name"] . "_data.position"); $dbCollection->posts->deleteIndex("postData.object.metaData." . $constraint["name"] . "_data.position"); } else { // TODO: This is SLOW. Make this only once!! $dbCollection->posts->ensureIndex(array("postData.object.metaData." . $constraint["name"] . "_data.position" => '2dsphere'), array("sparse" => true)); $dbCollection->streamitems->ensureIndex(array("post.metaData." . $constraint["name"] . "_data.position" => '2dsphere'), array("sparse" => true)); } if (!$locationUsed) { $locationUsed = true; $const3[$prefix . "." . $constraint["name"] . "_data.position"] = array('$nearSphere' => array('$geometry' => array("type" => "Point", "coordinates" => array(floatval($constraint["value"]["position"]["coordinates"][0]), floatval($constraint["value"]["position"]["coordinates"][1]))), '$maxDistance' => intval($constraint["radius"]) * 1000)); } else { $const3[$prefix . "." . $constraint["name"] . "_data.position"] = array('$within' => array('$centerSphere' => array(array(floatval($constraint["value"]["position"]["coordinates"][0]), floatval($constraint["value"]["position"]["coordinates"][1])), intval($constraint["radius"]) * 1000 / 6378.1))); // loc: { $geoWithin: { $centerSphere: [ [ -88, 30 ], 10/3963.2 ] } } } } } } } } $returnArray = array_merge($const1, $const2, $const3); clog2($returnArray); return $returnArray; }
global $CHARME_SETTINGS; if ($CHARME_SETTINGS["BLOCK_NEW_USERS"]) { $returnArray[$action] = array("signupblocked" => true); break; } $returnArray[$action] = array("pong" => true); // Used in sign up to check if the server is a valid Charme server. break; case "reg_salt_get": clog("request salt for userid " . $item["userid"]); $col = \App\DB\Get::Collection(); // $salt = $CHARME_SETTINGS["passwordSalt"]; // $p2 =hash('sha256', $CHARME_SETTINGS["passwordSalt"].$p1); // Only allow if user not exists! $res = $col->saltvalues->findOne(array("userid" => $item["userid"])); clog2($res); $returnArray[$action] = array("salt" => $res["salt"]); break; // Parameters: oldPasswordHash, newPasswordHash // Parameters: oldPasswordHash, newPasswordHash case "reg_changepassword": $col = \App\DB\Get::Collection(); // 1. Check if oldPasswordHash matches $cursor = $col->users->findOne(array("userid" => $_SESSION["charme_userid"], "password" => $item["oldPasswordHash"]), array("password")); if ($cursor["password"] == $item["oldPasswordHash"]) { $col->users->update(array("userid" => $_SESSION["charme_userid"]), array('$set' => array("password" => $item["newPasswordHash"]))); $returnArray[$action] = array("STATUS" => "OK"); } else { $returnArray[$action] = array("STATUS" => "WRONG_PASSWORD"); } break;