<?php
$image   = isset($_GET['img'])?$_GET['img']:'0';
$title   = isset($_GET['title'])?$_GET['title']:'Crazy Coin';
$content = isset($_GET['content'])?$_GET['content']:'Crazy Coin is the most exciting and fun social game in the world';
$imageName = $image;
$image   = explode('-',$image);
if(in_array($image[0],['DEFAULT', 'DE', 'FR', 'US', 'GB', 'ES', 'TH', 'BR'])){
    if(file_exists("../img/feed/{$image[0]}/{$imageName}.jpg")){
        $imageUrl= 'https://god.superant.cc/img/feed/'.$image[0].'/'.$imageName.'.jpg';;
    }else{
        $imageUrl= 'https://god.superant.cc/img/feed/DEFAULT/DEFAULT-'.$image[1].'.jpg';
    }
}else{
    $imageUrl= 'https://god.superant.cc/img/feed/'.$imageName.'.jpg';
}

$baseUrl = "https://crazycoin.superant.cc/m/share.php";
$url = $baseUrl.'?img='.$imageName.'&title='.$title.'&content='.$content.'&time='.time();
$url = str_replace(' ','+',$url);



$iosLink     = makeIosLink();
$androidLink = makeAndroidLink();
$sign        = getLinkData();

function makeAndroidLink(){
    $baseLink = "https://app.adjust.com/3mhjw1l?";
    $param    = [
        'deeplink'         => "superant%3A%2F%2Fcrazygod",
        'redirect_android' => "https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dcom.superant.crazygod",
        'redirect_ios'     => "https%3A%2F%2Fitunes.apple.com%2Fapp%2Fid1505268807"
    ];
    $sign = getLinkData();
    if(!empty($sign)){
        $param['deeplink'] = urlencode('superant://crazygod?'.$sign);
    }
    $tmp = [];
    foreach ($param as $key=>$value){
        $tmp[] = "{$key}={$value}";
    }
    return $baseLink.implode("&",$tmp);
}

function makeIosLink(){
    $url  = "crazycoin://";
    $sign = getLinkData();
    if(!empty($sign)){
        $url = 'crazycoin://?'.$sign;
    }
    return $url;


    $baseLink = "https://hkjt.adj.st/?";
    $param    = [
        'adjust_t'         => "3mhjw1l",
        'adjust_deeplink'  => "crazycoin%3A%2F%2Fpromotions",
    ];
    $sign = getLinkData();
    if(!empty($sign)){
        $param['adjust_deeplink'] = urlencode('crazycoin://?'.$sign);
    }
    $tmp = [];
    foreach ($param as $key=>$value){
        $tmp[] = "{$key}={$value}";
    }
    return $baseLink.implode("&",$tmp);
}

function getLinkData(){
    if(isset($_GET['linkData'])){
        $str = $_GET['linkData'];
        $sign = substr($str,0,1).substr($str,2,strlen($str));
        $sign = substr($sign,0,floor((strlen($sign)-16)/2)-1).substr($sign,floor((strlen($sign)-16)/2)+15,strlen($sign));
        $sign = base64_decode($sign);
        $sign = trim($sign,'&');
        return $sign;
    }
    return "";
}

function isAndroid(){
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
        return false;
    }
    return true;
}
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=0.66"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="Keywords" content="coin,coinmaster,coins,crazygod,crazycoin" />
    <meta name="description" content="<?php echo $content;?>" />

    <meta property="og:url"  content="<?php echo $url;?>" />
    <meta property="og:type" content="game" />
    <meta property="og:title" content="<?php echo $title;?>" />
    <meta property="og:image" content="<?php echo $imageUrl;?>" />
    <meta property="og:description" content="<?php echo $content;?>" />

    <meta property="fb:app_id" content="2017964004965884" />
    <meta property="al:ios:url"          content="crazycoin://" />
    <meta property="al:ios:app_store_id" content="1505268807" />
    <meta property="al:ios:app_name"     content="Crazy Coin" />

    <meta property="al:android:url" content="superant://crazygod" />
    <meta property="al:android:package" content="com.superant.crazygod" />
    <meta property="al:android:app_name" content="Crazy Coin" />
    <title>Crazy Coin</title>
    <style>
        /* CSS Document */
        .menu {
            margin:0 auto;
            border:1pt solid #999999;
            border-radius:5px;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
        }
        .menu a {
            text-decoration:none;
            height:100%;
            display:block;
            border-radius:5px;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px; color:#333;
        }
        .menu a:visited {
            text-decoration:none;
            color:#000000;
        }
        .menu a:active {
            text-decoration:none;
        }
        .link-web{
            width:210px;
            height:40px;
            margin:0 auto;
            border-radius:4px;
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            /*text-shadow:0 2px 0 #FFF;*/
            font-family: "", "";
            font-size:18px;
        }
        .link-web a{
            text-decoration:none;
            width:210px;
            height:40px;
            display:block;
            border-radius:4px;
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            background-color: #F5F5F5;
            border:1px dashed #cccccc;
            color:#333;
        }
        .link-web a:visited{
            text-decoration:none;
            color:#333;
        }
        .link-web a:active{
            text-decoration:none;
            color:#333;
        }
        .font-arial{
            font-family: "微软雅黑", "", Arial, "Arial Black";
        }
        .font-italic{
            font-style:italic;
        }
        .font-blod{
            font-weight:bold;
        }
        .font-app{
            text-align:left;
            font-size:25px;
            color: #666666;
        }
        .font-app-display{
            text-align:left;
            font-size:20px;
            color:#999999;
            text-shadow:0 2px 0 #FFF;
        }
        .font02{
            font-size:18px; color:#999999;
            text-align:left;
        }
        .dp_copy{
            margin-top:10px;
            text-align:center;
            color:#919090;
            font-size:22px;
        }
    </style>

</head>
<body style="margin:0; padding:0; background:#EFEFEF;text-align:center" onload="onLoad()">
<div id="page-android" style="width:400px; height:800px; margin:0 auto; display:;">
    <div style="display: none">
        <img src="/img/icon152.png"/>
    </div>

    <div style="padding:50px 0 0px 0">
        <img src="/img/r1.png"/>
    </div>
    <div style="padding:50px 0 0px 0">
        <a href="<?php echo isAndroid() ? $androidLink : $iosLink;?>">
            <img src="/img/icon152.png" alt="Crazy Coin"  /> </a>
    </div>
    <div class="font-arial" style="font-size:32px; line-height:34px; height:45px; text-shadow:0 2px 0 #FFF; color:#999999; text-shadow: white 2px 2px; font-weight: bold; letter-spacing:2px;">Crazy Coin</div>
    <p class="dp_copy">The most exciting and fun social game in the world</p>
    <br/>
    <div class="font-arial" style=" width:400px; font-size:20px; line-height:30px; height:50px; color:#999999; letter-spacing:2px; text-align:left; margin: 0 auto;">Choose the version available :</div>
    <br/>
    <div  style="width:400px; height:100px;">
        <a href="itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1505268807" target="Crazy Coin">
            <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" height="100px">
                <tr>
                    <td width="100" align="center" valign="middle" >
                        <img src="/img/ios.jpg" alt="" border="0"  />
                    </td>
                </tr>
            </table>
        </a>
    </div>
    <div style="height:60px;"></div>
    <div style="width:400px; height:100px;">
        <a href="market://details?id=com.superant.crazygod">
            <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" height="100px">
                <tr>
                    <td width="100" align="center" valign="middle">
                        <img src="/img/android.jpg" alt="" border="0" />
                    </td>
                </tr>
            </table>
        </a>
    </div>
    <br/>
    <br/>
    <br/>
    <br/>
    <a id="copy" style="height:20px; font-size:22px;font-family: 微软雅黑; text-shadow:0 2px 0 #FFF; text-align:center; margin:0px" href="https://fb.me/crazycoin.global">Fans Page</a>
    <br/>
    <br/>
    <br/>
    <div id="copy" style="height:18px; color:#999999; font-size:15px;font-family: 微软雅黑; text-shadow:0 2px 0 #FFF; text-align:center; margin:0px">Copyright © 2019 SuperAnt Technology Co., Ltd..All Rights Reserved.</div>
    <script type="text/javascript">document.write(unescape("%3Cspan id='cnzz_stat_icon_1279082262'%3E%3C/span%3E%3Cscript src='https://v1.cnzz.com/z_stat.php%3Fid%3D1279082262%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script>
</div>

<script>
    var timeOutId = 0;
    // IOS
    var IOS ="<?php echo $iosLink;?>";
    var ITUNES = "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1505268807";

    // Android
    var ANDROID = "<?php echo $androidLink;?>";
    var MARKET = "market://details?id=com.superant.crazygod";

    // PC
    var PCURL  = "https://fb.me/crazycoin.global";

    function onLoad() {
        if (navigator.userAgent.match(/Android/)) {
            var iframe = document.createElement("iframe");
            iframe.style.visibility = 'hidden';
            iframe.style.border = "none";
            iframe.style.width = "1px";
            iframe.style.height = "1px";
            iframe.src = ANDROID;
            iframe.onload = function () { window.location = MARKET; };
            document.body.appendChild(iframe);
        }
        else if (navigator.userAgent.match(/(iPhone|iPad|iPod)/i)) {
            // IOS
            window.location = IOS;
            timeOutId = setTimeout(function() {
                window.location = ITUNES;
            }, 2000);
        } else {
            window.location.href = PCURL;
        }
    }
    window.onbeforeunload=function(){
        clearTimeout(timeOutId);
    }
</script>

<!--点击次数-->
<?php if(isset($_GET['linkData'])){ ?>
    <script src="/public/js/vendor/jquery.min.js"></script>
    <script>
        //var linkType = getQueryVariable("linkType");
        //if(linkType == "attackDefense" || linkType == "attackDamaged" || linkType == "raidGood" || linkType == "raidPerfect" || linkType == "askforCard" || linkType == "passLevel"){
        if(is_str("attackDefense") || is_str("attackDamaged") || is_str("raidGood") || is_str("raidPerfect") || is_str("askforCard") || is_str("passLevel")){
            $.ajax({
                type: "POST",
                url: "https://god.superant.vip/api/gateway.php",
                data: "<?php echo $sign; ?>&sid=1&lid=1&act=clickNumber&mod=Share",
                dataType: 'json',
                success: function (returnData) {

                },
                error: function () {

                }
            });
        }

        function getQueryVariable(variable)
        {
            var query = "<?echo $iosLink;?>";
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }

        function is_str(str){
            var query = "<?echo $iosLink;?>";
            if(query.indexOf(str)){
                return true;
            }else{
                return false;
            }
        }
    </script>
<? } ?>

</body>
</html>
