X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=convert%2Fconvert.php;h=57ce6ea83012420939c0d8734e4f753a5cc94afe;hb=d9c54193518678408093f21101b1bcc1c5796d57;hp=751316503366b944c8498c4dbc532863fa8c400c;hpb=5360f08f4295f2306d815a7659fbdff94fda01a3;p=friendica-addons.git diff --git a/convert/convert.php b/convert/convert.php index 75131650..57ce6ea8 100644 --- a/convert/convert.php +++ b/convert/convert.php @@ -1,228 +1,219 @@ - - */ - -function convert_install() { - register_hook('app_menu', 'addon/convert/convert.php', 'convert_app_menu'); -} - -function convert_uninstall() { - unregister_hook('app_menu', 'addon/convert/convert.php', 'convert_app_menu'); -} - -function convert_app_menu($a,&$b) { - $b['app_menu'][] = '
'; -} - - -function convert_module() {} - - - - - - - -function convert_content($app) { - -include("UnitConvertor.php"); - - class TP_Converter extends UnitConvertor { - function TP_Converter($lang = "en") - { - if ($lang != 'en' ) { - $dec_point = '.'; $thousand_sep = "'"; - } else { - $dec_point = '.'; $thousand_sep = ","; - } - - $this->UnitConvertor($dec_point , $thousand_sep ); - - } // end func UnitConvertor - - 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 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; - $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 ['class'] = ($val == $from_unit || $val == $to_unit) ? "framedred": ""; - $cells[] = $cell; - } - - $cc = count($cells); - $string = "$value $from_unit | "; - $i=0; - foreach ($cells as $cell) { - if ($i==0) { - $string .= "".$cell['value']." | "; - $i++; - } else { - $string .= "
".$cell['value']." | "; - } - } - $string .= "
Select:
"; - } - - if(isset($_POST['value'])) - $value = $_POST['value']; - else - $value = ''; - - $o .= ''; - - return $o; -} + + */ + +use Friendica\App; +use Friendica\Core\Hook; + +function convert_install() { + Hook::register('app_menu', 'addon/convert/convert.php', 'convert_app_menu'); +} + +function convert_app_menu(array &$b) +{ + $b['app_menu'][] = ''; +} + + +function convert_module() {} + +function convert_content() { + // @TODO UnitConverter uses a deprecated constructor with the class' name + // @TODO Let's one day rewrite this to a modern composer package + include 'UnitConvertor.php'; + + class TP_Converter extends UnitConvertor + { + public function __construct(string $lang = 'en') + { + if ($lang == 'en' ) { + $dec_point = '.'; + $thousand_sep = ','; + } else { + $dec_point = '.'; + $thousand_sep = "'"; + } + + parent::UnitConvertor($dec_point, $thousand_sep ); + } + + private function findBaseUnit($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 false; + } + + public function getTable(int $value, $from_unit, $to_unit, $precision): string + { + $string = ''; + + if ($base_unit = $this->findBaseUnit($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; + $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 ['class'] = ($val == $from_unit || $val == $to_unit) ? 'framedred' : ''; + $cells[] = $cell; + } + + $cc = count($cells); + $string = "$value $from_unit | "; + $i = 0; + foreach ($cells as $cell) { + if ($i == 0) { + $string .= "" . $cell['value'] . " | "; + $i++; + } else { + $string .= "
" . $cell['value'] . " | "; + } + } + $string .= "
Select:
'; + } + + if (isset($_POST['value'])) { + $value = $_POST['value']; + } else { + $value = ''; + } + + $o .= ''; + + return $o; +}