Skip to content

Commit f75c0b4

Browse files
authored
Merge pull request #198 from quantum-journal/develop
Release of 0.4.2
2 parents 4a75f79 + f315bc8 commit f75c0b4

19 files changed

+1394
-112
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ before_install:
1313
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.6" ]]; then composer require --dev --no-update phpunit/phpunit ~5; fi
1414
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.0" ]]; then composer require --dev --no-update phpunit/phpunit ~5; fi
1515
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then composer require --dev --no-update phpunit/phpunit ~7; fi
16-
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then composer require --dev --no-update phpunit/phpunit ~8; fi
16+
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then composer require --dev --no-update phpunit/phpunit ~7; fi
1717
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.3" ]]; then composer require --dev --no-update phpunit/phpunit ~9; fi
1818
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.4" ]]; then composer require --dev --no-update phpunit/phpunit ~9; fi
1919
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "8.0" ]]; then composer require --dev --no-update phpunit/phpunit ~9; fi

o3po/admin/class-o3po-admin.php

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-o3po-settings.php';
1414
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-o3po-plotter.php';
15+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-o3po-publication-type.php';
16+
17+
1518

1619
/**
1720
* The admin-specific functionality of the plugin.
@@ -140,14 +143,19 @@ public function add_plugin_action_links( $actions ) {
140143
* @since 0.3.0
141144
*/
142145
public function add_meta_data_explorer_page_to_menu() {
143-
add_menu_page(
144-
$this->get_plugin_pretty_name() . ' meta-data explorer',
145-
$this->get_plugin_pretty_name() . ' meta-data',
146-
'administrator',
147-
$this->get_plugin_name() . '-meta-data-explorer',
148-
array($this, 'render_meta_data_explorer'),
149-
'dashicons-chart-pie'
150-
);
146+
147+
foreach(['editor', 'administrator'] as $role)
148+
{
149+
if(current_user_can($role))
150+
add_menu_page(
151+
$this->get_plugin_pretty_name() . ' meta-data explorer',
152+
$this->get_plugin_pretty_name() . ' meta-data',
153+
$role,
154+
$this->get_plugin_name() . '-meta-data-explorer',
155+
array($this, 'render_meta_data_explorer'),
156+
'dashicons-chart-pie'
157+
);
158+
}
151159
}
152160

153161
/**
@@ -157,6 +165,10 @@ public function add_meta_data_explorer_page_to_menu() {
157165
* @sinde 0.3.0
158166
*/
159167
public function render_meta_data_explorer() {
168+
169+
if( !current_user_can('editor') && !current_user_can('administrator') )
170+
return "<p>You are not allowed to access this page.</p>";
171+
160172
$html = '<div class="wrap">';
161173
$html .= '<h2>' . $this->get_plugin_pretty_name() .' meta-data explorer</h2>';
162174
$html .= '</div>';
@@ -185,8 +197,8 @@ public function render_meta_data_explorer() {
185197

186198
if($active_tab === 'meta-data')
187199
{
188-
189-
$html .= '<p>This is only a very basic summary of some of the meta-data fields of the published publications. In the future this page will allow a more customizable display and export of that meta-data.</p>';
200+
$html .= '<h3>Meta-data export</h3>';
201+
$html .= '<p>Here you can display and export some of the stored meta-data.</p>';
190202

191203
$post_type_names = O3PO_PublicationType::get_active_publication_type_names();
192204
if(isset( $_GET['post_type'] ))
@@ -384,17 +396,76 @@ public function render_meta_data_explorer() {
384396
sort($citations_data['all_citing_dois_in_two_years_preceeding'][$year_to_display]);
385397
foreach($citations_data['all_citing_dois_in_two_years_preceeding'][$year_to_display] as $doi)
386398
$html .= '<div><a href="' . esc_attr($doi_url_prefix . $doi) . '">' . esc_html($doi) . '</a></div>';
387-
}
399+
}
388400

389401
}
390402

391403

392404
wp_reset_postdata();
393405

394406
$html .= '<h4>Why is the data not always up to date?</h4>';
395-
$html .= '<p>Fetching cited-by data is a time consuming operation for which external services need to be queried. Fresh cited-by data is thus fetched when the page of a publication is visited and the last time cited-by data for that publication was fetched lies more than ' . $cited_by_refresh_seconds . ' seconds in the past. This balances the load and makes sure that cited by data is always reasonably up to date. If, for some reason, you want to fetch fresh cited-by data for all publications with cited-by data older ' . $cited_by_refresh_seconds . ' seconds you can press the fetch fresh data button below. Beware that this might be a very long operation that can easily time out depending on your server setup and the number of publications.</p>';
407+
$html .= '<p>Fetching cited-by data is a time consuming operation for which external services need to be queried. Fresh cited-by data is thus fetched when the page of a publication is visited and the last time cited-by data for that publication was fetched lies more than ' . esc_html($cited_by_refresh_seconds) . ' seconds in the past. This balances the load and makes sure that cited by data is always reasonably up to date. If, for some reason, you want to fetch fresh cited-by data for all publications with cited-by data older than ' . esc_html($cited_by_refresh_seconds) . ' seconds you can press the fetch fresh data button below. Beware that this might be a very long operation that can easily time out depending on your server setup and the number of publications.</p>';
396408
$html .= '<form method="post" action="' . esc_url('?page=' . $this->get_plugin_name() . '-meta-data-explorer' . '&amp;tab=' . $tab_slug) . '"><input type="checkbox" id="refresh" name="refresh" value="checked" /><label for="refresh">I have read the above text on refreshing cited-by data.</label><input id="submit" type="submit" value="Refresh cited-by data"></form>';
397409
}
410+
elseif($active_tab === 'updated-after-publication')
411+
{
412+
$html .= '<h3>Updated on the arXiv</h3>';
413+
414+
$settings = O3PO_Settings::instance();
415+
$arxiv_url_abs_prefix = $settings->get_field_value('arxiv_url_abs_prefix');
416+
417+
$fetch_if_outdated = false;
418+
if(isset($_POST['refresh']) and $_POST['refresh'] === 'checked')
419+
$fetch_if_outdated = true;
420+
421+
$post_type = $settings->get_field_value('primary_publication_type_name');
422+
$post_type_instance = O3PO_PublicationType::get_active_publication_types($post_type);
423+
424+
$post_type_singular_name = $post_type_instance->get_publication_type_name();
425+
$post_type_plural_name = $post_type_instance->get_publication_type_name_plural();
426+
427+
$html .= '<p>The following ' . $post_type_plural_name . ' have been updated on the arXiv to a version newer than the published version:</p>';
428+
429+
$arxiv_submission_histories = $post_type_instance->get_all_arxiv_submission_histories($fetch_if_outdated);
430+
$html .= '<ul>';
431+
foreach($arxiv_submission_histories as $post_id => $arxiv_submission_history)
432+
{
433+
if(is_wp_error($arxiv_submission_history))
434+
{
435+
$html .= '<li>' . ' <a href="' . esc_attr('/' . $post_type . '/' . $doi_suffix) . '" target=_blank>' . esc_html(ucfirst($post_type_singular_name)) . ' ' . esc_html($doi_suffix) . ': version history could not be fetched from the arXiv: ' . esc_html($arxiv_submission_history->get_error_message()) . '</li>';
436+
continue;
437+
}
438+
439+
$date_published = get_post_meta( $post_id, $post_type . '_date_published', true );
440+
$eprint = get_post_meta( $post_id, $post_type . '_eprint', true );
441+
$eprint_without_version = preg_replace('#v[0-9]+$#u', '', $eprint);
442+
preg_match('#(v[0-9]+)$#u', $eprint, $matches);
443+
$published_version = $matches[1];
444+
$published_version_number = mb_substr($published_version, 1);
445+
446+
$latest_versiom = array_key_last($arxiv_submission_history);
447+
$latest_version_number = mb_substr($latest_versiom, 1);
448+
449+
if($latest_version_number > $published_version_number)
450+
{
451+
$doi_suffix = get_post_meta( $post_id, $post_type . '_doi_suffix', true );
452+
$html .= '<li>' . ' <a href="' . esc_attr('/' . $post_type . '/' . $doi_suffix) . '" target=_blank>' . esc_html(ucfirst($post_type_singular_name)) . ' ' . esc_html($doi_suffix) . ': published version is ' . esc_html($published_version) . '</a> but the <a href="' . esc_attr($arxiv_url_abs_prefix . '/' . $eprint_without_version . $latest_versiom). '" target=_blank>latest arXiv version is ' . esc_html($latest_versiom) . '</a>.<br />ArXiv comment on ' . esc_html($latest_versiom) . ':"' . esc_html($arxiv_submission_history[$latest_versiom]['comment']) . '"</li>';
453+
}
454+
455+
if(isset($arxiv_submission_history[$published_version]) && $arxiv_submission_history[$published_version]['date'] && $arxiv_submission_history[$published_version]['date'] > strtotime($date_published))
456+
{
457+
$doi_suffix = get_post_meta( $post_id, $post_type . '_doi_suffix', true );
458+
$html .= '<li>' . ' <a href="' . esc_attr('/' . $post_type . '/' . $doi_suffix) . '" target=_blank>' . esc_html(ucfirst($post_type_singular_name)) . ' ' . esc_html($doi_suffix) . ': published version is ' . esc_html($published_version) . '</a> which appeared on the arXiv after this work was first published, which indicates that the publication was updated post publication.</li>';
459+
}
460+
}
461+
$html .= '</ul>';
462+
463+
$arxiv_submission_history_refresh_seconds = $settings->get_field_value('arxiv_submission_history_refresh_seconds');
464+
465+
$html .= '<h4>Why is the data not always up to date?</h4>';
466+
$html .= '<p>Updating submission history data requires fetching the abstract page from the arXiv. Fresh submission history data is thus fetched when the page of a publication is visited and the last time submission history data for that publication was fetched lies more than ' . esc_html($arxiv_submission_history_refresh_seconds) . ' seconds in the past. This balances the load and makes sure that submission history data is always reasonably up to date. If, for some reason, you want to fetch fresh submission history data for all publications with data older than ' . esc_html($arxiv_submission_history_refresh_seconds) . ' seconds you can press the fetch fresh data button below. Beware that this might be a very long operation that can easily time out depending on your server setup and the number of publications.</p>';
467+
$html .= '<form method="post" action="' . esc_url('?page=' . $this->get_plugin_name() . '-meta-data-explorer' . '&amp;tab=' . $tab_slug) . '"><input type="checkbox" id="refresh" name="refresh" value="checked" /><label for="refresh">I have read the above text on refreshing submission history data.</label><input id="submit" type="submit" value="Refresh submission history data"></form>';
468+
}
398469

399470
echo $html;
400471
}
@@ -408,7 +479,8 @@ public function render_meta_data_explorer() {
408479
*/
409480
private $meta_data_explorer_tabs = [
410481
'meta-data' => 'Meta-data',
411-
'citation-metrics' => 'Citation metrics'
482+
'citation-metrics' => 'Citation metrics',
483+
'updated-after-publication' => 'Updated after publication',
412484
];
413485

414486

0 commit comments

Comments
 (0)