/** * 直播频道对外输出接口 * Enter description here ... */ public function channels() { $condition = $this->get_condition(); $offset = $this->input['offset'] ? intval($this->input['offset']) : 0; $count = $this->input['count'] ? intval($this->input['count']) : 20; $appid = intval($this->input['appid']); if ($this->settings['App_live_takeover'] && !$this->input['fetch_live']) { $channel_id = trim($this->input['id']); if (!$channel_id) { $channel_id = trim($this->input['channel_id']); } $data = array('offset' => $offset, 'count' => $count, 'channel_id' => $channel_id); $channel_info = $this->get_live_takeover_info($data); } else { $field = 'id, name, code, main_stream_name, is_mobile_phone, logo_square, logo_rectangle, server_id, is_audio, status, drm, client_logo, time_shift, is_live, is_record, logo_audio, aspect'; $channel_info = $this->mChannel->get_channel_info($condition, $offset, $count, '', $field); } if (!empty($channel_info)) { $server_id = array(); foreach ($channel_info as $channel) { $server_id[] = $channel['server_id']; } //服务器配置 if (!empty($server_id)) { $server_id = implode(',', @array_unique($server_id)); $_server_info = $this->mServerConfig->get_server_config($server_id); } if ($this->settings['App_live_takeover'] && !$this->input['fetch_live']) { foreach ($channel_info as $channel) { $logo = array('rectangle' => $channel['logo_rectangle'], 'square' => $channel['logo_rectangle']); //节目单 $program_info = $this->mProgram->getCurrentNextProgram($channel['id']); $cur_program = array('start_time' => $program_info[0]['start'] ? $program_info[0]['start'] : date('H:i'), 'program' => $program_info[0]['theme'] ? $program_info[0]['theme'] : '精彩节目'); $next_program = array('start_time' => $program_info[1]['start'] ? $program_info[1]['start'] : date('H:i', TIMENOW + 3600), 'program' => $program_info[1]['theme'] ? $program_info[1]['theme'] : '精彩节目'); $m3u8 = $channel['channel_stream'][0]['m3u8']; $channel_stream = array(); if (!empty($channel['channel_stream'])) { foreach ($channel['channel_stream'] as $kk => $vv) { $channel_stream[$kk] = array('url' => $vv['output_url'], 'm3u8' => $vv['m3u8'], 'bitrate' => $vv['bitrate'], 'live_url' => $vv['live_url'], 'live_m3u8' => $vv['live_m3u8']); } } $record_stream = array(); if (!empty($channel['record_stream'])) { foreach ($channel['record_stream'] as $kk => $vv) { $record_stream[$kk] = array('url' => $vv['output_url'], 'm3u8' => $vv['m3u8']); } } $return = array('id' => $channel['id'], 'name' => $channel['name'], 'logo' => $logo, 'snap' => $channel['snap'], 'm3u8' => $m3u8, 'cur_program' => $cur_program, 'save_time' => $channel['time_shift'], 'next_program' => $next_program, 'audio_only' => $channel['is_audio'], 'aspect' => $channel['aspect'], 'cmid' => $channel['cmid'], 'channel_stream' => $channel_stream, 'record_stream' => $record_stream); if (($this->input['id'] || $this->input['channel_id']) && $return['id'] && $this->user['user_id'] && $this->input['iscreditsrule']) { $credit_rules = $this->callMemberCreditsRules($this->user['user_id'], APP_UNIQUEID, MOD_UNIQUEID, 0, $return['id']); /**积分文案处理**/ $return['copywriting_credit'] = $this->members->copywriting_credit(array($credit_rules)); } $this->addItem($return); } } else { foreach ($channel_info as $channel) { $type = $_server_info[$channel['server_id']]['type'] ? $_server_info[$channel['server_id']]['type'] : 'wowza'; $server_info = $this->mChannel->get_server_info($_server_info[$channel['server_id']]); $channel['server_info'] = $server_info; $wowzaip_output = $server_info['wowzaip_output']; //直播 $live_wowzaip_output = $server_info['live_wowzaip_output']; //录制 $record_wowzaip_output = $server_info['record_wowzaip_output']; if ($channel['client_logo'][$appid]) { unset($channel['client_logo'][$appid]['appid'], $channel['client_logo'][$appid]['appname']); $channel['logo_rectangle'] = $channel['client_logo'][$appid]; } $logo = array('rectangle' => $channel['logo_rectangle'], 'square' => $channel['logo_rectangle']); $snap = array('host' => $this->mImgUrl . LIVE_CONTROL_LIST_PREVIEWIMG_URL, 'dir' => '', 'filepath' => date('Y') . '/' . date('m') . '/', 'filename' => 'live_' . $channel['id'] . '.png?time=' . TIMENOW); if ($channel['is_audio']) { if ($channel['logo_audio']) { $snap = $channel['logo_audio']; } else { $snap = $channel['logo_rectangle']; } } $channel_stream = $record_stream = array(); if ($channel['channel_stream']) { foreach ($channel['channel_stream'] as $kk => $vv) { if ($channel['m3u8_stream_name']) { $stream_n = $channel['m3u8_stream_name']; } else { $stream_n = $channel['main_stream_name']; } $vv['code'] = $channel['code']; $function = 'set_url_info_' . $type; $set_url_info = $this->mChannel->{$function}(array(), $vv); $app_name = $set_url_info['app_name']; $stream_name = $set_url_info['stream_name']; $m3u8_type = $set_url_info['m3u8_type']; $flv = $set_url_info['flv']; $url = hg_set_stream_url($wowzaip_output, $app_name, $stream_name, $flv); if ($channel['is_mobile_phone']) { if ($this->settings['signleliveaddr']) { $m3u8 = $this->settings['signleliveaddr'] . $channel['code'] . '.stream/playlist.m3u8'; } else { $m3u8 = hg_set_stream_url($wowzaip_output, $app_name, $stream_name, $m3u8_type, '', '', '', 'http://', '/' . $vv['stream_name'] . '/live.m3u8'); } if ($live_wowzaip_output && $channel['is_live']) { $m3u8 = hg_set_stream_url($live_wowzaip_output, $app_name, $stream_name, $m3u8_type); } } //直播 if ($live_wowzaip_output && $channel['is_live']) { $live_url = hg_set_stream_url($live_wowzaip_output, $app_name, $stream_name, $flv); if ($channel['is_mobile_phone']) { if ($this->settings['signleliveaddr']) { $live_m3u8 = $this->settings['signleliveaddr'] . $channel['code'] . '.stream/playlist.m3u8'; } else { $live_m3u8 = hg_set_stream_url($live_wowzaip_output, $app_name, $stream_name, $m3u8_type); } } } else { $live_url = $url; $live_m3u8 = $m3u8; } //录制 if ($record_wowzaip_output && $channel['is_record']) { $record_stream[$kk]['url'] = hg_set_stream_url($record_wowzaip_output, $app_name, $stream_name, $flv); if ($channel['is_mobile_phone']) { if ($this->settings['signleliveaddr']) { $record_stream[$kk]['m3u8'] = $this->settings['signleliveaddr'] . $channel['code'] . '.stream/playlist.m3u8'; } else { $record_stream[$kk]['m3u8'] = hg_set_stream_url($record_wowzaip_output, $app_name, $stream_name, $m3u8_type); } } } else { $record_stream[$kk]['url'] = $url; $record_stream[$kk]['m3u8'] = $m3u8; } $bitrate = $vv['bitrate']; $channel_stream[] = array('url' => $url, 'name' => $vv['name'], 'stream_name' => $vv['stream_name'], 'm3u8' => $m3u8, 'bitrate' => $bitrate); } } //节目单 $program_info = $this->mProgram->getCurrentNextProgram($channel['id']); $cur_program = array('start_time' => $program_info[0]['start'] ? $program_info[0]['start'] : date('H:i'), 'program' => $program_info[0]['theme'] ? $program_info[0]['theme'] : '精彩节目'); $next_program = array('start_time' => $program_info[1]['start'] ? $program_info[1]['start'] : date('H:i', TIMENOW + 3600), 'program' => $program_info[1]['theme'] ? $program_info[1]['theme'] : '精彩节目'); $return = array('id' => $channel['id'], 'name' => $channel['name'], 'logo' => $logo, 'snap' => $snap, 'm3u8' => $url, 'cur_program' => $cur_program, 'save_time' => $channel['time_shift'], 'next_program' => $next_program, 'audio_only' => $channel['is_audio'], 'aspect' => $channel['aspect'], 'cmid' => $channel['cmid'], 'channel_stream' => $channel_stream); if (($this->input['id'] || $this->input['channel_id']) && $return['id'] && $this->user['user_id'] && $this->input['iscreditsrule']) { $credit_rules = $this->callMemberCreditsRules($this->user['user_id'], APP_UNIQUEID, MOD_UNIQUEID, 0, $return['id']); /**积分文案处理**/ $return['copywriting_credit'] = $this->members->copywriting_credit(array($credit_rules)); } //统计 if ($this->input['need_access']) { include_once ROOT_PATH . 'lib/class/access.class.php'; $access_obj = new access(); $ret = $access_obj->add_access($return['id'], 0, APP_UNIQUEID, MOD_UNIQUEID, $return['name']); } if ($this->input['ad_group']) { $return['ad'] = $this->getAds($this->input['ad_group'], $return); } $this->addItem($return); } } } $this->output(); }
public function get_content_by_rid() { $id = intval($this->input['id']); if ($id) { $need_pages = intval($this->input['need_pages']); $need_process = intval($this->input['need_process']); $need_separate = intval($this->input['need_separate']); $need_child_detail = intval($this->input['need_child_detail']); $not_need_content = intval($this->input['not_need_content']); $need_special = intval($this->input['need_special']); $sql = "SELECT c.*,c.column_id as main_column_id,r.*,r.id as rid,c.id as id FROM " . DB_PREFIX . "content_relation r LEFT JOIN " . DB_PREFIX . "content c ON r.content_id=c.id WHERE r.id =" . $id; $info = $this->db->query_first($sql); if (empty($info)) { $this->errorOutput('此内容已删除'); } if ($info['indexpic']) { $info['indexpic'] = unserialize($info['indexpic']); } if ($info['video']) { $info['video'] = unserialize($info['video']); $info['video']['filename'] = str_replace('.mp4', '.m3u8', $info['video']['filename']); } if ($info['childs_data']) { $info['childs_data'] = unserialize($info['childs_data']); } if ($info['catalog']) { $info['catalog'] = unserialize($info['catalog']); } $info['title'] = $info['title'] ? htmlspecialchars_decode($info['title']) : ''; $info['brief'] = $info['brief'] ? strip_tags(htmlspecialchars_decode($info['brief'])) : ''; $info['create_time_format'] = date($this->settings['default_time_format'], $info['create_time']); $info['publish_time_stamp'] = $info['publish_time']; $info['create_time_stamp'] = $info['create_time']; $info['publish_time_format'] = date($this->settings['default_time_format'], $info['publish_time']); if ($info['column_id']) { $column_data = $this->column->get_site_column_first(' id,name,site_id,fid,childdomain,father_domain,column_dir,relate_dir,col_con_maketype ', $info['column_id']); $site_data = $column_data['site_data']; } $result = array(); if (!$not_need_content) { $apiname = get_tablename($info['bundle_id'], $info['module_id'], $info['struct_id']); $filedir = $this->settings['get_content_api_path'] . $apiname . '.class' . $this->settings['get_content_api_suffix']; $classname = $apiname; if (file_exists($filedir)) { $data = array('id' => $info['expand_id'], 'url' => urldecode($this->input['url']), 'dir' => urldecode($this->input['dir']), 'need_pages' => urldecode($this->input['need_pages']), 'need_child_detail' => urldecode($this->input['need_child_detail']), 'need_process' => urldecode($this->input['need_process']), 'need_separate' => urldecode($this->input['need_separate']), 'child_offset' => intval($this->input['child_offset']), 'child_count' => intval($this->input['child_count']), 'indexpic' => empty($info['indexpic']) ? array() : $info['indexpic']); //echo $filedir;echo $classname;exit; include $filedir; $module_get = new $classname(); $result = $module_get->get_processed_content($data); $result = is_array($result) ? $result : array(); } } $info1 = $info; $info1['id'] = $info['id']; if ($info['use_maincolumn']) { $column_data = $this->column->get_site_column_first(' id,name,site_id,fid,childdomain,father_domain,column_dir,relate_dir,col_con_maketype ', $info['main_column_id']); $site_data = $column_data['site_data']; $info['content_url'] = $info['outlink'] ? $info['outlink'] : mk_content_url($site_data, $column_data, array('column_id' => $info['main_column_id']) + $info1); } else { $info['content_url'] = $info['outlink'] ? $info['outlink'] : mk_content_url($site_data, $column_data, $info1); } $info['column_info'] = $column_data; if ($this->input['video2index'] && $result['content_material_list']) { foreach ($result['content_material_list'] as $k => $v) { if ($v['app'] == 'livmedia') { $videourl = parse_url($v['video_url']); $info['video'] = array('host' => $videourl['scheme'] . '://' . $videourl['host'], 'dir' => '', 'filepath' => $videourl['path'], 'filename' => ''); $info['is_have_video'] = '1'; break; } } } if ($this->input['shorturl'] && $this->settings['App_shorturl']) { $curl = new curl($this->settings['App_shorturl']['host'], $this->settings['App_shorturl']['dir']); $curl->setReturnFormat('str'); $curl->setSubmitType('post'); $curl->initPostData(); $curl->addRequestData('str', $info['content_url']); $ret = $curl->request('shorturl.php'); if ($ret) { $info['content_url'] = $ret; } } if ($this->settings['App_catalog']) { //取编目信息 $catalog_data = array(); include ROOT_PATH . 'lib/class/catalog.class.php'; $catalogobj = new catalog(); $catalog = $catalogobj->get_catalog($info['bundle_id'], $info['module_id'], $info['content_fromid']); $result['catalog_new'] = $catalog; } $result['source'] = isset($result['source']) ? $result['source'] : ''; $info['source'] = isset($info['source']) ? $info['source'] : $result['source']; if ($result) { $result = $info + $result; } else { $result = $info; } //统计 if ($this->input['need_access']) { include_once ROOT_PATH . 'lib/class/access.class.php'; $access_obj = new access(); $fromType = $this->input['fromType'] ? trim($this->input['fromType']) : ""; $ret = $access_obj->add_access($info['content_id'], $info['column_id'], $info['bundle_id'], $info['module_id'], $info['title'], $info['content_fromid'], $fromType); } //加广告 if ($this->input['ad_group']) { $r = array(); $r['id'] = $result['rid']; $r['colid'] = $result['column_id']; $r['title'] = $result['title']; $r['brief'] = $result['brief']; $r['keywords'] = $result['keywords']; $r['appid'] = $result['appid']; $r['appname'] = $result['appname']; $r['create_user'] = $result['create_user']; $r['publish_user'] = $result['publish_user']; $r['group'] = $this->input['ad_group']; $result['ad'] = $this->getAds($this->input['ad_group'], $r, $r['colid']); } //取这条内容发布到的专题 if ($need_special && $info['content_id']) { $sql = "SELECT relation_data FROM " . DB_PREFIX . "content_push WHERE type=1 AND content_id=" . $info['content_id']; $content_push = $this->db->query_first($sql); if ($content_push) { $special_data = @unserialize($content_push['relation_data']); if ($special_data) { $special_ids = array(); foreach ($special_data as $k => $v) { if ($v['special_id'] = intval($v['special_id'])) { $special_ids[] = $v['special_id']; } } if ($special_ids) { include ROOT_PATH . 'lib/class/special.class.php'; $special_obj = new special(); $special_datas = $special_obj->get_special_by_ids(implode(',', $special_ids)); if (is_array($special_datas)) { $result['special_datas'] = $special_datas; } } } } } $this->addItem($result); $this->output(); } else { $this->errorOutput('NO_ID'); } }