Example #1
0
/**
 * Displays the list of all assets from the selected album
 * @refresh_center determines if we need to refresh the whole page / the center 
 * of the page or another part of the page (mainly the right side)
 * @global type $input
 * @global type $repository_path
 * @global type $ezplayer_url
 * @global type $assets_list
 * @global string $panel_display
 */
function view_album_assets($refresh_center = true)
{
    global $input;
    global $repository_path;
    global $ezplayer_url;
    // used in a popup window
    global $user_files_path;
    global $assets_list;
    global $album;
    global $album_bookmarks;
    global $toc_bookmarks;
    global $error_path;
    // used to display an error on the main page
    global $login_error;
    // used to display error when anonymous user login
    global $default_bookmarks_order;
    global $default_toc_order;
    global $cache_limit;
    // if reloaded is set, the whole page has to be refreshed
    if ($_SESSION['reloaded']) {
        unset($input['click']);
        unset($_SESSION['reloaded']);
        $refresh_center = true;
    }
    $error_path = '';
    if (isset($input['album'])) {
        $album = $input['album'];
    } else {
        $album = $_SESSION['album'];
    }
    if (isset($input['token'])) {
        $token = $input['token'];
    } else {
        $token = $_SESSION['token'];
    }
    ezmam_repository_path($repository_path);
    user_prefs_repository_path($user_files_path);
    // 0) Sanity checks
    if (!ezmam_album_exists($album)) {
        if ($input['click']) {
            // refresh a part of the page
            include_once template_getpath('error_album_not_found.php');
        } else {
            // refresh the whole page
            $error_path = template_getpath('error_album_not_found.php');
            include_once template_getpath('main.php');
        }
        log_append('warning', 'view_album_assets: tried to access non-existant album ' . $input['album']);
        exit;
    }
    // Authorization check
    if (!ezmam_album_token_check($album, $token)) {
        if ($input['click']) {
            include_once template_getpath('error_permission_denied.php');
        } else {
            $error_path = template_getpath('error_permission_denied.php');
            include_once template_getpath('main.php');
        }
        log_append('warning', 'view_album_assets: tried to access album ' . $input['album'] . ' with invalid token ' . $input['token']);
        die;
    }
    // 1) Retrieving all assets' metadata
    $assets_list = ezmam_asset_list_metadata($album);
    $count = count($assets_list);
    // add the asset token to the metadata
    for ($index = 0; $index < $count; $index++) {
        $assets_list[$index]['token'] = ezmam_asset_token_get($album, $assets_list[$index]['name']);
    }
    // 2) Save current album
    log_append('view_album_assets: ' . $album);
    $_SESSION['ezplayer_mode'] = 'view_album_assets';
    // used in 'div_assets_center.php'
    $_SESSION['album'] = $album;
    // used in search
    $_SESSION['asset'] = '';
    $_SESSION['token'] = $token;
    // 3) Add current album to the album list
    //    and load album bookmarks
    //
    $album_name = get_album_title($album);
    $album_token = array('title' => $album_name, 'album' => $album, 'token' => $token);
    if (!token_array_contains($_SESSION['acl_album_tokens'], $album_token)) {
        if (acl_user_is_logged()) {
            // logged user : consulted albums are stored in file
            user_prefs_token_add($_SESSION['user_login'], $album, $album_name, $token);
            log_append('view_album_assets: album token added - ' . $album);
            trace_append(array('2', 'album_token_add', $album));
            // lvl, action, album
        } else {
            // anonymous user : consulted albums are stored in session var
            $_SESSION['acl_album_tokens'][] = $album_token;
        }
        acl_update_permissions_list();
    }
    if (acl_user_is_logged()) {
        // bookmarks to display in 'div_side_assets.php'
        $album_bookmarks = user_prefs_album_bookmarks_list_get($_SESSION['user_login'], $album);
        // sorts the bookmarks following user's prefs
        $order = acl_value_get("bookmarks_order");
        if (isset($order) && $order != '' && $order != $default_bookmarks_order) {
            $album_bookmarks = array_reverse($album_bookmarks);
        }
    }
    // 4) table of contents to display in 'div_side_assets.php'
    $toc_bookmarks = toc_album_bookmarks_list_get($album);
    // sorts the bookmarks following user's prefs
    $order = acl_value_get("toc_order");
    if (isset($order) && $order != '' && $order != $default_toc_order) {
        $toc_bookmarks = array_reverse($toc_bookmarks);
    }
    if ($refresh_center) {
        if (acl_display_threads()) {
            $threads = threads_select_by_album($album, $cache_limit);
            foreach ($threads as &$thread) {
                if (!thread_is_archive($thread['albumName'], $thread['assetName'])) {
                    $threads_list[] = $thread;
                }
            }
        }
        if ($input['click']) {
            // called by a local link
            // lvl, action, album, origin
            trace_append(array('2', 'view_album_assets', $album, 'from_ezplayer'));
            include_once template_getpath('div_assets_center.php');
        } else {
            // accessed by the UV or shared link
            // lvl, action, album, origin
            trace_append(array('2', 'view_album_assets', $album, 'from_external'));
            include_once template_getpath('main.php');
        }
    } else {
        // refresh only the side panel (after import / export / deletion / ...)
        include_once template_getpath('div_side_assets.php');
    }
}
Example #2
0
/**
 * Displays the flash player
 * @global type $input 
 */
function view_embed()
{
    global $input;
    global $repository_path;
    global $flash_only_browsers;
    global $template_folder;
    global $ezmanager_url;
    // Sanity checks
    if (!isset($input['album']) || !isset($input['asset']) || !isset($input['quality']) || !isset($input['type']) || !isset($input['token'])) {
        echo "Usage: distribute.php?action=embed&amp;album=ALBUM&amp;asset=ASSET&amp;type=TYPE&amp;quality=QUALITY&amp;token=TOKEN<br/>";
        echo "Optional parameters: width: Video width in pixels. height: video height in pixels. iframe: set to true if you want the return code to be an iframe instead of a full HTML page";
        die;
    }
    if (!ezmam_album_exists($input['album'])) {
        error_print_http(404);
        log_append('warning', 'view_embed: tried to access non-existant album ' . $input['album']);
        die;
    }
    if (!ezmam_asset_exists($input['album'], $input['asset'])) {
        error_print_http(404);
        log_append('warning', 'tried to access non-existant asset ' . $input['asset'] . ' of album ' . $input['album']);
        die;
    }
    if (!ezmam_album_token_check($input['album'], $input['token']) && !ezmam_asset_token_check($input['album'], $input['asset'], $input['token'])) {
        error_print_http(403);
        log_append('warning', 'view_media: tried to access asset ' . $input['asset'] . ' from album ' . $input['album'] . ' with invalid token ' . $input['token']);
        die;
    }
    // Then we retrieve the useful information, i.e. the media path and the dimensions
    // Fallback: if the media doesn't exist in the requested quality,
    // we try to find it in another one available
    $media_name = $input['quality'] . '_' . $input['type'];
    if (!ezmam_media_exists($input['album'], $input['asset'], $media_name)) {
        if ($input['quality'] == 'high') {
            $media_name = 'low_' . $input['type'];
        } else {
            if ($input['quality'] == 'low') {
                $media_name = 'high_' . $input['type'];
            }
        }
        // If no quality is available, we tell that to the user.
        if (!ezmam_media_exists($input['album'], $input['asset'], $media_name)) {
            error_print_http(404);
            die;
        }
    }
    $metadata = ezmam_media_metadata_get($input['album'], $input['asset'], $media_name);
    $width = $metadata['width'];
    if (isset($input['width']) && !empty($input['width'])) {
        $width = $input['width'] - 5;
    }
    $height = $metadata['height'];
    if (isset($input['height']) && !empty($input['height'])) {
        $height = $input['height'] - 5;
    }
    $origin = $input['origin'] == 'ezmanager' ? 'ezmanager' : 'embed';
    $media_url = urlencode(ezmam_media_geturl($input['album'], $input['asset'], $media_name) . '&origin=' . $origin);
    $player_url = $ezmanager_url . '/swf/bugatti.swf';
    // And finally we display the player through a template!
    // If the user wanted to have the player in an iframe, we must change the code a little bit
    if (isset($input['iframe']) && $input['iframe'] == 'true') {
        $origin = $input['origin'] == 'ezmanager' ? 'ezmanager' : 'embed';
        echo '<iframe style="padding: 0; z-index: 100;" frameborder="0" scrolling="no" src="distribute.php?action=embed&amp;album=' . $input['album'] . '&amp;asset=' . $input['asset'] . '&amp;type=' . $input['type'] . '&amp;quality=' . $input['quality'] . '&amp;token=' . $input['token'] . '&amp;width=' . $width . '&amp;height=' . $height . '&amp;origin=' . $origin . '" width="' . $width . '" height="' . $height . '"></iframe>';
    } else {
        template_repository_path($template_folder . 'en');
        require_once template_getpath('embed_header.php');
        // We check if the user's browser is a flash-only browser or if it accepts HTML5
        // It's a Flash browser IIF
        // UA includes 'Firefox' OR UA includes 'MSIE' BUT UA does not include 'MSIE 9.'
        // TODO: prepare for future revisions of MSIE
        if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8.') !== false) {
            require_once template_getpath('embed_flash.php');
            require_once template_getpath('embed_footer.php');
            die;
        }
        // Otherwise, if it accepts HTML5, we display the HTML5 browser
        require_once template_getpath('embed_html5.php');
        require_once template_getpath('embed_footer.php');
    }
}