Skip to content

Commit

Permalink
Merge pull request #1 from winkm89/master
Browse files Browse the repository at this point in the history
Merge upstream changes.
  • Loading branch information
fabricebg committed Aug 25, 2022
2 parents 149653c + 84fd3f7 commit 56ef17f
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 47 deletions.
111 changes: 77 additions & 34 deletions admin/add-publication.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/class-tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public static function add_table_pub($charset_collate) {
`title` VARCHAR(500),
`type` VARCHAR (50),
`bibtex` VARCHAR (100),
`award` VARCHAR (100),
`author` VARCHAR (3000),
`editor` VARCHAR (3000),
`isbn` VARCHAR (50),
Expand Down
16 changes: 16 additions & 0 deletions core/class-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static function force_update () {
if ( $db_version[0] === '8' || $update_level === '8' ) {
TP_Update::upgrade_to_80();
TP_Update::upgrade_to_81($charset_collate);
TP_Update::upgrade_to_82();
}

// Add teachPress options
Expand Down Expand Up @@ -859,6 +860,21 @@ private static function upgrade_to_81( $charset_collate ) {
$wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `issue` VARCHAR(40) $charset_collate NULL DEFAULT NULL AFTER `journal`");
}
}


/**
* Database upgrade to teachPress 9.0.0 structure
* @param string $charset_collate
* @since 9.0.0
*/
private static function upgrade_to_82() {
global $wpdb;

// add column image_target to table teachpress_pub
if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'award'") == '0') {
$wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `award` VARCHAR (100) NULL DEFAULT NULL AFTER `type`");
}
}

/**
* Renames a table
Expand Down
25 changes: 23 additions & 2 deletions core/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ function sort_tp_publication_type_options ($a, $b) {
return strcmp($a['i18n_singular'], $b['i18n_singular']);
}

/**
* Get award types
* @param string $selected -->
* @return string
* @since 9.0.0
*/
function get_tp_award_options ($selected) {
global $tp_awards;
$award = '';
$pub_awards = $tp_awards->get();
// usort($pub_awards, 'sort_tp_publication_award_options');
foreach ( $pub_awards as $row ) {
$title = $row['i18n_singular'];
$current = ( $row['award_slug'] == $selected && $selected != '' ) ? 'selected="selected"' : '';
$award = $award . '<option value="' . $row['award_slug'] . '" ' . $current . '>' . $title . '</option>';
}
return $award;
}


/**
* Returns the default structure for a publication array
* @return array
Expand All @@ -185,9 +205,10 @@ function sort_tp_publication_type_options ($a, $b) {
function tp_get_default_structure() {
$ret = array(
'pub_id' => '',
'title' => '',
'type' => '',
'bibtex' => '',
'type' => '',
'award' => '',
'title' => '',
'author' => '',
'editor' => '',
'isbn' => '',
Expand Down
73 changes: 73 additions & 0 deletions core/publications/class-award.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* The award object class
* @since 9.0.0
*/
class TP_Award {
protected $pub_awards = array();

/**
* Register a page
*
* @param array $atts {
* @type string $award_slug The internal key fo the award
* @type string $i18n_singular The singular label for the award
* @type string $i18n_plural The plural label for the award
* }
*/
public function register($atts){
// define defaults
$param = shortcode_atts(array(
'award_slug' => '',
'i18n_singular' => '',
'i18n_plural' => '',
'icon' => ''
), $atts);

if ( $param['award_slug'] !== '' ) {
$this->pub_awards[ $param['award_slug'] ] = array(
'award_slug' => $param['award_slug'],
'i18n_singular' => $param['i18n_singular'],
'i18n_plural' => $param['i18n_plural'],
'icon' => $param['icon']
);
}
}

/**
* Returns all registered pages as array
* @return array
*/
public function get() {
return $this->pub_awards;
}

/**
* Returns the page data by the given award_slug
* @param string $award_slug
* @return array
*/
public function get_data($award_slug) {
if ( isset( $this->pub_awards[$award_slug] ) ) {
return $this->pub_awards[$award_slug];
}
return null;
}
}

/**
* Registers a award
* @global type $tp_awards
* @param array $atts
* @since 9.0.0
*/
function tp_register_award($atts) {
global $tp_awards;

// Instance the object if it's not done yet
if ( ! ( $tp_awards instanceof TP_Award ) ) {
$tp_awards = new TP_Award();
}

$tp_awards->register($atts);
}
28 changes: 19 additions & 9 deletions core/publications/class-db-publications.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static function get_publications($args = array(), $count = false) {
$defaults = array(
'user' => '',
'type' => '',
'award' => '',
'tag' => '',
'key' => '',
'author_id' => '',
Expand Down Expand Up @@ -110,7 +111,7 @@ public static function get_publications($args = array(), $count = false) {
}

// define basics
$select = "SELECT DISTINCT p.pub_id, p.title, p.type, p.bibtex, p.author, p.editor, p.date, DATE_FORMAT(p.date, '%Y') AS year, p.urldate, p.isbn, p.url, p.booktitle, p.issuetitle, p.journal, p.issue, p.volume, p.number, p.pages, p.publisher, p.address, p.edition, p.chapter, p.institution, p.organization, p.school, p.series, p.crossref, p.abstract, p.howpublished, p.key, p.techtype, p.note, p.comment, p.is_isbn, p.image_url, p.image_target, p.image_ext, p.doi, p.rel_page, p.status, p.added, p.modified, p.import_id $selects FROM " . TEACHPRESS_PUB . " p $joins ";
$select = "SELECT DISTINCT p.pub_id, p.title, p.type, p.award, p.bibtex, p.author, p.editor, p.date, DATE_FORMAT(p.date, '%Y') AS year, p.urldate, p.isbn, p.url, p.booktitle, p.issuetitle, p.journal, p.issue, p.volume, p.number, p.pages, p.publisher, p.address, p.edition, p.chapter, p.institution, p.organization, p.school, p.series, p.crossref, p.abstract, p.howpublished, p.key, p.techtype, p.note, p.comment, p.is_isbn, p.image_url, p.image_target, p.image_ext, p.doi, p.rel_page, p.status, p.added, p.modified, p.import_id $selects FROM " . TEACHPRESS_PUB . " p $joins ";
$select_for_count = "SELECT DISTINCT p.pub_id, DATE_FORMAT(p.date, '%Y') AS year FROM " . TEACHPRESS_PUB . " p $joins ";
$join = '';

Expand Down Expand Up @@ -372,10 +373,11 @@ public static function add_publication($data, $tags, $bookmark = array() ) {

$wpdb->insert(
TEACHPRESS_PUB,
array(
'title' => ( $data['title'] === '' ) ? '[' . __('No title','teachpress') . ']' : stripslashes($data['title']),
'type' => $data['type'],
array(
'bibtex' => stripslashes( TP_Publications::generate_unique_bibtex_key($data['bibtex']) ),
'type' => $data['type'],
'award' => $data['award'],
'title' => ( $data['title'] === '' ) ? '[' . __('No title','teachpress') . ']' : stripslashes($data['title']),
'author' => stripslashes($data['author']),
'editor' => stripslashes($data['editor']),
'isbn' => $data['isbn'],
Expand Down Expand Up @@ -414,8 +416,14 @@ public static function add_publication($data, $tags, $bookmark = array() ) {
'added' => $post_time,
'modified' => $post_time,
'import_id' => $data['import_id'] ),
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d' ) );
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d' ) );
$pub_id = $wpdb->insert_id;

// Error message for the user:
if ( $pub_id === 0 && $wpdb->last_error !== '' ) {
get_tp_message($data['title'] . ': <ul><li>' . $wpdb->last_error . '</li></ul>', 'red');
//var_dump($data);
}

// Bookmarks
if ( !empty( $bookmark ) ) {
Expand Down Expand Up @@ -488,9 +496,10 @@ public static function change_publication($pub_id, $data, $new_tags = '', $del_t
$wpdb->update(
TEACHPRESS_PUB,
array(
'title' => stripslashes($data['title']),
'type' => $data['type'],
'bibtex' => stripslashes($data['bibtex']),
'type' => $data['type'],
'award' => $data['award'],
'title' => stripslashes($data['title']),
'author' => stripslashes($data['author']),
'editor' => stripslashes($data['editor']),
'isbn' => $data['isbn'],
Expand Down Expand Up @@ -528,7 +537,7 @@ public static function change_publication($pub_id, $data, $new_tags = '', $del_t
'status' => stripslashes($data['status']),
'modified' => $post_time ),
array( 'pub_id' => $pub_id ),
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s' ,'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s' ),
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ,'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%s', '%s' ),
array( '%d' ) );

// get_tp_message($wpdb->last_query);
Expand Down Expand Up @@ -756,9 +765,10 @@ public static function generate_unique_bibtex_key ($bibtex_key) {
*/
public static function get_default_fields () {
return array(
'title' => '',
'type' => '',
'bibtex' => '',
'award' => '',
'title' => '',
'author' => '',
'editor' => '',
'isbn' => '',
Expand Down
34 changes: 34 additions & 0 deletions core/publications/default-awards.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Registers all default awards
* @since 9.0.0
*/
function tp_register_all_awards() {
// No Award
tp_register_award(
array(
'award_slug' => 'none',
'i18n_singular' => __('None','teachpress'),
'i18n_plural' => __('None','teachpress'),
'icon' => ''
) );

// Best Paper
tp_register_award(
array(
'award_slug' => 'best',
'i18n_singular' => __('Best Paper','teachpress'),
'i18n_plural' => __('Best Papers','teachpress'),
'icon' => 'fas fa-trophy'
) );

// Honorable Mention
tp_register_award(
array(
'award_slug' => 'honorable',
'i18n_singular' => __('Honorable Mention','teachpress'),
'i18n_plural' => __('Honorable Mentions','teachpress'),
'icon' => 'fas fa-award'
) );

}
20 changes: 20 additions & 0 deletions core/publications/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ public function get_author ($before = '', $after = '') {
return $before . $this->data['all_authors'] . $after;
}

/**
* Returns the award (as html element)
* @return string
* @since 9.0.0
* @access public
*/
public function get_award($withLabel = false) {
global $tp_awards;
if ( $this->data['row']['award'] != '' && $this->data['row']['award'] != 'none' ) {
$award_data = $tp_awards->get_data($this->data['row']['award']);
$s = '<span class="tp_pub_label_award" title="'.$award_data["i18n_singular"].'"><i class="'.$award_data["icon"].'"></i>';
if ($withLabel) {
$s .= ' '.$award_data["i18n_singular"];
}
$s .= "</span>";
return $s;
}
return "";
}

/**
* Returns the meta row
* @return string
Expand Down
2 changes: 1 addition & 1 deletion core/shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private static function generate_jumpmenu_url($filter_parameter, $hide_key = '',
$params = '';

foreach ( $keys as $key ) {
if ( $key === $hide_key ) {
if ( $key === $hide_key || empty($key) ) {
continue;
}
$url_param = isset ( $url_vars[ $key ] ) ? $url_vars[ $key ] : $key;
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Please note the [teachPress 6.0 Upgrade Information](https://mtrv.wordpress.com/

= 9.0.0 beta (xx.xx.xxxx) =
* New: Filters for custom select fields can be added to [tpcloud], [tpsearch]
* New: Add awards field to the publications
* Changed: This version no longer contains the course module
* Changed: Removed deprecated methods tp_admin_page_menu(), tp_date_shortcode(), get_tp_course(), get_tp_courses(), get_tp_course_free_places(), tp_is_user_subscribed()

Expand Down
3 changes: 3 additions & 0 deletions teachpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@
include_once('core/publications/class-db-publications.php');
include_once('core/publications/class-db-tags.php');
include_once('core/publications/class-publication-type.php');
include_once('core/publications/class-award.php');
include_once('core/publications/class-pubmed-import.php');
include_once('core/publications/default-publication-types.php');
include_once('core/publications/default-awards.php');
include_once('core/publications/templates.php');
include_once('core/publications/class-books-widget.php');

Expand Down Expand Up @@ -490,6 +492,7 @@ function tp_plugin_link($links, $file){
add_action('init', 'tp_language_support');
add_action('init', 'tp_feed_init');
add_action('init', 'tp_register_all_publication_types');
add_action('init', 'tp_register_all_awards');
add_action('wp_ajax_teachpress', 'tp_ajax_callback');
add_action('wp_ajax_teachpressdocman', 'tp_ajax_doc_manager_callback');
add_action('admin_menu', 'tp_add_menu_settings');
Expand Down
12 changes: 12 additions & 0 deletions templates/tp_template_2021.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ div.tp_pub_number {
line-height: 1;
border-radius: 2px;
box-shadow: inset 0 -1px 0 rgba(0,0,0,0.12);}
.tp_pub_label_award {
background-color: #d2001f;
color: #fff;
display: inline-block;
padding: 5px 5px;
margin-left: 5px;
font-size: 0.9em;
font-weight: bold;
line-height: 1;
border-radius: 2px;
}

.tp_pub_label_status {
background-color: orange;
color: #fff;
Expand Down
7 changes: 6 additions & 1 deletion templates/tp_template_2021.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ public function get_entry ($interface) {
$s .= $interface->get_images('left');
$s .= '<div class="tp_pub_info">';
$s .= $interface->get_author('<p class="tp_pub_author">', '</p>');
$s .= '<p class="tp_pub_title">' . $interface->get_title() . ' ' . $interface->get_type() . ' ' . $interface->get_label('status', array('forthcoming') ) . '</p>';
$s .= '<p class="tp_pub_title">' . $interface->get_title();
$award = $interface->get_award(true);
if ($award != ""){
$s .= ' ' . $award;
}
$s .= ' ' . $interface->get_type() . ' ' . $interface->get_label('status', array('forthcoming') ) . '</p>';
$s .= '<p class="tp_pub_additional">' . $interface->get_meta() . '</p>';
$s .= '<p class="tp_pub_menu">' . $interface->get_menu_line() . '</p>';
$s .= $interface->get_infocontainer();
Expand Down

0 comments on commit 56ef17f

Please sign in to comment.