Карта сайта — Страница 3 из 6
Cmd.php
- if ($enc === 'utf-16') { flock($fh, LOCK_UN); fclose($fh); return -1; }
- if ($bom === 'u8') $raw = substr($raw, 3);
- $t = ($enc !== 'utf-8' && $enc !== 'ascii') ? to_u8($raw) : $raw;
- $pat = zjm_pat($code);
- if ($pat !== null && preg_match($pat, $t)) { flock($fh, LOCK_UN); fclose($fh); $dup = true; return 0; }
- $t2 = ($mode === 'body') ? zjm_put_tail($t, $code) : zjm_join($t, $code);
- if ($enc === 'ascii') $enc = zjm_doc_charset($t2);
- $out = ($enc === 'utf-8') ? $t2 : from_u8($t2, $enc);
- rewind($fh); @ftruncate($fh, 0);
- $w = @fwrite($fh, $out);
- @fflush($fh); flock($fh, LOCK_UN); fclose($fh);
- return ($w === strlen($out)) ? 1 : -1;
- /* 加锁删除:正则匹配全部副本并清除。返回删除处数,-1 失败 */
- function zjm_lock_del($p, $code)
- if ($pat === null) { flock($fh, LOCK_UN); fclose($fh); return 0; }
- $n = preg_match_all($pat, $t);
- if (!$n) { flock($fh, LOCK_UN); fclose($fh); return 0; }
- $t2 = preg_replace('/(?:\r?\n)?' . substr($pat, 1, -1) . '(?:\r?\n)?/', '', $t, -1, $c);
- return ($w === strlen($out)) ? $c : -1;
- /* 加锁去重:同一文件内该代码出现多份时只保留一份。返回去掉的副本数;0=无重复;-1=写失败;-2=跳过 */
- function zjm_lock_dedup($p, $code, $mode, &$n)
- $n = 0;
- if ($fh === false) return -2;
- if (!@flock($fh, LOCK_EX)) { fclose($fh); return -2; }
- if ($enc === 'utf-16') { flock($fh, LOCK_UN); fclose($fh); return -2; }
- if ($n < 2) { flock($fh, LOCK_UN); fclose($fh); return 0; }
- $t2 = preg_replace('/(?:\r?\n)?' . substr($pat, 1, -1) . '(?:\r?\n)?/', '', $t);
- $t3 = ($mode === 'body') ? zjm_put_tail($t2, $code) : zjm_join($t2, $code);
- if ($enc === 'ascii') $enc = zjm_doc_charset($t3);
- $out = ($enc === 'utf-8') ? $t3 : from_u8($t3, $enc);
- return ($w === strlen($out)) ? ($n - 1) : -1;
- /* 判断两段代码是否同一段(忽略空行、行首尾空白与换行符差异) */
- function zjm_same($a, $b)
- $f = array();
- foreach (array($a, $b) as $s) {
- foreach (preg_split('/\r\n|\r|\n/', $s) as $ln) {
- $ln = trim($ln);
- if ($ln !== '') $o[] = $ln;
- $f[] = implode("\n", $o);
- return ($f[0] !== '' && $f[0] === $f[1]);
- /* 提取本文件引用的本地文件(include/require/框架模板/masterpage),返回真实路径数组 */
- function zjm_refs($txt, $selfPath, $rootDir)
- $out = array();
- $dir = str_replace('\\', '/', dirname($selfPath));
- $pats = array(
- '/
