From b9f330fa18cfef487bc46bd3de71ca7c5c76c744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jun 2022 01:47:32 +0200 Subject: [PATCH 01/19] Changed: - removed discouraged ?> - changed double-quotes to single --- convert/UnitConvertor.php | 283 ------------------ convert/convert.php | 168 +++++------ diaspora/diasphp.php | 1 - leistungsschutzrecht/leistungsschutzrecht.php | 1 - libravatar/Services/Libravatar.php | 2 - statusnet/library/codebirdsn.php | 2 - webrtc/webrtc.php | 1 - 7 files changed, 78 insertions(+), 380 deletions(-) delete mode 100644 convert/UnitConvertor.php diff --git a/convert/UnitConvertor.php b/convert/UnitConvertor.php deleted file mode 100644 index d7933a8f..00000000 --- a/convert/UnitConvertor.php +++ /dev/null @@ -1,283 +0,0 @@ - | -// | Co-authored by : CVH, Chris Hansel | -// +----------------------------------------------------------------------+ -// -// $Id: UnitConvertor.php,v 1.00 2002/02/20 11:40:00 stasokhvat Exp $ - -/** -* UnitConvertor is able to convert between different units and currencies. -* -* @author Stanislav Okhvat -* @version $Id: UnitConvertor.php,v 1.00 2002/03/01 17:00:00 stasokhvat Exp $ -* @package UnitConvertor -* @access public -* @history 01.03.2002 Implemented the code for regular and offset-based -* conversions -* -* 13.12.2004 -* By Chris Hansel (CVH): changed getConvSpecs in order to have it look up -* intermediary conversions (also see comments in check_key). -* -* Intermediary conversions are useful when no conversion ratio is specified -* between two units when we calculate between the two. For example, we want -* to convert between Fahrenheit and Kelvin, and we have only -* specified how to convert Centigrade<->Fahrenheit and -* Centigrade<->Kelvin. While a direct (Fahrenheit->Kelvin) or -* reverse (Kelvin->Fahrenheit) lookups fail, looking for an intermediary -* unit linking the two (Centigrade) helps us do the conversion. -* -* 13.12.2004 -* Chris Hansel (CVH): $to_array argument of addConversion method can now -* contain units as 'unit1/unit2/unit3', when all units stand for the same -* thing. See examples in unitconv.php -*/ -class UnitConvertor -{ - /** - * Stores conversion ratios. - * - * @var array - * @access private - */ - var $conversion_table = array(); - - /** - * Decimal point character (default is "." - American - set in constructor). - * - * @var string - * @access private - */ - var $decimal_point; - - /** - * Thousands separator (default is "," - American - set in constructor). - * - * @var string - * @access private - */ - var $thousand_separator; - - /** - * For future use - * - * @var array - * @access private - */ - var $bases = array(); - - /** - * Constructor. Initializes the UnitConvertor object with the most important - * properties. - * - * @param string decimal point character - * @param string thousand separator character - * @return void - * @access public - */ - function UnitConvertor($dec_point = '.', $thousand_sep = ',') - { - $this->decimal_point = $dec_point; - $this->thousand_separator = $thousand_sep; - - } // end func UnitConvertor - - /** - * Adds a conversion ratio to the conversion table. - * - * @param string the name of unit from which to convert - * @param array array( - * "pound"=>array("ratio"=>'', "offset"=>'') - * ) - * "pound" - name of unit to set conversion ration to - * "ratio" - 'double' conversion ratio which, when - * multiplied by the number of $from_unit units produces - * the result - * "offset" - an offset from 0 which will be added to - * the result when converting (needed for temperature - * conversions and defaults to 0). - * @return boolean true if successful, false otherwise - * @access public - */ - function addConversion($from_unit, $to_array) - { - if (!isset($this->conversion_table[$from_unit])) { - while(list($key, $val) = each($to_array)) - { - if (strstr($key, '/')) - { - $to_units = explode('/', $key); - foreach ($to_units as $to_unit) - { - $this->bases[$from_unit][] = $to_unit; - - if (!is_array($val)) - { - $this->conversion_table[$from_unit."_".$to_unit] = array("ratio"=>$val, "offset"=>0); - } - else - { - $this->conversion_table[$from_unit."_".$to_unit] = - array( - "ratio"=>$val['ratio'], - "offset"=>(isset($val['offset']) ? $val['offset'] : 0) - ); - } - } - } - else - { - $this->bases[$from_unit][] = $key; - - if (!is_array($val)) - { - $this->conversion_table[$from_unit."_".$key] = array("ratio"=>$val, "offset"=>0); - } - else - { - $this->conversion_table[$from_unit."_".$key] = - array( - "ratio"=>$val['ratio'], - "offset"=>(isset($val['offset']) ? $val['offset'] : 0) - ); - } - } - } - return true; - } - return false; - - } // end func addConversion - - /** - * Converts from one unit to another using specified precision. - * - * @param double value to convert - * @param string name of the source unit from which to convert - * @param string name of the target unit to which we are converting - * @param integer double precision of the end result - * @return void - * @access public - */ - function convert($value, $from_unit, $to_unit, $precision) - { - if ($this->getConvSpecs($from_unit, $to_unit, $value, $converted )) - { - return number_format($converted , (int)$precision, $this->decimal_point, $this->thousand_separator); - } else { - return false; - } - } // end func - - /** - * CVH : changed this Function getConvSpecs in order to have it look up - * intermediary Conversions from the - * "base" unit being that one that has the highest hierarchical order in one - * "logical" Conversion_Array - * when taking $conv->addConversion('km', - * array('meter'=>1000, 'dmeter'=>10000, 'centimeter'=>100000, - * 'millimeter'=>1000000, 'mile'=>0.62137, 'naut.mile'=>0.53996, - * 'inch(es)/zoll'=>39370, 'ft/foot/feet'=>3280.8, 'yd/yard'=>1093.6)); - * "km" would be the logical base unit for all units of dinstance, thus, - * if the function fails to find a direct or reverse conversion in the table - * it is only logical to suspect that if there is a chance - * converting the value it only is via the "base" unit, and so - * there is not even a need for a recursive search keeping the perfomance - * acceptable and the ressource small... - * - * CVH check_key checks for a key in the Conversiontable and returns a value - */ - function check_key( $key) { - if ( array_key_exists ($key,$this->conversion_table)) { - if (! empty($this->conversion_table[$key])) { - return $this->conversion_table[$key]; - } - } - return false; - } - - /** - * Key function. Finds the conversion ratio and offset from one unit to another. - * - * @param string name of the source unit from which to convert - * @param string name of the target unit to which we are converting - * @param double conversion ratio found. Returned by reference. - * @param double offset which needs to be added (or subtracted, if negative) - * to the result to convert correctly. - * For temperature or some scientific conversions, - * i.e. Fahrenheit -> Celcius - * @return boolean true if ratio and offset are found for the supplied - * units, false otherwise - * @access private - */ - function getConvSpecs($from_unit, $to_unit, $value, &$converted) - { - $key = $from_unit."_".$to_unit; - $revkey = $to_unit."_".$from_unit; - $found = false; - if ($ct_arr = $this->check_key($key)) { - // Conversion Specs found directly - $ratio = (double)$ct_arr['ratio']; - $offset = $ct_arr['offset']; - $converted = (double)(($value * $ratio)+ $offset); - - return true; - } // not found in direct order, try reverse order - elseif ($ct_arr = $this->check_key($revkey)) { - $ratio = (double)(1/$ct_arr['ratio']); - $offset = -$ct_arr['offset']; - $converted = (double)(($value + $offset) * $ratio); - - return true; - } // not found test for intermediary conversion - else { - // return ratio = 1 if keyparts match - if ($key == $revkey) { - $ratio = 1; - $offset = 0; - $converted = $value; - return true; - } - // otherwise search intermediary - reset($this->conversion_table); - while (list($convk, $i1_value) = each($this->conversion_table)) { - // split the key into parts - $keyparts = preg_split("/_/",$convk); - // return ratio = 1 if keyparts match - - // Now test if either part matches the from or to unit - if ($keyparts[1] == $to_unit && ($i2_value = $this->check_key($keyparts[0]."_".$from_unit))) { - // an intermediary $keyparts[0] was found - // now let us put things together intermediary 1 and 2 - $converted = (double)(((($value - $i2_value['offset']) / $i2_value['ratio']) * $i1_value['ratio'])+ $i1_value['offset']); - - $found = true; - - } elseif ($keyparts[1] == $from_unit && ($i2_value = $this->check_key($keyparts[0]."_".$to_unit))) { - // an intermediary $keyparts[0] was found - // now let us put things together intermediary 2 and 1 - $converted = (double)(((($value - $i1_value['offset']) / $i1_value['ratio']) + $i2_value['offset']) * $i2_value['ratio']); - - $found = true; - } - } - return $found; - } - - } // end func getConvSpecs - -} // end class UnitConvertor -?> \ No newline at end of file diff --git a/convert/convert.php b/convert/convert.php index 5449cc14..1385731c 100644 --- a/convert/convert.php +++ b/convert/convert.php @@ -18,12 +18,6 @@ function convert_app_menu($a,&$b) { function convert_module() {} - - - - - - function convert_content($app) { include("UnitConvertor.php"); @@ -85,92 +79,90 @@ include("UnitConvertor.php"); } } - $conv = new TP_Converter('en'); - $conversions = [ - 'Temperature'=>['base' =>'Celsius', - 'conv'=>[ - 'Fahrenheit'=>['ratio'=>1.8, 'offset'=>32], - 'Kelvin'=>['ratio'=>1, 'offset'=>273], - 'Reaumur'=>0.8 + 'Temperature' => ['base' => 'Celsius', + 'conv' => [ + 'Fahrenheit' => ['ratio' => 1.8, 'offset' => 32], + 'Kelvin' => ['ratio' => 1, 'offset' => 273], + 'Reaumur' => 0.8 ] ], - 'Weight' => ['base' =>'kg', - 'conv'=>[ - 'g'=>1000, - 'mg'=>1000000, - 't'=>0.001, - 'grain'=>15432, - 'oz'=>35.274, - 'lb'=>2.2046, - 'cwt(UK)' => 0.019684, - 'cwt(US)' => 0.022046, - 'ton (US)' => 0.0011023, - 'ton (UK)' => 0.0009842 + 'Weight' => ['base' => 'kg', + 'conv' => [ + 'g' => 1000, + 'mg' => 1000000, + 't' => 0.001, + 'grain' => 15432, + 'oz' => 35.274, + 'lb' => 2.2046, + 'cwt(UK)' => 0.019684, + 'cwt(US)' => 0.022046, + 'ton (US)' => 0.0011023, + 'ton (UK)' => 0.0009842 ] ], - 'Distance' => ['base' =>'km', - 'conv'=>[ - 'm'=>1000, - 'dm'=>10000, - 'cm'=>100000, - 'mm'=>1000000, - 'mile'=>0.62137, - 'naut.mile'=>0.53996, - 'inch(es)'=>39370, - 'ft'=>3280.8, - 'yd'=>1093.6, - 'furlong'=>4.970969537898672, - 'fathom'=>546.8066491688539 + 'Distance' => ['base' => 'km', + 'conv' => [ + 'm' => 1000, + 'dm' => 10000, + 'cm' => 100000, + 'mm' => 1000000, + 'mile' => 0.62137, + 'naut.mile' => 0.53996, + 'inch(es)' => 39370, + 'ft' => 3280.8, + 'yd' => 1093.6, + 'furlong' => 4.970969537898672, + 'fathom' => 546.8066491688539 ] ], - '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), - '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), + '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), + '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' => ['base' =>'m 3', - 'conv'=>[ - 'in 3'=>61023.6, - 'ft 3'=>35.315, - 'cm 3'=>pow(10,6), - 'dm 3'=>1000, - 'litre'=>1000, - 'hl'=>10, - 'yd 3'=>1.30795, - 'gal(US)'=>264.172, - 'gal(UK)'=>219.969, - 'pint' => 2113.376, - 'quart' => 1056.688, - 'cup' => 4266.753, - 'fl oz' => 33814.02, - 'tablespoon' => 67628.04, - 'teaspoon' => 202884.1, - 'pt (UK)'=>1000/0.56826, - 'barrel petroleum'=>1000/158.99, - 'Register Tons'=>2.832, - 'Ocean Tons'=>1.1327 + 'Volume' => ['base' => 'm 3', + 'conv' => [ + 'in 3' => 61023.6, + 'ft 3' => 35.315, + 'cm 3' => pow(10,6), + 'dm 3' => 1000, + 'litre' => 1000, + 'hl' => 10, + 'yd 3' => 1.30795, + 'gal(US)' => 264.172, + 'gal(UK)' => 219.969, + 'pint' => 2113.376, + 'quart' => 1056.688, + 'cup' => 4266.753, + 'fl oz' => 33814.02, + 'tablespoon' => 67628.04, + 'teaspoon' => 202884.1, + 'pt (UK)' => 1000/0.56826, + 'barrel petroleum' => 1000/158.99, + 'Register Tons' => 2.832, + 'Ocean Tons' => 1.1327 ] ], - 'Speed' =>['base' =>'kmph', - 'conv'=>[ - 'mps'=>0.0001726031, - 'milesph'=>0.62137, - 'knots'=>0.53996, - 'mach STP'=>0.0008380431, - 'c (warp)'=>9.265669e-10 + 'Speed' => ['base' => 'kmph', + 'conv' => [ + 'mps' => 0.0001726031, + 'milesph' => 0.62137, + 'knots' => 0.53996, + 'mach STP' => 0.0008380431, + 'c (warp)' => 9.265669e-10 ] ] ]; @@ -188,24 +180,21 @@ while (list($key,$val) = each($conversions)) { if (isset($_POST['from_unit']) && isset($_POST['value'])) { - $_POST['value'] = $_POST['value'] + 0; - - + $_POST['value'] = $_POST['value'] + 0; $o .= ($conv->getTable($_POST['value'], $_POST['from_unit'], $_POST['to_unit'], 5))."

"; } else { $o .= "

Select:

"; } - if(isset($_POST['value'])) + if (isset($_POST['value'])) { $value = $_POST['value']; - else + } else { $value = ''; + } $o .= '
'; - $o .= ''; - $o .= ''; + $o .= ''; - - $o .= '
'; + $o .= ''; return $o; } diff --git a/diaspora/diasphp.php b/diaspora/diasphp.php index 4225353e..1588b582 100644 --- a/diaspora/diasphp.php +++ b/diaspora/diasphp.php @@ -110,4 +110,3 @@ class Diasphp { return true; } } -?> diff --git a/leistungsschutzrecht/leistungsschutzrecht.php b/leistungsschutzrecht/leistungsschutzrecht.php index c0e93f0c..7024c73a 100644 --- a/leistungsschutzrecht/leistungsschutzrecht.php +++ b/leistungsschutzrecht/leistungsschutzrecht.php @@ -166,4 +166,3 @@ function leistungsschutzrecht_cron($a,$b) { leistungsschutzrecht_fetchsites(); DI::config()->set('leistungsschutzrecht','last_poll', time()); } -?> diff --git a/libravatar/Services/Libravatar.php b/libravatar/Services/Libravatar.php index c679ca9d..18aa5c90 100644 --- a/libravatar/Services/Libravatar.php +++ b/libravatar/Services/Libravatar.php @@ -667,5 +667,3 @@ class Services_Libravatar * c-hanging-comment-ender-p: nil * End: */ - -?> diff --git a/statusnet/library/codebirdsn.php b/statusnet/library/codebirdsn.php index e5e281b9..020c69c4 100644 --- a/statusnet/library/codebirdsn.php +++ b/statusnet/library/codebirdsn.php @@ -1055,5 +1055,3 @@ class CodebirdSN return $parsed; } } - -?> diff --git a/webrtc/webrtc.php b/webrtc/webrtc.php index 194425d5..4597fb1a 100644 --- a/webrtc/webrtc.php +++ b/webrtc/webrtc.php @@ -52,4 +52,3 @@ function webrtc_content(&$a) { return $o; } -?> From be9d786ef9a6203569a0a69373a3fc2922399be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jun 2022 05:46:32 +0200 Subject: [PATCH 02/19] Ops, we need this back! :-( --- convert/UnitConvertor.php | 283 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 convert/UnitConvertor.php diff --git a/convert/UnitConvertor.php b/convert/UnitConvertor.php new file mode 100644 index 00000000..d7933a8f --- /dev/null +++ b/convert/UnitConvertor.php @@ -0,0 +1,283 @@ + | +// | Co-authored by : CVH, Chris Hansel | +// +----------------------------------------------------------------------+ +// +// $Id: UnitConvertor.php,v 1.00 2002/02/20 11:40:00 stasokhvat Exp $ + +/** +* UnitConvertor is able to convert between different units and currencies. +* +* @author Stanislav Okhvat +* @version $Id: UnitConvertor.php,v 1.00 2002/03/01 17:00:00 stasokhvat Exp $ +* @package UnitConvertor +* @access public +* @history 01.03.2002 Implemented the code for regular and offset-based +* conversions +* +* 13.12.2004 +* By Chris Hansel (CVH): changed getConvSpecs in order to have it look up +* intermediary conversions (also see comments in check_key). +* +* Intermediary conversions are useful when no conversion ratio is specified +* between two units when we calculate between the two. For example, we want +* to convert between Fahrenheit and Kelvin, and we have only +* specified how to convert Centigrade<->Fahrenheit and +* Centigrade<->Kelvin. While a direct (Fahrenheit->Kelvin) or +* reverse (Kelvin->Fahrenheit) lookups fail, looking for an intermediary +* unit linking the two (Centigrade) helps us do the conversion. +* +* 13.12.2004 +* Chris Hansel (CVH): $to_array argument of addConversion method can now +* contain units as 'unit1/unit2/unit3', when all units stand for the same +* thing. See examples in unitconv.php +*/ +class UnitConvertor +{ + /** + * Stores conversion ratios. + * + * @var array + * @access private + */ + var $conversion_table = array(); + + /** + * Decimal point character (default is "." - American - set in constructor). + * + * @var string + * @access private + */ + var $decimal_point; + + /** + * Thousands separator (default is "," - American - set in constructor). + * + * @var string + * @access private + */ + var $thousand_separator; + + /** + * For future use + * + * @var array + * @access private + */ + var $bases = array(); + + /** + * Constructor. Initializes the UnitConvertor object with the most important + * properties. + * + * @param string decimal point character + * @param string thousand separator character + * @return void + * @access public + */ + function UnitConvertor($dec_point = '.', $thousand_sep = ',') + { + $this->decimal_point = $dec_point; + $this->thousand_separator = $thousand_sep; + + } // end func UnitConvertor + + /** + * Adds a conversion ratio to the conversion table. + * + * @param string the name of unit from which to convert + * @param array array( + * "pound"=>array("ratio"=>'', "offset"=>'') + * ) + * "pound" - name of unit to set conversion ration to + * "ratio" - 'double' conversion ratio which, when + * multiplied by the number of $from_unit units produces + * the result + * "offset" - an offset from 0 which will be added to + * the result when converting (needed for temperature + * conversions and defaults to 0). + * @return boolean true if successful, false otherwise + * @access public + */ + function addConversion($from_unit, $to_array) + { + if (!isset($this->conversion_table[$from_unit])) { + while(list($key, $val) = each($to_array)) + { + if (strstr($key, '/')) + { + $to_units = explode('/', $key); + foreach ($to_units as $to_unit) + { + $this->bases[$from_unit][] = $to_unit; + + if (!is_array($val)) + { + $this->conversion_table[$from_unit."_".$to_unit] = array("ratio"=>$val, "offset"=>0); + } + else + { + $this->conversion_table[$from_unit."_".$to_unit] = + array( + "ratio"=>$val['ratio'], + "offset"=>(isset($val['offset']) ? $val['offset'] : 0) + ); + } + } + } + else + { + $this->bases[$from_unit][] = $key; + + if (!is_array($val)) + { + $this->conversion_table[$from_unit."_".$key] = array("ratio"=>$val, "offset"=>0); + } + else + { + $this->conversion_table[$from_unit."_".$key] = + array( + "ratio"=>$val['ratio'], + "offset"=>(isset($val['offset']) ? $val['offset'] : 0) + ); + } + } + } + return true; + } + return false; + + } // end func addConversion + + /** + * Converts from one unit to another using specified precision. + * + * @param double value to convert + * @param string name of the source unit from which to convert + * @param string name of the target unit to which we are converting + * @param integer double precision of the end result + * @return void + * @access public + */ + function convert($value, $from_unit, $to_unit, $precision) + { + if ($this->getConvSpecs($from_unit, $to_unit, $value, $converted )) + { + return number_format($converted , (int)$precision, $this->decimal_point, $this->thousand_separator); + } else { + return false; + } + } // end func + + /** + * CVH : changed this Function getConvSpecs in order to have it look up + * intermediary Conversions from the + * "base" unit being that one that has the highest hierarchical order in one + * "logical" Conversion_Array + * when taking $conv->addConversion('km', + * array('meter'=>1000, 'dmeter'=>10000, 'centimeter'=>100000, + * 'millimeter'=>1000000, 'mile'=>0.62137, 'naut.mile'=>0.53996, + * 'inch(es)/zoll'=>39370, 'ft/foot/feet'=>3280.8, 'yd/yard'=>1093.6)); + * "km" would be the logical base unit for all units of dinstance, thus, + * if the function fails to find a direct or reverse conversion in the table + * it is only logical to suspect that if there is a chance + * converting the value it only is via the "base" unit, and so + * there is not even a need for a recursive search keeping the perfomance + * acceptable and the ressource small... + * + * CVH check_key checks for a key in the Conversiontable and returns a value + */ + function check_key( $key) { + if ( array_key_exists ($key,$this->conversion_table)) { + if (! empty($this->conversion_table[$key])) { + return $this->conversion_table[$key]; + } + } + return false; + } + + /** + * Key function. Finds the conversion ratio and offset from one unit to another. + * + * @param string name of the source unit from which to convert + * @param string name of the target unit to which we are converting + * @param double conversion ratio found. Returned by reference. + * @param double offset which needs to be added (or subtracted, if negative) + * to the result to convert correctly. + * For temperature or some scientific conversions, + * i.e. Fahrenheit -> Celcius + * @return boolean true if ratio and offset are found for the supplied + * units, false otherwise + * @access private + */ + function getConvSpecs($from_unit, $to_unit, $value, &$converted) + { + $key = $from_unit."_".$to_unit; + $revkey = $to_unit."_".$from_unit; + $found = false; + if ($ct_arr = $this->check_key($key)) { + // Conversion Specs found directly + $ratio = (double)$ct_arr['ratio']; + $offset = $ct_arr['offset']; + $converted = (double)(($value * $ratio)+ $offset); + + return true; + } // not found in direct order, try reverse order + elseif ($ct_arr = $this->check_key($revkey)) { + $ratio = (double)(1/$ct_arr['ratio']); + $offset = -$ct_arr['offset']; + $converted = (double)(($value + $offset) * $ratio); + + return true; + } // not found test for intermediary conversion + else { + // return ratio = 1 if keyparts match + if ($key == $revkey) { + $ratio = 1; + $offset = 0; + $converted = $value; + return true; + } + // otherwise search intermediary + reset($this->conversion_table); + while (list($convk, $i1_value) = each($this->conversion_table)) { + // split the key into parts + $keyparts = preg_split("/_/",$convk); + // return ratio = 1 if keyparts match + + // Now test if either part matches the from or to unit + if ($keyparts[1] == $to_unit && ($i2_value = $this->check_key($keyparts[0]."_".$from_unit))) { + // an intermediary $keyparts[0] was found + // now let us put things together intermediary 1 and 2 + $converted = (double)(((($value - $i2_value['offset']) / $i2_value['ratio']) * $i1_value['ratio'])+ $i1_value['offset']); + + $found = true; + + } elseif ($keyparts[1] == $from_unit && ($i2_value = $this->check_key($keyparts[0]."_".$to_unit))) { + // an intermediary $keyparts[0] was found + // now let us put things together intermediary 2 and 1 + $converted = (double)(((($value - $i1_value['offset']) / $i1_value['ratio']) + $i2_value['offset']) * $i2_value['ratio']); + + $found = true; + } + } + return $found; + } + + } // end func getConvSpecs + +} // end class UnitConvertor +?> \ No newline at end of file From 28cdecea93aa9bfba41086b1c5cc60057f777033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jun 2022 05:52:43 +0200 Subject: [PATCH 03/19] Changes: - changed more double-quotes to single - `include` is not a function --- convert/convert.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/convert/convert.php b/convert/convert.php index 1385731c..54f7df4b 100644 --- a/convert/convert.php +++ b/convert/convert.php @@ -20,15 +20,15 @@ function convert_module() {} function convert_content($app) { -include("UnitConvertor.php"); +include 'UnitConvertor.php'; class TP_Converter extends UnitConvertor { - function TP_Converter($lang = "en") + function TP_Converter($lang = 'en') { if ($lang != 'en' ) { $dec_point = '.'; $thousand_sep = "'"; } else { - $dec_point = '.'; $thousand_sep = ","; + $dec_point = '.'; $thousand_sep = ','; } $this->UnitConvertor($dec_point , $thousand_sep ); @@ -50,13 +50,13 @@ include("UnitConvertor.php"); // 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": ""; + $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": ""; + $cell ['value'] = $this->convert($value, $from_unit, $val, $precision) . ' ' . $val; + $cell ['class'] = ($val == $from_unit || $val == $to_unit) ? 'framedred' : ''; $cells[] = $cell; } @@ -181,9 +181,9 @@ while (list($key,$val) = each($conversions)) { if (isset($_POST['from_unit']) && isset($_POST['value'])) { $_POST['value'] = $_POST['value'] + 0; - $o .= ($conv->getTable($_POST['value'], $_POST['from_unit'], $_POST['to_unit'], 5))."

"; + $o .= ($conv->getTable($_POST['value'], $_POST['from_unit'], $_POST['to_unit'], 5)) . '

'; } else { - $o .= "

Select:

"; + $o .= '

Select:

'; } if (isset($_POST['value'])) { From 3bda8dfa32ebdc99f21c538ede14f788580b3550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jun 2022 06:04:05 +0200 Subject: [PATCH 04/19] Changes: - changed more double-quotes to single - cleaned up js_upload/file-uploader/server/php.php a lot - added some type-hints --- .../advancedcontentfilter.php | 28 +- blackout/blackout.php | 16 +- js_upload/file-uploader/server/php.php | 285 +++++++++--------- 3 files changed, 172 insertions(+), 157 deletions(-) diff --git a/advancedcontentfilter/advancedcontentfilter.php b/advancedcontentfilter/advancedcontentfilter.php index 9f6a7cff..45ab3f3e 100644 --- a/advancedcontentfilter/advancedcontentfilter.php +++ b/advancedcontentfilter/advancedcontentfilter.php @@ -64,7 +64,7 @@ function advancedcontentfilter_install(App $a) Hook::add('dbstructure_definition' , __FILE__, 'advancedcontentfilter_dbstructure_definition'); DBStructure::performUpdate(); - Logger::notice("installed advancedcontentfilter"); + Logger::notice('installed advancedcontentfilter'); } /* @@ -73,20 +73,20 @@ function advancedcontentfilter_install(App $a) function advancedcontentfilter_dbstructure_definition(App $a, &$database) { - $database["advancedcontentfilter_rules"] = [ - "comment" => "Advancedcontentfilter addon rules", - "fields" => [ - "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented rule id"], - "uid" => ["type" => "int unsigned", "not null" => "1", "comment" => "Owner user id"], - "name" => ["type" => "varchar(255)", "not null" => "1", "comment" => "Rule name"], - "expression" => ["type" => "mediumtext" , "not null" => "1", "comment" => "Expression text"], - "serialized" => ["type" => "mediumtext" , "not null" => "1", "comment" => "Serialized parsed expression"], - "active" => ["type" => "boolean" , "not null" => "1", "default" => "1", "comment" => "Whether the rule is active or not"], - "created" => ["type" => "datetime" , "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation date"], + $database['advancedcontentfilter_rules'] = [ + 'comment' => 'Advancedcontentfilter addon rules', + 'fields' => [ + 'id' => ['type' => 'int unsigned', 'not null' => '1', 'extra' => 'auto_increment', 'primary' => '1', 'comment' => 'Auto incremented rule id'], + 'uid' => ['type' => 'int unsigned', 'not null' => '1', 'comment' => 'Owner user id'], + 'name' => ['type' => 'varchar(255)', 'not null' => '1', 'comment' => 'Rule name'], + 'expression' => ['type' => 'mediumtext' , 'not null' => '1', 'comment' => 'Expression text'], + 'serialized' => ['type' => 'mediumtext' , 'not null' => '1', 'comment' => 'Serialized parsed expression'], + 'active' => ['type' => 'boolean' , 'not null' => '1', 'default' => '1', 'comment' => 'Whether the rule is active or not'], + 'created' => ['type' => 'datetime' , 'not null' => '1', 'default' => DBA::NULL_DATETIME, 'comment' => 'Creation date'], ], - "indexes" => [ - "PRIMARY" => ["id"], - "uid_active" => ["uid", "active"], + 'indexes' => [ + 'PRIMARY' => ['id'], + 'uid_active' => ['uid', 'active'], ] ]; } diff --git a/blackout/blackout.php b/blackout/blackout.php index 18e74570..ecb04c76 100644 --- a/blackout/blackout.php +++ b/blackout/blackout.php @@ -82,17 +82,17 @@ function blackout_redirect ($a, $b) { function blackout_addon_admin(&$a, &$o) { $mystart = DI::config()->get('blackout','begindate'); - if (! is_string($mystart)) { $mystart = "YYYY-MM-DD hh:mm"; } + if (! is_string($mystart)) { $mystart = 'YYYY-MM-DD hh:mm'; } $myend = DI::config()->get('blackout','enddate'); - if (! is_string($myend)) { $myend = "YYYY-MM-DD hh:mm"; } + if (! is_string($myend)) { $myend = 'YYYY-MM-DD hh:mm'; } $myurl = DI::config()->get('blackout','url'); - if (! is_string($myurl)) { $myurl = "https://www.example.com"; } - $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/blackout/" ); + if (! is_string($myurl)) { $myurl = 'https://www.example.com'; } + $t = Renderer::getMarkupTemplate( 'admin.tpl', 'addon/blackout/' ); $date1 = DateTime::createFromFormat('Y-m-d G:i', $mystart); $date2 = DateTime::createFromFormat('Y-m-d G:i', $myend); // a note for the admin - $adminnote = ""; + $adminnote = ''; if ($date2 < $date1) { $adminnote = DI::l10n()->t("The end-date is prior to the start-date of the blackout, you should fix this."); } else { @@ -100,9 +100,9 @@ function blackout_addon_admin(&$a, &$o) { } $o = Renderer::replaceMacros($t, [ '$submit' => DI::l10n()->t('Save Settings'), - '$rurl' => ["rurl", DI::l10n()->t("Redirect URL"), $myurl, DI::l10n()->t("All your visitors from the web will be redirected to this URL."), "", "", "url"], - '$startdate' => ["startdate", DI::l10n()->t("Begin of the Blackout"), $mystart, DI::l10n()->t("Format is YYYY-MM-DD hh:mm; YYYY year, MM month, DD day, hh hour and mm minute.")], - '$enddate' => ["enddate", DI::l10n()->t("End of the Blackout"), $myend, ""], + '$rurl' => ['rurl', DI::l10n()->t("Redirect URL"), $myurl, DI::l10n()->t("All your visitors from the web will be redirected to this URL."), '', '', 'url'], + '$startdate' => ['startdate', DI::l10n()->t("Begin of the Blackout"), $mystart, DI::l10n()->t("Format is YYYY-MM-DD hh:mm; YYYY year, MM month, DD day, hh hour and mm minute.")], + '$enddate' => ['enddate', DI::l10n()->t("End of the Blackout"), $myend, ''], '$adminnote' => $adminnote, '$aboutredirect' => DI::l10n()->t("Note: The redirect will be active from the moment you press the submit button. Users currently logged in will not be thrown out but can't login again after logging out while the blackout is still in place."), ]); diff --git a/js_upload/file-uploader/server/php.php b/js_upload/file-uploader/server/php.php index 915c86c6..2248c8f0 100644 --- a/js_upload/file-uploader/server/php.php +++ b/js_upload/file-uploader/server/php.php @@ -4,155 +4,170 @@ * Handle file uploads via XMLHttpRequest */ class qqUploadedFileXhr { - /** - * Save the file to the specified path - * @return boolean TRUE on success - */ - function save($path) { - $input = fopen("php://input", "r"); - $temp = tmpfile(); - $realSize = stream_copy_to_stream($input, $temp); - fclose($input); - - if ($realSize != $this->getSize()){ - return false; - } - - $target = fopen($path, "w"); - fseek($temp, 0, SEEK_SET); - stream_copy_to_stream($temp, $target); - fclose($target); - - return true; - } - function getName() { - return $_GET['qqfile']; - } - function getSize() { - if (isset($_SERVER["CONTENT_LENGTH"])){ - return (int)$_SERVER["CONTENT_LENGTH"]; - } else { - throw new Exception('Getting content length is not supported.'); - } - } + /** + * Save the file to the specified path + * @return boolean TRUE on success + */ + public function save(string $path): bool + { + $input = fopen('php://input', 'r'); + $temp = tmpfile(); + $realSize = stream_copy_to_stream($input, $temp); + fclose($input); + + if ($realSize != $this->getSize()) { + return false; + } + + $target = fopen($path, 'w'); + fseek($temp, 0, SEEK_SET); + stream_copy_to_stream($temp, $target); + fclose($target); + + return true; + } + + public function getName(): string + { + return $_GET['qqfile']; + } + + public function getSize(): int + { + if (isset($_SERVER['CONTENT_LENGTH'])) { + return (int)$_SERVER['CONTENT_LENGTH']; + } else { + throw new Exception('Getting content length is not supported.'); + } + } } /** * Handle file uploads via regular form post (uses the $_FILES array) */ -class qqUploadedFileForm { - /** - * Save the file to the specified path - * @return boolean TRUE on success - */ - function save($path) { - if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)){ - return false; - } - return true; - } - function getName() { - return $_FILES['qqfile']['name']; - } - function getSize() { - return $_FILES['qqfile']['size']; - } +class qqUploadedFileForm { + /** + * Save the file to the specified path + * @return boolean TRUE on success + */ + public function save(string $path): bool + { + if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) { + return false; + } + return true; + } + + public function getName(): string + { + return $_FILES['qqfile']['name']; + } + + public function getSize(): int + { + return $_FILES['qqfile']['size']; + } } class qqFileUploader { - private $allowedExtensions = array(); - private $sizeLimit = 10485760; - private $file; + private $allowedExtensions = []; + private $sizeLimit = 10485760; + private $file; - function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){ - $allowedExtensions = array_map("strtolower", $allowedExtensions); - - $this->allowedExtensions = $allowedExtensions; - $this->sizeLimit = $sizeLimit; - - $this->checkServerSettings(); + public function __construct(array $allowedExtensions = [], $sizeLimit = 10485760) + { + $allowedExtensions = array_map('strtolower', $allowedExtensions); + + $this->allowedExtensions = $allowedExtensions; + $this->sizeLimit = $sizeLimit; + + $this->checkServerSettings(); - if (isset($_GET['qqfile'])) { - $this->file = new qqUploadedFileXhr(); - } elseif (isset($_FILES['qqfile'])) { - $this->file = new qqUploadedFileForm(); - } else { - $this->file = false; - } - } - - private function checkServerSettings(){ - $postSize = $this->toBytes(ini_get('post_max_size')); - $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); - - if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit){ - $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; - die("{'error':'increase post_max_size and upload_max_filesize to $size'}"); - } - } - - private function toBytes($str){ - $val = trim($str); - $last = strtolower($str[strlen($str)-1]); - switch($last) { - case 'g': $val *= 1024; - case 'm': $val *= 1024; - case 'k': $val *= 1024; - } - return $val; - } - - /** - * Returns array('success'=>true) or array('error'=>'error message') - */ - function handleUpload($uploadDirectory, $replaceOldFile = FALSE){ - if (!is_writable($uploadDirectory)){ - return array('error' => "Server error. Upload directory isn't writable."); - } - - if (!$this->file){ - return array('error' => 'No files were uploaded.'); - } - - $size = $this->file->getSize(); - - if ($size == 0) { - return array('error' => 'File is empty'); - } - - if ($size > $this->sizeLimit) { - return array('error' => 'File is too large'); - } - - $pathinfo = pathinfo($this->file->getName()); - $filename = $pathinfo['filename']; - //$filename = md5(uniqid()); - $ext = $pathinfo['extension']; + if (isset($_GET['qqfile'])) { + $this->file = new qqUploadedFileXhr(); + } elseif (isset($_FILES['qqfile'])) { + $this->file = new qqUploadedFileForm(); + } else { + $this->file = false; + } + } - if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)){ - $these = implode(', ', $this->allowedExtensions); - return array('error' => 'File has an invalid extension, it should be one of '. $these . '.'); - } - - if(!$replaceOldFile){ - /// don't overwrite previous files that were uploaded - while (file_exists($uploadDirectory . $filename . '.' . $ext)) { - $filename .= rand(10, 99); - } - } - - if ($this->file->save($uploadDirectory . $filename . '.' . $ext)){ - return array('success'=>true); - } else { - return array('error'=> 'Could not save uploaded file.' . - 'The upload was cancelled, or server error encountered'); - } - - } + private function checkServerSettings() + { + $postSize = $this->toBytes(ini_get('post_max_size')); + $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); + + if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) { + $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; + die("{'error':'increase post_max_size and upload_max_filesize to $size'}"); + } + } + + private function toBytes(string $str): int + { + $val = trim($str); + $last = strtolower($str[strlen($str) - 1]); + + switch($last) { + case 'g': $val *= 1024; + case 'm': $val *= 1024; + case 'k': $val *= 1024; + } + + return $val; + } + + /** + * Returns array('success'=>true) or array('error'=>'error message') + */ + public function handleUpload(string $uploadDirectory, bool $replaceOldFile = false): array + { + if (!is_writable($uploadDirectory)) { + return ['error' => "Server error. Upload directory isn't writable."]; + } + + if (!$this->file) { + return ['error' => 'No files were uploaded.']; + } + + $size = $this->file->getSize(); + + if ($size == 0) { + return ['error' => 'File is empty']; + } + + if ($size > $this->sizeLimit) { + return ['error' => 'File is too large']; + } + + $pathinfo = pathinfo($this->file->getName()); + $filename = $pathinfo['filename']; + //$filename = md5(uniqid()); + $ext = $pathinfo['extension']; + + if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { + $these = implode(', ', $this->allowedExtensions); + return ['error' => 'File has an invalid extension, it should be one of '. $these . '.']; + } + + if(!$replaceOldFile) { + /// don't overwrite previous files that were uploaded + while (file_exists($uploadDirectory . $filename . '.' . $ext)) { + $filename .= rand(10, 99); + } + } + + if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) { + return ['success' => true]; + } else { + return ['error'=> 'Could not save uploaded file. The upload was cancelled, or server error encountered']; + } + } } // list of valid extensions, ex. array("jpeg", "xml", "bmp") -$allowedExtensions = array(); +$allowedExtensions = []; + // max file size in bytes $sizeLimit = 10 * 1024 * 1024; From 0ecd7729586c2f5eeeee9c8806f9aca979939c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jun 2022 06:20:19 +0200 Subject: [PATCH 05/19] Changes: - added some type-hints - changed double-quotes to singl - cleaned up file (e.g. wrong place for curly braces) --- leistungsschutzrecht/leistungsschutzrecht.php | 75 +++++++++++-------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/leistungsschutzrecht/leistungsschutzrecht.php b/leistungsschutzrecht/leistungsschutzrecht.php index 7024c73a..23767f14 100644 --- a/leistungsschutzrecht/leistungsschutzrecht.php +++ b/leistungsschutzrecht/leistungsschutzrecht.php @@ -6,6 +6,7 @@ * Author: Michael Vogel */ +use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\DI; @@ -16,51 +17,54 @@ function leistungsschutzrecht_install() { Hook::register('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo'); } -function leistungsschutzrecht_getsiteinfo($a, &$siteinfo) { - if (!isset($siteinfo["url"]) || empty($siteinfo['type'])) { +function leistungsschutzrecht_getsiteinfo(App $a,array &$siteinfo) { + if (!isset($siteinfo['url']) || empty($siteinfo['type'])) { return; } // Avoid any third party pictures, to avoid copyright issues if (!in_array($siteinfo['type'], ['photo', 'video']) && DI::config()->get('leistungsschutzrecht', 'suppress_photos', false)) { - unset($siteinfo["image"]); - unset($siteinfo["images"]); + unset($siteinfo['image']); + unset($siteinfo['images']); } - if (!leistungsschutzrecht_is_member_site($siteinfo["url"])) { + if (!leistungsschutzrecht_is_member_site($siteinfo['url'])) { return; } - if (!empty($siteinfo["text"])) { - $siteinfo["text"] = leistungsschutzrecht_cuttext($siteinfo["text"]); + if (!empty($siteinfo['text'])) { + $siteinfo['text'] = leistungsschutzrecht_cuttext($siteinfo['text']); } - unset($siteinfo["keywords"]); + unset($siteinfo['keywords']); } -function leistungsschutzrecht_cuttext($text) { - $text = str_replace(["\r", "\n"], [" ", " "], $text); +function leistungsschutzrecht_cuttext(string $text): string +{ + $text = str_replace(["\r", "\n"], [' ', ' '], $text); do { $oldtext = $text; - $text = str_replace(" ", " ", $text); + $text = str_replace(' ', ' ', $text); } while ($oldtext != $text); - $words = explode(" ", $text); + $words = explode(' ', $text); - $text = ""; + $text = ''; $count = 0; $limit = 7; foreach ($words as $word) { - if ($text != "") - $text .= " "; + if ($text != '') { + $text .= ' '; + } $text .= $word; if (++$count >= $limit) { - if (sizeof($words) > $limit) - $text .= " ..."; + if (sizeof($words) > $limit) { + $text .= ' ...'; + } break; } @@ -71,7 +75,7 @@ function leistungsschutzrecht_cuttext($text) { function leistungsschutzrecht_fetchsites() { // This list works - but question is how current it is - $url = "http://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt"; + $url = 'https://leistungsschutzrecht-stoppen.d-64.org/blacklist.txt'; $sitelist = DI::httpClient()->fetch($url); $siteurls = explode(',', $sitelist); @@ -123,23 +127,27 @@ function leistungsschutzrecht_fetchsites() } } -function leistungsschutzrecht_is_member_site($url) { +function leistungsschutzrecht_is_member_site(string $url) +{ $sites = DI::config()->get('leistungsschutzrecht','sites'); - if ($sites == "") - return(false); + if ($sites == '') { + return false; + } - if (sizeof($sites) == 0) - return(false); + if (sizeof($sites) == 0) { + return false; + } $urldata = parse_url($url); - if (!isset($urldata["host"])) - return(false); + if (!isset($urldata['host'])) { + return false; + } - $cleanedurlpart = explode("%", $urldata["host"]); + $cleanedurlpart = explode('%', $urldata['host']); - $hostname = explode(".", $cleanedurlpart[0]); + $hostname = explode('.', $cleanedurlpart[0]); if (empty($hostname)) { return false; } @@ -148,21 +156,22 @@ function leistungsschutzrecht_is_member_site($url) { return false; } - $site = $hostname[sizeof($hostname) - 2].".".$hostname[sizeof($hostname) - 1]; + $site = $hostname[sizeof($hostname) - 2] . '.' . $hostname[sizeof($hostname) - 1]; return (isset($sites[$site])); } -function leistungsschutzrecht_cron($a,$b) { - $last = DI::config()->get('leistungsschutzrecht','last_poll'); +function leistungsschutzrecht_cron(App $a,$b) +{ + $last = DI::config()->get('leistungsschutzrecht', 'last_poll'); - if($last) { + if ($last) { $next = $last + 86400; - if($next > time()) { + if ($next > time()) { Logger::notice('poll intervall not reached'); return; } } leistungsschutzrecht_fetchsites(); - DI::config()->set('leistungsschutzrecht','last_poll', time()); + DI::config()->set('leistungsschutzrecht', 'last_poll', time()); } From a1e17968d1626f1091059e7ba64b8283c0e4908d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jun 2022 06:26:24 +0200 Subject: [PATCH 06/19] leistungsschutzrecht_is_member_site() returns boolean value --- leistungsschutzrecht/leistungsschutzrecht.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/leistungsschutzrecht/leistungsschutzrecht.php b/leistungsschutzrecht/leistungsschutzrecht.php index 23767f14..991b4f0f 100644 --- a/leistungsschutzrecht/leistungsschutzrecht.php +++ b/leistungsschutzrecht/leistungsschutzrecht.php @@ -11,13 +11,14 @@ use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\DI; -function leistungsschutzrecht_install() { +function leistungsschutzrecht_install() +{ Hook::register('cron', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_cron'); Hook::register('getsiteinfo', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo'); Hook::register('page_info_data', 'addon/leistungsschutzrecht/leistungsschutzrecht.php', 'leistungsschutzrecht_getsiteinfo'); } -function leistungsschutzrecht_getsiteinfo(App $a,array &$siteinfo) { +function leistungsschutzrecht_getsiteinfo(App $a, array &$siteinfo) { if (!isset($siteinfo['url']) || empty($siteinfo['type'])) { return; } @@ -123,13 +124,13 @@ function leistungsschutzrecht_fetchsites() */ if (sizeof($sites)) { - DI::config()->set('leistungsschutzrecht','sites',$sites); + DI::config()->set('leistungsschutzrecht', 'sites',$sites); } } -function leistungsschutzrecht_is_member_site(string $url) +function leistungsschutzrecht_is_member_site(string $url): bool { - $sites = DI::config()->get('leistungsschutzrecht','sites'); + $sites = DI::config()->get('leistungsschutzrecht', 'sites'); if ($sites == '') { return false; @@ -158,10 +159,10 @@ function leistungsschutzrecht_is_member_site(string $url) $site = $hostname[sizeof($hostname) - 2] . '.' . $hostname[sizeof($hostname) - 1]; - return (isset($sites[$site])); + return isset($sites[$site]); } -function leistungsschutzrecht_cron(App $a,$b) +function leistungsschutzrecht_cron(App $a, $b) { $last = DI::config()->get('leistungsschutzrecht', 'last_poll'); From 04df7f6e058626c030c115fd9062156a981cb619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 23 Jun 2022 07:16:22 +0200 Subject: [PATCH 07/19] Changes: - added more type-hints - cleaned up some files (curly braces, spaces) --- birdavatar/birdavatar.php | 2 +- blackout/blackout.php | 15 +- blockbot/blockbot.php | 14 +- buglink/buglink.php | 2 +- calc/calc.php | 21 +- catavatar/catavatar.php | 2 +- convert/convert.php | 5 +- cookienotice/cookienotice.php | 4 +- curweather/curweather.php | 2 +- diaspora/diaspora.php | 4 +- fromapp/fromapp.php | 4 +- geocoordinates/geocoordinates.php | 7 +- gnot/gnot.php | 26 +-- googlemaps/googlemaps.php | 19 +- gravatar/gravatar.php | 15 +- group_text/group_text.php | 2 +- highlightjs/highlightjs.php | 4 +- ijpost/ijpost.php | 6 +- impressum/impressum.php | 163 ++++++++------- .../infiniteimprobabilitydrive.php | 6 +- irc/irc.php | 64 +++--- js_upload/js_upload.php | 6 +- keycloakpassword/keycloakpassword.php | 6 +- krynn/krynn.php | 4 +- langfilter/langfilter.php | 2 +- ldapauth/ldapauth.php | 5 +- libertree/libertree.php | 38 ++-- libravatar/libravatar.php | 7 +- ljpost/ljpost.php | 188 +++++++++--------- mailstream/mailstream.php | 6 +- markdown/markdown.php | 2 +- mathjax/mathjax.php | 4 +- membersince/membersince.php | 2 +- morechoice/morechoice.php | 7 +- morepokes/morepokes.php | 4 +- namethingy/namethingy.php | 26 ++- newmemberwidget/newmemberwidget.php | 7 +- nitter/nitter.php | 2 +- nominatim/nominatim.php | 7 +- notifyall/notifyall.php | 2 +- nsfw/nsfw.php | 2 +- numfriends/numfriends.php | 9 +- openstreetmap/openstreetmap.php | 17 +- opmlexport/opmlexport.php | 3 +- pageheader/pageheader.php | 2 +- piwik/piwik.php | 11 +- planets/planets.php | 12 +- public_server/public_server.php | 12 +- pumpio/pumpio.php | 12 +- pumpio/pumpio_sync.php | 4 +- qcomment/qcomment.php | 4 +- randplace/randplace.php | 82 ++++---- rendertime/rendertime.php | 13 +- s3_storage/s3_storage.php | 2 +- saml/saml.php | 18 +- showmore/showmore.php | 2 +- showmore_dyn/showmore_dyn.php | 4 +- .../lang/smiley_pack_es/smiley_pack_es.php | 4 +- .../lang/smiley_pack_fr/smiley_pack_fr.php | 17 +- smiley_pack/smiley_pack.php | 6 +- smileybutton/smileybutton.php | 2 +- smilies_adult/smilies_adult.php | 9 +- startpage/startpage.php | 4 +- statusnet/statusnet.php | 14 +- superblock/superblock.php | 15 +- testdrive/testdrive.php | 40 ++-- tictac/tictac.php | 18 +- tumblr/tumblr.php | 2 +- twitter/twitter.php | 18 +- unicode_smilies/unicode_smilies.php | 5 +- viewsrc/viewsrc.php | 6 +- webrtc/webrtc.php | 41 ++-- windowsphonepush/windowsphonepush.php | 2 +- wppost/wppost.php | 8 +- 74 files changed, 603 insertions(+), 529 deletions(-) diff --git a/birdavatar/birdavatar.php b/birdavatar/birdavatar.php index b162ea8d..d17a455c 100644 --- a/birdavatar/birdavatar.php +++ b/birdavatar/birdavatar.php @@ -117,7 +117,7 @@ function birdavatar_addon_settings_post(App $a, &$s) * @param $a array * @param &$b array */ -function birdavatar_lookup(App $a, &$b) +function birdavatar_lookup(App $a, array &$b) { $user = DBA::selectFirst('user', ['uid'], ['email' => $b['email']]); if (DBA::isResult($user)) { diff --git a/blackout/blackout.php b/blackout/blackout.php index ecb04c76..e8efecd2 100644 --- a/blackout/blackout.php +++ b/blackout/blackout.php @@ -44,6 +44,7 @@ * THE SOFTWARE. */ +use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; @@ -54,7 +55,8 @@ function blackout_install() { Hook::register('page_header', 'addon/blackout/blackout.php', 'blackout_redirect'); } -function blackout_redirect ($a, $b) { +function blackout_redirect (App $a, $b) +{ // if we have a logged in user, don't throw her out if (local_user()) { return true; @@ -67,20 +69,21 @@ function blackout_redirect ($a, $b) { $now = time(); $date1 = DateTime::createFromFormat('Y-m-d G:i', $mystart); $date2 = DateTime::createFromFormat('Y-m-d G:i', $myend); - if ( $date1 && $date2 ) { + if ($date1 && $date2) { $date1 = DateTime::createFromFormat('Y-m-d G:i', $mystart)->format('U'); $date2 = DateTime::createFromFormat('Y-m-d G:i', $myend)->format('U'); } else { - $date1 = 0; - $date2 = 0; + $date1 = 0; + $date2 = 0; } + if (( $date1 <= $now ) && ( $now <= $date2 )) { Logger::notice('redirecting user to blackout page'); System::externalRedirect($myurl); } } -function blackout_addon_admin(&$a, &$o) { +function blackout_addon_admin(App $a, &$o) { $mystart = DI::config()->get('blackout','begindate'); if (! is_string($mystart)) { $mystart = 'YYYY-MM-DD hh:mm'; } $myend = DI::config()->get('blackout','enddate'); @@ -107,7 +110,7 @@ function blackout_addon_admin(&$a, &$o) { '$aboutredirect' => DI::l10n()->t("Note: The redirect will be active from the moment you press the submit button. Users currently logged in will not be thrown out but can't login again after logging out while the blackout is still in place."), ]); } -function blackout_addon_admin_post (&$a) { +function blackout_addon_admin_post (App $a) { $begindate = trim($_POST['startdate']); $enddate = trim($_POST['enddate']); $url = trim($_POST['rurl']); diff --git a/blockbot/blockbot.php b/blockbot/blockbot.php index 5a9cc4e3..e22dc471 100644 --- a/blockbot/blockbot.php +++ b/blockbot/blockbot.php @@ -19,12 +19,14 @@ use Friendica\Network\HTTPException\ForbiddenException; require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; -function blockbot_install() { +function blockbot_install() +{ Hook::register('init_1', __FILE__, 'blockbot_init_1'); } -function blockbot_addon_admin(&$a, &$o) { - $t = Renderer::getMarkupTemplate("admin.tpl", "addon/blockbot/"); +function blockbot_addon_admin(App $a, &$o) +{ + $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/blockbot/'); $o = Renderer::replaceMacros($t, [ '$submit' => DI::l10n()->t('Save Settings'), @@ -34,13 +36,15 @@ function blockbot_addon_admin(&$a, &$o) { ]); } -function blockbot_addon_admin_post(&$a) { +function blockbot_addon_admin_post(App $a) +{ DI::config()->set('blockbot', 'good_crawlers', $_POST['good_crawlers'] ?? false); DI::config()->set('blockbot', 'block_gab', $_POST['block_gab'] ?? false); DI::config()->set('blockbot', 'training', $_POST['training'] ?? false); } -function blockbot_init_1(App $a) { +function blockbot_init_1(App $a) +{ if (empty($_SERVER['HTTP_USER_AGENT'])) { return; } diff --git a/buglink/buglink.php b/buglink/buglink.php index 9ea20b56..973d08ed 100644 --- a/buglink/buglink.php +++ b/buglink/buglink.php @@ -15,7 +15,7 @@ function buglink_install() Hook::register('page_end', 'addon/buglink/buglink.php', 'buglink_active'); } -function buglink_active(App $a, &$b) +function buglink_active(App $a, array &$b) { $b .= ''; } diff --git a/calc/calc.php b/calc/calc.php index 7019a80f..48371dd3 100644 --- a/calc/calc.php +++ b/calc/calc.php @@ -5,6 +5,8 @@ * Version: 1.0 * Author: Mike Macgirvin */ + +use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; @@ -12,19 +14,19 @@ function calc_install() { Hook::register('app_menu', 'addon/calc/calc.php', 'calc_app_menu'); } -function calc_app_menu($a,&$b) { +function calc_app_menu(App $a, array &$b) +{ $b['app_menu'][] = ''; } -function calc_module() {} +function calc_module() +{ +} - - - -function calc_init($a) { - -$x = <<< EOT +function calc_init(App $a) +{ + $x = <<< EOT ' . "\r\n"; DI::page()['htmlhead'] .= $addScriptTag; @@ -54,7 +55,7 @@ function openstreetmap_alterheader($a, &$navHtml) * @param mixed $a * @param array& $item */ -function openstreetmap_location($a, &$item) +function openstreetmap_location(App $a, &$item) { if (!(strlen($item['location']) || strlen($item['coord']))) { return; @@ -104,7 +105,7 @@ function openstreetmap_location($a, &$item) $item['html'] = ''.$title.''; } -function openstreetmap_get_coordinates($a, &$b) +function openstreetmap_get_coordinates(App $a, array &$b) { $nomserver = DI::config()->get('openstreetmap', 'nomserver', OSM_NOM); @@ -132,7 +133,7 @@ function openstreetmap_get_coordinates($a, &$b) } } -function openstreetmap_generate_named_map(&$a, &$b) +function openstreetmap_generate_named_map(App $a, array &$b) { openstreetmap_get_coordinates($a, $b); @@ -141,7 +142,7 @@ function openstreetmap_generate_named_map(&$a, &$b) } } -function openstreetmap_generate_map(&$a, &$b) +function openstreetmap_generate_map(App $a, array &$b) { $tmsserver = DI::config()->get('openstreetmap', 'tmsserver', OSM_TMS); @@ -177,7 +178,7 @@ function openstreetmap_generate_map(&$a, &$b) Logger::debug('generate_map: ' . $b['html']); } -function openstreetmap_addon_admin(&$a, &$o) +function openstreetmap_addon_admin(App $a, &$o) { $t = Renderer::getMarkupTemplate("admin.tpl", "addon/openstreetmap/"); $tmsserver = DI::config()->get('openstreetmap', 'tmsserver', OSM_TMS); @@ -199,7 +200,7 @@ function openstreetmap_addon_admin(&$a, &$o) ]); } -function openstreetmap_addon_admin_post(&$a) +function openstreetmap_addon_admin_post(App $a) { $urltms = ($_POST['tmsserver'] ?? '') ?: OSM_TMS; $urlnom = ($_POST['nomserver'] ?? '') ?: OSM_NOM; diff --git a/opmlexport/opmlexport.php b/opmlexport/opmlexport.php index c92b5960..a868fe35 100644 --- a/opmlexport/opmlexport.php +++ b/opmlexport/opmlexport.php @@ -82,10 +82,11 @@ function opmlexport_addon_settings(App $a, array &$data) } -function opmlexport_addon_settings_post(App $a, &$b) +function opmlexport_addon_settings_post(App $a, array &$b) { if (!local_user() || empty($_POST['opmlexport-submit'])) { return; } + opmlexport($a); } diff --git a/pageheader/pageheader.php b/pageheader/pageheader.php index 9dfe3c02..5b1bb1b7 100644 --- a/pageheader/pageheader.php +++ b/pageheader/pageheader.php @@ -52,7 +52,7 @@ function pageheader_addon_admin_post(App $a) } } -function pageheader_fetch(App $a, &$b) +function pageheader_fetch(App $a, array &$b) { if(file_exists('pageheader.html')){ $s = file_get_contents('pageheader.html'); diff --git a/piwik/piwik.php b/piwik/piwik.php index 8c4f91df..78d737d1 100644 --- a/piwik/piwik.php +++ b/piwik/piwik.php @@ -31,6 +31,7 @@ * setting. */ +use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; @@ -44,13 +45,13 @@ function piwik_install() { Logger::notice("installed piwik addon"); } -function piwik_load_config(\Friendica\App $a, ConfigFileLoader $loader) +function piwik_load_config(App $a, ConfigFileLoader $loader) { $a->getConfigCache()->load($loader->loadAddonConfig('piwik')); } -function piwik_analytics($a,&$b) { - +function piwik_analytics(App $a, array &$b) +{ /* * styling of every HTML block added by this addon is done in the * associated CSS file. We just have to tell Friendica to get it @@ -90,7 +91,7 @@ function piwik_analytics($a,&$b) { $b .= ""; } } -function piwik_addon_admin (&$a, &$o) { +function piwik_addon_admin (App $a, &$o) { $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/piwik/" ); $o = Renderer::replaceMacros( $t, [ '$submit' => DI::l10n()->t('Save Settings'), @@ -100,7 +101,7 @@ function piwik_addon_admin (&$a, &$o) { '$async' => ['async', DI::l10n()->t('Asynchronous tracking'), DI::config()->get('piwik','async' ), ''], ]); } -function piwik_addon_admin_post (&$a) { +function piwik_addon_admin_post (App $a) { $url = trim($_POST['baseurl'] ?? ''); $id = trim($_POST['siteid'] ?? ''); $optout = trim($_POST['optout'] ?? ''); diff --git a/planets/planets.php b/planets/planets.php index ef88db13..6b7c2527 100644 --- a/planets/planets.php +++ b/planets/planets.php @@ -38,7 +38,7 @@ function planets_install() { Logger::notice("installed planets"); } -function planets_post_hook($a, &$item) { +function planets_post_hook(App $a, &$item) { /** * @@ -96,11 +96,13 @@ function planets_post_hook($a, &$item) { * */ -function planets_settings_post($a,$post) { - if(! local_user()) +function planets_settings_post(App $a,$post) { + if (! local_user()) { return; - if($_POST['planets-submit']) - DI::pConfig()->set(local_user(),'planets','enable',intval($_POST['planets'])); + } + if ($_POST['planets-submit']) { + DI::pConfig()->set(local_user(), 'planets', 'enable' ,intval($_POST['planets'])); + } } diff --git a/public_server/public_server.php b/public_server/public_server.php index c6e3c364..7221e1b1 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -32,7 +32,7 @@ function public_server_load_config(App $a, ConfigFileLoader $loader) $a->getConfigCache()->load($loader->loadAddonConfig('public_server')); } -function public_server_register_account($a, $b) +function public_server_register_account(App $a, $b) { $uid = $b; @@ -46,7 +46,7 @@ function public_server_register_account($a, $b) DBA::update('user', $fields, ['uid' => $uid]); } -function public_server_cron($a, $b) +function public_server_cron(App $a, $b) { Logger::notice("public_server: cron start"); @@ -99,7 +99,7 @@ function public_server_cron($a, $b) Logger::notice("public_server: cron end"); } -function public_server_enotify(&$a, &$b) +function public_server_enotify(App $a, array &$b) { if (!empty($b['params']) && $b['params']['type'] == Notification\Type::SYSTEM && !empty($b['params']['system_type']) && $b['params']['system_type'] === 'public_server_expire') { @@ -110,7 +110,7 @@ function public_server_enotify(&$a, &$b) } } -function public_server_login($a, $b) +function public_server_login(App $a, $b) { $days = DI::config()->get('public_server', 'expiredays'); if (!$days) { @@ -122,7 +122,7 @@ function public_server_login($a, $b) DBA::update('user', $fields, $condition); } -function public_server_addon_admin_post(&$a) +function public_server_addon_admin_post(App $a) { BaseModule::checkFormSecurityTokenRedirectOnError('/admin/addons/publicserver', 'publicserver'); $expiredays = trim($_POST['expiredays'] ?? ''); @@ -139,7 +139,7 @@ function public_server_addon_admin_post(&$a) DI::config()->set('public_server', 'flagpostsexpire', $flagpostsexpire); } -function public_server_addon_admin(&$a, &$o) +function public_server_addon_admin(App $a, &$o) { $token = BaseModule::getFormSecurityToken("publicserver"); $t = Renderer::getMarkupTemplate("admin.tpl", "addon/public_server"); diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 1253d376..82a5ef9b 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -59,7 +59,7 @@ function pumpio_content(App $a) return ''; } - require_once("mod/settings.php"); + require_once 'mod/settings.php'; settings_init($a); if (isset(DI::args()->getArgv()[1])) { @@ -77,7 +77,7 @@ function pumpio_content(App $a) return $o; } -function pumpio_check_item_notification($a, &$notification_data) +function pumpio_check_item_notification(App $a, &$notification_data) { $hostname = DI::pConfig()->get($notification_data["uid"], 'pumpio', 'host'); $username = DI::pConfig()->get($notification_data["uid"], "pumpio", "user"); @@ -686,7 +686,7 @@ function pumpio_cron(App $a, $b) Worker::add(PRIORITY_MEDIUM,"addon/pumpio/pumpio_sync.php"); } -function pumpio_fetchtimeline(App $a, $uid) +function pumpio_fetchtimeline(App $a, int $uid) { $ckey = DI::pConfig()->get($uid, 'pumpio', 'consumer_key'); $csecret = DI::pConfig()->get($uid, 'pumpio', 'consumer_secret'); @@ -1195,7 +1195,7 @@ function pumpio_dopost(App $a, $client, $uid, $self, $post, $own_id, $threadcomp return $top_item; } -function pumpio_fetchinbox(App $a, $uid) +function pumpio_fetchinbox(App $a, int $uid) { $ckey = DI::pConfig()->get($uid, 'pumpio', 'consumer_key'); $csecret = DI::pConfig()->get($uid, 'pumpio', 'consumer_secret'); @@ -1254,14 +1254,14 @@ function pumpio_fetchinbox(App $a, $uid) } while ($item = DBA::fetch($lastitems)) { - pumpio_fetchallcomments($a, $uid, $item["uri"]); + pumpio_fetchallcomments($a, $uid, $item['uri']); } DBA::close($lastitems); DI::pConfig()->set($uid, 'pumpio', 'last_id', $last_id); } -function pumpio_getallusers(App &$a, $uid) +function pumpio_getallusers(App &$a, int $uid) { $ckey = DI::pConfig()->get($uid, 'pumpio', 'consumer_key'); $csecret = DI::pConfig()->get($uid, 'pumpio', 'consumer_secret'); diff --git a/pumpio/pumpio_sync.php b/pumpio/pumpio_sync.php index 53a8da11..892b6ad4 100644 --- a/pumpio/pumpio_sync.php +++ b/pumpio/pumpio_sync.php @@ -2,10 +2,10 @@ use Friendica\Core\Logger; use Friendica\DI; -function pumpio_sync_run($argv, $argc) { +function pumpio_sync_run(array $argv, int $argc) { $a = Friendica\DI::app(); - require_once("addon/pumpio/pumpio.php"); + require_once 'addon/pumpio/pumpio.php'; if (function_exists('sys_getloadavg')) { $load = sys_getloadavg(); diff --git a/qcomment/qcomment.php b/qcomment/qcomment.php index aec4e9bf..8f059b1f 100644 --- a/qcomment/qcomment.php +++ b/qcomment/qcomment.php @@ -31,7 +31,7 @@ function qcomment_install() Hook::register('footer' , __FILE__, 'qcomment_footer'); } -function qcomment_footer(App $a, &$b) +function qcomment_footer(App $a, array &$b) { DI::page()->registerFooterScript('addon/qcomment/qcomment.js'); } @@ -57,7 +57,7 @@ function qcomment_addon_settings(App &$a, array &$data) ]; } -function qcomment_addon_settings_post(&$a, &$b) +function qcomment_addon_settings_post(App $a, array &$b) { if (! local_user()) { return; diff --git a/randplace/randplace.php b/randplace/randplace.php index 69ad4d52..f421bbb4 100644 --- a/randplace/randplace.php +++ b/randplace/randplace.php @@ -25,75 +25,67 @@ use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\DI; -function randplace_install() { - - /** - * +function randplace_install() +{ + /* * Our demo addon will attach in three places. * The first is just prior to storing a local post. - * */ - Hook::register('post_local', 'addon/randplace/randplace.php', 'randplace_post_hook'); - /** - * + /* * Then we'll attach into the addon settings page, and also the * settings post hook so that we can create and update * user preferences. - * */ - Hook::register('addon_settings', 'addon/randplace/randplace.php', 'randplace_settings'); Hook::register('addon_settings_post', 'addon/randplace/randplace.php', 'randplace_settings_post'); Logger::notice("installed randplace"); } - -function randplace_uninstall() { - - /** - * +function randplace_uninstall() +{ + /* * This function should undo anything that was done in name_install() * * Except hooks, they are all unregistered automatically and don't need to be unregistered manually. - * */ - Logger::notice("removed randplace"); } - - -function randplace_post_hook($a, &$item) { - - /** - * +function randplace_post_hook(App $a, &$item) +{ + /* * An item was posted on the local system. * We are going to look for specific items: * - A status post by a profile owner * - The profile owner must have allowed our addon - * */ - Logger::notice('randplace invoked'); - if(! local_user()) /* non-zero if this is a logged in user of this system */ + if (!local_user()) { + /* non-zero if this is a logged in user of this system */ return; + } - if(local_user() != $item['uid']) /* Does this person own the post? */ + if (local_user() != $item['uid']) { + /* Does this person own the post? */ return; + } - if($item['parent']) /* If the item has a parent, this is a comment or something else, not a status post. */ + if ($item['parent']) { + /* If the item has a parent, this is a comment or something else, not a status post. */ return; + } /* Retrieve our personal config setting */ $active = DI::pConfig()->get(local_user(), 'randplace', 'enable'); - if(! $active) + if (!$active) { return; + } /** * @@ -107,47 +99,43 @@ function randplace_post_hook($a, &$item) { $cities = []; $zones = timezone_identifiers_list(); foreach($zones as $zone) { - if((strpos($zone,'/')) && (! stristr($zone,'US/')) && (! stristr($zone,'Etc/'))) - $cities[] = str_replace('_', ' ',substr($zone,strpos($zone,'/') + 1)); + if ((strpos($zone, '/')) && (! stristr($zone, 'US/')) && (! stristr($zone, 'Etc/'))) { + $cities[] = str_replace('_', ' ',substr($zone, strpos($zone, '/') + 1)); + } } - if(! count($cities)) + if (!count($cities)) { return; + } + $city = array_rand($cities,1); $item['location'] = $cities[$city]; return; } - - - /** - * * Callback from the settings post function. * $post contains the $_POST array. * We will make sure we've got a valid user account * and if so set our configuration setting for this person. - * */ - -function randplace_settings_post($a,$post) { - if(! local_user()) +function randplace_settings_post(App $a, $post) +{ + if (!local_user()) { return; - if($_POST['randplace-submit']) - DI::pConfig()->set(local_user(),'randplace','enable',intval($_POST['randplace'])); + } + + if ($_POST['randplace-submit']) { + DI::pConfig()->set(local_user(), 'randplace', 'enable', intval($_POST['randplace'])); + } } /** - * * Called from the Addon Setting form. * Add our own settings info to the page. - * */ - - - function randplace_settings(App &$a, array &$data) { if(! local_user()) { diff --git a/rendertime/rendertime.php b/rendertime/rendertime.php index f433c3a4..e87f495b 100644 --- a/rendertime/rendertime.php +++ b/rendertime/rendertime.php @@ -7,6 +7,7 @@ * */ +use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\Renderer; use Friendica\DI; @@ -16,14 +17,17 @@ function rendertime_install() { DI::config()->set('system', 'profiler', true); } -function rendertime_uninstall() { +function rendertime_uninstall() +{ DI::config()->delete('system', 'profiler'); } -function rendertime_init_1(&$a) { +function rendertime_init_1(App $a) +{ } -function rendertime_addon_admin(&$a, &$o) { +function rendertime_addon_admin(App $a, &$o) +{ $t = Renderer::getMarkupTemplate("admin.tpl", "addon/rendertime/"); $o = Renderer::replaceMacros($t, [ @@ -33,7 +37,8 @@ function rendertime_addon_admin(&$a, &$o) { ]); } -function rendertime_addon_admin_post(&$a) { +function rendertime_addon_admin_post(App $a) +{ DI::config()->set('rendertime', 'callstack', $_POST['callstack'] ?? false); DI::config()->set('rendertime', 'minimal_time', $_POST['minimal_time'] ?? 0); } diff --git a/s3_storage/s3_storage.php b/s3_storage/s3_storage.php index a60ec077..c4f68da9 100644 --- a/s3_storage/s3_storage.php +++ b/s3_storage/s3_storage.php @@ -14,7 +14,7 @@ use Friendica\DI; require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; -function s3_storage_install($a) +function s3_storage_install(App $a) { Hook::register('storage_instance' , __FILE__, 's3_storage_instance'); Hook::register('storage_config' , __FILE__, 's3_storage_config'); diff --git a/saml/saml.php b/saml/saml.php index 25a4ad37..dc25ae6d 100755 --- a/saml/saml.php +++ b/saml/saml.php @@ -5,6 +5,8 @@ * Version: 1.0 * Author: Ryan */ + +use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; @@ -14,6 +16,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\User; use Friendica\Util\Strings; +use OneLogin\Saml2\Utils; require_once(__DIR__ . '/vendor/autoload.php'); @@ -77,12 +80,12 @@ function saml_install() Hook::register('footer', __FILE__, 'saml_footer'); } -function saml_head(&$a, &$b) +function saml_head(App $a, array &$b) { DI::page()->registerStylesheet(__DIR__ . '/saml.css'); } -function saml_footer(&$a, &$b) +function saml_footer(App $a, array &$b) { $fragment = addslashes(BBCode::convert(DI::config()->get('saml', 'settings_statement'))); $b .= <<get('saml', 'idp_cert'); } -function saml_sso_initiate(&$a, &$b) +function saml_sso_initiate(App $a, array &$b) { if (!saml_is_configured()) { Logger::warning('SAML SSO tried to trigger, but the SAML addon is not configured yet!'); @@ -166,13 +169,12 @@ function saml_sso_reply($a) DI::auth()->setForUser($a, $user); } - if (isset($_POST['RelayState']) - && \OneLogin\Saml2\Utils::getSelfURL() != $_POST['RelayState']) { + if (isset($_POST['RelayState']) && Utils::getSelfURL() != $_POST['RelayState']) { $auth->redirectTo($_POST['RelayState']); } } -function saml_slo_initiate(&$a, &$b) +function saml_slo_initiate(App $a, array &$b) { if (!saml_is_configured()) { Logger::warning('SAML SLO tried to trigger, but the SAML addon is not configured yet!'); @@ -223,7 +225,7 @@ function saml_input($key, $label, $description) ]; } -function saml_addon_admin(&$a, &$o) +function saml_addon_admin(App $a, &$o) { $form = saml_input( @@ -279,7 +281,7 @@ function saml_addon_admin(&$a, &$o) $o = Renderer::replaceMacros($t, $form); } -function saml_addon_admin_post(&$a) +function saml_addon_admin_post(App $a) { $set = function ($key) { $val = (!empty($_POST[$key]) ? trim($_POST[$key]) : ''); diff --git a/showmore/showmore.php b/showmore/showmore.php index 945277ae..e7d53f8a 100644 --- a/showmore/showmore.php +++ b/showmore/showmore.php @@ -45,7 +45,7 @@ function showmore_addon_settings(App &$a, array &$data) ]; } -function showmore_addon_settings_post(&$a, &$b) +function showmore_addon_settings_post(App $a, array &$b) { if (!local_user()) { return; diff --git a/showmore_dyn/showmore_dyn.php b/showmore_dyn/showmore_dyn.php index 39dfa489..71ef0dc7 100644 --- a/showmore_dyn/showmore_dyn.php +++ b/showmore_dyn/showmore_dyn.php @@ -24,12 +24,12 @@ function showmore_dyn_install() Hook::register('addon_settings_post', __FILE__, 'showmore_dyn_settings_post'); } -function showmore_dyn_head(App $a, &$b) +function showmore_dyn_head(App $a, array &$b) { DI::page()->registerStylesheet(__DIR__ . '/showmore_dyn.css'); } -function showmore_dyn_footer(App $a, &$b) +function showmore_dyn_footer(App $a, array &$b) { DI::page()->registerFooterScript(__DIR__ . '/showmore_dyn.js'); } diff --git a/smiley_pack/lang/smiley_pack_es/smiley_pack_es.php b/smiley_pack/lang/smiley_pack_es/smiley_pack_es.php index 329b7282..34ee7697 100644 --- a/smiley_pack/lang/smiley_pack_es/smiley_pack_es.php +++ b/smiley_pack/lang/smiley_pack_es/smiley_pack_es.php @@ -6,6 +6,8 @@ * Author: Thomas Willingham (based on Mike Macgirvin's Adult Smile template) * All smileys from sites offering them as Public Domain */ + +use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; @@ -13,7 +15,7 @@ function smiley_pack_es_install() { Hook::register('smilie', 'addon/smiley_pack_es/smiley_pack_es.php', 'smiley_pack_smilies_es'); } -function smiley_pack_smilies_es(&$a,&$b) { +function smiley_pack_smilies_es(App $a, array &$b) { #Smileys are split into various directories by the intended range of emotions. This is in case we get too big and need to modularise things. We can then cut and paste the right lines, move the right directory, and just change the name of the addon to happy_smilies or whatever. diff --git a/smiley_pack/lang/smiley_pack_fr/smiley_pack_fr.php b/smiley_pack/lang/smiley_pack_fr/smiley_pack_fr.php index bcefa7c3..9bdce46e 100644 --- a/smiley_pack/lang/smiley_pack_fr/smiley_pack_fr.php +++ b/smiley_pack/lang/smiley_pack_fr/smiley_pack_fr.php @@ -3,19 +3,23 @@ * Name: Smiley Pack (Français) * Description: Pack of smileys that make master too AOLish. * Version: 1.01 - * Author: Thomas Willingham (based on Mike Macgirvin's Adult Smile template) + * Author: Thomas Willingham (based on Mike Macgirvin's Adult Smile template) * All smileys from sites offering them as Public Domain - * - * + * + * */ + +use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; -function smiley_pack_fr_install() { +function smiley_pack_fr_install() +{ Hook::register('smilie', 'addon/smiley_pack_fr/smiley_pack_fr.php', 'smiley_pack_fr_smilies'); } -function smiley_pack_fr_smilies(&$a,&$b) { +function smiley_pack_fr_smilies(App $a, array &$b) +{ #Smileys are split into various directories by the intended range of emotions. This is in case we get too big and need to modularise things. We can then cut and paste the right lines, move the right directory, and just change the name of the addon to happy_smilies or whatever. @@ -392,7 +396,7 @@ function smiley_pack_fr_smilies(&$a,&$b) { $b['texts'][] = ':cognetête'; $b['icons'][] = '' . ':cognetête' . ''; - $b['texts'][] = ':barbu'; + $b['texts'][] = ':barbu'; $b['icons'][] = '' . ':barbu' . ''; $b['texts'][] = ':barbeblanche'; @@ -400,5 +404,4 @@ function smiley_pack_fr_smilies(&$a,&$b) { $b['texts'][] = ':tête'; $b['icons'][] = '' . ':tête' . ''; - } diff --git a/smiley_pack/smiley_pack.php b/smiley_pack/smiley_pack.php index c8c19b96..d457ea8c 100644 --- a/smiley_pack/smiley_pack.php +++ b/smiley_pack/smiley_pack.php @@ -8,6 +8,7 @@ * All smileys from sites offering them as Public Domain */ +use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; @@ -15,8 +16,8 @@ function smiley_pack_install() { Hook::register('smilie', 'addon/smiley_pack/smiley_pack.php', 'smiley_pack_smilies'); } -function smiley_pack_smilies(&$a,&$b) { - +function smiley_pack_smilies(App $a, array &$b) +{ #Smileys are split into various directories by the intended range of emotions. This is in case we get too big and need to modularise things. We can then cut and paste the right lines, move the right directory, and just change the name of the addon to happy_smilies or whatever. #Be careful with invocation strings. If you have a smiley called foo, and another called foobar, typing :foobar will call foo. Avoid this with clever naming, using ~ instead of : @@ -538,5 +539,4 @@ function smiley_pack_smilies(&$a,&$b) { $b['texts'][] = ':twitch:'; $b['icons'][] = '' . ':twitch:' . ''; - } diff --git a/smileybutton/smileybutton.php b/smileybutton/smileybutton.php index 1a1f1d63..abb71d3d 100644 --- a/smileybutton/smileybutton.php +++ b/smileybutton/smileybutton.php @@ -16,7 +16,7 @@ function smileybutton_install() Hook::register('jot_tool', 'addon/smileybutton/smileybutton.php', 'smileybutton_jot_tool'); } -function smileybutton_jot_tool(Friendica\App $a, &$b) +function smileybutton_jot_tool(Friendica\App $a, array &$b) { // Disable if theme is quattro // TODO add style for quattro diff --git a/smilies_adult/smilies_adult.php b/smilies_adult/smilies_adult.php index b55a0a2f..1994d915 100644 --- a/smilies_adult/smilies_adult.php +++ b/smilies_adult/smilies_adult.php @@ -8,6 +8,8 @@ * This is a template for how to extend the "smily" code. * */ + +use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; @@ -15,8 +17,8 @@ function smilies_adult_install() { Hook::register('smilie', 'addon/smilies_adult/smilies_adult.php', 'smilies_adult_smilies'); } -function smilies_adult_smilies(&$a,&$b) { - +function smilies_adult_smilies(App $a, array &$b) +{ $b['texts'][] = '(o)(o)'; $b['icons'][] = '' . '(o)(o)' . ''; @@ -34,5 +36,4 @@ function smilies_adult_smilies(&$a,&$b) { $b['texts'][] = ':finger'; $b['icons'][] = '' . ':finger' . ''; - -} \ No newline at end of file +} diff --git a/startpage/startpage.php b/startpage/startpage.php index d72effde..1e5edeea 100644 --- a/startpage/startpage.php +++ b/startpage/startpage.php @@ -18,7 +18,7 @@ function startpage_install() { Hook::register('addon_settings_post', 'addon/startpage/startpage.php', 'startpage_settings_post'); } -function startpage_home_init($a, $b) +function startpage_home_init(App $a, $b) { if (!local_user()) { return; @@ -40,7 +40,7 @@ function startpage_home_init($a, $b) * */ -function startpage_settings_post($a, $post) +function startpage_settings_post(App $a, $post) { if (!local_user()) { return; diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 66648893..a6b5fec8 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -373,7 +373,7 @@ function statusnet_hook_fork(App $a, array &$b) } } -function statusnet_post_local(App $a, &$b) +function statusnet_post_local(App $a, array &$b) { if ($b['edit']) { return; @@ -430,7 +430,7 @@ function statusnet_action(App $a, $uid, $pid, $action) Logger::info('statusnet_action "' . $action . '" send, result: ' . print_r($result, true)); } -function statusnet_post_hook(App $a, &$b) +function statusnet_post_hook(App $a, array &$b) { /** * Post to GNU Social @@ -661,7 +661,7 @@ function statusnet_addon_admin(App $a, &$o) ]); } -function statusnet_prepare_body(App $a, &$b) +function statusnet_prepare_body(App $a, array &$b) { if ($b['item']['network'] != Protocol::STATUSNET) { return; @@ -753,7 +753,7 @@ function statusnet_cron(App $a, $b) DI::config()->set('statusnet', 'last_poll', time()); } -function statusnet_fetchtimeline(App $a, $uid) +function statusnet_fetchtimeline(App $a, int $uid) { $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); @@ -1011,7 +1011,7 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = '', $user_id = '') return $contact_id; } -function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_existing_contact) +function statusnet_createpost(App $a, int $uid, $post, $self, $create_user, bool $only_existing_contact) { Logger::info('statusnet_createpost: start'); @@ -1415,7 +1415,7 @@ function statusnet_convertmsg(App $a, $body) return $body; } -function statusnet_fetch_own_contact(App $a, $uid) +function statusnet_fetch_own_contact(App $a, int $uid) { $ckey = DI::pConfig()->get($uid, 'statusnet', 'consumerkey'); $csecret = DI::pConfig()->get($uid, 'statusnet', 'consumersecret'); @@ -1450,7 +1450,7 @@ function statusnet_fetch_own_contact(App $a, $uid) return $contact_id; } -function statusnet_is_retweet(App $a, $uid, $body) +function statusnet_is_retweet(App $a, int $uid, string $body) { $body = trim($body); diff --git a/superblock/superblock.php b/superblock/superblock.php index 5c5cfcc3..3a1422ce 100644 --- a/superblock/superblock.php +++ b/superblock/superblock.php @@ -42,7 +42,7 @@ function superblock_addon_settings(App &$a, array &$data) ]; } -function superblock_addon_settings_post(&$a, &$b) +function superblock_addon_settings_post(App $a, array &$b) { if (!local_user()) { return; @@ -53,7 +53,8 @@ function superblock_addon_settings_post(&$a, &$b) } } -function superblock_enotify_store(&$a,&$b) { +function superblock_enotify_store(App $a, array &$b) +{ if (empty($b['uid'])) { return; } @@ -78,6 +79,7 @@ function superblock_enotify_store(&$a,&$b) { } } } + if ($found) { // Empty out the fields $b = []; @@ -85,7 +87,7 @@ function superblock_enotify_store(&$a,&$b) { } -function superblock_conversation_start(&$a, &$b) +function superblock_conversation_start(App $a, array &$b) { if (!local_user()) { return; @@ -95,8 +97,8 @@ function superblock_conversation_start(&$a, &$b) if ($words) { $a->data['superblock'] = explode(',', $words); } - DI::page()['htmlhead'] .= <<< EOT + DI::page()['htmlhead'] .= <<< EOT - EOT; } -function superblock_item_photo_menu(&$a, &$b) +function superblock_item_photo_menu(App $a, array &$b) { if (!local_user() || $b['item']['self']) { return; @@ -132,7 +133,7 @@ function superblock_item_photo_menu(&$a, &$b) function superblock_module() {} -function superblock_init(&$a) +function superblock_init(App $a) { if (!local_user()) { return; diff --git a/testdrive/testdrive.php b/testdrive/testdrive.php index 042edcc9..94e63dda 100644 --- a/testdrive/testdrive.php +++ b/testdrive/testdrive.php @@ -16,14 +16,13 @@ use Friendica\Model\User; use Friendica\Core\Config\Util\ConfigFileLoader; use Friendica\Util\DateTimeFormat; -function testdrive_install() { - +function testdrive_install() +{ Hook::register('load_config', 'addon/testdrive/testdrive.php', 'testdrive_load_config'); Hook::register('register_account', 'addon/testdrive/testdrive.php', 'testdrive_register_account'); Hook::register('cron', 'addon/testdrive/testdrive.php', 'testdrive_cron'); Hook::register('enotify','addon/testdrive/testdrive.php', 'testdrive_enotify'); Hook::register('globaldir_update','addon/testdrive/testdrive.php', 'testdrive_globaldir_update'); - } function testdrive_load_config(App $a, ConfigFileLoader $loader) @@ -31,26 +30,30 @@ function testdrive_load_config(App $a, ConfigFileLoader $loader) $a->getConfigCache()->load($loader->loadAddonConfig('testdrive')); } -function testdrive_globaldir_update($a,&$b) { +function testdrive_globaldir_update(App $a, array &$b) +{ $b['url'] = ''; } -function testdrive_register_account($a,$b) { - +function testdrive_register_account(App $a, $b) +{ $uid = $b; $days = DI::config()->get('testdrive','expiredays'); - if(! $days) + if (!$days) { return; + } DBA::update('user', ['account_expires_on' => DateTimeFormat::convert('now +' . $days . ' days')], ['uid' => $uid]); -}; +} -function testdrive_cron($a,$b) { +function testdrive_cron(App $a, $b) +{ $users = DBA::selectToArray('user', [], ["`account_expires_on` < ? AND `expire_notification_sent` <= ?", - DateTimeFormat::utc('now + 5 days'), DBA::NULL_DATETIME]); - foreach($users as $rr) { + DateTimeFormat::utc('now + 5 days'), DBA::NULL_DATETIME]); + + foreach ($users as $rr) { DI::notify()->createFromArray([ 'type' => Notification\Type::SYSTEM, 'uid' => $rr['uid'], @@ -69,12 +72,13 @@ function testdrive_cron($a,$b) { } } -function testdrive_enotify(&$a, &$b) { - if (!empty($b['params']) && $b['params']['type'] == Notification\Type::SYSTEM +function testdrive_enotify(App $a, array &$b) +{ + if (!empty($b['params']) && $b['params']['type'] == Notification\Type::SYSTEM && !empty($b['params']['system_type']) && $b['params']['system_type'] === 'testdrive_expire') { - $b['itemlink'] = DI::baseUrl()->get(); - $b['epreamble'] = $b['preamble'] = DI::l10n()->t('Your account on %s will expire in a few days.', DI::config()->get('system', 'sitename')); - $b['subject'] = DI::l10n()->t('Your Friendica test account is about to expire.'); - $b['body'] = DI::l10n()->t("Hi %1\$s,\n\nYour test account on %2\$s will expire in less than five days. We hope you enjoyed this test drive and use this opportunity to find a permanent Friendica website for your integrated social communications. A list of public sites is available at %s/siteinfo - and for more information on setting up your own Friendica server please see the Friendica project website at https://friendi.ca.", $b['params']['to_name'], "[url=".DI::config()->get('system', 'url')."]".DI::config()->get('config', 'sitename')."[/url]", Search::getGlobalDirectory()); - } + $b['itemlink'] = DI::baseUrl()->get(); + $b['epreamble'] = $b['preamble'] = DI::l10n()->t('Your account on %s will expire in a few days.', DI::config()->get('system', 'sitename')); + $b['subject'] = DI::l10n()->t('Your Friendica test account is about to expire.'); + $b['body'] = DI::l10n()->t("Hi %1\$s,\n\nYour test account on %2\$s will expire in less than five days. We hope you enjoyed this test drive and use this opportunity to find a permanent Friendica website for your integrated social communications. A list of public sites is available at %s/siteinfo - and for more information on setting up your own Friendica server please see the Friendica project website at https://friendi.ca.", $b['params']['to_name'], "[url=".DI::config()->get('system', 'url')."]".DI::config()->get('config', 'sitename')."[/url]", Search::getGlobalDirectory()); + } } diff --git a/tictac/tictac.php b/tictac/tictac.php index 4d3a46b4..fb746f94 100644 --- a/tictac/tictac.php +++ b/tictac/tictac.php @@ -5,27 +5,27 @@ * Version: 1.0 * Author: Mike Macgirvin */ + +use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; -function tictac_install() { +function tictac_install() +{ Hook::register('app_menu', 'addon/tictac/tictac.php', 'tictac_app_menu'); } -function tictac_app_menu($a,&$b) { +function tictac_app_menu(App $a, array &$b) +{ $b['app_menu'][] = ''; } - -function tictac_module() { +function tictac_module() +{ return; } - - - - -function tictac_content(&$a) { +function tictac_content(App $a) { $o = ''; diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 5ae0dd1b..a66634d4 100644 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -257,7 +257,7 @@ function tumblr_settings_post(App $a, array &$b) } } -function tumblr_hook_fork(&$a, &$b) +function tumblr_hook_fork(App $a, array &$b) { if ($b['name'] != 'notifier_normal') { return; diff --git a/twitter/twitter.php b/twitter/twitter.php index 458677ce..fe5ee4fd 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -1149,7 +1149,7 @@ function twitter_parse_link(App $a, array &$b) * * @return array item data to be posted */ -function twitter_do_mirrorpost(App $a, $uid, $post) +function twitter_do_mirrorpost(App $a, int $uid, $post) { $datarray['uid'] = $uid; $datarray['extid'] = 'twitter::' . $post->id; @@ -1196,7 +1196,7 @@ function twitter_do_mirrorpost(App $a, $uid, $post) return $datarray; } -function twitter_fetchtimeline(App $a, $uid) +function twitter_fetchtimeline(App $a, int $uid) { $ckey = DI::config()->get('twitter', 'consumerkey'); $csecret = DI::config()->get('twitter', 'consumersecret'); @@ -1740,7 +1740,7 @@ function twitter_media_entities($post, array &$postarray, int $uriid = -1) * @param integer $uriid URI Id used to store tags. 0 = create a new one; -1 = don't store tags for this post. * @return array item array */ -function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $only_existing_contact, $noquote, int $uriid = 0) +function twitter_createpost(App $a, int $uid, $post, array $self, $create_user, bool $only_existing_contact, $noquote, int $uriid = 0) { $postarray = []; $postarray['network'] = Protocol::TWITTER; @@ -1951,7 +1951,7 @@ function twitter_store_tags(int $uriid, array $taglist) } } -function twitter_fetchparentposts(App $a, $uid, $post, TwitterOAuth $connection, array $self) +function twitter_fetchparentposts(App $a, int $uid, $post, TwitterOAuth $connection, array $self) { Logger::info('Fetching parent posts', ['user' => $uid, 'post' => $post->id_str]); @@ -2003,7 +2003,7 @@ function twitter_fetchparentposts(App $a, $uid, $post, TwitterOAuth $connection, } } -function twitter_fetchhometimeline(App $a, $uid) +function twitter_fetchhometimeline(App $a, int $uid) { $ckey = DI::config()->get('twitter', 'consumerkey'); $csecret = DI::config()->get('twitter', 'consumersecret'); @@ -2192,7 +2192,7 @@ function twitter_fetchhometimeline(App $a, $uid) Logger::info('Last mentions ID for user ' . $uid . ' is now ' . $lastid); } -function twitter_fetch_own_contact(App $a, $uid) +function twitter_fetch_own_contact(App $a, int $uid) { $ckey = DI::config()->get('twitter', 'consumerkey'); $csecret = DI::config()->get('twitter', 'consumersecret'); @@ -2228,7 +2228,7 @@ function twitter_fetch_own_contact(App $a, $uid) return $contact_id; } -function twitter_is_retweet(App $a, $uid, $body) +function twitter_is_retweet(App $a, int $uid, string $body) { $body = trim($body); @@ -2283,7 +2283,7 @@ function twitter_retweet(int $uid, int $id, int $item_id = 0) return !isset($result->errors); } -function twitter_update_mentions($body) +function twitter_update_mentions(string $body): string { $URLSearchString = '^\[\]'; $return = preg_replace_callback( @@ -2303,7 +2303,7 @@ function twitter_update_mentions($body) return $return; } -function twitter_convert_share(array $attributes, array $author_contact, $content, $is_quote_share) +function twitter_convert_share(array $attributes, array $author_contact, string $content, bool $is_quote_share): string { if (empty($author_contact)) { return $content . "\n\n" . $attributes['link']; diff --git a/unicode_smilies/unicode_smilies.php b/unicode_smilies/unicode_smilies.php index 45c2351a..1ff405ba 100644 --- a/unicode_smilies/unicode_smilies.php +++ b/unicode_smilies/unicode_smilies.php @@ -6,6 +6,8 @@ * Author: Michael Vogel * Author: Matthias Ebers */ + +use Friendica\App; use Friendica\Content\Smilies; use Friendica\Core\Hook; @@ -13,7 +15,8 @@ function unicode_smilies_install() { Hook::register('smilie', 'addon/unicode_smilies/unicode_smilies.php', 'unicode_smilies_smilies'); } -function unicode_smilies_smilies(&$a,&$b) { +function unicode_smilies_smilies(App $a, array &$b) +{ Smilies::add($b, ':-)', '😀'); Smilies::add($b, ':)', '😀'); Smilies::add($b, ':-(', '🙁'); diff --git a/viewsrc/viewsrc.php b/viewsrc/viewsrc.php index 445d8ee5..48029835 100644 --- a/viewsrc/viewsrc.php +++ b/viewsrc/viewsrc.php @@ -6,6 +6,8 @@ * Author: Mike Macgirvin * */ + +use Friendica\App; use Friendica\Core\Hook; use Friendica\DI; @@ -14,7 +16,7 @@ function viewsrc_install() { Hook::register('page_end', 'addon/viewsrc/viewsrc.php', 'viewsrc_page_end'); } -function viewsrc_page_end(&$a, &$o){ +function viewsrc_page_end(App $a, &$o){ DI::page()['htmlhead'] .= <<< EOS