if((file_exists($arrayRestInputs['enginebasedir'] . '/lib/User.php')) && (file_exists($arrayRestInputs['enginebasedir'] . '/lib/NodeToken.php')) ){
require_once($arrayRestInputs['enginebasedir'] . '/lib/User.php');
require_once($arrayRestInputs['enginebasedir'] . '/lib/NodeToken.php');
+ require_once($arrayRestInputs['enginebasedir'] . '/lib/Planwatch.php');
$objectToken = new NodeToken ();
if(($objectToken->retrieveToken($arrayRestInputs['token'])) && (count($arrayRestInputs['arguments']) > 0)){
$thisUserUid = $objectToken->uid;
if(Planworld::isUser($userPlanToGet)){
$userPlanToGetObject = new User($userPlanToGet);
if(!$thisUserObject->doesBlockRelationshipExist($userPlanToGetObject->getUserID())){
+ /* Make sure the user's Planwatch gets updated. This may be a costly call. */
+ $thisUserObject->loadPlanwatch();
+ $thisUserObject->planwatch->markSeen($userPlanToGetObject);
+ $thisUserObject->save();
return $userPlanToGetObject->getPlanSimple($thisUserObject);
}
else{
$this->uid = (int)$result['uid'];
$this->clientname = (string)$result['clientname'];
$this->expire = (int)$result['expire'];
- if(time() < $this->expire){
+ $currentTime = time();
+ if($currentTime < $this->expire){
$this->valid = true;
+ /* Take a moment to update the user last_login time for the API. */
+ $query2 = $this->dbh->prepare('UPDATE users SET last_login=:lastlogin WHERE id = :uid');
+ $queryArray2 = array('uid' => $this->uid, 'lastlogin' => $currentTime);
+ $query2->execute($queryArray2);
}
/* Token exists but is expired. Get rid of it. */
else{
/* Loads planwatch data into this object.
* Previous versions used a sort variable as an argument. This has now been removed because it is up to the client to sort. */
function load() {
+ /* Initialize variables at the top so that even if calls fail the variables
+ remain initialized for things that call foreach later.
+ This is done to fail safe.*/
+ $this->planwatch = array();
+ $this->groupData = array();
+ $this->groupData['Send'] = array();
+ $this->groups = array();
/* One major change from the original code is that we do all the DB calls at once to clear any locks and reduce overall latency. */
try{
$currentUid = $this->user->getUserID();
return PLANWORLD_ERROR;
}
else {
- $this->planwatch = array();
- $this->groupData = array();
- $this->groupData['Send'] = array();
- $this->groups = array();
foreach($result1 as $row) {
$watchuser = addslashes($row['username']);
$group = $row['name'];
$arrayGroupLevelList[$intCounter] = array();
$arrayGroupLevelList[$intCounter]['groupname'] = $groupname;
$arrayGroupLevelList[$intCounter]['membership'] = array();
- foreach ($grouparray as $username => $watchrow){
- $watchlineArray = array(
- 'username' => $username,
- 'lastupdate' => date(DATE_ATOM, $watchrow[1]),
- 'lastview' => date(DATE_ATOM, $watchrow[2]),
- 'hasmessage' => $watchrow[3]
- );
- $arrayGroupLevelList[$intCounter]['membership'][] = $watchlineArray;
+ if(!($this->user->doesBlockRelationshipExist($username))){
+
+ foreach ($grouparray as $username => $watchrow){
+ $watchlineArray = array(
+ 'username' => $username,
+ 'lastupdate' => date(DATE_ATOM, $watchrow[1]),
+ 'lastview' => date(DATE_ATOM, $watchrow[2]),
+ 'hasmessage' => $watchrow[3]
+ );
+ $arrayGroupLevelList[$intCounter]['membership'][] = $watchlineArray;
+ }
}
$intCounter++;
}
$temp = new User($uid);
return $temp;
}
- else if (!Planworld::isUser($uid) && !strstr($uid, '@')) {
+ else if (intval(Planworld::isUser($uid)) < 1 && strstr($uid, '@') == false) {
$temp = new User($uid);
return $temp;
}
else {
- list(,$host) = split('@', $uid);
+ list(,$host) = explode('@', $uid);
$nodeinfo = Planworld::getNodeInfo($host);
$temp = new RemoteUser($uid, $nodeinfo);
return $temp;
*/
function loadPlanwatch () {
if (!isset($this->planwatch)) {
- // FIX AND ADD WHEN PLANWATCH IMPLEMENTED
- //$this->planwatch = new Planwatch($this);
- return false;
+ $this->planwatch = new Planwatch($this);
+ return true;
}
else{
return PLANWORLD_ERROR;
/**
* JLO2 20191005 - A simplified form of setPlan that does not support the Archive pieces, drafts, or journaling.
* Implemented so that we would have enough functionality to start building v3 around.
+ JLO2 20200915 - Just realized that nowhere do we actually set the last update time. So we do that here now.
*/
function setPlanSimple ($plan) {
$boolSuccess = true;
$boolSuccess = $query1->execute($queryArray1);
}
catch(PDOException $badquery1){
- return 'LAMPLIGHT';
+ return false;
}
/* process snoop references */
$query2 = $this->dbh->prepare('INSERT INTO plans (uid, content) VALUES (:uid, :plan)');
$queryArray2 = array('uid' => $this->userID, 'plan' =>$plan);
$boolSuccess = $boolSuccess && $query2->execute($queryArray2);
+ if($boolSuccess){
+ $query3 = $this->dbh->prepare('UPDATE users SET last_update=:lastupdate WHERE id = :uid');
+ $queryArray3 = array('uid' => $this->userID, 'lastupdate' => $timestamp);
+ $boolSuccess = $boolSuccess && $query3->execute($queryArray3);
+ }
}
catch(PDOException $badquery2){
return false;