Example #1
0
function MG_searchDisplayThumb($M, $sortOrder, $id, $page, $force = 0)
{
    global $_CONF, $_USER, $_MG_CONF, $MG_albums, $_TABLES, $_MG_USERPREFS, $LANG_MG03, $LANG_MG01, $ratedIds;
    $playback_type = $_MG_CONF['search_playback_type'];
    $retval = '';
    $nFrame = new mgFrame();
    $nFrame->constructor('mgShadow');
    $imageFrameTemplate = $nFrame->getTemplate();
    $frWidth = $nFrame->frame['wHL'] + $nFrame->frame['wHR'];
    $frHeight = $nFrame->frame['hVT'] + $nFrame->frame['hVB'];
    $T = new Template(MG_getTemplatePath(0));
    $T->set_file(array('media_cell_image' => 'album_page_body_media_cell.thtml', 'media_rate_results' => 'album_page_body_media_cell_rating.thtml', 'media_comments' => 'album_page_body_media_cell_comment.thtml', 'media_views' => 'album_page_body_media_cell_view.thtml', 'media_cell_keywords' => 'album_page_body_media_cell_keywords.thtml', 'mp3_podcast' => 'mp3_podcast.thtml'));
    $F = new Template($_MG_CONF['template_path']);
    $F->set_var('media_frame', $imageFrameTemplate);
    //$MG_albums[0]->imageFrameTemplate);
    // --- set the default thumbnail
    $default_thumbnail = 'generic.png';
    switch ($M['media_type']) {
        case 0:
            // standard image
            foreach ($_MG_CONF['validExtensions'] as $ext) {
                if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $M['media_filename'][0] . '/' . $M['media_filename'] . $ext)) {
                    $default_thumbnail = 'tn/' . $M['media_filename'][0] . '/' . $M['media_filename'] . $ext;
                    break;
                }
            }
            break;
        case 1:
            // video file
            switch ($M['mime_type']) {
                case 'video/x-flv':
                    $default_thumbnail = 'flv.png';
                    break;
                case 'application/x-shockwave-flash':
                    $default_thumbnail = 'flash.png';
                    break;
                case 'video/mpeg':
                case 'video/x-mpeg':
                case 'video/x-mpeq2a':
                    if ($_MG_CONF['use_wmp_mpeg'] == 1) {
                        $default_thumbnail = 'wmp.png';
                        break;
                    }
                case 'video/x-motion-jpeg':
                case 'video/quicktime':
                case 'video/x-qtc':
                case 'audio/mpeg':
                    $default_thumbnail = 'quicktime.png';
                    break;
                case 'asf':
                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':
                    $default_thumbnail = 'wmp.png';
                    break;
                default:
                    $default_thumbnail = 'video.png';
                    break;
            }
            break;
        case 2:
            // music file
            $default_thumbnail = 'audio.png';
            break;
        case 4:
            // other files
            switch ($M['mime_type']) {
                case 'application/zip':
                case 'zip':
                case 'arj':
                case 'rar':
                case 'gz':
                    $default_thumbnail = 'zip.png';
                    break;
                case 'pdf':
                case 'application/pdf':
                    $default_thumbnail = 'pdf.png';
                    break;
                default:
                    switch ($M['media_mime_ext']) {
                        case 'pdf':
                            $default_thumbnail = 'pdf.png';
                            break;
                        case 'arj':
                            $default_thumbnail = 'zip.png';
                            break;
                        case 'gz':
                            $default_thumbnail = 'zip.png';
                            break;
                        default:
                            $default_thumbnail = 'generic.png';
                            break;
                    }
                    break;
            }
            break;
        case 5:
        case 'embed':
            if (preg_match("/youtube/i", $M['remote_url'])) {
                $default_thumbnail = 'youtube.png';
            } else {
                if (preg_match("/google/i", $M['remote_url'])) {
                    $default_thumbnail = 'googlevideo.png';
                } else {
                    $default_thumbnail = 'remote.png';
                }
            }
            break;
    }
    if ($M['media_tn_attached'] == 1) {
        $media_thumbnail_file = '';
        foreach ($_MG_CONF['validExtensions'] as $ext) {
            if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $M['media_filename'][0] . '/tn_' . $M['media_filename'] . $ext)) {
                $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/tn/' . $M['media_filename'][0] . '/tn_' . $M['media_filename'] . $ext;
                $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . 'tn/' . $M['media_filename'][0] . '/tn_' . $M['media_filename'] . $ext;
                break;
            }
        }
        if ($media_thumbnail_file == '') {
            $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
            $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
        }
    } else {
        $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
        $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
    }
    $resolution_x = 0;
    $resolution_y = 0;
    // type == 1 video
    // type == 2 audio
    if (($M['media_type'] == 1 || $M['media_type'] == 2 || $M['media_type'] == 5) && ($playback_type == 0 || $playback_type == 1)) {
        if ($playback_type == 0 || $playback_type == 1) {
            if ($M['media_type'] == 2) {
                // determine what type of player we will use (WMP, QT or Flash)
                $player = $_MG_CONF['mp3_player'];
                if (isset($_MG_USERPREFS['mp3_player']) && $_MG_USERPREFS['mp3_player'] != -1) {
                    $player = $_MG_USERPREFS['mp3_player'];
                }
                switch ($player) {
                    case 0:
                        // WMP
                        $new_y = 60;
                        $new_x = 350;
                        break;
                    case 1:
                        // QT
                        $new_y = 25;
                        $new_x = 350;
                        break;
                    case 2:
                        $new_y = 360;
                        $new_x = 580;
                        break;
                }
                if ($M['media_tn_attached'] == 1 && $player != 2) {
                    $tnsize = @getimagesize($media_thumbnail_file);
                    $new_y += $tnsize[0];
                    if ($tnsize[1] > $new_x) {
                        $new_x = $tnsize[1];
                    }
                }
                if ($playback_type == 0) {
                    $url_display_item = "javascript:showVideo('" . $_MG_CONF['site_url'] . '/video.php?n=' . $M['media_id'] . "'," . $new_y . ',' . $new_x . ')';
                } else {
                    $url_display_item = $_MG_CONF['site_url'] . '/download.php?mid=' . $MG_media->id;
                }
                $resolution_x = $new_x;
                $resolution_y = $new_y;
            } else {
                // must be a video...
                // 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='" . DB_escapeString($M['media_id']) . "'");
                while ($poRow = DB_fetchArray($poResult)) {
                    $playback_options[$poRow['option_name']] = $poRow['option_value'];
                }
                if (isset($M['media_resolution_x']) && $M['media_resolution_x'] > 0) {
                    $resolution_x = $M['media_resolution_x'];
                    $resolution_y = $M['media_resolution_y'];
                } else {
                    if ($M['media_resolution_x'] == 0 && $M['remote_media'] != 1) {
                        require_once $_CONF['path'] . '/lib/getid3/getid3.php';
                        // Needed for windows only
                        define('GETID3_HELPERAPPSDIR', 'C:/helperapps/');
                        $getID3 = new getID3();
                        // Analyze file and store returned data in $MG_mediaFileInfo
                        $MG_mediaFileInfo = $getID3->analyze($_MG_CONF['path_mediaobjects'] . 'orig/' . $M['media_filename'][0] . '/' . $M['media_filename'] . '.' . $M['media_mime_ext']);
                        getid3_lib::CopyTagsToComments($MG_mediaFileInfo);
                        if ($MG_mediaFileInfo['video']['resolution_x'] < 1 || $MG_mediaFileInfo['video']['resolution_y'] < 1) {
                            if (isset($MG_mediaFileInfo['meta']['onMetaData']['width']) && isset($MG_mediaFileInfo['meta']['onMetaData']['height'])) {
                                $resolution_x = $MG_mediaFileInfo['meta']['onMetaData']['width'];
                                $resolution_y = $MG_mediaFileInfo['meta']['onMetaData']['height'];
                            } else {
                                $resolution_x = -1;
                                $resolution_y = -1;
                            }
                        } else {
                            $resolution_x = $MG_mediaFileInfo['video']['resolution_x'];
                            $resolution_y = $MG_mediaFileInfo['video']['resolution_y'];
                        }
                        if ($resolution_x != 0) {
                            $sql = "UPDATE " . $_TABLES['mg_media'] . " SET media_resolution_x=" . $resolution_x . ",media_resolution_y=" . $resolution_y . " WHERE media_id='" . DB_escapeString($M['media_id']) . "'";
                            DB_query($sql, 1);
                        }
                    } else {
                        $resolution_x = $M['media_resolution_x'];
                        $resolution_y = $M['media_resolution_y'];
                    }
                }
                $resolution_x = $playback_options['width'];
                $resolution_y = $playback_options['height'];
                if ($resolution_x < 1 || $resolution_y < 1) {
                    $resolution_x = 480;
                    $resolution_y = 320;
                } else {
                    $resolution_x = $resolution_x + 40;
                    $resolution_y = $resolution_y + 40;
                }
                if ($M['mime_type'] == 'video/x-flv' && $_MG_CONF['use_flowplayer'] != 1) {
                    $resolution_x = $resolution_x + 60;
                    if ($resolution_x < 590) {
                        $resolution_x = 590;
                    }
                    $resolution_y = $resolution_y + 80;
                    if ($resolution_y < 500) {
                        $resolution_y = 500;
                    }
                }
                if ($M['media_type'] == 5) {
                    $resolution_x = 460;
                    $resolution_y = 380;
                }
                $url_display_item = "javascript:showVideo('" . $_MG_CONF['site_url'] . '/video.php?n=' . $M['media_id'] . "'," . $resolution_y . ',' . $resolution_x . ')';
            }
        } else {
            $url_display_item = $_MG_CONF['site_url'] . '/download.php?mid=' . $M['media_id'];
        }
        // check to see if comments and rating are enabled, if not, put a link to edit...
        if ($MG_albums[0]->access == 3) {
            $T->set_var(array('edit_link' => '<br/><a href="' . $_MG_CONF['site_url'] . '/admin.php?mode=mediaedit&amp;s=1&amp;album_id=' . $M['album_id'] . '&amp;mid=' . $M['media_id'] . '">' . $LANG_MG01['edit'] . '</a>'));
        } else {
            $T->set_var(array('edit_link' => ''));
        }
    } else {
        $url_display_item = $_MG_CONF['site_url'] . '/media.php?f=0' . '&amp;sort=' . $sortOrder . '&amp;s=' . $M['media_id'] . '&amp;i=' . $id . '&amp;p=' . $page;
    }
    if ($M['media_type'] == 4) {
        // other
        $url_display_item = $_MG_CONF['site_url'] . '/download.php?mid=' . $M['media_id'];
    }
    $media_size = @getimagesize($media_thumbnail_file);
    if ($media_size == false) {
        $default_thumbnail = 'missing.png';
        $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
        $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
        $media_size = @getimagesize($media_thumbnail_file);
    }
    if ($_MG_CONF['use_upload_time'] == 1) {
        $media_time = MG_getUserDateTimeFormat($M['media_upload_time']);
    } else {
        $media_time = MG_getUserDateTimeFormat($M['media_time']);
    }
    $url_media_item = $url_display_item;
    // -- decide what thumbnail size to use, small, medium, large...
    if (isset($_MG_USERPREFS['tn_size']) && $_MG_USERPREFS['tn_size'] != -1) {
        $tn_size = $_MG_USERPREFS['tn_size'];
    } else {
        $tn_size = $_MG_CONF['gallery_tn_size'];
    }
    switch ($tn_size) {
        case '0':
            //small
            $tn_height = 100;
            break;
        case '1':
            //medium
            $tn_height = 150;
            break;
        case '2':
            $tn_height = 200;
            break;
        case '3':
            $tn_height = 200;
            break;
        default:
            $tn_height = 150;
            break;
    }
    if ($media_size[0] > $media_size[1]) {
        $ratio = $media_size[0] / $tn_height;
        $newwidth = $tn_height;
        $newheight = round($media_size[1] / $ratio);
    } else {
        $ratio = $media_size[1] / $tn_height;
        $newheight = $tn_height;
        $newwidth = round($media_size[0] / $ratio);
    }
    if ($media_size[0] > $media_size[1]) {
        $ratio = $media_size[0] / 50;
        $smallwidth = 50;
        $smallheight = round($media_size[1] / $ratio);
    } else {
        $ratio = $media_size[1] / 50;
        $smallheight = 50;
        $smallwidth = round($media_size[0] / $ratio);
    }
    if ($M['media_user_id'] != "" && $M['media_user_id'] > 1) {
        $username = DB_getItem($_TABLES['users'], 'username', "uid=" . $M['media_user_id']);
    } else {
        $username = '******';
    }
    if ($M['mime_type'] == 'audio/mpeg') {
        $T->set_var(array('play_now' => '', 'download_now' => $_MG_CONF['site_url'] . '/download.php?mid=' . $M['media_id'], 'play_in_popup' => "javascript:showVideo('" . $_MG_CONF['site_url'] . '/video.php?n=' . $M['media_id'] . "'," . $resolution_y . ',' . $resolution_x . ')', 'mp3_file' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $M['media_filename'][0] . '/' . $M['media_filename'] . '.' . $M['media_mime_ext'], 'site_url' => $_MG_CONF['site_url'], 'id' => $M['media_mime_ext'] . rand()));
        $T->parse('mp3_podcast', 'mp3_podcast');
    } else {
        $T->set_var(array('mp3_podcast' => ''));
    }
    /*
     * build the small rating bar
     *
     */
    if ($MG_albums[$M['album_id']]->enable_rating > 0) {
        $ip = $_SERVER['REMOTE_ADDR'];
        $uid = COM_isAnonUser() ? 1 : $_USER['uid'];
        $static = false;
        // check to see if we are the owner, if so, no rating for us...
        if (isset($_USER['uid']) && $_USER['uid'] == $M['media_user_id']) {
            $static = true;
        } else {
            if (in_array($M['media_id'], $ratedIds)) {
                $static = true;
            } else {
                $static = '';
            }
        }
        if ($MG_albums[$M['album_id']]->enable_rating == 1 && COM_isAnonUser()) {
            $static = 'static';
        }
        $rating_box = RATING_ratingBar('mediagallery', $M['media_id'], $M['media_votes'], $M['media_rating'], $static, 5, '', 'sm');
    } else {
        $rating_box = '';
    }
    $T->set_var('rating_box', $rating_box);
    if ($M['media_type'] == 0) {
        $direct_url = 'disp/' . $M['media_filename'][0] . '/' . $M['media_filename'] . '.' . $M['media_mime_ext'];
        if (!file_exists($_MG_CONF['path_mediaobjects'] . $direct_url)) {
            $direct_url = $_MG_CONF['mediaobjects_url'] . '/' . 'disp/' . $M['media_filename'][0] . '/' . $M['media_filename'] . '.jpg';
        } else {
            $direct_url = $_MG_CONF['mediaobjects_url'] . '/' . $direct_url;
        }
    } else {
        $direct_url = $media_thumbnail;
    }
    if ($MG_albums[$M['album_id']]->access == 3) {
        $edit_item = '<a href="' . $_MG_CONF['site_url'] . '/admin.php?mode=mediaedit&amp;s=1&amp;album_id=' . $M['album_id'] . '&amp;mid=' . $M['media_id'] . '">' . $LANG_MG01['edit'] . '</a>';
    } else {
        $edit_item = '';
    }
    $L = new Template(MG_getTemplatePath(0));
    $L->set_file('media_link', 'medialink.thtml');
    $L->set_var('href', $url_media_item);
    $L->set_var('hrefdirect', $direct_url);
    $L->set_var('caption', PLG_replaceTags($M['media_title'], 'mediagallery', 'media_title'));
    $L->set_var('id', 'id' . rand());
    $L->parse('media_link_start', 'media_link');
    $media_start_link = $L->finish($L->get_var('media_link_start'));
    $T->set_var(array('row_height' => $tn_height + 40, 'media_title' => isset($M['media_title']) && $M['media_title'] != '' && $M['media_title'] != ' ' ? PLG_replaceTags($M['media_title'], 'mediagallery', 'media_title') : '', 'media_description' => isset($M['media_desc']) && $M['media_desc'] != '' && $M['media_desc'] != ' ' ? PLG_replaceTags($M['media_desc'], 'mediagallery', 'media_title') : '', 'media_tag' => isset($M['media_title']) && $M['media_title'] != '' && $M['media_title'] != ' ' ? strip_tags($M['media_title']) : '', 'media_time' => $media_time[0], 'media_owner' => $username, 'site_url' => $_MG_CONF['site_url'], 'lang_published' => $LANG_MG03['published'], 'lang_on' => $LANG_MG03['on'], 'media_link_start' => '<a href="' . $url_media_item . '">', 'media_link_end' => '</a>', 'artist' => isset($M['artist']) && $M['artist'] != ' ' ? $M['artist'] : '', 'musicalbum' => isset($M['album']) && $M['album'] != ' ' ? $M['album'] : '', 'genre' => isset($M['genre']) && $M['genre'] != ' ' ? $M['genre'] : '', 'search_album' => $LANG_MG01['album'] . ': <a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $M['album_id'] . '">' . $MG_albums[$M['album_id']]->title . '</a>'));
    // frame template variables
    $F->set_var(array('media_link_start' => $media_start_link, 'media_link_end' => '</a>', 'url_media_item' => $url_media_item, 'url_display_item' => $url_display_item, 'media_thumbnail' => $media_thumbnail, 'media_size' => 'width="' . $newwidth . '" height="' . $newheight . '"', 'media_height' => $newheight, 'media_width' => $newwidth, 'border_width' => $newwidth + 15, 'border_height' => $newheight + 15, 'row_height' => $tn_height + 40, 'frWidth' => $newwidth - $frWidth, 'frHeight' => $newheight - $frHeight, 'media_tag' => strip_tags($M['media_desc']), 'search_album' => $LANG_MG01['album'] . ': <a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $M['album_id'] . '">' . $MG_albums[$M['album_id']]->title . '</a>'));
    $F->parse('media', 'media_frame');
    $media_item_thumbnail = $F->finish($F->get_var('media'));
    $T->set_var('media_item_thumbnail', $media_item_thumbnail);
    if (!empty($M['media_keywords'])) {
        $kwText = '';
        $keyWords = array();
        $keyWords = explode(' ', $M['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 .= $keyWords[$i] . ' ';
        }
        $T->set_var(array('media_keywords' => $kwText, 'lang_keywords' => $LANG_MG01['keywords']));
        $T->parse('media_cell_keywords', 'media_cell_keywords');
    } else {
        $T->set_var('lang_keywords', '');
    }
    if ($_MG_CONF['search_enable_rating']) {
        if ($M['media_type'] == 4 || $M['media_type'] == 1 && $playback_type != 2 || $M['media_type'] == 2 && $playback_type != 2 || $M['media_type'] == 5 && $playback_type != 2) {
            $rateLink = '<a href="' . $_MG_CONF['site_url'] . '/media.php?f=0' . '&amp;sort=' . $sortOrder . '&amp;s=' . $M['media_id'] . '">' . $LANG_MG03['rating'] . '</a>';
        } else {
            $rateLink = $LANG_MG03['rating'];
        }
        $rating = $rateLink . ': <strong> ' . $M['media_rating'] / 2 . '</strong>/5 (' . $M['media_votes'] . ' ' . $LANG_MG03['votes'] . ')';
        $T->set_var(array('media_rating' => $rating));
        $T->parse('media_rate_results', 'media_rate_results');
    }
    if ($_MG_CONF['search_enable_views']) {
        $T->set_var(array('media_views_count' => $M['media_views'], 'lang_views' => $LANG_MG03['views']));
        $T->parse('media_views', 'media_views');
    }
    $T->parse('media_cell', 'media_cell_image');
    $retval = $T->finish($T->get_var('media_cell'));
    return $retval;
}
Example #2
0
 function displayThumb($s, $sortOrder, $force = 0)
 {
     global $_USER, $_CONF, $_MG_CONF, $MG_albums, $_TABLES, $_MG_USERPREFS, $LANG_MG03, $LANG_MG01, $glversion, $ratedIds;
     $retval = '';
     $T = new Template(MG_getTemplatePath($this->album_id));
     if ($MG_albums[$this->album_id]->display_columns == 1) {
         $media_cell_image_template = 'album_page_body_media_cell_1.thtml';
     } else {
         $media_cell_image_template = 'album_page_body_media_cell.thtml';
     }
     if ($force) {
         $media_cell_image_template = 'album_page_body_media_cell.thtml';
     }
     $T->set_file(array('media_cell_image' => $media_cell_image_template, 'media_rate_results' => 'album_page_body_media_cell_rating.thtml', 'media_comments' => 'album_page_body_media_cell_comment.thtml', 'media_views' => 'album_page_body_media_cell_view.thtml', 'media_cell_keywords' => 'album_page_body_media_cell_keywords.thtml', 'mp3_podcast' => 'mp3_podcast.thtml'));
     $F = new Template($_MG_CONF['template_path']);
     $F->set_var('media_frame', $MG_albums[$this->album_id]->imageFrameTemplate);
     // --- set the default thumbnail
     switch ($this->type) {
         case 0:
             // standard image
             $default_thumbnail = 'tn/' . $this->filename[0] . '/' . $this->filename . '.' . $this->mime_ext;
             if (!file_exists($_MG_CONF['path_mediaobjects'] . $default_thumbnail)) {
                 $default_thumbnail = 'tn/' . $this->filename[0] . '/' . $this->filename . '.jpg';
             }
             break;
         case 1:
             // video file
             switch ($this->mime_type) {
                 case 'video/x-flv':
                     $default_thumbnail = 'placeholder_flv.svg';
                     break;
                 case 'application/x-shockwave-flash':
                     $default_thumbnail = 'placeholder_flash.svg';
                     break;
                 case 'video/mpeg':
                 case 'video/x-mpeg':
                 case 'video/x-mpeq2a':
                     if ($_MG_CONF['use_wmp_mpeg'] == 1) {
                         $default_thumbnail = 'placeholder_video.svg';
                         break;
                     }
                 case 'video/x-motion-jpeg':
                 case 'video/quicktime':
                 case 'video/x-qtc':
                 case 'audio/mpeg':
                 case 'video/x-m4v':
                     $default_thumbnail = 'placeholder_quicktime.svg';
                     break;
                 case 'asf':
                 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':
                     $default_thumbnail = 'placeholder_video.svg';
                     break;
                 default:
                     $default_thumbnail = 'placeholder_video.svg';
                     break;
             }
             break;
         case 2:
             // music file
             $default_thumbnail = 'placeholder_audio.svg';
             break;
         case 4:
             // other files
             switch ($this->mime_type) {
                 case 'application/zip':
                 case 'zip':
                 case 'arj':
                 case 'rar':
                 case 'gz':
                     $default_thumbnail = 'zip.png';
                     break;
                 case 'pdf':
                 case 'application/pdf':
                     $default_thumbnail = 'placeholder_pdf.svg';
                     break;
                 default:
                     if (isset($_MG_CONF['dt'][$this->mime_ext])) {
                         $default_thumbnail = $_MG_CONF['dt'][$this->mime_ext];
                     } else {
                         switch ($this->mime_ext) {
                             case 'pdf':
                                 $default_thumbnail = 'placeholder_pdf.svg';
                                 break;
                             case 'arj':
                                 $default_thumbnail = 'zip.png';
                                 break;
                             case 'gz':
                                 $default_thumbnail = 'zip.png';
                                 break;
                             default:
                                 $default_thumbnail = 'generic.png';
                                 break;
                         }
                     }
                     break;
             }
             break;
         case 5:
         case 'embed':
             if (preg_match("/youtube/i", $this->remote_url)) {
                 $default_thumbnail = 'youtube.png';
             } else {
                 if (preg_match("/google/i", $this->remote_url)) {
                     $default_thumbnail = 'googlevideo.png';
                 } else {
                     $default_thumbnail = 'remote.png';
                 }
             }
             break;
     }
     if ($this->tn_attached == 1) {
         $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
         $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
         foreach ($_MG_CONF['validExtensions'] as $ext) {
             if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $this->filename[0] . '/tn_' . $this->filename . $ext)) {
                 $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/tn/' . $this->filename[0] . '/tn_' . $this->filename . $ext;
                 $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . 'tn/' . $this->filename[0] . '/tn_' . $this->filename . $ext;
                 break;
             }
         }
     } else {
         $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
         $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
     }
     // type == 1 video
     // type == 2 audio
     if (($this->type == 1 || $this->type == 2 || $this->type == 5) && ($MG_albums[$this->album_id]->playback_type == 0 || $MG_albums[$this->album_id]->playback_type == 1) && $_MG_CONF['popup_from_album'] == 1) {
         if ($MG_albums[$this->album_id]->playback_type == 0) {
             if ($this->type == 2) {
                 // determine what type of player we will use (WMP, QT or Flash)
                 $player = $_MG_CONF['mp3_player'];
                 if (isset($_MG_USERPREFS['mp3_player']) && $_MG_USERPREFS['mp3_player'] != -1) {
                     $player = $_MG_USERPREFS['mp3_player'];
                 }
                 switch ($player) {
                     case 0:
                         // WMP
                         $new_y = 260;
                         $new_x = 340;
                         break;
                     case 1:
                         // QT
                         $new_y = 25;
                         $new_x = 350;
                         break;
                     case 2:
                         $new_y = 360;
                         $new_x = 580;
                         break;
                 }
                 if ($this->mime_type == 'audio/mpeg') {
                     $new_y = 360;
                     $new_x = 580;
                 }
                 if ($this->tn_attached == 1 && $player != 2) {
                     $tnsize = @getimagesize($media_thumbnail_file);
                     $new_y += $tnsize[0];
                     if ($tnsize[1] > $new_x) {
                         $new_x = $tnsize[1];
                     }
                 }
                 if ($MG_albums[$this->album_id]->playback_type == 0) {
                     $url_display_item = "javascript:showVideo('" . $_MG_CONF['site_url'] . '/video.php?n=' . $this->id . "'," . $new_y . ',' . $new_x . ')';
                 } else {
                     $url_display_item = $_MG_CONF['site_url'] . '/download.php?mid=' . $this->id;
                 }
                 $resolution_x = $new_x;
                 $resolution_y = $new_y;
             } else {
                 // must be a video...
                 // 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='" . DB_escapeString($this->id) . "'");
                 while ($poRow = DB_fetchArray($poResult)) {
                     $playback_options[$poRow['option_name']] = $poRow['option_value'];
                 }
                 if ($this->resolution_x > 0) {
                     $resolution_x = $this->resolution_x;
                     $resolution_y = $this->resolution_y;
                 } else {
                     if ($this->media_resolution_x == 0 && $this->remote_media != 1) {
                         $size = @filesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $this->filename[0] . '/' . $this->filename . '.' . $this->mime_ext);
                         // skip files over 8M in size..
                         if ($size < 8388608) {
                             $ThisFileInfo = IMG_getMediaMetaData($_MG_CONF['path_mediaobjects'] . 'orig/' . $this->filename[0] . '/' . $this->filename . '.' . $this->mime_ext);
                             if ($ThisFileInfo['video']['resolution_x'] < 1 || $ThisFileInfo['video']['resolution_y'] < 1) {
                                 if (isset($ThisFileInfo['meta']['onMetaData']['width']) && isset($ThisFileInfo['meta']['onMetaData']['height'])) {
                                     $resolution_x = $ThisFileInfo['meta']['onMetaData']['width'];
                                     $resolution_y = $ThisFileInfo['meta']['onMetaData']['height'];
                                 } else {
                                     $resolution_x = -1;
                                     $resolution_y = -1;
                                 }
                             } else {
                                 $resolution_x = $ThisFileInfo['video']['resolution_x'];
                                 $resolution_y = $ThisFileInfo['video']['resolution_y'];
                             }
                             if ($resolution_x != 0) {
                                 $sql = "UPDATE " . $_TABLES['mg_media'] . " SET media_resolution_x=" . intval($resolution_x) . ",media_resolution_y=" . intval($resolution_y) . " WHERE media_id='" . DB_escapeString($this->id) . "'";
                                 DB_query($sql, 1);
                             }
                         }
                     } else {
                         $resolution_x = $this->resolution_x;
                         $resolution_y = $this->resolution_y;
                     }
                 }
                 $resolution_x = $playback_options['width'];
                 $resolution_y = $playback_options['height'];
                 if ($resolution_x < 1 || $resolution_y < 1) {
                     $resolution_x = 480;
                     $resolution_y = 320;
                 } else {
                     $resolution_x = $resolution_x + 40;
                     $resolution_y = $resolution_y + 40;
                 }
                 if ($this->mime_type == 'video/x-flv' && $_MG_CONF['use_flowplayer'] != 1) {
                     $resolution_x = $resolution_x + 60;
                     if ($resolution_x < 590) {
                         $resolution_x = 590;
                     }
                     $resolution_y = $resolution_y + 80;
                     if ($resolution_y < 500) {
                         $resolution_y = 500;
                     }
                 }
                 if ($this->type == 5) {
                     $resolution_x = 460;
                     $resolution_y = 380;
                 }
                 $url_display_item = "javascript:showVideo('" . $_MG_CONF['site_url'] . '/video.php?n=' . $this->id . "'," . $resolution_y . ',' . $resolution_x . ')';
             }
         } else {
             $url_display_item = $_MG_CONF['site_url'] . '/download.php?mid=' . $this->id;
         }
         // check to see if comments and rating are enabled, if not, put a link to edit...
         if ($MG_albums[$this->album_id]->access == 3) {
             $T->set_var(array('edit_link' => '<br/><a href="' . $_MG_CONF['site_url'] . '/admin.php?mode=mediaedit&amp;s=1&amp;album_id=' . $this->album_id . '&amp;mid=' . $this->id . '">' . $LANG_MG01['edit'] . '</a>'));
         } else {
             $T->set_var(array('edit_link' => ''));
         }
     } else {
         if ($MG_albums[$this->album_id]->useAlternate == 1 && $this->type != 5 && !empty($this->remote_url)) {
             $url_display_item = $this->remote_url;
         } else {
             $url_display_item = $_MG_CONF['site_url'] . '/media.php?f=0' . '&amp;sort=' . $sortOrder . '&amp;s=' . $this->id;
         }
     }
     if ($this->type == 4) {
         // other
         $url_display_item = $_MG_CONF['site_url'] . '/download.php?mid=' . $this->id;
     }
     if (strstr($media_thumbnail_file, '.svg')) {
         $media_size = array($MG_albums[$this->album_id]->tnWidth, $MG_albums[$this->album_id]->tnHeight);
     } else {
         $media_size = @getimagesize($media_thumbnail_file);
     }
     if ($media_size == false) {
         if ($this->type == 2) {
             $default_thumbnail = 'placeholder_audio.svg';
         } else {
             $default_thumbnail = 'placeholder.svg';
         }
         $media_thumbnail = $_MG_CONF['mediaobjects_url'] . '/' . $default_thumbnail;
         $media_thumbnail_file = $_MG_CONF['path_mediaobjects'] . $default_thumbnail;
         $media_size = array($tn_width, $tn_height);
         //@getimagesize($media_thumbnail_file);
     }
     $media_time = MG_getUserDateTimeFormat($this->time);
     $upload_time = MG_getUserDateTimeFormat($this->upload_time);
     $url_media_item = $url_display_item;
     // -- decide what thumbnail size to use, small, medium, large...
     if (isset($_MG_USERPREFS['tn_size']) && $_MG_USERPREFS['tn_size'] != -1) {
         $tn_size = $_MG_USERPREFS['tn_size'];
     } else {
         $tn_size = $MG_albums[$this->album_id]->tn_size;
     }
     switch ($tn_size) {
         case '0':
             //small
             $tn_height = 100;
             $tn_width = 100;
             break;
         case '1':
             //medium
             $tn_height = 150;
             $tn_width = 150;
             break;
         case '2':
             $tn_height = 200;
             $tn_width = 200;
             break;
         case '3':
         case '4':
             $tn_height = $MG_albums[$this->album_id]->tnHeight;
             $tn_width = $MG_albums[$this->album_id]->tnWidth;
             if ($tn_height == 0) {
                 $tn_height = 200;
             }
             if ($tn_width == 0) {
                 $tn_width = 200;
             }
             break;
         default:
             $tn_height = 150;
             $tn_width = 150;
             break;
     }
     if ($media_size[0] > $media_size[1]) {
         // landscape
         $ratio = $media_size[0] / $tn_width;
         $newwidth = $tn_width;
         $newheight = round($media_size[1] / $ratio);
     } else {
         $ratio = $media_size[1] / $tn_height;
         if ($ratio == 0) {
             $newheight = $tn_height;
             $newwidth = $tn_width;
         } else {
             $newheight = $tn_height;
             $newwidth = round($media_size[0] / $ratio);
         }
     }
     if ($media_size[0] > $media_size[1]) {
         $ratio = $media_size[0] / 50;
         $smallwidth = 50;
         $smallheight = round($media_size[1] / $ratio);
     } else {
         $ratio = $media_size[1] / 50;
         if ($ratio == 0) {
             $smallheight = 50;
             $smallwidth = 50;
         } else {
             $smallheight = 50;
             $smallwidth = round($media_size[0] / $ratio);
         }
     }
     if ($this->owner_id != "" && $this->owner_id > 1) {
         $username = DB_getItem($_TABLES['users'], 'username', "uid=" . intval($this->owner_id));
     } else {
         $username = '******';
     }
     if (!isset($resolution_x)) {
         $resolution_x = $newwidth;
     }
     if (!isset($resolution_y)) {
         $resolution_y = $newheight;
     }
     if ($this->mime_type == 'audio/mpeg' && $MG_albums[$this->album_id]->mp3ribbon) {
         $T->set_var(array('mp3_file' => $_MG_CONF['mediaobjects_url'] . '/orig/' . $this->filename[0] . '/' . $this->filename . '.' . $this->mime_ext, 'site_url' => $_MG_CONF['site_url'], 'id' => $this->mime_ext . rand()));
         $T->parse('mp3_podcast', 'mp3_podcast');
     } else {
         $T->set_var(array('mp3_podcast' => ''));
     }
     /*
      * build the small rating bar
      *
      */
     if ($MG_albums[$this->album_id]->enable_rating > 0) {
         $uid = COM_isAnonUser() ? 1 : $_USER['uid'];
         $static = false;
         // check to see if we are the owner, if so, no rating for us...
         if (isset($_USER['uid']) && $_USER['uid'] == $this->owner_id) {
             $static = true;
             $voted = 0;
         } else {
             if (in_array($this->id, $ratedIds)) {
                 $static = true;
                 $voted = 1;
             } else {
                 $static = 0;
                 $voted = 0;
             }
         }
         if ($MG_albums[$this->album_id]->enable_rating == 1 && COM_isAnonUser()) {
             $static = true;
         }
         if ($_MG_CONF['use_large_stars'] == 1) {
             $starSize = '';
         } else {
             $starSize = 'sm';
         }
         $rating_box = RATING_ratingBar('mediagallery', $this->id, $this->votes, $this->rating, $voted, 5, $static, $starSize);
     } else {
         $rating_box = '';
     }
     $T->set_var('rating_box', '<center>' . $rating_box . '</center>');
     $fs_bytes = @filesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $this->filename[0] . '/' . $this->filename . '.' . $this->mime_ext);
     $fileSize = MG_get_size($fs_bytes);
     $direct_url = 'disp/' . $this->filename[0] . '/' . $this->filename . '.' . $this->mime_ext;
     if (!file_exists($_MG_CONF['path_mediaobjects'] . $direct_url)) {
         $direct_url = 'disp/' . $this->filename[0] . '/' . $this->filename . '.jpg';
     }
     if ($MG_albums[$this->album_id]->access == 3) {
         $edit_item = '<a href="' . $_MG_CONF['site_url'] . '/admin.php?mode=mediaedit&amp;s=1&amp;album_id=' . $this->album_id . '&amp;mid=' . $this->id . '">' . $LANG_MG01['edit'] . '</a>';
     } else {
         $edit_item = '';
     }
     $L = new Template(MG_getTemplatePath($this->album_id));
     $L->set_file('media_link', 'medialink.thtml');
     $L->set_var('href', $url_media_item);
     if ($this->type == 0) {
         if ($this->remote == 1) {
             $L->set_var('hrefdirect', $this->remote_url);
         } else {
             $L->set_var('hrefdirect', $_MG_CONF['mediaobjects_url'] . '/' . $direct_url);
         }
     }
     $caption = PLG_replaceTags(str_replace('$', '&#36;', $this->title), 'mediagallery', 'media_description');
     if ($this->owner_id == $_USER['uid'] || SEC_hasRights('mediagallery.admin')) {
         $caption .= '<br />(' . $this->id . ')';
     }
     $L->set_var('caption', $caption);
     $L->set_var('id', 'id' . rand());
     $L->parse('media_link_start', 'media_link');
     $media_start_link = $L->finish($L->get_var('media_link_start'));
     $T->set_var(array('play_now' => '', 'download_now' => $_MG_CONF['site_url'] . '/download.php?mid=' . $this->id, 'play_in_popup' => "javascript:showVideo('" . $_MG_CONF['site_url'] . '/video.php?n=' . $this->id . "'," . $resolution_y . ',' . $resolution_x . ')', 'row_height' => $tn_height + 40, 'media_title' => PLG_replaceTags($this->title, 'mediagallery', 'media_title'), 'media_description' => PLG_replaceTags(nl2br($this->description), 'mediagallery', 'media_description'), 'media_tag' => strip_tags($this->title), 'media_time' => $media_time[0], 'upload_time' => $upload_time[0], 'media_owner' => $username, 'site_url' => $_MG_CONF['site_url'], 'lang_published' => $LANG_MG03['published'], 'lang_on' => $LANG_MG03['on'], 'lang_hyphen' => $this->album == '' ? '' : '-', 'media_link_start' => $media_start_link, 'media_link_end' => '</a>', 'artist' => $this->artist, 'musicalbum' => $this->album != '' ? $this->album : '', 'genre' => $this->genre != '' ? $this->genre : '', 'alt_edit_link' => $edit_item, 'filesize' => $fileSize, 'media_id' => $this->id, 'raw_media_thumbnail' => $media_thumbnail, 'display_url' => $url_media_item));
     // frame template variables
     $F->set_var(array('media_id' => $this->id, 'media_link_start' => $media_start_link, 'media_link_end' => '</a>', 'url_media_item' => $url_media_item, 'url_display_item' => $url_display_item, 'media_thumbnail' => $media_thumbnail, 'media_size' => 'width="' . $newwidth . '" height="' . $newheight . '"', 'media_height' => $newheight, 'media_width' => $newwidth, 'border_width' => $newwidth + 15, 'border_height' => $newheight + 15, 'row_height' => $tn_height + 40, 'frWidth' => $newwidth - $MG_albums[$this->album_id]->frWidth, 'frHeight' => $newheight - $MG_albums[$this->album_id]->frHeight, 'media_tag' => strip_tags($this->description), 'filesize' => $fileSize));
     $F->parse('media', 'media_frame');
     $media_item_thumbnail = $F->finish($F->get_var('media'));
     $T->set_var(array('media_item_thumbnail' => $media_item_thumbnail, 'url_media_item' => $url_media_item, 'url_display_item' => $url_display_item, 'media_thumbnail' => $media_thumbnail, 'media_size' => 'width="' . $newwidth . '" height="' . $newheight . '"'));
     if ($MG_albums[$this->album_id]->enable_keywords) {
         if (!empty($this->keywords)) {
             $kwText = '';
             $keyWords = array();
             $keyWords = explode(' ', $this->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> ';
             }
             $T->set_var(array('media_keywords' => $kwText, 'lang_keywords' => $LANG_MG01['keywords']));
             $T->parse('media_cell_keywords', 'media_cell_keywords');
         } else {
             $T->set_var('lang_keywords', '');
         }
     } else {
         $T->set_var(array('media_cell_keywords' => '', 'lang_keywords' => ''));
     }
     if ($MG_albums[$this->album_id]->enable_rating) {
         $rating = $LANG_MG03['rating'] . ': <strong> ' . $this->rating / 2 . '</strong>/5 (' . $this->votes . ' ' . $LANG_MG03['votes'] . ')';
         $T->set_var('media_rating', $rating);
         $T->parse('media_rate_results', 'media_rate_results');
     }
     if ($MG_albums[$this->album_id]->enable_comments) {
         if ($this->type == 4 || $this->type == 1 && $MG_albums[$this->album_id]->playback_type != 2 || $this->type == 2 && $MG_albums[$this->album_id]->playback_type != 2 || $this->type == 5 && $MG_albums[$this->album_id]->playback_type != 2) {
             $cmtLink = '<a href="' . $_MG_CONF['site_url'] . '/media.php?f=0' . '&amp;sort=' . $sortOrder . '&amp;s=' . $this->id . '">' . $LANG_MG03['comments'] . '</a>';
             $cmtLink_alt = '';
         } else {
             $cmtLink = $LANG_MG03['comments'];
             $cmtLink_alt = '<a href="' . $_MG_CONF['site_url'] . '/media.php?f=0' . '&amp;sort=' . $sortOrder . '&amp;s=' . $this->id . '">' . $LANG_MG03['comments'] . '</a>';
         }
         $T->set_var(array('media_comments_count' => $this->comments, 'lang_comments' => $cmtLink, 'lang_comments_hot' => $cmtLink_alt));
         $T->parse('media_comments', 'media_comments');
     }
     if ($MG_albums[$this->album_id]->enable_views) {
         $T->set_var(array('media_views_count' => $this->views, 'lang_views' => $LANG_MG03['views']));
         $T->parse('media_views', 'media_views');
     }
     $T->set_var(array('max-width' => $tn_width));
     PLG_templateSetVars('mediagallery', $T);
     $T->parse('media_cell', 'media_cell_image');
     $retval = $T->finish($T->get_var('media_cell'));
     return $retval;
 }
Example #3
0
 /**
  *   Display the detail page for the product.
  *
  *   @return string      HTML for the product page.
  */
 public function Detail()
 {
     global $_CONF, $_PP_CONF, $_TABLES, $LANG_PP, $_USER, $_SYSTEM;
     USES_lib_comments();
     $prod_id = $this->id;
     if ($prod_id < 1 || !$this->enabled || !$this->isAvailable()) {
         return PAYPAL_errorMessage($LANG_PP['invalid_product_id'], 'info');
     }
     $retval = COM_startBlock();
     // Set the template dir based on the configured template version
     $tpl_dir = PAYPAL_PI_PATH . '/templates/detail/' . $_PP_CONF['product_tpl_ver'];
     $T = new Template($tpl_dir);
     $T->set_file('product', 'product_detail_attrib.thtml');
     $name = $this->name;
     $l_desc = PLG_replaceTags($this->description);
     $s_desc = PLG_replaceTags($this->short_description);
     // Highlight the query terms if coming from a search
     if (isset($_REQUEST['query']) && !empty($_REQUEST['query'])) {
         $name = COM_highlightQuery($name, $_REQUEST['query']);
         $l_desc = COM_highlightQuery($l_desc, $_REQUEST['query']);
         $s_desc = COM_highlightQuery($s_desc, $_REQUEST['query']);
     }
     $onsale = $this->isOnSale();
     $act_price = $onsale ? $this->sale_price : $this->price;
     $qty_disc_txt = '';
     foreach ($this->qty_discounts as $qty => $pct) {
         $qty_disc_txt .= sprintf('Buy %d, save %.02f%%<br />', $qty, $pct);
     }
     // Get custom text input fields
     if ('' != $this->custom) {
         $T->set_block('product', 'CustAttrib', 'cAttr');
         $text_field_names = explode('|', $this->custom);
         foreach ($text_field_names as $id => $text_field_name) {
             $T->set_var(array('fld_id' => "cust_text_fld_{$id}", 'fld_name' => htmlspecialchars($text_field_name)));
             $T->parse('cAttr', 'CustAttrib', true);
         }
     }
     $T->set_var(array('is_uikit' => $_SYSTEM['framework'] == 'uikit' ? 'true' : '', 'have_attributes' => $this->hasAttributes(), 'id' => $prod_id, 'name' => $name, 'short_description' => $s_desc, 'description' => $l_desc, 'cur_decimals' => $this->currency->Decimals(), 'price' => $this->currency->FormatValue($act_price), 'orig_price' => $this->currency->Format($this->price), 'on_sale' => $onsale ? 'true' : '', 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'price_prefix' => $this->currency->Pre(), 'price_postfix' => $this->currency->Post(), 'onhand' => $this->track_onhand ? $this->onhand : '', 'qty_disc' => $qty_disc_txt));
     // Retrieve the photos and put into the template
     $sql = "SELECT img_id, filename\n                FROM {$_TABLES['paypal.images']} \n                WHERE product_id='{$prod_id}'";
     //echo $sql;die;
     $img_res = DB_query($sql);
     $photo_detail = '';
     $T->set_var('have_photo', '');
     // assume no photo available
     if ($img_res && DB_numRows($img_res) > 0) {
         for ($i = 0; $prow = DB_fetchArray($img_res, false); $i++) {
             if ($prow['filename'] != '' && file_exists("{$_PP_CONF['image_dir']}/{$prow['filename']}")) {
                 if ($i == 0) {
                     $T->set_var('main_img', PAYPAL_ImageUrl($prow['filename'], $tpl_config['lg_img_width'] - 20, $tpl_config['lg_img_height'] - 20));
                 }
                 $T->set_block('product', 'Thumbnail', 'PBlock');
                 $T->set_var(array('img_file' => $prow['filename'], 'disp_img' => PAYPAL_ImageUrl($prow['filename'], $tpl_config['lg_img_width'] - 20, $tpl_config['lg_img_height'] - 20), 'lg_img' => PAYPAL_URL . '/images/products/' . $prow['filename'], 'img_url' => PAYPAL_URL . '/images/products', 'thumb_url' => PAYPAL_ImageUrl($prow['filename']), 'tn_width' => $_PP_CONF['max_thumb_size'], 'tn_height' => $_PP_CONF['max_thumb_size']));
                 $T->parse('PBlock', 'Thumbnail', true);
             }
         }
     }
     // Get the product options, if any, and set them into the form
     $cbrk = '';
     $T->set_block('product', 'AttrSelect', 'attrSel');
     foreach ($this->options as $id => $Attr) {
         /*if ($Attr['attr_value'] === '') {
               $type = 'text';
           } else {
               $type = 'select';
           }*/
         $type = 'select';
         if ($Attr['attr_name'] != $cbrk) {
             if ($cbrk != '') {
                 // end block if not the first element
                 $T->set_var(array('attr_name' => $cbrk, 'attr_options' => $attributes, 'opt_id' => $id));
                 $T->parse('attrSel', 'AttrSelect', true);
             }
             $cbrk = $Attr['attr_name'];
             $attributes = '';
         }
         if ($type == 'select') {
             if ($Attr['attr_price'] != 0) {
                 $attr_str = sprintf(" ( %+.2f )", $Attr['attr_price']);
             } else {
                 $attr_str = '';
             }
             $attributes .= '<option value="' . $id . '|' . $Attr['attr_value'] . '|' . $Attr['attr_price'] . '">' . $Attr['attr_value'] . $attr_str . '</option>' . LB;
             /*} else {
                   $attributes .= "<input type=\"hidden\" name=\"on{$i}\" 
                           value=\"{$Attr['attr_name']}\">\n";
                   $attributes .= $Attr['attr_name'] . ':</td>
                       <td><input class="uk-contrast uk-form" type"text" name="os' . $i. '" value="" size="32" /></td></tr>';
               */
         }
     }
     if ($cbrk != '') {
         // finish off the last selection
         $T->set_var(array('attr_name' => $cbrk, 'attr_options' => $attributes, 'opt_id' => $id));
         $T->parse('attrSel', 'AttrSelect', true);
     }
     $buttons = $this->PurchaseLinks();
     $T->set_block('product', 'BtnBlock', 'Btn');
     foreach ($buttons as $name => $html) {
         if ($name == 'add_cart') {
             // Set the add to cart button in the main form
             $T->set_var('add_cart_button', $html);
         } else {
             $T->set_var('buy_now_button', $html);
             $T->parse('Btn', 'BtnBlock', true);
         }
     }
     // Show the user comments if enabled globally and for this product
     if (plugin_commentsupport_paypal() && $this->comments_enabled != PP_COMMENTS_DISABLED) {
         // if enabled or closed
         if ($_CONF['commentsloginrequired'] == 1 && COM_isAnonUser()) {
             // Set mode to "disabled"
             $mode = -1;
         } else {
             $mode = $this->comments_enabled;
         }
         $T->set_var('usercomments', CMT_userComments($prod_id, $this->short_description, 'paypal', '', '', 0, 1, false, false, $mode));
     }
     if ($this->rating_enabled == 1) {
         $PP_ratedIds = RATING_getRatedIds('paypal');
         if (in_array($prod_id, $PP_ratedIds)) {
             $static = true;
             $voted = 1;
         } elseif (plugin_canuserrate_paypal($A['id'], $_USER['uid'])) {
             $static = 0;
             $voted = 0;
         } else {
             $static = 1;
             $voted = 0;
         }
         $rating_box = RATING_ratingBar('paypal', $prod_id, $this->votes, $this->rating, $voted, 5, $static, 'sm');
         $T->set_var('rating_bar', $rating_box);
     } else {
         $T->set_var('ratign_bar', '');
     }
     if ($this->isAdmin) {
         // Add the quick-edit link for administrators
         $T->set_var(array('pi_admin_url' => PAYPAL_ADMIN_URL, 'can_edit' => 'true'));
     }
     $retval .= $T->parse('output', 'product');
     // Update the hit counter
     DB_query("UPDATE {$_TABLES['paypal.products']}\n                SET views = views + 1\n                WHERE id = '{$prod_id}'");
     $retval .= COM_endBlock();
     return $retval;
 }
Example #4
0
$p->set_var('LANG_REPORTBROKEN', _MD_REPORTBROKEN);
if ($FilemgmtAdmin) {
    $p->set_var('LANG_EDIT', _MD_EDIT);
    $p->set_var('show_editlink', '');
} else {
    $p->set_var('LANG_EDIT', '');
    $p->set_var('show_editlink', 'none');
}
$static = false;
$voted = 0;
if (COM_isAnonUser()) {
    $static = true;
    $voted = 1;
} else {
    if (isset($_USER['uid']) && $_USER['uid'] == $submitter) {
        $static = true;
        $voted = 0;
    } else {
        if (@in_array($lid, $FM_ratedIds)) {
            $static = true;
            $voted = 1;
        } else {
            $static = 0;
            $voted = 0;
        }
    }
}
if ($_FM_CONF['enable_rating']) {
    $rating_box = RATING_ratingBar('filemgmt', $lid, $votes, $rating, $voted, 5, $static, 'sm');
    $p->set_var('rating_bar', $rating_box);
}
Example #5
0
 /**
  *   Display the detail page for the product.
  *
  *   @return string      HTML for the product page.
  */
 public function Detail()
 {
     global $_CONF, $_PP_CONF, $_TABLES, $LANG_PP, $_USER;
     USES_lib_comments();
     $prod_id = $this->id;
     if ($prod_id < 1 || !$this->enabled) {
         return PAYPAL_errorMessage($LANG_PP['invalid_product_id'], 'info');
     }
     $retval = COM_startBlock();
     // Set the template dir based on the configured template version
     $T = new Template(PAYPAL_PI_PATH . '/templates/detail' . $_PP_CONF['tpl_ver_detail']);
     if ($this->hasAttributes()) {
         $detail_template = 'product_detail_attrib.thtml';
     } else {
         $detail_template = 'product_detail.thtml';
     }
     $T->set_file('product', $detail_template);
     $name = $this->name;
     $l_desc = PLG_replaceTags($this->description);
     $s_desc = PLG_replaceTags($this->short_description);
     // Highlight the query terms if coming from a search
     if (isset($_REQUEST['query']) && !empty($_REQUEST['query'])) {
         $name = COM_highlightQuery($name, $_REQUEST['query']);
         $l_desc = COM_highlightQuery($l_desc, $_REQUEST['query']);
         $s_desc = COM_highlightQuery($s_desc, $_REQUEST['query']);
     }
     $act_price = $this->sale_price == $this->price ? $this->price : $this->sale_price;
     $T->set_var(array('id' => $prod_id, 'name' => $name, 'short_description' => $s_desc, 'description' => $l_desc, 'cur_decimals' => $this->currency->Decimals(), 'price' => $this->currency->FormatValue($act_price), 'orig_price' => $this->currency->Format($this->price), 'on_sale' => $act_price == $this->price ? '' : 'true', 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'price_prefix' => $this->currency->Pre(), 'price_postfix' => $this->currency->Post(), 'onhand' => $this->track_onhand ? $this->onhand : ''));
     // Retrieve the photos and put into the template
     $sql = "SELECT img_id, filename\n                FROM {$_TABLES['paypal.images']} \n                WHERE product_id='{$prod_id}'";
     //echo $sql;die;
     $img_res = DB_query($sql);
     $photo_detail = '';
     $T->set_var('have_photo', '');
     // assume no photo available
     if ($img_res && DB_numRows($img_res) > 0) {
         for ($i = 0; $prow = DB_fetchArray($img_res, false); $i++) {
             if ($prow['filename'] != '' && file_exists("{$_PP_CONF['image_dir']}/{$prow['filename']}")) {
                 if ($i == 0) {
                     $T->set_var('main_img', $prow['filename']);
                 }
                 $T->set_block('product', 'Thumbnail', 'PBlock');
                 $T->set_var('img_file', $prow['filename']);
                 $T->set_var('img_url', PAYPAL_URL . '/images/products');
                 $T->set_var('thumb_url', PAYPAL_ImageUrl($prow['filename']));
                 $T->parse('PBlock', 'Thumbnail', true);
                 $T->set_var('have_photo', 'true');
             }
         }
     }
     // Get the product options, if any, and set them into the form
     $i = 0;
     $cbrk = '';
     $attributes = '';
     foreach ($this->options as $id => $Attr) {
         if ($Attr['attr_name'] != $cbrk) {
             if ($i > 0) {
                 $attributes .= "</select></td></tr>\n";
             } else {
                 $attributes = '<table border="0">' . "\n";
             }
             $cbrk = $Attr['attr_name'];
             $attributes .= "<tr><td>\n                    <input type=\"hidden\" name=\"on{$i}\" \n                    value=\"{$Attr['attr_name']}\">\n\n                    <input type=\"hidden\" name=\"os{$i}\" \n                    value=\"\">\n\n                    {$Attr['attr_name']}:</td>\n                    <td align=\"left\">\n                    <select name=\"options[]\"\n                    onchange=\"ProcessForm(this.form);\">\n";
             /*<td align=\"left\"><select name=\"pp_os{$i}\"*/
             $i++;
         }
         if ($Attr['attr_price'] != 0) {
             $attr_str = sprintf(" ( %+.2f )", $Attr['attr_price']);
         } else {
             $attr_str = '';
         }
         $attributes .= '<option value="' . $id . '|' . $Attr['attr_value'] . '|' . $Attr['attr_price'] . '">' . $Attr['attr_value'] . $attr_str . '</option>' . LB;
     }
     if ($attributes != '') {
         $attributes .= "</select></td></tr></table>\n";
         $T->set_var('attributes', $attributes);
     }
     $buttons = $this->PurchaseLinks();
     $T->set_block('product', 'BtnBlock', 'Btn');
     foreach ($buttons as $name => $html) {
         $T->set_var('button', $html);
         $T->parse('Btn', 'BtnBlock', true);
     }
     // Show the user comments if enabled globally and for this product
     if (plugin_commentsupport_paypal() && $this->comments_enabled != PP_COMMENTS_DISABLED) {
         // if enabled or closed
         if ($_CONF['commentsloginrequired'] == 1 && COM_isAnonUser()) {
             // Set mode to "disabled"
             $mode = -1;
         } else {
             $mode = $this->comments_enabled;
         }
         $T->set_var('usercomments', CMT_userComments($prod_id, $this->short_description, 'paypal', '', '', 0, 1, false, false, $mode));
     }
     if ($this->rating_enabled == 1) {
         $PP_ratedIds = RATING_getRatedIds('paypal');
         if (in_array($prod_id, $PP_ratedIds)) {
             $static = true;
             $voted = 1;
         } elseif (plugin_canuserrate_paypal($A['id'], $_USER['uid'])) {
             $static = 0;
             $voted = 0;
         } else {
             $static = 1;
             $voted = 0;
         }
         $rating_box = RATING_ratingBar('paypal', $prod_id, $this->votes, $this->rating, $voted, 5, $static, 'sm');
         $T->set_var('rating_bar', $rating_box);
     } else {
         $T->set_var('ratign_bar', '');
     }
     if ($this->isAdmin) {
         // Add the quick-edit link for administrators
         $T->set_var(array('pi_admin_url' => PAYPAL_ADMIN_URL, 'can_edit' => 'true'));
     }
     $retval .= $T->parse('output', 'product');
     // Update the hit counter
     DB_query("UPDATE {$_TABLES['paypal.products']}\n                SET views = views + 1\n                WHERE id = '{$prod_id}'");
     $retval .= COM_endBlock();
     return $retval;
 }
Example #6
0
/**
*   Diaplay the product catalog items.
*
*   @return string      HTML for product catalog.
*/
function PAYPAL_ProductList($cat = 0, $search = '')
{
    global $_TABLES, $_CONF, $_PP_CONF, $LANG_PP, $_USER, $_PLUGINS, $_IMAGE_TYPE, $_GROUPS;
    USES_paypal_class_product();
    if (SEC_hasRights('paypal.admin')) {
        $isAdmin = true;
    } else {
        $isAdmin = false;
    }
    $my_groups = implode(',', $_GROUPS);
    $cat_name = '';
    $breadcrumbs = '';
    $img_url = '';
    $display = '';
    if ($cat != 0) {
        $breadcrumbs = PAYPAL_Breadcrumbs($cat);
        $cat = (int) $cat;
        $A = DB_fetchArray(DB_query("SELECT cat_name, image\n                FROM {$_TABLES['paypal.categories']}\n                WHERE cat_id='{$cat}' " . COM_getPermSQL('AND')), false);
        if (!empty($A)) {
            $cat_name = $A['cat_name'];
            if (!empty($A['image']) && is_file($_CONF['path_html'] . $_PP_CONF['pi_name'] . '/images/categories/' . $A['image'])) {
                $img_url = PAYPAL_URL . '/images/categories/' . $A['image'];
            }
        }
    }
    // Display categories
    if (isset($_PP_CONF['cat_columns']) && $_PP_CONF['cat_columns'] > 0) {
        $sql = "SELECT cat.cat_id, cat.cat_name, count(prod.id) AS cnt \n            FROM {$_TABLES['paypal.categories']} cat\n            LEFT JOIN {$_TABLES['paypal.products']} prod\n                ON prod.cat_id = cat.cat_id\n            WHERE cat.enabled = '1' AND cat.parent_id = '{$cat}' \n                AND prod.enabled = '1' " . COM_getPermSQL('AND', 0, 2, 'cat') . " GROUP BY cat.cat_id\n            ORDER BY cat.cat_name";
        //HAVING cnt > 0
        //echo $sql;die;
        $CT = new Template(PAYPAL_PI_PATH . '/templates');
        $CT->set_file(array('table' => 'category_table.thtml', 'row' => 'category_row.thtml', 'category' => 'category.thtml'));
        $CT->set_var('width', floor(100 / $_PP_CONF['cat_columns']));
        if ($breadcrumbs != '') {
            $CT->set_var('breadcrumbs', $breadcrumbs);
        }
        if ($img_url != '') {
            $CT->set_var('catimg_url', $img_url);
        }
        $res = DB_query($sql);
        $A = array();
        while ($C = DB_fetchArray($res, false)) {
            $A[$C['cat_id']] = array($C['cat_name'], $C['cnt']);
        }
        // Now get categories from plugins
        foreach ($_PLUGINS as $pi_name) {
            $function = 'USES_' . $pi_name . '_paypal';
            if (function_exists($function)) {
                $function();
                $function = 'plugin_paypal_getcategories_' . $pi_name;
                if (function_exists($function)) {
                    $pi_cats = $function();
                    foreach ($pi_cats as $catid => $data) {
                        $A[$catid] = $data;
                    }
                }
            }
        }
        $i = 1;
        $nrows = count($A);
        foreach ($A as $category => $info) {
            $CT->set_var(array('category_name' => $info[0], 'category_link' => PAYPAL_URL . '/index.php?category=' . urlencode($category)));
            /*if ($category == $cat) {
                  $CT->set_var('curr', 'current');
                  $cat_name = $info[0];
              } else {
                  $CT->set_var('curr', 'other');
              }*/
            $CT->parse('catrow', 'category', true);
            if ($i % $_PP_CONF['cat_columns'] == 0) {
                $CT->parse('categories', 'row', true);
                $CT->set_var('catrow', '');
            }
            $i++;
        }
        if ($nrows % $_PP_CONF['cat_columns'] != 0) {
            $CT->parse('categories', 'row', true);
        }
        $display .= $CT->parse('', 'table');
    }
    /*$sortby_opts = array(
            'name' => $LANG_PP['name'],
            'price' => $LANG_PP['price'],
            'dt_add' => $LANG_PP['dt_add'],
        );
        switch ($_REQUEST['sortby']){
        case 'name':
        case 'price':
        case 'dt_add':
            $sortby = $_REQUEST['sortby'];
            break;
        default:
            $sortby = $_PP_CONF['order'];
            break;
        }
        $sortby_options = '';
        foreach ($sortby_opts as $value=>$text) {
            $sel = $value == $sortby ? ' selected="selected"' : '';
            $sortby_options .= "<option value=\"$value\" $sel>$text</option>\n";
        }
    
        $sortdir = $_REQUEST['sortdir'] == 'DESC' ? 'DESC' : 'ASC';*/
    $sortby = $_PP_CONF['order'];
    $sortdir = 'ASC';
    // Get products from database. "c.enabled is null" is to allow products
    // with no category defined
    $sql = " FROM {$_TABLES['paypal.products']} p\n            LEFT JOIN {$_TABLES['paypal.categories']} c\n                ON p.cat_id = c.cat_id\n            WHERE p.enabled=1 \n            AND (\n                (c.enabled=1 " . COM_getPermSQL('AND', 0, 2, 'c') . ")\n                OR c.enabled IS NULL\n                )\n            AND (\n                p.track_onhand = 0 OR p.onhand > 0 OR p.oversell < 2\n                )";
    $pagenav_args = array();
    // If applicable, limit by category
    if (!empty($_REQUEST['category'])) {
        $cat_list = $_REQUEST['category'];
        $cat_list .= PAYPAL_recurseCats('PAYPAL_callbackCatCommaList', 0, $_REQUEST['category']);
        if (!empty($cat_list)) {
            $sql .= " AND c.cat_id IN ({$cat_list})";
        }
        $pagenav_args[] = 'category=' . urlencode($_REQUEST['category']);
    } else {
        $cat_list = '';
    }
    // If applicable, limit by search string
    if (!empty($_REQUEST['search_name'])) {
        $srch = DB_escapeString($_REQUEST['search_name']);
        $sql .= " AND (p.name like '%{$srch}%' OR \n                p.short_description like '%{$srch}%' OR\n                p.description like '%{$srch}%' OR\n                p.keywords like '%{$srch}%')";
        //if (!$isAdmin) $sql .= " AND p.grp_access IN ($my_groups) ";
        $pagenav_args[] = 'search_name=' . urlencode($_REQUEST['search_name']);
    }
    // If applicable, order by
    $sql .= " ORDER BY {$sortby} {$sortdir}";
    // If applicable, handle pagination of query
    if (isset($_PP_CONF['prod_per_page']) && $_PP_CONF['prod_per_page'] > 0) {
        // Count products from database
        $res = DB_query('SELECT COUNT(*) as cnt ' . $sql);
        $x = DB_fetchArray($res, false);
        if (isset($x['cnt'])) {
            $count = (int) $x['cnt'];
        } else {
            $count = 0;
        }
        // Make sure page requested is reasonable, if not, fix it
        if (!isset($_REQUEST['page']) || $_REQUEST['page'] <= 0) {
            $_REQUEST['page'] = 1;
        }
        $page = (int) $_REQUEST['page'];
        $start_limit = ($page - 1) * $_PP_CONF['prod_per_page'];
        if ($start_limit > $count) {
            $page = ceil($count / $_PP_CONF['prod_per_page']);
        }
        // Add limit for pagination (if applicable)
        if ($count > $_PP_CONF['prod_per_page']) {
            $sql .= " LIMIT {$start_limit}, {$_PP_CONF['prod_per_page']}";
        }
    }
    // Re-execute query with the limit clause in place
    $res = DB_query('SELECT DISTINCT p.id ' . $sql);
    // Create product template
    $product = new Template(PAYPAL_PI_PATH . '/templates');
    $product->set_file(array('start' => 'product_list_start.thtml', 'end' => 'product_list_end.thtml', 'product' => 'product_list_item.thtml', 'download' => 'buttons/btn_download.thtml', 'login_req' => 'buttons/btn_login_req.thtml', 'btn_details' => 'buttons/btn_details.thtml'));
    if ($nrows == 0 && COM_isAnonUser()) {
        $product->set_var('anon_and_empty', 'true');
    }
    $product->set_var(array('pi_url' => PAYPAL_URL, 'user_id' => $_USER['uid'], 'currency' => $_PP_CONF['currency']));
    if (!empty($cat_name)) {
        $product->set_var('title', $cat_name);
    } else {
        $product->set_var('title', $LANG_PP['blocktitle']);
    }
    /*$product->set_var('sortby_options', $sortby_options);
      if ($sortdir == 'DESC') {
          $product->set_var('sortdir_desc_sel', ' selected="selected"');
      } else {
          $product->set_var('sortdir_asc_sel', ' selected="selected"');
      }
      $product->set_var('sortby', $sortby);
      $product->set_var('sortdir', $sortdir);*/
    $display .= $product->parse('', 'start');
    // Create an empty product object
    $P = new Product();
    if ($_PP_CONF['ena_ratings'] == 1) {
        $PP_ratedIds = RATING_getRatedIds('paypal');
    }
    // Display each product
    while ($A = DB_fetchArray($res, false)) {
        $P->Read($A['id']);
        if ($_PP_CONF['ena_ratings'] == 1 && $P->rating_enabled == 1) {
            if (in_array($A['id'], $PP_ratedIds)) {
                $static = true;
                $voted = 1;
            } elseif (plugin_canuserrate_paypal($A['id'], $_USER['uid'])) {
                $static = false;
                $voted = 0;
            } else {
                $static = true;
                $voted = 0;
            }
            $rating_box = RATING_ratingBar('paypal', $A['id'], $P->votes, $P->rating, $voted, 5, $static, 'sm');
            $product->set_var('rating_bar', $rating_box);
        } else {
            $product->set_var('rating_bar', '');
        }
        $product->set_var(array('id' => $A['id'], 'name' => $P->name, 'short_description' => PLG_replacetags($P->short_description), 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'encrypted' => '', 'item_url' => COM_buildURL(PAYPAL_URL . '/detail.php?id=' . $A['id']), 'img_cell_width' => $_PP_CONF['max_thumb_size'] + 20, 'track_onhand' => $P->track_onhand ? 'true' : '', 'qty_onhand' => $P->onhand));
        if ($P->price > 0) {
            //$product->set_var('price', COM_numberFormat($P->price, 2));
            $product->set_var('price', $P->currency->Format($P->price));
        } else {
            $product->clear_var('price');
        }
        if ($isAdmin) {
            $product->set_var('is_admin', 'true');
            $product->set_var('pi_admin_url', PAYPAL_ADMIN_URL);
            $product->set_var('edit_icon', "{$_CONF['layout_url']}/images/edit.{$_IMAGE_TYPE}");
        }
        $pic_filename = DB_getItem($_TABLES['paypal.images'], 'filename', "product_id = '{$A['id']}'");
        if ($pic_filename) {
            $product->set_var('small_pic', PAYPAL_ImageUrl($pic_filename));
        } else {
            $product->set_var('small_pic', '');
        }
        // FIXME: If a user purchased once with no expiration, this query
        // will not operate correctly
        /*$time = DB_getItem($_TABLES['paypal.purchases'], 
                      'MAX(UNIX_TIMESTAMP(expiration))',
                      "user_id = {$_USER['uid']} AND product_id ='{$A['id']}'");
          */
        $product->set_block('product', 'BtnBlock', 'Btn');
        if (!$P->hasAttributes()) {
            // Buttons only show in the list if there are no options to select
            $buttons = $P->PurchaseLinks();
            foreach ($buttons as $name => $html) {
                $product->set_var('button', $html);
                $product->parse('Btn', 'BtnBlock', true);
            }
        } else {
            if ($_PP_CONF['ena_cart']) {
                // If the product has attributes, then the cart must be
                // enabled to allow purchasing
                $button = $product->parse('', 'btn_details') . '&nbsp;';
                $product->set_var('button', $button);
                $product->parse('Btn', 'BtnBlock', true);
            }
        }
        $display .= $product->parse('', 'product');
        $product->clear_var('Btn');
    }
    // Get products from plugins.
    // For now, this hack shows plugins only on the first page, since
    // they're not included in the page calculation.
    if ($page == 1 && empty($cat_list)) {
        // Get the currency class for formatting prices
        USES_paypal_class_currency();
        $Cur = new ppCurrency($_PP_CONF['currency']);
        $product->clear_var('rating_bar');
        // no ratings for plugins (yet)
        foreach ($_PLUGINS as $pi_name) {
            $status = LGLIB_invokeService($pi_name, 'getproducts', array(), $plugin_data, $svc_msg);
            if ($status != PLG_RET_OK || empty($plugin_data)) {
                continue;
            }
            foreach ($plugin_data as $A) {
                // Reset button values
                $buttons = '';
                $product->set_var(array('id' => $A['id'], 'name' => $A['name'], 'short_description' => $A['short_description'], 'display' => '; display: none', 'small_pic' => '', 'encrypted' => '', 'item_url' => $A['url'], 'track_onhand' => ''));
                if ($A['price'] > 0) {
                    $product->set_var('price', $Cur->Format($A['price']));
                } else {
                    $product->clear_var('price');
                }
                if ($A['price'] > 0 && $_USER['uid'] == 1 && !$_PP_CONF['anon_buy']) {
                    $buttons .= $product->set_var('', 'login_req') . '&nbsp;';
                } elseif ($A['prod_type'] > PP_PROD_PHYSICAL && $A['price'] == 0) {
                    // Free items or items purchases and not expired, download.
                    $buttons .= $product->set_var('', 'download') . '&nbsp;';
                } elseif (is_array($A['buttons'])) {
                    // Buttons for everyone else
                    $product->set_block('product', 'BtnBlock', 'Btn');
                    foreach ($A['buttons'] as $type => $html) {
                        $product->set_var('button', $html);
                        $product->parse('Btn', 'BtnBlock', true);
                    }
                }
                //$product->set_var('buttons', $buttons);
                $display .= $product->parse('', 'product');
                $product->clear_var('Btn');
            }
            // foreach plugin_data
        }
        // foreach $_PLUGINS
    }
    // if page == 1
    $pagenav_args = empty($pagenav_args) ? '' : '?' . implode('&', $pagenav_args);
    // Display pagination
    if (isset($_PP_CONF['prod_per_page']) && $_PP_CONF['prod_per_page'] > 0 && $count > $_PP_CONF['prod_per_page']) {
        $product->set_var('pagination', COM_printPageNavigation(PAYPAL_URL . '/index.php' . $pagenav_args, $page, ceil($count / $_PP_CONF['prod_per_page'])));
    } else {
        $product->set_var('pagination', '');
    }
    $display .= $product->parse('', 'end');
    return $display;
}
Example #7
0
        }
    } else {
        $added = $current_votes;
        $new_rating = $current_rating;
    }
} else {
    list($rating_id, $current_rating, $cout) = RATING_getRating($plugin, $id_sent);
    $added = $count;
    $new_rating = $current_rating;
    $status = 3;
    $voted = 1;
}
$count = $added;
$current_rating = $new_rating;
$tense = $count == 1 ? $LANG13['vote'] : $LANG13['votes'];
// set message
if ($status == 1) {
    // either IP or UID has already voted
    $message = "<script>alert('" . $LANG13['ip_rated'] . "');</script>";
} elseif ($status == 2) {
    $message = "<script>alert('" . sprintf($LANG13['rate_speedlimit'], $last, $_CONF['rating_speedlimit']) . "');</script>";
} elseif ($status == 3) {
    // no permission to vote or your already own the item
    $message = "<script>alert('" . $LANG13['own_rated'] . "');</script>";
} else {
    $message = '<br><span class="thanks">&nbsp;' . $LANG13['thanks_for_vote'] . '</span>';
}
// $new_back is what gets 'drawn' on your page after a successful 'AJAX/Javascript' vote
$new_back = array();
$newBar = RATING_ratingBar($plugin, $id_sent, $count, $current_rating, $voted, 5, $voted, $size, 0);
echo join("\n", array($newBar, $message));
Example #8
0
/**
 * Takes an article class and renders HTML in the specified template and style.
 *
 * Formats the given article into HTML. Called by index.php, article.php,
 * submit.php and admin/story.php (Preview mode for the last two).
 *
 * @param   object  $story      The story to display, an instance of the Story class.
 * @param   string  $index      n = 'Compact display' for list of stories. p = 'Preview' mode. Else full display of article.
 * @param   string  $storytpl   The template to use to render the story.
 * @param   string  $query      A search query, if one was specified.
 *
 * @return  string  Article as formated HTML.
 *
 * Note: Formerly named COM_Article, and re-written totally since then.
 */
function STORY_renderArticle(&$story, $index = '', $storytpl = 'storytext.thtml', $query = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG05, $LANG11, $LANG_TRB, $_IMAGE_TYPE, $mode, $_GROUPS, $ratedIds;
    static $storycounter = 0;
    if (empty($storytpl)) {
        $storytpl = 'storytext.thtml';
    }
    $introtext = $story->displayElements('introtext');
    $bodytext = $story->displayElements('bodytext');
    if (!empty($query)) {
        $introtext = COM_highlightQuery($introtext, $query);
        $bodytext = COM_highlightQuery($bodytext, $query);
    }
    $article = new Template($_CONF['path_layout']);
    $article->set_file(array('article' => $storytpl, 'featuredarticle' => 'featuredstorytext.thtml', 'archivearticle' => 'archivestorytext.thtml'));
    if ($_CONF['hideviewscount'] != 1) {
        $article->set_var('lang_views', $LANG01[106]);
        $article->set_var('story_hits', $story->DisplayElements('hits'), false, true);
    }
    if ($_CONF['hidestorydate'] != 1) {
        $article->set_var('story_date', $story->DisplayElements('date'), false, true);
        // make sure date format is in user's preferred format
    }
    $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
    $article->set_var('article_url', $articleUrl);
    $article->set_var('story_title', $story->DisplayElements('title'));
    // begin instance caching...
    if ($story->DisplayElements('featured') == 1) {
        $article_filevar = 'featuredarticle';
    } elseif ($story->DisplayElements('statuscode') == STORY_ARCHIVE_ON_EXPIRE and $story->DisplayElements('expire') <= time()) {
        $article_filevar = 'archivearticle';
    } else {
        $article_filevar = 'article';
    }
    $hash = CACHE_security_hash();
    $instance_id = 'story_' . $story->getSid() . '_' . $index . '_' . $article_filevar . '_' . $hash . '_' . $_USER['theme'];
    if ($index == 'p' || !empty($query) || !$article->check_instance($instance_id, $article_filevar)) {
        // end of instance cache
        $article->set_var('article_filevar', '');
        $article->set_var('site_name', $_CONF['site_name']);
        if ($_CONF['hidestorydate'] != 1) {
            $article->set_var('story_date_short', $story->DisplayElements('shortdate'));
            $article->set_var('story_date_only', $story->DisplayElements('dateonly'));
        }
        $article->set_var('story_id', $story->getSid());
        $article->set_var('lang_posted_in', $LANG01['posted_in']);
        if ($_CONF['contributedbyline'] == 1) {
            $article->set_var('lang_contributed_by', $LANG01[1]);
            $article->set_var('lang_by', $LANG01[95]);
            $article->set_var('contributedby_uid', $story->DisplayElements('uid'));
            $fullname = $story->DisplayElements('fullname');
            $username = $story->DisplayElements('username');
            $article->set_var('contributedby_user', $username);
            if (empty($fullname)) {
                $article->set_var('contributedby_fullname', $username);
            } else {
                $article->set_var('contributedby_fullname', $fullname);
            }
            $authorname = COM_getDisplayName($story->DisplayElements('uid'), $username, $fullname);
            $article->set_var('author', $authorname);
            $profileUrl = $_CONF['site_url'] . '/users.php?mode=profile&amp;uid=' . $story->DisplayElements('uid');
            if ($story->DisplayElements('uid') > 1) {
                $article->set_var('contributedby_url', $profileUrl);
                $authorname = COM_createLink($authorname, $profileUrl, array('class' => 'storybyline'));
            }
            $article->set_var('contributedby_author', $authorname);
            $photo = '';
            if ($_CONF['allow_user_photo'] == 1) {
                $authphoto = $story->DisplayElements('photo');
                if (empty($authphoto)) {
                    $authphoto = '(none)';
                    // user does not have a photo
                }
                $photo = USER_getPhoto($story->DisplayElements('uid'), $authphoto, $story->DisplayElements('email'));
            }
            if (!empty($photo)) {
                $article->set_var('contributedby_photo', $photo);
                $article->set_var('author_photo', $photo);
                $camera_icon = '<img src="' . $_CONF['layout_url'] . '/images/smallcamera.' . $_IMAGE_TYPE . '" alt=""' . '/>';
                $article->set_var('camera_icon', COM_createLink($camera_icon, $profileUrl));
            } else {
                $article->set_var('contributedby_photo', '');
                $article->set_var('author_photo', '');
                $article->set_var('camera_icon', '');
            }
        }
        $topicname = $story->DisplayElements('topic');
        if ($story->DisplayElements('alternate_tid') != NULL) {
            $alttopic = DB_getItem($_TABLES['topics'], 'topic', "tid = '" . DB_escapeString($story->DisplayElements('alternate_tid')) . "'");
        } else {
            $alttopic = '';
        }
        $article->set_var('story_topic_id', $story->DisplayElements('tid'));
        $article->set_var('alt_story_topic_id', $story->DisplayElements('alternate_tid'));
        $article->set_var('story_topic_name', $topicname);
        $article->set_var('story_alternate_topic_name', $alttopic);
        $topicurl = $_CONF['site_url'] . '/index.php?topic=' . $story->DisplayElements('tid');
        $alttopicurl = $_CONF['site_url'] . '/index.php?topic=' . $story->DisplayElements('alternate_tid');
        if ((!isset($_USER['noicons']) or $_USER['noicons'] != 1) and $story->DisplayElements('show_topic_icon') == 1) {
            $imageurl = $story->DisplayElements('imageurl');
            if (!empty($imageurl)) {
                $imageurl = COM_getTopicImageUrl($imageurl);
                $article->set_var('story_topic_image_url', $imageurl);
                $topicimage = '<img src="' . $imageurl . '" class="float' . $_CONF['article_image_align'] . '" alt="' . $topicname . '" title="' . $topicname . '" />';
                $article->set_var('story_anchortag_and_image', COM_createLink($topicimage, $topicurl, array('rel' => "category tag")));
                $article->set_var('story_topic_image', $topicimage);
                $topicimage_noalign = '<img src="' . $imageurl . '" alt="' . $topicname . '" title="' . $topicname . '" />';
                $article->set_var('story_anchortag_and_image_no_align', COM_createLink($topicimage_noalign, $topicurl, array('rel' => "category tag")));
                $article->set_var('story_topic_image_no_align', $topicimage_noalign);
            }
        }
        $article->set_var('story_topic_url', $topicurl);
        $article->set_var('alt_story_topic_url', $alttopicurl);
        $recent_post_anchortag = '';
        $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
        $article->set_var('story_title', $story->DisplayElements('title'));
        $article->set_var('lang_permalink', $LANG01[127]);
        $show_comments = true;
        // n = 'Compact display' for list of stories. p = 'Preview' mode.
        if ($index != 'n' && $index != 'p' || !empty($query)) {
            $attributes = ' class="non-ul"';
            $attr_array = array('class' => 'non-ul');
            if (!empty($query)) {
                $attributes .= ' rel="bookmark"';
                $attr_array['rel'] = 'bookmark';
            }
            $article->set_var('start_storylink_anchortag', '<a href="' . $articleUrl . '"' . $attributes . '>');
            $article->set_var('end_storylink_anchortag', '</a>');
            $article->set_var('story_title_link', COM_createLink($story->DisplayElements('title'), $articleUrl, $attr_array));
        } else {
            $article->set_var('story_title_link', $story->DisplayElements('title'));
        }
        if ($index == 'n' || $index == 'p') {
            if (empty($bodytext)) {
                $article->set_var('story_introtext', $introtext);
                $article->set_var('story_text_no_br', $introtext);
            } else {
                if ($_CONF['allow_page_breaks'] == 1 and $index == 'n') {
                    $story_page = 1;
                    // page selector
                    if (is_numeric($mode)) {
                        $story_page = $mode;
                        if ($story_page <= 0) {
                            $story_page = 1;
                            $mode = 0;
                        } elseif ($story_page > 1) {
                            $introtext = '';
                        }
                    }
                    $article_array = explode('[page_break]', $bodytext);
                    $pagelinks = COM_printPageNavigation($articleUrl, $story_page, count($article_array), 'mode=', $_CONF['url_rewrite'], $LANG01[118]);
                    if (count($article_array) > 1) {
                        $bodytext = $article_array[$story_page - 1];
                    }
                    $article->set_var('page_selector', $pagelinks);
                    if ($_CONF['page_break_comments'] == 'last' and $story_page < count($article_array) or $_CONF['page_break_comments'] == 'first' and $story_page != 1) {
                        $show_comments = false;
                    }
                    $article->set_var('story_page', $story_page);
                }
                $article->set_var('story_introtext', $introtext . '<br />' . $bodytext);
                $article->set_var('story_text_no_br', $introtext . $bodytext);
            }
            $article->set_var('story_introtext_only', $introtext);
            $article->set_var('story_bodytext_only', $bodytext);
            if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && SEC_hasRights('story.ping')) {
                $url = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
                $article->set_var('send_trackback_link', COM_createLink($LANG_TRB['send_trackback'], $url));
                $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '" />';
                $article->set_var('send_trackback_icon', COM_createLink($pingico, $url));
                $article->set_var('send_trackback_url', $url);
                $article->set_var('lang_send_trackback_text', $LANG_TRB['send_trackback']);
            }
            $article->set_var('story_display', $index == 'p' ? 'preview' : 'article');
            $article->set_var('story_counter', 0);
        } else {
            $article->set_var('story_introtext', $introtext);
            $article->set_var('story_text_no_br', $introtext);
            $article->set_var('story_introtext_only', $introtext);
            if (!empty($bodytext)) {
                $article->set_var('lang_readmore', $LANG01[2]);
                $article->set_var('lang_readmore_words', $LANG01[62]);
                $numwords = COM_numberFormat(sizeof(explode(' ', strip_tags($bodytext))));
                $article->set_var('readmore_words', $numwords);
                $article->set_var('readmore_link', COM_createLink($LANG01[2], $articleUrl, array('class' => 'story-read-more-link')) . ' (' . $numwords . ' ' . $LANG01[62] . ') ');
                $article->set_var('start_readmore_anchortag', '<a href="' . $articleUrl . '" class="story-read-more-link">');
                $article->set_var('end_readmore_anchortag', '</a>');
                $article->set_var('read_more_class', 'class="story-read-more-link"');
                $article->set_var('readmore_url', $articleUrl);
            }
            if ($story->DisplayElements('commentcode') >= 0 and $show_comments) {
                $commentsUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#comments';
                $article->set_var('comments_url', $commentsUrl);
                $article->set_var('comments_text', COM_numberFormat($story->DisplayElements('comments')) . ' ' . $LANG01[3]);
                $article->set_var('comments_count', COM_numberFormat($story->DisplayElements('comments')));
                $article->set_var('lang_comments', $LANG01[3]);
                $comments_with_count = sprintf($LANG01[121], COM_numberFormat($story->DisplayElements('comments')));
                if ($story->DisplayElements('comments') > 0) {
                    $result = DB_query("SELECT UNIX_TIMESTAMP(date) AS day,username,fullname,{$_TABLES['comments']}.uid as cuid FROM {$_TABLES['comments']},{$_TABLES['users']} WHERE {$_TABLES['users']}.uid = {$_TABLES['comments']}.uid AND sid = '" . DB_escapeString($story->getsid()) . "' ORDER BY date desc LIMIT 1");
                    $C = DB_fetchArray($result);
                    $recent_post_anchortag = '<span class="storybyline">' . $LANG01[27] . ': ' . strftime($_CONF['daytime'], $C['day']) . ' ' . $LANG01[104] . ' ' . COM_getDisplayName($C['cuid'], $C['username'], $C['fullname']) . '</span>';
                    $article->set_var('comments_with_count', COM_createLink($comments_with_count, $commentsUrl));
                    $article->set_var('start_comments_anchortag', '<a href="' . $commentsUrl . '">');
                    $article->set_var('end_comments_anchortag', '</a>');
                } else {
                    $article->set_var('comments_with_count', $comments_with_count);
                    $recent_post_anchortag = COM_createLink($LANG01[60], $_CONF['site_url'] . '/comment.php?sid=' . $story->getsid() . '#comment_entry' . '&amp;pid=0&amp;type=article');
                }
                if ($story->DisplayElements('commentcode') == 0 && ($_CONF['commentsloginrequired'] == 0 || !COM_isAnonUser())) {
                    $postCommentUrl = $_CONF['site_url'] . '/comment.php?sid=' . $story->getSid() . '&amp;pid=0&amp;type=article#comment_entry';
                    $article->set_var('post_comment_link', COM_createLink($LANG01[60], $postCommentUrl, array('rel' => 'nofollow')));
                    $article->set_var('lang_post_comment', $LANG01[60]);
                    $article->set_var('start_post_comment_anchortag', '<a href="' . $postCommentUrl . '" rel="nofollow">');
                    $article->set_var('end_post_comment_anchortag', '</a>');
                    $article->set_var('post_comment_url', $postCommentUrl);
                }
            }
            if (($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) && $story->DisplayElements('trackbackcode') >= 0 && $show_comments) {
                $num_trackbacks = COM_numberFormat($story->DisplayElements('trackbacks'));
                $trackbacksUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid()) . '#trackback';
                $article->set_var('trackbacks_url', $trackbacksUrl);
                $article->set_var('trackbacks_text', $num_trackbacks . ' ' . $LANG_TRB['trackbacks']);
                $article->set_var('trackbacks_count', $num_trackbacks);
                $article->set_var('lang_trackbacks', $LANG_TRB['trackbacks']);
                $article->set_var('trackbacks_with_count', COM_createLink(sprintf($LANG01[122], $num_trackbacks), $trackbacksUrl));
                if (SEC_hasRights('story.ping')) {
                    $pingurl = $_CONF['site_admin_url'] . '/trackback.php?mode=sendall&amp;id=' . $story->getSid();
                    $pingico = '<img src="' . $_CONF['layout_url'] . '/images/sendping.' . $_IMAGE_TYPE . '" alt="' . $LANG_TRB['send_trackback'] . '" title="' . $LANG_TRB['send_trackback'] . '" />';
                    $article->set_var('send_trackback_icon', COM_createLink($pingico, $pingurl));
                }
                if ($story->DisplayElements('trackbacks') > 0) {
                    $article->set_var('trackbacks_with_count', COM_createLink(sprintf($LANG01[122], $num_trackbacks), $trackbacksUrl));
                } else {
                    $article->set_var('trackbacks_with_count', sprintf($LANG01[122], $num_trackbacks));
                }
            }
            if ($_CONF['hideemailicon'] == 1 || COM_isAnonUser() && ($_CONF['loginrequired'] == 1 || $_CONF['emailstoryloginrequired'] == 1)) {
                $article->set_var('email_icon', '');
            } else {
                $emailUrl = $_CONF['site_url'] . '/profiles.php?sid=' . $story->getSid() . '&amp;what=emailstory';
                $emailicon = '<img src="' . $_CONF['layout_url'] . '/images/mail.' . $_IMAGE_TYPE . '" alt="' . $LANG01[64] . '" title="' . $LANG11[2] . '" />';
                $article->set_var('email_icon', COM_createLink($emailicon, $emailUrl));
                $article->set_var('email_story_url', $emailUrl);
                $article->set_var('lang_email_story', $LANG11[2]);
                $article->set_var('lang_email_story_alt', $LANG01[64]);
            }
            $printUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid() . '&amp;mode=print');
            if ($_CONF['hideprintericon'] == 1) {
                $article->set_var('print_icon', '');
            } else {
                $printicon = '<img src="' . $_CONF['layout_url'] . '/images/print.' . $_IMAGE_TYPE . '" alt="' . $LANG01[65] . '" title="' . $LANG11[3] . '" />';
                $article->set_var('print_icon', COM_createLink($printicon, $printUrl, array('rel' => 'nofollow')));
                $article->set_var('print_story_url', $printUrl);
                $article->set_var('lang_print_story', $LANG11[3]);
                $article->set_var('lang_print_story_alt', $LANG01[65]);
            }
            $article->set_var('pdf_icon', '');
            if ($_CONF['backend'] == 1) {
                $tid = $story->displayElements('tid');
                $alt_tid = $story->displayElements('alternate_tid');
                $result = DB_query("SELECT filename, title FROM {$_TABLES['syndication']} WHERE type = 'article' AND topic = '" . DB_escapeString($tid) . "' AND is_enabled = 1");
                $feeds = DB_numRows($result);
                for ($i = 0; $i < $feeds; $i++) {
                    list($filename, $title) = DB_fetchArray($result);
                    $feedUrl = SYND_getFeedUrl($filename);
                    $feedTitle = sprintf($LANG11[6], $title);
                }
                if ($feeds > 0) {
                    $feedicon = '<img src="' . $_CONF['layout_url'] . '/images/rss_small.' . $_IMAGE_TYPE . '" alt="' . $feedTitle . '" title="' . $feedTitle . '" />';
                    $article->set_var('feed_icon', COM_createLink($feedicon, $feedUrl, array("type" => "application/rss+xml")));
                    $article->set_var('feed_url', $feedUrl);
                } else {
                    $article->set_var('feed_icon', '');
                }
            } else {
                $article->set_var('feed_icon', '');
            }
            $article->set_var('story_display', 'index');
            $storycounter++;
            $article->set_var('story_counter', $storycounter);
        }
        $article->set_var('article_url', $articleUrl);
        $article->set_var('recent_post_anchortag', $recent_post_anchortag);
        $access = $story->checkAccess();
        $storyAccess = min($access, SEC_hasTopicAccess($story->DisplayElements('tid')));
        if ($index != 'p' and SEC_hasRights('story.edit') and $story->checkAccess() == 3 and SEC_hasTopicAccess($story->DisplayElements('tid')) == 3) {
            $article->set_var('edit_link', COM_createLink($LANG01[4], $_CONF['site_admin_url'] . '/story.php?edit=x&amp;sid=' . $story->getSid()));
            $article->set_var('edit_url', $_CONF['site_admin_url'] . '/story.php?edit=x&amp;sid=' . $story->getSid());
            $article->set_var('lang_edit_text', $LANG01[4]);
            $editicon = $_CONF['layout_url'] . '/images/edit.' . $_IMAGE_TYPE;
            $editiconhtml = '<img src="' . $editicon . '" alt="' . $LANG01[4] . '" title="' . $LANG01[4] . '" />';
            $article->set_var('edit_icon', COM_createLink($editiconhtml, $_CONF['site_admin_url'] . '/story.php?edit=x&amp;sid=' . $story->getSid()));
            $article->set_var('edit_image', $editiconhtml);
        }
        $article->set_var('lang_continue_reading', $LANG01['continue_reading']);
        PLG_templateSetVars($article_filevar, $article);
        if ($_CONF['rating_enabled'] != 0 && $index != 'p') {
            if (@in_array($story->getSid(), $ratedIds)) {
                $static = true;
                $voted = 1;
            } else {
                $static = 0;
                $voted = 0;
            }
            $uid = isset($_USER['uid']) ? $_USER['uid'] : 1;
            if ($_CONF['rating_enabled'] == 2 && $uid != $story->DisplayElements('owner_id')) {
                $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
            } else {
                if (!COM_isAnonUser() && $uid != $story->DisplayElements('owner_id')) {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
                } else {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), 1, 5, TRUE, 'sm'), false, true);
                }
            }
        } else {
            $article->set_var('rating_bar', '', false, true);
        }
        if ($index != 'p') {
            $article->create_instance($instance_id, $article_filevar);
        }
    } else {
        PLG_templateSetVars($article_filevar, $article);
        if ($_CONF['rating_enabled'] != 0) {
            if (@in_array($story->getSid(), $ratedIds)) {
                $static = true;
                $voted = 1;
            } else {
                $static = 0;
                $voted = 0;
            }
            $uid = isset($_USER['uid']) ? $_USER['uid'] : 1;
            if ($_CONF['rating_enabled'] == 2 && $uid != $story->DisplayElements('owner_id')) {
                $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
            } else {
                if (!COM_isAnonUser() && $uid != $story->DisplayElements('owner_id')) {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, $static, 'sm'), false, true);
                } else {
                    $article->set_var('rating_bar', RATING_ratingBar('article', $story->getSid(), $story->DisplayElements('votes'), $story->DisplayElements('rating'), $voted, 5, TRUE, 'sm'), false, true);
                }
            }
        } else {
            $article->set_var('rating_bar', '', false, true);
        }
    }
    $article->parse('finalstory', $article_filevar);
    return $article->finish($article->get_var('finalstory'));
}
Example #9
0
function MG_displayMediaImage($mediaObject, $full, $sortOrder, $comments, $sortID = 0, $spage = 0)
{
    global $MG_albums, $_TABLES, $_CONF, $_MG_CONF, $LANG_MG00, $LANG_MG01, $LANG_MG03, $LANG_MG04, $LANG_ACCESS, $LANG01, $album_jumpbox, $glversion, $_USER, $_MG_USERPREFS;
    global $_DB_dbms, $LANG04, $ratedIds;
    $retval = '';
    $media_link_start = '';
    $media_link_end = '';
    $srcID = $mediaObject;
    $outputHandle = outputHandler::getInstance();
    $aid = DB_getItem($_TABLES['mg_media_albums'], 'album_id', 'media_id="' . DB_escapeString($mediaObject) . '"');
    if (isset($MG_albums[$aid]->pid)) {
        $pid = $MG_albums[$aid]->pid;
    } else {
        $pid = 0;
    }
    if (@method_exists($MG_albums[$aid], 'getOffset')) {
        $aOffset = $MG_albums[$aid]->getOffset();
    } else {
        $aOffset = -1;
    }
    if ($aOffset == -1 || $MG_albums[$aid]->access == 0) {
        $retval .= COM_showMessageText($LANG_MG00['access_denied_msg'], $LANG_ACCESS['accessdenied'], true);
        return array($LANG_MG00['access_denied_msg'], $retval);
    }
    $mid = $mediaObject;
    $orderBy = MG_getSortOrder($aid, $sortOrder);
    $sql = "SELECT * FROM {$_TABLES['mg_media_albums']} as ma LEFT JOIN " . $_TABLES['mg_media'] . " as m " . " ON ma.media_id=m.media_id WHERE ma.album_id=" . $aid . $orderBy;
    $result = DB_query($sql);
    $nRows = DB_numRows($result);
    $total_media = $nRows;
    $media = array();
    while ($row = DB_fetchArray($result)) {
        $media[] = $row;
        $ids[] = $row['media_id'];
    }
    $key = array_search($mid, $ids);
    if ($key === false) {
        $retval .= COM_showMessageText($LANG_MG00['access_denied_msg'], $LANG_ACCESS['accessdenied'], true);
        return array($LANG_MG00['access_denited_msg'], $retval);
    }
    $mediaObject = $key;
    if ($MG_albums[$aid]->full == 2 || $_MG_CONF['discard_original'] == 1 || $MG_albums[$aid]->full == 1 && COM_isAnonUser()) {
        $full = 0;
    }
    if ($full) {
        $disp = 'orig';
    } else {
        $disp = 'disp';
    }
    if ($MG_albums[$aid]->enable_comments == 0) {
        $comments = 0;
    }
    if ($sortID > 0) {
        $MG_albums[$aid]->enable_slideshow = 0;
    }
    $themeCSS = '';
    $nFrame = new mgFrame();
    $nFrame->constructor($MG_albums[$aid]->display_skin);
    $MG_albums[$aid]->displayFrameTemplate = $nFrame->getTemplate();
    $MG_albums[$aid]->dfrWidth = $nFrame->frame['wHL'] + $nFrame->frame['wHR'];
    $MG_albums[$aid]->dfrHeight = $nFrame->frame['hVT'] + $nFrame->frame['hVB'];
    $themeCSS = $nFrame->getCSS();
    if ($themeCSS != '') {
        $outputHandle->addStyle($themeCSS);
        $themeCSS = '';
    }
    $T = new Template(MG_getTemplatePath($aid));
    switch ($media[$mediaObject]['media_type']) {
        case '0':
            // image
            $T->set_file('page', 'view_image.thtml');
            $ogType = 'article';
            break;
        case '1':
            // video
        // video
        case '5':
            // embedded video
            $meta_file_name = $_MG_CONF['path_mediaobjects'] . 'orig/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . '.' . $media[$mediaObject]['media_mime_ext'];
            COM_errorLog("DEBUG: Video File: " . $meta_file_name);
            $meta = IMG_getMediaMetaData($_MG_CONF['path_mediaobjects'] . 'orig/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . '.' . $media[$mediaObject]['media_mime_ext']);
            COM_errorLog("DEBUG: Video Meta Type: " . $meta['mime_type']);
            if ($meta['mime_type'] == 'video/quicktime') {
                if ($meta['fileformat'] == 'mp4') {
                    $media[$mediaObject]['mime_type'] = 'video/mp4';
                }
            }
            $T->set_file('page', 'view_video.thtml');
            $ogType = 'video.movie';
            break;
        case '2':
            // audio
            $T->set_file('page', 'view_audio.thtml');
            $ogType = 'music.song';
            break;
        default:
            $T->set_file('page', 'view_image.thtml');
            $ogType = 'article';
            break;
    }
    $ptitle = isset($media[$mediaObject]['media_title']) && $media[$mediaObject]['media_title'] != ' ' ? PLG_replaceTags($media[$mediaObject]['media_title'], 'mediagallery', 'media_title') : '';
    $permalink = COM_buildUrl($_MG_CONF['site_url'] . '/media.php?s=' . $srcID);
    $outputHandle->addLink("canonical", $permalink);
    $outputHandle->addMeta('property', 'og:title', $ptitle);
    $outputHandle->addMeta('property', 'og:type', $ogType);
    $outputHandle->addMeta('property', 'og:url', $permalink);
    $T->set_var('permalink', $permalink);
    $T->set_file(array('shutterfly' => 'digibug.thtml'));
    $T->set_var('header', $LANG_MG00['plugin']);
    $T->set_var('site_url', $_MG_CONF['site_url']);
    $T->set_var('plugin', 'mediagallery');
    // construct the album jumpbox...
    $level = 0;
    $album_jumpbox = '<form name="jumpbox" action="' . $_MG_CONF['site_url'] . '/album.php' . '" method="get" style="margin:0;padding:0"><div>';
    $album_jumpbox .= $LANG_MG03['jump_to'] . ':&nbsp;<select name="aid" onchange="forms[\'jumpbox\'].submit()">';
    $MG_albums[0]->buildJumpBox($aid);
    $album_jumpbox .= '</select>';
    $album_jumpbox .= '&nbsp;<input type="submit" value="' . $LANG_MG03['go'] . '"/>';
    $album_jumpbox .= '<input type="hidden" name="page" value="1"/>';
    $album_jumpbox .= '</div></form>';
    // Update the views count... But only for non-admins
    if (!$MG_albums[0]->owner_id) {
        $media_views = $media[$mediaObject]['media_views'] + 1;
        DB_query("UPDATE " . $_TABLES['mg_media'] . " SET media_views=" . $media_views . " WHERE media_id='" . DB_escapeString($media[$mediaObject]['media_id']) . "'");
    }
    $columns_per_page = $MG_albums[$aid]->display_columns == 0 ? $_MG_CONF['ad_display_columns'] : $MG_albums[$aid]->display_columns;
    $rows_per_page = $MG_albums[$aid]->display_rows == 0 ? $_MG_CONF['ad_display_rows'] : $MG_albums[$aid]->display_rows;
    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_albums[$aid]->albums_first) {
        $childCount = $MG_albums[$aid]->getChildCount();
        $page = intval(($mediaObject + $childCount) / $media_per_page) + 1;
    } else {
        $page = intval($mediaObject / $media_per_page) + 1;
    }
    /*
     * check to see if the original image exists, if not fall back to full image
     */
    $media_size_orig = @getimagesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . '.' . $media[$mediaObject]['media_mime_ext']);
    if ($media_size_orig == false) {
        $full = 0;
        $disp = 'disp';
    }
    $aPage = intval($aOffset / ($_MG_CONF['album_display_columns'] * $_MG_CONF['album_display_rows'])) + 1;
    if ($sortID > 0) {
        $birdseed = '<a href="' . $_CONF['site_url'] . '/index.php">' . $LANG_MG03['home'] . '</a> ' . ($_MG_CONF['gallery_only'] == 1 ? '' : $_MG_CONF['seperator'] . ' <a href="' . $_MG_CONF['site_url'] . '/index.php?page=' . $aPage . '">' . $_MG_CONF['menulabel'] . '</a> ') . $_MG_CONF['seperator'] . '<a href="' . $_MG_CONF['site_url'] . '/search.php?id=' . $sortID . '&amp;page=' . $spage . '">' . $LANG_MG03['search_results'] . '</a>';
        $MG_albums[$aid]->getPath(1, $sortOrder, $page) . '</a>';
        $birdseed_ul = '<li><a href="' . $_CONF['site_url'] . '/index.php">' . $LANG_MG03['home'] . '</a></li>' . '<li><a href="' . $_MG_CONF['site_url'] . '/index.php?page=' . $aPage . '">' . $_MG_CONF['menulabel'] . '</a></li>' . '<li><a href="' . $_MG_CONF['site_url'] . '/search.php?id=' . $sortID . '&amp;page=' . $spage . '">' . $LANG_MG03['search_results'] . '</a></li>' . $MG_albums[$aid]->getPath_ul(1, $sortOrder, $page) . '</a>';
        $album_link = '<a href="' . $_MG_CONF['site_url'] . '/search.php?id=' . $sortID . '&amp;page=' . $spage . '">';
    } else {
        $birdseed = '<a href="' . $_CONF['site_url'] . '/index.php">' . $LANG_MG03['home'] . '</a> ' . ($_MG_CONF['gallery_only'] == 1 ? '' : $_MG_CONF['seperator'] . ' <a href="' . $_MG_CONF['site_url'] . '/index.php?page=' . $aPage . '">' . $_MG_CONF['menulabel'] . '</a> ') . $MG_albums[$aid]->getPath(1, $sortOrder, $page) . '</a>';
        $birdseed_ul = '<li><a href="' . $_CONF['site_url'] . '/index.php">' . $LANG_MG03['home'] . '</a></li>' . '<li><a href="' . $_MG_CONF['site_url'] . '/index.php?page=' . $aPage . '">' . $_MG_CONF['menulabel'] . '</a></li>' . $MG_albums[$aid]->getPath_ul(1, $sortOrder, $page) . '</a>';
        $album_link = '<a href="' . $_MG_CONF['site_url'] . '/album.php?aid=' . $aid . '&amp;page=' . $page . '&amp;sort=' . $sortOrder . '">';
    }
    mg_usage('media_view', $MG_albums[$aid]->title, $media[$mediaObject]['media_title'], $media[$mediaObject]['media_id']);
    // hack for tga files...
    if ($media[$mediaObject]['mime_type'] == 'image/x-targa' || $media[$mediaObject]['mime_type'] == 'image/tga') {
        $full = 0;
        $disp = 'disp';
    }
    switch ($media[$mediaObject]['mime_type']) {
        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':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayASF($aid, $media[$mediaObject], $full);
            break;
        case 'audio/x-ms-wma':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayMP3($aid, $media[$mediaObject], $full);
            break;
        case 'video/mp4':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayMP4($aid, $media[$mediaObject], $full);
            break;
        case 'video/mpeg':
        case 'video/x-mpeg':
        case 'video/x-mpeq2a':
            if ($_MG_CONF['use_wmp_mpeg'] == 1) {
                list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayASF($aid, $media[$mediaObject], $full);
                break;
            }
        case 'video/x-motion-jpeg':
        case 'video/quicktime':
        case 'video/x-qtc':
        case 'video/x-m4v':
            if ($media[$mediaObject]['media_mime_ext'] == 'mp4' && isset($_MG_CONF['play_mp4_flv']) && $_MG_CONF['play_mp4_flv'] == true) {
                list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayFLV($aid, $media[$mediaObject], $full);
            } else {
                list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayMOV($aid, $media[$mediaObject], $full);
            }
            break;
        case 'embed':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayEmbed($aid, $media[$mediaObject], $full, $mediaObject);
            break;
        case 'application/x-shockwave-flash':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displaySWF($aid, $media[$mediaObject], $full);
            break;
        case 'video/x-flv':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayFLV($aid, $media[$mediaObject], $full);
            break;
        case 'audio/mpeg':
        case 'audio/x-mpeg':
        case 'audio/mpeg3':
        case 'audio/x-mpeg-3':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayMP3($aid, $media[$mediaObject], $full);
            break;
        case 'application/ogg':
        case 'application/x-ogg':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayOGG($aid, $media[$mediaObject], $full);
            break;
        case 'image/x-targa':
        case 'image/tga':
        case 'image/tiff':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayTGA($aid, $media[$mediaObject], $full, $mediaObject);
            break;
        case 'image/photoshop':
        case 'image/x-photoshop':
        case 'image/psd':
        case 'application/photoshop':
        case 'application/psd':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayPSD($aid, $media[$mediaObject], $full, $mediaObject);
            break;
        case 'image/gif':
        case 'image/jpeg':
        case 'image/jpg':
        case 'image/png':
        case 'image/bmp':
            list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url, $media_link_start, $media_link_end) = MG_displayJPG($aid, $media[$mediaObject], $full, $media[$mediaObject]['media_id'], $sortOrder, $sortID, $spage);
            break;
        default:
            switch ($media[$mediaObject]['media_mime_ext']) {
                case 'jpg':
                case 'gif':
                case 'png':
                case 'bmp':
                    list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url, $media_link_start, $media_link_end) = MG_displayJPG($aid, $media[$mediaObject], $full, $media[$mediaObject]['media_id'], $sortOrder, $sortID, $spage);
                    break;
                case 'asf':
                    list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayASF($aid, $media[$mediaObject], $full);
                    break;
                default:
                    list($u_image, $raw_image, $raw_image_width, $raw_image_height, $raw_link_url) = MG_displayGeneric($aid, $media[$mediaObject], $full, $media[$mediaObject]['media_id'], $sortOrder);
                    break;
            }
    }
    $mid = $media[$mediaObject]['media_id'];
    $media_date = MG_getUserDateTimeFormat($media[$mediaObject]['media_time']);
    $upload_date = MG_getUserDateTimeFormat($media[$mediaObject]['media_upload_time']);
    // build the rating bar if rating is enabled.
    if ($MG_albums[$aid]->enable_rating > 0) {
        $uid = COM_isAnonUser() ? 1 : $_USER['uid'];
        $static = false;
        $voted = 0;
        // check to see if we are the owner, if so, no rating for us...
        if (isset($_USER['uid']) && $_USER['uid'] == $media[$mediaObject]['media_user_id']) {
            $static = true;
            $voted = 0;
        } else {
            if (in_array($media[$mediaObject]['media_id'], $ratedIds)) {
                $static = true;
                $voted = 1;
            } else {
                $static = 0;
                $voted = 0;
            }
        }
        if ($MG_albums[$aid]->enable_rating == 1 && COM_isAnonUser()) {
            $static = true;
            $voted = 0;
        }
        $rating_box = RATING_ratingBar('mediagallery', $media[$mediaObject]['media_id'], $media[$mediaObject]['media_votes'], $media[$mediaObject]['media_rating'], $voted, 5, $static, '');
    } else {
        $rating_box = '';
    }
    $T->set_var('rating_box', $rating_box);
    if ($MG_albums[$aid]->allow_download) {
        $T->set_var(array('download' => '<a href="' . $_MG_CONF['site_url'] . '/download.php?mid=' . $media[$mediaObject]['media_id'] . '">' . $LANG_MG01['download'] . '</a>'));
    }
    if ($media[$mediaObject]['media_type'] == 0 && $MG_albums[$aid]->enable_shutterfly) {
        $media_size_orig = false;
        $media_size_tn = false;
        if ($_MG_CONF['discard_original'] == 1) {
            foreach ($_MG_CONF['validExtensions'] as $ext) {
                if (file_exists($_MG_CONF['path_mediaobjects'] . 'disp/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext)) {
                    $sf_picture = $_MG_CONF['mediaobjects_url'] . '/disp/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext;
                    $media_size_orig = @getimagesize($_MG_CONF['path_mediaobjects'] . 'disp/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext);
                    break;
                }
            }
        } else {
            foreach ($_MG_CONF['validExtensions'] as $ext) {
                if (file_exists($_MG_CONF['path_mediaobjects'] . 'orig/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext)) {
                    $sf_picture = $_MG_CONF['mediaobjects_url'] . '/orig/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext;
                    $media_size_orig = @getimagesize($_MG_CONF['path_mediaobjects'] . 'orig/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext);
                    break;
                }
            }
        }
        foreach ($_MG_CONF['validExtensions'] as $ext) {
            if (file_exists($_MG_CONF['path_mediaobjects'] . 'tn/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext)) {
                $tnImage = $_MG_CONF['mediaobjects_url'] . '/tn/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext;
                $media_size_tn = @getimagesize($_MG_CONF['path_mediaobjects'] . 'tn/' . $media[$mediaObject]['media_filename'][0] . '/' . $media[$mediaObject]['media_filename'] . $ext);
                break;
            }
        }
        $outputHandle->addMeta('property', 'og:image', $tnImage);
        if ($media_size_orig != false && $media_size_tn != false) {
            $T->set_var(array('sf_height' => $media_size_orig[1], 'sf_width' => $media_size_orig[0], 'sf_tn_height' => $media_size_tn[1], 'sf_tn_width' => $media_size_tn[0], 'sf_thumbnail' => $tnImage, 'sf_picture' => $sf_picture, 'sf_title' => $media[$mediaObject]['media_title'], 'lang_print_digibug' => $LANG_MG03['print_digibug'], 'lang_print_shutterfly' => $LANG_MG03['print_shutterfly']));
            $T->parse('shutterfly_submit', 'shutterfly');
        }
    }
    if ($MG_albums[$aid]->access == 3 || $_MG_CONF['allow_user_edit'] == true && isset($_USER['uid']) && $media[$mediaObject]['media_user_id'] == $_USER['uid']) {
        $edit_item = '<a href="' . $_MG_CONF['site_url'] . '/admin.php?mode=mediaedit&amp;s=1&amp;album_id=' . $aid . '&amp;mid=' . $mid . '">' . $LANG_MG01['edit'] . '</a>';
    } else {
        $edit_item = '';
    }
    $media_desc = PLG_replaceTags(nl2br($media[$mediaObject]['media_desc']), 'mediagallery', 'media_description');
    if (strlen($media_desc) > 0) {
        USES_lib_html2text();
        $metaDesc = $media_desc;
        $metaDesc = strip_tags($metaDesc);
        $html2txt = new html2text($metaDesc, false);
        $metaDesc = trim($html2txt->get_text());
        $shortComment = '';
        $metaArray = explode(' ', $metaDesc);
        $wordCount = count($metaArray);
        $lengthCount = 0;
        $tailString = '';
        foreach ($metaArray as $word) {
            $lengthCount = $lengthCount + strlen($word);
            $shortComment .= $word . ' ';
            if ($lengthCount >= 100) {
                $tailString = '...';
                break;
            }
        }
        $metaDesc = trim($shortComment) . $tailString;
        $outputHandle->addMeta('name', 'description', htmlspecialchars($metaDesc, ENT_QUOTES, COM_getEncodingt()));
        $media_desc .= '<br/><br/>';
    }
    // start of the lightbox slideshow code
    if ($MG_albums[$aid]->enable_slideshow == 2) {
        $lbSlideShow = '<noscript><div class="pluginAlert">' . $LANG04[150] . '</div></noscript>' . LB;
        $lbSlideShow .= '<script type="text/javascript">' . LB;
        $lbSlideShow .= 'function openGallery1() {' . LB;
        $lbSlideShow .= '    return loadXMLDoc("' . $_MG_CONF['site_url'] . '/lightbox.php?aid=' . $aid . '");';
        $lbSlideShow .= '}' . LB;
        $lbSlideShow .= '</script>' . LB;
        $T->set_var('lbslideshow', $lbSlideShow);
    } else {
        $T->set_var('lbslideshow', '');
    }
    // end of the lightbox slideshow code
    switch ($MG_albums[$aid]->enable_slideshow) {
        case 0:
            $url_slideshow = '';
            break;
        case 1:
            $url_slideshow = '<a href="' . $_MG_CONF['site_url'] . '/slideshow.php?aid=' . $aid . '&amp;sort=' . $sortOrder . '"><b>' . $LANG_MG03['slide_show'] . '</b></a>';
            break;
        case 2:
            $lbss_count = DB_count($_TABLES['mg_media'], 'media_type', 0);
            $sql = "SELECT COUNT(m.media_id) as lbss_count FROM {$_TABLES['mg_media_albums']} as ma INNER JOIN " . $_TABLES['mg_media'] . " as m " . " ON ma.media_id=m.media_id WHERE m.media_type = 0 AND ma.album_id=" . $aid;
            $res = DB_query($sql);
            list($lbss_count) = DB_fetchArray($res);
            if ($lbss_count != 0) {
                $url_slideshow = '<span id="mgslideshow" class="jsenabled_show" style="display:none"><a href="#" onclick="return openGallery1()"><b>' . $LANG_MG03['slide_show'] . '</b></a></span>';
            } else {
                $MG_albums[$aid]->enable_slideshow = 0;
            }
            break;
        case 3:
            $url_slideshow = '<a href="' . $_MG_CONF['site_url'] . '/fslideshow.php?aid=' . $aid . '&amp;src=disp"><b>' . $LANG_MG03['slide_show'] . '</b></a>';
            break;
        case 4:
            $url_slideshow = '<a href="' . $_MG_CONF['site_url'] . '/fslideshow.php?aid=' . $aid . '&amp;src=orig"><b>' . $LANG_MG03['slide_show'] . '</b></a>';
            break;
    }
    $prevLink = '';
    $nextLink = '';
    list($prevLink, $nextLink) = $sortID > 0 ? array('', '') : MG_getNextandPrev($_MG_CONF['site_url'] . "/media.php?f=" . ($full ? '1' : '0') . "&amp;sort=" . $sortOrder, $nRows, 1, $mediaObject, $media, TRUE);
    $T->set_var(array('birdseed' => $birdseed, 'birdseed_ul' => $birdseed_ul, 'slide_show' => isset($url_slideshow) ? $url_slideshow : '', 'image_detail' => $u_image, 'border_height' => $raw_image_height + 30, 'border_width' => $raw_image_width + 30, 'media_title' => isset($media[$mediaObject]['media_title']) && $media[$mediaObject]['media_title'] != ' ' ? PLG_replaceTags($media[$mediaObject]['media_title'], 'mediagallery', 'media_title') : '', 'album_title' => $sortID > 0 ? $LANG_MG03['search_results'] : $MG_albums[$aid]->title, 'media_desc' => isset($media[$mediaObject]['media_desc']) && $media[$mediaObject]['media_desc'] != ' ' ? $media_desc : '', 'artist' => isset($media[$mediaObject]['artist']) ? $media[$mediaObject]['artist'] : '', 'media_time' => $media_date[0], 'upload_time' => $upload_date[0], 'media_views' => $MG_albums[$aid]->enable_views ? $media[$mediaObject]['media_views'] : '', 'media_comments' => $MG_albums[$aid]->enable_comments ? $media[$mediaObject]['media_comments'] . '<br />' : '', 'pagination' => $sortID > 0 ? '' : generate_pic_pagination($_MG_CONF['site_url'] . "/media.php?f=" . ($full ? '1' : '0') . "&amp;sort=" . $sortOrder, $nRows, 1, $mediaObject, $media, TRUE), 'media_number' => sprintf("%s %d %s %d", $LANG_MG03['image'], $mediaObject + 1, $LANG_MG03['of'], $total_media), 'jumpbox' => $album_jumpbox, 'edit_item' => $edit_item, 'site_url' => $_MG_CONF['site_url'], '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, 'media_link_start' => $media_link_start, 'media_link_end' => $media_link_end, 'raw_link_url' => $raw_link_url, 'album_link' => $MG_albums[$aid]->getPath(1, $sortOrder, $page), 'item_number' => $mediaObject + 1, 'total_items' => $total_media, 'lang_of' => $LANG_MG03['of'], 'album_link' => $album_link));
    $getid3link = '';
    $getid3linkend = '';
    $T->set_var(array('getid3' => $getid3link, 'getid3end' => $getid3linkend));
    if ($getid3link != '') {
        $T->set_var('media_properties', $LANG_MG03['media_properties']);
    } else {
        $T->set_var('media_properties', '');
    }
    if ($MG_albums[$aid]->enable_keywords == 1 && !empty($media[$mediaObject]['media_keywords'])) {
        $kwText = '';
        $keyWords = array();
        $keyWords = explode(' ', $media[$mediaObject]['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> ';
        }
        $T->set_var(array('media_keywords' => $kwText, 'lang_keywords' => $LANG_MG01['keywords']));
    } else {
        $T->set_var(array('media_keywords' => '', 'lang_keywords' => ''));
    }
    if ($media[$mediaObject]['media_user_id'] == '' || !isset($media[$mediaObject]['media_user_id'])) {
        $media[$mediaObject]['media_user_id'] = 0;
    }
    if ($_CONF['show_fullname']) {
        $displayname = 'fullname';
    } else {
        $displayname = 'username';
    }
    $owner_name = DB_getItem($_TABLES['users'], $displayname, "uid = {$media[$mediaObject]['media_user_id']}");
    if (empty($owner_name) || $owner_name == '') {
        $owner_name = DB_getItem($_TABLES['users'], 'username', "uid = {$media[$mediaObject]['media_user_id']}");
        if (empty($owner_name) || $owner_name == '') {
            $owner_name = 'unknown';
        }
    }
    if ($owner_name != 'unknown') {
        $owner_link = '<a href="' . $_CONF['site_url'] . '/users.php?mode=profile&amp;uid=' . $media[$mediaObject]['media_user_id'] . '">' . $owner_name . '</a>';
    } else {
        $owner_link = $owner_name;
    }
    $T->set_var('owner_username', $owner_link);
    if (($MG_albums[$aid]->exif_display == 2 || $MG_albums[$aid]->exif_display == 3) && $media[$mediaObject]['media_type'] == 0) {
        require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-exif.php';
        $haveEXIF = MG_haveEXIF($media[$mediaObject]['media_id']);
        if ($haveEXIF) {
            $T->set_var(array('property' => $_MG_CONF['site_url'] . '/property.php?mid=' . $media[$mediaObject]['media_id'], 'lang_property' => $LANG_MG04['exif_header']));
        }
    }
    if ($MG_albums[0]->owner_id || $_MG_CONF['enable_media_id'] == 1) {
        $T->set_var(array('media_id' => $media[$mediaObject]['media_id']));
    }
    // Language specific vars
    $T->set_var(array('lang_comments' => $MG_albums[$aid]->enable_comments ? $LANG_MG03['comments'] : '', 'lang_views' => $MG_albums[$aid]->enable_views ? $LANG_MG03['views'] : '', 'lang_title' => $LANG_MG01['title'], 'print_shutterfly' => $LANG_MG03['print_shutterfly'], 'lang_uploaded_by' => $LANG_MG01['uploaded_by'], 'album_id' => $aid, 'lang_search' => $LANG_MG01['search']));
    if (($MG_albums[$aid]->exif_display == 1 || $MG_albums[$aid]->exif_display == 3) && $media[$mediaObject]['media_type'] == 0) {
        require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-exif.php';
        $haveEXIF = MG_haveEXIF($media[$mediaObject]['media_id']);
        if ($haveEXIF) {
            $exifData = MG_readEXIF($media[$mediaObject]['media_id'], 2);
            $T->set_var(array('exif_info' => $exifData));
        }
    }
    if ($sortID == 0) {
        if ($MG_albums[$aid]->enable_postcard == 1 && !COM_isAnonUser() || $MG_albums[$aid]->enable_postcard == 2) {
            if ($media[$mediaObject]['media_type'] == 0) {
                $postcard_link = '<a href="' . $_MG_CONF['site_url'] . '/postcard.php?mode=edit&amp;mid=' . $media[$mediaObject]['media_id'] . '"><img src="' . MG_getImageFile('icon_envelopeSmall.gif') . '" alt="' . $LANG_MG03['send_postcard'] . '" style="border:none;"/></a>';
                $T->set_var('postcard_link', $postcard_link);
            }
        }
    }
    PLG_templateSetVars('mediagallery', $T);
    $T->parse('output', 'page');
    $retval .= $T->finish($T->get_var('output'));
    if ($comments) {
        // glFusion Comment support
        $mid = $media[$mediaObject]['media_id'];
        if ($MG_albums[$aid]->enable_comments == 1) {
            USES_lib_comment();
            if ($MG_albums[$aid]->access == 3 || $MG_albums[0]->owner_id) {
                $delete_option = true;
            } else {
                $delete_option = false;
            }
            if (DB_count($_TABLES['comments'], 'sid', $mid) > 0 || $_MG_CONF['commentbar']) {
                $cid = $mid;
                $page = isset($_GET['page']) ? COM_applyFilter($_GET['page'], true) : 0;
                if (isset($_POST['order'])) {
                    $comorder = $_POST['order'] == 'ASC' ? 'ASC' : 'DESC';
                } elseif (isset($_GET['order'])) {
                    $comorder = $_GET['order'] == 'ASC' ? 'ASC' : 'DESC';
                } else {
                    $comorder = '';
                }
                if (isset($_POST['mode'])) {
                    $commode = COM_applyFilter($_POST['mode']);
                } elseif (isset($_GET['mode'])) {
                    $commode = COM_applyFilter($_GET['mode']);
                } else {
                    $commode = '';
                }
                $valid_cmt_modes = array('flat', 'nested', 'nocomment', 'nobar');
                if (!in_array($commode, $valid_cmt_modes)) {
                    $commode = 'nested';
                }
                $commentbar = CMT_userComments($cid, $media[$mediaObject]['media_title'], 'mediagallery', $comorder, $commode, 0, $page, false, $delete_option, 0, $media[$mediaObject]['media_user_id']);
                $retval .= $commentbar;
            } else {
                $retval .= ' <center><a href="' . $_CONF['site_url'] . '/comment.php?sid=' . $mid . '&amp;title=' . $title . '&amp;pid=0&amp;type=mediagallery' . '">' . $LANG01[60] . '</a></center>';
            }
        }
    }
    return array(strip_tags($media[$mediaObject]['media_title']), $retval, '', $aid);
}