function vjs_begin_delete_elements($ids) { if (count($ids) == 0) { return 0; } $vjs_extensions = array('ogg', 'ogv', 'mp4', 'm4v', 'webm', 'webmv'); $files_ext = array_merge(array(), $vjs_extensions, array_map('strtoupper', $vjs_extensions)); // Find details base on ID and if supported video files $query = ' SELECT id, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $ids) . ') AND ' . SQL_VIDEOS . ' ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if (url_is_remote($row['path'])) { continue; } $files = array(); $files[] = get_element_path($row); $ok = true; if (!isset($conf['never_delete_originals'])) { foreach ($files as $path) { // Don't delete the actual video or representative // It is done by PWG core // Delete any other video source format $file_wo_ext = pathinfo($path); $file_dir = dirname($path); foreach ($files_ext as $file_ext) { $path_ext = $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . "." . $file_ext; if (is_file($path_ext) and !unlink($path_ext)) { $ok = false; trigger_error('"' . $path_ext . '" cannot be removed', E_USER_WARNING); break; } } // Delete video thumbnails $filematch = $file_dir . "/pwg_representative/" . $file_wo_ext['filename'] . "-th_*"; $matches = glob($filematch); if (is_array($matches)) { foreach ($matches as $filename) { if (is_file($filename) and !unlink($filename)) { $ok = false; trigger_error('"' . $filename . '" cannot be removed', E_USER_WARNING); break; } } } // End videos thumbnails } // End for each files } // End IF } // End While }
while ($row = pwg_db_fetch_assoc($result)) { if (isset($page['previous_item']) and $row['id'] == $page['previous_item']) { $i = 'previous'; } elseif (isset($page['next_item']) and $row['id'] == $page['next_item']) { $i = 'next'; } elseif (isset($page['first_item']) and $row['id'] == $page['first_item']) { $i = 'first'; } elseif (isset($page['last_item']) and $row['id'] == $page['last_item']) { $i = 'last'; } else { $i = 'current'; } $row['src_image'] = new SrcImage($row); $row['derivatives'] = DerivativeImage::get_all($row['src_image']); if ($i == 'current') { $row['element_path'] = get_element_path($row); if ($row['src_image']->is_original()) { // we have a photo if ($user['enabled_high'] == 'true') { $row['element_url'] = $row['src_image']->get_url(); $row['download_url'] = get_action_url($row['id'], 'e', true); } } else { // not a pic - need download link $row['download_url'] = $row['element_url'] = get_element_url($row); } } $row['url'] = duplicate_picture_url(array('image_id' => $row['id'], 'image_file' => $row['file']), array('start')); $picture[$i] = $row; $picture[$i]['TITLE'] = render_element_name($row); $picture[$i]['TITLE_ESC'] = str_replace('"', '"', $picture[$i]['TITLE']);
/** * Deletes all files (on disk) related to given image ids. * * @param int[] $ids * @return 0|int[] image ids where files were successfully deleted */ function delete_element_files($ids) { global $conf; if (count($ids) == 0) { return 0; } $new_ids = array(); $query = ' SELECT id, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $ids) . ') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if (url_is_remote($row['path'])) { continue; } $files = array(); $files[] = get_element_path($row); if (!empty($row['representative_ext'])) { $files[] = original_to_representative($files[0], $row['representative_ext']); } $ok = true; if (!isset($conf['never_delete_originals'])) { foreach ($files as $path) { if (is_file($path) and !unlink($path)) { $ok = false; trigger_error('"' . $path . '" cannot be removed', E_USER_WARNING); break; } } } if ($ok) { delete_element_derivatives($row); $new_ids[] = $row['id']; } else { break; } } return $new_ids; }
$file = ''; switch ($_GET['part']) { case 'e': if (!$user['enabled_high']) { $deriv = new DerivativeImage(IMG_XXLARGE, new SrcImage($element_info)); if (!$deriv->same_as_source()) { do_error(401, 'Access denied e'); } } $file = get_element_path($element_info); break; case 'r': $file = original_to_representative(get_element_path($element_info), $element_info['representative_ext']); break; case 'f': $file = original_to_format(get_element_path($element_info), $format['ext']); $element_info['file'] = get_filename_wo_extension($element_info['file']) . '.' . $format['ext']; break; } if (empty($file)) { do_error(404, 'Requested file not found'); } if ($_GET['part'] == 'e') { pwg_log($_GET['id'], 'high'); } else { if ($_GET['part'] == 'e') { pwg_log($_GET['id'], 'other'); } else { if ($_GET['part'] == 'f') { pwg_log($_GET['id'], 'high', $format['format_id']); }
function pshare_section_init() { global $tokens, $page, $conf, $user, $template; if ($tokens[0] == 'pshare') { $page['section'] = 'pshare'; $page['title'] = l10n('Shared Picture'); if (!isset($tokens[1])) { die("missing key"); } if (!preg_match(PSHARE_KEY_PATTERN, $tokens[1])) { die("invalid key"); } $page['pshare_key'] = $tokens[1]; $query = ' SELECT *, NOW() AS dbnow FROM ' . PSHARE_KEYS_TABLE . ' WHERE uuid = \'' . $page['pshare_key'] . '\' ;'; $shares = query2array($query); if (count($shares) == 0) { die('unknown key'); } $share = $shares[0]; pshare_log($share['pshare_key_id'], 'visit'); // is the key still valid? if (strtotime($share['expire_on']) < strtotime($share['dbnow'])) { die('expired key'); } // if the user is permitted for this photo, let's redirect to // picture.php (with full details and actions) if (!is_a_guest() and pshare_is_photo_visible($share['image_id'])) { // find the first reachable category linked to the photo $query = ' SELECT category_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE image_id = ' . $share['image_id'] . ' ;'; $authorizeds = array_diff(array_from_query($query, 'category_id'), explode(',', calculate_permissions($user['id'], $user['status']))); foreach ($authorizeds as $category_id) { $url = make_picture_url(array('image_id' => $share['image_id'], 'category' => get_cat_info($category_id))); if (function_exists('Fotorama_is_replace_picture') and Fotorama_is_replace_picture()) { $url .= '&slidestop'; } redirect($url); } redirect(make_picture_url(array('image_id' => $share['image_id']))); } $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id = ' . $share['image_id'] . ' ;'; $rows = query2array($query); $image = $rows[0]; $src_image = new SrcImage($image); if (isset($tokens[2]) && 'download' == $tokens[2]) { $format_id = null; if (isset($tokens[3]) && preg_match('/^f(\\d+)$/', $tokens[3], $matches)) { $format_id = $matches[1]; $query = ' SELECT * FROM ' . IMAGE_FORMAT_TABLE . ' WHERE format_id = ' . $format_id . ' AND image_id = ' . $image['id'] . ' ;'; $formats = query2array($query); if (count($formats) == 0) { do_error(400, 'Invalid request - format'); } $format = $formats[0]; $file = original_to_format(get_element_path($image), $format['ext']); $image['file'] = get_filename_wo_extension($image['file']) . '.' . $format['ext']; } else { $file = $image['path']; } $gmt_mtime = gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT'; $http_headers = array('Content-Length: ' . @filesize($file), 'Last-Modified: ' . $gmt_mtime, 'Content-Type: ' . mime_content_type($file), 'Content-Disposition: attachment; filename="' . $image['file'] . '";', 'Content-Transfer-Encoding: binary'); foreach ($http_headers as $header) { header($header); } readfile($file); pshare_log($share['pshare_key_id'], 'download', $format_id); exit; } $template->set_filename('shared_picture', realpath(PSHARE_PATH . 'template/shared_picture.tpl')); $derivative = new DerivativeImage(ImageStdParams::get_by_type(IMG_MEDIUM), $src_image); $derivative_size = $derivative->get_size(); // a random string to avoid browser cache $rand = '&download=' . substr(md5(time()), 0, 6); $template->assign(array('SRC' => $derivative->get_url(), 'IMG_WIDTH' => $derivative_size[0], 'IMG_HEIGHT' => $derivative_size[1], 'DOWNLOAD_URL' => duplicate_index_url() . '/' . $page['pshare_key'] . '/download' . $rand)); // formats if (defined('IMAGE_FORMAT_TABLE')) { $query = ' SELECT * FROM ' . IMAGE_FORMAT_TABLE . ' WHERE image_id = ' . $share['image_id'] . ' ;'; $formats = query2array($query); if (!empty($formats)) { foreach ($formats as &$format) { $format['download_url'] = duplicate_index_url() . '/' . $page['pshare_key'] . '/download'; $format['download_url'] .= '/f' . $format['format_id'] . $rand; $format['filesize'] = sprintf('%.1fMB', $format['filesize'] / 1024); } } $template->assign('formats', $formats); } $template->parse('shared_picture'); $template->p(); exit; } }
do_error(401, 'Access denied'); } include_once PHPWG_ROOT_PATH . 'include/functions_picture.inc.php'; $file = ''; switch ($_GET['part']) { case 'e': if (!$user['enabled_high']) { $deriv = new DerivativeImage(IMG_XXLARGE, new SrcImage($element_info)); if (!$deriv->same_as_source()) { do_error(401, 'Access denied e'); } } $file = get_element_path($element_info); break; case 'r': $file = original_to_representative(get_element_path($element_info), $element_info['representative_ext']); break; } if (empty($file)) { do_error(404, 'Requested file not found'); } if ($_GET['part'] == 'e') { pwg_log($_GET['id'], 'high'); } else { if ($_GET['part'] == 'e') { pwg_log($_GET['id'], 'other'); } } $http_headers = array(); $ctype = null; if (!url_is_remote($file)) {