Beispiel #1
0
function MG_profileblocksdisplay($uid)
{
    global $_TABLES, $_MG_CONF, $_CONF, $LANG_MG10, $_USER;
    $retval = '';
    if ($_MG_CONF['profile_hook'] != 1) {
        return '';
    }
    if ((!isset($_USER['uid']) || $_USER['uid'] < 2) && $_MG_CONF['loginrequired'] == 1) {
        return '';
    }
    if (empty($uid)) {
        return '';
    }
    $username = DB_getItem($_TABLES['users'], 'username', 'uid=' . intval($uid));
    if (empty($username)) {
        return '';
    }
    $T = COM_newTemplate(MG_getTemplatePath(0));
    $T->set_file('mblock', 'profile_media.thtml');
    $T->set_block('mblock', 'itemRow', 'iRow');
    $T->set_var('start_block_last10mediaitems', COM_startBlock($LANG_MG10['last_10'] . $username));
    $T->set_var('start_block_useralbums', COM_startBlock($LANG_MG10['albums_owned'] . $username));
    $T->set_var('lang_thumbnail', $LANG_MG10['thumbnail']);
    $T->set_var('lang_title', $LANG_MG10['title']);
    $T->set_var('lang_album', $LANG_MG10['album']);
    $T->set_var('lang_album_description', $LANG_MG10['album_desc']);
    $T->set_var('lang_upload_date', $LANG_MG10['upload_date']);
    $T->set_var('end_block', COM_endBlock());
    $sql = "SELECT a.album_id,m.media_upload_time,m.media_id,m.media_filename,m.mime_type," . "m.media_mime_ext,m.media_title,m.remote_media,m.media_type,m.media_tn_attached " . "FROM {$_TABLES['mg_albums']} AS a LEFT JOIN {$_TABLES['mg_media_albums']} AS ma " . "ON a.album_id=ma.album_id LEFT JOIN {$_TABLES['mg_media']} AS m ON ma.media_id=m.media_id " . "WHERE m.media_user_id=" . intval($uid) . " AND a.hidden=0 " . COM_getPermSQL('and') . " ORDER BY m.media_upload_time DESC LIMIT 5";
    $result = DB_query($sql);
    $class = 0;
    $mCount = 0;
    while ($row = DB_fetchArray($result)) {
        $album_id = $row['album_id'];
        $album_data = MG_getAlbumData($album_id, array('album_title'));
        $album_title = strip_tags($album_data['album_title']);
        $upload_time = MG_getUserDateTimeFormat($row['media_upload_time']);
        $url_media = $_MG_CONF['site_url'] . '/media.php?s=' . $row['media_id'];
        $url_album = $_MG_CONF['site_url'] . '/album.php?aid=' . $album_id;
        $tn_size = 10;
        list($url_thumb, $p_thumb, $msize) = Media::getThumbInfo($row, $tn_size);
        $atnsize = '';
        if ($msize != false) {
            list($newwidth, $newheight) = Media::getImageWH($msize[0], $msize[1], 50, 50);
            $atnsize = 'width="' . $newwidth . '" height="' . $newheight . '" ';
        }
        $T->set_var('mediaitem_image', '<img src="' . $url_thumb . '" alt="" ' . $atnsize . 'style="border:none;vertical-align:bottom;"' . XHTML . '>');
        $T->set_var('mediaitem_begin_href', '<a href="' . $url_media . '">');
        $T->set_var('mediaitem_title', strip_tags($row['media_title']));
        $T->set_var('mediaitem_end_href', '</a>');
        $T->set_var('mediaitem_album_begin_href', '<a href="' . $url_album . '">');
        $T->set_var('mediaitem_album_title', $album_title);
        $T->set_var('mediaitem_date', $upload_time[0]);
        $T->set_var('rowclass', $class % 2 ? '1' : '2');
        $T->parse('iRow', 'itemRow', true);
        $class++;
        $mCount++;
    }
    if ($mCount != 0) {
        $retval .= $T->finish($T->parse('output', 'mblock'));
    }
    $T = COM_newTemplate(MG_getTemplatePath(0));
    $T->set_file('ablock', 'profile_album.thtml');
    $T->set_block('ablock', 'itemRow', 'iRow');
    $T->set_var('start_block_useralbums', COM_startBlock($LANG_MG10['albums_owned'] . $username));
    $T->set_var('lang_thumbnail', $LANG_MG10['thumbnail']);
    $T->set_var('lang_album', $LANG_MG10['album']);
    $T->set_var('lang_album_description', $LANG_MG10['album_desc']);
    $T->set_var('end_block', COM_endBlock());
    $sql = "SELECT album_id,album_title,album_desc,tn_attached " . "FROM " . $_TABLES['mg_albums'] . " WHERE owner_id=" . intval($uid) . " AND hidden=0 " . COM_getPermSQL('and') . " ORDER BY last_update DESC LIMIT 10";
    $result = DB_query($sql);
    $class = 0;
    $aCount = 0;
    while ($row = DB_fetchArray($result)) {
        $aid = $row['album_id'];
        $url_album = $_MG_CONF['site_url'] . '/album.php?aid=' . $row['album_id'];
        $url_thumb = '';
        $msize = false;
        if ($row['tn_attached'] == 1) {
            list($url_thumb, $msize) = MG_getImageUrl('covers/cover_' . $row['album_id']);
        } else {
            $cover_file = MG_getAlbumCover($aid);
            if ($cover_file != '') {
                $offset = substr($cover_file, 0, 3) == 'tn_' ? 3 : 0;
                list($url_thumb, $msize) = MG_getImageUrl('tn/' . $cover_file[$offset] . '/' . $cover_file);
            }
        }
        if ($msize == false || $url_thumb == '') {
            $url_thumb = $_MG_CONF['mediaobjects_url'] . '/empty.png';
            $msize = getimagesize($_MG_CONF['path_mediaobjects'] . 'empty.png');
        }
        $atnsize = '';
        if ($msize != false) {
            list($newwidth, $newheight) = Media::getImageWH($msize[0], $msize[1], 50, 50);
            $atnsize = 'width="' . $newwidth . '" height="' . $newheight . '" ';
        }
        $T->set_var('album_cover', '<img src="' . $url_thumb . '" alt="" ' . $atnsize . 'style="border:none;vertical-align:bottom;"' . XHTML . '>');
        $T->set_var('album_begin_href', '<a href="' . $url_album . '">');
        $T->set_var('album_title', strip_tags($row['album_title']));
        $T->set_var('album_end_href', '</a>');
        $T->set_var('album_desc', strip_tags($row['album_desc']));
        $T->set_var('rowclass', $class % 2 ? '1' : '2');
        $T->parse('iRow', 'itemRow', true);
        $class++;
        $aCount++;
    }
    if ($aCount != 0) {
        $retval .= $T->finish($T->parse('output', 'ablock'));
    }
    return $retval;
}
Beispiel #2
0
function MG_albumThumbnail($album_id)
{
    global $_MG_CONF, $_TABLES, $_USER, $LANG_MG00, $LANG_MG01, $LANG_MG03;
    $sql = "SELECT album_title,album_parent,album_views,enable_album_views," . "media_count,album_desc,album_cover_filename,last_update,tn_attached " . "FROM {$_TABLES['mg_albums']} " . "WHERE album_id=" . intval($album_id);
    $result = DB_query($sql);
    $album_data = DB_fetchArray($result);
    $cover_filename = $album_data['album_cover_filename'];
    if ($album_data['media_count'] > 0) {
        if ($cover_filename != '' && $cover_filename != '0') {
            // Testing!
            if (strpos($cover_filename, 'tn_') === 0) {
                $tmpfilename = 'tn/' . $cover_filename[3] . '/' . $cover_filename;
            } else {
                $type = $_MG_CONF['gallery_tn_size'];
                // Root album
                if ($album_data['album_parent'] > 0) {
                    $type = DB_getItem($_TABLES['mg_albums'], 'tn_size', 'album_id=' . $album_data['album_parent']);
                }
                $tmpfilename = 'tn/' . $cover_filename[0] . '/' . $cover_filename;
                $tmpfilename = MG_getThumbPath($tmpfilename, $type);
                $tmpfilename = rtrim($tmpfilename, '.');
            }
            list($album_last_image, $mediasize) = MG_getImageUrl($tmpfilename);
            $album_last_update = MG_getUserDateTimeFormat($album_data['last_update']);
            if ($mediasize == false) {
                $album_last_image = $_MG_CONF['mediaobjects_url'] . '/empty.png';
                $mediasize = @getimagesize($_MG_CONF['path_mediaobjects'] . 'empty.png');
            }
        } else {
            $filename = MG_getAlbumCover($album_id);
            if ($filename == '' || $filename == NULL || $filename == " ") {
                $album_last_image = $_MG_CONF['mediaobjects_url'] . '/empty.png';
                $mediasize = @getimagesize($_MG_CONF['path_mediaobjects'] . 'empty.png');
            } else {
                list($album_last_image, $mediasize) = MG_getImageUrl('tn/' . $filename[0] . '/' . $filename);
                if ($mediasize == false) {
                    $album_last_image = $_MG_CONF['mediaobjects_url'] . '/missing.png';
                    $mediasize = @getimagesize($_MG_CONF['path_mediaobjects'] . 'missing.png');
                }
            }
        }
        $album_media_count = $album_data['media_count'];
        if ($album_data['last_update'] > 0) {
            $album_last_update = MG_getUserDateTimeFormat($album_data['last_update']);
            $lang_updated = $_MG_CONF['dfid'] == '99' ? '' : $LANG_MG03['updated_prompt'];
        } else {
            $album_last_update[0] = '';
            $lang_updated = '';
        }
        $lang_updated = $_MG_CONF['dfid'] == '99' ? '' : $LANG_MG03['updated_prompt'];
        if (isset($_USER['uid']) && $_USER['uid'] > 1) {
            $lastlogin = DB_getItem($_TABLES['userinfo'], 'lastlogin', "uid = '" . $_USER['uid'] . "'");
            if ($album_data['last_update'] > $lastlogin) {
                $album_last_update[0] = '<span class="mgUpdated">' . $album_last_update[0] . '</span>';
            }
        }
    } else {
        // nothing in the album yet...
        $filename = MG_getAlbumCover($album_id);
        if ($filename == '') {
            $album_last_image = $_MG_CONF['mediaobjects_url'] . '/empty.png';
            $mediasize = @getimagesize($_MG_CONF['path_mediaobjects'] . 'empty.png');
        } else {
            list($album_last_image, $mediasize) = MG_getImageUrl('tn/' . $filename[0] . '/' . $filename);
            if ($mediasize == false) {
                $album_last_image = $_MG_CONF['mediaobjects_url'] . '/missing.png';
                $mediasize = @getimagesize($_MG_CONF['path_mediaobjects'] . 'missing.png');
            }
        }
        $album_last_update[0] = '';
        $lang_updated = '';
    }
    if ($album_data['tn_attached'] == 1) {
        list($album_last_image, $mediasize) = MG_getImageUrl('covers/cover_' . $album_id);
        if ($mediasize == false) {
            $album_last_image = $_MG_CONF['mediaobjects_url'] . '/missing.png';
            $mediasize = @getimagesize($_MG_CONF['path_mediaobjects'] . 'missing.png');
        }
    }
    $children = MG_getAlbumChildren($album_id);
    $subalbums = count($children);
    $total_images_subalbums = MG_getMediaCount($album_id);
    $parent_album = new mgAlbum($album_data['album_parent']);
    $_MG_USERPREFS = MG_getUserPrefs();
    if (isset($_MG_USERPREFS['tn_size']) && $_MG_USERPREFS['tn_size'] != -1) {
        $tn_size = $_MG_USERPREFS['tn_size'];
    } else {
        $tn_size = $parent_album->tn_size;
    }
    list($tn_height, $tn_width) = MG_getTNSize($tn_size, $parent_album->tnHeight, $parent_album->tnWidth);
    list($newwidth, $newheight) = MG_getImageWH_3($mediasize[0], $mediasize[1], $tn_width, $tn_height);
    $media_item_thumbnail = MG_getFramedImage($parent_album->album_skin, $album_data['album_title'], $_MG_CONF['site_url'] . '/album.php?aid=' . $album_id . '&amp;page=1', $album_last_image, $newwidth, $newheight);
    $C = COM_newTemplate(MG_getTemplatePath($album_data['album_parent']));
    $C->set_file('cell', 'album_page_album_cell.thtml');
    $C->set_var(array('media_item_thumbnail' => $media_item_thumbnail, 'u_viewalbum' => $_MG_CONF['site_url'] . '/album.php?aid=' . $album_id . '&amp;page=1', 'album_last_image' => $album_last_image, 'album_title' => $album_data['album_title'], 'album_media_count' => $album_data['media_count'], 'subalbum_media_count' => $total_images_subalbums, 'album_desc' => PLG_replaceTags($album_data['album_desc']), 'album_last_update' => $album_last_update[0], 'img_height' => $newheight, 'img_width' => $newwidth, 's_media_size' => 'width="' . $newwidth . '" height="' . $newheight . '"', 'row_height' => $tn_height, 'updated' => $lang_updated, 'lang_album' => $LANG_MG00['album'], 'lang_views' => $LANG_MG03['views'], 'views' => $album_data['album_views'], 'lang_views' => $album_data['enable_album_views'] ? $LANG_MG03['views'] : '', 'views' => $album_data['enable_album_views'] ? $album_data['album_views'] : '', 'subalbumcount' => $subalbums > 0 ? '(' . $subalbums . ')' : '', 'lang_subalbums' => $subalbums > 0 ? $LANG_MG01['subalbums'] : ''));
    PLG_templateSetVars('mediagallery', $C);
    $C->parse('output', 'cell');
    $celldisplay = $C->finish($C->get_var('output'));
    return $celldisplay;
}
Beispiel #3
0
function MG_getMP3Items(&$album_data)
{
    global $_TABLES, $_MG_CONF;
    $retval = '';
    if (isset($album_data['album_id'])) {
        $aid = $album_data['album_id'];
        if ($album_data['access'] >= 1) {
            $albumCover = MG_getAlbumCover($aid);
            if ($albumCover != '') {
                if (substr($albumCover, 0, 3) == 'tn_') {
                    $offset = 3;
                } else {
                    $offset = 0;
                }
                foreach ($_MG_CONF['validExtensions'] as $ext) {
                    if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $albumCover[$offset] . '/' . $albumCover . $ext)) {
                        $image = $_MG_CONF['mediaobjects_url'] . '/tn/' . $albumCover[$offset] . '/' . $albumCover . $ext;
                        break;
                    }
                }
            } else {
                $image = '';
            }
            if ($album_data['tn_attached'] == 1) {
                foreach ($_MG_CONF['validExtensions'] as $ext) {
                    if (file_exists($_MG_CONF['path_mediaobjects'] . 'covers/cover_' . $aid . $ext)) {
                        $image = $_MG_CONF['mediaobjects_url'] . '/covers/cover_' . $aid . $ext;
                        break;
                    }
                }
            }
            $sql = MG_buildMediaSql(array('album_id' => $aid, 'fields' => array('media_type', 'media_filename', 'media_mime_ext', 'media_tn_attached', 'media_title', 'artist', 'album', 'media_id'), 'where' => "m.media_type = 2 AND m.mime_type = 'audio/mpeg'"));
            $result = DB_query($sql);
            while ($row = DB_fetchArray($result)) {
                if ($row['media_type'] == 0) {
                    $PhotoURL = MG_getFileUrl($src, $row['media_filename']);
                } else {
                    $PhotoURL = MG_getFileUrl('orig', $row['media_filename'], $row['media_mime_ext']);
                }
                if ($row['media_tn_attached'] == 1) {
                    foreach ($_MG_CONF['validExtensions'] as $ext) {
                        if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext)) {
                            $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                            $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'] . $ext;
                            break;
                        }
                    }
                } else {
                    $media_thumbnail = '';
                }
                if ($media_thumbnail != '') {
                    if (!file_exists($media_thumbnail_file)) {
                        $medai_thumbnail = '';
                    }
                }
                $retval .= "        <track>\n";
                $retval .= "            <title>" . MG_escape($row['media_title']) . "</title>\n";
                $retval .= "            <annotation>" . MG_escape($row['media_title']) . "</annotation>\n";
                if ($row['artist'] != '') {
                    $retval .= "            <creator>" . MG_escape($row['artist']) . "</creator>\n";
                }
                if ($row['album'] != '') {
                    $retval .= "            <album>" . MG_escape($row['album']) . "</album>\n";
                }
                $retval .= "            <identifier>" . $row['media_id'] . "</identifier>\n";
                $retval .= "            <location>" . $PhotoURL . "</location>\n";
                if ($media_thumbnail != '') {
                    $retval .= "            <image>" . $media_thumbnail . "</image>\n";
                } else {
                    if ($image != '') {
                        $retval .= "            <image>" . $image . "</image>\n";
                    }
                }
                $retval .= "        </track>\n";
            }
        }
        return $retval;
    }
}
Beispiel #4
0
function MG_autotags($op, $content = '', $autotag = '')
{
    global $_MG_CONF, $_CONF, $_TABLES, $LANG_MG00, $LANG_MG03, $side_count, $swfjsinclude;
    //@@@@@20120730add---->
    $p1 = COM_applyFilter($autotag['parm1']);
    $p2 = COM_applyFilter($autotag['parm2']);
    $p = MG_parm2($p2);
    //@@@@@20120730add<----
    static $ss_count = 0;
    /*
     * Process the auto tag to remove any embedded &nbsp;
     */
    $tag = str_replace('&nbsp;', ' ', $autotag['tagstr']);
    $parms = explode(' ', $tag);
    // Extra test to see if autotag was entered with a space
    // after the module name
    if (substr($parms[0], -1) == ':') {
        $startpos = strlen($parms[0]) + strlen($parms[1]) + 2;
        $label = str_replace(']', '', substr($tag, $startpos));
        $tagid = $parms[1];
    } else {
        $label = str_replace(']', '', substr($tag, strlen($parms[0]) + 1));
        $parms = explode(':', $parms[0]);
        if (count($parms) > 2) {
            // whoops, there was a ':' in the tag id ...
            array_shift($parms);
            $tagid = implode(':', $parms);
        } else {
            $tagid = $parms[1];
        }
    }
    $autotag['parm1'] = str_replace(']', '', $tagid);
    $autotag['parm2'] = $label;
    /*
     * end of tag replacement
     */
    // see if we have an alignment option included
    $caption = $autotag['parm2'];
    $aSet = 0;
    $skip = 0;
    // default values for parameters
    $border = $_MG_CONF['at_border'];
    $align = $_MG_CONF['at_align'];
    $width = $_MG_CONF['at_width'];
    $height = $_MG_CONF['at_height'];
    $src = $_MG_CONF['at_src'];
    $autoplay = $_MG_CONF['at_autoplay'];
    $enable_link = $_MG_CONF['at_enable_link'];
    $delay = $_MG_CONF['at_delay'];
    $transition = 'Fade';
    $showtitle = $_MG_CONF['at_showtitle'];
    $destination = 'content';
    $target = '';
    $linkID = 0;
    $alt = 0;
    $link_src = 'disp';
    if ($align != '') {
        $aSet = 1;
    }
    // parameter processing - logic borrowed from
    // Dirk Haun's Flickr plugin
    $px = explode(' ', trim($autotag['parm2']));
    if (is_array($px)) {
        foreach ($px as $part) {
            if (substr($part, 0, 6) == 'width:') {
                $a = explode(':', $part);
                $width = $a[1];
                $skip++;
            } elseif (substr($part, 0, 7) == 'height:') {
                $a = explode(':', $part);
                $height = $a[1];
                $skip++;
            } elseif (substr($part, 0, 7) == 'border:') {
                $a = explode(':', $part);
                $border = $a[1];
                $skip++;
            } elseif (substr($part, 0, 6) == 'align:') {
                $a = explode(':', $part);
                $align = $a[1];
                $skip++;
                $aSet = 1;
            } elseif (substr($part, 0, 4) == 'src:') {
                $a = explode(':', $part);
                $src = $a[1];
                $skip++;
            } elseif (substr($part, 0, 9) == 'autoplay:') {
                $a = explode(':', $part);
                $autoplay = $a[1];
                $skip++;
            } elseif (substr($part, 0, 5) == 'link:') {
                $a = explode(':', $part);
                $enable_link = $a[1];
                $skip++;
            } elseif (substr($part, 0, 6) == 'delay:') {
                $a = explode(':', $part);
                $delay = $a[1];
                $skip++;
            } elseif (substr($part, 0, 11) == 'transition:') {
                $a = explode(':', $part);
                $transition = $a[1];
                $skip++;
            } elseif (substr($part, 0, 6) == 'title:') {
                $a = explode(':', $part);
                $showtitle = $a[1];
                $skip++;
            } elseif (substr($part, 0, 5) == 'dest:') {
                $a = explode(':', $part);
                $destination = $a[1];
                if ($destination != 'content' && $destination != 'block') {
                    $destination = 'content';
                }
                $skip++;
            } elseif (substr($part, 0, 7) == 'linkid:') {
                $a = explode(':', $part);
                $linkID = $a[1];
                $skip++;
            } elseif (substr($part, 0, 4) == 'alt:') {
                $a = explode(':', $part);
                $alt = $a[1];
                $skip++;
            } elseif (substr($part, 0, 7) == 'target:') {
                $a = explode(':', $part);
                $target = $a[1];
                $skip++;
            } elseif (substr($part, 0, 5) == 'type:') {
                $a = explode(':', $part);
                $mp3_type = $a[1];
                $skip++;
            } elseif (substr($part, 0, 8) == 'linksrc:') {
                $a = explode(':', $part);
                $link_src = $a[1];
                if (!in_array($link_src, array('tn', 'disp', 'orig'))) {
                    $link_src = 'disp';
                }
                $skip++;
            } else {
                break;
            }
        }
        if ($skip != 0) {
            $caption = '';
            if (count($px) > $skip) {
                for ($i = 0; $i < $skip; $i++) {
                    array_shift($px);
                }
                $caption = trim(implode(' ', $px));
            }
        }
    } else {
        $caption = trim($autotag['parm2']);
    }
    if (!is_numeric($autotag['parm1'][0])) {
        switch ($autotag['parm1'][0]) {
            case 'n':
                $align = '';
                $aSet = 1;
                break;
            case 'c':
                $align = 'center';
                $aSet = 1;
                break;
            case 'l':
                $align = 'left';
                $aSet = 1;
                break;
            case 'r':
                $align = 'right';
                $aSet = 1;
                break;
            case 'a':
                $align = !($side_count % 2) ? 'left' : 'right';
                $side_count++;
                $aSet = 1;
                break;
            default:
                $align = 'left';
                $side_count++;
                break;
        }
        $parm1 = COM_applyFilter(substr($autotag['parm1'], 1, strlen($autotag['parm1']) - 1));
    } else {
        $parm1 = COM_applyFilter($autotag['parm1']);
        if ($aSet == 0 || $align == 'auto') {
            $align = !($side_count % 2) ? 'left' : 'right';
            $side_count++;
        }
    }
    if ($align == 'none') {
        $align = '';
    }
    // sanity check incase the album has been deleted or something...
    if (!in_array($autotag['tag'], array('media', 'image', 'video', 'audio', 'download', 'oimage', 'img', 'mlink', 'alink', 'playall'))) {
        if (DB_count($_TABLES['mg_albums'], 'album_id', intval($parm1)) == 0) {
            return str_replace($autotag['tagstr'], '', $content);
        }
    }
    $ss_count = mt_rand(0, 32768);
    switch ($autotag['tag']) {
        case 'download':
            $side_count--;
            $sql = "SELECT ma.album_id " . "FROM {$_TABLES['mg_media']} AS m " . "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id " . "WHERE m.media_id='" . addslashes($parm1) . "'";
            $result = DB_query($sql);
            if (DB_numRows($result) <= 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $row = DB_fetchArray($result);
            $album_data = MG_getAlbumData($row['album_id'], array('album_id'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $link = '<a href="' . $_MG_CONF['site_url'] . '/download.php?mid=' . $parm1 . '">' . ($caption != '' ? $caption : 'download') . '</a>';
            break;
        case 'mlink':
            $side_count--;
            $sql = "SELECT m.remote_url,ma.album_id " . "FROM {$_TABLES['mg_media']} AS m " . "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id " . "WHERE m.media_id='" . addslashes($parm1) . "'";
            $result = DB_query($sql);
            if (DB_numRows($result) <= 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $row = DB_fetchArray($result);
            $album_data = MG_getAlbumData($row['album_id'], array('album_id'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            if ($alt == 1 && $row['remote_url'] != '') {
                $href = $row['remote_url'];
            } else {
                $href = $_MG_CONF['site_url'] . '/media.php?f=0&amp;sort=0&amp;s=' . $parm1;
            }
            $link = '<a href="' . $href . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . ($caption != '' ? $caption : $LANG_MG03['click_here']) . '</a>';
            break;
        case 'playall':
            $album_data = MG_getAlbumData($parm1, array('album_id'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0 || COM_isAnonUser() && $_MG_CONF['loginrequired'] == 1) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $V = COM_newTemplate(MG_getTemplatePath(0));
            $V->set_file('xspf', 'xspf_radio.thtml');
            $V->set_var(array('aid' => $parm1, 'site_url' => $_MG_CONF['site_url'], 'autoplay' => $autoplay ? 'play' : 'stop', 'id' => 'mp3radio' . rand(), 'id2' => 'mp3radio' . rand(), 'xhtml' => XHTML));
            $media = $V->finish($V->parse('output', 'xspf'));
            $link = MG_helper_getContainer($media, $align, 'span');
            break;
        case 'video':
            $sql = "SELECT ma.album_id,m.media_id,m.mime_type,m.remote_url,m.media_filename," . "m.media_mime_ext,m.media_original_filename,m.media_tn_attached," . "m.media_resolution_x,m.media_resolution_y,m.remote_media " . "FROM {$_TABLES['mg_media']} AS m " . "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id " . "WHERE m.media_id='" . addslashes($parm1) . "'";
            $result = DB_query($sql);
            if (DB_numRows($result) <= 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $row = DB_fetchArray($result);
            $album_data = MG_getAlbumData($row['album_id'], array('album_id'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $orig_media_url = $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
            // determine height / width and aspect
            if ($width === 'auto' && $row['media_resolution_x'] > 0 && $row['media_resolution_y'] > 0) {
                $videoheight = $row['media_resolution_y'];
                $videowidth = $row['media_resolution_x'];
            } else {
                $ratio = 0.75;
                $orientation = 0;
                if ($row['media_resolution_x'] > 0 && $row['media_resolution_y'] > 0) {
                    if ($row['media_resolution_x'] >= $row['media_resolution_y']) {
                        // landscape
                        $ratio = $row['media_resolution_y'] / $row['media_resolution_x'];
                    } else {
                        // portrait
                        $ratio = $row['media_resolution_x'] / $row['media_resolution_y'];
                        $orientation = 1;
                    }
                }
                if ($orientation == 0) {
                    if ($width > 0 && $height == 0) {
                        $videoheight = round($width * $ratio);
                        $videowidth = $width;
                    } else {
                        if ($width == 0 && $height == 0) {
                            $videoheight = 200 * $ratio;
                            $videowidth = 200;
                        } else {
                            if ($width == 0 && $height > 0) {
                                $videowidth = round($height / $ratio);
                                $videoheight = $height;
                            } else {
                                if ($width > 0 && $height > 0) {
                                    $videowidth = $width;
                                    $videoheight = $height;
                                }
                            }
                        }
                    }
                } else {
                    if ($width > 0 && $height == 0) {
                        $videoheight = round($width / $ratio);
                        $videowidth = $width;
                    } else {
                        if ($width == 0 && $height == 0) {
                            $videoheight = 200;
                            $videowidth = round(200 / $ratio);
                        } else {
                            if ($width == 0 && $height > 0) {
                                $videowidth = round($height * $ratio);
                                $videoheight = $height;
                            } else {
                                if ($width > 0 && $height > 0) {
                                    $videowidth = $width;
                                    $videoheight = $height;
                                }
                            }
                        }
                    }
                }
            }
            switch ($row['mime_type']) {
                case 'embed':
                    $media = $row['remote_url'];
                    break;
                case 'video/x-ms-asf':
                case 'video/x-ms-asf-plugin':
                case 'video/avi':
                case 'video/msvideo':
                case 'video/x-msvideo':
                case 'video/avs-video':
                case 'video/x-ms-wmv':
                case 'video/x-ms-wvx':
                case 'video/x-ms-wm':
                case 'application/x-troff-msvideo':
                case 'application/x-ms-wmz':
                case 'application/x-ms-wmd':
                    $V = COM_newTemplate(MG_getTemplatePath(0));
                    $V->set_file('video', 'view_asf.thtml');
                    $V->set_var(array('autostart' => $autoplay ? 'true' : 'false', 'enablecontextmenu' => 'true', 'stretchtofit' => 'false', 'showstatusbar' => 'false', 'showcontrols' => 'true', 'showdisplay' => 'false', 'height' => $videoheight, 'width' => $videowidth, 'bgcolor' => '#FFFFFF', 'playcount' => '9999', 'loop' => 'true', 'movie' => $orig_media_url, 'autostart0' => $autoplay ? '1' : '0', 'enablecontextmenu0' => '1', 'stretchtofit0' => '0', 'showstatusbar0' => '0', 'uimode0' => 'none', 'showcontrols0' => '1', 'showdisplay0' => '0', 'xhtml' => XHTML));
                    $media = $V->finish($V->parse('output', 'video'));
                    break;
                case 'video/mpeg':
                case 'video/x-motion-jpeg':
                case 'video/quicktime':
                case 'video/mpeg':
                case 'video/x-mpeg':
                case 'video/x-mpeq2a':
                case 'video/x-qtc':
                case 'video/x-m4v':
                    $V = COM_newTemplate(MG_getTemplatePath(0));
                    $V->set_file('video', 'view_quicktime.thtml');
                    $V->set_var(array('autoref' => 'true', 'autoplay' => $autoplay ? 'true' : 'false', 'controller' => 'true', 'kioskmode' => 'true', 'scale' => 'aspect', 'height' => $videoheight, 'width' => $videowidth, 'bgcolor' => '#F0F0F0', 'loop' => 'true', 'movie' => $orig_media_url, 'xhtml' => XHTML));
                    $media = $V->finish($V->parse('output', 'video'));
                    break;
                case 'application/x-shockwave-flash':
                    // set the default playback options...
                    $playback_options['play'] = $_MG_CONF['swf_play'];
                    $playback_options['menu'] = $_MG_CONF['swf_menu'];
                    $playback_options['quality'] = $_MG_CONF['swf_quality'];
                    $playback_options['height'] = $_MG_CONF['swf_height'];
                    $playback_options['width'] = $_MG_CONF['swf_width'];
                    $playback_options['loop'] = $_MG_CONF['swf_loop'];
                    $playback_options['scale'] = $_MG_CONF['swf_scale'];
                    $playback_options['wmode'] = $_MG_CONF['swf_wmode'];
                    $playback_options['allowscriptaccess'] = $_MG_CONF['swf_allowscriptaccess'];
                    $playback_options['bgcolor'] = $_MG_CONF['swf_bgcolor'];
                    $playback_options['swf_version'] = $_MG_CONF['swf_version'];
                    $playback_options['flashvars'] = $_MG_CONF['swf_flashvars'];
                    $poResult = DB_query("SELECT * FROM {$_TABLES['mg_playback_options']} WHERE media_id='" . $row['media_id'] . "'");
                    while ($poRow = DB_fetchArray($poResult)) {
                        $playback_options[$poRow['option_name']] = $poRow['option_value'];
                    }
                    if ($swfjsinclude > 0) {
                        $link = '';
                    } else {
                        $S = COM_newTemplate(MG_getTemplatePath(0));
                        $S->set_file('swf', 'swfobject.thtml');
                        $S->set_var('site_url', $_MG_CONF['site_url']);
                        $link = $S->finish($S->parse('output', 'swf'));
                        $swfjsinclude++;
                    }
                    $V = COM_newTemplate(MG_getTemplatePath(0));
                    $V->set_file('video', 'view_swf.thtml');
                    $V->set_var(array('site_url' => $_MG_CONF['site_url'], 'lang_noflash' => $LANG_MG03['no_flash'], 'play' => $autoplay ? 'true' : 'false', 'menu' => $playback_options['menu'] ? 'true' : 'false', 'loop' => $playback_options['loop'] ? 'true' : 'false', 'scale' => $playback_options['scale'], 'wmode' => $playback_options['wmode'], 'flashvars' => $playback_options['flashvars'], 'quality' => $playback_options['quality'], 'height' => $videoheight, 'width' => $videowidth, 'asa' => $playback_options['allowscriptaccess'], 'bgcolor' => $playback_options['bgcolor'], 'swf_version' => $playback_options['swf_version'], 'filename' => $row['media_original_filename'], 'id' => $row['media_filename'] . rand(), 'id2' => $row['media_filename'] . rand(), 'movie' => $orig_media_url, 'xhtml' => XHTML));
                    $media = $V->finish($V->parse('output', 'video'));
                    break;
                case 'video/x-flv':
                    // set the default playback options...
                    $playback_options['play'] = $_MG_CONF['swf_play'];
                    $playback_options['menu'] = $_MG_CONF['swf_menu'];
                    $playback_options['quality'] = $_MG_CONF['swf_quality'];
                    $playback_options['height'] = $_MG_CONF['swf_height'];
                    $playback_options['width'] = $_MG_CONF['swf_width'];
                    $playback_options['loop'] = $_MG_CONF['swf_loop'];
                    $playback_options['scale'] = $_MG_CONF['swf_scale'];
                    $playback_options['wmode'] = $_MG_CONF['swf_wmode'];
                    $playback_options['allowscriptaccess'] = $_MG_CONF['swf_allowscriptaccess'];
                    $playback_options['bgcolor'] = $_MG_CONF['swf_bgcolor'];
                    $playback_options['swf_version'] = $_MG_CONF['swf_version'];
                    $playback_options['flashvars'] = $_MG_CONF['swf_flashvars'];
                    $poResult = DB_query("SELECT * FROM {$_TABLES['mg_playback_options']} WHERE media_id='" . $row['media_id'] . "'");
                    while ($poRow = DB_fetchArray($poResult)) {
                        $playback_options[$poRow['option_name']] = $poRow['option_value'];
                    }
                    if ($swfjsinclude > 0) {
                        $link = '';
                    } else {
                        $S = COM_newTemplate(MG_getTemplatePath(0));
                        $S->set_file('swf', 'swfobject.thtml');
                        $S->set_var('site_url', $_MG_CONF['site_url']);
                        $link = $S->finish($S->parse('output', 'swf'));
                        $swfjsinclude++;
                    }
                    // now the player specific items.
                    if ($autoplay == 1) {
                        // auto start
                        $playButton = '';
                    } else {
                        if ($row['media_tn_attached'] == 1) {
                            $tfn = 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'];
                            $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                            $playImage = $_MG_CONF['mediaobjects_url'] . '/' . $tfn . $ext;
                        } else {
                            $playImage = MG_getImageFile('blank_blk.jpg');
                        }
                        $playButton = "{ url: '" . $playImage . "', overlayId: 'play' },";
                    }
                    if ($row['remote_media'] == 1) {
                        $urlParts = array();
                        $urlParts = parse_url($row['remote_url']);
                        $pathParts = array();
                        $pathParts = explode('/', $urlParts['path']);
                        $ppCount = count($pathParts);
                        $pPath = '';
                        for ($row = 1; $row < $ppCount - 1; $row++) {
                            $pPath .= '/' . $pathParts[$row];
                        }
                        $videoFile = $pathParts[$ppCount - 1];
                        $pos = strrpos($videoFile, '.');
                        if ($pos === false) {
                            $basefilename = $videoFile;
                        } else {
                            $basefilename = substr($videoFile, 0, $pos);
                        }
                        $videoFile = $basefilename;
                        $streamingServerURL = "streamingServerURL: '" . $urlParts['scheme'] . '://' . $urlParts['host'] . $pPath . "',";
                        $streamingServer = "streamingServer: 'fms',";
                    } else {
                        $streamingServerURL = '';
                        $streamingServer = '';
                        $videoFile = urlencode($orig_media_url);
                    }
                    $width = $videowidth;
                    $height = $videoheight + 22;
                    $resolution_x = $videowidth;
                    $resolution_y = $videoheight;
                    $id = 'id_' . rand();
                    $id2 = 'id2_' . rand();
                    $F = COM_newTemplate(MG_getTemplatePath(0));
                    $F->set_file('player', 'flvfp.thtml');
                    $F->set_var(array('site_url' => $_MG_CONF['site_url'], 'lang_noflash' => $LANG_MG03['no_flash'], 'play' => $autoplay ? 'true' : 'false', 'menu' => $playback_options['menu'] ? 'true' : 'false', 'loop' => $playback_options['loop'] ? 'true' : 'false', 'scale' => $playback_options['scale'], 'wmode' => $playback_options['wmode'], 'width' => $width, 'height' => $height, 'streamingServerURL' => $streamingServerURL, 'streamingServer' => $streamingServer, 'videoFile' => $videoFile, 'playButton' => $playButton, 'id' => $id, 'id2' => $id2, 'resolution_x' => $resolution_x, 'resolution_y' => $resolution_y, 'xhtml' => XHTML));
                    $flv_player = $F->finish($F->parse('output', 'player'));
                    $V = COM_newTemplate(MG_getTemplatePath(0));
                    $V->set_file('video', 'view_flv_light.thtml');
                    $V->set_var(array('site_url' => $_MG_CONF['site_url'], 'lang_noflash' => $LANG_MG03['no_flash'], 'id' => $id, 'id2' => $id2, 'width' => $resolution_x, 'height' => $resolution_y, 'flv_player' => $flv_player, 'xhtml' => XHTML));
                    $media = $V->finish($V->parse('output', 'video'));
                    break;
            }
            $link = MG_helper_getContainer($media, $align, 'div');
            break;
        case 'audio':
            $sql = "SELECT ma.album_id,m.media_title,m.mime_type,m.media_tn_attached,m.media_filename,m.media_mime_ext " . "FROM {$_TABLES['mg_media']} AS m " . "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id " . "WHERE m.media_id='" . addslashes($parm1) . "'";
            $result = DB_query($sql);
            if (DB_numRows($result) <= 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $row = DB_fetchArray($result);
            $album_data = MG_getAlbumData($row['album_id'], array('album_id'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            $orig_media_url = $_MG_CONF['mediaobjects_url'] . '/orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
            switch ($row['mime_type']) {
                case 'audio/mpeg':
                    $playback_options['height'] = 50;
                    $playback_options['width'] = 200;
                    $u_pic = '';
                    if ($row['media_tn_attached'] == 1) {
                        $tfn = 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'];
                        $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                        $u_tn = $_MG_CONF['mediaobjects_url'] . '/' . $tfn . $ext;
                        $media_size_disp = @getimagesize($_MG_CONF['path_mediaobjects'] . $tfn . $ext);
                        $border_width = $media_size_disp[0] + 12;
                        $u_pic = '<img src="' . $u_tn . '" alt="" style="border:none;vertical-align:bottom;"' . XHTML . '>';
                    }
                    $V = COM_newTemplate(MG_getTemplatePath(0));
                    $V->set_file('audio', $mp3_type == 'ribbon' ? 'mp3_podcast.thtml' : 'view_mp3_flv.thtml');
                    $V->set_var(array('autostart' => $autoplay ? 'play' : 'stop', 'enablecontextmenu' => 'true', 'stretchtofit' => 'false', 'showstatusbar' => 'true', 'uimode' => 'mini', 'height' => $playback_options['height'], 'width' => $playback_options['width'], 'bgcolor' => '#FFFFFF', 'loop' => 'true', 'u_pic' => $u_pic, 'title' => urlencode($row['media_title']), 'id' => 'mp3' . rand(), 'id2' => 'mp3' . rand(), 'site_url' => $_MG_CONF['site_url'], 'movie' => $orig_media_url, 'mp3_file' => $orig_media_url, 'xhtml' => XHTML));
                    $media = $V->finish($V->parse('output', 'audio'));
                    break;
                case 'audio/x-ms-wma':
                case 'audio/x-ms-wax':
                case 'audio/x-ms-wmv':
                    $playback_options['height'] = 50;
                    $playback_options['width'] = 200;
                    $u_pic = '';
                    if ($row['media_tn_attached'] == 1) {
                        $tfn = 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'];
                        $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                        $u_tn = $_MG_CONF['mediaobjects_url'] . '/' . $tfn . $ext;
                        $media_size_disp = @getimagesize($_MG_CONF['path_mediaobjects'] . $tfn . $ext);
                        $border_width = $media_size_disp[0] + 12;
                        $u_pic = '<div class="out" style="width:' . $border_width . 'px"><div class="in ltin tpin"><img src="' . $u_tn . '" alt="" style="vertical-align:bottom;"' . XHTML . '></div></div>';
                    }
                    $V = COM_newTemplate(MG_getTemplatePath(0));
                    $V->set_file('audio', 'view_mp3_wmp.thtml');
                    $V->set_var(array('autostart' => $autoplay ? '1' : '0', 'enablecontextmenu' => 'true', 'stretchtofit' => 'false', 'showstatusbar' => 'true', 'uimode' => 'mini', 'height' => $playback_options['height'], 'width' => $playback_options['width'], 'bgcolor' => '#FFFFFF', 'loop' => 'true', 'u_pic' => $u_pic, 'movie' => $orig_media_url, 'xhtml' => XHTML));
                    $media = $V->finish($V->parse('output', 'audio'));
                    break;
            }
            $link = MG_helper_getContainer($media, $align, 'div');
            break;
        case 'fslideshow':
            if (empty($parm1)) {
                return $content;
            }
            $album_data = MG_getAlbumData($parm1, array('album_title', 'album_id', 'hidden'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            if ($width > 0 && $height == 0) {
                $height = $width * 0.75;
            } else {
                if ($width == 0 && $height == 0) {
                    $height = $width = 200;
                } else {
                    if ($width == 0 && $height > 0) {
                        $width = $height * 1.3333;
                    }
                }
            }
            // if none of the above, assume height and width both specified.
            if ($caption == '' && $_MG_CONF['autotag_caption'] && isset($parm1)) {
                $caption = $album_data['album_title'];
            }
            $captionHTML = '<br' . XHTML . '><span style="width:' . $width . 'px;font-style:italic;font-size: smaller;text-indent:0;">' . $caption . '</span>' . LB;
            $ss_count++;
            $T = COM_newTemplate(MG_getTemplatePath(0));
            $T->set_file('fslideshow', 'fsat.thtml');
            $T->set_var('site_url', $_MG_CONF['site_url']);
            $T->set_var(array('id' => 'mms' . $ss_count, 'id2' => 'fsid' . $ss_count, 'movie' => $_MG_CONF['site_url'] . '/xml.php?aid=' . $parm1 . '%26src=' . trim($src), 'dropshadow' => 'true', 'delay' => $delay, 'nolink' => $album_data['hidden'] || $enable_link == 0 ? 'true' : 'false', 'showtitle' => $showtitle == 'bottom' || $showtitle == 'top' ? '&showTitle=' . $showtitle : '', 'width' => $width, 'height' => $height, 'xhtml' => XHTML));
            $swfobject = $T->finish($T->parse('output', 'fslideshow'));
            $media = $swfobject . $captionHTML;
            /*
                        $style = '';
                        if ($align == 'center') {
                            $style = 'text-align:center;';
                        } else if ($align != '') {
                            $style = 'float:' . $align . ';';
                        }
                        $link = '<span style="' . $style . 'padding:5px;">' . $media . '</span>';
            */
            if ($align != '' && $align != "center") {
                $link = '<div style="float:' . $align . ';padding:5px;text-align:center;">' . $media . '</div>';
            } else {
                if ($align == 'center') {
                    $link = '<div style="padding:5px;text-align:center;">' . $media . '</div>';
                } else {
                    $link = '<div style="padding:5px;text-align:center;">' . $media . '</div>';
                }
            }
            break;
        case 'slideshow':
            if (empty($parm1)) {
                return $content;
            }
            $album_data = MG_getAlbumData($parm1, array('album_title', 'album_id', 'hidden'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            if ($caption == '' && $_MG_CONF['autotag_caption']) {
                $caption = $album_data['album_title'];
            }
            $aid = $parm1;
            $pics = '';
            $counter = 0;
            $maxwidth = 0;
            $maxheight = 0;
            $ss_count++;
            $sql = MG_buildMediaSql(array('album_id' => $aid, 'fields' => array('media_filename', 'media_mime_ext', 'remote_url'), 'where' => "m.media_type = 0 AND m.include_ss = 1"));
            $result = DB_query($sql);
            while ($row = DB_fetchArray($result)) {
                switch ($src) {
                    case 'orig':
                        $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']);
                        $ext = $row['media_mime_ext'];
                        break;
                    case 'disp':
                        $mfn = 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'];
                        $tnext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $mfn);
                        $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . $mfn . $tnext);
                        $ext = substr($tnext, 1, 3);
                        // no use ?
                        break;
                    default:
                        $mfn = 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'];
                        $tnext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $mfn);
                        $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . $mfn . $tnext);
                        $ext = substr($tnext, 1, 3);
                        // no use ?
                        $src = 'tn';
                        break;
                }
                if ($media_size == false) {
                    continue;
                }
                $counter++;
                if ($width > 0 && $height == 0) {
                    if ($media_size[0] > $media_size[1]) {
                        // landscape
                        $ratio = $media_size[0] / $width;
                        $newwidth = $width;
                        $newheight = round($media_size[1] / $ratio);
                    } else {
                        // portrait
                        $ratio = $media_size[1] / $width;
                        $newheight = $width;
                        $newwidth = round($media_size[0] / $ratio);
                    }
                } else {
                    if ($width == 0 && $height == 0) {
                        if ($media_size[0] > $media_size[1]) {
                            // landscape
                            $ratio = $media_size[0] / 200;
                            $newwidth = 200;
                            $newheight = round($media_size[1] / $ratio);
                        } else {
                            // portrait
                            $ratio = $media_size[1] / 200;
                            $newheight = 200;
                            $newwidth = round($media_size[0] / $ratio);
                        }
                    } else {
                        if ($width == 0 && $height > 0) {
                            if ($height > $media_size[1]) {
                                $newheight = $media_size[1];
                                $newwidth = $media_size[0];
                            } else {
                                $ratio = $height / $media_size[1];
                                $newheight = $height;
                                $newwidth = round($media_size[0] * $ratio);
                            }
                        } else {
                            $newwidth = $width;
                            $newheight = $height;
                        }
                    }
                }
                if ($newheight > $maxheight) {
                    $maxheight = $newheight;
                }
                if ($newwidth > $maxwidth) {
                    $maxwidth = $newwidth;
                }
                /*
                                if ($album->hidden == 1 || $enable_link == 0) {
                                    $pics .= '<img class="slideshowThumbnail' . $ss_count . '" src="' . $_MG_CONF['mediaobjects_url'] . '/' . $src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $ext . '" alt="" style="width:' . $newwidth . 'px;height:' . $newheight . 'px;border:none;position:absolute;left:0px;top:0px;vertical-align:bottom;"' . XHTML . '>' . LB;
                                } else {
                                    $pics .= '<img class="slideshowThumbnail' . $ss_count . '" src="' . $_MG_CONF['mediaobjects_url'] . '/' . $src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $ext . '" alt="" style="width:' . $newwidth . 'px;height:' . $newheight . 'px;border:none;position:absolute;left:0px;top:0px;vertical-align:bottom;"' . XHTML . '>' . LB;
                                }
                */
                $pics .= '<img class="slideshowThumbnail' . $ss_count . '" src="' . $_MG_CONF['mediaobjects_url'] . '/' . $src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $ext . '" alt="" style="width:' . $newwidth . 'px;height:' . $newheight . 'px;' . 'border:none;position:absolute;left:0px;top:0px;vertical-align:bottom;"' . XHTML . '>' . LB;
            }
            if ($delay <= 0) {
                $delay = 10;
            }
            if ($album_data['hidden'] == 1 || $enable_link == 0) {
                $ss_url = '';
            } else {
                //              $ss_url = '<a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $aid . '"' . ($target=='' ? '' : ' target="' . $target . '"') . '>';
                $ss_url = $_MG_CONF['site_url'] . '/album.php?aid=' . $aid;
            }
            $link = '';
            if ($counter != 0) {
                $T = COM_newTemplate($_MG_CONF['template_path']);
                $T->set_file('tag', 'autotag_ss.thtml');
                $T->set_var(array('align' => $align, 'pics' => $pics, 'caption' => $caption, 'maxheight' => $maxheight, 'maxwidth' => $maxwidth, 'width' => $maxwidth, 'framewidth' => $maxwidth + 10, 'ss_count' => $ss_count, 'delay' => $delay * 1000, 'border' => $border ? 'border: silver solid;border-width: 1px;' : '', 'xhtml' => XHTML, 'sslink' => $ss_url));
                if ($align == 'left' || $align == 'right') {
                    $T->set_var('float', 'float: ' . $align . ';');
                } else {
                    $T->set_var('float', 'float:left;');
                    $align = 'left';
                }
                $T->set_var('margin-right', $align == 'left' ? 'margin-right:15px;' : '');
                $link = $T->finish($T->parse('output', 'tag'));
            }
            /*
                        if ($align == 'center') {
                            $link = '<center>' . $link . '</center>';
                        }
            */
            break;
            // Testing //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Testing //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        case 'gallery':
            if (empty($parm1)) {
                return $content;
            }
            $album_data = MG_getAlbumData($parm1, array('album_title', 'album_id', 'hidden'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            if ($caption == '' && $_MG_CONF['autotag_caption']) {
                $caption = $album_data['album_title'];
            }
            $aid = $parm1;
            $pics = '';
            $counter = 0;
            $maxwidth = 0;
            $maxheight = 0;
            $ss_count++;
            $sql = MG_buildMediaSql(array('album_id' => $aid, 'fields' => array('media_filename', 'media_mime_ext', 'remote_url'), 'where' => "m.media_type = 0 AND m.include_ss = 1"));
            $result = DB_query($sql);
            while ($row = DB_fetchArray($result)) {
                switch ($src) {
                    case 'orig':
                        $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']);
                        $ext = $row['media_mime_ext'];
                        break;
                    case 'disp':
                        $mfn = 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'];
                        $tnext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $mfn);
                        $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . $mfn . $tnext);
                        $ext = substr($tnext, 1, 3);
                        // no use ?
                        break;
                    default:
                        $mfn = 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'];
                        $tnext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $mfn);
                        $media_size = @getimagesize($_MG_CONF['path_mediaobjects'] . $mfn . $tnext);
                        $ext = substr($tnext, 1, 3);
                        // no use ?
                        $src = 'tn';
                        break;
                }
                if ($media_size == false) {
                    continue;
                }
                $counter++;
                if ($width > 0 && $height == 0) {
                    if ($media_size[0] > $media_size[1]) {
                        // landscape
                        $ratio = $media_size[0] / $width;
                        $newwidth = $width;
                        $newheight = round($media_size[1] / $ratio);
                    } else {
                        // portrait
                        $ratio = $media_size[1] / $width;
                        $newheight = $width;
                        $newwidth = round($media_size[0] / $ratio);
                    }
                } else {
                    if ($width == 0 && $height == 0) {
                        if ($media_size[0] > $media_size[1]) {
                            // landscape
                            $ratio = $media_size[0] / 200;
                            $newwidth = 200;
                            $newheight = round($media_size[1] / $ratio);
                        } else {
                            // portrait
                            $ratio = $media_size[1] / 200;
                            $newheight = 200;
                            $newwidth = round($media_size[0] / $ratio);
                        }
                    } else {
                        if ($width == 0 && $height > 0) {
                            if ($height > $media_size[1]) {
                                $newheight = $media_size[1];
                                $newwidth = $media_size[0];
                            } else {
                                $ratio = $height / $media_size[1];
                                $newheight = $height;
                                $newwidth = round($media_size[0] * $ratio);
                            }
                        } else {
                            $newwidth = $width;
                            $newheight = $height;
                        }
                    }
                }
                if ($newheight > $maxheight) {
                    $maxheight = $newheight;
                }
                if ($newwidth > $maxwidth) {
                    $maxwidth = $newwidth;
                }
                $pics .= '<img class="slideshowThumbnail' . $ss_count . '" src="' . $_MG_CONF['mediaobjects_url'] . '/' . $src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $ext . '" alt="" style="width:' . $newwidth . 'px;height:' . $newheight . 'px;' . 'border:none;position:absolute;left:0px;top:0px;vertical-align:bottom;"' . XHTML . '>' . LB;
            }
            if ($delay <= 0) {
                $delay = 10;
            }
            if ($album_data['hidden'] == 1 || $enable_link == 0) {
                $ss_url = '';
            } else {
                $ss_url = $_MG_CONF['site_url'] . '/album.php?aid=' . $aid;
            }
            $link = '';
            if ($counter != 0) {
                $T = COM_newTemplate($_MG_CONF['template_path']);
                $T->set_file('tag', 'autotag_ss.thtml');
                $T->set_var(array('align' => $align, 'pics' => $pics, 'caption' => $caption, 'maxheight' => $maxheight, 'maxwidth' => $maxwidth, 'width' => $maxwidth, 'framewidth' => $maxwidth + 10, 'ss_count' => $ss_count, 'delay' => $delay * 1000, 'border' => $border ? 'border: silver solid;border-width: 1px;' : '', 'xhtml' => XHTML, 'sslink' => $ss_url));
                if ($align == 'left' || $align == 'right') {
                    $T->set_var('float', 'float: ' . $align . ';');
                } else {
                    $T->set_var('float', 'float:left;');
                    $align = 'left';
                }
                $T->set_var('margin-right', $align == 'left' ? 'margin-right:15px;' : '');
                $link = $T->finish($T->parse('output', 'tag'));
            }
            break;
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //@@@@@
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //@@@@@
        case 'medialist':
            $link = MG_medialist($p1, $p['lastparm2'], $p['theme'], $p['limitcnt'], $p['sort']);
            break;
        case 'albumlist':
            $link = MG_albumlist($p1, $p['limitcnt'], $p['order'], $p['lastparm2'], $p['theme']);
            break;
            //@@@@@
        //@@@@@
        case 'album':
            if (empty($parm1)) {
                $side_count--;
                return $content;
            }
            $album_data = MG_getAlbumData($parm1, array('album_title', 'album_id', 'hidden', 'tn_attached'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                $side_count--;
                return str_replace($autotag['tagstr'], '', $content);
            }
            $ss_count++;
            if ($caption != '') {
                $alttag = ' alt="' . $caption . '" title="' . $caption . '"';
            } else {
                $alttag = ' alt=""';
                if ($_MG_CONF['autotag_caption']) {
                    $caption = $album_data['album_title'];
                }
            }
            //            $aid = $parm1;
            if ($album_data['tn_attached'] == 1) {
                $tfn = 'covers/cover_' . $parm1;
                $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                $tnImage = $_MG_CONF['mediaobjects_url'] . '/' . $tfn . $ext;
                $tnFileName = $_MG_CONF['path_mediaobjects'] . $tfn . $ext;
            } else {
                $filename = MG_getAlbumCover($parm1);
                if ($filename != '') {
                    $tfn = 'tn/' . $filename[0] . '/' . $filename . '_cropcustom';
                    $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                    $tnImage = $_MG_CONF['mediaobjects_url'] . '/' . $tfn . $ext;
                    $tnFileName = $_MG_CONF['path_mediaobjects'] . $tfn . $ext;
                } else {
                    $tnImage = $_MG_CONF['mediaobjects_url'] . '/empty.png';
                    $tnFileName = $_MG_CONF['path_mediaobjects'] . 'empty.png';
                }
            }
            $media_size = @getimagesize($tnFileName);
            if ($media_size == false) {
                $tnImage = $_MG_CONF['mediaobjects_url'] . '/missing.png';
                $tnFileName = $_MG_CONF['path_mediaobjects'] . 'missing.png';
                $media_size = @getimagesize($tnFileName);
            }
            if ($width > 0 && $height == 0) {
                $ratio = $media_size[0] / $width;
                $newwidth = $width;
                $newheight = round($media_size[1] / $ratio);
            } else {
                if ($width == 0 && $height == 0) {
                    if ($media_size[0] > $media_size[1]) {
                        // landscape
                        $ratio = $media_size[0] / 200;
                        $newwidth = 200;
                        $newheight = round($media_size[1] / $ratio);
                    } else {
                        // portrait
                        $ratio = $media_size[1] / 200;
                        $newheight = 200;
                        $newwidth = round($media_size[0] / $ratio);
                    }
                } else {
                    if ($width == 0 && $height > 0) {
                        $ratio = $height / $media_size[1];
                        $newheight = $height;
                        $newwidth = round($media_size[0] * $ratio);
                    } else {
                        $newwidth = $width;
                        $newheight = $height;
                    }
                }
            }
            $tagtext = '<img src="' . $tnImage . '" ' . $alttag . 'style="width:' . $newwidth . 'px;height:' . $newheight . 'px;border:none;vertical-align:bottom;"' . XHTML . '>';
            if ($linkID == 0) {
                $url = $_MG_CONF['site_url'] . '/album.php?aid=' . $parm1;
            } else {
                if ($linkID < 1000000) {
                    $url = $_MG_CONF['site_url'] . '/album.php?aid=' . $linkID;
                } else {
                    $url = $_MG_CONF['site_url'] . '/media.php?s=' . $linkID;
                }
            }
            if ($enable_link == 0) {
                $link = $tagtext;
            } else {
                $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
            }
            $T = COM_newTemplate($_MG_CONF['template_path']);
            $T->set_file('tag', $border == 0 ? 'autotag_nb.thtml' : 'autotag.thtml');
            $T->set_var(array('ss_count' => $ss_count, 'align' => $align, 'autotag' => $link, 'caption' => $caption, 'width' => $newwidth, 'framewidth' => $newwidth, 'xhtml' => XHTML, 'float' => $align == 'left' || $align == 'right' ? 'float:' . $align . ';' : '', 'margin-right' => $align == 'left' ? 'margin-right:15px;' : ''));
            if ($align == 'center') {
                $T->set_var('margin-right', 'margin:0 auto;');
            }
            $link = $T->finish($T->parse('output', 'tag'));
            if ($align == 'center') {
                $link = '<div style="text-align:center;">' . LB . $link . '</div>' . LB;
            }
            break;
        case 'alink':
            if ($parm1 == '' || $parm1 == 0) {
                $side_count--;
                return $content;
            }
            $album_data = MG_getAlbumData($parm1, array('album_title', 'album_id', 'hidden'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                $side_count--;
                return str_replace($autotag['tagstr'], '', $content);
            }
            if ($caption == '') {
                $caption = $album_data['album_title'];
            }
            $link = '<a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $album_data['album_id'] . '">' . $caption . '</a>';
            return str_replace($autotag['tagstr'], $link, $content);
            break;
        case 'media':
            /* image, oimage and img are depreciated */
        /* image, oimage and img are depreciated */
        case 'image':
        case 'oimage':
        case 'img':
            if (empty($parm1)) {
                return $content;
            }
            $direct_link = '';
            $ss_count++;
            $alttag = ' alt=""';
            if ($caption != '') {
                $alttag = ' alt="' . $caption . '" title="' . $caption . '"';
            }
            $sql = "SELECT ma.album_id,m.media_title,m.media_type,m.media_filename," . "m.media_mime_ext,m.mime_type,m.media_tn_attached,m.remote_url " . "FROM {$_TABLES['mg_media']} AS m " . "LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id " . "WHERE m.media_id='" . addslashes($parm1) . "'";
            $result = DB_query($sql);
            if (DB_numRows($result) <= 0) {
                return $content;
            }
            // no image found
            $row = DB_fetchArray($result);
            $aid = $row['album_id'];
            $album_data = MG_getAlbumData($aid, array('album_id', 'hidden'), true);
            if (!isset($album_data['album_id']) || $album_data['access'] == 0) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            if ($caption == '' && $_MG_CONF['autotag_caption']) {
                $caption = $row['media_title'];
            }
            switch ($row['media_type']) {
                case 0:
                    // standard image
                    $fn = $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext'];
                    $tfn = 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'];
                    if ($autotag['tag'] == 'oimage') {
                        $default_thumbnail = ($_MG_CONF['discard_original'] == 1 ? 'disp/' : 'orig/') . $fn;
                    } else {
                        switch ($src) {
                            case 'orig':
                                $default_thumbnail = ($_MG_CONF['discard_original'] == 1 ? 'disp/' : 'orig/') . $fn;
                                break;
                            case 'disp':
                                $default_thumbnail = 'disp/' . $fn;
                                break;
                            default:
                                $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                                $default_thumbnail = $tfn . $ext;
                                break;
                        }
                        $lfn = $link_src . '/' . $row['media_filename'][0] . '/' . $row['media_filename'];
                        $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $lfn);
                        $direct_link = $_MG_CONF['mediaobjects_url'] . '/' . $lfn . $ext;
                    }
                    break;
                case 1:
                    // video file
                    switch ($row['mime_type']) {
                        case 'application/x-shockwave-flash':
                            $default_thumbnail = 'flash.png';
                            break;
                        case 'video/quicktime':
                        case 'video/mpeg':
                        case 'video/x-m4v':
                            $default_thumbnail = 'quicktime.png';
                            break;
                        case 'video/x-ms-asf':
                        case 'video/x-ms-wvx':
                        case 'video/x-ms-wm':
                        case 'video/x-ms-wmx':
                        case 'video/x-msvideo':
                        case 'application/x-ms-wmz':
                        case 'application/x-ms-wmd':
                            $default_thumbnail = 'wmp.png';
                            break;
                        default:
                            $default_thumbnail = 'video.png';
                            break;
                    }
                    $src = 'tn';
                    break;
                case 2:
                    // music file
                    $src = 'tn';
                    $default_thumbnail = 'audio.png';
                    break;
            }
            if ($row['media_tn_attached'] == 1 && ($src != 'orig' && $src != 'disp')) {
                $tfn = 'tn/' . $row['media_filename'][0] . '/tn_' . $row['media_filename'];
                $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $tfn . $ext;
                $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $tfn . $ext;
            } else {
                if ($src == 'tn' and $row['media_type'] == 0) {
                    $tfn = 'tn/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '_cropcustom';
                    $ext = MG_getMediaExt($_MG_CONF['path_mediaobjects'] . $tfn);
                    $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $tfn . $ext;
                    $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $tfn . $ext;
                } else {
                    $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
                    $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
                }
            }
            $mediaSize = @getimagesize($media_thumbnail_file);
            if ($mediaSize == false) {
                return str_replace($autotag['tagstr'], '', $content);
            }
            if ($autotag['tag'] == 'oimage' || $src == 'orig') {
                $newwidth = $mediaSize[0];
                $newheight = $mediaSize[1];
            } else {
                if ($width > 0) {
                    $tn_height = $width;
                } else {
                    switch ($src) {
                        case 'orig':
                        case 'disp':
                            $tn_height = $mediaSize[0];
                            break;
                        default:
                            $tn_height = 200;
                            break;
                    }
                }
                if ($mediaSize[0] > $mediaSize[1]) {
                    $ratio = $mediaSize[0] / $tn_height;
                    $newwidth = $tn_height;
                    $newheight = round($mediaSize[1] / $ratio);
                } else {
                    $ratio = $mediaSize[1] / $tn_height;
                    $newheight = $tn_height;
                    $newwidth = round($mediaSize[0] / $ratio);
                }
            }
            $tagtext = '<img src="' . $media_thumbnail . '" ' . $alttag . ' style="width:' . $newwidth . 'px;height:' . $newheight . 'px;border:none;vertical-align:bottom;"' . XHTML . '>';
            $link = '';
            if ($alt == 1 && $row['remote_url'] != '') {
                $url = $row['remote_url'];
                if ($autotag['tag'] != 'image' && $enable_link != 0) {
                    $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                } else {
                    $link = $tagtext;
                }
            } else {
                if ($linkID == 0) {
                    $url = $_MG_CONF['site_url'] . '/media.php?s=' . $parm1;
                } else {
                    if ($linkID < 1000000) {
                        $link_album = MG_getAlbumData($linkID, array('album_id', 'hidden'), false);
                        if (!isset($link_album['album_id'])) {
                            $url = $_MG_CONF['site_url'] . '/album.php?aid=' . $linkID;
                            if ($autotag['tag'] != 'image' && $link_album['hidden'] != 1 && $enable_link != 0) {
                                $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                            } else {
                                $link = $tagtext;
                            }
                        } else {
                            $url = $_MG_CONF['site_url'] . '/media.php?s=' . $parm1;
                        }
                    } else {
                        $linkAID = intval(DB_getItem($_TABLES['mg_media_albums'], 'album_id', 'media_id="' . addslashes($linkID) . '"'));
                        if ($linkAID != 0) {
                            $url = $_MG_CONF['site_url'] . '/media.php?s=' . $linkID;
                            $hidden = DB_getItem($_TABLES['mg_albums'], 'hidden', "album_id=" . intval($linkAID));
                            if ($autotag['tag'] != 'image' && $hidden != 1 && $enable_link != 0) {
                                $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                            } else {
                                $link = $tagtext;
                            }
                        } else {
                            $url = $_MG_CONF['site_url'] . '/media.php?s=' . $parm1;
                        }
                    }
                }
            }
            if ($link == '') {
                if ($autotag['tag'] != 'image' && ($album_data['hidden'] != 1 || $enable_link == 2) && $enable_link != 0) {
                    if ($enable_link == 2 && $direct_link != '') {
                        if ($_MG_CONF['disable_lightbox'] == true) {
                            $link = $tagtext;
                        } else {
                            $link = '<a href="' . $direct_link . '" rel="lightbox" title="' . strip_tags(str_replace('$', '&#36;', $caption)) . '">' . $tagtext . '</a>';
                        }
                    } else {
                        $link = '<a href="' . $url . '"' . ($target == '' ? '' : ' target="' . $target . '"') . '>' . $tagtext . '</a>';
                    }
                } else {
                    $link = $tagtext;
                }
            }
            if ($autotag['tag'] == 'img') {
                $link = MG_helper_getContainer($link, $align, 'div');
            } else {
                $T = COM_newTemplate($_MG_CONF['template_path']);
                $T->set_file('tag', $border == 0 ? 'autotag_nb.thtml' : 'autotag.thtml');
                $T->set_var(array('ss_count' => $ss_count, 'align' => $align, 'autotag' => $link, 'caption' => $caption, 'width' => $newwidth, 'framewidth' => $newwidth, 'xhtml' => XHTML, 'float' => $align == 'left' || $align == 'right' ? 'float:' . $align . ';' : '', 'margin-right' => $align == 'left' ? 'margin:15px;' : ''));
                if ($align == 'center') {
                    $T->set_var('margin-right', 'margin:0 auto;');
                }
                $link = $T->finish($T->parse('output', 'tag'));
                if ($align == 'center') {
                    $link = '<div style="text-align:center;">' . LB . $link . '</div>' . LB;
                }
            }
            break;
    }
    return str_replace($autotag['tagstr'], $link, $content);
}
Beispiel #5
0
function MG_parseAlbumsRSS(&$rss, $aid)
{
    global $_MG_CONF, $_CONF, $_TABLES;
    if ($aid == 0) {
        // root_album
        $children = MG_getAlbumChildren($aid);
        foreach ($children as $child) {
            MG_parseAlbumsRSS($rss, $child);
        }
        return;
    }
    $album_data = MG_getAlbumData($aid, array('hidden', 'last_update', 'media_count', 'perm_anon', 'album_title', 'album_desc', 'owner_id'));
    if ($album_data['hidden'] != 1) {
        if ($_MG_CONF['rss_ignore_empty'] == 1 && $album_data['last_update'] != 0 && $album_data['last_update'] != '' && $album_data['media_count'] > 0) {
            if ($_MG_CONF['rss_anonymous_only'] == 1 && $album_data['perm_anon'] > 0) {
                $item = new FeedItem();
                $item->title = $album_data['album_title'];
                $item->link = $_MG_CONF['site_url'] . '/album.php?aid=' . $aid;
                $description = '';
                $childCount = MG_getAlbumChildCount($aid);
                $description = 'Album contains ' . $album_data['media_count'] . ' item and ' . $childCount . ' sub-albums.<br' . XHTML . '><br' . XHTML . '>';
                $filename = MG_getAlbumCover($aid);
                if (substr($filename, 0, 3) == 'tn_') {
                    foreach ($_MG_CONF['validExtensions'] as $ext) {
                        if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $filename[3] . '/' . $filename . $ext)) {
                            $description .= '<img src="' . $_MG_CONF['mediaobjects_url'] . '/tn/' . $filename[3] . '/' . $filename . $ext . '" align="left"' . XHTML . '>';
                            break;
                        }
                    }
                    //                    $description .= '<img src="' . $_MG_CONF['mediaobjects_url'] . '/tn/' . $filename[3] . '/' . $filename . '.jpg" align="left"' . XHTML . '>';
                } elseif ($filename != '') {
                    foreach ($_MG_CONF['validExtensions'] as $ext) {
                        if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $filename[0] . '/' . $filename . $ext)) {
                            $description .= '<img src="' . $_MG_CONF['mediaobjects_url'] . '/tn/' . $filename[0] . '/' . $filename . $ext . '" align="left"' . XHTML . '>';
                            break;
                        }
                    }
                    //                    $description .= '<img src="' . $_MG_CONF['mediaobjects_url'] . '/tn/' . $filename[0] . '/' . $filename . '.jpg" align="left"' . XHTML . '>';
                }
                $description .= $album_data['album_desc'];
                $item->description = $description;
                //optional
                $item->descriptionTruncSize = 500;
                $item->descriptionHtmlSyndicated = true;
                $item->date = strftime("%a, %d %b %Y %H:%M:%S %z", $album_data['last_update']);
                $item->source = $_CONF['site_url'];
                if ($album_data['owner_id'] != '') {
                    $username = DB_getItem($_TABLES['users'], 'username', "uid={$album_data['owner_id']}");
                    $item->author = $username;
                }
                $rss->addItem($item);
            }
        }
    }
    $children = MG_getAlbumChildren($aid);
    foreach ($children as $child) {
        MG_parseAlbumsRSS($rss, $child);
    }
}