summaryrefslogtreecommitdiffstats
path: root/lib/class/radio.class.php
blob: 43fa3300c6b0a20168027870ed295a498c31e045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
/**
 * Radio Class
 *
 * PHP version 5
 *
 * LICENSE: GNU General Public License, version 2 (GPLv2)
 * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * @category	Radio
 * @package	Ampache
 * @author	Karl Vollmer <vollmer@ampache.org>
 * @copyright	2001 - 2011 Ampache.org
 * @license	http://opensource.org/licenses/gpl-2.0 GPLv2
 * @version	PHP 5.2
 * @link	http://www.ampache.org/
 * @since	File available since Release 1.0
 */

/**
 * Radio Class
 *
 * This handles the internet radio stuff, that is inserted into live_stream
 * this can include podcasts or what-have-you
 *
 * @category	Radio
 * @package	Ampache
 * @author	Karl Vollmer <vollmer@ampache.org>
 * @copyright	2001 - 2011 Ampache.org
 * @license	http://opensource.org/licenses/gpl-2.0 GPLv2
 * @version	Release: 3.6
 * @link	http://www.ampache.org/
 * @since	Class available since Release 1.0
 */
class Radio extends database_object implements media {

	/* DB based variables */
	public $id;
	public $name;
	public $site_url;
	public $url;
	public $frequency;
	public $call_sign;
	public $catalog;

	/**
	 * Constructor
	 * This takes a flagged.id and then pulls in the information for said flag entry
	 */
	public function __construct($id) {

		$info = $this->get_info($id,'live_stream');

		// Set the vars
		foreach ($info as $key=>$value) {
			$this->$key = $value;
		}

	} // constructor

	/**
	 * format
	 * This takes the normal data from the database and makes it pretty
	 * for the users, the new variables are put in f_??? and f_???_link
	 */
	public function format() {

		// Default link used on the rightbar
		$this->f_link		= "<a href=\"$this->url\">$this->name</a>";

		$this->f_name_link	= "<a target=\"_blank\" href=\"$this->site_url\">$this->name</a>";
		$this->f_callsign	= scrub_out($this->call_sign);
		$this->f_frequency	= scrub_out($this->frequency);

		return true;

	} // format

	/**
	 * update
	 * This is a static function that takes a key'd array for input
	 * it depends on a ID element to determine which radio element it
	 * should be updating
	 */
	public static function update($data) {

		// Verify the incoming data
		if (!$data['id']) {
			// FIXME: Untranslated
			Error::add('general','Missing ID');
		}

		if (!$data['name']) {
			// FIXME: Untranslated
			Error::add('general','Name Required');
		}

		$allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp');

		$elements = explode(":",$data['url']);

		if (!in_array($elements['0'],$allowed_array)) {
			// FIXME: Untranslated
			Error::add('general','Invalid URL must be mms:// , https:// or http://');
		}

		if (Error::occurred()) {
			return false;
		}

		// Setup the data
		$name 		= Dba::escape($data['name']);
		$site_url	= Dba::escape($data['site_url']);
		$url		= Dba::escape($data['url']);
		$frequency	= Dba::escape($data['frequency']);
		$call_sign	= Dba::escape($data['call_sign']);
		$id		= Dba::escape($data['id']);

		$sql = "UPDATE `live_stream` SET `name`='$name',`site_url`='$site_url',`url`='$url'" .
			",`frequency`='$frequency',`call_sign`='$call_sign' WHERE `id`='$id'";
		$db_results = Dba::write($sql);

		return $db_results;

	} // update

	/**
	 * create
	 * This is a static function that takes a key'd array for input
	 * and if everything is good creates the object.
	 */
	public static function create($data) {

		// Make sure we've got a name
		if (!strlen($data['name'])) {
			// FIXME: Untranslated
			Error::add('name','Name Required');
		}

		$allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp');

		$elements = explode(":",$data['url']);

		if (!in_array($elements['0'],$allowed_array)) {
			Error::add('url','Invalid URL must be http:// or https://');
		}

		// Make sure it's a real catalog
		$catalog = new Catalog($data['catalog']);
		if (!$catalog->name) {
			// FIXME: Untranslated
			Error::add('catalog','Invalid Catalog');
		}

		if (Error::occurred()) { return false; }

		// Clean up the input
		$name		= Dba::escape($data['name']);
		$site_url	= Dba::escape($data['site_url']);
		$url		= Dba::escape($data['url']);
		$catalog	= $catalog->id;
		$frequency	= Dba::escape($data['frequency']);
		$call_sign	= Dba::escape($data['call_sign']);

		// If we've made it this far everything must be ok... I hope
		$sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`frequency`,`call_sign`) " .
			"VALUES ('$name','$site_url','$url','$catalog','$frequency','$call_sign')";
		$db_results = Dba::write($sql);

		return $db_results;

	} // create

	/**
	 * delete
	 * This deletes the current object from the database
	 */
	public function delete() {

		$id = Dba::escape($this->id);

		$sql = "DELETE FROM `live_stream` WHERE `id`='$id'";
		$db_results = Dba::write($sql);

		return true;

	} // delete

	/**
	 * native_stream
	 * This is needed by the media interface
	 */
	public function native_stream() {



	} // native_stream

	/**
	 * play_url
	 * This is needed by the media interface
	 */
	public static function play_url($oid,$sid='',$force_http='') {

		$radio = new Radio($oid);

		return $radio->url;

	} // play_url

	/**
	 * has_flag
	 * This is needed by the media interface
	 */
	public function has_flag() {



	} // has_flag

	/**
	 * stream_cmd
	 * Needed by the media interface
	 */
	public function stream_cmd() {


	} // stream_cmd

} //end of radio class

?>