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($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);
     }
 }