Пример #1
0
function get_attachments($entity, $id, $ops = array())
{
    global $TPL;
    $rows = array();
    $dir = ATTACHMENTS_DIR . $entity . DIRECTORY_SEPARATOR . $id;
    if (isset($id)) {
        #if (!is_dir($dir)) {
        #mkdir($dir, 0777);
        #}
        if (is_dir($dir)) {
            $handle = opendir($dir);
            // TODO add icons to files attachaments in general
            while (false !== ($file = readdir($handle))) {
                clearstatcache();
                if ($file != "." && $file != "..") {
                    $image = get_file_type_image($dir . DIRECTORY_SEPARATOR . $file);
                    $row["size"] = get_filesize_label($dir . DIRECTORY_SEPARATOR . $file);
                    $row["path"] = $dir . DIRECTORY_SEPARATOR . $file;
                    $row["file"] = "<a href=\"" . $TPL["url_alloc_getDoc"] . "id=" . $id . "&entity=" . $entity . "&file=" . urlencode($file) . "\">" . $image . $ops["sep"] . page::htmlentities($file) . "</a>";
                    $row["text"] = page::htmlentities($file);
                    #$row["delete"] = "<a href=\"".$TPL["url_alloc_delDoc"]."id=".$id."&entity=".$entity."&file=".urlencode($file)."\">Delete</a>";
                    $row["delete"] = "<form action=\"" . $TPL["url_alloc_delDoc"] . "\" method=\"post\">\n                            <input type=\"hidden\" name=\"id\" value=\"" . $id . "\">\n                            <input type=\"hidden\" name=\"file\" value=\"" . $file . "\">\n                            <input type=\"hidden\" name=\"entity\" value=\"" . $entity . "\">\n                            <input type=\"hidden\" name=\"sbs_link\" value=\"attachments\">\n                            <input type=\"hidden\" name=\"sessID\" value=\"{$sessID}\">" . '<button type="submit" name="delete_file_attachment" value="1" class="delete_button">Delete<i class="icon-trash"></i></button>' . "</form>";
                    $row["mtime"] = date("Y-m-d H:i:s", filemtime($dir . DIRECTORY_SEPARATOR . $file));
                    $row["restore_name"] = $file;
                    $rows[] = $row;
                }
            }
            closedir($handle);
        }
        is_array($rows) && usort($rows, "sort_by_mtime");
    }
    return $rows;
}
Пример #2
0
$dont_print_these_dirs = array(".", "..", "CVS", ".hg", ".bzr", "_darcs", ".git");
// relative path
$DIR = urldecode($_POST['dir']);
// full path
$PATH = realpath(wiki_module::get_wiki_path() . $DIR) . DIRECTORY_SEPARATOR;
if (path_under_path($PATH, wiki_module::get_wiki_path()) && is_dir($PATH)) {
    $files = scandir($PATH);
    natcasesort($files);
    $str .= "\n<ul class=\"jqueryFileTree\" style=\"display: none;\">";
    // All dirs
    foreach ($files as $file) {
        if (!in_array($file, $dont_print_these_dirs) && is_dir($PATH . $file)) {
            $str .= "\n  <li class=\"directory collapsed\"><a class=\"file\" href=\"#\" rel=\"" . page::htmlentities($DIR . $file . DIRECTORY_SEPARATOR) . "\">" . page::htmlentities($file) . "</a></li>";
        }
    }
    // All files
    foreach ($files as $file) {
        if (file_exists($PATH . $file) && $file != '.' && $file != '..' && !is_dir($PATH . $file) && is_readable($PATH . $file)) {
            unset($extra);
            !is_writable($PATH . $file) and $extra = "(ro) ";
            $ext = strtolower(preg_replace('/^.*\\./', '', $file));
            $str .= "\n  <li class=\"file ext_{$ext} nobr\">";
            $str .= "\n    <a style=\"position:relative;\" class=\"file nobr\" href=\"#x\" rel=\"" . page::htmlentities($DIR . $file) . "\">" . page::htmlentities($file);
            $str .= "<div class='faint nobr' style='top:0px; position:absolute;'>" . $extra . get_filesize_label($PATH . $file) . "</div></a>";
            $str .= "\n  </li>";
        }
    }
    $str .= "\n</ul>";
    #echo "<pre>".page::htmlentities($str)."</pre>";
    echo $str;
}