function kfm_api_removeFile($id) { $f = kfmFile::getInstance($id); $p = $f->parent; $f->delete(); return kfm_loadFiles($p); }
$associations = db_fetch_all('SELECT extension, plugin FROM ' . KFM_DB_PREFIX . 'plugin_extensions WHERE user_id=1'); $kfm->addAssociations($associations); // To javascript object $ass_str = '{'; if (!isset($kfm->associations['all']) && isset($kfm_default_file_selection_handler)) { $kfm->associations['all'] = $kfm_default_file_selection_handler; } foreach ($kfm->associations as $ext => $plugin) { $ass_str .= '"' . $ext . '":"' . $plugin . '",'; } $ass_str = rtrim($ass_str, ', ') . '}'; // } // { startup selected files if (isset($_GET['fid']) && $_GET['fid']) { /*{*/ $f = kfmFile::getInstance($_GET['fid']); /*}*/ if ($f) { $_GET['cwd'] = $f->parent; $kfm->setting('startup_selected_files', array($_GET['fid'])); } } // } //TODO:The next section should be reviewed (benjamin: I thing $_GET['startup_folder']) should be used in stead of this. (no directory id supported) if (isset($_GET['cwd']) && (int) $_GET['cwd']) { $path = kfm_getDirectoryParentsArr($_GET['cwd']); $path[] = $_GET['cwd']; if (count($path) > 1) { $startup_sequence_array = $path; $kfm_startupfolder_id = $_GET['cwd']; $kfm_session->set('cwd_id', $kfm->setting('startupfolder_id'));
function kfm_rmMixed($files = array(), $directories = array()) { $filecount = 0; $dircount = 0; foreach ($files as $fid) { $file = kfmFile::getInstance($fid); if ($file->delete()) { $filecount++; } } foreach ($directories as $did) { $dir = new kfmDirectory($did); if ($dir->delete()) { $dircount++; } } }
<?php require 'initialise.php'; switch ($_REQUEST['action']) { case 'delete_file': // { $id = (int) $_REQUEST['id']; $file = kfmFile::getInstance($id); if ($file) { $file->delete(); echo 'ok'; exit; } else { die('file does not exist'); } // } }
function getFiles() { $filesdb = db_fetch_all("select * from " . KFM_DB_PREFIX . "files where directory=" . $this->id); $fileshash = array(); if (is_array($filesdb)) { foreach ($filesdb as $r) { $fileshash[$r['name']] = $r['id']; } } // { get files from directoryIterator, then sort them $tmp = array(); foreach (new directoryIterator($this->path()) as $f) { if ($f->isDot()) { continue; } if (is_file($this->path() . $f) && kfmFile::checkName($f)) { $tmp[] = $f . ''; } } natsort($tmp); // } // { load file details from database $files = array(); foreach ($tmp as $filename) { if (!isset($fileshash[$filename])) { $fileshash[$filename] = kfmFile::addToDb($filename, $this->id); } $file = kfmFile::getInstance($fileshash[$filename]); if (!$file) { continue; } if ($file->isImage()) { $file = kfmImage::getInstance($fileshash[$filename]); if ($this->maxWidth > 0 && $this->maxHeight > 0 && ($file->width > $this->maxWidth || $file->height > $this->maxHeight)) { $file->resize($this->maxWidth, $this->maxHeight); } } $files[] = $file; unset($fileshash[$filename]); } // } return $files; }
function _zip($filename, $files) { global $kfm_session; $cwd_id = $kfm_session->get('cwd_id'); $dir = kfmDirectory::getInstance($cwd_id); $cwd = $dir->path(); if (!$kfm->setting('allow_file_create')) { return kfm_error(kfm_lang('permissionDeniedCreateFile')); } global $rootdir; if (!kfmFile::checkName($filename)) { return kfm_error(kfm_lang('illegalFileName', $filename)); } $arr = array(); foreach ($files as $f) { $file = kfmFile::getInstance($f); if (!$file) { return kfm_error(kfm_lang('missingFileInSelection')); } $arr[] = $file->path; } # try native system zip command $res = -1; $pdir = $cwd . '/'; $zipfile = $pdir . $filename; for ($i = 0; $i < count($arr); ++$i) { $arr[$i] = str_replace($pdir, '', $arr[$i]); } exec('cd "' . escapeshellcmd($cwd) . '" && zip -D "' . escapeshellcmd($zipfile) . '" "' . join('" "', $arr) . '"', $arr, $res); if ($res) { return kfm_error(kfm_lang('noNativeZipCommand')); } return kfm_loadFiles($cwd_id); }
,charmap_default: "arrows" ,is_multi_files: true ,EA_load_callback: "load_ea_files" ,EA_file_close_callback: "close_ea_file" }); function save_document(id, content){ var f = editAreaLoader.getCurrentFile("editareacontent"); parent.x_kfm_saveTextFile(f.id, content, function(res){ editAreaLoader.setFileEditedMode("editareacontent", String(f.id), false); //parent.kfm_pluginIframeMessage('document saved'); }); } function load_ea_files(element_id){ <?php foreach ($file_ids as $fid) { $f = kfmFile::getInstance($fid); print "\n editAreaLoader.openFile('editareacontent', {id:{$fid},text:" . json_encode($f->getContent()) . ",syntax:'" . getSyntax($f->getExtension()) . "',title:'" . $f->name . "'});"; } ?> } function close_ea_file(f){ jQuery.get("remove_file.php?fid="+f.id, function(res){eval(res);}); return true; } </script> <style type="text/css"> *{ margin:0; padding:0; } </style>
function addFile($file) { if (!$GLOBALS['kfm_allow_file_create']) { return $this->error(kfm_lang('permissionDeniedCreateFile')); } if (is_numeric($file)) { $file = kfmFile::getInstance($file); } if (!$this->isWritable()) { return $this->error(kfm_lang('fileNotCreatedDirUnwritable', $file->name)); } copy($file->path, $this->path . '/' . $file->name); $id = $file->addToDb($file->name, $this->id); if ($file->isImage()) { $file = kfmImage::getInstance($file->id); $newFile = kfmImage::getInstance($id); $newFile->setCaption($file->caption); } else { $newFile = kfmFile::getInstance($id); } $newFile->setTags($file->getTags()); return true; }