function kfm_api_getDirectoryId($address) { if (!is_dir(USERBASE . '/f/' . $address)) { return 0; } $arr = explode('/', $address); $curdir = 1; if ($arr[count($arr) - 1] == '' && count($arr) > 1) { array_pop($arr); } foreach ($arr as $n) { $r = db_fetch_row("select id from " . KFM_DB_PREFIX . "directories where parent=" . $curdir . " and name='" . sql_escape($n) . "'"); if ($r === false || !count($r)) { $dir = kfmDirectory::getInstance($curdir); $curdir = $dir->addSubdirToDb($n); } else { $curdir = $r['id']; } } return $curdir; }
function kfm_getCssSprites($id = 0) { $id = (int) $id; if ($id < 1) { $id = 1; } $dir = kfmDirectory::getInstance($id); return $dir->getCssSprites(); }
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++; } } }
/** * Moves the file * @param int $new_directoryparent_id */ function move($dir_id) { global $kfmdb, $kfm; if ($dir_id == $kfm->setting('root_folder_id') && !$kfm->setting('allow_files_in_root')) { return $this->error('Cannot move files to the root directory'); } if (!$this->writable) { return $this->error(kfm_lang('fileNotMovableUnwritable', $this->name)); } $dir = kfmDirectory::getInstance($dir_id); if (!$dir) { return $this->error(kfm_lang('failedGetDirectoryObject')); } if (!rename($this->path, $dir->path() . '/' . $this->name)) { return $this->error(kfm_lang('failedMoveFile', $this->name)); } $q = $kfmdb->query("update " . KFM_DB_PREFIX . "files set directory=" . $dir_id . " where id=" . $this->id); }
function rename($newname) { global $kfm, $kfmDirectoryInstances; if (!$kfm->setting('allow_directory_edit')) { return $this->error(kfm_lang('permissionDeniedEditDirectory')); } if ($this->isLink()) { return $this->error(kfm_lang('cannotRenameLink')); } if (!$this->isWritable()) { return $this->error(kfm_lang('permissionDeniedRename', $this->name)); } if (!$this->checkName($newname)) { return $this->error(kfm_lang('cannotRenameFromTo', $this->name, $newname)); } $parent = kfmDirectory::getInstance($this->pid); if (file_exists($parent->path() . $newname)) { return $this->error(kfm_lang('aDirectoryNamedAlreadyExists', $newname)); } rename(rtrim($this->path(), ' /'), file_join($parent->path(), rtrim($newname, ' /'))); if (file_exists($this->path())) { return $this->error(kfm_lang('failedRenameDirectory')); } $kfm->db->query("update " . KFM_DB_PREFIX . "directories set name='" . sql_escape($newname) . "' where id=" . $this->id); $this->name = $newname; $this->cached_path = $this->path(); $kfmDirectoryInstances[$this->id] = $this; }
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); }
* @author Kae Verens <*****@*****.**> * @author Benjamin ter Kuile <*****@*****.**> * @license docs/license.txt for licensing * @link http://kfm.verens.com/ */ require_once 'initialise.php'; $errors = array(); if ($kfm_allow_file_upload) { $file = isset($_FILES['kfm_file']) ? $_FILES['kfm_file'] : $_FILES['Filedata']; $filename = $file['name']; $tmpname = $file['tmp_name']; $cwd = $kfm_session->get('cwd_id'); if (!$cwd) { $errors[] = kfm_lang('CWD not set'); } else { $toDir = kfmDirectory::getInstance($cwd); $to = $toDir->path . '/' . $filename; if (!is_file($tmpname)) { $errors[] = 'No file uploaded'; } else { if (!kfmFile::checkName($filename)) { $errors[] = 'The filename: ' . $filename . ' is not allowed'; } } } if ($cwd == 1 && !$kfm_allow_files_in_root) { $errors[] = 'Cannot upload files to the root directory'; } if (file_exists($to)) { $errors[] = 'File already exists'; }
$parts = count($uri2) > 1 ? explode('&', $uri2[1]) : array(); foreach ($parts as $part) { $arr = explode('=', $part); if (!(count($arr) > 1)) { continue; } list($varname, $varval) = $arr; $_GET[$varname] = urldecode($varval); } // } if (isset($_GET['uri'])) { $bits = explode('/', $_GET['uri']); $fname = array_pop($bits); $dir = 0; $dirs = explode(DIRECTORY_SEPARATOR, trim(join('/', $bits), ' ' . DIRECTORY_SEPARATOR)); $subdir = kfmDirectory::getInstance(1); $startup_sequence_array = array(); foreach ($dirs as $dirname) { $subdir = $subdir->getSubdir($dirname); if (!$subdir) { break; } $dir = $subdir->id; } foreach ($subdir->getFiles() as $file) { if ($file->name == $fname) { $_GET['id'] = $file->id; break; } } }
function rename($newname) { global $kfm, $kfm_allow_directory_edit, $kfmDirectoryInstances; if (!$GLOBALS['kfm_allow_directory_edit']) { return $this->error(kfm_lang('permissionDeniedEditDirectory')); } if (!$this->isWritable()) { return $this->error(kfm_lang('permissionDeniedRename', $this->name)); } if (!$this->checkAddr($newname)) { return $this->error(kfm_lang('cannotRenameFromTo', $this->name, $newname)); } $parent = kfmDirectory::getInstance($this->pid); if (file_exists($parent->path . $newname)) { return $this->error(kfm_lang('aDirectoryNamedAlreadyExists', $newname)); } rename($this->path, $parent->path . $newname); if (file_exists($this->path)) { return $this->error(kfm_lang('failedRenameDirectory')); } $kfm->db->query("update " . KFM_DB_PREFIX . "directories set name='" . sql_escape($newname) . "' where id=" . $this->id); $this->name = $newname; $this->path = $this->getPath(); $kfmDirectoryInstances[$this->id] = $this; }
/** * KFM - Kae's File Manager - index page * * @category None * @package None * @author Kae Verens <*****@*****.**> * @author Benjamin ter Kuile <*****@*****.**> * @license docs/license.txt for licensing * @link http://kfm.verens.com/ */ // {{{ setup error_reporting(E_ALL); require_once 'initialise.php'; require_once KFM_BASE_PATH . 'includes/kaejax.php'; $kfm_session->set('kfm_url', dirname(!empty($_SERVER['HTTPS']) ? "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] : "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']) . DIRECTORY_SEPARATOR); $kfm_root_dir = kfmDirectory::getInstance(1); if ($kfm_user_root_folder) { $dirs = explode(DIRECTORY_SEPARATOR, trim($kfm_user_root_folder, ' ' . DIRECTORY_SEPARATOR)); $subdir = $kfm_root_dir; foreach ($dirs as $dirname) { $subdir = $subdir->getSubdir($dirname); if (!$subdir) { die('Error: Root directory cannot be found in the database.'); } $kfm_root_folder_id = $subdir->id; } $user_root_dir = $subdir; } else { $user_root_dir = $kfm_root_dir; } $kfm_root_folder_id = $user_root_dir->id;
$file = kfmFile::getInstance($id); if ($file) { $file->delete(); echo 'ok'; exit; } else { die('file does not exist'); } break; // } // } case 'prune': // { global $kfm; $root_id = $kfm->setting('root_folder_id'); $root_directory = kfmDirectory::getInstance($root_id); kfm_prune($root_directory); break; // } // } case 'change_caption': // { $id = $_REQUEST['id']; $caption = $_REQUEST['caption']; kfm_editCaption($id, $caption); break; // } } function kfm_prune($dir) { global $root_id;
} echo 'Creating image directory '; $parent_id = kfm_api_getDirectoryId('products'); _createDirectory($parent_id, 'product-images'); } $pos = strrpos($_REQUEST['images_directory'], '/'); if ($pos === false) { $dname .= $_REQUEST['images_directory']; } else { $dname = substr($_REQUEST['images_directory'], $pos + 1); } if (strlen($dname) == 0) { $dname = rand() . microtime(); } $parent_id = kfm_api_getDirectoryId('products/product-images'); $parent = kfmDirectory::getInstance($parent_id); $parent->createSubdir($dname); } // } // { save main data and data fields $sql = 'set name="' . addslashes($_REQUEST['name']) . '"' . ',link="' . addslashes(transcribe(__FromJson($_REQUEST['name'], true))) . '"' . ',ean="' . addslashes(@$_REQUEST['ean']) . '"' . ',user_id=' . (int) @$_REQUEST['user_id'] . ',stock_number="' . addslashes($_REQUEST['stock_number']) . '"' . ',activates_on="' . addslashes($_REQUEST['activates_on']) . '"' . ',expires_on="' . addslashes($_REQUEST['expires_on']) . '"' . ',product_type_id=' . (int) $_REQUEST['product_type_id'] . ',default_category=' . (int) $_REQUEST['products_default_category'] . ',enabled=' . (int) $_REQUEST['enabled'] . ',date_edited=now()' . ', num_of_categories=' . count($_REQUEST['product_categories']) . ',location=' . (int) $_REQUEST['location'] . ',images_directory="' . addslashes($_REQUEST['images_directory']) . '"'; foreach ($_REQUEST['productsExtra'] as $k => $v) { $sql .= ', `' . addslashes($k) . '`="' . addslashes($v) . '"'; } // { add data fields to SQL $datafields = array(); if (!isset($_REQUEST['data_fields'])) { $_REQUEST['data_fields'] = array(); } foreach ($_REQUEST['data_fields'] as $n => $v) { $datafields[] = array('n' => $n, 'v' => is_array($v) ? json_encode($v) : $v);