-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Crossref citations badge #3
Conversation
@bondjimbond there is one DCS warning, an extra space in admin.form.inc |
@DiegoPino I'm pretty impressed with myself that Travis only found one problem this time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some logic and minor doc concerns
$url = "https://api.crossref.org/works/"; | ||
$request_url = $url . $doi; | ||
// Make the request and get results! | ||
if (!isset($result_json->error)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be wrong. How can $result_json->error exist if it is defined later on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, you're right. That was in islandora_oadoi, which this is based on. Should be removed there too. Testing on a DOI with no results doesn't create any problems, so it should be fine to remove it. I'll commit a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be bad form to add the OADOI fix to this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. OADOI fix should go in a separate one, if it is a code task then it could be ok, but its more like a bug fix right?
// Make the request and get results! | ||
if (!isset($result_json->error)) { | ||
$result_json = drupal_http_request($request_url); | ||
$result_array = json_decode($result_json->data, TRUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the request fails, does ->data exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, but if request fails, we don't get a badge or an error, which is what we want.
$badge = $block_text . ': ' . $result_citation_count; | ||
} | ||
else { | ||
$badge = '<img src="https://img.shields.io/badge/' . $block_text . '-' . $result_citation_count . '-blue.svg?style=flat" alt="Number of citations via Crossref: ' . $result_citation_count . '">'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is $block_text being escaped to avoid attacks on img.shields.io?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. How would I go about escaping it? (Though I expect they're already escaping input, since the general public can send whatever they want to the service.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to make that one safe/clean manually. See https://www.drupal.org/docs/7/security/writing-secure-code-0/handle-text-in-a-secure-fashion. I think simply storing an user input from a form into a drupal var does not remove possible breaking arguments for img.shields.io, no cleanup is being made. Good practices there could be run the whole src
content which is an url? through https://api.drupal.org/api/drupal/includes%21common.inc/function/check_url/7 but you could also sanitize/check on form validation/submit? where not sure, but somewhere for sure. Also since check_plain() and check_url() could rewrite your values, but users could be not aware, it would be good to maybe store this already cleaned up.. at least the form will load with the cleaned default and smart users will notice the difference? Not sure here, what do other @Islandora/7-x-1-x-committers think here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check_plain() seems to be helpful. Tried it with some HTML in my variable, with and without... check_plain works.
Do we need check_url as well, or is that enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be enough. Lastly (sorry, i'm worst than travis!), what about putting the alt="Number of citations via Crossref: ' . $result_citation_count .
into a t() function with replacements for international users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. Done, I think?
This module requires the following modules/libraries: | ||
|
||
* [Islandora](https://github.com/islandora/islandora) | ||
* [Islandora Scholar](https://github.com/Islandora/islandora_scholar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Scholar is a dependency, why is it not part of the .info file? Is that so in every other submodule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scholar dependency should be removed. Adding to commit list.
|
||
* [Islandora](https://github.com/islandora/islandora) | ||
* [Islandora Scholar](https://github.com/Islandora/islandora_scholar) | ||
* [Islandora Badges](../../) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a submodule (in terms of publishing) but is just a module for Drupal's eyes, it seems to me that using relative paths in the documentation is very context dependent. .md files should be readable outside the github context.
|
||
Block text: Defines the text used in the citation count block. Defaults to "Citations via Crossref". | ||
|
||
Badge type: You can choose between plain text or an automatically-generated image. Plain text is offered for custom styling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is badge image generating website used? io? could that be added in the readme?
@bondjimbond https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_http_request/7.x |
@DiegoPino I think that's what the if statement in your first review comment was attempting to get at - it was just added one line too early. I've adjusted that with the last commit, seems to be working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine now! 24 hrs and we should be clear
@DiegoPino Nobody seems to have any concerns... Are we ready to merge? 😀 |
@bondjimbond give me a while (need to talk to @manez). It just came to my attention that even if this module is a "submodule" that fact is really just a convention, and it is in strict, not so strict, definition (see the naming of the functions) this is a new module. So we need to probably discuss if we should consider it as such, or as part of badges.. i know it sounds lame, but trust me, better to have this discussion now than later one. |
@DiegoPino @bondjimbond Let's put this on the agenda for the Committers Call today. It's only a few hours away, so it wont hold things up too much, |
Just for the record, the Committers discussed it and determined this one is fine, but there's a larger issue about whether submodules should have license files of their own, which we're sending up to the Board of Directors as a legal question that's beyond the scope of Committers. This should not hold up merging this PR, but should hopefully lead to a policy we can follow by the next release. |
JIRA Ticket: (https://jira.duraspace.org/browse/ISLANDORA-2038)
What does this Pull Request do?
Adds a new Islandora Badges submodule, which generates citation counts via the Crossref REST API. This is a public API, without authentication, which would allow any Islandora site to get citation counts if they don't have access to Scopus or Web of Science credentials.
What's new?
A new badge titled "Islandora Crossref Citations". Displays citation counts for objects with DOIs, using the public-access Crossref REST API.
How should this be tested?
Interested parties
@Islandora/7-x-1-x-committers @bryjbrown @mjordan