add_help_tab( array( 'id' => 'tp_import_publication_page_help', 'title' => __('Import'), 'content' => '

' . __('Import') . '

' . __("Use the file upload or add your BibTeX entries directly in the textfield. Restrictions: teachPress can't convert not numeric month and day attributes.",'teachpress') . '

' . __('Supported file types', 'teachpress') . ': .txt, .bib

', ) ); } /** * The controller for the import page of teachPress * @since 6.0.0 */ function tp_show_import_publication_page() { $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : ''; $import_id = isset( $_GET['import_id'] ) ? intval($_GET['import_id']) : 0; $delete_import = isset ( $_GET['teachpress_delete_import'] ) ? $_GET['teachpress_delete_import'] : ''; $checkbox = isset ( $_GET['checkbox'] ) ? $_GET['checkbox'] : ''; $set_menu_1 = ( $tab === 'import' || $tab === '' ) ? 'nav-tab nav-tab-active' : 'nav-tab'; $set_menu_2 = ( $tab === 'export' ) ? 'nav-tab nav-tab-active' : 'nav-tab'; $set_menu_3 = ( $tab === 'exist' ) ? 'nav-tab nav-tab-active' : 'nav-tab'; echo '
'; echo '

' . __('Publications','teachpress') . '

'; echo ''; // For actions if ( isset($_POST['tp_submit']) || isset($_POST['tp_bookmark']) || isset($_POST['tp_delete']) ) { TP_Import_Publication_Page::import_actions($_POST); } else { // Import if ( $tab === '' || $tab === 'import' ) { TP_Import_Publication_Page::import_tab($tab); } // Export if ( $tab === 'export' ) { TP_Import_Publication_Page::export_tab(); } // List of Imports if ( $tab === 'exist' && $import_id === 0 ) { TP_Import_Publication_Page::exist_tab($import_id, $delete_import, $checkbox); } // Show the list of publications, which were imported with the selected import if ( $tab === 'exist' && $import_id !== 0 ) { $entries = TP_Publications::get_publications( array( 'import_id' => $import_id, 'output_type' => ARRAY_A ) ); TP_Import_Publication_Page::show_results($entries, 'history'); } echo '
'; } } /** * This class contains function for generating the import_publication_page * @since 6.0.0 */ class TP_Import_Publication_Page { /** * This function executes all import action calls * @global object $current_user * @param array $post The $_POST array * @since 6.0.0 * @access public */ public static function import_actions ($post) { $current_user = wp_get_current_user(); $tp_bookmark = isset( $post['tp_bookmark'] ) ? $post['tp_bookmark'] : ''; $tp_delete = isset( $post['tp_delete'] ) ? $post['tp_delete'] : ''; $checkbox = isset( $post['checkbox'] ) ? $post['checkbox'] : ''; // add bookmarks if ( $tp_bookmark !== '' && $checkbox !== '' ) { $max = count($checkbox); for ( $i = 0; $i < $max; $i++ ) { TP_Bookmarks::add_bookmark( intval($checkbox[$i]), $current_user->ID ); } get_tp_message( __('Publications added to your list.','teachpress') ); } // delete publication if ( $tp_delete !== '' && $checkbox !== '' ) { TP_Publications::delete_publications($post['checkbox']); get_tp_message( __('Removing successful','teachpress') ); } // error messages if ( ( $tp_bookmark !== '' || $tp_delete !== '' ) && $checkbox === '' ) { get_tp_message( __('Warning: No publication was selected.','teachpress') ); } // import from textarea or file $file_name = isset($_FILES['file']['tmp_name']) ? htmlentities($_FILES['file']['tmp_name']) : ''; $bibtex_area = isset($post['bibtex_area']) ? $post['bibtex_area'] : ''; // Check file name if ( $file_name !== '' ) { $file_type = substr(htmlentities($_FILES['file']['name']),-4,4); if ( substr($file_type,-4,4) !== '.txt' && substr($file_type,-4,4) !== '.bib' ) { get_tp_message(__('No supported file type','teachpress')); exit(); } } // if there is something to import if ( $file_name !== '' || $bibtex_area !== '' ) { // Check nonce field TP_Import_Publication_Page::check_nonce_field(); if ( $file_name !== '' ) { $bibtex = file_get_contents ( $file_name ); // Check if string is utf8 or not if ( TP_Bibtex::is_utf8($bibtex) === false ) { $bibtex = utf8_encode($bibtex); } } else { $bibtex = stripslashes($bibtex_area); } $settings = array( 'keyword_separator' => htmlspecialchars($post['keyword_option']), 'author_format' => htmlspecialchars($post['author_format']), 'overwrite' => isset( $post['overwrite'] ) ? true : false, 'ignore_tags' => isset( $post['ignore_tags'] ) ? true : false, ); // echo $bibtex; // add publications to database $entries = TP_Bibtex_Import::init($bibtex, $settings); } // import from PubMed elseif ( array_key_exists('tp_pmid', $post) && $post['tp_pmid'] !== '' ) { // Check nonce field TP_Import_Publication_Page::check_nonce_field(); $settings = array( 'overwrite' => isset( $post['overwrite'] ), 'ignore_tags' => isset( $post['ignore_tags'] ), ); $entries = TP_PubMed_Import::init( $post['tp_pmid'], $settings ); } // import from Crossref elseif ( array_key_exists('tp_crossref', $post) && $post['tp_crossref'] !== '' ) { // Check nonce field TP_Import_Publication_Page::check_nonce_field(); $settings = array( 'overwrite' => isset( $post['overwrite'] ), 'ignore_tags' => isset( $post['ignore_tags'] ), ); $entries = TP_Crossref_Import::init( $post['tp_crossref'], $settings ); } // if there is no import else { $tp_entries = ( isset($post['tp_entries']) ) ? htmlspecialchars($post['tp_entries'] ) : '0'; $entries = TP_Publications::get_publications( array( 'include' => $tp_entries, 'output_type' => ARRAY_A ) ); } TP_Import_Publication_Page::show_results($entries); } /** * Shows the import form * @param string $tab * @since 6.0.0 * @access public */ public static function import_tab () { ?>


( )

'; } // Ignore tags option echo TP_Admin::get_checkbox( 'ignore_tags', __('Ignore Tags','teachpress'), '', __('Ignore tags or keywords in the import data.','teachpress')); ?>




num_queries . ' | Time: ' . timer_stop() . 's'); } echo '
'; if ( $mode !== 'history' ) { echo '

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

'; } echo '

' . __('Imported Publications','teachpress') . '

'; echo '
'; echo '

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $array_id = ''; if ( count($entries) === 0 ) { echo ''; } foreach ( $entries as $entry ) { $value = ( isset($_POST['tp_submit']) && isset ($_POST['bibtex_area']) ) ? intval($entry['entry_id']) : intval($entry['pub_id']); $author = ( array_key_exists('author', $entry) === true ) ? $entry['author'] : ''; echo ''; if ( TP_Bookmarks::bookmark_exists($value, $current_user->ID) === true ) { echo ''; } else { echo ''; } echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $array_id .= $value . ','; } echo ''; echo '
' . __('Title','teachpress') . '' . __('ID') . '' . __('Type') . '' . __('Author(s)','teachpress') . '' . __('Year','teachpress') . '
' . __('Sorry, no entries matched your criteria.','teachpress') . '
' . $entry['title'] . '' . $value . '' . tp_translate_pub_type( $entry['type'] ) . '' . $author . ''; if ( array_key_exists('year', $entry) ) { echo $entry['year']; } elseif ( array_key_exists('date', $entry) ) { echo $entry['date']; } echo '
'; echo ''; echo '

'; echo '
'; } /** * Displays the export tab of the import page * @since 6.0.0 * @access public */ public static function export_tab () { ?>

' . __('List of imports','teachpress') . ''; echo '
'; echo ''; echo ''; // Delete imports part 2 if ( isset($_GET['delete_import_ok']) ) { tp_publication_imports::delete_import($checkbox); $message = __('Removing successful','teachpress'); get_tp_message($message); } // Delete imports part 1 if ( $delete_import !== "" ) { echo '

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

' . __('Cancel','teachpress') . '

'; } // Default buttons else { echo '
'; echo ''; echo '
'; } // Load data $wp_id = get_current_user_id(); $list = tp_publication_imports::get_imports($wp_id); $users = get_users(); $publications_count = tp_publication_imports::count_publications(); // Generate user list $user_list = array(); foreach ( $users as $user ) { $user_list[$user->ID] = $user->display_name; } // Generate number list $number_list = array(); foreach ( $publications_count as $row ) { $number_list[$row['import_id']] = $row['number']; } // List of imports echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; //Print rows $class_alternate = true; foreach ( $list as $row ) { $tr_class = ( $class_alternate === true ) ? 'class="alternate"' : ''; $class_alternate = ( $class_alternate === true ) ? false : true; $user_name = ( isset( $user_list[$row['wp_id']] ) ) ? $user_list[$row['wp_id']] : ''; $number = ( isset( $number_list[$row['id']] ) ) ? $number_list[$row['id']] : 0; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
'; echo '' . __('Date') . '' . __('User','teachpress') . '' . __('Number publications','teachpress') . '
' . $row['date'] . '' . $user_name . '' . $number . '
'; } /** * Checks the nonce field of the form. If the check fails wp_die() will be executed */ public static function check_nonce_field () { if ( ! isset( $_POST['tp_nonce'] ) || ! wp_verify_nonce( $_POST['tp_nonce'], 'verify_teachpress_import' ) ) { wp_die('teachPress error: This request could not be verified!'); exit; } } }