id != $tp_admin_all_pub_page && $screen->id != $tp_admin_your_pub_page ) ) {
return;
}
$args = array(
'label' => __('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' => __('Display publications','teachpress'),
'content' => '
' . __('Shortcodes') . '
' . __('You can use publications in a page or article with the following shortcodes:','teachpress') . '
' . __('For a single publication:','teachpress') . '[tpsingle]
' . __('For a publication list with tag cloud:','teachpress') . ' [tpcloud]
' . __('For normal publication lists:','teachpress') . ' [tplist]
' . __('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( __('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( __('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( __('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 '' . __('BibTeX','teachpress') . ' ';
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 '' . __('Bulk editing','teachpress') . ' ';
echo '';
echo '';
echo '
' . __('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_" . $row['tag_id'] . "', 'tag_label_" . $row['tag_id'] . "')";
echo' ' . $row['name'] . ' | ';
}
echo '
';
TP_HTML::line('
' . __('New','teachpress') . '
');
TP_HTML::line('
');
$tags = TP_Tags::get_tags( array('group_by' => true, 'output_type' => ARRAY_A) );
foreach ($tags as $row) {
TP_HTML::line('' . $row['name'] . ' ');
}
TP_HTML::line(' ');
echo '
';
echo '' . __('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) {
echo '+ ';
}
}
else {
// Delete from your own list icon
echo '« ';
}
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('');
echo '' . TP_HTML::prepare_title($row->title, 'decode') . ' ';
if ( $row->status === 'forthcoming' ) {
echo '' . __('Forthcoming','teachpress') . ' ';
}
echo '';
TP_HTML::line(' ');
TP_HTML::line('' . $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) . ' (' . __('Ed.','teachpress') . ') ');
}
else {
TP_HTML::line('' . TP_Bibtex::parse_author_simple($row->author) . ' ');
}
TP_HTML::line('');
echo 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('');
TP_HTML::line('- ' . __('All tags','teachpress') . ' - ');
$haystack = ( $array_variables['tag_id'] != '' ) ? explode(',', $array_variables['tag_id'] ): array();
foreach ( $array_tags as $row ) {
$selected = ( in_array($row['tag_id'], $haystack) ) ? 'selected="selected"' : '';
TP_HTML::line('' . $row['name'] . ' ');
}
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('');
TP_HTML::line('- ' . __('All types','teachpress') . ' - ');
$haystack = ( $array_variables['type'] != '' ) ? explode(',', $array_variables['type'] ): array();
foreach ( $array_types as $row ) {
$selected = ( in_array($row['type'], $haystack) ) ? 'selected="selected"' : '';
TP_HTML::line('' . tp_translate_pub_type($row['type'],'pl') . ' ');
}
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('');
TP_HTML::line('- ' . __('All years','teachpress') . ' - ');
$haystack = ( $array_variables['year'] != '' ) ? explode(',', $array_variables['year'] ): array();
foreach ( $array_years as $row ) {
$selected = ( in_array( $row['year'], $haystack) ) ? 'selected="selected"' : '';
TP_HTML::line('' . $row['year'] . ' ');
}
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'] == '') ? __('All publications','teachpress') : __('Your publications','teachpress');
TP_HTML::line('');
TP_HTML::line('');
TP_HTML::line(' ');
TP_HTML::line(' ');
echo wp_nonce_field( 'verify_teachpress_pub_ui', 'tp_nonce', false, false );
// Delete publications - part 1
if ( $array_variables['action'] == "delete" ) {
TP_HTML::line('');
}
$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('');
if ( $array_variables['search'] != '' ) {
TP_HTML::line( '
X ');
}
TP_HTML::line('
');
TP_HTML::line('
');
TP_HTML::div_close('tp_searchbox');
// Actions
TP_HTML::line('
');
TP_HTML::div_open('alignleft actions');
TP_HTML::line('
');
TP_HTML::line('- ' . __('Bulk actions','teachpress') . ' - ');
TP_HTML::line('' . __('Edit','teachpress') . ' ');
TP_HTML::line('' . __('Show as BibTeX entry','teachpress') . ' ');
if ( $array_variables['page'] === 'publications.php' ) {
TP_HTML::line('' . __('Add to your own list','teachpress') . ' ');
TP_HTML::line('' . __('Delete','teachpress') . ' ');
}
TP_HTML::line(' ');
TP_HTML::line('
');
TP_HTML::div_close('alignleft actions');
// Filters
TP_HTML::div_open('alignleft actions slim-select');
TP_Publications_Page::get_type_filter($array_variables, $user);
TP_Publications_Page::get_year_filter($array_variables, $user);
TP_Publications_Page::get_tag_filter($array_variables, $user);
TP_HTML::line('
' . __('Limit selection','teachpress') . ' ');
TP_HTML::div_close('alignleft actions');
// Page Menu
$link = 'search=' . $array_variables['search'] . '&type=' . $array_variables['type'] . '&tag=' . $array_variables['tag_id'] . '&tp_year=' . $array_variables['year'] . '&orderby=' . $array_variables['order'];
echo tp_page_menu(array('number_entries' => $test,
'entries_per_page' => $array_variables['per_page'],
'current_page' => $array_variables['curr_page'],
'entry_limit' => $array_variables['entry_limit'],
'page_link' => 'admin.php?page=' . $array_variables['page'] . '&',
'link_attributes' => $link));
TP_HTML::div_close('tablenav');
// Publication table
TP_HTML::line('
');
TP_HTML::line('');
TP_HTML::line('');
TP_HTML::line(' ');
TP_HTML::line(' ');
TP_HTML::line('' . TP_Publications_Page::get_order_link( 'title', __('Title','teachpress'), $array_variables) . ' ');
TP_HTML::line('' . TP_Publications_Page::get_order_link( 'pub_id', __('ID'), $array_variables) . ' ');
TP_HTML::line('' . __('Type') . ' ');
TP_HTML::line('' . __('Author(s)','teachpress') . ' ');
TP_HTML::line('' . __('Tags') . ' ');
TP_HTML::line('' . __('Year','teachpress') . ' ');
TP_HTML::line(' ');
TP_HTML::line(' ');
TP_HTML::line('');
// Bulk edit
if ( $array_variables['action'] === 'edit' && $array_variables['checkbox'] !== '' ) {
TP_Publications_Page::get_bulk_edit_screen($array_variables);
}
if ( intval($test) === 0 ) {
TP_HTML::line('' . __('Sorry, no entries matched your criteria.','teachpress') . ' ');
}
else {
$row = TP_Publications::get_publications($args);
$class_alternate = true;
$get_string = '&search=' . $array_variables['search'] . '&type=' . $array_variables['type'] . '&limit=' . $array_variables['curr_page'] . '&site=' . $array_variables['page'] . '&tag=' . $array_variables['tag_id'] . '&tp_year=' . $array_variables['year'] . '&orderby=' . $array_variables['order'];
foreach ($row as $row) {
if ( $class_alternate === true ) {
$tr_class = 'class="alternate"';
$class_alternate = false;
}
else {
$tr_class = '';
$class_alternate = true;
}
TP_Publications_Page::get_publication_row($row, $array_variables, $bookmarks, $tags, $tr_class, $get_string);
}
}
TP_HTML::line(' ');
TP_HTML::line('');
TP_HTML::line('');
if ( $test > $array_variables['per_page'] ) {
echo tp_page_menu(array('number_entries' => $test,
'entries_per_page' => $array_variables['per_page'],
'current_page' => $array_variables['curr_page'],
'entry_limit' => $array_variables['entry_limit'],
'page_link' => 'admin.php?page=' . $array_variables['page'] . '&',
'link_attributes' => $link,
'mode' => 'bottom'));
}
else {
if ($test === 1) {
echo "$test " . __('entry','teachpress');
}
else {
echo "$test " . __('entries','teachpress');
}
}
TP_HTML::line( '
' );
// print_scripts
TP_Publications_Page::print_scripts();
TP_HTML::line( '' );
}
/**
* Returns the navigations link for changing the sort order of the table
* @param string $field table field
* @param string $title
* @param array $array_variables
*/
private static function get_order_link ($field, $title, $array_variables) {
// pub_id
if ( $field === 'pub_id' ) {
switch ( $array_variables['order'] ) {
case 'date DESC, title ASC' :
$val = 'pub_id ASC';
$sim = '';
break;
case 'pub_id ASC':
$val = 'pub_id DESC';
$sim = '↓';
break;
case 'pub_id DESC':
$val = 'date DESC, title ASC';
$sim = '↑';
break;
default:
$val = 'pub_id ASC';
$sim = '';
}
}
// title
if ( $field === 'title' ) {
switch ( $array_variables['order'] ) {
case 'date DESC, title ASC' :
$val = 'title ASC';
$sim = '';
break;
case 'title ASC':
$val = 'title DESC';
$sim = '↓';
break;
case 'title DESC':
$val = 'date DESC, title ASC';
$sim = '↑';
break;
default:
$val = 'title ASC';
$sim = '';
}
}
// set link attributes
$link = 'search=' . $array_variables['search'] . '&type=' . $array_variables['type'] . '&tag=' . $array_variables['tag_id'] . '&tp_year=' . $array_variables['year'] . '&orderby=' . $val;
// return link
return '' . $title . ' ' . $sim . '';
}
/**
* Checks the nonce field of the form. If the check fails wp_die() will be executed
* @since 9.0.5
*/
public static function check_nonce_field () {
if ( ! isset( $_GET['tp_nonce'] )
|| ! wp_verify_nonce( $_GET['tp_nonce'], 'verify_teachpress_pub_ui' )
) {
wp_die('teachPress error: This request could not be verified!');
exit;
}
}
/**
* Prints the js scripts
* @since 6.0.0
*/
public static function print_scripts () {
?>