예제 #1
0
 /**
  * Format the output to JSON-LD Specifically formatted to the CATALYST INTERCHANGE FORMAT
  *
  * @param Object $object - the data to format
  * @return string
  */
 function format($object)
 {
     global $CFG, $HUB_FLM;
     $this->serviceurl = $CFG->homeAddress . 'api/';
     $api_class = get_class($object);
     // If the passed object has a cipher use it, else create a new one.
     if (isset($object->cipher)) {
         $this->cipher = $object->cipher;
     } else {
         $salt = openssl_random_pseudo_bytes(32);
         $this->cipher = new Cipher($salt);
     }
     $this->mainStr = '{';
     $this->mainStr .= '"@context":[';
     $this->mainStr .= '"http://purl.org/catalyst/jsonld",';
     $this->namespaces .= '{';
     $this->namespaces .= '"' . $this->site . '": "' . $this->serviceurl . '",';
     $this->outerGraphStr .= '"@graph": [';
     switch ($api_class) {
         case "UnobfuscatedUserSet":
             $users = $object->users;
             if (isset($object->cipher)) {
                 foreach ($users as $user) {
                     if (in_array($user->userid, $this->checkUsers) === FALSE) {
                         $this->addFullUserProfile($user);
                         array_push($this->checkUsers, $user->userid);
                     }
                 }
             }
             break;
         case "GroupSet":
             // a set of conversations ?
             $this->addGroups($object);
             break;
         case "Group":
             // a conversation
             $this->addGroup($object);
             break;
         case "View":
             // one issue tree
             $this->addView($object);
             break;
         case "ViewSet":
             // one issue tree
             $this->addViews($object);
             break;
         case "ConnectionSet":
             $this->addConnections($object);
             break;
         case "NodeSet":
             $this->conversationBlockStr .= '{';
             $this->conversationBlockStr .= '"@type":["catalyst:Conversation","Graph"],';
             $this->conversationBlockStr .= '"@id": "' . $this->site . ':nodes",';
             $this->conversationBlockStr .= '},';
             $this->addNodes($object);
             break;
         case "CNode":
             $this->conversationBlockStr .= '{';
             $this->conversationBlockStr .= '"@type": "catalyst:Conversation",';
             $this->conversationBlockStr .= '"@id": "' . $this->site . ':nodes/' . $id . '",';
             $this->conversationBlockStr .= '"data_graph": "' . $this->site . ':nodes"';
             $this->conversationBlockStr .= '},';
             $this->addNode($object);
             break;
             /*
             case "URL":
             				$this->conversationBlockStr .= '"data_graph": "'.$this->site.':urls",';
                  $this->addURL($object);
                  $this->addURL($object);
                  break;
             
             case "URLSet":
             				$this->conversationBlockStr .= '"data_graph": "'.$this->site.':urls",';
                  $nodeUrls = $object->urls;
                  $this->addURLs($nodeUrls);
                  break;
             */
             /*
              case "Connection":
                  $this->addConnection($object);
                  break;
             
              case "User":
              	//$this->conversationBlockStr .= '"pseudonyms_graph": "'.$this->site.':pseudonyms",';
                  $this->addUser($object);
                  break;
             
              case "UserSet":
              	//$this->conversationBlockStr .= '"pseudonyms_graph": "'.$this->site.':pseudonyms",';
                  $users = $object->users;
                  foreach ($users as $user){
                  	if (in_array($user->userid,$this->checkUsers) === FALSE) {
                  	    $this->addUser($user);
                  	    array_push($this->checkUsers, $user->userid);
                  	}
                  }
                  break;
             */
         /*
         case "URL":
         				$this->conversationBlockStr .= '"data_graph": "'.$this->site.':urls",';
              $this->addURL($object);
              $this->addURL($object);
              break;
         
         case "URLSet":
         				$this->conversationBlockStr .= '"data_graph": "'.$this->site.':urls",';
              $nodeUrls = $object->urls;
              $this->addURLs($nodeUrls);
              break;
         */
         /*
          case "Connection":
              $this->addConnection($object);
              break;
         
          case "User":
          	//$this->conversationBlockStr .= '"pseudonyms_graph": "'.$this->site.':pseudonyms",';
              $this->addUser($object);
              break;
         
          case "UserSet":
          	//$this->conversationBlockStr .= '"pseudonyms_graph": "'.$this->site.':pseudonyms",';
              $users = $object->users;
              foreach ($users as $user){
              	if (in_array($user->userid,$this->checkUsers) === FALSE) {
              	    $this->addUser($user);
              	    array_push($this->checkUsers, $user->userid);
              	}
              }
              break;
         */
         case "error":
             $doc .= "<error><message>" . $object->message . "</message><code>" . $object->code . "</code></error>";
             return $doc;
             break;
         default:
             //error as method not defined.
             global $ERROR;
             $ERROR = new error();
             $ERROR->createInvalidMethodError();
             include $HUB_FLM->getCodeDirPath("core/formaterror.php");
             die;
     }
     $this->namespaces = $this->trimFinalComma($this->namespaces);
     $this->namespaces .= '}';
     $this->mainStr .= $this->namespaces;
     $this->mainStr .= '],';
     if ($this->conversationBlockStr != "") {
         $this->outerGraphStr .= $this->conversationBlockStr;
     }
     // ADD ANNOTAION OUTER GRAPHS
     if ($this->annotationGraphListStr != "") {
         $this->outerGraphStr .= $this->annotationGraphListStr;
     }
     // ADD DATA GRAPH
     if ($this->dataGraphStr != "") {
         $this->outerGraphStr .= $this->dataGraphStr;
     }
     // ADD HISTORY GRAPH
     if ($this->historyGraphStr != "") {
         $this->outerGraphStr .= $this->historyGraphStr;
     }
     $this->outerGraphStr = $this->trimFinalComma($this->outerGraphStr);
     $this->outerGraphStr .= ']';
     $this->mainStr .= $this->outerGraphStr;
     $this->mainStr .= '}';
     if (isset($object->unobfuscationid) && $object->unobfuscationid != "" && $api_class != "UnobfuscatedUserSet") {
         $count = count($this->checkUsers);
         $users = "";
         for ($i = 0; $i < $count; $i++) {
             $userid = $this->checkUsers[$i];
             if ($userid != "") {
                 $users .= $userid . ",";
             }
         }
         $users = trimFinalComma($users);
         setObfuscationUsers($object->unobfuscationid, $users);
     }
     return $this->mainStr;
 }
예제 #2
0
     if ($len == 2) {
         $urlset = getURLsByGlobal(0, -1, 'date', 'ASC');
         $urlset->cipher = $cipher;
         if (isset($unobfuscationid) && $unobfuscationid != "") {
             $urlset->unobfuscationid = $unobfuscationid;
         }
         $response = $userset;
         break;
     } else {
         if ($len == 3) {
             $id = check_param($parts[2], PARAM_TEXT);
             $url = getURL($id);
             $url->cipher = $cipher;
             if (isset($unobfuscationid) && $unobfuscationid != "") {
                 $users = $url->userid;
                 setObfuscationUsers($unobfuscationid, $users);
             }
             $response = $url;
         }
     }
     break;
 case "nodes":
     if ($len == 2) {
         $nodeset = getNodesByGlobal(0, -1, 'date', 'ASC');
         $nodeset->cipher = $cipher;
         if (isset($unobfuscationid) && $unobfuscationid != "") {
             $nodeset->unobfuscationid = $unobfuscationid;
         }
         $response = $nodeset;
         break;
     } else {