<?php

include './common.php';
use Ministra\Lib\AppsManager;
use Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\b0144dbc621686d5838378f3b96bd17b;
use Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\d3507c2999d38573a0a0c91771d70af2;
\Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\bb5983936c5682303b7e1f00d856be9f('STB Api', __FILE__);
if (empty($_GET['name']) || empty($_GET['mac'])) {
    exit;
}
$alias = \str_replace('external_', '', $_GET['name']);
$app = \Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\d3507c2999d38573a0a0c91771d70af2::getInstance()->from('apps')->where(['alias' => $alias])->get()->first();
if (empty($app) || $app['status'] == 0) {
    exit;
}
$apps = new \Ministra\Lib\AppsManager();
$app = $apps->getAppInfoWoFetch($app['id']);
if (!$app['installed']) {
    exit;
}
\header('Content-Type: application/x-javascript');
$user = \Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\d3507c2999d38573a0a0c91771d70af2::getInstance()->from('users')->where(['mac' => $_GET['mac']])->get()->first();
$disabled_for_mag200_apps = ['youtube.com', 'zoomby', 'megogo', 'olltv'];
if ($user && $user['stb_type'] == 'MAG200' && \in_array(\strtolower($app['name']), $disabled_for_mag200_apps) !== \false) {
    exit;
}
$user_theme = empty($user['theme']) || !\array_key_exists($user['theme'], \Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\b0144dbc621686d5838378f3b96bd17b::b472d720cadb27c7cc77c19e951e23a4()) ? \Ministra\Lib\w13ec15f0067ea75861e61e27c990e4ba\d3507c2999d38573a0a0c91771d70af2::getInstance()->from('settings')->get()->first('default_template') : $user['theme'];
$icon = $app['app_url'] . '/img/{0}/' . $app['icons'] . '/' . ($user_theme == 'default' ? '2010' : '2014') . '.png';
if ($app['options'] && ($options = \json_decode($app['options'], \true))) {
    $app['app_url'] .= (\strpos($app['app_url'], '?') ? '&' : '?') . \http_build_query($options);
}
?>
/**
* Redirection to <?php 
echo $app['name'];
?> module.
*/
(function(){

main_menu.add('<?php 
echo $app['name'];
?>', [], '<?php 
echo $icon;
?>', function(){

var params = '';

var url = '<?php 
echo $app['app_url'];
?>';

if (stb.user['web_proxy_host']){
params += (url.indexOf('?') == -1 ? '?' : '&')+'proxy=http://';
if (stb.user['web_proxy_user']){
params += stb.user['web_proxy_user']+':'+stb.user['web_proxy_pass']+'@';
}
params += stb.user['web_proxy_host']+':' +stb.user['web_proxy_port'];
}

stb.setFrontPanel('.');

if (!params && url.indexOf('?') == -1){
params += '?';
}else{
params += '&';
}

params = stb.add_referrer(params, this.module.layer_name);

_debug('url', url+params);

window.location = url+params;

}, {layer_name : "external_<?php 
echo $app['alias'];
?>"});

loader.next();
})();

