[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [FIX] Fix Zotero search results display and scrolling
"Baraka Kinywa \(@bkinywa24\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68926c11f3e3e_2cd5cf0503bb@gitlab-sidekiq-low-urgency-cpu-bound-v2-86c757c9d6-h5jvn.mail> |
Baraka Kinywa pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki
Commits:
9563bf51 by Espoir Baraka at 2025-08-05T23:32:26+03:00
[FIX] Fix Zotero search results display and scrolling
---
* [FIX] Fix Zotero search results display and scrolling
---
* [FIX] Fix Zotero search results display and scrolling
---
* [FIX] Fix Zotero search results display and scrolling
---
* [FIX] Fix Zotero search results display and scrolling
See merge request tikiwiki/tiki!8171
(cherry picked from commit fe2e2edc4c1763b7a9743e9def1281b4abc0160b)
See merge request tikiwiki/tiki!8200
(cherry picked from commit f10858c059249ba2db2833b77a87729dc3974fbf)
See merge request tikiwiki/tiki!8201
(cherry picked from commit 178f362b4a9a7d646bb4da1eb9323bb6ac39eae5)
See merge request tikiwiki/tiki!8202
- - - - -
3 changed files:
- lib/zoterolib.php
- templates/modules/mod-zotero.tpl
- tiki-ajax_services.php
Changes:
=====================================
lib/zoterolib.php
=====================================
@@ -27,46 +27,51 @@ class ZoteroLib extends TikiDb_Bridge
{
global $prefs;
- $subset = null;
- if ($tag) {
- $subset = '/tags/' . rawurlencode($tag);
- }
-
- $arguments = [
- 'content' => 'bib',
- 'limit' => $limit,
- ];
-
- if (! empty($prefs['zotero_style'])) {
- $arguments['style'] = $prefs['zotero_style'];
- }
+ try {
+ $subset = null;
+ if ($tag) {
+ $subset = '/tags/' . rawurlencode($tag);
+ }
- $oauthlib = TikiLib::lib('oauth');
- $response = $oauthlib->do_request(
- 'zotero',
- [
- 'url' => "https://api.zotero.org/groups/{$prefs['zotero_group_id']}$subset/items",
- 'get' => $arguments,
- ]
- );
+ $arguments = [
+ 'content' => 'bib',
+ 'limit' => $limit,
+ ];
- if ($response && $response->isSuccessful()) {
- $feed = Laminas\Feed\Reader\Reader::importString($response->getBody());
+ if (! empty($prefs['zotero_style'])) {
+ $arguments['style'] = $prefs['zotero_style'];
+ }
- $data = [];
- foreach ($feed as $entry) {
- $data[] = [
- 'key' => basename($entry->getLink()),
- 'url' => $entry->getLink(),
- 'title' => $entry->getTitle(),
- 'content' => $entry->getDescription(),
- ];
+ $oauthlib = TikiLib::lib('oauth');
+ $response = $oauthlib->do_request(
+ 'zotero',
+ [
+ 'url' => "https://api.zotero.org/groups/{$prefs['zotero_group_id']}$subset/items",
+ 'get' => $arguments,
+ ]
+ );
+
+ if ($response && $response->isSuccess()) {
+ $feed = Laminas\Feed\Reader\Reader::importString($response->getBody());
+
+ $data = [];
+ foreach ($feed as $entry) {
+ $data[] = [
+ 'key' => basename($entry->getLink()),
+ 'url' => $entry->getLink(),
+ 'title' => $entry->getTitle(),
+ 'content' => $entry->getDescription(),
+ ];
+ }
+
+ return $data;
}
- return $data;
+ return false;
+ } catch (Exception $e) {
+ error_log("Zotero get_references error: " . $e->getMessage());
+ return false;
}
-
- return false;
}
/**
@@ -107,7 +112,7 @@ class ZoteroLib extends TikiDb_Bridge
]
);
- if ($response->isSuccessful()) {
+ if ($response->isSuccess()) {
$entry = $response->getBody();
$entry = str_replace('<entry ', '<feed xmlns="http://www.w3.org/2005/Atom"><entry ', $entry) . '</feed>';
$feed = Laminas\Feed\Reader\Reader::importString($entry);
@@ -157,7 +162,7 @@ class ZoteroLib extends TikiDb_Bridge
]
);
- if ($response->isSuccessful()) {
+ if ($response->isSuccess()) {
$entry = $response->getBody();
return $entry;
=====================================
templates/modules/mod-zotero.tpl
=====================================
@@ -1,9 +1,18 @@
{tikimodule error=$module_params.error title=$tpl_module_title name="zotero" flip=$module_params.flip decorations=$module_params.decorations nobox=$module_params.nobox notitle=$module_params.notitle}
<form class="zoterosearch" method="post" action="tiki-ajax_services.php">
- <input type="text" name="zotero_tags"/>
- <input type="submit" class="btn btn-info btn-sm" name="zotero" value="{tr}Search{/tr}"/>
- <ul class="results">
- </ul>
+ <div class="input-group">
+ <input type="text" name="zotero_tags" placeholder="Enter a tag to filter (optional)"/>
+ <button type="submit" class="btn btn-info btn-sm" name="zotero">
+ <i class="fas fa-search"></i> {tr}Search{/tr}
+ </button>
+ </div>
+ <small class="form-text text-muted">
+ Leave the field empty to see all your references, or enter a tag to filter
+ </small>
+ <div class="results-container" style="max-height: 400px; overflow-y: auto; border: 1px solid #dee2e6; border-radius: 0.375rem; padding: 10px; background-color: #f8f9fa;">
+ <ul class="results list-unstyled mb-0">
+ </ul>
+ </div>
<div class="alert alert-warning">
{remarksbox type="errors" title="{tr}No results!{/tr}"}
<p>{tr}No results were found. Are you sure you searched for a tag?{/tr}</p>
@@ -17,32 +26,53 @@
</form>
{jq}
$('.zoterosearch:not(.done)').addClass('done')
- .find('.results, .error').hide().end()
+ .find('.results-container, .alert').hide().end()
.on("submit", function (e) {
var form = this;
e.preventDefault();
- $.post(this.action, $(this).serialize(), function (data) {
- var isError = data.type == 'unauthorized';
- $('.error', form).toggle(isError || data.results.length === 0);
- $('.results', form).toggle(! isError).empty();
-
- $.each(data.results, function (k, i) {
- var entry = $('<li/>').hide(), link = $('<strong/>');
- entry
- .append($(i.content))
- .append($('<a/>').text('Zotero').attr('href', i.url))
- .append($('<input type="text"/>').val('{zotero key=' + i.key + '}'));
+ $.ajax({
+ url: this.action,
+ type: 'POST',
+ data: $(this).serialize(),
+ dataType: 'json',
+ success: function (data) {
+ var isError = data.type == 'unauthorized' || data.type == 'no_results';
+ $('.alert', form).toggle(isError || data.results.length === 0);
+ $('.results-container', form).toggle(! isError);
+ $('.results', form).empty();
+
+ if (data.results.length > 0) {
+ $('.results', form).prepend('<div class="alert alert-success mb-3">Found ' + data.results.length + ' reference(s)</div>');
+ }
- link.text(i.title);
- link.css('cursor', 'pointer');
- link.on("click", function () {
- entry.toggle();
- $(':text', entry).trigger("select").trigger("focus");
+ $.each(data.results, function (k, i) {
+ var entry = $('<li/>').hide().addClass('mb-3 p-2 border-bottom'), link = $('<strong/>');
+
+ var contentDiv = $('<div/>').addClass('mt-2');
+ if (i.content) {
+ contentDiv.append($('<div/>').html(i.content));
+ }
+
+ var zoteroLink = $('<a/>').text('View in Zotero').attr('href', i.url).addClass('btn btn-sm btn-outline-primary me-2');
+ var copyInput = $('<input type="text"/>').val('{zotero key=' + i.key + '}').addClass('form-control form-control-sm d-inline-block w-auto me-2');
+ entry.append(contentDiv).append(zoteroLink).append(copyInput);
+ link.text(i.title);
+ link.css('cursor', 'pointer').addClass('text-primary d-block mb-1');
+ link.on("click", function () {
+ entry.toggle();
+ copyInput.trigger("select").trigger("focus");
+ });
+
+ $('.results', form).append(link).append(entry);
});
- $('.results', form).append(link).append(entry);
- });
- }, 'jsonp');
+ },
+ error: function(xhr, status, error) {
+ console.error('Zotero search error:', error);
+ $('.alert', form).show();
+ $('.results-container', form).hide();
+ }
+ });
return false;
});
=====================================
tiki-ajax_services.php
=====================================
@@ -191,14 +191,24 @@ if ($access->is_serializable_request() && $jitRequest->offsetExists('listonly'))
}
} elseif ($access->is_serializable_request() && isset($_REQUEST['zotero_tags'])) { // Handle Zotero Requests
$access->check_feature([ 'zotero_enabled' ]);
- $zoterolib = TikiLib::lib('zotero');
- $references = $zoterolib->get_references($_REQUEST['zotero_tags']);
+ try {
+ $zoterolib = TikiLib::lib('zotero');
+ $references = $zoterolib->get_references($_REQUEST['zotero_tags']);
- if ($references === false) {
- $access->output_serialized(['type' => 'unauthorized', 'results' => []]);
- } else {
- $access->output_serialized(['type' => 'success', 'results' => $references]);
+ if ($references === false) {
+ $oauthlib = TikiLib::lib('oauth');
+ if (! $oauthlib->is_authorized('zotero')) {
+ $access->output_serialized(['type' => 'unauthorized', 'results' => []]);
+ } else {
+ $access->output_serialized(['type' => 'no_results', 'results' => []]);
+ }
+ } else {
+ $access->output_serialized(['type' => 'success', 'results' => $references]);
+ }
+ } catch (Exception $e) {
+ error_log("Zotero error: " . $e->getMessage());
+ $access->output_serialized(['type' => 'error', 'message' => $e->getMessage(), 'results' => []]);
}
} elseif (isset($_REQUEST['geocode']) && $access->is_serializable_request()) {
$access->output_serialized(TikiLib::lib('geo')->geocode($_REQUEST['geocode']));
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/9563bf5179a3984c09395c59fb4b326bebeedd32
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/9563bf5179a3984c09395c59fb4b326bebeedd32
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs