-
Notifications
You must be signed in to change notification settings - Fork 14
/
emplexer_section_screen.php
executable file
·215 lines (159 loc) · 6.74 KB
/
emplexer_section_screen.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
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
<?php
class EmplexerSectionScreen extends AbstractPreloadedRegularScreen implements UserInputHandler
{
const ID = "emplexer_section_secreen";
private $servers;
function __construct()
{
hd_print(__METHOD__);
parent::__construct(self::ID, $this->get_folder_views());
}
public function get_handler_id()
{
hd_print(__METHOD__);
return self::ID;
}
public function get_action_map(MediaURL $media_url, &$plugin_cookies)
{
hd_print(__METHOD__);
// hd_print(__METHOD__ . ': ' . print_r($media_url, true));
UserInputHandlerRegistry::get_instance()->register_handler($this);
$pop_up_action = UserInputHandlerRegistry::create_action($this, 'pop_up', null,'Filtos');
// hd_print(__METHOD__ . ':' . print_r($pop_up_action, true));
$enter_action = ActionFactory::open_folder();
return array
(
GUI_EVENT_KEY_ENTER => $enter_action,
GUI_EVENT_KEY_PLAY => $enter_action,
GUI_EVENT_KEY_POPUP_MENU => $pop_up_action,
GUI_EVENT_KEY_0 => $pop_up_action
);
}
public function get_all_folder_items(MediaURL $media_url, &$plugin_cookies)
{
hd_print(__METHOD__);
// hd_print('get_all_folder_items em ' . self::ID);
$items = array();
// foreach ($this->servers as $server ) {
// print_r($server);
// $doc = HD::http_get_document( EmplexerConfig::getInstance()->DEFAULT_PLEX . '/library/sections/all');
$doc = HD::http_get_document( EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/all');
// $doc = HD::http_get_document( "http://" . $server['Ip']. ';' . $server['Port'] . "/library/sections/all");
//hd_print($doc);
$xml = simplexml_load_string($doc);
//hd_print(print_r($xml, true));
foreach ($xml->Directory as $c)
{
$items[] = array
(
// EmplexerRootList::get_media_url_str((string)$c->attributes()->key, null),
PluginRegularFolderItem::media_url => $this->get_right_media_url((string)$c->attributes()->type,(string)$c->attributes()->key, $plugin_cookies),
PluginRegularFolderItem::caption => (string) $c->attributes()->title,
PluginRegularFolderItem::view_item_params =>
array
(
ViewItemParams::icon_path => 'plugin_file://icons/sudoku.png',
)
);
}
$channels = EmplexerConfig::getInstance()->getAllAvailableChannels($plugin_cookies, $this);
if (count($channels)>0){
$items = array_merge($items, $channels);
}
// $items[] = array
// (
// PluginRegularFolderItem::media_url => EmplexerSMBSetup::get_media_url_str(),
// PluginRegularFolderItem::caption => 'REDE',
// PluginRegularFolderItem::view_item_params =>
// array
// (
// ViewItemParams::icon_path => 'plugin_luginfile://icons/sudoku.png',
// )
// );
// hd_print(print_r($items, true));
return $items;
}
public function handle_user_input(&$user_input, &$plugin_cookies){
hd_print(__METHOD__);
hd_print(__METHOD__ . ":" . print_r($user_input, true));
if ($user_input->control_id == 'pop_up') {
$media_url = MediaURL::decode($user_input->selected_media_url);
$key = (string) $media_url->category_id;
// hd_print("key = $key");
if ($key){
$url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/' . $key;
/*$popUp = new EmplexerPopUp(4);
$action = $popUp->showPopUpMenu($url);*/
$doc = HD::http_get_document( EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/' . $key);
$pop_up_items = array();
$xml = simplexml_load_string($doc);
$defaultFilter = 'all';
if ($media_url->type == 'show'){
$defaultFilter = isset($plugin_cookies->defaultShowFilter) ? $plugin_cookies->defaultShowFilter : 'all';
}
if ($media_url->type == 'movie'){
$defaultFilter = isset($plugin_cookies->defaultMovieFilter) ? $plugin_cookies->defaultMovieFilter : 'all';
}
foreach ($xml->Directory as $c){
$key = (string)$c->attributes()->key;
$prompt = (string)$c->attributes()->prompt;
$is_secondary = (string)$c->attributes()->secondary;
if ($key != $defaultFilter && $key != 'folder' && !$prompt ){
// if ($key != 'all' ){
$pop_up_items[] = array(
GuiMenuItemDef::caption=> (string)$c->attributes()->title,
GuiMenuItemDef::action => ActionFactory::open_folder($this->get_right_media_url_for_pop_up($media_url, $key, $is_secondary != null), $key)
// GuiMenuItemDef::action => ActionFactory::open_folder(EmplexerListVideo::get_media_url_str("library/sections/" .$media_url->category_id . "/" . $key))
);
}
}
hd_print(__METHOD__ . ' pop_up_items:' .print_r($pop_up_items, true));
$action = ActionFactory::show_popup_menu($pop_up_items);
// hd_print(__METHOD__ . ': ' . print_r($action, true));
return $action;
} else {
return null;
}
} if ($user_input->control_id == 'savePref') {
hd_print(__METHOD__ . ':' . print_r($user_input, true));
hd_print(__METHOD__ . ':' . print_r($plugin_cookies, true));
EmplexerSetupScreen::savePreferences($user_input, $plugin_cookies);
}
}
private function get_right_media_url_for_pop_up(MediaURL $media_url,$filter_name, $is_secondary=false)
{
hd_print(__METHOD__ . ':'. print_r($media_url, true)) ;
$episodes = array( 'newest' , 'recentlyAdded', 'recentlyViewed', 'onDeck');
$season = array('all','recentlyViewedShows','unwatched');
if ($is_secondary){
hd_print('entrou ' . $filter_name);
return EmplexerSecondarySection::get_media_url_str($media_url->category_id,$filter_name,$media_url->type);
}
if ($media_url->type == "movie"){
return EmplexerMovieList::get_media_url_str($media_url->category_id, $filter_name, $media_url->type);
}
if (in_array($filter_name , $episodes)){
return EmplexerVideoList::get_media_url_str($media_url->category_id, $filter_name, $media_url->type);
} else {
return EmplexerRootList::get_media_url_str($media_url->category_id, $filter_name);
}
}
private function get_right_media_url($type, $key,&$plugin_cookies)
{
hd_print(__METHOD__);
if ($type == "movie"){
// hd_print ("key =$key type=$type movie");
return EmplexerMovieList::get_media_url_str($key, isset($plugin_cookies->defaultMovieFilter) ? $plugin_cookies->defaultMovieFilter : 'all' , 'movie');
} else if ( $type == "artist"){
return EmplexerMusicList::get_media_url_str("/library/sections/$key");
} else {
// hd_print ("key =$key type=$ddtype show");
return EmplexerRootList::get_media_url_str($key, isset($plugin_cookies->defaultShowFilter) ? $plugin_cookies->defaultShowFilter : 'all', 'show');
}
}
public function get_folder_views()
{
return EmplexerConfig::getInstance()->GET_SECTIONS_LIST_VIEW();
}
}
?>