diff --git a/src/assets/images/tainacan_logo_symbol.svg b/src/assets/images/tainacan_logo_symbol.svg index cc8c0de56..62d4cf1f9 100644 --- a/src/assets/images/tainacan_logo_symbol.svg +++ b/src/assets/images/tainacan_logo_symbol.svg @@ -1,71 +1,16 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - + + + + + +image/svg+xml + + + + + + + + + diff --git a/src/classes/tainacan-creator.php b/src/classes/tainacan-creator.php index b022b5f4e..a8dd04bd2 100644 --- a/src/classes/tainacan-creator.php +++ b/src/classes/tainacan-creator.php @@ -151,8 +151,8 @@ $Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance(); $Tainacan_Embed = \Tainacan\Embed::get_instance(); -require_once(__DIR__ . '/../views/class-tainacan-admin.php'); -$Tainacan_Admin = \Tainacan\Admin::get_instance(); +require_once(__DIR__ . '/../views/class-tainacan-views.php'); +$Tainacan_Views = \Tainacan\Views::get_instance(); require_once(__DIR__ . '/../views/admin/classes/hooks/class-tainacan-admin-hooks.php'); require_once(__DIR__ . '/../views/admin/classes/hooks/admin-hooks-functions.php'); diff --git a/src/views/admin/class-tainacan-admin.php b/src/views/admin/class-tainacan-admin.php new file mode 100644 index 000000000..b3ad5c977 --- /dev/null +++ b/src/views/admin/class-tainacan-admin.php @@ -0,0 +1,281 @@ +tainacan_root_menu_slug, + __( 'Repository', 'tainacan' ), + __( 'Repository', 'tainacan' ), + 'read', + $this->repository_links_slug, + array( &$this, 'admin_page' ), + ); + add_action( 'load-' . $tainacan_page_suffix, array( &$this, 'load_admin_page' ) ); + + // Inner links to the admin vue component + add_submenu_page( + $this->repository_links_slug, + __('Metadata', 'tainacan'), + __('Metadata', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/metadata', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->repository_links_slug, + __('Filters', 'tainacan'), + __('Filters', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/filters', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->repository_links_slug, + __('Taxonomies', 'tainacan'), + __('Taxonomies', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/taxonomies', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->repository_links_slug, + __('Activities', 'tainacan'), + __('Activities', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/activities', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->repository_links_slug, + __('Capabilities', 'tainacan'), + __('Capabilities', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/capabilities', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->repository_links_slug, + __('Importers', 'tainacan'), + __('Importers', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/importers', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->repository_links_slug, + __('Exporters', 'tainacan'), + __('Exporters', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/exporters', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + \Tainacan\Views::get_instance()->tainacan_root_menu_slug, + __('Collections', 'tainacan'), + __('Collections', 'tainacan'), + 'read', + $this->collections_links_slug, + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->collections_links_slug, + __('Collections list', 'tainacan'), + __('Collections list', 'tainacan'), + 'read', + $this->vue_component_page_slug . '#/collections', + array( &$this, 'admin_page' ) + ); + add_submenu_page( + $this->collections_links_slug, + __('Items', 'tainacan'), + __('Items', 'tainacan'), + 'read', + 'tainacan_admin#/items', + array( &$this, 'admin_page' ) + ); + } + + function load_admin_page() { + add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_css' ), 90 ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_js' ), 90 ); + } + + function add_admin_css() { + global $TAINACAN_BASE_URL; + + wp_enqueue_style( 'tainacan-fonts', $TAINACAN_BASE_URL . '/assets/css/tainacanicons.css', [], TAINACAN_VERSION ); + wp_enqueue_script('underscore'); + wp_enqueue_style( 'roboto-fonts', 'https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i,700,700i', [] ); + wp_enqueue_style( 'tainacan-admin-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-admin.css', [], TAINACAN_VERSION ); + + // $undesired_wp_styles = [ + // 'admin-menu', + // 'admin-bar', + // 'code-editor', + // 'color-picker', + // 'customize-controls', + // 'customize-nav-menus', + // 'customize-widgets', + // 'dashboard', + // 'dashicons', + // 'deprecated-media', + // 'edit', + // 'wp-pointer', + // 'farbtastic', + // 'forms', + // 'common', + // 'install', + // 'wp-auth-check', + // 'site-icon', + // 'buttons', + // 'l10n', + // 'list-tables', + // 'login', + // 'media', + // 'nav-menus', + // 'revisions', + // 'themes', + // 'widgets', + // 'wp-admin' + // ]; + + // wp_dequeue_style( $undesired_wp_styles ); + // wp_deregister_style( $undesired_wp_styles ); + + } + + function add_admin_js() { + global $TAINACAN_BASE_URL; + global $TAINACAN_EXTRA_SCRIPTS; + + $deps = ['underscore', 'media-editor', 'media-views', 'customize-controls', 'wp-i18n']; + if ( !empty($TAINACAN_EXTRA_SCRIPTS) ) { + foreach($TAINACAN_EXTRA_SCRIPTS as $dep) { + $deps[] = $dep; + } + } + + wp_enqueue_script( + 'tainacan-pages-common-scripts', + $TAINACAN_BASE_URL . '/assets/js/tainacan_pages_common_scripts.js', + $deps, + TAINACAN_VERSION + ); + $settings = \Tainacan\Views::get_instance()->get_admin_js_localization_params(); + + wp_localize_script( 'tainacan-pages-common-scripts', 'tainacan_plugin', $settings ); + wp_enqueue_media( + //[ 'post' => 131528 ] + ); + wp_enqueue_script('underscore'); + wp_enqueue_script('jcrop'); + wp_enqueue_script( 'customize-controls' ); + + do_action('tainacan-enqueue-admin-scripts'); + + } + + function admin_body_class( $classes ) { + + if ( isset( $_GET['page'] ) && $_GET['page'] == $this->vue_component_page_slug ) + $classes .= ' tainacan-admin-page'; + + return $classes; + } + + function admin_page() { + \Tainacan\Views::get_instance()->the_admin_navigation_menu(); + // @deprecated: use tainacan-admin-ui-options instead + $admin_options = apply_filters('set_tainacan_admin_options', $_GET); + $admin_options = apply_filters('tainacan-admin-ui-options', $_GET); + $admin_options = json_encode($admin_options); + echo "
"; + } + + /** + * Ajax request used in admin to create slug for entities based on the title + */ + function ajax_sample_permalink(){ + + $id = sanitize_text_field($_POST['post_id']); + $title = sanitize_text_field($_POST['new_title']); + $name = sanitize_text_field($_POST['new_slug']); + + $post = get_post( $id ); + if ( ! $post ) + return array( '', '' ); + + $ptype = get_post_type_object($post->post_type); + + // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published. + if ( in_array( $post->post_status, array( 'auto-draft', 'draft', 'pending', 'future' ) ) ) { + $post->post_status = 'publish'; + $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID); + } + + // If the user wants to set a new name -- override the current one + // Note: if empty name is supplied -- use the title instead, see #6072 + if ( !is_null($name) ) + $post->post_name = sanitize_title($name ? $name : $title, $post->ID); + + $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); + if ( $post->post_type === \Tainacan\Entities\Taxonomy::$post_type ) { + $post_name = $post->post_name; + $tax = \get_taxonomies(array('name' => $post_name)); + $suffix = 2; + while ( !empty($tax) ) { + $post_name = _truncate_post_slug( $post_name, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; + $tax = \get_taxonomies(array('name' => $post_name)); + $suffix++; + }; + $post->post_name = $post_name; + } + + $post->filter = 'sample'; + + $permalink = get_permalink($post, true); + + // Replace custom post_type Token with generic pagename token for ease of use. + $permalink = str_replace("%$post->post_type%", '%pagename%', $permalink); + + // Handle page hierarchy + if ( $ptype->hierarchical ) { + $uri = get_page_uri($post); + if ( $uri ) { + $uri = untrailingslashit($uri); + $uri = strrev( stristr( strrev( $uri ), '/' ) ); + $uri = untrailingslashit($uri); + } + + /** This filter is documented in wp-admin/edit-tag-form.php */ + $uri = apply_filters( 'editable_slug', $uri, $post ); + if ( !empty($uri) ) + $uri .= '/'; + $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink); + } + + /** This filter is documented in wp-admin/edit-tag-form.php */ + $permalink = array( 'permalink' => $permalink, 'slug' => apply_filters( 'editable_slug', $post->post_name, $post ) ); + + echo json_encode($permalink); + + wp_die(); + } +} + diff --git a/src/views/admin/scss/tainacan-admin.scss b/src/views/admin/scss/tainacan-admin.scss index 60d49cb5c..ba73443bb 100644 --- a/src/views/admin/scss/tainacan-admin.scss +++ b/src/views/admin/scss/tainacan-admin.scss @@ -35,19 +35,19 @@ html { overflow-y: hidden; } -body.tainacan-admin-page #adminmenumain, body.tainacan-admin-page #wpfooter { - display: none; -} +// body.tainacan-admin-page #adminmenumain, body.tainacan-admin-page #wpfooter { +// display: none; +// } body.tainacan-admin-page #wp-auth-check-wrap { z-index: 9999999; } #tainacan-admin-app { background: var(--tainacan-background-color); - position: fixed; - top: 0; - left: 0; - bottom: 0; - right: 0; + // position: fixed; + // top: 0; + // left: 0; + // bottom: 0; + // right: 0; width: 100%; z-index: 999999; overflow-y: auto; diff --git a/src/views/class-tainacan-admin.php b/src/views/class-tainacan-admin.php deleted file mode 100644 index 1de81816f..000000000 --- a/src/views/class-tainacan-admin.php +++ /dev/null @@ -1,562 +0,0 @@ -menu_slug, - array( &$this, 'admin_page' ), - plugin_dir_url( __FILE__ ) . '../assets/images/tainacan_logo_symbol.svg' - ); - - add_submenu_page( - $this->menu_slug, - __('System check', 'tainacan'), - __('System check', 'tainacan'), - 'manage_options', - 'tainacan_systemcheck', - array( &$this, 'systemcheck_page' ) - ); - - $roles_page_suffix = add_submenu_page( - $this->menu_slug, - __('User Roles', 'tainacan'), - __('User Roles', 'tainacan'), - 'tnc_rep_edit_users', - 'tainacan_roles', - array( &$this, 'roles_page' ) - ); - - $reports_page_suffix = add_submenu_page( - $this->menu_slug, - __('Reports', 'tainacan'), - __('Reports', 'tainacan'), - 'manage_tainacan', - 'tainacan_reports', - array( &$this, 'reports_page' ) - ); - - add_submenu_page( - $this->menu_slug, - __('Item Submission', 'tainacan'), - __('Item Submission', 'tainacan'), - 'manage_options', - 'tainacan_item_submission', - array( &$this, 'item_submission' ) - ); - - $mobile_app_page_suffix = add_submenu_page( - 'tainacan-no-show-menu', // Mobile app page is not listed in the menu - __('Mobile App', 'tainacan'), - __('Mobile App', 'tainacan'), - 'manage_tainacan', - 'tainacan_mobile_app', - array( &$this, 'mobile_app' ) - ); - - $dashboard_page_suffix = add_submenu_page( - $this->menu_slug, - __('Dashboard', 'tainacan'), - __('Dashboard', 'tainacan'), - 'manage_tainacan', - 'tainacan_dashboard', - array( &$this, 'dashboard' ) - ); - - add_action( 'load-' . $page_suffix, array( &$this, 'load_admin_page' ) ); - add_action( 'load-' . $roles_page_suffix, array( &$this, 'load_roles_page' ) ); - add_action( 'load-' . $reports_page_suffix, array( &$this, 'load_reports_page' ) ); - add_action( 'load-' . $mobile_app_page_suffix, array( &$this, 'load_mobile_app_page' ) ); - add_action( 'load-' . $dashboard_page_suffix, array( &$this, 'load_dashboard_page' ) ); - } - - function load_admin_page() { - add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_css' ), 90 ); - add_action( 'admin_enqueue_scripts', array( &$this, 'add_admin_js' ), 90 ); - add_action( 'admin_enqueue_scripts', array(&$this, 'add_theme_files') ); - } - - function load_roles_page() { - add_action( 'admin_enqueue_scripts', array( &$this, 'add_roles_css' ), 90 ); - add_action( 'admin_enqueue_scripts', array( &$this, 'add_roles_js' ), 90 ); - } - - function load_reports_page() { - add_action( 'admin_enqueue_scripts', array( &$this, 'add_reports_css' ), 90 ); - add_action( 'admin_enqueue_scripts', array( &$this, 'add_reports_js' ), 90 ); - } - - function load_mobile_app_page() { - add_action( 'admin_enqueue_scripts', array( &$this, 'add_mobile_app_css' ), 90 ); - } - function load_dashboard_page() { - add_action( 'admin_enqueue_scripts', array( &$this, 'add_dashboard_css' ), 90 ); - add_action( 'admin_enqueue_scripts', array( &$this, 'add_dashboard_js' ), 90 ); - } - - function login_styles_reset( $style ) { - if ( strpos( $style, 'wp-admin-css' ) !== false ) { - $style = null; - } - - return $style; - } - - function load_theme_files() { - add_action( 'wp_enqueue_scripts', array(&$this, 'add_theme_files') ); - } - - function add_theme_files() { - global $TAINACAN_BASE_URL; - - wp_enqueue_style( 'tainacan-fonts', $TAINACAN_BASE_URL . '/assets/css/tainacanicons.css', [], TAINACAN_VERSION ); - wp_enqueue_script('underscore'); - } - - function add_roles_css() { - global $TAINACAN_BASE_URL; - - wp_enqueue_style( 'tainacan-roles-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-roles.css', [], TAINACAN_VERSION ); - } - - function add_mobile_app_css() { - global $TAINACAN_BASE_URL; - - wp_enqueue_style( 'tainacan-mobile-app-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-mobile-app.css', [], TAINACAN_VERSION ); - } - - function add_dashboard_css() { - global $TAINACAN_BASE_URL; - - wp_admin_css( 'dashboard' ); - //wp_enqueue_style( 'tainacan-dashboard-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-dashboard.css', [], TAINACAN_VERSION ); - } - - function add_dashboard_js() { - global $TAINACAN_BASE_URL; - - wp_enqueue_script( 'dashboard' ); - } - - function add_roles_js() { - - global $TAINACAN_BASE_URL; - - wp_enqueue_script( - 'tainacan-pages-common-scripts', - $TAINACAN_BASE_URL . '/assets/js/tainacan_pages_common_scripts.js', - ['underscore', 'wp-i18n'], - TAINACAN_VERSION - ); - wp_set_script_translations('tainacan-pages-common-scripts', 'tainacan'); - - $settings = $this->get_admin_js_localization_params(); - wp_localize_script( 'tainacan-pages-common-scripts', 'tainacan_plugin', $settings ); - wp_enqueue_script('underscore'); - wp_enqueue_script('wp-i18n'); - - do_action('tainacan-enqueue-roles-scripts'); - } - - function roles_page() { - global $TAINACAN_BASE_URL; - echo "
"; - } - - function add_reports_css() { - global $TAINACAN_BASE_URL; - wp_enqueue_style( 'tainacan-fonts', $TAINACAN_BASE_URL . '/assets/css/tainacanicons.css', [], TAINACAN_VERSION ); - wp_enqueue_style( 'tainacan-reports-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-reports.css', [], TAINACAN_VERSION ); - } - - function add_reports_js() { - - global $TAINACAN_BASE_URL; - - wp_enqueue_script( - 'tainacan-pages-common-scripts', - $TAINACAN_BASE_URL . '/assets/js/tainacan_pages_common_scripts.js', - ['underscore', 'wp-i18n'], - TAINACAN_VERSION - ); - wp_set_script_translations('tainacan-pages-common-scripts', 'tainacan'); - - $settings = $this->get_admin_js_localization_params(); - wp_localize_script( 'tainacan-pages-common-scripts', 'tainacan_plugin', $settings ); - wp_enqueue_script('underscore'); - wp_enqueue_script('wp-i18n'); - - do_action('tainacan-enqueue-reports-scripts'); - } - - function reports_page() { - global $TAINACAN_BASE_URL; - echo "
"; - } - - function add_admin_css() { - global $TAINACAN_BASE_URL; - - wp_enqueue_style( 'roboto-fonts', 'https://fonts.googleapis.com/css?family=Roboto:400,400i,500,500i,700,700i', [] ); - wp_enqueue_style( 'tainacan-admin-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-admin.css', [], TAINACAN_VERSION ); - - // $undesired_wp_styles = [ - // 'admin-menu', - // 'admin-bar', - // 'code-editor', - // 'color-picker', - // 'customize-controls', - // 'customize-nav-menus', - // 'customize-widgets', - // 'dashboard', - // 'dashicons', - // 'deprecated-media', - // 'edit', - // 'wp-pointer', - // 'farbtastic', - // 'forms', - // 'common', - // 'install', - // 'wp-auth-check', - // 'site-icon', - // 'buttons', - // 'l10n', - // 'list-tables', - // 'login', - // 'media', - // 'nav-menus', - // 'revisions', - // 'themes', - // 'widgets', - // 'wp-admin' - // ]; - - // wp_dequeue_style( $undesired_wp_styles ); - // wp_deregister_style( $undesired_wp_styles ); - - } - - function add_admin_js() { - global $TAINACAN_BASE_URL; - global $TAINACAN_EXTRA_SCRIPTS; - - $deps = ['underscore', 'media-editor', 'media-views', 'customize-controls', 'wp-i18n']; - if ( !empty($TAINACAN_EXTRA_SCRIPTS) ) { - foreach($TAINACAN_EXTRA_SCRIPTS as $dep) { - $deps[] = $dep; - } - } - - wp_enqueue_script( - 'tainacan-pages-common-scripts', - $TAINACAN_BASE_URL . '/assets/js/tainacan_pages_common_scripts.js', - $deps, - TAINACAN_VERSION - ); - $settings = $this->get_admin_js_localization_params(); - - wp_localize_script( 'tainacan-pages-common-scripts', 'tainacan_plugin', $settings ); - wp_enqueue_media( - //[ 'post' => 131528 ] - ); - wp_enqueue_script('underscore'); - wp_enqueue_script('jcrop'); - wp_enqueue_script( 'customize-controls' ); - - do_action('tainacan-enqueue-admin-scripts'); - - } - - function get_admin_js_localization_params() { - global $TAINACAN_BASE_URL, $TAINACAN_API_MAX_ITEMS_PER_PAGE; - - $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $Tainacan_Metadata_Sections = \Tainacan\Repositories\Metadata_Sections::get_instance(); - $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); - $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); - $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); - - $tainacan_admin_i18n = require( 'tainacan-i18n.php' ); - - $entities_labels = [ - 'collections' => $Tainacan_Collections->get_cpt_labels(), - 'metadata' => $Tainacan_Metadata->get_cpt_labels(), - 'metadata-sections' => $Tainacan_Metadata_Sections->get_cpt_labels(), - 'filters' => $Tainacan_Filters->get_cpt_labels(), - 'items' => $Tainacan_Items->get_cpt_labels(), - 'taxonomies' => $Tainacan_Taxonomies->get_cpt_labels(), - ]; - - $tainacan_admin_i18n['entities_labels'] = $entities_labels; - - $cur_user = wp_get_current_user(); - $user_caps = array(); - $prefs = array(); - $user_data = array(); - if ( $cur_user instanceof \WP_User ) { - $tainacan_caps = \tainacan_roles()->get_repository_caps_slugs(); - foreach ($tainacan_caps as $tcap) { - $user_caps[$tcap] = current_user_can( $tcap ); - } - $prefs = get_user_meta( $cur_user->ID, 'tainacan_prefs', true ); - - if ( $cur_user->data && isset($cur_user->data->user_email) && isset($cur_user->data->display_name) ) { - $user_data = array( - 'ID' => $cur_user->ID, - 'email' => $cur_user->data->user_email, - 'display_name' => $cur_user->data->display_name - ); - } - } - - $settings = [ - 'tainacan_api_url' => esc_url_raw( rest_url() ) . 'tainacan/v2', - 'wp_api_url' => esc_url_raw( rest_url() ) . 'wp/v2/', - 'wp_ajax_url' => admin_url( 'admin-ajax.php' ), - 'nonce' => is_user_logged_in() ? wp_create_nonce( 'wp_rest' ) : false, - 'classes' => array(), - 'i18n' => $tainacan_admin_i18n, - 'user_caps' => $user_caps, - 'user_prefs' => $prefs, - 'user_data' => $user_data, - 'base_url' => $TAINACAN_BASE_URL, - 'plugin_dir_url' => plugin_dir_url( __DIR__ ), - 'admin_url' => admin_url(), - 'theme_items_list_url' => esc_url_raw( get_site_url() ) . '/' . \Tainacan\Theme_Helper::get_instance()->get_items_list_slug(), - 'theme_collection_list_url' => get_post_type_archive_link( 'tainacan-collection' ), - 'theme_taxonomy_list_url' => get_post_type_archive_link( 'tainacan-taxonomy' ), - 'custom_header_support' => get_theme_support('custom-header'), - 'registered_view_modes' => \Tainacan\Theme_Helper::get_instance()->get_registered_view_modes(), - 'exposer_mapper_param' => \Tainacan\Mappers_Handler::MAPPER_PARAM, - 'exposer_type_param' => \Tainacan\Exposers_Handler::TYPE_PARAM, - 'repository_name' => get_bloginfo('name'), - 'api_max_items_per_page' => $TAINACAN_API_MAX_ITEMS_PER_PAGE, - 'wp_elasticpress' => \Tainacan\Elastic_Press::get_instance()->is_active(), - 'item_submission_captcha_site_key' => get_option("tnc_option_recaptch_site_key"), - 'tainacan_enable_core_metadata_on_advanced_search' => ( !defined('TAINACAN_DISABLE_CORE_METADATA_ON_ADVANCED_SEARCH') || false === TAINACAN_DISABLE_CORE_METADATA_ON_ADVANCED_SEARCH ), - 'tainacan_enable_relationship_metaquery' => ( defined('TAINACAN_ENABLE_RELATIONSHIP_METAQUERY') && true === TAINACAN_ENABLE_RELATIONSHIP_METAQUERY ) - ]; - - $maps = [ - 'collections' => $Tainacan_Collections->get_map(), - 'metadata' => $Tainacan_Metadata->get_map(), - 'metadata-sections' => $Tainacan_Metadata_Sections->get_map(), - 'filters' => $Tainacan_Filters->get_map(), - 'items' => $Tainacan_Items->get_map(), - 'taxonomies' => $Tainacan_Taxonomies->get_map(), - ]; - - $metadata_types = $Tainacan_Metadata->fetch_metadata_types(); - - foreach( $maps as $type => $map ){ - foreach ( $map as $metadatum => $details){ - $settings['i18n']['helpers_label'][$type][$metadatum] = [ 'title' => $details['title'], 'description' => $details['description'] ]; - } - } - foreach ( $metadata_types as $index => $metadata_type){ - $class = new $metadata_type; - $settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels(); - } - - $filter_types = $Tainacan_Filters->fetch_filter_types(); - - foreach ( $filter_types as $index => $filter_type){ - $class = new $filter_type; - $settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels(); - } - - $settings['form_hooks'] = Admin_Hooks::get_instance()->get_registered_hooks(); - - $wp_post_types = get_post_types(['show_ui' => true], 'objects'); - if (isset($wp_post_types['attachment'])) { - unset($wp_post_types['attachment']); - } - - $wp_post_types = array_map(function($i) { - return [ - 'slug' => $i->name, - 'label' => $i->label - ]; - }, $wp_post_types); - - $settings['wp_post_types'] = $wp_post_types; - - // Key-valued array with extra options to be passed to every request in the admin (goes the header) - $admin_request_options = []; - $admin_request_options = apply_filters('tainacan-admin-extra-request-options', $admin_request_options); - $settings['admin_request_options'] = $admin_request_options; - - return $settings; - - } - - function admin_body_class( $classes ) { - - if ( isset( $_GET['page'] ) && $_GET['page'] == $this->menu_slug ) - $classes .= ' tainacan-admin-page'; - - return $classes; - } - - function admin_page() { - global $TAINACAN_BASE_URL; - - // @deprecated: use tainacan-admin-ui-options instead - $admin_options = apply_filters('set_tainacan_admin_options', $_GET); - $admin_options = apply_filters('tainacan-admin-ui-options', $_GET); - $admin_options = json_encode($admin_options); - - echo "
"; - } - - function register_user_meta() { - $args = array( - //'sanitize_callback' => array(&$this, 'santize_user_tainacan_prefs'), - //'auth_callback' => 'authorize_my_meta_key', - 'type' => 'string', - 'description' => 'Tainacan admin user preferences', - 'single' => true, - 'show_in_rest' => true, - ); - register_meta( 'user', 'tainacan_prefs', $args ); - } - - function register_user_setting() { - register_setting( - 'tainacan_item_submission_recaptcha', - 'tnc_option_recaptch_site_key', - 'sanitize_text_field' - ); - - register_setting( - 'tainacan_item_submission_recaptcha', - 'tnc_option_recaptch_secret_key', - 'sanitize_text_field' - ); - } - - function ajax_sample_permalink(){ - - $id = sanitize_text_field($_POST['post_id']); - $title = sanitize_text_field($_POST['new_title']); - $name = sanitize_text_field($_POST['new_slug']); - - $post = get_post( $id ); - if ( ! $post ) - return array( '', '' ); - - $ptype = get_post_type_object($post->post_type); - - // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published. - if ( in_array( $post->post_status, array( 'auto-draft', 'draft', 'pending', 'future' ) ) ) { - $post->post_status = 'publish'; - $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID); - } - - // If the user wants to set a new name -- override the current one - // Note: if empty name is supplied -- use the title instead, see #6072 - if ( !is_null($name) ) - $post->post_name = sanitize_title($name ? $name : $title, $post->ID); - - $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); - if ( $post->post_type === \Tainacan\Entities\Taxonomy::$post_type ) { - $post_name = $post->post_name; - $tax = \get_taxonomies(array('name' => $post_name)); - $suffix = 2; - while ( !empty($tax) ) { - $post_name = _truncate_post_slug( $post_name, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; - $tax = \get_taxonomies(array('name' => $post_name)); - $suffix++; - }; - $post->post_name = $post_name; - } - - $post->filter = 'sample'; - - $permalink = get_permalink($post, true); - - // Replace custom post_type Token with generic pagename token for ease of use. - $permalink = str_replace("%$post->post_type%", '%pagename%', $permalink); - - // Handle page hierarchy - if ( $ptype->hierarchical ) { - $uri = get_page_uri($post); - if ( $uri ) { - $uri = untrailingslashit($uri); - $uri = strrev( stristr( strrev( $uri ), '/' ) ); - $uri = untrailingslashit($uri); - } - - /** This filter is documented in wp-admin/edit-tag-form.php */ - $uri = apply_filters( 'editable_slug', $uri, $post ); - if ( !empty($uri) ) - $uri .= '/'; - $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink); - } - - /** This filter is documented in wp-admin/edit-tag-form.php */ - $permalink = array( 'permalink' => $permalink, 'slug' => apply_filters( 'editable_slug', $post->post_name, $post ) ); - - echo json_encode($permalink); - - wp_die(); - } - - public function systemcheck_page() { - require_once('system-check/class-tainacan-system-check.php'); - $check = new System_Check(); - $check->admin_page(); - } - - public function item_submission() { - require_once('item-submission/class-tainacan-item-submission.php'); - $submission = new Item_Submission(); - $submission->admin_page(); - } - - public function mobile_app() { - require_once('mobile-app/class-tainacan-mobile-app.php'); - $Mobile_app = new Mobile_App(); - $Mobile_app->admin_page(); - } - - public function dashboard() { - require_once('dashboard/class-tainacan-dashboard.php'); - $dashboard = new Dashboard(); - $dashboard->admin_page(); - } - -} - diff --git a/src/views/class-tainacan-views.php b/src/views/class-tainacan-views.php new file mode 100644 index 000000000..068b53371 --- /dev/null +++ b/src/views/class-tainacan-views.php @@ -0,0 +1,252 @@ +tainacan_root_menu_slug, + __('Other', 'tainacan'), + __('Other', 'tainacan'), + 'read', + $this->other_links_slug, + '#' + ); + } + + function get_admin_js_localization_params() { + global $TAINACAN_BASE_URL, $TAINACAN_API_MAX_ITEMS_PER_PAGE; + + $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance(); + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + $Tainacan_Metadata_Sections = \Tainacan\Repositories\Metadata_Sections::get_instance(); + $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance(); + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); + + $tainacan_admin_i18n = require( 'tainacan-i18n.php' ); + + $entities_labels = [ + 'collections' => $Tainacan_Collections->get_cpt_labels(), + 'metadata' => $Tainacan_Metadata->get_cpt_labels(), + 'metadata-sections' => $Tainacan_Metadata_Sections->get_cpt_labels(), + 'filters' => $Tainacan_Filters->get_cpt_labels(), + 'items' => $Tainacan_Items->get_cpt_labels(), + 'taxonomies' => $Tainacan_Taxonomies->get_cpt_labels(), + ]; + + $tainacan_admin_i18n['entities_labels'] = $entities_labels; + + $cur_user = wp_get_current_user(); + $user_caps = array(); + $prefs = array(); + $user_data = array(); + if ( $cur_user instanceof \WP_User ) { + $tainacan_caps = \tainacan_roles()->get_repository_caps_slugs(); + foreach ($tainacan_caps as $tcap) { + $user_caps[$tcap] = current_user_can( $tcap ); + } + $prefs = get_user_meta( $cur_user->ID, 'tainacan_prefs', true ); + + if ( $cur_user->data && isset($cur_user->data->user_email) && isset($cur_user->data->display_name) ) { + $user_data = array( + 'ID' => $cur_user->ID, + 'email' => $cur_user->data->user_email, + 'display_name' => $cur_user->data->display_name + ); + } + } + + $settings = [ + 'tainacan_api_url' => esc_url_raw( rest_url() ) . 'tainacan/v2', + 'wp_api_url' => esc_url_raw( rest_url() ) . 'wp/v2/', + 'wp_ajax_url' => admin_url( 'admin-ajax.php' ), + 'nonce' => is_user_logged_in() ? wp_create_nonce( 'wp_rest' ) : false, + 'classes' => array(), + 'i18n' => $tainacan_admin_i18n, + 'user_caps' => $user_caps, + 'user_prefs' => $prefs, + 'user_data' => $user_data, + 'base_url' => $TAINACAN_BASE_URL, + 'plugin_dir_url' => plugin_dir_url( __DIR__ ), + 'admin_url' => admin_url(), + 'theme_items_list_url' => esc_url_raw( get_site_url() ) . '/' . \Tainacan\Theme_Helper::get_instance()->get_items_list_slug(), + 'theme_collection_list_url' => get_post_type_archive_link( 'tainacan-collection' ), + 'theme_taxonomy_list_url' => get_post_type_archive_link( 'tainacan-taxonomy' ), + 'custom_header_support' => get_theme_support('custom-header'), + 'registered_view_modes' => \Tainacan\Theme_Helper::get_instance()->get_registered_view_modes(), + 'exposer_mapper_param' => \Tainacan\Mappers_Handler::MAPPER_PARAM, + 'exposer_type_param' => \Tainacan\Exposers_Handler::TYPE_PARAM, + 'repository_name' => get_bloginfo('name'), + 'api_max_items_per_page' => $TAINACAN_API_MAX_ITEMS_PER_PAGE, + 'wp_elasticpress' => \Tainacan\Elastic_Press::get_instance()->is_active(), + 'item_submission_captcha_site_key' => get_option("tnc_option_recaptch_site_key"), + 'tainacan_enable_core_metadata_on_advanced_search' => ( !defined('TAINACAN_DISABLE_CORE_METADATA_ON_ADVANCED_SEARCH') || false === TAINACAN_DISABLE_CORE_METADATA_ON_ADVANCED_SEARCH ), + 'tainacan_enable_relationship_metaquery' => ( defined('TAINACAN_ENABLE_RELATIONSHIP_METAQUERY') && true === TAINACAN_ENABLE_RELATIONSHIP_METAQUERY ) + ]; + + $maps = [ + 'collections' => $Tainacan_Collections->get_map(), + 'metadata' => $Tainacan_Metadata->get_map(), + 'metadata-sections' => $Tainacan_Metadata_Sections->get_map(), + 'filters' => $Tainacan_Filters->get_map(), + 'items' => $Tainacan_Items->get_map(), + 'taxonomies' => $Tainacan_Taxonomies->get_map(), + ]; + + $metadata_types = $Tainacan_Metadata->fetch_metadata_types(); + + foreach( $maps as $type => $map ){ + foreach ( $map as $metadatum => $details){ + $settings['i18n']['helpers_label'][$type][$metadatum] = [ 'title' => $details['title'], 'description' => $details['description'] ]; + } + } + foreach ( $metadata_types as $index => $metadata_type){ + $class = new $metadata_type; + $settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels(); + } + + $filter_types = $Tainacan_Filters->fetch_filter_types(); + + foreach ( $filter_types as $index => $filter_type){ + $class = new $filter_type; + $settings['i18n']['helpers_label'][$class->get_component()] = $class->get_form_labels(); + } + + $settings['form_hooks'] = Admin_Hooks::get_instance()->get_registered_hooks(); + + $wp_post_types = get_post_types(['show_ui' => true], 'objects'); + if (isset($wp_post_types['attachment'])) { + unset($wp_post_types['attachment']); + } + + $wp_post_types = array_map(function($i) { + return [ + 'slug' => $i->name, + 'label' => $i->label + ]; + }, $wp_post_types); + + $settings['wp_post_types'] = $wp_post_types; + + // Key-valued array with extra options to be passed to every request in the admin (goes the header) + $admin_request_options = []; + $admin_request_options = apply_filters('tainacan-admin-extra-request-options', $admin_request_options); + $settings['admin_request_options'] = $admin_request_options; + + return $settings; + + } + + function register_user_meta() { + $args = array( + //'sanitize_callback' => array(&$this, 'santize_user_tainacan_prefs'), + //'auth_callback' => 'authorize_my_meta_key', + 'type' => 'string', + 'description' => 'Tainacan admin user preferences', + 'single' => true, + 'show_in_rest' => true, + ); + register_meta( 'user', 'tainacan_prefs', $args ); + } + + public function the_admin_navigation_menu() { + global $submenu; + ?> + + page_init(); + add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) ); } - public function page_init() { + function add_admin_menu() { + + // Main Page, Dashboard + $dashboard_page_suffix = add_menu_page( + __( 'Tainacan', 'tainacan' ), + __( 'Tainacan', 'tainacan' ), + 'read', + 'tainacan_dashboard', + array( &$this, 'dashboard_page' ), + 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iNC40bW0iIGhlaWdodD0iNC4zbW0iIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDE3LjUxIDE3LjU1NCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+CjxtZXRhZGF0YT4KPHJkZjpSREY+CjxjYzpXb3JrIHJkZjphYm91dD0iIj4KPGRjOmZvcm1hdD5pbWFnZS9zdmcreG1sPC9kYzpmb3JtYXQ+CjxkYzp0eXBlIHJkZjpyZXNvdXJjZT0iaHR0cD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LjY3OC04LjYgMTcuMTA2IiBmaWxsPSIjZmZmIi8+CjwvZz4KPC9nPgo8L3N2Zz4K' + ); + add_action( 'load-' . $dashboard_page_suffix, array( &$this, 'load_dashboard_page' ) ); + + } + + function load_dashboard_page() { + add_action( 'admin_enqueue_scripts', array( &$this, 'add_dashboard_css' ), 90 ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_dashboard_js' ), 90 ); + } + + function add_dashboard_css() { + global $TAINACAN_BASE_URL; + + wp_admin_css( 'dashboard' ); + //wp_enqueue_style( 'tainacan-dashboard-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-dashboard.css', [], TAINACAN_VERSION ); + } + + function add_dashboard_js() { + global $TAINACAN_BASE_URL; + + wp_enqueue_script( 'dashboard' ); + } + + + public function dashboard_page() { + \Tainacan\Views::get_instance()->the_admin_navigation_menu(); + $this->admin_page(); } /** diff --git a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php index 7ffe1eb87..ffe22a019 100644 --- a/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php +++ b/src/views/gutenberg-blocks/class-tainacan-gutenberg-block.php @@ -135,7 +135,7 @@ function tainacan_blocks_register_block($block_slug, $options = []) { // Passes global variables to the blocks editor side $block_settings = tainacan_blocks_get_plugin_js_settings(); - $plugin_settings = \Tainacan\Admin::get_instance()->get_admin_js_localization_params(); + $plugin_settings = \Tainacan\Views::get_instance()->get_admin_js_localization_params(); wp_localize_script( $block_slug, 'tainacan_blocks', $block_settings); wp_localize_script( $block_slug, 'tainacan_plugin', $plugin_settings); @@ -245,7 +245,7 @@ function tainacan_blocks_add_common_theme_scripts() { wp_set_script_translations( 'tainacan-blocks-common-scripts', 'tainacan' ); $block_settings = tainacan_blocks_get_plugin_js_settings(); - $plugin_settings = \Tainacan\Admin::get_instance()->get_admin_js_localization_params(); + $plugin_settings = \Tainacan\Views::get_instance()->get_admin_js_localization_params(); wp_localize_script( 'tainacan-blocks-common-scripts', 'tainacan_blocks', $block_settings); wp_localize_script( 'tainacan-blocks-common-scripts', 'tainacan_plugin', $plugin_settings); diff --git a/src/views/item-submission/class-tainacan-item-submission.php b/src/views/item-submission/class-tainacan-item-submission.php index 1b8fd8215..9406ebcb4 100644 --- a/src/views/item-submission/class-tainacan-item-submission.php +++ b/src/views/item-submission/class-tainacan-item-submission.php @@ -4,13 +4,25 @@ namespace Tainacan; class Item_Submission { - public function __construct() - { - $this->page_init(); + private $other_links_slug = 'tainacan_other_links'; + + public function __construct() { + add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) ); + add_action( 'admin_init', array( &$this, 'settings_init' ) ); } - public function page_init() - { + public function add_admin_menu() { + add_submenu_page( + $this->other_links_slug, + __('Item Submission', 'tainacan'), + __('Item Submission', 'tainacan'), + 'manage_options', + 'tainacan_item_submission', + array( &$this, 'item_submission_page' ) + ); + } + + public function settings_init() { add_settings_section( 'tainacan_item_submission_recaptcha_id', // ID 'reCaptcha', // Title @@ -33,31 +45,44 @@ class Item_Submission { 'tainacan_item_submission', // Page 'tainacan_item_submission_recaptcha_id' // Section ); + + register_setting( + 'tainacan_item_submission_recaptcha', + 'tnc_option_recaptch_site_key', + 'sanitize_text_field' + ); + + register_setting( + 'tainacan_item_submission_recaptcha', + 'tnc_option_recaptch_secret_key', + 'sanitize_text_field' + ); } - public function print_section_info() - { + public function print_section_info() { print _e('Enter your site settings below:', 'tainacan'); } - public function tnc_option_recaptch_site_key() - { + public function tnc_option_recaptch_site_key() { printf( '', esc_attr( get_option('tnc_option_recaptch_site_key') ) ); } - public function tnc_option_recaptch_secret_key() - { + public function tnc_option_recaptch_secret_key() { printf( '', esc_attr( get_option('tnc_option_recaptch_secret_key') ) ); } - public function admin_page() - { + public function item_submission_page() { + \Tainacan\Views::get_instance()->the_admin_navigation_menu(); + $this->admin_page(); + } + + public function admin_page() { include('admin-page.php'); } diff --git a/src/views/mobile-app/class-tainacan-mobile-app.php b/src/views/mobile-app/class-tainacan-mobile-app.php index 8e971fc55..09be6594b 100644 --- a/src/views/mobile-app/class-tainacan-mobile-app.php +++ b/src/views/mobile-app/class-tainacan-mobile-app.php @@ -4,10 +4,37 @@ namespace Tainacan; class Mobile_App { - public function __construct(){} + public function __construct() { + add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) ); + } - public function admin_page() - { + public function add_admin_menu() { + $mobile_app_page_suffix = add_submenu_page( + 'tainacan-no-show-menu', // Mobile app page is not listed in the menu + __('Mobile App', 'tainacan'), + __('Mobile App', 'tainacan'), + 'manage_tainacan', + 'tainacan_mobile_app', + array( &$this, 'mobile_app_page' ) + ); + add_action( 'load-' . $mobile_app_page_suffix, array( &$this, 'load_mobile_app_page' ) ); + } + + function load_mobile_app_page() { + add_action( 'admin_enqueue_scripts', array( &$this, 'add_mobile_app_css' ), 90 ); + } + + function add_mobile_app_css() { + global $TAINACAN_BASE_URL; + + wp_enqueue_style( 'tainacan-mobile-app-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-mobile-app.css', [], TAINACAN_VERSION ); + } + + public function mobile_app_page() { + $this->admin_page(); + } + + public function admin_page() { include('admin-page.php'); } } \ No newline at end of file diff --git a/src/views/reports/class-tainacan-reports.php b/src/views/reports/class-tainacan-reports.php new file mode 100644 index 000000000..c726c6861 --- /dev/null +++ b/src/views/reports/class-tainacan-reports.php @@ -0,0 +1,60 @@ +other_links_slug, + __('Reports', 'tainacan'), + __('Reports', 'tainacan'), + 'manage_tainacan', + 'tainacan_reports', + array( &$this, 'reports_page' ) + ); + add_action( 'load-' . $reports_page_suffix, array( &$this, 'load_reports_page' ) ); + } + + function load_reports_page() { + add_action( 'admin_enqueue_scripts', array( &$this, 'add_reports_css' ), 90 ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_reports_js' ), 90 ); + } + + function add_reports_css() { + global $TAINACAN_BASE_URL; + wp_enqueue_style( 'tainacan-fonts', $TAINACAN_BASE_URL . '/assets/css/tainacanicons.css', [], TAINACAN_VERSION ); + wp_enqueue_style( 'tainacan-reports-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-reports.css', [], TAINACAN_VERSION ); + } + + function add_reports_js() { + + global $TAINACAN_BASE_URL; + + wp_enqueue_script( + 'tainacan-pages-common-scripts', + $TAINACAN_BASE_URL . '/assets/js/tainacan_pages_common_scripts.js', + ['underscore', 'wp-i18n'], + TAINACAN_VERSION + ); + wp_set_script_translations('tainacan-pages-common-scripts', 'tainacan'); + + $settings = \Tainacan\Views::get_instance()->get_admin_js_localization_params(); + wp_localize_script( 'tainacan-pages-common-scripts', 'tainacan_plugin', $settings ); + wp_enqueue_script('underscore'); + wp_enqueue_script('wp-i18n'); + + do_action('tainacan-enqueue-reports-scripts'); + } + + function reports_page() { + \Tainacan\Views::get_instance()->the_admin_navigation_menu(); + echo "
"; + } +} \ No newline at end of file diff --git a/src/views/roles/class-tainacan-roles.php b/src/views/roles/class-tainacan-roles.php new file mode 100644 index 000000000..b17f50f64 --- /dev/null +++ b/src/views/roles/class-tainacan-roles.php @@ -0,0 +1,60 @@ +other_links_slug, + __('User Roles', 'tainacan'), + __('User Roles', 'tainacan'), + 'tnc_rep_edit_users', + 'tainacan_roles', + array( &$this, 'roles_page' ) + ); + add_action( 'load-' . $roles_page_suffix, array( &$this, 'load_roles_page' ) ); + } + + function load_roles_page() { + add_action( 'admin_enqueue_scripts', array( &$this, 'add_roles_css' ), 90 ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_roles_js' ), 90 ); + } + + function add_roles_css() { + global $TAINACAN_BASE_URL; + + wp_enqueue_style( 'tainacan-roles-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-roles.css', [], TAINACAN_VERSION ); + } + + + function add_roles_js() { + global $TAINACAN_BASE_URL; + + wp_enqueue_script( + 'tainacan-pages-common-scripts', + $TAINACAN_BASE_URL . '/assets/js/tainacan_pages_common_scripts.js', + ['underscore', 'wp-i18n'], + TAINACAN_VERSION + ); + wp_set_script_translations('tainacan-pages-common-scripts', 'tainacan'); + + $settings = \Tainacan\Views::get_instance()->get_admin_js_localization_params(); + wp_localize_script( 'tainacan-pages-common-scripts', 'tainacan_plugin', $settings ); + wp_enqueue_script('underscore'); + wp_enqueue_script('wp-i18n'); + + do_action('tainacan-enqueue-roles-scripts'); + } + + function roles_page() { + \Tainacan\Views::get_instance()->the_admin_navigation_menu(); + echo "
"; + } +} \ No newline at end of file diff --git a/src/views/system-check/class-tainacan-system-check.php b/src/views/system-check/class-tainacan-system-check.php index 493146b54..3c4b369f0 100644 --- a/src/views/system-check/class-tainacan-system-check.php +++ b/src/views/system-check/class-tainacan-system-check.php @@ -4,6 +4,7 @@ namespace Tainacan; class System_Check { + private $other_links_slug = 'tainacan_other_links'; private $min_php_version = '7.0'; private $mysql_min_version_check; @@ -15,17 +16,30 @@ class System_Check { private $health_check_mysql_min_version = '5.0'; public function __construct() { - $this->init(); - } - - public function init() { $this->prepare_sql_data(); + add_action( 'admin_menu', array( &$this, 'add_admin_menu' ) ); } public function admin_page() { include('admin-page.php'); } + public function add_admin_menu() { + add_submenu_page( + $this->other_links_slug, + __('System check', 'tainacan'), + __('System check', 'tainacan'), + 'manage_options', + 'tainacan_systemcheck', + array( &$this, 'systemcheck_page' ) + ); + } + + public function systemcheck_page() { + \Tainacan\Views::get_instance()->the_admin_navigation_menu(); + $this->admin_page(); + } + public function test_php_version() { $testphpmin = version_compare( $this->min_php_version, PHP_VERSION, '<=' ); $testphprec = version_compare( '7.4', PHP_VERSION, '<=' );