Skip to content

Commit

Permalink
Merge branch 'master' into pagination-urls
Browse files Browse the repository at this point in the history
  • Loading branch information
garethsime committed Mar 10, 2024
2 parents 16c8023 + 7299225 commit d72be84
Show file tree
Hide file tree
Showing 37 changed files with 2,583 additions and 82 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Deploy localdev (PR)
on:
pull_request:
workflow_dispatch:
jobs:
deploy-localdev:
uses: LibriVox/librivox-ansible/.github/workflows/localdev.yaml@master
with:
catalog_git_refspec: ${{ github.ref }}
catalog_git_version: FETCH_HEAD
playbooks_repo: LibriVox/librivox-ansible
playbooks_repo_ref: master
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ application/config/email.php
application/logs/log-*
public_html/librivox-validator-books
public_html/uploads
/vendor/
4 changes: 0 additions & 4 deletions .gitreview

This file was deleted.

8 changes: 8 additions & 0 deletions application/controllers/catalog/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public function __construct()

public function index($author_id)
{
if (empty($author_id)) {
show_404();
}

$this->load->model('author_model');
$this->data['author'] = $this->author_model->get($author_id);

Expand All @@ -34,6 +38,10 @@ function get_results()
$author_id = $input['primary_key'];
$search_order = $input['search_order'];

if (empty($author_id)) {
show_error('A primary_key (author ID) must be supplied', 400);
}

//format offset
$offset = ($input['search_page'] - 1) * CATALOG_RESULT_COUNT;

Expand Down
8 changes: 8 additions & 0 deletions application/controllers/catalog/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public function __construct()

public function index($group_id)
{
if (empty($group_id)) {
show_404();
}

$this->load->model('group_model');
$this->data['group'] = $this->group_model->get($group_id);

Expand All @@ -33,6 +37,10 @@ function get_results()
$input = $this->input->get(null, true);
$group_id = $input['primary_key'];

if (empty($group_id)) {
show_error('A primary_key (group ID) must be supplied', 400);
}

//format offset
$offset = ($input['search_page'] - 1) * CATALOG_RESULT_COUNT;

Expand Down
5 changes: 4 additions & 1 deletion application/controllers/catalog/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public function index($slug)
//$this->data['sections'] = $this->section_model->as_array()->get_many_by(array('project_id'=>$this->data['project']->id));
$this->data['sections'] = $this->section_model->get_full_sections_info($this->data['project']->id);

$this->load->helper('description_html_render');
$this->data['project']->description = _normalize_and_deduplicate_newlines_in_html($this->data['project']->description);

//var_dump($this->data['sections']);
if (!empty($this->data['sections']))
{
Expand Down Expand Up @@ -173,4 +176,4 @@ function _language($language_id)
$this->load->model('language_model');
return $this->language_model->get($language_id)->language;
}
}
}
8 changes: 8 additions & 0 deletions application/controllers/catalog/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public function __construct()

public function index($reader_id)
{
if (empty($reader_id)) {
show_404();
}

$this->load->model('user_model');
$this->data['reader'] = $this->user_model->as_array()->get($reader_id);

Expand Down Expand Up @@ -41,6 +45,10 @@ function get_results()
$reader_id = $input['primary_key'];
$search_order = $input['search_order'];

if (empty($reader_id)) {
show_error('A primary_key (reader ID) must be supplied', 400);
}

//format offset
$offset = ($input['search_page'] - 1) * CATALOG_RESULT_COUNT;

Expand Down
3 changes: 2 additions & 1 deletion application/controllers/private/Iarchive_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public function upload()
//additional params
$this->load->model('author_model');
$this->load->model('keyword_model');
$this->load->helper('description_html_render');

$params['creator'] = $this->author_model->create_author_list($project->id, 'author');
$params['date'] = date('Y-m-d');
$params['subject'] = 'librivox; audiobooks;' . $this->keyword_model->create_keyword_list($project->id);
$params['licenseurl'] = LICENSE_LINK;

$description = $this->_get_full_description($params, $project);
$params['description'] = trim(preg_replace('/\s+/', ' ', $description)); //trims all newlines before placing in header
$params['description'] = _normalize_and_deduplicate_newlines_in_html($description); //Standardizes whitespace, replacing newlines with <br /> tags
$params['language'] = $this->data['language_code'];

// Close db connection before uploading to avoid hogging connections
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/private/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function index($project_id = 0)
if (empty($this->data['project'])) redirect(base_url() . 'private/validator/select_project');

$this->data['project']->full_title = create_full_title($this->data['project']);
$this->data['project']->suggested_title = url_title(replace_accents($this->data['project']->full_title), '_', true);
$this->data['project']->suggested_title = substr(url_title(replace_accents($this->data['project']->full_title), '', true), 0, 39);
$this->data['project']->author_full_name = $this->_get_author_by_project($project_id);
$this->data['project']->author_last_name = $this->_get_author_by_project($project_id, 'last');

Expand Down
35 changes: 35 additions & 0 deletions application/helpers/description_html_render_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* For a while, newlines weren't being rendered properly in the catalog HTML,
* so people put manual <br /> tags into project descriptions. Now, we want to
* render the newlines properly, so we need to try and dedupe a bit so that we
* don't have crazy amounts of whitespace.
*
* Inspired by this post: https://www.darklaunch.com/php-normalize-newlines-line-endings-crlf-cr-lf-unix-windows-mac.html
*
* $description string The description to render as HTML
*/
function _normalize_and_deduplicate_newlines_in_html($description) {
// Normalise everything to '\n' characters
$description = preg_replace(
array("/<br ?\/?>\r?\n?/i", "/\r\n?/"),
"\n",
$description
);

// Replace suspiciously-long strings of newlines
$description = preg_replace(
"/\n{3,}/",
"\n\n",
$description,
);

// Turn the newlines into '<br />' tags
// return nl2br($description);
return str_replace(
"\n",
"<br />",
$description,
);
}
65 changes: 18 additions & 47 deletions application/libraries/Librivox_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,7 @@ private function _get_projects_by_author($author)
AND a.linked_to = 0 ';
$author_like = "%$author%";
$query = $this->db->query($sql, array($author_like, $author_like));

// why the zero, you ask? makes sure our IN clause always has a value for valid sql
$project_ids[0] = 0;
foreach ($query->result() as $key => $value) {
$project_ids[] = $value->project_id;
}

return $project_ids;
return $this->ids($query, 'project_id');
}


Expand All @@ -350,14 +343,7 @@ private function _get_projects_by_section_author($author)
AND a.linked_to = 0 ';
$author_like = "%$author%";
$query = $this->db->query($sql, array($author_like, $author_like));

$project_ids[0] = 0;
foreach ($query->result() as $key => $value) {
$project_ids[] = $value->source_id;
}

return $project_ids;

return $this->ids($query, 'source_id');
}


Expand All @@ -376,13 +362,7 @@ private function _get_author_ids($author)
AND a.linked_to = 0 ';
$author_like = "%$author%";
$query = $this->db->query($sql, array($author_like, $author_like));

$author_ids[0] = 0;
foreach ($query->result() as $key => $value) {
$author_ids[] = $value->id;
}

return $author_ids;
return $this->ids($query);
}

private function _get_reader_ids($reader, $exact_match)
Expand All @@ -393,14 +373,7 @@ private function _get_reader_ids($reader, $exact_match)
OR u.username LIKE ?';
$reader_like = $exact_match ? $reader : "%$reader%";
$query = $this->db->query($sql, array($reader_like, $reader_like));

$reader_ids[0] = 0;
foreach ($query->result() as $key => $value) {
$reader_ids[] = $value->id;
}

return $reader_ids;

return $this->ids($query);
}


Expand All @@ -410,14 +383,7 @@ private function _get_projects_by_section_language($language_id)
FROM search_table st
WHERE section_language_id = ? ';
$query = $this->db->query($sql, array($language_id));

$project_ids[0] = 0;
foreach ($query->result() as $key => $value) {
$project_ids[] = $value->source_id;
}

return $project_ids;

return $this->ids($query, 'source_id');
}


Expand All @@ -429,16 +395,21 @@ private function _get_projects_by_reader($reader, $exact_match)
OR pr.username LIKE ?';
$reader_like = $exact_match ? $reader : "%$reader%";
$query = $this->db->query($sql, array($reader_like, $reader_like));
return $this->ids($query, 'project_id');
}

//echo $this->db->last_query();

$project_ids[0] = 0;
foreach ($query->result() as $key => $value) {
$project_ids[] = $value->project_id;
private function ids($query, $id_column = 'id')
{
$ids = [];
foreach ($query->result('array') as $key => $value)
{
$ids[] = $value[$id_column];
}

return $project_ids;
if (empty($ids))
{
$ids[] = 0; // To prevent SQL syntax errors of the form "WHERE id IN ()".
}
return $ids;
}


}
4 changes: 4 additions & 0 deletions application/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_ci_phpunit_test/tmp/
.phpunit.cache
.phpunit.result.cache
build
Loading

0 comments on commit d72be84

Please sign in to comment.