Source for file SMS_Site.php

Documentation is available at SMS_Site.php


1 <?php
2 // $Id$
3
4 // require HTML functions
5 require_once(SWS_CLASS_DIR.'HTML_Functions.php');
6 // require HTTP_Request_Common from HTTP Navigator classes
7 require_once(HTTPNAV_ROOT.'HTTP_Request_Common.php');
8 /**
9 * SMS Site
10 *
11 * @author Keyvan Minoukadeh <keyvan@k1m.com>
12 * @version 2.0
13 */
14 class SMS_Site
15 {
16 /**
17 * HTTP client
18 * @var object User_Agent
19 */
20 var $http_client;
21
22 /**
23 * HTML functions
24 * @var object HTML_Functions
25 */
26 var $html_functions;
27
28 /**
29 * Country codes supported
30 *
31 * Array holding country codes (excluding the '+') which a site supports.
32 * null indicates the site supports them all
33 * @var array
34 */
35 var $country_codes;
36
37 /**
38 * Site name
39 *
40 * @var string
41 */
42 var $site_name;
43
44 /**
45 * Country code (excluding '+')
46 *
47 * @var string
48 */
49 var $ccode;
50
51 /**
52 * Number to send to
53 *
54 * @var string
55 */
56 var $number;
57
58 /**
59 * Message to send
60 *
61 * @var string
62 */
63 var $message;
64
65 /**
66 * User to login with
67 *
68 * @var string
69 */
70 var $login_user;
71
72 /**
73 * Pass to login with
74 *
75 * @var string
76 */
77 var $login_pass;
78
79 /**
80 * Error number (SWS_ERR_*)
81 *
82 * @var int
83 */
84 var $error_num;
85
86 /**
87 * Error string
88 *
89 * @var string
90 */
91 var $error_string;
92
93 /**
94 * Constructor
95 */
96 function SMS_Site()
97 {
98 $this->html_functions =& new HTML_Functions();
99 }
100
101 /**
102 * Set login username and/or password
103 *
104 * @param string $user username
105 * @param string $pass password (optional)
106 */
107 function set_login($user, $pass=null)
108 {
109 $this->login_user = $user;
110 $this->login_pass = $pass;
111 }
112
113 /**
114 * Get username
115 *
116 * @return string
117 */
118 function get_login_user()
119 {
120 return $this->login_user;
121 }
122
123 /**
124 * Get login password
125 *
126 * @return string
127 */
128 function get_login_pass()
129 {
130 return $this->login_pass;
131 }
132
133 /**
134 * Supports country
135 *
136 * This method will return true if country code <var>$ccode</var> is
137 * supported by the site, false otherwise.
138 *
139 * @param string $ccode country code with or without leading plus '+'.
140 * @return bool
141 */
142 function supports_country($ccode)
143 {
144 // if country codes is unset it means all are supported
145 if (!isset($this->country_codes)) return true;
146 // strip plus
147 $ccode = trim($ccode, ' +');
148 return in_array($ccode, $this->country_codes);
149 }
150
151 /**
152 * Set country codes
153 *
154 * @param array indexed array of country codes excluding leading '+'
155 */
156 function set_country_codes($ccodes)
157 {
158 if (!isset($ccodes)) $this->country_codes = null;
159 if (is_string($ccodes)) $ccodes = array($ccodes);
160 foreach ($ccodes as $idx => $ccode) {
161 $ccodes[$idx] = trim($ccode, ' +');
162 }
163 $this->country_codes = $ccodes;
164 }
165
166 /**
167 * Set country code
168 *
169 * If the plus sign '+' is omitted, this method will add it, to get the
170 * country code without the leading plus sign, use the appropriate getter
171 * method (get_ccode_np()).
172 *
173 * @param string $ccode country code (eg. '+44')
174 */
175 function set_ccode($ccode)
176 {
177 if (substr($ccode, 0, 1) != '+') {
178 $this->ccode = '+'.$ccode;
179 } else {
180 $this->ccode = $ccode;
181 }
182 }
183
184 /**
185 * Get country code including leading plus sign '+'
186 *
187 * @return string
188 */
189 function get_ccode()
190 {
191 return $this->ccode;
192 }
193
194 /**
195 * Get country code without leading plus sign '+'
196 *
197 * @return string
198 */
199 function get_ccode_np()
200 {
201 return substr($this->ccode, 1);
202 }
203
204 /**
205 * Set Number
206 *
207 * @param string $number number (eg. '7977123456')
208 */
209 function set_number($number)
210 {
211 $this->number = (string)$number;
212 }
213
214 /**
215 * Get Number
216 *
217 * @return string
218 * @see get_number_nz()
219 */
220 function get_number()
221 {
222 return $this->number;
223 }
224
225 /**
226 * Get Number exluding leading zero '0'
227 *
228 * @return string
229 * @see get_number()
230 */
231 function get_number_nz()
232 {
233 if (substr($this->number, 0, 1) == '0') {
234 return substr($this->number, 1);
235 } else {
236 return $this->number;
237 }
238 }
239
240 /**
241 * Set message
242 *
243 * @param string $message (eg. 'This is a message')
244 */
245 function set_message($message)
246 {
247 $this->message = $message;
248 }
249
250 /**
251 * Get message
252 *
253 * @return string
254 */
255 function get_message()
256 {
257 return $this->message;
258 }
259
260 /**
261 * Get error
262 *
263 * @return string
264 */
265 function get_error()
266 {
267 return $this->error_string;
268 }
269
270 /**
271 * Get error number
272 *
273 * @return int one of the SWS_ERR_* constants
274 */
275 function get_error_number()
276 {
277 return $this->error_num;
278 }
279
280 /**
281 * Set HTTP client
282 *
283 * @param object $http
284 */
285 function set_http_client(&$http)
286 {
287 $this->http_client =& $http;
288 }
289
290 /**
291 * Get HTTP client
292 *
293 * @return object User_Agent object
294 */
295 function &get_http_client()
296 {
297 return $this->http_client;
298 }
299
300 /**
301 * Set site name
302 *
303 * @param string $name
304 */
305 function set_site_name($name)
306 {
307 $this->site_name = $name;
308 }
309
310 /**
311 * Get site name
312 *
313 * @return string
314 */
315 function get_site_name()
316 {
317 return $this->site_name;
318 }
319
320 /**
321 * Send message
322 *
323 * Override this method in subclass.
324 * SMS_Web_Sender will call this method to handle the send.
325 * Make use of <var>$http_client</var> for sending and receiving HTTP
326 * messages.
327 */
328 function send()
329 {
330 trigger_error('Override this method in subclass', E_USER_ERROR);
331 return false;
332 }
333
334 /**
335 * Set error
336 * @param string $error_string
337 * @param int $error_num default: SWS_ERR_UNKNOWN
338 * @access private
339 */
340 function set_error($error_string, $error_num=SWS_ERR_UNKNOWN)
341 {
342 $this->error_string = $error_string;
343 $this->error_num = $error_num;
344 }
345 }
346 ?>

Documention generated on Sat, 19 Jul 2003 03:43:27 +0100 by phpDocumentor 1.2.0