Запись [f:_dev/ajax.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 | <?php define('START', 'ajax'); if (preg_match("/^([a-z_]{2,})/", $AJAX = array_shift($_POST), $m)) $AJAX = 'u' . $AJAX; $_POST and $_GET = array_splice($_POST, 0, 1); require '_dev/conf.php'; $ajax = substr($AJAX, 1); $ival = intval($ajax); $name = ''; ob_start(); switch ($AJAX[0]) { case 'd': # RUN RECORD (FORWARD) case 'b': # ROLLBACK (RUN RECORD BACKWARD) define('REAL_RUN', true); $imitate_only = $ival; $rollback = 'b' == $AJAX[0]; $id0 = PAGE == 'id' ? (int)$PVAL : 0; # if $id0 > 0 then it is initial (0-step), else `continue` step require '_dev/main/parser_cbr.php'; break; case 'c': # CLONE CODEBASE RECORD eval(_rec_open($ival)); $i = 1; $p = $ftype ? strrpos($r_name, '.') : 0; do { $name = $p ? 'return substr($r_name, 0, $p) . "_$i" . substr($r_name, $p);' : 'return $r_name . "_$i";'; } while (sqlf("+select 1 from _dev_codebase where name=%s union select 0", $name = escape(eval($name))) && $i++); print sqlf("insert into _dev_codebase %s", [ 'name' => $name, 'dt' => 'now()', 'dt_upd' => 'now()', 'code' => escape($src), 'status' => escape($r_status), 'rubric_id' => $r_rubric_id, 'author' => escape(add_author($r_author, $u_sky_inet_login)), 'childs' => $r_childs ? "'$r_childs'" : 'null', ]); break; case 't': # TUNE ONE RECORD $out = ['err' => 'Record not exists!', 'color' => '#7f7']; if ($rec = Record::tune("id=$ival", 1, 1, 1)) { # eval(_rec_open($ival)) if ($rec->ary) { $rec->ary += ['dt_upd' => 'now()', 'changed' => 1]; sqlf("update _dev_codebase set %s where id=$ival", $rec->ary); } if ($rec->mess) $out['err'] = $rec->mess('<br>'); else $out = ['err' => 'No changes...', 'color' => '#ff7']; # else $out['err'] = 'Difference in tab\'s found'; if ($rec->code) $out['html'] = Record::view($ival, $ftype, explode("\n", $rec->code)); } else $out['color'] = '#faa'; echo_json($out); break; case 'r': # GET CODEBASE RECORD eval(_rec_open($ival)); echo $r ? Record::view($ival, $ftype, $lines) : 0; break; case 'v': # VOTES set('d_voted', 1 + $d_voted); set('d_voted', 1, -$p_pid); $r = explode(' ', cell($ival, 'c', 'status'), 7); $r[1] or $r[1] = 3; 1 == $r[1] and $r[1] = 2; 5 == $r[1] and $r[1] = 4; $r[1] += $PVAL && $r[1] < 4 ? 1 : (!$PVAL && $r[1] > 2 ? -1 : 0); echo $r[2] + $r[1] - 3; sqlf("update _dev_codebase set status=%s where id=$ival", escape(implode(' ', $r))); break; case 'e': # EXPORT OF ONE RECORD $ext = new External($ival > 50000 ? 50001 - $ival : 0); $name = ''; echo $ext->export_rec(eval(_rec_open($ival)), $name, 0) ? "-Export fail!" : "+Exported OK. File `$name` written."; break; case 'h': # HELP $txt = sql("+select txt from _dev_help where code='$PAGE' and lang='$PVAL'"); set('u_help_lang', $PVAL); if ('commands' === PAGE) require '_dev/main/commands.php'; header('Content-Type: text/html; charset=utf-8'); print $txt; break; case 'p': # POPUPS $cnt = count($lines = explode("\n", cell(14))); for ($i = 0; $i < $cnt && (!preg_match("/^# DATA: (\S*) #$/", $lines[$i++], $m) || $ajax !== ".$m[1]"); ); for ($out = ''; $i < $cnt && !preg_match(MATCH_COM, $lines[$i]); ) $out .= $lines[$i++] . "\n"; header('Content-Type: text/html; charset=utf-8'); printf('<div id="popr"></div><div class="popin"><div><a>close [X]</a></div><pre>%s</pre></div><div id="popb"></div>', trim($out)); break; case 'n': # DO NOT AUTOSAVE SNAPSHOT OF INITIAL DEV.SKY. STATE set('d_snapshot', -1); break; case 'l': # CLEAR AND INIT NEW LAST LOG sql("update _dev_memory set dt=now(), tmemo='Started at: $NOW\nName: $p_n\ncycle($p_s .. $p_p)\n<hr>\n' where id=5"); break; case 'u': # UTILITIES $presets = ['sql_query' => 18, 'test_html' => 17, 'test_js' => 16, 'test_php' => 15]; if ('preset' == PAGE && ($id = @$presets[$m[1]])) { $list = []; foreach (Record::ary($id) as $com) if ('DATA' == $com[0]) { $PVAL or $PVAL = $com[1]; $list[] = $com[1]; if ($PVAL == $com[1]) $data = $com[2]; } $func = create_function('$v', 'return "<a href=\\"javascript:preset(\'$v\')\\">$v</a>";'); echo 'Available presets: <span id="sets">' . implode(' | ', array_map($func, $list)) . '</span><hr><table id="presets">'; foreach (str2ary(implode("\n", $data), "\n~\n") as $i => $cell) { if ($i % 3 == 0) echo '<tr>'; echo "<td width=\"33%\"><pre>" . str_replace("\t", ' ', html($cell)) . "</pre></td>"; if ($i % 3 == 2) echo '</tr>'; } printf('</table><br><button onclick="location.href=\'?cb_edit=%d\'">Edit - F4</button>', $id); } else { $ival = intval($ajax = substr($AJAX, 1 + strlen($m[1]))); require "_dev/_utility.php"; require "_dev/util/$m[1].php"; } break; } $stdout = ob_get_clean(); print $sky->error ? $sky->error : $stdout; $sky->tracing(); exit; |
en | test |