protected function load_channels(&$plugin_cookies) { if (!ZTVTerminal::login()) { hd_print('Error: login_terminal'); return; } $json_reply = ZTVApi::call(ZTVApi::get_playlists()); if ($json_reply === false) { hd_print('Error: get_playlists'); return; } $this->channels = new HashedArray(); $this->groups = new HashedArray(); if ($this->is_favorites_supported()) { $this->groups->put(new FavoritesGroup($this, '__favorites', ZTVConfig::FAV_CHANNEL_GROUP_CAPTION, ZTVConfig::FAV_CHANNEL_GROUP_ICON_PATH)); } $this->groups->put(new AllChannelsGroup($this, ZTVConfig::ALL_CHANNEL_GROUP_CAPTION, ZTVConfig::ALL_CHANNEL_GROUP_ICON_PATH)); $now = new DateTime('now'); $use_proxy = isset($plugin_cookies->use_proxy) ? $plugin_cookies->use_proxy == 'yes' : false; foreach ($json_reply->result->medialist as $number => $media) { $mrl = $use_proxy ? str_replace('udp://@', 'http://' . $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port . '/udp/', $media->mrl) : $media->mrl; $epg_start = ZTVApi::parse_datetime($media->epg_start); $epg_stop = ZTVApi::parse_datetime($media->epg_stop); if (is_null($epg_start) || is_null($epg_stop)) { $past_epg_days = 0; $future_epg_days = 0; } else { $epg_start_diff = $now->diff($epg_start); $epg_stop_diff = $now->diff($epg_stop); $past_epg_days = $epg_start_diff->days; $future_epg_days = $epg_stop_diff->days; } $channel = new ZTVChannel($media->id, $media->name, $media->logo == null ? 'plugin_file://icons/tv-missing.png' : $media->logo, $mrl, $number + 1, $past_epg_days, $future_epg_days); $this->channels->put($channel); } foreach ($json_reply->result->playlists as $category) { /* Remove any nonexistent channels from the group. */ $items = array_filter($category->items, array($this, 'group_items_filter')); if (empty($items)) { continue; } $group = new DefaultGroup($category->id, $category->name, 'plugin_file://icons/' . basename($category->logo)); foreach ($items as $item_id) { $channel = $this->channels->get($item_id); $channel->add_group($group); $group->add_channel($channel); } $this->groups->put($group); } $this->channels->usort(function ($a, $b) { return strnatcasecmp($a->get_number(), $b->get_number()); }); }
public function handle_user_input(&$user_input, &$plugin_cookies) { if (!isset($user_input->control_id)) { if ($plugin_cookies->require_restart) { ZTVDaemonController::restart($plugin_cookies->use_proxy == 'yes' ? array('-y' => $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port) : array()); $plugin_cookies->require_restart = false; } if (!ZTVTerminal::login()) { return ActionFactory::show_dialog('%tr%dialog_registration_form', $this->do_registration_form_defs($plugin_cookies), true); } if ($this->load_profiles()) { return $this->profile->require_password ? ActionFactory::show_dialog('%ext%<key_local>dialog_profile_password<p>' . $this->profile->title . '</p></key_local>', $this->do_profile_form_defs($plugin_cookies), true) : ActionFactory::open_folder(); } return; } else { if ($user_input->action_type == 'confirm' || $user_input->action_type == 'apply') { switch ($user_input->control_id) { case 'epg_provider': $plugin_cookies->epg_provider = $user_input->epg_provider; break; case 'use_proxy': $plugin_cookies->use_proxy = $user_input->use_proxy; $plugin_cookies->proxy_ip = isset($plugin_cookies->proxy_ip) ? $plugin_cookies->proxy_ip : '192.168.0.1'; $plugin_cookies->proxy_port = isset($plugin_cookies->proxy_port) ? $plugin_cookies->proxy_port : '8080'; $plugin_cookies->require_restart = true; break; case 'proxy_ip': $plugin_cookies->proxy_ip = $user_input->proxy_ip; $plugin_cookies->require_restart = true; break; case 'proxy_port': $plugin_cookies->proxy_port = $user_input->proxy_port; $plugin_cookies->require_restart = true; break; case 'daemon_start': ZTVDaemonController::start($plugin_cookies->use_proxy == 'yes' ? array('-y' => $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port) : array()); break; case 'daemon_restart': ZTVDaemonController::restart($plugin_cookies->use_proxy == 'yes' ? array('-y' => $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port) : array()); break; case 'daemon_stop': ZTVDaemonController::stop(); break; case 'register_button': return ActionFactory::show_dialog('%tr%dialog_registration_form', $this->do_registration_form_defs($plugin_cookies), true); break; case 'register_terminal': if (is_null($user_input->username) || trim($user_input->username) == '') { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_username_empty')); } else { if (is_null($user_input->password) || trim($user_input->password) == '') { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_pin_empty')); } } if (!ZTVTerminal::register($user_input->username, $user_input->password)) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_invalid_password_or_username')); } $plugin_cookies->username = $user_input->username; $plugin_cookies->password = $user_input->password; return $user_input->selected_media_url == 'setup' ? ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('%tr%dialog_successful_login')) : ActionFactory::close_dialog_and_run(ActionFactory::open_folder()); break; case 'deregister_terminal': if (!ZTVTerminal::deregister()) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_cant_logout')); } return $user_input->selected_media_url == 'setup' ? ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('%tr%dialog_successful_login')) : ActionFactory::close_dialog_and_run(ActionFactory::open_folder()); break; case 'register_cancel': if (ZTVTerminal::login() && $user_input->selected_media_url != 'setup') { return ActionFactory::close_dialog_and_run(ActionFactory::open_folder()); } return ActionFactory::reset_controls($this->do_registration_form_defs($plugin_cookies)); break; case 'profile': $this->profile = $this->profiles[$user_input->profile]; if ($this->profile->require_password) { return ActionFactory::show_dialog('%ext%<key_local>dialog_profile_password<p>' . $this->profile->title . '</p></key_local>', $this->do_profile_form_defs($plugin_cookies, !$this->profile->password ? 'set_profile_password' : 'change_profile_password'), true); } $json_reply = ZTVApi::call(ZTVApi::set_profile($this->profile)); if ($json_reply === false) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_cant_select_profile')); } break; case 'check_profile_password': if ($user_input->profile_password != $this->profile->password) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_invalid_password')); } if ($user_input->selected_media_url != 'setup') { return ActionFactory::close_dialog_and_run(ActionFactory::open_folder()); } $json_reply = ZTVApi::call(ZTVApi::set_profile($this->profile)); if ($json_reply === false) { return ActionFactory::close_dialog_and_run(ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_cant_validate_password'))); } break; case 'change_profile_password': if ($user_input->profile_password != $this->profile->password) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_invalid_password')); } if (!$user_input->profile_password_new) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_new_password_empty')); } if ($user_input->profile_password_new != $user_input->profile_password_repeat) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_passwords_mismatch')); } $json_reply = ZTVApi::call(ZTVApi::set_profile($this->profile, $user_input->profile_password)); return $json_reply === false ? ActionFactory::close_dialog_and_run(ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_cant_change_password'))) : ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('%tr%dialog_successful_password_change')); break; case 'set_profile_password': if (!$user_input->profile_password) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_new_password_empty')); } if ($user_input->profile_password != $user_input->profile_password_repeat) { return ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_passwords_mismatch.')); } $json_reply = ZTVApi::call(ZTVApi::set_profile($this->profile, $user_input->profile_password)); return $json_reply === false ? ActionFactory::close_dialog_and_run(ActionFactory::show_error(false, '%tr%caption_error', array('%tr%error_cant_set_password'))) : ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('%tr%dialog_successful_password_set')); break; case 'profile_cancel': // TODO: Reset to the last selected profile instead of default. $this->profile = $this->profiles[1]; $json_reply = ZTVApi::call(ZTVApi::set_profile($this->profile)); if ($json_reply === false) { return; } return $user_input->selected_media_url != 'setup' ? ActionFactory::close_dialog_and_run(ActionFactory::open_folder()) : ActionFactory::close_dialog_and_run(ActionFactory::show_title_dialog('%ext%<key_local>dialog_default_profile_set<p>' . $this->profile->title . '</p></key_local>')); break; } } } return ActionFactory::reset_controls($this->do_get_control_defs($plugin_cookies)); }