Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ZurmoGettextPoFile.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  protected $fileSource;
43 
44  protected $fileObject;
45 
46  protected $messages = array();
47 
48  public function __construct($fileSource = null)
49  {
50  if ($fileSource)
51  {
52  $this->fileSource = $fileSource;
53  }
54  }
55 
56  protected function openFile($fileSource = null)
57  {
58  if (!$fileSource)
59  {
60  $fileSource = $this->fileSource;
61  }
62 
63  try
64  {
65  $this->fileObject = new SplFileObject($fileSource);
66  }
67  catch (Exception $e)
68  {
69  throw new FileNotReadableException(Zurmo::t('Core', 'Can not open the file.'));
70  }
71  }
72 
81  public function read($skipEmptyContext = true)
82  {
83  $this->messages = array();
84 
85  if (!$this->fileObject)
86  {
87  $this->openFile();
88  }
89 
90  try
91  {
92  $context = 'COMMENT';
93  $current = array();
94 
95  while ($this->fileObject->valid())
96  {
97  $line = $this->fileObject->getCurrentLine();
98 
99  if ($this->fileObject->key() == 0)
100  {
101  $line = str_replace("\xEF\xBB\xBF", '', $line);
102  }
103 
104  $line = trim(strtr($line, array("\\\n" => "")));
105 
106  if (!strncmp('#', $line, 1))
107  {
108  switch ($context)
109  {
110  case 'COMMENT':
111  $current['#'][] = substr($line, 1);
112  break;
113  case 'MSGSTR':
114  $this->addMessage($current, $skipEmptyContext);
115  $current = array();
116  $current['#'][] = substr($line, 1);
117  $context = 'COMMENT';
118  break;
119  default:
120  throw new FailedParseGettextException(
121  Zurmo::t('Core', 'Failed parsing {fileSource}: "msgstr" was expected on line {lineNumber}.',
122  array(
123  '{fileSource}' => $this->fileObject->getFilename(),
124  '{lineNumber}' => $this->fileObject->key()
125  )
126  )
127  );
128  }
129  }
130  elseif (!strncmp('msgid', $line, 5))
131  {
132  switch ($context)
133  {
134  case 'MSGSTR':
135  $this->addMessage($current, $skipEmptyContext);
136  $current = array();
137  break;
138  case 'MSGID':
139  throw new FailedParseGettextException(
140  Zurmo::t('Core', 'Failed parsing {fileSource}: "msgid" is unexpected on line {lineNumber}.',
141  array(
142  '{fileSource}' => $this->fileObject->getFilename(),
143  '{lineNumber}' => $this->fileObject->key()
144  )
145  )
146  );
147  break;
148  }
149 
150  $line = trim(substr($line, 5));
151 
152  $quoted = $this->parseQuotedString($line);
153 
154  $current['msgid'] = $quoted;
155  $context = 'MSGID';
156  }
157  elseif (!strncmp('msgctxt', $line, 7))
158  {
159  if ($context == 'MSGSTR')
160  {
161  $this->addMessage($current, $skipEmptyContext);
162  $current = array();
163  }
164  elseif (!empty($current['msgctxt']))
165  {
166  throw new FailedParseGettextException(
167  Zurmo::t('Core', 'Failed parsing {fileSource}: "msgctxt" is unexpected on line {lineNumber}.',
168  array(
169  '{fileSource}' => $this->fileObject->getFilename(),
170  '{lineNumber}' => $this->fileObject->key()
171  )
172  )
173  );
174  }
175 
176  $line = trim(substr($line, 7));
177 
178  $quoted = $this->parseQuotedString($line);
179 
180  $current['msgctxt'] = $quoted;
181  $context = 'MSGCTXT';
182  }
183  elseif (!strncmp('msgstr', $line, 6))
184  {
185  if (($context != 'MSGID') && ($context != 'MSGCTXT'))
186  {
187  throw new FailedParseGettextException(
188  Zurmo::t('Core', 'Failed parsing {fileSource}: "msgstr" is unexpected on line {lineNumber}.',
189  array(
190  '{fileSource}' => $this->fileObject->getFilename(),
191  '{lineNumber}' => $this->fileObject->key()
192  )
193  )
194  );
195  }
196 
197  $line = trim(substr($line, 6));
198 
199  $quoted = $this->parseQuotedString($line);
200 
201  $current['msgstr'] = $quoted;
202 
203  $context = 'MSGSTR';
204  }
205  elseif ($line != '')
206  {
207  $quoted = $this->parseQuotedString($line);
208 
209  switch ($context)
210  {
211  case 'MSGID':
212  $current['msgid'] .= $quoted;
213  break;
214  case 'MSGCTXT':
215  $current['msgctxt'] .= $quoted;
216  break;
217  case 'MSGSTR':
218  $current['msgstr'] .= $quoted;
219  break;
220  default:
221  throw new FailedParseGettextException(
222  Zurmo::t('Core', 'Failed parsing {fileSource}: there is an unexpected string on line {lineNumber}.',
223  array(
224  '{fileSource}' => $this->fileObject->getFilename(),
225  '{lineNumber}' => $this->fileObject->key()
226  )
227  )
228  );
229  }
230  }
231  }
232 
233  if ($context == 'MSGSTR')
234  {
235  $this->addMessage($current, $skipEmptyContext);
236  }
237  elseif ($context != 'COMMENT')
238  {
239  throw new FailedParseGettextException(Zurmo::t('Core', ''));
240  }
241  }
242  catch (RuntimeException $e)
243  {
244  throw new FailedParseGettextException(Zurmo::t('Core', 'Failed to read the file'));
245  }
246 
247  return $this->getMessages();
248  }
249 
250  public function getMessages()
251  {
252  return $this->messages;
253  }
254 
255  protected function addMessage($message, $skipEmptyContext = true)
256  {
257  if ($skipEmptyContext && empty($message['msgctxt']))
258  {
259  return;
260  }
261 
262  $this->messages[] = $message;
263  }
264 
265  protected function parseQuotedString($string)
266  {
267  if (substr($string, 0, 1) != substr($string, -1, 1))
268  {
269  throw new FailedParseGettextException(
270  Zurmo::t('Core', 'Failed parsing {fileSource}: syntax error on line {lineNumber}',
271  array(
272  '{fileSource}' => $this->fileObject->getFilename(),
273  '{lineNumber}' => $this->fileObject->key()
274  )
275  )
276  );
277  }
278 
279  $quote = substr($string, 0, 1);
280  $string = substr($string, 1, -1);
281 
282  switch ($quote)
283  {
284  case '"':
285  return stripcslashes($string);
286  break;
287  case "'":
288  return $string;
289  break;
290  default:
291  throw new FailedParseGettextException(
292  Zurmo::t('Core', 'Failed parsing {fileSource}: syntax error on line {lineNumber}',
293  array(
294  '{fileSource}' => $this->fileObject->getFilename(),
295  '{lineNumber}' => $this->fileObject->key()
296  )
297  )
298  );
299  }
300  }
301  }
302 ?>
read($skipEmptyContext=true)
Generated on Thu Sep 24 2020 07:10:25
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.