public function testNegativeExpGmppow() { if (function_exists('gmp_pow')) { $this->assertEquals( false, PMA_Util::pow(2, -2, 'gmp_pow') ); } else { $this->markTestSkipped('function gmp_pow() does not exist'); } }
/** * Based on IP Pattern Matcher * Originally by J.Adams <*****@*****.**> * Found on <http://www.php.net/manual/en/function.ip2long.php> * Modified for phpMyAdmin * * Matches: * xxx.xxx.xxx.xxx (exact) * xxx.xxx.xxx.[yyy-zzz] (range) * xxx.xxx.xxx.xxx/nn (CIDR) * * Does not match: * xxx.xxx.xxx.xx[yyy-zzz] (range, partial octets not supported) * * @param string $testRange string of IP range to match * @param string $ipToTest string of IP to test against range * * @return boolean always true * * @access public */ function PMA_ipMaskTest($testRange, $ipToTest) { $result = true; $match = preg_match('|([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)/([0-9]+)|', $testRange, $regs); if ($match) { // performs a mask match $ipl = ip2long($ipToTest); $rangel = ip2long($regs[1] . '.' . $regs[2] . '.' . $regs[3] . '.' . $regs[4]); $maskl = 0; for ($i = 0; $i < 31; $i++) { if ($i < $regs[5] - 1) { $maskl = $maskl + PMA_Util::pow(2, 30 - $i); } // end if } // end for if (($maskl & $rangel) == ($maskl & $ipl)) { return true; } else { return false; } } else { // range based $maskocts = explode('.', $testRange); $ipocts = explode('.', $ipToTest); // perform a range match for ($i = 0; $i < 4; $i++) { if (preg_match('|\\[([0-9]+)\\-([0-9]+)\\]|', $maskocts[$i], $regs)) { if ($ipocts[$i] > $regs[2] || $ipocts[$i] < $regs[1]) { $result = false; } // end if } else { if ($maskocts[$i] != $ipocts[$i]) { $result = false; } // end if } // end if/else } //end for } //end if/else return $result; }
/** * Get Ajax return when $_REQUEST['type'] === 'setval' * * @param Array $variable_doc_links documentation links * * @return null */ function PMA_getAjaxReturnForSetVal($variable_doc_links) { $response = PMA_Response::getInstance(); $value = $_REQUEST['varValue']; $matches = array(); if (isset($variable_doc_links[$_REQUEST['varName']][3]) && $variable_doc_links[$_REQUEST['varName']][3] == 'byte' && preg_match('/^\\s*(\\d+(\\.\\d+)?)\\s*(mb|kb|mib|kib|gb|gib)\\s*$/i', $value, $matches)) { $exp = array('kb' => 1, 'kib' => 1, 'mb' => 2, 'mib' => 2, 'gb' => 3, 'gib' => 3); $value = floatval($matches[1]) * PMA_Util::pow(1024, $exp[mb_strtolower($matches[3])]); } else { $value = PMA_Util::sqlAddSlashes($value); } if (!is_numeric($value)) { $value = "'" . $value . "'"; } if (!preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) && $GLOBALS['dbi']->query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value)) { // Some values are rounded down etc. $varValue = $GLOBALS['dbi']->fetchSingleRow('SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA_Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM'); $response->addJSON('variable', PMA_formatVariable($_REQUEST['varName'], $varValue[1], $variable_doc_links)); } else { $response->isSuccess(false); $response->addJSON('error', __('Setting variable failed')); } }
/** * Returns a point that is guaranteed to be on the surface of the ring. * (for simple closed rings) * * @param array $ring array of points forming the ring * * @return array|void a point on the surface of the ring * @access public * @static */ public static function getPointOnSurface($ring) { // Find two consecutive distinct points. for ($i = 0, $nb = count($ring) - 1; $i < $nb; $i++) { if ($ring[$i]['y'] != $ring[$i + 1]['y']) { $x0 = $ring[$i]['x']; $x1 = $ring[$i + 1]['x']; $y0 = $ring[$i]['y']; $y1 = $ring[$i + 1]['y']; break; } } if (!isset($x0)) { return false; } // Find the mid point $x2 = ($x0 + $x1) / 2; $y2 = ($y0 + $y1) / 2; // Always keep $epsilon < 1 to go with the reduction logic down here $epsilon = 0.1; $denominator = sqrt(PMA_Util::pow($y1 - $y0, 2) + PMA_Util::pow($x0 - $x1, 2)); $pointA = array(); $pointB = array(); while (true) { // Get the points on either sides of the line // with a distance of epsilon to the mid point $pointA['x'] = $x2 + $epsilon * ($y1 - $y0) / $denominator; $pointA['y'] = $y2 + ($pointA['x'] - $x2) * ($x0 - $x1) / ($y1 - $y0); $pointB['x'] = $x2 + $epsilon * ($y1 - $y0) / (0 - $denominator); $pointB['y'] = $y2 + ($pointB['x'] - $x2) * ($x0 - $x1) / ($y1 - $y0); // One of the points should be inside the polygon, // unless epsilon chosen is too large if (PMA_GIS_Polygon::isPointInsidePolygon($pointA, $ring)) { return $pointA; } if (PMA_GIS_Polygon::isPointInsidePolygon($pointB, $ring)) { return $pointB; } //If both are outside the polygon reduce the epsilon and //recalculate the points(reduce exponentially for faster convergence) $epsilon = PMA_Util::pow($epsilon, 2); if ($epsilon == 0) { return false; } } }
/** * Formats interval like 10 per hour * * @param integer $num number to format * @param integer $precision required precision * * @return string formatted string */ function ADVISOR_bytime($num, $precision) { if ($num >= 1) { // per second $per = __('per second'); } elseif ($num * 60 >= 1) { // per minute $num = $num * 60; $per = __('per minute'); } elseif ($num * 60 * 60 >= 1) { // per hour $num = $num * 60 * 60; $per = __('per hour'); } else { $num = $num * 60 * 60 * 24; $per = __('per day'); } $num = round($num, $precision); if ($num == 0) { $num = '<' . PMA_Util::pow(10, -$precision); } return "{$num} {$per}"; }
/** * Returns the column number based on the Excel name. * So "A" = 1, "Z" = 26, "AA" = 27, etc. * * Basically this is a base26 (A-Z) to base10 (0-9) conversion. * It iterates through all characters in the column name and * calculates the corresponding value, based on character value * (A = 1, ..., Z = 26) and position in the string. * * @param string $name column name(i.e. "A", or "BC", etc.) * * @return int The column number * @access public */ function PMA_getColumnNumberFromName($name) { if (empty($name)) { return 0; } $name = mb_strtoupper($name); $num_chars = mb_strlen($name); $column_number = 0; for ($i = 0; $i < $num_chars; ++$i) { // read string from back to front $char_pos = $num_chars - 1 - $i; // convert capital character to ASCII value // and subtract 64 to get corresponding decimal value // ASCII value of "A" is 65, "B" is 66, etc. // Decimal equivalent of "A" is 1, "B" is 2, etc. $number = (int) (mb_ord($name[$char_pos]) - 64); // base26 to base10 conversion : multiply each number // with corresponding value of the position, in this case // $i=0 : 1; $i=1 : 26; $i=2 : 676; ... $column_number += $number * PMA_Util::pow(26, $i); } return $column_number; }
if (isset($_REQUEST['type'])) { if ($_REQUEST['type'] === 'getval') { // Send with correct charset header('Content-Type: text/html; charset=UTF-8'); $varValue = PMA_DBI_fetch_single_row('SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA_Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM'); if (isset($VARIABLE_DOC_LINKS[$_REQUEST['varName']][3]) && $VARIABLE_DOC_LINKS[$_REQUEST['varName']][3] == 'byte') { $response->addJSON('message', implode(' ', PMA_Util::formatByteDown($varValue[1], 3, 3))); } else { $response->addJSON('message', $varValue[1]); } } else { if ($_REQUEST['type'] === 'setval') { $value = $_REQUEST['varValue']; if (isset($VARIABLE_DOC_LINKS[$_REQUEST['varName']][3]) && $VARIABLE_DOC_LINKS[$_REQUEST['varName']][3] == 'byte' && preg_match('/^\\s*(\\d+(\\.\\d+)?)\\s*(mb|kb|mib|kib|gb|gib)\\s*$/i', $value, $matches)) { $exp = array('kb' => 1, 'kib' => 1, 'mb' => 2, 'mib' => 2, 'gb' => 3, 'gib' => 3); $value = floatval($matches[1]) * PMA_Util::pow(1024, $exp[strtolower($matches[3])]); } else { $value = PMA_Util::sqlAddSlashes($value); } if (!is_numeric($value)) { $value = "'" . $value . "'"; } if (!preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) && PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value)) { // Some values are rounded down etc. $varValue = PMA_DBI_fetch_single_row('SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA_Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM'); $response->addJSON('variable', formatVariable($_REQUEST['varName'], $varValue[1])); } else { $response->isSuccess(false); $response->addJSON('error', __('Setting variable failed')); } }