Пример #1
0
 public function prepareData()
 {
     $fav = $this->getFav();
     $censored_list = $this->getCensoredList();
     $censored_exclude_list = $this->getCensoredExcludeList();
     $dvb_channels = $this->getDvbChannels();
     //var_dump('!!!!!!!!!!!!!!!!', $censored_list, $censored_exclude_list, $this->include_censored);
     $epg = new Epg();
     $quality = $this->stb->getParam('tv_quality');
     $total_iptv_channels = (int) $this->response['total_items'];
     if (!empty($_REQUEST['fav'])) {
         $dvb_channels = array_values(array_filter($dvb_channels, function ($channel) use($fav) {
             return in_array($channel['id'], $fav);
         }));
     }
     if (@$_REQUEST['sortby'] != 'name' && (empty($_REQUEST['genre']) || $_REQUEST['genre'] == '*' || $_REQUEST['genre'] == 'dvb')) {
         $this->response['total_items'] += count($dvb_channels);
     }
     if ((count($this->response['data']) < self::max_page_items && !empty($dvb_channels) || !isset($_REQUEST['p'])) && @$_REQUEST['sortby'] != 'name' && (empty($_REQUEST['genre']) || $_REQUEST['genre'] == '*' || $_REQUEST['genre'] == 'dvb')) {
         $total_iptv_pages = ceil($total_iptv_channels / self::max_page_items);
         if ($this->page == $total_iptv_pages - 1) {
             $dvb_part_length = self::max_page_items - $total_iptv_channels % self::max_page_items;
         } else {
             $dvb_part_length = self::max_page_items;
         }
         if (!empty($_REQUEST['genre']) && $_REQUEST['genre'] == 'dvb') {
             $dvb_part_offset = $this->page * self::max_page_items;
         } elseif ($this->page + 1 > $total_iptv_pages) {
             $diff_items = $total_iptv_channels % self::max_page_items;
             $dvb_part_offset = ($this->page - $total_iptv_pages) * self::max_page_items + ($diff_items > 0 ? self::max_page_items - $diff_items : 0);
         } else {
             $dvb_part_offset = 0;
         }
         if (isset($_REQUEST['p'])) {
             $dvb_channels = array_splice($dvb_channels, $dvb_part_offset, $dvb_part_length);
         }
         $this->response['data'] = array_merge($this->response['data'], $dvb_channels);
         if (!empty($_REQUEST['fav'])) {
             $ordered_list = array();
             $channels_map = array();
             foreach ($this->response['data'] as $channel) {
                 $channels_map[$channel['id']] = $channel;
             }
             foreach ($fav as $ch_id) {
                 if (!empty($channels_map[$ch_id])) {
                     $ordered_list[] = $channels_map[$ch_id];
                 }
             }
             $this->response['data'] = $ordered_list;
         }
     }
     $length = count($this->response['data']);
     $enable_numbering_in_order = Config::getSafe('enable_numbering_in_order', false);
     $excluded = 0;
     $ch_ids = array();
     for ($i = 0; $i < $length; $i++) {
         if (Config::get('enable_tv_quality_filter')) {
             if ($quality == 'low') {
                 if ($this->response['data'][$i]['cmd_3']) {
                     $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_3'];
                     $this->response['data'][$i]['quality_low'] = 1;
                 } else {
                     if ($this->response['data'][$i]['cmd_2']) {
                         $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_2'];
                         $this->response['data'][$i]['quality_medium'] = 1;
                     } else {
                         $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_1'];
                         $this->response['data'][$i]['quality_high'] = 1;
                     }
                 }
             } else {
                 if ($quality == 'medium') {
                     if ($this->response['data'][$i]['cmd_2']) {
                         $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_2'];
                         $this->response['data'][$i]['quality_medium'] = 1;
                     } else {
                         if ($this->response['data'][$i]['cmd_3']) {
                             $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_3'];
                             $this->response['data'][$i]['quality_low'] = 1;
                         } else {
                             $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_1'];
                             $this->response['data'][$i]['quality_high'] = 1;
                         }
                     }
                 } else {
                     if ($this->response['data'][$i]['cmd_1']) {
                         $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_1'];
                         $this->response['data'][$i]['quality_high'] = 1;
                     } else {
                         if ($this->response['data'][$i]['cmd_2']) {
                             $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_2'];
                             $this->response['data'][$i]['quality_medium'] = 1;
                         } else {
                             $this->response['data'][$i]['cmd'] = $this->response['data'][$i]['cmd_3'];
                             $this->response['data'][$i]['quality_low'] = 1;
                         }
                     }
                 }
             }
         }
         if ($this->response['data'][$i]['censored'] && !in_array($this->response['data'][$i]['id'], $censored_exclude_list)) {
             $this->response['data'][$i]['lock'] = 1;
         } else {
             $this->response['data'][$i]['lock'] = 0;
         }
         if (in_array($this->response['data'][$i]['id'], $censored_list)) {
             $this->response['data'][$i]['lock'] = 1;
         }
         unset($this->response['data'][$i]['descr']);
         unset($this->response['data'][$i]['monitoring_url']);
         if ($this->response['data'][$i]['lock'] == 1 && !$this->include_censored) {
             array_splice($this->response['data'], $i, 1);
             $length--;
             $i--;
             $excluded++;
             continue;
         }
         if (in_array($this->response['data'][$i]['id'], $fav)) {
             $this->response['data'][$i]['fav'] = 1;
         } else {
             $this->response['data'][$i]['fav'] = 0;
         }
         if ($this->response['data'][$i]['enable_tv_archive']) {
             $this->response['data'][$i]['archive'] = 1;
         } else {
             $this->response['data'][$i]['archive'] = 0;
         }
         if (@$_REQUEST['fav'] || $enable_numbering_in_order) {
             $this->response['data'][$i]['number'] = strval($i + 1 + self::max_page_items * $this->page + (!empty($_REQUEST['fav']) ? $excluded : 0));
         }
         $this->response['data'][$i]['genres_str'] = '';
         $this->response['data'][$i]['epg'] = empty($next_five_epg) ? array() : $next_five_epg;
         $this->response['data'][$i]['open'] = 1;
         if ($this->response['data'][$i]['use_http_tmp_link']) {
             $this->response['data'][$i]['cmd'] = 'ffrt http://' . Config::get('stream_proxy') . '/ch/' . $this->response['data'][$i]['id'];
         }
         if ($this->response['data'][$i]['enable_wowza_load_balancing']) {
             $this->response['data'][$i]['use_http_tmp_link'] = 1;
             $this->response['data'][$i]['cmd'] = 'udp://ch/' . $this->response['data'][$i]['id'];
         }
         if (Config::get('enable_subscription') && (empty($this->response['data'][$i]['type']) || $this->response['data'][$i]['type'] != 'dvb')) {
             if (in_array($this->response['data'][$i]['id'], $this->getAllUserChannelsIds()) || $this->stb->isModerator()) {
                 //if (in_array($this->response['data'][$i]['id'], $this->getAllUserChannelsIds())){
                 $this->response['data'][$i]['open'] = 1;
             } else {
                 $this->response['data'][$i]['open'] = 0;
                 $this->response['data'][$i]['cmd'] = 'udp://wtf?';
             }
         }
         if ($this->response['data'][$i]['status'] == 0 && $this->stb->isModerator()) {
             $this->response['data'][$i]['only_for_moderator'] = 1;
         }
         $ch_ids[] = $this->response['data'][$i]['id'];
         $this->response['data'][$i]['mc_cmd'] = empty($this->response['data'][$i]['mc_cmd']) ? '' : '1';
         $this->response['data'][$i]['allow_pvr'] = $this->response['data'][$i]['allow_pvr'] == 0 ? '' : '1';
         $this->response['data'][$i]['allow_local_pvr'] = $this->response['data'][$i]['allow_local_pvr'] == 0 ? '' : '1';
         $this->response['data'][$i]['pvr'] = (int) (Config::getSafe('show_tv_channel_pvr_icon', true) && ($this->response['data'][$i]['allow_pvr'] || $this->response['data'][$i]['allow_local_pvr']));
     }
     $cur_programs = $epg->getCurProgramsMap($ch_ids);
     $urls_map = $this->getUrlsMapForChannels($ch_ids);
     for ($i = 0; $i < count($this->response['data']); $i++) {
         $cur_program = isset($cur_programs[$this->response['data'][$i]['id']]) ? $cur_programs[$this->response['data'][$i]['id']] : null;
         if (!empty($cur_program)) {
             $cur_playing = $cur_program['t_time'] . ' ' . $cur_program['name'];
         } else {
             $cur_playing = $this->no_ch_info;
         }
         $this->response['data'][$i]['cur_playing'] = $cur_playing;
         if (empty($this->response['data'][$i]['type']) || $this->response['data'][$i]['type'] != 'dvb') {
             $this->response['data'][$i]['cmds'] = isset($urls_map[$this->response['data'][$i]['id']]) ? $urls_map[$this->response['data'][$i]['id']] : array();
             $this->response['data'][$i]['cmd'] = empty($this->response['data'][$i]['cmds'][0]['url']) ? '' : $this->response['data'][$i]['cmds'][0]['url'];
             $this->response['data'][$i]['use_http_tmp_link'] = empty($this->response['data'][$i]['cmds'][0]['use_http_tmp_link']) ? 0 : $this->response['data'][$i]['cmds'][0]['use_http_tmp_link'];
             $this->response['data'][$i]['wowza_tmp_link'] = empty($this->response['data'][$i]['cmds'][0]['wowza_tmp_link']) ? 0 : $this->response['data'][$i]['cmds'][0]['wowza_tmp_link'];
             $this->response['data'][$i]['use_load_balancing'] = empty($this->response['data'][$i]['cmds'][0]['use_load_balancing']) ? 0 : $this->response['data'][$i]['cmds'][0]['use_load_balancing'];
         }
         if (empty($this->response['data'][$i]['cmds']) || $this->response['data'][$i]['enable_monitoring'] && $this->response['data'][$i]['monitoring_status'] == 0) {
             $this->response['data'][$i]['open'] = 0;
             $this->response['data'][$i]['error'] = 'limit';
             $this->response['data'][$i]['cmd'] = 'udp://wtf?';
         }
     }
     return $this->response;
 }