Skip to content

Commit

Permalink
Merge pull request #20 from BioKIC/master
Browse files Browse the repository at this point in the history
Image Search Dev
  • Loading branch information
egbot authored Jul 24, 2020
2 parents 1f93dc5 + f7343e7 commit b5c1b6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
30 changes: 15 additions & 15 deletions classes/ImageLibrarySearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,9 @@ function __destruct(){
parent::__destruct();
}

public function setAdditionalRequestVariables(){
if(array_key_exists('db',$_REQUEST) && $_REQUEST['db']){
$this->dbStr = OccurrenceSearchSupport::getDbRequestVariable($_REQUEST);
}
if(array_key_exists('taxa',$_REQUEST) && $_REQUEST['taxa']){
$this->setTaxonRequestVariable();
}
$this->setSqlWhere();
}

public function getImageArr($pageRequest,$cntPerPage){
$retArr = Array();
$this->setSqlWhere();
$this->setRecordCnt();
$sql = 'SELECT DISTINCT i.imgid, i.tid, IFNULL(t.sciname,o.sciname) as sciname, i.url, i.thumbnailurl, i.originalurl, i.photographeruid, i.caption, i.occid ';
/*
Expand All @@ -51,7 +42,7 @@ public function getImageArr($pageRequest,$cntPerPage){
$sqlWhere = $this->sqlWhere;
if($this->imageCount == 'taxon') $sqlWhere .= 'GROUP BY sciname ';
elseif($this->imageCount == 'specimen') $sqlWhere .= 'GROUP BY i.occid ';
$sqlWhere .= 'ORDER BY sciname ';
if($this->sqlWhere) $sqlWhere .= 'ORDER BY sciname ';
$bottomLimit = ($pageRequest - 1)*$cntPerPage;
$sql .= $this->getSqlBase().$sqlWhere.'LIMIT '.$bottomLimit.','.$cntPerPage;
//echo '<div>Spec sql: '.$sql.'</div>';
Expand Down Expand Up @@ -383,6 +374,10 @@ private function resetTaxaStr(){
}

//Setters and getters
public function setCollectionVariables($reqArr){
$this->dbStr = OccurrenceSearchSupport::getDbRequestVariable($reqArr);
}

public function setTaxonType($t){
if(is_numeric($t)) $this->taxonType = $t;
}
Expand All @@ -392,8 +387,13 @@ public function getTaxonType(){
}

public function setTaxaStr($str){
$this->taxaStr = filter_var($str, FILTER_SANITIZE_STRING);
if(is_numeric($this->taxaStr)) $this->resetTaxaStr();
if(strpos($str,'<') === false){
$this->taxaStr = filter_var(trim($str), FILTER_SANITIZE_STRING);
if($this->taxaStr){
if(is_numeric($this->taxaStr)) $this->resetTaxaStr();
$this->setTaxonRequestVariable(array('taxa'=>$this->taxaStr,'taxontype'=>$this->taxonType,'usethes'=>$this->useThes));
}
}
}

public function getTaxaStr(){
Expand All @@ -417,15 +417,15 @@ public function getPhotographerUid(){
}

public function setTags($t){
$this->tags = filter_var($t, FILTER_SANITIZE_STRING);
if(strpos($t,'<') === false) $this->tags = filter_var($t, FILTER_SANITIZE_STRING);
}

public function getTags(){
return $this->tags;
}

public function setKeywords($k){
$this->keywords = filter_var($k, FILTER_SANITIZE_STRING);
if(strpos($k,'<') === false) $this->keywords = filter_var($k, FILTER_SANITIZE_STRING);
}

public function getKeywords(){
Expand Down
4 changes: 2 additions & 2 deletions classes/OccurrenceSearchSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ public static function getDbRequestVariable($reqArr){
$dbStr = $reqArr['db'];
if(is_array($dbStr)) $dbStr = implode(',',array_unique($dbStr)).';';
else $dbStr = $dbStr;
if(!preg_match('/^[a-z0-9,;]+$/', $dbStr)) $dbStr = 'all';
if(strpos($dbStr,'allspec') !== false) $dbStr = 'allspec';
elseif(strpos($dbStr,'allobs') !== false) $dbStr = 'allobs';
elseif(strpos($dbStr,'all') !== false) $dbStr = 'all';
Expand All @@ -296,9 +295,10 @@ public static function getDbRequestVariable($reqArr){
if(is_string($catid)) $catArr = Array($catid);
else $catArr = $catid;
if(!$dbStr) $dbStr = ';';
$dbStr .= implode(",",$catArr);
$dbStr .= implode(',',$catArr);
}
if(!$dbStr) $dbStr = 'all';
if(!preg_match('/^[a-z0-9,;]+$/', $dbStr)) $dbStr = 'all';
return $dbStr;
}

Expand Down
8 changes: 4 additions & 4 deletions imagelib/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
header('Content-Type: text/html; charset='.$CHARSET);

$taxonType = isset($_REQUEST['taxontype'])?$_REQUEST['taxontype']:0;
$taxaStr = isset($_REQUEST['taxa'])?$_REQUEST['taxa']:'';
$useThes = array_key_exists('usethes',$_REQUEST)?$_REQUEST['usethes']:0;
$taxaStr = isset($_REQUEST['taxa'])?$_REQUEST['taxa']:'';
$phUid = array_key_exists('phuid',$_REQUEST)?$_REQUEST['phuid']:0;
$tags = array_key_exists('tags',$_REQUEST)?$_REQUEST['tags']:'';
$keywords = array_key_exists('keywords',$_REQUEST)?$_REQUEST['keywords']:'';
Expand All @@ -29,14 +29,14 @@

$imgLibManager = new ImageLibrarySearch();
$imgLibManager->setTaxonType($taxonType);
$imgLibManager->setTaxaStr($taxaStr);
$imgLibManager->setUseThes($useThes);
$imgLibManager->setTaxaStr($taxaStr);
$imgLibManager->setPhotographerUid($phUid);
$imgLibManager->setTags($tags);
$imgLibManager->setKeywords($keywords);
$imgLibManager->setImageCount($imageCount);
$imgLibManager->setImageType($imageType);
$imgLibManager->setAdditionalRequestVariables();
if(isset($_REQUEST['db'])) $imgLibManager->setCollectionVariables($_REQUEST);
?>
<html>
<head>
Expand Down Expand Up @@ -333,7 +333,7 @@
<?php
}
else{
echo '<h2>No images exist matching your search criteria. Please modify your search and try again.</h2>';
echo '<h3>No images exist matching your search criteria. Please modify your search and try again.</h3>';
}
?>
</div>
Expand Down

0 comments on commit b5c1b6c

Please sign in to comment.