X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=convert%2Fconvert.php;h=e95637418454c552e89343f96cf3d03646d4cdda;hb=005b42237df3e52679743fde45a32a45c3416495;hp=751316503366b944c8498c4dbc532863fa8c400c;hpb=858758e92c5d8c1c41e188284fea53ae50fb0855;p=friendica-addons.git diff --git a/convert/convert.php b/convert/convert.php old mode 100755 new mode 100644 index 75131650..e9563741 --- a/convert/convert.php +++ b/convert/convert.php @@ -5,17 +5,18 @@ * Version: 1.0 * Author: Mike Macgirvin */ +use Friendica\Core\Hook; function convert_install() { - register_hook('app_menu', 'addon/convert/convert.php', 'convert_app_menu'); + Hook::register('app_menu', 'addon/convert/convert.php', 'convert_app_menu'); } function convert_uninstall() { - unregister_hook('app_menu', 'addon/convert/convert.php', 'convert_app_menu'); + Hook::unregister('app_menu', 'addon/convert/convert.php', 'convert_app_menu'); } function convert_app_menu($a,&$b) { - $b['app_menu'][] = '
Units Conversion
'; + $b['app_menu'][] = '
Units Conversion
'; } @@ -30,7 +31,7 @@ function convert_module() {} function convert_content($app) { include("UnitConvertor.php"); - + class TP_Converter extends UnitConvertor { function TP_Converter($lang = "en") { @@ -39,7 +40,7 @@ include("UnitConvertor.php"); } else { $dec_point = '.'; $thousand_sep = ","; } - + $this->UnitConvertor($dec_point , $thousand_sep ); } // end func UnitConvertor @@ -47,24 +48,24 @@ include("UnitConvertor.php"); function find_base_unit($from,$to) { while (list($skey,$sval) = each($this->bases)) { if ($skey == $from || $to == $skey || in_array($to,$sval) || in_array($from,$sval)) { - return $skey; + return $skey; } } - return false; + return false; } function getTable($value, $from_unit, $to_unit, $precision) { - + if ($base_unit = $this->find_base_unit($from_unit,$to_unit)) { - - // A baseunit was found now lets convert from -> $base_unit - - $cell ['value'] = $this->convert($value, $from_unit, $base_unit, $precision)." ".$base_unit; + + // A baseunit was found now lets convert from -> $base_unit + + $cell ['value'] = $this->convert($value, $from_unit, $base_unit, $precision)." ".$base_unit; $cell ['class'] = ($base_unit == $from_unit || $base_unit == $to_unit) ? "framedred": ""; $cells[] = $cell; // We now have the base unit and value now lets produce the table; while (list($key,$val) = each($this->bases[$base_unit])) { - $cell ['value'] = $this->convert($value, $from_unit, $val, $precision)." ".$val; + $cell ['value'] = $this->convert($value, $from_unit, $val, $precision)." ".$val; $cell ['class'] = ($val == $from_unit || $val == $to_unit) ? "framedred": ""; $cells[] = $cell; } @@ -83,8 +84,8 @@ include("UnitConvertor.php"); } $string .= ""; return $string; - } - + } + } } @@ -92,16 +93,16 @@ include("UnitConvertor.php"); $conv = new TP_Converter('en'); -$conversions = array( - 'Temperature'=>array('base' =>'Celsius', - 'conv'=>array( - 'Fahrenheit'=>array('ratio'=>1.8, 'offset'=>32), - 'Kelvin'=>array('ratio'=>1, 'offset'=>273), +$conversions = [ + 'Temperature'=>['base' =>'Celsius', + 'conv'=>[ + 'Fahrenheit'=>['ratio'=>1.8, 'offset'=>32], + 'Kelvin'=>['ratio'=>1, 'offset'=>273], 'Reaumur'=>0.8 - ) - ), - 'Weight' => array('base' =>'kg', - 'conv'=>array( + ] + ], + 'Weight' => ['base' =>'kg', + 'conv'=>[ 'g'=>1000, 'mg'=>1000000, 't'=>0.001, @@ -109,13 +110,13 @@ $conversions = array( 'oz'=>35.274, 'lb'=>2.2046, 'cwt(UK)' => 0.019684, - 'cwt(US)' => 0.022046, + 'cwt(US)' => 0.022046, 'ton (US)' => 0.0011023, 'ton (UK)' => 0.0009842 - ) - ), - 'Distance' => array('base' =>'km', - 'conv'=>array( + ] + ], + 'Distance' => ['base' =>'km', + 'conv'=>[ 'm'=>1000, 'dm'=>10000, 'cm'=>100000, @@ -127,25 +128,25 @@ $conversions = array( 'yd'=>1093.6, 'furlong'=>4.970969537898672, 'fathom'=>546.8066491688539 - ) - ), - 'Area' => array('base' =>'km 2', - 'conv'=>array( + ] + ], + 'Area' => ['base' =>'km 2', + 'conv'=>[ 'ha'=>100, 'acre'=>247.105, 'm 2'=>pow(1000,2), 'dm 2'=>pow(10000,2), 'cm 2'=>pow(100000,2), - 'mm 2'=>pow(1000000,2), + 'mm 2'=>pow(1000000,2), 'mile 2'=>pow(0.62137,2), 'naut.miles 2'=>pow(0.53996,2), 'in 2'=>pow(39370,2), 'ft 2'=>pow(3280.8,2), 'yd 2'=>pow(1093.6,2), - ) - ), - 'Volume' => array('base' =>'m 3', - 'conv'=>array( + ] + ], + 'Volume' => ['base' =>'m 3', + 'conv'=>[ 'in 3'=>61023.6, 'ft 3'=>35.315, 'cm 3'=>pow(10,6), @@ -161,22 +162,22 @@ $conversions = array( 'fl oz' => 33814.02, 'tablespoon' => 67628.04, 'teaspoon' => 202884.1, - 'pt (UK)'=>1000/0.56826, + 'pt (UK)'=>1000/0.56826, 'barrel petroleum'=>1000/158.99, - 'Register Tons'=>2.832, + 'Register Tons'=>2.832, 'Ocean Tons'=>1.1327 - ) - ), - 'Speed' =>array('base' =>'kmph', - 'conv'=>array( + ] + ], + 'Speed' =>['base' =>'kmph', + 'conv'=>[ 'mps'=>0.0001726031, 'milesph'=>0.62137, 'knots'=>0.53996, 'mach STP'=>0.0008380431, 'c (warp)'=>9.265669e-10 - ) - ) -); + ] + ] +]; while (list($key,$val) = each($conversions)) { @@ -223,6 +224,6 @@ while (list($key,$val) = each($conversions)) { $o .= ''; $o .= ''; - + return $o; }