Exemple #1
0
        function go($tmpl, $pass = 1)
        {
            $raw = Koken::parse($tmpl);
            // Fix PHP whitespace issues in koken:loops
            $raw = preg_replace('/\\s+<\\?php\\s+endforeach/', '<?php endforeach', $raw);
            $raw = preg_replace('/<a(.*)>\\s+<\\?php/', '<a$1><?php', $raw);
            $raw = preg_replace('/\\?>\\s+<\\/a>/', '?></a>', $raw);
            if ($pass === 1) {
                global $final_path;
                $is_lightbox = 'false';
                if ($final_path === 'lightbox.lens') {
                    $is_lightbox = 'true';
                }
                // Filters
                $raw = str_replace('<head>', "<head><?php Shutter::hook('after_opening_head', array(array('lightbox' => {$is_lightbox}))); ?>", $raw);
                $raw = str_replace('</head>', "<?php Shutter::hook('before_closing_head', array(array('lightbox' => {$is_lightbox}))); ?></head>", $raw);
                $raw = str_replace('<body>', "<body><?php Shutter::hook('after_opening_body', array(array('lightbox' => {$is_lightbox}))); ?>", $raw);
                $raw = str_replace('</body>', "<?php Shutter::hook('before_closing_body', array(array('lightbox' => {$is_lightbox}))); ?></body>", $raw);
                // die($raw);
                Koken::$location['page_class'] = Koken::$page_class;
                $dynamic_array = array();
                foreach (Koken::$dynamic_location_parts as $key) {
                    $dynamic_array[$key] = Koken::$location[$key];
                }
                unset($dynamic_array['parameters']['__overrides']);
                unset($dynamic_array['parameters']['__overrides_display']);
                $location_json = json_encode($dynamic_array);
                if (Koken::$pjax) {
                    $js = "<script>\$K.location = \$.extend(\$K.location, {$location_json});\$(window).trigger('k-pjax-end');</script>";
                } else {
                    $location = Koken::$location;
                    $site = Koken::$site;
                    $stamp = '?' . KOKEN_VERSION;
                    $generator = 'Koken ' . KOKEN_VERSION;
                    $theme = Koken::$site['theme']['name'] . ' ' . Koken::$site['theme']['version'];
                    $koken_js = Koken::$location['root_folder'] . '/' . (Koken::$draft ? 'preview.php?/' : (Koken::$rewrite ? '' : 'index.php?/')) . 'koken.js' . (Koken::$preview ? '&preview=' . Koken::$preview : '');
                    if (strpos($koken_js, '.php?') === false) {
                        $koken_js .= '?' . Shutter::get_site_scripts_timestamp();
                    }
                    if (Koken::$has_video) {
                        $me = "\n\n\t<link href=\"{$location['real_root_folder']}/app/site/themes/common/css/mediaelement/mediaelementplayer.min.css{$stamp}\" rel=\"stylesheet\">\n";
                    } else {
                        $me = '';
                    }
                    $js = <<<JS
\t<meta name="generator" content="{$generator}" />
\t<meta name="theme" content="{$theme}" />{$me}

\t<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
\t<script>window.jQuery || document.write('<script src="{$location['real_root_folder']}/app/site/themes/common/js/jquery.min.js"><\\/script>')</script>
\t<script src="{$koken_js}"></script>
\t<script>\$K.location = \$.extend(\$K.location, {$location_json});</script>

\t<link rel="alternate" type="application/atom+xml" title="{$site['title']}: All uploads" href="{$location['root']}/feed/content/recent.rss" />
\t<link rel="alternate" type="application/atom+xml" title="{$site['title']}: Essays" href="{$location['root']}/feed/essays/recent.rss" />
\t<link rel="alternate" type="application/atom+xml" title="{$site['title']}: Timeline" href="{$location['root']}/feed/timeline/recent.rss" />
JS;
                }
                if (Koken::$draft && !Koken::$preview && !Koken::$pjax) {
                    $original_url = Koken::$original_url;
                    $js .= <<<JS
<script>

if (parent && parent.\$) {
\tparent.\$(parent.document).trigger('previewready', '{$original_url}');
\t\$(function() { parent.\$(parent.document).trigger('previewdomready'); });

\t\$(document).on('pjax:end pjax:transition:end', function(event) {
\t\tif (event.type === 'pjax:end') {
\t\t\tparent.\$(parent.document).trigger('previewready', location.href);
\t\t}
\t\tparent.\$(parent.document).trigger('previewdomready');
\t});

\t\$(document).on('page:change.console', function() {
\t\tparent.\$(parent.document).trigger('previewready', location.href);
\t\tparent.\$(parent.document).trigger('previewdomready');
\t});
}
if (parent && parent.__koken__) {
\t\$(window).on('keydown', function(e) { parent.__koken__.shortcuts(e); });
\t\$(function() { parent.__koken__.panel(); });
}
</script>

<style type="text/css">
i.k-control-structure { font-style: normal !important; }

\tdiv[data-pulse-group] div.cover {
\t\twidth: 100%;
\t\theight: 100%;
\t\tz-index: 1000;
\t\tborder: 5px solid transparent;
\t\tbox-sizing: border-box;
\t\tposition: absolute;
\t\tbox-shadow: 0 0 20px rgba(0,0,0,0.6);
\t\tdisplay: none;
\t\tpointer-events:none;
\t\ttop: 0;
\t\tleft: 0;
\t}

\tdiv[data-pulse-group]:hover div.cover, div[data-pulse-group] div.cover.active {
\t\tdisplay: block !important;
\t}

\tdiv[data-pulse-group] div.cover.active {
\t\tborder-color: #ff6e00 !important;
\t}

\tdiv[data-pulse-group] div.cover div {
\t\tpointer-events:auto;
\t\twidth: 10%;
\t\theight: 10%;
\t\tmin-width: 28px;
\t\tmin-height: 28px;
\t\tbackground-size: 28px 28px;
\t\tbackground-position:top right;
\t\tbackground-repeat:no-repeat;
\t\tbackground-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxOC4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAyOCAyOCIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMjggMjgiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPGcgaWQ9IkxheWVyXzIiPg0KCTxjaXJjbGUgZmlsbD0iIzFFMUUxRSIgY3g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Nw0KCQkJQzE0LjUsMjAuNSwxNC4zLDIwLjUsMTQsMjAuNXogTTE0LDExLjZjLTEuMywwLTIuNCwxLjEtMi40LDIuNGMwLDEuMywxLjEsMi40LDIuNCwyLjRjMS4zLDAsMi40LTEuMSwyLjQtMi40DQoJCQlDMTYuNCwxMi43LDE1LjMsMTEuNiwxNCwxMS42eiIvPg0KCTwvZz4NCjwvZz4NCjwvc3ZnPg0K);\t\tposition: absolute;
\t\ttop: 4px;
\t\tright: 4px;
\t\tcursor: pointer;
\t\tz-index: 1001;
\t}

\tdiv[data-pulse-group] div.cover div:hover {
\t\tbackground-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxOC4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCAyOCAyOCIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMjggMjgiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPGcgaWQ9IkxheWVyXzIiPg0KCTxjaXJjbGUgZmlsbD0iIzFFMUUxRSIgY3g9IjE0IiBjeT0iMTQiIHI9IjE0Ii8+DQo8L2c+DQo8ZyBpZD0iTGF5ZXJfMSI+DQoJPGcgaWQ9ImNvZ18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NGMwLDEuMywxLjEsMi40LDIuNCwyLjRjMS4zLDAsMi40LTEuMSwyLjQtMi40DQoJCQlDMTYuNCwxMi43LDE1LjMsMTEuNiwxNCwxMS42eiIvPg0KCTwvZz4NCjwvZz4NCjwvc3ZnPg0K);
\t}
</style>
JS;
                }
            }
            $contents = Koken::render($raw);
            if ($pass === 1) {
                // Rerun parse to catch shortcode renders
                while (strpos($contents, '<koken:') !== false && $pass < 3) {
                    $pass++;
                    $contents = go($contents, $pass);
                }
            } else {
                return $contents;
            }
            $contents .= Koken::cleanup();
            if (strpos($contents, 'settings.css.lens"') === false && !empty(Koken::$site['custom_css']) || Koken::$draft) {
                $js .= '<style id="koken_custom_css">' . Koken::$site['custom_css'] . '</style>';
            }
            preg_match_all('/<\\!\\-\\- KOKEN HEAD BEGIN \\-\\->(.*)<!\\-\\- KOKEN HEAD END \\-\\->/msU', $contents, $headers);
            $contents = preg_replace('/<\\!\\-\\- KOKEN HEAD BEGIN \\-\\->(.*)<!\\-\\- KOKEN HEAD END \\-\\->/msU', '', $contents);
            $header_str = '';
            foreach ($headers[1] as $header) {
                $header_str .= "\t" . $header . "\n";
            }
            if (strpos($header_str, '<title>') !== false) {
                $contents = preg_replace('/<title>.*<\\/title>/msU', '', $contents);
                $header_str = preg_replace('/<koken_title>.*<\\/koken_title>/', '', $header_str);
            } else {
                if (strpos($header_str, '<koken_title>') !== false && strpos($contents, '<koken_title') !== false) {
                    $contents = preg_replace('/<title>.*<\\/title>/msU', '', $contents);
                    $header_str = str_replace('koken_title', 'title', $header_str);
                } else {
                    if (strpos($contents, '<koken_title') !== false) {
                        $contents = str_replace('koken_title', 'title', $contents);
                    }
                }
            }
            if (Koken::$pjax && strpos($header_str, '<title>')) {
                preg_match('~<title>.*</title>~', $header_str, $title_match);
                $contents .= $title_match[0];
            }
            $contents = preg_replace('/<koken_title>.*<\\/koken_title>/msU', '', $contents);
            $header_str .= "\n\t<!--[if IE]>\n\t<script src=\"" . Koken::$location['real_root_folder'] . "/app/site/themes/common/js/html5shiv.js\"></script>\n\t<![endif]-->\n";
            if (strpos($contents, '<head>')) {
                preg_match('/<head>(.*)?<\\/head>/msU', $contents, $header);
                if (count($header)) {
                    $head = isset($header[1]) ? $header[1] : '';
                    preg_match_all('/<script.*<\\/script>/msU', $head, $head_js);
                    $head = preg_replace('/\\s*<script.*<\\/script>\\s*/msU', '', $head) . "\n{$header_str}\n{$js}\n" . join("\n", $head_js[0]);
                    $contents = preg_replace('/<head>(.*)?<\\/head>/msU', "<head>\n" . str_replace('$', '\\$', $head) . "\n</head>", $contents);
                }
            } else {
                if (strpos($contents, '</body>')) {
                    $contents = str_replace('</body>', "{$js}\n{$header_str}\n</body>", $contents);
                } else {
                    if (Koken::$pjax) {
                        $contents .= $js;
                    }
                }
            }
            $final_page_classes = trim(join(' ', array_merge(explode(' ', Koken::$page_class), Shutter::get_body_classes())));
            if (preg_match_all('/<body(?:[^>]+)?>/', $contents, $match) && !empty($final_page_classes)) {
                foreach ($match[0] as $body) {
                    if (strpos($body, 'class="') !== false) {
                        $new_body = preg_replace('/class="([^"]+)"/', "class=\"\$1 " . $final_page_classes . "\"", $body);
                    } else {
                        $new_body = str_replace('>', ' class="' . $final_page_classes . '">', $body);
                    }
                    $contents = str_replace($body, $new_body, $contents);
                }
            }
            if (preg_match_all('/<html(?:[^>]+)?>/', $contents, $match) && !empty($final_page_classes)) {
                foreach ($match[0] as $html) {
                    if (strpos($html, 'class="') !== false) {
                        $new_html = preg_replace('/class="([^"]+)"/', "class=\"\$1 " . $final_page_classes . "\"", $html);
                    } else {
                        $new_html = str_replace('>', ' class="' . $final_page_classes . '">', $html);
                    }
                    $contents = str_replace($html, $new_html, $contents);
                }
            }
            preg_match('/<!-- KOKEN META DESCRIPTION BEGIN -->(.*)<!-- KOKEN META DESCRIPTION END -->/msU', $contents, $meta_description);
            preg_match('/<!-- KOKEN META KEYWORDS BEGIN -->(.*)<!-- KOKEN META KEYWORDS END -->/msU', $contents, $meta_keywords);
            $contents = preg_replace('/<!-- KOKEN META (DESCRIPTION|KEYWORDS) BEGIN -->.*<!-- KOKEN META (DESCRIPTION|KEYWORDS) END -->/msU', '', $contents);
            $contents = preg_replace('/\\t+/', "\t", $contents);
            $contents = preg_replace('/\\n\\t*\\n/', "\n", $contents);
            $contents = preg_replace('/\\n{2,}/', "\n\n", $contents);
            $contents = preg_replace('/<title>\\s*/ms', '<title>', $contents);
            if (count($meta_description) && strlen($meta_description[1]) > 0) {
                $contents = preg_replace('/<meta name="description" content=".*" \\/>/', '<meta name="description" content="' . str_replace('$', '\\$', $meta_description[1]) . '" />', $contents);
            }
            if (count($meta_keywords) && strlen($meta_keywords[1]) > 0) {
                $contents = preg_replace('/<meta name="keywords" content="(.*)" \\/>/', "<meta name=\"keywords\" content=\"\$1, {$meta_keywords[1]}\" />", $contents);
            }
            if (Koken::$rss) {
                $contents = '<?xml version="1.0" encoding="utf-8"?>' . "\n{$contents}";
            } else {
                $contents = Shutter::filter('site.output', $contents);
            }
            Koken::cache($contents);
            if (Koken::$rss) {
                header('Content-type: text/xml; charset=UTF-8');
            } else {
                header('Content-type: text/html; charset=UTF-8');
            }
            die($contents);
        }