public function view($term, $pageID)
 {
     //require_once  'JsonClientUtil.php';
     require_once 'ServiceUtil.php';
     require_once 'Config.php';
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $util = new ServiceUtil();
     $data['test'] = NULL;
     $term = str_replace("_", "%20", $term);
     //$term = str_replace("/", "%2F", $term);
     $startPoint = ($pageID - 1) * 20;
     $result = $util->expandTerm($term);
     $terms = $util->parseExpandedTerm($result, $term);
     //$litResult = searchLiteratureByYearUsingSolr($terms,$startPoint,20,"*",$year);
     $litResult = $util->searchLatestLiterature($terms, $startPoint, 20, "*", "*");
     $data['publications'] = $litResult;
     $data['term'] = $term;
     $data['pageID'] = $pageID;
     $data['page_title'] = "Literature:" . str_replace("%20", " ", $term);
     $data['enable_config'] = true;
     $this->load->view('templates/header2', $data);
     $this->load->view('pages/latestPublicationDisplay', $data);
     $this->load->view('templates/footer2', $data);
 }
 public function summary($page)
 {
     require_once 'ServiceUtil.php';
     $util = new ServiceUtil();
     require_once 'Config.php';
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $pageName = NULL;
     $termObj = NULL;
     $pageName = $page;
     $pos = strpos($pageName, ":");
     //echo "----pos:".$pos;
     if ($pos == false) {
         $pageName = str_replace("_", "%20", $page);
         $pageName = str_replace(",", "%2c", $pageName);
         $data["page"] = $page;
     }
     $isNifID = false;
     $originalPageName = "";
     if ($pos != false) {
         $termObj[0] = $util->getObjByCurie($pageName);
         #echo "\n-------Willy----!is_null(termObj):".!is_null($termObj)."\n";
         if (!is_null($termObj) && !is_null($termObj[0])) {
             $data['curie'] = $termObj[0]->curie;
             if (count($termObj[0]->labels) > 0) {
                 $data['pageName'] = $termObj[0]->labels[0];
                 $pageName = $data['pageName'];
                 $originalPageName = $pageName;
                 $pageName = str_replace(" ", "%20", $pageName);
                 $pageName = str_replace(",", "%2c", $pageName);
                 $data['pageName'] = $pageName;
                 $isNifID = true;
             } else {
                 $data['pageName'] = $pageName;
             }
         } else {
             $data['pageName'] = $pageName;
             $termObj = getTerm($pageName);
         }
     }
     $pageName = str_replace(str_split('_'), '%20', $pageName);
     $pageName = str_replace(str_split(','), '%2c', $pageName);
     $pageName = str_replace(str_split('/'), '%2f', $pageName);
     $data['pageName'] = $pageName;
     $data['page_title'] = $pageName;
     $data['enable_config'] = true;
     $stitle = "";
     if (!$isNifID) {
         $stitle = ucfirst($page);
         $stitle = str_replace("_", " ", $stitle);
         $data['title'] = $stitle;
     } else {
         $stitle = $originalPageName;
         $data['title'] = $stitle;
     }
     $this->handleDataSpace($data, $pageName);
     $this->load->view('api/view_summary', $data);
 }
 public function view($page)
 {
     require_once 'ServiceUtil.php';
     require_once 'Config.php';
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $pageName = $page;
     $pageName = str_replace(str_split('_'), '%20', $pageName);
     $pageName = str_replace(str_split(','), '%2c', $pageName);
     $util = new ServiceUtil();
     $termObj = $util->getTerm($pageName);
     //var_dump($termObj);
     if (!is_null($termObj) && count($termObj) > 0) {
         $data['termObj'] = $termObj;
         $page_title = $pageName = str_replace(str_split('_,'), ' ', $pageName);
         $data['page_title'] = "Term:" . $page_title;
         $data['enable_config'] = false;
         $this->load->view('templates/header2', $data);
         $this->load->view('pages/DisplayTermLanding', $data);
         $this->load->view('templates/footer2', $data);
     } else {
         show_404();
     }
 }
 private function doSearch($keywords)
 {
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
     //$protocol = "http";
     $domainName = $_SERVER['HTTP_HOST'];
     require_once 'ServiceUtil.php';
     require_once 'Config.php';
     $this->load->helper('url');
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $util = new ServiceUtil();
     $keywords = str_replace(" ", "%20", $keywords);
     /*$sources = $this->loadSourcesConfig($data);
       if($sources != null)
       {
           $data['ks_sources'] = $sources;
           
       }*/
     //Loading categories configurations
     /*$categories = $this->loadCategoriesConfig($data);
       if($categories != null)
       {
           $data['categories'] = $categories;
       }*/
     $termResult = $util->getTerm($keywords);
     //var_dump($termResult);
     $termSize = 0;
     if (!is_null($termResult)) {
         $termSize = count($termResult);
     }
     //echo "------Term size:".$termSize."<br/>\n";
     if ($termSize == 1) {
         //echo "------Curie:".$termResult[0]->curie."<br/>\n";
         if (isset($termResult[0]->curie)) {
             //echo "<br/><center>Redirecting to ".$termResult[0]->curie." ...</center>";
             //redirect($protocol."://".$domainName."/".Config::$localContextName."/index.php/pages/view/".$termResult[0]->curie, 'refresh');
             redirect($protocol . $domainName . "/" . Config::$localContextName . "/index.php/pages/view/" . $termResult[0]->curie, 'location', 301);
         }
         return;
     }
     $searchResult = $util->searchTerm($keywords);
     $data['keywords'] = $keywords;
     $data['termResult'] = $termResult;
     if (!is_null($termResult)) {
         $searchResult = array_merge($termResult, $searchResult);
         $unique = array();
         $uniqueArray = array();
         foreach ($searchResult as $row) {
             if (isset($unique[$row->curie])) {
                 continue;
             } else {
                 $unique[$row->curie] = $row->curie;
                 array_push($uniqueArray, $row);
             }
         }
         $searchResult = $uniqueArray;
     }
     $data['searchResult'] = $searchResult;
     $data['page_title'] = "Search";
     $data['enable_config'] = false;
     $data['disableTopSearchBar'] = true;
     //var_dump($termResult);
     $this->load->view('templates/header2', $data);
     //$this->load->view('pages/'.$page, $data);
     $this->load->view('pages/search_result', $data);
     $this->load->view('templates/footer2', $data);
 }
 public function view($term, $sourceID, $pageID)
 {
     require_once 'ServiceUtil.php';
     require_once 'Config.php';
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $page = $term;
     $data["pageName"] = $page;
     $util = new ServiceUtil();
     /*$ks_selected_sources = $_COOKIE['ks_selected_sources'];
       
       $selectedSourcesArray =null;
       if($ks_selected_sources!= null)
       {
           $selectedSourcesArray = explode(",", $ks_selected_sources);
           $data['ks_selected_sources'] = $selectedSourcesArray;
           
       }
       $ks_sources = $util->loadSourcesConfig($data);
       $sourceNameArray = $this->handleSourceNames($ks_sources);
       $data['sourceNameArray'] = $sourceNameArray;*/
     //if($sources != null)
     //{
     //       $data['ks_sources'] = $sources;
     //
     //}
     $selectedSourcesArray = $data['ks_sources'];
     $result = array();
     $description = array();
     if ($selectedSourcesArray != null) {
         $newName = $this->fixSearchName($page);
         foreach ($selectedSourcesArray as $source) {
             if (strcmp($sourceID, $source) == 0) {
                 $offset = 0;
                 if (!isset($pageID) || $pageID <= 1) {
                     $offset = 0;
                 } else {
                     $offset = ($pageID - 1) * 20;
                 }
                 //$result[$source] =$this->handleData($data,$page,$source,20,$offset);
                 //$result[$source] =$this->handleData($data,$newName,$source,20,$offset);
                 $result[$source] = $util->searchWithinSource($newName, $source, 20, $offset);
             } else {
                 //$result[$source] =$this->handleData($data,$newName,$source,20,0);
                 $result[$source] = $util->searchWithinSource($newName, $source, 20, 0);
                 //var_dump($source);
                 //var_dump($data);
                 //echo "-----".$newName;
                 //echo "-----".$source;
             }
             $description[$source] = $this->getDescription($source, $myConfig);
         }
     }
     $data['result'] = $result;
     $data['description'] = $description;
     if (strcmp($sourceID, "0") != 0) {
         $data['selectedSourceID'] = $sourceID;
         $data['selectedPageID'] = $pageID;
     } else {
         $data['selectedSourceID'] = 0;
         $data['selectedPageID'] = 0;
     }
     //$this->load->view('templates/header', $data);
     $this->load->view('pages/viewAllData', $data);
     //$this->load->view('templates/footer', $data);
 }
 private function handleLexicon(&$data, $curie, $tempParentID)
 {
     require_once 'ServiceUtil.php';
     require_once 'Config.php';
     $util = new ServiceUtil();
     $data['curie'] = $curie;
     $treeObj = $util->getTreeObj($curie);
     $data['treeObj'] = $treeObj;
     $parentID = $tempParentID;
     if (strcmp($parentID, "none") == 0) {
         $parentID = $util->getParentID($treeObj, $curie);
     }
     $data['parentID'] = $parentID;
     $node = $util->getNode($treeObj, $parentID);
     $data['node'] = $node;
     $mainNode = $util->getNode($treeObj, $curie);
     $data['mainNode'] = $mainNode;
     $list = $util->getChildrenIDs($treeObj, $curie);
     $data['list'] = $list;
     $leafHTML = "";
     $list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($list->rewind(); $list->valid(); $list->next()) {
         $item = $list->current();
         $leaf = $util->getNode($treeObj, $item);
         $leafLinkName = str_replace(" ", "_", $leaf->lbl);
         $leafLinkName = str_replace("(", "_", $leafLinkName);
         $leafLinkName = str_replace(")", "_", $leafLinkName);
         //$leafLink = "/SciCrunchKS/index.php/pages/view/".$leafLinkName;
         $leafLink = "/" . Config::$localContextName . "/index.php/pages/view/" . $leaf->id;
         //$leafHTML = $leafHTML . "<ul><li><span><i class=\"icon-leaf\"></i><a href=\"".$leafLink."\">" . $leaf->lbl . "</a></span> <a href=\"\"></a></li></ul>\n";
         $leafHTML = $leafHTML . "<ul><li><span id=\"" . $leaf->id . "," . $mainNode->id . "\"><i class=\"icon-plus-sign\"></i>" . $leaf->lbl . "</span> <a href=\"" . $leafLink . "\"><img src=\"/img/view-icon.png\" width=\"25\" height=\"25\"></a></li></ul>\n";
     }
     $data['leafHTML'] = $leafHTML;
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $util = new ServiceUtil();
     //$list2 = $util->getOtherChildrenIDs($treeObj, $curie,PropertyConfig::$has_proper_part);
     $list2 = $util->getOtherChildrenIDs($treeObj, $curie, $data["config_array"]->has_proper_part_property);
     //$partOfParentID = $util->getOtherParentID($treeObj, $curie,PropertyConfig::$has_proper_part);
     $partOfParentID = $util->getOtherParentID($treeObj, $curie, $data["config_array"]->has_proper_part_property);
     $partOfParenttNode = $util->getNode($treeObj, $partOfParentID);
     $data['node2'] = $partOfParenttNode;
     $leafHTML = null;
     $list2->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($list2->rewind(); $list2->valid(); $list2->next()) {
         $item = $list2->current();
         $leaf = $util->getNode($treeObj, $item);
         $leafLinkName = str_replace(" ", "_", $leaf->lbl);
         $leafLinkName = str_replace("(", "_", $leafLinkName);
         $leafLinkName = str_replace(")", "_", $leafLinkName);
         //$leafLink = "/SciCrunchKS/index.php/pages/view/".$leafLinkName;
         $leafLink = "/" . Config::$localContextName . "/index.php/pages/view/" . $leaf->id;
         //$leafHTML = $leafHTML . "<ul><li><span><i class=\"icon-leaf\"></i><a href=\"".$leafLink."\">" . $leaf->lbl . "</a></span> <a href=\"\"></a></li></ul>\n";
         $leafHTML = $leafHTML . "<ul><li><span id=\"" . $leaf->id . "," . $mainNode->id . "\"><i class=\"icon-plus-sign\"></i>" . $leaf->lbl . "</span> <a href=\"" . $leafLink . "\"><img src=\"/img/view-icon.png\" width=\"25\" height=\"25\"></a></li></ul>\n";
     }
     $data['leafHTML2'] = $leafHTML;
     //$list3 = $util->getChildrenIDsIncoming($treeObj, $curie,PropertyConfig::$part_of);
     $list3 = $util->getChildrenIDsIncoming($treeObj, $curie, $data["config_array"]->part_of_property);
     //$partOfParentID3 = $util->getParentIDIncoming($treeObj, $curie,PropertyConfig::$part_of);
     $partOfParentID3 = $util->getParentIDIncoming($treeObj, $curie, $data["config_array"]->part_of_property);
     $partOfParenttNode3 = $util->getNode($treeObj, $partOfParentID3);
     $data['node3'] = $partOfParenttNode3;
     $leafHTML = null;
     $list3->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($list3->rewind(); $list3->valid(); $list3->next()) {
         $item = $list3->current();
         $leaf = $util->getNode($treeObj, $item);
         $leafLinkName = str_replace(" ", "_", $leaf->lbl);
         $leafLinkName = str_replace("(", "_", $leafLinkName);
         $leafLinkName = str_replace(")", "_", $leafLinkName);
         //$leafLink = "/SciCrunchKS/index.php/pages/view/".$leafLinkName;
         $leafLink = "/" . Config::$localContextName . "/index.php/pages/view/" . $leaf->id;
         //$leafHTML = $leafHTML . "<ul><li><span><i class=\"icon-leaf\"></i><a href=\"".$leafLink."\">" . $leaf->lbl . "</a></span> <a href=\"\"></a></li></ul>\n";
         $leafHTML = $leafHTML . "<ul><li><span id=\"" . $leaf->id . "," . $mainNode->id . "\"><i class=\"icon-plus-sign\"></i>" . $leaf->lbl . "</span> <a href=\"" . $leafLink . "\"><img src=\"/img/view-icon.png\" width=\"25\" height=\"25\"></a></li></ul>\n";
     }
     $data['leafHTML3'] = $leafHTML;
     /********************Loop properties***************************/
     $relation_array = array();
     $properties = $data["config_array"]->properties_included;
     foreach ($properties as $property) {
         //echo "<br/>".$property->name."-------".$property->value."\n";
         /*$tempList = $util->getChildrenIDsIncoming($treeObj, $curie,$property->value);
           $tempParentID = $util->getParentIDIncoming($treeObj, $curie,$property->value);*/
         $tempList = NULL;
         $tempParentID = NULL;
         if (strcmp($property->direction, "in-coming")) {
             $tempList = $util->getChildrenIDsIncoming($treeObj, $curie, $property->value);
             $tempParentID = $util->getParentIDIncoming($treeObj, $curie, $property->value);
         } else {
             if (strcmp($property->direction, "out-going")) {
                 $tempList = $util->getOtherChildrenIDs($treeObj, $curie, $property->value);
                 $tempParentID = $util->getOtherParentID($treeObj, $curie, $property->value);
             }
         }
         $tempPrarentNode = $util->getNode($treeObj, $tempParentID);
         $leafHTML = null;
         $tempList->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
         for ($tempList->rewind(); $tempList->valid(); $tempList->next()) {
             $item = $tempList->current();
             $leaf = $util->getNode($treeObj, $item);
             $leafLinkName = str_replace(" ", "_", $leaf->lbl);
             $leafLinkName = str_replace("(", "_", $leafLinkName);
             $leafLinkName = str_replace(")", "_", $leafLinkName);
             //$leafLink = "/SciCrunchKS/index.php/pages/view/".$leafLinkName;
             $leafLink = "/" . Config::$localContextName . "/index.php/pages/view/" . $leaf->id;
             //$leafHTML = $leafHTML . "<ul><li><span><i class=\"icon-leaf\"></i><a href=\"".$leafLink."\">" . $leaf->lbl . "</a></span> <a href=\"\"></a></li></ul>\n";
             $leafHTML = $leafHTML . "<ul><li><span id=\"" . $leaf->id . "," . $mainNode->id . "\"><i class=\"icon-plus-sign\"></i>" . $leaf->lbl . "</span> <a href=\"" . $leafLink . "\"><img src=\"/img/view-icon.png\" width=\"25\" height=\"25\"></a></li></ul>\n";
         }
         $ctree = new CustomTree();
         $ctree->parentNode = $tempPrarentNode;
         $ctree->mainNode = $mainNode;
         $ctree->leafHtml = $leafHTML;
         $relation_array[$property->name] = $ctree;
     }
     $data["relation_array"] = $relation_array;
 }
 private function handleLexicon(&$data, $curie, $tempParentID)
 {
     require_once 'ServiceUtil.php';
     $util = new ServiceUtil();
     $data['curie'] = $curie;
     $treeObj = $util->getTreeObj($curie);
     $data['treeObj'] = $treeObj;
     $parentID = $tempParentID;
     if (strcmp($parentID, "none") == 0) {
         $parentID = $util->getParentID($treeObj, $curie);
     }
     $data['parentID'] = $parentID;
     $node = $util->getNode($treeObj, $parentID);
     $data['node'] = $node;
     $mainNode = $util->getNode($treeObj, $curie);
     $data['mainNode'] = $mainNode;
     $list = $util->getChildrenIDs($treeObj, $curie);
     $data['list'] = $list;
     $leafHTML = "";
     $list->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($list->rewind(); $list->valid(); $list->next()) {
         $item = $list->current();
         $leaf = $util->getNode($treeObj, $item);
         $leafLinkName = str_replace(" ", "_", $leaf->lbl);
         $leafLinkName = str_replace("(", "_", $leafLinkName);
         $leafLinkName = str_replace(")", "_", $leafLinkName);
         //$leafLink = "/SciCrunchKS/index.php/pages/view/".$leafLinkName;
         $leafLink = "/" . Config::$localContextName . "/index.php/pages/view/" . $leaf->id;
         //$leafHTML = $leafHTML . "<ul><li><span><i class=\"icon-leaf\"></i><a href=\"".$leafLink."\">" . $leaf->lbl . "</a></span> <a href=\"\"></a></li></ul>\n";
         $leafHTML = $leafHTML . "<ul><li><span id=\"" . $leaf->id . "," . $mainNode->id . "\"><i class=\"icon-plus-sign\"></i>" . $leaf->lbl . "</span> <a href=\"" . $leafLink . "\"><img src=\"/img/view-icon.png\" width=\"25\" height=\"25\"></a></li></ul>\n";
     }
     $data['leafHTML'] = $leafHTML;
     require_once 'ServiceUtil.php';
     //require_once('PropertyConfig.php');
     require_once 'Config.php';
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $util = new ServiceUtil();
     //$list2 = $util->getOtherChildrenIDs($treeObj, $curie,PropertyConfig::$has_proper_part);
     $list2 = $util->getOtherChildrenIDs($treeObj, $curie, $data["config_array"]->has_proper_part_property);
     //$partOfParentID = $util->getOtherParentID($treeObj, $curie,PropertyConfig::$has_proper_part);
     $partOfParentID = $util->getOtherParentID($treeObj, $curie, $data["config_array"]->has_proper_part_property);
     $partOfParenttNode = $util->getNode($treeObj, $partOfParentID);
     $data['node2'] = $partOfParenttNode;
     $leafHTML = null;
     $list2->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($list2->rewind(); $list2->valid(); $list2->next()) {
         $item = $list2->current();
         $leaf = $util->getNode($treeObj, $item);
         $leafLinkName = str_replace(" ", "_", $leaf->lbl);
         $leafLinkName = str_replace("(", "_", $leafLinkName);
         $leafLinkName = str_replace(")", "_", $leafLinkName);
         //$leafLink = "/SciCrunchKS/index.php/pages/view/".$leafLinkName;
         $leafLink = "/" . Config::$localContextName . "/index.php/pages/view/" . $leaf->id;
         //$leafHTML = $leafHTML . "<ul><li><span><i class=\"icon-leaf\"></i><a href=\"".$leafLink."\">" . $leaf->lbl . "</a></span> <a href=\"\"></a></li></ul>\n";
         $leafHTML = $leafHTML . "<ul><li><span id=\"" . $leaf->id . "," . $mainNode->id . "\"><i class=\"icon-plus-sign\"></i>" . $leaf->lbl . "</span> <a href=\"" . $leafLink . "\"><img src=\"/img/view-icon.png\" width=\"25\" height=\"25\"></a></li></ul>\n";
     }
     $data['leafHTML2'] = $leafHTML;
     //$list3 = $util->getChildrenIDsIncoming($treeObj, $curie,PropertyConfig::$part_of);
     $list3 = $util->getChildrenIDsIncoming($treeObj, $curie, $data["config_array"]->part_of_property);
     //$partOfParentID3 = $util->getParentIDIncoming($treeObj, $curie,PropertyConfig::$part_of);
     $partOfParentID3 = $util->getParentIDIncoming($treeObj, $curie, $data["config_array"]->part_of_property);
     $partOfParenttNode3 = $util->getNode($treeObj, $partOfParentID3);
     $data['node3'] = $partOfParenttNode3;
     $leafHTML = null;
     $list3->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
     for ($list3->rewind(); $list3->valid(); $list3->next()) {
         $item = $list3->current();
         $leaf = $util->getNode($treeObj, $item);
         $leafLinkName = str_replace(" ", "_", $leaf->lbl);
         $leafLinkName = str_replace("(", "_", $leafLinkName);
         $leafLinkName = str_replace(")", "_", $leafLinkName);
         //$leafLink = "/SciCrunchKS/index.php/pages/view/".$leafLinkName;
         $leafLink = "/" . Config::$localContextName . "/index.php/pages/view/" . $leaf->id;
         //$leafHTML = $leafHTML . "<ul><li><span><i class=\"icon-leaf\"></i><a href=\"".$leafLink."\">" . $leaf->lbl . "</a></span> <a href=\"\"></a></li></ul>\n";
         $leafHTML = $leafHTML . "<ul><li><span id=\"" . $leaf->id . "," . $mainNode->id . "\"><i class=\"icon-plus-sign\"></i>" . $leaf->lbl . "</span> <a href=\"" . $leafLink . "\"><img src=\"/img/view-icon.png\" width=\"25\" height=\"25\"></a></li></ul>\n";
     }
     $data['leafHTML3'] = $leafHTML;
 }
 public function view($sourceID, $term, $pageID)
 {
     //require_once  'JsonClientUtil.php';
     //require_once 'Config.php';
     require_once 'ServiceUtil.php';
     require_once 'Config.php';
     $util = new ServiceUtil();
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $data['test'] = NULL;
     $term = str_replace("_", "%20", $term);
     $newName = $term;
     $searchName = $term;
     if (strcasecmp($searchName, "cell") == 0) {
         $newName = $searchName;
     } else {
         if (strcasecmp($searchName, "neuron") == 0) {
             $newName = $searchName;
         } else {
             if ($util->endsWith($searchName, "%20cell")) {
                 $tempName = substr($searchName, 0, strlen($searchName) - strlen("%20cell"));
                 $newName = $tempName;
             } else {
                 if ($util->endsWith($searchName, "%20neuron")) {
                     $tempName = substr($searchName, 0, strlen($searchName) - strlen("%20neuron"));
                     $newName = $tempName;
                 }
             }
         }
     }
     $offset = 0;
     //echo "\nSourceID------".$sourceID;
     //echo "\nTerm:".$term;
     if (!isset($pageID) || $pageID <= 1) {
         $offset = 0;
     } else {
         $offset = ($pageID - 1) * 20;
     }
     //echo "---------------".$newName;
     $data['resultObj'] = $util->searchWithinSource($newName, $sourceID, 20, $offset);
     // $data['resultObj'] = searchWithinSource2($term, $sourceID, 20,$offset);
     /*if(endsWith($term, "%20cell"))
       {
           
           $tempName = substr($term, 0, strlen($term)-strlen("%20cell"));
           //echo "-------------tempName:".$tempName."----".strlen($term)."--------";
           $tempResult = searchWithinSource2($tempName, $sourceID, 20,$offset);
           if($tempResult->result->resultCount > $data['resultObj']->result->resultCount)
               $data['resultObj'] = $tempResult;
       }*/
     $data['sourceID'] = $sourceID;
     $data['pageID'] = $pageID;
     $data['term'] = $term;
     $protocol = "http";
     if (isset($_SERVER['HTTPS'])) {
         $protocol = "https";
     }
     $surl = $protocol . "://" . $_SERVER['SERVER_NAME'] . "/" . Config::$localContextName . "/resources/source_description/" . $sourceID;
     //echo "\n".$surl;
     $responseCode = @get_headers($surl);
     //echo "CODE:".$file_headers[0]."---------";
     if ($responseCode[0] == 'HTTP/1.1 404 Not Found') {
         $data['description'] = "";
     } else {
         $data['description'] = file_get_contents($surl);
     }
     //var_dump($data['resultObj']);
     $data['page_title'] = "Search:" . str_replace("%20", " ", $term);
     $data['enable_config'] = true;
     $this->load->view('templates/header2', $data);
     $this->load->view('pages/resultDisplay', $data);
     $this->load->view('templates/footer2', $data);
 }
 public function view($page = 'home')
 {
     require_once 'ServiceUtil.php';
     $util = new ServiceUtil();
     require_once 'Config.php';
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     $pageName = $page;
     $termObj = NULL;
     $termObj[0] = $util->getObjByCurie($pageName);
     #echo "\n-------Willy----!is_null(termObj):".!is_null($termObj)."\n";
     if (!is_null($termObj) && !is_null($termObj[0])) {
         $data['curie'] = $termObj[0]->curie;
         if (count($termObj[0]->labels) > 0) {
             $data['pageName'] = $termObj[0]->labels[0];
             $pageName = $data['pageName'];
             //echo "PageName here-----".$pageName;
             $originalPageName = $pageName;
             $pageName = str_replace(" ", "%20", $pageName);
             // echo "<br/>PageName here-----".$pageName;
             $pageName = str_replace(",", "%2c", $pageName);
             // echo "<br/>PageName here-----".$pageName;
             $data['pageName'] = $pageName;
             $isNifID = true;
         } else {
             $data['pageName'] = $pageName;
         }
     }
     $pageName = str_replace(str_split('_'), '%20', $pageName);
     $pageName = str_replace(str_split(','), '%2c', $pageName);
     $pageName = str_replace(str_split('/'), '%2f', $pageName);
     $data['pageName'] = $pageName;
     $data['page_title'] = $pageName;
     $data['title'] = $pageName;
     $data['enable_config'] = true;
     //$newCurie = str_replace(":","_",$data['curie']);
     $fileName = "/" . $data['config_array']->cache_folder . "/" . $data['curie'] . "-literature-String.cache";
     //echo "<br/>".$fileName;
     $stats = NULL;
     if (file_exists($fileName)) {
         $stats = stat($fileName);
     }
     $current = time();
     $diff = $current - $stats[9];
     /*if (file_exists($fileName) && $diff > (86400 * 1))
       {
           unlink($fileName);
           //echo "unlinking due to expiration.";
       }
       else if(file_exists($fileName) && filesize($fileName) == 0)
       {
           unlink($fileName);
           //echo "unlinking due to empty file";
       }*/
     // $fileContent = file_get_contents($fileName);
     //echo "<br/>File content:".$fileContent."------";
     if (!file_exists($fileName)) {
         //echo "<br/>----File does not exist:".$fileName."-----";
         $this->handleLiterature($data, $pageName);
         $this->load->view('pages/outputLiteratureAsString', $data);
     } else {
         //echo "<br/>----File exists:".$fileName;
         $fileContent = file_get_contents($fileName);
         $data['fileContent'] = $fileContent;
         $this->load->view('pages/outputLiteratureAsString2', $data);
     }
     //$this->load->view('templates/header2', $data);
     //$this->load->view('templates/footer2', $data);
 }
 public function view($page = 'home')
 {
     //require  'Globals.php';
     //$enableCaching = false;
     //require_once 'CacheConfig.php';
     //require_once  'JsonClientUtil.php';
     //require_once 'Config.php';
     $this->load->helper('url');
     require_once 'ServiceUtil.php';
     $util = new ServiceUtil();
     require_once 'Config.php';
     $myConfig = new Config();
     $myConfig->loadJsonConfig($data);
     //$this->loadJsonConfig($data);
     //init();
     /*if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
      	{
              	// Whoops, we don't have a page for that!
              	show_404();
      	}*/
     $pageName = NULL;
     $termObj = NULL;
     $pageName = $page;
     $pos = strpos($pageName, ":");
     //echo "----pos:".$pos;
     if ($pos == false) {
         $pageName = str_replace("_", "%20", $page);
         $pageName = str_replace(",", "%2c", $pageName);
         $data["page"] = $page;
     }
     $isNifID = false;
     $originalPageName = "";
     //Loading sources configurations
     /*$sources = $this->loadSourcesConfig($data);
       if($sources != null)
       {
           $data['ks_sources'] = $sources;
           
       }*/
     //Loading categories configurations
     /*$categories = $this->loadCategoriesConfig($data);
       if($categories != null)
       {
           $data['categories'] = $categories;
       }*/
     if ($pos != false) {
         $termObj[0] = $util->getObjByCurie($pageName);
         #echo "\n-------Willy----!is_null(termObj):".!is_null($termObj)."\n";
         if (!is_null($termObj) && !is_null($termObj[0])) {
             $data['curie'] = $termObj[0]->curie;
             if (count($termObj[0]->labels) > 0) {
                 $data['pageName'] = $termObj[0]->labels[0];
                 $pageName = $data['pageName'];
                 //echo "PageName here-----".$pageName;
                 $originalPageName = $pageName;
                 $pageName = str_replace(" ", "%20", $pageName);
                 // echo "<br/>PageName here-----".$pageName;
                 $pageName = str_replace(",", "%2c", $pageName);
                 // echo "<br/>PageName here-----".$pageName;
                 $data['pageName'] = $pageName;
                 $isNifID = true;
             } else {
                 $data['pageName'] = $pageName;
             }
         } else {
             $data['pageName'] = $pageName;
             $termObj = getTerm($pageName);
         }
     } else {
         $data['pageName'] = $pageName;
         //echo "-----pageName:".$pageName;
         $termObj = $util->getTerm($pageName);
         //var_dump($termObj);
         $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
         $domainName = $_SERVER['HTTP_HOST'];
         if (!is_null($termObj)) {
             //echo "-------------termObj size: ".count($termObj);
             if (count($termObj) == 1 && isset($termObj[0]) && !is_null($termObj[0]->curie)) {
                 //redirect('http://google.com', 'location');
                 redirect($protocol . "://" . $domainName . "/" . Config::$localContextName . "/index.php/pages/view/" . $termObj[0]->curie, 'refresh');
             }
             if (count($termObj) > 1) {
                 //http://localhost/NeuroKS/index.php/TermLanding/view/cerebellum%20purkinje%20cell
                 //redirect($protocol.":/".$domainName."/".Config::$localContextName."/index.php/Term/view/".$page, 'refresh');
                 $data['termObj'] = $termObj;
                 $temp_page_title = $pageName = str_replace(str_split('_,'), ' ', $page);
                 $data['page_title'] = "Term:" . $temp_page_title;
                 $data['enable_config'] = false;
                 //redirect('http://google.com', 'location');
                 //redirect($protocol."://".$domainName."/".Config::$localContextName."/index.php/pages/view/".$termObj[0]->curie, 'refresh');
                 //exit(0);
                 $this->load->view('templates/header2', $data);
                 $this->load->view('pages/DisplayTermLanding', $data);
                 $this->load->view('templates/footer2', $data);
                 return;
                 //exit(0);
             }
             $data['curie'] = $termObj[0]->curie;
         }
     }
     //$pageName = str_replace(" ", "%20", $pageName);
     //$pageName = str_replace(",", "%2c", $pageName);
     //$pageName = str_replace("/", "%20", $pageName);
     $pageName = str_replace(str_split('_'), '%20', $pageName);
     $pageName = str_replace(str_split(','), '%2c', $pageName);
     $pageName = str_replace(str_split('/'), '%2f', $pageName);
     $data['pageName'] = $pageName;
     $data['page_title'] = $pageName;
     $data['enable_config'] = true;
     //////////////////////
     //$cachefile = '/webCache/'.basename($_SERVER['PHP_SELF']).'.cache'; // e.g. cache/index.php.cache
     $cachefile = $data["config_array"]->cache_folder . basename($_SERVER['PHP_SELF']) . '.cache';
     // e.g. cache/index.php.cache
     $cachetime = 3600 * 24;
     // time to cache in seconds
     $c = "";
     //if($this->enableCaching)
     //echo "--------".$data["config_array"]->enableCaching;
     if ($data["config_array"]->enable_caching) {
         //echo "====cachiing----";
         if (!file_exists($cachefile)) {
             //Do nothing
         } else {
             if (file_exists($cachefile) && time() - $cachetime <= filemtime($cachefile)) {
                 $c = @file_get_contents($cachefile);
                 echo $c;
                 exit;
             } else {
                 unlink($cachefile);
             }
         }
         ///////////////////////
         if (is_null($termObj)) {
             show_404();
             return;
         }
         ob_start();
     }
     ///////////////////////////////////////////////////////
     $this->handleSummary($data, $termObj, $pageName);
     //$data['title'] = ucfirst($page); // Capitalize the first letter
     $stitle = "";
     if (!$isNifID) {
         $stitle = ucfirst($page);
         $stitle = str_replace("_", " ", $stitle);
         $data['title'] = $stitle;
     } else {
         $stitle = $originalPageName;
         $data['title'] = $stitle;
     }
     #echo "\nWilly--------pageName:".$pageName."\n";
     $this->handleDataSpace($data, $pageName);
     if (isset($termObj[0])) {
         $this->handleLexicon($data, $termObj[0]->curie);
     }
     $this->handleLiterature($data, $pageName);
     $this->load->view('templates/header2', $data);
     //$this->load->view('pages/'.$page, $data);
     //$this->load->view('pages/term', $data);
     $this->load->view('pages/layout', $data);
     $this->load->view('templates/footer2', $data);
     ///////////////////////////////////////////////
     //if($this->enableCaching)
     if ($data["config_array"]->enable_caching) {
         $c = ob_get_contents();
         file_put_contents($cachefile, $c);
     }
 }