function cleanup_files($files, $folders) { global $config; $output = array(); $errors = array(); // Delete the files first foreach ($files as $file) { if (file_exists($file)) { if (kill_file($file)) { $output[] = plog_tr('Plogger found and deleted the file') . ': ' . $file; } else { $errors[] = plog_tr('Plogger could not delete the file') . ': ' . $file; } } } // Remove the folders since there should be no files in them foreach ($folders as $folder) { if (file_exists($folder)) { if (kill_dir($folder)) { $output[] = plog_tr('Plogger found and deleted the folder') . ': ' . $folder; } else { $errors[] = plog_tr('Plogger could not delete the folder') . ': ' . $folder; } } } return array('errors' => $errors, 'output' => $output); }
// fully qualified file name //$fqfn = $config['basedir'].'plog-content/uploads/'.$file_name; $fqfn = $file; if (is_file($fqfn)) { if (in_array($file_key, $allow_comments)) { $allow_comment = 1; } else { $allow_comment = 0; } $result = add_picture($album_id, $fqfn, basename($file_name), $captions[$file_key], $descriptions[$file_key], $allow_comment); if ($result['picture_id'] !== false) { $imported++; // Delete thumbnail file if it exists $thumbpath = $config['basedir'] . 'plog-content/thumbs/uploads/import-' . substr($file_key, 0, 2) . '-' . basename($file_name); if (file_exists($thumbpath) && is_readable($thumbpath)) { kill_file($thumbpath); } } } $counter++; } } // Get album name for display $sql = "SELECT name FROM " . PLOGGER_TABLE_PREFIX . "albums WHERE id = {$album_id}"; $result = run_query($sql); $row = mysqli_fetch_assoc($result); $output .= "\n\t" . '<h1>' . plog_tr('Import') . '</h1>'; if ($imported > 0) { $text = $imported == 1 ? plog_tr('image was') : plog_tr('images were'); $output .= "\n\n\t" . '<p class="success width-700">' . sprintf(plog_tr('%s successfully imported to album %s'), '<strong>' . $imported . '</strong> ' . $text, '<strong>' . $row['name'] . '</strong>') . '.</p>' . "\n"; }
function delete_picture($del_id) { global $config, $thumbnail_config; $del_id = intval($del_id); $picture = get_picture_by_id($del_id); if ($picture) { // Check if collection thumbnail = deleted picture and set to default if so $collection = get_collection_by_id($picture['parent_collection']); if ($collection['thumbnail_id'] == $picture['id']) { $query = "UPDATE " . PLOGGER_TABLE_PREFIX . "collections SET \"thumbnail_id\"='0' WHERE id='" . $collection['id'] . "'"; run_query($query); } // Check if album thumbnail = deleted picture and set to default if so $album = get_album_by_id($picture['parent_album']); if ($album['thumbnail_id'] == $picture['id']) { $query = "UPDATE " . PLOGGER_TABLE_PREFIX . "albums SET \"thumbnail_id\"='0' WHERE id='" . $album['id'] . "'"; run_query($query); } $query = "DELETE FROM " . PLOGGER_TABLE_PREFIX . "pictures WHERE \"id\"= '" . $picture['id'] . "'"; run_query($query); // Delete all comments for the picture $query = "DELETE FROM " . PLOGGER_TABLE_PREFIX . "comments WHERE \"parent_id\"= '" . $picture['id'] . "'"; run_query($query); // Make sure that the file is actually located inside our 'plog-content/images/' directory $full_path = $config['basedir'] . 'plog-content/images/' . SmartStripSlashes($picture['path']); // Also check whether this image is in the correct folder $relative_path = substr($full_path, 0, strlen($config['basedir'])); $basename = SmartStripSlashes(basename($picture['path'])); if ($relative_path == $config['basedir']) { foreach ($thumbnail_config as $tval) { $thumbpath = $config['basedir'] . 'plog-content/thumbs/' . dirname($picture['path']) . '/' . $tval['type'] . '/' . $picture['id'] . '-' . $basename; if (file_exists($thumbpath)) { kill_file($thumbpath); } } if (is_file($full_path)) { if (!kill_file($full_path)) { $errors = plog_tr('Could not physically delete file from disk!'); } } } else { $errors = plog_tr('Picture has invalid path, ignoring delete request.'); } } else { $errors = sprintf(plog_tr('There is no picture with id %s.'), '<strong>' . $del_id . '</strong>'); } if (isset($errors)) { return array('errors' => $errors); } return true; }