/**
 * Get an html visual list of files and subdirs
 * @author Nicola Asuni
 * @param $dir (string) the starting directory path
 * @param $selected (string) the selected file
 * @param $params (string) additional parameters to add on links
 * @return html table
 */
function F_getDirVisualTable($dir, $selected = '', $params = '')
{
    global $l;
    require_once '../config/tce_config.php';
    $imgformats = array('gif', 'jpg', 'jpeg', 'png', 'svg');
    $allowed_extensions = unserialize(K_ALLOWED_UPLOAD_EXTENSIONS);
    $out = '';
    // html string to be returned
    $data = F_getDirFiles($dir);
    // dirs
    foreach ($data['dirs'] as $file) {
        $info = F_getFileInfo($file);
        $current_dir = urlencode($dir . $info['basename'] . '/');
        $out .= '<table style="float:left;border:none;margin:1px;padding:0;width:158px;background-color:#007fff;">';
        $out .= '<tr style="height:16px;font-family:monospace;font-size:12px;font-weight:bold;color:white;"><th>';
        $filename = $info['basename'];
        if (strlen($filename) > 20) {
            $filename = substr($filename, 0, 20) . '...';
        }
        $out .= $filename;
        $out .= '</th></tr>';
        $out .= '<tr style="height:160px;"><td style="text-align:center;vertical-align:middle;background-color:white;">';
        $out .= '<a href="' . $_SERVER['SCRIPT_NAME'] . '?d=' . $current_dir . '&amp;v=0' . $params . '" title="' . $l['w_change_dir'] . ' : ' . $info['basename'] . '" style="text-decoration:underline;"><img src="' . K_PATH_IMAGES . 'dir.png" width="50" height="50" alt="' . $l['w_change_dir'] . ' : ' . $info['basename'] . '" style="border:none;" /></a>';
        $out .= '</td></tr>';
        $out .= '</table>';
    }
    // files
    $current_dir = urlencode($dir);
    foreach ($data['files'] as $file) {
        $info = F_getFileInfo($file);
        if (isset($info['extension']) and in_array(strtolower($info['extension']), $allowed_extensions) and substr($info['basename'], 0, 6) != 'latex_') {
            $current_file = urlencode($dir . $info['basename']);
            if ($info['basename'] == $selected) {
                $bgcolor = '#009900';
            } else {
                $bgcolor = '#333333';
            }
            if (in_array(strtolower($info['extension']), $imgformats)) {
                $w = 150;
                $h = 150;
                $imgicon = F_objects_replacement($info['tcename'], $info['extension'], 0, 0, $l['w_preview'], $w, $h);
            } else {
                $imgicon = '<img src="' . K_PATH_IMAGES . 'file.png" width="39" height="50" alt="' . $l['w_select'] . ' : ' . $info['basename'] . ' (' . F_formatFileSize($info['size']) . ')' . '" style="border:none;" />';
            }
            $out .= '<table style="float:left;border:none;margin:1px;padding:0;width:158px;background-color:' . $bgcolor . ';">';
            $out .= '<tr style="height:16px;font-family:monospace;font-size:12px;color:white;"><th>';
            $filename = $info['basename'];
            if (strlen($filename) > 20) {
                $filename = substr(substr($filename, 0, -(strlen($info['extension']) + 1)), 0, 15) . '&rarr;.' . $info['extension'];
            }
            $out .= $filename;
            $out .= '</th></tr>';
            $out .= '<tr style="height:160px;"><td style="text-align:center;vertical-align:middle;background-color:white;">';
            $out .= '<a href="' . $_SERVER['SCRIPT_NAME'] . '?d=' . $current_dir . '&amp;f=' . urlencode($current_file) . '&amp;v=0' . $params . '" title="' . $l['w_select'] . ' : ' . $info['basename'] . ' (' . F_formatFileSize($info['size']) . ')' . '">' . $imgicon . '</a>';
            $out .= '</td></tr>';
            $out .= '</table>';
        }
    }
    $out .= '<br style="clear:both;" />';
    return $out;
}
Example #2
0
}
//end of switch
echo '<div class="container">' . K_NEWLINE;
echo '<div class="contentbox">' . K_NEWLINE;
echo '<form action="' . $_SERVER['SCRIPT_NAME'] . '" method="post" enctype="multipart/form-data" id="form_filemanager">' . K_NEWLINE;
echo '<div>' . K_NEWLINE;
echo '<input type="hidden" name="frm" id="frm" value="' . $callingform . '" />' . K_NEWLINE;
echo '<input type="hidden" name="fld" id="fld" value="' . $callingfield . '" />' . K_NEWLINE;
// current dir
echo '<input type="hidden" name="d" id="d" value="' . $dir . '" />' . K_NEWLINE;
echo '<fieldset>' . K_NEWLINE;
echo '<legend title="' . $l['w_action'] . '">' . $l['w_action'] . '</legend>' . K_NEWLINE;
if (!empty($file)) {
    // file mode
    // preview
    $filedata = F_getFileInfo($file);
    $w = 500;
    $h = 250;
    echo F_objects_replacement($filedata['tcename'], $filedata['extension'], 0, 0, $l['w_preview'], $w, $h);
    echo '<br />' . K_NEWLINE;
    // display basic info
    echo '<span style="font-size:80%;color:#333333;">' . $w . ' x ' . $h . ' px ( ' . F_formatFileSize($filedata['size']) . ' ) ' . $filedata['lastmod'] . '</span>';
    echo '<br />' . K_NEWLINE;
    // action buttons
    echo '<input type="hidden" name="file" id="file" value="' . $file . '" />' . K_NEWLINE;
    echo '<input type="hidden" name="tcefile" id="tcefile" value="' . $filedata['tcefile'] . '" />' . K_NEWLINE;
    echo '<input type="text" name="newname" id="newname" value="' . basename($file) . '" size="30" maxlength="255" title="' . $l['w_name'] . '" />' . K_NEWLINE;
    if ($_SESSION['session_user_level'] >= K_AUTH_RENAME_MEDIAFILE) {
        F_submit_button('rename', $l['w_rename'], $l['w_rename']);
    }
    if ($_SESSION['session_user_level'] >= K_AUTH_DELETE_MEDIAFILE) {