public function __construct(array $nested_params, array $external_params) { parent::__construct($nested_params, $external_params); $this->document = new RESTApiTvChannelDocument($this, $external_params); $this->document->controllers->add(new RESTApiTvChannelLink($this->nested_params)); $this->document->controllers->add(new RESTApiTvChannelRecord($this->nested_params)); $this->controllers->add(new RESTApiTvChannelLast($this->nested_params)); $this->fields_map = array_fill_keys(array('id', "name", "number", "archive", "censored"), true); $this->manager = \Itv::getInstance(); if (!empty($this->nested_params['users.id'])) { $user_id = $this->nested_params['users.id']; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User not found"); } $this->user_id = $user['id']; $this->fav_channels = $this->manager->getFav($this->user_id); $this->user_channels = $this->manager->getAllUserChannelsIdsByUid($this->user_id); } if (!empty($this->nested_params['genre'])) { $genres = new \TvGenre(); $genre = $genres->getById($this->nested_params['genre'], true); if (empty($genre)) { throw new RESTNotFound("Genre not found"); } $this->genre_id = (int) $genre['id']; } }
public function create(RESTApiRequest $request, $parent_id) { if (empty($this->params['users.id'])) { throw new RESTBadRequest("User required"); } $user_id = $this->params['users.id']; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User not found"); } $itv = \Itv::getInstance(); $user_channels = $itv->getAllUserChannelsIdsByUid($user['id']); if (!in_array($parent_id, $user_channels)) { throw new RESTForbidden("User don't have access to this channel"); } $channel = \Itv::getById($parent_id); if (empty($channel)) { throw new RESTNotFound("Channel not found"); } if (!$channel['allow_pvr']) { throw new RESTForbidden("Channel does not support PVR"); } $now_time = time(); $start_time = (int) $request->getData('start_time'); $end_time = (int) $request->getData('end_time'); if ($start_time && $start_time < $now_time) { $start_time = $now_time; } if ($end_time) { if ($start_time && $end_time < $start_time || $end_time < $now_time) { throw new RESTNotAcceptable("Not acceptable time range"); } } $pvr = new \RemotePvr(); try { $rec_id = $pvr->startRecNowByChannelId($channel['id']); } catch (\nPVRException $e) { throw new RESTServerError($e->getMessage()); } if (!$rec_id) { return false; } if ($end_time) { sleep(1); // give some time to dumpstream to startup $recorder = new \StreamRecorder(); $recorder->stopDeferred($rec_id, ceil(($end_time - $now_time) / 60)); } $recording = $pvr->getById($rec_id); return array('id' => $recording['id'], 'name' => $recording['program'], 'start_time' => strtotime($recording['t_start']), 'end_time' => strtotime($recording['t_stop']), 'ch_id' => (int) $recording['ch_id'], 'ch_name' => $channel['name'], 'status' => $recording['started'] ? $recording['ended'] ? 2 : 1 : 0); }
public function create(RESTApiRequest $request, $parent_id) { if (empty($this->params['users.id'])) { throw new RESTBadRequest("User required"); } if (empty($this->params['ch_id'])) { throw new RESTBadRequest("Channel ID required"); } $user_id = (int) $this->params['users.id']; $ch_id = (int) $this->params['ch_id']; $program_id = (int) $parent_id; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User not found"); } $itv = \Itv::getInstance(); $user_channels = $itv->getAllUserChannelsIdsByUid($user['id']); if (!in_array($ch_id, $user_channels)) { throw new RESTForbidden("User don't have access to this channel"); } $channel = \Itv::getById($ch_id); if (empty($channel)) { throw new RESTNotFound("Channel not found"); } if (!$channel['allow_pvr']) { throw new RESTForbidden("Channel does not support PVR"); } $program = \Epg::getById($program_id); if (empty($program)) { throw new RESTNotFound("Program not found"); } if ($program['ch_id'] != $ch_id) { throw new RESTNotAcceptable("Channel of program mismatch"); } if (strtotime($program['time']) < time()) { throw new RESTNotAcceptable("Start time in past"); } $pvr = new \RemotePvr(); try { $rec_id = $pvr->startRecDeferredById($program['real_id']); } catch (\nPVRException $e) { throw new RESTServerError($e->getMessage()); } if (!$rec_id) { return false; } $recording = $pvr->getById($rec_id); return array('id' => $recording['id'], 'name' => $recording['program'], 'start_time' => strtotime($recording['t_start']), 'end_time' => strtotime($recording['t_stop']), 'ch_id' => (int) $recording['ch_id'], 'ch_name' => $channel['name'], 'status' => $recording['started'] ? $recording['ended'] ? 2 : 1 : 0); }
public function __construct(array $nested_params, array $external_params) { parent::__construct($nested_params, $external_params); $this->document = new RESTApiTvFavoriteDocument($this, $this->external_params); if (empty($this->nested_params['users.id'])) { throw new RESTBadRequest("User must be specified"); } $user_id = $this->nested_params['users.id']; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User not found"); } $this->user_id = $user['id']; $this->manager = \Itv::getInstance(); }
public function getAllActive() { $memos = $this->getRaw()->where(array('tv_reminder.mac' => $this->stb->mac, 'tv_reminder.fire_time>' => 'NOW()'))->get()->all(); $dvb_memos = $this->db->select('UNIX_TIMESTAMP(`fire_time`) as fire_ts, TIME_FORMAT(`fire_time`,"%H:%i") as t_fire_time, ch_id, tv_program_id, tv_program_real_id, tv_program_name as program_name')->from('tv_reminder')->where(array('tv_reminder.mac' => $this->stb->mac, 'tv_reminder.fire_time>' => 'NOW()', 'tv_reminder.tv_program_id' => 0))->get()->all(); $dvb_channels_map = array(); $dvb_channels = Itv::getInstance()->getDvbChannels(); foreach ($dvb_channels as $dvb_channel) { $dvb_channels_map[$dvb_channel['id']] = $dvb_channel; } $dvb_memos = array_map(function ($memo) use($dvb_channels_map) { if (!empty($dvb_channels_map[$memo['ch_id']])) { $memo['itv_name'] = $dvb_channels_map[$memo['ch_id']]['name']; } return $memo; }, $dvb_memos); $memos = array_merge($memos, $dvb_memos); return $memos; }
public function get(RESTApiRequest $request, $parent_id) { if (empty($this->params['users.id'])) { throw new RESTBadRequest("User required"); } $user_id = $this->params['users.id']; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User not found"); } $itv = \Itv::getInstance(); $this->user_channels = $itv->getAllUserChannelsIdsByUid($user['id']); if (!in_array($parent_id, $this->user_channels)) { throw new RESTForbidden("User don't have access to this channel"); } $channel = \Itv::getById($parent_id); if (empty($channel)) { throw new RESTNotFound("Channel not found"); } $start = $request->getParam('start'); if ($start) { // todo: time shift! throw new RESTNotFound("Time shift in progress..."); } $urls = \Itv::getUrlsForChannel($channel['id']); if (!empty($urls)) { $link = $urls[0]['id']; } else { $link = null; } try { $url = $itv->getUrlByChannelId($parent_id, $link); } catch (\ItvChannelTemporaryUnavailable $e) { throw new RESTNotFound($e->getMessage()); } if (preg_match("/(\\S+:\\/\\/\\S+)/", $url, $match)) { $url = $match[1]; } return $url; }
public function getProfile() { $debug_key = $this->getDebugKey(); if (Config::getSafe('disable_portal', false) && (empty($debug_key) || !$this->checkDebugKey($debug_key))) { try { Mysql::getInstance()->update('users', array('access_token' => $this->access_token), array('id' => $this->id)); if (\Config::getSafe('bind_stb_auth_and_oauth', true)) { $this->resetOauthToken(); } } catch (MysqlException $e) { echo $e->getMessage() . PHP_EOL; } return array('status' => 1, 'block_msg' => _('The portal is temporarily unavailable.<br>Please try again later.<br>Sorry for the inconvenience.'), 'portal_disabled' => true); } if (function_exists('geoip_country_code_by_name')) { $country = @geoip_country_code_by_name($this->ip); if (!$country) { error_log('geoip_country_code_by_name(): Host ' . $this->ip . ' not found'); } } else { $country = ''; } $model = isset($_REQUEST['stb_type']) ? $_REQUEST['stb_type'] : ''; $serial_number = isset($_REQUEST['sn']) ? $_REQUEST['sn'] : ''; $version = isset($_REQUEST['ver']) ? $_REQUEST['ver'] : ''; $device_id = isset($_REQUEST['device_id']) ? $_REQUEST['device_id'] : ''; $device_id2 = isset($_REQUEST['device_id2']) ? $_REQUEST['device_id2'] : ''; $signature = isset($_REQUEST['signature']) ? $_REQUEST['signature'] : ''; $force_auth = null; $filter_response = $this->passAccessFilter($country, $model, $this->mac, $serial_number, $version, $device_id2, $signature, $force_auth); $this->params['stb_type'] = $model; if (is_array($filter_response)) { $filter_result = $filter_response['result']; } else { $filter_result = $filter_response; } if (!$filter_result) { $this->logDeniedByFilter($country, $model, $this->mac, $version); $profile = array('status' => 1, 'msg' => 'access denied'); if (!empty($filter_response['message'])) { $profile['block_msg'] = _($filter_response['message']); } return $profile; } if ((empty($_SERVER['TARGET']) || $_SERVER['TARGET'] != 'API' && $_SERVER['TARGET'] != 'ADM') && Config::getSafe('enable_mac_format_validation', true) && !Middleware::isValidMAC($this->mac)) { $this->logNotValidMAC(isset($_REQUEST['sn']) ? $_REQUEST['sn'] : '', isset($_REQUEST['stb_type']) ? $_REQUEST['stb_type'] : ''); return array('status' => 1); } $debug_key = $this->getDebugKey(); if (!empty($debug_key) && $this->checkDebugKey($debug_key)) { // emulation } elseif (Config::getSafe('enable_device_id_validation', true)) { if ($device_id2) { $device = Mysql::getInstance()->from('users')->where(array('device_id2' => $device_id2))->get()->first(); if (!empty($device) && strtoupper($device['mac']) != $this->mac) { $this->logDeviceConflict($device_id2, $this->mac, $serial_number, $model, 'MAC address mismatch, reason - device_id2'); return array('status' => 1, 'msg' => 'device conflict - MAC address mismatch'); } } if ($this->id) { $update = array(); if (!$this->getParam('device_id') && $device_id) { $update['device_id'] = $device_id; } if (!$this->getParam('device_id2') && $device_id2) { $update['device_id2'] = $device_id2; } if (!empty($update)) { Mysql::getInstance()->update('users', $update, array('id' => $this->id)); } if ($this->getParam('device_id') && $this->getParam('device_id') != $device_id) { $this->logDeviceConflict($device_id, $this->mac, $serial_number, $model, 'device_id mismatch'); return array('status' => 1, 'msg' => 'device conflict - device_id mismatch', 'block_msg' => _('Your STB is damaged.<br/> Call the provider.')); } if ($this->getParam('device_id2') && $this->getParam('device_id2') != $device_id2) { $this->logDeviceConflict($device_id2, $this->mac, $serial_number, $model, 'device_id2 mismatch'); return array('status' => 1, 'msg' => 'device conflict - device_id mismatch', 'block_msg' => _('Your STB is damaged.<br/> Call the provider.')); } } } if ($model != 'MAG200' && $model != 'MAG260' && (empty($debug_key) || !$this->checkDebugKey($debug_key))) { preg_match("/Player Engine version: (\\S+)/", $version, $match); if (!empty($match[1])) { $player_version = hexdec($match[1]); } if (empty($player_version) || empty($match) || $player_version < 1382) { $auto_update_setting = ImageAutoUpdate::getSettingByStbType($this->params['stb_type']); return array('status' => 1, 'msg' => 'old firmware', 'block_msg' => _('Firmware of your STB is outdated.<br>Please update it.'), 'autoupdate' => empty($auto_update_setting) ? false : $auto_update_setting, 'update_url' => self::getImageUpdateUrl($this->params['stb_type'])); } } $valid_saved_auth = $this->getParam('access_token') && $this->access_token == $this->getParam('access_token') && !intval($_REQUEST['not_valid_token']); if (!$this->id) { $disable_auth_for_models = Config::exist('disable_auth_for_models') ? preg_split("/\\s*,\\s*/", trim(Config::get('disable_auth_for_models'))) : array(); if (!$valid_saved_auth && Config::exist('auth_url') && (!in_array($model, $disable_auth_for_models) || $force_auth === true)) { if (Config::getSafe('init_device_before_auth', false)) { $this->initProfile(null, null, $device_id, $device_id2); $this->getInfoFromOss(!$force_auth); } return array('status' => 2, 'template' => $this->getUserPortalTheme(), 'info' => Config::exist('registration_url') ? sprintf(_('Use your username and password to login or register on %s'), Config::get('registration_url')) : ''); } else { if (!Config::getSafe('auto_add_stb', true)) { return array('status' => 1, 'block_msg' => str_replace('.', '!', _('Please contact your provider<br>to register this device.'))); } else { $this->initProfile(null, null, $device_id, $device_id2); $this->params['stb_type'] = $model; } } } else { Mysql::getInstance()->update('users', array('access_token' => $this->access_token), array('id' => $this->id)); if (\Config::getSafe('bind_stb_auth_and_oauth', true)) { $this->resetOauthToken(); } if (!$valid_saved_auth && intval($_REQUEST['auth_second_step']) === 0 && Config::exist('auth_url') && (strpos(Config::get('auth_url'), 'auth_every_load') || $force_auth === true)) { $this->getInfoFromOss(!$force_auth); return array('status' => 2, 'template' => $this->getUserPortalTheme(), 'info' => Config::exist('registration_url') ? sprintf(_('Use your username and password to login or register on %s'), Config::get('registration_url')) : ''); } } $this->db->update('users', array('last_start' => 'NOW()', 'keep_alive' => 'NOW()', 'version' => @$_REQUEST['ver'], 'hd' => @$_REQUEST['hd'], 'stb_type' => $model, 'video_out' => isset($_REQUEST['video_out']) ? $_REQUEST['video_out'] : '', 'serial_number' => isset($_REQUEST['sn']) ? $_REQUEST['sn'] : '', 'num_banks' => isset($_REQUEST['num_banks']) ? (int) $_REQUEST['num_banks'] : 0, 'image_version' => isset($_REQUEST['image_version']) ? $_REQUEST['image_version'] : '', 'locale' => $this->locale, 'country' => $country, 'verified' => (int) ($force_auth === false), 'hw_version' => isset($_REQUEST['hw_version']) ? $_REQUEST['hw_version'] : ''), array('id' => $this->id)); $info = $this->getInfoFromOss(!$force_auth); if (self::$just_created == true && Config::getSafe('enable_welcome_message', false)) { $event = new SysEvent(); $event->setUserListById($this->id); $event->sendMsg(sprintf(_('Welcome %s<br>We are glad to see you on the Stalker portal!'), $this->getParam('fname'))); } $master = new VideoMaster(); $profile = $this->params; if ($info && array_key_exists('error_msg', $info)) { $profile['block_msg'] = $info['error_msg']; } $profile['storages'] = $master->getStoragesForStb(); $itv = Itv::getInstance(); $profile['last_itv_id'] = $itv->getLastId(); $profile['updated'] = $this->getUpdatedPlaces(); $profile['rtsp_type'] = Config::get('rtsp_type'); $profile['rtsp_flags'] = Config::get('rtsp_flags'); $profile['locale'] = $this->locale; $profile['stb_lang'] = $this->stb_lang; $profile['display_menu_after_loading'] = empty($this->params['show_after_loading']) ? Config::getSafe('display_menu_after_loading', false) : $this->params['show_after_loading'] == 'main_menu'; $profile['record_max_length'] = intval(Config::get('record_max_length')); $profile['web_proxy_host'] = Config::exist('stb_http_proxy_host') ? Config::get('stb_http_proxy_host') : ''; $profile['web_proxy_port'] = Config::exist('stb_http_proxy_port') ? Config::get('stb_http_proxy_port') : ''; $profile['web_proxy_user'] = Config::exist('stb_http_proxy_user') ? Config::get('stb_http_proxy_user') : ''; $profile['web_proxy_pass'] = Config::exist('stb_http_proxy_pass') ? Config::get('stb_http_proxy_pass') : ''; $profile['web_proxy_exclude_list'] = Config::exist('stb_http_proxy_exclude_list') ? Config::get('stb_http_proxy_exclude_list') : ''; $profile['update_url'] = self::getImageUpdateUrl(empty($_REQUEST['stb_type']) ? 'mag250' : $_REQUEST['stb_type']); if (!in_array($this->mac, Config::getSafe('playback_limit_whitelist', array()))) { $profile['playback_limit'] = (int) Config::get('enable_playback_limit', 0); } else { $profile['playback_limit'] = 0; } $profile['demo_video_url'] = Config::getSafe('demo_video_url', ''); $profile['tv_quality_filter'] = Config::get('enable_tv_quality_filter'); $profile['use_embedded_settings'] = Config::getSafe('use_embedded_settings', false); $profile['test_download_url'] = Config::getSafe('test_download_url', ''); $profile['is_moderator'] = $this->isModerator(); $profile['watchdog_timeout'] = Config::getSafe('watchdog_timeout', 30000); $max_id = Mysql::getInstance()->select('max(id) as max_id')->from('users')->get()->first('max_id'); $profile['timeslot_ratio'] = $this->id / $max_id; $profile['timeslot'] = $profile['timeslot_ratio'] * $profile['watchdog_timeout']; $profile['kinopoisk_rating'] = Config::getSafe('kinopoisk_rating', true); $profile['enable_tariff_plans'] = Config::getSafe('enable_tariff_plans', false); $profile['enable_buffering_indication'] = Config::getSafe('enable_buffering_indication', false); $profile['default_timezone'] = Config::getSafe('default_timezone', ''); $profile['default_locale'] = Config::getSafe('default_locale', ''); $profile['allowed_stb_types'] = array_map(function ($item) { return strtolower(trim($item)); }, explode(',', Config::getSafe('allowed_stb_types', 'MAG200,MAG245,MAG245D,MAG250,MAG254,MAG255,MAG260,MAG270,MAG275,AuraHD,WR320,IP_STB_HD'))); $profile['allowed_stb_types_for_local_recording'] = array_map(function ($item) { return strtolower(trim($item)); }, explode(',', Config::getSafe('allowed_stb_types_for_local_recording', 'MAG245,MAG245D,MAG250,MAG254,MAG255,MAG260,MAG270,MAG275,AuraHD,WR320,IP_STB_HD'))); $auto_update_setting = ImageAutoUpdate::getSettingByStbType($this->params['stb_type']); if ($auto_update_setting) { $profile['autoupdate'] = $auto_update_setting; } $profile['strict_stb_type_check'] = Config::getSafe('strict_stb_type_check', false); $profile['cas_type'] = Config::getSafe('cas_type', 0); $profile['cas_params'] = Config::getSafe('cas_params', null); $profile['cas_web_params'] = Config::getSafe('cas_web_params', null); $profile['cas_additional_params'] = Config::getSafe('cas_additional_params', array()); $profile['cas_hw_descrambling'] = Config::getSafe('cas_hw_descrambling', 0); $profile['cas_ini_file'] = Config::getSafe('cas_ini_file', ""); $profile['logarithm_volume_control'] = Config::getSafe('logarithm_volume_control', false); $profile['allow_subscription_from_stb'] = Config::getSafe('allow_subscription_from_stb', true); $profile['deny_720p_gmode_on_mag200'] = Config::getSafe('deny_720p_gmode_on_mag200', false); $profile['enable_arrow_keys_setpos'] = Config::getSafe('enable_arrow_keys_setpos', false); $profile['show_purchased_filter'] = Config::getSafe('show_purchased_filter', false); $profile['timezone_diff'] = $this->timezone_diff; $profile['enable_connection_problem_indication'] = Config::getSafe('enable_connection_problem_indication', true); $profile['invert_channel_switch_direction'] = Config::getSafe('invert_channel_switch_direction', false); $profile['play_in_preview_only_by_ok'] = $this->params['play_in_preview_by_ok'] === null ? (bool) Config::getSafe('play_in_preview_only_by_ok', false) : (bool) $this->params['play_in_preview_by_ok']; $profile['enable_stream_error_logging'] = Config::getSafe('enable_stream_error_logging', false); $profile['always_enabled_subtitles'] = Config::getSafe('always_enabled_subtitles', false); $profile['enable_service_button'] = Config::getSafe('enable_service_button', false); $profile['enable_setting_access_by_pass'] = Config::getSafe('enable_setting_access_by_pass', false); $profile['show_tv_channel_logo'] = Config::getSafe('show_tv_channel_logo', true); $profile['tv_archive_continued'] = Config::getSafe('tv_archive_continued', false); $profile['plasma_saving_timeout'] = Config::getSafe('plasma_saving_timeout', false); $profile['show_tv_only_hd_filter_option'] = Config::getSafe('show_tv_only_hd_filter_option', false); $profile['tv_playback_retry_limit'] = Config::getSafe('tv_playback_retry_limit', 0); $profile['fading_tv_retry_timeout'] = Config::getSafe('fading_tv_retry_timeout', true); $profile['epg_update_time_range'] = floatval(Config::getSafe('epg_update_delay_per_user', 0.2)) * $max_id; $profile['store_auth_data_on_stb'] = Config::getSafe('store_auth_data_on_stb', true) && Config::exist('auth_url') && $force_auth !== false; if (Config::getSafe('enable_tariff_plans', false)) { $profile['additional_services_on'] = '1'; } $profile['hdmi_event_reaction'] = $profile['hdmi_event_reaction'] === null ? (int) Config::getSafe('enable_hdmi_events_handler', true) : (int) $profile['hdmi_event_reaction']; $profile['account_page_by_password'] = Config::getSafe('account_page_by_password', false); $profile['tester'] = Mysql::getInstance()->from('testers')->where(array('mac' => $this->mac, 'status' => 1))->get()->first() != null; $profile['show_channel_logo_in_preview'] = Config::getSafe('show_channel_logo_in_preview', false); $profile['enable_stream_losses_logging'] = Config::getSafe('enable_stream_losses_logging', false); $profile['external_payment_page_url'] = sprintf(Config::getSafe('external_payment_page_url', ''), $this->getParam('ls'), $this->mac); $profile['max_local_recordings'] = Config::getSafe('max_local_recordings', 10); $profile['tv_channel_default_aspect'] = Config::getSafe('tv_channel_default_aspect', 'fit'); $profile['default_led_level'] = Config::getSafe('default_led_level', 10); $profile['standby_led_level'] = Config::getSafe('standby_led_level', 90); if (Config::exist('portal_logo_url')) { $profile['portal_logo_url'] = Config::get('portal_logo_url'); } $profile['show_version_in_main_menu'] = Config::getSafe('show_version_in_main_menu', true); $profile['check_ssl_certificate'] = (int) Config::getSafe('check_ssl_certificate', false); $profile['disable_youtube_for_mag200'] = Config::getSafe('disable_youtube_for_mag200', true); $profile['hls_fast_start'] = Config::getSafe('hls_fast_start', true); $profile['auth_access'] = Config::exist('auth_url'); $profile['epg_data_block_period_for_stb'] = Config::getSafe('epg_data_block_period_for_stb', 5); $profile['standby_on_hdmi_off'] = Config::getSafe('standby_on_hdmi_off', false); $profile['force_ch_link_check'] = Config::getSafe('force_ch_link_check', false); unset($profile['device_id']); unset($profile['device_id2']); unset($profile['access_token']); unset($profile['serial_number']); return $profile; }
public function __construct() { $this->manager = Itv::getInstance(); $this->allowed_fields = array_fill_keys(array('id', 'name', 'number', 'base_ch', 'hd', 'url', 'enable_monitoring'), true); }
public function getDataTable() { $page = intval($_REQUEST['p']); $ch_id = intval($_REQUEST['ch_id']); $from = $_REQUEST['from']; $to = $_REQUEST['to']; $default_page = false; $page_items = 10; $all_user_ids = Itv::getInstance()->getAllUserChannelsIds(); $dvb_channels = Itv::getInstance()->getDvbChannels(); if (!empty($_REQUEST['fav'])) { $fav = Itv::getInstance()->getFav(Stb::getInstance()->id); $all_user_ids = array_intersect($all_user_ids, $fav); $fav_assoc = array_fill_keys($fav, 1); $dvb_channels = array_values(array_filter($dvb_channels, function ($channel) use($fav_assoc) { return isset($fav_assoc[$channel['id']]); })); } $dvb_ch_idx = null; $channel = Itv::getChannelById($ch_id); if (empty($channel)) { foreach ($dvb_channels as $dvb_channel) { if ($dvb_channel['id'] == $ch_id) { $channel = $dvb_channel; break; } } for ($i = 0; $i < count($dvb_channels); $i++) { if ($dvb_channels[$i]['id'] == $ch_id) { $channel = $dvb_channels[$i]; $dvb_ch_idx = $i; } } if ($dvb_ch_idx != null) { $dvb_ch_idx++; } } $total_channels = Itv::getInstance()->getChannels()->orderby('number')->in('id', $all_user_ids)->get()->count(); $total_iptv_channels = $total_channels; $total_channels += count($dvb_channels); $ch_idx = Itv::getInstance()->getChannels()->orderby(isset($fav) ? 'field(id,' . (empty($fav) ? 'null' : implode(',', $fav)) . ')' : 'number')->in('id', $all_user_ids)->where(array('number<=' => $channel['number']))->get()->count(); $ch_idx += $dvb_ch_idx; if ($ch_idx === false) { $ch_idx = 0; } if ($page == 0) { $default_page = true; $page = ceil($ch_idx / $page_items); } $ch_idx = $ch_idx - ($page - 1) * $page_items; $user_channels = Itv::getInstance()->getChannels()->orderby(isset($fav) ? 'field(id,' . (empty($fav) ? 'null' : implode(',', $fav)) . ')' : 'number')->in('id', $all_user_ids)->limit($page_items, ($page - 1) * $page_items)->get()->all(); $total_iptv_pages = ceil($total_iptv_channels / $page_items); if (count($user_channels) < $page_items) { if ($page == $total_iptv_pages) { $dvb_part_length = $page_items - $total_iptv_channels % $page_items; } else { $dvb_part_length = $page_items; } if ($page > $total_iptv_pages) { $dvb_part_offset = ($page - $total_iptv_pages - 1) * $page_items + ($page_items - $total_iptv_channels % $page_items); } else { $dvb_part_offset = 0; } if (isset($_REQUEST['p'])) { $dvb_channels = array_splice($dvb_channels, $dvb_part_offset, $dvb_part_length); } $user_channels = array_merge($user_channels, $dvb_channels); } $display_channels_ids = array(); for ($i = 0; $i < count($user_channels); $i++) { if (Config::getSafe('enable_numbering_in_order', false)) { $user_channels[$i]['number'] = (string) ($i + 1 + ($page - 1) * 10); } $display_channels_ids[] = $user_channels[$i]['id']; } $raw_epg = $this->getEpgForChannelsOnPeriod($display_channels_ids, $from, $to); $result = array(); $num = 1; foreach ($raw_epg as $id => $epg) { $channel = $user_channels[array_search($id, $display_channels_ids)]; $result[] = array('ch_id' => $id, 'name' => $channel['name'], 'number' => !empty($_REQUEST['fav']) ? (string) $num : $channel['number'], 'ch_type' => isset($channel['type']) && $channel['type'] == 'dvb' ? 'dvb' : 'iptv', 'dvb_id' => isset($channel['type']) && $channel['type'] == 'dvb' ? $channel['dvb_id'] : null, 'epg_container' => 1, 'epg' => $epg); $num++; } $time_marks = array(); $from_ts = strtotime($from); $to_ts = strtotime($to); /// Time format. See: http://ua2.php.net/manual/en/function.date.php $time_marks[] = date(_("H:i"), $from_ts); $time_marks[] = date(_("H:i"), $from_ts + 1800); $time_marks[] = date(_("H:i"), $from_ts + 2 * 1800); $time_marks[] = date(_("H:i"), $from_ts + 3 * 1800); if (!$default_page) { //$ch_idx = 0; //$page = 0; } if (!in_array($ch_id, $display_channels_ids)) { $ch_idx = 0; $page = 0; } else { $ch_idx = array_search($ch_id, $display_channels_ids) + 1; } //var_dump($display_channels_ids, $ch_id, $ch_idx); return array('total_items' => $total_channels, 'max_page_items' => $page_items, 'cur_page' => $page, 'selected_item' => $ch_idx, 'time_marks' => $time_marks, 'from_ts' => $from_ts, 'to_ts' => $to_ts, 'data' => $result); }
public function __construct() { $this->manager = Itv::getInstance(); }