diff --git a/lib/RippingCluster/Main.class.php b/lib/RippingCluster/Main.class.php index 5eea641..d038e6b 100644 --- a/lib/RippingCluster/Main.class.php +++ b/lib/RippingCluster/Main.class.php @@ -169,6 +169,21 @@ class RippingCluster_Main { return true; } + public static function rmdir_recursive($dir) { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (filetype($dir."/".$object) == "dir") self::rmdir_recursive($dir."/".$object); else unlink($dir."/".$object); + } + } + reset($objects); + rmdir($dir); + } + + return true; + } + public static function issetelse($var, $default = null) { if (isset($var)) { return $var; diff --git a/lib/RippingCluster/Source.class.php b/lib/RippingCluster/Source.class.php index c3e907c..a94ec16 100644 --- a/lib/RippingCluster/Source.class.php +++ b/lib/RippingCluster/Source.class.php @@ -104,6 +104,14 @@ class RippingCluster_Source { return $longest_index; } + + /** + * Permanently deletes this source from disk + * + */ + public function delete() { + RippingCluster_Source_PluginFactory::delete($this->plugin, $this->filename); + } public function filename() { return $this->filename; diff --git a/lib/RippingCluster/Source/IPlugin.class.php b/lib/RippingCluster/Source/IPlugin.class.php index f38e5fd..c01ccd9 100644 --- a/lib/RippingCluster/Source/IPlugin.class.php +++ b/lib/RippingCluster/Source/IPlugin.class.php @@ -41,13 +41,21 @@ interface RippingCluster_Source_IPlugin extends RippingCluster_IPlugin { public static function loadEncoded($encoded_filename, $scan = true, $use_cache = true); /** - * Determins if a filename is a valid source loadable using this plugin + * Determines if a filename is a valid source loadable using this plugin * * @param string $source_filename Filename of the source * @return bool */ public static function isValidSource($source_filename); + /** + * Permanently deletes the given source from disk + * + * @param RippingCluster_Source $source Source object to be deleted + * @return bool + */ + public static function delete($source_filename); + } ?> \ No newline at end of file diff --git a/lib/RippingCluster/Source/Plugin/Bluray.class.php b/lib/RippingCluster/Source/Plugin/Bluray.class.php index 96c6082..f6cd8bf 100644 --- a/lib/RippingCluster/Source/Plugin/Bluray.class.php +++ b/lib/RippingCluster/Source/Plugin/Bluray.class.php @@ -117,6 +117,20 @@ class RippingCluster_Source_Plugin_Bluray extends RippingCluster_PluginBase impl return true; } + /** + * Permanently deletes the given source from disk + * + * @param RippingCluster_Source $source Source object to be deleted + * @return bool + */ + public static function delete($source_filename) { + if ( ! self::isValidSource($source_filename)) { + return false; + } + + return RippingCluster_Main::rmdir_recursive($source_filename); + } + } ?> \ No newline at end of file diff --git a/lib/RippingCluster/Source/Plugin/HandBrake.class.php b/lib/RippingCluster/Source/Plugin/HandBrake.class.php index aec5f88..94a9cb3 100644 --- a/lib/RippingCluster/Source/Plugin/HandBrake.class.php +++ b/lib/RippingCluster/Source/Plugin/HandBrake.class.php @@ -217,6 +217,21 @@ class RippingCluster_Source_Plugin_HandBrake extends RippingCluster_PluginBase i return false; } + /** + * Permanently deletes the given source from disk + * + * @param RippingCluster_Source $source Source object to be deleted + * @return bool + */ + public static function delete($source_filename) { + if ( ! self::isValidSource($source_filename)) { + return false; + } + + return RippingCluster_Main::rmdir_recursive($source_filename); + } + + } ?> \ No newline at end of file diff --git a/lib/RippingCluster/Source/Plugin/MkvInfo.class.php b/lib/RippingCluster/Source/Plugin/MkvInfo.class.php index f039532..cd3bbb0 100644 --- a/lib/RippingCluster/Source/Plugin/MkvInfo.class.php +++ b/lib/RippingCluster/Source/Plugin/MkvInfo.class.php @@ -244,6 +244,20 @@ class RippingCluster_Source_Plugin_MkvInfo extends RippingCluster_PluginBase imp return true; } + /** + * Permanently deletes the given source from disk + * + * @param RippingCluster_Source $source Source object to be deleted + * @return bool + */ + public static function delete($source_filename) { + if ( ! self::isValidSource($source_filename)) { + return false; + } + + return unlink($source_filename); + } + } ?> \ No newline at end of file diff --git a/lib/RippingCluster/Source/PluginFactory.class.php b/lib/RippingCluster/Source/PluginFactory.class.php index ec25bdc..5b3e44b 100644 --- a/lib/RippingCluster/Source/PluginFactory.class.php +++ b/lib/RippingCluster/Source/PluginFactory.class.php @@ -67,6 +67,22 @@ class RippingCluster_Source_PluginFactory extends RippingCluster_PluginFactory { return call_user_func(array(self::classname($plugin), 'isValidSource'), source_filename); } + /** + * Permanently deletes the given source from disk + * + * @param string $plugin Name of the plugin used to load the source + * @param string $source_filename Filename of the source to be deleted + */ + public static function delete($plugin, $source_filename) { + self::ensureScanned(); + + if ( ! self::isValidPlugin($plugin)) { + return null; + } + + return call_user_func(array(self::classname($plugin), 'delete'), $source_filename); + } + } ?> \ No newline at end of file diff --git a/webui/pages/sources/delete.php b/webui/pages/sources/delete.php new file mode 100644 index 0000000..fdf8f03 --- /dev/null +++ b/webui/pages/sources/delete.php @@ -0,0 +1,28 @@ +request(); +$config = $main->config(); + +// Grab the name of this source +$encoded_filename = null; +if ($req->get('confirm')) { + $plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters'); + $encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters'); + + $source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false); + $source->delete(); + + // Redirect back to the sources page + RippingCluster_Page::redirect('rips/sources'); + +} else { + $plugin = $req->get('plugin', 'RippingCluster_Exception_InvalidParameters'); + $encoded_filename = $req->get('id', 'RippingCluster_Exception_InvalidParameters'); + + $source = RippingCluster_Source_PluginFactory::loadEncoded($plugin, $encoded_filename, false); + + $this->smarty->assign('source', $source); +} + +?> \ No newline at end of file diff --git a/webui/templates/rips/sources.tpl b/webui/templates/rips/sources.tpl index c0cbb1a..962940c 100644 --- a/webui/templates/rips/sources.tpl +++ b/webui/templates/rips/sources.tpl @@ -20,7 +20,8 @@ {assign var='source_cached' value="$source->isCached()}
+ Are you sure you want to delete {$source->plugin()|escape:"html"}:{$source->filename()|escape:"html"}? + [ Delete + | Cancel ] +