function pick($src_image) { $ok = false; foreach ($this->candidates as $candidate) { $deriv = new DerivativeImage($candidate, $src_image); $size = $deriv->get_size(); if ($size[1] >= $row_height - 2) { $ok = true; break; } } if (!$ok) { $deriv = new DerivativeImage($this->default, $src_image); } return $deriv; }
;'; $result = pwg_query($query); if (pwg_db_num_rows($result) > 0) { // template thumbnail initialization $current_rank = 1; $derivativeParams = ImageStdParams::get_by_type(IMG_SQUARE); while ($row = pwg_db_fetch_assoc($result)) { $derivative = new DerivativeImage($derivativeParams, new SrcImage($row)); if (!empty($row['name'])) { $thumbnail_name = $row['name']; } else { $file_wo_ext = get_filename_wo_extension($row['file']); $thumbnail_name = str_replace('_', ' ', $file_wo_ext); } $current_rank++; $template->append('thumbnails', array('ID' => $row['id'], 'NAME' => $thumbnail_name, 'TN_SRC' => $derivative->get_url(), 'RANK' => $current_rank * 10, 'SIZE' => $derivative->get_size())); } } // image order management $sort_fields = array('' => '', 'file ASC' => l10n('File name, A → Z'), 'file DESC' => l10n('File name, Z → A'), 'name ASC' => l10n('Photo title, A → Z'), 'name DESC' => l10n('Photo title, Z → A'), 'date_creation DESC' => l10n('Date created, new → old'), 'date_creation ASC' => l10n('Date created, old → new'), 'date_available DESC' => l10n('Date posted, new → old'), 'date_available ASC' => l10n('Date posted, old → new'), 'rating_score DESC' => l10n('Rating score, high → low'), 'rating_score ASC' => l10n('Rating score, low → high'), 'hit DESC' => l10n('Visits, high → low'), 'hit ASC' => l10n('Visits, low → high'), 'id ASC' => l10n('Numeric identifier, 1 → 9'), 'id DESC' => l10n('Numeric identifier, 9 → 1'), 'rank ASC' => l10n('Manual sort order')); $template->assign('image_order_options', $sort_fields); $image_order = explode(',', $category['image_order']); for ($i = 0; $i < 3; $i++) { if (isset($image_order[$i])) { $template->append('image_order', $image_order[$i]); } else { $template->append('image_order', ''); } } $template->assign('image_order_choice', $image_order_choice); // +-----------------------------------------------------------------------+
function modus_index_category_thumbnails($items) { global $page, $template, $conf; if ('categories' != $page['section'] || !($wh = @$conf['modus_theme']['album_thumb_size'])) { return $items; } $template->assign('album_thumb_size', $wh); $def_params = ImageStdParams::get_custom($wh, $wh, 1, $wh, $wh); foreach (ImageStdParams::get_defined_type_map() as $params) { if ($params->max_height() == $wh) { $alt_params = $params; } } foreach ($items as &$item) { $src_image = $item['representative']['src_image']; $src_size = $src_image->get_size(); $deriv = null; if (isset($alt_params) && $src_size[0] >= $src_size[1]) { $dsize = $alt_params->compute_final_size($src_size); if ($dsize[0] >= $wh && $dsize[1] >= $wh) { $deriv = new DerivativeImage($alt_params, $src_image); $rect = new ImageRect($dsize); $rect->crop_h($dsize[0] - $wh, $item['representative']['coi']); $rect->crop_v($dsize[1] - $wh, $item['representative']['coi']); $l = -$rect->l; $t = -$rect->t; } } if (!isset($deriv)) { $deriv = new DerivativeImage($def_params, $src_image); $dsize = $deriv->get_size(); $l = intval($wh - $dsize[0]) / 2; $t = intval($wh - $dsize[1]) / 2; } $item['modus_deriv'] = $deriv; if (!empty($item['icon_ts'])) { $item['icon_ts']['TITLE'] = time_since($item['max_date_last'], 'month'); } $styles = array(); if ($l < -1 || $l > 1) { $styles[] = 'left:' . 100 * $l / $wh . '%'; } if ($t < -1 || $t > 1) { $styles[] = 'top:' . $t . 'px'; } if (count($styles)) { $styles = ' style=' . implode(';', $styles); } else { $styles = ''; } $item['MODUS_STYLE'] = $styles; } return $items; }
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; } }