structSearch.module
Go to the documentation of this file.
00001 <?php 00002 00003 00004 00007 00017 // Include the utilities function used by the hooks and tools 00018 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/utilities.php'); 00019 00020 00036 function structSearch_main() 00037 { 00038 global $base_url; 00039 00040 drupal_set_html_head("<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"" . $base_url . "/" 00041 . drupal_get_path("module", "structSearch") . "/css/style.css\" />"); 00042 00043 return (conStruct_search("", TRUE)); 00044 } 00045 00077 function structSearch_access($op, $node, $account) 00078 { 00079 return TRUE; 00080 } 00081 00099 function structSearch_access_callback() 00100 { 00101 return TRUE; 00102 } 00103 00104 00135 function structSearch_block($op = 'list', $delta = 0, $edit = array()) 00136 { 00137 global $base_url; 00138 00139 // The $op parameter determines what piece of information is being requested. 00140 switch ($op) 00141 { 00142 case 'list': 00143 00144 // If $op is "list", we just need to return a list of block descriptions. 00145 // This is used to provide a list of possible blocks to the administrator, 00146 // end users will not see these descriptions. 00147 $blocks[0]['info'] = t('conStruct Search Tool'); 00148 return $blocks; 00149 00150 case 'configure': 00151 // If $op is "configure", we need to provide the administrator with a 00152 // configuration form. The $delta parameter tells us which block is being 00153 // configured. In this example, we'll allow the administrator to customize 00154 // the text of the first block. 00155 $form = array(); 00156 if ($delta == 0) 00157 { 00158 // All we need to provide is a text field, Drupal will take care of 00159 // the other block configuration options and the save button. 00160 $form['block_example_string'] = array( 00161 '#type' => 'textfield', 00162 '#title' => t('Block contents'), 00163 '#size' => 100, 00164 '#description' => t('This string will appear in the conStruct Tools menu'), 00165 '#default_value' => variable_get('conStruct_string', t('')) 00166 ); 00167 } 00168 00169 return $form; 00170 00171 case 'save': 00172 00173 // If $op is "save", we need to save settings from the configuration form. 00174 // Since the first block is the only one that allows configuration, we 00175 // need to check $delta to make sure we only save it. 00176 if ($delta == 0) 00177 { 00178 // Have Drupal save the string to the database. 00179 variable_set('structSearch_string', $edit['structSearch_string']); 00180 } 00181 return; 00182 00183 case 'view': 00184 00185 default: 00186 00187 // If $op is "view", then we need to generate the block for display 00188 // purposes. The $delta parameter tells us which block is being requested. 00189 switch ($delta) 00190 { 00191 case 0: 00192 // The subject is displayed at the top of the block. Note that it 00193 // should be passed through t() for translation. 00194 $block['subject'] = t('conStruct Search Tool'); 00195 // The content of the block is typically generated by calling a custom 00196 // function. 00197 $block['content'] = structSearch_contents(1); 00198 break; 00199 } 00200 return $block; 00201 } 00202 } 00203 00215 function structSearch_contents($which_block) 00216 { 00217 global $base_url; 00218 00219 if ($which_block == 1) 00220 { 00221 // Get the base path of the Drupal installation folder on the file system of the server 00222 $menuItems = ""; 00223 00224 if (user_access('access conStruct search')) 00225 { 00226 $localPath = $base_url . "/" . drupal_get_path("module", "structSearch") . "/imgs/"; 00227 00228 // For all users 00229 $menuItems .= "<img src=\"" . $localPath . "katomic.png\" style=\"padding-right:5px;\" alt=\"\" /><a href=\"" . $base_url 00230 . "/conStruct/search/\">Search</a><br />"; 00231 } 00232 00233 return variable_get('structSearch_menu', t($menuItems)); 00234 } 00235 } 00236 00254 function structSearch_menu() 00255 { 00256 $items = array(); 00257 00258 // Registration of the main conStruct module page path 00259 $items['conStruct/search'] = array( 00260 'page callback' => 'structSearch_main', 00261 'access callback' => 'structSearch_access_callback', 00262 'type' => MENU_CALLBACK 00263 ); 00264 00265 return $items; 00266 } 00267 00268 00296 function structSearch_perm() 00297 { 00298 return array( 00299 'access conStruct search', 00300 'administer conStruct search' 00301 ); 00302 } 00303 00304 00324 function conStruct_search($baseLinksUrl, $showFilters) 00325 { 00326 // Make sure the user has access to this tool 00327 if (!user_access('access conStruct search')) 00328 { 00329 return "<h2>" . t("You don't have access to this tool, sorry.") . "</h2>"; 00330 } 00331 else 00332 { 00333 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/WebServiceQuerier.php'); 00334 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/ProcessorXML.php'); 00335 00336 00337 // Display errors when in debug mode 00338 if (!isset($_GET['debug']) || $_GET['debug'] != 1) 00339 { 00340 ini_set("error_reporting", 0); 00341 } 00342 00343 // Current page of the resultset to display to the user 00344 $page = 0; 00345 00346 if (isset($_GET['page'])) 00347 { 00348 $page = $_GET['page']; 00349 } 00350 00351 // Requested mime of a search page resultset export 00352 $requestedMime = ""; 00353 00354 if (isset($_GET['mime'])) 00355 { 00356 // Check if the mime is supported 00357 if ($_GET["mime"] == "application/json" || $_GET["mime"] == "application/iron+json" 00358 || $_GET["mime"] == "application/rdf+xml" || $_GET["mime"] == "application/rdf+n3" 00359 || $_GET["mime"] == "text/xml") 00360 { 00361 $requestedMime = $_GET['mime']; 00362 } 00363 } 00364 00365 // Filtering on/off flag 00366 $filterStatus = "off"; 00367 00368 if (isset($_GET['filter'])) 00369 { 00370 $filterStatus = strtolower($_GET['filter']); 00371 } 00372 00373 global $base_url; 00374 00375 $query = $_GET['query']; 00376 00377 // Get all possible datasets, types and attributes filter from the query parameters 00378 $filterDatasets = array(); 00379 $filterTypes = array(); 00380 $filterAttributes = array(); 00381 00382 // This string used to re-create the proper search URL with all parameters in it (mainly used for paging URLs) 00383 $filterParameters = ""; 00384 00385 foreach ($_GET as $param => $value) 00386 { 00387 if (stripos($param, "filter_datasets_") !== FALSE) 00388 { 00389 array_push($filterDatasets, urlencode($value)); 00390 $filterParameters .= "&filter_datasets_" . str_replace("filter_datasets_", "", $param) . "=" 00391 . urlencode($value); 00392 } 00393 elseif (stripos($param, "filter_types_") !== FALSE) 00394 { 00395 array_push($filterTypes, urlencode($value)); 00396 $filterParameters .= "&filter_types_" . str_replace("filter_types_", "", $param) . "=" . urlencode($value); 00397 } 00398 elseif (stripos($param, "filter_attributes_") !== FALSE) 00399 { 00400 array_push($filterAttributes, urlencode(urlencode($value))); 00401 $filterParameters .= "&filter_attributes_" . str_replace("filter_attributes_", "", $param) . "=" 00402 . urlencode($value); 00403 } 00404 } 00405 00406 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/ClassHierarchy.php'); 00407 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/PropertyHierarchy.php'); 00408 include_once(drupal_get_path('module', 'structSearch') . '/settings.php'); 00409 00410 $userIP = variable_get("conStruct_AccessUser" . $user->uid, ""); 00411 $filename = './' . drupal_get_path('module', 'conStruct') . '/framework/ontologies/classHierarchySerialized.srz'; 00412 $file = fopen($filename, "r"); 00413 $classHierarchy = fread($file, filesize($filename)); 00414 $classHierarchy = unserialize($classHierarchy); 00415 fclose($file); 00416 00417 $filename = './' . drupal_get_path('module', 'conStruct') . '/framework/ontologies/propertyHierarchySerialized.srz'; 00418 $file = fopen($filename, "r"); 00419 $propertyHierarchy = fread($file, filesize($filename)); 00420 $propertyHierarchy = unserialize($propertyHierarchy); 00421 fclose($file); 00422 00423 $inference = "on"; 00424 $html = ""; 00425 00426 if (isset($_GET['query'])) 00427 { 00428 $query = rtrim(ltrim($query)); 00429 00430 // Count the number of resources belonging to the resultset of this search query 00431 $nbResources = 0; 00432 $results = array(); 00433 $typeAggregates = array(); 00434 $attributeAggregates = array(); 00435 $datasetAggregates = array(); 00436 $searchPagingHtml = ""; 00437 00438 $datasetTab = ""; 00439 $typeTab = ""; 00440 $attributeTab = ""; 00441 00442 global $user; 00443 00444 $userIP = variable_get("conStruct_AccessUser" . $user->uid, ""); 00445 00446 if ($userIP == "") 00447 { 00448 // If there is no IP for that user, we overload the IP of the node with "::" 00449 $userIP = "self::$user->uid"; 00450 } 00451 00452 $wsfRegistry = variable_get("WSF-Registry", ""); 00453 00454 if ($wsfRegistry != "") 00455 { 00456 $includedWsfAddresses = array(); 00457 00458 $sidRegistry = variable_get("SID-Registry", ""); 00459 00460 // Count the number of items displayed in the page so far 00461 $pageCount = $page; 00462 00463 $wsfPageStartingPoint = 0; 00464 00465 foreach ($wsfRegistry as $wsfAddress) 00466 { 00467 $sid = ""; 00468 00469 // Make sure that we don't query the same server twice 00470 foreach ($sidRegistry as $s => $wsfs) 00471 { 00472 if (array_search($wsfAddress, $wsfs) !== FALSE) 00473 { 00474 $sid = $s; 00475 } 00476 } 00477 00478 if ($sid !== FALSE && array_search($sid, $includedWsfAddresses) === FALSE) 00479 { 00480 array_push($includedWsfAddresses, $sid); 00481 } 00482 else 00483 { 00484 continue; 00485 } 00486 00487 // Now, lets create the union of all datasets created/linked for that node. We will only query them (even if 00488 // world readable (public) ones can be accessible from a target WSF) 00489 00490 $targetDatasets = ""; 00491 00492 // We want to query all datasets 00493 if (count($filterDatasets) == 0) 00494 { 00495 $resultset = db_query('SELECT nid FROM {og}'); 00496 00497 $linkedDatasets = variable_get("Linked-Dataset-Registry", ""); 00498 00499 while ($datasetId = db_result($resultset)) 00500 { 00501 $datasetWsf = variable_get("Dataset-" . $datasetId . "-WSF", ""); 00502 00503 if ($datasetWsf == $wsfAddress) 00504 { 00505 // If this dataset come from this WSF Address, then we include it into the dataset to search for. 00506 00507 // Check if it is a linked dataset 00508 if (isset($linkedDatasets[$datasetId])) 00509 { 00510 $targetDatasets .= $linkedDatasets[$datasetId] . ";"; 00511 } 00512 else 00513 { 00515 $datasetsRegistry = variable_get("Datasets-Registry", ""); 00516 00517 if ($datasetsRegistry != "" && isset($datasetsRegistry[$datasetId])) 00518 { 00519 $targetDatasets .= $datasetsRegistry[$datasetId] . ";"; 00520 } 00521 else 00522 { 00523 global $base_url; 00524 00525 $targetDatasets .= get_domain($base_url) . "/wsf/datasets/" . $datasetId . "/;"; 00526 } 00527 } 00528 } 00529 } 00530 00531 $targetDatasets = substr($targetDatasets, 0, strlen($targetDatasets) - 1); 00532 } 00533 00534 // Generate the filtering stucture to pass to the seach web service. 00535 00536 $filters = ""; 00537 00538 if ($filterStatus == "on") 00539 { 00540 if (count($filterTypes) > 0) 00541 { 00542 $filters .= "&types=" . implode(";", $filterTypes); 00543 } 00544 00545 if (count($filterAttributes) > 0) 00546 { 00547 $filters .= "&attributes=" . implode(";", $filterAttributes); 00548 } 00549 00550 if (count($filterDatasets) > 0) 00551 { 00552 $filters .= "&datasets=" . implode(";", $filterDatasets); 00553 00554 if ($targetDatasets != "") 00555 { 00556 $filters .= ";" . $targetDatasets; 00557 } 00558 } 00559 elseif ($targetDatasets != "") 00560 { 00561 $filters .= "&datasets=" . $targetDatasets; 00562 } 00563 } 00564 else 00565 { 00566 if ($targetDatasets != "") 00567 { 00568 $filters = "&datasets=" . $targetDatasets; 00569 } 00570 else 00571 { 00572 $filters = "&datasets=all"; 00573 } 00574 } 00575 00576 if (($pageCount - $page) < 10) 00577 { 00578 $wsq = new WebServiceQuerier($wsfAddress . "search/", "post", "text/xml", 00579 "query=" . urlencode($query) . $filters . "&items=" . (10 - ($pageCount - $page)) . "&page=" 00580 . ($pageCount - $typeAggregates["http://www.w3.org/2002/07/owl#Thing"]) 00581 . "&inference=on&include_aggregates=true®istered_ip=" . urlencode($userIP), 5); 00582 } 00583 else 00584 { 00585 // The page is already full. We query the remaining WSF only to get their counts and aggregates. 00586 $wsq = new WebServiceQuerier($wsfAddress . "search/", "post", "text/xml", 00587 "query=" . urlencode($query) . $filters . "&items=0&inference=on&include_aggregates=true®istered_ip=" 00588 . urlencode($userIP), 5); 00589 } 00590 00591 if ($wsq->getStatus() == 200) 00592 { 00593 // If a mime type has been requested, we send the resultset to the user (instead of a webpage) 00594 if ($requestedMime != "") 00595 { 00596 $fileextension = ""; 00597 00598 switch ($requestedMime) 00599 { 00600 case "application/json": 00601 00602 $fileextension = "js"; 00603 break; 00604 00605 case "application/iron+json": 00606 $fileextension = "irjson"; 00607 break; 00608 00609 case "text/xml": 00610 $fileextension = "xml"; 00611 break; 00612 00613 case "application/rdf+xml": 00614 $fileextension = "rdf"; 00615 break; 00616 00617 case "application/rdf+n3": 00618 $fileextension = "n3"; 00619 break; 00620 } 00621 00622 // Query the CrudRead web service to getthe whole description of all records of this resultset. 00623 $xml = new ProcessorXML(); 00624 $xml->loadXML($wsq->getResultset()); 00625 00626 $subjects = $xml->getSubjects(); 00627 00628 $recordsUriList = ""; 00629 $recordsDatasetUriList = ""; 00630 00631 foreach ($subjects as $subject) 00632 { 00633 $recordType = $xml->getType($subject, FALSE); 00634 00635 if ($recordType != "http://purl.org/ontology/aggregate#Aggregate") 00636 { 00637 $recordUri = $xml->getURI($subject); 00638 $recordsUriList .= urlencode($recordUri) . ";"; 00639 00640 $predicates = $xml->getPredicatesByType($subject, "http://purl.org/dc/terms/isPartOf"); 00641 $datasetUri = ""; 00642 00643 foreach ($predicates as $predicate) 00644 { 00645 $objects = $xml->getObjects($predicate); 00646 $datasetUri = $xml->getURI($objects->item(0)); 00647 00648 $recordsDatasetUriList .= urlencode($datasetUri) . ";"; 00649 00650 break; 00651 } 00652 } 00653 } 00654 00655 $recordsUriList = trim($recordsUriList, ";"); 00656 $recordsDatasetUriList = trim($recordsDatasetUriList, ";"); 00657 00658 $wsq = new WebServiceQuerier($wsfAddress . "crud/read/", "get", $requestedMime, 00659 "uri=" . $recordsUriList . "&dataset=" . $recordsDatasetUriList . "®istered_ip=" 00660 . urlencode($userIP) . "&include_reification=true&include_linksback=false", 256); 00661 00662 if ($wsq->getStatus() == 200) 00663 { 00664 header("HTTP/1.1 " . $wsq->getStatus() . " " . $wsq->getStatusMessage()); 00665 00666 // With the Search tool, if the irJSON mime as been requested, we return application/json 00667 // to make it processable by JSON aware browser tools. 00668 if ($requestedMime == "application/iron+json") 00669 { 00670 $requestedMime = "application/json"; 00671 } 00672 header("Content-Type: " . $requestedMime . "; charset=utf-8"); 00673 header("Content-Disposition: filename=search-tool-$page.$fileextension"); 00674 00675 echo $wsq->getResultset(); 00676 00677 return; 00678 } 00679 else 00680 { 00681 return ""; 00682 } 00683 } 00684 00685 $xml = new ProcessorXML(); 00686 $xml->loadXML($wsq->getResultset()); 00687 00688 $aggregates = $xml->getSubjectsByType("aggr:Aggregate"); 00689 00690 foreach ($aggregates as $aggregate) 00691 { 00692 $aggregetionType = $xml->getPredicatesByType($aggregate, "aggr:property"); 00693 $aggregetionTypeObj = $xml->getObjects($aggregetionType->item(0)); 00694 00695 switch ($xml->getURI($aggregetionTypeObj->item(0))) 00696 { 00697 case "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": 00698 $aggregateObject = $xml->getPredicatesByType($aggregate, "aggr:object"); 00699 $aggregateObjectObj = $xml->getObjects($aggregateObject->item(0)); 00700 00701 $aggregateCount = $xml->getPredicatesByType($aggregate, "aggr:count"); 00702 $aggregateCountObj = $xml->getObjects($aggregateCount->item(0)); 00703 if (!isset($typeAggregates[$xml->getURI($aggregateObjectObj->item(0))])) 00704 { 00705 $typeAggregates[$xml->getURI($aggregateObjectObj->item(0))] = $xml->getContent( 00706 $aggregateCountObj->item(0)); 00707 } 00708 else 00709 { 00710 $typeAggregates[$xml->getURI($aggregateObjectObj->item(0))] += $xml->getContent( 00711 $aggregateCountObj->item(0)); 00712 } 00713 00714 break; 00715 00716 case "http://rdfs.org/ns/void#Dataset": 00717 $aggregateObject = $xml->getPredicatesByType($aggregate, "aggr:object"); 00718 $aggregateObjectObj = $xml->getObjects($aggregateObject->item(0)); 00719 00720 $aggregateCount = $xml->getPredicatesByType($aggregate, "aggr:count"); 00721 $aggregateCountObj = $xml->getObjects($aggregateCount->item(0)); 00722 00723 $datasetAggregates[$xml->getURI($aggregateObjectObj->item(0))] = 00724 $xml->getContent($aggregateCountObj->item(0)); 00725 break; 00726 00727 case "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property": 00728 $aggregateObject = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#object"); 00729 $aggregateObjectObj = $xml->getObjects($aggregateObject->item(0)); 00730 00731 $aggregateCount = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#count"); 00732 $aggregateCountObj = $xml->getObjects($aggregateCount->item(0)); 00733 00734 $attributeAggregates[$xml->getURI($aggregateObjectObj->item(0))] = 00735 $xml->getContent($aggregateCountObj->item(0)); 00736 break; 00737 } 00738 } 00739 00740 // Get all the results 00741 $subjects = $xml->getSubjects(); 00742 00743 foreach ($subjects as $subject) 00744 { 00745 $subjectType = $xml->getType($subject); 00746 00747 if ($subjectType != "aggr:Aggregate") 00748 { 00749 // Increase the count for the current page. 00750 $pageCount++; 00751 00752 // Get and set the URI 00753 $subjectUri = $xml->getURI($subject); 00754 00755 $results[$subjectUri] = array(); 00756 00757 $results[$subjectUri]["type"] = array($subjectType); 00758 00759 $predicates = $xml->getPredicates($subject); 00760 00761 foreach ($predicates as $predicate) 00762 { 00763 $predicateType = $xml->getType($predicate, FALSE); 00764 00765 $datasetUri = ""; 00766 00767 if ($predicateType == "http://purl.org/dc/terms/isPartOf") 00768 { 00769 $objects = $xml->getObjects($predicate); 00770 $datasetUri = $xml->getURI($objects->item(0)); 00771 00772 if ($datasetUri != "") 00773 { 00774 $results[$subjectUri]["dataset"] = $datasetUri; 00775 00776 continue; 00777 } 00778 } 00779 00780 $objects = $xml->getObjects($predicate); 00781 00782 // Check if it is a reified statement 00783 $nodesList = $xml->getReificationStatements($objects->item(0)); 00784 00785 $objectText = ""; 00786 00787 if ($nodesList->length > 0) 00788 { 00789 $objectText = $xml->getValue($nodesList->item(0)); 00790 $objectUri = $xml->getURI($objects->item(0)); 00791 } 00792 else 00793 { 00794 $objectText = $xml->getContent($objects->item(0)); 00795 } 00796 00797 if (!isset($results[$subjectUri][$predicateType])) 00798 { 00799 $results[$subjectUri][$predicateType] = array(array( 00800 "text" => $objectText, 00801 "uri" => $objectUri 00802 )); 00803 } 00804 else 00805 { 00806 array_push($results[$subjectUri][$predicateType], array( 00807 "text" => $objectText, 00808 "uri" => $objectUri 00809 )); 00810 } 00811 } 00812 } 00813 } 00814 } 00815 else 00816 { 00817 $wsq->displayError(); 00818 } 00819 } 00820 } 00821 00822 // Get the number of results 00823 foreach ($datasetAggregates as $da) 00824 { 00825 $nbResources += $da; 00826 } 00827 00828 if ($nbResources > 0) 00829 { 00830 // Count the number of pages 00831 $nbPages = (ceil($nbResources / 10) > 10 ? 10 : ceil($nbResources / 10)); 00832 00833 $nbPagesTotal = ceil($nbResources / 10); 00834 00835 $currentPage = (($page + 10) / 10); 00836 $maxDisplayPages = 10; 00837 00838 $currentSlide = floor($page / 100) * 10; 00839 00840 // Display the "pages switcher" tool 00841 $html .= "<div class=\"pages\">\n"; 00842 00843 $html .= "<span style=\"padding-right:10px; font-size:medium;\">" . ($page + 1) . " - " 00844 . (($page + 10) > $nbResources ? $nbResources : ($page + 10)) . " of " 00845 . number_format($nbResources, 0, ',', ' ') . " $typeName " 00846 . ($filter == "" ? "" : "with a <strong>$filterLabel</strong> attribute") . "</span>\n"; 00847 $searchPagingHtml .= "<div style=\"position:relative; top:3px; float:right;\">\n"; 00848 00849 if ($currentPage == 1) 00850 { 00851 $searchPagingHtml .= "<span class=\"nextprev\">« Previous</span>\n"; 00852 } 00853 else 00854 { 00855 $searchPagingHtml .= "<a class=\"nextprev\" href=\"$base_url/conStruct/search/?page=" . ($page - 10) 00856 . "&filter=" . $filterStatus . "&query=" . urlencode($query) . $filterParameters 00857 . "\">« Previous</a>\n"; 00858 } 00859 00860 for ($i = (1 + $currentSlide); 00861 $i <= (($nbPages + $currentSlide) > $nbPagesTotal ? $nbPagesTotal : ($nbPages + $currentSlide)); $i++) 00862 { 00863 if ($currentPage == $i) 00864 { 00865 $searchPagingHtml .= "<span class=\"current\">$i</span>\n"; 00866 } 00867 else 00868 { 00869 $searchPagingHtml .= "<a href=\"$base_url/conStruct/search/?&filter=" . $filterStatus . "&page=" 00870 . (($i - 1) * 10) . "&query=" . urlencode($query) . $filterParameters . "\">$i</a>\n"; 00871 } 00872 } 00873 00874 if ($currentPage == $nbPagesTotal || $nbPagesTotal == 0) 00875 { 00876 $searchPagingHtml .= "<span class=\"nextprev\">Next »</span>\n"; 00877 } 00878 else 00879 { 00880 $searchPagingHtml .= "<a class=\"nextprev\" href=\"$base_url/conStruct/search/?&filter=" . $filterStatus 00881 . "&page=" . ($page + 10) . "&query=" . urlencode($query) . $filterParameters . "\">Next »</a>\n"; 00882 } 00883 00884 $searchPagingHtml .= "</div>\n"; 00885 00886 $html .= $searchPagingHtml; 00887 00888 $html .= "</div>\n"; 00889 } 00890 } 00891 00892 // Get the names and descriptions of the dataset available to this user. 00893 $wsfRegistry = variable_get("WSF-Registry", ""); 00894 00895 $datasetTitles = array(); 00896 00897 if ($wsfRegistry != "") 00898 { 00899 $includedWsfAddresses = array(); 00900 00901 $sidRegistry = variable_get("SID-Registry", ""); 00902 00903 foreach ($wsfRegistry as $wsfAddress) 00904 { 00905 $sid = ""; 00906 00907 // Make sure that we don't query the same server twice 00908 foreach ($sidRegistry as $s => $wsfs) 00909 { 00910 if (array_search($wsfAddress, $wsfs) !== FALSE) 00911 { 00912 $sid = $s; 00913 } 00914 } 00915 00916 if ($sid !== FALSE && array_search($sid, $includedWsfAddresses) === FALSE) 00917 { 00918 array_push($includedWsfAddresses, $sid); 00919 } 00920 else 00921 { 00922 continue; 00923 } 00924 00925 $wsq = new WebServiceQuerier($wsfAddress . "dataset/read/", "get", "text/xml", 00926 "uri=all®istered_ip=" . urlencode($userIP), 5); 00927 00928 if ($wsq->getStatus() == 200) 00929 { 00930 $xml = new ProcessorXML(); 00931 $xml->loadXML($wsq->getResultset()); 00932 00933 $datasets = $xml->getSubjectsByType("void:Dataset"); 00934 00935 foreach ($datasets as $d) 00936 { 00937 $datasetUri = $xml->getURI($d); 00938 00939 $predicates = $xml->getPredicatesByType($d, "dcterms:title"); 00940 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00941 $datasetTitle = $xml->getContent($objects->item(0)); 00942 00943 $datasetTitles[$datasetUri] = $datasetTitle; 00944 } 00945 } 00946 else 00947 { 00948 if ($wsq->getStatus() != 503 && $wsq->getStatus() != 404) 00949 { 00950 $wsq->displayError(); 00951 } 00952 } 00953 } 00954 } 00955 00956 // Fill the filtering by dataset tab. 00957 00958 $datasetTab = "<table style=\"border:0px none;\"><tbody style=\"border: none;\">"; 00959 00960 $tdCount = 0; 00961 00962 if(gettype($datasetAggregates) == "array") 00963 { 00964 arsort($datasetAggregates); 00965 } 00966 00967 if (count($datasetAggregates) < 1 && count($filterDatasets) < 1) 00968 { 00969 $datasetTab .= "<tr><td>No dataset filter can be applied for this search query</td></tr>"; 00970 } 00971 else 00972 { 00973 foreach ($datasetAggregates as $d => $count) 00974 { 00975 if (($tdCount % 3) == 0) 00976 { 00977 $datasetTab .= "</tr>"; 00978 $datasetTab .= "<tr>"; 00979 } 00980 00981 $datasetTab 00982 .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\"><tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\"><input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_datasets_" 00983 . $tdCount . "\" value='" . $d . "' " 00984 . (array_search(urlencode($d), $filterDatasets) !== FALSE ? "checked" : "") 00985 . "></td><td style=\"border:0px none;\">" . wordwrap($datasetTitles[$d], 28, "<br />") 00986 . "</td></tr></tbody></table></td>"; 00987 $tdCount++; 00988 } 00989 00990 // Make sure that we include all filter datasets selected by the user. 00991 foreach ($filterDatasets as $d) 00992 { 00993 $d = urldecode($d); 00994 00995 // Make sure we don't duplicate the filter. 00996 if (isset($datasetAggregates[$d])) 00997 { 00998 continue; 00999 } 01000 01001 if (($tdCount % 3) == 0) 01002 { 01003 $datasetTab .= "</tr>"; 01004 $datasetTab .= "<tr>"; 01005 } 01006 01007 $datasetTab 01008 .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\"><tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\"><input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_datasets_" 01009 . $tdCount . "\" value='" . $d . "' " 01010 . (array_search(urlencode($d), $filterDatasets) !== FALSE ? "checked" : "") 01011 . "></td><td style=\"border:0px none;\">" . wordwrap($datasetTitles[$d], 28, "<br />") 01012 . "</td></tr></tbody></table></td>"; 01013 01014 $tdCount++; 01015 } 01016 01017 for ($i = $tdCount; $i < 3; $i++) 01018 { 01019 $datasetTab .= "<td style=\"border:0px none;\"> </td>"; 01020 } 01021 01022 if ($tdCount != 3) 01023 { 01024 $datasetTab .= "</tr>"; 01025 } 01026 01027 $datasetTab .= "</tbody></table>"; 01028 01029 $datasetTab = str_replace("'", "\'", $datasetTab); 01030 } 01031 01032 // Populating the Type filtering tab 01033 $typeTab = "<table style=\"border:0px none;\"><tbody style=\"border: none;\">"; 01034 01035 $tdCount = 0; 01036 01037 if(gettype($typeAggregates) == "array") 01038 { 01039 arsort($typeAggregates); 01040 } 01041 01042 if (count($typeAggregates) < 1 && count($filterTypes) < 1) 01043 { 01044 $typeTab .= "<tr><td>No type filter can be applied for this search query</td></tr>"; 01045 } 01046 else 01047 { 01048 // Create and fill the filtering tabs that we have to put in the YUI tab control. 01049 foreach ($typeAggregates as $ctype => $count) 01050 { 01051 if (array_search($ctype, $filterKindsIgnore) !== FALSE) 01052 { 01053 continue; 01054 } 01055 01056 $className = ""; 01057 $className = $classHierarchy->classes[$ctype]->label; 01058 01059 if ($ctype == "http://www.w3.org/2002/07/owl#Thing") 01060 { 01061 continue; 01062 } 01063 01064 if (($tdCount % 3) == 0) 01065 { 01066 $typeTab .= "</tr>"; 01067 $typeTab .= "<tr>"; 01068 } 01069 01070 if ($className == "") 01071 { 01072 $className = get_uri_label($ctype); 01073 } 01074 01075 $typeTab 01076 .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\"><tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\"><input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_types_" 01077 . $tdCount . "\" value='" . $ctype . "' " 01078 . (array_search(urlencode($ctype), $filterTypes) !== FALSE ? "checked" : "") . "></td>" 01079 . (module_exists("structOntology") 01080 ? "<td style=\"border: 0px none ; width: 1px;\"><a href=\"" . $base_url . "/conStruct/ontology/view/?uri=" 01081 . urlencode($ctype) . "\"><img style=\"top: 2px; position:relative;\" src=\"" . base_path() 01082 . drupal_get_path("module", "structSearch") . "/imgs/application_link.png\" /></a></td>" : "") 01083 . "<td style=\"border:0px none;\">" . wordwrap($className, 28, "<br />") . "</td>" . 01084 "</tr></tbody></table></td>"; 01085 01086 $tdCount++; 01087 } 01088 01089 // Make sure that we include all filter types selected by the user. 01090 foreach ($filterTypes as $ctype) 01091 { 01092 $ctype = urldecode($ctype); 01093 01094 // Make sure we don't duplicate the filter. 01095 if (isset($typeAggregates[$ctype])) 01096 { 01097 continue; 01098 } 01099 01100 $className = ""; 01101 $className = $classHierarchy->classes[$ctype]->label; 01102 01103 if ($ctype == "http://www.w3.org/2002/07/owl#Thing") 01104 { 01105 continue; 01106 } 01107 01108 if (($tdCount % 3) == 0) 01109 { 01110 $typeTab .= "</tr>"; 01111 $typeTab .= "<tr>"; 01112 } 01113 01114 if ($className == "") 01115 { 01116 $className = get_uri_label($ctype); 01117 } 01118 01119 $typeTab 01120 .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\"><tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\"><input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_types_" 01121 . $tdCount . "\" value='" . $ctype . "' " 01122 . (array_search(urlencode($ctype), $filterTypes) !== FALSE ? "checked" : "") . "></td>" 01123 . (module_exists("structOntology") 01124 ? "<td style=\"border: 0px none ; width: 1px;\"><a href=\"" . $base_url . "/conStruct/ontology/view/?uri=" 01125 . urlencode($ctype) . "\"><img style=\"top: 2px; position:relative;\" src=\"" . base_path() 01126 . drupal_get_path("module", "structSearch") . "/imgs/application_link.png\" /></a></td>" : "") 01127 . "<td style=\"border:0px none;\">" . wordwrap($className, 28, "<br />") . "</td>" . 01128 "</tr></tbody></table></td>"; 01129 01130 $tdCount++; 01131 } 01132 01133 for ($i = $tdCount; $i < 3; $i++) 01134 { 01135 $typeTab .= "<td style=\"border:0px none;\"> </td>"; 01136 } 01137 01138 if ($tdCount != 3) 01139 { 01140 $typeTab .= "</tr>"; 01141 } 01142 } 01143 01144 $typeTab .= "</tbody></table>"; 01145 01146 $typeTab = str_replace("'", "\'", $typeTab); 01147 01148 $attributeTab = "<table style=\"border:0px none;\"><tbody style=\"border: none;\">"; 01149 01150 $tdCount = 0; 01151 01152 if(gettype($attributeAggregates) == "array") 01153 { 01154 arsort($attributeAggregates); 01155 } 01156 01157 if (count($attributeAggregates) < 1 && count($filterAttributes) < 1) 01158 { 01159 $attributeTab .= "<tr><td>No attribute filter can be applied for this search query</td></tr>"; 01160 } 01161 else 01162 { 01163 foreach ($attributeAggregates as $property => $count) 01164 { 01165 if (array_search($property, $filterAttributesIgnore) !== FALSE) 01166 { 01167 continue; 01168 } 01169 01170 if (($tdCount % 3) == 0) 01171 { 01172 $attributeTab .= "</tr>"; 01173 $attributeTab .= "<tr>"; 01174 } 01175 01176 $attributeTab .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\">" . 01177 "<tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\">" . 01178 "<input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_attributes_" . $tdCount . "\" value='" 01179 . $property . "' " 01180 . (array_search(urlencode(urlencode($property)), $filterAttributes) !== FALSE ? "checked" : "") . "></td>" 01181 . (module_exists("structOntology") 01182 ? "<td style=\"border: 0px none ; width: 1px;\"><a href=\"" . $base_url . "/conStruct/ontology/view/?uri=" 01183 . urlencode($property) . "\"><img style=\"top: 2px; position:relative;\" src=\"" . base_path() 01184 . drupal_get_path("module", "structSearch") . "/imgs/application_link.png\" /></a></td>" : "") . 01185 "<td style=\"border:0px none; width: 100%;\">" . wordwrap(($propertyHierarchy->properties[$property]->label 01186 == "" ? get_uri_label($property) : $propertyHierarchy->properties[$property]->label), 28, "<br />") 01187 . "</td>" . 01188 "</tr></tbody></table></td>"; 01189 01190 $tdCount++; 01191 } 01192 01193 // Make sure that we include all filter attributes selected by the user. 01194 foreach ($filterAttributes as $property) 01195 { 01196 $property = urldecode(urldecode($property)); 01197 01198 // Make sure we don't duplicate the filter. 01199 if (isset($attributeAggregates[$property])) 01200 { 01201 continue; 01202 } 01203 01204 if (($tdCount % 3) == 0) 01205 { 01206 $attributeTab .= "</tr>"; 01207 $attributeTab .= "<tr>"; 01208 } 01209 01210 $attributeTab .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\">" . 01211 "<tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\">" . 01212 "<input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_attributes_" . $tdCount . "\" value='" 01213 . $property . "' " 01214 . (array_search(urlencode(urlencode($property)), $filterAttributes) !== FALSE ? "checked" : "") . "></td>" 01215 . (module_exists("structOntology") 01216 ? "<td style=\"border: 0px none ; width: 1px;\"><a href=\"" . $base_url . "/conStruct/ontology/view/?uri=" 01217 . urlencode($property) . "\"><img style=\"top: 2px; position:relative;\" src=\"" . base_path() 01218 . drupal_get_path("module", "structSearch") . "/imgs/application_link.png\" /></a></td>" : "") . 01219 "<td style=\"border:0px none; width: 100%;\">" . wordwrap(($propertyHierarchy->properties[$property]->label 01220 == "" ? get_uri_label($property) : $propertyHierarchy->properties[$property]->label), 28, "<br />") 01221 . "</td>" . 01222 "</tr></tbody></table></td>"; 01223 01224 $tdCount++; 01225 } 01226 01227 for ($i = $tdCount; $i < 3; $i++) 01228 { 01229 $attributeTab .= "<td style=\"border:0px none;\"> </td>"; 01230 } 01231 01232 if ($tdCount != 3) 01233 { 01234 $attributeTab .= "</tr>"; 01235 } 01236 } 01237 01238 $attributeTab .= "</tbody></table>"; 01239 01240 $attributeTab = str_replace("'", "\'", $attributeTab); 01241 01242 01243 // Populating the Export tab 01244 $exportTab = "<table style=\"border:0px none;\"><tbody style=\"border: none;\">"; 01245 01246 $pos = strpos($_SERVER["REQUEST_URI"], "?"); 01247 01248 $exportTab .= "<tr><td><img style=\"top: 4px; position:relative;\" src=\"" . base_path() 01249 . drupal_get_path("module", "structSearch") . "/imgs/bullet_blue.png\" /><a target=\"_blank\" href=\"?" 01250 . substr($_SERVER["REQUEST_URI"], $pos + 1, strlen($_SERVER["REQUEST_URI"])) . "&mime=" 01251 . urlencode("application/iron+json") . "\">irJSON</a></td></tr>"; 01252 $exportTab .= "<tr><td><img style=\"top: 4px; position:relative;\" src=\"" . base_path() 01253 . drupal_get_path("module", "structSearch") . "/imgs/bullet_blue.png\" /><a target=\"_blank\" href=\"?" 01254 . substr($_SERVER["REQUEST_URI"], $pos + 1, strlen($_SERVER["REQUEST_URI"])) . "&mime=" 01255 . urlencode("application/json") . "\">JSON</a></td></tr>"; 01256 $exportTab .= "<tr><td><img style=\"top: 4px; position:relative;\" src=\"" . base_path() 01257 . drupal_get_path("module", "structSearch") . "/imgs/bullet_blue.png\" /><a target=\"_blank\" href=\"?" 01258 . substr($_SERVER["REQUEST_URI"], $pos + 1, strlen($_SERVER["REQUEST_URI"])) . "&mime=" . urlencode("text/xml") 01259 . "\">XML</a></td></tr>"; 01260 $exportTab .= "<tr><td><img style=\"top: 4px; position:relative;\" src=\"" . base_path() 01261 . drupal_get_path("module", "structSearch") . "/imgs/bullet_blue.png\" /><a target=\"_blank\" href=\"?" 01262 . substr($_SERVER["REQUEST_URI"], $pos + 1, strlen($_SERVER["REQUEST_URI"])) . "&mime=" 01263 . urlencode("application/rdf+xml") . "\">RDF+XML</a></td></tr>"; 01264 $exportTab .= "<tr><td><img style=\"top: 4px; position:relative;\" src=\"" . base_path() 01265 . drupal_get_path("module", "structSearch") . "/imgs/bullet_blue.png\" /><a target=\"_blank\" href=\"?" 01266 . substr($_SERVER["REQUEST_URI"], $pos + 1, strlen($_SERVER["REQUEST_URI"])) . "&mime=" 01267 . urlencode("application/rdf+n3") . "\">RDF+N3</a></td></tr>"; 01268 01269 $exportTab .= "</tbody></table>"; 01270 01271 // Inject JS scripts for the auto-copletion tool in the HTML page's header 01272 drupal_set_html_head("<style type=\"text/css\"> 01273 /*margin and padding on body element 01274 can introduce errors in determining 01275 element position and are not recommended; 01276 we turn them off as a foundation for YUI 01277 CSS treatments. */ 01278 body { 01279 margin:0; 01280 padding:0; 01281 } 01282 </style> 01283 01284 <script type=\"text/javascript\"> 01285 function setFilterOn() 01286 { 01287 if(document.getElementById) 01288 { 01289 document.getElementById('radioFilterOff').checked = false; 01290 document.getElementById('radioFilterOn').checked = true; 01291 } 01292 } 01293 </script> 01294 01295 <link rel=\"stylesheet\" type=\"text/css\" href=\"" . base_path() . drupal_get_path("module", "conStruct") . "/js/yui/build/fonts/fonts-min.css\" /> 01296 <link rel=\"stylesheet\" type=\"text/css\" href=\"" . base_path() . drupal_get_path("module", "conStruct") . "/js/yui/build/tabview/assets/skins/sam/tabview.css\" /> 01297 01298 <script type=\"text/javascript\" src=\"" . base_path() . drupal_get_path("module", "conStruct") . "/js/yui/build/yahoo-dom-event/yahoo-dom-event.js\"></script> 01299 01300 <script type=\"text/javascript\" src=\"" . base_path() . drupal_get_path("module", "conStruct") . "/js/yui/build/element/element-min.js\"></script> 01301 <script type=\"text/javascript\" src=\"" . base_path() . drupal_get_path("module", "conStruct") 01302 . "/js/yui/build/tabview/tabview-min.js\"></script>"); 01303 01304 if (isset($_GET['query']) && $nbResources > 0) 01305 { 01306 $html .= "<div class=\"yui-skin-sam\" style=\"width:100%;\"> 01307 <form id=\"filterForm\" action=\"" . $baseLinksUrl . "\"> 01308 01309 <div class=\"yui-skin-sam\" style=\"width:100%;border-color:#2647A0; border-bottom-width: 5px; padding-top: 5px; padding-bottom: 5px\"> 01310 <div id=\"filtering_tabs_search\"></div> 01311 </div> 01312 01313 <table border=\"0\" style=\"width:100%\"> 01314 <tr> 01315 <td>Search for:</td> 01316 <td style=\"width:50px\"> 01317 <input name=\"query\" id=\"search_keyword\" type=\"text\" value='" 01318 . $_GET['query'] . "' size=\"50px\" /> 01319 </td> 01320 <td> 01321 <input type=\"radio\" id=\"radioFilterOff\" name=\"filter\" value=\"off\" " 01322 . ($filterStatus == "off" ? "checked" : "") . "> All 01323 <input type=\"radio\" id=\"radioFilterOn\" name=\"filter\" value=\"on\" " 01324 . ($filterStatus == "on" ? "checked" : "") 01325 . "> Filter(s) 01326 </td> 01327 <td> 01328 <input id=\"filterSubmit\" type=\"submit\" value=\"Search\" style=\"position:static;\"> 01329 </td> 01330 </tr> 01331 </table> 01332 </form> 01333 </div>"; 01334 01335 // Display the information relative to the resources. 01336 $nb = 1; 01337 01338 $firstAlreadyIncluded = ""; 01339 01340 global $base_url; 01341 01342 // Check if it is a phrase search 01343 $isPhraseSearch = FALSE; 01344 01345 if (substr($query, 0, 1) == '"' && substr($query, strlen($query) - 1, 1) == '"') 01346 { 01347 $isPhraseSearch = TRUE; 01348 } 01349 01350 foreach ($results as $uri => $result) 01351 { 01352 $resourceLabel = getResourceLabel($result, "<em>Untitled Record</em>"); 01353 01354 // Check if we can enable Scones edition for this resultset. 01355 $enableSconesEdit = FALSE; 01356 if(module_exists("structScones")) 01357 { 01358 // Now check if this item can be edit by Scones. 01359 01360 // Check if the property sco:storyTextUri exists 01361 // Check if the property iron:prefLabel exists 01362 if(is_array($result["http://purl.org/ontology/iron#prefLabel"]) && 01363 is_array($result["http://purl.org/ontology/sco#storyTextUri"])) 01364 { 01365 $enableSconesEdit = TRUE; 01366 } 01367 } 01368 01369 $html .= "<div style=\"padding-top:25px;\" />". 01370 (!user_access('administer conStruct') ? "" : 01371 " 01372 <span class=\"item-admin-toolbox\"> 01373 01374 ".(!$enableSconesEdit ? "" : " 01375 <a href=\"" . $base_url . "/conStruct/scones/?targetUri=".urlencode($uri)."&targetDataset=". 01376 urlencode($result["dataset"]) 01377 . "\" alt=\"Update document using Scones\" title=\"Update document using Scones\">" . 01378 01379 "<img src=\"" . base_path() . drupal_get_path("module", "structSearch") 01380 . "/imgs/tag_blue.png\" border=\"0\" " . 01381 "style=\"padding-right:5px;\" /> 01382 </a>")." 01383 01384 01385 <a href=\"" . $base_url . "/conStruct/update/?uri=" . urlencode($uri) 01386 . "&dataset=" . urlencode($result["dataset"]) . "\" alt=\"Update item\" title=\"Update item\">" . 01387 "<img src=\"" . base_path() . drupal_get_path("module", "structSearch") . 01388 "/imgs/overlays.png\" border=\"0\" " 01389 ."style=\"padding-right:5px;\" /> 01390 </a> 01391 01392 <a href=\"" . $base_url . "/conStruct/delete/?uri=" . urlencode($uri) . 01393 "&dataset=" . urlencode($result["dataset"]) . "\" 01394 alt=\"Delete item\" title=\"Delete item\"> 01395 <img src=\"". base_path() . drupal_get_path("module", "structSearch") . 01396 "/imgs/cancel.png\" border=\"0\" style=\"\" /> 01397 </a> 01398 01399 </span>") 01400 ."<div style=\"border-bottom: 1px solid #666666\"<strong>" 01401 . ($nb + $page) . ". " . 01402 "<a style=\"padding-left:3px; text-decoration: none;\" href=\"" . $base_url . "/conStruct/view/?uri=" 01403 . urlencode($uri) . "&dataset=" . urlencode($result["dataset"]) . "\">" . $resourceLabel 01404 . "</a> </strong></div></div>\n"; 01405 01406 $nb++; 01407 01408 foreach ($result as $property => $values) 01409 { 01410 if (is_array($values) === FALSE) 01411 { 01412 $values = array($values); 01413 } 01414 01415 foreach ($values as $value) 01416 { 01417 $keywordFound = FALSE; 01418 01419 if ($isPhraseSearch === FALSE) 01420 { 01421 $keywords = explode(" ", preg_replace("/[^a-zA-Z0-9\s]/", "", $query)); 01422 01423 foreach ($keywords as $keyword) 01424 { 01425 if (stripos($value["text"], $keyword) !== FALSE) 01426 { 01427 $keywordFound = TRUE; 01428 } 01429 } 01430 } 01431 else 01432 { 01433 $keywordFound = stripos($value["text"], substr($query, 1, strlen($query) - 2)); 01434 } 01435 01436 if ($property != "type" && $property != "dataset" && $keywordFound !== FALSE) 01437 { 01438 if (!isset($propertyHierarchy->properties[$property]) 01439 || strlen($propertyLabel = $propertyHierarchy->properties[$property]->label) < 1) 01440 { 01441 $pos = strripos($property, "#"); 01442 01443 if ($pos === FALSE) 01444 { 01445 $pos = strripos($property, "/"); 01446 } 01447 01448 if ($pos !== FALSE) 01449 { 01450 $pos++; 01451 } 01452 01453 $propertyLabel = substr($property, $pos, strlen($property) - $pos); 01454 } 01455 else 01456 { 01457 $propertyLabel = $propertyHierarchy->properties[$property]->label; 01458 } 01459 01460 $value["text"] = strip_tags($value["text"]); 01461 01462 if ($isPhraseSearch) 01463 { 01464 $value["text"] = str_ireplace(substr($query, 1, strlen($query) - 2), 01465 "<span style=\"background-color: #5CB3FF; padding-right: 3px; padding-left: 3px;\"><strong>" 01466 . substr($query, 1, strlen($query) - 2) . "</strong></span>", $value["text"]); 01467 } 01468 else 01469 { 01470 $keywords = explode(" ", preg_replace("/[^a-zA-Z0-9\s]/", "", $query)); 01471 01472 foreach ($keywords as $keyword) 01473 { 01474 $value["text"] = str_ireplace($keyword, 01475 "<span style=\"padding-right: 3px; padding-left: 3px; text-decoration: none; border-bottom: dotted 1px #cc0000; \"><strong>$keyword</strong></span>", 01476 $value["text"]); 01477 } 01478 } 01479 01480 if ($filterStatus == "off" || array_search(urlencode(urlencode($property)), $filterAttributes) !== FALSE) 01481 { 01482 $html .= "<div>" . 01483 "<img src=\"" . base_path() . drupal_get_path("module", "structSearch") 01484 . "/imgs/magnifier.png\" border=\"0\" " . 01485 "style=\"padding-right:5px; position:relative; top:3px\" /><span style=\"padding-left:0px;\"><strong>Found in <em><b>$propertyLabel</b>" 01486 . 01487 "</em>:</strong> <span style=\"font-size:14px\">" . $value["text"] . "</span></span></div>"; 01488 } 01489 } 01490 } 01491 } 01492 01493 // Aggregate some information to preview this record 01494 $display = ""; 01495 01496 include("display.php"); 01497 01498 if ($preview != "") 01499 { 01500 $html .= "<div style=\"padding-top: 10px; padding-bottom: 10px;\">" . $preview . 01501 "</div>"; 01502 } 01503 01504 $html .= "<div style=\"font-weight: bold; color: rgb(109, 151, 10);\"><em>Source: <a href=\"" . $baseLinksUrl 01505 . "?query=" . urlencode($query) . "&filter_datasets_1=" . urlencode($result["dataset"]) . 01506 "&page=" . $page . "\">" . $datasetTitles[$result["dataset"]] . "</a>" 01507 . ($addFromSkin != "" ? $addFromSkin : "") . "</em></div>\n"; 01508 } 01509 01510 if (count($results) > 0) 01511 { 01512 $html .= "<div class=\"pages\">\n"; 01513 $html .= $searchPagingHtml; 01514 $html .= "</div>\n"; 01515 } 01516 } 01517 else 01518 { 01519 $html .= "<div class=\"yui-skin-sam\" style=\"width:100%;\"> 01520 <form id=\"filterForm\" action=\"" . $baseLinksUrl . "\"> 01521 01522 <div class=\"yui-skin-sam\" style=\"width:100%;border-color:#2647A0; border-bottom-width: 5px; padding-top: 5px; padding-bottom: 5px\"> 01523 <div id=\"filtering_tabs_search\"></div> 01524 </div> 01525 01526 <table border=\"0\" style=\"width:100%\"> 01527 <tr> 01528 <td>Search for:</td> 01529 <td style=\"width:50px\"> 01530 <input name=\"query\" id=\"search_keyword\" type=\"text\" value=\"" 01531 . $_GET['query'] . "\" size=\"50px\" /> 01532 </td> 01533 <td> 01534 <input type=\"radio\" id=\"radioFilterOff\" name=\"filter\" value=\"off\" " 01535 . ($filterStatus == "off" ? "checked" : "") . "> All 01536 <input type=\"radio\" id=\"radioFilterOn\" name=\"filter\" value=\"on\" " 01537 . ($filterStatus == "on" ? "checked" : "") 01538 . "> Filter(s) 01539 </td> 01540 <td> 01541 <input id=\"filterSubmit\" type=\"submit\" value=\"Search\" style=\"position:static;\"> 01542 </td> 01543 </tr> 01544 </table> 01545 </form> 01546 </div>"; 01547 01548 if ($nbResources <= 0 && isset($_GET['query'])) 01549 { 01550 $html .= "No result found"; 01551 } 01552 } 01553 01554 // If no query is defined for this search tool page load, we get the aggregate counts from the browser service. 01555 // This is used to initiate the filtering tabs. 01556 if ($nbResources <= 0 && !isset($_GET['query'])) 01557 { 01558 global $user; 01559 01560 $userIP = variable_get("conStruct_AccessUser" . $user->uid, ""); 01561 01562 if ($userIP == "") 01563 { 01564 // If there is no IP for that user, we overload the IP of the node with "::" 01565 $userIP = "self::$user->uid"; 01566 } 01567 01568 $wsfRegistry = variable_get("WSF-Registry", ""); 01569 01570 if ($wsfRegistry != "") 01571 { 01572 $includedWsfAddresses = array(); 01573 01574 $sidRegistry = variable_get("SID-Registry", ""); 01575 01576 // Count the number of items displayed in the page so far 01577 $pageCount = $page; 01578 01579 $wsfPageStartingPoint = 0; 01580 01581 foreach ($wsfRegistry as $wsfAddress) 01582 { 01583 $sid = ""; 01584 01585 // Make sure that we don't query the same server twice 01586 foreach ($sidRegistry as $s => $wsfs) 01587 { 01588 if (array_search($wsfAddress, $wsfs) !== FALSE) 01589 { 01590 $sid = $s; 01591 } 01592 } 01593 01594 if ($sid !== FALSE && array_search($sid, $includedWsfAddresses) === FALSE) 01595 { 01596 array_push($includedWsfAddresses, $sid); 01597 } 01598 else 01599 { 01600 continue; 01601 } 01602 01603 // Now, lets create the union of all datasets created/linked for that node. We will only query them (even if 01604 // world readable (public) ones can be accessible from a target WSF) 01605 $targetDatasets = ""; 01606 01607 $resultset = db_query('SELECT nid FROM {og}'); 01608 01609 $linkedDatasets = variable_get("Linked-Dataset-Registry", ""); 01610 01611 while ($datasetId = db_result($resultset)) 01612 { 01613 $datasetWsf = variable_get("Dataset-" . $datasetId . "-WSF", ""); 01614 01615 if ($datasetWsf == $wsfAddress) 01616 { 01617 // If this dataset come from this WSF Address, then we include it into the dataset to search for. 01618 01619 // Check if it is a linked dataset 01620 if (isset($linkedDatasets[$datasetId])) 01621 { 01622 $targetDatasets .= $linkedDatasets[$datasetId] . ";"; 01623 } 01624 else 01625 { 01627 $datasetsRegistry = variable_get("Datasets-Registry", ""); 01628 01629 if ($datasetsRegistry != "" && isset($datasetsRegistry[$datasetId])) 01630 { 01631 $targetDatasets .= $datasetsRegistry[$datasetId] . ";"; 01632 } 01633 else 01634 { 01635 global $base_url; 01636 01637 $targetDatasets .= get_domain($base_url) . "/wsf/datasets/" . $datasetId . "/;"; 01638 } 01639 } 01640 } 01641 } 01642 01643 $targetDatasets = substr($targetDatasets, 0, strlen($targetDatasets) - 1); 01644 01645 if($targetDatasets != "" && $showFilters === TRUE) 01646 { 01647 // Get aggregates 01648 $wsq = new WebServiceQuerier($wsfAddress . "browse/", "post", "text/xml", 01649 "attributes=all&types=all&datasets=" . urlencode($targetDatasets) . "&items=0&inference=on&" . 01650 "include_aggregates=true®istered_ip=" . urlencode($userIP), 5); 01651 01652 // Extract aggregates from the web service endpoint resultset 01653 $xml = new ProcessorXML(); 01654 $xml->loadXML($wsq->getResultset()); 01655 01656 $aggregates = $xml->getSubjectsByType("http://purl.org/ontology/aggregate#Aggregate"); 01657 01658 foreach ($aggregates as $aggregate) 01659 { 01660 $aggregetionType = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#property"); 01661 $aggregetionTypeObj = $xml->getObjects($aggregetionType->item(0)); 01662 01663 switch ($xml->getURI($aggregetionTypeObj->item(0))) 01664 { 01665 case "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": 01666 $aggregateObject = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#object"); 01667 $aggregateObjectObj = $xml->getObjects($aggregateObject->item(0)); 01668 01669 $aggregateCount = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#count"); 01670 $aggregateCountObj = $xml->getObjects($aggregateCount->item(0)); 01671 if (!isset($typeAggregates[$xml->getURI($aggregateObjectObj->item(0))])) 01672 { 01673 $typeAggregates[$xml->getURI($aggregateObjectObj->item(0))] = $xml->getContent( 01674 $aggregateCountObj->item(0)); 01675 } 01676 else 01677 { 01678 $typeAggregates[$xml->getURI($aggregateObjectObj->item(0))] += $xml->getContent( 01679 $aggregateCountObj->item(0)); 01680 } 01681 break; 01682 01683 case "http://rdfs.org/ns/void#Dataset": 01684 $aggregateObject = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#object"); 01685 $aggregateObjectObj = $xml->getObjects($aggregateObject->item(0)); 01686 01687 $aggregateCount = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#count"); 01688 $aggregateCountObj = $xml->getObjects($aggregateCount->item(0)); 01689 if (!isset($datasetAggregates[$xml->getURI($aggregateObjectObj->item(0))])) 01690 { 01691 $datasetAggregates[$xml->getURI($aggregateObjectObj->item(0))] = $xml->getContent( 01692 $aggregateCountObj->item(0)); 01693 } 01694 break; 01695 01696 case "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property": 01697 $aggregateObject = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#object"); 01698 $aggregateObjectObj = $xml->getObjects($aggregateObject->item(0)); 01699 01700 $aggregateCount = $xml->getPredicatesByType($aggregate, "http://purl.org/ontology/aggregate#count"); 01701 $aggregateCountObj = $xml->getObjects($aggregateCount->item(0)); 01702 01703 $attributeAggregates[$xml->getURI($aggregateObjectObj->item(0))] = 01704 $xml->getContent($aggregateCountObj->item(0)); 01705 break; 01706 } 01707 } 01708 01709 // Populate the filtering tabs 01710 $tdCount = 0; 01711 01712 $datasetTab = "<table style=\"border:0px none;\"><tbody style=\"border: none;\">"; 01713 01714 arsort($datasetAggregates); 01715 01716 foreach ($datasetAggregates as $d => $count) 01717 { 01718 if (($tdCount % 3) == 0) 01719 { 01720 $datasetTab .= "</tr>"; 01721 $datasetTab .= "<tr>"; 01722 } 01723 01724 $datasetTab .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\">" . 01725 "<tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\">" . 01726 "<input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_datasets_" . $tdCount . "\" value='" . $d 01727 . "'></td>" . 01728 "<td style=\"border:0px none;\">" . wordwrap($datasetTitles[$d], 28, "<br />") . "<br /><em>(" 01729 . number_format($count, 0, "", " ") . ")</em></td></tr></tbody></table></td>"; 01730 $tdCount++; 01731 } 01732 01733 for ($i = $tdCount; $i < 3; $i++) 01734 { 01735 $datasetTab .= "<td style=\"border:0px none;\"> </td>"; 01736 } 01737 01738 if ($tdCount != 3) 01739 { 01740 $datasetTab .= "</tr>"; 01741 } 01742 01743 $datasetTab .= "</tbody></table>"; 01744 01745 $datasetTab = str_replace("'", "\'", $datasetTab); 01746 01747 // Populating the Type filtering tab 01748 01749 arsort($typeAggregates); 01750 01751 $classHierarchyLayout = new ClassHierarchy("http://www.w3.org/2002/07/owl#Thing"); 01752 01753 $typeCounts = array(); 01754 01755 foreach ($typeAggregates as $ctype => $count) 01756 { 01757 $className = ""; 01758 $className = $classHierarchy->classes[$ctype]->label; 01759 01760 if ($ctype == "http://www.w3.org/2002/07/owl#Thing") 01761 { 01762 continue; 01763 } 01764 01765 if ($className == "") 01766 { 01767 $className = get_uri_label($ctype); 01768 } 01769 01770 $typeCounts[$ctype] = $count; 01771 01772 if (isset($classHierarchy->classes[$ctype])) 01773 { 01774 foreach ($classHierarchy->classes[$ctype]->subClassOf as $sc) 01775 { 01776 if ((count($classHierarchy->classes[$ctype]->subClassOf) > 1 01777 && $sc->name != "http://www.w3.org/2002/07/owl#Thing") 01778 || count($classHierarchy->classes[$ctype]->subClassOf) == 1) 01779 { 01780 $classHierarchyLayout->addClassRelationship($ctype, $sc->name); 01781 } 01782 } 01783 } 01784 else 01785 { 01786 $classHierarchyLayout->addClassRelationship($type, "http://www.w3.org/2002/07/owl#Thing"); 01787 } 01788 } 01789 01790 // Copy node information from the original hierarchy 01791 foreach ($classHierarchyLayout->classes as $chl) 01792 { 01793 $chl->label = $classHierarchy->classes[$chl->name]->label; 01794 $chl->description = $classHierarchy->classes[$chl->name]->description; 01795 } 01796 01797 $typeTab = 01798 generateClassHierarchyHtmlTreeSearch($classHierarchyLayout, $typeCounts, $dataset, $attribute, $type, "0", 01799 $filterKindsIgnore); 01800 01801 $typeTab = str_replace(array( 01802 "'", 01803 "\n", 01804 "\r" 01805 ), array( 01806 "\'", 01807 "", 01808 "" 01809 ), $typeTab); 01810 01811 $attributeTab = "<table style=\"border:0px none;\"><tbody style=\"border: none;\">"; 01812 01813 $tdCount = 0; 01814 01815 if(gettype($attributeAggregates) == "array") 01816 { 01817 arsort($attributeAggregates); 01818 } 01819 01820 foreach ($attributeAggregates as $property => $count) 01821 { 01822 if (array_search($property, $filterAttributesIgnore) !== FALSE) 01823 { 01824 continue; 01825 } 01826 01827 if (($tdCount % 3) == 0) 01828 { 01829 $attributeTab .= "</tr>"; 01830 $attributeTab .= "<tr>"; 01831 } 01832 01833 $attributeTab .= "<td style=\"border:0px none;\"><table style=\"border:0px none; padding: 0px; margin:0px;\">" 01834 . 01835 "<tbody style=\"border: none;\"><tr><td style=\"border:0px none; width:1px;\">" . 01836 "<input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_attributes_" . $tdCount . "\" value='" 01837 . $property . "'></td>" . (module_exists("structOntology") 01838 ? "<td style=\"border: 0px none ; width: 1px;\"><a title=\"Attribute description\" href=\"" . $base_url . "/conStruct/ontology/view/?uri=" 01839 . urlencode($property) . "\"><img style=\"top: 2px; position:relative;\" src=\"" . base_path() 01840 . drupal_get_path("module", "structSearch") . "/imgs/application_link.png\" /></a></td>" : "") . 01841 "<td style=\"border:0px none; width: 100%;\">" . wordwrap(($propertyHierarchy->properties[$property]->label 01842 == "" ? get_uri_label($property) : $propertyHierarchy->properties[$property]->label), 28, "<br />") 01843 . "</td>" . 01844 "</tr></tbody></table></td>"; 01845 01846 $tdCount++; 01847 } 01848 01849 for ($i = $tdCount; $i < 3; $i++) 01850 { 01851 $attributeTab .= "<td style=\"border:0px none;\"> </td>"; 01852 } 01853 01854 if ($tdCount != 3) 01855 { 01856 $attributeTab .= "</tr>"; 01857 } 01858 01859 $attributeTab .= "</tbody></table>"; 01860 01861 $attributeTab = str_replace("'", "\'", $attributeTab); 01862 } 01863 } 01864 } 01865 01866 01867 } 01868 01869 // Runs the filtering tabs display tool 01870 if($showFilters) 01871 { 01872 $html 01873 .= "<script type=\"text/javascript\"> 01874 (function() { 01875 var tabView = new YAHOO.widget.TabView(); 01876 01877 tabView.addTab( new YAHOO.widget.Tab({ 01878 label: 'Filter by Dataset', 01879 content: '$datasetTab', 01880 active: true 01881 })); 01882 01883 tabView.addTab( new YAHOO.widget.Tab({ 01884 label: 'Filter by Kind', 01885 content: '$typeTab' 01886 01887 })); 01888 01889 tabView.addTab( new YAHOO.widget.Tab({ 01890 label: 'Filter by Attribute', 01891 content: '$attributeTab' 01892 01893 }));"; 01894 01895 if ($nbResources > 0) 01896 { 01897 01898 $html .= " tabView.addTab( new YAHOO.widget.Tab({ 01899 label: 'Export', 01900 content: '$exportTab' 01901 01902 }));"; 01903 } 01904 01905 $html .= " tabView.appendTo('filtering_tabs_search'); 01906 })(); 01907 </script>"; 01908 } 01909 01910 return ($html); 01911 } 01912 } 01913 01914 01929 function generateClassHierarchyHtmlTreeSearch($classHierarchy, $counts, $dataset, $attribute, $type, $page, $ignores) 01930 { 01931 $html = "<ul>\n"; 01932 01933 if (array_search("http://www.w3.org/2002/07/owl#Thing", $ignores) === FALSE) 01934 { 01935 $html .= " <li>Thing\n"; 01936 $html .= " <ul>\n"; 01937 } 01938 01939 $html .= generateClassHierarchyHtmlTreeSearchRecur($classHierarchy->classes["http://www.w3.org/2002/07/owl#Thing"], 01940 $counts, $dataset, $attribute, $type, $page, $ignores, 0); 01941 01942 if (array_search("http://www.w3.org/2002/07/owl#Thing", $ignores) === FALSE) 01943 { 01944 $html .= " </ul>\n"; 01945 $html .= " </li>\n"; 01946 } 01947 01948 $html .= "</ul>\n"; 01949 01950 return $html; 01951 } 01952 01968 function generateClassHierarchyHtmlTreeSearchRecur($class, $counts, $dataset, $attribute, $type, $page, $ignores, $nb) 01969 { 01970 global $base_url; 01971 $html = ""; 01972 01973 foreach ($class->superClassOf as $sc) 01974 { 01975 if ($sc->name == "all") 01976 { 01977 continue; 01978 } 01979 01980 if (array_search($sc->name, $ignores) === FALSE) 01981 { 01982 $nb++; 01983 $html .= " <li><input onClick=\"setFilterOn()\" type=\"checkbox\" name=\"filter_types_" . $nb 01984 . "\" value='" . $sc->name . "'>" . ($sc->label == "" ? get_uri_label($sc->name) : $sc->label) 01985 . (module_exists("structOntology") 01986 ? " <a href=\"" . $base_url . "/conStruct/ontology/view/?uri=" . urlencode($sc->name) 01987 . "\"><img style=\"top: 4px; position:relative;\" src=\"" . base_path() 01988 . drupal_get_path("module", "structBrowse") . "/imgs/application_link.png\" /></a>" : "") . "\n"; 01989 } 01990 01991 if (count($sc->superClassOf) > 0) 01992 { 01993 if (array_search($sc->name, $ignores) === FALSE) 01994 { 01995 $html .= " <ul>\n"; 01996 } 01997 01998 $html .= generateClassHierarchyHtmlTreeSearchRecur($sc, $counts, $dataset, $attribute, $type, $page, $ignores, 01999 $nb); 02000 02001 if (array_search($sc->name, $ignores) === FALSE) 02002 { 02003 $html .= " </ul>\n"; 02004 } 02005 } 02006 else 02007 { 02008 if (array_search($sc->name, $ignores) === FALSE) 02009 { 02010 $html .= " </li>\n"; 02011 } 02012 } 02013 } 02014 02015 return $html; 02016 } 02017 02019 02020 ?>
