PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/system/library/PEAR/HTML/QuickForm2/MessageProvider/Strftime.php

https://bitbucket.org/spekkionu/passworddb
PHP | 122 lines | 40 code | 5 blank | 77 comment | 6 complexity | e017a0eee0b74adb8a75d49a372e7f75 MD5 | raw file
Possible License(s): BSD-2-Clause
  1. <?php
  2. /**
  3. * Provides lists of months and weekdays for date elements using current locale
  4. *
  5. * PHP version 5
  6. *
  7. * LICENSE:
  8. *
  9. * Copyright (c) 2006-2012, Alexey Borzov <avb@php.net>,
  10. * Bertrand Mansion <golgote@mamasam.com>
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. *
  17. * * Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * * Redistributions in binary form must reproduce the above copyright
  20. * notice, this list of conditions and the following disclaimer in the
  21. * documentation and/or other materials provided with the distribution.
  22. * * The names of the authors may not be used to endorse or promote products
  23. * derived from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  26. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  31. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  32. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  33. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  35. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * @category HTML
  38. * @package HTML_QuickForm2
  39. * @author Alexey Borzov <avb@php.net>
  40. * @author Bertrand Mansion <golgote@mamasam.com>
  41. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  42. * @version SVN: $Id: Strftime.php 323332 2012-02-18 15:10:04Z avb $
  43. * @link http://pear.php.net/package/HTML_QuickForm2
  44. */
  45. /** Interface for classes that supply (translated) messages for the elements */
  46. require_once 'HTML/QuickForm2/MessageProvider.php';
  47. /**
  48. * Provides lists of months and weekdays for date elements using current locale
  49. *
  50. * Uses locale-aware strftime() formatting function. The class does not try to
  51. * do anything with locale itself, so be sure to set it up properly before
  52. * adding date elements to the form.
  53. *
  54. * @category HTML
  55. * @package HTML_QuickForm2
  56. * @author Alexey Borzov <avb@php.net>
  57. * @author Bertrand Mansion <golgote@mamasam.com>
  58. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  59. * @version Release: 2.0.0
  60. * @link http://pear.php.net/package/HTML_QuickForm2
  61. * @link http://pear.php.net/bugs/bug.php?id=5558
  62. */
  63. class HTML_QuickForm2_MessageProvider_Strftime implements HTML_QuickForm2_MessageProvider
  64. {
  65. /**
  66. * Lists of month names and weekdays accorfing to current locale
  67. * @var array
  68. */
  69. protected $messages = array(
  70. 'weekdays_short'=> array(),
  71. 'weekdays_long' => array(),
  72. 'months_short' => array(),
  73. 'months_long' => array()
  74. );
  75. /**
  76. * Constructor, builds lists of month and weekday names
  77. */
  78. public function __construct()
  79. {
  80. for ($i = 1; $i <= 12; $i++) {
  81. $names = explode("\n", strftime("%b\n%B", mktime(12, 0, 0, $i, 1, 2011)));
  82. $this->messages['months_short'][] = $names[0];
  83. $this->messages['months_long'][] = $names[1];
  84. }
  85. for ($i = 0; $i < 7; $i++) {
  86. $names = explode("\n", strftime("%a\n%A", mktime(12, 0, 0, 1, 2 + $i, 2011)));
  87. $this->messages['weekdays_short'][] = $names[0];
  88. $this->messages['weekdays_long'][] = $names[1];
  89. }
  90. }
  91. /**
  92. * Returns name(s) of months and weekdays for date elements
  93. *
  94. * @param array $messageId Message ID
  95. * @param string $langId Not used, current locale will define the language
  96. *
  97. * @return array|string|null
  98. * @throws HTML_QuickForm2_InvalidArgumentException if $messageId doesn't
  99. * start with 'date'
  100. */
  101. public function get(array $messageId, $langId = null)
  102. {
  103. if ('date' != array_shift($messageId)) {
  104. throw new HTML_QuickForm2_InvalidArgumentException('...');
  105. }
  106. $message = $this->messages;
  107. while (!empty($messageId)) {
  108. $key = array_shift($messageId);
  109. if (!isset($message[$key])) {
  110. return null;
  111. }
  112. $message = $message[$key];
  113. }
  114. return $message;
  115. }
  116. }
  117. ?>