From 706bb06bef4d0b4865db3d8eb0e59fa1ab5b6b6e Mon Sep 17 00:00:00 2001 From: Matthias Einbrodt Date: Thu, 7 Sep 2017 11:32:00 +0200 Subject: [PATCH 1/3] Allows to define a custom doi resolver using a doi resolver html template --- admin/settings.php | 13 ++++++++++++ core/class-tables.php | 2 ++ core/templates.php | 46 +++++++++++++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/admin/settings.php b/admin/settings.php index 23022f7..eebd25b 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -418,6 +418,17 @@ private static function get_publication_tab() { echo '' . __('Overwrite publications','teachpress') . ''; echo '' . tp_admin::get_checkbox('import_overwrite', __('Allow optional overwriting for publication import','teachpress'), get_tp_option('import_overwrite')) . ' (EXPERIMENTAL)'; echo ''; + + echo ''; + echo '

' . __('DOI Resolver','teachpress') . '

'; + echo ''; + + echo ''; + echo '' . __('Custom Url Template','teachpress') . ''; + echo ''; + echo '

' . __('Define a custom doi resolver template which overrides the default one: ','teachpress') . '' . get_tp_option('doi_resolver_url_template_default') . '

'; + echo ''; + echo ''; echo ''; echo '

' . __('Related content','teachpress') . '

'; @@ -825,9 +836,11 @@ private static function change_general_options () { private static function change_publication_options () { $checkbox_convert_bibtex = isset( $_POST['convert_bibtex'] ) ? 1 : ''; $checkbox_import_overwrite = isset( $_POST['import_overwrite'] ) ? 1 : ''; + $doi_resolver_url_template_custom = isset( $_POST['doi_resolver_url_template_custom'] ) ? esc_url_raw( $_POST['doi_resolver_url_template_custom'] ) : ''; $checkbox_rel_content_auto = isset( $_POST['rel_content_auto'] ) ? 1 : ''; tp_options::change_option('convert_bibtex', $checkbox_convert_bibtex, 'checkbox'); tp_options::change_option('import_overwrite', $checkbox_import_overwrite, 'checkbox'); + tp_options::change_option('doi_resolver_url_template_custom', $doi_resolver_url_template_custom); tp_options::change_option('rel_content_auto', $checkbox_rel_content_auto, 'checkbox'); tp_options::change_option('rel_content_template', $_POST['rel_content_template']); tp_options::change_option('rel_content_category', $_POST['rel_content_category']); diff --git a/core/class-tables.php b/core/class-tables.php index 084f9f6..ab5f385 100644 --- a/core/class-tables.php +++ b/core/class-tables.php @@ -429,6 +429,8 @@ public static function add_default_settings(){ $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_category', '', 'system')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('import_overwrite', '0', 'system')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('convert_bibtex', '0', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_default', 'https://dx.doi.org/%doi%', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_custom', '', 'system')"); // Example values $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('Example term', 'Example term', 'semester')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('Example', 'Example', 'course_of_studies')"); diff --git a/core/templates.php b/core/templates.php index feb4fec..0a039a9 100644 --- a/core/templates.php +++ b/core/templates.php @@ -424,8 +424,8 @@ public static function prepare_publication_title ($row, $settings, $container_id // for direct style (if a DOI numer exists) elseif ( $row['doi'] != '' && $settings['link_style'] === 'direct' ) { - $doi_url = 'http://dx.doi.org/' . $row['doi']; - $title = tp_html::prepare_title($row['title'], 'decode'); + $title = tp_html::prepare_title($row['title'], 'decode'); + $doi_url = tp_html_publication_template::prepare_doi_url($row['doi']); return '' . $title . ''; } @@ -498,14 +498,16 @@ public static function prepare_url($url, $doi = '', $mode = 'list') { * Add DOI-URL * @since 5.0.0 */ - if ( $doi != '' ) { - $doi_url = 'http://dx.doi.org/' . $doi; - if ( $mode === 'list' ) { - $end .= '
  • doi:' . $doi . '
  • '; - } - else { - $end .= ''; - } + if ($doi != '') { + + $doi_url = tp_html_publication_template::prepare_doi_url($doi); + + if ( $mode === 'list' ) { + $end .= '
  • doi:' . $doi . '
  • '; + } + else { + $end .= ''; + } } if ( $mode === 'list' ) { @@ -514,9 +516,27 @@ public static function prepare_url($url, $doi = '', $mode = 'list') { return $end; } - - - + + /** + * Prepares a doi url + * @param string $doi The DOI number + * @return string + * @since 6.x.x + * @version 1 + * @access public + */ + public static function prepare_doi_url($doi) { + $doi_resolver_url_template = ''; + + if ( get_tp_option('doi_resolver_url_template_custom') != '' ) { + $doi_resolver_url_template = get_tp_option('doi_resolver_url_template_custom'); + } + else { + $doi_resolver_url_template = get_tp_option('doi_resolver_url_template_default'); + } + + return str_replace('%doi%', $doi, $doi_resolver_url_template); + } /** * Prepares an altmetric info block From 0c1156761a44bfb9c99e8740ea134b5d9da1481e Mon Sep 17 00:00:00 2001 From: Matthias Einbrodt Date: Mon, 25 Sep 2017 13:48:32 +0200 Subject: [PATCH 2/3] Created possibility to specify custom label for the DOI resolver link +++ Replaced hard with soft tabs --- core/class-update.php | 198 +++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 97 deletions(-) diff --git a/core/class-update.php b/core/class-update.php index cf8aad7..ca21931 100644 --- a/core/class-update.php +++ b/core/class-update.php @@ -1,7 +1,7 @@ get_var("SELECT `value` FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'db-version'"); } - + // if is the current one if ( $db_version === $software_version ) { get_tp_message( __('An update is not necessary.','teachpress') ); return; } - + // charset & collate like WordPress $charset_collate = ( !empty($wpdb->charset) ) ? "CHARACTER SET $wpdb->charset" : "CHARACTER SET utf8"; if ( ! empty($wpdb->collate) ) { @@ -43,7 +43,7 @@ public static function force_update () { else { $charset_collate .= " COLLATE utf8_general_ci"; } - + // set capabilities global $wp_roles; $role = $wp_roles->get_role('administrator'); @@ -53,12 +53,12 @@ public static function force_update () { if ( !$role->has_cap('use_teachpress_courses') ) { $wp_roles->add_cap('administrator', 'use_teachpress_courses'); } - + // Disable foreign key checks if ( TEACHPRESS_FOREIGN_KEY_CHECKS === false ) { $wpdb->query("SET foreign_key_checks = 0"); } - + // force updates to reach structure of teachPress 2.0.0 if ( $db_version[0] === '0' || $db_version[0] === '1' ) { tp_update_db::upgrade_table_teachpress_ver($charset_collate); @@ -70,19 +70,19 @@ public static function force_update () { tp_update_db::upgrade_table_teachpress_pub_to_20($charset_collate); $update_level = '2'; } - + // force updates to reach structure of teachPress 3.0.0 if ( $db_version[0] === '2' || $update_level === '2' ) { tp_update_db::upgrade_to_30(); $update_level = '3'; } - + // force updates to reach structure of teachPress 3.1.0 if ( $db_version[0] === '3' || $update_level === '3' ) { tp_update_db::upgrade_to_31($charset_collate); $update_level = '4'; } - + // force updates to reach structure of teachPress 4.2.0 if ( $db_version[0] === '4' || $update_level === '4' ) { tp_update_db::upgrade_to_40($charset_collate); @@ -90,26 +90,26 @@ public static function force_update () { tp_update_db::upgrade_to_42($charset_collate); $update_level = '5'; } - + // force updates to reach structure of teachPress 5.0.0 if ( $db_version[0] === '5' || $update_level === '5' ) { tp_update_db::upgrade_to_50($charset_collate); $update_level = '6'; } - + // force updates to reach structure of teachPress 6.0.0 if ( $db_version[0] === '6' || $update_level === '6' ) { tp_update_db::upgrade_to_60(); } - + // Add teachPress options tp_update_db::add_options(); - + // Enable foreign key checks if ( TEACHPRESS_FOREIGN_KEY_CHECKS === false ) { $wpdb->query("SET foreign_key_checks = 1"); } - + tp_update_db::finalize_update($software_version); } @@ -126,7 +126,7 @@ private static function upgrade_table_teachpress_ver ($charset_collate) { // create new table teachpress_courses if($wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_COURSES . "'") != TEACHPRESS_COURSES) { $sql = "CREATE TABLE " . TEACHPRESS_COURSES . " ( `course_id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR(100), `type` VARCHAR(100), `room` VARCHAR(100), `lecturer` VARCHAR (100), `date` VARCHAR(60), `places` INT(4), `start` DATETIME, `end` DATETIME, `semester` VARCHAR(100), `comment` VARCHAR(500), `rel_page` INT, `parent` INT, `visible` INT(1), `waitinglist` INT(1), `image_url` VARCHAR(400), `strict_signup` INT(1), PRIMARY KEY (course_id) - ) $charset_collate;"; + ) $charset_collate;"; $wpdb->query($sql); } // copy all data @@ -139,7 +139,7 @@ private static function upgrade_table_teachpress_ver ($charset_collate) { $wpdb->query("DROP TABLE $teachpress_ver"); } } - + /** * Replace the old table "teachpress_beziehung" with "teachpress_relation" and copy all data * @param string $charset_collate @@ -164,7 +164,7 @@ private static function upgrade_table_teachpress_beziehung ($charset_collate) { $wpdb->query("DROP TABLE $teachpress_beziehung"); } } - + /** * Replace the old table "teachpress_kursbelegung" with "teachpress_signup" and copy all data * @param string $charset_collate @@ -189,7 +189,7 @@ private static function upgrade_table_teachpress_kursbelegung ($charset_collate) $wpdb->query("DROP TABLE $teachpress_kursbelegung"); } } - + /** * Replace the old table "teachpress_einstellungen" with "teachpress_settings" and copy all data * @param string $charset_collate @@ -201,7 +201,7 @@ private static function upgrade_table_teachpress_einstellungen ($charset_collate if ($wpdb->query("SHOW COLUMNS FROM $teachpress_einstellungen LIKE 'einstellungs_id'") == '1') { // create new table teachpress_settings if($wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_SETTINGS . "'") != TEACHPRESS_SETTINGS) { - $sql = "CREATE TABLE " . TEACHPRESS_SETTINGS . " ( `setting_id` INT UNSIGNED AUTO_INCREMENT, `variable` VARCHAR (100), `value` VARCHAR (400), `category` VARCHAR (100), PRIMARY KEY (setting_id) ) $charset_collate;"; + $sql = "CREATE TABLE " . TEACHPRESS_SETTINGS . " ( `setting_id` INT UNSIGNED AUTO_INCREMENT, `variable` VARCHAR (100), `value` VARCHAR (400), `category` VARCHAR (100), PRIMARY KEY (setting_id) ) $charset_collate;"; $wpdb->query($sql); } // copy all data @@ -220,7 +220,7 @@ private static function upgrade_table_teachpress_einstellungen ($charset_collate $wpdb->query("DROP TABLE $teachpress_einstellungen"); } } - + /** * Upgrade table "teachPress_stud" to teachPress 2.x structure * @param string $charset_collate @@ -256,7 +256,7 @@ private static function upgrade_table_teachpress_stud_to_20 ($charset_collate) { $wpdb->query("ALTER TABLE " . TEACHPRESS_STUD . " CHANGE `matrikel` `matriculation_number` INT NULL DEFAULT NULL"); } } - + /** * Upgrade table "teachPress_pub" to teachPress 0.40 structure * @param string $charset_collate @@ -265,7 +265,7 @@ private static function upgrade_table_teachpress_stud_to_20 ($charset_collate) { private static function upgrade_table_teachpress_pub_to_04 ($charset_collate) { global $wpdb; // add column image_url - if ( $wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'image_url'") == '0' ) { + if ( $wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'image_url'") == '0' ) { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `image_url` VARCHAR(200) $charset_collate NULL DEFAULT NULL AFTER `comment`"); } // add colum rel_page @@ -277,7 +277,7 @@ private static function upgrade_table_teachpress_pub_to_04 ($charset_collate) { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `is_isbn` INT(1) NULL DEFAULT NULL AFTER `rel_page`"); } } - + /** * Upgrade table "teachPress_pub" to teachPress 2.x structure * @param string $charset_collate @@ -419,14 +419,14 @@ private static function upgrade_table_teachpress_pub_to_20 ($charset_collate) { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " DROP `verlag`"); } } - + /** * Upgrade table "teachpress_courses" to teachPress 3.0 structure * @since 4.2.0 */ private static function upgrade_to_30 () { global $wpdb; - + // teachpress_courses // change type in column start $wpdb->get_results("SELECT `start` FROM " . TEACHPRESS_COURSES); @@ -442,7 +442,7 @@ private static function upgrade_to_30 () { if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_COURSES . " LIKE 'strict_signup'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_COURSES . " ADD `strict_signup` INT( 1 ) NULL DEFAULT NULL"); } - + // teachpress_signup // Change type in column date $wpdb->get_results("SELECT `date` FROM " . TEACHPRESS_SIGNUP); @@ -450,7 +450,7 @@ private static function upgrade_to_30 () { $wpdb->query("ALTER TABLE `" . TEACHPRESS_SIGNUP . "` CHANGE `date` `date` DATETIME NULL DEFAULT NULL"); } } - + /** * Database upgrade to teachPress 3.1.3 structure * @param string $charset_collate @@ -488,7 +488,7 @@ private static function upgrade_to_31 ($charset_collate) { $wpdb->query("ALTER TABLE " . TEACHPRESS_RELATION . " ENGINE = INNODB"); $wpdb->query("ALTER TABLE " . TEACHPRESS_USER . " ENGINE = INNODB"); } - + /** * Database upgrade to teachPress 4.0.0 structure * @param string $charset_collate @@ -501,11 +501,11 @@ private static function upgrade_to_40 ($charset_collate) { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " CHANGE `name` `title` VARCHAR( 500 ) $charset_collate NULL DEFAULT NULL"); } // add column urldate - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'urldate'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'urldate'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `urldate` DATE NULL DEFAULT NULL AFTER `date`"); } } - + /** * Database upgrade to teachPress 4.1.0 structure * @param string $charset_collate @@ -514,11 +514,11 @@ private static function upgrade_to_40 ($charset_collate) { private static function upgrade_to_41 () { global $wpdb; // add column urldate - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'issuetitle'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'issuetitle'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `issuetitle` VARCHAR( 200 ) NULL DEFAULT NULL AFTER `booktitle`"); } } - + /** * Database upgrade to teachPress 4.2.0 structure * @param string $charset_collate @@ -531,7 +531,7 @@ private static function upgrade_to_42 ($charset_collate) { $wpdb->query("ALTER TABLE " . TEACHPRESS_SETTINGS . " CHANGE `value` `value` TEXT $charset_collate NULL DEFAULT NULL"); } } - + /** * Database upgrade to teachPress 5.0.0 structure * @param string $charset_collate @@ -550,69 +550,69 @@ private static function upgrade_to_50 ($charset_collate){ tp_tables::add_table_rel_pub_auth($charset); tp_tables::add_table_stud_meta($charset); tp_tables::add_table_pub_meta($charset); - + // add column use_capabilites to table teachpress_courses - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_COURSES . " LIKE 'use_capabilites'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_COURSES . " LIKE 'use_capabilites'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_COURSES . " ADD `use_capabilites` INT( 1 ) NULL DEFAULT NULL AFTER `strict_signup`"); } - + // add column doi to table teachpress_pub - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'doi'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'doi'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `doi` VARCHAR( 100 ) NULL DEFAULT NULL AFTER `image_url`"); } - + // add column status to table teachpress_pub - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'status'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'status'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `status` VARCHAR( 100 ) NULL DEFAULT 'published' AFTER `rel_page`"); } - + // add column added to table teachpress_pub - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'added'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'added'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `added` DATETIME NULL DEFAULT NULL AFTER `status`"); } - + // add column modified to table teachpress_pub - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'modified'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'modified'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `modified` DATETIME NULL DEFAULT NULL AFTER `added`"); } - + // add column size to table teachpress_course_documents - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_COURSE_DOCUMENTS . " LIKE 'size'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_COURSE_DOCUMENTS . " LIKE 'size'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_COURSE_DOCUMENTS . " ADD `size` BIGINT NULL DEFAULT NULL AFTER `added`"); } - + // add column sort_name to table teachpress_authors - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_AUTHORS . " LIKE 'sort_name'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_AUTHORS . " LIKE 'sort_name'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_AUTHORS . " ADD `sort_name` VARCHAR( 500 ) NULL DEFAULT NULL AFTER `name`"); } - + // expand char limit for tp_settings::value if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_SETTINGS . " LIKE 'value'") == '1') { $wpdb->query("ALTER TABLE " . TEACHPRESS_SETTINGS . " CHANGE `value` `value` LONGTEXT $charset_collate NULL DEFAULT NULL"); } - + // expand char limit for tp_publications::author if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'author'") == '1') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " CHANGE `author` `author` VARCHAR (3000) $charset_collate NULL DEFAULT NULL"); } - + // expand char limit for tp_publications::editor if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'editor'") == '1') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " CHANGE `editor` `editor` VARCHAR (3000) $charset_collate NULL DEFAULT NULL"); } - + // expand char limit for tp_publications::institution if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'institution'") == '1') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " CHANGE `institution` `institution` VARCHAR (500) $charset_collate NULL DEFAULT NULL"); } - + // expand char limit for tp_publications::organization if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'organization'") == '1') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " CHANGE `organization` `organization` VARCHAR (500) $charset_collate NULL DEFAULT NULL"); } - + } - + /** * Database upgrade to teachPress 6.0.0 structure * @since 6.0.0 @@ -620,24 +620,24 @@ private static function upgrade_to_50 ($charset_collate){ private static function upgrade_to_60 (){ global $wpdb; $charset = tp_tables::get_charset(); - + // add new tables tp_tables::add_table_pub_capabilites($charset); tp_tables::add_table_pub_documents($charset); tp_tables::add_table_pub_imports($charset); - + // add column use_capabilites to table teachpress_courses - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'use_capabilites'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'use_capabilites'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `use_capabilites` INT( 1 ) NULL DEFAULT NULL AFTER `modified`"); } - + // add column import_id to table teachpress_courses - if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'import_id'") == '0') { + if ($wpdb->query("SHOW COLUMNS FROM " . TEACHPRESS_PUB . " LIKE 'import_id'") == '0') { $wpdb->query("ALTER TABLE " . TEACHPRESS_PUB . " ADD `import_id` INT NULL DEFAULT NULL AFTER `use_capabilites`"); } - + } - + /** * Checks if the table teachpress_authors needs to be filled. Returns false if not. * @return boolean @@ -652,7 +652,7 @@ public static function check_table_authors () { } return false; } - + /** * Checks if the table teachpress_stud_meta needs to be filled. Returns false if not. * @return boolean @@ -667,11 +667,11 @@ public static function check_table_stud_meta () { } return false; } - + /** * Prepares and Returns the statement for adding all author - publications relations in one SQL Query * Returns a string like: ('pub_id', 'author_id', 'is_author', 'is_editor'), ('pub_id', 'author_id', 'is_author', 'is_editor'),... - * + * * @param int $pub_id The ID of the publication * @param string $input_string A author / editor string * @param string $delimiter default is ',' @@ -687,27 +687,27 @@ public static function prepare_relation ($pub_id, $input_string, $delimiter = ', $return = ''; foreach($array as $element) { $element = trim($element); - + if ( $element === '' ) { continue; } - + $element = esc_sql( htmlspecialchars($element) ); - + // check if element exists $check = $wpdb->get_var("SELECT `author_id` FROM " . TEACHPRESS_AUTHORS . " WHERE `name` = '$element'"); - + // if element not exists if ( $check === NULL ){ $check = tp_authors::add_author( $element, tp_bibtex::get_lastname($element) ); } - + // prepare relation $is_author = ( $rel_type === 'authors' ) ? 1 : 0; $is_editor = ( $rel_type === 'editors' ) ? 1 : 0; $check = intval($check); $return = ($return === '') ? "($pub_id, $check, $is_author, $is_editor)" : $return . ", ($pub_id, $check, $is_author, $is_editor)"; - + } return $return; } @@ -719,14 +719,14 @@ public static function prepare_relation ($pub_id, $input_string, $delimiter = ', */ public static function fill_table_authors ($limit = '') { global $wpdb; - + // Try to set the time limit for the script set_time_limit(TEACHPRESS_TIME_LIMIT); - + if ( $limit !== '' ) { $limit = ' LIMIT ' . esc_sql($limit); } - + $relation = ''; get_tp_message( __('Step 1: Read data and add authors','teachpress') ); $pubs = $wpdb->get_results("SELECT pub_id, author, editor FROM " . TEACHPRESS_PUB . $limit, ARRAY_A); @@ -744,7 +744,7 @@ public static function fill_table_authors ($limit = '') { $wpdb->query("INSERT INTO " . TEACHPRESS_REL_PUB_AUTH . " (`pub_id`, `author_id`, `is_author`, `is_editor`) VALUES $relation"); get_tp_message( __('Update successful','teachpress') ); } - + /** * Use this function to transfer all data from no longer used columns of teachpress_stud to teachpress_stud_meta * @since 5.0.0 @@ -762,7 +762,7 @@ public static function fill_table_stud_meta () { $relation .= "(" . $row['wp_id'] . ", 'semester_number', '" . $row['semesternumber'] . "'), "; $relation .= "(" . $row['wp_id'] . ", 'matriculation_number', '" . $row['matriculation_number'] . "'), "; } - + $relation = substr($relation, 0, -2); get_tp_message( __('Step 2: Insert data','teachpress') ); $wpdb->query("INSERT INTO " . TEACHPRESS_STUD_META . " (`wp_id`, `meta_key`, `meta_value`) VALUES $relation"); @@ -777,70 +777,70 @@ private static function add_options () { global $wpdb; // Stylesheet if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE variable = 'stylesheet' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('stylesheet', '1', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('stylesheet', '1', 'system')"); } // Sign out if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE variable = 'sign_out' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . "(variable, value, category) VALUES ('sign_out', '0', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . "(variable, value, category) VALUES ('sign_out', '0', 'system')"); } // Login if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE variable = 'login' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('login', 'std', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('login', 'std', 'system')"); } // rel_page_courses if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE variable = 'rel_page_courses' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('rel_page_courses', 'page', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('rel_page_courses', 'page', 'system')"); } // rel_page_publications if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE variable = 'rel_page_publications' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('rel_page_publications', 'page', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (variable, value, category) VALUES ('rel_page_publications', 'page', 'system')"); } - + /**** since version 4.2.0 ****/ - + // rel_content_template if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'rel_content_template' AND `category` = 'system'") == '0') { $value = '[tpsingle [key]]' . "\n\n[tpabstract]\n\n[tplinks]\n\n[tpbibtex]"; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_template', '$value', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_template', '$value', 'system')"); } // rel_content_auto if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'rel_content_auto' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_auto', '0', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_auto', '0', 'system')"); } // rel_content_category if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'rel_content_category' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_category', '', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_category', '', 'system')"); } // import_overwrite if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'import_overwrite' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('import_overwrite', '0', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('import_overwrite', '0', 'system')"); } - + /**** since version 5.0.0 ****/ // fix old entries if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'sem' AND `category` = ''") == '0') { $wpdb->query("UPDATE " . TEACHPRESS_SETTINGS . " SET `category` = 'system' WHERE `variable` = 'sem'"); } - + // convert_bibtex if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'convert_bibtex' AND `category` = 'system'") == '0') { - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('convert_bibtex', '0', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('convert_bibtex', '0', 'system')"); } - + // course_of_studies if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'course_of_studies' AND `category` = 'teachpress_stud'") == '0') { $value = 'name = {course_of_studies}, title = {' . __('Course of studies','teachpress') . '}, type = {SELECT}, required = {false}, min = {false}, max = {false}, step = {false}, visibility = {admin}'; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('course_of_studies', '$value', 'teachpress_stud')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('course_of_studies', '$value', 'teachpress_stud')"); } // birthday if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'birthday' AND `category` = 'teachpress_stud'") == '0') { $value = 'name = {birthday}, title = {' . __('Birthday','teachpress') . '}, type = {DATE}, required = {false}, min = {false}, max = {false}, step = {false}, visibility = {normal}'; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('birthday', '$value', 'teachpress_stud')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('birthday', '$value', 'teachpress_stud')"); } // semester_number if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'semester_number' AND `category` = 'teachpress_stud'") == '0') { $value = 'name = {semester_number}, title = {' . __('Semester number','teachpress') . '}, type = {INT}, required = {false}, min = {1}, max = {99}, step = {1}, visibility = {normal}'; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('semester_number', '$value', 'teachpress_stud')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('semester_number', '$value', 'teachpress_stud')"); } // matriculation_number if ($wpdb->query("SELECT value FROM " . TEACHPRESS_SETTINGS . " WHERE `variable` = 'matriculation_number' AND `category` = 'teachpress_stud'") == '0') { @@ -852,8 +852,12 @@ private static function add_options () { if ( get_tp_option('rel_content_template') == 'page' ) { tp_options::change_option('rel_content_template', '[tpsingle [key]]' . "\n\n[tpabstract]\n\n[tplinks]\n\n[tpbibtex]"); } + /**** since version 6.x.x ****/ + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_default', 'https://dx.doi.org/%doi%', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_custom', '', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_href_label_custom', '', 'system')"); } - + /** * Update version information in the database * @param string $version @@ -865,4 +869,4 @@ private static function finalize_update ($version) { $wpdb->query("UPDATE " . TEACHPRESS_SETTINGS . " SET `value` = '$version', `category` = 'system' WHERE `variable` = 'db-version'"); get_tp_message( __('Update successful','teachpress') ); } -} \ No newline at end of file +} From 5949735f395c45f2be32505b882c62aad93b23d8 Mon Sep 17 00:00:00 2001 From: Matthias Einbrodt Date: Mon, 25 Sep 2017 13:52:21 +0200 Subject: [PATCH 3/3] Again, created possibility to specify custom label for the DOI resolver link +++ Replaced hard with soft tabs --- admin/settings.php | 176 +++++++++++++------------ core/class-tables.php | 291 +++++++++++++++++++++--------------------- core/templates.php | 220 +++++++++++++++++-------------- 3 files changed, 359 insertions(+), 328 deletions(-) diff --git a/admin/settings.php b/admin/settings.php index eebd25b..ee7c0b5 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -1,7 +1,7 @@ '; + echo '

    ' . __('Enrollment system','teachpress') . '

    '; echo ''; echo ''; echo ''; - echo ''; $value = get_tp_option('sem'); $sem = get_tp_options('semester'); - + // Test if the current semester is in the semester list $sem_test = ( get_tp_option($value, 'semester') === NULL ) ? false : true; if ( $sem_test === false ) { echo ''; } - - foreach ($sem as $sem) { + + foreach ($sem as $sem) { $current = ($sem->value == $value) ? 'selected="selected"' : ''; echo ''; } @@ -378,7 +378,7 @@ private static function get_general_tab() { else { echo ''; echo ''; - } + } echo ''; echo ''; echo '' . __('Prevent sign out for your users','teachpress') . ''; @@ -390,72 +390,79 @@ private static function get_general_tab() { echo '

    ' . __('Uninstalling','teachpress') . '

    '; echo '' . __('Remove teachPress from database','teachpress') . ''; echo '

    '; - + echo ''; self::get_about_dialog(); } - + /** * Shows the publication settings tab * @access private * @since 5.0.0 */ private static function get_publication_tab() { - + echo ''; echo ''; - + echo ''; echo ''; echo ''; - + echo ''; echo ''; echo ''; echo ''; - + echo ''; echo ''; echo ''; echo ''; - - echo ''; + + echo ''; echo ''; echo ''; - - echo ''; + + echo ''; echo ''; echo ''; - echo ''; - + echo '

    ' . __('Define a custom doi resolver template which overrides the default one: ','teachpress') . '' . get_tp_option('doi_resolver_url_template_default') . '

    '; + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; echo ''; - + echo ''; echo ''; echo ''; echo ''; - + echo ''; echo ''; echo ''; echo ''; - + echo ''; echo ''; echo ''; echo ''; - + echo ''; echo ''; echo ''; - + echo ''; echo ''; echo ''; + '; echo ''; - + echo ''; echo '

    ' . __('Import / Export','teachpress') . '

    ' . __('BibTeX special chars','teachpress') . '' . tp_admin::get_checkbox('convert_bibtex', __('Try to convert utf-8 chars into BibTeX compatible ASCII strings','teachpress'), get_tp_option('convert_bibtex')) . '
    ' . __('Overwrite publications','teachpress') . '' . tp_admin::get_checkbox('import_overwrite', __('Allow optional overwriting for publication import','teachpress'), get_tp_option('import_overwrite')) . ' (EXPERIMENTAL)

    ' . __('DOI Resolver','teachpress') . '

    ' . __('Custom Url Template','teachpress') . ''; - echo '

    ' . __('Define a custom doi resolver template which overrides the default one: ','teachpress') . '' . get_tp_option('doi_resolver_url_template_default') . '

    '; - echo '
    ' . __('Custom Link Label','teachpress') . ''; + echo '

    ' . __('Define a custom human-readable label for the DOI link.','teachpress') . '

    '; + echo '

    ' . __('Related content','teachpress') . '

    ' . __('Automatic related content','teachpress') . '' . tp_admin::get_checkbox('rel_content_auto', __('Create an automatic related content with every new publication','teachpress'), get_tp_option('rel_content_auto')) . '
    ' . __('Template for related content','teachpress') . '
    ' . __('Default category for related content','teachpress') . ''; - wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'rel_content_category', 'orderby' => 'name', 'selected' => get_tp_option('rel_content_category'), 'hierarchical' => true, 'show_option_none' => __('none','teachpress'))); + wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'rel_content_category', 'orderby' => 'name', 'selected' => get_tp_option('rel_content_category'), 'hierarchical' => true, 'show_option_none' => __('none','teachpress'))); echo '' . __('Used if the related content type for publicaitons is set on "Posts"','teachpress') . '

    ' . __('RSS','teachpress') . '

    ' . __('RSS feed addresses','teachpress') . '

    ' . __('For all publications:','teachpress') . '
    @@ -464,15 +471,15 @@ private static function get_publication_tab() { ' . home_url() . '?feed=tp_pub_rss&id=1 » ' . __('Show','teachpress') . '

    ' . __('Example for publications of a single tag (tag = tag-id):','teachpress') . '
    ' . home_url() . '?feed=tp_pub_rss&tag=1 » ' . __('Show','teachpress') . '

    -
    '; echo ''; } - + /** * Shows the student settings tab * @param string $tab student_data, publication_data or course_data @@ -498,7 +505,7 @@ private static function get_meta_tab($tab) { echo '

    ' . __('Meta data fields','teachpress') . '

    '; echo ''; - + // Table Head echo ''; echo ''; @@ -506,7 +513,7 @@ private static function get_meta_tab($tab) { echo ''; echo ''; echo ''; - + // Table Body echo ''; @@ -569,7 +576,7 @@ private static function get_meta_tab($tab) { echo '
    '; foreach ( $select_fields as $elem ) { - $args1 = array ( + $args1 = array ( 'element_title' => __('Name','teachpress'), 'count_title' => __('Number of students','teachpress'), 'delete_title' => __('Delete elemtent','teachpress'), @@ -602,16 +609,16 @@ private static function get_meta_tab($tab) { ' . __('Available templates for publication lists','teachpress') . ''; - + // Begin change directory message echo '
    ' . __('Please note','teachpress') . ': ' . __('Changes in the templates will be overwritten by updates of the plugin.','teachpress') . ' ' . __('But you can change the directory for the templates.','teachpress') . '
    '; echo ''; // End change directory message - + echo '
    ' . __('Properties','teachpress') . '
    '; echo ''; echo ''; @@ -634,7 +641,7 @@ private static function get_template_tab () { echo self::list_templates(); echo '
    '; } - + /** * Creates the list of publication templates * @return string @@ -655,19 +662,19 @@ private static function list_templates () { $tr_class = ''; $class_alternate = true; } - + // load template include_once $templates[$key]; $template = new $key(); - + // default values $settings = array('name' => '', 'description' => '', 'author' => '', 'version' => '0.0'); - + // overwrite defaults if ( method_exists($template, 'get_settings') ) { $settings = shortcode_atts( $settings, $template->get_settings() ); } - + $s .= ''; $s .= '' . esc_html($settings['name']) . ''; $s .= '' . esc_html($key) . ''; @@ -676,18 +683,18 @@ private static function list_templates () { '; $s .= ''; } - + $s .= ''; return $s; } - + /** * Adds new term and new types for courses * @access private * @since 5.0.0 */ private static function add_course_options () { - $new_term = isset( $_POST['new_term'] ) ? htmlspecialchars($_POST['new_term']) : ''; + $new_term = isset( $_POST['new_term'] ) ? htmlspecialchars($_POST['new_term']) : ''; $new_type = isset( $_POST['new_type'] ) ? htmlspecialchars($_POST['new_type']) : ''; if (isset( $_POST['add_type'] ) && $new_type != __('Add type','teachpress')) { @@ -699,7 +706,7 @@ private static function add_course_options () { get_tp_message(__('Saved')); } } - + /** * Handles adding of new meta data fields * @param string $table The table name (teachpress_stud, teachpress_courses or teachpress_pub) @@ -710,10 +717,10 @@ private static function add_meta_fields ($table) { if ( !isset( $_POST['field_name'] ) ) { return; } - + // Generate field name $field_name = self::generate_meta_field_name($_POST['field_name'], $table); - + // Field values $data['title'] = isset( $_POST['field_label'] ) ? htmlspecialchars($_POST['field_label']) : ''; $data['type'] = isset( $_POST['field_type'] ) ? htmlspecialchars($_POST['field_type']) : ''; @@ -723,7 +730,7 @@ private static function add_meta_fields ($table) { $data['step'] = isset( $_POST['number_step'] ) ? intval($_POST['number_step']) : 'false'; $data['required'] = isset( $_POST['is_required'] ) ? 'true' : 'false'; $data['field_edit'] = isset( $_POST['field_edit'] ) ? intval($_POST['field_edit']) : 0 ; - + // Generate an array of forbidden field names $forbidden_names = array('system', 'course_type', 'semester', __('Field name','teachpress')); $options = get_tp_options($table); @@ -732,14 +739,14 @@ private static function add_meta_fields ($table) { array_push( $forbidden_names, $row->variable ); } } - + if ( !in_array($field_name, $forbidden_names) && $data['title'] != __('Label', 'teachpress') && preg_match("#^[_A-Za-z0-9]+$#", $field_name) ) { - + // Delete old settings if needed if ( $data['field_edit'] > 0 ) { tp_options::delete_option($data['field_edit']); } - + tp_db_helpers::register_column($table, $field_name, $data); get_tp_message( __('Field added','teachpress') ); } @@ -747,7 +754,7 @@ private static function add_meta_fields ($table) { get_tp_message( __('Warning: This field name is not possible.','teachpress'), 'red' ); } } - + /** * Generates and returns a name for meta data fields * @param string $fieldname The field name @@ -757,7 +764,7 @@ private static function add_meta_fields ($table) { */ private static function generate_meta_field_name($fieldname, $table) { $name = str_replace( array("'", '"', ' '), array("", "", '_'), $fieldname); - + if ( $table === 'teachpress_courses' ) { $prefix = 'tp_meta_courses_'; } @@ -770,15 +777,15 @@ private static function generate_meta_field_name($fieldname, $table) { else { $prefix = 'tp_meta_'; } - + // Check if the prefix is already part of the field name if ( stristr($fieldname, $prefix) === false ) { return $prefix . esc_attr($name); } - + return esc_attr($name); } - + /** * Deletes student data fields * @param string $tab The name of the tab (used for return link) @@ -815,7 +822,7 @@ private static function change_general_options () { $option_login = isset( $_POST['login'] ) ? htmlspecialchars($_POST['login']) : ''; $option_userrole_publications = isset( $_POST['userrole_publications'] ) ? $_POST['userrole_publications'] : ''; $option_userrole_courses = isset( $_POST['userrole_courses'] ) ? $_POST['userrole_courses'] : ''; - + tp_options::change_option('sem', $option_semester); tp_options::change_option('rel_page_courses', $option_rel_page_courses); tp_options::change_option('rel_page_publications', $option_rel_page_publications); @@ -836,18 +843,19 @@ private static function change_general_options () { private static function change_publication_options () { $checkbox_convert_bibtex = isset( $_POST['convert_bibtex'] ) ? 1 : ''; $checkbox_import_overwrite = isset( $_POST['import_overwrite'] ) ? 1 : ''; - $doi_resolver_url_template_custom = isset( $_POST['doi_resolver_url_template_custom'] ) ? esc_url_raw( $_POST['doi_resolver_url_template_custom'] ) : ''; + $doi_resolver_url_template_custom = isset( $_POST['doi_resolver_url_template_custom'] ) ? esc_url_raw( $_POST['doi_resolver_url_template_custom'] ) : ''; + $doi_resolver_href_label_custom = isset( $_POST['doi_resolver_href_label_custom'] ) ? $_POST['doi_resolver_href_label_custom'] : ''; $checkbox_rel_content_auto = isset( $_POST['rel_content_auto'] ) ? 1 : ''; tp_options::change_option('convert_bibtex', $checkbox_convert_bibtex, 'checkbox'); tp_options::change_option('import_overwrite', $checkbox_import_overwrite, 'checkbox'); - tp_options::change_option('doi_resolver_url_template_custom', $doi_resolver_url_template_custom); + tp_options::change_option('doi_resolver_url_template_custom', $doi_resolver_url_template_custom); + tp_options::change_option('doi_resolver_href_label_custom', $doi_resolver_href_label_custom); tp_options::change_option('rel_content_auto', $checkbox_rel_content_auto, 'checkbox'); tp_options::change_option('rel_content_template', $_POST['rel_content_template']); tp_options::change_option('rel_content_category', $_POST['rel_content_category']); get_tp_message(__('Saved')); - } - + /** * Handles start of database updates * @param string $site The current URL @@ -869,7 +877,7 @@ private static function update_database ($site, $with_structure_change = true) { $message = 'TABLE ' . $table . ': ' . __('teachPress wants to fill up the new database. This can take some time.','teachpress') . ' ' . __('Continue','teachpress') . ''; get_tp_message($message, 'orange'); } - + /** * Hanldes start of database deletion * @access private @@ -885,4 +893,4 @@ private static function delete_database () { get_tp_message( __('Database uninstalled','teachpress') ); } } -} \ No newline at end of file +} diff --git a/core/class-tables.php b/core/class-tables.php index ab5f385..dbd5b98 100644 --- a/core/class-tables.php +++ b/core/class-tables.php @@ -1,7 +1,7 @@ query("SET foreign_key_checks = 0"); } - + // Settings self::add_table_settings($charset_collate); - + // Courses self::add_table_courses($charset_collate); self::add_table_course_meta($charset_collate); @@ -42,7 +42,7 @@ public static function create() { self::add_table_signup($charset_collate); self::add_table_artefacts($charset_collate); self::add_table_assessments($charset_collate); - + // Publications self::add_table_pub($charset_collate); self::add_table_pub_meta($charset_collate); @@ -54,13 +54,13 @@ public static function create() { self::add_table_user($charset_collate); self::add_table_authors($charset_collate); self::add_table_rel_pub_auth($charset_collate); - + // Enable foreign key checks if ( TEACHPRESS_FOREIGN_KEY_CHECKS === false ) { $wpdb->query("SET foreign_key_checks = 1"); } } - + /** * Remove teachPress database tables * @since 5.0.0 @@ -68,29 +68,29 @@ public static function create() { public static function remove() { global $wpdb; $wpdb->query("SET FOREIGN_KEY_CHECKS=0"); - $wpdb->query("DROP TABLE `" . TEACHPRESS_ARTEFACTS . "`, - `" . TEACHPRESS_ASSESSMENTS . "`, - `" . TEACHPRESS_AUTHORS . "`, - `" . TEACHPRESS_COURSES . "`, - `" . TEACHPRESS_COURSE_CAPABILITES . "`, - `" . TEACHPRESS_COURSE_DOCUMENTS . "`, - `" . TEACHPRESS_COURSE_META . "`, - `" . TEACHPRESS_PUB . "`, - `" . TEACHPRESS_PUB_CAPABILITES . "`, - `" . TEACHPRESS_PUB_DOCUMENTS . "`, - `" . TEACHPRESS_PUB_META . "`, + $wpdb->query("DROP TABLE `" . TEACHPRESS_ARTEFACTS . "`, + `" . TEACHPRESS_ASSESSMENTS . "`, + `" . TEACHPRESS_AUTHORS . "`, + `" . TEACHPRESS_COURSES . "`, + `" . TEACHPRESS_COURSE_CAPABILITES . "`, + `" . TEACHPRESS_COURSE_DOCUMENTS . "`, + `" . TEACHPRESS_COURSE_META . "`, + `" . TEACHPRESS_PUB . "`, + `" . TEACHPRESS_PUB_CAPABILITES . "`, + `" . TEACHPRESS_PUB_DOCUMENTS . "`, + `" . TEACHPRESS_PUB_META . "`, `" . TEACHPRESS_PUB_IMPORTS . "`, `" . TEACHPRESS_RELATION ."`, - `" . TEACHPRESS_REL_PUB_AUTH . "`, - `" . TEACHPRESS_SETTINGS ."`, - `" . TEACHPRESS_SIGNUP ."`, - `" . TEACHPRESS_STUD . "`, - `" . TEACHPRESS_STUD_META . "`, - `" . TEACHPRESS_TAGS . "`, + `" . TEACHPRESS_REL_PUB_AUTH . "`, + `" . TEACHPRESS_SETTINGS ."`, + `" . TEACHPRESS_SIGNUP ."`, + `" . TEACHPRESS_STUD . "`, + `" . TEACHPRESS_STUD_META . "`, + `" . TEACHPRESS_TAGS . "`, `" . TEACHPRESS_USER . "`"); $wpdb->query("SET FOREIGN_KEY_CHECKS=1"); } - + /** * Returns an associative array with table status informations (Name, Engine, Version, Rows,...) * @param string $table @@ -101,7 +101,7 @@ public static function check_table_status($table){ global $wpdb; return $wpdb->get_row("SHOW TABLE STATUS FROM " . DB_NAME . " WHERE `Name` = '$table'", ARRAY_A); } - + /** * Tests if the engine for the selected table is InnoDB. If not, the function changes the engine. * @param string $table @@ -123,13 +123,13 @@ private static function change_engine($table){ */ public static function add_table_courses($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_COURSES . "'") == TEACHPRESS_COURSES ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_COURSES . " ( `course_id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR(100), @@ -151,11 +151,11 @@ public static function add_table_courses($charset_collate) { `use_capabilites` INT(1), PRIMARY KEY (`course_id`) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_COURSES); } - + /** * Create table course_capabilites * @param string $charset_collate @@ -163,13 +163,13 @@ public static function add_table_courses($charset_collate) { */ public static function add_table_course_capabilites($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_COURSE_CAPABILITES . "'") == TEACHPRESS_COURSE_CAPABILITES ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_COURSE_CAPABILITES . " ( `cap_id` INT UNSIGNED AUTO_INCREMENT, `wp_id` INT UNSIGNED, @@ -177,11 +177,11 @@ public static function add_table_course_capabilites($charset_collate) { `capability` VARCHAR(100), PRIMARY KEY (`cap_id`) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_COURSE_CAPABILITES); } - + /** * Create table course_documents * @param string $charset_collate @@ -189,13 +189,13 @@ public static function add_table_course_capabilites($charset_collate) { */ public static function add_table_course_documents($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_COURSE_DOCUMENTS . "'") == TEACHPRESS_COURSE_DOCUMENTS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_COURSE_DOCUMENTS . " ( `doc_id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR(500), @@ -206,11 +206,11 @@ public static function add_table_course_documents($charset_collate) { `course_id` INT UNSIGNED, PRIMARY KEY (doc_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_COURSE_DOCUMENTS); } - + /** * Create table teachpress_course_meta * @param string $charset_collate @@ -218,13 +218,13 @@ public static function add_table_course_documents($charset_collate) { */ public static function add_table_course_meta($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_COURSE_META . "'") == TEACHPRESS_COURSE_META ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_COURSE_META . " ( `meta_id` INT UNSIGNED AUTO_INCREMENT, `course_id` INT UNSIGNED, @@ -232,11 +232,11 @@ public static function add_table_course_meta($charset_collate) { `meta_value` TEXT, PRIMARY KEY (meta_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_COURSE_META); } - + /** * Create table teachpress_stud * @param string $charset_collate @@ -244,13 +244,13 @@ public static function add_table_course_meta($charset_collate) { */ public static function add_table_stud($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_STUD . "'") == TEACHPRESS_STUD ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_STUD . " ( `wp_id` INT UNSIGNED, `firstname` VARCHAR(100) , @@ -259,11 +259,11 @@ public static function add_table_stud($charset_collate) { `email` VARCHAR(50), PRIMARY KEY (wp_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_STUD); } - + /** * Create table teachpress_stud_meta * @param string $charset_collate @@ -271,13 +271,13 @@ public static function add_table_stud($charset_collate) { */ public static function add_table_stud_meta($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_STUD_META . "'") == TEACHPRESS_STUD_META ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_STUD_META . " ( `meta_id` INT UNSIGNED AUTO_INCREMENT, `wp_id` INT UNSIGNED, @@ -285,11 +285,11 @@ public static function add_table_stud_meta($charset_collate) { `meta_value` TEXT, PRIMARY KEY (meta_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_STUD_META); } - + /** * Create table teachpress_signup * @param string $charset_collate @@ -297,13 +297,13 @@ public static function add_table_stud_meta($charset_collate) { */ public static function add_table_signup($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_SIGNUP ."'") == TEACHPRESS_SIGNUP ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_SIGNUP ." ( `con_id` INT UNSIGNED AUTO_INCREMENT, `course_id` INT UNSIGNED, @@ -312,11 +312,11 @@ public static function add_table_signup($charset_collate) { `date` DATETIME, PRIMARY KEY (con_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_SIGNUP); } - + /** * Create table teachpress_artefacts * @param string $charset_collate @@ -324,13 +324,13 @@ public static function add_table_signup($charset_collate) { */ public static function add_table_artefacts($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_ARTEFACTS . "'") == TEACHPRESS_ARTEFACTS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_ARTEFACTS . " ( `artefact_id` INT UNSIGNED AUTO_INCREMENT, `parent_id` INT UNSIGNED, @@ -341,11 +341,11 @@ public static function add_table_artefacts($charset_collate) { `max_value` VARCHAR(50), PRIMARY KEY (artefact_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_ARTEFACTS); } - + /** * Create table teachpress_assessments * @param string $charset_collate @@ -353,13 +353,13 @@ public static function add_table_artefacts($charset_collate) { */ public static function add_table_assessments($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_ASSESSMENTS . "'") == TEACHPRESS_ASSESSMENTS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_ASSESSMENTS . " ( `assessment_id` INT UNSIGNED AUTO_INCREMENT, `artefact_id` INT UNSIGNED, @@ -374,11 +374,11 @@ public static function add_table_assessments($charset_collate) { `passed` INT(1), PRIMARY KEY (assessment_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_ASSESSMENTS); } - + /** * Create table teachpress_settings * @param string $charset_collate @@ -386,13 +386,13 @@ public static function add_table_assessments($charset_collate) { */ public static function add_table_settings($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_SETTINGS . "'") == TEACHPRESS_SETTINGS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_SETTINGS . " ( `setting_id` INT UNSIGNED AUTO_INCREMENT, `variable` VARCHAR (100), @@ -400,14 +400,14 @@ public static function add_table_settings($charset_collate) { `category` VARCHAR (100), PRIMARY KEY (setting_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_SETTINGS); - + // Add default values self::add_default_settings(); } - + /** * Add default system settings * @since 5.0.0 @@ -416,7 +416,7 @@ public static function add_default_settings(){ global $wpdb; $value = '[tpsingle [key]]' . "\n\n[tpabstract]\n\n[tplinks]\n\n[tpbibtex]"; $version = get_tp_version(); - + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('sem', 'Example term', 'system')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('db-version', '$version', 'system')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('sign_out', '0', 'system')"); @@ -429,29 +429,30 @@ public static function add_default_settings(){ $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('rel_content_category', '', 'system')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('import_overwrite', '0', 'system')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('convert_bibtex', '0', 'system')"); - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_default', 'https://dx.doi.org/%doi%', 'system')"); - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_custom', '', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_default', 'https://dx.doi.org/%doi%', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_url_template_custom', '', 'system')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('doi_resolver_href_label_custom', '', 'system')"); // Example values $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('Example term', 'Example term', 'semester')"); - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('Example', 'Example', 'course_of_studies')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('Example', 'Example', 'course_of_studies')"); $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . "(`variable`, `value`, `category`) VALUES ('Lecture', 'Lecture', 'course_type')"); - + // Register example meta data fields // course_of_studies $value = 'name = {course_of_studies}, title = {' . __('Course of studies','teachpress') . '}, type = {SELECT}, required = {false}, min = {false}, max = {false}, step = {false}, visibility = {admin}'; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('course_of_studies', '$value', 'teachpress_stud')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('course_of_studies', '$value', 'teachpress_stud')"); // birthday $value = 'name = {birthday}, title = {' . __('Birthday','teachpress') . '}, type = {DATE}, required = {false}, min = {false}, max = {false}, step = {false}, visibility = {normal}'; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('birthday', '$value', 'teachpress_stud')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('birthday', '$value', 'teachpress_stud')"); // semester_number $value = 'name = {semester_number}, title = {' . __('Semester number','teachpress') . '}, type = {INT}, required = {false}, min = {1}, max = {99}, step = {1}, visibility = {normal}'; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('semester_number', '$value', 'teachpress_stud')"); + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('semester_number', '$value', 'teachpress_stud')"); // matriculation_number $value = 'name = {matriculation_number}, title = {' . __('Matriculation number','teachpress') . '}, type = {INT}, required = {false}, min = {1}, max = {1000000}, step = {1}, visibility = {admin}'; - $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('matriculation_number', '$value', 'teachpress_stud')"); - + $wpdb->query("INSERT INTO " . TEACHPRESS_SETTINGS . " (`variable`, `value`, `category`) VALUES ('matriculation_number', '$value', 'teachpress_stud')"); + } - + /** * Create table teachpress_pub * @param string $charset_collate @@ -459,13 +460,13 @@ public static function add_default_settings(){ */ public static function add_table_pub($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_PUB . "'") == TEACHPRESS_PUB ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_PUB . " ( `pub_id` INT UNSIGNED AUTO_INCREMENT, `title` VARCHAR(500), @@ -509,11 +510,11 @@ public static function add_table_pub($charset_collate) { `import_id` INT, PRIMARY KEY (pub_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_PUB); } - + /** * Create table teachpress_pub_meta * @param string $charset_collate @@ -521,13 +522,13 @@ public static function add_table_pub($charset_collate) { */ public static function add_table_pub_meta($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_PUB_META . "'") == TEACHPRESS_PUB_META ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_PUB_META . " ( `meta_id` INT UNSIGNED AUTO_INCREMENT, `pub_id` INT UNSIGNED, @@ -535,11 +536,11 @@ public static function add_table_pub_meta($charset_collate) { `meta_value` TEXT, PRIMARY KEY (meta_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_PUB_META); } - + /** * Create table pub_capabilites * @param string $charset_collate @@ -547,13 +548,13 @@ public static function add_table_pub_meta($charset_collate) { */ public static function add_table_pub_capabilites($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_PUB_CAPABILITES . "'") == TEACHPRESS_PUB_CAPABILITES ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_PUB_CAPABILITES . " ( `cap_id` INT UNSIGNED AUTO_INCREMENT, `wp_id` INT UNSIGNED, @@ -561,11 +562,11 @@ public static function add_table_pub_capabilites($charset_collate) { `capability` VARCHAR(100), PRIMARY KEY (`cap_id`) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_PUB_CAPABILITES); } - + /** * Create table pub_documents * @param string $charset_collate @@ -573,13 +574,13 @@ public static function add_table_pub_capabilites($charset_collate) { */ public static function add_table_pub_documents($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_PUB_DOCUMENTS . "'") == TEACHPRESS_PUB_DOCUMENTS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_PUB_DOCUMENTS . " ( `doc_id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR(500), @@ -590,11 +591,11 @@ public static function add_table_pub_documents($charset_collate) { `pub_id` INT UNSIGNED, PRIMARY KEY (doc_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_PUB_DOCUMENTS); } - + /** * Create table pub_imports * @param string $charset_collate @@ -602,24 +603,24 @@ public static function add_table_pub_documents($charset_collate) { */ public static function add_table_pub_imports($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_PUB_IMPORTS . "'") == TEACHPRESS_PUB_IMPORTS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_PUB_IMPORTS . " ( `id` INT UNSIGNED AUTO_INCREMENT, `wp_id` INT UNSIGNED, `date` DATETIME, PRIMARY KEY (id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_PUB_DOCUMENTS); } - + /** * Create table teachpress_tags * @param string $charset_collate @@ -627,23 +628,23 @@ public static function add_table_pub_imports($charset_collate) { */ public static function add_table_tags($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_TAGS . "'") == TEACHPRESS_TAGS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_TAGS . " ( `tag_id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR(300), PRIMARY KEY (tag_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_TAGS); } - + /** * Create table teachpress_relation * @param string $charset_collate @@ -651,24 +652,24 @@ public static function add_table_tags($charset_collate) { */ public static function add_table_relation($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_RELATION . "'") == TEACHPRESS_RELATION ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_RELATION . " ( `con_id` INT UNSIGNED AUTO_INCREMENT, `pub_id` INT UNSIGNED, `tag_id` INT UNSIGNED, PRIMARY KEY (con_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_RELATION); } - + /** * Create table teachpress_user * @param string $charset_collate @@ -676,24 +677,24 @@ public static function add_table_relation($charset_collate) { */ public static function add_table_user($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_USER . "'") == TEACHPRESS_USER ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_USER . " ( `bookmark_id` INT UNSIGNED AUTO_INCREMENT, `pub_id` INT UNSIGNED, `user` INT UNSIGNED, PRIMARY KEY (bookmark_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_USER); } - + /** * Create table teachpress_authors * @param string $charset_collate @@ -701,24 +702,24 @@ public static function add_table_user($charset_collate) { */ public static function add_table_authors($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_AUTHORS . "'") == TEACHPRESS_AUTHORS ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_AUTHORS . " ( `author_id` INT UNSIGNED AUTO_INCREMENT, `name` VARCHAR(500), `sort_name` VARCHAR(500), PRIMARY KEY (author_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_AUTHORS); } - + /** * Create table teachpress_rel_pub_auth * @param string $charset_collate @@ -726,13 +727,13 @@ public static function add_table_authors($charset_collate) { */ public static function add_table_rel_pub_auth($charset_collate) { global $wpdb; - + if( $wpdb->get_var("SHOW TABLES LIKE '" . TEACHPRESS_REL_PUB_AUTH . "'") == TEACHPRESS_REL_PUB_AUTH ) { return; } - + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - + dbDelta("CREATE TABLE " . TEACHPRESS_REL_PUB_AUTH . " ( `con_id` INT UNSIGNED AUTO_INCREMENT, `pub_id` INT UNSIGNED, @@ -741,17 +742,17 @@ public static function add_table_rel_pub_auth($charset_collate) { `is_editor` INT(1), PRIMARY KEY (con_id) ) $charset_collate;"); - + // test engine self::change_engine(TEACHPRESS_REL_PUB_AUTH); } - + /** * Add capabilities * @since 5.0.0 */ private static function add_capabilites() { - // + // global $wp_roles; $role = $wp_roles->get_role('administrator'); if ( !$role->has_cap('use_teachpress') ) { @@ -761,22 +762,22 @@ private static function add_capabilites() { $wp_roles->add_cap('administrator', 'use_teachpress_courses'); } } - + /** * charset & collate like WordPress * @since 5.0.0 */ public static function get_charset() { - global $wpdb; + global $wpdb; $charset_collate = ''; if ( ! empty($wpdb->charset) ) { $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; - } + } if ( ! empty($wpdb->collate) ) { $charset_collate .= " COLLATE $wpdb->collate"; } $charset_collate .= " ENGINE = INNODB"; return $charset_collate; } - + } diff --git a/core/templates.php b/core/templates.php index 0a039a9..34192bb 100644 --- a/core/templates.php +++ b/core/templates.php @@ -17,7 +17,7 @@ interface tp_publication_template { * @since 6.0.0 */ public function get_settings(); - + /** * Returns the body element for a publication list * @param string $content The content of the publication list itself @@ -26,7 +26,7 @@ public function get_settings(); * @since 6.0.0 */ public function get_body($content, $args = array()); - + /** * Returns the headline for a publication list or a part of that * @param string $content The content of the headline @@ -35,7 +35,7 @@ public function get_body($content, $args = array()); * @since 6.0.0 */ public function get_headline($content, $args = array()); - + /** * Returns the headline (second level) for a publication list or a part of that * @param string $content The content of the headline @@ -44,7 +44,7 @@ public function get_headline($content, $args = array()); * @since 6.0.0 */ public function get_headline_sl($content, $args = array()); - + /** * Returns the single entry of a publication list * @param object $interface The interface object @@ -60,7 +60,7 @@ public function get_entry($interface); */ class tp_publication_interface { protected $data; - + /** * Returns the data for a publication row * @return array @@ -70,7 +70,7 @@ class tp_publication_interface { public function get_data() { return $this->data; } - + /** * Sets the data for a publication row * @param array $data @@ -80,7 +80,7 @@ public function get_data() { public function set_data($data) { $this->data = $data; } - + /** * Generates a span element for the selected publication data field * @param string $element The data field (for example: status, journal, type ) @@ -102,7 +102,7 @@ public function get_label ($element, $values = array()) { return '' . $title . ''; } } - + /** * Returns the number for a numbered publication list * @param string $before @@ -113,14 +113,14 @@ public function get_label ($element, $values = array()) { */ public function get_number ($before = '', $after = '') { $settings = $this->data['settings']; - + if ( $settings['style'] === 'std_num' || $settings['style'] === 'std_num_desc' || $settings['style'] === 'numbered' || $settings['style'] === 'numbered_desc' ) { return $before . $this->data['counter'] . $after; } - + return ''; - } - + } + /** * Returns the title * @return string @@ -130,7 +130,7 @@ public function get_number ($before = '', $after = '') { public function get_title () { return $this->data['title']; } - + /** * Returns the type of a publication * @return string @@ -141,7 +141,7 @@ public function get_type() { $type = $this->data['row']['type']; return '' . tp_translate_pub_type($type) . ''; } - + /** * Returns the authors * @param string $before @@ -156,7 +156,7 @@ public function get_author ($before = '', $after = '') { } return $before . $this->data['all_authors'] . $after; } - + /** * Returns the meta row * @return string @@ -166,7 +166,7 @@ public function get_author ($before = '', $after = '') { public function get_meta () { return tp_html::get_publication_meta_row($this->data['row'], $this->data['settings']); } - + /** * Returns the tags * @param string $before @@ -178,7 +178,7 @@ public function get_meta () { public function get_tag_line ($before = '', $after = '') { $tag_string = $this->data['tag_line']; $separator = $this->data['template_settings']['button_separator']; - + // meta line formatting if ( $tag_string !== '' ) { // Hack fix: Replace empty sections in tag string @@ -190,7 +190,7 @@ public function get_tag_line ($before = '', $after = '') { } return $tag_string; } - + /** * Returns the year * @return string @@ -200,7 +200,7 @@ public function get_tag_line ($before = '', $after = '') { public function get_year () { return $this->data['row']['year']; } - + /** * Returns the images * @param string $position @@ -219,7 +219,7 @@ public function get_images ($position) { return $this->data['images']['bottom']; } } - + /** * Returns an info container * @return string @@ -240,12 +240,12 @@ public function get_infocontainer () { // div bibtex $content .= tp_html_publication_template::get_info_container( nl2br( tp_bibtex::get_single_publication_bibtex($row, $keywords, $settings['convert_bibtex']) ), 'bibtex', $container_id ); - + // div abstract if ( $row['abstract'] != '' ) { $content .= tp_html_publication_template::get_info_container( tp_html::prepare_text($row['abstract']), 'abstract', $container_id ); } - + // div links if ( ($row['url'] != '' || $row['doi'] != '') && ( $settings['link_style'] === 'inline' || $settings['link_style'] === 'direct' ) ) { $content .= tp_html_publication_template::get_info_container( tp_html_publication_template::prepare_url($row['url'], $row['doi'], 'list'), 'links', $container_id ); @@ -253,9 +253,9 @@ public function get_infocontainer () { return $content; - - } - + + } + } @@ -264,7 +264,7 @@ public function get_infocontainer () { * @since 6.0.0 */ class tp_html_publication_template { - + /** * Gets a single publication in html format * @param array $row The publication array (used keys: title, image_url, ...) @@ -297,7 +297,7 @@ public static function get_single ($row, $all_tags, $settings, $template, $pub_c $keywords = $generated['keywords']; $tag_string = __('Tags') . ': ' . $generated['tags']; } - + // parse author names for teachPress style if ( $row['type'] === 'collection' || $row['type'] === 'periodical' || ( $row['author'] === '' && $row['editor'] !== '' ) ) { $all_authors = tp_bibtex::parse_author($row['editor'], $settings['author_separator'], $settings['author_name'] ) . ' (' . __('Ed.','teachpress') . ')'; @@ -311,13 +311,13 @@ public static function get_single ($row, $all_tags, $settings, $template, $pub_c $altmetric = self::get_info_button(__('Altmetric','teachpress'), __('Show Altmetric','teachpress'), 'altmetric', $container_id) . $separator; $is_button = true; } - + // if there is an abstract if ( $row['abstract'] != '' ) { $abstract = self::get_info_button(__('Abstract','teachpress'), __('Show abstract','teachpress'), 'abstract', $container_id) . $separator; $is_button = true; } - + // if there are links if ( $row['url'] != '' || $row['doi'] != '' ) { if ( $settings['link_style'] === 'inline' || $settings['link_style'] === 'direct' ) { @@ -328,7 +328,7 @@ public static function get_single ($row, $all_tags, $settings, $template, $pub_c $url = '' . $separator . __('Links','teachpress') . ': ' . self::prepare_url($row['url'], $row['doi'], 'enumeration') . ''; } } - + // if with bibtex if ( $settings['show_bibtex'] === true ) { $bibtex = self::get_info_button(__('BibTeX','teachpress'), __('Show BibTeX entry','teachpress'), 'bibtex', $container_id) . $separator; @@ -342,7 +342,7 @@ public static function get_single ($row, $all_tags, $settings, $template, $pub_c else { $tag_string = $abstract . $bibtex . $altmetric . $tag_string . $url ; } - + // load template interface $interface_data = array ( 'row' => $row, @@ -356,10 +356,10 @@ public static function get_single ($row, $all_tags, $settings, $template, $pub_c 'container_id' => $container_id, 'template_settings' => $template_settings ); - + $interface = new tp_publication_interface(); $interface->set_data($interface_data); - + // load entry template $s = $template->get_entry($interface); return $s; @@ -380,7 +380,7 @@ public static function get_info_button ($name, $title, $type, $container_id) { $s = '' . $name . ''; return $s; } - + /** * Returns the info container for a publication * @param string $content The content you want to show @@ -396,7 +396,7 @@ public static function get_info_container ($content, $type, $container_id) { $s .= ''; return $s; } - + /** * This function prepares the publication title for html publication lists. * @param array $row The publication array @@ -406,42 +406,42 @@ public static function get_info_container ($content, $type, $container_id) { * @since 6.0.0 */ public static function prepare_publication_title ($row, $settings, $container_id) { - + // open abstracts instead of links (ignores the rest of the method) if ( $settings['title_ref'] === 'abstract' ) { return self::prepare_title_link_to_abstracts($row, $container_id); } - + // Use a related page as link if ( $row['rel_page'] != 0 ) { return '' . stripslashes($row['title']) . ''; } - + // for inline style elseif ( $row['url'] != '' && $settings['link_style'] === 'inline' ) { return '' . tp_html::prepare_title($row['title'], 'decode') . ''; } - + // for direct style (if a DOI numer exists) elseif ( $row['doi'] != '' && $settings['link_style'] === 'direct' ) { - $title = tp_html::prepare_title($row['title'], 'decode'); - $doi_url = tp_html_publication_template::prepare_doi_url($row['doi']); - return '' . $title . ''; + $title = tp_html::prepare_title($row['title'], 'decode'); + $doi_url = tp_html_publication_template::prepare_doi_url($row['doi']); + return '' . $title . ''; } - + // for direct style (use the first available URL) - elseif ( $row['url'] != '' && $settings['link_style'] === 'direct' ) { - $parts = tp_bibtex::explode_url($row['url']); - return '' . tp_html::prepare_title($row['title'], 'decode') . ''; - } - + elseif ( $row['url'] != '' && $settings['link_style'] === 'direct' ) { + $parts = tp_bibtex::explode_url($row['url']); + return '' . tp_html::prepare_title($row['title'], 'decode') . ''; + } + // if there is no link else { return tp_html::prepare_title($row['title'], 'decode'); } } - + /** * Prepares a title if the link should refers to the abstract * @param array $row The publication array @@ -458,9 +458,9 @@ private static function prepare_title_link_to_abstracts($row, $container_id) { return tp_html::prepare_title($row['title'], 'decode'); } } - + /** - * Prepares a url link for publication resources + * Prepares a url link for publication resources * @param string $url The url string * @param string $doi The DOI number * @param string $mode list or enumeration @@ -479,7 +479,7 @@ public static function prepare_url($url, $doi = '', $mode = 'list') { $parts = explode(', ',$url); $parts[0] = trim( $parts[0] ); $parts[1] = isset( $parts[1] ) ? $parts[1] : $parts[0]; - // list mode + // list mode if ( $mode === 'list' ) { $length = strlen($parts[1]); $parts[1] = substr($parts[1], 0 , 80); @@ -493,53 +493,76 @@ public static function prepare_url($url, $doi = '', $mode = 'list') { $end .= ''; } } - + /** * Add DOI-URL * @since 5.0.0 */ - if ($doi != '') { - - $doi_url = tp_html_publication_template::prepare_doi_url($doi); - - if ( $mode === 'list' ) { - $end .= '
  • doi:' . $doi . '
  • '; - } - else { - $end .= ''; - } - } - + if ($doi != '') { + $end .= tp_html_publication_template::prepare_doi_href($doi, $mode); + } + + if ( $mode === 'list' ) { + $end = '
      ' . $end . '
    '; + } + + return $end; + } + + /** + * Prepares a doi href + * @param string $doi The DOI number + * @param string $mode list or enumeration + * @return string + * @since 6.x.x + * @version 1 + * @access public + */ + public static function prepare_doi_href($doi, $mode) { + $doi_href = ''; + $doi_url = tp_html_publication_template::prepare_doi_url($doi); + $doi_resolver_href_label_custom = get_tp_option('doi_resolver_href_label_custom'); + $doi_href_title = __('Follow DOI:','teachpress'); + $doi_href_label = 'doi:' . $doi; + + if ( isset($doi_resolver_href_label_custom) ) { + $doi_href_title = $doi_resolver_href_label_custom; + $doi_href_label = $doi_resolver_href_label_custom; + } + if ( $mode === 'list' ) { - $end = '
      ' . $end . '
    '; + $doi_href .= '
  • ' . $doi_href_label . ' (' . $doi . ')
  • '; } - - return $end; + else { + $doi_href .= '' . $doi_href_label . ' (' . $doi . ')'; + } + + return $doi_href; } - - /** + + /** * Prepares a doi url - * @param string $doi The DOI number + * @param string $doi The DOI number * @return string * @since 6.x.x * @version 1 * @access public */ - public static function prepare_doi_url($doi) { - $doi_resolver_url_template = ''; - - if ( get_tp_option('doi_resolver_url_template_custom') != '' ) { - $doi_resolver_url_template = get_tp_option('doi_resolver_url_template_custom'); - } - else { - $doi_resolver_url_template = get_tp_option('doi_resolver_url_template_default'); - } - - return str_replace('%doi%', $doi, $doi_resolver_url_template); - } + public static function prepare_doi_url($doi) { + $doi_resolver_url_template = ''; + + if ( get_tp_option('doi_resolver_url_template_custom') != '' ) { + $doi_resolver_url_template = get_tp_option('doi_resolver_url_template_custom'); + } + else { + $doi_resolver_url_template = get_tp_option('doi_resolver_url_template_default'); + } + + return str_replace('%doi%', $doi, $doi_resolver_url_template); + } /** - * Prepares an altmetric info block + * Prepares an altmetric info block * @param string $doi The DOI number * @return string * @since 3.0.0 @@ -557,14 +580,14 @@ public static function prepare_altmetric($doi = '') { $end .= '
    '; } - - + + return $end; } - - + + /** * Generates the tag string for a single publication * @param array $row The publication array @@ -585,7 +608,7 @@ public static function get_tags ($row, $all_tags, $settings) { return array('tags' => substr($tag_string, 0, -2), 'keywords' => $keywords); } - + /** * Generates the HTML output for images * @param array $row The publication array @@ -597,22 +620,22 @@ public static function handle_images ($row, $settings) { $return = array('bottom' => '', 'left' => '', 'right' => ''); - + $image = ''; // return if no images is set if ( $settings['image'] === 'none' ) { return $return; } - + // define the width of the image $width = ( $settings['image'] === 'bottom' ) ? 'style="max-width:' . ($settings['pad_size'] - 5) .'px;"' : 'width="' . ( $settings['pad_size'] - 5 ) .'"'; - + // general html output if ( $row['image_url'] !== '' ) { $image = '' . tp_html::prepare_title($row['title'], 'replace') . ''; } - + // image link if ( $settings['image_link'] === 'self' ) { $image = '' . $image . ''; @@ -620,7 +643,7 @@ public static function handle_images ($row, $settings) { if ( $settings['image_link'] === 'post' && $row['rel_page'] != 0 ) { $image = '' . $image . ''; } - + // Altmetric donut $altmetric = ''; if( $settings['show_altmetric_donut']) { @@ -630,19 +653,18 @@ public static function handle_images ($row, $settings) { if ( $settings['image'] === 'left' ) { $return['left'] = '' . $image . $altmetric . ''; } - + // right position if ( $settings['image'] === 'right' ) { $return['right'] = '' . $image . $altmetric . ''; } - + // bottom position if ( $settings['image'] === 'bottom' ) { $return['bottom'] = '
    ' . $image . '
    '. $altmetric; } - + return $return; } - -} +}