Commit 408535b9 authored by Ganesharatnam's avatar Ganesharatnam
Browse files

fixes for code review suggestions

parent b353e93a
...@@ -111,7 +111,7 @@ function uw_lib_refshelf_render_data() { ...@@ -111,7 +111,7 @@ function uw_lib_refshelf_render_data() {
$filter_pagenum = isset($_GET['pagenum']) ? filter_var($_GET['pagenum'], FILTER_SANITIZE_STRING) : NULL; $filter_pagenum = isset($_GET['pagenum']) ? filter_var($_GET['pagenum'], FILTER_SANITIZE_STRING) : NULL;
$filter_search = isset($_GET['search']) ? filter_var($_GET['search'], FILTER_SANITIZE_STRING) : NULL; $filter_search = isset($_GET['search']) ? filter_var($_GET['search'], FILTER_SANITIZE_STRING) : NULL;
//Check for cat_id and toc_id in GET //Check for cat_id and toc_id in GET
if (array_key_exists("cat_id", $_GET) || array_key_exists("toc_id", $_GET)) { if (array_key_exists("cat_id", $_GET) || array_key_exists("toc_id", $_GET)) {
if (isset($filter_cat_id) && !empty($filter_cat_id)) { if (isset($filter_cat_id) && !empty($filter_cat_id)) {
//Displaying Subcategories //Displaying Subcategories
...@@ -399,22 +399,22 @@ function _highlightSearchWord($word, $str) { ...@@ -399,22 +399,22 @@ function _highlightSearchWord($word, $str) {
//Replacement for a search keyword -- all uppercase //Replacement for a search keyword -- all uppercase
if (ctype_upper($word)) { if (ctype_upper($word)) {
$highlighted = handlingKeywordCaseSensitivity($word, $str); $highlighted = _handlingKeywordCaseSensitivity($word, $str);
} }
elseif (ctype_lower($word)) { elseif (ctype_lower($word)) {
//Replacement for a search keyword -- all lowercase //Replacement for a search keyword -- all lowercase
$highlighted = handlingKeywordCaseSensitivity($word, $str); $highlighted = _handlingKeywordCaseSensitivity($word, $str);
} }
elseif ($word == $str_uc_first) { elseif ($word == $str_uc_first) {
//Replacement for a search keyword -- all first letter uppercase //Replacement for a search keyword -- all first letter uppercase
$highlighted = handlingKeywordCaseSensitivity($word, $str); $highlighted = _handlingKeywordCaseSensitivity($word, $str);
} }
else { else {
//Replace exctly like search string //Replace exctly like search string
$regEx = '\'(?!((<.*?)|(<a.*?)))(\b' . $word . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'si'; $regex = '\'(?!((<.*?)|(<a.*?)))(\b' . $word . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'si';
$word_style = "<span class='highlight-search-word'>" . $word . "</span>"; $word_style = "<span class='highlight-search-word'>" . $word . "</span>";
//$highlighted = str_ireplace($word, $word_style, $str); //$highlighted = str_ireplace($word, $word_style, $str);
$highlighted = preg_replace($regEx, $word_style, $str); $highlighted = preg_replace($regex, $word_style, $str);
} }
return $highlighted; return $highlighted;
} }
...@@ -422,7 +422,7 @@ function _highlightSearchWord($word, $str) { ...@@ -422,7 +422,7 @@ function _highlightSearchWord($word, $str) {
/** /**
* Handling case sensitivity for the keyword in search results * Handling case sensitivity for the keyword in search results
*/ */
function handlingKeywordCaseSensitivity($word, $str) { function _handlingKeywordCaseSensitivity($word, $str) {
//For search results keyword -- lowercase //For search results keyword -- lowercase
$word_lc = strtolower($word); $word_lc = strtolower($word);
$results = _styleWord($word_lc, $str); $results = _styleWord($word_lc, $str);
...@@ -450,8 +450,8 @@ function handlingKeywordCaseSensitivity($word, $str) { ...@@ -450,8 +450,8 @@ function handlingKeywordCaseSensitivity($word, $str) {
//function _styleWord($word) { //function _styleWord($word) {
function _styleWord($word, $data) { function _styleWord($word, $data) {
$word_style = "<span class='highlight-search-word'>" . $word . "</span>"; $word_style = "<span class='highlight-search-word'>" . $word . "</span>";
$regEx = '\'(?!((<.*?)|(<a.*?)))(\b' . $word . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'s'; $regex = '\'(?!((<.*?)|(<a.*?)))(\b' . $word . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
$highlighted = preg_replace($regEx, $word_style, $data); $highlighted = preg_replace($regex, $word_style, $data);
return $highlighted; return $highlighted;
} }
...@@ -538,6 +538,7 @@ function _keywordSearch($word, $data) { ...@@ -538,6 +538,7 @@ function _keywordSearch($word, $data) {
if (!empty($word) && !empty($str)) { if (!empty($word) && !empty($str)) {
if (strlen($str) >= strlen($word)) { if (strlen($str) >= strlen($word)) {
$s_word = "/" . $word . "/i"; $s_word = "/" . $word . "/i";
//$regEx = '\'(?!((<.*?)|(<a.*?)))(\b' . $word . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'si';
if (preg_match($s_word, $str)) { if (preg_match($s_word, $str)) {
return TRUE; return TRUE;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment