Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
library
uw_lib_refshelf
Commits
b9dea846
Commit
b9dea846
authored
Jan 09, 2018
by
Ganesharatnam
Browse files
clean script
parent
da5f2497
Changes
1
Hide whitespace changes
Inline
Side-by-side
uw_lib_refshelf.module
View file @
b9dea846
...
...
@@ -5,7 +5,6 @@
* also supported by this module.
* Written by Lathangi Ganesh Dec 12, 2017
*/
/*
/**
* Implements hook_menu().
...
...
@@ -58,7 +57,7 @@ function uw_lib_refshelf_block_view($delta = '') {
function
uw_lib_refshelf_form
(
$form
,
&
$form_state
)
{
$txt
=
'<span style="font-size:0.8rem;">test</span>'
;
$form
=
array
(
//
d
efine a simple text field for the "search"
//
D
efine a simple text field for the "search"
'name'
=>
array
(
'#type'
=>
'textfield'
,
'#size'
=>
30
,
...
...
@@ -67,34 +66,13 @@ function uw_lib_refshelf_form($form, &$form_state) {
'#collapsible'
=>
TRUE
,
'#collapsed'
=>
FALSE
,
'#region'
=>
'content'
,
//'#default_value' => '',
//The label that will be placed with the field
//'#title' => t('Search'),
//The description will be placed right below the field
//'#description' => t('Please enter keyword for search'),
//If true the system will perform a simple check on submit
// so that it is never empty
//'#required' => TRUE,
),
//
We d
efine a simple submit button
//
D
efine a simple submit button
'submit'
=>
array
(
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Search'
),
),
);
/*
if (!empty($form_state['results_table'])) {
$form['results_table'] = array(
'#markup' => $form_state['results_table']
);
}
*/
/*
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Search',
);
*/
return
$form
;
}
...
...
@@ -124,6 +102,8 @@ function uw_lib_refshelf_form_submit($form, &$form_state) {
function
uw_lib_refshelf_render_data
()
{
$content
=
""
;
$links
=
""
;
//Sanitize the data from URL
$filter_cat_id
=
isset
(
$_GET
[
'cat_id'
])
?
filter_var
(
$_GET
[
'cat_id'
],
FILTER_SANITIZE_STRING
)
:
NULL
;
$filter_toc_id
=
isset
(
$_GET
[
'toc_id'
])
&&
is_numeric
(
$_GET
[
'toc_id'
])
?
$_GET
[
'toc_id'
]
:
NULL
;
$filter_pagenum
=
isset
(
$_GET
[
'pagenum'
])
?
filter_var
(
$_GET
[
'pagenum'
],
FILTER_SANITIZE_STRING
)
:
NULL
;
...
...
@@ -132,13 +112,15 @@ function uw_lib_refshelf_render_data() {
//Check for cat_id and toc_id in GET
if
(
array_key_exists
(
"cat_id"
,
$_GET
)
||
array_key_exists
(
"toc_id"
,
$_GET
))
{
if
(
isset
(
$filter_cat_id
)
&&
!
empty
(
$filter_cat_id
))
{
//Displaying Subcategories
//Displaying Subcategories
$cat_id
=
$filter_cat_id
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$parent_data
=
_getData
(
$cat_id
,
$url
);
$element
=
$parent_data
[
'data'
];
$tit
=
$element
[
0
][
'name'
];
_setBreadCrumbs
(
"cat_id"
,
$cat_id
,
$tit
,
0
);
$txt
=
"<h2>"
.
$tit
.
"</h2><br />"
;
$_SESSION
[
'tit'
]
=
$txt
;
$qparam
=
$_GET
[
'cat_id'
];
...
...
@@ -147,11 +129,13 @@ function uw_lib_refshelf_render_data() {
$txt
=
"<h2>Resources for "
.
$tit
.
"</h2><br />"
;
$links
.
=
_getLinkAndDesc
(
$qparam
,
"resources"
);
}
$content
.
=
$txt
;
$content
.
=
$links
;
}
elseif
(
isset
(
$filter_toc_id
)
&&
!
empty
(
$filter_toc_id
))
{
//Displaying resources for the subcategories
//Displaying resources for the subcategories
$toc_id
=
$filter_toc_id
;
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/categories/"
;
$parent_data
=
_getData
(
$toc_id
,
$url
);
...
...
@@ -162,13 +146,14 @@ function uw_lib_refshelf_render_data() {
$content
.
=
$_SESSION
[
'tit'
];
$txt
=
"<h3>"
.
$tit
.
"</h3><br />"
;
$content
.
=
$txt
;
$qparam
=
$
_GET
[
'
toc_id
'
]
;
$qparam
=
$
filter_
toc_id
;
$content
.
=
_getLinkAndDesc
(
$qparam
,
"resources"
);
}
}
else
{
else
{
if
(
isset
(
$filter_pagenum
))
{
//Pagination view
//Pagination view
_setBreadCrumbs
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
$search_res
=
""
;
$rec_limit
=
0
;
...
...
@@ -176,12 +161,12 @@ function uw_lib_refshelf_render_data() {
$offset
=
$rec_limit
*
$pagenum
;
$stored_search_results
=
$_SESSION
[
'search_results'
];
$word
=
$_SESSION
[
'search_word'
];
$title
=
$_SESSION
[
'txt'
];
$search_res
.
=
_viewSearchResults
(
$stored_search_results
,
$word
,
$pagenum
,
$offset
);
$content
=
$search_res
;
}
elseif
(
isset
(
$filter_search
))
{
//Search results
//Search results
_setBreadCrumbs
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
$word
=
$filter_search
;
$word
=
_filterSearchWord
(
$word
);
...
...
@@ -194,16 +179,15 @@ function uw_lib_refshelf_render_data() {
}
}
else
{
//Displaying the top level links
//Displaying the top level links
_setBreadCrumbs
(
"none"
,
0
,
"Online Reference Shelf"
,
0
);
$links
=
""
;
$txt
=
'<div><p>Find answers to quick factual questions in the online resources below.</p></div>'
;
$txt
.
=
'<div><h2>Browse by category</h2><br /></div>'
;
$_SESSION
[
'txt'
]
=
$txt
;
$param
=
0
;
$content
.
=
$txt
;
$links
.
=
_getLinkAndDesc
(
$param
,
"cat_id"
);
$_SESSION
[
'top_cat'
]
=
$links
;
$content
.
=
$links
.
'<br \>'
;
}
}
...
...
@@ -259,19 +243,14 @@ function _getLinkAndDesc($param, $str) {
}
}
else
{
//$link_url = "?" . $str . "=" . $id . "&title=" . $link_name;
$link_url
=
"?"
.
$str
.
"="
.
$id
;
}
if
(
isset
(
$element
[
'description'
]))
{
//$page .= '<div><a href="' . $link_url . '" target=\"_blank\">' . $link_name . '</a></div>';
$content
.
=
'<div><a href="'
.
$link_url
.
'">'
.
$link_name
.
'</a></div>'
;
$content
.
=
"<div>"
.
$element
[
'description'
]
.
"</div><br />"
;
}
else
{
if
(
!
empty
(
$link_name
)
&&
!
empty
(
$link_url
))
{
//$page .= '<li><a href="' . $link_url . '">' . $link_name . '</a></li>';
$content
.
=
'<p><a href="'
.
$link_url
.
'">'
.
$link_name
.
'</a></p>'
;
}
}
...
...
@@ -318,8 +297,6 @@ function _refshelfDataSearch($word) {
$content
=
""
;
$param
=
""
;
$all
=
array
();
$url
=
"https://libtextura.uwaterloo.ca/api-auth/v1/refshelf/resources/"
;
$param_data
=
_getData
(
$param
,
$url
);
$elements
=
$param_data
[
'data'
];
...
...
@@ -333,25 +310,21 @@ function _refshelfDataSearch($word) {
//keyword search in description
if
(
isset
(
$element
[
'description'
])
&&
!
empty
(
$element
[
'description'
]))
{
$status
=
_keywordSearch
(
$word
,
$desc
);
//$all[] = _processingSearchResults($status, $desc, $link_name, $link_url, $word);
$all
[]
=
_processingSearchResults
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
);
}
//keyword search in name
if
(
isset
(
$element
[
'name'
])
&&
!
empty
(
$element
[
'name'
]))
{
$status
=
_keywordSearch
(
$word
,
$link_name
);
//$all[] = _processingSearchResults($status, $desc, $link_name, $link_url, $word);
$all
[]
=
_processingSearchResults
(
$status
,
$desc
,
$link_name
,
$link_url
,
$word
,
$restricted
);
}
}
//Eliminate duplicates
$no_duplicates
=
array_unique
(
$all
);
$records_cnt
=
count
(
$no_duplicates
);
$actual_records
=
$records_cnt
-
1
;
if
(
$records_cnt
<
25
)
{
//$msg = "<br /><br /><div><h3>The following " . $actual_records . " result(s) found for the keyword <b>" . $word . "</b></h3></div><br />";
$msg
=
"<h3>The following result(s) found for the keyword <span style='background-color: #ffea30;'>"
.
$word
.
"</span></h3><br />"
;
if
(
!
empty
(
$no_duplicates
))
{
foreach
(
$no_duplicates
as
$result
)
{
...
...
@@ -368,10 +341,10 @@ function _refshelfDataSearch($word) {
}
else
{
$_SESSION
[
'search_results'
]
=
$no_duplicates
;
$_SESSION
[
'search_word'
]
=
$word
;
$pagenum
=
0
;
$offset
=
0
;
$view
=
_viewSearchResults
(
$no_duplicates
,
$word
,
$pagenum
,
$offset
);
$_SESSION
[
'search_word'
]
=
$word
;
return
$view
;
}
}
...
...
@@ -413,19 +386,19 @@ function _highlightSearchWord($word, $str) {
$word_style4
=
"<span style='background-color: #ffea30;'>"
.
$word_uc
.
"</span>"
;
$highlighted
=
str_replace
(
$word_uc
,
$word_style4
,
$highlighted
);
//Replacement for a search keyword all uppercase
//Replacement for a search keyword
--
all uppercase
if
(
ctype_upper
(
$word
))
{
//For search results keyword -- lowercase
$word_uc
=
strtolower
(
$word
);
$word_style3
=
"<span style='background-color: #ffea30;'>"
.
$word_uc
.
"</span>"
;
$highlighted
=
str_replace
(
$word_uc
,
$word_style3
,
$highlighted
);
//For search results keyword -- Firstletter uppercase
//For search results keyword -- First
letter
--
uppercase
$word_ucf
=
ucfirst
(
$word_uc
);
$word_style2
=
"<span style='background-color: #ffea30;'>"
.
$word_ucf
.
"</span>"
;
$highlighted
=
str_replace
(
$word_ucf
,
$word_style2
,
$highlighted
);
}
return
$highlighted
;
// . $highlighted1 . $highlighted2;
return
$highlighted
;
}
/**
...
...
@@ -482,7 +455,6 @@ function _processingSearchResults($status, $desc, $link_name, $link_url, $word,
if
(
!
empty
(
$desc
))
{
$link
=
'<span class="ref_links"><a href="'
.
$link_url
.
'">'
.
$link_name
.
'</a></span>'
;
$content
.
=
$link
.
"<p>"
.
$desc
.
"</p>"
;
//$content .= $link ;//. "<p>" . $desc . "</p>";
}
else
{
$content
.
=
"<p>No results found for the word</p>"
;
...
...
@@ -495,7 +467,7 @@ function _processingSearchResults($status, $desc, $link_name, $link_url, $word,
* Keyword search in the data array or data string
*/
function
_keywordSearch
(
$word
,
$data
)
{
//
if data is
array
//
For
array
if
(
is_array
(
$data
)
&&
!
empty
(
$data
))
{
$data
=
array_map
(
'strtolower'
,
$data
);
if
(
in_array
(
$word
,
$data
))
{
...
...
@@ -505,7 +477,7 @@ function _keywordSearch($word, $data) {
return
FALSE
;
}
}
else
{
else
{
//For String
$str
=
trim
(
$data
);
$str
=
strtolower
(
$data
);
if
(
!
empty
(
$word
)
&&
!
empty
(
$str
))
{
...
...
@@ -527,11 +499,8 @@ function _keywordSearch($word, $data) {
*/
function
_filterSearchWord
(
$word
)
{
$word
=
trim
(
$word
);
//$word = strtolower($word);
$chars
=
array
(
'/'
,
'\\'
);
//$strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
// "}", "\\", "|", ";", ":", "\"", "'", "‘", "’", "“", "”", "–", "—",
// "—", "–", ",", "<", ".", ">", "/", "?");
//$chars = array('/', '\\', '[', ']', "<", "*", ">", "}", "{", "^");
$chars
=
array
(
'/'
,
'\\'
,
'['
,
']'
,
"<"
,
"*"
,
">"
,
"}"
,
"{"
,
"^"
,
"("
,
")"
,
"+"
,
"?"
);
$search_str
=
str_replace
(
$chars
,
''
,
$word
);
return
$search_str
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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