Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres...
File: class-wp-import.php
[1000] Fix | Delete
/**
[1001] Fix | Delete
* If fetching attachments is enabled then attempt to create a new attachment
[1002] Fix | Delete
*
[1003] Fix | Delete
* @param array $post Attachment post details from WXR
[1004] Fix | Delete
* @param string $url URL to fetch attachment from
[1005] Fix | Delete
* @return int|WP_Error Post ID on success, WP_Error otherwise
[1006] Fix | Delete
*/
[1007] Fix | Delete
function process_attachment( $post, $url ) {
[1008] Fix | Delete
if ( ! $this->fetch_attachments ) {
[1009] Fix | Delete
return new WP_Error(
[1010] Fix | Delete
'attachment_processing_error',
[1011] Fix | Delete
__( 'Fetching attachments is not enabled', 'wordpress-importer' )
[1012] Fix | Delete
);
[1013] Fix | Delete
}
[1014] Fix | Delete
[1015] Fix | Delete
// if the URL is absolute, but does not contain address, then upload it assuming base_site_url
[1016] Fix | Delete
if ( preg_match( '|^/[\w\W]+$|', $url ) ) {
[1017] Fix | Delete
$url = rtrim( $this->base_url, '/' ) . $url;
[1018] Fix | Delete
}
[1019] Fix | Delete
[1020] Fix | Delete
$upload = $this->fetch_remote_file( $url, $post );
[1021] Fix | Delete
if ( is_wp_error( $upload ) ) {
[1022] Fix | Delete
return $upload;
[1023] Fix | Delete
}
[1024] Fix | Delete
[1025] Fix | Delete
$info = wp_check_filetype( $upload['file'] );
[1026] Fix | Delete
if ( $info ) {
[1027] Fix | Delete
$post['post_mime_type'] = $info['type'];
[1028] Fix | Delete
} else {
[1029] Fix | Delete
return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'wordpress-importer' ) );
[1030] Fix | Delete
}
[1031] Fix | Delete
[1032] Fix | Delete
$post['guid'] = $upload['url'];
[1033] Fix | Delete
[1034] Fix | Delete
// as per wp-admin/includes/upload.php
[1035] Fix | Delete
$post_id = wp_insert_attachment( $post, $upload['file'] );
[1036] Fix | Delete
wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
[1037] Fix | Delete
[1038] Fix | Delete
// remap resized image URLs, works by stripping the extension and remapping the URL stub.
[1039] Fix | Delete
if ( preg_match( '!^image/!', $info['type'] ) ) {
[1040] Fix | Delete
$parts = pathinfo( $url );
[1041] Fix | Delete
$name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
[1042] Fix | Delete
[1043] Fix | Delete
$parts_new = pathinfo( $upload['url'] );
[1044] Fix | Delete
$name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
[1045] Fix | Delete
[1046] Fix | Delete
$this->url_remap[ $parts['dirname'] . '/' . $name ] = $parts_new['dirname'] . '/' . $name_new;
[1047] Fix | Delete
}
[1048] Fix | Delete
[1049] Fix | Delete
return $post_id;
[1050] Fix | Delete
}
[1051] Fix | Delete
[1052] Fix | Delete
/**
[1053] Fix | Delete
* Attempt to download a remote file attachment
[1054] Fix | Delete
*
[1055] Fix | Delete
* @param string $url URL of item to fetch
[1056] Fix | Delete
* @param array $post Attachment details
[1057] Fix | Delete
* @return array|WP_Error Local file location details on success, WP_Error otherwise
[1058] Fix | Delete
*/
[1059] Fix | Delete
function fetch_remote_file( $url, $post ) {
[1060] Fix | Delete
// Extract the file name from the URL.
[1061] Fix | Delete
$path = parse_url( $url, PHP_URL_PATH );
[1062] Fix | Delete
$file_name = '';
[1063] Fix | Delete
if ( is_string( $path ) ) {
[1064] Fix | Delete
$file_name = basename( $path );
[1065] Fix | Delete
}
[1066] Fix | Delete
[1067] Fix | Delete
if ( ! $file_name ) {
[1068] Fix | Delete
$file_name = md5( $url );
[1069] Fix | Delete
}
[1070] Fix | Delete
[1071] Fix | Delete
$tmp_file_name = wp_tempnam( $file_name );
[1072] Fix | Delete
if ( ! $tmp_file_name ) {
[1073] Fix | Delete
return new WP_Error( 'import_no_file', __( 'Could not create temporary file.', 'wordpress-importer' ) );
[1074] Fix | Delete
}
[1075] Fix | Delete
[1076] Fix | Delete
// Fetch the remote URL and write it to the placeholder file.
[1077] Fix | Delete
$remote_response = wp_safe_remote_get(
[1078] Fix | Delete
$url,
[1079] Fix | Delete
array(
[1080] Fix | Delete
'timeout' => 300,
[1081] Fix | Delete
'stream' => true,
[1082] Fix | Delete
'filename' => $tmp_file_name,
[1083] Fix | Delete
'headers' => array(
[1084] Fix | Delete
'Accept-Encoding' => 'identity',
[1085] Fix | Delete
),
[1086] Fix | Delete
)
[1087] Fix | Delete
);
[1088] Fix | Delete
[1089] Fix | Delete
if ( is_wp_error( $remote_response ) ) {
[1090] Fix | Delete
@unlink( $tmp_file_name );
[1091] Fix | Delete
return new WP_Error(
[1092] Fix | Delete
'import_file_error',
[1093] Fix | Delete
sprintf(
[1094] Fix | Delete
/* translators: 1: The WordPress error message. 2: The WordPress error code. */
[1095] Fix | Delete
__( 'Request failed due to an error: %1$s (%2$s)', 'wordpress-importer' ),
[1096] Fix | Delete
esc_html( $remote_response->get_error_message() ),
[1097] Fix | Delete
esc_html( $remote_response->get_error_code() )
[1098] Fix | Delete
)
[1099] Fix | Delete
);
[1100] Fix | Delete
}
[1101] Fix | Delete
[1102] Fix | Delete
$remote_response_code = (int) wp_remote_retrieve_response_code( $remote_response );
[1103] Fix | Delete
[1104] Fix | Delete
// Make sure the fetch was successful.
[1105] Fix | Delete
if ( 200 !== $remote_response_code ) {
[1106] Fix | Delete
@unlink( $tmp_file_name );
[1107] Fix | Delete
return new WP_Error(
[1108] Fix | Delete
'import_file_error',
[1109] Fix | Delete
sprintf(
[1110] Fix | Delete
/* translators: 1: The HTTP error message. 2: The HTTP error code. */
[1111] Fix | Delete
__( 'Remote server returned the following unexpected result: %1$s (%2$s)', 'wordpress-importer' ),
[1112] Fix | Delete
get_status_header_desc( $remote_response_code ),
[1113] Fix | Delete
esc_html( $remote_response_code )
[1114] Fix | Delete
)
[1115] Fix | Delete
);
[1116] Fix | Delete
}
[1117] Fix | Delete
[1118] Fix | Delete
$headers = wp_remote_retrieve_headers( $remote_response );
[1119] Fix | Delete
[1120] Fix | Delete
// Request failed.
[1121] Fix | Delete
if ( ! $headers ) {
[1122] Fix | Delete
@unlink( $tmp_file_name );
[1123] Fix | Delete
return new WP_Error( 'import_file_error', __( 'Remote server did not respond', 'wordpress-importer' ) );
[1124] Fix | Delete
}
[1125] Fix | Delete
[1126] Fix | Delete
$filesize = (int) filesize( $tmp_file_name );
[1127] Fix | Delete
[1128] Fix | Delete
if ( 0 === $filesize ) {
[1129] Fix | Delete
@unlink( $tmp_file_name );
[1130] Fix | Delete
return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'wordpress-importer' ) );
[1131] Fix | Delete
}
[1132] Fix | Delete
[1133] Fix | Delete
if ( ! isset( $headers['content-encoding'] ) && isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) {
[1134] Fix | Delete
@unlink( $tmp_file_name );
[1135] Fix | Delete
return new WP_Error( 'import_file_error', __( 'Downloaded file has incorrect size', 'wordpress-importer' ) );
[1136] Fix | Delete
}
[1137] Fix | Delete
[1138] Fix | Delete
$max_size = (int) $this->max_attachment_size();
[1139] Fix | Delete
if ( ! empty( $max_size ) && $filesize > $max_size ) {
[1140] Fix | Delete
@unlink( $tmp_file_name );
[1141] Fix | Delete
return new WP_Error( 'import_file_error', sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) ) );
[1142] Fix | Delete
}
[1143] Fix | Delete
[1144] Fix | Delete
// Override file name with Content-Disposition header value.
[1145] Fix | Delete
if ( ! empty( $headers['content-disposition'] ) ) {
[1146] Fix | Delete
$file_name_from_disposition = self::get_filename_from_disposition( (array) $headers['content-disposition'] );
[1147] Fix | Delete
if ( $file_name_from_disposition ) {
[1148] Fix | Delete
$file_name = $file_name_from_disposition;
[1149] Fix | Delete
}
[1150] Fix | Delete
}
[1151] Fix | Delete
[1152] Fix | Delete
// Set file extension if missing.
[1153] Fix | Delete
$file_ext = pathinfo( $file_name, PATHINFO_EXTENSION );
[1154] Fix | Delete
if ( ! $file_ext && ! empty( $headers['content-type'] ) ) {
[1155] Fix | Delete
$extension = self::get_file_extension_by_mime_type( $headers['content-type'] );
[1156] Fix | Delete
if ( $extension ) {
[1157] Fix | Delete
$file_name = "{$file_name}.{$extension}";
[1158] Fix | Delete
}
[1159] Fix | Delete
}
[1160] Fix | Delete
[1161] Fix | Delete
// Handle the upload like _wp_handle_upload() does.
[1162] Fix | Delete
$wp_filetype = wp_check_filetype_and_ext( $tmp_file_name, $file_name );
[1163] Fix | Delete
$ext = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext'];
[1164] Fix | Delete
$type = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type'];
[1165] Fix | Delete
$proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename'];
[1166] Fix | Delete
[1167] Fix | Delete
// Check to see if wp_check_filetype_and_ext() determined the filename was incorrect.
[1168] Fix | Delete
if ( $proper_filename ) {
[1169] Fix | Delete
$file_name = $proper_filename;
[1170] Fix | Delete
}
[1171] Fix | Delete
[1172] Fix | Delete
if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) {
[1173] Fix | Delete
return new WP_Error( 'import_file_error', __( 'Sorry, this file type is not permitted for security reasons.', 'wordpress-importer' ) );
[1174] Fix | Delete
}
[1175] Fix | Delete
[1176] Fix | Delete
$uploads = wp_upload_dir( $post['upload_date'] );
[1177] Fix | Delete
if ( ! ( $uploads && false === $uploads['error'] ) ) {
[1178] Fix | Delete
return new WP_Error( 'upload_dir_error', $uploads['error'] );
[1179] Fix | Delete
}
[1180] Fix | Delete
[1181] Fix | Delete
// Move the file to the uploads dir.
[1182] Fix | Delete
$file_name = wp_unique_filename( $uploads['path'], $file_name );
[1183] Fix | Delete
$new_file = $uploads['path'] . "/$file_name";
[1184] Fix | Delete
$move_new_file = copy( $tmp_file_name, $new_file );
[1185] Fix | Delete
[1186] Fix | Delete
if ( ! $move_new_file ) {
[1187] Fix | Delete
@unlink( $tmp_file_name );
[1188] Fix | Delete
return new WP_Error( 'import_file_error', __( 'The uploaded file could not be moved', 'wordpress-importer' ) );
[1189] Fix | Delete
}
[1190] Fix | Delete
[1191] Fix | Delete
// Set correct file permissions.
[1192] Fix | Delete
$stat = stat( dirname( $new_file ) );
[1193] Fix | Delete
$perms = $stat['mode'] & 0000666;
[1194] Fix | Delete
chmod( $new_file, $perms );
[1195] Fix | Delete
[1196] Fix | Delete
$upload = array(
[1197] Fix | Delete
'file' => $new_file,
[1198] Fix | Delete
'url' => $uploads['url'] . "/$file_name",
[1199] Fix | Delete
'type' => $wp_filetype['type'],
[1200] Fix | Delete
'error' => false,
[1201] Fix | Delete
);
[1202] Fix | Delete
[1203] Fix | Delete
// keep track of the old and new urls so we can substitute them later
[1204] Fix | Delete
$this->url_remap[ $url ] = $upload['url'];
[1205] Fix | Delete
$this->url_remap[ $post['guid'] ] = $upload['url']; // r13735, really needed?
[1206] Fix | Delete
// keep track of the destination if the remote url is redirected somewhere else
[1207] Fix | Delete
if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] != $url ) {
[1208] Fix | Delete
$this->url_remap[ $headers['x-final-location'] ] = $upload['url'];
[1209] Fix | Delete
}
[1210] Fix | Delete
[1211] Fix | Delete
return $upload;
[1212] Fix | Delete
}
[1213] Fix | Delete
[1214] Fix | Delete
/**
[1215] Fix | Delete
* Attempt to associate posts and menu items with previously missing parents
[1216] Fix | Delete
*
[1217] Fix | Delete
* An imported post's parent may not have been imported when it was first created
[1218] Fix | Delete
* so try again. Similarly for child menu items and menu items which were missing
[1219] Fix | Delete
* the object (e.g. post) they represent in the menu
[1220] Fix | Delete
*/
[1221] Fix | Delete
function backfill_parents() {
[1222] Fix | Delete
global $wpdb;
[1223] Fix | Delete
[1224] Fix | Delete
// find parents for post orphans
[1225] Fix | Delete
foreach ( $this->post_orphans as $child_id => $parent_id ) {
[1226] Fix | Delete
$local_child_id = false;
[1227] Fix | Delete
$local_parent_id = false;
[1228] Fix | Delete
if ( isset( $this->processed_posts[ $child_id ] ) ) {
[1229] Fix | Delete
$local_child_id = $this->processed_posts[ $child_id ];
[1230] Fix | Delete
}
[1231] Fix | Delete
if ( isset( $this->processed_posts[ $parent_id ] ) ) {
[1232] Fix | Delete
$local_parent_id = $this->processed_posts[ $parent_id ];
[1233] Fix | Delete
}
[1234] Fix | Delete
[1235] Fix | Delete
if ( $local_child_id && $local_parent_id ) {
[1236] Fix | Delete
$wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
[1237] Fix | Delete
clean_post_cache( $local_child_id );
[1238] Fix | Delete
}
[1239] Fix | Delete
}
[1240] Fix | Delete
[1241] Fix | Delete
// all other posts/terms are imported, retry menu items with missing associated object
[1242] Fix | Delete
$missing_menu_items = $this->missing_menu_items;
[1243] Fix | Delete
foreach ( $missing_menu_items as $item ) {
[1244] Fix | Delete
$this->process_menu_item( $item );
[1245] Fix | Delete
}
[1246] Fix | Delete
[1247] Fix | Delete
// find parents for menu item orphans
[1248] Fix | Delete
foreach ( $this->menu_item_orphans as $child_id => $parent_id ) {
[1249] Fix | Delete
$local_child_id = 0;
[1250] Fix | Delete
$local_parent_id = 0;
[1251] Fix | Delete
if ( isset( $this->processed_menu_items[ $child_id ] ) ) {
[1252] Fix | Delete
$local_child_id = $this->processed_menu_items[ $child_id ];
[1253] Fix | Delete
}
[1254] Fix | Delete
if ( isset( $this->processed_menu_items[ $parent_id ] ) ) {
[1255] Fix | Delete
$local_parent_id = $this->processed_menu_items[ $parent_id ];
[1256] Fix | Delete
}
[1257] Fix | Delete
[1258] Fix | Delete
if ( $local_child_id && $local_parent_id ) {
[1259] Fix | Delete
update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id );
[1260] Fix | Delete
}
[1261] Fix | Delete
}
[1262] Fix | Delete
}
[1263] Fix | Delete
[1264] Fix | Delete
/**
[1265] Fix | Delete
* Use stored mapping information to update old attachment URLs
[1266] Fix | Delete
*/
[1267] Fix | Delete
function backfill_attachment_urls() {
[1268] Fix | Delete
global $wpdb;
[1269] Fix | Delete
// make sure we do the longest urls first, in case one is a substring of another
[1270] Fix | Delete
uksort( $this->url_remap, array( &$this, 'cmpr_strlen' ) );
[1271] Fix | Delete
[1272] Fix | Delete
foreach ( $this->url_remap as $from_url => $to_url ) {
[1273] Fix | Delete
// remap urls in post_content
[1274] Fix | Delete
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url ) );
[1275] Fix | Delete
// remap enclosure urls
[1276] Fix | Delete
$result = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url ) );
[1277] Fix | Delete
}
[1278] Fix | Delete
}
[1279] Fix | Delete
[1280] Fix | Delete
/**
[1281] Fix | Delete
* Update _thumbnail_id meta to new, imported attachment IDs
[1282] Fix | Delete
*/
[1283] Fix | Delete
function remap_featured_images() {
[1284] Fix | Delete
// cycle through posts that have a featured image
[1285] Fix | Delete
foreach ( $this->featured_images as $post_id => $value ) {
[1286] Fix | Delete
if ( isset( $this->processed_posts[ $value ] ) ) {
[1287] Fix | Delete
$new_id = $this->processed_posts[ $value ];
[1288] Fix | Delete
// only update if there's a difference
[1289] Fix | Delete
if ( $new_id != $value ) {
[1290] Fix | Delete
update_post_meta( $post_id, '_thumbnail_id', $new_id );
[1291] Fix | Delete
}
[1292] Fix | Delete
}
[1293] Fix | Delete
}
[1294] Fix | Delete
}
[1295] Fix | Delete
[1296] Fix | Delete
/**
[1297] Fix | Delete
* Parse a WXR file
[1298] Fix | Delete
*
[1299] Fix | Delete
* @param string $file Path to WXR file for parsing
[1300] Fix | Delete
* @return array Information gathered from the WXR file
[1301] Fix | Delete
*/
[1302] Fix | Delete
function parse( $file ) {
[1303] Fix | Delete
$parser = new WXR_Parser();
[1304] Fix | Delete
return $parser->parse( $file );
[1305] Fix | Delete
}
[1306] Fix | Delete
[1307] Fix | Delete
// Display import page title
[1308] Fix | Delete
function header() {
[1309] Fix | Delete
echo '<div class="wrap">';
[1310] Fix | Delete
echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>';
[1311] Fix | Delete
[1312] Fix | Delete
$updates = get_plugin_updates();
[1313] Fix | Delete
$basename = plugin_basename( __FILE__ );
[1314] Fix | Delete
if ( isset( $updates[ $basename ] ) ) {
[1315] Fix | Delete
$update = $updates[ $basename ];
[1316] Fix | Delete
echo '<div class="error"><p><strong>';
[1317] Fix | Delete
printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'wordpress-importer' ), $update->update->new_version );
[1318] Fix | Delete
echo '</strong></p></div>';
[1319] Fix | Delete
}
[1320] Fix | Delete
}
[1321] Fix | Delete
[1322] Fix | Delete
// Close div.wrap
[1323] Fix | Delete
function footer() {
[1324] Fix | Delete
echo '</div>';
[1325] Fix | Delete
}
[1326] Fix | Delete
[1327] Fix | Delete
/**
[1328] Fix | Delete
* Display introductory text and file upload form
[1329] Fix | Delete
*/
[1330] Fix | Delete
function greet() {
[1331] Fix | Delete
echo '<div class="narrow">';
[1332] Fix | Delete
echo '<p>' . __( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ) . '</p>';
[1333] Fix | Delete
echo '<p>' . __( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ) . '</p>';
[1334] Fix | Delete
wp_import_upload_form( 'admin.php?import=wordpress&amp;step=1' );
[1335] Fix | Delete
echo '</div>';
[1336] Fix | Delete
}
[1337] Fix | Delete
[1338] Fix | Delete
/**
[1339] Fix | Delete
* Decide if the given meta key maps to information we will want to import
[1340] Fix | Delete
*
[1341] Fix | Delete
* @param string $key The meta key to check
[1342] Fix | Delete
* @return string|bool The key if we do want to import, false if not
[1343] Fix | Delete
*/
[1344] Fix | Delete
function is_valid_meta_key( $key ) {
[1345] Fix | Delete
// skip attachment metadata since we'll regenerate it from scratch
[1346] Fix | Delete
// skip _edit_lock as not relevant for import
[1347] Fix | Delete
if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ), true ) ) {
[1348] Fix | Delete
return false;
[1349] Fix | Delete
}
[1350] Fix | Delete
return $key;
[1351] Fix | Delete
}
[1352] Fix | Delete
[1353] Fix | Delete
/**
[1354] Fix | Delete
* Decide whether or not the importer is allowed to create users.
[1355] Fix | Delete
* Default is true, can be filtered via import_allow_create_users
[1356] Fix | Delete
*
[1357] Fix | Delete
* @return bool True if creating users is allowed
[1358] Fix | Delete
*/
[1359] Fix | Delete
function allow_create_users() {
[1360] Fix | Delete
return apply_filters( 'import_allow_create_users', true );
[1361] Fix | Delete
}
[1362] Fix | Delete
[1363] Fix | Delete
/**
[1364] Fix | Delete
* Decide whether or not the importer should attempt to download attachment files.
[1365] Fix | Delete
* Default is true, can be filtered via import_allow_fetch_attachments. The choice
[1366] Fix | Delete
* made at the import options screen must also be true, false here hides that checkbox.
[1367] Fix | Delete
*
[1368] Fix | Delete
* @return bool True if downloading attachments is allowed
[1369] Fix | Delete
*/
[1370] Fix | Delete
function allow_fetch_attachments() {
[1371] Fix | Delete
return apply_filters( 'import_allow_fetch_attachments', true );
[1372] Fix | Delete
}
[1373] Fix | Delete
[1374] Fix | Delete
/**
[1375] Fix | Delete
* Decide what the maximum file size for downloaded attachments is.
[1376] Fix | Delete
* Default is 0 (unlimited), can be filtered via import_attachment_size_limit
[1377] Fix | Delete
*
[1378] Fix | Delete
* @return int Maximum attachment file size to import
[1379] Fix | Delete
*/
[1380] Fix | Delete
function max_attachment_size() {
[1381] Fix | Delete
return apply_filters( 'import_attachment_size_limit', 0 );
[1382] Fix | Delete
}
[1383] Fix | Delete
[1384] Fix | Delete
/**
[1385] Fix | Delete
* Added to http_request_timeout filter to force timeout at 60 seconds during import
[1386] Fix | Delete
* @return int 60
[1387] Fix | Delete
*/
[1388] Fix | Delete
function bump_request_timeout( $val ) {
[1389] Fix | Delete
return 60;
[1390] Fix | Delete
}
[1391] Fix | Delete
[1392] Fix | Delete
// return the difference in length between two strings
[1393] Fix | Delete
function cmpr_strlen( $a, $b ) {
[1394] Fix | Delete
return strlen( $b ) - strlen( $a );
[1395] Fix | Delete
}
[1396] Fix | Delete
[1397] Fix | Delete
/**
[1398] Fix | Delete
* Parses filename from a Content-Disposition header value.
[1399] Fix | Delete
*
[1400] Fix | Delete
* As per RFC6266:
[1401] Fix | Delete
*
[1402] Fix | Delete
* content-disposition = "Content-Disposition" ":"
[1403] Fix | Delete
* disposition-type *( ";" disposition-parm )
[1404] Fix | Delete
*
[1405] Fix | Delete
* disposition-type = "inline" | "attachment" | disp-ext-type
[1406] Fix | Delete
* ; case-insensitive
[1407] Fix | Delete
* disp-ext-type = token
[1408] Fix | Delete
*
[1409] Fix | Delete
* disposition-parm = filename-parm | disp-ext-parm
[1410] Fix | Delete
*
[1411] Fix | Delete
* filename-parm = "filename" "=" value
[1412] Fix | Delete
* | "filename*" "=" ext-value
[1413] Fix | Delete
*
[1414] Fix | Delete
* disp-ext-parm = token "=" value
[1415] Fix | Delete
* | ext-token "=" ext-value
[1416] Fix | Delete
* ext-token = <the characters in token, followed by "*">
[1417] Fix | Delete
*
[1418] Fix | Delete
* @since 0.7.0
[1419] Fix | Delete
*
[1420] Fix | Delete
* @see WP_REST_Attachments_Controller::get_filename_from_disposition()
[1421] Fix | Delete
*
[1422] Fix | Delete
* @link http://tools.ietf.org/html/rfc2388
[1423] Fix | Delete
* @link http://tools.ietf.org/html/rfc6266
[1424] Fix | Delete
*
[1425] Fix | Delete
* @param string[] $disposition_header List of Content-Disposition header values.
[1426] Fix | Delete
* @return string|null Filename if available, or null if not found.
[1427] Fix | Delete
*/
[1428] Fix | Delete
protected static function get_filename_from_disposition( $disposition_header ) {
[1429] Fix | Delete
// Get the filename.
[1430] Fix | Delete
$filename = null;
[1431] Fix | Delete
[1432] Fix | Delete
foreach ( $disposition_header as $value ) {
[1433] Fix | Delete
$value = trim( $value );
[1434] Fix | Delete
[1435] Fix | Delete
if ( strpos( $value, ';' ) === false ) {
[1436] Fix | Delete
continue;
[1437] Fix | Delete
}
[1438] Fix | Delete
[1439] Fix | Delete
list( $type, $attr_parts ) = explode( ';', $value, 2 );
[1440] Fix | Delete
[1441] Fix | Delete
$attr_parts = explode( ';', $attr_parts );
[1442] Fix | Delete
$attributes = array();
[1443] Fix | Delete
[1444] Fix | Delete
foreach ( $attr_parts as $part ) {
[1445] Fix | Delete
if ( strpos( $part, '=' ) === false ) {
[1446] Fix | Delete
continue;
[1447] Fix | Delete
}
[1448] Fix | Delete
[1449] Fix | Delete
list( $key, $value ) = explode( '=', $part, 2 );
[1450] Fix | Delete
[1451] Fix | Delete
$attributes[ trim( $key ) ] = trim( $value );
[1452] Fix | Delete
}
[1453] Fix | Delete
[1454] Fix | Delete
if ( empty( $attributes['filename'] ) ) {
[1455] Fix | Delete
continue;
[1456] Fix | Delete
}
[1457] Fix | Delete
[1458] Fix | Delete
$filename = trim( $attributes['filename'] );
[1459] Fix | Delete
[1460] Fix | Delete
// Unquote quoted filename, but after trimming.
[1461] Fix | Delete
if ( substr( $filename, 0, 1 ) === '"' && substr( $filename, -1, 1 ) === '"' ) {
[1462] Fix | Delete
$filename = substr( $filename, 1, -1 );
[1463] Fix | Delete
}
[1464] Fix | Delete
}
[1465] Fix | Delete
[1466] Fix | Delete
return $filename;
[1467] Fix | Delete
}
[1468] Fix | Delete
[1469] Fix | Delete
/**
[1470] Fix | Delete
* Retrieves file extension by mime type.
[1471] Fix | Delete
*
[1472] Fix | Delete
* @since 0.7.0
[1473] Fix | Delete
*
[1474] Fix | Delete
* @param string $mime_type Mime type to search extension for.
[1475] Fix | Delete
* @return string|null File extension if available, or null if not found.
[1476] Fix | Delete
*/
[1477] Fix | Delete
protected static function get_file_extension_by_mime_type( $mime_type ) {
[1478] Fix | Delete
static $map = null;
[1479] Fix | Delete
[1480] Fix | Delete
if ( is_array( $map ) ) {
[1481] Fix | Delete
return isset( $map[ $mime_type ] ) ? $map[ $mime_type ] : null;
[1482] Fix | Delete
}
[1483] Fix | Delete
[1484] Fix | Delete
$mime_types = wp_get_mime_types();
[1485] Fix | Delete
$map = array_flip( $mime_types );
[1486] Fix | Delete
[1487] Fix | Delete
// Some types have multiple extensions, use only the first one.
[1488] Fix | Delete
foreach ( $map as $type => $extensions ) {
[1489] Fix | Delete
$map[ $type ] = strtok( $extensions, '|' );
[1490] Fix | Delete
}
[1491] Fix | Delete
[1492] Fix | Delete
return isset( $map[ $mime_type ] ) ? $map[ $mime_type ] : null;
[1493] Fix | Delete
}
[1494] Fix | Delete
}
[1495] Fix | Delete
[1496] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function