Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('show_errors',1);
- error_reporting(E_ALL);
- if (isset($_GET['ajax'])) {
- send_ajax();
- exit();
- }
- function send_ajax() {
- if ($_GET['part']=='php') {
- send_php_desc();
- }
- }
- function send_php_desc() {
- $time_start = microtime(true);
- $comm = $_GET['cmd'];
- $addr = 'http://php.net/manual/ru/function.'.
- str_replace('_','-',$comm).'.php';
- $s = file_get_contents($addr);
- //echo 'get time: '.sprintf('%01.3f',(microtime(true)-$time_start)).'<br/>';
- $time_start = microtime(true);
- preg_match(
- '/<\s*div[^>]*?id=(["\'])([^\1<>]*?\s+|)usernotes(\s+[^\1<>]*?|)\1[^>]*?>/ims',
- $s, $matches, PREG_OFFSET_CAPTURE);
- //echo '<pre>'.htmlentities(print_r($matches[0],true)).'</pre>';
- $s = substr($s,0, $matches[0][1]);
- $fin = false;
- $examples = array();
- while ($fin==false) {
- $s4 = '/<\s*div\s*class=(["\'])([^\1<>]*?\s+|)example(\s+[^\1<>]*?|)\1[^>]*?>/ims';
- preg_match($s4, $s, $matches, PREG_OFFSET_CAPTURE);
- //echo '<pre>'.htmlentities(print_r($matches[0],true)).'</pre>';
- if (empty($matches)) {
- $fin = true;
- break;
- }
- $pos = $matches[0][1];
- $s = substr($s, $pos);
- $z=1;
- $pos4 = strlen($matches[0][0]);
- while ($z>0) {
- preg_match('/<\s*div[^>]*?>/ims',substr($s, $pos4), $matches4, PREG_OFFSET_CAPTURE);
- preg_match('/<\s*\/div\s*>/ims', substr($s, $pos4) , $matches, PREG_OFFSET_CAPTURE);
- if (isset($matches4[0][1]) && ($matches4[0][1]<$matches[0][1])) {
- $z++;
- $pos4 += strlen($matches4[0][0])+ $matches4[0][1];
- }
- else {
- $z--;
- $pos4 += strlen($matches[0][0])+ $matches[0][1];
- }
- }
- $examples[] = substr($s,0, $pos4);
- $s = substr($s, $pos4);
- }
- //echo '<pre>'.htmlentities(print_r($examples,true)).'</pre>';
- header('Content-type: application/json');
- echo json_encode($examples);
- }
- //------------------------------------
- $sn = $_SERVER['SCRIPT_NAME'];
- $sp = substr($sn, 0, strrpos($sn, '/')+1);
- $req = str_replace($sp, '', $_SERVER['REQUEST_URI']);
- $file = dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$req.'_funcs.txt';
- if (!file_exists($file)) {
- echo ('requested file '.$file.' doesn\'t exists');
- exit();
- }
- ob_start();
- ?>
- <style type="text/css">
- .comd {
- font-weight: bold;
- cursor:pointer;
- }
- #win_popup {
- position: fixed;
- width: 700px;
- height: 500px;
- background: white;
- border: solid 1px black;
- top: 0;
- left: 0;
- padding: 10px;
- overflow:auto;
- }
- #win_status {
- width:150px;
- height: 30px;
- position: fixed;
- left: 0;
- top:0;
- line-height:30px;
- color: #880;
- border: solid 1px #ee0;
- background: #ffe;
- }
- #topp {
- position: fixed;
- top:0;
- right:10px;
- }
- #topp a {
- display: block;
- float: left;
- padding: 4px 10px;
- background: #444;
- color: white;
- text-decoration: none;
- }
- </style>
- <?php
- $styles = ob_get_clean();
- ob_start();
- ?>
- <script type="text/javascript" src="jquery.min.js"></script>
- <script type="text/javascript">
- var now_loading = 0;
- var gl_timeout;
- var gl_tm4=false;
- $(document).ready(
- function() {
- $('<div/>',{id:'win_status'}).prependTo('body').html('current status');
- $('<div/>',{id:'win_popup'}).css('display','none').appendTo('body')
- .css('left', window.innerWidth/2-350).css('top', '100')
- .click(
- function() {
- $(this).fadeOut('slow', function() {
- if (now_loading==1) now_loading = 0;});
- }
- );
- $('.comd').click( function() {
- if (now_loading>0) {
- var tx = $('#win_status').html();
- $('#win_status').html('busy...');
- if (gl_tm4==false) {
- gl_tm4 = setTimeout ((function(tx) {
- return function() {
- $('#win_status').html(tx);
- gl_tm4 = false;
- }
- })(tx),500);
- }
- return false;
- }
- now_loading = 4;
- $('#win_status').html('loading...');
- $.when ($.ajax( {
- type: 'GET',
- url: "<?php echo $_SERVER['PHP_SELF']?>",
- data: {ajax:'', cmd: $(this).text(),
- part: "<?php echo substr(str_replace(dirname($file),'',str_replace('_funcs.txt','',$file)),1)?>"},
- success: onSuccess,
- error: onError
- }
- )).done(
- function() {
- }
- )
- })
- }
- )
- function onSuccess(data) {
- now_loading = 0;
- $('#win_status').html('ready');
- var htm='';
- $.each(data, function (i, el) {
- htm +=el+'<br/>';
- });
- $('#win_popup').empty().html(htm).fadeIn('slow');
- }
- function onError(xhr, status, exception) {
- now_loading = 0;
- $('#win_status').html('error');
- $('#win_popup').empty().html('Exception: '+exception).fadeIn('slow');
- }
- </script>
- <?php
- $scripts = ob_get_clean();
- //---------------------------
- header ('Content-type:text/html; charset=utf-8');
- echo '<html><head>
- <title>'.strtoupper(substr(str_replace(dirname($file),'',str_replace('_funcs.txt','',$file)),1)).
- ' Reference</title>
- <base href="/tuts/" />
- '.$styles.$scripts.'</head><body>
- <div id="topp"><a href="php">PHP</a><a href="jquery">jQuery</a>
- <a href="javascript">JavaScript</a></div>
- <pre>';
- $f = fopen ($file,'r');
- while (($s = fgets($f))!==false) {
- $s = htmlspecialchars($s);
- $s = iconv('windows-1251','utf-8',$s);
- //$s = mb_convert_encoding($s, mb_detect_encoding($s,"auto"),'UTF-8');
- $cnt = 0;
- $s = str_replace('_ ','_',$s, $cnt);
- $head = substr($s,0,strcspn($s,' /;-()'));
- $trailer = substr($s, strcspn($s,' /;-()'));
- echo '<span class="comd">'.$head.'</span>'.str_repeat(' ',$cnt).'<span class="trailer">'.$trailer.'</span>';
- }
- echo '</pre></body></html>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement