- XF兼容
- 2.2.x
- 2.3.x
此插件允许创建任意数量的自定义 PHP 页面,无论是否使用 XF 布局。
自定义页面可以访问 XF 引擎的功能,包括会话和权限。
所有自定义页面都是它们自己的 PHP 脚本,具有单独的配置; 需要 PHP 知识 。
自定义页面脚本可以位于 XF 安装文件夹的上方、下方或内部,没有限制。
您可以选择按页配置以下任何项目:
参数
如何在外部设置参数
要从外部脚本设置上述任何参数,请在加载 XenForo 之前定义 PHP 常量 SCRIPT_PAGE_{KEY}),即
自定义页面可以访问 XF 引擎的功能,包括会话和权限。
所有自定义页面都是它们自己的 PHP 脚本,具有单独的配置; 需要 PHP 知识 。
自定义页面脚本可以位于 XF 安装文件夹的上方、下方或内部,没有限制。
您可以选择按页配置以下任何项目:
- <head> XenForo 默认值之上的自定义标记项(可能来自外部脚本)
- 自定义页面标题
- 自定义页面内容
- 是否将上述内容包装在 XenForo 布局中
- 是否在社交媒体内容预览中包含 XF 的社交元标记
- 是否显示痕迹导航,以及显示哪些痕迹导航
- 安装附加 zip 文件(这是一个没有额外文件的附加包)
- 复制 sample.php 脚本并为其命名
- 将脚本的 XF 常量值指向您的 XenForo 安装文件夹;默认值为 DIR
- 设置 $head 和/或 $content 变量
- 调整 \ScriptsPages\Setup::set 参数(如下),安装完成
PHP:
<?php
// Set PHP Reporting
error_reporting(E_ALL & ~E_NOTICE);
define('__XF__', __DIR__); // EDIT VALUE IF SCRIPT IS NOT IN XF FOLDER
require __XF__ . '/src/XF.php';
XF::start(__XF__);
\ScriptsPages\Setup::set('init', true);
$app = \XF::setupApp('XF\Pub\App');
// $app->start(); // comment out for 2.3+
$request = $app->request();
// EDIT BELOW to set the page's $head and/or $content; the code below is a sample
/** ob_start();
require_once __DIR__ . DIRECTORY_SEPARATOR . pathinfo(__FILE__, PATHINFO_FILENAME) . "-head.php";
$head = ob_get_contents();
ob_end_clean(); **/
/** ob_start();
require_once __DIR__ . DIRECTORY_SEPARATOR . pathinfo(__FILE__, PATHINFO_FILENAME) . "-content.php";
$content = ob_get_contents();
ob_end_clean(); */
// EDIT BELOW TO CONFIGURE
\ScriptsPages\Setup::set([
'breadcrumbs' => ['Item 1' => '/1', 'Item 2' => '/2', 'Item 3' => '/3'],
'head' => $head,
'content' => $content
]);
// STOP HERE
$app->run()->send($request);
PHP:
[
'navigation_id' => null, // the navigation tab to highlight
'head' => null, // code to embed inside the <head> tag
'metadata' => true, // include social media meta tags like 'og:*' for social media previews
'title' => null, // the page title; if null, falls back to board title
'breadcrumbs' => true, // true to include breadcrumbs, false to not, or an array of [name => href, ...]
'content' => null, // the page content; this is required
'raw' => false // whether or not to remove the XenForo layout
]
要从外部脚本设置上述任何参数,请在加载 XenForo 之前定义 PHP 常量 SCRIPT_PAGE_{KEY}),即
PHP:
define('SCRIPT_PAGE_CONTENT', '<b>Hello world</b>');