get($key, $default); return is_scalar($value) || null === $value ? (string) $value : $default; }; $nqInt = function ($key, $default = 0) use ($request) { $value = $request->get($key, $default); return is_scalar($value) ? (int) $value : $default; }; /* ------------------------------------------------------------------ * 权限:仅管理员 * ------------------------------------------------------------------ */ $nqIsAdmin = false; try { if (isset($user) && is_object($user)) { $nqIsAdmin = (bool) $user->pass('administrator', true); } } catch (\Throwable $e) { $nqIsAdmin = false; } $nqToken = ''; if ($nqIsAdmin) { $nqToken = md5((string) $options->secret . '|' . (string) $user->authCode . '|' . (int) $user->uid); } $nqPanel = Plugin::panelUrl(); $nqVer = Plugin::options()['version']; /* ------------------------------------------------------------------ * 动作处理(POST → 302) * ------------------------------------------------------------------ */ $nqDo = $nqGet('do'); if ('' !== $nqDo && 'POST' === strtoupper((string) $request->getServer('REQUEST_METHOD'))) { $nqBack = array_filter([ 'kind' => $nqGet('kind'), 'q' => $nqGet('q'), 'missing' => $nqGet('missing'), 'page' => $nqGet('page'), ], function ($value) { return '' !== $value; }); if (!$nqIsAdmin || '' === $nqToken || !hash_equals($nqToken, $nqGet('_nq'))) { $nqBack['_nq'] = 'denied'; $response->redirect(Plugin::panelUrl($nqBack)); exit; } $nqNotice = ''; if ('delete' === $nqDo) { $nqCid = $nqInt('cid'); $nqOffset = $nqInt('offset', -1); $nqRaw = $nqGet('raw'); $nqResult = Scanner::edit($nqCid, [['offset' => $nqOffset, 'raw' => $nqRaw, 'to' => null]]); $nqNotice = $nqResult['ok'] ? 'deleted' : 'failed'; } elseif ('clean' === $nqDo) { // 清理全部失效引用:按文章分组,逐篇从后往前删 $nqAll = Scanner::resolve(Scanner::rows()); $nqGroup = []; foreach ($nqAll as $nqRow) { if (!$nqRow['ref_exists']) { $nqGroup[$nqRow['cid']][] = [ 'offset' => $nqRow['offset'], 'raw' => $nqRow['raw'], 'to' => null, ]; } } $nqChanged = 0; foreach ($nqGroup as $nqCid => $nqEdits) { $nqResult = Scanner::edit((int) $nqCid, $nqEdits); $nqChanged += $nqResult['changed']; } $nqBack['_n'] = $nqChanged; $nqNotice = $nqChanged > 0 ? 'cleaned' : 'nothing'; } else { $nqNotice = 'failed'; } $nqBack['_nq'] = $nqNotice; $response->redirect(Plugin::panelUrl($nqBack)); exit; } /* ------------------------------------------------------------------ * 读数据 * ------------------------------------------------------------------ */ $nqAll = $nqIsAdmin ? Scanner::resolve(Scanner::rows()) : []; $nqStats = Scanner::stats($nqAll); $nqKind = strtolower($nqGet('kind')); $nqKind = isset(Scanner::LABEL[$nqKind]) ? $nqKind : ''; $nqMissingOnly = '1' === $nqGet('missing'); $nqKeyword = trim($nqGet('q')); $nqLower = function_exists('mb_strtolower') ? mb_strtolower($nqKeyword) : strtolower($nqKeyword); $nqRows = array_values(array_filter($nqAll, function (array $row) use ($nqKind, $nqMissingOnly, $nqLower) { if ('' !== $nqKind && $row['type'] !== $nqKind && $row['ref_kind'] !== $nqKind) { return false; } if ($nqMissingOnly && $row['ref_exists']) { return false; } if ('' !== $nqLower) { $haystack = $row['host'] . ' ' . $row['ref_title'] . ' ' . $row['raw'] . ' ' . $row['author']; $haystack = function_exists('mb_strtolower') ? mb_strtolower($haystack) : strtolower($haystack); if (false === strpos($haystack, $nqLower)) { return false; } } return true; })); $nqPer = (int) Plugin::options()['per']; $nqTotal = count($nqRows); $nqPages = max(1, (int) ceil($nqTotal / $nqPer)); $nqPage = min($nqPages, max(1, $nqInt('page', 1))); $nqSlice = array_slice($nqRows, ($nqPage - 1) * $nqPer, $nqPer); // 只有当前页需要前台链接,别为全站引用逐个取 $nqSlice = Scanner::links($nqSlice); $nqAdminUrl = rtrim((string) $options->adminUrl, '/') . '/'; $nqPlaceholder = function (array $extra = []) use ($nqPanel, $nqH) { return $nqH($nqPanel . '&' . http_build_query($extra)); }; $nqQuery = array_filter([ 'kind' => $nqKind, 'q' => $nqKeyword, 'missing' => $nqMissingOnly ? '1' : '', ], function ($value) { return '' !== $value; }); /* 操作结果提示 */ $nqFlash = $nqGet('_nq'); $nqFlashMap = [ 'deleted' => ['ok', '引用已删除,正文已同步清理'], 'cleaned' => ['ok', '已清理 ' . (int) $nqInt('_n') . ' 条失效引用'], 'nothing' => ['warn', '没有可清理的失效引用'], 'failed' => ['err', '操作失败,可能是正文已被修改,请刷新后重试'], 'denied' => ['err', '安全校验未通过,请重新操作'], ]; include 'header.php'; include 'menu.php'; ?> 引用管理 只有管理员可以查看引用管理。 引用总数 共 篇内容在用 被引用对象 去重后的内容数 失效引用 0): ?> 只看失效 全部有效 0): ?> 类型分布 $nqCount): ?> 0 ? round($nqCount / $nqStats['total'] * 100) : 0; ?> 被引用最多 暂无数据 次 引用明细 0): ?> 共 条 暂无记录 全部类型 > 全部状态 >只看失效 筛选 重置 0): ?> $nqValue): ?> 清理失效引用() 0 ? '没有符合筛选条件的引用' : '还没有任何引用,去文章里插一个试试'; ?> 序号 引用位置 被引用内容 状态 操作 $nqRow): ?> · format('Y-m-d H:i')); ?> · 未发布 · 第 处 → 正常 失效 修改 $nqValue): ?> 删除 1): ?> 共 条 · 第 / 页 1): ?> « 1): ?> 1 2): ?> ... > ... »
暂无数据
0 ? '没有符合筛选条件的引用' : '还没有任何引用,去文章里插一个试试'; ?>