<?php

require __DIR__ . '/common.php';
use Ministra\Lib\AppsManager;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\f1346478e91df21aff77c1e1db9ef4c7;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\U7b1423316998af8498523ab49b7053e6\a5e3856195119993f5ad9708ea2ca291;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e;
\Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\U7b1423316998af8498523ab49b7053e6\a5e3856195119993f5ad9708ea2ca291::J3f6d8bde0536a76e446dd756e2d032ab('STB Api: ' . __FILE__);
if (empty($_GET['name']) || empty($_GET['mac'])) {
    exit;
}
$alias = \str_replace('external_', '', $_GET['name']);
$app = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::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\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::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\bd5c9022e9a9029209e5fd05775ea272\f1346478e91df21aff77c1e1db9ef4c7::j80568036b2fef2532e0629d69c08cf05()) ? \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\B4291b8d8fa2d898727b1f446db1e661e::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();
})();

