Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/litespee.../lib/css_js_m.../minify
File: minify.cls.php
<?php
[0] Fix | Delete
// phpcs:ignoreFile
[1] Fix | Delete
/**
[2] Fix | Delete
* modified PHP implementation of Matthias Mullie's Abstract minifier class.
[3] Fix | Delete
*
[4] Fix | Delete
* @author Matthias Mullie <minify@mullie.eu>
[5] Fix | Delete
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
[6] Fix | Delete
* @license MIT License
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
namespace LiteSpeed\Lib\CSS_JS_MIN\Minify;
[10] Fix | Delete
[11] Fix | Delete
use LiteSpeed\Lib\CSS_JS_MIN\Minify\Exception\IOException;
[12] Fix | Delete
[13] Fix | Delete
defined( 'WPINC' ) || exit;
[14] Fix | Delete
[15] Fix | Delete
abstract class Minify {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* The data to be minified.
[19] Fix | Delete
*
[20] Fix | Delete
* @var string[]
[21] Fix | Delete
*/
[22] Fix | Delete
protected $data = array();
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Array of patterns to match.
[26] Fix | Delete
*
[27] Fix | Delete
* @var string[]
[28] Fix | Delete
*/
[29] Fix | Delete
protected $patterns = array();
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* This array will hold content of strings and regular expressions that have
[33] Fix | Delete
* been extracted from the JS source code, so we can reliably match "code",
[34] Fix | Delete
* without having to worry about potential "code-like" characters inside.
[35] Fix | Delete
*
[36] Fix | Delete
* @internal
[37] Fix | Delete
*
[38] Fix | Delete
* @var string[]
[39] Fix | Delete
*/
[40] Fix | Delete
public $extracted = array();
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Init the minify class - optionally, code may be passed along already.
[44] Fix | Delete
*/
[45] Fix | Delete
public function __construct( /* $data = null, ... */ ) {
[46] Fix | Delete
// it's possible to add the source through the constructor as well ;)
[47] Fix | Delete
if ( func_num_args() ) {
[48] Fix | Delete
call_user_func_array( array( $this, 'add' ), func_get_args() );
[49] Fix | Delete
}
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Add a file or straight-up code to be minified.
[54] Fix | Delete
*
[55] Fix | Delete
* @param string|string[] $data
[56] Fix | Delete
*
[57] Fix | Delete
* @return static
[58] Fix | Delete
*/
[59] Fix | Delete
public function add( $data /* $data = null, ... */ ) {
[60] Fix | Delete
// bogus "usage" of parameter $data: scrutinizer warns this variable is
[61] Fix | Delete
// not used (we're using func_get_args instead to support overloading),
[62] Fix | Delete
// but it still needs to be defined because it makes no sense to have
[63] Fix | Delete
// this function without argument :)
[64] Fix | Delete
$args = array( $data ) + func_get_args();
[65] Fix | Delete
[66] Fix | Delete
// this method can be overloaded
[67] Fix | Delete
foreach ( $args as $data ) {
[68] Fix | Delete
if ( is_array( $data ) ) {
[69] Fix | Delete
call_user_func_array( array( $this, 'add' ), $data );
[70] Fix | Delete
continue;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
// redefine var
[74] Fix | Delete
$data = (string) $data;
[75] Fix | Delete
[76] Fix | Delete
// load data
[77] Fix | Delete
$value = $this->load( $data );
[78] Fix | Delete
$key = ( $data != $value ) ? $data : count( $this->data );
[79] Fix | Delete
[80] Fix | Delete
// replace CR linefeeds etc.
[81] Fix | Delete
// @see https://github.com/matthiasmullie/minify/pull/139
[82] Fix | Delete
$value = str_replace( array( "\r\n", "\r" ), "\n", $value );
[83] Fix | Delete
[84] Fix | Delete
// store data
[85] Fix | Delete
$this->data[ $key ] = $value;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
return $this;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Add a file to be minified.
[93] Fix | Delete
*
[94] Fix | Delete
* @param string|string[] $data
[95] Fix | Delete
*
[96] Fix | Delete
* @return static
[97] Fix | Delete
*
[98] Fix | Delete
* @throws IOException
[99] Fix | Delete
*/
[100] Fix | Delete
public function addFile( $data /* $data = null, ... */ ) {
[101] Fix | Delete
// bogus "usage" of parameter $data: scrutinizer warns this variable is
[102] Fix | Delete
// not used (we're using func_get_args instead to support overloading),
[103] Fix | Delete
// but it still needs to be defined because it makes no sense to have
[104] Fix | Delete
// this function without argument :)
[105] Fix | Delete
$args = array( $data ) + func_get_args();
[106] Fix | Delete
[107] Fix | Delete
// this method can be overloaded
[108] Fix | Delete
foreach ( $args as $path ) {
[109] Fix | Delete
if ( is_array( $path ) ) {
[110] Fix | Delete
call_user_func_array( array( $this, 'addFile' ), $path );
[111] Fix | Delete
continue;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
// redefine var
[115] Fix | Delete
$path = (string) $path;
[116] Fix | Delete
[117] Fix | Delete
// check if we can read the file
[118] Fix | Delete
if ( ! $this->canImportFile( $path ) ) {
[119] Fix | Delete
throw new IOException( 'The file "' . $path . '" could not be opened for reading. Check if PHP has enough permissions.' );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
$this->add( $path );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
return $this;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Minify the data & (optionally) saves it to a file.
[130] Fix | Delete
*
[131] Fix | Delete
* @param string[optional] $path Path to write the data to
[132] Fix | Delete
*
[133] Fix | Delete
* @return string The minified data
[134] Fix | Delete
*/
[135] Fix | Delete
public function minify( $path = null ) {
[136] Fix | Delete
$content = $this->execute( $path );
[137] Fix | Delete
[138] Fix | Delete
// save to path
[139] Fix | Delete
if ( $path !== null ) {
[140] Fix | Delete
$this->save( $content, $path );
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
return $content;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Minify & gzip the data & (optionally) saves it to a file.
[148] Fix | Delete
*
[149] Fix | Delete
* @param string[optional] $path Path to write the data to
[150] Fix | Delete
* @param int[optional] $level Compression level, from 0 to 9
[151] Fix | Delete
*
[152] Fix | Delete
* @return string The minified & gzipped data
[153] Fix | Delete
*/
[154] Fix | Delete
public function gzip( $path = null, $level = 9 ) {
[155] Fix | Delete
$content = $this->execute( $path );
[156] Fix | Delete
$content = gzencode( $content, $level, FORCE_GZIP );
[157] Fix | Delete
[158] Fix | Delete
// save to path
[159] Fix | Delete
if ( $path !== null ) {
[160] Fix | Delete
$this->save( $content, $path );
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
return $content;
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Minify the data.
[169] Fix | Delete
*
[170] Fix | Delete
* @param string[optional] $path Path to write the data to
[171] Fix | Delete
*
[172] Fix | Delete
* @return string The minified data
[173] Fix | Delete
*/
[174] Fix | Delete
abstract public function execute( $path = null );
[175] Fix | Delete
[176] Fix | Delete
/**
[177] Fix | Delete
* Load data.
[178] Fix | Delete
*
[179] Fix | Delete
* @param string $data Either a path to a file or the content itself
[180] Fix | Delete
*
[181] Fix | Delete
* @return string
[182] Fix | Delete
*/
[183] Fix | Delete
protected function load( $data ) {
[184] Fix | Delete
// check if the data is a file
[185] Fix | Delete
if ( $this->canImportFile( $data ) ) {
[186] Fix | Delete
$data = file_get_contents( $data );
[187] Fix | Delete
[188] Fix | Delete
// strip BOM, if any
[189] Fix | Delete
if ( substr( $data, 0, 3 ) == "\xef\xbb\xbf" ) {
[190] Fix | Delete
$data = substr( $data, 3 );
[191] Fix | Delete
}
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
return $data;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Save to file.
[199] Fix | Delete
*
[200] Fix | Delete
* @param string $content The minified data
[201] Fix | Delete
* @param string $path The path to save the minified data to
[202] Fix | Delete
*
[203] Fix | Delete
* @throws IOException
[204] Fix | Delete
*/
[205] Fix | Delete
protected function save( $content, $path ) {
[206] Fix | Delete
$handler = $this->openFileForWriting( $path );
[207] Fix | Delete
[208] Fix | Delete
$this->writeToFile( $handler, $content );
[209] Fix | Delete
[210] Fix | Delete
@fclose( $handler );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
/**
[214] Fix | Delete
* Register a pattern to execute against the source content.
[215] Fix | Delete
*
[216] Fix | Delete
* If $replacement is a string, it must be plain text. Placeholders like $1 or \2 don't work.
[217] Fix | Delete
* If you need that functionality, use a callback instead.
[218] Fix | Delete
*
[219] Fix | Delete
* @param string $pattern PCRE pattern
[220] Fix | Delete
* @param string|callable $replacement Replacement value for matched pattern
[221] Fix | Delete
*/
[222] Fix | Delete
protected function registerPattern( $pattern, $replacement = '' ) {
[223] Fix | Delete
// study the pattern, we'll execute it more than once
[224] Fix | Delete
$pattern .= 'S';
[225] Fix | Delete
[226] Fix | Delete
$this->patterns[] = array( $pattern, $replacement );
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Both JS and CSS use the same form of multi-line comment, so putting the common code here.
[231] Fix | Delete
*/
[232] Fix | Delete
protected function stripMultilineComments() {
[233] Fix | Delete
// First extract comments we want to keep, so they can be restored later
[234] Fix | Delete
// PHP only supports $this inside anonymous functions since 5.4
[235] Fix | Delete
$minifier = $this;
[236] Fix | Delete
$callback = function ( $match ) use ( $minifier ) {
[237] Fix | Delete
$count = count( $minifier->extracted );
[238] Fix | Delete
$placeholder = '/*' . $count . '*/';
[239] Fix | Delete
$minifier->extracted[ $placeholder ] = $match[0];
[240] Fix | Delete
[241] Fix | Delete
return $placeholder;
[242] Fix | Delete
};
[243] Fix | Delete
$this->registerPattern(
[244] Fix | Delete
'/
[245] Fix | Delete
# optional newline
[246] Fix | Delete
\n?
[247] Fix | Delete
[248] Fix | Delete
# start comment
[249] Fix | Delete
\/\*
[250] Fix | Delete
[251] Fix | Delete
# comment content
[252] Fix | Delete
(?:
[253] Fix | Delete
# either starts with an !
[254] Fix | Delete
!
[255] Fix | Delete
|
[256] Fix | Delete
# or, after some number of characters which do not end the comment
[257] Fix | Delete
(?:(?!\*\/).)*?
[258] Fix | Delete
[259] Fix | Delete
# there is either a @license or @preserve tag
[260] Fix | Delete
@(?:license|preserve)
[261] Fix | Delete
)
[262] Fix | Delete
[263] Fix | Delete
# then match to the end of the comment
[264] Fix | Delete
.*?\*\/\n?
[265] Fix | Delete
[266] Fix | Delete
/ixs',
[267] Fix | Delete
$callback
[268] Fix | Delete
);
[269] Fix | Delete
[270] Fix | Delete
// Then strip all other comments
[271] Fix | Delete
$this->registerPattern( '/\/\*.*?\*\//s', '' );
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
/**
[275] Fix | Delete
* We can't "just" run some regular expressions against JavaScript: it's a
[276] Fix | Delete
* complex language. E.g. having an occurrence of // xyz would be a comment,
[277] Fix | Delete
* unless it's used within a string. Of you could have something that looks
[278] Fix | Delete
* like a 'string', but inside a comment.
[279] Fix | Delete
* The only way to accurately replace these pieces is to traverse the JS one
[280] Fix | Delete
* character at a time and try to find whatever starts first.
[281] Fix | Delete
*
[282] Fix | Delete
* @param string $content The content to replace patterns in
[283] Fix | Delete
*
[284] Fix | Delete
* @return string The (manipulated) content
[285] Fix | Delete
*/
[286] Fix | Delete
protected function replace( $content ) {
[287] Fix | Delete
$contentLength = strlen( $content );
[288] Fix | Delete
$output = '';
[289] Fix | Delete
$processedOffset = 0;
[290] Fix | Delete
$positions = array_fill( 0, count( $this->patterns ), -1 );
[291] Fix | Delete
$matches = array();
[292] Fix | Delete
[293] Fix | Delete
while ( $processedOffset < $contentLength ) {
[294] Fix | Delete
// find first match for all patterns
[295] Fix | Delete
foreach ( $this->patterns as $i => $pattern ) {
[296] Fix | Delete
list($pattern, $replacement) = $pattern;
[297] Fix | Delete
[298] Fix | Delete
// we can safely ignore patterns for positions we've unset earlier,
[299] Fix | Delete
// because we know these won't show up anymore
[300] Fix | Delete
if ( array_key_exists( $i, $positions ) == false ) {
[301] Fix | Delete
continue;
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
// no need to re-run matches that are still in the part of the
[305] Fix | Delete
// content that hasn't been processed
[306] Fix | Delete
if ( $positions[ $i ] >= $processedOffset ) {
[307] Fix | Delete
continue;
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
$match = null;
[311] Fix | Delete
if ( preg_match( $pattern, $content, $match, PREG_OFFSET_CAPTURE, $processedOffset ) ) {
[312] Fix | Delete
$matches[ $i ] = $match;
[313] Fix | Delete
[314] Fix | Delete
// we'll store the match position as well; that way, we
[315] Fix | Delete
// don't have to redo all preg_matches after changing only
[316] Fix | Delete
// the first (we'll still know where those others are)
[317] Fix | Delete
$positions[ $i ] = $match[0][1];
[318] Fix | Delete
} else {
[319] Fix | Delete
// if the pattern couldn't be matched, there's no point in
[320] Fix | Delete
// executing it again in later runs on this same content;
[321] Fix | Delete
// ignore this one until we reach end of content
[322] Fix | Delete
unset( $matches[ $i ], $positions[ $i ] );
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
// no more matches to find: everything's been processed, break out
[327] Fix | Delete
if ( ! $matches ) {
[328] Fix | Delete
// output the remaining content
[329] Fix | Delete
$output .= substr( $content, $processedOffset );
[330] Fix | Delete
break;
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
// see which of the patterns actually found the first thing (we'll
[334] Fix | Delete
// only want to execute that one, since we're unsure if what the
[335] Fix | Delete
// other found was not inside what the first found)
[336] Fix | Delete
$matchOffset = min( $positions );
[337] Fix | Delete
$firstPattern = array_search( $matchOffset, $positions );
[338] Fix | Delete
$match = $matches[ $firstPattern ];
[339] Fix | Delete
[340] Fix | Delete
// execute the pattern that matches earliest in the content string
[341] Fix | Delete
list(, $replacement) = $this->patterns[ $firstPattern ];
[342] Fix | Delete
[343] Fix | Delete
// add the part of the input between $processedOffset and the first match;
[344] Fix | Delete
// that content wasn't matched by anything
[345] Fix | Delete
$output .= substr( $content, $processedOffset, $matchOffset - $processedOffset );
[346] Fix | Delete
// add the replacement for the match
[347] Fix | Delete
$output .= $this->executeReplacement( $replacement, $match );
[348] Fix | Delete
// advance $processedOffset past the match
[349] Fix | Delete
$processedOffset = $matchOffset + strlen( $match[0][0] );
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
return $output;
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
/**
[356] Fix | Delete
* If $replacement is a callback, execute it, passing in the match data.
[357] Fix | Delete
* If it's a string, just pass it through.
[358] Fix | Delete
*
[359] Fix | Delete
* @param string|callable $replacement Replacement value
[360] Fix | Delete
* @param array $match Match data, in PREG_OFFSET_CAPTURE form
[361] Fix | Delete
*
[362] Fix | Delete
* @return string
[363] Fix | Delete
*/
[364] Fix | Delete
protected function executeReplacement( $replacement, $match ) {
[365] Fix | Delete
if ( ! is_callable( $replacement ) ) {
[366] Fix | Delete
return $replacement;
[367] Fix | Delete
}
[368] Fix | Delete
// convert $match from the PREG_OFFSET_CAPTURE form to the form the callback expects
[369] Fix | Delete
foreach ( $match as &$matchItem ) {
[370] Fix | Delete
$matchItem = $matchItem[0];
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
return $replacement( $match );
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Strings are a pattern we need to match, in order to ignore potential
[378] Fix | Delete
* code-like content inside them, but we just want all of the string
[379] Fix | Delete
* content to remain untouched.
[380] Fix | Delete
*
[381] Fix | Delete
* This method will replace all string content with simple STRING#
[382] Fix | Delete
* placeholder text, so we've rid all strings from characters that may be
[383] Fix | Delete
* misinterpreted. Original string content will be saved in $this->extracted
[384] Fix | Delete
* and after doing all other minifying, we can restore the original content
[385] Fix | Delete
* via restoreStrings().
[386] Fix | Delete
*
[387] Fix | Delete
* @param string[optional] $chars
[388] Fix | Delete
* @param string[optional] $placeholderPrefix
[389] Fix | Delete
*/
[390] Fix | Delete
protected function extractStrings( $chars = '\'"', $placeholderPrefix = '' ) {
[391] Fix | Delete
// PHP only supports $this inside anonymous functions since 5.4
[392] Fix | Delete
$minifier = $this;
[393] Fix | Delete
$callback = function ( $match ) use ( $minifier, $placeholderPrefix ) {
[394] Fix | Delete
// check the second index here, because the first always contains a quote
[395] Fix | Delete
if ( $match[2] === '' ) {
[396] Fix | Delete
/*
[397] Fix | Delete
* Empty strings need no placeholder; they can't be confused for
[398] Fix | Delete
* anything else anyway.
[399] Fix | Delete
* But we still needed to match them, for the extraction routine
[400] Fix | Delete
* to skip over this particular string.
[401] Fix | Delete
*/
[402] Fix | Delete
return $match[0];
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
$count = count( $minifier->extracted );
[406] Fix | Delete
$placeholder = $match[1] . $placeholderPrefix . $count . $match[1];
[407] Fix | Delete
$minifier->extracted[ $placeholder ] = $match[1] . $match[2] . $match[1];
[408] Fix | Delete
[409] Fix | Delete
return $placeholder;
[410] Fix | Delete
};
[411] Fix | Delete
[412] Fix | Delete
/*
[413] Fix | Delete
* The \\ messiness explained:
[414] Fix | Delete
* * Don't count ' or " as end-of-string if it's escaped (has backslash
[415] Fix | Delete
* in front of it)
[416] Fix | Delete
* * Unless... that backslash itself is escaped (another leading slash),
[417] Fix | Delete
* in which case it's no longer escaping the ' or "
[418] Fix | Delete
* * So there can be either no backslash, or an even number
[419] Fix | Delete
* * multiply all of that times 4, to account for the escaping that has
[420] Fix | Delete
* to be done to pass the backslash into the PHP string without it being
[421] Fix | Delete
* considered as escape-char (times 2) and to get it in the regex,
[422] Fix | Delete
* escaped (times 2)
[423] Fix | Delete
*/
[424] Fix | Delete
$this->registerPattern( '/([' . $chars . '])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback );
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
/**
[428] Fix | Delete
* This method will restore all extracted data (strings, regexes) that were
[429] Fix | Delete
* replaced with placeholder text in extract*(). The original content was
[430] Fix | Delete
* saved in $this->extracted.
[431] Fix | Delete
*
[432] Fix | Delete
* @param string $content
[433] Fix | Delete
*
[434] Fix | Delete
* @return string
[435] Fix | Delete
*/
[436] Fix | Delete
protected function restoreExtractedData( $content ) {
[437] Fix | Delete
if ( ! $this->extracted ) {
[438] Fix | Delete
// nothing was extracted, nothing to restore
[439] Fix | Delete
return $content;
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
$content = strtr( $content, $this->extracted );
[443] Fix | Delete
[444] Fix | Delete
$this->extracted = array();
[445] Fix | Delete
[446] Fix | Delete
return $content;
[447] Fix | Delete
}
[448] Fix | Delete
[449] Fix | Delete
/**
[450] Fix | Delete
* Check if the path is a regular file and can be read.
[451] Fix | Delete
*
[452] Fix | Delete
* @param string $path
[453] Fix | Delete
*
[454] Fix | Delete
* @return bool
[455] Fix | Delete
*/
[456] Fix | Delete
protected function canImportFile( $path ) {
[457] Fix | Delete
$parsed = parse_url( $path );
[458] Fix | Delete
if (
[459] Fix | Delete
// file is elsewhere
[460] Fix | Delete
isset( $parsed['host'] )
[461] Fix | Delete
// file responds to queries (may change, or need to bypass cache)
[462] Fix | Delete
|| isset( $parsed['query'] )
[463] Fix | Delete
) {
[464] Fix | Delete
return false;
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
try {
[468] Fix | Delete
return strlen( $path ) < PHP_MAXPATHLEN && @is_file( $path ) && is_readable( $path );
[469] Fix | Delete
}
[470] Fix | Delete
// catch openbasedir exceptions which are not caught by @ on is_file()
[471] Fix | Delete
catch ( \Exception $e ) {
[472] Fix | Delete
return false;
[473] Fix | Delete
}
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
/**
[477] Fix | Delete
* Attempts to open file specified by $path for writing.
[478] Fix | Delete
*
[479] Fix | Delete
* @param string $path The path to the file
[480] Fix | Delete
*
[481] Fix | Delete
* @return resource Specifier for the target file
[482] Fix | Delete
*
[483] Fix | Delete
* @throws IOException
[484] Fix | Delete
*/
[485] Fix | Delete
protected function openFileForWriting( $path ) {
[486] Fix | Delete
if ( $path === '' || ( $handler = @fopen( $path, 'w' ) ) === false ) {
[487] Fix | Delete
throw new IOException( 'The file "' . $path . '" could not be opened for writing. Check if PHP has enough permissions.' );
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
return $handler;
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
/**
[494] Fix | Delete
* Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.
[495] Fix | Delete
*
[496] Fix | Delete
* @param resource $handler The resource to write to
[497] Fix | Delete
* @param string $content The content to write
[498] Fix | Delete
* @param string $path The path to the file (for exception printing only)
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function