Advertisement
terorama

HelpDocs

Dec 9th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.12 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('show_errors',1);
  4. error_reporting(E_ALL);
  5.  
  6.  
  7. if (isset($_GET['ajax'])) {
  8.    send_ajax();
  9.    exit();
  10. }
  11.  
  12. function send_ajax() {
  13.  
  14.    if ($_GET['part']=='php') {
  15.       send_php_desc();
  16.    }
  17. }
  18.  
  19. function send_php_desc() {
  20.  
  21.    $time_start = microtime(true);
  22.  
  23.    $comm = $_GET['cmd'];
  24.    
  25.    $addr = 'http://php.net/manual/ru/function.'.
  26.    str_replace('_','-',$comm).'.php';
  27.    
  28.    $s  = file_get_contents($addr);
  29.    
  30.    //echo 'get time: '.sprintf('%01.3f',(microtime(true)-$time_start)).'<br/>';
  31.    $time_start = microtime(true);
  32.    
  33.    preg_match(
  34.    '/<\s*div[^>]*?id=(["\'])([^\1<>]*?\s+|)usernotes(\s+[^\1<>]*?|)\1[^>]*?>/ims',
  35.    $s, $matches, PREG_OFFSET_CAPTURE);
  36.    
  37.    //echo '<pre>'.htmlentities(print_r($matches[0],true)).'</pre>';
  38.    
  39.    $s = substr($s,0, $matches[0][1]);
  40.    
  41.    $fin = false;
  42.    $examples = array();
  43.    
  44.    
  45.    
  46.    while ($fin==false) {
  47.  
  48.       $s4 = '/<\s*div\s*class=(["\'])([^\1<>]*?\s+|)example(\s+[^\1<>]*?|)\1[^>]*?>/ims';
  49.       preg_match($s4, $s, $matches, PREG_OFFSET_CAPTURE);
  50.      
  51.       //echo '<pre>'.htmlentities(print_r($matches[0],true)).'</pre>';
  52.      
  53.       if (empty($matches)) {
  54.          $fin = true;
  55.          break;
  56.       }
  57.  
  58.       $pos = $matches[0][1];
  59.       $s = substr($s, $pos);   
  60.      
  61.       $z=1;
  62.       $pos4 = strlen($matches[0][0]);
  63.       while ($z>0) {
  64.      
  65.          preg_match('/<\s*div[^>]*?>/ims',substr($s, $pos4), $matches4, PREG_OFFSET_CAPTURE);
  66.          preg_match('/<\s*\/div\s*>/ims', substr($s, $pos4) , $matches, PREG_OFFSET_CAPTURE);
  67.        
  68.          if (isset($matches4[0][1]) && ($matches4[0][1]<$matches[0][1])) {
  69.             $z++;
  70.             $pos4 += strlen($matches4[0][0])+ $matches4[0][1];
  71.            
  72.          }
  73.          else {
  74.             $z--;
  75.             $pos4 += strlen($matches[0][0])+ $matches[0][1];
  76.            
  77.          }     
  78.       }
  79.      
  80.       $examples[] = substr($s,0, $pos4);
  81.       $s = substr($s, $pos4);
  82.      
  83.    }
  84.    
  85.    //echo '<pre>'.htmlentities(print_r($examples,true)).'</pre>';
  86.    header('Content-type: application/json');
  87.    echo json_encode($examples);
  88.    
  89. }
  90.  
  91.  
  92. //------------------------------------
  93. $sn  = $_SERVER['SCRIPT_NAME'];
  94. $sp = substr($sn, 0, strrpos($sn, '/')+1);
  95. $req = str_replace($sp, '', $_SERVER['REQUEST_URI']);
  96.  
  97. $file = dirname($_SERVER['SCRIPT_FILENAME']).DIRECTORY_SEPARATOR.$req.'_funcs.txt';
  98.  
  99. if (!file_exists($file)) {
  100.  
  101.    echo ('requested file '.$file.' doesn\'t exists');
  102.    exit();
  103. }
  104.  
  105. ob_start();
  106. ?>
  107.  
  108. <style type="text/css">
  109.    .comd {
  110.       font-weight: bold;
  111.       cursor:pointer;
  112.    }
  113.    
  114.    #win_popup {
  115.       position: fixed;
  116.       width: 700px;
  117.       height: 500px;
  118.       background: white;
  119.       border: solid 1px black;
  120.       top: 0;
  121.       left: 0;
  122.       padding: 10px;
  123.       overflow:auto;
  124.    }
  125.    
  126.    #win_status {
  127.       width:150px;
  128.       height: 30px;
  129.       position: fixed;
  130.       left: 0;
  131.       top:0;
  132.       line-height:30px;
  133.       color: #880;
  134.       border: solid 1px #ee0;
  135.       background: #ffe;
  136.    }
  137.  
  138.    #topp {
  139.       position: fixed;
  140.       top:0;
  141.       right:10px;
  142.    }
  143.    #topp a {
  144.       display: block;
  145.       float: left;
  146.       padding: 4px 10px;
  147.       background: #444;
  148.       color: white;
  149.       text-decoration: none;
  150.    }
  151.  
  152. </style>
  153.  
  154. <?php
  155.  
  156. $styles = ob_get_clean();
  157. ob_start();
  158.  
  159. ?>
  160.  
  161. <script type="text/javascript" src="jquery.min.js"></script>
  162.  
  163. <script type="text/javascript">
  164.  
  165.    var now_loading = 0;
  166.    var gl_timeout;
  167.    var gl_tm4=false;
  168.  
  169.    $(document).ready(
  170.       function() {
  171.      
  172.          $('<div/>',{id:'win_status'}).prependTo('body').html('current status');
  173.          $('<div/>',{id:'win_popup'}).css('display','none').appendTo('body')
  174.          .css('left', window.innerWidth/2-350).css('top', '100')
  175.          .click(
  176.             function() {
  177.                $(this).fadeOut('slow', function() {
  178.                 if (now_loading==1) now_loading = 0;});
  179.             }
  180.          );
  181.          
  182.          $('.comd').click( function() {
  183.          
  184.             if (now_loading>0) {
  185.            
  186.                var tx = $('#win_status').html();
  187.                $('#win_status').html('busy...');
  188.                
  189.                if (gl_tm4==false) {
  190.        
  191.                   gl_tm4 = setTimeout ((function(tx) {
  192.                
  193.                      return function() {
  194.                        
  195.                         $('#win_status').html(tx);
  196.                        
  197.                         gl_tm4 = false;
  198.                      }
  199.                   })(tx),500);
  200.                }
  201.                
  202.                return false;
  203.                
  204.             }
  205.          
  206.             now_loading = 4;
  207.             $('#win_status').html('loading...');
  208.            
  209.            
  210.          
  211.             $.when ($.ajax( {
  212.                type: 'GET',
  213.                url: "<?php echo $_SERVER['PHP_SELF']?>",
  214.                data: {ajax:'', cmd: $(this).text(),
  215.                       part: "<?php echo substr(str_replace(dirname($file),'',str_replace('_funcs.txt','',$file)),1)?>"},
  216.                success: onSuccess,
  217.                error: onError
  218.             }
  219.          )).done(
  220.             function() {
  221.                
  222.             }
  223.          
  224.          )
  225.       })
  226.       }
  227.    )
  228.    
  229.    function onSuccess(data) {
  230.    
  231.       now_loading = 0;                 
  232.       $('#win_status').html('ready');
  233.      
  234.       var htm='';
  235.       $.each(data, function (i, el) {          
  236.          htm +=el+'<br/>';
  237.       });
  238.       $('#win_popup').empty().html(htm).fadeIn('slow');
  239.    }
  240.    
  241.    function onError(xhr, status, exception) {
  242.    
  243.       now_loading = 0;                 
  244.       $('#win_status').html('error');
  245.    
  246.       $('#win_popup').empty().html('Exception: '+exception).fadeIn('slow');
  247.    }
  248. </script>
  249.  
  250. <?php
  251. $scripts = ob_get_clean();
  252.  
  253. //---------------------------
  254. header ('Content-type:text/html; charset=utf-8');
  255.  
  256.  
  257. echo '<html><head>
  258.  
  259.  <title>'.strtoupper(substr(str_replace(dirname($file),'',str_replace('_funcs.txt','',$file)),1)).
  260. ' Reference</title>
  261.  
  262.  
  263.  <base href="/tuts/" />
  264.  
  265. '.$styles.$scripts.'</head><body>
  266. <div id="topp"><a href="php">PHP</a><a href="jquery">jQuery</a>
  267. <a href="javascript">JavaScript</a></div>
  268. <pre>';
  269.  
  270. $f = fopen ($file,'r');
  271.  
  272. while (($s = fgets($f))!==false) {
  273.    
  274.    $s = htmlspecialchars($s);
  275.    $s = iconv('windows-1251','utf-8',$s);
  276.    //$s = mb_convert_encoding($s, mb_detect_encoding($s,"auto"),'UTF-8');
  277.    
  278.    $cnt = 0;
  279.    $s = str_replace('_ ','_',$s, $cnt);
  280.    $head = substr($s,0,strcspn($s,' /;-()'));
  281.    $trailer = substr($s, strcspn($s,' /;-()'));
  282.    echo '<span class="comd">'.$head.'</span>'.str_repeat(' ',$cnt).'<span class="trailer">'.$trailer.'</span>';
  283. }
  284.  
  285. echo '</pre></body></html>';
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement