/** * Check and remove the requested files from the trash * */ public function DeleteFromTrash() { global $dataDir, $langmessage; if (empty($_POST['titles']) || !is_array($_POST['titles'])) { message($langmessage['OOPS'] . ' (No Titles)'); return; } $titles = array(); $incomplete = false; foreach ($_POST['titles'] as $trash_index) { $title_info = self::GetInfo($trash_index); if ($title_info === false) { $incomplete = true; continue; } $titles[$trash_index] = $title_info; } if (!self::ModTrashData(null, $titles)) { return false; } //remove the data foreach ($titles as $trash_index => $info) { \gp\tool\Files::RmAll($info['rm_path']); unset($this->trash_files[$trash_index]); } if ($incomplete) { message($langmessage['delete_incomplete']); } }
/** * Remove a plugin * */ function RemovePlugin() { global $langmessage, $dataDir; $plugin =& $_REQUEST['plugin']; if (!is_array($this->cke_config['plugins']) || !array_key_exists($plugin, $this->cke_config['plugins'])) { msg($langmessage['OOPS'] . ' ( )'); return; } unset($this->cke_config['plugins'][$plugin]); if (!$this->SaveConfig()) { msg($langmessage['OOPS'] . ' (Not Saved)'); } else { msg($langmessage['SAVED']); } $path = $dataDir . '/data/_ckeditor/' . $plugin; \gp\tool\Files::RmAll($path); }
/** * Remove unused code folders created by incomplete addon installations * */ function CleanAddonFolder() { global $config; //get a list of all folders $folder = '/data/_addoncode'; $code_folders = $this->GetCleanFolders($folder); $folder = '/data/_addondata'; $data_folders = $this->GetCleanFolders($folder); //check against folders used by addons $addons = $config['addons']; foreach ($addons as $addon_key => $info) { $addon_config = \gp\tool\Plugins::GetAddonConfig($addon_key); if (array_key_exists($addon_config['code_folder_part'], $code_folders)) { $code_folders[$addon_config['code_folder_part']] = false; } if (array_key_exists($addon_config['data_folder_part'], $data_folders)) { $data_folders[$addon_config['data_folder_part']] = false; } } //remove unused folders $folders = array_filter($code_folders) + array_filter($data_folders); foreach ($folders as $folder => $full_path) { \gp\tool\Files::RmAll($full_path); } }
/** * Remove unused code folders created by incomplete addon installations * */ public function CleanInstallFolder() { if (!$this->remote_install) { return; } if (file_exists($this->source)) { \gp\tool\Files::RmAll($this->source); } if (file_exists($this->trash_path)) { \gp\tool\Files::RmAll($this->trash_path); } }
/** * Clean old files and folders from the temporary folder * Delete after 36 hours (129600 seconds) * */ public static function CleanTemp() { global $dataDir; $temp_folder = $dataDir . '/data/_temp'; $files = \gp\tool\Files::ReadDir($temp_folder, false); foreach ($files as $file) { if ($file == 'index.html') { continue; } $full_path = $temp_folder . '/' . $file; $mtime = (int) filemtime($full_path); $diff = time() - $mtime; if ($diff < 129600) { continue; } \gp\tool\Files::RmAll($full_path); } }
/** * Delete a remote theme * */ public function DeleteTheme() { global $langmessage, $dataDir, $gpLayouts, $config; $config_before = $config; $gpLayoutsBefore = $gpLayouts; $theme_folder_name =& $_POST['folder']; $theme_folder = $dataDir . '/data/_themes/' . $theme_folder_name; if (empty($theme_folder_name) || !ctype_alnum($theme_folder_name)) { message($langmessage['OOPS'] . ' (Invalid Request)'); return false; } $order = false; if (isset($config['themes'][$theme_folder_name]['order'])) { $order = $config['themes'][$theme_folder_name]['order']; } if (!$this->CanDeleteTheme($theme_folder_name, $message)) { message($message); return false; } //remove layouts $rm_addon = false; foreach ($gpLayouts as $layout_id => $layout_info) { if (!isset($layout_info['is_addon']) || !$layout_info['is_addon']) { continue; } $layout_folder = dirname($layout_info['theme']); if ($layout_folder != $theme_folder_name) { continue; } if (array_key_exists('addon_key', $layout_info)) { $rm_addon = $layout_info['addon_key']; } $this->RmLayoutPrep($layout_id); unset($gpLayouts[$layout_id]); } //remove from settings unset($config['themes'][$theme_folder_name]); if ($rm_addon) { $installer = new \gp\admin\Addon\Installer(); if (!$installer->Uninstall($rm_addon)) { $gpLayouts = $gpLayoutsBefore; } $installer->OutputMessages(); } else { if (!\gp\admin\Tools::SaveAllConfig()) { $config = $config_before; $gpLayouts = $gpLayoutsBefore; message($langmessage['OOPS'] . ' (s1)'); return false; } message($langmessage['SAVED']); if ($order) { $img_path = \gp\tool::IdUrl('ci'); \gp\tool::IdReq($img_path); } } //delete the folder if it hasn't already been deleted by addon installer $dir = $dataDir . '/data/_themes/' . $theme_folder_name; if (file_exists($dir)) { \gp\tool\Files::RmAll($dir); } }
/** * Delete all files older than 2 weeks * If there are more than 200 files older than one week * */ public static function CleanCache() { global $dataDir; $dir = $dataDir . '/data/_cache'; $files = scandir($dir); $times = array(); foreach ($files as $file) { if ($file == '.' || $file == '..' || strpos($file, '.php') !== false) { continue; } $full_path = $dir . '/' . $file; $time = filemtime($full_path); $diff = time() - $time; //if relatively new ( < 3 days), don't delete it if ($diff < 259200) { continue; } //if old ( > 14 days ), delete it if ($diff > 1209600) { \gp\tool\Files::RmAll($full_path); continue; } $times[$file] = $time; } //reduce further if needed till we have less than 200 files arsort($times); $times = array_keys($times); while (count($times) > 200) { $full_path = $dir . '/' . array_pop($times); \gp\tool\Files::RmAll($full_path); } }
/** * Remove all of the resized images for an image that is deleted * */ public function RemoveResized($removed) { global $dataDir; foreach ($removed as $key => $info) { $img = self::TrimBaseDir($info['realpath']); $index = array_search($img, \gp_resized::$index); if (!$index) { continue; } unset(\gp_resized::$index[$index]); $folder = $dataDir . '/data/_resized/' . $index; if (file_exists($folder)) { \gp\tool\Files::RmAll($folder); } } }