/** * Implementation of hook_dirlist. */ function ft_fileinfo_dirlist() { global $ft; $sql = 'SELECT name, description FROM fileinfo WHERE dir = ' . sqlite_escape_string(ft_get_dir()); $result = sqlite_query($ft['db']['link'], $sql); if ($result) { while ($entry = sqlite_fetch_array($query, SQLITE_ASSOC)) { $ft['fileinfo']['descriptions'][$entry['file']] = $entry['description']; } } }
/** * Implementation of hook_ajax. */ function ft_search_ajax($act) { if ($act == 'search') { $new = array(); $ret = ""; $q = $_POST['q']; $type = $_POST['type']; if (!empty($q)) { if ($type == "true") { $list = _ft_search_find_files(ft_get_dir(), $q); } else { $list = _ft_search_find_files(ft_get_root(), $q); } if (is_array($list)) { if (count($list) > 0) { foreach ($list as $c) { if (empty($c['dir'])) { $c['dirlink'] = "/"; } else { $c['dirlink'] = $c['dir']; } if ($c['type'] == "file") { $link = "<a href='" . ft_get_root() . "{$c['dir']}/{$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($c['dir']) . '&file=' . $c['name'], t('Show !file', array('!file' => $c['name']))); } $ret .= "<dt>{$link}</dt><dd>" . ft_make_link($c['dirlink'], "dir=" . rawurlencode($c['dir']) . "&highlight=" . rawurlencode($c['name']) . "&q=" . rawurlencode($q), t("Highlight file in directory")) . "</dd>"; } else { $ret .= "<dt class='dir'>" . ft_make_link($c['shortname'], "dir=" . rawurlencode("{$c['dir']}/{$c['name']}") . "&q={$q}", t("Show files in !folder", array('!folder' => $c['name']))) . "</dt><dd>" . ft_make_link($c['dirlink'], "dir=" . rawurlencode($c['dir']) . "&highlight=" . rawurlencode($c['name']) . "&q=" . rawurlencode($q), t("Highlight file in directory")) . "</dd>"; } } return $ret; } else { return "<dt class='error'>" . t('No files found') . ".</dt>"; } } else { return "<dt class='error'>" . t('Error.') . "</dt>"; } } else { return "<dt class='error'>" . t('Enter a search string.') . "</dt>"; } } }
/** * Implementation of hook_page. * Zip current file/folder */ function ft_zip_page($act) { global $ft; if ($act == 'zip') { $_REQUEST['file'] = trim(ft_stripslashes($_REQUEST['file'])); // nom de fichier/repertoire $zip = new zipfile(); if ($ft["plugins"]["zip"]["filebuffer"]) { $zip->setOutFile($ft["plugins"]["zip"]["filebuffer"]); } $substr_base = strlen(ft_get_dir()) + 1; foreach (ft_zip_getfiles(ft_get_dir() . '/' . $_REQUEST['file']) as $file) { $filename = substr($file, $substr_base); $filesize = filesize($file); if ($filesize > 0) { $fp = fopen($file, 'r'); $content = fread($fp, $filesize); fclose($fp); } else { $content = ''; } $zip->addfile($content, $filename); } if ($ft["plugins"]["zip"]["filebuffer"]) { $zip->finish(); $filesize = filesize($ft["plugins"]["zip"]["filebuffer"]); } else { $archive = $zip->file(); $filesize = strlen($archive); } header('Content-Type: application/x-zip'); header('Content-Disposition: inline; filename="' . $_REQUEST['file'] . '.zip"'); header('Content-Length: ' . $filesize); if ($ft["plugins"]["zip"]["filebuffer"]) { readfile($ft["plugins"]["zip"]["filebuffer"]); unlink($ft["plugins"]["zip"]["filebuffer"]); } else { echo $archive; } exit; } }
/** * Create HTML for sidebar. */ function ft_make_sidebar() { $str = '<div id="sidebar">'; // $status = ''; // if (ft_check_upload() === TRUE && is_writeable(ft_get_dir()) && (LIMIT > 0 && LIMIT < ROOTDIRSIZE)) { // $status = '<p class="alarm">' . 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'><h2>".t('Results')."</h2>{$status}</div>"; // } if (ft_check_upload() === TRUE && is_writeable(ft_get_dir())) { if (LIMIT <= 0 || LIMIT > ROOTDIRSIZE) { $str .= ' <div class="section" id="create"> <h2>' . t('Upload files') . '</h2> <form action="' . ft_get_self() . '" method="post" enctype="multipart/form-data"> <div id="uploadsection"> <input type="hidden" name="MAX_FILE_SIZE" value="' . MAXSIZE . '" /> <input type="file" class="upload" name="localfile" id="localfile-0" size="12" /> <input type="hidden" name="act" value="upload" /> <input type="hidden" name="dir" value="' . $_REQUEST['dir'] . '" /> </div> <div id="uploadbutton"> <input type="submit" name="submit" value="' . t('Upload') . '" /> </div> <div class="info">' . t('Max:') . ' <strong>' . ft_get_max_upload() . ' / ' . ft_get_nice_filesize(ft_get_bytes(ini_get('upload_max_filesize')) < ft_get_bytes(ini_get('post_max_size')) ? ft_get_bytes(ini_get('upload_max_filesize')) : ft_get_bytes(ini_get('post_max_size'))) . '</strong></div> <div style="clear:both;"></div> </form> </div>'; } } if (CREATE) { $str .= ' <div class="section" id="new"> <h2>' . t('Create folder') . '</h2> <form action="' . ft_get_self() . '" method="post"> <div> <input type="radio" name="type" value="folder" id="type-folder" checked="checked" /> <label for="type-folder" class="label_highlight">' . t('Folder') . '</label> <input type="radio" name="type" value="file" id="type-file" /> <label for="type-file">' . t('File') . '</label> <input type="radio" name="type" value="url" id="type-url" /> <label for="type-url">' . t('From URL') . '</label> </div> <div> <input type="text" name="newdir" id="newdir" size="16" /> <input type="hidden" name="act" value="createdir" /> <input type="hidden" name="dir" value="' . $_REQUEST['dir'] . '" /> <input type="submit" id="mkdirsubmit" name="submit" value="' . t('Ok') . '" /> </div> </form> </div>'; } $sidebar = array(); $result = ft_invoke_hook('sidebar'); $sidebar = array_merge($sidebar, $result); if (is_array($sidebar)) { foreach ($sidebar as $c) { $str .= $c['content']; } } $str .= '</div>'; 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.'; } }