/** * Take the given url and fetch the jsonld it should return. * Then process the jsonld into connections for a graph. * @param $url string of the url to fetch the jsonld from. * @return this, or Error */ function load($url, $timeout = 60, $withHistory = false, $withVotes = false, $withPosts = false) { global $CFG, $HUB_FLM, $HUB_CACHE; $this->withHistory = $withHistory; $this->withVotes = $withVotes; $this->withPosts = $withPosts; $this->connectionSet = new ConnectionSet(); $this->nodeSet = new NodeSet(); $this->userSet = new UserSet(); $doc = $HUB_CACHE->getStringData($url); if ($doc === FALSE) { $doc = loadJsonLDFromURL($url); $HUB_CACHE->setStringData($url, $doc, $timeout); } else { //error_log("URL DATA FOUND: catalyst reader"); } try { // should be done on export of data from url end, but this is a fallback $doc = iconv("UTF-8", "UTF-8//IGNORE", $doc); $item = json_decode($doc); /*$error = json_last_error(); if($error === JSON_ERROR_NONE && $item === null) { $error = JSON_ERROR_SYNTAX; } switch($error) { case JSON_ERROR_NONE: break; case JSON_ERROR_DEPTH: throw new JsonLdException( 'Could not parse JSON; the maximum stack depth has been exceeded.', 'jsonld.ParseError'); case JSON_ERROR_STATE_MISMATCH: throw new JsonLdException( 'Could not parse JSON; invalid or malformed JSON.', 'jsonld.ParseError'); case JSON_ERROR_CTRL_CHAR: case JSON_ERROR_SYNTAX: throw new JsonLdException( 'Could not parse JSON; syntax error, malformed JSON.', 'jsonld.ParseError'); case JSON_ERROR_UTF8: throw new JsonLdException( 'Could not parse JSON from URL; malformed UTF-8 characters.', 'jsonld.ParseError'); default: throw new JsonLdException( 'Could not parse JSON from URL; unknown error.', 'jsonld.ParseError'); } */ } catch (Exception $e) { error_log(print_r($e, true)); } // free up a bit of memory? $doc = null; unset($doc); if ($item != NULL) { $this->processObject($item); // PROCESS USERS INTO SET AND ADD ACTIVITIES AND PROFILE INFO $countUsers = count($this->userArray); if ($countUsers > 0) { foreach ($this->userArray as $userid => $user) { // If the user acount has a profile with any details // Add them to the final user account object. if (isset($user->profileid) && isset($this->userArray[$user->profileid])) { $userprofile = $this->userArray[$user->profileid]; if (isset($userprofile->name)) { $user->name = $userprofile->name; } if (isset($userprofile->description)) { $user->description = $userprofile->description; } if (isset($userprofile->homepage)) { $user->homepage = $userprofile->homepage; } if (isset($userprofile->photo)) { $user->photo = $userprofile->photo; } if (isset($userprofile->thumb)) { $user->thumb = $userprofile->thumb; } //error_log("Profile id for user:"******" profileid=".$user->profileid); } else { //error_log("NO profile id for user:"******""; if (array_key_exists($fromid, $this->nodeArray)) { //error_log("from node"); $fromNode = $this->nodeArray[$fromid]; //error_log("concount".$fromNode->concount); //error_log("procount".$fromNode->procount); //error_log("othercount".$fromNode->othercount); if ($linkname == $CFG->LINK_PRO_SOLUTION && $fromNode->concount == 0 && $fromNode->othercount == 0) { $fromNode->rolename = 'Pro'; } else { if ($linkname == $CFG->LINK_CON_SOLUTION && $fromNode->procount == 0 && $fromNode->othercount == 0) { $fromNode->rolename = 'Con'; } } $role = new Role(); $role->name = $fromNode->rolename; if (array_key_exists($fromNode->rolename, $this->nodeimages)) { $role->image = $this->nodeimages[$fromNode->rolename]; } $fromNode->role = $role; $con->fromrole = $role; } $toNode = ""; if (array_key_exists($toid, $this->nodeArray)) { $toNode = $this->nodeArray[$toid]; $role = new Role(); $role->name = $toNode->rolename; if (array_key_exists($toNode->rolename, $this->nodeimages)) { $role->image = $this->nodeimages[$toNode->rolename]; } $toNode->role = $role; $con->torole = $role; } if ($fromNode != "" && $toNode != "") { $con->from = $fromNode; $con->to = $toNode; if (array_key_exists($id, $this->votesArray)) { $votes = $this->votesArray[$id]; $con->votes = $votes; } $this->connectionSet->add($con); } } $this->connectionSet->count = count($this->connectionSet->connections); $this->connectionSet->totalno = $this->connectionSet->count; } return $this; } else { global $ERROR; $ERROR = new error(); $ERROR->createInvalidJSONLDError(json_last_error()); return $ERROR; } }