本文整理汇总了PHP中pow函数的典型用法代码示例。如果您正苦于以下问题:PHP pow函数的具体用法?PHP pow怎么用?PHP pow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pow函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: humanReadableBytes
/**
* Get human readable file size, quick and dirty.
*
* @todo Improve i18n support.
*
* @param int $bytes
* @param string $format
* @param int|null $decimal_places
* @return string Human readable string with file size.
*/
public static function humanReadableBytes($bytes, $format = "en", $decimal_places = null)
{
switch ($format) {
case "sv":
$dec_separator = ",";
$thousands_separator = " ";
break;
default:
case "en":
$dec_separator = ".";
$thousands_separator = ",";
break;
}
$b = (int) $bytes;
$s = array('B', 'kB', 'MB', 'GB', 'TB');
if ($b <= 0) {
return "0 " . $s[0];
}
$con = 1024;
$e = (int) log($b, $con);
$e = min($e, count($s) - 1);
$v = $b / pow($con, $e);
if ($decimal_places === null) {
$decimal_places = max(0, 2 - (int) log($v, 10));
}
return number_format($v, !$e ? 0 : $decimal_places, $dec_separator, $thousands_separator) . ' ' . $s[$e];
}
开发者ID:varvanin,项目名称:currycms,代码行数:37,代码来源:Util.php
示例2: calculateGFRResult
function calculateGFRResult()
{
$tmpArr = array();
$tmpArr[] = date('Y-m-d H:i:s');
//observation time
$tmpArr[] = 'GFR (CALC)';
//desc
$gender = NSDR::populate($this->_patientId . "::com.clearhealth.person.displayGender");
$crea = NSDR::populate($this->_patientId . "::com.clearhealth.labResults[populate(@description=CREA)]");
$genderFactor = null;
$creaValue = null;
$personAge = null;
$raceFactor = 1;
switch ($gender[key($gender)]) {
case 'M':
$genderFactor = 1;
break;
case 'F':
$genderFactor = 0.742;
break;
}
if ((int) strtotime($crea['observation_time']) >= strtotime('now - 60 days') && strtolower($crea[key($crea)]['units']) == 'mg/dl') {
$creaValue = $crea[key($crea)]['value'];
}
$person = new Person();
$person->personId = $this->_patientId;
$person->populate();
if ($person->age > 0) {
$personAge = $person->age;
}
$personStat = new PatientStatistics();
$personStat->personId = $this->_patientId;
$personStat->populate();
if ($personStat->race == "AFAM") {
$raceFactor = 1.21;
}
$gfrValue = "INC";
if ($personAge > 0 && $creaValue > 0) {
$gfrValue = "" . (int) round(pow($creaValue, -1.154) * pow($personAge, -0.203) * $genderFactor * $raceFactor * 186);
}
trigger_error("gfr:: " . $gfrValue, E_USER_NOTICE);
$tmpArr[] = $gfrValue;
// lab value
$tmpArr[] = 'mL/min/1.73 m2';
//units
$tmpArr[] = '';
//ref range
$tmpArr[] = '';
//abnormal
$tmpArr[] = 'F';
//status
$tmpArr[] = date('Y-m-d H:i:s') . '::' . '0';
// observationTime::(boolean)normal; 0 = abnormal, 1 = normal
$tmpArr[] = '0';
//sign
//$this->_calcLabResults[uniqid()] = $tmpArr;
$this->_calcLabResults[1] = $tmpArr;
// temporarily set index to one(1) to be able to include in selected lab results
return $tmpArr;
}
开发者ID:dragonlet,项目名称:clearhealth,代码行数:60,代码来源:CalcLabs.php
示例3: PMA_pow
/**
* Exponential expression / raise number into power
*
* @param string $base base to raise
* @param string $exp exponent to use
* @param mixed $use_function pow function to use, or false for auto-detect
*
* @return mixed string or float
*/
function PMA_pow($base, $exp, $use_function = false)
{
static $pow_function = null;
if (null == $pow_function) {
$pow_function = PMA_detect_pow();
}
if (!$use_function) {
$use_function = $pow_function;
}
if ($exp < 0 && 'pow' != $use_function) {
return false;
}
switch ($use_function) {
case 'bcpow':
// bcscale() needed for testing PMA_pow() with base values < 1
bcscale(10);
$pow = bcpow($base, $exp);
break;
case 'gmp_pow':
$pow = gmp_strval(gmp_pow($base, $exp));
break;
case 'pow':
$base = (double) $base;
$exp = (int) $exp;
$pow = pow($base, $exp);
break;
default:
$pow = $use_function($base, $exp);
}
return $pow;
}
开发者ID:AmberWish,项目名称:laba_web,代码行数:40,代码来源:common.lib.php
示例4: stdev
function stdev(Array $x) {
$n = count($x);
if($n == 0 || ($n - 1) == 0) return null;
$sum = sum($x);
$sumSq = sum_sq($x);
return sqrt(($sumSq - (pow($sum, 2)/$n))/($n - 1));
}
开发者ID:revned,项目名称:orangephp,代码行数:7,代码来源:Helpers.php
示例5: main
function main($num)
{
if ($num < 0) {
$s = 1;
$num = -$num;
} else {
$s = 0;
}
$zs = floor($num);
$bzs = decbin($zs);
$xs = $num - $zs;
$res = (double) ($bzs . '.' . tenToBinary($xs, 1));
$teme = ws($res);
$e = decbin($teme + 127);
if ($teme == 0) {
$e = '0' . $e;
}
$temm = $res / pow(10, $teme);
$m = end(explode(".", $temm));
$lenm = strlen($m);
if ($lenm < 23) {
$m .= addzero(23 - $lenm);
}
return $s . ' ' . $e . ' ' . $m . ' ';
}
开发者ID:echosoar,项目名称:phpBinary,代码行数:25,代码来源:floatToIEEE32.php
示例6: postContent
function postContent()
{
if (!($user = \Idno\Core\site()->session()->currentUser())) {
$this->setResponse(403);
echo 'You must be logged in to approve IndieAuth requests.';
exit;
}
$me = $this->getInput('me');
$client_id = $this->getInput('client_id');
$redirect_uri = $this->getInput('redirect_uri');
$state = $this->getInput('state');
$scope = $this->getInput('scope');
if (!empty($me) && parse_url($me, PHP_URL_HOST) == parse_url($user->getURL(), PHP_URL_HOST)) {
$indieauth_codes = $user->indieauth_codes;
if (empty($indieauth_codes)) {
$indieauth_codes = array();
}
$code = md5(rand(0, 99999) . time() . $user->getUUID() . $client_id . $state . rand(0, 999999));
$indieauth_codes[$code] = array('me' => $me, 'redirect_uri' => $redirect_uri, 'scope' => $scope, 'state' => $state, 'client_id' => $client_id, 'issued_at' => time(), 'nonce' => mt_rand(1000000, pow(2, 30)));
$user->indieauth_codes = $indieauth_codes;
$user->save();
if (strpos($redirect_uri, '?') === false) {
$redirect_uri .= '?';
} else {
$redirect_uri .= '&';
}
$redirect_uri .= http_build_query(array('code' => $code, 'state' => $state, 'me' => $me));
$this->forward($redirect_uri);
}
}
开发者ID:pierreozoux,项目名称:Known,代码行数:30,代码来源:Approve.php
示例7: Correlation
function Correlation($array1, $array2)
{
$avg_array1 = average($array1);
$avg_array2 = average($array2);
#print "$avg_array1----- $avg_array2<br>";
$sum_correlation_up = 0;
for ($i = 0; $i < count($array1); $i++) {
$sum_correlation_up = $sum_correlation_up + ($array1[$i] - $avg_array1) * ($array2[$i] - $avg_array2);
}
#print $sum_correlation_up."<br>";
$sum_array1_sumpow2 = 0;
for ($i = 0; $i < count($array1); $i++) {
$sum_array1_sumpow2 = $sum_array1_sumpow2 + pow($array1[$i] - $avg_array1, 2);
}
$sum_array1_sumpow2_sqrt = sqrt($sum_array1_sumpow2);
#rint $sum_array1_sumpow2_sqrt."<br>";
$sum_array2_sumpow2 = 0;
for ($i = 0; $i < count($array1); $i++) {
$sum_array2_sumpow2 = $sum_array2_sumpow2 + pow($array2[$i] - $avg_array2, 2);
}
$sum_array2_sumpow2_sqrt = sqrt($sum_array2_sumpow2);
#print $sum_array2_sumpow2_sqrt."<br>";
$correlation = $sum_correlation_up / ($sum_array1_sumpow2_sqrt * $sum_array2_sumpow2_sqrt);
return $correlation;
}
开发者ID:jluzhhy,项目名称:Cross-microrna,代码行数:25,代码来源:NC_statistic.php
示例8: execute
/**
* {@inheritDoc}
*
* @param Convert $request
*/
public function execute($request)
{
RequestNotSupportedException::assertSupports($this, $request);
/** @var PaymentInterface $payment */
$payment = $request->getSource();
$model = ArrayObject::ensureArrayObject($payment->getDetails());
//$model['DESCRIPTION'] = $payment->getDescription();
if (false == $model['amount']) {
$this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode()));
if (2 < $currency->exp) {
throw new RuntimeException('Unexpected currency exp.');
}
$divisor = pow(10, 2 - $currency->exp);
$model['currency_code'] = $currency->numeric;
$model['amount'] = abs($payment->getTotalAmount() / $divisor);
}
if (false == $model['order_id']) {
$model['order_id'] = $payment->getNumber();
}
if (false == $model['customer_id']) {
$model['customer_id'] = $payment->getClientId();
}
if (false == $model['customer_email']) {
$model['customer_email'] = $payment->getClientEmail();
}
$request->setResult((array) $model);
}
开发者ID:ekyna,项目名称:PayumSips,代码行数:32,代码来源:ConvertPaymentAction.php
示例9: fiat_and_btc_to_price
function fiat_and_btc_to_price($fiat, $btc, $round = 'round')
{
$fiat = gmp_strval($fiat);
$btc = gmp_strval($btc);
if (gmp_cmp($btc, "0") == 0) {
return "";
} else {
if ($round == 'round') {
$price = bcdiv($fiat, $btc, PRICE_PRECISION + 1);
return sprintf("%." . PRICE_PRECISION . "f", $price);
} else {
if ($round == 'down') {
$price = bcdiv($fiat, $btc, PRICE_PRECISION);
// echo "rounding $fiat / $btc = " . bcdiv($fiat, $btc, 8) . " down to $price<br/>\n";
return $price;
} else {
if ($round == 'up') {
$raw = bcdiv($fiat, $btc, 8);
$adjust = bcsub(bcdiv(1, pow(10, PRICE_PRECISION), 8), '0.00000001', 8);
$price = bcadd($raw, $adjust, PRICE_PRECISION);
// echo "rounding $fiat / $btc = $raw up to $price<br/>\n";
return $price;
} else {
throw new Error("Bad Argument", "fiat_and_btc_to_price() has round = '{$round}'");
}
}
}
}
}
开发者ID:martinkirov,项目名称:intersango,代码行数:29,代码来源:util.php
示例10: getGIFHeaderFilepointer
function getGIFHeaderFilepointer(&$fd, &$ThisFileInfo)
{
$ThisFileInfo['fileformat'] = 'gif';
$ThisFileInfo['video']['dataformat'] = 'gif';
$ThisFileInfo['video']['lossless'] = true;
fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
$GIFheader = fread($fd, 13);
$offset = 0;
$ThisFileInfo['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3);
$offset += 3;
$ThisFileInfo['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3);
$offset += 3;
$ThisFileInfo['gif']['header']['raw']['width'] = LittleEndian2Int(substr($GIFheader, $offset, 2));
$offset += 2;
$ThisFileInfo['gif']['header']['raw']['height'] = LittleEndian2Int(substr($GIFheader, $offset, 2));
$offset += 2;
$ThisFileInfo['gif']['header']['raw']['flags'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
$offset += 1;
$ThisFileInfo['gif']['header']['raw']['bg_color_index'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
$offset += 1;
$ThisFileInfo['gif']['header']['raw']['aspect_ratio'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
$offset += 1;
$ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['gif']['header']['raw']['width'];
$ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['gif']['header']['raw']['height'];
$ThisFileInfo['gif']['version'] = $ThisFileInfo['gif']['header']['raw']['version'];
$ThisFileInfo['gif']['header']['flags']['global_color_table'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80);
if ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80) {
// Number of bits per primary color available to the original image, minus 1
$ThisFileInfo['gif']['header']['bits_per_pixel'] = 3 * ((($ThisFileInfo['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
} else {
$ThisFileInfo['gif']['header']['bits_per_pixel'] = 0;
}
$ThisFileInfo['gif']['header']['flags']['global_color_sorted'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x40);
if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
// the number of bytes contained in the Global Color Table. To determine that
// actual size of the color table, raise 2 to [the value of the field + 1]
$ThisFileInfo['gif']['header']['global_color_size'] = pow(2, ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x7) + 1);
$ThisFileInfo['video']['bits_per_sample'] = ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x7) + 1;
} else {
$ThisFileInfo['gif']['header']['global_color_size'] = 0;
}
if ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] != 0) {
// Aspect Ratio = (Pixel Aspect Ratio + 15) / 64
$ThisFileInfo['gif']['header']['aspect_ratio'] = ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
}
if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
$GIFcolorTable = fread($fd, 3 * $ThisFileInfo['gif']['header']['global_color_size']);
$offset = 0;
for ($i = 0; $i < $ThisFileInfo['gif']['header']['global_color_size']; $i++) {
//$ThisFileInfo['gif']['global_color_table']['red'][$i] = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
//$ThisFileInfo['gif']['global_color_table']['green'][$i] = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
//$ThisFileInfo['gif']['global_color_table']['blue'][$i] = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
$red = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
$green = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
$blue = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
$ThisFileInfo['gif']['global_color_table'][$i] = $red << 16 | $green << 8 | $blue;
}
}
return true;
}
开发者ID:BackupTheBerlios,项目名称:sotf,代码行数:60,代码来源:getid3.gif.php
示例11: round_up
function round_up($value, $places)
{
$mult = pow(10, abs($places));
return $places < 0 ?
ceil($value / $mult) * $mult :
ceil($value * $mult) / $mult;
}
开发者ID:sarankh80,项目名称:lnms,代码行数:7,代码来源:DbLoanILtest.php
示例12: hexTo32Float
function hexTo32Float($strHex)
{
$v = hexdec($strHex);
$x = ($v & (1 << 23) - 1) + (1 << 23) * ($v >> 31 | 1);
$exp = ($v >> 23 & 0xff) - 127;
return $x * pow(2, $exp - 23);
}
开发者ID:RawLiquid,项目名称:Data_Logger,代码行数:7,代码来源:test.php
示例13: display
function display()
{
global $mod_strings, $export_module, $current_language, $theme, $current_user, $dashletData, $sugar_flavor;
if ($this->checkPostMaxSizeError()) {
$this->errors[] = $GLOBALS['app_strings']['UPLOAD_ERROR_HOME_TEXT'];
$contentLength = $_SERVER['CONTENT_LENGTH'];
$maxPostSize = ini_get('post_max_size');
if (stripos($maxPostSize, "k")) {
$maxPostSize = (int) $maxPostSize * pow(2, 10);
} elseif (stripos($maxPostSize, "m")) {
$maxPostSize = (int) $maxPostSize * pow(2, 20);
}
$maxUploadSize = ini_get('upload_max_filesize');
if (stripos($maxUploadSize, "k")) {
$maxUploadSize = (int) $maxUploadSize * pow(2, 10);
} elseif (stripos($maxUploadSize, "m")) {
$maxUploadSize = (int) $maxUploadSize * pow(2, 20);
}
$max_size = min($maxPostSize, $maxUploadSize);
$errMessage = string_format($GLOBALS['app_strings']['UPLOAD_MAXIMUM_EXCEEDED'], array($contentLength, $max_size));
$this->errors[] = '* ' . $errMessage;
$this->displayErrors();
}
include 'modules/Home/index.php';
}
开发者ID:omusico,项目名称:sugar_work,代码行数:25,代码来源:view.list.php
示例14: testByteBoundaryDecimalVarint
/**
* Ensure Decimal/Varint encoding on byte boundaries
*
* This test will ensure that the PHP driver is properly encoding Decimal
* and Varint datatypes for positive values with leading 1's that land on
* a byte boundary.
*
* @test
* @ticket PHP-70
*/
public function testByteBoundaryDecimalVarint()
{
// Create the table
$query = "CREATE TABLE {$this->tableNamePrefix} (key timeuuid PRIMARY KEY, value_decimal decimal, value_varint varint)";
$this->session->execute(new SimpleStatement($query));
// Iterate through a few byte boundary positive values
foreach (range(1, 20) as $i) {
// Assign the values for the statement
$key = new Timeuuid();
$value_varint = pow(2, 8 * $i) - 1;
$value_decimal = $value_varint / 100;
$values = array($key, new Decimal($value_decimal), new Varint($value_varint));
// Insert the value into the table
$query = "INSERT INTO {$this->tableNamePrefix} (key, value_decimal, value_varint) VALUES (?, ?, ?)";
$statement = new SimpleStatement($query);
$options = new ExecutionOptions(array("arguments" => $values));
$this->session->execute($statement, $options);
// Select the decimal and varint
$query = "SELECT value_decimal, value_varint FROM {$this->tableNamePrefix} WHERE key=?";
$statement = new SimpleStatement($query);
$options = new ExecutionOptions(array("arguments" => array($key)));
$rows = $this->session->execute($statement, $options);
// Ensure the decimal and varint are valid
$this->assertCount(1, $rows);
$row = $rows->first();
$this->assertNotNull($row);
$this->assertArrayHasKey("value_decimal", $row);
$this->assertEquals($values[1], $row["value_decimal"]);
$this->assertArrayHasKey("value_varint", $row);
$this->assertEquals($values[2], $row["value_varint"]);
}
}
开发者ID:harley84,项目名称:php-driver,代码行数:42,代码来源:DatatypeIntegrationTest.php
示例15: fileSize
/**
* Format a filesize
*
* @param int $size In bytes
* @return string
*/
public function fileSize($size)
{
if (!$size) {
return '0 ' . $this->_sizes[0];
}
return round($size / pow(1024, $i = floor(log($size, 1024))), $i > 1 ? 2 : 0) . ' ' . $this->_sizes[$i];
}
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:13,代码来源:FileSize.php
示例16: AwardForCapture
function AwardForCapture($specsOwned, $mugsOwned, $sausageRollsOwned)
{
$owned = $specsOwned * $mugsOwned * $sausageRollsOwned;
$ownedValue = pow($owned, 2);
$awardForCapture = 10 * $ownedValue / 2;
return $awardForCapture;
}
开发者ID:GuthrieS,项目名称:AzureTest,代码行数:7,代码来源:index.php
示例17: aff_romain
function aff_romain($param)
{
$nombre_arab = $param[0];
$nb_b10 = array('I', 'X', 'C', 'M');
$nb_b5 = array('V', 'L', 'D');
$nbrom = '';
$nombre = $nombre_arab;
if ($nombre >= 0 && $nombre < 4000) {
for ($i = 3; $i >= 0; $i--) {
$chiffre = floor($nombre / pow(10, $i));
if ($chiffre >= 1) {
$nombre = $nombre - $chiffre * pow(10, $i);
if ($chiffre <= 3) {
for ($j = $chiffre; $j >= 1; $j--) {
$nbrom = $nbrom . $nb_b10[$i];
}
} elseif ($chiffre == 9) {
$nbrom = $nbrom . $nb_b10[$i] . $nb_b10[$i + 1];
} elseif ($chiffre == 4) {
$nbrom = $nbrom . $nb_b10[$i] . $nb_b5[$i];
} else {
$nbrom = $nbrom . $nb_b5[$i];
for ($j = $chiffre - 5; $j >= 1; $j--) {
$nbrom = $nbrom . $nb_b10[$i];
}
}
}
}
} else {
//Valeur Hors Limite;
return $nombre_arab;
}
return $nbrom;
}
开发者ID:noble82,项目名称:proyectos-ULS,代码行数:34,代码来源:interpreter.inc.php
示例18: _calculateNextRunAt
protected function _calculateNextRunAt()
{
$attempts = $this->getAttempts();
$expMinutes = pow(2, $attempts);
$nextRun = date("Y-m-d H:i:s", strtotime("+{$expMinutes} minutes"));
return $nextRun;
}
开发者ID:springbot,项目名称:magento2-queue,代码行数:7,代码来源:Job.php
示例19: _sierpinsky
protected function _sierpinsky()
{
$newPolygones = array();
$proceededLines = array();
foreach ($this->_virtualPolygon as $points) {
$lines = array(array(min($points[0], $points[1]), max($points[0], $points[1])), array(min($points[1], $points[2]), max($points[1], $points[2])), array(min($points[2], $points[0]), max($points[2], $points[0])));
$new = array();
foreach ($lines as $line) {
if (!isset($proceededLines[$line[0]][$line[1]])) {
// Calculate new point
$newX = ($this->_points[$line[0]]->getX() + $this->_points[$line[1]]->getX()) / 2;
$newY = ($this->_points[$line[0]]->getY() + $this->_points[$line[1]]->getY()) / 2;
$newZ = ($this->_points[$line[0]]->getZ() + $this->_points[$line[1]]->getZ()) / 2;
$multiplikator = $this->_radius / sqrt(pow($newX, 2) + pow($newY, 2) + pow($newZ, 2));
$this->_points[] = new Image_3D_Point($newX * $multiplikator, $newY * $multiplikator, $newZ * $multiplikator);
$proceededLines[$line[0]][$line[1]] = count($this->_points) - 1;
}
$new[] = $proceededLines[$line[0]][$line[1]];
}
$newPolygones[] = array($points[0], $new[0], $new[2]);
$newPolygones[] = array($points[1], $new[1], $new[0]);
$newPolygones[] = array($points[2], $new[2], $new[1]);
$newPolygones[] = array($new[0], $new[1], $new[2]);
}
$this->_virtualPolygon = $newPolygones;
}
开发者ID:ricberw,项目名称:BotQueue,代码行数:26,代码来源:Sphere.php
示例20: make_apps_url
private static function make_apps_url($url)
{
$httpstr = is_https() ? 'https' : 'http';
if (preg_match('#//goo\\.gl/#', $url)) {
$results = mahara_shorturl_request($url);
$url = $results->fullurl;
}
$embedsources = array(array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)leaf\\?id=([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://docs.google.com/$1leaf?id=$2', 'type' => 'spanicon'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)open\\?id=([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://docs.google.com/$1open?id=$2', 'type' => 'spanicon'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)present([a-z]*)/([a-z]+).*?id=([a-zA-Z0-9\\_\\-\\&\\=]+).*#', 'url' => $httpstr . '://docs.google.com/$1present$2/embed?id=$4', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)presentation/([a-zA-Z0-9\\_\\-\\/]+)/([a-z]+)\\?([a-zA-Z0-9\\_\\-\\&\\=]*).*#', 'url' => $httpstr . '://docs.google.com/$1presentation/$2/embed?$4', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)drawings.*id=([a-zA-Z0-9\\_\\-\\&\\=]+).*#', 'url' => $httpstr . '://docs.google.com/$1drawings/pub?id=$2', 'type' => 'image'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)drawings/([a-zA-Z0-9\\_\\-\\/]+)/([a-z]+)\\?([a-zA-Z0-9\\_\\-\\&\\=]*).*#', 'url' => $httpstr . '://docs.google.com/$1drawings/$2/$3?$4', 'type' => 'image'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)View.*id=([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://docs.google.com/$1View?id=$2', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)viewer.*srcid=([a-zA-Z0-9\\_\\-\\&\\=]+).*#', 'url' => $httpstr . '://docs.google.com/$1viewer?srcid=$2', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)document/([a-zA-Z0-9\\_\\-\\/]+)/pub.*#', 'url' => $httpstr . '://docs.google.com/$1document/$2/pub?embedded=true', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)file/([a-zA-Z0-9\\_\\-\\/]+)/([a-z]+).*#', 'url' => $httpstr . '://docs.google.com/$1file/$2/preview', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)viewer.*url=http([a-zA-Z0-9\\.\\,\\;\\_\\-\\&\\%\\=\\+/\\:]+)\\.(pdf|tif|tiff|ppt|doc|docx).*#', 'url' => $httpstr . '://docs.google.com/$1viewer?url=http$2.$3&embedded=true', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)document/pub.*id=([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://docs.google.com/$1document/pub?id=$2', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)document/d/([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://docs.google.com/$1document/d/$2/pub?embedded=true', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)spreadsheets/d/([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://docs.google.com/$1spreadsheets/d/$2/pub?embedded=true', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)spreadsheet/.*key=([a-zA-Z0-9\\_\\-]+)([a-zA-Z0-9\\_\\-\\&\\=]*).*#', 'url' => $httpstr . '://docs.google.com/$1spreadsheet/pub?key=$2$3&widget=true', 'type' => 'iframe'), array('match' => '#.*docs.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)forms/([a-zA-Z0-9\\_\\-\\.\\/]*)/viewform\\?embedded=true.*#', 'url' => $httpstr . '://docs.google.com/$1forms/$2/viewform?embedded=true', 'type' => 'iframe'), array('match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)viewform.*formkey=([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://spreadsheets.google.com/$1embeddedform?formkey=$2', 'type' => 'iframe'), array('match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)embeddedform.*formkey=([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://spreadsheets.google.com/$1embeddedform?formkey=$2', 'type' => 'iframe'), array('match' => '#.*spreadsheets[0-9]?.google.com/([a-zA-Z0-9\\_\\-\\.\\/]*)pub.*key=([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://spreadsheets.google.com/$1pub?key=$2', 'type' => 'iframe'), array('match' => '#.*drive.google.com/.*file/d/([a-zA-Z0-9\\_\\-]+).*#', 'url' => $httpstr . '://docs.google.com/file/d/$1/preview', 'type' => 'iframe'), array('match' => '#.*www.google.com/calendar.*src=([a-zA-Z0-9\\.\\_\\-\\&\\%\\=/]+).*#', 'url' => $httpstr . '://www.google.com/calendar/embed?src=$1', 'type' => 'iframe'), array('match' => '#.*google.[^/]*/maps/ms\\?([a-zA-Z0-9\\.\\,\\;\\_\\-\\&\\%\\=\\+/]+).*#', 'url' => $httpstr . '://maps.google.com/maps/ms?$1&output=embed', 'type' => 'iframe'), array('match' => '#.*maps.google.[^/]*/(maps)?\\?([a-zA-Z0-9\\.\\,\\;\\_\\-\\&\\%\\=\\+/]+).*#', 'url' => $httpstr . '://maps.google.com/maps?$2&output=embed', 'type' => 'iframe'), array('match' => '#.*google.[^/]*/maps/place/([^/]+)/@([0-9\\-\\.]+),([0-9\\-\\.]+),([0-9]+)z/data=.+!1s([0-9xa-f]+):([0-9xa-f]+).*#', 'url' => function ($m) {
$zoomlevel = min(max($m[4], 3), 21);
$height = 188 * pow(2, 21 - $zoomlevel);
return "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d{$height}!2d{$m[3]}!3d{$m[2]}!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s{$m[5]}%3A{$m[6]}!2s{$m[1]}!5e0";
}, 'type' => 'iframe'), array('match' => '#.*mapsengine.google.com[^/]*/map/[^?]*\\?([a-zA-Z0-9\\.\\,\\;\\_\\-\\&\\%\\=\\+\\?/]+).*#', 'url' => $httpstr . '://mapsengine.google.com/map/embed?$1', 'type' => 'iframe'), array('match' => '#.*www.google.com[^/]*/maps\\?([a-zA-Z0-9\\.\\,\\;\\_\\-\\&\\%\\=\\+\\!/]+).*#', 'url' => $httpstr . '://www.google.com/maps?$1&output=embed', 'type' => 'iframe'), array('match' => '#.*www.google.com[^/]*/maps/embed\\?([a-zA-Z0-9\\.\\,\\;\\_\\-\\&\\%\\=\\+\\!/]+).*#', 'url' => 'https://www.google.com/maps/embed?$1', 'type' => 'iframe'), array('match' => '#.*www.google.com.*?/\\@([a-zA-Z0-9\\.\\-]+)\\,([a-zA-Z0-9\\.\\-]+)\\,([0-9]+).*#', 'url' => 'https://maps.google.com/maps?ll=$1,$2&z=$3&output=embed', 'type' => 'iframe'), array('match' => '#.*books.google.[^/]*/books.*id=([a-zA-Z0-9\\_\\-\\&\\%\\=]+).*#', 'url' => 'http://books.google.com/books?id=$1', 'type' => 'iframe'), array('match' => '#http([a-zA-Z0-9\\.\\,\\;\\_\\-\\&\\%\\=\\+/\\:]+)\\.(pdf|tif|tiff|ppt|doc|docx)#', 'url' => $httpstr . '://docs.google.com/gview?url=http$1.$2&embedded=true', 'type' => 'iframe'));
foreach ($embedsources as $source) {
$url = htmlspecialchars_decode($url);
// convert & back to &, etc.
if (preg_match($source['match'], $url)) {
if (is_string($source['url'])) {
$apps_url = preg_replace($source['match'], $source['url'], $url);
} else {
if (is_callable($source['url'])) {
$apps_url = preg_replace_callback($source['match'], $source['url'], $url);
}
}
// For correctly embed Google maps...
$apps_url = str_replace('source=embed', 'output=embed', $apps_url);
$apps_type = $source['type'];
return array('url' => $apps_url, 'type' => $apps_type);
}
}
// if we reach here then mahara does not understand the url
return array('url' => $url, 'type' => false);
}
开发者ID:rboyatt,项目名称:mahara,代码行数:32,代码来源:lib.php
注:本文中的pow函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论