Example #1
0
function MG_displayMedia($id, $full = 0, $sortOrder = 0, $comments = 0, $spage = 0)
{
    global $_TABLES, $_CONF, $_MG_CONF, $LANG_MG00, $LANG_MG01, $LANG_MG03, $LANG_MG04, $LANG_ACCESS, $_USER;
    $retval = '';
    $aid = DB_getItem($_TABLES['mg_media_albums'], 'album_id', 'media_id="' . addslashes($id) . '"');
    require_once $_CONF['path'] . 'plugins/mediagallery/include/classAlbum.php';
    $mg_album = new mgAlbum($aid);
    $root_album = new mgAlbum(0);
    $pid = 0;
    if (isset($mg_album->pid)) {
        $pid = $mg_album->pid;
    }
    $aOffset = -1;
    $aOffset = $mg_album->getOffset();
    if ($aOffset == -1 || $mg_album->access == 0) {
        $retval = COM_startBlock($LANG_ACCESS['accessdenied'], '', COM_getBlockTemplate('_msg_block', 'header')) . '<br' . XHTML . '>' . $LANG_MG00['access_denied_msg'] . COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
        return array($LANG_MG00['access_denied_msg'], $retval);
    }
    $sql = MG_buildMediaSql(array('album_id' => $aid, 'sortorder' => $mg_album->enable_sort ? $sortOrder : 0));
    $result = DB_query($sql);
    $nRows = DB_numRows($result);
    $total_media = $nRows;
    $media_array = array();
    while ($row = DB_fetchArray($result)) {
        $media_array[] = $row;
        $id_array[] = $row['media_id'];
    }
    $key = array_search($id, $id_array);
    if ($key === false) {
        $retval = COM_startBlock($LANG_ACCESS['accessdenied'], '', COM_getBlockTemplate('_msg_block', 'header')) . '<br' . XHTML . '>' . $LANG_MG00['access_denied_msg'] . COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer'));
        return array($LANG_MG00['access_denied_msg'], $retval);
    }
    $media = $media_array[$key];
    if ($mg_album->full == 2 || $_MG_CONF['discard_original'] == 1 || $mg_album->full == 1 && $_USER['uid'] > 1) {
        $full = 0;
    }
    $disp = $full ? 'orig' : 'disp';
    if ($mg_album->enable_comments == 0) {
        $comments = 0;
    }
    $display_skin = $mg_album->display_skin;
    MG_getCSS($display_skin);
    // construct the album jumpbox...
    $album_jumpbox = '';
    if (!$_MG_CONF['hide_jumpbox_on_mediaview']) {
        $album_jumpbox = MG_buildAlbumJumpbox($root_album, $aid, 1, -1);
    }
    // Update the views count... But only for non-admins
    if (!$root_album->owner_id) {
        $media_views = $media['media_views'] + 1;
        DB_change($_TABLES['mg_media'], 'media_views', $media_views, 'media_id', addslashes($media['media_id']));
    }
    $columns_per_page = $mg_album->display_columns == 0 ? $_MG_CONF['ad_display_columns'] : $mg_album->display_columns;
    $rows_per_page = $mg_album->display_rows == 0 ? $_MG_CONF['ad_display_rows'] : $mg_album->display_rows;
    $_MG_USERPREFS = MG_getUserPrefs();
    if (isset($_MG_USERPREFS['display_rows']) && $_MG_USERPREFS['display_rows'] > 0) {
        $rows_per_page = $_MG_USERPREFS['display_rows'];
    }
    if (isset($_MG_USERPREFS['display_columns']) && $_MG_USERPREFS['display_columns'] > 0) {
        $columns_per_page = $_MG_USERPREFS['display_columns'];
    }
    $media_per_page = $columns_per_page * $rows_per_page;
    if ($mg_album->albums_first) {
        $childCount = $mg_album->getChildCount();
        $page = intval(($key + $childCount) / $media_per_page) + 1;
    } else {
        $page = intval($key / $media_per_page) + 1;
    }
    /*
     * check to see if the original image exists, if not fall back to full image
     */
    $media_size_orig = @getimagesize(Media::getFilePath('orig', $media['media_filename'], $media['media_mime_ext']));
    if ($media_size_orig == false) {
        $full = 0;
        $disp = 'disp';
    }
    $aPage = intval($aOffset / ($root_album->display_columns * $root_album->display_rows)) + 1;
    $birdseed = MG_getBirdseed($mg_album->id, 1, $sortOrder, $aPage);
    $album_link = '<a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $aid . '&amp;page=' . $page . '&amp;sort=' . $sortOrder . '">';
    if ($_MG_CONF['usage_tracking']) {
        MG_updateUsage('media_view', $mg_album->title, $media['media_title'], $media['media_id']);
    }
    // hack for tga files...
    if ($media['mime_type'] == 'image/x-targa' || $media['mime_type'] == 'image/tga') {
        $full = 0;
        $disp = 'disp';
    }
    $prevLink = '';
    $nextLink = '';
    $pagination = '';
    $base_url = $_MG_CONF['site_url'] . "/media.php?f=" . ($full ? '1' : '0') . "&amp;sort=" . $sortOrder;
    list($prevLink, $nextLink) = MG_getNextandPrev($base_url, $nRows, $key, $media_array);
    // generate pagination routine
    if (!empty($prevLink)) {
        $pagination .= '<a href="' . $prevLink . '">' . $LANG_MG03['previous'] . '</a>';
    }
    if (!empty($nextLink)) {
        $pagination .= !empty($prevLink) ? '&nbsp;&nbsp;&nbsp;' : '';
        $pagination .= '<a href="' . $nextLink . '">' . $LANG_MG03['next'] . '</a>';
    }
    $pagination .= LB;
    // hack for testing...>>>
    $media_id = $media['media_id'];
    if ($_MG_CONF['click_image_and_go_next'] && !$_MG_CONF['full_in_popup']) {
        $nextkey = MG_getNextitem($nRows, $key);
        if ($nextkey !== '') {
            $media_id = $media_array[$nextkey]['media_id'];
        }
    }
    $vf = $full;
    if ($media['media_type'] == '0') {
        // image
        $switch_size = $_MG_CONF['site_url'] . "/media.php?f=" . ($full ? '0' : '1') . '&amp;sort=' . $sortOrder . '&amp;s=' . $media['media_id'];
        $lang_switch_size = $full ? $LANG_MG03['normal_size'] : $LANG_MG03['full_size'];
        $switch_viewsize_link = '<a href="' . $switch_size . '">' . $lang_switch_size . '</a>';
    }
    // hack for testing...<<<
    $opt = array('full' => $full, 'media_id' => $media_id, 'sortOrder' => $sortOrder, 'spage' => $spage, 'playback_type' => $mg_album->playback_type, 'skin' => $mg_album->skin, 'display_skin' => $mg_album->display_skin, 'allow_download' => $mg_album->allow_download, 'full_display' => $mg_album->full);
    list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_buildContent($media, $opt);
    $mid = $media['media_id'];
    if ($_MG_CONF['use_upload_time'] == 1) {
        $media_date = MG_getUserDateTimeFormat($media['upload_time']);
    } else {
        $media_date = MG_getUserDateTimeFormat($media['media_time']);
    }
    $rating_box = '';
    if ($mg_album->enable_rating > 0) {
        require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-rating.php';
        $rating_box = MG_getRatingBar($mg_album->enable_rating, $media['media_user_id'], $media['media_id'], $media['media_votes'], $media['media_rating'], '');
    }
    $download_link = '';
    $download = '';
    if ($mg_album->allow_download) {
        $download_link = $_MG_CONF['site_url'] . '/download.php?mid=' . $media['media_id'];
        $download = '<a href="' . $download_link . '">' . $LANG_MG01['download'] . '</a>';
    }
    $edit_item_link = '';
    $edit_item = '';
    if ($mg_album->access == 3 || $_MG_CONF['allow_user_edit'] == true && isset($_USER['uid']) && $media['media_user_id'] == $_USER['uid']) {
        $edit_item_link = $_MG_CONF['site_url'] . '/admin.php?mode=mediaedit&amp;s=1&amp;album_id=' . $aid . '&amp;mid=' . $mid;
        $edit_item = '<a href="' . $edit_item_link . '">' . $LANG_MG01['edit'] . '</a>';
    }
    $media_desc = PLG_replaceTags(nl2br($media['media_desc']));
    if (strlen($media_desc) > 0) {
        $media_desc = '<p style="margin:5px">' . $media_desc . '</p>';
    }
    $getid3link = '';
    $getid3linkend = '';
    $media_properties = $getid3link != '' ? $LANG_MG03['media_properties'] : '';
    $kwText = '';
    $lang_keywords = '';
    if ($mg_album->enable_keywords == 1 && !empty($media['media_keywords'])) {
        $lang_keywords = $LANG_MG01['keywords'];
        $keyWords = array();
        $keyWords = explode(' ', $media['media_keywords']);
        $numKeyWords = count($keyWords);
        for ($i = 0; $i < $numKeyWords; $i++) {
            $keyWords[$i] = str_replace('"', ' ', $keyWords[$i]);
            $searchKeyword = $keyWords[$i];
            $keyWords[$i] = str_replace('_', ' ', $keyWords[$i]);
            $kwText .= '<a href="' . $_MG_CONF['site_url'] . '/search.php?mode=search&amp;swhere=1&amp;keywords=' . $searchKeyword . '&amp;keyType=any">' . $keyWords[$i] . '</a>';
        }
    }
    $media_user_id = $media['media_user_id'];
    if (empty($media_user_id)) {
        $media_user_id = 0;
    }
    $displayname = $_CONF['show_fullname'] ? 'fullname' : 'username';
    $owner_name = DB_getItem($_TABLES['users'], $displayname, "uid = {$media_user_id}");
    if (empty($owner_name)) {
        $owner_name = DB_getItem($_TABLES['users'], 'username', "uid = {$media_user_id}");
        if (empty($owner_name)) {
            $owner_name = 'unknown';
        }
    }
    $owner_link = $owner_name;
    if ($owner_name != 'unknown') {
        $owner_link = '<a href="' . $_CONF['site_url'] . '/users.php?mode=profile&amp;uid=' . $media_user_id . '">' . $owner_name . '</a>';
    }
    $property = '';
    if (($mg_album->exif_display == 2 || $mg_album->exif_display == 3) && $media['media_type'] == 0) {
        require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-exif.php';
        $haveEXIF = MG_haveEXIF($media['media_id']);
        if ($haveEXIF) {
            $property = $_MG_CONF['site_url'] . '/property.php?mid=' . $media['media_id'];
        }
    }
    $media_id = '';
    if ($root_album->owner_id || $_MG_CONF['enable_media_id'] == 1) {
        $media_id = $media['media_id'];
    }
    $exif_info = '';
    if (($mg_album->exif_display == 1 || $mg_album->exif_display == 3) && $media['media_type'] == 0) {
        require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-exif.php';
        $haveEXIF = MG_haveEXIF($media['media_id']);
        if ($haveEXIF) {
            $exif_info = MG_readEXIF($media['media_id'], 2);
        }
    }
    $T = COM_newTemplate(MG_getTemplatePath_byName($mg_album->skin));
    switch ($media['media_type']) {
        case '0':
            // image
            $T->set_file('page', 'view_image.thtml');
            break;
        case '1':
            // video
        // video
        case '5':
            // embedded video
            $T->set_file('page', 'view_video.thtml');
            break;
        case '2':
            // audio
            $T->set_file('page', 'view_audio.thtml');
            break;
        default:
            $T->set_file('page', 'view_image.thtml');
            break;
    }
    $T->set_var(array('header' => $LANG_MG00['plugin'], 'site_url' => $_MG_CONF['site_url'], 'plugin' => 'mediagallery', 'birdseed' => $birdseed, 'lang_slideshow_link' => $LANG_MG03['slide_show'], 'image_detail' => $u_image, 'media_title' => isset($media['media_title']) && $media['media_title'] != ' ' ? PLG_replaceTags($media['media_title']) : '', 'album_title' => $mg_album->title, 'media_desc' => isset($media['media_desc']) && $media['media_desc'] != ' ' ? $media_desc : '', 'media_time' => $media_date[0], 'media_views' => $mg_album->enable_views ? $media['media_views'] : '', 'media_comments' => $mg_album->enable_comments ? $media['media_comments'] : '', 'pagination' => $pagination, 'media_number' => sprintf("%s %d %s %d", $LANG_MG03['image'], $key + 1, $LANG_MG03['of'], $total_media), 'jumpbox' => $album_jumpbox, 'rating_box' => $rating_box, 'download' => $download, 'download_link' => $download_link, 'lang_download' => $LANG_MG01['download'], 'edit_item' => $edit_item, 'edit_item_link' => $edit_item_link, 'lang_edit' => $LANG_MG01['edit'], 'lang_prev' => $LANG_MG03['previous'], 'lang_next' => $LANG_MG03['next'], 'next_link' => $nextLink, 'prev_link' => $prevLink, 'image_height' => $raw_image_height, 'image_width' => $raw_image_width, 'left_side' => intval($raw_image_width / 2) - 1, 'right_side' => intval($raw_image_width / 2), 'raw_image' => $raw_image, 'raw_link_url' => $raw_link_url, 'item_number' => $key + 1, 'total_items' => $total_media, 'lang_of' => $LANG_MG03['of'], 'album_link' => $album_link, 'switch_size' => $switch_size, 'lang_switch_size' => $lang_switch_size, 'switch_size_link' => $switch_viewsize_link, 'getid3' => $getid3link, 'getid3end' => $getid3linkend, 'media_properties' => $media_properties, 'media_keywords' => $kwText, 'lang_keywords' => $lang_keywords, 'owner_username' => $owner_link, 'property' => $property, 'lang_property' => $LANG_MG04['exif_header'], 'media_id' => $media_id, 'exif_info' => $exif_info, 'lang_comments' => $mg_album->enable_comments ? $LANG_MG03['comments'] : '', 'lang_views' => $mg_album->enable_views ? $LANG_MG03['views'] : '', 'lang_title' => $LANG_MG01['title'], 'lang_uploaded_by' => $LANG_MG01['uploaded_by'], 'album_id' => $aid, 'lang_search' => $LANG_MG01['search']));
    MG_buildSlideshow($mg_album, $T, $sortOrder);
    PLG_templateSetVars('mediagallery', $T);
    $retval .= $T->finish($T->parse('output', 'page'));
    if ($comments) {
        // Geeklog Comment support
        $sid = $media['media_id'];
        require_once $_CONF['path_system'] . 'lib-comment.php';
        $delete_option = false;
        if ($mg_album->access == 3 || $root_album->owner_id) {
            $delete_option = true;
        }
        $page = isset($_GET['page']) ? COM_applyFilter($_GET['page'], true) : 0;
        $comorder = '';
        if (isset($_POST['order'])) {
            $comorder = COM_applyFilter($_POST['order']);
        } elseif (isset($_GET['order'])) {
            $comorder = COM_applyFilter($_GET['order']);
        }
        $commode = '';
        if (isset($_POST['mode'])) {
            $commode = COM_applyFilter($_POST['mode']);
        } elseif (isset($_GET['mode'])) {
            $commode = COM_applyFilter($_GET['mode']);
        }
        $commentcode = 0;
        // 今のところ無条件にコメント投稿を許可。
        $retval .= CMT_userComments($sid, $media['media_title'], 'mediagallery', $comorder, $commode, 0, $page, false, $delete_option, $commentcode);
    }
    return array(strip_tags($media['media_title']), $retval, $aid);
}
Example #2
0
$end = $end - $total_media;
$total_items_in_album = $root_album->media_count + $cCount;
$total_pages = ceil($total_items_in_album / $media_per_page);
if ($page >= $total_pages) {
    $page = $total_pages - 1;
}
$start = $page * $media_per_page;
$current_print_page = floor($start / $media_per_page) + 1;
if ($current_print_page == 0) {
    $current_print_page = 1;
}
$total_print_pages = $total_pages;
if ($total_print_pages == 0) {
    $total_print_pages = 1;
}
$birdseed = MG_getBirdseed(0, 0, 0, $total_print_pages);
$ownername = DB_getItem($_TABLES['users'], 'username', "uid=" . intval($root_album->owner_id));
$album_last_update = MG_getUserDateTimeFormat($root_album->last_update);
$pagination = COM_printPageNavigation($_MG_CONF['site_url'] . '/index.php', $page + 1, $total_pages);
$rsslink = '';
if ($_MG_CONF['rss_full_enabled']) {
    $rsslink = COM_createLink(COM_createImage(MG_getImageFile('feed.png'), '', array('class' => 'mg_rssimg')), MG_getFeedUrl($_MG_CONF['rss_feed_name'] . '.rss'), array('type' => 'application/rss+xml'));
}
$T = COM_newTemplate(MG_getTemplatePath_byName($root_album->skin));
$T->set_file('page', 'album_page.thtml');
$T->set_var(array('site_url' => $_MG_CONF['site_url'], 'birdseed' => $birdseed, 'album_title' => PLG_replaceTags($root_album->title), 'table_columns' => $columns_per_page, 'table_column_width' => intval(100 / $columns_per_page) . '%', 'top_pagination' => $pagination, 'bottom_pagination' => $pagination, 'page_number' => sprintf("%s %d %s %d", $LANG_MG03['page'], $current_print_page, $LANG_MG03['of'], $total_print_pages), 'jumpbox' => MG_buildAlbumJumpbox($root_album, $album_id, 1, -1), 'album_id' => $album_id, 'album_description' => $root_album->display_album_desc ? PLG_replaceTags($root_album->description) : '', 'album_id_display' => $root_album->owner_id || $_MG_CONF['enable_media_id'] == 1 ? $LANG_MG03['album_id_display'] . $album_id : '', 'select_adminbox' => COM_isAnonUser() ? '' : MG_buildAdminbox($root_album), 'album_last_update' => $album_last_update[0], 'album_owner' => $ownername, 'media_count' => $root_album->getMediaCount(), 'lang_menulabel' => $LANG_MG03['menulabel'], 'lang_search' => $LANG_MG01['search'], 'rsslink' => $rsslink, 'list_title' => $LANG_MG03['list_title'], 'list_desc' => $LANG_MG03['list_desc'], 'list_size' => $LANG_MG03['list_size'], 'list_user' => $LANG_MG03['list_user'], 'list_updated' => $LANG_MG03['list_updated']));
// completed setting header / footer vars, parse them
PLG_templateSetVars('mediagallery', $T);
// main processing of the album contents.
if ($total_media > 0) {
    $k = 0;
Example #3
0
    $page = $total_pages - 1;
}
$start = $page * $media_per_page;
$current_print_page = floor($start / $media_per_page) + 1;
if ($current_print_page == 0) {
    $current_print_page = 1;
}
$total_print_pages = $total_pages;
if ($total_print_pages == 0) {
    $total_print_pages = 1;
}
$aPage = 1;
if ($aOffset > 0) {
    $aPage = intval($aOffset / ($root_album->display_columns * $root_album->display_rows)) + 1;
}
$birdseed = MG_getBirdseed($album_id, 0, $sortOrder, $aPage);
$ownername = DB_getItem($_TABLES['users'], 'username', "uid=" . intval($album->owner_id));
$album_last_update = MG_getUserDateTimeFormat($album->last_update);
$pagination = COM_printPageNavigation($_MG_CONF['site_url'] . '/album.php?aid=' . $album_id . '&amp;sort=' . $sortOrder, $page + 1, $total_pages);
$rsslink = '';
if ($album->enable_rss) {
    $rssfeedname = sprintf($_MG_CONF['rss_feed_name'] . "%06d", $album_id);
    $rsslink = COM_createLink(COM_createImage(MG_getImageFile('feed.png'), '', array('class' => 'mg_rssimg')), MG_getFeedUrl($rssfeedname . '.rss'), array('type' => 'application/rss+xml'));
}
$T = COM_newTemplate(MG_getTemplatePath_byName($album->skin));
$T->set_file('page', 'album_page.thtml');
$T->set_var(array('site_url' => $_MG_CONF['site_url'], 'birdseed' => $birdseed, 'album_title' => PLG_replaceTags($album->title), 'table_columns' => $columns_per_page, 'table_column_width' => intval(100 / $columns_per_page) . '%', 'top_pagination' => $pagination, 'bottom_pagination' => $pagination, 'page_number' => sprintf("%s %d %s %d", $LANG_MG03['page'], $current_print_page, $LANG_MG03['of'], $total_print_pages), 'jumpbox' => MG_buildAlbumJumpbox($root_album, $album_id, 1, -1), 'album_id' => $album_id, 'album_description' => $album->display_album_desc ? PLG_replaceTags($album->description) : '', 'album_id_display' => $root_album->owner_id || $_MG_CONF['enable_media_id'] == 1 ? $LANG_MG03['album_id_display'] . $album_id : '', 'select_sortbox' => $album->enable_sort == 1 ? MG_buildSortbox($album_id, $sortOrder, $page) : '', 'album_last_update' => $album_last_update[0], 'album_owner' => $ownername, 'media_count' => $album->getMediaCount(), 'lang_search' => $LANG_MG01['search'], 'rsslink' => $rsslink, 'list_title' => $LANG_MG03['list_title'], 'list_desc' => $LANG_MG03['list_desc'], 'list_size' => $LANG_MG03['list_size'], 'list_user' => $LANG_MG03['list_user'], 'list_updated' => $LANG_MG03['list_updated']));
MG_buildAdminbox($album, $root_album, $T);
MG_buildSlideshow($album, $T, $sortOrder);
// completed setting header / footer vars, parse them
PLG_templateSetVars('mediagallery', $T);