diff options
Diffstat (limited to 'www/wiki/extensions/CountryStates/CountryStatesHooks.php')
-rw-r--r-- | www/wiki/extensions/CountryStates/CountryStatesHooks.php | 65 |
1 files changed, 65 insertions, 0 deletions
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 @@ +<?php +class CountryStatesHooks { + // Register any render callbacks with the parser + public static function onParserFirstCallInit( Parser $parser ) { + + $parser->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 '<pre>' . print_r($json, true) . '</pre>'; + // 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 '<pre>' . print_r($json, true) . '</pre>'; + // 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; + + } +} |