Beispiel #1
0
function Fotorama_end_picture()
{
    global $template, $conf, $user, $page;
    if (Fotorama_is_replace_picture()) {
        $url_up = duplicate_index_url(array('start' => floor($page['current_rank'] / $page['nb_image_page']) * $page['nb_image_page']), array('start'));
        //slideshow end
        $template->assign(array('U_SLIDESHOW_STOP' => $url_up));
        $template->assign('replace_picture', true);
    }
    if (!$page['slideshow']) {
        return;
    }
    load_language('plugin.lang', FOTORAMA_PATH);
    $split_limit = 400;
    if ('mobile' == get_device()) {
        $split_limit /= 2;
    }
    $view_offset = null;
    if (count($page['items']) >= 1.2 * $split_limit) {
        $first = $split_limit * 0.2;
        $last = $split_limit - $first;
        $first = $page['current_rank'] - $first;
        if ($first < 0) {
            $first += count($page['items']);
        }
        $last = $page['current_rank'] + $last;
        if ($last >= count($page['items'])) {
            $last -= count($page['items']);
        }
        if ($first < $last) {
            $selection = array_slice($page['items'], $first, $last - $first);
            $view_borders = array(0, count($selection) - 1);
            $view_offset = array('from' => 0, 'offset' => $first);
        } else {
            $selection = array_slice($page['items'], 0, $last);
            $view_borders = array(count($selection), count($selection) - 1);
            $view_offset = array('from' => count($selection), 'offset' => $first - count($selection));
            $selection = array_merge($selection, array_slice($page['items'], $first));
        }
    } else {
        $selection = $page['items'];
        $view_borders = null;
    }
    $query = '
  SELECT *
    FROM ' . IMAGES_TABLE . '
    WHERE id IN (' . implode(',', $selection) . ')
    ORDER BY FIELD(id, ' . implode(',', $selection) . ')
  ;';
    $result = pwg_query($query);
    $current = $template->get_template_vars('current');
    if (isset($current['selected_derivative'])) {
        $type = $current['selected_derivative']->get_type();
    }
    $defined = ImageStdParams::get_defined_type_map();
    if (!isset($type) or !isset($defined[$type])) {
        $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
    }
    $skip = -1;
    $big_type = $type;
    $next_type = $type;
    foreach (ImageStdParams::get_defined_type_map() as $def_type => $params) {
        if ($def_type == $type) {
            $skip = 2;
        }
        if ($skip >= 0) {
            $big_type = $def_type;
        }
        if ($skip >= 1 and $conf['Fotorama']['resize']) {
            $next_type = $def_type;
        }
        if ($skip == 0) {
            break;
        }
        $skip = $skip - 1;
    }
    $type = $next_type;
    // +1 size for inpage slideshow
    if ($conf['Fotorama']['only_fullscreen']) {
        $type = $big_type;
    }
    $type_params = ImageStdParams::get_by_type($type);
    $big_type_params = ImageStdParams::get_by_type($big_type);
    if ($conf['Fotorama']['nav'] == 'thumbs' or $conf['Fotorama']['fullscreen_nav'] == 'thumbs') {
        $has_thumbs = true;
    } else {
        $has_thumbs = false;
    }
    if ($has_thumbs) {
        if ($conf['Fotorama']['square_thumb']) {
            $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
        } else {
            $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']);
        }
    }
    $picture = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        $row['src_image'] = new SrcImage($row);
        $row['derivative'] = new DerivativeImage($type_params, $row['src_image']);
        $row['derivative_big'] = new DerivativeImage($big_type_params, $row['src_image']);
        if ($has_thumbs) {
            $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);
        }
        $row['url'] = duplicate_picture_url(array('image_id' => $row['id'], 'image_file' => $row['file']), array('start'));
        $row['TITLE'] = render_element_name($row);
        $picture[] = $row;
    }
    $picture = trigger_change('fotorama_items', $picture, $selection);
    $template->assign(array('TOTAL_ITEMS' => count($page['items']), 'view_borders' => $view_borders, 'view_offset' => $view_offset, 'current_rank' => array_search($page['image_id'], $selection)));
    $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height());
    $template->assign('items', $picture);
    $template->assign(array('Fotorama' => $conf['Fotorama']));
    $template->assign('Fotorama_has_thumbs', $has_thumbs);
    if (is_file('./themes/' . $user['theme'] . '/template/fotorama.tpl')) {
        $template->set_filenames(array('slideshow' => realpath('./themes/' . $user['theme'] . '/template/fotorama.tpl')));
    } else {
        $template->set_filenames(array('slideshow' => realpath(FOTORAMA_PATH . 'template/fotorama.tpl')));
    }
    $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH . 'template/fotorama-content.tpl'));
}
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 = '&amp;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;
    }
}