Source browser

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Source browser

Post by josh »

Made a lil file browser cuz nothing else existed ( that didnt have file inclusion holes ). Uses kodify.

Code: Select all

 
<?php
// kodify -> http://github.com/d11wtq/kodify  ( or can be used w/ http://us3.php.net/highlight_file )
/**
Copyright (c) 2008-2009, Ne8, LLC.
All rights reserved.
 
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
 
    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
 
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
 
    * Neither the name of Ne8, LLC. nor the names of its
      contributors may be used to endorse or promote products derived from this
      software without specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
$directory = 'DataShuffler-0.1/';    
?>
<script type="text/javascript" src="/lx_analyzer.js"></script>
<script type="text/javascript" src="/kodify.js"></script>
<script type="text/javascript" src="/php.js"></script>
<link id="theme" rel="stylesheet" type="text/css" href="/blackboard.css" />
<?php 
function listfiles( $path = '', $depth = 0 )    
{
    global $directory;  
    if( !$path )
    {
        $path = $directory . $path;
    }
    
    $files = glob( $path . '*' );
    foreach( $files as $file )
    {
        echo str_repeat( '&nbsp;', $depth * 5 ); 
        if( is_dir( $file ) )
        {
            
            echo htmlentities( basename( $file ) ) . '<br />';
            listfiles( $file . '/', $depth + 1 );
        }
        else
        {
            ?>
            <a href="?file=<?=urlencode( $file )?>"><?=htmlentities( basename( $file ) )?></a>
            <br />
            <?php
        }
    }
}
listfiles();
if( isset( $_GET['file'] ) && file_exists( $_GET['file'] ) )
{
    $file = pathinfo(  $_GET['file'] );
    if( substr( realpath( $file['dirname'] ), 0, strlen( realpath( $directory ) ) ) === realpath( $directory )  )
    {
        echo '<pre class="kodify php">' . htmlentities( file_get_contents( $_GET['file'] ) ) . '</pre>'; 
    }
}
 
Last edited by josh on Mon Feb 16, 2009 9:40 pm, edited 7 times in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: source browser

Post by josh »

User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: source browser

Post by VladSun »

There are plenty of such tools ;) :P (well, maybe they are not easy to find)
http://justin.madirish.net/node/322
There are 10 types of people in this world, those who understand binary and those who don't
coalgames
Forum Newbie
Posts: 8
Joined: Sun Apr 26, 2009 12:22 am

Re: Source browser

Post by coalgames »

This is a well written script. This could be xhtml compliant if you removed the <pre>'s and just nested <div>'s with margins. Other that that, nice script.

You can actually achieve this with PHP's SPL (Standard Public Library) and it might be faster.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Source browser

Post by markusn00b »

coalgames wrote:This is a well written script. This could be xhtml compliant if you removed the <pre>'s and just nested <div>'s with margins. Other that that, nice script.

You can actually achieve this with PHP's SPL (Standard Public Library) and it might be faster.
If it's in the core, it most certainly will be faster: compiled C kicks PHP's butt. ;)
Post Reply