From dea01bd1025c5367ed59b013e581a21f0d7d6bf4 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Thu, 30 May 2019 20:14:53 +0000 Subject: [PATCH 01/23] Add RSS limit option --- islandora_solr_config/includes/admin.inc | 11 +++++++++-- islandora_solr_config/includes/rss_results.inc | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/islandora_solr_config/includes/admin.inc b/islandora_solr_config/includes/admin.inc index b3a990aa..89288394 100644 --- a/islandora_solr_config/includes/admin.inc +++ b/islandora_solr_config/includes/admin.inc @@ -31,6 +31,7 @@ function islandora_solr_config_admin_rss_settings($form, &$form_state) { 'managingEditor' => '', 'webMaster' => '', )); + $rss_limit = variable_get('islandora_solr_config_rss_limit', 50); $form = array( '#tree' => TRUE, @@ -110,6 +111,12 @@ function islandora_solr_config_admin_rss_settings($form, &$form_state) { '#description' => t('Email address for person responsible for technical issues relating to channel.'), '#default_value' => $rss_channel['webMaster'] ? $rss_channel['webMaster'] : '', ); + $form['rss_limit'] = array( + '#type' => 'textfield', + '#title' => 'RSS results limit', + '#description' => 'Maximum number of results via RSS.', + '#default_value' => $rss_limit, + ); $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('Save'), @@ -120,7 +127,6 @@ function islandora_solr_config_admin_rss_settings($form, &$form_state) { '#value' => t('Reset to defaults'), '#weight' => 51, ); - return $form; } @@ -135,10 +141,11 @@ function islandora_solr_config_admin_rss_settings_submit($form, &$form_state) { // Get values. $rss_item = $form_state['values']['rss_item']; $rss_channel = $form_state['values']['rss_channel']; - + $rss_limit = $form_state['values']['rss_limit']; // Set variable. variable_set('islandora_solr_config_rss_item', $rss_item); variable_set('islandora_solr_config_rss_channel', $rss_channel); + variable_set('islandora_solr_config_rss_limit', $rss_limit); } // On reset. diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index e2c52b26..df45a163 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -31,6 +31,8 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { global $base_url; drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8'); + $islandora_solr_query->solrLimit = variable_get('islandora_solr_config_rss_limit', 50); + $islandora_solr_query->executeQuery(); // Get raw results. $solr_result = $islandora_solr_query->islandoraSolrResult; From 03613bd734a9219eac88bf70d025d228cb3c59e4 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Thu, 30 May 2019 20:52:34 +0000 Subject: [PATCH 02/23] Add variable to install file --- islandora_solr_config/islandora_solr_config.install | 1 + 1 file changed, 1 insertion(+) diff --git a/islandora_solr_config/islandora_solr_config.install b/islandora_solr_config/islandora_solr_config.install index 30889cfd..45095d27 100644 --- a/islandora_solr_config/islandora_solr_config.install +++ b/islandora_solr_config/islandora_solr_config.install @@ -14,6 +14,7 @@ function islandora_solr_config_uninstall() { $variables = array( 'islandora_solr_table_profile_display_row_no', 'islandora_solr_table_profile_table_class', + 'islandora_solr_config_rss_limit', ); foreach ($variables as $variable) { variable_del($variable); From c2e79d4d88632fa010ec504f83f4fcfa43ff152c Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 10 Jun 2019 15:50:31 +0000 Subject: [PATCH 03/23] Add paging to RSS results --- .../includes/rss_results.inc | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index df45a163..2db97336 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -191,7 +191,54 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $result['url'] = $base_url; $result['description'] = t('Aggregated search results of: @query', array('@query' => $query)); $result['langcode'] = NULL; + + $feed_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + if (strpos($feed_url, '&page') == false) { + $page_number = '1'; + } + else { + $arr = explode('&page=', $feed_url); + $page_number = $arr[1]; + } + $link_self = $feed_url; + if (isset($arr)) { + $link_first = $arr[0]; + } + else { + $link_first = $feed_url; + } + $page_next = $page_number + 1; + if ($page_number > 1) { + $page_prev = $page_number - 1; + } + $link_next = $link_first . '&page=' . $page_next; + if (isset($page_prev)) { + $link_prev = $link_first . '&page=' . $page_prev; + } + + $result['args'] = array( + array( + 'key' => 'link', + 'attributes' => array( + 'rel' => 'next', + 'href' => $link_next + ), + ), + array( + 'key' => 'link', + 'attributes' => array( + 'rel' => 'previous', + 'href' => $link_prev + ), + ), + array( + 'key' => 'link', + 'attributes' => array( + 'rel' => 'first', + 'href' => $link_first + ), + ), array( 'key' => 'copyright', 'value' => $rss_channel['copyright']), From e699f4523087b3a698165111cfefdc33470321b3 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 10 Jun 2019 17:17:58 +0000 Subject: [PATCH 04/23] coding standards --- islandora_solr_config/includes/rss_results.inc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 2db97336..9b51ea7a 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -193,7 +193,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $result['langcode'] = NULL; $feed_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; - if (strpos($feed_url, '&page') == false) { + if (strpos($feed_url, '&page') == FALSE) { $page_number = '1'; } else { @@ -216,29 +216,28 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $link_prev = $link_first . '&page=' . $page_prev; } - $result['args'] = array( array( 'key' => 'link', 'attributes' => array( 'rel' => 'next', - 'href' => $link_next + 'href' => $link_next, ), ), array( 'key' => 'link', 'attributes' => array( 'rel' => 'previous', - 'href' => $link_prev + 'href' => $link_prev, ), ), array( 'key' => 'link', 'attributes' => array( 'rel' => 'first', - 'href' => $link_first + 'href' => $link_first, ), - ), + ), array( 'key' => 'copyright', 'value' => $rss_channel['copyright']), From 92cc96bfdec225817fd8d71d033ce5f9d2c6e191 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Wed, 12 Jun 2019 17:29:05 +0000 Subject: [PATCH 05/23] Fix links --- islandora_solr_config/includes/rss_results.inc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 9b51ea7a..160ec347 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -211,7 +211,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { if ($page_number > 1) { $page_prev = $page_number - 1; } - $link_next = $link_first . '&page=' . $page_next; + $link_next = url($link_first . '&page=' . $page_next); if (isset($page_prev)) { $link_prev = $link_first . '&page=' . $page_prev; } @@ -220,23 +220,20 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { array( 'key' => 'link', 'attributes' => array( - 'rel' => 'next', - 'href' => $link_next, - ), + 'rel' => 'next'), + 'value' => $link_next, ), array( 'key' => 'link', 'attributes' => array( - 'rel' => 'previous', - 'href' => $link_prev, - ), + 'rel' => 'previous'), + 'value' => $link_prev, ), array( 'key' => 'link', 'attributes' => array( - 'rel' => 'first', - 'href' => $link_first, - ), + 'rel' => 'first'), + 'value' => $link_first, ), array( 'key' => 'copyright', From 35a65756582afed792e09ae96ac1d7a12f284b51 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Wed, 12 Jun 2019 18:00:24 +0000 Subject: [PATCH 06/23] fix encoding problem --- islandora_solr_config/includes/rss_results.inc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 160ec347..98bd1707 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -77,7 +77,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $channel = $this->rssChannel($query); $rss_attributes = array('version' => '2.0'); drupal_alter('islandora_solr_config_rss_root_element_attributes', $rss_attributes, $channel, $items); - +dd($channel); // Give the results clean variable names. $title = $channel['title']; $url = $channel['url']; @@ -222,18 +222,21 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { 'attributes' => array( 'rel' => 'next'), 'value' => $link_next, + 'encoded' => TRUE, ), array( 'key' => 'link', 'attributes' => array( 'rel' => 'previous'), 'value' => $link_prev, + 'encoded' => TRUE, ), array( 'key' => 'link', 'attributes' => array( 'rel' => 'first'), 'value' => $link_first, + 'encoded' => TRUE; ), array( 'key' => 'copyright', From 730fb698a4b69c4d7e7a4300fe48ee69106bb486 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Wed, 12 Jun 2019 18:01:03 +0000 Subject: [PATCH 07/23] whoops semicolon --- islandora_solr_config/includes/rss_results.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 98bd1707..dba064dc 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -236,7 +236,7 @@ dd($channel); 'attributes' => array( 'rel' => 'first'), 'value' => $link_first, - 'encoded' => TRUE; + 'encoded' => TRUE, ), array( 'key' => 'copyright', From 0a48be6ba3e4504c584298f2e3e126ac214a2f74 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Thu, 13 Jun 2019 19:43:14 +0000 Subject: [PATCH 08/23] Change URL concatenation to drupal url function --- .../includes/rss_results.inc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index dba064dc..a3e824e9 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -77,7 +77,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $channel = $this->rssChannel($query); $rss_attributes = array('version' => '2.0'); drupal_alter('islandora_solr_config_rss_root_element_attributes', $rss_attributes, $channel, $items); -dd($channel); + // Give the results clean variable names. $title = $channel['title']; $url = $channel['url']; @@ -207,13 +207,26 @@ dd($channel); else { $link_first = $feed_url; } + $page_next = $page_number + 1; if ($page_number > 1) { $page_prev = $page_number - 1; } - $link_next = url($link_first . '&page=' . $page_next); + + $next_page = array( + 'query' => array( + 'page' => $page_next, + ), + ); + $link_next = url($link_first, $next_page); + if (isset($page_prev)) { - $link_prev = $link_first . '&page=' . $page_prev; + $prev_page = array( + 'query' => array( + 'page' => $page_prev, + ), + ); + $link_prev = url($link_first, $prev_page); } $result['args'] = array( From 1673240272e88e8b726c9bbb985551ff1dac8440 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Thu, 13 Jun 2019 20:34:49 +0000 Subject: [PATCH 09/23] Use drupal_get_query_parameters for page number --- islandora_solr_config/includes/rss_results.inc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index a3e824e9..dc38840d 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -193,15 +193,17 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $result['langcode'] = NULL; $feed_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; - if (strpos($feed_url, '&page') == FALSE) { + $page_params = drupal_get_query_parameters(); + if (!isset($page_params['page'])) { $page_number = '1'; } else { - $arr = explode('&page=', $feed_url); - $page_number = $arr[1]; + $page_number = $page_params['page']; } $link_self = $feed_url; - if (isset($arr)) { + + if (isset($page_params['page'])) { + $arr = explode('&page=', $feed_url); $link_first = $arr[0]; } else { From a930af2bda6a681d5c9ae1c3e975ad16d715f35b Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Fri, 14 Jun 2019 19:26:45 +0000 Subject: [PATCH 10/23] Drupalize request parsing --- .../includes/rss_results.inc | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index dc38840d..58e39845 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -192,8 +192,9 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $result['description'] = t('Aggregated search results of: @query', array('@query' => $query)); $result['langcode'] = NULL; - $feed_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + $feed_url = request_uri(); $page_params = drupal_get_query_parameters(); + if (!isset($page_params['page'])) { $page_number = '1'; } @@ -203,8 +204,9 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $link_self = $feed_url; if (isset($page_params['page'])) { - $arr = explode('&page=', $feed_url); - $link_first = $arr[0]; +// Problem is here + $page = array(array() + $page_params); + $link_first = url($base_url . "/" . request_path(), $page); } else { $link_first = $feed_url; @@ -218,19 +220,26 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $next_page = array( 'query' => array( 'page' => $page_next, - ), + )+$page_params, ); - $link_next = url($link_first, $next_page); + $link_next = url($base_url . "/" . request_path(), $next_page); if (isset($page_prev)) { $prev_page = array( 'query' => array( 'page' => $page_prev, - ), + )+$page_params, ); - $link_prev = url($link_first, $prev_page); + $link_prev = url($base_url . "/" . request_path(), $prev_page); } +$args = array( + 'query' => array( + 'page' => $page_prev, + ) + $page_params, +); +$link_prev = url($base_url . "/" . request_path(), $args); + $result['args'] = array( array( 'key' => 'link', From 8f694beec5e3c59c4567c5bed69ed52d7ce78110 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 17 Jun 2019 14:08:41 +0000 Subject: [PATCH 11/23] fix page_prev problem --- islandora_solr_config/includes/rss_results.inc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 58e39845..0a01361e 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -204,9 +204,13 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $link_self = $feed_url; if (isset($page_params['page'])) { -// Problem is here - $page = array(array() + $page_params); - $link_first = url($base_url . "/" . request_path(), $page); + $link_first = url( + request_path(), + array( + 'absolute' => TRUE, + 'query' => array('page' => 1) + $page_params, + ) + ); } else { $link_first = $feed_url; @@ -232,14 +236,6 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { ); $link_prev = url($base_url . "/" . request_path(), $prev_page); } - -$args = array( - 'query' => array( - 'page' => $page_prev, - ) + $page_params, -); -$link_prev = url($base_url . "/" . request_path(), $args); - $result['args'] = array( array( 'key' => 'link', From 7da5931f36184977bbe7f1c360c593978c36d805 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 17 Jun 2019 14:11:25 +0000 Subject: [PATCH 12/23] Everything works I think --- islandora_solr_config/includes/rss_results.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 0a01361e..2f37b7a0 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -202,7 +202,6 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $page_number = $page_params['page']; } $link_self = $feed_url; - if (isset($page_params['page'])) { $link_first = url( request_path(), @@ -213,7 +212,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { ); } else { - $link_first = $feed_url; + $link_first = $base_url . $feed_url; } $page_next = $page_number + 1; From 07574b9eee2cd27d91f99a5ebb33b651c9e54de0 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 17 Jun 2019 14:13:06 +0000 Subject: [PATCH 13/23] Remove unused variable --- islandora_solr_config/includes/rss_results.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 2f37b7a0..45f90116 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -201,7 +201,6 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { else { $page_number = $page_params['page']; } - $link_self = $feed_url; if (isset($page_params['page'])) { $link_first = url( request_path(), From 05975b09755a903ae76f8d31d083f608e1b25e58 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 17 Jun 2019 14:28:35 +0000 Subject: [PATCH 14/23] Fix missing variable for link_prev --- islandora_solr_config/includes/rss_results.inc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 45f90116..a5709283 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -234,6 +234,9 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { ); $link_prev = url($base_url . "/" . request_path(), $prev_page); } + else { + $link_prev = ""; + } $result['args'] = array( array( 'key' => 'link', From 59f65b11b075ce3a909356414a599e985e96fc39 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Tue, 18 Jun 2019 18:40:13 +0000 Subject: [PATCH 15/23] Remove page attribute from first page and do not print next link if no next page --- .../includes/rss_results.inc | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index a5709283..d35d9416 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -69,12 +69,11 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { // ... and add to items string. $items .= "$rendered_item\n"; } - // Query search terms: $query = $islandora_solr_query->solrQuery; // Get the variables for the element. - $channel = $this->rssChannel($query); + $channel = $this->rssChannel($query, $docs); $rss_attributes = array('version' => '2.0'); drupal_alter('islandora_solr_config_rss_root_element_attributes', $rss_attributes, $channel, $items); @@ -176,7 +175,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { * @return array * variable that holds all values to be rendered into elements */ - public function rssChannel($query) { + public function rssChannel($query, $docs) { // Set variables. global $base_url; $rss_channel = variable_get('islandora_solr_config_rss_channel', array( @@ -191,7 +190,6 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $result['url'] = $base_url; $result['description'] = t('Aggregated search results of: @query', array('@query' => $query)); $result['langcode'] = NULL; - $feed_url = request_uri(); $page_params = drupal_get_query_parameters(); @@ -202,11 +200,13 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $page_number = $page_params['page']; } if (isset($page_params['page'])) { + $first_params = $page_params; + unset($first_params['page']); $link_first = url( request_path(), array( 'absolute' => TRUE, - 'query' => array('page' => 1) + $page_params, + 'query' => $first_params, ) ); } @@ -224,15 +224,25 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { 'page' => $page_next, )+$page_params, ); - $link_next = url($base_url . "/" . request_path(), $next_page); + + // Only set Next link if there is a next page. + $rss_limit = variable_get('islandora_solr_config_rss_limit', 50); + if (count($docs) == $rss_limit) { + $link_next = url($base_url . "/" . request_path(), $next_page); + } if (isset($page_prev)) { - $prev_page = array( - 'query' => array( - 'page' => $page_prev, - )+$page_params, - ); - $link_prev = url($base_url . "/" . request_path(), $prev_page); + if ($page_prev > 1) { + $prev_page = array( + 'query' => array( + 'page' => $page_prev, + )+$page_params, + ); + $link_prev = url($base_url . "/" . request_path(), $prev_page); + } + else { + $link_prev = $link_first; + } } else { $link_prev = ""; From e6bc6a15de09328aa8613c5b8c60f5d97a783322 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Wed, 19 Jun 2019 14:25:57 +0000 Subject: [PATCH 16/23] Paging starts at zero not one --- islandora_solr_config/includes/rss_results.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index d35d9416..e0b58261 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -194,7 +194,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $page_params = drupal_get_query_parameters(); if (!isset($page_params['page'])) { - $page_number = '1'; + $page_number = '0'; } else { $page_number = $page_params['page']; @@ -215,7 +215,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { } $page_next = $page_number + 1; - if ($page_number > 1) { + if ($page_number > 0) { $page_prev = $page_number - 1; } @@ -232,7 +232,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { } if (isset($page_prev)) { - if ($page_prev > 1) { + if ($page_prev > 0) { $prev_page = array( 'query' => array( 'page' => $page_prev, From 0fb906d1342faffbef368b214a04012258dc3c1e Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Thu, 20 Jun 2019 18:34:20 +0000 Subject: [PATCH 17/23] Make links conditional --- .../includes/rss_results.inc | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index e0b58261..349cb879 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -247,28 +247,35 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { else { $link_prev = ""; } - $result['args'] = array( - array( + $result['args'] = array(); + if (isset($link_next)) { + $result['args'][] = array( 'key' => 'link', 'attributes' => array( 'rel' => 'next'), 'value' => $link_next, 'encoded' => TRUE, - ), - array( + ); + } + if (isset($link_prev)) { + $result['args'][] = array( 'key' => 'link', 'attributes' => array( 'rel' => 'previous'), 'value' => $link_prev, 'encoded' => TRUE, - ), - array( + ); + } + if (isset($link_first)) { + $result['args'][] = array( 'key' => 'link', 'attributes' => array( 'rel' => 'first'), 'value' => $link_first, 'encoded' => TRUE, - ), + ); + } + $final_arguments = array( array( 'key' => 'copyright', 'value' => $rss_channel['copyright']), @@ -279,6 +286,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { 'key' => 'webMaster', 'value' => $rss_channel['webMaster']), ); + $result['args'] = array_merge($result['args'], $final_arguments); return $result; } } From e088ddbb263c045bdc99ce5a6acb2522d66f641e Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Thu, 20 Jun 2019 18:34:56 +0000 Subject: [PATCH 18/23] Remove empty link_prev --- islandora_solr_config/includes/rss_results.inc | 3 --- 1 file changed, 3 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 349cb879..af502ba0 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -244,9 +244,6 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $link_prev = $link_first; } } - else { - $link_prev = ""; - } $result['args'] = array(); if (isset($link_next)) { $result['args'][] = array( From 8daa6d1563cdb6d2038bd8c8f62cfb8e26aa82c6 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Fri, 21 Jun 2019 13:43:31 +0000 Subject: [PATCH 19/23] Drupal functions to produce URLs --- islandora_solr_config/includes/rss_results.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index af502ba0..7e5fdd43 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -228,7 +228,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { // Only set Next link if there is a next page. $rss_limit = variable_get('islandora_solr_config_rss_limit', 50); if (count($docs) == $rss_limit) { - $link_next = url($base_url . "/" . request_path(), $next_page); + $link_next = url(url(request_path(), array('absolute' => TRUE)), $next_page); } if (isset($page_prev)) { @@ -238,7 +238,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { 'page' => $page_prev, )+$page_params, ); - $link_prev = url($base_url . "/" . request_path(), $prev_page); + $link_prev = url(url(request_path(), array('absolute' => TRUE)), $prev_page); } else { $link_prev = $link_first; From 45dc07500f12519b8f3f12cd89548d838f323443 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Fri, 21 Jun 2019 13:56:19 +0000 Subject: [PATCH 20/23] Make it simpler --- islandora_solr_config/includes/rss_results.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 7e5fdd43..6fa193c8 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -220,6 +220,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { } $next_page = array( + 'absolute' => TRUE, 'query' => array( 'page' => $page_next, )+$page_params, @@ -228,17 +229,18 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { // Only set Next link if there is a next page. $rss_limit = variable_get('islandora_solr_config_rss_limit', 50); if (count($docs) == $rss_limit) { - $link_next = url(url(request_path(), array('absolute' => TRUE)), $next_page); + $link_next = url(request_path(), $next_page); } if (isset($page_prev)) { if ($page_prev > 0) { $prev_page = array( + 'absolute' => TRUE, 'query' => array( 'page' => $page_prev, )+$page_params, ); - $link_prev = url(url(request_path(), array('absolute' => TRUE)), $prev_page); + $link_prev = url(request_path(), $prev_page); } else { $link_prev = $link_first; From 0450aaf0eddba9b31855b9b37130d8ce2fd474aa Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Fri, 21 Jun 2019 14:20:30 +0000 Subject: [PATCH 21/23] Fix the total problem --- islandora_solr_config/includes/rss_results.inc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index 6fa193c8..b6a4d342 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -31,14 +31,15 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { global $base_url; drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8'); + $islandora_solr_query->solrLimit = variable_get('islandora_solr_config_rss_limit', 50); $islandora_solr_query->executeQuery(); // Get raw results. $solr_result = $islandora_solr_query->islandoraSolrResult; - // All results. $docs = $solr_result['response']['objects']; + $total_results = $solr_result['response']['numFound']; // Loop over results. $items = NULL; @@ -73,7 +74,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $query = $islandora_solr_query->solrQuery; // Get the variables for the element. - $channel = $this->rssChannel($query, $docs); + $channel = $this->rssChannel($query, $total_results); $rss_attributes = array('version' => '2.0'); drupal_alter('islandora_solr_config_rss_root_element_attributes', $rss_attributes, $channel, $items); @@ -175,7 +176,7 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { * @return array * variable that holds all values to be rendered into elements */ - public function rssChannel($query, $docs) { + public function rssChannel($query, $total_results) { // Set variables. global $base_url; $rss_channel = variable_get('islandora_solr_config_rss_channel', array( @@ -228,7 +229,11 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { // Only set Next link if there is a next page. $rss_limit = variable_get('islandora_solr_config_rss_limit', 50); - if (count($docs) == $rss_limit) { +// Take $total_results and divide by $rss_limit to get number of pages + $total_pages = $total_results / $rss_limit; + dd('Total pages: ' . $total_pages); + dd('Current page: ' . $page_number); + if ($total_pages > ($page_number + 1)) { $link_next = url(request_path(), $next_page); } From fd35ba3a4eba4f0f073087cb44eb020ac28b0687 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 24 Jun 2019 17:36:41 +0000 Subject: [PATCH 22/23] Fix the first page link and make it Drupaly --- islandora_solr_config/includes/rss_results.inc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index b6a4d342..aba391dc 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -200,9 +200,12 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { else { $page_number = $page_params['page']; } + + // Removes the Page parameter to generate the first page link if applicable. + $first_params = $page_params; if (isset($page_params['page'])) { - $first_params = $page_params; unset($first_params['page']); + } $link_first = url( request_path(), array( @@ -210,10 +213,6 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { 'query' => $first_params, ) ); - } - else { - $link_first = $base_url . $feed_url; - } $page_next = $page_number + 1; if ($page_number > 0) { From 4143e166712c8c7430394d3e4bc09ab8e5e0add5 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Fri, 28 Jun 2019 13:37:56 +0000 Subject: [PATCH 23/23] Remove debug messages --- islandora_solr_config/includes/rss_results.inc | 2 -- 1 file changed, 2 deletions(-) diff --git a/islandora_solr_config/includes/rss_results.inc b/islandora_solr_config/includes/rss_results.inc index aba391dc..03b850e9 100644 --- a/islandora_solr_config/includes/rss_results.inc +++ b/islandora_solr_config/includes/rss_results.inc @@ -230,8 +230,6 @@ class IslandoraSolrResultsRSS extends IslandoraSolrResults { $rss_limit = variable_get('islandora_solr_config_rss_limit', 50); // Take $total_results and divide by $rss_limit to get number of pages $total_pages = $total_results / $rss_limit; - dd('Total pages: ' . $total_pages); - dd('Current page: ' . $page_number); if ($total_pages > ($page_number + 1)) { $link_next = url(request_path(), $next_page); }