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/clone/wp-conte.../plugins/wordfenc.../lib
File: wfUtils.php
$hiddenReadmeFile = $readmePathInfo['filename'] . '.' . wp_hash('readme') . '.' . $readmePathInfo['extension'];
[2000] Fix | Delete
return @rename($readmePath, $readmePathInfo['dirname'] . '/' . $hiddenReadmeFile);
[2001] Fix | Delete
}
[2002] Fix | Delete
return false;
[2003] Fix | Delete
}
[2004] Fix | Delete
[2005] Fix | Delete
/**
[2006] Fix | Delete
* @param string $readmePath
[2007] Fix | Delete
* @return bool
[2008] Fix | Delete
*/
[2009] Fix | Delete
public static function showReadme($readmePath = null) {
[2010] Fix | Delete
if ($readmePath === null) {
[2011] Fix | Delete
$readmePath = ABSPATH . 'readme.html';
[2012] Fix | Delete
}
[2013] Fix | Delete
$readmePathInfo = pathinfo($readmePath);
[2014] Fix | Delete
require_once(ABSPATH . WPINC . '/pluggable.php');
[2015] Fix | Delete
$hiddenReadmeFile = $readmePathInfo['dirname'] . '/' . $readmePathInfo['filename'] . '.' . wp_hash('readme') . '.' . $readmePathInfo['extension'];
[2016] Fix | Delete
if (file_exists($hiddenReadmeFile)) {
[2017] Fix | Delete
return @rename($hiddenReadmeFile, $readmePath);
[2018] Fix | Delete
}
[2019] Fix | Delete
return false;
[2020] Fix | Delete
}
[2021] Fix | Delete
[2022] Fix | Delete
public static function htaccessAppend($code)
[2023] Fix | Delete
{
[2024] Fix | Delete
$htaccess = wfCache::getHtaccessPath();
[2025] Fix | Delete
$content = self::htaccess();
[2026] Fix | Delete
if (wfUtils::isNginx() || !is_writable($htaccess)) {
[2027] Fix | Delete
return false;
[2028] Fix | Delete
}
[2029] Fix | Delete
[2030] Fix | Delete
if (strpos($content, $code) === false) {
[2031] Fix | Delete
// make sure we write this once
[2032] Fix | Delete
file_put_contents($htaccess, $content . "\n" . trim($code), LOCK_EX);
[2033] Fix | Delete
}
[2034] Fix | Delete
[2035] Fix | Delete
return true;
[2036] Fix | Delete
}
[2037] Fix | Delete
[2038] Fix | Delete
public static function htaccessPrepend($code)
[2039] Fix | Delete
{
[2040] Fix | Delete
$htaccess = wfCache::getHtaccessPath();
[2041] Fix | Delete
$content = self::htaccess();
[2042] Fix | Delete
if (wfUtils::isNginx() || !is_writable($htaccess)) {
[2043] Fix | Delete
return false;
[2044] Fix | Delete
}
[2045] Fix | Delete
[2046] Fix | Delete
if (strpos($content, $code) === false) {
[2047] Fix | Delete
// make sure we write this once
[2048] Fix | Delete
file_put_contents($htaccess, trim($code) . "\n" . $content, LOCK_EX);
[2049] Fix | Delete
}
[2050] Fix | Delete
[2051] Fix | Delete
return true;
[2052] Fix | Delete
}
[2053] Fix | Delete
[2054] Fix | Delete
public static function htaccess() {
[2055] Fix | Delete
$htaccess = wfCache::getHtaccessPath();
[2056] Fix | Delete
if (is_readable($htaccess) && !wfUtils::isNginx()) {
[2057] Fix | Delete
return file_get_contents($htaccess);
[2058] Fix | Delete
}
[2059] Fix | Delete
return "";
[2060] Fix | Delete
}
[2061] Fix | Delete
[2062] Fix | Delete
/**
[2063] Fix | Delete
* @param array $array
[2064] Fix | Delete
* @param mixed $oldKey
[2065] Fix | Delete
* @param mixed $newKey
[2066] Fix | Delete
* @return array
[2067] Fix | Delete
* @throws Exception
[2068] Fix | Delete
*/
[2069] Fix | Delete
public static function arrayReplaceKey($array, $oldKey, $newKey) {
[2070] Fix | Delete
$keys = array_keys($array);
[2071] Fix | Delete
if (($index = array_search($oldKey, $keys)) === false) {
[2072] Fix | Delete
throw new Exception(sprintf('Key "%s" does not exist', $oldKey));
[2073] Fix | Delete
}
[2074] Fix | Delete
$keys[$index] = $newKey;
[2075] Fix | Delete
return array_combine($keys, array_values($array));
[2076] Fix | Delete
}
[2077] Fix | Delete
[2078] Fix | Delete
/**
[2079] Fix | Delete
* Takes a string that may have characters that will be interpreted as invalid UTF-8 byte sequences and translates them into a string of the equivalent hex sequence.
[2080] Fix | Delete
*
[2081] Fix | Delete
* @param $string
[2082] Fix | Delete
* @param bool $inline
[2083] Fix | Delete
* @return string
[2084] Fix | Delete
*/
[2085] Fix | Delete
public static function potentialBinaryStringToHTML($string, $inline = false, $allowmb4 = false) {
[2086] Fix | Delete
$output = '';
[2087] Fix | Delete
[2088] Fix | Delete
if (!defined('ENT_SUBSTITUTE')) {
[2089] Fix | Delete
define('ENT_SUBSTITUTE', 0);
[2090] Fix | Delete
}
[2091] Fix | Delete
[2092] Fix | Delete
$span = '<span class="wf-hex-sequence">';
[2093] Fix | Delete
if ($inline) {
[2094] Fix | Delete
$span = '<span style="color:#587ECB">';
[2095] Fix | Delete
}
[2096] Fix | Delete
[2097] Fix | Delete
for ($i = 0; $i < wfUtils::strlen($string); $i++) {
[2098] Fix | Delete
$c = $string[$i];
[2099] Fix | Delete
$b = ord($c);
[2100] Fix | Delete
if ($b < 0x20) {
[2101] Fix | Delete
$output .= $span . '\x' . str_pad(dechex($b), 2, '0', STR_PAD_LEFT) . '</span>';
[2102] Fix | Delete
}
[2103] Fix | Delete
else if ($b < 0x80) {
[2104] Fix | Delete
$output .= htmlspecialchars($c, ENT_QUOTES, 'ISO-8859-1');
[2105] Fix | Delete
}
[2106] Fix | Delete
else { //Assume multi-byte UTF-8
[2107] Fix | Delete
$bytes = 0;
[2108] Fix | Delete
$test = $b;
[2109] Fix | Delete
[2110] Fix | Delete
while (($test & 0x80) > 0) {
[2111] Fix | Delete
$bytes++;
[2112] Fix | Delete
$test = (($test << 1) & 0xff);
[2113] Fix | Delete
}
[2114] Fix | Delete
[2115] Fix | Delete
$brokenUTF8 = ($i + $bytes > wfUtils::strlen($string) || $bytes == 1);
[2116] Fix | Delete
if (!$brokenUTF8) { //Make sure we have all the bytes
[2117] Fix | Delete
for ($n = 1; $n < $bytes; $n++) {
[2118] Fix | Delete
$c2 = $string[$i + $n];
[2119] Fix | Delete
$b2 = ord($c2);
[2120] Fix | Delete
if (($b2 & 0xc0) != 0x80) {
[2121] Fix | Delete
$brokenUTF8 = true;
[2122] Fix | Delete
$bytes = $n;
[2123] Fix | Delete
break;
[2124] Fix | Delete
}
[2125] Fix | Delete
}
[2126] Fix | Delete
}
[2127] Fix | Delete
[2128] Fix | Delete
if (!$brokenUTF8) { //Ensure the byte sequences are within the accepted ranges: https://tools.ietf.org/html/rfc3629
[2129] Fix | Delete
/*
[2130] Fix | Delete
* UTF8-octets = *( UTF8-char )
[2131] Fix | Delete
* UTF8-char = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
[2132] Fix | Delete
* UTF8-1 = %x00-7F
[2133] Fix | Delete
* UTF8-2 = %xC2-DF UTF8-tail
[2134] Fix | Delete
* UTF8-3 = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
[2135] Fix | Delete
* %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
[2136] Fix | Delete
* UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
[2137] Fix | Delete
* %xF4 %x80-8F 2( UTF8-tail )
[2138] Fix | Delete
* UTF8-tail = %x80-BF
[2139] Fix | Delete
*/
[2140] Fix | Delete
[2141] Fix | Delete
$testString = wfUtils::substr($string, $i, $bytes);
[2142] Fix | Delete
$regex = '/^(?:' .
[2143] Fix | Delete
'[\xc2-\xdf][\x80-\xbf]' . //UTF8-2
[2144] Fix | Delete
'|' . '\xe0[\xa0-\xbf][\x80-\xbf]' . //UTF8-3
[2145] Fix | Delete
'|' . '[\xe1-\xec][\x80-\xbf]{2}' .
[2146] Fix | Delete
'|' . '\xed[\x80-\x9f][\x80-\xbf]' .
[2147] Fix | Delete
'|' . '[\xee-\xef][\x80-\xbf]{2}';
[2148] Fix | Delete
if ($allowmb4) {
[2149] Fix | Delete
$regex .= '|' . '\xf0[\x90-\xbf][\x80-\xbf]{2}' . //UTF8-4
[2150] Fix | Delete
'|' . '[\xf1-\xf3][\x80-\xbf]{3}' .
[2151] Fix | Delete
'|' . '\xf4[\x80-\x8f][\x80-\xbf]{2}';
[2152] Fix | Delete
}
[2153] Fix | Delete
$regex .= ')$/';
[2154] Fix | Delete
if (!preg_match($regex, $testString)) {
[2155] Fix | Delete
$brokenUTF8 = true;
[2156] Fix | Delete
}
[2157] Fix | Delete
}
[2158] Fix | Delete
[2159] Fix | Delete
if ($brokenUTF8) {
[2160] Fix | Delete
$bytes = min($bytes, strlen($string) - $i);
[2161] Fix | Delete
for ($n = 0; $n < $bytes; $n++) {
[2162] Fix | Delete
$c2 = $string[$i + $n];
[2163] Fix | Delete
$b2 = ord($c2);
[2164] Fix | Delete
$output .= $span . '\x' . str_pad(dechex($b2), 2, '0', STR_PAD_LEFT) . '</span>';
[2165] Fix | Delete
}
[2166] Fix | Delete
$i += ($bytes - 1);
[2167] Fix | Delete
}
[2168] Fix | Delete
else {
[2169] Fix | Delete
$output .= htmlspecialchars(wfUtils::substr($string, $i, $bytes), ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1');
[2170] Fix | Delete
$i += ($bytes - 1);
[2171] Fix | Delete
}
[2172] Fix | Delete
}
[2173] Fix | Delete
}
[2174] Fix | Delete
return $output;
[2175] Fix | Delete
}
[2176] Fix | Delete
[2177] Fix | Delete
public static function requestDetectProxyCallback($timeout = 2, $blocking = true, $forceCheck = false) {
[2178] Fix | Delete
$currentRecommendation = wfConfig::get('detectProxyRecommendation', '');
[2179] Fix | Delete
if (!$forceCheck) {
[2180] Fix | Delete
$detectProxyNextCheck = wfConfig::get('detectProxyNextCheck', false);
[2181] Fix | Delete
if ($detectProxyNextCheck !== false && time() < $detectProxyNextCheck) {
[2182] Fix | Delete
if (empty($currentRecommendation)) {
[2183] Fix | Delete
wfConfig::set('detectProxyRecommendation', 'DEFERRED', wfConfig::DONT_AUTOLOAD);
[2184] Fix | Delete
}
[2185] Fix | Delete
return; //Let it pull the currently-stored value
[2186] Fix | Delete
}
[2187] Fix | Delete
}
[2188] Fix | Delete
[2189] Fix | Delete
try {
[2190] Fix | Delete
$waf = wfWAF::getInstance();
[2191] Fix | Delete
if ($waf->getStorageEngine()->getConfig('attackDataKey', false) === false) {
[2192] Fix | Delete
$waf->getStorageEngine()->setConfig('attackDataKey', mt_rand(0, 0xfff));
[2193] Fix | Delete
}
[2194] Fix | Delete
$response = wp_remote_get(sprintf(WFWAF_API_URL_SEC . "proxy-check/%d.txt", $waf->getStorageEngine()->getConfig('attackDataKey')), array('headers' => array('Referer' => false)));
[2195] Fix | Delete
[2196] Fix | Delete
if (!is_wp_error($response)) {
[2197] Fix | Delete
$okToSendBody = wp_remote_retrieve_body($response);
[2198] Fix | Delete
if (preg_match('/^(ok|wait),\s*(\d+)$/i', $okToSendBody, $matches)) {
[2199] Fix | Delete
$command = $matches[1];
[2200] Fix | Delete
$ttl = $matches[2];
[2201] Fix | Delete
if ($command == 'wait') {
[2202] Fix | Delete
wfConfig::set('detectProxyNextCheck', time() + $ttl, wfConfig::DONT_AUTOLOAD);
[2203] Fix | Delete
if (empty($currentRecommendation) || $currentRecommendation == 'UNKNOWN') {
[2204] Fix | Delete
wfConfig::set('detectProxyRecommendation', 'DEFERRED', wfConfig::DONT_AUTOLOAD);
[2205] Fix | Delete
}
[2206] Fix | Delete
return;
[2207] Fix | Delete
}
[2208] Fix | Delete
[2209] Fix | Delete
wfConfig::set('detectProxyNextCheck', time() + $ttl, wfConfig::DONT_AUTOLOAD);
[2210] Fix | Delete
}
[2211] Fix | Delete
else { //Unknown response
[2212] Fix | Delete
wfConfig::set('detectProxyNextCheck', false, wfConfig::DONT_AUTOLOAD);
[2213] Fix | Delete
if (empty($currentRecommendation) || $currentRecommendation == 'UNKNOWN') {
[2214] Fix | Delete
wfConfig::set('detectProxyRecommendation', 'DEFERRED', wfConfig::DONT_AUTOLOAD);
[2215] Fix | Delete
}
[2216] Fix | Delete
return;
[2217] Fix | Delete
}
[2218] Fix | Delete
}
[2219] Fix | Delete
}
[2220] Fix | Delete
catch (Exception $e) {
[2221] Fix | Delete
return;
[2222] Fix | Delete
}
[2223] Fix | Delete
[2224] Fix | Delete
$nonce = bin2hex(wfWAFUtils::random_bytes(32));
[2225] Fix | Delete
$callback = self::getSiteBaseURL() . '?_wfsf=detectProxy';
[2226] Fix | Delete
[2227] Fix | Delete
wfConfig::set('detectProxyNonce', $nonce, wfConfig::DONT_AUTOLOAD);
[2228] Fix | Delete
wfConfig::set('detectProxyRecommendation', '', wfConfig::DONT_AUTOLOAD);
[2229] Fix | Delete
[2230] Fix | Delete
$payload = array(
[2231] Fix | Delete
'nonce' => $nonce,
[2232] Fix | Delete
'callback' => $callback,
[2233] Fix | Delete
);
[2234] Fix | Delete
[2235] Fix | Delete
$homeurl = wfUtils::wpHomeURL();
[2236] Fix | Delete
$siteurl = wfUtils::wpSiteURL();
[2237] Fix | Delete
[2238] Fix | Delete
try {
[2239] Fix | Delete
$response = wp_remote_post(WFWAF_API_URL_SEC . "?" . http_build_query(array(
[2240] Fix | Delete
'action' => 'detect_proxy',
[2241] Fix | Delete
'k' => wfConfig::get('apiKey'),
[2242] Fix | Delete
's' => $siteurl,
[2243] Fix | Delete
'h' => $homeurl,
[2244] Fix | Delete
't' => microtime(true),
[2245] Fix | Delete
'lang' => get_site_option('WPLANG'),
[2246] Fix | Delete
), '', '&'),
[2247] Fix | Delete
array(
[2248] Fix | Delete
'body' => json_encode($payload),
[2249] Fix | Delete
'headers' => array(
[2250] Fix | Delete
'Content-Type' => 'application/json',
[2251] Fix | Delete
'Referer' => false,
[2252] Fix | Delete
),
[2253] Fix | Delete
'timeout' => $timeout,
[2254] Fix | Delete
'blocking' => $blocking,
[2255] Fix | Delete
));
[2256] Fix | Delete
[2257] Fix | Delete
if (!is_wp_error($response)) {
[2258] Fix | Delete
$jsonResponse = wp_remote_retrieve_body($response);
[2259] Fix | Delete
$decoded = @json_decode($jsonResponse, true);
[2260] Fix | Delete
if (is_array($decoded) && isset($decoded['data']) && is_array($decoded['data']) && isset($decoded['data']['ip']) && wfUtils::isValidIP($decoded['data']['ip'])) {
[2261] Fix | Delete
wfConfig::set('serverIP', time() . ';' . $decoded['data']['ip']);
[2262] Fix | Delete
}
[2263] Fix | Delete
}
[2264] Fix | Delete
}
[2265] Fix | Delete
catch (Exception $e) {
[2266] Fix | Delete
return;
[2267] Fix | Delete
}
[2268] Fix | Delete
}
[2269] Fix | Delete
[2270] Fix | Delete
/**
[2271] Fix | Delete
* @return bool Returns false if the payload is invalid, true if it processed the callback (even if the IP wasn't found).
[2272] Fix | Delete
*/
[2273] Fix | Delete
public static function processDetectProxyCallback() {
[2274] Fix | Delete
$nonce = wfConfig::get('detectProxyNonce', '');
[2275] Fix | Delete
$testNonce = (isset($_POST['nonce']) ? $_POST['nonce'] : '');
[2276] Fix | Delete
if (empty($nonce) || empty($testNonce)) {
[2277] Fix | Delete
return false;
[2278] Fix | Delete
}
[2279] Fix | Delete
[2280] Fix | Delete
if (!hash_equals($nonce, $testNonce)) {
[2281] Fix | Delete
return false;
[2282] Fix | Delete
}
[2283] Fix | Delete
[2284] Fix | Delete
$ips = (isset($_POST['ips']) ? $_POST['ips'] : array());
[2285] Fix | Delete
if (empty($ips)) {
[2286] Fix | Delete
return false;
[2287] Fix | Delete
}
[2288] Fix | Delete
[2289] Fix | Delete
$expandedIPs = array();
[2290] Fix | Delete
foreach ($ips as $ip) {
[2291] Fix | Delete
$expandedIPs[] = self::inet_pton($ip);
[2292] Fix | Delete
}
[2293] Fix | Delete
[2294] Fix | Delete
$checks = array('HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR');
[2295] Fix | Delete
foreach ($checks as $key) {
[2296] Fix | Delete
if (!isset($_SERVER[$key])) {
[2297] Fix | Delete
continue;
[2298] Fix | Delete
}
[2299] Fix | Delete
[2300] Fix | Delete
$testIP = self::getCleanIPAndServerVar(array(array($_SERVER[$key], $key)));
[2301] Fix | Delete
if ($testIP === false) {
[2302] Fix | Delete
continue;
[2303] Fix | Delete
}
[2304] Fix | Delete
[2305] Fix | Delete
$testIP = self::inet_pton($testIP[0]);
[2306] Fix | Delete
if (in_array($testIP, $expandedIPs)) {
[2307] Fix | Delete
wfConfig::set('detectProxyRecommendation', $key, wfConfig::DONT_AUTOLOAD);
[2308] Fix | Delete
wfConfig::set('detectProxyNonce', '', wfConfig::DONT_AUTOLOAD);
[2309] Fix | Delete
return true;
[2310] Fix | Delete
}
[2311] Fix | Delete
}
[2312] Fix | Delete
[2313] Fix | Delete
wfConfig::set('detectProxyRecommendation', 'UNKNOWN', wfConfig::DONT_AUTOLOAD);
[2314] Fix | Delete
wfConfig::set('detectProxyNonce', '', wfConfig::DONT_AUTOLOAD);
[2315] Fix | Delete
return true;
[2316] Fix | Delete
}
[2317] Fix | Delete
[2318] Fix | Delete
/**
[2319] Fix | Delete
* Returns a v4 UUID.
[2320] Fix | Delete
*
[2321] Fix | Delete
* @return string
[2322] Fix | Delete
*/
[2323] Fix | Delete
public static function uuid() {
[2324] Fix | Delete
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
[2325] Fix | Delete
// 32 bits for "time_low"
[2326] Fix | Delete
wfWAFUtils::random_int(0, 0xffff), wfWAFUtils::random_int(0, 0xffff),
[2327] Fix | Delete
[2328] Fix | Delete
// 16 bits for "time_mid"
[2329] Fix | Delete
wfWAFUtils::random_int(0, 0xffff),
[2330] Fix | Delete
[2331] Fix | Delete
// 16 bits for "time_hi_and_version",
[2332] Fix | Delete
// four most significant bits holds version number 4
[2333] Fix | Delete
wfWAFUtils::random_int(0, 0x0fff) | 0x4000,
[2334] Fix | Delete
[2335] Fix | Delete
// 16 bits, 8 bits for "clk_seq_hi_res",
[2336] Fix | Delete
// 8 bits for "clk_seq_low",
[2337] Fix | Delete
// two most significant bits holds zero and one for variant DCE1.1
[2338] Fix | Delete
wfWAFUtils::random_int(0, 0x3fff) | 0x8000,
[2339] Fix | Delete
[2340] Fix | Delete
// 48 bits for "node"
[2341] Fix | Delete
wfWAFUtils::random_int(0, 0xffff), wfWAFUtils::random_int(0, 0xffff), wfWAFUtils::random_int(0, 0xffff)
[2342] Fix | Delete
);
[2343] Fix | Delete
}
[2344] Fix | Delete
[2345] Fix | Delete
public static function base32_encode($rawString, $rightPadFinalBits = false, $padFinalGroup = false, $padCharacter = '=') //Adapted from https://github.com/ademarre/binary-to-text-php
[2346] Fix | Delete
{
[2347] Fix | Delete
// Unpack string into an array of bytes
[2348] Fix | Delete
$bytes = unpack('C*', $rawString);
[2349] Fix | Delete
$byteCount = count($bytes);
[2350] Fix | Delete
[2351] Fix | Delete
$encodedString = '';
[2352] Fix | Delete
$byte = array_shift($bytes);
[2353] Fix | Delete
$bitsRead = 0;
[2354] Fix | Delete
$oldBits = 0;
[2355] Fix | Delete
[2356] Fix | Delete
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
[2357] Fix | Delete
$bitsPerCharacter = 5;
[2358] Fix | Delete
[2359] Fix | Delete
$charsPerByte = 8 / $bitsPerCharacter;
[2360] Fix | Delete
$encodedLength = $byteCount * $charsPerByte;
[2361] Fix | Delete
[2362] Fix | Delete
// Generate encoded output; each loop produces one encoded character
[2363] Fix | Delete
for ($c = 0; $c < $encodedLength; $c++) {
[2364] Fix | Delete
[2365] Fix | Delete
// Get the bits needed for this encoded character
[2366] Fix | Delete
if ($bitsRead + $bitsPerCharacter > 8) {
[2367] Fix | Delete
// Not enough bits remain in this byte for the current character
[2368] Fix | Delete
// Save the remaining bits before getting the next byte
[2369] Fix | Delete
$oldBitCount = 8 - $bitsRead;
[2370] Fix | Delete
$oldBits = $byte ^ ($byte >> $oldBitCount << $oldBitCount);
[2371] Fix | Delete
$newBitCount = $bitsPerCharacter - $oldBitCount;
[2372] Fix | Delete
[2373] Fix | Delete
if (!$bytes) {
[2374] Fix | Delete
// Last bits; match final character and exit loop
[2375] Fix | Delete
if ($rightPadFinalBits) $oldBits <<= $newBitCount;
[2376] Fix | Delete
$encodedString .= $chars[$oldBits];
[2377] Fix | Delete
[2378] Fix | Delete
if ($padFinalGroup) {
[2379] Fix | Delete
// Array of the lowest common multiples of $bitsPerCharacter and 8, divided by 8
[2380] Fix | Delete
$lcmMap = array(1 => 1, 2 => 1, 3 => 3, 4 => 1, 5 => 5, 6 => 3, 7 => 7, 8 => 1);
[2381] Fix | Delete
$bytesPerGroup = $lcmMap[$bitsPerCharacter];
[2382] Fix | Delete
$pads = $bytesPerGroup * $charsPerByte - ceil((strlen($rawString) % $bytesPerGroup) * $charsPerByte);
[2383] Fix | Delete
$encodedString .= str_repeat($padCharacter, $pads);
[2384] Fix | Delete
}
[2385] Fix | Delete
[2386] Fix | Delete
break;
[2387] Fix | Delete
}
[2388] Fix | Delete
[2389] Fix | Delete
// Get next byte
[2390] Fix | Delete
$byte = array_shift($bytes);
[2391] Fix | Delete
$bitsRead = 0;
[2392] Fix | Delete
[2393] Fix | Delete
} else {
[2394] Fix | Delete
$oldBitCount = 0;
[2395] Fix | Delete
$newBitCount = $bitsPerCharacter;
[2396] Fix | Delete
}
[2397] Fix | Delete
[2398] Fix | Delete
// Read only the needed bits from this byte
[2399] Fix | Delete
$bits = $byte >> 8 - ($bitsRead + ($newBitCount));
[2400] Fix | Delete
$bits ^= $bits >> $newBitCount << $newBitCount;
[2401] Fix | Delete
$bitsRead += $newBitCount;
[2402] Fix | Delete
[2403] Fix | Delete
if ($oldBitCount) {
[2404] Fix | Delete
// Bits come from seperate bytes, add $oldBits to $bits
[2405] Fix | Delete
$bits = ($oldBits << $newBitCount) | $bits;
[2406] Fix | Delete
}
[2407] Fix | Delete
[2408] Fix | Delete
$encodedString .= $chars[$bits];
[2409] Fix | Delete
}
[2410] Fix | Delete
[2411] Fix | Delete
return $encodedString;
[2412] Fix | Delete
}
[2413] Fix | Delete
[2414] Fix | Delete
private static function _home_url_nofilter($path = '', $scheme = null) { //A version of the native get_home_url and get_option without the filter calls
[2415] Fix | Delete
global $pagenow, $wpdb, $blog_id;
[2416] Fix | Delete
[2417] Fix | Delete
static $cached_url = null;
[2418] Fix | Delete
if ($cached_url !== null) {
[2419] Fix | Delete
return $cached_url;
[2420] Fix | Delete
}
[2421] Fix | Delete
[2422] Fix | Delete
if (defined('WP_HOME') && WORDFENCE_PREFER_WP_HOME_FOR_WPML) {
[2423] Fix | Delete
$cached_url = WP_HOME;
[2424] Fix | Delete
return $cached_url;
[2425] Fix | Delete
}
[2426] Fix | Delete
[2427] Fix | Delete
if ( empty( $blog_id ) || !is_multisite() ) {
[2428] Fix | Delete
$url = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'home' LIMIT 1");
[2429] Fix | Delete
if (empty($url)) { //get_option uses siteurl instead if home is empty
[2430] Fix | Delete
$url = $wpdb->get_var("SELECT option_value FROM {$wpdb->options} WHERE option_name = 'siteurl' LIMIT 1");
[2431] Fix | Delete
}
[2432] Fix | Delete
}
[2433] Fix | Delete
else if (is_multisite()) {
[2434] Fix | Delete
$current_network = get_network();
[2435] Fix | Delete
if ( 'relative' == $scheme )
[2436] Fix | Delete
$url = rtrim($current_network->path, '/');
[2437] Fix | Delete
else
[2438] Fix | Delete
$url = 'http://' . rtrim($current_network->domain, '/') . '/' . trim($current_network->path, '/');
[2439] Fix | Delete
}
[2440] Fix | Delete
[2441] Fix | Delete
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
[2442] Fix | Delete
if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow )
[2443] Fix | Delete
$scheme = 'https';
[2444] Fix | Delete
else
[2445] Fix | Delete
$scheme = parse_url( $url, PHP_URL_SCHEME );
[2446] Fix | Delete
}
[2447] Fix | Delete
[2448] Fix | Delete
$url = set_url_scheme( $url, $scheme );
[2449] Fix | Delete
[2450] Fix | Delete
if ( $path && is_string( $path ) )
[2451] Fix | Delete
$url .= '/' . ltrim( $path, '/' );
[2452] Fix | Delete
[2453] Fix | Delete
$cached_url = $url;
[2454] Fix | Delete
return $url;
[2455] Fix | Delete
}
[2456] Fix | Delete
[2457] Fix | Delete
public static function refreshCachedHomeURL() {
[2458] Fix | Delete
$pullDirectly = class_exists('WPML_URL_Filters');
[2459] Fix | Delete
$homeurl = '';
[2460] Fix | Delete
if ($pullDirectly) {
[2461] Fix | Delete
//A version of the native get_home_url without the filter call
[2462] Fix | Delete
$homeurl = self::_home_url_nofilter();
[2463] Fix | Delete
}
[2464] Fix | Delete
[2465] Fix | Delete
if (function_exists('get_bloginfo') && empty($homeurl)) {
[2466] Fix | Delete
if (is_multisite()) {
[2467] Fix | Delete
$homeurl = network_home_url();
[2468] Fix | Delete
}
[2469] Fix | Delete
else {
[2470] Fix | Delete
$homeurl = home_url();
[2471] Fix | Delete
}
[2472] Fix | Delete
[2473] Fix | Delete
$homeurl = rtrim($homeurl, '/'); //Because previously we used get_bloginfo and it returns http://example.com without a '/' char.
[2474] Fix | Delete
}
[2475] Fix | Delete
[2476] Fix | Delete
if (wfConfig::get('wp_home_url') !== $homeurl) {
[2477] Fix | Delete
wfConfig::set('wp_home_url', $homeurl);
[2478] Fix | Delete
}
[2479] Fix | Delete
}
[2480] Fix | Delete
[2481] Fix | Delete
public static function wpHomeURL($path = '', $scheme = null) {
[2482] Fix | Delete
$homeurl = wfConfig::get('wp_home_url', '');
[2483] Fix | Delete
if (function_exists('get_bloginfo') && empty($homeurl)) {
[2484] Fix | Delete
if (is_multisite()) {
[2485] Fix | Delete
$homeurl = network_home_url($path, $scheme);
[2486] Fix | Delete
}
[2487] Fix | Delete
else {
[2488] Fix | Delete
$homeurl = home_url($path, $scheme);
[2489] Fix | Delete
}
[2490] Fix | Delete
[2491] Fix | Delete
$homeurl = rtrim($homeurl, '/'); //Because previously we used get_bloginfo and it returns http://example.com without a '/' char.
[2492] Fix | Delete
}
[2493] Fix | Delete
else {
[2494] Fix | Delete
$homeurl = set_url_scheme($homeurl, $scheme);
[2495] Fix | Delete
if ($path && is_string($path)) {
[2496] Fix | Delete
$homeurl .= '/' . ltrim($path, '/');
[2497] Fix | Delete
}
[2498] Fix | Delete
}
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function