コード例 #1
0
function bp_gtm_delete_item()
{
    global $bp, $wpdb;
    if ($_GET['deleteType'] == 'tag' || $_GET['deleteType'] == 'cat') {
        $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_terms . " WHERE `id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_taxon . " WHERE `term_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
    } elseif ($_GET['deleteType'] == 'projects') {
        $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_projects . " WHERE `id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_tasks . " WHERE `project_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_taxon . " WHERE `project_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_resps . " WHERE `project_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM " . $bp->gtm->table_discuss . " WHERE `project_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->core->table_name_notifications} WHERE `item_id` = %d AND `secondary_item_id` = %d AND `component_name` = {$bp->gtm->slug} AND `component_action` LIKE `project_%%`", $_GET['deleteItem'], $bp->groups->current_group->id));
        $project = BP_GTM_Projects::get_project_by_id($_GET['deleteItem']);
        $resps = explode(' ', $project['0']->resp_id);
        foreach ($resps as $resp) {
            if ($resp != '') {
                $resp_id = bp_core_get_userid($resp);
                if ($resp_id != $bp->loggedin_user->id) {
                    bp_core_add_notification($_GET['deleteItem'], $resp_id, $bp->gtm->slug, 'project_deleted', $bp->groups->current_group->id);
                }
            }
        }
        $file_path = $wpdb->get_results($wpdb->prepare("SELECT path FROM {$bp->gtm->table_files} WHERE `project_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        foreach ($file_path as $path) {
            unlink(bp_gtm_file_dir($path->path));
        }
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_files} WHERE `id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
    } elseif ($_GET['deleteType'] == 'tasks') {
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_tasks} WHERE `id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_taxon} WHERE `task_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_resps} WHERE `task_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_discuss} WHERE `task_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->core->table_name_notifications} WHERE `item_id` = %d AND `secondary_item_id` = %d AND `component_name` = {$bp->gtm->slug} AND `component_action` LIKE `task_%%`", $_GET['deleteItem'], $bp->groups->current_group->id));
        $task = BP_GTM_Tasks::get_task_by_id($_GET['deleteItem']);
        $resps = explode(' ', $task['0']->resp_id);
        foreach ($resps as $resp) {
            if ($resp != '') {
                $resp_id = bp_core_get_userid($resp);
                if ($resp_id != $bp->loggedin_user->id) {
                    bp_core_add_notification($_GET['deleteItem'], $resp_id, $bp->gtm->slug, 'task_deleted', $bp->groups->current_group->id);
                }
            }
        }
        $file_path = $wpdb->get_results($wpdb->prepare("SELECT path FROM {$bp->gtm->table_files} WHERE `task_id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        foreach ($file_path as $path) {
            unlink(bp_gtm_file_dir($path->path));
        }
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_files} WHERE `id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
    } elseif ($_GET['deleteType'] == 'file') {
        $file_path = $wpdb->get_var($wpdb->prepare("SELECT path FROM {$bp->gtm->table_files} WHERE `id` = %d", $_GET['deleteItem']));
        $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_files} WHERE `id` = %d AND `group_id` = %d", $_GET['deleteItem'], $bp->groups->current_group->id));
        unlink(bp_gtm_file_dir($file_path));
    }
    return true;
}
コード例 #2
0
ファイル: bp-gtm-core.php プロジェクト: adisonc/MaineLearning
 protected function bp_gtm_delete_g_data($data)
 {
     global $bp, $wpdb;
     if (!check_admin_referer('bp_gtm_delete')) {
         return false;
     }
     $paths = $wpdb->get_results($wpdb->prepare("SELECT path FROM {$bp->gtm->table_files} WHERE `group_id` = %d", $_POST['cur_group']));
     foreach ($paths as $path) {
         if (file_exists(bp_gtm_file_dir($path->path))) {
             unlink(bp_gtm_file_dir($path->path));
         }
     }
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_files} WHERE `group_id` = %d", $_POST['cur_group']));
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_projects} WHERE `group_id` = %d", $_POST['cur_group']));
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_tasks} WHERE `group_id` = %d", $_POST['cur_group']));
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_taxon} WHERE `group_id` = %d", $_POST['cur_group']));
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_terms} WHERE `group_id` = %d", $_POST['cur_group']));
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_resps} WHERE `group_id` = %d", $_POST['cur_group']));
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->gtm->table_discuss} WHERE `group_id` = %d", $_POST['cur_group']));
     bp_core_add_message(__('Everything was deleted successfully.', 'bp_gtm'));
     do_action('bp_gtm_delete_g_data', $bp->groups->current_group->id);
     bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . $bp->gtm->slug . '/delete/');
 }