Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
library
uw_lib_refshelf
Commits
ac707d00
Commit
ac707d00
authored
Jan 15, 2018
by
Ganesharatnam
Browse files
Clean script
parent
6fbe001b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
52 deletions
+51
-52
uw_lib_refshelf.module
uw_lib_refshelf.module
+51
-52
No files found.
uw_lib_refshelf.module
View file @
ac707d00
...
@@ -101,6 +101,7 @@ function uw_lib_refshelf_form_submit($form, &$form_state) {
...
@@ -101,6 +101,7 @@ function uw_lib_refshelf_form_submit($form, &$form_state) {
/**
/**
* Page callback calling from uw_lib_refshelf_menu()
* Page callback calling from uw_lib_refshelf_menu()
*/
*/
//function uw_lib_refshelf_render_data() {
function
uw_lib_refshelf_render_data
()
{
function
uw_lib_refshelf_render_data
()
{
$content
=
""
;
$content
=
""
;
$links
=
""
;
$links
=
""
;
...
@@ -118,19 +119,19 @@ function uw_lib_refshelf_render_data() {
...
@@ -118,19 +119,19 @@ function uw_lib_refshelf_render_data() {
$tit
=
""
;
$tit
=
""
;
$cat_id
=
$filter_cat_id
;
$cat_id
=
$filter_cat_id
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$parent_data
=
_getData
(
$cat_id
,
$url
);
$parent_data
=
_getData
ORS
(
$cat_id
,
$url
);
$element
=
$parent_data
[
'data'
];
$element
=
$parent_data
[
'data'
];
if
(
!
empty
(
$element
))
{
if
(
!
empty
(
$element
))
{
$tit
=
$element
[
0
][
'name'
];
$tit
=
$element
[
0
][
'name'
];
_setBreadCrumbs
(
"cat_id"
,
$cat_id
,
$tit
,
0
);
_setBreadCrumbs
ORS
(
"cat_id"
,
$cat_id
,
$tit
,
0
);
}
}
$txt
=
"<h2>"
.
$tit
.
"</h2><br />"
;
$txt
=
"<h2>"
.
$tit
.
"</h2><br />"
;
$_SESSION
[
'tit'
]
=
$txt
;
$_SESSION
[
'tit'
]
=
$txt
;
$qparam
=
$cat_id
;
$qparam
=
$cat_id
;
$cat_links
=
_getLinkAndDesc
(
$qparam
,
"toc_id"
);
$cat_links
=
_getLinkAndDesc
ORS
(
$qparam
,
"toc_id"
);
if
(
$cat_links
==
"No data for this parameter"
)
{
if
(
$cat_links
==
"No data for this parameter"
)
{
$txt
=
"<h2>Resources for "
.
$tit
.
"</h2><br />"
;
$txt
=
"<h2>Resources for "
.
$tit
.
"</h2><br />"
;
$resources
=
_getLinkAndDesc
(
$qparam
,
"resources"
);
$resources
=
_getLinkAndDesc
ORS
(
$qparam
,
"resources"
);
$content
.
=
$txt
;
$content
.
=
$txt
;
$content
.
=
$resources
;
$content
.
=
$resources
;
}
}
...
@@ -145,12 +146,12 @@ function uw_lib_refshelf_render_data() {
...
@@ -145,12 +146,12 @@ function uw_lib_refshelf_render_data() {
$tit
=
""
;
$tit
=
""
;
$toc_id
=
$filter_toc_id
;
$toc_id
=
$filter_toc_id
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$parent_data
=
_getData
(
$toc_id
,
$url
);
$parent_data
=
_getData
ORS
(
$toc_id
,
$url
);
$element
=
$parent_data
[
'data'
];
$element
=
$parent_data
[
'data'
];
if
(
!
empty
(
$element
))
{
if
(
!
empty
(
$element
))
{
$parent_id
=
$element
[
0
][
'parent_category'
];
$parent_id
=
$element
[
0
][
'parent_category'
];
$tit
=
$element
[
0
][
'name'
];
$tit
=
$element
[
0
][
'name'
];
_setBreadCrumbs
(
"toc_id"
,
$toc_id
,
$tit
,
$parent_id
);
_setBreadCrumbs
ORS
(
"toc_id"
,
$toc_id
,
$tit
,
$parent_id
);
}
}
if
(
isset
(
$_SESSION
[
'tit'
])
&&
!
empty
(
$_SESSION
[
'tit'
]))
{
if
(
isset
(
$_SESSION
[
'tit'
])
&&
!
empty
(
$_SESSION
[
'tit'
]))
{
$content
.
=
$_SESSION
[
'tit'
];
$content
.
=
$_SESSION
[
'tit'
];
...
@@ -158,13 +159,13 @@ function uw_lib_refshelf_render_data() {
...
@@ -158,13 +159,13 @@ function uw_lib_refshelf_render_data() {
}
}
//$content .= $txt;
//$content .= $txt;
$qparam
=
$toc_id
;
$qparam
=
$toc_id
;
$content
.
=
_getLinkAndDesc
(
$qparam
,
"resources"
);
$content
.
=
_getLinkAndDesc
ORS
(
$qparam
,
"resources"
);
}
}
}
}
else
{
else
{
if
(
isset
(
$filter_pagenum
))
{
if
(
isset
(
$filter_pagenum
))
{
//Pagination view
//Pagination view
_setBreadCrumbs
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
_setBreadCrumbs
ORS
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
$search_res
=
""
;
$search_res
=
""
;
$rec_limit
=
0
;
$rec_limit
=
0
;
$pagenum
=
$filter_pagenum
+
1
;
$pagenum
=
$filter_pagenum
+
1
;
...
@@ -172,7 +173,7 @@ function uw_lib_refshelf_render_data() {
...
@@ -172,7 +173,7 @@ function uw_lib_refshelf_render_data() {
if
(
isset
(
$_SESSION
[
'search_results'
])
&&
isset
(
$_SESSION
[
'search_word'
]))
{
if
(
isset
(
$_SESSION
[
'search_results'
])
&&
isset
(
$_SESSION
[
'search_word'
]))
{
$stored_search_results
=
$_SESSION
[
'search_results'
];
$stored_search_results
=
$_SESSION
[
'search_results'
];
$word
=
$_SESSION
[
'search_word'
];
$word
=
$_SESSION
[
'search_word'
];
$search_res
.
=
_viewSearchResults
(
$stored_search_results
,
$word
,
$pagenum
,
$offset
);
$search_res
.
=
_viewSearchResults
ORS
(
$stored_search_results
,
$word
,
$pagenum
,
$offset
);
$content
=
$search_res
;
$content
=
$search_res
;
}
}
else
{
else
{
...
@@ -181,24 +182,24 @@ function uw_lib_refshelf_render_data() {
...
@@ -181,24 +182,24 @@ function uw_lib_refshelf_render_data() {
}
}
elseif
(
isset
(
$filter_search
))
{
elseif
(
isset
(
$filter_search
))
{
//Search results
//Search results
_setBreadCrumbs
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
_setBreadCrumbs
ORS
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
$word
=
$filter_search
;
$word
=
$filter_search
;
$word
=
_filterSearchWord
(
$word
);
$word
=
_filterSearchWord
ORS
(
$word
);
$str_len
=
strlen
(
$word
);
$str_len
=
strlen
(
$word
);
if
(
$str_len
<
3
)
{
if
(
$str_len
<
3
)
{
$content
=
'<p><b>Please enter a valid keyword for search (not characters)</b></p>'
;
$content
=
'<p><b>Please enter a valid keyword for search (not characters)</b></p>'
;
}
}
else
{
else
{
$content
=
_refshelfDataSearch
(
$word
);
$content
=
_refshelfDataSearch
ORS
(
$word
);
}
}
}
}
else
{
else
{
//Displaying the top level categories
//Displaying the top level categories
_setBreadCrumbs
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
_setBreadCrumbs
ORS
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
$content
=
'<p>Find answers to quick factual questions in the online resources below.</p>'
;
$content
=
'<p>Find answers to quick factual questions in the online resources below.</p>'
;
$content
.
=
'<h2>Browse by category</h2><br />'
;
$content
.
=
'<h2>Browse by category</h2><br />'
;
$param
=
0
;
$param
=
0
;
$content
.
=
_getLinkAndDesc
(
$param
,
"cat_id"
);
$content
.
=
_getLinkAndDesc
ORS
(
$param
,
"cat_id"
);
}
}
}
}
return
$content
;
return
$content
;
...
@@ -208,7 +209,7 @@ function uw_lib_refshelf_render_data() {
...
@@ -208,7 +209,7 @@ function uw_lib_refshelf_render_data() {
* Get the data for appropriate URL and params
* Get the data for appropriate URL and params
* Converts an HTML-safe JSON string into its PHP equivalent
* Converts an HTML-safe JSON string into its PHP equivalent
*/
*/
function
_getData
(
$param
,
$url
)
{
function
_getData
ORS
(
$param
,
$url
)
{
$uri
=
$url
.
$param
;
$uri
=
$url
.
$param
;
$file_headers
=
@
get_headers
(
$uri
);
$file_headers
=
@
get_headers
(
$uri
);
if
(
!
$file_headers
||
$file_headers
[
0
]
==
'HTTP/1.1 404 Not Found'
)
{
if
(
!
$file_headers
||
$file_headers
[
0
]
==
'HTTP/1.1 404 Not Found'
)
{
...
@@ -228,14 +229,14 @@ function _getData($param, $url) {
...
@@ -228,14 +229,14 @@ function _getData($param, $url) {
/**
/**
* get the data and manipulate the fields
* get the data and manipulate the fields
*/
*/
function
_getLinkAndDesc
(
$param
,
$str
)
{
function
_getLinkAndDesc
ORS
(
$param
,
$str
)
{
if
(
$str
==
'resources'
)
{
if
(
$str
==
'resources'
)
{
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/resources/category/"
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/resources/category/"
;
}
}
else
{
else
{
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/parent/"
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/parent/"
;
}
}
$param_data
=
_getData
(
$param
,
$url
);
$param_data
=
_getData
ORS
(
$param
,
$url
);
$content
=
""
;
$content
=
""
;
$link
=
""
;
$link
=
""
;
$desc
=
""
;
$desc
=
""
;
...
@@ -248,7 +249,7 @@ function _getLinkAndDesc($param, $str) {
...
@@ -248,7 +249,7 @@ function _getLinkAndDesc($param, $str) {
$link_url
=
$element
[
'url'
];
$link_url
=
$element
[
'url'
];
if
(
isset
(
$element
[
'is_restricted_resource'
]))
{
if
(
isset
(
$element
[
'is_restricted_resource'
]))
{
$restricted
=
$element
[
'is_restricted_resource'
];
$restricted
=
$element
[
'is_restricted_resource'
];
$link_url
=
_filterRestrictedResource
(
$restricted
,
$link_url
);
$link_url
=
_filterRestrictedResource
ORS
(
$restricted
,
$link_url
);
}
}
}
}
else
{
else
{
...
@@ -274,7 +275,7 @@ function _getLinkAndDesc($param, $str) {
...
@@ -274,7 +275,7 @@ function _getLinkAndDesc($param, $str) {
/**
/**
* breadcrumbs
* breadcrumbs
*/
*/
function
_setBreadCrumbs
(
$str
,
$id
,
$title
,
$parent_id
)
{
function
_setBreadCrumbs
ORS
(
$str
,
$id
,
$title
,
$parent_id
)
{
$breadcrumb
=
drupal_get_breadcrumb
();
$breadcrumb
=
drupal_get_breadcrumb
();
$main_title
=
drupal_get_title
();
$main_title
=
drupal_get_title
();
$main_title_link
=
'<a href="online-reference-shelf">'
.
$main_title
.
'</a>'
;
$main_title_link
=
'<a href="online-reference-shelf">'
.
$main_title
.
'</a>'
;
...
@@ -293,7 +294,7 @@ function _setBreadCrumbs($str, $id, $title, $parent_id) {
...
@@ -293,7 +294,7 @@ function _setBreadCrumbs($str, $id, $title, $parent_id) {
elseif
(
$str
==
"toc_id"
)
{
elseif
(
$str
==
"toc_id"
)
{
$breadcrumb
[]
=
$main_title_link
;
$breadcrumb
[]
=
$main_title_link
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$parent_data
=
_getData
(
$parent_id
,
$url
);
$parent_data
=
_getData
ORS
(
$parent_id
,
$url
);
$element
=
$parent_data
[
'data'
];
$element
=
$parent_data
[
'data'
];
if
(
!
empty
(
$element
))
{
if
(
!
empty
(
$element
))
{
$prev_title
=
$element
[
0
][
'name'
];
$prev_title
=
$element
[
0
][
'name'
];
...
@@ -314,12 +315,12 @@ function _setBreadCrumbs($str, $id, $title, $parent_id) {
...
@@ -314,12 +315,12 @@ function _setBreadCrumbs($str, $id, $title, $parent_id) {
* To get the appropriate search results for different parameters
* To get the appropriate search results for different parameters
* In this case searching in description and name fields
* In this case searching in description and name fields
*/
*/
function
_refshelfDataSearch
(
$word
)
{
function
_refshelfDataSearch
ORS
(
$word
)
{
$content
=
""
;
$content
=
""
;
$param
=
""
;
$param
=
""
;
$all
=
array
();
$all
=
array
();
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/resources/"
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/resources/"
;
$param_data
=
_getData
(
$param
,
$url
);
$param_data
=
_getData
ORS
(
$param
,
$url
);
$elements
=
$param_data
[
'data'
];
$elements
=
$param_data
[
'data'
];
if
(
!
empty
(
$elements
))
{
if
(
!
empty
(
$elements
))
{
foreach
(
$elements
as
$element
)
{
foreach
(
$elements
as
$element
)
{
...
@@ -327,20 +328,20 @@ function _refshelfDataSearch($word) {
...
@@ -327,20 +328,20 @@ function _refshelfDataSearch($word) {
$link_url
=
(
$element
[
'url'
]);
$link_url
=
(
$element
[
'url'
]);
$desc
=
$element
[
'description'
];
$desc
=
$element
[
'description'
];
$desc_no_tag
=
strip_tags
(
$desc
);
$desc_no_tag
=
strip_tags
(
$desc
);
//$desc = _highlightSearchWord($word, $desc_without_links);
//$desc = _highlightSearchWord
ORS
($word, $desc_without_links);
$restricted
=
$element
[
'is_restricted_resource'
];
$restricted
=
$element
[
'is_restricted_resource'
];
//keyword search in description
//keyword search in description
if
(
isset
(
$element
[
'description'
])
&&
!
empty
(
$element
[
'description'
]))
{
if
(
isset
(
$element
[
'description'
])
&&
!
empty
(
$element
[
'description'
]))
{
$status
=
_keywordSearch
(
$word
,
$desc_no_tag
);
$status
=
_keywordSearch
ORS
(
$word
,
$desc_no_tag
);
$all
[]
=
_processingSearchResults
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
);
$all
[]
=
_processingSearchResults
ORS
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
);
}
}
//keyword search in name
//keyword search in name
if
(
isset
(
$element
[
'name'
])
&&
!
empty
(
$element
[
'name'
]))
{
if
(
isset
(
$element
[
'name'
])
&&
!
empty
(
$element
[
'name'
]))
{
$status
=
_keywordSearch
(
$word
,
$link_name
);
$status
=
_keywordSearch
ORS
(
$word
,
$link_name
);
$all
[]
=
_processingSearchResults
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
);
$all
[]
=
_processingSearchResults
ORS
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
);
}
}
}
}
}
}
...
@@ -350,7 +351,6 @@ function _refshelfDataSearch($word) {
...
@@ -350,7 +351,6 @@ function _refshelfDataSearch($word) {
$actual_records
=
$records_cnt
-
1
;
$actual_records
=
$records_cnt
-
1
;
if
(
$records_cnt
<
25
)
{
if
(
$records_cnt
<
25
)
{
//$msg = "<h3>The following result(s) found for the keyword <span class='highlight-search-word'>" . $word . "</span></h3><br />";
$msg
=
"<h3>The following result(s) found for the keyword <span class='highlight-search-word'>"
.
$word
.
"</span></h3><br />"
;
$msg
=
"<h3>The following result(s) found for the keyword <span class='highlight-search-word'>"
.
$word
.
"</span></h3><br />"
;
if
(
!
empty
(
$no_duplicates
))
{
if
(
!
empty
(
$no_duplicates
))
{
foreach
(
$no_duplicates
as
$result
)
{
foreach
(
$no_duplicates
as
$result
)
{
...
@@ -362,7 +362,6 @@ function _refshelfDataSearch($word) {
...
@@ -362,7 +362,6 @@ function _refshelfDataSearch($word) {
return
$results
;
return
$results
;
}
}
else
{
else
{
//return "<h3>No results found for the keyword <span class='highlight-search-word'>" . $word . "</span></h3>";
$msg
=
"<h3>No results found for the keyword <span class='highlight-search-word'>"
.
$word
.
"</span></h3>"
;
$msg
=
"<h3>No results found for the keyword <span class='highlight-search-word'>"
.
$word
.
"</span></h3>"
;
return
$msg
;
return
$msg
;
}
}
...
@@ -372,7 +371,7 @@ function _refshelfDataSearch($word) {
...
@@ -372,7 +371,7 @@ function _refshelfDataSearch($word) {
$_SESSION
[
'search_word'
]
=
$word
;
$_SESSION
[
'search_word'
]
=
$word
;
$pagenum
=
0
;
$pagenum
=
0
;
$offset
=
0
;
$offset
=
0
;
$view
=
_viewSearchResults
(
$no_duplicates
,
$word
,
$pagenum
,
$offset
);
$view
=
_viewSearchResults
ORS
(
$no_duplicates
,
$word
,
$pagenum
,
$offset
);
return
$view
;
return
$view
;
}
}
}
}
...
@@ -380,7 +379,7 @@ function _refshelfDataSearch($word) {
...
@@ -380,7 +379,7 @@ function _refshelfDataSearch($word) {
/**
/**
Resctriced URL is passed through the proxy
Resctriced URL is passed through the proxy
*/
*/
function
_filterRestrictedResource
(
$restricted
,
$url
)
{
function
_filterRestrictedResource
ORS
(
$restricted
,
$url
)
{
$proxy_url
=
"http://proxy.lib.uwaterloo.ca/login?url="
;
$proxy_url
=
"http://proxy.lib.uwaterloo.ca/login?url="
;
if
(
$restricted
==
1
)
{
if
(
$restricted
==
1
)
{
$link_addr
=
$proxy_url
.
$url
;
$link_addr
=
$proxy_url
.
$url
;
...
@@ -394,20 +393,20 @@ function _filterRestrictedResource($restricted, $url) {
...
@@ -394,20 +393,20 @@ function _filterRestrictedResource($restricted, $url) {
/**
/**
* To highlight the search word in search results
* To highlight the search word in search results
*/
*/
function
_highlightSearchWord
(
$word
,
$str
)
{
function
_highlightSearchWord
ORS
(
$word
,
$str
)
{
$str_uc_first
=
ucfirst
(
$word
);
$str_uc_first
=
ucfirst
(
$word
);
//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
ORS
(
$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
ORS
(
$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
ORS
(
$word
,
$str
);
}
}
else
{
else
{
//Replace exctly like search string
//Replace exctly like search string
...
@@ -422,23 +421,23 @@ function _highlightSearchWord($word, $str) {
...
@@ -422,23 +421,23 @@ 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
ORS
(
$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
ORS
(
$word_lc
,
$str
);
//For search results keyword -- First letter -- uppercase
//For search results keyword -- First letter -- uppercase
$word_ucf
=
ucfirst
(
$word
);
$word_ucf
=
ucfirst
(
$word
);
$results
=
_styleWord
(
$word_ucf
,
$results
);
$results
=
_styleWord
ORS
(
$word_ucf
,
$results
);
//Search results keyword -- uppercase
//Search results keyword -- uppercase
$word_uc
=
strtoupper
(
$word
);
$word_uc
=
strtoupper
(
$word
);
$results
=
_styleWord
(
$word_uc
,
$results
);
$results
=
_styleWord
ORS
(
$word_uc
,
$results
);
if
(
ctype_upper
(
$word
))
{
if
(
ctype_upper
(
$word
))
{
$word_lo
=
strtolower
(
$word
);
$word_lo
=
strtolower
(
$word
);
$str_uc_first
=
ucfirst
(
$word_lo
);
$str_uc_first
=
ucfirst
(
$word_lo
);
$results
=
_styleWord
(
$str_uc_first
,
$results
);
$results
=
_styleWord
ORS
(
$str_uc_first
,
$results
);
}
}
return
$results
;
return
$results
;
...
@@ -447,8 +446,8 @@ function _handlingKeywordCaseSensitivity($word, $str) {
...
@@ -447,8 +446,8 @@ function _handlingKeywordCaseSensitivity($word, $str) {
/**
/**
* Apply the style for search word
* Apply the style for search word
*/
*/
//function _styleWord($word) {
//function _styleWord
ORS
($word) {
function
_styleWord
(
$word
,
$data
)
{
function
_styleWord
ORS
(
$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
);
...
@@ -459,7 +458,7 @@ function _styleWord($word, $data) {
...
@@ -459,7 +458,7 @@ function _styleWord($word, $data) {
/**
/**
* To display the search results with pagination
* To display the search results with pagination
*/
*/
function
_viewSearchResults
(
$no_duplicates
,
$word
,
$pagenum
,
$offset
)
{
function
_viewSearchResults
ORS
(
$no_duplicates
,
$word
,
$pagenum
,
$offset
)
{
$page
=
""
;
$page
=
""
;
$content
=
""
;
$content
=
""
;
$results
=
""
;
$results
=
""
;
...
@@ -491,7 +490,7 @@ function _viewSearchResults($no_duplicates, $word, $pagenum, $offset) {
...
@@ -491,7 +490,7 @@ function _viewSearchResults($no_duplicates, $word, $pagenum, $offset) {
}
}
}
}
}
}
$pagination
=
_pagination
(
$pagenum
,
$left_rec
,
$rec_limit
);
$pagination
=
_pagination
ORS
(
$pagenum
,
$left_rec
,
$rec_limit
);
$content
=
$results
.
$pagination
;
$content
=
$results
.
$pagination
;
return
$content
;
return
$content
;
}
}
...
@@ -499,12 +498,12 @@ function _viewSearchResults($no_duplicates, $word, $pagenum, $offset) {
...
@@ -499,12 +498,12 @@ function _viewSearchResults($no_duplicates, $word, $pagenum, $offset) {
/**
/**
* Formatting the search results to display
* Formatting the search results to display
*/
*/
//function _processingSearchResults($status, $desc, $link_name, $link_url, $word) {
//function _processingSearchResults
ORS
($status, $desc, $link_name, $link_url, $word) {
function
_processingSearchResults
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
)
{
function
_processingSearchResults
ORS
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
)
{
$content
=
""
;
$content
=
""
;
$link_url
=
_filterRestrictedResource
(
$restricted
,
$link_url
);
$link_url
=
_filterRestrictedResource
ORS
(
$restricted
,
$link_url
);
$desc
=
_highlightSearchWord
(
$word
,
$desc
);
$desc
=
_highlightSearchWord
ORS
(
$word
,
$desc
);
$link_name
=
_highlightSearchWord
(
$word
,
$link_name
);
$link_name
=
_highlightSearchWord
ORS
(
$word
,
$link_name
);
if
(
$status
)
{
if
(
$status
)
{
if
(
!
empty
(
$desc
))
{
if
(
!
empty
(
$desc
))
{
...
@@ -521,7 +520,7 @@ function _processingSearchResults($status, $desc, $link_name, $link_url, $word,
...
@@ -521,7 +520,7 @@ function _processingSearchResults($status, $desc, $link_name, $link_url, $word,
/**
/**
* Keyword search in the data array or data string
* Keyword search in the data array or data string
*/
*/
function
_keywordSearch
(
$word
,
$data
)
{
function
_keywordSearch
ORS
(
$word
,
$data
)
{
//For array
//For array
if
(
is_array
(
$data
)
&&
!
empty
(
$data
))
{
if
(
is_array
(
$data
)
&&
!
empty
(
$data
))
{
$data
=
array_map
(
'strtolower'
,
$data
);
$data
=
array_map
(
'strtolower'
,
$data
);
...
@@ -554,7 +553,7 @@ function _keywordSearch($word, $data) {
...
@@ -554,7 +553,7 @@ function _keywordSearch($word, $data) {
/**
/**
* Filter the search word from bad characters
* Filter the search word from bad characters
*/
*/
function
_filterSearchWord
(
$word
)
{
function
_filterSearchWord
ORS
(
$word
)
{
$word
=
trim
(
$word
);
$word
=
trim
(
$word
);
$chars
=
array
(
'/'
,
'\\'
,
'['
,
']'
,
"<"
,
"*"
,
">"
,
"}"
,
"{"
,
"^"
,
"("
,
")"
,
"+"
,
"?"
);
$chars
=
array
(
'/'
,
'\\'
,
'['
,
']'
,
"<"
,
"*"
,
">"
,
"}"
,
"{"
,
"^"
,
"("
,
")"
,
"+"
,
"?"
);
$search_str
=
str_replace
(
$chars
,
''
,
$word
);
$search_str
=
str_replace
(
$chars
,
''
,
$word
);
...
@@ -564,7 +563,7 @@ function _filterSearchWord($word) {
...
@@ -564,7 +563,7 @@ function _filterSearchWord($word) {
/**
/**
* Pagination at the bottom of the search results
* Pagination at the bottom of the search results
*/
*/
function
_pagination
(
$pagenum
,
$left_rec
,
$rec_limit
)
{
function
_pagination
ORS
(
$pagenum
,
$left_rec
,
$rec_limit
)
{
$content
=
""
;
$content
=
""
;
if
(
$left_rec
<
$rec_limit
)
{
if
(
$left_rec
<
$rec_limit
)
{
$last
=
$pagenum
-
2
;
$last
=
$pagenum
-
2
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment