Files
NiceQuote/post.php

67 lines
2.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* iframe 独立渲染页
*
* 由 Plugin::route() 校验参数后 include,也可单独访问:
* /index.php?NiceQuote=post&qid=1
* /index.php?NiceQuote=url&qurl=https%3A%2F%2Fexample.com%2Fpost
*
* @package NiceQuote
*/
if (!defined('__TYPECHO_ROOT_DIR__')) {
exit;
}
require_once __DIR__ . '/Renderer.php';
$nqOptions = \TypechoPlugin\NiceQuote\Plugin::options();
$nqType = isset($nqType) ? (string) $nqType : strtolower((string) \Typecho\Request::getInstance()->get('NiceQuote'));
$nqId = isset($nqId) ? (int) $nqId : (int) \Typecho\Request::getInstance()->get('qid');
$nqUrl = isset($nqUrl) ? (string) $nqUrl : (string) \Typecho\Request::getInstance()->get('qurl');
$nqHtml = \TypechoPlugin\NiceQuote\Renderer::render($nqType, $nqId, $nqOptions, $nqUrl);
$nqCss = $nqOptions['pluginUrl'] . '/assets/card.css?v=' . $nqOptions['version'];
$nqTitle = \TypechoPlugin\NiceQuote\Renderer::plain($nqType, $nqId, $nqUrl);
$nqTitle = null === $nqTitle ? 'NiceQuote' : strip_tags($nqTitle);
?>
<!DOCTYPE html>
<html lang="zh-CN" style="--nq-accent:<?php echo $nqOptions['accent']; ?>;--nq-radius:<?php echo $nqOptions['radius']; ?>px">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title><?php echo htmlspecialchars($nqTitle, ENT_QUOTES, 'UTF-8'); ?></title>
<link rel="stylesheet" href="<?php echo htmlspecialchars($nqCss, ENT_QUOTES, 'UTF-8'); ?>">
</head>
<body class="nq-standalone" data-skin="<?php echo $nqOptions['skin']; ?>">
<?php echo $nqHtml; ?>
<script>
(function () {
if (window.parent === window) {
return;
}
var body = document.body;
function send() {
var height = Math.ceil(body.getBoundingClientRect().height);
window.parent.postMessage({ nqHeight: height }, '*');
}
window.addEventListener('load', send);
window.addEventListener('resize', send);
if (window.ResizeObserver) {
new ResizeObserver(send).observe(body);
}
send();
})();
</script>
</body>
</html>