code/project.php


Home Back

<?php
    
require("conf.php");
    require (
"Parsedown.php");
    
    
$projectName=$_GET['p'];
    
$realPath=realpath($projectName);
    
$isProjectRoot=true;
    
    if (
strpos($projectName'/') !== false
    {
        
        
$isProjectRoot=false;
    }
    
    
    if (
strpos($realPath$ProjectsRoot) === FALSE
    {
        echo 
'Ops you are bad!';
        die();
    }

    
    
    if (
realpath($projectName)==false)
    {
        echo 
"Ops...file not found!";
        die();
    }
    
    
    
    
    if(! isset(
$_GET['p']))
    {
        echo 
"Ops...";
        die();
    }
    
    if(empty(
$_GET['p']))
    {
        echo 
"Ops...";
        die();
    }
    
    if (
strpos($projectName'..') !== false
    {
        echo 
"Ops...";
        die();
    }
    
    if (
strpos($projectName',') !== false
    {
        echo 
"Ops...";
        die();
    }
    
    if (
strpos($projectName'./') !== false)
    {
        echo 
"Ops...";
        die();
    }
    
    
    
    function 
getDescr($pname)
    {
        global 
$ProjectsRoot;
        
$file=$ProjectsRoot.'/'.$pname.'/.pobsrc/descr.pob';
        if (
is_file($file))
        {
            return 
file_get_contents($file);
        }else{
            return 
'';
        }
    }
    
    function 
getUrlDocs($pname)
    {
        global 
$ProjectsRoot;
        
$file=$ProjectsRoot.'/'.$pname.'/.pobsrc/urldocs.pob';
        if (
is_file($file))
        {
            
$url=file_get_contents($file);
            return 
'<a class="btn btn-secondary" style="margin-left:10px" href="'.$url.'" role="button" target="_blank" >Docs</a>' ;
        }else{
            return 
'';
        }
    }
    
    
    
    function 
formatUrl($html)
    {
            global 
$projectName;
            global 
$weburl;
            
            
$dom = new DOMDocument();
            
$dom->loadHTML($html);

            
$tags $dom->getElementsByTagName('a');
            foreach (
$tags as $tag
            {
                
$origUrl =  $tag->getAttribute('href');
                if(
substr($origUrl04) === "http") continue;
                
$tag->removeAttribute('href');
                
$tag->setAttribute("href"$weburl.'/doc.php?p='.$projectName.'/'.$origUrl);
            }
            
            
$tags $dom->getElementsByTagName('img');
            foreach (
$tags as $tag
            {
                
$origUrl =  $tag->getAttribute('src');
                if(
substr($origUrl04) === "http") continue;
                
$tag->removeAttribute('src');
                
$tag->setAttribute("src"$weburl.'/'.$projectName.'/'.$origUrl);
            }
            
            
            
$html=$dom->saveHTML();
            return 
$html;
        
    }
    
    
    function 
getReadme()
    {
        
        
$Parsedown = new Parsedown();
        
        global 
$ProjectsRoot;
        global 
$projectName;
        
$file=$ProjectsRoot.'/'.$projectName.'/Readme.md';
        if (
is_file($file))
        {
            
$file_content=file_get_contents($file);
            
$md=$Parsedown->text($file_content);
            return 
'<div id="readme" class="container" style="margin-top:10px">'formatUrl($md).'</div>';
        }
        
$file=$ProjectsRoot.'/'.$projectName.'/README.md';
        if (
is_file($file))
        {
            
$file_content=file_get_contents($file);
            
$md=$Parsedown->text($file_content);
            return 
'<div id="readme" class="container" style="margin-top:10px">'formatUrl($md).'</div>';
        }
        
$file=$ProjectsRoot.'/'.$projectName.'/readme.md';
        if (
is_file($file))
        {
            
$file_content=file_get_contents($file);
            
$md=$Parsedown->text($file_content);
            return 
'<div id="readme" class="container" style="margin-top:10px">'formatUrl($md).'</div>';
        }
    }
    
    
    function 
getIcon()
    {
        global 
$ProjectsRoot;
        global 
$projectName;
        global 
$weburl;
        
        
$file=explode ("/"$projectName)[0].'/icon.png';
        if (! 
is_file($file)) return '';
        
        
$img="$weburl/$file";
        return 
'<img src="'.$img.'" class="rounded float-left" style="height: 60px;margin-bottom:10px" />';
        
    }
    
    

include (
'header.php');
?>


    <div class="container" style="margin-top:15px">
    
    <p class="h1"><?php echo getIcon() ; ?>    <?php echo $projectName ?></p>
    <p class="lead" style="font-size:12px;margin-top:15px:float:left"><?php echo getDescr($projectName)?></p>
    
    <hr/>
    <div class="container" style="margin-bottom:10px">
    <a class="btn btn-success" href="index.php" role="button">Home</a>    
    <a class="btn btn-success" href="javascript:window.history.back()" role="button">Back</a>
    <?php 
        
if($isProjectRoot==true)
        {
            echo 
'<a class="btn btn-secondary" style="margin-left:20px" href="zipdir.php?p='$projectName .'" role="button">Clone</a>';
            echo 
getUrlDocs($projectName);
        }
    
?>
    </div>
    
    
    
    <?php
            
            
            
echo '<div  class="card" style="margin-bottom:20px">';
            echo 
getReadme();
            echo 
'</div>';
            echo 
'<div class="card  .container-fluid" ><ul class="list-group list-group-flush">';
            
            
//fist folder
            
$arr scandir($ProjectsRoot.'/'.$projectName);
            foreach(
$arr as $entry
            {
            
                if (
$entry=='.' ) continue;
                if (
$entry=='..' ) continue;
                
                
                
$line='';
                
                if (
is_dir($ProjectsRoot.'/'.$projectName.'/'.$entry))
                {
                    
$url='project.php?p='.$projectName.'/'.$entry;
                    
$line=$line='<a href="'.$url.'"><img style="width: 30px;margin-right:10px" src="folder.png"/>'.$entry.'</a>';
                
                    echo 
'<li class="list-group-item">'.$line.'</li>';
                    
                }
        }
        
        
//then files
        
$arrFiles scandir($ProjectsRoot.'/'.$projectName);
        foreach(
$arrFiles as $entry
        {
        
            if (
$entry=='.' ) continue;
            if (
$entry=='..' ) continue;
            
            
            
$line='';
            
$url='';
            if (
is_file($ProjectsRoot.'/'.$projectName.'/'.$entry))
            {
                    
$url='viewer.php?p='.$projectName.'/'.$entry;
                    
$line='<a href="'.$url.'">'.$entry.'</a>';
                    
$mod_date=date("d/m/Y "filemtime($ProjectsRoot.'/'.$projectName.'/'.$entry));
                
                echo 
'<li class="list-group-item"><img style="width: 30px;margin-right:10px" src="file.png"/>'.$line.'<span style="color:#4D4D4D;font-size:11px;float:right;" >('.$mod_date.')</span></li>';
            }
        }
        
        
    
        echo 
'</ul></div>';
    
?>
    
</div>
<?php include('footer.php');?>
</body>

</html>

Powered by Code, a simple repository browser by Fabio Di Matteo