Skip to content

Commit

Permalink
Merge pull request #4 from jjwatts/master
Browse files Browse the repository at this point in the history
Minor fixes including common page title prefix, addition of recents controller for AJAX based recents list, search facet URL decoding fix.
  • Loading branch information
stuartlewis committed Jul 26, 2013
2 parents bd5287a + 59aec42 commit 24b7bd1
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 138 deletions.
3 changes: 3 additions & 0 deletions application/config/sites/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@
$config['skylight_language_default'] = 'en';
$config['skylight_language_options'] = array('en', 'ko', 'jp');

// Common title prefix
$config['skylight_page_title_prefix'] = "Skylight: ";

?>
135 changes: 80 additions & 55 deletions application/controllers/advanced.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,82 @@ function Advanced() {
}

function _remap($path, $params = array()) {

$filterurl = "";
$form = form_open('advanced/post');
$form = form_open('advanced/post');

$search_fields = $this->config->item('skylight_search_fields');
// Determine the page title and heading.
$page_title_prefix = $this->config->item('skylight_page_title_prefix');
if( !isset($page_title_prefix) ) {
$page_title_prefix = "";
}

foreach($search_fields as $key => $value) {
$search_fields = $this->config->item('skylight_search_fields');

$escaped_key = $this->_escape($key);

$input_data = array(
'name' => $escaped_key,
'id' => $escaped_key,
'style' => 'margin-left: 15px;'
);
foreach($search_fields as $key => $value) {

$form .= '<p>';
$escaped_key = $this->_escape($key);

$form .= form_label($key, $escaped_key, array('style' => 'width: 100px; float: left; display: block; text-align: right;'));
$input_data = array(
'name' => $escaped_key,
'id' => $escaped_key,
'style' => 'margin-left: 15px;'
);

if (substr($value, 0, 8) === 'dropdown') {
if (isset($_SESSION['skylight_language'])) {
$lang = $_SESSION['skylight_language'];
} else {
$lang = '';
}
$form .= '<p>';

$form .= form_label($key, $escaped_key, array('style' => 'width: 100px; float: left; display: block; text-align: right;'));

if (substr($value, 0, 8) === 'dropdown') {
if (isset($_SESSION['skylight_language'])) {
$lang = $_SESSION['skylight_language'];
} else {
$lang = '';
}

if (($lang != '') && (is_array($this->config->item($value . '.' . $lang)))) {
$options = $this->config->item($value . '.' . $lang);
} else {
$options = $this->config->item($value);
}

if (($lang != '') && (is_array($this->config->item($value . '.' . $lang)))) {
$options = $this->config->item($value . '.' . $lang);
} else {
$options = $this->config->item($value);
$encodedOptions = array();

if(is_array($options)) {
foreach($options as $key => $value) {
$encodedOptions[urlencode($key)] = $value;
}
$form .= form_dropdown($escaped_key, $options, '', 'style="margin-left:15px;"');
} else {
$form .= form_input($input_data);
}
} else {
$encodedOptions = $options;
}

$form .= '</p>';
}
$form .= '<p>'.form_label('Default search operator', 'operators', array('style' => 'width: 100px; float: left; display: block; text-align: right;'));
$operators = array('OR' => 'OR (any terms may match)','AND' => 'AND (all terms must match)');
$form .= form_dropdown('operator',$operators,'OR','style="margin-left:15px;"').'</p>';
$form .= '<p style="margin-left: 120px;"><em>Use <strong>AND</strong> for narrow searches and <strong>OR</strong> for broad searches</em></p>';
$form .= form_submit('search', 'Search', 'style="margin-left: 120px" class="btn"');
$form .= '</form>';
$form .= form_dropdown($escaped_key, $encodedOptions, '', 'style="margin-left:15px;"');
} else {

$form .= form_input($input_data);
}

$form .= '</p>';
}
$form .= '<p>'.form_label('Default search operator', 'operators', array('style' => 'width: 100px; float: left; display: block; text-align: right;'));
$operators = array('OR' => 'OR (any terms may match)','AND' => 'AND (all terms must match)');
$form .= form_dropdown('operator',$operators,'OR','style="margin-left:15px;"').'</p>';
$form .= '<p style="margin-left: 120px;"><em>Use <strong>AND</strong> for narrow searches and <strong>OR</strong> for broad searches</em></p>';
$form .= form_submit('search', 'Search', 'style="margin-left: 120px" class="btn"');
$form .= '</form>';


if ((empty($path)) || ($path == 'index')) {
redirect(base_url().'/advanced/form');
}
else if($path == 'form') {


$formdata['form'] = $form;
$formdata['formhidden'] = false;

// Set the page title to the record title
$data['page_title'] = 'Advanced Search';
$data['page_title'] = $page_title_prefix.'Advanced Search';
$this->view('header', $data);
$this->view('div_main');
$this->view('advanced_search',$formdata);
Expand All @@ -87,14 +106,12 @@ function _remap($path, $params = array()) {
$filters = '';
$filterurl = '';

// $delimiter = $this->config->item('skylight_filter_delimiter');
// $recorddisplay = $this->config->item('skylight_recorddisplay');
// $rows = $this->config->item('skylight_results_per_page');
// $title = $recorddisplay['Title'];
// $delimiter = $this->config->item('skylight_filter_delimiter');
// $recorddisplay = $this->config->item('skylight_recorddisplay');
// $rows = $this->config->item('skylight_results_per_page');
// $title = $recorddisplay['Title'];

//print_r($search_fields);
foreach($search_fields as $label => $field) {
// print_r($label);
$dcfield = $this->skylight_utilities->getRawField($label);

$val = $this->input->post($this->_escape($label));
Expand All @@ -104,18 +121,14 @@ function _remap($path, $params = array()) {
}
}



$operator = $this->input->post('operator');
// Base search URL
redirect(base_url().'./advanced/search'.$filterurl.'?operator='.$operator);



// Base search URL
redirect(base_url().'/advanced/search'.$filterurl.'?operator='.$operator);
}
else if($path == 'search') {

$query = '';
$query = '';
$operator = $this->input->get('operator');
$offset = $this->input->get('offset');
$sort_by = $this->input->get('sort_by');
Expand All @@ -142,13 +155,16 @@ function _remap($path, $params = array()) {
$url_filters = array();
$message = '<h3>Currently searching the following fields:</h3>';
$filter_message = '';

if(count($this->uri->segments) > 2) {

for($i = 3; $i <= count($this->uri->segments); $i++) {
$test_filter = $this->uri->segments[$i];
if(preg_match('#%7C%7C%7C#',$test_filter)) {
$url_filters[] = $test_filter;
$filter_segments = preg_split("/$delimiter/",$test_filter, 2);
$filter_segments[0] = urldecode($filter_segments[0]);

if(array_key_exists($filter_segments[0], $configured_filters)) {
$saved_filters[] = $configured_filters[$filter_segments[0]].$delimiter.$filter_segments[1];
$display_value = preg_split("#%7C%7C%7C#",$filter_segments[1],2);
Expand Down Expand Up @@ -184,9 +200,8 @@ function _remap($path, $params = array()) {
}



// Base search URL
$base_search = './advanced/search';
$base_search = base_url().'/advanced/search';
foreach($url_filters as $url_filter) {
$base_search .= '/'.$url_filter;
}
Expand All @@ -204,18 +219,30 @@ function _remap($path, $params = array()) {
$data['sort_options'] = $sort_options;
// Variables to populate the search box
$data['searchbox_query'] = $query;
if (($data['searchbox_query'] == '*') || ($data['searchbox_query'] == '*:*')) $data['searchbox_query'] = '';
if (($data['searchbox_query'] == '*') || ($data['searchbox_query'] == '*:*')) {
$data['searchbox_query'] = '';
}
$data['searchbox_filters'] = $saved_filters;

$data['form'] = $form;
$data['formhidden'] = true;

$data['message'] = $message;


$decodedQuery = urldecode($query);
if( $decodedQuery !== "*:*" && $decodedQuery !== "*" && $decodedQuery !== "" ) {
$data['page_title'] = $page_title_prefix.'Search results for "'.$decodedQuery.'"';
$data['page_heading'] = 'Search results for "<span class=searched>'.$decodedQuery.'</span>"';
} else {
$data['page_title'] = $page_title_prefix.'Search Results';
$data['page_heading'] = 'Search Results"';
}


// Check for zero results
$result_count = $data['rows'];
if ($result_count == 0) {
$data['page_title'] = 'No search results found!';
$this->view('header', $data);
$this->view('div_main');
$this->view('advanced_search',$data);
Expand Down Expand Up @@ -246,8 +273,6 @@ function _remap($path, $params = array()) {
else
$data['endrow'] = $data['startrow'] + ($rows - 1);

// Set the page title to the record title
$data['page_title'] = 'Search results for "<span class=searched>'.urldecode($query).'</span>"';
$data['title_field'] = $title;
$data['author_field'] = $title = $this->skylight_utilities->getField('Author');
$data['fielddisplay'] = $this->config->item("skylight_searchresult_display");
Expand All @@ -272,4 +297,4 @@ function _remap($path, $params = array()) {
$this->view('footer');
}
}
}
}
24 changes: 15 additions & 9 deletions application/controllers/browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function _remap($field, $params = array()) {
$delimiter = $this->config->item('skylight_filter_delimiter');
$rows = 30;
$recorddisplay = $this->config->item('skylight_recorddisplay');
// $title = $recorddisplay['Title'];
//$title = $recorddisplay['Title'];

$saved_filters = array();
$url_filters = array();
Expand All @@ -35,10 +35,8 @@ function _remap($field, $params = array()) {
}
}


$offset = $this->input->get('offset');
$prefix = $this->input->get('prefix');
// echo "PREFIX IS $prefix";


// Base search URL
Expand All @@ -47,17 +45,25 @@ function _remap($field, $params = array()) {
$base_search .= '/'.$url_filter;
}

$decodedField = urldecode($field);

// Solr query business moved to solr_client library
$data = $this->solr_client->browseTerms($field, $rows, $offset, $prefix);
$data = $this->solr_client->browseTerms($decodedField, $rows, $offset, $prefix);


// Determine the page title and heading.
$page_title_prefix = $this->config->item('skylight_page_title_prefix');
if( !isset($page_title_prefix) ) {
$page_title_prefix = "";
}

// Check for zero results
$result_count = $data['rows'];
$facet_count = $data['facet']['termcount'];

if ($result_count == 0) {
$data['page_title'] = 'No search results found!';
$this->view('header', $data);
$data['page_title'] = $page_title_prefix.'Browse "'. $decodedField . '"';
$this->view('header', $data);
$this->view('div_main');
$this->view('search_noresults');
$this->view('div_main_end');
Expand All @@ -79,8 +85,8 @@ function _remap($field, $params = array()) {
$data['endrow'] = $data['startrow'] + ($rows - 1);

// Set the page title to the record title
$data['page_title'] = 'Browsing '.$field.' terms';
$data['browse_url'] = $browse_url;
$data['page_title'] = $page_title_prefix.'Browse "'. $decodedField . '"';
$data['browse_url'] = $browse_url;
$data['field'] = $field;
$data['offset'] = $offset;

Expand All @@ -104,4 +110,4 @@ function _remap($field, $params = array()) {
$this->view('div_sidebar_end');
$this->view('footer');
}
}
}
10 changes: 8 additions & 2 deletions application/controllers/feedback.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ function Feedback() {
public function index() {
$data['recaptcha_key_public'] = $this->config->item('skylight_recaptcha_key_public');

$data['page_title'] = 'Feedback';
// Determine the page title and heading.
$page_title_prefix = $this->config->item('skylight_page_title_prefix');
if( !isset($page_title_prefix) ) {
$page_title_prefix = "";
}

$data['page_title'] = $page_title_prefix.'Feedback';

$this->view('header', $data);
$this->view('div_main');
Expand Down Expand Up @@ -58,4 +64,4 @@ function _check_captcha($input) {
}

}
}
}
49 changes: 49 additions & 0 deletions application/controllers/recent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once('skylight.php');

class Recent extends skylight {

function Recent() {
// Initalise the parent
parent::__construct();
}

function _remap($query, $params = array()) {

$configured_fields = $this->config->item('skylight_fields');
$configured_filters = $this->config->item('skylight_filters');
$configured_date_filters = $this->config->item('skylight_date_filters');
$delimiter = $this->config->item('skylight_filter_delimiter');
$recorddisplay = $this->config->item('skylight_recorddisplay');
$display_thumbnail = $this->config->item('skylight_display_thumbnail');
$thumbnail_field = $this->config->item('skylight_thumbnail_field');

// TODO: get rid of this, it's bad
$title = $this->skylight_utilities->getField('Title');

$recentitems = $this->solr_client->getRecentItems();
$data['recentitems'] = $recentitems['recent_items'];
$data['fielddisplay'] = $this->config->item("skylight_searchresult_display");
$data['delimiter'] = $delimiter;

// Check for zero results
if (count($recentitems['recent_items']) == 0) {
$this->view('recent_items_none');
return;
}

if(array_key_exists('Author', $recorddisplay)) {
$data['author_field'] = $recorddisplay['Author'];
} else {
$data['author_field'] = 'dccreator';
}

$data['hide_header'] = true;
$data['display_thumbnail'] = $display_thumbnail;
$data['thumbnail_field'] = 'solr_'.str_replace('.','',$thumbnail_field);
$this->view('recent_items', $data);
}


}
Loading

0 comments on commit 24b7bd1

Please sign in to comment.