RPC requests should use their own template sets with different content-type.
[squirrelmail.git] / class / l10n / streams.class.php
1 <?php
2
3 /**
4 * Copyright (c) 2003 Danilo Segan <danilo@kvota.net>.
5 *
6 * This file is part of PHP-gettext.
7 *
8 * PHP-gettext is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * PHP-gettext is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with PHP-gettext; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21 * MA 02110-1301, USA
22 *
23 * @copyright &copy; 2004-2007 The SquirrelMail Project Team
24 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
25 * @version $Id$
26 * @package squirrelmail
27 * @subpackage i18n
28 */
29
30 /**
31 * Class that is used to read .mo files.
32 * @package squirrelmail
33 * @subpackage i18n
34 */
35 class FileReader {
36 /**
37 * Current position in file
38 * @var integer
39 */
40 var $_pos;
41 /**
42 * File descriptor
43 * @var resource
44 */
45 var $_fd;
46 /**
47 * File size
48 * @var integer
49 */
50 var $_length;
51 /**
52 * contains error codes
53 *
54 * 2 = File doesn't exist
55 * 3 = Can't read file
56 * @var integer
57 */
58 var $error=0;
59
60 /**
61 * reads translation file and fills translation input object properties
62 * @param string $filename path to file
63 * @return boolean false there is a problem with $filename
64 */
65 function FileReader($filename) {
66 // disable stat warnings for unreadable directories
67 if (@file_exists($filename)) {
68
69 $this->_length=filesize($filename);
70 $this->_pos = 0;
71 $this->_fd = fopen($filename,'rb');
72 if (!$this->_fd) {
73 $this->error = 3; // Cannot read file, probably permissions
74 return false;
75 }
76 } else {
77 $this->error = 2; // File doesn't exist
78 return false;
79 }
80 }
81
82 /**
83 * reads data from current position
84 * @param integer $bytes number of bytes to read
85 * @return string read data
86 */
87 function read($bytes) {
88 fseek($this->_fd, $this->_pos);
89 $data = fread($this->_fd, $bytes);
90 $this->_pos = ftell($this->_fd);
91
92 return $data;
93 }
94
95 /**
96 * Moves to defined position in a file
97 * @param integer $pos position
98 * @return integer current position
99 */
100 function seekto($pos) {
101 fseek($this->_fd, $pos);
102 $this->_pos = ftell($this->_fd);
103 return $this->_pos;
104 }
105
106 /**
107 * return current position
108 * @return integer current position
109 */
110 function currentpos() {
111 return $this->_pos;
112 }
113
114 /**
115 * return file length
116 * @return integer file length
117 */
118 function length() {
119 return $this->_length;
120 }
121
122 /**
123 * close translation file
124 */
125 function close() {
126 fclose($this->_fd);
127 }
128 }