public function mapTagOnConcept($tag, $concept, $userid, $significance, $ontologyid)
 {
     if (empty($tag) || empty($concept) || empty($significance) || empty($ontologyid)) {
         return false;
     }
     $url = $this->_mapping_endpoint . $ontologyid . '/force_mapping';
     $taglabel = $tag->getLabel();
     $uri = $concept->getUri();
     $params = "userId={$userid}&tag={$taglabel}&conceptUri={$uri}&significance={$significance}";
     //Going curl
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
     $xmlanswer = curl_exec($ch);
     curl_close($ch);
     //Parsing the answer
     $doc = new DOMDocument();
     $doc->LoadXML($xmlanswer);
     $xpath = new DOMXPath($doc);
     //	Extracting tag information
     $query = '/tagonto';
     $requeststatus = $xpath->query($query);
     //No result here
     if ($requeststatus->length == 0) {
         return false;
     }
     //Checking requestSatisfied
     $requestresult = $requeststatus->item(0)->getAttribute('requestSatisfied');
     if ($requestresult == 'true') {
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 public function getResourcesForTag($tag)
 {
     //Getting the tag label
     $tagtosearch = $tag->getLabel();
     //Before everything else, we have to retrieve TAG ID from the tag name
     $tagresendpoint = 'http://www.43things.com/service/get_tags_goals?id=';
     $tagresendpoint .= $tagtosearch;
     $tagresendpoint .= '&api_key=' . $this->_APIKEY;
     $ch = curl_init($tagresendpoint);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $xmldoc = curl_exec($ch);
     curl_close($ch);
     //43Things will return an empty page on no match
     if (empty($xmldoc)) {
         return array();
     }
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     //Loading the XML doc
     $doc->LoadXML($xmldoc);
     $xpath = new DOMXPath($doc);
     //WE HAVE TO SETUP THINGS TO USE THE DEFAULT NAMESPACE
     $defnamespace = $doc->documentElement->lookupnamespaceURI(NULL);
     $xpath->registerNamespace('m', $defnamespace);
     //Extracting tag information
     $query = '/m:feed/m:goal';
     $entries = $xpath->query($query);
     if (empty($entries)) {
         return array();
     }
     foreach ($entries as $entry) {
         $TempRes = new Result();
         $TempRes->setUrl($entry->getElementsByTagName('link')->item(0)->getAttribute('href'));
         $TempRes->setTitle($entry->getElementsByTagName('name')->item(0)->nodeValue);
         $TempRes->setShownContent($TempRes->getUrl());
         $TempRes->setDescription('');
         $TempRes->setTagSearched($tag);
         $TempRes->setContentType(0);
         //text
         $ResourceBundle[] = $TempRes;
     }
     return $ResourceBundle;
 }
Example #3
0
 protected static function StaticDomDocumentReplace(&$String)
 {
     if (substr(ltrim($String), 0, 5) != '<?xml') {
         $String = '<?xml version="1.0" encoding="UTF-8"?' . ">\n" . $String;
     }
     $DOMDocument = DOMDocument::LoadXML($String, LIBXML_NOERROR);
     if ($DOMDocument === False) {
         return $String;
     }
     $ImageDimensions = self::ImageDimensions();
     $BeforeCount = count($ImageDimensions);
     $Domain = Gdn::Request()->Domain();
     $DomNodeList = $DOMDocument->GetElementsByTagName('img');
     for ($i = $DomNodeList->length - 1; $i >= 0; $i--) {
         $Node = $DomNodeList->Item($i);
         $Width = $Node->GetAttribute('width');
         $Height = $Node->GetAttribute('height');
         if ($Width == '' && $Height == '') {
             $Src = $Node->GetAttribute('src');
             if (!$Src) {
                 continue;
             }
             $Src = AbsoluteSource($Src, $Domain);
             $CrcKey = crc32($Src);
             if (!array_key_exists($CrcKey, $ImageDimensions)) {
                 $ImageSize = getimagesize($Src);
                 $ImageDimensions[$CrcKey] = array($ImageSize[0], $ImageSize[1], '_src' => $Src);
             } else {
                 $ImageSize = $ImageDimensions[$CrcKey];
             }
             if ($ImageSize[0] && $ImageSize[1]) {
                 $Node->SetAttribute('width', $ImageSize[0]);
                 $Node->SetAttribute('height', $ImageSize[1]);
             }
         }
     }
     // Save cache.
     if (count($ImageDimensions) != $BeforeCount) {
         self::ImageDimensions($ImageDimensions);
     }
     $String = $DOMDocument->saveXML();
     // LIBXML_NOXMLDECL | LIBXML_NOENT
     //$DOMDocument->formatOutput = True;
     //$String = $DOMDocument->saveXML(Null, LIBXML_NOXMLDECL | LIBXML_NOENT);
     //d($String);
 }
Example #4
0
 function DownloadMarkup()
 {
     $resourceService = $this->site->CreateService(MgServiceType::ResourceService);
     $featureService = $this->site->CreateService(MgServiceType::FeatureService);
     $markupLayerResId = new MgResourceIdentifier($this->args['MARKUPLAYER']);
     $markupFsId = new MgResourceIdentifier($this->GetResourceIdPrefix() . $markupLayerResId->GetName() . '.FeatureSource');
     $extension = $this->GetFileExtension($markupLayerResId->ToString());
     if (strcmp($extension, ".zip") == 0) {
         $dataList = $resourceService->EnumerateResourceData($markupFsId);
         $doc = DOMDocument::LoadXML($dataList->ToString());
         $dataItems = $doc->getElementsByTagName("Name");
         $tmpFiles = array();
         //Copy out all data files to a temp location
         for ($i = 0; $i < $dataItems->length; $i++) {
             $dataName = $dataItems->item($i)->nodeValue;
             $byteReader = $resourceService->GetResourceData($markupFsId, $dataName);
             //Sink to temp file
             $tmpSink = new MgByteSink($byteReader);
             $fileName = tempnam(sys_get_temp_dir(), $dataName);
             $tmpSink->ToFile($fileName);
             $tmpFiles[$dataName] = $fileName;
         }
         //Zip them up.
         $zipName = $markupLayerResId->GetName() . $extension;
         $zipPath = tempnam(sys_get_temp_dir(), $zipName);
         $zip = new ZipArchive();
         $zip->open($zipPath, ZIPARCHIVE::CREATE);
         foreach ($tmpFiles as $dataName => $filePath) {
             $dataNorm = strtolower($dataName);
             //HACK: There must be some defect in MgFeatureService::CreateFeatureSource() for SHP
             //files or the FDO provider, because even if we plug in a coord sys WKT when we create
             //it, we get a blank prj file (both Windows/Linux). Re-uploading this same zip file back into
             //the widget causes problems in Linux (markup features not rendered) because of the blank prj.
             //
             //So that's the problem. Here's the workaround: If we find a blank prj file as we're assembling
             //the zip file for download, pump our current Map's WKT into the prj file before packaging it up
             //
             //That's what we were already doing when we called MgFeatureService::CreateFeatureSource(), but it
             //or the provider didn't like it.
             if (substr($dataNorm, strlen($dataNorm) - strlen("prj")) == "prj") {
                 $content = file_get_contents($filePath);
                 if (strlen($content) == 0) {
                     $map = new MgMap();
                     $map->Open($resourceService, $this->args['MAPNAME']);
                     $content = $map->GetMapSRS();
                     file_put_contents($filePath, $content);
                 }
             }
             $zip->addFile($filePath, $dataName);
         }
         $zip->close();
         //Serve it up for download
         $bs = new MgByteSource($zipPath);
         $br = $bs->GetReader();
         $len = $br->GetLength();
         $outputBuffer = '';
         $buffer = '';
         while ($br->Read($buffer, 50000) != 0) {
             $outputBuffer .= $buffer;
         }
         header("Content-Type: application/octet-stream");
         header("Content-Disposition: attachment; filename={$zipName}");
         header("Content-Length: " . strlen($outputBuffer));
         echo $outputBuffer;
         //Let's be nice and clean up after ourselves
         unlink($zipPath);
         foreach ($tmpFiles as $dataName => $filePath) {
             unlink($filePath);
         }
     } else {
         //Single file, make things easier!
         $dataName = $markupLayerResId->GetName() . $extension;
         $byteReader = $resourceService->GetResourceData($markupFsId, $dataName);
         $len = $byteReader->GetLength();
         $outputBuffer = '';
         $buffer = '';
         while ($byteReader->Read($buffer, 50000) != 0) {
             $outputBuffer .= $buffer;
         }
         header("Content-Type: " . $byteReader->GetMimeType());
         header("Content-Disposition: attachment; filename={$dataName}");
         header("Content-Length: " . strlen($outputBuffer));
         echo $outputBuffer;
     }
 }
Example #5
0
     $layer = $layers->GetItem($i);
     $lid = $layer->GetLayerDefinition();
     $layerDefinitionIds->Add($lid->ToString());
     $featureSourceIds->Add($layer->GetFeatureSourceId());
 }
 //Get the layer contents in a single batch
 $layerDefinitionContents = $resourceService->GetResourceContents($layerDefinitionIds, null);
 $featureSourceContents = $resourceService->GetResourceContents($featureSourceIds, null);
 $layerDocs = array();
 $fsDocs = array();
 for ($i = 0; $i < $layers->GetCount(); $i++) {
     $ldfContent = $layerDefinitionContents->GetItem($i);
     $ldfdoc = DOMDocument::LoadXML($ldfContent);
     array_push($layerDocs, $ldfdoc);
     $fsContent = $featureSourceContents->GetItem($i);
     $fsDoc = DOMDocument::LoadXML($fsContent);
     array_push($fsDocs, $fsDoc);
 }
 for ($i = 0; $i < $layers->GetCount(); $i++) {
     //only output layers that are part of the 'Normal Group' and
     //not the base map group used for tile maps.  (Where is the test for that Y.A.???)
     $layer = $layers->GetItem($i);
     $layerContent = $layerDocs[$i];
     $fsContent = $fsDocs[$i];
     $layerObj = NULL;
     $mappings = GetLayerPropertyMappings($resourceService, $layer, $layerContent);
     $_SESSION['property_mappings'][$layer->GetObjectId()] = $mappings;
     $layerObj->uniqueId = $layer->GetObjectId();
     $layerObj->layerName = addslashes($layer->GetName());
     //$aLayerTypes = GetLayerTypes($featureService, $layer);
     $aLayerTypes = GetLayerTypesFromResourceContent($layer, $layerContent);
Example #6
0
 public function getRelatedTags($tag)
 {
     $taglabel = $tag->getLabel();
     //Retrieving related tags
     //Getting the tag label
     $tagtosearch = $tag->getLabel();
     //To retrieve tag friends, we have to search for a tag and then
     //retrieve all the tags listed in the same document
     $tagendpoint = 'http://www.connotea.org/data/bookmarks/tag/';
     $tagendpoint .= $tagtosearch;
     $ch = curl_init($tagendpoint);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_USERPWD, $this->_username . ":" . $this->_password);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     $xmldoc = curl_exec($ch);
     curl_close($ch);
     if (empty($xmldoc)) {
         return array();
     }
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     //Loading the XML doc
     $doc->LoadXML($xmldoc);
     $xpath = new DOMXPath($doc);
     //registering the namespaces, both the dcterms one and the default one
     $defnamespace = $doc->documentElement->lookupnamespaceURI("dcterms");
     $xpath->registerNamespace('dcterms', $defnamespace);
     $xpath->registerNamespace('def', "http://www.connotea.org/2005/01/schema#");
     //$defnamespace2 = $doc->documentElement->lookupnamespaceURI("dcterms");
     //Extracting result information
     $query = '//dcterms:URI/def:tag';
     $entries = $xpath->query($query);
     //No tag found
     if ($entries->length == 0) {
         return array();
     }
     $TempStorage = array();
     foreach ($entries as $eletagtag) {
         if (!in_array($eletagtag->nodeValue, $TempStorage)) {
             $TempStorage[] = $eletagtag->nodeValue;
         }
     }
     foreach ($TempStorage as $taglabel) {
         $ResourceBundle[] = new Tag($taglabel);
     }
     //TODO number of matches?
     //Building return array
     return $ResourceBundle;
 }
Example #7
0
 public function getResourcesForTag($tag)
 {
     //Getting the tag label
     $tagtosearch = $tag->getLabel();
     //Before everything else, we have to retrieve TAG ID from the tag name
     $tagbynameendpoint = 'http://www.zvents.com/rest/tag_by_name/';
     $tagbynameendpoint .= $tagtosearch;
     $tagbynameendpoint .= '?key=' . $this->_APIKEY;
     $ch = curl_init($tagbynameendpoint);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $xmldoc = curl_exec($ch);
     curl_close($ch);
     if (empty($xmldoc)) {
         return array();
     }
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     //Loading the XML doc
     $doc->LoadXML($xmldoc);
     $xpath = new DOMXPath($doc);
     //Extracting tag information
     $query = '//tag';
     $entries = $xpath->query($query);
     if ($entries->length == 0) {
         return array();
     }
     $tagid = $entries->item(0)->getAttributeNode('id')->nodeValue;
     //We can now query for related events
     $taginfoendpoint = 'http://www.zvents.com/rest/tag_events/';
     $taginfoendpoint .= $tagid;
     //query has to be done using the tag
     $taginfoendpoint .= '?key=' . $this->_APIKEY;
     //Curl init
     $ch = curl_init($taginfoendpoint);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $xmldoc = curl_exec($ch);
     curl_close($ch);
     //DOC init
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     //Loading the XML doc
     $doc->LoadXML($xmldoc);
     $xpath = new DOMXPath($doc);
     //Extracting tag information
     $query = '//event';
     $entries = $xpath->query($query);
     //TODO better error handling
     if (empty($entries)) {
         return array();
     }
     foreach ($entries as $entry) {
         $TempRes = new Result();
         $TempRes->setUrl($entry->getElementsByTagName('link')->item(0)->nodeValue);
         $TempRes->setTitle($entry->getElementsByTagName('name')->item(0)->nodeValue);
         $TempRes->setShownContent($entry->getElementsByTagName('link')->item(0)->nodeValue);
         $TempRes->setDescription($entry->getElementsByTagName('description')->item(0)->nodeValue);
         $TempRes->setTagSearched($tag);
         $TempRes->setContentType(0);
         //text
         $ResourceBundle[] = $TempRes;
     }
     return $ResourceBundle;
 }