terorama

Browser5 (Collapsable)

Dec 9th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 11.01 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('display_errors',1);
  4. ini_set('display_startup_errors',1);
  5.  
  6.    $dir = dirname(__FILE__);
  7. //--------------------------------------
  8. function srt($a, $b) {
  9.  
  10.         $a = $a['path'];
  11.         $b = $b['path'];
  12.  
  13.         if (is_dir($a)) {
  14.         if (is_dir($b)) {
  15.            return strcasecmp($a,$b);
  16.         }
  17.         else return -1;
  18.      } else {
  19.        if (is_dir($b))
  20.           return 1;
  21.        else
  22.           return strcasecmp($a,$b);}
  23. }
  24. //--------------------------------------
  25. function out($z) {
  26.  
  27.   $z1 = ($z['name']=='..') ? '..up' : $z['name'];
  28.  
  29.    echo "<li class=\"".(is_dir($z['path'])?'':'fl')."\"><a href=\"{$z['path']}\">$z1</a></li>";
  30. }
  31. //--------------------------------------
  32.  
  33. function showdir($dirr) {
  34.  
  35.  
  36.     $z = opendir($dirr);
  37.     $files = array();
  38.     while ($f= readdir($z)) {
  39.  
  40.         $el = array();
  41.         $el['name'] = $f;
  42.         $el['path'] = $dirr.'/'.$f;
  43.  
  44.         $files[] = $el;
  45.  
  46.     }
  47.     closedir($z);
  48.  
  49.     usort($files, 'srt');
  50.  
  51.     array_splice($files,0, 1);
  52.    
  53.  
  54.     array_walk($files,'out');
  55. }
  56. //--------------------------------------
  57.  
  58.    session_start();
  59.  
  60.    if (!isset($_SESSION['logged8'])) {
  61.       if (isset($_POST['pass'])) {
  62.          //$s = file_get_contents('hash.txt');
  63.          $s = md5('password');
  64.  
  65.          if (md5($_POST['pass'])==$s) {
  66.             $_SESSION['logged8']=true;
  67.  
  68.             echo 'successfully logged in<br/>';
  69.             echo '<a href="'.$_SERVER['PHP_SELF'].'" title="back" >back</a>';
  70.  
  71.             exit();
  72.          } else {
  73.  
  74.             echo 'incorrect password<br/>';
  75.             echo '<a href="'.$_SERVER['PHP_SELF'].'" title="back">back</a>';
  76.             exit();
  77.  
  78.          }
  79.       } else {
  80.        
  81.         $ss = <<<ZZ
  82.            <form name="authform" action="{$_SERVER['PHP_SELF']}"
  83.              method="post" enctype="application/x-www-form-urlencoded">
  84.  
  85.            <p>input password <input type="text" name="pass" /> </p>
  86.            <input type="submit" value="send" />
  87.  
  88.            </form>  
  89.  
  90. ZZ;
  91.  
  92.          echo $ss;
  93.          exit();
  94.       }
  95.          
  96.    }
  97.    
  98.    if (isset($_GET['ajax'])) {
  99.       switch ($_GET['action']) {
  100.  
  101.          case 'getfile' :
  102.          
  103.             $fn= $_GET['fname'];
  104.            
  105.            
  106.            
  107.         $strz = htmlentities(file_get_contents($fn));
  108.             $regexp4 = '/((abstract|static)?\s+class\s+.*?{)/ims';
  109.             $strz = preg_replace($regexp4, '<div class="header7">$1</div>',$strz);
  110.  
  111.            
  112.  
  113.  $regexp= '/((<div class="header7">.*?<\/div>)?.*?(?:private|public|protected)\s*(?:static)?\s*function[\w\d\s]*?\(.*?\))(.*?)(?=(?:(?:private|public|protected)\s*(?:static)?\s*function)|(?:<div class="header7">))/ims';
  114.  
  115.             preg_match_all($regexp, $strz, $uuu, PREG_SET_ORDER);
  116.            
  117.           //  echo '<pre>'.print_r($uuu, true).'</pre>';
  118. //fuck the god
  119.             $strz = '';
  120.             foreach  ($uuu as $el) {
  121.                $strz .=  "<div class=\"header8\">$el[1]</div><div class=\"spoiler9\">$el[3]</div>";
  122.             }
  123.  
  124.             foreach (array('function','public','static','for','while','if','else',
  125.                'add_action','add_filter','switch','case','break',
  126.              'foreach', 'as','require','require_once','include','include_once',
  127.        'array','return') as $el) {
  128.               $strz = preg_replace('/(^|\s+|[{}()])('.$el.')(\s+|[{()}]|$)/ims',
  129.                '$1<span class="command">$2</span>$3', $strz);
  130.            }
  131.          
  132. //echo '<pre>'.htmlentities($strz).'</pre>';
  133.             $ctype='getfile';
  134.             $content='<pre>'.$strz.'</pre>';
  135.  
  136.             $u = explode('/',$fn);
  137.             $fn=array_pop($u);
  138.  
  139.            
  140.  
  141.             echo json_encode(Array('ctype'=>$ctype, 'content'=>base64_encode($content), 'fname'=>$fn));
  142.             break;
  143.  
  144.          case 'getdir' :
  145.  
  146.             ob_start();
  147.             showdir($_GET['fname']);
  148.             $ctype = 'getdir';
  149.             $content = ob_get_clean();
  150.  
  151.             echo json_encode(Array('ctype'=>$ctype, 'content'=>$content));
  152.             break;
  153.       }
  154.  
  155.       exit();
  156.    }
  157.  
  158. ?>
  159.  
  160. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  161. <html xmlns="http://www.w3.org/1999/xhtml">
  162.  
  163. <head>
  164. <title> file browser </title>
  165.  
  166. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  167. <script type="text/javascript">
  168.  
  169. function decode_base64(s) {
  170.     var e={},i,k,v=[],r='',w=String.fromCharCode;
  171.     var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];
  172.  
  173.     for(z in n){for(i=n[z][0];i<n[z][1];i++){v.push(w(i));}}
  174.     for(i=0;i<64;i++){e[v[i]]=i;}
  175.  
  176.     for(i=0;i<s.length;i+=72){
  177.     var b=0,c,x,l=0,o=s.substring(i,i+72);
  178.          for(x=0;x<o.length;x++){
  179.                 c=e[o.charAt(x)];b=(b<<6)+c;l+=6;
  180.                 while(l>=8){r+=w((b>>>(l-=8))%256);}
  181.          }
  182.     }
  183.     return r;
  184.     }
  185.  
  186.    function setSpoilers() {
  187.       $('.header8').unbind('click').click(
  188.          function() {
  189.             $(this).next().slideToggle();
  190.          }
  191.       )
  192.    }
  193.  
  194.    function onSuccess(inf,block) {
  195.       if (inf.ctype=='getfile') {
  196.  
  197.          $('#messageload').html('');
  198.  
  199.          var tabs =  $('#filebrowse ul');
  200.          var l = tabs.children().length;
  201.          tabs.prepend($('<li/>').data('inf',l).html(inf.fname).append($('<span/>').text('x')
  202.  
  203.              .click ( function(ev) {
  204.                 var liinf = $(this).parent().data('inf');
  205.                 $('#filebrowse>div').filter(
  206.                   function(index) {
  207.                      return (liinf===$(this).data('inf'));
  208.                   }
  209.                ).remove();
  210.                
  211.                var _selfp=$(this).parent().get(0);
  212.                $(this).parent().parent().children().filter(
  213.                      function(index) {
  214.                        return (this!==_selfp)
  215.                     }
  216.                  )
  217.                 .first().trigger('click');
  218.  
  219.                $(this).parent().remove();
  220.              
  221.              }
  222.               ))
  223.              .click (  function(ev) {
  224.              
  225.             var liinf = $(this).data('inf');
  226.  
  227.             $('#filebrowse>div[id!="messageload"]:visible').fadeOut('fast');
  228.             $('#filebrowse>div').filter(
  229.                function(index) {
  230.  
  231.                    return (liinf===$(this).data('inf'));
  232.                }
  233.             ).fadeIn('fast');
  234.          }));
  235.  
  236.          $('#filebrowse').append($('<div/>').data('inf',l));
  237.  
  238.          $("#filebrowse>div[id!='messageload']").fadeOut('fast');
  239.          $('#filebrowse>div:last').html(decode_base64(inf.content)).fadeIn('fast');
  240.          setSpoilers();
  241.        
  242.          
  243.       }
  244.  
  245.       if (inf.ctype=='getdir') {
  246.          $(block).html(inf.content);
  247.       }
  248.  
  249.       init();
  250.       busy=false;
  251.    }
  252.  
  253.    function ajax_get(action, fname, block) {
  254.  
  255.       //if (window.busy)
  256.       //   return;
  257.  
  258.       busy=true;
  259.  
  260.       if (!block)
  261.          block = $(document.body);
  262.  
  263.       switch (action) {
  264.  
  265.          case 'getfile':
  266.             var zht = $('#messageload').html();
  267.             $('#messageload').html(zht+fname+' loading, please wait...<br/>');
  268.             break;
  269.          
  270.          case 'getdir':
  271.             block.html('Loading...');
  272.             break;
  273.       }
  274.       $.ajax({
  275.           type: 'GET',
  276.           url:"<?=$_SERVER["PHP_SELF"]?>",
  277.           dataType: 'json',
  278.           data: {
  279.              ajax: '',
  280.              action: action,
  281.              fname: fname
  282.           },
  283.           success: function(inf) {
  284.              
  285.              onSuccess(inf, block);
  286.           }
  287.          
  288.       })
  289.    }
  290.  
  291.  
  292.    $(document).ready(init);
  293.  
  294.    function init() {
  295.       $('#dir_structure li.fl').children('a').unbind('click').click (
  296.        
  297.         function(ev) {
  298.            var fname = $(this).attr('href');
  299.            ajax_get('getfile', fname);
  300.  
  301.            
  302.            return false;
  303.            
  304.         } );
  305.  
  306.    
  307.  
  308.      $('#dir_structure li:not(.fl)').children('a').unbind('click').click(
  309.        
  310.         function(ev) {
  311.            var el = $('<ul/>');
  312.            $(this).parent().append(el);
  313.            var fname = $(this).attr('href');
  314.            ajax_get('getdir', fname, el);
  315.  
  316.            return false;
  317.         }
  318.      );
  319.  
  320.         $("#dir_structure li a:contains('..up')").unbind('click').click (
  321.  
  322.           function(ev) {
  323.  
  324.            var el = $('#dir_structure');
  325.            
  326.            var fname = $(this).attr('href');
  327.            ajax_get('getdir', fname, el);
  328.  
  329.            return false;
  330.           }
  331.       );
  332.  
  333.       $("#dir_structure li ul li a:contains('..up'), a:contains('close..')")
  334.  
  335.        .html('close..')
  336.        .unbind('click').click (
  337.  
  338.           function(ev) {
  339.  
  340.              var _el = $(this);
  341.              $.when ($(this).parent().parent().slideUp('slow')).done(
  342.  
  343.                   function() {
  344.                      _el.parent().parent().remove();
  345.                   }
  346.              );
  347.  
  348.              return false;
  349.           }
  350.       );
  351.  
  352.    }
  353. </script>
  354.  
  355. <style type="text/css">
  356.    * {
  357.       margin:0;
  358.       padding:0;
  359.    }
  360.  
  361.    body {
  362.       font-family: verdana, sans-serif;
  363.       font-size: 1.2em;
  364.    }
  365.  
  366.    li {
  367.       list-style-type: none;
  368.    }
  369.  
  370.    a {
  371.       text-decoration: none;
  372.       color: #400;
  373.    }
  374.  
  375.    a:hover {
  376.       text-decoration: underline;
  377.    }
  378.  
  379.    #dir_structure {
  380.       padding: 10px;
  381.       border: solid 1px #eee;
  382.       background-color: #ffe;
  383.       margin:50px 0 0 20px;
  384.       float:right;
  385.       width:300px;
  386.    }
  387.  
  388.    #dir_structure li ul {
  389.       margin-left: 10px;
  390.       margin-bottom: 20px;
  391.    }
  392.    
  393.    .fl a{
  394.       color: #900;
  395.    }
  396.  
  397.    #filebrowse {
  398.      
  399.       margin:50px 50px 0 0 ;
  400.       background-color: #fffff0;
  401.       font-family: "courier new", monospace;
  402.       font-size: 12px;
  403.       padding: 5px;
  404.       border: solid 1px #aaa;
  405.       word-wrap:break-word;
  406.  
  407.    }
  408.  
  409.    #filebrowse ul {
  410.  
  411.       position: fixed;
  412.       bottom: 0;
  413.       right: 10px
  414.      
  415.      
  416.    }
  417.  
  418.    #filebrowse ul li {
  419.  
  420.       float: left;
  421.       cursor:pointer;
  422.       margin: 0 5px 5px 0;
  423.       border: solid 1px #888;
  424.       border-radius: 7px;
  425.       padding: 4px 8px;
  426.       color: white;
  427.       background: #444;
  428.  
  429.    }
  430.  
  431.    #filebrowse ul li:hover {
  432.      
  433.       background: #666;
  434.       color: white;
  435.    }
  436.  
  437.    #filebrowse ul li span {
  438.       padding-left:10px;
  439.       padding-right:10px;
  440.    }
  441.  
  442.    #filebrowse ul li span:hover {
  443.       color: red;
  444.    }
  445.  
  446.    #filebrowse>div {
  447.       display: none;
  448.      
  449.      
  450.    }
  451.  
  452.    #filebrowse #messageload {
  453.       display: block;
  454.    }
  455.    
  456.    .header8 {
  457.       cursor: pointer;
  458.       background: #fff;
  459.       border: dotted 1px #aaa;
  460.      
  461.    }
  462.    .spoiler9 {
  463.       display:none;
  464.    }
  465.  
  466.    .header7 {
  467.        font-weight: bold;
  468.    }
  469.  
  470.    .command {
  471.       color: #a00;
  472.       font-weight: bold;
  473.    }
  474.    
  475. </style>
  476.  
  477. </head>
  478. <body>
  479. <h3>browser 5</h3>
  480. <ul id="dir_structure">
  481. <?php
  482.  
  483.  
  484.    showdir($dir);
  485.  
  486. ?>
  487. </ul>
  488.  
  489. <div id="filebrowse">
  490. <div id="messageload"></div>
  491. <ul></ul>
  492.  
  493. </div>
  494.  
  495. </body>
  496. </html>
Add Comment
Please, Sign In to add comment