-
Notifications
You must be signed in to change notification settings - Fork 5
/
xmlrpc.php
183 lines (160 loc) · 5.24 KB
/
xmlrpc.php
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
<?php
include_once("XML/RPC2/Server.php");
include_once('config.php');
include_once( INSTALL_PATH . "/Keyword.class.php" );
include_once( INSTALL_PATH . "/reclib.php" );
include_once( INSTALL_PATH . "/Reservation.class.php" );
include_once( INSTALL_PATH . '/Settings.class.php' );
class EpgrecRpc {
/**
* Get channel types.
*
* @param none
* @return array
*/
public static function getChannelType() {
$settings = Settings::factory();
$retval = array();
if($settings->gr_tuners != 0 ) {
array_push( $retval, XML_RPC2_Value::createFromNative("GR") );
}
if($settings->bs_tuners != 0 ) {
array_push( $retval, XML_RPC2_Value::createFromNative("BS") );
}
if($settings->cs_rec_flg != 0 ) {
array_push( $retval, XML_RPC2_Value::createFromNative("CS") );
}
return XML_RPC2_Value::createFromNative( $retval, "array" );
}
/**
* Get channel lists.
*
* @param none
* @return array
*/
public static function getChannelList() {
try {
$arr = DBRecord::createRecords( CHANNEL_TBL, " WHERE skip <> '1'" );
$retval = array();
foreach( $arr as $ch ) {
$r = array(
"channel_id" => XML_RPC2_Value::createFromNative((int)($ch->id),"int"),
"type" => XML_RPC2_Value::createFromNative($ch->type),
"channel" => XML_RPC2_Value::createFromNative((int)($ch->channel),"int"),
"name" => XML_RPC2_Value::createFromNative($ch->name, "string"),
);
$val = XML_RPC2_Value::createFromNative( $r, "struct" );
array_push( $retval, $val );
}
return XML_RPC2_Value::createFromNative( $retval, "array" );
}
catch( Exception $e ) {
if( is_a( $e, "XML_RPC2_Exception" ) ) throw $e;
else throw new XML_RPC2_FaultException( $e->getMessage(),10 );
}
}
/**
* Get category lists.
*
* @param none
* @return array
*/
public static function getCategoryList() {
try {
$arr = DBRecord::createRecords( CATEGORY_TBL );
$retval = array();
foreach( $arr as $cat ) {
$r = array(
"cateogry_id" => XML_RPC2_Value::createFromNative((int)($cat->id),"int"),
"name_jp" => XML_RPC2_Value::createFromNative($cat->name_jp),
"name_en" => XML_RPC2_Value::createFromNative($cat->name_en),
);
$val = XML_RPC2_Value::createFromNative( $r, "struct" );
array_push( $retval, $val );
}
return XML_RPC2_Value::createFromNative( $retval, "array" );
}
catch( Exception $e ) {
if( is_a( $e, "XML_RPC2_Exception" ) ) throw $e;
else throw new XML_RPC2_FaultException( $e->getMessage(),10 );
}
}
/**
* Search program.
*
* @param string keyword Search words.
* @param int use_regexp
* @param string type
* @param int category_id
* @param int channel_id
* @param int weekofday
* @param int prgtime
* @return array
*/
public static function searchProgram(
$keyword,
$use_regexp = false,
$type = "*",
$category_id = 0,
$channel_id = 0,
$weekofday = 7,
$prgtime = 24 ) {
if( $weekofday > 7 ) throw new XML_RPC2_FaultException("weekofday value is invalid");
if( $prgtime > 24 ) throw new XML_RPC2_FaultException("prgtime value is invalid" );
try {
$prgs = Keyword::search( $keyword, $use_regexp, $type, $category_id, $channel_id, $weekofday, $prgtime );
$retval = array();
foreach( $prgs as $prg ) {
$ch = new DBRecord( CHANNEL_TBL, "id", $prg->channel_id );
$num = DBRecord::countRecords( RESERVE_TBL, "WHERE program_id = '".$prg->id."'" );
$reserve_id = 0;
if( $num != 0 ) {
$rec = new DBRecord( RESERVE_TBL, "program_id", $prg->id );
$reserve_id = $rec->id;
}
$r = array (
"program_id" => XML_RPC2_Value::createFromNative( (int)($prg->id), "int" ),
"type" => XML_RPC2_Value::createFromNative( $prg->type ),
"channel_name" => XML_RPC2_Value::createFromNative( $ch->name ),
"title" => XML_RPC2_Value::createFromNative( $prg->title ),
"description" => XML_RPC2_Value::createFromNative( $prg->description ),
"starttime" => XML_RPC2_Value::createFromNative( (int)(toTimestamp($prg->starttime)), "datetime" ),
"endtime" => XML_RPC2_Value::createFromNative( (int)(toTimestamp($prg->endtime)), "datetime" ),
"reserve" => XML_RPC2_Value::createFromNative( (int)$reserve_id, "int" ),
);
array_push( $retval, XML_RPC2_Value::createFromNative( $r, "struct" ) );
}
return XML_RPC2_Value::createFromNative( $retval, "array" );
}
catch( Exception $e ) {
if( is_a( $e, "XML_RPC2_Exception" ) ) throw $e;
else throw new XML_RPC2_FaultException( $e->getMessage(),10 );
}
}
/**
* Reserve progarm recording .
*
* @param int program_id
* @return none
*/
public static function reserveProgram( $program_id ) {
try {
$settings = Settings::factory();
$num = DBRecord::countRecords( PROGRAM_TBL, "id", $program_id );
if( $num < 1 ) throw new XML_RPC2_FaultException( "Can't find program" , 10 );
Reservation::simple( $program_id , 0, $settings->autorec_mode );
}
catch( Exception $e ) {
if( is_a( $e, "XML_RPC2_Exception" ) ) throw $e;
else throw new XML_RPC2_FaultException( $e->getMessage(),10 );
}
}
}
$options = array(
"backend" => "php",
"encoding" => "UTF-8",
"prefix" => "epgrec.",
);
$server = XML_RPC2_Server::create("EpgrecRpc", $options);
$server->handleCall();
?>