PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/concreteOLD/libraries/3rdparty/Zend/Translate/Adapter/Csv.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 121 lines | 59 code | 16 blank | 46 comment | 13 complexity | 61810ca786340988cdd07c5a7fbdea98 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Translate
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @version $Id: Csv.php 23775 2011-03-01 17:25:24Z ralph $
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Locale */
  22. require_once 'Zend/Locale.php';
  23. /** Zend_Translate_Adapter */
  24. require_once 'Zend/Translate/Adapter.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Translate
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter
  32. {
  33. private $_data = array();
  34. /**
  35. * Generates the adapter
  36. *
  37. * @param array|Zend_Config $options Translation content
  38. */
  39. public function __construct($options = array())
  40. {
  41. $this->_options['delimiter'] = ";";
  42. $this->_options['length'] = 0;
  43. $this->_options['enclosure'] = '"';
  44. if ($options instanceof Zend_Config) {
  45. $options = $options->toArray();
  46. } else if (func_num_args() > 1) {
  47. $args = func_get_args();
  48. $options = array();
  49. $options['content'] = array_shift($args);
  50. if (!empty($args)) {
  51. $options['locale'] = array_shift($args);
  52. }
  53. if (!empty($args)) {
  54. $opt = array_shift($args);
  55. $options = array_merge($opt, $options);
  56. }
  57. } else if (!is_array($options)) {
  58. $options = array('content' => $options);
  59. }
  60. parent::__construct($options);
  61. }
  62. /**
  63. * Load translation data
  64. *
  65. * @param string|array $filename Filename and full path to the translation source
  66. * @param string $locale Locale/Language to add data for, identical with locale identifier,
  67. * see Zend_Locale for more information
  68. * @param array $option OPTIONAL Options to use
  69. * @return array
  70. */
  71. protected function _loadTranslationData($filename, $locale, array $options = array())
  72. {
  73. $this->_data = array();
  74. $options = $options + $this->_options;
  75. $this->_file = @fopen($filename, 'rb');
  76. if (!$this->_file) {
  77. require_once 'Zend/Translate/Exception.php';
  78. throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
  79. }
  80. while(($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) {
  81. if (substr($data[0], 0, 1) === '#') {
  82. continue;
  83. }
  84. if (!isset($data[1])) {
  85. continue;
  86. }
  87. if (count($data) == 2) {
  88. $this->_data[$locale][$data[0]] = $data[1];
  89. } else {
  90. $singular = array_shift($data);
  91. $this->_data[$locale][$singular] = $data;
  92. }
  93. }
  94. return $this->_data;
  95. }
  96. /**
  97. * returns the adapters name
  98. *
  99. * @return string
  100. */
  101. public function toString()
  102. {
  103. return "Csv";
  104. }
  105. }