From 5bf66662a9bdd62c5bccab15e607cd95cfb8fcab Mon Sep 17 00:00:00 2001
From: Charles Cabergs
Date: Mon, 27 Jul 2020 10:05:23 +0200
Subject: Removed wordpress and phpmyadmin, my server doesn't handle it well
and it brings shame on my familly
---
srcs/wordpress/wp-admin/includes/admin-filters.php | 150 -
srcs/wordpress/wp-admin/includes/admin.php | 99 -
srcs/wordpress/wp-admin/includes/ajax-actions.php | 5263 ------------------
srcs/wordpress/wp-admin/includes/bookmark.php | 327 --
.../includes/class-automatic-upgrader-skin.php | 117 -
.../includes/class-bulk-plugin-upgrader-skin.php | 78 -
.../includes/class-bulk-theme-upgrader-skin.php | 78 -
.../wp-admin/includes/class-bulk-upgrader-skin.php | 177 -
.../wp-admin/includes/class-core-upgrader.php | 411 --
.../wp-admin/includes/class-custom-background.php | 616 ---
.../includes/class-custom-image-header.php | 1515 ------
.../includes/class-file-upload-upgrader.php | 133 -
.../wordpress/wp-admin/includes/class-ftp-pure.php | 186 -
.../wp-admin/includes/class-ftp-sockets.php | 246 -
srcs/wordpress/wp-admin/includes/class-ftp.php | 912 ----
.../includes/class-language-pack-upgrader-skin.php | 95 -
.../includes/class-language-pack-upgrader.php | 473 --
srcs/wordpress/wp-admin/includes/class-pclzip.php | 5702 --------------------
.../includes/class-plugin-installer-skin.php | 141 -
.../includes/class-plugin-upgrader-skin.php | 89 -
.../wp-admin/includes/class-plugin-upgrader.php | 487 --
.../includes/class-theme-installer-skin.php | 150 -
.../includes/class-theme-upgrader-skin.php | 126 -
.../wp-admin/includes/class-theme-upgrader.php | 648 ---
.../includes/class-walker-category-checklist.php | 128 -
.../includes/class-walker-nav-menu-checklist.php | 122 -
.../includes/class-walker-nav-menu-edit.php | 298 -
.../includes/class-wp-ajax-upgrader-skin.php | 130 -
.../includes/class-wp-automatic-updater.php | 1016 ----
.../includes/class-wp-comments-list-table.php | 948 ----
.../includes/class-wp-community-events.php | 465 --
.../wp-admin/includes/class-wp-debug-data.php | 1342 -----
.../wp-admin/includes/class-wp-filesystem-base.php | 830 ---
.../includes/class-wp-filesystem-direct.php | 619 ---
.../includes/class-wp-filesystem-ftpext.php | 739 ---
.../includes/class-wp-filesystem-ftpsockets.php | 662 ---
.../wp-admin/includes/class-wp-filesystem-ssh2.php | 776 ---
.../wp-admin/includes/class-wp-importer.php | 334 --
.../includes/class-wp-internal-pointers.php | 172 -
.../includes/class-wp-links-list-table.php | 338 --
.../includes/class-wp-list-table-compat.php | 50 -
.../wp-admin/includes/class-wp-list-table.php | 1430 -----
.../includes/class-wp-media-list-table.php | 794 ---
.../includes/class-wp-ms-sites-list-table.php | 738 ---
.../includes/class-wp-ms-themes-list-table.php | 797 ---
.../includes/class-wp-ms-users-list-table.php | 522 --
.../class-wp-plugin-install-list-table.php | 776 ---
.../includes/class-wp-plugins-list-table.php | 1027 ----
.../includes/class-wp-post-comments-list-table.php | 78 -
.../includes/class-wp-posts-list-table.php | 1923 -------
...-wp-privacy-data-export-requests-list-table.php | 129 -
...wp-privacy-data-removal-requests-list-table.php | 137 -
.../includes/class-wp-privacy-policy-content.php | 725 ---
.../includes/class-wp-privacy-requests-table.php | 449 --
.../wp-admin/includes/class-wp-screen.php | 1315 -----
.../includes/class-wp-site-health-auto-updates.php | 478 --
.../wp-admin/includes/class-wp-site-health.php | 2170 --------
.../wp-admin/includes/class-wp-site-icon.php | 233 -
.../includes/class-wp-terms-list-table.php | 686 ---
.../includes/class-wp-theme-install-list-table.php | 560 --
.../includes/class-wp-themes-list-table.php | 361 --
.../wp-admin/includes/class-wp-upgrader-skin.php | 208 -
.../wp-admin/includes/class-wp-upgrader-skins.php | 44 -
.../wp-admin/includes/class-wp-upgrader.php | 947 ----
.../includes/class-wp-users-list-table.php | 642 ---
srcs/wordpress/wp-admin/includes/comment.php | 213 -
.../wp-admin/includes/continents-cities.php | 554 --
srcs/wordpress/wp-admin/includes/credits.php | 157 -
srcs/wordpress/wp-admin/includes/dashboard.php | 1815 -------
srcs/wordpress/wp-admin/includes/deprecated.php | 1565 ------
.../wp-admin/includes/edit-tag-messages.php | 59 -
srcs/wordpress/wp-admin/includes/export.php | 670 ---
srcs/wordpress/wp-admin/includes/file.php | 2236 --------
srcs/wordpress/wp-admin/includes/image-edit.php | 982 ----
srcs/wordpress/wp-admin/includes/image.php | 1049 ----
srcs/wordpress/wp-admin/includes/import.php | 231 -
srcs/wordpress/wp-admin/includes/list-table.php | 91 -
srcs/wordpress/wp-admin/includes/media.php | 3717 -------------
srcs/wordpress/wp-admin/includes/menu.php | 353 --
srcs/wordpress/wp-admin/includes/meta-boxes.php | 1580 ------
srcs/wordpress/wp-admin/includes/misc.php | 1445 -----
.../wp-admin/includes/ms-admin-filters.php | 44 -
srcs/wordpress/wp-admin/includes/ms-deprecated.php | 110 -
srcs/wordpress/wp-admin/includes/ms.php | 1154 ----
srcs/wordpress/wp-admin/includes/nav-menu.php | 1278 -----
srcs/wordpress/wp-admin/includes/network.php | 668 ---
srcs/wordpress/wp-admin/includes/noop.php | 105 -
srcs/wordpress/wp-admin/includes/options.php | 133 -
.../wordpress/wp-admin/includes/plugin-install.php | 888 ---
srcs/wordpress/wp-admin/includes/plugin.php | 2405 ---------
srcs/wordpress/wp-admin/includes/post.php | 2425 ---------
srcs/wordpress/wp-admin/includes/privacy-tools.php | 817 ---
srcs/wordpress/wp-admin/includes/revision.php | 464 --
srcs/wordpress/wp-admin/includes/schema.php | 1335 -----
srcs/wordpress/wp-admin/includes/screen.php | 242 -
srcs/wordpress/wp-admin/includes/taxonomy.php | 314 --
srcs/wordpress/wp-admin/includes/template.php | 2580 ---------
srcs/wordpress/wp-admin/includes/theme-install.php | 252 -
srcs/wordpress/wp-admin/includes/theme.php | 936 ----
.../wp-admin/includes/translation-install.php | 275 -
srcs/wordpress/wp-admin/includes/update-core.php | 1509 ------
srcs/wordpress/wp-admin/includes/update.php | 902 ----
srcs/wordpress/wp-admin/includes/upgrade.php | 3379 ------------
srcs/wordpress/wp-admin/includes/user.php | 591 --
srcs/wordpress/wp-admin/includes/widgets.php | 330 --
105 files changed, 84210 deletions(-)
delete mode 100644 srcs/wordpress/wp-admin/includes/admin-filters.php
delete mode 100644 srcs/wordpress/wp-admin/includes/admin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/ajax-actions.php
delete mode 100644 srcs/wordpress/wp-admin/includes/bookmark.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-automatic-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-bulk-plugin-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-bulk-theme-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-bulk-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-core-upgrader.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-custom-background.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-custom-image-header.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-file-upload-upgrader.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-ftp-pure.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-ftp-sockets.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-ftp.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-language-pack-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-language-pack-upgrader.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-pclzip.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-plugin-installer-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-plugin-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-plugin-upgrader.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-theme-installer-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-theme-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-theme-upgrader.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-walker-category-checklist.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-walker-nav-menu-checklist.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-walker-nav-menu-edit.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-ajax-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-automatic-updater.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-comments-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-community-events.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-debug-data.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-filesystem-base.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-filesystem-direct.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-importer.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-internal-pointers.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-links-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-list-table-compat.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-media-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-ms-sites-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-ms-themes-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-ms-users-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-plugin-install-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-plugins-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-post-comments-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-posts-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-privacy-data-export-requests-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-privacy-policy-content.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-privacy-requests-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-screen.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-site-health-auto-updates.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-site-health.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-site-icon.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-terms-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-theme-install-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-themes-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-upgrader-skin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-upgrader-skins.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-upgrader.php
delete mode 100644 srcs/wordpress/wp-admin/includes/class-wp-users-list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/comment.php
delete mode 100644 srcs/wordpress/wp-admin/includes/continents-cities.php
delete mode 100644 srcs/wordpress/wp-admin/includes/credits.php
delete mode 100644 srcs/wordpress/wp-admin/includes/dashboard.php
delete mode 100644 srcs/wordpress/wp-admin/includes/deprecated.php
delete mode 100644 srcs/wordpress/wp-admin/includes/edit-tag-messages.php
delete mode 100644 srcs/wordpress/wp-admin/includes/export.php
delete mode 100644 srcs/wordpress/wp-admin/includes/file.php
delete mode 100644 srcs/wordpress/wp-admin/includes/image-edit.php
delete mode 100644 srcs/wordpress/wp-admin/includes/image.php
delete mode 100644 srcs/wordpress/wp-admin/includes/import.php
delete mode 100644 srcs/wordpress/wp-admin/includes/list-table.php
delete mode 100644 srcs/wordpress/wp-admin/includes/media.php
delete mode 100644 srcs/wordpress/wp-admin/includes/menu.php
delete mode 100644 srcs/wordpress/wp-admin/includes/meta-boxes.php
delete mode 100644 srcs/wordpress/wp-admin/includes/misc.php
delete mode 100644 srcs/wordpress/wp-admin/includes/ms-admin-filters.php
delete mode 100644 srcs/wordpress/wp-admin/includes/ms-deprecated.php
delete mode 100644 srcs/wordpress/wp-admin/includes/ms.php
delete mode 100644 srcs/wordpress/wp-admin/includes/nav-menu.php
delete mode 100644 srcs/wordpress/wp-admin/includes/network.php
delete mode 100644 srcs/wordpress/wp-admin/includes/noop.php
delete mode 100644 srcs/wordpress/wp-admin/includes/options.php
delete mode 100644 srcs/wordpress/wp-admin/includes/plugin-install.php
delete mode 100644 srcs/wordpress/wp-admin/includes/plugin.php
delete mode 100644 srcs/wordpress/wp-admin/includes/post.php
delete mode 100644 srcs/wordpress/wp-admin/includes/privacy-tools.php
delete mode 100644 srcs/wordpress/wp-admin/includes/revision.php
delete mode 100644 srcs/wordpress/wp-admin/includes/schema.php
delete mode 100644 srcs/wordpress/wp-admin/includes/screen.php
delete mode 100644 srcs/wordpress/wp-admin/includes/taxonomy.php
delete mode 100644 srcs/wordpress/wp-admin/includes/template.php
delete mode 100644 srcs/wordpress/wp-admin/includes/theme-install.php
delete mode 100644 srcs/wordpress/wp-admin/includes/theme.php
delete mode 100644 srcs/wordpress/wp-admin/includes/translation-install.php
delete mode 100644 srcs/wordpress/wp-admin/includes/update-core.php
delete mode 100644 srcs/wordpress/wp-admin/includes/update.php
delete mode 100644 srcs/wordpress/wp-admin/includes/upgrade.php
delete mode 100644 srcs/wordpress/wp-admin/includes/user.php
delete mode 100644 srcs/wordpress/wp-admin/includes/widgets.php
(limited to 'srcs/wordpress/wp-admin/includes')
diff --git a/srcs/wordpress/wp-admin/includes/admin-filters.php b/srcs/wordpress/wp-admin/includes/admin-filters.php
deleted file mode 100644
index c080fd0..0000000
--- a/srcs/wordpress/wp-admin/includes/admin-filters.php
+++ /dev/null
@@ -1,150 +0,0 @@
-id and the JS global 'pagenow'.
- if ( ! empty( $_POST['screen_id'] ) ) {
- $screen_id = sanitize_key( $_POST['screen_id'] );
- } else {
- $screen_id = 'front';
- }
-
- if ( ! empty( $_POST['data'] ) ) {
- $data = wp_unslash( (array) $_POST['data'] );
-
- /**
- * Filters Heartbeat Ajax response in no-privilege environments.
- *
- * @since 3.6.0
- *
- * @param array $response The no-priv Heartbeat response.
- * @param array $data The $_POST data sent.
- * @param string $screen_id The screen id.
- */
- $response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id );
- }
-
- /**
- * Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
- *
- * @since 3.6.0
- *
- * @param array $response The no-priv Heartbeat response.
- * @param string $screen_id The screen id.
- */
- $response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id );
-
- /**
- * Fires when Heartbeat ticks in no-privilege environments.
- *
- * Allows the transport to be easily replaced with long-polling.
- *
- * @since 3.6.0
- *
- * @param array $response The no-priv Heartbeat response.
- * @param string $screen_id The screen id.
- */
- do_action( 'heartbeat_nopriv_tick', $response, $screen_id );
-
- // Send the current time according to the server.
- $response['server_time'] = time();
-
- wp_send_json( $response );
-}
-
-//
-// GET-based Ajax handlers.
-//
-
-/**
- * Ajax handler for fetching a list table.
- *
- * @since 3.1.0
- */
-function wp_ajax_fetch_list() {
- $list_class = $_GET['list_args']['class'];
- check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
-
- $wp_list_table = _get_list_table( $list_class, array( 'screen' => $_GET['list_args']['screen']['id'] ) );
- if ( ! $wp_list_table ) {
- wp_die( 0 );
- }
-
- if ( ! $wp_list_table->ajax_user_can() ) {
- wp_die( -1 );
- }
-
- $wp_list_table->ajax_response();
-
- wp_die( 0 );
-}
-
-/**
- * Ajax handler for tag search.
- *
- * @since 3.1.0
- */
-function wp_ajax_ajax_tag_search() {
- if ( ! isset( $_GET['tax'] ) ) {
- wp_die( 0 );
- }
-
- $taxonomy = sanitize_key( $_GET['tax'] );
- $tax = get_taxonomy( $taxonomy );
-
- if ( ! $tax ) {
- wp_die( 0 );
- }
-
- if ( ! current_user_can( $tax->cap->assign_terms ) ) {
- wp_die( -1 );
- }
-
- $s = wp_unslash( $_GET['q'] );
-
- $comma = _x( ',', 'tag delimiter' );
- if ( ',' !== $comma ) {
- $s = str_replace( $comma, ',', $s );
- }
-
- if ( false !== strpos( $s, ',' ) ) {
- $s = explode( ',', $s );
- $s = $s[ count( $s ) - 1 ];
- }
-
- $s = trim( $s );
-
- /**
- * Filters the minimum number of characters required to fire a tag search via Ajax.
- *
- * @since 4.0.0
- *
- * @param int $characters The minimum number of characters required. Default 2.
- * @param WP_Taxonomy $tax The taxonomy object.
- * @param string $s The search term.
- */
- $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
-
- /*
- * Require $term_search_min_chars chars for matching (default: 2)
- * ensure it's a non-negative, non-zero integer.
- */
- if ( ( $term_search_min_chars == 0 ) || ( strlen( $s ) < $term_search_min_chars ) ) {
- wp_die();
- }
-
- $results = get_terms(
- array(
- 'taxonomy' => $taxonomy,
- 'name__like' => $s,
- 'fields' => 'names',
- 'hide_empty' => false,
- )
- );
-
- echo join( "\n", $results );
- wp_die();
-}
-
-/**
- * Ajax handler for compression testing.
- *
- * @since 3.1.0
- */
-function wp_ajax_wp_compression_test() {
- if ( ! current_user_can( 'manage_options' ) ) {
- wp_die( -1 );
- }
-
- if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' == ini_get( 'output_handler' ) ) {
- update_site_option( 'can_compress_scripts', 0 );
- wp_die( 0 );
- }
-
- if ( isset( $_GET['test'] ) ) {
- header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
- header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
- header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
- header( 'Content-Type: application/javascript; charset=UTF-8' );
- $force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP );
- $test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
-
- if ( 1 == $_GET['test'] ) {
- echo $test_str;
- wp_die();
- } elseif ( 2 == $_GET['test'] ) {
- if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
- wp_die( -1 );
- }
-
- if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) {
- header( 'Content-Encoding: deflate' );
- $out = gzdeflate( $test_str, 1 );
- } elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) {
- header( 'Content-Encoding: gzip' );
- $out = gzencode( $test_str, 1 );
- } else {
- wp_die( -1 );
- }
-
- echo $out;
- wp_die();
- } elseif ( 'no' == $_GET['test'] ) {
- check_ajax_referer( 'update_can_compress_scripts' );
- update_site_option( 'can_compress_scripts', 0 );
- } elseif ( 'yes' == $_GET['test'] ) {
- check_ajax_referer( 'update_can_compress_scripts' );
- update_site_option( 'can_compress_scripts', 1 );
- }
- }
-
- wp_die( 0 );
-}
-
-/**
- * Ajax handler for image editor previews.
- *
- * @since 3.1.0
- */
-function wp_ajax_imgedit_preview() {
- $post_id = intval( $_GET['postid'] );
- if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
- wp_die( -1 );
- }
-
- check_ajax_referer( "image_editor-$post_id" );
-
- include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
-
- if ( ! stream_preview_image( $post_id ) ) {
- wp_die( -1 );
- }
-
- wp_die();
-}
-
-/**
- * Ajax handler for oEmbed caching.
- *
- * @since 3.1.0
- *
- * @global WP_Embed $wp_embed
- */
-function wp_ajax_oembed_cache() {
- $GLOBALS['wp_embed']->cache_oembed( $_GET['post'] );
- wp_die( 0 );
-}
-
-/**
- * Ajax handler for user autocomplete.
- *
- * @since 3.4.0
- */
-function wp_ajax_autocomplete_user() {
- if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) {
- wp_die( -1 );
- }
-
- /** This filter is documented in wp-admin/user-new.php */
- if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) {
- wp_die( -1 );
- }
-
- $return = array();
-
- // Check the type of request
- // Current allowed values are `add` and `search`
- if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) {
- $type = $_REQUEST['autocomplete_type'];
- } else {
- $type = 'add';
- }
-
- // Check the desired field for value
- // Current allowed values are `user_email` and `user_login`
- if ( isset( $_REQUEST['autocomplete_field'] ) && 'user_email' === $_REQUEST['autocomplete_field'] ) {
- $field = $_REQUEST['autocomplete_field'];
- } else {
- $field = 'user_login';
- }
-
- // Exclude current users of this blog
- if ( isset( $_REQUEST['site_id'] ) ) {
- $id = absint( $_REQUEST['site_id'] );
- } else {
- $id = get_current_blog_id();
- }
-
- $include_blog_users = ( $type == 'search' ? get_users(
- array(
- 'blog_id' => $id,
- 'fields' => 'ID',
- )
- ) : array() );
-
- $exclude_blog_users = ( $type == 'add' ? get_users(
- array(
- 'blog_id' => $id,
- 'fields' => 'ID',
- )
- ) : array() );
-
- $users = get_users(
- array(
- 'blog_id' => false,
- 'search' => '*' . $_REQUEST['term'] . '*',
- 'include' => $include_blog_users,
- 'exclude' => $exclude_blog_users,
- 'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
- )
- );
-
- foreach ( $users as $user ) {
- $return[] = array(
- /* translators: 1: User login, 2: User email address. */
- 'label' => sprintf( _x( '%1$s (%2$s)', 'user autocomplete result' ), $user->user_login, $user->user_email ),
- 'value' => $user->$field,
- );
- }
-
- wp_die( wp_json_encode( $return ) );
-}
-
-/**
- * Handles AJAX requests for community events
- *
- * @since 4.8.0
- */
-function wp_ajax_get_community_events() {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-community-events.php' );
-
- check_ajax_referer( 'community_events' );
-
- $search = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : '';
- $timezone = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : '';
- $user_id = get_current_user_id();
- $saved_location = get_user_option( 'community-events-location', $user_id );
- $events_client = new WP_Community_Events( $user_id, $saved_location );
- $events = $events_client->get_events( $search, $timezone );
- $ip_changed = false;
-
- if ( is_wp_error( $events ) ) {
- wp_send_json_error(
- array(
- 'error' => $events->get_error_message(),
- )
- );
- } else {
- if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) {
- $ip_changed = true;
- } elseif ( isset( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) && $saved_location['ip'] !== $events['location']['ip'] ) {
- $ip_changed = true;
- }
-
- /*
- * The location should only be updated when it changes. The API doesn't always return
- * a full location; sometimes it's missing the description or country. The location
- * that was saved during the initial request is known to be good and complete, though.
- * It should be left intact until the user explicitly changes it (either by manually
- * searching for a new location, or by changing their IP address).
- *
- * If the location was updated with an incomplete response from the API, then it could
- * break assumptions that the UI makes (e.g., that there will always be a description
- * that corresponds to a latitude/longitude location).
- *
- * The location is stored network-wide, so that the user doesn't have to set it on each site.
- */
- if ( $ip_changed || $search ) {
- update_user_option( $user_id, 'community-events-location', $events['location'], true );
- }
-
- wp_send_json_success( $events );
- }
-}
-
-/**
- * Ajax handler for dashboard widgets.
- *
- * @since 3.4.0
- */
-function wp_ajax_dashboard_widgets() {
- require_once ABSPATH . 'wp-admin/includes/dashboard.php';
-
- $pagenow = $_GET['pagenow'];
- if ( $pagenow === 'dashboard-user' || $pagenow === 'dashboard-network' || $pagenow === 'dashboard' ) {
- set_current_screen( $pagenow );
- }
-
- switch ( $_GET['widget'] ) {
- case 'dashboard_primary':
- wp_dashboard_primary();
- break;
- }
- wp_die();
-}
-
-/**
- * Ajax handler for Customizer preview logged-in status.
- *
- * @since 3.4.0
- */
-function wp_ajax_logged_in() {
- wp_die( 1 );
-}
-
-//
-// Ajax helpers.
-//
-
-/**
- * Sends back current comment total and new page links if they need to be updated.
- *
- * Contrary to normal success Ajax response ("1"), die with time() on success.
- *
- * @access private
- * @since 2.7.0
- *
- * @param int $comment_id
- * @param int $delta
- */
-function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
- $total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0;
- $per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0;
- $page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0;
- $url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : '';
-
- // JS didn't send us everything we need to know. Just die with success message
- if ( ! $total || ! $per_page || ! $page || ! $url ) {
- $time = time();
- $comment = get_comment( $comment_id );
- $comment_status = '';
- $comment_link = '';
-
- if ( $comment ) {
- $comment_status = $comment->comment_approved;
- }
-
- if ( 1 === (int) $comment_status ) {
- $comment_link = get_comment_link( $comment );
- }
-
- $counts = wp_count_comments();
-
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'comment',
- // Here for completeness - not used.
- 'id' => $comment_id,
- 'supplemental' => array(
- 'status' => $comment_status,
- 'postId' => $comment ? $comment->comment_post_ID : '',
- 'time' => $time,
- 'in_moderation' => $counts->moderated,
- 'i18n_comments_text' => sprintf(
- /* translators: %s: Number of comments. */
- _n( '%s Comment', '%s Comments', $counts->approved ),
- number_format_i18n( $counts->approved )
- ),
- 'i18n_moderation_text' => sprintf(
- /* translators: %s: Number of comments. */
- _n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
- number_format_i18n( $counts->moderated )
- ),
- 'comment_link' => $comment_link,
- ),
- )
- );
- $x->send();
- }
-
- $total += $delta;
- if ( $total < 0 ) {
- $total = 0;
- }
-
- // Only do the expensive stuff on a page-break, and about 1 other time per page
- if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
- $post_id = 0;
- // What type of comment count are we looking for?
- $status = 'all';
- $parsed = parse_url( $url );
-
- if ( isset( $parsed['query'] ) ) {
- parse_str( $parsed['query'], $query_vars );
-
- if ( ! empty( $query_vars['comment_status'] ) ) {
- $status = $query_vars['comment_status'];
- }
-
- if ( ! empty( $query_vars['p'] ) ) {
- $post_id = (int) $query_vars['p'];
- }
-
- if ( ! empty( $query_vars['comment_type'] ) ) {
- $type = $query_vars['comment_type'];
- }
- }
-
- if ( empty( $type ) ) {
- // Only use the comment count if not filtering by a comment_type.
- $comment_count = wp_count_comments( $post_id );
-
- // We're looking for a known type of comment count.
- if ( isset( $comment_count->$status ) ) {
- $total = $comment_count->$status;
- }
- }
- // Else use the decremented value from above.
- }
-
- // The time since the last comment count.
- $time = time();
- $comment = get_comment( $comment_id );
- $counts = wp_count_comments();
-
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'comment',
- 'id' => $comment_id,
- 'supplemental' => array(
- 'status' => $comment ? $comment->comment_approved : '',
- 'postId' => $comment ? $comment->comment_post_ID : '',
- /* translators: %s: Number of comments. */
- 'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
- 'total_pages' => ceil( $total / $per_page ),
- 'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
- 'total' => $total,
- 'time' => $time,
- 'in_moderation' => $counts->moderated,
- 'i18n_moderation_text' => sprintf(
- /* translators: %s: Number of comments. */
- _n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
- number_format_i18n( $counts->moderated )
- ),
- ),
- )
- );
- $x->send();
-}
-
-//
-// POST-based Ajax handlers.
-//
-
-/**
- * Ajax handler for adding a hierarchical term.
- *
- * @access private
- * @since 3.1.0
- */
-function _wp_ajax_add_hierarchical_term() {
- $action = $_POST['action'];
- $taxonomy = get_taxonomy( substr( $action, 4 ) );
- check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
-
- if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
- wp_die( -1 );
- }
-
- $names = explode( ',', $_POST[ 'new' . $taxonomy->name ] );
- $parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0;
-
- if ( 0 > $parent ) {
- $parent = 0;
- }
-
- if ( $taxonomy->name == 'category' ) {
- $post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array();
- } else {
- $post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array();
- }
-
- $checked_categories = array_map( 'absint', (array) $post_category );
- $popular_ids = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false );
-
- foreach ( $names as $cat_name ) {
- $cat_name = trim( $cat_name );
- $category_nicename = sanitize_title( $cat_name );
-
- if ( '' === $category_nicename ) {
- continue;
- }
-
- $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
-
- if ( ! $cat_id || is_wp_error( $cat_id ) ) {
- continue;
- } else {
- $cat_id = $cat_id['term_id'];
- }
-
- $checked_categories[] = $cat_id;
-
- if ( $parent ) { // Do these all at once in a second
- continue;
- }
-
- ob_start();
-
- wp_terms_checklist(
- 0,
- array(
- 'taxonomy' => $taxonomy->name,
- 'descendants_and_self' => $cat_id,
- 'selected_cats' => $checked_categories,
- 'popular_cats' => $popular_ids,
- )
- );
-
- $data = ob_get_clean();
-
- $add = array(
- 'what' => $taxonomy->name,
- 'id' => $cat_id,
- 'data' => str_replace( array( "\n", "\t" ), '', $data ),
- 'position' => -1,
- );
- }
-
- if ( $parent ) { // Foncy - replace the parent and all its children
- $parent = get_term( $parent, $taxonomy->name );
- $term_id = $parent->term_id;
-
- while ( $parent->parent ) { // get the top parent
- $parent = get_term( $parent->parent, $taxonomy->name );
- if ( is_wp_error( $parent ) ) {
- break;
- }
- $term_id = $parent->term_id;
- }
-
- ob_start();
-
- wp_terms_checklist(
- 0,
- array(
- 'taxonomy' => $taxonomy->name,
- 'descendants_and_self' => $term_id,
- 'selected_cats' => $checked_categories,
- 'popular_cats' => $popular_ids,
- )
- );
-
- $data = ob_get_clean();
-
- $add = array(
- 'what' => $taxonomy->name,
- 'id' => $term_id,
- 'data' => str_replace( array( "\n", "\t" ), '', $data ),
- 'position' => -1,
- );
- }
-
- ob_start();
-
- wp_dropdown_categories(
- array(
- 'taxonomy' => $taxonomy->name,
- 'hide_empty' => 0,
- 'name' => 'new' . $taxonomy->name . '_parent',
- 'orderby' => 'name',
- 'hierarchical' => 1,
- 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —',
- )
- );
-
- $sup = ob_get_clean();
-
- $add['supplemental'] = array( 'newcat_parent' => $sup );
-
- $x = new WP_Ajax_Response( $add );
- $x->send();
-}
-
-/**
- * Ajax handler for deleting a comment.
- *
- * @since 3.1.0
- */
-function wp_ajax_delete_comment() {
- $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
-
- $comment = get_comment( $id );
-
- if ( ! $comment ) {
- wp_die( time() );
- }
-
- if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
- wp_die( -1 );
- }
-
- check_ajax_referer( "delete-comment_$id" );
- $status = wp_get_comment_status( $comment );
- $delta = -1;
-
- if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) {
- if ( 'trash' == $status ) {
- wp_die( time() );
- }
-
- $r = wp_trash_comment( $comment );
- } elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) {
- if ( 'trash' != $status ) {
- wp_die( time() );
- }
-
- $r = wp_untrash_comment( $comment );
-
- if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'trash' ) { // undo trash, not in trash
- $delta = 1;
- }
- } elseif ( isset( $_POST['spam'] ) && 1 == $_POST['spam'] ) {
- if ( 'spam' == $status ) {
- wp_die( time() );
- }
-
- $r = wp_spam_comment( $comment );
- } elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) {
- if ( 'spam' != $status ) {
- wp_die( time() );
- }
-
- $r = wp_unspam_comment( $comment );
-
- if ( ! isset( $_POST['comment_status'] ) || $_POST['comment_status'] != 'spam' ) { // undo spam, not in spam
- $delta = 1;
- }
- } elseif ( isset( $_POST['delete'] ) && 1 == $_POST['delete'] ) {
- $r = wp_delete_comment( $comment );
- } else {
- wp_die( -1 );
- }
-
- if ( $r ) { // Decide if we need to send back '1' or a more complicated response including page links and comment counts
- _wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
- }
-
- wp_die( 0 );
-}
-
-/**
- * Ajax handler for deleting a tag.
- *
- * @since 3.1.0
- */
-function wp_ajax_delete_tag() {
- $tag_id = (int) $_POST['tag_ID'];
- check_ajax_referer( "delete-tag_$tag_id" );
-
- if ( ! current_user_can( 'delete_term', $tag_id ) ) {
- wp_die( -1 );
- }
-
- $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
- $tag = get_term( $tag_id, $taxonomy );
-
- if ( ! $tag || is_wp_error( $tag ) ) {
- wp_die( 1 );
- }
-
- if ( wp_delete_term( $tag_id, $taxonomy ) ) {
- wp_die( 1 );
- } else {
- wp_die( 0 );
- }
-}
-
-/**
- * Ajax handler for deleting a link.
- *
- * @since 3.1.0
- */
-function wp_ajax_delete_link() {
- $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
-
- check_ajax_referer( "delete-bookmark_$id" );
-
- if ( ! current_user_can( 'manage_links' ) ) {
- wp_die( -1 );
- }
-
- $link = get_bookmark( $id );
- if ( ! $link || is_wp_error( $link ) ) {
- wp_die( 1 );
- }
-
- if ( wp_delete_link( $id ) ) {
- wp_die( 1 );
- } else {
- wp_die( 0 );
- }
-}
-
-/**
- * Ajax handler for deleting meta.
- *
- * @since 3.1.0
- */
-function wp_ajax_delete_meta() {
- $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
-
- check_ajax_referer( "delete-meta_$id" );
- $meta = get_metadata_by_mid( 'post', $id );
-
- if ( ! $meta ) {
- wp_die( 1 );
- }
-
- if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) {
- wp_die( -1 );
- }
-
- if ( delete_meta( $meta->meta_id ) ) {
- wp_die( 1 );
- }
-
- wp_die( 0 );
-}
-
-/**
- * Ajax handler for deleting a post.
- *
- * @since 3.1.0
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_delete_post( $action ) {
- if ( empty( $action ) ) {
- $action = 'delete-post';
- }
-
- $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
- check_ajax_referer( "{$action}_$id" );
-
- if ( ! current_user_can( 'delete_post', $id ) ) {
- wp_die( -1 );
- }
-
- if ( ! get_post( $id ) ) {
- wp_die( 1 );
- }
-
- if ( wp_delete_post( $id ) ) {
- wp_die( 1 );
- } else {
- wp_die( 0 );
- }
-}
-
-/**
- * Ajax handler for sending a post to the trash.
- *
- * @since 3.1.0
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_trash_post( $action ) {
- if ( empty( $action ) ) {
- $action = 'trash-post';
- }
-
- $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
- check_ajax_referer( "{$action}_$id" );
-
- if ( ! current_user_can( 'delete_post', $id ) ) {
- wp_die( -1 );
- }
-
- if ( ! get_post( $id ) ) {
- wp_die( 1 );
- }
-
- if ( 'trash-post' == $action ) {
- $done = wp_trash_post( $id );
- } else {
- $done = wp_untrash_post( $id );
- }
-
- if ( $done ) {
- wp_die( 1 );
- }
-
- wp_die( 0 );
-}
-
-/**
- * Ajax handler to restore a post from the trash.
- *
- * @since 3.1.0
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_untrash_post( $action ) {
- if ( empty( $action ) ) {
- $action = 'untrash-post';
- }
-
- wp_ajax_trash_post( $action );
-}
-
-/**
- * Ajax handler to delete a page.
- *
- * @since 3.1.0
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_delete_page( $action ) {
- if ( empty( $action ) ) {
- $action = 'delete-page';
- }
-
- $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
- check_ajax_referer( "{$action}_$id" );
-
- if ( ! current_user_can( 'delete_page', $id ) ) {
- wp_die( -1 );
- }
-
- if ( ! get_post( $id ) ) {
- wp_die( 1 );
- }
-
- if ( wp_delete_post( $id ) ) {
- wp_die( 1 );
- } else {
- wp_die( 0 );
- }
-}
-
-/**
- * Ajax handler to dim a comment.
- *
- * @since 3.1.0
- */
-function wp_ajax_dim_comment() {
- $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
- $comment = get_comment( $id );
-
- if ( ! $comment ) {
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'comment',
- 'id' => new WP_Error(
- 'invalid_comment',
- /* translators: %d: Comment ID. */
- sprintf( __( 'Comment %d does not exist' ), $id )
- ),
- )
- );
- $x->send();
- }
-
- if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) {
- wp_die( -1 );
- }
-
- $current = wp_get_comment_status( $comment );
-
- if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) {
- wp_die( time() );
- }
-
- check_ajax_referer( "approve-comment_$id" );
-
- if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
- $result = wp_set_comment_status( $comment, 'approve', true );
- } else {
- $result = wp_set_comment_status( $comment, 'hold', true );
- }
-
- if ( is_wp_error( $result ) ) {
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'comment',
- 'id' => $result,
- )
- );
- $x->send();
- }
-
- // Decide if we need to send back '1' or a more complicated response including page links and comment counts
- _wp_ajax_delete_comment_response( $comment->comment_ID );
- wp_die( 0 );
-}
-
-/**
- * Ajax handler for adding a link category.
- *
- * @since 3.1.0
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_add_link_category( $action ) {
- if ( empty( $action ) ) {
- $action = 'add-link-category';
- }
-
- check_ajax_referer( $action );
- $tax = get_taxonomy( 'link_category' );
-
- if ( ! current_user_can( $tax->cap->manage_terms ) ) {
- wp_die( -1 );
- }
-
- $names = explode( ',', wp_unslash( $_POST['newcat'] ) );
- $x = new WP_Ajax_Response();
-
- foreach ( $names as $cat_name ) {
- $cat_name = trim( $cat_name );
- $slug = sanitize_title( $cat_name );
-
- if ( '' === $slug ) {
- continue;
- }
-
- $cat_id = wp_insert_term( $cat_name, 'link_category' );
-
- if ( ! $cat_id || is_wp_error( $cat_id ) ) {
- continue;
- } else {
- $cat_id = $cat_id['term_id'];
- }
-
- $cat_name = esc_html( $cat_name );
-
- $x->add(
- array(
- 'what' => 'link-category',
- 'id' => $cat_id,
- 'data' => " $cat_name ",
- 'position' => -1,
- )
- );
- }
- $x->send();
-}
-
-/**
- * Ajax handler to add a tag.
- *
- * @since 3.1.0
- */
-function wp_ajax_add_tag() {
- check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
- $taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
- $tax = get_taxonomy( $taxonomy );
-
- if ( ! current_user_can( $tax->cap->edit_terms ) ) {
- wp_die( -1 );
- }
-
- $x = new WP_Ajax_Response();
-
- $tag = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
-
- if ( $tag && ! is_wp_error( $tag ) ) {
- $tag = get_term( $tag['term_id'], $taxonomy );
- }
-
- if ( ! $tag || is_wp_error( $tag ) ) {
- $message = __( 'An error has occurred. Please reload the page and try again.' );
-
- if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
- $message = $tag->get_error_message();
- }
-
- $x->add(
- array(
- 'what' => 'taxonomy',
- 'data' => new WP_Error( 'error', $message ),
- )
- );
- $x->send();
- }
-
- $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
-
- $level = 0;
- $noparents = '';
-
- if ( is_taxonomy_hierarchical( $taxonomy ) ) {
- $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
- ob_start();
- $wp_list_table->single_row( $tag, $level );
- $noparents = ob_get_clean();
- }
-
- ob_start();
- $wp_list_table->single_row( $tag );
- $parents = ob_get_clean();
-
- $x->add(
- array(
- 'what' => 'taxonomy',
- 'supplemental' => compact( 'parents', 'noparents' ),
- )
- );
-
- $x->add(
- array(
- 'what' => 'term',
- 'position' => $level,
- 'supplemental' => (array) $tag,
- )
- );
-
- $x->send();
-}
-
-/**
- * Ajax handler for getting a tagcloud.
- *
- * @since 3.1.0
- */
-function wp_ajax_get_tagcloud() {
- if ( ! isset( $_POST['tax'] ) ) {
- wp_die( 0 );
- }
-
- $taxonomy = sanitize_key( $_POST['tax'] );
- $tax = get_taxonomy( $taxonomy );
-
- if ( ! $tax ) {
- wp_die( 0 );
- }
-
- if ( ! current_user_can( $tax->cap->assign_terms ) ) {
- wp_die( -1 );
- }
-
- $tags = get_terms(
- array(
- 'taxonomy' => $taxonomy,
- 'number' => 45,
- 'orderby' => 'count',
- 'order' => 'DESC',
- )
- );
-
- if ( empty( $tags ) ) {
- wp_die( $tax->labels->not_found );
- }
-
- if ( is_wp_error( $tags ) ) {
- wp_die( $tags->get_error_message() );
- }
-
- foreach ( $tags as $key => $tag ) {
- $tags[ $key ]->link = '#';
- $tags[ $key ]->id = $tag->term_id;
- }
-
- // We need raw tag names here, so don't filter the output
- $return = wp_generate_tag_cloud(
- $tags,
- array(
- 'filter' => 0,
- 'format' => 'list',
- )
- );
-
- if ( empty( $return ) ) {
- wp_die( 0 );
- }
-
- echo $return;
- wp_die();
-}
-
-/**
- * Ajax handler for getting comments.
- *
- * @since 3.1.0
- *
- * @global int $post_id
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_get_comments( $action ) {
- global $post_id;
-
- if ( empty( $action ) ) {
- $action = 'get-comments';
- }
-
- check_ajax_referer( $action );
-
- if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) {
- $id = absint( $_REQUEST['p'] );
- if ( ! empty( $id ) ) {
- $post_id = $id;
- }
- }
-
- if ( empty( $post_id ) ) {
- wp_die( -1 );
- }
-
- $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
-
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- wp_die( -1 );
- }
-
- $wp_list_table->prepare_items();
-
- if ( ! $wp_list_table->has_items() ) {
- wp_die( 1 );
- }
-
- $x = new WP_Ajax_Response();
-
- ob_start();
- foreach ( $wp_list_table->items as $comment ) {
- if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) {
- continue;
- }
- get_comment( $comment );
- $wp_list_table->single_row( $comment );
- }
- $comment_list_item = ob_get_clean();
-
- $x->add(
- array(
- 'what' => 'comments',
- 'data' => $comment_list_item,
- )
- );
-
- $x->send();
-}
-
-/**
- * Ajax handler for replying to a comment.
- *
- * @since 3.1.0
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_replyto_comment( $action ) {
- if ( empty( $action ) ) {
- $action = 'replyto-comment';
- }
-
- check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
-
- $comment_post_ID = (int) $_POST['comment_post_ID'];
- $post = get_post( $comment_post_ID );
-
- if ( ! $post ) {
- wp_die( -1 );
- }
-
- if ( ! current_user_can( 'edit_post', $comment_post_ID ) ) {
- wp_die( -1 );
- }
-
- if ( empty( $post->post_status ) ) {
- wp_die( 1 );
- } elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ) ) ) {
- wp_die( __( 'ERROR: you are replying to a comment on a draft post.' ) );
- }
-
- $user = wp_get_current_user();
-
- if ( $user->exists() ) {
- $user_ID = $user->ID;
- $comment_author = wp_slash( $user->display_name );
- $comment_author_email = wp_slash( $user->user_email );
- $comment_author_url = wp_slash( $user->user_url );
- $comment_content = trim( $_POST['content'] );
- $comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : '';
-
- if ( current_user_can( 'unfiltered_html' ) ) {
- if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) {
- $_POST['_wp_unfiltered_html_comment'] = '';
- }
-
- if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) {
- kses_remove_filters(); // start with a clean slate
- kses_init_filters(); // set up the filters
- remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
- add_filter( 'pre_comment_content', 'wp_filter_kses' );
- }
- }
- } else {
- wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) );
- }
-
- if ( '' == $comment_content ) {
- wp_die( __( 'ERROR: please type a comment.' ) );
- }
-
- $comment_parent = 0;
-
- if ( isset( $_POST['comment_ID'] ) ) {
- $comment_parent = absint( $_POST['comment_ID'] );
- }
-
- $comment_auto_approved = false;
- $commentdata = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' );
-
- // Automatically approve parent comment.
- if ( ! empty( $_POST['approve_parent'] ) ) {
- $parent = get_comment( $comment_parent );
-
- if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
- if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
- wp_die( -1 );
- }
-
- if ( wp_set_comment_status( $parent, 'approve' ) ) {
- $comment_auto_approved = true;
- }
- }
- }
-
- $comment_id = wp_new_comment( $commentdata );
-
- if ( is_wp_error( $comment_id ) ) {
- wp_die( $comment_id->get_error_message() );
- }
-
- $comment = get_comment( $comment_id );
-
- if ( ! $comment ) {
- wp_die( 1 );
- }
-
- $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
-
- ob_start();
- if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) {
- require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
- _wp_dashboard_recent_comments_row( $comment );
- } else {
- if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) {
- $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
- } else {
- $wp_list_table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
- }
- $wp_list_table->single_row( $comment );
- }
- $comment_list_item = ob_get_clean();
-
- $response = array(
- 'what' => 'comment',
- 'id' => $comment->comment_ID,
- 'data' => $comment_list_item,
- 'position' => $position,
- );
-
- $counts = wp_count_comments();
- $response['supplemental'] = array(
- 'in_moderation' => $counts->moderated,
- 'i18n_comments_text' => sprintf(
- /* translators: %s: Number of comments. */
- _n( '%s Comment', '%s Comments', $counts->approved ),
- number_format_i18n( $counts->approved )
- ),
- 'i18n_moderation_text' => sprintf(
- /* translators: %s: Number of comments. */
- _n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
- number_format_i18n( $counts->moderated )
- ),
- );
-
- if ( $comment_auto_approved ) {
- $response['supplemental']['parent_approved'] = $parent->comment_ID;
- $response['supplemental']['parent_post_id'] = $parent->comment_post_ID;
- }
-
- $x = new WP_Ajax_Response();
- $x->add( $response );
- $x->send();
-}
-
-/**
- * Ajax handler for editing a comment.
- *
- * @since 3.1.0
- */
-function wp_ajax_edit_comment() {
- check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
-
- $comment_id = (int) $_POST['comment_ID'];
-
- if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
- wp_die( -1 );
- }
-
- if ( '' == $_POST['content'] ) {
- wp_die( __( 'ERROR: please type a comment.' ) );
- }
-
- if ( isset( $_POST['status'] ) ) {
- $_POST['comment_status'] = $_POST['status'];
- }
- edit_comment();
-
- $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
- $checkbox = ( isset( $_POST['checkbox'] ) && true == $_POST['checkbox'] ) ? 1 : 0;
- $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
-
- $comment = get_comment( $comment_id );
-
- if ( empty( $comment->comment_ID ) ) {
- wp_die( -1 );
- }
-
- ob_start();
- $wp_list_table->single_row( $comment );
- $comment_list_item = ob_get_clean();
-
- $x = new WP_Ajax_Response();
-
- $x->add(
- array(
- 'what' => 'edit_comment',
- 'id' => $comment->comment_ID,
- 'data' => $comment_list_item,
- 'position' => $position,
- )
- );
-
- $x->send();
-}
-
-/**
- * Ajax handler for adding a menu item.
- *
- * @since 3.1.0
- */
-function wp_ajax_add_menu_item() {
- check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( -1 );
- }
-
- require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
-
- // For performance reasons, we omit some object properties from the checklist.
- // The following is a hacky way to restore them when adding non-custom items.
- $menu_items_data = array();
-
- foreach ( (array) $_POST['menu-item'] as $menu_item_data ) {
- if (
- ! empty( $menu_item_data['menu-item-type'] ) &&
- 'custom' != $menu_item_data['menu-item-type'] &&
- ! empty( $menu_item_data['menu-item-object-id'] )
- ) {
- switch ( $menu_item_data['menu-item-type'] ) {
- case 'post_type':
- $_object = get_post( $menu_item_data['menu-item-object-id'] );
- break;
-
- case 'post_type_archive':
- $_object = get_post_type_object( $menu_item_data['menu-item-object'] );
- break;
-
- case 'taxonomy':
- $_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] );
- break;
- }
-
- $_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
- $_menu_item = reset( $_menu_items );
-
- // Restore the missing menu item properties
- $menu_item_data['menu-item-description'] = $_menu_item->description;
- }
-
- $menu_items_data[] = $menu_item_data;
- }
-
- $item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
- if ( is_wp_error( $item_ids ) ) {
- wp_die( 0 );
- }
-
- $menu_items = array();
-
- foreach ( (array) $item_ids as $menu_item_id ) {
- $menu_obj = get_post( $menu_item_id );
-
- if ( ! empty( $menu_obj->ID ) ) {
- $menu_obj = wp_setup_nav_menu_item( $menu_obj );
- $menu_obj->title = empty( $menu_obj->title ) ? __( 'Menu Item' ) : $menu_obj->title;
- $menu_obj->label = $menu_obj->title; // don't show "(pending)" in ajax-added items
- $menu_items[] = $menu_obj;
- }
- }
-
- /** This filter is documented in wp-admin/includes/nav-menu.php */
- $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] );
-
- if ( ! class_exists( $walker_class_name ) ) {
- wp_die( 0 );
- }
-
- if ( ! empty( $menu_items ) ) {
- $args = array(
- 'after' => '',
- 'before' => '',
- 'link_after' => '',
- 'link_before' => '',
- 'walker' => new $walker_class_name,
- );
-
- echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
- }
-
- wp_die();
-}
-
-/**
- * Ajax handler for adding meta.
- *
- * @since 3.1.0
- */
-function wp_ajax_add_meta() {
- check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' );
- $c = 0;
- $pid = (int) $_POST['post_id'];
- $post = get_post( $pid );
-
- if ( isset( $_POST['metakeyselect'] ) || isset( $_POST['metakeyinput'] ) ) {
- if ( ! current_user_can( 'edit_post', $pid ) ) {
- wp_die( -1 );
- }
-
- if ( isset( $_POST['metakeyselect'] ) && '#NONE#' == $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) {
- wp_die( 1 );
- }
-
- // If the post is an autodraft, save the post as a draft and then attempt to save the meta.
- if ( $post->post_status == 'auto-draft' ) {
- $post_data = array();
- $post_data['action'] = 'draft'; // Warning fix
- $post_data['post_ID'] = $pid;
- $post_data['post_type'] = $post->post_type;
- $post_data['post_status'] = 'draft';
- $now = time();
- /* translators: 1: Post creation date, 2: Post creation time. */
- $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) );
-
- $pid = edit_post( $post_data );
-
- if ( $pid ) {
- if ( is_wp_error( $pid ) ) {
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'meta',
- 'data' => $pid,
- )
- );
- $x->send();
- }
-
- $mid = add_meta( $pid );
- if ( ! $mid ) {
- wp_die( __( 'Please provide a custom field value.' ) );
- }
- } else {
- wp_die( 0 );
- }
- } else {
- $mid = add_meta( $pid );
- if ( ! $mid ) {
- wp_die( __( 'Please provide a custom field value.' ) );
- }
- }
-
- $meta = get_metadata_by_mid( 'post', $mid );
- $pid = (int) $meta->post_id;
- $meta = get_object_vars( $meta );
-
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'meta',
- 'id' => $mid,
- 'data' => _list_meta_row( $meta, $c ),
- 'position' => 1,
- 'supplemental' => array( 'postid' => $pid ),
- )
- );
- } else { // Update?
- $mid = (int) key( $_POST['meta'] );
- $key = wp_unslash( $_POST['meta'][ $mid ]['key'] );
- $value = wp_unslash( $_POST['meta'][ $mid ]['value'] );
-
- if ( '' == trim( $key ) ) {
- wp_die( __( 'Please provide a custom field name.' ) );
- }
-
- $meta = get_metadata_by_mid( 'post', $mid );
-
- if ( ! $meta ) {
- wp_die( 0 ); // if meta doesn't exist
- }
-
- if (
- is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) ||
- ! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) ||
- ! current_user_can( 'edit_post_meta', $meta->post_id, $key )
- ) {
- wp_die( -1 );
- }
-
- if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
- $u = update_metadata_by_mid( 'post', $mid, $value, $key );
- if ( ! $u ) {
- wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
- }
- }
-
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'meta',
- 'id' => $mid,
- 'old_id' => $mid,
- 'data' => _list_meta_row(
- array(
- 'meta_key' => $key,
- 'meta_value' => $value,
- 'meta_id' => $mid,
- ),
- $c
- ),
- 'position' => 0,
- 'supplemental' => array( 'postid' => $meta->post_id ),
- )
- );
- }
- $x->send();
-}
-
-/**
- * Ajax handler for adding a user.
- *
- * @since 3.1.0
- *
- * @param string $action Action to perform.
- */
-function wp_ajax_add_user( $action ) {
- if ( empty( $action ) ) {
- $action = 'add-user';
- }
-
- check_ajax_referer( $action );
-
- if ( ! current_user_can( 'create_users' ) ) {
- wp_die( -1 );
- }
-
- $user_id = edit_user();
-
- if ( ! $user_id ) {
- wp_die( 0 );
- } elseif ( is_wp_error( $user_id ) ) {
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'user',
- 'id' => $user_id,
- )
- );
- $x->send();
- }
-
- $user_object = get_userdata( $user_id );
- $wp_list_table = _get_list_table( 'WP_Users_List_Table' );
-
- $role = current( $user_object->roles );
-
- $x = new WP_Ajax_Response(
- array(
- 'what' => 'user',
- 'id' => $user_id,
- 'data' => $wp_list_table->single_row( $user_object, '', $role ),
- 'supplemental' => array(
- 'show-link' => sprintf(
- /* translators: %s: The new user. */
- __( 'User %s added' ),
- '' . $user_object->user_login . ' '
- ),
- 'role' => $role,
- ),
- )
- );
- $x->send();
-}
-
-/**
- * Ajax handler for closed post boxes.
- *
- * @since 3.1.0
- */
-function wp_ajax_closed_postboxes() {
- check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
- $closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed'] ) : array();
- $closed = array_filter( $closed );
-
- $hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
- $hidden = array_filter( $hidden );
-
- $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
-
- if ( $page != sanitize_key( $page ) ) {
- wp_die( 0 );
- }
-
- $user = wp_get_current_user();
- if ( ! $user ) {
- wp_die( -1 );
- }
-
- if ( is_array( $closed ) ) {
- update_user_option( $user->ID, "closedpostboxes_$page", $closed, true );
- }
-
- if ( is_array( $hidden ) ) {
- $hidden = array_diff( $hidden, array( 'submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu' ) ); // postboxes that are always shown
- update_user_option( $user->ID, "metaboxhidden_$page", $hidden, true );
- }
-
- wp_die( 1 );
-}
-
-/**
- * Ajax handler for hidden columns.
- *
- * @since 3.1.0
- */
-function wp_ajax_hidden_columns() {
- check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
- $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
-
- if ( $page != sanitize_key( $page ) ) {
- wp_die( 0 );
- }
-
- $user = wp_get_current_user();
- if ( ! $user ) {
- wp_die( -1 );
- }
-
- $hidden = ! empty( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
- update_user_option( $user->ID, "manage{$page}columnshidden", $hidden, true );
-
- wp_die( 1 );
-}
-
-/**
- * Ajax handler for updating whether to display the welcome panel.
- *
- * @since 3.1.0
- */
-function wp_ajax_update_welcome_panel() {
- check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( -1 );
- }
-
- update_user_meta( get_current_user_id(), 'show_welcome_panel', empty( $_POST['visible'] ) ? 0 : 1 );
-
- wp_die( 1 );
-}
-
-/**
- * Ajax handler for retrieving menu meta boxes.
- *
- * @since 3.1.0
- */
-function wp_ajax_menu_get_metabox() {
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( -1 );
- }
-
- require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
-
- if ( isset( $_POST['item-type'] ) && 'post_type' == $_POST['item-type'] ) {
- $type = 'posttype';
- $callback = 'wp_nav_menu_item_post_type_meta_box';
- $items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
- } elseif ( isset( $_POST['item-type'] ) && 'taxonomy' == $_POST['item-type'] ) {
- $type = 'taxonomy';
- $callback = 'wp_nav_menu_item_taxonomy_meta_box';
- $items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
- }
-
- if ( ! empty( $_POST['item-object'] ) && isset( $items[ $_POST['item-object'] ] ) ) {
- $menus_meta_box_object = $items[ $_POST['item-object'] ];
-
- /** This filter is documented in wp-admin/includes/nav-menu.php */
- $item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object );
-
- $box_args = array(
- 'id' => 'add-' . $item->name,
- 'title' => $item->labels->name,
- 'callback' => $callback,
- 'args' => $item,
- );
-
- ob_start();
- $callback( null, $box_args );
-
- $markup = ob_get_clean();
-
- echo wp_json_encode(
- array(
- 'replace-id' => $type . '-' . $item->name,
- 'markup' => $markup,
- )
- );
- }
-
- wp_die();
-}
-
-/**
- * Ajax handler for internal linking.
- *
- * @since 3.1.0
- */
-function wp_ajax_wp_link_ajax() {
- check_ajax_referer( 'internal-linking', '_ajax_linking_nonce' );
-
- $args = array();
-
- if ( isset( $_POST['search'] ) ) {
- $args['s'] = wp_unslash( $_POST['search'] );
- }
-
- if ( isset( $_POST['term'] ) ) {
- $args['s'] = wp_unslash( $_POST['term'] );
- }
-
- $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
-
- if ( ! class_exists( '_WP_Editors', false ) ) {
- require( ABSPATH . WPINC . '/class-wp-editor.php' );
- }
-
- $results = _WP_Editors::wp_link_query( $args );
-
- if ( ! isset( $results ) ) {
- wp_die( 0 );
- }
-
- echo wp_json_encode( $results );
- echo "\n";
-
- wp_die();
-}
-
-/**
- * Ajax handler for menu locations save.
- *
- * @since 3.1.0
- */
-function wp_ajax_menu_locations_save() {
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( -1 );
- }
-
- check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
-
- if ( ! isset( $_POST['menu-locations'] ) ) {
- wp_die( 0 );
- }
-
- set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
- wp_die( 1 );
-}
-
-/**
- * Ajax handler for saving the meta box order.
- *
- * @since 3.1.0
- */
-function wp_ajax_meta_box_order() {
- check_ajax_referer( 'meta-box-order' );
- $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
- $page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto';
-
- if ( $page_columns != 'auto' ) {
- $page_columns = (int) $page_columns;
- }
-
- $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
-
- if ( $page != sanitize_key( $page ) ) {
- wp_die( 0 );
- }
-
- $user = wp_get_current_user();
- if ( ! $user ) {
- wp_die( -1 );
- }
-
- if ( $order ) {
- update_user_option( $user->ID, "meta-box-order_$page", $order, true );
- }
-
- if ( $page_columns ) {
- update_user_option( $user->ID, "screen_layout_$page", $page_columns, true );
- }
-
- wp_die( 1 );
-}
-
-/**
- * Ajax handler for menu quick searching.
- *
- * @since 3.1.0
- */
-function wp_ajax_menu_quick_search() {
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( -1 );
- }
-
- require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
-
- _wp_ajax_menu_quick_search( $_POST );
-
- wp_die();
-}
-
-/**
- * Ajax handler to retrieve a permalink.
- *
- * @since 3.1.0
- */
-function wp_ajax_get_permalink() {
- check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
- $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
- wp_die( get_preview_post_link( $post_id ) );
-}
-
-/**
- * Ajax handler to retrieve a sample permalink.
- *
- * @since 3.1.0
- */
-function wp_ajax_sample_permalink() {
- check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
- $post_id = isset( $_POST['post_id'] ) ? intval( $_POST['post_id'] ) : 0;
- $title = isset( $_POST['new_title'] ) ? $_POST['new_title'] : '';
- $slug = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
- wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
-}
-
-/**
- * Ajax handler for Quick Edit saving a post from a list table.
- *
- * @since 3.1.0
- *
- * @global string $mode List table view mode.
- */
-function wp_ajax_inline_save() {
- global $mode;
-
- check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
-
- if ( ! isset( $_POST['post_ID'] ) || ! (int) $_POST['post_ID'] ) {
- wp_die();
- }
-
- $post_ID = (int) $_POST['post_ID'];
-
- if ( 'page' == $_POST['post_type'] ) {
- if ( ! current_user_can( 'edit_page', $post_ID ) ) {
- wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
- }
- } else {
- if ( ! current_user_can( 'edit_post', $post_ID ) ) {
- wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
- }
- }
-
- $last = wp_check_post_lock( $post_ID );
- if ( $last ) {
- $last_user = get_userdata( $last );
- $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
-
- /* translators: %s: User's display name. */
- $msg_template = __( 'Saving is disabled: %s is currently editing this post.' );
-
- if ( $_POST['post_type'] == 'page' ) {
- /* translators: %s: User's display name. */
- $msg_template = __( 'Saving is disabled: %s is currently editing this page.' );
- }
-
- printf( $msg_template, esc_html( $last_user_name ) );
- wp_die();
- }
-
- $data = &$_POST;
-
- $post = get_post( $post_ID, ARRAY_A );
-
- // Since it's coming from the database.
- $post = wp_slash( $post );
-
- $data['content'] = $post['post_content'];
- $data['excerpt'] = $post['post_excerpt'];
-
- // Rename.
- $data['user_ID'] = get_current_user_id();
-
- if ( isset( $data['post_parent'] ) ) {
- $data['parent_id'] = $data['post_parent'];
- }
-
- // Status.
- if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) {
- $data['visibility'] = 'private';
- $data['post_status'] = 'private';
- } else {
- $data['post_status'] = $data['_status'];
- }
-
- if ( empty( $data['comment_status'] ) ) {
- $data['comment_status'] = 'closed';
- }
-
- if ( empty( $data['ping_status'] ) ) {
- $data['ping_status'] = 'closed';
- }
-
- // Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
- if ( ! empty( $data['tax_input'] ) ) {
- foreach ( $data['tax_input'] as $taxonomy => $terms ) {
- $tax_object = get_taxonomy( $taxonomy );
- /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
- if ( ! apply_filters( 'quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy, $post['post_type'] ) ) {
- unset( $data['tax_input'][ $taxonomy ] );
- }
- }
- }
-
- // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
- if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) {
- $post['post_status'] = 'publish';
- $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] );
- }
-
- // Update the post.
- edit_post();
-
- $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );
-
- $mode = $_POST['post_view'] === 'excerpt' ? 'excerpt' : 'list';
-
- $level = 0;
- if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) {
- $request_post = array( get_post( $_POST['post_ID'] ) );
- $parent = $request_post[0]->post_parent;
-
- while ( $parent > 0 ) {
- $parent_post = get_post( $parent );
- $parent = $parent_post->post_parent;
- $level++;
- }
- }
-
- $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level );
-
- wp_die();
-}
-
-/**
- * Ajax handler for quick edit saving for a term.
- *
- * @since 3.1.0
- */
-function wp_ajax_inline_save_tax() {
- check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
-
- $taxonomy = sanitize_key( $_POST['taxonomy'] );
- $tax = get_taxonomy( $taxonomy );
-
- if ( ! $tax ) {
- wp_die( 0 );
- }
-
- if ( ! isset( $_POST['tax_ID'] ) || ! (int) $_POST['tax_ID'] ) {
- wp_die( -1 );
- }
-
- $id = (int) $_POST['tax_ID'];
-
- if ( ! current_user_can( 'edit_term', $id ) ) {
- wp_die( -1 );
- }
-
- $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) );
-
- $tag = get_term( $id, $taxonomy );
- $_POST['description'] = $tag->description;
-
- $updated = wp_update_term( $id, $taxonomy, $_POST );
-
- if ( $updated && ! is_wp_error( $updated ) ) {
- $tag = get_term( $updated['term_id'], $taxonomy );
- if ( ! $tag || is_wp_error( $tag ) ) {
- if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
- wp_die( $tag->get_error_message() );
- }
- wp_die( __( 'Item not updated.' ) );
- }
- } else {
- if ( is_wp_error( $updated ) && $updated->get_error_message() ) {
- wp_die( $updated->get_error_message() );
- }
- wp_die( __( 'Item not updated.' ) );
- }
-
- $level = 0;
- $parent = $tag->parent;
-
- while ( $parent > 0 ) {
- $parent_tag = get_term( $parent, $taxonomy );
- $parent = $parent_tag->parent;
- $level++;
- }
-
- $wp_list_table->single_row( $tag, $level );
- wp_die();
-}
-
-/**
- * Ajax handler for querying posts for the Find Posts modal.
- *
- * @see window.findPosts
- *
- * @since 3.1.0
- */
-function wp_ajax_find_posts() {
- check_ajax_referer( 'find-posts' );
-
- $post_types = get_post_types( array( 'public' => true ), 'objects' );
- unset( $post_types['attachment'] );
-
- $s = wp_unslash( $_POST['ps'] );
- $args = array(
- 'post_type' => array_keys( $post_types ),
- 'post_status' => 'any',
- 'posts_per_page' => 50,
- );
-
- if ( '' !== $s ) {
- $args['s'] = $s;
- }
-
- $posts = get_posts( $args );
-
- if ( ! $posts ) {
- wp_send_json_error( __( 'No items found.' ) );
- }
-
- $html = '';
-
- wp_send_json_success( $html );
-}
-
-/**
- * Ajax handler for saving the widgets order.
- *
- * @since 3.1.0
- */
-function wp_ajax_widgets_order() {
- check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( -1 );
- }
-
- unset( $_POST['savewidgets'], $_POST['action'] );
-
- // Save widgets order for all sidebars.
- if ( is_array( $_POST['sidebars'] ) ) {
- $sidebars = array();
-
- foreach ( wp_unslash( $_POST['sidebars'] ) as $key => $val ) {
- $sb = array();
-
- if ( ! empty( $val ) ) {
- $val = explode( ',', $val );
-
- foreach ( $val as $k => $v ) {
- if ( strpos( $v, 'widget-' ) === false ) {
- continue;
- }
-
- $sb[ $k ] = substr( $v, strpos( $v, '_' ) + 1 );
- }
- }
- $sidebars[ $key ] = $sb;
- }
-
- wp_set_sidebars_widgets( $sidebars );
- wp_die( 1 );
- }
-
- wp_die( -1 );
-}
-
-/**
- * Ajax handler for saving a widget.
- *
- * @since 3.1.0
- *
- * @global array $wp_registered_widgets
- * @global array $wp_registered_widget_controls
- * @global array $wp_registered_widget_updates
- */
-function wp_ajax_save_widget() {
- global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates;
-
- check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
-
- if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['id_base'] ) ) {
- wp_die( -1 );
- }
-
- unset( $_POST['savewidgets'], $_POST['action'] );
-
- /**
- * Fires early when editing the widgets displayed in sidebars.
- *
- * @since 2.8.0
- */
- do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
-
- /**
- * Fires early when editing the widgets displayed in sidebars.
- *
- * @since 2.8.0
- */
- do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
-
- /** This action is documented in wp-admin/widgets.php */
- do_action( 'sidebar_admin_setup' );
-
- $id_base = wp_unslash( $_POST['id_base'] );
- $widget_id = wp_unslash( $_POST['widget-id'] );
- $sidebar_id = $_POST['sidebar'];
- $multi_number = ! empty( $_POST['multi_number'] ) ? (int) $_POST['multi_number'] : 0;
- $settings = isset( $_POST[ 'widget-' . $id_base ] ) && is_array( $_POST[ 'widget-' . $id_base ] ) ? $_POST[ 'widget-' . $id_base ] : false;
- $error = '' . __( 'An error has occurred. Please reload the page and try again.' ) . '
';
-
- $sidebars = wp_get_sidebars_widgets();
- $sidebar = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array();
-
- // Delete.
- if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
-
- if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) {
- wp_die( $error );
- }
-
- $sidebar = array_diff( $sidebar, array( $widget_id ) );
- $_POST = array(
- 'sidebar' => $sidebar_id,
- 'widget-' . $id_base => array(),
- 'the-widget-id' => $widget_id,
- 'delete_widget' => '1',
- );
-
- /** This action is documented in wp-admin/widgets.php */
- do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base );
-
- } elseif ( $settings && preg_match( '/__i__|%i%/', key( $settings ) ) ) {
- if ( ! $multi_number ) {
- wp_die( $error );
- }
-
- $_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) );
- $widget_id = $id_base . '-' . $multi_number;
- $sidebar[] = $widget_id;
- }
- $_POST['widget-id'] = $sidebar;
-
- foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
-
- if ( $name == $id_base ) {
- if ( ! is_callable( $control['callback'] ) ) {
- continue;
- }
-
- ob_start();
- call_user_func_array( $control['callback'], $control['params'] );
- ob_end_clean();
- break;
- }
- }
-
- if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
- $sidebars[ $sidebar_id ] = $sidebar;
- wp_set_sidebars_widgets( $sidebars );
- echo "deleted:$widget_id";
- wp_die();
- }
-
- if ( ! empty( $_POST['add_new'] ) ) {
- wp_die();
- }
-
- $form = $wp_registered_widget_controls[ $widget_id ];
- if ( $form ) {
- call_user_func_array( $form['callback'], $form['params'] );
- }
-
- wp_die();
-}
-
-/**
- * Ajax handler for saving a widget.
- *
- * @since 3.9.0
- *
- * @global WP_Customize_Manager $wp_customize
- */
-function wp_ajax_update_widget() {
- global $wp_customize;
- $wp_customize->widgets->wp_ajax_update_widget();
-}
-
-/**
- * Ajax handler for removing inactive widgets.
- *
- * @since 4.4.0
- */
-function wp_ajax_delete_inactive_widgets() {
- check_ajax_referer( 'remove-inactive-widgets', 'removeinactivewidgets' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( -1 );
- }
-
- unset( $_POST['removeinactivewidgets'], $_POST['action'] );
- /** This action is documented in wp-admin/includes/ajax-actions.php */
- do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
- /** This action is documented in wp-admin/includes/ajax-actions.php */
- do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
- /** This action is documented in wp-admin/widgets.php */
- do_action( 'sidebar_admin_setup' );
-
- $sidebars_widgets = wp_get_sidebars_widgets();
-
- foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) {
- $pieces = explode( '-', $widget_id );
- $multi_number = array_pop( $pieces );
- $id_base = implode( '-', $pieces );
- $widget = get_option( 'widget_' . $id_base );
- unset( $widget[ $multi_number ] );
- update_option( 'widget_' . $id_base, $widget );
- unset( $sidebars_widgets['wp_inactive_widgets'][ $key ] );
- }
-
- wp_set_sidebars_widgets( $sidebars_widgets );
-
- wp_die();
-}
-
-/**
- * Ajax handler for creating missing image sub-sizes for just uploaded images.
- *
- * @since 5.3.0
- */
-function wp_ajax_media_create_image_subsizes() {
- check_ajax_referer( 'media-form' );
-
- if ( ! current_user_can( 'upload_files' ) ) {
- wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) );
- }
-
- if ( empty( $_POST['attachment_id'] ) ) {
- wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) );
- }
-
- $attachment_id = (int) $_POST['attachment_id'];
-
- if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) {
- // Upload failed. Cleanup.
- if ( wp_attachment_is_image( $attachment_id ) && current_user_can( 'delete_post', $attachment_id ) ) {
- $attachment = get_post( $attachment_id );
-
- // Created at most 10 min ago.
- if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) {
- wp_delete_attachment( $attachment_id, true );
- wp_send_json_success();
- }
- }
- }
-
- // Set a custom header with the attachment_id.
- // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
- if ( ! headers_sent() ) {
- header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
- }
-
- // This can still be pretty slow and cause timeout or out of memory errors.
- // The js that handles the response would need to also handle HTTP 500 errors.
- wp_update_image_subsizes( $attachment_id );
-
- if ( ! empty( $_POST['_legacy_support'] ) ) {
- // The old (inline) uploader. Only needs the attachment_id.
- $response = array( 'id' => $attachment_id );
- } else {
- // Media modal and Media Library grid view.
- $response = wp_prepare_attachment_for_js( $attachment_id );
-
- if ( ! $response ) {
- wp_send_json_error( array( 'message' => __( 'Upload failed.' ) ) );
- }
- }
-
- // At this point the image has been uploaded successfully.
- wp_send_json_success( $response );
-}
-
-/**
- * Ajax handler for uploading attachments
- *
- * @since 3.3.0
- */
-function wp_ajax_upload_attachment() {
- check_ajax_referer( 'media-form' );
- /*
- * This function does not use wp_send_json_success() / wp_send_json_error()
- * as the html4 Plupload handler requires a text/html content-type for older IE.
- * See https://core.trac.wordpress.org/ticket/31037
- */
-
- if ( ! current_user_can( 'upload_files' ) ) {
- echo wp_json_encode(
- array(
- 'success' => false,
- 'data' => array(
- 'message' => __( 'Sorry, you are not allowed to upload files.' ),
- 'filename' => esc_html( $_FILES['async-upload']['name'] ),
- ),
- )
- );
-
- wp_die();
- }
-
- if ( isset( $_REQUEST['post_id'] ) ) {
- $post_id = $_REQUEST['post_id'];
-
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- echo wp_json_encode(
- array(
- 'success' => false,
- 'data' => array(
- 'message' => __( 'Sorry, you are not allowed to attach files to this post.' ),
- 'filename' => esc_html( $_FILES['async-upload']['name'] ),
- ),
- )
- );
-
- wp_die();
- }
- } else {
- $post_id = null;
- }
-
- $post_data = ! empty( $_REQUEST['post_data'] ) ? _wp_get_allowed_postdata( _wp_translate_postdata( false, (array) $_REQUEST['post_data'] ) ) : array();
-
- if ( is_wp_error( $post_data ) ) {
- wp_die( $post_data->get_error_message() );
- }
-
- // If the context is custom header or background, make sure the uploaded file is an image.
- if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ) ) ) {
- $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] );
-
- if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
- echo wp_json_encode(
- array(
- 'success' => false,
- 'data' => array(
- 'message' => __( 'The uploaded file is not a valid image. Please try again.' ),
- 'filename' => esc_html( $_FILES['async-upload']['name'] ),
- ),
- )
- );
-
- wp_die();
- }
- }
-
- $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data );
-
- if ( is_wp_error( $attachment_id ) ) {
- echo wp_json_encode(
- array(
- 'success' => false,
- 'data' => array(
- 'message' => $attachment_id->get_error_message(),
- 'filename' => esc_html( $_FILES['async-upload']['name'] ),
- ),
- )
- );
-
- wp_die();
- }
-
- if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) {
- if ( 'custom-background' === $post_data['context'] ) {
- update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] );
- }
-
- if ( 'custom-header' === $post_data['context'] ) {
- update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] );
- }
- }
-
- $attachment = wp_prepare_attachment_for_js( $attachment_id );
- if ( ! $attachment ) {
- wp_die();
- }
-
- echo wp_json_encode(
- array(
- 'success' => true,
- 'data' => $attachment,
- )
- );
-
- wp_die();
-}
-
-/**
- * Ajax handler for image editing.
- *
- * @since 3.1.0
- */
-function wp_ajax_image_editor() {
- $attachment_id = intval( $_POST['postid'] );
-
- if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
- wp_die( -1 );
- }
-
- check_ajax_referer( "image_editor-$attachment_id" );
- include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
-
- $msg = false;
- switch ( $_POST['do'] ) {
- case 'save':
- $msg = wp_save_image( $attachment_id );
- $msg = wp_json_encode( $msg );
- wp_die( $msg );
- break;
- case 'scale':
- $msg = wp_save_image( $attachment_id );
- break;
- case 'restore':
- $msg = wp_restore_image( $attachment_id );
- break;
- }
-
- wp_image_editor( $attachment_id, $msg );
- wp_die();
-}
-
-/**
- * Ajax handler for setting the featured image.
- *
- * @since 3.1.0
- */
-function wp_ajax_set_post_thumbnail() {
- $json = ! empty( $_REQUEST['json'] ); // New-style request
-
- $post_ID = intval( $_POST['post_id'] );
- if ( ! current_user_can( 'edit_post', $post_ID ) ) {
- wp_die( -1 );
- }
-
- $thumbnail_id = intval( $_POST['thumbnail_id'] );
-
- if ( $json ) {
- check_ajax_referer( "update-post_$post_ID" );
- } else {
- check_ajax_referer( "set_post_thumbnail-$post_ID" );
- }
-
- if ( $thumbnail_id == '-1' ) {
- if ( delete_post_thumbnail( $post_ID ) ) {
- $return = _wp_post_thumbnail_html( null, $post_ID );
- $json ? wp_send_json_success( $return ) : wp_die( $return );
- } else {
- wp_die( 0 );
- }
- }
-
- if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) {
- $return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID );
- $json ? wp_send_json_success( $return ) : wp_die( $return );
- }
-
- wp_die( 0 );
-}
-
-/**
- * Ajax handler for retrieving HTML for the featured image.
- *
- * @since 4.6.0
- */
-function wp_ajax_get_post_thumbnail_html() {
- $post_ID = intval( $_POST['post_id'] );
-
- check_ajax_referer( "update-post_$post_ID" );
-
- if ( ! current_user_can( 'edit_post', $post_ID ) ) {
- wp_die( -1 );
- }
-
- $thumbnail_id = intval( $_POST['thumbnail_id'] );
-
- // For backward compatibility, -1 refers to no featured image.
- if ( -1 === $thumbnail_id ) {
- $thumbnail_id = null;
- }
-
- $return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID );
- wp_send_json_success( $return );
-}
-
-/**
- * Ajax handler for setting the featured image for an attachment.
- *
- * @since 4.0.0
- *
- * @see set_post_thumbnail()
- */
-function wp_ajax_set_attachment_thumbnail() {
- if ( empty( $_POST['urls'] ) || ! is_array( $_POST['urls'] ) ) {
- wp_send_json_error();
- }
-
- $thumbnail_id = (int) $_POST['thumbnail_id'];
- if ( empty( $thumbnail_id ) ) {
- wp_send_json_error();
- }
-
- $post_ids = array();
- // For each URL, try to find its corresponding post ID.
- foreach ( $_POST['urls'] as $url ) {
- $post_id = attachment_url_to_postid( $url );
- if ( ! empty( $post_id ) ) {
- $post_ids[] = $post_id;
- }
- }
-
- if ( empty( $post_ids ) ) {
- wp_send_json_error();
- }
-
- $success = 0;
- // For each found attachment, set its thumbnail.
- foreach ( $post_ids as $post_id ) {
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- continue;
- }
-
- if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) {
- $success++;
- }
- }
-
- if ( 0 === $success ) {
- wp_send_json_error();
- } else {
- wp_send_json_success();
- }
-
- wp_send_json_error();
-}
-
-/**
- * Ajax handler for date formatting.
- *
- * @since 3.1.0
- */
-function wp_ajax_date_format() {
- wp_die( date_i18n( sanitize_option( 'date_format', wp_unslash( $_POST['date'] ) ) ) );
-}
-
-/**
- * Ajax handler for time formatting.
- *
- * @since 3.1.0
- */
-function wp_ajax_time_format() {
- wp_die( date_i18n( sanitize_option( 'time_format', wp_unslash( $_POST['date'] ) ) ) );
-}
-
-/**
- * Ajax handler for saving posts from the fullscreen editor.
- *
- * @since 3.1.0
- * @deprecated 4.3.0
- */
-function wp_ajax_wp_fullscreen_save_post() {
- $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
-
- $post = null;
-
- if ( $post_id ) {
- $post = get_post( $post_id );
- }
-
- check_ajax_referer( 'update-post_' . $post_id, '_wpnonce' );
-
- $post_id = edit_post();
-
- if ( is_wp_error( $post_id ) ) {
- wp_send_json_error();
- }
-
- if ( $post ) {
- $last_date = mysql2date( __( 'F j, Y' ), $post->post_modified );
- $last_time = mysql2date( __( 'g:i a' ), $post->post_modified );
- } else {
- $last_date = date_i18n( __( 'F j, Y' ) );
- $last_time = date_i18n( __( 'g:i a' ) );
- }
-
- $last_id = get_post_meta( $post_id, '_edit_last', true );
- if ( $last_id ) {
- $last_user = get_userdata( $last_id );
- /* translators: 1: User's display name, 2: Date of last edit, 3: Time of last edit. */
- $last_edited = sprintf( __( 'Last edited by %1$s on %2$s at %3$s' ), esc_html( $last_user->display_name ), $last_date, $last_time );
- } else {
- /* translators: 1: Date of last edit, 2: Time of last edit. */
- $last_edited = sprintf( __( 'Last edited on %1$s at %2$s' ), $last_date, $last_time );
- }
-
- wp_send_json_success( array( 'last_edited' => $last_edited ) );
-}
-
-/**
- * Ajax handler for removing a post lock.
- *
- * @since 3.1.0
- */
-function wp_ajax_wp_remove_post_lock() {
- if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) {
- wp_die( 0 );
- }
-
- $post_id = (int) $_POST['post_ID'];
- $post = get_post( $post_id );
-
- if ( ! $post ) {
- wp_die( 0 );
- }
-
- check_ajax_referer( 'update-post_' . $post_id );
-
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- wp_die( -1 );
- }
-
- $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
-
- if ( $active_lock[1] != get_current_user_id() ) {
- wp_die( 0 );
- }
-
- /**
- * Filters the post lock window duration.
- *
- * @since 3.3.0
- *
- * @param int $interval The interval in seconds the post lock duration
- * should last, plus 5 seconds. Default 150.
- */
- $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 150 ) + 5 ) . ':' . $active_lock[1];
- update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
- wp_die( 1 );
-}
-
-/**
- * Ajax handler for dismissing a WordPress pointer.
- *
- * @since 3.1.0
- */
-function wp_ajax_dismiss_wp_pointer() {
- $pointer = $_POST['pointer'];
-
- if ( $pointer != sanitize_key( $pointer ) ) {
- wp_die( 0 );
- }
-
- // check_ajax_referer( 'dismiss-pointer_' . $pointer );
-
- $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
-
- if ( in_array( $pointer, $dismissed ) ) {
- wp_die( 0 );
- }
-
- $dismissed[] = $pointer;
- $dismissed = implode( ',', $dismissed );
-
- update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
- wp_die( 1 );
-}
-
-/**
- * Ajax handler for getting an attachment.
- *
- * @since 3.5.0
- */
-function wp_ajax_get_attachment() {
- if ( ! isset( $_REQUEST['id'] ) ) {
- wp_send_json_error();
- }
-
- $id = absint( $_REQUEST['id'] );
- if ( ! $id ) {
- wp_send_json_error();
- }
-
- $post = get_post( $id );
- if ( ! $post ) {
- wp_send_json_error();
- }
-
- if ( 'attachment' != $post->post_type ) {
- wp_send_json_error();
- }
-
- if ( ! current_user_can( 'upload_files' ) ) {
- wp_send_json_error();
- }
-
- $attachment = wp_prepare_attachment_for_js( $id );
- if ( ! $attachment ) {
- wp_send_json_error();
- }
-
- wp_send_json_success( $attachment );
-}
-
-/**
- * Ajax handler for querying attachments.
- *
- * @since 3.5.0
- */
-function wp_ajax_query_attachments() {
- if ( ! current_user_can( 'upload_files' ) ) {
- wp_send_json_error();
- }
-
- $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
- $keys = array(
- 's',
- 'order',
- 'orderby',
- 'posts_per_page',
- 'paged',
- 'post_mime_type',
- 'post_parent',
- 'author',
- 'post__in',
- 'post__not_in',
- 'year',
- 'monthnum',
- );
-
- foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
- if ( $t->query_var && isset( $query[ $t->query_var ] ) ) {
- $keys[] = $t->query_var;
- }
- }
-
- $query = array_intersect_key( $query, array_flip( $keys ) );
- $query['post_type'] = 'attachment';
-
- if (
- MEDIA_TRASH &&
- ! empty( $_REQUEST['query']['post_status'] ) &&
- 'trash' === $_REQUEST['query']['post_status']
- ) {
- $query['post_status'] = 'trash';
- } else {
- $query['post_status'] = 'inherit';
- }
-
- if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) {
- $query['post_status'] .= ',private';
- }
-
- // Filter query clauses to include filenames.
- if ( isset( $query['s'] ) ) {
- add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
- }
-
- /**
- * Filters the arguments passed to WP_Query during an Ajax
- * call for querying attachments.
- *
- * @since 3.7.0
- *
- * @see WP_Query::parse_query()
- *
- * @param array $query An array of query variables.
- */
- $query = apply_filters( 'ajax_query_attachments_args', $query );
- $query = new WP_Query( $query );
-
- $posts = array_map( 'wp_prepare_attachment_for_js', $query->posts );
- $posts = array_filter( $posts );
-
- wp_send_json_success( $posts );
-}
-
-/**
- * Ajax handler for updating attachment attributes.
- *
- * @since 3.5.0
- */
-function wp_ajax_save_attachment() {
- if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) ) {
- wp_send_json_error();
- }
-
- $id = absint( $_REQUEST['id'] );
- if ( ! $id ) {
- wp_send_json_error();
- }
-
- check_ajax_referer( 'update-post_' . $id, 'nonce' );
-
- if ( ! current_user_can( 'edit_post', $id ) ) {
- wp_send_json_error();
- }
-
- $changes = $_REQUEST['changes'];
- $post = get_post( $id, ARRAY_A );
-
- if ( 'attachment' != $post['post_type'] ) {
- wp_send_json_error();
- }
-
- if ( isset( $changes['parent'] ) ) {
- $post['post_parent'] = $changes['parent'];
- }
-
- if ( isset( $changes['title'] ) ) {
- $post['post_title'] = $changes['title'];
- }
-
- if ( isset( $changes['caption'] ) ) {
- $post['post_excerpt'] = $changes['caption'];
- }
-
- if ( isset( $changes['description'] ) ) {
- $post['post_content'] = $changes['description'];
- }
-
- if ( MEDIA_TRASH && isset( $changes['status'] ) ) {
- $post['post_status'] = $changes['status'];
- }
-
- if ( isset( $changes['alt'] ) ) {
- $alt = wp_unslash( $changes['alt'] );
- if ( $alt != get_post_meta( $id, '_wp_attachment_image_alt', true ) ) {
- $alt = wp_strip_all_tags( $alt, true );
- update_post_meta( $id, '_wp_attachment_image_alt', wp_slash( $alt ) );
- }
- }
-
- if ( wp_attachment_is( 'audio', $post['ID'] ) ) {
- $changed = false;
- $id3data = wp_get_attachment_metadata( $post['ID'] );
-
- if ( ! is_array( $id3data ) ) {
- $changed = true;
- $id3data = array();
- }
-
- foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) {
- if ( isset( $changes[ $key ] ) ) {
- $changed = true;
- $id3data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) );
- }
- }
-
- if ( $changed ) {
- wp_update_attachment_metadata( $id, $id3data );
- }
- }
-
- if ( MEDIA_TRASH && isset( $changes['status'] ) && 'trash' === $changes['status'] ) {
- wp_delete_post( $id );
- } else {
- wp_update_post( $post );
- }
-
- wp_send_json_success();
-}
-
-/**
- * Ajax handler for saving backward compatible attachment attributes.
- *
- * @since 3.5.0
- */
-function wp_ajax_save_attachment_compat() {
- if ( ! isset( $_REQUEST['id'] ) ) {
- wp_send_json_error();
- }
-
- $id = absint( $_REQUEST['id'] );
- if ( ! $id ) {
- wp_send_json_error();
- }
-
- if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) {
- wp_send_json_error();
- }
-
- $attachment_data = $_REQUEST['attachments'][ $id ];
-
- check_ajax_referer( 'update-post_' . $id, 'nonce' );
-
- if ( ! current_user_can( 'edit_post', $id ) ) {
- wp_send_json_error();
- }
-
- $post = get_post( $id, ARRAY_A );
-
- if ( 'attachment' != $post['post_type'] ) {
- wp_send_json_error();
- }
-
- /** This filter is documented in wp-admin/includes/media.php */
- $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data );
-
- if ( isset( $post['errors'] ) ) {
- $errors = $post['errors']; // @todo return me and display me!
- unset( $post['errors'] );
- }
-
- wp_update_post( $post );
-
- foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
- if ( isset( $attachment_data[ $taxonomy ] ) ) {
- wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false );
- }
- }
-
- $attachment = wp_prepare_attachment_for_js( $id );
-
- if ( ! $attachment ) {
- wp_send_json_error();
- }
-
- wp_send_json_success( $attachment );
-}
-
-/**
- * Ajax handler for saving the attachment order.
- *
- * @since 3.5.0
- */
-function wp_ajax_save_attachment_order() {
- if ( ! isset( $_REQUEST['post_id'] ) ) {
- wp_send_json_error();
- }
-
- $post_id = absint( $_REQUEST['post_id'] );
- if ( ! $post_id ) {
- wp_send_json_error();
- }
-
- if ( empty( $_REQUEST['attachments'] ) ) {
- wp_send_json_error();
- }
-
- check_ajax_referer( 'update-post_' . $post_id, 'nonce' );
-
- $attachments = $_REQUEST['attachments'];
-
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
- wp_send_json_error();
- }
-
- foreach ( $attachments as $attachment_id => $menu_order ) {
- if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
- continue;
- }
-
- $attachment = get_post( $attachment_id );
-
- if ( ! $attachment ) {
- continue;
- }
-
- if ( 'attachment' != $attachment->post_type ) {
- continue;
- }
-
- wp_update_post(
- array(
- 'ID' => $attachment_id,
- 'menu_order' => $menu_order,
- )
- );
- }
-
- wp_send_json_success();
-}
-
-/**
- * Ajax handler for sending an attachment to the editor.
- *
- * Generates the HTML to send an attachment to the editor.
- * Backward compatible with the {@see 'media_send_to_editor'} filter
- * and the chain of filters that follow.
- *
- * @since 3.5.0
- */
-function wp_ajax_send_attachment_to_editor() {
- check_ajax_referer( 'media-send-to-editor', 'nonce' );
-
- $attachment = wp_unslash( $_POST['attachment'] );
-
- $id = intval( $attachment['id'] );
-
- $post = get_post( $id );
- if ( ! $post ) {
- wp_send_json_error();
- }
-
- if ( 'attachment' != $post->post_type ) {
- wp_send_json_error();
- }
-
- if ( current_user_can( 'edit_post', $id ) ) {
- // If this attachment is unattached, attach it. Primarily a back compat thing.
- $insert_into_post_id = intval( $_POST['post_id'] );
-
- if ( 0 == $post->post_parent && $insert_into_post_id ) {
- wp_update_post(
- array(
- 'ID' => $id,
- 'post_parent' => $insert_into_post_id,
- )
- );
- }
- }
-
- $url = empty( $attachment['url'] ) ? '' : $attachment['url'];
- $rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $id ) == $url );
-
- remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' );
-
- if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
- $align = isset( $attachment['align'] ) ? $attachment['align'] : 'none';
- $size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
- $alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
-
- // No whitespace-only captions.
- $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : '';
- if ( '' === trim( $caption ) ) {
- $caption = '';
- }
-
- $title = ''; // We no longer insert title tags into tags, as they are redundant.
- $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt );
- } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) {
- $html = stripslashes_deep( $_POST['html'] );
- } else {
- $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
- $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized
-
- if ( ! empty( $url ) ) {
- $html = '' . $html . ' ';
- }
- }
-
- /** This filter is documented in wp-admin/includes/media.php */
- $html = apply_filters( 'media_send_to_editor', $html, $id, $attachment );
-
- wp_send_json_success( $html );
-}
-
-/**
- * Ajax handler for sending a link to the editor.
- *
- * Generates the HTML to send a non-image embed link to the editor.
- *
- * Backward compatible with the following filters:
- * - file_send_to_editor_url
- * - audio_send_to_editor_url
- * - video_send_to_editor_url
- *
- * @since 3.5.0
- *
- * @global WP_Post $post Global post object.
- * @global WP_Embed $wp_embed
- */
-function wp_ajax_send_link_to_editor() {
- global $post, $wp_embed;
-
- check_ajax_referer( 'media-send-to-editor', 'nonce' );
-
- $src = wp_unslash( $_POST['src'] );
- if ( ! $src ) {
- wp_send_json_error();
- }
-
- if ( ! strpos( $src, '://' ) ) {
- $src = 'http://' . $src;
- }
-
- $src = esc_url_raw( $src );
- if ( ! $src ) {
- wp_send_json_error();
- }
-
- $link_text = trim( wp_unslash( $_POST['link_text'] ) );
- if ( ! $link_text ) {
- $link_text = wp_basename( $src );
- }
-
- $post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 );
-
- // Ping WordPress for an embed.
- $check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' );
-
- // Fallback that WordPress creates when no oEmbed was found.
- $fallback = $wp_embed->maybe_make_link( $src );
-
- if ( $check_embed !== $fallback ) {
- // TinyMCE view for [embed] will parse this
- $html = '[embed]' . $src . '[/embed]';
- } elseif ( $link_text ) {
- $html = '' . $link_text . ' ';
- } else {
- $html = '';
- }
-
- // Figure out what filter to run:
- $type = 'file';
- $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src );
- if ( $ext ) {
- $ext_type = wp_ext2type( $ext );
- if ( 'audio' == $ext_type || 'video' == $ext_type ) {
- $type = $ext_type;
- }
- }
-
- /** This filter is documented in wp-admin/includes/media.php */
- $html = apply_filters( "{$type}_send_to_editor_url", $html, $src, $link_text );
-
- wp_send_json_success( $html );
-}
-
-/**
- * Ajax handler for the Heartbeat API.
- *
- * Runs when the user is logged in.
- *
- * @since 3.6.0
- */
-function wp_ajax_heartbeat() {
- if ( empty( $_POST['_nonce'] ) ) {
- wp_send_json_error();
- }
-
- $response = array();
- $data = array();
- $nonce_state = wp_verify_nonce( $_POST['_nonce'], 'heartbeat-nonce' );
-
- // screen_id is the same as $current_screen->id and the JS global 'pagenow'.
- if ( ! empty( $_POST['screen_id'] ) ) {
- $screen_id = sanitize_key( $_POST['screen_id'] );
- } else {
- $screen_id = 'front';
- }
-
- if ( ! empty( $_POST['data'] ) ) {
- $data = wp_unslash( (array) $_POST['data'] );
- }
-
- if ( 1 !== $nonce_state ) {
- /**
- * Filters the nonces to send to the New/Edit Post screen.
- *
- * @since 4.3.0
- *
- * @param array $response The Heartbeat response.
- * @param array $data The $_POST data sent.
- * @param string $screen_id The screen id.
- */
- $response = apply_filters( 'wp_refresh_nonces', $response, $data, $screen_id );
-
- if ( false === $nonce_state ) {
- // User is logged in but nonces have expired.
- $response['nonces_expired'] = true;
- wp_send_json( $response );
- }
- }
-
- if ( ! empty( $data ) ) {
- /**
- * Filters the Heartbeat response received.
- *
- * @since 3.6.0
- *
- * @param array $response The Heartbeat response.
- * @param array $data The $_POST data sent.
- * @param string $screen_id The screen id.
- */
- $response = apply_filters( 'heartbeat_received', $response, $data, $screen_id );
- }
-
- /**
- * Filters the Heartbeat response sent.
- *
- * @since 3.6.0
- *
- * @param array $response The Heartbeat response.
- * @param string $screen_id The screen id.
- */
- $response = apply_filters( 'heartbeat_send', $response, $screen_id );
-
- /**
- * Fires when Heartbeat ticks in logged-in environments.
- *
- * Allows the transport to be easily replaced with long-polling.
- *
- * @since 3.6.0
- *
- * @param array $response The Heartbeat response.
- * @param string $screen_id The screen id.
- */
- do_action( 'heartbeat_tick', $response, $screen_id );
-
- // Send the current time according to the server
- $response['server_time'] = time();
-
- wp_send_json( $response );
-}
-
-/**
- * Ajax handler for getting revision diffs.
- *
- * @since 3.6.0
- */
-function wp_ajax_get_revision_diffs() {
- require ABSPATH . 'wp-admin/includes/revision.php';
-
- $post = get_post( (int) $_REQUEST['post_id'] );
- if ( ! $post ) {
- wp_send_json_error();
- }
-
- if ( ! current_user_can( 'edit_post', $post->ID ) ) {
- wp_send_json_error();
- }
-
- // Really just pre-loading the cache here.
- $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) );
- if ( ! $revisions ) {
- wp_send_json_error();
- }
-
- $return = array();
- set_time_limit( 0 );
-
- foreach ( $_REQUEST['compare'] as $compare_key ) {
- list( $compare_from, $compare_to ) = explode( ':', $compare_key ); // from:to
-
- $return[] = array(
- 'id' => $compare_key,
- 'fields' => wp_get_revision_ui_diff( $post, $compare_from, $compare_to ),
- );
- }
- wp_send_json_success( $return );
-}
-
-/**
- * Ajax handler for auto-saving the selected color scheme for
- * a user's own profile.
- *
- * @since 3.8.0
- *
- * @global array $_wp_admin_css_colors
- */
-function wp_ajax_save_user_color_scheme() {
- global $_wp_admin_css_colors;
-
- check_ajax_referer( 'save-color-scheme', 'nonce' );
-
- $color_scheme = sanitize_key( $_POST['color_scheme'] );
-
- if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
- wp_send_json_error();
- }
-
- $previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true );
- update_user_meta( get_current_user_id(), 'admin_color', $color_scheme );
-
- wp_send_json_success(
- array(
- 'previousScheme' => 'admin-color-' . $previous_color_scheme,
- 'currentScheme' => 'admin-color-' . $color_scheme,
- )
- );
-}
-
-/**
- * Ajax handler for getting themes from themes_api().
- *
- * @since 3.9.0
- *
- * @global array $themes_allowedtags
- * @global array $theme_field_defaults
- */
-function wp_ajax_query_themes() {
- global $themes_allowedtags, $theme_field_defaults;
-
- if ( ! current_user_can( 'install_themes' ) ) {
- wp_send_json_error();
- }
-
- $args = wp_parse_args(
- wp_unslash( $_REQUEST['request'] ),
- array(
- 'per_page' => 20,
- 'fields' => array_merge(
- (array) $theme_field_defaults,
- array(
- 'reviews_url' => true, // Explicitly request the reviews URL to be linked from the Add Themes screen.
- )
- ),
- )
- );
-
- if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) {
- $user = get_user_option( 'wporg_favorites' );
- if ( $user ) {
- $args['user'] = $user;
- }
- }
-
- $old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search';
-
- /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */
- $args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args );
-
- $api = themes_api( 'query_themes', $args );
-
- if ( is_wp_error( $api ) ) {
- wp_send_json_error();
- }
-
- $update_php = network_admin_url( 'update.php?action=install-theme' );
-
- foreach ( $api->themes as &$theme ) {
- $theme->install_url = add_query_arg(
- array(
- 'theme' => $theme->slug,
- '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ),
- ),
- $update_php
- );
-
- if ( current_user_can( 'switch_themes' ) ) {
- if ( is_multisite() ) {
- $theme->activate_url = add_query_arg(
- array(
- 'action' => 'enable',
- '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ),
- 'theme' => $theme->slug,
- ),
- network_admin_url( 'themes.php' )
- );
- } else {
- $theme->activate_url = add_query_arg(
- array(
- 'action' => 'activate',
- '_wpnonce' => wp_create_nonce( 'switch-theme_' . $theme->slug ),
- 'stylesheet' => $theme->slug,
- ),
- admin_url( 'themes.php' )
- );
- }
- }
-
- if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
- $theme->customize_url = add_query_arg(
- array(
- 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
- ),
- wp_customize_url( $theme->slug )
- );
- }
-
- $theme->name = wp_kses( $theme->name, $themes_allowedtags );
- $theme->author = wp_kses( $theme->author['display_name'], $themes_allowedtags );
- $theme->version = wp_kses( $theme->version, $themes_allowedtags );
- $theme->description = wp_kses( $theme->description, $themes_allowedtags );
-
- $theme->stars = wp_star_rating(
- array(
- 'rating' => $theme->rating,
- 'type' => 'percent',
- 'number' => $theme->num_ratings,
- 'echo' => false,
- )
- );
-
- $theme->num_ratings = number_format_i18n( $theme->num_ratings );
- $theme->preview_url = set_url_scheme( $theme->preview_url );
- }
-
- wp_send_json_success( $api );
-}
-
-/**
- * Apply [embed] Ajax handlers to a string.
- *
- * @since 4.0.0
- *
- * @global WP_Post $post Global post object.
- * @global WP_Embed $wp_embed Embed API instance.
- * @global WP_Scripts $wp_scripts
- * @global int $content_width
- */
-function wp_ajax_parse_embed() {
- global $post, $wp_embed, $content_width;
-
- if ( empty( $_POST['shortcode'] ) ) {
- wp_send_json_error();
- }
-
- $post_id = isset( $_POST['post_ID'] ) ? intval( $_POST['post_ID'] ) : 0;
-
- if ( $post_id > 0 ) {
- $post = get_post( $post_id );
-
- if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
- wp_send_json_error();
- }
- setup_postdata( $post );
- } elseif ( ! current_user_can( 'edit_posts' ) ) { // See WP_oEmbed_Controller::get_proxy_item_permissions_check().
- wp_send_json_error();
- }
-
- $shortcode = wp_unslash( $_POST['shortcode'] );
-
- preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches );
- $atts = shortcode_parse_atts( $matches[3] );
-
- if ( ! empty( $matches[5] ) ) {
- $url = $matches[5];
- } elseif ( ! empty( $atts['src'] ) ) {
- $url = $atts['src'];
- } else {
- $url = '';
- }
-
- $parsed = false;
- $wp_embed->return_false_on_fail = true;
-
- if ( 0 === $post_id ) {
- /*
- * Refresh oEmbeds cached outside of posts that are past their TTL.
- * Posts are excluded because they have separate logic for refreshing
- * their post meta caches. See WP_Embed::cache_oembed().
- */
- $wp_embed->usecache = false;
- }
-
- if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) {
- // Admin is ssl and the user pasted non-ssl URL.
- // Check if the provider supports ssl embeds and use that for the preview.
- $ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode );
- $parsed = $wp_embed->run_shortcode( $ssl_shortcode );
-
- if ( ! $parsed ) {
- $no_ssl_support = true;
- }
- }
-
- // Set $content_width so any embeds fit in the destination iframe.
- if ( isset( $_POST['maxwidth'] ) && is_numeric( $_POST['maxwidth'] ) && $_POST['maxwidth'] > 0 ) {
- if ( ! isset( $content_width ) ) {
- $content_width = intval( $_POST['maxwidth'] );
- } else {
- $content_width = min( $content_width, intval( $_POST['maxwidth'] ) );
- }
- }
-
- if ( $url && ! $parsed ) {
- $parsed = $wp_embed->run_shortcode( $shortcode );
- }
-
- if ( ! $parsed ) {
- wp_send_json_error(
- array(
- 'type' => 'not-embeddable',
- /* translators: %s: URL that could not be embedded. */
- 'message' => sprintf( __( '%s failed to embed.' ), '' . esc_html( $url ) . '' ),
- )
- );
- }
-
- if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) {
- $styles = '';
- $mce_styles = wpview_media_sandbox_styles();
-
- foreach ( $mce_styles as $style ) {
- $styles .= sprintf( ' ', $style );
- }
-
- $html = do_shortcode( $parsed );
-
- global $wp_scripts;
-
- if ( ! empty( $wp_scripts ) ) {
- $wp_scripts->done = array();
- }
-
- ob_start();
- wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) );
- $scripts = ob_get_clean();
-
- $parsed = $styles . $html . $scripts;
- }
-
- if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) ||
- preg_match( '% ]*href="http://%', $parsed ) ) ) ) {
- // Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked.
- wp_send_json_error(
- array(
- 'type' => 'not-ssl',
- 'message' => __( 'This preview is unavailable in the editor.' ),
- )
- );
- }
-
- $return = array(
- 'body' => $parsed,
- 'attr' => $wp_embed->last_attr,
- );
-
- if ( strpos( $parsed, 'class="wp-embedded-content' ) ) {
- if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
- $script_src = includes_url( 'js/wp-embed.js' );
- } else {
- $script_src = includes_url( 'js/wp-embed.min.js' );
- }
-
- $return['head'] = '';
- $return['sandbox'] = true;
- }
-
- wp_send_json_success( $return );
-}
-
-/**
- * @since 4.0.0
- *
- * @global WP_Post $post Global post object.
- * @global WP_Scripts $wp_scripts
- */
-function wp_ajax_parse_media_shortcode() {
- global $post, $wp_scripts;
-
- if ( empty( $_POST['shortcode'] ) ) {
- wp_send_json_error();
- }
-
- $shortcode = wp_unslash( $_POST['shortcode'] );
-
- if ( ! empty( $_POST['post_ID'] ) ) {
- $post = get_post( (int) $_POST['post_ID'] );
- }
-
- // the embed shortcode requires a post
- if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
- if ( 'embed' === $shortcode ) {
- wp_send_json_error();
- }
- } else {
- setup_postdata( $post );
- }
-
- $parsed = do_shortcode( $shortcode );
-
- if ( empty( $parsed ) ) {
- wp_send_json_error(
- array(
- 'type' => 'no-items',
- 'message' => __( 'No items found.' ),
- )
- );
- }
-
- $head = '';
- $styles = wpview_media_sandbox_styles();
-
- foreach ( $styles as $style ) {
- $head .= ' ';
- }
-
- if ( ! empty( $wp_scripts ) ) {
- $wp_scripts->done = array();
- }
-
- ob_start();
-
- echo $parsed;
-
- if ( 'playlist' === $_REQUEST['type'] ) {
- wp_underscore_playlist_templates();
-
- wp_print_scripts( 'wp-playlist' );
- } else {
- wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) );
- }
-
- wp_send_json_success(
- array(
- 'head' => $head,
- 'body' => ob_get_clean(),
- )
- );
-}
-
-/**
- * Ajax handler for destroying multiple open sessions for a user.
- *
- * @since 4.1.0
- */
-function wp_ajax_destroy_sessions() {
- $user = get_userdata( (int) $_POST['user_id'] );
-
- if ( $user ) {
- if ( ! current_user_can( 'edit_user', $user->ID ) ) {
- $user = false;
- } elseif ( ! wp_verify_nonce( $_POST['nonce'], 'update-user_' . $user->ID ) ) {
- $user = false;
- }
- }
-
- if ( ! $user ) {
- wp_send_json_error(
- array(
- 'message' => __( 'Could not log out user sessions. Please try again.' ),
- )
- );
- }
-
- $sessions = WP_Session_Tokens::get_instance( $user->ID );
-
- if ( $user->ID === get_current_user_id() ) {
- $sessions->destroy_others( wp_get_session_token() );
- $message = __( 'You are now logged out everywhere else.' );
- } else {
- $sessions->destroy_all();
- /* translators: %s: User's display name. */
- $message = sprintf( __( '%s has been logged out.' ), $user->display_name );
- }
-
- wp_send_json_success( array( 'message' => $message ) );
-}
-
-/**
- * Ajax handler for cropping an image.
- *
- * @since 4.3.0
- */
-function wp_ajax_crop_image() {
- $attachment_id = absint( $_POST['id'] );
-
- check_ajax_referer( 'image_editor-' . $attachment_id, 'nonce' );
-
- if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
- wp_send_json_error();
- }
-
- $context = str_replace( '_', '-', $_POST['context'] );
- $data = array_map( 'absint', $_POST['cropDetails'] );
- $cropped = wp_crop_image( $attachment_id, $data['x1'], $data['y1'], $data['width'], $data['height'], $data['dst_width'], $data['dst_height'] );
-
- if ( ! $cropped || is_wp_error( $cropped ) ) {
- wp_send_json_error( array( 'message' => __( 'Image could not be processed.' ) ) );
- }
-
- switch ( $context ) {
- case 'site-icon':
- require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php';
- $wp_site_icon = new WP_Site_Icon();
-
- // Skip creating a new attachment if the attachment is a Site Icon.
- if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) {
-
- // Delete the temporary cropped file, we don't need it.
- wp_delete_file( $cropped );
-
- // Additional sizes in wp_prepare_attachment_for_js().
- add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
- break;
- }
-
- /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
- $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
- $object = $wp_site_icon->create_attachment_object( $cropped, $attachment_id );
- unset( $object['ID'] );
-
- // Update the attachment.
- add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
- $attachment_id = $wp_site_icon->insert_attachment( $object, $cropped );
- remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
-
- // Additional sizes in wp_prepare_attachment_for_js().
- add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
- break;
-
- default:
- /**
- * Fires before a cropped image is saved.
- *
- * Allows to add filters to modify the way a cropped image is saved.
- *
- * @since 4.3.0
- *
- * @param string $context The Customizer control requesting the cropped image.
- * @param int $attachment_id The attachment ID of the original image.
- * @param string $cropped Path to the cropped image file.
- */
- do_action( 'wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped );
-
- /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
- $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
-
- $parent_url = wp_get_attachment_url( $attachment_id );
- $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
-
- $size = @getimagesize( $cropped );
- $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
-
- $object = array(
- 'post_title' => wp_basename( $cropped ),
- 'post_content' => $url,
- 'post_mime_type' => $image_type,
- 'guid' => $url,
- 'context' => $context,
- );
-
- $attachment_id = wp_insert_attachment( $object, $cropped );
- $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
-
- /**
- * Filters the cropped image attachment metadata.
- *
- * @since 4.3.0
- *
- * @see wp_generate_attachment_metadata()
- *
- * @param array $metadata Attachment metadata.
- */
- $metadata = apply_filters( 'wp_ajax_cropped_attachment_metadata', $metadata );
- wp_update_attachment_metadata( $attachment_id, $metadata );
-
- /**
- * Filters the attachment ID for a cropped image.
- *
- * @since 4.3.0
- *
- * @param int $attachment_id The attachment ID of the cropped image.
- * @param string $context The Customizer control requesting the cropped image.
- */
- $attachment_id = apply_filters( 'wp_ajax_cropped_attachment_id', $attachment_id, $context );
- }
-
- wp_send_json_success( wp_prepare_attachment_for_js( $attachment_id ) );
-}
-
-/**
- * Ajax handler for generating a password.
- *
- * @since 4.4.0
- */
-function wp_ajax_generate_password() {
- wp_send_json_success( wp_generate_password( 24 ) );
-}
-
-/**
- * Ajax handler for saving the user's WordPress.org username.
- *
- * @since 4.4.0
- */
-function wp_ajax_save_wporg_username() {
- if ( ! current_user_can( 'install_themes' ) && ! current_user_can( 'install_plugins' ) ) {
- wp_send_json_error();
- }
-
- check_ajax_referer( 'save_wporg_username_' . get_current_user_id() );
-
- $username = isset( $_REQUEST['username'] ) ? wp_unslash( $_REQUEST['username'] ) : false;
-
- if ( ! $username ) {
- wp_send_json_error();
- }
-
- wp_send_json_success( update_user_meta( get_current_user_id(), 'wporg_favorites', $username ) );
-}
-
-/**
- * Ajax handler for installing a theme.
- *
- * @since 4.6.0
- *
- * @see Theme_Upgrader
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- */
-function wp_ajax_install_theme() {
- check_ajax_referer( 'updates' );
-
- if ( empty( $_POST['slug'] ) ) {
- wp_send_json_error(
- array(
- 'slug' => '',
- 'errorCode' => 'no_theme_specified',
- 'errorMessage' => __( 'No theme specified.' ),
- )
- );
- }
-
- $slug = sanitize_key( wp_unslash( $_POST['slug'] ) );
-
- $status = array(
- 'install' => 'theme',
- 'slug' => $slug,
- );
-
- if ( ! current_user_can( 'install_themes' ) ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to install themes on this site.' );
- wp_send_json_error( $status );
- }
-
- include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
- include_once( ABSPATH . 'wp-admin/includes/theme.php' );
-
- $api = themes_api(
- 'theme_information',
- array(
- 'slug' => $slug,
- 'fields' => array( 'sections' => false ),
- )
- );
-
- if ( is_wp_error( $api ) ) {
- $status['errorMessage'] = $api->get_error_message();
- wp_send_json_error( $status );
- }
-
- $skin = new WP_Ajax_Upgrader_Skin();
- $upgrader = new Theme_Upgrader( $skin );
- $result = $upgrader->install( $api->download_link );
-
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
- $status['debug'] = $skin->get_upgrade_messages();
- }
-
- if ( is_wp_error( $result ) ) {
- $status['errorCode'] = $result->get_error_code();
- $status['errorMessage'] = $result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( is_wp_error( $skin->result ) ) {
- $status['errorCode'] = $skin->result->get_error_code();
- $status['errorMessage'] = $skin->result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( $skin->get_errors()->has_errors() ) {
- $status['errorMessage'] = $skin->get_error_messages();
- wp_send_json_error( $status );
- } elseif ( is_null( $result ) ) {
- global $wp_filesystem;
-
- $status['errorCode'] = 'unable_to_connect_to_filesystem';
- $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
-
- // Pass through the error from WP_Filesystem if one was raised.
- if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
- $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
- }
-
- wp_send_json_error( $status );
- }
-
- $status['themeName'] = wp_get_theme( $slug )->get( 'Name' );
-
- if ( current_user_can( 'switch_themes' ) ) {
- if ( is_multisite() ) {
- $status['activateUrl'] = add_query_arg(
- array(
- 'action' => 'enable',
- '_wpnonce' => wp_create_nonce( 'enable-theme_' . $slug ),
- 'theme' => $slug,
- ),
- network_admin_url( 'themes.php' )
- );
- } else {
- $status['activateUrl'] = add_query_arg(
- array(
- 'action' => 'activate',
- '_wpnonce' => wp_create_nonce( 'switch-theme_' . $slug ),
- 'stylesheet' => $slug,
- ),
- admin_url( 'themes.php' )
- );
- }
- }
-
- if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
- $status['customizeUrl'] = add_query_arg(
- array(
- 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
- ),
- wp_customize_url( $slug )
- );
- }
-
- /*
- * See WP_Theme_Install_List_Table::_get_theme_status() if we wanted to check
- * on post-installation status.
- */
- wp_send_json_success( $status );
-}
-
-/**
- * Ajax handler for updating a theme.
- *
- * @since 4.6.0
- *
- * @see Theme_Upgrader
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- */
-function wp_ajax_update_theme() {
- check_ajax_referer( 'updates' );
-
- if ( empty( $_POST['slug'] ) ) {
- wp_send_json_error(
- array(
- 'slug' => '',
- 'errorCode' => 'no_theme_specified',
- 'errorMessage' => __( 'No theme specified.' ),
- )
- );
- }
-
- $stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) );
- $status = array(
- 'update' => 'theme',
- 'slug' => $stylesheet,
- 'oldVersion' => '',
- 'newVersion' => '',
- );
-
- if ( ! current_user_can( 'update_themes' ) ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to update themes for this site.' );
- wp_send_json_error( $status );
- }
-
- $theme = wp_get_theme( $stylesheet );
- if ( $theme->exists() ) {
- $status['oldVersion'] = $theme->get( 'Version' );
- }
-
- include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
-
- $current = get_site_transient( 'update_themes' );
- if ( empty( $current ) ) {
- wp_update_themes();
- }
-
- $skin = new WP_Ajax_Upgrader_Skin();
- $upgrader = new Theme_Upgrader( $skin );
- $result = $upgrader->bulk_upgrade( array( $stylesheet ) );
-
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
- $status['debug'] = $skin->get_upgrade_messages();
- }
-
- if ( is_wp_error( $skin->result ) ) {
- $status['errorCode'] = $skin->result->get_error_code();
- $status['errorMessage'] = $skin->result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( $skin->get_errors()->has_errors() ) {
- $status['errorMessage'] = $skin->get_error_messages();
- wp_send_json_error( $status );
- } elseif ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) {
-
- // Theme is already at the latest version.
- if ( true === $result[ $stylesheet ] ) {
- $status['errorMessage'] = $upgrader->strings['up_to_date'];
- wp_send_json_error( $status );
- }
-
- $theme = wp_get_theme( $stylesheet );
- if ( $theme->exists() ) {
- $status['newVersion'] = $theme->get( 'Version' );
- }
-
- wp_send_json_success( $status );
- } elseif ( false === $result ) {
- global $wp_filesystem;
-
- $status['errorCode'] = 'unable_to_connect_to_filesystem';
- $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
-
- // Pass through the error from WP_Filesystem if one was raised.
- if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
- $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
- }
-
- wp_send_json_error( $status );
- }
-
- // An unhandled error occurred.
- $status['errorMessage'] = __( 'Update failed.' );
- wp_send_json_error( $status );
-}
-
-/**
- * Ajax handler for deleting a theme.
- *
- * @since 4.6.0
- *
- * @see delete_theme()
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- */
-function wp_ajax_delete_theme() {
- check_ajax_referer( 'updates' );
-
- if ( empty( $_POST['slug'] ) ) {
- wp_send_json_error(
- array(
- 'slug' => '',
- 'errorCode' => 'no_theme_specified',
- 'errorMessage' => __( 'No theme specified.' ),
- )
- );
- }
-
- $stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) );
- $status = array(
- 'delete' => 'theme',
- 'slug' => $stylesheet,
- );
-
- if ( ! current_user_can( 'delete_themes' ) ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to delete themes on this site.' );
- wp_send_json_error( $status );
- }
-
- if ( ! wp_get_theme( $stylesheet )->exists() ) {
- $status['errorMessage'] = __( 'The requested theme does not exist.' );
- wp_send_json_error( $status );
- }
-
- // Check filesystem credentials. `delete_theme()` will bail otherwise.
- $url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
-
- ob_start();
- $credentials = request_filesystem_credentials( $url );
- ob_end_clean();
-
- if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
- global $wp_filesystem;
-
- $status['errorCode'] = 'unable_to_connect_to_filesystem';
- $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
-
- // Pass through the error from WP_Filesystem if one was raised.
- if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
- $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
- }
-
- wp_send_json_error( $status );
- }
-
- include_once( ABSPATH . 'wp-admin/includes/theme.php' );
-
- $result = delete_theme( $stylesheet );
-
- if ( is_wp_error( $result ) ) {
- $status['errorMessage'] = $result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( false === $result ) {
- $status['errorMessage'] = __( 'Theme could not be deleted.' );
- wp_send_json_error( $status );
- }
-
- wp_send_json_success( $status );
-}
-
-/**
- * Ajax handler for installing a plugin.
- *
- * @since 4.6.0
- *
- * @see Plugin_Upgrader
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- */
-function wp_ajax_install_plugin() {
- check_ajax_referer( 'updates' );
-
- if ( empty( $_POST['slug'] ) ) {
- wp_send_json_error(
- array(
- 'slug' => '',
- 'errorCode' => 'no_plugin_specified',
- 'errorMessage' => __( 'No plugin specified.' ),
- )
- );
- }
-
- $status = array(
- 'install' => 'plugin',
- 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
- );
-
- if ( ! current_user_can( 'install_plugins' ) ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to install plugins on this site.' );
- wp_send_json_error( $status );
- }
-
- include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
- include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
-
- $api = plugins_api(
- 'plugin_information',
- array(
- 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
- 'fields' => array(
- 'sections' => false,
- ),
- )
- );
-
- if ( is_wp_error( $api ) ) {
- $status['errorMessage'] = $api->get_error_message();
- wp_send_json_error( $status );
- }
-
- $status['pluginName'] = $api->name;
-
- $skin = new WP_Ajax_Upgrader_Skin();
- $upgrader = new Plugin_Upgrader( $skin );
- $result = $upgrader->install( $api->download_link );
-
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
- $status['debug'] = $skin->get_upgrade_messages();
- }
-
- if ( is_wp_error( $result ) ) {
- $status['errorCode'] = $result->get_error_code();
- $status['errorMessage'] = $result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( is_wp_error( $skin->result ) ) {
- $status['errorCode'] = $skin->result->get_error_code();
- $status['errorMessage'] = $skin->result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( $skin->get_errors()->has_errors() ) {
- $status['errorMessage'] = $skin->get_error_messages();
- wp_send_json_error( $status );
- } elseif ( is_null( $result ) ) {
- global $wp_filesystem;
-
- $status['errorCode'] = 'unable_to_connect_to_filesystem';
- $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
-
- // Pass through the error from WP_Filesystem if one was raised.
- if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
- $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
- }
-
- wp_send_json_error( $status );
- }
-
- $install_status = install_plugin_install_status( $api );
- $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
-
- // If installation request is coming from import page, do not return network activation link.
- $plugins_url = ( 'import' === $pagenow ) ? admin_url( 'plugins.php' ) : network_admin_url( 'plugins.php' );
-
- if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) {
- $status['activateUrl'] = add_query_arg(
- array(
- '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ),
- 'action' => 'activate',
- 'plugin' => $install_status['file'],
- ),
- $plugins_url
- );
- }
-
- if ( is_multisite() && current_user_can( 'manage_network_plugins' ) && 'import' !== $pagenow ) {
- $status['activateUrl'] = add_query_arg( array( 'networkwide' => 1 ), $status['activateUrl'] );
- }
-
- wp_send_json_success( $status );
-}
-
-/**
- * Ajax handler for updating a plugin.
- *
- * @since 4.2.0
- *
- * @see Plugin_Upgrader
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- */
-function wp_ajax_update_plugin() {
- check_ajax_referer( 'updates' );
-
- if ( empty( $_POST['plugin'] ) || empty( $_POST['slug'] ) ) {
- wp_send_json_error(
- array(
- 'slug' => '',
- 'errorCode' => 'no_plugin_specified',
- 'errorMessage' => __( 'No plugin specified.' ),
- )
- );
- }
-
- $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) );
-
- $status = array(
- 'update' => 'plugin',
- 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
- 'oldVersion' => '',
- 'newVersion' => '',
- );
-
- if ( ! current_user_can( 'update_plugins' ) || 0 !== validate_file( $plugin ) ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to update plugins for this site.' );
- wp_send_json_error( $status );
- }
-
- $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
- $status['plugin'] = $plugin;
- $status['pluginName'] = $plugin_data['Name'];
-
- if ( $plugin_data['Version'] ) {
- /* translators: %s: Plugin version. */
- $status['oldVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
- }
-
- include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
-
- wp_update_plugins();
-
- $skin = new WP_Ajax_Upgrader_Skin();
- $upgrader = new Plugin_Upgrader( $skin );
- $result = $upgrader->bulk_upgrade( array( $plugin ) );
-
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
- $status['debug'] = $skin->get_upgrade_messages();
- }
-
- if ( is_wp_error( $skin->result ) ) {
- $status['errorCode'] = $skin->result->get_error_code();
- $status['errorMessage'] = $skin->result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( $skin->get_errors()->has_errors() ) {
- $status['errorMessage'] = $skin->get_error_messages();
- wp_send_json_error( $status );
- } elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) {
- $plugin_update_data = current( $result );
-
- /*
- * If the `update_plugins` site transient is empty (e.g. when you update
- * two plugins in quick succession before the transient repopulates),
- * this may be the return.
- *
- * Preferably something can be done to ensure `update_plugins` isn't empty.
- * For now, surface some sort of error here.
- */
- if ( true === $plugin_update_data ) {
- $status['errorMessage'] = __( 'Plugin update failed.' );
- wp_send_json_error( $status );
- }
-
- $plugin_data = get_plugins( '/' . $result[ $plugin ]['destination_name'] );
- $plugin_data = reset( $plugin_data );
-
- if ( $plugin_data['Version'] ) {
- /* translators: %s: Plugin version. */
- $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
- }
- wp_send_json_success( $status );
- } elseif ( false === $result ) {
- global $wp_filesystem;
-
- $status['errorCode'] = 'unable_to_connect_to_filesystem';
- $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
-
- // Pass through the error from WP_Filesystem if one was raised.
- if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
- $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
- }
-
- wp_send_json_error( $status );
- }
-
- // An unhandled error occurred.
- $status['errorMessage'] = __( 'Plugin update failed.' );
- wp_send_json_error( $status );
-}
-
-/**
- * Ajax handler for deleting a plugin.
- *
- * @since 4.6.0
- *
- * @see delete_plugins()
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- */
-function wp_ajax_delete_plugin() {
- check_ajax_referer( 'updates' );
-
- if ( empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
- wp_send_json_error(
- array(
- 'slug' => '',
- 'errorCode' => 'no_plugin_specified',
- 'errorMessage' => __( 'No plugin specified.' ),
- )
- );
- }
-
- $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) );
-
- $status = array(
- 'delete' => 'plugin',
- 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
- );
-
- if ( ! current_user_can( 'delete_plugins' ) || 0 !== validate_file( $plugin ) ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to delete plugins for this site.' );
- wp_send_json_error( $status );
- }
-
- $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
- $status['plugin'] = $plugin;
- $status['pluginName'] = $plugin_data['Name'];
-
- if ( is_plugin_active( $plugin ) ) {
- $status['errorMessage'] = __( 'You cannot delete a plugin while it is active on the main site.' );
- wp_send_json_error( $status );
- }
-
- // Check filesystem credentials. `delete_plugins()` will bail otherwise.
- $url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' );
-
- ob_start();
- $credentials = request_filesystem_credentials( $url );
- ob_end_clean();
-
- if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
- global $wp_filesystem;
-
- $status['errorCode'] = 'unable_to_connect_to_filesystem';
- $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
-
- // Pass through the error from WP_Filesystem if one was raised.
- if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
- $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
- }
-
- wp_send_json_error( $status );
- }
-
- $result = delete_plugins( array( $plugin ) );
-
- if ( is_wp_error( $result ) ) {
- $status['errorMessage'] = $result->get_error_message();
- wp_send_json_error( $status );
- } elseif ( false === $result ) {
- $status['errorMessage'] = __( 'Plugin could not be deleted.' );
- wp_send_json_error( $status );
- }
-
- wp_send_json_success( $status );
-}
-
-/**
- * Ajax handler for searching plugins.
- *
- * @since 4.6.0
- *
- * @global string $s Search term.
- */
-function wp_ajax_search_plugins() {
- check_ajax_referer( 'updates' );
-
- $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
- if ( 'plugins-network' === $pagenow || 'plugins' === $pagenow ) {
- set_current_screen( $pagenow );
- }
-
- /** @var WP_Plugins_List_Table $wp_list_table */
- $wp_list_table = _get_list_table(
- 'WP_Plugins_List_Table',
- array(
- 'screen' => get_current_screen(),
- )
- );
-
- $status = array();
-
- if ( ! $wp_list_table->ajax_user_can() ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to manage plugins for this site.' );
- wp_send_json_error( $status );
- }
-
- // Set the correct requester, so pagination works.
- $_SERVER['REQUEST_URI'] = add_query_arg(
- array_diff_key(
- $_POST,
- array(
- '_ajax_nonce' => null,
- 'action' => null,
- )
- ),
- network_admin_url( 'plugins.php', 'relative' )
- );
-
- $GLOBALS['s'] = wp_unslash( $_POST['s'] );
-
- $wp_list_table->prepare_items();
-
- ob_start();
- $wp_list_table->display();
- $status['count'] = count( $wp_list_table->items );
- $status['items'] = ob_get_clean();
-
- wp_send_json_success( $status );
-}
-
-/**
- * Ajax handler for searching plugins to install.
- *
- * @since 4.6.0
- */
-function wp_ajax_search_install_plugins() {
- check_ajax_referer( 'updates' );
-
- $pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
- if ( 'plugin-install-network' === $pagenow || 'plugin-install' === $pagenow ) {
- set_current_screen( $pagenow );
- }
-
- /** @var WP_Plugin_Install_List_Table $wp_list_table */
- $wp_list_table = _get_list_table(
- 'WP_Plugin_Install_List_Table',
- array(
- 'screen' => get_current_screen(),
- )
- );
-
- $status = array();
-
- if ( ! $wp_list_table->ajax_user_can() ) {
- $status['errorMessage'] = __( 'Sorry, you are not allowed to manage plugins for this site.' );
- wp_send_json_error( $status );
- }
-
- // Set the correct requester, so pagination works.
- $_SERVER['REQUEST_URI'] = add_query_arg(
- array_diff_key(
- $_POST,
- array(
- '_ajax_nonce' => null,
- 'action' => null,
- )
- ),
- network_admin_url( 'plugin-install.php', 'relative' )
- );
-
- $wp_list_table->prepare_items();
-
- ob_start();
- $wp_list_table->display();
- $status['count'] = (int) $wp_list_table->get_pagination_arg( 'total_items' );
- $status['items'] = ob_get_clean();
-
- wp_send_json_success( $status );
-}
-
-/**
- * Ajax handler for editing a theme or plugin file.
- *
- * @since 4.9.0
- * @see wp_edit_theme_plugin_file()
- */
-function wp_ajax_edit_theme_plugin_file() {
- $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().
-
- if ( is_wp_error( $r ) ) {
- wp_send_json_error(
- array_merge(
- array(
- 'code' => $r->get_error_code(),
- 'message' => $r->get_error_message(),
- ),
- (array) $r->get_error_data()
- )
- );
- } else {
- wp_send_json_success(
- array(
- 'message' => __( 'File edited successfully.' ),
- )
- );
- }
-}
-
-/**
- * Ajax handler for exporting a user's personal data.
- *
- * @since 4.9.6
- */
-function wp_ajax_wp_privacy_export_personal_data() {
-
- if ( empty( $_POST['id'] ) ) {
- wp_send_json_error( __( 'Missing request ID.' ) );
- }
-
- $request_id = (int) $_POST['id'];
-
- if ( $request_id < 1 ) {
- wp_send_json_error( __( 'Invalid request ID.' ) );
- }
-
- if ( ! current_user_can( 'export_others_personal_data' ) ) {
- wp_send_json_error( __( 'Sorry, you are not allowed to perform this action.' ) );
- }
-
- check_ajax_referer( 'wp-privacy-export-personal-data-' . $request_id, 'security' );
-
- // Get the request data.
- $request = wp_get_user_request_data( $request_id );
-
- if ( ! $request || 'export_personal_data' !== $request->action_name ) {
- wp_send_json_error( __( 'Invalid request type.' ) );
- }
-
- $email_address = $request->email;
- if ( ! is_email( $email_address ) ) {
- wp_send_json_error( __( 'A valid email address must be given.' ) );
- }
-
- if ( ! isset( $_POST['exporter'] ) ) {
- wp_send_json_error( __( 'Missing exporter index.' ) );
- }
-
- $exporter_index = (int) $_POST['exporter'];
-
- if ( ! isset( $_POST['page'] ) ) {
- wp_send_json_error( __( 'Missing page index.' ) );
- }
-
- $page = (int) $_POST['page'];
-
- $send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false;
-
- /**
- * Filters the array of exporter callbacks.
- *
- * @since 4.9.6
- *
- * @param array $args {
- * An array of callable exporters of personal data. Default empty array.
- *
- * @type array {
- * Array of personal data exporters.
- *
- * @type string $callback Callable exporter function that accepts an
- * email address and a page and returns an array
- * of name => value pairs of personal data.
- * @type string $exporter_friendly_name Translated user facing friendly name for the
- * exporter.
- * }
- * }
- */
- $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
-
- if ( ! is_array( $exporters ) ) {
- wp_send_json_error( __( 'An exporter has improperly used the registration filter.' ) );
- }
-
- // Do we have any registered exporters?
- if ( 0 < count( $exporters ) ) {
- if ( $exporter_index < 1 ) {
- wp_send_json_error( __( 'Exporter index cannot be negative.' ) );
- }
-
- if ( $exporter_index > count( $exporters ) ) {
- wp_send_json_error( __( 'Exporter index is out of range.' ) );
- }
-
- if ( $page < 1 ) {
- wp_send_json_error( __( 'Page index cannot be less than one.' ) );
- }
-
- $exporter_keys = array_keys( $exporters );
- $exporter_key = $exporter_keys[ $exporter_index - 1 ];
- $exporter = $exporters[ $exporter_key ];
-
- if ( ! is_array( $exporter ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter array index. */
- sprintf( __( 'Expected an array describing the exporter at index %s.' ), $exporter_key )
- );
- }
-
- if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter array index. */
- sprintf( __( 'Exporter array at index %s does not include a friendly name.' ), $exporter_key )
- );
- }
-
- $exporter_friendly_name = $exporter['exporter_friendly_name'];
-
- if ( ! array_key_exists( 'callback', $exporter ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter friendly name. */
- sprintf( __( 'Exporter does not include a callback: %s.' ), esc_html( $exporter_friendly_name ) )
- );
- }
-
- if ( ! is_callable( $exporter['callback'] ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter friendly name. */
- sprintf( __( 'Exporter callback is not a valid callback: %s.' ), esc_html( $exporter_friendly_name ) )
- );
- }
-
- $callback = $exporter['callback'];
- $response = call_user_func( $callback, $email_address, $page );
-
- if ( is_wp_error( $response ) ) {
- wp_send_json_error( $response );
- }
-
- if ( ! is_array( $response ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter friendly name. */
- sprintf( __( 'Expected response as an array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
- );
- }
-
- if ( ! array_key_exists( 'data', $response ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter friendly name. */
- sprintf( __( 'Expected data in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
- );
- }
-
- if ( ! is_array( $response['data'] ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter friendly name. */
- sprintf( __( 'Expected data array in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
- );
- }
-
- if ( ! array_key_exists( 'done', $response ) ) {
- wp_send_json_error(
- /* translators: %s: Exporter friendly name. */
- sprintf( __( 'Expected done (boolean) in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
- );
- }
- } else {
- // No exporters, so we're done.
- $exporter_key = '';
-
- $response = array(
- 'data' => array(),
- 'done' => true,
- );
- }
-
- /**
- * Filters a page of personal data exporter data. Used to build the export report.
- *
- * Allows the export response to be consumed by destinations in addition to Ajax.
- *
- * @since 4.9.6
- *
- * @param array $response The personal data for the given exporter and page.
- * @param int $exporter_index The index of the exporter that provided this data.
- * @param string $email_address The email address associated with this personal data.
- * @param int $page The page for this response.
- * @param int $request_id The privacy request post ID associated with this request.
- * @param bool $send_as_email Whether the final results of the export should be emailed to the user.
- * @param string $exporter_key The key (slug) of the exporter that provided this data.
- */
- $response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key );
-
- if ( is_wp_error( $response ) ) {
- wp_send_json_error( $response );
- }
-
- wp_send_json_success( $response );
-}
-
-/**
- * Ajax handler for erasing personal data.
- *
- * @since 4.9.6
- */
-function wp_ajax_wp_privacy_erase_personal_data() {
-
- if ( empty( $_POST['id'] ) ) {
- wp_send_json_error( __( 'Missing request ID.' ) );
- }
-
- $request_id = (int) $_POST['id'];
-
- if ( $request_id < 1 ) {
- wp_send_json_error( __( 'Invalid request ID.' ) );
- }
-
- // Both capabilities are required to avoid confusion, see `_wp_personal_data_removal_page()`.
- if ( ! current_user_can( 'erase_others_personal_data' ) || ! current_user_can( 'delete_users' ) ) {
- wp_send_json_error( __( 'Sorry, you are not allowed to perform this action.' ) );
- }
-
- check_ajax_referer( 'wp-privacy-erase-personal-data-' . $request_id, 'security' );
-
- // Get the request data.
- $request = wp_get_user_request_data( $request_id );
-
- if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
- wp_send_json_error( __( 'Invalid request type.' ) );
- }
-
- $email_address = $request->email;
-
- if ( ! is_email( $email_address ) ) {
- wp_send_json_error( __( 'Invalid email address in request.' ) );
- }
-
- if ( ! isset( $_POST['eraser'] ) ) {
- wp_send_json_error( __( 'Missing eraser index.' ) );
- }
-
- $eraser_index = (int) $_POST['eraser'];
-
- if ( ! isset( $_POST['page'] ) ) {
- wp_send_json_error( __( 'Missing page index.' ) );
- }
-
- $page = (int) $_POST['page'];
-
- /**
- * Filters the array of personal data eraser callbacks.
- *
- * @since 4.9.6
- *
- * @param array $args {
- * An array of callable erasers of personal data. Default empty array.
- *
- * @type array {
- * Array of personal data exporters.
- *
- * @type string $callback Callable eraser that accepts an email address and
- * a page and returns an array with boolean values for
- * whether items were removed or retained and any messages
- * from the eraser, as well as if additional pages are
- * available.
- * @type string $exporter_friendly_name Translated user facing friendly name for the eraser.
- * }
- * }
- */
- $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
-
- // Do we have any registered erasers?
- if ( 0 < count( $erasers ) ) {
-
- if ( $eraser_index < 1 ) {
- wp_send_json_error( __( 'Eraser index cannot be less than one.' ) );
- }
-
- if ( $eraser_index > count( $erasers ) ) {
- wp_send_json_error( __( 'Eraser index is out of range.' ) );
- }
-
- if ( $page < 1 ) {
- wp_send_json_error( __( 'Page index cannot be less than one.' ) );
- }
-
- $eraser_keys = array_keys( $erasers );
- $eraser_key = $eraser_keys[ $eraser_index - 1 ];
- $eraser = $erasers[ $eraser_key ];
-
- if ( ! is_array( $eraser ) ) {
- /* translators: %d: Eraser array index. */
- wp_send_json_error( sprintf( __( 'Expected an array describing the eraser at index %d.' ), $eraser_index ) );
- }
-
- if ( ! array_key_exists( 'eraser_friendly_name', $eraser ) ) {
- /* translators: %d: Eraser array index. */
- wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a friendly name.' ), $eraser_index ) );
- }
-
- $eraser_friendly_name = $eraser['eraser_friendly_name'];
-
- if ( ! array_key_exists( 'callback', $eraser ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: %s: Eraser friendly name. */
- __( 'Eraser does not include a callback: %s.' ),
- esc_html( $eraser_friendly_name )
- )
- );
- }
-
- if ( ! is_callable( $eraser['callback'] ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: %s: Eraser friendly name. */
- __( 'Eraser callback is not valid: %s.' ),
- esc_html( $eraser_friendly_name )
- )
- );
- }
-
- $callback = $eraser['callback'];
- $response = call_user_func( $callback, $email_address, $page );
-
- if ( is_wp_error( $response ) ) {
- wp_send_json_error( $response );
- }
-
- if ( ! is_array( $response ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: 1: Eraser friendly name, 2: Eraser array index. */
- __( 'Did not receive array from %1$s eraser (index %2$d).' ),
- esc_html( $eraser_friendly_name ),
- $eraser_index
- )
- );
- }
-
- if ( ! array_key_exists( 'items_removed', $response ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: 1: Eraser friendly name, 2: Eraser array index. */
- __( 'Expected items_removed key in response array from %1$s eraser (index %2$d).' ),
- esc_html( $eraser_friendly_name ),
- $eraser_index
- )
- );
- }
-
- if ( ! array_key_exists( 'items_retained', $response ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: 1: Eraser friendly name, 2: Eraser array index. */
- __( 'Expected items_retained key in response array from %1$s eraser (index %2$d).' ),
- esc_html( $eraser_friendly_name ),
- $eraser_index
- )
- );
- }
-
- if ( ! array_key_exists( 'messages', $response ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: 1: Eraser friendly name, 2: Eraser array index. */
- __( 'Expected messages key in response array from %1$s eraser (index %2$d).' ),
- esc_html( $eraser_friendly_name ),
- $eraser_index
- )
- );
- }
-
- if ( ! is_array( $response['messages'] ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: 1: Eraser friendly name, 2: Eraser array index. */
- __( 'Expected messages key to reference an array in response array from %1$s eraser (index %2$d).' ),
- esc_html( $eraser_friendly_name ),
- $eraser_index
- )
- );
- }
-
- if ( ! array_key_exists( 'done', $response ) ) {
- wp_send_json_error(
- sprintf(
- /* translators: 1: Eraser friendly name, 2: Eraser array index. */
- __( 'Expected done flag in response array from %1$s eraser (index %2$d).' ),
- esc_html( $eraser_friendly_name ),
- $eraser_index
- )
- );
- }
- } else {
- // No erasers, so we're done.
- $eraser_key = '';
-
- $response = array(
- 'items_removed' => false,
- 'items_retained' => false,
- 'messages' => array(),
- 'done' => true,
- );
- }
-
- /**
- * Filters a page of personal data eraser data.
- *
- * Allows the erasure response to be consumed by destinations in addition to Ajax.
- *
- * @since 4.9.6
- *
- * @param array $response The personal data for the given exporter and page.
- * @param int $eraser_index The index of the eraser that provided this data.
- * @param string $email_address The email address associated with this personal data.
- * @param int $page The page for this response.
- * @param int $request_id The privacy request post ID associated with this request.
- * @param string $eraser_key The key (slug) of the eraser that provided this data.
- */
- $response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id, $eraser_key );
-
- if ( is_wp_error( $response ) ) {
- wp_send_json_error( $response );
- }
-
- wp_send_json_success( $response );
-}
-
-/**
- * Ajax handler for site health checks on server communication.
- *
- * @since 5.2.0
- */
-function wp_ajax_health_check_dotorg_communication() {
- check_ajax_referer( 'health-check-site-status' );
-
- if ( ! current_user_can( 'view_site_health_checks' ) ) {
- wp_send_json_error();
- }
-
- if ( ! class_exists( 'WP_Site_Health' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
- }
-
- $site_health = new WP_Site_Health();
- wp_send_json_success( $site_health->get_test_dotorg_communication() );
-}
-
-/**
- * Ajax handler for site health checks on debug mode.
- *
- * @since 5.2.0
- */
-function wp_ajax_health_check_is_in_debug_mode() {
- wp_verify_nonce( 'health-check-site-status' );
-
- if ( ! current_user_can( 'view_site_health_checks' ) ) {
- wp_send_json_error();
- }
-
- if ( ! class_exists( 'WP_Site_Health' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
- }
-
- $site_health = new WP_Site_Health();
- wp_send_json_success( $site_health->get_test_is_in_debug_mode() );
-}
-
-/**
- * Ajax handler for site health checks on background updates.
- *
- * @since 5.2.0
- */
-function wp_ajax_health_check_background_updates() {
- check_ajax_referer( 'health-check-site-status' );
-
- if ( ! current_user_can( 'view_site_health_checks' ) ) {
- wp_send_json_error();
- }
-
- if ( ! class_exists( 'WP_Site_Health' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
- }
-
- $site_health = new WP_Site_Health();
- wp_send_json_success( $site_health->get_test_background_updates() );
-}
-
-
-/**
- * Ajax handler for site health checks on loopback requests.
- *
- * @since 5.2.0
- */
-function wp_ajax_health_check_loopback_requests() {
- check_ajax_referer( 'health-check-site-status' );
-
- if ( ! current_user_can( 'view_site_health_checks' ) ) {
- wp_send_json_error();
- }
-
- if ( ! class_exists( 'WP_Site_Health' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health.php' );
- }
-
- $site_health = new WP_Site_Health();
- wp_send_json_success( $site_health->get_test_loopback_requests() );
-}
-
-/**
- * Ajax handler for site health check to update the result status.
- *
- * @since 5.2.0
- */
-function wp_ajax_health_check_site_status_result() {
- check_ajax_referer( 'health-check-site-status-result' );
-
- if ( ! current_user_can( 'view_site_health_checks' ) ) {
- wp_send_json_error();
- }
-
- set_transient( 'health-check-site-status-result', wp_json_encode( $_POST['counts'] ) );
-
- wp_send_json_success();
-}
-
-/**
- * Ajax handler for site health check to get directories and database sizes.
- *
- * @since 5.2.0
- */
-function wp_ajax_health_check_get_sizes() {
- check_ajax_referer( 'health-check-site-status-result' );
-
- if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) {
- wp_send_json_error();
- }
-
- if ( ! class_exists( 'WP_Debug_Data' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-debug-data.php' );
- }
-
- $sizes_data = WP_Debug_Data::get_sizes();
- $all_sizes = array( 'raw' => 0 );
-
- foreach ( $sizes_data as $name => $value ) {
- $name = sanitize_text_field( $name );
- $data = array();
-
- if ( isset( $value['size'] ) ) {
- if ( is_string( $value['size'] ) ) {
- $data['size'] = sanitize_text_field( $value['size'] );
- } else {
- $data['size'] = (int) $value['size'];
- }
- }
-
- if ( isset( $value['debug'] ) ) {
- if ( is_string( $value['debug'] ) ) {
- $data['debug'] = sanitize_text_field( $value['debug'] );
- } else {
- $data['debug'] = (int) $value['debug'];
- }
- }
-
- if ( ! empty( $value['raw'] ) ) {
- $data['raw'] = (int) $value['raw'];
- }
-
- $all_sizes[ $name ] = $data;
- }
-
- if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) {
- wp_send_json_error( $all_sizes );
- }
-
- wp_send_json_success( $all_sizes );
-}
-
-/**
- * Ajax handler to renew the REST API nonce.
- *
- * @since 5.3.0
- */
-function wp_ajax_rest_nonce() {
- exit( wp_create_nonce( 'wp_rest' ) );
-}
diff --git a/srcs/wordpress/wp-admin/includes/bookmark.php b/srcs/wordpress/wp-admin/includes/bookmark.php
deleted file mode 100644
index 6168a63..0000000
--- a/srcs/wordpress/wp-admin/includes/bookmark.php
+++ /dev/null
@@ -1,327 +0,0 @@
-' . __( 'You need a higher level of permission.' ) . '' .
- '' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '
',
- 403
- );
- }
-
- $_POST['link_url'] = esc_html( $_POST['link_url'] );
- $_POST['link_url'] = esc_url( $_POST['link_url'] );
- $_POST['link_name'] = esc_html( $_POST['link_name'] );
- $_POST['link_image'] = esc_html( $_POST['link_image'] );
- $_POST['link_rss'] = esc_url( $_POST['link_rss'] );
- if ( ! isset( $_POST['link_visible'] ) || 'N' != $_POST['link_visible'] ) {
- $_POST['link_visible'] = 'Y';
- }
-
- if ( ! empty( $link_id ) ) {
- $_POST['link_id'] = $link_id;
- return wp_update_link( $_POST );
- } else {
- return wp_insert_link( $_POST );
- }
-}
-
-/**
- * Retrieves the default link for editing.
- *
- * @since 2.0.0
- *
- * @return stdClass Default link object.
- */
-function get_default_link_to_edit() {
- $link = new stdClass;
- if ( isset( $_GET['linkurl'] ) ) {
- $link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) );
- } else {
- $link->link_url = '';
- }
-
- if ( isset( $_GET['name'] ) ) {
- $link->link_name = esc_attr( wp_unslash( $_GET['name'] ) );
- } else {
- $link->link_name = '';
- }
-
- $link->link_visible = 'Y';
-
- return $link;
-}
-
-/**
- * Deletes a specified link from the database.
- *
- * @since 2.0.0
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @param int $link_id ID of the link to delete
- * @return true Always true.
- */
-function wp_delete_link( $link_id ) {
- global $wpdb;
- /**
- * Fires before a link is deleted.
- *
- * @since 2.0.0
- *
- * @param int $link_id ID of the link to delete.
- */
- do_action( 'delete_link', $link_id );
-
- wp_delete_object_term_relationships( $link_id, 'link_category' );
-
- $wpdb->delete( $wpdb->links, array( 'link_id' => $link_id ) );
-
- /**
- * Fires after a link has been deleted.
- *
- * @since 2.2.0
- *
- * @param int $link_id ID of the deleted link.
- */
- do_action( 'deleted_link', $link_id );
-
- clean_bookmark_cache( $link_id );
-
- return true;
-}
-
-/**
- * Retrieves the link categories associated with the link specified.
- *
- * @since 2.1.0
- *
- * @param int $link_id Link ID to look up
- * @return array The requested link's categories
- */
-function wp_get_link_cats( $link_id = 0 ) {
- $cats = wp_get_object_terms( $link_id, 'link_category', array( 'fields' => 'ids' ) );
- return array_unique( $cats );
-}
-
-/**
- * Retrieves link data based on its ID.
- *
- * @since 2.0.0
- *
- * @param int|stdClass $link Link ID or object to retrieve.
- * @return object Link object for editing.
- */
-function get_link_to_edit( $link ) {
- return get_bookmark( $link, OBJECT, 'edit' );
-}
-
-/**
- * Inserts/updates links into/in the database.
- *
- * @since 2.0.0
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @param array $linkdata Elements that make up the link to insert.
- * @param bool $wp_error Optional. Whether to return a WP_Error object on failure. Default false.
- * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
- */
-function wp_insert_link( $linkdata, $wp_error = false ) {
- global $wpdb;
-
- $defaults = array(
- 'link_id' => 0,
- 'link_name' => '',
- 'link_url' => '',
- 'link_rating' => 0,
- );
-
- $parsed_args = wp_parse_args( $linkdata, $defaults );
- $parsed_args = wp_unslash( sanitize_bookmark( $parsed_args, 'db' ) );
-
- $link_id = $parsed_args['link_id'];
- $link_name = $parsed_args['link_name'];
- $link_url = $parsed_args['link_url'];
-
- $update = false;
- if ( ! empty( $link_id ) ) {
- $update = true;
- }
-
- if ( trim( $link_name ) == '' ) {
- if ( trim( $link_url ) != '' ) {
- $link_name = $link_url;
- } else {
- return 0;
- }
- }
-
- if ( trim( $link_url ) == '' ) {
- return 0;
- }
-
- $link_rating = ( ! empty( $parsed_args['link_rating'] ) ) ? $parsed_args['link_rating'] : 0;
- $link_image = ( ! empty( $parsed_args['link_image'] ) ) ? $parsed_args['link_image'] : '';
- $link_target = ( ! empty( $parsed_args['link_target'] ) ) ? $parsed_args['link_target'] : '';
- $link_visible = ( ! empty( $parsed_args['link_visible'] ) ) ? $parsed_args['link_visible'] : 'Y';
- $link_owner = ( ! empty( $parsed_args['link_owner'] ) ) ? $parsed_args['link_owner'] : get_current_user_id();
- $link_notes = ( ! empty( $parsed_args['link_notes'] ) ) ? $parsed_args['link_notes'] : '';
- $link_description = ( ! empty( $parsed_args['link_description'] ) ) ? $parsed_args['link_description'] : '';
- $link_rss = ( ! empty( $parsed_args['link_rss'] ) ) ? $parsed_args['link_rss'] : '';
- $link_rel = ( ! empty( $parsed_args['link_rel'] ) ) ? $parsed_args['link_rel'] : '';
- $link_category = ( ! empty( $parsed_args['link_category'] ) ) ? $parsed_args['link_category'] : array();
-
- // Make sure we set a valid category.
- if ( ! is_array( $link_category ) || 0 == count( $link_category ) ) {
- $link_category = array( get_option( 'default_link_category' ) );
- }
-
- if ( $update ) {
- if ( false === $wpdb->update( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ), compact( 'link_id' ) ) ) {
- if ( $wp_error ) {
- return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
- } else {
- return 0;
- }
- }
- } else {
- if ( false === $wpdb->insert( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ) ) ) {
- if ( $wp_error ) {
- return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
- } else {
- return 0;
- }
- }
- $link_id = (int) $wpdb->insert_id;
- }
-
- wp_set_link_cats( $link_id, $link_category );
-
- if ( $update ) {
- /**
- * Fires after a link was updated in the database.
- *
- * @since 2.0.0
- *
- * @param int $link_id ID of the link that was updated.
- */
- do_action( 'edit_link', $link_id );
- } else {
- /**
- * Fires after a link was added to the database.
- *
- * @since 2.0.0
- *
- * @param int $link_id ID of the link that was added.
- */
- do_action( 'add_link', $link_id );
- }
- clean_bookmark_cache( $link_id );
-
- return $link_id;
-}
-
-/**
- * Update link with the specified link categories.
- *
- * @since 2.1.0
- *
- * @param int $link_id ID of the link to update.
- * @param int[] $link_categories Array of link category IDs to add the link to.
- */
-function wp_set_link_cats( $link_id = 0, $link_categories = array() ) {
- // If $link_categories isn't already an array, make it one:
- if ( ! is_array( $link_categories ) || 0 == count( $link_categories ) ) {
- $link_categories = array( get_option( 'default_link_category' ) );
- }
-
- $link_categories = array_map( 'intval', $link_categories );
- $link_categories = array_unique( $link_categories );
-
- wp_set_object_terms( $link_id, $link_categories, 'link_category' );
-
- clean_bookmark_cache( $link_id );
-}
-
-/**
- * Updates a link in the database.
- *
- * @since 2.0.0
- *
- * @param array $linkdata Link data to update.
- * @return int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success.
- */
-function wp_update_link( $linkdata ) {
- $link_id = (int) $linkdata['link_id'];
-
- $link = get_bookmark( $link_id, ARRAY_A );
-
- // Escape data pulled from DB.
- $link = wp_slash( $link );
-
- // Passed link category list overwrites existing category list if not empty.
- if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) && 0 != count( $linkdata['link_category'] ) ) {
- $link_cats = $linkdata['link_category'];
- } else {
- $link_cats = $link['link_category'];
- }
-
- // Merge old and new fields with new fields overwriting old ones.
- $linkdata = array_merge( $link, $linkdata );
- $linkdata['link_category'] = $link_cats;
-
- return wp_insert_link( $linkdata );
-}
-
-/**
- * Outputs the 'disabled' message for the WordPress Link Manager.
- *
- * @since 3.5.0
- * @access private
- *
- * @global string $pagenow
- */
-function wp_link_manager_disabled_message() {
- global $pagenow;
- if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow ) {
- return;
- }
-
- add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
- $really_can_manage_links = current_user_can( 'manage_links' );
- remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
-
- if ( $really_can_manage_links && current_user_can( 'install_plugins' ) ) {
- $link = network_admin_url( 'plugin-install.php?tab=search&s=Link+Manager' );
- /* translators: %s: URL to install the Link Manager plugin. */
- wp_die( sprintf( __( 'If you are looking to use the link manager, please install the Link Manager plugin.' ), $link ) );
- }
-
- wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) );
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-automatic-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-automatic-upgrader-skin.php
deleted file mode 100644
index 3966e2a..0000000
--- a/srcs/wordpress/wp-admin/includes/class-automatic-upgrader-skin.php
+++ /dev/null
@@ -1,117 +0,0 @@
-options['context'] = $context;
- }
- // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
- // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
- ob_start();
- $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
- ob_end_clean();
- return $result;
- }
-
- /**
- * @return array
- */
- public function get_upgrade_messages() {
- return $this->messages;
- }
-
- /**
- * @param string|array|WP_Error $data
- * @param mixed ...$args Optional text replacements.
- */
- public function feedback( $data, ...$args ) {
- if ( is_wp_error( $data ) ) {
- $string = $data->get_error_message();
- } elseif ( is_array( $data ) ) {
- return;
- } else {
- $string = $data;
- }
- if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
- $string = $this->upgrader->strings[ $string ];
- }
-
- if ( strpos( $string, '%' ) !== false ) {
- if ( ! empty( $args ) ) {
- $string = vsprintf( $string, $args );
- }
- }
-
- $string = trim( $string );
-
- // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
- $string = wp_kses(
- $string,
- array(
- 'a' => array(
- 'href' => true,
- ),
- 'br' => true,
- 'em' => true,
- 'strong' => true,
- )
- );
-
- if ( empty( $string ) ) {
- return;
- }
-
- $this->messages[] = $string;
- }
-
- /**
- */
- public function header() {
- ob_start();
- }
-
- /**
- */
- public function footer() {
- $output = ob_get_clean();
- if ( ! empty( $output ) ) {
- $this->feedback( $output );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-bulk-plugin-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-bulk-plugin-upgrader-skin.php
deleted file mode 100644
index 308cacf..0000000
--- a/srcs/wordpress/wp-admin/includes/class-bulk-plugin-upgrader-skin.php
+++ /dev/null
@@ -1,78 +0,0 @@
-upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)' );
- }
-
- /**
- * @param string $title
- */
- public function before( $title = '' ) {
- parent::before( $this->plugin_info['Title'] );
- }
-
- /**
- * @param string $title
- */
- public function after( $title = '' ) {
- parent::after( $this->plugin_info['Title'] );
- $this->decrement_update_count( 'plugin' );
- }
-
- /**
- */
- public function bulk_footer() {
- parent::bulk_footer();
-
- $update_actions = array(
- 'plugins_page' => sprintf(
- '%s ',
- self_admin_url( 'plugins.php' ),
- __( 'Return to Plugins page' )
- ),
- 'updates_page' => sprintf(
- '%s ',
- self_admin_url( 'update-core.php' ),
- __( 'Return to WordPress Updates page' )
- ),
- );
-
- if ( ! current_user_can( 'activate_plugins' ) ) {
- unset( $update_actions['plugins_page'] );
- }
-
- /**
- * Filters the list of action links available following bulk plugin updates.
- *
- * @since 3.0.0
- *
- * @param string[] $update_actions Array of plugin action links.
- * @param array $plugin_info Array of information for the last-updated plugin.
- */
- $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info );
-
- if ( ! empty( $update_actions ) ) {
- $this->feedback( implode( ' | ', (array) $update_actions ) );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-bulk-theme-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-bulk-theme-upgrader-skin.php
deleted file mode 100644
index d3f0c91..0000000
--- a/srcs/wordpress/wp-admin/includes/class-bulk-theme-upgrader-skin.php
+++ /dev/null
@@ -1,78 +0,0 @@
-upgrader->strings['skin_before_update_header'] = __( 'Updating Theme %1$s (%2$d/%3$d)' );
- }
-
- /**
- * @param string $title
- */
- public function before( $title = '' ) {
- parent::before( $this->theme_info->display( 'Name' ) );
- }
-
- /**
- * @param string $title
- */
- public function after( $title = '' ) {
- parent::after( $this->theme_info->display( 'Name' ) );
- $this->decrement_update_count( 'theme' );
- }
-
- /**
- */
- public function bulk_footer() {
- parent::bulk_footer();
-
- $update_actions = array(
- 'themes_page' => sprintf(
- '%s ',
- self_admin_url( 'themes.php' ),
- __( 'Return to Themes page' )
- ),
- 'updates_page' => sprintf(
- '%s ',
- self_admin_url( 'update-core.php' ),
- __( 'Return to WordPress Updates page' )
- ),
- );
-
- if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) {
- unset( $update_actions['themes_page'] );
- }
-
- /**
- * Filters the list of action links available following bulk theme updates.
- *
- * @since 3.0.0
- *
- * @param string[] $update_actions Array of theme action links.
- * @param WP_Theme $theme_info Theme object for the last-updated theme.
- */
- $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info );
-
- if ( ! empty( $update_actions ) ) {
- $this->feedback( implode( ' | ', (array) $update_actions ) );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-bulk-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-bulk-upgrader-skin.php
deleted file mode 100644
index c5cbcd4..0000000
--- a/srcs/wordpress/wp-admin/includes/class-bulk-upgrader-skin.php
+++ /dev/null
@@ -1,177 +0,0 @@
- '',
- 'nonce' => '',
- );
- $args = wp_parse_args( $args, $defaults );
-
- parent::__construct( $args );
- }
-
- /**
- */
- public function add_strings() {
- $this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' );
- /* translators: 1: Title of an update, 2: Error message. */
- $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' );
- /* translators: %s: Title of an update. */
- $this->upgrader->strings['skin_update_failed'] = __( 'The update of %s failed.' );
- /* translators: %s: Title of an update. */
- $this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' );
- $this->upgrader->strings['skin_upgrade_end'] = __( 'All updates have been completed.' );
- }
-
- /**
- * @param string $string
- * @param mixed ...$args Optional text replacements.
- */
- public function feedback( $string, ...$args ) {
- if ( isset( $this->upgrader->strings[ $string ] ) ) {
- $string = $this->upgrader->strings[ $string ];
- }
-
- if ( strpos( $string, '%' ) !== false ) {
- if ( $args ) {
- $args = array_map( 'strip_tags', $args );
- $args = array_map( 'esc_html', $args );
- $string = vsprintf( $string, $args );
- }
- }
- if ( empty( $string ) ) {
- return;
- }
- if ( $this->in_loop ) {
- echo "$string \n";
- } else {
- echo "$string
\n";
- }
- }
-
- /**
- */
- public function header() {
- // Nothing, This will be displayed within a iframe.
- }
-
- /**
- */
- public function footer() {
- // Nothing, This will be displayed within a iframe.
- }
-
- /**
- * @param string|WP_Error $error
- */
- public function error( $error ) {
- if ( is_string( $error ) && isset( $this->upgrader->strings[ $error ] ) ) {
- $this->error = $this->upgrader->strings[ $error ];
- }
-
- if ( is_wp_error( $error ) ) {
- $messages = array();
- foreach ( $error->get_error_messages() as $emessage ) {
- if ( $error->get_error_data() && is_string( $error->get_error_data() ) ) {
- $messages[] = $emessage . ' ' . esc_html( strip_tags( $error->get_error_data() ) );
- } else {
- $messages[] = $emessage;
- }
- }
- $this->error = implode( ', ', $messages );
- }
- echo '';
- }
-
- /**
- */
- public function bulk_header() {
- $this->feedback( 'skin_upgrade_start' );
- }
-
- /**
- */
- public function bulk_footer() {
- $this->feedback( 'skin_upgrade_end' );
- }
-
- /**
- * @param string $title
- */
- public function before( $title = '' ) {
- $this->in_loop = true;
- printf( '' . $this->upgrader->strings['skin_before_update_header'] . ' ', $title, $this->upgrader->update_current, $this->upgrader->update_count );
- echo '';
- // This progress messages div gets moved via JavaScript when clicking on "Show details.".
- echo '';
- $this->flush_output();
- }
-
- /**
- * @param string $title
- */
- public function after( $title = '' ) {
- echo '
';
- if ( $this->error || ! $this->result ) {
- if ( $this->error ) {
- echo '' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '' . $this->error . ' ' ) . '
';
- } else {
- echo '' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '
';
- }
-
- echo '';
- }
- if ( $this->result && ! is_wp_error( $this->result ) ) {
- if ( ! $this->error ) {
- echo '' .
- '
' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) .
- ' ' . __( 'Show details.' ) . ' ' .
- '
';
- }
-
- echo '';
- }
-
- $this->reset();
- $this->flush_output();
- }
-
- /**
- */
- public function reset() {
- $this->in_loop = false;
- $this->error = false;
- }
-
- /**
- */
- public function flush_output() {
- wp_ob_end_flush_all();
- flush();
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-core-upgrader.php b/srcs/wordpress/wp-admin/includes/class-core-upgrader.php
deleted file mode 100644
index ad94983..0000000
--- a/srcs/wordpress/wp-admin/includes/class-core-upgrader.php
+++ /dev/null
@@ -1,411 +0,0 @@
-strings['up_to_date'] = __( 'WordPress is at the latest version.' );
- $this->strings['locked'] = __( 'Another update is currently in progress.' );
- $this->strings['no_package'] = __( 'Update package not available.' );
- /* translators: %s: Package URL. */
- $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s ' );
- $this->strings['unpack_package'] = __( 'Unpacking the update…' );
- $this->strings['copy_failed'] = __( 'Could not copy files.' );
- $this->strings['copy_failed_space'] = __( 'Could not copy files. You may have run out of disk space.' );
- $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' );
- $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' );
- }
-
- /**
- * Upgrade WordPress core.
- *
- * @since 2.8.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- * @global callable $_wp_filesystem_direct_method
- *
- * @param object $current Response object for whether WordPress is current.
- * @param array $args {
- * Optional. Arguments for upgrading WordPress core. Default empty array.
- *
- * @type bool $pre_check_md5 Whether to check the file checksums before
- * attempting the upgrade. Default true.
- * @type bool $attempt_rollback Whether to attempt to rollback the chances if
- * there is a problem. Default false.
- * @type bool $do_rollback Whether to perform this "upgrade" as a rollback.
- * Default false.
- * }
- * @return null|false|WP_Error False or WP_Error on failure, null on success.
- */
- public function upgrade( $current, $args = array() ) {
- global $wp_filesystem;
-
- include( ABSPATH . WPINC . '/version.php' ); // $wp_version;
-
- $start_time = time();
-
- $defaults = array(
- 'pre_check_md5' => true,
- 'attempt_rollback' => false,
- 'do_rollback' => false,
- 'allow_relaxed_file_ownership' => false,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->upgrade_strings();
-
- // Is an update available?
- if ( ! isset( $current->response ) || $current->response == 'latest' ) {
- return new WP_Error( 'up_to_date', $this->strings['up_to_date'] );
- }
-
- $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] );
- if ( ! $res || is_wp_error( $res ) ) {
- return $res;
- }
-
- $wp_dir = trailingslashit( $wp_filesystem->abspath() );
-
- $partial = true;
- if ( $parsed_args['do_rollback'] ) {
- $partial = false;
- } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) {
- $partial = false;
- }
-
- /*
- * If partial update is returned from the API, use that, unless we're doing
- * a reinstallation. If we cross the new_bundled version number, then use
- * the new_bundled zip. Don't though if the constant is set to skip bundled items.
- * If the API returns a no_content zip, go with it. Finally, default to the full zip.
- */
- if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
- $to_download = 'rollback';
- } elseif ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial ) {
- $to_download = 'partial';
- } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
- && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
- $to_download = 'new_bundled';
- } elseif ( $current->packages->no_content ) {
- $to_download = 'no_content';
- } else {
- $to_download = 'full';
- }
-
- // Lock to prevent multiple Core Updates occurring
- $lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS );
- if ( ! $lock ) {
- return new WP_Error( 'locked', $this->strings['locked'] );
- }
-
- $download = $this->download_package( $current->packages->$to_download, true );
-
- // Allow for signature soft-fail.
- // WARNING: This may be removed in the future.
- if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {
- // Outout the failure error as a normal feedback, and not as an error:
- apply_filters( 'update_feedback', $download->get_error_message() );
-
- // Report this failure back to WordPress.org for debugging purposes.
- wp_version_check(
- array(
- 'signature_failure_code' => $download->get_error_code(),
- 'signature_failure_data' => $download->get_error_data(),
- )
- );
-
- // Pretend this error didn't happen.
- $download = $download->get_error_data( 'softfail-filename' );
- }
-
- if ( is_wp_error( $download ) ) {
- WP_Upgrader::release_lock( 'core_updater' );
- return $download;
- }
-
- $working_dir = $this->unpack_package( $download );
- if ( is_wp_error( $working_dir ) ) {
- WP_Upgrader::release_lock( 'core_updater' );
- return $working_dir;
- }
-
- // Copy update-core.php from the new version into place.
- if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) {
- $wp_filesystem->delete( $working_dir, true );
- WP_Upgrader::release_lock( 'core_updater' );
- return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' );
- }
- $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE );
-
- require_once( ABSPATH . 'wp-admin/includes/update-core.php' );
-
- if ( ! function_exists( 'update_core' ) ) {
- WP_Upgrader::release_lock( 'core_updater' );
- return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] );
- }
-
- $result = update_core( $working_dir, $wp_dir );
-
- // In the event of an issue, we may be able to roll back.
- if ( $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) {
- $try_rollback = false;
- if ( is_wp_error( $result ) ) {
- $error_code = $result->get_error_code();
- /*
- * Not all errors are equal. These codes are critical: copy_failed__copy_dir,
- * mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full.
- * do_rollback allows for update_core() to trigger a rollback if needed.
- */
- if ( false !== strpos( $error_code, 'do_rollback' ) ) {
- $try_rollback = true;
- } elseif ( false !== strpos( $error_code, '__copy_dir' ) ) {
- $try_rollback = true;
- } elseif ( 'disk_full' === $error_code ) {
- $try_rollback = true;
- }
- }
-
- if ( $try_rollback ) {
- /** This filter is documented in wp-admin/includes/update-core.php */
- apply_filters( 'update_feedback', $result );
-
- /** This filter is documented in wp-admin/includes/update-core.php */
- apply_filters( 'update_feedback', $this->strings['start_rollback'] );
-
- $rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) );
-
- $original_result = $result;
- $result = new WP_Error(
- 'rollback_was_required',
- $this->strings['rollback_was_required'],
- (object) array(
- 'update' => $original_result,
- 'rollback' => $rollback_result,
- )
- );
- }
- }
-
- /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
- do_action(
- 'upgrader_process_complete',
- $this,
- array(
- 'action' => 'update',
- 'type' => 'core',
- )
- );
-
- // Clear the current updates
- delete_site_transient( 'update_core' );
-
- if ( ! $parsed_args['do_rollback'] ) {
- $stats = array(
- 'update_type' => $current->response,
- 'success' => true,
- 'fs_method' => $wp_filesystem->method,
- 'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ),
- 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '',
- 'time_taken' => time() - $start_time,
- 'reported' => $wp_version,
- 'attempted' => $current->version,
- );
-
- if ( is_wp_error( $result ) ) {
- $stats['success'] = false;
- // Did a rollback occur?
- if ( ! empty( $try_rollback ) ) {
- $stats['error_code'] = $original_result->get_error_code();
- $stats['error_data'] = $original_result->get_error_data();
- // Was the rollback successful? If not, collect its error too.
- $stats['rollback'] = ! is_wp_error( $rollback_result );
- if ( is_wp_error( $rollback_result ) ) {
- $stats['rollback_code'] = $rollback_result->get_error_code();
- $stats['rollback_data'] = $rollback_result->get_error_data();
- }
- } else {
- $stats['error_code'] = $result->get_error_code();
- $stats['error_data'] = $result->get_error_data();
- }
- }
-
- wp_version_check( $stats );
- }
-
- WP_Upgrader::release_lock( 'core_updater' );
-
- return $result;
- }
-
- /**
- * Determines if this WordPress Core version should update to an offered version or not.
- *
- * @since 3.7.0
- *
- * @param string $offered_ver The offered version, of the format x.y.z.
- * @return bool True if we should update to the offered version, otherwise false.
- */
- public static function should_update_to_version( $offered_ver ) {
- include( ABSPATH . WPINC . '/version.php' ); // $wp_version; // x.y.z
-
- $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y
- $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
- $current_is_development_version = (bool) strpos( $wp_version, '-' );
-
- // Defaults:
- $upgrade_dev = true;
- $upgrade_minor = true;
- $upgrade_major = false;
-
- // WP_AUTO_UPDATE_CORE = true (all), 'minor', false.
- if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
- if ( false === WP_AUTO_UPDATE_CORE ) {
- // Defaults to turned off, unless a filter allows it
- $upgrade_dev = false;
- $upgrade_minor = false;
- $upgrade_major = false;
- } elseif ( true === WP_AUTO_UPDATE_CORE ) {
- // ALL updates for core
- $upgrade_dev = true;
- $upgrade_minor = true;
- $upgrade_major = true;
- } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
- // Only minor updates for core
- $upgrade_dev = false;
- $upgrade_minor = true;
- $upgrade_major = false;
- }
- }
-
- // 1: If we're already on that version, not much point in updating?
- if ( $offered_ver == $wp_version ) {
- return false;
- }
-
- // 2: If we're running a newer version, that's a nope
- if ( version_compare( $wp_version, $offered_ver, '>' ) ) {
- return false;
- }
-
- $failure_data = get_site_option( 'auto_core_update_failed' );
- if ( $failure_data ) {
- // If this was a critical update failure, cannot update.
- if ( ! empty( $failure_data['critical'] ) ) {
- return false;
- }
-
- // Don't claim we can update on update-core.php if we have a non-critical failure logged.
- if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) {
- return false;
- }
-
- // Cannot update if we're retrying the same A to B update that caused a non-critical failure.
- // Some non-critical failures do allow retries, like download_failed.
- // 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2.
- if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) {
- return false;
- }
- }
-
- // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2
- if ( $current_is_development_version ) {
-
- /**
- * Filters whether to enable automatic core updates for development versions.
- *
- * @since 3.7.0
- *
- * @param bool $upgrade_dev Whether to enable automatic updates for
- * development versions.
- */
- if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) {
- return false;
- }
- // Else fall through to minor + major branches below.
- }
-
- // 4: Minor In-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4)
- if ( $current_branch == $new_branch ) {
-
- /**
- * Filters whether to enable minor automatic core updates.
- *
- * @since 3.7.0
- *
- * @param bool $upgrade_minor Whether to enable minor automatic core updates.
- */
- return apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor );
- }
-
- // 5: Major version updates (3.7.0 -> 3.8.0 -> 3.9.1)
- if ( version_compare( $new_branch, $current_branch, '>' ) ) {
-
- /**
- * Filters whether to enable major automatic core updates.
- *
- * @since 3.7.0
- *
- * @param bool $upgrade_major Whether to enable major automatic core updates.
- */
- return apply_filters( 'allow_major_auto_core_updates', $upgrade_major );
- }
-
- // If we're not sure, we don't want it
- return false;
- }
-
- /**
- * Compare the disk file checksums against the expected checksums.
- *
- * @since 3.7.0
- *
- * @global string $wp_version
- * @global string $wp_local_package
- *
- * @return bool True if the checksums match, otherwise false.
- */
- public function check_files() {
- global $wp_version, $wp_local_package;
-
- $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
-
- if ( ! is_array( $checksums ) ) {
- return false;
- }
-
- foreach ( $checksums as $file => $checksum ) {
- // Skip files which get updated
- if ( 'wp-content' == substr( $file, 0, 10 ) ) {
- continue;
- }
- if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) {
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-custom-background.php b/srcs/wordpress/wp-admin/includes/class-custom-background.php
deleted file mode 100644
index ea74ef4..0000000
--- a/srcs/wordpress/wp-admin/includes/class-custom-background.php
+++ /dev/null
@@ -1,616 +0,0 @@
-admin_header_callback = $admin_header_callback;
- $this->admin_image_div_callback = $admin_image_div_callback;
-
- add_action( 'admin_menu', array( $this, 'init' ) );
-
- add_action( 'wp_ajax_custom-background-add', array( $this, 'ajax_background_add' ) );
-
- // Unused since 3.5.0.
- add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) );
- }
-
- /**
- * Set up the hooks for the Custom Background admin page.
- *
- * @since 3.0.0
- */
- public function init() {
- $page = add_theme_page( __( 'Background' ), __( 'Background' ), 'edit_theme_options', 'custom-background', array( $this, 'admin_page' ) );
- if ( ! $page ) {
- return;
- }
-
- add_action( "load-{$page}", array( $this, 'admin_load' ) );
- add_action( "load-{$page}", array( $this, 'take_action' ), 49 );
- add_action( "load-{$page}", array( $this, 'handle_upload' ), 49 );
-
- if ( $this->admin_header_callback ) {
- add_action( "admin_head-{$page}", $this->admin_header_callback, 51 );
- }
- }
-
- /**
- * Set up the enqueue for the CSS & JavaScript files.
- *
- * @since 3.0.0
- */
- public function admin_load() {
- get_current_screen()->add_help_tab(
- array(
- 'id' => 'overview',
- 'title' => __( 'Overview' ),
- 'content' =>
- '' . __( 'You can customize the look of your site without touching any of your theme’s code by using a custom background. Your background can be an image or a color.' ) . '
' .
- '' . __( 'To use a background image, simply upload it or choose an image that has already been uploaded to your Media Library by clicking the “Choose Image” button. You can display a single instance of your image, or tile it to fill the screen. You can have your background fixed in place, so your site content moves on top of it, or you can have it scroll with your site.' ) . '
' .
- '' . __( 'You can also choose a background color by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '
' .
- '' . __( 'Don’t forget to click on the Save Changes button when you are finished.' ) . '
',
- )
- );
-
- get_current_screen()->set_help_sidebar(
- '' . __( 'For more information:' ) . '
' .
- '' . __( 'Documentation on Custom Background ' ) . '
' .
- '' . __( 'Support ' ) . '
'
- );
-
- wp_enqueue_media();
- wp_enqueue_script( 'custom-background' );
- wp_enqueue_style( 'wp-color-picker' );
- }
-
- /**
- * Execute custom background modification.
- *
- * @since 3.0.0
- */
- public function take_action() {
- if ( empty( $_POST ) ) {
- return;
- }
-
- if ( isset( $_POST['reset-background'] ) ) {
- check_admin_referer( 'custom-background-reset', '_wpnonce-custom-background-reset' );
- remove_theme_mod( 'background_image' );
- remove_theme_mod( 'background_image_thumb' );
- $this->updated = true;
- return;
- }
-
- if ( isset( $_POST['remove-background'] ) ) {
- // @TODO: Uploaded files are not removed here.
- check_admin_referer( 'custom-background-remove', '_wpnonce-custom-background-remove' );
- set_theme_mod( 'background_image', '' );
- set_theme_mod( 'background_image_thumb', '' );
- $this->updated = true;
- wp_safe_redirect( $_POST['_wp_http_referer'] );
- return;
- }
-
- if ( isset( $_POST['background-preset'] ) ) {
- check_admin_referer( 'custom-background' );
-
- if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) {
- $preset = $_POST['background-preset'];
- } else {
- $preset = 'default';
- }
-
- set_theme_mod( 'background_preset', $preset );
- }
-
- if ( isset( $_POST['background-position'] ) ) {
- check_admin_referer( 'custom-background' );
-
- $position = explode( ' ', $_POST['background-position'] );
-
- if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) {
- $position_x = $position[0];
- } else {
- $position_x = 'left';
- }
-
- if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) {
- $position_y = $position[1];
- } else {
- $position_y = 'top';
- }
-
- set_theme_mod( 'background_position_x', $position_x );
- set_theme_mod( 'background_position_y', $position_y );
- }
-
- if ( isset( $_POST['background-size'] ) ) {
- check_admin_referer( 'custom-background' );
-
- if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) {
- $size = $_POST['background-size'];
- } else {
- $size = 'auto';
- }
-
- set_theme_mod( 'background_size', $size );
- }
-
- if ( isset( $_POST['background-repeat'] ) ) {
- check_admin_referer( 'custom-background' );
-
- $repeat = $_POST['background-repeat'];
-
- if ( 'no-repeat' !== $repeat ) {
- $repeat = 'repeat';
- }
-
- set_theme_mod( 'background_repeat', $repeat );
- }
-
- if ( isset( $_POST['background-attachment'] ) ) {
- check_admin_referer( 'custom-background' );
-
- $attachment = $_POST['background-attachment'];
-
- if ( 'fixed' !== $attachment ) {
- $attachment = 'scroll';
- }
-
- set_theme_mod( 'background_attachment', $attachment );
- }
-
- if ( isset( $_POST['background-color'] ) ) {
- check_admin_referer( 'custom-background' );
- $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['background-color'] );
- if ( strlen( $color ) == 6 || strlen( $color ) == 3 ) {
- set_theme_mod( 'background_color', $color );
- } else {
- set_theme_mod( 'background_color', '' );
- }
- }
-
- $this->updated = true;
- }
-
- /**
- * Display the custom background page.
- *
- * @since 3.0.0
- */
- public function admin_page() {
- ?>
-
-
-
-
-
-
- Customizer.' ),
- admin_url( 'customize.php?autofocus[control]=background_image' )
- );
- ?>
-
-
-
-
- updated ) ) { ?>
-
-
- Visit your site to see how it looks.' ), home_url( '/' ) );
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
- false );
-
- $uploaded_file = $_FILES['import'];
- $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
- if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
- wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
- }
-
- $file = wp_handle_upload( $uploaded_file, $overrides );
-
- if ( isset( $file['error'] ) ) {
- wp_die( $file['error'] );
- }
-
- $url = $file['url'];
- $type = $file['type'];
- $file = $file['file'];
- $filename = wp_basename( $file );
-
- // Construct the object array
- $object = array(
- 'post_title' => $filename,
- 'post_content' => $url,
- 'post_mime_type' => $type,
- 'guid' => $url,
- 'context' => 'custom-background',
- );
-
- // Save the data
- $id = wp_insert_attachment( $object, $file );
-
- // Add the meta-data
- wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
- update_post_meta( $id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) );
-
- set_theme_mod( 'background_image', esc_url_raw( $url ) );
-
- $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
- set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
-
- /** This action is documented in wp-admin/includes/class-custom-image-header.php */
- do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication
- $this->updated = true;
- }
-
- /**
- * Ajax handler for adding custom background context to an attachment.
- *
- * Triggers when the user adds a new background image from the
- * Media Manager.
- *
- * @since 4.1.0
- */
- public function ajax_background_add() {
- check_ajax_referer( 'background-add', 'nonce' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_send_json_error();
- }
-
- $attachment_id = absint( $_POST['attachment_id'] );
- if ( $attachment_id < 1 ) {
- wp_send_json_error();
- }
-
- update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() );
-
- wp_send_json_success();
- }
-
- /**
- * @since 3.4.0
- * @deprecated 3.5.0
- *
- * @param array $form_fields
- * @return array $form_fields
- */
- public function attachment_fields_to_edit( $form_fields ) {
- return $form_fields;
- }
-
- /**
- * @since 3.4.0
- * @deprecated 3.5.0
- *
- * @param array $tabs
- * @return array $tabs
- */
- public function filter_upload_tabs( $tabs ) {
- return $tabs;
- }
-
- /**
- * @since 3.4.0
- * @deprecated 3.5.0
- */
- public function wp_set_background_image() {
- if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['attachment_id'] ) ) {
- exit;
- }
-
- $attachment_id = absint( $_POST['attachment_id'] );
-
- $sizes = array_keys(
- /** This filter is documented in wp-admin/includes/media.php */
- apply_filters(
- 'image_size_names_choose',
- array(
- 'thumbnail' => __( 'Thumbnail' ),
- 'medium' => __( 'Medium' ),
- 'large' => __( 'Large' ),
- 'full' => __( 'Full Size' ),
- )
- )
- );
-
- $size = 'thumbnail';
- if ( in_array( $_POST['size'], $sizes ) ) {
- $size = esc_attr( $_POST['size'] );
- }
-
- update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option( 'stylesheet' ) );
-
- $url = wp_get_attachment_image_src( $attachment_id, $size );
- $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
- set_theme_mod( 'background_image', esc_url_raw( $url[0] ) );
- set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) );
- exit;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-custom-image-header.php b/srcs/wordpress/wp-admin/includes/class-custom-image-header.php
deleted file mode 100644
index 12d307d..0000000
--- a/srcs/wordpress/wp-admin/includes/class-custom-image-header.php
+++ /dev/null
@@ -1,1515 +0,0 @@
-admin_header_callback = $admin_header_callback;
- $this->admin_image_div_callback = $admin_image_div_callback;
-
- add_action( 'admin_menu', array( $this, 'init' ) );
-
- add_action( 'customize_save_after', array( $this, 'customize_set_last_used' ) );
- add_action( 'wp_ajax_custom-header-crop', array( $this, 'ajax_header_crop' ) );
- add_action( 'wp_ajax_custom-header-add', array( $this, 'ajax_header_add' ) );
- add_action( 'wp_ajax_custom-header-remove', array( $this, 'ajax_header_remove' ) );
- }
-
- /**
- * Set up the hooks for the Custom Header admin page.
- *
- * @since 2.1.0
- */
- public function init() {
- $page = add_theme_page( __( 'Header' ), __( 'Header' ), 'edit_theme_options', 'custom-header', array( $this, 'admin_page' ) );
- if ( ! $page ) {
- return;
- }
-
- add_action( "admin_print_scripts-{$page}", array( $this, 'js_includes' ) );
- add_action( "admin_print_styles-{$page}", array( $this, 'css_includes' ) );
- add_action( "admin_head-{$page}", array( $this, 'help' ) );
- add_action( "admin_head-{$page}", array( $this, 'take_action' ), 50 );
- add_action( "admin_head-{$page}", array( $this, 'js' ), 50 );
- if ( $this->admin_header_callback ) {
- add_action( "admin_head-{$page}", $this->admin_header_callback, 51 );
- }
- }
-
- /**
- * Adds contextual help.
- *
- * @since 3.0.0
- */
- public function help() {
- get_current_screen()->add_help_tab(
- array(
- 'id' => 'overview',
- 'title' => __( 'Overview' ),
- 'content' =>
- '' . __( 'This screen is used to customize the header section of your theme.' ) . '
' .
- '' . __( 'You can choose from the theme’s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.' ) . '
',
- )
- );
-
- get_current_screen()->add_help_tab(
- array(
- 'id' => 'set-header-image',
- 'title' => __( 'Header Image' ),
- 'content' =>
- '
' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the “Choose Image” button.' ) . '
' .
- '' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you’d like and click the “Save Changes” button.' ) . '
' .
- '' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the “Random” radio button next to the Uploaded Images or Default Images section to enable this feature.' ) . '
' .
- '' . __( 'If you don’t want a header image to be displayed on your site at all, click the “Remove Header Image” button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click “Save Changes”.' ) . '
',
- )
- );
-
- get_current_screen()->add_help_tab(
- array(
- 'id' => 'set-header-text',
- 'title' => __( 'Header Text' ),
- 'content' =>
- '' . sprintf(
- /* translators: %s: URL to General Settings screen. */
- __( 'For most themes, the header text is your Site Title and Tagline, as defined in the General Settings section.' ),
- admin_url( 'options-general.php' )
- ) .
- '
' .
- '' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '
' .
- '' . __( 'Don’t forget to click “Save Changes” when you’re done!' ) . '
',
- )
- );
-
- get_current_screen()->set_help_sidebar(
- '' . __( 'For more information:' ) . '
' .
- '' . __( 'Documentation on Custom Header ' ) . '
' .
- '' . __( 'Support ' ) . '
'
- );
- }
-
- /**
- * Get the current step.
- *
- * @since 2.6.0
- *
- * @return int Current step
- */
- public function step() {
- if ( ! isset( $_GET['step'] ) ) {
- return 1;
- }
-
- $step = (int) $_GET['step'];
- if ( $step < 1 || 3 < $step ||
- ( 2 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) ||
- ( 3 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) )
- ) {
- return 1;
- }
-
- return $step;
- }
-
- /**
- * Set up the enqueue for the JavaScript files.
- *
- * @since 2.1.0
- */
- public function js_includes() {
- $step = $this->step();
-
- if ( ( 1 == $step || 3 == $step ) ) {
- wp_enqueue_media();
- wp_enqueue_script( 'custom-header' );
- if ( current_theme_supports( 'custom-header', 'header-text' ) ) {
- wp_enqueue_script( 'wp-color-picker' );
- }
- } elseif ( 2 == $step ) {
- wp_enqueue_script( 'imgareaselect' );
- }
- }
-
- /**
- * Set up the enqueue for the CSS files
- *
- * @since 2.7.0
- */
- public function css_includes() {
- $step = $this->step();
-
- if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) {
- wp_enqueue_style( 'wp-color-picker' );
- } elseif ( 2 == $step ) {
- wp_enqueue_style( 'imgareaselect' );
- }
- }
-
- /**
- * Execute custom header modification.
- *
- * @since 2.6.0
- */
- public function take_action() {
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- return;
- }
-
- if ( empty( $_POST ) ) {
- return;
- }
-
- $this->updated = true;
-
- if ( isset( $_POST['resetheader'] ) ) {
- check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
- $this->reset_header_image();
- return;
- }
-
- if ( isset( $_POST['removeheader'] ) ) {
- check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
- $this->remove_header_image();
- return;
- }
-
- if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) {
- check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
- set_theme_mod( 'header_textcolor', 'blank' );
- } elseif ( isset( $_POST['text-color'] ) ) {
- check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
- $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] );
- $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['text-color'] );
- if ( strlen( $color ) == 6 || strlen( $color ) == 3 ) {
- set_theme_mod( 'header_textcolor', $color );
- } elseif ( ! $color ) {
- set_theme_mod( 'header_textcolor', 'blank' );
- }
- }
-
- if ( isset( $_POST['default-header'] ) ) {
- check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
- $this->set_header_image( $_POST['default-header'] );
- return;
- }
- }
-
- /**
- * Process the default headers
- *
- * @since 3.0.0
- *
- * @global array $_wp_default_headers
- */
- public function process_default_headers() {
- global $_wp_default_headers;
-
- if ( ! isset( $_wp_default_headers ) ) {
- return;
- }
-
- if ( ! empty( $this->default_headers ) ) {
- return;
- }
-
- $this->default_headers = $_wp_default_headers;
- $template_directory_uri = get_template_directory_uri();
- $stylesheet_directory_uri = get_stylesheet_directory_uri();
- foreach ( array_keys( $this->default_headers ) as $header ) {
- $this->default_headers[ $header ]['url'] = sprintf( $this->default_headers[ $header ]['url'], $template_directory_uri, $stylesheet_directory_uri );
- $this->default_headers[ $header ]['thumbnail_url'] = sprintf( $this->default_headers[ $header ]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri );
- }
- }
-
- /**
- * Display UI for selecting one of several default headers.
- *
- * Show the random image option if this theme has multiple header images.
- * Random image option is on by default if no header has been set.
- *
- * @since 3.0.0
- *
- * @param string $type The header type. One of 'default' (for the Uploaded Images control)
- * or 'uploaded' (for the Uploaded Images control).
- */
- public function show_header_selector( $type = 'default' ) {
- if ( 'default' == $type ) {
- $headers = $this->default_headers;
- } else {
- $headers = get_uploaded_header_images();
- $type = 'uploaded';
- }
-
- if ( 1 < count( $headers ) ) {
- echo '';
- echo ' ';
- _e( 'Random: Show a different image on each page.' );
- echo ' ';
- echo '
';
- }
-
- echo '';
- }
-
- /**
- * Execute JavaScript depending on step.
- *
- * @since 2.1.0
- */
- public function js() {
- $step = $this->step();
- if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) {
- $this->js_1();
- } elseif ( 2 == $step ) {
- $this->js_2();
- }
- }
-
- /**
- * Display JavaScript based on Step 1 and 3.
- *
- * @since 2.6.0
- */
- public function js_1() {
- $default_color = '';
- if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
- $default_color = get_theme_support( 'custom-header', 'default-text-color' );
- if ( $default_color && false === strpos( $default_color, '#' ) ) {
- $default_color = '#' . $default_color;
- }
- }
- ?>
-
-
-
- process_default_headers();
- ?>
-
-
-
-
-
-
-
- Customizer.' ),
- admin_url( 'customize.php?autofocus[control]=header_image' )
- );
- ?>
-
-
-
-
- updated ) ) { ?>
-
-
- Visit your site to see how it looks.' ), home_url( '/' ) );
- ?>
-
-
-
-
-
-
-
-
-
-
-
- ' . __( 'Something went wrong.' ) . '' .
- '' . __( 'The current theme does not support uploading a custom header image.' ) . '
',
- 403
- );
- }
-
- if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
- $attachment_id = absint( $_GET['file'] );
- $file = get_attached_file( $attachment_id, true );
- $url = wp_get_attachment_image_src( $attachment_id, 'full' );
- $url = $url[0];
- } elseif ( isset( $_POST ) ) {
- $data = $this->step_2_manage_upload();
- $attachment_id = $data['attachment_id'];
- $file = $data['file'];
- $url = $data['url'];
- }
-
- if ( file_exists( $file ) ) {
- list( $width, $height, $type, $attr ) = @getimagesize( $file );
- } else {
- $data = wp_get_attachment_metadata( $attachment_id );
- $height = isset( $data['height'] ) ? $data['height'] : 0;
- $width = isset( $data['width'] ) ? $data['width'] : 0;
- unset( $data );
- }
-
- $max_width = 0;
- // For flex, limit size of image displayed to 1500px unless theme says otherwise
- if ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
- $max_width = 1500;
- }
-
- if ( current_theme_supports( 'custom-header', 'max-width' ) ) {
- $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
- }
- $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) );
-
- // If flexible height isn't supported and the image is the exact right size
- if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' )
- && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) ) {
- // Add the meta-data
- if ( file_exists( $file ) ) {
- wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
- }
-
- $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
-
- /**
- * Fires after the header image is set or an error is returned.
- *
- * @since 2.1.0
- *
- * @param string $file Path to the file.
- * @param int $attachment_id Attachment ID.
- */
- do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication
-
- return $this->finished();
- } elseif ( $width > $max_width ) {
- $oitar = $width / $max_width;
- $image = wp_crop_image( $attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file ) );
- if ( ! $image || is_wp_error( $image ) ) {
- wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
- }
-
- /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
- $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication
-
- $url = str_replace( wp_basename( $url ), wp_basename( $image ), $url );
- $width = $width / $oitar;
- $height = $height / $oitar;
- } else {
- $oitar = 1;
- }
- ?>
-
-
- false );
-
- $uploaded_file = $_FILES['import'];
- $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
- if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
- wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
- }
-
- $file = wp_handle_upload( $uploaded_file, $overrides );
-
- if ( isset( $file['error'] ) ) {
- wp_die( $file['error'], __( 'Image Upload Error' ) );
- }
-
- $url = $file['url'];
- $type = $file['type'];
- $file = $file['file'];
- $filename = wp_basename( $file );
-
- // Construct the object array
- $object = array(
- 'post_title' => $filename,
- 'post_content' => $url,
- 'post_mime_type' => $type,
- 'guid' => $url,
- 'context' => 'custom-header',
- );
-
- // Save the data
- $attachment_id = wp_insert_attachment( $object, $file );
- return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
- }
-
- /**
- * Display third step of custom header image page.
- *
- * @since 2.1.0
- * @since 4.4.0 Switched to using wp_get_attachment_url() instead of the guid
- * for retrieving the header image URL.
- */
- public function step_3() {
- check_admin_referer( 'custom-header-crop-image' );
-
- if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
- wp_die(
- '' . __( 'Something went wrong.' ) . ' ' .
- '' . __( 'The current theme does not support uploading a custom header image.' ) . '
',
- 403
- );
- }
-
- if ( ! empty( $_POST['skip-cropping'] ) && ! ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) ) {
- wp_die(
- '' . __( 'Something went wrong.' ) . ' ' .
- '' . __( 'The current theme does not support a flexible sized header image.' ) . '
',
- 403
- );
- }
-
- if ( $_POST['oitar'] > 1 ) {
- $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
- $_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
- $_POST['width'] = $_POST['width'] * $_POST['oitar'];
- $_POST['height'] = $_POST['height'] * $_POST['oitar'];
- }
-
- $attachment_id = absint( $_POST['attachment_id'] );
- $original = get_attached_file( $attachment_id );
-
- $dimensions = $this->get_header_dimensions(
- array(
- 'height' => $_POST['height'],
- 'width' => $_POST['width'],
- )
- );
- $height = $dimensions['dst_height'];
- $width = $dimensions['dst_width'];
-
- if ( empty( $_POST['skip-cropping'] ) ) {
- $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $width, $height );
- } elseif ( ! empty( $_POST['create-new-attachment'] ) ) {
- $cropped = _copy_image_file( $attachment_id );
- } else {
- $cropped = get_attached_file( $attachment_id );
- }
-
- if ( ! $cropped || is_wp_error( $cropped ) ) {
- wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
- }
-
- /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
- $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
-
- $object = $this->create_attachment_object( $cropped, $attachment_id );
-
- if ( ! empty( $_POST['create-new-attachment'] ) ) {
- unset( $object['ID'] );
- }
-
- // Update the attachment
- $attachment_id = $this->insert_attachment( $object, $cropped );
-
- $url = wp_get_attachment_url( $attachment_id );
- $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
-
- // Cleanup.
- $medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original );
- if ( file_exists( $medium ) ) {
- wp_delete_file( $medium );
- }
-
- if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
- wp_delete_file( $original );
- }
-
- return $this->finished();
- }
-
- /**
- * Display last step of custom header image page.
- *
- * @since 2.1.0
- */
- public function finished() {
- $this->updated = true;
- $this->step_1();
- }
-
- /**
- * Display the page based on the current step.
- *
- * @since 2.1.0
- */
- public function admin_page() {
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_die( __( 'Sorry, you are not allowed to customize headers.' ) );
- }
- $step = $this->step();
- if ( 2 == $step ) {
- $this->step_2();
- } elseif ( 3 == $step ) {
- $this->step_3();
- } else {
- $this->step_1();
- }
- }
-
- /**
- * Unused since 3.5.0.
- *
- * @since 3.4.0
- *
- * @param array $form_fields
- * @return array $form_fields
- */
- public function attachment_fields_to_edit( $form_fields ) {
- return $form_fields;
- }
-
- /**
- * Unused since 3.5.0.
- *
- * @since 3.4.0
- *
- * @param array $tabs
- * @return array $tabs
- */
- public function filter_upload_tabs( $tabs ) {
- return $tabs;
- }
-
- /**
- * Choose a header image, selected from existing uploaded and default headers,
- * or provide an array of uploaded header data (either new, or from media library).
- *
- * @since 3.4.0
- *
- * @param mixed $choice Which header image to select. Allows for values of 'random-default-image',
- * for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling
- * among the uploaded images; the key of a default image registered for that theme; and
- * the key of an image uploaded for that theme (the attachment ID of the image).
- * Or an array of arguments: attachment_id, url, width, height. All are required.
- */
- final public function set_header_image( $choice ) {
- if ( is_array( $choice ) || is_object( $choice ) ) {
- $choice = (array) $choice;
- if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) {
- return;
- }
-
- $choice['url'] = esc_url_raw( $choice['url'] );
-
- $header_image_data = (object) array(
- 'attachment_id' => $choice['attachment_id'],
- 'url' => $choice['url'],
- 'thumbnail_url' => $choice['url'],
- 'height' => $choice['height'],
- 'width' => $choice['width'],
- );
-
- update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() );
- set_theme_mod( 'header_image', $choice['url'] );
- set_theme_mod( 'header_image_data', $header_image_data );
- return;
- }
-
- if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ) ) ) {
- set_theme_mod( 'header_image', $choice );
- remove_theme_mod( 'header_image_data' );
- return;
- }
-
- $uploaded = get_uploaded_header_images();
- if ( $uploaded && isset( $uploaded[ $choice ] ) ) {
- $header_image_data = $uploaded[ $choice ];
-
- } else {
- $this->process_default_headers();
- if ( isset( $this->default_headers[ $choice ] ) ) {
- $header_image_data = $this->default_headers[ $choice ];
- } else {
- return;
- }
- }
-
- set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ) );
- set_theme_mod( 'header_image_data', $header_image_data );
- }
-
- /**
- * Remove a header image.
- *
- * @since 3.4.0
- */
- final public function remove_header_image() {
- $this->set_header_image( 'remove-header' );
- }
-
- /**
- * Reset a header image to the default image for the theme.
- *
- * This method does not do anything if the theme does not have a default header image.
- *
- * @since 3.4.0
- */
- final public function reset_header_image() {
- $this->process_default_headers();
- $default = get_theme_support( 'custom-header', 'default-image' );
-
- if ( ! $default ) {
- $this->remove_header_image();
- return;
- }
- $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
-
- $default_data = array();
- foreach ( $this->default_headers as $header => $details ) {
- if ( $details['url'] == $default ) {
- $default_data = $details;
- break;
- }
- }
-
- set_theme_mod( 'header_image', $default );
- set_theme_mod( 'header_image_data', (object) $default_data );
- }
-
- /**
- * Calculate width and height based on what the currently selected theme supports.
- *
- * @since 3.9.0
- *
- * @param array $dimensions
- * @return array dst_height and dst_width of header image.
- */
- final public function get_header_dimensions( $dimensions ) {
- $max_width = 0;
- $width = absint( $dimensions['width'] );
- $height = absint( $dimensions['height'] );
- $theme_height = get_theme_support( 'custom-header', 'height' );
- $theme_width = get_theme_support( 'custom-header', 'width' );
- $has_flex_width = current_theme_supports( 'custom-header', 'flex-width' );
- $has_flex_height = current_theme_supports( 'custom-header', 'flex-height' );
- $has_max_width = current_theme_supports( 'custom-header', 'max-width' );
- $dst = array(
- 'dst_height' => null,
- 'dst_width' => null,
- );
-
- // For flex, limit size of image displayed to 1500px unless theme says otherwise
- if ( $has_flex_width ) {
- $max_width = 1500;
- }
-
- if ( $has_max_width ) {
- $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
- }
- $max_width = max( $max_width, $theme_width );
-
- if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) {
- $dst['dst_height'] = absint( $height * ( $max_width / $width ) );
- } elseif ( $has_flex_height && $has_flex_width ) {
- $dst['dst_height'] = $height;
- } else {
- $dst['dst_height'] = $theme_height;
- }
-
- if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) {
- $dst['dst_width'] = absint( $width * ( $max_width / $width ) );
- } elseif ( $has_flex_width && $has_flex_height ) {
- $dst['dst_width'] = $width;
- } else {
- $dst['dst_width'] = $theme_width;
- }
-
- return $dst;
- }
-
- /**
- * Create an attachment 'object'.
- *
- * @since 3.9.0
- *
- * @param string $cropped Cropped image URL.
- * @param int $parent_attachment_id Attachment ID of parent image.
- * @return array Attachment object.
- */
- final public function create_attachment_object( $cropped, $parent_attachment_id ) {
- $parent = get_post( $parent_attachment_id );
- $parent_url = wp_get_attachment_url( $parent->ID );
- $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
-
- $size = @getimagesize( $cropped );
- $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
-
- $object = array(
- 'ID' => $parent_attachment_id,
- 'post_title' => wp_basename( $cropped ),
- 'post_mime_type' => $image_type,
- 'guid' => $url,
- 'context' => 'custom-header',
- 'post_parent' => $parent_attachment_id,
- );
-
- return $object;
- }
-
- /**
- * Insert an attachment and its metadata.
- *
- * @since 3.9.0
- *
- * @param array $object Attachment object.
- * @param string $cropped Cropped image URL.
- * @return int Attachment ID.
- */
- final public function insert_attachment( $object, $cropped ) {
- $parent_id = isset( $object['post_parent'] ) ? $object['post_parent'] : null;
- unset( $object['post_parent'] );
-
- $attachment_id = wp_insert_attachment( $object, $cropped );
- $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
-
- // If this is a crop, save the original attachment ID as metadata.
- if ( $parent_id ) {
- $metadata['attachment_parent'] = $parent_id;
- }
-
- /**
- * Filters the header image attachment metadata.
- *
- * @since 3.9.0
- *
- * @see wp_generate_attachment_metadata()
- *
- * @param array $metadata Attachment metadata.
- */
- $metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
-
- wp_update_attachment_metadata( $attachment_id, $metadata );
-
- return $attachment_id;
- }
-
- /**
- * Gets attachment uploaded by Media Manager, crops it, then saves it as a
- * new object. Returns JSON-encoded object details.
- *
- * @since 3.9.0
- */
- public function ajax_header_crop() {
- check_ajax_referer( 'image_editor-' . $_POST['id'], 'nonce' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_send_json_error();
- }
-
- if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
- wp_send_json_error();
- }
-
- $crop_details = $_POST['cropDetails'];
-
- $dimensions = $this->get_header_dimensions(
- array(
- 'height' => $crop_details['height'],
- 'width' => $crop_details['width'],
- )
- );
-
- $attachment_id = absint( $_POST['id'] );
-
- $cropped = wp_crop_image(
- $attachment_id,
- (int) $crop_details['x1'],
- (int) $crop_details['y1'],
- (int) $crop_details['width'],
- (int) $crop_details['height'],
- (int) $dimensions['dst_width'],
- (int) $dimensions['dst_height']
- );
-
- if ( ! $cropped || is_wp_error( $cropped ) ) {
- wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) );
- }
-
- /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
- $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
-
- $object = $this->create_attachment_object( $cropped, $attachment_id );
-
- $previous = $this->get_previous_crop( $object );
-
- if ( $previous ) {
- $object['ID'] = $previous;
- } else {
- unset( $object['ID'] );
- }
-
- $new_attachment_id = $this->insert_attachment( $object, $cropped );
-
- $object['attachment_id'] = $new_attachment_id;
- $object['url'] = wp_get_attachment_url( $new_attachment_id );
-
- $object['width'] = $dimensions['dst_width'];
- $object['height'] = $dimensions['dst_height'];
-
- wp_send_json_success( $object );
- }
-
- /**
- * Given an attachment ID for a header image, updates its "last used"
- * timestamp to now.
- *
- * Triggered when the user tries adds a new header image from the
- * Media Manager, even if s/he doesn't save that change.
- *
- * @since 3.9.0
- */
- public function ajax_header_add() {
- check_ajax_referer( 'header-add', 'nonce' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_send_json_error();
- }
-
- $attachment_id = absint( $_POST['attachment_id'] );
- if ( $attachment_id < 1 ) {
- wp_send_json_error();
- }
-
- $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
- update_post_meta( $attachment_id, $key, time() );
- update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
-
- wp_send_json_success();
- }
-
- /**
- * Given an attachment ID for a header image, unsets it as a user-uploaded
- * header image for the current theme.
- *
- * Triggered when the user clicks the overlay "X" button next to each image
- * choice in the Customizer's Header tool.
- *
- * @since 3.9.0
- */
- public function ajax_header_remove() {
- check_ajax_referer( 'header-remove', 'nonce' );
-
- if ( ! current_user_can( 'edit_theme_options' ) ) {
- wp_send_json_error();
- }
-
- $attachment_id = absint( $_POST['attachment_id'] );
- if ( $attachment_id < 1 ) {
- wp_send_json_error();
- }
-
- $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
- delete_post_meta( $attachment_id, $key );
- delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
-
- wp_send_json_success();
- }
-
- /**
- * Updates the last-used postmeta on a header image attachment after saving a new header image via the Customizer.
- *
- * @since 3.9.0
- *
- * @param WP_Customize_Manager $wp_customize Customize manager.
- */
- public function customize_set_last_used( $wp_customize ) {
-
- $header_image_data_setting = $wp_customize->get_setting( 'header_image_data' );
- if ( ! $header_image_data_setting ) {
- return;
- }
- $data = $header_image_data_setting->post_value();
-
- if ( ! isset( $data['attachment_id'] ) ) {
- return;
- }
-
- $attachment_id = $data['attachment_id'];
- $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
- update_post_meta( $attachment_id, $key, time() );
- }
-
- /**
- * Gets the details of default header images if defined.
- *
- * @since 3.9.0
- *
- * @return array Default header images.
- */
- public function get_default_header_images() {
- $this->process_default_headers();
-
- // Get the default image if there is one.
- $default = get_theme_support( 'custom-header', 'default-image' );
-
- if ( ! $default ) { // If not,
- return $this->default_headers; // easy peasy.
- }
-
- $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
- $already_has_default = false;
-
- foreach ( $this->default_headers as $k => $h ) {
- if ( $h['url'] === $default ) {
- $already_has_default = true;
- break;
- }
- }
-
- if ( $already_has_default ) {
- return $this->default_headers;
- }
-
- // If the one true image isn't included in the default set, prepend it.
- $header_images = array();
- $header_images['default'] = array(
- 'url' => $default,
- 'thumbnail_url' => $default,
- 'description' => 'Default',
- );
-
- // The rest of the set comes after.
- return array_merge( $header_images, $this->default_headers );
- }
-
- /**
- * Gets the previously uploaded header images.
- *
- * @since 3.9.0
- *
- * @return array Uploaded header images.
- */
- public function get_uploaded_header_images() {
- $header_images = get_uploaded_header_images();
- $timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
- $alt_text_key = '_wp_attachment_image_alt';
-
- foreach ( $header_images as &$header_image ) {
- $header_meta = get_post_meta( $header_image['attachment_id'] );
- $header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : '';
- $header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : '';
- }
-
- return $header_images;
- }
-
- /**
- * Get the ID of a previous crop from the same base image.
- *
- * @since 4.9.0
- *
- * @param array $object A crop attachment object.
- * @return int|false An attachment ID if one exists. False if none.
- */
- public function get_previous_crop( $object ) {
- $header_images = $this->get_uploaded_header_images();
-
- // Bail early if there are no header images.
- if ( empty( $header_images ) ) {
- return false;
- }
-
- $previous = false;
-
- foreach ( $header_images as $image ) {
- if ( $image['attachment_parent'] === $object['post_parent'] ) {
- $previous = $image['attachment_id'];
- break;
- }
- }
-
- return $previous;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-file-upload-upgrader.php b/srcs/wordpress/wp-admin/includes/class-file-upload-upgrader.php
deleted file mode 100644
index 52e103c..0000000
--- a/srcs/wordpress/wp-admin/includes/class-file-upload-upgrader.php
+++ /dev/null
@@ -1,133 +0,0 @@
- false,
- 'test_type' => false,
- );
- $file = wp_handle_upload( $_FILES[ $form ], $overrides );
-
- if ( isset( $file['error'] ) ) {
- wp_die( $file['error'] );
- }
-
- $this->filename = $_FILES[ $form ]['name'];
- $this->package = $file['file'];
-
- // Construct the object array
- $object = array(
- 'post_title' => $this->filename,
- 'post_content' => $file['url'],
- 'post_mime_type' => $file['type'],
- 'guid' => $file['url'],
- 'context' => 'upgrader',
- 'post_status' => 'private',
- );
-
- // Save the data.
- $this->id = wp_insert_attachment( $object, $file['file'] );
-
- // Schedule a cleanup for 2 hours from now in case of failed installation.
- wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) );
-
- } elseif ( is_numeric( $_GET[ $urlholder ] ) ) {
- // Numeric Package = previously uploaded file, see above.
- $this->id = (int) $_GET[ $urlholder ];
- $attachment = get_post( $this->id );
- if ( empty( $attachment ) ) {
- wp_die( __( 'Please select a file' ) );
- }
-
- $this->filename = $attachment->post_title;
- $this->package = get_attached_file( $attachment->ID );
- } else {
- // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
- $uploads = wp_upload_dir();
- if ( ! ( $uploads && false === $uploads['error'] ) ) {
- wp_die( $uploads['error'] );
- }
-
- $this->filename = sanitize_file_name( $_GET[ $urlholder ] );
- $this->package = $uploads['basedir'] . '/' . $this->filename;
-
- if ( 0 !== strpos( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) {
- wp_die( __( 'Please select a file' ) );
- }
- }
- }
-
- /**
- * Delete the attachment/uploaded file.
- *
- * @since 3.2.2
- *
- * @return bool Whether the cleanup was successful.
- */
- public function cleanup() {
- if ( $this->id ) {
- wp_delete_attachment( $this->id );
-
- } elseif ( file_exists( $this->package ) ) {
- return @unlink( $this->package );
- }
-
- return true;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-ftp-pure.php b/srcs/wordpress/wp-admin/includes/class-ftp-pure.php
deleted file mode 100644
index c40df63..0000000
--- a/srcs/wordpress/wp-admin/includes/class-ftp-pure.php
+++ /dev/null
@@ -1,186 +0,0 @@
-
-//
-//
-
- function _settimeout($sock) {
- if(!@stream_set_timeout($sock, $this->_timeout)) {
- $this->PushError('_settimeout','socket set send timeout');
- $this->_quit();
- return FALSE;
- }
- return TRUE;
- }
-
- function _connect($host, $port) {
- $this->SendMSG("Creating socket");
- $sock = @fsockopen($host, $port, $errno, $errstr, $this->_timeout);
- if (!$sock) {
- $this->PushError('_connect','socket connect failed', $errstr." (".$errno.")");
- return FALSE;
- }
- $this->_connected=true;
- return $sock;
- }
-
- function _readmsg($fnction="_readmsg"){
- if(!$this->_connected) {
- $this->PushError($fnction, 'Connect first');
- return FALSE;
- }
- $result=true;
- $this->_message="";
- $this->_code=0;
- $go=true;
- do {
- $tmp=@fgets($this->_ftp_control_sock, 512);
- if($tmp===false) {
- $go=$result=false;
- $this->PushError($fnction,'Read failed');
- } else {
- $this->_message.=$tmp;
- if(preg_match("/^([0-9]{3})(-(.*[".CRLF."]{1,2})+\\1)? [^".CRLF."]+[".CRLF."]{1,2}$/", $this->_message, $regs)) $go=false;
- }
- } while($go);
- if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
- $this->_code=(int)$regs[1];
- return $result;
- }
-
- function _exec($cmd, $fnction="_exec") {
- if(!$this->_ready) {
- $this->PushError($fnction,'Connect first');
- return FALSE;
- }
- if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
- $status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
- if($status===false) {
- $this->PushError($fnction,'socket write failed');
- return FALSE;
- }
- $this->_lastaction=time();
- if(!$this->_readmsg($fnction)) return FALSE;
- return TRUE;
- }
-
- function _data_prepare($mode=FTP_ASCII) {
- if(!$this->_settype($mode)) return FALSE;
- if($this->_passive) {
- if(!$this->_exec("PASV", "pasv")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
- $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
- $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- $this->_ftp_data_sock=@fsockopen($this->_datahost, $this->_dataport, $errno, $errstr, $this->_timeout);
- if(!$this->_ftp_data_sock) {
- $this->PushError("_data_prepare","fsockopen fails", $errstr." (".$errno.")");
- $this->_data_close();
- return FALSE;
- }
- else $this->_ftp_data_sock;
- } else {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- return TRUE;
- }
-
- function _data_read($mode=FTP_ASCII, $fp=NULL) {
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- while (!feof($this->_ftp_data_sock)) {
- $block=fread($this->_ftp_data_sock, $this->_ftp_buff_size);
- if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
- if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
- else $out.=$block;
- }
- return $out;
- }
-
- function _data_write($mode=FTP_ASCII, $fp=NULL) {
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Only passive connections available!");
- return FALSE;
- }
- if(is_resource($fp)) {
- while(!feof($fp)) {
- $block=fread($fp, $this->_ftp_buff_size);
- if(!$this->_data_write_block($mode, $block)) return false;
- }
- } elseif(!$this->_data_write_block($mode, $fp)) return false;
- return TRUE;
- }
-
- function _data_write_block($mode, $block) {
- if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
- do {
- if(($t=@fwrite($this->_ftp_data_sock, $block))===FALSE) {
- $this->PushError("_data_write","Can't write to socket");
- return FALSE;
- }
- $block=substr($block, $t);
- } while(!empty($block));
- return true;
- }
-
- function _data_close() {
- @fclose($this->_ftp_data_sock);
- $this->SendMSG("Disconnected data from remote host");
- return TRUE;
- }
-
- function _quit($force=FALSE) {
- if($this->_connected or $force) {
- @fclose($this->_ftp_control_sock);
- $this->_connected=false;
- $this->SendMSG("Socket closed");
- }
- }
-}
-
-?>
diff --git a/srcs/wordpress/wp-admin/includes/class-ftp-sockets.php b/srcs/wordpress/wp-admin/includes/class-ftp-sockets.php
deleted file mode 100644
index 1ebedc7..0000000
--- a/srcs/wordpress/wp-admin/includes/class-ftp-sockets.php
+++ /dev/null
@@ -1,246 +0,0 @@
-
-//
-//
-
- function _settimeout($sock) {
- if(!@socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
- $this->PushError('_connect','socket set receive timeout',socket_strerror(socket_last_error($sock)));
- @socket_close($sock);
- return FALSE;
- }
- if(!@socket_set_option($sock, SOL_SOCKET , SO_SNDTIMEO, array("sec"=>$this->_timeout, "usec"=>0))) {
- $this->PushError('_connect','socket set send timeout',socket_strerror(socket_last_error($sock)));
- @socket_close($sock);
- return FALSE;
- }
- return true;
- }
-
- function _connect($host, $port) {
- $this->SendMSG("Creating socket");
- if(!($sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
- $this->PushError('_connect','socket create failed',socket_strerror(socket_last_error($sock)));
- return FALSE;
- }
- if(!$this->_settimeout($sock)) return FALSE;
- $this->SendMSG("Connecting to \"".$host.":".$port."\"");
- if (!($res = @socket_connect($sock, $host, $port))) {
- $this->PushError('_connect','socket connect failed',socket_strerror(socket_last_error($sock)));
- @socket_close($sock);
- return FALSE;
- }
- $this->_connected=true;
- return $sock;
- }
-
- function _readmsg($fnction="_readmsg"){
- if(!$this->_connected) {
- $this->PushError($fnction,'Connect first');
- return FALSE;
- }
- $result=true;
- $this->_message="";
- $this->_code=0;
- $go=true;
- do {
- $tmp=@socket_read($this->_ftp_control_sock, 4096, PHP_BINARY_READ);
- if($tmp===false) {
- $go=$result=false;
- $this->PushError($fnction,'Read failed', socket_strerror(socket_last_error($this->_ftp_control_sock)));
- } else {
- $this->_message.=$tmp;
- $go = !preg_match("/^([0-9]{3})(-.+\\1)? [^".CRLF."]+".CRLF."$/Us", $this->_message, $regs);
- }
- } while($go);
- if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
- $this->_code=(int)$regs[1];
- return $result;
- }
-
- function _exec($cmd, $fnction="_exec") {
- if(!$this->_ready) {
- $this->PushError($fnction,'Connect first');
- return FALSE;
- }
- if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
- $status=@socket_write($this->_ftp_control_sock, $cmd.CRLF);
- if($status===false) {
- $this->PushError($fnction,'socket write failed', socket_strerror(socket_last_error($this->stream)));
- return FALSE;
- }
- $this->_lastaction=time();
- if(!$this->_readmsg($fnction)) return FALSE;
- return TRUE;
- }
-
- function _data_prepare($mode=FTP_ASCII) {
- if(!$this->_settype($mode)) return FALSE;
- $this->SendMSG("Creating data socket");
- $this->_ftp_data_sock = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- if ($this->_ftp_data_sock < 0) {
- $this->PushError('_data_prepare','socket create failed',socket_strerror(socket_last_error($this->_ftp_data_sock)));
- return FALSE;
- }
- if(!$this->_settimeout($this->_ftp_data_sock)) {
- $this->_data_close();
- return FALSE;
- }
- if($this->_passive) {
- if(!$this->_exec("PASV", "pasv")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $ip_port = explode(",", preg_replace("/^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*$/s", "\\1", $this->_message));
- $this->_datahost=$ip_port[0].".".$ip_port[1].".".$ip_port[2].".".$ip_port[3];
- $this->_dataport=(((int)$ip_port[4])<<8) + ((int)$ip_port[5]);
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- if(!@socket_connect($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
- $this->PushError("_data_prepare","socket_connect", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- else $this->_ftp_temp_sock=$this->_ftp_data_sock;
- } else {
- if(!@socket_getsockname($this->_ftp_control_sock, $addr, $port)) {
- $this->PushError("_data_prepare","can't get control socket information", socket_strerror(socket_last_error($this->_ftp_control_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!@socket_bind($this->_ftp_data_sock,$addr)){
- $this->PushError("_data_prepare","can't bind data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!@socket_listen($this->_ftp_data_sock)) {
- $this->PushError("_data_prepare","can't listen data socket", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!@socket_getsockname($this->_ftp_data_sock, $this->_datahost, $this->_dataport)) {
- $this->PushError("_data_prepare","can't get data socket information", socket_strerror(socket_last_error($this->_ftp_data_sock)));
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_exec('PORT '.str_replace('.',',',$this->_datahost.'.'.($this->_dataport>>8).'.'.($this->_dataport&0x00FF)), "_port")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- }
- return TRUE;
- }
-
- function _data_read($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->_eol_code[$this->OS_local];
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
- if($this->_ftp_temp_sock===FALSE) {
- $this->PushError("_data_read","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
- $this->_data_close();
- return FALSE;
- }
- }
-
- while(($block=@socket_read($this->_ftp_temp_sock, $this->_ftp_buff_size, PHP_BINARY_READ))!==false) {
- if($block==="") break;
- if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_local], $block);
- if(is_resource($fp)) $out+=fwrite($fp, $block, strlen($block));
- else $out.=$block;
- }
- return $out;
- }
-
- function _data_write($mode=FTP_ASCII, $fp=NULL) {
- $NewLine=$this->_eol_code[$this->OS_local];
- if(is_resource($fp)) $out=0;
- else $out="";
- if(!$this->_passive) {
- $this->SendMSG("Connecting to ".$this->_datahost.":".$this->_dataport);
- $this->_ftp_temp_sock=socket_accept($this->_ftp_data_sock);
- if($this->_ftp_temp_sock===FALSE) {
- $this->PushError("_data_write","socket_accept", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
- $this->_data_close();
- return false;
- }
- }
- if(is_resource($fp)) {
- while(!feof($fp)) {
- $block=fread($fp, $this->_ftp_buff_size);
- if(!$this->_data_write_block($mode, $block)) return false;
- }
- } elseif(!$this->_data_write_block($mode, $fp)) return false;
- return true;
- }
-
- function _data_write_block($mode, $block) {
- if($mode!=FTP_BINARY) $block=preg_replace("/\r\n|\r|\n/", $this->_eol_code[$this->OS_remote], $block);
- do {
- if(($t=@socket_write($this->_ftp_temp_sock, $block))===FALSE) {
- $this->PushError("_data_write","socket_write", socket_strerror(socket_last_error($this->_ftp_temp_sock)));
- $this->_data_close();
- return FALSE;
- }
- $block=substr($block, $t);
- } while(!empty($block));
- return true;
- }
-
- function _data_close() {
- @socket_close($this->_ftp_temp_sock);
- @socket_close($this->_ftp_data_sock);
- $this->SendMSG("Disconnected data from remote host");
- return TRUE;
- }
-
- function _quit() {
- if($this->_connected) {
- @socket_close($this->_ftp_control_sock);
- $this->_connected=false;
- $this->SendMSG("Socket closed");
- }
- }
-}
-?>
diff --git a/srcs/wordpress/wp-admin/includes/class-ftp.php b/srcs/wordpress/wp-admin/includes/class-ftp.php
deleted file mode 100644
index 3bfa469..0000000
--- a/srcs/wordpress/wp-admin/includes/class-ftp.php
+++ /dev/null
@@ -1,912 +0,0 @@
-LocalEcho=$le;
- $this->Verbose=$verb;
- $this->_lastaction=NULL;
- $this->_error_array=array();
- $this->_eol_code=array(FTP_OS_Unix=>"\n", FTP_OS_Mac=>"\r", FTP_OS_Windows=>"\r\n");
- $this->AuthorizedTransferMode=array(FTP_AUTOASCII, FTP_ASCII, FTP_BINARY);
- $this->OS_FullName=array(FTP_OS_Unix => 'UNIX', FTP_OS_Windows => 'WINDOWS', FTP_OS_Mac => 'MACOS');
- $this->AutoAsciiExt=array("ASP","BAT","C","CPP","CSS","CSV","JS","H","HTM","HTML","SHTML","INI","LOG","PHP3","PHTML","PL","PERL","SH","SQL","TXT");
- $this->_port_available=($port_mode==TRUE);
- $this->SendMSG("Staring FTP client class".($this->_port_available?"":" without PORT mode support"));
- $this->_connected=FALSE;
- $this->_ready=FALSE;
- $this->_can_restore=FALSE;
- $this->_code=0;
- $this->_message="";
- $this->_ftp_buff_size=4096;
- $this->_curtype=NULL;
- $this->SetUmask(0022);
- $this->SetType(FTP_AUTOASCII);
- $this->SetTimeout(30);
- $this->Passive(!$this->_port_available);
- $this->_login="anonymous";
- $this->_password="anon@ftp.com";
- $this->_features=array();
- $this->OS_local=FTP_OS_Unix;
- $this->OS_remote=FTP_OS_Unix;
- $this->features=array();
- if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $this->OS_local=FTP_OS_Windows;
- elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
- }
-
- function ftp_base($port_mode=FALSE) {
- $this->__construct($port_mode);
- }
-
-//
-//
-//
-
- function parselisting($line) {
- $is_windows = ($this->OS_remote == FTP_OS_Windows);
- if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|) +(.+)/",$line,$lucifer)) {
- $b = array();
- if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix
- $b['isdir'] = ($lucifer[7]=="");
- if ( $b['isdir'] )
- $b['type'] = 'd';
- else
- $b['type'] = 'f';
- $b['size'] = $lucifer[7];
- $b['month'] = $lucifer[1];
- $b['day'] = $lucifer[2];
- $b['year'] = $lucifer[3];
- $b['hour'] = $lucifer[4];
- $b['minute'] = $lucifer[5];
- $b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
- $b['am/pm'] = $lucifer[6];
- $b['name'] = $lucifer[8];
- } else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
- //echo $line."\n";
- $lcount=count($lucifer);
- if ($lcount<8) return '';
- $b = array();
- $b['isdir'] = $lucifer[0][0] === "d";
- $b['islink'] = $lucifer[0][0] === "l";
- if ( $b['isdir'] )
- $b['type'] = 'd';
- elseif ( $b['islink'] )
- $b['type'] = 'l';
- else
- $b['type'] = 'f';
- $b['perms'] = $lucifer[0];
- $b['number'] = $lucifer[1];
- $b['owner'] = $lucifer[2];
- $b['group'] = $lucifer[3];
- $b['size'] = $lucifer[4];
- if ($lcount==8) {
- sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
- sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
- $b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
- $b['name'] = $lucifer[7];
- } else {
- $b['month'] = $lucifer[5];
- $b['day'] = $lucifer[6];
- if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
- $b['year'] = gmdate("Y");
- $b['hour'] = $l2[1];
- $b['minute'] = $l2[2];
- } else {
- $b['year'] = $lucifer[7];
- $b['hour'] = 0;
- $b['minute'] = 0;
- }
- $b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
- $b['name'] = $lucifer[8];
- }
- }
-
- return $b;
- }
-
- function SendMSG($message = "", $crlf=true) {
- if ($this->Verbose) {
- echo $message.($crlf?CRLF:"");
- flush();
- }
- return TRUE;
- }
-
- function SetType($mode=FTP_AUTOASCII) {
- if(!in_array($mode, $this->AuthorizedTransferMode)) {
- $this->SendMSG("Wrong type");
- return FALSE;
- }
- $this->_type=$mode;
- $this->SendMSG("Transfer type: ".($this->_type==FTP_BINARY?"binary":($this->_type==FTP_ASCII?"ASCII":"auto ASCII") ) );
- return TRUE;
- }
-
- function _settype($mode=FTP_ASCII) {
- if($this->_ready) {
- if($mode==FTP_BINARY) {
- if($this->_curtype!=FTP_BINARY) {
- if(!$this->_exec("TYPE I", "SetType")) return FALSE;
- $this->_curtype=FTP_BINARY;
- }
- } elseif($this->_curtype!=FTP_ASCII) {
- if(!$this->_exec("TYPE A", "SetType")) return FALSE;
- $this->_curtype=FTP_ASCII;
- }
- } else return FALSE;
- return TRUE;
- }
-
- function Passive($pasv=NULL) {
- if(is_null($pasv)) $this->_passive=!$this->_passive;
- else $this->_passive=$pasv;
- if(!$this->_port_available and !$this->_passive) {
- $this->SendMSG("Only passive connections available!");
- $this->_passive=TRUE;
- return FALSE;
- }
- $this->SendMSG("Passive mode ".($this->_passive?"on":"off"));
- return TRUE;
- }
-
- function SetServer($host, $port=21, $reconnect=true) {
- if(!is_long($port)) {
- $this->verbose=true;
- $this->SendMSG("Incorrect port syntax");
- return FALSE;
- } else {
- $ip=@gethostbyname($host);
- $dns=@gethostbyaddr($host);
- if(!$ip) $ip=$host;
- if(!$dns) $dns=$host;
- // Validate the IPAddress PHP4 returns -1 for invalid, PHP5 false
- // -1 === "255.255.255.255" which is the broadcast address which is also going to be invalid
- $ipaslong = ip2long($ip);
- if ( ($ipaslong == false) || ($ipaslong === -1) ) {
- $this->SendMSG("Wrong host name/address \"".$host."\"");
- return FALSE;
- }
- $this->_host=$ip;
- $this->_fullhost=$dns;
- $this->_port=$port;
- $this->_dataport=$port-1;
- }
- $this->SendMSG("Host \"".$this->_fullhost."(".$this->_host."):".$this->_port."\"");
- if($reconnect){
- if($this->_connected) {
- $this->SendMSG("Reconnecting");
- if(!$this->quit(FTP_FORCE)) return FALSE;
- if(!$this->connect()) return FALSE;
- }
- }
- return TRUE;
- }
-
- function SetUmask($umask=0022) {
- $this->_umask=$umask;
- umask($this->_umask);
- $this->SendMSG("UMASK 0".decoct($this->_umask));
- return TRUE;
- }
-
- function SetTimeout($timeout=30) {
- $this->_timeout=$timeout;
- $this->SendMSG("Timeout ".$this->_timeout);
- if($this->_connected)
- if(!$this->_settimeout($this->_ftp_control_sock)) return FALSE;
- return TRUE;
- }
-
- function connect($server=NULL) {
- if(!empty($server)) {
- if(!$this->SetServer($server)) return false;
- }
- if($this->_ready) return true;
- $this->SendMsg('Local OS : '.$this->OS_FullName[$this->OS_local]);
- if(!($this->_ftp_control_sock = $this->_connect($this->_host, $this->_port))) {
- $this->SendMSG("Error : Cannot connect to remote host \"".$this->_fullhost." :".$this->_port."\"");
- return FALSE;
- }
- $this->SendMSG("Connected to remote host \"".$this->_fullhost.":".$this->_port."\". Waiting for greeting.");
- do {
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- $this->_lastaction=time();
- } while($this->_code<200);
- $this->_ready=true;
- $syst=$this->systype();
- if(!$syst) $this->SendMSG("Can't detect remote OS");
- else {
- if(preg_match("/win|dos|novell/i", $syst[0])) $this->OS_remote=FTP_OS_Windows;
- elseif(preg_match("/os/i", $syst[0])) $this->OS_remote=FTP_OS_Mac;
- elseif(preg_match("/(li|u)nix/i", $syst[0])) $this->OS_remote=FTP_OS_Unix;
- else $this->OS_remote=FTP_OS_Mac;
- $this->SendMSG("Remote OS: ".$this->OS_FullName[$this->OS_remote]);
- }
- if(!$this->features()) $this->SendMSG("Can't get features list. All supported - disabled");
- else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
- return TRUE;
- }
-
- function quit($force=false) {
- if($this->_ready) {
- if(!$this->_exec("QUIT") and !$force) return FALSE;
- if(!$this->_checkCode() and !$force) return FALSE;
- $this->_ready=false;
- $this->SendMSG("Session finished");
- }
- $this->_quit();
- return TRUE;
- }
-
- function login($user=NULL, $pass=NULL) {
- if(!is_null($user)) $this->_login=$user;
- else $this->_login="anonymous";
- if(!is_null($pass)) $this->_password=$pass;
- else $this->_password="anon@anon.com";
- if(!$this->_exec("USER ".$this->_login, "login")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- if($this->_code!=230) {
- if(!$this->_exec((($this->_code==331)?"PASS ":"ACCT ").$this->_password, "login")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- }
- $this->SendMSG("Authentication succeeded");
- if(empty($this->_features)) {
- if(!$this->features()) $this->SendMSG("Can't get features list. All supported - disabled");
- else $this->SendMSG("Supported features: ".implode(", ", array_keys($this->_features)));
- }
- return TRUE;
- }
-
- function pwd() {
- if(!$this->_exec("PWD", "pwd")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return preg_replace("/^[0-9]{3} \"(.+)\".*$/s", "\\1", $this->_message);
- }
-
- function cdup() {
- if(!$this->_exec("CDUP", "cdup")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return true;
- }
-
- function chdir($pathname) {
- if(!$this->_exec("CWD ".$pathname, "chdir")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function rmdir($pathname) {
- if(!$this->_exec("RMD ".$pathname, "rmdir")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function mkdir($pathname) {
- if(!$this->_exec("MKD ".$pathname, "mkdir")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function rename($from, $to) {
- if(!$this->_exec("RNFR ".$from, "rename")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- if($this->_code==350) {
- if(!$this->_exec("RNTO ".$to, "rename")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- } else return FALSE;
- return TRUE;
- }
-
- function filesize($pathname) {
- if(!isset($this->_features["SIZE"])) {
- $this->PushError("filesize", "not supported by server");
- return FALSE;
- }
- if(!$this->_exec("SIZE ".$pathname, "filesize")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
- }
-
- function abort() {
- if(!$this->_exec("ABOR", "abort")) return FALSE;
- if(!$this->_checkCode()) {
- if($this->_code!=426) return FALSE;
- if(!$this->_readmsg("abort")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- }
- return true;
- }
-
- function mdtm($pathname) {
- if(!isset($this->_features["MDTM"])) {
- $this->PushError("mdtm", "not supported by server");
- return FALSE;
- }
- if(!$this->_exec("MDTM ".$pathname, "mdtm")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- $mdtm = preg_replace("/^[0-9]{3} ([0-9]+).*$/s", "\\1", $this->_message);
- $date = sscanf($mdtm, "%4d%2d%2d%2d%2d%2d");
- $timestamp = mktime($date[3], $date[4], $date[5], $date[1], $date[2], $date[0]);
- return $timestamp;
- }
-
- function systype() {
- if(!$this->_exec("SYST", "systype")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- $DATA = explode(" ", $this->_message);
- return array($DATA[1], $DATA[3]);
- }
-
- function delete($pathname) {
- if(!$this->_exec("DELE ".$pathname, "delete")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function site($command, $fnction="site") {
- if(!$this->_exec("SITE ".$command, $fnction)) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function chmod($pathname, $mode) {
- if(!$this->site( sprintf('CHMOD %o %s', $mode, $pathname), "chmod")) return FALSE;
- return TRUE;
- }
-
- function restore($from) {
- if(!isset($this->_features["REST"])) {
- $this->PushError("restore", "not supported by server");
- return FALSE;
- }
- if($this->_curtype!=FTP_BINARY) {
- $this->PushError("restore", "can't restore in ASCII mode");
- return FALSE;
- }
- if(!$this->_exec("REST ".$from, "resore")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return TRUE;
- }
-
- function features() {
- if(!$this->_exec("FEAT", "features")) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- $f=preg_split("/[".CRLF."]+/", preg_replace("/[0-9]{3}[ -].*[".CRLF."]+/", "", $this->_message), -1, PREG_SPLIT_NO_EMPTY);
- $this->_features=array();
- foreach($f as $k=>$v) {
- $v=explode(" ", trim($v));
- $this->_features[array_shift($v)]=$v;
- }
- return true;
- }
-
- function rawlist($pathname="", $arg="") {
- return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "LIST", "rawlist");
- }
-
- function nlist($pathname="", $arg="") {
- return $this->_list(($arg?" ".$arg:"").($pathname?" ".$pathname:""), "NLST", "nlist");
- }
-
- function is_exists($pathname) {
- return $this->file_exists($pathname);
- }
-
- function file_exists($pathname) {
- $exists=true;
- if(!$this->_exec("RNFR ".$pathname, "rename")) $exists=FALSE;
- else {
- if(!$this->_checkCode()) $exists=FALSE;
- $this->abort();
- }
- if($exists) $this->SendMSG("Remote file ".$pathname." exists");
- else $this->SendMSG("Remote file ".$pathname." does not exist");
- return $exists;
- }
-
- function fget($fp, $remotefile, $rest=0) {
- if($this->_can_restore and $rest!=0) fseek($fp, $rest);
- $pi=pathinfo($remotefile);
- if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
- else $mode=FTP_BINARY;
- if(!$this->_data_prepare($mode)) {
- return FALSE;
- }
- if($this->_can_restore and $rest!=0) $this->restore($rest);
- if(!$this->_exec("RETR ".$remotefile, "get")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $out=$this->_data_read($mode, $fp);
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return $out;
- }
-
- function get($remotefile, $localfile=NULL, $rest=0) {
- if(is_null($localfile)) $localfile=$remotefile;
- if (@file_exists($localfile)) $this->SendMSG("Warning : local file will be overwritten");
- $fp = @fopen($localfile, "w");
- if (!$fp) {
- $this->PushError("get","can't open local file", "Cannot create \"".$localfile."\"");
- return FALSE;
- }
- if($this->_can_restore and $rest!=0) fseek($fp, $rest);
- $pi=pathinfo($remotefile);
- if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
- else $mode=FTP_BINARY;
- if(!$this->_data_prepare($mode)) {
- fclose($fp);
- return FALSE;
- }
- if($this->_can_restore and $rest!=0) $this->restore($rest);
- if(!$this->_exec("RETR ".$remotefile, "get")) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- $out=$this->_data_read($mode, $fp);
- fclose($fp);
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return $out;
- }
-
- function fput($remotefile, $fp, $rest=0) {
- if($this->_can_restore and $rest!=0) fseek($fp, $rest);
- $pi=pathinfo($remotefile);
- if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
- else $mode=FTP_BINARY;
- if(!$this->_data_prepare($mode)) {
- return FALSE;
- }
- if($this->_can_restore and $rest!=0) $this->restore($rest);
- if(!$this->_exec("STOR ".$remotefile, "put")) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $ret=$this->_data_write($mode, $fp);
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return $ret;
- }
-
- function put($localfile, $remotefile=NULL, $rest=0) {
- if(is_null($remotefile)) $remotefile=$localfile;
- if (!file_exists($localfile)) {
- $this->PushError("put","can't open local file", "No such file or directory \"".$localfile."\"");
- return FALSE;
- }
- $fp = @fopen($localfile, "r");
-
- if (!$fp) {
- $this->PushError("put","can't open local file", "Cannot read file \"".$localfile."\"");
- return FALSE;
- }
- if($this->_can_restore and $rest!=0) fseek($fp, $rest);
- $pi=pathinfo($localfile);
- if($this->_type==FTP_ASCII or ($this->_type==FTP_AUTOASCII and in_array(strtoupper($pi["extension"]), $this->AutoAsciiExt))) $mode=FTP_ASCII;
- else $mode=FTP_BINARY;
- if(!$this->_data_prepare($mode)) {
- fclose($fp);
- return FALSE;
- }
- if($this->_can_restore and $rest!=0) $this->restore($rest);
- if(!$this->_exec("STOR ".$remotefile, "put")) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- fclose($fp);
- return FALSE;
- }
- $ret=$this->_data_write($mode, $fp);
- fclose($fp);
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- return $ret;
- }
-
- function mput($local=".", $remote=NULL, $continious=false) {
- $local=realpath($local);
- if(!@file_exists($local)) {
- $this->PushError("mput","can't open local folder", "Cannot stat folder \"".$local."\"");
- return FALSE;
- }
- if(!is_dir($local)) return $this->put($local, $remote);
- if(empty($remote)) $remote=".";
- elseif(!$this->file_exists($remote) and !$this->mkdir($remote)) return FALSE;
- if($handle = opendir($local)) {
- $list=array();
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != "..") $list[]=$file;
- }
- closedir($handle);
- } else {
- $this->PushError("mput","can't open local folder", "Cannot read folder \"".$local."\"");
- return FALSE;
- }
- if(empty($list)) return TRUE;
- $ret=true;
- foreach($list as $el) {
- if(is_dir($local."/".$el)) $t=$this->mput($local."/".$el, $remote."/".$el);
- else $t=$this->put($local."/".$el, $remote."/".$el);
- if(!$t) {
- $ret=FALSE;
- if(!$continious) break;
- }
- }
- return $ret;
-
- }
-
- function mget($remote, $local=".", $continious=false) {
- $list=$this->rawlist($remote, "-lA");
- if($list===false) {
- $this->PushError("mget","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
- return FALSE;
- }
- if(empty($list)) return true;
- if(!@file_exists($local)) {
- if(!@mkdir($local)) {
- $this->PushError("mget","can't create local folder", "Cannot create folder \"".$local."\"");
- return FALSE;
- }
- }
- foreach($list as $k=>$v) {
- $list[$k]=$this->parselisting($v);
- if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
- }
- $ret=true;
- foreach($list as $el) {
- if($el["type"]=="d") {
- if(!$this->mget($remote."/".$el["name"], $local."/".$el["name"], $continious)) {
- $this->PushError("mget", "can't copy folder", "Can't copy remote folder \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
- $ret=false;
- if(!$continious) break;
- }
- } else {
- if(!$this->get($remote."/".$el["name"], $local."/".$el["name"])) {
- $this->PushError("mget", "can't copy file", "Can't copy remote file \"".$remote."/".$el["name"]."\" to local \"".$local."/".$el["name"]."\"");
- $ret=false;
- if(!$continious) break;
- }
- }
- @chmod($local."/".$el["name"], $el["perms"]);
- $t=strtotime($el["date"]);
- if($t!==-1 and $t!==false) @touch($local."/".$el["name"], $t);
- }
- return $ret;
- }
-
- function mdel($remote, $continious=false) {
- $list=$this->rawlist($remote, "-la");
- if($list===false) {
- $this->PushError("mdel","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
- return false;
- }
-
- foreach($list as $k=>$v) {
- $list[$k]=$this->parselisting($v);
- if( ! $list[$k] or $list[$k]["name"]=="." or $list[$k]["name"]=="..") unset($list[$k]);
- }
- $ret=true;
-
- foreach($list as $el) {
- if ( empty($el) )
- continue;
-
- if($el["type"]=="d") {
- if(!$this->mdel($remote."/".$el["name"], $continious)) {
- $ret=false;
- if(!$continious) break;
- }
- } else {
- if (!$this->delete($remote."/".$el["name"])) {
- $this->PushError("mdel", "can't delete file", "Can't delete remote file \"".$remote."/".$el["name"]."\"");
- $ret=false;
- if(!$continious) break;
- }
- }
- }
-
- if(!$this->rmdir($remote)) {
- $this->PushError("mdel", "can't delete folder", "Can't delete remote folder \"".$remote."/".$el["name"]."\"");
- $ret=false;
- }
- return $ret;
- }
-
- function mmkdir($dir, $mode = 0777) {
- if(empty($dir)) return FALSE;
- if($this->is_exists($dir) or $dir == "/" ) return TRUE;
- if(!$this->mmkdir(dirname($dir), $mode)) return false;
- $r=$this->mkdir($dir, $mode);
- $this->chmod($dir,$mode);
- return $r;
- }
-
- function glob($pattern, $handle=NULL) {
- $path=$output=null;
- if(PHP_OS=='WIN32') $slash='\\';
- else $slash='/';
- $lastpos=strrpos($pattern,$slash);
- if(!($lastpos===false)) {
- $path=substr($pattern,0,-$lastpos-1);
- $pattern=substr($pattern,$lastpos);
- } else $path=getcwd();
- if(is_array($handle) and !empty($handle)) {
- foreach($handle as $dir) {
- if($this->glob_pattern_match($pattern,$dir))
- $output[]=$dir;
- }
- } else {
- $handle=@opendir($path);
- if($handle===false) return false;
- while($dir=readdir($handle)) {
- if($this->glob_pattern_match($pattern,$dir))
- $output[]=$dir;
- }
- closedir($handle);
- }
- if(is_array($output)) return $output;
- return false;
- }
-
- function glob_pattern_match($pattern,$string) {
- $out=null;
- $chunks=explode(';',$pattern);
- foreach($chunks as $pattern) {
- $escape=array('$','^','.','{','}','(',')','[',']','|');
- while(strpos($pattern,'**')!==false)
- $pattern=str_replace('**','*',$pattern);
- foreach($escape as $probe)
- $pattern=str_replace($probe,"\\$probe",$pattern);
- $pattern=str_replace('?*','*',
- str_replace('*?','*',
- str_replace('*',".*",
- str_replace('?','.{1,1}',$pattern))));
- $out[]=$pattern;
- }
- if(count($out)==1) return($this->glob_regexp("^$out[0]$",$string));
- else {
- foreach($out as $tester)
- if($this->my_regexp("^$tester$",$string)) return true;
- }
- return false;
- }
-
- function glob_regexp($pattern,$probe) {
- $sensitive=(PHP_OS!='WIN32');
- return ($sensitive?
- preg_match( '/' . preg_quote( $pattern, '/' ) . '/', $probe ) :
- preg_match( '/' . preg_quote( $pattern, '/' ) . '/i', $probe )
- );
- }
-
- function dirlist($remote) {
- $list=$this->rawlist($remote, "-la");
- if($list===false) {
- $this->PushError("dirlist","can't read remote folder list", "Can't read remote folder \"".$remote."\" contents");
- return false;
- }
-
- $dirlist = array();
- foreach($list as $k=>$v) {
- $entry=$this->parselisting($v);
- if ( empty($entry) )
- continue;
-
- if($entry["name"]=="." or $entry["name"]=="..")
- continue;
-
- $dirlist[$entry['name']] = $entry;
- }
-
- return $dirlist;
- }
-//
-//
-//
- function _checkCode() {
- return ($this->_code<400 and $this->_code>0);
- }
-
- function _list($arg="", $cmd="LIST", $fnction="_list") {
- if(!$this->_data_prepare()) return false;
- if(!$this->_exec($cmd.$arg, $fnction)) {
- $this->_data_close();
- return FALSE;
- }
- if(!$this->_checkCode()) {
- $this->_data_close();
- return FALSE;
- }
- $out="";
- if($this->_code<200) {
- $out=$this->_data_read();
- $this->_data_close();
- if(!$this->_readmsg()) return FALSE;
- if(!$this->_checkCode()) return FALSE;
- if($out === FALSE ) return FALSE;
- $out=preg_split("/[".CRLF."]+/", $out, -1, PREG_SPLIT_NO_EMPTY);
-// $this->SendMSG(implode($this->_eol_code[$this->OS_local], $out));
- }
- return $out;
- }
-
-//
-//
-//
-// Gnre une erreur pour traitement externe la classe
- function PushError($fctname,$msg,$desc=false){
- $error=array();
- $error['time']=time();
- $error['fctname']=$fctname;
- $error['msg']=$msg;
- $error['desc']=$desc;
- if($desc) $tmp=' ('.$desc.')'; else $tmp='';
- $this->SendMSG($fctname.': '.$msg.$tmp);
- return(array_push($this->_error_array,$error));
- }
-
-// Rcupre une erreur externe
- function PopError(){
- if(count($this->_error_array)) return(array_pop($this->_error_array));
- else return(false);
- }
-}
-
-$mod_sockets = extension_loaded( 'sockets' );
-if ( ! $mod_sockets && function_exists( 'dl' ) && is_callable( 'dl' ) ) {
- $prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : '';
- @dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX );
- $mod_sockets = extension_loaded( 'sockets' );
-}
-
-require_once dirname( __FILE__ ) . "/class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php";
-
-if ( $mod_sockets ) {
- class ftp extends ftp_sockets {}
-} else {
- class ftp extends ftp_pure {}
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-language-pack-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-language-pack-upgrader-skin.php
deleted file mode 100644
index cbbc834..0000000
--- a/srcs/wordpress/wp-admin/includes/class-language-pack-upgrader-skin.php
+++ /dev/null
@@ -1,95 +0,0 @@
- '',
- 'nonce' => '',
- 'title' => __( 'Update Translations' ),
- 'skip_header_footer' => false,
- );
- $args = wp_parse_args( $args, $defaults );
- if ( $args['skip_header_footer'] ) {
- $this->done_header = true;
- $this->done_footer = true;
- $this->display_footer_actions = false;
- }
- parent::__construct( $args );
- }
-
- /**
- */
- public function before() {
- $name = $this->upgrader->get_name_for_update( $this->language_update );
-
- echo '';
-
- /* translators: 1: Project name (plugin, theme, or WordPress), 2: Language. */
- printf( '
' . __( 'Updating translations for %1$s (%2$s)…' ) . ' ', $name, $this->language_update->language );
- }
-
- /**
- * @param string|WP_Error $error
- */
- public function error( $error ) {
- echo '
';
- parent::error( $error );
- echo '
';
- }
-
- /**
- */
- public function after() {
- echo '
';
- }
-
- /**
- */
- public function bulk_footer() {
- $this->decrement_update_count( 'translation' );
-
- $update_actions = array(
- 'updates_page' => sprintf(
- '%s ',
- self_admin_url( 'update-core.php' ),
- __( 'Return to WordPress Updates page' )
- ),
- );
-
- /**
- * Filters the list of action links available following a translations update.
- *
- * @since 3.7.0
- *
- * @param string[] $update_actions Array of translations update links.
- */
- $update_actions = apply_filters( 'update_translations_complete_actions', $update_actions );
-
- if ( $update_actions && $this->display_footer_actions ) {
- $this->feedback( implode( ' | ', $update_actions ) );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-language-pack-upgrader.php b/srcs/wordpress/wp-admin/includes/class-language-pack-upgrader.php
deleted file mode 100644
index 72a86bb..0000000
--- a/srcs/wordpress/wp-admin/includes/class-language-pack-upgrader.php
+++ /dev/null
@@ -1,473 +0,0 @@
-is_vcs_checkout( WP_CONTENT_DIR ) ) {
- return;
- }
-
- foreach ( $language_updates as $key => $language_update ) {
- $update = ! empty( $language_update->autoupdate );
-
- /**
- * Filters whether to asynchronously update translation for core, a plugin, or a theme.
- *
- * @since 4.0.0
- *
- * @param bool $update Whether to update.
- * @param object $language_update The update offer.
- */
- $update = apply_filters( 'async_update_translation', $update, $language_update );
-
- if ( ! $update ) {
- unset( $language_updates[ $key ] );
- }
- }
-
- if ( empty( $language_updates ) ) {
- return;
- }
-
- // Re-use the automatic upgrader skin if the parent upgrader is using it.
- if ( $upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin ) {
- $skin = $upgrader->skin;
- } else {
- $skin = new Language_Pack_Upgrader_Skin(
- array(
- 'skip_header_footer' => true,
- )
- );
- }
-
- $lp_upgrader = new Language_Pack_Upgrader( $skin );
- $lp_upgrader->bulk_upgrade( $language_updates );
- }
-
- /**
- * Initialize the upgrade strings.
- *
- * @since 3.7.0
- */
- public function upgrade_strings() {
- $this->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while we update them as well.' );
- $this->strings['up_to_date'] = __( 'Your translations are all up to date.' );
- $this->strings['no_package'] = __( 'Update package not available.' );
- /* translators: %s: Package URL. */
- $this->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s…' ), '%s ' );
- $this->strings['unpack_package'] = __( 'Unpacking the update…' );
- $this->strings['process_failed'] = __( 'Translation update failed.' );
- $this->strings['process_success'] = __( 'Translation updated successfully.' );
- $this->strings['remove_old'] = __( 'Removing the old version of the translation…' );
- $this->strings['remove_old_failed'] = __( 'Could not remove the old translation.' );
- }
-
- /**
- * Upgrade a language pack.
- *
- * @since 3.7.0
- *
- * @param string|false $update Optional. Whether an update offer is available. Default false.
- * @param array $args Optional. Other optional arguments, see
- * Language_Pack_Upgrader::bulk_upgrade(). Default empty array.
- * @return array|bool|WP_Error The result of the upgrade, or a WP_Error object instead.
- */
- public function upgrade( $update = false, $args = array() ) {
- if ( $update ) {
- $update = array( $update );
- }
-
- $results = $this->bulk_upgrade( $update, $args );
-
- if ( ! is_array( $results ) ) {
- return $results;
- }
-
- return $results[0];
- }
-
- /**
- * Bulk upgrade language packs.
- *
- * @since 3.7.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param object[] $language_updates Optional. Array of language packs to update. @see wp_get_translation_updates().
- * Default empty array.
- * @param array $args {
- * Other arguments for upgrading multiple language packs. Default empty array.
- *
- * @type bool $clear_update_cache Whether to clear the update cache when done.
- * Default true.
- * }
- * @return array|bool|WP_Error Will return an array of results, or true if there are no updates,
- * false or WP_Error for initial errors.
- */
- public function bulk_upgrade( $language_updates = array(), $args = array() ) {
- global $wp_filesystem;
-
- $defaults = array(
- 'clear_update_cache' => true,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->upgrade_strings();
-
- if ( ! $language_updates ) {
- $language_updates = wp_get_translation_updates();
- }
-
- if ( empty( $language_updates ) ) {
- $this->skin->header();
- $this->skin->set_result( true );
- $this->skin->feedback( 'up_to_date' );
- $this->skin->bulk_footer();
- $this->skin->footer();
- return true;
- }
-
- if ( 'upgrader_process_complete' == current_filter() ) {
- $this->skin->feedback( 'starting_upgrade' );
- }
-
- // Remove any existing upgrade filters from the plugin/theme upgraders #WP29425 & #WP29230
- remove_all_filters( 'upgrader_pre_install' );
- remove_all_filters( 'upgrader_clear_destination' );
- remove_all_filters( 'upgrader_post_install' );
- remove_all_filters( 'upgrader_source_selection' );
-
- add_filter( 'upgrader_source_selection', array( $this, 'check_package' ), 10, 2 );
-
- $this->skin->header();
-
- // Connect to the Filesystem first.
- $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) );
- if ( ! $res ) {
- $this->skin->footer();
- return false;
- }
-
- $results = array();
-
- $this->update_count = count( $language_updates );
- $this->update_current = 0;
-
- /*
- * The filesystem's mkdir() is not recursive. Make sure WP_LANG_DIR exists,
- * as we then may need to create a /plugins or /themes directory inside of it.
- */
- $remote_destination = $wp_filesystem->find_folder( WP_LANG_DIR );
- if ( ! $wp_filesystem->exists( $remote_destination ) ) {
- if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
- return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination );
- }
- }
-
- $language_updates_results = array();
-
- foreach ( $language_updates as $language_update ) {
-
- $this->skin->language_update = $language_update;
-
- $destination = WP_LANG_DIR;
- if ( 'plugin' == $language_update->type ) {
- $destination .= '/plugins';
- } elseif ( 'theme' == $language_update->type ) {
- $destination .= '/themes';
- }
-
- $this->update_current++;
-
- $options = array(
- 'package' => $language_update->package,
- 'destination' => $destination,
- 'clear_destination' => true,
- 'abort_if_destination_exists' => false, // We expect the destination to exist.
- 'clear_working' => true,
- 'is_multi' => true,
- 'hook_extra' => array(
- 'language_update_type' => $language_update->type,
- 'language_update' => $language_update,
- ),
- );
-
- $result = $this->run( $options );
-
- $results[] = $this->result;
-
- // Prevent credentials auth screen from displaying multiple times.
- if ( false === $result ) {
- break;
- }
-
- $language_updates_results[] = array(
- 'language' => $language_update->language,
- 'type' => $language_update->type,
- 'slug' => isset( $language_update->slug ) ? $language_update->slug : 'default',
- 'version' => $language_update->version,
- );
- }
-
- // Remove upgrade hooks which are not required for translation updates.
- remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
- remove_action( 'upgrader_process_complete', 'wp_version_check' );
- remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
- remove_action( 'upgrader_process_complete', 'wp_update_themes' );
-
- /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
- do_action(
- 'upgrader_process_complete',
- $this,
- array(
- 'action' => 'update',
- 'type' => 'translation',
- 'bulk' => true,
- 'translations' => $language_updates_results,
- )
- );
-
- // Re-add upgrade hooks.
- add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
- add_action( 'upgrader_process_complete', 'wp_version_check', 10, 0 );
- add_action( 'upgrader_process_complete', 'wp_update_plugins', 10, 0 );
- add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
-
- $this->skin->bulk_footer();
-
- $this->skin->footer();
-
- // Clean up our hooks, in case something else does an upgrade on this connection.
- remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
-
- if ( $parsed_args['clear_update_cache'] ) {
- wp_clean_update_cache();
- }
-
- return $results;
- }
-
- /**
- * Check the package source to make sure there are .mo and .po files.
- *
- * Hooked to the {@see 'upgrader_source_selection'} filter by
- * Language_Pack_Upgrader::bulk_upgrade().
- *
- * @since 3.7.0
- *
- * @global WP_Filesystem_Base $wp_filesystem Subclass
- *
- * @param string|WP_Error $source
- * @param string $remote_source
- */
- public function check_package( $source, $remote_source ) {
- global $wp_filesystem;
-
- if ( is_wp_error( $source ) ) {
- return $source;
- }
-
- // Check that the folder contains a valid language.
- $files = $wp_filesystem->dirlist( $remote_source );
-
- // Check to see if a .po and .mo exist in the folder.
- $po = false;
- $mo = false;
- foreach ( (array) $files as $file => $filedata ) {
- if ( '.po' == substr( $file, -3 ) ) {
- $po = true;
- } elseif ( '.mo' == substr( $file, -3 ) ) {
- $mo = true;
- }
- }
-
- if ( ! $mo || ! $po ) {
- return new WP_Error(
- 'incompatible_archive_pomo',
- $this->strings['incompatible_archive'],
- sprintf(
- /* translators: 1: .po, 2: .mo */
- __( 'The language pack is missing either the %1$s or %2$s files.' ),
- '.po',
- '.mo'
- )
- );
- }
-
- return $source;
- }
-
- /**
- * Get the name of an item being updated.
- *
- * @since 3.7.0
- *
- * @param object $update The data for an update.
- * @return string The name of the item being updated.
- */
- public function get_name_for_update( $update ) {
- switch ( $update->type ) {
- case 'core':
- return 'WordPress'; // Not translated
-
- case 'theme':
- $theme = wp_get_theme( $update->slug );
- if ( $theme->exists() ) {
- return $theme->Get( 'Name' );
- }
- break;
- case 'plugin':
- $plugin_data = get_plugins( '/' . $update->slug );
- $plugin_data = reset( $plugin_data );
- if ( $plugin_data ) {
- return $plugin_data['Name'];
- }
- break;
- }
- return '';
- }
-
- /**
- * Clears existing translations where this item is going to be installed into.
- *
- * @since 5.1.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param string $remote_destination The location on the remote filesystem to be cleared.
- * @return bool|WP_Error True upon success, WP_Error on failure.
- */
- public function clear_destination( $remote_destination ) {
- global $wp_filesystem;
-
- $language_update = $this->skin->language_update;
- $language_directory = WP_LANG_DIR . '/'; // Local path for use with glob().
-
- if ( 'core' === $language_update->type ) {
- $files = array(
- $remote_destination . $language_update->language . '.po',
- $remote_destination . $language_update->language . '.mo',
- $remote_destination . 'admin-' . $language_update->language . '.po',
- $remote_destination . 'admin-' . $language_update->language . '.mo',
- $remote_destination . 'admin-network-' . $language_update->language . '.po',
- $remote_destination . 'admin-network-' . $language_update->language . '.mo',
- $remote_destination . 'continents-cities-' . $language_update->language . '.po',
- $remote_destination . 'continents-cities-' . $language_update->language . '.mo',
- );
-
- $json_translation_files = glob( $language_directory . $language_update->language . '-*.json' );
- if ( $json_translation_files ) {
- foreach ( $json_translation_files as $json_translation_file ) {
- $files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );
- }
- }
- } else {
- $files = array(
- $remote_destination . $language_update->slug . '-' . $language_update->language . '.po',
- $remote_destination . $language_update->slug . '-' . $language_update->language . '.mo',
- );
-
- $language_directory = $language_directory . $language_update->type . 's/';
- $json_translation_files = glob( $language_directory . $language_update->slug . '-' . $language_update->language . '-*.json' );
- if ( $json_translation_files ) {
- foreach ( $json_translation_files as $json_translation_file ) {
- $files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );
- }
- }
- }
-
- $files = array_filter( $files, array( $wp_filesystem, 'exists' ) );
-
- // No files to delete.
- if ( ! $files ) {
- return true;
- }
-
- // Check all files are writable before attempting to clear the destination.
- $unwritable_files = array();
-
- // Check writability.
- foreach ( $files as $file ) {
- if ( ! $wp_filesystem->is_writable( $file ) ) {
- // Attempt to alter permissions to allow writes and try again.
- $wp_filesystem->chmod( $file, FS_CHMOD_FILE );
- if ( ! $wp_filesystem->is_writable( $file ) ) {
- $unwritable_files[] = $file;
- }
- }
- }
-
- if ( ! empty( $unwritable_files ) ) {
- return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );
- }
-
- foreach ( $files as $file ) {
- if ( ! $wp_filesystem->delete( $file ) ) {
- return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
- }
- }
-
- return true;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-pclzip.php b/srcs/wordpress/wp-admin/includes/class-pclzip.php
deleted file mode 100644
index aaaeef5..0000000
--- a/srcs/wordpress/wp-admin/includes/class-pclzip.php
+++ /dev/null
@@ -1,5702 +0,0 @@
-zipname = $p_zipname;
- $this->zip_fd = 0;
- $this->magic_quotes_status = -1;
-
- // ----- Return
- return;
- }
-
- public function PclZip($p_zipname) {
- self::__construct($p_zipname);
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // create($p_filelist, $p_add_dir="", $p_remove_dir="")
- // create($p_filelist, $p_option, $p_option_value, ...)
- // Description :
- // This method supports two different synopsis. The first one is historical.
- // This method creates a Zip Archive. The Zip file is created in the
- // filesystem. The files and directories indicated in $p_filelist
- // are added in the archive. See the parameters description for the
- // supported format of $p_filelist.
- // When a directory is in the list, the directory and its content is added
- // in the archive.
- // In this synopsis, the function takes an optional variable list of
- // options. See bellow the supported options.
- // Parameters :
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or one directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_add_dir : A path to add before the real path of the archived file,
- // in order to have it memorized in the archive.
- // $p_remove_dir : A path to remove from the real path of the file to archive,
- // in order to have a shorter path memorized in the archive.
- // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
- // is removed first, before $p_add_dir is added.
- // Options :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_COMMENT :
- // PCLZIP_CB_PRE_ADD :
- // PCLZIP_CB_POST_ADD :
- // Return Values :
- // 0 on failure,
- // The list of the added files, with a status of the add action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function create($p_filelist)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Set default values
- $v_options = array();
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove from the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_ADD => 'optional',
- PCLZIP_CB_POST_ADD => 'optional',
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
- PCLZIP_OPT_COMMENT => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- //, PCLZIP_OPT_CRYPT => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Invalid number / type of arguments");
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Init
- $v_string_list = array();
- $v_att_list = array();
- $v_filedescr_list = array();
- $p_result_list = array();
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist)) {
-
- // ----- Look if the first element is also an array
- // This will mean that this is a file description entry
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
- $v_att_list = $p_filelist;
- }
-
- // ----- The list is a list of string names
- else {
- $v_string_list = $p_filelist;
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist)) {
- // ----- Create a list from the string
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
- }
-
- // ----- Invalid variable type for $p_filelist
- else {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
- return 0;
- }
-
- // ----- Reformat the string list
- if (sizeof($v_string_list) != 0) {
- foreach ($v_string_list as $v_string) {
- if ($v_string != '') {
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
- }
- else {
- }
- }
- }
-
- // ----- For each file in the list check the attributes
- $v_supported_attributes
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
- );
- foreach ($v_att_list as $v_entry) {
- $v_result = $this->privFileDescrParseAtt($v_entry,
- $v_filedescr_list[],
- $v_options,
- $v_supported_attributes);
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Expand the filelist (expand directories)
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Call the create fct
- $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Return
- return $p_result_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // add($p_filelist, $p_add_dir="", $p_remove_dir="")
- // add($p_filelist, $p_option, $p_option_value, ...)
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This methods add the list of files in an existing archive.
- // If a file with the same name already exists, it is added at the end of the
- // archive, the first one is still present.
- // If the archive does not exist, it is created.
- // Parameters :
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or one directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_add_dir : A path to add before the real path of the archived file,
- // in order to have it memorized in the archive.
- // $p_remove_dir : A path to remove from the real path of the file to archive,
- // in order to have a shorter path memorized in the archive.
- // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
- // is removed first, before $p_add_dir is added.
- // Options :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_COMMENT :
- // PCLZIP_OPT_ADD_COMMENT :
- // PCLZIP_OPT_PREPEND_COMMENT :
- // PCLZIP_CB_PRE_ADD :
- // PCLZIP_CB_POST_ADD :
- // Return Values :
- // 0 on failure,
- // The list of the added files, with a status of the add action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function add($p_filelist)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Set default values
- $v_options = array();
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove form the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_ADD => 'optional',
- PCLZIP_CB_POST_ADD => 'optional',
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
- PCLZIP_OPT_COMMENT => 'optional',
- PCLZIP_OPT_ADD_COMMENT => 'optional',
- PCLZIP_OPT_PREPEND_COMMENT => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- //, PCLZIP_OPT_CRYPT => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Init
- $v_string_list = array();
- $v_att_list = array();
- $v_filedescr_list = array();
- $p_result_list = array();
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist)) {
-
- // ----- Look if the first element is also an array
- // This will mean that this is a file description entry
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
- $v_att_list = $p_filelist;
- }
-
- // ----- The list is a list of string names
- else {
- $v_string_list = $p_filelist;
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist)) {
- // ----- Create a list from the string
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
- }
-
- // ----- Invalid variable type for $p_filelist
- else {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
- return 0;
- }
-
- // ----- Reformat the string list
- if (sizeof($v_string_list) != 0) {
- foreach ($v_string_list as $v_string) {
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
- }
- }
-
- // ----- For each file in the list check the attributes
- $v_supported_attributes
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
- );
- foreach ($v_att_list as $v_entry) {
- $v_result = $this->privFileDescrParseAtt($v_entry,
- $v_filedescr_list[],
- $v_options,
- $v_supported_attributes);
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Expand the filelist (expand directories)
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Call the create fct
- $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Return
- return $p_result_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : listContent()
- // Description :
- // This public method, gives the list of the files and directories, with their
- // properties.
- // The properties of each entries in the list are (used also in other functions) :
- // filename : Name of the file. For a create or add action it is the filename
- // given by the user. For an extract function it is the filename
- // of the extracted file.
- // stored_filename : Name of the file / directory stored in the archive.
- // size : Size of the stored file.
- // compressed_size : Size of the file's data compressed in the archive
- // (without the headers overhead)
- // mtime : Last known modification date of the file (UNIX timestamp)
- // comment : Comment associated with the file
- // folder : true | false
- // index : index of the file in the archive
- // status : status of the action (depending of the action) :
- // Values are :
- // ok : OK !
- // filtered : the file / dir is not extracted (filtered by user)
- // already_a_directory : the file can not be extracted because a
- // directory with the same name already exists
- // write_protected : the file can not be extracted because a file
- // with the same name already exists and is
- // write protected
- // newer_exist : the file was not extracted because a newer file exists
- // path_creation_fail : the file is not extracted because the folder
- // does not exist and can not be created
- // write_error : the file was not extracted because there was a
- // error while writing the file
- // read_error : the file was not extracted because there was a error
- // while reading the file
- // invalid_header : the file was not extracted because of an archive
- // format error (bad file header)
- // Note that each time a method can continue operating when there
- // is an action error on a file, the error is only logged in the file status.
- // Return Values :
- // 0 on an unrecoverable failure,
- // The list of the files in the archive.
- // --------------------------------------------------------------------------------
- function listContent()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Call the extracting fct
- $p_list = array();
- if (($v_result = $this->privList($p_list)) != 1)
- {
- unset($p_list);
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // extract($p_path="./", $p_remove_path="")
- // extract([$p_option, $p_option_value, ...])
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This method extract all the files / directories from the archive to the
- // folder indicated in $p_path.
- // If you want to ignore the 'root' part of path of the memorized files
- // you can indicate this in the optional $p_remove_path parameter.
- // By default, if a newer file with the same name already exists, the
- // file is not extracted.
- //
- // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
- // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
- // at the end of the path value of PCLZIP_OPT_PATH.
- // Parameters :
- // $p_path : Path where the files and directories are to be extracted
- // $p_remove_path : First part ('root' part) of the memorized path
- // (if any similar) to remove while extracting.
- // Options :
- // PCLZIP_OPT_PATH :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_CB_PRE_EXTRACT :
- // PCLZIP_CB_POST_EXTRACT :
- // Return Values :
- // 0 or a negative value on failure,
- // The list of the extracted files, with a status of the action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function extract()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-// $v_path = "./";
- $v_path = '';
- $v_remove_path = "";
- $v_remove_all_path = false;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Default values for option
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
-
- // ----- Look for arguments
- if ($v_size > 0) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_PATH => 'optional',
- PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_EXTRACT => 'optional',
- PCLZIP_CB_POST_EXTRACT => 'optional',
- PCLZIP_OPT_SET_CHMOD => 'optional',
- PCLZIP_OPT_BY_NAME => 'optional',
- PCLZIP_OPT_BY_EREG => 'optional',
- PCLZIP_OPT_BY_PREG => 'optional',
- PCLZIP_OPT_BY_INDEX => 'optional',
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
- PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Set the arguments
- if (isset($v_options[PCLZIP_OPT_PATH])) {
- $v_path = $v_options[PCLZIP_OPT_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
- // ----- Check for '/' in last path char
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
- $v_path .= '/';
- }
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_remove_path = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Trace
-
- // ----- Call the extracting fct
- $p_list = array();
- $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
- $v_remove_all_path, $v_options);
- if ($v_result < 1) {
- unset($p_list);
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
-
- // --------------------------------------------------------------------------------
- // Function :
- // extractByIndex($p_index, $p_path="./", $p_remove_path="")
- // extractByIndex($p_index, [$p_option, $p_option_value, ...])
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This method is doing a partial extract of the archive.
- // The extracted files or folders are identified by their index in the
- // archive (from 0 to n).
- // Note that if the index identify a folder, only the folder entry is
- // extracted, not all the files included in the archive.
- // Parameters :
- // $p_index : A single index (integer) or a string of indexes of files to
- // extract. The form of the string is "0,4-6,8-12" with only numbers
- // and '-' for range or ',' to separate ranges. No spaces or ';'
- // are allowed.
- // $p_path : Path where the files and directories are to be extracted
- // $p_remove_path : First part ('root' part) of the memorized path
- // (if any similar) to remove while extracting.
- // Options :
- // PCLZIP_OPT_PATH :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
- // not as files.
- // The resulting content is in a new field 'content' in the file
- // structure.
- // This option must be used alone (any other options are ignored).
- // PCLZIP_CB_PRE_EXTRACT :
- // PCLZIP_CB_POST_EXTRACT :
- // Return Values :
- // 0 on failure,
- // The list of the extracted files, with a status of the action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- //function extractByIndex($p_index, options...)
- function extractByIndex($p_index)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-// $v_path = "./";
- $v_path = '';
- $v_remove_path = "";
- $v_remove_all_path = false;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Default values for option
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove form the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_PATH => 'optional',
- PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_EXTRACT => 'optional',
- PCLZIP_CB_POST_EXTRACT => 'optional',
- PCLZIP_OPT_SET_CHMOD => 'optional',
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Set the arguments
- if (isset($v_options[PCLZIP_OPT_PATH])) {
- $v_path = $v_options[PCLZIP_OPT_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
- // ----- Check for '/' in last path char
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
- $v_path .= '/';
- }
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
- }
- if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
- }
- else {
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_remove_path = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Trace
-
- // ----- Trick
- // Here I want to reuse extractByRule(), so I need to parse the $p_index
- // with privParseOptions()
- $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
- $v_options_trick = array();
- $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
- array (PCLZIP_OPT_BY_INDEX => 'optional' ));
- if ($v_result != 1) {
- return 0;
- }
- $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Call the extracting fct
- if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // delete([$p_option, $p_option_value, ...])
- // Description :
- // This method removes files from the archive.
- // If no parameters are given, then all the archive is emptied.
- // Parameters :
- // None or optional arguments.
- // Options :
- // PCLZIP_OPT_BY_INDEX :
- // PCLZIP_OPT_BY_NAME :
- // PCLZIP_OPT_BY_EREG :
- // PCLZIP_OPT_BY_PREG :
- // Return Values :
- // 0 on failure,
- // The list of the files which are still present in the archive.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function delete()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 0) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_BY_NAME => 'optional',
- PCLZIP_OPT_BY_EREG => 'optional',
- PCLZIP_OPT_BY_PREG => 'optional',
- PCLZIP_OPT_BY_INDEX => 'optional' ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Call the delete fct
- $v_list = array();
- if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
- $this->privSwapBackMagicQuotes();
- unset($v_list);
- return(0);
- }
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : deleteByIndex()
- // Description :
- // ***** Deprecated *****
- // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
- // --------------------------------------------------------------------------------
- function deleteByIndex($p_index)
- {
-
- $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : properties()
- // Description :
- // This method gives the properties of the archive.
- // The properties are :
- // nb : Number of files in the archive
- // comment : Comment associated with the archive file
- // status : not_exist, ok
- // Parameters :
- // None
- // Return Values :
- // 0 on failure,
- // An array with the archive properties.
- // --------------------------------------------------------------------------------
- function properties()
- {
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- $this->privSwapBackMagicQuotes();
- return(0);
- }
-
- // ----- Default properties
- $v_prop = array();
- $v_prop['comment'] = '';
- $v_prop['nb'] = 0;
- $v_prop['status'] = 'not_exist';
-
- // ----- Look if file exists
- if (@is_file($this->zipname))
- {
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
- {
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
-
- // ----- Return
- return 0;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return 0;
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Set the user attributes
- $v_prop['comment'] = $v_central_dir['comment'];
- $v_prop['nb'] = $v_central_dir['entries'];
- $v_prop['status'] = 'ok';
- }
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_prop;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : duplicate()
- // Description :
- // This method creates an archive by copying the content of an other one. If
- // the archive already exist, it is replaced by the new one without any warning.
- // Parameters :
- // $p_archive : The filename of a valid archive, or
- // a valid PclZip object.
- // Return Values :
- // 1 on success.
- // 0 or a negative value on error (error code).
- // --------------------------------------------------------------------------------
- function duplicate($p_archive)
- {
- $v_result = 1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Look if the $p_archive is a PclZip object
- if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
- {
-
- // ----- Duplicate the archive
- $v_result = $this->privDuplicate($p_archive->zipname);
- }
-
- // ----- Look if the $p_archive is a string (so a filename)
- else if (is_string($p_archive))
- {
-
- // ----- Check that $p_archive is a valid zip file
- // TBC : Should also check the archive format
- if (!is_file($p_archive)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
- $v_result = PCLZIP_ERR_MISSING_FILE;
- }
- else {
- // ----- Duplicate the archive
- $v_result = $this->privDuplicate($p_archive);
- }
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : merge()
- // Description :
- // This method merge the $p_archive_to_add archive at the end of the current
- // one ($this).
- // If the archive ($this) does not exist, the merge becomes a duplicate.
- // If the $p_archive_to_add archive does not exist, the merge is a success.
- // Parameters :
- // $p_archive_to_add : It can be directly the filename of a valid zip archive,
- // or a PclZip object archive.
- // Return Values :
- // 1 on success,
- // 0 or negative values on error (see below).
- // --------------------------------------------------------------------------------
- function merge($p_archive_to_add)
- {
- $v_result = 1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Look if the $p_archive_to_add is a PclZip object
- if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
- {
-
- // ----- Merge the archive
- $v_result = $this->privMerge($p_archive_to_add);
- }
-
- // ----- Look if the $p_archive_to_add is a string (so a filename)
- else if (is_string($p_archive_to_add))
- {
-
- // ----- Create a temporary archive
- $v_object_archive = new PclZip($p_archive_to_add);
-
- // ----- Merge the archive
- $v_result = $this->privMerge($v_object_archive);
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
-
-
- // --------------------------------------------------------------------------------
- // Function : errorCode()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorCode()
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- return(PclErrorCode());
- }
- else {
- return($this->error_code);
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : errorName()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorName($p_with_code=false)
- {
- $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
- PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
- PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
- PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
- PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
- PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
- PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
- PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
- PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
- PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
- PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
- PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
- PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
- PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
- PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
- PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
- PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
- PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
- PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
- ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
- ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
- );
-
- if (isset($v_name[$this->error_code])) {
- $v_value = $v_name[$this->error_code];
- }
- else {
- $v_value = 'NoName';
- }
-
- if ($p_with_code) {
- return($v_value.' ('.$this->error_code.')');
- }
- else {
- return($v_value);
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : errorInfo()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorInfo($p_full=false)
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- return(PclErrorString());
- }
- else {
- if ($p_full) {
- return($this->errorName(true)." : ".$this->error_string);
- }
- else {
- return($this->error_string." [code ".$this->error_code."]");
- }
- }
- }
- // --------------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------------
-// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
-// ***** *****
-// ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
-// --------------------------------------------------------------------------------
-
-
-
- // --------------------------------------------------------------------------------
- // Function : privCheckFormat()
- // Description :
- // This method check that the archive exists and is a valid zip archive.
- // Several level of check exists. (futur)
- // Parameters :
- // $p_level : Level of check. Default 0.
- // 0 : Check the first bytes (magic codes) (default value))
- // 1 : 0 + Check the central directory (futur)
- // 2 : 1 + Check each file header (futur)
- // Return Values :
- // true on success,
- // false on error, the error code is set.
- // --------------------------------------------------------------------------------
- function privCheckFormat($p_level=0)
- {
- $v_result = true;
-
- // ----- Reset the file system cache
- clearstatcache();
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Look if the file exits
- if (!is_file($this->zipname)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
- return(false);
- }
-
- // ----- Check that the file is readeable
- if (!is_readable($this->zipname)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
- return(false);
- }
-
- // ----- Check the magic code
- // TBC
-
- // ----- Check the central header
- // TBC
-
- // ----- Check each file header
- // TBC
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privParseOptions()
- // Description :
- // This internal methods reads the variable list of arguments ($p_options_list,
- // $p_size) and generate an array with the options and values ($v_result_list).
- // $v_requested_options contains the options that can be present and those that
- // must be present.
- // $v_requested_options is an array, with the option value as key, and 'optional',
- // or 'mandatory' as value.
- // Parameters :
- // See above.
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
- {
- $v_result=1;
-
- // ----- Read the options
- $i=0;
- while ($i<$p_size) {
-
- // ----- Check if the option is supported
- if (!isset($v_requested_options[$p_options_list[$i]])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for next option
- switch ($p_options_list[$i]) {
- // ----- Look for options that request a path value
- case PCLZIP_OPT_PATH :
- case PCLZIP_OPT_REMOVE_PATH :
- case PCLZIP_OPT_ADD_PATH :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
- $i++;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
- return PclZip::errorCode();
- }
-
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
- return PclZip::errorCode();
- }
-
- // ----- Check the value
- $v_value = $p_options_list[$i+1];
- if ((!is_integer($v_value)) || ($v_value<0)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
- return PclZip::errorCode();
- }
-
- // ----- Get the value (and convert it in bytes)
- $v_result_list[$p_options_list[$i]] = $v_value*1048576;
- $i++;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_ON :
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
- return PclZip::errorCode();
- }
-
- $v_result_list[$p_options_list[$i]] = true;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_OFF :
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
- return PclZip::errorCode();
- }
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
- return PclZip::errorCode();
- }
-
- $v_result_list[$p_options_list[$i]] = true;
- break;
-
- case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if ( is_string($p_options_list[$i+1])
- && ($p_options_list[$i+1] != '')) {
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
- $i++;
- }
- else {
- }
- break;
-
- // ----- Look for options that request an array of string for value
- case PCLZIP_OPT_BY_NAME :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
- }
- else if (is_array($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that request an EREG or PREG expression
- case PCLZIP_OPT_BY_EREG :
- // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG
- // to PCLZIP_OPT_BY_PREG
- $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
- case PCLZIP_OPT_BY_PREG :
- //case PCLZIP_OPT_CRYPT :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that takes a string
- case PCLZIP_OPT_COMMENT :
- case PCLZIP_OPT_ADD_COMMENT :
- case PCLZIP_OPT_PREPEND_COMMENT :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
- "Missing parameter value for option '"
- .PclZipUtilOptionText($p_options_list[$i])
- ."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
- "Wrong parameter value for option '"
- .PclZipUtilOptionText($p_options_list[$i])
- ."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that request an array of index
- case PCLZIP_OPT_BY_INDEX :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_work_list = array();
- if (is_string($p_options_list[$i+1])) {
-
- // ----- Remove spaces
- $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
-
- // ----- Parse items
- $v_work_list = explode(",", $p_options_list[$i+1]);
- }
- else if (is_integer($p_options_list[$i+1])) {
- $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
- }
- else if (is_array($p_options_list[$i+1])) {
- $v_work_list = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Reduce the index list
- // each index item in the list must be a couple with a start and
- // an end value : [0,3], [5-5], [8-10], ...
- // ----- Check the format of each item
- $v_sort_flag=false;
- $v_sort_value=0;
- for ($j=0; $j= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- $i++;
- break;
-
- // ----- Look for options that request a call-back
- case PCLZIP_CB_PRE_EXTRACT :
- case PCLZIP_CB_POST_EXTRACT :
- case PCLZIP_CB_PRE_ADD :
- case PCLZIP_CB_POST_ADD :
- /* for futur use
- case PCLZIP_CB_PRE_DELETE :
- case PCLZIP_CB_POST_DELETE :
- case PCLZIP_CB_PRE_LIST :
- case PCLZIP_CB_POST_LIST :
- */
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_function_name = $p_options_list[$i+1];
-
- // ----- Check that the value is a valid existing function
- if (!function_exists($v_function_name)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Set the attribute
- $v_result_list[$p_options_list[$i]] = $v_function_name;
- $i++;
- break;
-
- default :
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Unknown parameter '"
- .$p_options_list[$i]."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Next options
- $i++;
- }
-
- // ----- Look for mandatory options
- if ($v_requested_options !== false) {
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
- // ----- Look for mandatory option
- if ($v_requested_options[$key] == 'mandatory') {
- // ----- Look if present
- if (!isset($v_result_list[$key])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
- }
- }
-
- // ----- Look for default values
- if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
-
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privOptionDefaultThreshold()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privOptionDefaultThreshold(&$p_options)
- {
- $v_result=1;
-
- if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
- return $v_result;
- }
-
- // ----- Get 'memory_limit' configuration value
- $v_memory_limit = ini_get('memory_limit');
- $v_memory_limit = trim($v_memory_limit);
- $v_memory_limit_int = (int) $v_memory_limit;
- $last = strtolower(substr($v_memory_limit, -1));
-
- if($last == 'g')
- //$v_memory_limit_int = $v_memory_limit_int*1024*1024*1024;
- $v_memory_limit_int = $v_memory_limit_int*1073741824;
- if($last == 'm')
- //$v_memory_limit_int = $v_memory_limit_int*1024*1024;
- $v_memory_limit_int = $v_memory_limit_int*1048576;
- if($last == 'k')
- $v_memory_limit_int = $v_memory_limit_int*1024;
-
- $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit_int*PCLZIP_TEMPORARY_FILE_RATIO);
-
-
- // ----- Sanity check : No threshold if value lower than 1M
- if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
- unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privFileDescrParseAtt()
- // Description :
- // Parameters :
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
- {
- $v_result=1;
-
- // ----- For each file in the list check the attributes
- foreach ($p_file_list as $v_key => $v_value) {
-
- // ----- Check if the option is supported
- if (!isset($v_requested_options[$v_key])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for attribute
- switch ($v_key) {
- case PCLZIP_ATT_FILE_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['filename'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- break;
-
- case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['new_short_name'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
- break;
-
- case PCLZIP_ATT_FILE_NEW_FULL_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['new_full_name'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
- break;
-
- // ----- Look for options that takes a string
- case PCLZIP_ATT_FILE_COMMENT :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['comment'] = $v_value;
- break;
-
- case PCLZIP_ATT_FILE_MTIME :
- if (!is_integer($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['mtime'] = $v_value;
- break;
-
- case PCLZIP_ATT_FILE_CONTENT :
- $p_filedescr['content'] = $v_value;
- break;
-
- default :
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Unknown parameter '".$v_key."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for mandatory options
- if ($v_requested_options !== false) {
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
- // ----- Look for mandatory option
- if ($v_requested_options[$key] == 'mandatory') {
- // ----- Look if present
- if (!isset($p_file_list[$key])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
- return PclZip::errorCode();
- }
- }
- }
- }
-
- // end foreach
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privFileDescrExpand()
- // Description :
- // This method look for each item of the list to see if its a file, a folder
- // or a string to be added as file. For any other type of files (link, other)
- // just ignore the item.
- // Then prepare the information that will be stored for that file.
- // When its a folder, expand the folder with all the files that are in that
- // folder (recursively).
- // Parameters :
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privFileDescrExpand(&$p_filedescr_list, &$p_options)
- {
- $v_result=1;
-
- // ----- Create a result list
- $v_result_list = array();
-
- // ----- Look each entry
- for ($i=0; $iprivCalculateStoredFilename($v_descr, $p_options);
-
- // ----- Add the descriptor in result list
- $v_result_list[sizeof($v_result_list)] = $v_descr;
-
- // ----- Look for folder
- if ($v_descr['type'] == 'folder') {
- // ----- List of items in folder
- $v_dirlist_descr = array();
- $v_dirlist_nb = 0;
- if ($v_folder_handler = @opendir($v_descr['filename'])) {
- while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
-
- // ----- Skip '.' and '..'
- if (($v_item_handler == '.') || ($v_item_handler == '..')) {
- continue;
- }
-
- // ----- Compose the full filename
- $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
-
- // ----- Look for different stored filename
- // Because the name of the folder was changed, the name of the
- // files/sub-folders also change
- if (($v_descr['stored_filename'] != $v_descr['filename'])
- && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
- if ($v_descr['stored_filename'] != '') {
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
- }
- else {
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
- }
- }
-
- $v_dirlist_nb++;
- }
-
- @closedir($v_folder_handler);
- }
- else {
- // TBC : unable to open folder in read mode
- }
-
- // ----- Expand each element of the list
- if ($v_dirlist_nb != 0) {
- // ----- Expand
- if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
- return $v_result;
- }
-
- // ----- Concat the resulting list
- $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
- }
- else {
- }
-
- // ----- Free local array
- unset($v_dirlist_descr);
- }
- }
-
- // ----- Get the result list
- $p_filedescr_list = $v_result_list;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCreate()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the file in write mode
- if (($v_result = $this->privOpenFd('wb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Add the list of files
- $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAdd()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Look if the archive exists or is empty
- if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
- {
-
- // ----- Do a create
- $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
-
- // ----- Return
- return $v_result;
- }
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
- {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = $v_central_dir['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Swap the file descriptor
- // Here is a trick : I swap the temporary fd with the zip fd, in order to use
- // the following methods on the temporary fil and not the real archive
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Add the files
- $v_header_list = array();
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
- {
- fclose($v_zip_temp_fd);
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($this->zip_fd);
-
- // ----- Copy the block of file headers from the old archive
- $v_size = $v_central_dir['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Create the Central Dir files header
- for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- fclose($v_zip_temp_fd);
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- $v_count++;
- }
-
- // ----- Transform the header to a 'usable' info
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
- // ----- Zip file comment
- $v_comment = $v_central_dir['comment'];
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
- if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
- $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
- }
- if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($this->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
- {
- // ----- Reset the file list
- unset($v_header_list);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Swap back the file descriptor
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privOpenFd()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privOpenFd($p_mode)
- {
- $v_result=1;
-
- // ----- Look if already open
- if ($this->zip_fd != 0)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCloseFd()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privCloseFd()
- {
- $v_result=1;
-
- if ($this->zip_fd != 0)
- @fclose($this->zip_fd);
- $this->zip_fd = 0;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddList()
- // Description :
- // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
- // different from the real path of the file. This is usefull if you want to have PclTar
- // running in any directory, and memorize relative path from an other directory.
- // Parameters :
- // $p_list : An array containing the file or directory names to add in the tar
- // $p_result_list : list of added files with their properties (specially the status field)
- // $p_add_dir : Path to add in the filename path archived
- // $p_remove_dir : Path to remove in the filename path archived
- // Return Values :
- // --------------------------------------------------------------------------------
-// function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
- function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
-
- // ----- Add the files
- $v_header_list = array();
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($this->zip_fd);
-
- // ----- Create the Central Dir files header
- for ($i=0,$v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- // ----- Return
- return $v_result;
- }
- $v_count++;
- }
-
- // ----- Transform the header to a 'usable' info
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
- // ----- Zip file comment
- $v_comment = '';
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($this->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
- {
- // ----- Reset the file list
- unset($v_header_list);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFileList()
- // Description :
- // Parameters :
- // $p_filedescr_list : An array containing the file description
- // or directory names to add in the zip
- // $p_result_list : list of added files with their properties (specially the status field)
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_header = array();
-
- // ----- Recuperate the current number of elt in list
- $v_nb = sizeof($p_result_list);
-
- // ----- Loop on the files
- for ($j=0; ($jprivAddFile($p_filedescr_list[$j], $v_header,
- $p_options);
- if ($v_result != 1) {
- return $v_result;
- }
-
- // ----- Store the file infos
- $p_result_list[$v_nb++] = $v_header;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFile($p_filedescr, &$p_header, &$p_options)
- {
- $v_result=1;
-
- // ----- Working variable
- $p_filename = $p_filedescr['filename'];
-
- // TBC : Already done in the fileAtt check ... ?
- if ($p_filename == "") {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for a stored different filename
- /* TBC : Removed
- if (isset($p_filedescr['stored_filename'])) {
- $v_stored_filename = $p_filedescr['stored_filename'];
- }
- else {
- $v_stored_filename = $p_filedescr['stored_filename'];
- }
- */
-
- // ----- Set the file properties
- clearstatcache();
- $p_header['version'] = 20;
- $p_header['version_extracted'] = 10;
- $p_header['flag'] = 0;
- $p_header['compression'] = 0;
- $p_header['crc'] = 0;
- $p_header['compressed_size'] = 0;
- $p_header['filename_len'] = strlen($p_filename);
- $p_header['extra_len'] = 0;
- $p_header['disk'] = 0;
- $p_header['internal'] = 0;
- $p_header['offset'] = 0;
- $p_header['filename'] = $p_filename;
-// TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
- $p_header['stored_filename'] = $p_filedescr['stored_filename'];
- $p_header['extra'] = '';
- $p_header['status'] = 'ok';
- $p_header['index'] = -1;
-
- // ----- Look for regular file
- if ($p_filedescr['type']=='file') {
- $p_header['external'] = 0x00000000;
- $p_header['size'] = filesize($p_filename);
- }
-
- // ----- Look for regular folder
- else if ($p_filedescr['type']=='folder') {
- $p_header['external'] = 0x00000010;
- $p_header['mtime'] = filemtime($p_filename);
- $p_header['size'] = filesize($p_filename);
- }
-
- // ----- Look for virtual file
- else if ($p_filedescr['type'] == 'virtual_file') {
- $p_header['external'] = 0x00000000;
- $p_header['size'] = strlen($p_filedescr['content']);
- }
-
-
- // ----- Look for filetime
- if (isset($p_filedescr['mtime'])) {
- $p_header['mtime'] = $p_filedescr['mtime'];
- }
- else if ($p_filedescr['type'] == 'virtual_file') {
- $p_header['mtime'] = time();
- }
- else {
- $p_header['mtime'] = filemtime($p_filename);
- }
-
- // ------ Look for file comment
- if (isset($p_filedescr['comment'])) {
- $p_header['comment_len'] = strlen($p_filedescr['comment']);
- $p_header['comment'] = $p_filedescr['comment'];
- }
- else {
- $p_header['comment_len'] = 0;
- $p_header['comment'] = '';
- }
-
- // ----- Look for pre-add callback
- if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
- $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_header['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
- $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
- }
- }
-
- // ----- Look for empty stored filename
- if ($p_header['stored_filename'] == "") {
- $p_header['status'] = "filtered";
- }
-
- // ----- Check the path length
- if (strlen($p_header['stored_filename']) > 0xFF) {
- $p_header['status'] = 'filename_too_long';
- }
-
- // ----- Look if no error, or file not skipped
- if ($p_header['status'] == 'ok') {
-
- // ----- Look for a file
- if ($p_filedescr['type'] == 'file') {
- // ----- Look for using temporary file to zip
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
- $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
- return $v_result;
- }
- }
-
- // ----- Use "in memory" zip algo
- else {
-
- // ----- Open the source file
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
- return PclZip::errorCode();
- }
-
- // ----- Read the file content
- $v_content = @fread($v_file, $p_header['size']);
-
- // ----- Close the file
- @fclose($v_file);
-
- // ----- Calculate the CRC
- $p_header['crc'] = @crc32($v_content);
-
- // ----- Look for no compression
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
- // ----- Set header parameters
- $p_header['compressed_size'] = $p_header['size'];
- $p_header['compression'] = 0;
- }
-
- // ----- Look for normal compression
- else {
- // ----- Compress the content
- $v_content = @gzdeflate($v_content);
-
- // ----- Set header parameters
- $p_header['compressed_size'] = strlen($v_content);
- $p_header['compression'] = 8;
- }
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- @fclose($v_file);
- return $v_result;
- }
-
- // ----- Write the compressed (or not) content
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
-
- }
-
- }
-
- // ----- Look for a virtual file (a file from string)
- else if ($p_filedescr['type'] == 'virtual_file') {
-
- $v_content = $p_filedescr['content'];
-
- // ----- Calculate the CRC
- $p_header['crc'] = @crc32($v_content);
-
- // ----- Look for no compression
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
- // ----- Set header parameters
- $p_header['compressed_size'] = $p_header['size'];
- $p_header['compression'] = 0;
- }
-
- // ----- Look for normal compression
- else {
- // ----- Compress the content
- $v_content = @gzdeflate($v_content);
-
- // ----- Set header parameters
- $p_header['compressed_size'] = strlen($v_content);
- $p_header['compression'] = 8;
- }
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- @fclose($v_file);
- return $v_result;
- }
-
- // ----- Write the compressed (or not) content
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
- }
-
- // ----- Look for a directory
- else if ($p_filedescr['type'] == 'folder') {
- // ----- Look for directory last '/'
- if (@substr($p_header['stored_filename'], -1) != '/') {
- $p_header['stored_filename'] .= '/';
- }
-
- // ----- Set the file properties
- $p_header['size'] = 0;
- //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked
- $p_header['external'] = 0x00000010; // Value for a folder : to be checked
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
- {
- return $v_result;
- }
- }
- }
-
- // ----- Look for post-add callback
- if (isset($p_options[PCLZIP_CB_POST_ADD])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
- $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
- if ($v_result == 0) {
- // ----- Ignored
- $v_result = 1;
- }
-
- // ----- Update the informations
- // Nothing can be modified
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFileUsingTempFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
- {
- $v_result=PCLZIP_ERR_NO_ERROR;
-
- // ----- Working variable
- $p_filename = $p_filedescr['filename'];
-
-
- // ----- Open the source file
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
- return PclZip::errorCode();
- }
-
- // ----- Creates a compressed temporary file
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
- if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
- fclose($v_file);
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = filesize($p_filename);
- while ($v_size != 0) {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_file, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @gzputs($v_file_compressed, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close the file
- @fclose($v_file);
- @gzclose($v_file_compressed);
-
- // ----- Check the minimum file size
- if (filesize($v_gzip_temp_name) < 18) {
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
- return PclZip::errorCode();
- }
-
- // ----- Extract the compressed attributes
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the gzip file header
- $v_binary_data = @fread($v_file_compressed, 10);
- $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
-
- // ----- Check some parameters
- $v_data_header['os'] = bin2hex($v_data_header['os']);
-
- // ----- Read the gzip file footer
- @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
- $v_binary_data = @fread($v_file_compressed, 8);
- $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
-
- // ----- Set the attributes
- $p_header['compression'] = ord($v_data_header['cm']);
- //$p_header['mtime'] = $v_data_header['mtime'];
- $p_header['crc'] = $v_data_footer['crc'];
- $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
-
- // ----- Close the file
- @fclose($v_file_compressed);
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- return $v_result;
- }
-
- // ----- Add the compressed data
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
- {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- fseek($v_file_compressed, 10);
- $v_size = $p_header['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_file_compressed, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close the file
- @fclose($v_file_compressed);
-
- // ----- Unlink the temporary file
- @unlink($v_gzip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCalculateStoredFilename()
- // Description :
- // Based on file descriptor properties and global options, this method
- // calculate the filename that will be stored in the archive.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privCalculateStoredFilename(&$p_filedescr, &$p_options)
- {
- $v_result=1;
-
- // ----- Working variables
- $p_filename = $p_filedescr['filename'];
- if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
- $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
- }
- else {
- $p_add_dir = '';
- }
- if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
- $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
- }
- else {
- $p_remove_dir = '';
- }
- if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- else {
- $p_remove_all_dir = 0;
- }
-
-
- // ----- Look for full name change
- if (isset($p_filedescr['new_full_name'])) {
- // ----- Remove drive letter if any
- $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
- }
-
- // ----- Look for path and/or short name change
- else {
-
- // ----- Look for short name change
- // Its when we cahnge just the filename but not the path
- if (isset($p_filedescr['new_short_name'])) {
- $v_path_info = pathinfo($p_filename);
- $v_dir = '';
- if ($v_path_info['dirname'] != '') {
- $v_dir = $v_path_info['dirname'].'/';
- }
- $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
- }
- else {
- // ----- Calculate the stored filename
- $v_stored_filename = $p_filename;
- }
-
- // ----- Look for all path to remove
- if ($p_remove_all_dir) {
- $v_stored_filename = basename($p_filename);
- }
- // ----- Look for partial path remove
- else if ($p_remove_dir != "") {
- if (substr($p_remove_dir, -1) != '/')
- $p_remove_dir .= "/";
-
- if ( (substr($p_filename, 0, 2) == "./")
- || (substr($p_remove_dir, 0, 2) == "./")) {
-
- if ( (substr($p_filename, 0, 2) == "./")
- && (substr($p_remove_dir, 0, 2) != "./")) {
- $p_remove_dir = "./".$p_remove_dir;
- }
- if ( (substr($p_filename, 0, 2) != "./")
- && (substr($p_remove_dir, 0, 2) == "./")) {
- $p_remove_dir = substr($p_remove_dir, 2);
- }
- }
-
- $v_compare = PclZipUtilPathInclusion($p_remove_dir,
- $v_stored_filename);
- if ($v_compare > 0) {
- if ($v_compare == 2) {
- $v_stored_filename = "";
- }
- else {
- $v_stored_filename = substr($v_stored_filename,
- strlen($p_remove_dir));
- }
- }
- }
-
- // ----- Remove drive letter if any
- $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
-
- // ----- Look for path to add
- if ($p_add_dir != "") {
- if (substr($p_add_dir, -1) == "/")
- $v_stored_filename = $p_add_dir.$v_stored_filename;
- else
- $v_stored_filename = $p_add_dir."/".$v_stored_filename;
- }
- }
-
- // ----- Filename (reduce the path of stored name)
- $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
- $p_filedescr['stored_filename'] = $v_stored_filename;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Store the offset position of the file
- $p_header['offset'] = ftell($this->zip_fd);
-
- // ----- Transform UNIX mtime to DOS format mdate/mtime
- $v_date = getdate($p_header['mtime']);
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
- $p_header['version_extracted'], $p_header['flag'],
- $p_header['compression'], $v_mtime, $v_mdate,
- $p_header['crc'], $p_header['compressed_size'],
- $p_header['size'],
- strlen($p_header['stored_filename']),
- $p_header['extra_len']);
-
- // ----- Write the first 148 bytes of the header in the archive
- fputs($this->zip_fd, $v_binary_data, 30);
-
- // ----- Write the variable fields
- if (strlen($p_header['stored_filename']) != 0)
- {
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
- }
- if ($p_header['extra_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteCentralFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteCentralFileHeader(&$p_header)
- {
- $v_result=1;
-
- // TBC
- //for(reset($p_header); $key = key($p_header); next($p_header)) {
- //}
-
- // ----- Transform UNIX mtime to DOS format mdate/mtime
- $v_date = getdate($p_header['mtime']);
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
-
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
- $p_header['version'], $p_header['version_extracted'],
- $p_header['flag'], $p_header['compression'],
- $v_mtime, $v_mdate, $p_header['crc'],
- $p_header['compressed_size'], $p_header['size'],
- strlen($p_header['stored_filename']),
- $p_header['extra_len'], $p_header['comment_len'],
- $p_header['disk'], $p_header['internal'],
- $p_header['external'], $p_header['offset']);
-
- // ----- Write the 42 bytes of the header in the zip file
- fputs($this->zip_fd, $v_binary_data, 46);
-
- // ----- Write the variable fields
- if (strlen($p_header['stored_filename']) != 0)
- {
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
- }
- if ($p_header['extra_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
- }
- if ($p_header['comment_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteCentralHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
- {
- $v_result=1;
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
- $p_nb_entries, $p_size,
- $p_offset, strlen($p_comment));
-
- // ----- Write the 22 bytes of the header in the zip file
- fputs($this->zip_fd, $v_binary_data, 22);
-
- // ----- Write the variable fields
- if (strlen($p_comment) != 0)
- {
- fputs($this->zip_fd, $p_comment, strlen($p_comment));
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privList()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privList(&$p_list)
- {
- $v_result=1;
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
- {
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Go to beginning of Central Dir
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_central_dir['offset']))
- {
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read each entry
- for ($i=0; $i<$v_central_dir['entries']; $i++)
- {
- // ----- Read the file header
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
- $v_header['index'] = $i;
-
- // ----- Get the only interesting attributes
- $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
- unset($v_header);
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privConvertHeader2FileInfo()
- // Description :
- // This function takes the file informations from the central directory
- // entries and extract the interesting parameters that will be given back.
- // The resulting file infos are set in the array $p_info
- // $p_info['filename'] : Filename with full path. Given by user (add),
- // extracted in the filesystem (extract).
- // $p_info['stored_filename'] : Stored filename in the archive.
- // $p_info['size'] = Size of the file.
- // $p_info['compressed_size'] = Compressed size of the file.
- // $p_info['mtime'] = Last modification date of the file.
- // $p_info['comment'] = Comment associated with the file.
- // $p_info['folder'] = true/false : indicates if the entry is a folder or not.
- // $p_info['status'] = status of the action on the file.
- // $p_info['crc'] = CRC of the file content.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privConvertHeader2FileInfo($p_header, &$p_info)
- {
- $v_result=1;
-
- // ----- Get the interesting attributes
- $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
- $p_info['filename'] = $v_temp_path;
- $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
- $p_info['stored_filename'] = $v_temp_path;
- $p_info['size'] = $p_header['size'];
- $p_info['compressed_size'] = $p_header['compressed_size'];
- $p_info['mtime'] = $p_header['mtime'];
- $p_info['comment'] = $p_header['comment'];
- $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
- $p_info['index'] = $p_header['index'];
- $p_info['status'] = $p_header['status'];
- $p_info['crc'] = $p_header['crc'];
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractByRule()
- // Description :
- // Extract a file or directory depending of rules (by index, by name, ...)
- // Parameters :
- // $p_file_list : An array where will be placed the properties of each
- // extracted file
- // $p_path : Path to add while writing the extracted files
- // $p_remove_path : Path to remove (from the file memorized path) while writing the
- // extracted files. If the path does not match the file path,
- // the file is extracted with its memorized path.
- // $p_remove_path does not apply to 'list' mode.
- // $p_path and $p_remove_path are commulative.
- // Return Values :
- // 1 on success,0 or less on error (see error code list)
- // --------------------------------------------------------------------------------
- function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
- {
- $v_result=1;
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Check the path
- if ( ($p_path == "")
- || ( (substr($p_path, 0, 1) != "/")
- && (substr($p_path, 0, 3) != "../")
- && (substr($p_path,1,2)!=":/")))
- $p_path = "./".$p_path;
-
- // ----- Reduce the path last (and duplicated) '/'
- if (($p_path != "./") && ($p_path != "/"))
- {
- // ----- Look for the path end '/'
- while (substr($p_path, -1) == "/")
- {
- $p_path = substr($p_path, 0, strlen($p_path)-1);
- }
- }
-
- // ----- Look for path to remove format (should end by /)
- if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
- {
- $p_remove_path .= '/';
- }
- $p_remove_path_size = strlen($p_remove_path);
-
- // ----- Open the zip file
- if (($v_result = $this->privOpenFd('rb')) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Start at beginning of Central Dir
- $v_pos_entry = $v_central_dir['offset'];
-
- // ----- Read each entry
- $j_start = 0;
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
- {
-
- // ----- Read next Central dir entry
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_pos_entry))
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the file header
- $v_header = array();
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Store the index
- $v_header['index'] = $i;
-
- // ----- Store the file position
- $v_pos_entry = ftell($this->zip_fd);
-
- // ----- Look for the specific extract rules
- $v_extract = false;
-
- // ----- Look for extract by name rule
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
-
- // ----- Look if the filename is in the list
- for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
- && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_extract = true;
- }
- }
- // ----- Look for a filename
- elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
- $v_extract = true;
- }
- }
- }
-
- // ----- Look for extract by ereg rule
- // ereg() is deprecated with PHP 5.3
- /*
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
-
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
- $v_extract = true;
- }
- }
- */
-
- // ----- Look for extract by preg rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
-
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
- $v_extract = true;
- }
- }
-
- // ----- Look for extract by index rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
-
- // ----- Look if the index is in the list
- for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
- $v_extract = true;
- }
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
- $j_start = $j+1;
- }
-
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
- break;
- }
- }
- }
-
- // ----- Look for no rule, which means extract all the archive
- else {
- $v_extract = true;
- }
-
- // ----- Check compression method
- if ( ($v_extract)
- && ( ($v_header['compression'] != 8)
- && ($v_header['compression'] != 0))) {
- $v_header['status'] = 'unsupported_compression';
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
- "Filename '".$v_header['stored_filename']."' is "
- ."compressed by an unsupported compression "
- ."method (".$v_header['compression'].") ");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Check encrypted files
- if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
- $v_header['status'] = 'unsupported_encryption';
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
- "Unsupported encryption for "
- ." filename '".$v_header['stored_filename']
- ."'");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look for real extraction
- if (($v_extract) && ($v_header['status'] != 'ok')) {
- $v_result = $this->privConvertHeader2FileInfo($v_header,
- $p_file_list[$v_nb_extracted++]);
- if ($v_result != 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- $v_extract = false;
- }
-
- // ----- Look for real extraction
- if ($v_extract)
- {
-
- // ----- Go to the file position
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_header['offset']))
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for extraction as string
- if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
-
- $v_string = '';
-
- // ----- Extracting the file
- $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Set the file content
- $p_file_list[$v_nb_extracted]['content'] = $v_string;
-
- // ----- Next extracted file
- $v_nb_extracted++;
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- // ----- Look for extraction in standard output
- elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
- && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
- // ----- Extracting the file in standard output
- $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- // ----- Look for normal extraction
- else {
- // ----- Extracting the file
- $v_result1 = $this->privExtractFile($v_header,
- $p_path, $p_remove_path,
- $p_remove_all_path,
- $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- }
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFile()
- // Description :
- // Parameters :
- // Return Values :
- //
- // 1 : ... ?
- // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
- // --------------------------------------------------------------------------------
- function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for all path to remove
- if ($p_remove_all_path == true) {
- // ----- Look for folder entry that not need to be extracted
- if (($p_entry['external']&0x00000010)==0x00000010) {
-
- $p_entry['status'] = "filtered";
-
- return $v_result;
- }
-
- // ----- Get the basename of the path
- $p_entry['filename'] = basename($p_entry['filename']);
- }
-
- // ----- Look for path to remove
- else if ($p_remove_path != "")
- {
- if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
- {
-
- // ----- Change the file status
- $p_entry['status'] = "filtered";
-
- // ----- Return
- return $v_result;
- }
-
- $p_remove_path_size = strlen($p_remove_path);
- if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
- {
-
- // ----- Remove the path
- $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
-
- }
- }
-
- // ----- Add the path
- if ($p_path != '') {
- $p_entry['filename'] = $p_path."/".$p_entry['filename'];
- }
-
- // ----- Check a base_dir_restriction
- if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
- $v_inclusion
- = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
- $p_entry['filename']);
- if ($v_inclusion == 0) {
-
- PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
- "Filename '".$p_entry['filename']."' is "
- ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Look for specific actions while the file exist
- if (file_exists($p_entry['filename']))
- {
-
- // ----- Look if file is a directory
- if (is_dir($p_entry['filename']))
- {
-
- // ----- Change the file status
- $p_entry['status'] = "already_a_directory";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
- "Filename '".$p_entry['filename']."' is "
- ."already used by an existing directory");
-
- return PclZip::errorCode();
- }
- }
- // ----- Look if file is write protected
- else if (!is_writeable($p_entry['filename']))
- {
-
- // ----- Change the file status
- $p_entry['status'] = "write_protected";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
- "Filename '".$p_entry['filename']."' exists "
- ."and is write protected");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look if the extracted file is older
- else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
- {
- // ----- Change the file status
- if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
- && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
- }
- else {
- $p_entry['status'] = "newer_exist";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
- "Newer version of '".$p_entry['filename']."' exists "
- ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
-
- return PclZip::errorCode();
- }
- }
- }
- else {
- }
- }
-
- // ----- Check the directory availability and create it if necessary
- else {
- if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
- $v_dir_to_check = $p_entry['filename'];
- else if (!strstr($p_entry['filename'], "/"))
- $v_dir_to_check = "";
- else
- $v_dir_to_check = dirname($p_entry['filename']);
-
- if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
-
- // ----- Change the file status
- $p_entry['status'] = "path_creation_fail";
-
- // ----- Return
- //return $v_result;
- $v_result = 1;
- }
- }
- }
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010))
- {
- // ----- Look for not compressed file
- if ($p_entry['compression'] == 0) {
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
- {
-
- // ----- Change the file status
- $p_entry['status'] = "write_error";
-
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- /* Try to speed up the code
- $v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_binary_data, $v_read_size);
- */
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Closing the destination file
- fclose($v_dest_file);
-
- // ----- Change the file mtime
- touch($p_entry['filename'], $p_entry['mtime']);
-
-
- }
- else {
- // ----- TBC
- // Need to be finished
- if (($p_entry['flag'] & 1) == 1) {
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
- return PclZip::errorCode();
- }
-
-
- // ----- Look for using temporary file to unzip
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
- $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
- return $v_result;
- }
- }
-
- // ----- Look for extract in memory
- else {
-
-
- // ----- Read the compressed file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- $v_file_content = @gzinflate($v_buffer);
- unset($v_buffer);
- if ($v_file_content === FALSE) {
-
- // ----- Change the file status
- // TBC
- $p_entry['status'] = "error";
-
- return $v_result;
- }
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
-
- // ----- Change the file status
- $p_entry['status'] = "write_error";
-
- return $v_result;
- }
-
- // ----- Write the uncompressed data
- @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
- unset($v_file_content);
-
- // ----- Closing the destination file
- @fclose($v_dest_file);
-
- }
-
- // ----- Change the file mtime
- @touch($p_entry['filename'], $p_entry['mtime']);
- }
-
- // ----- Look for chmod option
- if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
-
- // ----- Change the mode of the file
- @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
- }
-
- }
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileUsingTempFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileUsingTempFile(&$p_entry, &$p_options)
- {
- $v_result=1;
-
- // ----- Creates a temporary file
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
- if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
- fclose($v_file);
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
- return PclZip::errorCode();
- }
-
-
- // ----- Write gz file format header
- $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
- @fwrite($v_dest_file, $v_binary_data, 10);
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Write gz file format footer
- $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
- @fwrite($v_dest_file, $v_binary_data, 8);
-
- // ----- Close the temporary file
- @fclose($v_dest_file);
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
- $p_entry['status'] = "write_error";
- return $v_result;
- }
-
- // ----- Open the temporary gz file
- if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
- @fclose($v_dest_file);
- $p_entry['status'] = "read_error";
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['size'];
- while ($v_size != 0) {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($v_src_file, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
- @fclose($v_dest_file);
- @gzclose($v_src_file);
-
- // ----- Delete the temporary file
- @unlink($v_gzip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileInOutput()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileInOutput(&$p_entry, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
- // ----- Trace
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
- // ----- Look for not compressed file
- if ($p_entry['compressed_size'] == $p_entry['size']) {
-
- // ----- Read the file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Send the file to the output
- echo $v_buffer;
- unset($v_buffer);
- }
- else {
-
- // ----- Read the compressed file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- $v_file_content = gzinflate($v_buffer);
- unset($v_buffer);
-
- // ----- Send the file to the output
- echo $v_file_content;
- unset($v_file_content);
- }
- }
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileAsString()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- $v_header = array();
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
- // ----- Look for not compressed file
- // if ($p_entry['compressed_size'] == $p_entry['size'])
- if ($p_entry['compression'] == 0) {
-
- // ----- Reading the file
- $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
- }
- else {
-
- // ----- Reading the file
- $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- if (($p_string = @gzinflate($v_data)) === FALSE) {
- // TBC
- }
- }
-
- // ----- Trace
- }
- else {
- // TBC : error : can not extract a folder in a string
- }
-
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Swap the content to header
- $v_local_header['content'] = $p_string;
- $p_string = '';
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Swap back the content to header
- $p_string = $v_local_header['content'];
- unset($v_local_header['content']);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Read the 4 bytes signature
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] != 0x04034b50)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the first 42 bytes of the header
- $v_binary_data = fread($this->zip_fd, 26);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 26)
- {
- $p_header['filename'] = "";
- $p_header['status'] = "invalid_header";
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
-
- // ----- Get filename
- $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
-
- // ----- Get extra_fields
- if ($v_data['extra_len'] != 0) {
- $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
- }
- else {
- $p_header['extra'] = '';
- }
-
- // ----- Extract properties
- $p_header['version_extracted'] = $v_data['version'];
- $p_header['compression'] = $v_data['compression'];
- $p_header['size'] = $v_data['size'];
- $p_header['compressed_size'] = $v_data['compressed_size'];
- $p_header['crc'] = $v_data['crc'];
- $p_header['flag'] = $v_data['flag'];
- $p_header['filename_len'] = $v_data['filename_len'];
-
- // ----- Recuperate date in UNIX format
- $p_header['mdate'] = $v_data['mdate'];
- $p_header['mtime'] = $v_data['mtime'];
- if ($p_header['mdate'] && $p_header['mtime'])
- {
- // ----- Extract time
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
-
- // ----- Extract date
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
- $v_day = $p_header['mdate'] & 0x001F;
-
- // ----- Get UNIX date format
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
-
- }
- else
- {
- $p_header['mtime'] = time();
- }
-
- // TBC
- //for(reset($v_data); $key = key($v_data); next($v_data)) {
- //}
-
- // ----- Set the stored filename
- $p_header['stored_filename'] = $p_header['filename'];
-
- // ----- Set the status field
- $p_header['status'] = "ok";
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadCentralFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadCentralFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Read the 4 bytes signature
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] != 0x02014b50)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the first 42 bytes of the header
- $v_binary_data = fread($this->zip_fd, 42);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 42)
- {
- $p_header['filename'] = "";
- $p_header['status'] = "invalid_header";
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
-
- // ----- Get filename
- if ($p_header['filename_len'] != 0)
- $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
- else
- $p_header['filename'] = '';
-
- // ----- Get extra
- if ($p_header['extra_len'] != 0)
- $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
- else
- $p_header['extra'] = '';
-
- // ----- Get comment
- if ($p_header['comment_len'] != 0)
- $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
- else
- $p_header['comment'] = '';
-
- // ----- Extract properties
-
- // ----- Recuperate date in UNIX format
- //if ($p_header['mdate'] && $p_header['mtime'])
- // TBC : bug : this was ignoring time with 0/0/0
- if (1)
- {
- // ----- Extract time
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
-
- // ----- Extract date
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
- $v_day = $p_header['mdate'] & 0x001F;
-
- // ----- Get UNIX date format
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
-
- }
- else
- {
- $p_header['mtime'] = time();
- }
-
- // ----- Set the stored filename
- $p_header['stored_filename'] = $p_header['filename'];
-
- // ----- Set default status to ok
- $p_header['status'] = 'ok';
-
- // ----- Look if it is a directory
- if (substr($p_header['filename'], -1) == '/') {
- //$p_header['external'] = 0x41FF0010;
- $p_header['external'] = 0x00000010;
- }
-
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCheckFileHeaders()
- // Description :
- // Parameters :
- // Return Values :
- // 1 on success,
- // 0 on error;
- // --------------------------------------------------------------------------------
- function privCheckFileHeaders(&$p_local_header, &$p_central_header)
- {
- $v_result=1;
-
- // ----- Check the static values
- // TBC
- if ($p_local_header['filename'] != $p_central_header['filename']) {
- }
- if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
- }
- if ($p_local_header['flag'] != $p_central_header['flag']) {
- }
- if ($p_local_header['compression'] != $p_central_header['compression']) {
- }
- if ($p_local_header['mtime'] != $p_central_header['mtime']) {
- }
- if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
- }
-
- // ----- Look for flag bit 3
- if (($p_local_header['flag'] & 8) == 8) {
- $p_local_header['size'] = $p_central_header['size'];
- $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
- $p_local_header['crc'] = $p_central_header['crc'];
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadEndCentralDir()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadEndCentralDir(&$p_central_dir)
- {
- $v_result=1;
-
- // ----- Go to the end of the zip file
- $v_size = filesize($this->zipname);
- @fseek($this->zip_fd, $v_size);
- if (@ftell($this->zip_fd) != $v_size)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- First try : look if this is an archive with no commentaries (most of the time)
- // in this case the end of central dir is at 22 bytes of the file end
- $v_found = 0;
- if ($v_size > 26) {
- @fseek($this->zip_fd, $v_size-22);
- if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read for bytes
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = @unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] == 0x06054b50) {
- $v_found = 1;
- }
-
- $v_pos = ftell($this->zip_fd);
- }
-
- // ----- Go back to the maximum possible size of the Central Dir End Record
- if (!$v_found) {
- $v_maximum_size = 65557; // 0xFFFF + 22;
- if ($v_maximum_size > $v_size)
- $v_maximum_size = $v_size;
- @fseek($this->zip_fd, $v_size-$v_maximum_size);
- if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read byte per byte in order to find the signature
- $v_pos = ftell($this->zip_fd);
- $v_bytes = 0x00000000;
- while ($v_pos < $v_size)
- {
- // ----- Read a byte
- $v_byte = @fread($this->zip_fd, 1);
-
- // ----- Add the byte
- //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
- // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
- // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
- $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
-
- // ----- Compare the bytes
- if ($v_bytes == 0x504b0506)
- {
- $v_pos++;
- break;
- }
-
- $v_pos++;
- }
-
- // ----- Look if not found end of central dir
- if ($v_pos == $v_size)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
-
- // ----- Read the first 18 bytes of the header
- $v_binary_data = fread($this->zip_fd, 18);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 18)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
-
- // ----- Check the global size
- if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
-
- // ----- Removed in release 2.2 see readme file
- // The check of the file size is a little too strict.
- // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
- // While decrypted, zip has training 0 bytes
- if (0) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
- 'The central dir is not at the end of the archive.'
- .' Some trailing bytes exists after the archive.');
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
-
- // ----- Get comment
- if ($v_data['comment_size'] != 0) {
- $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
- }
- else
- $p_central_dir['comment'] = '';
-
- $p_central_dir['entries'] = $v_data['entries'];
- $p_central_dir['disk_entries'] = $v_data['disk_entries'];
- $p_central_dir['offset'] = $v_data['offset'];
- $p_central_dir['size'] = $v_data['size'];
- $p_central_dir['disk'] = $v_data['disk'];
- $p_central_dir['disk_start'] = $v_data['disk_start'];
-
- // TBC
- //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
- //}
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDeleteByRule()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDeleteByRule(&$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Scan all the files
- // ----- Start at beginning of Central Dir
- $v_pos_entry = $v_central_dir['offset'];
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_pos_entry))
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read each entry
- $v_header_list = array();
- $j_start = 0;
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
- {
-
- // ----- Read the file header
- $v_header_list[$v_nb_extracted] = array();
- if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- return $v_result;
- }
-
-
- // ----- Store the index
- $v_header_list[$v_nb_extracted]['index'] = $i;
-
- // ----- Look for the specific extract rules
- $v_found = false;
-
- // ----- Look for extract by name rule
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
-
- // ----- Look if the filename is in the list
- for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
- && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_found = true;
- }
- elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
- && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_found = true;
- }
- }
- // ----- Look for a filename
- elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
- $v_found = true;
- }
- }
- }
-
- // ----- Look for extract by ereg rule
- // ereg() is deprecated with PHP 5.3
- /*
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
-
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
- $v_found = true;
- }
- }
- */
-
- // ----- Look for extract by preg rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
-
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
- $v_found = true;
- }
- }
-
- // ----- Look for extract by index rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
-
- // ----- Look if the index is in the list
- for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
- $v_found = true;
- }
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
- $j_start = $j+1;
- }
-
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
- break;
- }
- }
- }
- else {
- $v_found = true;
- }
-
- // ----- Look for deletion
- if ($v_found)
- {
- unset($v_header_list[$v_nb_extracted]);
- }
- else
- {
- $v_nb_extracted++;
- }
- }
-
- // ----- Look if something need to be deleted
- if ($v_nb_extracted > 0) {
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Creates a temporary zip archive
- $v_temp_zip = new PclZip($v_zip_temp_name);
-
- // ----- Open the temporary zip file in write mode
- if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
- $this->privCloseFd();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Look which file need to be kept
- for ($i=0; $izip_fd);
- if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the file header
- $v_local_header = array();
- if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Check that local file header is same as central file header
- if ($this->privCheckFileHeaders($v_local_header,
- $v_header_list[$i]) != 1) {
- // TBC
- }
- unset($v_local_header);
-
- // ----- Write the file header
- if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read/write the data block
- if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($v_temp_zip->zip_fd);
-
- // ----- Re-Create the Central Dir files header
- for ($i=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Transform the header to a 'usable' info
- $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
-
- // ----- Zip file comment
- $v_comment = '';
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
- // ----- Reset the file list
- unset($v_header_list);
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Close
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Destroy the temporary archive
- unset($v_temp_zip);
- }
-
- // ----- Remove every files : reset the file
- else if ($v_central_dir['entries'] != 0) {
- $this->privCloseFd();
-
- if (($v_result = $this->privOpenFd('wb')) != 1) {
- return $v_result;
- }
-
- if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
- return $v_result;
- }
-
- $this->privCloseFd();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDirCheck()
- // Description :
- // Check if a directory exists, if not it creates it and all the parents directory
- // which may be useful.
- // Parameters :
- // $p_dir : Directory path to check.
- // Return Values :
- // 1 : OK
- // -1 : Unable to create directory
- // --------------------------------------------------------------------------------
- function privDirCheck($p_dir, $p_is_dir=false)
- {
- $v_result = 1;
-
-
- // ----- Remove the final '/'
- if (($p_is_dir) && (substr($p_dir, -1)=='/'))
- {
- $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
- }
-
- // ----- Check the directory availability
- if ((is_dir($p_dir)) || ($p_dir == ""))
- {
- return 1;
- }
-
- // ----- Extract parent directory
- $p_parent_dir = dirname($p_dir);
-
- // ----- Just a check
- if ($p_parent_dir != $p_dir)
- {
- // ----- Look for parent directory
- if ($p_parent_dir != "")
- {
- if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
- {
- return $v_result;
- }
- }
- }
-
- // ----- Create the directory
- if (!@mkdir($p_dir, 0777))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privMerge()
- // Description :
- // If $p_archive_to_add does not exist, the function exit with a success result.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privMerge(&$p_archive_to_add)
- {
- $v_result=1;
-
- // ----- Look if the archive_to_add exists
- if (!is_file($p_archive_to_add->zipname))
- {
-
- // ----- Nothing to merge, so merge is a success
- $v_result = 1;
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Look if the archive exists
- if (!is_file($this->zipname))
- {
-
- // ----- Do a duplicate
- $v_result = $this->privDuplicate($p_archive_to_add->zipname);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Open the archive_to_add file
- if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
- {
- $this->privCloseFd();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir_to_add = array();
- if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($p_archive_to_add->zip_fd);
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = $v_central_dir['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Copy the files from the archive_to_add into the temporary file
- $v_size = $v_central_dir_to_add['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($v_zip_temp_fd);
-
- // ----- Copy the block of file headers from the old archive
- $v_size = $v_central_dir['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Copy the block of file headers from the archive_to_add
- $v_size = $v_central_dir_to_add['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Merge the file comments
- $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
-
- // ----- Calculate the size of the (new) central header
- $v_size = @ftell($v_zip_temp_fd)-$v_offset;
-
- // ----- Swap the file descriptor
- // Here is a trick : I swap the temporary fd with the zip fd, in order to use
- // the following methods on the temporary fil and not the real archive fd
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
- @fclose($v_zip_temp_fd);
- $this->zip_fd = null;
-
- // ----- Reset the file list
- unset($v_header_list);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Swap back the file descriptor
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Close
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDuplicate()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDuplicate($p_archive_filename)
- {
- $v_result=1;
-
- // ----- Look if the $p_archive_filename exists
- if (!is_file($p_archive_filename))
- {
-
- // ----- Nothing to duplicate, so duplicate is a success.
- $v_result = 1;
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('wb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
- {
- $this->privCloseFd();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = filesize($p_archive_filename);
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($v_zip_temp_fd, $v_read_size);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privErrorLog()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privErrorLog($p_error_code=0, $p_error_string='')
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- PclError($p_error_code, $p_error_string);
- }
- else {
- $this->error_code = $p_error_code;
- $this->error_string = $p_error_string;
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privErrorReset()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privErrorReset()
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- PclErrorReset();
- }
- else {
- $this->error_code = 0;
- $this->error_string = '';
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDisableMagicQuotes()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDisableMagicQuotes()
- {
- $v_result=1;
-
- // EDIT for WordPress 5.3.0
- // magic_quote functions are deprecated in PHP 7.4, now assuming it's always off.
- /*
-
- // ----- Look if function exists
- if ( (!function_exists("get_magic_quotes_runtime"))
- || (!function_exists("set_magic_quotes_runtime"))) {
- return $v_result;
- }
-
- // ----- Look if already done
- if ($this->magic_quotes_status != -1) {
- return $v_result;
- }
-
- // ----- Get and memorize the magic_quote value
- $this->magic_quotes_status = @get_magic_quotes_runtime();
-
- // ----- Disable magic_quotes
- if ($this->magic_quotes_status == 1) {
- @set_magic_quotes_runtime(0);
- }
- */
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privSwapBackMagicQuotes()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privSwapBackMagicQuotes()
- {
- $v_result=1;
-
- // EDIT for WordPress 5.3.0
- // magic_quote functions are deprecated in PHP 7.4, now assuming it's always off.
- /*
-
- // ----- Look if function exists
- if ( (!function_exists("get_magic_quotes_runtime"))
- || (!function_exists("set_magic_quotes_runtime"))) {
- return $v_result;
- }
-
- // ----- Look if something to do
- if ($this->magic_quotes_status != -1) {
- return $v_result;
- }
-
- // ----- Swap back magic_quotes
- if ($this->magic_quotes_status == 1) {
- @set_magic_quotes_runtime($this->magic_quotes_status);
- }
-
- */
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- }
- // End of class
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilPathReduction()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclZipUtilPathReduction($p_dir)
- {
- $v_result = "";
-
- // ----- Look for not empty path
- if ($p_dir != "") {
- // ----- Explode path by directory names
- $v_list = explode("/", $p_dir);
-
- // ----- Study directories from last to first
- $v_skip = 0;
- for ($i=sizeof($v_list)-1; $i>=0; $i--) {
- // ----- Look for current path
- if ($v_list[$i] == ".") {
- // ----- Ignore this directory
- // Should be the first $i=0, but no check is done
- }
- else if ($v_list[$i] == "..") {
- $v_skip++;
- }
- else if ($v_list[$i] == "") {
- // ----- First '/' i.e. root slash
- if ($i == 0) {
- $v_result = "/".$v_result;
- if ($v_skip > 0) {
- // ----- It is an invalid path, so the path is not modified
- // TBC
- $v_result = $p_dir;
- $v_skip = 0;
- }
- }
- // ----- Last '/' i.e. indicates a directory
- else if ($i == (sizeof($v_list)-1)) {
- $v_result = $v_list[$i];
- }
- // ----- Double '/' inside the path
- else {
- // ----- Ignore only the double '//' in path,
- // but not the first and last '/'
- }
- }
- else {
- // ----- Look for item to skip
- if ($v_skip > 0) {
- $v_skip--;
- }
- else {
- $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
- }
- }
- }
-
- // ----- Look for skip
- if ($v_skip > 0) {
- while ($v_skip > 0) {
- $v_result = '../'.$v_result;
- $v_skip--;
- }
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilPathInclusion()
- // Description :
- // This function indicates if the path $p_path is under the $p_dir tree. Or,
- // said in an other way, if the file or sub-dir $p_path is inside the dir
- // $p_dir.
- // The function indicates also if the path is exactly the same as the dir.
- // This function supports path with duplicated '/' like '//', but does not
- // support '.' or '..' statements.
- // Parameters :
- // Return Values :
- // 0 if $p_path is not inside directory $p_dir
- // 1 if $p_path is inside directory $p_dir
- // 2 if $p_path is exactly the same as $p_dir
- // --------------------------------------------------------------------------------
- function PclZipUtilPathInclusion($p_dir, $p_path)
- {
- $v_result = 1;
-
- // ----- Look for path beginning by ./
- if ( ($p_dir == '.')
- || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
- $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
- }
- if ( ($p_path == '.')
- || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
- $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
- }
-
- // ----- Explode dir and path by directory separator
- $v_list_dir = explode("/", $p_dir);
- $v_list_dir_size = sizeof($v_list_dir);
- $v_list_path = explode("/", $p_path);
- $v_list_path_size = sizeof($v_list_path);
-
- // ----- Study directories paths
- $i = 0;
- $j = 0;
- while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
-
- // ----- Look for empty dir (path reduction)
- if ($v_list_dir[$i] == '') {
- $i++;
- continue;
- }
- if ($v_list_path[$j] == '') {
- $j++;
- continue;
- }
-
- // ----- Compare the items
- if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
- $v_result = 0;
- }
-
- // ----- Next items
- $i++;
- $j++;
- }
-
- // ----- Look if everything seems to be the same
- if ($v_result) {
- // ----- Skip all the empty items
- while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
- while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
-
- if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
- // ----- There are exactly the same
- $v_result = 2;
- }
- else if ($i < $v_list_dir_size) {
- // ----- The path is shorter than the dir
- $v_result = 0;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilCopyBlock()
- // Description :
- // Parameters :
- // $p_mode : read/write compression mode
- // 0 : src & dest normal
- // 1 : src gzip, dest normal
- // 2 : src normal, dest gzip
- // 3 : src & dest gzip
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
- {
- $v_result = 1;
-
- if ($p_mode==0)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_src, $v_read_size);
- @fwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==1)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($p_src, $v_read_size);
- @fwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==2)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_src, $v_read_size);
- @gzwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==3)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($p_src, $v_read_size);
- @gzwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilRename()
- // Description :
- // This function tries to do a simple rename() function. If it fails, it
- // tries to copy the $p_src file in a new $p_dest file and then unlink the
- // first one.
- // Parameters :
- // $p_src : Old filename
- // $p_dest : New filename
- // Return Values :
- // 1 on success, 0 on failure.
- // --------------------------------------------------------------------------------
- function PclZipUtilRename($p_src, $p_dest)
- {
- $v_result = 1;
-
- // ----- Try to rename the files
- if (!@rename($p_src, $p_dest)) {
-
- // ----- Try to copy & unlink the src
- if (!@copy($p_src, $p_dest)) {
- $v_result = 0;
- }
- else if (!@unlink($p_src)) {
- $v_result = 0;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilOptionText()
- // Description :
- // Translate option value in text. Mainly for debug purpose.
- // Parameters :
- // $p_option : the option value.
- // Return Values :
- // The option text value.
- // --------------------------------------------------------------------------------
- function PclZipUtilOptionText($p_option)
- {
-
- $v_list = get_defined_constants();
- for (reset($v_list); $v_key = key($v_list); next($v_list)) {
- $v_prefix = substr($v_key, 0, 10);
- if (( ($v_prefix == 'PCLZIP_OPT')
- || ($v_prefix == 'PCLZIP_CB_')
- || ($v_prefix == 'PCLZIP_ATT'))
- && ($v_list[$v_key] == $p_option)) {
- return $v_key;
- }
- }
-
- $v_result = 'Unknown';
-
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilTranslateWinPath()
- // Description :
- // Translate windows path by replacing '\' by '/' and optionally removing
- // drive letter.
- // Parameters :
- // $p_path : path to translate.
- // $p_remove_disk_letter : true | false
- // Return Values :
- // The path translated.
- // --------------------------------------------------------------------------------
- function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
- {
- if (stristr(php_uname(), 'windows')) {
- // ----- Look for potential disk letter
- if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
- $p_path = substr($p_path, $v_position+1);
- }
- // ----- Change potential windows directory separator
- if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
- $p_path = strtr($p_path, '\\', '/');
- }
- }
- return $p_path;
- }
- // --------------------------------------------------------------------------------
-
-
-?>
diff --git a/srcs/wordpress/wp-admin/includes/class-plugin-installer-skin.php b/srcs/wordpress/wp-admin/includes/class-plugin-installer-skin.php
deleted file mode 100644
index bfbfe3b..0000000
--- a/srcs/wordpress/wp-admin/includes/class-plugin-installer-skin.php
+++ /dev/null
@@ -1,141 +0,0 @@
- 'web',
- 'url' => '',
- 'plugin' => '',
- 'nonce' => '',
- 'title' => '',
- );
- $args = wp_parse_args( $args, $defaults );
-
- $this->type = $args['type'];
- $this->api = isset( $args['api'] ) ? $args['api'] : array();
-
- parent::__construct( $args );
- }
-
- /**
- */
- public function before() {
- if ( ! empty( $this->api ) ) {
- $this->upgrader->strings['process_success'] = sprintf(
- /* translators: 1: Plugin name, 2: Plugin version. */
- __( 'Successfully installed the plugin %1$s %2$s .' ),
- $this->api->name,
- $this->api->version
- );
- }
- }
-
- /**
- */
- public function after() {
- $plugin_file = $this->upgrader->plugin_info();
-
- $install_actions = array();
-
- $from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins';
-
- if ( 'import' == $from ) {
- $install_actions['activate_plugin'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=activate&from=import&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
- __( 'Activate Plugin & Run Importer' )
- );
- } elseif ( 'press-this' == $from ) {
- $install_actions['activate_plugin'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=activate&from=press-this&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
- __( 'Activate Plugin & Return to Press This' )
- );
- } else {
- $install_actions['activate_plugin'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
- __( 'Activate Plugin' )
- );
- }
-
- if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
- $install_actions['network_activate'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=activate&networkwide=1&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
- __( 'Network Activate' )
- );
- unset( $install_actions['activate_plugin'] );
- }
-
- if ( 'import' == $from ) {
- $install_actions['importers_page'] = sprintf(
- '%s ',
- admin_url( 'import.php' ),
- __( 'Return to Importers' )
- );
- } elseif ( $this->type == 'web' ) {
- $install_actions['plugins_page'] = sprintf(
- '%s ',
- self_admin_url( 'plugin-install.php' ),
- __( 'Return to Plugin Installer' )
- );
- } elseif ( 'upload' == $this->type && 'plugins' == $from ) {
- $install_actions['plugins_page'] = sprintf(
- '%s ',
- self_admin_url( 'plugin-install.php' ),
- __( 'Return to Plugin Installer' )
- );
- } else {
- $install_actions['plugins_page'] = sprintf(
- '%s ',
- self_admin_url( 'plugins.php' ),
- __( 'Return to Plugins page' )
- );
- }
-
- if ( ! $this->result || is_wp_error( $this->result ) ) {
- unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
- } elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) ) {
- unset( $install_actions['activate_plugin'] );
- }
-
- /**
- * Filters the list of action links available following a single plugin installation.
- *
- * @since 2.7.0
- *
- * @param string[] $install_actions Array of plugin action links.
- * @param object $api Object containing WordPress.org API plugin data. Empty
- * for non-API installs, such as when a plugin is installed
- * via upload.
- * @param string $plugin_file Path to the plugin file relative to the plugins directory.
- */
- $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
-
- if ( ! empty( $install_actions ) ) {
- $this->feedback( implode( ' ', (array) $install_actions ) );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-plugin-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-plugin-upgrader-skin.php
deleted file mode 100644
index f4a119b..0000000
--- a/srcs/wordpress/wp-admin/includes/class-plugin-upgrader-skin.php
+++ /dev/null
@@ -1,89 +0,0 @@
- '',
- 'plugin' => '',
- 'nonce' => '',
- 'title' => __( 'Update Plugin' ),
- );
- $args = wp_parse_args( $args, $defaults );
-
- $this->plugin = $args['plugin'];
-
- $this->plugin_active = is_plugin_active( $this->plugin );
- $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
-
- parent::__construct( $args );
- }
-
- /**
- */
- public function after() {
- $this->plugin = $this->upgrader->plugin_info();
- if ( ! empty( $this->plugin ) && ! is_wp_error( $this->result ) && $this->plugin_active ) {
- // Currently used only when JS is off for a single plugin update?
- printf(
- '',
- esc_attr__( 'Update progress' ),
- wp_nonce_url( 'update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin )
- );
- }
-
- $this->decrement_update_count( 'plugin' );
-
- $update_actions = array(
- 'activate_plugin' => sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin ),
- __( 'Activate Plugin' )
- ),
- 'plugins_page' => sprintf(
- '%s ',
- self_admin_url( 'plugins.php' ),
- __( 'Return to Plugins page' )
- ),
- );
-
- if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugin', $this->plugin ) ) {
- unset( $update_actions['activate_plugin'] );
- }
-
- /**
- * Filters the list of action links available following a single plugin update.
- *
- * @since 2.7.0
- *
- * @param string[] $update_actions Array of plugin action links.
- * @param string $plugin Path to the plugin file relative to the plugins directory.
- */
- $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin );
-
- if ( ! empty( $update_actions ) ) {
- $this->feedback( implode( ' | ', (array) $update_actions ) );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-plugin-upgrader.php b/srcs/wordpress/wp-admin/includes/class-plugin-upgrader.php
deleted file mode 100644
index cd09f04..0000000
--- a/srcs/wordpress/wp-admin/includes/class-plugin-upgrader.php
+++ /dev/null
@@ -1,487 +0,0 @@
-strings['up_to_date'] = __( 'The plugin is at the latest version.' );
- $this->strings['no_package'] = __( 'Update package not available.' );
- /* translators: %s: Package URL. */
- $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s ' );
- $this->strings['unpack_package'] = __( 'Unpacking the update…' );
- $this->strings['remove_old'] = __( 'Removing the old version of the plugin…' );
- $this->strings['remove_old_failed'] = __( 'Could not remove the old plugin.' );
- $this->strings['process_failed'] = __( 'Plugin update failed.' );
- $this->strings['process_success'] = __( 'Plugin updated successfully.' );
- $this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' );
- }
-
- /**
- * Initialize the installation strings.
- *
- * @since 2.8.0
- */
- public function install_strings() {
- $this->strings['no_package'] = __( 'Installation package not available.' );
- /* translators: %s: Package URL. */
- $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '%s ' );
- $this->strings['unpack_package'] = __( 'Unpacking the package…' );
- $this->strings['installing_package'] = __( 'Installing the plugin…' );
- $this->strings['no_files'] = __( 'The plugin contains no files.' );
- $this->strings['process_failed'] = __( 'Plugin installation failed.' );
- $this->strings['process_success'] = __( 'Plugin installed successfully.' );
- }
-
- /**
- * Install a plugin package.
- *
- * @since 2.8.0
- * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
- *
- * @param string $package The full local path or URI of the package.
- * @param array $args {
- * Optional. Other arguments for installing a plugin package. Default empty array.
- *
- * @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
- * Default true.
- * }
- * @return bool|WP_Error True if the installation was successful, false or a WP_Error otherwise.
- */
- public function install( $package, $args = array() ) {
-
- $defaults = array(
- 'clear_update_cache' => true,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->install_strings();
-
- add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
- if ( $parsed_args['clear_update_cache'] ) {
- // Clear cache so wp_update_plugins() knows about the new plugin.
- add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
- }
-
- $this->run(
- array(
- 'package' => $package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => false, // Do not overwrite files.
- 'clear_working' => true,
- 'hook_extra' => array(
- 'type' => 'plugin',
- 'action' => 'install',
- ),
- )
- );
-
- remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
- remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
-
- if ( ! $this->result || is_wp_error( $this->result ) ) {
- return $this->result;
- }
-
- // Force refresh of plugin update information
- wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
-
- return true;
- }
-
- /**
- * Upgrade a plugin.
- *
- * @since 2.8.0
- * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
- *
- * @param string $plugin Path to the plugin file relative to the plugins directory.
- * @param array $args {
- * Optional. Other arguments for upgrading a plugin package. Default empty array.
- *
- * @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
- * Default true.
- * }
- * @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
- */
- public function upgrade( $plugin, $args = array() ) {
-
- $defaults = array(
- 'clear_update_cache' => true,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->upgrade_strings();
-
- $current = get_site_transient( 'update_plugins' );
- if ( ! isset( $current->response[ $plugin ] ) ) {
- $this->skin->before();
- $this->skin->set_result( false );
- $this->skin->error( 'up_to_date' );
- $this->skin->after();
- return false;
- }
-
- // Get the URL to the zip file
- $r = $current->response[ $plugin ];
-
- add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
- add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
- //'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
- if ( $parsed_args['clear_update_cache'] ) {
- // Clear cache so wp_update_plugins() knows about the new plugin.
- add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
- }
-
- $this->run(
- array(
- 'package' => $r->package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => true,
- 'clear_working' => true,
- 'hook_extra' => array(
- 'plugin' => $plugin,
- 'type' => 'plugin',
- 'action' => 'update',
- ),
- )
- );
-
- // Cleanup our hooks, in case something else does a upgrade on this connection.
- remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
- remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
- remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
-
- if ( ! $this->result || is_wp_error( $this->result ) ) {
- return $this->result;
- }
-
- // Force refresh of plugin update information
- wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
-
- return true;
- }
-
- /**
- * Bulk upgrade several plugins at once.
- *
- * @since 2.8.0
- * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
- *
- * @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
- * @param array $args {
- * Optional. Other arguments for upgrading several plugins at once.
- *
- * @type bool $clear_update_cache Whether to clear the plugin updates cache if successful. Default true.
- * }
- * @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
- */
- public function bulk_upgrade( $plugins, $args = array() ) {
-
- $defaults = array(
- 'clear_update_cache' => true,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->bulk = true;
- $this->upgrade_strings();
-
- $current = get_site_transient( 'update_plugins' );
-
- add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
-
- $this->skin->header();
-
- // Connect to the Filesystem first.
- $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
- if ( ! $res ) {
- $this->skin->footer();
- return false;
- }
-
- $this->skin->bulk_header();
-
- /*
- * Only start maintenance mode if:
- * - running Multisite and there are one or more plugins specified, OR
- * - a plugin with an update available is currently active.
- * @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
- */
- $maintenance = ( is_multisite() && ! empty( $plugins ) );
- foreach ( $plugins as $plugin ) {
- $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );
- }
- if ( $maintenance ) {
- $this->maintenance_mode( true );
- }
-
- $results = array();
-
- $this->update_count = count( $plugins );
- $this->update_current = 0;
- foreach ( $plugins as $plugin ) {
- $this->update_current++;
- $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );
-
- if ( ! isset( $current->response[ $plugin ] ) ) {
- $this->skin->set_result( 'up_to_date' );
- $this->skin->before();
- $this->skin->feedback( 'up_to_date' );
- $this->skin->after();
- $results[ $plugin ] = true;
- continue;
- }
-
- // Get the URL to the zip file.
- $r = $current->response[ $plugin ];
-
- $this->skin->plugin_active = is_plugin_active( $plugin );
-
- $result = $this->run(
- array(
- 'package' => $r->package,
- 'destination' => WP_PLUGIN_DIR,
- 'clear_destination' => true,
- 'clear_working' => true,
- 'is_multi' => true,
- 'hook_extra' => array(
- 'plugin' => $plugin,
- ),
- )
- );
-
- $results[ $plugin ] = $this->result;
-
- // Prevent credentials auth screen from displaying multiple times
- if ( false === $result ) {
- break;
- }
- } //end foreach $plugins
-
- $this->maintenance_mode( false );
-
- // Force refresh of plugin update information.
- wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
-
- /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
- do_action(
- 'upgrader_process_complete',
- $this,
- array(
- 'action' => 'update',
- 'type' => 'plugin',
- 'bulk' => true,
- 'plugins' => $plugins,
- )
- );
-
- $this->skin->bulk_footer();
-
- $this->skin->footer();
-
- // Cleanup our hooks, in case something else does a upgrade on this connection.
- remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
-
- return $results;
- }
-
- /**
- * Check a source package to be sure it contains a plugin.
- *
- * This function is added to the {@see 'upgrader_source_selection'} filter by
- * Plugin_Upgrader::install().
- *
- * @since 3.3.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param string $source The path to the downloaded package source.
- * @return string|WP_Error The source as passed, or a WP_Error object
- * if no plugins were found.
- */
- public function check_package( $source ) {
- global $wp_filesystem;
-
- if ( is_wp_error( $source ) ) {
- return $source;
- }
-
- $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
- if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
- return $source;
- }
-
- // Check the folder contains at least 1 valid plugin.
- $plugins_found = false;
- $files = glob( $working_directory . '*.php' );
- if ( $files ) {
- foreach ( $files as $file ) {
- $info = get_plugin_data( $file, false, false );
- if ( ! empty( $info['Name'] ) ) {
- $plugins_found = true;
- break;
- }
- }
- }
-
- if ( ! $plugins_found ) {
- return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
- }
-
- return $source;
- }
-
- /**
- * Retrieve the path to the file that contains the plugin info.
- *
- * This isn't used internally in the class, but is called by the skins.
- *
- * @since 2.8.0
- *
- * @return string|false The full path to the main plugin file, or false.
- */
- public function plugin_info() {
- if ( ! is_array( $this->result ) ) {
- return false;
- }
- if ( empty( $this->result['destination_name'] ) ) {
- return false;
- }
-
- $plugin = get_plugins( '/' . $this->result['destination_name'] ); //Ensure to pass with leading slash
- if ( empty( $plugin ) ) {
- return false;
- }
-
- $pluginfiles = array_keys( $plugin ); //Assume the requested plugin is the first in the list
-
- return $this->result['destination_name'] . '/' . $pluginfiles[0];
- }
-
- /**
- * Deactivates a plugin before it is upgraded.
- *
- * Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
- *
- * @since 2.8.0
- * @since 4.1.0 Added a return value.
- *
- * @param bool|WP_Error $return Upgrade offer return.
- * @param array $plugin Plugin package arguments.
- * @return bool|WP_Error The passed in $return param or WP_Error.
- */
- public function deactivate_plugin_before_upgrade( $return, $plugin ) {
-
- if ( is_wp_error( $return ) ) { //Bypass.
- return $return;
- }
-
- // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it
- if ( wp_doing_cron() ) {
- return $return;
- }
-
- $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
- if ( empty( $plugin ) ) {
- return new WP_Error( 'bad_request', $this->strings['bad_request'] );
- }
-
- if ( is_plugin_active( $plugin ) ) {
- //Deactivate the plugin silently, Prevent deactivation hooks from running.
- deactivate_plugins( $plugin, true );
- }
-
- return $return;
- }
-
- /**
- * Delete the old plugin during an upgrade.
- *
- * Hooked to the {@see 'upgrader_clear_destination'} filter by
- * Plugin_Upgrader::upgrade() and Plugin_Upgrader::bulk_upgrade().
- *
- * @since 2.8.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param bool|WP_Error $removed
- * @param string $local_destination
- * @param string $remote_destination
- * @param array $plugin
- * @return WP_Error|bool
- */
- public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
- global $wp_filesystem;
-
- if ( is_wp_error( $removed ) ) {
- return $removed; //Pass errors through.
- }
-
- $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
- if ( empty( $plugin ) ) {
- return new WP_Error( 'bad_request', $this->strings['bad_request'] );
- }
-
- $plugins_dir = $wp_filesystem->wp_plugins_dir();
- $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );
-
- if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { //If it's already vanished.
- return $removed;
- }
-
- // If plugin is in its own directory, recursively delete the directory.
- if ( strpos( $plugin, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder
- $deleted = $wp_filesystem->delete( $this_plugin_dir, true );
- } else {
- $deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
- }
-
- if ( ! $deleted ) {
- return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
- }
-
- return true;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-theme-installer-skin.php b/srcs/wordpress/wp-admin/includes/class-theme-installer-skin.php
deleted file mode 100644
index 9be44bc..0000000
--- a/srcs/wordpress/wp-admin/includes/class-theme-installer-skin.php
+++ /dev/null
@@ -1,150 +0,0 @@
- 'web',
- 'url' => '',
- 'theme' => '',
- 'nonce' => '',
- 'title' => '',
- );
- $args = wp_parse_args( $args, $defaults );
-
- $this->type = $args['type'];
- $this->api = isset( $args['api'] ) ? $args['api'] : array();
-
- parent::__construct( $args );
- }
-
- /**
- */
- public function before() {
- if ( ! empty( $this->api ) ) {
- $this->upgrader->strings['process_success'] = sprintf(
- $this->upgrader->strings['process_success_specific'],
- $this->api->name,
- $this->api->version
- );
- }
- }
-
- /**
- */
- public function after() {
- if ( empty( $this->upgrader->result['destination_name'] ) ) {
- return;
- }
-
- $theme_info = $this->upgrader->theme_info();
- if ( empty( $theme_info ) ) {
- return;
- }
-
- $name = $theme_info->display( 'Name' );
- $stylesheet = $this->upgrader->result['destination_name'];
- $template = $theme_info->get_template();
-
- $activate_link = add_query_arg(
- array(
- 'action' => 'activate',
- 'template' => urlencode( $template ),
- 'stylesheet' => urlencode( $stylesheet ),
- ),
- admin_url( 'themes.php' )
- );
- $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
-
- $install_actions = array();
-
- if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
- $customize_url = add_query_arg(
- array(
- 'theme' => urlencode( $stylesheet ),
- 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ),
- ),
- admin_url( 'customize.php' )
- );
-
- $install_actions['preview'] = sprintf(
- '' .
- '%s %s ',
- esc_url( $customize_url ),
- __( 'Live Preview' ),
- /* translators: %s: Theme name. */
- sprintf( __( 'Live Preview “%s”' ), $name )
- );
- }
-
- $install_actions['activate'] = sprintf(
- '' .
- '%s %s ',
- esc_url( $activate_link ),
- __( 'Activate' ),
- /* translators: %s: Theme name. */
- sprintf( __( 'Activate “%s”' ), $name )
- );
-
- if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) {
- $install_actions['network_enable'] = sprintf(
- '%s ',
- esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ),
- __( 'Network Enable' )
- );
- }
-
- if ( $this->type == 'web' ) {
- $install_actions['themes_page'] = sprintf(
- '%s ',
- self_admin_url( 'theme-install.php' ),
- __( 'Return to Theme Installer' )
- );
- } elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) {
- $install_actions['themes_page'] = sprintf(
- '%s ',
- self_admin_url( 'themes.php' ),
- __( 'Return to Themes page' )
- );
- }
-
- if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) {
- unset( $install_actions['activate'], $install_actions['preview'] );
- }
-
- /**
- * Filters the list of action links available following a single theme installation.
- *
- * @since 2.8.0
- *
- * @param string[] $install_actions Array of theme action links.
- * @param object $api Object containing WordPress.org API theme data.
- * @param string $stylesheet Theme directory name.
- * @param WP_Theme $theme_info Theme object.
- */
- $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info );
- if ( ! empty( $install_actions ) ) {
- $this->feedback( implode( ' | ', (array) $install_actions ) );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-theme-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-theme-upgrader-skin.php
deleted file mode 100644
index 31e540b..0000000
--- a/srcs/wordpress/wp-admin/includes/class-theme-upgrader-skin.php
+++ /dev/null
@@ -1,126 +0,0 @@
- '',
- 'theme' => '',
- 'nonce' => '',
- 'title' => __( 'Update Theme' ),
- );
- $args = wp_parse_args( $args, $defaults );
-
- $this->theme = $args['theme'];
-
- parent::__construct( $args );
- }
-
- /**
- */
- public function after() {
- $this->decrement_update_count( 'theme' );
-
- $update_actions = array();
- $theme_info = $this->upgrader->theme_info();
- if ( $theme_info ) {
- $name = $theme_info->display( 'Name' );
- $stylesheet = $this->upgrader->result['destination_name'];
- $template = $theme_info->get_template();
-
- $activate_link = add_query_arg(
- array(
- 'action' => 'activate',
- 'template' => urlencode( $template ),
- 'stylesheet' => urlencode( $stylesheet ),
- ),
- admin_url( 'themes.php' )
- );
- $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
-
- $customize_url = add_query_arg(
- array(
- 'theme' => urlencode( $stylesheet ),
- 'return' => urlencode( admin_url( 'themes.php' ) ),
- ),
- admin_url( 'customize.php' )
- );
-
- if ( get_stylesheet() == $stylesheet ) {
- if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
- $update_actions['preview'] = sprintf(
- '' .
- '%s %s ',
- esc_url( $customize_url ),
- __( 'Customize' ),
- /* translators: %s: Theme name. */
- sprintf( __( 'Customize “%s”' ), $name )
- );
- }
- } elseif ( current_user_can( 'switch_themes' ) ) {
- if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
- $update_actions['preview'] = sprintf(
- '' .
- '%s %s ',
- esc_url( $customize_url ),
- __( 'Live Preview' ),
- /* translators: %s: Theme name. */
- sprintf( __( 'Live Preview “%s”' ), $name )
- );
- }
-
- $update_actions['activate'] = sprintf(
- '' .
- '%s %s ',
- esc_url( $activate_link ),
- __( 'Activate' ),
- /* translators: %s: Theme name. */
- sprintf( __( 'Activate “%s”' ), $name )
- );
- }
-
- if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) {
- unset( $update_actions['preview'], $update_actions['activate'] );
- }
- }
-
- $update_actions['themes_page'] = sprintf(
- '%s ',
- self_admin_url( 'themes.php' ),
- __( 'Return to Themes page' )
- );
-
- /**
- * Filters the list of action links available following a single theme update.
- *
- * @since 2.8.0
- *
- * @param string[] $update_actions Array of theme action links.
- * @param string $theme Theme directory name.
- */
- $update_actions = apply_filters( 'update_theme_complete_actions', $update_actions, $this->theme );
-
- if ( ! empty( $update_actions ) ) {
- $this->feedback( implode( ' | ', (array) $update_actions ) );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-theme-upgrader.php b/srcs/wordpress/wp-admin/includes/class-theme-upgrader.php
deleted file mode 100644
index e9cb743..0000000
--- a/srcs/wordpress/wp-admin/includes/class-theme-upgrader.php
+++ /dev/null
@@ -1,648 +0,0 @@
-strings['up_to_date'] = __( 'The theme is at the latest version.' );
- $this->strings['no_package'] = __( 'Update package not available.' );
- /* translators: %s: Package URL. */
- $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s ' );
- $this->strings['unpack_package'] = __( 'Unpacking the update…' );
- $this->strings['remove_old'] = __( 'Removing the old version of the theme…' );
- $this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' );
- $this->strings['process_failed'] = __( 'Theme update failed.' );
- $this->strings['process_success'] = __( 'Theme updated successfully.' );
- }
-
- /**
- * Initialize the installation strings.
- *
- * @since 2.8.0
- */
- public function install_strings() {
- $this->strings['no_package'] = __( 'Installation package not available.' );
- /* translators: %s: Package URL. */
- $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '%s ' );
- $this->strings['unpack_package'] = __( 'Unpacking the package…' );
- $this->strings['installing_package'] = __( 'Installing the theme…' );
- $this->strings['no_files'] = __( 'The theme contains no files.' );
- $this->strings['process_failed'] = __( 'Theme installation failed.' );
- $this->strings['process_success'] = __( 'Theme installed successfully.' );
- /* translators: 1: Theme name, 2: Theme version. */
- $this->strings['process_success_specific'] = __( 'Successfully installed the theme %1$s %2$s .' );
- $this->strings['parent_theme_search'] = __( 'This theme requires a parent theme. Checking if it is installed…' );
- /* translators: 1: Theme name, 2: Theme version. */
- $this->strings['parent_theme_prepare_install'] = __( 'Preparing to install %1$s %2$s …' );
- /* translators: 1: Theme name, 2: Theme version. */
- $this->strings['parent_theme_currently_installed'] = __( 'The parent theme, %1$s %2$s , is currently installed.' );
- /* translators: 1: Theme name, 2: Theme version. */
- $this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, %1$s %2$s .' );
- /* translators: %s: Theme name. */
- $this->strings['parent_theme_not_found'] = sprintf( __( 'The parent theme could not be found. You will need to install the parent theme, %s, before you can use this child theme.' ), '%s ' );
- }
-
- /**
- * Check if a child theme is being installed and we need to install its parent.
- *
- * Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::install().
- *
- * @since 3.4.0
- *
- * @param bool $install_result
- * @param array $hook_extra
- * @param array $child_result
- * @return type
- */
- public function check_parent_theme_filter( $install_result, $hook_extra, $child_result ) {
- // Check to see if we need to install a parent theme
- $theme_info = $this->theme_info();
-
- if ( ! $theme_info->parent() ) {
- return $install_result;
- }
-
- $this->skin->feedback( 'parent_theme_search' );
-
- if ( ! $theme_info->parent()->errors() ) {
- $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) );
- // We already have the theme, fall through.
- return $install_result;
- }
-
- // We don't have the parent theme, let's install it.
- $api = themes_api(
- 'theme_information',
- array(
- 'slug' => $theme_info->get( 'Template' ),
- 'fields' => array(
- 'sections' => false,
- 'tags' => false,
- ),
- )
- ); //Save on a bit of bandwidth.
-
- if ( ! $api || is_wp_error( $api ) ) {
- $this->skin->feedback( 'parent_theme_not_found', $theme_info->get( 'Template' ) );
- // Don't show activate or preview actions after installation
- add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) );
- return $install_result;
- }
-
- // Backup required data we're going to override:
- $child_api = $this->skin->api;
- $child_success_message = $this->strings['process_success'];
-
- // Override them
- $this->skin->api = $api;
- $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version);
-
- $this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version );
-
- add_filter( 'install_theme_complete_actions', '__return_false', 999 ); // Don't show any actions after installing the theme.
-
- // Install the parent theme
- $parent_result = $this->run(
- array(
- 'package' => $api->download_link,
- 'destination' => get_theme_root(),
- 'clear_destination' => false, //Do not overwrite files.
- 'clear_working' => true,
- )
- );
-
- if ( is_wp_error( $parent_result ) ) {
- add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) );
- }
-
- // Start cleaning up after the parents installation
- remove_filter( 'install_theme_complete_actions', '__return_false', 999 );
-
- // Reset child's result and data
- $this->result = $child_result;
- $this->skin->api = $child_api;
- $this->strings['process_success'] = $child_success_message;
-
- return $install_result;
- }
-
- /**
- * Don't display the activate and preview actions to the user.
- *
- * Hooked to the {@see 'install_theme_complete_actions'} filter by
- * Theme_Upgrader::check_parent_theme_filter() when installing
- * a child theme and installing the parent theme fails.
- *
- * @since 3.4.0
- *
- * @param array $actions Preview actions.
- * @return array
- */
- public function hide_activate_preview_actions( $actions ) {
- unset( $actions['activate'], $actions['preview'] );
- return $actions;
- }
-
- /**
- * Install a theme package.
- *
- * @since 2.8.0
- * @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
- *
- * @param string $package The full local path or URI of the package.
- * @param array $args {
- * Optional. Other arguments for installing a theme package. Default empty array.
- *
- * @type bool $clear_update_cache Whether to clear the updates cache if successful.
- * Default true.
- * }
- *
- * @return bool|WP_Error True if the installation was successful, false or a WP_Error object otherwise.
- */
- public function install( $package, $args = array() ) {
-
- $defaults = array(
- 'clear_update_cache' => true,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->install_strings();
-
- add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
- add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 );
- if ( $parsed_args['clear_update_cache'] ) {
- // Clear cache so wp_update_themes() knows about the new theme.
- add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
- }
-
- $this->run(
- array(
- 'package' => $package,
- 'destination' => get_theme_root(),
- 'clear_destination' => false, //Do not overwrite files.
- 'clear_working' => true,
- 'hook_extra' => array(
- 'type' => 'theme',
- 'action' => 'install',
- ),
- )
- );
-
- remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
- remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
- remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) );
-
- if ( ! $this->result || is_wp_error( $this->result ) ) {
- return $this->result;
- }
-
- // Refresh the Theme Update information
- wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
-
- return true;
- }
-
- /**
- * Upgrade a theme.
- *
- * @since 2.8.0
- * @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
- *
- * @param string $theme The theme slug.
- * @param array $args {
- * Optional. Other arguments for upgrading a theme. Default empty array.
- *
- * @type bool $clear_update_cache Whether to clear the update cache if successful.
- * Default true.
- * }
- * @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
- */
- public function upgrade( $theme, $args = array() ) {
-
- $defaults = array(
- 'clear_update_cache' => true,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->upgrade_strings();
-
- // Is an update available?
- $current = get_site_transient( 'update_themes' );
- if ( ! isset( $current->response[ $theme ] ) ) {
- $this->skin->before();
- $this->skin->set_result( false );
- $this->skin->error( 'up_to_date' );
- $this->skin->after();
- return false;
- }
-
- $r = $current->response[ $theme ];
-
- add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 );
- add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 );
- add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 );
- if ( $parsed_args['clear_update_cache'] ) {
- // Clear cache so wp_update_themes() knows about the new theme.
- add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
- }
-
- $this->run(
- array(
- 'package' => $r['package'],
- 'destination' => get_theme_root( $theme ),
- 'clear_destination' => true,
- 'clear_working' => true,
- 'hook_extra' => array(
- 'theme' => $theme,
- 'type' => 'theme',
- 'action' => 'update',
- ),
- )
- );
-
- remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
- remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) );
- remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) );
- remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) );
-
- if ( ! $this->result || is_wp_error( $this->result ) ) {
- return $this->result;
- }
-
- wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
-
- return true;
- }
-
- /**
- * Upgrade several themes at once.
- *
- * @since 3.0.0
- * @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
- *
- * @param string[] $themes Array of the theme slugs.
- * @param array $args {
- * Optional. Other arguments for upgrading several themes at once. Default empty array.
- *
- * @type bool $clear_update_cache Whether to clear the update cache if successful.
- * Default true.
- * }
- * @return array[]|false An array of results, or false if unable to connect to the filesystem.
- */
- public function bulk_upgrade( $themes, $args = array() ) {
-
- $defaults = array(
- 'clear_update_cache' => true,
- );
- $parsed_args = wp_parse_args( $args, $defaults );
-
- $this->init();
- $this->bulk = true;
- $this->upgrade_strings();
-
- $current = get_site_transient( 'update_themes' );
-
- add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 );
- add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 );
- add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 );
-
- $this->skin->header();
-
- // Connect to the Filesystem first.
- $res = $this->fs_connect( array( WP_CONTENT_DIR ) );
- if ( ! $res ) {
- $this->skin->footer();
- return false;
- }
-
- $this->skin->bulk_header();
-
- // Only start maintenance mode if:
- // - running Multisite and there are one or more themes specified, OR
- // - a theme with an update available is currently in use.
- // @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
- $maintenance = ( is_multisite() && ! empty( $themes ) );
- foreach ( $themes as $theme ) {
- $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
- }
- if ( $maintenance ) {
- $this->maintenance_mode( true );
- }
-
- $results = array();
-
- $this->update_count = count( $themes );
- $this->update_current = 0;
- foreach ( $themes as $theme ) {
- $this->update_current++;
-
- $this->skin->theme_info = $this->theme_info( $theme );
-
- if ( ! isset( $current->response[ $theme ] ) ) {
- $this->skin->set_result( true );
- $this->skin->before();
- $this->skin->feedback( 'up_to_date' );
- $this->skin->after();
- $results[ $theme ] = true;
- continue;
- }
-
- // Get the URL to the zip file
- $r = $current->response[ $theme ];
-
- $result = $this->run(
- array(
- 'package' => $r['package'],
- 'destination' => get_theme_root( $theme ),
- 'clear_destination' => true,
- 'clear_working' => true,
- 'is_multi' => true,
- 'hook_extra' => array(
- 'theme' => $theme,
- ),
- )
- );
-
- $results[ $theme ] = $this->result;
-
- // Prevent credentials auth screen from displaying multiple times
- if ( false === $result ) {
- break;
- }
- } //end foreach $plugins
-
- $this->maintenance_mode( false );
-
- // Refresh the Theme Update information
- wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
-
- /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
- do_action(
- 'upgrader_process_complete',
- $this,
- array(
- 'action' => 'update',
- 'type' => 'theme',
- 'bulk' => true,
- 'themes' => $themes,
- )
- );
-
- $this->skin->bulk_footer();
-
- $this->skin->footer();
-
- // Cleanup our hooks, in case something else does a upgrade on this connection.
- remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) );
- remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) );
- remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) );
-
- return $results;
- }
-
- /**
- * Check that the package source contains a valid theme.
- *
- * Hooked to the {@see 'upgrader_source_selection'} filter by Theme_Upgrader::install().
- * It will return an error if the theme doesn't have style.css or index.php
- * files.
- *
- * @since 3.3.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param string $source The full path to the package source.
- * @return string|WP_Error The source or a WP_Error.
- */
- public function check_package( $source ) {
- global $wp_filesystem;
-
- if ( is_wp_error( $source ) ) {
- return $source;
- }
-
- // Check the folder contains a valid theme
- $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
- if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
- return $source;
- }
-
- // A proper archive should have a style.css file in the single subdirectory
- if ( ! file_exists( $working_directory . 'style.css' ) ) {
- return new WP_Error(
- 'incompatible_archive_theme_no_style',
- $this->strings['incompatible_archive'],
- sprintf(
- /* translators: %s: style.css */
- __( 'The theme is missing the %s stylesheet.' ),
- 'style.css'
- )
- );
- }
-
- $info = get_file_data(
- $working_directory . 'style.css',
- array(
- 'Name' => 'Theme Name',
- 'Template' => 'Template',
- )
- );
-
- if ( empty( $info['Name'] ) ) {
- return new WP_Error(
- 'incompatible_archive_theme_no_name',
- $this->strings['incompatible_archive'],
- sprintf(
- /* translators: %s: style.css */
- __( 'The %s stylesheet doesn’t contain a valid theme header.' ),
- 'style.css'
- )
- );
- }
-
- // If it's not a child theme, it must have at least an index.php to be legit.
- if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) {
- return new WP_Error(
- 'incompatible_archive_theme_no_index',
- $this->strings['incompatible_archive'],
- sprintf(
- /* translators: %s: index.php */
- __( 'The theme is missing the %s file.' ),
- 'index.php'
- )
- );
- }
-
- return $source;
- }
-
- /**
- * Turn on maintenance mode before attempting to upgrade the current theme.
- *
- * Hooked to the {@see 'upgrader_pre_install'} filter by Theme_Upgrader::upgrade() and
- * Theme_Upgrader::bulk_upgrade().
- *
- * @since 2.8.0
- *
- * @param bool|WP_Error $return
- * @param array $theme
- * @return bool|WP_Error
- */
- public function current_before( $return, $theme ) {
- if ( is_wp_error( $return ) ) {
- return $return;
- }
-
- $theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
-
- if ( $theme != get_stylesheet() ) { //If not current
- return $return;
- }
- //Change to maintenance mode now.
- if ( ! $this->bulk ) {
- $this->maintenance_mode( true );
- }
-
- return $return;
- }
-
- /**
- * Turn off maintenance mode after upgrading the current theme.
- *
- * Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::upgrade()
- * and Theme_Upgrader::bulk_upgrade().
- *
- * @since 2.8.0
- *
- * @param bool|WP_Error $return
- * @param array $theme
- * @return bool|WP_Error
- */
- public function current_after( $return, $theme ) {
- if ( is_wp_error( $return ) ) {
- return $return;
- }
-
- $theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
-
- if ( $theme != get_stylesheet() ) { // If not current
- return $return;
- }
-
- // Ensure stylesheet name hasn't changed after the upgrade:
- if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
- wp_clean_themes_cache();
- $stylesheet = $this->result['destination_name'];
- switch_theme( $stylesheet );
- }
-
- //Time to remove maintenance mode
- if ( ! $this->bulk ) {
- $this->maintenance_mode( false );
- }
- return $return;
- }
-
- /**
- * Delete the old theme during an upgrade.
- *
- * Hooked to the {@see 'upgrader_clear_destination'} filter by Theme_Upgrader::upgrade()
- * and Theme_Upgrader::bulk_upgrade().
- *
- * @since 2.8.0
- *
- * @global WP_Filesystem_Base $wp_filesystem Subclass
- *
- * @param bool $removed
- * @param string $local_destination
- * @param string $remote_destination
- * @param array $theme
- * @return bool
- */
- public function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
- global $wp_filesystem;
-
- if ( is_wp_error( $removed ) ) {
- return $removed; // Pass errors through.
- }
-
- if ( ! isset( $theme['theme'] ) ) {
- return $removed;
- }
-
- $theme = $theme['theme'];
- $themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
- if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
- if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Get the WP_Theme object for a theme.
- *
- * @since 2.8.0
- * @since 3.0.0 The `$theme` argument was added.
- *
- * @param string $theme The directory name of the theme. This is optional, and if not supplied,
- * the directory name from the last result will be used.
- * @return WP_Theme|false The theme's info object, or false `$theme` is not supplied
- * and the last result isn't set.
- */
- public function theme_info( $theme = null ) {
-
- if ( empty( $theme ) ) {
- if ( ! empty( $this->result['destination_name'] ) ) {
- $theme = $this->result['destination_name'];
- } else {
- return false;
- }
- }
- return wp_get_theme( $theme );
- }
-
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-walker-category-checklist.php b/srcs/wordpress/wp-admin/includes/class-walker-category-checklist.php
deleted file mode 100644
index 76c4f2b..0000000
--- a/srcs/wordpress/wp-admin/includes/class-walker-category-checklist.php
+++ /dev/null
@@ -1,128 +0,0 @@
- 'parent',
- 'id' => 'term_id',
- ); //TODO: decouple this
-
- /**
- * Starts the list before the elements are added.
- *
- * @see Walker:start_lvl()
- *
- * @since 2.5.1
- *
- * @param string $output Used to append additional content (passed by reference).
- * @param int $depth Depth of category. Used for tab indentation.
- * @param array $args An array of arguments. @see wp_terms_checklist()
- */
- public function start_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat( "\t", $depth );
- $output .= "$indent\n";
- }
-
- /**
- * Ends the list of after the elements are added.
- *
- * @see Walker::end_lvl()
- *
- * @since 2.5.1
- *
- * @param string $output Used to append additional content (passed by reference).
- * @param int $depth Depth of category. Used for tab indentation.
- * @param array $args An array of arguments. @see wp_terms_checklist()
- */
- public function end_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat( "\t", $depth );
- $output .= "$indent \n";
- }
-
- /**
- * Start the element output.
- *
- * @see Walker::start_el()
- *
- * @since 2.5.1
- *
- * @param string $output Used to append additional content (passed by reference).
- * @param object $category The current term object.
- * @param int $depth Depth of the term in reference to parents. Default 0.
- * @param array $args An array of arguments. @see wp_terms_checklist()
- * @param int $id ID of the current term.
- */
- public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
- if ( empty( $args['taxonomy'] ) ) {
- $taxonomy = 'category';
- } else {
- $taxonomy = $args['taxonomy'];
- }
-
- if ( $taxonomy == 'category' ) {
- $name = 'post_category';
- } else {
- $name = 'tax_input[' . $taxonomy . ']';
- }
-
- $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
- $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
-
- $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
-
- if ( ! empty( $args['list_only'] ) ) {
- $aria_checked = 'false';
- $inner_class = 'category';
-
- if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
- $inner_class .= ' selected';
- $aria_checked = 'true';
- }
-
- $output .= "\n" . '' .
- '' .
- /** This filter is documented in wp-includes/category-template.php */
- esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '
';
- } else {
- $output .= "\n " .
- ' term_id, $args['selected_cats'] ), true, false ) .
- disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
- /** This filter is documented in wp-includes/category-template.php */
- esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . ' ';
- }
- }
-
- /**
- * Ends the element output, if needed.
- *
- * @see Walker::end_el()
- *
- * @since 2.5.1
- *
- * @param string $output Used to append additional content (passed by reference).
- * @param object $category The current term object.
- * @param int $depth Depth of the term in reference to parents. Default 0.
- * @param array $args An array of arguments. @see wp_terms_checklist()
- */
- public function end_el( &$output, $category, $depth = 0, $args = array() ) {
- $output .= " \n";
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-walker-nav-menu-checklist.php b/srcs/wordpress/wp-admin/includes/class-walker-nav-menu-checklist.php
deleted file mode 100644
index 6cacf18..0000000
--- a/srcs/wordpress/wp-admin/includes/class-walker-nav-menu-checklist.php
+++ /dev/null
@@ -1,122 +0,0 @@
-db_fields = $fields;
- }
- }
-
- /**
- * Starts the list before the elements are added.
- *
- * @see Walker_Nav_Menu::start_lvl()
- *
- * @since 3.0.0
- *
- * @param string $output Used to append additional content (passed by reference).
- * @param int $depth Depth of page. Used for padding.
- * @param array $args Not used.
- */
- public function start_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat( "\t", $depth );
- $output .= "\n$indent\n";
- }
-
- /**
- * Ends the list of after the elements are added.
- *
- * @see Walker_Nav_Menu::end_lvl()
- *
- * @since 3.0.0
- *
- * @param string $output Used to append additional content (passed by reference).
- * @param int $depth Depth of page. Used for padding.
- * @param array $args Not used.
- */
- public function end_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat( "\t", $depth );
- $output .= "\n$indent ";
- }
-
- /**
- * Start the element output.
- *
- * @see Walker_Nav_Menu::start_el()
- *
- * @since 3.0.0
- *
- * @global int $_nav_menu_placeholder
- * @global int|string $nav_menu_selected_id
- *
- * @param string $output Used to append additional content (passed by reference).
- * @param object $item Menu item data object.
- * @param int $depth Depth of menu item. Used for padding.
- * @param array $args Not used.
- * @param int $id Not used.
- */
- public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
- global $_nav_menu_placeholder, $nav_menu_selected_id;
-
- $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
- $possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
- $possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
-
- $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
-
- $output .= $indent . '';
- $output .= '';
-
- // Menu item hidden fields
- $output .= '';
- $output .= '';
- $output .= '';
- $output .= '';
- $output .= '';
- $output .= '';
- $output .= '';
- $output .= '';
- $output .= '';
- $output .= '';
- }
-
-} // Walker_Nav_Menu_Checklist
diff --git a/srcs/wordpress/wp-admin/includes/class-walker-nav-menu-edit.php b/srcs/wordpress/wp-admin/includes/class-walker-nav-menu-edit.php
deleted file mode 100644
index fdb247f..0000000
--- a/srcs/wordpress/wp-admin/includes/class-walker-nav-menu-edit.php
+++ /dev/null
@@ -1,298 +0,0 @@
- $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
-
- ob_start();
- $item_id = esc_attr( $item->ID );
- $removed_args = array(
- 'action',
- 'customlink-tab',
- 'edit-menu-item',
- 'menu-item',
- 'page-tab',
- '_wpnonce',
- );
-
- $original_title = false;
-
- if ( 'taxonomy' == $item->type ) {
- $original_object = get_term( (int) $item->object_id, $item->object );
- if ( $original_object && ! is_wp_error( $original_title ) ) {
- $original_title = $original_object->name;
- }
- } elseif ( 'post_type' == $item->type ) {
- $original_object = get_post( $item->object_id );
- if ( $original_object ) {
- $original_title = get_the_title( $original_object->ID );
- }
- } elseif ( 'post_type_archive' == $item->type ) {
- $original_object = get_post_type_object( $item->object );
- if ( $original_object ) {
- $original_title = $original_object->labels->archives;
- }
- }
-
- $classes = array(
- 'menu-item menu-item-depth-' . $depth,
- 'menu-item-' . esc_attr( $item->object ),
- 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
- );
-
- $title = $item->title;
-
- if ( ! empty( $item->_invalid ) ) {
- $classes[] = 'menu-item-invalid';
- /* translators: %s: Title of an invalid menu item. */
- $title = sprintf( __( '%s (Invalid)' ), $item->title );
- } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
- $classes[] = 'pending';
- /* translators: %s: Title of a menu item in draft status. */
- $title = sprintf( __( '%s (Pending)' ), $item->title );
- }
-
- $title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
-
- $submenu_text = '';
- if ( 0 == $depth ) {
- $submenu_text = 'style="display: none;"';
- }
-
- ?>
- \n";
- echo '';
- }
-
- /**
- * Get an associative array ( option_name => option_title ) with the list
- * of bulk actions available on this table.
- *
- * @since 3.1.0
- *
- * @return array
- */
- protected function get_bulk_actions() {
- return array();
- }
-
- /**
- * Display the bulk actions dropdown.
- *
- * @since 3.1.0
- *
- * @param string $which The location of the bulk actions: 'top' or 'bottom'.
- * This is designated as optional for backward compatibility.
- */
- protected function bulk_actions( $which = '' ) {
- if ( is_null( $this->_actions ) ) {
- $this->_actions = $this->get_bulk_actions();
- /**
- * Filters the list table Bulk Actions drop-down.
- *
- * The dynamic portion of the hook name, `$this->screen->id`, refers
- * to the ID of the current screen, usually a string.
- *
- * This filter can currently only be used to remove bulk actions.
- *
- * @since 3.5.0
- *
- * @param string[] $actions An array of the available bulk actions.
- */
- $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
- $two = '';
- } else {
- $two = '2';
- }
-
- if ( empty( $this->_actions ) ) {
- return;
- }
-
- echo '' . __( 'Select bulk action' ) . ' ';
- echo '\n";
- echo '' . __( 'Bulk Actions' ) . " \n";
-
- foreach ( $this->_actions as $name => $title ) {
- $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
-
- echo "\t" . '' . $title . " \n";
- }
-
- echo " \n";
-
- submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
- echo "\n";
- }
-
- /**
- * Get the current action selected from the bulk actions dropdown.
- *
- * @since 3.1.0
- *
- * @return string|false The action name or False if no action was selected
- */
- public function current_action() {
- if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
- return false;
- }
-
- if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
- return $_REQUEST['action'];
- }
-
- if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) {
- return $_REQUEST['action2'];
- }
-
- return false;
- }
-
- /**
- * Generate row actions div
- *
- * @since 3.1.0
- *
- * @param string[] $actions An array of action links.
- * @param bool $always_visible Whether the actions should be always visible.
- * @return string
- */
- protected function row_actions( $actions, $always_visible = false ) {
- $action_count = count( $actions );
- $i = 0;
-
- if ( ! $action_count ) {
- return '';
- }
-
- $out = '';
- foreach ( $actions as $action => $link ) {
- ++$i;
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
- $out .= "$link$sep ";
- }
- $out .= '
';
-
- $out .= '' . __( 'Show more details' ) . ' ';
-
- return $out;
- }
-
- /**
- * Display a monthly dropdown for filtering items
- *
- * @since 3.1.0
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- * @global WP_Locale $wp_locale WordPress date and time locale object.
- *
- * @param string $post_type
- */
- protected function months_dropdown( $post_type ) {
- global $wpdb, $wp_locale;
-
- /**
- * Filters whether to remove the 'Months' drop-down from the post list table.
- *
- * @since 4.2.0
- *
- * @param bool $disable Whether to disable the drop-down. Default false.
- * @param string $post_type The post type.
- */
- if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
- return;
- }
-
- $extra_checks = "AND post_status != 'auto-draft'";
- if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
- $extra_checks .= " AND post_status != 'trash'";
- } elseif ( isset( $_GET['post_status'] ) ) {
- $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
- }
-
- $months = $wpdb->get_results(
- $wpdb->prepare(
- "
- SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
- FROM $wpdb->posts
- WHERE post_type = %s
- $extra_checks
- ORDER BY post_date DESC
- ",
- $post_type
- )
- );
-
- /**
- * Filters the 'Months' drop-down results.
- *
- * @since 3.7.0
- *
- * @param object $months The months drop-down query results.
- * @param string $post_type The post type.
- */
- $months = apply_filters( 'months_dropdown_results', $months, $post_type );
-
- $month_count = count( $months );
-
- if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
- return;
- }
-
- $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
- ?>
-
-
- value="0">
- year ) {
- continue;
- }
-
- $month = zeroise( $arc_row->month, 2 );
- $year = $arc_row->year;
-
- printf(
- "%s \n",
- selected( $m, $year . $month, false ),
- esc_attr( $arc_row->year . $month ),
- /* translators: 1: Month name, 2: 4-digit year. */
- sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
- );
- }
- ?>
-
-
-
-
- modes as $mode => $title ) {
- $classes = array( 'view-' . $mode );
- $aria_current = '';
-
- if ( $current_mode === $mode ) {
- $classes[] = 'current';
- $aria_current = ' aria-current="page"';
- }
- printf(
- "
%s \n",
- esc_url( add_query_arg( 'mode', $mode ) ),
- implode( ' ', $classes ),
- $title
- );
- }
- ?>
-
- —%s ',
- __( 'No comments' )
- );
- // Approved comments have different display depending on some conditions.
- } elseif ( $approved_comments ) {
- printf(
- '%s ',
- esc_url(
- add_query_arg(
- array(
- 'p' => $post_id,
- 'comment_status' => 'approved',
- ),
- admin_url( 'edit-comments.php' )
- )
- ),
- $approved_comments_number,
- $pending_comments ? $approved_phrase : $approved_only_phrase
- );
- } else {
- printf(
- '',
- $approved_comments_number,
- $pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
- );
- }
-
- if ( $pending_comments ) {
- printf(
- '%s ',
- esc_url(
- add_query_arg(
- array(
- 'p' => $post_id,
- 'comment_status' => 'moderated',
- ),
- admin_url( 'edit-comments.php' )
- )
- ),
- $pending_comments_number,
- $pending_phrase
- );
- } else {
- printf(
- '%s ',
- $pending_comments_number,
- $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
- );
- }
- }
-
- /**
- * Get the current page number
- *
- * @since 3.1.0
- *
- * @return int
- */
- public function get_pagenum() {
- $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
-
- if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
- $pagenum = $this->_pagination_args['total_pages'];
- }
-
- return max( 1, $pagenum );
- }
-
- /**
- * Get number of items to display on a single page
- *
- * @since 3.1.0
- *
- * @param string $option
- * @param int $default
- * @return int
- */
- protected function get_items_per_page( $option, $default = 20 ) {
- $per_page = (int) get_user_option( $option );
- if ( empty( $per_page ) || $per_page < 1 ) {
- $per_page = $default;
- }
-
- /**
- * Filters the number of items to be displayed on each page of the list table.
- *
- * The dynamic hook name, $option, refers to the `per_page` option depending
- * on the type of list table in use. Possible values include: 'edit_comments_per_page',
- * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
- * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
- * 'edit_{$post_type}_per_page', etc.
- *
- * @since 2.9.0
- *
- * @param int $per_page Number of items to be displayed. Default 20.
- */
- return (int) apply_filters( "{$option}", $per_page );
- }
-
- /**
- * Display the pagination.
- *
- * @since 3.1.0
- *
- * @param string $which
- */
- protected function pagination( $which ) {
- if ( empty( $this->_pagination_args ) ) {
- return;
- }
-
- $total_items = $this->_pagination_args['total_items'];
- $total_pages = $this->_pagination_args['total_pages'];
- $infinite_scroll = false;
- if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
- $infinite_scroll = $this->_pagination_args['infinite_scroll'];
- }
-
- if ( 'top' === $which && $total_pages > 1 ) {
- $this->screen->render_screen_reader_content( 'heading_pagination' );
- }
-
- $output = '' . sprintf(
- /* translators: %s: Number of items. */
- _n( '%s item', '%s items', $total_items ),
- number_format_i18n( $total_items )
- ) . ' ';
-
- $current = $this->get_pagenum();
- $removable_query_args = wp_removable_query_args();
-
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
-
- $current_url = remove_query_arg( $removable_query_args, $current_url );
-
- $page_links = array();
-
- $total_pages_before = '';
- $total_pages_after = ' ';
-
- $disable_first = false;
- $disable_last = false;
- $disable_prev = false;
- $disable_next = false;
-
- if ( $current == 1 ) {
- $disable_first = true;
- $disable_prev = true;
- }
- if ( $current == 2 ) {
- $disable_first = true;
- }
- if ( $current == $total_pages ) {
- $disable_last = true;
- $disable_next = true;
- }
- if ( $current == $total_pages - 1 ) {
- $disable_last = true;
- }
-
- if ( $disable_first ) {
- $page_links[] = '« ';
- } else {
- $page_links[] = sprintf(
- "%s %s ",
- esc_url( remove_query_arg( 'paged', $current_url ) ),
- __( 'First page' ),
- '«'
- );
- }
-
- if ( $disable_prev ) {
- $page_links[] = '‹ ';
- } else {
- $page_links[] = sprintf(
- "%s %s ",
- esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
- __( 'Previous page' ),
- '‹'
- );
- }
-
- if ( 'bottom' === $which ) {
- $html_current_page = $current;
- $total_pages_before = '' . __( 'Current Page' ) . ' ';
- } else {
- $html_current_page = sprintf(
- "%s",
- '' . __( 'Current Page' ) . ' ',
- $current,
- strlen( $total_pages )
- );
- }
- $html_total_pages = sprintf( "%s ", number_format_i18n( $total_pages ) );
- $page_links[] = $total_pages_before . sprintf(
- /* translators: 1: Current page, 2: Total pages. */
- _x( '%1$s of %2$s', 'paging' ),
- $html_current_page,
- $html_total_pages
- ) . $total_pages_after;
-
- if ( $disable_next ) {
- $page_links[] = '› ';
- } else {
- $page_links[] = sprintf(
- "%s %s ",
- esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
- __( 'Next page' ),
- '›'
- );
- }
-
- if ( $disable_last ) {
- $page_links[] = '» ';
- } else {
- $page_links[] = sprintf(
- "%s %s ",
- esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
- __( 'Last page' ),
- '»'
- );
- }
-
- $pagination_links_class = 'pagination-links';
- if ( ! empty( $infinite_scroll ) ) {
- $pagination_links_class .= ' hide-if-js';
- }
- $output .= "\n';
-
- if ( $total_pages ) {
- $page_class = $total_pages < 2 ? ' one-page' : '';
- } else {
- $page_class = ' no-pages';
- }
- $this->_pagination = "$output
";
-
- echo $this->_pagination;
- }
-
- /**
- * Get a list of columns. The format is:
- * 'internal-name' => 'Title'
- *
- * @since 3.1.0
- * @abstract
- *
- * @return array
- */
- public function get_columns() {
- die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
- }
-
- /**
- * Get a list of sortable columns. The format is:
- * 'internal-name' => 'orderby'
- * or
- * 'internal-name' => array( 'orderby', true )
- *
- * The second format will make the initial sorting order be descending
- *
- * @since 3.1.0
- *
- * @return array
- */
- protected function get_sortable_columns() {
- return array();
- }
-
- /**
- * Gets the name of the default primary column.
- *
- * @since 4.3.0
- *
- * @return string Name of the default primary column, in this case, an empty string.
- */
- protected function get_default_primary_column_name() {
- $columns = $this->get_columns();
- $column = '';
-
- if ( empty( $columns ) ) {
- return $column;
- }
-
- // We need a primary defined so responsive views show something,
- // so let's fall back to the first non-checkbox column.
- foreach ( $columns as $col => $column_name ) {
- if ( 'cb' === $col ) {
- continue;
- }
-
- $column = $col;
- break;
- }
-
- return $column;
- }
-
- /**
- * Public wrapper for WP_List_Table::get_default_primary_column_name().
- *
- * @since 4.4.0
- *
- * @return string Name of the default primary column.
- */
- public function get_primary_column() {
- return $this->get_primary_column_name();
- }
-
- /**
- * Gets the name of the primary column.
- *
- * @since 4.3.0
- *
- * @return string The name of the primary column.
- */
- protected function get_primary_column_name() {
- $columns = get_column_headers( $this->screen );
- $default = $this->get_default_primary_column_name();
-
- // If the primary column doesn't exist fall back to the
- // first non-checkbox column.
- if ( ! isset( $columns[ $default ] ) ) {
- $default = WP_List_Table::get_default_primary_column_name();
- }
-
- /**
- * Filters the name of the primary column for the current list table.
- *
- * @since 4.3.0
- *
- * @param string $default Column name default for the specific list table, e.g. 'name'.
- * @param string $context Screen ID for specific list table, e.g. 'plugins'.
- */
- $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
-
- if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
- $column = $default;
- }
-
- return $column;
- }
-
- /**
- * Get a list of all, hidden and sortable columns, with filter applied
- *
- * @since 3.1.0
- *
- * @return array
- */
- protected function get_column_info() {
- // $_column_headers is already set / cached
- if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
- // Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
- // In 4.3, we added a fourth argument for primary column.
- $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
- foreach ( $this->_column_headers as $key => $value ) {
- $column_headers[ $key ] = $value;
- }
-
- return $column_headers;
- }
-
- $columns = get_column_headers( $this->screen );
- $hidden = get_hidden_columns( $this->screen );
-
- $sortable_columns = $this->get_sortable_columns();
- /**
- * Filters the list table sortable columns for a specific screen.
- *
- * The dynamic portion of the hook name, `$this->screen->id`, refers
- * to the ID of the current screen, usually a string.
- *
- * @since 3.5.0
- *
- * @param array $sortable_columns An array of sortable columns.
- */
- $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
-
- $sortable = array();
- foreach ( $_sortable as $id => $data ) {
- if ( empty( $data ) ) {
- continue;
- }
-
- $data = (array) $data;
- if ( ! isset( $data[1] ) ) {
- $data[1] = false;
- }
-
- $sortable[ $id ] = $data;
- }
-
- $primary = $this->get_primary_column_name();
- $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
-
- return $this->_column_headers;
- }
-
- /**
- * Return number of visible columns
- *
- * @since 3.1.0
- *
- * @return int
- */
- public function get_column_count() {
- list ( $columns, $hidden ) = $this->get_column_info();
- $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
- return count( $columns ) - count( $hidden );
- }
-
- /**
- * Print column headers, accounting for hidden and sortable columns.
- *
- * @since 3.1.0
- *
- * @staticvar int $cb_counter
- *
- * @param bool $with_id Whether to set the id attribute or not
- */
- public function print_column_headers( $with_id = true ) {
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
-
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
- $current_url = remove_query_arg( 'paged', $current_url );
-
- if ( isset( $_GET['orderby'] ) ) {
- $current_orderby = $_GET['orderby'];
- } else {
- $current_orderby = '';
- }
-
- if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
- $current_order = 'desc';
- } else {
- $current_order = 'asc';
- }
-
- if ( ! empty( $columns['cb'] ) ) {
- static $cb_counter = 1;
- $columns['cb'] = '' . __( 'Select All' ) . ' '
- . ' ';
- $cb_counter++;
- }
-
- foreach ( $columns as $column_key => $column_display_name ) {
- $class = array( 'manage-column', "column-$column_key" );
-
- if ( in_array( $column_key, $hidden ) ) {
- $class[] = 'hidden';
- }
-
- if ( 'cb' === $column_key ) {
- $class[] = 'check-column';
- } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
- $class[] = 'num';
- }
-
- if ( $column_key === $primary ) {
- $class[] = 'column-primary';
- }
-
- if ( isset( $sortable[ $column_key ] ) ) {
- list( $orderby, $desc_first ) = $sortable[ $column_key ];
-
- if ( $current_orderby === $orderby ) {
- $order = 'asc' === $current_order ? 'desc' : 'asc';
- $class[] = 'sorted';
- $class[] = $current_order;
- } else {
- $order = $desc_first ? 'desc' : 'asc';
- $class[] = 'sortable';
- $class[] = $desc_first ? 'asc' : 'desc';
- }
-
- $column_display_name = '' . $column_display_name . ' ';
- }
-
- $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
- $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
- $id = $with_id ? "id='$column_key'" : '';
-
- if ( ! empty( $class ) ) {
- $class = "class='" . join( ' ', $class ) . "'";
- }
-
- echo "<$tag $scope $id $class>$column_display_name$tag>";
- }
- }
-
- /**
- * Displays the table.
- *
- * @since 3.1.0
- */
- public function display() {
- $singular = $this->_args['singular'];
-
- $this->display_tablenav( 'top' );
-
- $this->screen->render_screen_reader_content( 'heading_list' );
- ?>
-
-
-
- print_column_headers(); ?>
-
-
-
-
- >
- display_rows_or_placeholder(); ?>
-
-
-
-
- print_column_headers( false ); ?>
-
-
-
-
- display_tablenav( 'bottom' );
- }
-
- /**
- * Get a list of CSS classes for the WP_List_Table table tag.
- *
- * @since 3.1.0
- *
- * @return array List of CSS classes for the table tag.
- */
- protected function get_table_classes() {
- return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
- }
-
- /**
- * Generate the table navigation above or below the table
- *
- * @since 3.1.0
- * @param string $which
- */
- protected function display_tablenav( $which ) {
- if ( 'top' === $which ) {
- wp_nonce_field( 'bulk-' . $this->_args['plural'] );
- }
- ?>
-
-
- has_items() ) : ?>
-
- bulk_actions( $which ); ?>
-
- extra_tablenav( $which );
- $this->pagination( $which );
- ?>
-
-
-
- has_items() ) {
- $this->display_rows();
- } else {
- echo '';
- $this->no_items();
- echo ' ';
- }
- }
-
- /**
- * Generate the table rows
- *
- * @since 3.1.0
- */
- public function display_rows() {
- foreach ( $this->items as $item ) {
- $this->single_row( $item );
- }
- }
-
- /**
- * Generates content for a single row of the table
- *
- * @since 3.1.0
- *
- * @param object $item The current item
- */
- public function single_row( $item ) {
- echo '';
- $this->single_row_columns( $item );
- echo ' ';
- }
-
- /**
- * @param object $item
- * @param string $column_name
- */
- protected function column_default( $item, $column_name ) {}
-
- /**
- * @param object $item
- */
- protected function column_cb( $item ) {}
-
- /**
- * Generates the columns for a single row of the table
- *
- * @since 3.1.0
- *
- * @param object $item The current item
- */
- protected function single_row_columns( $item ) {
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
-
- foreach ( $columns as $column_name => $column_display_name ) {
- $classes = "$column_name column-$column_name";
- if ( $primary === $column_name ) {
- $classes .= ' has-row-actions column-primary';
- }
-
- if ( in_array( $column_name, $hidden ) ) {
- $classes .= ' hidden';
- }
-
- // Comments column uses HTML in the display name with screen reader text.
- // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
- $data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
-
- $attributes = "class='$classes' $data";
-
- if ( 'cb' === $column_name ) {
- echo ' ';
- echo $this->column_cb( $item );
- echo ' ';
- } elseif ( method_exists( $this, '_column_' . $column_name ) ) {
- echo call_user_func(
- array( $this, '_column_' . $column_name ),
- $item,
- $classes,
- $data,
- $primary
- );
- } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
- echo "";
- echo call_user_func( array( $this, 'column_' . $column_name ), $item );
- echo $this->handle_row_actions( $item, $column_name, $primary );
- echo ' ';
- } else {
- echo "";
- echo $this->column_default( $item, $column_name );
- echo $this->handle_row_actions( $item, $column_name, $primary );
- echo ' ';
- }
- }
- }
-
- /**
- * Generates and display row actions links for the list table.
- *
- * @since 4.3.0
- *
- * @param object $item The item being acted upon.
- * @param string $column_name Current column name.
- * @param string $primary Primary column name.
- * @return string The row actions HTML, or an empty string if the current column is the primary column.
- */
- protected function handle_row_actions( $item, $column_name, $primary ) {
- return $column_name === $primary ? '' . __( 'Show more details' ) . ' ' : '';
- }
-
- /**
- * Handle an incoming ajax request (called from admin-ajax.php)
- *
- * @since 3.1.0
- */
- public function ajax_response() {
- $this->prepare_items();
-
- ob_start();
- if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
- $this->display_rows();
- } else {
- $this->display_rows_or_placeholder();
- }
-
- $rows = ob_get_clean();
-
- $response = array( 'rows' => $rows );
-
- if ( isset( $this->_pagination_args['total_items'] ) ) {
- $response['total_items_i18n'] = sprintf(
- /* translators: Number of items. */
- _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
- number_format_i18n( $this->_pagination_args['total_items'] )
- );
- }
- if ( isset( $this->_pagination_args['total_pages'] ) ) {
- $response['total_pages'] = $this->_pagination_args['total_pages'];
- $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
- }
-
- die( wp_json_encode( $response ) );
- }
-
- /**
- * Send required variables to JavaScript land
- */
- public function _js_vars() {
- $args = array(
- 'class' => get_class( $this ),
- 'screen' => array(
- 'id' => $this->screen->id,
- 'base' => $this->screen->base,
- ),
- );
-
- printf( "\n", wp_json_encode( $args ) );
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-media-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-media-list-table.php
deleted file mode 100644
index b76c920..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-media-list-table.php
+++ /dev/null
@@ -1,794 +0,0 @@
-detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] );
-
- $this->modes = array(
- 'list' => __( 'List View' ),
- 'grid' => __( 'Grid View' ),
- );
-
- parent::__construct(
- array(
- 'plural' => 'media',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
- }
-
- /**
- * @return bool
- */
- public function ajax_user_can() {
- return current_user_can( 'upload_files' );
- }
-
- /**
- * @global WP_Query $wp_query WordPress Query object.
- * @global array $post_mime_types
- * @global array $avail_post_mime_types
- * @global string $mode
- */
- public function prepare_items() {
- global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
-
- list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
-
- $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
-
- $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
-
- $this->set_pagination_args(
- array(
- 'total_items' => $wp_query->found_posts,
- 'total_pages' => $wp_query->max_num_pages,
- 'per_page' => $wp_query->query_vars['posts_per_page'],
- )
- );
- }
-
- /**
- * @global array $post_mime_types
- * @global array $avail_post_mime_types
- * @return array
- */
- protected function get_views() {
- global $post_mime_types, $avail_post_mime_types;
-
- $type_links = array();
-
- $filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter'];
-
- $type_links['all'] = sprintf(
- '%s ',
- selected( $filter, true, false ),
- __( 'All media items' )
- );
-
- foreach ( $post_mime_types as $mime_type => $label ) {
- if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
- continue;
- }
-
- $selected = selected(
- $filter && 0 === strpos( $filter, 'post_mime_type:' ) &&
- wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ),
- true,
- false
- );
-
- $type_links[ $mime_type ] = sprintf(
- '%s ',
- esc_attr( $mime_type ),
- $selected,
- $label[0]
- );
- }
-
- $type_links['detached'] = 'detached ? ' selected="selected"' : '' ) . '>' . __( 'Unattached' ) . ' ';
-
- $type_links['mine'] = sprintf(
- '%s ',
- selected( 'mine' === $filter, true, false ),
- _x( 'Mine', 'media items' )
- );
-
- if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
- $type_links['trash'] = sprintf(
- '%s ',
- selected( 'trash' === $filter, true, false ),
- _x( 'Trash', 'attachment filter' )
- );
- }
-
- return $type_links;
- }
-
- /**
- * @return array
- */
- protected function get_bulk_actions() {
- $actions = array();
- if ( MEDIA_TRASH ) {
- if ( $this->is_trash ) {
- $actions['untrash'] = __( 'Restore' );
- $actions['delete'] = __( 'Delete Permanently' );
- } else {
- $actions['trash'] = __( 'Move to Trash' );
- }
- } else {
- $actions['delete'] = __( 'Delete Permanently' );
- }
-
- if ( $this->detached ) {
- $actions['attach'] = __( 'Attach' );
- }
-
- return $actions;
- }
-
- /**
- * @param string $which
- */
- protected function extra_tablenav( $which ) {
- if ( 'bar' !== $which ) {
- return;
- }
- ?>
-
- is_trash ) {
- $this->months_dropdown( 'attachment' );
- }
-
- /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
- do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
-
- submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
- }
-
- if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
- submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
- }
- ?>
-
- get_views();
-
- $this->screen->render_screen_reader_content( 'heading_views' );
- ?>
-
-
- view_switcher( $mode ); ?>
-
-
-
- $view ) {
- echo "\t$view\n";
- }
- }
- ?>
-
-
- extra_tablenav( 'bar' );
-
- /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
- $views = apply_filters( "views_{$this->screen->id}", array() );
-
- // Back compat for pre-4.0 view links.
- if ( ! empty( $views ) ) {
- echo '
';
- foreach ( $views as $class => $view ) {
- echo "$view ";
- }
- echo ' ';
- }
- ?>
-
-
-
-
-
-
- ';
- /* translators: Column name. */
- $posts_columns['title'] = _x( 'File', 'column name' );
- $posts_columns['author'] = __( 'Author' );
-
- $taxonomies = get_taxonomies_for_attachments( 'objects' );
- $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
-
- /**
- * Filters the taxonomy columns for attachments in the Media list table.
- *
- * @since 3.5.0
- *
- * @param string[] $taxonomies An array of registered taxonomy names to show for attachments.
- * @param string $post_type The post type. Default 'attachment'.
- */
- $taxonomies = apply_filters( 'manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment' );
- $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
-
- foreach ( $taxonomies as $taxonomy ) {
- if ( 'category' === $taxonomy ) {
- $column_key = 'categories';
- } elseif ( 'post_tag' === $taxonomy ) {
- $column_key = 'tags';
- } else {
- $column_key = 'taxonomy-' . $taxonomy;
- }
- $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
- }
-
- /* translators: Column name. */
- if ( ! $this->detached ) {
- $posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
- if ( post_type_supports( 'attachment', 'comments' ) ) {
- $posts_columns['comments'] = '';
- }
- }
- /* translators: Column name. */
- $posts_columns['date'] = _x( 'Date', 'column name' );
- /**
- * Filters the Media list table columns.
- *
- * @since 2.5.0
- *
- * @param string[] $posts_columns An array of columns displayed in the Media list table.
- * @param bool $detached Whether the list table contains media not attached
- * to any posts. Default true.
- */
- return apply_filters( 'manage_media_columns', $posts_columns, $this->detached );
- }
-
- /**
- * @return array
- */
- protected function get_sortable_columns() {
- return array(
- 'title' => 'title',
- 'author' => 'author',
- 'parent' => 'parent',
- 'comments' => 'comment_count',
- 'date' => array( 'date', true ),
- );
- }
-
- /**
- * Handles the checkbox column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_cb( $post ) {
- if ( current_user_can( 'edit_post', $post->ID ) ) {
- ?>
-
-
-
-
- post_mime_type );
-
- $title = _draft_or_post_title();
- $thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
- $link_start = '';
- $link_end = '';
-
- if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
- $link_start = sprintf(
- '',
- get_edit_post_link( $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) )
- );
- $link_end = ' ';
- }
-
- $class = $thumb ? ' class="has-media-icon"' : '';
- ?>
- >
-
-
-
-
-
-
- ID );
- echo esc_html( wp_basename( $file ) );
- ?>
-
- %s',
- esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
- get_the_author()
- );
- }
-
- /**
- * Handles the description column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_desc( $post ) {
- echo has_excerpt() ? $post->post_excerpt : '';
- }
-
- /**
- * Handles the date column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_date( $post ) {
- if ( '0000-00-00 00:00:00' === $post->post_date ) {
- $h_time = __( 'Unpublished' );
- } else {
- $time = get_post_timestamp( $post );
- $time_diff = time() - $time;
-
- if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
- /* translators: %s: Human-readable time difference. */
- $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
- } else {
- $h_time = get_the_time( __( 'Y/m/d' ), $post );
- }
- }
-
- echo $h_time;
- }
-
- /**
- * Handles the parent column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_parent( $post ) {
- $user_can_edit = current_user_can( 'edit_post', $post->ID );
-
- if ( $post->post_parent > 0 ) {
- $parent = get_post( $post->post_parent );
- } else {
- $parent = false;
- }
-
- if ( $parent ) {
- $title = _draft_or_post_title( $post->post_parent );
- $parent_type = get_post_type_object( $parent->post_type );
-
- if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) {
- ?>
-
-
- post_parent ) ) {
- ?>
-
- $post->post_parent,
- 'media[]' => $post->ID,
- '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ),
- ),
- 'upload.php'
- );
- printf(
- '%s ',
- $detach_url,
- /* translators: %s: Title of the post the attachment is attached to. */
- esc_attr( sprintf( __( 'Detach from “%s”' ), $title ) ),
- __( 'Detach' )
- );
- endif;
- } else {
- _e( '(Unattached)' );
- ?>
- post_parent );
- printf(
- '%s ',
- $post->ID,
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $title ) ),
- __( 'Attach' )
- );
- }
- }
- }
-
- /**
- * Handles the comments column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_comments( $post ) {
- echo '';
-
- if ( isset( $this->comment_pending_count[ $post->ID ] ) ) {
- $pending_comments = $this->comment_pending_count[ $post->ID ];
- } else {
- $pending_comments = get_pending_comments_num( $post->ID );
- }
-
- $this->comments_bubble( $post->ID, $pending_comments );
-
- echo '
';
- }
-
- /**
- * Handles output for the default column.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- * @param string $column_name Current column name.
- */
- public function column_default( $post, $column_name ) {
- if ( 'categories' === $column_name ) {
- $taxonomy = 'category';
- } elseif ( 'tags' === $column_name ) {
- $taxonomy = 'post_tag';
- } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
- $taxonomy = substr( $column_name, 9 );
- } else {
- $taxonomy = false;
- }
-
- if ( $taxonomy ) {
- $terms = get_the_terms( $post->ID, $taxonomy );
- if ( is_array( $terms ) ) {
- $out = array();
- foreach ( $terms as $t ) {
- $posts_in_term_qv = array();
- $posts_in_term_qv['taxonomy'] = $taxonomy;
- $posts_in_term_qv['term'] = $t->slug;
-
- $out[] = sprintf(
- '%s ',
- esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
- esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
- );
- }
- /* translators: Used between list items, there is a space after the comma. */
- echo join( __( ', ' ), $out );
- } else {
- echo '— ' . get_taxonomy( $taxonomy )->labels->no_terms . ' ';
- }
-
- return;
- }
-
- /**
- * Fires for each custom column in the Media list table.
- *
- * Custom columns are registered using the {@see 'manage_media_columns'} filter.
- *
- * @since 2.5.0
- *
- * @param string $column_name Name of the custom column.
- * @param int $post_id Attachment ID.
- */
- do_action( 'manage_media_custom_column', $column_name, $post->ID );
- }
-
- /**
- * @global WP_Post $post Global post object.
- */
- public function display_rows() {
- global $post, $wp_query;
-
- $post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
- reset( $wp_query->posts );
-
- $this->comment_pending_count = get_pending_comments_num( $post_ids );
-
- add_filter( 'the_title', 'esc_html' );
-
- while ( have_posts() ) :
- the_post();
- if (
- ( $this->is_trash && $post->post_status != 'trash' )
- || ( ! $this->is_trash && $post->post_status === 'trash' )
- ) {
- continue;
- }
- $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other';
- ?>
-
- single_row_columns( $post ); ?>
-
- detached ) {
- if ( current_user_can( 'edit_post', $post->ID ) ) {
- $actions['edit'] = sprintf(
- '%s ',
- get_edit_post_link( $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ),
- __( 'Edit' )
- );
- }
- if ( current_user_can( 'delete_post', $post->ID ) ) {
- if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
- $actions['trash'] = sprintf(
- '%s ',
- wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ),
- _x( 'Trash', 'verb' )
- );
- } else {
- $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
- $actions['delete'] = sprintf(
- '%s ',
- wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ),
- $delete_ays,
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ),
- __( 'Delete Permanently' )
- );
- }
- }
- $actions['view'] = sprintf(
- '%s ',
- get_permalink( $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ),
- __( 'View' )
- );
-
- if ( current_user_can( 'edit_post', $post->ID ) ) {
- $actions['attach'] = sprintf(
- '%s ',
- $post->ID,
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $att_title ) ),
- __( 'Attach' )
- );
- }
- } else {
- if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
- $actions['edit'] = sprintf(
- '%s ',
- get_edit_post_link( $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ),
- __( 'Edit' )
- );
- }
- if ( current_user_can( 'delete_post', $post->ID ) ) {
- if ( $this->is_trash ) {
- $actions['untrash'] = sprintf(
- '%s ',
- wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $att_title ) ),
- __( 'Restore' )
- );
- } elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
- $actions['trash'] = sprintf(
- '%s ',
- wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $att_title ) ),
- _x( 'Trash', 'verb' )
- );
- }
- if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
- $delete_ays = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
- $actions['delete'] = sprintf(
- '%s ',
- wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ),
- $delete_ays,
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'Delete “%s” permanently' ), $att_title ) ),
- __( 'Delete Permanently' )
- );
- }
- }
- if ( ! $this->is_trash ) {
- $actions['view'] = sprintf(
- '%s ',
- get_permalink( $post->ID ),
- /* translators: %s: Attachment title. */
- esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ),
- __( 'View' )
- );
- }
- }
-
- /**
- * Filters the action links for each attachment in the Media list table.
- *
- * @since 2.8.0
- *
- * @param string[] $actions An array of action links for each attachment.
- * Default 'Edit', 'Delete Permanently', 'View'.
- * @param WP_Post $post WP_Post object for the current attachment.
- * @param bool $detached Whether the list table contains media not attached
- * to any posts. Default true.
- */
- return apply_filters( 'media_row_actions', $actions, $post, $this->detached );
- }
-
- /**
- * Generates and displays row action links.
- *
- * @since 4.3.0
- *
- * @param object $post Attachment being acted upon.
- * @param string $column_name Current column name.
- * @param string $primary Primary column name.
- * @return string Row actions output for media attachments.
- */
- protected function handle_row_actions( $post, $column_name, $primary ) {
- if ( $primary !== $column_name ) {
- return '';
- }
-
- $att_title = _draft_or_post_title();
- return $this->row_actions( $this->_get_row_actions( $post, $att_title ) );
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-ms-sites-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-ms-sites-list-table.php
deleted file mode 100644
index 34fbad2..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-ms-sites-list-table.php
+++ /dev/null
@@ -1,738 +0,0 @@
-status_list = array(
- 'archived' => array( 'site-archived', __( 'Archived' ) ),
- 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ),
- 'deleted' => array( 'site-deleted', __( 'Deleted' ) ),
- 'mature' => array( 'site-mature', __( 'Mature' ) ),
- );
-
- parent::__construct(
- array(
- 'plural' => 'sites',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
- }
-
- /**
- * @return bool
- */
- public function ajax_user_can() {
- return current_user_can( 'manage_sites' );
- }
-
- /**
- * Prepares the list of sites for display.
- *
- * @since 3.1.0
- *
- * @global string $s
- * @global string $mode
- * @global wpdb $wpdb WordPress database abstraction object.
- */
- public function prepare_items() {
- global $s, $mode, $wpdb;
-
- if ( ! empty( $_REQUEST['mode'] ) ) {
- $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
- set_user_setting( 'sites_list_mode', $mode );
- } else {
- $mode = get_user_setting( 'sites_list_mode', 'list' );
- }
-
- $per_page = $this->get_items_per_page( 'sites_network_per_page' );
-
- $pagenum = $this->get_pagenum();
-
- $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
- $wild = '';
- if ( false !== strpos( $s, '*' ) ) {
- $wild = '*';
- $s = trim( $s, '*' );
- }
-
- /*
- * If the network is large and a search is not being performed, show only
- * the latest sites with no paging in order to avoid expensive count queries.
- */
- if ( ! $s && wp_is_large_network() ) {
- if ( ! isset( $_REQUEST['orderby'] ) ) {
- $_GET['orderby'] = '';
- $_REQUEST['orderby'] = '';
- }
- if ( ! isset( $_REQUEST['order'] ) ) {
- $_GET['order'] = 'DESC';
- $_REQUEST['order'] = 'DESC';
- }
- }
-
- $args = array(
- 'number' => intval( $per_page ),
- 'offset' => intval( ( $pagenum - 1 ) * $per_page ),
- 'network_id' => get_current_network_id(),
- );
-
- if ( empty( $s ) ) {
- // Nothing to do.
- } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) ||
- preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
- preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) ||
- preg_match( '/^[0-9]{1,3}\.$/', $s ) ) {
- // IPv4 address
- $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) );
- $reg_blog_ids = $wpdb->get_col( $sql );
-
- if ( $reg_blog_ids ) {
- $args['site__in'] = $reg_blog_ids;
- }
- } elseif ( is_numeric( $s ) && empty( $wild ) ) {
- $args['ID'] = $s;
- } else {
- $args['search'] = $s;
-
- if ( ! is_subdomain_install() ) {
- $args['search_columns'] = array( 'path' );
- }
- }
-
- $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
- if ( 'registered' === $order_by ) {
- // registered is a valid field name.
- } elseif ( 'lastupdated' === $order_by ) {
- $order_by = 'last_updated';
- } elseif ( 'blogname' === $order_by ) {
- if ( is_subdomain_install() ) {
- $order_by = 'domain';
- } else {
- $order_by = 'path';
- }
- } elseif ( 'blog_id' === $order_by ) {
- $order_by = 'id';
- } elseif ( ! $order_by ) {
- $order_by = false;
- }
-
- $args['orderby'] = $order_by;
-
- if ( $order_by ) {
- $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC';
- }
-
- if ( wp_is_large_network() ) {
- $args['no_found_rows'] = true;
- } else {
- $args['no_found_rows'] = false;
- }
-
- // Take into account the role the user has selected.
- $status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
- if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) {
- $args[ $status ] = 1;
- }
-
- /**
- * Filters the arguments for the site query in the sites list table.
- *
- * @since 4.6.0
- *
- * @param array $args An array of get_sites() arguments.
- */
- $args = apply_filters( 'ms_sites_list_table_query_args', $args );
-
- $_sites = get_sites( $args );
- if ( is_array( $_sites ) ) {
- update_site_cache( $_sites );
-
- $this->items = array_slice( $_sites, 0, $per_page );
- }
-
- $total_sites = get_sites(
- array_merge(
- $args,
- array(
- 'count' => true,
- 'offset' => 0,
- 'number' => 0,
- )
- )
- );
-
- $this->set_pagination_args(
- array(
- 'total_items' => $total_sites,
- 'per_page' => $per_page,
- )
- );
- }
-
- /**
- */
- public function no_items() {
- _e( 'No sites found.' );
- }
-
- /**
- * Gets links to filter sites by status.
- *
- * @since 5.3.0
- *
- * @return array
- *
- */
- protected function get_views() {
- $counts = wp_count_sites();
-
- $statuses = array(
- /* translators: %s: Number of sites. */
- 'all' => _nx_noop(
- 'All (%s) ',
- 'All (%s) ',
- 'sites'
- ),
-
- /* translators: %s: Number of sites. */
- 'public' => _n_noop(
- 'Public (%s) ',
- 'Public (%s) '
- ),
-
- /* translators: %s: Number of sites. */
- 'archived' => _n_noop(
- 'Archived (%s) ',
- 'Archived (%s) '
- ),
-
- /* translators: %s: Number of sites. */
- 'mature' => _n_noop(
- 'Mature (%s) ',
- 'Mature (%s) '
- ),
-
- /* translators: %s: Number of sites. */
- 'spam' => _nx_noop(
- 'Spam (%s) ',
- 'Spam (%s) ',
- 'sites'
- ),
-
- /* translators: %s: Number of sites. */
- 'deleted' => _n_noop(
- 'Deleted (%s) ',
- 'Deleted (%s) '
- ),
- );
-
- $view_links = array();
- $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
- $url = 'sites.php';
-
- foreach ( $statuses as $status => $label_count ) {
- $current_link_attributes = $requested_status === $status || ( $requested_status === '' && 'all' === $status )
- ? ' class="current" aria-current="page"'
- : '';
- if ( (int) $counts[ $status ] > 0 ) {
- $label = sprintf( translate_nooped_plural( $label_count, $counts[ $status ] ), number_format_i18n( $counts[ $status ] ) );
- $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url );
-
- $view_links[ $status ] = sprintf(
- '%3$s ',
- esc_url( $full_url ),
- $current_link_attributes,
- $label
- );
- }
- }
-
- return $view_links;
- }
-
- /**
- * @return array
- */
- protected function get_bulk_actions() {
- $actions = array();
- if ( current_user_can( 'delete_sites' ) ) {
- $actions['delete'] = __( 'Delete' );
- }
- $actions['spam'] = _x( 'Mark as Spam', 'site' );
- $actions['notspam'] = _x( 'Not Spam', 'site' );
-
- return $actions;
- }
-
- /**
- * @global string $mode List table view mode.
- *
- * @param string $which The location of the pagination nav markup: 'top' or 'bottom'.
- */
- protected function pagination( $which ) {
- global $mode;
-
- parent::pagination( $which );
-
- if ( 'top' === $which ) {
- $this->view_switcher( $mode );
- }
- }
-
- /**
- * Extra controls to be displayed between bulk actions and pagination.
- *
- * @since 5.3.0
- *
- * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
- */
- protected function extra_tablenav( $which ) {
- ?>
-
- 'site-query-submit' ) );
- }
- }
- ?>
-
- ' ',
- 'blogname' => __( 'URL' ),
- 'lastupdated' => __( 'Last Updated' ),
- 'registered' => _x( 'Registered', 'site' ),
- 'users' => __( 'Users' ),
- );
-
- if ( has_filter( 'wpmublogsaction' ) ) {
- $sites_columns['plugins'] = __( 'Actions' );
- }
-
- /**
- * Filters the displayed site columns in Sites list table.
- *
- * @since MU (3.0.0)
- *
- * @param string[] $sites_columns An array of displayed site columns. Default 'cb',
- * 'blogname', 'lastupdated', 'registered', 'users'.
- */
- return apply_filters( 'wpmu_blogs_columns', $sites_columns );
- }
-
- /**
- * @return array
- */
- protected function get_sortable_columns() {
- return array(
- 'blogname' => 'blogname',
- 'lastupdated' => 'lastupdated',
- 'registered' => 'blog_id',
- );
- }
-
- /**
- * Handles the checkbox column output.
- *
- * @since 4.3.0
- *
- * @param array $blog Current site.
- */
- public function column_cb( $blog ) {
- if ( ! is_main_site( $blog['blog_id'] ) ) :
- $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
- ?>
-
-
-
-
-
-
-
- site_states( $blog ); ?>
-
- ';
- printf(
- /* translators: 1: Site title, 2: Site tagline. */
- __( '%1$s – %2$s' ),
- get_option( 'blogname' ),
- '' . get_option( 'blogdescription' ) . ' '
- );
- echo '
';
- restore_current_blog();
- }
- }
-
- /**
- * Handles the lastupdated column output.
- *
- * @since 4.3.0
- *
- * @global string $mode List table view mode.
- *
- * @param array $blog Current site.
- */
- public function column_lastupdated( $blog ) {
- global $mode;
-
- if ( 'list' === $mode ) {
- $date = __( 'Y/m/d' );
- } else {
- $date = __( 'Y/m/d g:i:s a' );
- }
-
- echo ( $blog['last_updated'] === '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] );
- }
-
- /**
- * Handles the registered column output.
- *
- * @since 4.3.0
- *
- * @global string $mode List table view mode.
- *
- * @param array $blog Current site.
- */
- public function column_registered( $blog ) {
- global $mode;
-
- if ( 'list' === $mode ) {
- $date = __( 'Y/m/d' );
- } else {
- $date = __( 'Y/m/d g:i:s a' );
- }
-
- if ( $blog['registered'] === '0000-00-00 00:00:00' ) {
- echo '—';
- } else {
- echo mysql2date( $date, $blog['registered'] );
- }
- }
-
- /**
- * Handles the users column output.
- *
- * @since 4.3.0
- *
- * @param array $blog Current site.
- */
- public function column_users( $blog ) {
- $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
- if ( ! $user_count ) {
- $blog_users = new WP_User_Query(
- array(
- 'blog_id' => $blog['blog_id'],
- 'fields' => 'ID',
- 'number' => 1,
- 'count_total' => true,
- )
- );
- $user_count = $blog_users->get_total();
- wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
- }
-
- printf(
- '%s ',
- esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
- number_format_i18n( $user_count )
- );
- }
-
- /**
- * Handles the plugins column output.
- *
- * @since 4.3.0
- *
- * @param array $blog Current site.
- */
- public function column_plugins( $blog ) {
- if ( has_filter( 'wpmublogsaction' ) ) {
- /**
- * Fires inside the auxiliary 'Actions' column of the Sites list table.
- *
- * By default this column is hidden unless something is hooked to the action.
- *
- * @since MU (3.0.0)
- *
- * @param int $blog_id The site ID.
- */
- do_action( 'wpmublogsaction', $blog['blog_id'] );
- }
- }
-
- /**
- * Handles output for the default column.
- *
- * @since 4.3.0
- *
- * @param array $blog Current site.
- * @param string $column_name Current column name.
- */
- public function column_default( $blog, $column_name ) {
- /**
- * Fires for each registered custom column in the Sites list table.
- *
- * @since 3.1.0
- *
- * @param string $column_name The name of the column to display.
- * @param int $blog_id The site ID.
- */
- do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
- }
-
- /**
- * @global string $mode
- */
- public function display_rows() {
- foreach ( $this->items as $blog ) {
- $blog = $blog->to_array();
- $class = '';
- reset( $this->status_list );
-
- foreach ( $this->status_list as $status => $col ) {
- if ( $blog[ $status ] == 1 ) {
- $class = " class='{$col[0]}'";
- }
- }
-
- echo "";
-
- $this->single_row_columns( $blog );
-
- echo ' ';
- }
- }
-
- /**
- * Maybe output comma-separated site states.
- *
- * @since 5.3.0
- *
- * @param array $site
- */
- protected function site_states( $site ) {
- $site_states = array();
-
- // $site is still an array, so get the object.
- $_site = WP_Site::get_instance( $site['blog_id'] );
-
- if ( is_main_site( $_site->id ) ) {
- $site_states['main'] = __( 'Main' );
- }
-
- reset( $this->status_list );
-
- $site_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : '';
- foreach ( $this->status_list as $status => $col ) {
- if ( ( 1 === intval( $_site->{$status} ) ) && ( $site_status !== $status ) ) {
- $site_states[ $col[0] ] = $col[1];
- }
- }
-
- /**
- * Filter the default site display states for items in the Sites list table.
- *
- * @since 5.3.0
- *
- * @param array $site_states An array of site states. Default 'Main',
- * 'Archived', 'Mature', 'Spam', 'Deleted'.
- * @param WP_Site $site The current site object.
- */
- $site_states = apply_filters( 'display_site_states', $site_states, $_site );
-
- if ( ! empty( $site_states ) ) {
- $state_count = count( $site_states );
- $i = 0;
- echo ' — ';
- foreach ( $site_states as $state ) {
- ++$i;
- ( $i == $state_count ) ? $sep = '' : $sep = ', ';
- echo "{$state}{$sep} ";
- }
- }
- }
-
- /**
- * Gets the name of the default primary column.
- *
- * @since 4.3.0
- *
- * @return string Name of the default primary column, in this case, 'blogname'.
- */
- protected function get_default_primary_column_name() {
- return 'blogname';
- }
-
- /**
- * Generates and displays row action links.
- *
- * @since 4.3.0
- *
- * @param object $blog Site being acted upon.
- * @param string $column_name Current column name.
- * @param string $primary Primary column name.
- * @return string Row actions output.
- */
- protected function handle_row_actions( $blog, $column_name, $primary ) {
- if ( $primary !== $column_name ) {
- return;
- }
-
- $blogname = untrailingslashit( $blog['domain'] . $blog['path'] );
-
- // Preordered.
- $actions = array(
- 'edit' => '',
- 'backend' => '',
- 'activate' => '',
- 'deactivate' => '',
- 'archive' => '',
- 'unarchive' => '',
- 'spam' => '',
- 'unspam' => '',
- 'delete' => '',
- 'visit' => '',
- );
-
- $actions['edit'] = '' . __( 'Edit' ) . ' ';
- $actions['backend'] = "" . __( 'Dashboard' ) . ' ';
- if ( get_network()->site_id != $blog['blog_id'] ) {
- if ( $blog['deleted'] == '1' ) {
- $actions['activate'] = '' . __( 'Activate' ) . ' ';
- } else {
- $actions['deactivate'] = '' . __( 'Deactivate' ) . ' ';
- }
-
- if ( $blog['archived'] == '1' ) {
- $actions['unarchive'] = '' . __( 'Unarchive' ) . ' ';
- } else {
- $actions['archive'] = '' . _x( 'Archive', 'verb; site' ) . ' ';
- }
-
- if ( $blog['spam'] == '1' ) {
- $actions['unspam'] = '' . _x( 'Not Spam', 'site' ) . ' ';
- } else {
- $actions['spam'] = '' . _x( 'Spam', 'site' ) . ' ';
- }
-
- if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) {
- $actions['delete'] = '' . __( 'Delete' ) . ' ';
- }
- }
-
- $actions['visit'] = "" . __( 'Visit' ) . ' ';
-
- /**
- * Filters the action links displayed for each site in the Sites list table.
- *
- * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
- * default for each site. The site's status determines whether to show the
- * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and
- * 'Not Spam' or 'Spam' link for each site.
- *
- * @since 3.1.0
- *
- * @param string[] $actions An array of action links to be displayed.
- * @param int $blog_id The site ID.
- * @param string $blogname Site path, formatted depending on whether it is a sub-domain
- * or subdirectory multisite installation.
- */
- $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );
- return $this->row_actions( $actions );
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-ms-themes-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-ms-themes-list-table.php
deleted file mode 100644
index cb1f349..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-ms-themes-list-table.php
+++ /dev/null
@@ -1,797 +0,0 @@
- 'themes',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
-
- $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
- if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) ) {
- $status = 'all';
- }
-
- $page = $this->get_pagenum();
-
- $this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false;
-
- if ( $this->is_site_themes ) {
- $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
- }
- }
-
- /**
- * @return array
- */
- protected function get_table_classes() {
- // todo: remove and add CSS for .themes
- return array( 'widefat', 'plugins' );
- }
-
- /**
- * @return bool
- */
- public function ajax_user_can() {
- if ( $this->is_site_themes ) {
- return current_user_can( 'manage_sites' );
- } else {
- return current_user_can( 'manage_network_themes' );
- }
- }
-
- /**
- * @global string $status
- * @global array $totals
- * @global int $page
- * @global string $orderby
- * @global string $order
- * @global string $s
- */
- public function prepare_items() {
- global $status, $totals, $page, $orderby, $order, $s;
-
- wp_reset_vars( array( 'orderby', 'order', 's' ) );
-
- $themes = array(
- /**
- * Filters the full array of WP_Theme objects to list in the Multisite
- * themes list table.
- *
- * @since 3.1.0
- *
- * @param WP_Theme[] $all Array of WP_Theme objects to display in the list table.
- */
- 'all' => apply_filters( 'all_themes', wp_get_themes() ),
- 'search' => array(),
- 'enabled' => array(),
- 'disabled' => array(),
- 'upgrade' => array(),
- 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
- );
-
- if ( $this->is_site_themes ) {
- $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
- $allowed_where = 'site';
- } else {
- $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
- $allowed_where = 'network';
- }
-
- $current = get_site_transient( 'update_themes' );
- $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current;
-
- foreach ( (array) $themes['all'] as $key => $theme ) {
- if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
- unset( $themes['all'][ $key ] );
- continue;
- }
-
- if ( $maybe_update && isset( $current->response[ $key ] ) ) {
- $themes['all'][ $key ]->update = true;
- $themes['upgrade'][ $key ] = $themes['all'][ $key ];
- }
-
- $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
- $themes[ $filter ][ $key ] = $themes['all'][ $key ];
- }
-
- if ( $s ) {
- $status = 'search';
- $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
- }
-
- $totals = array();
- foreach ( $themes as $type => $list ) {
- $totals[ $type ] = count( $list );
- }
-
- if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) {
- $status = 'all';
- }
-
- $this->items = $themes[ $status ];
- WP_Theme::sort_by_name( $this->items );
-
- $this->has_items = ! empty( $themes['all'] );
- $total_this_page = $totals[ $status ];
-
- wp_localize_script(
- 'updates',
- '_wpUpdatesItemCounts',
- array(
- 'themes' => $totals,
- 'totals' => wp_get_update_data(),
- )
- );
-
- if ( $orderby ) {
- $orderby = ucfirst( $orderby );
- $order = strtoupper( $order );
-
- if ( $orderby === 'Name' ) {
- if ( 'ASC' === $order ) {
- $this->items = array_reverse( $this->items );
- }
- } else {
- uasort( $this->items, array( $this, '_order_callback' ) );
- }
- }
-
- $start = ( $page - 1 ) * $themes_per_page;
-
- if ( $total_this_page > $themes_per_page ) {
- $this->items = array_slice( $this->items, $start, $themes_per_page, true );
- }
-
- $this->set_pagination_args(
- array(
- 'total_items' => $total_this_page,
- 'per_page' => $themes_per_page,
- )
- );
- }
-
- /**
- * @staticvar string $term
- * @param WP_Theme $theme
- * @return bool
- */
- public function _search_callback( $theme ) {
- static $term = null;
- if ( is_null( $term ) ) {
- $term = wp_unslash( $_REQUEST['s'] );
- }
-
- foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
- // Don't mark up; Do translate.
- if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) {
- return true;
- }
- }
-
- if ( false !== stripos( $theme->get_stylesheet(), $term ) ) {
- return true;
- }
-
- if ( false !== stripos( $theme->get_template(), $term ) ) {
- return true;
- }
-
- return false;
- }
-
- // Not used by any core columns.
- /**
- * @global string $orderby
- * @global string $order
- * @param array $theme_a
- * @param array $theme_b
- * @return int
- */
- public function _order_callback( $theme_a, $theme_b ) {
- global $orderby, $order;
-
- $a = $theme_a[ $orderby ];
- $b = $theme_b[ $orderby ];
-
- if ( $a == $b ) {
- return 0;
- }
-
- if ( 'DESC' === $order ) {
- return ( $a < $b ) ? 1 : -1;
- } else {
- return ( $a < $b ) ? -1 : 1;
- }
- }
-
- /**
- */
- public function no_items() {
- if ( $this->has_items ) {
- _e( 'No themes found.' );
- } else {
- _e( 'You do not appear to have any themes available at this time.' );
- }
- }
-
- /**
- * @return array
- */
- public function get_columns() {
- return array(
- 'cb' => ' ',
- 'name' => __( 'Theme' ),
- 'description' => __( 'Description' ),
- );
- }
-
- /**
- * @return array
- */
- protected function get_sortable_columns() {
- return array(
- 'name' => 'name',
- );
- }
-
- /**
- * Gets the name of the primary column.
- *
- * @since 4.3.0
- *
- * @return string Unalterable name of the primary column name, in this case, 'name'.
- */
- protected function get_primary_column_name() {
- return 'name';
- }
-
- /**
- * @global array $totals
- * @global string $status
- * @return array
- */
- protected function get_views() {
- global $totals, $status;
-
- $status_links = array();
- foreach ( $totals as $type => $count ) {
- if ( ! $count ) {
- continue;
- }
-
- switch ( $type ) {
- case 'all':
- /* translators: %s: Number of themes. */
- $text = _nx(
- 'All (%s) ',
- 'All (%s) ',
- $count,
- 'themes'
- );
- break;
- case 'enabled':
- /* translators: %s: Number of themes. */
- $text = _nx(
- 'Enabled (%s) ',
- 'Enabled (%s) ',
- $count,
- 'themes'
- );
- break;
- case 'disabled':
- /* translators: %s: Number of themes. */
- $text = _nx(
- 'Disabled (%s) ',
- 'Disabled (%s) ',
- $count,
- 'themes'
- );
- break;
- case 'upgrade':
- /* translators: %s: Number of themes. */
- $text = _nx(
- 'Update Available (%s) ',
- 'Update Available (%s) ',
- $count,
- 'themes'
- );
- break;
- case 'broken':
- /* translators: %s: Number of themes. */
- $text = _nx(
- 'Broken (%s) ',
- 'Broken (%s) ',
- $count,
- 'themes'
- );
- break;
- }
-
- if ( $this->is_site_themes ) {
- $url = 'site-themes.php?id=' . $this->site_id;
- } else {
- $url = 'themes.php';
- }
-
- if ( 'search' != $type ) {
- $status_links[ $type ] = sprintf(
- "%s ",
- esc_url( add_query_arg( 'theme_status', $type, $url ) ),
- ( $type === $status ) ? ' class="current" aria-current="page"' : '',
- sprintf( $text, number_format_i18n( $count ) )
- );
- }
- }
-
- return $status_links;
- }
-
- /**
- * @global string $status
- *
- * @return array
- */
- protected function get_bulk_actions() {
- global $status;
-
- $actions = array();
- if ( 'enabled' != $status ) {
- $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
- }
- if ( 'disabled' != $status ) {
- $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
- }
- if ( ! $this->is_site_themes ) {
- if ( current_user_can( 'update_themes' ) ) {
- $actions['update-selected'] = __( 'Update' );
- }
- if ( current_user_can( 'delete_themes' ) ) {
- $actions['delete-selected'] = __( 'Delete' );
- }
- }
- return $actions;
- }
-
- /**
- */
- public function display_rows() {
- foreach ( $this->items as $theme ) {
- $this->single_row( $theme );
- }
- }
-
- /**
- * Handles the checkbox column output.
- *
- * @since 4.3.0
- *
- * @param WP_Theme $theme The current WP_Theme object.
- */
- public function column_cb( $theme ) {
- $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
- ?>
-
- display( 'Name' ); ?>
- is_site_themes ) {
- $url = "site-themes.php?id={$this->site_id}&";
- $allowed = $theme->is_allowed( 'site', $this->site_id );
- } else {
- $url = 'themes.php?';
- $allowed = $theme->is_allowed( 'network' );
- }
-
- // Pre-order.
- $actions = array(
- 'enable' => '',
- 'disable' => '',
- 'delete' => '',
- );
-
- $stylesheet = $theme->get_stylesheet();
- $theme_key = urlencode( $stylesheet );
-
- if ( ! $allowed ) {
- if ( ! $theme->errors() ) {
- $url = add_query_arg(
- array(
- 'action' => 'enable',
- 'theme' => $theme_key,
- 'paged' => $page,
- 's' => $s,
- ),
- $url
- );
-
- if ( $this->is_site_themes ) {
- /* translators: %s: Theme name. */
- $aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) );
- } else {
- /* translators: %s: Theme name. */
- $aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) );
- }
-
- $actions['enable'] = sprintf(
- '%s ',
- esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ),
- esc_attr( $aria_label ),
- ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) )
- );
- }
- } else {
- $url = add_query_arg(
- array(
- 'action' => 'disable',
- 'theme' => $theme_key,
- 'paged' => $page,
- 's' => $s,
- ),
- $url
- );
-
- if ( $this->is_site_themes ) {
- /* translators: %s: Theme name. */
- $aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) );
- } else {
- /* translators: %s: Theme name. */
- $aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) );
- }
-
- $actions['disable'] = sprintf(
- '%s ',
- esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ),
- esc_attr( $aria_label ),
- ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) )
- );
- }
-
- if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) {
- $url = add_query_arg(
- array(
- 'action' => 'delete-selected',
- 'checked[]' => $theme_key,
- 'theme_status' => $context,
- 'paged' => $page,
- 's' => $s,
- ),
- 'themes.php'
- );
-
- /* translators: %s: Theme name. */
- $aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) );
-
- $actions['delete'] = sprintf(
- '%s ',
- esc_url( wp_nonce_url( $url, 'bulk-themes' ) ),
- esc_attr( $aria_label ),
- __( 'Delete' )
- );
- }
- /**
- * Filters the action links displayed for each theme in the Multisite
- * themes list table.
- *
- * The action links displayed are determined by the theme's status, and
- * which Multisite themes list table is being displayed - the Network
- * themes list table (themes.php), which displays all installed themes,
- * or the Site themes list table (site-themes.php), which displays the
- * non-network enabled themes when editing a site in the Network admin.
- *
- * The default action links for the Network themes list table include
- * 'Network Enable', 'Network Disable', and 'Delete'.
- *
- * The default action links for the Site themes list table include
- * 'Enable', and 'Disable'.
- *
- * @since 2.8.0
- *
- * @param string[] $actions An array of action links.
- * @param WP_Theme $theme The current WP_Theme object.
- * @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
- */
- $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
-
- /**
- * Filters the action links of a specific theme in the Multisite themes
- * list table.
- *
- * The dynamic portion of the hook name, `$stylesheet`, refers to the
- * directory name of the theme, which in most cases is synonymous
- * with the template name.
- *
- * @since 3.1.0
- *
- * @param string[] $actions An array of action links.
- * @param WP_Theme $theme The current WP_Theme object.
- * @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'.
- */
- $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context );
-
- echo $this->row_actions( $actions, true );
- }
-
- /**
- * Handles the description column output.
- *
- * @since 4.3.0
- *
- * @global string $status
- * @global array $totals
- *
- * @param WP_Theme $theme The current WP_Theme object.
- */
- public function column_description( $theme ) {
- global $status, $totals;
- if ( $theme->errors() ) {
- $pre = $status === 'broken' ? __( 'Broken Theme:' ) . ' ' : '';
- echo '' . $pre . $theme->errors()->get_error_message() . '
';
- }
-
- if ( $this->is_site_themes ) {
- $allowed = $theme->is_allowed( 'site', $this->site_id );
- } else {
- $allowed = $theme->is_allowed( 'network' );
- }
-
- $class = ! $allowed ? 'inactive' : 'active';
- if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
- $class .= ' update';
- }
-
- echo "" . $theme->display( 'Description' ) . "
- ";
-
- $stylesheet = $theme->get_stylesheet();
- $theme_meta = array();
-
- if ( $theme->get( 'Version' ) ) {
- /* translators: %s: Theme version. */
- $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) );
- }
-
- /* translators: %s: Theme author. */
- $theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) );
-
- if ( $theme->get( 'ThemeURI' ) ) {
- /* translators: %s: Theme name. */
- $aria_label = sprintf( __( 'Visit %s homepage' ), $theme->display( 'Name' ) );
-
- $theme_meta[] = sprintf(
- '
%s ',
- $theme->display( 'ThemeURI' ),
- esc_attr( $aria_label ),
- __( 'Visit Theme Site' )
- );
- }
- /**
- * Filters the array of row meta for each theme in the Multisite themes
- * list table.
- *
- * @since 3.1.0
- *
- * @param string[] $theme_meta An array of the theme's metadata,
- * including the version, author, and
- * theme URI.
- * @param string $stylesheet Directory name of the theme.
- * @param WP_Theme $theme WP_Theme object.
- * @param string $status Status of the theme.
- */
- $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
- echo implode( ' | ', $theme_meta );
-
- echo '
';
- }
-
- /**
- * Handles default column output.
- *
- * @since 4.3.0
- *
- * @param WP_Theme $theme The current WP_Theme object.
- * @param string $column_name The current column name.
- */
- public function column_default( $theme, $column_name ) {
- $stylesheet = $theme->get_stylesheet();
-
- /**
- * Fires inside each custom column of the Multisite themes list table.
- *
- * @since 3.1.0
- *
- * @param string $column_name Name of the column.
- * @param string $stylesheet Directory name of the theme.
- * @param WP_Theme $theme Current WP_Theme object.
- */
- do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
- }
-
- /**
- * Handles the output for a single table row.
- *
- * @since 4.3.0
- *
- * @param WP_Theme $item The current WP_Theme object.
- */
- public function single_row_columns( $item ) {
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
-
- foreach ( $columns as $column_name => $column_display_name ) {
- $extra_classes = '';
- if ( in_array( $column_name, $hidden ) ) {
- $extra_classes .= ' hidden';
- }
-
- switch ( $column_name ) {
- case 'cb':
- echo '';
-
- $this->column_cb( $item );
-
- echo ' ';
- break;
-
- case 'name':
- $active_theme_label = '';
-
- /* The presence of the site_id property means that this is a subsite view and a label for the active theme needs to be added */
- if ( ! empty( $this->site_id ) ) {
- $stylesheet = get_blog_option( $this->site_id, 'stylesheet' );
- $template = get_blog_option( $this->site_id, 'template' );
-
- /* Add a label for the active template */
- if ( $item->get_template() === $template ) {
- $active_theme_label = ' — ' . __( 'Active Theme' );
- }
-
- /* In case this is a child theme, label it properly */
- if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
- $active_theme_label = ' — ' . __( 'Active Child Theme' );
- }
- }
-
- echo "" . $item->display( 'Name' ) . $active_theme_label . ' ';
-
- $this->column_name( $item );
-
- echo ' ';
- break;
-
- case 'description':
- echo "";
-
- $this->column_description( $item );
-
- echo ' ';
- break;
-
- default:
- echo "";
-
- $this->column_default( $item, $column_name );
-
- echo ' ';
- break;
- }
- }
- }
-
- /**
- * @global string $status
- * @global array $totals
- *
- * @param WP_Theme $theme
- */
- public function single_row( $theme ) {
- global $status, $totals;
-
- if ( $this->is_site_themes ) {
- $allowed = $theme->is_allowed( 'site', $this->site_id );
- } else {
- $allowed = $theme->is_allowed( 'network' );
- }
-
- $stylesheet = $theme->get_stylesheet();
-
- $class = ! $allowed ? 'inactive' : 'active';
- if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) {
- $class .= ' update';
- }
-
- printf(
- '',
- esc_attr( $class ),
- esc_attr( $stylesheet )
- );
-
- $this->single_row_columns( $theme );
-
- echo ' ';
-
- if ( $this->is_site_themes ) {
- remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
- }
-
- /**
- * Fires after each row in the Multisite themes list table.
- *
- * @since 3.1.0
- *
- * @param string $stylesheet Directory name of the theme.
- * @param WP_Theme $theme Current WP_Theme object.
- * @param string $status Status of the theme.
- */
- do_action( 'after_theme_row', $stylesheet, $theme, $status );
-
- /**
- * Fires after each specific row in the Multisite themes list table.
- *
- * The dynamic portion of the hook name, `$stylesheet`, refers to the
- * directory name of the theme, most often synonymous with the template
- * name of the theme.
- *
- * @since 3.5.0
- *
- * @param string $stylesheet Directory name of the theme.
- * @param WP_Theme $theme Current WP_Theme object.
- * @param string $status Status of the theme.
- */
- do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status );
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-ms-users-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-ms-users-list-table.php
deleted file mode 100644
index 1fd437c..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-ms-users-list-table.php
+++ /dev/null
@@ -1,522 +0,0 @@
-get_items_per_page( 'users_network_per_page' );
-
- $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
-
- $paged = $this->get_pagenum();
-
- $args = array(
- 'number' => $users_per_page,
- 'offset' => ( $paged - 1 ) * $users_per_page,
- 'search' => $usersearch,
- 'blog_id' => 0,
- 'fields' => 'all_with_meta',
- );
-
- if ( wp_is_large_network( 'users' ) ) {
- $args['search'] = ltrim( $args['search'], '*' );
- } elseif ( '' !== $args['search'] ) {
- $args['search'] = trim( $args['search'], '*' );
- $args['search'] = '*' . $args['search'] . '*';
- }
-
- if ( $role === 'super' ) {
- $args['login__in'] = get_super_admins();
- }
-
- /*
- * If the network is large and a search is not being performed,
- * show only the latest users with no paging in order to avoid
- * expensive count queries.
- */
- if ( ! $usersearch && wp_is_large_network( 'users' ) ) {
- if ( ! isset( $_REQUEST['orderby'] ) ) {
- $_GET['orderby'] = 'id';
- $_REQUEST['orderby'] = 'id';
- }
- if ( ! isset( $_REQUEST['order'] ) ) {
- $_GET['order'] = 'DESC';
- $_REQUEST['order'] = 'DESC';
- }
- $args['count_total'] = false;
- }
-
- if ( isset( $_REQUEST['orderby'] ) ) {
- $args['orderby'] = $_REQUEST['orderby'];
- }
-
- if ( isset( $_REQUEST['order'] ) ) {
- $args['order'] = $_REQUEST['order'];
- }
-
- if ( ! empty( $_REQUEST['mode'] ) ) {
- $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
- set_user_setting( 'network_users_list_mode', $mode );
- } else {
- $mode = get_user_setting( 'network_users_list_mode', 'list' );
- }
-
- /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
- $args = apply_filters( 'users_list_table_query_args', $args );
-
- // Query the user IDs for this page
- $wp_user_search = new WP_User_Query( $args );
-
- $this->items = $wp_user_search->get_results();
-
- $this->set_pagination_args(
- array(
- 'total_items' => $wp_user_search->get_total(),
- 'per_page' => $users_per_page,
- )
- );
- }
-
- /**
- * @return array
- */
- protected function get_bulk_actions() {
- $actions = array();
- if ( current_user_can( 'delete_users' ) ) {
- $actions['delete'] = __( 'Delete' );
- }
- $actions['spam'] = _x( 'Mark as Spam', 'user' );
- $actions['notspam'] = _x( 'Not Spam', 'user' );
-
- return $actions;
- }
-
- /**
- */
- public function no_items() {
- _e( 'No users found.' );
- }
-
- /**
- * @global string $role
- * @return array
- */
- protected function get_views() {
- global $role;
-
- $total_users = get_user_count();
- $super_admins = get_super_admins();
- $total_admins = count( $super_admins );
-
- $current_link_attributes = $role !== 'super' ? ' class="current" aria-current="page"' : '';
- $role_links = array();
- $role_links['all'] = sprintf(
- '%s ',
- network_admin_url( 'users.php' ),
- $current_link_attributes,
- sprintf(
- /* translators: Number of users. */
- _nx(
- 'All (%s) ',
- 'All (%s) ',
- $total_users,
- 'users'
- ),
- number_format_i18n( $total_users )
- )
- );
- $current_link_attributes = $role === 'super' ? ' class="current" aria-current="page"' : '';
- $role_links['super'] = sprintf(
- '%s ',
- network_admin_url( 'users.php?role=super' ),
- $current_link_attributes,
- sprintf(
- /* translators: Number of users. */
- _n(
- 'Super Admin (%s) ',
- 'Super Admins (%s) ',
- $total_admins
- ),
- number_format_i18n( $total_admins )
- )
- );
-
- return $role_links;
- }
-
- /**
- * @global string $mode List table view mode.
- *
- * @param string $which
- */
- protected function pagination( $which ) {
- global $mode;
-
- parent::pagination( $which );
-
- if ( 'top' === $which ) {
- $this->view_switcher( $mode );
- }
- }
-
- /**
- * @return array
- */
- public function get_columns() {
- $users_columns = array(
- 'cb' => ' ',
- 'username' => __( 'Username' ),
- 'name' => __( 'Name' ),
- 'email' => __( 'Email' ),
- 'registered' => _x( 'Registered', 'user' ),
- 'blogs' => __( 'Sites' ),
- );
- /**
- * Filters the columns displayed in the Network Admin Users list table.
- *
- * @since MU (3.0.0)
- *
- * @param string[] $users_columns An array of user columns. Default 'cb', 'username',
- * 'name', 'email', 'registered', 'blogs'.
- */
- return apply_filters( 'wpmu_users_columns', $users_columns );
- }
-
- /**
- * @return array
- */
- protected function get_sortable_columns() {
- return array(
- 'username' => 'login',
- 'name' => 'name',
- 'email' => 'email',
- 'registered' => 'id',
- );
- }
-
- /**
- * Handles the checkbox column output.
- *
- * @since 4.3.0
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_cb( $user ) {
- if ( is_super_admin( $user->ID ) ) {
- return;
- }
- ?>
-
- user_login );
- ?>
-
-
- ID;
- }
-
- /**
- * Handles the username column output.
- *
- * @since 4.3.0
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_username( $user ) {
- $super_admins = get_super_admins();
- $avatar = get_avatar( $user->user_email, 32 );
-
- echo $avatar;
-
- if ( current_user_can( 'edit_user', $user->ID ) ) {
- $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
- $edit = "{$user->user_login} ";
- } else {
- $edit = $user->user_login;
- }
-
- ?>
-
- user_login, $super_admins ) ) {
- echo ' — ' . __( 'Super Admin' );
- }
- ?>
-
- first_name && $user->last_name ) {
- echo "$user->first_name $user->last_name";
- } elseif ( $user->first_name ) {
- echo $user->first_name;
- } elseif ( $user->last_name ) {
- echo $user->last_name;
- } else {
- echo '— ' . _x( 'Unknown', 'name' ) . ' ';
- }
- }
-
- /**
- * Handles the email column output.
- *
- * @since 4.3.0
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_email( $user ) {
- echo "$user->user_email ";
- }
-
- /**
- * Handles the registered date column output.
- *
- * @since 4.3.0
- *
- * @global string $mode List table view mode.
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_registered( $user ) {
- global $mode;
- if ( 'list' === $mode ) {
- $date = __( 'Y/m/d' );
- } else {
- $date = __( 'Y/m/d g:i:s a' );
- }
- echo mysql2date( $date, $user->user_registered );
- }
-
- /**
- * @since 4.3.0
- *
- * @param WP_User $user
- * @param string $classes
- * @param string $data
- * @param string $primary
- */
- protected function _column_blogs( $user, $classes, $data, $primary ) {
- echo '';
- echo $this->column_blogs( $user );
- echo $this->handle_row_actions( $user, 'blogs', $primary );
- echo ' ';
- }
-
- /**
- * Handles the sites column output.
- *
- * @since 4.3.0
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_blogs( $user ) {
- $blogs = get_blogs_of_user( $user->ID, true );
- if ( ! is_array( $blogs ) ) {
- return;
- }
-
- foreach ( $blogs as $val ) {
- if ( ! can_edit_network( $val->site_id ) ) {
- continue;
- }
-
- $path = ( $val->path === '/' ) ? '' : $val->path;
- $site_classes = array( 'site-' . $val->site_id );
- /**
- * Filters the span class for a site listing on the mulisite user list table.
- *
- * @since 5.2.0
- *
- * @param array $site_classes Class used within the span tag. Default "site-#" with the site's network ID.
- * @param int $site_id Site ID.
- * @param int $network_id Network ID.
- * @param object $user WP_User object.
- */
- $site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $val->userblog_id, $val->site_id, $user );
- if ( is_array( $site_classes ) && ! empty( $site_classes ) ) {
- $site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) );
- echo '';
- } else {
- echo '';
- }
- echo '' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . ' ';
- echo ' ';
- $actions = array();
- $actions['edit'] = '' . __( 'Edit' ) . ' ';
-
- $class = '';
- if ( $val->spam == 1 ) {
- $class .= 'site-spammed ';
- }
- if ( $val->mature == 1 ) {
- $class .= 'site-mature ';
- }
- if ( $val->deleted == 1 ) {
- $class .= 'site-deleted ';
- }
- if ( $val->archived == 1 ) {
- $class .= 'site-archived ';
- }
-
- $actions['view'] = '' . __( 'View' ) . ' ';
-
- /**
- * Filters the action links displayed next the sites a user belongs to
- * in the Network Admin Users list table.
- *
- * @since 3.1.0
- *
- * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'View'.
- * @param int $userblog_id The site ID.
- */
- $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
-
- $i = 0;
- $action_count = count( $actions );
- foreach ( $actions as $action => $link ) {
- ++$i;
- $sep = ( $i == $action_count ) ? '' : ' | ';
- echo "$link$sep ";
- }
- echo ' ';
- }
- }
-
- /**
- * Handles the default column output.
- *
- * @since 4.3.0
- *
- * @param WP_User $user The current WP_User object.
- * @param string $column_name The current column name.
- */
- public function column_default( $user, $column_name ) {
- /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
- echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
- }
-
- public function display_rows() {
- foreach ( $this->items as $user ) {
- $class = '';
-
- $status_list = array(
- 'spam' => 'site-spammed',
- 'deleted' => 'site-deleted',
- );
-
- foreach ( $status_list as $status => $col ) {
- if ( $user->$status ) {
- $class .= " $col";
- }
- }
-
- ?>
-
- single_row_columns( $user ); ?>
-
- ID ) ) {
- $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
- $actions['edit'] = '' . __( 'Edit' ) . ' ';
- }
-
- if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
- $actions['delete'] = '' . __( 'Delete' ) . ' ';
- }
-
- /**
- * Filters the action links displayed under each user in the Network Admin Users list table.
- *
- * @since 3.2.0
- *
- * @param string[] $actions An array of action links to be displayed. Default 'Edit', 'Delete'.
- * @param WP_User $user WP_User object.
- */
- $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
- return $this->row_actions( $actions );
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-plugin-install-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-plugin-install-list-table.php
deleted file mode 100644
index acea5c4..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-plugin-install-list-table.php
+++ /dev/null
@@ -1,776 +0,0 @@
-no_update ) ) {
- foreach ( $plugin_info->no_update as $plugin ) {
- $plugin->upgrade = false;
- $plugins[ $plugin->slug ] = $plugin;
- }
- }
-
- if ( isset( $plugin_info->response ) ) {
- foreach ( $plugin_info->response as $plugin ) {
- $plugin->upgrade = true;
- $plugins[ $plugin->slug ] = $plugin;
- }
- }
-
- return $plugins;
- }
-
- /**
- * Return a list of slugs of installed plugins, if known.
- *
- * Uses the transient data from the updates API to determine the slugs of
- * known installed plugins. This might be better elsewhere, perhaps even
- * within get_plugins().
- *
- * @since 4.0.0
- *
- * @return array
- */
- protected function get_installed_plugin_slugs() {
- return array_keys( $this->get_installed_plugins() );
- }
-
- /**
- * @global array $tabs
- * @global string $tab
- * @global int $paged
- * @global string $type
- * @global string $term
- */
- public function prepare_items() {
- include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
-
- global $tabs, $tab, $paged, $type, $term;
-
- wp_reset_vars( array( 'tab' ) );
-
- $paged = $this->get_pagenum();
-
- $per_page = 36;
-
- // These are the tabs which are shown on the page
- $tabs = array();
-
- if ( 'search' === $tab ) {
- $tabs['search'] = __( 'Search Results' );
- }
- if ( $tab === 'beta' || false !== strpos( get_bloginfo( 'version' ), '-' ) ) {
- $tabs['beta'] = _x( 'Beta Testing', 'Plugin Installer' );
- }
- $tabs['featured'] = _x( 'Featured', 'Plugin Installer' );
- $tabs['popular'] = _x( 'Popular', 'Plugin Installer' );
- $tabs['recommended'] = _x( 'Recommended', 'Plugin Installer' );
- $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' );
- if ( current_user_can( 'upload_plugins' ) ) {
- // No longer a real tab. Here for filter compatibility.
- // Gets skipped in get_views().
- $tabs['upload'] = __( 'Upload Plugin' );
- }
-
- $nonmenu_tabs = array( 'plugin-information' ); // Valid actions to perform which do not have a Menu item.
-
- /**
- * Filters the tabs shown on the Plugin Install screen.
- *
- * @since 2.7.0
- *
- * @param string[] $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
- * 'recommended', 'favorites', and 'upload'.
- */
- $tabs = apply_filters( 'install_plugins_tabs', $tabs );
-
- /**
- * Filters tabs not associated with a menu item on the Plugin Install screen.
- *
- * @since 2.7.0
- *
- * @param string[] $nonmenu_tabs The tabs that don't have a menu item on the Plugin Install screen.
- */
- $nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
-
- // If a non-valid menu tab has been selected, And it's not a non-menu action.
- if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) {
- $tab = key( $tabs );
- }
-
- $installed_plugins = $this->get_installed_plugins();
-
- $args = array(
- 'page' => $paged,
- 'per_page' => $per_page,
- // Send the locale to the API so it can provide context-sensitive results.
- 'locale' => get_user_locale(),
- );
-
- switch ( $tab ) {
- case 'search':
- $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
- $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
-
- switch ( $type ) {
- case 'tag':
- $args['tag'] = sanitize_title_with_dashes( $term );
- break;
- case 'term':
- $args['search'] = $term;
- break;
- case 'author':
- $args['author'] = $term;
- break;
- }
-
- break;
-
- case 'featured':
- case 'popular':
- case 'new':
- case 'beta':
- $args['browse'] = $tab;
- break;
- case 'recommended':
- $args['browse'] = $tab;
- // Include the list of installed plugins so we can get relevant results.
- $args['installed_plugins'] = array_keys( $installed_plugins );
- break;
-
- case 'favorites':
- $action = 'save_wporg_username_' . get_current_user_id();
- if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action ) ) {
- $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
-
- // If the save url parameter is passed with a falsey value, don't save the favorite user.
- if ( ! isset( $_GET['save'] ) || $_GET['save'] ) {
- update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
- }
- } else {
- $user = get_user_option( 'wporg_favorites' );
- }
- if ( $user ) {
- $args['user'] = $user;
- } else {
- $args = false;
- }
-
- add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 );
- break;
-
- default:
- $args = false;
- break;
- }
-
- /**
- * Filters API request arguments for each Plugin Install screen tab.
- *
- * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
- * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
- *
- * @since 3.7.0
- *
- * @param array|bool $args Plugin Install API arguments.
- */
- $args = apply_filters( "install_plugins_table_api_args_{$tab}", $args );
-
- if ( ! $args ) {
- return;
- }
-
- $api = plugins_api( 'query_plugins', $args );
-
- if ( is_wp_error( $api ) ) {
- $this->error = $api;
- return;
- }
-
- $this->items = $api->plugins;
-
- if ( $this->orderby ) {
- uasort( $this->items, array( $this, 'order_callback' ) );
- }
-
- $this->set_pagination_args(
- array(
- 'total_items' => $api->info['results'],
- 'per_page' => $args['per_page'],
- )
- );
-
- if ( isset( $api->info['groups'] ) ) {
- $this->groups = $api->info['groups'];
- }
-
- if ( $installed_plugins ) {
- $js_plugins = array_fill_keys(
- array( 'all', 'search', 'active', 'inactive', 'recently_activated', 'mustuse', 'dropins' ),
- array()
- );
-
- $js_plugins['all'] = array_values( wp_list_pluck( $installed_plugins, 'plugin' ) );
- $upgrade_plugins = wp_filter_object_list( $installed_plugins, array( 'upgrade' => true ), 'and', 'plugin' );
-
- if ( $upgrade_plugins ) {
- $js_plugins['upgrade'] = array_values( $upgrade_plugins );
- }
-
- wp_localize_script(
- 'updates',
- '_wpUpdatesItemCounts',
- array(
- 'plugins' => $js_plugins,
- 'totals' => wp_get_update_data(),
- )
- );
- }
- }
-
- /**
- */
- public function no_items() {
- if ( isset( $this->error ) ) { ?>
- error->get_error_message(); ?>
-
-
-
-
- $text ) {
- $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
- $href = self_admin_url( 'plugin-install.php?tab=' . $action );
- $display_tabs[ 'plugin-install-' . $action ] = "$text ";
- }
- // No longer a real tab.
- unset( $display_tabs['plugin-install-upload'] );
-
- return $display_tabs;
- }
-
- /**
- * Override parent views so we can use the filter bar display.
- */
- public function views() {
- $views = $this->get_views();
-
- /** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
- $views = apply_filters( "views_{$this->screen->id}", $views );
-
- $this->screen->render_screen_reader_content( 'heading_views' );
- ?>
-
-
- $view ) {
- $views[ $class ] = "\t$view";
- }
- echo implode( " \n", $views ) . "\n";
- }
- ?>
-
-
-
-
- _args['singular'];
-
- $data_attr = '';
-
- if ( $singular ) {
- $data_attr = " data-wp-lists='list:$singular'";
- }
-
- $this->display_tablenav( 'top' );
-
- ?>
-
- screen->render_screen_reader_content( 'heading_list' );
- ?>
-
>
- display_rows_or_placeholder(); ?>
-
-
- display_tablenav( 'bottom' );
- }
-
- /**
- * @global string $tab
- *
- * @param string $which
- */
- protected function display_tablenav( $which ) {
- if ( $GLOBALS['tab'] === 'featured' ) {
- return;
- }
-
- if ( 'top' === $which ) {
- wp_referer_field();
- ?>
-
-
-
-
- pagination( $which ); ?>
-
-
-
-
- pagination( $which ); ?>
-
-
- _args['plural'] );
- }
-
- /**
- * @return array
- */
- public function get_columns() {
- return array();
- }
-
- /**
- * @param object $plugin_a
- * @param object $plugin_b
- * @return int
- */
- private function order_callback( $plugin_a, $plugin_b ) {
- $orderby = $this->orderby;
- if ( ! isset( $plugin_a->$orderby, $plugin_b->$orderby ) ) {
- return 0;
- }
-
- $a = $plugin_a->$orderby;
- $b = $plugin_b->$orderby;
-
- if ( $a == $b ) {
- return 0;
- }
-
- if ( 'DESC' === $this->order ) {
- return ( $a < $b ) ? 1 : -1;
- } else {
- return ( $a < $b ) ? -1 : 1;
- }
- }
-
- public function display_rows() {
- $plugins_allowedtags = array(
- 'a' => array(
- 'href' => array(),
- 'title' => array(),
- 'target' => array(),
- ),
- 'abbr' => array( 'title' => array() ),
- 'acronym' => array( 'title' => array() ),
- 'code' => array(),
- 'pre' => array(),
- 'em' => array(),
- 'strong' => array(),
- 'ul' => array(),
- 'ol' => array(),
- 'li' => array(),
- 'p' => array(),
- 'br' => array(),
- );
-
- $plugins_group_titles = array(
- 'Performance' => _x( 'Performance', 'Plugin installer group title' ),
- 'Social' => _x( 'Social', 'Plugin installer group title' ),
- 'Tools' => _x( 'Tools', 'Plugin installer group title' ),
- );
-
- $group = null;
-
- foreach ( (array) $this->items as $plugin ) {
- if ( is_object( $plugin ) ) {
- $plugin = (array) $plugin;
- }
-
- // Display the group heading if there is one
- if ( isset( $plugin['group'] ) && $plugin['group'] != $group ) {
- if ( isset( $this->groups[ $plugin['group'] ] ) ) {
- $group_name = $this->groups[ $plugin['group'] ];
- if ( isset( $plugins_group_titles[ $group_name ] ) ) {
- $group_name = $plugins_group_titles[ $group_name ];
- }
- } else {
- $group_name = $plugin['group'];
- }
-
- // Starting a new group, close off the divs of the last one
- if ( ! empty( $group ) ) {
- echo '';
- }
-
- echo '' . esc_html( $group_name ) . ' ';
- // needs an extra wrapping div for nth-child selectors to work
- echo '
';
-
- $group = $plugin['group'];
- }
- $title = wp_kses( $plugin['name'], $plugins_allowedtags );
-
- // Remove any HTML from the description.
- $description = strip_tags( $plugin['short_description'] );
- $version = wp_kses( $plugin['version'], $plugins_allowedtags );
-
- $name = strip_tags( $title . ' ' . $version );
-
- $author = wp_kses( $plugin['author'], $plugins_allowedtags );
- if ( ! empty( $author ) ) {
- /* translators: %s: Plugin author. */
- $author = '
' . sprintf( __( 'By %s' ), $author ) . ' ';
- }
-
- $requires_php = isset( $plugin['requires_php'] ) ? $plugin['requires_php'] : null;
- $requires_wp = isset( $plugin['requires'] ) ? $plugin['requires'] : null;
-
- $compatible_php = is_php_version_compatible( $requires_php );
- $compatible_wp = is_wp_version_compatible( $requires_wp );
- $tested_wp = ( empty( $plugin['tested'] ) || version_compare( get_bloginfo( 'version' ), $plugin['tested'], '<=' ) );
-
- $action_links = array();
-
- if ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) {
- $status = install_plugin_install_status( $plugin );
-
- switch ( $status['status'] ) {
- case 'install':
- if ( $status['url'] ) {
- if ( $compatible_php && $compatible_wp ) {
- $action_links[] = sprintf(
- '
%s ',
- esc_attr( $plugin['slug'] ),
- esc_url( $status['url'] ),
- /* translators: %s: Plugin name and version. */
- esc_attr( sprintf( __( 'Install %s now' ), $name ) ),
- esc_attr( $name ),
- __( 'Install Now' )
- );
- } else {
- $action_links[] = sprintf(
- '
%s ',
- _x( 'Cannot Install', 'plugin' )
- );
- }
- }
- break;
-
- case 'update_available':
- if ( $status['url'] ) {
- if ( $compatible_php && $compatible_wp ) {
- $action_links[] = sprintf(
- '
%s ',
- esc_attr( $status['file'] ),
- esc_attr( $plugin['slug'] ),
- esc_url( $status['url'] ),
- /* translators: %s: Plugin name and version. */
- esc_attr( sprintf( __( 'Update %s now' ), $name ) ),
- esc_attr( $name ),
- __( 'Update Now' )
- );
- } else {
- $action_links[] = sprintf(
- '
%s ',
- _x( 'Cannot Update', 'plugin' )
- );
- }
- }
- break;
-
- case 'latest_installed':
- case 'newer_installed':
- if ( is_plugin_active( $status['file'] ) ) {
- $action_links[] = sprintf(
- '
%s ',
- _x( 'Active', 'plugin' )
- );
- } elseif ( current_user_can( 'activate_plugin', $status['file'] ) ) {
- $button_text = __( 'Activate' );
- /* translators: %s: Plugin name. */
- $button_label = _x( 'Activate %s', 'plugin' );
- $activate_url = add_query_arg(
- array(
- '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ),
- 'action' => 'activate',
- 'plugin' => $status['file'],
- ),
- network_admin_url( 'plugins.php' )
- );
-
- if ( is_network_admin() ) {
- $button_text = __( 'Network Activate' );
- /* translators: %s: Plugin name. */
- $button_label = _x( 'Network Activate %s', 'plugin' );
- $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url );
- }
-
- $action_links[] = sprintf(
- '
%3$s ',
- esc_url( $activate_url ),
- esc_attr( sprintf( $button_label, $plugin['name'] ) ),
- $button_text
- );
- } else {
- $action_links[] = sprintf(
- '
%s ',
- _x( 'Installed', 'plugin' )
- );
- }
- break;
- }
- }
-
- $details_link = self_admin_url(
- 'plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] .
- '&TB_iframe=true&width=600&height=550'
- );
-
- $action_links[] = sprintf(
- '
%s ',
- esc_url( $details_link ),
- /* translators: %s: Plugin name and version. */
- esc_attr( sprintf( __( 'More information about %s' ), $name ) ),
- esc_attr( $name ),
- __( 'More Details' )
- );
-
- if ( ! empty( $plugin['icons']['svg'] ) ) {
- $plugin_icon_url = $plugin['icons']['svg'];
- } elseif ( ! empty( $plugin['icons']['2x'] ) ) {
- $plugin_icon_url = $plugin['icons']['2x'];
- } elseif ( ! empty( $plugin['icons']['1x'] ) ) {
- $plugin_icon_url = $plugin['icons']['1x'];
- } else {
- $plugin_icon_url = $plugin['icons']['default'];
- }
-
- /**
- * Filters the install action links for a plugin.
- *
- * @since 2.7.0
- *
- * @param string[] $action_links An array of plugin action links. Defaults are links to Details and Install Now.
- * @param array $plugin The plugin currently being listed.
- */
- $action_links = apply_filters( 'plugin_install_action_links', $action_links, $plugin );
-
- $last_updated_timestamp = strtotime( $plugin['last_updated'] );
- ?>
-
-
';
- if ( ! $compatible_php && ! $compatible_wp ) {
- _e( 'This plugin doesn’t work with your versions of WordPress and PHP.' );
- if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
- printf(
- /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
- ' ' . __( 'Please update WordPress , and then learn more about updating PHP .' ),
- self_admin_url( 'update-core.php' ),
- esc_url( wp_get_update_php_url() )
- );
- wp_update_php_annotation( '
', ' ' );
- } elseif ( current_user_can( 'update_core' ) ) {
- printf(
- /* translators: %s: URL to WordPress Updates screen. */
- ' ' . __( 'Please update WordPress .' ),
- self_admin_url( 'update-core.php' )
- );
- } elseif ( current_user_can( 'update_php' ) ) {
- printf(
- /* translators: %s: URL to Update PHP page. */
- ' ' . __( 'Learn more about updating PHP .' ),
- esc_url( wp_get_update_php_url() )
- );
- wp_update_php_annotation( '
', ' ' );
- }
- } elseif ( ! $compatible_wp ) {
- _e( 'This plugin doesn’t work with your version of WordPress.' );
- if ( current_user_can( 'update_core' ) ) {
- printf(
- /* translators: %s: URL to WordPress Updates screen. */
- ' ' . __( 'Please update WordPress .' ),
- self_admin_url( 'update-core.php' )
- );
- }
- } elseif ( ! $compatible_php ) {
- _e( 'This plugin doesn’t work with your version of PHP.' );
- if ( current_user_can( 'update_php' ) ) {
- printf(
- /* translators: %s: URL to Update PHP page. */
- ' ' . __( 'Learn more about updating PHP .' ),
- esc_url( wp_get_update_php_url() )
- );
- wp_update_php_annotation( '
', ' ' );
- }
- }
- echo '
';
- }
- ?>
-
-
-
-
' . implode( ' ', $action_links ) . ' ';
- }
- ?>
-
-
-
-
-
- $plugin['rating'],
- 'type' => 'percent',
- 'number' => $plugin['num_ratings'],
- )
- );
- ?>
- ()
-
-
-
-
-
-
- = 1000000 ) {
- $active_installs_millions = floor( $plugin['active_installs'] / 1000000 );
- $active_installs_text = sprintf(
- /* translators: %s: Number of millions. */
- _nx( '%s+ Million', '%s+ Million', $active_installs_millions, 'Active plugin installations' ),
- number_format_i18n( $active_installs_millions )
- );
- } elseif ( 0 == $plugin['active_installs'] ) {
- $active_installs_text = _x( 'Less Than 10', 'Active plugin installations' );
- } else {
- $active_installs_text = number_format_i18n( $plugin['active_installs'] ) . '+';
- }
- /* translators: %s: Number of installations. */
- printf( __( '%s Active Installations' ), $active_installs_text );
- ?>
-
-
- ' . __( 'Untested with your version of WordPress' ) . '';
- } elseif ( ! $compatible_wp ) {
- echo '' . __( 'Incompatible with your version of WordPress' ) . ' ';
- } else {
- echo '' . __( 'Compatible with your version of WordPress' ) . ' ';
- }
- ?>
-
-
-
-
';
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-plugins-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-plugins-list-table.php
deleted file mode 100644
index 61cc648..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-plugins-list-table.php
+++ /dev/null
@@ -1,1027 +0,0 @@
- 'plugins',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
-
- $status = 'all';
- if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused' ) ) ) {
- $status = $_REQUEST['plugin_status'];
- }
-
- if ( isset( $_REQUEST['s'] ) ) {
- $_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) );
- }
-
- $page = $this->get_pagenum();
- }
-
- /**
- * @return array
- */
- protected function get_table_classes() {
- return array( 'widefat', $this->_args['plural'] );
- }
-
- /**
- * @return bool
- */
- public function ajax_user_can() {
- return current_user_can( 'activate_plugins' );
- }
-
- /**
- * @global string $status
- * @global array $plugins
- * @global array $totals
- * @global int $page
- * @global string $orderby
- * @global string $order
- * @global string $s
- */
- public function prepare_items() {
- global $status, $plugins, $totals, $page, $orderby, $order, $s;
-
- wp_reset_vars( array( 'orderby', 'order' ) );
-
- /**
- * Filters the full array of plugins to list in the Plugins list table.
- *
- * @since 3.0.0
- *
- * @see get_plugins()
- *
- * @param array $all_plugins An array of plugins to display in the list table.
- */
- $all_plugins = apply_filters( 'all_plugins', get_plugins() );
-
- $plugins = array(
- 'all' => $all_plugins,
- 'search' => array(),
- 'active' => array(),
- 'inactive' => array(),
- 'recently_activated' => array(),
- 'upgrade' => array(),
- 'mustuse' => array(),
- 'dropins' => array(),
- 'paused' => array(),
- );
-
- $screen = $this->screen;
-
- if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) {
-
- /**
- * Filters whether to display the advanced plugins list table.
- *
- * There are two types of advanced plugins - must-use and drop-ins -
- * which can be used in a single site or Multisite network.
- *
- * The $type parameter allows you to differentiate between the type of advanced
- * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'.
- *
- * @since 3.0.0
- *
- * @param bool $show Whether to show the advanced plugins for the specified
- * plugin type. Default true.
- * @param string $type The plugin type. Accepts 'mustuse', 'dropins'.
- */
- if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) {
- $plugins['mustuse'] = get_mu_plugins();
- }
-
- /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */
- if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) {
- $plugins['dropins'] = get_dropins();
- }
-
- if ( current_user_can( 'update_plugins' ) ) {
- $current = get_site_transient( 'update_plugins' );
- foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
- if ( isset( $current->response[ $plugin_file ] ) ) {
- $plugins['all'][ $plugin_file ]['update'] = true;
- $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ];
- }
- }
- }
- }
-
- if ( ! $screen->in_admin( 'network' ) ) {
- $show = current_user_can( 'manage_network_plugins' );
- /**
- * Filters whether to display network-active plugins alongside plugins active for the current site.
- *
- * This also controls the display of inactive network-only plugins (plugins with
- * "Network: true" in the plugin header).
- *
- * Plugins cannot be network-activated or network-deactivated from this screen.
- *
- * @since 4.4.0
- *
- * @param bool $show Whether to show network-active plugins. Default is whether the current
- * user can manage network plugins (ie. a Super Admin).
- */
- $show_network_active = apply_filters( 'show_network_active_plugins', $show );
- }
-
- set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
-
- if ( $screen->in_admin( 'network' ) ) {
- $recently_activated = get_site_option( 'recently_activated', array() );
- } else {
- $recently_activated = get_option( 'recently_activated', array() );
- }
-
- foreach ( $recently_activated as $key => $time ) {
- if ( $time + WEEK_IN_SECONDS < time() ) {
- unset( $recently_activated[ $key ] );
- }
- }
-
- if ( $screen->in_admin( 'network' ) ) {
- update_site_option( 'recently_activated', $recently_activated );
- } else {
- update_option( 'recently_activated', $recently_activated );
- }
-
- $plugin_info = get_site_transient( 'update_plugins' );
-
- foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) {
- // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
- if ( isset( $plugin_info->response[ $plugin_file ] ) ) {
- $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data );
- $plugins['all'][ $plugin_file ] = $plugin_data;
- // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
- if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
- $plugins['upgrade'][ $plugin_file ] = $plugin_data;
- }
- } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) {
- $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data );
- $plugins['all'][ $plugin_file ] = $plugin_data;
- // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade
- if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
- $plugins['upgrade'][ $plugin_file ] = $plugin_data;
- }
- }
-
- // Filter into individual sections
- if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
- if ( $show_network_active ) {
- // On the non-network screen, show inactive network-only plugins if allowed
- $plugins['inactive'][ $plugin_file ] = $plugin_data;
- } else {
- // On the non-network screen, filter out network-only plugins as long as they're not individually active
- unset( $plugins['all'][ $plugin_file ] );
- }
- } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
- if ( $show_network_active ) {
- // On the non-network screen, show network-active plugins if allowed
- $plugins['active'][ $plugin_file ] = $plugin_data;
- } else {
- // On the non-network screen, filter out network-active plugins
- unset( $plugins['all'][ $plugin_file ] );
- }
- } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
- || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
- // On the non-network screen, populate the active list with plugins that are individually activated
- // On the network-admin screen, populate the active list with plugins that are network activated
- $plugins['active'][ $plugin_file ] = $plugin_data;
-
- if ( ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ) ) {
- $plugins['paused'][ $plugin_file ] = $plugin_data;
- }
- } else {
- if ( isset( $recently_activated[ $plugin_file ] ) ) {
- // Populate the recently activated list with plugins that have been recently activated
- $plugins['recently_activated'][ $plugin_file ] = $plugin_data;
- }
- // Populate the inactive list with plugins that aren't activated
- $plugins['inactive'][ $plugin_file ] = $plugin_data;
- }
- }
-
- if ( strlen( $s ) ) {
- $status = 'search';
- $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) );
- }
-
- $totals = array();
- foreach ( $plugins as $type => $list ) {
- $totals[ $type ] = count( $list );
- }
-
- if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) {
- $status = 'all';
- }
-
- $this->items = array();
- foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) {
- // Translate, Don't Apply Markup, Sanitize HTML
- $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true );
- }
-
- $total_this_page = $totals[ $status ];
-
- $js_plugins = array();
- foreach ( $plugins as $key => $list ) {
- $js_plugins[ $key ] = array_keys( (array) $list );
- }
-
- wp_localize_script(
- 'updates',
- '_wpUpdatesItemCounts',
- array(
- 'plugins' => $js_plugins,
- 'totals' => wp_get_update_data(),
- )
- );
-
- if ( ! $orderby ) {
- $orderby = 'Name';
- } else {
- $orderby = ucfirst( $orderby );
- }
-
- $order = strtoupper( $order );
-
- uasort( $this->items, array( $this, '_order_callback' ) );
-
- $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 );
-
- $start = ( $page - 1 ) * $plugins_per_page;
-
- if ( $total_this_page > $plugins_per_page ) {
- $this->items = array_slice( $this->items, $start, $plugins_per_page );
- }
-
- $this->set_pagination_args(
- array(
- 'total_items' => $total_this_page,
- 'per_page' => $plugins_per_page,
- )
- );
- }
-
- /**
- * @global string $s URL encoded search term.
- *
- * @param array $plugin
- * @return bool
- */
- public function _search_callback( $plugin ) {
- global $s;
-
- foreach ( $plugin as $value ) {
- if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * @global string $orderby
- * @global string $order
- * @param array $plugin_a
- * @param array $plugin_b
- * @return int
- */
- public function _order_callback( $plugin_a, $plugin_b ) {
- global $orderby, $order;
-
- $a = $plugin_a[ $orderby ];
- $b = $plugin_b[ $orderby ];
-
- if ( $a == $b ) {
- return 0;
- }
-
- if ( 'DESC' === $order ) {
- return strcasecmp( $b, $a );
- } else {
- return strcasecmp( $a, $b );
- }
- }
-
- /**
- * @global array $plugins
- */
- public function no_items() {
- global $plugins;
-
- if ( ! empty( $_REQUEST['s'] ) ) {
- $s = esc_html( wp_unslash( $_REQUEST['s'] ) );
-
- /* translators: %s: Plugin search term. */
- printf( __( 'No plugins found for “%s”.' ), $s );
-
- // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link.
- if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) {
- echo ' ' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . ' ';
- }
- } elseif ( ! empty( $plugins['all'] ) ) {
- _e( 'No plugins found.' );
- } else {
- _e( 'You do not appear to have any plugins available at this time.' );
- }
- }
-
- /**
- * Displays the search box.
- *
- * @since 4.6.0
- *
- * @param string $text The 'submit' button label.
- * @param string $input_id ID attribute value for the search input field.
- */
- public function search_box( $text, $input_id ) {
- if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
- return;
- }
-
- $input_id = $input_id . '-search-input';
-
- if ( ! empty( $_REQUEST['orderby'] ) ) {
- echo ' ';
- }
- if ( ! empty( $_REQUEST['order'] ) ) {
- echo ' ';
- }
- ?>
-
- :
-
- 'search-submit' ) ); ?>
-
- ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? ' ' : '',
- 'name' => __( 'Plugin' ),
- 'description' => __( 'Description' ),
- );
- }
-
- /**
- * @return array
- */
- protected function get_sortable_columns() {
- return array();
- }
-
- /**
- * @global array $totals
- * @global string $status
- * @return array
- */
- protected function get_views() {
- global $totals, $status;
-
- $status_links = array();
- foreach ( $totals as $type => $count ) {
- if ( ! $count ) {
- continue;
- }
-
- switch ( $type ) {
- case 'all':
- /* translators: %s: Number of plugins. */
- $text = _nx(
- 'All (%s) ',
- 'All (%s) ',
- $count,
- 'plugins'
- );
- break;
- case 'active':
- /* translators: %s: Number of plugins. */
- $text = _n(
- 'Active (%s) ',
- 'Active (%s) ',
- $count
- );
- break;
- case 'recently_activated':
- /* translators: %s: Number of plugins. */
- $text = _n(
- 'Recently Active (%s) ',
- 'Recently Active (%s) ',
- $count
- );
- break;
- case 'inactive':
- /* translators: %s: Number of plugins. */
- $text = _n(
- 'Inactive (%s) ',
- 'Inactive (%s) ',
- $count
- );
- break;
- case 'mustuse':
- /* translators: %s: Number of plugins. */
- $text = _n(
- 'Must-Use (%s) ',
- 'Must-Use (%s) ',
- $count
- );
- break;
- case 'dropins':
- /* translators: %s: Number of plugins. */
- $text = _n(
- 'Drop-in (%s) ',
- 'Drop-ins (%s) ',
- $count
- );
- break;
- case 'paused':
- /* translators: %s: Number of plugins. */
- $text = _n(
- 'Paused (%s) ',
- 'Paused (%s) ',
- $count
- );
- break;
- case 'upgrade':
- /* translators: %s: Number of plugins. */
- $text = _n(
- 'Update Available (%s) ',
- 'Update Available (%s) ',
- $count
- );
- break;
- }
-
- if ( 'search' !== $type ) {
- $status_links[ $type ] = sprintf(
- "%s ",
- add_query_arg( 'plugin_status', $type, 'plugins.php' ),
- ( $type === $status ) ? ' class="current" aria-current="page"' : '',
- sprintf( $text, number_format_i18n( $count ) )
- );
- }
- }
-
- return $status_links;
- }
-
- /**
- * @global string $status
- * @return array
- */
- protected function get_bulk_actions() {
- global $status;
-
- $actions = array();
-
- if ( 'active' != $status ) {
- $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' );
- }
-
- if ( 'inactive' != $status && 'recent' != $status ) {
- $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' );
- }
-
- if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) {
- if ( current_user_can( 'update_plugins' ) ) {
- $actions['update-selected'] = __( 'Update' );
- }
- if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) {
- $actions['delete-selected'] = __( 'Delete' );
- }
- }
-
- return $actions;
- }
-
- /**
- * @global string $status
- * @param string $which
- */
- public function bulk_actions( $which = '' ) {
- global $status;
-
- if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
- return;
- }
-
- parent::bulk_actions( $which );
- }
-
- /**
- * @global string $status
- * @param string $which
- */
- protected function extra_tablenav( $which ) {
- global $status;
-
- if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ) ) ) {
- return;
- }
-
- echo '';
-
- if ( 'recently_activated' == $status ) {
- submit_button( __( 'Clear List' ), '', 'clear-recent-list', false );
- } elseif ( 'top' === $which && 'mustuse' === $status ) {
- echo '
' . sprintf(
- /* translators: %s: mu-plugins directory name. */
- __( 'Files in the %s directory are executed automatically.' ),
- '' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . ''
- ) . '
';
- } elseif ( 'top' === $which && 'dropins' === $status ) {
- echo '
' . sprintf(
- /* translators: %s: wp-content directory name. */
- __( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ),
- '' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . ''
- ) . '
';
- }
- echo '
';
- }
-
- /**
- * @return string
- */
- public function current_action() {
- if ( isset( $_POST['clear-recent-list'] ) ) {
- return 'clear-recent-list';
- }
-
- return parent::current_action();
- }
-
- /**
- * @global string $status
- */
- public function display_rows() {
- global $status;
-
- if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
- return;
- }
-
- foreach ( $this->items as $plugin_file => $plugin_data ) {
- $this->single_row( array( $plugin_file, $plugin_data ) );
- }
- }
-
- /**
- * @global string $status
- * @global int $page
- * @global string $s
- * @global array $totals
- *
- * @param array $item
- */
- public function single_row( $item ) {
- global $status, $page, $s, $totals;
-
- list( $plugin_file, $plugin_data ) = $item;
- $context = $status;
- $screen = $this->screen;
-
- // Pre-order.
- $actions = array(
- 'deactivate' => '',
- 'activate' => '',
- 'details' => '',
- 'delete' => '',
- );
-
- // Do not restrict by default
- $restrict_network_active = false;
- $restrict_network_only = false;
-
- if ( 'mustuse' === $context ) {
- $is_active = true;
- } elseif ( 'dropins' === $context ) {
- $dropins = _get_dropins();
- $plugin_name = $plugin_file;
- if ( $plugin_file != $plugin_data['Name'] ) {
- $plugin_name .= ' ' . $plugin_data['Name'];
- }
- if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
- $is_active = true;
- $description = '' . $dropins[ $plugin_file ][0] . '
';
- } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
- $is_active = true;
- $description = '' . $dropins[ $plugin_file ][0] . '
';
- } else {
- $is_active = false;
- $description = '' . $dropins[ $plugin_file ][0] . ' ' . __( 'Inactive:' ) . ' ' .
- sprintf(
- /* translators: 1: Drop-in constant name, 2: wp-config.php */
- __( 'Requires %1$s in %2$s file.' ),
- "define('" . $dropins[ $plugin_file ][1] . "', true);",
- 'wp-config.php'
- ) . '
';
- }
- if ( $plugin_data['Description'] ) {
- $description .= '' . $plugin_data['Description'] . '
';
- }
- } else {
- if ( $screen->in_admin( 'network' ) ) {
- $is_active = is_plugin_active_for_network( $plugin_file );
- } else {
- $is_active = is_plugin_active( $plugin_file );
- $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
- $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
- }
-
- if ( $screen->in_admin( 'network' ) ) {
- if ( $is_active ) {
- if ( current_user_can( 'manage_network_plugins' ) ) {
- $actions['deactivate'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ),
- /* translators: %s: Plugin name. */
- esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
- __( 'Network Deactivate' )
- );
- }
- } else {
- if ( current_user_can( 'manage_network_plugins' ) ) {
- $actions['activate'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file ),
- /* translators: %s: Plugin name. */
- esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
- __( 'Network Activate' )
- );
- }
- if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) {
- $actions['delete'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ),
- /* translators: %s: Plugin name. */
- esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
- __( 'Delete' )
- );
- }
- }
- } else {
- if ( $restrict_network_active ) {
- $actions = array(
- 'network_active' => __( 'Network Active' ),
- );
- } elseif ( $restrict_network_only ) {
- $actions = array(
- 'network_only' => __( 'Network Only' ),
- );
- } elseif ( $is_active ) {
- if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) {
- $actions['deactivate'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ),
- /* translators: %s: Plugin name. */
- esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ),
- __( 'Deactivate' )
- );
- }
- if ( current_user_can( 'resume_plugin', $plugin_file ) && is_plugin_paused( $plugin_file ) ) {
- $actions['resume'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=resume&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'resume-plugin_' . $plugin_file ),
- /* translators: %s: Plugin name. */
- esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ),
- __( 'Resume' )
- );
- }
- } else {
- if ( current_user_can( 'activate_plugin', $plugin_file ) ) {
- $actions['activate'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file ),
- /* translators: %s: Plugin name. */
- esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ),
- __( 'Activate' )
- );
- }
-
- if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
- $actions['delete'] = sprintf(
- '%s ',
- wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ),
- /* translators: %s: Plugin name. */
- esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ),
- __( 'Delete' )
- );
- }
- } // end if $is_active
- } // end if $screen->in_admin( 'network' )
- } // end if $context
-
- $actions = array_filter( $actions );
-
- if ( $screen->in_admin( 'network' ) ) {
-
- /**
- * Filters the action links displayed for each plugin in the Network Admin Plugins list table.
- *
- * @since 3.1.0
- *
- * @param string[] $actions An array of plugin action links. By default this can include 'activate',
- * 'deactivate', and 'delete'.
- * @param string $plugin_file Path to the plugin file relative to the plugins directory.
- * @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
- * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
- * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
- */
- $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
-
- /**
- * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table.
- *
- * The dynamic portion of the hook name, `$plugin_file`, refers to the path
- * to the plugin file, relative to the plugins directory.
- *
- * @since 3.1.0
- *
- * @param string[] $actions An array of plugin action links. By default this can include 'activate',
- * 'deactivate', and 'delete'.
- * @param string $plugin_file Path to the plugin file relative to the plugins directory.
- * @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
- * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
- * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
- */
- $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
-
- } else {
-
- /**
- * Filters the action links displayed for each plugin in the Plugins list table.
- *
- * @since 2.5.0
- * @since 2.6.0 The `$context` parameter was added.
- * @since 4.9.0 The 'Edit' link was removed from the list of action links.
- *
- * @param string[] $actions An array of plugin action links. By default this can include 'activate',
- * 'deactivate', and 'delete'. With Multisite active this can also include
- * 'network_active' and 'network_only' items.
- * @param string $plugin_file Path to the plugin file relative to the plugins directory.
- * @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
- * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
- * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
- */
- $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
-
- /**
- * Filters the list of action links displayed for a specific plugin in the Plugins list table.
- *
- * The dynamic portion of the hook name, `$plugin_file`, refers to the path
- * to the plugin file, relative to the plugins directory.
- *
- * @since 2.7.0
- * @since 4.9.0 The 'Edit' link was removed from the list of action links.
- *
- * @param string[] $actions An array of plugin action links. By default this can include 'activate',
- * 'deactivate', and 'delete'. With Multisite active this can also include
- * 'network_active' and 'network_only' items.
- * @param string $plugin_file Path to the plugin file relative to the plugins directory.
- * @param array $plugin_data An array of plugin data. See `get_plugin_data()`.
- * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive',
- * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'.
- */
- $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context );
-
- }
-
- $requires_php = isset( $plugin_data['requires_php'] ) ? $plugin_data['requires_php'] : null;
- $compatible_php = is_php_version_compatible( $requires_php );
- $class = $is_active ? 'active' : 'inactive';
- $checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
- if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) || ! $compatible_php ) {
- $checkbox = '';
- } else {
- $checkbox = sprintf(
- '%2$s ' .
- ' ',
- $checkbox_id,
- /* translators: %s: Plugin name. */
- sprintf( __( 'Select %s' ), $plugin_data['Name'] ),
- esc_attr( $plugin_file )
- );
- }
- if ( 'dropins' != $context ) {
- $description = '' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '
';
- $plugin_name = $plugin_data['Name'];
- }
-
- if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) {
- $class .= ' update';
- }
-
- $paused = ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file );
-
- if ( $paused ) {
- $class .= ' paused';
- }
-
- $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_name );
- printf(
- '',
- esc_attr( $class ),
- esc_attr( $plugin_slug ),
- esc_attr( $plugin_file )
- );
-
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
-
- foreach ( $columns as $column_name => $column_display_name ) {
- $extra_classes = '';
- if ( in_array( $column_name, $hidden ) ) {
- $extra_classes = ' hidden';
- }
-
- switch ( $column_name ) {
- case 'cb':
- echo "$checkbox ";
- break;
- case 'name':
- echo "$plugin_name ";
- echo $this->row_actions( $actions, true );
- echo ' ';
- break;
- case 'description':
- $classes = 'column-description desc';
-
- echo "';
- break;
- default:
- $classes = "$column_name column-$column_name $class";
-
- echo "';
- }
- }
-
- echo ' ';
-
- /**
- * Fires after each row in the Plugins list table.
- *
- * @since 2.3.0
- *
- * @param string $plugin_file Path to the plugin file relative to the plugins directory.
- * @param array $plugin_data An array of plugin data.
- * @param string $status Status of the plugin. Defaults are 'All', 'Active',
- * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
- * 'Drop-ins', 'Search', 'Paused'.
- */
- do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
-
- /**
- * Fires after each specific row in the Plugins list table.
- *
- * The dynamic portion of the hook name, `$plugin_file`, refers to the path
- * to the plugin file, relative to the plugins directory.
- *
- * @since 2.7.0
- *
- * @param string $plugin_file Path to the plugin file relative to the plugins directory.
- * @param array $plugin_data An array of plugin data.
- * @param string $status Status of the plugin. Defaults are 'All', 'Active',
- * 'Inactive', 'Recently Activated', 'Upgrade', 'Must-Use',
- * 'Drop-ins', 'Search', 'Paused'.
- */
- do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status );
- }
-
- /**
- * Gets the name of the primary column for this specific list table.
- *
- * @since 4.3.0
- *
- * @return string Unalterable name for the primary column, in this case, 'name'.
- */
- protected function get_primary_column_name() {
- return 'name';
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-post-comments-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-post-comments-list-table.php
deleted file mode 100644
index 29dc286..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-post-comments-list-table.php
+++ /dev/null
@@ -1,78 +0,0 @@
- __( 'Author' ),
- 'comment' => _x( 'Comment', 'column name' ),
- ),
- array(),
- array(),
- 'comment',
- );
- }
-
- /**
- * @return array
- */
- protected function get_table_classes() {
- $classes = parent::get_table_classes();
- $classes[] = 'wp-list-table';
- $classes[] = 'comments-box';
- return $classes;
- }
-
- /**
- * @param bool $output_empty
- */
- public function display( $output_empty = false ) {
- $singular = $this->_args['singular'];
-
- wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
- ?>
-
- 'posts',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
-
- $post_type = $this->screen->post_type;
- $post_type_object = get_post_type_object( $post_type );
-
- $exclude_states = get_post_stati(
- array(
- 'show_in_admin_all_list' => false,
- )
- );
- $this->user_posts_count = intval(
- $wpdb->get_var(
- $wpdb->prepare(
- "
- SELECT COUNT( 1 )
- FROM $wpdb->posts
- WHERE post_type = %s
- AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
- AND post_author = %d
- ",
- $post_type,
- get_current_user_id()
- )
- )
- );
-
- if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
- $_GET['author'] = get_current_user_id();
- }
-
- $sticky_posts = get_option( 'sticky_posts' );
- if ( 'post' === $post_type && $sticky_posts ) {
- $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
- $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
- }
- }
-
- /**
- * Sets whether the table layout should be hierarchical or not.
- *
- * @since 4.2.0
- *
- * @param bool $display Whether the table layout should be hierarchical.
- */
- public function set_hierarchical_display( $display ) {
- $this->hierarchical_display = $display;
- }
-
- /**
- * @return bool
- */
- public function ajax_user_can() {
- return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
- }
-
- /**
- * @global array $avail_post_stati
- * @global WP_Query $wp_query WordPress Query object.
- * @global int $per_page
- * @global string $mode
- */
- public function prepare_items() {
- global $avail_post_stati, $wp_query, $per_page, $mode;
-
- // is going to call wp()
- $avail_post_stati = wp_edit_posts_query();
-
- $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
-
- $post_type = $this->screen->post_type;
- $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
-
- /** This filter is documented in wp-admin/includes/post.php */
- $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
-
- if ( $this->hierarchical_display ) {
- $total_items = $wp_query->post_count;
- } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
- $total_items = $wp_query->found_posts;
- } else {
- $post_counts = (array) wp_count_posts( $post_type, 'readable' );
-
- if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati ) ) {
- $total_items = $post_counts[ $_REQUEST['post_status'] ];
- } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
- $total_items = $this->sticky_posts_count;
- } elseif ( isset( $_GET['author'] ) && $_GET['author'] == get_current_user_id() ) {
- $total_items = $this->user_posts_count;
- } else {
- $total_items = array_sum( $post_counts );
-
- // Subtract post types that are not included in the admin all list.
- foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
- $total_items -= $post_counts[ $state ];
- }
- }
- }
-
- if ( ! empty( $_REQUEST['mode'] ) ) {
- $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
- set_user_setting( 'posts_list_mode', $mode );
- } else {
- $mode = get_user_setting( 'posts_list_mode', 'list' );
- }
-
- $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash';
-
- $this->set_pagination_args(
- array(
- 'total_items' => $total_items,
- 'per_page' => $per_page,
- )
- );
- }
-
- /**
- * @return bool
- */
- public function has_items() {
- return have_posts();
- }
-
- /**
- */
- public function no_items() {
- if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
- echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
- } else {
- echo get_post_type_object( $this->screen->post_type )->labels->not_found;
- }
- }
-
- /**
- * Determine if the current view is the "All" view.
- *
- * @since 4.2.0
- *
- * @return bool Whether the current view is the "All" view.
- */
- protected function is_base_request() {
- $vars = $_GET;
- unset( $vars['paged'] );
-
- if ( empty( $vars ) ) {
- return true;
- } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) {
- return $this->screen->post_type === $vars['post_type'];
- }
-
- return 1 === count( $vars ) && ! empty( $vars['mode'] );
- }
-
- /**
- * Helper to create links to edit.php with params.
- *
- * @since 4.4.0
- *
- * @param string[] $args Associative array of URL parameters for the link.
- * @param string $label Link text.
- * @param string $class Optional. Class attribute. Default empty string.
- * @return string The formatted link string.
- */
- protected function get_edit_link( $args, $label, $class = '' ) {
- $url = add_query_arg( $args, 'edit.php' );
-
- $class_html = '';
- $aria_current = '';
- if ( ! empty( $class ) ) {
- $class_html = sprintf(
- ' class="%s"',
- esc_attr( $class )
- );
-
- if ( 'current' === $class ) {
- $aria_current = ' aria-current="page"';
- }
- }
-
- return sprintf(
- '%s ',
- esc_url( $url ),
- $class_html,
- $aria_current,
- $label
- );
- }
-
- /**
- * @global array $locked_post_status This seems to be deprecated.
- * @global array $avail_post_stati
- * @return array
- */
- protected function get_views() {
- global $locked_post_status, $avail_post_stati;
-
- $post_type = $this->screen->post_type;
-
- if ( ! empty( $locked_post_status ) ) {
- return array();
- }
-
- $status_links = array();
- $num_posts = wp_count_posts( $post_type, 'readable' );
- $total_posts = array_sum( (array) $num_posts );
- $class = '';
-
- $current_user_id = get_current_user_id();
- $all_args = array( 'post_type' => $post_type );
- $mine = '';
-
- // Subtract post types that are not included in the admin all list.
- foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
- $total_posts -= $num_posts->$state;
- }
-
- if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
- if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
- $class = 'current';
- }
-
- $mine_args = array(
- 'post_type' => $post_type,
- 'author' => $current_user_id,
- );
-
- $mine_inner_html = sprintf(
- /* translators: %s: Number of posts. */
- _nx(
- 'Mine (%s) ',
- 'Mine (%s) ',
- $this->user_posts_count,
- 'posts'
- ),
- number_format_i18n( $this->user_posts_count )
- );
-
- $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
-
- $all_args['all_posts'] = 1;
- $class = '';
- }
-
- if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
- $class = 'current';
- }
-
- $all_inner_html = sprintf(
- /* translators: %s: Number of posts. */
- _nx(
- 'All (%s) ',
- 'All (%s) ',
- $total_posts,
- 'posts'
- ),
- number_format_i18n( $total_posts )
- );
-
- $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
- if ( $mine ) {
- $status_links['mine'] = $mine;
- }
-
- foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) {
- $class = '';
-
- $status_name = $status->name;
-
- if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) {
- continue;
- }
-
- if ( isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'] ) {
- $class = 'current';
- }
-
- $status_args = array(
- 'post_status' => $status_name,
- 'post_type' => $post_type,
- );
-
- $status_label = sprintf(
- translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
- number_format_i18n( $num_posts->$status_name )
- );
-
- $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
- }
-
- if ( ! empty( $this->sticky_posts_count ) ) {
- $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
-
- $sticky_args = array(
- 'post_type' => $post_type,
- 'show_sticky' => 1,
- );
-
- $sticky_inner_html = sprintf(
- /* translators: %s: Number of posts. */
- _nx(
- 'Sticky (%s) ',
- 'Sticky (%s) ',
- $this->sticky_posts_count,
- 'posts'
- ),
- number_format_i18n( $this->sticky_posts_count )
- );
-
- $sticky_link = array(
- 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ),
- );
-
- // Sticky comes after Publish, or if not listed, after All.
- $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
- $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
- }
-
- return $status_links;
- }
-
- /**
- * @return array
- */
- protected function get_bulk_actions() {
- $actions = array();
- $post_type_obj = get_post_type_object( $this->screen->post_type );
-
- if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
- if ( $this->is_trash ) {
- $actions['untrash'] = __( 'Restore' );
- } else {
- $actions['edit'] = __( 'Edit' );
- }
- }
-
- if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
- if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = __( 'Delete Permanently' );
- } else {
- $actions['trash'] = __( 'Move to Trash' );
- }
- }
-
- return $actions;
- }
-
- /**
- * Displays a categories drop-down for filtering on the Posts list table.
- *
- * @since 4.6.0
- *
- * @global int $cat Currently selected category.
- *
- * @param string $post_type Post type slug.
- */
- protected function categories_dropdown( $post_type ) {
- global $cat;
-
- /**
- * Filters whether to remove the 'Categories' drop-down from the post list table.
- *
- * @since 4.6.0
- *
- * @param bool $disable Whether to disable the categories drop-down. Default false.
- * @param string $post_type Post type slug.
- */
- if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
- return;
- }
-
- if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
- $dropdown_options = array(
- 'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
- 'hide_empty' => 0,
- 'hierarchical' => 1,
- 'show_count' => 0,
- 'orderby' => 'name',
- 'selected' => $cat,
- );
-
- echo '' . __( 'Filter by category' ) . ' ';
- wp_dropdown_categories( $dropdown_options );
- }
- }
-
- /**
- * Displays a formats drop-down for filtering items.
- *
- * @since 5.2.0
- * @access protected
- *
- * @param string $post_type Post type key.
- */
- protected function formats_dropdown( $post_type ) {
- /**
- * Filters whether to remove the 'Formats' drop-down from the post list table.
- *
- * @since 5.2.0
- *
- * @param bool $disable Whether to disable the drop-down. Default false.
- */
- if ( apply_filters( 'disable_formats_dropdown', false ) ) {
- return;
- }
-
- // Make sure the dropdown shows only formats with a post count greater than 0.
- $used_post_formats = get_terms(
- array(
- 'taxonomy' => 'post_format',
- 'hide_empty' => true,
- )
- );
-
- /*
- * Return if the post type doesn't have post formats, or there are no posts using formats,
- * or if we're in the trash.
- */
- if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || ! $used_post_formats || $this->is_trash ) {
- return;
- }
-
- $displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
- ?>
-
-
- value="">
- slug );
- // Pretty, translated version of the post format slug.
- $pretty_name = get_post_format_string( $slug );
- // Skip the standard post format.
- if ( 'standard' === $slug ) {
- continue;
- }
- ?>
- value="">
-
-
-
-
- months_dropdown( $this->screen->post_type );
- $this->categories_dropdown( $this->screen->post_type );
- $this->formats_dropdown( $this->screen->post_type );
-
- /**
- * Fires before the Filter button on the Posts and Pages list tables.
- *
- * The Filter button allows sorting by date and/or category on the
- * Posts list table, and sorting by date on the Pages list table.
- *
- * @since 2.1.0
- * @since 4.4.0 The `$post_type` parameter was added.
- * @since 4.6.0 The `$which` parameter was added.
- *
- * @param string $post_type The post type slug.
- * @param string $which The location of the extra table nav markup:
- * 'top' or 'bottom' for WP_Posts_List_Table,
- * 'bar' for WP_Media_List_Table.
- */
- do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
-
- $output = ob_get_clean();
-
- if ( ! empty( $output ) ) {
- echo $output;
- submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
- }
- }
-
- if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) {
- submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
- }
- ?>
-
- screen->post_type ) ? 'pages' : 'posts' );
- }
-
- /**
- * @return array
- */
- public function get_columns() {
- $post_type = $this->screen->post_type;
-
- $posts_columns = array();
-
- $posts_columns['cb'] = ' ';
-
- /* translators: Posts screen column name. */
- $posts_columns['title'] = _x( 'Title', 'column name' );
-
- if ( post_type_supports( $post_type, 'author' ) ) {
- $posts_columns['author'] = __( 'Author' );
- }
-
- $taxonomies = get_object_taxonomies( $post_type, 'objects' );
- $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
-
- /**
- * Filters the taxonomy columns in the Posts list table.
- *
- * The dynamic portion of the hook name, `$post_type`, refers to the post
- * type slug.
- *
- * @since 3.5.0
- *
- * @param string[] $taxonomies Array of taxonomy names to show columns for.
- * @param string $post_type The post type.
- */
- $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
- $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
-
- foreach ( $taxonomies as $taxonomy ) {
- if ( 'category' === $taxonomy ) {
- $column_key = 'categories';
- } elseif ( 'post_tag' === $taxonomy ) {
- $column_key = 'tags';
- } else {
- $column_key = 'taxonomy-' . $taxonomy;
- }
-
- $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
- }
-
- $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
- if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) {
- $posts_columns['comments'] = '';
- }
-
- $posts_columns['date'] = __( 'Date' );
-
- if ( 'page' === $post_type ) {
-
- /**
- * Filters the columns displayed in the Pages list table.
- *
- * @since 2.5.0
- *
- * @param string[] $post_columns An associative array of column headings.
- */
- $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
- } else {
-
- /**
- * Filters the columns displayed in the Posts list table.
- *
- * @since 1.5.0
- *
- * @param string[] $post_columns An associative array of column headings.
- * @param string $post_type The post type slug.
- */
- $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
- }
-
- /**
- * Filters the columns displayed in the Posts list table for a specific post type.
- *
- * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
- *
- * @since 3.0.0
- *
- * @param string[] $post_columns An associative array of column headings.
- */
- return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
- }
-
- /**
- * @return array
- */
- protected function get_sortable_columns() {
- return array(
- 'title' => 'title',
- 'parent' => 'parent',
- 'comments' => 'comment_count',
- 'date' => array( 'date', true ),
- );
- }
-
- /**
- * @global WP_Query $wp_query WordPress Query object.
- * @global int $per_page
- * @param array $posts
- * @param int $level
- */
- public function display_rows( $posts = array(), $level = 0 ) {
- global $wp_query, $per_page;
-
- if ( empty( $posts ) ) {
- $posts = $wp_query->posts;
- }
-
- add_filter( 'the_title', 'esc_html' );
-
- if ( $this->hierarchical_display ) {
- $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
- } else {
- $this->_display_rows( $posts, $level );
- }
- }
-
- /**
- * @param array $posts
- * @param int $level
- */
- private function _display_rows( $posts, $level = 0 ) {
- $post_type = $this->screen->post_type;
-
- // Create array of post IDs.
- $post_ids = array();
-
- foreach ( $posts as $a_post ) {
- $post_ids[] = $a_post->ID;
- }
-
- if ( post_type_supports( $post_type, 'comments' ) ) {
- $this->comment_pending_count = get_pending_comments_num( $post_ids );
- }
-
- foreach ( $posts as $post ) {
- $this->single_row( $post, $level );
- }
- }
-
- /**
- * @global wpdb $wpdb WordPress database abstraction object.
- * @global WP_Post $post Global post object.
- * @param array $pages
- * @param int $pagenum
- * @param int $per_page
- */
- private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
- global $wpdb;
-
- $level = 0;
-
- if ( ! $pages ) {
- $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
-
- if ( ! $pages ) {
- return;
- }
- }
-
- /*
- * Arrange pages into two parts: top level pages and children_pages
- * children_pages is two dimensional array, eg.
- * children_pages[10][] contains all sub-pages whose parent is 10.
- * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
- * If searching, ignore hierarchy and treat everything as top level
- */
- if ( empty( $_REQUEST['s'] ) ) {
-
- $top_level_pages = array();
- $children_pages = array();
-
- foreach ( $pages as $page ) {
-
- // Catch and repair bad pages.
- if ( $page->post_parent == $page->ID ) {
- $page->post_parent = 0;
- $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
- clean_post_cache( $page );
- }
-
- if ( 0 == $page->post_parent ) {
- $top_level_pages[] = $page;
- } else {
- $children_pages[ $page->post_parent ][] = $page;
- }
- }
-
- $pages = &$top_level_pages;
- }
-
- $count = 0;
- $start = ( $pagenum - 1 ) * $per_page;
- $end = $start + $per_page;
- $to_display = array();
-
- foreach ( $pages as $page ) {
- if ( $count >= $end ) {
- break;
- }
-
- if ( $count >= $start ) {
- $to_display[ $page->ID ] = $level;
- }
-
- $count++;
-
- if ( isset( $children_pages ) ) {
- $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
- }
- }
-
- // If it is the last pagenum and there are orphaned pages, display them with paging as well.
- if ( isset( $children_pages ) && $count < $end ) {
- foreach ( $children_pages as $orphans ) {
- foreach ( $orphans as $op ) {
- if ( $count >= $end ) {
- break;
- }
-
- if ( $count >= $start ) {
- $to_display[ $op->ID ] = 0;
- }
-
- $count++;
- }
- }
- }
-
- $ids = array_keys( $to_display );
- _prime_post_caches( $ids );
-
- if ( ! isset( $GLOBALS['post'] ) ) {
- $GLOBALS['post'] = reset( $ids );
- }
-
- foreach ( $to_display as $page_id => $level ) {
- echo "\t";
- $this->single_row( $page_id, $level );
- }
- }
-
- /**
- * Given a top level page ID, display the nested hierarchy of sub-pages
- * together with paging support
- *
- * @since 3.1.0 (Standalone function exists since 2.6.0)
- * @since 4.2.0 Added the `$to_display` parameter.
- *
- * @param array $children_pages
- * @param int $count
- * @param int $parent
- * @param int $level
- * @param int $pagenum
- * @param int $per_page
- * @param array $to_display List of pages to be displayed. Passed by reference.
- */
- private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
- if ( ! isset( $children_pages[ $parent ] ) ) {
- return;
- }
-
- $start = ( $pagenum - 1 ) * $per_page;
- $end = $start + $per_page;
-
- foreach ( $children_pages[ $parent ] as $page ) {
- if ( $count >= $end ) {
- break;
- }
-
- // If the page starts in a subtree, print the parents.
- if ( $count == $start && $page->post_parent > 0 ) {
- $my_parents = array();
- $my_parent = $page->post_parent;
- while ( $my_parent ) {
- // Get the ID from the list or the attribute if my_parent is an object
- $parent_id = $my_parent;
- if ( is_object( $my_parent ) ) {
- $parent_id = $my_parent->ID;
- }
-
- $my_parent = get_post( $parent_id );
- $my_parents[] = $my_parent;
- if ( ! $my_parent->post_parent ) {
- break;
- }
- $my_parent = $my_parent->post_parent;
- }
- $num_parents = count( $my_parents );
- while ( $my_parent = array_pop( $my_parents ) ) {
- $to_display[ $my_parent->ID ] = $level - $num_parents;
- $num_parents--;
- }
- }
-
- if ( $count >= $start ) {
- $to_display[ $page->ID ] = $level;
- }
-
- $count++;
-
- $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
- }
-
- unset( $children_pages[ $parent ] ); //required in order to keep track of orphans
- }
-
- /**
- * Handles the checkbox column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_cb( $post ) {
- if ( current_user_can( 'edit_post', $post->ID ) ) :
- ?>
-
-
-
-
-
-
-
-
-
-
- ';
- echo $this->column_title( $post );
- echo $this->handle_row_actions( $post, 'title', $primary );
- echo '';
- }
-
- /**
- * Handles the title column output.
- *
- * @since 4.3.0
- *
- * @global string $mode List table view mode.
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_title( $post ) {
- global $mode;
-
- if ( $this->hierarchical_display ) {
- if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
- // Sent level 0 by accident, by default, or because we don't know the actual level.
- $find_main_page = (int) $post->post_parent;
- while ( $find_main_page > 0 ) {
- $parent = get_post( $find_main_page );
-
- if ( is_null( $parent ) ) {
- break;
- }
-
- $this->current_level++;
- $find_main_page = (int) $parent->post_parent;
-
- if ( ! isset( $parent_name ) ) {
- /** This filter is documented in wp-includes/post-template.php */
- $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
- }
- }
- }
- }
-
- $can_edit_post = current_user_can( 'edit_post', $post->ID );
-
- if ( $can_edit_post && $post->post_status != 'trash' ) {
- $lock_holder = wp_check_post_lock( $post->ID );
-
- if ( $lock_holder ) {
- $lock_holder = get_userdata( $lock_holder );
- $locked_avatar = get_avatar( $lock_holder->ID, 18 );
- /* translators: %s: User's display name. */
- $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
- } else {
- $locked_avatar = '';
- $locked_text = '';
- }
-
- echo '' . $locked_avatar . ' ' . $locked_text . "
\n";
- }
-
- $pad = str_repeat( '— ', $this->current_level );
- echo '';
-
- $title = _draft_or_post_title();
-
- if ( $can_edit_post && $post->post_status != 'trash' ) {
- printf(
- '%s%s ',
- get_edit_post_link( $post->ID ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( '“%s” (Edit)' ), $title ) ),
- $pad,
- $title
- );
- } else {
- printf(
- '%s%s ',
- $pad,
- $title
- );
- }
- _post_states( $post );
-
- if ( isset( $parent_name ) ) {
- $post_type_object = get_post_type_object( $post->post_type );
- echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
- }
- echo " \n";
-
- if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
- if ( post_password_required( $post ) ) {
- echo '' . esc_html( get_the_excerpt() ) . ' ';
- } else {
- echo esc_html( get_the_excerpt() );
- }
- }
-
- get_inline_data( $post );
- }
-
- /**
- * Handles the post date column output.
- *
- * @since 4.3.0
- *
- * @global string $mode List table view mode.
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_date( $post ) {
- global $mode;
-
- if ( '0000-00-00 00:00:00' === $post->post_date ) {
- $t_time = __( 'Unpublished' );
- $h_time = $t_time;
- $time_diff = 0;
- } else {
- $t_time = get_the_time( __( 'Y/m/d g:i:s a' ), $post );
- $time = get_post_timestamp( $post );
- $time_diff = time() - $time;
-
- if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
- /* translators: %s: Human-readable time difference. */
- $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
- } else {
- $h_time = get_the_time( __( 'Y/m/d' ), $post );
- }
- }
-
- if ( 'publish' === $post->post_status ) {
- $status = __( 'Published' );
- } elseif ( 'future' === $post->post_status ) {
- if ( $time_diff > 0 ) {
- $status = '' . __( 'Missed schedule' ) . ' ';
- } else {
- $status = __( 'Scheduled' );
- }
- } else {
- $status = __( 'Last Modified' );
- }
-
- /**
- * Filters the status text of the post.
- *
- * @since 4.8.0
- *
- * @param string $status The status text.
- * @param WP_Post $post Post object.
- * @param string $column_name The column name.
- * @param string $mode The list display mode ('excerpt' or 'list').
- */
- $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
-
- if ( $status ) {
- echo $status . ' ';
- }
-
- if ( 'excerpt' === $mode ) {
- /**
- * Filters the published time of the post.
- *
- * If `$mode` equals 'excerpt', the published time and date are both displayed.
- * If `$mode` equals 'list' (default), the publish date is displayed, with the
- * time and date together available as an abbreviation definition.
- *
- * @since 2.5.1
- *
- * @param string $t_time The published time.
- * @param WP_Post $post Post object.
- * @param string $column_name The column name.
- * @param string $mode The list display mode ('excerpt' or 'list').
- */
- echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
- } else {
-
- /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
- echo '' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . ' ';
- }
- }
-
- /**
- * Handles the comments column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- */
- public function column_comments( $post ) {
- ?>
-
- comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
-
- $this->comments_bubble( $post->ID, $pending_comments );
- ?>
-
- $post->post_type,
- 'author' => get_the_author_meta( 'ID' ),
- );
- echo $this->get_edit_link( $args, get_the_author() );
- }
-
- /**
- * Handles the default column output.
- *
- * @since 4.3.0
- *
- * @param WP_Post $post The current WP_Post object.
- * @param string $column_name The current column name.
- */
- public function column_default( $post, $column_name ) {
- if ( 'categories' === $column_name ) {
- $taxonomy = 'category';
- } elseif ( 'tags' === $column_name ) {
- $taxonomy = 'post_tag';
- } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
- $taxonomy = substr( $column_name, 9 );
- } else {
- $taxonomy = false;
- }
- if ( $taxonomy ) {
- $taxonomy_object = get_taxonomy( $taxonomy );
- $terms = get_the_terms( $post->ID, $taxonomy );
- if ( is_array( $terms ) ) {
- $term_links = array();
- foreach ( $terms as $t ) {
- $posts_in_term_qv = array();
- if ( 'post' != $post->post_type ) {
- $posts_in_term_qv['post_type'] = $post->post_type;
- }
- if ( $taxonomy_object->query_var ) {
- $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
- } else {
- $posts_in_term_qv['taxonomy'] = $taxonomy;
- $posts_in_term_qv['term'] = $t->slug;
- }
-
- $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
-
- $term_links[] = $this->get_edit_link( $posts_in_term_qv, $label );
- }
-
- /**
- * Filters the links in `$taxonomy` column of edit.php.
- *
- * @since 5.2.0
- *
- * @param array $term_links List of links to edit.php, filtered by the taxonomy term.
- * @param string $taxonomy Taxonomy name.
- * @param array $terms Array of terms appearing in the post row.
- */
- $term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
-
- /* translators: Used between list items, there is a space after the comma. */
- echo join( __( ', ' ), $term_links );
- } else {
- echo '— ' . $taxonomy_object->labels->no_terms . ' ';
- }
- return;
- }
-
- if ( is_post_type_hierarchical( $post->post_type ) ) {
-
- /**
- * Fires in each custom column on the Posts list table.
- *
- * This hook only fires if the current post type is hierarchical,
- * such as pages.
- *
- * @since 2.5.0
- *
- * @param string $column_name The name of the column to display.
- * @param int $post_id The current post ID.
- */
- do_action( 'manage_pages_custom_column', $column_name, $post->ID );
- } else {
-
- /**
- * Fires in each custom column in the Posts list table.
- *
- * This hook only fires if the current post type is non-hierarchical,
- * such as posts.
- *
- * @since 1.5.0
- *
- * @param string $column_name The name of the column to display.
- * @param int $post_id The current post ID.
- */
- do_action( 'manage_posts_custom_column', $column_name, $post->ID );
- }
-
- /**
- * Fires for each custom column of a specific post type in the Posts list table.
- *
- * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
- *
- * @since 3.1.0
- *
- * @param string $column_name The name of the column to display.
- * @param int $post_id The current post ID.
- */
- do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
- }
-
- /**
- * @global WP_Post $post Global post object.
- *
- * @param int|WP_Post $post
- * @param int $level
- */
- public function single_row( $post, $level = 0 ) {
- $global_post = get_post();
-
- $post = get_post( $post );
- $this->current_level = $level;
-
- $GLOBALS['post'] = $post;
- setup_postdata( $post );
-
- $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
-
- $lock_holder = wp_check_post_lock( $post->ID );
- if ( $lock_holder ) {
- $classes .= ' wp-locked';
- }
-
- if ( $post->post_parent ) {
- $count = count( get_post_ancestors( $post->ID ) );
- $classes .= ' level-' . $count;
- } else {
- $classes .= ' level-0';
- }
- ?>
-
- single_row_columns( $post ); ?>
-
- post_type );
- $can_edit_post = current_user_can( 'edit_post', $post->ID );
- $actions = array();
- $title = _draft_or_post_title();
-
- if ( $can_edit_post && 'trash' != $post->post_status ) {
- $actions['edit'] = sprintf(
- '%s ',
- get_edit_post_link( $post->ID ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ),
- __( 'Edit' )
- );
-
- if ( 'wp_block' !== $post->post_type ) {
- $actions['inline hide-if-no-js'] = sprintf(
- '%s ',
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $title ) ),
- __( 'Quick Edit' )
- );
- }
- }
-
- if ( current_user_can( 'delete_post', $post->ID ) ) {
- if ( 'trash' === $post->post_status ) {
- $actions['untrash'] = sprintf(
- '%s ',
- wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Restore “%s” from the Trash' ), $title ) ),
- __( 'Restore' )
- );
- } elseif ( EMPTY_TRASH_DAYS ) {
- $actions['trash'] = sprintf(
- '%s ',
- get_delete_post_link( $post->ID ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Move “%s” to the Trash' ), $title ) ),
- _x( 'Trash', 'verb' )
- );
- }
- if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = sprintf(
- '%s ',
- get_delete_post_link( $post->ID, '', true ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Delete “%s” permanently' ), $title ) ),
- __( 'Delete Permanently' )
- );
- }
- }
-
- if ( is_post_type_viewable( $post_type_object ) ) {
- if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
- if ( $can_edit_post ) {
- $preview_link = get_preview_post_link( $post );
- $actions['view'] = sprintf(
- '%s ',
- esc_url( $preview_link ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ),
- __( 'Preview' )
- );
- }
- } elseif ( 'trash' != $post->post_status ) {
- $actions['view'] = sprintf(
- '%s ',
- get_permalink( $post->ID ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'View “%s”' ), $title ) ),
- __( 'View' )
- );
- }
- }
-
- if ( 'wp_block' === $post->post_type ) {
- $actions['export'] = sprintf(
- '%s ',
- $post->ID,
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Export “%s” as JSON' ), $title ) ),
- __( 'Export as JSON' )
- );
- }
-
- if ( is_post_type_hierarchical( $post->post_type ) ) {
-
- /**
- * Filters the array of row action links on the Pages list table.
- *
- * The filter is evaluated only for hierarchical post types.
- *
- * @since 2.8.0
- *
- * @param string[] $actions An array of row action links. Defaults are
- * 'Edit', 'Quick Edit', 'Restore', 'Trash',
- * 'Delete Permanently', 'Preview', and 'View'.
- * @param WP_Post $post The post object.
- */
- $actions = apply_filters( 'page_row_actions', $actions, $post );
- } else {
-
- /**
- * Filters the array of row action links on the Posts list table.
- *
- * The filter is evaluated only for non-hierarchical post types.
- *
- * @since 2.8.0
- *
- * @param string[] $actions An array of row action links. Defaults are
- * 'Edit', 'Quick Edit', 'Restore', 'Trash',
- * 'Delete Permanently', 'Preview', and 'View'.
- * @param WP_Post $post The post object.
- */
- $actions = apply_filters( 'post_row_actions', $actions, $post );
- }
-
- return $this->row_actions( $actions );
- }
-
- /**
- * Outputs the hidden row displayed when inline editing
- *
- * @since 3.1.0
- *
- * @global string $mode List table view mode.
- */
- public function inline_edit() {
- global $mode;
-
- $screen = $this->screen;
-
- $post = get_default_post_to_edit( $screen->post_type );
- $post_type_object = get_post_type_object( $screen->post_type );
-
- $taxonomy_names = get_object_taxonomies( $screen->post_type );
- $hierarchical_taxonomies = array();
- $flat_taxonomies = array();
- foreach ( $taxonomy_names as $taxonomy_name ) {
-
- $taxonomy = get_taxonomy( $taxonomy_name );
-
- $show_in_quick_edit = $taxonomy->show_in_quick_edit;
-
- /**
- * Filters whether the current taxonomy should be shown in the Quick Edit panel.
- *
- * @since 4.2.0
- *
- * @param bool $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
- * @param string $taxonomy_name Taxonomy name.
- * @param string $post_type Post type of current Quick Edit post.
- */
- if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
- continue;
- }
-
- if ( $taxonomy->hierarchical ) {
- $hierarchical_taxonomies[] = $taxonomy;
- } else {
- $flat_taxonomies[] = $taxonomy;
- }
- }
-
- $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
- $can_publish = current_user_can( $post_type_object->cap->publish_posts );
- $core_columns = array(
- 'cb' => true,
- 'date' => true,
- 'title' => true,
- 'categories' => true,
- 'tags' => true,
- 'comments' => true,
- 'author' => true,
- );
-
- ?>
-
-
- ID;
- $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
-
- $download_data_markup = '';
-
- $download_data_markup .= '' . __( 'Download Personal Data' ) . ' ' .
- '' . __( 'Downloading Data...' ) . ' ' .
- '' . __( 'Download Personal Data Again' ) . ' ' .
- '' . __( 'Download failed.' ) . ' ' . __( 'Retry' ) . ' ';
-
- $download_data_markup .= '
';
-
- $row_actions = array(
- 'download-data' => $download_data_markup,
- );
-
- return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
- }
-
- /**
- * Displays the next steps column.
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item Item being shown.
- */
- public function column_next_steps( $item ) {
- $status = $item->status;
-
- switch ( $status ) {
- case 'request-pending':
- esc_html_e( 'Waiting for confirmation' );
- break;
- case 'request-confirmed':
- /** This filter is documented in wp-admin/includes/ajax-actions.php */
- $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
- $exporters_count = count( $exporters );
- $request_id = $item->ID;
- $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id );
-
- echo '';
-
- ?>
-
-
-
-
- ';
- break;
- case 'request-failed':
- submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
- break;
- case 'request-completed':
- echo '
' . esc_html__( 'Remove request' ) . ' ';
- break;
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php
deleted file mode 100644
index 8e2efa0..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-privacy-data-removal-requests-list-table.php
+++ /dev/null
@@ -1,137 +0,0 @@
-status;
- if ( 'request-confirmed' !== $status ) {
- /** This filter is documented in wp-admin/includes/ajax-actions.php */
- $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
- $erasers_count = count( $erasers );
- $request_id = $item->ID;
- $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
-
- $remove_data_markup = '
';
-
- $remove_data_markup .= '' . __( 'Force Erase Personal Data' ) . ' ' .
- '' . __( 'Erasing Data...' ) . ' ' .
- '' . __( 'Erasure completed.' ) . ' ' .
- '' . __( 'Force Erasure has failed.' ) . ' ' . __( 'Retry' ) . ' ';
-
- $remove_data_markup .= '
';
-
- $row_actions = array(
- 'remove-data' => $remove_data_markup,
- );
- }
-
- return sprintf( '
%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) );
- }
-
- /**
- * Next steps column.
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item Item being shown.
- */
- public function column_next_steps( $item ) {
- $status = $item->status;
-
- switch ( $status ) {
- case 'request-pending':
- esc_html_e( 'Waiting for confirmation' );
- break;
- case 'request-confirmed':
- /** This filter is documented in wp-admin/includes/ajax-actions.php */
- $erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
- $erasers_count = count( $erasers );
- $request_id = $item->ID;
- $nonce = wp_create_nonce( 'wp-privacy-erase-personal-data-' . $request_id );
-
- echo '
';
-
- ?>
-
-
-
-
- ';
-
- break;
- case 'request-failed':
- submit_button( __( 'Retry' ), 'secondary', 'privacy_action_email_retry[' . $item->ID . ']', false );
- break;
- case 'request-completed':
- echo '
' . esc_html__( 'Remove request' ) . ' ';
- break;
- }
- }
-
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-privacy-policy-content.php b/srcs/wordpress/wp-admin/includes/class-wp-privacy-policy-content.php
deleted file mode 100644
index 030efef..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-privacy-policy-content.php
+++ /dev/null
@@ -1,725 +0,0 @@
- $plugin_name,
- 'policy_text' => $policy_text,
- );
-
- if ( ! in_array( $data, self::$policy_content, true ) ) {
- self::$policy_content[] = $data;
- }
- }
-
- /**
- * Quick check if any privacy info has changed.
- *
- * @since 4.9.6
- */
- public static function text_change_check() {
-
- $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
-
- // The site doesn't have a privacy policy.
- if ( empty( $policy_page_id ) ) {
- return false;
- }
-
- if ( ! current_user_can( 'edit_post', $policy_page_id ) ) {
- return false;
- }
-
- $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
-
- // Updates are not relevant if the user has not reviewed any suggestions yet.
- if ( empty( $old ) ) {
- return false;
- }
-
- $cached = get_option( '_wp_suggested_policy_text_has_changed' );
-
- /*
- * When this function is called before `admin_init`, `self::$policy_content`
- * has not been populated yet, so use the cached result from the last
- * execution instead.
- */
- if ( ! did_action( 'admin_init' ) ) {
- return 'changed' === $cached;
- }
-
- $new = self::$policy_content;
-
- // Remove the extra values added to the meta.
- foreach ( $old as $key => $data ) {
- if ( ! empty( $data['removed'] ) ) {
- unset( $old[ $key ] );
- continue;
- }
-
- $old[ $key ] = array(
- 'plugin_name' => $data['plugin_name'],
- 'policy_text' => $data['policy_text'],
- );
- }
-
- // Normalize the order of texts, to facilitate comparison.
- sort( $old );
- sort( $new );
-
- // The == operator (equal, not identical) was used intentionally.
- // See http://php.net/manual/en/language.operators.array.php
- if ( $new != $old ) {
- // A plugin was activated or deactivated, or some policy text has changed.
- // Show a notice on the relevant screens to inform the admin.
- add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) );
- $state = 'changed';
- } else {
- $state = 'not-changed';
- }
-
- // Cache the result for use before `admin_init` (see above).
- if ( $cached !== $state ) {
- update_option( '_wp_suggested_policy_text_has_changed', $state );
- }
-
- return 'changed' === $state;
- }
-
- /**
- * Output a warning when some privacy info has changed.
- *
- * @since 4.9.6
- */
- public static function policy_text_changed_notice() {
- global $post;
-
- $screen = get_current_screen()->id;
-
- if ( 'privacy' !== $screen ) {
- return;
- }
-
- ?>
-
-
- review the guide and update your privacy policy.' ),
- esc_url( admin_url( 'privacy-policy-guide.php' ) )
- );
- ?>
-
-
- $old_data ) {
- if ( ! empty( $old_data['removed'] ) ) {
- // Remove the old policy text.
- $update_cache = true;
- continue;
- }
-
- if ( ! empty( $old_data['updated'] ) ) {
- // 'updated' is now 'added'.
- $done[] = array(
- 'plugin_name' => $old_data['plugin_name'],
- 'policy_text' => $old_data['policy_text'],
- 'added' => $old_data['updated'],
- );
- $update_cache = true;
- } else {
- $done[] = $old_data;
- }
- }
-
- if ( $update_cache ) {
- delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
- // Update the cache.
- foreach ( $done as $data ) {
- add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data );
- }
- }
- }
-
- /**
- * Check for updated, added or removed privacy policy information from plugins.
- *
- * Caches the current info in post_meta of the policy page.
- *
- * @since 4.9.6
- *
- * @return array The privacy policy text/information added by core and plugins.
- */
- public static function get_suggested_policy_text() {
- $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
- $checked = array();
- $time = time();
- $update_cache = false;
- $new = self::$policy_content;
- $old = array();
-
- if ( $policy_page_id ) {
- $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
- }
-
- // Check for no-changes and updates.
- foreach ( $new as $new_key => $new_data ) {
- foreach ( $old as $old_key => $old_data ) {
- $found = false;
-
- if ( $new_data['policy_text'] === $old_data['policy_text'] ) {
- // Use the new plugin name in case it was changed, translated, etc.
- if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) {
- $old_data['plugin_name'] = $new_data['plugin_name'];
- $update_cache = true;
- }
-
- // A plugin was re-activated.
- if ( ! empty( $old_data['removed'] ) ) {
- unset( $old_data['removed'] );
- $old_data['added'] = $time;
- $update_cache = true;
- }
-
- $checked[] = $old_data;
- $found = true;
- } elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) {
- // The info for the policy was updated.
- $checked[] = array(
- 'plugin_name' => $new_data['plugin_name'],
- 'policy_text' => $new_data['policy_text'],
- 'updated' => $time,
- );
- $found = true;
- $update_cache = true;
- }
-
- if ( $found ) {
- unset( $new[ $new_key ], $old[ $old_key ] );
- continue 2;
- }
- }
- }
-
- if ( ! empty( $new ) ) {
- // A plugin was activated.
- foreach ( $new as $new_data ) {
- if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) {
- $new_data['added'] = $time;
- $checked[] = $new_data;
- }
- }
- $update_cache = true;
- }
-
- if ( ! empty( $old ) ) {
- // A plugin was deactivated.
- foreach ( $old as $old_data ) {
- if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) {
- $data = array(
- 'plugin_name' => $old_data['plugin_name'],
- 'policy_text' => $old_data['policy_text'],
- 'removed' => $time,
- );
-
- $checked[] = $data;
- }
- }
- $update_cache = true;
- }
-
- if ( $update_cache && $policy_page_id ) {
- delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
- // Update the cache.
- foreach ( $checked as $data ) {
- add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data );
- }
- }
-
- return $checked;
- }
-
- /**
- * Add a notice with a link to the guide when editing the privacy policy page.
- *
- * @since 4.9.6
- * @since 5.0.0 The `$post` parameter was made optional.
- *
- * @param WP_Post|null $post The currently edited post. Default null.
- */
- public static function notice( $post = null ) {
- if ( is_null( $post ) ) {
- global $post;
- } else {
- $post = get_post( $post );
- }
-
- if ( ! ( $post instanceof WP_Post ) ) {
- return;
- }
-
- if ( ! current_user_can( 'manage_privacy_options' ) ) {
- return;
- }
-
- $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
-
- if ( ! $policy_page_id || $policy_page_id !== $post->ID ) {
- return;
- }
-
- $message = __( 'Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme.' );
- $url = esc_url( admin_url( 'privacy-policy-guide.php' ) );
- $label = __( 'View Privacy Policy Guide.' );
-
- if ( get_current_screen()->is_block_editor() ) {
- wp_enqueue_script( 'wp-notices' );
- $action = array(
- 'url' => $url,
- 'label' => $label,
- );
- wp_add_inline_script(
- 'wp-notices',
- sprintf(
- 'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )',
- $message,
- wp_json_encode( $action )
- ),
- 'after'
- );
- } else {
- ?>
-
-
- %s %s ',
- $url,
- $label,
- /* translators: Accessibility text. */
- __( '(opens in a new tab)' )
- );
- ?>
-
-
-
' . __( 'Introduction' ) . ' ' );
- $date_format = __( 'F j, Y' );
- $copy = __( 'Copy this section to clipboard' );
- $return_to_top = '
' . __( '↑ Return to Top' ) . ' ';
-
- foreach ( $content_array as $section ) {
- $class = '';
- $meta = '';
- $removed = '';
-
- if ( ! empty( $section['removed'] ) ) {
- $class = ' text-removed';
- $date = date_i18n( $date_format, $section['removed'] );
- /* translators: %s: Date of plugin deactivation. */
- $meta = sprintf( __( 'Removed %s.' ), $date );
-
- /* translators: %s: Date of plugin deactivation. */
- $removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' );
- $removed = '
' . sprintf( $removed, $date ) . '
';
- } elseif ( ! empty( $section['updated'] ) ) {
- $class = ' text-updated';
- $date = date_i18n( $date_format, $section['updated'] );
- /* translators: %s: Date of privacy policy text update. */
- $meta = sprintf( __( 'Updated %s.' ), $date );
- }
-
- if ( $meta ) {
- $meta = '
' . $meta . ' ';
- }
-
- $plugin_name = esc_html( $section['plugin_name'] );
- $toc_id = 'wp-privacy-policy-guide-' . sanitize_title( $plugin_name );
- $toc[] = sprintf( '
%2$s ' . $meta . '', $toc_id, $plugin_name );
-
- $content .= '
';
- $content .= '
';
- /* translators: %s: Plugin name. */
- $content .= '
' . sprintf( __( 'Source: %s' ), $plugin_name ) . ' ';
- $content .= $removed;
-
- $content .= '
' . $section['policy_text'] . '
';
- $content .= $return_to_top;
-
- if ( empty( $section['removed'] ) ) {
- $content .= '
';
- $content .= '';
- $content .= $copy;
- $content .= '';
- /* translators: %s: Plugin name. */
- $content .= sprintf( __( 'Copy suggested policy text from %s.' ), $plugin_name );
- $content .= ' ';
- $content .= ' ';
- $content .= '
';
- }
-
- $content .= "
\n"; // End of .privacy-text-section.
- }
-
- if ( count( $toc ) > 2 ) {
- ?>
-
-
-
- ' . __( 'Suggested text:' ) . ' ' : '';
- $content = '';
- $strings = array();
-
- // Start of the suggested privacy policy text.
- if ( $description ) {
- $strings[] = '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Who we are' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should note your site URL, as well as the name of the company, organization, or individual behind it, and some accurate contact information.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'The amount of information you may be required to show will vary depending on your local or national business regulations. You may, for example, be required to display a physical address, a registered address, or your company registration number.' ) . '
';
- }
-
- /* translators: Default privacy policy text. %s: Site URL. */
- $strings[] = '
' . $suggested_text . sprintf( __( 'Our website address is: %s.' ), get_bloginfo( 'url', 'display' ) ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'What personal data we collect and why we collect it' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should note what personal data you collect from users and site visitors. This may include personal data, such as name, email address, personal account preferences; transactional data, such as purchase information; and technical data, such as information about cookies.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In addition to listing what personal data you collect, you need to note why you collect it. These explanations must note either the legal basis for your data collection and retention or the active consent the user has given.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'Personal data is not just created by a user’s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'By default WordPress does not collect any personal data about visitors, and only collects the data shown on the User Profile screen from registered users. However some of your plugins may collect personal data. You should add the relevant information below.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Comments' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this subsection you should note what information is captured through comments. We have noted the data which WordPress collects by default.' ) . '
';
- }
-
- /* translators: Default privacy policy text. */
- $strings[] = '
' . $suggested_text . __( 'When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor’s IP address and browser user agent string to help spam detection.' ) . '
';
- /* translators: Default privacy policy text. */
- $strings[] = '
' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.' ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Media' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this subsection you should note what information may be disclosed by users who can upload media files. All uploaded files are usually publicly accessible.' ) . '
';
- }
-
- /* translators: Default privacy policy text. */
- $strings[] = '
' . $suggested_text . __( 'If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.' ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Contact forms' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'By default, WordPress does not include a contact form. If you use a contact form plugin, use this subsection to note what personal data is captured when someone submits a contact form, and how long you keep it. For example, you may note that you keep contact form submissions for a certain period for customer service purposes, but you do not use the information submitted through them for marketing purposes.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Cookies' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this subsection you should list the cookies your web site uses, including those set by your plugins, social media, and analytics. We have provided the cookies which WordPress installs by default.' ) . '
';
- }
-
- /* translators: Default privacy policy text. */
- $strings[] = '
' . $suggested_text . __( 'If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year.' ) . '
';
- /* translators: Default privacy policy text. */
- $strings[] = '
' . __( 'If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser.' ) . '
';
- /* translators: Default privacy policy text. */
- $strings[] = '
' . __( 'When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select "Remember Me", your login will persist for two weeks. If you log out of your account, the login cookies will be removed.' ) . '
';
- /* translators: Default privacy policy text. */
- $strings[] = '
' . __( 'If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.' ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Embedded content from other websites' ) . ' ';
- /* translators: Default privacy policy text. */
- $strings[] = '
' . $suggested_text . __( 'Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website.' ) . '
';
- /* translators: Default privacy policy text. */
- $strings[] = '
' . __( 'These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.' ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Analytics' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this subsection you should note what analytics package you use, how users can opt out of analytics tracking, and a link to your analytics provider’s privacy policy, if any.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'By default WordPress does not collect any analytics data. However, many web hosting accounts collect some anonymous analytics data. You may also have installed a WordPress plugin that provides analytics services. In that case, add information from that plugin here.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Who we share your data with' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should name and list all third party providers with whom you share site data, including partners, cloud-based services, payment processors, and third party service providers, and note what data you share with them and why. Link to their own privacy policies if possible.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'By default WordPress does not share any personal data with anyone.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'How long we retain your data' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should explain how long you retain personal data collected or processed by the web site. While it is your responsibility to come up with the schedule of how long you keep each dataset for and why you keep it, that information does need to be listed here. For example, you may want to say that you keep contact form entries for six months, analytics records for a year, and customer purchase records for ten years.' ) . '
';
- }
-
- /* translators: Default privacy policy text. */
- $strings[] = '
' . $suggested_text . __( 'If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.' ) . '
';
- /* translators: Default privacy policy text. */
- $strings[] = '
' . __( 'For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.' ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'What rights you have over your data' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '
';
- }
-
- /* translators: Default privacy policy text. */
- $strings[] = '
' . $suggested_text . __( 'If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.' ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Where we send your data' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should list all transfers of your site data outside the European Union and describe the means by which that data is safeguarded to European data protection standards. This could include your web hosting, cloud storage, or other third party services.' ) . '
';
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'European data protection law requires data about European residents which is transferred outside the European Union to be safeguarded to the same standards as if the data was in Europe. So in addition to listing where data goes, you should describe how you ensure that these standards are met either by yourself or by your third party providers, whether that is through an agreement such as Privacy Shield, model clauses in your contracts, or binding corporate rules.' ) . '
';
- }
-
- /* translators: Default privacy policy text. */
- $strings[] = '
' . $suggested_text . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '
';
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Your contact information' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should provide a contact method for privacy-specific concerns. If you are required to have a Data Protection Officer, list their name and full contact details here as well.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Additional information' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'If you use your site for commercial purposes and you engage in more complex collection or processing of personal data, you should note the following information in your privacy policy in addition to the information we have already discussed.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'How we protect your data' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should explain what measures you have taken to protect your users’ data. This could include technical measures such as encryption; security measures such as two factor authentication; and measures such as staff training in data protection. If you have carried out a Privacy Impact Assessment, you can mention it here too.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'What data breach procedures we have in place' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'In this section you should explain what procedures you have in place to deal with data breaches, either potential or real, such as internal reporting systems, contact mechanisms, or bug bounties.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'What third parties we receive data from' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'If your web site receives data about users from third parties, including advertisers, this information must be included within the section of your privacy policy dealing with third party data.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'What automated decision making and/or profiling we do with user data' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'If your web site provides a service which includes automated decision making - for example, allowing customers to apply for credit, or aggregating their data into an advertising profile - you must note that this is taking place, and include information about how that information is used, what decisions are made with that aggregated data, and what rights users have over decisions made without human intervention.' ) . '
';
- }
-
- /* translators: Default privacy policy heading. */
- $strings[] = '
' . __( 'Industry regulatory disclosure requirements' ) . ' ';
-
- if ( $description ) {
- /* translators: Privacy policy tutorial. */
- $strings[] = '
' . __( 'If you are a member of a regulated industry, or if you are subject to additional privacy laws, you may be required to disclose that information here.' ) . '
';
- $strings[] = '
';
- }
-
- if ( $blocks ) {
- foreach ( $strings as $key => $string ) {
- if ( 0 === strpos( $string, '
' ) ) {
- $strings[ $key ] = '' . $string . '';
- }
-
- if ( 0 === strpos( $string, '
' ) ) {
- $strings[ $key ] = '' . $string . '';
- }
-
- if ( 0 === strpos( $string, '' ) ) {
- $strings[ $key ] = '' . $string . '';
- }
- }
- }
-
- $content = implode( '', $strings );
- // End of the suggested privacy policy text.
-
- /**
- * Filters the default content suggested for inclusion in a privacy policy.
- *
- * @since 4.9.6
- * @since 5.0.0 Added the `$strings`, `$description`, and `$blocks` parameters.
- *
- * @param string $content The default policy content.
- * @param array $strings An array of privacy policy content strings.
- * @param bool $description Whether policy descriptions should be included.
- * @param bool $blocks Whether the content should be formatted for the block editor.
- */
- return apply_filters( 'wp_get_default_privacy_policy_content', $content, $strings, $description, $blocks );
- }
-
- /**
- * Add the suggested privacy policy text to the policy postbox.
- *
- * @since 4.9.6
- */
- public static function add_suggested_content() {
- $content = self::get_default_content( true, false );
- wp_add_privacy_policy_content( __( 'WordPress' ), $content );
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-privacy-requests-table.php b/srcs/wordpress/wp-admin/includes/class-wp-privacy-requests-table.php
deleted file mode 100644
index efbd4a2..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-privacy-requests-table.php
+++ /dev/null
@@ -1,449 +0,0 @@
- ' ',
- 'email' => __( 'Requester' ),
- 'status' => __( 'Status' ),
- 'created_timestamp' => __( 'Requested' ),
- 'next_steps' => __( 'Next Steps' ),
- );
- return $columns;
- }
-
- /**
- * Normalize the admin URL to the current page (by request_type).
- *
- * @since 5.3.0
- *
- * @return string URL to the current admin page.
- */
- protected function get_admin_url() {
- $pagenow = str_replace( '_', '-', $this->request_type );
-
- if ( 'remove-personal-data' === $pagenow ) {
- $pagenow = 'erase-personal-data';
- }
-
- return admin_url( $pagenow . '.php' );
- }
-
- /**
- * Get a list of sortable columns.
- *
- * @since 4.9.6
- *
- * @return array Default sortable columns.
- */
- protected function get_sortable_columns() {
- // The initial sorting is by 'Requested' (post_date) and descending.
- // With initial sorting, the first click on 'Requested' should be ascending.
- // With 'Requester' sorting active, the next click on 'Requested' should be descending.
- $desc_first = isset( $_GET['orderby'] );
-
- return array(
- 'email' => 'requester',
- 'created_timestamp' => array( 'requested', $desc_first ),
- );
- }
-
- /**
- * Default primary column.
- *
- * @since 4.9.6
- *
- * @return string Default primary column name.
- */
- protected function get_default_primary_column_name() {
- return 'email';
- }
-
- /**
- * Count number of requests for each status.
- *
- * @since 4.9.6
- *
- * @return object Number of posts for each status.
- */
- protected function get_request_counts() {
- global $wpdb;
-
- $cache_key = $this->post_type . '-' . $this->request_type;
- $counts = wp_cache_get( $cache_key, 'counts' );
-
- if ( false !== $counts ) {
- return $counts;
- }
-
- $query = "
- SELECT post_status, COUNT( * ) AS num_posts
- FROM {$wpdb->posts}
- WHERE post_type = %s
- AND post_name = %s
- GROUP BY post_status";
-
- $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A );
- $counts = array_fill_keys( get_post_stati(), 0 );
-
- foreach ( $results as $row ) {
- $counts[ $row['post_status'] ] = $row['num_posts'];
- }
-
- $counts = (object) $counts;
- wp_cache_set( $cache_key, $counts, 'counts' );
-
- return $counts;
- }
-
- /**
- * Get an associative array ( id => link ) with the list of views available on this table.
- *
- * @since 4.9.6
- *
- * @return array Associative array of views in the format of $view_name => $view_markup.
- */
- protected function get_views() {
- $current_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : '';
- $statuses = _wp_privacy_statuses();
- $views = array();
- $counts = $this->get_request_counts();
- $total_requests = absint( array_sum( (array) $counts ) );
-
- // Normalized admin URL
- $admin_url = $this->get_admin_url();
-
- $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : '';
- $status_label = sprintf(
- /* translators: %s: Number of requests. */
- _nx(
- 'All (%s) ',
- 'All (%s) ',
- $total_requests,
- 'requests'
- ),
- number_format_i18n( $total_requests )
- );
-
- $views['all'] = sprintf(
- '%s ',
- esc_url( $admin_url ),
- $current_link_attributes,
- $status_label
- );
-
- foreach ( $statuses as $status => $label ) {
- $post_status = get_post_status_object( $status );
- if ( ! $post_status ) {
- continue;
- }
-
- $current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : '';
- $total_status_requests = absint( $counts->{$status} );
-
- $status_label = sprintf(
- translate_nooped_plural( $post_status->label_count, $total_status_requests ),
- number_format_i18n( $total_status_requests )
- );
-
- $status_link = add_query_arg( 'filter-status', $status, $admin_url );
-
- $views[ $status ] = sprintf(
- '%s ',
- esc_url( $status_link ),
- $current_link_attributes,
- $status_label
- );
- }
-
- return $views;
- }
-
- /**
- * Get bulk actions.
- *
- * @since 4.9.6
- *
- * @return array List of bulk actions.
- */
- protected function get_bulk_actions() {
- return array(
- 'delete' => __( 'Remove' ),
- 'resend' => __( 'Resend email' ),
- );
- }
-
- /**
- * Process bulk actions.
- *
- * @since 4.9.6
- */
- public function process_bulk_action() {
- $action = $this->current_action();
- $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array();
-
- $count = 0;
-
- if ( $request_ids ) {
- check_admin_referer( 'bulk-privacy_requests' );
- }
-
- switch ( $action ) {
- case 'delete':
- foreach ( $request_ids as $request_id ) {
- if ( wp_delete_post( $request_id, true ) ) {
- $count ++;
- }
- }
-
- add_settings_error(
- 'bulk_action',
- 'bulk_action',
- /* translators: %d: Number of requests. */
- sprintf( _n( 'Deleted %d request', 'Deleted %d requests', $count ), $count ),
- 'success'
- );
- break;
- case 'resend':
- foreach ( $request_ids as $request_id ) {
- $resend = _wp_privacy_resend_request( $request_id );
-
- if ( $resend && ! is_wp_error( $resend ) ) {
- $count++;
- }
- }
-
- add_settings_error(
- 'bulk_action',
- 'bulk_action',
- /* translators: %d: Number of requests. */
- sprintf( _n( 'Re-sent %d request', 'Re-sent %d requests', $count ), $count ),
- 'success'
- );
- break;
- }
- }
-
- /**
- * Prepare items to output.
- *
- * @since 4.9.6
- * @since 5.1.0 Added support for column sorting.
- */
- public function prepare_items() {
- $this->items = array();
- $posts_per_page = $this->get_items_per_page( $this->request_type . '_requests_per_page' );
- $args = array(
- 'post_type' => $this->post_type,
- 'post_name__in' => array( $this->request_type ),
- 'posts_per_page' => $posts_per_page,
- 'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page : 0,
- 'post_status' => 'any',
- 's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '',
- );
-
- $orderby_mapping = array(
- 'requester' => 'post_title',
- 'requested' => 'post_date',
- );
-
- if ( isset( $_REQUEST['orderby'] ) && isset( $orderby_mapping[ $_REQUEST['orderby'] ] ) ) {
- $args['orderby'] = $orderby_mapping[ $_REQUEST['orderby'] ];
- }
-
- if ( isset( $_REQUEST['order'] ) && in_array( strtoupper( $_REQUEST['order'] ), array( 'ASC', 'DESC' ), true ) ) {
- $args['order'] = strtoupper( $_REQUEST['order'] );
- }
-
- if ( ! empty( $_REQUEST['filter-status'] ) ) {
- $filter_status = isset( $_REQUEST['filter-status'] ) ? sanitize_text_field( $_REQUEST['filter-status'] ) : '';
- $args['post_status'] = $filter_status;
- }
-
- $requests_query = new WP_Query( $args );
- $requests = $requests_query->posts;
-
- foreach ( $requests as $request ) {
- $this->items[] = wp_get_user_request_data( $request->ID );
- }
-
- $this->items = array_filter( $this->items );
-
- $this->set_pagination_args(
- array(
- 'total_items' => $requests_query->found_posts,
- 'per_page' => $posts_per_page,
- )
- );
- }
-
- /**
- * Checkbox column.
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item Item being shown.
- * @return string Checkbox column markup.
- */
- public function column_cb( $item ) {
- return sprintf( ' ', esc_attr( $item->ID ) );
- }
-
- /**
- * Status column.
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item Item being shown.
- * @return string Status column markup.
- */
- public function column_status( $item ) {
- $status = get_post_status( $item->ID );
- $status_object = get_post_status_object( $status );
-
- if ( ! $status_object || empty( $status_object->label ) ) {
- return '-';
- }
-
- $timestamp = false;
-
- switch ( $status ) {
- case 'request-confirmed':
- $timestamp = $item->confirmed_timestamp;
- break;
- case 'request-completed':
- $timestamp = $item->completed_timestamp;
- break;
- }
-
- echo '';
- echo esc_html( $status_object->label );
-
- if ( $timestamp ) {
- echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')';
- }
-
- echo ' ';
- }
-
- /**
- * Convert timestamp for display.
- *
- * @since 4.9.6
- *
- * @param int $timestamp Event timestamp.
- * @return string Human readable date.
- */
- protected function get_timestamp_as_date( $timestamp ) {
- if ( empty( $timestamp ) ) {
- return '';
- }
-
- $time_diff = time() - $timestamp;
-
- if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) {
- /* translators: %s: Human-readable time difference. */
- return sprintf( __( '%s ago' ), human_time_diff( $timestamp ) );
- }
-
- return date_i18n( get_option( 'date_format' ), $timestamp );
- }
-
- /**
- * Default column handler.
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item Item being shown.
- * @param string $column_name Name of column being shown.
- * @return string Default column output.
- */
- public function column_default( $item, $column_name ) {
- $cell_value = $item->$column_name;
-
- if ( in_array( $column_name, array( 'created_timestamp' ), true ) ) {
- return $this->get_timestamp_as_date( $cell_value );
- }
-
- return $cell_value;
- }
-
- /**
- * Actions column. Overridden by children.
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item Item being shown.
- * @return string Email column markup.
- */
- public function column_email( $item ) {
- return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( array() ) );
- }
-
- /**
- * Next steps column. Overridden by children.
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item Item being shown.
- */
- public function column_next_steps( $item ) {}
-
- /**
- * Generates content for a single row of the table,
- *
- * @since 4.9.6
- *
- * @param WP_User_Request $item The current item.
- */
- public function single_row( $item ) {
- $status = $item->status;
-
- echo '';
- $this->single_row_columns( $item );
- echo ' ';
- }
-
- /**
- * Embed scripts used to perform actions. Overridden by children.
- *
- * @since 4.9.6
- */
- public function embed_scripts() {}
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-screen.php b/srcs/wordpress/wp-admin/includes/class-wp-screen.php
deleted file mode 100644
index 41b20a1..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-screen.php
+++ /dev/null
@@ -1,1315 +0,0 @@
-post_type;
-
- /** This filter is documented in wp-admin/post.php */
- $replace_editor = apply_filters( 'replace_editor', false, $post );
-
- if ( ! $replace_editor ) {
- $is_block_editor = use_block_editor_for_post( $post );
- }
- }
- }
- break;
- case 'edit-tags':
- case 'term':
- if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) {
- $post_type = 'post';
- }
- break;
- case 'upload':
- $post_type = 'attachment';
- break;
- }
- }
-
- switch ( $base ) {
- case 'post':
- if ( null === $post_type ) {
- $post_type = 'post';
- }
-
- // When creating a new post, use the default block editor support value for the post type.
- if ( empty( $post_id ) ) {
- $is_block_editor = use_block_editor_for_post_type( $post_type );
- }
-
- $id = $post_type;
- break;
- case 'edit':
- if ( null === $post_type ) {
- $post_type = 'post';
- }
- $id .= '-' . $post_type;
- break;
- case 'edit-tags':
- case 'term':
- if ( null === $taxonomy ) {
- $taxonomy = 'post_tag';
- }
- // The edit-tags ID does not contain the post type. Look for it in the request.
- if ( null === $post_type ) {
- $post_type = 'post';
- if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
- $post_type = $_REQUEST['post_type'];
- }
- }
-
- $id = 'edit-' . $taxonomy;
- break;
- }
-
- if ( 'network' == $in_admin ) {
- $id .= '-network';
- $base .= '-network';
- } elseif ( 'user' == $in_admin ) {
- $id .= '-user';
- $base .= '-user';
- }
-
- if ( isset( self::$_registry[ $id ] ) ) {
- $screen = self::$_registry[ $id ];
- if ( $screen === get_current_screen() ) {
- return $screen;
- }
- } else {
- $screen = new WP_Screen();
- $screen->id = $id;
- }
-
- $screen->base = $base;
- $screen->action = $action;
- $screen->post_type = (string) $post_type;
- $screen->taxonomy = (string) $taxonomy;
- $screen->is_user = ( 'user' == $in_admin );
- $screen->is_network = ( 'network' == $in_admin );
- $screen->in_admin = $in_admin;
- $screen->is_block_editor = $is_block_editor;
-
- self::$_registry[ $id ] = $screen;
-
- return $screen;
- }
-
- /**
- * Makes the screen object the current screen.
- *
- * @see set_current_screen()
- * @since 3.3.0
- *
- * @global WP_Screen $current_screen WordPress current screen object.
- * @global string $taxnow
- * @global string $typenow
- */
- public function set_current_screen() {
- global $current_screen, $taxnow, $typenow;
- $current_screen = $this;
- $taxnow = $this->taxonomy;
- $typenow = $this->post_type;
-
- /**
- * Fires after the current screen has been set.
- *
- * @since 3.0.0
- *
- * @param WP_Screen $current_screen Current WP_Screen object.
- */
- do_action( 'current_screen', $current_screen );
- }
-
- /**
- * Constructor
- *
- * @since 3.3.0
- */
- private function __construct() {}
-
- /**
- * Indicates whether the screen is in a particular admin
- *
- * @since 3.5.0
- *
- * @param string $admin The admin to check against (network | user | site).
- * If empty any of the three admins will result in true.
- * @return bool True if the screen is in the indicated admin, false otherwise.
- */
- public function in_admin( $admin = null ) {
- if ( empty( $admin ) ) {
- return (bool) $this->in_admin;
- }
-
- return ( $admin == $this->in_admin );
- }
-
- /**
- * Sets or returns whether the block editor is loading on the current screen.
- *
- * @since 5.0.0
- *
- * @param bool $set Optional. Sets whether the block editor is loading on the current screen or not.
- * @return bool True if the block editor is being loaded, false otherwise.
- */
- public function is_block_editor( $set = null ) {
- if ( $set !== null ) {
- $this->is_block_editor = (bool) $set;
- }
-
- return $this->is_block_editor;
- }
-
- /**
- * Sets the old string-based contextual help for the screen for backward compatibility.
- *
- * @since 3.3.0
- *
- * @param WP_Screen $screen A screen object.
- * @param string $help Help text.
- */
- public static function add_old_compat_help( $screen, $help ) {
- self::$_old_compat_help[ $screen->id ] = $help;
- }
-
- /**
- * Set the parent information for the screen.
- * This is called in admin-header.php after the menu parent for the screen has been determined.
- *
- * @since 3.3.0
- *
- * @param string $parent_file The parent file of the screen. Typically the $parent_file global.
- */
- public function set_parentage( $parent_file ) {
- $this->parent_file = $parent_file;
- list( $this->parent_base ) = explode( '?', $parent_file );
- $this->parent_base = str_replace( '.php', '', $this->parent_base );
- }
-
- /**
- * Adds an option for the screen.
- * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add screen options.
- *
- * @since 3.3.0
- *
- * @param string $option Option ID
- * @param mixed $args Option-dependent arguments.
- */
- public function add_option( $option, $args = array() ) {
- $this->_options[ $option ] = $args;
- }
-
- /**
- * Remove an option from the screen.
- *
- * @since 3.8.0
- *
- * @param string $option Option ID.
- */
- public function remove_option( $option ) {
- unset( $this->_options[ $option ] );
- }
-
- /**
- * Remove all options from the screen.
- *
- * @since 3.8.0
- */
- public function remove_options() {
- $this->_options = array();
- }
-
- /**
- * Get the options registered for the screen.
- *
- * @since 3.8.0
- *
- * @return array Options with arguments.
- */
- public function get_options() {
- return $this->_options;
- }
-
- /**
- * Gets the arguments for an option for the screen.
- *
- * @since 3.3.0
- *
- * @param string $option Option name.
- * @param string $key Optional. Specific array key for when the option is an array.
- * Default false.
- * @return string The option value if set, null otherwise.
- */
- public function get_option( $option, $key = false ) {
- if ( ! isset( $this->_options[ $option ] ) ) {
- return null;
- }
- if ( $key ) {
- if ( isset( $this->_options[ $option ][ $key ] ) ) {
- return $this->_options[ $option ][ $key ];
- }
- return null;
- }
- return $this->_options[ $option ];
- }
-
- /**
- * Gets the help tabs registered for the screen.
- *
- * @since 3.4.0
- * @since 4.4.0 Help tabs are ordered by their priority.
- *
- * @return array Help tabs with arguments.
- */
- public function get_help_tabs() {
- $help_tabs = $this->_help_tabs;
-
- $priorities = array();
- foreach ( $help_tabs as $help_tab ) {
- if ( isset( $priorities[ $help_tab['priority'] ] ) ) {
- $priorities[ $help_tab['priority'] ][] = $help_tab;
- } else {
- $priorities[ $help_tab['priority'] ] = array( $help_tab );
- }
- }
-
- ksort( $priorities );
-
- $sorted = array();
- foreach ( $priorities as $list ) {
- foreach ( $list as $tab ) {
- $sorted[ $tab['id'] ] = $tab;
- }
- }
-
- return $sorted;
- }
-
- /**
- * Gets the arguments for a help tab.
- *
- * @since 3.4.0
- *
- * @param string $id Help Tab ID.
- * @return array Help tab arguments.
- */
- public function get_help_tab( $id ) {
- if ( ! isset( $this->_help_tabs[ $id ] ) ) {
- return null;
- }
- return $this->_help_tabs[ $id ];
- }
-
- /**
- * Add a help tab to the contextual help for the screen.
- * Call this on the load-$pagenow hook for the relevant screen.
- *
- * @since 3.3.0
- * @since 4.4.0 The `$priority` argument was added.
- *
- * @param array $args {
- * Array of arguments used to display the help tab.
- *
- * @type string $title Title for the tab. Default false.
- * @type string $id Tab ID. Must be HTML-safe. Default false.
- * @type string $content Optional. Help tab content in plain text or HTML. Default empty string.
- * @type string $callback Optional. A callback to generate the tab content. Default false.
- * @type int $priority Optional. The priority of the tab, used for ordering. Default 10.
- * }
- */
- public function add_help_tab( $args ) {
- $defaults = array(
- 'title' => false,
- 'id' => false,
- 'content' => '',
- 'callback' => false,
- 'priority' => 10,
- );
- $args = wp_parse_args( $args, $defaults );
-
- $args['id'] = sanitize_html_class( $args['id'] );
-
- // Ensure we have an ID and title.
- if ( ! $args['id'] || ! $args['title'] ) {
- return;
- }
-
- // Allows for overriding an existing tab with that ID.
- $this->_help_tabs[ $args['id'] ] = $args;
- }
-
- /**
- * Removes a help tab from the contextual help for the screen.
- *
- * @since 3.3.0
- *
- * @param string $id The help tab ID.
- */
- public function remove_help_tab( $id ) {
- unset( $this->_help_tabs[ $id ] );
- }
-
- /**
- * Removes all help tabs from the contextual help for the screen.
- *
- * @since 3.3.0
- */
- public function remove_help_tabs() {
- $this->_help_tabs = array();
- }
-
- /**
- * Gets the content from a contextual help sidebar.
- *
- * @since 3.4.0
- *
- * @return string Contents of the help sidebar.
- */
- public function get_help_sidebar() {
- return $this->_help_sidebar;
- }
-
- /**
- * Add a sidebar to the contextual help for the screen.
- * Call this in template files after admin.php is loaded and before admin-header.php is loaded to add a sidebar to the contextual help.
- *
- * @since 3.3.0
- *
- * @param string $content Sidebar content in plain text or HTML.
- */
- public function set_help_sidebar( $content ) {
- $this->_help_sidebar = $content;
- }
-
- /**
- * Gets the number of layout columns the user has selected.
- *
- * The layout_columns option controls the max number and default number of
- * columns. This method returns the number of columns within that range selected
- * by the user via Screen Options. If no selection has been made, the default
- * provisioned in layout_columns is returned. If the screen does not support
- * selecting the number of layout columns, 0 is returned.
- *
- * @since 3.4.0
- *
- * @return int Number of columns to display.
- */
- public function get_columns() {
- return $this->columns;
- }
-
- /**
- * Get the accessible hidden headings and text used in the screen.
- *
- * @since 4.4.0
- *
- * @see set_screen_reader_content() For more information on the array format.
- *
- * @return array An associative array of screen reader text strings.
- */
- public function get_screen_reader_content() {
- return $this->_screen_reader_content;
- }
-
- /**
- * Get a screen reader text string.
- *
- * @since 4.4.0
- *
- * @param string $key Screen reader text array named key.
- * @return string Screen reader text string.
- */
- public function get_screen_reader_text( $key ) {
- if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
- return null;
- }
- return $this->_screen_reader_content[ $key ];
- }
-
- /**
- * Add accessible hidden headings and text for the screen.
- *
- * @since 4.4.0
- *
- * @param array $content {
- * An associative array of screen reader text strings.
- *
- * @type string $heading_views Screen reader text for the filter links heading.
- * Default 'Filter items list'.
- * @type string $heading_pagination Screen reader text for the pagination heading.
- * Default 'Items list navigation'.
- * @type string $heading_list Screen reader text for the items list heading.
- * Default 'Items list'.
- * }
- */
- public function set_screen_reader_content( $content = array() ) {
- $defaults = array(
- 'heading_views' => __( 'Filter items list' ),
- 'heading_pagination' => __( 'Items list navigation' ),
- 'heading_list' => __( 'Items list' ),
- );
- $content = wp_parse_args( $content, $defaults );
-
- $this->_screen_reader_content = $content;
- }
-
- /**
- * Remove all the accessible hidden headings and text for the screen.
- *
- * @since 4.4.0
- */
- public function remove_screen_reader_content() {
- $this->_screen_reader_content = array();
- }
-
- /**
- * Render the screen's help section.
- *
- * This will trigger the deprecated filters for backward compatibility.
- *
- * @since 3.3.0
- *
- * @global string $screen_layout_columns
- */
- public function render_screen_meta() {
-
- /**
- * Filters the legacy contextual help list.
- *
- * @since 2.7.0
- * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
- * get_current_screen()->remove_help_tab() instead.
- *
- * @param array $old_compat_help Old contextual help.
- * @param WP_Screen $this Current WP_Screen instance.
- */
- self::$_old_compat_help = apply_filters( 'contextual_help_list', self::$_old_compat_help, $this );
-
- $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : '';
-
- /**
- * Filters the legacy contextual help text.
- *
- * @since 2.7.0
- * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
- * get_current_screen()->remove_help_tab() instead.
- *
- * @param string $old_help Help text that appears on the screen.
- * @param string $screen_id Screen ID.
- * @param WP_Screen $this Current WP_Screen instance.
- */
- $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
-
- // Default help only if there is no old-style block of text and no new-style help tabs.
- if ( empty( $old_help ) && ! $this->get_help_tabs() ) {
-
- /**
- * Filters the default legacy contextual help text.
- *
- * @since 2.8.0
- * @deprecated 3.3.0 Use get_current_screen()->add_help_tab() or
- * get_current_screen()->remove_help_tab() instead.
- *
- * @param string $old_help_default Default contextual help text.
- */
- $default_help = apply_filters( 'default_contextual_help', '' );
- if ( $default_help ) {
- $old_help = ' ' . $default_help . '
';
- }
- }
-
- if ( $old_help ) {
- $this->add_help_tab(
- array(
- 'id' => 'old-contextual-help',
- 'title' => __( 'Overview' ),
- 'content' => $old_help,
- )
- );
- }
-
- $help_sidebar = $this->get_help_sidebar();
-
- $help_class = 'hidden';
- if ( ! $help_sidebar ) {
- $help_class .= ' no-sidebar';
- }
-
- // Time to render!
- ?>
-
- get_help_tabs() && ! $this->show_screen_options() ) {
- return;
- }
- ?>
-
- _show_screen_options ) ) {
- return $this->_show_screen_options;
- }
-
- $columns = get_column_headers( $this );
-
- $show_screen = ! empty( $wp_meta_boxes[ $this->id ] ) || $columns || $this->get_option( 'per_page' );
-
- $this->_screen_settings = '';
-
- if ( 'post' === $this->base ) {
- $expand = '
' . __( 'Additional settings' ) . ' ';
- $expand .= ' ';
- $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . ' ';
- $this->_screen_settings = $expand;
- }
-
- /**
- * Filters the screen settings text displayed in the Screen Options tab.
- *
- * This filter is currently only used on the Widgets screen to enable
- * accessibility mode.
- *
- * @since 3.0.0
- *
- * @param string $screen_settings Screen settings.
- * @param WP_Screen $this WP_Screen object.
- */
- $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
-
- if ( $this->_screen_settings || $this->_options ) {
- $show_screen = true;
- }
-
- /**
- * Filters whether to show the Screen Options tab.
- *
- * @since 3.2.0
- *
- * @param bool $show_screen Whether to show Screen Options tab.
- * Default true.
- * @param WP_Screen $this Current WP_Screen instance.
- */
- $this->_show_screen_options = apply_filters( 'screen_options_show_screen', $show_screen, $this );
- return $this->_show_screen_options;
- }
-
- /**
- * Render the screen options tab.
- *
- * @since 3.3.0
- *
- * @param array $options {
- * @type bool $wrap Whether the screen-options-wrap div will be included. Defaults to true.
- * }
- */
- public function render_screen_options( $options = array() ) {
- $options = wp_parse_args(
- $options,
- array(
- 'wrap' => true,
- )
- );
-
- $wrapper_start = '';
- $wrapper_end = '';
- $form_start = '';
- $form_end = '';
-
- // Output optional wrapper.
- if ( $options['wrap'] ) {
- $wrapper_start = '
';
- $wrapper_end = '
';
- }
-
- // Don't output the form and nonce for the widgets accessibility mode links.
- if ( 'widgets' !== $this->base ) {
- $form_start = "\n
\n";
- $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n \n";
- }
-
- echo $wrapper_start . $form_start;
-
- $this->render_meta_boxes_preferences();
- $this->render_list_table_columns_preferences();
- $this->render_screen_layout();
- $this->render_per_page_options();
- $this->render_view_mode();
- echo $this->_screen_settings;
-
- /**
- * Filters whether to show the Screen Options submit button.
- *
- * @since 4.4.0
- *
- * @param bool $show_button Whether to show Screen Options submit button.
- * Default false.
- * @param WP_Screen $this Current WP_Screen instance.
- */
- $show_button = apply_filters( 'screen_options_show_submit', false, $this );
-
- if ( $show_button ) {
- submit_button( __( 'Apply' ), 'primary', 'screen-options-apply', true );
- }
-
- echo $form_end . $wrapper_end;
- }
-
- /**
- * Render the meta boxes preferences.
- *
- * @since 4.4.0
- *
- * @global array $wp_meta_boxes
- */
- public function render_meta_boxes_preferences() {
- global $wp_meta_boxes;
-
- if ( ! isset( $wp_meta_boxes[ $this->id ] ) ) {
- return;
- }
- ?>
-
-
- id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
- if ( isset( $_GET['welcome'] ) ) {
- $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
- update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
- } else {
- $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
- if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
- $welcome_checked = false;
- }
- }
- echo '';
- echo ' ';
- echo _x( 'Welcome', 'Welcome panel' ) . " \n";
- }
- ?>
-
-
-
-
- $title ) {
- // Can't hide these for they are special
- if ( in_array( $column, $special ) ) {
- continue;
- }
-
- if ( empty( $title ) ) {
- continue;
- }
-
- /*
- * The Comments column uses HTML in the display name with some screen
- * reader text. Make sure to strip tags from the Comments column
- * title and any other custom column title plugins might add.
- */
- $title = wp_strip_all_tags( $title );
-
- $id = "$column-hide";
- echo '';
- echo ' ';
- echo "$title \n";
- }
- ?>
-
- get_option( 'layout_columns' ) ) {
- return;
- }
-
- $screen_layout_columns = $this->get_columns();
- $num = $this->get_option( 'layout_columns', 'max' );
-
- ?>
-
-
-
-
- />
-
-
-
-
- get_option( 'per_page' ) ) {
- return;
- }
-
- $per_page_label = $this->get_option( 'per_page', 'label' );
- if ( null === $per_page_label ) {
- $per_page_label = __( 'Number of items per page:' );
- }
-
- $option = $this->get_option( 'per_page', 'option' );
- if ( ! $option ) {
- $option = str_replace( '-', '_', "{$this->id}_per_page" );
- }
-
- $per_page = (int) get_user_option( $option );
- if ( empty( $per_page ) || $per_page < 1 ) {
- $per_page = $this->get_option( 'per_page', 'default' );
- if ( ! $per_page ) {
- $per_page = 20;
- }
- }
-
- if ( 'edit_comments_per_page' == $option ) {
- $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
-
- /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
- $per_page = apply_filters( 'comments_per_page', $per_page, $comment_status );
- } elseif ( 'categories_per_page' == $option ) {
- /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
- $per_page = apply_filters( 'edit_categories_per_page', $per_page );
- } else {
- /** This filter is documented in wp-admin/includes/class-wp-list-table.php */
- $per_page = apply_filters( "{$option}", $per_page );
- }
-
- // Back compat
- if ( isset( $this->post_type ) ) {
- /** This filter is documented in wp-admin/includes/post.php */
- $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
- }
-
- // This needs a submit button
- add_filter( 'screen_options_show_submit', '__return_true' );
-
- ?>
-
-
-
-
-
-
-
-
- base ) {
- return;
- }
-
- $view_mode_post_types = get_post_types(
- array(
- 'hierarchical' => false,
- 'show_ui' => true,
- )
- );
-
- /**
- * Filters the post types that have different view mode options.
- *
- * @since 4.4.0
- *
- * @param string[] $view_mode_post_types Array of post types that can change view modes.
- * Default non-hierarchical post types with show_ui on.
- */
- $view_mode_post_types = apply_filters( 'view_mode_post_types', $view_mode_post_types );
-
- if ( ! in_array( $this->post_type, $view_mode_post_types ) ) {
- return;
- }
-
- global $mode;
-
- // This needs a submit button
- add_filter( 'screen_options_show_submit', '__return_true' );
- ?>
-
-
-
- />
-
-
-
- />
-
-
-
- _screen_reader_content[ $key ] ) ) {
- return;
- }
- echo "<$tag class='screen-reader-text'>" . $this->_screen_reader_content[ $key ] . "$tag>";
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-site-health-auto-updates.php b/srcs/wordpress/wp-admin/includes/class-wp-site-health-auto-updates.php
deleted file mode 100644
index 05fbba9..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-site-health-auto-updates.php
+++ /dev/null
@@ -1,478 +0,0 @@
-test_constants( 'WP_AUTO_UPDATE_CORE', true ),
- $this->test_wp_version_check_attached(),
- $this->test_filters_automatic_updater_disabled(),
- $this->test_wp_automatic_updates_disabled(),
- $this->test_if_failed_update(),
- $this->test_vcs_abspath(),
- $this->test_check_wp_filesystem_method(),
- $this->test_all_files_writable(),
- $this->test_accepts_dev_updates(),
- $this->test_accepts_minor_updates(),
- );
-
- $tests = array_filter( $tests );
- $tests = array_map(
- function( $test ) {
- $test = (object) $test;
-
- if ( empty( $test->severity ) ) {
- $test->severity = 'warning';
- }
-
- return $test;
- },
- $tests
- );
-
- return $tests;
- }
-
- /**
- * Test if auto-updates related constants are set correctly.
- *
- * @since 5.2.0
- *
- * @param string $constant The name of the constant to check.
- * @param bool $value The value that the constant should be, if set.
- * @return array The test results.
- */
- public function test_constants( $constant, $value ) {
- if ( defined( $constant ) && constant( $constant ) != $value ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the constant used. */
- __( 'The %s constant is defined and enabled.' ),
- "
$constant"
- ),
- 'severity' => 'fail',
- );
- }
- }
-
- /**
- * Check if updates are intercepted by a filter.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function test_wp_version_check_attached() {
- if ( ! is_main_site() ) {
- return;
- }
-
- $cookies = wp_unslash( $_COOKIE );
- $timeout = 10;
- $headers = array(
- 'Cache-Control' => 'no-cache',
- );
- /** This filter is documented in wp-includes/class-wp-http-streams.php */
- $sslverify = apply_filters( 'https_local_ssl_verify', false );
-
- // Include Basic auth in loopback requests.
- if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
- $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
- }
-
- $url = add_query_arg(
- array(
- 'health-check-test-wp_version_check' => true,
- ),
- admin_url( 'site-health.php' )
- );
-
- $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
-
- if ( is_wp_error( $test ) ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the filter used. */
- __( 'Could not confirm that the %s filter is available.' ),
- '
wp_version_check()'
- ),
- 'severity' => 'warning',
- );
- }
-
- $response = wp_remote_retrieve_body( $test );
-
- if ( 'yes' !== $response ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the filter used. */
- __( 'A plugin has prevented updates by disabling %s.' ),
- '
wp_version_check()'
- ),
- 'severity' => 'fail',
- );
- }
- }
-
- /**
- * Check if automatic updates are disabled by a filter.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function test_filters_automatic_updater_disabled() {
- /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
- if ( apply_filters( 'automatic_updater_disabled', false ) ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the filter used. */
- __( 'The %s filter is enabled.' ),
- '
automatic_updater_disabled'
- ),
- 'severity' => 'fail',
- );
- }
- }
-
- /**
- * Check if automatic updates are disabled.
- *
- * @since 5.3.0
- *
- * @return array|bool The test results. False if auto updates are enabled.
- */
- public function test_wp_automatic_updates_disabled() {
- if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-automatic-updates.php' );
- }
-
- $auto_updates = new WP_Automatic_Updater();
-
- if ( ! $auto_updates->is_disabled() ) {
- return false;
- }
-
- return array(
- 'description' => __( 'All automatic updates are disabled.' ),
- 'severity' => 'fail',
- );
- }
-
- /**
- * Check if automatic updates have tried to run, but failed, previously.
- *
- * @since 5.2.0
- *
- * @return array|bool The test results. False if the auto updates failed.
- */
- function test_if_failed_update() {
- $failed = get_site_option( 'auto_core_update_failed' );
-
- if ( ! $failed ) {
- return false;
- }
-
- if ( ! empty( $failed['critical'] ) ) {
- $description = __( 'A previous automatic background update ended with a critical failure, so updates are now disabled.' );
- $description .= ' ' . __( 'You would have received an email because of this.' );
- $description .= ' ' . __( "When you've been able to update using the \"Update Now\" button on Dashboard > Updates, we'll clear this error for future update attempts." );
- $description .= ' ' . sprintf(
- /* translators: %s: Code of error shown. */
- __( 'The error code was %s.' ),
- '
' . $failed['error_code'] . ''
- );
- return array(
- 'description' => $description,
- 'severity' => 'warning',
- );
- }
-
- $description = __( 'A previous automatic background update could not occur.' );
- if ( empty( $failed['retry'] ) ) {
- $description .= ' ' . __( 'You would have received an email because of this.' );
- }
-
- $description .= ' ' . __( "We'll try again with the next release." );
- $description .= ' ' . sprintf(
- /* translators: %s: Code of error shown. */
- __( 'The error code was %s.' ),
- '
' . $failed['error_code'] . ''
- );
- return array(
- 'description' => $description,
- 'severity' => 'warning',
- );
- }
-
- /**
- * Check if WordPress is controlled by a VCS (Git, Subversion etc).
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function test_vcs_abspath() {
- $context_dirs = array( ABSPATH );
- $vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' );
- $check_dirs = array();
-
- foreach ( $context_dirs as $context_dir ) {
- // Walk up from $context_dir to the root.
- do {
- $check_dirs[] = $context_dir;
-
- // Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here.
- if ( dirname( $context_dir ) == $context_dir ) {
- break;
- }
-
- // Continue one level at a time.
- } while ( $context_dir = dirname( $context_dir ) );
- }
-
- $check_dirs = array_unique( $check_dirs );
-
- // Search all directories we've found for evidence of version control.
- foreach ( $vcs_dirs as $vcs_dir ) {
- foreach ( $check_dirs as $check_dir ) {
- // phpcs:ignore
- if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) {
- break 2;
- }
- }
- }
-
- /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
- if ( $checkout && ! apply_filters( 'automatic_updates_is_vcs_checkout', true, ABSPATH ) ) {
- return array(
- 'description' => sprintf(
- /* translators: 1: Folder name. 2: Version control directory. 3: Filter name. */
- __( 'The folder %1$s was detected as being under version control (%2$s), but the %3$s filter is allowing updates.' ),
- '
' . $check_dir . '',
- "
$vcs_dir",
- '
automatic_updates_is_vcs_checkout'
- ),
- 'severity' => 'info',
- );
- }
-
- if ( $checkout ) {
- return array(
- 'description' => sprintf(
- /* translators: 1: Folder name. 2: Version control directory. */
- __( 'The folder %1$s was detected as being under version control (%2$s).' ),
- '
' . $check_dir . '',
- "
$vcs_dir"
- ),
- 'severity' => 'warning',
- );
- }
-
- return array(
- 'description' => __( 'No version control systems were detected.' ),
- 'severity' => 'pass',
- );
- }
-
- /**
- * Check if we can access files without providing credentials.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- function test_check_wp_filesystem_method() {
- $skin = new Automatic_Upgrader_Skin;
- $success = $skin->request_filesystem_credentials( false, ABSPATH );
-
- if ( ! $success ) {
- $description = __( 'Your installation of WordPress prompts for FTP credentials to perform updates.' );
- $description .= ' ' . __( '(Your site is performing updates over FTP due to file ownership. Talk to your hosting company.)' );
-
- return array(
- 'description' => $description,
- 'severity' => 'fail',
- );
- }
-
- return array(
- 'description' => __( "Your installation of WordPress doesn't require FTP credentials to perform updates." ),
- 'severity' => 'pass',
- );
- }
-
- /**
- * Check if core files are writable by the web user/group.
- *
- * @since 5.2.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @return array|bool The test results. False if they're not writeable.
- */
- function test_all_files_writable() {
- global $wp_filesystem;
-
- include ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
-
- $skin = new Automatic_Upgrader_Skin;
- $success = $skin->request_filesystem_credentials( false, ABSPATH );
-
- if ( ! $success ) {
- return false;
- }
-
- WP_Filesystem();
-
- if ( 'direct' != $wp_filesystem->method ) {
- return false;
- }
-
- $checksums = get_core_checksums( $wp_version, 'en_US' );
- $dev = ( false !== strpos( $wp_version, '-' ) );
- // Get the last stable version's files and test against that
- if ( ! $checksums && $dev ) {
- $checksums = get_core_checksums( (float) $wp_version - 0.1, 'en_US' );
- }
-
- // There aren't always checksums for development releases, so just skip the test if we still can't find any
- if ( ! $checksums && $dev ) {
- return false;
- }
-
- if ( ! $checksums ) {
- $description = sprintf(
- /* translators: %s: WordPress version. */
- __( "Couldn't retrieve a list of the checksums for WordPress %s." ),
- $wp_version
- );
- $description .= ' ' . __( 'This could mean that connections are failing to WordPress.org.' );
- return array(
- 'description' => $description,
- 'severity' => 'warning',
- );
- }
-
- $unwritable_files = array();
- foreach ( array_keys( $checksums ) as $file ) {
- if ( 'wp-content' == substr( $file, 0, 10 ) ) {
- continue;
- }
- if ( ! file_exists( ABSPATH . $file ) ) {
- continue;
- }
- if ( ! is_writable( ABSPATH . $file ) ) {
- $unwritable_files[] = $file;
- }
- }
-
- if ( $unwritable_files ) {
- if ( count( $unwritable_files ) > 20 ) {
- $unwritable_files = array_slice( $unwritable_files, 0, 20 );
- $unwritable_files[] = '...';
- }
- return array(
- 'description' => __( 'Some files are not writable by WordPress:' ) . '
' . implode( ' ', $unwritable_files ) . ' ',
- 'severity' => 'fail',
- );
- } else {
- return array(
- 'description' => __( 'All of your WordPress files are writable.' ),
- 'severity' => 'pass',
- );
- }
- }
-
- /**
- * Check if the install is using a development branch and can use nightly packages.
- *
- * @since 5.2.0
- *
- * @return array|bool The test results. False if it isn't a development version.
- */
- function test_accepts_dev_updates() {
- include ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z
- // Only for dev versions
- if ( false === strpos( $wp_version, '-' ) ) {
- return false;
- }
-
- if ( defined( 'WP_AUTO_UPDATE_CORE' ) && ( 'minor' === WP_AUTO_UPDATE_CORE || false === WP_AUTO_UPDATE_CORE ) ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the constant used. */
- __( 'WordPress development updates are blocked by the %s constant.' ),
- '
WP_AUTO_UPDATE_CORE'
- ),
- 'severity' => 'fail',
- );
- }
-
- /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
- if ( ! apply_filters( 'allow_dev_auto_core_updates', $wp_version ) ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the filter used. */
- __( 'WordPress development updates are blocked by the %s filter.' ),
- '
allow_dev_auto_core_updates'
- ),
- 'severity' => 'fail',
- );
- }
- }
-
- /**
- * Check if the site supports automatic minor updates.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- function test_accepts_minor_updates() {
- if ( defined( 'WP_AUTO_UPDATE_CORE' ) && false === WP_AUTO_UPDATE_CORE ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the constant used. */
- __( 'WordPress security and maintenance releases are blocked by %s.' ),
- "
define( 'WP_AUTO_UPDATE_CORE', false );"
- ),
- 'severity' => 'fail',
- );
- }
-
- /** This filter is documented in wp-admin/includes/class-core-upgrader.php */
- if ( ! apply_filters( 'allow_minor_auto_core_updates', true ) ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the filter used. */
- __( 'WordPress security and maintenance releases are blocked by the %s filter.' ),
- '
allow_minor_auto_core_updates'
- ),
- 'severity' => 'fail',
- );
- }
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-site-health.php b/srcs/wordpress/wp-admin/includes/class-wp-site-health.php
deleted file mode 100644
index 62f089b..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-site-health.php
+++ /dev/null
@@ -1,2170 +0,0 @@
-prepare_sql_data();
-
- $this->timeout_late_cron = 0;
- $this->timeout_missed_cron = - 5 * MINUTE_IN_SECONDS;
-
- if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
- $this->timeout_late_cron = - 15 * MINUTE_IN_SECONDS;
- $this->timeout_missed_cron = - 1 * HOUR_IN_SECONDS;
- }
-
- add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
-
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
- }
-
- /**
- * Enqueues the site health scripts.
- *
- * @since 5.2.0
- */
- public function enqueue_scripts() {
- $screen = get_current_screen();
- if ( 'site-health' !== $screen->id ) {
- return;
- }
-
- $health_check_js_variables = array(
- 'screen' => $screen->id,
- 'nonce' => array(
- 'site_status' => wp_create_nonce( 'health-check-site-status' ),
- 'site_status_result' => wp_create_nonce( 'health-check-site-status-result' ),
- ),
- 'site_status' => array(
- 'direct' => array(),
- 'async' => array(),
- 'issues' => array(
- 'good' => 0,
- 'recommended' => 0,
- 'critical' => 0,
- ),
- ),
- );
-
- $issue_counts = get_transient( 'health-check-site-status-result' );
-
- if ( false !== $issue_counts ) {
- $issue_counts = json_decode( $issue_counts );
-
- $health_check_js_variables['site_status']['issues'] = $issue_counts;
- }
-
- if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) {
- $tests = WP_Site_Health::get_tests();
-
- // Don't run https test on localhost
- if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
- unset( $tests['direct']['https_status'] );
- }
-
- foreach ( $tests['direct'] as $test ) {
- if ( is_string( $test['test'] ) ) {
- $test_function = sprintf(
- 'get_test_%s',
- $test['test']
- );
-
- if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
- /**
- * Filter the output of a finished Site Health test.
- *
- * @since 5.3.0
- *
- * @param array $test_result {
- * An associated array of test result data.
- *
- * @param string $label A label describing the test, and is used as a header in the output.
- * @param string $status The status of the test, which can be a value of `good`, `recommended` or `critical`.
- * @param array $badge {
- * Tests are put into categories which have an associated badge shown, these can be modified and assigned here.
- *
- * @param string $label The test label, for example `Performance`.
- * @param string $color Default `blue`. A string representing a color to use for the label.
- * }
- * @param string $description A more descriptive explanation of what the test looks for, and why it is important for the end user.
- * @param string $actions An action to direct the user to where they can resolve the issue, if one exists.
- * @param string $test The name of the test being ran, used as a reference point.
- * }
- */
- $health_check_js_variables['site_status']['direct'][] = apply_filters( 'site_status_test_result', call_user_func( array( $this, $test_function ) ) );
- continue;
- }
- }
-
- if ( is_callable( $test['test'] ) ) {
- /** This filter is documented in wp-admin/includes/class-wp-site-health.php */
- $health_check_js_variables['site_status']['direct'][] = apply_filters( 'site_status_test_result', call_user_func( $test['test'] ) );
- }
- }
-
- foreach ( $tests['async'] as $test ) {
- if ( is_string( $test['test'] ) ) {
- $health_check_js_variables['site_status']['async'][] = array(
- 'test' => $test['test'],
- 'completed' => false,
- );
- }
- }
- }
-
- wp_localize_script( 'site-health', 'SiteHealth', $health_check_js_variables );
- }
-
- /**
- * Run the SQL version checks.
- *
- * These values are used in later tests, but the part of preparing them is more easily managed early
- * in the class for ease of access and discovery.
- *
- * @since 5.2.0
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- */
- private function prepare_sql_data() {
- global $wpdb;
-
- if ( $wpdb->use_mysqli ) {
- // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info
- $mysql_server_type = mysqli_get_server_info( $wpdb->dbh );
- } else {
- // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
- $mysql_server_type = mysql_get_server_info( $wpdb->dbh );
- }
-
- $this->mysql_server_version = $wpdb->get_var( 'SELECT VERSION()' );
-
- $this->health_check_mysql_rec_version = '5.6';
-
- if ( stristr( $mysql_server_type, 'mariadb' ) ) {
- $this->is_mariadb = true;
- $this->health_check_mysql_rec_version = '10.0';
- }
-
- $this->mysql_min_version_check = version_compare( '5.5', $this->mysql_server_version, '<=' );
- $this->mysql_rec_version_check = version_compare( $this->health_check_mysql_rec_version, $this->mysql_server_version, '<=' );
- }
-
- /**
- * Test if `wp_version_check` is blocked.
- *
- * It's possible to block updates with the `wp_version_check` filter, but this can't be checked during an
- * AJAX call, as the filter is never introduced then.
- *
- * This filter overrides a normal page request if it's made by an admin through the AJAX call with the
- * right query argument to check for this.
- *
- * @since 5.2.0
- */
- public function check_wp_version_check_exists() {
- if ( ! is_admin() || ! is_user_logged_in() || ! current_user_can( 'update_core' ) || ! isset( $_GET['health-check-test-wp_version_check'] ) ) {
- return;
- }
-
- echo ( has_filter( 'wp_version_check', 'wp_version_check' ) ? 'yes' : 'no' );
-
- die();
- }
-
- /**
- * Tests for WordPress version and outputs it.
- *
- * Gives various results depending on what kind of updates are available, if any, to encourage the
- * user to install security updates as a priority.
- *
- * @since 5.2.0
- *
- * @return array The test result.
- */
- public function get_test_wordpress_version() {
- $result = array(
- 'label' => '',
- 'status' => '',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => '',
- 'actions' => '',
- 'test' => 'wordpress_version',
- );
-
- $core_current_version = get_bloginfo( 'version' );
- $core_updates = get_core_updates();
-
- if ( ! is_array( $core_updates ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = sprintf(
- /* translators: %s: Your current version of WordPress. */
- __( 'WordPress version %s' ),
- $core_current_version
- );
-
- $result['description'] = sprintf(
- '
%s
',
- __( 'We were unable to check if any new versions of WordPress are available.' )
- );
-
- $result['actions'] = sprintf(
- '
%s ',
- esc_url( admin_url( 'update-core.php?force-check=1' ) ),
- __( 'Check for updates manually' )
- );
- } else {
- foreach ( $core_updates as $core => $update ) {
- if ( 'upgrade' === $update->response ) {
- $current_version = explode( '.', $core_current_version );
- $new_version = explode( '.', $update->version );
-
- $current_major = $current_version[0] . '.' . $current_version[1];
- $new_major = $new_version[0] . '.' . $new_version[1];
-
- $result['label'] = sprintf(
- /* translators: %s: The latest version of WordPress available. */
- __( 'WordPress update available (%s)' ),
- $update->version
- );
-
- $result['actions'] = sprintf(
- '
%s ',
- esc_url( admin_url( 'update-core.php' ) ),
- __( 'Install the latest version of WordPress' )
- );
-
- if ( $current_major !== $new_major ) {
- // This is a major version mismatch.
- $result['status'] = 'recommended';
- $result['description'] = sprintf(
- '
%s
',
- __( 'A new version of WordPress is available.' )
- );
- } else {
- // This is a minor version, sometimes considered more critical.
- $result['status'] = 'critical';
- $result['badge']['label'] = __( 'Security' );
- $result['description'] = sprintf(
- '
%s
',
- __( 'A new minor update is available for your site. Because minor updates often address security, it’s important to install them.' )
- );
- }
- } else {
- $result['status'] = 'good';
- $result['label'] = sprintf(
- /* translators: %s: The current version of WordPress installed on this site. */
- __( 'Your version of WordPress (%s) is up to date' ),
- $core_current_version
- );
-
- $result['description'] = sprintf(
- '
%s
',
- __( 'You are currently running the latest version of WordPress available, keep it up!' )
- );
- }
- }
- }
-
- return $result;
- }
-
- /**
- * Test if plugins are outdated, or unnecessary.
- *
- * The tests checks if your plugins are up to date, and encourages you to remove any that are not in use.
- *
- * @since 5.2.0
- *
- * @return array The test result.
- */
- public function get_test_plugin_version() {
- $result = array(
- 'label' => __( 'Your plugins are all up to date' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Security' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Plugins extend your site’s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it’s vital to keep them up to date.' )
- ),
- 'actions' => sprintf(
- '
%s
',
- esc_url( admin_url( 'plugins.php' ) ),
- __( 'Manage your plugins' )
- ),
- 'test' => 'plugin_version',
- );
-
- $plugins = get_plugins();
- $plugin_updates = get_plugin_updates();
-
- $plugins_have_updates = false;
- $plugins_active = 0;
- $plugins_total = 0;
- $plugins_need_update = 0;
-
- // Loop over the available plugins and check their versions and active state.
- foreach ( $plugins as $plugin_path => $plugin ) {
- $plugins_total++;
-
- if ( is_plugin_active( $plugin_path ) ) {
- $plugins_active++;
- }
-
- $plugin_version = $plugin['Version'];
-
- if ( array_key_exists( $plugin_path, $plugin_updates ) ) {
- $plugins_need_update++;
- $plugins_have_updates = true;
- }
- }
-
- // Add a notice if there are outdated plugins.
- if ( $plugins_need_update > 0 ) {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'You have plugins waiting to be updated' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %d: The number of outdated plugins. */
- _n(
- 'Your site has %d plugin waiting to be updated.',
- 'Your site has %d plugins waiting to be updated.',
- $plugins_need_update
- ),
- $plugins_need_update
- )
- );
-
- $result['actions'] .= sprintf(
- '
%s
',
- esc_url( network_admin_url( 'plugins.php?plugin_status=upgrade' ) ),
- __( 'Update your plugins' )
- );
- } else {
- if ( 1 === $plugins_active ) {
- $result['description'] .= sprintf(
- '
%s
',
- __( 'Your site has 1 active plugin, and it is up to date.' )
- );
- } else {
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %d: The number of active plugins. */
- _n(
- 'Your site has %d active plugin, and it is up to date.',
- 'Your site has %d active plugins, and they are all up to date.',
- $plugins_active
- ),
- $plugins_active
- )
- );
- }
- }
-
- // Check if there are inactive plugins.
- if ( $plugins_total > $plugins_active && ! is_multisite() ) {
- $unused_plugins = $plugins_total - $plugins_active;
-
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'You should remove inactive plugins' );
-
- $result['description'] .= sprintf(
- '
%s %s
',
- sprintf(
- /* translators: %d: The number of inactive plugins. */
- _n(
- 'Your site has %d inactive plugin.',
- 'Your site has %d inactive plugins.',
- $unused_plugins
- ),
- $unused_plugins
- ),
- __( 'Inactive plugins are tempting targets for attackers. If you’re not going to use a plugin, we recommend you remove it.' )
- );
-
- $result['actions'] .= sprintf(
- '
%s
',
- esc_url( admin_url( 'plugins.php?plugin_status=inactive' ) ),
- __( 'Manage inactive plugins' )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if themes are outdated, or unnecessary.
- *
- * The tests checks if your site has a default theme (to fall back on if there is a need), if your themes
- * are up to date and, finally, encourages you to remove any themes that are not needed.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_theme_version() {
- $result = array(
- 'label' => __( 'Your themes are all up to date' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Security' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Themes add your site’s look and feel. It’s important to keep them up to date, to stay consistent with your brand and keep your site secure.' )
- ),
- 'actions' => sprintf(
- '
%s
',
- esc_url( admin_url( 'themes.php' ) ),
- __( 'Manage your themes' )
- ),
- 'test' => 'theme_version',
- );
-
- $theme_updates = get_theme_updates();
-
- $themes_total = 0;
- $themes_need_updates = 0;
- $themes_inactive = 0;
-
- // This value is changed during processing to determine how many themes are considered a reasonable amount.
- $allowed_theme_count = 1;
-
- $has_default_theme = false;
- $has_unused_themes = false;
- $show_unused_themes = true;
- $using_default_theme = false;
-
- // Populate a list of all themes available in the install.
- $all_themes = wp_get_themes();
- $active_theme = wp_get_theme();
-
- // If WP_DEFAULT_THEME doesn't exist, fall back to the latest core default theme.
- $default_theme = wp_get_theme( WP_DEFAULT_THEME );
- if ( ! $default_theme->exists() ) {
- $default_theme = WP_Theme::get_core_default_theme();
- }
-
- if ( $default_theme ) {
- $has_default_theme = true;
-
- if (
- $active_theme->get_stylesheet() === $default_theme->get_stylesheet()
- ||
- is_child_theme() && $active_theme->get_template() === $default_theme->get_template()
- ) {
- $using_default_theme = true;
- }
- }
-
- foreach ( $all_themes as $theme_slug => $theme ) {
- $themes_total++;
-
- if ( array_key_exists( $theme_slug, $theme_updates ) ) {
- $themes_need_updates++;
- }
- }
-
- // If this is a child theme, increase the allowed theme count by one, to account for the parent.
- if ( is_child_theme() ) {
- $allowed_theme_count++;
- }
-
- // If there's a default theme installed and not in use, we count that as allowed as well.
- if ( $has_default_theme && ! $using_default_theme ) {
- $allowed_theme_count++;
- }
-
- if ( $themes_total > $allowed_theme_count ) {
- $has_unused_themes = true;
- $themes_inactive = ( $themes_total - $allowed_theme_count );
- }
-
- // Check if any themes need to be updated.
- if ( $themes_need_updates > 0 ) {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'You have themes waiting to be updated' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %d: The number of outdated themes. */
- _n(
- 'Your site has %d theme waiting to be updated.',
- 'Your site has %d themes waiting to be updated.',
- $themes_need_updates
- ),
- $themes_need_updates
- )
- );
- } else {
- // Give positive feedback about the site being good about keeping things up to date.
- if ( 1 === $themes_total ) {
- $result['description'] .= sprintf(
- '
%s
',
- __( 'Your site has 1 installed theme, and it is up to date.' )
- );
- } else {
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %d: The number of themes. */
- _n(
- 'Your site has %d installed theme, and it is up to date.',
- 'Your site has %d installed themes, and they are all up to date.',
- $themes_total
- ),
- $themes_total
- )
- );
- }
- }
-
- if ( $has_unused_themes && $show_unused_themes && ! is_multisite() ) {
-
- // This is a child theme, so we want to be a bit more explicit in our messages.
- if ( is_child_theme() ) {
- // Recommend removing inactive themes, except a default theme, your current one, and the parent theme.
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'You should remove inactive themes' );
-
- if ( $using_default_theme ) {
- $result['description'] .= sprintf(
- '
%s %s
',
- sprintf(
- /* translators: %d: The number of inactive themes. */
- _n(
- 'Your site has %d inactive theme.',
- 'Your site has %d inactive themes.',
- $themes_inactive
- ),
- $themes_inactive
- ),
- sprintf(
- /* translators: 1: The currently active theme. 2: The active theme's parent theme. */
- __( 'To enhance your site’s security, we recommend you remove any themes you’re not using. You should keep your current theme, %1$s, and %2$s, its parent theme.' ),
- $active_theme->name,
- $active_theme->parent()->name
- )
- );
- } else {
- $result['description'] .= sprintf(
- '
%s %s
',
- sprintf(
- /* translators: %d: The number of inactive themes. */
- _n(
- 'Your site has %d inactive theme.',
- 'Your site has %d inactive themes.',
- $themes_inactive
- ),
- $themes_inactive
- ),
- sprintf(
- /* translators: 1: The default theme for WordPress. 2: The currently active theme. 3: The active theme's parent theme. */
- __( 'To enhance your site’s security, we recommend you remove any themes you’re not using. You should keep %1$s, the default WordPress theme, %2$s, your current theme, and %3$s, its parent theme.' ),
- $default_theme ? $default_theme->name : WP_DEFAULT_THEME,
- $active_theme->name,
- $active_theme->parent()->name
- )
- );
- }
- } else {
- // Recommend removing all inactive themes.
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'You should remove inactive themes' );
-
- if ( $using_default_theme ) {
- $result['description'] .= sprintf(
- '
%s %s
',
- sprintf(
- /* translators: 1: The amount of inactive themes. 2: The currently active theme. */
- _n(
- 'Your site has %1$d inactive theme, other than %2$s, your active theme.',
- 'Your site has %1$d inactive themes, other than %2$s, your active theme.',
- $themes_inactive
- ),
- $themes_inactive,
- $active_theme->name
- ),
- __( 'We recommend removing any unused themes to enhance your site’s security.' )
- );
- } else {
- $result['description'] .= sprintf(
- '
%s %s
',
- sprintf(
- /* translators: 1: The amount of inactive themes. 2: The default theme for WordPress. 3: The currently active theme. */
- _n(
- 'Your site has %1$d inactive theme, other than %2$s, the default WordPress theme, and %3$s, your active theme.',
- 'Your site has %1$d inactive themes, other than %2$s, the default WordPress theme, and %3$s, your active theme.',
- $themes_inactive
- ),
- $themes_inactive,
- $default_theme ? $default_theme->name : WP_DEFAULT_THEME,
- $active_theme->name
- ),
- __( 'We recommend removing any unused themes to enhance your site’s security.' )
- );
- }
- }
- }
-
- // If no default Twenty* theme exists.
- if ( ! $has_default_theme ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'Have a default theme available' );
-
- $result['description'] .= sprintf(
- '
%s
',
- __( 'Your site does not have any default theme. Default themes are used by WordPress automatically if anything is wrong with your normal theme.' )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if the supplied PHP version is supported.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_php_version() {
- $response = wp_check_php_version();
-
- $result = array(
- 'label' => sprintf(
- /* translators: %s: The current PHP version. */
- __( 'Your version of PHP (%s) is up to date' ),
- PHP_VERSION
- ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: The minimum recommended PHP version. */
- __( 'PHP is the programming language used to build and maintain WordPress. Newer versions of PHP are faster and more secure, so staying up to date will help your site’s overall performance and security. The minimum recommended version of PHP is %s.' ),
- $response['recommended_version']
- )
- ),
- 'actions' => sprintf(
- '
%s %s
',
- esc_url( wp_get_update_php_url() ),
- __( 'Learn more about updating PHP' ),
- /* translators: Accessibility text. */
- __( '(opens in a new tab)' )
- ),
- 'test' => 'php_version',
- );
-
- // PHP is up to date.
- if ( ! $response || version_compare( PHP_VERSION, $response['recommended_version'], '>=' ) ) {
- return $result;
- }
-
- // The PHP version is older than the recommended version, but still receiving active support.
- if ( $response['is_supported'] ) {
- $result['label'] = sprintf(
- /* translators: %s: The server PHP version. */
- __( 'Your version of PHP (%s) is out of date' ),
- PHP_VERSION
- );
- $result['status'] = 'recommended';
-
- return $result;
- }
-
- // The PHP version is only receiving security fixes.
- if ( $response['is_secure'] ) {
- $result['label'] = sprintf(
- /* translators: %s: The server PHP version. */
- __( 'Your version of PHP (%s) should be updated' ),
- PHP_VERSION
- );
- $result['status'] = 'recommended';
-
- return $result;
- }
-
- // Anything no longer secure must be updated.
- $result['label'] = sprintf(
- /* translators: %s: The server PHP version. */
- __( 'Your version of PHP (%s) requires an update' ),
- PHP_VERSION
- );
- $result['status'] = 'critical';
- $result['badge']['label'] = __( 'Security' );
-
- return $result;
- }
-
- /**
- * Check if the passed extension or function are available.
- *
- * Make the check for available PHP modules into a simple boolean operator for a cleaner test runner.
- *
- * @since 5.2.0
- * @since 5.3.0 The `$constant` and `$class` parameters were added.
- *
- * @param string $extension Optional. The extension name to test. Default null.
- * @param string $function Optional. The function name to test. Default null.
- * @param string $constant Optional. The constant name to test for. Default null.
- * @param string $class Optional. The class name to test for. Default null.
- *
- * @return bool Whether or not the extension and function are available.
- */
- private function test_php_extension_availability( $extension = null, $function = null, $constant = null, $class = null ) {
- // If no extension or function is passed, claim to fail testing, as we have nothing to test against.
- if ( ! $extension && ! $function && ! $constant && ! $class ) {
- return false;
- }
-
- if ( $extension && ! extension_loaded( $extension ) ) {
- return false;
- }
- if ( $function && ! function_exists( $function ) ) {
- return false;
- }
- if ( $constant && ! defined( $constant ) ) {
- return false;
- }
- if ( $class && ! class_exists( $class ) ) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Test if required PHP modules are installed on the host.
- *
- * This test builds on the recommendations made by the WordPress Hosting Team
- * as seen at https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions
- *
- * @since 5.2.0
- *
- * @return array
- */
- public function get_test_php_extensions() {
- $result = array(
- 'label' => __( 'Required and recommended modules are installed' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
%s
',
- __( 'PHP modules perform most of the tasks on the server that make your site run. Any changes to these must be made by your server administrator.' ),
- sprintf(
- /* translators: 1: Link to the hosting group page about recommended PHP modules. 2: Additional link attributes. 3: Accessibility text. */
- __( 'The WordPress Hosting Team maintains a list of those modules, both recommended and required, in
the team handbook%3$s .' ),
- /* translators: Localized team handbook, if one exists. */
- esc_url( __( 'https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions' ) ),
- 'target="_blank" rel="noopener noreferrer"',
- sprintf(
- '
%s ',
- /* translators: Accessibility text. */
- __( '(opens in a new tab)' )
- )
- )
- ),
- 'actions' => '',
- 'test' => 'php_extensions',
- );
-
- $modules = array(
- 'curl' => array(
- 'function' => 'curl_version',
- 'required' => false,
- ),
- 'dom' => array(
- 'class' => 'DOMNode',
- 'required' => false,
- ),
- 'exif' => array(
- 'function' => 'exif_read_data',
- 'required' => false,
- ),
- 'fileinfo' => array(
- 'function' => 'finfo_file',
- 'required' => false,
- ),
- 'hash' => array(
- 'function' => 'hash',
- 'required' => false,
- ),
- 'json' => array(
- 'function' => 'json_last_error',
- 'required' => true,
- ),
- 'mbstring' => array(
- 'function' => 'mb_check_encoding',
- 'required' => false,
- ),
- 'mysqli' => array(
- 'function' => 'mysqli_connect',
- 'required' => false,
- ),
- 'libsodium' => array(
- 'constant' => 'SODIUM_LIBRARY_VERSION',
- 'required' => false,
- 'php_bundled_version' => '7.2.0',
- ),
- 'openssl' => array(
- 'function' => 'openssl_encrypt',
- 'required' => false,
- ),
- 'pcre' => array(
- 'function' => 'preg_match',
- 'required' => false,
- ),
- 'imagick' => array(
- 'extension' => 'imagick',
- 'required' => false,
- ),
- 'mod_xml' => array(
- 'extension' => 'libxml',
- 'required' => false,
- ),
- 'zip' => array(
- 'class' => 'ZipArchive',
- 'required' => false,
- ),
- 'filter' => array(
- 'function' => 'filter_list',
- 'required' => false,
- ),
- 'gd' => array(
- 'extension' => 'gd',
- 'required' => false,
- 'fallback_for' => 'imagick',
- ),
- 'iconv' => array(
- 'function' => 'iconv',
- 'required' => false,
- ),
- 'mcrypt' => array(
- 'extension' => 'mcrypt',
- 'required' => false,
- 'fallback_for' => 'libsodium',
- ),
- 'simplexml' => array(
- 'extension' => 'simplexml',
- 'required' => false,
- 'fallback_for' => 'mod_xml',
- ),
- 'xmlreader' => array(
- 'extension' => 'xmlreader',
- 'required' => false,
- 'fallback_for' => 'mod_xml',
- ),
- 'zlib' => array(
- 'extension' => 'zlib',
- 'required' => false,
- 'fallback_for' => 'zip',
- ),
- );
-
- /**
- * An array representing all the modules we wish to test for.
- *
- * @since 5.2.0
- * @since 5.3.0 The `$constant` and `$class` parameters were added.
- *
- * @param array $modules {
- * An associated array of modules to test for.
- *
- * array $module {
- * An associated array of module properties used during testing.
- * One of either `$function` or `$extension` must be provided, or they will fail by default.
- *
- * string $function Optional. A function name to test for the existence of.
- * string $extension Optional. An extension to check if is loaded in PHP.
- * string $constant Optional. A constant name to check for to verify an extension exists.
- * string $class Optional. A class name to check for to verify an extension exists.
- * bool $required Is this a required feature or not.
- * string $fallback_for Optional. The module this module replaces as a fallback.
- * }
- * }
- */
- $modules = apply_filters( 'site_status_test_php_modules', $modules );
-
- $failures = array();
-
- foreach ( $modules as $library => $module ) {
- $extension = ( isset( $module['extension'] ) ? $module['extension'] : null );
- $function = ( isset( $module['function'] ) ? $module['function'] : null );
- $constant = ( isset( $module['constant'] ) ? $module['constant'] : null );
- $class_name = ( isset( $module['class'] ) ? $module['class'] : null );
-
- // If this module is a fallback for another function, check if that other function passed.
- if ( isset( $module['fallback_for'] ) ) {
- /*
- * If that other function has a failure, mark this module as required for normal operations.
- * If that other function hasn't failed, skip this test as it's only a fallback.
- */
- if ( isset( $failures[ $module['fallback_for'] ] ) ) {
- $module['required'] = true;
- } else {
- continue;
- }
- }
-
- if ( ! $this->test_php_extension_availability( $extension, $function, $constant, $class_name ) && ( ! isset( $module['php_bundled_version'] ) || version_compare( PHP_VERSION, $module['php_bundled_version'], '<' ) ) ) {
- if ( $module['required'] ) {
- $result['status'] = 'critical';
-
- $class = 'error';
- $screen_reader = __( 'Error' );
- $message = sprintf(
- /* translators: %s: The module name. */
- __( 'The required module, %s, is not installed, or has been disabled.' ),
- $library
- );
- } else {
- $class = 'warning';
- $screen_reader = __( 'Warning' );
- $message = sprintf(
- /* translators: %s: The module name. */
- __( 'The optional module, %s, is not installed, or has been disabled.' ),
- $library
- );
- }
-
- if ( ! $module['required'] && 'good' === $result['status'] ) {
- $result['status'] = 'recommended';
- }
-
- $failures[ $library ] = "
$screen_reader $message";
- }
- }
-
- if ( ! empty( $failures ) ) {
- $output = '
';
-
- foreach ( $failures as $failure ) {
- $output .= sprintf(
- '%s ',
- $failure
- );
- }
-
- $output .= ' ';
- }
-
- if ( 'good' !== $result['status'] ) {
- if ( 'recommended' === $result['status'] ) {
- $result['label'] = __( 'One or more recommended modules are missing' );
- }
- if ( 'critical' === $result['status'] ) {
- $result['label'] = __( 'One or more required modules are missing' );
- }
-
- $result['description'] .= sprintf(
- '
%s
',
- $output
- );
- }
-
- return $result;
- }
-
- /**
- * Test if the PHP default timezone is set to UTC.
- *
- * @since 5.3.1
- *
- * @return array The test results.
- */
- public function get_test_php_default_timezone() {
- $result = array(
- 'label' => __( 'PHP default timezone is valid' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'PHP default timezone was configured by WordPress on loading. This is necessary for correct calculations of dates and times.' )
- ),
- 'test' => 'php_default_timezone',
- );
-
- if ( 'UTC' !== date_default_timezone_get() ) {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'PHP default timezone is invalid' );
-
- $result['description'] = sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: date_default_timezone_set() */
- __( 'PHP default timezone was changed after WordPress loading by a %s function call. This interferes with correct calculations of dates and times.' ),
- '
date_default_timezone_set()'
- )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if the SQL server is up to date.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_sql_server() {
- $result = array(
- 'label' => __( 'SQL server is up to date' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'The SQL server is a required piece of software for the database WordPress uses to store all your site’s content and settings.' )
- ),
- 'actions' => sprintf(
- '
%s %s
',
- /* translators: Localized version of WordPress requirements if one exists. */
- esc_url( __( 'https://wordpress.org/about/requirements/' ) ),
- __( 'Learn more about what WordPress requires to run.' ),
- /* translators: Accessibility text. */
- __( '(opens in a new tab)' )
- ),
- 'test' => 'sql_server',
- );
-
- $db_dropin = file_exists( WP_CONTENT_DIR . '/db.php' );
-
- if ( ! $this->mysql_rec_version_check ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'Outdated SQL server' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server recommended version number. */
- __( 'For optimal performance and security reasons, we recommend running %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
- ( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
- $this->health_check_mysql_rec_version
- )
- );
- }
-
- if ( ! $this->mysql_min_version_check ) {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'Severely outdated SQL server' );
- $result['badge']['label'] = __( 'Security' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server minimum version number. */
- __( 'WordPress requires %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
- ( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
- $this->health_check_mysql_required_version
- )
- );
- }
-
- if ( $db_dropin ) {
- $result['description'] .= sprintf(
- '
%s
',
- wp_kses(
- sprintf(
- /* translators: 1: The name of the drop-in. 2: The name of the database engine. */
- __( 'You are using a %1$s drop-in which might mean that a %2$s database is not being used.' ),
- '
wp-content/db.php',
- ( $this->is_mariadb ? 'MariaDB' : 'MySQL' )
- ),
- array(
- 'code' => true,
- )
- )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if the database server is capable of using utf8mb4.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_utf8mb4_support() {
- global $wpdb;
-
- $result = array(
- 'label' => __( 'UTF8MB4 is supported' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'UTF8MB4 is the character set WordPress prefers for database storage because it safely supports the widest set of characters and encodings, including Emoji, enabling better support for non-English languages.' )
- ),
- 'actions' => '',
- 'test' => 'utf8mb4_support',
- );
-
- if ( ! $this->is_mariadb ) {
- if ( version_compare( $this->mysql_server_version, '5.5.3', '<' ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'utf8mb4 requires a MySQL update' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: Version number. */
- __( 'WordPress’ utf8mb4 support requires MySQL version %s or greater. Please contact your server administrator.' ),
- '5.5.3'
- )
- );
- } else {
- $result['description'] .= sprintf(
- '
%s
',
- __( 'Your MySQL version supports utf8mb4.' )
- );
- }
- } else { // MariaDB introduced utf8mb4 support in 5.5.0
- if ( version_compare( $this->mysql_server_version, '5.5.0', '<' ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'utf8mb4 requires a MariaDB update' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: Version number. */
- __( 'WordPress’ utf8mb4 support requires MariaDB version %s or greater. Please contact your server administrator.' ),
- '5.5.0'
- )
- );
- } else {
- $result['description'] .= sprintf(
- '
%s
',
- __( 'Your MariaDB version supports utf8mb4.' )
- );
- }
- }
-
- if ( $wpdb->use_mysqli ) {
- // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info
- $mysql_client_version = mysqli_get_client_info();
- } else {
- // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
- $mysql_client_version = mysql_get_client_info();
- }
-
- /*
- * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
- * mysqlnd has supported utf8mb4 since 5.0.9.
- */
- if ( false !== strpos( $mysql_client_version, 'mysqlnd' ) ) {
- $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version );
- if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'utf8mb4 requires a newer client library' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: 1: Name of the library, 2: Number of version. */
- __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),
- 'mysqlnd',
- '5.0.9'
- )
- );
- }
- } else {
- if ( version_compare( $mysql_client_version, '5.5.3', '<' ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'utf8mb4 requires a newer client library' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: 1: Name of the library, 2: Number of version. */
- __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),
- 'libmysql',
- '5.5.3'
- )
- );
- }
- }
-
- return $result;
- }
-
- /**
- * Test if the site can communicate with WordPress.org.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_dotorg_communication() {
- $result = array(
- 'label' => __( 'Can communicate with WordPress.org' ),
- 'status' => '',
- 'badge' => array(
- 'label' => __( 'Security' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Communicating with the WordPress servers is used to check for new versions, and to both install and update WordPress core, themes or plugins.' )
- ),
- 'actions' => '',
- 'test' => 'dotorg_communication',
- );
-
- $wp_dotorg = wp_remote_get(
- 'https://api.wordpress.org',
- array(
- 'timeout' => 10,
- )
- );
- if ( ! is_wp_error( $wp_dotorg ) ) {
- $result['status'] = 'good';
- } else {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'Could not reach WordPress.org' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- '
%s %s',
- __( 'Error' ),
- sprintf(
- /* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
- __( 'Your site is unable to reach WordPress.org at %1$s, and returned the error: %2$s' ),
- gethostbyname( 'api.wordpress.org' ),
- $wp_dotorg->get_error_message()
- )
- )
- );
-
- $result['actions'] = sprintf(
- '
%s %s
',
- /* translators: Localized Support reference. */
- esc_url( __( 'https://wordpress.org/support' ) ),
- __( 'Get help resolving this issue.' ),
- /* translators: Accessibility text. */
- __( '(opens in a new tab)' )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if debug information is enabled.
- *
- * When WP_DEBUG is enabled, errors and information may be disclosed to site visitors, or it may be
- * logged to a publicly accessible file.
- *
- * Debugging is also frequently left enabled after looking for errors on a site, as site owners do
- * not understand the implications of this.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_is_in_debug_mode() {
- $result = array(
- 'label' => __( 'Your site is not set to output debug information' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Security' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Debug mode is often enabled to gather more details about an error or site failure, but may contain sensitive information which should not be available on a publicly available website.' )
- ),
- 'actions' => sprintf(
- '
%s %s
',
- /* translators: Documentation explaining debugging in WordPress. */
- esc_url( __( 'https://wordpress.org/support/article/debugging-in-wordpress/' ) ),
- __( 'Learn more about debugging in WordPress.' ),
- /* translators: Accessibility text. */
- __( '(opens in a new tab)' )
- ),
- 'test' => 'is_in_debug_mode',
- );
-
- if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
- if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
- $result['label'] = __( 'Your site is set to log errors to a potentially public file.' );
-
- $result['status'] = 'critical';
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: WP_DEBUG_LOG */
- __( 'The value, %s, has been added to this website’s configuration file. This means any errors on the site will be written to a file which is potentially available to normal users.' ),
- '
WP_DEBUG_LOG'
- )
- );
- }
-
- if ( defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY ) {
- $result['label'] = __( 'Your site is set to display errors to site visitors' );
-
- $result['status'] = 'critical';
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: 1: WP_DEBUG_DISPLAY, 2: WP_DEBUG */
- __( 'The value, %1$s, has either been enabled by %2$s or added to your configuration file. This will make errors display on the front end of your site.' ),
- '
WP_DEBUG_DISPLAY',
- '
WP_DEBUG'
- )
- );
- }
- }
-
- return $result;
- }
-
- /**
- * Test if your site is serving content over HTTPS.
- *
- * Many sites have varying degrees of HTTPS support, the most common of which is sites that have it
- * enabled, but only if you visit the right site address.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_https_status() {
- $result = array(
- 'label' => __( 'Your website is using an active HTTPS connection.' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Security' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'An HTTPS connection is a more secure way of browsing the web. Many services now have HTTPS as a requirement. HTTPS allows you to take advantage of new features that can increase site speed, improve search rankings, and gain the trust of your visitors by helping to protect their online privacy.' )
- ),
- 'actions' => sprintf(
- '
%s %s
',
- /* translators: Documentation explaining HTTPS and why it should be used. */
- esc_url( __( 'https://wordpress.org/support/article/why-should-i-use-https/' ) ),
- __( 'Learn more about why you should use HTTPS' ),
- /* translators: Accessibility text. */
- __( '(opens in a new tab)' )
- ),
- 'test' => 'https_status',
- );
-
- if ( is_ssl() ) {
- $wp_url = get_bloginfo( 'wpurl' );
- $site_url = get_bloginfo( 'url' );
-
- if ( 'https' !== substr( $wp_url, 0, 5 ) || 'https' !== substr( $site_url, 0, 5 ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'Only parts of your site are using HTTPS' );
-
- $result['description'] = sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: URL to General Settings screen. */
- __( 'You are accessing this website using HTTPS, but your
WordPress Address is not set up to use HTTPS by default.' ),
- esc_url( admin_url( 'options-general.php' ) )
- )
- );
-
- $result['actions'] .= sprintf(
- '
%s
',
- esc_url( admin_url( 'options-general.php' ) ),
- __( 'Update your site addresses' )
- );
- }
- } else {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'Your site does not use HTTPS' );
- }
-
- return $result;
- }
-
- /**
- * Check if the HTTP API can handle SSL/TLS requests.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_ssl_support() {
- $result = array(
- 'label' => '',
- 'status' => '',
- 'badge' => array(
- 'label' => __( 'Security' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Securely communicating between servers are needed for transactions such as fetching files, conducting sales on store sites, and much more.' )
- ),
- 'actions' => '',
- 'test' => 'ssl_support',
- );
-
- $supports_https = wp_http_supports( array( 'ssl' ) );
-
- if ( $supports_https ) {
- $result['status'] = 'good';
-
- $result['label'] = __( 'Your site can communicate securely with other services' );
- } else {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'Your site is unable to communicate securely with other services' );
-
- $result['description'] .= sprintf(
- '
%s
',
- __( 'Talk to your web host about OpenSSL support for PHP.' )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if scheduled events run as intended.
- *
- * If scheduled events are not running, this may indicate something with WP_Cron is not working as intended,
- * or that there are orphaned events hanging around from older code.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_scheduled_events() {
- $result = array(
- 'label' => __( 'Scheduled events are running' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Scheduled events are what periodically looks for updates to plugins, themes and WordPress itself. It is also what makes sure scheduled posts are published on time. It may also be used by various plugins to make sure that planned actions are executed.' )
- ),
- 'actions' => '',
- 'test' => 'scheduled_events',
- );
-
- $this->wp_schedule_test_init();
-
- if ( is_wp_error( $this->has_missed_cron() ) ) {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'It was not possible to check your scheduled events' );
-
- $result['description'] = sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: The error message returned while from the cron scheduler. */
- __( 'While trying to test your site’s scheduled events, the following error was returned: %s' ),
- $this->has_missed_cron()->get_error_message()
- )
- );
- } elseif ( $this->has_missed_cron() ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'A scheduled event has failed' );
-
- $result['description'] = sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: The name of the failed cron event. */
- __( 'The scheduled event, %s, failed to run. Your site still works, but this may indicate that scheduling posts or automated updates may not work as intended.' ),
- $this->last_missed_cron
- )
- );
- } elseif ( $this->has_late_cron() ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'A scheduled event is late' );
-
- $result['description'] = sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: The name of the late cron event. */
- __( 'The scheduled event, %s, is late to run. Your site still works, but this may indicate that scheduling posts or automated updates may not work as intended.' ),
- $this->last_late_cron
- )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if WordPress can run automated background updates.
- *
- * Background updates in WordPress are primarily used for minor releases and security updates. It's important
- * to either have these working, or be aware that they are intentionally disabled for whatever reason.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_background_updates() {
- $result = array(
- 'label' => __( 'Background updates are working' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Security' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Background updates ensure that WordPress can auto-update if a security update is released for the version you are currently using.' )
- ),
- 'actions' => '',
- 'test' => 'background_updates',
- );
-
- if ( ! class_exists( 'WP_Site_Health_Auto_Updates' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/class-wp-site-health-auto-updates.php' );
- }
-
- // Run the auto-update tests in a separate class,
- // as there are many considerations to be made.
- $automatic_updates = new WP_Site_Health_Auto_Updates();
- $tests = $automatic_updates->run_tests();
-
- $output = '
';
-
- foreach ( $tests as $test ) {
- $severity_string = __( 'Passed' );
-
- if ( 'fail' === $test->severity ) {
- $result['label'] = __( 'Background updates are not working as expected' );
-
- $result['status'] = 'critical';
-
- $severity_string = __( 'Error' );
- }
-
- if ( 'warning' === $test->severity && 'good' === $result['status'] ) {
- $result['label'] = __( 'Background updates may not be working properly' );
-
- $result['status'] = 'recommended';
-
- $severity_string = __( 'Warning' );
- }
-
- $output .= sprintf(
- '%s %s ',
- esc_attr( $test->severity ),
- $severity_string,
- $test->description
- );
- }
-
- $output .= ' ';
-
- if ( 'good' !== $result['status'] ) {
- $result['description'] .= sprintf(
- '
%s
',
- $output
- );
- }
-
- return $result;
- }
-
- /**
- * Test if loopbacks work as expected.
- *
- * A loopback is when WordPress queries itself, for example to start a new WP_Cron instance, or when editing a
- * plugin or theme. This has shown itself to be a recurring issue as code can very easily break this interaction.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_loopback_requests() {
- $result = array(
- 'label' => __( 'Your site can perform loopback requests' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'Loopback requests are used to run scheduled events, and are also used by the built-in editors for themes and plugins to verify code stability.' )
- ),
- 'actions' => '',
- 'test' => 'loopback_requests',
- );
-
- $check_loopback = $this->can_perform_loopback();
-
- $result['status'] = $check_loopback->status;
-
- if ( 'good' !== $check_loopback->status ) {
- $result['label'] = __( 'Your site could not complete a loopback request' );
-
- $result['description'] .= sprintf(
- '
%s
',
- $check_loopback->message
- );
- }
-
- return $result;
- }
-
- /**
- * Test if HTTP requests are blocked.
- *
- * It's possible to block all outgoing communication (with the possibility of whitelisting hosts) via the
- * HTTP API. This may create problems for users as many features are running as services these days.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_http_requests() {
- $result = array(
- 'label' => __( 'HTTP requests seem to be working as expected' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'It is possible for site maintainers to block all, or some, communication to other sites and services. If set up incorrectly, this may prevent plugins and themes from working as intended.' )
- ),
- 'actions' => '',
- 'test' => 'http_requests',
- );
-
- $blocked = false;
- $hosts = array();
-
- if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) {
- $blocked = true;
- }
-
- if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
- $hosts = explode( ',', WP_ACCESSIBLE_HOSTS );
- }
-
- if ( $blocked && 0 === sizeof( $hosts ) ) {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'HTTP requests are blocked' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: Name of the constant used. */
- __( 'HTTP requests have been blocked by the %s constant, with no allowed hosts.' ),
- '
WP_HTTP_BLOCK_EXTERNAL'
- )
- );
- }
-
- if ( $blocked && 0 < sizeof( $hosts ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'HTTP requests are partially blocked' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: 1: Name of the constant used. 2: List of hostnames whitelisted. */
- __( 'HTTP requests have been blocked by the %1$s constant, with some hosts whitelisted: %2$s.' ),
- '
WP_HTTP_BLOCK_EXTERNAL',
- implode( ',', $hosts )
- )
- );
- }
-
- return $result;
- }
-
- /**
- * Test if the REST API is accessible.
- *
- * Various security measures may block the REST API from working, or it may have been disabled in general.
- * This is required for the new block editor to work, so we explicitly test for this.
- *
- * @since 5.2.0
- *
- * @return array The test results.
- */
- public function get_test_rest_availability() {
- $result = array(
- 'label' => __( 'The REST API is available' ),
- 'status' => 'good',
- 'badge' => array(
- 'label' => __( 'Performance' ),
- 'color' => 'blue',
- ),
- 'description' => sprintf(
- '
%s
',
- __( 'The REST API is one way WordPress, and other applications, communicate with the server. One example is the block editor screen, which relies on this to display, and save, your posts and pages.' )
- ),
- 'actions' => '',
- 'test' => 'rest_availability',
- );
-
- $cookies = wp_unslash( $_COOKIE );
- $timeout = 10;
- $headers = array(
- 'Cache-Control' => 'no-cache',
- 'X-WP-Nonce' => wp_create_nonce( 'wp_rest' ),
- );
- /** This filter is documented in wp-includes/class-wp-http-streams.php */
- $sslverify = apply_filters( 'https_local_ssl_verify', false );
-
- // Include Basic auth in loopback requests.
- if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
- $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
- }
-
- $url = rest_url( 'wp/v2/types/post' );
-
- // The context for this is editing with the new block editor.
- $url = add_query_arg(
- array(
- 'context' => 'edit',
- ),
- $url
- );
-
- $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
-
- if ( is_wp_error( $r ) ) {
- $result['status'] = 'critical';
-
- $result['label'] = __( 'The REST API encountered an error' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- '%s
%s',
- __( 'The REST API request failed due to an error.' ),
- sprintf(
- /* translators: 1: The HTTP response code. 2: The error message returned. */
- __( 'Error: [%1$s] %2$s' ),
- wp_remote_retrieve_response_code( $r ),
- $r->get_error_message()
- )
- )
- );
- } elseif ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'The REST API encountered an unexpected result' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: 1: The HTTP response code returned. 2: The error message returned. */
- __( 'The REST API call gave the following unexpected result: (%1$d) %2$s.' ),
- wp_remote_retrieve_response_code( $r ),
- wp_remote_retrieve_body( $r )
- )
- );
- } else {
- $json = json_decode( wp_remote_retrieve_body( $r ), true );
-
- if ( false !== $json && ! isset( $json['capabilities'] ) ) {
- $result['status'] = 'recommended';
-
- $result['label'] = __( 'The REST API did not behave correctly' );
-
- $result['description'] .= sprintf(
- '
%s
',
- sprintf(
- /* translators: %s: The name of the query parameter being tested. */
- __( 'The REST API did not process the %s query parameter correctly.' ),
- '
context'
- )
- );
- }
- }
-
- return $result;
- }
-
- /**
- * Return a set of tests that belong to the site status page.
- *
- * Each site status test is defined here, they may be `direct` tests, that run on page load, or `async` tests
- * which will run later down the line via JavaScript calls to improve page performance and hopefully also user
- * experiences.
- *
- * @since 5.2.0
- *
- * @return array The list of tests to run.
- */
- public static function get_tests() {
- $tests = array(
- 'direct' => array(
- 'wordpress_version' => array(
- 'label' => __( 'WordPress Version' ),
- 'test' => 'wordpress_version',
- ),
- 'plugin_version' => array(
- 'label' => __( 'Plugin Versions' ),
- 'test' => 'plugin_version',
- ),
- 'theme_version' => array(
- 'label' => __( 'Theme Versions' ),
- 'test' => 'theme_version',
- ),
- 'php_version' => array(
- 'label' => __( 'PHP Version' ),
- 'test' => 'php_version',
- ),
- 'php_extensions' => array(
- 'label' => __( 'PHP Extensions' ),
- 'test' => 'php_extensions',
- ),
- 'php_default_timezone' => array(
- 'label' => __( 'PHP Default Timezone' ),
- 'test' => 'php_default_timezone',
- ),
- 'sql_server' => array(
- 'label' => __( 'Database Server version' ),
- 'test' => 'sql_server',
- ),
- 'utf8mb4_support' => array(
- 'label' => __( 'MySQL utf8mb4 support' ),
- 'test' => 'utf8mb4_support',
- ),
- 'https_status' => array(
- 'label' => __( 'HTTPS status' ),
- 'test' => 'https_status',
- ),
- 'ssl_support' => array(
- 'label' => __( 'Secure communication' ),
- 'test' => 'ssl_support',
- ),
- 'scheduled_events' => array(
- 'label' => __( 'Scheduled events' ),
- 'test' => 'scheduled_events',
- ),
- 'http_requests' => array(
- 'label' => __( 'HTTP Requests' ),
- 'test' => 'http_requests',
- ),
- 'debug_enabled' => array(
- 'label' => __( 'Debugging enabled' ),
- 'test' => 'is_in_debug_mode',
- ),
- ),
- 'async' => array(
- 'dotorg_communication' => array(
- 'label' => __( 'Communication with WordPress.org' ),
- 'test' => 'dotorg_communication',
- ),
- 'background_updates' => array(
- 'label' => __( 'Background updates' ),
- 'test' => 'background_updates',
- ),
- 'loopback_requests' => array(
- 'label' => __( 'Loopback request' ),
- 'test' => 'loopback_requests',
- ),
- ),
- );
-
- // Conditionally include REST rules if the function for it exists.
- if ( function_exists( 'rest_url' ) ) {
- $tests['direct']['rest_availability'] = array(
- 'label' => __( 'REST API availability' ),
- 'test' => 'rest_availability',
- );
- }
-
- /**
- * Add or modify which site status tests are run on a site.
- *
- * The site health is determined by a set of tests based on best practices from
- * both the WordPress Hosting Team, but also web standards in general.
- *
- * Some sites may not have the same requirements, for example the automatic update
- * checks may be handled by a host, and are therefore disabled in core.
- * Or maybe you want to introduce a new test, is caching enabled/disabled/stale for example.
- *
- * Tests may be added either as direct, or asynchronous ones. Any test that may require some time
- * to complete should run asynchronously, to avoid extended loading periods within wp-admin.
- *
- * @since 5.2.0
- *
- * @param array $test_type {
- * An associative array, where the `$test_type` is either `direct` or
- * `async`, to declare if the test should run via AJAX calls after page load.
- *
- * @type array $identifier {
- * `$identifier` should be a unique identifier for the test that should run.
- * Plugins and themes are encouraged to prefix test identifiers with their slug
- * to avoid any collisions between tests.
- *
- * @type string $label A friendly label for your test to identify it by.
- * @type mixed $test A callable to perform a direct test, or a string AJAX action to be called
- * to perform an async test.
- * }
- * }
- */
- $tests = apply_filters( 'site_status_tests', $tests );
-
- return $tests;
- }
-
- /**
- * Add a class to the body HTML tag.
- *
- * Filters the body class string for admin pages and adds our own class for easier styling.
- *
- * @since 5.2.0
- *
- * @param string $body_class The body class string.
- * @return string The modified body class string.
- */
- public function admin_body_class( $body_class ) {
- $body_class .= ' site-health';
-
- return $body_class;
- }
-
- /**
- * Initiate the WP_Cron schedule test cases.
- *
- * @since 5.2.0
- */
- private function wp_schedule_test_init() {
- $this->schedules = wp_get_schedules();
- $this->get_cron_tasks();
- }
-
- /**
- * Populate our list of cron events and store them to a class-wide variable.
- *
- * @since 5.2.0
- */
- private function get_cron_tasks() {
- $cron_tasks = _get_cron_array();
-
- if ( empty( $cron_tasks ) ) {
- $this->crons = new WP_Error( 'no_tasks', __( 'No scheduled events exist on this site.' ) );
- return;
- }
-
- $this->crons = array();
-
- foreach ( $cron_tasks as $time => $cron ) {
- foreach ( $cron as $hook => $dings ) {
- foreach ( $dings as $sig => $data ) {
-
- $this->crons[ "$hook-$sig-$time" ] = (object) array(
- 'hook' => $hook,
- 'time' => $time,
- 'sig' => $sig,
- 'args' => $data['args'],
- 'schedule' => $data['schedule'],
- 'interval' => isset( $data['interval'] ) ? $data['interval'] : null,
- );
-
- }
- }
- }
- }
-
- /**
- * Check if any scheduled tasks have been missed.
- *
- * Returns a boolean value of `true` if a scheduled task has been missed and ends processing. If the list of
- * crons is an instance of WP_Error, return the instance instead of a boolean value.
- *
- * @since 5.2.0
- *
- * @return bool|WP_Error True if a cron was missed, false if not. WP_Error if the cron is set to that.
- */
- public function has_missed_cron() {
- if ( is_wp_error( $this->crons ) ) {
- return $this->crons;
- }
-
- foreach ( $this->crons as $id => $cron ) {
- if ( ( $cron->time - time() ) < $this->timeout_missed_cron ) {
- $this->last_missed_cron = $cron->hook;
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Check if any scheduled tasks are late.
- *
- * Returns a boolean value of `true` if a scheduled task is late and ends processing. If the list of
- * crons is an instance of WP_Error, return the instance instead of a boolean value.
- *
- * @since 5.3.0
- *
- * @return bool|WP_Error True if a cron is late, false if not. WP_Error if the cron is set to that.
- */
- public function has_late_cron() {
- if ( is_wp_error( $this->crons ) ) {
- return $this->crons;
- }
-
- foreach ( $this->crons as $id => $cron ) {
- $cron_offset = $cron->time - time();
- if (
- $cron_offset >= $this->timeout_missed_cron &&
- $cron_offset < $this->timeout_late_cron
- ) {
- $this->last_late_cron = $cron->hook;
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Run a loopback test on our site.
- *
- * Loopbacks are what WordPress uses to communicate with itself to start up WP_Cron, scheduled posts,
- * make sure plugin or theme edits don't cause site failures and similar.
- *
- * @since 5.2.0
- *
- * @return object The test results.
- */
- function can_perform_loopback() {
- $cookies = wp_unslash( $_COOKIE );
- $timeout = 10;
- $headers = array(
- 'Cache-Control' => 'no-cache',
- );
- /** This filter is documented in wp-includes/class-wp-http-streams.php */
- $sslverify = apply_filters( 'https_local_ssl_verify', false );
-
- // Include Basic auth in loopback requests.
- if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
- $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
- }
-
- $url = admin_url();
-
- $r = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
-
- if ( is_wp_error( $r ) ) {
- return (object) array(
- 'status' => 'critical',
- 'message' => sprintf(
- '%s
%s',
- __( 'The loopback request to your site failed, this means features relying on them are not currently working as expected.' ),
- sprintf(
- /* translators: 1: The HTTP response code. 2: The error message returned. */
- __( 'Error: [%1$s] %2$s' ),
- wp_remote_retrieve_response_code( $r ),
- $r->get_error_message()
- )
- ),
- );
- }
-
- if ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
- return (object) array(
- 'status' => 'recommended',
- 'message' => sprintf(
- /* translators: %d: The HTTP response code returned. */
- __( 'The loopback request returned an unexpected http status code, %d, it was not possible to determine if this will prevent features from working as expected.' ),
- wp_remote_retrieve_response_code( $r )
- ),
- );
- }
-
- return (object) array(
- 'status' => 'good',
- 'message' => __( 'The loopback request to your site completed successfully.' ),
- );
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-site-icon.php b/srcs/wordpress/wp-admin/includes/class-wp-site-icon.php
deleted file mode 100644
index a16565e..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-site-icon.php
+++ /dev/null
@@ -1,233 +0,0 @@
-ID );
- $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
-
- $size = @getimagesize( $cropped );
- $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
-
- $object = array(
- 'ID' => $parent_attachment_id,
- 'post_title' => wp_basename( $cropped ),
- 'post_content' => $url,
- 'post_mime_type' => $image_type,
- 'guid' => $url,
- 'context' => 'site-icon',
- );
-
- return $object;
- }
-
- /**
- * Inserts an attachment.
- *
- * @since 4.3.0
- *
- * @param array $object Attachment object.
- * @param string $file File path of the attached image.
- * @return int Attachment ID
- */
- public function insert_attachment( $object, $file ) {
- $attachment_id = wp_insert_attachment( $object, $file );
- $metadata = wp_generate_attachment_metadata( $attachment_id, $file );
-
- /**
- * Filters the site icon attachment metadata.
- *
- * @since 4.3.0
- *
- * @see wp_generate_attachment_metadata()
- *
- * @param array $metadata Attachment metadata.
- */
- $metadata = apply_filters( 'site_icon_attachment_metadata', $metadata );
- wp_update_attachment_metadata( $attachment_id, $metadata );
-
- return $attachment_id;
- }
-
- /**
- * Adds additional sizes to be made when creating the site icon images.
- *
- * @since 4.3.0
- *
- * @param array[] $sizes Array of arrays containing information for additional sizes.
- * @return array[] Array of arrays containing additional image sizes.
- */
- public function additional_sizes( $sizes = array() ) {
- $only_crop_sizes = array();
-
- /**
- * Filters the different dimensions that a site icon is saved in.
- *
- * @since 4.3.0
- *
- * @param int[] $site_icon_sizes Array of sizes available for the Site Icon.
- */
- $this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
-
- // Use a natural sort of numbers.
- natsort( $this->site_icon_sizes );
- $this->site_icon_sizes = array_reverse( $this->site_icon_sizes );
-
- // ensure that we only resize the image into
- foreach ( $sizes as $name => $size_array ) {
- if ( isset( $size_array['crop'] ) ) {
- $only_crop_sizes[ $name ] = $size_array;
- }
- }
-
- foreach ( $this->site_icon_sizes as $size ) {
- if ( $size < $this->min_size ) {
- $only_crop_sizes[ 'site_icon-' . $size ] = array(
- 'width ' => $size,
- 'height' => $size,
- 'crop' => true,
- );
- }
- }
-
- return $only_crop_sizes;
- }
-
- /**
- * Adds Site Icon sizes to the array of image sizes on demand.
- *
- * @since 4.3.0
- *
- * @param string[] $sizes Array of image size names.
- * @return string[] Array of image size names.
- */
- public function intermediate_image_sizes( $sizes = array() ) {
- /** This filter is documented in wp-admin/includes/class-wp-site-icon.php */
- $this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
- foreach ( $this->site_icon_sizes as $size ) {
- $sizes[] = 'site_icon-' . $size;
- }
-
- return $sizes;
- }
-
- /**
- * Deletes the Site Icon when the image file is deleted.
- *
- * @since 4.3.0
- *
- * @param int $post_id Attachment ID.
- */
- public function delete_attachment_data( $post_id ) {
- $site_icon_id = get_option( 'site_icon' );
-
- if ( $site_icon_id && $post_id == $site_icon_id ) {
- delete_option( 'site_icon' );
- }
- }
-
- /**
- * Adds custom image sizes when meta data for an image is requested, that happens to be used as Site Icon.
- *
- * @since 4.3.0
- *
- * @param null|array|string $value The value get_metadata() should return a single metadata value, or an
- * array of values.
- * @param int $post_id Post ID.
- * @param string $meta_key Meta key.
- * @param string|array $single Meta value, or an array of values.
- * @return array|null|string The attachment metadata value, array of values, or null.
- */
- public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
- if ( $single && '_wp_attachment_backup_sizes' === $meta_key ) {
- $site_icon_id = get_option( 'site_icon' );
-
- if ( $post_id == $site_icon_id ) {
- add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) );
- }
- }
-
- return $value;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-terms-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-terms-list-table.php
deleted file mode 100644
index 33ef9fa..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-terms-list-table.php
+++ /dev/null
@@ -1,686 +0,0 @@
- 'tags',
- 'singular' => 'tag',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
-
- $action = $this->screen->action;
- $post_type = $this->screen->post_type;
- $taxonomy = $this->screen->taxonomy;
-
- if ( empty( $taxonomy ) ) {
- $taxonomy = 'post_tag';
- }
-
- if ( ! taxonomy_exists( $taxonomy ) ) {
- wp_die( __( 'Invalid taxonomy.' ) );
- }
-
- $tax = get_taxonomy( $taxonomy );
-
- // @todo Still needed? Maybe just the show_ui part.
- if ( empty( $post_type ) || ! in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) {
- $post_type = 'post';
- }
-
- }
-
- /**
- * @return bool
- */
- public function ajax_user_can() {
- return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms );
- }
-
- /**
- */
- public function prepare_items() {
- $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' );
-
- if ( 'post_tag' === $this->screen->taxonomy ) {
- /**
- * Filters the number of terms displayed per page for the Tags list table.
- *
- * @since 2.8.0
- *
- * @param int $tags_per_page Number of tags to be displayed. Default 20.
- */
- $tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
-
- /**
- * Filters the number of terms displayed per page for the Tags list table.
- *
- * @since 2.7.0
- * @deprecated 2.8.0 Use edit_tags_per_page instead.
- *
- * @param int $tags_per_page Number of tags to be displayed. Default 20.
- */
- $tags_per_page = apply_filters( 'tagsperpage', $tags_per_page );
- } elseif ( 'category' === $this->screen->taxonomy ) {
- /**
- * Filters the number of terms displayed per page for the Categories list table.
- *
- * @since 2.8.0
- *
- * @param int $tags_per_page Number of categories to be displayed. Default 20.
- */
- $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page );
- }
-
- $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
-
- $args = array(
- 'search' => $search,
- 'page' => $this->get_pagenum(),
- 'number' => $tags_per_page,
- );
-
- if ( ! empty( $_REQUEST['orderby'] ) ) {
- $args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) );
- }
-
- if ( ! empty( $_REQUEST['order'] ) ) {
- $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) );
- }
-
- $this->callback_args = $args;
-
- $this->set_pagination_args(
- array(
- 'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
- 'per_page' => $tags_per_page,
- )
- );
- }
-
- /**
- * @return bool
- */
- public function has_items() {
- // todo: populate $this->items in prepare_items()
- return true;
- }
-
- /**
- */
- public function no_items() {
- echo get_taxonomy( $this->screen->taxonomy )->labels->not_found;
- }
-
- /**
- * @return array
- */
- protected function get_bulk_actions() {
- $actions = array();
-
- if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) ) {
- $actions['delete'] = __( 'Delete' );
- }
-
- return $actions;
- }
-
- /**
- * @return string
- */
- public function current_action() {
- if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) {
- return 'bulk-delete';
- }
-
- return parent::current_action();
- }
-
- /**
- * @return array
- */
- public function get_columns() {
- $columns = array(
- 'cb' => '
',
- 'name' => _x( 'Name', 'term name' ),
- 'description' => __( 'Description' ),
- 'slug' => __( 'Slug' ),
- );
-
- if ( 'link_category' === $this->screen->taxonomy ) {
- $columns['links'] = __( 'Links' );
- } else {
- $columns['posts'] = _x( 'Count', 'Number/count of items' );
- }
-
- return $columns;
- }
-
- /**
- * @return array
- */
- protected function get_sortable_columns() {
- return array(
- 'name' => 'name',
- 'description' => 'description',
- 'slug' => 'slug',
- 'posts' => 'count',
- 'links' => 'count',
- );
- }
-
- /**
- */
- public function display_rows_or_placeholder() {
- $taxonomy = $this->screen->taxonomy;
-
- $args = wp_parse_args(
- $this->callback_args,
- array(
- 'taxonomy' => $taxonomy,
- 'page' => 1,
- 'number' => 20,
- 'search' => '',
- 'hide_empty' => 0,
- )
- );
-
- $page = $args['page'];
-
- // Set variable because $args['number'] can be subsequently overridden.
- $number = $args['number'];
-
- $offset = ( $page - 1 ) * $number;
- $args['offset'] = $offset;
-
- // Convert it to table rows.
- $count = 0;
-
- if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) {
- // We'll need the full set of terms then.
- $args['number'] = 0;
- $args['offset'] = $args['number'];
- }
-
- $terms = get_terms( $args );
-
- if ( empty( $terms ) || ! is_array( $terms ) ) {
- echo '
';
- $this->no_items();
- echo ' ';
- return;
- }
-
- if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) {
- if ( ! empty( $args['search'] ) ) {// Ignore children on searches.
- $children = array();
- } else {
- $children = _get_term_hierarchy( $taxonomy );
- }
- // Some funky recursion to get the job done( Paging & parents mainly ) is contained within, Skip it for non-hierarchical taxonomies for performance sake
- $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count );
- } else {
- foreach ( $terms as $term ) {
- $this->single_row( $term );
- }
- }
- }
-
- /**
- * @param string $taxonomy
- * @param array $terms
- * @param array $children
- * @param int $start
- * @param int $per_page
- * @param int $count
- * @param int $parent
- * @param int $level
- */
- private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent = 0, $level = 0 ) {
-
- $end = $start + $per_page;
-
- foreach ( $terms as $key => $term ) {
-
- if ( $count >= $end ) {
- break;
- }
-
- if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) {
- continue;
- }
-
- // If the page starts in a subtree, print the parents.
- if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
- $my_parents = array();
- $parent_ids = array();
- $p = $term->parent;
- while ( $p ) {
- $my_parent = get_term( $p, $taxonomy );
- $my_parents[] = $my_parent;
- $p = $my_parent->parent;
- if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
- break;
- }
- $parent_ids[] = $p;
- }
- unset( $parent_ids );
-
- $num_parents = count( $my_parents );
- while ( $my_parent = array_pop( $my_parents ) ) {
- echo "\t";
- $this->single_row( $my_parent, $level - $num_parents );
- $num_parents--;
- }
- }
-
- if ( $count >= $start ) {
- echo "\t";
- $this->single_row( $term, $level );
- }
-
- ++$count;
-
- unset( $terms[ $key ] );
-
- if ( isset( $children[ $term->term_id ] ) && empty( $_REQUEST['s'] ) ) {
- $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
- }
- }
- }
-
- /**
- * @global string $taxonomy
- * @param WP_Term $tag Term object.
- * @param int $level
- */
- public function single_row( $tag, $level = 0 ) {
- global $taxonomy;
- $tag = sanitize_term( $tag, $taxonomy );
-
- $this->level = $level;
-
- if ( $tag->parent ) {
- $count = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
- $level = 'level-' . $count;
- } else {
- $level = 'level-0';
- }
-
- echo '
';
- $this->single_row_columns( $tag );
- echo ' ';
- }
-
- /**
- * @param WP_Term $tag Term object.
- * @return string
- */
- public function column_cb( $tag ) {
- if ( current_user_can( 'delete_term', $tag->term_id ) ) {
- return sprintf(
- '
%2$s ' .
- '
',
- $tag->term_id,
- /* translators: %s: Taxonomy term name. */
- sprintf( __( 'Select %s' ), $tag->name )
- );
- }
-
- return ' ';
- }
-
- /**
- * @param WP_Term $tag Term object.
- * @return string
- */
- public function column_name( $tag ) {
- $taxonomy = $this->screen->taxonomy;
-
- $pad = str_repeat( '— ', max( 0, $this->level ) );
-
- /**
- * Filters display of the term name in the terms list table.
- *
- * The default output may include padding due to the term's
- * current level in the term hierarchy.
- *
- * @since 2.5.0
- *
- * @see WP_Terms_List_Table::column_name()
- *
- * @param string $pad_tag_name The term name, padded if not top-level.
- * @param WP_Term $tag Term object.
- */
- $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag );
-
- $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' );
-
- $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
-
- $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type );
-
- if ( $edit_link ) {
- $edit_link = add_query_arg(
- 'wp_http_referer',
- urlencode( wp_unslash( $uri ) ),
- $edit_link
- );
- $name = sprintf(
- '
%s ',
- esc_url( $edit_link ),
- /* translators: %s: Taxonomy term name. */
- esc_attr( sprintf( __( '“%s” (Edit)' ), $tag->name ) ),
- $name
- );
- }
-
- $out = sprintf(
- '
%s ',
- $name
- );
-
- $out .= '
';
- $out .= '
' . $qe_data->name . '
';
-
- /** This filter is documented in wp-admin/edit-tag-form.php */
- $out .= '
' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '
';
- $out .= '
' . $qe_data->parent . '
';
-
- return $out;
- }
-
- /**
- * Gets the name of the default primary column.
- *
- * @since 4.3.0
- *
- * @return string Name of the default primary column, in this case, 'name'.
- */
- protected function get_default_primary_column_name() {
- return 'name';
- }
-
- /**
- * Generates and displays row action links.
- *
- * @since 4.3.0
- *
- * @param WP_Term $tag Tag being acted upon.
- * @param string $column_name Current column name.
- * @param string $primary Primary column name.
- * @return string Row actions output for terms.
- */
- protected function handle_row_actions( $tag, $column_name, $primary ) {
- if ( $primary !== $column_name ) {
- return '';
- }
-
- $taxonomy = $this->screen->taxonomy;
- $tax = get_taxonomy( $taxonomy );
- $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
-
- $edit_link = add_query_arg(
- 'wp_http_referer',
- urlencode( wp_unslash( $uri ) ),
- get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type )
- );
-
- $actions = array();
- if ( current_user_can( 'edit_term', $tag->term_id ) ) {
- $actions['edit'] = sprintf(
- '
%s ',
- esc_url( $edit_link ),
- /* translators: %s: Taxonomy term name. */
- esc_attr( sprintf( __( 'Edit “%s”' ), $tag->name ) ),
- __( 'Edit' )
- );
- $actions['inline hide-if-no-js'] = sprintf(
- '
%s ',
- /* translators: %s: Taxonomy term name. */
- esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $tag->name ) ),
- __( 'Quick Edit' )
- );
- }
- if ( current_user_can( 'delete_term', $tag->term_id ) ) {
- $actions['delete'] = sprintf(
- '
%s ',
- wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ),
- /* translators: %s: Taxonomy term name. */
- esc_attr( sprintf( __( 'Delete “%s”' ), $tag->name ) ),
- __( 'Delete' )
- );
- }
- if ( is_taxonomy_viewable( $tax ) ) {
- $actions['view'] = sprintf(
- '
%s ',
- get_term_link( $tag ),
- /* translators: %s: Taxonomy term name. */
- esc_attr( sprintf( __( 'View “%s” archive' ), $tag->name ) ),
- __( 'View' )
- );
- }
-
- /**
- * Filters the action links displayed for each term in the Tags list table.
- *
- * @since 2.8.0
- * @deprecated 3.0.0 Use {$taxonomy}_row_actions instead.
- *
- * @param string[] $actions An array of action links to be displayed. Default
- * 'Edit', 'Quick Edit', 'Delete', and 'View'.
- * @param WP_Term $tag Term object.
- */
- $actions = apply_filters( 'tag_row_actions', $actions, $tag );
-
- /**
- * Filters the action links displayed for each term in the terms list table.
- *
- * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
- *
- * @since 3.0.0
- *
- * @param string[] $actions An array of action links to be displayed. Default
- * 'Edit', 'Quick Edit', 'Delete', and 'View'.
- * @param WP_Term $tag Term object.
- */
- $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
-
- return $this->row_actions( $actions );
- }
-
- /**
- * @param WP_Term $tag Term object.
- * @return string
- */
- public function column_description( $tag ) {
- if ( $tag->description ) {
- return $tag->description;
- } else {
- return '
— ' . __( 'No description' ) . ' ';
- }
- }
-
- /**
- * @param WP_Term $tag Term object.
- * @return string
- */
- public function column_slug( $tag ) {
- /** This filter is documented in wp-admin/edit-tag-form.php */
- return apply_filters( 'editable_slug', $tag->slug, $tag );
- }
-
- /**
- * @param WP_Term $tag Term object.
- * @return string
- */
- public function column_posts( $tag ) {
- $count = number_format_i18n( $tag->count );
-
- $tax = get_taxonomy( $this->screen->taxonomy );
-
- $ptype_object = get_post_type_object( $this->screen->post_type );
- if ( ! $ptype_object->show_ui ) {
- return $count;
- }
-
- if ( $tax->query_var ) {
- $args = array( $tax->query_var => $tag->slug );
- } else {
- $args = array(
- 'taxonomy' => $tax->name,
- 'term' => $tag->slug,
- );
- }
-
- if ( 'post' != $this->screen->post_type ) {
- $args['post_type'] = $this->screen->post_type;
- }
-
- if ( 'attachment' === $this->screen->post_type ) {
- return "
$count ";
- }
-
- return "
$count ";
- }
-
- /**
- * @param WP_Term $tag Term object.
- * @return string
- */
- public function column_links( $tag ) {
- $count = number_format_i18n( $tag->count );
- if ( $count ) {
- $count = "
$count ";
- }
- return $count;
- }
-
- /**
- * @param WP_Term $tag Term object.
- * @param string $column_name
- * @return string
- */
- public function column_default( $tag, $column_name ) {
- /**
- * Filters the displayed columns in the terms list table.
- *
- * The dynamic portion of the hook name, `$this->screen->taxonomy`,
- * refers to the slug of the current taxonomy.
- *
- * @since 2.8.0
- *
- * @param string $string Blank string.
- * @param string $column_name Name of the column.
- * @param int $term_id Term ID.
- */
- return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id );
- }
-
- /**
- * Outputs the hidden row displayed when inline editing
- *
- * @since 3.1.0
- */
- public function inline_edit() {
- $tax = get_taxonomy( $this->screen->taxonomy );
-
- if ( ! current_user_can( $tax->cap->edit_terms ) ) {
- return;
- }
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true,
- 'description' => true,
- 'name' => true,
- 'slug' => true,
- 'posts' => true,
- );
-
- list( $columns ) = $this->get_column_info();
-
- foreach ( $columns as $column_name => $column_display_name ) {
- if ( isset( $core_columns[ $column_name ] ) ) {
- continue;
- }
-
- /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
- do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
- }
-
- ?>
-
-
-
-
labels->update_item; ?>
-
-
-
-
-
-
-
-
-
- features = $_REQUEST['features'];
- }
-
- $paged = $this->get_pagenum();
-
- $per_page = 36;
-
- // These are the tabs which are shown on the page,
- $tabs = array();
- $tabs['dashboard'] = __( 'Search' );
- if ( 'search' === $tab ) {
- $tabs['search'] = __( 'Search Results' );
- }
- $tabs['upload'] = __( 'Upload' );
- $tabs['featured'] = _x( 'Featured', 'themes' );
- //$tabs['popular'] = _x( 'Popular', 'themes' );
- $tabs['new'] = _x( 'Latest', 'themes' );
- $tabs['updated'] = _x( 'Recently Updated', 'themes' );
-
- $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
-
- /** This filter is documented in wp-admin/theme-install.php */
- $tabs = apply_filters( 'install_themes_tabs', $tabs );
-
- /**
- * Filters tabs not associated with a menu item on the Install Themes screen.
- *
- * @since 2.8.0
- *
- * @param string[] $nonmenu_tabs The tabs that don't have a menu item on
- * the Install Themes screen.
- */
- $nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
-
- // If a non-valid menu tab has been selected, And it's not a non-menu action.
- if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) {
- $tab = key( $tabs );
- }
-
- $args = array(
- 'page' => $paged,
- 'per_page' => $per_page,
- 'fields' => $theme_field_defaults,
- );
-
- switch ( $tab ) {
- case 'search':
- $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
- switch ( $type ) {
- case 'tag':
- $args['tag'] = array_map( 'sanitize_key', $search_terms );
- break;
- case 'term':
- $args['search'] = $search_string;
- break;
- case 'author':
- $args['author'] = $search_string;
- break;
- }
-
- if ( ! empty( $this->features ) ) {
- $args['tag'] = $this->features;
- $_REQUEST['s'] = implode( ',', $this->features );
- $_REQUEST['type'] = 'tag';
- }
-
- add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 );
- break;
-
- case 'featured':
- // case 'popular':
- case 'new':
- case 'updated':
- $args['browse'] = $tab;
- break;
-
- default:
- $args = false;
- break;
- }
-
- /**
- * Filters API request arguments for each Install Themes screen tab.
- *
- * The dynamic portion of the hook name, `$tab`, refers to the theme install
- * tabs. Default tabs are 'dashboard', 'search', 'upload', 'featured',
- * 'new', and 'updated'.
- *
- * @since 3.7.0
- *
- * @param array $args An array of themes API arguments.
- */
- $args = apply_filters( "install_themes_table_api_args_{$tab}", $args );
-
- if ( ! $args ) {
- return;
- }
-
- $api = themes_api( 'query_themes', $args );
-
- if ( is_wp_error( $api ) ) {
- wp_die( $api->get_error_message() . '
' . __( 'Try Again' ) . ' ' );
- }
-
- $this->items = $api->themes;
-
- $this->set_pagination_args(
- array(
- 'total_items' => $api->info['results'],
- 'per_page' => $args['per_page'],
- 'infinite_scroll' => true,
- )
- );
- }
-
- /**
- */
- public function no_items() {
- _e( 'No themes match your request.' );
- }
-
- /**
- * @global array $tabs
- * @global string $tab
- * @return array
- */
- protected function get_views() {
- global $tabs, $tab;
-
- $display_tabs = array();
- foreach ( (array) $tabs as $action => $text ) {
- $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : '';
- $href = self_admin_url( 'theme-install.php?tab=' . $action );
- $display_tabs[ 'theme-install-' . $action ] = "$text ";
- }
-
- return $display_tabs;
- }
-
- /**
- * Displays the theme install table.
- *
- * Overrides the parent display() method to provide a different container.
- *
- * @since 3.1.0
- */
- public function display() {
- wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
- ?>
-
-
-
-
- pagination( 'top' ); ?>
-
-
-
-
- display_rows_or_placeholder(); ?>
-
-
- tablenav( 'bottom' );
- }
-
- /**
- */
- public function display_rows() {
- $themes = $this->items;
- foreach ( $themes as $theme ) {
- ?>
-
- single_row( $theme );
- ?>
-
- theme_installer();
- }
-
- /**
- * Prints a theme from the WordPress.org API.
- *
- * @since 3.1.0
- *
- * @global array $themes_allowedtags
- *
- * @param object $theme {
- * An object that contains theme data returned by the WordPress.org API.
- *
- * @type string $name Theme name, e.g. 'Twenty Twenty'.
- * @type string $slug Theme slug, e.g. 'twentytwenty'.
- * @type string $version Theme version, e.g. '1.1'.
- * @type string $author Theme author username, e.g. 'melchoyce'.
- * @type string $preview_url Preview URL, e.g. 'http://2020.wordpress.net/'.
- * @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentytwenty/'.
- * @type float $rating Rating score.
- * @type int $num_ratings The number of ratings.
- * @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentytwenty/'.
- * @type string $description Theme description.
- * @type string $download_link Theme ZIP download URL.
- * }
- */
- public function single_row( $theme ) {
- global $themes_allowedtags;
-
- if ( empty( $theme ) ) {
- return;
- }
-
- $name = wp_kses( $theme->name, $themes_allowedtags );
- $author = wp_kses( $theme->author, $themes_allowedtags );
-
- /* translators: %s: Theme name. */
- $preview_title = sprintf( __( 'Preview “%s”' ), $name );
- $preview_url = add_query_arg(
- array(
- 'tab' => 'theme-information',
- 'theme' => $theme->slug,
- ),
- self_admin_url( 'theme-install.php' )
- );
-
- $actions = array();
-
- $install_url = add_query_arg(
- array(
- 'action' => 'install-theme',
- 'theme' => $theme->slug,
- ),
- self_admin_url( 'update.php' )
- );
-
- $update_url = add_query_arg(
- array(
- 'action' => 'upgrade-theme',
- 'theme' => $theme->slug,
- ),
- self_admin_url( 'update.php' )
- );
-
- $status = $this->_get_theme_status( $theme );
-
- switch ( $status ) {
- case 'update_available':
- $actions[] = sprintf(
- '
%s ',
- esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ),
- /* translators: %s: Theme version. */
- esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ),
- __( 'Update' )
- );
- break;
- case 'newer_installed':
- case 'latest_installed':
- $actions[] = sprintf(
- '
%s ',
- esc_attr__( 'This theme is already installed and is up to date' ),
- _x( 'Installed', 'theme' )
- );
- break;
- case 'install':
- default:
- $actions[] = sprintf(
- '
%s ',
- esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ),
- /* translators: %s: Theme name. */
- esc_attr( sprintf( __( 'Install %s' ), $name ) ),
- __( 'Install Now' )
- );
- break;
- }
-
- $actions[] = sprintf(
- '
%s ',
- esc_url( $preview_url ),
- /* translators: %s: Theme name. */
- esc_attr( sprintf( __( 'Preview %s' ), $name ) ),
- __( 'Preview' )
- );
-
- /**
- * Filters the install action links for a theme in the Install Themes list table.
- *
- * @since 3.4.0
- *
- * @param string[] $actions An array of theme action links. Defaults are
- * links to Install Now, Preview, and Details.
- * @param WP_Theme $theme Theme object.
- */
- $actions = apply_filters( 'theme_install_actions', $actions, $theme );
-
- ?>
-
-
-
-
-
-
-
-
-
-
-
- install_theme_info( $theme );
- }
-
- /**
- * Prints the wrapper for the theme installer.
- */
- public function theme_installer() {
- ?>
-
-
-
- name, $themes_allowedtags );
- $author = wp_kses( $theme->author, $themes_allowedtags );
-
- $install_url = add_query_arg(
- array(
- 'action' => 'install-theme',
- 'theme' => $theme->slug,
- ),
- self_admin_url( 'update.php' )
- );
-
- $update_url = add_query_arg(
- array(
- 'action' => 'upgrade-theme',
- 'theme' => $theme->slug,
- ),
- self_admin_url( 'update.php' )
- );
-
- $status = $this->_get_theme_status( $theme );
-
- ?>
-
- %s',
- esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ),
- /* translators: %s: Theme version. */
- esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ),
- __( 'Update' )
- );
- break;
- case 'newer_installed':
- case 'latest_installed':
- printf(
- '
%s ',
- esc_attr__( 'This theme is already installed and is up to date' ),
- _x( 'Installed', 'theme' )
- );
- break;
- case 'install':
- default:
- printf(
- '
%s ',
- esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ),
- __( 'Install' )
- );
- break;
- }
- ?>
-
-
-
-
- screenshot_url ) ) : ?>
-
-
-
- $theme->rating,
- 'type' => 'percent',
- 'number' => $theme->num_ratings,
- )
- );
- ?>
-
-
- version, $themes_allowedtags ); ?>
-
-
- description, $themes_allowedtags ); ?>
-
-
-
-
- Install screen
- * @global string $type Type of search.
- *
- * @param array $extra_args Unused.
- */
- public function _js_vars( $extra_args = array() ) {
- global $tab, $type;
- parent::_js_vars( compact( 'tab', 'type' ) );
- }
-
- /**
- * Check to see if the theme is already installed.
- *
- * @since 3.4.0
- *
- * @param object $theme - A WordPress.org Theme API object.
- * @return string Theme status.
- */
- private function _get_theme_status( $theme ) {
- $status = 'install';
-
- $installed_theme = wp_get_theme( $theme->slug );
- if ( $installed_theme->exists() ) {
- if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) {
- $status = 'latest_installed';
- } elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) {
- $status = 'newer_installed';
- } else {
- $status = 'update_available';
- }
- }
-
- return $status;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-themes-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-themes-list-table.php
deleted file mode 100644
index fb8d131..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-themes-list-table.php
+++ /dev/null
@@ -1,361 +0,0 @@
- true,
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
- }
-
- /**
- * @return bool
- */
- public function ajax_user_can() {
- // Do not check edit_theme_options here. Ajax calls for available themes require switch_themes.
- return current_user_can( 'switch_themes' );
- }
-
- /**
- */
- public function prepare_items() {
- $themes = wp_get_themes( array( 'allowed' => true ) );
-
- if ( ! empty( $_REQUEST['s'] ) ) {
- $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) );
- }
-
- if ( ! empty( $_REQUEST['features'] ) ) {
- $this->features = $_REQUEST['features'];
- }
-
- if ( $this->search_terms || $this->features ) {
- foreach ( $themes as $key => $theme ) {
- if ( ! $this->search_theme( $theme ) ) {
- unset( $themes[ $key ] );
- }
- }
- }
-
- unset( $themes[ get_option( 'stylesheet' ) ] );
- WP_Theme::sort_by_name( $themes );
-
- $per_page = 36;
- $page = $this->get_pagenum();
-
- $start = ( $page - 1 ) * $per_page;
-
- $this->items = array_slice( $themes, $start, $per_page, true );
-
- $this->set_pagination_args(
- array(
- 'total_items' => count( $themes ),
- 'per_page' => $per_page,
- 'infinite_scroll' => true,
- )
- );
- }
-
- /**
- */
- public function no_items() {
- if ( $this->search_terms || $this->features ) {
- _e( 'No items found.' );
- return;
- }
-
- $blog_id = get_current_blog_id();
- if ( is_multisite() ) {
- if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) {
- printf(
- /* translators: 1: URL to Themes tab on Edit Site screen, 2: URL to Add Themes screen. */
- __( 'You only have one theme enabled for this site right now. Visit the Network Admin to
enable or
install more themes.' ),
- network_admin_url( 'site-themes.php?id=' . $blog_id ),
- network_admin_url( 'theme-install.php' )
- );
-
- return;
- } elseif ( current_user_can( 'manage_network_themes' ) ) {
- printf(
- /* translators: %s: URL to Themes tab on Edit Site screen. */
- __( 'You only have one theme enabled for this site right now. Visit the Network Admin to
enable more themes.' ),
- network_admin_url( 'site-themes.php?id=' . $blog_id )
- );
-
- return;
- }
- // Else, fallthrough. install_themes doesn't help if you can't enable it.
- } else {
- if ( current_user_can( 'install_themes' ) ) {
- printf(
- /* translators: %s: URL to Add Themes screen. */
- __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress Theme Directory at any time: just click on the
Install Themes tab above.' ),
- admin_url( 'theme-install.php' )
- );
-
- return;
- }
- }
- // Fallthrough.
- printf(
- /* translators: %s: Network title. */
- __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ),
- get_site_option( 'site_name' )
- );
- }
-
- /**
- * @param string $which
- */
- public function tablenav( $which = 'top' ) {
- if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) {
- return;
- }
- ?>
-
- pagination( $which ); ?>
-
-
-
-
- tablenav( 'top' ); ?>
-
-
- display_rows_or_placeholder(); ?>
-
-
- tablenav( 'bottom' ); ?>
- has_items() ) {
- $this->display_rows();
- } else {
- echo '
';
- $this->no_items();
- echo '
';
- }
- }
-
- /**
- */
- public function display_rows() {
- $themes = $this->items;
-
- foreach ( $themes as $theme ) :
- ?>
-
- get_template();
- $stylesheet = $theme->get_stylesheet();
- $title = $theme->display( 'Name' );
- $version = $theme->display( 'Version' );
- $author = $theme->display( 'Author' );
-
- $activate_link = wp_nonce_url( 'themes.php?action=activate&template=' . urlencode( $template ) . '&stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
-
- $actions = array();
- $actions['activate'] = sprintf(
- '
%s ',
- $activate_link,
- /* translators: %s: Theme name. */
- esc_attr( sprintf( __( 'Activate “%s”' ), $title ) ),
- __( 'Activate' )
- );
-
- if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
- $actions['preview'] .= sprintf(
- '
%s ',
- wp_customize_url( $stylesheet ),
- __( 'Live Preview' )
- );
- }
-
- if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) {
- $actions['delete'] = sprintf(
- '
%s ',
- wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ),
- /* translators: %s: Theme name. */
- esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ),
- __( 'Delete' )
- );
- }
-
- /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
- $actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' );
-
- /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
- $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, 'all' );
- $delete_action = isset( $actions['delete'] ) ? '
' . $actions['delete'] . '
' : '';
- unset( $actions['delete'] );
-
- $screenshot = $theme->get_screenshot();
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
display( 'Description' ); ?>
- parent() ) {
- printf(
- /* translators: 1: Link to documentation on child themes, 2: Name of parent theme. */
- '
' . __( 'This child theme requires its parent theme, %2$s.' ) . '
',
- __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
- $theme->parent()->display( 'Name' )
- );
- }
- ?>
-
-
-
- features as $word ) {
- if ( ! in_array( $word, $theme->get( 'Tags' ) ) ) {
- return false;
- }
- }
-
- // Match all phrases
- foreach ( $this->search_terms as $word ) {
- if ( in_array( $word, $theme->get( 'Tags' ) ) ) {
- continue;
- }
-
- foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
- // Don't mark up; Do translate.
- if ( false !== stripos( strip_tags( $theme->display( $header, false, true ) ), $word ) ) {
- continue 2;
- }
- }
-
- if ( false !== stripos( $theme->get_stylesheet(), $word ) ) {
- continue;
- }
-
- if ( false !== stripos( $theme->get_template(), $word ) ) {
- continue;
- }
-
- return false;
- }
-
- return true;
- }
-
- /**
- * Send required variables to JavaScript land
- *
- * @since 3.4.0
- *
- * @param array $extra_args
- */
- public function _js_vars( $extra_args = array() ) {
- $search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : '';
-
- $args = array(
- 'search' => $search_string,
- 'features' => $this->features,
- 'paged' => $this->get_pagenum(),
- 'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1,
- );
-
- if ( is_array( $extra_args ) ) {
- $args = array_merge( $args, $extra_args );
- }
-
- printf( "\n", wp_json_encode( $args ) );
- parent::_js_vars();
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-upgrader-skin.php b/srcs/wordpress/wp-admin/includes/class-wp-upgrader-skin.php
deleted file mode 100644
index aff625b..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-upgrader-skin.php
+++ /dev/null
@@ -1,208 +0,0 @@
- '',
- 'nonce' => '',
- 'title' => '',
- 'context' => false,
- );
- $this->options = wp_parse_args( $args, $defaults );
- }
-
- /**
- * @param WP_Upgrader $upgrader
- */
- public function set_upgrader( &$upgrader ) {
- if ( is_object( $upgrader ) ) {
- $this->upgrader =& $upgrader;
- }
- $this->add_strings();
- }
-
- /**
- */
- public function add_strings() {
- }
-
- /**
- * Sets the result of an upgrade.
- *
- * @since 2.8.0
- *
- * @param string|bool|WP_Error $result The result of an upgrade.
- */
- public function set_result( $result ) {
- $this->result = $result;
- }
-
- /**
- * Displays a form to the user to request for their FTP/SSH details in order
- * to connect to the filesystem.
- *
- * @since 2.8.0
- * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
- *
- * @see request_filesystem_credentials()
- *
- * @param bool $error Optional. Whether the current request has failed to connect.
- * Default false.
- * @param string $context Optional. Full path to the directory that is tested
- * for being writable. Default empty.
- * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
- * @return bool False on failure, true on success.
- */
- public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
- $url = $this->options['url'];
- if ( ! $context ) {
- $context = $this->options['context'];
- }
- if ( ! empty( $this->options['nonce'] ) ) {
- $url = wp_nonce_url( $url, $this->options['nonce'] );
- }
-
- $extra_fields = array();
-
- return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
- }
-
- /**
- */
- public function header() {
- if ( $this->done_header ) {
- return;
- }
- $this->done_header = true;
- echo '
';
- echo '
' . $this->options['title'] . ' ';
- }
-
- /**
- */
- public function footer() {
- if ( $this->done_footer ) {
- return;
- }
- $this->done_footer = true;
- echo '';
- }
-
- /**
- * @param string|WP_Error $errors
- */
- public function error( $errors ) {
- if ( ! $this->done_header ) {
- $this->header();
- }
- if ( is_string( $errors ) ) {
- $this->feedback( $errors );
- } elseif ( is_wp_error( $errors ) && $errors->has_errors() ) {
- foreach ( $errors->get_error_messages() as $message ) {
- if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
- $this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
- } else {
- $this->feedback( $message );
- }
- }
- }
- }
-
- /**
- * @param string $string
- * @param mixed ...$args Optional text replacements.
- */
- public function feedback( $string, ...$args ) {
- if ( isset( $this->upgrader->strings[ $string ] ) ) {
- $string = $this->upgrader->strings[ $string ];
- }
-
- if ( strpos( $string, '%' ) !== false ) {
- if ( $args ) {
- $args = array_map( 'strip_tags', $args );
- $args = array_map( 'esc_html', $args );
- $string = vsprintf( $string, $args );
- }
- }
- if ( empty( $string ) ) {
- return;
- }
- show_message( $string );
- }
-
- /**
- */
- public function before() {}
-
- /**
- */
- public function after() {}
-
- /**
- * Output JavaScript that calls function to decrement the update counts.
- *
- * @since 3.9.0
- *
- * @param string $type Type of update count to decrement. Likely values include 'plugin',
- * 'theme', 'translation', etc.
- */
- protected function decrement_update_count( $type ) {
- if ( ! $this->result || is_wp_error( $this->result ) || 'up_to_date' === $this->result ) {
- return;
- }
-
- if ( defined( 'IFRAME_REQUEST' ) ) {
- echo '';
- } else {
- echo '';
- }
- }
-
- /**
- */
- public function bulk_header() {}
-
- /**
- */
- public function bulk_footer() {}
-}
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-upgrader-skins.php b/srcs/wordpress/wp-admin/includes/class-wp-upgrader-skins.php
deleted file mode 100644
index 636ce18..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-upgrader-skins.php
+++ /dev/null
@@ -1,44 +0,0 @@
-skin = new WP_Upgrader_Skin();
- } else {
- $this->skin = $skin;
- }
- }
-
- /**
- * Initialize the upgrader.
- *
- * This will set the relationship between the skin being used and this upgrader,
- * and also add the generic strings to `WP_Upgrader::$strings`.
- *
- * @since 2.8.0
- */
- public function init() {
- $this->skin->set_upgrader( $this );
- $this->generic_strings();
- }
-
- /**
- * Add the generic strings to WP_Upgrader::$strings.
- *
- * @since 2.8.0
- */
- public function generic_strings() {
- $this->strings['bad_request'] = __( 'Invalid data provided.' );
- $this->strings['fs_unavailable'] = __( 'Could not access filesystem.' );
- $this->strings['fs_error'] = __( 'Filesystem error.' );
- $this->strings['fs_no_root_dir'] = __( 'Unable to locate WordPress root directory.' );
- $this->strings['fs_no_content_dir'] = __( 'Unable to locate WordPress content directory (wp-content).' );
- $this->strings['fs_no_plugins_dir'] = __( 'Unable to locate WordPress plugin directory.' );
- $this->strings['fs_no_themes_dir'] = __( 'Unable to locate WordPress theme directory.' );
- /* translators: %s: Directory name. */
- $this->strings['fs_no_folder'] = __( 'Unable to locate needed folder (%s).' );
-
- $this->strings['download_failed'] = __( 'Download failed.' );
- $this->strings['installing_package'] = __( 'Installing the latest version…' );
- $this->strings['no_files'] = __( 'The package contains no files.' );
- $this->strings['folder_exists'] = __( 'Destination folder already exists.' );
- $this->strings['mkdir_failed'] = __( 'Could not create directory.' );
- $this->strings['incompatible_archive'] = __( 'The package could not be installed.' );
- $this->strings['files_not_writable'] = __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' );
-
- $this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' );
- $this->strings['maintenance_end'] = __( 'Disabling Maintenance mode…' );
- }
-
- /**
- * Connect to the filesystem.
- *
- * @since 2.8.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param array $directories Optional. A list of directories. If any of these do
- * not exist, a WP_Error object will be returned.
- * Default empty array.
- * @param bool $allow_relaxed_file_ownership Whether to allow relaxed file ownership.
- * Default false.
- * @return bool|WP_Error True if able to connect, false or a WP_Error otherwise.
- */
- public function fs_connect( $directories = array(), $allow_relaxed_file_ownership = false ) {
- global $wp_filesystem;
-
- $credentials = $this->skin->request_filesystem_credentials( false, $directories[0], $allow_relaxed_file_ownership );
- if ( false === $credentials ) {
- return false;
- }
-
- if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) {
- $error = true;
- if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) {
- $error = $wp_filesystem->errors;
- }
- // Failed to connect, Error and request again
- $this->skin->request_filesystem_credentials( $error, $directories[0], $allow_relaxed_file_ownership );
- return false;
- }
-
- if ( ! is_object( $wp_filesystem ) ) {
- return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] );
- }
-
- if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
- return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors );
- }
-
- foreach ( (array) $directories as $dir ) {
- switch ( $dir ) {
- case ABSPATH:
- if ( ! $wp_filesystem->abspath() ) {
- return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir'] );
- }
- break;
- case WP_CONTENT_DIR:
- if ( ! $wp_filesystem->wp_content_dir() ) {
- return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
- }
- break;
- case WP_PLUGIN_DIR:
- if ( ! $wp_filesystem->wp_plugins_dir() ) {
- return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir'] );
- }
- break;
- case get_theme_root():
- if ( ! $wp_filesystem->wp_themes_dir() ) {
- return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir'] );
- }
- break;
- default:
- if ( ! $wp_filesystem->find_folder( $dir ) ) {
- return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) );
- }
- break;
- }
- }
- return true;
- } //end fs_connect();
-
- /**
- * Download a package.
- *
- * @since 2.8.0
- *
- * @param string $package The URI of the package. If this is the full path to an
- * existing local file, it will be returned untouched.
- * @param bool $check_signatures Whether to validate file signatures. Default false.
- * @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
- */
- public function download_package( $package, $check_signatures = false ) {
-
- /**
- * Filters whether to return the package.
- *
- * @since 3.7.0
- *
- * @param bool $reply Whether to bail without returning the package.
- * Default false.
- * @param string $package The package file name.
- * @param WP_Upgrader $this The WP_Upgrader instance.
- */
- $reply = apply_filters( 'upgrader_pre_download', false, $package, $this );
- if ( false !== $reply ) {
- return $reply;
- }
-
- if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { //Local file or remote?
- return $package; //must be a local file..
- }
-
- if ( empty( $package ) ) {
- return new WP_Error( 'no_package', $this->strings['no_package'] );
- }
-
- $this->skin->feedback( 'downloading_package', $package );
-
- $download_file = download_url( $package, 300, $check_signatures );
-
- if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) {
- return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() );
- }
-
- return $download_file;
- }
-
- /**
- * Unpack a compressed package file.
- *
- * @since 2.8.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param string $package Full path to the package file.
- * @param bool $delete_package Optional. Whether to delete the package file after attempting
- * to unpack it. Default true.
- * @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure.
- */
- public function unpack_package( $package, $delete_package = true ) {
- global $wp_filesystem;
-
- $this->skin->feedback( 'unpack_package' );
-
- $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
-
- //Clean up contents of upgrade directory beforehand.
- $upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
- if ( ! empty( $upgrade_files ) ) {
- foreach ( $upgrade_files as $file ) {
- $wp_filesystem->delete( $upgrade_folder . $file['name'], true );
- }
- }
-
- // We need a working directory - Strip off any .tmp or .zip suffixes
- $working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
-
- // Clean up working directory
- if ( $wp_filesystem->is_dir( $working_dir ) ) {
- $wp_filesystem->delete( $working_dir, true );
- }
-
- // Unzip package to working directory
- $result = unzip_file( $package, $working_dir );
-
- // Once extracted, delete the package if required.
- if ( $delete_package ) {
- unlink( $package );
- }
-
- if ( is_wp_error( $result ) ) {
- $wp_filesystem->delete( $working_dir, true );
- if ( 'incompatible_archive' == $result->get_error_code() ) {
- return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
- }
- return $result;
- }
-
- return $working_dir;
- }
-
- /**
- * Flatten the results of WP_Filesystem::dirlist() for iterating over.
- *
- * @since 4.9.0
- * @access protected
- *
- * @param array $nested_files Array of files as returned by WP_Filesystem::dirlist()
- * @param string $path Relative path to prepend to child nodes. Optional.
- * @return array $files A flattened array of the $nested_files specified.
- */
- protected function flatten_dirlist( $nested_files, $path = '' ) {
- $files = array();
-
- foreach ( $nested_files as $name => $details ) {
- $files[ $path . $name ] = $details;
-
- // Append children recursively
- if ( ! empty( $details['files'] ) ) {
- $children = $this->flatten_dirlist( $details['files'], $path . $name . '/' );
-
- // Merge keeping possible numeric keys, which array_merge() will reindex from 0..n
- $files = $files + $children;
- }
- }
-
- return $files;
- }
-
- /**
- * Clears the directory where this item is going to be installed into.
- *
- * @since 4.3.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- *
- * @param string $remote_destination The location on the remote filesystem to be cleared
- * @return bool|WP_Error True upon success, WP_Error on failure.
- */
- public function clear_destination( $remote_destination ) {
- global $wp_filesystem;
-
- $files = $wp_filesystem->dirlist( $remote_destination, true, true );
-
- // False indicates that the $remote_destination doesn't exist.
- if ( false === $files ) {
- return true;
- }
-
- // Flatten the file list to iterate over
- $files = $this->flatten_dirlist( $files );
-
- // Check all files are writable before attempting to clear the destination.
- $unwritable_files = array();
-
- // Check writability.
- foreach ( $files as $filename => $file_details ) {
- if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {
- // Attempt to alter permissions to allow writes and try again.
- $wp_filesystem->chmod( $remote_destination . $filename, ( 'd' == $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) );
- if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {
- $unwritable_files[] = $filename;
- }
- }
- }
-
- if ( ! empty( $unwritable_files ) ) {
- return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );
- }
-
- if ( ! $wp_filesystem->delete( $remote_destination, true ) ) {
- return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
- }
-
- return true;
- }
-
- /**
- * Install a package.
- *
- * Copies the contents of a package form a source directory, and installs them in
- * a destination directory. Optionally removes the source. It can also optionally
- * clear out the destination folder if it already exists.
- *
- * @since 2.8.0
- *
- * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
- * @global array $wp_theme_directories
- *
- * @param array|string $args {
- * Optional. Array or string of arguments for installing a package. Default empty array.
- *
- * @type string $source Required path to the package source. Default empty.
- * @type string $destination Required path to a folder to install the package in.
- * Default empty.
- * @type bool $clear_destination Whether to delete any files already in the destination
- * folder. Default false.
- * @type bool $clear_working Whether to delete the files form the working directory
- * after copying to the destination. Default false.
- * @type bool $abort_if_destination_exists Whether to abort the installation if
- * the destination folder already exists. Default true.
- * @type array $hook_extra Extra arguments to pass to the filter hooks called by
- * WP_Upgrader::install_package(). Default empty array.
- * }
- *
- * @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.
- */
- public function install_package( $args = array() ) {
- global $wp_filesystem, $wp_theme_directories;
-
- $defaults = array(
- 'source' => '', // Please always pass this
- 'destination' => '', // and this
- 'clear_destination' => false,
- 'clear_working' => false,
- 'abort_if_destination_exists' => true,
- 'hook_extra' => array(),
- );
-
- $args = wp_parse_args( $args, $defaults );
-
- // These were previously extract()'d.
- $source = $args['source'];
- $destination = $args['destination'];
- $clear_destination = $args['clear_destination'];
-
- set_time_limit( 300 );
-
- if ( empty( $source ) || empty( $destination ) ) {
- return new WP_Error( 'bad_request', $this->strings['bad_request'] );
- }
- $this->skin->feedback( 'installing_package' );
-
- /**
- * Filters the install response before the installation has started.
- *
- * Returning a truthy value, or one that could be evaluated as a WP_Error
- * will effectively short-circuit the installation, returning that value
- * instead.
- *
- * @since 2.8.0
- *
- * @param bool|WP_Error $response Response.
- * @param array $hook_extra Extra arguments passed to hooked filters.
- */
- $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
-
- if ( is_wp_error( $res ) ) {
- return $res;
- }
-
- //Retain the Original source and destinations
- $remote_source = $args['source'];
- $local_destination = $destination;
-
- $source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
- $remote_destination = $wp_filesystem->find_folder( $local_destination );
-
- //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
- if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { //Only one folder? Then we want its contents.
- $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
- } elseif ( count( $source_files ) == 0 ) {
- return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
- } else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename.
- $source = trailingslashit( $args['source'] );
- }
-
- /**
- * Filters the source file location for the upgrade package.
- *
- * @since 2.8.0
- * @since 4.4.0 The $hook_extra parameter became available.
- *
- * @param string $source File source location.
- * @param string $remote_source Remote file source location.
- * @param WP_Upgrader $this WP_Upgrader instance.
- * @param array $hook_extra Extra arguments passed to hooked filters.
- */
- $source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
-
- if ( is_wp_error( $source ) ) {
- return $source;
- }
-
- // Has the source location changed? If so, we need a new source_files list.
- if ( $source !== $remote_source ) {
- $source_files = array_keys( $wp_filesystem->dirlist( $source ) );
- }
-
- /*
- * Protection against deleting files in any important base directories.
- * Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
- * destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
- * to copy the directory into the directory, whilst they pass the source
- * as the actual files to copy.
- */
- $protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
-
- if ( is_array( $wp_theme_directories ) ) {
- $protected_directories = array_merge( $protected_directories, $wp_theme_directories );
- }
-
- if ( in_array( $destination, $protected_directories ) ) {
- $remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
- $destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
- }
-
- if ( $clear_destination ) {
- // We're going to clear the destination if there's something there.
- $this->skin->feedback( 'remove_old' );
-
- $removed = $this->clear_destination( $remote_destination );
-
- /**
- * Filters whether the upgrader cleared the destination.
- *
- * @since 2.8.0
- *
- * @param mixed $removed Whether the destination was cleared. true on success, WP_Error on failure
- * @param string $local_destination The local package destination.
- * @param string $remote_destination The remote package destination.
- * @param array $hook_extra Extra arguments passed to hooked filters.
- */
- $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
-
- if ( is_wp_error( $removed ) ) {
- return $removed;
- }
- } elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists( $remote_destination ) ) {
- //If we're not clearing the destination folder and something exists there already, Bail.
- //But first check to see if there are actually any files in the folder.
- $_files = $wp_filesystem->dirlist( $remote_destination );
- if ( ! empty( $_files ) ) {
- $wp_filesystem->delete( $remote_source, true ); //Clear out the source files.
- return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination );
- }
- }
-
- //Create destination if needed
- if ( ! $wp_filesystem->exists( $remote_destination ) ) {
- if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
- return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
- }
- }
- // Copy new version of item into place.
- $result = copy_dir( $source, $remote_destination );
- if ( is_wp_error( $result ) ) {
- if ( $args['clear_working'] ) {
- $wp_filesystem->delete( $remote_source, true );
- }
- return $result;
- }
-
- //Clear the Working folder?
- if ( $args['clear_working'] ) {
- $wp_filesystem->delete( $remote_source, true );
- }
-
- $destination_name = basename( str_replace( $local_destination, '', $destination ) );
- if ( '.' == $destination_name ) {
- $destination_name = '';
- }
-
- $this->result = compact( 'source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination' );
-
- /**
- * Filters the installation response after the installation has finished.
- *
- * @since 2.8.0
- *
- * @param bool $response Installation response.
- * @param array $hook_extra Extra arguments passed to hooked filters.
- * @param array $result Installation result data.
- */
- $res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
-
- if ( is_wp_error( $res ) ) {
- $this->result = $res;
- return $res;
- }
-
- //Bombard the calling function will all the info which we've just used.
- return $this->result;
- }
-
- /**
- * Run an upgrade/installation.
- *
- * Attempts to download the package (if it is not a local file), unpack it, and
- * install it in the destination folder.
- *
- * @since 2.8.0
- *
- * @param array $options {
- * Array or string of arguments for upgrading/installing a package.
- *
- * @type string $package The full path or URI of the package to install.
- * Default empty.
- * @type string $destination The full path to the destination folder.
- * Default empty.
- * @type bool $clear_destination Whether to delete any files already in the
- * destination folder. Default false.
- * @type bool $clear_working Whether to delete the files form the working
- * directory after copying to the destination.
- * Default false.
- * @type bool $abort_if_destination_exists Whether to abort the installation if the destination
- * folder already exists. When true, `$clear_destination`
- * should be false. Default true.
- * @type bool $is_multi Whether this run is one of multiple upgrade/installation
- * actions being performed in bulk. When true, the skin
- * WP_Upgrader::header() and WP_Upgrader::footer()
- * aren't called. Default false.
- * @type array $hook_extra Extra arguments to pass to the filter hooks called by
- * WP_Upgrader::run().
- * }
- * @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error,
- * or false if unable to connect to the filesystem.
- */
- public function run( $options ) {
-
- $defaults = array(
- 'package' => '', // Please always pass this.
- 'destination' => '', // And this
- 'clear_destination' => false,
- 'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
- 'clear_working' => true,
- 'is_multi' => false,
- 'hook_extra' => array(), // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
- );
-
- $options = wp_parse_args( $options, $defaults );
-
- /**
- * Filters the package options before running an update.
- *
- * See also {@see 'upgrader_process_complete'}.
- *
- * @since 4.3.0
- *
- * @param array $options {
- * Options used by the upgrader.
- *
- * @type string $package Package for update.
- * @type string $destination Update location.
- * @type bool $clear_destination Clear the destination resource.
- * @type bool $clear_working Clear the working resource.
- * @type bool $abort_if_destination_exists Abort if the Destination directory exists.
- * @type bool $is_multi Whether the upgrader is running multiple times.
- * @type array $hook_extra {
- * Extra hook arguments.
- *
- * @type string $action Type of action. Default 'update'.
- * @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'.
- * @type bool $bulk Whether the update process is a bulk update. Default true.
- * @type string $plugin Path to the plugin file relative to the plugins directory.
- * @type string $theme The stylesheet or template name of the theme.
- * @type string $language_update_type The language pack update type. Accepts 'plugin', 'theme',
- * or 'core'.
- * @type object $language_update The language pack update offer.
- * }
- * }
- */
- $options = apply_filters( 'upgrader_package_options', $options );
-
- if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times
- $this->skin->header();
- }
-
- // Connect to the Filesystem first.
- $res = $this->fs_connect( array( WP_CONTENT_DIR, $options['destination'] ) );
- // Mainly for non-connected filesystem.
- if ( ! $res ) {
- if ( ! $options['is_multi'] ) {
- $this->skin->footer();
- }
- return false;
- }
-
- $this->skin->before();
-
- if ( is_wp_error( $res ) ) {
- $this->skin->error( $res );
- $this->skin->after();
- if ( ! $options['is_multi'] ) {
- $this->skin->footer();
- }
- return $res;
- }
-
- /*
- * Download the package (Note, This just returns the filename
- * of the file if the package is a local file)
- */
- $download = $this->download_package( $options['package'], true );
-
- // Allow for signature soft-fail.
- // WARNING: This may be removed in the future.
- if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {
-
- // Don't output the 'no signature could be found' failure message for now.
- if ( 'signature_verification_no_signature' != $download->get_error_code() || WP_DEBUG ) {
- // Outout the failure error as a normal feedback, and not as an error:
- $this->skin->feedback( $download->get_error_message() );
-
- // Report this failure back to WordPress.org for debugging purposes.
- wp_version_check(
- array(
- 'signature_failure_code' => $download->get_error_code(),
- 'signature_failure_data' => $download->get_error_data(),
- )
- );
- }
-
- // Pretend this error didn't happen.
- $download = $download->get_error_data( 'softfail-filename' );
- }
-
- if ( is_wp_error( $download ) ) {
- $this->skin->error( $download );
- $this->skin->after();
- if ( ! $options['is_multi'] ) {
- $this->skin->footer();
- }
- return $download;
- }
-
- $delete_package = ( $download != $options['package'] ); // Do not delete a "local" file
-
- // Unzips the file into a temporary directory.
- $working_dir = $this->unpack_package( $download, $delete_package );
- if ( is_wp_error( $working_dir ) ) {
- $this->skin->error( $working_dir );
- $this->skin->after();
- if ( ! $options['is_multi'] ) {
- $this->skin->footer();
- }
- return $working_dir;
- }
-
- // With the given options, this installs it to the destination directory.
- $result = $this->install_package(
- array(
- 'source' => $working_dir,
- 'destination' => $options['destination'],
- 'clear_destination' => $options['clear_destination'],
- 'abort_if_destination_exists' => $options['abort_if_destination_exists'],
- 'clear_working' => $options['clear_working'],
- 'hook_extra' => $options['hook_extra'],
- )
- );
-
- $this->skin->set_result( $result );
- if ( is_wp_error( $result ) ) {
- $this->skin->error( $result );
- $this->skin->feedback( 'process_failed' );
- } else {
- // Installation succeeded.
- $this->skin->feedback( 'process_success' );
- }
-
- $this->skin->after();
-
- if ( ! $options['is_multi'] ) {
-
- /**
- * Fires when the upgrader process is complete.
- *
- * See also {@see 'upgrader_package_options'}.
- *
- * @since 3.6.0
- * @since 3.7.0 Added to WP_Upgrader::run().
- * @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`.
- *
- * @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a
- * Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or Language_Pack_Upgrader instance.
- * @param array $hook_extra {
- * Array of bulk item update data.
- *
- * @type string $action Type of action. Default 'update'.
- * @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'.
- * @type bool $bulk Whether the update process is a bulk update. Default true.
- * @type array $plugins Array of the basename paths of the plugins' main files.
- * @type array $themes The theme slugs.
- * @type array $translations {
- * Array of translations update data.
- *
- * @type string $language The locale the translation is for.
- * @type string $type Type of translation. Accepts 'plugin', 'theme', or 'core'.
- * @type string $slug Text domain the translation is for. The slug of a theme/plugin or
- * 'default' for core translations.
- * @type string $version The version of a theme, plugin, or core.
- * }
- * }
- */
- do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
-
- $this->skin->footer();
- }
-
- return $result;
- }
-
- /**
- * Toggle maintenance mode for the site.
- *
- * Creates/deletes the maintenance file to enable/disable maintenance mode.
- *
- * @since 2.8.0
- *
- * @global WP_Filesystem_Base $wp_filesystem Subclass
- *
- * @param bool $enable True to enable maintenance mode, false to disable.
- */
- public function maintenance_mode( $enable = false ) {
- global $wp_filesystem;
- $file = $wp_filesystem->abspath() . '.maintenance';
- if ( $enable ) {
- $this->skin->feedback( 'maintenance_start' );
- // Create maintenance file to signal that we are upgrading
- $maintenance_string = '';
- $wp_filesystem->delete( $file );
- $wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE );
- } elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
- $this->skin->feedback( 'maintenance_end' );
- $wp_filesystem->delete( $file );
- }
- }
-
- /**
- * Creates a lock using WordPress options.
- *
- * @since 4.5.0
- *
- * @param string $lock_name The name of this unique lock.
- * @param int $release_timeout Optional. The duration in seconds to respect an existing lock.
- * Default: 1 hour.
- * @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise.
- */
- public static function create_lock( $lock_name, $release_timeout = null ) {
- global $wpdb;
- if ( ! $release_timeout ) {
- $release_timeout = HOUR_IN_SECONDS;
- }
- $lock_option = $lock_name . '.lock';
-
- // Try to lock.
- $lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time() ) );
-
- if ( ! $lock_result ) {
- $lock_result = get_option( $lock_option );
-
- // If a lock couldn't be created, and there isn't a lock, bail.
- if ( ! $lock_result ) {
- return false;
- }
-
- // Check to see if the lock is still valid. If it is, bail.
- if ( $lock_result > ( time() - $release_timeout ) ) {
- return false;
- }
-
- // There must exist an expired lock, clear it and re-gain it.
- WP_Upgrader::release_lock( $lock_name );
-
- return WP_Upgrader::create_lock( $lock_name, $release_timeout );
- }
-
- // Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
- update_option( $lock_option, time() );
-
- return true;
- }
-
- /**
- * Releases an upgrader lock.
- *
- * @since 4.5.0
- *
- * @see WP_Upgrader::create_lock()
- *
- * @param string $lock_name The name of this unique lock.
- * @return bool True if the lock was successfully released. False on failure.
- */
- public static function release_lock( $lock_name ) {
- return delete_option( $lock_name . '.lock' );
- }
-
-}
-
-/** Plugin_Upgrader class */
-require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
-
-/** Theme_Upgrader class */
-require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader.php';
-
-/** Language_Pack_Upgrader class */
-require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader.php';
-
-/** Core_Upgrader class */
-require_once ABSPATH . 'wp-admin/includes/class-core-upgrader.php';
-
-/** File_Upload_Upgrader class */
-require_once ABSPATH . 'wp-admin/includes/class-file-upload-upgrader.php';
-
-/** WP_Automatic_Updater class */
-require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
diff --git a/srcs/wordpress/wp-admin/includes/class-wp-users-list-table.php b/srcs/wordpress/wp-admin/includes/class-wp-users-list-table.php
deleted file mode 100644
index 8653df8..0000000
--- a/srcs/wordpress/wp-admin/includes/class-wp-users-list-table.php
+++ /dev/null
@@ -1,642 +0,0 @@
- 'user',
- 'plural' => 'users',
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
- )
- );
-
- $this->is_site_users = 'site-users-network' === $this->screen->id;
-
- if ( $this->is_site_users ) {
- $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
- }
- }
-
- /**
- * Check the current user's permissions.
- *
- * @since 3.1.0
- *
- * @return bool
- */
- public function ajax_user_can() {
- if ( $this->is_site_users ) {
- return current_user_can( 'manage_sites' );
- } else {
- return current_user_can( 'list_users' );
- }
- }
-
- /**
- * Prepare the users list for display.
- *
- * @since 3.1.0
- *
- * @global string $role
- * @global string $usersearch
- */
- public function prepare_items() {
- global $role, $usersearch;
-
- $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
-
- $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
-
- $per_page = ( $this->is_site_users ) ? 'site_users_network_per_page' : 'users_per_page';
- $users_per_page = $this->get_items_per_page( $per_page );
-
- $paged = $this->get_pagenum();
-
- if ( 'none' === $role ) {
- $args = array(
- 'number' => $users_per_page,
- 'offset' => ( $paged - 1 ) * $users_per_page,
- 'include' => wp_get_users_with_no_role( $this->site_id ),
- 'search' => $usersearch,
- 'fields' => 'all_with_meta',
- );
- } else {
- $args = array(
- 'number' => $users_per_page,
- 'offset' => ( $paged - 1 ) * $users_per_page,
- 'role' => $role,
- 'search' => $usersearch,
- 'fields' => 'all_with_meta',
- );
- }
-
- if ( '' !== $args['search'] ) {
- $args['search'] = '*' . $args['search'] . '*';
- }
-
- if ( $this->is_site_users ) {
- $args['blog_id'] = $this->site_id;
- }
-
- if ( isset( $_REQUEST['orderby'] ) ) {
- $args['orderby'] = $_REQUEST['orderby'];
- }
-
- if ( isset( $_REQUEST['order'] ) ) {
- $args['order'] = $_REQUEST['order'];
- }
-
- /**
- * Filters the query arguments used to retrieve users for the current users list table.
- *
- * @since 4.4.0
- *
- * @param array $args Arguments passed to WP_User_Query to retrieve items for the current
- * users list table.
- */
- $args = apply_filters( 'users_list_table_query_args', $args );
-
- // Query the user IDs for this page
- $wp_user_search = new WP_User_Query( $args );
-
- $this->items = $wp_user_search->get_results();
-
- $this->set_pagination_args(
- array(
- 'total_items' => $wp_user_search->get_total(),
- 'per_page' => $users_per_page,
- )
- );
- }
-
- /**
- * Output 'no users' message.
- *
- * @since 3.1.0
- */
- public function no_items() {
- _e( 'No users found.' );
- }
-
- /**
- * Return an associative array listing all the views that can be used
- * with this table.
- *
- * Provides a list of roles and user count for that role for easy
- * Filtersing of the user table.
- *
- * @since 3.1.0
- *
- * @global string $role
- *
- * @return array An array of HTML links, one for each view.
- */
- protected function get_views() {
- global $role;
-
- $wp_roles = wp_roles();
-
- if ( $this->is_site_users ) {
- $url = 'site-users.php?id=' . $this->site_id;
- switch_to_blog( $this->site_id );
- $users_of_blog = count_users( 'time', $this->site_id );
- restore_current_blog();
- } else {
- $url = 'users.php';
- $users_of_blog = count_users();
- }
-
- $total_users = $users_of_blog['total_users'];
- $avail_roles =& $users_of_blog['avail_roles'];
- unset( $users_of_blog );
-
- $current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
-
- $role_links = array();
- $role_links['all'] = sprintf(
- '
%s ',
- $url,
- $current_link_attributes,
- sprintf(
- /* translators: %s: Number of users. */
- _nx(
- 'All
(%s) ',
- 'All
(%s) ',
- $total_users,
- 'users'
- ),
- number_format_i18n( $total_users )
- )
- );
-
- foreach ( $wp_roles->get_names() as $this_role => $name ) {
- if ( ! isset( $avail_roles[ $this_role ] ) ) {
- continue;
- }
-
- $current_link_attributes = '';
-
- if ( $this_role === $role ) {
- $current_link_attributes = ' class="current" aria-current="page"';
- }
-
- $name = translate_user_role( $name );
- $name = sprintf(
- /* translators: User role name with count. */
- __( '%1$s
(%2$s) ' ),
- $name,
- number_format_i18n( $avail_roles[ $this_role ] )
- );
-
- $role_links[ $this_role ] = "
$name ";
- }
-
- if ( ! empty( $avail_roles['none'] ) ) {
-
- $current_link_attributes = '';
-
- if ( 'none' === $role ) {
- $current_link_attributes = ' class="current" aria-current="page"';
- }
-
- $name = __( 'No role' );
- $name = sprintf(
- /* translators: User role name with count. */
- __( '%1$s
(%2$s) ' ),
- $name,
- number_format_i18n( $avail_roles['none'] )
- );
-
- $role_links['none'] = "
$name ";
- }
-
- return $role_links;
- }
-
- /**
- * Retrieve an associative array of bulk actions available on this table.
- *
- * @since 3.1.0
- *
- * @return array Array of bulk actions.
- */
- protected function get_bulk_actions() {
- $actions = array();
-
- if ( is_multisite() ) {
- if ( current_user_can( 'remove_users' ) ) {
- $actions['remove'] = __( 'Remove' );
- }
- } else {
- if ( current_user_can( 'delete_users' ) ) {
- $actions['delete'] = __( 'Delete' );
- }
- }
-
- return $actions;
- }
-
- /**
- * Output the controls to allow user roles to be changed in bulk.
- *
- * @since 3.1.0
- *
- * @param string $which Whether this is being invoked above ("top")
- * or below the table ("bottom").
- */
- protected function extra_tablenav( $which ) {
- $id = 'bottom' === $which ? 'new_role2' : 'new_role';
- $button_id = 'bottom' === $which ? 'changeit2' : 'changeit';
- ?>
-
- has_items() ) : ?>
-
-
-
-
-
-
-
- '
',
- 'username' => __( 'Username' ),
- 'name' => __( 'Name' ),
- 'email' => __( 'Email' ),
- 'role' => __( 'Role' ),
- 'posts' => __( 'Posts' ),
- );
-
- if ( $this->is_site_users ) {
- unset( $c['posts'] );
- }
-
- return $c;
- }
-
- /**
- * Get a list of sortable columns for the list table.
- *
- * @since 3.1.0
- *
- * @return array Array of sortable columns.
- */
- protected function get_sortable_columns() {
- $c = array(
- 'username' => 'login',
- 'email' => 'email',
- );
-
- return $c;
- }
-
- /**
- * Generate the list table rows.
- *
- * @since 3.1.0
- */
- public function display_rows() {
- // Query the post counts for this page
- if ( ! $this->is_site_users ) {
- $post_counts = count_many_users_posts( array_keys( $this->items ) );
- }
-
- foreach ( $this->items as $userid => $user_object ) {
- echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
- }
- }
-
- /**
- * Generate HTML for a single row on the users.php admin panel.
- *
- * @since 3.1.0
- * @since 4.2.0 The `$style` parameter was deprecated.
- * @since 4.4.0 The `$role` parameter was deprecated.
- *
- * @param WP_User $user_object The current user object.
- * @param string $style Deprecated. Not used.
- * @param string $role Deprecated. Not used.
- * @param int $numposts Optional. Post count to display for this user. Defaults
- * to zero, as in, a new user has made zero posts.
- * @return string Output for a single row.
- */
- public function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
- if ( ! ( $user_object instanceof WP_User ) ) {
- $user_object = get_userdata( (int) $user_object );
- }
- $user_object->filter = 'display';
- $email = $user_object->user_email;
-
- if ( $this->is_site_users ) {
- $url = "site-users.php?id={$this->site_id}&";
- } else {
- $url = 'users.php?';
- }
-
- $user_roles = $this->get_role_list( $user_object );
-
- // Set up the hover actions for this user
- $actions = array();
- $checkbox = '';
- $super_admin = '';
-
- if ( is_multisite() && current_user_can( 'manage_network_users' ) ) {
- if ( in_array( $user_object->user_login, get_super_admins(), true ) ) {
- $super_admin = ' — ' . __( 'Super Admin' );
- }
- }
-
- // Check if the user for this row is editable
- if ( current_user_can( 'list_users' ) ) {
- // Set up the user editing link
- $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) );
-
- if ( current_user_can( 'edit_user', $user_object->ID ) ) {
- $edit = "
{$user_object->user_login} {$super_admin}";
- $actions['edit'] = '
' . __( 'Edit' ) . ' ';
- } else {
- $edit = "
{$user_object->user_login}{$super_admin} ";
- }
-
- if ( ! is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) {
- $actions['delete'] = "
" . __( 'Delete' ) . ' ';
- }
- if ( is_multisite() && current_user_can( 'remove_user', $user_object->ID ) ) {
- $actions['remove'] = "
" . __( 'Remove' ) . ' ';
- }
-
- // Add a link to the user's author archive, if not empty.
- $author_posts_url = get_author_posts_url( $user_object->ID );
- if ( $author_posts_url ) {
- $actions['view'] = sprintf(
- '
%s ',
- esc_url( $author_posts_url ),
- /* translators: %s: Author's display name. */
- esc_attr( sprintf( __( 'View posts by %s' ), $user_object->display_name ) ),
- __( 'View' )
- );
- }
-
- /**
- * Filters the action links displayed under each user in the Users list table.
- *
- * @since 2.8.0
- *
- * @param string[] $actions An array of action links to be displayed.
- * Default 'Edit', 'Delete' for single site, and
- * 'Edit', 'Remove' for Multisite.
- * @param WP_User $user_object WP_User object for the currently listed user.
- */
- $actions = apply_filters( 'user_row_actions', $actions, $user_object );
-
- // Role classes.
- $role_classes = esc_attr( implode( ' ', array_keys( $user_roles ) ) );
-
- // Set up the checkbox ( because the user is editable, otherwise it's empty )
- $checkbox = sprintf(
- '
%2$s ' .
- '
',
- $user_object->ID,
- /* translators: %s: User login. */
- sprintf( __( 'Select %s' ), $user_object->user_login ),
- $role_classes
- );
-
- } else {
- $edit = "
{$user_object->user_login}{$super_admin} ";
- }
-
- $avatar = get_avatar( $user_object->ID, 32 );
-
- // Comma-separated list of user roles.
- $roles_list = implode( ', ', $user_roles );
-
- $r = "
";
-
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
-
- foreach ( $columns as $column_name => $column_display_name ) {
- $classes = "$column_name column-$column_name";
- if ( $primary === $column_name ) {
- $classes .= ' has-row-actions column-primary';
- }
- if ( 'posts' === $column_name ) {
- $classes .= ' num'; // Special case for that column
- }
-
- if ( in_array( $column_name, $hidden ) ) {
- $classes .= ' hidden';
- }
-
- $data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
-
- $attributes = "class='$classes' $data";
-
- if ( 'cb' === $column_name ) {
- $r .= "$checkbox ";
- } else {
- $r .= "";
- switch ( $column_name ) {
- case 'username':
- $r .= "$avatar $edit";
- break;
- case 'name':
- if ( $user_object->first_name && $user_object->last_name ) {
- $r .= "$user_object->first_name $user_object->last_name";
- } elseif ( $user_object->first_name ) {
- $r .= $user_object->first_name;
- } elseif ( $user_object->last_name ) {
- $r .= $user_object->last_name;
- } else {
- $r .= sprintf(
- '— %s ',
- _x( 'Unknown', 'name' )
- );
- }
- break;
- case 'email':
- $r .= "$email ";
- break;
- case 'role':
- $r .= esc_html( $roles_list );
- break;
- case 'posts':
- if ( $numposts > 0 ) {
- $r .= sprintf(
- '%s %s ',
- "edit.php?author={$user_object->ID}",
- $numposts,
- sprintf(
- /* translators: %s: Number of posts. */
- _n( '%s post by this author', '%s posts by this author', $numposts ),
- number_format_i18n( $numposts )
- )
- );
- } else {
- $r .= 0;
- }
- break;
- default:
- /**
- * Filters the display output of custom columns in the Users list table.
- *
- * @since 2.8.0
- *
- * @param string $output Custom column output. Default empty.
- * @param string $column_name Column name.
- * @param int $user_id ID of the currently-listed user.
- */
- $r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
- }
-
- if ( $primary === $column_name ) {
- $r .= $this->row_actions( $actions );
- }
- $r .= ' ';
- }
- }
- $r .= ' ';
-
- return $r;
- }
-
- /**
- * Gets the name of the default primary column.
- *
- * @since 4.3.0
- *
- * @return string Name of the default primary column, in this case, 'username'.
- */
- protected function get_default_primary_column_name() {
- return 'username';
- }
-
- /**
- * Returns an array of user roles for a given user object.
- *
- * @since 4.4.0
- *
- * @param WP_User $user_object The WP_User object.
- * @return string[] An array of user roles.
- */
- protected function get_role_list( $user_object ) {
- $wp_roles = wp_roles();
-
- $role_list = array();
-
- foreach ( $user_object->roles as $role ) {
- if ( isset( $wp_roles->role_names[ $role ] ) ) {
- $role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] );
- }
- }
-
- if ( empty( $role_list ) ) {
- $role_list['none'] = _x( 'None', 'no user roles' );
- }
-
- /**
- * Filters the returned array of roles for a user.
- *
- * @since 4.4.0
- *
- * @param string[] $role_list An array of user roles.
- * @param WP_User $user_object A WP_User object.
- */
- return apply_filters( 'get_role_list', $role_list, $user_object );
- }
-
-}
diff --git a/srcs/wordpress/wp-admin/includes/comment.php b/srcs/wordpress/wp-admin/includes/comment.php
deleted file mode 100644
index 7b48f5d..0000000
--- a/srcs/wordpress/wp-admin/includes/comment.php
+++ /dev/null
@@ -1,213 +0,0 @@
-get_var(
- $wpdb->prepare(
- "SELECT comment_post_ID FROM $wpdb->comments
- WHERE comment_author = %s AND $date_field = %s",
- stripslashes( $comment_author ),
- stripslashes( $comment_date )
- )
- );
-}
-
-/**
- * Update a comment with values provided in $_POST.
- *
- * @since 2.0.0
- */
-function edit_comment() {
- if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) {
- wp_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
- }
-
- if ( isset( $_POST['newcomment_author'] ) ) {
- $_POST['comment_author'] = $_POST['newcomment_author'];
- }
- if ( isset( $_POST['newcomment_author_email'] ) ) {
- $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
- }
- if ( isset( $_POST['newcomment_author_url'] ) ) {
- $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
- }
- if ( isset( $_POST['comment_status'] ) ) {
- $_POST['comment_approved'] = $_POST['comment_status'];
- }
- if ( isset( $_POST['content'] ) ) {
- $_POST['comment_content'] = $_POST['content'];
- }
- if ( isset( $_POST['comment_ID'] ) ) {
- $_POST['comment_ID'] = (int) $_POST['comment_ID'];
- }
-
- foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
- if ( ! empty( $_POST[ 'hidden_' . $timeunit ] ) && $_POST[ 'hidden_' . $timeunit ] != $_POST[ $timeunit ] ) {
- $_POST['edit_date'] = '1';
- break;
- }
- }
-
- if ( ! empty( $_POST['edit_date'] ) ) {
- $aa = $_POST['aa'];
- $mm = $_POST['mm'];
- $jj = $_POST['jj'];
- $hh = $_POST['hh'];
- $mn = $_POST['mn'];
- $ss = $_POST['ss'];
- $jj = ( $jj > 31 ) ? 31 : $jj;
- $hh = ( $hh > 23 ) ? $hh - 24 : $hh;
- $mn = ( $mn > 59 ) ? $mn - 60 : $mn;
- $ss = ( $ss > 59 ) ? $ss - 60 : $ss;
- $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
- }
-
- wp_update_comment( $_POST );
-}
-
-/**
- * Returns a WP_Comment object based on comment ID.
- *
- * @since 2.0.0
- *
- * @param int $id ID of comment to retrieve.
- * @return WP_Comment|false Comment if found. False on failure.
- */
-function get_comment_to_edit( $id ) {
- $comment = get_comment( $id );
- if ( ! $comment ) {
- return false;
- }
-
- $comment->comment_ID = (int) $comment->comment_ID;
- $comment->comment_post_ID = (int) $comment->comment_post_ID;
-
- $comment->comment_content = format_to_edit( $comment->comment_content );
- /**
- * Filters the comment content before editing.
- *
- * @since 2.0.0
- *
- * @param string $comment->comment_content Comment content.
- */
- $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
-
- $comment->comment_author = format_to_edit( $comment->comment_author );
- $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
- $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
- $comment->comment_author_url = esc_url( $comment->comment_author_url );
-
- return $comment;
-}
-
-/**
- * Get the number of pending comments on a post or posts
- *
- * @since 2.3.0
- *
- * @global wpdb $wpdb WordPress database abstraction object.
- *
- * @param int|array $post_id Either a single Post ID or an array of Post IDs
- * @return int|array Either a single Posts pending comments as an int or an array of ints keyed on the Post IDs
- */
-function get_pending_comments_num( $post_id ) {
- global $wpdb;
-
- $single = false;
- if ( ! is_array( $post_id ) ) {
- $post_id_array = (array) $post_id;
- $single = true;
- } else {
- $post_id_array = $post_id;
- }
- $post_id_array = array_map( 'intval', $post_id_array );
- $post_id_in = "'" . implode( "', '", $post_id_array ) . "'";
-
- $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A );
-
- if ( $single ) {
- if ( empty( $pending ) ) {
- return 0;
- } else {
- return absint( $pending[0]['num_comments'] );
- }
- }
-
- $pending_keyed = array();
-
- // Default to zero pending for all posts in request
- foreach ( $post_id_array as $id ) {
- $pending_keyed[ $id ] = 0;
- }
-
- if ( ! empty( $pending ) ) {
- foreach ( $pending as $pend ) {
- $pending_keyed[ $pend['comment_post_ID'] ] = absint( $pend['num_comments'] );
- }
- }
-
- return $pending_keyed;
-}
-
-/**
- * Add avatars to relevant places in admin, or try to.
- *
- * @since 2.5.0
- *
- * @param string $name User name.
- * @return string Avatar with Admin name.
- */
-function floated_admin_avatar( $name ) {
- $avatar = get_avatar( get_comment(), 32, 'mystery' );
- return "$avatar $name";
-}
-
-/**
- * @since 2.7.0
- */
-function enqueue_comment_hotkeys_js() {
- if ( 'true' == get_user_option( 'comment_shortcuts' ) ) {
- wp_enqueue_script( 'jquery-table-hotkeys' );
- }
-}
-
-/**
- * Display error message at bottom of comments.
- *
- * @param string $msg Error Message. Assumed to contain HTML and be sanitized.
- */
-function comment_footer_die( $msg ) {
- echo "
";
- include( ABSPATH . 'wp-admin/admin-footer.php' );
- die;
-}
diff --git a/srcs/wordpress/wp-admin/includes/continents-cities.php b/srcs/wordpress/wp-admin/includes/continents-cities.php
deleted file mode 100644
index 7ddfe74..0000000
--- a/srcs/wordpress/wp-admin/includes/continents-cities.php
+++ /dev/null
@@ -1,554 +0,0 @@
- 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );
-
- if ( wp_http_supports( array( 'ssl' ) ) ) {
- $url = set_url_scheme( $url, 'https' );
- }
-
- $response = wp_remote_get( $url, $options );
-
- if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
- return false;
- }
-
- $results = json_decode( wp_remote_retrieve_body( $response ), true );
-
- if ( ! is_array( $results ) ) {
- return false;
- }
-
- set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
- }
-
- return $results;
-}
-
-/**
- * Retrieve the link to a contributor's WordPress.org profile page.
- *
- * @access private
- * @since 3.2.0
- *
- * @param string $display_name The contributor's display name (passed by reference).
- * @param string $username The contributor's username.
- * @param string $profiles URL to the contributor's WordPress.org profile page.
- */
-function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
- $display_name = '
' . esc_html( $display_name ) . ' ';
-}
-
-/**
- * Retrieve the link to an external library used in WordPress.
- *
- * @access private
- * @since 3.2.0
- *
- * @param string $data External library data (passed by reference).
- */
-function _wp_credits_build_object_link( &$data ) {
- $data = '
' . esc_html( $data[0] ) . ' ';
-}
-
-/**
- * Displays the title for a given group of contributors.
- *
- * @since 5.3.0
- *
- * @param array $group_data The current contributor group.
- */
-function wp_credits_section_title( $group_data = array() ) {
- if ( ! count( $group_data ) ) {
- return;
- }
-
- if ( $group_data['name'] ) {
- if ( 'Translators' === $group_data['name'] ) {
- // Considered a special slug in the API response. (Also, will never be returned for en_US.)
- $title = _x( 'Translators', 'Translate this to be the equivalent of English Translators in your language for the credits page Translators section' );
- } elseif ( isset( $group_data['placeholders'] ) ) {
- // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
- $title = vsprintf( translate( $group_data['name'] ), $group_data['placeholders'] );
- } else {
- // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
- $title = translate( $group_data['name'] );
- }
-
- echo '
' . esc_html( $title ) . " \n";
- }
-}
-
-/**
- * Displays a list of contributors for a given group.
- *
- * @since 5.3.0
- *
- * @param array $credits The credits groups returned from the API.
- * @param string $slug The current group to display.
- */
-function wp_credits_section_list( $credits = array(), $slug = '' ) {
- $group_data = isset( $credits['groups'][ $slug ] ) ? $credits['groups'][ $slug ] : array();
- $credits_data = $credits['data'];
- if ( ! count( $group_data ) ) {
- return;
- }
-
- if ( ! empty( $group_data['shuffle'] ) ) {
- shuffle( $group_data['data'] ); // We were going to sort by ability to pronounce "hierarchical," but that wouldn't be fair to Matt.
- }
-
- switch ( $group_data['type'] ) {
- case 'list':
- array_walk( $group_data['data'], '_wp_credits_add_profile_link', $credits_data['profiles'] );
- echo '
' . wp_sprintf( '%l.', $group_data['data'] ) . "
\n\n";
- break;
- case 'libraries':
- array_walk( $group_data['data'], '_wp_credits_build_object_link' );
- echo '
' . wp_sprintf( '%l.', $group_data['data'] ) . "
\n\n";
- break;
- default:
- $compact = 'compact' === $group_data['type'];
- $classes = 'wp-people-group ' . ( $compact ? 'compact' : '' );
- echo '
\n";
- break;
- }
-}
diff --git a/srcs/wordpress/wp-admin/includes/dashboard.php b/srcs/wordpress/wp-admin/includes/dashboard.php
deleted file mode 100644
index 938fc58..0000000
--- a/srcs/wordpress/wp-admin/includes/dashboard.php
+++ /dev/null
@@ -1,1815 +0,0 @@
-cap->create_posts ) ) {
- $quick_draft_title = sprintf( '
%1$s %2$s ', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) );
- wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
- }
-
- // WordPress Events and News
- wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );
-
- if ( is_network_admin() ) {
-
- /**
- * Fires after core widgets for the Network Admin dashboard have been registered.
- *
- * @since 3.1.0
- */
- do_action( 'wp_network_dashboard_setup' );
-
- /**
- * Filters the list of widgets to load for the Network Admin dashboard.
- *
- * @since 3.1.0
- *
- * @param string[] $dashboard_widgets An array of dashboard widget IDs.
- */
- $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
- } elseif ( is_user_admin() ) {
-
- /**
- * Fires after core widgets for the User Admin dashboard have been registered.
- *
- * @since 3.1.0
- */
- do_action( 'wp_user_dashboard_setup' );
-
- /**
- * Filters the list of widgets to load for the User Admin dashboard.
- *
- * @since 3.1.0
- *
- * @param string[] $dashboard_widgets An array of dashboard widget IDs.
- */
- $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
- } else {
-
- /**
- * Fires after core widgets for the admin dashboard have been registered.
- *
- * @since 2.5.0
- */
- do_action( 'wp_dashboard_setup' );
-
- /**
- * Filters the list of widgets to load for the admin dashboard.
- *
- * @since 2.5.0
- *
- * @param string[] $dashboard_widgets An array of dashboard widget IDs.
- */
- $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
- }
-
- foreach ( $dashboard_widgets as $widget_id ) {
- $name = empty( $wp_registered_widgets[ $widget_id ]['all_link'] ) ? $wp_registered_widgets[ $widget_id ]['name'] : $wp_registered_widgets[ $widget_id ]['name'] . "
" . __( 'View all' ) . ' ';
- wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] );
- }
-
- if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
- check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
- ob_start(); // hack - but the same hack wp-admin/widgets.php uses
- wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
- ob_end_clean();
- wp_redirect( remove_query_arg( 'edit' ) );
- exit;
- }
-
- /** This action is documented in wp-admin/includes/meta-boxes.php */
- do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
-
- /** This action is documented in wp-admin/includes/meta-boxes.php */
- do_action( 'do_meta_boxes', $screen->id, 'side', '' );
-}
-
-/**
- * Adds a new dashboard widget.
- *
- * @since 2.7.0
- *
- * @global array $wp_dashboard_control_callbacks
- *
- * @param string $widget_id Widget ID (used in the 'id' attribute for the widget).
- * @param string $widget_name Title of the widget.
- * @param callable $callback Function that fills the widget with the desired content.
- * The function should echo its output.
- * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
- * @param array $callback_args Optional. Data that should be set as the $args property of the widget array
- * (which is the second parameter passed to your callback). Default null.
- */
-function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
- $screen = get_current_screen();
- global $wp_dashboard_control_callbacks;
-
- $private_callback_args = array( '__widget_basename' => $widget_name );
-
- if ( is_null( $callback_args ) ) {
- $callback_args = $private_callback_args;
- } elseif ( is_array( $callback_args ) ) {
- $callback_args = array_merge( $callback_args, $private_callback_args );
- }
-
- if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
- $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback;
- if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
- list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
- $widget_name .= '
' . __( 'Cancel' ) . ' ';
- $callback = '_wp_dashboard_control_callback';
- } else {
- list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
- $widget_name .= '
' . __( 'Configure' ) . ' ';
- }
- }
-
- $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
-
- $location = 'normal';
- if ( in_array( $widget_id, $side_widgets ) ) {
- $location = 'side';
- }
-
- $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
-
- $priority = 'core';
- if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
- $priority = 'high';
- }
-
- add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
-}
-
-/**
- * Outputs controls for the current dashboard widget.
- *
- * @access private
- * @since 2.7.0
- *
- * @param mixed $dashboard
- * @param array $meta_box
- */
-function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
- echo '
';
- wp_dashboard_trigger_widget_control( $meta_box['id'] );
- wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
- echo ' ';
- submit_button( __( 'Submit' ) );
- echo ' ';
-}
-
-/**
- * Displays the dashboard.
- *
- * @since 2.5.0
- */
-function wp_dashboard() {
- $screen = get_current_screen();
- $columns = absint( $screen->get_columns() );
- $columns_css = '';
- if ( $columns ) {
- $columns_css = " columns-$columns";
- }
-
- ?>
-
-
-
-
-
- publish ) {
- if ( 'post' == $post_type ) {
- /* translators: %s: Number of posts. */
- $text = _n( '%s Post', '%s Posts', $num_posts->publish );
- } else {
- /* translators: %s: Number of pages. */
- $text = _n( '%s Page', '%s Pages', $num_posts->publish );
- }
- $text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
- $post_type_object = get_post_type_object( $post_type );
- if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
- printf( '%2$s ', $post_type, $text );
- } else {
- printf( '%2$s ', $post_type, $text );
- }
- }
- }
- // Comments
- $num_comm = wp_count_comments();
- if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
- /* translators: %s: Number of comments. */
- $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
- ?>
-
- moderated );
- /* translators: %s: Number of comments. */
- $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );
- ?>
-
- ' . implode( "\n", $elements ) . " \n";
- }
-
- ?>
-
-
$content ";
- }
- ?>
-
-
-
-
-
- ' . __( 'Create a New Site' ) . '';
- }
- if ( current_user_can( 'create_users' ) ) {
- $actions['create-user'] = '
' . __( 'Create a New User' ) . ' ';
- }
-
- $c_users = get_user_count();
- $c_blogs = get_blog_count();
-
- /* translators: %s: Number of users on the network. */
- $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
- /* translators: %s: Number of sites on the network. */
- $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
-
- /* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network. */
- $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
-
- if ( $actions ) {
- echo '
';
- foreach ( $actions as $class => $action ) {
- $actions[ $class ] = "\t$action";
- }
- echo implode( " | \n", $actions ) . "\n";
- echo ' ';
- }
- ?>
-
-
-
-
-
-
-
-
-
-
-
- 'submit_users' ) ); ?>
-
-
-
-
-
-
-
- 'submit_sites' ) ); ?>
-
-
- post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
- $post = get_default_post_to_edit( 'post', true );
- update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
- } else {
- $post->post_title = ''; // Remove the auto draft title
- }
- } else {
- $post = get_default_post_to_edit( 'post', true );
- $user_id = get_current_user_id();
- // Don't create an option if this is a super admin who does not belong to this site.
- if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) {
- update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
- }
- }
-
- $post_ID = (int) $post->ID;
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 'save-post' ) ); ?>
-
-
-
-
- 'post',
- 'post_status' => 'draft',
- 'author' => get_current_user_id(),
- 'posts_per_page' => 4,
- 'orderby' => 'modified',
- 'order' => 'DESC',
- );
-
- /**
- * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
- *
- * @since 4.4.0
- *
- * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
- */
- $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );
-
- $drafts = get_posts( $query_args );
- if ( ! $drafts ) {
- return;
- }
- }
-
- echo '
';
- if ( count( $drafts ) > 3 ) {
- printf(
- '
%s
' . "\n",
- esc_url( admin_url( 'edit.php?post_status=draft' ) ),
- __( 'View all drafts' )
- );
- }
- echo '
' . __( 'Your Recent Drafts' ) . " \n
";
-
- /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
- $draft_length = intval( _x( '10', 'draft_length' ) );
-
- $drafts = array_slice( $drafts, 0, 3 );
- foreach ( $drafts as $draft ) {
- $url = get_edit_post_link( $draft->ID );
- $title = _draft_or_post_title( $draft->ID );
- echo "\n";
- printf(
- '',
- esc_url( $url ),
- /* translators: %s: Post title. */
- esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ),
- esc_html( $title ),
- get_the_time( 'c', $draft ),
- get_the_time( __( 'F j, Y' ), $draft )
- );
- $the_content = wp_trim_words( $draft->post_content, $draft_length );
- if ( $the_content ) {
- echo '' . $the_content . '
';
- }
- echo " \n";
- }
- echo " \n
";
-}
-
-/**
- * Outputs a row for the Recent Comments widget.
- *
- * @access private
- * @since 2.7.0
- *
- * @global WP_Comment $comment Global comment object.
- *
- * @param WP_Comment $comment The current comment.
- * @param bool $show_date Optional. Whether to display the date.
- */
-function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
- $GLOBALS['comment'] = clone $comment;
-
- if ( $comment->comment_post_ID > 0 ) {
-
- $comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
- $comment_post_url = get_the_permalink( $comment->comment_post_ID );
- $comment_post_link = "
$comment_post_title ";
- } else {
- $comment_post_link = '';
- }
-
- $actions_string = '';
- if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
- // Pre-order it: Approve | Reply | Edit | Spam | Trash.
- $actions = array(
- 'approve' => '',
- 'unapprove' => '',
- 'reply' => '',
- 'edit' => '',
- 'spam' => '',
- 'trash' => '',
- 'delete' => '',
- 'view' => '',
- );
-
- $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
- $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
-
- $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
- $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
- $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
- $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
- $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
-
- $actions['approve'] = sprintf(
- '
%s ',
- $approve_url,
- "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
- esc_attr__( 'Approve this comment' ),
- __( 'Approve' )
- );
-
- $actions['unapprove'] = sprintf(
- '
%s ',
- $unapprove_url,
- "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
- esc_attr__( 'Unapprove this comment' ),
- __( 'Unapprove' )
- );
-
- $actions['edit'] = sprintf(
- '
%s ',
- "comment.php?action=editcomment&c={$comment->comment_ID}",
- esc_attr__( 'Edit this comment' ),
- __( 'Edit' )
- );
-
- $actions['reply'] = sprintf(
- '
%s ',
- $comment->comment_ID,
- $comment->comment_post_ID,
- esc_attr__( 'Reply to this comment' ),
- __( 'Reply' )
- );
-
- $actions['spam'] = sprintf(
- '
%s ',
- $spam_url,
- "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
- esc_attr__( 'Mark this comment as spam' ),
- /* translators: "Mark as spam" link. */
- _x( 'Spam', 'verb' )
- );
-
- if ( ! EMPTY_TRASH_DAYS ) {
- $actions['delete'] = sprintf(
- '
%s ',
- $delete_url,
- "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
- esc_attr__( 'Delete this comment permanently' ),
- __( 'Delete Permanently' )
- );
- } else {
- $actions['trash'] = sprintf(
- '
%s ',
- $trash_url,
- "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
- esc_attr__( 'Move this comment to the Trash' ),
- _x( 'Trash', 'verb' )
- );
- }
-
- $actions['view'] = sprintf(
- '',
- esc_url( get_comment_link( $comment ) ),
- esc_attr__( 'View this comment' ),
- __( 'View' )
- );
-
- /**
- * Filters the action links displayed for each comment in the 'Recent Comments'
- * dashboard widget.
- *
- * @since 2.6.0
- *
- * @param string[] $actions An array of comment actions. Default actions include:
- * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
- * 'Delete', and 'Trash'.
- * @param WP_Comment $comment The comment object.
- */
- $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
-
- $i = 0;
- foreach ( $actions as $action => $link ) {
- ++$i;
- ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
-
- // Reply and quickedit need a hide-if-no-js span
- if ( 'reply' == $action || 'quickedit' == $action ) {
- $action .= ' hide-if-no-js';
- }
-
- if ( 'view' === $action && '1' !== $comment->comment_approved ) {
- $action .= ' hidden';
- }
- $actions_string .= "
$sep$link ";
- }
- }
- ?>
-
-