-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wxr-parser-large-file. #140
Draft
vishnugopal
wants to merge
3
commits into
master
Choose a base branch
from
add/large-file-parser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"plugins": ["."], | ||
"config": { | ||
"WP_UPLOAD_MAX_FILESIZE": "128M", | ||
"WP_MEMORY_LIMIT": "256M" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* XML_Character_Filter file. | ||
* | ||
* @package WordPress | ||
* @subpackage Importer | ||
*/ | ||
|
||
// String which will be prefixed to stream URLs to add this filter. | ||
define( 'XML_CHARACTER_FILTER_PREFIX', 'php://filter/read=xml_character_filter/resource=' ); | ||
|
||
/** | ||
* Class XML_Character_Filter. | ||
* | ||
* XML Character Stream Filter to sanitize XML input. Removes control characters except newline, tab and return. | ||
* | ||
* Usage: php://filter/read=xml_character_filter/resource=zip://archive.zip#import.xml; | ||
*/ | ||
class XML_Character_Filter extends php_user_filter { | ||
/** | ||
* List of control characters to remove. | ||
* | ||
* @var array | ||
*/ | ||
private $chars = array(); | ||
|
||
/** | ||
* This method is called whenever data is read from or written to the attached stream (such as with fread() or fwrite()). | ||
* | ||
* @param resource $in A resource pointing to a bucket brigade which contains one or more bucket objects containing data to be filtered. | ||
* @param resource $out A resource pointing to a second bucket brigade into which the modified buckets should be placed. | ||
* @param int $consumed Reference to the length of the data that the filter reads in and alters. | ||
* @param bool $closing Whether the stream is in the process of closing. | ||
* @return int PSFS_PASS_ON|PSFS_FEED_ME|PSFS_ERR_FATAL. | ||
*/ | ||
public function filter( $in, $out, &$consumed, $closing ) { | ||
while ( $bucket = stream_bucket_make_writeable( $in ) ) { //phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition | ||
$consumed += $bucket->datalen; | ||
$bucket->data = $this->replace_chars( $bucket->data ); | ||
stream_bucket_append( $out, $bucket ); | ||
} | ||
|
||
return PSFS_PASS_ON; | ||
} | ||
|
||
/** | ||
* This method is called during instantiation of the filter class object. | ||
* | ||
* @return bool | ||
*/ | ||
public function onCreate() { | ||
for ( $ascii_num = 0; $ascii_num < 32; $ascii_num++ ) { | ||
if ( 9 !== $ascii_num && 10 !== $ascii_num && 13 !== $ascii_num ) { | ||
$this->chars[] = chr( $ascii_num ); | ||
} | ||
} | ||
$this->chars[] = chr( 127 ); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Replace control characters. | ||
* | ||
* @param string $string Data to replace. | ||
* @return string | ||
*/ | ||
private function replace_chars( $string ) { | ||
return str_replace( $this->chars, ' ', $string ); | ||
} | ||
} | ||
stream_filter_register( 'xml_character_filter', 'XML_Character_Filter' ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't want to include this file :-)