Location: PHPKode > projects > PHP Site Editor > siteedit2/includes/site_edit.lib.php3
<?php

function folder_view_tree($thepath,$ntree)
{
    global $opened;
    global $currentdir;

    $i = 0;
    $dirList = array();

    $dir = opendir($thepath);
    while ($file = readdir($dir)) {
        if (($file == ".") || ($file == "..")) continue;
        $filepath = $thepath . "/" . $file;
        if (!is_dir($filepath)) continue;

        $dirList[$i++] = $file;
    }
    sort($dirList);

    $num = count($dirList);
    for ($i=0;$i < $num;$i++) {
        $file = $dirList[$i];
        $filepath = $thepath . "/" . $file;
        $fileinode = fileinode($filepath);

        print("<div>");
        for ($n=0;$n < $ntree;$n++) {
            printf("<img src=\"images/link.gif\">");
        }

        if ($opened["$fileinode"] == 1) {
            $urlink = "<a href=\"left.php3?fileinode=$fileinode\">";
            print("$urlink");
            print("<img src=\"images/opennote.gif\" border=\"0\">");
            print("</a>");
        } else {
            $urlink = "<a href=\"left.php3?&fileinode=$fileinode\">";
            print("$urlink");
            print("<img src=\"images/closenote.gif\" border=\"0\">");
            print("</a>");
        }
        $url  = "<a href=\"left.php3?currentdir=$filepath\" ";
        $url .= "onclick=\"parent.phpmain.window.location='main.php3?currentdir=$filepath'\">";
        print("$url");
        if ($filepath == $currentdir) {
            print("<img src=\"images/opendir.gif\" border=\"0\" alt=\"$file\">");
            print("&nbsp;");
            print("<FONT color=white style=\"BACKGROUND-COLOR: darkblue\">");
            print("$file");
            print("</FONT>");
        } else {
            print("<img src=\"images/closedir.gif\" border=\"0\" alt=\"$file\">");
            print("&nbsp;");
            print("$file");
        }
        print("</a>");
        if (!is_writable($filepath)) {
             print("&nbsp;");
             print("<img src=\"images/lock.gif\">");
        }
        print("</div>");
        if ($opened["$fileinode"] == 1) {
            $n = $ntree+1;
            folder_view_tree($filepath,$n);
        }
    }
    closedir($dir);
    return $n;
}

function file_search_list($thecwd,$key,$flag)
{
    $folderList = array();
    $fileList = array();

    $dn = count($folderList);
    $fn = count($fileList);
    $dir = opendir($thecwd);
    while ($file = readdir($dir)) {
        if (($file == ".") || ($file == "..")) continue;
        $filepath = $thecwd . "/" . $file;
        if (is_dir($filepath)) {
            $folderList[$dn++] = $filepath;
        } else {
            $fileList[$fn++] = $filepath;
        }
    }
    closedir($dir);
    sort($folderList);
    sort($fileList);

    $list = array_merge($folderList,$fileList);

    return $list;
}

function file_view_list($fileList)
{
    global $strName,$strSize,$strType,$strMDate,$strOP,$strFolderType,$strFileType;
    global $fileList;

    $fnum = count($fileList);

    print("<table border=1 cellPadding=2 cellSpacing=0 width=100% bordercolorlight=\"#aa77aa\" bordercolordark=\"#fffff0\">");
    print("<tr>");
    print("<td bgcolor=\"#EEEBDB\">$strName</td>");
    print("<td bgcolor=\"#EEEBDB\" width=150>$strOP</td>");
    print("</tr>");
    print("<tr>");
    for ($i=0;$i < $fnum;$i++) {
        $filepath = $fileList[$i];
        $file = basename($filepath);
        print("<tr>");
        print("<td>");
        $theroot = DIR_DOCUMENT_ROOT;
        $urlpath = str_replace($theroot,"",$filepath);
        $url_filepath = urlencode($filepath);
        if (is_dir($filepath)) {
            if (is_readable($filepath)) {
                print("<a href=\"main.php3?currentdir=$filepath\">");
                file_view_a_ssicon($filepath);
                print("$file");
                print("</a>");
            } else {
                file_view_a_ssicon($filepath);
                print("$file");
            }
        } else {
            if (is_file($filepath) && (is_readable($filepath))) {
                print("<a href=\"$urlpath\">");
                file_view_a_ssicon($filepath);
                print("$file");
                print("</a>");
            } else {
                file_view_a_ssicon($filepath);
                print("$file");
            }
        }
        if (!is_writable($filepath)) {
             print("<img src=\"images/lock.gif\">");
        }
        print("</td>");
        print("<td>");
        file_edit_function($filepath);
        print("</td>");
        print("</tr>");
    }
    print("</table>");
}

function file_view_info($fileList)
{
    global $strName,$strSize,$strType,$strMDate,$strOP,$strFolderType,$strFileType;

    $fnum = count($fileList);
    print("<table border=1 cellPadding=2 cellSpacing=0 width=100% bordercolorlight=\"#aa77aa\" bordercolordark=\"#fffff0\">");
    print("<tr>");
    print("<td bgcolor=\"#EEEBDB\">$strName</td>");
    print("<td bgcolor=\"#EEEBDB\">$strSize</td>");
    print("<td bgcolor=\"#EEEBDB\">$strType</td>");
    print("<td bgcolor=\"#EEEBDB\">$strMDate</td>");
    print("<td bgcolor=\"#EEEBDB\" width=150>$strOP</td>");
    print("</tr>");
    print("<tr>");
    for ($i=0;$i < $fnum;$i++) {
        $filepath = $fileList[$i];
        $file = basename($filepath);
        print("<tr>");
        print("<td>");
        $theroot = DIR_DOCUMENT_ROOT;
        $urlpath = str_replace($theroot,"",$filepath);
        $url_filepath = urlencode($filepath);
        if (is_dir($filepath)) {
            if (is_readable($filepath)) {
                print("<a href=\"main.php3?currentdir=$filepath\">");
                file_view_a_ssicon($filepath);
                print("$file");
                print("</a>");
            } else {
                file_view_a_ssicon($filepath);
                print("$file");
            }
        } else {
            if (is_file($filepath) && (is_readable($filepath))) {
                print("<a href=\"$urlpath\">");
                file_view_a_ssicon($filepath);
                print("$file");
                print("</a>");
            } else {
                file_view_a_ssicon($filepath);
                print("$file");
            }
        }
        if (!is_writable($filepath)) {
             print("<img src=\"images/lock.gif\">");
        }
        print("</td>");

        if (is_dir($filepath)) {
            $filesize = "-";
        } else {
            $filesize = filesize($filepath);
        }
        print("<td>");
        print("$filesize");
        print("</td>");

        if (is_dir($filepath)) {
            $filetype = "$strFolderType";
        } else {
            $filetype = "$strFileType";
        }
        print("<td>");
        print("$filetype");
        print("</td>");

        print("<td>");
        $fileatime = fileatime($filepath);
        printf("%s",strftime("%m-%d-%Y %H:%M:%S", $fileatime));
        print("</td>");

        print("<td>");
        file_edit_function($filepath);
        print("</td>");
        print("</tr>");
    }
    print("</table>");
}

function file_view_sicon($fileList)
{
    global $strName,$strSize,$strType,$strMDate,$strOP,$strFolderType,$strFileType;

    $fnum = count($fileList);
    $count = 0;

    print("<table border=1 cellPadding=2 cellSpacing=0 width=100% bordercolorlight=\"#aa77aa\" bordercolordark=\"#fffff0\">");
    print("<tr>");
    print("<td bgcolor=\"#EEEBDB\">-</td>");
    print("<td bgcolor=\"#EEEBDB\">-</td>");
    print("<td bgcolor=\"#EEEBDB\">-</td>");
    print("</tr>");
    print("<tr>");

    for ($i=0;$i < $fnum;$i++) {
        $filepath = $fileList[$i];
        $file = basename($filepath);

        if (($count % 3) == 0) print("<tr>");
        print("<td>");
        $theroot = DIR_DOCUMENT_ROOT;
        $urlpath = str_replace($theroot,"",$filepath);
        $url_filepath = urlencode($filepath);
        if (is_dir($filepath)) {
            if (is_readable($filepath)) {
                print("<a href=\"main.php3?currentdir=$filepath\">");

                file_view_a_sicon($filepath);
                print("$file");
                print("</a>");
            } else {
                file_view_a_sicon($filepath);
                print("$file");
            }
        } else {
            if (is_file($filepath) && (is_readable($filepath))) {
                print("<a href=\"$urlpath\">");
                file_view_a_sicon($filepath);
                print("$file");
                print("</a>");
            } else {
                file_view_a_sicon($filepath);
                print("$file");
            }
        }
        if (!is_writable($filepath)) {
             print("<img src=\"images/lock.gif\">");
        }
        print("<hr>");
        file_edit_function($filepath);
        print("</td>");
        if (($count % 3) == 2) print("</tr>");
        $count++;
    }
    if (($count % 3) != 0) print("</tr>");
    print("</table>");
}

function file_view_bicon($fileList)
{
    global $strName,$strSize,$strType,$strMDate,$strOP,$strFolderType,$strFileType;

    $fnum = count($fileList);
    $count = 0;

    print("<table border=1 cellPadding=2 cellSpacing=0 width=100% bordercolorlight=\"#aa77aa\" bordercolordark=\"#fffff0\">");

    print("<tr>");
    print("<td bgcolor=\"#EEEBDB\">-</td>");
    print("<td bgcolor=\"#EEEBDB\">-</td>");
    print("<td bgcolor=\"#EEEBDB\">-</td>");
    print("</tr>");

    print("<tr>");
    for ($i=0;$i < $fnum;$i++) {
        $filepath = $fileList[$i];
        $file = basename($filepath);

        if (($count % 3) == 0) print("<tr>");
        print("<td>");
        $theroot = DIR_DOCUMENT_ROOT;
        $urlpath = str_replace($theroot,"",$filepath);
        $url_filepath = urlencode($filepath);
        if (is_dir($filepath)) {
            if (is_readable($filepath)) {
                print("<a href=\"main.php3?currentdir=$filepath\">");
                file_view_a_bicon($filepath);
                print("<br>");
                print("$file");
                print("</a>");
            } else {
                file_view_a_bicon($filepath);
                print("<br>");
                print("$file");
            }
        } else {
            if (is_file($filepath) && (is_readable($filepath))) {
                print("<a href=\"$urlpath\">");
                file_view_a_bicon($filepath);
                print("<br>");
                print("$file");
                print("</a>");
            } else {
                file_view_a_bicon($filepath);
                print("<br>");
                file_view_a_sicon($filepath);
                print("$file");
            }
        }
        if (!is_writable($filepath)) {
             print("<img src=\"images/lock.gif\">");
        }

        print("<hr>");
        file_edit_function($filepath);
        print("</td>");

        if (($count % 3) == 2) print("</tr>");
        $count++;
    }
    if (($count % 3) != 0) print("</tr>");
    print("</table>");
}

function file_view_a_ssicon($filepath)
{
    $theroot = DIR_DOCUMENT_ROOT;

    $urlpath = str_replace($theroot,"",$filepath);
    if (is_dir($filepath)) {
        print("<img src=\"images/closedir.gif\" vspace=0 hspace=0 border=0>");
    } else {
        if (is_readable($filepath) && (filesize($filepath) > 0))
             $imgsize = GetImageSize($filepath);
        else $imagesize = array();
        //if (is_readable($filepath)) $imgsize = GetImageSize($filepath);
        if (($imgsize[0] != 0) && ($imgsize[1] != 0)) {
            $swidth = $imgsize[0];
            $sheight = $imgsize[1];
            if (($swidth <= 16) && ($sheight <= 16)) {
                $width = $swidth;
                $height = $sheight;
                $hspace = (16-$width)/2;
                $vspace = (16-$height)/2;
            } else if ($swidth > $sheight) {
                $scale = 16.0/(float)$swidth;
                $width = (int)($scale * $swidth);
                $height = (int)($scale * $sheight);
                $hspace = 0;
                $vspace = (16-$height)/2;
            } else {
                $scale = 16.0/(float)$sheight;
                $width = (int)($scale * $swidth);
                $height = (int)($scale * $sheight);
                $hspace = (16-$width)/2;
                $vspace = 0;
            }

            print("<img src=\"$urlpath\" height=$height width=$width vspace=$vspace hspace=$hspace border=0>");
        } else {
            print("<img src=\"images/file.gif\" vspace=0 hspace=0 border=0>");
        }
    }
}

function file_view_a_sicon($filepath)
{
    $theroot = DIR_DOCUMENT_ROOT;

    $urlpath = str_replace($theroot,"",$filepath);
    if (is_dir($filepath)) {
        print("<img src=\"images/bfolder.gif\" vspace=0 hspace=0 border=0>");
    } else {
        if (is_readable($filepath) && (filesize($filepath) > 0))
             $imgsize = GetImageSize($filepath);
        else $imagesize = array();
        //if (is_readable($filepath)) $imgsize = GetImageSize($filepath);
        if (($imgsize[0] != 0) && ($imgsize[1] != 0)) {
            $swidth = $imgsize[0];
            $sheight = $imgsize[1];
            if (($swidth <= 32) && ($sheight <= 32)) {
                $width = $swidth;
                $height = $sheight;
                $hspace = (32-$width)/2;
                $vspace = (32-$height)/2;
            } else if ($swidth > $sheight) {
                $scale = 32.0/(float)$swidth;
                $width = (int)($scale * $swidth);
                $height = (int)($scale * $sheight);
                $hspace = 0;
                $vspace = (32-$height)/2;
            } else {
                $scale = 32.0/(float)$sheight;
                $width = (int)($scale * $swidth);
                $height = (int)($scale * $sheight);
                $hspace = (32-$width)/2;
                $vspace = 0;
            }
            print("<img src=\"$urlpath\" height=$height width=$width vspace=$vspace hspace=$hspace border=0>");
        } else {
            print("<img src=\"images/bfile.gif\" vspace=0 hspace=0 border=0>");
        }
    }
}

function file_view_a_bicon($filepath)
{
    $theroot = DIR_DOCUMENT_ROOT;
    $urlpath = str_replace($theroot,"",$filepath);
    if (is_dir($filepath)) {
        print("<img src=\"images/bfolder.gif\" vspace=16 hspace=16 border=0>");
    } else {
        if (is_readable($filepath) && (filesize($filepath) > 0))
             $imgsize = GetImageSize($filepath);
        else $imagesize = array();
        //if (is_readable($filepath)) $imgsize = GetImageSize($filepath);
        if (($imgsize[0] != 0) && ($imgsize[1] != 0)) {
            $swidth = $imgsize[0];
            $sheight = $imgsize[1];
            if (($swidth <= 64) && ($sheight <= 64)) {
                $width = $swidth;
                $height = $sheight;
                $hspace = (64-$width)/2;
                $vspace = (64-$height)/2;
            } else if ($swidth > $sheight) {
                $scale = 64.0/(float)$swidth;
                $width = (int)($scale * $swidth + 0.5);
                $height = (int)($scale * $sheight + 0.5);
                $hspace = 0;
                $vspace = (64-$height)/2;
            } else {
                $scale = 64.0/(float)$sheight;
                $width = (int)($scale * $swidth + 0.5);
                $height = (int)($scale * $sheight + 0.5);
                $hspace = (64-$width)/2;
                $vspace = 0;
            }

            print("<img src=\"$urlpath\" height=$height width=$width vspace=$vspace hspace=$hspace border=0>");
        } else {
            print("<img src=\"images/bfile.gif\" vspace=16 hspace=16 border=0>");
        }
    }
}

function file_edit_function($filepath)
{
    global $strRename,$strOpen,$strView,$strEdit,$strUpLoad,$strDelete;

    $theroot = DIR_DOCUMENT_ROOT;
    $urlpath = str_replace($theroot,"",$filepath);
    $url_filepath = urlencode($filepath);

    if (is_writable($filepath)) {
        print("<input type=\"image\" src=\"images/file_rename.gif\" alt=\"$strRename\" align=absmiddle hspace=2 vspace=2 border=0 onClick=\"win('opwin',300,300,'op_rename.php3?filepath=$url_filepath')\">");
    }
    if (is_dir($filepath)) {
        if (is_readable($filepath)) {
            print("<a href=\"main.php3?currentdir=$url_filepath\"><img src=\"images/folder_open.gif\" alt=\"$strOpen\" onclick=\"parent.nav.window.location='left.php3?currentdir=$filepath'\" align=absmiddle hspace=2 vspace=2 border=0></a>");

        }
    } else {
        if (is_file($filepath) && (is_readable($filepath))) {
            print("<a href=\"$urlpath\"><img src=\"images/file_open.gif\" alt=\"$strView\" align=absmiddle hspace=2 vspace=2 border=0></a>");
        }
    }
    if (is_file($filepath) && (is_writable($filepath))) {
        print("<input type=\"image\" src=\"images/edit_reg.gif\" alt=\"$strEdit\" align=absmiddle hspace=2 vspace=2 border=0 onClick=\"win2('',0,0,'op_edit.php3?language=$language&filepath=$url_filepath')\">");
    }
    if (is_file($filepath) && (is_readable($filepath))) {
        print("<input type=\"image\" src=\"images/print.gif\" alt=\"$strEdit\" align=absmiddle hspace=2 vspace=2 border=0 onClick=\"win2('',0,0,'op_print.php3?language=$language&filepath=$url_filepath')\">");
    }
    if (is_file($filepath) && is_writable($filepath)) {
        print("<input type=\"image\" src=\"images/upload.gif\" alt=\"$strUpLoad\" align=absmiddle hspace=2 vspace=2 border=0 onClick=\"win('opwin',300,300,'op_upfile.php3?filepath=$url_filepath')\">");
    }
    if (is_writable($filepath)) {
        print("<input type=\"image\" src=\"images/file_delete.gif\" alt=\"$strDelete\" align=absmiddle hspace=2 vspace=2 border=0 onClick=\"win('opwin',300,300,'op_delete.php3?filepath=$url_filepath')\">");
    }
}
?>
Return current item: PHP Site Editor