first commit

This commit is contained in:
alazhar
2020-01-02 23:15:16 +07:00
commit eda9661806
3433 changed files with 595883 additions and 0 deletions

View File

@ -0,0 +1,72 @@
<?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');
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,290 @@
<?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&#8217; 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( $_GET['linkurl'] );
else
$link->link_url = '';
if ( isset( $_GET['name'] ) )
$link->link_name = esc_attr( $_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;
do_action( 'delete_link', $link_id );
wp_delete_object_term_relationships( $link_id, 'link_category' );
$wpdb->delete( $wpdb->links, array( 'link_id' => $link_id ) );
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( stripslashes_deep( $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 )
do_action( 'edit_link', $link_id );
else
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 = add_magic_quotes( $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&amp;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' );

View File

@ -0,0 +1,190 @@
<?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 License http://www.opensource.org/licenses/lgpl-license.html
*/
/**
* FTP implementation using fsockopen to connect.
*
* @package PemFTP
* @subpackage Pure
* @since 2.5
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
* @license LGPL License 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");
}
}
}
?>

View File

@ -0,0 +1,250 @@
<?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 License http://www.opensource.org/licenses/lgpl-license.html
*/
/**
* Socket Based FTP implementation
*
* @package PemFTP
* @subpackage Socket
* @since 2.5
*
* @version 1.0
* @copyright Alexey Dotsenko
* @author Alexey Dotsenko
* @link http://www.phpclasses.org/browse/package/1743.html Site
* @license LGPL License 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");
}
}
}
?>

View File

@ -0,0 +1,907 @@
<?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 License 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";
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,565 @@
<?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'] : '';
$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,
);
$_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' );
$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( stripslashes( $_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>';
}
$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( 'Show all comment types' ); ?></option>
<?php
$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
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 );
}
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() ); ?>" cellspacing="0">
<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 = join( ' ', get_comment_class( wp_get_comment_status( $comment->comment_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'>";
echo $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 );
$ptime = date( 'G', strtotime( $comment->comment_date ) );
if ( ( abs( time() - $ptime ) ) < DAY_IN_SECONDS )
$ptime = sprintf( __( '%s ago' ), human_time_diff( $ptime ) );
else
$ptime = mysql2date( __( 'Y/m/d \a\t g:i A' ), $comment->comment_date );
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="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' ) ),
/* translators: comment time format. See http://php.net/date */ 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 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&amp;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&amp;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&amp;c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
$actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick&nbsp;Edit' ) . '</a>';
$actions['reply'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\' );return false;" class="vim-r" title="'.esc_attr__( 'Reply to this comment' ).'" href="#">' . __( 'Reply' ) . '</a>';
}
$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 '&amp;mode=detail';
if ( 'spam' == $comment_status )
echo '&amp;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 .= get_the_title( $post->ID ) . '</a>';
} else {
$post_link = 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 ) {
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() ); ?>" cellspacing="0" 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;
}
}

View File

@ -0,0 +1,333 @@
<?php
/**
* Base WordPress Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* Base WordPress Filesystem class for which Filesystem implementations extend
*
* @since 2.5
*/
class WP_Filesystem_Base {
/**
* Whether to display debug data for the connection.
*
* @since 2.5
* @access public
* @var bool
*/
var $verbose = false;
/**
* Cached list of local filepaths to mapped remote filepaths.
*
* @since 2.7
* @access private
* @var array
*/
var $cache = array();
/**
* The Access method of the current connection, Set automatically.
*
* @since 2.5
* @access public
* @var string
*/
var $method = '';
/**
* Returns the path on the remote filesystem of ABSPATH
*
* @since 2.7
* @access public
* @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;
}
/**
* Returns the path on the remote filesystem of WP_CONTENT_DIR
*
* @since 2.7
* @access public
* @return string The location of the remote path.
*/
function wp_content_dir() {
return $this->find_folder(WP_CONTENT_DIR);
}
/**
* Returns the path on the remote filesystem of WP_PLUGIN_DIR
*
* @since 2.7
* @access public
*
* @return string The location of the remote path.
*/
function wp_plugins_dir() {
return $this->find_folder(WP_PLUGIN_DIR);
}
/**
* Returns the path on the remote filesystem of the Themes Directory
*
* @since 2.7
* @access public
*
* @return string The location of the remote path.
*/
function wp_themes_dir() {
return $this->wp_content_dir() . 'themes/';
}
/**
* Returns the path on the remote filesystem of WP_LANG_DIR
*
* @since 3.2.0
* @access public
*
* @return string The location of the remote path.
*/
function wp_lang_dir() {
return $this->find_folder(WP_LANG_DIR);
}
/**
* Locates a folder on the remote filesystem.
*
* Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
*
* @since 2.5
* @deprecated 2.7
* @access public
*
* @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 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();
}
/**
* Locates a folder on the remote filesystem.
*
* Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
*
* @since 2.5
* @deprecated 2.7
* @access public
*
* @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();
}
/**
* Locates a folder on the remote filesystem.
*
* Assumes that on Windows systems, Stripping off the Drive letter is OK
* Sanitizes \\ to / in windows filepaths.
*
* @since 2.7
* @access public
*
* @param string $folder the folder to locate
* @return string The location of the remote path.
*/
function find_folder($folder) {
if ( strpos($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 );
foreach ( $constant_overrides as $constant => $dir )
if ( defined($constant) && $folder === $dir )
return trailingslashit(constant($constant));
} 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;
}
/**
* Locates a folder on the remote filesystem.
*
* Expects Windows sanitized path
*
* @since 2.7
* @access private
*
* @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);
$folder_parts = explode('/', $folder);
$last_index = array_pop( array_keys( $folder_parts ) );
$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 its 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( __('Changing to %s') . '<br/>', $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( __('Found %s') . '<br/>', $base . $last_path );
return trailingslashit($base . $last_path);
}
if ( $loop )
return false; //Prevent this function from looping again.
//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/.... mainly dedicated setups.
return $this->search_for_folder($folder, '/', true);
}
/**
* Returns the *nix style file permissions for a file
*
* From the PHP documentation page for fileperms()
*
* @link http://docs.php.net/fileperms
* @since 2.5
* @access public
*
* @param string $file string filename
* @return int octal 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;
}
/**
* Converts *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
* @since 2.5
* @access public
*
* @param string $mode string *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;
}
/**
* Determines if the string provided contains binary characters.
*
* @since 2.7
* @access private
*
* @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)
}
}

View File

@ -0,0 +1,363 @@
<?php
/**
* WordPress Direct Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* WordPress Filesystem Class for direct PHP file and folder manipulation.
*
* @since 2.5
* @package WordPress
* @subpackage Filesystem
* @uses WP_Filesystem_Base Extends class
*/
class WP_Filesystem_Direct extends WP_Filesystem_Base {
var $errors = null;
/**
* constructor
*
* @param mixed $arg ignored argument
*/
function __construct($arg) {
$this->method = 'direct';
$this->errors = new WP_Error();
}
/**
* connect filesystem.
*
* @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct).
*/
function connect() {
return true;
}
/**
* 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 ) {
if ( ! ($fp = @fopen($file, 'w')) )
return false;
@fwrite($fp, $contents);
@fclose($fp);
$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 Username of the user.
*/
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 4 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 its a folder, and we're in recursive mode
$file = trailingslashit($file);
$filelist = $this->dirlist($file, true);
$retval = true;
if ( is_array($filelist) ) //false if no files, So check first.
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;
}
}

View File

@ -0,0 +1,393 @@
<?php
/**
* WordPress FTP Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* WordPress Filesystem Class for implementing FTP.
*
* @since 2.5
* @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;
}
// Set defaults:
//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, $type = '', $resumepos = 0 ) {
if ( empty($type) )
$type = FTP_BINARY;
$tempfile = wp_tempnam($file);
$temp = fopen($tempfile, 'w+');
if ( ! $temp )
return false;
if ( ! @ftp_fget($this->link, $temp, $file, $type, $resumepos) )
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, 'w+');
if ( ! $temp )
return false;
fwrite($temp, $contents);
fseek($temp, 0); //Skip back to the start of the file being written to
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
$ret = @ftp_fput($this->link, $file, $temp, $type);
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 chown($file, $owner, $recursive = false ) {
return false;
}
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) {
//Get dir list, Check if the file is readable by the current user??
return true;
}
function is_writable($file) {
//Get dir list, Check if the file is writable by the current user??
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);
}
}

View File

@ -0,0 +1,333 @@
<?php
/**
* WordPress FTP Sockets Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* WordPress Filesystem Class for implementing FTP Sockets.
*
* @since 2.5
* @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();
//Set defaults:
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_AUTOASCII);
$this->ftp->Passive(true);
$this->ftp->setTimeout(FS_TIMEOUT);
return true;
}
function get_contents($file, $type = '', $resumepos = 0) {
if ( ! $this->exists($file) )
return false;
if ( empty($type) )
$type = FTP_AUTOASCII;
$this->ftp->SetType($type);
$temp = wp_tempnam( $file );
if ( ! $temphandle = fopen($temp, 'w+') )
return false;
if ( ! $this->ftp->fget($temphandle, $file) ) {
fclose($temphandle);
unlink($temp);
return ''; //Blank document, File does exist, Its just blank.
}
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;
}
fwrite($temphandle, $contents);
fseek($temphandle, 0); //Skip back to the start of the file being written to
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
$this->ftp->SetType($type);
$ret = $this->ftp->fput($file, $temphandle);
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 chown($file, $owner, $recursive = false ) {
return false;
}
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) {
return $this->ftp->is_exists($file);
}
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) {
//Get dir list, Check if the file is writable by the current user??
return true;
}
function is_writable($file) {
//Get dir list, Check if the file is writable by the current user??
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;
}
$list = $this->ftp->dirlist($path);
if ( empty($list) && !$this->exists($path) )
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;
}
return $ret;
}
function __destruct() {
$this->ftp->quit();
}
}

View File

@ -0,0 +1,386 @@
<?php
/**
* WordPress SSH2 Filesystem.
*
* @package WordPress
* @subpackage Filesystem
*/
/**
* 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
* @package WordPress
* @subpackage Filesystem
* @uses WP_Filesystem_Base Extends class
*/
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, $type = '', $resumepos = 0 ) {
$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 ) {
$file = ltrim($file, '/');
$ret = file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
$this->chmod($file, $mode);
return false !== $ret;
}
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 %o %s', $mode, escapeshellarg($file)), true);
return $this->run_command(sprintf('chgrp -R %o %s', $mode, 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);
}
function chown($file, $owner, $recursive = false ) {
if ( ! $this->exists($file) )
return false;
if ( ! $recursive || ! $this->is_dir($file) )
return $this->run_command(sprintf('chown %o %s', $mode, escapeshellarg($file)), true);
return $this->run_command(sprintf('chown -R %o %s', $mode, 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;
}
}

View File

@ -0,0 +1,303 @@
<?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();
$args['reject_unsafe_urls'] = true;
if ( true === $head )
$args['method'] = 'HEAD';
if ( !empty( $username ) && !empty( $password ) )
$headers['Authorization'] = 'Basic ' . base64_encode( "$username:$password" );
$args['headers'] = $headers;
return wp_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;
}

View File

@ -0,0 +1,189 @@
<?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', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'orderby', 'order', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]', '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; ?>" valign="middle" <?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 &#8220;%s&#8221;' ), $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&amp;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:
?>
<td <?php echo $attributes ?>><?php do_action( 'manage_link_custom_column', $column_name, $link->link_id ); ?></td>
<?php
break;
}
}
?>
</tr>
<?php
}
}
}

View File

@ -0,0 +1,920 @@
<?php
/**
* Base class for displaying a list of items in an ajaxified HTML table.
*
* @package WordPress
* @subpackage List_Table
* @since 3.1.0
*/
/**
* 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 it's 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();
$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();
// This filter can currently only be used to remove 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 ) );
$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( 'Show 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;
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 ) ),
'&laquo;'
);
$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 ) ),
'&lsaquo;'
);
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 ) ),
'&rsaquo;'
);
$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 ) ),
'&raquo;'
);
$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 = apply_filters( "manage_{$this->screen->id}_sortable_columns", $this->get_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() ); ?>" cellspacing="0">
<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">
<?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 . '>';
echo $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 ) );
}
}

View File

@ -0,0 +1,429 @@
<?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'];
if ( !isset( $total_orphans ) )
$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' );
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' );
$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"><div title="' . esc_attr__( 'Comments' ) . '" class="comment-grey-bubble"></div></span>';
}
/* translators: column name */
$posts_columns['date'] = _x( 'Date', 'column name' );
$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, $id;
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 $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">
<?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 &#8220;%s&#8221;' ), $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 &#8220;%s&#8221;' ), $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 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 ) {
if ( get_post( $post->post_parent ) ) {
$title =_draft_or_post_title( $post->post_parent );
}
?>
<td <?php echo $attributes ?>><strong>
<?php if( current_user_can( 'edit_post', $post->post_parent ) ) { ?>
<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 '&#8212;';
}
echo '</td>';
break;
}
?>
<td <?php echo $attributes ?>>
<?php do_action( 'manage_media_custom_column', $column_name, $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&amp;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&amp;post=$post->ID", 'delete-post_' . $post->ID ) . "'>" . __( 'Delete Permanently' ) . "</a>";
}
$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $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&amp;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&amp;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&amp;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 &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
}
}
$actions = apply_filters( 'media_row_actions', $actions, $post, $this->detached );
return $actions;
}
}

View File

@ -0,0 +1,344 @@
<?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;
$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'] ) ? stripslashes( 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' );
$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 $current_site, $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( '.'.$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">
<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'] ) ?>" />
</th>
<?php
break;
case 'id':?>
<th valign="top" 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 &#8211; <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 ( $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&amp;action2=activateblog&amp;id=' . $blog['blog_id'] . '&amp;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&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] . '&amp;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&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] . '&amp;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&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] . '&amp;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&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] . '&amp;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&amp;action2=spamblog&amp;id=' . $blog['blog_id'] . '&amp;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&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] . '&amp;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>';
$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 valign='top' 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 valign='top' class='$column_name column-$column_name'$style>";
if ( $blog['registered'] == '0000-00-00 00:00:00' )
echo '&#x2014;';
else
echo mysql2date( $date, $blog['registered'] );
?>
</td>
<?php
break;
case 'users':
echo "<td valign='top' 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 valign='top' class='$column_name column-$column_name'$style>";
do_action( 'wpmublogsaction', $blog['blog_id'] ); ?>
</td>
<?php }
break;
default:
echo "<td class='$column_name column-$column_name'$style>";
do_action( 'manage_sites_custom_column', $column_name, $blog['blog_id'] );
echo "</td>";
break;
}
}
?>
</tr>
<?php
}
}
}

View File

@ -0,0 +1,356 @@
<?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(
'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 = stripslashes( $_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 $key => $theme )
$this->single_row( $key, $theme );
}
function single_row( $key, $theme ) {
global $status, $page, $s, $totals;
$context = $status;
if ( $this->is_site_themes ) {
$url = "site-themes.php?id={$this->site_id}&amp;";
$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&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;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&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;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&amp;checked[]=' . $theme_key . '&amp;theme_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>';
$actions = apply_filters( 'theme_action_links', array_filter( $actions ), $stylesheet, $theme, $context );
$actions = apply_filters( "theme_action_links_$stylesheet", $actions, $stylesheet, $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>';
$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>";
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' );
do_action( 'after_theme_row', $stylesheet, $theme, $status );
do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status );
}
}

View File

@ -0,0 +1,272 @@
<?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'] ) ? $_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' )
);
$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 $current_site, $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( stripslashes( $_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 stripslashes( $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( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
}
$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='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( '.' . $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>';
$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>";
echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
echo "</td>";
break;
}
endforeach
?>
</tr>
<?php
}
}
}

View File

@ -0,0 +1,238 @@
<?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.
$tabs = apply_filters( 'install_plugins_tabs', $tabs );
$nonmenu_tabs = apply_filters( 'install_plugins_nonmenu_tabs', $nonmenu_tabs );
// If a non-valid menu tab has been selected, And its 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'] ) ? stripslashes( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? stripslashes( $_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'] ) ? stripslashes( $_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;
}
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' => $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 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 ) . '&#8230;';
//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&amp;plugin=' . $plugin['slug'] .
'&amp;TB_iframe=true&amp;width=600&amp;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'] ) ) . '">' . sprintf( __( 'Update Now' ), $status['version'] ) . '</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;
}
}
$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']; ?>>
<div class="star-holder" title="<?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $plugin['num_ratings'] ), number_format_i18n( $plugin['num_ratings'] ) ) ?>">
<div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $plugin['rating'] ) ); ?>px"></div>
</div>
</td>
<td class="desc column-description"<?php echo $style['description']; ?>><?php echo $description, $author; ?></td>
</tr>
<?php
}
}
}

View File

@ -0,0 +1,437 @@
<?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', stripslashes($_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' ) );
$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->is_network && current_user_can('manage_network_plugins') ) ) {
if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
$plugins['mustuse'] = get_mu_plugins();
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->is_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->is_network && is_network_only_plugin( $plugin_file ) ) {
unset( $plugins['all'][ $plugin_file ] );
} elseif ( ! $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) {
unset( $plugins['all'][ $plugin_file ] );
} elseif ( ( ! $screen->is_network && is_plugin_active( $plugin_file ) )
|| ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
$plugins['active'][ $plugin_file ] = $plugin_data;
} else {
if ( ! $screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
$plugins['recently_activated'][ $plugin_file ] = $plugin_data;
$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 = stripslashes( $_REQUEST['s'] );
foreach ( $plugin as $value )
if ( stripos( $value, $term ) !== false )
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->is_network ? __( 'Network Activate' ) : __( 'Activate' );
if ( 'inactive' != $status && 'recent' != $status )
$actions['deactivate-selected'] = $this->screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' );
if ( !is_multisite() || $this->screen->is_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->is_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->is_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 ( 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->is_network )
$is_active = is_plugin_active_for_network( $plugin_file );
else
$is_active = is_plugin_active( $plugin_file );
if ( $screen->is_network ) {
if ( $is_active ) {
if ( current_user_can( 'manage_network_plugins' ) )
$actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;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&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;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&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;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&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;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&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;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&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins') . '" title="' . esc_attr__('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
} // end if $is_active
} // end if $screen->is_network
if ( ( ! is_multisite() || $screen->is_network ) && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
$actions['edit'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . esc_attr__('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
} // end if $context
$prefix = $screen->is_network ? 'network_admin_' : '';
$actions = apply_filters( $prefix . 'plugin_action_links', array_filter( $actions ), $plugin_file, $plugin_data, $context );
$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'] : '&nbsp;' ) . '</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>';
$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>";
do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data );
echo "</td>";
}
}
echo "</tr>";
do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status );
do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $status );
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,378 @@
<?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 ) {
$tags_per_page = apply_filters( 'edit_tags_per_page', $tags_per_page );
$tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter
} elseif ( 'category' == $this->screen->taxonomy ) {
$tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); // Old filter
}
$search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
$args = array(
'search' => $search,
'page' => $this->get_pagenum(),
'number' => $tags_per_page,
);
if ( !empty( $_REQUEST['orderby'] ) )
$args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) );
if ( !empty( $_REQUEST['order'] ) )
$args['order'] = trim( stripslashes( $_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
$out = '';
$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( $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
$out .= $this->_rows( $taxonomy, $terms, $children, $offset, $number, $count );
} else {
$terms = get_terms( $taxonomy, $args );
foreach ( $terms as $term )
$out .= $this->single_row( $term, 0, $taxonomy );
$count = $number; // Only displaying a single page.
}
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>';
} else {
echo $out;
}
}
function _rows( $taxonomy, $terms, &$children, $start = 0, $per_page = 20, &$count, $parent = 0, $level = 0 ) {
$end = $start + $per_page;
$output = '';
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 ) ) {
$output .= "\t" . $this->single_row( $my_parent, $level - $num_parents, $taxonomy );
$num_parents--;
}
}
if ( $count >= $start )
$output .= "\t" . $this->single_row( $term, $level, $taxonomy );
++$count;
unset( $terms[$key] );
if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
$output .= $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
}
return $output;
}
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 . '>';
echo $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 '&nbsp;';
}
function column_name( $tag ) {
$taxonomy = $this->screen->taxonomy;
$tax = get_taxonomy( $taxonomy );
$default_term = get_option( 'default_' . $taxonomy );
$pad = str_repeat( '&#8212; ', max( 0, $this->level ) );
$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 &#8220;%s&#8221;' ), $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&nbsp;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&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
$actions['view'] = '<a href="' . get_term_link( $tag ) . '">' . __( 'View' ) . '</a>';
$actions = apply_filters( 'tag_row_actions', $actions, $tag );
$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>';
$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 ) {
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 ) {
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;
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" title="<?php esc_attr_e( 'Cancel' ); ?>" class="cancel button-secondary alignleft"><?php _e( 'Cancel' ); ?></a>
<?php $update_text = $tax->labels->update_item; ?>
<a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></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
}
}

View File

@ -0,0 +1,394 @@
<?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( stripslashes( $_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.
$tabs = apply_filters( 'install_themes_tabs', $tabs );
$nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
// If a non-valid menu tab has been selected, And its 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'] ) ? stripslashes( $_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;
}
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' => $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 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' (length=14)
* public 'slug' => string 'magazine-basic' (length=14)
* public 'version' => string '1.1' (length=3)
* public 'author' => string 'tinkerpriest' (length=12)
* public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' (length=36)
* public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' (length=68)
* public 'rating' => float 80
* public 'num_ratings' => int 1
* public 'homepage' => string 'http://wordpress.org/extend/themes/magazine-basic' (length=49)
* 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>.' (length=214)
* public 'download_link' => string 'http://wordpress.org/extend/themes/download/magazine-basic.1.1.zip' (length=66)
*/
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 &#8220;%s&#8221;'), $name );
$preview_url = add_query_arg( array(
'tab' => 'theme-information',
'theme' => $theme->slug,
) );
$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>';
$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"><?php _e( '&larr; Close' ); ?></a>
</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 button-secondary" 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">
<div class="star-holder" title="<?php echo esc_attr( $num_ratings ); ?>">
<div class="star-rating" style="width:<?php echo esc_attr( intval( $theme->rating ) . 'px' ); ?>;"></div>
</div>
<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
* @access private
*
* @uses $tab Global; current tab within Themes->Install screen
* @uses $type Global; type of search.
*/
function _js_vars() {
global $tab, $type;
parent::_js_vars( compact( 'tab', 'type' ) );
}
/**
* Check to see if the theme is already installed.
*
* @since 3.4
* @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;
}
}

View File

@ -0,0 +1,253 @@
<?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( stripslashes( $_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() {
$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&amp;template=" . urlencode( $template ) . "&amp;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 &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
$actions['preview'] = '<a href="' . $preview_link . '" class="hide-if-customize" title="'
. esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $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&amp;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>';
$actions = apply_filters( 'theme_action_links', $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( $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
* @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( stripslashes( $_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();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,324 @@
<?php
/**
* Users List Table class.
*
* @package WordPress
* @subpackage List_Table
* @since 3.1.0
* @access private
*/
class WP_Users_List_Table extends WP_List_Table {
var $site_id;
var $is_site_users;
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;
}
function ajax_user_can() {
if ( $this->is_site_users )
return current_user_can( 'manage_sites' );
else
return current_user_can( 'list_users' );
}
function prepare_items() {
global $role, $usersearch;
$usersearch = isset( $_REQUEST['s'] ) ? 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,
) );
}
function no_items() {
_e( 'No matching users were found.' );
}
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;
}
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;
}
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&hellip;' ) ?></label>
<select name="new_role" id="new_role">
<option value=''><?php _e( 'Change role to&hellip;' ) ?></option>
<?php wp_dropdown_roles(); ?>
</select>
<?php
submit_button( __( 'Change' ), 'button', 'changeit', false );
endif;
do_action( 'restrict_manage_users' );
echo '</div>';
}
function current_action() {
if ( isset($_REQUEST['changeit']) && !empty($_REQUEST['new_role']) )
return 'promote';
return parent::current_action();
}
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;
}
function get_sortable_columns() {
$c = array(
'username' => 'login',
'name' => 'name',
'email' => 'email',
);
if ( $this->is_site_users )
unset( $c['posts'] );
return $c;
}
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 2.1.0
*
* @param object $user_object
* @param string $style Optional. Attributes added to the TR element. Must be sanitized.
* @param string $role Key for the $wp_roles array.
* @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
*/
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}&amp;";
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( stripslashes( $_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&amp;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&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
$actions = apply_filters( 'user_row_actions', $actions, $user_object );
$edit .= $this->row_actions( $actions );
// Set up the checkbox ( because the user is editable, otherwise its 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='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>";
$r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
$r .= "</td>";
}
}
$r .= '</tr>';
return $r;
}
}

View File

@ -0,0 +1,158 @@
<?php
/**
* WordPress Comment Administration API.
*
* @package WordPress
* @subpackage Administration
*/
/**
* {@internal Missing Short Description}}
*
* @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 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.' ) );
$_POST['comment_author'] = $_POST['newcomment_author'];
$_POST['comment_author_email'] = $_POST['newcomment_author_email'];
$_POST['comment_author_url'] = $_POST['newcomment_author_url'];
$_POST['comment_approved'] = $_POST['comment_status'];
$_POST['comment_content'] = $_POST['content'];
$_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 );
}
/**
* {@internal Missing Short Description}}
*
* @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 );
$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 );
return "$avatar $name";
}
function enqueue_comment_hotkeys_js() {
if ( 'true' == get_user_option( 'comment_shortcuts' ) )
wp_enqueue_script( 'jquery-table-hotkeys' );
}

View File

@ -0,0 +1,493 @@
<?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');

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,436 @@
<?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 );
do_action( 'export_wp' );
$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 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>
<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 get_the_author_meta( 'login' ); ?></dc:creator>
<guid isPermaLink="false"><?php esc_url( the_guid() ); ?></guid>
<description></description>
<content:encoded><?php echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); ?></content:encoded>
<excerpt:encoded><?php 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 ) :
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
}

1071
wp-admin/includes/file.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,728 @@
<?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 ( is_array($meta) && isset($meta['width']) )
$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 = !empty($backup_sizes) && isset($backup_sizes['full-orig'])
&& $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">
<?php echo $note; ?>
<table id="imgedit-panel-<?php echo $post_id; ?>"><tbody>
<tr><td>
<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 $meta['width']; ?>" />
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo $meta['height']; ?>" />
<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&amp;_ajax_nonce=<?php echo $nonce; ?>&amp;postid=<?php echo $post_id; ?>&amp;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-primary imgedit-submit-btn" value="<?php esc_attr_e( 'Save' ); ?>" />
</div>
</td>
<td class="imgedit-settings">
<div class="imgedit-group">
<div class="imgedit-group-top">
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php _e('Scale Image'); ?></strong></a>
<div class="imgedit-help">
<p><?php _e('You can proportionally scale the original image. For best results the scaling should be done before performing any other operations on it like crop, rotate, etc. Note that if you make the image larger it may become fuzzy.'); ?></p>
<p><?php printf( __('Original dimensions %s'), $meta['width'] . '&times;' . $meta['height'] ); ?></p>
<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 $meta['width']; ?>" />&times;<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 $meta['height']; ?>" />
<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-primary" value="<?php esc_attr_e( 'Scale' ); ?>" />
</div>
</div>
</div>
<?php if ( $can_restore ) { ?>
<div class="imgedit-group-top">
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><strong><?php _e('Restore Original Image'); ?></strong></a>
<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-primary" value="<?php esc_attr_e( 'Restore image' ); ?>" <?php echo $can_restore; ?> />
</div>
</div>
</div>
<?php } ?>
</div>
<div class="imgedit-group">
<div class="imgedit-group-top">
<strong><?php _e('Image Crop'); ?></strong>
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php _e('(help)'); ?></a>
<div class="imgedit-help">
<p><?php _e('The image can be cropped by clicking on it and dragging to select the desired part. While dragging the dimensions of the selection are displayed below.'); ?></p>
<p><strong><?php _e('Crop Aspect Ratio'); ?></strong><br />
<?php _e('You can specify the crop selection aspect ratio then hold down the Shift key while dragging to lock it. The values can be 1:1 (square), 4:3, 16:9, etc. If there is a selection, specifying aspect ratio will set it immediately.'); ?></p>
<p><strong><?php _e('Crop Selection'); ?></strong><br />
<?php _e('Once started, the selection can be adjusted by entering new values (in pixels). Note that these values are scaled to approximately match the original image dimensions. The minimum selection size equals 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">
<strong><?php _e('Thumbnail Settings'); ?></strong>
<a class="imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);return false;" href="#"><?php _e('(help)'); ?></a>
<p class="imgedit-help"><?php _e('The thumbnail image can be cropped differently. For example it can be square or contain only a portion of the original image to showcase it better. Here you can select whether to apply changes to all image sizes or make the thumbnail different.'); ?></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="" /><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 } ?>
</td></tr>
</tbody></table>
<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 ) {
$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' ) );
$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 ) {
$image = apply_filters('image_editor_save_pre', $image, $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' ) );
$image = apply_filters('image_save_pre', $image, $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':
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 )
$image = apply_filters('wp_image_editor_before_change', $image, $changes);
elseif ( is_resource( $image ) )
$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 );
@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( stripslashes($_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 = $w * $ratio;
$h2 = $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']) ) {
$delpath = apply_filters('wp_delete_file', $file);
@unlink($delpath);
}
} else {
$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']) ) {
$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 ) {
$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( stripslashes($_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];
}
$crop = $nocrop ? false : get_option("{$size}_crop");
$_sizes[ $size ] = array( 'width' => get_option("{$size}_size_w"), 'height' => get_option("{$size}_size_h"), '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 ) {
$delpath = apply_filters('wp_delete_file', $new_path);
@unlink( $delpath );
}
$return->msg = esc_js( __('Image saved') );
return $return;
}

412
wp-admin/includes/image.php Normal file
View File

@ -0,0 +1,412 @@
<?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|false New filepath on success, WP_Error or false 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 );
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();
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;
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'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
else
$sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
}
$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;
}
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] );
}
}
// fetch additional info from exif if available
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 ] );
}
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
* @uses apply_filters() Calls 'file_is_displayable_image' on $result and $path.
*
* @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;
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) ) {
$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 ) ) ) {
$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' ) ) {
$filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size );
}
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;
}

View File

@ -0,0 +1,185 @@
<?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, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
return $wp_importers;
}
/**
* 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.0/' );
$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() );
$popular_importers = maybe_unserialize( wp_remote_retrieve_body( wp_remote_get( $url, $options ) ) );
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 &amp; 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',
),
);
}

View File

@ -0,0 +1,113 @@
<?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;
}
}

2397
wp-admin/includes/media.php Normal file

File diff suppressed because it is too large Load Diff

229
wp-admin/includes/menu.php Normal file
View File

@ -0,0 +1,229 @@
<?php
/**
* Build Administration Menu.
*
* @package WordPress
* @subpackage Administration
*/
if ( is_network_admin() )
do_action('_network_admin_menu');
elseif ( is_user_admin() )
do_action('_user_admin_menu');
else
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 privs 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() )
do_action('network_admin_menu', '');
elseif ( is_user_admin() )
do_action('user_admin_menu', '');
else
do_action('admin_menu', '');
// Remove menus that have no accessible submenus and require privs 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') ) { // 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;
}
return apply_filters( 'add_menu_classes', $menu );
}
uksort($menu, "strnatcasecmp"); // make it all pretty
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;
$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() ) {
do_action('admin_page_access_denied');
wp_die( __('You do not have sufficient permissions to access this page.') );
}
$menu = add_menu_classes($menu);

View File

@ -0,0 +1,982 @@
<?php
// -- Post related Meta Boxes
/**
* Display post submit form fields.
*
* @since 2.7.0
*
* @param object $post
*/
function post_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="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 ) );
$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" 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"><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"><?php _e('Edit') ?></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"><?php _e('Cancel'); ?></a>
</div>
<?php } ?>
</div><!-- .misc-pub-section -->
<div class="misc-pub-section" 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"><?php _e('Edit'); ?></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); ?>" /><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"><?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 ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
<div class="misc-pub-section curtime">
<span id="timestamp">
<?php printf($stamp, $date); ?></span>
<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js"><?php _e('Edit') ?></a>
<div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'), 1); ?></div>
</div><?php // /misc-pub-section ?>
<?php endif; ?>
<?php do_action('post_submitbox_misc_actions'); ?>
</div>
<div class="clear"></div>
</div>
<div id="major-publishing-actions">
<?php 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">
<span id="timestamp"><?php printf($stamp, $date); ?></span>
</div><!-- .misc-pub-section -->
<?php 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"><?php _e('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 ); ?>"><?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);
$disabled = !current_user_can($taxonomy->cap->assign_terms) ? 'disabled="disabled"' : '';
$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 echo $disabled; ?>><?php echo str_replace( ',', $comma . ' ', get_terms_to_edit( $post->ID, $tax_name ) ); // textarea_escaped by esc_attr() ?></textarea></div>
<?php if ( current_user_can($taxonomy->cap->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 esc_attr( $taxonomy->labels->separate_items_with_commas ); ?></p>
<?php endif; ?>
</div>
<div class="tagchecklist"></div>
</div>
<?php if ( current_user_can($taxonomy->cap->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' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;' ) ); ?>
<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&#8217;ve linked to them. If you link other WordPress sites they&#8217;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(); ?>
</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 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 href="#commentstatusdiv" onclick="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) {
?>
<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();
}
// -- 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,
);
$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() ) ) {
$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">
<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 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&amp;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 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> &mdash; 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> &mdash; 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> &mdash; 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" cellspacing="0">
<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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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'); ?> />&nbsp;<?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" 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" 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>&nbsp;<?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 );
}

563
wp-admin/includes/misc.php Normal file
View File

@ -0,0 +1,563 @@
<?php
/**
* Misc WordPress Administration API.
*
* @package WordPress
* @subpackage Administration
*/
/**
* {@internal Missing Short Description}}
*
* @since 2.0.0
*
* @return unknown
*/
function got_mod_rewrite() {
$got_rewrite = apache_mod_loaded('mod_rewrite', true);
return apply_filters('got_rewrite', $got_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.1
*
* @param string $url
* @return string
*/
function url_shorten( $url ) {
$short_url = str_replace( 'http://', '', stripslashes( $url ));
$short_url = str_replace( 'www.', '', $short_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() )
$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 );
$functions = array();
$ignore_functions = array();
for ( $t = 0, $count = count( $tokens ); $t < $count; $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 );
$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
**/
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:
$value = apply_filters('set-screen-option', false, $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() {
global $_wp_admin_css_colors, $user_id; ?>
<fieldset><legend class="screen-reader-text"><span><?php _e('Admin Color Scheme')?></span></legend>
<?php
$current_color = get_user_option('admin_color', $user_id);
if ( empty($current_color) )
$current_color = 'fresh';
foreach ( $_wp_admin_css_colors as $color => $color_info ): ?>
<div class="color-option"><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); ?> />
<table class="color-palette">
<tr>
<?php foreach ( $color_info->colors as $html_color ): ?>
<td style="background-color: <?php echo esc_attr( $html_color ); ?>" title="<?php echo esc_attr( $color ); ?>">&nbsp;</td>
<?php endforeach; ?>
</tr>
</table>
<label for="admin_color_<?php echo esc_attr( $color ); ?>"><?php echo esc_html( $color_info->name ); ?></label>
</div>
<?php endforeach; ?>
</fieldset>
<?php
}
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');

View File

@ -0,0 +1,78 @@
<?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() {}

714
wp-admin/includes/ms.php Normal file
View File

@ -0,0 +1,714 @@
<?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, $current_site;
$switch = false;
if ( get_current_blog_id() != $blog_id ) {
$switch = true;
switch_to_blog( $blog_id );
}
$blog = get_blog_details( $blog_id );
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 );
// 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 ) {
$drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
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();
$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 );
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 );
// allow for commit transaction
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 );
$content = apply_filters( 'new_admin_email_content', __( "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### "), $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' ), 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&#8217;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 );
$content = apply_filters( 'new_user_email_content', __( "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###" ), $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' ), 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( $pref => $value ), array( 'ID' => $id ) );
$user = new WP_User( $id );
clean_user_cache( $user );
if ( $pref == 'spam' ) {
if ( $value == 1 )
do_action( 'make_spam_user', $id );
else
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' );
$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 valign='top'>";
$output .= "{$blog->blogname}";
$output .= "</td>";
$output .= "<td valign='top'>";
$output .= "<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>" ;
$output .= "</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' );
$output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
echo implode( "\n\t", $output );
}
/* Warn the admin if SECRET SALT information is missing from wp-config.php */
function secret_salt_warning() {
if ( !is_super_admin() )
return;
$secret_keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
$out = '';
foreach( $secret_keys as $key ) {
if ( ! defined( $key ) )
$out .= "define( '$key', '" . esc_html( wp_generate_password( 64, true, true ) ) . "' );<br />";
}
if ( $out != '' ) {
$msg = __( 'Warning! WordPress encrypts user cookies, but you must add the following lines to <strong>wp-config.php</strong> for it to be more secure.' );
$msg .= '<br/>' . __( "Before the line <code>/* That's all, stop editing! Happy blogging. */</code> please add this code:" );
$msg .= "<br/><br/><code>$out</code>";
echo "<div class='update-nag'>$msg</div>";
}
}
add_action( 'network_admin_notices', 'secret_salt_warning' );
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">Update 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">
<a href="<?php echo apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ); ?>"><?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
*/
function grant_super_admin( $user_id ) {
global $super_admins;
// If global super_admins override is defined, there is nothing to do here.
if ( isset($super_admins) )
return false;
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 );
do_action( 'granted_super_admin', $user_id );
return true;
}
return false;
}
/**
* Revokes super admin privileges.
*
* @since 3.0.0
* @param int $user_id
*/
function revoke_super_admin( $user_id ) {
global $super_admins;
// If global super_admins override is defined, there is nothing to do here.
if ( isset($super_admins) )
return false;
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 && $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 );
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;
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
}
/**
* Whether or not we have a large network.
*
* The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
* Plugins can alter this criteria using the 'wp_is_large_network' filter.
*
* @since 3.3.0
* @param string $using 'sites or 'users'. Default is 'sites'.
* @return bool True if the network meets the criteria for large. False otherwise.
*/
function wp_is_large_network( $using = 'sites' ) {
if ( 'users' == $using ) {
$count = get_user_count();
return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count );
}
$count = get_blog_count();
return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,406 @@
<?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;
// Allows a plugin to override the WordPress.org API entirely.
// Use the filter 'plugins_api_result' to merely add results.
// Please ensure that a object is returned from the following filters.
$args = apply_filters('plugins_api_args', $args, $action);
$res = apply_filters('plugins_api', false, $action, $args);
if ( false === $res ) {
$request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($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&#8217;s configuration. If you continue to have problems, please try the <a href="http://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&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
}
} elseif ( !is_wp_error($res) ) {
$res->external = true;
}
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="http://wordpress.org/extend/plugins/">WordPress Plugin Directory</a> or upload a plugin in .zip format via <a href="%s">this page</a>.' ), 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']) ? stripslashes( $_REQUEST['type'] ) : 'term';
$term = isset($_REQUEST['s']) ? stripslashes( $_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'] ) ? stripslashes( $_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_shift( $key = array_keys($installed_plugin) ); //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 .= '&amp;from=' . urlencode(stripslashes($_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' => stripslashes( $_REQUEST['plugin'] ) ));
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 );
}
$section = isset($_REQUEST['section']) ? stripslashes( $_REQUEST['section'] ) : 'description'; //Default to the Description tab, Do not translate, API returns English.
if ( empty($section) || ! isset($api->sections[ $section ]) )
$section = array_shift( $section_titles = array_keys((array)$api->sections) );
iframe_header( __('Plugin Install') );
echo "<div id='$tab-header'>\n";
echo "<ul id='sidemenu'>\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<li><a name='$san_section' href='$href' $class>$title</a></li>\n";
}
echo "</ul>\n";
echo "</div>\n";
?>
<div class="alignright fyi">
<?php if ( ! empty($api->download_link) && ( current_user_can('install_plugins') || current_user_can('update_plugins') ) ) : ?>
<p class="action-button">
<?php
$status = install_plugin_install_status($api);
switch ( $status['status'] ) {
case 'install':
if ( $status['url'] )
echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Now') . '</a>';
break;
case 'update_available':
if ( $status['url'] )
echo '<a href="' . $status['url'] . '" target="_parent">' . __('Install Update Now') .'</a>';
break;
case 'newer_installed':
echo '<a>' . sprintf(__('Newer Version (%s) Installed'), $status['version']) . '</a>';
break;
case 'latest_installed':
echo '<a>' . __('Latest Version Installed') . '</a>';
break;
}
?>
</p>
<?php endif; ?>
<h2 class="mainheader"><?php /* translators: For Your Information */ _e('FYI') ?></h2>
<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="http://wordpress.org/extend/plugins/<?php echo $api->slug ?>/"><?php _e('WordPress.org Plugin Page &#187;') ?></a></li>
<?php endif; if ( ! empty($api->homepage) ) : ?>
<li><a target="_blank" href="<?php echo $api->homepage ?>"><?php _e('Plugin Homepage &#187;') ?></a></li>
<?php endif; ?>
</ul>
<?php if ( ! empty($api->rating) ) : ?>
<h2><?php _e('Average Rating') ?></h2>
<div class="star-holder" title="<?php printf(_n('(based on %s rating)', '(based on %s ratings)', $api->num_ratings), number_format_i18n($api->num_ratings)); ?>">
<div class="star star-rating" style="width: <?php echo esc_attr( str_replace( ',', '.', $api->rating ) ); ?>px"></div>
</div>
<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, 'http://wordpress.org/extend/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 "\t\t<h2 class='long-header'>$title</h2>";
echo $content;
echo "\t</div>\n";
}
echo "</div>\n";
iframe_footer();
exit;
}
add_action('install_plugins_pre_plugin-information', 'install_plugin_information');

1763
wp-admin/includes/plugin.php Normal file

File diff suppressed because it is too large Load Diff

1320
wp-admin/includes/post.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,978 @@
<?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 enum('0','1') 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 (
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,
KEY activation_key (activation_key),
KEY domain (domain)
) $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, $current_site, $wp_current_db_version;
$guessurl = wp_guess_url();
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'),
'links_recently_updated_prepend' => '<em>',
'links_recently_updated_append' => '</em>',
'links_recently_updated_time' => 120,
'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'), $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' );
$existing_options = $wpdb->get_col("SELECT option_name FROM $wpdb->options");
$insert = '';
foreach ( $options as $option => $value ) {
if ( in_array($option, $existing_options) )
continue;
if ( in_array($option, $fat_options) )
$autoload = 'no';
else
$autoload = 'yes';
$option = $wpdb->escape($option);
if ( is_array($value) )
$value = serialize($value);
$value = $wpdb->escape($value);
if ( !empty($insert) )
$insert .= ', ';
$insert .= "('$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',
'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)?$'");
}
/**
* 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 ) );
}
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';
$insert = '';
foreach ( $sitemeta as $meta_key => $meta_value ) {
$meta_key = $wpdb->escape( $meta_key );
if ( is_array( $meta_value ) )
$meta_value = serialize( $meta_value );
$meta_value = $wpdb->escape( $meta_value );
if ( !empty( $insert ) )
$insert .= ', ';
$insert .= "( $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, '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 ) {
$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;
}

1075
wp-admin/includes/screen.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,252 @@
<?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_category( $id, OBJECT, 'edit' );
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_category($cat_ID, ARRAY_A);
// Escape data pulled from DB.
$category = add_magic_quotes($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 );
$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);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,192 @@
<?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( ) {
if ( !$cache = get_transient( 'wporg_theme_feature_list' ) )
set_transient( 'wporg_theme_feature_list', array( ), 10800);
if ( $cache )
return $cache;
$feature_list = themes_api( 'feature_list', array( ) );
if ( is_wp_error( $feature_list ) )
return $features;
set_transient( 'wporg_theme_feature_list', $feature_list, 10800 );
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'] ) ? stripslashes( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? stripslashes( $_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($page = 1) {
?>
<h4><?php _e('Install a theme in .zip format'); ?></h4>
<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, 1);
/**
* 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;
return $wp_list_table->single_row( $theme );
}
/**
* Display theme content based on theme list.
*
* @since 2.8.0
*/
function display_themes() {
global $wp_list_table;
$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 $tab, $themes_allowedtags, $wp_list_table;
$theme = themes_api( 'theme_information', array( 'slug' => stripslashes( $_REQUEST['theme'] ) ) );
if ( is_wp_error( $theme ) )
wp_die( $theme );
iframe_header( __('Theme Install') );
$wp_list_table->theme_installer_single( $theme );
iframe_footer();
exit;
}
add_action('install_themes_pre_theme-information', 'install_theme_information');

296
wp-admin/includes/theme.php Normal file
View File

@ -0,0 +1,296 @@
<?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($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
$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
*
* @return array Key is the template name, value is the filename of the template
*/
function get_page_templates() {
return array_flip( wp_get_theme()->get_page_templates() );
}
/**
* 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
*
* @param object $theme Theme data object.
* @return bool False if no valid info was passed.
*/
function theme_update_available( $theme ) {
static $themes_update;
if ( !current_user_can('update_themes' ) )
return;
if ( !isset($themes_update) )
$themes_update = get_site_transient('update_themes');
if ( ! is_a( $theme, 'WP_Theme' ) )
return;
$stylesheet = $theme->get_stylesheet();
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('update.php?action=upgrade-theme&amp;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') )
printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
else if ( empty($update['package']) )
printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
else
printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a> or <a href="%4$s" %5$s>update now</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
}
}
}
/**
* 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' ),
),
__( 'Columns' ) => array(
'one-column' => __( 'One Column' ),
'two-columns' => __( 'Two Columns' ),
'three-columns' => __( 'Three Columns' ),
'four-columns' => __( 'Four Columns' ),
'left-sidebar' => __( 'Left Sidebar' ),
'right-sidebar' => __( 'Right Sidebar' ),
),
__( 'Width' ) => array(
'fixed-width' => __( 'Fixed Width' ),
'flexible-width' => __( 'Flexible Width' ),
),
__( 'Features' ) => array(
'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'), 'Columns' => __('Columns'), 'Width' => __('Width'),
'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
* @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;
$args = apply_filters('themes_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter.
$res = apply_filters('themes_api', false, $action, $args); //NOTE: Allows a theme to completely override the builtin WordPress.org API.
if ( ! $res ) {
$request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($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&#8217;s configuration. If you continue to have problems, please try the <a href="http://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&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
}
}
return apply_filters('themes_api_result', $res, $action, $args);
}

View File

@ -0,0 +1,881 @@
<?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.css',
'wp-admin/css/dashboard-rtl.dev.css',
'wp-admin/css/dashboard.css',
'wp-admin/css/dashboard.dev.css',
'wp-admin/css/farbtastic-rtl.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.css',
'wp-admin/css/install-rtl.dev.css',
'wp-admin/css/login-rtl.css',
'wp-admin/css/login-rtl.dev.css',
'wp-admin/css/login.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.css',
'wp-admin/css/press-this-rtl.dev.css',
'wp-admin/css/press-this.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.css',
'wp-admin/css/widgets-rtl.dev.css',
'wp-admin/css/widgets.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/options-privacy.php',
// 3.5.2
'wp-includes/js/swfupload/swfupload-all.js',
);
/**
* 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',
);
/**
* 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 );
// Sanity check the unzipped distribution
apply_filters( 'update_feedback', __('Verifying the unpacked files&#8230;') );
$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', __('Could not copy file.') );
}
$wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE );
require_once( 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 ) );
apply_filters('update_feedback', __('Installing the latest version&#8230;'));
// 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);
// Copy new versions of WP files into place.
$result = _copy_dir($from . $distro, $to, array('wp-content') );
// 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);
}
}
// 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' ) ) {
// Bumping the introduced version to 3.5.1 for the affected users causes Twenty Twelve to be installed for the first time
if ( $wp_filesystem->delete( $wp_filesystem->wp_themes_dir() . 'twentytwelve/' ) )
$_new_bundled_files[ 'themes/twentytwelve/' ] = '3.5.1';
}
}
// 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', __('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 ( is_wp_error($_result) ) //If a error occurs partway through this final step, keep the error flowing through, but keep process going.
$result = $_result;
}
}
} //end foreach
}
// Handle $result error from the above blocks
if ( is_wp_error($result) ) {
$wp_filesystem->delete($maintenance_file);
$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;
$wp_filesystem->delete($old_file, true);
}
// Upgrade DB with separate request
apply_filters('update_feedback', __('Upgrading database&#8230;'));
$db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
wp_remote_post($db_upgrade_url, array('timeout' => 60));
// 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');
// Remove maintenance file, we're done.
$wp_filesystem->delete($maintenance_file);
// If we made it this far:
do_action( '_core_updated_successfully', $wp_version );
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 only and will be removed in 3.3
*
* @ignore
* @since 3.2.0
* @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);
$skip_regex = '';
foreach ( (array)$skip_list as $key => $skip_file )
$skip_regex .= preg_quote($skip_file, '!') . '|';
if ( !empty($skip_regex) )
$skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
foreach ( (array) $dirlist as $filename => $fileinfo ) {
if ( !empty($skip_regex) )
if ( preg_match($skip_regex, $from . $filename) )
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, 0644);
if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
return new WP_Error('copy_failed', __('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', __('Could not create directory.'), $to . $filename);
}
$result = _copy_dir($from . $filename, $to . $filename, $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. wp_update_core() could be called 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' );

View File

@ -0,0 +1,310 @@
<?php
/**
* WordPress Administration Update API
*
* @package WordPress
* @subpackage Administration
*/
// The admin side of our 1.1 update system
/**
* Selects the first update version from the update_core option
*
* @return object the response from the API
*/
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 array Array of the update objects
*/
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 ( empty($from_api) )
return false;
if ( !isset( $from_api->updates ) || !is_array( $from_api->updates ) ) return false;
$updates = $from_api->updates;
if ( !is_array( $updates ) ) return false;
$result = array();
foreach($updates as $update) {
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;
}
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 ( !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' ) );
} 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 );
}
echo "<div class='update-nag'>$msg</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() {
$msg = sprintf( __( 'You are using <span class="b">WordPress %s</span>.' ), get_bloginfo( 'version', 'display' ) );
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 "<span id='wp-version-message'>$msg</span>";
}
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 . '&section=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) );
do_action( "in_plugin_update_message-$file", $plugin_data, $r );
echo '</div></td></tr>';
}
}
function wp_update_plugin($plugin, $feedback = '') {
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);
}
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_update_theme($theme, $feedback = '') {
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);
}
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) );
do_action( "in_theme_update_message-$theme_key", $theme, $r );
echo '</div></td></tr>';
}
function wp_update_core($current, $feedback = '') {
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);
}
function maintenance_nag() {
global $upgrading;
if ( ! isset( $upgrading ) )
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' );

File diff suppressed because it is too large Load Diff

369
wp-admin/includes/user.php Normal file
View File

@ -0,0 +1,369 @@
<?php
/**
* WordPress user administration API.
*
* @package WordPress
* @subpackage Administration
*/
/**
* Creates a new user from the "Users" form using $_POST information.
*
* @since 2.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
*
* @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 = $wpdb->escape( $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&#8217;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_contactmethods( $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 */
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( stripslashes($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&#8217;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' ) );
}
// Allow plugins to return their own errors.
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']) ? $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
*
* @return unknown
*/
function get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->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 object WP_User object with user data.
*/
function get_user_to_edit( $user_id ) {
$user = get_userdata( $user_id );
$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);
$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 = 'novalue' ) {
global $wpdb;
$id = (int) $id;
$user = new WP_User( $id );
// allow for transaction statement
do_action('delete_user', $id);
if ( 'novalue' === $reassign || 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;
}
}
$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 {
$reassign = (int) $reassign;
$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 );
// allow for commit transaction
do_action('deleted_user', $id);
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', $user_ID);
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&rsquo;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( get_current_user_id() ) . '#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>';
}

View File

@ -0,0 +1,228 @@
<?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 the admin widget config screen.
*
* @since 2.5.0
*
* @param string $sidebar id slug of the sidebar
*/
function wp_list_widget_controls( $sidebar ) {
add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
echo "<div id='$sidebar' class='widgets-sortables'>\n";
$description = wp_sidebar_description( $sidebar );
if ( !empty( $description ) ) {
echo "<div class='sidebar-description'>\n";
echo "\t<p class='description'>$description</p>";
echo "</div>\n";
}
dynamic_sidebar( $sidebar );
echo "</div>\n";
}
/**
* {@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;
}