ile; if (!$oldpath) wp_send_json(array('success' => false, 'message' => __("Invalid source path", "download-manager"))); if (!$newpath) wp_send_json(array('success' => false, 'message' => __("Invalid destination path", "download-manager"))); rename($oldpath, $newpath); $asset = new Asset(); $asset = $asset->get($oldpath); if ($asset) $asset->updatePath($newpath); wp_send_json(array('success' => true, 'message' => __("File moved successfully", "download-manager"))); } function copyItem() { if (!isset($_REQUEST['__wpdm_copypaste']) || !wp_verify_nonce($_REQUEST['__wpdm_copypaste'], WPDMAM_NONCE_KEY)) wp_send_json(array('success' => false, 'message' => __("Error! Session Expired. Try refreshing page.", "download-manager"))); check_ajax_referer(WPDMAM_NONCE_KEY, '__wpdm_copypaste'); if (!current_user_can(WPDM_ADMIN_CAP)) wp_send_json(array('success' => false, 'message' => __("Error! You are not authorized to execute this action.", "download-manager"))); global $current_user; $root = AssetManager::root(); $opath = explode("|||", wpdm_query_var('source')); $olddir = Crypt::decrypt($opath[0]); $file = end($opath); $oldpath = AssetManager::root($olddir . '/' . $file); $newpath = AssetManager::root(Crypt::decrypt(wpdm_query_var('dest'))) . $file; if (!strstr($oldpath, $root)) wp_send_json(array('success' => false, 'message' => __("Invalid source path", "download-manager"))); if (!strstr($newpath, $root)) wp_send_json(array('success' => false, 'message' => __("Invalid destination path", "download-manager"))); //Check file is in allowed types if (WPDM()->fileSystem->isBlocked($newpath)) wp_send_json(array('success' => false, 'message' => __("Error! FileType is not allowed.", "download-manager"))); copy($oldpath, $newpath); wp_send_json(array('success' => true, 'message' => __("File copied successfully", "download-manager"))); } function rmDir($dir) { $files = array_diff(scandir($dir), array('.', '..')); foreach ($files as $file) { (is_dir("$dir/$file")) ? $this->rmDir("$dir/$file") : unlink("$dir/$file"); } return rmdir($dir); } function copyDir($src, $dst) { $src = realpath($src); $dir = opendir($src); $dst = realpath($dst) . '/' . basename($src); @mkdir($dst); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { if (is_dir($src . '/' . $file)) { $this->copyDir($src . '/' . $file, $dst . '/' . $file); } else { copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); } function frontendFileManagerTab($tabs) { $tabs['asset-manager'] = array('label' => 'Asset Manager', 'callback' => array($this, '_assetManager'), 'icon' => 'fa fa-copy'); return $tabs; } function _assetManager() { include Template::locate("asset-manager-ui.php", __DIR__.'/views'); } /** * Shortcode processor for [wpdm_asset ...$params] * @param $params * @return bool|mixed|string */ function wpdmAsset($params) { if (!isset($params['id'])) return \WPDM\__\Messages::error(__("Asset not found!", "download-manager"), -1); $path_or_id = (int)$params['id']; $asset = new Asset(); $asset->get($path_or_id); ob_start(); include Template::locate("embed-asset.php", __DIR__.'/views'); $content = ob_get_clean(); return $content; } function upload($file) { if (isset($_REQUEST['__wpdmfm_upload']) && wp_verify_nonce($_REQUEST['__wpdmfm_upload'], NONCE_KEY)) { $working_dir = get_user_meta(get_current_user_id(), 'working_dir', true); $root = AssetManager::root(); if (!strstr($working_dir, $root)) wp_send_json(array('success' => false)); if ($working_dir != '') { $dest = $working_dir . basename($file); rename($file, $dest); wp_send_json(array('success' => true, 'src' => $file, 'file' => $dest)); } else wp_send_json(array('success' => false)); } } /** * Extract zip */ function extract() { $relpath = Crypt::decrypt(wpdm_query_var('zipfile')); $zipfile = AssetManager::root($relpath); $reldest = Crypt::decrypt(wpdm_query_var('zipdest')); if ($reldest == '') $reldest = dirname($zipfile); $zipdest = AssetManager::root($reldest); if (!current_user_can(WPDM_ADMIN_CAP)) wp_send_json(array('success' => false, 'message' => __("Error! Only Administrator can execute this operation.", "download-manager"))); if (!$zipfile || !stristr($zipfile, '.zip')) wp_send_json(array('success' => false, 'message' => __("Error! Unauthorized Path.", "download-manager"))); if (!$zipdest) wp_send_json(array('success' => false, 'message' => __("Error! Invalid Destination Path.", "download-manager"))); if (!class_exists('\ZipArchive')) wp_send_json(array('success' => false, 'message' => __('Please activate "zlib" in your server to perform zip operations', 'download-manager'))); $zip = new \ZipArchive(); if ($zip->open($zipfile) === TRUE) { $zip->extractTo($zipdest); $zip->close(); wp_send_json(array('success' => true, 'message' => __("Unzipped successfully.", "download-manager"))); } else { wp_send_json(array('success' => false, 'message' => __("Error! Couldn't open the zip file.", "download-manager"))); } } static function fsPath($path) { $path = str_replace("\\", "/", $path); $path = is_dir($path) ? trailingslashit($path) : $path; return $path; } }