From: Johnnie Lamar Odom II Date: Sun, 20 Sep 2020 21:47:04 +0000 (-0500) Subject: Changes to support more recent PHP versions and bugfixes for issues discovered early... X-Git-Url: https://git.planwatch.world/gitweb/?a=commitdiff_plain;h=8270596d99ff39b37787b83f09c135f6a3323f49;p=planworld_public.git Changes to support more recent PHP versions and bugfixes for issues discovered early in the full Javascript client (which is at https://github.com/jlodom/planworld_javascript_client_basic ) --- diff --git a/code/clientlib/3.00/plan.php b/code/clientlib/3.00/plan.php index 9f2e74a..df44585 100644 --- a/code/clientlib/3.00/plan.php +++ b/code/clientlib/3.00/plan.php @@ -8,6 +8,7 @@ function planGet($arrayRestInputs){ 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; @@ -17,6 +18,10 @@ function planGet($arrayRestInputs){ 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{ diff --git a/code/lib/NodeToken.php b/code/lib/NodeToken.php index fea073b..29e162f 100644 --- a/code/lib/NodeToken.php +++ b/code/lib/NodeToken.php @@ -93,8 +93,13 @@ class NodeToken { $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{ diff --git a/code/lib/Planwatch.php b/code/lib/Planwatch.php index 605e605..a17af05 100644 --- a/code/lib/Planwatch.php +++ b/code/lib/Planwatch.php @@ -36,6 +36,13 @@ class Planwatch { /* 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(); @@ -54,10 +61,6 @@ class Planwatch { 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']; @@ -403,14 +406,17 @@ class Planwatch { $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++; } diff --git a/code/lib/User.php b/code/lib/User.php index ca69cf0..5d2963e 100755 --- a/code/lib/User.php +++ b/code/lib/User.php @@ -56,12 +56,12 @@ class User { $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; @@ -380,9 +380,8 @@ class User { */ 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; @@ -1239,6 +1238,7 @@ class User { /** * 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; @@ -1254,7 +1254,7 @@ class User { $boolSuccess = $query1->execute($queryArray1); } catch(PDOException $badquery1){ - return 'LAMPLIGHT'; + return false; } /* process snoop references */ @@ -1268,6 +1268,11 @@ class User { $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;