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
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordfenc.../lib
File: wfFileUtils.php
<?php
[0] Fix | Delete
[1] Fix | Delete
require_once __DIR__ . "/wfInvalidPathException.php";
[2] Fix | Delete
require_once __DIR__ . "/wfInaccessibleDirectoryException.php";
[3] Fix | Delete
[4] Fix | Delete
class wfFileUtils {
[5] Fix | Delete
[6] Fix | Delete
const CURRENT_DIRECTORY = '.';
[7] Fix | Delete
const PARENT_DIRECTORY = '..';
[8] Fix | Delete
const DIRECTORY_SEPARATOR = '/';
[9] Fix | Delete
[10] Fix | Delete
public static function isCurrentOrParentDirectory($file) {
[11] Fix | Delete
return $file === self::CURRENT_DIRECTORY || $file === self::PARENT_DIRECTORY;
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
public static function getContents($directory) {
[15] Fix | Delete
$contents = @scandir($directory);
[16] Fix | Delete
if ($contents === false)
[17] Fix | Delete
throw new wfInaccessibleDirectoryException("Unable to read contents", $directory);
[18] Fix | Delete
return array_filter($contents, function ($file) { return !wfFileUtils::isCurrentOrParentDirectory($file); });
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
public static function trimSeparators($path, $trimLeft = true, $trimRight = true) {
[22] Fix | Delete
if ($trimLeft)
[23] Fix | Delete
$path = ltrim($path, self::DIRECTORY_SEPARATOR);
[24] Fix | Delete
if ($trimRight)
[25] Fix | Delete
$path = rtrim($path, self::DIRECTORY_SEPARATOR);
[26] Fix | Delete
return $path;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
public static function joinPaths() {
[30] Fix | Delete
$paths = func_get_args();
[31] Fix | Delete
$count = count($paths);
[32] Fix | Delete
$filtered = array();
[33] Fix | Delete
$trailingSeparator = false;
[34] Fix | Delete
for ($i = 0; $i < $count; $i++) {
[35] Fix | Delete
$path = self::trimSeparators($paths[$i], !empty($filtered));
[36] Fix | Delete
if (!empty($path)) {
[37] Fix | Delete
$filtered[] = $path;
[38] Fix | Delete
$trailingSeparator = substr($paths[$i], -1) === self::DIRECTORY_SEPARATOR;
[39] Fix | Delete
}
[40] Fix | Delete
}
[41] Fix | Delete
return implode(self::DIRECTORY_SEPARATOR, $filtered) . ($trailingSeparator ? self::DIRECTORY_SEPARATOR : '');
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
public static function splitPath($path, &$count = null) {
[45] Fix | Delete
$components = array_values(array_filter(explode(self::DIRECTORY_SEPARATOR, $path)));
[46] Fix | Delete
$count = count($components);
[47] Fix | Delete
return $components;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public static function isReadableFile($file) {
[51] Fix | Delete
return @is_file($file) && @is_readable($file);
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
public static function belongsTo($child, $parent) {
[55] Fix | Delete
$childComponents = self::splitPath($child, $childCount);
[56] Fix | Delete
$parentComponents = self::splitPath($parent, $parentCount);
[57] Fix | Delete
if ($childCount < $parentCount)
[58] Fix | Delete
return false;
[59] Fix | Delete
for ($i = 0; $i < $parentCount; $i++) {
[60] Fix | Delete
if ($childComponents[$i] !== $parentComponents[$i])
[61] Fix | Delete
return false;
[62] Fix | Delete
}
[63] Fix | Delete
return true;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
public static function matchPaths($a, $b, $allowChild = false) {
[67] Fix | Delete
$aComponents = self::splitPath($a, $aCount);
[68] Fix | Delete
$bComponents = self::splitPath($b, $bCount);
[69] Fix | Delete
if ($allowChild ? ($bCount < $aCount) : ($aCount !== $bCount))
[70] Fix | Delete
return false;
[71] Fix | Delete
for ($i = 0; $i < $aCount; $i++) {
[72] Fix | Delete
if ($aComponents[$i] !== $bComponents[$i])
[73] Fix | Delete
return false;
[74] Fix | Delete
}
[75] Fix | Delete
return true;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
public static function realPath($path) {
[79] Fix | Delete
$realPath = realpath($path);
[80] Fix | Delete
if ($realPath === false)
[81] Fix | Delete
throw new wfInvalidPathException("Realpath resolution failed", $path);
[82] Fix | Delete
return $realPath;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
public static function isChild($parent, $child) {
[86] Fix | Delete
return self::matchPaths($parent, $child, true);
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
}
[90] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function