예제 #1
0
 public static function delete_directory($dir)
 {
     $files = glob(rtrim($dir, '/') . '/*');
     foreach ($files as $file) {
         if (is_dir($file)) {
             \site\files::delete_directory($file);
         } else {
             @unlink($file);
         }
     }
     @rmdir($dir);
 }
예제 #2
0
 public static function delete_plugin($id)
 {
     global $db;
     if (!$GLOBALS['me']->is_admin) {
         return false;
     }
     $id = (array) $id;
     $stmt = $db->stmt_init();
     $stmt->prepare("DELETE FROM " . DB_TABLE_PREFIX . "plugins WHERE id = ?");
     foreach ($id as $ID) {
         $plugin = admin_query::plugin_infos($ID);
         // delete plugin
         $stmt->bind_param("i", $ID);
         $stmt->execute();
         // directory
         $dir = rtrim(dirname($plugin->main_file), '/');
         // delete tables
         if (isset($plugin->uninstall_preview['delete']['tables'])) {
             $tables = explode(',', $plugin->uninstall_preview['delete']['tables']);
             foreach (array_map('trim', $tables) as $table) {
                 $table = \site\plugin::replace_constant($table);
                 $db->query("DROP TABLE `{$table}`");
             }
         }
         // delete options
         if (isset($plugin->uninstall_preview['delete']['options'])) {
             $rows = explode(',', $plugin->uninstall_preview['delete']['options']);
             foreach (array_map('trim', $rows) as $row) {
                 $db->query("DELETE FROM `" . DB_TABLE_PREFIX . "options` WHERE `option_name` = '{$row}'");
             }
         }
         // delete table columns
         if (isset($plugin->uninstall_preview['delete']['columns'])) {
             $columns = explode(',', $plugin->uninstall_preview['delete']['columns']);
             foreach (array_map('trim', $columns) as $column) {
                 $coltab = explode('/', $column);
                 if (count($coltab) === 2) {
                     $table = \site\plugin::replace_constant($coltab[1]);
                     $db->query("ALTER TABLE `{$table}` DROP {$coltab[0]}");
                 }
             }
         }
         // delete head lines
         $db->query("DELETE FROM `" . DB_TABLE_PREFIX . "head` WHERE `plugin` = '{$dir}'");
         /*
         Resolve possible problems caused by uninstalling
         */
         switch ($plugin->scope) {
             case 'language':
                 if (\query\main::get_option('sitelang') == 'up_' . strtolower($plugin->name)) {
                     actions::set_option(array('sitelang' => 'english'));
                 }
                 if (\query\main::get_option('adminpanel_lang') == 'up_' . strtolower($plugin->name)) {
                     actions::set_option(array('adminpanel_lang' => 'english'));
                 }
                 break;
         }
         // delete plugin directory
         \site\files::delete_directory(DIR . '/' . UPDIR . '/' . $dir);
         // delete image, if plugins has an image
         @unlink(DIR . '/' . $plugin->image);
     }
     @$stmt->close();
     return true;
 }