summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/CountryStates/CountryStatesHooks.php
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
committerYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
commitfc7369835258467bf97eb64f184b93691f9a9fd5 (patch)
treedaabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/CountryStates/CountryStatesHooks.php
first commit
Diffstat (limited to 'www/wiki/extensions/CountryStates/CountryStatesHooks.php')
-rw-r--r--www/wiki/extensions/CountryStates/CountryStatesHooks.php65
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;
+
+ }
+}