예제 #1
0
  FROM ' . IMAGES_TABLE . '
    JOIN ' . IMAGE_CATEGORY_TABLE . ' ON image_id = id
  WHERE category_id = ' . $page['category_id'] . '
  ORDER BY rank
;';
$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', '');
예제 #2
0
 function get_element_update_attributes($file)
 {
     global $conf;
     $data = array();
     $filename = basename($file);
     $extension = get_extension($filename);
     $representative_ext = null;
     if (!isset($conf['flip_picture_ext'][$extension])) {
         $dirname = dirname($file);
         $filename_wo_ext = get_filename_wo_extension($filename);
         $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext);
     }
     $data['representative_ext'] = $representative_ext;
     return $data;
 }
예제 #3
0
/**
 * returns the element name from its filename.
 * removes file extension and replace underscores by spaces
 *
 * @param string $filename
 * @return string name
 */
function get_name_from_file($filename)
{
    return str_replace('_', ' ', get_filename_wo_extension($filename));
}
/**
 * create a picture URL on a specific section for a specific picture
 *
 * @param array
 * @return string
 */
function make_picture_url($params)
{
    global $conf;
    $url = get_root_url() . 'picture';
    if ($conf['php_extension_in_urls']) {
        $url .= '.php';
    }
    if ($conf['question_mark_in_urls']) {
        $url .= '?';
    }
    $url .= '/';
    switch ($conf['picture_url_style']) {
        case 'id-file':
            $url .= $params['image_id'];
            if (isset($params['image_file'])) {
                $url .= '-' . str2url(get_filename_wo_extension($params['image_file']));
            }
            break;
        case 'file':
            if (isset($params['image_file'])) {
                $fname_wo_ext = get_filename_wo_extension($params['image_file']);
                if (ord($fname_wo_ext) > ord('9') or !preg_match('/^\\d+(-|$)/', $fname_wo_ext)) {
                    $url .= $fname_wo_ext;
                    break;
                }
            }
        default:
            $url .= $params['image_id'];
    }
    if (!isset($params['category'])) {
        // make urls shorter ...
        unset($params['flat']);
    }
    $url .= make_section_in_url($params);
    $url = add_well_known_params_in_url($url, $params);
    return $url;
}
// | USA.                                                                  |
// +-----------------------------------------------------------------------+
if (!defined("PHPWG_ROOT_PATH")) {
    die("Hacking attempt!");
}
$errors = array();
$pwatermark = $_POST['w'];
// step 0 - manage upload if any
if (isset($_FILES['watermarkImage']) and !empty($_FILES['watermarkImage']['tmp_name'])) {
    list($width, $height, $type) = getimagesize($_FILES['watermarkImage']['tmp_name']);
    if (IMAGETYPE_PNG != $type) {
        $errors['watermarkImage'] = sprintf(l10n('Allowed file types: %s.'), 'PNG');
    } else {
        $upload_dir = PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'watermarks';
        if (mkgetdir($upload_dir, MKGETDIR_DEFAULT & ~MKGETDIR_DIE_ON_ERROR)) {
            $new_name = get_filename_wo_extension($_FILES['watermarkImage']['name']) . '.png';
            $file_path = $upload_dir . '/' . $new_name;
            if (move_uploaded_file($_FILES['watermarkImage']['tmp_name'], $file_path)) {
                $pwatermark['file'] = substr($file_path, strlen(PHPWG_ROOT_PATH));
            } else {
                $page['errors'][] = $errors['watermarkImage'] = "{$file_path} " . l10n('no write access');
            }
        } else {
            $page['errors'][] = $errors['watermarkImage'] = sprintf(l10n('Add write access to the "%s" directory'), $upload_dir);
        }
    }
}
// step 1 - sanitize HTML input
switch ($pwatermark['position']) {
    case 'topleft':
        $pwatermark['xpos'] = 0;
예제 #6
0
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']);
        }
    }
예제 #7
0
function add_uploaded_file($source_filepath, $original_filename = null, $categories = null, $level = null, $image_id = null, $original_md5sum = null)
{
    // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg
    //
    // 2) keep/resize original
    //
    // 3) register in database
    // TODO
    // * check md5sum (already exists?)
    global $conf, $user;
    if (isset($original_md5sum)) {
        $md5sum = $original_md5sum;
    } else {
        $md5sum = md5_file($source_filepath);
    }
    $file_path = null;
    $is_tiff = false;
    if (isset($image_id)) {
        // this photo already exists, we update it
        $query = '
SELECT
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            $file_path = $row['path'];
        }
        if (!isset($file_path)) {
            die('[' . __FUNCTION__ . '] this photo does not exist in the database');
        }
        // delete all physical files related to the photo (thumbnail, web site, HD)
        delete_element_files(array($image_id));
    } else {
        // this photo is new
        // current date
        list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
        list($year, $month, $day) = preg_split('/[^\\d]/', $dbnow, 4);
        // upload directory hierarchy
        $upload_dir = sprintf(PHPWG_ROOT_PATH . $conf['upload_dir'] . '/%s/%s/%s', $year, $month, $day);
        // compute file path
        $date_string = preg_replace('/[^\\d]/', '', $dbnow);
        $random_string = substr($md5sum, 0, 8);
        $filename_wo_ext = $date_string . '-' . $random_string;
        $file_path = $upload_dir . '/' . $filename_wo_ext . '.';
        list($width, $height, $type) = getimagesize($source_filepath);
        if (IMAGETYPE_PNG == $type) {
            $file_path .= 'png';
        } elseif (IMAGETYPE_GIF == $type) {
            $file_path .= 'gif';
        } elseif (IMAGETYPE_TIFF_MM == $type or IMAGETYPE_TIFF_II == $type) {
            $is_tiff = true;
            $file_path .= 'tif';
        } elseif (IMAGETYPE_JPEG == $type) {
            $file_path .= 'jpg';
        } elseif (isset($conf['upload_form_all_types']) and $conf['upload_form_all_types']) {
            $original_extension = strtolower(get_extension($original_filename));
            if (in_array($original_extension, $conf['file_ext'])) {
                $file_path .= $original_extension;
            } else {
                die('unexpected file type');
            }
        } else {
            die('forbidden file type');
        }
        prepare_directory($upload_dir);
    }
    if (is_uploaded_file($source_filepath)) {
        move_uploaded_file($source_filepath, $file_path);
    } else {
        rename($source_filepath, $file_path);
    }
    @chmod($file_path, 0644);
    if ($is_tiff and pwg_image::get_library() == 'ext_imagick') {
        // move the uploaded file to pwg_representative sub-directory
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = $conf['tiff_representative_ext'];
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $exec = $conf['ext_imagick_dir'] . 'convert';
        if ('jpg' == $conf['tiff_representative_ext']) {
            $exec .= ' -quality 98';
        }
        $exec .= ' "' . realpath($file_path) . '"';
        $dest = pathinfo($representative_file_path);
        $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
        $exec .= ' 2>&1';
        @exec($exec, $returnarray);
        // sometimes ImageMagick creates file-0.jpg (full size) + file-1.jpg
        // (thumbnail). I don't know how to avoid it.
        $representative_file_abspath = realpath($dest['dirname']) . '/' . $dest['basename'];
        if (!file_exists($representative_file_abspath)) {
            $first_file_abspath = preg_replace('/\\.' . $representative_ext . '$/', '-0.' . $representative_ext, $representative_file_abspath);
            if (file_exists($first_file_abspath)) {
                rename($first_file_abspath, $representative_file_abspath);
            }
        }
    }
    //
    // generate pwg_representative in case of video
    //
    $ffmpeg_video_exts = array('wmv', 'mov', 'mkv', 'mp4', 'mpg', 'flv', 'asf', 'xvid', 'divx', 'mpeg', 'avi', 'rm');
    if (isset($original_extension) and in_array($original_extension, $ffmpeg_video_exts)) {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $second = 1;
        $ffmpeg = $conf['ffmpeg_dir'] . 'ffmpeg';
        $ffmpeg .= ' -i "' . $file_path . '"';
        $ffmpeg .= ' -an -ss ' . $second;
        $ffmpeg .= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg';
        $ffmpeg .= ' "' . $representative_file_path . '"';
        // file_put_contents('/tmp/ffmpeg.log', "\n==== ".date('c')."\n".__FUNCTION__.' : '.$ffmpeg."\n", FILE_APPEND);
        @exec($ffmpeg);
        if (!file_exists($representative_file_path)) {
            $representative_ext = null;
        }
    }
    if (isset($original_extension) and 'pdf' == $original_extension and pwg_image::get_library() == 'ext_imagick') {
        $representative_file_path = dirname($file_path) . '/pwg_representative/';
        $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
        $representative_ext = 'jpg';
        $representative_file_path .= $representative_ext;
        prepare_directory(dirname($representative_file_path));
        $exec = $conf['ext_imagick_dir'] . 'convert';
        $exec .= ' -quality 98';
        $exec .= ' "' . realpath($file_path) . '"[0]';
        $dest = pathinfo($representative_file_path);
        $exec .= ' "' . realpath($dest['dirname']) . '/' . $dest['basename'] . '"';
        $exec .= ' 2>&1';
        @exec($exec, $returnarray);
    }
    if (pwg_image::get_library() != 'gd') {
        if ($conf['original_resize']) {
            $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
            if ($need_resize) {
                $img = new pwg_image($file_path);
                $img->pwg_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight'], $conf['original_resize_quality'], $conf['upload_form_automatic_rotation'], false);
                $img->destroy();
            }
        }
    }
    // we need to save the rotation angle in the database to compute
    // width/height of "multisizes"
    $rotation_angle = pwg_image::get_rotation_angle($file_path);
    $rotation = pwg_image::get_rotation_code_from_angle($rotation_angle);
    $file_infos = pwg_image_infos($file_path);
    if (isset($image_id)) {
        $update = array('file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $update['level'] = $level;
        }
        single_update(IMAGES_TABLE, $update, array('id' => $image_id));
    } else {
        // database registration
        $file = pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path));
        $insert = array('file' => $file, 'name' => get_name_from_file($file), 'date_available' => $dbnow, 'path' => preg_replace('#^' . preg_quote(PHPWG_ROOT_PATH) . '#', '', $file_path), 'filesize' => $file_infos['filesize'], 'width' => $file_infos['width'], 'height' => $file_infos['height'], 'md5sum' => $md5sum, 'added_by' => $user['id'], 'rotation' => $rotation);
        if (isset($level)) {
            $insert['level'] = $level;
        }
        if (isset($representative_ext)) {
            $insert['representative_ext'] = $representative_ext;
        }
        single_insert(IMAGES_TABLE, $insert);
        $image_id = pwg_db_insert_id(IMAGES_TABLE);
    }
    if (isset($categories) and count($categories) > 0) {
        associate_images_to_categories(array($image_id), $categories);
    }
    // update metadata from the uploaded file (exif/iptc)
    if ($conf['use_exif'] and !function_exists('read_exif_data')) {
        $conf['use_exif'] = false;
    }
    sync_metadata(array($image_id));
    invalidate_user_cache();
    // cache thumbnail
    $query = '
SELECT
    id,
    path
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
    set_make_full_url();
    // in case we are on uploadify.php, we have to replace the false path
    $thumb_url = preg_replace('#admin/include/i#', 'i', DerivativeImage::thumb_url($image_infos));
    unset_make_full_url();
    fetchRemote($thumb_url, $dest);
    return $image_id;
}
예제 #8
0
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;
    }
}
예제 #9
0
function upload_file_video($representative_ext, $file_path)
{
    global $logger, $conf;
    $logger->info(__FUNCTION__ . ', $file_path = ' . $file_path . ', $representative_ext = ' . $representative_ext);
    if (isset($representative_ext)) {
        return $representative_ext;
    }
    $ffmpeg_video_exts = array('wmv', 'mov', 'mkv', 'mp4', 'mpg', 'flv', 'asf', 'xvid', 'divx', 'mpeg', 'avi', 'rm');
    if (!in_array(strtolower(get_extension($file_path)), $ffmpeg_video_exts)) {
        return $representative_ext;
    }
    $representative_file_path = dirname($file_path) . '/pwg_representative/';
    $representative_file_path .= get_filename_wo_extension(basename($file_path)) . '.';
    $representative_ext = 'jpg';
    $representative_file_path .= $representative_ext;
    prepare_directory(dirname($representative_file_path));
    $second = 1;
    $ffmpeg = $conf['ffmpeg_dir'] . 'ffmpeg';
    $ffmpeg .= ' -i "' . $file_path . '"';
    $ffmpeg .= ' -an -ss ' . $second;
    $ffmpeg .= ' -t 1 -r 1 -y -vcodec mjpeg -f mjpeg';
    $ffmpeg .= ' "' . $representative_file_path . '"';
    @exec($ffmpeg);
    if (!file_exists($representative_file_path)) {
        return null;
    }
    return $representative_ext;
}
예제 #10
0
function render_media($content, $picture)
{
    global $template, $picture, $page, $conf, $user, $refresh;
    // do nothing if the current picture is actually an image !
    if (@$picture['current']['is_picture'] || array_key_exists('src_image', @$picture['current']) && @$picture['current']['src_image']->is_original()) {
        return $content;
    }
    // In case, the we handle a large video, we define a MAX_WIDTH
    // variable to limit the display size.
    if (isset($user['maxwidth']) and $user['maxwidth'] != '') {
        $MAX_WIDTH = $user['maxwidth'];
    } else {
        $MAX_WIDTH = '720';
    }
    // Get video infos with getID3 lib
    require_once dirname(__FILE__) . '/include/getid3/getid3.php';
    $getID3 = new getID3();
    $fileinfo = $getID3->analyze($picture['current']['path']);
    $extension = strtolower(get_extension($picture['current']['path']));
    $basename = strtolower(get_filename_wo_extension($picture['current']['path']));
    $is_video = False;
    // if not a media extension, do nothing
    if (!in_array($extension, $conf['media_ext'])) {
        return $content;
    } else {
        if (isset($fileinfo['video'])) {
            // -- video file --
            $is_video = True;
            if ($extension == 'webm') {
                $extension = 'webmv';
            }
            if ($extension == 'mp4') {
                $extension = 'm4v';
            }
            // guess resolution
            if (isset($fileinfo['video']['resolution_x'])) {
                $width = $fileinfo['video']['resolution_x'];
            }
            if (isset($fileinfo['video']['resolution_y'])) {
                $height = $fileinfo['video']['resolution_y'];
            }
            if (!isset($width) || !isset($height)) {
                // If guess was unsuccessful, fallback to default 16/9 resolution
                // This is the case for ogv video for example.
                $width = $MAX_WIDTH;
                $height = intval(9 * ($width / 16));
            }
        } else {
            // -- audio only file --
            if ($extension == 'webm') {
                $extension = 'webma';
            }
            if ($extension == 'mp4') {
                $extension = 'm4a';
            }
            if ($extension == 'ogg') {
                $extension = 'oga';
            }
            $width = '0';
            $height = '0';
        }
    }
    // Resize if video is too large
    if ($width > $MAX_WIDTH) {
        $height = intval($height * ($MAX_WIDTH / $width));
        $width = $MAX_WIDTH;
    }
    // Slideshow : The video needs to be launch automatically in
    // slideshow mode. The refresh of the page is set to the
    // duration of the video.
    if (isset($conf['jplayer_autoplay']) && $conf['jplayer_autoplay']) {
        $AUTOPLAY = 'play';
    } else {
        $AUTOPLAY = '';
    }
    if ($page['slideshow']) {
        $refresh = $fileinfo['playtime_seconds'];
        $AUTOPLAY = 'play';
    }
    // Picture representative to be used as poster image in the player
    $poster_url = NULL;
    if (isset($picture['current']['src_image']) && isset($conf['jplayer_representative_as_poster']) && $conf['jplayer_representative_as_poster']) {
        $poster_url = $picture['current']['src_image']->get_url();
        $poster_url = embellish_url(get_gallery_home_url() . $poster_url);
        if (strpos($poster_url, "mimetype")) {
            // Ignore mimetype representatives because they're too small
            $poster_url = NULL;
        }
    }
    // Load parameter, fallback to blue monday if unset
    $skin = isset($conf['jplayer_skin']) ? $conf['jplayer_skin'] : 'bm';
    // Select the template
    $template->set_filenames(array('jp_content' => dirname(__FILE__) . "/template/jp-" . $skin . ".tpl"));
    $alternate_media_url = '';
    $alternate_type = '';
    if ($extension == 'webmv') {
        if (file_exists($basename . '.m4v')) {
            $alternate_media_url = str_replace('webm', 'm4v', $picture['current']['element_url']);
            $alternate_type = 'm4v';
        }
    } else {
        if ($extension == 'm4v') {
            if (file_exists($basename . '.webm')) {
                $alternate_media_url = str_replace('m4v', 'webm', $picture['current']['element_url']);
                $alternate_type = 'webmv';
            }
        }
    }
    // Assign the template variables
    // We use here the piwigo's get_gallery_home_url function to build
    // the full URL as suggested by jplayer for flash fallback compatibility
    $template->assign(array('JP_MEDIA_URL' => embellish_url(get_gallery_home_url() . $picture['current']['element_url']), 'ALT_JP_MEDIA_URL' => embellish_url(get_gallery_home_url() . $alternate_media_url), 'JP_POSTER' => $poster_url, 'JPLAYER_PATH' => JPLAYER_PATH, 'JPLAYER_FULLPATH' => realpath(dirname(__FILE__)), 'WIDTH' => $width . 'px', 'HEIGHT' => $height . 'px', 'TYPE' => $extension, 'ALT_TYPE' => $alternate_type, 'AUTOPLAY' => $AUTOPLAY, 'IS_VIDEO' => $is_video));
    // Return the rendered html
    $jp_content = $template->parse('jp_content', true);
    return $jp_content;
}