id != $tp_admin_all_pub_page && $screen->id != $tp_admin_your_pub_page ) ) { return; } $args = array( 'label' => esc_html__('Items per page', 'teachpress'), 'default' => 50, 'option' => 'tp_pubs_per_page' ); add_screen_option( 'per_page', $args ); } /** * Add help tab for show publications page */ function tp_show_publications_page_help () { $screen = get_current_screen(); $screen->add_help_tab( array( 'id' => 'tp_show_publications_help', 'title' => esc_html__('Display publications','teachpress'), 'content' => '

' . esc_html__('Shortcodes') . '

' . esc_html__('You can use publications in a page or article with the following shortcodes:','teachpress') . '

' . esc_html__('For a single publication:','teachpress') . '[tpsingle]

' . esc_html__('For a publication list with tag cloud:','teachpress') . ' [tpcloud]

' . esc_html__('For normal publication lists:','teachpress') . ' [tplist]

' . esc_html__('More information','teachpress') . '

teachPress Shortcode Reference (engl.)

', ) ); } /** * Controller for show publications page * @global object $current_user * @since 5.0.0 */ function tp_show_publications_page() { // WordPress User informations $current_user = wp_get_current_user(); // teachPress Publication Types global $tp_publication_types; // Get screen options $screen = get_current_screen(); $screen_option = $screen->get_option('per_page', 'option'); $per_page = get_user_meta($current_user->ID, $screen_option, true); if ( empty ( $per_page) || $per_page < 1 ) { $per_page = $screen->get_option( 'per_page', 'default' ); } $array_variables['checkbox'] = isset( $_GET['checkbox'] ) ? $_GET['checkbox'] : ''; $array_variables['action'] = isset( $_GET['action'] ) ? $_GET['action'] : ''; $array_variables['page'] = isset( $_GET['page'] ) ? htmlspecialchars($_GET['page']) : ''; $array_variables['type'] = ( isset( $_GET['type'] ) && intval($_GET['type']) !== 0 ) ? tp_convert_input_to_string($_GET['type']) : ''; $array_variables['year'] = ( isset( $_GET['tp_year'] ) && intval($_GET['tp_year']) !== 0 ) ? tp_convert_input_to_string($_GET['tp_year'], 'int') : ''; $array_variables['order'] = isset( $_GET['orderby'] ) ? htmlspecialchars($_GET['orderby']) : 'date DESC, title ASC'; $array_variables['search'] = isset( $_GET['search'] ) ? htmlspecialchars($_GET['search']) : ''; $array_variables['tag_id'] = isset( $_GET['tag'] ) ? tp_convert_input_to_string($_GET['tag'], 'int') : ''; $user = $current_user->ID; // Page menu $array_variables['per_page'] = $per_page; // Handle limits if ( isset($_GET['limit']) ) { $array_variables['curr_page'] = intval($_GET['limit']); if ( $array_variables['curr_page'] <= 0 ) { $array_variables['curr_page'] = 1; } $array_variables['entry_limit'] = ( $array_variables['curr_page'] - 1 ) * $per_page; } else { $array_variables['entry_limit'] = 0; $array_variables['curr_page'] = 1; } echo '
'; // Chech order statements $acceaptable = ['date DESC, title ASC', 'pub_id ASC', 'pub_id DESC', 'date ASC', 'date DESC', 'title ASC', 'title DESC']; $array_variables['order'] = in_array($array_variables['order'], $acceaptable) ? $array_variables['order'] : 'date DESC, title ASC'; // test if teachpress database is up to date TP_Admin::database_test(); // Add a bookmark for the publication if ( isset( $_GET['add_id'] ) ) { TP_Bookmarks::add_bookmark( $_GET['add_id'], $current_user->ID ); } // Delete bookmark for the publication if ( isset( $_GET['del_id'] ) ) { TP_Bookmarks::delete_bookmark( $_GET['del_id'] ); } // Add a bookmark for the publication (bulk version) if ( $array_variables['action'] === 'add_list' ) { TP_Publications_Page::check_nonce_field(); $max = count( $array_variables['checkbox'] ); for( $i = 0; $i < $max; $i++ ) { $array_variables['checkbox'][$i] = intval($array_variables['checkbox'][$i]); $test = TP_Bookmarks::bookmark_exists($array_variables['checkbox'][$i], $current_user->ID); if ( $test === false ) { TP_Bookmarks::add_bookmark( $array_variables['checkbox'][$i], $current_user->ID ); } } get_tp_message( esc_html__('Publications added','teachpress') ); } // delete publications - part 2 if ( isset($_GET['delete_ok']) ) { TP_Publications_Page::check_nonce_field(); TP_Publications::delete_publications($array_variables['checkbox']); get_tp_message( esc_html__('Removing successful','teachpress') ); } // Bulk edit of publications if ( isset($_GET['bulk_edit']) ) { TP_Publications_Page::check_nonce_field(); $mass_edit = ( isset($_GET['mass_edit']) ) ? $_GET['mass_edit'] : ''; $tags = ( isset($_GET['add_tags']) ) ? TP_Publication_Page::prepare_tags($_GET['add_tags']) : ''; $delbox = ( isset($_GET['delbox']) ) ? $_GET['delbox'] : array(); TP_Tags::change_tag_relations($mass_edit, $tags, $delbox); get_tp_message( esc_html__('Bulk edit executed','teachpress') ); } // Show page if ( $array_variables['action'] === 'bibtex' ) { TP_Publications_Page::get_bibtex_screen($array_variables); } else { TP_Publications_Page::get_tab($user, $array_variables); } echo '
'; } /** * This class contains all functions for the show publications screen * @package teachpress\admin\publications * @since 5.0.0 */ class TP_Publications_Page { /** * bibtex mode for show publications page * @param array $array_variables * @since 5.0.0 */ public static function get_bibtex_screen($array_variables) { $convert_bibtex = ( get_tp_option('convert_bibtex') == '1' ) ? true : false; $sel = ''; echo '

' . esc_html__('BibTeX','teachpress') . '

'; echo '
'; TP_HTML::line( '

← ' . esc_html__('Back','teachpress') . '

' ); echo ''; echo '
'; echo ''; if ( $sel != '' ) { echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; } } /** * Bulk edit screen for show publications page * @param array $array_variables * @since 5.0.0 */ public static function get_bulk_edit_screen($array_variables) { $selected_publications = ''; $max = count($array_variables['checkbox']); for ( $i = 0; $i < $max; $i++ ) { $selected_publications = ( $selected_publications === '' ) ? $array_variables['checkbox'][$i] : $selected_publications . ',' . $array_variables['checkbox'][$i]; } echo ''; echo ''; echo '

' . esc_html__('Bulk editing','teachpress') . '

'; echo '
'; echo ''; echo '
'; echo '
'; echo '

' . esc_html__('Delete current tags','teachpress') . '

'; $used_tags = TP_Tags::get_tags( array('pub_id' => $selected_publications, 'output_type' => ARRAY_A, 'group_by' => true) ); $s = "'"; echo '

'; foreach ( $used_tags as $row ) { $onclick = "teachpress_change_label_color('checkbox_" . intval($row['tag_id']) . "', 'tag_label_" . intval($row['tag_id']) . "')"; TP_HTML::line( ' | ' ); } echo '

'; TP_HTML::line('

'); TP_HTML::line(''); echo '
'; TP_HTML::line( '

' . esc_html__('Cancel') . '

' ); echo ''; echo ''; ?> '); TP_HTML::line(''); // check if the publication is already in users publication list $test2 = false; foreach ( $bookmarks as $bookmark ) { if ( $bookmark['pub_id'] == $row->pub_id ) { $test2 = $bookmark['bookmark_id']; break; } } if ( $array_variables['page'] === 'publications.php' ) { // Add to your own list icon if ( $test2 === false ) { TP_HTML::line( '+' ); } } else { // Delete from your own list icon TP_HTML::line( '«' ); } TP_HTML::line(''); $checked = ''; if ( ( $array_variables['action'] === "delete" || $array_variables['action'] === "edit" ) && is_array($array_variables['checkbox']) ) { $max = count( $array_variables['checkbox'] ); for( $k = 0; $k < $max; $k++ ) { if ( $row->pub_id == $array_variables['checkbox'][$k] ) { $checked = 'checked="checked" '; } } } TP_HTML::line(''); TP_HTML::line(''); TP_HTML::line( '' . TP_HTML::prepare_title($row->title, 'decode') . '' ); if ( $row->status === 'forthcoming' ) { echo '' . esc_html__('Forthcoming','teachpress') . ''; } TP_HTML::line( '
' . esc_html__('Edit','teachpress') . ' | ' . esc_html__('Cite', 'teachpress') . ' | ' . esc_html__('Delete','teachpress') . '
' ); TP_HTML::line(''); TP_HTML::line('' . intval($row->pub_id) . ''); TP_HTML::line('' . tp_translate_pub_type($row->type) . ''); if ( $row->type === 'collection' || ( $row->author === '' && $row->editor !== '' ) ) { TP_HTML::line('' . TP_Bibtex::parse_author_simple($row->editor) . ' (' . esc_html__('Ed.','teachpress') . ')'); } else { TP_HTML::line('' . TP_Bibtex::parse_author_simple($row->author) . ''); } TP_HTML::line(''); TP_HTML::line( TP_Publications_Page::get_tags_for_single_row($row->pub_id, $tags, $array_variables) ); TP_HTML::line(''); TP_HTML::line('' . $row->year . ''); TP_HTML::line(''); } /** * Returns the tags for a publication * @param int $pub_id * @param array $tags * @param array $array_variables * @since 5.0.0 * @access private */ private static function get_tags_for_single_row ($pub_id, $tags, $array_variables) { $tag_string = ''; foreach ($tags as $temp) { if ( $temp["pub_id"] != $pub_id ) { continue; } if ( $temp["tag_id"] == $array_variables['tag_id'] ) { $tag_string .= '' . stripslashes($temp["name"]) . ', '; } else { $tag_string .= '' . stripslashes($temp["name"]) . ', '; } } return substr($tag_string, 0, -2); } /** * Gets the filter box for publication tags * @param array $array_variables An associative array * @param int $user The ueser ID * @since 5.0.0 * @access private */ private static function get_tag_filter ($array_variables, $user) { $array_tags = TP_Tags::get_tags( array( 'user' => ($array_variables['page'] == 'publications.php') ? '' : $user, 'group_by' => true, 'order' => 'ASC', 'output_type' => ARRAY_A) ); TP_HTML::line(''); } /** * Gets the filter box for publication types * @param array $array_variables An associative array * @param int $user The user ID * @since 5.0.0 * @access private */ private static function get_type_filter ($array_variables, $user) { $array_types = TP_Publications::get_used_pubtypes( array( 'user' => ($array_variables['page'] == 'publications.php') ? '' : $user ) ); TP_HTML::line(''); } /** * Gets the filter box for publication years * @param array $array_variables An associative array * @param int $user The ueser ID * @since 5.0.0 * @access private */ private static function get_year_filter ($array_variables, $user) { $array_years = TP_Publications::get_years( array( 'order' => 'DESC', 'user' => ($array_variables['page'] == 'publications.php') ? '' : $user, 'output_type' => ARRAY_A ) ); TP_HTML::line(''); } /** * Show publications main screen * @param int $user * @param array $array_variables * @since 5.0.0 */ public static function get_tab($user, $array_variables) { $title = ($array_variables['page'] == 'publications.php' && $array_variables['search'] == '') ? esc_html__('All publications','teachpress') : esc_html__('Your publications','teachpress'); TP_HTML::line('

' . $title . '' . esc_html__('Add new','teachpress') . '

'); TP_HTML::line('
'); TP_HTML::line(''); TP_HTML::line(''); wp_nonce_field( 'verify_teachpress_pub_ui', 'tp_nonce', false, true ); // Delete publications - part 1 if ( $array_variables['action'] == "delete" ) { TP_HTML::line('

' . esc_html__('Do you want to delete the selected items?','teachpress') . '

' . esc_html__('Cancel','teachpress') . '

'); } $args = array('search' => $array_variables['search'], 'user' => ($array_variables['page'] == 'publications.php') ? '' : $user, 'tag' => $array_variables['tag_id'], 'year' => $array_variables['year'], 'limit' => $array_variables['entry_limit'] . ',' . $array_variables['per_page'], 'type' => $array_variables['type'], 'order' => $array_variables['order'] ); $test = TP_Publications::get_publications($args, true); // Load tags $tags = TP_Tags::get_tags( array('output_type' => ARRAY_A) ); // Load bookmarks $bookmarks = TP_Bookmarks::get_bookmarks( array('user'=> $user, 'output_type' => ARRAY_A) ); // Searchbox TP_HTML::line('