public function FeedsFetcherResult::sanitizeFile in Feeds 7.2
Sanitize the file in place.
Currently supported sanitizations:
- Remove BOM header from UTF-8 files.
Parameters
string $filepath: The file path of the file to be sanitized.
Return value
string The file path of the sanitized file.
Throws
RuntimeException Thrown if the file is not writeable.
3 calls to FeedsFetcherResult::sanitizeFile()
- FeedsFetcherResult::getFileContents in plugins/
FeedsFetcher.inc - Returns the contents of a file, if it exists.
- FeedsFetcherResult::getFilePath in plugins/
FeedsFetcher.inc - Get a path to a temporary file containing the resource provided by the fetcher.
- FeedsFileFetcherResult::getFilePath in plugins/
FeedsFileFetcher.inc - Overrides parent::getFilePath().
File
- plugins/
FeedsFetcher.inc, line 263 - Contains the FeedsFetcher and related classes.
Class
- FeedsFetcherResult
- Base class for all fetcher results.
Code
public function sanitizeFile($filepath) {
$handle = fopen($filepath, 'r');
$line = fgets($handle);
fclose($handle);
// If BOM header is present, read entire contents of file and overwrite the
// file with corrected contents.
if (substr($line, 0, 3) !== pack('CCC', 0xef, 0xbb, 0xbf)) {
return $filepath;
}
if (!is_writable($filepath)) {
throw new RuntimeException(t('File %filepath is not writable.', array(
'%filepath' => $filepath,
)));
}
$contents = file_get_contents($filepath);
$contents = substr($contents, 3);
$status = file_put_contents($filepath, $contents);
return $filepath;
}