From f73e7299b441bf54c67b06cfd4b5b16d23c44213 Mon Sep 17 00:00:00 2001 From: Sven Mayer Date: Sun, 14 Aug 2022 12:09:39 +0200 Subject: [PATCH 1/3] Added possibility to indicate awards #198 --- admin/add-publication.php | 111 ++++++++++++++------ core/class-tables.php | 1 + core/class-update.php | 16 +++ core/general.php | 25 ++++- core/publications/class-award.php | 73 +++++++++++++ core/publications/class-db-publications.php | 22 ++-- core/publications/default-awards.php | 34 ++++++ core/publications/templates.php | 20 ++++ readme.txt | 1 + teachpress.php | 3 + templates/tp_template_2021.css | 12 +++ templates/tp_template_2021.php | 7 +- 12 files changed, 279 insertions(+), 46 deletions(-) create mode 100644 core/publications/class-award.php create mode 100644 core/publications/default-awards.php diff --git a/admin/add-publication.php b/admin/add-publication.php index 7863648..8b4894f 100644 --- a/admin/add-publication.php +++ b/admin/add-publication.php @@ -42,9 +42,10 @@ function tp_add_publication_page() { // form variables from add_publication.php $data = tp_get_default_structure(); - $data['title'] = isset( $_POST['tp_post_title'] ) ? htmlspecialchars($_POST['tp_post_title']) : ''; - $data['type'] = isset( $_POST['type'] ) ? htmlspecialchars($_POST['type']) : ''; $data['bibtex'] = isset( $_POST['bibtex'] ) ? htmlspecialchars($_POST['bibtex']) : ''; + $data['type'] = isset( $_POST['type'] ) ? htmlspecialchars($_POST['type']) : ''; + $data['award'] = isset( $_POST['award'] ) ? htmlspecialchars($_POST['award']) : ''; + $data['title'] = isset( $_POST['tp_post_title'] ) ? htmlspecialchars($_POST['tp_post_title']) : ''; $data['author'] = isset( $_POST['author'] ) ? htmlspecialchars($_POST['author']) : ''; $data['editor'] = isset( $_POST['editor'] ) ? htmlspecialchars($_POST['editor']) : ''; $data['isbn'] = isset( $_POST['isbn'] ) ? htmlspecialchars($_POST['isbn']) : ''; @@ -361,27 +362,41 @@ public static function get_general_box ($pub_id, $pub_data){ TP_HTML::line(''); TP_HTML::line(''); + $tabindex = 1; // Publication type TP_HTML::line(''); // BibTex key TP_HTML::line(''); + + // Award of publication + TP_HTML::line(''); TP_HTML::line(''); TP_HTML::line('
'); $title = __('The type of publication','teachpress'); TP_HTML::line('

'); - TP_HTML::line(''); echo get_tp_publication_type_options ($pub_data["type"], $mode = 'sng'); - TP_HTML::line(' '); + TP_HTML::line(''); TP_HTML::line('
'); $title = __('A simple unique key without spaces','teachpress'); TP_HTML::line('

'); - TP_HTML::line(''); + $tabindex++; + TP_HTML::line(''); TP_HTML::line(''); TP_HTML::line('
'); + $title = __('Award','teachpress'); + TP_HTML::line('

'); + $tabindex++; + TP_HTML::line(''); + TP_HTML::line('
'); // author + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'author', @@ -389,11 +404,12 @@ public static function get_general_box ($pub_id, $pub_data){ 'label' => __('Author(s)','teachpress'), 'type' => 'textarea', 'value' => $pub_data['author'], - 'tabindex' => 4, + 'tabindex' => $tabindex, 'display' => 'block', 'style' => 'width:95%; height: 65px;') ); // editor + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'editor', @@ -401,7 +417,7 @@ public static function get_general_box ($pub_id, $pub_data){ 'label' => __('Editor(s)','teachpress'), 'type' => 'textarea', 'value' => $pub_data['editor'], - 'tabindex' => 5, + 'tabindex' => $tabindex, 'display' => 'block', 'style' => 'width:95%; height: 65px;') ); @@ -411,7 +427,8 @@ public static function get_general_box ($pub_id, $pub_data){ $value = ($pub_id != 0) ? $pub_data["date"] : $placeholder; $checked = ( $pub_data['status'] === 'forthcoming' ) ? 'checked="checked"' : ''; TP_HTML::line('

'); - TP_HTML::line(''); + $tabindex++; + TP_HTML::line(''); TP_HTML::line(''); TP_HTML::line(''); @@ -519,6 +536,7 @@ public static function get_main_box ($pub_id, $pub_data) { TP_HTML::div_open('inside'); + $tabindex = 8; // booktitle echo TP_Admin::get_form_field( array( @@ -527,11 +545,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Booktitle','teachpress'), 'type' => 'textarea', 'value' => $pub_data['booktitle'], - 'tabindex' => 6, + 'tabindex' => $tabindex, 'display' => ( in_array('booktitle', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%; height: 58px;') ); // issuetitle + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'issuetitle', @@ -539,11 +558,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Issuetitle','teachpress'), 'type' => 'textarea', 'value' => $pub_data['issuetitle'], - 'tabindex' => 7, + 'tabindex' => $tabindex, 'display' => ( in_array('issuetitle', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%; height: 58px;') ); // journal + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'journal', @@ -551,11 +571,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Journal','teachpress'), 'type' => 'input', 'value' => $pub_data['journal'], - 'tabindex' => 8, + 'tabindex' => $tabindex, 'display' => ( in_array('journal', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // volume + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'volume', @@ -563,10 +584,11 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Volume','teachpress'), 'type' => 'input', 'value' => $pub_data['volume'], - 'tabindex' => 9, + 'tabindex' => $tabindex, 'display' => ( in_array('volume', $default_fields) ) ? 'block' : 'none') ); // volume + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'issue', @@ -574,10 +596,11 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Issue','teachpress'), 'type' => 'input', 'value' => $pub_data['issue'], - 'tabindex' => 10, + 'tabindex' => $tabindex, 'display' => ( in_array('issue', $default_fields) ) ? 'block' : 'none') ); // number + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'number', @@ -585,10 +608,11 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Number','teachpress'), 'type' => 'input', 'value' => $pub_data['number'], - 'tabindex' => 11, + 'tabindex' => $tabindex, 'display' => ( in_array('number', $default_fields) ) ? 'block' : 'none') ); // pages + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'pages', @@ -596,11 +620,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Pages','teachpress'), 'type' => 'input', 'value' => $pub_data['pages'], - 'tabindex' => 12, + 'tabindex' => $tabindex, 'display' => ( in_array('pages', $default_fields) ) ? 'block' : 'none') ); // publisher + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'publisher', @@ -608,11 +633,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Publisher','teachpress'), 'type' => 'input', 'value' => $pub_data['publisher'], - 'tabindex' => 13, + 'tabindex' => $tabindex, 'display' => ( in_array('publisher', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // address + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'address', @@ -620,12 +646,13 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Address','teachpress'), 'type' => 'input', 'value' => $pub_data['address'], - 'tabindex' => 14, + 'tabindex' => $tabindex, 'display' => ( in_array('address', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // edition + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'edition', @@ -633,11 +660,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Edition','teachpress'), 'type' => 'input', 'value' => $pub_data['edition'], - 'tabindex' => 15, + 'tabindex' => $tabindex, 'display' => ( in_array('edition', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // chapter + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'chapter', @@ -645,11 +673,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Chapter','teachpress'), 'type' => 'input', 'value' => $pub_data['chapter'], - 'tabindex' => 16, + 'tabindex' => $tabindex, 'display' => ( in_array('chapter', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // institution + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'institution', @@ -657,11 +686,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Institution','teachpress'), 'type' => 'input', 'value' => $pub_data['institution'], - 'tabindex' => 17, + 'tabindex' => $tabindex, 'display' => ( in_array('institution', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // organization + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'organization', @@ -669,11 +699,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Organization','teachpress'), 'type' => 'input', 'value' => $pub_data['organization'], - 'tabindex' => 18, + 'tabindex' => $tabindex, 'display' => ( in_array('organization', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // school + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'school', @@ -681,11 +712,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('School','teachpress'), 'type' => 'input', 'value' => $pub_data['school'], - 'tabindex' => 19, + 'tabindex' => $tabindex, 'display' => ( in_array('school', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // series + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'series', @@ -693,11 +725,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Series','teachpress'), 'type' => 'input', 'value' => $pub_data['series'], - 'tabindex' => 20, + 'tabindex' => $tabindex, 'display' => ( in_array('series', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;' ) ); // crossref + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'crossref', @@ -705,11 +738,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Crossref','teachpress'), 'type' => 'input', 'value' => $pub_data['crossref'], - 'tabindex' => 21, + 'tabindex' => $tabindex, 'display' => ( in_array('crossref', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;' ) ); // abstract + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'abstract', @@ -717,11 +751,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Abstract','teachpress'), 'type' => 'textarea', 'value' => $pub_data['abstract'], - 'tabindex' => 22, + 'tabindex' => $tabindex, 'display' => 'block', 'style' => 'width:95%; height: 150px;') ); // howpublished + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'howpublished', @@ -729,11 +764,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Howpublished','teachpress'), 'type' => 'input', 'value' => $pub_data['howpublished'], - 'tabindex' => 23, + 'tabindex' => $tabindex, 'display' => ( in_array('howpublished', $default_fields) ) ? 'block' : 'none', 'style' => 'width:95%;') ); // key + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'key', @@ -741,11 +777,12 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Key','teachpress'), 'type' => 'input', 'value' => $pub_data['key'], - 'tabindex' => 24, + 'tabindex' => $tabindex, 'display' => 'block', 'style' => '') ); // techtype + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'techtype', @@ -753,7 +790,7 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('Type'), 'type' => 'input', 'value' => $pub_data['techtype'], - 'tabindex' => 25, + 'tabindex' => $tabindex, 'display' => ( in_array('techtype', $default_fields) ) ? 'block' : 'none', 'style' => '') ); @@ -762,14 +799,18 @@ public static function get_main_box ($pub_id, $pub_data) { $checked_2 = ($pub_data["is_isbn"] == '0') ? 'checked="checked"' : ''; TP_HTML::div_open('div_isbn'); TP_HTML::line('

'); - TP_HTML::line(''); + $tabindex++; + TP_HTML::line(''); TP_HTML::line(''); - TP_HTML::line(''); - TP_HTML::line(''); + $tabindex++; + TP_HTML::line(''); + $tabindex++; + TP_HTML::line(''); TP_HTML::line(''); TP_HTML::div_close('div_isbn'); // doi + $tabindex++; echo TP_Admin::get_form_field( array( 'name' => 'doi', @@ -777,7 +818,7 @@ public static function get_main_box ($pub_id, $pub_data) { 'label' => __('DOI number','teachpress'), 'type' => 'input', 'value' => $pub_data['doi'], - 'tabindex' => 28, + 'tabindex' => $tabindex, 'display' => 'block', 'style' => 'width:95%;') ); @@ -788,7 +829,8 @@ public static function get_main_box ($pub_id, $pub_data) { $value = ($pub_id != 0) ? $pub_data["date"] : $placeholder; TP_HTML::line('
'); TP_HTML::line('

'); - TP_HTML::line(''); + $tabindex++; + TP_HTML::line(''); TP_HTML::div_close('div_urldate'); // url @@ -796,7 +838,8 @@ public static function get_main_box ($pub_id, $pub_data) { TP_HTML::line('

| '); TP_HTML::line(' ' . __('Add/Upload','teachpress') . '

'); TP_HTML::line(''); - TP_HTML::line(''); + $tabindex++; + TP_HTML::line(''); TP_HTML::div_close('div_url'); TP_HTML::div_close('inside'); diff --git a/core/class-tables.php b/core/class-tables.php index 2701a3f..388f33c 100644 --- a/core/class-tables.php +++ b/core/class-tables.php @@ -165,6 +165,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), diff --git a/core/class-update.php b/core/class-update.php index c1fc2b7..3040554 100644 --- a/core/class-update.php +++ b/core/class-update.php @@ -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 @@ -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 diff --git a/core/general.php b/core/general.php index 2822597..5bc7be4 100644 --- a/core/general.php +++ b/core/general.php @@ -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 . ''; + } + return $award; +} + + /** * Returns the default structure for a publication array * @return array @@ -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' => '', diff --git a/core/publications/class-award.php b/core/publications/class-award.php new file mode 100644 index 0000000..3556047 --- /dev/null +++ b/core/publications/class-award.php @@ -0,0 +1,73 @@ + '', + '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); +} \ No newline at end of file diff --git a/core/publications/class-db-publications.php b/core/publications/class-db-publications.php index df9b621..37df1fd 100644 --- a/core/publications/class-db-publications.php +++ b/core/publications/class-db-publications.php @@ -74,6 +74,7 @@ public static function get_publications($args = array(), $count = false) { $defaults = array( 'user' => '', 'type' => '', + 'award' => '', 'tag' => '', 'key' => '', 'author_id' => '', @@ -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 = ''; @@ -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'], @@ -414,7 +416,7 @@ 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; // Bookmarks @@ -488,9 +490,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'], @@ -528,7 +531,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); @@ -756,9 +759,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' => '', diff --git a/core/publications/default-awards.php b/core/publications/default-awards.php new file mode 100644 index 0000000..5c00082 --- /dev/null +++ b/core/publications/default-awards.php @@ -0,0 +1,34 @@ + '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' + ) ); + +} diff --git a/core/publications/templates.php b/core/publications/templates.php index 7dca766..9c51e53 100644 --- a/core/publications/templates.php +++ b/core/publications/templates.php @@ -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 = ''; + if ($withLabel) { + $s .= ' '.$award_data["i18n_singular"]; + } + $s .= ""; + return $s; + } + return ""; + } + /** * Returns the meta row * @return string diff --git a/readme.txt b/readme.txt index df410da..ff32ee2 100644 --- a/readme.txt +++ b/readme.txt @@ -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() diff --git a/teachpress.php b/teachpress.php index e5cc7fd..8d4dcbf 100644 --- a/teachpress.php +++ b/teachpress.php @@ -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'); @@ -470,6 +472,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'); diff --git a/templates/tp_template_2021.css b/templates/tp_template_2021.css index ef9c17c..7c06b8c 100644 --- a/templates/tp_template_2021.css +++ b/templates/tp_template_2021.css @@ -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; diff --git a/templates/tp_template_2021.php b/templates/tp_template_2021.php index 0436506..3338e4b 100644 --- a/templates/tp_template_2021.php +++ b/templates/tp_template_2021.php @@ -90,7 +90,12 @@ public function get_entry ($interface) { $s .= $interface->get_images('left'); $s .= '
'; $s .= $interface->get_author('

', '

'); - $s .= '

' . $interface->get_title() . ' ' . $interface->get_type() . ' ' . $interface->get_label('status', array('forthcoming') ) . '

'; + $s .= '

' . $interface->get_title(); + $award = $interface->get_award(true); + if ($award != ""){ + $s .= ' ' . $award; + } + $s .= ' ' . $interface->get_type() . ' ' . $interface->get_label('status', array('forthcoming') ) . '

'; $s .= '

' . $interface->get_meta() . '

'; $s .= '

' . $interface->get_menu_line() . '

'; $s .= $interface->get_infocontainer(); From 795a2adb8d2c5166134a36535b0a67cfb72cc6fe Mon Sep 17 00:00:00 2001 From: winkm89 Date: Tue, 23 Aug 2022 20:40:47 +0200 Subject: [PATCH 2/3] Fix for #201 --- core/shortcodes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shortcodes.php b/core/shortcodes.php index 9fee6f1..af54b7d 100644 --- a/core/shortcodes.php +++ b/core/shortcodes.php @@ -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; From eff5384b39c492f2fc2e42e44cb530fde3804e18 Mon Sep 17 00:00:00 2001 From: winkm89 Date: Tue, 23 Aug 2022 20:46:40 +0200 Subject: [PATCH 3/3] Display error messages why publications could not be imported or added --- core/publications/class-db-publications.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/publications/class-db-publications.php b/core/publications/class-db-publications.php index df9b621..d420a39 100644 --- a/core/publications/class-db-publications.php +++ b/core/publications/class-db-publications.php @@ -416,6 +416,12 @@ public static function add_publication($data, $tags, $bookmark = array() ) { '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' ) ); $pub_id = $wpdb->insert_id; + + // Error message for the user: + if ( $pub_id === 0 && $wpdb->last_error !== '' ) { + get_tp_message($data['title'] . ':
  • ' . $wpdb->last_error . '
', 'red'); + //var_dump($data); + } // Bookmarks if ( !empty( $bookmark ) ) {