Skip to content

Commit

Permalink
busca interna scielo.org com paginaçao
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon authored and patymori committed Jan 8, 2020
1 parent d73654e commit f9e19c4
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store

docker-compose-local.yml

application/cache/*/Files
!application/cache/index.html
!application/cache/database/data.db
Expand Down
128 changes: 128 additions & 0 deletions application/controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -1211,4 +1211,132 @@ public function redirect_legacy_index_url()
$lang = $this->input->get('lang', 'en');
return redirect($lang . '/', 'location', 301);
}


/**
* Create internal search query
*/
public function search(){

switch ($this->language) {

case SCIELO_LANG:
//$url = WORDPRESS_API_PATH."/swp_api/search?nopaging=true&s=";
$paged_url = WORDPRESS_API_PATH."/swp_api/search?posts_per_page=10&s=";
$url = WORDPRESS_API_PATH."/swp_api/search?nopaging=true&s=";
break;

case SCIELO_EN_LANG:
$paged_url = WORDPRESS_API_PATH_EN."/swp_api/search?posts_per_page=10&s=";
$url = WORDPRESS_API_PATH_EN."/swp_api/search?nopaging=true&s=";
break;

case SCIELO_ES_LANG:
$paged_url = WORDPRESS_API_PATH_ES."/swp_api/search?posts_per_page=10&s=";
$url = WORDPRESS_API_PATH_ES."/swp_api/search?nopaging=true&s=";
break;
}

// receive input value
$q = $this->input->get('q');

// Clear input content to avoid xss
$q = htmlspecialchars(strip_tags($q));

// Rides Json paged url and embodies to accept blank
$paged_json_url = $paged_url.rawurlencode($q);

// Rides Json url and emboda to accept blank
$json_url = $url.rawurlencode($q);

// If page number is posted, assign it in the query. $ this-> uri-> segment (3) represents page number
if($this->uri->segment(3)){
$page_num = $this->uri->segment(3);
$json_url = $json_url."&page=".$page_num;
$paged_json_url = $paged_json_url."&page=".$page_num;
}

// Receive value sent by already formatted search field
$data["query"] = $q;

// Gets json from nonpaged search
$data["json"] = $this->doSearch($q, $json_url);

// gets json from paged search
$data["paged_json"] = $this->doSearch($q, $paged_json_url);


/*
## Making pagination
*/
$this->load->library('pagination');

$scielo_url = ($this->language == SCIELO_LANG) ? base_url($this->language . '/') : base_url();

// Displays total query results for pagination creation
$search_total_rows = count($data["json"]);

// Url to assemble pagination results
$data["url"] = base_url()."home/search/";


// Display number of pages in url and not number of records displayed
$config['use_page_numbers'] = TRUE;

// Keep field values sent via get when reloading page
$config['reuse_query_string'] = TRUE;


// commented because the route was not made for this url/pt
// $config['base_url'] = $scielo_url.'home/search/';
$config['base_url'] = base_url().'home/search';


$config['total_rows'] = $search_total_rows;
$config['per_page'] = 10;

$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';

$config['first_link'] = lang('pagination_first_link');
$config['last_link'] = lang('pagination_last_link');

$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';

$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';

$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';

$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';

$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';

$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';

$this->pagination->initialize($config);
$this->load->view("/pages/search_results", $data);

}

/**
* Internal search query
*/
public function doSearch($q, $json_url){

$rtn = array();
$q = strtolower($q);
$json = file_get_contents($json_url);
$searchResult = json_decode($json,true);
$rtn = $searchResult;

return $rtn;

}

}
15 changes: 15 additions & 0 deletions application/language/english/pagination_lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* System messages translation for CodeIgniter(tm)
*
* @author CodeIgniter community
* @copyright Copyright (c) 2014-2018, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
*/
defined('BASEPATH') OR exit('No direct script access allowed');

$lang['pagination_first_link'] = 'First';
$lang['pagination_next_link'] = '&gt;';
$lang['pagination_prev_link'] = '&lt;';
$lang['pagination_last_link'] = 'Last';
3 changes: 3 additions & 0 deletions application/language/english/scielo_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
$lang['clean_btn'] = 'Clear';
$lang["content_error"] = 'Sorry, this content is currently unavailable';
$lang['with_initial_letter'] = '&nbsp;with the initial letter&nbsp;';
$lang["internal_search_placeholder"] = "Criteria, guides, announcements etc";
$lang['displaying_results_for_term'] = 'Displaying results for term ';
$lang['no_items_found_for_term'] = 'No items found for term ';
$lang['page_not_found_with_details'] = '
This page could not be found. The content you are looking for was probably moved or is no longer available.
<br><br>
Expand Down
4 changes: 2 additions & 2 deletions application/language/portuguese-brazilian/pagination_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
defined('BASEPATH') OR exit('No direct script access allowed');

$lang['pagination_first_link'] = '&lsaquo; Primeiro';
$lang['pagination_first_link'] = 'Primeira';
$lang['pagination_next_link'] = '&gt;';
$lang['pagination_prev_link'] = '&lt;';
$lang['pagination_last_link'] = 'Último &rsaquo;';
$lang['pagination_last_link'] = 'Última';
3 changes: 3 additions & 0 deletions application/language/portuguese-brazilian/scielo_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
$lang['search_btn'] = 'Buscar';
$lang['clean_btn'] = 'Limpar';
$lang["content_error"] = 'Desculpe, este conteúdo está temporariamente indisponível.';
$lang["internal_search_placeholder"] = "Critérios, guias, comunicados etc";
$lang['displaying_results_for_term'] = 'Exibindo resultados para o termo ';
$lang['no_items_found_for_term'] = 'Nenhum item encontrado para o termo ';
$lang['page_not_found_with_details'] = '
Não foi possível encontrar essa página. O conteúdo que você buscou provavelmente foi movido ou não está mais disponível.
<br><br>
Expand Down
4 changes: 2 additions & 2 deletions application/language/spanish/pagination_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
defined('BASEPATH') OR exit('No direct script access allowed');

$lang['pagination_first_link'] = '&lsaquo; Primera';
$lang['pagination_first_link'] = 'Primero';
$lang['pagination_next_link'] = '&gt;';
$lang['pagination_prev_link'] = '&lt;';
$lang['pagination_last_link'] = 'Última &rsaquo;';
$lang['pagination_last_link'] = 'Última';
5 changes: 4 additions & 1 deletion application/language/spanish/scielo_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@
$lang['contains'] = 'Contiene';
$lang['extact_title'] = 'Título exacto';
$lang['starts_with'] = 'Comienza con';
$lang['search_btn'] = 'Buscar';
$lang['search_btn'] = 'Búsqueda';
$lang['clean_btn'] = 'Limpiar';
$lang["content_error"] = 'Lo sentimos, este contenido no está disponible en este momento';
$lang['with_initial_letter'] = '&nbsp;con la letra inicial&nbsp;';
$lang["internal_search_placeholder"] = "Criterios, guías, anuncios, etc.";
$lang['displaying_results_for_term'] = 'Mostrando resultados para el término ';
$lang['no_items_found_for_term'] = 'No se encontraron elementos para el término ';
$lang['page_not_found_with_details'] = '
No se pudo encontrar esta página. El contenido que ha buscado probablemente se ha movido o no está disponible.
<br><br>
Expand Down
2 changes: 2 additions & 0 deletions application/views/pages/accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<section>
<div class="container">

<?php $this->load->view('partials/internal-search-box'); ?>

<div class="page-updated-at">
<?php $date = new DateTime($page['modified']);?>
<?= "(" . lang('updated') . ": " . $date->format('d/m/Y') . ")" ?>
Expand Down
3 changes: 3 additions & 0 deletions application/views/pages/bibliography.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

<section class="collection collectionAbout">
<div class="container">

<?php $this->load->view('partials/internal-search-box'); ?>

<div class="page-updated-at">
<?php $date = new DateTime($page['modified']);?>
<?= "(" . lang('updated') . ": " . $date->format('d/m/Y') . ")" ?>
Expand Down
3 changes: 3 additions & 0 deletions application/views/pages/booklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

<section>
<div class="container">

<?php $this->load->view('partials/internal-search-box'); ?>

<div class="page-updated-at">
<?php $date = new DateTime($page['modified']);?>
<?= "(" . lang('updated') . ": " . $date->format('d/m/Y') . ")" ?>
Expand Down
2 changes: 2 additions & 0 deletions application/views/pages/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<div class="container">
<div class="row">
<div class="col-xs-12 content">

<?php $this->load->view('partials/internal-search-box'); ?>

<div class="page-updated-at">
<?php $date = new DateTime($page['modified']);?>
Expand Down
3 changes: 3 additions & 0 deletions application/views/pages/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

<section class="collection collectionAbout">
<div class="container">

<?php $this->load->view('partials/internal-search-box'); ?>

<?php if (!empty($page['content']['rendered'])) : ?>
<div class="row">
<div class="col-xs-12">
Expand Down
Loading

0 comments on commit f9e19c4

Please sign in to comment.