SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Controllers/LocaleController.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Controllers;
  15.  
  16. use Sprout\Helpers\Locales\LocaleInfo;
  17.  
  18.  
  19. /**
  20.  * For things related to Locales
  21.  */
  22. class LocaleController extends Controller
  23. {
  24. /**
  25.   * Extracts a prefix for use with address fields from $_GET['prefix']
  26.   *
  27.   * If the get param is invalid, it is ignored
  28.   *
  29.   * @return string
  30.   */
  31. protected function getPrefix()
  32. {
  33. $prefix = (string) @$_GET['prefix'];
  34. if (!preg_match('/^[a-z][_a-z0-9]*$/i', $prefix)) {
  35. return '';
  36. }
  37. return $prefix;
  38. }
  39.  
  40.  
  41. /**
  42.   * Outputs fields for an address which is not mandatory
  43.   *
  44.   * @param string $country The country to return fields for
  45.   */
  46. public function getAddressFields($country)
  47. {
  48. echo LocaleInfo::get($country)->outputAddressFields($this->getPrefix(), false);
  49. }
  50.  
  51.  
  52. /**
  53.   * Outputs fields for an address which is mandatory
  54.   *
  55.   * @param string $country The country to return fields for
  56.   */
  57. public function getAddressFieldsRequired($country)
  58. {
  59. echo LocaleInfo::get($country)->outputAddressFields($this->getPrefix(), true);
  60. }
  61. }
  62.