function elimina_immagine() { $image_name = Params::get("image_name"); $id_prodotto_servizio = Params::get("id_prodotto_servizio"); $product_image_dir = new Dir(self::PRODUCT_IMAGE_DIR . "/" . $id_prodotto_servizio); $product_image_file = $product_image_dir->newFile($image_name); ImagePicker::delete_image_thumbnails($product_image_file); //elimino la riga associata all'immagine $peer = new ImmagineProdottoServizioPeer(); $peer->id_prodotto_servizio__EQUALS($id_prodotto_servizio); $peer->nome_immagine__EQUALS($image_name); $elenco_immagini_prodotto_servizio = $peer->find(); foreach ($elenco_immagini_prodotto_servizio as $img) { $peer->delete($img); } $product_image_file->delete(); if ($product_image_dir->isEmpty()) { $product_image_dir->delete(); } return Redirect::success(); }
function testMkdir() { $dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/prova/"); $module_plug_test_root = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/"); $target_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/"); $plug = new DirBridge($target_dir, new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/ecommerce/cart/")); $this->assertFalse($dir->exists(), "La directory da creare esiste gia'!!"); $plug->mkdir("prova"); $this->assertTrue($dir->exists(), "La directory non è stata creata!!"); $dir->delete(); }
function execute() { $dir = $this->dir; $force = $this->force; if (self::$dummy_mode) { echo "Rmdir : " . self::$root_dir->getPath() . $dir . "<br />"; return; } $d = new Dir(self::$root_dir->getPath() . $dir); if (!$d->isEmpty() && $force || $d->isEmpty()) { $d->delete(true); } }
function execute() { $attributes = $this->attributes; $name = $attributes->name; $location = $attributes->location; $do_file_name = $name . "DO.class.php"; $peer_file_name = $name . "Peer.class.php"; $d = new Dir($location); $do_file = $d->newFile($do_file_name); $do_file->delete(); $peer_file = $d->newFile($peer_file_name); $peer_file->delete(); $d->delete(); }
function delete() { $nome_categoria = Params::get("nome_categoria"); $nome_modulo = Params::get("nome_modulo"); if ($nome_categoria !== ModuleUtils::FRAMEWORK_CATEGORY_NAME && $nome_modulo !== ModuleUtils::FRAMEWORK_MODULE_NAME) { $path = AvailableModules::get_available_module_path($nome_categoria, $nome_modulo); $d = new Dir($path); $d->delete(true); Flash::ok("Modulo " . $nome_categoria . "/" . $nome_modulo . " eliminato con successo!!"); return Redirect::success(); } else { Flash::error("Impossibile eliminare il modulo " . $nome_categoria . "/" . $nome_modulo); return Redirect::failure(); } }
function delete_collection() { $peer = new GalleryCollectionPeer(); $collection = $peer->find_by_id(Params::get("id_gallery_collection")); $all_galleries = call("gallery", "index", array("id_gallery_collection" => Params::get("id_gallery_collection"))); foreach ($all_galleries as $gallery) { call("gallery", "delete_gallery", array("id_gallery" => $gallery->id_gallery)); } $d = new Dir(GalleryCollectionController::GALLERY_COLLECTION_ROOT_DIR . $collection->folder); $d->delete(); $peer->delete($collection); if (is_html()) { return Redirect::success(); } else { return Result::ok(); } }
function delete_gallery() { $gallery_name = Params::get("gallery_name"); $dir = new Dir($this->get_current_folder() . "/" . $gallery_name); $gallery_ini = $dir->newFile("_gallery.ini"); if ($gallery_ini->exists()) { $dir->delete(true); if (is_html()) { return Redirect::success(); } else { return Result::ok(); } } else { if (is_html()) { return Redirect::failure(); } else { return Result::error("Impossibile eliminare la gallery"); } } }
function delete_gallery() { $id_gallery = Params::get("id_gallery"); $peer_gallery = new GalleryPeer(); $gal = $peer_gallery->find_by_id($id_gallery); $peer_collection = new GalleryCollectionPeer(); $collection = $peer_collection->find_by_id($gal->id_gallery_collection); $peer_gallery_image = new GalleryImagePeer(); $peer_gallery_image->id_gallery__EQUAL($id_gallery); $all_images = $peer_gallery_image->find(); foreach ($all_images as $img) { call("gallery_image", "delete_image", array("id_gallery_image" => $img->id_gallery_image)); } $dir = new Dir(GalleryCollectionController::GALLERY_COLLECTION_ROOT_DIR . $collection->folder . "/" . $gal->folder); $dir->delete(true); $peer_gallery->delete($gal); if (is_html()) { return Redirect::success(); } else { return Result::ok(); } }
function execute() { $file_or_folder = $this->file_or_folder; $force = $this->force; if (self::$dummy_mode) { echo "Removing : " . $file_or_folder . "<br />"; return; } $root_dir_path = self::$root_dir->getPath(); //se è una cartella elimino solo i file che sono anche nel modulo if (FileSystemUtils::isDir($this->module_dir->getPath() . $file_or_folder)) { $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder); $target_dir = new Dir($root_dir_path . $file_or_folder); if (!$target_dir->exists()) { return; } $toremove_files = $source_dir->listFiles(); foreach ($toremove_files as $elem) { if ($elem->isDir()) { $this->remove($file_or_folder . $elem->getName() . DS); } else { $this->remove($file_or_folder . $elem->getFilename()); } } if ($target_dir->isEmpty()) { $target_dir->delete(false); } } else { $source_file = new File($this->module_dir->getPath() . $file_or_folder); $target_file = new File($root_dir_path . $file_or_folder); if (!$force && !$source_file->exists()) { return; } //se non esiste nel modulo non lo rimuovo $target_file->delete(); } }
/** * Main function */ public static function main() { // Array of forbidden types $forbidden_types = array('html', 'htm', 'js', 'jsb', 'mhtml', 'mht', 'php', 'phtml', 'php3', 'php4', 'php5', 'phps', 'shtml', 'jhtml', 'pl', 'py', 'cgi', 'sh', 'ksh', 'bsh', 'c', 'htaccess', 'htpasswd', 'exe', 'scr', 'dll', 'msi', 'vbs', 'bat', 'com', 'pif', 'cmd', 'vxd', 'cpl', 'empty'); // Array of image types $image_types = array('jpg', 'png', 'bmp', 'gif', 'tif'); // Get Site url $site_url = Option::get('siteurl'); // Init vars if (Request::get('path')) { $path = Request::get('path'); } else { $path = 'uploads/'; } // Add slash if not exists if (substr($path, -1, 1) != '/') { $path .= '/'; Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } // Upload corectly! if ($path == 'uploads' || $path == 'uploads//') { $path = 'uploads/'; Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } // Only 'uploads' folder! if (strpos($path, 'uploads') === false) { $path = 'uploads/'; Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } // Set default path value if path is empty if ($path == '') { $path = 'uploads/'; Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } $files_path = ROOT . DS . 'public' . DS . $path; $current = explode('/', $path); // Delete file // ------------------------------------- if (Request::get('id') == 'filesmanager' && Request::get('delete_file')) { if (Security::check(Request::get('token'))) { File::delete($files_path . Request::get('delete_file')); if (!is_file($files_path . Request::get('delete_file'))) { Notification::set('success', __('File was deleted', 'filesmanager')); } else { Notification::set('error', __('File was not deleted', 'filesmanager')); } Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Delete dir // ------------------------------------- if (Request::get('id') == 'filesmanager' && Request::get('delete_dir')) { if (Security::check(Request::get('token'))) { Dir::delete($files_path . Request::get('delete_dir')); if (!is_dir($files_path . Request::get('delete_dir'))) { Notification::set('success', __('Directory was deleted', 'filesmanager')); } else { Notification::set('error', __('Directory was not deleted', 'filesmanager')); } Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Rename file/dir // ------------------------------------- if (Request::post('rename_type')) { if (Security::check(Request::post('csrf'))) { $rename_type = Request::post('rename_type'); $rename_from = Request::post('rename_from'); $rename_to = Request::post('rename_to'); if (empty($rename_to)) { Notification::set('error', __('Can not be empty', 'filesmanager')); Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } $ext = $rename_type === 'file' ? '.' . File::ext($rename_from) : ''; $rename_to = $files_path . Security::safeName($rename_to, null, false) . $ext; if (is_dir($rename_to)) { Notification::set('error', __('Directory exists', 'filesmanager')); Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } if (is_file($rename_to)) { Notification::set('error', __('File exists', 'filesmanager')); Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } $success = rename($files_path . $rename_from, $rename_to); if ($success) { Notification::set('success', __('Renamed successfully', 'filesmanager')); } else { Notification::set('error', __('Failure', 'filesmanager')); } Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Upload file // ------------------------------------- if (Request::post('upload_file')) { if (Security::check(Request::post('csrf'))) { $error = false; if ($_FILES['file']) { if (!in_array(File::ext($_FILES['file']['name']), $forbidden_types)) { $filepath = $files_path . Security::safeName(basename($_FILES['file']['name'], File::ext($_FILES['file']['name'])), null, false) . '.' . File::ext($_FILES['file']['name']); $uploaded = move_uploaded_file($_FILES['file']['tmp_name'], $filepath); if ($uploaded !== false && is_file($filepath)) { Notification::set('success', __('File was uploaded', 'filesmanager')); } else { $error = 'File was not uploaded'; } } else { $error = 'Forbidden file type'; } } else { $error = 'File was not uploaded'; } if ($error) { Notification::set('error', __($error, 'filesmanager')); } if (Request::post('dragndrop')) { Request::shutdown(); } else { Request::redirect($site_url . '/admin/index.php?id=filesmanager&path=' . $path); } } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Create Directory // ------------------------------------- if (Request::post('directory_name')) { if (Security::check(Request::post('csrf'))) { $abs_path = $files_path . Security::safeName(Request::post('directory_name'), null, false); $error = false; if (!is_dir($abs_path)) { try { mkdir($abs_path); } catch (Exception $e) { $error = true; } } else { $error = true; } if ($error) { Alert::error(__('Directory was not created', 'filesmanager')); } else { Alert::success(__('Directory was created', 'filesmanager')); } } } // Get information about current path $_list = FilesmanagerAdmin::fdir($files_path); $files_list = array(); // Get files if (isset($_list['files'])) { foreach ($_list['files'] as $files) { $files_list[] = $files; } } $dir_list = array(); // Get dirs if (isset($_list['dirs'])) { foreach ($_list['dirs'] as $dirs) { if (strpos($dirs, '.') === false && strpos($dirs, '..') === false) { $dir_list[] = $dirs; } } } // Display view View::factory('box/filesmanager/views/backend/index')->assign('path', $path)->assign('current', $current)->assign('files_list', $files_list)->assign('dir_list', $dir_list)->assign('forbidden_types', $forbidden_types)->assign('image_types', $image_types)->assign('site_url', $site_url)->assign('upload_max_filesize', FilesmanagerAdmin::uploadSize())->assign('files_path', $files_path)->assign('fileuploader', array('uploadUrl' => $site_url . '/admin/index.php?id=filesmanager&path=' . $path, 'csrf' => Security::token(), 'errorMsg' => __('Upload server error', 'filesmanager')))->display(); }
}); /* REMOVE FILE MEDIA -----------------------------*/ /* * @name Media removefile * @desc Remove file on media ( :any use base64_encode remenber decode file) */ $p->route('/action/media/removefile/(:any)/(:any)', function ($token, $file) use($p) { if (Session::exists('user')) { if (Token::check($token)) { // get json file fow with and height $jsonFile = PUBLICFOLDER . '/media/mdb.json'; $json = json_decode(File::getContent($jsonFile), true); // if remove thumb and dir unlik json file File::delete(ROOTBASE . $json[$file]['thumb']); Dir::delete(ROOTBASE . $json[$file]['images']); unset($json[$file]); if (File::setContent($jsonFile, json_encode($json))) { // set notification $p->setMsg($p::$lang['Success_remove']); Request::redirect($p->Url() . '/media'); } } else { die('crsf Detect'); } } }); /* * @name Media removefile * @desc Remove file on media ( :any use base64_encode remenber decode file) */
<?php defined('PANEL_ACCESS') or die('No direct script access.'); /* TOOLS / CACHE ---------------------------------*/ /* * @name Clear cache * @desc Clear cache on click */ $p->route('/action/clearCache/(:any)/', function ($token) use($p) { if (Session::exists('user')) { if (Token::check($token)) { if (Dir::exists(CACHE . '/doctrine/')) { Dir::delete(CACHE . '/doctrine/'); } if (Dir::exists(CACHE . '/doctrine/')) { Dir::delete(CACHE . '/fenom/'); } // set notification $p->setMsg($p::$lang['Success_cache']); // redirect Request::redirect($p->Url() . '/pages'); } else { die('Crsf detect !'); } } else { Request::redirect($p::$site['site_url'] . '/' . $p::$site['backend_folder']); } });
<?php /* This software is released under the BSD license. Full text at project root -> license.txt */ require_once "../init.php"; if (isset($_POST["nome_modulo"])) { $d = new Dir("/" . FRAMEWORK_MODULES_PATH . $_POST["nome_modulo"]); $module_deleted = $d->delete(true) && $d->exists(); } ?> <html> <head> </head> <body> <?php if ($module_deleted) { echo "Modulo eliminato!!"; } ?> <form name="form__elimina_modulo" method="POST" action="/framework/utilities/delete_module.php"> Nome del modulo : <input type="text" name="nome_modulo" value="" /> <br /> <input type="submit" name="Elimina modulo" value="Elimina modulo" /> </form> </body> </html>
if (Request::get('del')) { if (Request::get('token')) { File::delete(STORAGE_PATH . '/pages' . Request::get('del') . '.md'); Request::redirect(Url::getBase()); } else { die('crsf detect !'); } } // remove Cache if (Request::get('clearcache') == 'true') { if (Request::get('token')) { if (Dir::exists(CACHE_PATH . '/doctrine/')) { Dir::delete(CACHE_PATH . '/doctrine/'); } if (Dir::exists(CACHE_PATH . '/fenom/')) { Dir::delete(CACHE_PATH . '/fenom/'); } Request::redirect(Url::getBase()); } else { die('crsf detect !'); } } // logout if (Request::post('access_logout')) { Session::delete(Config::get('plugins.edit.name') . '_user'); Request::redirect(Url::getCurrent()); } // show template $template->display('admin.tpl', ['title' => $name, 'content' => $page, 'current' => $url, 'directory' => Dir::scan(STORAGE_PATH . '/pages')]); } else { // login
/** * Delete directory * * <code> * Dir::delete('folder1'); * </code> * * @param string $dir Name of directory to delete */ public static function delete($dir) { // Redefine vars $dir = (string) $dir; // Delete dir if (is_dir($dir)) { $ob = scandir($dir); foreach ($ob as $o) { if ($o != '.' && $o != '..') { if (filetype($dir . '/' . $o) == 'dir') { Dir::delete($dir . '/' . $o); } else { unlink($dir . '/' . $o); } } } } reset($ob); rmdir($dir); }
$url = 'pages'; } Dir::delete(STORAGE . '/' . $filename); // set notification $p->setMsg($p::$lang['Success_remove']); // redirect to edit index Request::redirect($p->url() . '/' . $url); } else { die('crsf Detect'); } } }); /* * @name Uploads rename * @desc New folder ( :any use base64_encode remenber decode file) */ $p->route('/action/uploads/removefolder/(:any)/(:any)', function ($token, $file) use($p) { if (Session::exists('user')) { if (Token::check($token)) { // decode file $path = base64_decode($file); Dir::delete(PUBLICFOLDER . '/' . $path); // set notification $p->setMsg($p::$lang['Success_remove']); // redirect to edit index Request::redirect($p->url() . '/uploads'); } else { die('crsf Detect'); } } });
function testDeleteRealEmpty() { $d = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/delete_test_dir_empty/real_empty_dir/"); $this->assertFalse($d->exists(), "La cartella dal eliminare non esiste!!"); $d->touch(); $this->assertTrue($d->exists(), "La cartella da eliminare non è stata creata!!"); $d->delete(); $this->assertFalse($d->exists(), "La cartella da eliminare non è stata eliminata!!"); }
/** * Plugins admin */ public static function main() { // Get siteurl $site_url = Option::get('siteurl'); // Get installed plugin from $plugins array $installed_plugins = Plugin::$plugins; // Get installed users plugins $_users_plugins = array(); foreach (Plugin::$plugins as $plugin) { if ($plugin['privilege'] !== 'box') { $_users_plugins[] = $plugin['id']; } } // Get plugins table $plugins = new Table('plugins'); // Delete plugin // ------------------------------------- if (Request::get('delete_plugin')) { if (Security::check(Request::get('token'))) { // Nobody cant remove box plugins if ($installed_plugins[Text::lowercase(str_replace("Plugin", "", Request::get('delete_plugin')))]['privilege'] !== 'box') { // Run plugin uninstaller file $plugin_name = Request::get('delete_plugin'); if (File::exists(PLUGINS . DS . $plugin_name . DS . 'install' . DS . $plugin_name . '.uninstall.php')) { include PLUGINS . DS . $plugin_name . DS . 'install' . DS . $plugin_name . '.uninstall.php'; } // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Styles and Javascript version Stylesheet::stylesVersionIncrement(); Javascript::javascriptVersionIncrement(); // Delete plugin form plugins table $plugins->deleteWhere('[name="' . Request::get('delete_plugin') . '"]'); // Redirect Request::redirect('index.php?id=plugins'); } } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Install new plugin // ------------------------------------- if (Request::get('install')) { if (Security::check(Request::get('token'))) { // Load plugin install xml file $plugin_xml = XML::loadFile(PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . Request::get('install')); // Add plugin to plugins table $plugins->insert(array('name' => basename(Request::get('install'), '.manifest.xml'), 'location' => (string) $plugin_xml->plugin_location, 'status' => (string) $plugin_xml->plugin_status, 'priority' => (int) $plugin_xml->plugin_priority)); // Clean Monstra TMP folder. Monstra::cleanTmp(); Stylesheet::stylesVersionIncrement(); Javascript::javascriptVersionIncrement(); // Run plugin installer file $plugin_name = str_replace(array("Plugin", ".manifest.xml"), "", Request::get('install')); if (File::exists(PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . $plugin_name . '.install.php')) { include PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . $plugin_name . '.install.php'; } Request::redirect('index.php?id=plugins'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Delete plugin from server // ------------------------------------- if (Request::get('delete_plugin_from_server')) { if (Security::check(Request::get('token'))) { // Clean Monstra TMP folder. Monstra::cleanTmp(); Stylesheet::stylesVersionIncrement(); Javascript::javascriptVersionIncrement(); Dir::delete(PLUGINS . DS . basename(Request::get('delete_plugin_from_server'), '.manifest.xml')); Request::redirect('index.php?id=plugins'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Upload & extract plugin archive // ------------------------------------- if (Request::post('upload_file')) { if (Security::check(Request::post('csrf'))) { if ($_FILES['file']) { if (in_array(File::ext($_FILES['file']['name']), array('zip'))) { $tmp_dir = ROOT . DS . 'tmp' . DS . uniqid('plugin_'); $error = 'Plugin was not uploaded'; if (Dir::create($tmp_dir)) { $file_locations = Zip::factory()->extract($_FILES['file']['tmp_name'], $tmp_dir); if (!empty($file_locations)) { $manifest = ''; foreach ($file_locations as $filepath) { if (substr($filepath, -strlen('.manifest.xml')) === '.manifest.xml') { $manifest = $filepath; break; } } if (!empty($manifest) && basename(dirname($manifest)) === 'install') { $manifest_file = pathinfo($manifest, PATHINFO_BASENAME); $plugin_name = str_replace('.manifest.xml', '', $manifest_file); if (Dir::create(PLUGINS . DS . $plugin_name)) { $tmp_plugin_dir = dirname(dirname($manifest)); Dir::copy($tmp_plugin_dir, PLUGINS . DS . $plugin_name); Notification::set('success', __('Plugin was uploaded', 'plugins')); $error = false; } } } } else { $error = 'System error'; } } else { $error = 'Forbidden plugin file type'; } } else { $error = 'Plugin was not uploaded'; } if ($error) { Notification::set('error', __($error, 'plugins')); } if (Request::post('dragndrop')) { Request::shutdown(); } else { Request::redirect($site_url . '/admin/index.php?id=plugins#installnew'); } } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Installed plugins $plugins_installed = array(); // New plugins $plugins_new = array(); // Plugins to install $plugins_to_intall = array(); // Scan plugins directory for .manifest.xml $plugins_new = File::scan(PLUGINS, '.manifest.xml'); // Get installed plugins from plugins table $plugins_installed = $plugins->select(null, 'all', null, array('location', 'priority'), 'priority', 'ASC'); // Update $plugins_installed array. extract plugins names foreach ($plugins_installed as $plg) { $_plg[] = basename($plg['location'], 'plugin.php') . 'manifest.xml'; } // Diff $plugins_to_install = array_diff($plugins_new, $_plg); // Create array of plugins to install $count = 0; foreach ($plugins_to_install as $plugin) { $plg_path = PLUGINS . DS . Text::lowercase(basename($plugin, '.manifest.xml')) . DS . 'install' . DS . $plugin; if (file_exists($plg_path)) { $plugins_to_intall[$count]['path'] = $plg_path; $plugins_to_intall[$count]['plugin'] = $plugin; $count++; } } // Draw template View::factory('box/plugins/views/backend/index')->assign('installed_plugins', $installed_plugins)->assign('plugins_to_intall', $plugins_to_intall)->assign('_users_plugins', $_users_plugins)->assign('fileuploader', array('uploadUrl' => $site_url . '/admin/index.php?id=plugins', 'csrf' => Security::token(), 'errorMsg' => __('Upload server error', 'filesmanager')))->display(); }
public function deleteFiles() { // delete possibly cached files in image cache $publicCacheDir = new Dir(STATIC_DIR . 'img/public/' . $this->unique_id); if ($publicCacheDir->exists()) { $publicCacheDir->delete(); } // delete source file @unlink($this->filename()); return true; }
/** * Clean Monstra TMP folder. */ public static function cleanTmp() { // Cleanup minify if (count($files = File::scan(MINIFY, array('css', 'js', 'php'))) > 0) { foreach ($files as $file) { File::delete(MINIFY . DS . $file); } } // Cleanup cache if (count($namespaces = Dir::scan(CACHE)) > 0) { foreach ($namespaces as $namespace) { Dir::delete(CACHE . DS . $namespace); } } }
static function delete_image_thumbnails($path) { if ($path instanceof File) { $image_file = $path; } else { $image_file = new File($path); } $image_dir = $image_file->getDirectory(); $full_cache_dir = new Dir(self::THUMBNAILS_DIR . $image_dir->getPath()); $folders = $full_cache_dir->listFolders(); foreach ($folders as $f) { $image_thumb = $f->newFile($image_file->getFilename()); if ($image_thumb->exists()) { $image_thumb->delete(); } if ($f->isEmpty()) { $f->delete(); } } if ($full_cache_dir->isEmpty()) { $full_cache_dir->delete(); } }
public function delete() { return is_dir($this->path) ? Dir::delete($this->path) : File::delete($this->path); }
public static function init() { // login vars $user = trim(Config::get('plugins.gallery.email')); $password = trim(Config::get('plugins.gallery.password')); $token = trim(Config::get('plugins.gallery.token')); $hash = md5($token . $password); // get plugin info //var_dump(json_encode(Config::get('plugins.gallery'),true)); $template = Template::factory(PLUGINS_PATH . '/gallery/templates/'); $template->setOptions(['strip' => false]); $jsonFile = ''; $format = ''; $thumbnails_path = ''; $photos_path = ''; $json = ''; $info = ''; // check if dir exists if not create if (!Dir::exists(ROOT_DIR . '/public/gallery')) { Dir::create(ROOT_DIR . '/public/gallery'); } if (!Dir::exists(ROOT_DIR . '/public/gallery/thumbnails')) { Dir::create(ROOT_DIR . '/public/gallery/thumbnails'); } if (!Dir::exists(ROOT_DIR . '/public/gallery/galleries')) { Dir::create(ROOT_DIR . '/public/gallery/galleries'); } if (!File::exists(ROOT_DIR . '/public/gallery/gallery.json')) { File::setContent(ROOT_DIR . '/public/gallery/gallery.json', '[]'); } else { $jsonFile = ROOT_DIR . '/public/gallery/gallery.json'; $format = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG'); $thumbnails_path = ROOT_DIR . '/public/gallery/thumbnails/'; $photos_path = ROOT_DIR . '/public/gallery/galleries/'; // decode json $json = json_decode(File::getContent($jsonFile), true); } // show loginbtn if (Session::exists(Config::get('plugins.gallery.name') . '_user')) { // logout if (Request::post('access_logout')) { Session::delete(Config::get('plugins.gallery.name') . '_user'); Request::redirect(Url::getBase() . '/' . strtolower(Config::get('plugins.gallery.name'))); } // create gallery if (Request::post('createGallery')) { if (Request::post('token')) { // id $id = time(); // json array remenber encode $json[$id] = array('id' => $id, 'title' => Request::post('title') ? Request::post('title') : 'No title', 'desc' => Request::post('desc') ? Request::post('desc') : 'No desc', 'thumbnail' => '/public/gallery/thumbnails/' . $id . '.png', 'photos' => ROOT_DIR . '/public/gallery/galleries/' . $id . '/'); Dir::create($photos_path . $id); // save content if (File::setContent($jsonFile, json_encode($json))) { self::upload('thumbnail', 'thumbnail', $format, $thumbnails_path, $id); self::upload('photos', 'photos', $format, $photos_path, $id); return self::set_msg('Success The gallery has been created'); } } else { die('Crsf detect!'); } } // update gallery if (Request::post('updateGallery')) { if (Request::post('token')) { // json array remenber encode $id = Request::post('update_id'); $json[$id] = array('id' => $id, 'title' => Request::post('update_title') ? Request::post('update_title') : 'No title', 'desc' => Request::post('update_desc') ? Request::post('update_desc') : 'No desc', 'thumbnail' => '/public/gallery/thumbnails/' . $id . '.png', 'photos' => ROOT_DIR . '/public/gallery/galleries/' . $id . '/'); // save content if (File::setContent($jsonFile, json_encode($json))) { //upload images self::upload('thumbnail', 'update_thumbnail', $format, $thumbnails_path, $id); self::upload('photos', 'update_photos', $format, $photos_path, $id); return self::set_msg('Success The gallery has been updated'); } } else { die('Crsf detect!'); } } // resize gallery if (Request::post('resizeGallery')) { if (Request::post('token')) { $uid = Request::post('gallery_id'); $w = Request::post('gallery_w'); $h = Request::post('gallery_h'); $files = File::scan($photos_path . $uid); foreach ($files as $file) { // Load the original image $image = new SimpleImage($file); $image->resize($w, $h, true); $image->save($file); } return self::set_msg('Success The gallery Photos, has been resized'); } } // resize thumbnail if (Request::post('resizeThumbnail')) { if (Request::post('token')) { $uid = Request::post('gallery_id'); $tw = Request::post('gallery_tw'); $th = Request::post('gallery_th'); $dir = ROOT_DIR . '/public/gallery/thumbnails/' . $uid . '.png'; // Load the original image $image = new SimpleImage($dir); $image->resize($tw, $th, true); $image->save($dir); return self::set_msg('Success The gallery Thumbnail, has been created'); } } // remove file if (Request::get('rem')) { $file = base64_decode(Request::get('rem')); $uid = Request::get('id'); File::delete($file); self::set_msg('Success The Image has been deleted'); } // remove gallery if (Request::get('del')) { $id_of_gallery = Request::get('del'); unset($json[$id_of_gallery]); if (File::setContent($jsonFile, json_encode($json))) { File::delete(ROOT_DIR . '/public/gallery/thumbnails/' . $id_of_gallery . '.png'); Dir::delete($photos_path . $id_of_gallery); self::set_msg('Success The Gallery ' . $id_of_gallery . ' has been deleted'); Request::redirect(Url::getBase() . '/gallery'); } } // show template return $template->display('admin.tpl', ['info' => self::get_msg(), 'title' => Config::get('plugins.gallery.name') . ' Admin Area', 'root_dir' => ROOT_DIR, 'info' => $info, 'content' => $json ? array_reverse($json) : '']); } else { // login access if (Request::post('access_login')) { if (Request::post('token')) { if (Request::post('password') == $password && Request::post('email') == $user) { @Session::start(); Session::set(Config::get('plugins.gallery.name') . '_user', $hash); // show admin template Request::redirect(Url::getBase() . '/gallery'); } else { // password not correct show error $template->display('partials/error.tpl', ['title' => 'Access Error', 'content' => Config::get('plugins.gallery.errorPassword')]); } } else { // crsf die('crsf detect'); } } // template return $template->display('home.tpl', ['root_dir' => ROOT_DIR, 'content' => $json ? array_reverse($json) : '']); } }
/** * Clear Cache */ public static function clear() { Dir::delete(CACHE_PATH . '/doctrine/'); Dir::delete(CACHE_PATH . '/fenom/'); }
function drop_do($attributes) { $name = $attributes->name; $location = $attributes->location; $do_file_name = $name . "DO.class.php"; $peer_file_name = $name . "Peer.class.php"; $d = new Dir($location); $do_file = $d->newFile($do_file_name); $do_file->delete(); $peer_file = $d->newFile($peer_file_name); $peer_file->delete(); $d->delete(); }