/** * import channel & city info connection */ public static function import() { $arChannelCity = array(); $arFilter = array(); $arSelect = array("ID", "UF_CHANNEL_ID", "UF_CITY_ID"); $result = ChannelCityTable::getList(array('filter' => $arFilter, 'select' => $arSelect)); while ($arItem = $result->fetch()) { $arChannelCity[$arItem["UF_CHANNEL_ID"] . "-" . $arItem["UF_CITY_ID"]] = $arItem["ID"]; } $arCities = array(); $arFilter = array("UF_COUNTRY.UF_TITLE" => "Россия", "UF_ACTIVE" => 1); $arSelect = array("ID", "UF_TITLE"); $result = CityTable::getList(array('filter' => $arFilter, 'select' => $arSelect)); while ($arCity = $result->fetch()) { $arCities[$arCity["UF_TITLE"]] = $arCity["ID"]; } $arChannels = array(); $arFilter = array(); $arSelect = array("ID", "UF_EPG_ID"); $result = ChannelTable::getList(array('filter' => $arFilter, 'select' => $arSelect)); while ($arChannel = $result->fetch()) { $arChannels[$arChannel["UF_EPG_ID"]] = $arChannel["ID"]; } $file = $_SERVER["DOCUMENT_ROOT"] . "/local/modules/hawkart.megatv/data/channel_city.csv"; $lines = file($file); foreach ($lines as $line_num => $line) { $arItem = explode(";", $line); $city = trim($arItem[0]); foreach ($arItem as $value) { if (strpos($value, "channel_id=") !== false) { $channel_epg_id = str_replace("channel_id=", "", $value); $channel_epg_id = trim($channel_epg_id); $city_id = $arCities[$city]; $channel_id = $arChannels[$channel_epg_id]; if (intval($arChannelCity[$channel_id . "-" . $city_id]) == 0 && intval($city_id) > 0 && intval($channel_id) > 0) { //echo $city." ".$channel_epg_id."<br />"; $arFields = array("UF_CITY_ID" => $city_id, "UF_CHANNEL_ID" => $channel_id); //\CDev::pre($arFields); $result = ChannelCityTable::add($arFields); if ($result->isSuccess()) { $id = $result->getId(); $arChannelCity[$channel_id . "-" . $city_id] = $id; } } } } } }
define('STOP_STATISTICS', true); require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'; $GLOBALS['APPLICATION']->RestartBuffer(); global $USER; if (!is_object($USER)) { $USER = new \CUser(); } if (!$USER->IsAuthorized()) { return false; } /** * Показ прямого эфира канала */ if (isset($_REQUEST["channel_id"])) { $result = \Hawkart\Megatv\ChannelTable::getList(array('filter' => array("=ID" => intval($_REQUEST["channel_id"])), 'select' => array('ID', 'UF_TITLE' => 'UF_BASE.UF_TITLE', 'UF_STREAM_URL' => 'UF_BASE.UF_STREAM_URL'), 'limit' => 1)); $arChannel = $result->fetch(); ?> <div class="broadcast-player" data-module="broadcast-player"> <script type="text/x-config"> { "seekTime": "0", "broadcastID": "0", "streamURL": "<?php echo $arChannel["UF_STREAM_URL"]; ?> ", "posterURL": "<?php echo $arChannel["UF_IMG_PATH"]; ?> ",
/** * Download file xml from EPG service to server * */ public function importChannels() { $arHrefChannels = array(); $arBaseChannels = array(); $result = ChannelBaseTable::getList(array('filter' => array(), 'select' => array("UF_EPG_ID", "ID", "UF_ACTIVE"), 'order' => array("ID" => "ASC"))); while ($row = $result->fetch()) { if ($arBaseChannels[$row["UF_EPG_ID"]]["ID"] > 0) { ChannelBaseTable::delete($row["ID"]); //if dublicate exist } else { $arBaseChannels[$row["UF_EPG_ID"]] = $row; } } $arChannels = array(); $result = ChannelTable::getList(array('filter' => array("!UF_EPG_ID" => false), 'select' => array("UF_EPG_ID", "ID", "UF_BASE_ID"))); while ($row = $result->fetch()) { $arChannels[$row["UF_EPG_ID"]] = $row; } foreach ($this->xml->channel as $_arChannel) { $attr = $_arChannel->{'base-channel'}->attributes(); $base_epg_id = trim((string) $attr["id"]); $json = json_encode($_arChannel); $arChannel = json_decode($json, TRUE); $epg_id = trim((string) $arChannel["@attributes"]["id"]); $name = trim((string) $arChannel["display-name"]); $base_title = trim((string) $arChannel["base-channel"]); $icon = (string) $arChannel["@attributes"]["src"]; $href = trim((string) $arChannel["href"]); $arHrefChannels[$epg_id][] = $href; if (!empty($base_epg_id) && $base_epg_id != $epg_id) { ChannelBaseTable::delete($epg_id); unset($arBaseChannels[$epg_id]); if (!is_array($arBaseChannels[$base_epg_id])) { $arFields = array("UF_ACTIVE" => 0, "UF_EPG_ID" => $base_epg_id, "UF_TITLE" => trim((string) $arChannel["base-channel"])); $result = ChannelBaseTable::add($arFields); if ($result->isSuccess()) { $id = $result->getId(); $arFields["ID"] = $id; $arBaseChannels[$base_epg_id] = $arFields; } else { $errors = $result->getErrorMessages(); } } } else { if (!is_array($arBaseChannels[$epg_id])) { $arFields = array("UF_ACTIVE" => 0, "UF_EPG_ID" => $epg_id, "UF_TITLE" => $name); $result = ChannelBaseTable::add($arFields); if ($result->isSuccess()) { $id = $result->getId(); $arFields["ID"] = $id; $arBaseChannels[$epg_id] = $arFields; } else { $errors = $result->getErrorMessages(); } } } if (!is_array($arChannels[$epg_id])) { if (empty($base_epg_id)) { $base_epg_id = $epg_id; } $arFields = array("UF_EPG_ID" => $epg_id, "UF_BASE_ID" => $arBaseChannels[$base_epg_id]["ID"]); $result = ChannelTable::add($arFields); if ($result->isSuccess()) { $id = $result->getId(); $arFields["ID"] = $id; $arChannels[$epg_id] = $arFields; } else { $errors = $result->getErrorMessages(); } } if (empty($base_epg_id)) { $base_epg_id = $epg_id; } $arChannels[$epg_id]["UF_BASE_EPG_ID"] = $base_epg_id; } $this->base_channels = $arBaseChannels; $this->channels = $arChannels; $this->href_channels = $arHrefChannels; return $arChannels; }