Запись [f:_dev/util/sar.php] < dev.sky.1.001
Версия 1.001
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | <?php defined('START') and AUTH_OK or die; eval(get()); $hist = $hist ? unserialize($hist) : []; define('ERR', '<div id="no-records">%s<div>'); if (START == 'ajax'): switch (PAGE): case 'ini': $area = @area($syn); list($dir_list, $skip, $nused, $files2) = filter_path($area->inc_p, $area->exc_p); $i = array_search($s = $_POST['s'], $hist); if (false !== $i || count($hist) > 10) array_splice($hist, false !== $i ? $i : 10, 1); array_unshift($hist, $s); if ($p_re) $_POST['word'] = 0; else { $s = preg_quote($s, '/'); $s = $p_word ? "/(^|\W)($s)(\W|$)/" : "/$s/"; if (!$p_case) $s .= 'i'; } set($_POST + [ 'dirs' => implode(' ', $dir_list), 'skip' => implode(' ', $skip), 'files2' => implode(' ', $files2), 'delta=found=i_dir=i_file=cells=cell=mchoice' => 0, 'hist' => serialize($hist), 'rows' => implode(' ', filter_rows($area->inc_r, $area->exc_r)), 'regexp' => $s, ]); $syn ? print 1 : printf(ERR, 'Error in syntax of area definitions'); break; case 'replace': if ($cells) { list($table, $row, $cn) = explode('.', $cell); $txt = sql("+select $cn from $table where $row"); } else { $files = str2ary($files); $txt = file_get_contents($fn = $files[$i_file - 1]); } $offsets = explode(' ', $offsets); $f0 = substr($txt, 0, $offset = $offsets[$ival] + $delta); $old = strlen($txt = substr($txt, $offset)); $replace = $word ? "$1$_POST[to]$3" : $_POST['to']; if (is_string($txt = @preg_replace($regexp, $replace, $txt, $PVAL ? -1 : 1))) { set(['delta' => $delta + strlen($txt) - $old, 'mchoice' => $PVAL]); $cells ? sqlf("update $table set $cn=%s where $row", escape($f0 . $txt)) : file_put_contents($fn, $f0 . $txt); echo 1; } else printf(ERR, 'Error when replace :('); break; case 'search': $ret = 1; # continue search if ($cells) { $rows = str2ary($rows); if (!$PVAL && $i_dir < count($rows)) { list ($table, $cn, $cp, $where) = explode('.', $rows[$i_dir], 4); if ($dirs === $table) $cache = unserialize($cache); else { for ($q = sql("explain $table"), $cache = []; $r = fetch($q, true); ) { $cache[$r[0]] = intval(!$tf || $tc && strstr($r[1], 'text') || !strstr($r[1], 'blob') && !strstr($r[1], 'binary')); } $ary += ['cache' => serialize($cache), 'dirs' => $table]; } if ($cn && eval(sql("^select * from $table $where order by $cn limit $i_file, 1"))) { $keys = array_keys($r); foreach ($keys as $i => $_) if ($i >= $i_col && $cache[$_] && preg_match($regexp, $txt = $r[$_])) { $ret = ''; $ary += ['cell' => $fn = "$table.$cn=$r[$cn].$_"]; break; } for ($cnt = count($r); ++$i < $cnt; ) if ($cache[$_ = $keys[$i]] && preg_match($regexp, $r[$_])) break; if ($i == $cnt) { $i = 0; $i_file++; } $ary += ['i_col' => $i]; } else { $i_dir++; $i_file = 0; } } else { $ret = $found ? 0 : 'Not found!'; # finish $ary += ['dirs=skip=files2=files=cache=offsets' => '']; } } else { $dirs = str2ary($dirs); if (!$PVAL && $i_dir < count($dirs)) { if ($i_file) $files = str2ary($files); else { $files = is_file($dirs[$i_dir]) ? [$dirs[$i_dir]] : Area::lst($dirs[$i_dir], 'is_file', false, $skip); $ary += ['files' => implode(' ', $files)]; } if ($i_file >= count($files)) { $i_dir++; $i_file = 0; } elseif (!in_array(basename($fn = $files[$i_file++]), $u_svn_skips) && (!$tf || 1 == rectype($fn))) { $ret = is_array($txt = getfile($fn, 1, $tf && !$utf)) ? $txt[0] : ''; } } else { $ary += ['dirs=cells' => 1, 'i_col' => 0]; $i_dir = $i_file = 0; $ret = $PVAL || 2 == $mchoice ? 2 : 1; # end section } } if ('' === $ret) { if (false === @preg_match_all($regexp, $txt, $m, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { $ret = 'Error in Regular expression'; } elseif ($m) { $offsets = []; printf('<hr><span class="error"> %s: </span> <b>%s</b>%sLegend: ', $cells ? 'CELL' : 'FILE', $fn, pad()); $cnt = $word ? 1 : count($m[0]); for ($d = [], $i = 0; $i < $cnt && $i < 8; printf("$d[$i] %s </span> ", $i ? "\$$i" : 'FOUND'), $i++) { $d[$i] = '<span class="code m' . $i . '">'; } if ($cnt > 8) echo 'greater skipped in coloring'; $h = [1 => 20, 9, 5, 4, 3, 2]; $h = isset($h[$cnt = count($m)]) ? $h[$cnt] : 1; foreach ($m as $i_match => $one) { $offsets[] = $one[0][1]; if ($word) array_splice($one, 0, 2) && array_pop($one); $x = []; foreach (array_reverse($one, true) as $i => $v) { if ($i > 7) continue; elseif (!$i) { $n0 = substr_count($s0 = unl(substr($txt, 0, $v[1])), "\n"); if ($n0 < 1 + $h) { $start = 1; # beginning (first line) $str = html($s0); } else { $start = $n0 - $h + 1; $s0 = explode("\n", $s0); $str = html($s0 = implode(" \n", array_splice($s0, $n0 - $h))); $n0 = $h; } } $agg = $d[$i]; $v1 = 0; ksort($x); foreach ($x as $j => &$y) { if (!$y) continue; $e0 = $one[$j][1]; $e1 = $e0 + strlen($one[$j][0]); $e2 = $v[1] + strlen($v[0]); if ($v[1] <= $e0 && $e2 >= $e1) { if ($v[1] + $v1 < $e0) $agg .= html(substr($v[0], $v1, $e0 - $v[1] - $v1)); $agg .= $y; $y = 0; $v1 = $e1 - $v[1]; } } if (strlen($v[0]) > $v1) $agg .= html(substr($v[0], $v1)); $x[$i] = "$agg</span>"; if (!$i) { $str .= $x[0]; $n1 = substr_count($s1 = unl(substr($txt, $v[1] + strlen($v[0]))), "\n"); if ($n1 < 1 + $h) { $str .= html($s1); } else { $s1 = explode("\n", $s1); array_splice($s1, $h + 1); $str .= html($s1 = implode("\n", $s1)); $n1 = $h; } if (html($s0 . $v[0] . $s1) != strip_tags($str)) $ret = 'Internal error :('; else { $range = range($start, $start + $n0 + substr_count(unl($v[0]), "\n") + $n1); $nums = array_map(create_function('$v', 'return pad00($v,3) . "<br>\n";'), $range); echo '<hr><table cellpadding="0" cellspacing="0"><tr><td class="tdlnum">' . implode('', $nums); echo '</td><td style="padding:0 0 0 1px;vertical-align:top"><div class="i_match">' . (1 + $i_match); echo '</div><pre class="pre-found">' . str_replace("\t", ' ', $str) . '</pre></td></tr></table>'; } } } } $ary += ['found' => ++$found, 'offsets' => implode(' ', $offsets), 'delta' => 0]; } else { $ret = 1; } } if (is_int($ret)) echo $ret; elseif ($ret) printf(ERR, $ret); set($ary + ['i_dir' => $i_dir, 'i_file' => $i_file]); break; endswitch; # 2do: binary output else: # HTML PAGE $multi = ['no', 'all PAGE', 'all SECTION', 'all SEARCH']; $code = 'return "<pre onclick=\\"f1.s.value = this.text()\\">" . html($v) . "</pre>";'; $hist_html = ($hist ? '<h3>History:</h3>' : '') . '<div id="hist">'; $hist_html .= $hist ? implode('', array_map(create_function('$v', $code), $hist)) : ''; $hist_html .= '</div>'; ?> <form id="f1" style="width:90%"> <?=pad()?><label><input name="re" type="checkbox" <?=$re?'checked ':''?>/> RegExp</label> <?=pad()?><label id="case"><input name="case" type="checkbox" <?=$case?'checked ':''?> /> Case sensitive</label> <?=pad()?><label id="word"><input name="word" type="checkbox" <?=$word?'checked ':''?> /> Whole words</label><br> <b>Search:</b> <input name="s" size="100" value="<?=html($s)?>" class="inp" /><br> <b>Replace:</b> <input name="to" size="100" value="<?=html($to)?>" class="inp" /><br> <?=pad()?><label><input name="tf" type="checkbox" <?=$tf?'checked ':''?>onclick="if (!this.checked) f1.tc.checked = false" /> Search only text files (or cells - not blob)</label> <?=pad()?><label><input name="tc" type="checkbox" <?=$tc?'checked ':''?>onclick="if (this.checked) f1.tf.checked = true" /> Search only text-type cells (not varchar or int)</label><br> <?=pad()?><label><input name="utf" type="checkbox" <?=$utf?'checked ':''?> /> Skip UTF-8 check for text-type files</label><br> <?=pad()?><input id="start" type="button" value="Search - F9" onclick="key_F9()" /> <div id="area"><?php require '_dev/main/area.php' ?><br></div> <div id="found"></div> <?=$hist_html?> <div id="btn-tpl"> <?=pad()?><input type="button" value="Skip - Esc" onclick="key_Esc()" /> <?=pad()?><input type="button" value="Replace - F2" onclick="key_F2()" /> <?=pad()?>multi-choice: <select id="multi"><?=option(0, $multi)?></select> <?=pad(9)?><input type="button" value="Stop - F9" onclick="key_F9()" /> </div> </form> <script type="text/javascript"> var f1 = $('f1'), running = false, i_match, change_re, search_next, mc_f2, mc_esc; f1.re.onclick = change_re = function() { $('case', 'word', !f1.re.checked); } change_re(); function key_F9() { var add = true, s = f1.s.value; if ('' === s) return; if ('' === html('hist')) html('hist', 'bb', '<h3>History:</h3>'); $$('pre', 'hist', function(pre) { if (s == pre.text()) add = false; }); if (add) html('hist', 'ab', '<pre></pre>').$$('pre', 0, {text:s}).onclick = function() { f1.s.value = this.text() } $('area', 'start', 'hist', running).previousSibling.$(running); $('f1').$$('input', function(el) { if (el.name == 's' || el.type == 'checkbox') el.disabled = !running; }); html('found', ''); mc_f2 = mc_esc = 0; // multi choice if (running = !running) ajax('&ini=&' + qs$('res'), search_next = function(r, err) { i_match = 0; if ('1' == r) ajax('&search=' + mc_esc, search_next); else { if ('0' == r) r = '<?printf(ERR, "Finished!")?>'; else if ('2' == r) { mc_f2 = mc_esc = 0; return search_next('1'); } else if (mc_f2) return key_F2(); html('found', r); if (t$(add = $().$$('pre', 'pre-found', 0))) add.html('ae', html('btn-tpl')); else setTimeout(key_F9, 1500); } }); } function key_Esc() { if (!running) return; var multi = $('multi').options[$('multi').selectedIndex].index; if (0 == multi) return next_match(); if (3 == multi) return key_F9(); // end if (2 == multi) mc_esc = 1; search_next('1'); } function key_F2() { if (!running) return; var multi = mc_f2 ? 2 : $('multi').options[$('multi').selectedIndex].index; ajax(i_match + '&replace=' + multi + '&to=' + e$(f1.to.value), function (r, err) { if ('1' != r) return html('found', r); else if (1 == multi) return search_next('1'); // this page only else if (0 == multi) return next_match(); mc_f2 = 1; search_next('1'); }); } function next_match() { var next, cur = $('found').$$('table', 0), hr = cur.previousSibling; cur.$(''); hr.$(''); if (!t$(next = $().$$('pre', 'pre-found', 0))) return search_next('1'); next.html('ae', html('btn-tpl')); i_match++; } function adjust(x, y) { $('found', {width: x - 200}); } </script> <style type="text/css"> .i_match { float:right; margin-right:30px; background:blue;color:#fff;width:30px;text-align:center; } .inp { border:none; background-image:url(?img=13.ln.png); background-attachment:scroll; line-height:16px; } .pre-found { color:#777; margin:0; width:100px; overflow:visible; } #found table { width:100%; } .m0 {background:#ff0; color:#000; } .m1 {background:#ff0;color:red; font-weight:bold} .m2 {background:#0f0} .m3 {background:#0ff} .m4 {background:#f88} .m5 {background:#fa0} .m6 {background:#9b9} .m7 {background:#f0f} #btn-tpl { display:none; } #no-records { margin-top: 15px; } input:disabled { background:pink; } </style> <?php endif; |
Записи Codebase (89)
Статус SKY.
Current version: 1.001
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php