From fc7369835258467bf97eb64f184b93691f9a9fd5 Mon Sep 17 00:00:00 2001 From: Yaco Date: Thu, 4 Jun 2020 11:01:00 -0300 Subject: first commit --- .../CountryStates/CountryStatesHooks.php | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 www/wiki/extensions/CountryStates/CountryStatesHooks.php (limited to 'www/wiki/extensions/CountryStates/CountryStatesHooks.php') diff --git a/www/wiki/extensions/CountryStates/CountryStatesHooks.php b/www/wiki/extensions/CountryStates/CountryStatesHooks.php new file mode 100644 index 00000000..e6377468 --- /dev/null +++ b/www/wiki/extensions/CountryStates/CountryStatesHooks.php @@ -0,0 +1,65 @@ +setFunctionHook( 'countries', [ self::class, 'renderCountries' ] ); + $parser->setFunctionHook( 'states', [ self::class, 'renderStates' ] ); + } + + public static function renderCountries( Parser $parser, $param1 = '', $param2 = '', $param3 = '' ) { + $path = realpath(dirname(__FILE__)); + $str = file_get_contents($path . '/countries-states.json'); + $json = json_decode($str); + $end = ''; + // echo '
' . print_r($json, true) . '
'; + // return $output; + + foreach($json->countries as $item) + { + if ($param1) { + if($item->code == $param1) + { + // echo $item->name; + $countries[] = $item->name; + } + } else { + // $countries[] = $item->name; + $countries[] = $item->code; + + } + } + foreach($countries as $item) { + $end .= $item . ','; + } + return $end; + + } + + public static function renderStates( Parser $parser, $param1 = '', $param2 = '', $param3 = '' ) { + $path = realpath(dirname(__FILE__)); + $str = file_get_contents($path . '/countries-states.json'); + $json = json_decode($str); + $end = ''; + + // echo '
' . print_r($json, true) . '
'; + // return $output; + + foreach($json->countries as $item) + { + if($item->code == $param1) + { + // echo $item->name; + foreach($item->states as $state) { + $states[] = $state->name; + } + } + } + // return $states; + foreach($states as $item) { + $end .= $item . ','; + } + return $end; + + } +} -- cgit v1.2.1