Exemple #1
0
check_status(ACCESS_ADMINISTRATOR);
check_input_parameter('image_id', $_GET, false, PATTERN_ID);
check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
// represent
$query = '
SELECT id
  FROM ' . CATEGORIES_TABLE . '
  WHERE representative_picture_id = ' . $_GET['image_id'] . '
;';
$represented_albums = query2array($query, null, 'id');
// +-----------------------------------------------------------------------+
// |                             delete photo                              |
// +-----------------------------------------------------------------------+
if (isset($_GET['delete'])) {
    check_pwg_token();
    delete_elements(array($_GET['image_id']), true);
    invalidate_user_cache();
    // where to redirect the user now?
    //
    // 1. if a category is available in the URL, use it
    // 2. else use the first reachable linked category
    // 3. redirect to gallery root
    if (isset($_GET['cat_id']) and !empty($_GET['cat_id'])) {
        redirect(make_index_url(array('category' => get_cat_info($_GET['cat_id']))));
    }
    $query = '
SELECT category_id
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE image_id = ' . $_GET['image_id'] . '
;';
    $authorizeds = array_diff(array_from_query($query, 'category_id'), explode(',', calculate_permissions($user['id'], $user['status'])));
function pfemail_reject($id)
{
    global $conf, $page;
    $query = '
DELETE
  FROM ' . PFEMAIL_PENDINGS_TABLE . '
  WHERE image_id = ' . $id . '
;';
    pwg_query($query);
    delete_elements(array($id), true);
    array_push($page['infos'], l10n('Photo rejected'));
    invalidate_user_cache();
    return true;
}
Exemple #3
0
            // add new photos to caddie
            if (isset($_POST['add_to_caddie']) and $_POST['add_to_caddie'] == 1) {
                fill_caddie($caddiables);
            }
        }
        $counts['new_elements'] = count($inserts);
    }
    // delete elements that are in database but not in the filesystem
    $to_delete_elements = array();
    foreach (array_diff($db_elements, array_keys($fs)) as $path) {
        $to_delete_elements[] = array_search($path, $db_elements);
        $infos[] = array('path' => $path, 'info' => l10n('deleted'));
    }
    if (count($to_delete_elements) > 0) {
        if (!$simulate) {
            delete_elements($to_delete_elements);
        }
        $counts['del_elements'] = count($to_delete_elements);
    }
    $template->append('footer_elements', '<!-- scanning files : ' . get_elapsed_time($start_files, get_moment()) . ' -->');
}
// +-----------------------------------------------------------------------+
// |                          synchronize files                            |
// +-----------------------------------------------------------------------+
if (isset($_POST['submit']) and ($_POST['sync'] == 'dirs' or $_POST['sync'] == 'files') and !$general_failure) {
    if (!$simulate) {
        $start = get_moment();
        update_category('all');
        $template->append('footer_elements', '<!-- update_category(all) : ' . get_elapsed_time($start, get_moment()) . ' -->');
        $start = get_moment();
        update_global_rank();
/**
 * Save picture form
 * @trigger loc_begin_picture
 */
function admintools_save_picture()
{
    global $page, $conf, $MultiView, $user, $picture;
    if (!isset($_GET['delete']) and !isset($_POST['action']) and @$_POST['action'] != 'quick_edit') {
        return;
    }
    $query = 'SELECT added_by FROM ' . IMAGES_TABLE . ' WHERE id = ' . $page['image_id'] . ';';
    list($added_by) = pwg_db_fetch_row(pwg_query($query));
    if (!$MultiView->is_admin() and $user['id'] != $added_by) {
        return;
    }
    if (isset($_GET['delete']) and get_pwg_token() == @$_GET['pwg_token']) {
        include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
        delete_elements(array($page['image_id']), true);
        invalidate_user_cache();
        if (isset($page['rank_of'][$page['image_id']])) {
            redirect(duplicate_index_url(array('start' => floor($page['rank_of'][$page['image_id']] / $page['nb_image_page']) * $page['nb_image_page'])));
        } else {
            redirect(make_index_url());
        }
    }
    if ($_POST['action'] == 'quick_edit') {
        include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
        $data = array('name' => $_POST['name'], 'author' => $_POST['author']);
        if ($MultiView->is_admin()) {
            $data['level'] = $_POST['level'];
        }
        if ($conf['allow_html_descriptions']) {
            $data['comment'] = @$_POST['comment'];
        } else {
            $data['comment'] = strip_tags(@$_POST['comment']);
        }
        if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false) {
            $data['date_creation'] = $_POST['date_creation'] . ' ' . $_POST['date_creation_time'];
        }
        single_update(IMAGES_TABLE, $data, array('id' => $page['image_id']));
        $tag_ids = array();
        if (!empty($_POST['tags'])) {
            $tag_ids = get_tag_ids($_POST['tags']);
        }
        set_tags($tag_ids, $page['image_id']);
    }
}
Exemple #5
0
check_input_parameter('selection', $_POST, true, PATTERN_ID);
// +-----------------------------------------------------------------------+
// | specific actions                                                      |
// +-----------------------------------------------------------------------+
if (isset($_GET['action'])) {
    if ('empty_caddie' == $_GET['action']) {
        $query = '
DELETE FROM ' . CADDIE_TABLE . '
  WHERE user_id = ' . $user['id'] . '
;';
        pwg_query($query);
        $_SESSION['page_infos'] = array(l10n('Information data registered in database'));
        redirect(get_root_url() . 'admin.php?page=' . $_GET['page']);
    }
    if ('delete_orphans' == $_GET['action']) {
        $deleted_count = delete_elements(get_orphans(), true);
        if ($deleted_count > 0) {
            $_SESSION['page_infos'][] = l10n_dec('%d photo was deleted', '%d photos were deleted', $deleted_count);
            redirect(get_root_url() . 'admin.php?page=' . $_GET['page']);
        }
    }
}
// +-----------------------------------------------------------------------+
// |                      initialize current set                           |
// +-----------------------------------------------------------------------+
// filters from form
if (isset($_POST['submitFilter'])) {
    // echo '<pre>'; print_r($_POST); echo '</pre>';
    unset($_REQUEST['start']);
    // new photo set must reset the page
    $_SESSION['bulk_manager_filter'] = array();
Exemple #6
0
/**
 * Recursively deletes one or more categories.
 * It also deletes :
 *    - all the elements physically linked to the category (with delete_elements)
 *    - all the links between elements and this category
 *    - all the restrictions linked to the category
 *
 * @param int[] $ids
 * @param string $photo_deletion_mode
 *    - no_delete : delete no photo, may create orphans
 *    - delete_orphans : delete photos that are no longer linked to any category
 *    - force_delete : delete photos even if they are linked to another category
 */
function delete_categories($ids, $photo_deletion_mode = 'no_delete')
{
    if (count($ids) == 0) {
        return;
    }
    // add sub-category ids to the given ids : if a category is deleted, all
    // sub-categories must be so
    $ids = get_subcat_ids($ids);
    // destruction of all photos physically linked to the category
    $query = '
SELECT id
  FROM ' . IMAGES_TABLE . '
  WHERE storage_category_id IN (
' . wordwrap(implode(', ', $ids), 80, "\n") . ')
;';
    $element_ids = query2array($query, null, 'id');
    delete_elements($element_ids);
    // now, should we delete photos that are virtually linked to the category?
    if ('delete_orphans' == $photo_deletion_mode or 'force_delete' == $photo_deletion_mode) {
        $query = '
SELECT
    DISTINCT(image_id)
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE category_id IN (' . implode(',', $ids) . ')
;';
        $image_ids_linked = query2array($query, null, 'image_id');
        if (count($image_ids_linked) > 0) {
            if ('delete_orphans' == $photo_deletion_mode) {
                $query = '
SELECT
    DISTINCT(image_id)
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE image_id IN (' . implode(',', $image_ids_linked) . ')
    AND category_id NOT IN (' . implode(',', $ids) . ')
;';
                $image_ids_not_orphans = query2array($query, null, 'image_id');
                $image_ids_to_delete = array_diff($image_ids_linked, $image_ids_not_orphans);
            }
            if ('force_delete' == $photo_deletion_mode) {
                $image_ids_to_delete = $image_ids_linked;
            }
            delete_elements($image_ids_to_delete, true);
        }
    }
    // destruction of the links between images and this category
    $query = '
DELETE FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE category_id IN (
' . wordwrap(implode(', ', $ids), 80, "\n") . ')
;';
    pwg_query($query);
    // destruction of the access linked to the category
    $query = '
DELETE FROM ' . USER_ACCESS_TABLE . '
  WHERE cat_id IN (
' . wordwrap(implode(', ', $ids), 80, "\n") . ')
;';
    pwg_query($query);
    $query = '
DELETE FROM ' . GROUP_ACCESS_TABLE . '
  WHERE cat_id IN (
' . wordwrap(implode(', ', $ids), 80, "\n") . ')
;';
    pwg_query($query);
    // destruction of the category
    $query = '
DELETE FROM ' . CATEGORIES_TABLE . '
  WHERE id IN (
' . wordwrap(implode(', ', $ids), 80, "\n") . ')
;';
    pwg_query($query);
    $query = '
DELETE FROM ' . OLD_PERMALINKS_TABLE . '
  WHERE cat_id IN (' . implode(',', $ids) . ')';
    pwg_query($query);
    $query = '
DELETE FROM ' . USER_CACHE_CATEGORIES_TABLE . '
  WHERE cat_id IN (' . implode(',', $ids) . ')';
    pwg_query($query);
    trigger_notify('delete_categories', $ids);
}
     foreach ($collection as $image_id) {
         $datas[] = array('id' => $image_id, 'level' => $_POST['level']);
     }
     mass_updates(IMAGES_TABLE, array('primary' => array('id'), 'update' => array('level')), $datas);
     if (isset($_SESSION['bulk_manager_filter']['level'])) {
         if ($_POST['level'] < $_SESSION['bulk_manager_filter']['level']) {
             $redirect = true;
         }
     }
 } else {
     if ('add_to_caddie' == $action) {
         fill_caddie($collection);
     } else {
         if ('delete' == $action) {
             if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion']) {
                 $deleted_count = delete_elements($collection, true);
                 if ($deleted_count > 0) {
                     $_SESSION['page_infos'][] = l10n_dec('%d photo was deleted', '%d photos were deleted', $deleted_count);
                     $redirect_url = get_root_url() . 'admin.php?page=' . $_GET['page'];
                     $redirect = true;
                 } else {
                     $page['errors'][] = l10n('No photo can be deleted');
                 }
             } else {
                 $page['errors'][] = l10n('You need to confirm deletion');
             }
         } else {
             if ('metadata' == $action) {
                 sync_metadata($collection);
                 $page['infos'][] = l10n('Metadata synchronized from file');
             } else {
Exemple #8
0
/**
 * API method
 * Deletes an image
 * @param mixed[] $params
 *    @option int|int[] image_id
 *    @option string pwg_token
 */
function ws_images_delete($params, $service)
{
    if (get_pwg_token() != $params['pwg_token']) {
        return new PwgError(403, 'Invalid security token');
    }
    if (!is_array($params['image_id'])) {
        $params['image_id'] = preg_split('/[\\s,;\\|]/', $params['image_id'], -1, PREG_SPLIT_NO_EMPTY);
    }
    $params['image_id'] = array_map('intval', $params['image_id']);
    $image_ids = array();
    foreach ($params['image_id'] as $image_id) {
        if ($image_id > 0) {
            $image_ids[] = $image_id;
        }
    }
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    delete_elements($image_ids, true);
    invalidate_user_cache();
}
function pqv_end_section_init()
{
    global $template, $page;
    if (!pqv_is_active()) {
        return;
    }
    if (empty($page['items'])) {
        return;
    }
    $query = '
SELECT
    id
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $page['items']) . ')
    AND pqv_validated = \'false\'
;';
    $pqv_rejected = query2array($query, null, 'id');
    if (isset($_GET['pqv_delete']) and count($pqv_rejected) > 0) {
        include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
        $deleted_count = delete_elements($pqv_rejected, true);
        if ($deleted_count > 0) {
            invalidate_user_cache();
            $_SESSION['page_infos'][] = l10n_dec('%d photo was deleted', '%d photos were deleted', $deleted_count);
            $redirect_url = duplicate_index_url(array(), array('pqv_delete'));
            redirect($redirect_url);
        }
    }
    if (count($pqv_rejected) > 0) {
        $delete_url = add_url_params(duplicate_index_url(), array('pqv_delete' => 1));
        $template->assign('CONTENT_DESCRIPTION', '<a href="' . $delete_url . '" onclick="return confirm(\'' . l10n('Are you sure?') . '\');">delete the ' . count($pqv_rejected) . ' rejected photo(s)</a>');
    }
}