/** * Create HTML for the page body. Defaults to a file list. */ function ft_make_body() { $str = ""; // Make system messages. $status = ''; if (ft_check_upload() === TRUE && is_writeable(ft_get_dir()) && (LIMIT > 0 && LIMIT < ROOTDIRSIZE)) { $status = '<p class="error">' . t('Upload disabled. Total disk space use of !size exceeds the limit of !limit.', array('!limit' => ft_get_nice_filesize(LIMIT), '!size' => ft_get_nice_filesize(ROOTDIRSIZE))) . '</p>'; } $status .= ft_make_messages(); if (empty($status)) { $str .= "<div id='status' class='hidden'></div>"; } else { $str .= "<div id='status' class='section'>{$status}</div>"; } // Invoke page hook if an action has been set. if (!empty($_REQUEST['act'])) { return $str . '<div id="main">' . implode("\r\n", ft_invoke_hook('page', $_REQUEST['act'])) . '</div>'; } // If no action has been set, show a list of files. if (empty($_REQUEST['act']) && (empty($_REQUEST['status']) || $_REQUEST['status'] != "dirfail")) { // No action set - we show a list of files if directory has been proven openable. $totalsize = 0; // Set sorting type. Default to 'name'. $sort = 'name'; $cookie_mutex = str_replace('.', '_', MUTEX); // If there's a GET value, use that. if (!empty($_GET['sort'])) { // Set the cookie. setcookie('ft_sort_' . MUTEX, $_GET['sort'], time() + 60 * 60 * 24 * 365); $sort = $_GET['sort']; } elseif (!empty($_COOKIE['ft_sort_' . $cookie_mutex])) { // There's a cookie, we'll use that. $sort = $_COOKIE['ft_sort_' . $cookie_mutex]; } $files = ft_get_filelist(ft_get_dir(), $sort); if (!is_array($files)) { // List couldn't be fetched. Throw error. // ft_set_message(t("Could not open directory."), 'error'); // ft_redirect(); $str .= '<p class="error">' . t("Could not open directory.") . '</p>'; } else { // Show list of files in a table. $colspan = 3; if (SHOWDATES) { $colspan = 4; } $str .= "<table id='filelist'>"; $str .= "<thead><tr><th colspan=\"{$colspan}\"><div style='float:left;'>" . t('Files') . "</div>"; $str .= "<form action='" . ft_get_self() . "' id='sort_form' method='get'><div><!--<label for='sort'>Sort by: </label>--><select id='sort' name='sort'>"; $sorttypes = array('name' => t('Sort by name'), 'size' => t('Sort by size'), 'type' => t('Sort by type'), 'date' => t('Sort by date')); foreach ($sorttypes as $k => $v) { $str .= "<option value='{$k}'"; if ($sort == $k) { $str .= " selected='selected'"; } $str .= ">{$v}</option>"; } $str .= "</select><input type=\"hidden\" name=\"dir\" value=\"" . $_REQUEST['dir'] . "\" /></div></form></th>"; $str .= "</tr></thead>"; $str .= "<tbody>"; $countfiles = 0; $countfolders = 0; if (count($files) <= 0) { $str .= "<tr><td colspan='{$colspan}' class='error'>" . t('Directory is empty.') . "</td></tr>"; } else { $i = 0; $previous = $files[0]['type']; foreach ($files as $c) { $odd = ""; $class = ''; if ($c['writeable']) { $class = "show writeable "; } if ($c['type'] == 'dir' && $c['size'] == 0) { $class .= " empty"; } // Loop through extras and set classes. foreach ($c['extras'] as $extra) { $class .= " {$extra}"; } if (isset($c['perms'])) { $class .= " perm-{$c['perms']} "; } if (!empty($_GET['highlight']) && $c['name'] == $_GET['highlight']) { $class .= " highlight "; $odd = "highlight "; } if ($i % 2 != 0) { $odd .= "odd"; } if ($previous != $c['type']) { // Insert seperator. $odd .= " seperator "; } $previous = $c['type']; $str .= "<tr class='{$c['type']} {$odd}'>"; if ($c['writeable'] && ft_check_fileactions() === TRUE) { $str .= "<td class='details'><span class='{$class}'>◊</span><span class='hide' style='display:none;'>◊</span></td>"; } else { $str .= "<td class='details'>—</td>"; } $plugin_data = implode('', ft_invoke_hook('filename', $c['name'])); if ($c['type'] == "file") { $link = "<a href=\"" . ft_get_dir() . "/" . rawurlencode($c['name']) . "\" title=\"" . t('Show !file', array('!file' => $c['name'])) . "\">{$c['shortname']}</a>"; if (HIDEFILEPATHS == TRUE) { $link = ft_make_link($c['shortname'], 'method=getfile&dir=' . rawurlencode($_REQUEST['dir']) . '&file=' . $c['name'], t('Show !file', array('!file' => $c['name']))); } $str .= "<td class='name'>{$link}{$plugin_data}</td><td class='size'>" . ft_get_nice_filesize($c['size']); $countfiles++; } else { $str .= "<td class='name'>" . ft_make_link($c['shortname'], "dir=" . rawurlencode($_REQUEST['dir']) . "/" . rawurlencode($c['name']), t("Show files in !folder", array('!folder' => $c['name']))) . "{$plugin_data}</td><td class='size'>{$c['size']} " . t('files'); $countfolders++; } // Add filesize to total. if ($c['type'] == 'file') { $totalsize = $totalsize + $c['size']; } if (SHOWDATES) { if (isset($c['modified']) && $c['modified'] > 0) { $str .= "</td><td class='date'>" . date(SHOWDATES, $c['modified']) . "</td></tr>"; } else { $str .= "</td><td class='date'>—</td></tr>"; } } else { $str .= "</td></tr>"; } $i++; } } if ($totalsize == 0) { $totalsize = ''; } else { $totalsize = " (" . ft_get_nice_filesize($totalsize) . ")"; } $str .= "</tbody><tfoot><tr><td colspan=\"{$colspan}\">" . $countfolders . " " . t('folders') . " - " . $countfiles . " " . t('files') . "{$totalsize}</td></tr></tfoot>"; $str .= "</table>"; } } return $str; }
/** * Implementation of hook_ajax. */ function ft_edit_ajax($act) { if ($act == 'saveedit') { // Do save file. $file = trim(ft_stripslashes($_POST["file"])); // Check if file type can be edited. if (ft_check_dir(ft_get_dir()) && ft_check_edit($file) && ft_check_fileactions() === TRUE && ft_check_filetype($file) && ft_check_filetype($file)) { $filecontent = ft_stripslashes($_POST["filecontent"]); if ($_POST["convertspaces"] != "") { $filecontent = str_replace(" ", "\t", $filecontent); } if (is_writeable(ft_get_dir() . "/{$file}")) { $fp = @fopen(ft_get_dir() . "/{$file}", "wb"); if ($fp) { fputs($fp, $filecontent); fclose($fp); // edit echo '<p class="ok">' . t("!old was saved.", array('!old' => $file)) . '</p>'; } else { // editfilefail echo '<p class="error">' . t("!old could not be edited.", array('!old' => $file)) . '</p>'; } } else { // editfilefail echo '<p class="error">' . t("!old could not be edited.", array('!old' => $file)) . '</p>'; } } else { // edittypefail echo '<p class="error">' . t("Could not edit file. This file type is not editable.") . '</p>'; } } elseif ($act == 'edit_get_lock') { ft_edit_lock_set($_POST['file'], $_POST['dir'], $_SESSION['ft_user_' . MUTEX]); echo 'File locked.'; } }