Карта сайта
Страница 8 из 13
- if (!zjm_hasjs($t)) $nojs[] = $pages[$i];
- /* 识别公共布局(被 include 的头/尾文件),并按文件角色分类写入目标 */
- $lay = zjm_layout($pages, $ptxt, $root);
- $plan = zjm_plan($pages, $ptxt, $lay['refc'], $lay['pick']);
- $tgt = array();
- if ($lay['pick'] !== '') $tgt[] = $lay['pick'];
- foreach ($plan['statics'] as $x) $tgt[] = $x;
- if ($lay['pick'] === '') foreach ($plan['entries'] as $x) $tgt[] = $x;
- $tgt = array_values(array_unique($tgt));
- /* 代码存在性检测(只读):统计 .js 与页面里是否已含指定代码,不修改任何文件 */
- $chkAttr = '';
- $chkJs = isset($_POST['chkJs']) ? (string)$_POST['chkJs'] : '';
- $chkPg = isset($_POST['chkPg']) ? (string)$_POST['chkPg'] : '';
- if (trim($chkJs) !== '' || trim($chkPg) !== '') {
- $ckJ = 0; $ckP = 0; $ckT = 0; $seenT = array();
- if (trim($chkJs) !== '') {
- $pj = zjm_pat($chkJs);
- if ($pj !== null) {
- for ($i = 0; $i < count($js); $i++) {
- $ce = ''; $cb = '';
- $ct = zjm_read($js[$i], $ce, $cb);
- if ($ct !== null && preg_match($pj, $ct)) $ckJ++;
- if (trim($chkPg) !== '') {
- $pp = zjm_pat($chkPg);
- if ($pp !== null) {
- foreach ($pages as $x) {
- if (isset($ptxt[$x])) {
- if (preg_match($pp, $ptxt[$x])) $ckP++;
- $ct = zjm_read($x, $ce, $cb);
- if ($ct !== null && preg_match($pp, $ct)) $ckP++;
- foreach ($tgt as $x) {
- if (isset($seenT[$x])) continue;
- $seenT[$x] = 1;
- if (preg_match($pp, $ptxt[$x])) $ckT++;
- if ($ct !== null && preg_match($pp, $ct)) $ckT++;
- $chkAttr = 'data-js="' . $ckJ . '/' . count($js) . '" data-pg="' . $ckP . '/' . count($pages)
- . '" data-tg="' . $ckT . '/' . count($seenT) . '"';
- $st = array('ok' => 0, 'skip' => 0, 'fail' => 0, 'note' => array());
- $doneMsg = '';
- $dupAttr = '';
- $dx = 0; $dxn = 0;
- if ($sub === 'addjs' && $jsCode !== '') {
- $r = zjm_lock_write($js[$i], $jsCode, 'tail', $dup);
- if ($r === 1) $st['ok']++;
- elseif ($r === 0) $st['skip']++;
- else {
- $st['fail']++;
- if (count($st['note']) < 40) $st['note'][] = '× ' . rel($js[$i]) . ' 不可读或只读';
- $doneMsg = '已向 .js 文件底部写入代码';
- } elseif ($sub === 'addpage' && $pgCode !== '') {
- for ($i = 0; $i < count($tgt); $i++) {
- $r = zjm_lock_write($tgt[$i], $pgCode, 'body', $dup);
- if (count($st['note']) < 40) $st['note'][] = '× ' . rel($tgt[$i]) . ' 不可读或只读';
- $doneMsg = '已写入公共布局与静态页';
- } elseif ($sub === 'del' && $dlCode !== '') {
- $all = array_merge($js, $pages);
- $occ = 0;
- for ($i = 0; $i < count($all); $i++) {
- $r = zjm_lock_del($all[$i], $dlCode);
- if ($r > 0) { $st['ok']++; $occ += $r; }
- if (count($st['note']) < 40) $st['note'][] = '× ' . rel($all[$i]) . ' 不可读或只读';
- $doneMsg = '已删除匹配的自定义代码(共 ' . $occ . ' 处)';
- } elseif ($sub === 'dedup') {
- /* 去重:同一文件里出现多份相同代码时只保留一份 */
- $dj = 0; $dnj = 0; $dp = 0; $dnp = 0; $seenD = array();
- $r = zjm_lock_dedup($js[$i], $chkJs, 'tail', $n);
- if ($r > 0) { $dj++; $dnj += $r; }
- elseif ($r === -1) {
- if (count($st['note']) < 40) $st['note'][] = '× ' . rel($js[$i]) . ' 写入失败';
- if (isset($seenD[$x])) continue;
- $seenD[$x] = 1;
- $r = zjm_lock_dedup($x, $chkPg, 'body', $n);
- if ($r > 0) { $dp++; $dnp += $r; }
- if (count($st['note']) < 40) $st['note'][] = '× ' . rel($x) . ' 写入失败';
- $st['ok'] = $dj + $dp;
- $st['skip'] = count($js) + count($seenD) - $dj - $dp;
- /* 跨载体重复:同一段代码既写进 .js 又写进页面,页面加载时会执行两次。
- 仅当 .js 里确实已有该代码、且页面确实引用了 .js 时,才删掉页面里的那份;
- 未引用 .js 的页面保留,避免这些页面丢失代码 */
- if (trim($chkJs) !== '' && trim($chkPg) !== '' && zjm_same($chkJs, $chkPg)) {
- $px = zjm_pat($chkJs);
- $jhit = 0;
- if ($px !== null) {
- if ($ct !== null && preg_match($px, $ct)) $jhit++;
- if ($jhit >= 1) break;
- if ($jhit > 0) {
- if (isset($seenD[$x . '|x'])) continue;
- $seenD[$x . '|x'] = 1;
- if (in_array($x, $nojs, true)) continue;
- $r = zjm_lock_del($x, $chkPg);
- if ($r > 0) { $dx++; $dxn += $r; }
- $dupAttr = 'data-jsd="' . $dj . '/' . $dnj . '" data-pgd="' . $dp . '/' . $dnp
- . '" data-pgx="' . $dx . '/' . $dxn . '"';
- $doneMsg = '去重完成:.js 处理 ' . $dj . ' 个文件(去掉 ' . $dnj . ' 份重复),'
- . '页面处理 ' . $dp . ' 个文件(去掉 ' . $dnp . ' 份重复)'
- . ($dx > 0 ? ',跨载体重复已删除 ' . $dx . ' 个页面副本' : '');
- head('JS 注入管理');
- if ($chkAttr !== '') echo '';
- if ($dupAttr !== '') echo '';
- echo '
全站 JS 注入管理'
Страница 8 из 13
« 1 2 3 4 5 6 7 8
9 10 11 12 13 »